Given a permutation, this function returns its position in the Lehmer code order.
Usage
getpermutationnumber(permutation)
Value
The position of the permutation according to the Lehmer code order, as an integer.
Arguments
permutation
A permutation, as a vector.
Details
The Lehmer code makes use of the fact that there are \(n!\) permutations of a sequence of \(n\) numbers.
If a permutation \(\sigma\) is specified by the sequence \((\sigma_{i})_{i=1}^{n}\), its Lehmer code is the
sequence \(L(\sigma)=(L(\sigma)_{i})_{i=1}^{n}\), where \(L(\sigma)_i=|\{j>i:\sigma_j<\sigma_i\}|\).
The position of permutation \(\sigma\) according to the Lehmer code order is
$$L_{\sigma}=1 + \sum_{i=1}^{n} (n-i)! L(\sigma)_i$$.