On the last digits of conscutive prime numbers

If you have a prime number p (other than two and five) then the last digit of p is 1, 3, 7, or 9. If for some reason we believe that prime numbers are randomly distributed (after all, the last digits 1,3,7, and 9 appear equally likely among primes), then we expect if a prime numbers ends in 1, then the next prime number also ends in 1 with probability of 1/4. A recent study has shown otherwise, statistically, and has proved it mathematically, assuming the Hardy–Littlewood k-tuple conjecture is true. In fact the statistical data shows the probability is less than 1/4. Here is an article explaining the main content of this study.

And if you want to check it for yourself, here is a little code that finds the empirical probability of two consecutive prime numbers ending in the same last digit:

n = 100000
Primes = primes_first_n(n)
q = 10
Qrimes = []
for p in Primes:
    Qrimes += [p % q]
count = [ 0 for i in range(q) ]
for i in range(n-1):
    a = Qrimes[i]
    if a == Qrimes[i+1]:
        count[a] += 1
        #print(Primes[i],Primes[i+1])
(sum(count)/(n)).n(32)
0.153300000

And here is a modification that shows how the probability changes as n grows:

n = 1000000

Primes = primes_first_n(n)
q = 10

Qrimes = []
for p in Primes:
    Qrimes += [p % q]

Probs = []

count = [ 0 for i in range(q) ]
for i in range(n-1):
    a = Qrimes[i]
    if a == Qrimes[i+1]:
        count[a] += 1
        Probs += [[i,(sum(count)/(i))]]
        
P = point(Probs)
P
tmp_Ex59GO

As n grows (horizontal axis) the empirical probability of having two consecutive prime numbers with the same last digit (vertical axis) changes but remains well below 1/4.

The fun part is by noting the last digit of a number is just the remainder mod 10, then you can ask about what happens to the remainders mod some other number q. In the paper they show the probability is still less than what one would expect  mod any number q, which sounds paradoxical.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s