# Prime counting function

### From Polymath1Wiki

One way to find primes is to find a polynomial time algorithm to compute π(*x*), the number of primes less than x, to reasonable accuracy. For example, if we can find π(*x*) to better than 10^{k / 2} accuracy for k-digit x, we can break the square root barrier. We don't necessarily have to do this for all x; just having a targeted x for which we can show π(*x* + *y*) − π(*x*) > 0 for some *x*˜10^{k} and *y* = *o*(10^{k / 2}) would suffice.

Now, perhaps instead of trying to prove that intervals like [*x*,*x* + (log*x*)^{A}] contain primes unconditionally, we should first try to be much less ambitious and aim to show that *some* interval with , contains a prime number that we can discover computationally.

How? Well, let’s start by assuming that we can computationally locate all the zeros in the critical strip up to height . Then what we can do is some kind of “binary search” to locate an interval containing loads of primes: say at the *i*th step in the iteration we have that some interval [*u*,*v*] has loads of primes. Then, using the explicit formula for (actually, the usual quantitative form of the identity), we can decide which of the two intervals [*u*,(*u* + *v*) / 2] or [(*u* + *v*) / 2,*v*] contains loads of primes (maybe both do — if so, pick either one for the next step in the iteration). We keep iterating like this until we have an interval of width around *x*^{1 / 2 + ε} or so that we know contains primes.

Ok, but how do you locate the zeros of the zeta function up to height ? Well, I’m not sure, but maybe one can try something like the following: if we can understand the value of ζ(*s*) for enough well-spaced, but close together, points up the half-line, then by taking local interpolations with these points, we can locate the zeros to good precision. And then to evaluate ζ(*s*) at these well-spaced points, maybe we can use a Dirichlet polynomial approximations, and then perhaps apply some variant of Fast Fourier Transforms (if this is even possible with Dirichlet polynomials, which are not really polynomials) to evaluate them at lots of values *s* = 1 / 2 + δ quickly — perhaps FFTs can speed things up enough so that the whole process doesn’t take more than, say, 10^{k / 2} polylog(k) bit operations. Keep in mind also that our Dirichlet polynomial approximation only needs to hold “on average” once we are sufficiently high up the half-line, so it seems quite plausible that this could work. Note that for *s* near to 1/2 we would need to be more careful, and get the sharpest approximation we can, because those terms contribute more in the explicit formula.

## Computing the parity of π(*x*)

Interestingly, there is an elementary way to compute the parity of π(*x*) in *x*^{1 / 2 + o(1)} time. The observation is that for square-free n, the divisor function τ(*n*) (the number of divisors of n) is equal to 2 mod 4 if n is prime, and is divisible by 4 otherwise. This gives the identity

2π(x) = | ∑ | τ(n)μ(n)^{2} mod 4. |

n < x |

Thus, to compute the parity of π(*x*), it suffices to compute

∑ | τ(n)μ(n)^{2} |

n < x |

.

But by Mobius inversion, one can express and so

Since one can compute all the μ(*d*) for *d* < *x*^{1 / 2} in *x*^{1 / 2 + o(1)} time, it would suffice to compute in (*x* / *d*^{2})^{1 / 2}*x*^{o(1)} time for each d. One can use the multiplicativity properties of τ to decompose this sum as a combination of *x*^{o(1)} sums of the form

∑ | τ(n) |

n < y |

for various , so it suffices to show that

∑ | τ(n) = | ∑ | 1 |

n < y | a,b:ab < y |

can be computed in *y*^{1 / 2 + o(1)} time. But this can be done by the Gauss hyperbola method, indeed

The same method lets us compute π(*x*) mod 3 efficiently provided one can compute

∑ | τ_{2}(n) = | ∑ | 1 |

n < x | a,b,c:abc < x |

efficiently. Unfortunately, so far the best algorithm for this takes time *x*^{2 / 3 + o(1)}. If one can compute π(*x*) mod q for every modulus q up to O(\log x), one can compute π(*x*) by the Chinese remainder theorem.

Related to this approach, there is a nice identity of Linnik. Let Λ(*n*) be the van Mangoldt function and *t*_{j}(*n*) the number of representations of n as ordered products of integers greater than 1, then . The sum is rather short since *t*_{j}(*n*) = 0 for j larger than about \ln(n). Note that the function *t*_{j}(*n*) is related to τ_{k}(*n*) by the relation . Again, *t*_{2}(*n*) is computable in n^{1/2} steps, however *t*_{j}(*n*), for larger j, appears more complicated. Curiously this is a fundamental ingredient in the Friedlander and Iwaniec work.

## Breaking the square root barrier

It is known that breaking the square root barrier for breaks the square root barrier for the parity of π(*x*) also: specifically, if the former can be computed in time *x*^{1 / 2 − ε + o(1)} for some ε < 1 / 4, then the latter can be computed in time *x*^{1 / 4 + 1 / (4 + 16ε / 3) + o(1)}. Details are here.

