Skip to content
Related Articles

Related Articles

Improve Article
Python | SymPy Permutation.commutes_with() method
  • Last Updated : 26 Aug, 2019


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 iff 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




# 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




# 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

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :