"""Verdicts Y1-Y6 of PREREG_extrapolation_gates_2026-09-21.md from sweep_extrap2.json, plus the check that mode 'steps' (A) reproduces sweep_extrap.json bit for bit. python -u analyze_extrap2.py """ from __future__ import annotations import json import math from analyze_extrap import FAMILY, FLAT, fam_sum, h2h, load, sign_p MODES = ("none", "steps", "confirmed", "pattern", "steps+results") NAME = {"none": "no lengthening", "steps": "A", "confirmed": "G1 confirmed", "pattern": "G2 pattern", "steps+results": "G3 steps+results"} def key(r): s = r["spec"] return (s[1], s[2], s[3], s[5], s[6], s[7]) def main(): rows = load("sweep_extrap2.json") old = {r["label"]: r for r in load("sweep_extrap.json")} cha = {r["label"]: r for r in load("sweep_full.json")}["chandrupatla"] cells = {} for r in rows: cells.setdefault(key(r), {})[r["spec"][9]] = r # A reproduces its own earlier sweep? same = diff = 0 for r in rows: if r["spec"][9] in ("none", "steps") and r["label"] in old: o = old[r["label"]] if o["APS"]["per"] == r["APS"]["per"] and o["CHA"]["per"] == r["CHA"]["per"]: same += 1 else: diff += 1 print(f"A and no-lengthening cells identical to sweep_extrap.json: {same} same, {diff} differ\n") prop = cells[("ratio", "derived3", "project", "none", "recent", "distance")] base = prop["none"] print("PROPOSED RULE (tent, 3-point, projection), by mode:") print(f" {'mode':<18} {'APS':>5} {'CHA':>5} {'both':>5} {'flat':>5} Y1 Y2 Y3 Y4 " f"vs Chandrupatla APS (w/t/l, p)") for m in MODES: r = prop[m] fam = [c[m] for k, c in cells.items() if k[2] in FAMILY] viol = sum(x["APS"]["over"] + x["CHA"]["over"] for x in fam) low = sum(1 for x in fam if x["APS"]["solved"] + x["CHA"]["solved"] < 193) y1 = r["CHA"]["total"] < 3220 y2 = r["APS"]["total"] <= 2806 y3 = viol == 0 and low == 0 y4 = fam_sum(r, FLAT) < fam_sum(base, FLAT) w, t, l = h2h(r, cha, "APS") mark = lambda b: "✓" if b else "✗" # noqa: E731 print(f" {NAME[m]:<18} {r['APS']['total']:5d} {r['CHA']['total']:5d} " f"{r['APS']['total'] + r['CHA']['total']:5d} {fam_sum(r, FLAT):5d} " f"{mark(y1) if m != 'none' else '-':>2} {mark(y2) if m != 'none' else '-':>2} " f"{mark(y3):>2} {mark(y4) if m != 'none' else '-':>2} {w}/{t}/{l} p={sign_p(w, l):.2g}" + (" ACCEPTED" if m != "none" and y1 and y2 and y3 else "")) print("\nY6 best cell over both sets, per mode (guarantee family, >= 193 solved):") for m in MODES: cand = [c[m] for k, c in cells.items() if k[2] in FAMILY and c[m]["APS"]["solved"] + c[m]["CHA"]["solved"] >= 193] b = min(cand, key=lambda x: x["APS"]["total"] + x["CHA"]["total"]) print(f" {NAME[m]:<18} {b['label']:<52} {b['APS']['total']}+{b['CHA']['total']}=" f"{b['APS']['total'] + b['CHA']['total']}") print("\nreadings under the projection, APS/CHA by mode:") for rd, k in (("slope", ("slope", "recent", "distance")), ("shape+slope", ("slope", "shape", "distance")), ("dissim+slope", ("slope", "recent", "dissimilar")), ("defect", ("defect", "recent", "distance"))): c = cells[("ratio", "derived3", "project") + k] print(f" {rd:<13} " + " ".join(f"{NAME[m].split()[0]} {c[m]['APS']['total']}/" f"{c[m]['CHA']['total']}" for m in MODES)) if __name__ == "__main__": main()