Using Farey sequences, one can compute the former sum in time *x*^{1 / 3 + o(1)} (and hence the latter sum in time *x*^{5 / 11 + o(1)}:

The argument is similar to elementary proofs (such as the one waved at in the exercises to Chapter 3 of Vinogradov's Elements of Number Theory) of the fact that the number of points under the hyperbola equals (*m**a**i**n**t**e**r**m*) + *O*(*N*^{1 / 3}(log*N*)^{2}).

What we must do is compute in time *O*(*N*^{1 / 3}(log*N*)^{3}).

**Lemma 1**Let*x*be about*N*^{θ}. Assume that . Assume furthermore that

*q* < = *Q*, where *Q* = *N*^{θ − 1 / 3} / 10. Then the sum

∑ | {N / n} |

x < = n < x + q |

can be computed in time *O*(log*x*) with an error term < 1 / 2.

**Proof**

We can write

*N*/*n*=*N*/*x*−*N*/*x*^{2}*t*+ η_{2}*t*^{2}/*N*^{3θ − 1}=*N*/*x*− (*a*/*q*+ η /*q*^{2})*t*+ η_{2}*t*^{2}/*N*^{3θ − 1},

where *n* = *x* + *t*,0 < = *t* < *q* an integer, and | η_{2} | < = 1*f**s* independent of n. Since *q* < = *Q* and *Q* = *N*^{θ − 1 / 3} / 10, we have
η*t*^{2} / *N*^{3θ − 1} < 1 / 1000*q*. We also have .
Thus, η*t*^{2} / *N*^{3θ − 1} + η / *q*^{2}*t* < 1 / 2*q*. It follows that

- | {
*N*/*n*} − {*N*/*x*−*a**t*/*q*} | < 1 / (2*q*)

except when {*N* / *x* − *a**t* / *q*}1 − 1 / (2*q*). That exception
can happen for only one value of (namely, when *a**t* is congruent mod q to
the integer closest to {*N* / *x*}*q*) and we can easily find that *t* (and isolate it
and compute its term exactly) in time *O*(log*n*) by taking the inverse of .

Thus, we get the sum

∑ | {N / n} |

x < = n < x + q |

in time *O*(log*n*) with an error term less than (1 / 2*q*) * *q* = 1 / 2 once we know the sum

∑ | {N / x − at / q} |

0 < = t < q |

exactly. But this sum is equal to

∑ | {r / q + ε / q} |

0 < = r < q |

, where
ε: = {*q**N* / *x*}, and that sum is simply (*q* − 1) / 2 + ε. Thus, we have
computed the sum

∑ | {N / n} |

x < = n < x + q |

in time *O*(log*n*).
QED

Now we show why the lemma is enough for attaining our goal (namely, computing with **no** error term). We know that

∑ | [N / n] = | ∑ | N / n − | ∑ | {N / n} = N * (log(x + q) − log(x)) − | ∑ | {N / n}. |

x < = n < = x + q | x < = n < x + q | x < = n < x + q | x < = n < x + q |

We also know that

∑ | [N / n] |

x < = n < = x + q |

is an integer. Thus, it is enough to compute

∑ | {N / n} |

x < = n < x + q |

with an error term <1/2 in order to compute

∑ | [N / n] |

x < = n < x + q |

exactly.

We now partition the range , into intervals of the form *x* < = *n* < *x* + *q*, where q is the denominator of a good approximation to *N* / *x*^{2}, that is to say, an approximation of the form *a* / *q*,gcd(*a*,*q*) = 1,*q* < = *Q* with an error term . Such good approximations are provided to us by Hurwitz's approximation theorem. Moreover, it shouldn't be hard to show that, as x varies, the q's will be fairly evenly distributed in [1,Q]. (Since Hurwitz's approximation is either one of the ends of the interval containing *N* / *x*^{2} in the Farey series with upper bound Q/2 or the new Farey fraction produced within that interval, it is enough to show that Dirichlet's more familiar approximations have fairly evenly distributed denominators.) This means that 1/q should be about (log*Q*) / *Q* in the average.

Thus, the number of intervals of the form *x* < = *n* < *x* + *q* into which has been partitioned should be about (log*Q*)*N* / *Q*. Since the contribution of each interval to the sum can (by Lemma 1 and the paragraph after its proof) be computed exactly in time *O*(log*x*), we can compute the entire sum in in time *O*((log*x*)(log*Q*)*N*^{θ} / *Q*) = *O*((log*N*)^{2}*N*^{1 / 3}).

(There are bits of the sum (at the end and the beginning) that belong to two truncated intervals, but those can be computed in time .)

We partition into *O*(log*N*) intervals of the form , and obtain a total running time of *O*((log*N*)^{3}*N*^{1 / 3}),
as claimed.