 combinat - Maple Programming Help

Home : Support : Online Help : Mathematics : Discrete Mathematics : Combinatorics : combinat : combinat/nextperm

combinat

 nextperm
 construct the lexicographic successor of a given permutation
 prevperm
 construct the lexicographic predecessor of a given permutation
 firstperm
 construct the first permutation in lexicographic order
 lastperm
 construct the last permutation in lexicographic order

 Calling Sequence nextperm( p ) prevperm( p ) firstperm( n ) lastperm( n )

Parameters

 p - permlist; permutation of positive integers from 1 to n for some n n - nonnegint; degree of the permutation

Description

 • Given a permutation p (of type permlist) of the integers 1 through n, for some n, the command nextperm returns the lexicographic successor of p.
 • If p is the lexicographically last permutation of degree n (that is, [n,n-1,...,2,1]), then the value FAIL is returned.
 • Given a permutation p (of type permlist) of the integers 1 through n, for some n, the command prevperm returns the lexicographic predecessor of p.
 • If p is the first permutation of degree n in lexicographic order (that is, [1,2,...,n-1,n]), then the value FAIL is returned.
 • The command firstperm returns the first permutation, in lexicographic order, of the permutations of the set {1,2,...,n} of integers from 1 to n. This is the permutation [ 1, 2, ..., n ].
 • The command lastperm returns the last permutation, in lexicographic order, of the permutations of the set {1,2,...,n} of integers from 1 to n. The lexicographically last permutation of {1,2,...,n} is [n, n-1, ..., 2, 1 ].

 • The combinat[nextperm], combinat[prevperm], combinat[firstperm] and combinat[lastperm] 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{nextperm}\left(\left[1,3,2\right]\right)$
 $\left[{2}{,}{1}{,}{3}\right]$ (2)
 > $\mathrm{nextperm}\left(\left[4,3,2,1\right]\right)$
 ${\mathrm{FAIL}}$ (3)
 > $\mathrm{prevperm}\left(\left[2,1,3\right]\right)$
 $\left[{1}{,}{3}{,}{2}\right]$ (4)
 > $\mathrm{prevperm}\left(\left[1,2,3,4,5\right]\right)$
 ${\mathrm{FAIL}}$ (5)
 > $\mathrm{firstperm}\left(4\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}\right]$ (6)
 > $\mathrm{lastperm}\left(3\right)$
 $\left[{3}{,}{2}{,}{1}\right]$ (7)

Compatibility

 • The combinat[nextperm], combinat[prevperm], combinat[firstperm] and combinat[lastperm] commands were introduced in Maple 16.