Permutation Generator

Permutation Generator#

To use the generator of permutation, import it as

from symmetria import permutation_generator

The API of the method is given as following:

symmetria.permutation_generator(degree: int, algorithm: str = 'lexicographic') Generator[Permutation, None, None][source]#

Generate all the permutations of the 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. 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.

# Activate once we have the lexicographic algorithm #:examples:

# >>> from symmetria import permutation_generator # … # >>> permutations = permutation_generator(degree=3, algorithm=”lexicographic”) # >>> for perm in permutations: # … print(perm) # Permutation(1, 2, 3) # Permutation(1, 3, 2) # Permutation(2, 1, 3) …