How Primes Thin Out
Prime numbers become less frequent as we count higher, but they never stop appearing. The density of primes near N is approximately 1/ln(N) — about 1 in 7 near 1000, and 1 in 23 near 10 billion. This gradual thinning, quantified by the Prime Number Theorem, is one of the deepest results in mathematics. This simulation plots the prime counting staircase π(x) alongside its asymptotic approximations, letting you see the theorem in action.
The Prime Counting Function
The function π(x) counts the exact number of primes up to x. It forms an irregular staircase — flat between primes and jumping by 1 at each prime. Despite this jaggedness, π(x) follows a remarkably smooth trend on large scales. The simplest approximation, x/ln(x), captures the right growth rate but consistently underestimates. The logarithmic integral Li(x) = ∫₂ˣ dt/ln(t) provides a far more accurate estimate, overshooting slightly for all computed values (though it is known to eventually oscillate).
Gaps Between Primes
The spaces between consecutive primes reveal rich structure. Twin primes (gap 2) like 11,13 and 29,31 appear frequently at first but become rarer, though they are conjectured to continue forever. The average gap near pₙ is approximately ln(pₙ), but actual gaps fluctuate wildly — 'prime deserts' of length roughly ln²(p) appear regularly, and the largest known gaps far exceed the average. This simulation highlights large gaps as red bars on the number line.
The Riemann Connection
The distribution of primes is intimately connected to the zeros of the Riemann zeta function ζ(s). The Prime Number Theorem is equivalent to the statement that ζ(s) has no zeros on the line Re(s) = 1. The Riemann Hypothesis — that all non-trivial zeros have Re(s) = 1/2 — would give the sharpest possible error bound for π(x). After 160 years and trillions of verified zeros, the hypothesis remains unproven, standing as the most important open problem in mathematics.