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