How it Works
This simulator generates all primes up to N using the Sieve of Eratosthenes, then visualizes their distribution in four different ways. Each view reveals different properties of the prime numbers.
The Ulam Spiral (1963) arranges integers on a square spiral, coloring primes. Diagonal patterns emerge because many prime-rich polynomials (like 4n²-2n+1) lie along these diagonals. The Gap Histogram shows the distribution of distances between consecutive primes. The PNT view plots π(x) vs. x/ln(x) to demonstrate the Prime Number Theorem approximation.
PNT: π(n) ~ n/ln(n) (Hadamard & de la Vallée Poussin, 1896)
Gap: g(p) = next_prime(p) - p, avg g ≈ ln(p)
Bertrand: ∀ n>1, ∃ prime p : n < p ≤ 2n
The Sieve of Eratosthenes runs in O(N log log N) time and O(N) space — efficient enough to find all primes up to 50,000 in milliseconds. After sieving, gap statistics, twin prime counts, and the PNT approximation ratio are computed.
Frequently Asked Questions
What is the Ulam spiral?
The Ulam spiral (1963) places integers on a square spiral starting from the center, then highlights primes. Primes tend to cluster along diagonal lines, suggesting arithmetic progressions contain unusually many primes. This pattern remains partially unexplained.
What is the Prime Number Theorem?
The Prime Number Theorem states that π(n) ~ n/ln(n) as n→∞. Equivalently, the average gap between consecutive primes near n is approximately ln(n). Proved independently by Hadamard and de la Vallée Poussin in 1896.
What are twin primes?
Twin primes are pairs of primes differing by 2: (3,5), (11,13), (17,19), (29,31)... The Twin Prime Conjecture states there are infinitely many such pairs, but it remains unproven. Yitang Zhang proved in 2013 there are infinitely many prime pairs differing by at most 70 million.
What is Bertrand's postulate?
Bertrand's postulate (proved by Chebyshev 1852): for every n > 1, there exists at least one prime p with n < p ≤ 2n. This means prime gaps can never be larger than the primes themselves in a relative sense.
What is the Riemann Hypothesis connection to primes?
The Riemann Hypothesis conjectures that all non-trivial zeros of ζ(s) lie on Re(s) = 1/2. If true, it gives the best possible error bound: |π(x) - Li(x)| ≤ C·√x·ln(x), where Li(x) is the logarithmic integral.
What is the Sieve of Eratosthenes?
The Sieve of Eratosthenes finds all primes up to n: start with all integers 2…n; repeatedly mark multiples of each prime as composite. Primes are the survivors. Time complexity is O(n log log n). Used here to generate the prime list.
What is the prime gap distribution?
The gap between consecutive primes p and q is q-p. Cramér's conjecture predicts the maximal gap near n is approximately (ln n)². The distribution of normalized gaps g/ln(p) follows an exponential distribution, consistent with primes behaving like a Poisson process.
What is Dirichlet's theorem on primes in arithmetic progressions?
For coprime integers a and d, the arithmetic progression a, a+d, a+2d, … contains infinitely many primes, distributed roughly equally among the φ(d) valid residue classes mod d. This explains diagonal patterns in the Ulam spiral.
What is the Green-Tao theorem?
The Green-Tao theorem (2004) proves that the primes contain arithmetic progressions of arbitrary length — for any k, there exist k primes a, a+d, …, a+(k-1)d. Uses techniques from ergodic theory.
How dense are the primes?
The density of primes near n is approximately 1/ln(n) by the PNT. A random integer near n is prime with probability ~1/ln(n). Density decreases as n grows, but there are always infinitely many primes (Euclid, ~300 BCE).