Visualising prime numbers

Prime numbers are a lot of fun. One area I think worth considering is to visualise them in different ways to find patterns.

For example mathematicians were recently excited by the finding that the last digit of prime numbers shows some interesting statistical properties. For centuries mathematicians have mulled over prime numbers. It is quite plausible that the next big step would be made by looking at their statistical properties and visualising them in different ways. Since they are stubbornly “random”, the challenge is to find transformations and visualisations that will let us see new patterns which we didn’t know existed. I put random in quotes because although they seem random, the underlying mechanism that generates them is quite precise.

So here are some fun images of them.

To make things easier I downloaded a file with a list of prime numbers this site. There are a total of 78498 primes in the file (or perhaps one less because the file contains number 1, which is not prime).

First the first 100 prime numbers in all their glory,

 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 
 89  97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 
 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257
 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353
 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449
 457 461 463 467 479 487 491 499 503 509 521 523 541

and the last 5 in my file,

 999953 999959 999961 999979 999983

Let’s plot the first 100 primes.

Welcome the misbehaving numbers. Let’s plot the difference between successive primes for all primes (remember, around 78 thousand of them). This is known as the prime gap.

The white lines are odd numbers. Since all primes except 2 are odd, the gap between them is always even. Distance between primes seems to be increasing generally but the bottom of the graph remains dark as we progress to the right. It shows that even for large primes, we find primes whose gap is as little as 2. This is actually related to one of the unanswered questions of primes – Are there infinite prime pairs with a gap of 2?

If you find the previous graph too dense here is another one for the first 100 primes.

How about we plot prime gaps as a 2D image? To arrange our 78k primes in more or less square image, we draw the prime gaps row by row, with 280 primes in each row.

There are so many questions we can ask on this plot. For example how frequently are the prime gaps themselves divisible by, say, 23?

It’s like watching the stars 🙂 Of course, the questions we’re asking may not be the right ones. But seemingly silly questions may produce interesting answers. For example who would have guessed that a number is divisible by 3 if the sum of its digits is divisible by 3? Numbers are full of surprises.
Let’s do one more. This one is inspired by Sierpinski triangle.
A common way of generating it is by recursively drawing a solid triangle and “removing” smaller triangles from it, then removing even smaller triangles from those, and so on. However such an object can also be generated by successively applying the logical XOR.
It works like this. Write as many zeros as you like and replace the middle zero with a 1. Say we start with 000010000. This will be our “seed”.
row1 ....1....
Next, compute the second row. For each position we want to compute, we take the position on the row immediately above it and compute xor between its adjacent digits. So second row will be 000101000.
row2 ...1.1...
We continue this process computing the bottom rows. The result is the interesting structure you saw above.
....1....
...1.1...
..1.1.1..
We can also start off this exercise with a different seed. How about starting with a row that represents even numbers as 1 and odds as zero? We take the numbers 1, 2, 3, 4, 5 …, 198, 199 and transform them to 0, 1, 0, 1, 0, …, 1, 0. Generate 100 rows and this beautiful pattern emerges.
How about prime numbers? After experimenting a little bit I decided to leave out 2 and start from 3. I took all prime numbers between 3 and 199 and encoded them as 0 and 1 just like above.
And now its raining triangles!
Could go on forever playing with numbers so better stop here. Hope you had fun like I did. All graphs are generated by a python script. You can access html version of my Jupyter notebook and its source code.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code