#!/usr/bin/env python3 # -*- coding: utf-8 -*- """MEASURED-yardstick rerun of the deficit frontier (job #2052, triage of research route 87). QUESTION. This is return #1091's own declared next experiment (job #2046, route 87), quoted verbatim from the record: "Read only, no new sieve: take pi2 at a few hundred log-spaced points from the published TOS pi2 tables (and the A007508 endpoint ladder as the cross-check), compute d(x), measure its oscillation amplitude by the local extremal envelope or by a distribution-free spread of the detrended residual, and recompute W(x) = 3*sigma_osc(x)/M'(x) with the same constant-free M." sigma_osc was INFERRED in #1091 from ten decade points, so its frontier's second significant figure was provisional. This script measures it. DATA (published, downloaded read-only 2026-09-18/19 from https://sweet.ua.pt/tos/primes/ ; 49061 distinct grid points, i.e. two orders of magnitude more than the "few hundred" asked for): tos/2b00.txt.gz pi2(2^k), k=1..61 x in [2, 2.3e18] tos/2d10..2d14 pi2(k*10^m), k=1..10000, m=10..14 x in [1e10, 1e18] tos/2d15 pi2(k*10^15), k=1..4000 x in [1e15, 4e18] Every row carries BOTH pi2(x) and TOS's own published 2*Ctwin*li2(x), so d(x) is read off published columns; my own integral is used only as a control. DEFINITIONS AND DECISION RULE (fixed before this run; the falsifier is return #1091's own words). Grid: every (x, pi2, model) row of the tables. d = pi2 - model. Detrend: within a window of half-width HALF_DECADE decades in log10 x centred on x, subtract the local least-squares line of d against log10 x; residuals r_i. sigma_rms(x) := rms of r_i (two-sided amplitude) sigma_dn(x) := -min(r_i) (one-sided DOWNWARD excursion -- the quantity a deficit test needs, since only a downward move can hide a stopped world) sigma_up(x) := max(r_i) Frontier: W(x) = kappa*sigma(x)/M'(x), kappa = 3, M'(x) = 2 C2 (1/ln^2 x)(1 - 2/ln x). HEADLINE yardstick: sigma(x) := max(sigma_rms(x), sigma_dn(x)) -- the conservative choice (a larger yardstick excludes fewer worlds). FALSIFIER (return #1091, verbatim): "The falsifier is pre-registered in the answer: sigma_osc larger than the trend scatter used here weakens the frontier and must be reported as such." Made concrete against #1091's own numbers: measure sigma at 1e19 and compare with #1091's endpoint residual yardstick |d(1e19)| = 3.0981e7 (its W_resid(1e19) = 1.412e11, eps = 1.41e-8). If the measured yardstick EXCEEDS it, the frontier weakens by exactly that factor and this return must say so; if it is smaller, the frontier tightens by that factor. Neither may be reported as the other. CONTROLS (all reported whatever the verdict). A. Cross-table agreement at shared points, and agreement with A007508 (published counts below 10^n). B. TOS's published model column vs my own 30-digit quadrature, x >= 1e6 (the low-x rows are the model's known transient and are reported as such, not as control failures). C. KNOWN-ANSWER control on the measurement itself: for a Poisson world with the same local model the cumulative count is a RANDOM WALK with increment variance equal to the model increment (pi2(x) is cumulative, so its points are nested, not independent -- simulating independent point noise would measure the model's curvature instead, which is exactly the trap this control is built to avoid). Simulate that walk on the actual grid, recover sigma with the SAME estimator, and report measured/simulated. A ratio near 1 says the measured amplitude is a Poisson count fluctuation; a ratio below 1 says the real counts are SMOOTHER than Poisson at this resolution (and then the Poisson yardstick is the conservative one). D. Sub-sample robustness: the assignment asks for "a few hundred" points; recompute the whole measurement from a 300-point log-spaced sub-sample of the fine grid and report the change. Sources cited: TOS pi(x)/pi2(x) tables (sweet.ua.pt/tos/primes.html); A007508; return #1091 (this handle) for the statistic, the model, the three assumed yardsticks and the falsifier wording; Wolf arXiv:1107.2809 (the residual oscillates, so a yardstick must be an amplitude). """ import gzip import json import math import os import sys import mpmath as mp import numpy as np mp.mp.dps = 30 HERE = os.path.dirname(os.path.abspath(__file__)) C2 = mp.mpf("0.660161815846869573927812110014") KAPPA = 3.0 HALF_DECADE = 0.10 MC_TRIALS = 300 A007508 = {10: 27412679, 11: 224376048, 12: 1870585220, 13: 15834664872, 14: 135780321665, 15: 1177209242304, 16: 10304195697298, 17: 90948839353159, 18: 808675888577436, 19: 7237518093734545} TABLES = [("2b00", 2), ("2d10", 10), ("2d11", 11), ("2d12", 12), ("2d13", 13), ("2d14", 14), ("2d15", 15)] # #1091's three ASSUMED yardsticks and the frontier they produced, at the decade grid (from # frontier2.json / report.md section 3). These are the numbers being replaced. R1091 = {14: {"sigma_resid": 5.6771e4, "sigma_detrend": 2.2948e5, "W_resid": 1.429e8, "W_detrend": 5.777e8}, 15: {"sigma_resid": 7.5044e5, "sigma_detrend": 1.1108e6, "W_resid": 2.159e9, "W_detrend": 3.196e9}, 16: {"sigma_resid": 3.1428e6, "sigma_detrend": 1.5502e7, "W_resid": 1.025e10, "W_detrend": 5.055e10}, 17: {"sigma_resid": 6.0922e6, "sigma_detrend": 1.0094e8, "W_resid": 2.235e10, "W_detrend": 3.703e11}, 18: {"sigma_resid": 1.2916e7, "sigma_detrend": 1.4222e8, "W_resid": 5.297e10, "W_detrend": 5.832e11}, 19: {"sigma_resid": 3.0981e7, "sigma_detrend": 8.8234e9, "W_resid": 1.412e11, "W_detrend": 4.021e13, "eps_resid": 1.41e-8}} PROBES = [1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 2e18, 3e18] def parse_table(name): """Rows of (x, pi2, model); the tag 'NbM'/'NdM' means N * base^M.""" base = 2.0 if name == "2b00" else 10.0 rows = [] txt = gzip.decompress(open(os.path.join(HERE, "tos", name + ".txt.gz"), "rb").read()) for line in txt.decode("latin-1", "replace").splitlines(): s = line.strip() if not s or s.startswith("#") or s.startswith("-"): continue parts = s.split() if len(parts) < 3 or not parts[1].isdigit(): continue tag = parts[0] n, e = tag.split("b") if "b" in tag else tag.split("d") rows.append((float(n) * (base ** int(e)), int(parts[1]), float(parts[2].rstrip(".")), name)) return rows def Mp(x): """M(x) = 2 C2 Li2(x) as an mpf, the constant-free Hardy-Littlewood model.""" return 2 * C2 * mp.quad(lambda t: 1 / mp.log(t) ** 2, [2, mp.mpf(x)]) def Mprime(x): """dM/dx at x, analytically.""" L = mp.log(mp.mpf(x)) return 2 * C2 * (1 / L ** 2) * (1 - 2 / L) def main(): out, log = {"tool": "frontier3.py/job2052", "kappa": KAPPA, "half_decade": HALF_DECADE, "mc_trials": MC_TRIALS, "r1091_yardsticks": R1091}, [] def say(s): log.append(s) print(s, flush=True) rows = [] for name, _m in TABLES: r = parse_table(name) say("loaded %-5s rows=%5d x in [%.3e, %.3e]" % (name, len(r), r[0][0], r[-1][0])) rows.append((name, r)) out["grids"] = [{"table": n, "rows": len(r), "x_min": r[0][0], "x_max": r[-1][0]} for n, r in rows] # ---------------- CONTROL A: tables agree with each other and with A007508 ------------------ byx = {} for name, r in rows: for x, pi2, model, src in r: byx.setdefault(x, []).append((pi2, model, src)) clashes = {x: v for x, v in byx.items() if len({p for p, _, _ in v}) > 1} a_ok, a_bad = 0, [] for k, v in A007508.items(): x = float(10 ** k) if x in byx: if byx[x][0][0] == v: a_ok += 1 else: a_bad.append((k, byx[x][0][0], v)) say("CONTROL A: distinct grid points = %d ; pi2 disagreements across tables = %d ; " "A007508 agreement at shared 10^k = %d/%d %s" % (len(byx), len(clashes), a_ok, a_ok + len(a_bad), a_bad)) out["control_A"] = {"distinct_points": len(byx), "disagreements": len(clashes), "a007508_agree": a_ok, "a007508_disagree": a_bad} # ---------------- CONTROL B: TOS's model column vs my own integral -------------------------- sample = [] for name, r in rows: step = max(1, len(r) // 40) sample += r[::step] worst, worst_at, transient = 0.0, None, [] for x, pi2, model, src in sample: if model <= 0: transient.append({"x": x, "table": src, "model": model, "pi2": pi2, "ratio": (pi2 / model if model else None)}) continue mine = float(Mp(x)) rel = abs(mine - model) / abs(model) if x >= 1e6 and rel > worst: worst, worst_at = rel, (x, src, mine, model) if x < 1e6: transient.append({"x": x, "table": src, "model": model, "pi2": pi2, "ratio_mine": mine / model if model else None}) say("CONTROL B: my 30-digit quadrature vs TOS's published column, %d sampled points, " "worst relative difference for x >= 1e6 : %.3e (at x=%.6e, table %s)" % (len(sample), worst, worst_at[0], worst_at[1])) say(" (x < 1e6 rows: %d, left out of the control on purpose -- they are the model's known " "low-x transient; at 1e3 the published ratio pi2/2C2Li2 is 0.764)" % len(transient)) out["control_B"] = {"sampled": len(sample), "worst_rel_xge1e6": worst, "worst_at": {"x": worst_at[0], "table": worst_at[1], "mine": worst_at[2], "tos": worst_at[3]}, "low_x_transient_rows": len(transient)} # ---------------- the measured residual on the fine grid ------------------------------------ grid = sorted(byx.keys()) xs = np.array(grid) pi2v = np.array([float(byx[x][0][0]) for x in grid]) modelv = np.array([float(byx[x][0][1]) for x in grid]) # TOS's published 2*Ctwin*li2 dd = pi2v - modelv lx = np.log10(xs) say("residual d(x) = pi2 - 2C2 Li2, %d points, log10 x in [%.3f, %.3f]" % (len(grid), lx.min(), lx.max())) def window(x): sel = (lx >= math.log10(x) - HALF_DECADE) & (lx <= math.log10(x) + HALF_DECADE) return sel def resid(L, r): A = np.vstack([np.ones_like(L), L]).T coef, *_ = np.linalg.lstsq(A, r, rcond=None) return r - A @ coef def detrended(sel, d): return resid(lx[sel], d[sel]) def amp(x): sel = window(x) if sel.sum() < 5: return None res = detrended(sel, dd) return {"sigma_rms": float(np.sqrt((res ** 2).mean())), "sigma_dn": float(max(-res.min(), 0.0)), "sigma_up": float(max(res.max(), 0.0)), "points": int(sel.sum())} # ---------------- CONTROL C: known answer -- Poisson world, same estimator ------------------ # The counts are CUMULATIVE, so their grid points are nested. A Poisson world is therefore a # random walk whose increment between consecutive grid points has variance M(x_i) - M(x_{i-1}); # independent point noise would instead measure the model's curvature over the window. Both # lanes are simulated, so the difference between them is on the record too. rng = np.random.default_rng(2052) ctrl_c = [] for x in PROBES: sel = window(x) if sel.sum() < 5: continue idx = np.flatnonzero(sel) Mv = modelv[idx] # published model, the same M as in d inc = np.diff(Mv) walk_rms, walk_dn, dot_rms, dot_dn = [], [], [], [] for _ in range(MC_TRIALS): z = rng.standard_normal(len(inc)) walk = np.concatenate([[0.0], np.cumsum(np.sqrt(np.maximum(inc, 0)) * z)]) res = resid(lx[idx], walk) walk_rms.append(float(np.sqrt((res ** 2).mean()))) walk_dn.append(float(max(-res.min(), 0.0))) dot = np.sqrt(Mv) * rng.standard_normal(len(Mv)) res2 = resid(lx[idx], dot) dot_rms.append(float(np.sqrt((res2 ** 2).mean()))) dot_dn.append(float(max(-res2.min(), 0.0))) dM = float(Mv[-1] - Mv[0]) ctrl_c.append({"x": x, "points": int(sel.sum()), "delta_M": dM, "sqrt_delta_M": math.sqrt(dM), "sim_sigma_rms": float(np.mean(walk_rms)), "sim_sigma_dn": float(np.mean(walk_dn)), "sim_dn_p95": float(np.percentile(walk_dn, 95)), "sim_indep_point_rms": float(np.mean(dot_rms)), "sim_indep_point_dn": float(np.mean(dot_dn))}) say("CONTROL C (known answer, Poisson random walk on the same grid, %d trials; the second " "number is the WRONG model -- independent point noise -- kept to show the trap):" % MC_TRIALS) out["control_C"] = ctrl_c for c in ctrl_c: say(" x=%.2e pts=%4d sqrt(delta_M)=%.4e | walk sigma_rms=%.4e dn=%.4e (p95 %.4e) " "| indep-point sigma_rms=%.4e" % (c["x"], c["points"], c["sqrt_delta_M"], c["sim_sigma_rms"], c["sim_sigma_dn"], c["sim_dn_p95"], c["sim_indep_point_rms"])) # ---------------- MEASUREMENT -------------------------------------------------------------- meas = [] for x in PROBES: a = amp(x) if a is None: continue sig = max(a["sigma_rms"], a["sigma_dn"]) Mx = float(Mp(x)) Mpr = float(Mprime(x)) dd_at = float(np.interp(math.log10(x), lx, dd)) c = next((c for c in ctrl_c if c["x"] == x), None) meas.append({"x": x, **a, "sigma_headline": sig, "d_at_x": dd_at, "poisson": math.sqrt(Mx), "M": Mx, "Mprime": Mpr, "W_headline": KAPPA * sig / Mpr, "W_poisson": KAPPA * math.sqrt(Mx) / Mpr, "W_resid": KAPPA * abs(dd_at) / Mpr, "eps_headline": KAPPA * sig / Mpr / x, "sim_sigma_rms": c["sim_sigma_rms"] if c else None, "sim_sigma_dn": c["sim_sigma_dn"] if c else None, "sqrt_delta_M": c["sqrt_delta_M"] if c else None, "rel_to_sim_rms": (a["sigma_rms"] / c["sim_sigma_rms"]) if c else None, "rel_to_sim_dn": (a["sigma_dn"] / c["sim_sigma_dn"]) if c else None, "r1091": R1091.get(round(math.log10(x))) if abs(math.log10(x) - round( math.log10(x))) < 1e-9 else None}) m = meas[-1] say("x=%.3e pts=%4d | sigma_rms=%.4e sigma_dn=%.4e sigma_up=%.4e -> headline=%.4e | " "d(x)=%+.4e | Poisson=%.4e | W_meas=%.4e W_poisson=%.4e W_resid=%.4e | eps=%.4e" % (x, m["points"], m["sigma_rms"], m["sigma_dn"], m["sigma_up"], sig, dd_at, m["poisson"], m["W_headline"], m["W_poisson"], m["W_resid"], m["eps_headline"])) if c: say(" control C: measured/simulated = %.3f (rms), %.3f (one-sided down); " "measured/sqrt(delta_M) = %.3f (rms), %.3f (down)" % (m["rel_to_sim_rms"], m["rel_to_sim_dn"], a["sigma_rms"] / c["sqrt_delta_M"], a["sigma_dn"] / c["sqrt_delta_M"])) out["measurement"] = meas # ---------------- amplitude growth, measured (this replaces #1091's x^0.48 inference) ------- def slope(key, lo=1e12, hi=3e18): pts = [m for m in meas if lo <= m["x"] <= hi] return float(np.polyfit(np.log10([m["x"] for m in pts]), np.log10([m[key] for m in pts]), 1)[0]), len(pts) s_rms, n_rms = slope("sigma_rms") s_dn, n_dn = slope("sigma_dn") lo_pts = [m for m in meas if m["x"] >= 1e17] s_dn_top = float(np.polyfit(np.log10([m["x"] for m in lo_pts]), np.log10([m["sigma_dn"] for m in lo_pts]), 1)[0]) say("MEASURED growth (1e12..3e18, %d points): sigma_rms ~ x^%.3f ; sigma_dn ~ x^%.3f " "(#1091 INFERRED x^0.48 for |d| from ten decade points)" % (n_rms, s_rms, s_dn)) say("MEASURED top-local growth (1e17..3e18): sigma_dn ~ x^%.3f" % s_dn_top) out["growth"] = {"sigma_rms": s_rms, "sigma_dn": s_dn, "sigma_dn_top": s_dn_top, "fit_points": n_rms} # ---------------- the frontier at 1e19: measured vs #1091's assumed -------------------------- Mp19 = float(Mprime(1e19)) top = [m for m in meas if m["x"] == 3e18][0] ext = {} for tag, key, sob in (("rms", "sigma_rms", s_rms), ("dn", "sigma_dn", s_dn), ("dn_toplocal", "sigma_dn", s_dn_top)): sig = top[key] * (1e19 / 3e18) ** sob W = KAPPA * sig / Mp19 ext[tag] = {"sigma": sig, "slope": sob, "W": W, "eps": W / 1e19} head = max(ext["rms"]["sigma"], ext["dn"]["sigma"], ext["dn_toplocal"]["sigma"]) keys = [k for k, v in ext.items() if v["sigma"] == head] W_head = KAPPA * head / Mp19 eps19 = W_head / 1e19 say("") say("EXTRAPOLATED FRONTIER AT THE CENSUS OF #1091 (1e19), measured yardstick, kappa=3 " "(anchor: the 3e18 probe, the top of the published tables):") for k in ("rms", "dn", "dn_toplocal"): v = ext[k] say(" sigma[%s] = %.4e (slope %.3f) -> W = %.4e, eps = %.4e%s" % (k, v["sigma"], v["slope"], v["W"], v["eps"], " <-- headline" if k in keys else "")) out["extrapolation_1e19"] = ext out["headline_1e19"] = {"sigma": head, "W": W_head, "eps": eps19, "from": keys} sig_head = head # ---------------- FALSIFIER (return #1091's own words) -------------------------------------- assumed = R1091[19]["sigma_resid"] ratio = sig_head / assumed verdict = "WEAKENS" if ratio > 1 else "TIGHTENS" say("") say("FALSIFIER (pre-registered in return #1091): measured sigma_osc(1e19) = %.4e vs the assumed " "endpoint yardstick |d(1e19)| = %.4e" % (sig_head, assumed)) say(" ratio measured/assumed = %.3f -> the frontier %s by that factor: eps = %.3e " "(#1091 headline 1.41e-8)" % (ratio, verdict, eps19)) say(" for the record, #1091's other two assumed yardsticks: Poisson 3.877e11 (eps 3.88e-8), " "trend-fit 4.021e13 (eps 4.02e-6); the measured W is %.3e = %.3e x the assumed trend-fit W" % (W_head, W_head / R1091[19]["W_detrend"])) out["falsifier"] = {"measured_sigma_1e19": sig_head, "assumed_sigma_resid_1e19": assumed, "ratio": ratio, "verdict": verdict, "eps_measured": eps19, "eps_1091_headline": 1.41e-8, "W_measured": W_head, "W_1091_resid": R1091[19]["W_resid"], "W_1091_detrend": R1091[19]["W_detrend"], "ratio_to_detrend": W_head / R1091[19]["W_detrend"]} # ---------------- side by side with #1091 at the shared decades ----------------------------- say("") say("SIDE BY SIDE at the decade grid (W, kappa=3): measured vs #1091's assumed yardsticks") say(" x W_meas W_1091_resid ratio W_1091_trendfit ratio") side = [] for m in meas: r = m["r1091"] if not r: continue side.append({"x": m["x"], "W_meas": m["W_headline"], "W_1091_resid": r["W_resid"], "ratio_resid": m["W_headline"] / r["W_resid"], "W_1091_detrend": r["W_detrend"], "ratio_detrend": m["W_headline"] / r["W_detrend"], "eps_meas": m["eps_headline"]}) say(" %.0e %.4e %.4e %.3f %.4e %.4f" % (m["x"], m["W_headline"], r["W_resid"], m["W_headline"] / r["W_resid"], r["W_detrend"], m["W_headline"] / r["W_detrend"])) out["side_by_side"] = side # ---------------- the window law, from the measured amplitude -------------------------------- pts = [m for m in meas if m["x"] >= 1e13] pW = float(np.polyfit(np.log10([m["x"] for m in pts]), np.log10([m["W_headline"] for m in pts]), 1)[0]) pe = float(np.polyfit(np.log10([m["x"] for m in pts]), np.log10([m["eps_headline"] for m in pts]), 1)[0]) say("") say("WINDOW LAW from the MEASURED yardstick (1e13..3e18): W ~ x^%.3f, eps = W/x ~ x^%.3f " "(#1091 DERIVED x^0.55 and x^-0.45 from its inferred scale)" % (pW, pe)) out["window_law"] = {"W_exponent": pW, "eps_exponent": pe} # ---------------- the amplitude LAW: is sigma proportional to sqrt(delta_M)? --------------- # A yardstick that is a law rather than a table needs an x-independent constant. For a Poisson # walk sigma = c*sqrt(delta_M); the measured c is read off the same windows. say("") say("AMPLITUDE LAW: c(x) := sigma(x)/sqrt(delta_M), delta_M = model change across the window") crows = [] for m in meas: if not m["sqrt_delta_M"]: continue c_r, c_d = m["sigma_rms"] / m["sqrt_delta_M"], m["sigma_dn"] / m["sqrt_delta_M"] crows.append({"x": m["x"], "c_rms": c_r, "c_dn": c_d, "sqrt_delta_M": m["sqrt_delta_M"]}) say(" x=%.2e sqrt(delta_M)=%.3e c_rms=%.4f c_dn=%.4f" % (m["x"], m["sqrt_delta_M"], c_r, c_d)) core = [c for c in crows if c["x"] >= 1e13] c_rms_m = float(np.mean([c["c_rms"] for c in core])) c_dn_m = float(np.mean([c["c_dn"] for c in core])) c_dn_sd = float(np.std([c["c_dn"] for c in core])) c_rms_sd = float(np.std([c["c_rms"] for c in core])) say(" over 1e13..3e18 (%d probes): c_rms = %.4f +- %.4f ; c_dn = %.4f +- %.4f (spread %.0f%%)" % (len(core), c_rms_m, c_rms_sd, c_dn_m, c_dn_sd, 100 * c_dn_sd / c_dn_m)) # analytic frontier implied by the law: delta_M ~ 2 sinh(h ln10) x M'(x), so # sigma = c sqrt(2 sinh(h ln10) x M'(x)) and W = 3 sigma / M'. shrink = 2 * math.sinh(HALF_DECADE * math.log(10)) law19 = {} for tag, c in (("rms", c_rms_m), ("dn", c_dn_m)): sig = c * math.sqrt(shrink * 1e19 * Mp19) W = KAPPA * sig / Mp19 law19[tag] = {"c": c, "sigma": sig, "W": W, "eps": W / 1e19} say(" LAW at 1e19 with c_%s=%.4f: sigma=%.4e -> W=%.4e, eps=%.4e" % (tag, c, sig, W, W / 1e19)) out["amplitude_law"] = {"rows": crows, "c_rms_mean": c_rms_m, "c_rms_sd": c_rms_sd, "c_dn_mean": c_dn_m, "c_dn_sd": c_dn_sd, "law_at_1e19": law19, "window_factor": shrink} say(" (a Poisson walk would give c_dn = %.3f by control C, so the real counts sit at %.2f x " "that: smoother than Poisson at this resolution)" % (np.mean([c["sim_sigma_dn"] / c["sqrt_delta_M"] for c in ctrl_c if c["x"] >= 1e13]), c_dn_m / np.mean([c["sim_sigma_dn"] / c["sqrt_delta_M"] for c in ctrl_c if c["x"] >= 1e13]))) # ---------------- CONTROL D: the same measurement from "a few hundred" points --------------- anchors = np.linspace(lx[0], lx[-1], 600) pick = np.unique(np.array([int(np.argmin(np.abs(lx - a))) for a in anchors])) lx2, dd2 = lx[pick], dd[pick] say("") say("CONTROL D: the assignment asks for a few hundred points; re-measuring on a %d-point " "log-spaced sub-sample of the fine grid" % len(pick)) ctrl_d = [] for x in PROBES: sel = (lx2 >= math.log10(x) - HALF_DECADE) & (lx2 <= math.log10(x) + HALF_DECADE) if sel.sum() < 5: continue res = resid(lx2[sel], dd2[sel]) s_r, s_d = float(np.sqrt((res ** 2).mean())), float(max(-res.min(), 0.0)) full = next(m for m in meas if m["x"] == x) ctrl_d.append({"x": x, "points": int(sel.sum()), "sigma_rms": s_r, "sigma_dn": s_d, "full_sigma_rms": full["sigma_rms"], "full_sigma_dn": full["sigma_dn"], "ratio_rms": s_r / full["sigma_rms"], "ratio_dn": s_d / full["sigma_dn"]}) say(" x=%.2e pts=%2d | 300-pt sigma_rms=%.4e dn=%.4e | full sigma_rms=%.4e dn=%.4e | " "ratio %.2f / %.2f" % (x, int(sel.sum()), s_r, s_d, full["sigma_rms"], full["sigma_dn"], s_r / full["sigma_rms"], s_d / full["sigma_dn"])) out["control_D"] = {"subsample_points": int(len(pick)), "rows": ctrl_d, "median_ratio_rms": float(np.median([r["ratio_rms"] for r in ctrl_d])) if ctrl_d else None, "median_ratio_dn": float(np.median([r["ratio_dn"] for r in ctrl_d])) if ctrl_d else None} out["log"] = log with open(os.path.join(HERE, "frontier3.json"), "w", encoding="utf-8") as fh: json.dump(out, fh, indent=1, default=str) return 0 if __name__ == "__main__": sys.exit(main())