# How to force prime numbers into a line?

Inspired by an article on Prime Spiral and Hough transform I tried to analyze patterns created by plotting numbers on spiral (Archimedean?).

$$x = \cos( angle ) * radius$$ $$y = \sin( angle ) * radius$$

where angle and radius is incremented by a constant value

No surprise so far.

When all non prime numbers are suppressed this ray pattern appears at a specific point (manipulating the increments of the spiral):

It turned out that the increment of the angle is exactly $$\cfrac{\pi}{30}$$

All prime numbers are on 16 lines (ignoring that the first numbers probably don't match the scheme).

Setting the increments to $$\cfrac{\pi}{3}$$

leads to (white dots are prime numbers):

Mirroring them on the x-axis doesn't seem to help to have them on a single line. Because there are some non prime numbers in the lines.

What could I do the force them to a single straight line?

If this pattern is a well known property of prime numbers how is it called?

In case someone would like to experiment I added the java source at github

Related:

Meaning of Rays in Polar Plot of Prime Numbers

• How are you assigning a point to each number? In other words, what map from $\Bbb{Z}_{>0}$ to $\Bbb{R}^2$ are you using?
– A.P.
May 20, 2015 at 20:44
• @A.P.es each number is represented by a point, the coordinates are calculated:: x = cos(angle) * radius ; y = sin( angle ) * radius; where radius and angle is incremented for each number. May 20, 2015 at 20:47
• That's the definition of polar coordinates, which I assumed you are using. An Archimedean spiral is given by the equation in polar coordinates ($r$ for the radius and $\theta$ for the angle) $r = a + b \theta$ with $a,b \in \Bbb{R}$ constants and $b \neq 0$. I assume you are using something like $n \mapsto (r,\theta) = (n b \phi,n\phi)$ for some fixed angle $\phi$ and a constant $b \neq 0$. Is this correct?
– A.P.
May 20, 2015 at 20:52
• In other words: how are you incrementing radius and angle as a function of each number?
– A.P.
May 20, 2015 at 20:52
• By the way, the notation $\pi / 10 / 3$ is ambiguous. Do you mean $(\pi / 10) / 3) = \pi / 30$ or $\pi / (10/3) = 3\pi / 10$?
– A.P.
May 20, 2015 at 20:54

## 3 Answers

There are 2 behaviours going on here.

In your last picture, it's easy to see that all numbers lie on the 6 rays through the origin. Why? This is because there are $2\pi$ radians in a circle, and you are incrementing by $\pi/3$ radians each time (which is 1/6 of the circle). This is why you are getting distinct rays.

The other behaviour occurs when you only look at primes. In the second picture (the one consisting of only primes), there is space for 60 rays (since you are incrementing by $\pi/30$ radians, which is 1/60th of a circle each time). So the new question is, why do only 16 rays appear?

The answer is that $\varphi(60) = 16$, meaning that there are only 16 residue classes for primes to fit in mod 60. Stated differently there are only 16 solutions to $p \equiv x \pmod {60}$ in $x$, where $p$ ranges across all the primes. So there are 16 distinguished rays containing primes.

Similarly, there are two distinguished rays in the last picture, which is why you can only see primes on 2 of the rays.

You might be interested to know that the property of being a ray containing primes will not be origin-symmetric, but mirror-symmetric over the horizontal line $y = 0$. This has to do with how $\gcd(x,n) = \gcd(n-x,n)$, and the order in which you are plotting these rays.

To answer your final question, you can plot all primes (except 2) on the same line by using $\pi$ as your increment, or by using $2\pi$ as your increment. The first is equivalent to saying that all primes except $2$ are odd. The second actually puts all numbers on a single line.

• I'm glad you added the "new question" part, I was about to say "why has no one said "the angle you're incrementing by divides $2\pi$!" May 21, 2015 at 10:03
• You say that there are 16 solutions to p=x(mod 60). Didn't you mean that there are only 16 which has more than 1 solution(I believe you forgot $x \in \{\text{prime divisors of 60}\}$
– RiaD
May 21, 2015 at 19:08

