#!/usr/bin/env node // ============================================================================ // JOB #630, probe 2 validation -- enumerate EVERY translate of the desert-length // window exactly (small p), so the closed-form ensemble mean/sd used by // desertspec.mjs is checked against brute force and the square anchor's exact // position in the distribution is measured rather than modelled. // ============================================================================ const ACAP = 200000000; // bytes of slot array we allow 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 IP = new Uint8Array(4000); for (const q of PR) if (q < 4000) IP[q] = 1; const isP = (n) => n >= 2 && n < 4000 && 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; }; const CQ = new Map(); for (const q of PR) { if (q > 60) 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); } function muSigL(p, L) { let logd = 0; for (const q of PR) { if (q > p) break; logd += Math.log((q === 2 ? 1 : q - 2) / q); } const density = Math.exp(logd), mu = L * density, 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 }; } for (const p of PR) { if (p < 7 || p > 19) continue; const pp = nextP(p), lo = p * p, hi = pp * pp, L = hi - lo - 3, W = Number(primorial(p)); if (W > ACAP) { console.log(` p=${p} skipped (W=${W} > cap)`); continue; } // slot indicator on the cyclic tile word const slot = new Uint8Array(W).fill(1); for (const q of PR) { if (q > p) break; for (let j = 0; j < W; j += q) slot[j] = 0; for (let j = (q - 2) % q; j < W; j += q) slot[j] = 0; } if (L >= W) { console.log(` p=${p} skipped (L=${L} >= W=${W})`); continue; } let sum = 0, sum2 = 0, cur = 0; for (let i = 0; i < L; i++) cur += slot[i]; const hist = new Map(); let anchorCount = null; const anchor = lo % W; // the square anchor p^2 for (let t = 0; t < W; t++) { if (t > 0) cur += slot[(t + L - 1) % W] - slot[t - 1]; sum += cur; sum2 += cur * cur; hist.set(cur, (hist.get(cur) || 0) + 1); if (t === anchor) anchorCount = cur; } const mean = sum / W, varr = sum2 / W - mean * mean, sd = Math.sqrt(varr); let below = 0; for (const [c, k] of hist) if (c < anchorCount) below += k; const pct = 100 * (below + (hist.get(anchorCount) || 0)) / W; const cf = muSigL(p, L); console.log(` p=${String(p).padStart(2)} W=${String(W).padStart(9)} L=${String(L).padStart(5)} enum mean ${mean.toFixed(4)} vs closed ${cf.mu.toFixed(4)}` + ` | enum sd ${sd.toFixed(4)} vs closed ${cf.sd.toFixed(4)}` + ` | anchor count ${anchorCount} at pct ${pct.toFixed(2)}% C/mu(enum) ${(anchorCount / mean).toFixed(4)} C/mu(closed) ${(anchorCount / cf.mu).toFixed(4)}` + ` | min ${Math.min(...hist.keys())} max ${Math.max(...hist.keys())}`); }