/* * objective-tail.mjs — job #641. Question, then the code. * * QUESTION. At a fold p -> q the certificate's objective is the sum G_{L+1}(i) of a window (i, L) of the old * word's gap word, over the windows whose interiors qualify mod q. Every retained census takes either the * MAXIMUM of that objective (the certificate M, and its argmax count) or a threshold count of the NEW word's * own gaps. The objective's own distribution near its maximum is not retained anywhere. Does it decide * something? It decides whether the certificate's value is a POPULATION value or an ACCIDENT: * - population => a density argument ("no window can reach M") could replace the argmax-structure * argument the instrument uses for exactness, which is what a sieve-type bound controls; * - accident => only the argmax windows' structure can decide exactness, a bound on this whole family. * Pre-registered in `prereg-641.md` BEFORE this file existed, including the falsifier and the control. * * THE STATISTIC. f(delta) = #{windows with sum >= M - delta} / W_total, in parts per million, at * delta = 6, 12, 18; emitted with M, hits (count at exactly M) and W_total. Exact, not sampled: the * objective is counted exhaustively in one pass, one sum per window. * * PRE-REGISTERED FALSIFIER. The density route is refuted if, at every reachable fold, f(6) <= 10 ppm and the * permutation control's f(6) lies in the same range. * * MATCHED CONTROL. Permutation of the gap word (histogram preserved exactly, arrangement destroyed), seeds * 1..5 via mulberry32, declared. Second control: the palindrome check, which decides whether route 1 in my * claim (reversal closure of the extremal set) is a statistic or a triviality of the word. * * OUTPUT: tables; stdout is the artifact, progress and timing go to stderr. Node >= 18, stdlib only. */ const P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]; const prim = (p) => P.filter((r) => r <= p).reduce((a, r) => a * r, 1); const CAP = 128; const MASK = 511; const SUMCAP = 2048; // every tile gap is a multiple of 6 and <= 2048 here const SHUF = 5; function slotsSmall(p) { const W = prim(p), rs = P.filter((r) => r <= p); const cop = new Uint8Array(W).fill(1); for (const r of rs) for (let x = r; x < W; x += r) cop[x] = 0; cop[0] = 0; const out = new Uint32Array(W); let n = 0; for (let x = 1; x < W; x++) if (cop[x] && cop[(x + 2) % W]) out[n++] = x; return out.subarray(0, n); } function foldToSlots(slots, Wp, q) { const Wq = Wp * q, want = Math.round(slots.length * (q - 2)); const out = new Float64Array(want); const r = new Uint8Array(slots.length); for (let i = 0; i < slots.length; i++) r[i] = slots[i] % q; const WpMod = Wp % q; let n = 0, prev = -1, first = -1, maxg = 0; for (let k = 0; k < q; k++) { const base = k * Wp; const e1 = (q - ((k * WpMod) % q)) % q, e2 = (q - (((k * WpMod) + 2) % q)) % q; for (let i = 0; i < slots.length; i++) { if (r[i] === e1 || r[i] === e2) continue; const x = base + slots[i]; if (first < 0) first = x; if (prev >= 0) { const g = x - prev; if (g > maxg) maxg = g; } prev = x; if (n < want) out[n++] = x; } } { const g = first + Wq - prev; if (g > maxg) maxg = g; } return { slots: out.subarray(0, n), D: n, maxGap: maxg }; } function gapsOfSlots(sl, W) { const g = new Uint16Array(sl.length); for (let i = 0; i < sl.length; i++) g[i] = (i + 1 < sl.length ? sl[i + 1] : sl[0] + W) - sl[i]; return g; } function gapsOf(p) { const W = prim(p); return gapsOfSlots(slotsSmall(p), W); } /** Is the cyclic gap word a palindrome up to rotation? Returns the rotation offset, or -1. */ function cyclicPalindrome(g) { const D = g.length; if (D < 2) return 0; const rev = new Uint16Array(D); for (let i = 0; i < D; i++) rev[i] = g[D - 1 - i]; const dd = new Uint16Array(2 * D); for (let i = 0; i < 2 * D; i++) dd[i] = g[i % D]; const lps = new Int32Array(D).fill(0); for (let i = 1; i < D; i++) { let j = lps[i - 1]; while (j > 0 && rev[i] !== rev[j]) j = lps[j - 1]; if (rev[i] === rev[j]) j++; lps[i] = j; } let j = 0; for (let i = 0; i < 2 * D - 1; i++) { while (j > 0 && dd[i] !== rev[j]) j = lps[j - 1]; if (dd[i] === rev[j]) j++; if (j === D) return i - D + 1; } return -1; } /** One exhaustive pass over the objective: windows (i, L), L >= 1, qualifying interiors. */ class Objective { constructor(q, theta) { this.q = q; this.theta = theta ?? Infinity; this.buf = new Float64Array(MASK + 1); this.pos = 0; this.D = 0; this.W = 0; this.hist = new Int32Array((CAP * SUMCAP) / 6 + 8); this.top = []; // windows with sum >= theta, for the realizability pass (capped) this.topN = 0; this.head = new Float64Array(CAP + 3); this.headN = 0; } ring(j) { return this.buf[(this.pos - 1 - j + MASK + 1) & MASK]; } // pos is post-increment: newest gap at pos-1 qual(x) { const r = x % this.q; return r === 0 || r === 2 || r === this.q - 2; } consider(i, L, s) { this.W++; const b = s / 6; if (b < this.hist.length) this.hist[b]++; if (s >= this.theta) { this.topN++; if (this.top.length < 200000) { const gs = []; for (let j = L; j >= 0; j--) gs.push(this.ring(j)); this.top.push(gs); } } } scan(i, seam) { const inc = seam ? (L) => L > i : (L) => L <= i; let s = this.ring(1) + this.ring(0); if (inc(1)) this.consider(i, 1, s); for (let L = 2; L <= CAP; L++) { if (!this.qual(this.ring(L - 1))) break; s += this.ring(L); if (inc(L)) this.consider(i, L, s); } } push(g) { const i = this.D; this.buf[this.pos++ & MASK] = g; this.D++; if (this.headN <= CAP + 2) this.head[this.headN++] = g; this.scan(i, false); } replay() { for (let j = 0; j < this.headN; j++) { this.buf[this.pos++ & MASK] = this.head[j]; this.scan(j, true); } } max() { let M = -1, hits = 0; for (let b = 0; b < this.hist.length; b++) if (this.hist[b] > 0) { const s = b * 6; if (s > M) { M = s; hits = 0; } if (s === M) hits += this.hist[b]; } return { M, hits }; } tail(M, delta) { let n = 0; for (let b = Math.max(0, Math.ceil((M - delta) / 6)); b < this.hist.length; b++) n += this.hist[b]; return n; } nu(gs) { const G = []; let s = 0; for (const v of gs) { s += v; G.push(s); } const L = gs.length - 1; let c = 0; for (let a = 0; a < this.q; a++) { if (a === 0 || a === 2) continue; if (a === G[L] % this.q || a === (G[L] + 2) % this.q) continue; let ok = true; for (let j = 0; j < L; j++) { const rr = G[j] % this.q; if (rr !== a && rr !== (a - 2 + this.q) % this.q) { ok = false; break; } } if (ok) c++; } return c; } } function runObjective(gaps, q, theta) { const o = new Objective(q, theta); for (let i = 0; i < gaps.length; i++) o.push(gaps[i]); o.replay(); return o; } function mulberry32(a) { return function () { a |= 0; 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; }; } function shuffled(g, seed) { const a = Uint16Array.from(g), r = mulberry32(seed); for (let i = a.length - 1; i > 0; i--) { const j = Math.floor(r() * (i + 1)); const t = a[i]; a[i] = a[j]; a[j] = t; } return a; } const ppm = (n, W) => (1e6 * n / W).toFixed(2); const t0 = Date.now(); console.log('# objective-tail.mjs — job #641, the objective\'s tail near its maximum, with its permutation control'); console.log(`# CAP=${CAP}, permutation seeds 1..${SHUF} (mulberry32), pre-registration: prereg-641.md`); console.log(''); // --- control 0: the palindrome, which decides whether route 1 is a statistic or a triviality console.log('## control 0 — is the tile\'s cyclic gap word a palindrome?'); for (const p of [11, 13, 17, 19]) { const g = gapsOf(p); const off = cyclicPalindrome(g); console.log(` T_${p}: D = ${g.length}, rotation offset ${off === -1 ? 'NONE (not a cyclic palindrome)' : off + ' (palindrome up to rotation)'}`); } console.log(' (checked by KMP on the doubled word; larger tiles are not checked here, and the fact is de Polignac 1849 per the seed audit)'); console.log(''); // --- the statistic, per fold, with its control const F = [[11, 13], [13, 17], [17, 19], [19, 23], [23, 29], [29, 31]]; const rows = []; for (const [p, q] of F) { const g = p <= 23 ? gapsOf(p) : (() => { const s29 = foldToSlots(slotsSmall(23), prim(23), 29); return gapsOfSlots(s29.slots, prim(29)); })(); for (let i = 0; i < g.length; i++) if (g[i] % 6 !== 0) throw new Error('a gap is not a multiple of 6'); const o = runObjective(g, q); const { M, hits } = o.max(); const row = { fold: `${p} -> ${q}`, M, hits, W: o.W, f6: ppm(o.tail(M, 6), o.W), f12: ppm(o.tail(M, 12), o.W), f18: ppm(o.tail(M, 18), o.W), perms: [] }; // pass 2: are the top windows realisable? (theta known only now) const above = o.tail(M, 6); let real = null, tested = 0; if (above <= 200000) { const o2 = runObjective(g, q, M - 6); tested = o2.top.length; real = 0; for (const gs of o2.top) if (o2.nu(gs) > 0) real++; } row.above6 = above; row.tested = tested; row.real = real; process.stderr.write(` fold ${row.fold}: M=${M} hits=${hits} W=${o.W} f6=${row.f6}ppm above6=${above} real=${real}\n`); for (let s = 1; s <= SHUF; s++) { const gs = shuffled(g, s); const op = runObjective(gs, q); const mp = op.max(); row.perms.push({ seed: s, M: mp.M, hits: mp.hits, W: op.W, f6: ppm(op.tail(mp.M, 6), op.W) }); process.stderr.write(` perm ${s}: M=${mp.M} f6=${row.perms[row.perms.length - 1].f6}ppm\n`); } rows.push(row); } console.log('## the statistic: the objective\'s tail near its maximum, and its permutation control'); console.log(''); console.log('| fold | M | hits at M | windows W | f(6) ppm | f(12) ppm | f(18) ppm | windows above M-6 | realisable | permutation M (seeds 1..5) | permutation f(6) ppm |'); console.log('|---|---|---|---|---|---|---|---|---|---|---|'); for (const r of rows) { console.log(`| ${r.fold} | ${r.M} | ${r.hits} | ${r.W} | ${r.f6} | ${r.f12} | ${r.f18} | ${r.above6} | ${r.real === null ? 'not tested' : r.real + '/' + r.tested} | ${r.perms.map((x) => x.M).join(', ')} | ${r.perms.map((x) => x.f6).join(', ')} |`); } console.log(''); console.log('## reading of the pre-registered falsifier'); const fired = rows.every((r) => Number(r.f6) <= 10) && rows.every((r) => r.perms.every((x) => Number(x.f6) <= 10)); const trueAbove = rows.filter((r) => Number(r.f6) > Math.max(...r.perms.map((x) => Number(x.f6)))).map((r) => r.fold); console.log(` f(6) <= 10 ppm at every fold: ${rows.every((r) => Number(r.f6) <= 10) ? 'yes' : 'no (' + rows.filter((r) => Number(r.f6) > 10).map((r) => r.fold + ': ' + r.f6).join('; ') + ')'}`); console.log(` permutation f(6) <= 10 ppm at every fold and seed: ${rows.every((r) => r.perms.every((x) => Number(x.f6) <= 10)) ? 'yes' : 'no'}`); console.log(` FALSIFIER ${fired ? 'FIRED: the extremum is an arrangement accident at this scale, and the density route is refuted for these folds' : 'did not fire'}`); console.log(` folds where the true word is above every permutation: ${trueAbove.length ? trueAbove.join(', ') : 'none'}`); process.stderr.write(`# wall clock ${((Date.now() - t0) / 1000).toFixed(1)} s (stderr: stdout is the artifact and holds no timing)\n`);