"""p35_hadrons — the ledger file of 35-hadrons (the 35-hadrons migration, 19 October 2026).

"Ground-State Light Hadron Spectroscopy over Finite Substrate" (Akhtman and Voether, preprint 2026). The paper's predicate
ledger is docs/35-hadrons/35-hadrons-ledger.json. This file binds its python-witnessed predicates to the framework: the table
of keys (generated from the ledger by ci/make_ledgers.py) and the checks of seven blocks. The exact checks call the hadrons
theme (frc/hadrons.py) over the interactions theme's colour field F_4, unitary frames, Haar moments and polynomials; the
readings of the PDG masses and of the finite operators' decimals call the chart theme (frc/chart_hadrons.py) and compare
them with rational bounds. Each check names the predicate(s) it witnesses (LEDGER) and carries a `# 35:XN (<key>)` marker
when it decides one (PREDICATES).

The checks are EXACT or CHART, one kind per check. An EXACT check decides by finite-field, integer or rational arithmetic:
SU(3, F_2) over F_4 by frames with its centre and the colourless content of Λ•(3), the Weyl constant terms of SU(3), the
relations as zero polynomials over their parameters, the Casimir, spin and charge rationals, the admissible shells, and
Sturm's count of the finite confinement operator in Fractions; no float decides anything. A CHART check is a reading of
the PDG masses or of the finite operators' decimals, every float converted exactly before the comparison; its label carries
"[chart]". The paper's own classes were EXACT, MIXED, PROFINITE and CHART, one per package record (src/35-hadrons, fifteen
scripts and the figure script run by hadcommon.py): a MIXED record is an exact check here and a chart check, a PROFINITE
record an exact Sturm bracket and the chart's decimals. FAMILY names the package record each check reproduces, None for
the checks beyond the package (A5 the flavour cube, F1 the exact brackets). The figure script is not reproduced; the
package stays the paper's published witness until its release pins the framework.

The Lean side: the theorems of the hadrons theme (lean/FrcCore/Theme/Hadrons.lean) over the interactions theme's colour
sector (Theme/Fields.lean), the readings on Mathlib (lean/FrcLedger/Theme/Hadrons.lean); the keys in Keys/Hadrons.lean of
both libraries, the certificates Ledgers/P35Hadrons.lean.

The one Ω-hard scale √σ = 440 MeV enters once, declared in the chart data, and only the chart readings use it; the
electromagnetic coupling α is the imported constant. The shells 53, 173, 389, 1373 are the laboratory shells of the
discriminator; no numeral above Ω ∼ 10¹²³ is formed.

    python3 -m frc.ledgers.p35_hadrons         every block, the census; exit 1 if a check fails (≈ 15 s, the Sturm count 9 s)
    python3 -m frc.ledgers.p35_hadrons B       one block (A to G)
    from frc.ledgers.p35_hadrons import R; R.predicate("35:C2")    one predicate: its blocks run once per session

Blocks:  A  the colour frame: SU(3, F_2), its centre, the colourless content, the meson contraction, the moments   (35:C1, X2, C15, X1, X3, X7, P4, C18, C14, C6, C23, P5)
         B  the relations as identities: GMO, the spacing, the third difference, the links, CG, the vector nonet, the gap and the split   (35:C2, X4, C3, X5, C11, C12, C7, X10, X12, C16, C17)
         C  the colour–spin–charge arithmetic: the colour factor, the spin pattern, the Σ–Λ correlators, the charges   (35:C4, C5, X6, C9, X9, C13)
         D  the PDG confrontations                                                          (35:P1, P2, P8, C12, P6, C8, X8, C10, C22, X11, P7, P3, P9, P10, P11)
         E  the single scale: the admissible shells, the residual orders, the ratios at √σ (35:C23, Z1, C20, X13)
         F  the finite operators: the exact Sturm brackets, the Airy decimals, E₀, the forward landing   (35:C16, C17, C19)
         G  the electromagnetic magnitude                                                   (35:C21)

Checks: 34, of them 18 EXACT and 16 CHART (D1–D10, E2, E3, F2, F3, F4, G1). The notebook frc/ledgers/p35_hadrons.ipynb
runs one predicate per cell, the cell's id its key (gate G13).
"""
import sys
from fractions import Fraction as Q
from math import comb

from frc.registry import Registry
from frc import interactions as I
from frc import hadrons as H
from frc import chart_hadrons as CH

# ---- generated by ci/make_ledgers.py from docs/35-hadrons/35-hadrons-ledger.json; edit the ledger, not this table ----
PAPER = "35-hadrons"
KEYS = {"A1": "p35001", "A2": "p35002", "A3": "p35003", "A4": "p35004", "A5": "p35005", "A6": "p35006", "A7": "p35007", "A8": "p35008", "A9": "p35009", "B1": "p35010", "B2": "p35011", "B3": "p35012", "B4": "p35013", "B5": "p35014", "C1": "p35015", "C2": "p35016", "C3": "p35017", "C4": "p35018", "C5": "p35019", "C6": "p35020", "C7": "p35021", "C8": "p35022", "C9": "p35023", "C10": "p35024", "C11": "p35025", "C12": "p35026", "C13": "p35027", "C14": "p35028", "C15": "p35029", "C16": "p35030", "C17": "p35031", "C18": "p35032", "C19": "p35033", "C20": "p35034", "C21": "p35035", "C22": "p35036", "C23": "p35037", "X1": "p35038", "X2": "p35039", "X3": "p35040", "X4": "p35041", "X5": "p35042", "X6": "p35043", "X7": "p35044", "X8": "p35045", "X9": "p35046", "X10": "p35047", "X11": "p35048", "X12": "p35049", "X13": "p35050", "P1": "p35051", "P2": "p35052", "P3": "p35053", "P4": "p35054", "P5": "p35055", "P6": "p35056", "P7": "p35057", "P8": "p35058", "P9": "p35059", "P10": "p35060", "P11": "p35061", "V1": "p35062", "V2": "p35063", "Z1": "p35065"}       # every row of the ledger: its label and its accession key
LEAN = {"C1": "core", "C2": "core, ml", "C3": "core, ml", "C4": "core, ml", "C5": "core, ml", "C6": "core, ml", "C7": "core, ml", "C8": "core, ml", "C9": "core, ml", "C10": "ml", "C11": "core, ml", "C12": "core, ml", "C13": "core, ml", "C14": "core, ml", "C15": "core", "C16": "core, ml", "C17": "core, ml", "C18": "core, ml", "C19": "core, ml", "C20": "core, ml", "C21": "core, ml", "C22": "ml", "C23": "core, ml", "X1": "core", "X2": "core", "X3": "core", "X4": "core, ml", "X5": "core, ml", "X6": "core, ml", "X7": "core", "X8": "core, ml", "X9": "core, ml", "X10": "core, ml", "X11": "ml", "X12": "core, ml", "X13": "core, ml", "P1": "core, ml", "P2": "core, ml", "P3": "core, ml", "P4": "core", "P5": "core", "P6": "core, ml", "P7": "ml", "P8": "core, ml", "P9": "core, ml", "P10": "core, ml", "P11": "core, ml"}       # the rows with a Lean declaration: the libraries whose key files prove them
# ---- end of the generated table ----

LEAN_ONLY = ()                  # the predicates with a Lean declaration and no python check (gate G12): none

