Density of primes containing specific digits

202 Views Asked by At

I suspect that primes containing certain digits (e.g. $1$, $3$) are way more common than primes containing other digits e.g. containing $2,4$ since my intuition tells me the latter combination is divisible by so many numbers: For example $13$ and $31$ are prime while neither $24$ or $42$ is (I take here the trivial null case of $2$'s and $4$'s for illustrative purposes).

This came to my mind as I was playing around with $1$'s and $3$'s trying to guess a prime number consisting of these two digits. To my surprise I guessed the following primes (tested with PrimeQ[...] of Mathematica) quite easily (the first ones in a couple of guesses while that last one took a dozen): $$ 11131, \\ 111311131 \\ 11131113113131111 \\ 11131113111111111111131311 $$

How come? Is this pure luck? I have a hard time believing it be pure luck due to the Prime Number Theorem.

(For the last number in the list I basically put in $1$'s and $3$'s randomly a dozen of times until I hit a prime.)

3

There are 3 best solutions below

2
On BEST ANSWER

This is not so surprising: An improvement to the P.N.T. implies that the number $\pi(x)$ of primes $\leq n$ is given by the (offset) logarithmic integral function, $$\operatorname{Li}(x) := \int_2^x \frac{dt}{\log t} .$$ Heuristically, the probability that a given random integer $\approx N$ is prime is $$\left.\frac{d}{dx}\right\vert_N \operatorname{\operatorname{Li}(x) = \frac{1}{\log N}},$$ but all primes $> 2$ are odd, so (again heuristically) the probability that a given random odd integer $\approx N$ is twice that, $$\frac{2}{\log N}.$$ For the largest number $N_0 := 11131113111111111111131311 11131$ in your list, computing gives $$\frac{2}{\log N_0} = 0.034679\!\ldots \approx \frac{1}{29} ,$$ so, naively, one would have to try $29$ odd numbers of that magnitude to find a prime, and one would find one in the first dozen attempts $> \frac{1}{3}$ of the time. One could derive a similar approximation using just the P.N.T., but the math for this better approximation is a little easier.

1
On

As you have Mathematica you could simply create all numbers made of 1s and 3s of a certain length then determine which ones are prime then divide by the number of possible numbers. Here is a function which can do that:

f[n_]:=Count[Map[PrimeQ[FromDigits[#]]&,Tuples[{1,3},n]],True]/2^n

Lets break it down:

Tuples[{1,3},n] creates all possible lists of length n made from the digits 1 and 3. Then the functions PrimeQ and FromDigits is Mapped over all these lists to firstly convert each list to an actual number then test if its prime. The True results of this mapping is then counted and finally this number is divide by the total number of permutations.

Comparing to your situation we see:

f[5]=$\frac{9}{32}$

f[9]=$\frac{75}{512}$

f[17]=$\frac{9461}{131072}$

f[26]=$\frac{?}{67108864}$ = too hard for my computer to process

1
On

Your question, whether or not primes containing some digits are more common than primes containing others can be made into a precise question in various different ways. One obvious way is the following: does the quantity $$ \lim_{N \to \infty} \frac{\#\{p < N \mid \text{$p$ prime and $p$ contains digit $d$}\}}{\#\{p < N \mid \text{$p$ prime}\}} $$ always exist, and if so, does it differ for different digits $d$?

The answer to this question is no, and in fact the limit above always exists and always equals 1. The reason comes down to the following informal facts: there are quite many primes, while there are very few numbers which do not contain all 10 digits.

In their paper on the Copeland-Erdős constant, Copeland and Erdős prove the following result (paraphrased, and specialized to our situation):

Lemma: There is a $\delta < 1$ such that for sufficiently large $N$, the number of numbers below $N$ which do not contain all 10 digits is less than $N^\delta$.

Let's fix such a $\delta$. From the prime number theorem, we know that the number of primes less than $N$ is approximately $\frac N{\log N}$ for large enough $N$. Thus, the number of primes below $N$ which contain all 10 digits is certainly at least $$ \frac N{\log N} - N^\delta $$ for $N$ sufficiently large. But then we have for any digit $d$ \begin{align*} 1 &\geq \lim_{N \to \infty} \frac{\#\{p < N \mid \text{$p$ prime and $p$ contains digit $d$}\}}{\#\{p < N \mid \text{$p$ prime}\}}\\ & \geq\lim_{N \to \infty} \frac{\#\{p < N \mid \text{$p$ prime and $p$ contains all digits $d$}\}}{\#\{p < N \mid \text{$p$ prime}\}}\\ &\geq \lim_{N \to \infty} \frac{\frac N{\log N} - N^\delta}{\frac N{\log N}}\\ &= 1. \end{align*} This argument can be extended without too much effort to different bases, and to different substrings (instead of just single digits).