Flat regime: exit by midpoint similarity (flatstickexit), one judgment at entry and exit (flatjudge), entry by analogy (flatanalog).

PREREG_flat_exit: NOT accepted - APS 2806 -> 3125, CHA 3220 -> 2503 (the exit is earned: APS 6897 without it).
PREREG_flat_judge: NOT accepted (smoke) - APS 3009, CHA 2486: at the model's point f is small by construction, the judgment cannot tell flat from simple there.
PREREG_flat_analogy: ACCEPTED with G2. Entry = unkept promise AND the (xi, phi) configuration nearer to its own past than to the line AND the pair's similarity exponent m >= 2. Projection + G2: APS 2782 -> 2780 (below Chandrupatla 2787, per problem 95/20/38 p=8e-7), CHA 3169 -> 2625, guarantee holds. Without G2: APS 2806 -> 2807 (fails by one call), CHA 2635. Simple roots are spared exactly (cost unchanged); flat families 1823 -> 1238, entry comes late. Goal (below Chandrupatla on both) NOT met: CHA 2625 vs 2441, per problem 9/6/25.
Server regression x2: 1052 passed, 1 failed = the expected paper-number check.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
vvs
2026-09-21 14:55:45 +01:00
co-authored by Claude Opus 5
parent 42bfab4330
commit 1842eb0765
7 changed files with 321 additions and 5 deletions
+109
View File
@@ -158,3 +158,112 @@ def test_an_infinite_end_gives_the_midpoint_not_nan():
safeguard before the loop checked finiteness."""
assert _order_split(0.0, -math.inf, 2.0, 1.0, 3.0) == 1.0
assert _order_split(0.0, -math.inf, 2.0, math.inf, 3.0) == 1.0
# ---- PREREG_flat_exit_2026-09-21: leaving the sticky regime by similarity at the midpoint ----
@pytest.mark.parametrize("f,a,b", PROBS)
@pytest.mark.parametrize("guard", ("project", "credit"))
@pytest.mark.parametrize("ext", ("none", "pattern"))
def test_the_guarantee_holds_with_the_exit(f, a, b, guard, ext):
x, n, ok = pure_root(f, a, b, XTOL, MAXFEV, similarity="ratio", scale="derived3",
guard=guard, prestep="flatstickexit", extrapolate=ext)
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 _exit_stats(f, a, b):
st = {}
pure_root(f, a, b, XTOL, MAXFEV, similarity="ratio", scale="derived3", guard="project",
prestep="flatstickexit", stats=st)
return st.get("stick_entries", 0), st.get("stick_exits", 0)
def test_the_exit_leaves_a_false_entry_and_keeps_a_true_one():
"""Measured before pinning: a simple root that trips the flag (the cubic, exp) leaves
the regime at a midpoint; pure powers, scale-invariant, never do."""
assert _exit_stats(lambda t: 3.0 * t - 1.0, -2.0, 5.0) == (0, 0)
assert _exit_stats(lambda t: t ** 3 - 2.0 * t - 5.0, 1.0, 4.0) == (1, 1)
assert _exit_stats(lambda t: math.exp(t) - 2.0, 0.0, 3.0) == (1, 1)
for f, a, b in ((lambda t: t ** 9, -1.0, 2.0), (lambda t: t ** 19, -10.0, 100.0),
(lambda t: 6.0 * (t - 2.0) ** 5, 0.0, 10.0)):
ent, ex = _exit_stats(f, a, b)
assert ent >= 1 and ex == 0, (ent, ex)
def test_the_exit_does_not_touch_the_other_sticky_modes():
for gate in ("flatstick", "flatstickmid"):
st = {}
pure_root(lambda t: math.exp(t) - 2.0, 0.0, 3.0, XTOL, MAXFEV, similarity="ratio",
scale="derived3", guard="project", prestep=gate, stats=st)
assert st.get("stick_exits", 0) == 0
# ---- PREREG_flat_judge_2026-09-21: one similarity judgment at entry and exit ----
@pytest.mark.parametrize("f,a,b", PROBS)
@pytest.mark.parametrize("guard", ("project", "credit"))
@pytest.mark.parametrize("ext", ("none", "pattern"))
def test_the_guarantee_holds_with_the_judge(f, a, b, guard, ext):
x, n, ok = pure_root(f, a, b, XTOL, MAXFEV, similarity="ratio", scale="derived3",
guard=guard, prestep="flatjudge", extrapolate=ext)
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 test_the_judge_is_silent_on_a_line_and_holds_a_pure_power():
st = {}
pure_root(lambda t: 3.0 * t - 1.0, -2.0, 5.0, XTOL, MAXFEV, similarity="ratio",
scale="derived3", guard="project", prestep="flatjudge", stats=st)
assert st.get("stick_entries", 0) == 0 and st["pre_refused"] == 0
st = {}
pure_root(lambda t: t ** 19, -10.0, 100.0, XTOL, MAXFEV, similarity="ratio",
scale="derived3", guard="project", prestep="flatjudge", stats=st)
assert st.get("stick_entries", 0) >= 1 and st.get("stick_exits", 0) == 0, st
# ---- PREREG_flat_analogy_2026-09-21: entry by analogy with the run's own past ----
from simroot.pure import _analogous_and_steep, _config3 # noqa: E402
@pytest.mark.parametrize("f,a,b", PROBS)
@pytest.mark.parametrize("guard", ("project", "credit"))
@pytest.mark.parametrize("ext", ("none", "pattern"))
def test_the_guarantee_holds_with_the_analogy_entry(f, a, b, guard, ext):
x, n, ok = pure_root(f, a, b, XTOL, MAXFEV, similarity="ratio", scale="derived3",
guard=guard, prestep="flatanalog", extrapolate=ext)
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 test_the_analogy_entry_spares_simple_roots_and_catches_powers():
"""Measured before pinning: the cubic and exp, which trip the single flag, never
enter, and cost exactly what the rule costs without the regime."""
for f, a, b in ((lambda t: 3.0 * t - 1.0, -2.0, 5.0),
(lambda t: t ** 3 - 2.0 * t - 5.0, 1.0, 4.0),
(lambda t: math.exp(t) - 2.0, 0.0, 3.0)):
st = {}
_x, n1, _ = pure_root(f, a, b, XTOL, MAXFEV, similarity="ratio", scale="derived3",
guard="project", prestep="flatanalog", stats=st)
_x, n0, _ = pure_root(f, a, b, XTOL, MAXFEV, similarity="ratio", scale="derived3",
guard="project")
assert st.get("stick_entries", 0) == 0 and n1 == n0
for f, a, b in ((lambda t: t ** 9, -1.0, 2.0), (lambda t: t ** 19, -10.0, 100.0),
(lambda t: 6.0 * (t - 2.0) ** 5, 0.0, 10.0)):
st = {}
pure_root(f, a, b, XTOL, MAXFEV, similarity="ratio", scale="derived3",
guard="project", prestep="flatanalog", stats=st)
assert st.get("stick_entries", 0) >= 1
def test_a_line_is_never_analogous_and_an_exact_power_repeats_with_its_order():
line = [_config3(x, 3 * x, xp, 3 * xp, xp2, 3 * xp2)
for x, xp, xp2 in ((0.1, 0.5, 1.0), (0.05, 0.1, 0.5))]
assert line[0][0] == pytest.approx(line[0][1]) # phi = xi on a line
assert not _analogous_and_steep(line[1], [line[0]])
p = lambda t: t ** 5 # noqa: E731
old = _config3(0.4, p(0.4), 0.8, p(0.8), 1.6, p(1.6))
new = _config3(0.1, p(0.1), 0.2, p(0.2), 0.4, p(0.4)) # the same shape, zoomed by 4
assert new[0] == pytest.approx(old[0]) and new[1] == pytest.approx(old[1])
assert _analogous_and_steep(new, [old])