Cookies   I display ads to cover the expenses. See the privacy policy for more information. You can keep or reject the ads.

# Why do prime numbers make these spirals?

The full title of this video might be something like
"How pretty but pointless patterns in polar plots of primes prompt pretty important ponderings on properties of those primes"
I first saw this pattern that I'm about to show you in a question on the Math Stack Exchange
It was asked by a user under the name "dwymark" and answered by Greg Martin.
And it relates to the distribution of prime numbers
together with rational approximations for pi.
You see what the user had been doing was playing around with data in polar coordinates.
As a quick reminder so we're all in the same page:
This means labeling points in 2D space, not with the usual xy coordinates,
but instead with a distance from the origin,
commonly called r for radius together with the angle that that radial line makes with the horizontal
commonly called theta.
And for our purposes this angle will be measured in radians.
Which basically means that an angle of π is halfway around
and then 2π is a full circle.
And notice polar coordinates are not unique in the sense that
adding 2π to that second coordinate doesn't change the location that this pair of numbers is referring to.
The pattern that we'll look at centers around plotting points where both of these coordinates are a given prime number.
There is no practical reason to do this. It's purely fun.
We're just frolicking around in the playground of data visualization and to get a sense for what it means
Look at all the whole numbers rather than just the primes.
The point (1, 1) sits a distance one away from the origin with an angle of 1 radian.
Which actually means this arc is the same length as that radial line
and then (2, 2) has twice that angle and twice the distance
and to get to (3, 3) you rotate one more radian with a total angle
that's now slightly less than a half turn since 3 is slightly less than pi
and you step one unit farther away from the origin.
I really want you to make sure that it's clear what's being plotted because
everything that follows depends on understanding it.
Each step forward is like the tip of a clock hand which rotates one radian with each tick
(a little less than a sixth of a turn)
and it grows by one unit at each step.
As you continue these points spiral outwards forming
what's known in the business as an Archimedean spiral.
Now if you make the admittedly arbitrary move to knock out everything except the prime numbers
It initially looks quite random after all primes are famous for their chaotic and difficult to predict behavior
but when you zoom out
What you start to see are these very clear galactic seeming spirals and what's weird is some of the arms seem to be missing.
Then zooming out even further those spirals give way to a different pattern
These many different outward pointing rays.
And those rays seem to mostly come in clumps of four
But there's the occasional gap like a comb missing its teeth.
The question for you and me naturally is what on earth is going on here. Where do these spirals come from?
And why do we instead get straight lines at this larger scale?
If you wanted you could ask a more quantitative question and count that there are 20 total spirals
And then up at that larger scale if you patiently went through each ray you'd count up a total of 280.
And so this adds a further mystery of where these numbers are coming from and why they would arise from primes.
Now this is shocking and beautiful and you might think that it suggests some divine hidden symmetry within the primes.
But to steady your expectations I should say that
the fact that the person asking this question on Math Exchange jumped right into prime numbers makes the puzzle a little misleading
if you look at all of the whole numbers (not just the primes).
As you zoom out you see very similar spirals
They're much cleaner and now there's 44 of them instead of 20
But it means that the question of where the spirals come from is perhaps disappointingly
Completely separate from the question of what happens when we limit our view to primes.
But don't be too disappointed because both these questions are still phenomenal puzzles.
There's a very satisfying answer for the spirals and
Even if the primes don't cause the spirals asking what goes on when you filter for those primes
Does lead you to one of the most important theorems about the distribution of prime numbers
known in number theory as Dirichlet's theorem.
To kick things off. Let's zoom back in a little bit smaller.
Did you notice that as we were zooming out there were these six little spirals?
This offers a good starting point to explain what's happening in the two larger patterns.
Notice how all the multiples of 6 form one arm of this spiral.
Then the next one is every integer, that's 1 above a multiple of 6.
Then after that it includes all the numbers 2 above a multiple of 6 and so on. Why is that?
Well, remember that each step forward in the sequence involves a turn of one radian.
So when you count up by 6, you've turned a total of 6 radians
Which is a little bit less than 2π, a full turn.
So every time you count up by 6
You've almost made a full turn. It's just a little less.
Another six steps, a slightly smaller angle.
Six more steps, smaller still and so on.
With this angle changing gently enough that it gives the illusion of a single curving line.
When you limit the view to prime numbers all but two of these spiral arms
they'll go away, and think about it.
A prime number can't be a multiple of 6
and it also can't be 2 above a multiple of 6 unless it's 2 or 4 above a multiple of 6
since all of those are even numbers.
It also can't be 3 above a multiple of 6 unless it's the number 3 itself since all of those are divisible by 3.
So at least at the smaller-scale nothing magical is going on.
And while we're in the simpler context
let me introduce some terminology that mathematicians use.
Each one of these sequences where you're counting up by 6 is fancifully called a
"residue class mod 6".
The word "residue" here is sort of an overdramatic way of saying remainder
and mod means something like where the thing you divide by is.
So for example 6 goes into 20 three times and it leaves a remainder of 2
So 20 has a residue of 2 mod 6.
Together with all the other numbers leaving a remainder of 2 when the thing you divide by is 6
you have a full residue class mod 6
I know that that sounds like the world's most pretentious way of saying "everything 2 above a multiple of 6".
But this is the standard jargon and it is actually handy to have some words for the idea.
So looking at our diagram in the lingo each of these spiral arms corresponds to a residue class mod 6
and the reason we see them is that 6 is close to 2π turning 6 radians is almost a full turn.
And the reason we see only two of them when filtering for primes is that
all prime numbers are either 1 or 5 above a multiple of 6 with the exceptions of 2 and 3.
With all that as a warm-up, let's think about the larger scale. In the same way that six steps is close to a full turn
Taking 44 steps is very close to a whole number of turns.
Let's compute it. There are 2π radians per rotation, right?
So taking 44 steps, turning 44 radians, gives a total of 44 divided by 2π rotations,
which comes out to be just barely above seven full turns.
You could also write this by saying that 44/7 is a close approximation for 2π.
Which some of you may better recognize as the famous 22/7 approximation for π.
What this means is when you count up by multiples of 44 in the diagram
Each point has almost the same angle as the last one just a little bit bigger.
So as you continue on with more and more we get this very gentle spiral as the angle increases very slowly
Similarly all the numbers 1 above a multiple of 44 make another spiral but rotated 1 radian counterclockwise.
Same for everything 2 above a multiple of 44 and so on eventually filling out the full diagram.
To phrase it with our fancier language, each of these spiral arms shows a residue class mod 44.
And maybe now you can tell me what happens when we limit our view to prime numbers.
Primes cannot be a multiple of 44 so that arm won't be visible
nor can a prime be 2 above a multiple of 44 or 4 above and so on
since all those residue classes have nothing but even numbers.
Likewise any multiples of 11 can't be prime except for 11 itself.
So the spiral of numbers 11 above a multiple of 44
They won't be visible. And neither will the spiral of numbers 33 above a multiple of 44.
This is what gives the picture those Milky Way seeming gaps.
Each spiral were left with is a residue class that doesn't share any prime factors with 44.
And within each one of those arms that we can't reject out of hand
The prime numbers seem to be sort of randomly distributed and that's a fact that I'd like you to tuck away.
We'll return to it later.
This is another good chance to inject some of the jargon that mathematicians use.
what we care about right here are all the numbers between 0 and 43 that don't share a prime factor with 44, right?
The ones that aren't even and they also aren't divisible by 11.
When two numbers don't share any factors like this
We call them "relatively prime" or also "coprime".
In this example, you could count that there are 20 different numbers between 1 and 44 that are coprime to 44
And this is a fact that a number theorist would compactly write by saying:
phi of 44 equals 20.
Where the Greek letter phi here refers to Euler's totient function, yet another needlessly fancy word
Which is defined to be the number of integers from 1 up to n which are coprime to n.
It comes up enough that it's handy to have compact notation.
More obscurely and I had never heard this before but I find it too delightful not to tell
these numbers are sometimes called the "totatives" of n.
Back to the main thread in short what the user on math exchange was seeing
are two unrelated pieces of number theory but illustrated in one drawing.
The first is that 44/7 is a very close rational approximation for 2π
Which results in the residue classes mod 44 being cleanly separated out.
The second is that many of these residue classes contain zero prime numbers or sometimes just one so they won't show up.
But on the other hand primes do show up
plentifully enough in all 20 of the other residue classes that it makes these spiral arms visible.
And at this point maybe you can predict what's going on at the larger scale.
Just as 6 radians is vaguely close to a full turn and 44 radians is quite close to seven full turns
it just so happens that 710 radians is
extremely close to a whole number of full turns.
Visually, you can see this by the fact that the point ends up almost exactly on the x axis, but it's more compelling analytically.
710 radians is 710 divided by 2π rotations, which works out to be
113 point 0 0 0 0 0 9 5.
Some of you may have seen this in another form.
It's saying the 710/113 is a close approximation for 2π which is more commonly seen in saying that
355/113 is a very good approximation for π.
Now if you want to understand where these rational approximations are coming from and what it means for one like this to be
Unusually good, like way better than you would get for Φ or e or √2 or other famous irrationals.
I highly recommend taking a look at this great Mathologer video.
For our storyline though. It means that when you move forward by steps of 710
the angle of each new point is almost exactly the same as the last one
Just microscopically bigger.
Even very far out one of these sequences looks like a straight line.
And of course, the other residue classes mod 710 also form these nearly straight lines.
710 is a big number though. So when all of them are on-screen and there's only so many pixels on the screen
It's a little hard to make them out.
So in this case it's actually easier to see when we limit the view to primes
where you don't see many of those residue classes.
In reality with a little further zooming you can see that there actually is a very gentle spiral to these.
But the fact that it takes so long to become prominent is a wonderful illustration.
Maybe the best illustration I've ever seen for just how good an approximation this is for 2π.
Tying up the remaining loose thread here if you want to understand what happens when you filter for primes
It's entirely analogous to what we did before.
The factors of 710 are 71, 5 and 2.
So if the remainder or residue is divisible by any of those then so is the number.
When you pull up all of the residue classes with odd numbers
It looks like every other ray in the otherwise quite crowded picture
And then of those that remain these are the ones that are divisible by 5
Which are nice and evenly spaced at every fifth line.
Notice, the fact that prime numbers never show up in any of these
is what explains the pattern of the lines we saw at the beginning coming in clumps of four.
And moreover, of those remaining these four residue classes are the ones that are divisible by 71
So the primes aren't going to show up there.
And that's what explains why the clumps of four that we saw occasionally have like a missing tooth in your cone.
And if you were wondering where that number 280 came from?
It comes from counting how many of the numbers from 1 up to 710 don't share any prime factors with 710.
These are the ones that we can't rule out for including primes based on some obvious divisibility consideration.
This of course doesn't guarantee that any particular one will contain prime numbers
But at least empirically when you look at this picture
It actually seems like the primes are pretty evenly distributed among the remaining classes.
Wouldn't you agree?
This last point is actually the most interesting observation of the whole deal.
It relates to a pretty deep fact in number theory known as Dirichlet's theorem.
To take a simpler example than residue classes mod 710 think of those mod 10.
Because we write numbers in base 10, this is the same thing as grouping numbers together by what their last digit is.
Everything whose last digit is 0 is a residue class, everything whose last digit is 1 is another residue class and so on.
Other than two prime numbers can't have an even number as their last digit since that means they're even
And likewise any prime bigger than 5 can't end in a 5.
There's nothing surprising there, that's one of the first facts you observe when you learn about prime numbers.
Anything bigger than 5 has to end in either a 1, a 3, a 7, or a 9.
A much more nuanced question though
is how exactly these primes are divvied up among those remaining four groups.
Here, let's make a quick histogram counting through each prime number
where the bars are going to show what proportion of the primes that we've seen so far have a given last digit.
So in particular the 2 and the 5 slots should go down to 0 over time.
What would you predict is gonna happen as we move through more and more primes?
Well
As we get a lot of them, it seems like a pretty even spread between these four classes about 25% each.
And probably that's what you would expect.
After all, why would prime numbers show some sort of preference for one last digit over another?
But Prime's aren't random
they are a definite sequence and they show patterns in other ways
and it's highly non-obvious how you would prove something like this.
Or for that matter, how do you rigorously phrase what it is that you want to prove?
A mathematician might go about it something like this:
If you look at all the prime numbers less than some big number x
and you consider what fraction of them are, say, 1 above a multiple of 10
That fraction should approach 1/4 as x approaches infinity.
And likewise for all of the other allowable residue classes like 3 and 7 and 9.
Of course there's nothing special about 10 - a similar fact should hold for any other number.
Considering our old friends the residue classes mod 44, for example,
let's make a similar histogram showing what proportion of the primes show up in each one of these.
Again as time goes on we see an even spread between the 20 different allowable residue classes.
Which you can think of in terms of each spiral arm from our diagram
Having about the same number of primes as each of the others.
Maybe that's what you would expect but this is a shockingly hard fact to prove.
The first man who cracked this puzzle was Dirichlet, in 1837.
And it forms one of the crowning jewels at the foundation of modern analytic number theory.
Histograms like these ones give a pretty good illustration of what the theorem is actually saying.
Nevertheless you might find it enlightening to see how it might be written in a math text
with all the fancy jargon and everything.
It's essentially what we just saw for 10, but more general.
Again, you look at all of the primes up to some bound x
But instead of asking for what proportion of them have a residue of, say, 1 mod 10
You ask what proportion have a residue of r mod n,
Where n is any number and r is anything that's coprime to n.
Remember, that means it doesn't share any factors with n bigger than 1.
Instead of approaching 1/4 as x goes to infinity,
that proportion goes to 1 divided by phi of n,
where phi is that special function I mentioned earlier that gives the number of possible residues coprime to n.
And in case this is too clear for the reader you might see it buried in more notation.
Where this denominator and the numerator are both written with a special prime counting function.
The convention, rather confusingly, is to use the symbol π for this function,
even though it's totally unrelated to the number pi.
In some contexts when people refer to Dirichlet's Theorem, they refer to a much more modest statement.
Which is simply that each of these residue classes that MIGHT have infinitely many primes DOES have infinitely many.
In order to prove this, what Dirichlet did
was show that the primes are just as dense in any one of these residue classes as in any other.
For example, imagine someone asked you to prove that there are infinitely many primes ending in the number 1,
and the way you do it is by showing that a quarter of all the primes end in a 1.
Together with the fact that there are infinitely many primes, which we've known since Euclid,
This gives a stronger statement and a much more interesting one.
Now the proof - well, it's way more involved than would be reasonable to show here.
One interesting fact worth mentioning is that it relies heavily on complex analysis.
Which is the study of doing calculus with functions whose inputs and outputs are complex numbers.
Now that might seem weird, right?
I mean, prime numbers seem wholly unrelated to the continuous world of calculus;
Much less when complex numbers end up in the mix.
But since the early 19th century
This is absolutely par for the course, when it comes to understanding how primes are distributed.
And this isn't just antiquated technology either
Understanding the distribution of primes in residue classes like this
Continues to be relevant in modern research too!
Some of the recent breakthroughs on small gaps between primes,
edging towards that ever elusive twin prime conjecture,
have their basis in understanding how primes split up among these kinds of residue classes.
Okay, looking back over the puzzle, I want to emphasize something
The original bit of data visualization whimsy that led to these patterns
Well, like it doesn't matter. No one cares
There's nothing special about plotting (p, p) in polar coordinates.
And most of the initial mystery in these spirals
resulted from the artifacts that come from dealing with integer number of radians, which is kind of weird.
But on the other hand, this kind of play is CLEARLY worth it
If the end result is a line of questions that leads you to something like Dirichlet's theorem, which is important.
Especially if it inspires you to learn enough to understand the tactics of the underlying proof.
No small task, by the way.
And this isn't a coincidence that a fairly random question like this can lead you to an important and deep fact for math.
What it means for a piece of math to be important and deep is that it connects to many other topics.
So even an arbitrary exploration of numbers
as long as it's not too arbitrary
Has a good chance of stumbling into something meaningful.
Sure, you'll get a much more concentrated dosage of important facts by going through a textbook or a course.
And there will be many fewer uninteresting dead ends.
But there is something special about rediscovering these topics on your own.
If you effectively reinvent Euler's totient function, before you've ever seen it defined
Or if you start wondering about rational approximations before learning about continued fractions
Or if you seriously explore how primes are divvied up between residue classes
Before you've even heard the name "Dirichlet"
Then when you DO learn those topics,
you'll see them as familiar friends, not as arbitrary definitions,
and that will almost certainly mean that you learn it more effectively.