#!/usr/bin/env node // ============================================================================ // JOB #630, probe 2 -- is the SQUARE-ANCHORED desert window special? // // The desert D_p = (p^2, p'^2) is onset-free (zonegap-02-reduction.md section 4 // D1/D2), and inside it slot <=> prime (Lemma A), so the whole tail question is // "does the p#-sieve leave a slot in the interval (p^2, p'^2)". That window is a // length-L window of the cyclic tile word T_p at offset p^2 + 1, L = p'^2-p^2-3. // Unlike the zone window its offset is a PRIME SQUARE, so its residue mod every // q <= p is a nonzero square -- an anchor coupled to the modulus in a way no // uniform covering theorem uses. // // Route probe: if the square anchor were RICH, a covering/anti-covering argument // there would have a mechanism. This script prices that premise exactly: it // compares each desert window's exact slot count with the EXACT translate- // ensemble mean and sd for the same length (the closed form of zonetranslate.mjs, // validated there against full enumeration), and reports the z-score. // // c_q(d) tables are precomputed once per q (they do not depend on p). // ============================================================================ const PLIM = 500; function sieve(n){const c=new Uint8Array(n+1),pr=[];for(let i=2;i<=n;i++){if(!c[i]){pr.push(i);for(let j=i*i;j<=n;j+=i)c[j]=1;}}return pr;} const PR = sieve(3000); const SQMAX = 260000; // 503^2 + 1: covers every desert for p <= PLIM const IP = new Uint8Array(SQMAX + 1); for (const q of sieve(SQMAX)) IP[q] = 1; // sieve() returns the prime list const isP = (n) => (n >= 2 && n <= SQMAX && IP[n] === 1); const nextP = (p) => { let q = p + 1; while (!isP(q)) q++; return q; }; const primorial = (p) => { let W = 1n; for (const q of PR) { if (q > p) break; W *= BigInt(q); } return W; }; const Aof = (p) => { let A = 1n; for (const q of PR) { if (q > p) break; if (q >= 3) A *= BigInt(q - 2); } return A; }; // c_q(d) = #{r mod q : r, r+2, r+d, r+d+2 all nonzero mod q}, precomputed once. const CQ = new Map(); for (const q of PR) { if (q > PLIM) break; const t = new Uint16Array(q); for (let d = 0; d < q; d++) { let c = 0; for (let r = 0; r < q; r++) { if (r % q && (r + 2) % q && (r + d) % q && (r + d + 2) % q) c++; } t[d] = c; } CQ.set(q, t); } // mean/sd of the count in ANY window of length L of T_p, from the precomputed tables function muSigL(p, L) { // density = prod_{q<=p} a_q/q in LOG space: Number(p#) overflows past p ~ 700 let logd = 0; for (const q of PR) { if (q > p) break; const a = q === 2 ? 1 : q - 2; logd += Math.log(a / q); } const density = Math.exp(logd); const mu = L * density; const T = [...CQ.entries()].filter(([q]) => q <= p); let S = 0; for (let d = -(L - 1); d <= L - 1; d += 2) { let G = 1; for (const [q, t] of T) { const c = t[((d % q) + q) % q]; if (c === 0) { G = 0; break; } const a = q === 2 ? 1 : q - 2; G *= c * q / (a * a); } S += (L - Math.abs(d)) * G; } const varr = Math.exp(2 * logd) * (S - L * L); return { mu, sd: varr > 0 ? Math.sqrt(varr) : 0, var: varr }; } const rows = []; for (const p of PR) { if (p > PLIM || p < 3) continue; const pp = nextP(p), lo = p * p, hi = pp * pp, L = hi - lo - 3; let C = 0, Cp = 0; for (let n = lo + 1; n + 2 < hi; n++) { let ok = true; for (const q of PR) { if (q > p) break; if (n % q === 0 || (n + 2) % q === 0) { ok = false; break; } } if (ok) C++; if (isP(n) && isP(n + 2)) Cp++; } const m = muSigL(p, L); rows.push({ p, pp, L, C, Cp, match: C === Cp, z: m.sd > 0 ? (C - m.mu) / m.sd : 0, mu: m.mu, sd: m.sd, ratio: C / m.mu }); } console.log('JOB #630 probe 2 -- the square-anchored desert window vs the exact translate ensemble'); console.log(' p L C C_prime mu sd z C/mu'); for (const r of rows) { if (r.p < 20 || r.p % 41 === 0 || r.p === 499) console.log(` ${String(r.p).padStart(4)} ${String(r.L).padStart(7)} ${String(r.C).padStart(7)} ${String(r.Cp).padStart(7)} ${r.mu.toFixed(2).padStart(8)} ${r.sd.toFixed(3).padStart(7)} ${r.z.toFixed(3).padStart(8)} ${r.ratio.toFixed(4)}`); } const zs = rows.map((r) => r.z), pos = rows.filter((r) => r.z >= 0).length, N = rows.length; let binom = 0; for (let k = pos; k <= N; k++) { let c = 1; for (let i = 1; i <= k; i++) c = c * (N - i + 1) / i; binom += c; } binom /= Math.pow(2, N); const mism = rows.filter((r) => !r.match).length; console.log(''); console.log('SUMMARY'); console.log(` levels ${N}; slot-count == prime-pair-count: ${mism === 0 ? 'YES (' + N + '/' + N + ')' : 'NO (' + mism + ' mismatches)'}`); console.log(` z >= 0 at ${pos}/${N} (${(100 * pos / N).toFixed(1)}%), one-sided binomial tail ${binom.toExponential(3)}`); console.log(` min z ${Math.min(...zs).toFixed(3)} max z ${Math.max(...zs).toFixed(3)} mean z ${(zs.reduce((a, b) => a + b, 0) / N).toFixed(3)}`); console.log(` C/mu in [${Math.min(...rows.map((r) => r.ratio)).toFixed(4)}, ${Math.max(...rows.map((r) => r.ratio)).toFixed(4)}]`); console.log(` min C over all levels ${Math.min(...rows.map((r) => r.C))}; C == 0 at ${rows.filter((r) => r.C === 0).length} levels`); const big = rows.filter((r) => r.p >= 101); console.log(` p >= 101: n=${big.length} mean z ${(big.reduce((a, r) => a + r.z, 0) / big.length).toFixed(3)}, z>=0 ${big.filter(r => r.z >= 0).length}`);