#!/usr/bin/env python3 """Job #3643: build the revision of research/history/staging/attack-0830-varE-identification.md. The revision is the SERVED file (v2, sha256 33cc3583...) with the seven edits below and nothing else. The script refuses to run unless the base file on disk is exactly the served sha, and refuses to replace any block whose sha256 is not the one frozen here, so a change to the served file, or a transcription slip in this script, stops the build instead of producing a silent overwrite. Every replaced block was measured from the served bytes by block-shas.py; no old line is transcribed by hand. apply-revision.py [--base served-v2.md] [--out revised-....md] Exit 0 on success, 2 on refusal. """ import argparse import hashlib import sys BASE_SHA = "33cc35833d33533777971079dc0d763e5b7e6be8a3bc9fab7bb0249208ddd6fb" # --------------------------------------------------------------------------- # the edits: (name, first line, last line, sha256 of the replaced block, new lines) # --------------------------------------------------------------------------- E1 = ( "ledger verdict (line 8): the over-broad Kloosterman clause (finding #2553 / #1547 hunk 4), " "Harper's range (finding #221), Henriot's hypotheses (finding #221)", 8, 8, "d7f33aaeb75e1b9927a5d28a439cf176b43ca4adb5864e346176829256ad5f3c", ["verdict: Neither closes, and the two named steps are one statement (Conjecture 1 of variance-note sec.10; " "the model half is PROVEN in varE-limit-theorem.md). The remainder is re-split exactly at five levels: the " "corpus's X2 column doubles the positive half of one shift pattern (X2c = 2.66 against the group sum 0.09 at " "x = 19, PROVEN by rebuild), so its Xmix is overstated 2.3x; the true mixed remainder is MEASURED at -0.49 ln y " "and 82 % of it sits BELOW 2L, in the two-branch type, in the unbalanced range min(d,e) <= L^(2/5) (99.7 % of " "that cell at x = 19), outside the reach of the bilinear Kloosterman-fraction bounds in print below every fixed " "power L^delta and in the three-branch / sharp-cut complements (DFI97 Thm 1, whose Fejer-weighted rectangular " "block (A) is PROVEN in return #916, reaches from L^delta up to L^(2/5)); the divisor-distribution estimate the " "record names (n > 2L only) is therefore not the whole open step. Henriot's Corollary 2 (read at the page, " "erratum read) applies as the erratum states it, under eps < alpha/600 and with F_0, F_1 read at prime powers " "(redteam-0830-imports.md row a5), and cuts the moduli to n <= L ln^(2+o(1)) y, PROVEN given that theorem; the " "one inequality left is the uniform o(1) equidistribution of y-friable squarefree integers in progressions to " "moduli up to y^(4/5), which has since been searched at the page in recon-0830-smooth-aps.md " "(Q-recon-0830-smooth-aps, same TODO item 9): eleven sources, NONE APPLIES AS STATED; per that note's " "2026-08-30 rider from redteam-0830-imports.md the nearest statement is Harper, JLMS 112 (2025) e70293 = " "arXiv:2412.19644 (the BDH asymptotic for an arbitrary complex sequence on the same dyadic all-classes object), " "and the step still does not close, on Harper's range sqrt(2N) < Q <= N (N the length of his sum) and because " "its Theorem 2 route bars sieved sets by name. The limit 0.45546 stays HEURISTIC. Not TPC-strength."], ) E2 = ( "section 0 PART G bullet: the over-broad 'no Kloosterman-fraction bound' clause (#1547 hunk 2, finding #5)", 89, 90, "d6bcb355394dcc1b182af9c8cfb690a9a0d08fc8ccaac0abbcf8bb7b0e1796eb", [" obstruction is unbalanced, and the Kloosterman-fraction bounds in print reach", " only part of the unbalanced range: DFI97 Theorem 1 (statement via Shen", " 2607.06575 Lemma 5) saves `D^{-1/2} + sqrt(D/E)` for a fixed-power short", " factor `L^delta <= D <= L^{2/5}`, and return #916 (accepted at proven) proves", " its Fejer-weighted rectangular block (A), so what no bound in print reaches is", " a short factor below every fixed power `L^delta`, together with the", " three-branch and sharp-cut complements of the cell (section 4)."], ) E3 = ( "section 0 Henriot bullet: 'hypotheses met as stated' -> the erratum's statement, two hypotheses (finding #221)", 94, 95, "b6c76a7ed542e34c3f17f394c3050da4e5d53eba5fde3963fbf651edd0a52d03", [" (although they are still valid)\") applies to `F_0(h) F_1(h-2) F_1(h+2)` as the", " ERRATUM states it, under `eps < alpha/600` and with `F_0, F_1` read at prime", " powers (`redteam-0830-imports.md` row a5; section 5), and gives"], ) E5 = ( "section 1: '4^omega count' -> the weighted coefficient mass, class count 3^omega (finding #200)", 154, 154, "73e838f1afee70125373307e446cb7a43f9cc09333d0f2bbd995d5d98ed50979", ["`sum_{n>2L} W_mix(n)` are both `O(ln^3 y)` by the `4^omega` weighted coefficient", "mass (the sum of `2^{#zero labels}` over the assignments of labels to the primes),", "not by a class count of `4^omega`: the classes number `3^omega` (return #913", "section 4)), so the"], ) E4 = ( "section 3 item 5: same restriction in the same terms (#1547 hunk 3, finding #5)", 246, 249, "83e0b516219a9e1a560c3257a38a1a7a7c0b37d5e73c0a3e48aed0eb3c1844e8", [" dominant cell sits at `min(d, e) <= L^{2/5}`. For `e(a inv(m)/n)` with", " arbitrary coefficients a bound in print does save in part of that range:", " DFI97 Theorem 1 (statement via Shen 2607.06575 Lemma 5, and review #184 on", " return #916) gives `D^{-1/2} + sqrt(D/E)` for a fixed-power short factor", " `L^delta <= D <= L^{2/5}`, and return #916 (accepted at proven) proves its", " Fejer-weighted rectangular block (A), which is the shape of the cell here.", " What no bound in print reaches is a short factor below every fixed power", " `L^delta`, and the three-branch and sharp-cut complements. Section 4 states", " what is needed there."], ) # --------------------------------------------------------------------------- # the two edits inside one-line table rows: (name, line, sha of the whole old line, # [(old, new), ...]) # --------------------------------------------------------------------------- E6 = ( "section 5 Henriot row: 'for every eps' and 'APPLIES AS STATED' -> the erratum's statement " "under eps < alpha/600 and F at prime powers (finding #221, redteam-0830-imports.md row a5)", 322, "623272c6238a374df895077480ef6499bc1123538d934dd2c0d2da394ecaede2", [ ("`F in M_3(17/3, B, eps)` for every `eps`; `x^alpha <= y <= x` met on dyadic blocks", "`F in M_3(17/3, B, eps)` for `eps < alpha/600` and with `F_0, F_1` read at prime " "powers, where the note's squarefree `lam0, lam1` put them (`redteam-0830-imports.md` " "row a5); `x^alpha <= y <= x` met on dyadic blocks"), ("**APPLIES AS STATED.** Deduction below", "**APPLIES AS THE ERRATUM STATES IT**, under those two hypotheses. Deduction below"), ], ) E7 = ( "section 5 toolkit: split the DFI / Bettin-Chandee row, so DFI97 Theorem 1 carries its own " "statement and the hypothesis |a| << MN (#1547 hunk 1, findings #5 and #2553)", 325, 325, "910889bb8642b013ebfb98de95af0bad7c9bc6624b87404036fa75f732b13395", ["| Duke-Friedlander-Iwaniec 1997, Theorem 1 (statement read at the page in Shen 2607.06575 " "Lemma 5, which quotes it: `B << \\|\\|alpha\\|\\|_2 \\|\\|beta\\|\\|_2 ((M+N)^{1/2} + " "(1 + \\|a\\|/MN)^{1/2} min(M,N)) (MN)^eps`; and review #184 on return #916; the DFI97 paper " "itself NOT read at the page) | `e(a inv(m)/n)`, arbitrary coefficients: saving " "`D^{-1/2} + sqrt(D/E)` for a fixed-power short factor `L^delta <= D <= L^{2/5}`, the branch " "`(1+\\|a\\|/MN)^{1/2}` needing the hypothesis `\\|a\\| << MN` (Shen, above his Lemma 5: " "\"in the case `a << MN`\"); the `(MN)^eps` loss is why `D >= L^delta` is needed | our " "coefficients are arbitrary and coprime-supported and the phase is the right one (PART A); " "its Fejer-weighted rectangular block (A) is the shape of the dominant cell here (PART G) | " "**HYPOTHESIS MET for block (A)**, `\\|a\\| << MN` and `L^delta <= D <= L^{2/5}` (PROVEN in " "return #916); the three-branch type and the sharp-cut complements are NOT of shape (A); " "below every fixed power `L^delta` it does not reach the obstruction |", "| Bettin-Chandee Theorem 1 (read, p.2) | bilinear / trilinear forms with `e(a inv(m)/n)`, " "arbitrary coefficients, saving a power when the two variables are balanced | our " "coefficients are arbitrary and coprime-supported, the phase is the right one (PART A); the " "kernel couples the third variable to the product | HYPOTHESIS MET on the balanced blocks; " "owed the separation; does not reach the obstruction |"], ) BLOCK_EDITS = [E1, E2, E3, E5, E4, E7] ROW_EDITS = [E6] def sha(text: str) -> str: return hashlib.sha256(text.encode("utf-8")).hexdigest() def main() -> int: ap = argparse.ArgumentParser() ap.add_argument("--base", default="served-v2.md") ap.add_argument("--out", default="revised-attack-0830-varE-identification.md") a = ap.parse_args() sys.stdout.reconfigure(newline="\n", encoding="utf-8", errors="replace") with open(a.base, "rb") as fh: raw = fh.read() if hashlib.sha256(raw).hexdigest() != BASE_SHA: print("REFUSING: the base file is not the served sha %s" % BASE_SHA) return 2 lines = raw.decode("utf-8").split("\n") if lines[-1] != "": print("REFUSING: the base file does not end in a newline") return 2 # every edit carries its own line span, and all of them are applied bottom up, so a # block that grows or shrinks cannot move a later edit's line numbers. jobs = ([("block", e) for e in BLOCK_EDITS] + [("row", e) for e in ROW_EDITS]) for kind, edit in sorted(jobs, key=lambda j: -j[1][1]): if kind == "block": name, first, last, old_sha, new = edit else: name, first, old_sha, subs = edit last = first block = "\n".join(lines[first - 1:last]) + "\n" if sha(block) != old_sha: print("REFUSING: %s\n the block at lines %d-%d is not the frozen sha %s\n it hashes to %s" % (name, first, last, old_sha, sha(block))) return 2 if kind == "block": lines[first - 1:last] = list(new) print("ok block lines %d-%d -> %d lines" % (first, last, len(new))) else: text = lines[first - 1] for old_sub, new_sub in subs: if text.count(old_sub) != 1: print("REFUSING: %s\n the anchor occurs %d times in line %d: %r" % (name, text.count(old_sub), first, old_sub[:60])) return 2 text = text.replace(old_sub, new_sub) lines[first - 1] = text print("ok row line %d: %d substring(s)" % (first, len(subs))) out = "\n".join(lines) with open(a.out, "w", encoding="utf-8", newline="\n") as fh: fh.write(out) print("\nwrote %s\nsha256 %s\nbytes %d\nlines %d" % (a.out, sha(out), len(out.encode("utf-8")), out.count("\n"))) return 0 if __name__ == "__main__": raise SystemExit(main())