polymerist.maths.combinatorics.permutations
Utilites for representing pure permutations, cycles, and permutation groups
Attributes
Classes
For representing a cyclic collection of objects |
|
For representing a permutation |
Module Contents
- polymerist.maths.combinatorics.permutations.T
- class polymerist.maths.combinatorics.permutations.Cycle[source]
Bases:
tupleFor representing a cyclic collection of objects
- starting_from_index(index: int) Cycle[source]
Return a Cycle which is in the same order as self but begins at the given index
- property mapping: dict[T, T]
A mapping of each item in the cycle to the following item
- static max_elem_in_cycles(cycles: Iterable[Cycle]) int[source]
Returns the largest element across a collection of Cycles
- static cycles_are_disjoint(cycles: Iterable[Cycle]) bool[source]
Check if a cycle decomposition is disjoint
- static cycles_produce_partition(cycles: Iterable[Cycle]) bool[source]
Check if a cycle decomposition forms a partition of some set of integers
- class polymerist.maths.combinatorics.permutations.Permutation(*elems: Sequence[int])[source]
For representing a permutation
- elems: Sequence[int] = []
- property degree: int
- property element_set: set[int]
- classmethod from_degree(degree: int, random: bool = False) Permutation[source]
Construct a permutation of the given degree. Is just the identity by default, but can be made random with the “random” flag
- classmethod identity(degree: int) Permutation[source]
Construct the Identity permutation of a given degree
- property natural_order: list[int]
- property as_identity: Permutation
The identity permutation with the same degree as the current permutation
- property inverse: Permutation
The permutation which, when composed with this permutation from either the left or the right, yields the identity permutation
- property reverse: Permutation
The reversed-order of a permutation
- copy() Permutation[source]
Create a copy of the current Permutation
- image(coll: Iterable[T]) Iterable[T][source]
The image of an ordered collection under the defined permutation
- compose
- property order: int
Smallest power of a permutation which generates the identity permutation
- classmethod from_matrix(matrix: numpy.ndarray) Permutation[source]
Create a permutation from a permutation matrix
- property matrix: numpy.ndarray
- classmethod from_word(word: str, delimiter: str = '') Permutation[source]
Create a permutation from a string with a total ordering
- classmethod from_cycle(cycle: Cycle, degree: int | None = None) None[source]
Create a permutation from an ordering of elements in a single cycle. Missing elements are inferred to be fixed points
- classmethod from_cycles(cycles: list[Cycle]) Permutation[source]
Stitch together Permutation from disjoint cycle representation
- to_cycles(canonicalize: bool = True) list[Cycle][source]
Produce cycle decompositon of permutation. NOT TO BE CONFUSED WITH Permutation.as_cycles()! By default, returns in canonical order (i.e. each cycle is presented with the least element first)
- property cycles: list[Cycle]
Cycle decompositon of permutation in the order that elements appear (i.e. NOT in canonical order)
- property cycles_canonical: list[Cycle]
Cycle decompositon of permutation in canonical order (largest element) first in each cycle and)
- property cycle_type: dict[int, int]
Returns a dict of cycle lengths and the number of cycle in the permutation with that length
- classmethod from_lehmer(lehmer_code: Sequence[int]) Permutation[source]
Stitch together permutation from an inversion vector
- to_lehmer_code() list[int][source]
Construct the left lehmer code for a permutation Each position in the code gives the number of inversions to the right of the permutation element at the corresponding position
- property lehmer_code: list[int]
- property num_inversions: int
Get total number of “out-of-order” elements in the permutation
- property sign: int
The parity of the number of inversion of a permutation
- parity
- property is_even: bool
- property is_odd: bool
- property ascents: list[int]
The positions of elements which are followed by a greater element
- property num_ascents: int
The number of elements which are followed by a greater element
- property descents: list[int]
The positions of elements which are followed by a lesser element
- property num_descents: int
The number of elements which are followed by a lesser element
- property support: list[int]
The positions of elemnts which do not map to themselves
- property support_size: int
The number of elements in the permutation which do not map to themselves
- static cycle_index(perm_group: Iterable[Permutation], variable: str = 'x', add_sym: str = ' + ', mul_sym: str = '*', exp_sym: str = '^') str[source]
Construct a string of the cycle index of a permutation group
- classmethod symmetric_group(order: int) Generator[Permutation, None, None][source]
Generate all permutations of a given order
- classmethod alternating_group(order: int) Generator[Permutation, None, None][source]
Generate all even permutations of a given order
- classmethod cyclic_group(order: int, _base_perm: Permutation | None = None) Generator[Permutation, None, None][source]
Generate all cyclic shifts of a given permutation of a given order
- classmethod dihedral_group(order: int) Generator[Permutation, None, None][source]
Generate all permutations of vertex-numbered regular polygon