This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Add-ons / Standard Packages / DiscreteMath  /


A permutation is a rule for rearranging a finite collection of elements. In this package, a permutation on elements is represented by a list containing the first positive integers. If the integer is in the place in the list, this means that the permutation moves the element to the place. Thus, for example,

3,1,2 represents the permutation that moves to , to , and to


Working with permutations.

A cyclic permutation or cycle is a permutation in which any element can be moved to any other element by repeated application of the permutation. All permutations are not cycles, but it is a basic fact that any permutation can be decomposed into a product of cycles. This cyclic decomposition is represented as a list containing the cycles as sublists.
Cycles are represented differently than permutations. If the integer follows the integer in the sublist representing the cycle, this means that the cycle moves the element to the element. The sublist is treated cyclically so the last element is thought of as being "before" the first. As an example, {{1,

3,2},{5,4}} represents a permutation containing a cycle that sends to , to and to and a cycle that switches and


  • This loads the package.
  • In[1]:= <<DiscreteMath`Permutations`

  • Here is a randomly chosen permutation of

  • In[2]:= RandomPermutation[10]


  • This is the permutation's cyclic decomposition.
  • In[3]:= ToCycles[%]


  • This transforms the cyclic decomposition back into a permutation.
  • In[4]:= FromCycles[%]


  • To transform the given list into one arranged in numerical order, you need to reverse the order of the elements.
  • In[5]:= Ordering[{4, 3, 2, 1}]