"""Verdicts X1-X5 of PREREG_extrapolate_in_method_2026-09-21.md from sweep_extrap.json. python -u analyze_extrap.py """ from __future__ import annotations import json import math FLAT = ("fun3", "fun4", "fun5", "fun6") FAMILY = ("project", "safe", "credit") def load(p): with open(p, encoding="utf8") as fh: return json.load(fh) def key(r): s = r["spec"] return (s[1], s[2], s[3], s[5], s[6], s[7]) def fam_sum(r, fams): return sum((n if ok else 200) for pid, (n, ok) in r["CHA"]["per"].items() if pid.split(".")[0] in fams) def sign_p(w, l): k, n = min(w, l), w + l return min(1.0, 2.0 * sum(math.comb(n, i) for i in range(k + 1)) / 2.0 ** n) if n else 1.0 def h2h(a, b, s): w = t = l = 0 for pid, (na, oka) in a[s]["per"].items(): nb, okb = b[s]["per"][pid] if oka and okb: w += na < nb l += na > nb t += na == nb return w, t, l def main(): rows = load("sweep_extrap.json") full = {r["label"]: r for r in load("sweep_full.json")} cha = full["chandrupatla"] pairs = {} for r in rows: pairs.setdefault(key(r), {})[r["spec"][9]] = r readings = {("none", "recent", "distance"): "plain", ("slope", "recent", "distance"): "slope", ("slope", "shape", "distance"): "shape+slope", ("slope", "recent", "dissimilar"): "dissim+slope", ("defect", "recent", "distance"): "defect"} print("tent, three-point, pairs (without A -> with A): APS | CHA | both | flat fun3-6 sum") for (sim, sc, gu, pre, pts, dirn), p in sorted(pairs.items()): if sim != "ratio" or gu not in FAMILY + ("none",): continue a, b = p["none"], p["steps"] rd = readings[(pre, pts, dirn)] print(f" {rd:<13} {gu:<8} {a['APS']['total']:5d}->{b['APS']['total']:<5d} " f"{a['CHA']['total']:5d}->{b['CHA']['total']:<5d} " f"{a['APS']['total'] + a['CHA']['total']:5d}->" f"{b['APS']['total'] + b['CHA']['total']:<5d} " f"{fam_sum(a, FLAT):4d}->{fam_sum(b, FLAT):<4d} " f"solved {b['APS']['solved'] + b['CHA']['solved']} over {b['APS']['over'] + b['CHA']['over']}") prop = pairs[("ratio", "derived3", "project", "none", "recent", "distance")] a, b = prop["none"], prop["steps"] print("\nVERDICTS for the proposed rule (tent, 3-point, projection)") print(f" X1 CHA < 3220: {b['CHA']['total']} -> {'PASS' if b['CHA']['total'] < 3220 else 'FAIL'}") print(f" X2 APS <= 2806: {b['APS']['total']} -> {'PASS' if b['APS']['total'] <= 2806 else 'FAIL'}") fam = [p["steps"] for k, p in pairs.items() if k[2] in FAMILY] viol = sum(r["APS"]["over"] + r["CHA"]["over"] for r in fam) low = [r["label"] for r in fam if r["APS"]["solved"] + r["CHA"]["solved"] < 193] print(f" X3 guarantee family with A: {viol} violations over {len(fam)} cells; " f"cells solving < 193: {len(low)} -> {'PASS' if viol == 0 and not low else 'FAIL'}") fa, fb = fam_sum(a, FLAT), fam_sum(b, FLAT) print(f" X4 flat fun3-6 sum: {fa} -> {fb} -> {'PASS' if fb < fa else 'FAIL'}") best = min((p["steps"] for p in pairs.values() if p["steps"]["spec"][3] in FAMILY and p["steps"]["APS"]["solved"] + p["steps"]["CHA"]["solved"] >= 193), key=lambda r: r["APS"]["total"] + r["CHA"]["total"]) print(f" X5 best pair with A over both sets: {best['label']} " f"{best['APS']['total']}+{best['CHA']['total']}=" f"{best['APS']['total'] + best['CHA']['total']} (reference 5511, Chandrupatla 5228)") for s in ("APS", "CHA"): w, t, l = h2h(b, cha, s) print(f" proposed + A vs Chandrupatla, {s}: {w}/{t}/{l} sign p={sign_p(w, l):.2g} " f"totals {b[s]['total']} vs {cha[s]['total']}") print("\nnine functions, three-point, projection, no readings (without A -> with A), both sets:") for (sim, sc, gu, pre, pts, dirn), p in sorted(pairs.items()): if gu == "project" and pre == "none" and pts == "recent" and dirn == "distance": a2, b2 = p["none"], p["steps"] print(f" {sim:<11} {a2['APS']['total'] + a2['CHA']['total']:6d} -> " f"{b2['APS']['total'] + b2['CHA']['total']:6d}") if __name__ == "__main__": main()