#!/usr/bin/env python3 """check.py -- the served gate for job #4209 (rescue, route 89). Run it in the folder it ships in: python check.py # prints C1..C9, then 'N checks, N passed, 0 failed', exit 0 What it checks, and against what: C1/C2 the published-number gates G1 (validator line at x=2^16) and G2 (the census row at 2^20), quoted in the report from return #787 `T-B-census.md` section 2 and from the served `research/fixed-endpoint-discrepancy-validation.js` as printed in section 5 / #787 section 0. C3 G3: the instrument's own ladder at V=32 reproduces return #1831's `ladder2070.jsonl` (sha256 f903591a605dc8117a90c1987f7ff249e6a3ef5cbf0a1f5252b4009a7cfc1af8) exactly after the published 9-decimal rounding, for j=12..22, on members, MT and increments. The published rows used here are the served extract `baseline-1831-extract.jsonl`. C4 every control field of every served run row: mu_violations = 0, c_gather_mismatches = 0, window_resid = "0" (the served validator's three identities, per range). C5 an INDEPENDENT re-derivation at j=12 with no numpy: plain Python enumeration of the same pair set from the definitions (odd squarefree e < e_1, m in I_e, (m,e)=1, m>V, Lambda(em-2)>0) and direct TI_U(m) products, compared with the served rows for V=3 and V=32, both ranges. C6 the pre-registered falsifiers F1..F4 of PREREG-4209.md, recomputed from the served rows, with the verdicts the report states (F1 fires at V=3 only; F2 fires; F3 and F4 do not fire). C7 the allowance arithmetic at the two largest measured scales: the low part's worst increment ratio is 2.2..3.3 (out), the band's is 0.10..0.30 (in, with margin), the contrast at j=24. C8 the new cutoff scan `vscan.jsonl`: the band's worst increment ratio at j=24 is monotone decreasing in V over V=4,8,16,32,64, and the 64 value is the smallest. C9 no row of any served run file is missing the fields the report cites. Nothing here tests an asymptotic statement; every check is finite, and a failure is a failure of this job's own numbers, not of the route's premise. """ import json import math import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) ALLOW = 2.0 / 25.0 EPS = 1.0 / 60.0 fails = [] checks = [0] def load(name): with open(os.path.join(HERE, name), encoding="utf-8") as fh: return [json.loads(line) for line in fh if line.strip()] def ck(name, ok, detail=""): checks[0] += 1 print("%-4s %-4s %s" % (name, "ok" if ok else "FAIL", detail)) if not ok: fails.append(name) def near(a, b, tol): return abs(a - b) <= tol # ---------------------------------------------------------------- C1/C2: published-number gates g16 = load("gate-j16.jsonl")[0] g20 = load("gate-j20.jsonl")[0] ck("C1a", near(g16["low"]["C"]["members_over_x"][-1], 4.4864, 5e-5), "x=2^16, V=U=3: T_I^low/x = %.6f (published 4.4864)" % g16["low"]["C"]["members_over_x"][-1]) ck("C1b", near(g16["low"]["C"]["complement_over_x"][-1], -4.4982, 5e-5), "T_II^low/x = %.6f (published -4.4982)" % g16["low"]["C"]["complement_over_x"][-1]) ck("C1c", near(g16["P_band_over_x"], -0.0295, 5e-5), "P_band/x = %.6f (published -0.0295)" % g16["P_band_over_x"]) ck("C1d", near(g16["D_over_x"], -0.0231, 5e-5), "D^(e_1)/x = %.6f (published -0.0231)" % g16["D_over_x"]) ck("C2a", near(g20["low"]["C"]["members_over_x"][-1], 6.6850, 5e-5), "x=2^20, V=U=3: T_I^low/x = %.6f (census 6.6850)" % g20["low"]["C"]["members_over_x"][-1]) ck("C2b", near(g20["low"]["C"]["complement_over_x"][-1], -6.6905, 5e-5), "T_II^low/x = %.6f (census -6.6905)" % g20["low"]["C"]["complement_over_x"][-1]) ck("C2c", near(g20["P_band_over_x"], -0.0083, 5e-5), "P_band/x = %.6f (census -0.0083)" % g20["P_band_over_x"]) ck("C2d", near(g20["invariant_over_x"], -0.0139, 5e-5), "P(1,e_1)/x = %.6f (census -0.0139)" % g20["invariant_over_x"]) # ---------------------------------------------------------------- C3: the route's own ladder (G3) base = {r["j"]: r for r in load("baseline-1831-extract.jsonl")} mine = {r["j"]: r for r in load("ladder-V32.jsonl")} worst, cells, bad = 0.0, 0, 0 for j, b in sorted(base.items()): m = mine[j] for key, src, dst in (("members_over_x", b, m["low"]["C"]), ("MT_over_x", b, m), ("increments_over_x", b, m["low"]["C"])): for a_, b_ in zip(src[key], dst[key]): cells += 1 worst = max(worst, abs(a_ - b_)) if round(b_, 9) != round(a_, 9): bad += 1 ck("C3", bad == 0 and cells == 11 * (6 + 6 + 5), "G3 j=12..22 V=32: %d cells, %d mismatched after 9-decimal rounding, max |diff| = %.2e" % (cells, bad, worst)) # ---------------------------------------------------------------- C4: the served controls rows = [] for f in ("family-V32.jsonl", "family-V3.jsonl", "ladder-V32.jsonl", "vscan.jsonl", "gate-j16.jsonl", "gate-j20.jsonl"): for r in load(f): r["_file"] = f rows.append(r) bad = [r for r in rows if r["mu_violations"] != 0 or r["c_gather_mismatches"] != 0 or str(r["window_resid"]) != "0"] ck("C4", not bad, "%d run rows; %d with a failing control (mu_violations, c_gather, window_resid)" % (len(rows), len(bad))) # ---------------------------------------------------------------- C5: independent re-derivation def small_sieve(n): mu = [1] * (n + 1) mu[0] = 0 lam = [0.0] * (n + 1) comp = [False] * (n + 1) for p in range(2, n + 1): if not comp[p]: for m in range(p, n + 1, p): mu[m] = -mu[m] for m in range(p * p, n + 1, p): comp[m] = True for m in range(p * p, n + 1, p * p): mu[m] = 0 pk = p while pk <= n: lam[pk] = math.log(p) pk *= p return mu, lam def brute(j, V): x = 1 << j mu, lam = small_sieve(x) e1 = int(math.floor(x ** (0.5 + EPS))) e0 = int(math.floor(x ** (0.5 - EPS))) g = [sum(mu[k] for k in range(1, V + 1) if b % k == 0) for b in range(x + 1)] ti = {} for U in (1, 2, 4): if U > V: continue ti[U] = [None] * (x + 1) for m in range(1, x + 1): s = 0.0 for d in range(1, U + 1): if mu[d]: s += mu[d] * g[m // d] ti[U][m] = s tot = {"low": 0.0, "band": 0.0} for e in range(1, e1): if e % 2 == 0 or mu[e] == 0: continue lo, hi = x // (2 * e), x // e for m in range(max(lo + 1, V + 1), hi + 1): if lam[e * m - 2] > 0 and math.gcd(m, e) == 1: w = math.log(m) * lam[e * m - 2] key = "low" if e < e0 else "band" tot[key] += w * ti[1][m] return {"low": tot["low"] / x, "band": tot["band"] / x} rows12 = {r["V"]: r for r in load("family-V32.jsonl") + load("family-V3.jsonl") if r["j"] == 12} worst = 0.0 for V, which in ((3, "partial"), (32, "partial")): b = brute(12, V) for part in ("low", "band"): d = abs(b[part] - rows12[V][part]["C"]["members_over_x"][0]) worst = max(worst, d) ck("C5", worst < 1e-9, "independent j=12 enumeration (no numpy, U=1 member) reproduces the served rows to %.2e" % worst) # ---------------------------------------------------------------- C6: pre-registered falsifiers fam32 = {r["j"]: r for r in load("family-V32.jsonl")} fam3 = {r["j"]: r for r in load("family-V3.jsonl")} big2 = sorted(fam32)[-2:] big3 = sorted(fam3)[-2:] f1_3 = all(max(abs(v) for v in fam3[j]["band"]["C"]["members_over_x"]) > 0.08 for j in big3) f1_32 = all(max(abs(v) for v in fam32[j]["band"]["C"]["members_over_x"]) > 0.08 for j in big2) ck("C6a", f1_3 and not f1_32, "F1 (band member above the allowance at both largest scales): fires at V=3 (%s), not at V=32 (%s)" % (["%.3f" % max(abs(v) for v in fam3[j]["band"]["C"]["members_over_x"]) for j in big3], ["%.4f" % max(abs(v) for v in fam32[j]["band"]["C"]["members_over_x"]) for j in big2])) jlo, jhi = min(fam32), max(fam32) growth = [] for i in range(len(fam32[jlo]["band"]["C"]["members_over_x"])): a = abs(fam32[jlo]["band"]["C"]["members_over_x"][i]) b = abs(fam32[jhi]["band"]["C"]["members_over_x"][i]) growth.append(b / a if a else float("inf")) f2 = sum(1 for g in growth if g >= 3.0) ck("C6b", f2 == len(growth), "F2 (band member grows >= 3x from j=%d to j=%d at fixed U): fires at %d of %d U values, factors %s" % (jlo, jhi, f2, len(growth), ["%.1f" % g for g in growth])) f3 = [] for j in big2: r = fam32[j]["band"]["C"] ref = fam32[j]["band"]["Cref"] f3.append(abs(ref["Vx"] - r["Vx"]) / r["Vx"]) ck("C6c", max(f3) < 1.0, "F3 (chain refinement changes Vx_band by more than 2x): does not fire, worst change %.1f%% at j=%s" % (100 * max(f3), big2[list(f3).index(max(f3))])) cells = big = 0 for j in sorted(fam32): lo = fam32[j]["low"]["C"]["members_over_x"] ba = fam32[j]["band"]["C"]["members_over_x"] for i in range(len(lo)): cells += 1 if abs(ba[i]) >= abs(lo[i]): big += 1 ck("C6d", big * 2 < cells, "F4 (band at least as large as low in a majority of cells): does not fire; band < low in %d of %d " "cells of the V=32 ladder" % (cells - big, cells)) # ---------------------------------------------------------------- C7: allowance arithmetic for j in big2: lr = fam32[j]["low"]["C"]["allowance_ratio"] br = fam32[j]["band"]["C"]["allowance_ratio"] if not (2.2 <= lr <= 3.3 and 0.10 <= br <= 0.30): ck("C7", False, "j=%d ratios out of the reported ranges (low %.3f, band %.3f)" % (j, lr, br)) break else: ck("C7", True, "j=%s: low worst increment = %.3fx the 0.08x allowance, band = %.3fx (margin %.1fx)" % (big2, fam32[max(big2)]["low"]["C"]["allowance_ratio"], fam32[max(big2)]["band"]["C"]["allowance_ratio"], 1.0 / fam32[max(big2)]["band"]["C"]["allowance_ratio"])) # ---------------------------------------------------------------- C8: the cutoff scan sc = {} for r in load("vscan.jsonl"): if r["j"] == 24: sc[r["V"]] = r["band"]["C"]["allowance_ratio"] seq = [sc[v] for v in (4, 8, 16, 32, 64)] ck("C8", all(seq[i] > seq[i + 1] for i in range(len(seq) - 1)), "band worst-increment ratio at j=24 vs V=4,8,16,32,64: %s (monotone decreasing)" % ["%.3f" % v for v in seq]) # ---------------------------------------------------------------- C9: fields the report cites need = ("low", "band", "P_low_over_x", "P_band_over_x", "invariant_over_x", "pairs_low", "pairs_band", "e0", "e1", "chain") missing = [r["_file"] for r in rows if any(k not in r for k in need)] missing += ["MT_over_x (%s, V=%d)" % (r["_file"], r["V"]) for r in rows if r["V"] >= 2 and "MT_over_x" not in r] ck("C9", not missing, "%d run rows carry every field the report cites (MT_over_x absent only at V < 2, where #1831's " "main term is undefined)" % len(rows)) print() print("%d checks, %d passed, %d failed" % (checks[0], checks[0] - len(fails), len(fails))) sys.exit(1 if fails else 0)