Where pi hides. Nobody drew a circle.

Needles on a ruled floor and pairs of whole numbers both give pi. Two experiments, and one old question about what mathematics is.

  • Probability
  • 9 min read
  • 2 simulations

Where does pi come from, when nobody drew a circle?

Pi belongs to circles. It is the way round divided by the way across. So it is a bit unsettling to find it somewhere nobody drew one.

There are two places to look. One is a floor ruled with lines, with needles dropped on it. The other is pairs of whole numbers, picked at random. Neither has a circle on it, and both give pi if you count.

The figure beside the text changes as you scroll, and you can take hold of it. Drop needles and drag the sliders. Tap a point on the grid and see what is behind it.

Drop a needle

Rule a floor with parallel lines, all the same distance apart. Call that distance the gap. Drop a needle exactly as long as the gap. It touches a line, or it does not.

Guess first. Out of 100 drops, how many touch a line?

Now press +100 and count. About 64 do. Divide twice the number of drops by the number that touched. Drop more and the answer keeps landing near 3.1.

There is no circle anywhere on that floor.

Press +100 a few times. Needles that touch a line turn colour.

Figure. A floor ruled with seven parallel lines, with needles lying across it at random angles. Needles that touch a line are coloured and the rest are grey. Controls drop 1, 10 or 100 needles, stream them, reset the floor, and set the needle length. The readout gives the drops, the touches and the estimate of pi. After 1,000 drops with the first seed, 631 touch a line and the estimate is 3.170.

A slow way to find pi

Press stream and watch the estimate. At first it jumps about. Then it settles, but slowly.

The shaded funnel is where about 95 runs in 100 should stay, which is pi give or take two typical errors. A typical error is how far a run usually strays. It shrinks like 1/n1/\sqrt{n}. After 1,000 drops it is about 0.075. After 10,000 it is about 0.024.

So each extra digit of pi costs about 100 times more drops. An error of 0.0005 would take about 23 million. As a way to find pi, the needle is a poor one.

Stream the drops, then switch on ten more runs.

Figure. The floor above a chart of the running estimate of pi against the number of drops, on a log scale from 1 to 100,000. The line jumps about at first, then settles near 3.14 inside a shaded funnel that narrows slowly. Ten fainter lines show other runs, mostly inside the funnel. The readout gives the drops, the estimate and the typical error, and says that a typical error of 0.0005 needs about 23 million drops.

The circle is in the angle

Buffon asked for a probability. For a needle of length ll on lines dd apart, with l≤dl \le d, the chance of touching a line is

P=2 lπ d.P = \frac{2\,l}{\pi\,d}.

That is the needle’s length over the gap, times a fixed 2/π2/\pi. Turn it around and nn drops with cc touches give π≈2ln/(dc)\pi \approx 2ln/(dc). That is the number in the readout.

So where is the circle? A needle at angle θ\theta to the lines stands l ∣sin⁡θ∣l\,|\sin\theta| high, and that height, out of the gap, is its chance of touching a line. A throw has no favourite direction, so every angle on a half turn is as likely as any other. Average ∣sin⁡θ∣|\sin\theta| over a half turn and you get 2/π2/\pi.

The ring is that circle. Each needle’s direction is a point on it, and so is the opposite point, since a needle has no head. The points fill the ring evenly. The ones that touch gather near the top and bottom, where the needle stands across the lines. The curve around the ring is the chance at each angle, and it shrinks as the needle gets shorter.

No direction is favoured, and that symmetry is where pi comes from.

Each needle is a pair of dots on the ring. Shorten the needle.

Figure. The floor beside a ring. Each needle’s direction is a point on the ring, with a second point opposite it, and the points fill the ring evenly. Points for needles that touch a line gather near the top and bottom. A curve around the ring shows the chance of touching a line at each angle, zero along the lines and the needle length across them. The readout gives the drops, the share that touch and the exact chance, 63.7 percent for a needle as long as the gap.

Now whole numbers

