#!/usr/bin/env python3 """Control for split_census.py: certify the port against BOTH lanes' published values. Two independent anchors, neither of them mine: (A) the served validator research/fixed-endpoint-discrepancy-validation.js, whose embedded OUTPUT line at x=2^16, U=V=3 reads T_I^low/x=4.4864, T_II^low/x=-4.4982, P_band/x=-0.0295, D^(e1)/x=-0.0231 (sha256 edd9d46975b651dcde3a06cfea69b0812c40e9e1ffa2a677e559e1f8489b72c3); (B) return #165's published MAIN TABLE row at j=16: M/x = 0.014472, D_y/x = -0.016647 (the moving-cutoff center of moving-cutoff-parity.md (9)), with rows j=16..20 used for the cross-parameterization comparison. Exit 0 only if every assertion holds. Any disagreement is a finding about the PORT, not about the notes. """ import json import math import sys import split_census as sc X16 = 2 ** 16 OK = [] def check(cond, tag, detail=""): OK.append((bool(cond), tag, detail)) if not cond: print("FAIL %-34s %s" % (tag, detail)) # ---- (A) reproduce the served validator's own printed line, in Python ---- r = sc.measure(X16, 3, 3) served = {"tI_over_x": 4.4864, "tII_over_x": -4.4982, "Pband_over_x": -0.0295, "Dall_over_x": -0.0231} for k, v in served.items(): check(abs(round(r[k], 4) - v) < 1e-12, "served_line:" + k, "port=%.4f served=%.4f" % (r[k], v)) # ---- (B) the two lanes' M agree: the served validator's M and #165's published M/x ---- check(abs(r["M_over_x"] - 0.014471617101367918) < 1e-12, "M_matches_served_validator", "port=%.12f" % r["M_over_x"]) check(abs(round(r["M_over_x"], 6) - 0.014472) < 1e-12, "M_matches_return_165_published", "port=%.6f published=0.014472" % r["M_over_x"]) # ---- (C) the two parameterizations of the SAME margin at the same x ---- # #165 published, MAIN TABLE (measure lane, moving cutoff y=ceil(x^(12/25))). pub_Dy = {16: -0.016647, 17: -0.039617, 18: -0.030072, 19: -0.003985, 20: -0.014966} rows = {} for j in sorted(pub_Dy): rows[j] = sc.measure(2 ** j, 3, 3) d = rows[j]["Dall_over_x"] - pub_Dy[j] print("j=%d D^(e1)/x=%.6f D_y/x(published)=%.6f difference/x=%.6f (%.1f%% of the 4/25 target)" % (j, rows[j]["Dall_over_x"], pub_Dy[j], d, 100 * abs(d) / 0.16)) gaps = [abs(rows[j]["Dall_over_x"] - pub_Dy[j]) for j in sorted(pub_Dy)] check(max(gaps) > 1e-3, "two_centers_differ_at_reachable_x", "max |difference|/x = %.6f" % max(gaps)) # ---- (D) the cutoff-invariance and the non-stability of the pieces ---- vals = [sc.measure(X16, U, U)["tI_over_x"] for U in (2, 3, 5, 8, 10)] plow = [sc.measure(X16, U, U)["Plow_over_x"] for U in (2, 3, 5, 8, 10)] spread = max(vals) / min(vals) check(spread > 4, "pieces_not_cutoff_stable", "|tI|/x spans %.4f..%.4f (x%.2f)" % (min(vals), max(vals), spread)) check(max(plow) - min(plow) < 1e-6, "sum_is_cutoff_invariant", "P_low/x spans %.9f..%.9f" % (min(plow), max(plow))) # ---- (E) the note's own cutoff rule is degenerate on the whole computed range ---- first_j = min(j for j in range(2, 400) if int(math.floor((2 ** j) ** (sc.EPS / 3.0))) >= 2) check(first_j == 180, "note_cutoff_U_1_below_2_pow_180", "first j with U>=2 is %d" % first_j) eps_needed = 3 * math.log(3) / math.log(X16) check(0 < eps_needed < 0.5, "validator_cutoff_needs_other_eps", "U=V=3 at x=2^16 needs eps'=%.4f while the split uses eps'=%.5f" % (eps_needed, sc.EPS)) out = {"checks": [{"tag": t, "ok": o, "detail": d} for (o, t, d) in OK], "cross_parameterization_difference_over_x": {str(j): rows[j]["Dall_over_x"] - pub_Dy[j] for j in sorted(pub_Dy)}, "piece_spread_at_2_16": {"tI_over_x": vals, "Plow_over_x": plow}} with open("port-control.json", "w", encoding="utf-8", newline="\n") as fh: json.dump(out, fh, indent=1, sort_keys=True) bad = [t for (o, t, _) in OK if not o] print("checks: %d, failed: %d %s" % (len(OK), len(bad), bad if bad else "")) sys.exit(1 if bad else 0)