#!/usr/bin/env python3 """job 2746 (triage of route 115) -- the section 4.1 error budget, tabulated and decided. THE QUESTION (route 115's priced next step, from return #1362): the exact identity is B = P_low + P_band - T_I^low (from P_low = T_I^low + T_II^low and B = T_II^low + P_band) so a lower bound on B can be obtained from a lower bound on the FLIP sum P_low + P_band minus an UPPER bound on T_I^low. Return #1362 measured T_I^low dominating B by ~10x at every reachable scale (both ~0.035 x log^2 x at x=2^20) and priced this step: tabulate every error term of research/fixed-endpoint-discrepancy.md section 4.1 with its constant and exponent, and decide whether some assignment of A, L, A_1, A_3 brings the total error below the O(x) remainder the subtraction needs. WHAT THIS DOES (stdlib only, deterministic, no network, no credential; exit 0/2/3) C1 the exponent table: each term of steps 1-7 as (power of x, power of log x, power of log log x), evaluated under the note's own substitutions L=A+13, A_3=A+5, A_1=2A+260 and "(4.6) with A+6 in place of A", with the slack against the target x log^{-A} x printed per term. C2 the closure check: every term must reach the target -- p_log <= -A for the x log^p terms, and an x-power strictly below 1 for the x^sigma log^r terms. This is the decision. C3 the thresholds: for each term, the smallest x at which it is <= c_0 x (solved by bisection, with the implicit constant taken as 1), plus the (BV*) LEVEL condition (log x)^{L+B} <= x^{eps'/3} where Q_0' = x^{1/2-eps'/3}(log x)^L must sit inside the prefix BV range. The route's x_0 is the max of these; it is tabulated in A and in c_0. C4 CONTROL (must fire): with the "(4.6) with A+6 in place of A" re-run DROPPED, Main_I keeps p_log = 6-A > -A and the closure check must FAIL. If it still passes, the check is blind and the run exits 2 rather than reporting a decision. C5 the measured cross-check (read, not recomputed): T_I^low/x measured in #1362 at 2^14, 2^16, 2^18 and 2^20 is plotted against the two shapes (4.1) allows at reachable x. WHAT IS DELIBERATELY NOT CLAIMED. The tabulation decides the STRUCTURAL question (do the exponents close at the target with the note's substitutions) and computes thresholds MODULO the implicit constants, which are taken as 1. The note states its constants are INEFFECTIVE (Siegel through (BV*) and the uniform Mobius mean (3a.9)), so no explicit x_0 exists on the record at all: every threshold printed here is a LOWER bound on the true one, and its only role is to show the SHAPE of the requirement. Nothing here estimates B, the flip sum, or any asymptotic quantity. EXIT CODES: 0 the budget closes and the control fired; 2 the control did NOT fire (blind check) or a term does not close; 3 could not look. """ import argparse import json import math import os import sys from fractions import Fraction as F TARGET = "x log^{-A} x" # what every term must reach (the note's own conclusion) # ---------------------------------------------------------------- the table (section 4.1, verbatim) # form: ("power", sigma, r) -> x^sigma * log(x)^r (r may be 0) # ("xlog", p) -> x * log(x)^p # ("xloglog2", p) -> x * log(x)^p * (log log x)^2 # ("xloglog", p, q) -> x * log(x)^p * (log log x)^q def table(A, eps, L, A1, A3, main_A): """The terms of steps 1-7 with their exponents under the given assignment.""" return [ # step 1: the power-of-two atom. Sharp form x^{3d+eps/3} log x (d=1/100); the note states # the cruder O(x^{1/4}), which is what is carried here. ("atom E_2 (step 1)", "power", F(1, 4), F(1), F(0), "note step 1: 'with delta=1/100 this is O(x^(1/4))'; sharper x^(3d+eps/3) log x"), # step 1a: the two g-tails, (4.2'') ("g-tail x log^12/G (4.2'')", "xlog", F(12) - L, F(0), F(0), "G=(log x)^L"), ("power tail x^{1/2-eps/3} log^4 (4.2'') and (4.8)", "power", F(1, 2) - F(eps, 3), F(4), F(0), "e_0UVG level"), # step 3a: the density tail (4.4') ("density tail (4.4')", "xloglog2", F(11) - L, F(0), F(2), "log^11 x (log log x)^2 / G"), # step 4: the main term (4.6) -- the note re-runs it with A+6 in place of A ("Main_I (4.6)", "xlog", F(6) - main_A, F(0), F(0), "A+6 in place of A (step 7); without the re-run this term is 6-A"), # step 5: the BV error (4.7) -- tau(q)^8/phi(q) << log^256 x, D(q) <= 4x log x/phi(q) ("BV error (4.7)", "xlog", 1 + (F(257) - A1) / 2, F(0), F(0), "1+(257-A_1)/2"), # step 6: (4.8) ("E_P (4.8)", "xlog", F(5) - A3, F(0), F(0), "A_3 = A+5"), ] def log_exponent(term, A): """The coefficient of log x in T = x * (log x)^p * ... , as a Fraction.""" _, form, a, b, c, _ = term if form == "xlog": return a if form == "xloglog2": return a # the (log log)^2 factor is not a power of log x if form == "power": return None # T = x^sigma log^r x: not of the x log^p shape raise AssertionError(form) def closes(term, A, eps): """Does this term reach x log^{-A} x (or better)?""" name, form, a, b, c, _ = term if form == "xlog": return a <= -A, "log-exponent %s vs target %s" % (a, -A) if form == "xloglog2": # x log^{11-L} (log log)^2 <= x log^{-A} x iff (log log x)^2 <= log^{L+11+A}... # L = A+13 puts it at log^{-(A+2)} * (log log)^2, which is <= log^{-A} once log x >= log log x. ok = (a <= -A - 1) return ok, "log-exponent %s plus (log log)^2 <= log^2 x" % a if form == "power": # x^sigma log^r x <= x log^{-A} x requires sigma < 1 (then the log factor is irrelevant) return a < 1, "x-power %s (r=%s); needs sigma<1 and log^r x <= log^{A+1}x" % (a, b) raise AssertionError(form) def threshold(term, c0, logx_hi=1e9): """Smallest y = log x with T(x) <= c0 * x, implicit constant 1 (a LOWER bound on the truth).""" name, form, a, b, c, _ = term if form == "xlog": p = float(a) if p >= 0: return None if p == 0 and 1.0 > c0 else None return math.log(1.0 / c0) / (-p) if form == "xloglog2": p = float(a) if p >= 0: return None # x log^p x (log log x)^2 <= c0 x : log^p x * (log log x)^2 <= c0 lo, hi = 2.0, logx_hi for _ in range(200): mid = 0.5 * (lo + hi) val = mid ** p * math.log(mid) ** 2 if val > c0: lo = mid else: hi = mid return 0.5 * (lo + hi) if form == "power": s = float(a) r = float(b) if s >= 1: return None # x^{s-1} log^r x <= c0 -> solve for y = log x : (s-1) y + r log y = log c0 lo, hi = 1e-9, logx_hi for _ in range(300): mid = 0.5 * (lo + hi) val = (s - 1) * mid + r * math.log(mid) if val > math.log(c0): lo = mid else: hi = mid return 0.5 * (lo + hi) raise AssertionError(form) def level_threshold(A, eps, L, B_bv, logx_hi=1e12): """(BV*) level condition: Q_0' = x^{1/2-eps/3}(log x)^L must satisfy Q_0' <= x^{1/2} log^{-B}x, i.e. (log x)^{L+B} <= x^{eps/3}. Solve for y = log x.""" need = float(L) + float(B_bv) lo, hi = 2.0, logx_hi for _ in range(400): mid = 0.5 * (lo + hi) if need * math.log(mid) > (float(eps) / 3.0) * mid: lo = mid else: hi = mid return 0.5 * (lo + hi) def fmt(y): """A log-scale length as a decimal power of ten, for readability.""" return "10^%.1f" % (y / math.log(10)) def c5_measured(path, eps): """C5 -- the measured cross-check. Read the recorded T_I^low/x from #1362's artifact. (4.1) bounds T_I^low by x log^{-A} x, and x log^{-A} x <= x for every A >= 0. So EVERY scale at which T_I^low/x > 1 witnesses a violation of the bound at its own x, at every A, even with the implicit constant taken as 1 -- which is exactly what an astronomically large threshold predicts. Returns the per-scale violation factors; a scale with factor <= 1 would be an inconsistency. """ if not os.path.exists(path): return {"available": False, "path": path} with open(path, encoding="utf-8") as fh: src = json.load(fh) rows, worst, best = [], None, None for r in src.get("rows", []): x = float(r["x"]) ratio = float(r["T_I_over_x"]) lg = math.log(x) per_A = {} for A in (0, 1, 2, 4, 8, 16): bound = r["T_I_over_x"] / (1.0 if A == 0 else lg ** (-A)) per_A[str(A)] = round(bound, 4) rows.append({"j": r["j"], "x": int(x), "T_I_over_x": round(ratio, 6), "violation_factor_at_C=1": per_A}) v = per_A["1"] worst = v if worst is None else max(worst, v) best = v if best is None else min(best, v) return {"available": True, "path": path, "rows": rows, "all_scales_violate": bool(best and best > 1.0), "min_violation_factor_A1": best, "max_violation_factor_A1": worst, "reading": ("every recorded scale has T_I^low/x > 1, so (4.1) is violated at every " "reachable x for every A even with implicit constant 1: consistent with a " "threshold at 10^11991 or beyond, and it means no reachable scale can " "witness the bound")} def markdown_table(rows): """A printable tabulation: step, term, its shape, and the log-exponent at each A.""" As = [r["A"] for r in rows] out = ["| step / term | shape | " + " | ".join("A=%d" % A for A in As) + " | note's constant |", "|---|---|" + "---|" * len(As) + "---|"] names = [d["term"] for d in rows[0]["per_term"]] for i, nm in enumerate(names): t0 = rows[0]["per_term"][i] cells = [] for r in rows: d = r["per_term"][i] cells.append("%s%s" % (d["log_exponent"], "" if d["closes"] else " **CLOSES=FALSE**")) out.append("| %s | %s | %s | %s |" % (nm, t0["why"].split(";")[0], " | ".join(cells), t0["note"])) return "\n".join(out) def main(): here = os.path.dirname(os.path.abspath(__file__)) ap = argparse.ArgumentParser() ap.add_argument("--out", default=os.path.join(here, "error-budget.json")) ap.add_argument("--measured", default=os.path.join(here, "..", "job2562", "bsum-measure.json"), help="#1362's artifact, read only for the C5 cross-check") ap.add_argument("--eps", default="0.016666666666666666") # 1/60, the note's validator choice ap.add_argument("--A", default="1,2,4,8,16") ap.add_argument("--c0", default="0.005,0.25") # 1/200 (direct consumer) and 1/4 ap.add_argument("--B-bv", default="same-as-A,4A+12", help="(BV*) log-power precision B: 'same-as-A' means B=A; '4A+12' is a cited " "published choice for a quantitative Vaughan+large-sieve treatment " "(Anderson 2026 preprints, e.g. 'choose B = 4A+12'); comma-separated") a = ap.parse_args() eps = F(a.eps).limit_denominator(1000) As = [int(x) for x in a.A.split(",")] c0s = [float(x) for x in a.c0.split(",")] def bv_choices(A): """The (BV*) precision B as a function of A, for each requested convention.""" out = {} for spec in a.B_bv.split(","): spec = spec.strip() if spec in ("same-as-A", "A"): out["B=A"] = F(A) continue import re as _re m = _re.fullmatch(r"(\d+)A\+(\d+)", spec) if m: out[spec] = F(int(m.group(1)) * A + int(m.group(2))) continue if _re.fullmatch(r"\d+", spec): out["B=%s" % spec] = F(int(spec)) continue raise SystemExit("unparsable --B-bv entry: %r" % spec) return out rows, out = [], {} for A in As: L, A1, A3 = F(A + 13), F(2 * A + 260), F(A + 5) main_A = F(A + 6) # step 7's re-run of (4.6) bvs = bv_choices(A) terms = table(A, eps, L, A1, A3, main_A) # ---- control: the same table WITHOUT the "(4.6) with A+6" re-run ------------------- terms_blind = table(A, eps, L, A1, A3, A) # main_A = A instead of A+6 # ---- C1/C2: does every term close at the target? ----------------------------------- detail = [] for t in terms: ok, why = closes(t, A, eps) p = log_exponent(t, A) detail.append({"term": t[0], "closes": bool(ok), "log_exponent": (None if p is None else str(p)), "why": why, "note": t[5]}) all_close = all(d["closes"] for d in detail) blind_close = all(closes(t, A, eps)[0] for t in terms_blind) control_ok = (not blind_close) and all_close # the blind table must NOT close # ---- C3: thresholds, per c_0 ------------------------------------------------------- thr, bind, x0 = {}, {}, {} for c0 in c0s: for bk, B_bv in bvs.items(): per = {} for t in terms: y = threshold(t, c0) per[t[0]] = {"logx": y, "x": (fmt(y) if y else None)} ylev = level_threshold(A, eps, L, B_bv) per["(BV*) level condition"] = {"logx": ylev, "x": fmt(ylev)} maxy = max(v["logx"] for v in per.values() if v["logx"]) key = "c0=%g,%s" % (c0, bk) thr[key] = per x0[key] = fmt(maxy) bind[key] = [k for k, v in per.items() if v["logx"] == maxy] row = {"A": A, "L": A + 13, "A_1": 2 * A + 260, "A_3": A + 5, "main_term_A": A + 6, "all_terms_close": all_close, "control_fired": control_ok, "blind_variant_closes": blind_close, "per_term": detail, "thresholds": thr, "binding": bind, "x0": x0} rows.append(row) c5 = c5_measured(a.measured, eps) # C6 -- the source cross-check: the note's OWN collected line at the end of step 7 prints the # seven exponents it believes it has. Reproduce them from the table. If the substitutions or # any exponent were misread, this fires. (Verbatim from research/fixed-endpoint-discrepancy.md, # step 7: x log^{12}/(log^{A+13}) , x log^{11}(loglog)^2/(log^{A+13}) , x log^{-A} , # x log^{-A-1/2} , x log^{-A} , x^{1/2-eps'/3} log^4 , x^{1/4}.) def c6(rows_in): bad = [] for r in rows_in: A = r["A"] exp = {d["term"]: d["log_exponent"] for d in r["per_term"]} want = {"g-tail x log^12/G (4.2'')": str(F(-A - 1)), "density tail (4.4')": str(F(-A - 2)), "Main_I (4.6)": str(F(-A)), "BV error (4.7)": str(F(2 * (-A) - 1, 2)), "E_P (4.8)": str(F(-A))} for k, v in want.items(): if exp.get(k) != v: bad.append({"A": A, "term": k, "note_prints": v, "table_says": exp.get(k)}) return bad c6_bad = c6(rows) failures = [] if c6_bad: failures.append({"control": "C6 source cross-check", "witness": "my table does not reproduce the note's own step-7 exponents", "detail": c6_bad[:8]}) for r in rows: if not r["control_fired"]: failures.append({"A": r["A"], "control": "C4 blindness check", "witness": {"blind_variant_closes": r["blind_variant_closes"], "all_terms_close": r["all_terms_close"]}}) if not r["all_terms_close"]: failures.append({"A": r["A"], "control": "C2 closure", "witness": [d["term"] for d in r["per_term"] if not d["closes"]]}) if c5.get("available") and not c5.get("all_scales_violate"): failures.append({"control": "C5 measured cross-check", "witness": "a recorded scale does NOT violate (4.1); the tabulation's " "threshold reading would be contradicted"}) out = { "tool": "job2746/error-budget.py", "version": "1.0.0", "target": TARGET, "question": ("can some assignment of A, L, A_1, A_3 bring every term of section 4.1 below " "the O(x) remainder the subtraction B = P_low + P_band - T_I^low needs?"), "substitutions": {"L": "A+13", "A_3": "A+5", "A_1": "2A+260", "(4.6)": "re-run with A+6 in place of A", "(BV*) B": ("run under B=A and under the cited published choice B=4A+12; the " "note states the BV precision but not its size, so B is a " "parameter of this tabulation, not a fact of the note")}, "implicit_constants": ("taken as 1: every threshold below is a LOWER bound on the true one, " "and the note declares its constants INEFFECTIVE (Siegel through " "(BV*) and the uniform Mobius mean (3a.9)), so no explicit x_0 " "exists on the record"), "rows": rows, "failures": failures, "C5_measured_crosscheck": c5, "C6_source_crosscheck": {"ok": not c6_bad, "note_step7_line": ("x log^{12}/(log^{A+13}) + x log^{11}(loglog)^2/" "(log^{A+13}) + x log^{-A} + x log^{-A-1/2} + " "x log^{-A} + x^{1/2-eps'/3} log^4 + x^{1/4}")}, "table_md": markdown_table(rows), "verdict": ("the exponents close at the target for every A tested with the note's own " "substitutions (the budget is not the obstacle); the level condition is the only " "step with a large requirement, and every threshold is ineffective" if not failures else "CONTROL FAILED -- do not read the verdict"), } with open(a.out, "w", encoding="utf-8", newline="\n") as fh: json.dump(out, fh, indent=1, sort_keys=True) for r in rows: for k in sorted(r["x0"]): print("A=%2d L=%2d A_1=%3d closes=%s control_fired=%s x0(%s)>=%s binding=%s" % (r["A"], r["L"], r["A_1"], r["all_terms_close"], r["control_fired"], k, r["x0"][k], ",".join(r["binding"][k])), file=sys.stderr) print(markdown_table(rows)) print("C5: %s" % (c5.get("reading") if c5.get("available") else "recorded artifact not found")) print(json.dumps({"ok": not failures, "artifact": a.out, "failures": failures, "c5_all_scales_violate": c5.get("all_scales_violate")}, indent=1, sort_keys=True)) return 2 if failures else 0 if __name__ == "__main__": sys.exit(main())