Li(x) vs π(x) and Littlewood's Sign Change

Here is one of the most seductive traps in all of number theory. The logarithmic integral \operatorname{Li}(x) is the sharpest simple estimate we have for the prime count \pi(x) — and in every single case anyone has ever computed, from x = 10 out past x = 10^{25}, it comes out a little too big:

\pi(x) < \operatorname{Li}(x).

Trillions upon trillions of cases, and the inequality has never once failed. Any sane empiricist would call that a law of nature. It is not. In 1914 J. E. Littlewood proved that the difference \pi(x) - \operatorname{Li}(x) changes sign infinitely often — so somewhere out there \pi(x) not only catches up but overtakes \operatorname{Li}(x), then falls behind, forever, back and forth. The first place this happens is so enormous that no computer will ever reach it by counting. This page is the story of that gap: why the bias is there, why it is almost always one-sided, and why "true for every number we can check" is a world away from "true".

The persistent bias, in a table

Recall \operatorname{Li}(x) = \int_0^x \frac{dt}{\ln t} (the principal-value integral, sometimes written \operatorname{li}(x)). Line it up against the true prime count and watch the last column: the overshoot \operatorname{Li}(x) - \pi(x) grows steadily, and it is always positive.

x\pi(x)\operatorname{Li}(x) (rounded)\operatorname{Li}(x) - \pi(x)
10^{3}168178+10
10^{6}78{,}49878{,}628+130
10^{9}50{,}847{,}53450{,}849{,}235+1{,}701
10^{12}37{,}607{,}912{,}01837{,}607{,}950{,}281+38{,}263
10^{15}29{,}844{,}570{,}422{,}66929{,}844{,}571{,}475{,}287+1{,}052{,}618
10^{18}24{,}739{,}954{,}287{,}740{,}86024{,}739{,}954{,}309{,}690{,}415+21{,}949{,}555

The gap itself is roughly of size \sqrt{x}/\ln x — small next to x, but growing without bound. And it never turns negative. Why the stubborn one-sidedness? The answer is not luck; it comes from a second, hidden population of numbers that \operatorname{Li}(x) quietly overcounts.

Riemann's better estimate: R(x)

In his 1859 memoir, Riemann wrote down a sharper approximation than \operatorname{Li}(x) alone. Using the \mu from the logarithmic integral's neighbourhood — the Möbius function — he formed

R(x) = \sum_{n=1}^{\infty} \frac{\mu(n)}{n}\,\operatorname{Li}\!\left(x^{1/n}\right) = \operatorname{Li}(x) - \tfrac12\operatorname{Li}\!\left(x^{1/2}\right) - \tfrac13\operatorname{Li}\!\left(x^{1/3}\right) - \tfrac15\operatorname{Li}\!\left(x^{1/5}\right) + \tfrac16\operatorname{Li}\!\left(x^{1/6}\right) - \cdots

The leading correction is the term -\tfrac12\operatorname{Li}(x^{1/2}) = -\tfrac12\operatorname{Li}(\sqrt{x}), and it is the whole secret of the bias. Here is the intuition. Riemann's exact theory naturally counts not just primes, but prime powers, each weighted by 1/k: a prime p counts once, a square p^2 counts as \tfrac12, a cube p^3 as \tfrac13, and so on. There are about \pi(\sqrt{x}) \approx \operatorname{Li}(\sqrt{x}) squares of primes below x, so the "prime-square" population contributes an extra \tfrac12\operatorname{Li}(\sqrt{x}) that \operatorname{Li}(x) has silently folded in. Subtract it back off and you recover the honest prime count. That single -\tfrac12\operatorname{Li}(\sqrt{x}) is a smooth, always-negative drift of size \sim \tfrac12\sqrt{x}/\ln x — exactly the scale of the overshoot in the table above.

Worked example: R(x) vs Li(x) vs π(x) at x = 10⁶

Let us see how much the correction buys us. At x = 10^{6} the true count is

\pi(10^{6}) = 78{,}498.

The two estimates are

\operatorname{Li}(10^{6}) \approx 78{,}627.5, \qquad R(10^{6}) \approx 78{,}527.4.

Compare the errors head to head:

\operatorname{Li}(10^{6}) - \pi(10^{6}) \approx +129.5, \qquad R(10^{6}) - \pi(10^{6}) \approx +29.4.

Riemann's R is about 4.4 times closer. And we can see where the improvement comes from. The dominant correction is

\tfrac12\operatorname{Li}(\sqrt{10^{6}}) = \tfrac12\operatorname{Li}(1000) \approx \tfrac12(177.6) \approx 88.8.

