"""p32_dark — the ledger file of 32-dark (the 32-dark migration, 18 October 2026).

"The Dark Sector over Finite Relational Substrate" (Akhtman, Geifman and Voether, preprint 2026). The paper's predicate
ledger is docs/32-dark/32-dark-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 dark
theme (frc/dark.py) over the gravity theme's Gauss law and the extension theme's F_{p²}; the continuum readings call the
chart theme (frc/chart.py, frc/chart_dark.py, the SPARC tables under frc/data/sparc/) and compare its readings with
rational bounds. Each check names the predicate(s) it witnesses (LEDGER) and carries a `# 32: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 or rational
arithmetic: the 5³ box in Fractions, Z[i], Z[ω] and F_{p²} for p = 13, 17, 53, the rational roots of the first-passage
quadratic, the killed walk on Z_N solved exactly, the divisor lattice of Ω − 1 on the laboratory Carrier; no float
decides anything. A CHART check is a continuum reading or a confrontation with the SPARC tables, every float converted
exactly before the comparison; its label carries "[chart]". The paper's own classes were EXACT, SIM and CHART, one per
package record (src/32-dark, twelve scripts and the figure script run by darkcommon.py); FAMILY names the package record
each check reproduces, None for the checks beyond the package (D2 the external-field speeds of the body's figure, F1 the
cosmological constant, Z1 the divisor lattice). The two seeded simulations (deep_regime, the killed walk of
meridian_walk) are not reproduced: the stationary Fokker–Planck slope and the exact cycle solution decide their clauses,
and the runs stay in the package as the figures' sources (decision D5 of the blueprint). The package stays the paper's
published witness until its release pins the framework.

The Lean side: the theorems of the dark theme (lean/FrcCore/Theme/Dark.lean) over the gravity theme's Gauss law and
locked sum (Theme/Drift.lean) and the transform theme's geometric sum, the readings on Mathlib
(lean/FrcLedger/Theme/Dark.lean); the keys in Keys/Dark.lean (core) and Keys/Chart.lean (Mathlib), the certificates
Ledgers/P32Dark.lean.

No numeral above Ω ∼ 10¹²³ is formed: the entropy S = 3.3 × 10¹²² enters Λ = 3π/S and the Λ-face of the floor as a
declared datum, and the divisor lattice is that of the laboratory Carrier's Ω − 1 = 2 408 560.

    python3 -m frc.ledgers.p32_dark         every block, the census; exit 1 if a check fails (≈ 2 s)
    python3 -m frc.ledgers.p32_dark C       one block (A to Z)
    from frc.ledgers.p32_dark import R; R.predicate("32:C6")    one predicate: its blocks run once per session

Blocks:  A  the Gauss law and the floor: the 5³ box, a₀ = cH₀/2π and its Λ-face                      (32:C1, X1, C2, X2, X10)
         B  the amplitude reading: n² and n, the geometric mean, the Newtonian link, Tully–Fisher       (32:C3, C4, C5, X3)
         C  the registration theorem: the count, Vieta, the cycle solution, the reduction               (32:C6, X4, C7, C2)
         D  the scatter and the environment: SPARC at the fixed floor, the external-field downturn      (32:C8, X5, P2, C9, X6)
         E  the coherence law: the weights 1 and 0, N_eff, the cluster core                             (32:C10, X7, P5, X8)
         F  the cosmological constant from the one cardinality                                          (32:C11, X9, X10)
         G  the predictions: the running floor, the scatter form, wide binaries, the offset, the law    (32:P1, P2, P3, P4, X11, P6)
         Z  the Ω-hard reading: the divisor lattice of Ω − 1                                            (32:Z1)

Checks: 23, of them 9 EXACT and 14 CHART (A2, B2c, B3c, C1c, C2c, D1, D2, E2c, F1, G1, G2, G3, G4, G5). The notebook
frc/ledgers/p32_dark.ipynb runs one predicate per cell, the cell's id its key (gate G13).
"""
import random
import sys
from fractions import Fraction as Q

from frc.registry import Registry
from frc import dark as D
from frc import flavour as FL
from frc import chart as CH
from frc import chart_dark as CD