# The paper's predicate ledger (predicates cited as 35:XN): the predicate(s) each check witnesses.
LEDGER = {
    "A1": "35:C1, 35:X2", "A2": "35:C15, 35:X1, 35:X3, 35:X7, 35:P4", "A3": "35:C18, 35:X12", "A4": "35:C14, 35:C6, 35:C23", "A5": "35:P5",
    "B1": "35:C2, 35:X4, 35:P1", "B2": "35:C3, 35:X5, 35:P2", "B3": "35:C11, 35:P8", "B4": "35:C12", "B5": "35:C7, 35:X10, 35:P6",
    "B6": "35:X12, 35:C18, 35:P9", "B7": "35:C16, 35:C17, 35:P10, 35:P11",
    "C1": "35:C4, 35:X6", "C2": "35:C5, 35:X6, 35:P3", "C3": "35:C9, 35:X9", "C4": "35:C13, 35:C8, 35:X8, 35:C21",
    "D1": "35:P1", "D2": "35:P2", "D3": "35:P8", "D4": "35:C12", "D5": "35:P6, 35:C8, 35:X8, 35:C9, 35:X9",
    "D6": "35:C10, 35:C22, 35:X11, 35:P7", "D7": "35:P3, 35:C6", "D8": "35:P9, 35:C18, 35:X12", "D9": "35:P10", "D10": "35:P11, 35:C16",
    "E1": "35:C23, 35:Z1, 35:C20, 35:X13", "E2": "35:C20", "E3": "35:X13, 35:C16, 35:C23",
    "F1": "35:C16", "F2": "35:C16", "F3": "35:C17", "F4": "35:C19",
    "G1": "35:C21, 35:C13",
}

# the package record (had.<script>) each check reproduces; None for the two checks beyond the package
FAMILY = {
    "A1": "su3_singlet", "A2": "carrier_residue", "A3": "vector_nonet", "A4": "em_heavy_cmag", "A5": None,
    "B1": "su3f_relations", "B2": "su3f_relations", "B3": "su3f_second_order", "B4": "su3f_second_order", "B5": "isospin_cottingham",
    "B6": "vector_nonet", "B7": "confinement_completion",
    "C1": "hyperfine_charsum", "C2": "hyperfine_charsum", "C3": "isospin_cottingham", "C4": "em_heavy_cmag",
    "D1": "su3f_relations", "D2": "su3f_relations", "D3": "su3f_second_order", "D4": "su3f_second_order", "D5": "isospin_cottingham",
    "D6": "heavy_flavour", "D7": "hyperfine_charsum", "D8": "vector_nonet", "D9": "absolute_masses", "D10": "confinement_completion",
    "E1": "subhorizon_resolution", "E2": "subhorizon_resolution", "E3": "confinement_completion",
    "F1": None, "F2": "final_resolution", "F3": "confinement_closure", "F4": "forward_eigenvalues",
    "G1": "em_heavy_cmag",
}

BLOCK = {"A": "the colour frame: SU(3, F_2) by frames, its centre, the colourless content of Λ•(3), the meson contraction, the Weyl moments",
         "B": "the relations as identities: Gell-Mann–Okubo, the spacing, the third difference, the links, Coleman–Glashow, the vector nonet, the gap and the split",
         "C": "the colour–spin–charge arithmetic: the colour factor, the spin pattern, the Σ–Λ correlators, the charge structure",
         "D": "the PDG confrontations: the relations, the hyperfine constant, the orderings, heavy flavour, the vector nonet, the anchored spectrum, the gap",
         "E": "the single scale: the admissible shells, the residual orders, the ratios at √σ",
         "F": "the finite confinement operators: the exact Sturm brackets, the Airy decimals, the baryon eigenvalue, the forward landing",
         "G": "the electromagnetic magnitude: α √σ against the lattice QED splitting"}

# the deciding check of each witnessed predicate (the other checks that touch it are corroboration)
PREDICATES = {
    "35:C1": "A1", "35:C2": "B1", "35:C3": "B2", "35:C4": "C1", "35:C5": "C2", "35:C6": "A4", "35:C7": "B5", "35:C8": "D5",
    "35:C9": "C3", "35:C10": "D6", "35:C11": "B3", "35:C12": "B4", "35:C13": "C4", "35:C14": "A4", "35:C15": "A2", "35:C16": "F1",
    "35:C17": "F3", "35:C18": "A3", "35:C19": "F4", "35:C20": "E2", "35:C21": "G1", "35:C22": "D6", "35:C23": "E1",
    "35:X1": "A2", "35:X2": "A1", "35:X3": "A2", "35:X4": "B1", "35:X5": "B2", "35:X6": "C2", "35:X7": "A2", "35:X8": "D5",
    "35:X9": "C3", "35:X10": "B5", "35:X11": "D6", "35:X12": "B6", "35:X13": "E3",
    "35:P1": "D1", "35:P2": "D2", "35:P3": "D7", "35:P4": "A2", "35:P5": "A5", "35:P6": "D5", "35:P7": "D6", "35:P8": "D3",
    "35:P9": "D8", "35:P10": "D9", "35:P11": "D10",
    "35:Z1": "E1",
}

R = Registry("35", "hadrons", LEDGER, PREDICATES, sources=[__file__])

SHELLS = (53, 173, 389, 1373)                           # the laboratory shells of the discriminator


def _within(x, centre, tol):
    """|x − centre| < tol, x a float of the chart converted exactly."""
    return abs(Q(x) - Q(centre)) < Q(tol)


def _between(x, lo, hi):
    return Q(lo) < Q(x) < Q(hi)


def _pct(x, nd=2, sign=False):
    """x as a percentage string (the chart tier formats it: no float call in this tier, gate G09)."""
    return CH.fmt(Q(x) * 100, nd, sign)


def _f(x, nd=3, sign=False):
    return CH.fmt(x, nd, sign)


