The musical scale is arguably humanity’s oldest algorithm for beauty.

Music theory can seem intimidating (for instance, I probably should have learned tuning theory back in 16 when I was sitting in orchestra). But it’s actually quite straightforward. Imagine you’re a piano designer: you want your instrument to sound nice, but you also don’t want it to have an infinite number of keys.

Axiom 1 (Sounding nice) Two notes sound consonant when their frequencies form a ratio of small integers. The simpler the ratio, the more pleasant the sound. For example, a perfectly harmonic octave has a ratio of $2:1$, and a nice fifth has $3:2$.

Axiom (Finite keys) We want a finite set $\mathbf{P}$ of notes (frequencies) that behaves almost like a group: moving up or down by an octave gives the same note, and $\mathbf{P}$ should be closed under transposition by a fifth (multiplying or dividing every frequency by $\frac{3}{2}$).

These two axioms can’t both be perfectly satisfied. The impossibility is quite straightforward: for any base note $t$, the set of all fifth transpositions that still lie within one octave is infinite: $$ \mathbf P(t) := \lbrace t’:t’ = \frac{(3/2)^m}{2^n}, t’\in [t, 2t], m, n\in \Z\rbrace. $$ Historically, three major tuning systems emerged:

‘Sexy,’ isn’t it

‘Sexy,’ isn’t it

The old wisdom of Pythagorean, the Pythagorean scale is a heuristic that approximates both axioms with 12 notes. The just intonation system, by contrast, defines notes directly from pure integer ratios. It produces the most consonant intervals but requires many, MANY keys to preserve that purity across transpositions.

A 17th-century mathematician Marin Mersenne designed a keyboard with 31 notes in an octave, and no fewer than 4 keys between F and G.

A 17th-century mathematician Marin Mersenne designed a keyboard with 31 notes in an octave, and no fewer than 4 keys between F and G.

The problem was beautifully resolved by equal temperament — divide the octave into 12 equal geometric steps, each raised by $2^{1/12}$. This tuning slightly compromises the purity of individual intervals (for instance, the fifth is $1.4983$ instead of the perfect $1.5$), but the ear hardly minds (though often the thirds are tricky). In return, we gain a beautifully closed, finite set $\mathbf{P}$ of 12 notes — a workable, nearly symmetric solution.

It took humanity thousands of years to discover this near-perfect approximation of harmony. So finally, our piano sings brilliantly — and it does so with just 88 keys.

Reference

Fauvel, J., Flood, R., & Wilson, R. J. (Eds.). (2006). Music and mathematics: From Pythagoras to fractals. Oxford University Press.