↑ ↓ to move · enter to open

027 · Math · Geometry, series, probability, digits

pi

Measure around any circle, divide by the distance across, and you get the same number every time: π = 3.14159… Its digits never end and never repeat. Here you'll pin π down five ways: trap it between polygons, throw random darts at it, add up infinite sums that race toward it, catch it in places that have nothing to do with circles, and finally draw a million of its digits.

LAB 1

squeezing the circle

Take a circle of radius 1. Its perimeter (the distance around) is 2π, so half the perimeter is exactly π. Draw a regular polygon inside the circle, touching it at its corners, and another outside, touching it at the middle of each side. The inside one is a bit shorter than the circle and the outside one a bit longer, so π is trapped between their half-perimeters. Double the number of sides and the trap tightens. Around 250 BC Archimedes did this by hand, up to 96 sides.

96 sides
96 sides

How to read this: the boxed panel zooms in on one side of the polygons, straightened out and stretched tall. The flat gold line is the circle, the amber curve is the outside polygon, the green curve is the inside one, and the band between them is the gap that traps π. The sides are straight; they only look curved because the circle has been flattened. "Gap stretched" says how many times the gap is enlarged so you can still see it.

  • inside polygon (dots are its corners)
  • outside polygon
  • the circle
  • gold digits in the readouts: decimals both bounds already agree on

Try this: press Double the sides and watch the stretch factor jump.

—
Sides n
—
Decimals pinned down
—
Inside: n·sin(π/n)
—
Outside: n·tan(π/n)

Now

Doubling without knowing π

Writing the bounds as n·sin(π/n) and n·tan(π/n) would need π itself. Archimedes didn't need it. Start from the hexagons, where the outside half-perimeter is a6 = 2√3 and the inside one is b6 = 3, then double with two kinds of average:

a2n = 2·an·bn / (an + bn) (harmonic mean)
b2n = √(a2n·bn) (geometric mean)
bn = n·sin(π/n) < π < n·tan(π/n) = an

Each doubling cuts the gap to about a quarter, because a − b ≈ π³/(2n²). That's 0.6 more decimals per doubling. His 96-gon gives 3.14103 < π < 3.14271. He had to round square roots with fractions as he went, rounding the safe way, and ended with 223/71 < π < 22/7: 3.140845… < π < 3.142857…, a slightly wider but still correct trap.

CodePython

LAB 2

darts at a square

Throw darts at a 1 × 1 square at random, so every spot is equally likely. A quarter of a circle with radius 1 fills π/4 of the square, about 78.5%. So the share of darts that land inside the curve is close to π/4, and 4 × that share estimates π. This is a Monte Carlo method: answering a question with random sampling. The randomness here comes from a seeded generator, so the same seed always throws the same darts.

darts

How to read this: each dot is one dart. 4 × (green ÷ all darts) is the estimate of π.

  • landed inside the curve
  • landed outside
  • a quarter of a circle
error vs darts · log–log

How to read this: lower is better.

  • your error, |estimate − π|
  • typical error 1.64/√n
  • 2 × typical
  • where you are now
—
Darts thrown
—
Inside the curve
—
Estimate 4·hits/n
—
Error vs typical

Why it's fair, and why it's slow

P(inside) = p = π/4 ⇒ E[4·hits/n] = 4p = π
σ = 4·√(p(1−p)/n) ≈ 1.642/√n

On average the estimate is exactly π: it is unbiased. Any single run misses by about σ, and σ only shrinks like 1/√n. One more correct decimal means a 10× smaller error, which takes 10² = 100× more darts.

CodePython

Related

Buffon's needle gets π from random needles dropped across floorboards: 006 · Probability.

LAB 3

a race of infinite sums

An infinite series is a sum that never stops: add a term, then another, forever. Some of them close in on π. Each added term is a step; the question is how many steps buy how many correct decimals. Five famous ones run side by side here, all given the same number of terms. Both axes are logarithmic, so every grid line is ten times the one before.

terms: 1,000
  • race clock: terms handed out so far

The runners

