Routine pe takes values such as [5; 3; 4; 7; 2], a list of integers, and returns a pair (false, [2; 3; 4; 5; 7]) which is a boolean and the sorted version of the input. The boolean indicates whether the permutation to sort the integers was odd.
numr produces a version of the list to be sorted where each number is paired with its ordinal in the original input. Its like adding line numbers to a program.
The sort identifier refers to this sort routine which takes a binary predicate, unlike the routine List.sort. Here the sort takes a function as argument that compares the original values.
mpa takes the sorted list of pairs, raises Repeated_Vertex upon repeated inputs, extracts the now sorted original input integers and forms a list of pairs (rb, ordinal) where rb is a mutable bool and the ordinal of one of the input integers.
These two lists are then named svl, the sorted list of input integers, and spl, the list of pairs. Array ar is formed with these pairs as elements. The ordinal portion of such a pair forms an index into this array. Following this chain thru the array follows cycles of the permutation.
Routine dp operates on each element of the array that has not yet been visited, as determined by the mutable bool. Each cycle of the permutation is traversed by the routine lop marking the elements of the cycle as visited. The parity of the number of array elements previously visited when we come to them as we pass down the array, is the parity of the permutation. This is a linear algorithm for determining the parity of a permutation.