music.InterestingPermutations¶
- class music.InterestingPermutations(nelements=4, method='dimino')[source]¶
Bases:
objectGet permutations of n elements in meaningful sequences. Mirrors are ordered by swaps (0,n-1…).
- Parameters:
- nelements
integer 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.
- method
str The generation method handed to sympy’s group
generate():"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.
- nelements
Methods
Generates permutations in the alternating group.
Generates rotations of permutations.
Generates mirror permutations.
Generates swap permutations.
even_odd(sequence)Determines if a permutation is even or odd.
Generates permutations with full symmetry.
- Raises:
ValueErrorIf nelements is less than two, or method is neither of the two sympy generates by. One element has no swaps, mirrors or second rotation, and failed inside sympy; an unknown method failed there as
NotImplementedError.
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']
Methods
__init__([nelements, method])even_odd(sequence)Determines if a permutation is even or odd.
Generates permutations in the alternating group.
Generates permutations with full symmetry.
Generates mirror permutations.
Generates rotations of permutations.
Generates swap permutations.
Attributes
- 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:
- sequence
list The sequence of elements representing the permutation.
- sequence
- Returns:
strEither ‘even’ or ‘odd’ indicating the parity of the permutation.
- Raises:
ValueErrorIf sequence is not a permutation of
0ton - 1. A repeated entry used to be read as a cycle, so[1, 1]was ‘odd’.