Visualizations
374 / 500

374 · Math

Music of the Primes

Riemann's explicit formula rebuilds the prime staircase from 500 zeta zeros.

The white staircase is pi(x), the number of primes up to x. The orange curve is Riemann's explicit formula, R(x) minus the sum of R(x^rho) over the zeros rho = 1/2 + i gamma of the zeta function, where R is computed from the Gram series and each R(x^rho) from the exponential integral of a complex argument (power series near zero, asymptotic series far out). Every pair of zeros adds one wave like cos(gamma ln x), and the strip below isolates the oscillating part so you can watch the waves sum toward a sawtooth that jumps at every prime. None of the 500 zeros are stored: they are found on the fly as sign changes of Hardy's Z function, exactly from the accelerated eta series below t = 60 and from the Riemann-Siegel formula with two correction terms above, refined by bisection. The same values trace zeta(1/2 + it) on the right, a spiral that passes through the origin at each zero.

Try it. Drag the slider (or use the arrow keys, Shift for steps of ten) to choose how many zeros to include, from 1 to 500. Hover the plot to read pi(x) against the formula at any x. Space pauses the autoplay, the buttons or keys 1 to 3 switch the range to x up to 50, 100 or 250, and Home and End jump to no zeros or all of them.

  • Riemann's explicit formula
  • Riemann-Siegel formula
  • Complex exponential integral
  • Borwein eta acceleration

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a visualization of Riemann's explicit formula with JavaScript and the HTML canvas element: the zeros of the zeta function rebuilding the staircase of prime numbers. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Use the Chebyshev function psi(x), which counts prime powers p^k up to x with weight ln p. Compute it exactly for x from 1 to 100 with a small sieve and draw it as a white staircase.
- Hardcode the first 30 zeta zeros gamma (14.134725, 21.022040, 25.010858, 30.424876, 32.935062, 37.586178, and so on; look up the rest).
- The explicit formula is psi(x) = x - ln(2 pi) - 0.5 ln(1 - x^-2) - sum over zeros of 2 Re(x^rho / rho), with rho = 1/2 + i gamma. Each term is 2 sqrt(x) times a cosine of gamma ln x divided by |rho|, so write a few lines of complex arithmetic for x^rho / rho.
- Sample x at about 800 points, sum the first k zeros, and draw the result as a glowing orange curve over the staircase. Add a slider for k.

Once that works, make it beautiful:
- Animate k from 0 upward, fading each new zero's wave in, so you can watch the smooth line x grow corners at every prime power.
- Draw the newest zero's wave on its own in a strip underneath, so each zero reads as one note.
- Add a side panel that plots zeta(1/2 + it) as t increases, using the alternating eta series with about 60 terms for t up to 40. It is a spiral that passes through the origin exactly at each zero, so mark the origin.
- Use a dark background, a soft gradient fill under the curve and a small legend.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as computing the zeros yourself from the Riemann-Siegel formula, switching to the prime counting function pi(x) with Riemann's R function, or going to hundreds of zeros.
PreviousViterbi TrellisA hidden Markov model catches a dealer swapping in a loaded die, roll by roll. NextSpatial IndexesQuadtree, k-d tree, BVH and grid rebuilt every frame over thousands of moving points.

Related visualizations

  • Domain ColoringMath Drag the zeros and poles of a complex function and count them with a loop.
  • Prime SpiralsMath A million integers on Ulam and Sacks spirals, where prime-rich polynomials glow as rays.
  • Gaussian PrimesMath A frog hops across the Gaussian primes, looking for a way to infinity.
  • Road to ChaosMath The logistic map's bifurcations, Mandelbrot bulbs and a cobweb, linked in one picture.
  • Pole-Zero FilterMath Drag poles and zeros over a 3D |H(z)| surface and hear the filter you built ring.
  • Root BraidsMath Loop a quintic's coefficients and its roots braid, swap and refuse to come home.
  • Circle PackingMath Thurston's discrete Riemann map: a live circle packing warps a picture into your blob.
  • Ford CirclesMath A circle for every fraction, and a dive into why the golden ratio is the most irrational.
  • Space-Filling CurvesMath Hilbert, Peano, Gosper and friends fold smoothly from one order to the next.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs