StringTools - Maple Help

Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Transformations : StringTools/Permute

StringTools

 Permute
 apply a given permutation to a string

 Calling Sequence Permute( s, perm )

Parameters

 s - Maple string perm - list of integers; permutation of 1 .. length(s)

Description

 • The Permute(s, perm) command applies a given permutation perm to the string s.
 • The permutation perm must be a permutation of the integer $1..\mathrm{length}\left(s\right)$, given as a list.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{Permute}\left("abc",\left[1,2,3\right]\right)$
 ${"abc"}$ (1)
 > $\mathrm{Permute}\left("abc",\left[1,3,2\right]\right)$
 ${"acb"}$ (2)
 > $\mathrm{Permute}\left("abc",\left[2,1,3\right]\right)$
 ${"bac"}$ (3)
 > $\mathrm{Permute}\left("abc",\left[2,3,1\right]\right)$
 ${"bca"}$ (4)
 > $\mathrm{Permute}\left("abc",\left[3,1,2\right]\right)$
 ${"cab"}$ (5)
 > $\mathrm{Permute}\left("abc",\left[3,2,1\right]\right)$
 ${"cba"}$ (6)
 > $\mathrm{Permute}\left("abc",\left[2,1,4,3\right]\right)$
 > $\mathrm{Permute}\left("abc",\left[2,3,3\right]\right)$

Using combinat[permute] you can construct all permutations of a string.

 > AllPermutations := proc( s::string )     local    p;     seq( StringTools:-Permute( s, p ),         p = combinat[ 'permute' ]( length( s ) ) ) end proc:
 > $\mathrm{AllPermutations}\left("uvw"\right)$
 ${"uvw"}{,}{"uwv"}{,}{"vuw"}{,}{"vwu"}{,}{"wuv"}{,}{"wvu"}$ (7)
 > $\mathrm{AllPermutations}\left("abcd"\right)$
 ${"abcd"}{,}{"abdc"}{,}{"acbd"}{,}{"acdb"}{,}{"adbc"}{,}{"adcb"}{,}{"bacd"}{,}{"badc"}{,}{"bcad"}{,}{"bcda"}{,}{"bdac"}{,}{"bdca"}{,}{"cabd"}{,}{"cadb"}{,}{"cbad"}{,}{"cbda"}{,}{"cdab"}{,}{"cdba"}{,}{"dabc"}{,}{"dacb"}{,}{"dbac"}{,}{"dbca"}{,}{"dcab"}{,}{"dcba"}$ (8)