# ------------------------------------------------------------------------------------------------------------
# block A: the colour frame (35:C1, X2, C15, X1, X3, X7, P4, C18, X12, C14, C6, C23, P5)
@R.block("A", BLOCK["A"])
def block_A():
    """Block A — the colour frame over F_4: A1–A5 exact."""
    # A1 SU(3, F_2) over F_4 by orthonormal frames: 36 unit vectors, |U(3, 2)| = 648, |SU(3, 2)| = 216; g†g = I and det g = 1
    #    on every element; the centre is the three scalars I, wI, w²I (the cube roots of unity, Z_3 triality), by the full
    #    commutation table and as the commutant of diag(1, w, w²) and the permutation U₁
    F, G = H.colour_group()
    u3 = I.unitary_frames(F, 3, det_one=False)
    scal = H.colour_scalars(F); cen = H.centre(F, G)
    D1 = tuple(tuple(x if i == j else F.zero for j in range(3)) for i, x in enumerate([F.one, (0, 1), (1, 1)]))
    U1 = tuple(tuple(F.one if i + j == 2 else F.zero for j in range(3)) for i in range(3))
    com = H.commutant(F, G, [D1, U1])
    ok = I.unit_vectors(F, 3) == 36 and len(u3) == 648 and len(G) == 216 and H.hermitian_invariant(F, G)
    ok &= all(I.det(F, g) == F.one for g in G) and sorted(cen) == sorted(scal) and len(scal) == 3 and sorted(com) == sorted(scal)
    ok &= D1 in G and U1 in G and all(F.mul(x[0][0], F.mul(x[0][0], x[0][0])) == F.one for x in scal)
    # 35:C1 (p35015), 35:X2 (p35039)
    R.check("A1", "colour SU(3, F_2) built exactly over F_4 by orthonormal frames: 36 unit vectors, 648 frames (U(3, 2)), 216 of "
            "determinant one; g†g = I and det g = 1 on every element; the centre is the three scalars I, wI, w²I (Z_3, colour "
            "triality) by the full commutation table and as the commutant of diag(1, w, w²) and the permutation U₁: the "
            "colour-singlet baryon is the centre-neutral ε_abc invariant, triality 0", ok,
            f"|U| = {len(u3)}, |SU| = {len(G)}, centre {len(cen)} scalars, commutant {len(com)}")

    # A2 the colourless content of Λ•(3): no nonzero vector fixed by the group on the fundamental (a quark has residue 0), none on
    #    Λ²(3) by the 2 × 2 minors and by the conjugate action (the diquark), det g = 1 on all (Λ³ = det, the baryon, residue 1):
    #    (1, 0, 0, 1); the dimensions 1, 3, 3, 1; the trialities of qqq and q q̄ are 0; the determinant is the only colourless
    #    escape, at k = N = 3: the proton is the minimal residue-1 colourless object
    content = H.colourless_content(F, G)
    ok = content == (1, 0, 0, 1) and [1, 3, 3, 1] == [comb(3, k) for k in range(4)]
    ok &= H.triality(3, 0) == 0 and H.triality(1, 1) == 0 and H.triality(1, 0) == 1 and H.triality(2, 0) == 2
    # 35:C15 (p35029), 35:X1 (p35038), 35:X3 (p35040), 35:X7 (p35044), 35:P4 (p35054)
    R.check("A2", "the baryon is the Carrier residue 1: the colourless content of Λ•(3) on SU(3, F_2) is (1, 0, 0, 1) — no nonzero "
            "vector of the fundamental fixed by the group (a quark has residue 0), none of Λ²(3) (the minors and the conjugate "
            "action agree; the diquark), det g = 1 on every element (Λ³ = det, the one invariant, baryon number); the only "
            "colourless escape is the determinant at k = N = 3, and the trialities of qqq and q q̄ are 0 while a quark's is 1: "
            "the baryon is three quarks and the proton the minimal residue-1 wrap, with no lighter B = 1 residue", ok,
            f"content {content}; fixed on 3: {content[1]}, on Λ²: {content[2]}")

    # A3 the meson contraction: g†g = I on all 216 elements is the invariance of the Hermitian form on the basis pairs, so the q q̄
    #    contraction v^a w̄_a is the one-dimensional invariant of 3 ⊗ 3̄ = 1 ⊕ 8 (the singlet once, by the moments); triality
    #    1 + 2 ≡ 0, residue 1, B = 0; the residue series photon 2, gluon 0, baryon 1, meson 1
    E, c = H.weyl_moments()
    ok = H.hermitian_invariant(F, G) and c["singlet_3x3bar"] == 1 and H.triality(1, 1) == 0 and content[3] == 1
    # 35:C18 (p35032)
    R.check("A3", "the meson is the Carrier residue 1 with B = 0: g†g = I on every element of SU(3, F_2) is the invariance of the "
            "Hermitian form on the basis pairs, so the q q̄ contraction is the one invariant of 3 ⊗ 3̄ = 1 ⊕ 8 (one singlet, "
            "E[χχ̄] = 1), triality 1 + 2 ≡ 0; with the baryon's determinant (A2) the residue series closes: photon 2, gluon 0, "
            "baryon 1, meson 1", ok, f"E[χχ̄] = {E[(1, 1)]}, Hermitian form invariant on all {len(G)}")

    # A4 the adjoint channel by the Weyl constant terms: E[χχ̄] = 1, E[χ²] = 0, the adjoint 8 = χχ̄ − 1 once in 3 ⊗ 3̄
    #    (E[χ²χ̄²] − E[χχ̄] = 1) and absent from 3 ⊗ 3 (E[χ³χ̄] − E[χ²] = 0); the single-plaquette coefficients c₁ = β/(2N²) = β/18
    #    (the fundamental, O(β)) and c_adj = β²/(2N)² = β²/36 (the adjoint, O(β²), one order finer than the tension)
    c1, cadj = H.character_coefficients(3)
    ok = c["adjoint_in_3x3bar"] == 1 and c["adjoint_in_3x3"] == 0 and c["singlet_3x3bar"] == 1 and c["singlet_3x3"] == 0
    ok &= c1 == Q(1, 18) and cadj == Q(1, 36) and E[(2, 2)] == 2 and E[(3, 1)] == 0
    # 35:C14 (p35028), 35:C6 (p35020)
    R.check("A4", "c_mag is the adjoint-channel plaquette sum: by the Weyl constant terms the adjoint 8 sits once in 3 ⊗ 3̄ "
            "(E[χ²χ̄²] − E[χχ̄] = 2 − 1 = 1) and is absent from 3 ⊗ 3 (E[χ³χ̄] − E[χ²] = 0 − 0), so the colour-magnetic coefficient "
            "enters at O(β²) with the leading coefficient β²/(2N)² = β²/36, one order finer than the tension's c₁ = β/(2N²) = β/18 "
            "of the fundamental channel; the dimensionless pattern is exact, the absolute A_light = √σ c_mag carries the Ω-hard "
            "scale (Z1)", ok, f"moments {dict((k, v) for k, v in E.items() if k in [(1, 1), (2, 0), (2, 2), (3, 1)])}; c₁ {c1} β, c_adj {cadj} β²")

    # A5 the flavour cube 3 ⊗ 3 ⊗ 3 = 10 ⊕ 8 ⊕ 8 ⊕ 1 by the moments: one singlet (E[χ³] = 1), the adjoint twice (E[χ⁴χ̄] − E[χ³] = 2),
    #    Σ m² = E[χ³χ̄³] = 6 = 1 + 2² + 1 so the remaining ten dimensions are one irreducible; 27 = 10 + 8 + 8 + 1; the symmetric
    #    spin–flavour cube Sym³(6) has C(8, 3) = 56 = 10·4 + 8·2 states: no multiplet beyond the 8 and the 10 at leading order
    mults, dim27, dim56, split56 = H.flavour_cube()
    ok = mults == {"1": 1, "8": 2, "10": 1} and dim27 == 27 == 10 + 8 + 8 + 1 and dim56 == 56 == split56 and c["sum_sq_cube"] == 6
    # 35:P5 (p35055)
    R.check("A5", "no exotic light multiplets beyond the 8 and the 10 at leading wrap order: the flavour cube 3 ⊗ 3 ⊗ 3 is 10 ⊕ 8 ⊕ 8 ⊕ 1 "
            "by the Weyl constant terms (one singlet E[χ³] = 1, the adjoint twice E[χ⁴χ̄] − E[χ³] = 2, the squared multiplicities "
            "E[χ³χ̄³] = 6 = 1 + 4 + 1, so the remaining ten dimensions are one irreducible), 27 = 10 + 8 + 8 + 1; the symmetric "
            "spin–flavour cube Sym³(6) has 56 = 10·4 + 8·2 states", ok, f"multiplicities {mults}, Σm² = {c['sum_sq_cube']}, 56 = {split56}")


