SymPy | Permutation.rank_nonlex() in Python
Last Updated :
27 Aug, 2019
Permutation.rank_nonlex() : rank_nonlex() is a sympy Python library function that returns the rank of non lexicographical permutation.
Syntax : sympy.combinatorics.permutations.Permutation.rank_nonlex()
Return : rank of non lexicographical permutation.
Code #1 : rank_nonlex() 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 - rank_nonlex form : " , a.rank_nonlex())
print ( "Permutation b - rank_nonlex form : " , b.rank_nonlex())
|
Output :
Permutation a – rank_nonlex form : 13
Permutation b – rank_nonlex form : 72
Code #2 : rank_nonlex() Example – 2D Permutation
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 - rank_nonlex form : " , a.rank_nonlex())
|
Output :
Permutation a – rank_nonlex form : 218
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...