Sunday, May 4, 2014

Spontaneus symetry breaking of prime numbers.



Let's imagine for a moment that we start adding "+1" for each natural number. Whenever we reach a prime number we switch the sum from "+1" to "-1".  If prime numbers are randomly distributed we expect the total sum to oscillate around 0.
Take for example the first 20 numbers (in bold prime numbers, where we start switching back):

                                        | Total
    3       3                           |
  2   2   2   2                         |
1       1       1       1               |
------------------0---0---0--------------
                   -1      -1      -1   |
                             -2  -2  -2 |
                               -3       |
                                        |
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 |
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
    *   *   *       *   *       *   *   |



 Let's see what we get in practice.


Next python code simulate the previous process/algorithm/"thing":


  1 def isprime(n):
  2     n*=1.0
  3     if n%2==0 and n!=2 or n%3==0 and n!=3:
  4         return False
  5     for b in range(1,int((n**0.5+1)/6.0+1)):
  6         if n%(6*b-1)==0:
  7             return False
  8         if n %(6*b+1)==0:
  9            return False
 10     return True
 11
 12 START=1
 13 total=0
 14 sum = -1
 15 for END in xrange(5000000,30000001,5000000):
 16     totalNeg=0
 17     totalPos=0
 18        
 19     for i in xrange(START, END):
 20         total = total + sum
 21         if total > 0:
 22             totalPos += 1
 23         if total < 0:
 24             totalNeg += 1
 25         if isprime(i):
 26             sum  = -1 * sum
 27     START = END+1
 28    
 29     rat = totalPos*1./totalNeg
 30     if rat > 1:
 31        rat = 1./rat
 32     
 33     print total, total*1./END, totalPos, totalNeg, rat


Every 5000000 numbers we print some statistics (line 33).



In the program output, the first column prints the "total" variable, which shows the total sum at a given time. We expect such column to be evenly distributed between negative and positive numbers. The second column shows the ratio between the total sum and the current natural number, that we expect to be close to zero. The third column will show how many times the total sum was possitive, with the fourth column showing how many times it was negative, finally the fith column shows the ratio between the times the total sum was possitive and the time it was negative. We expect column 3 to be quite similar to column 4, and so fith column close to 1.


Let's see what our program shows in practice:

SUM    Current / SUM    
-1757  -0.00292833333333 90292  509554 0.177198

-3393  -0.00308454545455 90292 1009554 0.089437
-6197  -0.003873125      90292 1509554 0.059813
-9685  -0.0046119047619  90292 2009554 0.044931
-10401 -0.00400038461538 90292 2509554 0.035979


Not exactly the result I was waiting for. Intuition failed (as is always the case with prime numbers). The sum never oscillates and cross back to zero creating what scientifics will call an spontaneous break of symmetry.



1 comment:

Unknown said...

Very interesting. I love prime numbers and all misteries around them. Take a look to this post about Ulam's Spiral and my own implementation of a similar approach.