# ------------------------------------------------------------------------------------------------------------
# block B: the relations as identities (35:C2, X4, C3, X5, C11, C12, C7, X10, X12, C16, C17)
@R.block("B", BLOCK["B"])
def block_B():
    """Block B — the relations as zero polynomials over their parameters: B1–B7 exact."""
    # B1 Gell-Mann–Okubo: with M = M₀ + aY + b[I(I+1) − Y²/4] on the octet, 2N + 2Ξ − 3Λ − Σ is the zero polynomial in (M₀, a, b):
    #    the relation holds for every value of the scale and the breaking parameters
    g = H.gmo_vector()
    # 35:C2 (p35016), 35:X4 (p35041)
    R.check("B1", "Gell-Mann–Okubo ½(N + Ξ) = ¼(3Λ + Σ) is an exact scale-cancelling identity: with the octet operator "
            "M = M₀ + aY + b[I(I+1) − Y²/4] the combination 2N + 2Ξ − 3Λ − Σ is the zero polynomial in (M₀, a, b), so the "
            "relation holds for every scale and every breaking parameter — a derived sum rule of linear flavour breaking", g.is_zero(),
            f"2N + 2Ξ − 3Λ − Σ = {g}")

    # B2 decuplet equal spacing: with M = α + β n_s both second differences Δ − 2Σ* + Ξ* and Σ* − 2Ξ* + Ω are zero polynomials
    d1, d2 = H.spacing_vectors()
    # 35:C3 (p35017), 35:X5 (p35042)
    R.check("B2", "the decuplet is equally spaced because the strange seed enters the wrap additively: with M = α + β n_s the two "
            "second differences Δ − 2Σ* + Ξ* and Σ* − 2Ξ* + Ω are zero polynomials in (α, β); the common spacing is "
            "β = (M_Ω − M_Δ)/3, one strange-seed wrap increment", d1.is_zero() and d2.is_zero(), f"{d1}, {d2}")

    # B3 the third difference: in the linear-seed pairwise-hyperfine model (A_ij = A (m/m_i)(m/m_j), r = m/m_s, every decuplet pair
    #    +1/4) M_Δ − 3M_Σ* + 3M_Ξ* − M_Ω is the zero polynomial in (M₀, d, A, r)
    t = H.third_difference()
    # 35:C11 (p35025)
    R.check("B3", "the second-order decuplet relation M_Δ − 3M_Σ* + 3M_Ξ* − M_Ω = 0: in the linear-seed pairwise-hyperfine model "
            "(A_ij = A (m/m_i)(m/m_j), r = m/m_s, every decuplet pair S_i·S_j = +1/4) the third difference is the zero polynomial "
            "in (M₀, d, A, r), parameter-free", t.is_zero(), f"third difference = {t}")

    # B4 the octet–decuplet hyperfine links: (M_Σ − M_Λ) − (2/3)[(M_Δ − M_N) − (M_Σ* − M_Σ)] and (M_Σ* − M_Σ) − (M_Ξ* − M_Ξ) are
    #    zero polynomials in the same model (the octet correlators −3/4, +1/4, −1 of block C)
    l1, l2 = H.hyperfine_links()
    # 35:C12 (p35026)
    R.check("B4", "the octet–decuplet hyperfine links M_Σ − M_Λ = (2/3)[(M_Δ − M_N) − (M_Σ* − M_Σ)] and M_Σ* − M_Σ = M_Ξ* − M_Ξ are "
            "parameter-free: both differences are zero polynomials in (M₀, d, A, r) of the linear-seed pairwise-hyperfine model, "
            "with the octet correlators S_u·S_d = −3/4 (Λ), +1/4 (Σ) and the strange coupling −1 (Σ), the decuplet pairs +1/4",
            l1.is_zero() and l2.is_zero(), f"{l1}, {l2}")

    # B5 Coleman–Glashow: counting the d − u content, n − p = δ, Ξ⁻ − Ξ⁰ = δ, Σ⁻ − Σ⁺ = 2δ, so (n − p) + (Ξ⁻ − Ξ⁰) − (Σ⁻ − Σ⁺) is the
    #    zero polynomial in the one-body unit δ; the two-body electromagnetic term cancels in the same count
    cg = H.coleman_glashow()
    # 35:C7 (p35021), 35:X10 (p35047)
    R.check("B5", "Coleman–Glashow (n − p) + (Ξ⁻ − Ξ⁰) = Σ⁻ − Σ⁺ is an exact one-body identity: counting the d − u content, "
            "n − p = δ, Ξ⁻ − Ξ⁰ = δ, Σ⁻ − Σ⁺ = 2δ, so the combination is the zero polynomial in the one-body unit "
            "δ = δ_d − δ_u (the mass seed and the one-body electromagnetic self-energy together), the two-body term cancelling",
            cg.is_zero(), f"(n − p) + (Ξ⁻ − Ξ⁰) − (Σ⁻ − Σ⁺) = {cg}")

    # B6 the vector nonet: with M = a + b n_s on the spin-1 nonet, 2M_K* − M_ρ − M_φ is the zero polynomial in (a, b); the same
    #    frame and the same colour-magnetic operator as the baryons (the spin shift common to the nonet)
    v = H.vector_spacing()
    # 35:X12 (p35049)
    R.check("B6", "the vector mesons space equally, 2M_K* = M_ρ + M_φ: with M = a + b n_s on the spin-1 nonet (the hyperfine a "
            "common shift) the combination 2K* − ρ − φ is the zero polynomial in (a, b), the vector analogue of the decuplet "
            "spacing on the same frame, with the meson residue 1 and B = 0 (A3)", v.is_zero(), f"2K* − ρ − φ = {v}")

    # B7 the gap and the split: M_Λ − M_N − (m_s − m_l) is the zero polynomial with M_N = 3m_l − (3/4)v_ll and
    #    M_Λ = 2m_l + m_s − (3/4)v_ll (the strange quark hyperfine-decoupled in Λ, both correlator sums −3/4), and the spin split
    #    inverts: (M_N + M_Δ)/6 = λ_l, M_Δ − M_N = (3/2)λ_hf; every baryon's correlator sum is its multiplet's g_spin
    gap = H.gap_identity(); s1, s2 = H.spin_split()
    ok = gap.is_zero() and s1.is_zero() and s2.is_zero() and H.correlator_sums()
    R.check("B7", "the Λ–N gap is the strange constituent excess and the spin split inverts: M_Λ − M_N − (m_s − m_l) is the zero "
            "polynomial (both carry the hyperfine −(3/4)v_ll, the strange quark decoupled in Λ), (M_N + M_Δ)/6 − λ_l and "
            "(M_Δ − M_N) − (3/2)λ_hf are zero polynomials; every octet and decuplet correlator sum equals its multiplet's "
            "g_spin, −3/4 and +3/4", ok, f"gap {gap}, split {s1}, {s2}")


