## Finding Primes: A Fun Subproblem

The ongoing open mathematics project finding primes aims to find a deterministic algorithm to efficiently generate $$k$$-digit primes. The fastest known algorithm seems to be a method of Odlyzko which generates a $$k$$-digit prime in time $$O(10^{k/2})$$. The people working on the project have made some observations which come tantalizingly close to breaking that barrier. The obstruction is a beautiful little problem that I thought many people might enjoy, and which may well be tractable. If you’re interested in participating in the finding primes project, it might be a good entry point. So if you’ve got a good idea to solve the problem, pitch in and help over at the Polymath blog. But please be polite: read some background first, and take a look at some of the research threads to get a feel for how things work, and what’s already known.

One small caveat: the argument that follows is not in any way mine, it’s all the work of other people! A recent comment thread on this argument starts here.

Let $$\pi(x)$$ denote the number of primes less than or equal to $$x$$. $$\pi(x)$$ has a lot of structure, and there’s a surprising amount that can be said about it. In particular, the people working on finding primes have figured out a clever way of computing the parity of $$\pi(x)$$ in time about $$x^{5/11+o(1)}$$.

Suppose you can find two $$k$$-digit numbers $$x$$ and $$y$$ such that the parity of $$\pi(x)$$ and $$\pi(y)$$ are different. Set $$z = \lfloor (x+y)/2 \rfloor$$, i.e., take $$z$$ to be the midpoint between $$x$$ and $$y$$. Compute the parity of $$z$$. It must have either a different parity to $$x$$ or a different parity to $$y$$. Repeating this procedure $$O(k)$$ times, we can use a binary search to find adjacent $$k$$-digit numbers $$p-1$$ and $$p$$ such that $$\pi(p-1)$$ and $$\pi(p)$$ have different parity. We conclude that $$p$$ must be prime. That takes time $$O(10^{5/11 k + o(1)})$$, and so breaks the barrier set by Odlyzko’s method.

What’s the problem with this algorithm? The problem is finding the initial $$k$$-digit numbers $$x$$ and $$y$$ such that $$\pi(x)$$ and $$\pi(y)$$ have different parity. It would surprise me a great deal if this weren’t possible, but it’s not obvious (at least to me) how to do it quickly. Is there a fast way of doing this?

## Bertrand’s postulate

This post is motivated by the ongoing Polymath Project “finding primes”, an open source mathematics project whose aim (roughly speaking) is to find an efficient algorithm to deterministically generate a prime number of at least $$k$$ digits. The post isn’t a contribution to the ongoing research discussion, but rather describes background material I wanted to understand better: a proof of a mathematical theorem known as Bertrand’s Postulate, a simple result from the 19th century about how frequently prime numbers occur. It’s being cross-posted to the Polymath wiki. The post requires some familiarity with elementary number theory.

Despite its name, Bertrand’s postulate is a theorem, not an example of what we’d ordinarily call a postulate in mathematics. Here’s what it says:

Theorem (Bertrand’s Postulate): For every integer $$n \geq 2$$, there is a prime $$p$$ satisfying $$n < p < 2n$$.

Bertrand’s postulate is relevant to the finding primes problem because it guarantees the existence of a $$k$$-digit prime for any $$k$$. Brute force search thus yields a $$k$$-digit prime after about $$O(10^k)$$ steps; this can be considered the “trivial bound” for the problem.

Bertrand’s postulate was apparently first proved by Chebyshev. For large $$n$$, the claim follows as a consequence of the prime number theorem. We will give an elementary proof due to Erdos.

Our strategy is to analyse the prime factorization of the binomial coefficient $${2n \choose n}$$. What we’ll discover is that for primes $$p \leq n$$, the corresponding prime power in the prime factorization of $${2n \choose n}$$ is never very big. In fact, we can guarantee that those powers are quite small – much smaller than what one might a priori believe could be the case. What we’ll find as a consequence is that when we take the product of all the prime powers for $$p \leq n$$, the product can’t possibly be as big as $${2n \choose n}$$. And that means that there must be primes in the range $$n < p < 2n$$ which appear in the prime factorization of $${2n \choose n}$$. Rather than prove Bertrand's postulate directly, we'll first prove two results of independent interest. The first is a bound on the product of all primes less than $$n$$, due to Chebyshev. Lemma (Chebyshev bound): For integers $$n \geq 2$$, $$\prod_{p \leq n} p \leq 4^n$$, where the product is over all primes $$p$$ less than or equal to $$n$$.

