Back to home page


Plotting Primes in Arrays

Stanislaw Ulam's Square Spiral

Stan Ulam plotted the prime numbers in a square spiral. The black and white image below is a copy of the illustration in Ulam's book and in the original paper in Math Monthly. The idea of a square spiral plotting of primes is one that Ulam developed at Los Alamos in the 50's. I've reproduced the image from a volume by Manfred Schroeder. Ulam plotted a dark point for every prime number and left non-primes unmarked.

Ulam's square spiral array of primes

The plotting of points starts with the number 1 at the center of the image and spiral around in ever larger squares like the simple example below. In the sample plot below, I've colored the prime numbers with a blue background and the non-prime with a yellow background.

17

16

15

14

13

18

5

4

3

12

19

6

1

2

11

20

7

8

9

10

21

22

23

24

25

A number of intriguing "strings" of primes appear in Stanislaw Ulam's square spiral plot. It would be nice if we could find a way to plot all the primes or even to find a way to plot many or some of the primes. According to Manfred Schroeder, "Many primes are of the form 4n^2 + an +b, which makes them lie on straight lines if n is plotted along a square spiral."



My Triangular Array

I loved the patterns generated by Ulam's square spiral plotting of points, but I never felt comfortable with the idea of a square spiral. Where do you start? Which way do you go? Why a square spiral? I decided to try using a triangle instead of a square. In addition, instead of using a spiral format to grow the plot I choose to grow the array from a single point at the bottom of the plotting area. Then I add new rows above the initial point, each row growing by one point in width.

22 23 24 25 26 27 28
16 17 18 19 20 21  
11 12 13 14 15    
7 8 9 10      
4 5 6        
2 3          
1            

After the initial computer coding I cleaned up the plot graphics from the right-triangle format in the table above to the centered equilateral triangle plot shown below. The plot below is a small part of a larger array. Note the strong vertical "strings" or columns that appear in the triangular array. Vertical columns with a high percentage of primes stand out in the triangular array just as they do in the square array. The strongest column is offset to the right of center by 29. Plus 12, plus 18, minus 17 and - 38 are the offsets for other prominent columns.

Since the number of dots in each horizontal row in the triangle is one more than the row before, the values for any vertical column of dots can be computed by finding the sum of the numbers up to the row in question, adding half to get to the center of that row, and then adding or subtracting the offset.

Nugent's triangular array of primes

The next illustration contains a screen shot of a plot of the prime numbers in the first half-million digits. To create this image I sieved the prime numbers up to 480,000 and then plotted the primes with a white point. The bottom row contains one white point for the number 1. The next row up contains the number 2 and 3 so only the point for number 3 is plotted in white. The third row up contains 4, 5 and 6 and again only one of these is prime so only the center point in row 3 is white.

This image is 1152 by 840 pixels so viewers with small monitors will need to scroll horizontally and vertically to explore the triangular array of primes in this image.

The values along the right edge are the triangular numbers (1,3,6,10,15. . .k). I've calculated the values for some of the vertical lines that appear rich in primes, for the first 100,000 and/or 1,000,000 integers.

38 to the right of center is one of the prominent vertical lines. The ratio of primes to elements in the line is .419437 for values up to 100,000. That's a lot of primes. At 1,000,000 the ratio is .354673. which is still a lot of primes. Other lines, like 3 and 39 to the left of center are prime free out to 100,000.

Once again, compare this to Ulam's square spiral figures. I think it is more interesting. The square spiral did not yield any lines that were prime free while the triangle does. . . so far.


Fainter lines are also apparent running parallel to or perpendicular to the left edge of the triangle. The values of the dots forming the bright line parallel to the left edge are equal to a triagular number plus a constant. The rows that are perpendicular to the left edge terminate at the right edge of the triangle and are therefore finite. These lines of primes are the sum a nth triangular number plus a regularly increasing offset amount.


Bibliography

Nugent, Jim. Pascal's Pyramid for Personal Computer Users. Chapter in Chaos and Fractals: A Computer Graphical Journey. Clifford Pickover, editor. Elsevier Publishing, 1998.

Nugent, Jim. Primes in a Triangular Array. Chapter in The Pattern Book: Fractals, Art, and Nature. Clifford Pickover, editor. World Scientific Publishing, River Edge, New Jersey, 1995.

Nugent, Jim. Notes on Pascal's Pyramid for Personal Computer Users, Chaos and Graphics section of Computers and Graphics, Pergamon Press, Oxford, England. Volume 15, Number 2, 1991. pages 303-311.

Schroeder, Manfred Robert. Number Theory in Science and Communication with Applications in Cryptography, Physics, Biology, Digital Information, and Computing. Published by Springer-Verlag in 1984

Stein, M. L., Ulam, S. M., Wells, M. B. (1964) A Visual Display of some Properties of the distribution of primes. Math Monthly. 71(5):516-520.


Back to home page

page updated on December 2, 1999