Write the integers in a square spiral, mark the primes, and diagonal lines appear that nobody can explain.
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.
Renderings
| Rendering | Zoom | Canvas | Ink |
|---|
| Cyber Cyan | 0.70 | 800×800 | cyan on black |
| Neon Coral | 0.65 | 800×800 | coral on near-black |
| Laser Purple | 0.75 | 800×800 | purple on near-black |
| Forge | 0.50 | 800×800 | amber on near-black |
| Frost | 1.05 | 800×800 | pale blue on near-black |
| Museum | 0.70 | 1000×1000 | cyan on black, warm mat |
Zoom sets the spacing between consecutive integers, so it decides how many the frame
holds — and therefore how many diagonals are visible. Forge packs the most (Zoom 0.50):
prime marks are tiny and the diagonals read as fine striations across a dense field.
Frost opens the widest (Zoom 1.05): fewer integers reach the frame edge, each prime
ring is clearly legible, and the diagonal geometry is directly traceable.
Museum is a gallery presentation of the Cyber Cyan design. A 100 px warm mat
surrounds the 800×800 art area on a 1000×1000 canvas, leaving the spiral itself
unchanged. It is a framing layer, not a new colour variant.
Determinism
Nothing is seeded and nothing is random. Every mark is a primality test on an integer.