Two whole numbers share a factor when some number above 1 divides both. 6 and 9 share 3. 8 and 15 share nothing, so they are coprime.

Pick two whole numbers at random. How often do they share nothing? Guess before you look.

Each point on the lattice is a pair (a,b)(a, b), and the coloured ones share no factor. There is a catch. No rule picks a whole number evenly from all of them, so “at random” needs care. Pick both from 1 to NN and let NN grow. The share of coprime pairs tends to

6π2≈0.6079.\frac{6}{\pi^2} \approx 0.6079.

Count the pairs and pi falls out. 6/share\sqrt{6/\text{share}} gives 3.119 at N=30N = 30, 3.139 at N=300N = 300 and 3.141 at N=3000N = 3000.

The coloured points are also the ones you can see from the origin with nothing in the way. From the origin, (12, 18) is hidden behind (2, 3).

Drag N. Tap a point such as (12, 18) to see what hides behind it.

Figure. A square lattice with one point for each pair of whole numbers (a, b) up to N, beside a chart of the estimate of pi from all pairs up to N, against N on a log scale. Points whose two numbers share no factor are coloured. As N grows from 2 to 300, about 61 in 100 stay coloured and the estimate settles near 3.14. At N equal to 30, 555 of 900 points are coloured and the estimate is 3.119.

Cross out the primes

Why 6/π26/\pi^2? Start with one prime, pp. A random number is a multiple of pp with chance 1/p1/p, so both numbers are with chance 1/p21/p^2. A pair avoids sharing pp with chance 1−1/p21 - 1/p^2.

Watch the primes go. Cross out every pair that shares a 2 and 75% is left. Then the 3s, and 66.7% is left. Then the 5s, and 64.0%. The grid and the product of those chances agree at every step, because 34⋅89⋅2425=0.64\tfrac34 \cdot \tfrac89 \cdot \tfrac{24}{25} = 0.64.

After the ten primes up to 29, 61.7% of the grid is left. That is the coprime share at N=30N = 30. The product says 0.6123. The grid stops at 30 and the product does not know that.

It runs by itself. Drag the primes slider to take over.

Figure. The lattice at N equal to 30 beside a table. Primes are crossed out one at a time, 2, then 3, then 5. The share of points left in the grid falls from 100 percent to 75, then 66.7, then 64.0, matching the running product of one minus one over p squared. After all ten primes up to 29, 61.7 percent of the grid is left and the product is 0.6123.

The circle, this time

Do the same for every prime and multiply the chances, treating the primes as independent. For any handful of primes that is exact. Going on to all of them takes a proof, and this note leaves it out.

∏p(1−1p2)=1ζ(2),ζ(2)=1+14+19+⋯\prod_{p}\Bigl(1 - \frac{1}{p^2}\Bigr) = \frac{1}{\zeta(2)}, \qquad \zeta(2) = 1 + \frac14 + \frac19 + \cdots

The share of coprime pairs is one over the sum of 1/k21/k^2. Unique factorisation into primes is what turns that sum into a product over primes. The product creeps down slowly. It is 0.612 after the ten primes up to 29, and 0.6079 after every prime below 10,000.

Euler announced in 1735 that the sum is π2/6\pi^2/6. The circle enters through the sine, which is zero at exactly the whole numbers. Euler wrote sin⁡(πx)/(πx)\sin(\pi x)/(\pi x) as a product over those zeros, ∏k≥1(1−x2/k2)\prod_{k\ge 1}(1 - x^2/k^2), and compared it with its series. His first argument was not rigorous by later standards. Correct proofs followed.

So each of them has a cause. For the needles it is rotation. For the whole numbers it is unique factorisation, with a sine behind the sum.

Drag the primes slider. The last digits are slow.

Figure. A chart of the running product of one minus one over p squared against the number of primes, on a log scale from 1 to 1,229. It falls from 0.75 toward a dashed line at six over pi squared, 0.6079. Above the chart is the equation: the product over all primes p of one minus one over p squared equals six over pi squared. The readout gives the number of primes, the product and the limit.

Invented, or discovered?

