Mertens' Theorems
Here is a fact that ought to feel impossible. Add up the reciprocals of the primes —
\tfrac12 + \tfrac13 + \tfrac15 + \tfrac17 + \tfrac1{11} + \cdots — and the
total never stops growing. It runs off to infinity. That already tells you there are
infinitely many
primes, and more: it says the primes are not too sparse, since a genuinely thin set
(like the squares, whose reciprocals sum to \pi^2/6) would converge.
But how fast does it diverge? In 1874 Franz Mertens answered this — and two sister questions —
with a precision that is almost eerie, and, remarkably, entirely by elementary means:
a full generation before the
Prime Number Theorem was proved, using
nothing heavier than Stirling's formula and careful bookkeeping. The answer is one of the most
beautiful in analytic number theory:
\sum_{p \le x} \frac{1}{p} = \log\log x + M + o(1).
The reciprocals of the primes diverge — but only like \log\log x, the
slowest-growing function you are ever likely to meet. To make the sum exceed 4
you need primes out past x \approx 10^{18}. This is divergence at a crawl.
The three theorems
Mertens proved three statements, and they form a ladder: the first is the workhorse, the second falls
out of it by summation, and the third is the showstopper — an infinite product over primes whose value
is governed by Euler's
constant \gamma.
As x \to \infty:
-
First theorem.
\sum_{p \le x} \frac{\log p}{p} = \log x + O(1).
-
Second theorem.
\sum_{p \le x} \frac{1}{p} = \log\log x + M + o(1),
where M = 0.26149\,72128\dots is the Meissel–Mertens constant.
-
Third theorem.
\prod_{p \le x}\left(1 - \frac{1}{p}\right)^{-1} \sim e^{\gamma}\log x,
\qquad\text{equivalently}\qquad \prod_{p \le x}\left(1 - \frac{1}{p}\right) \sim \frac{e^{-\gamma}}{\log x},
with \gamma = 0.57721\dots the Euler–Mascheroni constant.
Note the sharpness. The second theorem does not merely say "the sum diverges"; it pins the divergence
to \log\log x and names the exact constant left over. The third
conjures an e^{\gamma} out of a product that mentions only the integer
1 and the primes — a genuinely startling appearance we will explain below.
Proving the first theorem: Stirling meets the primes
The engine is an identity you may know from the
von Mangoldt function
\Lambda(n) — which equals \log p when
n = p^{k} is a prime power and 0 otherwise. It
rebuilds the logarithm out of divisors:
\log n = \sum_{d \mid n} \Lambda(d).
(Check it on n = 12 = 2^2\cdot 3: the divisors that are prime powers are
2, 4, 3, contributing \log 2 + \log 2 + \log 3 = \log 12.)
Sum this over all n \le x and swap the order of summation, grouping by the
divisor d — which appears in every multiple d, 2d, 3d, \dots
up to x, i.e. \lfloor x/d\rfloor times:
\sum_{n \le x}\log n = \sum_{n \le x}\sum_{d \mid n}\Lambda(d) = \sum_{d \le x}\Lambda(d)\left\lfloor \frac{x}{d}\right\rfloor.
Now evaluate the left side with Stirling's formula,
\log(\lfloor x\rfloor!) = \sum_{n\le x}\log n = x\log x - x + O(\log x). On
the right, drop the floor at a cost of O(1) per term, using
\lfloor x/d\rfloor = x/d + O(1):
\sum_{d \le x}\Lambda(d)\left\lfloor\frac{x}{d}\right\rfloor = x\sum_{d \le x}\frac{\Lambda(d)}{d} + O\!\left(\sum_{d\le x}\Lambda(d)\right) = x\sum_{d \le x}\frac{\Lambda(d)}{d} + O(x),
where the error is O(x) because Chebyshev's estimate gives
\sum_{d\le x}\Lambda(d) = \psi(x) = O(x). Matching the two expressions and
dividing by x:
\sum_{d \le x}\frac{\Lambda(d)}{d} = \log x + O(1).
Finally, split \Lambda into primes and higher prime powers. The
higher-power tail is harmless — it converges:
\sum_{p}\sum_{k \ge 2}\frac{\log p}{p^{k}} = \sum_p \frac{\log p}{p(p-1)} < \infty.
So the prime-power terms contribute only O(1), and what survives is exactly
the first theorem: \sum_{p\le x}\frac{\log p}{p} = \log x + O(1). One line of
Stirling, one swap of summation — no complex analysis anywhere.
From the first to the second: peeling off the \log p
The second theorem is the first theorem with the weight \log p removed. The
clean way to remove it is Abel summation (partial
summation): to turn a sum \sum a_p into \sum a_p\cdot g(p)
you integrate g against the running total of the a_p.
Here a_p = \frac{\log p}{p} and g(t) = \frac{1}{\log t},
so that a_p\cdot g(p) = \frac1p. Write the running total as
A(t) = \sum_{p \le t}\frac{\log p}{p} = \log t + R(t), \qquad R(t) = O(1).
Abel summation then gives
\sum_{p \le x}\frac{1}{p} = \frac{A(x)}{\log x} + \int_2^x \frac{A(t)}{t\,\log^2 t}\,dt.
Substitute A(t) = \log t + R(t). The leading pieces are the whole story:
\frac{\log x}{\log x} + \int_2^x \frac{\log t}{t\,\log^2 t}\,dt = 1 + \int_2^x \frac{dt}{t\,\log t} = 1 + \log\log x - \log\log 2.
The remaining R-terms, \dfrac{R(x)}{\log x} + \displaystyle\int_2^x \dfrac{R(t)}{t\log^2 t}\,dt,
converge as x\to\infty (the first goes to 0;
the integral converges because R is bounded and
\int^\infty \frac{dt}{t\log^2 t} < \infty). Sweeping every constant into a
single number M leaves
\sum_{p \le x}\frac{1}{p} = \log\log x + M + o(1).
A short computation identifies the constant exactly:
M = \gamma + \sum_p\left[\log\!\left(1 - \frac1p\right) + \frac1p\right] = 0.26149\,72128\ldots
That \gamma hiding inside M is precisely what
surfaces, undisguised, in the third theorem.
The third theorem: where does e^{\gamma} come from?
Take the product \prod_{p\le x}(1-1/p)^{-1} and hit it with a logarithm,
using the series -\log(1-u) = u + \tfrac{u^2}{2} + \tfrac{u^3}{3} + \cdots:
\log\prod_{p \le x}\left(1-\frac1p\right)^{-1} = -\sum_{p \le x}\log\!\left(1 - \frac1p\right) = \sum_{p \le x}\frac1p + \sum_{p \le x}\sum_{k \ge 2}\frac{1}{k\,p^{k}}.
The first sum is Mertens' second theorem, \log\log x + M + o(1). The double
sum converges to a constant as x\to\infty — call its limit
C = \sum_p\sum_{k\ge2}\frac{1}{k p^k}. Adding them:
-\sum_{p \le x}\log\!\left(1-\frac1p\right) = \log\log x + (M + C) + o(1).
Now the magic of the constant. Because -\log(1-\frac1p) = \frac1p + \sum_{k\ge2}\frac{1}{kp^k},
the bracket in M is exactly -\big[\log(1-\frac1p)+\frac1p\big]'s
partner, and one finds M + C = \gamma — the prime-power corrections in
C are precisely what turn M back into
\gamma. Hence
-\sum_{p \le x}\log\!\left(1-\frac1p\right) = \log\log x + \gamma + o(1),
and exponentiating both sides,
\prod_{p \le x}\left(1-\frac1p\right)^{-1} = e^{\gamma + o(1)}\cdot \log x \sim e^{\gamma}\log x.
The e^{\gamma} is not decoration — it is the fingerprint of Euler's
constant, the same \gamma that measures the gap between the harmonic sum and
\log n. It is a beautiful shock that the "probability" a random integer near
x survives sieving by all primes up to x,
\prod_{p\le x}(1-1/p) \sim e^{-\gamma}/\log x, is not the naive
1/\log x — it is smaller by the factor e^{-\gamma}\approx 0.561.
The correction factor e^{-\gamma} \approx 0.5615 is not a curiosity; it is a
famous trap. If you sieve the integers below x by every prime up to
\sqrt{x}, you might guess the survivors — the primes between
\sqrt{x} and x — have density
\prod_{p\le\sqrt x}(1-1/p) \sim e^{-\gamma}/\log\sqrt x = 2e^{-\gamma}/\log x.
That is about 2e^{-\gamma}\approx 1.12 times the true density
1/\log x. The mismatch — heuristic sieving overcounts by exactly the Mertens
factor — is the subtlety that makes sieve theory hard, and it is why the naive
inclusion–exclusion estimate for primes is wrong by a constant. Mertens' third theorem is the precise
statement of that constant.
Seeing the crawl
The staircase below is the true partial sum \sum_{p\le x}1/p: it jumps up by
1/p at each prime and is flat between primes. The smooth curve is Mertens'
prediction \log\log x + M. The staircase hugs the curve almost immediately,
and note the vertical scale: from x=10 all the way out to
x=1000 the sum climbs only from about 1.2 to
2.2. That flattening is \log\log x — the
graph of divergence in slow motion.
The gap between staircase and curve is the o(1) error term, and you can
watch it shrink toward zero as x grows — Mertens' second theorem made visible.
Worked example: \sum_{p \le 100} 1/p
There are 25 primes up to 100. Adding their
reciprocals:
\frac12+\frac13+\frac15+\frac17+\frac1{11}+\cdots+\frac1{89}+\frac1{97} = 1.80280\ldots
Now Mertens' prediction. We have \log 100 = 4.60517, so
\log\log 100 = \log(4.60517) = 1.52718, and adding the constant
M = 0.26150:
\log\log 100 + M = 1.52718 + 0.26150 = 1.78868.
The two agree to within 0.014 — the leftover o(1)
term — already at the modest cutoff x = 100. Push the cutoff higher and the
agreement tightens relentlessly. Run it yourself and watch the gap close:
const M = 0.2614972128;
function isPrime(n: number): boolean {
if (n < 2) return false;
for (let d = 2; d * d <= n; d++) if (n % d === 0) return false;
return true;
}
function primeReciprocalSum(x: number): number {
let s = 0;
for (let p = 2; p <= x; p++) if (isPrime(p)) s += 1 / p;
return s;
}
for (const x of [100, 1000, 10000, 100000]) {
const actual = primeReciprocalSum(x);
const predicted = Math.log(Math.log(x)) + M;
console.log(
"x=" + x,
" actual=" + actual.toFixed(5),
" loglog+M=" + predicted.toFixed(5),
" gap=" + (actual - predicted).toFixed(5),
);
}
Two classic misreadings of Mertens' theorems.
The divergence is \log\log x-slow, not \log x-slow.
It is tempting to remember "the sum of prime reciprocals diverges" and mentally file it next to the
harmonic series \sum 1/n \sim \log x. But \sum_{p\le x}1/p \sim \log\log x
is vastly slower — the double log is the whole point. To reach a sum of just
3 you need primes up to about x \approx 10^{7.6};
to reach 4, past 10^{18}. This function grows so
gently it is essentially a constant on any range you could compute by hand.
The third theorem has e^{\gamma}, not 1.
Since \prod_{p\le x}(1-\frac1p)^{-1} and \log x
both diverge, a hasty guess is \prod(1-1/p)^{-1} \sim \log x. Wrong by the
factor e^{\gamma} \approx 1.781. The prime-power corrections buried in
-\log(1-1/p) = \frac1p + \frac{1}{2p^2} + \cdots accumulate to exactly the
Euler constant — drop them and you lose the e^{\gamma}. Never assume the
constant is 1.
Yes — and that is exactly what makes these theorems so admired. The Prime Number Theorem
(\pi(x) \sim x/\log x) was not proved until 1896, over twenty years after
Mertens' 1874 paper. Mertens never needed the full strength of PNT; he needed only Chebyshev's cruder
bound \psi(x) = O(x) (from the 1850s) plus Stirling's formula. In fact the
logic runs the "wrong" way to what you might expect: Mertens' first theorem,
\sum_{p\le x}\frac{\log p}{p} = \log x + O(1), is a genuine consequence
of PNT — but it can be proved without it, and is strictly weaker. If you had a version with
o(1) in place of O(1), that would be equivalent to
PNT. The O(1)-versus-o(1) distinction is the exact
boundary between "elementary and provable by Mertens" and "as hard as the Prime Number Theorem."
Why it all matters
Mertens' theorems are the quantitative heart of "the primes are infinite, but only just." Euler had
shown \sum 1/p = \infty; Mertens told us the rate, to the last
constant. They are the everyday tools of the trade: the second theorem is what you reach for whenever a
sum over primes needs estimating, and the third is the exact normalisation behind sieve methods,
\zeta(s) near s=1, and heuristics for prime
constellations. Every time an e^{\gamma} or a \log\log
appears in analytic number theory, Mertens is usually standing quietly behind it.