Permutation.transpositions() : transpositions() is a sympy Python library function that returns the permutation decomposed into a list of transpositions. It is always possible to express a permutation as the product of transpositions.
Syntax : sympy.combinatorics.permutations.Permutation.transpositions()
Return : permutation decomposed into a list of transpositions
Code #1 : transpositions() Example
# Python code explaining # SymPy.Permutation.transpositions() # importing SymPy libraries from sympy.combinatorics.partitions import Partition from sympy.combinatorics.permutations import Permutation # Using from # sympy.combinatorics.permutations.Permutation.transpositions() method # creating Permutation a = Permutation([[ 2 , 0 ], [ 3 , 1 ]]) b = Permutation([ 1 , 3 , 5 , 4 , 2 , 0 ]) print ( "Permutation a - transpositions form : " , a.transpositions()) print ( "Permutation b - transpositions form : " , b.transpositions()) |
Output :
Permutation a – transpositions form : [(0, 2), (1, 3)]
Permutation b – transpositions form : [(0, 5), (0, 2), (0, 4), (0, 3), (0, 1)]
Code #2 : transpositions() Example
# Python code explaining # SymPy.Permutation.transpositions() # importing SymPy libraries from sympy.combinatorics.partitions import Partition from sympy.combinatorics.permutations import Permutation # Using from # sympy.combinatorics.permutations.Permutation.transpositions() method # creating Permutation a = Permutation([[ 2 , 4 , 0 ], [ 3 , 1 , 2 ], [ 1 , 5 , 6 ]]) print ( "Permutation a - transpositions form : " , a.transpositions()) |
Output :
Permutation a – transpositions form : [(0, 4), (0, 2), (0, 1), (0, 6), (0, 5), (0, 3)]