2. Operations with permutations

By default, xPerm` does not check at every step that the objects we are working with are actually permutations because it would take quite some time. The function PermQ is supplied to do that when you require it.

We can validate a permutation with PermQ:

In[20]:=

PermQ[Perm[{1, 2, 3, 0}]]

Out[20]=

False

In[21]:=

PermQ[Perm[{1, 4, 3, 2}]]

Out[21]=

True

In[22]:=

PermQ[Images[{1, 2, 3, 1}]]

Out[22]=

False

In[23]:=

PermQ[Cycles[{1, 2.}, {4, 3}]]

Out[23]=

False

In[24]:=

PermQ[Rules[1→2, 1→3, 2→3]]

Out[24]=

False

In[25]:=

PermQ[-Cycles[{2, 3}, {4, 5}]]

Out[25]=

True

Every permutation has a degree, defined as the largest moved point (signs are not relevant):

In[26]:=

PermDeg[Perm[{4, 3, 5, 2, 1}]]

Out[26]=

5

In[27]:=

PermDeg[-Images[{3, 4, 5, 6, 2, 1}]]

Out[27]=

6

In[28]:=

PermDeg[Cycles[{2, 3, 1}, {55, 78}]]

Out[28]=

78

In[29]:=

PermDeg[Perm[{2, 1, 3, 4, 5}]]

Out[29]=

2

The identity permutation has degree zero:

In[30]:=

PermDeg[Cycles[]]

Out[30]=

0

In[31]:=

PermDeg[Perm[{1, 2, 3, 4, 5}]]

Out[31]=

0

A different concept is that of "length" of a permutation, defined only for notations Perm and Images: it is the length of the list of points. On Cycles and Rules notations length is defined as the degree. This concept is used in internal computations to avoid recomputing the degree of a permutation many times.

In[32]:=

PermDeg[Perm[{2, 1, 3, 4, 5}]]

Out[32]=

2

In[33]:=

PermLength[Perm[{2, 1, 3, 4, 5}]]

Out[33]=

5

On notations Perm and Images the function NotationOfPerm returns the length (not the degree):

In[34]:=

NotationOfPerm[Perm[{2, 1, 3, 4, 5}]]

Out[34]=

{Perm, 5}

It is possible to generate random permutations, of any notation

In[35]:=

RandomPerm[10, Cycles]

Out[35]=

Cycles[{1, 3, 10, 8, 5, 2, 4, 7}, {6, 9}]

In[36]:=

RandomPerm[8, Images]

Out[36]=

Images[{7, 1, 8, 5, 4, 3, 2, 6}]

The most important operation with permutations is that of their product. I don't like names like Times or similar. I choose a name which is associated only with permutations:

Product of two permutations in the same notation. The (noncommutative) product is from right to left. This means that the product permutation Permute[p1, p2] applied on a given list is equivalent to the application of p1 on that list and then p2 on the result.

In[37]:=

Permute[Perm[{3, 2, 1}], Perm[{2, 3, 1}]]

Out[37]=

Perm[{2, 1, 3}]

In[38]:=

Permute[Perm[{2, 3, 1}], Perm[{3, 2, 1}]]

Out[38]=

Perm[{1, 3, 2}]

That is the choice in GAP. This example is taken from its manual:

In[39]:=

PermEqual[Permute[Cycles[{1, 2, 3}], Cycles[{1, 2}]], Cycles[{2, 3}]]

Out[39]=

True

In[40]:=

PermEqual[Permute[Cycles[{1, 2}], Cycles[{1, 2, 3}]], Cycles[{1, 3}]]

Out[40]=

True

Inverse permutation:

In[41]:=

InversePerm[Perm[{4, 3, 1, 2}]]

Out[41]=

Perm[{3, 4, 2, 1}]

In[42]:=

Permute[Perm[{4, 3, 1, 2}], %]

Out[42]=

Perm[{1, 2, 3, 4}]

Powers of a permutation (equivalent to repeated product with itself). Negative exponents mean powers of the inverse. Note the high efficiency of this function:

In[43]:=

myTiming[PowerPermute[Perm[{5, 1, 2, 3, 4}], 27]]

0.000548 Second

Out[43]=

Perm[{4, 5, 1, 2, 3}]

In[44]:=

myTiming[PowerPermute[Perm[{5, 1, 2, 3, 4}], -10^10 - 27]]

0.002646 Second

Out[44]=

Perm[{3, 4, 5, 1, 2}]

In[45]:=

Permute[%, %%]

Out[45]=

Perm[{1, 2, 3, 4, 5}]

In[46]:=

PowerPermute[Perm[{5, 1, 2, 3, 4}], 0]

Out[46]=

Perm[{1, 2, 3, 4, 5}]

Permutations can be sorted and compared according to their lists of images:

In[47]:=

PermSort[{Perm[{2, 3, 1}], Perm[{3, 1, 2}], Perm[{1, 2, 3}]}]

Out[47]=

{Perm[{1, 2, 3}], Perm[{3, 1, 2}], Perm[{2, 3, 1}]}

In[48]:=

TranslatePerm[%, Images]

Out[48]=

{Images[{1, 2, 3}], Images[{2, 3, 1}], Images[{3, 1, 2}]}

In[49]:=

PermLess[Perm[{3, 1, 2}], Perm[{2, 3, 1}]]

Out[49]=

True

The function PermEqual checks mathematical equality of permutations comparing images of points and it is thus notation independent:

In[50]:=

PermEqual[Cycles[{1, 2, 3}], Perm[{3, 1, 2}]]

Out[50]=

True

In[51]:=

Cycles[{1, 2, 3}] === Perm[{3, 1, 2}]

Out[51]=

False

All comparatives have been generalized: PermEqual, PermLess, PermGreater, PermLessEqual, PermGreaterEqual, PermOrderedQ, and we can also sort points and permutations as given by a base.

In[52]:=

? PermOrderedQ

Images of points or lists of points:

In[53]:=

OnPoints[4, Perm[{1, 2, 5, 3, 4}]]

Out[53]=

5

In[54]:=

OnPoints[{2, 4, 3}, Rules[1→3, 2→1, 3→2]]

Out[54]=

{1, 4, 2}

There is a simple way to generate the identity corresponding to any notation, degree and sign:

In[55]:=

ID[Perm[{3, 2, 4, 1}]]

Out[55]=

Perm[{1, 2, 3, 4}]

In[56]:=

ID[Cycles[{3, 2, 4}, {5, 6}]]

Out[56]=

Cycles[]

In[57]:=

ID[-Images[{4, 5, 3, 2, 1}]]

Out[57]=

Images[{1, 2, 3, 4, 5}]

ID also represents the identity:

In[58]:=

Permute[ID, Perm[{3, 2, 4, 1}]]

Out[58]=

Perm[{3, 2, 4, 1}]

We can permute any kind of list, even with repeated elements:

In[59]:=

PermuteList[{a, b, c, d, b}, Perm[{4, 3, 2, 5, 1}]]

Out[59]=

{d, c, b, b, a}

Or find a permutation linking two different lists. The result is given in Images notation:

In[60]:=

PermutationFromTo[{a, b, c, d}, {d, c, b, a}]

Out[60]=

Images[{4, 3, 2, 1}]

Again, note that the order of permutation is very important:

In[61]:=

p1 = Images[{4, 3, 2, 5, 1}] ;

p2 = Images[{5, 3, 4, 1, 2}] ;

In[63]:=

{1, 2, 3, 4, 5}//OnPoints[#, p1] &//OnPoints[#, p2] &

Out[63]=

{1, 4, 3, 2, 5}

In[64]:=

{1, 2, 3, 4, 5}//OnPoints[#, Permute[p1, p2]] &

Out[64]=

{1, 4, 3, 2, 5}

In[65]:=

{1, 2, 3, 4, 5}//OnPoints[#, p1] &

Out[65]=

{4, 3, 2, 5, 1}

In[66]:=

PermuteList[{1, 2, 3, 4, 5}, InversePerm[p1]]

Out[66]=

{4, 3, 2, 5, 1}

PermQ                    Validate a permutation
PermDeg                    
Give the degree of a permutation
PermLength                Give the length of a permutation
RandomPerm                Construct a random permutation of a given degree
Permute                    
Product of several permutations
InversePerm                
Inverse of a permutation
PowerPermute            
Repeated product of a permutation
PermSort                
Order permutations according to their images
OnPoints                
Compute images of points under a permutation
ID                        
Identity permutation
PermuteList                Apply permutation on a given list
PermutationFromTo        Calculate permutation changing one list into other

Basic operations with permutations.

SortB                    Sort points as given by a base
MinB                    
Least point of a list as given by a base
PermEqual                Compare permutations
PermGreater                Compare permutations
PermLess                
Compare permutations
PermGreaterqual            Compare permutations
PermLessEqual            Compare permutations
PermOrderedQ            
Check whether a list of permuations is sorted
PermSort                
Sort permutations according to their images

Sorting and comparing permutations.


Created by Mathematica  (May 16, 2008) Valid XHTML 1.1!