← Laboratorium
Mathematics · experiment

Mathematical constant · geometry · chance

the number that is everywhere — Pi

Divide the circumference of any circle by its diameter and you always get the same number: π ≈ 3.14159. Its digits go on forever and never settle into a repeating pattern. We'll catch it by throwing darts, dropping needles, drawing polygons and adding up series — and then compute as many as a million of its digits in your browser.

Decimal digit no. 0 

To the experiments ↓

Space start / stop+− speed

π where there's no circle at all

π pops up in places that seem to have nothing to do with circles — in number theory and in infinite sums.

Two random integers

Pick two large whole numbers at random. The chance that they share no common divisor greater than 1 (they are coprime) is 6/π² ≈ 60.79%.

Pairs0
Coprime—
√(6/p)—

Why? For each prime p, the chance that p does not divide both numbers is 1 − 1/p². The product over all primes gives 1/(1 + 1/4 + 1/9 + …) = 6/π².

The Basel problem

What is the sum of the reciprocals of the squares? For more than 80 years nobody could work it out. In 1734 Leonhard Euler showed that:

1 + 14 + 19 + 116 + … = π²6 ≈ 1.644934
Sum Sn—
√(6 · Sn)—

This sum converges slowly: the missing remainder is almost exactly 1/n, so after a million terms we only have about 6 digits of π.

How does it work?

π is the ratio of a circle's circumference to its diameter. It's the same for a circle the size of a coin and for a planet's orbit — because all circles are scaled-up copies of one another. The same number governs the area of a circle, the volume of a sphere, waves, and probability.

C = π · d = 2πrcircumference of a circle with diameter d
A = π · r²area of a circle
π ≈ 4 · k/N,   σ ≈ 1.64/√NMonte Carlo: k hits in the quarter circle out of N throws; σ = 4·√(p(1−p)/N), p = π/4
P(crossing) = 2lπtBuffon's needle, l ≤ t
n·sin(180°/n) < π < n·tan(180°/n)perimeters of the n-gons inscribed in and circumscribed about a circle of diameter 1
π4 = 1 − 13 + 15 − 17 + …Leibniz (and before him Madhava of Kerala, 14th century)
π4 = 4 arctan 15 − arctan 1239Machin, 1706 — the first 100 digits of π
1π = 12 Σ (−1)k (6k)! (13591409 + 545140134k)(3k)! (k!)³ · 6403203k+3/2the Chudnovsky brothers, 1988 — about 14 digits per term; today's records are computed with this formula

Why are the methods so different in speed? Random throws (darts, needles) gain one digit only with a hundred times more tries. The Leibniz series after N terms is off by about 1/N, so each digit costs ten times more work. Archimedes' polygons narrow the interval fourfold with every doubling of the sides. Machin's series adds about 1.4 digits per term, and Chudnovsky's more than 14.

How does this page compute a million digits? In the background (in a separate thread, so the page doesn't freeze) the Chudnovsky formula is summed using “binary splitting” on huge BigInt integers, and at the end we do one big division and one square root. We check the result with Machin's formula, computed independently.

Simplifications: the darts and needles use the browser's pseudorandom generator, and the needles are perfectly thin line segments. Ordinary floating-point numbers have about 16 significant digits, so the Leibniz, Nilakantha and Wallis series can't show more than about 15 correct digits.