primelab — patterns in the primes (started 2026-10-31)
Exploring the "lines when you fold the primes onto a plane": the polar prime spiral and the Ulam spiral. Goal: reproduce the patterns, QUANTIFY where the lines come from, and SEARCH other foldings.
Tools (pure numpy + a tiny stdlib PNG writer, no matplotlib)
- plib.py : sieve + write_png + point splat.
- polar.py : polar spiral (theta=n, r=n), renders out_polar*.png.
- rays.py : WHY the rays exist — ray count = phi(numerator of a continued-fraction convergent of 2*pi).
- foldsearch.py: scans the angle-per-step alpha; measures anisotropy (line strength).
- ulam.py : Ulam square spiral (out_ulam.png) + search for prime-dense quadratics.
- compare.py : out_sunflower.png (golden angle, no lines), out_spiral.png (classic), out_twolines.png (pi).
Findings (all reproducible, all explained)
- Polar spiral rays = residue classes. With theta=n rad, a ray is a residue class mod m where m1 ~ 2pi*k,
i.e. m = numerator of a convergent of 2*pi: 6, 44, 710, ... The number of PRIME rays = phi(m):
phi(6)=2 arms, phi(44)=20 rays, phi(710)=280 rays. (Measured: prime residues mod 44 = 20+2, mod 710 = 280+3;
the +few are the small primes dividing m.) phi(m) is the prime fingerprint: any set gives m rays, primes give phi(m).
- Folding search: rational alpha=2pip/q -> q fixed lines (strongest); alpha=pi -> exactly 2 lines (max concentration);
noble/irrational alpha (golden angle) -> sunflower, NO lines. The classic alpha=1 rad is irrational -> the
44/710 rays are a joint radius-angle effect, not a single angular bin.
- Ulam spiral diagonals = quadratics. Search over n^2+n+c reproduces Euler's lucky number 41:
n^2+n+41 is prime for n=0..39 (40 in a row, the unique champion) and is prime for 581/1000 of n=0..999 (58%).
Honest note
These are gorgeous but fully understood: Dirichlet (primes equidistribute over residues coprime to m) + Diophantine approximation (which m line up with 2*pi) explain everything. The value here is a clean, quantified, reproducible exploration + a polynomial-density search harness. Open thread: 3D ("room") embeddings and whether any folding reveals structure NOT reducible to residue classes (none found so far).
Primes × fractals (2026-10-31, combine)
- cgr.py: CHAOS GAME (an IFS fractal) on the sequence of prime LAST DIGITS (1,3,7,9 -> square corners).
A random sequence fills the square uniformly; the primes leave fractal VOIDS. This reveals the
Oliver-Soundararajan bias (2016): from 1.27M primes, P(a prime repeats the previous one's last digit)
= 0.166, not 0.25. Full transition matrix printed (e.g. after 9 the next is 1 far more often than 9).
out_cgr_primes.png (structured) vs out_cgr_random.png (uniform control).
- gauss.py: GAUSSIAN PRIMES a+bi in the complex plane (a^2+b^2 prime, or axis p=4k+3). 153k points in
[-600,600]^2, box-counting dimension ~1.85 (< 2 => fractal-like gaps at finite scale). out_gaussprimes.png.
Takeaway: fractal lenses (IFS/chaos game, box dimension) are good DETECTORS of hidden arithmetic structure — the chaos game turned a modern research result into a picture. Still all residue-class / equidistribution phenomena underneath; no new theorem, but a sharp, reproducible combined toolkit.
Bilder








