Permutation.commutes_with() : commutes_with() is a sympy Python library function that checks whether the two permutations are commuting. Suppose ‘a’ and ‘b’ are part of ‘C’, then the commutator of a and b is the ‘C’ identity if a and b commute, i.e. ab == ba.
Syntax : sympy.combinatorics.permutations.Permutation.commutes_with() Return : checks whether the two permutations are commuting
Code #1 : commutes_with() Example
Python3
# Python code explaining # SymPy.Permutation.commutes_with() # importing SymPy libraries from sympy.combinatorics.partitions import Partition from sympy.combinatorics.permutations import Permutation # Using from sympy.combinatorics.permutations.Permutation.commutes_with() method # creating Permutation a = Permutation([ 2 , 0 , 3 , 1 , 5 , 4 ]) b = Permutation([ 3 , 1 , 2 , 5 , 4 , 0 ]) print ("Permutation a - commutes_with form : ", a.commutes_with(b)) print ("Permutation b - commutes_with form : ", b.commutes_with(a)) |
Output :
Permutation a – commutes_with form : False Permutation b – commutes_with form : False
Code #2 : commutes_with() Example – Self Commutator
Python3
# Python code explaining # SymPy.Permutation.commutes_with() # importing SymPy libraries from sympy.combinatorics.partitions import Partition from sympy.combinatorics.permutations import Permutation # Using from sympy.combinatorics.permutations.Permutation.commutes_with() method # creating Permutation a = Permutation([[ 2 , 4 , 0 ], [ 3 , 1 , 2 ], [ 1 , 5 , 6 ]]) # SELF COMMUTATING print ("Permutation a - commutes_with form : ", a.commutes_with(a)) |
Output :
Permutation a – commutes_with form : True