"""p27_fields — the ledger file of 27-fields (ledger migration, task LM35, 7 October 2026; the 27-fields migration,
16 October 2026).

"Standard-Model Interactions over Finite Substrate" (Akhtman and Voether, preprint 2026; doi 10.20944/preprints202606.1328.v1).
The paper's predicate ledger is docs/27-fields/27-fields-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 eight blocks. The
exact checks call the interactions theme (frc/interactions.py) and, for the closed role ladder, the horizon theme
(frc/ladder.py); the continuum readings call the chart theme (frc/chart.py, frc/chart_fields.py) and compare its
readings with rational bounds. Each check names the predicate(s) it witnesses (LEDGER) and carries a `# 27:XN (<key>)`
marker when it decides one (PREDICATES).

The checks are EXACT or CHART, one kind per check. An EXACT check decides by integer, finite-field, rational or
cyclotomic arithmetic; no float decides anything. A CHART check is a continuum reading: floats, transcendental
functions, measured data, dimensional estimates; its label carries "[chart]". The paper's own classes were EXACT, MIXED
and APPROX, one per package record (src/27-fields, twenty-eight scripts run by fldcommon.py); the checks of 7 October
carried their record's class. On 16 October 2026 (the 27-fields migration) MIXED and APPROX split: each mixed check whose
two halves both carry content became an exact check under the old label and a chart check under the label with the
suffix c (B1/B1c, B4/B4c, C8/C8c, E5/E5c, F6/F6c); a check whose float clause only illustrated an exact clause was
retagged EXACT; a check that is wholly a continuum reading was retagged CHART; and the APPROX checks of the finite gauge
correspondence B1, B2 and B4 became EXACT (the roots of unity in Q(ζ_M), the 24 quaternions of 2T over Q, the area law's
rational function positive beyond x = 1), the rest CHART. FAMILY names the package record (fld.<script>) each check
reproduces. The package stays the paper's published witness until its release pins the framework (tasks LM33, LM36).
The Lean side (16 October 2026): the theorems of the interactions theme (Theme/Interactions.lean, Theme/Unitary.lean) and its
kernel-decided certificates (Theme/Fields.lean), the paper module FrcCore/Fields.lean, and the chart readings on Mathlib
(FrcLedger/Theme/Fields.lean); the keys in Keys/Interactions.lean, the certificates Ledgers/P27Fields.lean.

The anchor Ω = 4S + 1 at the scale import (ln Ω = 283.5) enters one check, B3, and is read from frc.chart (LN_OMEGA, the
bracket of ln 10); no numeral above Ω is formed. The "Ω ≡ 5 (mod 12)" of E8 and F7 is the paper's residue clause on the
shells, decided in the integers.

    python3 -m frc.ledgers.p27_fields         every block, the census; exit 1 if a check fails (≈ 6 s)
    python3 -m frc.ledgers.p27_fields C       one block (A to H)
    from frc.ledgers.p27_fields import R; R.predicate("27:C5")    one predicate: its blocks run once per session

Blocks:  A  electromagnetism: the finite U(1), Maxwell's uniqueness, the bare coupling     (27:C2, C3, X1, X2, X3)
         B  the finite gauge correspondence                                              (27:C1, C7, C12)
         C  the weak sector: the SU(2) connection, the breaking, the spectrum, V − A       (27:C4–C6, C10, X1, X3–X6)
         D  the electroweak scale against the transmutation forms                        (27:Y1, Z1)
         E  the strong sector: SU(3) over F_4 and F_25, the string tension, the β-function  (27:C7, C8, X1, X7, Z1)
         F  matter: one generation, unification, the generations, the residue mod 12      (27:C6, C8–C11, X8, X9, P1, P2, P4, P6, P7)
         G  the running couplings and the mass mechanism                                 (27:C6, P3, P5, Z1)
         H  flavour: the Koide form and the strong-CP angle                              (27:X10, X11, P8, P9)

Checks: 58, of them 38 EXACT and 20 CHART (A3, A4, A11, A12, B1c, B3, B4c, B5, C8c, D1, D2, E2, E5c, E7, F3, F6c, G2,
G3, G4, H2). The notebook frc/ledgers/p27_fields.ipynb runs one predicate per cell, the cell's id its key (gate G13).
"""
import random
import sys
from collections import Counter
from fractions import Fraction as Q
from itertools import product
from math import comb, gcd, isqrt

from frc.registry import Registry
from frc import arith
from frc import interactions as I
from frc import ladder as LD
from frc import chart as CH
from frc import chart_fields as CF

# ---- generated by ci/make_ledgers.py from docs/27-fields/27-fields-ledger.json; edit the ledger, not this table ----
PAPER = "27-fields"
KEYS = {"A1": "p27001", "A2": "p27002", "A3": "p27003", "A4": "p27004", "A5": "p27005", "A6": "p27006", "B1": "p27007", "B2": "p27008", "B3": "p27009", "B4": "p27010", "B5": "p27011", "B6": "p27012", "C1": "p27013", "C2": "p27014", "C3": "p27015", "C4": "p27016", "C5": "p27017", "C6": "p27018", "C7": "p27019", "C8": "p27020", "C9": "p27021", "C10": "p27022", "C11": "p27023", "C12": "p27049", "X1": "p27024", "X2": "p27025", "X3": "p27026", "X4": "p27027", "X5": "p27028", "X6": "p27029", "X7": "p27030", "X8": "p27031", "X9": "p27032", "X10": "p27033", "X11": "p27034", "P1": "p27035", "P2": "p27036", "P3": "p27037", "P4": "p27038", "P5": "p27039", "P6": "p27040", "P7": "p27041", "P8": "p27042", "P9": "p27043", "Z1": "p27047", "Y1": "p27048"}       # every row of the ledger: its label and its accession key
LEAN = {"C1": "core, ml", "C2": "core", "C3": "core", "C4": "core", "C5": "core", "C6": "core, ml", "C7": "core, ml", "C8": "core", "C9": "core", "C10": "core", "C11": "core", "X1": "core", "X2": "core", "X3": "core", "X4": "core", "X5": "core", "X6": "core", "X7": "core, ml", "X8": "core", "X9": "core", "X10": "core", "X11": "core", "P1": "core", "P2": "core", "P3": "core, ml", "P4": "core, ml", "P5": "core, ml", "P6": "core", "P7": "core", "P8": "core", "P9": "core"}       # 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 27:XN): the predicate(s) each check witnesses. The union over a
# family's checks contains the package's row list for that family (fldcommon.LEDGER); since 16 October 2026 the checks
# also witness the rows the package did not (27:X1, P2, P6, P7, C12), and the correspondence's chart checks B3, B5 witness
# the window row 27:C12 in place of 27:C1.
LEDGER = {
    "A1": "27:C2", "A2": "27:X2, 27:C2", "A3": "27:C3, 27:C2", "A4": "27:C2, 27:C3", "A5": "27:C2, 27:X3, 27:X1", "A6": "27:X3, 27:C2",
    "A7": "27:C2, 27:C3", "A8": "27:C3", "A9": "27:C2", "A10": "27:C2", "A11": "27:C2", "A12": "27:C2",
    "B1": "27:C1", "B1c": "27:C1", "B2": "27:C1", "B3": "27:C12", "B4": "27:C7, 27:C1", "B4c": "27:C7, 27:C1", "B5": "27:C12",
    "C1": "27:C4", "C2": "27:C4, 27:X1", "C3": "27:C5, 27:X5", "C4": "27:C6, 27:X4", "C5": "27:C5, 27:X5, 27:X3", "C6": "27:C5, 27:X5",
    "C7": "27:C4, 27:X6", "C8": "27:C6", "C8c": "27:C6", "C9": "27:X6, 27:C4", "C10": "27:C10",
    "D1": "27:Z1", "D2": "27:Y1",
    "E1": "27:C7", "E2": "27:X7", "E3": "27:C7", "E4": "27:X7, 27:C7", "E5": "27:X7, 27:C7", "E5c": "27:X7, 27:C7", "E6": "27:X7",
    "E7": "27:Z1", "E8": "27:C7, 27:C8, 27:X1",
    "F1": "27:C8, 27:X8, 27:C6, 27:P2, 27:P6, 27:P7", "F2": "27:C9, 27:X8", "F3": "27:P4", "F4": "27:C9, 27:X8", "F5": "27:C10",
    "F6": "27:C10, 27:X9, 27:P1, 27:P2, 27:P6, 27:P7", "F6c": "27:C10, 27:X9, 27:P1", "F7": "27:C11", "F8": "27:C9, 27:X8",
    "G1": "27:C6", "G2": "27:P3", "G3": "27:P5", "G4": "27:Z1",
    "H1": "27:X10, 27:P8", "H2": "27:P8", "H3": "27:X11, 27:P9", "H4": "27:X11, 27:P9",
}

# the package record (fld.<script>) each check reproduces (a chart check with the suffix c reproduces its parent's record)
FAMILY = {
    "A1": "em1_prototype", "A2": "em1_prototype", "A3": "em1_prototype", "A4": "em1_prototype",
    "A5": "enumerate_maxwell", "A6": "enumerate_maxwell", "A7": "audit_finitism", "A8": "audit_finitism",
    "A9": "audit_finitism", "A10": "audit_finitism", "A11": "o2_numbers", "A12": "p2",
    "B1": "correspondence", "B1c": "correspondence", "B2": "correspondence", "B3": "correspondence", "B4": "correspondence",
    "B4c": "correspondence", "B5": "correspondence",
    "C1": "p3", "C2": "ew1", "C3": "ew1", "C4": "ew1", "C5": "weak_spectrum", "C6": "weak_spectrum",
    "C7": "weak_current", "C8": "weak_current", "C8c": "weak_current", "C9": "p4", "C10": "p10",
    "D1": "v_scale", "D2": "v_scale",
    "E1": "qcd", "E2": "qcd", "E3": "p5", "E4": "string_tension", "E5": "string_tension", "E5c": "string_tension", "E6": "p6",
    "E7": "p6", "E8": "missing_rank",
    "F1": "generation", "F2": "p8", "F3": "p8", "F4": "p8b", "F5": "p9", "F6": "p9b", "F6c": "p9b", "F7": "p11", "F8": "p8b",
    "G1": "p1", "G2": "p1", "G3": "p7", "G4": "p7",
    "H1": "koide", "H2": "koide", "H3": "strongcp", "H4": "strongcp",
}

BLOCK = {"A": "electromagnetism: the finite U(1), Maxwell's uniqueness, the bare coupling",
         "B": "the finite gauge correspondence",
         "C": "the weak sector: the SU(2) connection, the breaking, the spectrum, the V − A current",
         "D": "the electroweak scale against the transmutation forms",
         "E": "the strong sector: SU(3) over F_4 and F_25, the string tension, the β-function",
         "F": "matter: one generation, unification, the generations, the residue mod 12",
         "G": "the running couplings and the mass mechanism",
         "H": "flavour: the Koide form and the strong-CP angle"}

# the deciding check of each witnessed predicate (the other checks that touch it are corroboration)
PREDICATES = {
    "27:C1": "B2", "27:C2": "A5", "27:C3": "A3", "27:C4": "C2", "27:C5": "C5", "27:C6": "C4", "27:C7": "E8", "27:C8": "F1",
    "27:C9": "F4", "27:C10": "F6", "27:C11": "F7", "27:C12": "B3",
    "27:X1": "A5", "27:X2": "A2", "27:X3": "A6", "27:X4": "C4", "27:X5": "C5", "27:X6": "C9", "27:X7": "E4", "27:X8": "F1",
    "27:X9": "F6", "27:X10": "H1", "27:X11": "H3",
    "27:P1": "F6", "27:P2": "F6", "27:P3": "G2", "27:P4": "F3", "27:P5": "G3", "27:P6": "F6", "27:P7": "F6", "27:P8": "H2",
    "27:P9": "H3",
    "27:Y1": "D2", "27:Z1": "D1",
}

R = Registry("27", "fields", LEDGER, PREDICATES, sources=[__file__])

PI = CH.pi_bracket()                                  # π between two rationals (Machin; the chart theme)


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