Do mathematicians invent mathematics, or discover it? The two experiments do not answer that. They give each side something to point at.

Invented. People chose the axioms and the definitions. On this view pi, coprime pairs and probability are ideas we built because they were useful, and other axioms would give other mathematics. Mathematics is a human tool.

Discovered. Once the definitions were set, nothing else was up to anyone. Nobody chose 2/π2/\pi for the needle or 6/π26/\pi^2 for the whole numbers, and two unrelated starting points gave the same constant. On this view the structure was there to be found.

A middle view says both. We invent the concepts and discover what follows from them.

Each side can answer the other’s evidence. The first can say the two starting points are less unrelated than they look, since both rest on concepts we built. The second can say that is exactly what needs explaining. The experiments cannot settle it.

Both keep running. Press replay to run them again.

Figure. Two pictures side by side. On the left, the ring of needle directions filling up as needles drop. On the right, the lattice of pairs growing to N equal to 300. A readout gives the estimate of pi from each, near 3.14 for the needles and 3.139 for the whole numbers, beside pi itself, 3.142.

What this does not say

Pi does not turn up everywhere, and these two appearances are not a sign of anything. Each has a cause you have just met. Whether mathematics is invented or discovered is still open.

“At random” here is a model. Needles and numbers are spread evenly and independently, drawn by a seeded generator, so every run can be replayed.

Sources

Checked against the pages listed. Items marked “as cited” were read through a secondary source.

  1. Buffon’s needle problem, Wikipedia. The formula for a needle no longer than the gap, rotational symmetry as the reason pi appears, Lazzarini’s report and Badger’s analysis, and Barbier’s argument of 1860 (citing Aigner and Ziegler, Proofs from THE BOOK, 2nd ed., Springer, 2013, as cited).
  2. Buffon’s Needle Problem, Wolfram MathWorld. Buffon posed the problem in 1733 and gave the solution in 1777.
  3. Lee Badger, “Lazzarini’s Lucky Approximation of π”, Mathematics Magazine 67(2), 1994, pp. 83 to 91 (as cited).
  4. M. Lazzarini, “Un’applicazione del calcolo della probabilità alla ricerca sperimentale di un valore approssimato di π”, Periodico di Matematica per l’Insegnamento Secondario 4 (1901), pp. 140 to 143 (as cited).
  5. Relatively Prime, Wolfram MathWorld. The limit 6/π26/\pi^2, the credit to Cesàro and Sylvester, and visible lattice points.
  6. Coprime integers, Wikipedia. The Euler product argument, Cesàro in 1881, and Hardy and Wright, Theorem 332.
  7. Sergei Abramovich and Yakov Nikitin, “On the probability of co-primality of two natural numbers chosen at random” (2017). Cesàro’s odds of 61 to 39, Dirichlet’s earlier work of 1849, and the argument over priority.
  8. OEIS A018805, the number of coprime pairs up to nn. Checked against the engine for n=1n = 1 to 30.
  9. Basel problem, Wikipedia. Mengoli in 1650, Euler in 1734 and 1735, and the accepted proof of 1741 (citing Raymond Ayoub, “Euler and the zeta function”, American Mathematical Monthly 81(10), 1974, as cited).
  10. Eugene P. Wigner, “The Unreasonable Effectiveness of Mathematics in the Natural Sciences”, Communications on Pure and Applied Mathematics 13(1), 1960, pp. 1 to 14.
  11. Øystein Linnebo, “Platonism in the Philosophy of Mathematics”, Stanford Encyclopedia of Philosophy. The view that mathematical truths are discovered.
  12. Leon Horsten, “Philosophy of Mathematics”, Stanford Encyclopedia of Philosophy. Logicism, intuitionism and formalism as accounts that do not take mathematics to be discovered.
  13. Mieczysław Szyszkowicz, “Buffon’s needle experiment and its realization”, Antiquitates Mathematicae 18 (2024), pp. 3 to 14 (as cited). Choosing a needle’s direction from random points of a circle, so no value of pi is needed in advance.