Files
sim-numerics/analyze_extrap2.py
vvsandClaude Opus 5 68df1d25db Sign tests by product underflowed: FIXED everywhere (branch, not master - the paper is not yet updated). FA * fnew < 0.0 with FA ~ -1e-200, fnew ~ 1e-150 is -0.0 and '-0.0 < 0.0' is False, so on flat functions (x^19) the bracket update moved the wrong end, the root left the bracket and the run still reported convergence - the proposed rule returned 4.9e-9, bisection 3.5e-9, ITP 1.6e-8 with a claimed 1e-12 bracket; the 1e-6 harness scored them solved. Same defect in our bisection, false-position family, Ridders, Brent, ITP and twelve copies in stage scripts, simroot/sim.py and one test; all replaced by _opposite / _same_sign, pinned by test_sign_underflow.
Impact, every sweep regenerated: the paper's key configurations are unchanged to the evaluation (proposed 2806/3220, credit 3568/3020, Chandrupatla, TOMS 748, Brent, bisection); 46 stated numbers move (ITP CHA 2857 -> 2896, ITP oracle 2611 -> 2647, record CHA figures by 14-18, the grid means by ~1%) and one finding weakens: the measured-order exponent of section 7.1 was cheaper in 29 of 60 far cells and 7 of 7 safeguards; with the fix 12 of 61 and 6 of 7, and on the wide-bracket set it now loses in every safeguard and drops 5 problems.

PREREG G1-G3 outcome on the fixed code: G2 (repeating step pattern, period from the data) PASSES Y1-Y4 and is ACCEPTED by the stop rule - proposed rule APS 2806 -> 2782 (below Chandrupatla's 2787), CHA 3220 -> 3169, both 6026 -> 5951, per problem vs Chandrupatla on APS 95/20/38 p = 8e-7. G1 fails Y1/Y2 (its Y3 miss was the sign bug), G3 fails Y2, A fails Y2. Regression 887 pass; the two red tests are the paper-number check (awaiting the paper update) and test_blend (fixed since, copy in stage16).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 12:49:01 +01:00

81 lines
3.6 KiB
Python

"""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()