# ------------------------------------------------------------------------------------------------------------
# block C: the colour–spin–charge arithmetic (35:C4, X6, C5, P3, C9, X9, C13, C8, X8, C21)
@R.block("C", BLOCK["C"])
def block_C():
    """Block C — exact rational arithmetic: C1–C4."""
    # C1 the colour factor of the singlet: C₂(3) = (N² − 1)/(2N) = 4/3, C₂(1) = 0, Σ T_i·T_j = (0 − 3·4/3)/2 = −2, λ = 2T gives
    #    Σ λ_i·λ_j = −8, −8/3 per pair
    c2, sTT, sll, per = H.colour_factor()
    ok = c2 == Q(4, 3) and sTT == -2 and sll == -8 and per == Q(-8, 3)
    # 35:C4 (p35018)
    R.check("C1", "the colour factor of the colour-singlet baryon Σ_{i<j} λ_i·λ_j = −8 (−8/3 per pair) from the Casimirs "
            "C₂(3) = (N² − 1)/(2N) = 4/3 and C₂(1) = 0: Σ T_i·T_j = (C₂(1) − 3C₂(3))/2 = −2 and λ = 2T", ok,
            f"C₂ = {c2}, ΣT·T = {sTT}, Σλ·λ = {sll}, per pair {per}")

    # C2 the spin pattern g_spin = ½S(S+1) − 9/8: octet −3/4, decuplet +3/4, separation 3/2; the eigenvalues of Σ(λ·λ)(S·S) on
    #    the singlet (−8/3)g = +2 (octet), −2 (decuplet); M_10 − M_8 = (3/2)A_light with A_light = −(8/3)κ_hf: the decuplet
    #    heavier by a derived sign
    e8, e10, sep, de = H.hyperfine_eigenvalues()
    ok = H.g_spin(1) == Q(-3, 4) and H.g_spin(3) == Q(3, 4) and sep == Q(3, 2) and e8 == 2 and e10 == -2 and de == -4
    # 35:C5 (p35019), 35:X6 (p35043)
    R.check("C2", "the hyperfine pattern is exact: g_spin = ½S(S+1) − 9/8 is −3/4 on the octet and +3/4 on the decuplet, the "
            "separation 3/2; the eigenvalues of Σ(λ_i·λ_j)(S_i·S_j) on the singlet are (−8/3)g = +2 and −2; so "
            "M_10 − M_8 = (3/2)A_light with A_light = −(8/3)κ_hf, the decuplet heavier than the octet by the colour-magnetic "
            "curvature invariant, a derived sign and pattern", ok, f"g = {H.g_spin(1)}, {H.g_spin(3)}; eigenvalues {e8}, {e10}; separation {sep}")

    # C3 the Σ–Λ fine structure: the light pair S_u·S_d is −3/4 at spin 0 (Λ) and +1/4 at spin 1 (Σ); the strange coupling
    #    S_s·(S_u + S_d) at total spin ½ is 0 for the spin-0 pair and −1 for the spin-1 pair; so M_Σ − M_Λ = a_ll(1/4 + 3/4) +
    #    a_ls(−1 − 0) = a_ll − a_ls = a_ll(1 − m_l/m_s) > 0 for m_s > m_l: Σ heavier, derived
    pc = H.pair_correlators()
    diff_ll, diff_ls = pc["ud_spin1"] - pc["ud_spin0"], pc["s_pair_sigma"] - pc["s_pair_lambda"]
    ok = pc == dict(ud_spin0=Q(-3, 4), ud_spin1=Q(1, 4), s_pair_lambda=Q(0), s_pair_sigma=Q(-1)) and diff_ll == 1 and diff_ls == -1
    # 35:C9 (p35023), 35:X9 (p35046)
    R.check("C3", "Σ is heavier than Λ by hyperfine fine structure of two states of identical quark content: the light pair's "
            "S_u·S_d is −3/4 at spin 0 (Λ) and +1/4 at spin 1 (Σ), the strange coupling S_s·(S_u + S_d) at total spin ½ is 0 and −1, "
            "so M_Σ − M_Λ = a_ll·1 + a_ls·(−1) = a_ll − a_ls = a_ll(1 − m_l/m_s), positive for m_s > m_l", ok,
            f"correlators {dict((k, str(v)) for k, v in pc.items())}")

    # C4 the charge structure: one-body Σ Q² is 1 for uud and 2/3 for udd, two-body Σ_{i<j} Q_iQ_j is 0 and −1/3; both differences
    #    p − n are +1/3: the electromagnetic term makes the proton heavier; Δ_EM = α √σ × this structure × O(1), so its magnitude
    #    reduces to the imported α and √σ (no new residue)
    qp = [H.QUARK_CHARGE[q] for q in "uud"]; qn = [H.QUARK_CHARGE[q] for q in "udd"]
    (op, tp), (on, tn) = H.charge_structure(qp), H.charge_structure(qn)
    ok = (op, tp) == (1, 0) and (on, tn) == (Q(2, 3), Q(-1, 3)) and op - on == Q(1, 3) and tp - tn == Q(1, 3) and op > on
    # 35:C13 (p35027)
    R.check("C4", "the electromagnetic splitting structure is exact: one-body Σ Q² = 1 for the proton (uud) and 2/3 for the neutron "
            "(udd), two-body Σ_{i<j} Q_iQ_j = 0 and −1/3, both differences p − n equal to +1/3 — the electromagnetic term makes "
            "the proton heavier; Δ_EM = α √σ × this structure, its magnitude the imported α (A9) times √σ (A3), no new residue", ok,
            f"p: ({op}, {tp}); n: ({on}, {tn})")


