Interactive geometry & the essays beside it — Inês Ferreira, Lisbon

Prime spirals and pattern-hunger

May 3, 2026 · 4 min · probability, teaching

In 1963 the mathematician Stanisław Ulam sat through a dull lecture and, to stay awake, wrote the whole numbers in a square spiral: 1 in the middle, then 2, 3, 4, 5 winding outward. Idly, he circled the primes. He expected a mess. What he got was a picture full of diagonal streaks, and the streaks have been unsettling people ever since. The prime-spiral toy lets you build Ulam’s doodle for yourself and hunt those streaks at whatever zoom you like.

The doodle that shouldn’t have a pattern

Primes are supposed to be the unpredictable ones. They thin out as you climb — around a big number n, roughly one in every ln n numbers is prime — but which numbers get to be prime looks, for all the world, like a coin the universe flips without telling anyone the rule. So when you lay them on a spiral and clear diagonal lines leap out, the first honest reaction is unease. Randomness is not supposed to make lines.

The square built up in layers

Why some lines are real

Here is the reassuring half of the answer. A diagonal in the spiral is not a random alignment; it is a formula. Because of how the spiral wraps, the numbers along any given diagonal are the values of a quadratic — something of the shape 4k² + bk + c as k counts along the line. Some of these quadratics are simply better at producing primes than others, and that is a real, provable fact about polynomials, not a trick of the eye.

The most famous is Euler’s k² + k + 41, which spits out prime after prime for every k from 0 all the way to 39 — forty primes in a row before it finally stumbles. On the spiral, a prime-rich quadratic like that shows up as a long, dark, unmistakable streak. So the diagonals are telling the truth: certain quadratic formulas really do concentrate primes, and the picture is a genuine map of that concentration.

Why some lines are a lie

And here is the half a teacher must not skip. Not every streak your eye finds is real. Stare at any large field of scattered dots — genuinely random ones, sprinkled by a dice-roll — and your visual system, which was tuned on the savannah to catch the tiger in the grass, will hand you lines, curves, and clusters that are pure noise. We are pattern-hungry. It is our finest and most dangerous trait. The prime spiral is doubly seductive because it mixes real diagonals with imaginary ones, and from the inside they feel identical.

Lines that only look parallel

This is exactly why I put the toy in front of students, and exactly why I make them slow down. The spiral is a superb machine for generating conjectures: “that diagonal looks dense — is it?” is a wonderful question. But a diagonal that looks dense is a hypothesis, not a result. To promote it you check the formula, test more terms, and — if you are lucky and it is provable — prove it. Many apparent patterns survive; many evaporate the moment you count carefully. Telling the two apart, with arithmetic rather than enthusiasm, is mathematics.

So the prime spiral teaches a lesson that reaches far past primes. The world hands us suggestive pictures constantly — in data, in charts, in the streaks our own minds paint over randomness. The discipline is not to stop seeing patterns; you cannot, and you should not want to. The discipline is to treat every pattern you see as a question addressed to the evidence, and to let the counting, not the wanting, cast the deciding vote. Ulam’s bored doodle is, quietly, a lesson in how not to fool yourself — which Feynman called the first principle of all science, and which no badge or streak-counter will ever teach.