# ---- generated by ci/make_ledgers.py from docs/32-dark/32-dark-ledger.json; edit the ledger, not this table ----
PAPER = "32-dark"
KEYS = {"A1": "p32001", "A2": "p32002", "A3": "p32003", "A4": "p32004", "A5": "p32005", "A6": "p32006", "A7": "p32007", "B1": "p32008", "B2": "p32009", "B3": "p32010", "B4": "p32011", "B5": "p32012", "B6": "p32013", "B7": "p32014", "B8": "p32015", "B9": "p32051", "C1": "p32016", "C2": "p32017", "C3": "p32018", "C4": "p32019", "C5": "p32020", "C6": "p32021", "C7": "p32022", "C8": "p32023", "C9": "p32024", "C10": "p32050", "C11": "p32026", "X1": "p32027", "X2": "p32028", "X3": "p32029", "X4": "p32030", "X5": "p32031", "X6": "p32032", "X7": "p32033", "X8": "p32034", "X9": "p32035", "X10": "p32036", "X11": "p32037", "P1": "p32038", "P2": "p32039", "P3": "p32040", "P4": "p32041", "P5": "p32042", "P6": "p32043", "V1": "p32044", "V2": "p32045", "Z1": "p32047", "Y1": "p32048", "Y2": "p32049"}       # every row of the ledger: its label and its accession key
LEAN = {"C1": "core", "C2": "ml", "C3": "core", "C4": "core, ml", "C5": "core, ml", "C6": "core, ml", "C7": "core, ml", "C8": "ml", "C9": "ml", "C10": "core, ml", "C11": "ml", "X1": "core", "X2": "ml", "X3": "core, ml", "X4": "core, ml", "X5": "ml", "X6": "ml", "X7": "core, ml", "X8": "core, ml", "X9": "ml", "X10": "ml", "X11": "ml", "P1": "ml", "P2": "ml", "P3": "ml", "P4": "ml", "P5": "core", "P6": "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 32:XN): the predicate(s) each check witnesses.
LEDGER = {
    "A1": "32:C1, 32:X1", "A2": "32:C2, 32:X2, 32:X10",
    "B1": "32:C3", "B2": "32:C4, 32:C1", "B2c": "32:C4", "B3": "32:C5, 32:X3", "B3c": "32:C5, 32:X3, 32:C4",
    "C1": "32:C6, 32:X4", "C1c": "32:C6, 32:X4", "C2": "32:C7, 32:C6", "C2c": "32:C7",
    "D1": "32:C8, 32:X5, 32:P2", "D2": "32:C9, 32:X6",
    "E1": "32:C10, 32:X7, 32:P5", "E2": "32:X8", "E2c": "32:X8",
    "F1": "32:C11, 32:X9, 32:X10",
    "G1": "32:P1", "G2": "32:P2, 32:C8", "G3": "32:P3", "G4": "32:P4", "G5": "32:X11, 32:P6, 32:C6, 32:C2",
    "Z1": "32:Z1",
}

# the package record (dark.<script>) each check reproduces; None for the three checks beyond the package
FAMILY = {
    "A1": "flux_exact", "A2": "deep_mond",
    "B1": "born_exact", "B2": "flux_exact", "B2c": "deep_regime_fp", "B3": "deep_mond", "B3c": "deep_mond",
    "C1": "meridian_walk", "C1c": "interpolation", "C2": "firstpassage_finite", "C2c": "firstpassage_finite",
    "D1": "rar_scatter", "D2": None,
    "E1": "cluster_coherent", "E2": "cluster_coherent", "E2c": "cluster_coherent",
    "F1": None,
    "G1": "predictions", "G2": "predictions", "G3": "predictions", "G4": "predictions", "G5": "rar_shape",
    "Z1": None,
}

BLOCK = {"A": "the Gauss law and the floor: the 5³ box, a₀ = cH₀/2π and its Λ-face",
         "B": "the amplitude reading: n² and n, the geometric mean, the Newtonian link, Tully–Fisher",
         "C": "the registration theorem: the count, Vieta, the cycle solution, the reduction",
         "D": "the scatter and the environment: SPARC at the fixed floor, the external-field downturn",
         "E": "the coherence law: the weights 1 and 0, N_eff, the cluster core",
         "F": "the cosmological constant from the one cardinality",
         "G": "the predictions: the running floor, the scatter form, wide binaries, the offset, the one-variable law",
         "Z": "the Ω-hard reading: the divisor lattice of Ω − 1"}

# the deciding check of each witnessed predicate (the other checks that touch it are corroboration)
PREDICATES = {
    "32:C1": "A1", "32:C2": "A2", "32:C3": "B1", "32:C4": "B2", "32:C5": "B3", "32:C6": "C1", "32:C7": "C2",
    "32:C8": "D1", "32:C9": "D2", "32:C10": "E1", "32:C11": "F1",
    "32:X1": "A1", "32:X2": "A2", "32:X3": "B3", "32:X4": "C1", "32:X5": "D1", "32:X6": "D2", "32:X7": "E1",
    "32:X8": "E2", "32:X9": "F1", "32:X10": "F1", "32:X11": "G5",
    "32:P1": "G1", "32:P2": "G2", "32:P3": "G3", "32:P4": "G4", "32:P5": "E1", "32:P6": "G5",
    "32:Z1": "Z1",
}

R = Registry("32", "dark", LEDGER, PREDICATES, sources=[__file__])

SHELLS = (13, 17, 53)                                   # the shells of the F_{p²} checks
RNG = random.Random(32)


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 _rand_ext(K):
    return (RNG.randrange(K.p), RNG.randrange(K.p))


# ------------------------------------------------------------------------------------------------------------
# block A: the Gauss law and the floor (32:C1, X1, C2, X2, X10)
@R.block("A", BLOCK["A"])
def block_A():
    """Block A — the Gauss law and the floor: A1 exact, A2 chart."""
    # A1 the discrete Gauss law in Fractions on the 5³ box with Dirichlet boundary: the unit source at the centre has flux 1
    #    through the surfaces R = 0 and R = 1 (and through a non-cubic region enclosing it), a source-free field with random
    #    rational boundary values has flux 0, their superposition flux 1; two sources (the centre and a neighbour, charges 1 and
    #    3/7) give the enclosed count 10/7 through R = 1 and 1 through R = 0
    f0, f1, fn, fsn = D.gauss_law(seed=1, n=5)
    ok = f0 == 1 and f1 == 1 and fn == 0 and fsn == 1
    det = [f"5³: flux(R=0) = {f0}, flux(R=1) = {f1}, source-free {fn}, superposed {fsn}"]
    box = D.GaussBox(5)
    zero = {p: Q(0) for p in box.boundary}
    U = box.field({box.centre: Q(1)}, zero)
    region = {box.centre, (2, 2, 3)}                                             # a non-cubic region enclosing the source
    tot = Q(0)
    for p in region:
        for q in box.nbrs(p):
            if q not in region: tot += U[p] - U[q]
    ok &= tot == 1
    U2 = box.field({box.centre: Q(1), (1, 2, 2): Q(3, 7)}, zero)
    ok &= box.flux(U2, 1) == Q(10, 7) and box.flux(U2, 0) == 1
    det.append(f"two sources 1 and 3/7: flux(R=1) = {box.flux(U2, 1)}, flux(R=0) = {box.flux(U2, 0)}")
    # 32:C1 (p32016), 32:X1 (p32027)
    R.check("A1", "the discrete Gauss law of the synchronisation flux, exact in rationals on the 5³ box with Dirichlet boundary: "
            "a unit point source gives flux 1 through both enclosing cubes and through a non-cubic region around it, a "
            "source-free field with random rational boundary values gives flux 0, their superposition gives 1, and two sources "
            "of charges 1 and 3/7 give the enclosed count 10/7 — Newton's law as the enclosed count, the test cluster's "
            "acceleration independent of its composition", ok, "; ".join(det))

    # A2 [chart] the floor a₀ = cH₀/2π at the entailed H₀ = 67.4: 1.0422 × 10⁻¹⁰ m s⁻², 13.2 % below the fitted g_† = 1.20 ×
    #    10⁻¹⁰ and 0.66 of its systematic 0.24 × 10⁻¹⁰; the Λ-face of the floor from the entropy alone, cH_Λ/2π with
    #    H_Λ = c/(√(S/π) ℓ_P), 0.864 × 10⁻¹⁰, five sixths of a₀
    a0, pct, sig = CD.floor_comparison()
    lo, hi = CH.floor_bracket(CD.DATA["cosmology"]["H0"])
    rH, HL, face = CD.lambda_face()
    ok = _within(a0, "1.0422e-10", "1e-14") and lo - Q("1e-25") < Q(a0) < hi + Q("1e-25") and _between(pct, "13.1", "13.2") and _between(sig, "0.65", "0.66")
    ok &= _between(face, "8.63e-11", "8.64e-11") and _between(Q(face) / Q(a0), "0.82", "0.84")
    # 32:C2 (p32017), 32:X2 (p32028)
    R.check("A2", "[chart] the acceleration floor a₀ = cH₀/2π = 1.0422 × 10⁻¹⁰ m s⁻² at the entailed H₀ = 67.4 km s⁻¹ Mpc⁻¹, "
            "inside the chart theme's certified bracket, 13.2 % below the fitted g_† = 1.20 × 10⁻¹⁰ and 0.66 of its systematic "
            "band (the paper's 13 %, 0.7σ); the Λ-face of the floor read from the entropy S = 3.3 × 10¹²² alone, "
            "cH_Λ/2π = 0.864 × 10⁻¹⁰, five sixths of a₀ (X10)", ok,
            f"a₀ = {a0:.5e}, {pct:.2f} % below g_†, {sig:.3f}σ; Λ-face {face:.4e} = {face / a0:.3f} a₀", kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block B: the amplitude reading (32:C3, C4, C5, X3)
@R.block("B", BLOCK["B"])
def block_B():
    """Block B — the amplitude reading: B1–B3 exact, B2c and B3c chart."""
    # B1 amplitude = √count: n aligned units have norm n² in Z[i] (the units 1 and i) and on F_{p²}; over all 2^n sign
    #    patterns the total of the norms is 2^n Σ norm(u_k) (the cross terms cancel), the mean of (Σ ε_k)² is exactly n for
    #    n ≤ 10; the parallelogram identity norm(a + b) + norm(a − b) = 2 norm a + 2 norm b on random Gaussian integers
    GI = D.GI; ok = True
    for n in range(1, 11):
        for u in (GI.el(1, 0), GI.el(0, 1), GI.el(1, 1)):
            lhs, rhs = D.coherent_count(GI, u, n); ok &= lhs == rhs == n * n * GI.norm(u)
        ok &= D.incoherent_mean(n) == n
        us = [GI.el(1, 0)] * n
        lhs, rhs = D.sign_pattern_total(GI, us); ok &= lhs == rhs == 2 ** n * n
    for _ in range(20):
        a, b = GI.el(RNG.randint(-9, 9), RNG.randint(-9, 9)), GI.el(RNG.randint(-9, 9), RNG.randint(-9, 9))
        ok &= GI.norm(GI.add(a, b)) + GI.norm(GI.add(a, GI.neg(b))) == 2 * GI.norm(a) + 2 * GI.norm(b)
        us = [GI.el(RNG.randint(-5, 5), RNG.randint(-5, 5)) for _ in range(6)]
        lhs, rhs = D.sign_pattern_total(GI, us); ok &= lhs == rhs
    det = []
    for p in SHELLS:
        K = D.shell_ext(p)
        for _ in range(5):
            u = _rand_ext(K); lhs, rhs = D.coherent_count(K, u, RNG.randint(2, 12)); ok &= lhs == rhs
            us = [_rand_ext(K) for _ in range(RNG.randint(2, 7))]; lhs, rhs = D.sign_pattern_total(K, us); ok &= lhs == rhs
        det.append(f"F_{p}² (ν = {K.nu})")
    # 32:C3 (p32018)
    R.check("B1", "amplitude is the square root of the count, exact in Z[i]: n aligned unit phasors have |Σ|² = n² (amplitude n, "
            "the coherent first moment) and the mean of |Σ ε_k|² over all 2ⁿ sign patterns is n (amplitude √n, the incoherent "
            "second moment) for n ≤ 10, by the cross-term cancellation Σ_ε N(Σ ε_k u_k) = 2ⁿ Σ N(u_k) on random Gaussian "
            "integers and on F_{p²} for p = 13, 17, 53; the parallelogram identity on 20 random pairs", ok,
            "n ≤ 10 in Z[i]; the shells " + ", ".join(det))

    # B2 the deep-regime geometric mean on rational squares: g² = g_b a₀ ⟹ g = √(g_b a₀), and the Gauss law's invariance under
    #    a source-free current: the superposed field's enclosed flux equals the source's for three noise fields
    ok = True
    for gb, a0 in ((Q(1, 4), Q(9)), (Q(16, 25), Q(25, 4)), (Q(49), Q(1, 49)), (Q(2, 3), Q(3, 8))):
        g = D._sqrt_q(gb * a0); ok &= g is not None and g * g == gb * a0 and g > 0
    for seed in (2, 3, 4):
        f0, f1, fn, fsn = D.gauss_law(seed=seed)
        ok &= f1 == 1 and fn == 0 and fsn == f1
    # 32:C4 (p32019)
    R.check("B2", "the deep-regime law is registration, not force modification: below the floor the conserved flux g_b a₀ is read "
            "as an amplitude, g = √(g_b a₀) with g² = g_b a₀ exactly on rational squares, while the mean force stays Newtonian — "
            "the enclosed flux of the unit source on the 5³ box is unchanged by three source-free noise fields (the Gauss law's "
            "invariance under a source-free current, exact)", ok, "four rational instances; three noise fields, flux 1 = 1")

    # B2c [chart] the stationary Fokker–Planck solution of the noisy link dφ = (T − sin φ)dt + √(2D) dW: the small-tilt log-slope
    #     of the mean response is 1.000 within 2 × 10⁻³ at D = 0.3 and 0.6, the boost T/⟨sin φ⟩ constant to rising — no √ regime
    #     in the mean force; the paper's simulated 1.03, 1.11 are the exhibit's step bias on this exact 1
    ok = True; det = []
    for Dn in CD.DATA["link"]["D"]:
        slope, boost = CD.fokker_planck_slope(Dn)
        ok &= _within(slope, 1, "0.002") and all(Q(b2) >= Q(b1) - Q("1e-9") for b1, b2 in zip(boost[:-1], boost[1:]))
        det.append(f"D = {Dn}: slope {slope:.4f}, boost {boost[0]:.3f} → {boost[-1]:.3f}")
    R.check("B2c", "[chart] the mean force of the noisy link is Newtonian at every noise level: in the stationary Fokker–Planck "
            "solution the small-tilt log-slope d ln T/d ln⟨sin φ⟩ is 1.000 within 2 × 10⁻³ at D = 0.3 and 0.6 and the boost "
            "T/⟨sin φ⟩ is constant to rising with the tilt (the paper's simulated 1.03 and 1.11 are the exhibit's step bias on "
            "this exact 1); the √ law is not in the mean force", ok, "; ".join(det), kind="CHART")

    # B3 v⁴ = GMa₀ on rationals: s² = GMa₀, v² = s, so v⁴ = GMa₀ (the flat speed from the geometric mean g = √(GMa₀)/r)
    ok = True
    for G, M, a0 in ((Q(2, 3), Q(3, 2), Q(16)), (Q(1, 4), Q(9), Q(4, 9)), (Q(81, 16), Q(16), Q(1, 81)), (Q(5), Q(5), Q(1, 25))):
        r = D.tully_fisher(G, M, a0); ok &= r is not None and r[0] == r[1] and r[2] == r[3] and r[3] * r[3] == G * M * a0
    # 32:C5 (p32020), 32:X3 (p32029)
    R.check("B3", "flat rotation curves and the baryonic Tully–Fisher relation: with g = √(GMa₀)/r below the floor, v² = gr = "
            "√(GMa₀) is independent of r and v⁴ = GMa₀, exact on four rational instances where GMa₀ is a fourth power", ok,
            "v⁴ = GMa₀ on (2/3, 3/2, 16), (1/4, 9, 4/9), (81/16, 16, 1/81), (5, 5, 1/25)")

    # B3c [chart] the Tully–Fisher speed (GMa₀)^{1/4} = 162 km s⁻¹ at 5 × 10¹⁰ M_⊙, the slope d ln v/d ln M = 1/4, the RAR
    #     deep slope 0.514 and the Newtonian slope 1.000; the exponential disk 5 × 10¹⁰ M_⊙, R_d = 3 kpc: its baryonic curve peaks
    #     at 167 km s⁻¹ and the registered curve runs flat at 180 km s⁻¹ over 20–30 kpc, 11 % above the Tully–Fisher asymptote
    v = CD.btfr_speed(); bt = CD.btfr_slope(); deep, newt = CD.slopes(); peak, outer, tf = CD.rotation_curve()
    ok = _between(v, 162, 163) and _within(bt, Q(1, 4), "1e-6") and _between(deep, "0.514", "0.515") and _within(newt, 1, "1e-4")
    ok &= _between(peak, 166, 167) and _between(outer, 180, 181) and _between(Q(outer) / Q(tf), "1.10", "1.12")
    R.check("B3c", "[chart] the Tully–Fisher speed (GMa₀)^{1/4} = 162 km s⁻¹ at 5 × 10¹⁰ M_⊙, the slope d ln v_flat/d ln M = 1/4, "
            "the RAR deep slope d ln(xν)/d ln x = 0.514 over 10⁻³ < x < 10⁻² and the Newtonian slope 1.000 over 10² < x < 10³; "
            "the exponential disk of that mass (R_d = 3 kpc, the Bessel kernel by quadrature) peaks at 167 km s⁻¹ in baryons and "
            "its registered curve runs flat at 180 km s⁻¹ over 20–30 kpc, 1.11 of the asymptote", ok,
            f"v = {v:.1f} km/s, slopes {bt:.4f}, {deep:.3f}, {newt:.4f}; disk peak {peak:.1f}, outer {outer:.1f}", kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block C: the registration theorem (32:C6, X4, C7, C2)
@R.block("C", BLOCK["C"])
def block_C():
    """Block C — the registration theorem: C1, C2 exact, C1c, C2c chart."""
    # C1 the registration count: N_bar = f N_reg ⟺ g_obs = g_b/f on rationals (both directions, 40 draws), and Vieta's form of
    #    the first-passage quadratic (z/2)f² − f + z/2 = 0 on z = 3/5, 5/13, 8/17 (1 − z² a square): the roots 1/3 and 3, 1/5
    #    and 5, 1/4 and 4, product 1, sum 2/z, residual 0
    ok = True
    for _ in range(40):
        f = Q(RNG.randint(1, 99), 100); gb = Q(RNG.randint(1, 99), RNG.randint(1, 9)); go = gb / f
        ok &= (f * go == gb) and (go == gb / f) and not (f * (go + 1) == gb)
    det = []
    for z in (Q(3, 5), Q(5, 13), Q(8, 17)):
        f, g = D.passage_roots(z)
        ok &= f * g == 1 and f + g == 2 / z and D.passage_residual(z, f) == 0 and D.passage_residual(z, g) == 0 and 0 < f < 1
        det.append(f"z = {z}: f = {f}, f' = {g}")
    # 32:C6 (p32021), 32:X4 (p32030)
    R.check("C1", "the registration theorem's exact core: the conditional count N_bar = f·N_reg is the relation g_obs = g_b/f and "
            "conversely (40 rational draws), and the first-passage quadratic (z/2)f² − f + z/2 = 0 has the two roots f = (1 − "
            "√(1 − z²))/z and 1/f with product 1 and sum 2/z — Vieta, exact on z = 3/5, 5/13, 8/17; the interpolation "
            "g_b/(1 − e^{−√x}) is this registration with the amplitude barrier B8, no fitted function", ok, "; ".join(det))

    # C1c [chart] the interpolation against the simple rational form (1 + √(1 + 4/x))/2 with the same limits: the discriminant
    #     ν_simple − ν peaks at 0.0512 (0.0195 dex) at x = 5.22; the chart angle α(1) = arcsin(e^{−1/2}) = 37.3°
    dmax, xmax, ddex = CD.discriminant(); ang = CD.chart_angle()
    ok = _between(dmax, "0.0511", "0.0513") and _between(xmax, "5.2", "5.25") and _between(ddex, "0.0194", "0.0196") and _between(ang, "37.3", "37.4")
    R.check("C1c", "[chart] the interpolation ν(x) = 1/(1 − e^{−√x}) against the simple rational form with the same two limits: "
            "the discriminant ν_simple − ν is largest at x = 5.22, 0.0512 in g_obs/g_b (0.0195 dex), the paper's 0.051 at 5.2; "
            "the chart angle at the floor α(1) = arcsin(e^{−1/2}) = 37.3°", ok,
            f"max {dmax:.4f} at x = {xmax:.2f} ({ddex:.4f} dex); α(1) = {ang:.1f}°", kind="CHART")

    # C2 the finite-cycle first-passage law: the killed walk on Z_N (absorbing barrier at a, per-step survival z) solved as an
    #    exact linear system equals the two-image form (f^a + f^{N−a})/(1 + f^N) for every a on Z₁₂ at z = 3/5 (f = 1/3) and
    #    Z₁₀ at z = 5/13 (f = 1/5); the passage factor f = u − √(u² − 1) at u = 5/4 is 1/2, the root at z = 4/5, its reciprocal 2;
    #    the single-step identity z(t + tf²) = 2tf
    ok = True; det = []
    for N, z in ((12, Q(3, 5)), (10, Q(5, 13))):
        f = D.passage_roots(z)[0]
        for a in range(1, N):
            ok &= D.cycle_escape(N, a, z) == D.cycle_closed(N, a, f)
        det.append(f"Z_{N}, z = {z}: h_0 = {D.cycle_closed(N, N // 4, f)} at a = {N // 4}, the line's f^a = {f ** (N // 4)}")
    fac, rec = D.passage_factor(Q(5, 4))
    ok &= fac == Q(1, 2) and rec == 2 and D.passage_roots(Q(4, 5))[0] == Q(1, 2)
    for z in (Q(3, 5), Q(5, 13), Q(8, 17), Q(4, 5)):
        f = D.passage_roots(z)[0]
        for t in (Q(1), Q(7, 3), Q(-2, 5)):
            ok &= z * (t + t * f * f) == 2 * t * f
    # 32:C7 (p32022)
    R.check("C2", "the finite-cycle first-passage law, exact: the killed walk on Z₁₂ (z = 3/5) and Z₁₀ (z = 5/13), absorbing at a, "
            "solved as a rational linear system equals the two-image form (f^a + f^{N−a})/(1 + f^N) for every a, the wrap term "
            "f^{N−a} the whole correction to the line's f^a; the passage factor u − √(u² − 1) is 1/2 at u = 5/4 (the root of the "
            "quadratic at z = 4/5, reciprocal 2); the single-step identity z(t + tf²) = 2tf on four rational z", ok, "; ".join(det))

    # C2c [chart] the controlled reduction arccosh(e^s) = √(2s)(1 + s/6 + …): the coefficient (arccosh(e^s)/√(2s) − 1)/s is 1/6
    #     within 10⁻⁵ at s = 10⁻⁴; the wrap correction on Z₂₀₀ (a = 8, s = 0.02): the two-image difference 1.78 × 10⁻¹⁷, the
    #     wrap term e^{−192 arccosh(e^s)} = 1.85 × 10⁻¹⁷
    c4, c2 = CD.passage_reduction(Q("1e-4")), CD.passage_reduction(Q("1e-2")); diff, wrap = CD.wrap_term()
    ok = _within(c4, Q(1, 6), "1e-5") and _within(c2, Q(1, 6), "1e-3") and _between(diff, "1.77e-17", "1.78e-17") and _between(wrap, "1.85e-17", "1.86e-17")
    R.check("C2c", "[chart] the reduction of the exact exponent arccosh(e^s) to the Brownian √(2s): the relative error over s is "
            "1/6 within 10⁻⁵ at s = 10⁻⁴ (within 10⁻³ at 10⁻²), so e^{−√x} is the resolvable reading to O(s) = O(Ω^{−1/2}); on "
            "Z₂₀₀ with the barrier at 8 and s = 0.02 the cycle departs from the line by 1.78 × 10⁻¹⁷, the wrap term "
            "e^{−192 arccosh(e^s)} = 1.85 × 10⁻¹⁷", ok, f"coefficient {c4:.7f}; wrap difference {diff:.3e}, term {wrap:.3e}", kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block D: the scatter and the environment (32:C8, X5, P2, C9, X6)
@R.block("D", BLOCK["D"])
def block_D():
    """Block D — the scatter and the environment: D1, D2 chart."""
    # D1 [chart] the SPARC radial acceleration relation at the fixed floor a₀ = cH₀/2π: the 2693 points scatter by 0.133 dex
    #    against 0.127 expected from the quoted errors, an intrinsic 0.038 dex; binned in x the intrinsic scatter is 0.043 and
    #    0.046 dex across the knee (−0.5 < log x < 0.5), 0.135 dex at x ≈ 0.02 and zero above x = 3; the knee value bounds
    #    δα ≲ 3.5° while the dynamical-temperature identification δα = 6–11° would give 0.07–0.13 dex there; the within-galaxy
    #    intrinsic scatter of 116 disks shows no correlation with 1/V_flat (ρ = −0.02); an amplitude sum of a galaxy's gas, disk
    #    and bulge would lift the relation by 0.14 dex
    n, rms, exp_rms, intr, mean, bins = CD.sparc_residuals()
    ok = n == 2693 and _between(rms, "0.132", "0.134") and _between(exp_rms, "0.126", "0.128") and _between(intr, "0.037", "0.039")
    knee1, knee2, deep = bins[("-0.5", "0")][1], bins[("0", "0.5")][1], bins[("-2", "-1.5")][1]
    ok &= _between(knee1, "0.04", "0.05") and _between(knee2, "0.04", "0.05") and _between(deep, "0.13", "0.14") and Q(deep) > 2 * Q(knee1)
    ok &= bins[("0.5", "1")][1] == 0 and bins[("1", "1.5")][1] == 0
    da = CD.delta_alpha_bound(Q("0.04"), 1); s6, s11 = CD.scatter_at_angle(1, 6), CD.scatter_at_angle(1, 11)
    ok &= _between(da, "3.4", "3.5") and _between(s6, "0.069", "0.070") and _between(s11, "0.127", "0.128") and Q(s6) > Q(3, 2) * Q(knee2)
    ng, med, rho = CD.sparc_within_galaxy(); npts, boost, b16, b84 = CD.sparc_amplitude_boost()
    ok &= ng == 116 and _within(rho, "-0.02", "0.005") and abs(Q(rho)) < Q("0.17") and _between(boost, "0.13", "0.14") and Q(boost) > Q(1, 10)
    # 32:C8 (p32023), 32:X5 (p32031)
    R.check("D1", "[chart] the SPARC relation at the fixed floor: the 2693 points scatter by 0.133 dex against 0.127 expected from "
            "the quoted errors, an intrinsic 0.038 dex, smallest at high acceleration (zero above x = 3), 0.043–0.046 dex across "
            "the knee and 0.135 dex at x ≈ 0.02 — the deep rise of the form; the knee bounds δα ≲ 3.5°, the dynamical-temperature "
            "identification δα = 6–11° (0.07–0.13 dex at x = 1) exceeds the intrinsic scatter 1.5-fold and the within-galaxy "
            "scatter of 116 disks is uncorrelated with 1/V_flat (ρ = −0.02); an amplitude sum of gas, disk and bulge would lift "
            "the relation by 0.14 dex (the within-galaxy constraint on Y1)", ok,
            f"rms {rms:.3f}, expected {exp_rms:.3f}, intrinsic {intr:.3f}; bins {knee1:.3f}, {knee2:.3f}, deep {deep:.3f}; "
            f"δα ≲ {da:.2f}°; {ng} disks ρ = {rho:+.3f}; boost {boost:.3f} dex over {npts} points", kind="CHART")

    # D2 [chart] the external-field effect: the registration reads the total field, g_obs = g_in ν((g_in + g_ext)/a₀), so a
    #    stronger environment uses up the deep enhancement; the outer speed (40 kpc) of the 6 × 10¹⁰ M_⊙ disk falls from 181 to
    #    163, 143 and 113 km s⁻¹ as g_ext/a₀ runs through 0, 0.03, 0.1, 0.5 (the body's figure); ν decreasing in its argument
    v = CD.efe_speeds()
    ok = all(_within(x, c, "0.5") for x, c in zip(v, (181, 163, 143, 113))) and all(Q(a) > Q(b) for a, b in zip(v[:-1], v[1:]))
    ok &= _between(100 * (1 - Q(v[1]) / Q(v[0])), 9, 10) and _between(100 * (1 - Q(v[3]) / Q(v[0])), 37, 38)
    ok &= all(CD.nu(y1) > CD.nu(y2) for y1, y2 in ((Q(1, 10), Q(1, 5)), (Q(1, 2), 1), (1, 2), (2, 5)))
    # 32:C9 (p32024), 32:X6 (p32032)
    R.check("D2", "[chart] the external-field effect: the registration reads the total field, g_obs = g_in ν((g_in + g_ext)/a₀) with "
            "ν decreasing, so a stronger environment uses up the deep enhancement — the outer rotation speed of the fixed disk "
            "(6 × 10¹⁰ M_⊙, R_d = 3 kpc, at 40 kpc) falls from 181 to 163, 143 and 113 km s⁻¹ as g_ext/a₀ increases through 0, "
            "0.03, 0.1, 0.5 (a 9 % downturn at the Milky-Way-scale field, 37 % at 0.5); the acceleration scale stays global", ok,
            "speeds " + ", ".join(f"{x:.1f}" for x in v) + " km/s", kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block E: the coherence law (32:C10, X7, P5, X8)
@R.block("E", BLOCK["E"])
def block_E():
    """Block E — the coherence law: E1, E2 exact, E2c chart."""
    # E1 the bulk-coherence weight: n aligned unit phasors sum to n (|Σ|² = n², w = 1); a full cycle of phases sums to zero
    #    (w = 0) — Σ_{l<3} ω^l = 0 in Z[ω], Σ_{l<4} i^l = 0 in Z[i], Σ_{l<n} ζ^l = 0 on F_{p²} for ζ of order n | p² − 1; the
    #    coherence sum g_amp² = Σg + 2Σ_{i<j}√(g_i g_j) C_ij equals (Σ√g)² at C = 1 (the relaxed core, the gas gravitates) and
    #    Σg at C = 0 (the merger, the shocked gas drops out) on rational squares
    w = FL.OMEGA; ok = (1 + w + w * w == 0) and (w + w + w == FL.QOmega(0, 3))
    GI = D.GI
    ok &= D.phasor_cycle_sum(GI, GI.el(0, 1), 4) == GI.el(0, 0) and D.phasor_cycle_sum(GI, GI.el(1, 0), 4) == GI.el(4, 0)
    det = []
    for p in SHELLS:
        K = D.shell_ext(p)
        for n in (3, 4, 6, p + 1, p - 1):
            if (p * p - 1) % n: continue
            zeta = next(z for z in ((a, b) for a in range(p) for b in range(p)) if z != (0, 0) and K.pow(z, n) == (1, 0)
                        and all(K.pow(z, d) != (1, 0) for d in range(1, n) if n % d == 0))
            ok &= D.phasor_cycle_sum(K, zeta, n) == (0, 0) and D.phasor_cycle_sum(K, (1, 0), n) == (n % p, 0)
        det.append(f"F_{p}²: the orders 3, 4, 6, {p - 1}, {p + 1}")
    for gs in (([4, 1, 1]), ([9, 4]), ([1, 1, 1, 1]), ([Q(1, 4), Q(9, 16), 1])):
        roots = [D._sqrt_q(g) for g in gs]
        ok &= D.coherence_sum(gs, 1) == sum(roots) ** 2 and D.coherence_sum(gs, 0) == sum(Q(g) for g in gs)
        ok &= D.coherence_sum(gs, 1) >= D.coherence_sum(gs, 0)
    # 32:C10 (p32050), 32:X7 (p32033), 32:P5 (p32042)
    R.check("E1", "the coherence law: n aligned phasors sum to n (weight w = 1, the virialised clump) and a full cycle of phases "
            "sums to zero (w = 0, the shock-randomised gas) — in Z[ω] and Z[i] and on F_{p²} for p = 13, 17, 53 at the orders 3, 4, "
            "6, p ± 1; the coherence sum g_amp² = Σg_i + 2Σ_{i<j}√(g_i g_j)C_ij is (Σ√g)² at C = 1 (the relaxed cluster, the gas "
            "gravitates) and Σg at C = 0 (the merger, the gas drops out of the lensing), exact on rational squares — the "
            "merging-cluster offset as a selection", ok, "; ".join(det) + "; four coherence sums")

    # E2 N_eff = (Σ√g)²/Σg on rational squares: 8/3 for the BCG-dominated 4:1:1, N for N equal components (N = 2..8), 25/11
    #    for 9:1:1; 1 ≤ N_eff ≤ N on 30 random square triples and quadruples
    ok = D.n_eff([4, 1, 1]) == Q(8, 3) and D.n_eff([9, 1, 1]) == Q(25, 11) and all(D.n_eff([1] * n) == n for n in range(2, 9))
    ok &= D.n_eff([Q(1, 4), Q(1, 4), 1]) == Q(8, 3) and D.n_eff([Q(1, 9), Q(4, 9)]) == Q(9, 5)
    for _ in range(30):
        gs = [Q(RNG.randint(1, 9)) ** 2 / Q(RNG.randint(1, 5)) ** 2 for _ in range(RNG.randint(3, 4))]
        ne = D.n_eff(gs); ok &= 1 <= ne <= len(gs)
    # 32:X8 (p32034)
    R.check("E2", "the cluster-core residual's law: coherent amplitude addition over N separately virialised composites boosts the "
            "registered amplitude by √N_eff with N_eff = (Σ√g_i)²/Σg_i — exactly N for equal components (N = 2..8), 8/3 for the "
            "BCG-dominated 4:1:1 and 25/11 for 9:1:1, and 1 ≤ N_eff ≤ N on 30 random rational-square tuples; the quantitative "
            "closure with N_eff from a core population is the conjecture Y1", ok, "N_eff(4:1:1) = 8/3, N_eff(1ᴺ) = N")

    # E2c [chart] the core numbers: ν(0.1) = 3.69 and ν(0.25) = 2.54 at the cluster-core accelerations, √6 = 2.449 for a
    #     six-composite core, √(8/3) = 1.63 for the BCG-dominated core
    (n1, n2), r6, r83 = CD.nu_core()
    ok = _between(n1, "3.68", "3.70") and _between(n2, "2.53", "2.55") and _between(r6, "2.449", "2.450") and _between(r83, "1.63", "1.64")
    R.check("E2c", "[chart] the cluster core's numbers: the registration factor ν = 3.69 at g_b/a₀ = 0.1 and 2.54 at 0.25 (the "
            "paper's 2.5–3.7), the coherent boost √6 = 2.449 for six comparable composites and √(8/3) = 1.63 for the "
            "BCG-dominated 4:1:1 core, decaying to 1 where the components fall out of mutual lock", ok,
            f"ν(0.1) = {n1:.3f}, ν(0.25) = {n2:.3f}, √6 = {r6:.3f}", kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block F: the cosmological constant (32:C11, X9, X10)
@R.block("F", BLOCK["F"])
def block_F():
    """Block F — the cosmological constant (chart): F1."""
    # F1 [chart] Λ = 3/r_H² = 3π/S in Planck units at S = 3.3 × 10¹²²: 2.86 × 10⁻¹²², positive, ΛS = 3π; the measured Λ = 1.088 ×
    #    10⁻⁵² m⁻² is 2.84 × 10⁻¹²² in Planck units, within 1 % of it; the floor's Λ-face and Λ are both read from the one S
    lam, lamS = CD.lambda_planck(); lam_fit = CD.lambda_measured(); pi_lo, pi_hi = CH.pi_bracket()
    rH, HL, face = CD.lambda_face(); a0 = CD.floor()
    ok = _between(lam, "2.85e-122", "2.86e-122") and Q(lam) > 0 and 3 * pi_lo - Q("1e-12") < Q(lamS) < 3 * pi_hi + Q("1e-12")
    ok &= _between(lam_fit, "2.83e-122", "2.85e-122") and _within(Q(lam_fit) / Q(lam), 1, "0.01")
    ok &= _between(Q(face) / Q(a0), "0.82", "0.84") and _between(Q(face) ** 2 / Q(lam), "2.6e101", "2.7e101")
    # 32:C11 (p32026), 32:X9 (p32035), 32:X10 (p32036)
    R.check("F1", "[chart] the cosmological constant is the curvature of the wrapped finite chart, Λ = 3/r_H² = 3π/S = 2.86 × 10⁻¹²² "
            "in Planck units at S = 3.3 × 10¹²², positive, ΛS = 3π exactly — a reading of the one cardinality Ω ∼ 4S, not a "
            "mode-sum vacuum energy, so no 120-order cancellation; the measured Λ = 1.088 × 10⁻⁵² m⁻² is 2.84 × 10⁻¹²² in Planck "
            "units, within 1 %; the same S gives the floor's Λ-face 0.86 × 10⁻¹⁰ = 0.83 a₀, the two dark scales fixed together "
            "(X10)", ok, f"Λ = {lam:.3e}, ΛS = {lamS:.6f} = 3π; measured {lam_fit:.3e}; Λ-face/a₀ = {face / a0:.3f}", kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block G: the predictions (32:P1, P2, P3, P4, X11, P6)
@R.block("G", BLOCK["G"])
def block_G():
    """Block G — the predictions (chart): G1–G5."""
    # G1 [chart] the running floor a₀(z) = cH(z)/2π: v_flat ∝ E(z)^{1/4}, +7.2 %, +15.7 %, +32.0 % at z = 0.5, 1, 2 for Ω_m = 0.315;
    #    the knee at z = 1 at cH(1)/2π = 1.87 × 10⁻¹⁰, the rise 0.82 × 10⁻¹⁰
    pct, a1, rise = CD.ez_quarter()
    ok = _within(pct[0], "7.23", "0.01") and _within(pct[1], "15.67", "0.01") and _within(pct[2], "31.95", "0.01")
    ok &= _between(a1, "1.86e-10", "1.87e-10") and _between(rise, "8.2e-11", "8.3e-11")
    ok &= _within(CD.tully_fisher_shift(1), CH.tully_fisher_shift(1, 1 - CD.DATA["cosmology"]["Omega_m"]), "1e-12")
    # 32:P1 (p32038)
    R.check("G1", "[chart] the redshift law a₀(z) = cH(z)/2π: at fixed baryonic mass v_flat ∝ a₀^{1/4} ∝ E(z)^{1/4}, so the "
            "Tully–Fisher zero-point rises by 7 %, 16 % and 32 % at z = 0.5, 1, 2 (Ω_m = 0.315) and the knee moves to "
            "cH(1)/2π = 1.87 × 10⁻¹⁰ m s⁻² at z = 1, a rise of 0.82 × 10⁻¹⁰; parameter-free, the shape resolvable, the value Ω-hard "
            "(Z1); the chart theme's running floor gives the same E(z)^{1/4}", ok,
            f"+{pct[0]:.1f} %, +{pct[1]:.1f} %, +{pct[2]:.1f} %; cH(1)/2π = {a1:.3e}", kind="CHART")

    # G2 [chart] the two-variable scatter σ = (2 tan α/ln 10) arctan(σ_v/v): 0.267 dex at x = 0.01 and σ_v/v = 0.1, under 0.01 dex
    #    at x = 100, zero for cold systems; tan α(x)·x^{1/4} → 1 into the deep regime (the x^{−1/4} rise)
    s001 = CD.scatter_law(Q(1, 100), Q(1, 10)); s100 = CD.scatter_law(100, Q(1, 10)); rise = CD.scatter_rise()
    ok = _between(s001, "0.266", "0.268") and Q(s100) < Q(1, 100) and CD.scatter_law(1, 0) == 0
    ok &= all(Q(a) < Q(b) for a, b in zip(rise[:-1], rise[1:])) and _between(rise[-1], "0.997", 1) and _between(rise[0], "0.97", "0.98")
    # 32:P2 (p32039)
    R.check("G2", "[chart] the scatter is the two-variable form σ = (2 tan α(x)/ln 10)·δα with tan²α = 1/(e^{√x} − 1): 0.267 dex at "
            "x = 0.01 for σ_v/v = 0.1, below 0.01 dex at x = 100, zero for cold systems, and tan α·x^{1/4} → 1 (0.975, 0.992, 0.998 "
            "at x = 10⁻², 10⁻³, 10⁻⁴) — the x^{−1/4} rise into the deep regime that the SPARC bins show (D1)", ok,
            f"σ(0.01, 0.1) = {s001:.3f} dex; tan α·x^(1/4) = {rise[0]:.3f}, {rise[1]:.3f}, {rise[2]:.4f}", kind="CHART")

    # G3 [chart] wide binaries in the Galactic field g_ext = 1.8 a₀ (a 1.5 M_⊙ pair, the collinear estimate): the enhancement
    #    √ν − 1 = 11.5 %, 14.9 %, 16.0 % at 10, 20, 40 kAU — the paper's 12–16 %; the arguments y = (g_b + g_ext)/a₀ = 2.65, 2.01, 1.85
    wb = CD.wide_binaries()
    ok = all(_within(r[4], c, "0.05") for r, c in zip(wb, ("11.53", "14.86", "15.96")))
    ok &= all(_within(r[2], c, "0.0005") for r, c in zip(wb, ("2.6535", "2.0134", "1.8533")))
    ok &= all(Q(a[4]) < Q(b[4]) for a, b in zip(wb[:-1], wb[1:])) and all(10 < r[4] < 30 for r in wb)
    # 32:P3 (p32040)
    R.check("G3", "[chart] wide binaries follow g_b ν((g_b + g_ext)/a₀) with the global a₀ and the Galactic field 1.8 a₀: a 1.5 M_⊙ "
            "pair at 10, 20, 40 kAU (g_b/a₀ = 0.85, 0.21, 0.053) has y = 2.65, 2.01, 1.85 and a velocity enhancement √ν − 1 of "
            "11.5 %, 14.9 %, 16.0 % (the paper's 12–16 % on the collinear estimate), rising with separation, inside the 10–30 % "
            "band; the exponential knee distinct from the Newtonian and rational forms", ok,
            "; ".join(f"{r[0]} kAU: y = {r[2]:.4f}, {r[4]:.1f} %" for r in wb), kind="CHART")

    # G4 [chart] the pressure-supported offset log₁₀ √w, w = 1/(1 + (σ_v/v)²): −0.0485 dex at σ_v/v = 0.5 and −0.1505 at 1
    o1, o2 = CD.coherence_offsets()
    ok = _within(o1, "-0.04846", "0.00005") and _within(o2, "-0.15051", "0.00005") and Q(o1) < 0 and Q(o2) < Q(o1)
    # 32:P4 (p32041)
    R.check("G4", "[chart] pressure-supported systems lie below the cold-disk relation by the coherence factor √w with "
            "w = 1/(1 + (σ_v/v)²): log₁₀√w = −0.0485 dex at σ_v/v = 0.5 and −0.1505 dex at σ_v/v = 1 (the paper's 0.05–0.15 dex), "
            "the offset growing with the dispersion ratio; cold disks lose under 1 %", ok, f"{o1:.4f}, {o2:.4f} dex", kind="CHART")

    # G5 [chart] the one-variable law: g_obs = g_b ν(g_b/a₀) with one global a₀ is strictly increasing in g_b (x ν(x) rising on a
    #    2001-point log grid 10⁻⁴..10⁴) — one registered acceleration fixes one baryonic acceleration, no second component (X11),
    #    no direction or environment in the law once the external field is in the argument (P6); the one global a₀ fits the binned
    #    SPARC relation: 17 bins of 0.2 dex, the exponential form's free a₀ = 1.17 × 10⁻¹⁰ within 3 % of g_† and 12–13 % above
    #    the floor, its χ² below the rational form's, every bin of 2 < x < 10 within its scatter
    mono = CD.monotone_grid()
    nb, a_e, c_e, a_s, c_s, ratio, worst, be, bs, ce0, cs0 = CD.binned_shape()
    ok = mono and nb == 17 and _between(a_e, "1.16e-10", "1.18e-10") and _within(Q(a_e) / Q(CH.A0_FIT[0]), 1, "0.03")
    ok &= _between(Q(a_e) / Q(CD.floor()), "1.12", "1.13") and _between(ratio, "0.88", "0.89") and Q(c_e) < Q(c_s) and Q(be) < Q(bs)
    ok &= Q(worst) < 1 and Q(ce0) < Q(cs0)
    # 32:X11 (p32037), 32:P6 (p32043)
    R.check("G5", "[chart] the dark sector adds no particle and the scale is global and isotropic: the registered acceleration "
            "g_b ν(g_b/a₀) is a strictly increasing function of g_b with the one global a₀ (x ν(x) rising on a 2001-point grid over "
            "10⁻⁴ < x < 10⁴), so one registered acceleration fixes one baryonic acceleration with no room for a second component, "
            "and no direction or environment enters once the external field is in the argument; one a₀ fits the binned SPARC "
            "relation (17 bins of 0.2 dex): the exponential form's free a₀ = 1.17 × 10⁻¹⁰ lies within 3 % of g_† and 12.5 % above "
            "the floor (floor/fit 0.89), its χ² below the rational form's at the fixed floor and free, every bin of 2 < x < 10 "
            "within its scatter", ok,
            f"monotone {mono}; free a₀ {a_e:.3e} (χ² {c_e:.2f} vs {c_s:.2f}), floor/fit {ratio:.3f}, worst band departure {worst:.2f}σ", kind="CHART")


# ------------------------------------------------------------------------------------------------------------
# block Z: the Ω-hard reading (32:Z1)
@R.block("Z", BLOCK["Z"])
def block_Z():
    """Block Z — the Ω-hard reading: Z1 exact."""
    # Z1 the cross-scale running a₀(d)/a₀(carrier) = (Ω − 1)/d on the laboratory Carrier Ω = 2 408 561: Ω − 1 = 2⁴·5·7·11·17·23 has
    #    160 divisors, every ratio (Ω − 1)/d an integer with d·((Ω − 1)/d) = Ω − 1, the ratios running from 1 to Ω − 1; the
    #    certificate closes at carrier scale only (master Z7), the value at Ω ∼ 10¹²³ Ω-hard
    n = D.CARRIER - 1
    fac, divs, ratios = D.divisor_lattice(n)
    ok = fac == {2: 4, 5: 1, 7: 1, 11: 1, 17: 1, 23: 1} and len(divs) == 160 and divs[0] == 1 and divs[-1] == n
    ok &= all(d * r == n for d, r in zip(divs, ratios)) and ratios == sorted(ratios, reverse=True) and len(set(divs)) == 160
    ok &= all(n % d == 0 for d in divs)
    # 32:Z1 (p32047)
    R.check("Z1", "the cross-scale running a₀(d)/a₀(carrier) = (Ω − 1)/d on the laboratory Carrier Ω = 2 408 561: Ω − 1 = 2⁴·5·7·11·17·23 "
            "has 160 divisors, each ratio (Ω − 1)/d an exact integer, the lattice running from 1 at d = Ω − 1 to Ω − 1 at d = 1; "
            "the uniform certificate closes at carrier scale only (master Z7), the value at Ω ∼ 10¹²³ Ω-hard", ok,
            f"Ω − 1 = {n} = 2⁴·5·7·11·17·23, {len(divs)} divisors, ratios {ratios[0]} … {ratios[-1]}")


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)
