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
The function counts the number of primes less than or equal to . For example, (the primes are 2, 3, 5, 7).
Interactive Lab
def count_primes(x):
# Sieve of Eratosthenes to count
primes = [True] * (x + 1)
for p in range(2, int(x**0.5) + 1):
if primes[p]:
for i in range(p * p, x + 1, p):
primes[i] = False
return sum(primes[2:])
print(f"pi(100) = {count_primes(100)}")
print(f"pi(1000) = {count_primes(1000)}")
python
1def count_primes(x):
2# Sieve of Eratosthenes to count
3 primes =[True]*(x +1)
4for p inrange(2, int(x**0.5)+1):
5if primes[p]:
6for i inrange(p * p, x +1, p):
7 primes[i]= False
8returnsum(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:
This means that the density of primes near is approximately .
Interactive Lab
import numpy as np
import matplotlib.pyplot as plt
def pi_approx(x): return x / np.log(x)
x_vals = np.linspace(10, 1000, 100)
y_pnt = pi_approx(x_vals)
plt.plot(x_vals, y_pnt, label='x / ln x', linestyle='--')
plt.title("The Density of Primes (Asymptotic)")
plt.xlabel("x")
plt.ylabel("pi(x)")
plt.legend()
plt.show()
The distribution of primes is perfectly encoded in the Riemann Zeta Function:
This link, discovered by Euler and expanded by Riemann, connects prime numbers (arithmetic) to complex analysis (calculus over complex numbers).
Knowledge Check
If the density of primes is 1/ln x, are primes more frequent as x increases?
Answer: No, because ln x increases, so 1/ln x decreases.
As x increases, the 'gaps' between primes generally grow larger.
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 and . The conjecture states that there are infinitely many such pairs.
Interactive Lab
def get_twin_primes(limit):
primes = [True] * (limit + 1)
for p in range(2, int(limit**0.5) + 1):
if primes[p]:
for i in range(p * p, limit + 1, p):
primes[i] = False
prime_list = [p for p in range(2, limit + 1) if primes[p]]
twins = []
for i in range(len(prime_list) - 1):
if prime_list[i+1] - prime_list[i] == 2:
twins.append((prime_list[i], prime_list[i+1]))
return twins
print(f"Twin primes up to 200: {get_twin_primes(200)}")
python
1def get_twin_primes(limit):
2 primes =[True]*(limit +1)
3for p inrange(2, int(limit**0.5)+1):
4if primes[p]:
5for i inrange(p * p, limit +1, p):
6 primes[i]= False
7
8 prime_list =[p for p inrange(2, limit +1)if primes[p]]
9 twins =[]
10for i inrange(len(prime_list)-1):
11if prime_list[i+1]- prime_list[i]==2:
12 twins.append((prime_list[i], prime_list[i+1]))
13return twins
14
15print(f"Twin primes up to 200: {get_twin_primes(200)}")
5. Summary Check
Knowledge Check
What is the non-trivial zeros hypothesis of the Riemann Zeta Function called?
Answer: Riemann Hypothesis
What is the non-trivial zeros hypothesis of the Riemann Zeta Function called?