music.InterestingPermutations

class music.InterestingPermutations(nelements=4, method='dimino')[source]

Bases: object

Get permutations of n elements in meaningful sequences. Mirrors are ordered by swaps (0,n-1…).

Parameters:
nelementsinteger

How many elements are permuted. Every group generated here – symmetric, alternating, cyclic, dihedral – is the group on this many elements, so it also sets how many permutations there are.

methodstr

The generation method handed to sympy’s group generate(), such as "dimino" or "coset". It changes the order the permutations come out in, which is the sequence this class exists to make meaningful, and not which permutations they are.

Methods

get_alternating()

Generates permutations in the alternating group.

get_rotations()

Generates rotations of permutations.

get_mirrors()

Generates mirror permutations.

get_swaps()

Generates swap permutations.

even_odd(sequence)

Determines if a permutation is even or odd.

get_full_symmetry()

Generates permutations with full symmetry.

Examples

>>> structures = InterestingPermutations(nelements=4)
>>> len(structures.rotations), len(structures.dihedral)
(4, 8)
>>> rows = [p(list("abcd")) for p in structures.rotations]
>>> ["".join(row) for row in rows]
['abcd', 'bcda', 'cdab', 'dabc']
__init__(nelements=4, method='dimino')[source]

Methods

__init__([nelements, method])

even_odd(sequence)

Determines if a permutation is even or odd.

get_alternating()

Generates permutations in the alternating group.

get_full_symmetry()

Generates permutations with full symmetry.

get_mirrors()

Generates mirror permutations.

get_rotations()

Generates rotations of permutations.

get_swaps()

Generates swap permutations.

Attributes

permutations_by_sizes: list
permutations: list
neighbor_swaps: list
swaps_by_stepsizes: list
swaps_as_comes: list
swaps: list
rotations: list
mirrors: list
dihedral: list
get_alternating()[source]

Generates permutations in the alternating group.

This method generates permutations in the alternating group of the specified size using the provided generation method.

get_rotations()[source]

Generates rotations of permutations.

This method generates rotations of permutations of the specified size using the provided generation method.

get_mirrors()[source]

Generates mirror permutations.

This method generates mirror permutations of the specified size using the provided generation method.

get_swaps()[source]

Generates swap permutations.

This method generates swap permutations of the specified size using the provided generation method.

even_odd(sequence)[source]

Determines if a permutation is even or odd.

This method determines if a given permutation is even or odd based on its sequence of elements.

Parameters:
sequencelist

The sequence of elements representing the permutation.

Returns:
str

Either ‘even’ or ‘odd’ indicating the parity of the permutation.

get_full_symmetry()[source]

Generates permutations with full symmetry.

This method generates permutations with full symmetry of the specified size using the provided generation method.