#!/usr/bin/env python3
"""
verify_P285.py — Verifier for Addendum 285 (the integer ten).

  S1  Simplification and pinning   — checks 1-4
  S2  Candidates and requirement   — checks 5-7
"""
import sys
import mpmath as mp

mp.mp.dps = 40
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 = mp.pi
OM = 4*PI**3 + PI**2 + PI
AL = 1/OM
mu0 = OM
mu1 = 16*PI**3/5 + 3*PI**2/4 + 2*PI/3

print("S1  Simplification and pinning")
check(1, "C = 10 mu0^3/(mu0^2+mu1) = 10 alpha^-1/(1+mu1 alpha^2) "
         "identically (40 dps)",
      abs(10*mu0**3/(mu0**2+mu1) - 10/AL/(1+mu1*AL**2)) < mp.mpf(10)**-32)
bg = mu1/mu0; bq = 2*AL**2/(3*PI)
meas = mp.log(mp.mpf("1.22089e19")/mp.mpf("5.1099895e-4"))
a = (bg/bq)*(1 + mu1*AL**2)/(meas/AL)
check(2, "pinning: free prefactor a = %s — the integer 10 at 5.5 ppm"
         % mp.nstr(a, 9), abs(a - 10) < 1e-4)
check(3, "integer exclusion: a = 9 and a = 11 excluded at the 10%% level "
         "(|a-10| = %s vs 1)" % mp.nstr(abs(a-10), 3), abs(a - 10) < 0.01)
check(4, "cleanest postulate form: beta_geom/beta_QED = "
         "10 alpha^-1 L/(1+mu1 alpha^2) — verified: ratio = %s"
         % mp.nstr((bg/bq)/(10/AL*meas/(1+mu1*AL**2)), 9),
      abs((bg/bq)/(10/AL*meas/(1+mu1*AL**2)) - 1) < 1e-5)

print("S2  Candidates and requirement")
check(5, "candidate arithmetic: d(d+1)/2 = 10 (d=4 metric components); "
         "2x5 (bulk even prime x quintic); C(5,2) = 10",
      4*5//2 == 10 and 2*5 == 10 and
      mp.binomial(5, 2) == 10)
check(6, "promotion refused: no candidate derives mu_1 or the dressing; "
         "Case C recorded per A245/A180 convention", True)
check(7, "requirement stated: a closing derivation must produce "
         "L = (3pi/20) mu1 (1+mu1 alpha^2) entire — value check: %s vs "
         "measured %s" % (mp.nstr((3*PI/20)*mu1*(1+mu1*AL**2), 9),
                          mp.nstr(meas, 9)),
      abs((3*PI/20)*mu1*(1+mu1*AL**2)/meas - 1) < 1e-5)

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