The Logarithmic Integral
The Prime Number Theorem
tells us that \pi(x), the count of primes up to x, is
asymptotic to x/\ln x. That is true — but it is also a slightly lazy way to state
the theorem, because x/\ln x is a surprisingly loose fit. There is a
cleaner, sharper "main term" hiding just underneath it: the logarithmic integral
\operatorname{Li}(x). It hugs \pi(x) so closely that at
a million it is off by barely a hundredth of a percent, and — as we'll see — the exact size of the gap
between \pi(x) and \operatorname{Li}(x) is one of the
deepest open questions in mathematics.
The idea behind it is almost childishly simple. If a whole number near t is prime
with "probability" about 1/\ln t, then to count all the primes up to
x we should just add up those probabilities — and adding up a density is
exactly what an integral does. That single instinct produces the best elementary estimate for
\pi(x) that anyone knows.
The definition
-
\operatorname{Li}(x) = \displaystyle\int_2^x \frac{dt}{\ln t} for
x > 2 — the offset logarithmic integral used throughout prime
counting.
-
\operatorname{li}(x) = \displaystyle\int_0^x \frac{dt}{\ln t} — the plain
logarithmic integral, taken as a Cauchy principal value to skirt the singularity where
\ln t = 0 at t = 1.
The two differ only by a constant: \operatorname{Li}(x) = \operatorname{li}(x) - \operatorname{li}(2),
where \operatorname{li}(2) \approx 1.045. Starting the clock at
2 instead of 0 is convenient for prime counting — the
first prime is 2, and it avoids the pole at t = 1
entirely. The integrand 1/\ln t blows up as t \to 1^+,
which is exactly why \operatorname{li}(x) needs the principal-value dodge and
\operatorname{Li}(x) does not.
There is no elementary closed form for either integral — you cannot write
\int dt/\ln t in terms of powers, roots, exponentials and logs. It is a genuinely
new "special function", as fundamental to prime counting as
the Gamma function
is to interpolation.
The heuristic: summing a density
Why should \int_2^x dt/\ln t count primes? Gauss's teenage insight was that the
primes thin out at a predictable rate: near t, about one integer in every
\ln t is prime, so the local density of primes is 1/\ln t.
Near t = 100 that density is 1/\ln 100 \approx 0.217
(roughly one prime in five); near t = 10^9 it has fallen to
1/\ln 10^9 \approx 0.048 (about one in twenty-one).
To count all the primes up to x, add up that density across every value
of t. A discrete sum \sum_{t=2}^{x} 1/\ln t becomes, in
the continuous limit, the integral
\pi(x) \;\approx\; \sum_{t=2}^{x} \frac{1}{\ln t} \;\approx\; \int_2^x \frac{dt}{\ln t} \;=\; \operatorname{Li}(x).
This is more honest than x/\ln x. The crude estimate x/\ln x
pretends the density stays fixed at its final value 1/\ln x across the
whole range [2, x] — but early on the primes are much denser, so that undercounts.
\operatorname{Li}(x) uses the correct, higher density at every point along the way,
which is precisely why it comes out larger, and closer to the truth.
The asymptotic expansion — where the extra accuracy comes from
Integrate \operatorname{Li}(x) by parts repeatedly (take
u = 1/\ln t, dv = dt) and a beautiful expansion falls
out:
\operatorname{Li}(x) \;\sim\; \frac{x}{\ln x}\left(1 + \frac{1!}{\ln x} + \frac{2!}{\ln^2 x} + \frac{3!}{\ln^3 x} + \cdots\right) = \frac{x}{\ln x}\sum_{k=0}^{\infty} \frac{k!}{(\ln x)^k}.
Read this carefully. The very first term is x/\ln x — so
\operatorname{Li}(x) agrees with the crude estimate to leading order, which
is why both satisfy the PNT. But \operatorname{Li}(x) then adds an entire tail of
correction terms 1!/\ln x, 2!/\ln^2 x, \dots that
x/\ln x simply throws away. That first correction, x/\ln^2 x,
is not small — it is smaller than the main term by only a single factor of \ln x —
so ignoring it (as x/\ln x does) is what leaves that estimate stuck several percent
adrift.
Worked example — watching the corrections land at x = 10^6. Here
\ln x = 13.816, so x/\ln x = 72{,}382. Multiply in the
successive factors k!/(\ln x)^k and accumulate:
| terms kept | new term x\cdot k!/\ln^{k+1}x | running total |
| k=0 | 72{,}382 | 72{,}382 |
| +\,k=1 | +5{,}239 | 77{,}621 |
| +\,k=2 | +758 | 78{,}380 |
| +\,k=3 | +165 | 78{,}545 |
| +\,k=4 | +48 | 78{,}593 |
The total is climbing toward \operatorname{Li}(10^6) \approx 78{,}628 — and the
true count is \pi(10^6) = 78{,}498. Notice how the crude first line,
72{,}382, is more than six thousand short, while just a few correction terms carry
us to within a hundred or so of the answer. That tail of factorials is the whole story of why
\operatorname{Li} wins.
That series is divergent — do not sum it forever. Because the numerators are factorials
k!, the terms k!/(\ln x)^k eventually grow once
k passes about \ln x, and the "sum" runs off to infinity.
It is an asymptotic series, not a convergent one: the right way to use it is to
truncate at the smallest term (near k \approx \ln x), which gives
the best possible accuracy — adding more terms after that makes the estimate worse. This is the
classic behaviour of asymptotic expansions, the same phenomenon you meet in Stirling's series for
\ln \Gamma.
A second trap: keep \operatorname{Li} and \operatorname{li}
straight. The offset \operatorname{Li}(x) = \int_2^x and the principal-value
\operatorname{li}(x) = \int_0^x differ by the constant
\operatorname{li}(2) \approx 1.045. It is a small shift, but sources disagree on
which they call "Li", so always check the lower limit before comparing numbers.
Seeing all three at once
Below, the jagged staircase is the true \pi(x), jumping by one at every prime. The
two smooth curves are the estimates: \operatorname{Li}(x) rides just above the
staircase, tracing its shape almost perfectly, while x/\ln x sags noticeably below.
Even at this modest scale the difference is unmistakable — and it only widens in
\operatorname{Li}'s favour as you zoom out.
Watch how \operatorname{Li}(x) stays a hair above the staircase across the
whole window. That persistent overshoot — \operatorname{Li}(x) > \pi(x) — is not an
accident of this range; as we'll see, it holds for every x anyone has ever computed,
and yet is provably not the final word.
The numbers, side by side
Nothing sells \operatorname{Li}'s superiority like the raw figures. Here are the two
estimates against the truth at three scales, together with their errors (using the offset
\operatorname{Li}):
| x |
\pi(x) (true) |
\operatorname{Li}(x) |
x/\ln x |
\operatorname{Li}(x)-\pi(x) |
\pi(x)-x/\ln x |
| 10^3 |
168 |
178 |
145 |
+10 |
+23 |
| 10^6 |
78{,}498 |
78{,}628 |
72{,}382 |
+130 |
+6{,}116 |
| 10^9 |
50{,}847{,}534 |
50{,}849{,}235 |
48{,}254{,}942 |
+1{,}701 |
+2{,}592{,}592 |
Look at the two error columns. At x = 10^9, the crude estimate is short by over
two and a half million primes; \operatorname{Li} is off by just
1{,}701 — a relative error of roughly 0.000003\%. And
there is a striking pattern in the \operatorname{Li} column: its error grows only
like \sqrt{x} (compare 10, 130, 1701 against the square
roots \sqrt{10^3}\approx 32, \sqrt{10^6}=1000,
\sqrt{10^9}\approx 31{,}623). That square-root-sized error is not a coincidence — it
is the fingerprint of the Riemann zeta zeros.
The connection to the zeta zeros
The Prime Number Theorem is best written not with x/\ln x but with
\operatorname{Li} as its true main term:
\pi(x) = \operatorname{Li}(x) + E(x),
and the entire mystery of the primes lives in the error E(x). Riemann's explicit
formula expresses that error as a sum over the non-trivial zeros
\rho of \zeta, schematically
E(x) \approx -\sum_{\rho} \operatorname{Li}(x^{\rho}). Each zero
\rho = \beta + i\gamma contributes an oscillation of size about
x^{\beta}: the further right a zero sits, the larger and more damaging its wobble.
-
Unconditionally, \pi(x) = \operatorname{Li}(x) + O\!\big(x\,e^{-c\sqrt{\ln x}}\big)
for some constant c > 0 — the classical PNT error.
-
The Riemann Hypothesis (all non-trivial zeros lie on \Re(s) = \tfrac12) is
equivalent to the sharpened bound
\pi(x) = \operatorname{Li}(x) + O\!\big(\sqrt{x}\,\ln x\big).
This is why the error column above hovers near \sqrt{x}: if RH holds, the gap
\operatorname{Li}(x) - \pi(x) can never grow faster than about
\sqrt{x}\,\ln x. A single zero drifting off the critical line to
\Re(s) = \beta > \tfrac12 would let the error swell to
x^{\beta} and spoil the fit. So the astonishing tightness of
\operatorname{Li} is, quite literally, empirical evidence for the Riemann
Hypothesis.
In every case ever computed — up to x = 10^{25} and beyond —
\operatorname{Li}(x) comes out larger than
\pi(x), so \operatorname{Li}(x) - \pi(x) > 0. Gauss and
Riemann both suspected this held forever. It does not.
In 1914, J. E. Littlewood proved that the difference \operatorname{Li}(x) - \pi(x)
changes sign infinitely often: infinitely far out, \pi(x) catches
up and overtakes \operatorname{Li}(x), then falls back, forever. What makes
this so startling is that Littlewood proved a crossing must exist without exhibiting a single one — no
computed value of x had ever shown it, and none has since. In 1933 his student
Stanley Skewes gave the first (colossal) upper bound on where the first flip occurs, the famous
Skewes number, originally around 10^{10^{10^{34}}} — for a time the
largest number to appear in a serious mathematical proof. Modern work has pulled the bound down to somewhere
near 10^{316}, but that is still hopelessly beyond any conceivable computation.
The moral is pure analytic number theory: a pattern that holds for every number humanity will ever test can
still be false. Only proof, never computation, settles the question. We pick this thread up in
Li versus π and Littlewood's sign change.
A divergent series sounds useless, yet the asymptotic expansion of \operatorname{Li}
is one of the most practically accurate tools in the subject. The resolution is the meaning of
\sim: it does not promise the infinite sum converges, only that
truncating after N terms leaves an error smaller than the last term kept —
for each fixed N, as x \to \infty. So you get real,
controlled accuracy by stopping at the optimal point (the smallest term), and the best you can do is
exponentially good in \ln x. Divergent-but-asymptotic series like this one power
everything from Stirling's formula to quantum field theory; convergence is a luxury, not a requirement, for
usefulness.