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

Core reference: - http://www.gutenberg.org/files/18567/18567-h/18567-h.htm

Also check peal rules, such as conditions for trueness. - Wikipedia seemed ok last time.

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

permutations_by_sizes

permutations

neighbor_swaps

swaps_by_stepsizes

swaps_as_comes

swaps

rotations

mirrors

dihedral

peals

name -> list of permutations.

acted_peals

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