#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Does the measured amplitude constant survive a change of WINDOW WIDTH? (follow-on to return #1094) CLAIM UNDER TEST. Return #1094 measured c(x) := sigma(x)/sqrt(delta_M), with delta_M the model change across a +/-0.10-decade window, and found sigma_dn = 0.469 +- 0.154 * sqrt(delta_M) over 1e13..3e18, i.e. the residual of pi2(x) - 2C2 Li2(x) behaves like a Poisson WALK whose local scale is the model increment. A law, not a table, must not depend on the arbitrary window width h. Since delta_M(h) ~ M'(x) x 2 sinh(h ln10), the Poisson-walk prediction is that c is INDEPENDENT of h; a smooth (non-walk) residual would instead give sigma ~ h, hence c ~ sqrt(h). WHAT THIS RUN DOES (read-only, no new sieve, same published TOS tables as #1094): h in {0.05, 0.10, 0.20, 0.40} decades; the estimator is #1094's, per h: window |log10 x - log10 xi| <= h, local least-squares line of d removed, sigma_rms, sigma_dn = -min, sigma_up = max; delta_M := model(last selected point) - model(first selected point) [same convention as #1094]; c_rms := sigma_rms/sqrt(delta_M), c_dn := sigma_dn/sqrt(delta_M). Anchors: probes 1e11..3e18, cells with fewer than MIN_POINTS points are reported as skipped. KNOWN-ANSWER CONTROL (the part that makes this a test rather than a tautology): the detrending estimator is NOT h-independent even for a pure Poisson walk, so the SAME series is computed for a simulated walk with increment variance = model increment (300 trials per cell). The measured sequence is therefore compared with the simulated one, not with 1. PRE-REGISTERED DECISION RULE (fixed here, before the run). R_h := c_h / c_0.10 for the measured data and for the simulated walk, per estimator (rms, dn), averaging c over the probes that are valid at BOTH h and h=0.10 for that estimator. THE LAW HOLDS if, for every h and both estimators, |log(R_h^meas / R_h^sim)| <= log(1.33) -- the 33% spread already measured at h = 0.10 in #1094, i.e. the deviation from the predicted h-scaling stays inside the band the claim itself carries. THE LAW FAILS if any |log(R_h^meas / R_h^sim)| > 2 log(1.33) (a factor 1.77) -- the amplitude then has window dependence beyond the walk, and c is not a constant but a function of an arbitrary choice. Between the two the outcome is reported as INCONCLUSIVE with the numbers, not rounded to either. Secondary, reported whatever happens: the implied eps(1e19) = 3 sigma_h(1e19)/(1e19 M'(1e19)) with sigma_h(1e19) from the law, to show how much the frontier moves with h. Sources cited: TOS pi(x)/pi2(x) tables (sweet.ua.pt/tos/primes.html); A007508; returns #1094 and #1091 (this handle) for the estimator, the constant and the frontier; research route 87. """ 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 H_LIST = [0.05, 0.10, 0.20, 0.40] ANCHOR_H = 0.10 PROBES = [1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 2e18, 3e18] MIN_POINTS = 10 MC_TRIALS = 300 TOL = math.log(1.33) # inside: law holds FAIL = 2 * TOL # beyond: law fails A007508 = {10: 27412679, 11: 224376048, 12: 1870585220, 13: 15834664872, 14: 135780321665, 15: 1177209242304, 16: 10304195697298, 17: 90948839353159, 18: 808675888577436, 19: 7237518093734545} TABLES = ["2b00", "2d10", "2d11", "2d12", "2d13", "2d14", "2d15"] def parse_table(name): 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(".")))) return rows def Mprime(x): L = mp.log(mp.mpf(x)) return 2 * C2 * (1 / L ** 2) * (1 - 2 / L) def main(): out, log = {"tool": "frontier4.py/job2052-followon", "h_list": H_LIST, "anchor_h": ANCHOR_H, "min_points": MIN_POINTS, "mc_trials": MC_TRIALS, "tolerance": {"hold": TOL, "fail": FAIL}}, [] def say(s): log.append(s) print(s, flush=True) byx = {} for name in TABLES: for x, pi2, model in parse_table(name): byx[(x, name)] = (pi2, model) pts = {} for (x, name), (pi2, model) in byx.items(): pts[x] = (pi2, model) grid = sorted(pts) xs = np.array(grid) lx = np.log10(xs) dd = np.array([pts[x][0] - pts[x][1] for x in grid]) # published pi2 - published 2C2 Li2 modelv = np.array([pts[x][1] for x in grid]) say("grid: %d distinct points, log10 x in [%.3f, %.3f]; residual d = pi2 - 2C2 Li2 taken from the " "published columns" % (len(grid), lx.min(), lx.max())) a_ok = sum(1 for k, v in A007508.items() if float(10 ** k) in pts and pts[float(10 ** k)][0] == v) a_tot = sum(1 for k in A007508 if float(10 ** k) in pts) say("CONTROL A: A007508 agreement at the 10^k present in the grid: %d/%d" % (a_ok, a_tot)) rng = np.random.default_rng(2052) 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 cell(x, h, sim): """measured (sim=False) or simulated-walk (sim=True) amplitudes in the +/-h window at x.""" lo, hi = math.log10(x) - h, math.log10(x) + h if lo < lx.min() or hi > lx.max(): return {"x": x, "h": h, "skipped": "window leaves the grid range [%.3g, %.3g]" % (10 ** lx.min(), 10 ** lx.max())} sel = (lx >= lo) & (lx <= hi) idx = np.flatnonzero(sel) n = int(sel.sum()) if n < MIN_POINTS: return {"x": x, "h": h, "skipped": "only %d points in the window (< %d)" % (n, MIN_POINTS)} Mv = modelv[idx] dM = float(Mv[-1] - Mv[0]) if dM <= 0: return {"x": x, "h": h, "skipped": "non-positive model change across the window"} sdM = math.sqrt(dM) L = lx[idx] if not sim: r = resid(L, dd[idx]) s_rms, s_dn, s_up = (float(np.sqrt((r ** 2).mean())), float(max(-r.min(), 0.0)), float(max(r.max(), 0.0))) else: inc = np.diff(Mv) rms_v, dn_v = [], [] 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)]) r = resid(L, walk) rms_v.append(float(np.sqrt((r ** 2).mean()))) dn_v.append(float(max(-r.min(), 0.0))) s_rms, s_dn, s_up = float(np.mean(rms_v)), float(np.mean(dn_v)), float("nan") return {"x": x, "h": h, "points": n, "delta_M": dM, "sqrt_delta_M": sdM, "sigma_rms": s_rms, "sigma_dn": s_dn, "sigma_up": s_up, "c_rms": s_rms / sdM, "c_dn": s_dn / sdM, "skipped": None} cells, sims = {}, {} for h in H_LIST: for x in PROBES: c = cell(x, h, sim=False) cells[(h, x)] = c if not c["skipped"]: sims[(h, x)] = cell(x, h, sim=True) say("") say("MEASURED c = sigma/sqrt(delta_M) by window half-width h (decades in log10 x):") say(" x " + "".join("| h=%.2f c_rms c_dn " % h for h in H_LIST)) for x in PROBES: row = " %.1e " % x for h in H_LIST: c = cells[(h, x)] row += ("| skip " if c["skipped"] else "| %8.4f %7.4f " % (c["c_rms"], c["c_dn"])) say(row) skips = [{"x": c["x"], "h": c["h"], "why": c["skipped"]} for c in cells.values() if c["skipped"]] say(" cells skipped: %d %s" % (len(skips), [(s["x"], s["h"]) for s in skips])) say("") say("SIMULATED (known answer: Poisson walk with increment variance = model increment, %d " "trials/cell) -- this is the estimator's own h-dependence, which no measurement can avoid:" % MC_TRIALS) say(" x " + "".join("| h=%.2f c_rms c_dn " % h for h in H_LIST)) for x in PROBES: row = " %.1e " % x for h in H_LIST: c = sims.get((h, x)) row += ("| -- " if not c or c["skipped"] else "| %8.4f %7.4f " % (c["c_rms"], c["c_dn"])) say(row) # ---- the test: measured h-scaling against simulated h-scaling, both anchored at h = ANCHOR_H ---- def means(key, table, h): vals = [table[(h, x)][key] for x in PROBES if (h, x) in table and not table[(h, x)]["skipped"] and x >= 1e13] return (float(np.mean(vals)), len(vals)) if vals else (None, 0) say("") say("THE TEST. R_h := c_h / c_%.2f, averaged over probes >= 1e13 that are valid at BOTH widths; a " "Poisson-walk residual gives R_h^meas = R_h^sim, and the pre-registered band is log(1.33) = " "%.4f (fail beyond %.4f)." % (ANCHOR_H, TOL, FAIL)) verdicts = [] rows = [] for key in ("c_rms", "c_dn"): base_m, _ = means(key, cells, ANCHOR_H) base_s, _ = means(key, sims, ANCHOR_H) say(" %s: anchor c_%.2f measured %.4f simulated %.4f" % (key, ANCHOR_H, base_m, base_s)) for h in H_LIST: if h == ANCHOR_H: continue cm, nm = means(key, cells, h) cs, ns = means(key, sims, h) if not cm or not cs: say(" h=%.2f: no shared valid cells" % h) continue Rm, Rs = cm / base_m, cs / base_s dev = math.log(Rm / Rs) v = "HOLDS" if abs(dev) <= TOL else ("FAILS" if abs(dev) > FAIL else "INCONCLUSIVE") verdicts.append(v) rows.append({"estimator": key, "h": h, "c_meas": cm, "c_sim": cs, "R_meas": Rm, "R_sim": Rs, "deviation_log": dev, "verdict": v, "n_cells": min(nm, ns)}) say(" h=%.2f: c_meas=%.4f (c_sim=%.4f) -> R_meas=%.3f, R_sim=%.3f, " "log(R_meas/R_sim)=%+.4f %s" % (h, cm, cs, Rm, Rs, dev, v)) overall = ("HOLDS" if verdicts and all(v == "HOLDS" for v in verdicts) else "FAILS" if any(v == "FAILS" for v in verdicts) else "INCONCLUSIVE") say(" VERDICT: the amplitude constant is %s across window widths 0.05..0.40" % ("CONSTANT" if overall == "HOLDS" else "NOT CONSTANT" if overall == "FAILS" else "NOT RESOLVED")) out["test"] = {"rows": rows, "verdict": overall, "per_check": verdicts} # ---- how much the frontier moves with h, via the law sigma = c sqrt(delta_M(h)) --------------- shrink = lambda h: 2 * math.sinh(h * math.log(10)) Mp19 = float(Mprime(1e19)) say("") say("IMPACT ON THE FRONTIER (law with the measured c_dn at each h, extrapolated to the 1e19 census):") imp = [] for h in H_LIST: c, n = means("c_dn", cells, h) if not c: continue sig = c * math.sqrt(shrink(h) * 1e19 * Mp19) W = KAPPA * sig / Mp19 imp.append({"h": h, "c_dn": c, "sigma_1e19": sig, "W_1e19": W, "eps_1e19": W / 1e19, "probes": n}) say(" h=%.2f c_dn=%.4f -> sigma(1e19)=%.3e, W=%.3e, eps=%.3e" % (h, c, sig, W, W / 1e19)) out["frontier_impact"] = imp out["cells"] = [cells[k] for k in cells] out["sim_cells"] = [sims[k] for k in sims] out["log"] = log with open(os.path.join(HERE, "frontier4.json"), "w", encoding="utf-8") as fh: json.dump(out, fh, indent=1, default=str) return 0 if __name__ == "__main__": sys.exit(main())