#!/usr/bin/env python3 # -*- coding: utf-8 -*- """VERIFICATION CHECKER for the decision-margin package (job #2555). WHAT THIS CHECKS, EXACTLY. For j in {16,18,20,22,24,26} it recomputes, from scratch and with no input other than the corpus's own definitions embedded below, the four quantities the package claims: D^(e1)(x)/x the centered consumer's own object, exactly, with the real Moebius signs sigma the standard deviation of D^(e1)(x)/x over 64 matched random-sign controls (same squarefree support, fair coins, seed 20260919+j) M_centered (0.16 + D/x) / sigma with the requirement D/x >= -4/25 M_invariant (0.655162 + P/x) / sigma_P for the split-invariant P(1,e1)/x and it re-runs the three gates the package declares: G1 PROVENANCE at j=16, (U,V)=(3,3), eps'=1/60: D^(e1)/x must equal the corpus's own printed -0.0231 to 5e-5. (It is -0.023063.) This pins the boundary convention e in [1, e1) that the rest of the table inherits. G2 SUPPORT every control draw must have exactly supp(mu) -- same squarefree integers. G3 NEGATIVE the control must MOVE the statistic; a control that does not move is blind. WHAT IT DOES NOT CHECK, AND MUST NOT BE READ AS CHECKING. It does not check any asymptotic statement, any proof, or the corpus's numbers at other scales. It does not independently reproduce the corpus's j=38 census; the package's j=38 figure is an elementary ratio of two numbers REPORTED by that document (0.001476 and 21.816) and is not part of this checker. A pass establishes: this table, on this finite range, under this control. Nothing else. DEFINITIONS (the corpus's own; research/fixed-endpoint-discrepancy.md (2.8)/(2.9), research/centered-discrepancy-measurement.md (9), and D^(e1) = P(1,e1) - Q(1,e1)): Lambda(n) standard (prime powers get log p), mu(n) the Moebius function x = 2^j, e1 = floor(x^(1/2 + 1/60)), U = V = 3, eps' = 1/60 P(1,e1) = -sum_{e odd squarefree, 1 <= e < e1} sum_{m in (x/(2e), x/e], (m,e)=1, mu(m)!=0} mu(m) log(m) Lambda(e m - 2) M = sum_{n in (x/2, x]} Lambda(n-2) mu(n) Q(1,e1) = sum_{e odd squarefree, 1 <= e < e1} mu(e)/phi(e) * (M log e - sum_{n in (x/2,x]} Lambda(n-2) mu(n) log n) D^(e1) = P(1,e1) - Q(1,e1) control : same support, signs replaced by fair coins (no multiplicativity), NTRIALS draws Run: python3 check-decision-margin.py (expects decision-margin-2555.json alongside) Exit: 0 and {"outcome": "pass"} iff every field matches within the stated tolerance. """ import json import os import sys import numpy as np SEED = 20260919 NTRIALS = 64 EPS = EPSP = 1.0 / 60.0 C2 = 0.6601618158468695739278121100145557784326233602847334133194484233354056423 THRESH_CENTERED = 0.16 THRESH_INVARIANT = C2 - 0.005 U = V = 3 # tolerances, and why: the algorithm and the seeds are fixed, so agreement should be exact; the # tolerances only absorb a different BLAS summation order in the dot products, which perturbs a # sum of O(x) terms of size log^2 x. 1e-6 absolute in units of x is ~1e-9 relative at j=26. TOL_RATIO = 1e-6 # on D/x, P/x, control mean, sigma, mean|control| TOL_M = 1e-3 # relative, on M TOL_G1 = 5e-5 # the corpus's own printed 4 decimals def sieve(N): mu = np.ones(N + 1, dtype=np.int8) mu[0] = 0 is_p = np.ones(N + 1, dtype=bool) is_p[:2] = False for p in range(2, N + 1): if not is_p[p]: continue is_p[p * p::p] = False for q in range(p, N + 1, p): mu[q] = -mu[q] pp = p * p if pp <= N: mu[pp::pp] = 0 lam = np.zeros(N + 1, dtype=np.float64) for p in range(2, N + 1): if not is_p[p]: continue q = p while q <= N: lam[q] = np.log(p) q *= p return lam, mu def phi_of(n): r, m, p = n, n, 2 while p * p <= m: if m % p == 0: r = r // p * (p - 1) while m % p == 0: m //= p p += 1 if m > 1: r = r // m * (m - 1) return r def evaluate(x, signs, plan): lamp, logm = plan['lamp'], plan['logm'] n = plan['n'] F = lamp[n - 2].astype(np.float64) * signs[n].astype(np.float64) M = float(np.sum(F)) Ln = float(np.sum(F * logm[n])) P = 0.0 for e, ms, Lev, lg in plan['terms']: P -= float(np.dot(signs[ms].astype(np.float64), lg * Lev)) Q = 0.0 for e in plan['e1_list']: se = int(signs[e]) if se: Q += se / plan['phi'][e] * (M * plan['loge'][e] - Ln) return dict(P=P, Q=Q, D=P - Q) def one_scale(j, lam, mu): x = 2 ** j e1 = int(x ** (0.5 + EPS)) lamp = lam[:x + 1] logm = np.zeros(x + 1, dtype=np.float64) logm[1:] = np.log(np.arange(1, x + 1)) terms, e1_list = [], [] for e in range(1, max(e1, 2)): # [1, e1) -- the corpus's convention, G1 if not (e & 1) or mu[e] == 0: continue e1_list.append(e) lo, hi = x // (2 * e) + 1, x // e if hi < lo: continue m = np.arange(lo, hi + 1) m = m[mu[m] != 0] if m.size == 0: continue if e > 1: m = m[np.gcd(m, e) == 1] if m.size == 0: continue base = e * (m - 1) + (e - 2) L = lamp[base] nz = L != 0 if not nz.any(): continue terms.append((e, m[nz], L[nz], logm[m[nz]])) plan = dict(lamp=lamp, logm=logm, terms=terms, e1_list=e1_list, phi={e: phi_of(e) for e in e1_list}, loge={e: float(np.log(e)) for e in e1_list}, n=np.arange(x // 2 + 1, x + 1)) supp_mu = int(np.count_nonzero(mu)) rng = np.random.default_rng(SEED + j) idx = np.nonzero(mu)[0] ctl, ctlP = [], [] for _ in range(NTRIALS): c = np.zeros(x + 3, dtype=np.int8) c[idx] = rng.choice(np.array([-1, 1], dtype=np.int8), size=idx.size) assert int(np.count_nonzero(c)) == supp_mu, 'G2 FAILED: control support != supp(mu)' r = evaluate(x, c, plan) ctl.append(r['D'] / x) ctlP.append(r['P'] / x) ctl, ctlP = np.array(ctl), np.array(ctlP) real = evaluate(x, mu, plan) if abs(real['D'] / x - ctl.mean()) < 1e-12: raise SystemExit('G3 FAILED: the control does not move the statistic') return dict(x=x, e1=e1, D_over_x=real['D'] / x, P_over_x=real['P'] / x, ctl_mean=float(ctl.mean()), sigma=float(ctl.std(ddof=1)), ctl_absmean=float(np.mean(np.abs(ctl))), sigma_P=float(ctlP.std(ddof=1))) def main(): here = os.path.dirname(os.path.abspath(__file__)) with open(os.path.join(here, 'decision-margin-2555.json'), encoding='utf-8') as fh: tgt = json.load(fh) fails, checked = [], 0 for js, want in sorted(tgt['rows'].items(), key=lambda kv: int(kv[0])): j = int(js) lam, mu = sieve(2 ** j + 2) got = one_scale(j, lam, mu) if j == 16: g1 = abs(got['D_over_x'] - (-0.0231)) print(f'G1 provenance j=16: D^(e1)/x = {got["D_over_x"]:.6f} vs corpus -0.0231 ' f'(|diff| {g1:.2e}, tol {TOL_G1:.0e})') if g1 > TOL_G1: fails.append(f'G1 j=16: {got["D_over_x"]:.6f}') gap = THRESH_CENTERED + got['D_over_x'] M = gap / got['sigma'] gapP = THRESH_INVARIANT + got['P_over_x'] MP = gapP / got['sigma_P'] for k in ('D_over_x', 'P_over_x', 'ctl_mean', 'sigma', 'sigma_P', 'ctl_absmean'): checked += 1 if abs(got[k] - want[k]) > TOL_RATIO: fails.append(f'j={j} {k}: got {got[k]!r} want {want[k]!r}') for nm, val, wx in (('M_centered', M, want['M_centered']), ('M_invariant', MP, want['M_invariant'])): checked += 1 if abs(val - wx) > TOL_M * max(1.0, abs(wx)): fails.append(f'j={j} {nm}: got {val:.4f} want {wx:.4f}') # the qualitative verdicts the package's falsifiers turn on, checked as restatements if j in (16, 18, 20) and not M < 3: fails.append(f'j={j}: M_centered {M:.2f} should be < 3 (pre-registered F2, below 2^22)') if j == 26 and not M >= 3: fails.append(f'j={j}: M_centered {M:.2f} should be >= 3 (pre-registered F2, at 2^26)') if not MP > M: fails.append(f'j={j}: M_invariant {MP:.2f} should exceed M_centered {M:.2f} (F3 outcome)') print(f'j={j:>2d} D/x {got["D_over_x"]:+.6f} (want {want["D_over_x"]:+.6f}) ' f'sigma {got["sigma"]:.6f} (want {want["sigma"]:.6f}) M_c {M:.2f} ' f'(want {want["M_centered"]:.2f}) M_P {MP:.2f} (want {want["M_invariant"]:.2f})') sys.stdout.flush() out = {'outcome': 'pass' if not fails else 'fail', 'fields_checked': checked, 'scales': sorted(int(k) for k in tgt['rows']), 'draws': NTRIALS, 'failures': fails} print(json.dumps(out, indent=1, sort_keys=True)) return 0 if not fails else 1 if __name__ == '__main__': raise SystemExit(main())