Setup
Let us first understand what is this visualization! Here, the prime numbers are visualized in polar coordinates (r, θ)- This means labelling the data in 2D space - not with usual (x, y) points instead with distance from origin (commonly known as r for radius) and angle (θ) which the line makes with the horizontal plane (x - axis).
Polar Coordinates
Here, θ is measures in radians which means π is 180° and 2π is 360°/0°. In polar coordinates, angle is not unique - meaning 2π is same as 0 and hence the values are modulated by 2π. i.e., angle varies always between 0 and 2π.
With this setup, here in the visualization we are going to look at has both (r, θ) coordinates are a given prime number p i.e., (r, θ) = (p, p). This visualization has no practical reasons- just pure fun in the playground for data visualization!
Natural numbers
Let us look into what happens when we plot all the natural numbers - consider a single point (1, 1) which sits at a distance of 1 from origin and with an angle of 1 radian (2, 2) is twice the radius and twice the angle - we can also note that the point (3, 3) is slightly closer to x axis- this is because radian 3 is closer to 3.14 which is π !
With the basic understanding set each step is like tip of the clock hands rotating 1 radian at a time with further increasing radius - with this growing rate - the points form the spiral known as the Archimedean spiral - which when plotted as lines instead of arc forms the rosette pattern😁.
Rosette pattern in Natural numbers
Primes under attack
First 7 Primes
When we remove the numbers other than the primes, the plot initially looks random - but when we zoom out - we start to see the galactic spirals 🎇- typical nature of primes where it seems to be random and then turns out to be chaotic😑!
First 1000 Prime numbers forming galactic spirals!
Even further zooming out we see outward pointing rays --
First 100K Prime Numbers forming outward pointing rays!
Those rays seem to be coming as batches of 4 with occasional gaps in between - looks like a comb missing a teeth😱 --
How? Why?
20 Spirals and 280 Rays
We can clearly see that there are 20 spirals present and 280 rays emerging out - does this number mean anything? Where does these spirals come from? Let's find out --
The origin of the problem of using only prime numbers is misleading in its own way - Let's see how this visualization holds for all natural numbers --
First 10K Natural numbers
Now the spirals are more clear and we see 44 spirals here - So, it is pretty clear that it is not the primes that causes the spirals. But what happens when we filter the visualization only for primes leads to one of the most important theorems in number theory about distribution of prime numbers - known as Dirichlet's theorem.
MVP (The Most Valuable Part)!
6 inner spirals in visualization
Let's zoom in a little further – we can clearly see 6 spirals, understanding of what is happening here will help us further expand our knowledge about other patterns which we see - here all the multiple of 6 form 1 arm of the spiral (6k) and other arm contains numbers one above multiple of 6 (6k +1) and so on..
We can see the numbers spiraling to be split across these 6 buckets
Mathematically, each of the buckets are called as residue classes - as the buckets are based off of number 6 - these are residue class of mod 6 6k => 6,12,18,.... 6k+1 => 7,13,19,.... 6k+2 => 8,14,20,.... 6k+3 => 9,15,21,.... 6k+4 => 10,16,22,.... 6k+5 => 11,17,23,....
Residue : Just means the remainder when divided by the number (here 6) Mod : Modulus (%)
But why 6? We know that whole circle had 2π radians which is numerically ~6.28, so every time when we count till 6, we almost made a full turn - another 6 steps, another almost full turn with a slightly smaller angle (0.28 radians for every rotation) which actually creates these spirals. With the angle changing slightly enough, which gives us the illusion of curving line.
When we limit the view to only prime numbers, all but 2 arms remain - just think about it - we lose all the even numbers - so we lost the arm with 6k, 6k+2 and 6k+4 series as they are even numbers, we lose the multiple of 3, so 6k+3 is also lost - we are left with the series 6k+1 and 6k+5.
Lets scale it up!
The way 6 radians is very closer to a whole turn (2π), 44 radians is very closer to the whole turn as well (14π (7 full turns) is 43.96). This also comes to the mathematical approximation of π as 22/7
Math representation
What this means is, when we count by multiples of 44 in the visualization, the points lie in the same plane - with slight increase in the angle (0.04 radians). This results in the view of residue class of mod 44 which results in the gentle spiral which we came across in the scaled down version
Residue class of mod 44 : All Natural Numbers
So, when looking with the same way as in primes - we can remove class with even numbers (44k, 44k+2, 44k+4,...) and the classes which share the prime factors (similar to what we did when we removed 6k+3 in the previous case) - the classes which left form the below visualization – there are 20 residue classes of mod 44. This explains the 20 spirals which we saw initially
Residue class mod 44 : Only Primes
As we saw, 6 radians is close to a full turn (2π) and 44 radians are close to 7 full turns, similar way 710 radians is way more closer to the 113th full turn - (difference of 0.00000959!)
First 100K Prime Numbers forming outward pointing rays!
As the difference is very very very small - the increase in angle for every 710th count is very smaller that it is nearly straight lines - which we see as the outward pointing rays in the picture.
But that comb missing some teeth? that is due to the elimination of even and prime factor residue classes from residue class of mod 710. The prime factors of 710 are 71, 5 and 2. If the remainders are divisible by any of those, we can ignore the whole class. But that doesn't explain the 4 rays pointing outward- right? No! It explains
When we remove the residue classes of prime factor 2, we get evenly spaced distribution of numbers (as half of the numbers are removed by Thanos's snap😊)
Natural numbers with removed residue classes whose remainder is divisible by 2
When we remove residue classes of prime factor 5 from this, we get the below visualization where every 5th ray is removed - which results in the 4 rays !!
Natural numbers with removed residue classes whose remainder is divisible by 2 and 5
Of the remaining classes - there are only 4 residue classes whose remainders are divisible by 71 - this explains why primes doesn't show up occasionally in some part.
And if you are wondering where the initial 280 rays came from - it comes from counting how many numbers from 1 to 710 don't share any prime factors with 710
Conclusion
Starting with some random visualization of prime numbers - and its anomalies, the answer became very simple - it is due to the approximation of π and human nature of finding patterns in structured data - and that's how brain works!
Inspiration for this blog came from a post from math exchange with the question posted by dwymark and answer suggested by Greg Martin.