InversePermutation - Maple Help

ListTools

 InversePermutation
 compute the inverse of a permutation
 Unpermute
 apply the inverse of a permutation to a permuted list

 Calling Sequence InversePermutation( Permutation ) Unpermute( Data, Permutation )

Parameters

 Permutation - list that is a permutation of the positive integers up to n for some nonnegative integer n Data - list having the same number of elements as Permutation

Description

 • The InversePermutation command takes a permutation list P, and computes the inverse Q. More precisely, if P is a permutation of the positive integers up to nonnegative integer n, then P[Q]=N and Q[P]=N, where N=[1,..,n].
 • The Unpermute command takes a list B and a permutation list P of the same size as B, and applies the inverse permutation to B. That is, if Q is the inverse of P, then the command returns B[Q]. Note that A=B[Q] satisfies A[P]=B.
 • The commands also accept Vectors and 1-D Arrays. If an Array or Vector is passed for Permutation, the inverse is computed as a list. Moreover, if Data is an Array with first index different than 1, then the inverse permutation is performed as if Data is an Array with first index 1, but the dimensions of the result will match the original.

Examples

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$

Example 1

 > $P≔\left[3,8,9,5,1,7,2,10,4,6\right]$
 ${P}{≔}\left[{3}{,}{8}{,}{9}{,}{5}{,}{1}{,}{7}{,}{2}{,}{10}{,}{4}{,}{6}\right]$ (1)
 > $Q≔\mathrm{InversePermutation}\left(P\right)$
 ${Q}{≔}\left[{5}{,}{7}{,}{1}{,}{9}{,}{4}{,}{10}{,}{6}{,}{2}{,}{3}{,}{8}\right]$ (2)
 > ${P}_{Q}$
 $\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}{,}{6}{,}{7}{,}{8}{,}{9}{,}{10}\right]$ (3)
 > ${Q}_{P}$
 $\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}{,}{6}{,}{7}{,}{8}{,}{9}{,}{10}\right]$ (4)

Example 2

 • First, consider this unsorted list:
 > $A≔\left["e","c","a","b","d"\right]$
 ${A}{≔}\left[{"e"}{,}{"c"}{,}{"a"}{,}{"b"}{,}{"d"}\right]$ (5)
 • Now, sort the list and record the sorting permutation:
 > $B,P≔\mathrm{sort}\left(A,'\mathrm{output}'=\left['\mathrm{sorted}','\mathrm{permutation}'\right]\right)$
 ${B}{,}{P}{≔}\left[{"a"}{,}{"b"}{,}{"c"}{,}{"d"}{,}{"e"}\right]{,}\left[{3}{,}{4}{,}{2}{,}{5}{,}{1}\right]$ (6)
 • The Unpermute returns the original, unsorted list:
 > $\mathrm{Unpermute}\left(B,P\right)$
 $\left[{"e"}{,}{"c"}{,}{"a"}{,}{"b"}{,}{"d"}\right]$ (7)

Example 3

 > $X≔\mathrm{Array}\left(0..2,\left[5,10,15\right]\right)$
 > $P≔\left[2,3,1\right]$
 ${P}{≔}\left[{2}{,}{3}{,}{1}\right]$ (8)
 > $Q≔\mathrm{InversePermutation}\left(P\right)$
 ${Q}{≔}\left[{3}{,}{1}{,}{2}\right]$ (9)
 > $Y≔\mathrm{Unpermute}\left(X,P\right)$

Compatibility

 • The ListTools[InversePermutation] and ListTools[Unpermute] commands were introduced in Maple 2023.