Artificial Wasteland — number you can dance to

The Algorithm That Drums

an instrument  ·  Euclid's GCD, run on beats — and out fall the rhythms of the world

An engineer needed a particle accelerator to fire as evenly as possible. The algorithm he wrote was two thousand years old, and it had been keeping time on three continents the whole time.

Companion film — 2:16 The accelerator note that turned out to be Euclid: Bjorklund's 2003 fold (E[i]=1 iff (i·k mod n)<k) shown to be the GCD; the two-gap evenness theorem; six traditional rhythms — tresillo, cinquillo, Râčenica, aksak, bossa clave, the Ewe bell — each ring drawn live by the same bjorklund() the verifier runs; then the turn, E(7,12) played first as a drum, then as the major scale, then both at once. Unlike most companion films, the music here is the mathematics: every drum hit falls on an onset of the necklace E(k,n), and the climax sounds the verified §E identity directly. Every word on screen is one research/euclidean-rhythms/verify.mjs asserts (24/24); cultural attributions are Toussaint's (BRIDGES 2005), cited.

I · A problem in a neutron accelerator

In 2003, an engineer named E. Bjorklund had a small, exact problem at the Spallation Neutron Source. A timing controller had to fire k pulses spread across n available slots, and they had to be spaced as evenly as humanly possible — clump them and you waste the machine. When n divides k it's trivial; lay them down every n/k slots. But 5 pulses in 16 slots? There is no whole gap that works. You need the most even arrangement that isn't regular.

Bjorklund's solution was to take the long run of empty slots and fold it, repeatedly, into the run of full ones — peel the smaller pile off the larger, again and again, until nothing's left to fold. If that sounds familiar, it should. It is Euclid's algorithm for the greatest common divisor — the oldest algorithm we still run, the reciprocal subtraction of the Elements — only here the lengths being measured against each other are counts of beats, not lengths of line. (We check this equivalence below: the divisions Bjorklund performs are exactly Euclid's. verify.mjs, part A.)

And here is the turn that made it more than an accelerator note. Godfried Toussaint, a computational geometer with an ethnomusicologist's ear, ran the algorithm for small k and n and recognised the output. The pattern for 3-in-8 is the Cuban tresillo. The pattern for 5-in-8 is the cinquillo. The one for 7-in-12 is a West African bell line played from Ghana to the diaspora. The most even way to place beats — the thing a machine computes to avoid waste — is, over and over, the thing human cultures independently arrived at and kept. Here is the machine. Turn it on.

the instrument — E(k, n): k beats, n slots, spaced as evenly as possible
Drag beats and slots; the ring re-balances live. Tap a dot to nudge a beat by hand. Sound starts on play.

II · The gallery — the rhythms that fall out

None of these were put in by hand. Each is just E(k,n) for some small pair — the bare output of the evenness algorithm — and each is a rhythm a culture plays. Tap one to load it into the instrument and hear it. (The cultural names and origins are Toussaint's, cited; what we verify is the mathematical half — that each named pattern is, beat-for-beat, a rotation of the Euclidean word. Some traditions start the cycle on a different beat; that is a rotation of the same necklace, and the algorithm fixes the necklace, not where you start counting.)

tap to play — every one is E(k,n), unedited

III · Why these, and not others

What does “as evenly as possible” actually buy you? A clean, provable shape. In any Euclidean rhythm the gaps between consecutive beats take only two values, and they are the two closest whole numbers to the true average n/k — some gaps of ⌊n/k⌋, the rest of ⌈n/k⌉, never anything further out. Five beats in sixteen averages 3.2 slots apart, so you get gaps of only 3 and 4 — three threes and a four — distributed as smoothly as their own little Euclidean rhythm. The evenness is fractal: the pattern of long-and-short gaps is itself a Euclidean pattern. We checked the two-gap property for every pair up to n = 48, and brute-forced that E(k,n) beats every other arrangement on gap-variance up to n = 16. (verify.mjs, part C.)

That is the whole secret of why the algorithm keeps landing on real music. A timeline you can lock to has to be even enough to feel steady but uneven enough to have a shape — to tell you where you are in the cycle. The two-gap rhythms are exactly the ones that thread that needle, and there is one of them for each (k,n). Cultures separated by oceans, optimising the same constraint by ear, converged on the same small set of words.

IV · The same machine, made visible

The claim that Bjorklund is Euclid isn't a metaphor; it's an identity you can watch. Computing the most even k-in-n rhythm folds the n−k rests into the k beats by the same reciprocal subtraction that computes gcd(k, n−k) — same quotients, same remainders, same halt. Here is the GCD ladder running underneath the rhythm currently in the instrument:

gcd(k, n−k) — the subtraction Bjorklund is secretly doing
steplarger÷ smallerquotientremainder

V · Where the drum becomes the scale

Now the part that doesn't quite seem like it should be allowed. Take the West African bell, E(7,12) — seven beats spaced as evenly as possible around twelve slots. Twelve slots. Seven beats. Stop and look at a piano: twelve semitones to the octave, seven of them white. The most even way to choose seven of twelve is a single shape, and it does not care whether you read the twelve as moments in time or as pitches in an octave. Read as time, it's the bell line. Read as pitch, the seven chosen notes are exactly the major scale — the white keys. They are the same necklace. (Mathematically verified: the major-scale set {0,2,4,5,7,9,11} is the same rotation-class as E(7,12); the pentatonic {0,2,4,7,9} is E(5,12). verify.mjs, part E. The bridge between even rhythms and even scales is the theory of maximally even sets — Clough & Douthett, 1991.)

Press hear it as pitch in the instrument and the beats stop being drums and become notes: each slot is one step of the n-tone equal-tempered octave, each beat a note of the scale that rhythm carves out. Set it to E(7,12) and you are listening to the major scale and the Ewe bell pattern at once, because there was only ever one thing there. The oldest algorithm we have, asked the simplest question — how do you share evenly what won't divide? — answers in rhythm and in melody with the same breath.