#!/usr/bin/env python3 """Exact checker for the rational data of Theorems 3.3 and 3.5 of "Complete positivity and equilibrium realizations of reversible observations". Standard library only (fractions, decimal, itertools, math). Run: python check_certificate.py Every check prints "[ok]" or "[FAIL]"; the script ends with "ALL CHECKS PASSED" (exit code 0) or a list of failures (exit code 1). Arithmetic. All data, the finite-lag action A_h, the interpolant, the constants and the normalisation are computed in exact rational arithmetic. The target moments of Appendix E involve exp(sQ0), s in {t, h}; they are enclosed rigorously by an exact rational Taylor polynomial of degree N_ENC plus an entrywise remainder interval, and propagated with interval arithmetic whose endpoints are rounded outward to the dyadic grid 2^-K. The moments are evaluated twice: (i) through the restricted-adjoint Gram identity of the paper (forward conditional features only), and (ii) directly from the observed law, using the actual stationary reverse chain Q0^dagger for the reflected half (no Gram identity assumed). Section and equation names refer to the paper: A Theorem 3.3 data (Appendix C, eqs. polygon-*) B certificate inputs (Appendix E, eqs. certificate-parameters ... certificate-coefficient-bounds) C target moments (eqs. certificate-target-moments, certificate-target-bound) D word normalisation (eq. certificate-normalization; all 6^7 words) E margin and dissipation floor (Theorem 3.5) """ from fractions import Fraction as Fr from decimal import Decimal, getcontext import itertools import math import sys getcontext().prec = 50 FAILS = [] def check(name, cond, info=""): if not cond: FAILS.append(name) print(f"[{'ok' if cond else 'FAIL'}] {name}" + (f" ({info})" if info else "")) def dec(x, digits=10): x = Fr(x) return f"{Decimal(x.numerator) / Decimal(x.denominator):.{digits}e}" # ----------------------------------------------------------------- helpers def zeros(n, m): return [[Fr(0)] * m for _ in range(n)] def eye(n): M = zeros(n, n) for i in range(n): M[i][i] = Fr(1) return M def matmul(A, B): m = len(B[0]) return [[sum((a * B[k][j] for k, a in enumerate(row) if a), Fr(0)) for j in range(m)] for row in A] def transpose(A): return [list(r) for r in zip(*A)] def solve(A, b): """Exact Gaussian elimination; returns (solution, rank).""" n, m = len(A), len(A[0]) M = [list(A[i]) + [b[i]] for i in range(n)] piv_cols, r = [], 0 for c in range(m): p = next((i for i in range(r, n) if M[i][c] != 0), None) if p is None: continue M[r], M[p] = M[p], M[r] M[r] = [v / M[r][c] for v in M[r]] for i in range(n): if i != r and M[i][c] != 0: f = M[i][c] M[i] = [vi - f * vr for vi, vr in zip(M[i], M[r])] piv_cols.append(c) r += 1 consistent = all(M[i][m] == 0 for i in range(r, n)) x = [Fr(0)] * m for i, c in enumerate(piv_cols): x[c] = M[i][m] return x, r, consistent def dot(u, v): return sum((a * b for a, b in zip(u, v)), Fr(0)) # ====================================================================== print("A. Theorem 3.3 data (Appendix C)") # ====================================================================== p = [(Fr(1), Fr(0)), (Fr(0), Fr(1)), (Fr(-1), Fr(0)), (Fr(-3, 5), Fr(-4, 5)), (Fr(3, 5), Fr(-4, 5))] omega = [Fr(k, 28) for k in (5, 8, 5, 5, 5)] Fl = {(0, 1): Fr(11, 126), (0, 3): Fr(5, 126), (0, 4): Fr(5, 72), (1, 3): Fr(25, 63), (1, 4): Fr(25, 63), (2, 1): Fr(11, 126), (2, 3): Fr(5, 72), (2, 4): Fr(5, 126), (3, 1): Fr(13, 42), (3, 2): Fr(11, 56), (4, 0): Fr(11, 56), (4, 1): Fr(13, 42)} Fm = zeros(5, 5) for (i, j), v in Fl.items(): Fm[i][j] = v check("vertices have unit norm", all(x * x + y * y == 1 for x, y in p)) check("sum omega = 1", sum(omega) == 1) check("weighted mean zero", all(sum(omega[i] * p[i][k] for i in range(5)) == 0 for k in (0, 1))) Sig = [[sum(omega[i] * p[i][a] * p[i][b] for i in range(5)) for b in (0, 1)] for a in (0, 1)] check("covariance Sigma = diag(17/35, 18/35)", Sig == [[Fr(17, 35), 0], [0, Fr(18, 35)]]) check("flow balance sum_j F_ij = sum_j F_ji", all(sum(Fm[i]) == sum(Fm[j][i] for j in range(5)) for i in range(5))) check("flow drift sum_j F_ij (p_j - p_i) = omega_i diag(-1,-5) p_i", all(sum(Fm[i][j] * (p[j][0] - p[i][0]) for j in range(5)) == -omega[i] * p[i][0] and sum(Fm[i][j] * (p[j][1] - p[i][1]) for j in range(5)) == -5 * omega[i] * p[i][1] for i in range(5))) R = zeros(5, 5) for i in range(5): for j in range(5): if i != j: R[i][j] = Fm[i][j] / omega[i] + omega[j] / 10 R[i][i] = -sum(R[i][j] for j in range(5) if j != i) alpha, beta = Fr(11, 10), Fr(51, 10) check("R off-diagonal entries positive", all(R[i][j] > 0 for i in range(5) for j in range(5) if i != j)) check("omega R = 0", all(sum(omega[i] * R[i][j] for i in range(5)) == 0 for j in range(5))) check("R drift = L p_i, L = diag(-11/10, -51/10)", all(sum(R[i][j] * p[j][0] for j in range(5)) == -alpha * p[i][0] and sum(R[i][j] * p[j][1] for j in range(5)) == -beta * p[i][1] for i in range(5))) yv = [(Fr(0), Fr(0)), (Fr(0), Fr(0)), (Fr(-35, 3), Fr(35, 3)), (Fr(-21), Fr(7)), (Fr(0), Fr(0))] dij = {(i, j): dot((yv[i][0] - yv[j][0], yv[i][1] - yv[j][1]), (p[j][0] - p[i][0], p[j][1] - p[i][1])) for i in range(5) for j in range(i + 1, 5)} check("all d_ij <= 0", all(v <= 0 for v in dij.values())) check("nonzero d_ij are d02=-70/3, d03=d24=-28, d34=-126/5", {k: v for k, v in dij.items() if v != 0} == {(0, 2): Fr(-70, 3), (0, 3): Fr(-28), (2, 4): Fr(-28), (3, 4): Fr(-126, 5)}) sep = sum(omega[i] * (yv[i][0] * (-alpha * p[i][0]) + yv[i][1] * (-beta * p[i][1])) for i in range(5)) check("separating value sum_i omega_i y_i.L p_i = beta - 13 alpha/3 = 1/3", sep == Fr(1, 3) and beta - 13 * alpha / 3 == Fr(1, 3)) # facets g_l = b_l + m_l . p bvec = [Fr(2), Fr(2), Fr(2), Fr(8, 5), Fr(2)] mx = [Fr(-2), Fr(2), Fr(2), Fr(0), Fr(-2)] my = [Fr(-2), Fr(-2), Fr(1), Fr(2), Fr(1)] lam = Fr(48, 5) def g(l, x, y): return bvec[l] + mx[l] * x + my[l] * y G = [[g(l, *p[i]) for l in range(5)] for i in range(5)] check("facet values g_l(p_i) >= 0", all(v >= 0 for r in G for v in r)) check("each facet vanishes at exactly two vertices (probe has 3 core neighbours)", all(sum(1 for i in range(5) if G[i][l] == 0) == 2 for l in range(5))) check("each facet passes through two adjacent vertices (K = polygon)", all({i for i in range(5) if G[i][l] == 0} in [{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 0}] for l in range(5))) check("sum of facet functions = lambda = 48/5", sum(bvec) == lam and sum(mx) == 0 and sum(my) == 0) n = 10 Q0 = zeros(n, n) for i in range(5): for j in range(5): Q0[i][j] = R[i][j] Q0[i][i] -= lam for l in range(5): Q0[i][5 + l] = G[i][l] Q0[5 + l][i] = 5 * G[i][l] * omega[i] for l in range(5): Q0[5 + l][5 + l] = -5 * bvec[l] pi0 = [w / 2 for w in omega] + [Fr(1, 10)] * 5 check("Q0 row sums zero", all(sum(r) == 0 for r in Q0)) check("Q0 off-diagonal nonnegative", all(Q0[i][j] >= 0 for i in range(n) for j in range(n) if i != j)) check("pi0 Q0 = 0 and sum pi0 = 1", all(sum(pi0[i] * Q0[i][j] for i in range(n)) == 0 for j in range(n)) and sum(pi0) == 1) check("Q0 reciprocal (q_ij > 0 iff q_ji > 0)", all((Q0[i][j] > 0) == (Q0[j][i] > 0) for i in range(n) for j in range(n) if i != j)) reach = {0} frontier = [0] while frontier: i = frontier.pop() for j in range(n): if Q0[i][j] > 0 and j not in reach: reach.add(j) frontier.append(j) check("Q0 irreducible (reciprocal + connected)", len(reach) == n) check("core flux difference across (a0,a1) = 11/252 (not detailed balanced)", pi0[0] * Q0[0][1] - pi0[1] * Q0[1][0] == Fr(11, 252)) nQ0 = max(sum(abs(v) for v in r) for r in Q0) check("||Q0||_inf = 10513/420 < 26", nQ0 == Fr(10513, 420) and nQ0 < 26) # observable space W and the matrix C Phi = zeros(n, 8) for i in range(5): Phi[i][0], Phi[i][1], Phi[i][2] = Fr(1), p[i][0], p[i][1] for l in range(5): Phi[5 + l][3 + l] = Fr(1) C = zeros(8, 8) C[0][0] = -lam C[1][1] = -(lam + alpha) C[2][2] = -(lam + beta) for l in range(5): C[0][3 + l], C[1][3 + l], C[2][3 + l] = bvec[l], mx[l], my[l] C[3 + l][0] = 5 * bvec[l] C[3 + l][1] = 5 * Sig[0][0] * mx[l] C[3 + l][2] = 5 * Sig[1][1] * my[l] C[3 + l][3 + l] = -5 * bvec[l] check("Q0 phi_j = sum_i C_ij phi_i on all ten states", matmul(Q0, Phi) == matmul(Phi, C)) Gram = [[sum(pi0[s] * Phi[s][a] * Phi[s][b] for s in range(n)) for b in range(8)] for a in range(8)] Mg = zeros(8, 8) Mg[0][0], Mg[1][1], Mg[2][2] = Fr(1, 2), Sig[0][0] / 2, Sig[1][1] / 2 for l in range(5): Mg[3 + l][3 + l] = Fr(1, 10) check("stationary Gram of the basis = metric (polygon-metric), positive definite: rank 8", Gram == Mg and all(Mg[k][k] > 0 for k in range(8))) MC = matmul(Mg, C) check("Q0|_W self-adjoint in the pi0 metric (Mg C symmetric)", MC == transpose(MC)) nC = max(sum(abs(C[i][j]) for i in range(8)) for j in range(8)) check("||C||_1 = 288/5", nC == Fr(288, 5)) # weights are fixed by the moments 1, x, y, x^2, xy, y^2 rows = [[Fr(1)] * 5, [q[0] for q in p], [q[1] for q in p], [q[0] ** 2 for q in p], [q[0] * q[1] for q in p], [q[1] ** 2 for q in p]] sol, rk, ok = solve(rows, [Fr(1), Fr(0), Fr(0), Sig[0][0], Fr(0), Sig[1][1]]) check("vertex weights uniquely fixed by moments (rank 5) and equal omega", rk == 5 and ok and sol == omega) # ====================================================================== print("\nB. Certificate inputs (Appendix E)") # ====================================================================== h, t, N = Fr(1, 1000), Fr(1, 10 ** 7), 12 hC = [[h * v for v in r] for r in C] Ah, term = eye(8), eye(8) for k in range(1, N + 1): term = [[v / k for v in r] for r in matmul(term, hC)] Ah = [[a + b for a, b in zip(r1, r2)] for r1, r2 in zip(Ah, term)] E_, X_, Y_ = 0, 1, 2 colsum = [sum(abs(Ah[i][j]) for i in range(8)) for j in (E_, X_, Y_)] check("sum_i |(A_h)_ij| <= 2 for j = e,x,y", max(colsum) <= 2, f"max = {dec(max(colsum), 6)}") r_ = h * nC AmI = max(sum(abs(Ah[i][j] - (1 if i == j else 0)) for i in range(8)) for j in range(8)) check("r = h||C||_1 = 36/625 and ||A_h - I||_1 < r/(1-r) = 36/589 < 1/10", r_ == Fr(36, 625) and r_ / (1 - r_) == Fr(36, 589) and AmI < Fr(36, 589) < Fr(1, 10), f"||A_h-I||_1 = {dec(AmI, 6)}") # H_h(xi) = c_h + B_h xi - xi (k_h . xi) ch = (Ah[E_][X_], Ah[E_][Y_]) Bh = [[Ah[X_][X_] - Ah[E_][E_], Ah[Y_][X_]], [Ah[X_][Y_], Ah[Y_][Y_] - Ah[E_][E_]]] kh = (Ah[X_][E_], Ah[Y_][E_]) def Aj(j, x, y): return Ah[E_][j] + Ah[X_][j] * x + Ah[Y_][j] * y def H(x, y): ae = Aj(E_, x, y) return (Aj(X_, x, y) - x * ae, Aj(Y_, x, y) - y * ae) check("H_h(xi) = c_h + B_h xi - xi (k_h . xi) (3x3 grid identity, quadratic)", all(H(x, y) == tuple(ch[a] + Bh[a][0] * x + Bh[a][1] * y - (x, y)[a] * (kh[0] * x + kh[1] * y) for a in (0, 1)) for x in (Fr(-1), Fr(0), Fr(2)) for y in (Fr(-1), Fr(0), Fr(3)))) w = yv z = [dot(w[i], H(*p[i])) for i in range(5)] d0 = Fr(25, 72) * (z[3] + z[4]) + Fr(5, 9) * z[1] - Fr(1, 8) * (z[0] + z[2]) d1 = (z[0] - z[2]) / 2 d2 = z[1] - d0 d3 = (z[0] + z[2]) / 2 - d0 d4 = Fr(5, 4) * d1 + Fr(25, 24) * (z[3] - z[4]) dd = [d0, d1, d2, d3, d4] def qh(x, y): return d0 + d1 * x + d2 * y + d3 * x * x + d4 * x * y check("interpolant q_h(p_i) = z_i", all(qh(*p[i]) == z[i] for i in range(5))) check("sum_r |d_r| <= 60h", sum(abs(v) for v in dd) <= 60 * h, f"sum|d_r|/h = {dec(sum(abs(v) for v in dd) / h, 6)}") Mq = [[d3, d4 / 2], [d4 / 2, Fr(0)]] ok_cancel, ell2, lam_ok = True, [], True for i in range(5): px, py = p[i] grad = (d1 + 2 * d3 * px + d4 * py, d2 + d4 * px) wp = dot(w[i], p[i]) kp = dot(kh, p[i]) BtW = (Bh[0][0] * w[i][0] + Bh[1][0] * w[i][1], Bh[0][1] * w[i][0] + Bh[1][1] * w[i][1]) li = tuple(grad[a] - BtW[a] + wp * kh[a] + kp * w[i][a] for a in (0, 1)) Mi = [[Mq[a][b] + (w[i][a] * kh[b] + kh[a] * w[i][b]) / 2 for b in (0, 1)] for a in (0, 1)] for ux in (Fr(-1), Fr(0), Fr(1)): for uy in (Fr(-1), Fr(0), Fr(1)): lhs = qh(px + ux, py + uy) - dot(w[i], H(px + ux, py + uy)) rhs = li[0] * ux + li[1] * uy + Mi[0][0] * ux * ux + 2 * Mi[0][1] * ux * uy + Mi[1][1] * uy * uy ok_cancel &= (lhs == rhs) ell2.append(dot(li, li)) S = [[12 * h - Mi[0][0], -Mi[0][1]], [-Mi[1][0], 12 * h - Mi[1][1]]] lam_ok &= S[0][0] > 0 and S[0][0] * S[1][1] - S[0][1] * S[1][0] > 0 check("cancellation q_h(xi) - w_i.H_h(xi) = l_i.u + u^T M_i u (3x3 grid per vertex)", ok_cancel) check("max |l_i|^2 < (36h)^2", max(ell2) < (36 * h) ** 2, f"max|l_i|^2/h^2 = {dec(max(ell2) / h ** 2, 6)}") check("lambda_max(M_i) < 12h (12h I - M_i positive definite)", lam_ok) w2 = [dot(wi, wi) for wi in w] check("max |w_i|^2 < 491", max(w2) < 491, f"max = {max(w2)}") check("max |w_i|^2 + (w_i.p_i)^2 < 540", max(w2[i] + dot(w[i], p[i]) ** 2 for i in range(5)) < 540, f"max = {max(w2[i] + dot(w[i], p[i]) ** 2 for i in range(5))}") Aw = [[dot((w[i][0] - w[j][0], w[i][1] - w[j][1]), (p[i][0] - p[j][0], p[i][1] - p[j][1])) for j in range(5)] for i in range(5)] check("A_ij = (w_i - w_j).(p_i - p_j) >= 0", all(v >= 0 for r in Aw for v in r)) Msq = max(dot((w[i][0] - w[j][0], w[i][1] - w[j][1]), (w[i][0] - w[j][0], w[i][1] - w[j][1])) for i in range(5) for j in range(5)) check("M^2 = max |w_i - w_j|^2 <= 490 < 23^2", Msq <= 490 < 23 ** 2, f"M^2 = {Msq}") dmin2 = min(dot((p[i][0] - p[j][0], p[i][1] - p[j][1]), (p[i][0] - p[j][0], p[i][1] - p[j][1])) for i in range(5) for j in range(i + 1, 5)) kappa = Fr(9, 4) check("d_*^2 = 4/5 and kappa = 9/4 >= 2/d_* = sqrt 5", dmin2 == Fr(4, 5) and kappa ** 2 >= 4 / dmin2) check("facet intercepts >= 8/5 (so xi/(1+5 eta_f/8) lies in K)", min(bvec) == Fr(8, 5)) # rounding coefficients, polynomial identities in eta (degree 2, checked at 3 points) ok_r = True for eta_ in (Fr(0), Fr(1), Fr(3)): a_ = 1 + 5 * eta_ / 8 ok_r &= 2 * a_ * (a_ - 1) == Fr(5, 4) * eta_ + Fr(25, 32) * eta_ ** 2 ok_r &= (a_ - 1) + kappa * (a_ ** 2 - 1) == Fr(55, 16) * eta_ + Fr(225, 256) * eta_ ** 2 check("rounding coefficients 5/4, 25/32 and 55/16, 225/256", ok_r) cmin = Fr(147, 5) * t check("c_4 >= 792t/25 > c_min = 147t/5", Fr(842, 25) - 2 == Fr(792, 25) and Fr(792, 25) * t > cmin) beta_t = Fr(25, 2352) / t + Fr(25, 32) a_t = Fr(275, 9408) / t + Fr(225, 256) check("beta_t = 5/(16 c_min) + 25/32", beta_t == 5 / (16 * cmin) + Fr(25, 32)) check("a_t = 55/(64 c_min) + 225/256", a_t == 55 / (64 * cmin) + Fr(225, 256)) Cdelta = Fr(63843) CG = (23 / h + 36) * a_t + (12 + 12 / h) * beta_t CR = Fr(491, 48) / h + 12960 / h ** 2 check("C_delta = 63843 cancels the signed delta coefficient: (23/h+36)(9/4) + (12+12/h)", (23 / h + 36) * kappa + (12 + 12 / h) == Cdelta) check("Young: sqrt(491) D sqrt(R) <= 12 D^2 + (491/48) R [491 <= 4*12*491/48]", 491 <= 4 * 12 * Fr(491, 48)) check("AM-GM: sqrt(540)/h sqrt(R) <= 1/96 + (12960/h^2) R [540 <= 4*(1/96)*12960]", 540 <= 4 * Fr(1, 96) * 12960) print(f" C_G = {dec(CG)}, C_R = {dec(CR)}") # ====================================================================== print("\nC. Target moments (eq. certificate-target-moments), interval enclosure") # ====================================================================== N_ENC, K = 16, 640 SCALE = 1 << K def rd(x): return Fr(x.numerator * SCALE // x.denominator, SCALE) def ru(x): return Fr(-((-x.numerator * SCALE) // x.denominator), SCALE) def iv(a, b=None): return (rd(Fr(a)), ru(Fr(a if b is None else b))) def iadd(a, b): return (a[0] + b[0], a[1] + b[1]) def isub(a, b): return (a[0] - b[1], a[1] - b[0]) def imul(a, b): c = (a[0] * b[0], a[0] * b[1], a[1] * b[0], a[1] * b[1]) return (rd(min(c)), ru(max(c))) def isc(a, s): # scale by an exact rational s = Fr(s) return (rd(a[0] * s), ru(a[1] * s)) if s >= 0 else (rd(a[1] * s), ru(a[0] * s)) def isum(it): tot = (Fr(0), Fr(0)) for x in it: tot = iadd(tot, x) return tot ZERO = (Fr(0), Fr(0)) def expm_enclosure(s): x = s * nQ0 assert x < N_ENC + 2 P, term = eye(n), eye(n) sQ = [[s * v for v in r] for r in Q0] for k in range(1, N_ENC + 1): term = [[v / k for v in r] for r in matmul(term, sQ)] P = [[a + b for a, b in zip(r1, r2)] for r1, r2 in zip(P, term)] u = x ** (N_ENC + 1) / math.factorial(N_ENC + 1) / (1 - x / (N_ENC + 2)) return [[(rd(v - u), ru(v + u)) for v in r] for r in P], u Et, ut = expm_enclosure(t) Eh, uh = expm_enclosure(h) print(f" Taylor degree {N_ENC}: entrywise remainder u_t = {dec(ut, 3)}, u_h = {dec(uh, 3)}") def reverse(E): return [[isc(E[sp][s], pi0[sp] / pi0[s]) for sp in range(n)] for s in range(n)] def features(E_t, E_h): """Conditional expectations given X0 = s of the observed functionals.""" phi = [] # 8 basis features e, Fx, Fy, e1..e5 fl = [] for s in range(n): core = s < 5 f = [isc(E_t[s][5 + l], 1 / t) if core else ZERO for l in range(5)] e = iv(1 if core else 0) Fx = isc(isub(f[1], f[0]), Fr(1, 4)) Fy = isub(e, isc(iadd(f[0], f[1]), Fr(1, 4))) el = [iv(1 if s == 5 + l else 0) for l in range(5)] phi.append([e, Fx, Fy] + el) fl.append(f) gam = [] # gamma_l = E[G_l | X0], l = 3,4,5 (indices 2,3,4) for s in range(n): e, Fx, Fy = phi[s][0], phi[s][1], phi[s][2] row = [] for l in (2, 3, 4): r = isub(isub(isub(fl[s][l], isc(e, bvec[l])), isc(Fx, mx[l])), isc(Fy, my[l])) if l == 3: r = isub(iadd(r, isc(e, Fr(842, 25) * t)), isc(Fy, 2 * t)) else: r = iadd(r, isc(e, Fr(147, 5) * t)) row.append(r) gam.append(row) res = [] # R_j = E_h phibar_j - sum_i (A_h)_ij phibar_i, j = e,x,y for s in range(n): row = [] for j in (E_, X_, Y_): Th = isum(imul(E_h[s][sp], phi[sp][j]) for sp in range(n)) Aphi = isum(isc(phi[s][i], Ah[i][j]) for i in range(8)) row.append(isub(Th, Aphi)) res.append(row) return phi, gam, res fw = features(Et, Eh) bw = features(reverse(Et), reverse(Eh)) def moments(past, fut): phP, gP, rP = past phF, gF, rF = fut def E(fn): return isum(isc(fn(s), pi0[s]) for s in range(n)) Eq = E(lambda s: isum([isc(phF[s][0], d0), isc(phF[s][1], d1), isc(phF[s][2], d2), isc(imul(phP[s][1], phF[s][1]), d3), isc(imul(phP[s][1], phF[s][2]), d4)])) delta = E(lambda s: isub(phF[s][0], iadd(imul(phP[s][1], phF[s][1]), imul(phP[s][2], phF[s][2])))) AG = E(lambda s: isum(imul(gP[s][k], gF[s][k]) for k in range(3))) RR = E(lambda s: isum(imul(rP[s][k], rF[s][k]) for k in range(3))) return isc(Eq, 1 / h), delta, AG, RR claimed = dict(q_lo=Fr("0.1134506396"), delta_hi=Fr("1.137856e-6"), AG_hi=Fr("5.51524e-24"), R_hi=Fr("8.21447e-17")) EL_lo_all = [] for label, past in (("Gram identity (forward features)", fw), ("observed law (actual reverse chain for theta)", bw)): q, de, AG, RR = moments(past, fw) print(f" [{label}]") print(f" E q_obs/h in [{dec(q[0], 12)}, {dec(q[1], 12)}]") print(f" delta in [{dec(de[0], 12)}, {dec(de[1], 12)}]") print(f" A_G in [{dec(AG[0], 10)}, {dec(AG[1], 10)}]") print(f" calR in [{dec(RR[0], 10)}, {dec(RR[1], 10)}]") check(f"{label}: E q_obs/h > 0.1134506396", q[0] > claimed["q_lo"]) check(f"{label}: delta < 1.137856e-6", de[1] < claimed["delta_hi"]) check(f"{label}: A_G < 5.51524e-24", AG[1] < claimed["AG_hi"]) check(f"{label}: calR < 8.21447e-17", RR[1] < claimed["R_hi"]) EL_lo = q[0] - Cdelta * de[1] - CG * AG[1] - CR * RR[1] EL_lo_all.append(EL_lo) check(f"{label}: E_P L_obs > 1/25 (direct enclosure)", EL_lo > Fr(1, 25), f"E_P L >= {dec(EL_lo, 8)}") EL_paper = claimed["q_lo"] - Cdelta * claimed["delta_hi"] - CG * claimed["AG_hi"] - CR * claimed["R_hi"] check("E_P L_obs > 1/25 from the four printed endpoints", EL_paper > Fr(1, 25), f"{dec(EL_paper, 8)}") # ====================================================================== print("\nD. Word normalisation: all 6^7 words over {a, b1..b5}") # ====================================================================== labels = ["a", 0, 1, 2, 3, 4] def basis(ya, yb): e = Fr(1 if ya == "a" else 0) F = [Fr(1) / t if (ya == "a" and yb == l) else Fr(0) for l in range(5)] Fx = (F[1] - F[0]) / 4 Fy = e - (F[0] + F[1]) / 4 return [e, Fx, Fy] + [Fr(1 if ya == l else 0) for l in range(5)], F def word_features(y0, yt, yh, yht): """Future functional of (Y_0, Y_t, Y_h, Y_{h+t}); theta applies it to (Y_0, Y_{-t}, Y_{-h}, Y_{-h-t}).""" v, F = basis(y0, yt) vs, _ = basis(yh, yht) e, Fx, Fy = v[0], v[1], v[2] Gs = [] for l in (2, 3, 4): Fr_l = F[l] - bvec[l] * e - mx[l] * Fx - my[l] * Fy Gs.append(Fr_l + Fr(842, 25) * t * e - 2 * t * Fy if l == 3 else Fr_l + Fr(147, 5) * t * e) FR = [vs[j] - sum(Ah[i][j] * v[i] for i in range(8)) for j in (E_, X_, Y_)] return (e, Fx, Fy, tuple(Gs), tuple(FR)) B = (60 + 3 * Cdelta + (1 + 7 * t) ** 2 * CG + Fr(121, 400) * CR) / t ** 2 maxL, minL = None, None maxG2 = maxFR2 = Fr(0) bounds_ok = True ndistinct = {} for y0 in labels: # L_obs depends on a word only through Y_0, the future half-vector of # (Y_0,Y_t,Y_h,Y_{h+t}) and the reflected half-vector of # (Y_0,Y_{-t},Y_{-h},Y_{-h-t}); both range over the same set for fixed Y_0. vecs = {word_features(y0, a, b, c) for a in labels for b in labels for c in labels} ndistinct[y0] = len(vecs) for f in vecs: maxG2 = max(maxG2, sum(x * x for x in f[3])) maxFR2 = max(maxFR2, sum(x * x for x in f[4])) for pv in vecs: # past (theta) half for f in vecs: # future half e, Fx, Fy = f[0], f[1], f[2] q = d0 * e + d1 * Fx + d2 * Fy + d3 * pv[1] * Fx + d4 * pv[1] * Fy dl = e - pv[1] * Fx - pv[2] * Fy Go = sum(a * b for a, b in zip(pv[3], f[3])) Ro = sum(a * b for a, b in zip(pv[4], f[4])) L = q / h - Cdelta * dl - CG * Go - CR * Ro bounds_ok &= (abs(q / h) <= 60 / t ** 2 and abs(dl) <= 3 / t ** 2 and abs(Go) <= (1 + 7 * t) ** 2 / t ** 2 and abs(Ro) <= Fr(121, 400) / t ** 2) maxL = L if maxL is None else max(maxL, L) minL = L if minL is None else min(minL, L) print(f" distinct half-word feature vectors per Y_0: {ndistinct}") check("||G|| <= (1+7t)/t on every half-word", maxG2 <= ((1 + 7 * t) / t) ** 2, f"max ||G|| t = {dec((Decimal(maxG2.numerator) / Decimal(maxG2.denominator)).sqrt() * Decimal(t.numerator) / Decimal(t.denominator), 8)}") check("||F_R|| <= 11/(20t) on every half-word", maxFR2 <= (Fr(11, 20) / t) ** 2, f"max ||F_R|| t = {dec((Decimal(maxFR2.numerator) / Decimal(maxFR2.denominator)).sqrt() * Decimal(t.numerator) / Decimal(t.denominator), 6)}") check("|q/h| <= 60/t^2, |delta| <= 3/t^2, |G_obs| <= (1+7t)^2/t^2, |R_obs| <= 121/(400t^2)", bounds_ok) check("|L_obs| <= B on every word (so 0 <= W <= 1)", -B <= minL and maxL <= B, f"min L = {dec(minL, 4)}, max L = {dec(maxL, 4)}, B = {dec(B, 6)}") # ====================================================================== print("\nE. Margin and entropy-production floor (Theorem 3.5)") # ====================================================================== c_ = Fr(1, 2) + 1 / (192 * B) eta = Fr(71, 4800) / B check("c = (1/96 + B)/(2B)", c_ == (Fr(1, 96) + B) / (2 * B)) check("eta = (1/25 + B)/(2B) - c = (1/25 - 1/96)/(2B) = 71/(4800B)", eta == (Fr(1, 25) + B) / (2 * B) - c_ and Fr(1, 25) - Fr(1, 96) == Fr(71, 2400)) T = 2 * (h + t) floor = 8 * eta ** 2 / T print(f" B = {dec(B, 10)}") print(f" eta = {dec(eta, 10)}") print(f" 8eta^2/T = {dec(floor, 10)} (T = 2(h+t))") check("eta rounds to 1.2398e-26 (value quoted in the paper)", f"{dec(eta, 4)}" == "1.2398e-26") check("8 eta^2/T rounds to 6.1475e-49 (value quoted in the paper)", f"{dec(floor, 4)}" == "6.1475e-49") print() if FAILS: print(f"{len(FAILS)} CHECK(S) FAILED:") for f in FAILS: print(" -", f) sys.exit(1) print("ALL CHECKS PASSED")