101
1
1.0

More information about the Ulam spiral

Ulam spiral

The Ulam spiral writes the positive integers in a square, starting at 1 and turning counterclockwise. Mark the primes and they gather on diagonal lines. Each of those lines is a quadratic polynomial. Start the spiral at 41 and one diagonal is Euler's formula, prime for forty steps in a row. Drag to move, scroll to zoom, and click a cell to read the quadratic on its diagonal.

How it works

  1. Open this page and look at the primes. The diagonal streaks are the whole discovery.
  2. Drag to move and scroll to zoom, or open the 5×5 favorite and read every number.
  3. Choose Euler's 40 or click a cell to read its polynomial, then save a PNG.

A spiral of the integers

The path starts at 1. It steps right, then turns left, and each straight run is one step longer than the one before. The first square is the familiar block with 17 in the top left and 25 in the bottom right. Primes are marked. Composites can be shown faintly or hidden, which is the picture Ulam drew in 1963.

Diagonals are formulas

A diagonal of the square is exactly the values of a quadratic 4n² + bn + c. Some of those formulas factor and the diagonal is empty. Others, such as Euler's, are prime far more often than a random number of the same size. Click a cell and the readout gives the formula, the longest prime run on that line, and how that compares with 1 / ln n.

Forty primes, one diagonal

n² + n + 41 is prime for n = 0 through 39. At n = 40 the value is 1,681 = 41². On the spiral those numbers are the diagonal 4n² − 2n + 41 once the center cell is 41. The run goes from 1,523 through 41 to 1,601, forty primes, and then it breaks. Hardy and Littlewood's conjecture predicts that this polynomial is prime nearly seven times as often as chance. It does not prove that the primes continue forever.

Frequently asked questions

What is the Ulam spiral?

A square spiral of the positive integers, devised by Stanisław Ulam in 1963. Start at 1, step right, and turn counterclockwise. Mark the primes and they gather on diagonal, horizontal, and vertical lines.

Why do the primes line up?

Each of those lines is a quadratic polynomial, 4n² + bn + c. Some of those formulas are divisible by a small prime almost all the time. Others, including Euler's, almost never are.

What is Euler's run of 40 primes?

n² + n + 41 is prime for n = 0 through 39, and 41² at n = 40. Start the spiral at 41 and those values are one diagonal, 4n² − 2n + 41, from 1,523 through 41 to 1,601.

Does the spiral prove a formula for the primes?

No. It makes the variation visible. Hardy and Littlewood's Conjecture F predicts how rich each quadratic should be. No quadratic has been proved to produce infinitely many primes.

Does the spiral leave my device?

No. The sieve, the spiral, and the picture are computed in your browser. Save a PNG or open the canvas in the PictorX editor.

Ready to try it?

Open PictorX in your browser — no install, no credit card required to start.

Go to Editor