Skip to main content

Module primes

Module primes 

Source
Expand description

Prime number distribution, sieves, and rendering utilities.

Structs§

PrimeDistributionRenderer
Maps primes to glyph positions, sizes, and colors for engine rendering.
PrimeGlyph
A renderable glyph descriptor for a prime.
SacksSpiral
Sacks spiral: polar plot where integer n is at angle sqrt(n) * 2*pi, radius sqrt(n).
UlamSpiral
Ulam spiral: maps positive integers to a 2D grid position via a spiral walk, highlighting prime positions.

Functions§

is_prime
Primality test. Uses trial division for small n, Miller-Rabin for large n.
nth_prime
Returns the n-th prime (1-indexed: nth_prime(1) == 2).
prime_counting
Prime counting function pi(x): number of primes <= x.
prime_factorization
Prime factorization of n, returned as sorted (prime, exponent) pairs.
prime_gaps
Gaps between consecutive primes up to limit.
sieve_of_eratosthenes
Classic sieve of Eratosthenes returning all primes up to limit.
twin_primes
Twin prime pairs (p, p+2) up to limit.