#!/usr/bin/env python3
"""verify_P130.py -- Addendum 130: C_A = 3 from Peirce sectors."""

from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent))
from verify_common import CheckResult, Verifier


class ModernVerifier(Verifier):
    """Local adapter: tolerance logic inherited byte-identical from
    verify_common.Verifier; only the output layer is modernised."""

    def __init__(self, name: str) -> None:
        self.name = name
        self.results = []
        print(name)

    def record(self, label, ok, computed="", claimed="", detail=""):
        self.results.append(CheckResult(label, ok, computed, claimed, detail))
        n = len(self.results)
        desc = f"{label} -- {detail}" if detail else label
        print(f"  [{'PASS' if ok else 'FAIL'}] {n:>2}. {desc}")
        if computed != "" or claimed != "":
            print(f"        computed: {computed}")
            print(f"        claimed : {claimed}")
        return ok

    def summary(self):
        passed = sum(r.ok for r in self.results)
        failed = len(self.results) - passed
        print(f"\n{'='*60}\nRESULT: {passed} PASS / {failed} FAIL")
        return 1 if failed else 0


v = ModernVerifier("P130 -- Adjoint Casimir")
ROOT = Path(__file__).resolve().parents[1]
TEX = (ROOT / "130_Addendum_AdjointCasimir.tex").read_text()

marks = [1, 1, 1]
rank_g2 = 2
h_g2 = 6
roots_g2 = rank_g2 * h_g2
dim_g2 = roots_g2 + rank_g2
a2_roots = 2 * 3
peirce_ratio = (3 * 8) / 8

v.record("TeX source is present", "C_A = 3" in TEX and "Peirce Off-Diagonal" in TEX)
v.check("affine A2 marks sum", sum(marks), 3, rel=0)
v.check("standard SU(3) adjoint Casimir h-dual", 3, 3, rel=0)
v.check("Peirce sector dimension ratio", peirce_ratio, 3, rel=0)
v.check("G2 root count from rank times Coxeter number", roots_g2, 12, rel=0)
v.check("G2 Lie algebra dimension", dim_g2, 14, rel=0)
v.check("A2 root count", a2_roots, 6, rel=0)
v.check("SU(3) adjoint dimension", 3**2 - 1, 8, rel=0)
v.record(
    "paper gives the standard highest-root mark route",
    "highest root is" in TEX and "coefficients" in TEX and "1 + 1 + 1 = 3" in TEX,
    computed="A2 highest-root/affine-mark route found",
    claimed="C_A=h^vee=3 route",
)

v.record(
    "derivation avoids standard Lie-theory input",
    False,
    computed="the proof explicitly uses the standard facts C_A=h^vee and affine Dynkin marks for SU(3)",
    claimed="without invoking h^vee=N for SU(N) by hand",
    detail="Expected independence/status fail.",
)
v.record(
    "affine Dynkin nodes are constructed as Peirce sectors",
    False,
    computed="the paper asserts a correspondence P12/P13/P23 <-> affine A2 nodes, but does not define a map from Jordan idempotents/sectors to the affine root datum",
    claimed="three nodes correspond bijectively to the three Peirce sectors",
    detail="Expected construction gap.",
)
v.record(
    "off-diagonal cells carry eight imaginary octonion directions",
    False,
    computed="each O cell is 8-real-dimensional, while Im(O) is 7-real-dimensional",
    claimed="each off-diagonal cell carries eight imaginary octonion directions",
    detail="Expected dimension fail.",
)
v.record(
    "three diagonal idempotents are the SU(3) Cartan generators",
    False,
    computed="SU(3) has rank 2; three diagonal idempotents have one trace/sum relation and cannot be three independent Cartan generators",
    claimed="e11,e22,e33 are the Cartan generators",
    detail="Expected rank/counting fail.",
)
v.record(
    "dimension ratio computes a quadratic Casimir rather than a count",
    False,
    computed="(3*8)/8 counts three Peirce sectors per octonion-sized sector; no adjoint trace form or root-length normalization is computed",
    claimed="C_A = dim(P12+P13+P23)/dim(O) = 3",
    detail="Expected proof gap.",
)
v.record(
    "sector Hurwitz norms force affine Dynkin marks",
    False,
    computed="unit octonion norm explains a vector-length convention, not the affine Dynkin null vector or highest-root coefficients",
    claimed="each mark is 1 because each sector carries one unit of color weight by Hurwitz norm",
    detail="Expected Lie/Jordan bridge gap.",
)
v.record(
    "b1 is fully first-principles closed after P130",
    False,
    computed="the arithmetic is correct, but C_A closure still depends on standard SU(3) root theory plus asserted Peirce correspondence",
    claimed="b1=116/3 is derived entirely from J3(O)",
    detail="Expected closure-status fail.",
)

sys.exit(v.summary())
