Class Permutation.CanonicalForm
- All Implemented Interfaces:
Serializable
- Enclosing class:
Permutation
The canonical form consists of a sequence of sequences of integers:
- Each subsequence specifies a cycle, starting with the highest member.
- The outer sequence is ordered ascendingly by starting members.
- Trivial cycles that contain only one element are omitted.
These rules ensure that the canonical form is finite and uniquely determined.
The permutation can be reconstructed from the canonical form; the
following expression is equivalent to p:
p.canonicalForm().stream()
.map(Permutation::cycle)
.reduce(Permutation.identity(), Permutation::compose)
Several algebraic operations on permutations are algorithmically easier on their canonical forms. Therefore canonical forms may be computed internally as a preliminary step.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleaninthashCode()voidshuffle(int[] seq) Permutes the elements of a sequence according to this canonical form.voidPermutes the elements of a sequence according to this canonical form.<E> voidPermutes the elements of a sequence according to this canonical form.sqrt()Finds some canonical form that composed with itself is equivalent to this canonical form.Stream<int[]> stream()Returns a stream of integer sequences representing the cycles of this canonical form.toString()
-
Constructor Details
-
CanonicalForm
CanonicalForm(int[][] cycles) Creates a new instance. Do not call this constructor directly!- Parameters:
cycles- the ordered sequence of nontrivial cycles
-
-
Method Details
-
equals
-
hashCode
public int hashCode() -
toString
-
stream
Returns a stream of integer sequences representing the cycles of this canonical form.The elements of the stream are copies of the internal data structures of this object; subsequent modifications by the caller have no effect on the internal state of the canonical form.
- Returns:
- a stream of cycles
-
shuffle
Permutes the elements of a sequence according to this canonical form.The element at each index
iis moved to indexget(i).- Parameters:
seq- the sequence to permute- Throws:
NullPointerException- ifseqis null- See Also:
-
shuffle
public void shuffle(int[] seq) Permutes the elements of a sequence according to this canonical form.The element at each index
iis moved to indexget(i).- Parameters:
seq- the sequence to permute- Throws:
NullPointerException- ifseqis null- See Also:
-
shuffle
Permutes the elements of a sequence according to this canonical form.The element at each index
iis moved to indexget(i).- Type Parameters:
E- the element type- Parameters:
seq- the sequence to permute- Throws:
NullPointerException- ifseqis null- See Also:
-
sqrt
Finds some canonical form that composed with itself is equivalent to this canonical form.The implemented algorithm is stable; for equivalent canonical forms, equivalent results are obtained always. It is also complete; if there are any solutions, one will be found. It is not unique; if there are several solutions, only a single, arbitrary one is found.
- Returns:
- some canonical form that composed with itself is equivalent to
this canonical form; or
Optional.empty()if none exists.
-