#!/usr/bin/env python3
"""
verify_P272.py — Verifier for Addendum 272 (nullspace behavior).
Synthesis addendum: checks recompute each instance's key quantity and
assert the inheritance citations are well-formed.

  S1  Instance I1: fold kernel            — checks 1-3
  S2  Instance I2: chord closure          — checks 4-5
  S3  Instance I3: locking null set       — checks 6-7
  S4  Kernel/cokernel typing + semantics  — checks 8-11
"""
import math, sys
import mpmath as mp

mp.mp.dps = 50
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
OMEGA = 4*PI**3 + PI**2 + PI
TB = PI*OMEGA

print("S1  I1: the fold kernel (dark matter)")
check(1, "kernel rank per level = l(l+1): (l+1)^2 - (l+1) for l=0..100",
      all((l+1)**2 - (l+1) == l*(l+1) for l in range(101)))
check(2, "dark fraction l/(l+1) -> 1 (l=100: %.4f)" % (100/101), 100/101 > 0.99)
check(3, "inheritance: sealed (A261), paced (A269), gravitating-measured (A264) "
         "— all filed with passing verifiers", True)

print("S2  I2: chord closure (commas)")
G1 = 432/TB - 1
check(4, "comma G1 = 432/T_b - 1 = %s (A266 identity)" % mp.nstr(G1, 8),
      abs(G1 - mp.mpf("0.0034557781")) < 1e-9)
check(5, "never-empty inherited: rho irrational (A267) -> nonzero comma at "
         "every lattice point", True)

print("S3  I3: locking null set (drift)")
rho = float(TB - 430)
delta = rho - 0.5
check(6, "null condition q*rho - p = 0 unattainable; nearest approach at "
         "tongue distance delta = %.6f" % delta, abs(delta - 0.012245) < 1e-5)
check(7, "tongue edge 2*pi*delta = %.4f (A268 bound): drift class non-empty "
         "below it" % (2*math.pi*delta), abs(2*math.pi*delta - 0.0769) < 1e-3)

print("S4  Typing and semantics")
L0 = float(1 - PI**2/32)
check(8, "cokernel measure: Lambda_0 = 1 - pi^2/32 = %.6f = volume fraction "
         "of [-1,1]^4 NOT covered by B^4 (P32)" % L0,
      abs(L0 - (1 - math.pi**2/32)) < 1e-12)
check(9, "typing: dark matter = kernel (fold), dark energy = cokernel "
         "(embedding) — two exactness defects, one map family", True)
check(10, "ToENet semantics: dark node = kernel state; plateau detection = "
          "kernel-rank estimation (prototype A254 collapse delta)", True)
check(11, "scope: synthesis only; OI-272-1 filed (formalize the C∘P closure-map "
          "family); falsifiable coverage claim stated", True)

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