// Job 2844 (route 142 triage): does the sub-Poisson consecutive-twin-gap dispersion of #1456 survive // a density-matched control, and how much of it is the Hardy-Littlewood small-prime (singular-series) // structure? Pre-registered before running (see prereg.md): // Controls C_z: candidates n = 6k-1 <= X with no prime factor p <= z dividing n or n+2 (p >= 5), // each kept independently with probability q = (data count)/(candidate count) on 400 fine log-bins // (non-parametric density match). z = 3 is the lattice-6 Cramer control the route proposed. // Data = the same sieve with z = sqrt(X), q = 1 (then n, n+2 are both prime for n > sqrt X). // Statistic per coarse bin (10 equal bins of ln n on [ln 1e4, ln X]): CV2 = Var(d)/mean(d)^2 of // consecutive gaps (left point in bin), and #1456's S_disp = Var(u)/mean(u), u = d/ln n. // usage: node zctl.mjs X z1,z2,... reps seed > out.json const X = Number(process.argv[2] || 1e9); const zs = (process.argv[3] || '3,13').split(',').map(Number); const REPS = Number(process.argv[4] || 2); const SEED = Number(process.argv[5] || 20260923); const KMAX = Math.floor((X - 1) / 6); // n = 6k-1 <= X-2 so that n+2 <= X ... checked below const LO = Math.log(1e4), HI = Math.log(X), NB = 10, NF = 400; const primesUpTo = (m) => { const s = new Uint8Array(m + 1); const p = []; for (let i = 2; i <= m; i++) if (!s[i]) { p.push(i); for (let j = i * i; j <= m; j += i) s[j] = 1; } return p; }; const SQ = Math.floor(Math.sqrt(X)) + 1; const PR = primesUpTo(Math.max(SQ, 2000)).filter((p) => p >= 5); const inv6 = (p) => { for (let a = 1; a < p; a++) if ((6 * a) % p === 1) return a; }; const INV = new Map(PR.map((p) => [p, inv6(p)])); const SEG = 1 << 21; // iterate candidates k (n=6k-1) in [1, KMAX] with no p in (5..z) dividing n or n+2 (except n or n+2 == p) function* candidates(z) { const ps = PR.filter((p) => p <= z); const seg = new Uint8Array(SEG); for (let k0 = 1; k0 <= KMAX; k0 += SEG) { const len = Math.min(SEG, KMAX - k0 + 1); seg.fill(0, 0, len); for (const p of ps) { const iv = INV.get(p); // 6k-1 = 0 mod p <=> k = inv6 mod p ; 6k+1 = 0 mod p <=> k = -inv6 mod p for (const r of [iv % p, (p - iv) % p]) { let k = k0 + ((r - k0) % p + p) % p; for (; k < k0 + len; k += p) { const n = 6 * k - 1; if (n !== p && n + 2 !== p) seg[k - k0] = 1; } } } for (let i = 0; i < len; i++) if (!seg[i]) { const n = 6 * (k0 + i) - 1; if (n + 2 <= X) yield n; } } } const fine = (n) => Math.floor((Math.log(n) - LO) / (HI - LO) * NF); const coarse = (n) => Math.floor((Math.log(n) - LO) / (HI - LO) * NB); let rng = SEED >>> 0; const rand = () => { rng ^= rng << 13; rng >>>= 0; rng ^= rng >>> 17; rng ^= rng << 5; rng >>>= 0; return rng / 4294967296; }; function stats(stream, keep) { const A = Array.from({ length: NB }, () => ({ m: 0, sd: 0, sd2: 0, su: 0, su2: 0 })); let prev = -1, count = 0; for (const n of stream) { if (keep && !keep(n)) continue; count++; if (prev > 0 && n >= 1e4) { const b = coarse(prev); if (b >= 0 && b < NB) { const d = n - prev, u = d / Math.log(prev), a = A[b]; a.m++; a.sd += d; a.sd2 += d * d; a.su += u; a.su2 += u * u; } } prev = n; } return { count, bins: A.map((a) => { const md = a.sd / a.m, vd = a.sd2 / a.m - md * md, mu = a.su / a.m, vu = a.su2 / a.m - mu * mu; return { m: a.m, mean_d: md, cv2: vd / (md * md), s_disp: vu / mu }; }) }; } const t0 = Date.now(); // data const dataFine = new Float64Array(NF + 1); const data = stats((function* () { for (const n of candidates(SQ)) { const f = fine(n); if (f >= 0 && f <= NF) dataFine[Math.min(f, NF)]++; yield n; } })()); const out = { X, seed: SEED, reps: REPS, pi2_check: data.count + 1 /* (3,5) is not of the form 6k-1 */, data: data.bins, controls: {}, secs: {} }; out.secs.data = (Date.now() - t0) / 1000; for (const z of zs) { const t1 = Date.now(); const candFine = new Float64Array(NF + 1); for (const n of candidates(z)) { const f = fine(n); if (f >= 0) candFine[Math.min(f, NF)]++; } const q = candFine.map((c, i) => (c ? dataFine[i] / c : 0)); if (Math.max(...q) > 1) throw new Error(`q>1 at z=${z}`); out.controls[z] = []; for (let r = 0; r < REPS; r++) { const s = stats(candidates(z), (n) => { const f = fine(n); return f < 0 ? true : rand() < q[Math.min(f, NF)]; }); out.controls[z].push(s.bins); } out.secs['z' + z] = (Date.now() - t1) / 1000; } console.log(JSON.stringify(out));