Prime Distribution Visualizer: The Prime Number Theorem in Action

simulator intermediate ~10 min
Loading simulation...
π(1000) = 168 — versus N/ln(N) ≈ 145 and Li(1000) ≈ 178

There are exactly 168 primes up to 1000. The estimate N/ln(N) gives 145 (13.7% low) while the logarithmic integral Li(1000) gives 178 (6.0% high), demonstrating Li's superior accuracy.

Formula

π(N) ~ N / ln(N) (Prime Number Theorem)
Li(x) = ∫₂ˣ dt / ln(t) (logarithmic integral)
Average prime gap ≈ ln(pₙ)

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.

FAQ

What is the Prime Number Theorem?

The Prime Number Theorem (PNT) states that the number of primes up to N, denoted π(N), is asymptotically equal to N/ln(N). More precisely, π(N)/[N/ln(N)] → 1 as N → ∞. It was conjectured by Gauss and Legendre around 1800 and proved independently by Hadamard and de la Vallée-Poussin in 1896.

What is the logarithmic integral Li(x)?

Li(x) = ∫₂ˣ dt/ln(t) is a more accurate estimate of π(x) than x/ln(x). Gauss observed empirically that Li(x) closely tracks the prime counting function. The Riemann Hypothesis, if true, would bound the error |π(x) - Li(x)| by O(√x ln x).

What are prime gaps?

A prime gap is the difference between consecutive primes: gₙ = pₙ₊₁ - pₙ. Gaps grow on average like ln(pₙ), but individual gaps fluctuate widely. The largest known prime gaps far exceed ln(p), while twin primes (gap 2) are conjectured to occur infinitely often.

What is the Riemann Hypothesis?

The Riemann Hypothesis conjectures that all non-trivial zeros of the Riemann zeta function have real part 1/2. If true, it would give the sharpest known error bound for the PNT: |π(x) - Li(x)| = O(√x ln x). It is the most famous open problem in mathematics, with a $1 million Millennium Prize.

Sources

Embed

<iframe src="https://homo-deus.com/lab/number-theory/prime-distribution/embed" width="100%" height="400" frameborder="0"></iframe>
View source on GitHub