Академический Документы
Профессиональный Документы
Культура Документы
Permutations
Representation of a Permutation
Product of Permutations
Permutations are basic elements in algebra. They have a natural non-commutative product (as matrices do as well), and
hence can encode highly nontrivial structures in a compact way. Permutations provide a way of representing any finite
group, which makes them key tools in many applications in mathematics, science, engineering, or even art. In particular,
permutations play a central role in the description of discrete symmetries.
Permutations are, roughly speaking, reorderings of a set of elements, or more precisely, bijections from the set onto
itself. Only sets with a finite number of elements will be considered. The number of possible permutations of a set of n
elements is n !, and therefore for a moderate number n 100 there are already 100 ! permutations, which is almost 10158 .
This tutorial discusses how to manipulate permutations in cyclic notation in Mathematica, and "Permutation Lists"
describes the relation to permutation list notation. Other tutorials, "Permutation Groups" and "Named Groups", describe
how to work with groups of permutations, and "Group Theory Algorithms" shows how to extract information from them
without listing all elements of the group.
Representation of a Permutation
Cycles
PermutationCyclesQ
validate a permutation
Representation of a permutation.
The disjoint cyclic representation of a permutation has the form Cycles @8cyc1 , cyc2 , <D in Mathematica, where the
cycles cyci are disjoint lists of positive integers. Integers are mapped under the permutation to their right neighbors, and
the last integer of a cycle is mapped to the first member of that cycle. Integers not present in the cycles are mapped onto
themselves, though they could also appear in cycles of length 1, which are called singletons or fixed points. The ordering
of cycles is immaterial, and individual cycles can be rotated without changing the permutation. Permutations are automatically canonicalized so that the smallest integer of each cycle comes first, and then cycles are sorted by their first integer.
This is a permutation with two cycles 3 8 5 3 and 6 1 6.
In[1]:=
Out[1]=
This represents the same permutation. Singletons and empty cycles are removed.
In[2]:=
Out[2]=
Cycles@881, 6<, 82<, 85, 3, 8<, 84<, 87<, 89<, 8<, 810<<D
Out[3]=
Cycles@8<D
With permutations containing explicit lists of numbers, there is automatic syntax checking. In other cases, you can use
the function PermutationCyclesQ to check the syntax.
The cycles must be disjoint.
In[4]:=
Out[4]=
Out[5]=
Cycles::pospoint : Cycles@881, 0<, 8-2, 3<<D contains integers that are not positive.
1
2
>>F
Out[7]=
True
Cycles::pospoint : Cycles@881, 2<, 80, 3<<D contains integers that are not positive.
Out[8]=
False
In[9]:=
Out[9]=
False
In[10]:=
PermutationCyclesQ@Cycles@8cycle1, cycle2<DD
Out[10]=
False
If a permutation perm maps the integer p to the integer q, then q is called the image of p under the permutation perm.
Images are computed with the function PermutationReplace .
PermutationReplace
Out[11]=
81, 3, 4, 2, 5, 6<
The standard action of permutations can be extended to other objects, like other permutations or arrays of integers or
permutations.
Map integers of the first permutation under the second permutation (conjugation).
In[13]:=
Out[13]=
Permutations are not assumed to belong to any particular finite group, not even a particular symmetric group of some
degree. However, there is the concept of support, defined as the set of integers moved by the permutation, which better
describes where a permutation acts naturally.
PermutationSupport
PermutationLength
PermutationMax
PermutationMin
In[15]:=
Out[15]=
In[16]:=
PermutationLength@permD
Out[16]=
PermutationMax@permD
Out[17]=
55
PermutationMin@permD
Out[18]=
RandomPermutation
Generate a random permutation moving (perhaps not all) integers 81, , 15<.
In[19]:=
Out[19]=
SeedRandom@1234D; RandomPermutation@15D
SeedRandom@1234D; RandomPermutation@AlternatingGroup@7D, 5D
Permute
FindPermutation
8z, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, a<
In[24]:=
Permute@expr, permD
Out[24]=
f@u, x, v, w, y, zD
The same result can be obtained using a permutation list representation and the function Part .
In[25]:=
Out[25]=
permlist = PermutationList@perm, 6D
81, 3, 4, 2, 5, 6<
In[26]:=
expr@@Ordering permlistDD
Out[26]=
f@u, x, v, w, y, zD
In[27]:=
Out[27]=
True
However, the length of the permutation list must match that of the expression.
In[28]:=
Out[29]=
f@a, d, b, c, e, f, g, hD
In[30]:=
expr@@Ordering permlistDD
Out[30]=
f@a, d, b, c, e, fD
Permute@expr, permlistD
Out[31]=
f@a, d, b, c, e, f, g, hD
Vice versa, given two expressions with the same elements, a permutation linking them can be computed.
In[32]:=
In[34]:=
FindPermutation@expr1, expr2D
Out[34]=
Cycles@882, 3, 4<<D
In[35]:=
Out[35]=
True
FindPermutation@expr2, expr1D
Out[36]=
Cycles@882, 4, 3<<D
With a single argument, FindPermutation returns the permutation that generates an expression from its canonical order.
In[37]:=
FindPermutation@Characters@"Mathematica"DD
Out[37]=
In[38]:=
Permute@Sort Characters@"Mathematica"D, %D
Out[38]=
8M, a, t, h, e, m, a, t, i, c, a<
Product of Permutations
PermutationProduct
InversePermutation
inverse of a permutation
PermutationPower
PermutationOrder
Product of permutations.
There are two possible conventions for the product of two permutations perm1 and perm2 , depending on whether
PermutationProduct @ perm1 , perm2 D means that you first use perm1 and then perm2 (this is called a left-to-right product) or
you first use perm2 and then perm1 (right-to-left product). With the convention of writing images as right neighbors in
cycles, Mathematica's PermutationProduct effectively is a left-to-right product.
The product of permutations is not commutative.
In[39]:=
In[41]:=
PermutationProduct@perm1, perm2D
Out[41]=
Cycles@881, 2, 4<<D
In[42]:=
PermutationProduct@perm2, perm1D
Out[42]=
Cycles@881, 3, 2<<D
PermutationReplace acts from the right, consistent with the left-to-right character of the product.
In[43]:=
Out[43]=
True
In[44]:=
Out[44]=
False
Out[45]=
True
In[46]:=
Out[46]=
False
After the permutation product law has been given, the associated concepts of inversion, power, and order can be immediately defined. For permutations of finite support, the order is always finite.
You can compute inverses of permutations.
In[47]:=
InversePermutation@perm1D
Out[47]=
Cycles@882, 4, 3<<D
In[48]:=
PermutationProduct@perm1, %D
Out[48]=
Cycles@8<D
And you can compute powers of them. Negative powers are powers of the inverse.
In[49]:=
PermutationPower@perm1, 4D
Out[49]=
Cycles@882, 3, 4<<D
In[50]:=
Out[50]=
True
In[51]:=
PermutationPower@perm2, -11D
Out[51]=
In[52]:=
PermutationPower@perm1, 0D
Out[52]=
Cycles@8<D
The order of a permutation is the lowest positive power such that the identity permutation is obtained.
In[53]:=
PermutationOrder@perm1D
Out[53]=
In[54]:=
PermutationPower@perm1, %D
Out[54]=
Cycles@8<D
Another example.
In[55]:=
perm3 = Cycles@
881, 9, 12, 3<, 82, 17, 4, 29, 20, 30, 26, 15, 14<, 88, 10, 16, 13, 27, 25, 22, 28, 23, 19, 24, 18, 11<<D;
In[56]:=
order = PermutationOrder@perm3D
Out[56]=
468
In[57]:=
PermutationPower@perm3, orderD
Out[57]=
Cycles@8<D
This means that (for permutations of finite support) the inverse is always a positive power of the permutation.
In[58]:=
Out[58]=
True
Any two permutations of any degree can always be tested for equality and ordering. This is done by comparing sequentially the images of the integers 1, 2, 3, . The smaller permutation corresponds to smaller images, such that the
identity permutation always comes first. This defines mathematical order. Canonical order follows standard rules, and may
differ from mathematical order.
Take two permutations.
In[59]:=
In[61]:=
PermutationReplace@Range@7D, perm1D
Out[61]=
81, 5, 3, 2, 4, 6, 7<
In[62]:=
PermutationReplace@Range@7D, perm2D
Out[62]=
81, 2, 4, 7, 6, 5, 3<
Permutation perm2 must be sorted before perm1 because its second image is smaller.
In[63]:=
Out[63]=
False
You can sort permutations using mathematical order by using an "ordering function".
In[65]:=
Out[65]=
OrderedQ@%, LessEqualD
Out[66]=
True
In[68]:=
Out[68]=
True
In[69]:=
Out[69]=
Cycles@8<D
A permutation is a derangement of degree n if all integers 81, , n< are moved.
In[70]:=
In[71]:=
Out[71]=
True
In[72]:=
permutationDerangementQ@Cycles@881, 2, 4, 5<<D, 5D
Out[72]=
False
In[74]:=
circularPermutationQ@Cycles@881, 5, 3, 2, 6, 4<<D, 6D
Out[74]=
True
In[75]:=
Out[75]=
False
From the cyclic notation of a permutation it is also simple to construct a decomposition into transpositions, that is, permutations with a single cycle of length 2.
These functions construct a list of transpositions whose product is the original permutation.
In[76]:=
In[78]:=
In[79]:=
toTranspositions@permD
Out[79]=
8Cycles@881, 2<<D, Cycles@881, 5<<D, Cycles@883, 7<<D, Cycles@886, 8<<D, Cycles@886, 10<<D<
In[80]:=
perm == PermutationProduct %
Out[80]=
True
Such decomposition into transpositions is not unique, but the parity (even or odd) of the number of transpositions is invariant.
This is called the signature of the permutation.
In[81]:=
In[82]:=
permutationSignature@Cycles@884, 3, 5, 2, 1<<DD
Out[82]=
In[83]:=
Out[83]=
-1
The previous example permutation perm was decomposed into five transpositions, an odd number. Hence it has signature -1.
In[84]:=
permutationSignature@permD
Out[84]=
-1
Related Tutorials
Permutation Lists
Permutation Groups
10