Subtracting that from \operatorname{Li} already knocks the estimate down from 78{,}627.5 to about 78{,}538.7 — most of the way from \operatorname{Li}'s error of +129.5 down toward R's +29.4. The remaining cube-and-higher terms (-\tfrac13\operatorname{Li}(x^{1/3}) and beyond) trim off the last little bit. The \tfrac12\operatorname{Li}(\sqrt{x}) term really does explain the lion's share of the gap.

Seeing the bias

Below, the prime count \pi(x) is computed exactly by sieve, and we plot two error curves against it. The upper curve is \operatorname{Li}(x) - \pi(x): it climbs away from zero and, over this range, never comes back — the persistent positive bias, live. The lower curve is R(x) - \pi(x), Riemann's estimate, which oscillates in a tight band right around zero, crossing it repeatedly. R is not biased; it wobbles evenly on both sides, which is precisely why it is the better guess.

The distance between the two curves is essentially the smooth \tfrac12\operatorname{Li}(\sqrt{x}) drift. Take that drift away — as R does — and the leftover error is the pure "noise" of the primes, centred on zero.

Littlewood's theorem: the bias is a lie in the long run

Since \operatorname{Li}(x) - \pi(x) is positive for every computable x and its smooth part is the always-positive \tfrac12\operatorname{Li}(\sqrt{x}), it is desperately tempting to conjecture the inequality holds for all x. Gauss and Riemann themselves seem to have believed it. Littlewood demolished the guess.

The \Omega_{\pm} notation is the point: not only does the difference return to zero and cross, it swings by a genuinely large amount on both sides — the excursions grow like \sqrt{x}/\ln x (times a whisper of \ln\ln\ln x). What makes the theorem so striking is that Littlewood proved it without exhibiting a single crossing point. His argument shows a crossing must exist without saying where — a pure existence proof, the kind that drives computationalists to distraction.

Where the oscillation comes from: the explicit formula

Why does R(x) wobble around \pi(x) instead of tracking it perfectly? The answer is Riemann's explicit formula, which writes the prime count exactly as a smooth part plus a sum over the non-trivial zeros \rho = \tfrac12 + i\gamma of the zeta function. In the convenient R-smoothed form,

\pi(x) \approx R(x) - \sum_{\rho} R\!\left(x^{\rho}\right).

Read the two pieces separately.

So Littlewood's theorem is really a statement about resonance: infinitely often the countless prime-encoded waves conspire to point the same way. The bias and the sign changes are two faces of the same explicit formula — the smooth drift versus the rare constructive interference of the zeros.

If the first sign change exists, how big is it? This is the legend of the Skewes number. In 1933 Stanley Skewes, a student of Littlewood's, gave the first explicit upper bound for where \pi(x) > \operatorname{Li}(x) must first occur — assuming the Riemann Hypothesis — of about

e^{e^{e^{79}}} \approx 10^{10^{10^{34}}}.

Hardy called it, at the time, the largest number that had ever served any definite purpose in mathematics. In 1955 Skewes removed the reliance on RH, at the cost of an even more monstrous bound, e^{e^{e^{e^{7.705}}}}. Since then the estimate has been beaten down enormously: modern work (te Riele, Bays–Hudson, and others) shows a crossing occurs below about 1.4 \times 10^{316}, and there is very likely one near 1.397 \times 10^{316}. On the other side, direct computation has verified \pi(x) < \operatorname{Li}(x) for all x up beyond 10^{19}, so the true first crossing sits somewhere in the vast unexplored gulf between 10^{19} and 10^{316} — a region no sieve will ever enumerate.

"\pi(x) < \operatorname{Li}(x) always" is false — flatly, provably false — even though it holds for every number ever tested and probably every number that will ever be tested by direct computation. This is the cautionary tale par excellence of experimental mathematics:

The moral: in analytic number theory, "I checked it up to 10^{25}" is a hunch, not a theorem.

Yes, and it is called Chebyshev's bias. Split the odd primes by their remainder modulo 4: those \equiv 3 (like 3,7,11,19) versus those \equiv 1 (like 5,13,17,29). Chebyshev noticed in 1853 that the "3\bmod 4" team almost always leads the count: \pi(x;4,3) \ge \pi(x;4,1) for the overwhelming majority of x. It is the very same phenomenon — a smooth bias term (here fed by the primes squared, which are all \equiv 1 \bmod 4) tilting the race one way — sitting on top of an oscillation from the zeros of a Dirichlet L-function. And, exactly as with \operatorname{Li} vs \pi, the lead does change hands infinitely often (Littlewood again): the first time \pi(x;4,1) pulls ahead is at x = 26{,}861. These "prime races" are a whole rich subject, all descended from the same tension between a smooth drift and the music of the zeros.