#!/usr/bin/env python3 # -*- coding: utf-8 -*- # JOB #2083: THE POOLED-R POWER FLOOR. Derived by textual patch from the lane's OWN # instrument work/p2046/frontier9.py (job #2079, return #1111) -- the same table loader, # estimator definitions, fGn family, anchors and sub-ranges. The base docstring, which is # the #1111 pre-registration, is unchanged below. """MAY THE eps TABLE BE PROMOTED? Pre-registered replication + disjoint sub-range check (job #2079). THE QUESTION (return #1108's registered next step, verbatim). #1108 found the residual's increments Gaussian-consistent, confirmed the fGn shape only at w = 0.02 decades with inverted H = 0.42 (its registered w = 0.20 channel had a family separation of just 1.7 sd), and reported a conditional eps table: eps(1e19) would move from 1.9765e-08 (H = 1/2) to 1.3773e-08 / 1.4301e-08 / 1.4628e-08 at H = 0.404 / 0.414 / 0.42. It declined to promote that table because the licensing width was chosen POST HOC. WHAT THIS RUN DOES, with everything fixed before any number is computed. PART 1, replication. The shape channel at the DECLARED widths w = 0.02, 0.03 and 0.05 decades -- 0.02 is the width #1108 found, 0.03 and 0.05 are declared alternates so that no width is chosen afterwards -- against a denser H grid (0.36 to 0.50 in steps of 0.02) and 240 replicates per H, all through the identical estimator. Primary statistic: the non-overlapping standardised increment lag-1 autocorrelation rho1(w), inverted through the synthetic family curve. ACCEPTANCE, fixed here: the inverted H at w = 0.02 lies within +-0.03 of 0.42. PART 2, out of sample. The whole three-channel inversion is repeated on TWO DISJOINT sub-ranges -- LOW = [1e13, 1e15) and HIGH = [1e15, 4e18] -- with the channels (a) r_dn(x) = measured local one-sided amplitude / the #1106 walk expectation at the same anchor (the walk expectation is H-independent and is loaded from frontier6.json), (b) R = mean r_dn / c_int(0.2) measured within the sub-range, (c) rho1 at w = 0.02 measured within the sub-range, each inverted against synthetic curves recomputed RESTRICTED TO THAT SUB-RANGE's anchors (a response curve is not transferable across anchor sets), 150 replicates per H for (c) and 50 for (a) and (b) on a 5-point H grid (0.38, 0.41, 0.44, 0.47, 0.50). The sub-ranges are disjoint; the FULL range (which produced 0.404 / 0.414 / 0.42) is the sample both halves must reproduce. PRE-REGISTERED DECISION RULE (fixed before the run). PROMOTE the eps table iff ALL of: (i) the w = 0.02 full-range inversion is within +-0.03 of 0.42; (ii) both sub-ranges' rho1(w=0.02) inversions are within +-0.05 of 0.42; (iii) within each sub-range the three channels agree with each other within 2 se (of the noisiest) AND all three invert INSIDE the family grid (DEFECT (a) of the first run: a channel that lands outside was being skipped by the agreement test, which let a sub-range whose channels pointed in opposite directions pass vacuously); and (iv) the two sub-ranges' rho1 inversions differ from each other by <= 0.05 (no range dependence). RETRACT (and keep eps at the H = 1/2 value 2.0e-08) iff the two sub-ranges' rho1 inversions differ by more than 0.05, which would make the full-range agreement a coincidence. Anything in between is reported as PARTIAL with the numbers, and the eps table stays conditional. REPORTED WHATEVER HAPPENS: the per-width full-range inversions with their se, the per-sub-range channel table, and the conditional eps range implied by the promoted (or unpromoted) H. Sources cited: TOS pi(x)/pi2(x) tables; returns #1091, #1094, #1101, #1104, #1106, #1107, #1108 (this handle); Davies & Harte (1987) for the fGn generator; the Hurst-estimation-instability literature located in this job's prior-work search (Gomez-Aguila 2022; Raubitzek 2023; the Hurst-estimator comparison reviews) -- the reason a split-half check is the right next move rather than another estimator. """ import gzip import json import math import os import sys import numpy as np # #2083: the gzipped TOS tables and the #1106 walk expectation are loaded from a local copy # of the sibling run's data directory, so this instrument reads the SAME bytes as #1111. HERE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data2083") Z_LOCAL = 0.10 NU = 8192 W_DECLARED = [0.02, 0.03, 0.05] # declared widths for the replication W_PRIMARY = 0.02 H_FULL = [round(0.36 + 0.02 * i, 2) for i in range(8)] # 0.36 .. 0.50 H_SUB = [0.30, 0.33, 0.36, 0.39, 0.42, 0.45, 0.48] # DEFECT (b): the pre-registered grid was # 0.38..0.50 and the LOW half's rho1 and r_dn both inverted BELOW it, so the grid is widened downward; # this is a disclosed design fix made after the first run, not a re-registration. N_FULL = 240 N_SUB_RHO = 120 N_SUB_LEV = 40 SUB_LOW = (1e13, 1e15) SUB_HIGH = (1e15, 4e18) # #2083. PRE-REGISTERED HERE, BEFORE ANY MEASURED POOLED VALUE IS COMPUTED: R = mean r_dn / # c_int(0.2) is underpowered where its denominator spans ~2 decades (#1111). The pooled # estimator keeps the interval WIDTH fixed at 0.2 and widens the BAND to +-1.0 and +-2.0 # decades around the sub-range, so the denominator averages ~4x and ~8x more intervals at the # same scale. The band is CLIPPED to the table's support. Acceptance is unchanged from # #1111: within each half the three channels must agree within 2 se of the noisiest AND invert # INSIDE the family grid; PROMOTION additionally needs the two halves within 0.05. POOL_BANDS = [1.0, 2.0] H_TARGET = 0.42 E_1_2 = 1.9765e-8 LN_RANGE = 43.056 KAPPA = 3.0 Z_ALPHA = 2.7478 TABLES = ["2b00", "2d10", "2d11", "2d12", "2d13", "2d14", "2d15"] A007508 = {10: 27412679, 11: 224376048, 12: 1870585220, 13: 15834664872, 14: 135780321665, 15: 1177209242304, 16: 10304195697298, 17: 90948839353159, 18: 808675888577436} 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 p = s.split() if len(p) < 3 or not p[1].isdigit(): continue tag = p[0] n, e = tag.split("b") if "b" in tag else tag.split("d") rows.append((float(n) * (base ** int(e)), int(p[1]), float(p[2].rstrip(".")))) return rows def fgn(H, n, rng): k = np.arange(n) gam = 0.5 * (np.abs(k - 1) ** (2 * H) - 2 * np.abs(k) ** (2 * H) + np.abs(k + 1) ** (2 * H)) gam[0] = 1.0 c = np.concatenate([gam, np.zeros(1), gam[:0:-1]]) lam = np.maximum(np.real(np.fft.fft(c)), 0.0) n2 = c.size z = (rng.standard_normal(n2) + 1j * rng.standard_normal(n2)) / math.sqrt(2.0) x = np.real(np.fft.fft(np.sqrt(lam) * z)) / math.sqrt(n2) * math.sqrt(0.5) x = x[:n] v = float(np.var(x)) return (x - x.mean()) / math.sqrt(v) if v > 0 else x def resid(Lv, r): A = np.vstack([np.ones_like(Lv), Lv]).T coef, *_ = np.linalg.lstsq(A, r, rcond=None) return r - A @ coef OUT_PATH = 'D:/AI/TwinPrimeProject/.solveathome/twin-primes/runs/bf4-911665bf27f8081b1e/artifacts/check-2083.out.json' def main(): out, log = {"tool": "check-2083.py/job2083", "w_declared": W_DECLARED, "w_primary": W_PRIMARY, "h_full_grid": H_FULL, "h_sub_grid": H_SUB, "n_full": N_FULL, "n_sub_rho": N_SUB_RHO, "n_sub_lev": N_SUB_LEV, "sub_low": SUB_LOW, "sub_high": SUB_HIGH, "h_target": H_TARGET, "eps_half": E_1_2}, [] def dump(): ff = open(OUT_PATH + ".tmp", "w", encoding="utf-8", newline="\n") json.dump(out, ff, indent=1, default=str) ff.close() os.replace(OUT_PATH + ".tmp", OUT_PATH) def say(s): log.append(s) print(s, flush=True) dump() pts = {} for name in TABLES: for x, pi2, model in parse_table(name): pts[x] = (pi2, model) grid = sorted(pts) lx = np.log10(np.array(grid)) modelv = np.array([pts[x][1] for x in grid]) dd = np.array([pts[x][0] - pts[x][1] for x in grid]) dd -= dd[0] a_ok = sum(1 for k, v in A007508.items() if float(10 ** k) in pts and pts[float(10 ** k)][0] == v) say("grid: %d points, log10 x in [%.3f, %.3f]; CONTROL A: A007508 %d/9" % (len(grid), lx.min(), lx.max(), a_ok)) f6 = json.load(open(os.path.join(HERE, "frontier6.json"), encoding="utf-8")) anchors = {r["x"]: r for r in f6["per_census"]} say("anchors from #1106: %s" % sorted("%.3e" % x for x in anchors)) sim_dn = {x: r["c_dn_sim"] for x, r in anchors.items()} # ---- estimators ------------------------------------------------------------------------------ def rho1_w(series, w, lo_x, hi_x, min_pts=4): h = w / 2.0 vals = [] for p in np.arange(math.log10(lo_x) + h, math.log10(hi_x) - h, w): if int(((lx >= p - h) & (lx <= p + h)).sum()) < min_pts: continue a, b = p + h, p - h d = float(np.interp(a, lx, series) - np.interp(b, lx, series)) inc = float(np.interp(a, lx, modelv) - np.interp(b, lx, modelv)) if inc > 0: vals.append(d / math.sqrt(inc)) v = np.array(vals) if v.size < 12: return None v = (v - v.mean()) / v.std(ddof=1) return float((v[:-1] * v[1:]).sum() / float((v ** 2).sum())) def c_int(series, lo_x, hi_x, w=0.20): h = w / 2.0 vals = [] for p in np.arange(math.log10(lo_x) + h, math.log10(hi_x) - h, w): a, b = p + h, p - h d = float(np.interp(a, lx, series) - np.interp(b, lx, series)) inc = float(np.interp(a, lx, modelv) - np.interp(b, lx, modelv)) if inc > 0: vals.append(d / math.sqrt(inc)) return float(np.sqrt(np.mean(np.square(vals)))) if vals else None def local_cdn(series, x): lo, hi = math.log10(x) - Z_LOCAL, math.log10(x) + Z_LOCAL sel = np.flatnonzero((lx >= lo) & (lx <= hi)) if len(sel) < 10: return None Mv = modelv[sel] dM = float(Mv[-1] - Mv[0]) if dM <= 0: return None r = resid(lx[sel], series[sel]) return float(max(-r.min(), 0.0)) / math.sqrt(dM) # ---- PART 1: the declared-width replication --------------------------------------------------- say("") say("PART 1 -- the DECLARED widths %s at a dense H grid, %d replicates per H." % (W_DECLARED, N_FULL)) say(" w n_data | H: " + " ".join("%.2f" % h for h in H_FULL) + " | measured H_inv se(H)") rng = np.random.default_rng(2079) u_grid = np.linspace(lx.min(), lx.max(), NU + 1) Mu = np.interp(u_grid, lx, modelv) dM = np.diff(Mu) def synth(nsteps, seed_rng): g = fgn(H, NU, seed_rng) if nsteps is None else None return None part1, meas_w = {}, {} # synthetic families, one generation per (rep, H) shared across widths fam = {h: [] for h in H_FULL} for H in H_FULL: for _ in range(N_FULL): g = fgn(H, NU, rng) syn_u = np.concatenate([[0.0], np.cumsum(np.sqrt(np.maximum(dM, 0)) * g)]) syn = np.interp(lx, u_grid, syn_u) row = {} for w in W_DECLARED: row[w] = rho1_w(syn, w, 1e9, 4e18) fam[H].append(row) for w in W_DECLARED: m = rho1_w(dd, w, 1e9, 4e18) meas_w[w] = m n_data = len(np.arange(math.log10(1e9) + w / 2, math.log10(4e18) - w / 2, w)) means, sds = [], [] for H in H_FULL: vals = np.array([r[w] for r in fam[H] if r[w] is not None], dtype=float) means.append(float(vals.mean())) sds.append(float(vals.std(ddof=1))) slope = (means[-1] - means[0]) / (H_FULL[-1] - H_FULL[0]) inv = None for i in range(len(H_FULL) - 1): if (means[i] - m) * (means[i + 1] - m) <= 0: inv = H_FULL[i] + (m - means[i]) * (H_FULL[i + 1] - H_FULL[i]) / (means[i + 1] - means[i]) break se = sds[0] / abs(slope) if slope else float("nan") sep = (means[0] - means[-1]) / sds[0] if sds[0] else float("nan") part1["%.2f" % w] = {"measured": m, "means": means, "sds": sds, "inverted_H": inv, "se_H": se, "slope": slope, "separation_sd": sep, "n_data_points": n_data} say(" %.2f %4d | " % (w, n_data) + " ".join("%+.3f" % x for x in means) + " | %+.4f %s %.3f" % (m, ("%.3f" % inv) if inv is not None else "outside", se)) out["part1"] = part1 inv_primary = part1["%.2f" % W_PRIMARY]["inverted_H"] c1 = inv_primary is not None and abs(inv_primary - H_TARGET) <= 0.03 say(" (i) ACCEPTANCE at w = %.2f: H_inv = %s, target %.2f +- 0.03 -> %s" % (W_PRIMARY, ("%.3f" % inv_primary) if inv_primary is not None else "outside", H_TARGET, "PASS" if c1 else "FAIL")) # ---- PART 2: the disjoint sub-range check ----------------------------------------------------- say("") say("PART 2 -- OUT OF SAMPLE on two DISJOINT sub-ranges, all three channels, curves recomputed") say("restricted to each sub-range's own anchors (%d reps for rho1, %d for the level channels)." % (N_SUB_RHO, N_SUB_LEV)) subs = {"LOW": SUB_LOW, "HIGH": SUB_HIGH} sub_anchors = {k: [x for x in anchors if (v[0] <= x < v[1])] for k, v in subs.items()} for k, v in sub_anchors.items(): say(" %s %s: %d anchors" % (k, subs[k], len(v))) rho_fam = {k: {h: [] for h in H_SUB} for k in subs} lev_fam = {k: {h: [] for h in H_SUB} for k in subs} pool_fam = {k: {h: {} for h in H_SUB} for k in subs} for H in H_SUB: buf_rho = {k: [] for k in subs} buf_rdn = {k: [] for k in subs} buf_r = {k: [] for k in subs} buf_rp = {k: {B: [] for B in POOL_BANDS} for k in subs} for _ in range(N_SUB_RHO): g = fgn(H, NU, rng) syn_u = np.concatenate([[0.0], np.cumsum(np.sqrt(np.maximum(dM, 0)) * g)]) syn = np.interp(lx, u_grid, syn_u) for k, (lo, hi) in subs.items(): buf_rho[k].append(rho1_w(syn, W_PRIMARY, lo, hi)) for _ in range(N_SUB_LEV): g = fgn(H, NU, rng) syn_u = np.concatenate([[0.0], np.cumsum(np.sqrt(np.maximum(dM, 0)) * g)]) syn = np.interp(lx, u_grid, syn_u) for k, (lo, hi) in subs.items(): rs = [local_cdn(syn, x) / sim_dn[x] for x in sub_anchors[k] if x in sim_dn] rs = [r for r in rs if r is not None] ci = c_int(syn, lo, hi) cip = {B: c_int(syn, lo / 10.0 ** B, min(hi * 10.0 ** B, 10.0 ** float(lx.max()))) for B in POOL_BANDS} if rs and ci: buf_rdn[k].append(float(np.mean(rs))) buf_r[k].append(float(np.mean(rs)) / ci) for B in POOL_BANDS: if cip.get(B): buf_rp[k][B].append(float(np.mean(rs)) / cip[B]) for k in subs: rho_fam[k][H] = [v for v in buf_rho[k] if v is not None] lev_fam[k][H] = (buf_rdn[k], buf_r[k]) pool_fam[k][H] = {B: buf_rp[k][B] for B in POOL_BANDS} table = {} for k, (lo, hi) in subs.items(): say(" --- %s [%.0e, %.0e) ---" % (k, lo, hi)) if k == "LOW": say(" PRE-REGISTRATION, stated BEFORE the measured pooled value is computed:") say(" bands %s decades, interval WIDTH fixed at 0.2, clipped to the table support;" % POOL_BANDS) for B in POOL_BANDS: fs = [np.array(pool_fam[k][h][B], dtype=float) for h in H_SUB] mm = [float(f.mean()) for f in fs] ss = [float(f.std(ddof=1)) for f in fs] sl = (mm[-1] - mm[0]) / (H_SUB[-1] - H_SUB[0]) say(" band +-%.1f: family %s | sd %.4f | separation %.2f sd | slope %.4f" % (B, " ".join("%+.3f" % x for x in mm), ss[0], (mm[0] - mm[-1]) / ss[0], sl)) m_rho = rho1_w(dd, W_PRIMARY, lo, hi) rs = [anchors[x]["c_dn_meas"] / anchors[x]["c_dn_sim"] for x in sub_anchors[k] if "c_dn_meas" in anchors[x]] ci = c_int(dd, lo, hi) cip_m = {B: c_int(dd, lo / 10.0 ** B, min(hi * 10.0 ** B, 10.0 ** float(lx.max()))) for B in POOL_BANDS} row = {"n_rho": int(np.sum([1 for _ in np.arange(math.log10(lo) + 0.01, math.log10(hi) - 0.01, W_PRIMARY)])), "rho1": m_rho, "r_dn": float(np.mean(rs)), "r_dn_sd": float(np.std(rs, ddof=1)), "c_int": ci, "R": float(np.mean(rs)) / ci if ci else None, "R_pool": {("%.1f" % B): (float(np.mean(rs)) / cip_m[B] if cip_m.get(B) else None) for B in POOL_BANDS}, "channels": {}} chans = [("rho1", m_rho, [rho_fam[k][h] for h in H_SUB]), ("r_dn", row["r_dn"], [lev_fam[k][h][0] for h in H_SUB]), ("R", row["R"], [lev_fam[k][h][1] for h in H_SUB])] for B in POOL_BANDS: chans.append(("R_pool(%.1f)" % B, row["R_pool"]["%.1f" % B], [pool_fam[k][h][B] for h in H_SUB])) for name, measured, fams in tuple(chans): means = [float(np.mean(np.array(f, dtype=float))) for f in fams] sds = [float(np.std(np.array(f, dtype=float), ddof=1)) for f in fams] slope = (means[-1] - means[0]) / (H_SUB[-1] - H_SUB[0]) inv = None for i in range(len(H_SUB) - 1): if (means[i] - measured) * (means[i + 1] - measured) <= 0: inv = H_SUB[i] + (measured - means[i]) * (H_SUB[i + 1] - H_SUB[i]) / (means[i + 1] - means[i]) break se = sds[0] / abs(slope) if slope else float("nan") row["channels"][name] = {"measured": measured, "means": means, "sds": sds, "inverted_H": inv, "se_H": se, "slope": slope} say(" %-5s measured %+.4f | family %s | H_inv %s +- %.3f" % (name, measured, " ".join("%+.3f" % x for x in means), ("%.3f" % inv) if inv is not None else "outside", se)) table[k] = row say(" n_rho = %d, n_anchors = %d, c_int(0.2) = %.4f" % (row["n_rho"], len(sub_anchors[k]), ci)) out["part2"] = table # ---- the pre-registered decision -------------------------------------------------------------- say("") inv_low = table["LOW"]["channels"]["rho1"]["inverted_H"] inv_high = table["HIGH"]["channels"]["rho1"]["inverted_H"] c2 = (inv_low is not None and inv_high is not None and abs(inv_low - H_TARGET) <= 0.05 and abs(inv_high - H_TARGET) <= 0.05) c4 = (inv_low is not None and inv_high is not None and abs(inv_low - inv_high) <= 0.05) agree = {} for k in subs: ch = table[k]["channels"] vals = [(n, c["inverted_H"], c["se_H"]) for n, c in ch.items() if c["inverted_H"] is not None] ok = True for i in range(len(vals)): for j in range(i + 1, len(vals)): tol = 2 * max(vals[i][2], vals[j][2]) if abs(vals[i][1] - vals[j][1]) > tol: ok = False outside = {n: ("below" if c["measured"] < min(c["means"]) else "above") for n, c in ch.items() if c["inverted_H"] is None} ok = ok and not outside agree[k] = {"values": [[v[0], v[1], v[2]] for v in vals], "within_2se": ok, "outside_family": outside} say(" (iii) %s: three channels %s%s -> %s" % (k, " ".join("%s %.3f+-%.3f" % (v[0], v[1], v[2]) for v in vals), ("" if not outside else " [outside the family grid: " + " ".join("%s %s" % (n, d) for n, d in outside.items()) + "]"), "AGREE within 2 se" if ok else "DISAGREE (or incomparable)")) c3 = agree["LOW"]["within_2se"] and agree["HIGH"]["within_2se"] say(" (ii) sub-range rho1 within +-0.05 of 0.42: LOW %s, HIGH %s -> %s" % (("%.3f" % inv_low) if inv_low is not None else "outside", ("%.3f" % inv_high) if inv_high is not None else "outside", "PASS" if c2 else "FAIL")) say(" (iv) the two halves agree within 0.05: %s (|%s - %s|)" % ("PASS" if c4 else "FAIL", ("%.3f" % inv_low) if inv_low is not None else "-", ("%.3f" % inv_high) if inv_high is not None else "-")) if c4 is False: verdict = "retract" elif c1 and c2 and c3 and c4: verdict = "promote" else: verdict = "partial" say("") say("VERDICT: %s" % verdict.upper()) out["criteria"] = {"c1_full_range_w002": bool(c1), "c2_subranges_near_target": bool(c2), "c3_channels_agree": bool(c3), "c4_halves_agree": bool(c4)} out["verdict"] = verdict if verdict == "promote": Hc = float(np.mean([inv_primary, inv_low, inv_high])) se = float(np.mean([part1["%.2f" % W_PRIMARY]["se_H"], table["LOW"]["channels"]["rho1"]["se_H"], table["HIGH"]["channels"]["rho1"]["se_H"]])) say(" PROMOTED: the three independent estimates %s give H = %.3f +- %.3f, and the eps table may" % (["%.3f" % inv_primary, "%.3f" % inv_low, "%.3f" % inv_high], Hc, se)) say(" be stated as eps(1e19) = %.4e +- %.1e (band from H +- %.3f), against the published %.4e." % (E_1_2 * LN_RANGE ** (Hc - 0.5), abs(E_1_2 * LN_RANGE ** (Hc + se - 0.5) - E_1_2 * LN_RANGE ** (Hc - se - 0.5)) / 2.0, se, E_1_2)) out["promoted"] = {"H": Hc, "se_H": se, "eps": E_1_2 * LN_RANGE ** (Hc - 0.5), "eps_band": abs(E_1_2 * LN_RANGE ** (Hc + se - 0.5) - E_1_2 * LN_RANGE ** (Hc - se - 0.5)) / 2.0} elif verdict == "retract": say(" RETRACTED: the two disjoint halves disagree by more than 0.05 in H, so the full-range") say(" agreement is a coincidence; the lane's headline stays at the H = 1/2 value %.4e." % E_1_2) else: say(" PARTIAL: not every pre-registered criterion is met; the eps table stays CONDITIONAL at") say(" %.4e and the published headline is unchanged." % E_1_2) out["log"] = log dump() return 0 if __name__ == "__main__": sys.exit(main())