by Dirk Brockmann

This explorable is about prime numbers. It illustrates interesting patterns that emerge if you arrange the positive natural numbers \(1,2,3,....\) and so forth in a regular pattern in the plane and look at the distribution of the primes in the arrangement. Although prime numbers, as one might expect, don't follow some regular repetitive pattern, they are also not distributed completely at random. Instead, in all arrangements streaks and fragments of neighboring primes emerge. These structures are related to prime generating polynomials like the famous polynomial discovered by Leonard Euler.

This explorable follows three sequential steps. Press the large buttons from left to right as indicated and keep on reading...

This is how it works

Let's begin with the Ulam Spiral named after physicist Stanislaw Ulam). This is proabably the most famous number spiral related to patterns of prime numbers. The Ulam spiral is constructed like a growing spiral on a square lattice. If you press the left play button, you see how it grows up to \(N=121\).

In the spiral the prime numbers are black and the composite numbers (the numbers that aren't prime) gray.

Press the center play button to "accelerate" the process and zoom out until \(N=10000\) numbers are shown (of which \(1230\) are prime). You can focus on the primes, if you switch the display of composite numbers off using the corresponding toggle on the right.

Although the primes are somewhat distributed randomly, clear linear, fragmented structures can be seen. If you toggle "randomize locations" you can compare to a random distribution of black dots.

Euler's prime generating polynomial

These fragments are related to specific prime generating polynomial functions that produce long sequences of primes. The most famous function was discovered by Leonard Euler:


For \(n=0,...,40\) this equation generates a streak of prime numbers: 41, 43, 47, 53, 61, 71, 83, 97, 113, 131, 151, 173, 197, 223, 251, 281, 313, 347, 383, 421, 461, 503, 547, 593, 641, 691, 743, 797, 853, 911, 971, 1033, 1097, 1163, 1231, 1301, 1373, 1447, 1523, 1601, 1681, 1763.

For \(n=41\) it doesn't work anymore, because then \(p=41+41+41^2 = 43\times 41\) a composite number. Yet, even for larger \(n\) Euler's polynomial continues to generate long streaks of primes. You can see these in the Ulam Spiral by toggling the Euler switch on the right.

Here's another prime generating polynomial, discovered by Legendre:


For \(n=0,...,28\) this one generates a streak of primes: 29, 31, 37, 47, 61, 79, 101, 127, 157, 191, 229, 271, 317, 367, 421, 479, 541, 607, 677, 751, 829, 911, 997, 1087, 1181, 1279, 1381, 1487, 1597. For some reason, these are not as visible in the Ulam Spiral.

The Klauber Triangle

In this arrangement of the natural numbers a triangle of rows numbered \(m=1,2,3....\) is constructed, each row containing the numbers from \((m-1)^2+1\) to \(m^2\). The arrangements was invented by rattle snake expert Laurence M. Klauber in 1932. In the Klauber triangle the Euler primes are visible as clear vertical streaks.

The Sack Spiral

Probably the nicest number spiral is this one in which each number \(n\) is located at polar coordinates

\[r_n=\sqrt n,\qquad \theta_n = 2 \pi \sqrt n.\]

In the Sack Spiral the Euler primes correspond to a dense spiral with only few interruptions by composite numbers.

The Witch's Spiral

This spiral is much like the Ulam spiral only on a hexagonal lattice. In this arrangement neither Euler nor Legendre primes exhibit salient structures. However, for some reason, the South and South-East segments of the lattice exhibit short streaks of primes. You can see this clearly by switching the randomization toggle on and off.

Related Explorables:


A stochastic cellular automaton

Hokus Fractus!

Famous fractals

Weeds & Trees

Lindenmayer Systems

Anomalous Itinerary

Lévy flights

Stranger Things

Strange attractors

Particularly Stuck

Diffusion Limited Aggregation