src/6-fourier — fourier.py

The validation package of Scale-Shift and Fractional Fourier Transform as Rotations over Finite Holographic Substrate: one script, fourier.py, 4 blocks, Python with numpy>=1.24, one check per predicate of the paper's predicate ledger — 31 of 31 checks passing. The script is rendered below with an anchor per line; its markers (# 6:B1 (p06008): the predicate and its key) are the checks the ledger predicates cite, and the block index opens each block at its definition. The notebook frc-6-fourier.ipynb runs one cell per predicate on Google Colab (its generator make_notebook.py). Installed from this site as a named requirement: pip install frc-6-fourier --find-links https://finitering.space/pkg/ (the sdist frc-6-fourier-20261012.tar.gz).

Blocks: A (6) · B (9) · C (4) · D (8) — the predicates each decides in parentheses.

6-fourier ledgersrc/6-fourier/fourier.py · 52.6 KBfourier.pyColab
1"""2fourier.py — the validation package of "Scale-Shift and Fractional Fourier Transform as Rotations over Finite Holographic3Substrate" (Akhtman, 2026; doi 10.20944/preprints202606.0127.v1), the paper 6-fourier of the FRC corpus4(finite-ring-space/src/6-fourier), added with the paper's predicate ledger (13 September 2026; one script since524 September 2026, the five block scripts merged; the entropy block retired with the revision of 9 October 2026, reports/entropy-20261008.md of the paper).6========================================================================================================================78One script, four blocks, thirty-one checks, numpy. Each check names the predicate(s) of the9paper's ledger it witnesses (LEDGER below; predicates cited as 6:XN) under a `# 6:XN (<key>)` marker, and the ledger's10source column links the marker in return (finitering.space/src/6-fourier/#<key>). The paper \\label(s) a11check decides are in the block banners. Three master-ledger predicates of the corpus are reached through the paper's:1200:C2 (6:B5, 6:C3, 6:D4), 00:C14 (6:B2), 00:C7 on the transform layer (6:C9).1314    python3 fourier.py            every block, results.json written; exit 1 if a check fails (≈ 5 s)15    python3 fourier.py D          one block (A, B, C or D); no results.json16    from frc_6_fourier import predicate; predicate("6:C3")     one predicate: its block runs once per session1718Blocks:  A  the frame datum and the shell Fourier operator     EXACT            (6:B1–B3, B5–B7)19         B  the fractional family F^[s]                        EXACT            (6:C2–C9, C11)20         C  representation domains and the coordinate zoom     EXACT            (6:D1, D2, D4, D7)21         D  the Weil dictionary, the operator-level comparison EXACT            (6:E2, E3, E5–E10)2223Everything the blocks share:24  * the frame datum of a shell: p = 4κ+1, the smallest primitive root g (the generators of Table `tab:checks`),25    the oriented quarter-turn i = −g^κ, π = 2κ, e = g^i;26  * exact matrix arithmetic over F_p (numpy int64, reduced mod p after every product);27  * the shell Fourier matrix W_{kj} = g^{jk}, the reversal J, the normalised operator F = iW, the four projectors Π_ℓ,28    the fractional family F^[s] = Σ_ℓ g^{−ℓs} Π_ℓ, rank mod p;29  * the PASS/FAIL registry every block reports into (results.json).3031Kinds: every check is EXACT, an integer-pinned computation in F_p (a pass is a proof on the tested instances). The32[approx] checks of the retired block E, the cyclotomic observer readout on C^n, are kept with the paper's entropy report33(_to_delete/fourier-pre-rewrite-20261009.py).34"""35import os, json, sys, re36import numpy as np3738SCRIPT = os.path.splitext(os.path.basename(__file__))[0]        # "fourier": the one script, the name results.json and the site pages carry3940# The shells of Table tab:checks (p, κ, g, i); the package recomputes g and i and checks the table.41TABLE = [(5, 1, 2, 3), (13, 3, 2, 5), (17, 4, 3, 4), (29, 7, 2, 17), (37, 9, 2, 6), (41, 10, 6, 9)]42SHELLS = [p for p, _, _, _ in TABLE]4344# ----------------------------------------------------------------------------- registry45RESULTS = []4647# The paper's predicate ledger (Appendix A, predicates cited as 6:XN): the predicate(s) each check witnesses.48LEDGER = {49    "A1": "6:B1", "A2": "6:B2", "A3": "6:B3", "A4": "6:B5", "A5": "6:B6", "A6": "6:B7",50    "B1": "6:C2", "B2": "6:C3", "B3": "6:C3", "B4": "6:C4", "B5": "6:C5", "B6": "6:C6", "B7": "6:C7", "B8": "6:C7",51    "B9": "6:C8, 6:C11", "B10": "6:C9",52    "C1": "6:D1", "C2": "6:D2", "C3": "6:D2, 6:D7", "C4": "6:D4", "C5": "6:D4", "C6": "6:D4",53    "D1": "6:E2", "D2": "6:E2", "D3": "6:E3", "D4": "6:E5, 6:E9", "D5": "6:E6", "D6": "6:E7", "D7": "6:E8", "D8": "6:E8", "D9": "6:E10",54}55# The master-ledger predicates of the corpus witnessed through the paper's: 00:C2 (6:B5, 6:C3, 6:D4), 00:C14 (6:B2),56# 00:C7 on the transform layer (6:C9).5758BLOCK = {"A": "the frame datum and the shell Fourier operator",          # check-id prefix -> the block (the function block_<letter> below)59         "B": "the fractional family F^[s]",60         "C": "representation domains and the coordinate zoom",61         "D": "the Weil dictionary and the operator-level comparison"}6263# the deciding check of each witnessed predicate: the one whose verdict decides the predicate's statement (the other checks64# that touch it are corroboration, listed by predicate() from the records): the first check of a two-check predicate, except65# E2 (D2, the isomorphism and the count; D1's membership corroborates) and E8 (D8, the theorem's row-0 argument; D7, the sweep on66# the six shells, is its instance)67PREDICATES = {68    "6:B1": "A1", "6:B2": "A2", "6:B3": "A3", "6:B5": "A4", "6:B6": "A5", "6:B7": "A6",69    "6:C2": "B1", "6:C3": "B2", "6:C4": "B4", "6:C5": "B5", "6:C6": "B6", "6:C7": "B7", "6:C8": "B9", "6:C9": "B10", "6:C11": "B9",70    "6:D1": "C1", "6:D2": "C2", "6:D4": "C4", "6:D7": "C3",71    "6:E2": "D2", "6:E3": "D3", "6:E5": "D4", "6:E6": "D5", "6:E7": "D6", "6:E8": "D8", "6:E9": "D4", "6:E10": "D9",72}73_RAN = set()                                            # blocks already run in this session (predicate() runs each once)7475def check(pid, label, ok, detail="", kind="EXACT"):76    """Record one predicate check. pid = package check id; LEDGER[pid] = the paper statement(s) decided."""77    ok = bool(ok)78    rows = LEDGER.get(pid, "")79    RESULTS.append({"id": pid, "rows": rows, "block": pid[0], "script": SCRIPT, "label": label, "ok": ok, "detail": detail, "kind": kind})80    print(f"  [{'PASS' if ok else 'FAIL'}] {pid:4s} {kind:7s} [{rows}] {label}" + (f"  --  {detail}" if detail else ""))81    return ok8283def summary(write=True):84    n_ok = sum(r["ok"] for r in RESULTS)85    print(f"\nSUMMARY: {n_ok}/{len(RESULTS)} checks passed" + ("" if n_ok == len(RESULTS) else "  <-- FAILURES"))86    if write:87        with open("results.json", "w") as f:88            json.dump(RESULTS, f, indent=1)89    return n_ok == len(RESULTS)9091def markers():92    """predicate label -> (script file, line) of its marker `# <paper>:<label> (<key>)`: the line of the check that decides it."""93    out = {}94    for i, line in enumerate(open(os.path.abspath(__file__), encoding="utf-8"), 1):95        m = re.match(r"\s*# ((?:\d+:[A-Z]+\d+[a-z]?(?: \(p\d{5}\))?)(?:, \d+:[A-Z]+\d+[a-z]?(?: \(p\d{5}\))?)*)\s*$", line)96        if m:97            for lab in re.findall(r"\d+:[A-Z]+\d+[a-z]?", m.group(1)): out.setdefault(lab, (SCRIPT + ".py", i))98    return out99100def _run_block(letter):101    if letter not in _RAN:102        globals()[f"block_{letter}"](); _RAN.add(letter)103104def predicate(label, lines=14):105    """Verify one ledger predicate: run the block of the check that decides it (once per session), print that check's source106    (from its marker) and every record that cites the predicate, and return True iff all pass."""107    pid = PREDICATES.get(label)108    if pid is None:109        print(f"{label}: no python witness (see the predicate's Lean witness or its source)"); return None110    citing = {i[0] for i, rows in LEDGER.items() if label in [t.strip() for t in rows.split(",")]}111    for b in sorted({pid[0]} | citing): _run_block(b)          # the deciding block and every block whose checks cite the predicate112    mk = markers().get(label)113    if mk:114        src = open(os.path.abspath(__file__), encoding="utf-8").read().split("\n")115        print(f"— {mk[0]}:{mk[1]} (the check that decides {label}: {pid})")116        for j in range(mk[1] - 1, min(mk[1] - 1 + lines, len(src))): print(f"{j + 1:5d}  {src[j]}")117    recs = [r for r in RESULTS if label in [t.strip() for t in r["rows"].split(",")]]118    ok = all(r["ok"] for r in recs)119    for r in recs:120        role = "(deciding)" if r["id"] == pid else "(corroborating)"121        print(f"  [{'PASS' if r['ok'] else 'FAIL'}] {r['id']:4s} {role:16s} {r['detail'][:150]}")122    print(f"{label}: {'VERIFIED' if ok and recs else 'FAILED'} — {len(recs)} record(s)")123    return ok124125def verify_all():126    """Run every block (those already run in this session are not re-run) and print the summary; True iff every check passed."""127    for b in sorted(BLOCK): _run_block(b)128    return summary(write=False)129130# ----------------------------------------------------------------------------- the frame datum131def prime_factors(n):132    f, d = set(), 2133    while d * d <= n:134        while n % d == 0:135            f.add(d); n //= d136        d += 1137    if n > 1: f.add(n)138    return f139140def order(a, p):141    o, x = 1, a % p142    while x != 1:143        x = x * a % p; o += 1144    return o145146def primitive_root(p):147    """The smallest primitive root of F_p (the generators of Table tab:checks)."""148    for g in range(2, p):149        if all(pow(g, (p - 1) // q, p) != 1 for q in prime_factors(p - 1)):150            return g151152def primitive_roots(p):153    return [g for g in range(2, p) if order(g, p) == p - 1]154155class Frame:156    """The framed shell F_p(t; 0, 1, g): p = 4κ+1, g primitive, i = −g^κ (the oriented quarter-turn,157    clockwise phase convention eq:it-def), π = 2κ, e = g^i, n = p−1 = 4κ."""158    def __init__(self, p, g=None):159        assert p % 4 == 1160        self.p, self.n, self.kap = p, p - 1, (p - 1) // 4161        self.g = primitive_root(p) if g is None else g162        assert order(self.g, p) == p - 1163        self.i = (-pow(self.g, self.kap, p)) % p164        self.pi = 2 * self.kap165        self.e = pow(self.g, self.i, p)166        self.inv2 = pow(2, p - 2, p)167        self.inv4 = pow(4, p - 2, p)168        self._W = self._F = self._Pi = None169170    def conjugate(self):171        """The conjugate reframing (g, i) ↦ (g⁻¹, −i)."""172        return Frame(self.p, pow(self.g, self.p - 2, self.p))173174    def gpow(self, k):175        return pow(self.g, int(k) % self.n, self.p)176177    # --- matrices over F_p (int64, entries in [0, p))178    @property179    def W(self):180        if self._W is None:181            self._W = np.array([[self.gpow(j * k) for j in range(self.n)] for k in range(self.n)], dtype=np.int64)   # W_{k,j} = g^{jk}182        return self._W183184    @property185    def F(self):186        if self._F is None:187            self._F = (self.i * self.W) % self.p188        return self._F189190    @property191    def J(self):192        return J_matrix(self.n)193194    def I(self):195        return np.eye(self.n, dtype=np.int64)196197    @property198    def Pi(self):199        """The four projectors Π_ℓ = ¼ Σ_{r=0}^{3} i^{−ℓr} F^r (eq:projector-def)."""200        if self._Pi is None:201            Fs = [self.I()]202            for _ in range(3):203                Fs.append(mm(Fs[-1], self.F, self.p))204            inv_i = pow(self.i, self.p - 2, self.p)205            self._Pi = []206            for ell in range(4):207                P = np.zeros((self.n, self.n), dtype=np.int64)208                for r in range(4):209                    P = (P + pow(inv_i, ell * r, self.p) * Fs[r]) % self.p210                self._Pi.append((self.inv4 * P) % self.p)211            self._Fpows = Fs212        return self._Pi213214    def Fpow(self, r):215        self.Pi216        return self._Fpows[r % 4]217218    def frft(self, s):219        """F^[s] = Σ_ℓ g^{−ℓ s} Π_ℓ (eq:FRC-FrFT-def), s ∈ Z_{4κ}."""220        M = np.zeros((self.n, self.n), dtype=np.int64)221        for ell, P in enumerate(self.Pi):222            M = (M + self.gpow(-ell * s) * P) % self.p223        return M224225    def mults(self):226        """(m_0, m_1, m_2, m_3) = rank Π_ℓ over F_p."""227        return tuple(rank_mod_p(P, self.p) for P in self.Pi)228229    def gauss(self):230        """The frame's exponent-cycle Gauss sum G = Σ_{k ∈ Z_{4κ}} g^{k²} (thm:multiplicity)."""231        return sum(self.gpow(k * k) for k in range(self.n)) % self.p232233    def epsilon(self):234        """The sign ε with G = ε(1+i), or None if G is neither."""235        G, onepi = self.gauss(), (1 + self.i) % self.p236        return 1 if G == onepi else (-1 if G == (-onepi) % self.p else None)237238    # --- coordinate side239    def meridian(self, m):240        """M_m = {a g^m : a ∈ I_p}, I_p = {0, …, π} (eq:meridian-def, eq:Ip-zoom), as the ordered tuple."""241        em = self.gpow(m)242        return tuple((a * em) % self.p for a in range(self.pi + 1))243244    def S(self, r, x):245        """The meridian-scale map S_r(x) = g^r x (def:scale-map)."""246        return (self.gpow(r) * x) % self.p247248    # --- the Weil side249    def z(self, s):250        return self.gpow(-s)                                       # z_s = g^{−s} (eq:zs-def)251252    def R(self, s):253        """R_s = [[c_s, −d_s], [d_s, c_s]], c_s = (z+z⁻¹)/2, d_s = (z−z⁻¹)/(2i) (eq:csds-def, eq:Rs-def)."""254        p, z = self.p, self.z(s)255        zi = pow(z, p - 2, p)256        c = ((z + zi) * self.inv2) % p257        d = ((z - zi) * self.inv2 * pow(self.i, p - 2, p)) % p258        return np.array([[c, (-d) % p], [d, c]], dtype=np.int64)259260# ----------------------------------------------------------------------------- matrix arithmetic mod p261def mm(A, B, p):262    return (A @ B) % p263264def J_matrix(n):265    J = np.zeros((n, n), dtype=np.int64)266    for k in range(n):267        J[k, (-k) % n] = 1268    return J269270def eq(A, B, p):271    return bool(np.array_equal(A % p, B % p))272273def rank_mod_p(M, p):274    A = (M % p).astype(np.int64).copy()275    n, m = A.shape276    r = 0277    for col in range(m):278        piv = next((i for i in range(r, n) if A[i, col] % p), None)279        if piv is None:280            continue281        A[[r, piv]] = A[[piv, r]]282        A[r] = (A[r] * pow(int(A[r, col]), p - 2, p)) % p283        for i in range(n):284            if i != r and A[i, col]:285                A[i] = (A[i] - A[i, col] * A[r]) % p286        r += 1287        if r == n:288            break289    return r290291def is_monomial(M):292    """Exactly one nonzero entry in every row and every column."""293    nz = (M != 0)294    return bool(np.all(nz.sum(0) == 1) and np.all(nz.sum(1) == 1))295296def matpow(M, k, p):297    R = np.eye(M.shape[0], dtype=np.int64)298    for _ in range(k):299        R = mm(R, M, p)300    return R301302# ------------------------------------------------------------------------------------------------------------303# Block A — the frame datum and the shell Fourier operator (EXACT, integer-pinned)304# ================================================================================305# Paper statements decided (Sections 3–4; master ledger rows 00:C2, 00:C14):306#307#   A1  §2 shell data, tab:checks   p = 4κ+1, the generator g of Table tab:checks is the smallest primitive308#                                    root, i = −g^κ = g^{−κ} = g^{3κ}, i² ≡ −1, π = 2κ, 2π ≡ −1, g^π ≡ −1,309#                                    −π ≡ 2⁻¹, e = g^i; the table's (κ, g, i) on all six shells310#   A2  §2 rem:euler                  e^{iπ} = g^{2κ(i mod 2)} ≡ −1 exactly when the quarter-turn residue i is311#       00:C14                       odd; the conjugate reframing (g, i) ↦ (g⁻¹, −i) toggles the parity, so312#                                    exactly one member of each conjugate pair carries e^{iπ} ≡ −1 — on every313#                                    primitive frame of the six shells; anchor F_13(t;0,1,2): i = 5, 6^{iπ} ≡ −1314#   A3  rem:gt-covariance            the relabelling g' = g^u, u ∈ Z_{4κ}^×: i' = i iff u ≡ 1 (mod 4), i' = −i315#                                    iff u ≡ 3 (mod 4); e' = g^{ui} ≠ e whenever i(u−1) ≢ 0 (mod 4κ), as at316#                                    p = 13, g = 2, u = 5: e' = 2 ≠ 6 = e317#   A4  lem:W-square, prop:F-cycle   W² = −J, (iW)² = J, (iW)⁴ = I on the six shells (the three boolean318#       tab:checks; 00:C2            columns of Table tab:checks)319#   A5  rem:unitary-norm             the square roots of 1/n = −1 in F_p are exactly ±i; (cW)² = J iff c = ±i320#   A6  lem:JF-decomp                WJ = JW, FJ = JF; dim V⁺ = 2κ+1, dim V⁻ = 2κ−1321#322# Shells: p = 5, 13, 17, 29, 37, 41 (Table tab:checks), every primitive frame of each for A2 and A3.323def block_A():324    """Block A — the frame datum and the shell Fourier operator (EXACT, integer-pinned): A1–A6."""325    print("block A — the frame datum and the shell Fourier operator")326    frames = {p: Frame(p) for p in SHELLS}327328    # A1 — the shell data and the table329    ok, rows = True, []330    for p, kap, g, i in TABLE:331        f = frames[p]332        ok &= (p == 4 * kap + 1 and f.kap == kap and f.g == g and f.i == i)333        ok &= (f.i == (-pow(g, kap, p)) % p == pow(g, p - 1 - kap, p) == pow(g, 3 * kap, p))334        ok &= (f.i * f.i % p == p - 1)335        ok &= (f.pi == 2 * kap and (2 * f.pi) % p == p - 1 and pow(g, f.pi, p) == p - 1)336        ok &= ((-f.pi) % p == f.inv2)337        ok &= (f.e == pow(g, i, p))338        rows.append(f"F_{p}(κ={kap}, g={g}, i={i}, e={f.e})")339    # 6:B1 (p06008)340    check("A1", "p = 4κ+1, g the smallest primitive root, i = −g^κ = g^{−κ}, i² ≡ −1, π = 2κ, 2π ≡ −1, g^π ≡ −1, −π ≡ 2⁻¹, e = g^i; Table tab:checks (κ, g, i)",341          ok, "; ".join(rows))342343    # A2 — the Euler identity on the odd member (00:C14)344    ok, n_frames, n_carry = True, 0, 0345    for p in SHELLS:346        for g in primitive_roots(p):347            f = Frame(p, g)348            euler = pow(f.e, f.i * f.pi, p)                       # e^{iπ} = (g^i)^{iπ}349            ok &= (euler == pow(g, f.pi * (f.i % 2), p))          # = g^{2κ (i mod 2)}350            ok &= ((euler == p - 1) == (f.i % 2 == 1))            # ≡ −1 iff i odd351            fc = f.conjugate()352            ok &= (fc.i == (-f.i) % p and fc.i % 2 != f.i % 2)    # the conjugate toggles the parity353            carries_c = pow(fc.e, fc.i * fc.pi, p) == p - 1354            ok &= ((euler == p - 1) != carries_c)                 # exactly one member of the pair355            n_frames += 1; n_carry += (euler == p - 1)356    f13 = frames[13]357    ok &= (f13.i == 5 and f13.e == 6 and pow(6, 5 * 6, 13) == 12 and pow(6, 6, 13) == 12)358    # 6:B2 (p06009)359    check("A2", "e^{iπ} = g^{2κ(i mod 2)} ≡ −1 exactly on the odd quarter-turn; the conjugate reframing toggles it, one member of each pair carries it",360          ok, f"{n_frames} primitive frames of p ∈ {SHELLS}, {n_carry} carry e^{{iπ}} ≡ −1 (one per conjugate pair); F_13(t;0,1,2): i = 5, e = 6, 6^{{30}} = 6^{{6}} ≡ −1")361362    # A3 — the u-relabelling363    ok = True364    for p in SHELLS:365        f = frames[p]366        for u in range(1, f.n):367            if np.gcd(u, f.n) != 1:368                continue369            fu = Frame(p, pow(f.g, u, p))370            ok &= (fu.i == f.i) if u % 4 == 1 else (fu.i == (-f.i) % p)371            if u % 4 == 1:372                ok &= (fu.e == pow(f.g, u * f.i, p))373                ok &= ((fu.e != f.e) == ((f.i * (u - 1)) % f.n != 0))374    f5 = Frame(13, pow(2, 5, 13))375    ok &= (f5.i == f13.i and f5.e == 2 and f13.e == 6 and pow(6, 5, 13) == 2)376    # 6:B3 (p06010)377    check("A3", "g' = g^u: the quarter-turn flips only on u ≡ 3 (mod 4); e' = g^{ui} ≠ e iff i(u−1) ≢ 0 (mod 4κ); at p = 13, u = 5: e' = 2 ≠ 6",378          ok, "every unit u of Z_{4κ} on the six shells; F_13, g' = 2^5 = 6: i' = 5, e' = 6^5 = 2")379380    # A4 — the operator identities of Table tab:checks (00:C2)381    ok, det = True, []382    for p in SHELLS:383        f = frames[p]384        W2 = mm(f.W, f.W, p); F2 = mm(f.F, f.F, p); F4 = mm(F2, F2, p)385        a, b, c = eq(W2, (-f.J) % p, p), eq(F2, f.J, p), eq(F4, f.I(), p)386        ok &= a and b and c387        det.append(f"p={p}: {a},{b},{c}")388    # 6:B5 (p06012)389    check("A4", "W² = −J, (iW)² = J, (iW)⁴ = I on the six shells of Table tab:checks", ok, "; ".join(det))390391    # A5 — the unitary normalisation read in the field392    ok = True393    for p in SHELLS:394        f = frames[p]395        roots = sorted(c for c in range(p) if c * c % p == p - 1)396        ok &= (roots == sorted([f.i, (-f.i) % p]))397        ok &= ((1 * pow(f.n, p - 2, p)) % p == p - 1)                        # 1/n = −1398        for c in range(1, p):399            ok &= (eq(mm(c * f.W % p, c * f.W % p, p), f.J, p) == (c in roots))400    # 6:B6 (p06013)401    check("A5", "the square roots of 1/n ≡ −1 in F_p are exactly ±i, the two unitary normalisations of W: (cW)² = J iff c = ±i", ok, f"every c ∈ F_p^× tested on p ∈ {SHELLS}")402403    # A6 — the symmetric/antisymmetric decomposition404    ok, det = True, []405    for p in SHELLS:406        f = frames[p]407        ok &= eq(mm(f.W, f.J, p), mm(f.J, f.W, p), p) and eq(mm(f.F, f.J, p), mm(f.J, f.F, p), p)408        dplus = f.n - rank_mod_p((f.J - f.I()) % p, p); dminus = f.n - rank_mod_p((f.J + f.I()) % p, p)409        ok &= (dplus == 2 * f.kap + 1 and dminus == 2 * f.kap - 1)410        det.append(f"p={p}: dim V⁺={dplus}, V⁻={dminus}")411    # 6:B7 (p06014)412    check("A6", "WJ = JW, FJ = JF; dim V⁺ = 2κ+1, dim V⁻ = 2κ−1", ok, "; ".join(det))413414# ------------------------------------------------------------------------------------------------------------415# Block B — the fractional family F^[s] = Σ_ℓ g^{−ℓs} Π_ℓ (EXACT, integer-pinned)416# ===============================================================================417# Paper statements decided (Section 5; master ledger rows 00:C2, 00:C7):418#419#   B1  lem:projectors        Π_ℓ² = Π_ℓ, Π_ℓ Π_m = 0 (ℓ ≠ m), Σ_ℓ Π_ℓ = I, F Π_ℓ = i^ℓ Π_ℓ420#   B2  thm:FRC-FrFT          additivity F^[s+r] = F^[s] F^[r] on every pair (s, r) ∈ Z_{4κ}²      (00:C2)421#   B3  thm:FRC-FrFT          cardinal values F^[0] = I, F^[κ] = F, F^[2κ] = J, F^[3κ] = F⁻¹, F^[4κ] = I;422#                             (F^[1])^κ = F                                                     (00:C2)423#   B4  thm:faithful          s ↦ F^[s] injective on Z_{4κ} (p = 5 included: the surviving odd projector424#                             carries a faithful character)425#   B5  lem:multiplicity      Π_0 + Π_2 = ½(I + J), Π_1 + Π_3 = ½(I − J); (Π_0)_{00}, (Π_2)_{00} ≠ 0; for κ ≥ 2426#                             (Π_1)_{21} = ¼(g² − g⁻²) = −(Π_3)_{21} ≠ 0; the ranks m_ℓ = rank Π_ℓ = dim ker(F − i^ℓ I),427#                             m_0 + m_2 = 2κ+1, m_1 + m_3 = 2κ−1; at p = 5 exactly one of Π_1, Π_3 is 0428#   B6  rem:multiplicities    p = 13: g = 2 gives (3,3,4,2) with Tr F = 4, g = 6 gives (4,2,3,3) with Tr F = 9;429#                             the site relabelling m ↦ um conjugates F(g) to F(g^{u²}) by a permutation430#   B7  thm:multiplicity      G = Σ_k g^{k²} = ε(1+i); the two patterns (κ,κ,κ+1,κ−1) / (κ+1,κ−1,κ,κ);431#                             ε(g⁻¹) = −ε(g); the 38 primitive frames of p ∈ {5,13,17,29,37} (and the 16 of432#                             p = 41); the table frames with κ ≥ 2 in class ε = +1; p = 5: (2,0,1,1) at g = 2433#                             (ε = −1), (1,1,2,0) at g = 3 (ε = +1). (The Jacobi law ε(g^u) = (κ/u) ε(g), the434#                             retired row C10, is no longer checked: it is a statement of no row.)435#   B8  thm:multiplicity      the proof's identities: G G* = −2, G² = 2i, Tr F = iG, Tr F² = 2, Tr F³ = iG*,436#       (proof)               m_ℓ ≡ ¼ Σ_r i^{−ℓr} Tr F^r (mod p)437#   B9  rem:classification    every exponent lift a_ℓ ≡ ℓ (mod 4) is additive with the same cardinal438#                             skeleton; the family canonical in the chart g^u with u² ≢ 1 (mod 4κ) does not439#                             commute with F — at p = 29, u = 5 (u² = 25 ≢ 1 mod 28)440#   B10 rem:gt-covariance     the conjugate reframing (g, i) ↦ (g⁻¹, −i): operator relations, cardinal441#       00:C7 (transform      values, additivity and faithfulness hold on the conjugate frame, while the442#       layer)                multiplicity tuple flips between the two patterns (chart data); exactly443#                             F' = −F⁻¹ and Π'_ℓ = Π_{ℓ+2}444#445# Shells: p = 5, 13, 17, 29, 37, 41; every primitive frame for B7.446def block_B():447    """Block B — the fractional family F^[s] = Σ_ℓ g^{−ℓs} Π_ℓ (EXACT, integer-pinned): B1–B10."""448    print("block B — the fractional family")449    frames = {p: Frame(p) for p in SHELLS}450451    # B1 — the projectors452    ok = True453    for p in SHELLS:454        f = frames[p]; Pi = f.Pi455        S = np.zeros((f.n, f.n), dtype=np.int64)456        for l in range(4):457            S = (S + Pi[l]) % p458            ok &= eq(mm(Pi[l], Pi[l], p), Pi[l], p)459            ok &= eq(mm(f.F, Pi[l], p), pow(f.i, l, p) * Pi[l], p)460            for m in range(4):461                if m != l:462                    ok &= eq(mm(Pi[l], Pi[m], p), np.zeros_like(S), p)463        ok &= eq(S, f.I(), p)464    # 6:C2 (p06016)465    check("B1", "Π_ℓ² = Π_ℓ, Π_ℓ Π_m = 0, Σ Π_ℓ = I, F Π_ℓ = i^ℓ Π_ℓ", ok, f"p ∈ {SHELLS}")466467    # B2 — additivity on every pair468    ok, npairs = True, 0469    for p in SHELLS:470        f = frames[p]471        fam = [f.frft(s) for s in range(f.n)]472        for s in range(f.n):473            for r in range(f.n):474                ok &= eq(mm(fam[s], fam[r], p), fam[(s + r) % f.n], p); npairs += 1475        f._fam = fam476    # 6:C3 (p06017)477    check("B2", "F^[s+r] = F^[s] F^[r] on every pair (s, r) of Z_{4κ}", ok, f"{npairs} pairs over p ∈ {SHELLS}")478479    # B3 — cardinal values480    ok = True481    for p in SHELLS:482        f = frames[p]; fam = f._fam; k = f.kap483        F3 = matpow(f.F, 3, p)484        ok &= eq(fam[0], f.I(), p) and eq(fam[k], f.F, p) and eq(fam[2 * k], f.J, p) and eq(fam[3 * k], F3, p)485        ok &= eq(mm(F3, f.F, p), f.I(), p)                       # F³ = F⁻¹486        ok &= eq(matpow(fam[1], k, p), f.F, p)487    check("B3", "F^[0] = I, F^[κ] = F, F^[2κ] = J, F^[3κ] = F⁻¹, F^[4κ] = I; (F^[1])^κ = F", ok, f"p ∈ {SHELLS}")488489    # B4 — faithfulness490    ok = True491    for p in SHELLS:492        f = frames[p]; fam = f._fam493        ok &= all(not eq(fam[s], f.I(), p) for s in range(1, f.n))494        ok &= len({fam[s].tobytes() for s in range(f.n)}) == f.n495    # 6:C4 (p06018)496    check("B4", "s ↦ F^[s] is injective on Z_{4κ}: the 4κ members are pairwise distinct (p = 5 included)", ok, f"p ∈ {SHELLS}")497498    # B5 — the multiplicity lemma: the projector sums, the named entries, the ranks499    ok, det = True, []500    for p in SHELLS:501        f = frames[p]; m = f.mults(); half = pow(2, p - 2, p)502        ok &= eq((f.Pi[0] + f.Pi[2]) % p, (half * (f.I() + f.J)) % p, p) and eq((f.Pi[1] + f.Pi[3]) % p, (half * (f.I() - f.J)) % p, p)503        ok &= (int(f.Pi[0][0, 0]) % p != 0 and int(f.Pi[2][0, 0]) % p != 0)504        if f.kap >= 2:505            e21 = f.inv4 * (f.gpow(2) - f.gpow(-2)) % p506            ok &= (e21 != 0 and int(f.Pi[1][2, 1]) % p == e21 and int(f.Pi[3][2, 1]) % p == (-e21) % p)507        for l in range(4):508            ok &= (m[l] == f.n - rank_mod_p((f.F - pow(f.i, l, p) * f.I()) % p, p))509        ok &= (m[0] + m[2] == 2 * f.kap + 1 and m[1] + m[3] == 2 * f.kap - 1 and m[0] >= 1 and m[2] >= 1)510        ok &= (m[1] >= 1 and m[3] >= 1) if f.kap >= 2 else ((m[1] == 0) != (m[3] == 0))511        det.append(f"p={p}: {m}")512    # 6:C5 (p06019)513    check("B5", "Π_0+Π_2 = ½(I+J), Π_1+Π_3 = ½(I−J); (Π_0)_{00}, (Π_2)_{00} ≠ 0; κ ≥ 2: (Π_1)_{21} = ¼(g²−g⁻²) = −(Π_3)_{21} ≠ 0; m_ℓ = rank Π_ℓ = dim ker(F − i^ℓ I), m_0+m_2 = 2κ+1, m_1+m_3 = 2κ−1; p = 5: one odd projector vanishes", ok, "; ".join(det))514515    # B6 — multiplicities are chart data516    f2, f6 = Frame(13, 2), Frame(13, 6)517    ok = (f2.mults() == (3, 3, 4, 2) and f6.mults() == (4, 2, 3, 3))518    ok &= (int(np.trace(f2.F)) % 13 == 4 and int(np.trace(f6.F)) % 13 == 9)519    ok &= (pow(2, 5, 13) == 6)                                    # same orientation class: 6 = 2^5, 5 ≡ 1 (mod 4)520    nconj = 0521    for p in SHELLS:522        f = frames[p]523        for u in range(1, f.n):524            if np.gcd(u, f.n) != 1:525                continue526            fu = Frame(p, pow(f.g, u * u, p))527            perm = [(u * k) % f.n for k in range(f.n)]528            ok &= eq(fu.F, f.F[np.ix_(perm, perm)], p); nconj += 1529    # 6:C6 (p06020)530    check("B6", "p = 13: g = 2 gives (3,3,4,2), Tr F = 4; g = 6 gives (4,2,3,3), Tr F = 9; m ↦ um carries F(g) to F(g^{u²}) by a permutation", ok, f"{nconj} relabellings over p ∈ {SHELLS}")531532    # B7 — the multiplicity dichotomy on every primitive frame533    ok, det, n38 = True, [], 0534    for p in SHELLS:535        f0 = frames[p]; k = f0.kap536        prims = primitive_roots(p)537        eps = {}538        for g in prims:539            f = Frame(p, g); e = f.epsilon()540            ok &= (e is not None)541            eps[g] = e542            want = (k, k, k + 1, k - 1) if e == 1 else (k + 1, k - 1, k, k)543            ok &= (f.mults() == want)544        for g in prims:545            ok &= (eps[pow(g, p - 2, p)] == -eps[g])                                     # conjugate law546        if k >= 2:547            ok &= (eps[f0.g] == 1)                                                       # the table frames548        if p != 41:549            n38 += len(prims)550        det.append(f"p={p}: {len(prims)} frames, ε=+1 on {sum(1 for g in prims if eps[g] == 1)}")551    ok &= (n38 == 38)552    ok &= (Frame(5, 2).mults() == (2, 0, 1, 1) and Frame(5, 2).epsilon() == -1)553    ok &= (Frame(5, 3).mults() == (1, 1, 2, 0) and Frame(5, 3).epsilon() == 1)554    # 6:C7 (p06021)555    check("B7", "G = ε(1+i), the two patterns, ε(g⁻¹) = −ε(g); 38 frames of p ∈ {5,…,37} and 16 of p = 41; the table frames with κ ≥ 2 in class ε = +1; p = 5: (2,0,1,1) at g = 2, (1,1,2,0) at g = 3",556          ok, "; ".join(det))557558    # B8 — the proof's identities559    ok = True560    for p in SHELLS:561        for g in primitive_roots(p):562            f = Frame(p, g)563            G = f.gauss(); Gs = sum(f.gpow(-k * k) for k in range(f.n)) % p564            ok &= (G * Gs % p == p - 2 and G * G % p == 2 * f.i % p)565            tr = [int(np.trace(f.Fpow(r))) % p for r in range(4)]566            ok &= (tr[1] == f.i * G % p and tr[2] == 2 and tr[3] == f.i * Gs % p)567            m = f.mults()568            inv_i = pow(f.i, p - 2, p)569            for l in range(4):570                ok &= (m[l] % p == f.inv4 * sum(pow(inv_i, l * r, p) * tr[r] for r in range(4)) % p)571    check("B8", "G G* = −2, G² = 2i, Tr F = iG, Tr F² = 2, Tr F³ = iG*, m_ℓ ≡ ¼ Σ_r i^{−ℓr} Tr F^r (mod p)", ok, "every primitive frame of the six shells")572573    # B9 — classification: exponent lifts and the non-commuting chart574    f = frames[13]; ok = True575    for a in [(0, 1, 2, 3), (0, 5, 2, 3), (4, 1, 6, 7), (0, 1, 2, 11)]:576        U = [sum(f.gpow(-a[l] * s) * f.Pi[l] for l in range(4)) % 13 for s in range(12)]577        ok &= all(eq(mm(U[s], U[r], 13), U[(s + r) % 12], 13) for s in range(12) for r in range(12))578        ok &= eq(U[0], f.I(), 13) and eq(U[3], f.F, 13) and eq(U[6], f.J, 13) and eq(U[9], matpow(f.F, 3, 13), 13)579    f29 = frames[29]; f29u = Frame(29, pow(f29.g, 5, 29))580    ok &= (25 % 28 != 1)581    noncomm = not eq(mm(f29u.frft(1), f29.F, 29), mm(f29.F, f29u.frft(1), 29), 29)582    ok &= noncomm583    scan = []584    for p in SHELLS:585        f0 = frames[p]586        for u in range(1, f0.n):587            if np.gcd(u, f0.n) == 1 and (u * u) % f0.n != 1:588                fu = Frame(p, pow(f0.g, u, p))589                scan.append((p, u, not eq(mm(fu.frft(1), f0.F, p), mm(f0.F, fu.frft(1), p), p)))590    ok &= all(x[2] for x in scan)                                                          # every such chart of the six shells (6:C11)591    # 6:C8 (p06022), 6:C11 (p06052)592    check("B9", "exponent lifts a_ℓ ≡ ℓ (mod 4) are additive with the cardinal skeleton (p = 13); the chart g^5 at p = 29 (u² ≢ 1 mod 28) does not commute with F, nor does any chart with u² ≢ 1 (mod 4κ) on the six shells",593          ok, f"non-commuting at p = 29, u = 5: {noncomm}; all charts with u² ≢ 1 (mod 4κ) on the six shells non-commuting: {all(x[2] for x in scan)} ({len(scan)} charts)")594595    # B10 — the conjugate reframing (00:C7, transform layer)596    ok, det = True, []597    for p in SHELLS:598        f = frames[p]; fc = f.conjugate(); k = f.kap599        ok &= (fc.i == (-f.i) % p)600        Finv = matpow(f.F, 3, p)601        ok &= eq(fc.F, (-Finv) % p, p)                                             # F' = −F⁻¹602        ok &= eq(mm(fc.F, fc.F, p), f.J, p) and eq(matpow(fc.F, 4, p), f.I(), p)603        famc = [fc.frft(s) for s in range(f.n)]604        ok &= eq(famc[0], f.I(), p) and eq(famc[k], fc.F, p) and eq(famc[2 * k], f.J, p)605        ok &= all(eq(mm(famc[s], famc[r], p), famc[(s + r) % f.n], p) for s in range(f.n) for r in range(0, f.n, 3))606        ok &= len({M.tobytes() for M in famc}) == f.n607        ok &= all(eq(fc.Pi[l], f.Pi[(l + 2) % 4], p) for l in range(4))                 # Π'_ℓ = Π_{ℓ+2}608        m, mc = f.mults(), fc.mults()609        ok &= (mc == (m[2], m[3], m[0], m[1]) and {m, mc} == {(k, k, k + 1, k - 1), (k + 1, k - 1, k, k)})610        det.append(f"p={p}: {m} ↦ {mc}")611    # 6:C9 (p06023)612    check("B10", "the conjugate frame (g⁻¹, −i) keeps the operator relations, cardinal values, additivity and faithfulness; its multiplicity tuple is the other pattern; F' = −F⁻¹, Π'_ℓ = Π_{ℓ+2}",613          ok, "; ".join(det))614615# ------------------------------------------------------------------------------------------------------------616# Block C — representation domains and the coordinate-side zoom (EXACT, integer-pinned)617# =====================================================================================618# Paper statements decided (Sections 4–5 of the revision of 9 October 2026; master ledger row 00:C2):619#620#   C1  def:domain            every F^[s] is invertible (rank 4κ over F_p); its eigenvalues g^{−ℓs} are621#                             nonzero, so the meridional bases B_s = F^[s] B_0 are bases622#   C2  thm:faithful          the 4κ framed (ordered) bases B_0, …, B_{4κ−1} are pairwise distinct623#   C3  rem:ordered-bases     B_{s+2κ} = B_s as unordered sets (F^[s+2κ] = F^[s] J, J a coordinate624#                             permutation) and B_{s+t} ≠ B_s for t ∉ {0, 2κ} (row 0 of F^[t] is (i/2)(1 − g^{−2t}) off625#                             site 0, so F^[t] is not monomial): the cycle carries exactly 2κ unordered bases626#   C4  prop:meridian-scale   S_r(M_m) = M_{m+r} for every (m, r) ∈ Z_{4κ}², as ordered lists  (00:C2)627#   C5  cor:effective-step    consecutive entries of M_m differ by g^m; S_{r+(p−1)} = S_r (A5)628#   C6  sec:examples          p = 13, g = 2: M_0 … M_3 as printed (steps 1, 2, 4, 8); the no-wrap window of629#       def:scale-chart       Definition scale-chart — with w = π = 6 the listing stays unwrapped for w·2^r < 13, i.e.630#                             r ≤ 1, and wraps from M_2 on (the ladder is D4's kernel instance since the revision)631#632# Shells: p = 5, 13, 17, 29, 37, 41.633def block_C():634    """Block C — representation domains and the coordinate-side zoom (EXACT, integer-pinned): C1–C6."""635    print("block C — representation domains and the coordinate-side zoom")636    frames = {p: Frame(p) for p in SHELLS}637638    # C1 — invertibility639    ok = True640    for p in SHELLS:641        f = frames[p]642        fam = [f.frft(s) for s in range(f.n)]; f._fam = fam643        ok &= all(rank_mod_p(M, p) == f.n for M in fam)644        ok &= all(f.gpow(-l * s) != 0 for s in range(f.n) for l in range(4))645    # 6:D1 (p06024)646    check("C1", "every F^[s] has full rank 4κ over F_p; the eigenvalues g^{−ℓs} are nonzero", ok, f"p ∈ {SHELLS}")647648    # C2 — the framed bases are pairwise distinct649    ok = True650    for p in SHELLS:651        f = frames[p]652        ordered = {tuple(map(tuple, M.T)) for M in f._fam}          # B_s = the ordered columns of F^[s]653        ok &= (len(ordered) == f.n)654    # 6:D2 (p06025)655    check("C2", "the 4κ framed bases B_s = F^[s] B_0 are pairwise distinct", ok, f"p ∈ {SHELLS}")656657    # C3 — unordered bases: the parity identification658    ok, det = True, []659    for p in SHELLS:660        f = frames[p]; k = f.kap661        ok &= all(eq(f._fam[(s + 2 * k) % f.n], mm(f._fam[s], f.J, p), p) for s in range(f.n))662        unordered = {frozenset(map(tuple, M.T)) for M in f._fam}663        ok &= (len(unordered) == 2 * k)664        bases = [frozenset(map(tuple, M.T)) for M in f._fam]665        ok &= all((bases[s] == bases[t]) == ((s - t) % (2 * k) == 0) for s in range(f.n) for t in range(f.n))   # B_s = B_t iff s ≡ t (mod 2κ)666        for t in range(f.n):                                                                         # rem:ordered-bases: row 0 of F^[t] off site 0667            if t in (0, 2 * k):668                continue669            val = f.i * f.inv2 * (1 - f.gpow(-2 * t)) % p                                            # (i/2)(1 − g^{−2t}) ≠ 0670            ok &= val != 0 and all(f._fam[t][0, kk] == val for kk in range(1, f.n)) and int(np.count_nonzero(f._fam[t][0])) >= 2671        det.append(f"p={p}: {f.n} framed, {len(unordered)} unordered")672    # 6:D7 (p06053)673    check("C3", "F^[s+2κ] = F^[s] J, so B_{s+2κ} = B_s as unordered bases, and B_{s+t} ≠ B_s for t ∉ {0,2κ}: every off-site entry of row 0 of F^[t] is (i/2)(1 − g^{−2t}) ≠ 0, F^[t] not monomial — 4κ framed domains, exactly 2κ measurement bases", ok, "; ".join(det))674675    # C4 — meridian-scale covariance676    ok, npairs = True, 0677    for p in SHELLS:678        f = frames[p]679        for m in range(f.n):680            Mm = f.meridian(m)681            for r in range(f.n):682                ok &= (tuple(f.S(r, x) for x in Mm) == f.meridian(m + r)); npairs += 1683    # 6:D4 (p06027)684    check("C4", "S_r(M_m) = M_{m+r} on every (m, r), as ordered lists", ok, f"{npairs} pairs over p ∈ {SHELLS}")685686    # C5 — the effective step and the periodicity687    ok = True688    for p in SHELLS:689        f = frames[p]690        for m in range(f.n):691            Mm = f.meridian(m)692            ok &= all((Mm[a + 1] - Mm[a]) % p == f.gpow(m) for a in range(f.pi))693        ok &= all(f.S(r + p - 1, x) == f.S(r, x) for r in range(f.n) for x in range(p))694    check("C5", "consecutive entries of M_m differ by the effective step g^m; S_{r+(p−1)} = S_r", ok, f"p ∈ {SHELLS}")695696    # C6 — the ladder at p = 13 and the no-wrap window697    f = frames[13]698    ladder = {0: (0, 1, 2, 3, 4, 5, 6), 1: (0, 2, 4, 6, 8, 10, 12), 2: (0, 4, 8, 12, 3, 7, 11), 3: (0, 8, 3, 11, 6, 1, 9)}699    ok = (f.g == 2 and f.i == 5 and f.pi == 6 and all(f.meridian(m) == ladder[m] for m in ladder))700    ok &= all(f.gpow(m) == 2 ** m for m in range(4))701    w = f.pi702    unwrapped = [m for m in range(f.n) if w * 2 ** m < 13]703    wraps = [m for m in range(4) if any(a * 2 ** m >= 13 for a in range(w + 1))]704    ok &= (unwrapped == [0, 1] and wraps == [2, 3])705    check("C6", "p = 13, g = 2: M_0…M_3 = the printed ladder at steps 1, 2, 4, 8; the no-wrap window w·g^r < p with w = π = 6 holds for r ≤ 1 and the listing wraps from M_2", ok, f"unwrapped meridians {unwrapped}, wrapping {wraps}")706707# ------------------------------------------------------------------------------------------------------------708# Block D — the Weil dictionary and the operator-level comparison (EXACT, integer-pinned)709# =======================================================================================710# Paper statements decided (Section 6 of the revision of 9 October 2026):711#712#   D1  prop:rotation-isom    c_s² + d_s² = 1 and det R_s = 1 for every s: R_s ∈ SO(2, F_p)713#   D2  prop:rotation-isom    s ↦ R_s is a homomorphism Z_{4κ} → SO(2, F_p), injective, onto: |SO(2, F_p)| = p−1714#   D3  thm:Weil-equivalence  the cardinal matrices R_0 = I, R_κ = w = [[0,−1],[1,0]] (the R_κ column of715#       tab:checks            Table tab:checks), R_{2κ} = −I, R_{3κ} = w⁻¹; z_κ = i716#   D4  prop:nogo             σ (the exponent shift) has the n = 4κ distinct eigenvalues F_p^×, each simple;717#                             F^[1] has at most four; for κ ≥ 2 the cyclic groups ⟨σ⟩, ⟨F^[1]⟩ of order 4κ718#                             are not conjugate719#   D5  prop:charsector       E_1 = im Π_1 ≠ 0 for κ ≥ 2; F^[s]|_{E_1} = g^{−s}; F^[s] T_v = T_v S_{−s} on every720#                             x ∈ F_p and s; R_s (1, −i)ᵀ = g^{−s} (1, −i)ᵀ721#   D6  prop:heisenberg       F σ F⁻¹ = D_1, F D_1 F⁻¹ = σ⁻¹ with D_1 = diag(g^k); F^r σ = σ_r F^r,722#                             (σ_0, σ_1, σ_2, σ_3) = (σ, D_1, σ⁻¹, D_1⁻¹); the expansion eq:conj-expansion723#                             F^[s] = Σ_r c_r(s) F^r with c_r(s) = ¼ Σ_ℓ (g^{rκ−s})^ℓ724#   D7  thm:monomial          the sweep on the six shells: F^[s] σ F^[s]⁻¹ monomial exactly at the four cardinal725#                             indices, non-monomial at every one of the 112 intermediate indices over726#                             p ∈ {13, 17, 29, 37, 41} (p = 5 has no intermediate index); E8's instance727#   D8  thm:monomial          cardinal exclusivity: off j ∈ {−1, 0, 1} row 0 of F^[s] σ F^[s]⁻¹ is x⁻¹ times a728#                             quadratic in x = g^j with leading coefficient i(c₀+c₂)c₃(−s) ≠ 0, so at least 4κ−5729#                             nonzero entries for every non-cardinal s; every shell p ≡ 1 (mod 4) below 200730#   D9  cor:boundary          the plane as orbits of the cycle: |SO(2, F_p)| = p−1 = n; F_p² is the origin and n+2 free731#                             orbits of the rotation group (the n circles x²+y² = c ≠ 0 and the two isotropic lines732#                             y = ±ix without the origin), p² = 1 + (n+2)n; R_s acts on u = x+iy, v = x−iy as733#                             (u, v) ↦ (z_s u, z_s⁻¹ v); dim V = n (the transforms are n×n)734#735# Shells: p = 5, 13, 17, 29, 37, 41 (D8: every shell below 200).736def shift(n):737    """(σ v)_k = v_{k−1}: the exponent-shift permutation matrix."""738    S = np.zeros((n, n), dtype=np.int64)739    for k in range(n):740        S[k, (k - 1) % n] = 1741    return S742743def block_D():744    """Block D — the Weil dictionary and the operator-level comparison (EXACT, integer-pinned): D1–D9."""745    print("block D — the Weil dictionary and the operator-level comparison")746    frames = {p: Frame(p) for p in SHELLS}747748    # D1 — R_s ∈ SO(2, F_p)749    ok = True750    for p in SHELLS:751        f = frames[p]752        for s in range(f.n):753            R = f.R(s); c, d = int(R[0, 0]), int(R[1, 0])754            ok &= ((c * c + d * d) % p == 1 and (R[0, 0] * R[1, 1] - R[0, 1] * R[1, 0]) % p == 1)755            ok &= (R[0, 1] == (-d) % p and R[1, 1] == c)756    check("D1", "c_s² + d_s² = 1, det R_s = 1: R_s ∈ SO(2, F_p) for every s", ok, f"p ∈ {SHELLS}")757758    # D2 — the isomorphism Z_{4κ} ≅ SO(2, F_p)759    ok, det = True, []760    for p in SHELLS:761        f = frames[p]762        Rs = [f.R(s) for s in range(f.n)]763        ok &= all(eq(mm(Rs[s], Rs[r], p), Rs[(s + r) % f.n], p) for s in range(f.n) for r in range(f.n))764        ok &= (len({R.tobytes() for R in Rs}) == f.n)765        so2 = sum(1 for c in range(p) for d in range(p) if (c * c + d * d) % p == 1)766        ok &= (so2 == p - 1)767        det.append(f"p={p}: |SO(2)|={so2}")768    # 6:E2 (p06031)769    check("D2", "R_{s+r} = R_s R_r, s ↦ R_s injective, |SO(2, F_p)| = p−1 = 4κ: an isomorphism", ok, "; ".join(det))770771    # D3 — the cardinal matrices772    ok = True773    for p in SHELLS:774        f = frames[p]; k = f.kap775        w = np.array([[0, p - 1], [1, 0]], dtype=np.int64)776        ok &= (f.z(k) == f.i)777        ok &= eq(f.R(0), np.eye(2, dtype=np.int64), p) and eq(f.R(k), w, p)778        ok &= eq(f.R(2 * k), (-np.eye(2, dtype=np.int64)) % p, p) and eq(f.R(3 * k), matpow(w, 3, p), p)779        ok &= eq(mm(f.R(3 * k), w, p), np.eye(2, dtype=np.int64), p)780    # 6:E3 (p06032)781    check("D3", "R_0 = I, R_κ = [[0,−1],[1,0]] (Table tab:checks), R_{2κ} = −I, R_{3κ} = w⁻¹; z_κ = g^{−κ} = i", ok, f"p ∈ {SHELLS}")782783    # D4 — the spectral obstruction784    ok, det = True, []785    for p in SHELLS:786        f = frames[p]; n = f.n787        sig = shift(n)788        ok &= eq(matpow(sig, n, p), f.I(), p) and all(not eq(matpow(sig, r, p), f.I(), p) for r in range(1, n))789        ok &= all(rank_mod_p((sig - a * f.I()) % p, p) == n - 1 for a in range(1, p))      # every a ∈ F_p^× a simple eigenvalue790        ok &= all(rank_mod_p((f.frft(1) - a * f.I()) % p, p) == n for a in range(1, p) if a not in {f.gpow(-l) for l in range(4)})791        neig = sum(1 for a in range(1, p) if rank_mod_p((f.frft(1) - a * f.I()) % p, p) < n)792        ok &= (neig <= 4) and (f.kap == 1 or neig < n)793        det.append(f"p={p}: σ has {n} simple eigenvalues, F^[1] has {neig}")794    # 6:E5 (p06034), 6:E9 (p06054)795    check("D4", "σ has the 4κ simple eigenvalues F_p^×; F^[1] has at most four; for κ ≥ 2 ⟨σ⟩ and ⟨F^[1]⟩ are not conjugate", ok, "; ".join(det))796797    # D5 — the common character sector798    ok, det = True, []799    for p in SHELLS:800        f = frames[p]; n = f.n801        P1 = f.Pi[1]; m1 = rank_mod_p(P1, p)802        ok &= (m1 >= 1) if f.kap >= 2 else True803        if m1 == 0:804            det.append(f"p={p}: E_1 = 0 (κ = 1)"); continue805        cols = [P1[:, j] for j in range(n) if np.any(P1[:, j])]806        for s in range(n):807            Fs = f.frft(s)808            for v in cols[:3]:809                ok &= eq(mm(Fs, v.reshape(n, 1), p), (f.gpow(-s) * v).reshape(n, 1), p)810                for x in range(p):811                    lhs = mm(Fs, (x * v % p).reshape(n, 1), p)                  # F^[s] T_v(x)812                    rhs = ((f.S(-s, x) * v) % p).reshape(n, 1)                  # T_v S_{−s}(x)813                    ok &= eq(lhs, rhs, p)814            vec = np.array([[1], [(-f.i) % p]], dtype=np.int64)815            ok &= eq(mm(f.R(s), vec, p), (f.gpow(-s) * vec) % p, p)816        det.append(f"p={p}: dim E_1 = {m1}")817    # 6:E6 (p06035)818    check("D5", "E_1 ≠ 0 for κ ≥ 2; F^[s] = g^{−s} on E_1; F^[s] T_v = T_v S_{−s} on every x and s; R_s (1,−i)ᵀ = g^{−s} (1,−i)ᵀ", ok, "; ".join(det))819820    # D6 — cardinal Heisenberg covariance and the expansion821    ok = True822    for p in SHELLS:823        f = frames[p]; n = f.n824        sig = shift(n); D1 = np.diag([f.gpow(k) for k in range(n)]).astype(np.int64)825        Finv = matpow(f.F, 3, p)826        ok &= eq(mm(mm(f.F, sig, p), Finv, p), D1, p)827        ok &= eq(mm(mm(f.F, D1, p), Finv, p), matpow(sig, n - 1, p), p)828        sigs = [sig, D1, matpow(sig, n - 1, p), np.diag([f.gpow(-k) for k in range(n)]).astype(np.int64)]829        for r in range(4):830            ok &= eq(mm(f.Fpow(r), sig, p), mm(sigs[r], f.Fpow(r), p), p)831        for s in range(n):832            M = np.zeros((n, n), dtype=np.int64)833            for r in range(4):834                c = f.inv4 * sum(pow(f.gpow(r * f.kap - s), l, p) for l in range(4)) % p835                M = (M + c * f.Fpow(r)) % p836            ok &= eq(M, f.frft(s), p)837    # 6:E7 (p06036)838    check("D6", "F σ F⁻¹ = D_1, F D_1 F⁻¹ = σ⁻¹; F^r σ = σ_r F^r with (σ, D_1, σ⁻¹, D_1⁻¹); F^[s] = Σ_r c_r(s) F^r, c_r(s) = ¼ Σ_ℓ (g^{rκ−s})^ℓ", ok, f"p ∈ {SHELLS}")839840    # D7 — the monomial sweep on the six shells (the instance of E8; D8 is the theorem's check)841    ok, n_int, n_card, det = True, 0, 0, []842    for p in SHELLS:843        f = frames[p]; n = f.n; k = f.kap844        sig = shift(n)845        mono = []846        for s in range(n):847            Fs = f.frft(s); Fsinv = f.frft(-s)848            mono.append(is_monomial(mm(mm(Fs, sig, p), Fsinv, p)))849        card = {0, k, 2 * k, 3 * k}850        ok &= all(mono[s] for s in card) and all(not mono[s] for s in range(n) if s not in card)851        if p != 5:852            n_int += n - 4853        n_card += 4854        det.append(f"p={p}: monomial at {sorted(s for s in range(n) if mono[s])}")855    ok &= (n_int == 112)856    check("D7", "on the six shells F^[s] σ F^[s]⁻¹ is monomial exactly at the four cardinal indices: the 112 intermediate indices of p ∈ {13,17,29,37,41} all non-monomial (E8 on Table tab:checks)", ok, "; ".join(det) + f"; {n_int} intermediate indices swept")857858    # D8 — cardinal exclusivity as a theorem (thm:monomial): off j ∈ {−1, 0, 1} row 0 of F^[s] σ F^[s]⁻¹ is859    # i[(c₀+c₂)(c'₃x + c'₁x⁻¹) + (c₁+c₃)(c'₀+c'₂)], x = g^j, c_r = c_r(s), c'_r = c_r(−s): x⁻¹ times a quadratic in x whose leading860    # coefficient i(c₀+c₂)c'₃ is nonzero for every non-cardinal s (c₀+c₂ = (1+g^{−2s})/2, every c_r(±s) ≠ 0), so the row has at861    # least 4κ−5 nonzero entries. Checked on every shell p ≡ 1 (mod 4) below 200 (the quadratic's coefficients, the entry formula862    # against the direct product, the count), five of the six shells of Table tab:checks among them (p = 5 has no such index).863    ok, n_int8, worst, det = True, 0, None, []864    for p in [q for q in range(13, 200) if q % 4 == 1 and all(q % d for d in range(2, int(q ** 0.5) + 1))]:865        f = frames.get(p) or Frame(p); n, k, inv2 = f.n, f.kap, pow(2, p - 2, p)866        sig = shift(n)867        c = lambda r, t: f.inv4 * sum(pow(f.gpow(r * k - t), l, p) for l in range(4)) % p868        for s in range(n):869            if s % k == 0:870                continue871            cs, cps = [c(r, s) for r in range(4)], [c(r, -s) for r in range(4)]872            c02 = (cs[0] + cs[2]) % p873            ok &= all(x != 0 for x in cs + cps) and c02 == inv2 * (1 + f.gpow(-2 * s)) % p and c02 != 0874            lead, cst = f.i * c02 * cps[3] % p, f.i * c02 * cps[1] % p875            ok &= lead != 0 and cst != 0876            row = (mm(f.frft(s)[:1], sig, p) @ f.frft(-s)) % p                 # row 0 of F^[s] σ F^[s]⁻¹, by the product877            D0 = [f.i * (c02 * (cps[3] * f.gpow(j) + cps[1] * f.gpow(-j)) + (cs[1] + cs[3]) * (cps[0] + cps[2])) % p for j in range(n)]878            ok &= all(row[0, j] == D0[j] for j in range(n) if j not in {n - 1, 0, 1})879            nz = int(np.count_nonzero(row)); roots = sum(1 for j in range(n) if D0[j] == 0)880            ok &= roots <= 2 and nz >= n - 5881            worst = nz if worst is None else min(worst, nz)882            n_int8 += 1883        det.append(f"p={p}")884    ok &= len(det) == 20 and n_int8 == 1920                                         # the twenty shells 13..197, Σ(p−5)885    # 6:E8 (p06050)886    check("D8", "cardinal exclusivity (thm:monomial): row 0 of F^[s] σ F^[s]⁻¹ is x⁻¹ times a quadratic in x = g^j off j ∈ {−1,0,1}, leading coefficient i(c₀+c₂)c₃(−s) ≠ 0, at least 4κ−5 nonzero entries for every non-cardinal s, every shell p ≡ 1 (mod 4) below 200", ok,887          f"{len(det)} shells, {n_int8} non-cardinal indices; fewest nonzero entries in row 0: {worst}")888889    # D9 — the plane as orbits of the cycle (cor:boundary): the rotation group {(c, d): c² + d² = 1} has p−1 = n elements890    # and is {R_s}; on F_p² its orbits are the origin, the n circles x² + y² = c ≠ 0 and the two isotropic lines y = ±ix891    # without the origin, every orbit but the origin free (of size n), n+2 of them, p² = 1 + (n+2)n; in u = x + iy,892    # v = x − iy the rotation R_s is (u, v) ↦ (z_s u, z_s⁻¹ v) with x² + y² = uv; the transforms act on n×n.893    ok, det = True, []894    for p in SHELLS:895        f = frames[p]; n, i = f.n, f.i896        circle = {(c, d) for c in range(p) for d in range(p) if (c * c + d * d) % p == 1}897        Rs = {(int(f.R(s)[0, 0]), int(f.R(s)[1, 0])) for s in range(n)}898        ok &= len(circle) == n and Rs == circle                                       # |SO(2, F_p)| = n, and it is {R_s}899        seen, orbits = set(), []900        for x in range(p):901            for y in range(p):902                if (x, y) in seen:903                    continue904                orb = {((c * x - d * y) % p, (d * x + c * y) % p) for (c, d) in circle}905                seen |= orb; orbits.append((len(orb), (x * x + y * y) % p))906        sizes = sorted(o[0] for o in orbits)907        ok &= sizes == [1] + [n] * (n + 2) and p * p == 1 + (n + 2) * n              # the origin and n+2 free orbits908        ok &= len({q for (sz, q) in orbits if q != 0}) == n                             # one circle per nonzero norm909        ok &= sum(1 for (sz, q) in orbits if q == 0 and sz == n) == 2                   # the two isotropic lines910        null = {(x, y) for x in range(p) for y in range(p) if (x * x + y * y) % p == 0 and (x, y) != (0, 0)}911        ok &= null == {(x, (i * x) % p) for x in range(1, p)} | {(x, (-i * x) % p) for x in range(1, p)}   # y = ±ix912        for s in range(n):913            R, z = f.R(s), f.z(s); zi = pow(z, p - 2, p)914            for (x, y) in [(1, 0), (0, 1), (2, 3), (i, 1)]:915                x2, y2 = (int(R[0, 0]) * x + int(R[0, 1]) * y) % p, (int(R[1, 0]) * x + int(R[1, 1]) * y) % p916                u, v = (x + i * y) % p, (x - i * y) % p917                ok &= (x2 + i * y2) % p == z * u % p and (x2 - i * y2) % p == zi * v % p and (x * x + y * y) % p == u * v % p918        ok &= f.frft(1).shape == (n, n)                                                 # dim V = n919        det.append(f"p={p}: |SO(2)|={len(circle)}, orbits 1+{n + 2}×{n}")920    # 6:E10 (p06056)921    check("D9", "the plane as orbits of the cycle (cor:boundary): |SO(2,F_p)| = n = p−1 and it is {R_s}; F_p² = the origin + (n+2) free orbits (n circles of nonzero norm, two isotropic lines y = ±ix), p² = 1+(n+2)n; (u,v) ↦ (z_s u, z_s⁻¹ v); dim V = n",922          ok, "; ".join(det))923924925if __name__ == "__main__":926    import time927    want = [a.upper() for a in sys.argv[1:]] or sorted(BLOCK)928    bad = [b for b in want if b not in BLOCK]929    if bad: sys.exit(f"no block {', '.join(bad)}: the blocks are {', '.join(sorted(BLOCK))}")930    t0 = time.time()931    for b in want:932        t = time.time(); _run_block(b); print(f"    [block {b}: {time.time() - t:.1f} s]")933    ok = summary(write=(want == sorted(BLOCK)))934    kinds = {}935    for r in RESULTS: kinds[r["kind"]] = kinds.get(r["kind"], 0) + 1936    print("by kind: " + ", ".join(f"{k} {v}" for k, v in sorted(kinds.items())) + f"; {len(RESULTS)} checks in {time.time() - t0:.1f} s" + ("; results.json written" if want == sorted(BLOCK) else ""))937    sys.exit(0 if ok else 1)938