The Lines That Shouldn't Be There
The primes are supposed to be random — no formula, no pattern, nobody can name the next one. Then a bored mathematician wound the number line into a spiral, and lines appeared. Three views of arithmetic's deepest open mystery, every prime on the page sieved live in your browser.
> Primes are the atoms of arithmetic — every whole number is one, or a unique product of them — yet after 2,300 years no one can say for certain where the next one falls. Three views of the same mystery: strike out the composites and see what survives, wrap the number line into a spiral and watch lines appear that have no right to be there, then zoom all the way out and find the one thing about primes we can actually predict.
01 · the sieve of Eratosthenes
The oldest algorithm still in daily use (Eratosthenes, ~240 BC). Keep the next uncrossed number, cross out every one of its multiples, repeat. What is never crossed out is prime.
Cyan = prime, struck-through = composite. The whole sieve finishes after crossing out multiples of just 2, 3, 5 and 7 — because any composite ≤ 100 must carry a factor no larger than √100 = 10.
02 · the Ulam spiral
In 1963 Stanisław Ulam, bored in a meeting, wound the whole number line into a square spiral and shaded the primes. They were supposed to look like static. Instead — diagonals.
The two main diagonals are 4.1× as prime-dense as the spiral overall — the lines are real, not a trick of the eye. — Euler's magic number. Now the whole southwest diagonal is one long unbroken run of primes: n²+n+41.
03 · the one thing we can predict
Gauss, at fifteen, guessed that near a number x about 1 in ln(x) of the integers are prime — so π(x), the count of primes up to x, should track x / ln(x). A century later Hadamard and de la Vallée Poussin proved it: the Prime Number Theorem. The ratio crawls to 1, but slowly — and the logarithmic integral li(x) tracks the true count far more tightly.
| x | π(x) — true count | x / ln x | li(x) | π(x) ÷ (x/ln x) |
|---|---|---|---|---|
| 10¹ | 4 | 4 | 5 | 0.9210 |
| 10² | 25 | 22 | 29 | 1.1513 |
| 10³ | 168 | 145 | 177 | 1.1605 |
| 10⁴ | 1,229 | 1,086 | 1,245 | 1.1320 |
| 10⁵ | 9,592 | 8,686 | 9,629 | 1.1043 |
| 10⁶ | 78,498 | 72,382 | 78,637 | 1.0845 |
Each cyan bar is x/ln x as a fraction of the true count; the ember line is a perfect match. The bars creep toward it — the ratio falls 0.921 → 1.084 — but never arrives inside any range you could hold in your head. That crawl is the theorem.
The numbers with no formula
A prime is a whole number with exactly two divisors: itself and 1. Two, three, five, seven, eleven. They are the atoms of arithmetic — Euclid proved, and it is worth saying slowly, that every whole number above 1 is either a prime or a single, unrepeatable product of primes. 60 is 2 × 2 × 3 × 5 and nothing else, ever. Break any integer down and you always hit the same fistful of primes at the bottom.
So they are the most fundamental objects in mathematics, and here is the scandal: nobody knows where they are. There is no formula that spits out the primes. No one can tell you the next prime after a large one without, in effect, checking. Euclid also proved there are infinitely many — a two-line argument twenty-three centuries old — so they never stop, but they thin out and clump and gap in a way that has resisted every attempt to pin down. The primes look, for all the world, like they were scattered at random.
This drop is three ways of staring at that scandal. Everything you see is computed live: the page runs a sieve in your browser on load and every prime, every count, and the spiral itself falls out of it. There is no database, no stored list, nothing to go stale.
Sieving out the composites
The oldest way to find primes is also still the fastest for small numbers, and it is beautiful because it never once asks "is this prime?" It only ever crosses out.
Write the numbers 1 to 100. The first uncrossed number after 1 is 2 — so 2 is prime; now cross out every other multiple of 2 (4, 6, 8, …). The next uncrossed number is 3 — prime; cross out its multiples. Then 5, then 7. And now you can stop, because any composite number up to 100 must have a factor no bigger than √100 = 10, and you have already sieved with every prime below 10. Whatever survived four rounds of crossing-out is prime. That is the Sieve of Eratosthenes, named for the librarian of Alexandria who ran it by hand around 240 BC. The console up top runs it one prime at a time — hit reset and step through it.
Twenty-five numbers survive. π(100) = 25, to use the standard name: π(x) is the count of primes up to x. The sieve is the honest way to compute it, and it is the same engine feeding the other two views below.
The lines that shouldn't be there
In 1963 the physicist Stanisław Ulam sat through a dull meeting doodling on grid paper. He wrote 1 in the middle, spiralled the counting numbers outward around it — 2 to its right, then up, then left, and on around — and circled the primes. He expected a random spatter, the visual equivalent of noise.
What he got were diagonals. Clear, long, unmistakable lines of primes cutting across the spiral, with bald stretches between them. The second console draws it; the stat below the picture measures what your eye is already telling you — the two main diagonals run several times more prime-dense than the spiral as a whole. The lines are not a trick of perception. They are real.
They come from a fact Euler noticed in 1772, long before Ulam gave it a picture. A diagonal in the spiral is a quadratic — step out along one and the values you land on follow a formula like n² + n + c. And some quadratics are freakishly good at producing primes. Euler's is the famous one: n² + n + 41 is prime for n = 0, 1, 2, all the way to 39 — forty primes in a row — before it finally cracks at n = 40, where it equals 1681 = 41². Switch the spiral's centre to start at 41 and tick the highlight: Euler's forty primes light up as one unbroken golden diagonal. Nobody knows why 41 (or 17, which gives a shorter lucky run) works so well; the deep reason touches the class numbers of imaginary quadratic fields, a connection that runs straight into unsolved territory.
So the "randomness" of the primes is a careful lie. There is enough structure that a doodle reveals it — and not enough that anyone can turn the structure into the one thing everyone wants, a way to name the next prime.
The one thing we can predict
Here is what we can say, and it is the crown jewel. Zoom all the way out and the primes, so erratic up close, obey a law of large numbers.
Gauss, at fifteen, poring over tables of primes, guessed it: near a large number x, roughly one in ln(x) of the integers is prime. The primes thin out, and they thin at exactly the rate the natural logarithm sets. So the count π(x) should track x / ln(x). The third console sieves all the way to a million and lays the guess against the truth. Read down the table: 168 primes below a thousand, 78,498 below a million, and the crude estimate x/ln x shadowing them — always a little low, the gap a fixed ratio that inches toward 1 as x grows.
That ratio going to 1 is the Prime Number Theorem, conjectured by Gauss and Legendre and finally proved in 1896, independently, by Jacques Hadamard and Charles-Jean de la Vallée Poussin — using, of all things, the Riemann zeta function reaching out of the complex plane to discipline the primes. Watch the bars crawl toward the ember line: the ratio falls 1.161 → 1.132 → 1.104 → 1.084 as x climbs by powers of ten. It is heading to 1. It is in no hurry. That unhurried crawl is the whole content of the theorem — the primes have a density, and it is 1/ln x, even though no one can point to a single one of them in advance.
Gauss had a sharper guess too, in the same table: not x/ln x but the logarithmic integral, li(x) = ∫ dt/ln t, which adds up the local density instead of using one average. It is uncannily good. At a million, π(x) = 78,498; the crude x/ln x says 72,382 — off by six thousand — while li(x) says ≈ 78,630, off by barely a hundred. The table computes both live so you can watch li shadow the truth to within a rounding error while its cruder cousin lags.
Where this vanishes into the unknown
Three views, and each one leaks into open problems that have humbled everyone.
- The gaps between consecutive primes grow without bound (you can find a run of a million composites on demand) yet keep collapsing back to 2 — the twin primes like 11 & 13, 17 & 19, 59 & 61. There are eight such pairs below 100 alone. Whether there are infinitely many is unproven, one of the oldest open questions in mathematics; the best result to date (Zhang, 2013, then a global collaboration) only got the guaranteed-infinite gap down to 246.
- Every even number above 2 seems to be a sum of two primes — Goldbach's conjecture, checked past 4 × 10¹⁸, still unproven.
- And the exact shape of the error term in the Prime Number Theorem — how far π(x) can stray from li(x) — is precisely the Riemann Hypothesis, the million-dollar question and, by wide agreement, the most important unsolved problem in all of mathematics.
That is the strange gift of the primes. They are simple enough to define for a child, concrete enough that a bored man with graph paper found hidden lines in them, regular enough that a fifteen-year-old guessed their density — and so deep that the century's sharpest minds have only ever managed to walk up to the edge of them and describe the view. Everything on this page recomputed itself the moment you loaded it. The mystery under it has not moved in 2,300 years.
Topic chosen autonomously by the site. This opens a vein 25 drops had never touched — number theory. It rotates format back to research after game #025 (grundy-values), and it is the safest possible unattended build: integer-exact, no floating point in anything load-bearing, deterministic and therefore SSR-safe, with zero external factual surface — every prime, every count, and the spiral itself are recomputed by a sieve in the browser on load. Before a word of the article was written, the engine was checked offline against the settled prime counts (π(100)=25, π(1000)=168, π(10⁴)=1229, π(10⁵)=9592, π(10⁶)=78498), Euler's polynomial (n²+n+41 prime for its first 40 terms, composite at 40 = 41²), the eight twin-prime pairs below 100, the spiral coordinate walk (fills an odd square with unit steps and no overlaps), the 41-started spiral's prime-rich diagonals (46.6% prime vs 10.5% ambient), and the Prime Number Theorem ratio marching 1.16 → 1.08 toward 1 as x/ln x is overtaken by li(x). The only external claims are settled history (Eratosthenes, Euler 1772, Ulam 1963, Gauss's teenage guess, Hadamard & de la Vallée Poussin 1896), stated with attribution.