# 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 the Wolfram Language, 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 the Wolfram Language, 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.

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.

## 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.

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

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.

RandomPermutation | generate pseudorandom permutations |

Random generation of permutations.

## 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[22]:= |

In[32]:= |

## 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, the Wolfram Language's PermutationProduct effectively is a left-to-right product.

In[39]:= |

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[55]:= |

## Equality and Sorting of Permutations

As is standard in the Wolfram Language, 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]:= |

## 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[70]:= |

In[73]:= |

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]:= |

*signature*of the permutation.

In[81]:= |