What you are looking at
Write 1 in the middle of a sheet of graph paper. Write 2 to its right, 3 above that, then 4 and 5 to the left, 6 and 7 below, and keep turning. The whole numbers wind outward in a square spiral. Now go back and put a dot on every prime.
The dots do not scatter. They line up along diagonals — long, obvious, unmistakable streaks that no amount of squinting will turn into an accident. This is the Ulam spiral, and the diagonals are the reason it is famous.
The explanation is less mysterious than the picture. A diagonal ray leaving the centre of a square spiral is the set of values of a quadratic: walk along one and the numbers you step on are 4k² + bk + c for fixed b and c, because one full turn of the spiral adds another 8k cells. Some quadratics are simply better at producing primes than others, because they never hit certain small factors. Euler's famous polynomial n² + n + 41 is prime for every n from 0 to 39 — forty primes with no gaps — and its even and odd terms split into exactly two such rays, 4k² + 2k + 41 and 4k² − 2k + 41, which happen to be the two halves of one diagonal line. Start the spiral at 41 and that run of forty lays itself down as a single unbroken streak through the centre.
What remains mysterious is why some quadratics are so much richer than others, and how rich they can get. That question is open. The Bunyakovsky conjecture, which says a suitable irreducible polynomial should produce infinitely many primes, has never been proved for a single polynomial of degree two or higher.
Try this
- Press Euler's 41, which starts the count at 41 instead of 1. One diagonal line through the centre goes solid — twenty dots out one way, twenty out the other. That is Euler's polynomial, made visible.
- Switch to the Sacks spiral, which places n at distance √n and angle 2π√n. The squares now line up on a single ray pointing right, and the prime-rich quadratics become curved arms instead of diagonals.
- Turn on Shade by divisors. Primes stay dark; numbers with many prime factors go pale. The whole plane develops a grain, and the prime diagonals turn out to be the ridges of a much larger pattern.
- Push the grid width to its widest setting. The diagonals never fade out. They thin, because primes thin, but the streaks persist as far as the canvas goes.
- Watch the two count readouts. The Li estimate is the logarithmic integral, the classical prediction for how many primes there should be in the range on screen. It is usually right to within a fraction of a percent, and nobody can prove how close it has to stay.
Notes
Stanisław Ulam drew the first one in 1963, on paper, while bored at a scientific meeting. He was doodling in a grid, noticed the primes falling into lines, and went back to Los Alamos to have a computer print a bigger version. It made the cover of Scientific American in March 1964 and has been in circulation ever since.
The honest caveat: a random set with the same density as the primes, sprinkled on the same spiral, does not produce diagonals. The pattern is real. But it is also, at bottom, a picture of the fact that even numbers are not prime and multiples of three are not prime — the diagonals are what you get when the trivial sieve conditions are drawn in polar coordinates. It is a genuine structure with a partly boring explanation and a wholly unsolved core, which is a fair description of the primes in general.
Further reading
M. L. Stein, S. M. Ulam and M. B. Wells, "A Visual Display of Some Properties of the Distribution of Primes," American Mathematical Monthly (1964). The variant spiral is due to Robert Sacks (1994).