Deterministic Generation

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:

overview#

Algorithm

Description

Reference

lexicographic

The permutations are generate following the lexicographic order.

[1]

heap

The permutations are generate following the Heap’s algorithm.

[2]

steinhaus-johnson-trotter

The permutations are generate following the Steinhaus-Johnson-Trotter algorithm.

[3]

zaks

The permutations are generate following the Zaks algorithm.

[4]


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.

Warning:

This function will be deprecated in a future version. Use ‘permutation_generator’ instead.

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 is lexicographic.

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)
symmetria.generators.algorithm.api.permutation_generator(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 is lexicographic.

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:
>>> from symmetria import permutation_generator
...
>>> permutations = permutation_generator(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)