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
+102 -2
View File
@@ -593,6 +593,41 @@ def _order_split(A, FA, B, FB, m):
return A + t * (B - A)
def _config3(x, fx, xp, fp, xp2, fp2):
"""The dimensionless configuration of the last three points and its two scales
(PREREG_flat_analogy 2026-09-21): xi = where x sits between the earlier two, phi =
where f(x) sits between their values, and |x - xp|, |fx - fp|. A linear f has
phi = xi exactly; a pure power repeats (xi, phi) under zoom. None when undefined."""
if xp2 is None or xp2 == xp or fp2 == fp:
return None
xi = (x - xp) / (xp2 - xp)
phi = (fx - fp) / (fp2 - fp)
if not (math.isfinite(xi) and math.isfinite(phi)):
return None
return xi, phi, abs(x - xp), abs(fx - fp)
def _analogous_and_steep(cur, past):
"""Is the configuration nearer to its own past than to the line phi = xi, and does the
analogous pair scale like a power of order m >= 2? Two ordinal judgments and the
flag's own break-even (1/4 = (1 - 1/2)^2 <-> m = 2); no new constant.
Nearness: Euclidean in the (xi, phi) plane, the line by its perpendicular. Order: the
pair shrank x by L and f by L^m, m = ln(f ratio) / ln(x ratio)."""
if cur is None or not past:
return False
xi, phi = cur[0], cur[1]
best = min(past, key=lambda q: math.hypot(xi - q[0], phi - q[1]))
if not math.hypot(xi - best[0], phi - best[1]) < abs(phi - xi) / math.sqrt(2.0):
return False
if best[2] <= 0.0 or best[3] <= 0.0 or cur[2] <= 0.0 or cur[3] <= 0.0:
return False
lx, lf = cur[2] / best[2], cur[3] / best[3]
if not (math.isfinite(lx) and math.isfinite(lf)) or lx == 1.0 or lf <= 0.0:
return False
return math.log(lf) / math.log(lx) >= 2.0
def _local_order(x2, f2, x1, f1, x0, f0):
"""The local order m of f, from three evaluations and nothing else.
@@ -710,7 +745,8 @@ def pure_root(f, a, b, xtol, maxfev, similarity="ratio", scale="derived",
if space not in SPACES:
raise ValueError(f"unknown space {space!r}")
if prestep not in ("none", "progress", "slope", "band", "defect", "simpair", "flat",
"flat2", "flatcreep", "flatstick", "flatstickmid"):
"flat2", "flatcreep", "flatstick", "flatstickmid", "flatstickexit",
"flatjudge", "flatanalog"):
raise ValueError(f"unknown prestep {prestep!r}")
if prestep in ("band", "defect", "simpair") and scale not in (
"derived3", "derived3_cap", "derived3_m", "bracket", "far"):
@@ -766,6 +802,8 @@ def pure_root(f, a, b, xtol, maxfev, similarity="ratio", scale="derived",
last_model = False # was the step just evaluated the model's own? (flat gate)
unkept_run = 0 # consecutive model steps whose promise failed (flat2)
sticky_m = None # order read at entry to the sticky flat regime (flatstick*)
judged = 0 # flatjudge: +1 the last point looked flat, -1 linear, 0 tie
configs = [] # flatanalog: the run's memory of (xi, phi, |dx|, |df|)
if stats is not None:
stats['forced'] = 0
stats['pre_refused'] = 0
@@ -959,22 +997,58 @@ def pure_root(f, a, b, xtol, maxfev, similarity="ratio", scale="derived",
# late, before the crossing (flat2's failure).
step = 0.5 * (A + B) - x
pre_refused += 1
if step is None and prestep in ("flatstick", "flatstickmid"):
if step is None and prestep in ("flatstick", "flatstickmid",
"flatstickexit"):
# PREREG_flat_stick 2026-09-21. The same entry as "flat", but the
# regime is a property of the root, not of one step: once the
# promise has failed, every later step splits the bracket. The
# single flag replaced one step and the model undershot again.
# flatstick splits where |f| ~ |x-r|^m puts the root, m read from
# the failed promise itself; flatstickmid halves (the ablation).
# flatstickexit halves too, and may LEAVE the regime - see the
# similarity judgment at the midpoint after the evaluation.
if (sticky_m is None and last_model and f_prev != 0.0
and fx / f_prev >= 0.25):
sticky_m = _order_from_promise(fx / f_prev)
if stats is not None:
stats['stick_entries'] = stats.get('stick_entries', 0) + 1
if sticky_m is not None:
if prestep == "flatstick":
step = _order_split(A, FA, B, FB, sticky_m) - x
else:
step = 0.5 * (A + B) - x
pre_refused += 1
if step is None and prestep == "flatanalog":
# 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
# configuration is nearer to its own past than to the line AND the
# analogous pair scales as a power of order >= 2. Every state the
# gate sees joins the memory after it has been judged.
cur = _config3(x, fx, x_prev, f_prev, x_prev2, f_prev2)
if (sticky_m is None and last_model and f_prev != 0.0
and fx / f_prev >= 0.25 and _analogous_and_steep(cur, configs)):
sticky_m = math.inf
if stats is not None:
stats['stick_entries'] = stats.get('stick_entries', 0) + 1
if cur is not None:
configs.append(cur)
if sticky_m is not None:
step = 0.5 * (A + B) - x
pre_refused += 1
if step is None and prestep == "flatjudge":
# PREREG_flat_judge 2026-09-21. Enter only when the unkept promise
# AND the point itself looks flat (judged at its evaluation, below);
# a simple root that trips the flag is usually judged linear there
# and never pays for a midpoint. In the regime every step halves.
if (sticky_m is None and last_model and f_prev != 0.0
and fx / f_prev >= 0.25 and judged > 0):
sticky_m = math.inf
if stats is not None:
stats['stick_entries'] = stats.get('stick_entries', 0) + 1
if sticky_m is not None:
step = 0.5 * (A + B) - x
pre_refused += 1
if step is None and prestep == "flat2" and unkept_run >= 2:
# PREREG_flat_twice 2026-09-21. The same unkept promise as
# "flat" (model step, no crossing, r >= 1/4), but only after it has
@@ -1080,7 +1154,33 @@ def pure_root(f, a, b, xtol, maxfev, similarity="ratio", scale="derived",
# step moved by the safeguard says nothing about the model
last_model = model_target is not None and x_new == model_target
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") 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
# against the two predictions: a simple root (f nearly linear on the
# bracket) puts f(M) at (FA+FB)/2, a flat approach puts it at ~0. More
# like the linear one - the regime is left and the model steps again.
# Ordinal: two distances compared, no threshold; a tie stays.
sticky_m = None
if stats is not None:
stats['stick_exits'] = stats.get('stick_exits', 0) + 1
if prestep == "flatjudge":
# PREREG_flat_judge 2026-09-21. One similarity judgment, made at every new
# point before the bracket moves: is f(x) more like the line through the
# bracket ends (a simple root) or like 0 (a flat approach)? Weighted as
# FA(1-t) + FB t, t in (0,1), so it cannot overflow. At a midpoint it is
# exactly the exit judgment of flatstickexit. Ordinal, no threshold.
t_at = (x_new - A) / (B - A)
lin_at = FA * (1.0 - t_at) + FB * t_at
d_lin, d_flat = abs(fnew - lin_at), abs(fnew)
judged = 1 if d_flat < d_lin else (-1 if d_lin < d_flat else 0)
if sticky_m is not None and x_new == mid_now and judged < 0:
sticky_m = None
if stats is not None:
stats['stick_exits'] = stats.get('stick_exits', 0) + 1
# the run of unkept promises (flat2): x, fx are still the point the step left
if last_model and fx != 0.0 and fnew / fx >= 0.25:
unkept_run += 1