An Ulam spiral is a pattern of numbers. It was discovered in 1963 by Stanislaw Ulam who, amongst other things, was a mathematician. With a flair for finding simplicity in complexity he developed many mathematical tools.
Ulam, bored in a scientific meeting, decided to draw the postive integers in a grid. Starting with 1 in the middle and spiraling out from the centre. Not the sort of thing most people would do, but it was right up Ulams alley... especially when he was bored.
A positive integer spiral
You will find renditions of the spiral drawn in different directions to the above spiral (Figure 1). When I say 'direction' I mean the position of the numbers 2 and 3... which then defines the rest of the spiral. I headed South and then East because it matches the direction I used in the logo for this website.
Ulam went one step further with his boredom and decided to circle all the prime numbers in his drawing.
If you are not sure what a prime number is, please watch this YouTube clip:
Here is the same number spiral with the prime numbers circled:
A positive integer spiral
Ulam was surprised to find that the prime numbers linked together in diagonal lines. Prime numbers are always odd numbers (except for 2) so they can only exist in the diagonals anyway... look at all the odd numbers in the above grid and you will see what I mean, the odd numbers are only next to each other in the diagonal directions. BUT, having said that, a random selection of odd numbers does not result in linking of diagonal lines to this extent. The story goes that Ulam drew a larger spiral after the meeting to investigate his suspicions.
The integer number spiral in a grid, with prime numbers marked is know as an Ulam spiral.
On this site I create Ulam spirals with software. It does not usually create the Ulam spirals as grids of numbers, instead each pixel in the image is considered an integer. If the integer is prime then it is rendered as a pixel. Please note that the software creates spirals heading in the direction right and then down.
Below (Figure 3) is a 400 x 400 pixel wide Ulam spiral... that's a total of 160,000 pixels... or 160,000 integers. Prime numbers are the black pixels. There are 14,683 primes (black pixels) in this Ulam spiral. To view a huge Ulam spiral with 10,000,000,000 pixels / integers then click here.
Ulam Spiral, 1 to 160,000
The diagonal lines that Ulam noticed give the image a cross hatch effect. But how does it compare to a random distribution of odd numbers?
Below (Figure 4) is a 400 x 400 pixel wide image of 14,683 randomly chosen pixels that correspond to odd positions on the number spiral. There are 14,683 random pixels because that's how many primes there are in an Ulam spiral of the same size.
14,683 Random Odd numbers in 400 x 400 pixels
There are short diagonal lines visible, but they do not even come close to matching the length of the diagonal lines visible in the Ulam spiral.
There are some that claim that these diagonal lines are explained by the fact that we know that all primes are of the form 6n +/ 1 (except 2 and 3). This doesn't quite work either, we still don't get the diagonal alignment to the extent that we see in the Ulam spiral. Below is an image containing 14,683 random integers that land on the positive integer spiral and are of the form 6n +/ 1. This was achieved by first creating an image of all integers that conform to the rule 6n +/ 1 and then randomly removing black pixels (possible primes) until there were 14,683 left.
14,683 Random integers of the form 6n +/ 1 in 400 x 400 pixels
There is certainly more alignment (not suprisingly)... but in the Ulam spiral there are longer diagonal lines and in the cases that there are longer digonal lines they tend to fall on the same diagonal.