Loosely, what's going on here is that you're discovering the notion of residue class. If you look carefully, you'll discover that all of the points on your original spiral actually lie on a finite set of 60 lines through the origin: one line for every $6^\circ$ or for every $\frac\pi{30}$ radians. This means that what line a number is on is determined by its remainder when divided by $60$: $19$ is on the same line as $79, 139, 199, \ldots$ For convenience's sake, we'll label these lines by the smallest positive number on them (this is called the residue class of all the numbers on the line, $\bmod 60$). Now, consider:

• Every even number (greater than 2) remains even after adding 60 to it, so none of your 'even' lines hold more than possibly one prime. This means that no primes (other than just one transient one that we can ignore) can be on the lines with labels $0, 2, 4, 6, 8, 10, \ldots, 56, 58$.
• Every multiple of 3 (greater than 3) remains a multiple of 3 after adding 30 to it, so none of the multiple-of-three lines hold more than possibly one prime; so no primes (again, except for that one ignorable exception) can be on the lines with labels $3, 6, 9, \ldots, 54, 57$.
• And the same thing happens with multiples of 5, so we get no primes on the lines with labels $5, 10, 15, \ldots, 50, 55$ either.

Once you take all these into account, you'll find that the only lines that can possibly have infinitely many primes on them are the lines labeled $1, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49, 53, 59$ - these are the sixteen lines you find in your ray pattern.

As for whether you can get all of the primes onto a single line this way, the answer is no (unless you use such a large angle increment for your spiral that all your points lie on either the x or y axes), but the reasoning is a bit complex: it turns out that for any number $n$, there are infinitely many primes that are of the form $k\times n+1$ (or primes that are on the line labeled '$1$'), and there are infinitely many primes of the form $k\times n-1$ (or primes on the line labeled '$n-1$'). This means that you'll get at least a couple of lines for any angular increment, and in fact you're going to get more than that - the number of lines you should expect to have primes on them is (essentially) equal to Euler's Totient function $\phi(n)$, which counts the numbers less than $n$ that are relatively prime to $n$ (i.e., have no common factors with $n$), and it's known that $\phi(n)$ grows as $n$ does, in the sense that for any given $K$ there are only finitely many values of $n$ where $\phi(n)$ is less than $K$.

But how do you know that all of these lines will have primes on them? (It should be clear that the primes can only show up on these lines, by a variant of the argument I gave above). Well, that's the content of Dirichlet's Theorem, which basically says that for any arithmetic progression, as long as you know that values on the progression are relatively prime, there will always be infinitely many primes on that progression. Here, the 'spokes' in your renderings represent these progressions.

Let's fix some notation first: in polar coordinates an Archimedean spiral is a curve in the real plane (i.e. the "usual" plane with coordinates over the real numbers) $$r = a + b \cdot \theta$$ for some fixed constants $a,b \in \Bbb{R}$ with $b \neq 0$. Here $r$ and $\theta$ represent the radius and angle of a given point, respectively.

Now, inspecting your code it looks like you are assigning to every positive integer $n$ the point with polar coordinates $(n \cdot b \cdot \varphi , n \cdot \varphi)$ where $$\varphi = \frac{\pi}{30} \qquad \text{and} \qquad b\varphi = \frac{1}{40} = 0.025$$

Now, observe that two points lie on the same ray if and only if they have the same angle (modulo $2\pi$). In particular, two positive integers $m,n$ will lie on the same ray if and only if $m \varphi = n \varphi + 2k\pi$ for some $k \in \Bbb{Z}$, i.e. $$(m-n) \varphi = 2k\pi$$ taking $m = 3$ and $n = 2$ gives $\varphi = 2k\pi$ for some integer $k$.

This implies, though, that every positive integer will have to lie on the same line, not just the primes. Actually, this is already happening even in your last picture: if you plot the other numbers as well and not just the primes, you will see that they lie in the same $$6 = 2\pi \cdot \frac{3}{\pi}$$ rays, too.