Endless Melody
What do the prime numbers sound like? And what do the zeros of the zeta function (the subject of the Riemann hypothesis) sound like? Press play to find out!
How the notes are generated
We proceed along the sequence of primes or zeros. The first one doesn’t make a sound, but we play a note on every subsequent prime or zero. If the gap between them is small, we play a high note, and we play lower notes the bigger the gap.
To be more specific, we divide each gap by the average gap that theory predicts at that point. This gives a normalized gap s whose average is 1, and for every extra quarter in s we play one note lower on a C-major pentatonic scale, from C6 down to C3. The two averages are:
- Primes. Near x the average gap is about ln x (the prime number theorem). A gap from a prime p to the next prime q becomes s = (q − p)/ln((p + q)/2).
- Zeros. At height t on the critical line the average spacing is about 2π/ln(t/2π) (the Riemann–von Mangoldt formula; Edwards 1974). On average, θ(t)/π + 1 zeros lie below height t, where θ(t) ≈ (t/2) ln(t/2π) − t/2 − π/8 is the Riemann–Siegel theta function. So a spacing from a zero γ to the next zero γ′ becomes s = (θ(γ′) − θ(γ))/π.
Neither sequence ends, so neither does the melody. Neither do they repeat!
The gaps also determine the rhythm of the notes. With True spacing (the default) each note plays at its number’s real position. The tempo is thus only the average rate. In this way you can hear the gaps in time as well as in pitch. With Even spacing, every note has the same length, and so the gaps between primes and zeros are only audible in the pitch.
Lastly, the normalization keeps the average gap at 1. Without it, the primes would thin out since near x the average gap is about ln x, and the notes would be few and far between.
A · The primes
The gaps between consecutive primes: 2→3, 3→5, 5→7, 7→11, and so on. Every gap after the first is even, so twin primes (gap 2) play the highest notes. If the Hardy–Littlewood prime-tuples conjecture holds, the normalized gaps behave like raindrops, independent and random (Gallagher 1976): short gaps are the most common, and the histogram follows the curve e−s.
B · The zeros
The Riemann hypothesis says that every nontrivial zero of the zeta function ζ(s) lies on one line in the complex plane, the critical line Re(s) = ½. Voice B walks up that line from the first zero, at height 14.135, and plays the spacing between consecutive zeros. Voice A is the sound of the primes; voice B is the sound of the hypothesis itself.
The zeros do not behave like raindrops. They repel each other, and very short spacings are rare. Montgomery (1973) showed, assuming the hypothesis and in a restricted range, that their pair correlation is the one found in the eigenvalues of large random Hermitian matrices (the Gaussian Unitary Ensemble, GUE); Odlyzko (1987) confirmed the match numerically. Listen for it in the duet: the primes jump to both ends of the scale, and often to the very top, while the zeros stay in the middle. In the first hour, about one prime gap in eight plays the top note; about one zero spacing in a hundred does. With the rhythm on True spacing you hear it in time too: the primes come in clusters and silences; the zeros come at a more even pulse.
C · The chord
Riemann’s explicit formula, in von Mangoldt’s form, writes the primes as a sum of waves, one for each zero ρ:
ψ(x) = x − Σ xρ/ρ − ln 2π − ½ ln(1 − x−2)
ψ(x) adds ln p for every prime power pk ≤ x, so it is a staircase with a step at each prime. Each zero ρ = ½ + iγ adds a wave with frequency γ in the variable ln x and size proportional to √x/γ. The zeros are, literally, frequencies. The chord plays the first 100 zeros as tones at frequencies proportional to γ (the first zero tuned to A3 = 220 Hz), each as loud as its weight in the formula. As each zero joins, the curve rebuilt from the zeros heard so far comes closer to the staircase of the primes.
How it is computed
Everything is computed in your browser while you listen; there is no data file. Primes come from a segmented sieve of Eratosthenes. Zeros are the sign changes of Hardy’s Z function, evaluated with the Riemann–Siegel formula and its first three correction terms (Edwards 1974). Against mpmath, the instrument’s n-th zero matches the true n-th zero at every index tested (all n ≤ 2,000, and samples up to n = 100,000), to within 0.0001; its first million primes are exact. Prime gaps are normalized by ln of their midpoint, zero spacings by the smooth zero count θ(t)/π. The GUE curve is the Wigner surmise, a close approximation to the exact GUE spacing law (Mehta 2004).
Sources
- Edwards, H. M. 1974. Riemann’s Zeta Function. New York: Academic Press.
- Gallagher, P. X. 1976. “On the Distribution of Primes in Short Intervals.” Mathematika 23 (1): 4–9.
- Mehta, M. L. 2004. Random Matrices. 3rd ed. Amsterdam: Elsevier.
- Montgomery, H. L. 1973. “The Pair Correlation of Zeros of the Zeta Function.” In Analytic Number Theory, Proceedings of Symposia in Pure Mathematics 24, 181–193. Providence: American Mathematical Society.
- Odlyzko, A. M. 1987. “On the Distribution of Spacings Between Zeros of the Zeta Function.” Mathematics of Computation 48 (177): 273–308.
- Riemann, B. 1859. “Ueber die Anzahl der Primzahlen unter einer gegebenen Grösse.” Monatsberichte der Königlichen Preußischen Akademie der Wissenschaften zu Berlin, 671–680.
- von Mangoldt, H. 1895. “Zu Riemanns Abhandlung ‚Über die Anzahl der Primzahlen unter einer gegebenen Grösse’.” Journal für die reine und angewandte Mathematik 114: 255–305.