In 1963, Stanislaw Ulam was attending a tedious lecture and began doodling: he wrote integers in a square spiral on graph paper and highlighted the prime numbers. He was startled to find that the primes did not scatter randomly but instead clustered along diagonal lines crossing the spiral. A prime along a diagonal corresponds to a quadratic polynomial evaluated at consecutive integers — for example, the rich diagonal n² + n + 41 produces a prime for every integer n from 0 to 39, a polynomial discovered by Euler in 1772. Despite intense study, no one fully understands why certain diagonals are so much richer in primes than others.
Adjust the spiral size to see more of the pattern emerge, toggle between the classic Ulam view and the Sacks spiral (which arranges integers on an Archimedean spiral placing perfect squares on a single ray), and overlay known prime-rich polynomials to highlight their diagonals.
How is the Ulam spiral constructed?
Start at the centre with 1, then wind the integers outward in a square spiral: right, up, left, left, down, down, right, right, right, … Each successive L-shaped shell adds the next ring of integers. Prime numbers are marked with a coloured cell. The key observation is that many diagonals of the resulting grid contain far more primes than the diagonal average, forming visible stripes across an otherwise irregular-looking grid of dots.
Why do diagonal lines appear in the Ulam spiral?
Each diagonal in the spiral corresponds to a quadratic polynomial p(n) = an² + bn + c for some constants a, b, c determined by the diagonal's position. Certain quadratics yield many prime values — notably the Euler polynomial p(n) = n² + n + 41, which is prime for n = 0, 1, 2, …, 39 (40 consecutive primes). Such polynomials correspond to especially dense diagonals. The underlying reason — why some quadratics yield more primes — connects to deep unsolved problems in number theory, including Bunyakovsky's conjecture.
What is the prime number theorem and how does it relate to the spiral?
The prime number theorem states that the number of primes up to N is approximately N/ln(N), meaning that near N, about 1 in ln(N) integers is prime. On the Ulam spiral at radius r (roughly the r²-th integer), primes appear with density ~1/(2ln(r)). The average density decreases outward — the spiral looks sparser near the edges — but the diagonal structure persists. The local density variations visible in the spiral hint at correlations between primes that go beyond the simple asymptotic average.
Stanislaw Ulam (1909–1984) was a Polish-American mathematician who made fundamental contributions to set theory, ergodic theory, nuclear physics, and computational mathematics. He was a key member of the Manhattan Project and co-invented the Teller-Ulam design for thermonuclear weapons. He also co-developed the Monte Carlo method with John von Neumann (also during the Manhattan Project) — a numerical technique now indispensable in physics, finance, and statistics. The spiral bears his name from his 1963 doodle, later investigated computationally with colleagues at Los Alamos.
The Sacks spiral, invented by Robert Sacks in 1994, places integers on an Archimedean spiral so that perfect squares (1, 4, 9, 16, …) all lie on the same radial ray. This means each ring of the spiral corresponds to one "turn" between consecutive squares. Primes highlighted on the Sacks spiral also show curvilinear structures — arcs and parabolas rather than straight diagonal lines — because quadratic polynomials become smooth curves in the continuous spiral geometry. Both spirals visualise the same arithmetic fact from different geometric perspectives.
Bunyakovsky's conjecture (1857) states that an irreducible polynomial p(n) with integer coefficients produces infinitely many prime values as n ranges over positive integers, provided it satisfies one necessary condition: no fixed prime divides p(n) for all n (no "fixed divisor"). For example, p(n) = n² + n + 41 has no fixed prime divisor and is conjectured to produce infinitely many primes — though this remains unproven. The Bateman-Horn conjecture (1962) gives a precise quantitative version predicting the density of prime values of a set of polynomials.
Yes. The hexagonal spiral (arranging integers on a triangular lattice in a spiral) also shows diagonals rich in primes, corresponding to different sets of quadratic polynomials with the hexagonal geometry. Arrangements based on Gaussian integers (complex integers a+bi) reveal prime patterns in 2D via the Gaussian primes, which occur where |a+bi|² = a²+b² is prime. Visualising Gaussian primes shows a different but equally striking structure of diagonal and circular symmetry.
Twin primes are pairs of primes differing by 2 (e.g., 11 and 13, 17 and 19, 41 and 43). In the Ulam spiral, twin-prime pairs appear as adjacent dots on the same diagonal (separated by one grid step along the diagonal). The twin prime conjecture states there are infinitely many twin prime pairs — still unproven, though Yitang Zhang's 2013 breakthrough showed there are infinitely many prime pairs with gap ≤ 70,000,000, later reduced to 246 by the Polymath project.
The diagonal patterns require proving that specific quadratic polynomials represent infinitely many primes — a statement beyond current mathematical tools. The key obstacle is that while the Riemann hypothesis and its generalisations give control over how primes are distributed on average, the specific fluctuations that create denser diagonals involve correlations between primes that are captured only conjecturally by the Hardy-Littlewood circle method. Fully explaining the visual patterns would likely require resolving major open problems in analytic number theory.
The Riemann zeta function ζ(s) = Σ 1/n^s encodes the distribution of all primes via its zeros. The Riemann hypothesis (all non-trivial zeros have Re(s) = 1/2) is equivalent to the "best possible" error bound in the prime number theorem: π(N) = Li(N) + O(√N log N). The diagonal structures in the Ulam spiral are closely related to the error term — they represent non-random fluctuations in prime counts that, if the Riemann hypothesis is true, are bounded in a precise way. Understanding one would illuminate the other.
Yes — a 3D Ulam spiral can be constructed by winding integers in a cubic spiral (each layer a 2D Ulam spiral, stacked). Primes highlighted in 3D again reveal planar structures analogous to the 2D diagonals, corresponding to quadratic forms in three variables. More commonly, 3D prime visualisations use "prime cubes" where each prime n maps to a point at position (n mod p₁, n mod p₂, n mod p₃) for small primes p₁, p₂, p₃, revealing lattice structure from the Chinese Remainder Theorem.