Following from my previous post, here’s another surprising crossover between maths and music. Did you know that some composers use number theory to write music? We can think of a rhythm as notes distributed in a measure of fixed length. We’ll ignore syncopation for the sake of simplicity. For example, in a measure of 4/4 time, there are four positions in which a crotchet could be written (or a quarter note for my fellow Americans). I claim it’s possible to determine a rhythm by using the Euclidean algorithm. The main idea is that equally distributing notes in a measure is equivalent to finding the gcd of the length of the measure and the number of notes (not rests).

Now, if you accept my premise that musical application of Euclid is **possible**, it would still be fair to ask whether the results are **worth listening to**. This is a subjective question, and personally I would lean towards “yes”. However, I am not alone in the sentiment. It turns out that many of these *Euclidean rhythms* have been part of traditional music for hundreds of years. Whether or not the traditional rhythms are considered to be mathematical in their home cultures is far outside the scope of this post.

In 2005, Godfried Toussaint wrote a survey of Euclidean rhythms as they appear in Cuban, Persian, South African, and Turkish music, to name a few. Since then, the concept has found popularity composer’s circles, particularly the experimental and electronic groups I dabble in.

## How to Write a Euclidean Rhythm

Toussaint describes an algorithm for producing Euclidean rhythms in his paper. This method looks the most like Euclid; the algorithm recursively allocates blocks of notes and rests until the remainder goes to zero. It was originally developed by E. Bjorklund to solve a problem in control systems theory. There, the goal is to evenly space events in a discrete time setting. For example, a circuit may need to be activated five out of every nine clock ticks, spaced as equally as possible to minimise wear and tear.

The Wikipedia article on Euclidean rhythms notes that another algorithm, Bresenham’s line-drawing algorithm, produces equivalent results. Both of these methods have publicly available pseudocode, but I find them to be opaque. Instead, I’d like to offer an approach involving permutation descents that I cooked up while trying to understand Bresenham’s algorithm.

## Residue Sequences

Recall that in permutation theory, an *ascent* is an adjacent pair of permutation entries with the property that . Likewise, a *descent* satisfies the inequality

Here is my method. Given a length and a number of notes to place, construct the sequence . This arithmetic sequence begins at and consists of terms.

Next, reduce these integers modulo to their representatives in the set . This gives a sequence of integers. That is, we have adjacent pairs to work with. Read left to right, each adjacent pair corresponds to a position in a measure of music beats long. To produce the rhythm, place a note in a position whenever the corresponding pair is a descent.

For example, if and , the residue sequence is , and the rhythm is ♩_♩_♩_♩_♩. This is exactly the Euclidean rhythm E(5,9) as documented here. (It is standard to treat rhythms as a cycles in this context, so that rotating the starting point does not change the rhythm.)

## Under the Hood

Why does this work? I have a geometrical argument, likely related to the idea that Bresenham had in 1962. Consider a line segment drawn in the plane from to . It has slope . The points along this segment where is an integer have integer coordinates, which exactly reproduce the arithmetic sequence I described above, before reduction. Every crossing between this segment and a horizontal line where is an integer multiple of corresponds to a descent in the reduced sequence, and there are exactly such crossings.

I’ve implemented this algorithm in Python here. There are some other versions of the algorithm in the same directory.

## Question

How does this relate to gcds? Well, consider a rhythm, say ♩__♩__, which is E(2,6). All rhythms can be considered to be periodic. From that point of view, then is equal to the number of occurrences of the minimal period of the Euclidean rhythm E(k,N) in a duration of beats. Here, we verify that . More broadly, there is a way we can extract the results of the extended Euclidean algorithm from the method described above. As a challenge, how would you look at a sequence like and use it find integers and so that ?

Here is a recording of me performing the algorithm with explanations of each step: https://www.youtube.com/watch?v=8-vakfQ-qlk

LikeLike