← Recreational maths

Lab · Probabilistic number theory

Erdős–Kac Lab

How many prime factors does a random number have? Experiments with the Gaussian law of prime factors.

Pick an integer $n$ at random up to $x$ and count its distinct prime factors, $\omega(n)$. The answer is random, but its distribution is not: once centred at $\log\log x$ and scaled by $\sqrt{\log\log x}$, it follows the bell curve. This is the Erdős–Kac theorem, and the lab below lets you watch it happen for $\omega(n)$, for $\Omega(n)$, for values of polynomials, for shifted primes, and for polynomials over finite fields.

Where this comes from: probabilistic number theory

In 1917 Hardy and Ramanujan showed that almost every integer $n$ has about $\log\log n$ prime factors. Their proof was intricate. In 1934 Turán gave a short one by bounding a variance, $$\sum_{n \le x} \big(\omega(n) - \log\log x\big)^2 \ll x \log\log x,$$ which is Chebyshev's inequality in disguise. That proof made it clear that probability was hiding in the problem.

Mark Kac made the probability explicit. Write $\omega(n) = \sum_{p} \mathbf{1}_{p \mid n}$. For a random $n$, the events "$p$ divides $n$" have probability $1/p$ and behave almost independently for different primes. So $\omega(n)$ looks like a sum of independent Bernoulli variables, with $$\text{mean} \approx \sum_{p \le x} \frac1p = \log\log x + O(1), \qquad \text{variance} \approx \sum_{p \le x} \frac1p\Big(1 - \frac1p\Big) \sim \log\log x$$ by Mertens' theorem. The central limit theorem then predicts a Gaussian. Kac saw this heuristic and Erdős supplied the sieve argument to make it rigorous. Their theorem (1940) says that for every real $z$, $$\lim_{x \to \infty} \frac1x \,\#\Big\{ n \le x : \frac{\omega(n) - \log\log x}{\sqrt{\log\log x}} \le z \Big\} = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^{z} e^{-t^2/2}\, dt.$$

Why the pictures look lopsided

The convergence is very slow. Even at $x = 10^{20}$ we have $\log\log x \approx 3.8$, so $\omega(n)$ takes only a handful of values and the histogram is visibly skewed. The error in the normal approximation is of order $1/\sqrt{\log\log x}$ (Rényi and Turán). The "prime model" overlay in the lab, which treats each prime as an independent coin, matches the data far better than the Gaussian at any range you can compute. That gap is a good illustration of what "asymptotically normal" does and does not promise.

Polynomials over finite fields

The same story holds in $\mathbb{F}_q[t]$. For a random monic polynomial of degree $n$, the number of distinct irreducible factors has mean and variance about $\log n$, and is asymptotically normal. Here the degree $n$ plays the role of $\log x$, so $\log n$ replaces $\log\log x$. The lab computes these distributions exactly from the generating function, for degrees in the thousands.

Why I care

My own work on the Chowla conjecture for a truncated Möbius function over $\mathbb{F}_q[t]$ turns a correlation problem into a uniform bivariate Erdős–Kac theorem, proved through characteristic functions. See arXiv:2610.06471.

Further reading

  • M. Kac, Statistical Independence in Probability, Analysis and Number Theory, Carus Mathematical Monographs 12, 1959.
  • P. Erdős and M. Kac, The Gaussian law of errors in the theory of additive number theoretic functions, American Journal of Mathematics 62 (1940).
  • A. Granville and K. Soundararajan, Sieving and the Erdős–Kac theorem, in Equidistribution in Number Theory, an Introduction, Springer, 2007.
  • G. Tenenbaum, Introduction to Analytic and Probabilistic Number Theory, AMS Graduate Studies in Mathematics 163, 2015.