Prime Counting Function π(n)
Statement
The prime counting function counts the number of primes up to :
The Prime Number Theorem (Hadamard and de la Vallée-Poussin, 1896) gives the asymptotic:
meaning . Equivalently, where is the logarithmic integral.
Mathlib defines Nat.primeCounting n as the number of primes , with notation (scoped to Nat.Prime).
Visualization
Exact values of and comparison with the approximation :
| 10 | 4 | 4 | 0 |
| 50 | 15 | 11 | 4 |
| 100 | 25 | 21 | 4 |
| 500 | 95 | 80 | 15 |
| 1000 | 168 | 144 | 24 |
| 5000 | 669 | 591 | 78 |
| 10000 | 1229 | 1085 | 144 |
The logarithmic integral is a better approximation (within assuming the Riemann Hypothesis):
| (approx) | error | ||
|---|---|---|---|
| 1000 | 168 | 178 | |
| 10000 | 1229 | 1246 | |
| 100000 | 9592 | 9630 |
Note for all computed values, though Skewes showed the inequality reverses for some astronomically large .
Proof Sketch
- Elementary lower bound. By Bertrand's PostulateBertrand's PostulateFor every positive integer n there is always a prime p with n < p ≤ 2nRead more →, , giving .
- Chebyshev bounds. for large (see Chebyshev's Bounds for π(n)Chebyshev's Bounds for π(n)The prime counting function satisfies c₁·n/ln(n) ≤ π(n) ≤ c₂·n/ln(n) for explicit constantsRead more →).
- Prime Number Theorem. The full asymptotics use complex analysis: on (zero-free region) implies .
- Equivalent forms. (von Mangoldt function) (Chebyshev ).
Connections
is the primary object of study in analytic number theory, shaped by Chebyshev's Bounds for π(n)Chebyshev's Bounds for π(n)The prime counting function satisfies c₁·n/ln(n) ≤ π(n) ≤ c₂·n/ln(n) for explicit constantsRead more → and Mertens' TheoremsMertens' TheoremsThe sum of reciprocals of primes diverges, with precise logarithmic asymptoticsRead more →. The Infinitude of PrimesInfinitude of PrimesEuclid's classic proof that there are infinitely many prime numbersRead more → shows ; the Prime Number Theorem quantifies the rate. The Multiplicative FunctionsMultiplicative FunctionsArithmetic functions that split over coprime inputs: f(mn) = f(m)f(n) when gcd(m,n) = 1Read more → Dirichlet series generating function is , linking to the Riemann zeta function.
Lean4 Proof
import Mathlib.NumberTheory.PrimeCounting
import Mathlib.Data.Nat.Prime.Basic
/-- π(10) = 4: there are exactly 4 primes ≤ 10 (namely 2, 3, 5, 7). -/
theorem pi_10 : Nat.primeCounting 10 = 4 := by decide
/-- π is monotone: if m ≤ n then π(m) ≤ π(n). -/
theorem pi_monotone : Monotone Nat.primeCounting :=
Nat.monotone_primeCounting
/-- π(n) is unbounded: Nat.tendsto_primeCounting' shows it diverges to infinity. -/
theorem pi_tendsto : Filter.Tendsto Nat.primeCounting' Filter.atTop Filter.atTop :=
Nat.tendsto_primeCounting'Referenced by
- Bertrand's PostulateNumber Theory
- Chebyshev's Bounds for π(n)Number Theory