#!/usr/bin/env python3 """Job #278: sensitivity of the registered rule's X1 = 79 verdict (phase1-T3prep-decision-rule.md ยง1). Sensitivities only; the verdict is decide.py's. Leave-one-out over the 18 window terms, and each A144311 term 47..79 moved by +-6.""" import json, math G = {int(p): v for p, v in json.load(open('a144311-g2.json')).items()} 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 return b, math.sqrt(sum((y - a - b * x) ** 2 for x, y in zip(xs, ys)) / (n - 2) / sxx), n def verdict(g, window): xs = [math.log(p) for p in window]; ys = [math.log(g[p] / p ** 2) for p in window] b, se_nom, n = ols(xs, ys) se = max(1.55 * se_nom, 1.052 / n) v = 'FALLS' if b + 3 * se < 0 else ('RISES' if b - 3 * se > 0 else 'FLAT') w5 = sorted(set(window) | {5, 7}) b5, _, _ = ols([math.log(p) for p in w5], [math.log(g[p] / p ** 2) for p in w5]) if v != 'FLAT' and (b5 < 0) != (b < 0): v = 'FLAT (gate)' return b, se, b / se, v win = [p for p in sorted(G) if 11 <= p <= 79] b, se, z, v = verdict(G, win) print(f'base X1=79 n={len(win)}: b={b:.4f} se_honest={se:.4f} z={z:.2f} {v}; b would need to exceed {-3*se:.4f} (a shift of {(-3*se)-b:+.4f}) to read FLAT') print('\nleave-one-out (window minus one prime; the rule itself forbids gaps, so these are sensitivities only):') flips = 0 for p in win: w = [q for q in win if q != p] bb, ss, zz, vv = verdict(G, w) flips += vv != 'FALLS' print(f' drop {p:2d}: b={bb:.4f} se={ss:.4f} z={zz:.2f} {vv}') print(f' {flips} of {len(win)} single drops read other than FALLS') print('\nliterature term moved by +-6 (one at a time):') fl = 0 for p in [q for q in win if q >= 47]: for d in (-6, 6): g2 = dict(G); g2[p] += d bb, ss, zz, vv = verdict(g2, win) fl += vv != 'FALLS' print(f' G2({p}#) {G[p]}{d:+d}: b={bb:.4f} z={zz:.2f} {vv}') print(f' {fl} of {2*len([q for q in win if q >= 47])} perturbations read other than FALLS')