Deterministic Generation#
Symmetria provides a way to generate all the permutations of a given degree. The generation follows different algorithms which can be specified.
You can use the generator of permutations in the following way
import symmetria
permutations = symmetria.generate(algorithm="lexicographic", degree=3)
A list of implemented algorithms to generate permutations:
Algorithm |
Description |
Reference |
|---|---|---|
|
The permutations are generate following the lexicographic order. |
|
|
The permutations are generate following the Heap’s algorithm. |
|
|
The permutations are generate following the Steinhaus-Johnson-Trotter algorithm. |
The API of the method is given as following:
- symmetria.generators.algorithm.api.generate(degree: int, algorithm: str = 'lexicographic') Generator[Permutation, None, None][source]#
Generate all the permutations of the given degree based on the chosen algorithm.
The method generates all the permutations of the given degree using the specified algorithm.
- Parameters:
degree (int) – The degree of the permutations to be generated. Must be a non-zero positive integer.
algorithm (str, optional) – The algorithm to use for generating permutations. It must be one of:
lexicographic,heap. Default islexicographic.
- Returns:
A generator yielding permutations.
- Return type:
Generator[“Permutation”, None, None]
- Raises:
ValueError – If the algorithm is not supported or the degree is invalid.
- Examples:
>>> import symmetria ... >>> permutations = symmetria.generate(degree=3, algorithm="lexicographic") >>> for permutation in permutations: ... permutation Permutation(1, 2, 3) Permutation(1, 3, 2) Permutation(2, 1, 3) Permutation(2, 3, 1) Permutation(3, 1, 2) Permutation(3, 2, 1)