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

Checks the structure of the master operator O-hat: that it is an 8-sector sum, that the runtime
'Wheel' maps five named moves onto five of those sectors, that the three-family generator
T_cycle is an order-3 rotation with eigenvalues {1, w, w^2}, and the uniqueness accounting
(5 sectors forced by named theorems, 2 fixed multipliers, 1 foundational form).

Method: exact structural and group-theoretic checks (numpy). The honest counterpoint -- the
eigenvalue route to the masses failed by a factor of 66 -- is recorded as a row, not hidden.
Independently pinned by verify_P018.py, verify_P349b.py, verify_P399.py."""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import numpy as np
from se_verify_common import Report

R = Report("The Kernel",
    "the 8-sector master operator, the Wheel bridge, and the uniqueness accounting",
    "exact structural / group-theoretic checks (numpy)",
    sources=["measured m_mu/m_e = 206.768 (PDG), for the recorded eigenvalue-route failure"],
    pins=["verify_P018.py", "verify_P349b.py", "verify_P399.py"])

sectors = ["D2_B4","Delta_S3","Delta_S1","V_self","lambda*rho","gamma*T_cycle","zeta*R","beta*M"]
R.check("O-hat sector count", len(sectors) == 8, kind="fact", note=" + ".join(sectors))
wheel = {"Fork":"D2_B4","Weld":"Delta_S3","Plateau":"Delta_S1","Oscillate":"gamma*T_cycle","Perturb":"zeta*R"}
R.check("Wheel <-> O-hat bridge (5 moves)", all(v in sectors for v in wheel.values()), kind="fact",
        note=", ".join("%s=%s" % (k, v) for k, v in wheel.items()))
# T_cycle: order-3 rotation generating the three families
w = np.exp(2j*np.pi/3)
T = np.diag([1, w, w**2])
R.check("T_cycle^3 = I (three families)", np.allclose(T@T@T, np.eye(3)), kind="fact",
        note="eigenvalues {1, w, w^2}, w = exp(2pi i/3)")
R.check("sectors forced by named theorems", 5, 5, source="audit (A349b)", tol=1e-9,
        note="2 Laplacians, bulk Lichnerowicz, T_cycle, RG generator")
R.check("sectors = fixed multipliers", 2, 2, source="audit", tol=1e-9, note="lambda*rho, beta*M")
R.check("genuinely open form", 1, 1, source="audit", tol=1e-9, note="V_self, closes to the foundation")
# honest: the eigenvalue route to lepton masses failed
R.check("eigenvalue route to m_mu/m_e", "3.1 vs 206.8 (PDG)", kind="note",
        note="recorded FAILURE, off by ~66x; the self-lensing route (Matter chapter) is the one that works")
R.emit()
