Search Knowledge

© 2026 LIBREUNI PROJECT

Prime Number Distribution

Prime Number Distribution

Primes are scattered along the number line in a way that appears random at small scales, but follows strict mathematical laws at large scales.

1. The Prime Counting Function π(x)\pi(x)

The function π(x)\pi(x) counts the number of primes less than or equal to xx. For example, π(10)=4\pi(10) = 4 (the primes are 2, 3, 5, 7).

python
1def count_primes(x):
2 # Sieve of Eratosthenes to count
3 primes = [True] * (x + 1)
4 for p in range(2, int(x**0.5) + 1):
5 if primes[p]:
6 for i in range(p * p, x + 1, p):
7 primes[i] = False
8 return sum(primes[2:])
9 
10print(f"pi(100) = {count_primes(100)}")
11print(f"pi(1000) = {count_primes(1000)}")

2. The Prime Number Theorem (PNT)

The PNT describes the asymptotic distribution of primes. It states that: π(x)xlnx\pi(x) \sim \frac{x}{\ln x} This means that the density of primes near xx is approximately 1/lnx1/\ln x.

python
1import numpy as np
2import matplotlib.pyplot as plt
3 
4def pi_approx(x): return x / np.log(x)
5 
6x_vals = np.linspace(10, 1000, 100)
7y_pnt = pi_approx(x_vals)
8 
9plt.plot(x_vals, y_pnt, label='x / ln x', linestyle='--')
10plt.title("The Density of Primes (Asymptotic)")
11plt.xlabel("x")
12plt.ylabel("pi(x)")
13plt.legend()
14plt.show()

3. The Riemann Zeta Function

The distribution of primes is perfectly encoded in the Riemann Zeta Function: ζ(s)=n=11ns=pPrimes11ps\zeta(s) = \sum_{n=1}^\infty \frac{1}{n^s} = \prod_{p \in \text{Primes}} \frac{1}{1 - p^{-s}}

This link, discovered by Euler and expanded by Riemann, connects prime numbers (arithmetic) to complex analysis (calculus over complex numbers).

If the density of primes is 1/ln x, are primes more frequent as x increases?

4. The Twin Prime Conjecture

Twin primes are pairs of primes that differ by 2, such as (3,5)(3, 5) and (11,13)(11, 13). The conjecture states that there are infinitely many such pairs.

python
1def get_twin_primes(limit):
2 primes = [True] * (limit + 1)
3 for p in range(2, int(limit**0.5) + 1):
4 if primes[p]:
5 for i in range(p * p, limit + 1, p):
6 primes[i] = False
7
8 prime_list = [p for p in range(2, limit + 1) if primes[p]]
9 twins = []
10 for i in range(len(prime_list) - 1):
11 if prime_list[i+1] - prime_list[i] == 2:
12 twins.append((prime_list[i], prime_list[i+1]))
13 return twins
14 
15print(f"Twin primes up to 200: {get_twin_primes(200)}")

5. Summary Check

What is the non-trivial zeros hypothesis of the Riemann Zeta Function called?

Previous Module Predicate Logic