Euclidean Rhythms is a method to generate rhythmic patterns which gives the most even way to distribute k onsets over n of beats with k < n. It was first discovered in 2004 by Godfried Toussaint [1] who described how these rhythms are found in music all over the world and presented an algorithm by Björklund [2] to generate the rhythms. There is also nice presentation of the math in [3]. All algorithms, including mine, relies on the Euclidean Algorithm, hence the name.
Toussaint’s paper is very interesting but I found the description of Björklunds algorithm a bit confusing. Looking at the the C code from Björklunds original paper is a bit better, but I think it lacks some modularity it doesn’t really explain why the algorithm works.
Here, I present an algorithm to compute Euclidean Rhythms using continued fractions and morphic words. Using these concepts, the algorithm becomes very simple, and it has the added benefit that it works not only for integers n and k but for any real numbers. It is equivalent to Björklunds algorithm but is much simpler in my opinion.
Euclidean Rhythm
We represent a rhythmic pattern as a finite sequence of 0’s and 1’s where 1 is an onset and 0 is a rest. So the first half of a classic clave pattern (which can be computed as an Euclidean Rhythm with k=3 and n=8) is written as 10010010.
Generating an Euclidean Rhythm for k onsets over n of beats can be done using a cutting sequences for a straight line with slope k / n. This means that we can define the i‘th element in the sequence as
s_i = \left\lfloor \frac{(i+1)k}{n} \right\rfloor - \left\lfloor \frac{ik}{n} \right\rfloor.This gives a geometric interpretation of Euclidean Rhythms: The goal is to distribute the onsets as evenly as possible among the beats. Note that if you use this in the example with k=3 and n=8 we get when starting from i = 0 the sequence 01001010 which is a rotation of the desired result, and we will say sequences that are equal up to rotation are equivalent.
Prerequisites
We define the rhythmic pattern as a morphic word using a family of endomorphisms:
\theta_a(x) = \begin{cases} 0^{a-1}1 & \text{if } x = 0, \\ 0^{a-1}10 & \text{if } x = 1.
\end{cases}Note that since these are endomorphisms, they define a mapping on a word by using them on one letter at a time. So, e.g.,
\theta_2(101) = \theta_2(1) \theta_2(0) \theta_2(1) = 01001010.
Recall that a (simple) continued fraction is a representation of a real number,
a = a_0 + \frac{1}{a_1 + {\frac{1}{a_2 + \frac{1}{a_3 + \cdots}}}}which is written a = [a_0; a_1, a_2, \ldots]. All numbers has a representation as a continued fraction, and the representation is finite if and only if it represents a rational numbers. Computing the continued fraction of a rational number is equivalent to the Euclidean Algorithm on the numerator and denominator.
The algorithm
Using these two concepts, we can define a very simple algorithm for generating an Euclidean Rhythm:
- Write \frac{k}{n} = [0; a_1, a_2, \ldots, a_m] as a continued fraction,
- Return \theta_{a_m} \circ \theta_{a_{m-1}} \circ \ldots \circ \theta_{a_1} (0).
We assume that n and k are coprime – otherwise we can reduce and simply repeat the pattern.
For the example above with k = 3 and n = 8, we get that \frac{3}{8} = [0; 2, 1, 2], so we get the Euclidean Rhythm using the morphisms in order as
0 \overset{\theta_2}{\rightarrow} 01 \overset{\theta_1}{\rightarrow} 110 \overset{\theta_2}{\rightarrow} 01001001which is a rotation of the sequence we found above.
Non-rational patterns — a Golden rhythm
Since any number has a continued fraction representation, the above algorithm also makes sense if \frac{k}{n} is not rational. The musical interpretation of this is not as clear since it requires an infinite number of beats, but the recurrent nature of the algorithm may give a hint to what is going on.
Consider the inverse golden ratio which has continued fraction representation
\frac{-1 + \sqrt{5}}{2} = [0; 1,1,\ldots].Since this has an infinite continued fraction expansion the above algorithm wont work directly, but if we set some limit, say m, and considers only the first m terms it gives a rational approximation which gets better as m grows. This approximation will be equal to the Euclidean Rhythm which distributes F_{m-1} onsets over F_m beats where F_m is the m‘th Fibonacci number, and will be equal to the prefix of length F_{m} of the Fibonacci word.
Source code
I have written some code in Rust which tests the equivalence of constructing Euclidean Rhythms as cutting sequences, from Björklunds Algorithm and using my algorithm.
References
[1] https://cgm.cs.mcgill.ca/~godfried/publications/banff.pdf
[2] https://www.semanticscholar.org/paper/The-Theory-of-Rep-Rate-Pattern-Generation-in-the-Bjorklund/c652d0a32895afc5d50b6527447824c31a553659
[3] https://erikdemaine.org/papers/DeepRhythms_CGTA/paper.pdf