# ------------------------------------------------------------------------------------------------------------
# block D: the PDG confrontations (35:P1, P2, P8, C12, P6, C8, X8, C9, X9, C10, C22, X11, P7, P3, C6, P9, C18, X12, P10, P11, C16)
@R.block("D", BLOCK["D"])
def block_D():
    """Block D — the readings of the PDG masses: D1–D10 chart."""
    c = CH.confrontations()
    # D1 [chart] GMO on the isospin-averaged PDG masses: the residual 0.57 % (in (0.56, 0.58) %), the bounded second order
    r = c["gmo"]["residual"]
    # 35:P1 (p35051)
    R.check("D1", "[chart] Gell-Mann–Okubo holds on the PDG masses to 0.57 %: ½(N + Ξ) against ¼(3Λ + Σ), the residual in (0.56, 0.58) %, "
            "the bounded second-order (27-plet) insertion", _between(r, "0.0056", "0.0058"), f"residual {_pct(r, 3)} %", kind="CHART")

    # D2 [chart] the decuplet spacings 152.6, 148.8, 139.1 MeV, the mean β = 146.8, the spread 9.2 % (in (9.2, 9.21) %), the
    #    spacings decreasing with strangeness (the second-order curvature)
    sp = c["spacing"]
    ok = _between(sp["beta"], "146.8", "146.85") and _between(sp["spread"], "0.092", "0.0921") and sp["spacings"][0] > sp["spacings"][1] > sp["spacings"][2]
    ok &= _between(sp["strange_step"], "189.6", "189.7")
    # 35:P2 (p35052)
    R.check("D2", "[chart] the decuplet equal spacing on the PDG masses: the spacings 152.6, 148.8, 139.1 MeV, the mean increment "
            "β = (M_Ω − M_Δ)/3 = 146.8 MeV, the spread (max − min)/β = 9.2 %, decreasing with strangeness — the second order "
            "the third-difference relation (P8) closes; the octet strange step (Ξ − N)/2 = 189.7 MeV", ok,
            f"spacings {', '.join(_f(x, 2) for x in sp['spacings'])}, β {_f(sp['beta'], 2)}, spread {_pct(sp['spread'], 2)} %", kind="CHART")

    # D3 [chart] the third difference on PDG: M_Δ − 3M_Σ* + 3M_Ξ* − M_Ω = 6.05 MeV, 0.36 % of M_Ω (in (0.36, 0.363) %)
    t = c["third"]
    ok = _between(t["value"], "6.0", "6.1") and _between(t["relative"], "0.0036", "0.00363")
    # 35:P8 (p35058)
    R.check("D3", "[chart] the second-order decuplet relation holds on the PDG masses to 6.05 MeV, 0.36 % of the scale: "
            "M_Δ − 3M_Σ* + 3M_Ξ* − M_Ω in (6.0, 6.1) MeV, halving the first-order 9.2 % spread's 13.5 MeV", ok,
            f"{_f(t['value'], 2)} MeV, {_pct(t['relative'], 3)} %", kind="CHART")

    # D4 [chart] the links on PDG: 77.5 against 67.8 MeV (12.5 %), 191.4 against 215.1 MeV (−12.4 %): the wavefunction wrap correction
    lk = c["links"]
    ok = _between(lk["rel1"], "0.125", "0.1252") and _between(lk["rel2"], "-0.124", "-0.1238")
    R.check("D4", "[chart] the octet–decuplet hyperfine links on the PDG masses hold to 12.5 % and −12.4 %: M_Σ − M_Λ = 77.5 against "
            "(2/3)[(M_Δ − M_N) − (M_Σ* − M_Σ)] = 67.8 MeV, M_Σ* − M_Σ = 191.4 against M_Ξ* − M_Ξ = 215.1 MeV, the residual the "
            "wavefunction wrap correction beyond the 1/(m_i m_j) hyperfine", ok,
            f"{_f(lk['l1'], 1)} vs {_f(lk['r1'], 1)} ({_pct(lk['rel1'], 1)} %); {_f(lk['l2'], 1)} vs {_f(lk['r2'], 1)} ({_pct(lk['rel2'], 1)} %)", kind="CHART")

    # D5 [chart] Coleman–Glashow on the charged PDG masses: 8.143 against 8.079 MeV, 0.79 % (in (0.79, 0.80) %); n − p = 1.293 > 0
    #    (the d − u seed wins over the charge-squared term, which favours p: C4); Σ⁰ − Λ = 76.96 > 0 (the spin-1 pair: C3)
    cg = c["cg"]
    ok = _between(cg["residual"], "0.0079", "0.0080") and cg["n_minus_p"] == Q("1.293") and cg["n_minus_p"] > 0 and cg["sigma0_minus_lambda"] > 0
    ok &= _between(cg["sigma0_minus_lambda"], "76.9", "77.0") and _between(cg["lhs"], "8.14", "8.15") and _between(cg["rhs"], "8.07", "8.08")
    # 35:P6 (p35056), 35:C8 (p35022), 35:X8 (p35045)
    R.check("D5", "[chart] the isospin splittings obey Coleman–Glashow to 0.79 %: (n − p) + (Ξ⁻ − Ξ⁰) = 8.143 against "
            "Σ⁻ − Σ⁺ = 8.079 MeV, the residual the two-body electromagnetic term; the neutron is heavier, n − p = 1.293 MeV > 0, "
            "although the charge-squared term favours the proton (Σ Q² = 1 against 2/3), so the d − u seed exceeds it and "
            "m_d > m_u; Σ⁰ − Λ = 76.96 MeV > 0, the spin-1 light pair heavier (C3)", ok,
            f"CG {_f(cg['lhs'], 3)} vs {_f(cg['rhs'], 3)} ({_pct(cg['residual'], 2)} %); n − p {_f(cg['n_minus_p'], 3)}; Σ⁰ − Λ {_f(cg['sigma0_minus_lambda'], 2)}", kind="CHART")

    # D6 [chart] heavy-quark symmetry on PDG: M_Λb − M_Λc = 3333.1 against M_B − M_D = 3414.8 MeV (−2.4 %); the 1/m_Q hyperfine ratio
    #    (Σ_c* − Σ_c)/(Σ* − Σ) = 0.339 ≈ m_s/m_c (constituent): the heavy-quark spin decouples, Λ_Q a spin-0 light diquark; the heavy
    #    absolute masses m_Q + O(√σ) reduce to the imported scales
    hv = c["heavy"]
    ok = _between(hv["residual"], "-0.024", "-0.0239") and _between(hv["ratio"], "0.339", "0.3391") and _between(hv["baryon"], "3333.1", "3333.2") and _between(hv["meson"], "3414.8", "3414.9")
    # 35:C10 (p35024), 35:C22 (p35036), 35:X11 (p35048), 35:P7 (p35057)
    R.check("D6", "[chart] the heavy baryons follow heavy-quark symmetry: M_Λb − M_Λc = 3333.1 against M_B − M_D = 3414.8 MeV "
            "(−2.4 %), the two differences one quantity m_b − m_c because the heavy-quark spin decouples (a_iQ ∼ 1/m_Q) and Λ_Q "
            "carries a spin-0 light diquark; the 1/m_Q hyperfine ratio (Σ_c* − Σ_c)/(Σ* − Σ) = 0.339 ≈ m_s/m_c; the heavy absolute "
            "masses m_Q + O(√σ) reduce to the imported scales, no new residue", ok,
            f"{_f(hv['baryon'], 1)} vs {_f(hv['meson'], 1)} ({_pct(hv['residual'], 2)} %); ratio {_f(hv['ratio'], 4)}", kind="CHART")

    # D7 [chart] the hyperfine constant: A_light = (2/3)(M_Δ − M_N) = 195.4 MeV; the light-light pair M_Σ* − M_Σ = 191.4 MeV of the
    #    same order (equality needs the constituent-mass ratio)
    hf = c["hyperfine"]
    ok = _between(hf["A_light"], "195.3", "195.4") and _between(hf["ll_pair"], "191.4", "191.5")
    # 35:P3 (p35053)
    R.check("D7", "[chart] the hyperfine pattern on the PDG masses: A_light = (2/3)(M_Δ − M_N) = 195.4 MeV (the paper's ≃ 195), the "
            "separation (3/2)A_light = M_Δ − M_N; the light-light pair M_Σ* − M_Σ = 191.4 MeV of the same order, the strange "
            "spectator's 1/(m_l m_s) correction the difference", ok, f"A_light {_f(hf['A_light'], 2)}, Σ* − Σ {_f(hf['ll_pair'], 2)} MeV", kind="CHART")

    # D8 [chart] the vector nonet on PDG: (2K* − ρ − φ)/(ρ + φ) = −0.42 %; K* predicted (ρ + φ)/2 = 897.4 against 893.6 (+0.42 %),
    #    ω predicted = ρ against 782.7 (−0.95 %), both under 1 %; the strange increment b = 122.1 MeV
    v = c["vector"]
    ok = _between(v["residual"], "-0.0042", "-0.0041") and v["Ks_pred"] == Q("897.36") and abs(v["Ks_rel"]) < Q("0.005") and abs(v["ome_rel"]) < Q("0.01")
    ok &= v["b"] == Q("122.1")
    # 35:P9 (p35059)
    R.check("D8", "[chart] the vector nonet on the PDG masses: 2M_K* against M_ρ + M_φ to −0.42 %; with ρ and φ anchored the predicted "
            "K* = (M_ρ + M_φ)/2 = 897.4 MeV lands within 0.5 % of 893.6 and the ideally mixed ω = ρ within 1 % of 782.7; the strange "
            "increment b = (M_φ − M_ρ)/2 = 122.1 MeV (the baryon Λ–N gap 176.8, D10: the two-body and three-body confinement "
            "eigenvalues differ on the same √σ)", ok,
            f"residual {_pct(v['residual'], 2)} %, K* {_f(v['Ks_pred'], 1)} ({_pct(v['Ks_rel'], 2, True)} %), ω {_pct(v['ome_rel'], 2, True)} %", kind="CHART")

    # D9 [chart] the anchored spectrum: from N, Λ, Δ the constituents m_l = 361.8 MeV, m_s/m_l = 1.4885, v_ll/m_l = 0.540; the five
    #    predictions Σ −1.12 %, Ξ +0.87 %, Σ* −0.57 %, Ξ* −0.44 %, Ω +0.56 %, all within 1.12 % (the paper's 1.1 %)
    (ml, ms, vll, vls, vss), table, res, worst = CH.anchored_spectrum()
    ok = _between(ml, "361.8", "361.9") and _between(ms / ml, "1.488", "1.489") and _between(vll / ml, "0.540", "0.5401") and worst < Q("0.0112")
    ok &= all(res[t] == 0 for t in ("N", "Lam", "Del")) and _between(worst, "0.0111", "0.0112")
    # 35:P10 (p35060)
    R.check("D9", "[chart] the absolute octet and decuplet from one scale and two ratios: anchored to N, Λ, Δ the constituents are "
            "m_l = 361.8 MeV, m_s/m_l = 1.4885 and v_ll/m_l = 0.540; the five parameter-free predictions land within 1.12 % of PDG "
            "(Σ −1.12, Ξ +0.87, Σ* −0.57, Ξ* −0.44, Ω +0.56 %), the residuals traced to the strange-wrap and Σ–Λ hyperfine orders", ok,
            "; ".join(f"{t} {_pct(res[t], 2, True)} %" for t in res if t not in ("N", "Lam", "Del")) + f"; m_l {_f(ml, 1)}, m_s/m_l {_f(ms / ml, 4)}, v_ll/m_l {_f(vll / ml, 4)}", kind="CHART")

    # D10 [chart] the Λ–N gap on PDG: M_Λ − M_N = 176.7645 MeV exactly on the declared masses, the strange constituent excess m_s − m_l
    #    (B7), hyperfine- and scale-free; (m_s − m_l)/√σ = 0.40 at √σ = 440
    ss = CH.single_scale()
    ok = ss["gap"] == Q("176.7645") and ss["m_s"] - ss["m_l"] == ss["gap"] and _between(ss["gap_over_s"], "0.401", "0.402")
    # 35:P11 (p35061)
    R.check("D10", "[chart] the Λ–N gap is the strange constituent excess: M_Λ − M_N = 176.8 MeV on the PDG masses equals m_s − m_l of "
            "the anchored constituents exactly (the hyperfine −(3/4)v_ll cancels, B7), hyperfine- and scale-free; "
            "(m_s − m_l)/√σ = 0.40 at √σ = 440 MeV", ok, f"gap {_f(ss['gap'], 4)} MeV, /√σ {_f(ss['gap_over_s'], 4)}", kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block E: the single scale (35:C23, Z1, C20, X13, C16)
@R.block("E", BLOCK["E"])
def block_E():
    """Block E — the discriminator and the ratios: E1 exact, E2 and E3 chart."""
    # E1 the colour rank is shell-independent: on every admissible shell Ω = 12k + 5, Ω + 1 = 3(4k + 2), so 3 | Ω + 1 (and 2 | Ω + 1,
    #    Ω + 1 ≡ 2 mod 4): the triality frame N = 3 on every shell; the four laboratory shells 53, 173, 389, 1373 are admissible; the
    #    character-sum coefficients 1/18, 1/36 depend on N alone — every dimensionless baryon quantity is Ω-stable; Ω enters only
    #    through the one scale √σ, declared once in the chart data
    ok = H.admissible_shells(range(2000)) and H.shells_ok(SHELLS) and H.character_coefficients(3) == (Q(1, 18), Q(1, 36))
    ok &= [k for k, v in CH.DATA["scales"].items() if k == "sqrt_sigma"] == ["sqrt_sigma"]
    # 35:C23 (p35037), 35:Z1 (p35065)
    R.check("E1", "the colour rank is shell-independent and the sector introduces no Ω-hard residue of its own: on every admissible "
            "shell Ω = 12k + 5 the successor 3(4k + 2) is divisible by 3 (k < 2000 checked, the identity for all k in the core), the "
            "laboratory shells 53, 173, 389, 1373 included, so the triality frame N = 3 and the coefficients β/18, β²/36 carry no Ω; "
            "the dimensionless A_light/√σ is Ω-stable, sub-horizon; the one Ω-hard input is the imported scale √σ (A3), declared "
            "once in the chart data, the electromagnetic α (A9) an imported constant", ok, f"shells {SHELLS}, coefficients {H.character_coefficients(3)}")

    # E2 [chart] the second-order residuals are O(ε_s²) of the leading splittings: the GMO residual over the octet strange splitting
    #    Ξ − N is 0.017, the third difference over the decuplet spacing 0.041 — a convergent small-parameter expansion, ε_s ≈ 0.13–0.2
    ro = CH.residual_orders()
    ok = _between(ro["gmo"], "0.0169", "0.0171") and _between(ro["third"], "0.0412", "0.0413")
    # 35:C20 (p35034)
    R.check("E2", "[chart] the second-order SU(3)_F residuals are sub-horizon: the Gell-Mann–Okubo residual is 0.017 of the octet "
            "strange splitting Ξ − N and the decuplet third difference 0.041 of the spacing, both O(ε_s²) of a convergent "
            "strange-breaking expansion with ε_s ≈ 0.13–0.2, Ω-stable", ok, f"{_f(ro['gmo'], 4)}, {_f(ro['third'], 4)}", kind="CHART")

    # E3 [chart] the single-scale readings at √σ = 440 MeV: λ_l = m_l/√σ = 0.822, m_s/m_l = 1.4885, λ_hf = v_ll/√σ = 0.444,
    #    M_N/√σ = 2.134, (m_s − m_l)/√σ = 0.402: the three anchored masses as one Ω-hard scale and three sub-horizon numbers
    ss = CH.single_scale()
    ok = _between(ss["lam_l"], "0.822", "0.8224") and _between(ss["ms_over_ml"], "1.488", "1.489") and _between(ss["lam_hf"], "0.444", "0.4441")
    ok &= _between(ss["mN_over_s"], "2.133", "2.134") and _between(ss["gap_over_s"], "0.401", "0.402")
    # 35:X13 (p35050)
    R.check("E3", "[chart] the spectrum rests on one scale: at √σ = 440 MeV the anchored constituents read λ_l = m_l/√σ = 0.822, "
            "m_s/m_l = 1.4885, λ_hf = v_ll/√σ = 0.444, M_N/√σ = 2.134 and (m_s − m_l)/√σ = 0.402 — every dimensionless mass ratio "
            "a sub-horizon number, the absolute scale the lone Ω-hard residue", ok,
            f"λ_l {_f(ss['lam_l'], 4)}, m_s/m_l {_f(ss['ms_over_ml'], 4)}, λ_hf {_f(ss['lam_hf'], 4)}, M_N/√σ {_f(ss['mN_over_s'], 4)}", kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block F: the finite confinement operators (35:C16, C17, C19)
@R.block("F", BLOCK["F"])
def block_F():
    """Block F — the finite operators: F1 exact (Sturm in Fractions), F2–F4 chart."""
    # F1 the finite-stage spectrum is exact: on the grid N = 4000, L = 30 the tridiagonal H^(N) = −u'' + x u has, by Sturm's count in
    #    exact rational arithmetic, exactly one eigenvalue in each of (2.338, 2.339), (4.087, 4.088), (5.520, 5.521), (6.786, 6.787):
    #    the counts (0, 1), (1, 2), (2, 3), (3, 4) at the brackets' ends
    N, L = CH.DATA["grid"]["airy"]
    br = [("2.338", "2.339"), ("4.087", "4.088"), ("5.520", "5.521"), ("6.786", "6.787")]
    counts = H.sturm_brackets(N, L, br)
    ok = counts == [(k, k + 1) for k in range(4)]
    # 35:C16 (p35030)
    R.check("F1", "the finite-stage confinement eigenvalues are exact: Sturm's count of the tridiagonal H^(N) = −u'' + x u on "
            "N = 4000 sites of [0, 30], in exact rational arithmetic, places exactly one eigenvalue in each of (2.338, 2.339), "
            "(4.087, 4.088), (5.520, 5.521) and (6.786, 6.787) — the finite spectrum at the decimals of the Airy zeros; the "
            "single-scale reduction M_H = √σ λ_H reads the three anchors as one Ω-hard scale and three sub-horizon numbers (E3), "
            "and M_Λ − M_N = m_s − m_l exactly (B7)", ok, f"counts at the bracket ends {counts}")

    # F2 [chart] the decimals: the four eigenvalues by bisection 2.33810, 4.08793, 5.52053, 6.78666 against the Airy zeros 2.33811,
    #    4.08795, 5.52056, 6.78671 (within 5 × 10⁻⁵, the grid's accuracy); ε₁/ε₀ = 1.7484, pure and scale-free
    eps, zeros, diff, ratio = CH.airy_readout()
    ok = all(abs(Q(d)) < Q("5e-5") for d in diff) and _within(ratio, "1.7484", "0.00005") and all(Q(d) < 0 for d in diff)
    R.check("F2", "[chart] the finite-grid eigenvalues of H^(N) at N = 4000, L = 30 read 2.3381, 4.0879, 5.5205, 6.7867 against the "
            "Airy zeros 2.33811, 4.08795, 5.52056, 6.78671, each within 5 × 10⁻⁵ below its zero (the grid's accuracy); the level "
            "ratio ε₁/ε₀ = 1.7484 is pure and scale-free, a kind-(b) sub-horizon number", ok,
            f"{[round(e, 5) for e in eps]}, ratio {ratio:.4f}", kind="CHART")

    # F3 [chart] the baryon scale is a computed eigenvalue: E₀ of H_G = |p| + r on the grid (600, 30) is 2.2320, within 0.001 of the
    #    converged 2.232 (the package's tower 2.2316, 2.2320, 2.2322, 2.2322 at N = 300..2200); E₁/E₀ = 1.49; M_N = E₀√σ = 982 MeV at
    #    √σ = 440, 4.6 % above 938.9, exact at √σ = 420.7 MeV inside the lattice band 420–447
    fl = CH.forward_landing()
    E0, E1 = fl["E0"], fl["E1"]; s = CH.DATA["scales"]["sqrt_sigma"]; mN = CH.pdg()["N"]
    MN_pred = Q(E0) * s; excess = (MN_pred - mN) / mN; sig_exact = mN / Q(E0)
    ok = _within(E0, "2.232", "0.001") and _between(E1 / E0, "1.491", "1.492") and _between(MN_pred, "981", "983")
    ok &= _between(excess, "0.045", "0.047") and _between(sig_exact, "420", "421")
    # 35:C17 (p35031)
    R.check("F3", "[chart] the baryon scale is the computed finite eigenvalue, no baryon mass entering: E₀ of H_G = |p| + r on the grid "
            "N = 600, L = 30 (|p| = T^{1/2} diagonal in the sine basis, the lowest pair by a Lanczos iteration) is 2.2320, within "
            "0.001 of the converged 2.232; E₁/E₀ = 1.49; M_N = E₀√σ = 982 MeV at √σ = 440 predicts the nucleon to 4.6 %, exact at "
            "√σ = 420.7 MeV inside the lattice band; λ_l = (M_N + M_Δ)/(6√σ) and λ_hf = 2(M_Δ − M_N)/(3√σ) then follow (B7, E3)", ok,
            f"E₀ {E0:.5f}, E₁/E₀ {E1 / E0:.4f}, M_N {_f(MN_pred, 0)} MeV ({_pct(excess, 1)} %), √σ exact {_f(sig_exact, 1)}", kind="CHART")

    # F4 [chart] the forward landing on the grid (600, 30): |u'(0)|² of the nonrelativistic ground state 0.999 → 1 (the Airy
    #    normalisation identity), the relativistic contact 3.50, F_rel = 3.50 (3.52 on the package's N = 3000 grid); α_s(√σ) =
    #    2π/(9 ln 2) = 1.007 against the hyperfine-required 0.93 (within 12 %); v_ll/m_l = (2ρ/9)F_rel α_s/λ_l² = 0.536 (target
    #    0.540), λ_hf = 0.440 within 7 % of 0.444 at α_s = 0.93 and 0.474 at 1.00; λ_l = (E₀ + (3/4)λ_hf)/3 = 0.855 within 7 % of 0.822
    t = CH.DATA["targets"]
    ok = _within(fl["contact_nr"], 1, "0.002") and _between(fl["F_rel"], "3.49", "3.52") and _between(fl["alpha_s"], "1.00", "1.01")
    ok &= abs(Q(fl["hf"]["lam_hf"]) - t["lam_hf"]) / t["lam_hf"] < Q("0.07") and abs(Q(fl["hf"]["vm"]) - t["vm"]) / t["vm"] < Q("0.01")
    ok &= abs(Q(fl["transmutation"]["lam_hf"]) - t["lam_hf"]) / t["lam_hf"] < Q("0.08") and abs(Q(fl["lam_l_fwd"]) - t["lam_l"]) / t["lam_l"] < Q("0.07")
    ok &= abs(Q(fl["alpha_s"]) - t["alpha_s_hf"]) / Q(fl["alpha_s"]) < Q("0.12") and _within(fl["eps0"], "2.3379", "0.0002")
    # 35:C19 (p35033)
    R.check("F4", "[chart] the constituent eigenvalues evaluated forward from {N = 3, β} with no measured baryon mass: on the grid "
            "N = 600, L = 30 the nonrelativistic contact |u'(0)|² = 0.999 → 1 (the Airy normalisation identity), the relativistic "
            "enhancement F_rel = 3.50 (3.52 at N = 3000), the transmutation-pinned α_s(√σ) = 2π/(9 ln 2) = 1.007 within 12 % of the "
            "hyperfine-required 0.93; v_ll/m_l = (2ρ/9)F_rel α_s/λ_l² = 0.536 against 0.540, λ_hf = 0.440 within 7 % of 0.444 at "
            "α_s = 0.93 (0.474 at 1.00), λ_l = (E₀ + (3/4)λ_hf)/3 = 0.855 within 7 % of 0.822: constituent-model accuracy, the margin "
            "the linear-potential approximation", ok,
            f"|u'(0)|² {fl['contact_nr']:.4f}, F_rel {fl['F_rel']:.3f}, α_s {fl['alpha_s']:.3f}, v/m {fl['hf']['vm']:.3f}, λ_hf {fl['hf']['lam_hf']:.3f}/{fl['transmutation']['lam_hf']:.3f}, λ_l {fl['lam_l_fwd']:.3f}", kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block G: the electromagnetic magnitude (35:C21, C13)
@R.block("G", BLOCK["G"])
def block_G():
    """Block G — the magnitude reading: G1 chart."""
    # G1 [chart] Δ_EM = α √σ × structure: the one-body difference p − n of 1/3 (C4) at α = 1/137.036 and √σ = 440 MeV is 1.07 MeV, within
    #    10 % of the lattice QED part of M_n − M_p (1.00 MeV in magnitude, Borsányi et al. 2015); the magnitude reduces to the imported
    #    α and √σ, no new residue; Coleman–Glashow and the orderings are derived (B5, C3, C4, D5)
    em = CH.em_magnitude()
    ok = _between(em["value"], "1.07", "1.08") and abs(em["relative"]) < Q("0.1")
    # 35:C21 (p35035)
    R.check("G1", "[chart] the electromagnetic splitting magnitude reduces to the imported α and √σ: the one-body charge difference 1/3 "
            "(C4) times α √σ at α = 1/137.036 and √σ = 440 MeV is 1.07 MeV, within 10 % of the lattice QED part of M_n − M_p "
            "(1.00 MeV in magnitude); no new residue; Coleman–Glashow and the two orderings are derived (B5, C3, D5)", ok,
            f"α√σ/3 = {_f(em['value'], 3)} MeV ({_pct(em['relative'], 1, True)} % of 1.00)", kind="CHART")


if __name__ == "__main__":
    want = [a.upper() for a in sys.argv[1:]] or sorted(BLOCK)
    bad = [b for b in want if b not in BLOCK]
    if bad: sys.exit(f"no block {', '.join(bad)}: the blocks are {', '.join(sorted(BLOCK))}")
    for b in want: R.run_block(b)
    sys.exit(0 if R.summary(write=False, expect=list(LEDGER) if want == sorted(BLOCK) else None) else 1)
