#!/usr/bin/env python3 """Apply finding-driven corrections to the served staging note. python fix_recon.py doc/recon-0830-smooth-aps.md out/recon-0830-smooth-aps.md Every replacement asserts that its old string occurs EXACTLY once in the served bytes (and that its new string occurs zero times), so a drifted base fails loudly instead of patching the wrong place. The script writes bytes verbatim (LF, UTF-8, no newline translation) and refuses to write unless every assertion holds. Findings answered: #6, #142, #201, #222, #2554, #2555, #2556. Nothing outside those findings is touched; the edits below are the whole diff. """ import hashlib import os import sys sys.stdout.reconfigure(encoding="utf-8", errors="replace") BASE_SHA = "b64900a74c7649dbc91e4f8efc5e181d705150ffd3db4db115447a8ef0eab38e" # ---------------------------------------------------------------- E1: ledger verdict NEW_VERDICT = ( "verdict: NONE APPLIES AS STATED, and the step stays open; lim Var/E = 0.45546 stays " "HEURISTIC. Read at the page (eleven sources, arXiv text layers and the Acta Math. page " "image): every pointwise asymptotic is O(log q / log y)-precise (Granville 1993 Thm 1) or " "hypothesises log x / log q -> infinity, and every beyond-square-root level " "(Fouvry-Tenenbaum 1996, Drappeau 2015, Drappeau-Granville-Shao 2017, Pascadi 2023/2025) " "hypothesises y <= x^delta, i.e. u -> infinity, against our u in (1.2, 2]; beyond the " "square root nothing with an o(1) reaches u <= 2, and the one bounded-u statement in the " "range, Harman (Acta Arith. 91 (1999) 279-289, cube-free q), is an order-of-magnitude " "lower bound, in the same register as Granville Thm 3. NEAREST is now Harper, JLMS 112 " "(2025) e70293 = arXiv:2412.19644: the 2026-08-30 rider REFUTES this note's earlier " "\"weight unmet in print\" clause, which named Harper arXiv:1208.5992 (2012, a preprint " "with no journal version found) Theorem 2, because the 2025 Barban-Davenport-Halberstam " "asymptotic treats an arbitrary complex sequence on the same dyadic all-classes object, " "and its footnote 1 answers the missing maximum over x' (which may be incorporated into " "the 2012 Theorem 1, at the cost of a factor log^{9/2} x there in place of log^{7/2} x). " "The step still does not close, on hypotheses of the 2025 theorem: its range " "sqrt(2x) < Q <= x excludes the small-D dyadic blocks, its Theorem 2 route bars sequences " "produced by a sieve process, exactly our mu^2 1_{(e,30)=1} restriction, and the 2025 " "asymptotic carries no maximum over x' of its own. No reduction to the 2025 paper was " "attempted. The record's quantifier is also refined: the cell needs the lam0-weighted " "AVERAGE over d, not uniformity. PROVEN given the weighted form (H_w) of section 3.1, " "derivation mine and unreviewed, with its two identities checked numerically in the " "producer: every two-branch cell of Xmix, both mirror cases, all bands, balanced blocks " "included, is o(ln^2 y), so the Bettin-Chandee kernel separation is not on this route; " "the reduction of (H_w) to Harper's 2012 Theorem 2 is OUTLINED and not written, and the " "three-branch type (measured -0.0002 at x = 19, trivial bound O(ln^3 y)) is untouched. " "Not TPC-strength." ) # ------------------------------------------------- E3d: rider scope + attribution OLD_H = ("The existing conditional arguments and published finite measurements below\n" "> are retained; a pending proof must not be promoted to a reviewed conclusion.") NEW_H = ( "The existing conditional arguments and published finite measurements below\n" "> are retained. Scope, per review #188: what the transfer proves is the\n" "> weighted distribution lemma for `y >= X^{1/3}`, `Q <= X^{1/8}`, and it is\n" "> accepted at proven only within that range and for #921's two families (the\n" "> zero/plus and zero/minus two-branch families, review #187); the\n" "> opposite-shift pair, the three-branch term and the pure groups stay open,\n" "> and the full-range `H_w` stays unproven. The divergence argument and the\n" "> `b_k` repair are @admiralorbiter's (#925, accepted at proven, review #323).") # ------------------------------------------------------- E4: section 3.4(b) rewrite OLD_B = ( "`g(p) = p/(p-4)` (or `2p/(p-4)`). (a) The `1/e` is partial summation on\n" "`[E, 2E]` against `f`, costing the maximum over `t` that `(H_w)` already\n" "carries. (b) `prod_{p|e} g(p) = sum_{m | e} h(m)`, `h(m) = mu^2(m) prod_{p|m}(g(p)-1)`,\n" "with `sum_m h(m)/m^{1/2} = prod_p (1 + (g(p)-1)/p^{1/2}) < infinity`; so\n" "`sum_{e<=t, e=a(d)} f(e) = sum_{(m,d)=1} h(m) sum_{e'<=t/m, e'=a inv(m)(d), (e',m)=1} mu^2(e') 1_{(e',30)=1} 1_{S(y)}(e')`.\n" "Truncate at `m <= T = log^B t`; the class map `a -> a inv(m)` permutes the\n" "units, so Cauchy-Schwarz over `m` costs `sum_{m<=T} h(m) tau(m) << log^8 T`." ) NEW_B = ( "`g(p) = p/(p-4)` for the first weight (`lam1`); the second weight (`lam0`) has\n" "`g(p) = 2p/(p-4)`, and its correction is in (b). (a) The `1/e` is partial\n" "summation on `[E, 2E]` against `f`, costing the maximum over `t` that `(H_w)`\n" "already carries. (b) `prod_{p|e} g(p) = sum_{m | e} h(m)`,\n" "`h(m) = mu^2(m) prod_{p|m}(g(p)-1)`. For the first weight this is\n" "summable: `h(p) = p/(p-4) - 1 = 4/(p-4)`, so\n" "`sum_m h(m)/m^{1/2} = prod_p (1 + 4/((p-4) p^{1/2})) < infinity`; so\n" "`sum_{e<=t, e=a(d)} f(e) = sum_{(m,d)=1} h(m) sum_{e'<=t/m, e'=a inv(m)(d), (e',m)=1} mu^2(e') 1_{(e',30)=1} 1_{S(y)}(e')`.\n" "Truncate at `m <= T = log^B t`; the class map `a -> a inv(m)` permutes the\n" "units, so Cauchy-Schwarz over `m` costs `sum_{m<=T} h(m) tau(m) << log^8 T`.\n" "**That `h`-decomposition is available for the first weight only.** For the\n" "second weight `h(p) = (p+4)/(p-4) -> 1`, so `sum_m h(m)/m^{1/2}` DIVERGES\n" "(even its prime terms do), and `h` must not be used for `lam0`: the step is\n" "valid only for the `g(p) = p/(p-4)` family. The scoped repair is #926\n" "(review #188, accepted at proven for `y >= X^{1/3}`, `Q <= X^{1/8}` only,\n" "NOT the full-range `(H_w)`): write each weight as `f_k = b_k * F_k` with\n" "`F_k = I_y^{*k}` (`F_1 = I_y`, `F_2 = tau I_y`), `k = 1, 2`, local factor\n" "`(1 + [kp/(p-4)] z)(1-z)^k`. Its linear coefficient is `4k/(p-4) = O(1/p)`;\n" "the `z^2` coefficient is `-p/(p-4)` (k = 1) or `1 - 4p/(p-4)` (k = 2) and\n" "the `z^3` coefficient is `2p/(p-4)` (k = 2), all bounded, so\n" "`sum_n |b_k(n)|/n^sigma` and `sum_n |b_k(n)|^2/n^sigma` converge for every\n" "`sigma > 1/2` (#926 (5)). Of the rest of (b)-(d) only the identity\n" "carries over,\n" "`sum_{e<=t, e=a(d)} f_k(e) = sum_{(m,d)=1} b_k(m) sum_{n<=t/m, n=a inv(m)(d)} I_y^{*k}(n)`,\n" "with no `(n,m)=1` condition. The truncation cost does not: `b_k(p^2)` is\n" "about `-1` (k = 1) or `-3` (k = 2), so\n" "`sum_{m<=T} |b_k(m)| tau(m) >> T^{1/2}/log T`, not `log^8 T`; step (c)'s\n" "Mobius removal does not apply; and for `k = 2`, `F_2 = tau I_y` is not\n" "Harper Theorem 2's object, so the transfer runs through the hyperbola\n" "identity and the squared tail of #926 sections 2b-2e (hyperbola transfer,\n" "tail via (5) at `sigma = 3/4`, grid maximum), not through (c)-(f)." ) # ------------------------------------------------- E5: 3.4(d), the m > T tail bound # (finding #2556, and #201's optional item; review #323's advisory wording) OLD_D = ("`<= eps^2 t^2/d` for `P >= 2/eps^2` and `d <= t`; the same shape handles the\n" "`m > T` tail of (b) with `sum_{m>T} h(m)/m << T^{-1/2}`. (e) The maximum over") NEW_D = ("`<= eps^2 t^2/d` for `P >= 2/eps^2` and `d <= t`; the same shape handles the\n" "`m > T` tail of (b) with `sum_{m>T} h(m)/m << T^{-1/2}`, **but only for the\n" "first weight**: for `lam0`, `h(p) -> 1` and `sum_{m>T} h(m)/m` is about\n" "`log y`, not a `T`-power tail, so that bound fails too. (e) The maximum over") # (old, new, label) — every old must occur exactly once, every new zero times. EDITS = [ ("verdict-line", NEW_VERDICT, None), ("rider-footnote", "addresses the missing maximum over", "says the missing maximum over"), ("rider-footnote2", " The NEAREST citation is that", " That maximum may be incorporated into\n" "> the 2012 Theorem 1 (arXiv:1208.5992), at the cost of a factor log^{9/2} x\n" "> there in place of log^{7/2} x. The NEAREST citation is that"), ("rider-no-max", "paper, not arXiv:1208.5992; the step still does not close, on the range", "paper, not arXiv:1208.5992, and the 2025 asymptotic itself carries no\n" "> maximum over x'; the step still does not close, on the range"), ("rider-header", "**SCOPED CORRECTION 2026-09-17 (job1745; review pending).** Section3.4(b)'s", "**SCOPED CORRECTION 2026-09-17 (job 1745 = return #926, review #188; return\n" "> #921, review #187).** Section 3.4(b)'s"), ("rider-spacing1", "h(p)=g(p)-1 tends to1, so even the prime terms in", "h(p)=g(p)-1 tends to 1, so even the prime terms in"), ("rider-spacing2", "and summable corrections at every exponent>1/2.", "and summable corrections at every exponent > 1/2."), ("rider-scope", OLD_H, NEW_H), ("b-rewrite", OLD_B, NEW_B), ("d-tail", OLD_D, NEW_D), ] def main(): src, dst = sys.argv[1], sys.argv[2] with open(src, "rb") as fh: raw = fh.read() sha0 = hashlib.sha256(raw).hexdigest() text = raw.decode("utf-8") orig = text.split("\n") # never mutated: the before-image for the diff report lines0 = orig if BASE_SHA and sha0 != BASE_SHA: raise SystemExit("REFUSING: base sha256 %s, expected %s" % (sha0, BASE_SHA)) if b"\r" in raw: raise SystemExit("REFUSING: served bytes contain CR") # --- E1: the verdict is a whole line, replaced by line index (no ambiguity) --- idx = [i for i, ln in enumerate(orig) if ln.startswith("verdict: NONE APPLIES AS STATED")] assert len(idx) == 1, "verdict line anchors found: %r" % idx cur = list(orig) cur[idx[0]] = NEW_VERDICT text = "\n".join(cur) # --- the substring edits --- checks = [] for label, old, new in EDITS: if label == "verdict-line": continue n_old = text.count(old) assert n_old == 1, "%s: old occurs %d times" % (label, n_old) n_new = text.count(new) assert n_new == 0, "%s: replacement already present" % (label,) text = text.replace(old, new, 1) checks.append((label, n_old)) out = text.encode("utf-8") assert b"\r" not in out, "CR introduced" # --- checks: what changed, and that it is only what was intended --- lines1 = text.split("\n") n0, n1 = len(orig), len(lines1) sha1 = hashlib.sha256(out).hexdigest() # A positional comparison is meaningless across insertions; count real edits with a # line-sequence match, and report the hunks. import difflib sm = difflib.SequenceMatcher(a=orig, b=lines1, autojunk=False) hunks = [(i1 + 1, i2 - i1, j1 + 1, j2 - j1) for tag, i1, i2, j1, j2 in sm.get_opcodes() if tag != "equal"] # structure guards: the ledger comment, the two blockquotes, the table lset0 = set(orig) lset1 = set(lines1) removed = sorted(lset0 - lset1) print("edits applied (old string occurred once):") for label, n in checks: print(" %-18s ok" % label) print("verdict line replaced at line %d (1-indexed)" % (idx[0] + 1)) def ranges(xs): out, i = [], 0 while i < len(xs): j = i while j + 1 < len(xs) and xs[j + 1] == xs[j] + 1: j += 1 out.append(str(xs[i]) if i == j else "%d-%d" % (xs[i], xs[j])) i = j + 1 return ",".join(out) print("lines %d -> %d" % (n0, n1)) print("%d non-equal hunks (served line,new line,+/-):" % len(hunks)) for a, na, b, nb in hunks: print(" served %-4d (+%3d) -> new %-4d (+%3d)" % (a, na, b, nb)) print("lines with no surviving copy (all rewritten, %d):" % len(removed)) for r in removed: print(" - %s" % r[:110]) print("ledger block opens: %s ; closes: %s ; todo line: %s" % (lines1[2].strip() == "", "todo: 9" in text)) print("ledger lines 3-6 and 8-9 untouched: %s" % all(orig[i] == lines1[i] for i in (0, 2, 3, 4, 5, 8))) print("section count: %d headings -> %d" % (sum(1 for l in orig if l.startswith("#")), sum(1 for l in lines1 if l.startswith("#")))) print("table rows: %d -> %d" % (sum(1 for l in orig if l.startswith("|")), sum(1 for l in lines1 if l.startswith("|")))) print("SCOPED CORRECTION header present: %s" % ("SCOPED CORRECTION 2026-09-17 (job 1745 = return #926" in text)) print("sha256 before %s" % sha0) print("sha256 after %s" % sha1) print("bytes %d -> %d" % (len(raw), len(out))) import difflib as _dl diff = "".join(_dl.unified_diff( raw.decode("utf-8").splitlines(keepends=True), out.decode("utf-8").splitlines(keepends=True), fromfile="a/research/history/staging/recon-0830-smooth-aps.md", tofile="b/research/history/staging/recon-0830-smooth-aps.md")) open(dst + ".diff", "w", encoding="utf-8", newline="\n").write(diff) dlines = diff.split("\n") adds = sum(1 for l in dlines if l.startswith("+") and not l.startswith("+++")) dels = sum(1 for l in dlines if l.startswith("-") and not l.startswith("---")) print("diff: +%d -%d lines in %d hunks ; wrote %s.diff" % (adds, dels, sum(1 for l in dlines if l.startswith("@@")), dst)) inserted = [l for l in diff.split("\n") if (l.startswith("+") and not l.startswith("+++"))] widths = sorted((len(l) - 1, l[1:70]) for l in inserted) print("longest inserted lines:") for w, s in widths[-4:]: print(" %3d %s" % (w, s)) prose_over = [w for w, s in widths if w > 88 and "sum_" not in s and "sum(" not in s and "x\u2032" not in s] print("inserted PROSE lines over 88 chars: %s" % (", ".join(str(w) for w in prose_over) or "none")) os.makedirs(os.path.dirname(os.path.abspath(dst)), exist_ok=True) with open(dst, "wb") as fh: fh.write(out) print("wrote %s" % dst) return 0 if __name__ == "__main__": sys.exit(main())