The Orthogonal Stream Prime Generator — executable reference for algorithm.md

Every section below is a live implementation of a numbered claim in the specification: the wheel tables (§4.2), the ownership theorem (§2.1) and its multiplier wheel (§2.2–2.4), Algorithm A — exact one-touch orthogonal streams (§3), Algorithm B — wheeled streaming generator with O(1) state per prime (§4), the bucket-queue segmented layout (§5.1), a machine-checkable validation suite, and an empirical measurement of S(N) with a log–log fit of θ (§3.7, §9.1). Nothing is loaded from the network.

1 · Wheel tables §4.2 — spokes, step[], gte[]

next_coprime(x) = x + step[x mod W] (strictly greater), next_coprime_ge(x) = x + gte[x mod W]. Both tables are built in one backward pass over [0,W). κW = φ(W)/W is the candidate density.

2 · Ownership explorer Thm 2.1, Cor 2.2, Lem 2.3, Cor 2.4, Prop 2.6

Θp = p·Ap with Ap = { a ≥ p : gcd(a, P<p) = 1 } — the p-rough numbers, a wheel, not a list of primes. Below p² every multiplier is prime (Lemma 2.3); the first composite multiplier is exactly p². Try p = 11 for the observation.md counterexample 121 ∈ A11.

3 · Algorithm A — exact one-touch orthogonal generator §3

Stream tree Σb = { b·q : q prime, q ≥ P(b) } (Thm 3.1) with lazy child creation via EMIT/SPAWN cursors (§3.2). No marking array, no divisibility, no √ — one multiply and one compare per step. The assertion pops == composites is the machine-checkable statement of exact orthogonality (Thm 3.2).

4 · Algorithm B — wheeled streaming generator §4 (recommended)

Exact multiplier set Ap is relaxed to the tabulated Ãp = { a ≥ p : gcd(a,W)=1 }. Advancement is a += step[a % W]; v = p*a — genuinely O(1) time and O(1) state per prime — at the cost of ω>pw(m) touches per composite (§4.5). Measured pops are compared against both the exact factor-count and the κW·N·(lnln√N − lnln pw) estimate.

5 · Engineering layer — bucket queue + segments §5.1, §4.6

Algorithm B with the log factor removed: streams are filed into per-segment buckets, drained into a Δ-byte mark array, and re-filed. Stream state at an arbitrary segment start X is recomputed in O(1) by a0 = max(p, next_coprime_ge(⌈X/p⌉)) — the property that makes B segment-parallel and A not.

6 · Validation suite every numbered claim

Each line is an independent executable check of a theorem, lemma, corollary or correction from the specification.

7 · Measuring S(N) — the real cost of exact orthogonality §3.7, §9.1

S(N) = #{ b ≥ 2 : b·P(b) ≤ N } is the live-stream count of Algorithm A. The heuristic says S(N) = Nθ+o(1), θ ≈ 0.75 — decisively worse than π(√N). Measure, then fit; do not trust the exponent.