Question: How to transform a permutation into numbers and vice versa (via Lehmer Code)

Dear all,

I hope everyone helps me about the problem of converting a permutation into numbers and vice versa on maple

Let Sn denote the set of all permutations of the set {0, 1, ..., n − 1}

Lehmer code is a bijective function l : Sn ->{0, 1, 2, ..., n! − 1}.

Define function l(S)=Sum(ci x (n − 1 − i)! ) where S in Sn and ci is the number of elements of the set { j > i | sj < si }

Inverse Lehmer code is a bijective function l−1 : {0, 1, 2, ..., n! − 1} -> Sn

For example: n=4 -->{0, 1, 2, 3}, for S = (0, 2, 1, 3) , so c0 = 0, c1 = 1 ( j=2 > i=1 and sj = 1 < si = 2), c2 = 0, c3 = 0 -->

I(S) = 0 x (3-0)! + 1 x (3 - 1)! + 0 x (3-2)! + 0 x (3 - 3)! = 2! = 2. So I((0, 2, 1, 3)) =2  and I-1(2) = (0, 2, 1, 3).

How to calculate I and I-1 on maple? Please help me! Thanks alot.

 

 

Please Wait...