The Chebyshev bound tells us that primes can’t occur too frequently (for example, with constant density) in the positive integers, for if they did, the product of primes on the left would rise much faster than $$4^n$$. Although it’s not needed for a proof of Bertrand’s postulate, insight can be gained by expressing this idea in a simple quantitative way. Observe that if $$\pi(n)$$ is the number of primes less than or equal to $$n$$, then $$\pi(n)! \leq \prod_{p \leq n} p$$, simply because the $$k$$th prime must be at least $$k$$. Combining this observation with Chebyshev’s bound gives $$\pi(n)! \leq 4^n$$. Taking logarithms of both sides, and applying Stirling’s approximation, we see that up to constant factors and small corrections, we have $$\pi(n) \ln \pi(n) \leq n$$. This, in turn, implies that, up to constant factors and small corrections, $$\pi(n) \leq n \ln \ln n / \ln n$$. Roughly speaking, the prime numbers are at most logarithmically dense in the positive integers. In fact, the prime number theorem tells us that $$\pi(n) \approx n / \ln n$$, as $$n$$ becomes large.

Proof of Chebyshev’s bound: We will induct on $$n$$. The case when $$n=2$$ is obviously true. Furthermore, if we assume the result when $$n$$ is odd, it follows immediately for $$n+1$$, since the left-hand side is not affected by incrementing $$n$$. So we assume the result is true up to some even number, $$n = 2m$$, and try to prove the result for $$2m+1$$. What we’ll aim to show is that:

$$(*) \prod_{m+1 < p \leq 2m+1} p \leq 4^m$$ If we can prove this, then multiplying by the inequality $$\prod_{p \leq m+1} p \leq 4^{m+1}$$ (which is true by the inductive hypothesis) will give us the desired result. To prove (*), note that every prime $$p$$ satisfying $$m+1 < p \leq 2m+1$$ must divide $${2m+1 \choose m}$$, since $$p$$ appears in the numerator, but not the denominator. Furthermore, the uniqueness of prime factorization means that the product of all such primes must also divide $${2m+1 \choose m}$$, and so we have $$\prod_{m+1 < p \leq 2m+1} p \leq {2m+1 \choose m}.$$ The proof is completed by noting that $${2m+1 \choose m}$$ appears twice in the binomial expansion of $$(1+1)^{2m+1}$$, and thus $${2m+1 \choose m} \leq 4^m$$. QED

There are two main ideas in our proof of Chebyshev’s bound, and it’s worth pausing to appreciate them. The first idea is that there should be a relationship between products of primes and factorials, e.g.,

$$\prod_{m+1 < p \leq 2m+1} p \leq {2m+1 \choose m}.$$ The second is that there should be a relationship between combinatorial coefficients like $${2m+1 \choose m}$$ and exponentials with fixed bases, e.g., $${2m+1 \choose m} \leq 4^m$$. Once these two ideas are firmly in mind, the proof of the Chebyshev bound is obvious. The second lemma used in our proof of Bertrand's postulate is a useful fact about the prime factorization of $${2n \choose n}$$, telling us that $${2n \choose n}$$ has a rather special prime factorization which only involves low powers. After the main statement of the lemma we will single out two special cases where the proof can be used to make statements that are a little stronger than the main statement. These cases are included explicitly only because they are useful later. Note that although they complicate the statement of the lemma somewhat, they are trivial consequences of the proof of the main statement in the lemma. Lemma: Let $$p$$ be a prime, and define $$r(p,n)$$ to be the largest number such that $$p^{r(p,n)}$$ divides $${2n \choose n}$$. Then $$p^{r(p,n)} \leq 2n$$. There are two special cases where we can make stronger statements: (1) if $$p > \sqrt{2n}$$, then $$r(p,n)$$ is $$1$$ or $$0$$; (2) if $$2n/3 < p \leq n$$, then $$r(p,n) = 0$$.