def _pi_scaled_within(value_over_pi, centre, tol):
    """|v/π − centre| < tol for both ends of the bracket of π (v > 0)."""
    return all(abs(value_over_pi / p - centre) < tol for p in PI)


# ------------------------------------------------------------------------------------------------------------
# block A: electromagnetism (27:C2, C3, X1, X2, X3)
# The finite U(1) lives on the phase cycle Z/M (em1_prototype). Its plaquette flux, Wilson action, covariant difference
# and global phases are gauge invariant as integer identities. The holonomy of a loop is the enclosed flux (discrete
# Stokes). The lattice Green's function carries the Coulomb coefficient 1/4π on the chart, and the field-quadratic action
# makes like charges repel. The range-1 gauge- and cube-invariant quadratic actions form a space of dimension 2 on
# L = 4, 5, 6: one relevant operator, Maxwell's transverse projector, and one irrelevant one (enumerate_maxwell); that
# uniqueness is the gauging of the phase frame (27:X1). audit_finitism makes the same claims with no float, and o2_numbers
# and p2 read the bare coupling 1/4π on the chart.
@R.block("A", BLOCK["A"])
def block_A():
    """Block A — electromagnetism: A1–A12 (A3, A4, A11, A12 CHART)."""
    # A1 gauge invariance on Z/M for M = 12, 52, 156, 420 (the phase cycles of F_13, F_53, F_157, F_421), on 200 random
    #    configurations each (L = 4). The Wilson action is a function of the plaquette values, so their multiset decides it.
    rng = random.Random(20260615); L = 4; n = L ** 3; ok = True; det = []
    for M in (12, 52, 156, 420):
        okF = okS = okC = okG = True
        for _ in range(200):
            A = [[rng.randrange(M) for _ in range(n)] for _ in range(3)]
            lam = [rng.randrange(M) for _ in range(n)]; phi = [rng.randrange(M) for _ in range(n)]
            Ap = I.gauge_transform(A, lam, M, L)
            vals, valsp = [], []
            for i in range(3):
                for j in range(i + 1, 3):
                    F, Fp = I.plaquette(A, i, j, M, L), I.plaquette(Ap, i, j, M, L)
                    okF &= F == Fp; vals += F; valsp += Fp
            okS &= Counter(vals) == Counter(valsp)
            phip = [(a + b) % M for a, b in zip(phi, lam)]
            okC &= I.gauge_transform([[(-a) % M for a in row] for row in A], phi, M, L) == \
                I.gauge_transform([[(-a) % M for a in row] for row in Ap], phip, M, L)       # φ(x+e_i) − φ(x) − A_i(x)
            c = rng.randrange(M)
            okG &= I.gauge_transform(A, [c] * n, M, L) == A
        ok &= okF and okS and okC and okG
        det.append(f"M={M}: {okF} {okS} {okC} {okG}")
    R.check("A1", "plaquette flux, Wilson action, covariant difference and global superselection gauge-invariant over Z/M, "
            "M = 12, 52, 156, 420, on 200 random configurations each (L = 4)", ok, "; ".join(det))

    # A2 discrete Stokes: the holonomy of a rectangle is the enclosed flux mod M, and adjacent rectangles add
    rng = random.Random(156); L = 8; ok_s = ok_a = True
    for M in (12, 156, 420):
        for _ in range(100):
            Ax = {(x, y): rng.randrange(M) for x in range(L) for y in range(L)}
            Ay = {(x, y): rng.randrange(M) for x in range(L) for y in range(L)}
            F = {(x, y): (Ax[(x, y)] + Ay[((x + 1) % L, y)] - Ax[(x, (y + 1) % L)] - Ay[(x, y)]) % M
                 for x in range(L) for y in range(L)}
            a, b = rng.randrange(2, L), rng.randrange(2, L)
            enclosed = sum(F[(x, y)] for x in range(a) for y in range(b)) % M
            ok_s &= I.holonomy(Ax, Ay, 0, 0, a, b, L, M) == enclosed
            a2 = rng.randrange(1, L - a + 1)
            ok_a &= (I.holonomy(Ax, Ay, 0, 0, a, b, L, M) + I.holonomy(Ax, Ay, a, 0, a2, b, L, M)) % M == \
                I.holonomy(Ax, Ay, 0, 0, a + a2, b, L, M)
    # 27:X2 (p27025)
    R.check("A2", "charge = winding: the holonomy of a loop is the enclosed flux mod M (discrete Stokes) and additive over "
            "adjacent loops, M = 12, 156, 420, 100 random fields each (L = 8)", ok_s and ok_a, f"Stokes {ok_s}, additive {ok_a}")

    # A3 [chart] the Coulomb coefficient of the L = 128 periodic lattice Green's function (the chart theme's separable sums)
    C, target, resid, g0 = CF.coulomb_fit(128)
    ratio = Q(C) / Q(target)
    # 27:C3 (p27015)
    R.check("A3", "[chart] the lattice Green's function on L = 128 carries the Coulomb coefficient: C/(1/4π) within 2 %, the "
            "fit residual below 2 %", abs(ratio - 1) < Q(2, 100) and Q(resid) < Q(2, 100),
            f"C = {C:.5f}, 1/4π = {target:.5f}, ratio = {C / target:.4f}, rel. residual = {100 * resid:.2f} %, g(0) = {g0:.4f}",
            kind="CHART")

    # A4 [chart] the sign: like charges repel under the field-quadratic action, gravity's linear coupling attracts (L = 48)
    seps, Uem, Ugr = CF.sign_dichotomy(48)
    em = all(Q(Uem[i]) > Q(Uem[i + 1]) > 0 for i in range(len(seps) - 1))
    gr = all(Q(Ugr[i]) < Q(Ugr[i + 1]) < 0 for i in range(len(seps) - 1))
    R.check("A4", "[chart] like charges repel (U_EM > 0, falling with r) and gravity attracts (U < 0, deepening as r → 0) at "
            "r = 6 … 20 on L = 48", em and gr, "U_EM×1e3 = " + ", ".join(f"{1000 * u:.3f}" for u in Uem), kind="CHART")

    # A5 Maxwell's plaquette action is admissible (L = 5), and the admissible space has exact corank 2 on L = 4, 5, 6
    pars, rows5 = I.maxwell_constraints(5)
    cM = I.maxwell_form(5)
    ok = all(sum(r.get(a, 0) * cM[a] for a in r) == 0 for r in rows5) and any(cM)
    det = [f"{len(pars)} range-1 parameters"]
    adm = {}
    for L in (4, 5, 6):
        pars, rows = I.maxwell_constraints(L)
        rk = I.rank_mod(rows, len(pars), (1 << 61) - 1)
        basis = I.nullspace(rows, len(pars))
        adm[L] = basis
        ok &= len(pars) - rk == 2 == len(basis)
        det.append(f"L={L}: corank {len(pars) - rk} over F_(2^61-1), rational nullity {len(basis)}")
    # 27:C2 (p27014), 27:X1 (p27024)
    R.check("A5", "Maxwell's plaquette action is gauge- and hypercubic-invariant; the range-1 translation-, gauge- and "
            "hypercubic-invariant quadratic actions have exact corank 2 on L = 4, 5, 6: the gauging of the phase frame by the "
            "one recipe leaves no choice of operator", ok, "; ".join(det))

    # A6 the split: the quadratic part of the cosine symbol has rank 1 on the admissible space, its image is the
    #    transverse projector |k|²δ − kk (exactly), the constant part vanishes, so the second operator is O(k⁴)
    P = I.transverse_projector(); ok = True; det = []
    flat = lambda S0, S2: [x for r in S0 for x in r] + [x for a in S2 for b in a for c in b for x in c]
    for L in (4, 5, 6):
        vecs = [flat(*I.symbol_taylor(I.kernel_of(v))) for v in adm[L]]
        rk = len(vecs[0]) - len(I.nullspace([{k: v[k] for k in range(len(v)) if v[k]} for v in vecs], len(vecs[0])))
        rel = next(v for v in vecs if any(v))
        S2 = rel[9:]; Pf = [x for a in P for b in a for c in b for x in c]
        lam = next(s / p for s, p in zip(S2, Pf) if p)
        proj = all(s == lam * p for s, p in zip(S2, Pf)) and lam != 0 and not any(rel[:9])
        ok &= rk == 1 and proj
        det.append(f"L={L}: {rk} relevant + {len(vecs) - rk} irrelevant, relevant = {lam} × transverse projector")
    # 27:X3 (p27026)
    R.check("A6", "the admissible space splits into one relevant O(k²) operator, exactly the transverse projector "
            "|k|²δ − kk, and one irrelevant O(k⁴) operator, on L = 4, 5, 6", ok, "; ".join(det))

    # A7 F(dλ) = 0 on all 64 basis gauge fields of L = 4, hence for every λ by linearity. A constant gauge is inert.
    L = 4; worst = 0
    for s in range(L ** 3):
        lam = [int(x == s) for x in range(L ** 3)]
        A = I.gradient(lam, L)
        for i in range(3):
            for j in range(i + 1, 3):
                worst = max(worst, max(abs(v) for v in I.plaquette(A, i, j, None, L)))
    const = all(v == 0 for row in I.gradient([7] * L ** 3, L) for v in row)
    R.check("A7", "F(dλ) = 0 exactly on all 64 basis gauge fields (L = 4), and the gradient of a constant vanishes",
            worst == 0 and const, f"max |F| = {worst}")

    # A8 the L = 4 Green's function in exact rationals (the quarter-turn DFT): two unit charges at separation 1
    axis = [I.green_exact(4, (k, 0, 0)) for k in range(4)]
    R.check("A8", "the L = 4 Coulomb Green's function is an exact rational: U(separation 1) = 257/7680, and "
            "G(0,0,0) > G(1,0,0) > G(2,0,0)", axis[1] == Q(257, 7680) and axis[0] > axis[1] > axis[2],
            "G(n,0,0) = " + ", ".join(str(g) for g in axis))

    # A9 the admissible nullity by the integer Gram matrix of the constraints (the package's route), rank mod two primes
    pars, rows = I.maxwell_constraints(4); npar = len(pars)
    gram = [[0] * npar for _ in range(npar)]
    for r in rows:
        items = list(r.items())
        for a, x in items:
            for b, y in items: gram[a][b] += x * y
    grows = [{b: gram[a][b] for b in range(npar) if gram[a][b]} for a in range(npar)]
    rk = max(I.rank_mod(grows, npar, 2147483647), I.rank_mod(grows, npar, 2147483629))
    R.check("A9", "the O1 admissible nullity is 2 by the exact rank of the integer Gram matrix (123 range-1 parameters, L = 4)",
            npar - rk == 2 and npar == 123, f"parameters {npar}, rank {rk}, nullity {npar - rk}")

    # A10 the Wilson action is cyclotomic: 1 − cos(2πF/M) = 1 − (ζ^F + ζ^−F)/2 lies in Q(ζ_M). Its values at (12, 1),
    #     (12, 3), (52, 13), (8, 1) are 1 − √3/2, 1, 1, 1 − √2/2, decided by the square of 2cos and by the sign of cos.
    def zc(M, F):
        v = [0] * M; v[F % M] += 1; v[(-F) % M] += 1
        return v
    def zsq(v, M):
        w = [0] * M
        for a, x in enumerate(v):
            for b, y in enumerate(v): w[(a + b) % M] += x * y
        return w
    def is_value(M, F, sq, sign):
        v = zsq(zc(M, F), M); v[0] -= sq
        quarter = Q(F, M) % 1
        positive = quarter < Q(1, 4) or quarter > Q(3, 4)
        return I.cyclo_zero(v, M) and (sign == 0 or positive == (sign > 0))
    ok = is_value(12, 1, 3, 1) and I.cyclo_zero(zc(12, 3), 12) and I.cyclo_zero(zc(52, 13), 52) and is_value(8, 1, 2, 1)
    R.check("A10", "1 − cos(2πF/M) is exact in Q(ζ_M): 2cos(2π/12) = √3, cos(2π·3/12) = cos(2π·13/52) = 0, 2cos(2π/8) = √2",
            ok, "(12,1): 1 − √3/2; (12,3): 1; (52,13): 1; (8,1): 1 − √2/2")

    # A11 [chart] the bare coupling as phase-channel capacity: 1/α_bare = 4π, the hierarchy α/(m_p/m_P)² on the measured
    #     constants, the gap 4π → 137.04
    inv_bare, ratio_f, gap_f = CF.o2_numbers(); d = CF.DATA["o2_numbers"]
    hier = d["m_P"] ** 2 / (d["alpha0_inv"] * d["m_p"] ** 2)
    ok = _pi_scaled_within(Q(inv_bare), 4, Q(1, 10 ** 12)) and 10 ** 36 < hier < 2 * 10 ** 36 and abs(Q(ratio_f) / hier - 1) < Q(1, 10 ** 9)
    ok &= _pi_scaled_within(d["alpha0_inv"] / 4, Q(10905, 1000), Q(1, 100))
    R.check("A11", "[chart] 1/α_bare = 4π; the EM/gravity hierarchy α/(m_p/m_P)² on the measured m_p, m_P and α lies in "
            "[10³⁶, 2·10³⁶]; the gap 4π → 137.04 is a factor 10.9 (the open part)", ok,
            f"hierarchy = {ratio_f:.3e}, gap = {gap_f:.3f}", kind="CHART")

    # A12 [chart] the order-one coefficient 1, and the saturation profile 4πr² sin E = q with its core and self-energy
    a20 = Q(CF.saturation_potential(20)) * 20
    rstar = Q(CF.saturation_core()); U = Q(CF.saturation_self_energy(CF.saturation_core()))
    ok = all(abs(a20 * 4 * p - 1) < Q(1, 100) for p in PI)                           # r·A₀(20) against 1/4π within 1 %
    ok &= all(abs(rstar ** 2 * 4 * p - 1) < Q(1, 10 ** 12) for p in PI)            # r* = (4π)^(−1/2)
    ok &= all(Q(1, 2) < U * 8 * p * rstar < 2 for p in PI) and U > 0             # U of the order q²/(8πr*)
    R.check("A12", "[chart] α_bare = e²/4π = 1/4π with coefficient 1 (e = 1, one phase quantum); the weak-field Coulomb "
            "coefficient r·A₀(r) of the saturation profile 4πr² sin E = q at r = 20 within 1 % of 1/4π; the core r* = (4π)^(−1/2); "
            "a finite self-energy of the order q²/(8πr*)", ok,
            f"r·A₀(20) = {CH.show(a20, '.5f')}, r* = {CH.show(rstar, '.5f')}, U(>r*) = {CH.show(U, '.4f')}", kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block B: the finite gauge correspondence (27:C1, C7, C12)
# correspondence.py has eight blocks. Z_M embeds in U(1) with a positive Wilson weight (A). SU(2, F_3) = 2T is a finite
# subgroup of SU(2, C) of order 24 = |SL(2, F_3)|, with S ≥ 0 (B) and S a class function (D). Near the identity
# S = (ε²/2n) Tr X² + O(ε⁴), the Yang–Mills term (C), and the window residue grows linearly in H (E). The area law σ > 0
# follows from positivity on 2T (F). The character lift is fixed on the shells (G). Finite quadrature converges on the
# near-identity ball (H). Since 16 October 2026 A, B, D and F are decided exactly (B1, B2, B4: Q(ζ_M), the quaternions
# over Q, Q[x]); C, E, G and H are the chart's resolvable-window reading (B3, B5, row 27:C12), with B1c and B4c the
# chart clauses of B1 and B4.
@R.block("B", BLOCK["B"])
def block_B():
    """Block B — the finite gauge correspondence: B1, B2, B4 EXACT; B1c, B3, B4c, B5 CHART."""
    # B1 (A) Z_M -> U(1), j -> ζ^j, exactly in Q(ζ_M) for M = 12, 52, 156, 420: a homomorphism (x^j x^k reduced modulo Φ_M
    #    is ζ^{(j+k) mod M}, since ζ^M = 1), injective (the M canonical forms are distinct), and the Wilson weight
    #    1 − Re ζ^k = |1 − ζ^k|²/2 as an identity of Z[ζ_M], positive off k ≡ 0
    ok = True; det = []
    for M in (12, 52, 156, 420):
        hom, inj = I.roots_embed(M); ident, pos = I.wilson_weight(M)
        ok &= hom and inj and ident and pos and len(I.roots_of_unity(M)) == M
        det.append(f"M={M}: homomorphism {hom}, injective {inj}, weight identity {ident}, positive off 0 {pos}")
    R.check("B1", "Z_M embeds in U(1) as the M-th roots of unity, exactly in Q(ζ_M): j ↦ ζ^j is a homomorphism and injective "
            "on Z/M for M = 12, 52, 156, 420 (the phase cycles of F_13, F_53, F_157, F_421); the Wilson weight "
            "1 − Re ζ^k = |1 − ζ^k|²/2 is an identity of Z[ζ_M], so it is ≥ 0, and it vanishes only at k ≡ 0", ok, "; ".join(det))

    # B1c [chart] the window residue of the embedding, 2π/M, at M = 1000
    res = 2 * PI[1] / 1000
    R.check("B1c", "[chart] the window residue 2π/M of the embedding Z_M → U(1) at M = 1000 is below 10⁻²", res < Q(1, 100),
            f"2π/M < {CH.show(res, '.5f')}", kind="CHART")

    # B2 (B, D) 2T is 24 unit quaternions with integer and half-integer coordinates, each an SU(2) matrix over the Gaussian
    #    rationals, closed under the quaternion product. |SL(2, F_3)| = 24. S(U) = 1 − ½ Re Tr U is nonnegative and a class
    #    function (all 24 × 24 pairs, exact).
    G, closed, unit, traces = I.tetrahedral_quaternions()
    su2 = all(I.su2_unitary(x) for x in G)
    sl23 = I.sl2_order(3)
    S = [1 - x[0] for x in G]                                                     # 1 − ½ Re Tr U, Tr U = 2a
    cls = I.trace_class_function(G)
    ok = len(G) == 24 == len(set(G)) and closed and unit and su2 and sl23 == 24
    ok &= traces == {2: 1, -2: 1, 0: 6, 1: 8, -1: 8} and min(S) >= 0 and cls
    # 27:C1 (p27013)
    R.check("B2", "SU(2, F_3) = 2T is a finite subgroup of SU(2, C), exactly over Q: 24 unit quaternions with integer and "
            "half-integer coordinates, closed under the quaternion product, each unitary with det 1 over the Gaussian rationals; "
            "|SL(2, F_3)| = 24; the trace multiset {2:1, −2:1, 0:6, 1:8, −1:8}; S(U) = 1 − ½ Re Tr U ≥ 0 on 2T and a class "
            "function", ok, f"|2T| = {len(G)}, |SL(2,F_3)| = {sl23}, closed {closed}, unit {unit}, min S = {min(S)}")

    # B3 (C, E) [chart] low curvature, read in the chart: S/ε² → Tr X²/2n for SU(2) and SU(3) with an O(ε⁴) residue. The
    #    F_q directions are spaced 1/q. The window residue of H links grows linearly in H and is O(ε⁴) per link. The
    #    substrate term H/Ω of the window bound is read on the anchor: ln Ω = 283.5 > 122 ln 10, so H/Ω < 10⁻¹²⁰ at H = 100.
    x2, x3 = (Q(1, 2), Q(-1, 2)), (Q(1, 2), Q(-1, 2), Q(0))
    c2, c3 = sum(x * x for x in x2) / 4, sum(x * x for x in x3) / 6                 # Tr X²/(2n)
    eps = Q(1, 1000)
    ok = abs(Q(CF.s_fund_diag(x2, eps)) / eps ** 2 - c2) < Q(1, 10 ** 6)
    res = [(Q(CF.s_fund_diag(x2, e)) - c2 * e ** 2) / e ** 4 for e in (Q(1, 10), Q(1, 100), Q(1, 1000))]
    ok &= max(abs(r) for r in res) < 1
    ok &= abs(Q(CF.s_fund_diag(x3, eps)) / eps ** 2 - c3) < Q(1, 1000)
    ok &= all(Q(1, q) < Q(2, 100) for q in (53, 997))
    r10, n10 = CF.window_residue(10, seed=10); r100, n100 = CF.window_residue(100, seed=100)
    e5 = Q(5, 100)
    ok &= 8 < Q(r100) / Q(r10) < 12 and Q(r10) / 10 < 5 * e5 ** 4
    ok &= CH.LN_OMEGA > 122 * CH.log10_bracket()[1]                              # Ω > 10¹²², so 100/Ω < 10⁻¹²⁰
    # 27:C12 (p27049)
    R.check("B3", "[chart] the resolvable window: the compact Wilson action's expansion S(exp iεX) = (ε²/2n) Tr X² + O(ε⁴), the "
            "Yang–Mills coefficient 1/(2n), for SU(2) (c = 1/8) and SU(3) (c = 1/12), the finite action compared at q = 3 only "
            "(B2); the 1/q-net at q = 53, 997; the window residue grows linearly in H "
            "(r(100)/r(10) ≈ 10) and is O(ε⁴) per link; the substrate term H/Ω of the window bound at H = 100 is below 10⁻¹²⁰ "
            "on the anchor Ω = 4S + 1 at the scale import, ln Ω = 283.5", ok,
            f"r(10) = {r10:.2e}, r(100) = {r100:.2e}, ratio {r100 / r10:.2f}; ln Ω = {CH.show(CH.LN_OMEGA, '.1f')} > "
            f"122 ln 10 = {CH.show(122 * CH.log10_bracket()[1], '.1f')}", kind="CHART")

    # B4 (F) the area law from positivity on 2T, exactly. Σχ = 0, and c₁(β) = N(x)/D(x) in x = e^{β/2}, with
    #    N = (x − 1)(x³ + 5x² + 5x + 1) and D − N = 4x³ + 6x² + 12x + 2. N, D and D − N are positive for every x > 1 by the
    #    Taylor shift to x = 1 + y, so 0 < c₁ < 1 and σ = −ln c₁ > 0 for every β > 0.
    Nn, Dd, positive = I.area_law_rational()
    exact = sum(t * m for t, m in traces.items()) == 0 and positive
    exact &= Nn == [Q(c) for c in (-1, -4, 0, 4, 1)] and Dd == [Q(c) for c in (1, 8, 6, 8, 1)]
    c1_at = I.area_law_rational(Q(3, 2))[3]                                       # one rational x > 1, exactly
    exact &= 0 < c1_at < 1
    R.check("B4", "confinement from positivity on 2T, exactly: Σχ = 0 over the trace multiset; c₁(β) = "
            "(x⁴ + 4x³ − 4x − 1)/(x⁴ + 8x³ + 6x² + 8x + 1), x = e^{β/2}, has numerator, denominator and their difference "
            "positive for every x > 1 (the Taylor shift to x = 1 + y), so 0 < c₁ < 1 and σ = −ln c₁ > 0 for every β > 0",
            exact, f"c₁(x = 3/2) = {c1_at}")

    # B4c [chart] the same c₁ on the chart at β = 0.2, 0.5, 1.0: in (0, 1) and increasing in β
    vals = [Q(CF.c1_traces(traces, 2, b)) for b in (Q(2, 10), Q(5, 10), Q(1))]
    R.check("B4c", "[chart] c₁(β) of 2T on the chart at β = 0.2, 0.5, 1.0 lies in (0, 1) and increases with β, so σ = −ln c₁ "
            "is positive and falling", all(0 < c < 1 for c in vals) and vals[0] < vals[1] < vals[2],
            "c₁ = " + ", ".join(CH.show(c, ".3f") for c in vals), kind="CHART")

    # B5 (G, H) [chart] the character lift. The fundamental coefficient I_ρ/d_ρ = 1/n is one rational on every admissible
    #    shell, so the finite-minus-compact difference vanishes at each (the package's last clause, recorded as it is).
    #    The midpoint residue of finite quadrature decreases as the grid refines, with N·err non-increasing.
    ok = True
    for n in (2, 3):
        shells = [q for q in (2, 3, 5, 7, 13) if gcd(n, q) == 1]
        ok &= all(n % q for q in shells) and len(shells) >= 4                      # the admissible shells: n invertible on each
    e = [Q(CF.quadrature_error(N)) for N in (50, 100, 200)]
    ok &= e[0] > e[1] > e[2] and 50 * e[0] >= 100 * e[1] >= 200 * e[2] - Q(1, 10 ** 12)
    R.check("B5", "[chart] the character lift on the resolvable window: the fundamental coefficient 1/n is fixed on the "
            "admissible shells for SU(2), SU(3), so the finite-minus-compact difference vanishes at each; the finite quadrature "
            "residue decreases with the grid, N·err non-increasing (N = 50, 100, 200)", ok,
            "errors " + ", ".join(CH.show(x, ".2e") for x in e), kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block C: the weak sector (27:C4, C5, C6, C10, X1, X3–X6)
# p3 builds SU(2, F_3) over K = F_9 with its Wilson invariance and the drive's centraliser. ew1 reads the breaking in
# F_13 as drive–torus misalignment (the gauging of the spinor frame, 27:X1), with the neutral mass matrix, ρ = 1 and the
# Weinberg angle from the charge spectrum. weak_spectrum takes the Hessian of S_ρ at the broken vacuum over Q and over
# F_13 and F_5. weak_current sums the V − A characters and derives G_F (C8), read against the measured G_F on the chart
# (C8c). p4 decouples the Frobenius branch. p10 reads chirality relative to the drive.
@R.block("C", BLOCK["C"])
def block_C():
    """Block C — the weak sector: C1–C10 EXACT, C8c CHART."""
    # C1 SU(2, 3) over F_9 = F_3[i] has order 24 and its Wilson trace is invariant exhaustively. The plaquette and the
    #    doublet transform covariantly. The drive diag(i, −i) has a proper centraliser, so SU(2) breaks to a U(1).
    K = I.Fq2(3, 0, 2)
    SU2 = [((a, b), (c, d)) for a, b, c, d in product(K.elements(), repeat=4)
           if I.mat_mul(K, I.dagger(K, ((a, b), (c, d))), ((a, b), (c, d))) == ((K.one, K.zero), (K.zero, K.one))
           and I.det(K, ((a, b), (c, d))) == K.one]
    mm = lambda X, Y: I.mat_mul(K, X, Y); inv = lambda X: I.dagger(K, X); tr = lambda X: I.trace(K, X)
    ok = len(SU2) == 24 == 3 * (9 - 1)
    ok &= any(mm(X, Y) != mm(Y, X) for X in SU2 for Y in SU2) and all(tr(X)[1] == 0 for X in SU2)
    ok &= all(tr(mm(mm(g, X), inv(g))) == tr(X) for g in SU2 for X in SU2)
    Uab, Ubc, Ucd, Uda = SU2[5], SU2[11], SU2[17], SU2[23]; ga, gb, gc, gd = SU2[3], SU2[8], SU2[14], SU2[20]
    P = mm(mm(Uab, Ubc), mm(Ucd, Uda))
    U2 = [mm(mm(ga, Uab), inv(gb)), mm(mm(gb, Ubc), inv(gc)), mm(mm(gc, Ucd), inv(gd)), mm(mm(gd, Uda), inv(ga))]
    P2 = mm(mm(U2[0], U2[1]), mm(U2[2], U2[3]))
    ok &= P2 == mm(mm(ga, P), inv(ga)) and tr(P2) == tr(P)
    psi_a, psi_b = (SU2[1][0][0], SU2[1][1][0]), (SU2[2][0][0], SU2[2][1][0])
    sub = lambda u, w: tuple(K.sub(x, y) for x, y in zip(u, w))
    D = sub(psi_a, I.matvec(K, Uab, psi_b)); D2 = sub(I.matvec(K, ga, psi_a), I.matvec(K, U2[0], I.matvec(K, gb, psi_b)))
    ok &= D2 == I.matvec(K, ga, D)
    t = (0, 1); drive = ((t, K.zero), (K.zero, K.conj(t)))
    cent = sum(1 for X in SU2 if mm(drive, X) == mm(X, drive))
    ok &= drive in SU2 and cent == 4
    R.check("C1", "SU(2, F_3) over F_9: order 24 = q(q² − 1), non-abelian, Tr ∈ F_3; Tr(gMg⁻¹) = Tr M exhaustively; the "
            "plaquette conjugates and the doublet is covariant; the drive diag(i, −i) has centraliser of order exactly 4", ok,
            f"|SU(2,3)| = {len(SU2)}, Tr P = {tr(P)}, centraliser {cent}")

    # C2 the breaking in F_13. Ad_drive fixes H and scales E, F by g^{±2}. The drive's centraliser in SL₂(F_13) is the
    #    split torus of order p − 1, and the non-split torus does not commute with the drive.
    p, g = 13, 2
    mul = lambda X, Y: ((X[0] * Y[0] + X[1] * Y[2]) % p, (X[0] * Y[1] + X[1] * Y[3]) % p,
                        (X[2] * Y[0] + X[3] * Y[2]) % p, (X[2] * Y[1] + X[3] * Y[3]) % p)
    ti = pow(g, p - 2, p); drive, drive_i = (g, 0, 0, ti), (ti, 0, 0, g)
    eig = {}
    for name, Xb in (("H", (1, 0, 0, p - 1)), ("E", (0, 1, 0, 0)), ("F", (0, 0, 1, 0))):
        Y = mul(mul(drive, Xb), drive_i); c = next(i for i in range(4) if Xb[i])
        eig[name] = Y[c] * pow(Xb[c], p - 2, p) % p
        assert all(Y[i] == eig[name] * Xb[i] % p for i in range(4))
    cent = sum(1 for M in product(range(p), repeat=4) if (M[0] * M[3] - M[1] * M[2]) % p == 1 and mul(M, drive) == mul(drive, M))
    sq = {x * x % p for x in range(p)}; nu = next(x for x in range(2, p) if x not in sq)
    a, b = next((a, b) for a in range(p) for b in range(p) if (a * a - nu * b * b) % p == 1 and not (b == 0 and a == 1))
    ns = (a, nu * b % p, b, a)
    ok = eig["H"] == 1 and eig["E"] != 1 and eig["F"] != 1 and eig["E"] * eig["F"] % p == 1 and cent == p - 1 == 12
    ok &= mul(ns, drive) != mul(drive, ns)
    # 27:C4 (p27016)
    R.check("C2", "electroweak breaking as drive–torus misalignment in F_13: Ad_drive H = H (the unbroken U(1) direction), E, F scaled by "
            "g^{±2} ≠ 1 (gapped W±); the drive's centraliser in SL₂(F_13) is the split torus of order 12; the non-split torus "
            "does not commute: the gauging of the spinor frame", ok,
            f"eigenvalues H {eig['H']}, E {eig['E']}, F {eig['F']}; centraliser {cent}; ν = {nu}")

    # C3 the neutral (W₃, B) mass matrix ¼v²[[g², −gg'], [−gg', g'²]] has determinant 0 (the photon) and trace M_Z²
    names = ("g", "gp", "v"); gg, gp, v = (I.Poly.var(names, x) for x in names)
    M2 = [[gg * gg * v * v * Q(1, 4), -gg * gp * v * v * Q(1, 4)], [-gg * gp * v * v * Q(1, 4), gp * gp * v * v * Q(1, 4)]]
    MW2, MZ2 = gg * gg * v * v * Q(1, 4), (gg * gg + gp * gp) * v * v * Q(1, 4)
    ok = (M2[0][0] * M2[1][1] - M2[0][1] * M2[1][0]).is_zero() and M2[0][0] + M2[1][1] == MZ2
    ok &= MW2 * (gg * gg + gp * gp) == MZ2 * gg * gg                              # ρ = M_W²/(M_Z² cos²θ_W) = 1
    R.check("C3", "the neutral (W₃, B) mass matrix has a zero eigenvalue (the photon) and the other M_Z² = (g² + g'²)v²/4; "
            "custodial ρ = 1 as a polynomial identity", ok, f"M_Z² = {MZ2}")

    # C4 the Weinberg angle from the charge spectrum: Tr T₃²/Tr Q² = 1/2 for a lone lepton doublet, 3/8 for a generation
    def sin2(ferm):
        t3 = sum(Q(a) ** 2 * m for a, qq, m in ferm); q2 = sum(Q(qq) ** 2 * m for a, qq, m in ferm)
        return t3 / q2, t3, q2
    lep = [(Q(1, 2), 0, 1), (Q(-1, 2), -1, 1)]
    gen = [(Q(1, 2), 0, 1), (Q(-1, 2), -1, 1), (0, 1, 1), (Q(1, 2), Q(2, 3), 3), (Q(-1, 2), Q(-1, 3), 3), (0, Q(-2, 3), 3),
           (0, Q(1, 3), 3)]
    s_lep, s_gen, t3, q2 = sin2(lep)[0], *sin2(gen)
    # 27:C6 (p27018), 27:X4 (p27027)
    R.check("C4", "sin²θ_W = Tr T₃²/Tr Q²: 1/2 for a lone lepton doublet, 3/8 for a complete generation (Tr T₃² = 2, "
            "Tr Q² = 16/3)", s_lep == Q(1, 2) and t3 == 2 and q2 == Q(16, 3) and s_gen == Q(3, 8), f"{s_lep}, {s_gen}")

    # C5 the Hessian of the gauged-Higgs action at the broken vacuum over Q: M²_ab = Re (X_a φ₀)†(X_b φ₀), with
    #    X = (gT₁, gT₂, gT₃, g'Y) and φ₀ = (0, v). The eigenvectors e₁, e₂ (M_W²), (0, 0, g', g) (0, the photon) and
    #    (0, 0, g, −g') (M_Z²) are independent, so the spectrum is {0, M_W² (×2), M_Z²}. At sin²θ_W = 3/8 the ratio
    #    M_W²/M_Z² is cos²θ_W = 5/8.
    names = ("i", "g", "gp", "v"); iu, gg, gp, v = (I.Poly.var(names, x) for x in names)
    h = Q(1, 2); z = I.Poly.const(names, 0)
    T = [[[z, h + z], [h + z, z]], [[z, -iu * h], [iu * h, z]], [[h + z, z], [z, -h + z]], [[h + z, z], [z, h + z]]]
    X = [[[gg * e for e in row] for row in T[0]], [[gg * e for e in row] for row in T[1]],
         [[gg * e for e in row] for row in T[2]], [[gp * e for e in row] for row in T[3]]]
    phi0 = [z, v]
    Xphi = [[Xa[r][0] * phi0[0] + Xa[r][1] * phi0[1] for r in range(2)] for Xa in X]
    M2 = [[(Xphi[a][0].conj() * Xphi[b][0] + Xphi[a][1].conj() * Xphi[b][1]).real() for b in range(4)] for a in range(4)]
    MW2, MZ2 = gg * gg * v * v * Q(1, 4), (gg * gg + gp * gp) * v * v * Q(1, 4)
    apply = lambda vec: [sum((M2[a][b] * vec[b] for b in range(4)), z) for a in range(4)]
    vecs = {"e1": ([1 + z, z, z, z], MW2), "e2": ([z, 1 + z, z, z], MW2), "photon": ([z, z, gp, gg], z),
            "Z": ([z, z, gg, -gp], MZ2)}
    ok = all(all((x - lamb * y).is_zero() for x, y in zip(apply(vec), vec)) for vec, lamb in vecs.values())
    ok &= not (gp * (-gp) - gg * gg).is_zero()                                      # the 4 eigenvectors' determinant −(g² + g'²) ≠ 0
    ok &= MW2 * (gg * gg + gp * gp) == MZ2 * gg * gg
    ok &= (M2[2][2] * M2[3][3] - M2[2][3] * M2[3][2]).is_zero()
    ok &= Q(1) / (1 + (Q(3, 8) / (1 - Q(3, 8)))) == Q(5, 8)                        # g'²/g² = 3/5 ⇒ cos²θ_W = 5/8
    # 27:C5 (p27017), 27:X5 (p27028)
    R.check("C5", "the propagating spectrum as the Hessian of S_ρ over Q: eigenvalues {0, g²v²/4 (×2), (g² + g'²)v²/4}, the "
            "photon the exact kernel ∝ (0, 0, g', g), ρ = 1, det(W₃, B) ≡ 0, M_W²/M_Z² = 5/8 at sin²θ_W = 3/8", ok,
            f"M²[W1,W2] = {M2[0][1]} (the real part)")

    # C6 the same operator over F_13 and F_5 (i = √−1 in F_q), at (q, g, g', v) = (13, 1, 2, 2) and (5, 1, 1, 2)
    ok = True; det = []
    for q, g1, g2, vv in ((13, 1, 2, 2), (5, 1, 1, 2)):
        iq = next(x for x in range(q) if x * x % q == q - 1); h2 = pow(2, q - 2, q)
        def gens(i_):
            return [[[0, g1 * h2], [g1 * h2, 0]], [[0, -i_ * g1 * h2], [i_ * g1 * h2, 0]], [[g1 * h2, 0], [0, -g1 * h2]],
                    [[g2 * h2, 0], [0, g2 * h2]]]
        Xp = [[(A[0][1] * vv) % q, (A[1][1] * vv) % q] for A in gens(iq)]
        Xc = [[(A[0][1] * vv) % q, (A[1][1] * vv) % q] for A in gens(q - iq)]
        Mq = [[(Xc[a][0] * Xp[b][0] + Xc[a][1] * Xp[b][1]) % q for b in range(4)] for a in range(4)]
        kern = all(sum(Mq[a][b] * w for b, w in enumerate((0, 0, g2, g1))) % q == 0 for a in range(4))
        dWB = (Mq[2][2] * Mq[3][3] - Mq[2][3] * Mq[3][2]) % q
        ok &= kern and dWB == 0 and Mq[0][0] == Mq[1][1] and (g1 * g1 + g2 * g2) * vv * vv % q != 0
        ok &= (Mq[2][2] + Mq[3][3]) % q == (g1 * g1 + g2 * g2) * vv * vv * h2 * h2 % q          # the trace is M_Z² = (g² + g'²)v²/4
        det.append(f"F_{q}: kernel {kern}, det(W3,B) = {dWB}, M_W² = {Mq[0][0]}")
    R.check("C6", "over F_13 and F_5: (0, 0, g', g) is the exact photon kernel, det(W₃, B) ≡ 0 (ρ = 1), W₁, W₂ degenerate and "
            "M_Z² = (g² + g'²)v²/4 ≠ 0", ok, "; ".join(det))

    # C7 the V − A current: Σ_τ ζ_N^0 = N and Σ_τ ζ_N^{2τ} = 0 in Q(ζ_N), N = q + 1, for q = 3, 5, 7, 13. The chiral
    #    projector P_L = (1/N) Σ_τ diag(1, ζ^{2τ}) = diag(1, 0) is idempotent and kills the right branch (q = 5, 13).
    ok = True
    for q in (3, 5, 7, 13):
        N = q + 1; left = I.char_sum(N, 0)
        ok &= left[0] == N and not any(left[1:]) and I.cyclo_zero(I.char_sum(N, 2), N)
    for q in (5, 13):
        N = q + 1
        PL = (Q(I.char_sum(N, 0)[0], N), Q(0) if I.cyclo_zero(I.char_sum(N, 2), N) else None)
        ok &= PL == (1, 0) and (PL[0] * PL[0], PL[1] * PL[1]) == PL
    R.check("C7", "the V − A current: left = Σζ⁰ = N and right = Σζ_N^{2τ} = 0 exactly (q = 3, 5, 7, 13); P_L = diag(1, 0), "
            "idempotent, annihilating the right branch", ok)

    # C8 the four-fermion amplitude: G_F/√2 = g²/(8M_W²) = 1/(2v²) with M_W² = g²v²/4, so G_F = 1/(√2 v²), a polynomial
    #    identity in g and v
    names = ("g", "v"); gg, v = (I.Poly.var(names, x) for x in names)
    MW2 = gg * gg * v * v * Q(1, 4)
    sym = 8 * MW2 == 2 * v * v * gg * gg                                          # g²/(8 M_W²) = 1/(2 v²)
    R.check("C8", "the four-fermion amplitude: G_F/√2 = g²/(8M_W²) = 1/(2v²) from M_W² = g²v²/4, so G_F = 1/(√2 v²), as a "
            "polynomial identity in g and v", sym, f"8 M_W² = {8 * MW2}")

    # C8c [chart] the reading at v = 246.21965 GeV meets the measured G_F within 0.01 %, compared squared as 2(G_F v²)²
    #     against 1
    d = CF.DATA["weak_current"]; x2 = 2 * (d["G_F"] * d["v"] ** 2) ** 2
    num = (1 - Q(1, 10 ** 4)) ** 2 < x2 < (1 + Q(1, 10 ** 4)) ** 2
    R.check("C8c", "[chart] 1/(√2 v²) at v = 246.22 GeV agrees with the measured G_F within 0.01 %, compared squared as "
            "2(G_F v²)² against 1", num, f"√2 G_F v² = √{CH.show(x2, '.8f')}", kind="CHART")

    # C9 maximal parity violation from the Frobenius branch, exact in Z/(q + 1)
    ok = True
    for q in (3, 5, 7, 13):
        N = q + 1
        ok &= all(q * a % N == (-a) % N for a in range(N))                       # Frobenius z -> z^q is inversion
    for q, dl in ((3, 1), (3, 2), (7, 1), (7, 3)):
        N = q + 1
        DS = [((-a) % N + dl) % N for a in range(N)]; SD = [(-((a + dl) % N)) % N for a in range(N)]
        ok &= (DS == SD) == ((2 * dl) % N == 0)
    for q in (3, 5, 7, 13):
        N = q + 1; dl = next(x for x in range(1, N) if gcd(x, N) == 1)
        right = N if (2 * dl) % N == 0 else 0
        ok &= right == 0 and I.cyclo_zero(I.char_sum(N, 2 * dl), N)
    # 27:X6 (p27029)
    R.check("C9", "Frobenius inverts the boost cycle C_{q+1} (q = 3, 5, 7, 13); the drive commutes with it iff 2δ ≡ 0 (mod N); "
            "over one drive period the left coupling is N and the right exactly 0 for a generator drive", ok)

    # C10 chirality selection: the two orientation conventions disagree on the label and agree on the drive-aligned branch
    #     (the relabelling theorem orientation_flip): the drive-aligned branch carries the exponent 0 and sums to N over the
    #     period, the counter-aligned branch the exponent 2εδ, ε = ±1 the orientation convention, and sums to 0 for either
    #     sign (the inverse exponent 2(N − δ) as well as 2δ); the convention names the aligned branch L (ε = +1) or R (ε = −1).
    ok = True; labels = {}
    for q in (3, 5, 7, 13):
        N = q + 1; dl = next(x for x in range(1, N) if gcd(x, N) == 1)
        for eps in (1, -1):
            counter = (2 * eps * dl) % N                                              # the counter-aligned branch's exponent
            aligned = I.char_sum(N, 0)
            ok &= aligned[0] == N and not any(aligned[1:]) and counter != 0 and I.cyclo_zero(I.char_sum(N, counter), N)
            labels[(q, eps)] = "L" if eps > 0 else "R"
        ok &= labels[(q, 1)] != labels[(q, -1)]
    R.check("C10", "chirality: the conventions ε = ±1 disagree on the absolute label (L against R) and agree on the drive-aligned "
            "branch, which sums to N over the period while the counter-aligned branch, exponent 2εδ, sums to 0 for either sign "
            "(q = 3, 5, 7, 13)", ok)


# ------------------------------------------------------------------------------------------------------------
# block D: the electroweak scale against the transmutation forms (27:Y1, Z1)
# v_scale.py shows that v is not the SU(2) gauge transmutation scale. The b = 2.00 that lands on M_W is a fit, b₂ = 19/6
# lands at 10⁸–10⁹ GeV, and the SU(2) infrared scale is far below. The QCD control is consistent. The closed forms
# m_P e^{−(2π)²} = 87.4 GeV and 2^{3/2} m_P e^{−(2π)²} = 247.2 GeV are readings, the second the conjecture Y1. Both
# checks are continuum readings on the measured scales: CHART.
@R.block("D", BLOCK["D"])
def block_D():
    """Block D — the electroweak scale: D1–D2 CHART."""
    r = CF.v_scale(); d = CF.DATA["v_scale"]
    ok = _within(r["b_fit_MW"], 2, Q(1, 100)) and 10 ** 8 < Q(r["L_b2"]) < 10 ** 9 and Q(r["mu_IR"]) < Q(1, 10 ** 20)
    ok &= _within(Q(r["as_MP_needed"]) / Q(r["as_MP_run"]), 1, Q(1, 10)) and _within(Q(r["vc"]) / d["M_W"], 1, Q(1, 10))
    # 27:Z1 (p27047)
    R.check("D1", "[chart] v against the transmutation forms: the b landing on M_W is a fit (|b − 2| < 0.01); b₂ = 19/6 gives "
            "10⁸–10⁹ GeV; the SU(2) infrared scale is below 10⁻²⁰ GeV; the QCD control agrees within 10 %; m_P e^{−(2π)²} within "
            "10 % of M_W: the absolute scales lie beyond the coherence horizon",
            ok, f"b = {r['b_fit_MW']:.3f}, Λ(b₂) = {r['L_b2']:.2e} GeV, μ_IR = {r['mu_IR']:.1e} GeV, "
                f"α_s(M_P) {r['as_MP_needed']:.4f} vs {r['as_MP_run']:.4f}", kind="CHART")
    ok = _within(Q(r["v1"]) / d["v_ref"], 1, Q(5, 1000)) and _within(r["vc"], Q(874, 10), Q(2, 10))
    # 27:Y1 (p27048)
    R.check("D2", "[chart] the Y1 numeral 2^{3/2} m_P e^{−(2π)²} = 247.2 GeV against v = 246.2 GeV within 0.5 %; "
            "m_P e^{−(2π)²} = 87.4 GeV",
            ok, f"{r['v1']:.1f} GeV against {CH.show(d['v_ref'], '.1f')} GeV ({CH.show(100 * (Q(r['v1']) / d['v_ref'] - 1), '+.2f')} %), "
                f"m_P e^(-(2π)²) = {r['vc']:.2f} GeV", kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block E: the strong sector (27:C7, C8, X1, X7, Z1)
# qcd.py builds SU(3, 2) over F_4, of order 216 with centre Z_3 (E1), and the strong-coupling string tensions of U(1)
# and Z_N on the chart (E2). p5.py gauges the colour frame over F_4. string_tension.py gives c₁ as an exact character sum,
# in closed form on 2T and as the series β/18 + β²/216 for SU(3) (E4, E5), with its resolved-window fit on the chart
# (E5c). p6.py has b₀ = 11 − (2/3)n_f (E6) and Λ_QCD by transmutation on the chart (E7). missing_rank.py has the rank
# tower and SU(3, 5): the gauging of the colour frame (E8, 27:X1).
@R.block("E", BLOCK["E"])
def block_E():
    """Block E — the strong sector: E1, E3–E6, E8 EXACT; E2, E5c, E7 CHART."""
    F4 = I.Fq2(2, 1, 1)                                                          # F_4 = F_2[w], w² = w + 1
    code = lambda x: x[0] + 2 * x[1]                                             # 0, 1, w, w² as the package's 0, 1, 2, 3
    su3 = sorted(I.unitary_frames(F4, 3), key=lambda M: tuple(code(e) for row in M for e in row))
    cube = [x for x in F4.elements() if x != F4.zero and F4.mul(x, F4.conj(x)) == F4.one and F4.pow(x, 3) == F4.one]
    scal = lambda x: tuple(tuple(x if i == j else F4.zero for j in range(3)) for i in range(3))
    mm0 = lambda X, Y: I.mat_mul(F4, X, Y)
    centre = [g for g in su3 if all(mm0(g, h) == mm0(h, g) for h in su3)]         # the centre, by the 216² products
    # E1 SU(3, 2) by its orthonormal frames over F_4: order 216 = q³(q² − 1)(q³ + 1), the centre the scalar cube roots of unity
    R.check("E1", "|SU(3, 2)| = 216 = q³(q² − 1)(q³ + 1) by exhaustive enumeration over F_4; the centre, by all 216² products, "
            "is the three scalar cube roots of unity (Z_3, colour triality)",
            len(su3) == 216 == 2 ** 3 * (2 ** 2 - 1) * (2 ** 3 + 1) and len(cube) == 3 and sorted(centre) == sorted(scal(x) for x in cube),
            f"|SU(3,2)| = {len(su3)}, centre Z_{len(centre)}")

    # E2 [chart] the strong-coupling string tension σ = −ln c₁(β): U(1) (σ(0.5) = 1.4168, positive, decreasing), Z₃ positive
    s = {b: Q(CF.sigma_U1(b)) for b in (Q(2, 10), Q(5, 10), Q(1), Q(2), Q(4))}
    bs = sorted(s)
    ok = abs(s[Q(1, 2)] - Q(14168, 10000)) < Q(1, 1000) and all(s[a] > s[b] > 0 for a, b in zip(bs, bs[1:]))
    ok &= all(Q(CF.sigma_ZN(b, 3)) > 0 for b in bs)
    R.check("E2", "[chart] the U(1) string tension σ(0.5) = 1.4168, positive and decreasing in β (0.2 … 4.0); σ_Z₃(β) > 0", ok,
            f"σ_U(1)(0.5) = {CH.show(s[Q(1, 2)], '.4f')}", kind="CHART")

    # E3 the gluon connection over F_4: the plaquette conjugates, Tr P invariant exhaustively, the commutator plaquette of
    #    two non-commuting links ≠ I against = I for the diagonal U(1) control, the triplet covariant
    mm = lambda X, Y: I.mat_mul(F4, X, Y); inv = lambda X: I.dagger(F4, X); tr = lambda X: I.trace(F4, X)
    one = tuple(tuple(F4.one if i == j else F4.zero for j in range(3)) for i in range(3))
    Uab, Ubc, Ucd, Uda = su3[7], su3[40], su3[123], su3[200]; ga, gb, gc, gd = su3[3], su3[55], su3[150], su3[210]
    P = mm(mm(Uab, Ubc), mm(Ucd, Uda))
    U2 = [mm(mm(ga, Uab), inv(gb)), mm(mm(gb, Ubc), inv(gc)), mm(mm(gc, Ucd), inv(gd)), mm(mm(gd, Uda), inv(ga))]
    P2 = mm(mm(U2[0], U2[1]), mm(U2[2], U2[3]))
    ok = P2 == mm(mm(ga, P), inv(ga)) and tr(P2) == tr(P) and all(tr(mm(mm(g, P), inv(g))) == tr(P) for g in su3)
    X, Y = next((X, Y) for X in su3 for Y in su3 if mm(X, Y) != mm(Y, X))
    Fc = mm(mm(X, Y), mm(inv(X), inv(Y)))
    w = (0, 1); w2 = F4.mul(w, w)
    dg = lambda a, b, c: ((a, F4.zero, F4.zero), (F4.zero, b, F4.zero), (F4.zero, F4.zero, c))
    D1, D2 = dg(F4.one, w, w2), dg(w, F4.one, w2)
    Fab = mm(mm(D1, D2), mm(inv(D1), inv(D2)))
    el = {0: (0, 0), 1: (1, 0), 2: (0, 1), 3: (1, 1)}
    psi_a, psi_b = tuple(el[c] for c in (1, 2, 0)), tuple(el[c] for c in (0, 1, 3))
    vsub = lambda u, v: tuple(F4.sub(x, y) for x, y in zip(u, v))
    Dq = vsub(psi_a, I.matvec(F4, Uab, psi_b)); Dq2 = vsub(I.matvec(F4, ga, psi_a), I.matvec(F4, U2[0], I.matvec(F4, gb, psi_b)))
    ok &= Fc != one and Fab == one and Dq2 == I.matvec(F4, ga, Dq) and len(su3) == 216
    R.check("E3", "the SU(3, F_4) gluon connection: the plaquette conjugates and Tr P is invariant over all of SU(3, 2); the "
            "commutator plaquette U₁U₂U₁⁻¹U₂⁻¹ ≠ I (gluon self-coupling), = I for the abelian control; the triplet covariant", ok,
            f"Tr P = {tr(P)}")

    # E4 the string tension, exact. S₃ and 2T satisfy character orthogonality, with the trace multiset of 2T
    #    {2:1, −2:1, 0:6, 1:8, −1:8}. The moments of 2T give c₁^{2T}(β) = β/4 + …, equal to the continuum SU(2) series
    #    I₂/I₁ through β⁴. σ > 0 for every β > 0 by the closed form of B4. |SU(3, 2)| = 216 and its centre is Z_3.
    chars = {"triv": (1, 1, 1), "sgn": (1, -1, 1), "std": (2, 0, -1)}; sizes = (1, 3, 2)
    ok = all(sum(s_ * c for s_, c in zip(sizes, chars[r])) == 0 for r in ("sgn", "std"))
    ok &= all(Q(sum(s_ * c * c for s_, c in zip(sizes, chars[r])), 6) == 1 for r in chars)
    G, closed, unit, traces = I.tetrahedral_quaternions()
    ok &= len(G) == 24 and closed and unit
    ok &= traces == {2: 1, -2: 1, 0: 6, 1: 8, -1: 8} and sum(t * m for t, m in traces.items()) == 0
    mom = [Q(sum(m * t ** k for t, m in traces.items()), 24) for k in range(8)]
    c2T = I.moment_c1_series(mom, 2, 7); cSU2 = I.bessel_ratio_series(1, 7)
    ok &= c2T[0] == 0 and c2T[1] == Q(1, 4) and c2T[:5] == cSU2[:5] and c2T[5] != cSU2[5]      # the difference starts at β⁵
    ok &= I.area_law_rational()[2]                                                # 0 < c₁ < 1 for every x > 1 (B4)
    ok &= len(su3) == 216 and len(centre) == 3 and (2 + 1) % 3 == 0
    # 27:X7 (p27030)
    R.check("E4", "the string tension in finite units: S₃ and 2T character orthogonality; |2T| = 24 in SU(2, C) with traces "
            "{2:1, −2:1, 0:6, 1:8, −1:8}; c₁^{2T} = β/4 + … agrees with continuum SU(2) through β⁴; σ > 0 for every β > 0 by "
            "the closed form of B4; |SU(3, 2)| = 216, centre Z_3", ok,
            f"c₁^2T series {[str(c) for c in c2T[:6]]}; I₂/I₁ {[str(c) for c in cSU2[:6]]}")

    # E5 colour SU(3): c₁ = β/18 + β²/216 + … exactly, from the Haar moments of the fundamental character (the Weyl
    #    constant term)
    mom = []
    for k in range(5):
        mom.append(sum(comb(k, j) * I.su3_moment(j, k - j) for j in range(k + 1)) * Q(1, 2 ** k))
    c3 = I.moment_c1_series(mom, 3, 4)
    R.check("E5", "colour SU(3): c₁ = β/18 + β²/216 + … exactly, from the Haar moments of the fundamental character (the "
            "Weyl constant term)", c3[:3] == [0, Q(1, 18), Q(1, 216)], f"series {[str(c) for c in c3]}")

    # E5c [chart] the package's fit on the resolved window agrees with the series within 10⁻⁴, σ^{SU(3)} > 0 at β = 0.2 … 8,
    #     and the U(1) normalisation σ(0.5) = 1.4168
    a, b, _ = CF.su3_fit()
    ok = abs(Q(a) - Q(1, 18)) < Q(1, 10 ** 4) and abs(Q(b) - Q(1, 216)) < Q(1, 10 ** 4)
    ok &= all(0 < Q(CF.c1_su3(be)) < 1 for be in (Q(2, 10), Q(5, 10), Q(1), Q(2), Q(4), Q(8)))
    ok &= abs(Q(CF.sigma_U1(Q(1, 2))) - Q(14168, 10000)) < Q(1, 1000)
    R.check("E5c", "[chart] the resolved-window fit of c₁^{SU(3)} agrees with β/18 + β²/216 within 10⁻⁴; σ^{SU(3)}(β) > 0 at "
            "β = 0.2 … 8; the U(1) normalisation σ(0.5) = 1.4168", ok, f"fit {a:.6f} β + {b:.6f} β²", kind="CHART")

    # E6 asymptotic freedom: b₀ = 11 − (2/3)n_f exactly, positive up to n_f = 16, while the abelian b₀ is negative
    b0 = lambda nf: 11 - Q(2, 3) * nf; bU = lambda nf: -Q(4, 3) * nf
    ok = b0(2) == Q(29, 3) and b0(6) == 7 and b0(16) > 0 and b0(17) < 0 and all(bU(n_) < 0 for n_ in (2, 6, 16))
    R.check("E6", "b₀ = 11 − (2/3)n_f as exact rationals: 29/3 at n_f = 2, 7 at n_f = 6, positive up to 16, negative at 17; the "
            "abelian b₀ < 0", ok)

    # E7 [chart] Λ_QCD by one-loop transmutation from the M_Z anchor (n_f = 5) lies in the 50–500 MeV decade, and
    #    (m_p/m_P)² = e^{−88}
    lam = Q(CF.lambda_qcd(b0(5))); ex = Q(CF.proton_planck_exponent())
    ok = Q(5, 100) < lam < Q(5, 10) and abs(ex - 88) < Q(1, 10)
    R.check("E7", "[chart] Λ_QCD = M_Z exp(−2π/(b₀α_s)) at n_f = 5 lies in 50–500 MeV; (m_p/m_P)² = e^{−88.0}", ok,
            f"Λ = {CH.show(lam * 1000, '.0f')} MeV, 2 ln(m_P/m_p) = {CH.show(ex, '.2f')}", kind="CHART")

    # E8 the rank tower and SU(3, 5) over F_25 = F_5[t]/(t² − 2): the colour frame forced as the minimal triality-carrying
    #    rank, its gauging the SU(3) connection (27:X1)
    adm = [q for q in range(5, 200) if q % 12 == 5 and all(q % d_ for d_ in range(2, q) if d_ * d_ <= q)]
    A_ok = all([gcd(n_, Om + 1) for n_ in (1, 2, 3)] == [1, 2, 3] for Om in adm[:8])
    r3 = min(n_ for n_ in range(1, 13) if gcd(n_, 6) % 3 == 0); r2 = min(n_ for n_ in range(1, 13) if gcd(n_, 6) % 2 == 0)
    K = I.Fq2(5, 0, 2)
    N1, N2, N3 = (I.unit_vectors(K, m) for m in (1, 2, 3))
    SU3 = N3 * N2 * N1 // (5 + 1)
    cube = [x for x in K.elements() if K.pow(x, 3) == K.one and K.norm(x) == 1]
    def frame(reverse):
        vs = list(product(K.elements(), repeat=3)); vs = vs[::-1] if reverse else vs
        cols = []
        for vec in vs:
            if I.herm(K, vec, vec) != K.one: continue
            if all(I.herm(K, c, vec) == K.zero for c in cols):
                cols.append(vec)
                if len(cols) == 3: break
        M = [[cols[j][i] for j in range(3)] for i in range(3)]
        dinv = K.inv(I.det(K, M))
        return tuple(tuple(K.mul(M[r_][c_], dinv) if c_ == 2 else M[r_][c_] for c_ in range(3)) for r_ in range(3))
    U1, U2 = frame(False), frame(True)
    one = tuple(tuple(K.one if i == j else K.zero for j in range(3)) for i in range(3))
    mm = lambda X, Y: I.mat_mul(K, X, Y); dg_ = lambda X: I.dagger(K, X)
    unit = mm(dg_(U1), U1) == one and mm(dg_(U2), U2) == one
    dets = I.det(K, U1) == K.one and I.det(K, U2) == K.one
    Up = mm(mm(U1, U2), mm(dg_(U1), dg_(U2)))
    gi = I.trace(K, mm(mm(U2, Up), dg_(U2))) == I.trace(K, Up)
    ok = A_ok and r3 == 3 and r2 == 2 and SU3 == 378000 and len(cube) == 3 and unit and dets and gi and Up != one
    ok &= comb(5, 0) + comb(5, 2) + comb(5, 4) == 16
    # 27:C7 (p27019)
    R.check("E8", "the rank tower: centre orders [1, 2, 3] for n = 1, 2, 3 over the first eight shell primes Ω ≡ 5 (mod 12); "
            "minimal ranks 3 (colour) and 2 (isospin), the gauging of the colour frame; |SU(3, 5)| = 378 000; three norm-one "
            "cube roots of unity; two SU(3, 5) matrices unitary, det 1, Wilson-invariant, non-commuting; dim Λ^even(C⁵) = 16", ok,
            f"(N1, N2, N3) = {(N1, N2, N3)}, |SU(3,5)| = {SU3}, admissible {adm[:8]}")


# ------------------------------------------------------------------------------------------------------------
# block F: matter (27:C6, C8–C11, X8, X9, P1, P2, P4, P6, P7)
# generation.py reads one generation as the spinor of C³ ⊕ C² (F1: the matter content, which the exclusion rows P2, P6,
# P7 rest on). p8.py and p8b.py give the spinorial unification argument, the X, Y as the colour–isospin off-block and
# the proton lifetime (F3, a dimensional estimate on the chart). p9.py counts Frobenius orbits. p9b.py splits the roles
# 1 + 3 (F6, with the ladder's closure from the horizon theme: no further sector, the deciding check of P2, P6, P7) and
# orders the masses (F6c, on the measured masses). p11.py derives Ω ≡ 5 (mod 12).
@R.block("F", BLOCK["F"])
def block_F():
    """Block F — matter: F1, F2, F4–F7 EXACT; F3, F6c CHART."""
    # F1 the 16 = 1 ⊕ 5̄ ⊕ 10: sixteen Weyl fermions with ΣY = ΣY³ = 0 and Tr T₃²/Tr Q² = 3/8. The 6Y multiset equals
    #    that of the theme's even subsets read 3 + 2 (gen16, y6).
    h = Q(1, 2)
    GEN = [("Q", 3, [h, -h], Q(1, 6)), ("u^c", 3, [Q(0)], Q(-2, 3)), ("d^c", 3, [Q(0)], Q(1, 3)),
           ("L", 1, [h, -h], Q(-1, 2)), ("e^c", 1, [Q(0)], Q(1)), ("nu^c", 1, [Q(0)], Q(0))]
    nW = sum(c * len(t) for _, c, t, _ in GEN)
    sY = sum(c * len(t) * y for _, c, t, y in GEN); sY3 = sum(c * len(t) * y ** 3 for _, c, t, y in GEN)
    T3 = sum(c * sum(x * x for x in t) for _, c, t, _ in GEN); Q2 = sum(c * sum((x + y) ** 2 for x in t) for _, c, t, y in GEN)
    charges = {x + y for _, c, t, y in GEN for x in t}
    wsum = all(any(y == a * Q(-1, 3) + b * h for a in range(-3, 4) for b in range(-2, 3)) for _, _, _, y in GEN)
    six = Counter(6 * y for _, c, t, y in GEN for _ in range(c * len(t)))
    ok = nW == 16 and sY == 0 and sY3 == 0 and charges == {Q(2, 3), Q(-1, 3), Q(-2, 3), Q(1, 3), Q(0), Q(-1), Q(1)}
    ok &= T3 / Q2 == Q(3, 8) and wsum and six == Counter(I.y6(S) for S in I.gen16())
    # 27:C8 (p27020), 27:X8 (p27031)
    R.check("F1", "one generation as the spinor of C³ ⊕ C²: sixteen Weyl fermions, hypercharges weight sums of (−1/3, +1/2), "
            "charges {±2/3, ±1/3, 0, ±1}, ΣY = ΣY³ = 0, Tr T₃²/Tr Q² = 3/8: the matter content that the exclusion predictions "
            "rest on", ok, f"Tr T₃² = {T3}, Tr Q² = {Q2}")

    # F2 the spinorial argument: 1 + 5 + 10 = 16
    R.check("F2", "the generation pieces of the irreducible SO(10) spinor: 1 + 5 + 10 = 16", 1 + 5 + 10 == 16)

    # F3 [chart] the proton lifetime τ_p ~ M_X⁴/(α_GUT² m_p⁵) in years, a dimensional estimate on the declared numerals. It
    #    is 10⁴⁸ yr at the Planck scale, above row P4's bound 10⁴⁵, and 4.6 × 10³⁵ yr at 10¹⁶ GeV, above the Super-K bound 10³⁴.
    d = CF.DATA["p8"]
    tau = {M: M ** 4 / (d["alpha_GUT"] ** 2 * d["m_p"] ** 5) * d["hbar_GeV_s"] / d["year_s"] for M in d["M_X"]}
    Ms = sorted(tau)
    ok = all(tau[b] / tau[a] == (b / a) ** 4 for a, b in zip(Ms, Ms[1:])) and tau[Ms[-1]] >= 10 ** 45 and tau[Ms[0]] > 10 ** 34
    # 27:P4 (p27038)
    R.check("F3", "[chart] τ_p ∝ M_X⁴; τ_p at the Planck scale ≥ 10⁴⁵ yr (row P4's bound); τ_p at M_X = 10¹⁶ GeV above the "
            "Super-K bound 10³⁴ yr", ok, ", ".join(f"{CH.show(M, '.1e')} GeV: {CH.show(tau[M], '.1e')} yr" for M in Ms), kind="CHART")

    # F4 the X, Y as the colour–isospin off-block: dim SU(5) − dim(SU(3) × SU(2) × U(1)) = 24 − 12 = 12 = 2·(3·2)
    su5, sm, off, so10 = 5 ** 2 - 1, (3 ** 2 - 1) + (2 ** 2 - 1) + 1, 2 * (3 * 2), 10 * 9 // 2
    # 27:C9 (p27021)
    R.check("F4", "the X, Y leptoquarks are the colour–isospin off-block: 24 − 12 = 12 = the 3 × 2 complex off-block; "
            "dim SO(10) = 45; 1 + 5 + 10 = 16", su5 == 24 and sm == 12 and su5 - sm == off == 12 and so10 == 45 and 1 + 5 + 10 == 16)

    # F5 generations as Galois conjugates: the orbits of x -> x^q on F_{q^n}^× (multiplication by q on Z/(q^n − 1))
    def orbits(q, n):
        N = q ** n - 1; seen = set(); out = []
        for a in range(N):
            if a in seen: continue
            orb = []; b = a
            while b not in seen: seen.add(b); orb.append(b); b = b * q % N
            out.append(orb)
        return out
    ok = True
    for q in (2, 3, 5):
        fo = {n: orbits(q, n) for n in (2, 3, 6)}
        ok &= {n: max(len(o) for o in fo[n]) for n in fo} == {2: 2, 3: 3, 6: 6}
        ok &= all(all(n % len(o) == 0 for o in fo[n]) for n in fo)
    R.check("F5", "Frobenius orbits on F_{q^n}^× for q = 2, 3, 5: full orbits of size 2, 3, 6 for n = 2, 3, 6, every orbit size "
            "dividing the degree; the degrees 2 and 3 coprime", ok and gcd(2, 3) == 1)

    # F6 the closed role ladder and its 1 + 3 split. The fifth step returns to counting: on the shells F_13, F_53, F_157,
    #    F_421 the tower g^(g^j) is read with its exponent modulo p − 1, an index on the cycle, for every j (the horizon
    #    theme's tower, as 26-pnp's closure). One role is non-generative (counting, the bosonic Carrier), three are
    #    generative (the generations): no fifth interaction, no fourth generation, no further sector.
    ok = True; det = []
    for p in (13, 53, 157, 421):
        g, n = arith.primitive_root(p), p - 1
        closes = all(LD.tower(g, j, p)[0] == LD.tower(g, j, p)[1] for j in range(n))    # g^(g^j) = g^((g^j) mod n)
        acts = any(pow(g, j, p) >= n for j in range(n))                                   # the reduction is not vacuous
        ok &= closes and acts
        det.append(f"F_{p}: g = {g}, the tower exponent read modulo {n} for all {n} indices")
    # 27:C10 (p27022), 27:X9 (p27032), 27:P1 (p27035), 27:P2 (p27036), 27:P6 (p27040), 27:P7 (p27041)
    R.check("F6", "the closed role ladder: the fifth step returns to counting (on F_13, F_53, F_157, F_421 the tower g^(g^j) is "
            "read with its exponent modulo p − 1, an index on the cycle, for every j, and the reduction is not vacuous): iterated "
            "exponentiation opens no fifth role; the count 4 = 1 + 3 (one non-generative role, the bosonic Carrier, three "
            "generative, the generations) is the realisation B6's reading of the closed ladder, not decided here", ok, "; ".join(det))

    # F6c [chart] the generations ordered by the ladder: the geometric-mean masses of the three generations from the
    #     measured quark and lepton masses, gen1 < gen2 < gen3, each step above ×40 (compared cubed, in rationals)
    d = CF.DATA["p9b"]
    pr = [d[g][0] * d[g][1] * d[g][2] for g in ("gen1", "gen2", "gen3")]
    ok = pr[0] < pr[1] < pr[2] and pr[1] / pr[0] > 40 ** 3 and pr[2] / pr[1] > 40 ** 3
    R.check("F6c", "[chart] the generations ordered as the ladder orders the roles: the geometric-mean masses from the measured "
            "quark and lepton masses satisfy gen1 < gen2 < gen3, each step above ×40", ok,
            "step ratios³ " + ", ".join(CH.show(pr[i + 1] / pr[i], ".3g") for i in range(2)), kind="CHART")

    # F7 Ω ≡ 5 (mod 12) as the CRT conjunction, and the primes below 200 000 by residue mod 12 (1/4 each within 0.01)
    lim = 200000; sieve = bytearray([1]) * lim; sieve[0] = sieve[1] = 0
    for i in range(2, isqrt(lim) + 1):
        if sieve[i]: sieve[i * i::i] = bytearray(len(range(i * i, lim, i)))
    cnt = Counter(p % 12 for p in range(5, lim) if sieve[p]); tot = sum(cnt[r] for r in (1, 5, 7, 11))
    shells = (13, 53, 61, 157, 421)
    ok = {r for r in range(12) if r % 4 == 1 and r % 3 == 2} == {5}
    ok &= all(abs(Q(cnt[r], tot) - Q(1, 4)) < Q(1, 100) for r in (1, 5, 7, 11))
    ok &= all(p % 4 == 1 for p in shells) and [p for p in shells if p % 12 == 5] == [53]
    # 27:C11 (p27023)
    R.check("F7", "5 is the unique residue mod 12 with r ≡ 1 (mod 4) and r ≡ 2 (mod 3), the residue clause Ω ≡ 5 (mod 12) as a "
            "CRT conjunction; the primes below 200 000 split 1/4 each by residue mod 12 within 0.01; the shells 13, 53, 61, 157, "
            "421 are ≡ 1 (mod 4), 53 alone ≡ 5 (mod 12)", ok,
            ", ".join(f"{r}: {CH.show(Q(cnt[r], tot), '.3f')}" for r in (1, 5, 7, 11)))

    # F8 the torsion period against the horizon count (17 October 2026): on every admissible shell Ω ≡ 5 (mod 12) the
    #    non-split torus has order Ω + 1 ≡ 0 (mod 3), so the Z_3-against-Z_2 torsion is read after (Ω + 1)/3 coherent steps;
    #    that count exceeds every horizon count s with s² ≤ Ω, since 3 s < Ω + 1 — on the shells 17, 53, 173, 389, 1373, the
    #    laboratory Carrier 2 408 561 and every Ω from 7 to 10⁵. The cap of coherent reading at the horizon is the master's
    #    (00:Z2–Z4); this check is the relation alone.
    tors = SHELLS_5MOD12 + (2408561,)
    ok = all(w % 12 == 5 and (w + 1) % 3 == 0 and 3 * isqrt(w) < w + 1 and (w + 1) // 3 > isqrt(w) for w in tors)
    ok &= all(3 * isqrt(w) < w + 1 for w in range(7, 10 ** 5)) and not all(3 * isqrt(w) < w + 1 for w in range(1, 7))
    R.check("F8", "the torsion period exceeds the horizon count: (Ω + 1)/3 > ⌊√Ω⌋ and 3⌊√Ω⌋ < Ω + 1 on the shells 17, 53, 173, "
            "389, 1373 and 2 408 561, and on every Ω from 7 to 10⁵ (false below 7)", ok,
            ", ".join(f"Ω={w}: (Ω+1)/3 = {(w + 1) // 3}, ⌊√Ω⌋ = {isqrt(w)}" for w in tors[:3]))


# ------------------------------------------------------------------------------------------------------------
# block G: the running couplings and the mass mechanism (27:C6, P3, P5, Z1)
# p1.py runs the measured M_Z couplings at one loop with b = (41/10, −19/6, −7) (G2, on the chart), and sin²θ_W = 3/8
# where α₁ = α₂ (G1, exact). p7.py reads the seesaw scale, b–τ unification and the winding-overlap hierarchy (G3, G4, on
# the chart).
@R.block("G", BLOCK["G"])
def block_G():
    """Block G — the running couplings and the mass mechanism: G1 EXACT; G2–G4 CHART."""
    # G1 at α₁ = α₂ (GUT-normalised hypercharge, α_Y = (3/5)α₁): sin²θ_W = α_Y/(α₂ + α_Y) = (3/5)/(1 + 3/5) = 3/8
    s = Q(3, 5) / (1 + Q(3, 5))
    R.check("G1", "sin²θ_W = (3/5)/(1 + 3/5) = 3/8 exactly where α₁ = α₂", s == Q(3, 8), str(s))

    # G2 [chart] the running in rationals on the measured couplings, since π cancels from the couplings at the meeting.
    #    The α₃ near-miss is below 20 %; the chart reads the meeting scale in [10¹², 10¹⁴] GeV. The clause "3/8 runs back
    #    to the measured value" of 16 October was an identity (one-loop running is linear, so running up and back returns
    #    the input exactly) and is gone (17 October 2026).
    d = CF.DATA["p1"]; b1, b2, b3 = d["b"]
    a1, a2, a3 = Q(3, 5) * (1 - d["sin2"]) * d["ainv_em"], d["sin2"] * d["ainv_em"], 1 / d["alpha_s"]
    u = (a1 - a2) / (b1 - b2)                                                     # t₁₂/2π
    aG, a3X = a2 - b2 * u, a3 - b3 * u
    miss = abs(a3X - aG) / aG
    MX = Q(CF.unification_scale())
    ok = miss < Q(1, 5) and 10 ** 12 < MX < 10 ** 14
    # 27:P3 (p27037)
    R.check("G2", "[chart] one-loop running of the measured M_Z couplings with b = (41/10, −19/6, −7): α₁ = α₂ at M_X in "
            "[10¹², 10¹⁴] GeV, where sin²θ_W = 3/8 by the normalisation (G1); the α₃ near-miss below 20 %", ok,
            f"M_X = {CH.show(MX, '.2e')} GeV, α_GUT⁻¹ = {CH.show(aG, '.1f')}, α₃⁻¹ = {CH.show(a3X, '.1f')}, "
            f"near-miss {CH.show(100 * miss, '.0f')} %", kind="CHART")

    # G3 [chart] the seesaw m_ν = y²v²/M_R reaches 0.01–0.1 eV for M_R = 10¹⁴–10¹⁵ GeV, and m_b/m_τ lies in the band 2–3
    d = CF.DATA["p7"]
    band = [y ** 2 * d["v"] ** 2 / MR * 10 ** 9 for MR in d["M_R"][1:3] for y in d["y"]]
    ok = any(Q(1, 100) < m < Q(1, 10) for m in band) and 2 < d["m_b"] / d["m_tau"] < 3
    # 27:P5 (p27039)
    R.check("G3", "[chart] the seesaw y²v²/M_R reaches 0.01–0.1 eV for M_R = 10¹⁴–10¹⁵ GeV; m_b/m_τ = 2.35 in the b–τ band 2–3",
            ok, "m_ν (eV) = " + ", ".join(CH.show(m, ".3f") for m in band) + f"; m_b/m_τ = {CH.show(d['m_b'] / d['m_tau'], '.2f')}",
            kind="CHART")

    # G4 [chart] the winding overlap |Σ_{t<T} ζ_N^{kt}|/T (N = 60, T = 12): 1 at k = 0 and decreasing in k = 0 … 5
    ov = [Q(x) for x in CF.winding_overlaps(d["N"], d["T"])]
    ok = abs(ov[0] - 1) < Q(1, 10 ** 12) and all(ov[k] > ov[k + 1] for k in range(5))
    R.check("G4", "[chart] the winding overlap |Σζ^{kτ}|/T is 1 at k = 0 and decreases in the winding distance k = 0 … 5", ok,
            ", ".join(CH.show(x, ".3f") for x in ov), kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block H: flavour (27:X10, X11, P8, P9)
# koide.py proves the framed-rational Koide identity over F_p, p ≡ 5 (mod 12), with the cube root of unity in
# F_{p²} = F_p(√−3) (H1), and reads the measured charged leptons on the chart (H2). strongcp.py shows that Hermitian mass
# matrices over F_{p²}/F_p have their determinant in F_p, so arg det M_q = 0, while [M_u, M_d] ≠ 0 (H3).
SHELLS_5MOD12 = (17, 53, 173, 389, 1373)


@R.block("H", BLOCK["H"])
def block_H():
    """Block H — flavour: H1, H3 EXACT; H2 CHART."""
    # H1 over each shell −3 is a non-residue and ω = (−1 + θ)/2 has order 3. The eigenvalues λ_k = a + bω^k + b^pω^{−k}
    #    lie in F_p, with Σλ = 3a, Σλ² = 3a² + 6N(b) and Q = 1/3 + (2/3)ρ². So ρ² = N(b)/a² = 1/2 gives Q = 2/3.
    ok = True
    for p in SHELLS_5MOD12:
        K = I.Fq2(p, 0, -3); i2, i3 = pow(2, p - 2, p), pow(3, p - 2, p)
        ok &= p % 12 == 5 and pow(p - 3, (p - 1) // 2, p) == p - 1
        om = ((-i2) % p, i2); ok &= K.pow(om, 3) == K.one and om != K.one
        oms = [K.one, om, K.mul(om, om)]
        for a in (1, 2, 7):
            for b in ((1, 1), (2, 1), (3, 2)):
                lam = []
                for k in range(3):
                    e = K.add(K.add(K.scalar(a), K.mul(b, oms[k])), K.mul(K.conj(b), oms[(-k) % 3]))
                    ok &= e[1] == 0; lam.append(e[0])
                S1, S2, nb = sum(lam) % p, sum(x * x for x in lam) % p, K.norm(b)
                ok &= S1 == 3 * a % p and S2 == (3 * a * a + 6 * nb) % p
                Qk = S2 * pow(S1 * S1 % p, p - 2, p) % p; rho2 = nb * pow(a * a % p, p - 2, p) % p
                ok &= Qk == (i3 + 2 * i3 * rho2) % p
        ok &= (i3 + 2 * i3 * i2) % p == 2 * i3 % p
    # 27:X10 (p27033)
    R.check("H1", "the framed-rational Koide identity over F_p, p = 17, 53, 173, 389, 1373 (p ≡ 5 mod 12): Σλ = 3a, "
            "Σλ² = 3a² + 6N(b), Q = 1/3 + (2/3)ρ², and ρ² = 1/2 gives Q = 2/3 exactly", ok)

    # H2 [chart] the measured charged-lepton Q against 2/3 (10⁻⁴) and ρ² against 1/2 (10⁻³)
    Qm, r2 = CF.koide_measured()
    # 27:P8 (p27042)
    R.check("H2", "[chart] the measured charged-lepton Q = Σm/(Σ√m)² is 2/3 within 10⁻⁴ and ρ² is 1/2 within 10⁻³",
            _within(Qm, Q(2, 3), Q(1, 10 ** 4)) and _within(r2, Q(1, 2), Q(1, 1000)), f"Q = {Qm:.6f}, ρ² = {r2:.5f}", kind="CHART")

    # H3 Hermitian circulant and textured up/down mass matrices over F_{p²}/F_p: det ∈ F_p, det(M_u M_d) ∈ F_p, [M_u, M_d] ≠ 0
    ok = True; n_ = 0
    for p in SHELLS_5MOD12:
        K = I.Fq2(p, 0, -3)
        def herm_m(diag, up):
            return ((K.scalar(diag[0]), up[0], up[1]), (K.conj(up[0]), K.scalar(diag[1]), up[2]),
                    (K.conj(up[1]), K.conj(up[2]), K.scalar(diag[2])))
        b = (2, 1)
        Hc = herm_m((7, 7, 7), (b, K.conj(b), b))                                # det = (7 − 5)(7 + 1)(7 + 4) = 176 ≠ 0
        Hu = herm_m((3, 7, 11), ((1, 1), (2, 3), (4, 1))); Hd = herm_m((2, 5, 13), ((3, 2), (1, 4), (5, 2)))
        dc, du, dd = I.det(K, Hc), I.det(K, Hu), I.det(K, Hd)
        checks = [dc[1] == 0 and dc != K.zero, du[1] == 0 and du != K.zero, dd[1] == 0 and dd != K.zero, K.mul(du, dd)[1] == 0,
                  I.mat_mul(K, Hu, Hd) != I.mat_mul(K, Hd, Hu)]
        ok &= all(checks); n_ += len(checks)
    # 27:X11 (p27034), 27:P9 (p27043)
    R.check("H3", "the strong-CP angle over F_{p²}/F_p, p = 17, 53, 173, 389, 1373: Hermitian circulant and textured mass "
            "matrices have det ∈ F_p, nonzero (arg det M_q = 0), det(M_u M_d) ∈ F_p, and [M_u, M_d] ≠ 0", ok, f"{n_} exact checks")

    # H4 the Wilson term under orientation reversal (17 October 2026): on the 24 elements of 2T over the Gaussian rationals
    #    and on all 216 elements of SU(3, 2) over F_4, U⁻¹ = U† and Tr U⁻¹ = conj Tr U, so the plaquette term Tr U + conj Tr U
    #    is unchanged by U ↦ U⁻¹: the Wilson class carries no orientation-odd term. 2T first: the inverse of a unit quaternion
    #    is its conjugate, the matrix trace 2a is real, so Tr U⁻¹ = Tr U = conj Tr U.
    G, _, _, _ = I.tetrahedral_quaternions()
    ok = all(I.qmul(g, I.qconj(g)) == (1, 0, 0, 0) for g in G)
    for g in G:
        M, Mi = I.su2_matrix(g), I.su2_matrix(I.qconj(g))
        trM = tuple(a + b for a, b in zip(M[0][0], M[1][1])); trMi = tuple(a + b for a, b in zip(Mi[0][0], Mi[1][1]))
        ok &= trMi == I.gauss_conj(trM) and trM[1] == 0 and I.gauss_mul(trMi, (1, 0)) == trM
    F4 = I.Fq2(2, 1, 1); su3 = I.unitary_frames(F4, 3)
    one = tuple(tuple(F4.one if i == j else F4.zero for j in range(3)) for i in range(3))
    mm = lambda X, Y: I.mat_mul(F4, X, Y); dg = lambda X: I.dagger(F4, X); tr = lambda X: I.trace(F4, X)
    re2 = lambda U: F4.add(tr(U), F4.conj(tr(U)))                                 # Tr U + conj Tr U, the Wilson term
    ok &= len(su3) == 216 and all(mm(U, dg(U)) == one and mm(dg(U), U) == one for U in su3)
    ok &= all(tr(dg(U)) == F4.conj(tr(U)) and re2(dg(U)) == re2(U) for U in su3)
    # 27:X11 (p27034), 27:P9 (p27043) — corroboration of H3's rows: the orientation clause
    R.check("H4", "the Wilson term Tr U + conj Tr U is even under orientation reversal U → U⁻¹ = U† on the 24 elements of 2T "
            "and all 216 elements of SU(3, 2) over F_4: no orientation-odd (topological) term in the Wilson class", ok,
            f"{len(G)} + {len(su3)} elements")


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)
