PREREG_defect_contra_flat outcome (smoke, all 199 problems). Goal (below Chandrupatla on both) NOT reached by any cell: best CHA 2537 vs 2441. Best total: defect+flatanalogmem APS 2530 / CHA 2561 = 5091 < Chandrupatla 5228 (first time), C1-C3 hold; ablation: defect earns APS +284 (costs CHA 9), remembered analogy earns CHA +649 (costs APS 7). contra earned without defect (APS 2806 -> 2785, CHA 3220 -> 3198; with the remembered analogy 2792 / 2537, the best CHA), redundant with defect (defect+contra = defect). fun9: 105 -> 81 (Chandrupatla 55). Remaining CHA gap 120: flat +88, fun1 +20, fun9 +26. Server regression x2: 1116 passed, 1 failed = the paper-number check.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
vvs
2026-09-21 15:57:15 +01:00
co-authored by Claude Opus 5
parent 3c92d610d6
commit 3d9287ec2c
6 changed files with 205 additions and 12 deletions
+64
View File
@@ -0,0 +1,64 @@
"""Verdicts of PREREG_defect_contra_flat_2026-09-21 (C1-C4, the goal) from a results file.
python -u analyze_defcontra.py [sweep_defcontra_smoke.json]
"""
from __future__ import annotations
import json
import sys
from analyze_extrap import h2h, sign_p
from where_we_lose import per_family
CH_APS, CH_CHA = 2787, 2441
def main(path="sweep_defcontra_smoke.json"):
rows = json.load(open(path, encoding="utf8"))
cha = {r["label"]: r for r in json.load(open("sweep_full.json", encoding="utf8"))}["chandrupatla"]
cell = {(r["spec"][9], r["spec"][5]): r for r in rows if r["spec"][3] == "project"}
for ext, name in (("none", "proposed rule"), ("pattern", "proposed rule + G2")):
base = cell[(ext, "none")]
b_aps, b_cha = base["APS"]["total"], base["CHA"]["total"]
print(f"\n== {name}: baseline APS {b_aps} CHA {b_cha}")
print(f" {'prestep':<30} {'APS':>5} {'CHA':>5} {'both':>5} C1 C2 C3 goal "
f"vs Chandrupatla APS / CHA (w/t/l)")
best = None
for (e, pre), r in cell.items():
if e != ext:
continue
aps, chv = r["APS"]["total"], r["CHA"]["total"]
c1, c2 = chv < b_cha, aps <= b_aps
c3 = r["APS"]["over"] + r["CHA"]["over"] == 0 and \
r["APS"]["solved"] + r["CHA"]["solved"] >= 193
goal = aps < CH_APS and chv < CH_CHA
wa, ta, la = h2h(r, cha, "APS")
wc, tc, lc = h2h(r, cha, "CHA")
print(f" {pre:<30} {aps:5d} {chv:5d} {aps + chv:5d} "
f"{'✓' if c1 else '✗'} {'✓' if c2 else '✗'} {'✓' if c3 else '✗'} "
f"{'YES' if goal else ' no'} {wa}/{ta}/{la} p={sign_p(wa, la):.2g} | "
f"{wc}/{tc}/{lc}")
if c1 and c2 and c3 and (best is None or aps + chv < best[1]):
best = (pre, aps + chv)
if best is None:
print(" no cell passes C1-C3")
continue
pre = best[0]
print(f" best accepted cell: {pre} (both {best[1]})")
parts = pre.split("+")
r = cell[(ext, pre)]
for p in parts:
rest = "+".join(q for q in parts if q != p) or "none"
if (ext, rest) not in cell:
continue
o = cell[(ext, rest)]
print(f" C4 ablation - remove {p:<14}: APS {o['APS']['total'] - r['APS']['total']:+d}"
f" CHA {o['CHA']['total'] - r['CHA']['total']:+d} (positive = the component earns it)")
a = per_family(r, "CHA")
c = per_family(cha, "CHA")
print(" CHA per family (ours/Chandrupatla): "
+ " ".join(f"{k} {a[k]}/{c[k]}" for k in sorted(c)))
if __name__ == "__main__":
main(*sys.argv[1:2])
+38
View File
@@ -0,0 +1,38 @@
== proposed rule: baseline APS 2806 CHA 3220
prestep APS CHA both C1 C2 C3 goal vs Chandrupatla APS / CHA (w/t/l)
none 2806 3220 6026 ✗ ✓ ✓ no 87/24/42 p=9.2e-05 | 9/5/26
defect 2523 3210 5733 ✓ ✓ ✓ no 86/21/46 p=0.00063 | 7/4/29
contra 2785 3198 5983 ✓ ✓ ✓ no 90/23/40 p=1.4e-05 | 9/5/26
flatanalog 2807 2635 5442 ✓ ✗ ✓ no 87/24/42 p=9.2e-05 | 9/6/25
flatanalogmem 2814 2552 5366 ✓ ✗ ✓ no 87/24/42 p=9.2e-05 | 9/7/24
defect+flatanalog 2526 2624 5150 ✓ ✓ ✓ no 86/20/47 p=0.00091 | 8/4/28
contra+flatanalog 2785 2620 5405 ✓ ✓ ✓ no 90/23/40 p=1.4e-05 | 8/6/26
defect+contra 2523 3210 5733 ✓ ✓ ✓ no 86/21/46 p=0.00063 | 7/4/29
defect+flatanalogmem 2530 2561 5091 ✓ ✓ ✓ no 86/20/47 p=0.00091 | 8/5/27
defect+contra+flatanalog 2526 2624 5150 ✓ ✓ ✓ no 86/20/47 p=0.00091 | 8/4/28
contra+flatanalogmem 2792 2537 5329 ✓ ✓ ✓ no 90/23/40 p=1.4e-05 | 8/7/25
defect+contra+flatanalogmem 2530 2561 5091 ✓ ✓ ✓ no 86/20/47 p=0.00091 | 8/5/27
best accepted cell: defect+flatanalogmem (both 5091)
C4 ablation - remove defect : APS +284 CHA -9 (positive = the component earns it)
C4 ablation - remove flatanalogmem : APS -7 CHA +649 (positive = the component earns it)
CHA per family (ours/Chandrupatla): fun1 123/103 fun2 144/152 fun3 304/305 fun4 315/297 fun5 257/233 fun6 280/233 fun7 1000/1000 fun8 57/63 fun9 81/55
== proposed rule + G2: baseline APS 2782 CHA 3169
prestep APS CHA both C1 C2 C3 goal vs Chandrupatla APS / CHA (w/t/l)
flatanalog 2780 2625 5405 ✓ ✓ ✓ no 95/20/38 p=8.2e-07 | 9/6/25
flatanalogmem 2787 2548 5335 ✓ ✗ ✓ no 95/20/38 p=8.2e-07 | 9/7/24
defect+flatanalog 2583 2622 5205 ✓ ✓ ✓ no 85/20/48 p=0.0017 | 8/3/29
defect+flatanalogmem 2587 2564 5151 ✓ ✓ ✓ no 85/20/48 p=0.0017 | 8/4/28
contra+flatanalog 2766 2625 5391 ✓ ✓ ✓ no 98/18/37 p=1.5e-07 | 8/6/26
defect+contra+flatanalog 2583 2622 5205 ✓ ✓ ✓ no 85/20/48 p=0.0017 | 8/3/29
contra+flatanalogmem 2773 2548 5321 ✓ ✓ ✓ no 98/18/37 p=1.5e-07 | 8/7/25
defect+contra+flatanalogmem 2587 2564 5151 ✓ ✓ ✓ no 85/20/48 p=0.0017 | 8/4/28
defect 2580 3182 5762 ✗ ✓ ✓ no 85/21/47 p=0.0012 | 8/2/30
contra 2766 3173 5939 ✗ ✓ ✓ no 98/18/37 p=1.5e-07 | 9/3/28
defect+contra 2580 3182 5762 ✗ ✓ ✓ no 85/21/47 p=0.0012 | 8/2/30
none 2782 3169 5951 ✗ ✓ ✓ no 95/20/38 p=8.2e-07 | 10/3/27
best accepted cell: defect+flatanalogmem (both 5151)
C4 ablation - remove defect : APS +200 CHA -16 (positive = the component earns it)
C4 ablation - remove flatanalogmem : APS -7 CHA +618 (positive = the component earns it)
CHA per family (ours/Chandrupatla): fun1 123/103 fun2 145/152 fun3 306/305 fun4 315/297 fun5 257/233 fun6 280/233 fun7 1000/1000 fun8 57/63 fun9 81/55
+37 -8
View File
@@ -744,11 +744,25 @@ def pure_root(f, a, b, xtol, maxfev, similarity="ratio", scale="derived",
"{'derived3', 'derived3_cap', 'bracket', 'far'}")
if space not in SPACES:
raise ValueError(f"unknown space {space!r}")
if prestep not in ("none", "progress", "slope", "band", "defect", "simpair", "flat",
# PREREG_defect_contra_flat 2026-09-21: a composite prestep "a+b+c" takes at most one
# component per category - decision {defect}, contradiction {contra}, flat regime
# {flatanalog, flatanalogmem}. A single prestep keeps its old meaning exactly: the
# category variables below then carry the same string the old tests compared.
if "+" in prestep:
parts = prestep.split("+")
cats = ({"defect"}, {"contra"}, {"flatanalog", "flatanalogmem"})
if (len(parts) != len(set(parts)) or any(not any(p in c for c in cats) for p in parts)
or any(sum(p in c for p in parts) > 1 for c in cats)):
raise ValueError(f"unknown composite prestep {prestep!r}")
elif prestep not in ("none", "progress", "slope", "band", "defect", "simpair", "flat",
"flat2", "flatcreep", "flatstick", "flatstickmid", "flatstickexit",
"flatjudge", "flatanalog", "flatanalogmem"):
"flatjudge", "flatanalog", "flatanalogmem", "contra"):
raise ValueError(f"unknown prestep {prestep!r}")
if prestep in ("band", "defect", "simpair") and scale not in (
parts = prestep.split("+")
pre_dec = next((p for p in parts if p in ("band", "defect", "simpair")), "none")
pre_flat = next((p for p in parts if p in ("flatanalog", "flatanalogmem")), "none")
pre_contra = "contra" in parts
if pre_dec != "none" and scale not in (
"derived3", "derived3_cap", "derived3_m", "bracket", "far"):
# the decision reads a TRIPLE; under the two-point scale there is no third point
# to read a configuration from, and reading one from elsewhere would hide that
@@ -964,13 +978,13 @@ def pure_root(f, a, b, xtol, maxfev, similarity="ratio", scale="derived",
if exponent == "order" else None)
z_now = _read_z(abs(fx), sc, exponent, m_loc)
step = None
if prestep in ("band", "defect", "simpair"):
if pre_dec != "none":
# THE DECISION PLACE (PREREG 2026-09-21, slot 2). Same slot as the
# slope gate, a different reading of it: the question is not whether
# the slope has settled but whether the CONFIGURATION deserves the
# model. The triple is the recency triple, so only the reading
# changes against the slope-gate cells.
if _decide_refuse(prestep, S, z_now, x, fx, x_prev, f_prev,
if _decide_refuse(pre_dec, S, z_now, x, fx, x_prev, f_prev,
x_prev2, f_prev2):
step = 0.5 * (A + B) - x
pre_refused += 1
@@ -1019,7 +1033,9 @@ def pure_root(f, a, b, xtol, maxfev, similarity="ratio", scale="derived",
else:
step = 0.5 * (A + B) - x
pre_refused += 1
if step is None and prestep in ("flatanalog", "flatanalogmem"):
if pre_flat != "none":
# PREREG_defect_contra_flat: no "step is None" here - the memory must
# see every state even when the decision place already halves it.
# PREREG_flat_analogy 2026-09-21. A pure power is similar to itself
# under zoom: its configuration RECURS, while a simple root's tends
# to the line. Enter on the unkept promise only when the current
@@ -1033,7 +1049,7 @@ def pure_root(f, a, b, xtol, maxfev, similarity="ratio", scale="derived",
cur = _config3(x, fx, x_prev, f_prev, x_prev2, f_prev2)
flag = (sticky_m is None and last_model and f_prev != 0.0
and fx / f_prev >= 0.25)
if prestep == "flatanalogmem":
if pre_flat == "flatanalogmem":
if _analogous_and_steep(cur, configs):
analogy_seen = True
enter = flag and analogy_seen
@@ -1046,6 +1062,19 @@ def pure_root(f, a, b, xtol, maxfev, similarity="ratio", scale="derived",
if cur is not None:
configs.append(cur)
if sticky_m is not None:
if step is None:
pre_refused += 1
step = 0.5 * (A + B) - x
if step is None and pre_contra and x != x_prev:
# PREREG_defect_contra_flat 2026-09-21 (contra). The bracket says
# which way f must go between its ends; the last two points say which
# way it goes here. Opposite signs: the local picture contradicts
# the bracket (fun9: a near-cancelling end reads the root as close,
# and 17 model steps in a row double |f|), so the model is not
# trusted and this evaluation halves. Two signs compared.
loc = (fx - f_prev) / (x - x_prev)
brk = (FB - FA) / (B - A)
if loc != 0.0 and (loc > 0.0) != (brk > 0.0):
step = 0.5 * (A + B) - x
pre_refused += 1
if step is None and prestep == "flatjudge":
@@ -1168,7 +1197,7 @@ def pure_root(f, a, b, xtol, maxfev, similarity="ratio", scale="derived",
w_before = abs(B - A)
mid_now, lin_mid = 0.5 * (A + B), 0.5 * (FA + FB) # before the bracket moves
fnew = g(x_new)
if (prestep in ("flatstickexit", "flatanalog", "flatanalogmem") and sticky_m is not None
if ((prestep == "flatstickexit" or pre_flat != "none") and sticky_m is not None
and x_new == mid_now
and abs(fnew - lin_mid) < abs(fnew)):
# PREREG_flat_exit 2026-09-21. A midpoint evaluated in the regime is judged
File diff suppressed because one or more lines are too long
+26 -3
View File
@@ -246,6 +246,26 @@ def build_grid_flat(smoke, gate="flat"):
return specs
DEFCONTRA_PRESTEPS = (
"none", "defect", "contra", "flatanalog", "flatanalogmem",
"defect+contra", "defect+flatanalog", "defect+flatanalogmem", "contra+flatanalog",
"contra+flatanalogmem", "defect+contra+flatanalog", "defect+contra+flatanalogmem")
def build_grid_defcontra(smoke):
"""PREREG_defect_contra_flat_2026-09-21: every composite of the decision (defect), the
sign contradiction (contra) and the flat regime (flatanalog / flatanalogmem), on the
proposed rule with and without G2."""
for pre in DEFCONTRA_PRESTEPS[1:]:
x, _n, ok = pure_root(lambda t: t - 1.0, 0.0, 3.0, 1e-10, 100, similarity="ratio",
scale="derived3", guard="project", prestep=pre)
if not (ok and abs(x - 1.0) < 1e-8):
raise SystemExit(f"prestep={pre} preflight FAILED: refusing to report zeros")
guards = ("project", "credit") if smoke else GUARD_MODES
return [("pure", "ratio", "derived3", gu, "x", pre, "recent", "distance", "none", ext)
for gu in guards for ext in ("none", "pattern") for pre in DEFCONTRA_PRESTEPS]
def build_grid_extrap2(smoke):
"""PREREG_extrapolation_gates_2026-09-21: the same cells as build_grid_extrap, every
one in all five modes (none, A, G1, G2, G3)."""
@@ -423,10 +443,12 @@ def main():
judgemode = "--flatjudge" in sys.argv # one similarity judgment at entry and exit
analogmode = "--flatanalog" in sys.argv # entry by analogy with the run's own past
memmode = "--flatanalogmem" in sys.argv # the analogy remembered as a property of the run
dcmode = "--defcontra" in sys.argv # defect x contra x flat regime, composites
combomode = "--combo" in sys.argv # modes A and B together
pointsmode = "--points" in sys.argv # mode A: triple by shape
dirmode = "--direction" in sys.argv # mode B: far end by dissimilarity
specs = (build_grid_flat(smoke, ("flatanalogmem", "flatanalog")) if memmode else
specs = (build_grid_defcontra(smoke) if dcmode else
build_grid_flat(smoke, ("flatanalogmem", "flatanalog")) if memmode else
build_grid_flat(smoke, ("flatanalog", "flatstickexit")) if analogmode else
build_grid_flat(smoke, ("flatjudge", "flatstickexit")) if judgemode else
build_grid_flat(smoke, ("flatstickexit", "flatstickmid")) if exitmode else
@@ -460,8 +482,9 @@ def main():
# the published sweep_full.json is what verify_article.py checks the paper
# against, so the log grid never writes into it
if memmode or analogmode or judgemode or exitmode or stickmode or creepmode or flat2mode or flatmode or ext2mode or extmode or decmode or ordermode or capmode or combomode or pointsmode or dirmode:
base = ("sweep_flatanalogmem" if memmode else
if dcmode or memmode or analogmode or judgemode or exitmode or stickmode or creepmode or flat2mode or flatmode or ext2mode or extmode or decmode or ordermode or capmode or combomode or pointsmode or dirmode:
base = ("sweep_defcontra" if dcmode else
"sweep_flatanalogmem" if memmode else
"sweep_flatanalog" if analogmode else
"sweep_flatjudge" if judgemode else
"sweep_flatexit" if exitmode else
+38
View File
@@ -300,3 +300,41 @@ def test_the_remembered_analogy_spares_simple_roots_and_enters_no_later():
_x, na, _ = pure_root(f, a, b, XTOL, MAXFEV, similarity="ratio", scale="derived3",
guard="project", prestep="flatanalog")
assert nm <= na, (nm, na)
# ---- PREREG_defect_contra_flat_2026-09-21: composite prestep and the sign contradiction ----
@pytest.mark.parametrize("bad", ("defect+defect", "defect+band", "flatanalog+flatanalogmem",
"none+defect", "defect+flat", "contra+slope"))
def test_a_malformed_composite_is_refused(bad):
with pytest.raises(ValueError):
pure_root(lambda t: t - 1.0, 0.0, 3.0, XTOL, MAXFEV, similarity="ratio",
scale="derived3", guard="project", prestep=bad)
@pytest.mark.parametrize("f,a,b", PROBS)
@pytest.mark.parametrize("guard", ("project", "credit"))
@pytest.mark.parametrize("pre", ("contra", "defect+contra", "defect+flatanalogmem",
"defect+contra+flatanalog", "defect+contra+flatanalogmem"))
def test_the_guarantee_holds_with_composites(f, a, b, guard, pre):
x, n, ok = pure_root(f, a, b, XTOL, MAXFEV, similarity="ratio", scale="derived3",
guard=guard, prestep=pre)
assert ok and min(a, b) <= x <= max(a, b)
half = math.ceil(math.log2(abs(b - a) / XTOL))
assert n <= (2 * half + 3 if guard == "project" else half + 4), n
def _fun9(t):
return math.exp(t) - 2.0 - 0.01 / t ** 2 + 0.000002 / t ** 3
def test_contra_is_silent_on_a_line_and_breaks_the_fun9_well():
"""Measured before pinning: fun9.4 ([2e-4, 27]) costs 39 without, 21 with contra."""
st = {}
pure_root(lambda t: 3.0 * t - 1.0, -2.0, 5.0, XTOL, MAXFEV, similarity="ratio",
scale="derived3", guard="project", prestep="contra", stats=st)
assert st["pre_refused"] == 0
_x, n0, _ = pure_root(_fun9, 0.0002, 27.0, XTOL, MAXFEV, similarity="ratio",
scale="derived3", guard="project")
_x, n1, ok = pure_root(_fun9, 0.0002, 27.0, XTOL, MAXFEV, similarity="ratio",
scale="derived3", guard="project", prestep="contra")
assert ok and n1 < n0, (n0, n1)