# Approximate number of primes below a given integer?

The problem of the complexity of the exact counting problem for primes is interesting. The best result we have about primes is that it is hard for TC0. But counting the number of witnesses to a TC0 function can be as difficult as sharpP. The best upper-bound is P by AKS which gives a sharpP upper-bound for the exact counting problem.

There is no known algorithm for exact counting better that P, otherwise we would be able to check if a number x is a prime by counting the number of primes before x-1 and x and comparing them.

The problem can't be in P unless we can solve the problem of finding prime numbers in P which is an open problem: we can use a binary search to find the first prime number after x by finding the first number y>x where there are more primes before y than x.

Can we do better if we relax the question to approximate counting? I know that the question is not completely well-defined. We need to first clarify what we mean by "approximate", e.g., an absolute error or a relative error? etc. But I don't know what would be a good definition.

Given $n$, how well can we approximate the number of prime numbers below $n$ in polynomial time?

• Any particular reason you put [closed] at the end of your own question? I'm guessing you thought people wouldn't look at it then, and it'd stay open? (See tea.mathoverflow.net/discussion/1543) – Zev Chonoles Apr 8 '13 at 0:52
• This is all more strange because the questions seems to make sense, and to be of some interest. – Joël Apr 8 '13 at 0:57
• The obvious upper bound, assuming RH, is $O(\sqrt{x} \ln x)$, using $Li(x)$. – Will Sawin Apr 8 '13 at 1:32
• For example, how would one prove that there is no algorithm computing the number $\pi(n)$ of primes up to $n$ in polynomial time ? Or is it not possible to prove statements like this with current technology ? Is it even true ? After all, in Hardy's book "Ramanujan", Hardy mentions several false formulas that the young Ramanujan believed to have proved expressing $\pi(x)$ as the sum of a series, and such a formula would give, if I am not mistaken, such an algorithm. The formulas happened to be false, but is there a reason such formulas cannot be true ? – Joël Apr 8 '13 at 3:58
• @Joël, of course you are right. I would, however, like to see some evidence that the person asking knows what all the words mean. – Will Jagy Apr 8 '13 at 4:54

The Lagarias-Odlyzko algorithm gives a method for counting the number of primes less than $n$ in time $O_{\epsilon} ( n^{1/2+\epsilon})$ time. Roughly speaking, this algorithm proceeds by expressing the prime counting function as an integral involving the Riemann zeta function and then approximating the integral with numerical integration. This is currently the best known result in this direction, however the Polymath4 project found an algorithm for computing the parity of the number of primes less than $n$ in time $n^{1/2 -\delta}$ for some small $\delta > 0$.

• I'm guessing the words "polynomial time" above are meant in the logarithm of $n$. To answer that, it would be interesting to know how well the Lagarias-Odlyzko algorithm approximates $\pi(x)$ if one is only willing to put it in $log^k(x)$ time. – Dror Speiser Apr 8 '13 at 7:57
• So we have subexponential time algorithm, but nothing close to a polynomial time. Is it expected that there is no polynomial time algorithm, or on the contrary that there is some method ? Or perhaps people disagree about what to expect, as I have read somewhere on this site, they disagree if we ought to expect that the factorization problem can be solved in polynomial time or not. An indication that there might be a positive answer is an analogy with an admittedly rather different case, the one of the partition function $p(n)$. Computing it naively is certainly exponential time (or more)... – Joël Apr 8 '13 at 13:53
• but the formula of Hardy, Ramanujan and Rademacher allows for an exact computation in polynomial time. – Joël Apr 8 '13 at 13:55
• @Dror, I agree that that is likely what Alex meant. I didn't mean to suggest that this was a complete solution, only partial progress. – Mark Lewko Apr 8 '13 at 21:34

The problem of the complexity of the exact counting problem for primes is interesting. The best result we have about primes is that it is hard for TC0. But counting the number of witnesses to a TC0 function can be as difficult as sharpP. The best upper-bound is P by AKS which gives a sharpP upper-bound for the exact counting problem.

There is no known algorithm for exact counting better that P, otherwise we would be able to check if a number x is a prime by counting the number of primes before x-1 and x and comparing them. The problem can't be in P unless we can solve the problem of finding prime numbers in P which is an open problem: we can use a binary search to find the first prime number after x by finding the first number y>x where there are more primes before y than x.

Can we do better if we relax the question to approximate counting? I know that the question is not completely well-defined. We need to first clarify what we mean by "approximate", e.g., an absolute error or a relative error? etc. But I don't know what would be a good definition.

PS I added [closed] to the title. I wanted to test if anyone reads closed questions. No mischief was intended.

Alex

• Turning this around, it is not known that P$\neq$#P, so there is no way to show that one cannot get perfect accuracy in polynomial time. – Will Sawin Apr 8 '13 at 7:01
• To Alex: I think some dark side of the human soul makes that people are even more likely to read a question if it is closed, somewhat similarly to the well-known phenomenon as people driving much slower on the highway when there has been a car accident on the other side, just to have more time to look at what happened. – Joël Apr 8 '13 at 13:48
• Alex, so if I understand well, one can formulate your question in a more open-ended way as follows: given $\epsilon>0$, what is the time $T_a(n,\epsilon)$ (resp $T_r(n,\epsilon)$) that the best known algorithm takes to compute $\pi(n)$ with an error less than $\epsilon$ (resp. less than $\epsilon \pi(n)$)? Also one can replace best known algorithm with best possible algorithm, so that makes four question. Are you more interested into what one can do right now, or what is eventually possible? The answer depends on two variables, so may be more subtle than a dichotomy polynomial/exponential. – Joël Apr 8 '13 at 14:05
• @Alex, I noticed you set up a separate account (with the same name) for your answer here. You might look into getting the two accounts merged. (You really should have edited the original question instead of posting an answer.) – Barry Cipra Apr 8 '13 at 14:37
• @Joël, unregistered users cannot edit their own posts: there is no way to log into an unregistered account. The software uses a temporary cookie in the browser to remember unregistered users, however as soon as the cookie is deleted the user looses access to the account. – Kaveh Apr 10 '13 at 20:20