# Permutations

Representation of a Permutation | Product of Permutations |

Permutation Action and Support | Equality and Sorting of Permutations |

Permute Parts of an Expression | Special Types 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 elements is , and therefore for a moderate number there are already permutations, which is almost .

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 | head denoting a permutation in disjoint cyclic form |

PermutationCyclesQ | validate a permutation |

Representation of a permutation.

The disjoint cyclic representation of a permutation has the form Cycles[{cyc_{1}, cyc_{2}, ...}] in *Mathematica*, where the cycles 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.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

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.

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]= |

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

In[9]:= |

Out[9]= |

In[10]:= |

Out[10]= |

## Permutation Action and Support

If a permutation perm maps the integer to the integer , then is called the image of under the permutation perm. Images are computed with the function PermutationReplace.

PermutationReplace | image of an integer under a permutation |

Standard action of permutations on other expressions.

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]= |

The standard action of permutations can be extended to other objects, like other permutations or arrays of integers or permutations.

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 | set of integers moved by a permutation |

PermutationLength | number of integers moved by a permutation |

PermutationMax | largest integer moved by a permutation |

PermutationMin | smallest integer moved by a permutation |

Permutation support functions.

In[14]:= |

Out[14]= |

In[15]:= |

Out[15]= |

In[16]:= |

Out[16]= |

In[17]:= |

Out[17]= |

In[18]:= |

Out[18]= |

RandomPermutation | generate pseudorandom permutations |

Random generation of permutations.

In[19]:= |

Out[19]= |

In[20]:= |

Out[20]= |

## Permute Parts of an Expression

Permutations can be used to permute the parts of other expressions with the function Permute. Integer being mapped to integer is interpreted as part being moved to part . Permute never changes the number of elements of an expression, it simply reorders them.

Permute | permute parts of an expression |

FindPermutation | return permutation linking two expressions with the same elements |

Reordering under a permutation.

In[21]:= |

Out[21]= |

In[22]:= |

In[24]:= |

Out[24]= |

In[25]:= |

Out[25]= |

In[26]:= |

Out[26]= |

In[27]:= |

Out[27]= |

In[28]:= |

Out[29]= |

In[30]:= |

Out[30]= |

In[31]:= |

Out[31]= |

In[32]:= |

In[34]:= |

Out[34]= |

In[35]:= |

Out[35]= |

In[36]:= |

Out[36]= |

In[37]:= |

Out[37]= |

In[38]:= |

Out[38]= |

## Product of Permutations

PermutationProduct | product of permutations (non-commutative) |

InversePermutation | inverse of a permutation |

PermutationPower | integer power (product with itself or inverse) of a permutation |

PermutationOrder | lowest positive power of a permutation yielding the identity |

There are two possible conventions for the product of two permutations and , depending on whether PermutationProduct[perm_{1}, perm_{2}] means that you first use and then (this is called a left-to-right product) or you first use and then (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.

In[39]:= |

In[41]:= |

Out[41]= |

In[42]:= |

Out[42]= |

In[43]:= |

Out[43]= |

In[44]:= |

Out[44]= |

In[45]:= |

Out[45]= |

In[46]:= |

Out[46]= |

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.

In[47]:= |

Out[47]= |

In[48]:= |

Out[48]= |

In[49]:= |

Out[49]= |

In[50]:= |

Out[50]= |

In[51]:= |

Out[51]= |

In[52]:= |

Out[52]= |

In[53]:= |

Out[53]= |

In[54]:= |

Out[54]= |

In[55]:= |

In[56]:= |

Out[56]= |

In[57]:= |

Out[57]= |

In[58]:= |

Out[58]= |

## Equality and Sorting of Permutations

As is standard in *Mathematica*, there are two types of equality tests: structural equality (SameQ) and mathematical equality (Equal). The former can compare any two expressions, but the latter will only return True or False when comparing mathematical expressions with the same type of value. The same happens when ordering expressions: there is structural (*canonical*) order, implemented through Order and OrderedQ, and there is mathematical order, given by Less and related functions.

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.

In[59]:= |

In[61]:= |

Out[61]= |

In[62]:= |

Out[62]= |

In[63]:= |

Out[63]= |

In[64]:= |

Out[64]= |

In[65]:= |

Out[65]= |

In[66]:= |

Out[66]= |

## Special Types of Permutations

There are special types of permutations. In many cases the cyclic notation allows simple constructions to detect them.

In[67]:= |

In[68]:= |

Out[68]= |

In[69]:= |

Out[69]= |

In[70]:= |

In[71]:= |

Out[71]= |

In[72]:= |

Out[72]= |

In[73]:= |

In[74]:= |

Out[74]= |

In[75]:= |

Out[75]= |

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.

In[76]:= |

In[78]:= |

In[79]:= |

Out[79]= |

In[80]:= |

Out[80]= |

*signature*of the permutation.

In[81]:= |

In[82]:= |

Out[82]= |

In[83]:= |

Out[83]= |

In[84]:= |

Out[84]= |