S-ablation of A' (server): A' with each of the nine similarity functions in the step - tent 4443 on the paper protocol (13032 over 855 problems), the nearest other function e^-|z| 4988 (+12%; +9% over six corpora), quadratic ones 18410-18422 (+315%); ranking as the contraction law predicts; guarantee held with every S. The audit of section 7 rerun on the regenerated sweeps (APS unchanged: triple by shape -493 with the tent, +250 with 1/sqrt(1+z^2); defect -283 vs +215). Text: abstract and section 3 no longer call the similarity scaffolding - the tent making the step Newton's is a property of the similarity chosen; a paragraph in section 7 on the audit; Table 9a; new 8.6 'What is known, and what is new' - Lagouanelle (the order estimate of 7.1 / 10.5), Rall and Hansen-Patrick (8.1), the log-log slope / COC / ACOC (8.2, formula 6), Schroeder and Traub (the split 7 = false position on sign(f)|f|^(1/m)), Brent's acceptance condition (half), Dekker/Brent (tolerance step); what we found no counterpart for is the decision layer by similarity and analogy and the step set by a similarity whose form is decisive. References 13-19. verify_article: Table 9a, the percentages and the audit numbers added; server 446 OK, 0 BAD; regression x2 1226 passed, 0 failed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
841 lines
43 KiB
Python
841 lines
43 KiB
Python
"""Check every number the paper states against sweep_full.json.
|
|
|
|
A paper is a claim about data; transcribing its tables by hand is how a claim
|
|
stops matching its data. A failure here means the paper is wrong, not the
|
|
test.
|
|
|
|
PROPOSED/PROJ below is the BASE rule of section 3: the scheduled projection with its
|
|
multiplier DECLARED as the one free constant (Valeri, 2026-09-21, variant a); the method
|
|
the paper now proposes, A', is checked in verify_flat_regime_and_oos(); the earned projection
|
|
(credit) is the constant-free variant. Both are checked. Baselines are the
|
|
library alone since 2026-09-21: Chandrupatla = scipy elementwise.find_root,
|
|
Brent = brentq.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
from report_sweep import CREDIT, PROPOSED, head_to_head, place, rank
|
|
|
|
FAILS = []
|
|
PROJ = "pure.ratio.derived3.project"
|
|
assert PROPOSED == PROJ, "the paper proposes the projection (variant a)"
|
|
|
|
|
|
def check(label, got, want):
|
|
ok = got == want
|
|
print(f" {'OK ' if ok else 'BAD'} {label:58s} got {got!r:>16} "
|
|
f"want {want!r}")
|
|
if not ok:
|
|
FAILS.append(label)
|
|
|
|
|
|
def row(rows, setname, lbl):
|
|
return next(r for r in rows if r["label"] == lbl)[setname]
|
|
|
|
|
|
def main():
|
|
with open("sweep_full.json", encoding="utf8") as fh:
|
|
rows = json.load(fh)
|
|
|
|
# Guard against quoting places from a field that is missing a competitor.
|
|
# It has already happened once: before Chandrupatla's own method was
|
|
# added, every ranking assertion here passed only because the method that
|
|
# beats us was absent.
|
|
labels = {r["label"] for r in rows}
|
|
missing = {"chandrupatla", "dekker", PROPOSED} - labels
|
|
if missing:
|
|
print(f" !! THE SWEEP IS STALE: missing {sorted(missing)}. "
|
|
"Re-run sweep_full.py.\n")
|
|
FAILS.append("sweep is stale")
|
|
|
|
check("number of configurations", len(rows), 264)
|
|
|
|
# ---- the proposed method: projection, one declared constant ----------
|
|
print("\nThe proposed method (projection, multiplier declared):")
|
|
for setname, pl, tot, sol in (("APS", 3, 2806, 153),
|
|
("CHA", 45, 3220, 40)):
|
|
d = row(rows, setname, PROPOSED)
|
|
check(f"{setname} place", place(rows, setname, PROPOSED), pl)
|
|
check(f"{setname} total", d["total"], tot)
|
|
check(f"{setname} solved", d["solved"], sol)
|
|
check("both sets", row(rows, "APS", PROPOSED)["total"]
|
|
+ row(rows, "CHA", PROPOSED)["total"], 6026)
|
|
|
|
print("\nHead to head of the proposed method:")
|
|
for setname, opp, want in [
|
|
("APS", "chandrupatla", (87, 24, 42)),
|
|
("APS", "toms748", (86, 16, 51)),
|
|
("APS", "brent", (102, 11, 40)),
|
|
("APS", "itp", (132, 3, 18)),
|
|
("APS", "itp_oracle", (121, 4, 28)),
|
|
("APS", "bisection", (152, 1, 0)),
|
|
("CHA", "chandrupatla", (9, 5, 26)),
|
|
("CHA", "toms748", (31, 1, 8)),
|
|
("CHA", "brent", (30, 4, 4)),
|
|
("CHA", "itp", (17, 0, 23)),
|
|
("CHA", "itp_oracle", (16, 0, 24))]:
|
|
w, t, l, _ = head_to_head(rows, PROPOSED, opp, setname)
|
|
check(f"{setname} vs {opp}", (w, t, l), want)
|
|
|
|
def sign_p(w, l):
|
|
import math as _m
|
|
k, n = min(w, l), w + l
|
|
return min(1.0, 2.0 * sum(_m.comb(n, i) for i in range(k + 1)) / 2.0 ** n)
|
|
w, _t, l, _ = head_to_head(rows, PROPOSED, "chandrupatla", "APS")
|
|
check("APS vs Chandrupatla sign test p < 1e-4", sign_p(w, l) < 1e-4, True)
|
|
w, _t, l, _ = head_to_head(rows, PROPOSED, "chandrupatla", "CHA")
|
|
check("CHA vs Chandrupatla sign test p (rounded)", round(sign_p(w, l), 3), 0.006)
|
|
|
|
# ---- the constant-free variant ---------------------------------------
|
|
print("\nThe constant-free variant (earned projection):")
|
|
for setname, pl, tot in (("APS", 29, 3568), ("CHA", 10, 3020)):
|
|
check(f"credit {setname} place", place(rows, setname, CREDIT), pl)
|
|
check(f"credit {setname} total", row(rows, setname, CREDIT)["total"], tot)
|
|
check("credit both sets", row(rows, "APS", CREDIT)["total"]
|
|
+ row(rows, "CHA", CREDIT)["total"], 6588)
|
|
check("credit costs 762 more on the canonical set",
|
|
row(rows, "APS", CREDIT)["total"] - row(rows, "APS", PROPOSED)["total"], 762)
|
|
for setname, opp, want in [("APS", "chandrupatla", (79, 3, 71)),
|
|
("APS", "toms748", (77, 9, 67)),
|
|
("APS", "brent", (78, 5, 70))]:
|
|
w, t, l, _ = head_to_head(rows, CREDIT, opp, setname)
|
|
check(f"credit {setname} vs {opp}", (w, t, l), want)
|
|
w, _t, l, _ = head_to_head(rows, CREDIT, "chandrupatla", "APS")
|
|
check("credit APS vs Chandrupatla sign test p (rounded)", round(sign_p(w, l), 2), 0.57)
|
|
|
|
# ---- what the earlier, order-destroying guards cost --------------------
|
|
print("\nThe guards that replace the step instead of projecting it:")
|
|
check("APS unguarded", row(rows, "APS", "pure.ratio.derived3.none")["total"],
|
|
2806)
|
|
cha_none = row(rows, "CHA", "pure.ratio.derived3.none")
|
|
check("CHA unguarded total", cha_none["total"], 4104)
|
|
check("CHA unguarded solved", cha_none["solved"], 35)
|
|
check("CHA unguarded bound violations", cha_none["over"], 10)
|
|
check("APS bracket-guard", row(rows, "APS", "pure.ratio.derived3.bracket")["total"],
|
|
7260)
|
|
check("APS both-guard", row(rows, "APS", "pure.ratio.derived3.both")["total"],
|
|
7239)
|
|
|
|
# ---- the field --------------------------------------------------------
|
|
print("\nAlefeld-Potra-Shi:")
|
|
check("APS winner", rank(rows, "APS")[0]["label"], "chandrupatla")
|
|
for lbl, pl, tot in [("chandrupatla", 1, 2787), ("toms748", 4, 2820),
|
|
("brent", 5, 2889), ("dekker", 12, 3158),
|
|
("itp_oracle", 13, 3260), ("ridders", 20, 3313),
|
|
("itp", 34, 3957), ("illinois", 73, 7045),
|
|
("bisection", 79, 7530), ("regula_falsi", 244, 10560)]:
|
|
check(f"APS {lbl} place", place(rows, "APS", lbl), pl)
|
|
check(f"APS {lbl} total", row(rows, "APS", lbl)["total"], tot)
|
|
check("APS regula falsi solved", row(rows, "APS", "regula_falsi")["solved"],
|
|
127)
|
|
|
|
print("\nChandrupatla:")
|
|
top = rank(rows, "CHA")[0]
|
|
check("CHA rank 1 label", top["label"], "pure.sqrt.bracket.project")
|
|
check("CHA rank 1 solves one more than anyone else", top["CHA"]["solved"], 41)
|
|
for lbl, pl, tot in [("chandrupatla", 2, 2441), ("itp_oracle", 3, 2647),
|
|
("itp", 6, 2896), ("bisection", 16, 3090),
|
|
("toms748", 159, 4000), ("brent", 227, 4115)]:
|
|
check(f"CHA {lbl} place", place(rows, "CHA", lbl), pl)
|
|
check(f"CHA {lbl} total", row(rows, "CHA", lbl)["total"], tot)
|
|
check("CHA brent solved", row(rows, "CHA", "brent")["solved"], 38)
|
|
|
|
ours_both = (row(rows, "APS", PROPOSED)["total"]
|
|
+ row(rows, "CHA", PROPOSED)["total"])
|
|
cha_both = (row(rows, "APS", "chandrupatla")["total"]
|
|
+ row(rows, "CHA", "chandrupatla")["total"])
|
|
check("chandrupatla, both sets", cha_both, 5228)
|
|
check("Chandrupatla beats us on both sets", cha_both < ours_both, True)
|
|
|
|
# ---- the regime findings ---------------------------------------------
|
|
print("\nNegative results, the regime claims:")
|
|
check("CHA cbrt over the whole set",
|
|
row(rows, "CHA", "pure.cbrt.derived3.project")["total"], 4109)
|
|
switched = (row(rows, "APS", PROJ)["total"]
|
|
+ row(rows, "CHA", "pure.cbrt.derived3.project")["total"])
|
|
single = row(rows, "APS", PROJ)["total"] + row(rows, "CHA", PROJ)["total"]
|
|
check("single fixed choice, both sets", single, 6026)
|
|
check("switch by benchmark set, both sets", switched, 6915)
|
|
check("switching is worse than not switching", switched > single, True)
|
|
for pid, ours_n, cb_n in (("fun4.1", 89, 32), ("fun4.2", 93, 32),
|
|
("fun4.3", 113, 40), ("fun4.4", 125, 47),
|
|
("fun4.5", 153, 59)):
|
|
o = row(rows, "CHA", PROJ)["per"][pid]
|
|
c = row(rows, "CHA", "pure.cbrt.derived3.project")["per"][pid]
|
|
check(f"{pid} projection variant", o[0], ours_n)
|
|
check(f"{pid} cbrt", c[0], cb_n)
|
|
|
|
# ---- the law across the grid ------------------------------------------
|
|
print("\nThe law across the grid:")
|
|
lin = ("ratio", "rational", "exp_abs")
|
|
quad = ("rat_sq", "exp_sq", "cosine")
|
|
want = {("derived3", "lin"): 6893, ("derived3", "quad"): 22315,
|
|
("derived", "lin"): 6981, ("derived", "quad"): 22206,
|
|
("bracket", "lin"): 10279, ("bracket", "quad"): 19127,
|
|
("start", "lin"): 16102, ("start", "quad"): 15345}
|
|
for scale in ("derived3", "derived", "bracket", "start"):
|
|
for group, gname in ((lin, "lin"), (quad, "quad")):
|
|
tot = cnt = 0
|
|
for r in rows:
|
|
if r["spec"][0] != "pure":
|
|
continue
|
|
_, sim, sc, gu = r["spec"]
|
|
if sc != scale or gu != "step" or sim not in group:
|
|
continue
|
|
cnt += 1
|
|
tot += r["APS"]["total"] + r["CHA"]["total"]
|
|
check(f"mean total, scale={scale}, {gname}",
|
|
round(tot / cnt), want[(scale, gname)])
|
|
|
|
best_by_sim, best_by_scale = {}, {}
|
|
for r in rows:
|
|
if r["spec"][0] != "pure" or r["spec"][3] != "step":
|
|
continue
|
|
t = r["APS"]["total"] + r["CHA"]["total"]
|
|
best_by_sim[r["spec"][1]] = min(best_by_sim.get(r["spec"][1], 10 ** 9), t)
|
|
best_by_scale[r["spec"][2]] = min(best_by_scale.get(r["spec"][2], 10 ** 9), t)
|
|
check("every c=1 similarity beats every c=0 similarity",
|
|
max(best_by_sim[s] for s in lin) < min(best_by_sim[s] for s in quad),
|
|
True)
|
|
check("similarity ranking",
|
|
[s for s, _ in sorted(best_by_sim.items(), key=lambda kv: kv[1])],
|
|
["ratio", "exp_abs", "rational", "ratio_soft", "sqrt", "cbrt",
|
|
"exp_sq", "rat_sq", "cosine"])
|
|
for sim, v in [("ratio", 6560), ("exp_abs", 6895), ("rational", 7118),
|
|
("ratio_soft", 9578), ("sqrt", 10546), ("cbrt", 12002),
|
|
("exp_sq", 14307), ("rat_sq", 15102), ("cosine", 16394)]:
|
|
check(f"similarity {sim} best", best_by_sim[sim], v)
|
|
check("scale ranking",
|
|
[s for s, _ in sorted(best_by_scale.items(), key=lambda kv: kv[1])],
|
|
["derived3", "derived", "bracket", "start"])
|
|
for sc, v in [("derived3", 6560), ("derived", 6702), ("bracket", 9107),
|
|
("start", 14540)]:
|
|
check(f"scale {sc} best", best_by_scale[sc], v)
|
|
|
|
verify_placement_modes()
|
|
verify_per_place()
|
|
verify_decision_place()
|
|
verify_gap_decomposition()
|
|
verify_safeguard_and_tables()
|
|
verify_flat_regime_and_oos()
|
|
|
|
print()
|
|
if FAILS:
|
|
print(f"{len(FAILS)} STATED NUMBERS DO NOT MATCH THE DATA:")
|
|
for f in FAILS:
|
|
print(f" {f}")
|
|
sys.exit(1)
|
|
print("every number stated in the paper matches the sweep data.")
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Section "where the similarity is read" (PREREGs of 2026-09-20/21). Each new
|
|
# grid lives in its OWN sweep file so the published sweep_full.json stays the
|
|
# artefact of the original claims; every number the new section quotes is
|
|
# re-checked here against that file.
|
|
# --------------------------------------------------------------------------
|
|
PLACEMENT = {
|
|
# file label APS CHA
|
|
"sweep_slope.json": ("slope.ratio.derived3.project", 2848, 3114),
|
|
"sweep_points.json": ("pure+shape+slope.ratio.derived3.safe", 2527, 3126),
|
|
"sweep_direction.json": ("pure+dissim+slope.ratio.derived3.project", 2726, 2799),
|
|
"sweep_combo.json": ("pure+shape+dissim+slope.ratio.derived3.safe", 2884, 2871),
|
|
"sweep_gate.json": ("progress.ratio.derived.project", 4449, 3047),
|
|
"sweep_log.json": ("log.ratio_soft.derived.safe", 6940, 3541),
|
|
}
|
|
# The per-place table of section "the similarity function belongs to the place":
|
|
# seven PAIRED comparisons in sweep_order.json. Checked as pairs, because a pair is
|
|
# what the pre-registration licensed and a single cell would prove nothing.
|
|
ORDER_PAIRS = {
|
|
# guard (APS m=1, APS measured, CHA m=1, CHA measured)
|
|
"both": (4522, 3675, 3406, 3241),
|
|
"bracket": (4606, 3542, 3602, 3359),
|
|
"credit": (5190, 4686, 3013, 2884),
|
|
"project": (6932, 6364, 4789, 4554),
|
|
"safe": (5987, 5229, 4134, 3954),
|
|
"step": (6435, 5551, 4287, 4068),
|
|
"none": (10676, 10043, 8265, 7794),
|
|
}
|
|
# the negative item: the order does not cure false position
|
|
ORDER_FALSEPOS = {("rational", "far", "none", "none"): (127, 10676),
|
|
("rational", "far", "none", "order"): (128, 10043)}
|
|
# and the harmful direction, quoted in the same subsection
|
|
ORDER_SLOPE_HARM = {("ratio", "derived3", "none", "none"): 2806,
|
|
("ratio", "derived3", "none", "order"): 2854}
|
|
|
|
|
|
def verify_per_place():
|
|
print("\nThe per-place reading (sweep_order.json):")
|
|
if not os.path.exists("sweep_order.json"):
|
|
print(" !! sweep_order.json absent — section 'belongs to the place' unverifiable")
|
|
FAILS.append("missing sweep_order.json")
|
|
return
|
|
with open("sweep_order.json", encoding="utf8") as fh:
|
|
rows = json.load(fh)
|
|
|
|
def cell(sim, sc, gu, ex):
|
|
for r in rows:
|
|
s = r["spec"]
|
|
if (s[1], s[2], s[3], s[8] if len(s) > 8 else "none") == (sim, sc, gu, ex):
|
|
return r
|
|
return None
|
|
|
|
cheaper = 0
|
|
for gu, (a1, a2, c1, c2) in ORDER_PAIRS.items():
|
|
p = cell("rational", "far", gu, "none")
|
|
q = cell("rational", "far", gu, "order")
|
|
if p is None or q is None:
|
|
FAILS.append(f"order pair {gu} missing from sweep_order.json")
|
|
print(f" !! pair {gu} missing — stale sweep")
|
|
continue
|
|
check(f"far+rational {gu} APS m=1", p["APS"]["total"], a1)
|
|
check(f"far+rational {gu} APS order", q["APS"]["total"], a2)
|
|
check(f"far+rational {gu} CHA m=1", p["CHA"]["total"], c1)
|
|
check(f"far+rational {gu} CHA order", q["CHA"]["total"], c2)
|
|
cheaper += (q["APS"]["total"] + q["CHA"]["total"]
|
|
< p["APS"]["total"] + p["CHA"]["total"])
|
|
check("cheaper in 7 of 7 safeguards", cheaper, 7)
|
|
for (sim, sc, gu, ex), (solved, total) in ORDER_FALSEPOS.items():
|
|
r = cell(sim, sc, gu, ex)
|
|
if r is None:
|
|
FAILS.append(f"false-position cell {ex} missing")
|
|
continue
|
|
check(f"false position {ex} solved", r["APS"]["solved"], solved)
|
|
check(f"false position {ex} APS", r["APS"]["total"], total)
|
|
for (sim, sc, gu, ex), want in ORDER_SLOPE_HARM.items():
|
|
r = cell(sim, sc, gu, ex)
|
|
if r is None:
|
|
FAILS.append(f"slope-harm cell {ex} missing")
|
|
continue
|
|
check(f"slope reading {ex} APS", r["APS"]["total"], want)
|
|
fam = [r for r in rows if r["spec"][3] in ("project", "safe", "credit")]
|
|
check("guarantee family violations", sum(r["APS"]["over"] + r["CHA"]["over"]
|
|
for r in fam), 0)
|
|
|
|
|
|
DECISION_CELLS = {
|
|
# (similarity, prestep, guard): {set: total}
|
|
("ratio", "band", "project"): {"APS": 5432, "CHA": 3059},
|
|
("ratio", "band", "credit"): {"CHA": 2892},
|
|
("ratio", "none", "project"): {"APS": 2806},
|
|
("ratio", "defect", "project"): {"APS": 2523, "CHA": 3210},
|
|
("ratio_soft", "simpair", "project"): {"CHA": 2897},
|
|
}
|
|
DECISION_RATES = {"band": 63.5, "defect": 6.6}
|
|
|
|
|
|
def verify_decision_place():
|
|
print("\nThe decision place (sweep_decision.json):")
|
|
if not os.path.exists("sweep_decision.json"):
|
|
print(" !! sweep_decision.json absent — section 'decision place' unverifiable")
|
|
FAILS.append("missing sweep_decision.json")
|
|
return
|
|
with open("sweep_decision.json", encoding="utf8") as fh:
|
|
rows = json.load(fh)
|
|
by = {(r["spec"][1], r["spec"][5], r["spec"][3]): r for r in rows}
|
|
for k, sets in DECISION_CELLS.items():
|
|
r = by.get(k)
|
|
if r is None:
|
|
FAILS.append(f"decision cell {k} missing")
|
|
print(f" !! {k} missing — stale sweep")
|
|
continue
|
|
for setname, want in sets.items():
|
|
check(f"{'.'.join(k)} {setname}", r[setname]["total"], want)
|
|
d = by[("ratio", "defect", "project")]
|
|
check("defect APS solved", d["APS"]["solved"], 153)
|
|
check("defect both sets", d["APS"]["total"] + d["CHA"]["total"], 5733)
|
|
check("defect is the new canonical best (< 2527)", d["APS"]["total"] < 2527, True)
|
|
fam = [r for r in rows if r["spec"][3] in ("project", "safe", "credit")]
|
|
check("decision grid guarantee violations", sum(r["APS"]["over"] + r["CHA"]["over"]
|
|
for r in fam), 0)
|
|
# the refusal rates are recomputed, not transcribed
|
|
from scipy.optimize._tstutils import _APS_TESTS_DICTS, _CHANDRUPATLA_TESTS_DICTS
|
|
from simroot.pure import pure_root
|
|
probs = [(float(q["bracket"][0]), float(q["bracket"][1]),
|
|
(lambda ff, aa: lambda t: ff(t, *aa))(q["f"], q.get("args", ())))
|
|
for q in _APS_TESTS_DICTS]
|
|
probs += [(float(q["bracket"][0]), float(q["bracket"][1]),
|
|
(lambda ff: lambda t: ff(t))(q["f"])) for q in _CHANDRUPATLA_TESTS_DICTS]
|
|
for mode, want in DECISION_RATES.items():
|
|
ref = nfev = 0
|
|
for a, b, f in probs:
|
|
st = {}
|
|
try:
|
|
_x, n, _c = pure_root(f, a, b, 1e-12, 200, similarity="ratio",
|
|
scale="derived3", guard="project", prestep=mode,
|
|
stats=st)
|
|
except Exception:
|
|
continue
|
|
ref += st.get("pre_refused", 0)
|
|
nfev += int(n)
|
|
check(f"{mode} refusal rate %", round(100.0 * ref / nfev, 1), want)
|
|
|
|
|
|
def verify_gap_decomposition():
|
|
"""Section 7.4 of the .md (sec:widelimit in the .tex): the wide-bracket gap taken
|
|
apart on the same evaluations. Every number is RECOMPUTED by running the diagnosis
|
|
scripts, not transcribed from their saved printouts."""
|
|
import contextlib
|
|
import io
|
|
print("\nThe gap decomposition (fresh runs of the diagnosis scripts):")
|
|
import diag_flat_detectable
|
|
import diag_model_order
|
|
import diag_model_order_checks
|
|
with contextlib.redirect_stdout(io.StringIO()):
|
|
mo = diag_model_order.main()
|
|
ck = diag_model_order_checks.main()
|
|
fl = diag_flat_detectable.main()
|
|
per = mo["per_problem"]
|
|
check("problems where we lose", len(mo["lose"]), 33)
|
|
check("fun1.4 our bracket halvings/eval", round(per["fun1.4"][2], 2), 0.62)
|
|
check("fun1.4 IQI from our points", round(per["fun1.4"][3], 2), 10.37)
|
|
flat = [p for p in per if p.split(".")[0] in ("fun3", "fun4", "fun5", "fun6")]
|
|
check("flat: ours min", round(min(per[p][2] for p in flat), 2), 0.41)
|
|
check("flat: ours max", round(max(per[p][2] for p in flat), 2), 0.75)
|
|
check("flat: IQI min", round(min(per[p][3] for p in flat), 2), 0.01)
|
|
check("flat: IQI max", round(max(per[p][3] for p in flat), 2), 0.17)
|
|
check("non-degenerate states with one negative weight", mo["neg_ok"], 428)
|
|
check("bracketing states in total", mo["neg_all"], 431)
|
|
check("every exception is an underflowed zero weight",
|
|
all(any(w == 0.0 for w in ws) for _p, _f, ws in ck["exceptions"]), True)
|
|
fam = ck["fam"]
|
|
gap = {k: v[2] - v[3] for k, v in fam.items()}
|
|
check("total gap on the losing problems", sum(gap.values()), 256)
|
|
check("flat families' gap", sum(gap[k] for k in ("fun3", "fun4", "fun5", "fun6")), 172)
|
|
check("fun1 gap", gap["fun1"], 58)
|
|
for k, want in (("fun3", 92), ("fun4", 96), ("fun5", 100), ("fun6", 100)):
|
|
b, q = fam[k][0], fam[k][1]
|
|
check(f"Chandrupatla bisect share {k} %", round(100.0 * b / (b + q)), want)
|
|
for k, want in (("fun4", 297), ("fun5", 233), ("fun6", 233)):
|
|
check(f"Chandrupatla total {k}", fam[k][3], want)
|
|
check("m>=2 on canonical states %", round(fl["APS (canonical)"][2], 1), 0.2)
|
|
check("m>=2 on flat states %", round(fl["CHA flat fun3-6"][2], 1), 0.0)
|
|
# the band per family, from the Linux sweep
|
|
with open("sweep_decision.json", encoding="utf8") as fh:
|
|
rows = json.load(fh)
|
|
by = {(r["spec"][1], r["spec"][5], r["spec"][3]): r for r in rows}
|
|
base = by[("ratio", "none", "project")]["CHA"]["per"]
|
|
band = by[("ratio", "band", "project")]["CHA"]["per"]
|
|
|
|
def fam_total(per_, k):
|
|
return sum(n if ok else 200 for pid, (n, ok) in per_.items()
|
|
if pid.split(".")[0] == k)
|
|
for k, b0, b1 in (("fun4", 573, 296), ("fun5", 456, 239), ("fun6", 456, 228)):
|
|
check(f"band {k} no-gate", fam_total(base, k), b0)
|
|
check(f"band {k} with band", fam_total(band, k), b1)
|
|
for k, d in (("fun1", 164), ("fun2", 111), ("fun8", 170), ("fun9", 144)):
|
|
check(f"band cost on {k}", fam_total(band, k) - fam_total(base, k), d)
|
|
# negative item 11, corrected pairing: the same configuration in x and in log space
|
|
with open("sweep_full.json", encoding="utf8") as fh:
|
|
full = json.load(fh)
|
|
xcell = next(r for r in full if r["label"] == "pure.ratio_soft.derived.safe")
|
|
check("log item: x-space control APS", xcell["APS"]["total"], 5822)
|
|
check("log item: x-space control CHA", xcell["CHA"]["total"], 3695)
|
|
|
|
|
|
def verify_safeguard_and_tables():
|
|
"""§3.1 of the .md (the multiplier is a free constant; the earned budget), Tables 2-3
|
|
regenerated with Chandrupatla, §5.1, and the constant-free numbers of §7. The
|
|
measured tables are RECOMPUTED by running the measurement scripts."""
|
|
import contextlib
|
|
import io
|
|
import measure_budget_factor
|
|
import measure_records_vs_multiplier
|
|
print("\n§3.1: the multiplier and the endowment (fresh runs):")
|
|
with contextlib.redirect_stdout(io.StringIO()):
|
|
bf = measure_budget_factor.main()
|
|
rm = measure_records_vs_multiplier.main()
|
|
for c, (aps, cha) in ((1.0, (4817, 2997)), (1.25, (2806, 2752)), (1.5, (2806, 2889)),
|
|
(2.0, (2806, 3220)), (3.0, (2806, 3756)), (4.0, (2806, 4006))):
|
|
check(f"multiplier {c} APS", bf[c][0], aps)
|
|
check(f"multiplier {c} CHA", bf[c][2], cha)
|
|
for c0, (aps, cha) in ((0.1, (5344, 3051)), (0.5, (4656, 3002)), (1.0, (3568, 3020)),
|
|
(2.0, (3692, 2712)), (5.0, (3006, 2615))):
|
|
check(f"endowment {c0} APS", bf["endowment"][c0][0], aps)
|
|
check(f"endowment {c0} CHA", bf["endowment"][c0][1], cha)
|
|
within_one_step = {c0: sum(v) for c0, v in bf["endowment"].items() if c0 <= 1.0}
|
|
check("C0=1 cheapest within the one-step promise",
|
|
min(within_one_step, key=within_one_step.get), 1.0)
|
|
sh = rm["shape reading (2527)"]
|
|
check("2527 at multiplier 1.25", sh[1.25][0], 2541)
|
|
check("2527 flat from 1.5 to 4", {sh[f][0] for f in (1.5, 2.0, 3.0, 4.0)}, {2527})
|
|
de = rm["defect reading (2523)"]
|
|
check("2523 flat from 1.25 to 4", {de[f][0] for f in (1.25, 1.5, 2.0, 3.0, 4.0)}, {2523})
|
|
|
|
print("\nTables 2-3 regenerated:")
|
|
with open("sweep_full.json", encoding="utf8") as fh:
|
|
rows = json.load(fh)
|
|
by = {r["label"]: r for r in rows}
|
|
none_ = "pure.ratio.derived3.none"
|
|
for setname, lbl, pl in (("APS", PROJ, 3), ("APS", none_, 2), ("CHA", PROJ, 45),
|
|
("CHA", none_, 228), ("CHA", "pure.exp_abs.bracket.both", 4)):
|
|
check(f"{setname} {lbl} place", place(rows, setname, lbl), pl)
|
|
check("CHA exp_abs.bracket.both total", by["pure.exp_abs.bracket.both"]["CHA"]["total"],
|
|
2736)
|
|
check("CHA TOMS 748 over the 2x bound", by["toms748"]["CHA"]["over"], 15)
|
|
check("CHA Brent over the 2x bound", by["brent"]["CHA"]["over"], 18)
|
|
for lbl, setname, opp, want in (
|
|
(CREDIT, "APS", "itp_oracle", (86, 6, 61)),
|
|
(CREDIT, "CHA", "itp_oracle", (2, 2, 36)),
|
|
(CREDIT, "CHA", "bisection", (5, 0, 35)),
|
|
(PROJ, "APS", "chandrupatla", (87, 24, 42)),
|
|
(PROJ, "APS", "itp", (132, 3, 18)),
|
|
(PROJ, "APS", "itp_oracle", (121, 4, 28)),
|
|
(PROJ, "APS", "bisection", (152, 1, 0)),
|
|
(PROJ, "CHA", "toms748", (31, 1, 8)),
|
|
(PROJ, "CHA", "brent", (30, 4, 4)),
|
|
(PROJ, "CHA", "itp", (17, 0, 23)),
|
|
(PROJ, "CHA", "itp_oracle", (16, 0, 24))):
|
|
w, t, l, _ = head_to_head(rows, lbl, opp, setname)
|
|
check(f"{lbl.split('.')[-1]} {setname} vs {opp}", (w, t, l), want)
|
|
for lbl, want in ((CREDIT, 6588), (PROJ, 6026), ("chandrupatla", 5228),
|
|
("itp_oracle", 5907), ("toms748", 6820), ("brent", 7004)):
|
|
check(f"both sets {lbl}", by[lbl]["APS"]["total"] + by[lbl]["CHA"]["total"], want)
|
|
|
|
print("\n§7 under the earned projection:")
|
|
import glob
|
|
cells = {}
|
|
for p in glob.glob("sweep_*.json"):
|
|
if "smoke" in p:
|
|
continue
|
|
with open(p, encoding="utf8") as fh:
|
|
data = json.load(fh)
|
|
# only grid files (a list of labelled cells); the out-of-sample results
|
|
# (sweep_oos.json, sweep_fourth_*.json, ...) are dicts of a different shape
|
|
if not isinstance(data, list):
|
|
continue
|
|
for r in data:
|
|
cells.setdefault(r["label"], r)
|
|
for lbl, aps, cha in (("slope.ratio.derived3.credit", 3507, 2997),
|
|
("pure+shape+slope.ratio.derived3.credit", 3755, 3021),
|
|
("pure+dissim+slope.ratio.derived3.credit", 3857, 3002),
|
|
("pure+shape+dissim+slope.ratio.derived3.credit", 4354, 3037),
|
|
("defect.ratio.derived3.credit", 3545, 2949)):
|
|
check(f"{lbl} APS", cells[lbl]["APS"]["total"], aps)
|
|
check(f"{lbl} CHA", cells[lbl]["CHA"]["total"], cha)
|
|
free = [r for r in cells.values() if r.get("spec") and len(r["spec"]) > 3
|
|
and r["spec"][0] == "pure" and r["spec"][3] == "credit"
|
|
and r["APS"]["solved"] + r["CHA"]["solved"] == 193]
|
|
top = min(free, key=lambda r: r["APS"]["total"] + r["CHA"]["total"])
|
|
check("best constant-free configuration", top["label"],
|
|
"defect+flatanalogmempt+exp+half.ratio.derived3.credit")
|
|
check("its total over both sets", top["APS"]["total"] + top["CHA"]["total"], 6111)
|
|
d = cells["defect.ratio.derived3.credit"]
|
|
check("defect under the earned projection, both sets",
|
|
d["APS"]["total"] + d["CHA"]["total"], 6494)
|
|
|
|
|
|
PLACEMENT_PER_SET = {
|
|
"sweep_direction.json": ("CHA", "pure+dissim+slope.ratio.derived3.safe", 2695),
|
|
"sweep_gate.json": ("CHA", "progress.ratio_soft.derived.safe", 2888),
|
|
}
|
|
|
|
|
|
def verify_placement_modes():
|
|
print("\nThe placement modes (each in its own sweep file):")
|
|
for path, (lbl, aps, cha) in PLACEMENT.items():
|
|
if not os.path.exists(path):
|
|
print(f" !! {path} absent — the section quoting it cannot be verified")
|
|
FAILS.append(f"missing {path}")
|
|
continue
|
|
with open(path, encoding="utf8") as fh:
|
|
rows = json.load(fh)
|
|
try:
|
|
d = next(r for r in rows if r["label"] == lbl)
|
|
except StopIteration:
|
|
print(f" !! {lbl} not in {path} — stale sweep")
|
|
FAILS.append(f"{lbl} missing from {path}")
|
|
continue
|
|
check(f"{lbl} APS", d["APS"]["total"], aps)
|
|
check(f"{lbl} CHA", d["CHA"]["total"], cha)
|
|
check(f"{lbl} solved", d["APS"]["solved"] + d["CHA"]["solved"], 193)
|
|
check(f"{lbl} guarantee (over 2x)", d["APS"]["over"] + d["CHA"]["over"], 0)
|
|
for path, (setname, lbl, want) in PLACEMENT_PER_SET.items():
|
|
if not os.path.exists(path):
|
|
continue
|
|
with open(path, encoding="utf8") as fh:
|
|
rows = json.load(fh)
|
|
d = next((r for r in rows if r["label"] == lbl), None)
|
|
if d is None:
|
|
FAILS.append(f"{lbl} missing from {path}")
|
|
continue
|
|
check(f"{lbl} {setname} per-set", d[setname]["total"], want)
|
|
|
|
|
|
def _load(path):
|
|
with open(path, encoding="utf8") as fh:
|
|
return json.load(fh)
|
|
|
|
|
|
def _cell(path, lbl):
|
|
return next(r for r in _load(path) if r["label"] == lbl)
|
|
|
|
|
|
def _flat_sum(r):
|
|
return sum(n if ok else 200 for pid, (n, ok) in r["CHA"]["per"].items()
|
|
if pid.split(".")[0] in ("fun3", "fun4", "fun5", "fun6"))
|
|
|
|
|
|
def verify_flat_regime_and_oos():
|
|
"""Sections 8-9 and negative items 12-16 of the .md, and the abstract that quotes them:
|
|
the flat regime by analogy, the proposed method A', its ablation, and the out-of-sample
|
|
corpora. Every number is read from a server results file or recomputed by the diagnosis
|
|
scripts; none is transcribed."""
|
|
import contextlib
|
|
import io
|
|
import math
|
|
import re
|
|
print("\nSection 8 and negative items 12-16 (the development grids):")
|
|
P = "ratio.derived3.project"
|
|
for path, lbl, aps, cha in (
|
|
("sweep_flat.json", f"flat.{P}", 3029, 3198),
|
|
("sweep_flat2.json", f"flat2.{P}", 2803, 3341),
|
|
("sweep_flatcreep.json", f"flatcreep.{P}", 2878, 3354),
|
|
("sweep_flatstick.json", f"flatstickmid.{P}", 6897, 3019),
|
|
("sweep_flatexit.json", f"flatstickexit.{P}", 3125, 2503),
|
|
("sweep_flatjudge.json", f"flatjudge.{P}", 3009, 2486),
|
|
("sweep_orderpt.json", f"flatanalogmem.{P}", 2814, None),
|
|
("sweep_half.json", f"half.{P}", 2564, None)):
|
|
r = _cell(path, lbl)
|
|
check(f"{lbl} APS", r["APS"]["total"], aps)
|
|
if cha is not None:
|
|
check(f"{lbl} CHA", r["CHA"]["total"], cha)
|
|
check(f"{lbl} guarantee", r["APS"]["over"] + r["CHA"]["over"], 0)
|
|
check("sticky with order from the failed promise, APS",
|
|
_cell("sweep_flatstick.json", f"flatstick.{P}")["APS"]["total"], 6781)
|
|
check("sticky midpoint: flat families",
|
|
_flat_sum(_cell("sweep_flatstick.json", f"flatstickmid.{P}")), 1057)
|
|
full = {r["label"]: r for r in _load("sweep_full.json")}
|
|
check("bisection: flat families", _flat_sum(full["bisection"]), 1044)
|
|
check("Chandrupatla: flat families", _flat_sum(full["chandrupatla"]), 1068)
|
|
op = {r["label"]: r for r in _load("sweep_orderpt.json")}
|
|
check("split from the order: flat families, low end",
|
|
_flat_sum(op[f"flatanalogmempt.{P}"]), 743)
|
|
check("split from the order: flat families, high end",
|
|
_flat_sum(op[f"pure+extP+flatanalogpt.{P}"]), 847)
|
|
check("item 16: remembered + split, with the step pattern, CHA",
|
|
op[f"pure+extP+flatanalogmempt.{P}"]["CHA"]["total"], 2117)
|
|
check("item 16: one-state analogy + split, with the step pattern, CHA",
|
|
op[f"pure+extP+flatanalogpt.{P}"]["CHA"]["total"], 2221)
|
|
|
|
print("\nSection 8 diagnostics (fresh runs):")
|
|
import diag_analogy_decoupled
|
|
import diag_flat_analogy
|
|
import diag_flat_stick
|
|
buf = io.StringIO()
|
|
with contextlib.redirect_stdout(buf):
|
|
diag_flat_analogy.main()
|
|
out = buf.getvalue()
|
|
aps = re.search(r"^APS\s+154\s+(\d+)\s+(\d+)\s+(\d+)", out, re.M)
|
|
flat = re.search(r"^CHA-flat\s+20\s+(\d+)\s+(\d+)\s+(\d+)", out, re.M)
|
|
check("flag rises on canonical problems", int(aps.group(1)), 142)
|
|
check("flag + analogy + m>=2 on canonical problems", int(aps.group(3)), 3)
|
|
check("flag + analogy + m>=2 on flat problems", int(flat.group(3)), 20)
|
|
for fam in ("fun2", "fun8", "fun9"):
|
|
m = re.search(rf"^CHA-{fam}\s+5\s+\d+\s+\d+\s+(\d+)", out, re.M)
|
|
check(f"flag + analogy + m>=2 on {fam}", int(m.group(1)), 0)
|
|
buf = io.StringIO()
|
|
with contextlib.redirect_stdout(buf):
|
|
diag_analogy_decoupled.main()
|
|
m = re.search(r"mean entry state ([\d.]+) \(same state\) -> ([\d.]+)", buf.getvalue())
|
|
check("mean entry state, one state", m.group(1), "12.9")
|
|
check("mean entry state, remembered", m.group(2), "8.2")
|
|
buf = io.StringIO()
|
|
with contextlib.redirect_stdout(buf):
|
|
diag_flat_stick.main()
|
|
inf = tot = 0
|
|
for d in re.findall(r"order read at entry: (\{[^}]*\})", buf.getvalue()):
|
|
dd = eval(d) # noqa: S307 - the diagnosis script's own printed dict
|
|
inf += dd.get("inf", 0)
|
|
tot += sum(dd.values())
|
|
check("order from the failed promise is inf", (inf, tot), (163, 174))
|
|
from simroot.pure import pure_root
|
|
ap = "contra+flatanalogmempt+exp+half+close+sub"
|
|
|
|
def n_of(f, a, b, pre="none", ext="none"):
|
|
return pure_root(f, a, b, 1e-12, 200, similarity="ratio", scale="derived3",
|
|
guard="project", prestep=pre, extrapolate=ext)[1]
|
|
sq = lambda t: math.sqrt(abs(t)) * (0.0 if t == 0 else math.copysign(1.0, t)) # noqa: E731
|
|
check("sqrt|x| sgn x, base rule", n_of(sq, -1 / 3, 1.0), 84)
|
|
check("sin on [3,4], base rule", n_of(math.sin, 3.0, 4.0), 24)
|
|
check("sin on [3,4], A'", n_of(math.sin, 3.0, 4.0, ap, "pattern"), 7)
|
|
|
|
print("\nTable 8 (A' on the protocol of section 4, sweep_aprime.json):")
|
|
rows_ap = _load("sweep_aprime.json")
|
|
A = f"pure+extP+{ap}.ratio.derived3"
|
|
apr = {r["label"]: r for r in rows_ap}
|
|
a = apr[f"{A}.project"]
|
|
check("A' APS", a["APS"]["total"], 2438)
|
|
check("A' CHA", a["CHA"]["total"], 2005)
|
|
check("A' both", a["APS"]["total"] + a["CHA"]["total"], 4443)
|
|
check("A' solved", a["APS"]["solved"] + a["CHA"]["solved"], 193)
|
|
c = apr[f"{A}.credit"]
|
|
check("A' earned budget", (c["APS"]["total"], c["CHA"]["total"]), (3608, 2807))
|
|
check("A' under every safeguard: violations",
|
|
sum(r["APS"]["over"] + r["CHA"]["over"] for lb, r in apr.items() if lb.startswith(A)), 0)
|
|
check("A' safeguards measured", sum(1 for lb in apr if lb.startswith(A + ".")), 7)
|
|
both = [r for r in _load("sweep_full.json")] + rows_ap
|
|
for setname, opp, want in (("APS", "chandrupatla", (103, 20, 30)),
|
|
("CHA", "chandrupatla", (29, 4, 7)),
|
|
("APS", "toms748", (127, 6, 20)), ("CHA", "toms748", (38, 2, 0)),
|
|
("APS", "brent", (118, 17, 18)), ("CHA", "brent", (33, 3, 2)),
|
|
("APS", "itp_oracle", (126, 7, 20)),
|
|
("CHA", "itp_oracle", (35, 1, 4))):
|
|
w, t, l, _ = head_to_head(both, f"{A}.project", opp, setname)
|
|
check(f"A' {setname} vs {opp}", (w, t, l), want)
|
|
|
|
def sign_p(w, l):
|
|
k, n = min(w, l), w + l
|
|
return min(1.0, 2.0 * sum(math.comb(n, i) for i in range(k + 1)) / 2.0 ** n)
|
|
check("A' APS vs Chandrupatla p (2 digits)", float(f"{sign_p(103, 30):.2g}"), 1.5e-10)
|
|
check("A' CHA vs Chandrupatla p (1 digit)", float(f"{sign_p(29, 7):.1g}"), 3e-4)
|
|
check("A' below Chandrupatla, APS %", round(100 * (1 - 2438 / 2787), 1), 12.5)
|
|
check("A' below Chandrupatla, CHA %", round(100 * (1 - 2005 / 2441), 1), 17.9)
|
|
from where_we_lose import per_family
|
|
af, cf = per_family(a, "CHA"), per_family(full["chandrupatla"], "CHA")
|
|
check("A' fun9 vs Chandrupatla", (af["fun9"], cf["fun9"]), (65, 55))
|
|
check("A' ahead on wide-bracket families", sum(af[k] < cf[k] for k in cf), 7)
|
|
check("A' level on fun7", af["fun7"] == cf["fun7"], True)
|
|
|
|
print("\nTable 9 (ablation of A' on six corpora, sweep_ablation_all.json):")
|
|
ab = _load("sweep_ablation_all.json")
|
|
sets = ("APS", "CHA", "NEW", "RJL", "APP", "D")
|
|
|
|
def tot(r, s):
|
|
return sum(n if ok else 200 for n, ok, _o in r[s].values())
|
|
base_ = {s: tot(ab["ablA'"], s) for s in sets}
|
|
for comp, want in (("-regime", (-7, 1013, 1660, 324, 77, 2269)),
|
|
("-point", (-5, 479, 667, 272, 30, 1672)),
|
|
("-sub", (-6, 0, -7, 16, 63, 893)),
|
|
("-close", (130, 35, 97, 78, 135, -2)),
|
|
("-half", (249, 65, 82, -16, -5, 1)),
|
|
("-exp", (31, 143, 100, -21, -2, 87)),
|
|
("-G2", (-22, -6, 123, -30, -10, 34)),
|
|
("-contra", (11, -12, 29, 0, 1, -1))):
|
|
got = tuple(tot(ab[f"abl{comp}"], s) - base_[s] for s in sets)
|
|
check(f"ablation {comp}", got, want)
|
|
|
|
print("\nSection 9 (out-of-sample corpora):")
|
|
seen, four = _load("sweep_fourth_seen.json"), _load("sweep_fourth_fourth.json")
|
|
for k in seen:
|
|
seen[k].update(four[k])
|
|
names = {"APS": 154, "CHA": 45, "NEW": 206, "RJL": 78, "APP": 132, "D": 240}
|
|
for s, n in names.items():
|
|
check(f"corpus {s} size", len(seen["Aprime"][s]), n)
|
|
table10 = {"APS": (2259, 2595, 2707, 2636, (103, 20, 31)),
|
|
"CHA": (1074, 1505, 3238, 3088, (31, 4, 10)),
|
|
"NEW": (3290, 3716, 6395, 5746, (108, 33, 65)),
|
|
"RJL": (1371, 1566, 2455, 2339, (44, 14, 20)),
|
|
"APP": (1382, 1382, 1503, 1756, (48, 52, 32)),
|
|
"D": (3656, 5717, 8267, 8084, (177, 35, 28))}
|
|
|
|
def cost(v):
|
|
return v[0] if v[1] else 200
|
|
for s, (ta, tc, tb, tt, wtl) in table10.items():
|
|
got = tuple(tot(seen[k], s) for k in ("Aprime", "chandrupatla", "brent", "toms748"))
|
|
check(f"Table 10 {s} totals", got, (ta, tc, tb, tt))
|
|
ps = list(seen["Aprime"][s])
|
|
w = sum(cost(seen["Aprime"][s][p]) < cost(seen["chandrupatla"][s][p]) for p in ps)
|
|
l = sum(cost(seen["Aprime"][s][p]) > cost(seen["chandrupatla"][s][p]) for p in ps)
|
|
check(f"Table 10 {s} vs Chandrupatla", (w, len(ps) - w - l, l), wtl)
|
|
check(f"Table 10 {s} A' violations", sum(v[2] for v in seen["Aprime"][s].values()), 0)
|
|
viol = {k: sum(v[2] for s in names for v in seen[k][s].values()) for k in ("brent", "toms748")}
|
|
check("Brent / TOMS 748 bound violations over 855", (viol["brent"], viol["toms748"]), (118, 84))
|
|
check("all 855 totals", tuple(sum(tot(seen[k], s) for s in names)
|
|
for k in ("Aprime", "chandrupatla", "brent", "toms748")),
|
|
(13032, 16481, 24565, 23649))
|
|
d4 = seen["Aprime"]["D"]
|
|
for label, cls, want in (("without targeted", ("D1", "D2", "D4", "D5"), (2403, 3569, (107, 31, 22))),
|
|
("simple roots", ("D1", "D4"), (737, 747, (43, 22, 15)))):
|
|
ps = [p for p in d4 if p[:2] in cls]
|
|
a_ = sum(cost(d4[p]) for p in ps)
|
|
c_ = sum(cost(seen["chandrupatla"]["D"][p]) for p in ps)
|
|
w = sum(cost(d4[p]) < cost(seen["chandrupatla"]["D"][p]) for p in ps)
|
|
l = sum(cost(d4[p]) > cost(seen["chandrupatla"]["D"][p]) for p in ps)
|
|
check(f"corpus 4 {label}", (a_, c_, (w, len(ps) - w - l, l)), want)
|
|
for cls, want in (("D1", (433, 419, (20, 8, 12))), ("D2", (1163, 1805, (39, 1, 0))),
|
|
("D3", (924, 1784, (37, 1, 2))), ("D4", (304, 328, (23, 14, 3))),
|
|
("D5", (503, 1017, (25, 8, 7))), ("D6", (329, 364, (33, 3, 4)))):
|
|
ps = [p for p in d4 if p.startswith(cls)]
|
|
a_ = sum(cost(d4[p]) for p in ps)
|
|
c_ = sum(cost(seen["chandrupatla"]["D"][p]) for p in ps)
|
|
w = sum(cost(d4[p]) < cost(seen["chandrupatla"]["D"][p]) for p in ps)
|
|
l = sum(cost(d4[p]) > cost(seen["chandrupatla"]["D"][p]) for p in ps)
|
|
check(f"Table 11 {cls}", (a_, c_, (w, len(ps) - w - l, l)), want)
|
|
c5 = [p for p in seen["Aprime"]["NEW"] if p.startswith("C5")]
|
|
check("near-cancelling class of corpus 1", (sum(cost(seen["Aprime"]["NEW"][p]) for p in c5),
|
|
sum(cost(seen["chandrupatla"]["NEW"][p]) for p in c5)),
|
|
(491, 391))
|
|
# the pre-registered verdicts on corpora 1-3 (variant without close and sub)
|
|
oos = _load("sweep_oos.json")
|
|
|
|
def tot_new(r):
|
|
return sum(n if ok else 200 for n, ok, _o in r["NEW"].values())
|
|
|
|
def h2h_new(r, o, keep=lambda p: True):
|
|
ps = [p for p in r["NEW"] if keep(p)]
|
|
w = sum(cost(r["NEW"][p]) < cost(o["NEW"][p]) for p in ps)
|
|
l = sum(cost(r["NEW"][p]) > cost(o["NEW"][p]) for p in ps)
|
|
return w, len(ps) - w - l, l
|
|
check("corpus 1, variant carried: total vs Chandrupatla",
|
|
(tot_new(oos["A"]), tot_new(oos["chandrupatla"])), (3492, 3899))
|
|
check("corpus 1, variant carried: per problem", h2h_new(oos["A"], oos["chandrupatla"]),
|
|
(105, 34, 67))
|
|
check("corpus 1, with defect: per problem", h2h_new(oos["B"], oos["chandrupatla"]),
|
|
(95, 33, 78))
|
|
check("corpus 1, with defect: exponential class",
|
|
h2h_new(oos["B"], oos["chandrupatla"], lambda p: p.startswith("C4")), (9, 5, 26))
|
|
rj = _load("sweep_rootsjl.json")
|
|
keep = [p for p, v in rj["A"].items() if not v[3]]
|
|
check("Roots.jl, variant carried: totals", (sum(cost(rj["A"][p]) for p in keep),
|
|
sum(cost(rj["chandrupatla"][p]) for p in keep)),
|
|
(1464, 1566))
|
|
w = sum(cost(rj["A"][p]) < cost(rj["chandrupatla"][p]) for p in keep)
|
|
l = sum(cost(rj["A"][p]) > cost(rj["chandrupatla"][p]) for p in keep)
|
|
check("Roots.jl, variant carried: per problem", (w, len(keep) - w - l, l), (38, 10, 30))
|
|
app = _load("sweep_applied.json")
|
|
check("applied, variant carried: totals", (sum(cost(v) for v in app["A"].values()),
|
|
sum(cost(v) for v in app["chandrupatla"].values())),
|
|
(1580, 1382))
|
|
print("\nTable 9a and section 7: the similarity in the step (fresh audit run):")
|
|
aps_ = {r["spec"][1]: r for r in _load("sweep_aprime_s.json")}
|
|
abs_ = _load("sweep_ablation_s.json")
|
|
t9a = {"ratio": (4443, 13032), "exp_abs": (4988, 14142), "rational": (5486, 14843),
|
|
"ratio_soft": (8360, 28500), "sqrt": (12718, 45552), "cbrt": (17207, 63031),
|
|
"exp_sq": (18410, 67701), "cosine": (18412, 67854), "rat_sq": (18422, 67394)}
|
|
for s_, (two, six) in t9a.items():
|
|
r = aps_[s_]
|
|
check(f"Table 9a {s_} APS+CHA", r["APS"]["total"] + r["CHA"]["total"], two)
|
|
check(f"Table 9a {s_} six corpora", sum(tot(abs_[f"S:{s_}"], s) for s in sets), six)
|
|
check(f"Table 9a {s_} guarantee", r["APS"]["over"] + r["CHA"]["over"]
|
|
+ sum(v[2] for s in sets for v in abs_[f"S:{s_}"][s].values()), 0)
|
|
check("nearest other S costs more, protocol %", round(100 * (4988 / 4443 - 1)), 12)
|
|
check("worst S costs more, protocol %", round(100 * (18422 / 4443 - 1)), 315)
|
|
check("nearest other S costs more, six corpora %", round(100 * (14142 / 13032 - 1)), 9)
|
|
check("quadratic S: four to five times",
|
|
(int(18410 / 4443), int(67854 / 13032)), (4, 5))
|
|
import audit_similarity_places
|
|
buf = io.StringIO()
|
|
with contextlib.redirect_stdout(buf):
|
|
audit_similarity_places.main()
|
|
rows_a = {ln.split(" ")[0].strip(): re.findall(r"([+-]\d+) \|", ln)
|
|
for ln in buf.getvalue().splitlines() if " | " in ln}
|
|
check("audit: shape gain with the tent (APS)", int(rows_a["tent 1-|z|"][1]), -493)
|
|
check("audit: shape gain with 1/sqrt(1+z^2) (APS)", int(rows_a["1/sqrt(1+z^2)"][1]), 250)
|
|
check("audit: defect gain with the tent (APS)", int(rows_a["tent 1-|z|"][3]), -283)
|
|
check("audit: defect gain with 1-|z|^1/3 (APS)", int(rows_a["1-|z|^1/3"][3]), 215)
|
|
|
|
# every sign-test p the paper prints in Section 9, at the precision printed
|
|
for (w, l), printed in (((103, 31), "3e-10"), ((31, 10), "0.001"), ((108, 65), "0.001"),
|
|
((44, 20), "0.004"), ((48, 32), "0.09"), ((177, 28), "1e-27"),
|
|
((107, 22), "1e-14"), ((43, 15), "0.0003"), ((105, 67), "0.005"),
|
|
((38, 30), "0.4")):
|
|
check(f"sign test p for {w}:{l}", f"{sign_p(w, l):.1g}", printed)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|