Python | SymPy Permutation.commutes_with() method
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
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import 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
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
a = Permutation([[ 2 , 4 , 0 ],
[ 3 , 1 , 2 ],
[ 1 , 5 , 6 ]])
print ("Permutation a - commutes_with form : ", a.commutes_with(a))
|
Output :
Permutation a – commutes_with form : True
Last Updated :
12 Sep, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...