#!/usr/bin/env python3 """Job #278: the pre-registered decision rule of research/history/staging/phase1-T3prep-decision-rule.md §1, applied mechanically. Stdlib only. Gate: reproduce §1.7 and §2.1 at X1 = 41 before any new window.""" import json, math exact = json.load(open('ladder.json')) # corpus exact ladder (exact-g2-ladder.js LADDER) + 47, 53 appended lit = json.load(open('a144311-g2.json')) # OEIS A144311 a(n)+1, n = 1..22 (to 79#) corpus_max = 43 # exact-g2-ladder.js LADDER stops at 43# G = {int(p): v for p, v in lit.items()} for p, v in exact.items(): if int(p) <= corpus_max: assert G[int(p)] == v, (p, v, G[int(p)]) def primes_in(a, b): return [p for p in sorted(G) if a <= p <= b] def ols(xs, ys): n = len(xs); mx = sum(xs) / n; my = sum(ys) / n sxx = sum((x - mx) ** 2 for x in xs); sxy = sum((x - mx) * (y - my) for x, y in zip(xs, ys)) b = sxy / sxx; a = my - b * mx rss = sum((y - a - b * x) ** 2 for x, y in zip(xs, ys)) return b, math.sqrt(rss / (n - 2) / sxx), n def rule(X1): ps = primes_in(11, X1) xs = [math.log(p) for p in ps]; ys = [math.log(G[p] / p ** 2) for p in ps] b, se_nom, n = ols(xs, ys) se = max(1.55 * se_nom, 1.052 / n) verdict = 'FALLS' if b + 3 * se < 0 else ('RISES' if b - 3 * se > 0 else 'FLAT / UNRESOLVED') ps5 = primes_in(5, X1) b5, se5, n5 = ols([math.log(p) for p in ps5], [math.log(G[p] / p ** 2) for p in ps5]) if verdict != 'FLAT / UNRESOLVED' and (b5 < 0) != (b < 0): verdict = 'FLAT / UNRESOLVED (sign gate)' s, _, _ = ols(xs, [math.log(math.log(p)) for p in ps]) return dict(X1=X1, n=n, b=b, se_nom=se_nom, se_honest=se, z=b / se, verdict=verdict, b5=b5, n5=n5, s=s, k_hat=(b + 1) / s, se_k=se / s, k_flat=1 / s, grade='corpus exact' if X1 <= corpus_max else ('A144311 Alekseyev 2009' if X1 <= 53 else 'A144311 Wang 2024')) g = rule(41) checks = [('b', g['b'], -0.0694, 5e-5), ('se_nom', g['se_nom'], 0.0747, 5e-5), ('se_honest', g['se_honest'], 0.1169, 5e-5), ('b[5,41]', g['b5'], -0.2025, 5e-5), ('s', g['s'], 0.3302, 5e-5), ('k_hat', g['k_hat'], 2.82, 5e-3), ('se_k', g['se_k'], 0.35, 5e-3)] bad = [c for c in checks if abs(c[1] - c[2]) > c[3]] print('GATE X1 = 41 against note §1.7/§2.1: ' + ('PASS' if not bad else 'FAIL ' + repr(bad))) for c in checks: print(f' {c[0]:10s} here {c[1]: .4f} note {c[2]: .4f}') if bad: raise SystemExit(1) print() print(' X1 n b se_nom se_honest b/se verdict b[5,X1] s k_hat se_k k_flat largest-term grade') for X1 in primes_in(41, 79): r = rule(X1) print(f"{r['X1']:3d} {r['n']:3d} {r['b']: .4f} {r['se_nom']:.4f} {r['se_honest']:.4f} {r['z']: .2f} {r['verdict']:30s} {r['b5']: .4f} " f"{r['s']:.4f} {r['k_hat']:.2f} {r['se_k']:.2f} {r['k_flat']:.3f} {r['grade']}")