What you are seeing
In 1859 Riemann found an exact formula for the number of primes \(\pi(x)\) less than or equal to \(x\). Written so as to show the wave coming from each zero of the zeta function, it says that for \(x \ge 4\) not a prime
Here \(\mathrm{li}\) is the logarithmic integral, and the sum runs over the nontrivial zeros \(\rho = \tfrac12 + i\gamma\) of the zeta function with \(\gamma > 0\), in order of increasing height. Each zero contributes a wave of amplitude about \(2\sqrt{x}/(|\rho| \ln x)\) that oscillates like \(\cos(\gamma \ln x - \arg \rho)\). The last three terms are corrections. To write them down, let \(M = \lfloor \log_2 x \rfloor\), and let \(\mu(n)\) be \(0\) if \(n\) is divisible by a square greater than 1, and otherwise \((-1)^m\) where \(m\) is the number of prime factors of \(n\). Then
The term \(A(x)\) collects smooth corrections: the error in the three-term expansion of \(\tfrac12\mathrm{li}(\sqrt{x})\), the contributions of cube roots, fifth roots and so on, and some small constants. The term \(B(x)\) is the error in the two-term expansion of each wave, and is tiny: about \(2\times 10^{-6}\) at \(x = 1000\) with 1000 zeros. The term \(C(x)\) consists of further waves from the same zeros, of size about \(x^{1/4}\) rather than \(x^{1/2}\); together with the smooth terms in \(A\), they cancel the steps at squares, cubes and higher powers of primes that the main waves would otherwise produce. At \(x = 1000\) we have \(A \approx -2.60\) and, with 1000 zeros, \(C \approx -0.12\).
This is a rearrangement of Riemann’s own formula. He counted prime powers with weights, \(J(x) = \sum_{p^k \le x} 1/k\), proved that
and recovered the primes using \(\pi(x) = \sum_{n} \frac{\mu(n)}{n} J(x^{1/n})\). Only the terms with \(n \le M\) appear, since \(J(y) = 0\) for \(y < 2\).
The red curve \(\pi_N(x)\) is the same formula with every sum over zeros restricted to the first \(N\) pairs. Step 0 is the smooth part alone. Each later step adds one more zero’s wave, together with its share of \(B\) and \(C\). The heights run from \(\gamma_1 \approx 14.1347\) to \(\gamma_{1000} \approx 1419.4225\). A zero of height \(\gamma\) varies on the scale \(\Delta x \approx 2\pi x/\gamma\). For \(\gamma_{1000}\) this scale is about \(0.44\) near \(x = 100\), about \(2.2\) near \(x = 500\) and about \(4.4\) near \(x = 1000\). So 1000 pairs resolve every step below 100 and most steps near 500, while near 1000 they separate primes that are more than a few units apart but blur close pairs together.
For \(x < 2\) every \(\pi_N(x)\) is exactly 0. The smooth part has small jumps at \(x = 2, 4, 8, 32, 64, 128\) and \(1024\), where a new term \(J(x^{1/n})\) switches on; the zero terms smooth these out as \(N\) grows. At a prime the full formula gives the midpoint of the jump, and the truncated sums show the usual overshoot on either side of each step.
References
- Bernhard Riemann, “Ueber die Anzahl der Primzahlen unter einer gegebenen Grösse,” Monatsberichte der Berliner Akademie, November 1859. English translation by David R. Wilkins, “On the Number of Prime Numbers less than a Given Quantity” (1998).
- Hans Riesel and Gunnar Göhl, “Some Calculations Related to Riemann’s Prime Number Formula,” Mathematics of Computation 24 (1970): 969–983, doi:10.1090/S0025-5718-1970-0277489-3. The first plots of this kind, using 29 pairs of zeros.
- Andrew Odlyzko, Tables of zeros of the Riemann zeta function. The heights used here were computed with mpmath and agree with these tables.