Ever wondered why pianos have 88 keys or why guitar frets are spaced the way they are? Or why an octave contains exactly 12 notes—5 black keys and 7 white keys—instead of 10 or 15? The answers lie in elegant mathematical formulas that shape our musical world.
After quitting my job last year, I finally found time to explore topics I’d long been curious about. While browsing Hacker News, I came across this brilliant piece on musical tuning systems. As someone who spent my high school years immersed in electric guitar and music theory, I was instantly captivated.
Let’s explore the fascinating intersection of mathematics and music that determines how our instruments are designed.
Pythagoras and the Mathematics of Harmony
About 2,500 years ago, Pythagoras made a groundbreaking discovery: harmonious sounds correspond to simple integer ratios.
Believing that the universe could be expressed through integers and their ratios, Pythagoras identified specific frequency relationships that sound particularly pleasing to our ears:
1:2 (Octave): When a note with frequency $f$ is played together with a note of frequency $2f$, they sound exceptionally harmonious. The audio below features A3, A4, A5.
2:3 (Perfect Fifth): The most harmonious interval after the octave. Electric guitar power chords are based on this interval. The audio below features A4, E5.
The Cycle of Fifths and the Pythagorean Comma: A Mathematical Puzzle
Pythagoras realized he could build an entire musical system using perfect fifth relationships:
- Begin with a reference note (like C)
- Find its perfect fifth by multiplying its frequency by 3/2 (giving us G)
- When a new note’s frequency exceeds twice the original, bring it down an octave (divide by 2)
- Repeat to generate a complete scale
In theory, after 12 perfect fifths, we should return exactly to our starting note (in a higher octave). But mathematics reveals a problem:
$$\left(\frac{3}{2}\right)^{12} \approx 129.746$$
While $2^7 = 128$, creating a difference of about 1.36%. This means 12 stacked perfect fifths produces a slightly different pitch than 7 octaves. This small but crucial discrepancy is called the “Pythagorean Comma.”
The Mathematical Inevitability of Imperfection
The core question is: do integers $n$ and $m$ exist such that:
$$\left(\frac{3}{2}\right)^n = 2^m$$
Taking logarithms:
$$\frac{n}{m} = \frac{\log(2)}{\log\left(\frac{3}{2}\right)} \approx 1.7095…$$
The Gelfond–Schneider theorem proves this value is irrational—meaning no integers can make the equation exactly true. This isn’t a flaw in our tuning methods but a fundamental mathematical reality, similar to how π can never be expressed as a finite decimal.
Interestingly, $\frac{12}{7} \approx 1.7142$ closely approximates $1.7095$, which explains why Western music adopted a 12-tone system.
12-Tone Equal Temperament: The Elegant Compromise
To solve the Pythagorean Comma problem, musicians and mathematicians developed 12-tone equal temperament (12-TET):
- The octave is divided into 12 precisely equal semitones
- Each semitone has a frequency ratio of $2^{1/12} \approx 1.059463$
- Twelve semitones complete the octave perfectly: $(2^{1/12})^{12} = 2$
This system prioritizes consistency and modulation flexibility over perfect harmonic ratios. In 12-TET, the perfect fifth becomes $2^{7/12} \approx 1.498$—just 0.11% off from the ideal $\frac{3}{2} = 1.5$. This slight adjustment enables all keys to function equally well and allows for seamless modulation between them.
The Mathematical Precision of 12-TET
The frequency ratio for each semitone in 12-TET is:
$$
r = \sqrt[12]{2} \approx 1.059463…
$$
Being irrational, this number cannot be expressed as an exact integer ratio. The challenge becomes approximating key musical intervals with this system, a problem in Diophantine approximation—the mathematical field of approximating irrational numbers with rational ones.
12-TET provides remarkably good approximations of traditional just intonation intervals:
Interval | Just Ratio | 12-TET Ratio | Error (%) |
---|---|---|---|
Octave | 2.000000 | 2.000000 | 0.000000 |
Perfect Fifth | 1.500000 | 1.498307 | -0.112862 |
Perfect Fourth | 1.333333 | 1.334840 | 0.112989 |
Major Third | 1.250000 | 1.259921 | 0.793684 |
Minor Third | 1.200000 | 1.189207 | -0.899407 |
Major Sixth | 1.666667 | 1.681793 | 0.907570 |
Minor Sixth | 1.600000 | 1.587401 | -0.787434 |
Major Second | 1.125000 | 1.122462 | -0.225596 |
Minor Second | 1.066667 | 1.059463 | -0.675335 |
Tritone (Augmented Fourth) | 1.400000 | 1.414214 | 1.015254 |
Beyond 12 Notes: Alternative Equal Temperament Systems
The mathematical exploration extends beyond 12-TET to other possible systems:
19-Tone Equal Temperament (19-TET)
- Each step: $2^{1/19} \approx 1.0371$
- Perfect fifth: $2^{11/19} \approx 1.4937$ (0.42% error)
- Ratio approximation: $\frac{19}{11} \approx 1.7273$ vs. actual $\frac{\log(2)}{\log(3/2)} \approx 1.7095$ (1.04% error)
31-Tone Equal Temperament (31-TET)
- Each step: $2^{1/31} \approx 1.0226$
- Perfect fifth: $2^{18/31} \approx 1.4955$ (0.3% error)
- Ratio approximation: $\frac{31}{18} \approx 1.7222$ vs. actual $\frac{\log(2)}{\log(3/2)} \approx 1.7095$ (0.74% error)
- Nearly perfect reproduction of just intonation intervals, but practically complex
Calculating Optimal Temperaments: A Computational Approach
1 | import numpy as np |
Harmony Scores Across Different Temperaments
Equal Divisions | Harmony Score |
---|---|
2 | 0.000 |
3 | 1.178 |
4 | 0.363 |
5 | 0.138 |
6 | 28.359 |
7 | 1.715 |
8 | 0.363 |
9 | 1.180 |
10 | 3.776 |
11 | 29.144 |
12 | 253.200 |
19 | 250.865 |
22 | 144.688 |
31 | 324.254 |
34 | 438.195 |
41 | 439.427 |
46 | 454.806 |
The results reveal that 12, 19, 31, 34, 41, and 46 equal divisions achieve notably high harmony scores. While 19-TET and 31-TET have historical precedent in music theory and composition, systems like 34-TET, 41-TET, and 46-TET remain largely theoretical despite their mathematical advantages. The reason for this practical limitation is likely evident to readers.
Experience Alternative Temperaments: Recommended Listening
19-Tone Equal Temperament (19-TET):
31-Tone Equal Temperament (31-TET):
Conclusion: Where Mathematics and Music Converge
The 12-tone equal temperament system represents an elegant compromise between mathematical purity and musical practicality. It trades the perfect harmony of pure intervals for a system offering lower complexity, key equality, and modulation freedom.
The mathematics behind tuning systems—involving Diophantine approximation, continued fraction theory, and error minimization—reveals why certain numbers emerge as particularly significant in music theory. This intersection of mathematics and music demonstrates how abstract numerical relationships shape our tangible musical experiences.