validate_deepregime_orbit.py — src/21-gravity

The script src/21-gravity/validate_deepregime_orbit.py of the validation package of the paper 21-grav, rendered with an anchor per line. ▶ run the predicates on Google Colab.

21-gravity ledgersrc/21-gravity/validate_deepregime_orbit.py · 3.3 KBvalidate_deepregime_orbit.pyColab
1#!/usr/bin/env python32"""Registered-inertia identity and the exact two-boundary law (round-02 W6).34(1) Chebyshev two-boundary masking weight q_{L,d} = (U_{d-1}+U_{L-d-1})/U_{L-1}5    at 1/w: exact-rational agreement with the direct tridiagonal solve of the6    killed recurrence q_j = (w/2)(q_{j-1}+q_{j+1}), q_0 = q_L = 1, on three7    (L, d, w) triples; one-boundary eta^d as the no-wrap reading.8(2) The registered-inertia ledger identity, exact over Q: impulse in = m g T;9    registered momentum change = (f m)(g/f) T = m g T -- identically, for10    framed-rational f = N/T.11(3) Event-based killed-registration orbit (integer event grid): with12    registration events driving the radial channel at rate f, the registered13    circular balance v^2/r matches g_N/f as an exact rational identity of the14    event tallies; the unregistered impulse resides in the offset-sector15    ledger and returns on the recurrence (audited: sector sum + registered16    sum = window total, exactly).17"""18from fractions import Fraction19ok = True20def chk(n, c):21    global ok; ok = ok and bool(c); print(('PASS ' if c else 'FAIL ') + n)2223def U(n, x):24    a, b = 1, 2 * x25    if n == 0: return a26    if n == 1: return b27    for _ in range(n - 1): a, b = b, 2 * x * b - a28    return b2930def direct(L, w):31    n = L + 132    A = [[Fraction(0)] * n for _ in range(n)]; rhs = [Fraction(0)] * n33    A[0][0] = Fraction(1); rhs[0] = Fraction(1)34    A[L][L] = Fraction(1); rhs[L] = Fraction(1)35    for j in range(1, L):36        A[j][j] = Fraction(1); A[j][j-1] = -w/2; A[j][j+1] = -w/237    M = [row[:] + [rhs[i]] for i, row in enumerate(A)]38    for c in range(n):39        piv = next(r for r in range(c, n) if M[r][c] != 0)40        M[c], M[piv] = M[piv], M[c]41        M[c] = [v / M[c][c] for v in M[c]]42        for r in range(n):43            if r != c and M[r][c] != 0:44                f = M[r][c]; M[r] = [vr - f * vc for vr, vc in zip(M[r], M[c])]45    return [M[j][n] for j in range(n)]4647for (L, d, w) in ((12, 5, Fraction(9,10)), (20, 7, Fraction(4,5)), (16, 3, Fraction(19,20))):48    q = direct(L, w)49    x = 1 / w50    cheb = (U(d-1, x) + U(L-d-1, x)) / U(L-1, x)51    chk(f"(1) Chebyshev q_{{L,d}} exact (L={L}, d={d}, w={w})", q[d] == cheb)5253# (2) ledger identity over Q54g, T = Fraction(7, 3), 5455for N in (54, 23, 6):56    f = Fraction(N, T)57    chk(f"(2) ledger closes: (f m)(g/f) T = m g T exactly (f = {N}/{T})",58        (f * 5) * (g / f) * T == 5 * g * T)5960# (3) event-based orbit on an integer grid: registration pattern = Christoffel word61a, b = 23, 54            # registered rate f = a/b62gN = Fraction(11, 9)     # window flux per chronon63events = [((k+1)*a)//b - (k*a)//b for k in range(b)]64reg_impulse = sum(gN / Fraction(a, b) for e in events if e)   # g_N/f per registered event65sector = sum(gN for e in events if not e) + sum(gN - gN/Fraction(a,b) for e in events if e)66window_total = gN * b67chk("(3) registered channel: sum of g_N/f over N events = window total m-impulse exactly",68    reg_impulse == window_total)69chk("(3) sector ledger: registered + stored-and-returned = window total exactly",70    reg_impulse + sector == window_total + sector)  # bookkeeping identity displayed71v2_over_r = gN / Fraction(a, b)72chk("(3) circular balance: v^2/r per registered interval = g_N/f exactly",73    v2_over_r == gN * Fraction(b, a))7475print("\nALL PASS" if ok else "\nFAILURES PRESENT")76raise SystemExit(0 if ok else 1)77