The Ulam spiral drawn as a connected path through the grid rather than as isolated marks.
Ulam’s doodle
Stanisław Ulam was sitting through a dull conference talk in 1963, doodling. He wrote
the integers in a square spiral — 1 in the middle, 2 to its right, then up, then left,
and so on — and circled the primes.
Diagonal lines appeared. He went back to Los Alamos, had a computer plot the first
65,000 integers, and the lines were still there.
The first numbers. The spiral turns after 1, 1, 2, 2, 3, 3, 4, 4 … steps, which is the
only structure in the layout:
for (var side = 0; side < 2 && running; side++)
{
for (var j = 0; j < steps && running; j++) { … }
var tmp = dx; dx = dy; dy = -tmp;
}
steps++;
Two sides at each length, then the length increases. Nothing about primes anywhere.
A sixth of the numbers, with the primes marked.
Why there are diagonals
A third, and the diagonals are unmistakable. They are real, and there is a partial
explanation.
Walk along a diagonal of the spiral and the numbers you pass are a quadratic in the
step index — expressions like 4n² + bn + c. Some quadratics produce primes far more
often than chance would suggest: Euler’s n² + n + 41 is prime for every n from 0 to
39, and is still unusually prime-rich thereafter.
Every diagonal in the picture is one such polynomial, and the bright ones are the
prime-rich ones.
Immediately visible, too: no even diagonal exists, because half the diagonals consist
entirely of even numbers.
Two thirds.
What is not known
The mechanism above says which lines can be prime-rich. It does not say why some
quadratics are and others are not, and that is the open part.
Hardy and Littlewood’s Conjecture F, from 1923, predicts the density of primes along any
such quadratic — and it is still a conjecture, a century later. It is not known whether
even one quadratic produces infinitely many primes.
So the picture shows a pattern that everyone can see, that has a partial explanation, and
that rests on something nobody has proved.
The full spiral.
The primality test
if (num % 2 == 0 || num % 3 == 0) return false;
for (var i = 5; i * i <= num; i += 6)
if (num % i == 0 || num % (i + 2) == 0) return false;
Trial division with a 6k±1 wheel: every prime above 3 is one more or one less than a
multiple of six, so two thirds of the candidate divisors can be skipped. Adequate for
integers in the tens of thousands, and it means the piece has no lookup table — every
mark is decided from scratch.
Five renderings
| Rendering | Mode | Ink |
|---|
| Cyber Cyan | 3 | cyan on black |
| Neon Gold | 3 | gold on near-black |
| Deep Violet | 3 | violet on near-black |
| Trace | 0 | silver on near-black, no marks |
| Deep Field | 3 | orange on black, scale 4 |
Mode selects what a marked number contributes: a point, a connecting segment, a
printed numeral, or a combination. Drawing the path rather than isolated dots is what
distinguishes this piece from its sibling — the spiral’s route becomes visible, and the
prime diagonals then read as places where the path is dense rather than as rows of
marks.
Determinism
Nothing is seeded and nothing is random. Every mark is a primality test on an integer.