#!/usr/bin/env python3 """Job #2491 ledger: #162's census ladder IS the leading coefficient of #159's Tail-Count Transport inequality. Pure exact integer / Fraction arithmetic on PUBLIC claims. No network, no timings in stdout (gotcha 47: the artifact must stay byte-reproducible). Checks A1 census identity D(T_x) = prod_{3<=q<=x}(q-2) reproduced against #162's three integers and the department's own independent D(T29) (#1178). A2 multiplicativity D(T_p) = (p-2) * D(T_prev(p)) at every prime step. A3 #162 x #159 the factor (p-2) in #159's leading RHS term is exactly the census multiplier for the same fold step. A4 cancellation dividing #159's inequality by D(new) removes (p-2) exactly: ((p-2)N + 2S)/((p-2)D) == N/D + 2S/((p-2)D) for all N,S,D. A5 #159 table column which tile its per-fold D(old) column matches (exact). A6 boundary at theta = G2, N(theta)=0, so the inequality reads N_new(G2) <= 2 * sum_L Q_L(G2). """ import json import os import random from fractions import Fraction ROOT = os.path.dirname(os.path.abspath(__file__)) OUT = os.path.join(ROOT, "ledger2491.log") RES = os.path.join(ROOT, "ledger2491.json") LINES = [] CHECKS = [] def emit(s): LINES.append(s) def check(name, ok, detail): CHECKS.append({"check": name, "pass": bool(ok), "detail": detail}) emit("%-6s %s" % ("PASS" if ok else "FAIL", name)) emit(" %s" % detail) def primes_upto(n): ps = [] for q in range(3, n + 1): if all(q % r for r in range(2, int(q ** 0.5) + 1)): ps.append(q) return ps PRIMES = primes_upto(97) # enough for folds through 97 DPRIME = [3] + primes_upto(97) # ... and for the "previous prime" bookkeeping PRIMES = sorted(set(PRIMES)) def D(x): """Census of the twin-admissible residues mod P_x = prod_{3<=q<=x} q.""" n = 1 for q in primes_upto(x): n *= (q - 2) return n def prev_prime(p): ps = primes_upto(p) return ps[-2] if len(ps) > 1 else None emit("# job #2491 ledger -- census multiplicativity is the transport coefficient") emit("") # ---------------------------------------------------------------- A1 claimed_162 = {29: 214708725, 31: 6226553025, 37: 217929355875} indep_1178 = {29: 214708725} # department's own measured D(T29) A1 = [] for x, v in sorted(claimed_162.items()): A1.append((x, D(x), v, D(x) == v)) A1.append(("23", D(23), 7952175, D(23) == 7952175)) for x, got, want in [(k, g, w) for k, g, w, _ in A1]: pass a1ok = all(ok for *_, ok in A1) check("A1_census_identity", a1ok, "prod_{3<=q<=x}(q-2) == published census: " + "; ".join("T%s %d==%d %s" % (x, g, w, ok) for x, g, w, ok in A1)) emit(" independent second source: return #1178 measured D(T29)=%d (%s)" % (indep_1178[29], D(29) == indep_1178[29])) # ---------------------------------------------------------------- A2 A2 = [] for p in [pp for pp in PRIMES if pp >= 17]: pv = prev_prime(p) A2.append((pv, p, D(p) == (p - 2) * D(pv))) check("A2_multiplicativity", all(ok for *_, ok in A2), "; ".join("D(T%d)/D(T%d)=%d (%s)" % (b, a, b - 2, ok) for a, b, ok in A2)) # ---------------------------------------------------------------- A3 # #159's inequality: N_new(theta) <= (q-2) * N(theta) + 2 * sum_{L>=1} Q_L(theta) # for the fold step into q. Claim: the coefficient (q-2) is exactly D(T_q)/D(T_prev). A3 = [] steps = [(23, 29), (29, 31), (31, 37), (37, 41), (41, 43)] for a, b in steps: A3.append((a, b, D(b) == (b - 2) * D(a), (b - 2))) check("A3_coefficient_is_census_ratio", all(ok for *_, ok in A3), "; ".join("step %d->%d: coeff q-2=%d, D ratio %s" % (a, b, c, ok) for a, b, ok, c in A3)) # ---------------------------------------------------------------- A4 rng = random.Random(2491) A4 = [] for a, b in steps: p = b Dn = (p - 2) * D(a) for _ in range(50): N = rng.randrange(0, D(a) + 1) S = rng.randrange(0, D(a) + 1) lhs = Fraction((p - 2) * N + 2 * S, Dn) rhs = Fraction(N, D(a)) + Fraction(2 * S, Dn) A4.append(lhs == rhs) check("A4_density_form_cancellation", all(A4), "((p-2)N+2S)/((p-2)D_old) == N/D_old + 2S/((p-2)D_old) exactly, " "%d random (N,S) pairs over %d fold steps" % (50 * len(steps), len(steps))) emit(" => the inequality divided by D(new) reads") emit(" N_new/D(new) <= N/D(old) + 2*sum_L Q_L/D(new)") emit(" i.e. the leading term is a DENSITY comparison; (q-2) cancels.") # ---------------------------------------------------------------- A5 # #159 per-fold table (return #159, "## Per fold"), D(old) column, verbatim. table = [(13, 17, 22275), (17, 19, 378675), (19, 23, 7952175), (23, 29, 7952175), (23, 31, 7952175), (23, 37, 7952175), (31, 37, 6226553025), (37, 41, 217929355875)] tagged = [] for a, b, v in table: tagged.append((a, b, v, "D(T%s)" % b if v == D(b) else ("D(T%s)" % a if v == D(a) else "?"))) mis = [t for t in tagged if t[3] == "?"] pre = [t for t in tagged if t[3] == "D(T%d)" % t[0]] post = [t for t in tagged if t[3] == "D(T%d)" % t[1]] check("A5_table_column_names_a_tile", not mis, "all 8 rows match a tile census; %d rows carry the PRE-step tile (%s) and " "%d the POST-step tile (%s) -> the column's side is not uniform" % (len(pre), [(a, b) for a, b, _, _ in pre], len(post), [(a, b) for a, b, _, _ in post])) for a, b, v, tag in tagged: emit(" %2d->%-2d D(col)=%-15d = %s" % (a, b, v, tag)) # ---------------------------------------------------------------- A6 # #159 reports at fold 37->41: N_new = 4 <= 39*0 + 2*4 = 8 at theta = G2 = 546. check("A6_G2_boundary", 4 <= 2 * 4, "#159 fold 41 at theta=G2=546: N_new=4, N(G2)=0, sum_L Q_L(G2)=4, " "so RHS=39*0+2*4=8 and the ratio is 0.5 (the #159 report's own reading)") emit("") emit("margins (max N_new/RHS) from #159, folds into 17,19,23,29,31,37,41:") for q, m in [(17, 0.8881), (19, 0.8975), (23, 0.9180), (29, 0.9324), (37, 0.9477), (41, 0.9551)]: emit(" into %-2d %s (1 - m = %.4f)" % (q, m, 1.0 - m)) emit(" => the deficit 1-m shrinks by ~2/q per step and the trend decelerates;") emit(" in the density form this deficit IS the whole content of the inequality.") payload = { "job": 2491, "checks": CHECKS, "census": {str(x): D(x) for x in [17, 19, 23, 29, 31, 37, 41]}, "table_tagging": [[a, b, v, t] for a, b, v, t in tagged], "all_pass": all(c["pass"] for c in CHECKS), } with open(RES, "w", encoding="utf-8") as f: json.dump(payload, f, indent=1, sort_keys=True) f.write("\n") LINES.append("") LINES.append("all_pass=%s checks=%d/%d" % (payload["all_pass"], sum(c["pass"] for c in CHECKS), len(CHECKS))) with open(OUT, "w", encoding="utf-8") as f: f.write("\n".join(LINES) + "\n") for ln in LINES: print(ln) raise SystemExit(0 if payload["all_pass"] else 1)