Leibniz π = 4·(1 − 1/3 + 1/5 − 1/7 + …)
Nilakantha π = 3 + 4/(2·3·4) − 4/(4·5·6) + 4/(6·7·8) − …
Wallis π = 2 · (2·2)/(1·3) · (4·4)/(3·5) · (6·6)/(5·7) ⋯
Machin π = 16·arctan(1/5) − 4·arctan(1/239)
arctan(x) = x − x³/3 + x⁵/5 − …
Chudnovsky 1/π = 12·Σk (−1)k(6k)!(13591409 + 545140134k) / ((3k)!(k!)³·6403203k+3/2)

The Leibniz series was known to Madhava's school in Kerala, India, centuries before Leibniz. Nilakantha Somayaji gave his series in the Tantrasamgraha, around 1501. Wallis published his product in 1656. John Machin used his formula for 100 digits in 1706. The Chudnovsky brothers published theirs in 1988, and record computations still use it.

Measured, not quoted

How the page counts

"Correct decimals" here is −log10|sum − π|, so 6 means the error is about one millionth. A term count "for 6 decimals" is the first n with |error| < 0.5×10⁻⁶, which is what rounding to 6 places needs. Leibniz and Wallis run in ordinary 64-bit floats, Nilakantha in double-double (about 31 digits), and Machin and Chudnovsky in exact integer arithmetic with 1,110 digits, checked against π computed separately by this page. The chart stops at 1,000 decimals.

CodePython

LAB 4

π shows up uninvited

π turns up in problems that never mention a circle. Add up 1/1² + 1/2² + 1/3² + … forever. Pick two whole numbers at random and ask whether they share a factor. Measure the area under a bell curve. Each answer has π hiding in it, and each one gives another way to estimate π. All three estimates below are live.

basel
1,000

How to read this: in Sum of 1/n², the thin vertical line is the N set by the slider. In Coprime pairs, the green line on the right is π estimated from the random pairs so far; it should stay between the two faint gold dashed curves most of the time. In Bell curve, the amber strips are the slices whose total area is measured.

—
π from Σ1/n²
—
π from coprime pairs
—
π from the bell curve
—
Error of the shown one

Now

Why π?

CodePython

LAB 5

a million digits of π

Below are the first 1,000,000 decimals of π, loaded as a 1 MB text file (it shrinks to under half that on the wire). They were computed with the Chudnovsky series and checked against an independent calculation. Start with the step-by-step: it turns the first 12 decimals into two pictures, one digit at a time. Then zoom out to the full million and compare π with 22/7, a fraction close to π, and with digits from a random number generator. The chord picture is inspired by the π art of Cristian Ilies Vasile and Martin Krzywinski.

walk: each digit is a step
chords: each pair is a line
how it works

first 1,000 digits are built in
Compute here
Chudnovsky + binary splitting, in a Web Worker
—
Digits in hand
—
χ² (lower = more even digit counts)
—
Walk ends this far from start
—
Computed in this browser

Now

π vs 22/7 vs random

22/7 = 3.142857… is a fraction, close to π (too big by 0.00126). The decimals of every fraction eventually repeat in a cycle, here 142857 forever. So its walk repeats one zigzag and marches off in a straight line, and it only ever uses 6 of the 100 digit pairs.

π is irrational: no fraction equals it, so its decimals never settle into a repeating cycle, and its walk never settles either. Statistically its digits look like the random ones, with every digit and every pair about equally common. That is what being normal would predict, which is conjectured, not proven.

Find your string

Random-looking, maybe random

χ² = Σd (Od − E)² / E, E = N/10
expected wait for string s = Σ 10j over every j where s's first j digits equal its last j

A number is normal if every string of k digits appears with frequency 10−k in the long run. π is conjectured to be normal, not proven. Nobody has proved it for √2 or for the 001 · golden ratio either. The digit counts and the walk above look exactly like those of a fair 10-sided die, which is evidence, not a proof.

Scale

The Guinness World Records record is 300 trillion digits, computed by Linus Media Group and KIOXIA in April 2025 with y-cruncher, which uses the Chudnovsky formula. StorageReview reported 314 trillion digits in December 2025.

CodePython