#!/usr/bin/env python3 """ =============================================================================== 100% EXACT SYMBOLIC & RATIONAL VERIFIER FOR GYIRES CONJECTURE 20 AT n = 4 AND ITS STRONGER SINGLE-TERM FORM: 32 * per(A)^2 >= 3 * per(A A^T) for all A in Omega_4, equality iff A = J_4. ZERO floating-point arithmetic is used in any proof check (pure Python 3 fractions.Fraction, exact multivariate polynomial algebra over Q, plus compilation and execution of the exact __int128 Q30 C++20 4D certifier). =============================================================================== """ from fractions import Fraction import itertools import os import random import subprocess import sys # --------------------------------------------------------------------------- # Minimal exact multivariate polynomial arithmetic over Q[x_0, ..., x_{k-1}] # Representation: dict[tuple[int, ...], Fraction], zero coeffs omitted. # --------------------------------------------------------------------------- def p_zero(): return {} def p_const(c, nvars): c = Fraction(c) return {(0,) * nvars: c} if c != 0 else {} def p_var(idx, nvars): e = [0] * nvars e[idx] = 1 return {tuple(e): Fraction(1)} def p_add(a, b, scale=Fraction(1)): out = dict(a) for k, v in b.items(): nv = out.get(k, Fraction(0)) + scale * v if nv == 0: out.pop(k, None) else: out[k] = nv return out def p_sub(a, b): return p_add(a, b, Fraction(-1)) def p_scale(a, c): c = Fraction(c) if c == 0: return {} return {k: v * c for k, v in a.items()} def p_mul(a, b): if not a or not b: return {} out = {} for k1, v1 in a.items(): for k2, v2 in b.items(): k = tuple(x + y for x, y in zip(k1, k2)) nv = out.get(k, Fraction(0)) + v1 * v2 if nv == 0: out.pop(k, None) else: out[k] = nv return out def p_pow(a, e, nvars): res = p_const(1, nvars) for _ in range(e): res = p_mul(res, a) return res def mat_mul_exact(A, B): n = len(A) return [[sum(A[i][k] * B[k][j] for k in range(n)) for j in range(n)] for i in range(n)] def mat_T(A): n = len(A) return [[A[j][i] for j in range(n)] for i in range(n)] def perm_exact(M): n = len(M) total = Fraction(0) for p in itertools.permutations(range(n)): prod = Fraction(1) for i in range(n): prod *= M[i][p[i]] total += prod return total def perm_poly(M, nvars): n = len(M) total = p_zero() for p in itertools.permutations(range(n)): prod = p_const(1, nvars) for i in range(n): prod = p_mul(prod, M[i][p[i]]) total = p_add(total, prod) return total # Walsh-Hadamard matrix H (4x4, symmetric orthogonal) H = [ [Fraction(1, 2), Fraction(1, 2), Fraction(1, 2), Fraction(1, 2)], [Fraction(1, 2), Fraction(1, 2), Fraction(-1, 2), Fraction(-1, 2)], [Fraction(1, 2), Fraction(-1, 2), Fraction(1, 2), Fraction(-1, 2)], [Fraction(1, 2), Fraction(-1, 2), Fraction(-1, 2), Fraction(1, 2)], ] # --------------------------------------------------------------------------- # CHECK 1 (Lemma L1): Walsh-Hadamard orthogonality, S_3 symmetry, J_4 equality # --------------------------------------------------------------------------- def check_L1_walsh_group(): print("[check_L1_walsh_group] Verifying H orthogonality, S_3 row-perm conjugation, J_4 equality...") I4 = [[Fraction(1 if i == j else 0) for j in range(4)] for i in range(4)] assert H == mat_T(H), "H must be symmetric" assert mat_mul_exact(H, H) == I4, "H^2 must be I_4" J4 = [[Fraction(1, 4)] * 4 for _ in range(4)] HJ4H = mat_mul_exact(mat_mul_exact(H, J4), H) expected_J = [[Fraction(1 if (i == 0 and j == 0) else 0) for j in range(4)] for i in range(4)] assert HJ4H == expected_J # Check equality case at A = J_4 pJ = perm_exact(J4) assert pJ == Fraction(3, 32) assert 32 * pJ * pJ == 3 * pJ # Verify Stab_{S_4}(0) ~= S_3 conjugates under H to ALL 6 3x3 permutation matrices! perm3_seen = set() for p3 in itertools.permutations([1, 2, 3]): pi = (0,) + p3 Q = [[Fraction(1 if pi[i] == j else 0) for j in range(4)] for i in range(4)] HQH = mat_mul_exact(mat_mul_exact(H, Q), H) assert HQH[0] == [Fraction(1), Fraction(0), Fraction(0), Fraction(0)] for r in range(1, 4): assert HQH[r][0] == 0 block = tuple(tuple(HQH[r][c] for c in range(1, 4)) for r in range(1, 4)) # Confirm block is a 3x3 permutation matrix for r in range(3): assert sorted(block[r]) == [Fraction(0), Fraction(0), Fraction(1)] for c in range(3): assert sorted(block[r][c] for r in range(3)) == [Fraction(0), Fraction(0), Fraction(1)] perm3_seen.add(block) assert len(perm3_seen) == 6, "Must generate all 6 permutations of the 3 rows of Y" print(" PASS: H^2 = I_4, H J_4 H = diag(1,0,0,0), all 6 S_3 row permutations exact.") # --------------------------------------------------------------------------- # CHECK 2 (Lemma L2): Exact Symbolic Polynomial Permanent Identity over Q[X] # --------------------------------------------------------------------------- def check_L2_perm_identity(): print("[check_L2_perm_identity] Verifying exact degree-4 identity in Q[x_11..x_33]...") nvars = 9 X = [[p_var(3 * i + j, nvars) for j in range(3)] for i in range(3)] # Build M = H diag(1, X) H symbolically D = [[p_zero() for _ in range(4)] for _ in range(4)] D[0][0] = p_const(1, nvars) for i in range(3): for j in range(3): D[i + 1][j + 1] = X[i][j] HD = [[p_zero() for _ in range(4)] for _ in range(4)] for i in range(4): for j in range(4): s = p_zero() for k in range(4): if H[i][k] != 0: s = p_add(s, p_scale(D[k][j], H[i][k])) HD[i][j] = s M = [[p_zero() for _ in range(4)] for _ in range(4)] for i in range(4): for j in range(4): s = p_zero() for k in range(4): if H[k][j] != 0: s = p_add(s, p_scale(HD[i][k], H[k][j])) M[i][j] = s lhs = perm_poly(M, nvars) # Compute RHS terms symbolically norm2 = p_zero() for i in range(3): for j in range(3): norm2 = p_add(norm2, p_mul(X[i][j], X[i][j])) perX = perm_poly(X, nvars) norm4 = p_mul(norm2, norm2) # ||X X^T||_F^2 = sum_{i,j} (sum_k X_ik X_jk)^2 u_poly = p_zero() for i in range(3): for j in range(3): dot = p_zero() for k in range(3): dot = p_add(dot, p_mul(X[i][k], X[j][k])) u_poly = p_add(u_poly, p_mul(dot, dot)) # Q(X) = Q_row(X) + Q_col(X) Q_poly = p_zero() for i in range(3): for j1 in range(3): for j2 in range(j1 + 1, 3): Q_poly = p_add(Q_poly, p_mul(p_mul(X[i][j1], X[i][j1]), p_mul(X[i][j2], X[i][j2]))) for j in range(3): for i1 in range(3): for i2 in range(i1 + 1, 3): Q_poly = p_add(Q_poly, p_mul(p_mul(X[i1][j], X[i1][j]), p_mul(X[i2][j], X[i2][j]))) rhs = p_const(Fraction(3, 32), nvars) rhs = p_add(rhs, p_scale(norm2, Fraction(1, 16))) rhs = p_add(rhs, p_scale(perX, Fraction(1, 4))) rhs = p_add(rhs, p_scale(norm4, Fraction(1, 32))) rhs = p_add(rhs, p_scale(u_poly, Fraction(1, 16))) rhs = p_add(rhs, p_scale(Q_poly, Fraction(-3, 8))) diff = p_sub(lhs, rhs) assert diff == {}, f"Permanent identity mismatch: {len(diff)} nonzero terms" # Also verify (1/4)*per(X) == (1/6)*sum_{i,j} E_{ij}^3 where E = M - J_4 S3_E = p_zero() c14 = p_const(Fraction(1, 4), nvars) for i in range(4): for j in range(4): Eij = p_sub(M[i][j], c14) S3_E = p_add(S3_E, p_pow(Eij, 3, nvars)) diff_cub = p_sub(p_scale(perX, Fraction(1, 4)), p_scale(S3_E, Fraction(1, 6))) assert diff_cub == {}, "Cubic identity (1/4)*per(X) == (1/6)*S_3(E) failed" print(f" PASS: Exact Q[X] permanent identity ({len(lhs)} monomials) and cubic identity verified with 0 residual.") # --------------------------------------------------------------------------- # CHECK 3 (Lemma L3): Sharp 3-Vector Quartic Bound q*(R) Algebraic Identities # --------------------------------------------------------------------------- def check_L3_qstar_identities(): print("[check_L3_qstar_identities] Verifying exact algebraic identities for q*(R) and s_min(R)...") # Univariate polynomial in u (nvars=1) u = p_var(0, 1) c1 = p_const(1, 1) # 1. 16 + 8*t^3 + 3*t^4 - 3*(t^2 + 2)^2 == 4*(1 - t)^2*(1 + 2*t) lhs1 = p_add(p_const(16, 1), p_add(p_scale(p_pow(u, 3, 1), 8), p_scale(p_pow(u, 4, 1), 3))) lhs1 = p_sub(lhs1, p_scale(p_pow(p_add(p_pow(u, 2, 1), p_const(2, 1)), 2, 1), 3)) rhs1 = p_scale(p_mul(p_pow(p_sub(c1, u), 2, 1), p_add(c1, p_scale(u, 2))), 4) assert p_sub(lhs1, rhs1) == {} # 2. Derivative of h(u) = (16 + 8 u^3 + 3 u^4) / (12 (u^2 + 2)^2): # Let N(u) = 16 + 8 u^3 + 3 u^4, D(u) = (u^2 + 2)^2. # N'(u) D(u) - N(u) D'(u) = (u^2 + 2) * [-8 u (1 - u)(u + 2)(4 - u)] N = p_add(p_const(16, 1), p_add(p_scale(p_pow(u, 3, 1), 8), p_scale(p_pow(u, 4, 1), 3))) Np = p_add(p_scale(p_pow(u, 2, 1), 24), p_scale(p_pow(u, 3, 1), 12)) D_base = p_add(p_pow(u, 2, 1), p_const(2, 1)) D = p_pow(D_base, 2, 1) Dp = p_mul(p_scale(u, 4), D_base) num_hprime = p_sub(p_mul(Np, D), p_mul(N, Dp)) factored = p_mul( D_base, p_scale( p_mul(p_mul(u, p_sub(c1, u)), p_mul(p_add(u, p_const(2, 1)), p_sub(p_const(4, 1), u))), -8 ) ) assert p_sub(num_hprime, factored) == {} # 3. Derivative of R^2 - 2 q*(R) on [1/3, 1/2], where R = (t^2 + 2)/6 and q*'(R) = t(2+t)/12: # 2*R - 2*q*'(R) = (t^2 + 2)/3 - t(2+t)/6 = ((t - 1)^2 + 3)/6 > 0! R_of_t = p_scale(p_add(p_pow(u, 2, 1), p_const(2, 1)), Fraction(1, 6)) qp_of_t = p_scale(p_mul(u, p_add(u, p_const(2, 1))), Fraction(1, 12)) deriv = p_sub(p_scale(R_of_t, 2), p_scale(qp_of_t, 2)) expected_deriv = p_scale(p_add(p_pow(p_sub(u, c1), 2, 1), p_const(3, 1)), Fraction(1, 6)) assert p_sub(deriv, expected_deriv) == {} # 4. Exact continuity at R = 1/3 (t = 0) and R = 1/2 (t = 1) assert Fraction(1, 3)**2 / 3 == Fraction(16, 432) == Fraction(1, 27) assert Fraction(16 + 8 + 3, 432) == Fraction(1, 16) == (1 - Fraction(1, 2))**2 / 4 # 5. Exact check of minimum of w^3 - p1 w^2 + p2 w on [0, infty) at w_+ = (2 p1 + sqrt(4 p1^2 - 12 p2))/6: # With p2 = (p1^2 - R)/2 and u = sqrt(6R/p1^2 - 2), 4 p1^2 - 12 p2 = 6R - 2 p1^2 = p1^2 u^2, # so w_+ = p1 (2 + u) / 6, p3_min = w_+^3 - p1 w_+^2 + p2 w_+ = p1^3 (2 + u)(u - 1)^2 / 108? Wait: # Let's verify exact p2^2 - 2 p1 p3_min == R^2 * (16 + 8 u^3 + 3 u^4) / (12 (u^2 + 2)^2) symbolically in Q[p1, u]! p1 = p_var(0, 2) uu = p_var(1, 2) R_pu = p_scale(p_mul(p_pow(p1, 2, 2), p_add(p_pow(uu, 2, 2), p_const(2, 2))), Fraction(1, 6)) p2_pu = p_scale(p_sub(p_pow(p1, 2, 2), R_pu), Fraction(1, 2)) wp = p_scale(p_mul(p1, p_add(p_const(2, 2), uu)), Fraction(1, 6)) # p3_min = wp^3 - p1 wp^2 + p2 wp (note: at w_+, local min of f(w) = w^3 - p1 w^2 + p2 w; check f(w_+) >= 0 iff u <= 1!) p3_min = p_add(p_sub(p_pow(wp, 3, 2), p_mul(p1, p_pow(wp, 2, 2))), p_mul(p2_pu, wp)) # Verify f'(w_+) = 3 wp^2 - 2 p1 wp + p2 == 0! fp_wp = p_add(p_sub(p_scale(p_pow(wp, 2, 2), 3), p_scale(p_mul(p1, wp), 2)), p2_pu) assert fp_wp == {}, "w_+ must be exact critical point of w^3 - p1 w^2 + p2 w" # Verify p3_min = p1^3 (2 + u)^2 (1 - u) / 108 (attained at x = y = p1*(2+u)/6, z = p1*(1-u)/3 >= 0)! p3_expected = p_scale( p_mul(p_pow(p1, 3, 2), p_mul(p_pow(p_add(p_const(2, 2), uu), 2, 2), p_sub(p_const(1, 2), uu))), Fraction(1, 108) ) assert p_sub(p3_min, p3_expected) == {}, "p3_min formula mismatch" # And check q_max = p2^2 - 2 p1 p3_min == (p1^4 / 432) * (16 + 8 u^3 + 3 u^4)! q_max_pu = p_sub(p_pow(p2_pu, 2, 2), p_scale(p_mul(p1, p3_min), 2)) q_expected = p_scale( p_mul(p_pow(p1, 4, 2), p_add(p_const(16, 2), p_add(p_scale(p_pow(uu, 3, 2), 8), p_scale(p_pow(uu, 4, 2), 3)))), Fraction(1, 432) ) assert p_sub(q_max_pu, q_expected) == {}, "q_max formula mismatch" print(" PASS: All 5 exact algebraic identities for q*(R) and s_min(R) verified with 0 residual.") # --------------------------------------------------------------------------- # CHECK 4 (Lemma L4): Cubic Permanent Cauchy-Schwarz Identity # --------------------------------------------------------------------------- def check_L4_cubic_identities(): print("[check_L4_cubic_identities] Verifying exact permanent Cauchy-Schwarz identity...") # 6 variables: v1, v2, v3, w1, w2, w3 v = [p_var(i, 6) for i in range(3)] w = [p_var(3 + i, 6) for i in range(3)] star = [ p_add(p_mul(v[1], w[2]), p_mul(v[2], w[1])), p_add(p_mul(v[0], w[2]), p_mul(v[2], w[0])), p_add(p_mul(v[0], w[1]), p_mul(v[1], w[0])), ] lhs = p_add(p_pow(star[0], 2, 6), p_add(p_pow(star[1], 2, 6), p_pow(star[2], 2, 6))) v2 = p_add(p_pow(v[0], 2, 6), p_add(p_pow(v[1], 2, 6), p_pow(v[2], 2, 6))) w2 = p_add(p_pow(w[0], 2, 6), p_add(p_pow(w[1], 2, 6), p_pow(w[2], 2, 6))) vw = p_add(p_mul(v[0], w[0]), p_add(p_mul(v[1], w[1]), p_mul(v[2], w[2]))) pen = p_zero() for j in range(3): for k in range(j + 1, 3): d = p_sub(p_mul(v[j], w[j]), p_mul(v[k], w[k])) pen = p_add(pen, p_pow(d, 2, 6)) rhs = p_add(p_mul(v2, w2), p_add(p_scale(p_pow(vw, 2, 6), Fraction(1, 3)), p_scale(pen, Fraction(-2, 3)))) assert p_sub(lhs, rhs) == {}, "v * w identity failed" print(" PASS: ||v star w||_2^2 == ||v||^2 ||w||^2 + (1/3)^2 - (2/3) sum (v_j w_j - v_k w_k)^2 exact.") # --------------------------------------------------------------------------- # CHECK 5 (Lemmas L7 & L8): Newton Quartic, Symmetric 3x3 Z Identities, det3 # --------------------------------------------------------------------------- def check_L7_newton_and_det(): print("[check_L7_newton_and_det] Verifying Newton quartic, Z-matrix identities, and det3 identity...") # 1. Newton quartic in Q[l1, l2, l3] l = [p_var(i, 3) for i in range(3)] s = p_add(l[0], p_add(l[1], l[2])) u = p_add(p_pow(l[0], 2, 3), p_add(p_pow(l[1], 2, 3), p_pow(l[2], 2, 3))) w = p_add(p_pow(l[0], 4, 3), p_add(p_pow(l[1], 4, 3), p_pow(l[2], 4, 3))) detZ = p_mul(p_mul(l[0], l[1]), l[2]) s2 = p_pow(s, 2, 3) s4 = p_pow(s, 4, 3) u2 = p_pow(u, 2, 3) newton_rhs = p_add( p_scale(p_sub(p_add(u2, p_scale(p_mul(s2, u), 2)), s4), Fraction(1, 2)), p_scale(p_mul(s, detZ), 4) ) assert p_sub(w, newton_rhs) == {}, "Newton quartic identity failed" # Also check (1/32) u^2 + (1/16) w == (3 u^2 - (s^2 - u)^2)/32 + (s/4) detZ comb_lhs = p_add(p_scale(u2, Fraction(1, 32)), p_scale(w, Fraction(1, 16))) comb_rhs = p_add( p_scale(p_sub(p_scale(u2, 3), p_pow(p_sub(s2, u), 2, 3)), Fraction(1, 32)), p_scale(p_mul(s, detZ), Fraction(1, 4)) ) assert p_sub(comb_lhs, comb_rhs) == {} # Also check det(I - Z) = 1 - s + (s^2 - u)/2 - detZ detImZ = p_mul(p_mul(p_sub(p_const(1, 3), l[0]), p_sub(p_const(1, 3), l[1])), p_sub(p_const(1, 3), l[2])) detImZ_rhs = p_sub(p_add(p_sub(p_const(1, 3), s), p_scale(p_sub(s2, u), Fraction(1, 2))), detZ) assert p_sub(detImZ, detImZ_rhs) == {} # 2. Symmetric 3x3 matrix Z = [[a,d,e],[d,b,f],[e,f,c]] in Q[a,b,c,d,e,f] a, b, c, d, e, f = [p_var(i, 6) for i in range(6)] Z = [[a, d, e], [d, b, f], [e, f, c]] perZ = perm_poly(Z, 6) detZ_sym = p_sub( p_add(p_mul(p_mul(a, b), c), p_scale(p_mul(p_mul(d, e), f), 2)), p_add(p_mul(a, p_pow(f, 2, 6)), p_add(p_mul(b, p_pow(e, 2, 6)), p_mul(c, p_pow(d, 2, 6)))) ) off_expected = p_scale( p_add(p_mul(a, p_pow(f, 2, 6)), p_add(p_mul(b, p_pow(e, 2, 6)), p_mul(c, p_pow(d, 2, 6)))), 2 ) assert p_sub(p_sub(perZ, detZ_sym), off_expected) == {} # Q(Z) = Q_row(Z) + Q_col(Z) QZ = p_zero() for i in range(3): for j1 in range(3): for j2 in range(j1 + 1, 3): QZ = p_add(QZ, p_mul(p_pow(Z[i][j1], 2, 6), p_pow(Z[i][j2], 2, 6))) for j in range(3): for i1 in range(3): for i2 in range(i1 + 1, 3): QZ = p_add(QZ, p_mul(p_pow(Z[i1][j], 2, 6), p_pow(Z[i2][j], 2, 6))) a2, b2, c2, d2, e2, f2 = [p_pow(v, 2, 6) for v in (a, b, c, d, e, f)] QZ_expected = p_scale( p_add( p_add(p_mul(p_add(a2, b2), d2), p_mul(p_add(a2, c2), e2)), p_add( p_mul(p_add(b2, c2), f2), p_add(p_mul(d2, e2), p_add(p_mul(d2, f2), p_mul(e2, f2))) ) ), 2 ) assert p_sub(QZ, QZ_expected) == {} # 3. 1-line determinant bound identity in Q[r, x]: # (1/4) r^3 - (x^3 - (3/4) r^2 x) == (1/4) (r - x) (2 x + r)^2 r_v, x_v = p_var(0, 2), p_var(1, 2) det_id_lhs = p_sub(p_scale(p_pow(r_v, 3, 2), Fraction(1, 4)), p_sub(p_pow(x_v, 3, 2), p_scale(p_mul(p_pow(r_v, 2, 2), x_v), Fraction(3, 4)))) det_id_rhs = p_scale(p_mul(p_sub(r_v, x_v), p_pow(p_add(p_scale(x_v, 2), r_v), 2, 2)), Fraction(1, 4)) assert p_sub(det_id_lhs, det_id_rhs) == {} # And s^3 - 3 s d^2 + 2 d^3 == (s - d)^2 (s + 2 d) sv, dv = p_var(0, 2), p_var(1, 2) phi_lhs = p_add(p_sub(p_pow(sv, 3, 2), p_scale(p_mul(sv, p_pow(dv, 2, 2)), 3)), p_scale(p_pow(dv, 3, 2), 2)) phi_rhs = p_mul(p_pow(p_sub(sv, dv), 2, 2), p_add(sv, p_scale(dv, 2))) assert p_sub(phi_lhs, phi_rhs) == {} print(" PASS: Newton quartic, det(I-Z), symmetric Z identities, and det3 factorization all exact.") # --------------------------------------------------------------------------- # CHECK 6 (Lemma L9): Exact Analytic Ball 0 < s <= 9/20 over Q # --------------------------------------------------------------------------- def poly1_mul(a, b): res = [Fraction(0)] * (len(a) + len(b) - 1) for i, x in enumerate(a): for j, y in enumerate(b): res[i + j] += x * y return res def poly1_add(a, b, sc=Fraction(1)): n = max(len(a), len(b)) return [(a[i] if i < len(a) else Fraction(0)) + sc * (b[i] if i < len(b) else Fraction(0)) for i in range(n)] def check_L9_analytic_ball(): print("[check_L9_analytic_ball] Verifying exact rational analytic ball 0 < s <= 9/20...") # Rational upper bound 1/(36*sqrt(2)) < 1/50 assert 50 * 50 < 2 * 36 * 36 # 2500 < 2592 # Range 1: 0 < t = sqrt(s) <= 1/2 (i.e. 0 < s <= 1/4) # L0(t) = 3/32 + t^2/16 - t^3/18 - 3*t^4/32 # dF/du(u = s^2) = 4*L0(t) - 3/16 - t^2/4 - (5/16)*t^4 = 3/16 - (2/9)*t^3 - (11/16)*t^4 L0_t = [Fraction(3, 32), Fraction(0), Fraction(1, 16), Fraction(-1, 18), Fraction(-3, 32)] dF_t = poly1_add( [4 * c for c in L0_t], [Fraction(3, 16), Fraction(0), Fraction(1, 4), Fraction(0), Fraction(5, 16)], Fraction(-1) ) assert dF_t == [Fraction(3, 16), Fraction(0), Fraction(0), Fraction(-2, 9), Fraction(-11, 16)] t_half = Fraction(1, 2) dF_t_min = sum(c * (t_half ** k) for k, c in enumerate(dF_t)) assert dF_t_min == Fraction(269, 2304) and dF_t_min > 0 # Check L_mid(t) > 0 on [0, 1/2]: L_mid = 3/32 + t^2/16 - t^3/18 - t^4/16 Lmid_t = [Fraction(3, 32), Fraction(0), Fraction(1, 16), Fraction(-1, 18), Fraction(-1, 16)] Lmid_t_lb = Lmid_t[0] + sum(c * (t_half ** k) for k, c in enumerate(Lmid_t) if k > 0 and c < 0) assert Lmid_t_lb > 0 # G_mid(t^2) = 32 * Lmid_t^2 - 3 * (3/32 + t^4/32 + t^6/50 + 3*t^8/128) = t^2 * P1(t) U_t = [Fraction(3, 32), Fraction(0), Fraction(0), Fraction(0), Fraction(1, 32), Fraction(0), Fraction(1, 50), Fraction(0), Fraction(3, 128)] G1_t = poly1_add([32 * c for c in poly1_mul(Lmid_t, Lmid_t)], U_t, Fraction(-3)) assert G1_t[0] == 0 and G1_t[1] == 0 P1_t = G1_t[2:] expected_P1 = [ Fraction(3, 8), Fraction(-1, 3), Fraction(-11, 32), Fraction(-2, 9), Fraction(-1711, 8100), Fraction(2, 9), Fraction(7, 128) ] assert P1_t == expected_P1 P1_lb = P1_t[0] + sum(c * (t_half ** k) for k, c in enumerate(P1_t) if k > 0 and c < 0) assert P1_lb == Fraction(21103, 259200) and P1_lb > 0 # Range 2: 1/4 <= s <= 9/20 # L0(s) = 3/32 + s/16 + (s^2 - s)/24 - 3*s^2/32 = 3/32 + s/48 - (5/96)*s^2 L0_s = [Fraction(3, 32), Fraction(1, 48), Fraction(-5, 96)] dF_s = poly1_add( [4 * c for c in L0_s], [Fraction(3, 16), Fraction(1, 4), Fraction(5, 16)], Fraction(-1) ) assert dF_s == [Fraction(3, 16), Fraction(-1, 6), Fraction(-25, 48)] s45 = Fraction(9, 20) dF_s_min = sum(c * (s45 ** k) for k, c in enumerate(dF_s)) assert dF_s_min == Fraction(9, 1280) and dF_s_min > 0 # L_mid(s) = 3/32 + (s - s^2)/48 > 0 for all s in [0, 1] Lmid_s = [Fraction(3, 32), Fraction(1, 48), Fraction(-1, 48)] assert Lmid_s[0] + Lmid_s[1] * s45 + Lmid_s[2] * s45 * s45 > 0 U_s = [Fraction(3, 32), Fraction(0), Fraction(1, 32), Fraction(1, 50), Fraction(3, 128)] G2_s = poly1_add([32 * c for c in poly1_mul(Lmid_s, Lmid_s)], U_s, Fraction(-3)) assert G2_s[0] == 0 P2_s = G2_s[1:] expected_P2 = [Fraction(1, 8), Fraction(-59, 288), Fraction(-79, 900), Fraction(-65, 1152)] assert P2_s == expected_P2 assert all(c < 0 for c in P2_s[1:]), "All degree >= 1 coeffs of P2(s) are strictly negative" P2_min = sum(c * (s45 ** k) for k, c in enumerate(P2_s)) assert P2_min == Fraction(50667, 5120000) and P2_min > 0 print(f" PASS: Range 1 (0 < t <= 1/2): dF/du >= {dF_t_min}, P1(t) >= {P1_lb} > 0.") print(f" PASS: Range 2 (1/4 <= s <= 9/20): dF/du >= {dF_s_min}, P2(s) >= {P2_min} > 0.") # --------------------------------------------------------------------------- # CHECK 7 (Lemma L10 + End-to-End Exact Stress Check): C++20 Q30 Certifier # --------------------------------------------------------------------------- def check_L10_exact_4d_certifier(): print("[check_L10_exact_4d_certifier] Compiling & running zero-float __int128 Q30 4D certifier...") base = os.path.dirname(os.path.abspath(__file__)) cpp = os.path.join(base, "certify_4d_exact.cpp") exe = os.path.join(base, "certify_4d_exact") subprocess.run( ["clang++", "-O3", "-std=c++20", "-pthread", "-Wall", "-Wextra", "-Werror", cpp, "-o", exe], check=True ) res = subprocess.run([exe], check=True, capture_output=True, text=True) print(res.stdout.rstrip()) assert "CERTIFICATION COMPLETE" in res.stdout assert "Tree check: EXACT" in res.stdout assert "> 0 strictly!" in res.stdout # Independent exact-rational stress check on 500 random matrices in Omega_4 + extremal circulant! print("[check_exact_omega4_samples] Cross-checking 500 exact rational matrices in Omega_4...") perms4 = list(itertools.permutations(range(4))) rng = random.Random(20261127) # First check extremal circulant C = (1/2)*(I_4 + P_(1234)) where G_4(C)/s = 5/64 C_ext = [ [Fraction(1, 2), Fraction(1, 2), Fraction(0), Fraction(0)], [Fraction(0), Fraction(1, 2), Fraction(1, 2), Fraction(0)], [Fraction(0), Fraction(0), Fraction(1, 2), Fraction(1, 2)], [Fraction(1, 2), Fraction(0), Fraction(0), Fraction(1, 2)], ] pC = perm_exact(C_ext) pCCt = perm_exact(mat_mul_exact(C_ext, mat_T(C_ext))) pC2 = perm_exact(mat_mul_exact(C_ext, C_ext)) sC = sum((C_ext[i][j] - Fraction(1, 4))**2 for i in range(4) for j in range(4)) G4_C = 32 * pC * pC - 3 * pCCt assert sC == Fraction(1) and pC == Fraction(1, 8) and pCCt == Fraction(9, 64) assert G4_C == Fraction(5, 64), f"Expected 5/64 at circulant, got {G4_C}" assert 2 * pC2 <= pCCt + pCCt # Test 500 exact rational convex combinations of permutation matrices # (including dyadic denominator-16/32 matrices so --check-point exercises exact Q30 outer points!) SCALE = 1 << 30 checked_outer = 0 for idx in range(500): k = rng.choice([2, 3, 4, 6, 12, 24]) chosen = rng.sample(perms4, k) if idx < 100 and k <= 6: # Exact dyadic weights summing to 16 -> all (a, b, c, K) are exact Q30! cuts = sorted([rng.randint(1, 15) for _ in range(k - 1)]) pts = [0] + cuts + [16] ws = [pts[i + 1] - pts[i] for i in range(k)] W = 16 else: ws = [rng.randint(1, 20) for _ in range(k)] W = sum(ws) A = [[Fraction(0)] * 4 for _ in range(4)] for p, w in zip(chosen, ws): if w == 0: continue frac = Fraction(w, W) for i in range(4): A[i][p[i]] += frac # Compute Y = (H A H)[1:, 1:] HAH = mat_mul_exact(mat_mul_exact(H, A), H) Y = [[HAH[i][j] for j in range(1, 4)] for i in range(1, 4)] Z = mat_mul_exact(Y, mat_T(Y)) # Verify L1: row/col l1 norms of Y <= 1 for i in range(3): assert sum(abs(Y[i][j]) for j in range(3)) <= 1 assert sum(abs(Y[j][i]) for j in range(3)) <= 1 # Verify exact single-term & full Gyires inequalities pA = perm_exact(A) pAAt = perm_exact(mat_mul_exact(A, mat_T(A))) pAtA = perm_exact(mat_mul_exact(mat_T(A), A)) pA2 = perm_exact(mat_mul_exact(A, A)) assert 2 * pA2 <= pAAt + pAtA, "Cauchy-Binet failed" G4 = 32 * pA * pA - 3 * pAAt F4 = 128 * pA * pA - 3 * (pAAt + pAtA + 2 * pA2) s = sum(Y[i][j]**2 for i in range(3) for j in range(3)) if s > 0: assert G4 > 0 and F4 > 0 else: assert G4 == 0 and F4 == 0 # Spot-check 25 outer matrices against C++ --check-point to verify gap_lo <= true G4! if s >= Fraction(9, 20) and checked_outer < 25: rows = sorted([Z[0][0], Z[1][1], Z[2][2]], reverse=True) a, b, c = rows u = sum(Z[i][j]**2 for i in range(3) for j in range(3)) K = u - (a*a + b*b + c*c) # Round to nearest Q30 grid point (check via tiny box? Wait: --check-point tests a single Q30 point; # only query exact Q30-representable points or check if certified gap_lo is sane) if all((v * SCALE).denominator == 1 for v in (a, b, c, K)): out = subprocess.run( [exe, "--check-point", str(int(a*SCALE)), str(int(b*SCALE)), str(int(c*SCALE)), str(int(K*SCALE))], check=True, capture_output=True, text=True ).stdout.strip() parts = out.split() assert parts[0] == "CERTIFIED", f"Exact Q30 feasible point not certified: {out}" gap_lo = Fraction(int(parts[1]), SCALE) assert gap_lo <= G4, f"SOUNDNESS VIOLATION: gap_lo={gap_lo} > true G4={G4}" checked_outer += 1 # Also test C_ext (exact Q30!) directly in --check-point! # For C_ext: Y has singular values (1/sqrt(2), 1/sqrt(2), 0), rows of Z are (1/2, 1/2, 0), K = 0! HAH_C = mat_mul_exact(mat_mul_exact(H, C_ext), H) Y_C = [[HAH_C[i][j] for j in range(1, 4)] for i in range(1, 4)] Z_C = mat_mul_exact(Y_C, mat_T(Y_C)) rows_C = sorted([Z_C[0][0], Z_C[1][1], Z_C[2][2]], reverse=True) u_C = sum(Z_C[i][j]**2 for i in range(3) for j in range(3)) K_C = u_C - sum(x*x for x in rows_C) assert all((v * SCALE).denominator == 1 for v in (*rows_C, K_C)) out_C = subprocess.run( [exe, "--check-point", str(int(rows_C[0]*SCALE)), str(int(rows_C[1]*SCALE)), str(int(rows_C[2]*SCALE)), str(int(K_C*SCALE))], check=True, capture_output=True, text=True ).stdout.strip() parts_C = out_C.split() assert parts_C[0] == "CERTIFIED" gap_lo_C = Fraction(int(parts_C[1]), SCALE) assert Fraction(0) < gap_lo_C <= G4_C assert checked_outer >= 25, f"Expected >= 25 exact Q30 outer points checked, got {checked_outer}" print(f" PASS: 500 exact Omega_4 matrices ({checked_outer} exact-Q30 outer points via --check-point) + C_ext verified!") print(f" At C_ext: exact G4 = {G4_C} ({float(G4_C):.6f}), certified lower bound = {float(gap_lo_C):.6f} (> 0, <= exact!).") def main(): check_L1_walsh_group() check_L2_perm_identity() check_L3_qstar_identities() check_L4_cubic_identities() check_L7_newton_and_det() check_L9_analytic_ball() check_L10_exact_4d_certifier() print("\nALL 7 EXACT VERIFICATION CHECKS PASSED WITH ZERO ERRORS!") if __name__ == "__main__": main()