#!/usr/bin/env python3
"""LUMEN Second Edition -- The Constant chapter verifier.

Checks the fine-structure inverse as a sum of three geometric layers, the honest +2.2 ppm seed
gap of the bare identity, and the parameter-free 'alpha-comma' correction that brings the
prediction to 0.43 ppb of the modern measured value.

Method: exact arithmetic in pi (no fitting). Independently pinned by verify_P036.py.
Measured: CODATA-2022 alpha^-1 = 137.035999177(21)."""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from numpy import pi, sqrt
from se_verify_common import Report

CODATA = 137.035999177
SIG = 0.000000021     # CODATA-2022 1-sigma on alpha^-1
R = Report("The Constant",
    "alpha^-1 = 4pi^3 + pi^2 + pi, its three contributions, the seed gap, and the alpha-comma correction",
    "exact arithmetic in pi; the correction has zero adjustable parameters",
    sources=["CODATA-2022: alpha^-1 = 137.035999177(21)"],
    pins=["verify_P036.py"])

Om = 4*pi**3 + pi**2 + pi
R.check("contribution  bulk 4pi^3", 4*pi**3, None, source="geometric")
R.check("contribution  boundary pi^2", pi**2, None, source="geometric")
R.check("contribution  edge pi", pi, None, source="geometric")
R.check("bare identity  alpha^-1 = 4pi^3+pi^2+pi", Om, kind="note",
        note="137.036304 -- the SEED identity; +2.2 ppm from CODATA, an open gap (registry C-I-01)")
# the alpha-comma: a measurement time-averages an oscillating coupling; kappa = alpha^(5/4)
kappa = (1/Om)**1.25
alpha_meas = Om*sqrt(1 - kappa**2*(1 - pi/Om))
sigma = (alpha_meas - CODATA)/SIG
R.check("alpha-comma corrected  alpha^-1", alpha_meas, CODATA, source="CODATA-2022", sigma=sigma,
        note="Omega*sqrt(1 - kappa^2(1-pi/Omega)), parameter-free")
R.check("residual after correction", abs(alpha_meas-CODATA)/CODATA*1e9, None, unit="ppb", source="vs CODATA")
R.check("the pi-lift to the breath  pi*alpha^-1", pi*Om, 4*pi**4+pi**3+pi**2, source="closed form",
        tol=1e-9, note="same three-term shape, one level up")
R.emit()
