Friday, November 21, 2025
HomeLanguagesPython | SymPy Permutation.commutes_with() method

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




# 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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6781 POSTS0 COMMENTS
Nicole Veronica
11928 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11997 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7166 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS