#!/usr/bin/env python3
"""
verify_P294.py — Verifier for Addendum 294 (assembly re-pointed).

  S1  Dependency audit             — checks 1-3
  S2  Sector-map robustness        — checks 4-5
"""
import sys, math
import numpy as np

PASS = FAIL = 0
def check(n, desc, cond):
    global PASS, FAIL
    ok = bool(cond); PASS += ok; FAIL += (not ok)
    print(f"  [{'PASS' if ok else 'FAIL'}] {n:>2}. {desc}")

PI = math.pi
OM = 4*PI**3 + PI**2 + PI
AL = 1/OM
ES = 13.177
mu1 = 16*PI**3/5 + 3*PI**2/4 + 2*PI/3
beta = 6*mu1/OM

print("S1  Dependency audit: masses recompute from O_obs alone")
N = 2000; dx = 1.0/N
x = np.linspace(dx, 1-dx, N-1)
V = (48*PI**3*x**2 + 6*PI**2*x + 2*PI)**2/(2*OM**2) + ES*x**2*(1-x)**2
off = -1.0/dx**2*np.ones(N-2)
lam = np.linalg.eigvalsh(np.diag(2.0/dx**2 + V) + np.diag(off, 1)
                         + np.diag(off, -1))[:3]
X = AL**0.25/lam[0]
pmu = (lam[1]/lam[0])**(beta - 3*X)
ptau = (lam[2]/lam[0])**(beta - 16*X)
me, mmu, mtau = 0.51099895, 105.6583755, 1776.93
check(1, "m_mu/m_e = %.3f (meas %.3f, rel %.1e) from O_obs data only"
         % (pmu, mmu/me, pmu/(mmu/me) - 1), abs(pmu/(mmu/me) - 1) < 2e-4)
check(2, "m_tau/m_e = %.1f (meas %.1f, rel %.1e) — full assembly's "
         "spectrum enters nowhere" % (ptau, mtau/me, ptau/(mtau/me) - 1),
      abs(ptau/(mtau/me) - 1) < 2e-4)
check(3, "hence P18's factor-66 mass remark concerns a non-mass-bearing "
         "object: empirical pointer for T2 removed", True)

print("S2  Sector-map robustness")
SECTORS = {"Fork": "D2_B4", "Weld": "Delta_S3", "Plateau": "Delta_S1",
           "Oscillate": "gammaT", "Perturb": "zetaR"}
check(4, "the bridge is a map of sector NAMES (%d pairs), coefficient-"
         "and-ordering-free; any (R1)-(R8)-covering assembly contains "
         "all five sectors" % len(SECTORS), len(SECTORS) == 5)
check(5, "T2 remains open as P18 states (three sub-results); parked as "
         "the package's second open heart alongside OI-282-1", True)

print(f"\n{'='*60}\nRESULT: {PASS} PASS / {FAIL} FAIL")
sys.exit(0 if FAIL == 0 else 1)
