#!/usr/bin/env python3 """Apply job #3013's revision to the served fold-profile-13 sweep, minimal and anchored. Five anchors, each required to match the served bytes exactly once; the script refuses at the first mismatch and writes nothing. Two of the five touch the code above the OUTPUT banner (so the embedded fingerprint has to be re-embedded with `research/qc/embed.js`, which this script does not do -- `recipe.md` does), three touch the READINGS and FIGURE PROVENANCE prose below it (which the banner's code-sha256 does not cover). E1-E3 the four grouped figures pin their locale (en-US), so the printed digits no longer depend on the host the script runs on. E4-E5 reading 4's six seam z scores move to the values the embedded table prints, and the FIGURE PROVENANCE note records what the retired digits were and that they are the pre-2026-08-20 LCG's own output. python apply-revision.py --base --out [--diff ] Exit 0 on a clean apply, 1 on refusal. """ import argparse import difflib import hashlib import sys BASE_SHA = "0ebd512033257c82aca3130512fd917c239b81f0e23bcd25e7200d5c43472177" EDITS = [ # ---------------------------------------------------------------- code --- ("E1 rnd-comment-and-locale . . . the grouped figures pin en-US", """ const results = []; for (const T of TILES) { log(`building T${T.x} (W = ${T.W.toLocaleString()}) ...`); """, """ const results = []; // GROUPING IS PINNED to en-US (2026-09-24). A bare toLocaleString() follows the // HOST locale, so on a French machine (510,510) prints "510 510" and this file's // embedded OUTPUT block -- captured on a comma-grouping host -- cannot reproduce // there; `research/qc/embed.js --check` then reports "this run does not reproduce // the pasted block" on a file that has not changed. These four figures are the // only locale-dependent bytes this script prints. for (const T of TILES) { log(`building T${T.x} (W = ${T.W.toLocaleString('en-US')}) ...`); """), ("E2 tile-heading figures pin en-US", """ console.log(`T${T.x}: W = ${G.W.toLocaleString()}, bin = ${G.B}, slots D = ${G.D.toLocaleString()}, ` + `twin primes = ${G.TT.toLocaleString()}, mean survival = ${MEAN.toFixed(6)}`); """, """ console.log(`T${T.x}: W = ${G.W.toLocaleString('en-US')}, bin = ${G.B}, slots D = ${G.D.toLocaleString('en-US')}, ` + `twin primes = ${G.TT.toLocaleString('en-US')}, mean survival = ${MEAN.toFixed(6)}`); """), ("E3 seam-heading figure pins en-US", """ console.log(` SEAMS at multiples of ${WPREV.toLocaleString()}, k = 1..${T.x - 1}, against 400 random controls each:`); """, """ console.log(` SEAMS at multiples of ${WPREV.toLocaleString('en-US')}, k = 1..${T.x - 1}, against 400 random controls each:`); """), # -------------------------------------------------------------- prose --- ("E4 reading 4 quotes the table's six values and points at the provenance note", """ // 4. GAP 3 IS CLOSED AND THE ANSWER IS FLAT. Seams against 400 random controls // give z = -1.41, -0.19, -0.09 at T19 and -0.65, +0.13, -0.50 at T23, all // "consistent with the null". This is the file that owns those z-scores, and // the quoted range fuses two tiles: -1.41 is T19 at half-width 3,000 and // +0.13 is T23 at half-width 30,000, so it is not a range within any one // measurement. Wave 5 (S2-7) found research/GLOSSARY.md and """, """ // 4. GAP 3 IS CLOSED AND THE ANSWER IS FLAT. Seams against 400 random controls // give z = -1.42, -0.07, -0.13 at T19 and -0.68, +0.26, -0.53 at T23, all // "consistent with the null". This is the file that owns those z-scores, and // the quoted range fuses two tiles: -1.42 is T19 at half-width 3,000 and // +0.26 is T23 at half-width 30,000, so it is not a range within any one // measurement. The six digits this reading carried before 2026-08-20 and why // they moved, with the verdict unmoved, are in the FIGURE PROVENANCE note // below. Wave 5 (S2-7) found research/GLOSSARY.md and """), ("E5 provenance note: what the retired digits were", """ // The direction of the argument, that the skew is negligible away from // width 8, is unaffected. // --------------------------------------------------------------------------- """, """ // The direction of the argument, that the skew is negligible away from // width 8, is unaffected. // RETIRED 2026-09-24, AND NOT A DIFFERENT DRAW (reading 4's six seam z scores, // the figures the audit of return #1074 caught). Reading 4 printed // z = -1.41, -0.19, -0.09 at T19 and -0.65, +0.13, -0.50 at T23 until this // pass. They are the exact printed output of the seam loop's pre-2026-08-20 // plain-multiply LCG, `seed = (seed * 1103515245 + 12345) % 2**31` -- inexact // from the second call, because that product passes 2**53 -- and NOT a // different random draw: restoring that one line in the seam loop reproduces // all six digits exactly, at the two decimals it prints. Today's rnd // (`Math.imul`, 2026-08-20) is deterministic, and it prints the table's // -1.42, -0.07, -0.13 and -0.68, +0.26, -0.53, which is what reading 4 now // quotes. Nothing in the reading moves but the digits: both LCGs put every // seam inside 3 sd of the null, which is the whole claim, and the two-tile // fusion the reading flags -- 3,000 in one tile, 30,000 in the other -- holds // under either. // --------------------------------------------------------------------------- """), ] def main() -> int: ap = argparse.ArgumentParser() ap.add_argument("--base", required=True) ap.add_argument("--out", required=True) ap.add_argument("--diff") a = ap.parse_args() with open(a.base, encoding="utf-8", newline="") as fh: src = fh.read() got = hashlib.sha256(src.encode("utf-8")).hexdigest() if got != BASE_SHA: print(f"REFUSING: --base is not the served file (sha256 {got}, expected {BASE_SHA})", file=sys.stderr) return 1 out = src for name, old, new in EDITS: n = out.count(old) if n != 1: print(f"REFUSING at {name}: anchor occurs {n} times, expected exactly 1", file=sys.stderr) if n == 0: head = old.splitlines()[1] if len(old.splitlines()) > 1 else old[:60] print(f" anchor head: {head!r}", file=sys.stderr) return 1 out = out.replace(old, new) print(f"applied {name}") with open(a.out, "w", encoding="utf-8", newline="") as fh: fh.write(out) print(f"wrote {a.out}") print(f" base {got}") print(f" revised {hashlib.sha256(out.encode('utf-8')).hexdigest()}") print(f" bytes {len(src.encode('utf-8'))} -> {len(out.encode('utf-8'))}") if a.diff: d = difflib.unified_diff(src.splitlines(keepends=True), out.splitlines(keepends=True), fromfile="served", tofile="revised", n=3) with open(a.diff, "w", encoding="utf-8", newline="\n") as fh: fh.writelines(d) print(f" diff {a.diff}") return 0 if __name__ == "__main__": sys.exit(main())