This lemma contains the essential insight underlying Bertrand’s postulate, and that we explained earlier: because we can guarantee that the prime powers are low, $${2n \choose n}$$ must have many prime factors. A careful accounting using the Chebyshev bound will show that we simply don’t have enough if one of those prime factors isn’t in the range $$n < p < 2n$$. Proof: To prove the lemma, first note that the prime power of $$p$$ in the factorization of $$n!$$ is given by $$\sum_{j=1}^{\infty} \lfloor n / p^j \rfloor$$. As a result, $$r(p,n) = \sum_{j=1}^\infty ( \lfloor 2n / p^j \rfloor – 2 \lfloor n / p^j \rfloor)$$. All terms in this sum are either $$0$$ or $$1$$, depending on whether $$\lfloor 2n/p^j \rfloor$$ is even or odd, and they are always $$0$$ when $$j > \log_p (2n)$$, whence $$r(p,n) \leq \log_p (2n)$$, which gives the main result.

In the special case of (1), $$p > \sqrt{2n}$$, simply observe that all but the first term in the sum vanishes, and so $$r(p,n) = \lfloor 2n/ p \rfloor – 2 \lfloor n/p \rfloor$$, which is either $$0$$ or $$1$$, according to whether $$\lfloor 2n/p \rfloor$$ is even or odd.

In the special case of (2), $$2n/3 < p \leq n$$, observe again that all but the first term in the sum vanishes, and so $$r(p,n) = \lfloor 2n/p \rfloor - 2 \lfloor n/p \rfloor$$. But for any such value of $$p$$ we see that $$\lfloor 2n/p \rfloor$$ is equal to $$2$$, which is even, and so $$r(p,n) = 0$$. QED

The proof of Bertrand’s postulate is now straightforward.

Proof of Bertrand’s postulate: For a contradiction, suppose there are no primes satisfying $$n < p < 2n$$. In light of case (2) of the last lemma, we can assume that all the prime factors in $${2n \choose n}$$ satisfy $$p \leq 2n/3$$. We split the prime factorizing of $${2n \choose n}$$ up into the cases where $$p \leq \sqrt{2n}$$ and where $$\sqrt{2n} < p \leq 2n/3$$. Applying the last lemma we obtain: $${2n \choose n} \leq \prod_{p \leq \sqrt{2n}} (2n) \prod_{\sqrt{2n} < p \leq 2n/3} p$$ We can bound the first product by noting that there are no more than $$\sqrt{2n}$$ primes of size at most $$\sqrt{2n}$$, and bound the second product using Chebyshev's bound: $${2n \choose n} \leq (2n)^{\sqrt 2n} 4^{2n/3}.$$ Observing that $${2n \choose n}$$ is the largest of the $$2n+1$$ terms in the binomial expansion of $$(1+1)^{2n}=4^n$$, we see that $$\frac{4^n}{2n+1} \leq {2n \choose n}$$ Combinining the last two inequalities and rearranging a little gives $$4^{n/3} \leq (2n+1)(2n)^{\sqrt 2n}.$$ The left-hand side rises much faster than the right, and so this inequality can only be true over some finite set of $$n$$. It should be straightforward to convince yourself that it fails for $$n > 2048$$, for example, and thus we must have $$n \leq 2048$$. In fact, we can do quite a bit better than $$n \leq 2048$$ with a bit more work, but the bound suffices for our purposes. What we have now shown is that our initial assumption – no prime in the range $$n < p < 2n$$ - can only possibly hold when $$n \leq 2048$$. But it's easily seen that the assumption is also false in that range, just by considering the sequence of primes $$2,3,5,7,13,23,43,83,163,317,631,1259$$, and $$2503$$. Each prime in the sequence is less than twice its predecessor, and so there must be a prime between $$n$$ and $$2n$$ for any $$n \leq 2048$$. QED

Published
Categorized as Polymath

## The Polymath blog

Earlier this year, Tim Gowers started a project in massively collaborative mathematics – an open approach to solving mathematical problems using blogs and wikis. The first iteration of this “Polymath Project” was very successful (see also Terry Taoâ€™s recent mini-Polymath), and new iterations are now being planned. To help with that process, Terry Tao has set up a Polymath blog, and there is now a very lively discussion going on about possible problems, including the very interesting problem of finding an efficient deterministic algorithm to generate prime numbers above a specified size.

Published
Categorized as Polymath