rankperm - Maple Help

combinat

 rankperm
 construct the lexicographic successor of a given permutation
 unrankperm
 construct the lexicographic predecessor of a given permutation

 Calling Sequence rankperm( p ) unrankperm( n, r )

Parameters

 p - permlist; permutation of positive integers from 1 to n for some n n - posint; permutation degree r - posint; rank of permutation

Description

 • Given a permutation p (of type permlist) of the integers 1 through n, for some n, the command rankperm returns the lexicographic rank of p. That is, its position in the lexicographically sorted list of all permutations of degree n.
 • The unrankperm command is a kind of inverse to rankperm.   Given the lexicographic rank r (an integer in the range 1..n!), it returns the permutation that occurs in position r in a lexicographically sorted list of all the permutations of {1,2,...,n}.

 • The combinat[rankperm] and combinat[unrankperm] commands are thread-safe as of Maple 16.

Examples

 > $\mathrm{with}\left(\mathrm{combinat}\right)$
 $\left[{\mathrm{Chi}}{,}{\mathrm{bell}}{,}{\mathrm{binomial}}{,}{\mathrm{cartprod}}{,}{\mathrm{character}}{,}{\mathrm{choose}}{,}{\mathrm{composition}}{,}{\mathrm{conjpart}}{,}{\mathrm{decodepart}}{,}{\mathrm{encodepart}}{,}{\mathrm{eulerian1}}{,}{\mathrm{eulerian2}}{,}{\mathrm{fibonacci}}{,}{\mathrm{firstcomb}}{,}{\mathrm{firstpart}}{,}{\mathrm{firstperm}}{,}{\mathrm{graycode}}{,}{\mathrm{inttovec}}{,}{\mathrm{lastcomb}}{,}{\mathrm{lastpart}}{,}{\mathrm{lastperm}}{,}{\mathrm{multinomial}}{,}{\mathrm{nextcomb}}{,}{\mathrm{nextpart}}{,}{\mathrm{nextperm}}{,}{\mathrm{numbcomb}}{,}{\mathrm{numbcomp}}{,}{\mathrm{numbpart}}{,}{\mathrm{numbperm}}{,}{\mathrm{partition}}{,}{\mathrm{permute}}{,}{\mathrm{powerset}}{,}{\mathrm{prevcomb}}{,}{\mathrm{prevpart}}{,}{\mathrm{prevperm}}{,}{\mathrm{randcomb}}{,}{\mathrm{randpart}}{,}{\mathrm{randperm}}{,}{\mathrm{rankcomb}}{,}{\mathrm{rankperm}}{,}{\mathrm{setpartition}}{,}{\mathrm{stirling1}}{,}{\mathrm{stirling2}}{,}{\mathrm{subsets}}{,}{\mathrm{unrankcomb}}{,}{\mathrm{unrankperm}}{,}{\mathrm{vectoint}}\right]$ (1)
 > $\mathrm{rankperm}\left(\left[1,3,2\right]\right)$
 ${2}$ (2)
 > $\mathrm{rankperm}\left(\left[4,1,2,3\right]\right)$
 ${19}$ (3)
 > $\mathrm{unrankperm}\left(19,4\right)$
 $\left[{4}{,}{1}{,}{2}{,}{3}\right]$ (4)
 > $\left[\mathrm{seq}\right]\left(\mathrm{unrankperm}\left(r,3\right),r=1..3!\right)$
 $\left[\left[{1}{,}{2}{,}{3}\right]{,}\left[{1}{,}{3}{,}{2}\right]{,}\left[{2}{,}{1}{,}{3}\right]{,}\left[{2}{,}{3}{,}{1}\right]{,}\left[{3}{,}{1}{,}{2}\right]{,}\left[{3}{,}{2}{,}{1}\right]\right]$ (5)

Compatibility

 • The combinat[rankperm] and combinat[unrankperm] commands were introduced in Maple 16.