My Mobile Page

J.J.'s Quick Summary of the Ulam Spiral

Background

    Prime numbers are numbers which have no factors other than themselvs and one. They are used in many different algorithms, including some cryptography methods. In cryptography, a private key might be two different large primes, and the public key would be their product. Because we don't yet have quantum computers, factoring large numbers is difficult and time consuming, so finding the only two non-one numbers which multiply to the public key is nearly impossibly for anyone who doesn't already know the primes used to generate it.

    Because primes are so useful, and so important to cryptography, it would be bad if large primes were predictable and could easily be generated. Luckily for us, primes are seemingly random.

Primes Below 100
Source
Nth Prime Prime #
25 Primes < 100
0 to 2512
23
35
47
511
613
717
819
923
25 to 501029
1131
1237
1341
1443
1547
50 to 751653
1759
1861
1967
2071
2173
75 to 1002279
2383
2489
2597

Story

    Along comes our friend Stanislaw Ulam.  He was a cool dude, a mathematician. In 1963, during a long and boring presentation he does what any good scientist does -- he doodles. He started writing down the integers, with one at the center and spiraling outwards, like so:


Spiraling Numbers

    Next, he marked only the prime numbers. He found that the seemingly random prime numbers seemed to stick together in diagonal lines.


Spiraling Numbers Shaded

    In fact, when examined with the aid of a computer, large images may be generated showing seeming patterns to the primes, when ordered spiraling. There seem to be certain diagonal lines which start to appear. Even when there's a break in the diagonal line it is often picked up again on the same line. No matter how much you expand the diagonal lines keep appearing.

    One of the reasons for this phenomenon is that even though primes are random there are certain families of primes. These families might fit according to a polynomial rule, which happens to lie on certain diagonals when the numbers are ordered via a spiraling technique. Interestingly, even if you started the Ulam Spiral at a random number, instead of 1, diagonals would still appear.

Construction and Sample Images of Different Sized Ulam Spirals

Construction

  1. Preliminary steps
    1. Pick how large you want your spiral (see below for size 15 and 101).
      • Note: if you want a square final image with 1 at the center, your dimension must be odd, for there to be a center.
    2. Choose a color for prime numbers (black used below).
    3. Choose a color for composite numbers (white used below).
    4. Obtain (grid) paper or computer skills.
  2. Make a grid of square boxes (or pixels).
  3. Number the center square 1.
  4. Number the square to the right of the frist square 2.
  5. Number the square above the previous square 3.
  6. Continue spiraling outward and numbering the squares until none are left, or until you get tired.
  7. Color in every composite number with your chosen color for composites.
  8. Color in every primes number with your chosen color for primes.
  9. Observe the awesomeness you have made.

A couple gifs and final images I made using Python and GIMP.

ULAM's Spiral Construction for 15x15
Creation of Ulam Spiral of size 15x15
ULAM's Spiral Construction for 101x101
Creation of Ulam Spiral of size 101x101
ULAM's Spiral for 201x201
Ulam Spiral of size 201x201
Link to Ulam Spiral of size 10001x10001
(Warning: large (>7MB) file)