// QUESTION (pre-registered 2026-09-16, written before this file was executed) — // solveathome twin-primes, job #1499, lane formalize, stage discover. // // The retained measurement `research/kernel-sign-control.js` (companion note // kernel-sign-control.md) measured ONE aggregate functional of the (δ,ν)=(8/25,9/20) // moment - the small-common-divisor kernel X_small, the cells with class index j<=J0 - // against a same-support seeded random-sign control, and reported its verdict as a // least-squares slope of log2 |X_small(actual)|/|X_small(random)| over seven dyadic // scales j=18..30. Its own recorded weakness: the moment is 97.66-102.58 percent // equal-frequency class while X_small carries 0.02-2.88 percent, and J0=1 at j=18, // 2 at j=20..30. So the aggregate statistic averaged over a class that is inert by // construction, and the slope estimator is the wrong instrument for a short range // (exponent-control.md: the same estimator on 58 terms of an object whose answer is // known reports 1.282 against a truth of 1). // // THIS FILE validates, by exact arithmetic and seeded Monte-Carlo, the calibration of // the replacement statistic the job #1499 design proposes: the CLASS-STANDARDISED // quadratic form, stratified by the moment's own class index j, // // Z_{x,j} = X_{x,j} / sigma_{x,j}, sigma_{x,j}^2 = sum_{cells of stratum} (b*phase)^2, // Qbar = (1/N) * sum over admissible (x,j) of Z_{x,j}^2, // // whose null moments are closed-form: E[Z^2] = 1 and Var[Z^2] = 2(1 - 1/n_eff) with // n_eff = (sum w^2)^2 / (sum w^4) the effective cell count. The pre-registered claims // checked below are C1..C4 (see the assert list); each is a statistic-calibration // claim about the estimator, NOT a claim about the twin-prime problem. No asymptotic // rate, no saving, and no twin margin is asserted or excluded anywhere in this file. // // Usage: node job1499-stratified-statistic.js [--draws 4000] 'use strict'; const assert = require('node:assert/strict'); const argv = process.argv.slice(2); const optOf = (n, d) => { const i = argv.indexOf('--' + n); return i === -1 ? d : argv[i + 1]; }; const DRAWS = Number(optOf('draws', 4000)); function mulberry32(seed) { let a = seed >>> 0; return function () { a = (a + 0x6D2B79F5) >>> 0; let t = Math.imul(a ^ (a >>> 15), 1 | a); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; } // ---- 1. exact null moments of the class-standardised statistic --------------- // For weights w (|b*phase| per cell) and i.i.d. signs e in {+1,-1}, // Z = (sum e_i w_i) / sqrt(sum w_i^2), Z^2 = 1 + 2*sum_{i (rnd() < 0.5 ? -1 : 1)); acc.push(zsq(w, signs)); } const n = acc.length; const mu = acc.reduce((a, b) => a + b, 0) / n; const va = acc.reduce((a, b) => a + (b - mu) ** 2, 0) / (n - 1); return { mu, va, se_mu: Math.sqrt(va / n), n }; } // ---- 2. weights that MIMIC the measured class shares ------------------------- // kernel-sign-control.md verdict: equal-frequency class 97.66-102.58 percent, // X_small (j<=J0) 0.02-2.88 percent. A support with a dominant inert class and a // small "kernel" stratum, weights drawn from a seeded deterministic schedule so the // fixture is reproducible and carries no research data. function fixture(share, nKer, nBig, seed) { const rnd = mulberry32(seed); const ker = Array.from({ length: nKer }, () => 0.5 + rnd()); const big = Array.from({ length: nBig }, () => 0.5 + rnd()); const s2ker = ker.reduce((a, b) => a + b * b, 0); // scale the inert class so that the kernel carries exactly `share` of the mass const target = s2ker * (1 / share - 1); const s2big = big.reduce((a, b) => a + b * b, 0); const k = Math.sqrt(target / s2big); return { ker, big: big.map((x) => x * k) }; } const lines = []; const say = (s) => { lines.push(s); }; say('STRATIFIED STATISTIC CALIBRATION — job #1499 (statistic calibration only; no science claim)'); say(`draws per Monte-Carlo = ${DRAWS}, seeds deterministic (mulberry32)`); // ---- C1: exact null moments vs Monte-Carlo, per stratum ---------------------- let c1worst = 0; for (const [label, w] of [['kernel', fixture(0.0288, 24, 400, 11).ker], ['inert', fixture(0.0288, 24, 400, 11).big], ['single-cell', [0.7]]]) { const ex = moments(w); const mc = mcMoments(w, DRAWS, 1000); const devE = Math.abs(mc.mu - 1) / mc.se_mu; const devV = Math.abs(mc.va - ex.varZ2) / ex.varZ2; if (Number.isFinite(devE)) c1worst = Math.max(c1worst, devE); say(`C1 ${label.padEnd(11)} n=${String(w.length).padStart(4)} n_eff=${ex.n_eff.toFixed(2).padStart(9)} E[Z^2]: exact 1, MC ${mc.mu.toFixed(4)} (${devE.toFixed(2)} se) Var[Z^2]: exact ${ex.varZ2.toFixed(4)}, MC ${mc.va.toFixed(4)} (${(100 * devV).toFixed(1)}%)`); if (ex.n_eff > 1.05) assert(devE < 4, `C1 failed: ${label} mean off null by ${devE} se`); assert(devV < 0.12 || ex.n_eff < 1.05, `C1 failed: ${label} variance off analytic value`); } say(`C1 PASS exact null moments confirmed for every stratum (worst mean deviation ${c1worst.toFixed(2)} se)`); // ---- C3: the aggregate statistic's dilution, quantified --------------------- // The retained statistic measures the whole moment through one aggregate whose // kernel share is s; a depression factor rho on the kernel moves the aggregate by // only ~(1-rho)*s of the aggregate's own null scale, while the stratified statistic // moves by (1-rho^2) of ITS OWN scale. Required samples for a 2-sd detection: // N_agg = 4 / (s^2 (1-rho)^2) // N_strat = 4 (1 - 1/n_eff) / (1 - rho^2)^2 function required(share, rho, n_eff) { return { agg: 4 / (share * share * (1 - rho) * (1 - rho)), strat: 4 * (1 - 1 / n_eff) / ((1 - rho * rho) ** 2) }; } say('C3 dilution: samples needed for a 2-sd detection of a kernel depression rho,'); say(' at the measured kernel shares s of kernel-sign-control.md (0.02 .. 0.0288)'); say(' rho s=0.0002 s=0.0288 ratio (agg/strat) at s=0.0288'); for (const rho of [0.25, 0.5, 0.75]) { for (const s of [0.0002, 0.0288]) { const r = required(s, rho, 24); if (s === 0.0002) say(` ${rho.toFixed(2)} agg ${r.agg.toExponential(2)} strat ${r.strat.toFixed(1)}`); else say(` agg ${r.agg.toExponential(2)} strat ${r.strat.toFixed(1)} ${(r.agg / r.strat).toExponential(2)}x`); } } const r028 = required(0.0288, 0.5, 24); assert(r028.agg / r028.strat > 100, 'C3 failed: dilution advantage not reproduced'); say(`C3 PASS at s=0.0288, rho=0.5 the stratified statistic needs ${(r028.agg / r028.strat).toExponential(2)}x fewer samples than the retained aggregate`); // ---- C2: known-answer control — recover an INJECTED depression -------------- // The exponent-control.md lesson: calibrate the estimator on an object whose answer // is known. Here the answer is known by construction: the kernel stratum's actual // coefficient is rho times a random draw, so E[Z^2] = rho^2 and the pooled estimator // must return it within its predicted sd. const RHO = 0.5, R = 64; const { ker } = fixture(0.0288, 24, 400, 11); const ex = moments(ker); let est = 0, estSq = 0; for (let d = 0; d < R; d++) { const rnd = mulberry32(5000 + d); const signs = ker.map(() => (rnd() < 0.5 ? -1 : 1)); const z = Math.sqrt(zsq(ker, signs)) * RHO; // actual = rho * random draw est += z * z; estSq += z * z * z * z; } est /= R; const sdPred = Math.sqrt(ex.varZ2 / R) * RHO * RHO; // sd of mean of 64 scaled Z^2 const dev = Math.abs(est - RHO * RHO) / sdPred; say(`C2 injected rho=${RHO} on n_eff=${ex.n_eff.toFixed(2)}: pooled estimator ${est.toFixed(4)} vs known answer ${(RHO * RHO).toFixed(4)} (${dev.toFixed(2)} predicted sd; predicted sd ${sdPred.toFixed(4)})`); assert(dev < 4, `C2 failed: known-answer control off by ${dev} sd`); // the zero-signal control: rho=1 must return 1 let est1 = 0; for (let d = 0; d < R; d++) { const rnd = mulberry32(7000 + d); const signs = ker.map(() => (rnd() < 0.5 ? -1 : 1)); est1 += zsq(ker, signs); } est1 /= R; say(`C2 zero-signal control rho=1: estimator ${est1.toFixed(4)} (predicted 1, sd ${Math.sqrt(ex.varZ2 / R).toFixed(4)})`); assert(Math.abs(est1 - 1) < 4 * Math.sqrt(ex.varZ2 / R), 'C2 failed: rho=1 returns not 1'); say('C2 PASS known-answer control recovers the injected depression and the null returns 1'); // ---- C4: independent thinning leaves the calibration invariant -------------- // Thinning a pre-registered fraction of cells at random changes n_eff but must not // move E[Z^2] away from 1: the statistic is calibrated on any sub-support. const thin = ker.filter((_, i) => i % 2 === 0); const exT = moments(thin); const mcT = mcMoments(thin, DRAWS, 2000); const devT = Math.abs(mcT.mu - 1) / mcT.se_mu; say(`C4 independent thinning 1-in-2: n ${ker.length}->${thin.length}, n_eff ${ex.n_eff.toFixed(2)}->${exT.n_eff.toFixed(2)}, E[Z^2] MC ${mcT.mu.toFixed(4)} (${devT.toFixed(2)} se)`); assert(devT < 4, 'C4 failed: thinned stratum not calibrated'); say('C4 PASS calibration invariant under independent thinning'); say('ALL CHECKS PASS'); process.stdout.write(lines.join('\n') + '\n');