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.
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 ran across this brilliant video on YouTube that explains a lot of this. Enjoy.