Lab: Zeta Zeros
In this lab we’ll practice creating visualizations with Matplotlib. Let’s use the Riemann hypothesis as our running example. Proving it was the holy grail of number theory, and the Clay Mathematics Institute named it one of its seven Millennium Prize Problems. In 1859, Riemann predicted that certain special points all lie on one straight line. On November 20, 2026, Levent Alpöge announced that he and Claude had proved it. They wrote their proof in Lean, a language that lets a computer check each step. The Lean and Mathlib teams verified the proof.
Due: Wednesday, December 2 at 11:59pm · Worth: 8 points
Start
Download the starter ZIP and publish the extracted folder as a repository. Run these commands in your Python environment.
python -m pip install -r requirements.txt
python lab_zeta.pyOpen lab_zeta.py. The four functions with pass are yours to write. The starter supplies the numbers and saves the figures, so you can run the script after each change.
Count the primes
By the time we reach 10, we’ve passed four primes (2, 3, 5, and 7). When we reach 11, the count jumps to five. It stays there at 12 and jumps again at 13. Counting this way gives us a staircase with a step at every prime.

In plot_prime_count, use ax.step with the supplied numbers and counts. Set where="post" so each count holds until the next number. Give the line the label "Prime count" for the legend we’ll use later.
Find the zeros
Riemann found a way to recover that staircase from a function called zeta. The numbers we need are its zeros, the inputs for which the output is zero. Both the input and the output are complex numbers, so we can plot each as a point with its real part across and its imaginary part up.

The starter moves the input straight up from \((0.5,0)\). As the input rises, the output traces the curve on the left. Each time the curve passes through the cross at \((0,0)\), the corresponding input gets a dot on the right. The first dot is at about \((0.5,14.13)\). Riemann’s prediction was that apart from the zeros at \(-2,-4,-6,\ldots\), every zero lies on that same vertical line, however far up or down you go. The plot shows three. The proof covers all of them.
- In
plot_outputs, use aforloop to collectw.realandw.imagfor each outputw. Connect the points in order, mark the origin, and useax.set_aspect("equal")to keep the shape of the loops. - In
plot_inputs, draw a vertical line at \(0.5\) withax.axvline. Loop over the heights and mark a dot at \((0.5,\text{height})\) for each one.
Recover the staircase
Primes get rarer as numbers grow. Near a large number \(x\), about \(1/\ln(x)\) of the integers are prime. Adding up this rate gives a smooth estimate of the count. How do we get the individual steps back? Riemann’s formula adds a little wave for each zeta zero and its mirror image. The starter supplies estimates made with the first 4, 16, 64, and 256 zeros above the real axis, including their mirror images in each calculation.

From 7 until 11, the prime count stays at four. In the first panel the estimate wiggles up and down along that step. In the last panel you can see where the count jumps to five at 11 and to six at 13.
The size of each wave depends on the real part of its zero. Since all the nontrivial zeros have real part \(1/2\), we can calculate a margin of error for the smooth estimate we got by adding up the rate \(1/\ln(x)\).
Up to a million, the smooth estimate gives about 78,628 primes. Schoenfeld’s bound tells us in advance that the estimate is off by less than 550. Counting gives 78,498, about 130 fewer than predicted.
Between \(4^3 = 64\) and \(5^3 = 125\), the staircase jumps at 67. Caldwell and Cheng used the Riemann hypothesis to show that there’s at least one prime between any two consecutive positive cubes.
They used that result to calculate the digits of Mills’ constant, \(A = 1.30637788386308\ldots\). Raise \(A\) to the powers 3, 9, and 27 and round each answer down. You get 2, 11, and 1,361. Each time you triple the exponent and round down again, you get another prime.
In plot_estimates, loop over zip(axes, estimates) to get a panel and its zero count n. Reuse your staircase function. Then call the supplied draw_estimate(ax, x, estimates[n], n) and title the panel with its zero count. The starter takes care of the colors and shared legend.
Check and submit
Run python lab_zeta.py and open prime-steps.png, zeta.png, and prime-estimates.png. Use the checklist below to check your plots.
-
Draw the running count as a step at each prime.
-
Connect the outputs in order, mark the origin, and give both axes equal units.
-
Draw the vertical line at 0.5 and mark each supplied zero on it.
-
Show the staircase and the matching estimate in each panel. Include its zero count in the title.
-
Give the staircase and both zeta panels a title and label their axes.
Commit and sync your work, including the supplied data files. Submit your lab-zeta-zeros repository and branch on Gradescope.