validate_inertia.py — src/21-gravity

The script src/21-gravity/validate_inertia.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_inertia.py · 2.1 KBvalidate_inertia.pyColab
1#!/usr/bin/env python32"""Two-shift update law (Theorem thm:twoshift): exact checks.34(1) Kick as character identity: multiplying a state by the character5    zeta^(-s q) shifts its winding spectrum by exactly s -- exact in F_p6    (finite Fourier shift theorem), no error term.7(2) Ehrenfest parabola on exact chirps: alternating kick (s per chronon) and8    quadratic transport reproduces Delta^2 <q> = -s/m as an exact integer9    second difference of the registered label.10(3) Equivalence principle bitwise: the runs (m, F) and (3m, 3F) produce11    identical registered trajectories -- equality of Python objects, not12    approximate agreement.13"""14ok = True15def chk(n, c):16    global ok; ok = ok and bool(c); print(('PASS ' if c else 'FAIL ') + n)1718# (1) finite Fourier shift theorem on C_n in F_p (p = 1 mod n)19p_, n = 241, 12                       # 241 = 1 + 20*1220g = 721zeta = pow(g, (p_ - 1) // n, p_)      # primitive n-th root in F_24122assert pow(zeta, n, p_) == 1 and pow(zeta, n // 2, p_) != 123def dft(v):24    return [sum(v[x] * pow(zeta, -k * x, p_) for x in range(n)) % p_ for k in range(n)]25import random26random.seed(3)27v = [random.randrange(p_) for _ in range(n)]28sft = 529w = [v[x] * pow(zeta, -sft * x, p_) % p_ for x in range(n)]30V, W = dft(v), dft(w)31chk("(1) kick = exact winding shift: DFT(zeta^{-sq} v)_k = DFT(v)_{k+s} for all k",32    all(W[k] == V[(k + sft) % n] for k in range(n)))3334# (2)(3) registered trajectory: integer kick/transport dynamics35def run(m, gradu, T=40):36    q, k = 0, 037    traj = [q]38    for _ in range(T):39        k -= m * gradu      # kick: winding shift m*grad(u) (coherent additivity)40        q += k // m         # transport: dq = k/m per chronon (m | k by construction)41        traj.append(q)42    return traj43m, F = 4, 244t1 = run(m, F)45sec = [t1[i+1] - 2*t1[i] + t1[i-1] for i in range(1, len(t1)-1)]46chk(f"(2) Ehrenfest parabola: second difference = -grad(u) = {-F} at every interior chronon",47    all(d == -F for d in sec))48chk("(3) equivalence principle bitwise: run(m, grad u) == run(3m, grad u) -- mass cancels",49    run(m, F) == run(3*m, F))5051print("\nALL PASS" if ok else "\nFAILURES PRESENT")52raise SystemExit(0 if ok else 1)53