"""Is the flat regime DETECTABLE from evaluations already paid for? Established by diag_model_order.py and its checks: two thirds of the wide-bracket gap sit on the flat families (fun3-fun6), where Chandrupatla bisects 93-100% of his steps and our step removes 0.41-0.81 halvings of the bracket per evaluation - less than bisection's 1. On an approach |f| ~ K e^m the tangent step lands at e(1 - 1/m): it beats bisection's halving only while 1 - 1/m < 1/2, i.e. m < 2. The 2 is bisection's 1/2 rewritten, not a chosen number. m is what _local_order reads from the three latest evaluations. Question measured here, BEFORE anything is built: does "m >= 2" separate the states of the flat families from the states of the canonical set? _local_order is known to fire falsely (derived3_m: m > 1 on 27.9% of APS steps, excursions to 34.8), so the separation is the whole question. If APS states cross m >= 2 about as often as flat ones, the regime is NOT detectable this way and no gate may be built on it. python -u diag_flat_detectable.py """ from __future__ import annotations from collections import defaultdict from scipy.optimize._tstutils import _APS_TESTS_DICTS, _CHANDRUPATLA_TESTS_DICTS from diag_model_order import ACC, MAXFEV, OURS, XTOL from simroot.pure import _local_order, pure_root FLAT = ("fun3", "fun4", "fun5", "fun6") def states(f, a, b, r): st = {"trace": []} x, _n, conv = pure_root(f, a, b, XTOL, MAXFEV, stats=st, **OURS) if not (conv and abs(float(x) - r) <= ACC): return [] out = [] for s in st["trace"]: if s["xp2"] is None: continue out.append(_local_order(s["x"], s["fx"], s["xp"], s["fp"], s["xp2"], s["fp2"])) return out def main(): groups = defaultdict(list) for d in _APS_TESTS_DICTS: a, b = (float(v) for v in d["bracket"]) f = (lambda ff, aa: lambda t: ff(t, *aa))(d["f"], d.get("args", ())) groups["APS (canonical)"] += states(f, a, b, float(d["root"])) for d in _CHANDRUPATLA_TESTS_DICTS: a, b = (float(v) for v in d["bracket"]) fam = str(d["ID"]).split(".")[0] key = "CHA flat fun3-6" if fam in FLAT else "CHA other" groups[key] += states(d["f"], a, b, float(d["root"])) print(f"{'group':<18} {'states':>7} {'m > 1':>8} {'m >= 2':>8}") shares = {} for k in ("APS (canonical)", "CHA other", "CHA flat fun3-6"): ms = groups[k] n = max(len(ms), 1) gt1 = 100.0 * sum(m > 1.0 for m in ms) / n ge2 = 100.0 * sum(m >= 2.0 for m in ms) / n shares[k] = (len(ms), gt1, ge2) print(f"{k:<18} {len(ms):7d} {gt1:7.1f}% {ge2:7.1f}%") return shares # for verify_article.py if __name__ == "__main__": main()