music.Peals

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

Bases: InterestingPermutations, GenericPeal

Uses permutations to make peals and represents peals as permutations.

Holds peals by name, which is the model GenericPeal provides act and act_all for – act("some_peal", domain). That is a different operation from PlainChanges.act(), which acts the one peal the object was built from and takes the domain first.

Notes

The peals are rung as Tintinnalogia describes them [1], and each method’s notes say how the tests check them against its tables. A peal here is the rule that rings it rather than a check of its truth: a peal is true when no row repeats, which the tests check of each.

References

[1]

Duckworth, Richard, and Fabian Stedman. Tintinnalogia, or, The Art of Ringing, 1668. https://www.gutenberg.org/files/18567/18567-h/18567-h.htm

Examples

>>> peals = Peals(nelements=4)
>>> len(peals.twenty_all_over())   # twelve rows on four bells
12
__init__(nelements=4, method='dimino')[source]

Initializes a Peals object.

Parameters:
nelementsint, optional

How many elements the permutations act on, by default 4. This also sizes the default domain that act and act_all build.

methodstr, optional

The generation method passed to InterestingPermutations.

Methods

__init__([nelements, method])

Initializes a Peals object.

act(peal[, domain])

Acts a specific peal on the specified domain.

act_all([domain])

Acts all peals on the specified domain.

an_eight_and_forty([peal_name])

Ring An Eight and Forty, on five bells.

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.

transpositions_peal(permutation[, peal_name])

Generates a peal from transpositions of a permutation.

twenty_all_over([peal_name])

Ring the Twenty All Over.

Attributes

peals: dict

name -> list of permutations. Empty rather than None: a collection with nothing in it is what an unpopulated one is, and act() refuses to run on either.

transpositions_peal(permutation, peal_name='transposition_peal')[source]

Generates a peal from transpositions of a permutation.

Parameters:
permutationPermutation

The permutation to generate transpositions from.

peal_namestr, optional

The name of the peal. Defaults to “transposition_peal”.

Returns:
list

The transpositions, as permutations over the same domain.

Notes

sympy’s transpositions() yields index pairs, which are cycle notation rather than array form: Permutation((0, 1)) is the identity and Permutation((0, 2)) raises. The pairs are expanded with the original size, so composing them in reverse rebuilds the permutation they came from.

twenty_all_over(peal_name='twenty_all_over')[source]

Ring the Twenty All Over.

Every bell hunts up in turn, from the lead to behind the others, and the bell that inherits the lead hunts next. On five bells that is the twenty changes the peal is named for, and they bring the bells back into rounds [1]:

“every Bell hunts in order once through the Bells, until it comes behind them; and first the Treble hunts up, next the Second, and then the 3, 4 and 5, which brings the Bells round in their right places again, at the end of the Twenty Changes.”

Parameters:
peal_namestr

The key to store the peal under in peals.

Returns:
list of Permutation

One permutation per row, from rounds onwards. The closing change back into rounds is implied rather than stored, as it is for music.PlainChanges.

Notes

The rule holds for any number of bells, and the twenty is what it comes to on five: each of the n bells takes n - 1 changes to hunt from the lead to the back, so the peal is n * (n - 1) changes long and every row of it is distinct. The name is the five-bell case, which is the one Tintinnalogia prints and the one the tests check row for row.

References

[1]

Duckworth, Richard, and Fabian Stedman. Tintinnalogia, or, The Art of Ringing, 1668. https://www.gutenberg.org/files/18567/18567-h/18567-h.htm

Examples

>>> peal = Peals(nelements=5).twenty_all_over()
>>> len(peal)
20
an_eight_and_forty(peal_name='an_eight_and_forty')[source]

Ring An Eight and Forty, on five bells.

The fifth and the fourth are both whole hunts. They take turns hunting down to the lead and back up to the back, and each time one of them lies at the lead a single change is made among the other three, which run the six changes between them [1]:

“the Fifth and Fourth are both whole Hunts, each of which does hunt down before the Bells by turns, and lies there twice together and then hunts up again: The 1, 2 and 3 goes the six changes, one of which is made every time, either of the whole Hunts lies before the Bells.”

Six changes among three bells, one for each visit to the lead, with seven hunting changes between one visit and the next: forty eight changes, and back into rounds.

Parameters:
peal_namestr

The key to store the peal under in peals.

Returns:
list of Permutation

One permutation per row, from rounds onwards, forty eight of them. The closing change back into rounds is implied.

Raises:
ValueError

If this object was not built for five bells. Unlike twenty_all_over(), this is a composition for a particular number of bells rather than a rule that holds for any: the two whole hunts and the three bells ringing the six changes between them are five, and the forty eight is what that arrangement comes to.

Notes

The three bells that are not hunts ring the plain changes on three, which is why the six changes are the same six music.PlainChanges produces for that many elements.

The implementation is the rule above rather than the table, and the test checks that it reproduces Tintinnalogia’s forty eight rows exactly, in order.

References

[1]

Duckworth, Richard, and Fabian Stedman. Tintinnalogia, or, The Art of Ringing, 1668. https://www.gutenberg.org/files/18567/18567-h/18567-h.htm

Examples

>>> peal = Peals(nelements=5).an_eight_and_forty()
>>> len(peal)
48
act(peal, domain=None)

Acts a specific peal on the specified domain.

Parameters:
pealstr

The name of the peal to act.

domainlist, optional

The domain on which to act the peal. Defaults to None.

Returns:
list

The result of acting the peal on the specified domain.

Raises:
ValueError

If no peals are defined, no domain is given and nelements is not set, or the domain’s length is not the number of elements the peal permutes.

KeyError

If no peal goes by peal.

act_all(domain=None)

Acts all peals on the specified domain.

Parameters:
domainlist, optional

The domain on which to act the peals. Defaults to None.

Raises:
ValueError

As act() raises it.

even_odd(sequence)

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.

Raises:
ValueError

If sequence is not a permutation of 0 to n - 1. A repeated entry used to be read as a cycle, so [1, 1] was ‘odd’.

get_alternating()

Generates permutations in the alternating group.

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

get_full_symmetry()

Generates permutations with full symmetry.

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

get_mirrors()

Generates mirror permutations.

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

get_rotations()

Generates rotations of permutations.

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

get_swaps()

Generates swap permutations.

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

permutations_by_sizes: list
permutations: list
alternations: list
alternations_complement: list
alternations_by_sizes: list
neighbor_swaps: list
swaps_by_stepsizes: list
swaps_as_comes: list
swaps: list
rotations: list
mirrors: list
dihedral: list
acted_peals: dict