Article 3Y2KQ Pi primes

Pi primes

by
John
from John D. Cook on (#3Y2KQ)

I was reading a recent blog post by Evelyn Lamb where she mentioned in passing that 314159 is a prime number and that made me curious how many such primes there are.

Let's look at numbers formed from the digits of I to see which ones are prime.

Obviously 3 and 31 are prime. 314 is even. 3141 is divisible by 9 because its digits sum to 9, and 31415 is clearly divisible by 5. And now we know that 314159 is prime. What's the next prime in the sequence? Here's a little Python code to find out.

 from sympy import pi, isprime M = 1000 digits = "3" + str(pi.evalf(M+1))[2:] for i in range(1, M+1): n = int(digits[:i]) if isprime(n): print(n)

This looks at numbers formed from the first digit up to the thousandth digit in the representation of I. The only other prime it finds is

31415926535897932384626433832795028841.

After writing running the Python code above, I wondered whether this sequence is in OEIS, and indeed it is, sequence A005042. The OEIS says the next number in the sequence is 16,208 digits long.

Expected number of primes

I expected to find more primes out of the first 1,000 digits of I and was surprised that the next prime is so long.

How many primes whould we expect if we look at random numbers of length 1 through 1000? (The numbers formed from the digits of I are not random, but I want to compare them to random selections.)

From the prime number theorem, the probability that a d-digit number is prime is approximately 1/d log 10. So if we pick numbers of length 1, 2, 3, " N, the number of primes we'd expect to find is

pi_primes.svg

where HN is the Nth harmonic number. Harmonic numbers grow very slowly, and so this gives us an idea why the number of primes we find is so small. In particular, it says if we look out 1,000 digits, we'd expect to find 3.25 primes. And so finding 4 primes isn't surprising.

By the way, HN is roughly log N, so the expected number of primes is roughly log N / log 10, or simply log10N. [1]

Other numbers

To see if our prediction holds, let's try a few more irrational numbers.

First, let's look at e. Then we get these four prime numbers:

227127182812718281828459045235360287471352662497757247093699959574966967627724076630353547594571

Next, let's try the square root of 2. Then we get these three prime numbers:

14142135623730950488016887242096980785696718753769480731414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641141421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623091229702492483605585073721264412149709993583141322266592750559275579995050115278206057147010955997160597027453459

And finally, sin(2018) gives us two primes:

89890078059172214077866908781516358161827277734319970800477363723960779818810729974998238099333154892009885458973321640841442042739723513347225471340149039460391024770670777037177784685508982613866838293832904866761046669825265135653209394367093522291768886320360545920897111922035021827790766895274726280695701753189405911185099453319400331979946988526902527520607778873012543871813339138882571549068827579760491442082336321409598206489746377828352552073997340874649330911864108558685738003182332758299767812686413014214285003827180623455181083706822164258525158371971877396069605035317998430446771215296978812833752733

We might expect to find more primes when the leading digit is small because each time we select a number with d digits we're looking lower in the range where primes are more dense. That is consistent with the small number of examples in this post.

Related posts

[1] When I write "log" without a subscript, I always mean natural log, log base e. If you're not accustomed to this, see why this is conventional.

inMkddwCT_4
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments