
Prime number patterns - christophilus
http://chrisdavies.github.io/primepattern/
======
wfn
Ulam's spiral is fascinating, too. I've recently discovered this excellent
prime number distribution visualization page, which combines the general idea
of Ulam's spiral with other things:
[http://www.dcs.gla.ac.uk/~jhw/spirals/](http://www.dcs.gla.ac.uk/~jhw/spirals/)

~~~
robert_tweed
This is pretty cool, but seems like an illusion in that it appears to show a
pattern where there isn't one. At least not exactly.

Firstly, the formula traces a spiral. If you plot every point, that is. You
only plot a point if it's a prime, but it's still always going to trace a
spiral!

Still, this only-plotting-primes business leads to new, unexpected patterns
emerging. Yet, if you think about it, that's not altogether surprising really.
Patterns emerge not so much in where the primes are, as where the primes
aren't. Once you go beyond two, anything divisible by two can't be a prime
anymore. Same with three. Same for all numbers, because that's what prime
means. As a result, you get a pattern. It just so happens that this is what
that pattern looks like when you plot it on a spiral rather than a straight
line, or in a grid like the OP.

The grid has a similar effect, but the pattern forms vertical lines depending
on how many of the prime factors within the set divide evenly by the modulo
divisor chosen. Or the divisor +/\- 1, which gives rise to diagonals (try
adjusting the number up/down by 1 to see this effect).

~~~
ay1n
Thank you, your explanation was a deep insight into those patterns for me.

------
Zolomon
I always thought these attempts were interesting, because the patterns depend
completely upon the visualization implementation and not directly on the
pattern of the prime numbers. Is there some way to find prime number patterns
without depending on a specific visualization?

~~~
netcraft
i've had the same thought, but I dont think theres anything wrong with the
fact that patterns are only noticeable in a certain visualization. A pattern
in a decimal number wouldn't be discernible in another base for instance. Its
may just be that finding the right visualization might be the way to discover
new insights.

~~~
foolrush
See Sociology.

The model / metric forms the inference.

------
escape_goat
I don't have a very strong math background, but it seems to me self-evident
that the strong vertical striping, for instance, would be a trivial artefact
of the modulus rather than anything interesting about the prime numbers
themselves.

This leads me to suspect that the rest of the linear striping has a similar
explanation which is simply less obvious to me.

This in turn leads me to wonder what it is, exactly, that we're looking at.
There will always be patterns visible because there is a deep connection
between the ability to form a pattern and not-being-a-prime-number; the latter
always implies the former, if not the other way around. So how does one
perceive a "subtle" pattern of primes when not-being-a-prime is a property
possessed by an overlay of an infinite number of patterns?

------
readerrrr
Try 4513 for two divergent lines in the first million and almost complete
randomness in the 50th million.

~~~
morsch
That's a prime number and those diagonals were present for all primes I tried.
There's probably a name for that.

~~~
readerrrr
There are two non-parallel lines in 4513( and I'm not talking about the two
sets of parallel lines crossing each other ). Look carefully, and ignore other
parallels. I haven't seen any such clear example in other primes( or any other
number for that matter ).

I though it was interesting so here is a picture:
[http://i.imgur.com/KpbfuSz.jpg](http://i.imgur.com/KpbfuSz.jpg)

Between the purple and blue lines, there are a couple of segments desperately
trying to form a line, but failing.

------
mrcactu5
the UI is very nice... where did you find 50 million primes?
[https://github.com/chrisdavies/primepattern/tree/master/sets](https://github.com/chrisdavies/primepattern/tree/master/sets)

I found them:
[https://primes.utm.edu/lists/small/millions/](https://primes.utm.edu/lists/small/millions/)
He says: Usually it is faster to run a program on your own computer than to
download them.

Here in numpy:

    
    
      import numpy as np
    
      N = 1000000
    
      n = np.arange(N)+2
      p = []
    
      while(len(n) > np.sqrt(N)):
          p += [n[0]]
          n = n[np.where(n% p[-1] != 0)]
    
      print len(p), N/np.log(N)

~~~
thomasahle
I like this way of using numpy. This resembles the sieve of eratosthenes, so
you'd think it was fast.

However `n%p[-1]` isn't fast to do, your inner loop ends up taking nearly
linear time. At least linear in the final number of primes, which is larger
than `N/logN`. Hence your algorithm runs in `N^(3/2)` whereas eratosthenes is
`NloglogN`.

Funny how many versions of this algorithm there are out there.

~~~
mrcactu5
I noticed it ran a bit slow... it is supposed to be Eratosthenes Sieve

------
ccvannorman
I noticed that comparing sequential mod N (1260, 1261, 1262) you can see the
composite lines rotating (which makes sense because the lines follow the 2s,
so a mod of a number makes the 2s on each line be 1 or 2 pixels apart the
lines appear diagonal.)

This isn't a huge insight, but it does feel like a jumping off point for
looking at the patterns -- a sort of lattice or baseline by which to compare
the rest of the static.

This app makes me happy. :-]

------
tikhonj
This is great, although it's obviously hard to draw conclusions. I'd love to
see the same sort of visualizations done for 50 million (or however many)
random numbers drawn from a distribution that vaguely mimics the primes.

------
netcraft
Github source:
[https://github.com/chrisdavies/primepattern](https://github.com/chrisdavies/primepattern)

------
antimora
Assuming the black striped continue forever for "prime mod 1260", does this
mean we can quickly weed out non prime numbers?

~~~
christophilus
I was wondering that, myself. The magic number seems to be 210. (1260 is 210 *
6)

~~~
christophilus
You'll also notice that between the black stripes, there is a somewhat denser
white stripe. A while back, I calculated the number of primes in those white
stripes, and the number was a good bit higher than the over all average.

------
protopete
2310

~~~
CoffeeDregs
Yeah, I just did the same thing. 2 _3_ 5 _7_ 11 Unfortunately, it didn't yield
anything much more interesting than 1260...

------
api
If a pattern were found that allowed primes of arbitrary size to be computed
trivially, how would this impact cryptography?

~~~
readerrrr
There is such a formula, it is very simple

    
    
      n^2+n+41
    

It doesn't generate sequential primes.

That doesn't really matter, checking if a number is prime can be done in
sublinear time complexity. The real problem is factoring large numbers.

~~~
schoen
It also stops generating primes for n=40. See

[https://en.wikipedia.org/wiki/Formula_for_primes#Prime_formu...](https://en.wikipedia.org/wiki/Formula_for_primes#Prime_formulas_and_polynomial_functions)

~~~
readerrrr
It never stops generating primes, but it doesn't give a prime for every n.

~~~
alphaBetaGamma
Then why is it better than just

n

which also doesn't give a prime for any n, but does generate them all.

~~~
readerrrr
Because it grows exponentially. ( And it is interesting )

In reality you will use a O( (log n)^6 ) algorithm.

~~~
schoen
I think n² grows quadratically rather than exponentially.

~~~
readerrrr
::blush::

------
mariusz79
for 1618 (golden ratio x 1000) there is a straight line right in the middle of
the screen. Best visible when scrolling

~~~
CJefferson
This kind of really obvious single line will occur for anything which is 2
_prime number. 1618 = 2_ 809, so all numbers of the form: n _1618 and n_
1618+809 are composite. There is no other 0<c<1617 where n*1618+c is always
prime, so the line is really obvious.

~~~
MichaelDickens
Your division signs got parsed as italic typesetting.

------
mariusz79
31415

