
The other night I was messing around with a very large array of the first 64000 prime numbers – download here – to see if I could find some pattern in their distribution. I was really just making crap up and plotting crazy things while I watched Carl Sagan’s Contact on the side monitor.
I had read about the Ulam Spiral, a.k.a. Prime Spiral, and Sacks spiral and thought I’d mess around with something along these lines. I didn’t feel like figuring out how I’d graph things on the number spiral. That alone could take all night. So I cut corners and just figured I’d use polar coordinates. I’ve done lots with that so it meant I’d be able to get right down to the hard work of making shit up and see what comes out.
To use polar coordinates I would need two numbers: an angle and a radius to plot a point. A prime number is just a prime number and I couldn’t figure out a way to tease two numbers with any meaning out of a single prime number. That got me to thinking that instead of just using one prime number I could use two: the relationship between a sequence of two prime numbers. After a few experiments that basically produced graphs of static I tried this:
var angle : Number = prime / ( prime - previousPrime ); var radius : Number = prime - previousPrime;
That produces the image below ( figure a )
![]() |
I thought that was pretty cool. I certainly didn’t expect concentric circles and especially not, seemingly, evenly spaced concentric circles. Maybe if I were a mathematician I would have but remember, I’m just making things up and so to get any pattern at all was a surprise.
Then I thought that I’d factor in 2 * pi with the angle and see what happened and I ended up with the pattern below ( figure b )
![]() |
That is very similar to Sacks Spiral ( here on wikipedia.org near the bottom ) but the approach is entirely different and Sacks Spiral is asymmetric whereas the pattern I generated seems to be symmetric about the x-axis which corresponds to the angle % pi = 0.
![]() |
The two images above – figures a and b – use the first 64,000 prime numbers to plot the points. Obviously there are not 64,000 dots. It seems that the many different combinations of prime/previous prime yield the same values for angle and radius. So points get used over and over. I tried to illustrate that by making the dots semi-transparent so that the more a angle/radius value is used the brighter it would be. But that doesn’t provide much sensitivity to the range.
To get a view on how ofter the same angle/radius pair came up I collected every point in an array – lets call it the collectionArray. Then after every point had been plotted I sifted through the array to create another similar array – lets call it the siftedArray. To fill up the siftedArray I would start by pulling out a point from the collectionArray and then looping through the siftedArray to see if there was already a point in there with the same angle/radius value. If so then instead of adding the new point to the siftedArray I would take the existing duplicate and increment it’s count value.
What I end up with in the siftedArray is a collection of all the unique points that include the angle/radius and a count of how many points ended up with the same values. That yielded an array of just 464 unique points.
I used Away3D to plot that data in the view below. Now you can see that the values near the origin get used the most. And it spreads out thinner towards the edge. Presumably if I had a larger array of primes the edges just continue to expand outward.
| view source |
Next I’ll try to do some analysis to see if I can figure out what relationship the prime pairs have that create the same angle/radius values. This might be a little beyond my feeble mathematical skills. But it will be fun trying.
Again, I don’t really know what I’m doing here. This might be the most profound discovery in the field of Number Theory since … a long time ago or it could be something that gets covered in the preface of an Introduction to Number Theory book. If you have any idea I’d love to hear about it in the comments.
More about prime numbers and number theory







I don’t really know where it is in the texts, but it seems like you have a 3 dimensional gaussian distribution (may or may not have zero mean).
I would also like to ask that why did you took the angle as a value grater than one? (was it just an intuition or some logic)… what could be fun is if you invert the value of angle, then it will always be between 0 and 1, which look like a sine or cosine range and also seems to converge. would be glad if you post something on this side of the story :)
@Romesh Thanks for the idea for inverting the angle. I’ll play with that sometime.
3-dimensional Gaussian distribution??? Man, that class was 25 years ago. I’m so old! :-)
Pretty cool, If nothing else it is pretty neat to look at!
This goes to show you that all the great ideas have be dreamed up somewhere before. I too, before reading any of this or knowing anything of Ulam or Sacks, thought of plotting the primes along a spiral, because it would give you a way to visualize patterns among the primes. Although I think it’s only tangentially related to what you discovered, what strikes me now is that, shouldn’t the Ulam or Sacks spirals provide a way of deriving very large primes, since the prime-rich lines/curves therein can be extracted as independent functions? Couldn’t you then search along that curve for any arbitrarily large integer (i.e., larger than the largest prime known to date) where the curve intersects the base spiral at a point, and then simply test to see whether it is indeed a prime? Or is it that the prime-rich curves/lines peter out at some point (which in itself would be interesting)?
>Couldn’t you then search along that curve for any arbitrarily large integer
@Terser That’s what I’m thinking. I really expected just to get static out of this. You should have seen my face when these patterns appeared. Although, you probably know what it’s like since you did something similar, right? At any rate, I don’t know what I’ve done but it was fun. :-)
The prime patterns might be related to the Ulam spiral.
http://en.wikipedia.org/wiki/Ulam_spiral
-j