Musical Math Lab

number theory, polyrhythms & tuning comparison

Loading interactive simulation...

Twelve perfect fifths overshoot seven octaves 🖖

Stack twelve pure fifths, each a 3:2 frequency ratio, and you should land back on the note you started from, seven octaves up. You do not. (3/2)¹² = 129.7463 while seven octaves is 2⁷ = 128, so the spiral misses the octave by 1.4% — the Pythagorean comma, 23.46 cents. There is no way to tune a keyboard that keeps every fifth pure and every octave pure at once, because 3 and 2 share no common power. Twelve-tone equal temperament resolves this by shaving 1.955 cents off every fifth, making all twelve slightly flat and none of them exactly right. Every piano you have heard is deliberately, evenly out of tune.

How a number becomes a chord 🖖

Every whole number breaks into prime factors — its indivisible building blocks. This tool turns each prime into a musical interval: 2 is an octave, 3 a perfect fifth, 5 a major third. So the number 6 = 2 × 3 sounds as an octave with a fifth stacked on top, while a prime like 7 plays a single pure tone. You are literally hearing a number's arithmetic skeleton.

Rhythms born in a particle accelerator 🖖

The evenly spaced beat patterns here come from Bjorklund's algorithm, invented to time neutron pulses in a spallation neutron source at Los Alamos. In 2005 computer scientist Godfried Toussaint noticed its output matches folk rhythms worldwide — one default, E(5,8), is the Cuban cinquillo. Stranger still, the method is Euclid's more than 2000-year-old algorithm for the greatest common divisor, repurposed to space drum hits.

Problem solved in full

  1. A perfect fifth with a 1.96 cents gap on a piano 6 steps

    A perfect fifth is 3/2 in just intonation and 2^(7/12) on a piano. The gap is 1.96 cents. Work out why nobody could simply fix it.

    1. Two definitions of the same interval. One is a ratio of small whole numbers, which is what makes it sound consonant; the other is a twelfth root, which is what makes it fit on a keyboard.

    2. Cents put both on a logarithmic scale where an octave is 1200 and intervals add. The just fifth is not a round number of cents and the equal one is, by construction.

    3. The difference is small — well under the 5 cents most listeners notice on a sustained tone, which is why equal temperament is tolerable at all.

    4. Now stack twelve of them and compare with seven octaves, which is where twelve fifths should land.

    5. The gap in cents is the Pythagorean comma, and it is about a quarter of a semitone — unmistakable.

    6. And it is exactly the small error, twelve times. Nothing was lost or gained in the stacking; equal temperament simply divides the comma by twelve and pays it once per fifth.

    Answer

    Because twelve of those gaps make 23.46 cents, and that is a real interval you can hear. Stack twelve pure fifths and you land on 129.746; stack seven octaves and you land on 128. The two should be the same note and they differ by 1.4%, the Pythagorean comma. There is no tuning that keeps every fifth pure and closes the circle, because 3/2 raised to any whole power is never a power of 2 — the prime factorisations cannot match. So every keyboard tuning is a decision about where to put the comma: spread it evenly over all twelve fifths, which is equal temperament and costs 1.96 cents each, or hide it in keys nobody plays, which is what the historical temperaments did and why music written for them sounds different in different keys.

References (1)
  • Insight block 3 — the algorithm, and the observation that it makes folk rhythms: E. Bjorklund, "The Theory of Rep-Rate Pattern Generation in the SNS Timing System." Los Alamos National Laboratory, SNS ASD Tech Note 2003. G. T. Toussaint, "The Euclidean algorithm generates traditional musical rhythms." Proceedings of BRIDGES: Mathematical Connections in Art, Music and Science, 47–56, 2005.

Example problems

  • Naturals - Natural numbers arpeggio: watch the prime factor mandala expand.
  • Fibonacci - Fibonacci ambient sequence: notes scale outwards matching spiral values.
  • Polyrhythm - Polyrhythm loop: a 5-beat and 7-beat Euclidean rhythm playing in parallel.
  • Tuning Compare - Tuning comparison: compare Just intonation (3:2) against Equal temperament (2^(7/12)).