Research source · python
verify-longitude-difference.py
site/public/evidence/dehn-filled-quantum-trace/longitude-difference-attack/verify-longitude-difference.py
318 lines. Source is displayed for inspection; it is not executed by this page.
File fingerprint
SHA-256: bb34138384b50fdaf9c707e32558bc794ce769a31f1d985dff060a7fa5c41a3a
#!/usr/bin/env python3
"""Exact, standard-library audit of the longitude-difference attack.
No topological inputs or configurations are searched. One explicitly defined
algebraic witness is checked, including an all-orders finite relation
certificate. Its finite series check uses proved degree bounds and is only
an independent normalization check, not the proof of cancellation.
"""
from collections import defaultdict
from fractions import Fraction as Q
from functools import lru_cache
from pathlib import Path
import json
import math
class QT:
"""Z[B^+-1] quantum torus, PBW order x1,y1,x2,y2,x3,y3.
y_j*x_j=B^4*x_j*y_j. B=i*A, hence B^4=A^4.
A monomial is (B exponent, x1,y1,x2,y2,x3,y3).
"""
def __init__(self, terms=None):
self.terms = {m: c for m, c in (terms or {}).items() if c}
@staticmethod
def of(value):
return value if isinstance(value, QT) else QT({(0,)*7: value})
@staticmethod
def var(i):
m = [0]*7
m[i] = 1
return QT({tuple(m): 1})
def __add__(self, other):
out = defaultdict(int, self.terms)
for m, c in QT.of(other).terms.items():
out[m] += c
return QT(out)
__radd__ = __add__
def __neg__(self):
return QT({m: -c for m, c in self.terms.items()})
def __sub__(self, other):
return self + (-QT.of(other))
def __rsub__(self, other):
return QT.of(other) - self
def __mul__(self, other):
out = defaultdict(int)
for a, c in self.terms.items():
for b, d in QT.of(other).terms.items():
m = [x+y for x, y in zip(a, b)]
m[0] += 4*sum(a[j+1]*b[j] for j in (1, 3, 5))
out[tuple(m)] += c*d
return QT(out)
__rmul__ = __mul__
def __pow__(self, n):
if n < 0:
assert len(self.terms) == 1
(m, c), = self.terms.items()
assert c in (1, -1)
inv = [-x for x in m]
inv[0] += 4*sum(m[j+1]*m[j] for j in (1, 3, 5))
return QT({tuple(inv): c})**(-n)
out = QT.of(1)
for _ in range(n):
out = out*self
return out
def __eq__(self, other):
return self.terms == QT.of(other).terms
checks = []
def check(name, assertion):
if not assertion:
raise AssertionError(name)
checks.append(name)
print(f"PASS {len(checks):02d}: {name}")
B, x1, y1, x2, y2, X, Y = (QT.var(j) for j in range(7))
check("squared-root PBW convention", Y*X == B**4*X*Y)
check("PBW Laurent inverse", (X*Y)**-1*(X*Y) == 1)
f1, f2, f3 = x1**-1+y1-1, x2**-1+y2-1, X**-1+Y-1
E1 = y1*y2**-1+1
E2 = y1**-2*Y**-2-B**-5
E3 = Y-B
check("exact first native scalar c_e1=A^2=-B^2",
-B**2*E1 == -B**2*y1*y2**-1-B**2)
check("exact second native scalar c_e2=B^7",
B**7*E2 == B**7*y1**-2*Y**-2-B**2)
check("exact native meridian scalar c_m=B",
B*E3 == B*Y-B**2)
# c_l=B^-1; W(2b)=A^2*x1^-1*x2^-1*X*Y=-B^2*...
l_squared = -x1**-1*x2**-1*X*Y
check("the exact longitude square retains its crucial minus sign",
B**-2*(-B**2*x1**-1*x2**-1*X*Y) == l_squared)
tetra_terms = X*Y*x2**-1*f1 + X*Y*(1-y1)*f2 + X*f3
moment_terms = (E1*y2*(y1-1)*X*Y
+ E2*B**5*y1**2*X*Y
+ E3*(B**3*Y**-2*(Y+B)*X*Y-B**-1*X))
check("ALL-ORDERS: finite correct-sided certificate for 1-l^2",
1-l_squared == tetra_terms+moment_terms)
check("intermediate moment consequence y1^2=B^3",
y1**2-B**3 == E2*(-B**5*y1**2)
+ E3*(-B**3*Y**-2*(Y+B)))
check("final local q-difference cancellation",
1+(1-B**3)*X*Y == X*f3-E3*B**-1*X)
def omega(u, v):
return sum(u[j+1]*v[j]-u[j]*v[j+1] for j in range(0, len(u), 2))
edge1 = (0, 2, 0, -2, 0, 0)
edge2 = (0, -4, 0, 0, 0, -4)
meridian = (0, 0, 0, 0, 0, 2)
longitude = (-1, 0, -1, 0, 1, 1)
rows = (edge1, edge2, meridian)
check("all moment rows are isotropic", all(omega(h, g) == 0 for h in rows for g in rows))
check("longitude commutes with both edge rows", omega(edge1, longitude) == omega(edge2, longitude) == 0)
check("the named meridian/longitude law is ml=A^2 lm", omega(meridian, longitude) == 2)
alpha = (Q(3,4), Q(3,4), Q(1,2))
theta = ((Q(1,8), Q(1,8), Q(3,4)),
(Q(1,8), Q(1,8), Q(3,4)),
(Q(1,4), Q(1,4), Q(1,2)))
vartheta = lambda u: sum(theta[j][0]*u[2*j]+theta[j][2]*u[2*j+1] for j in range(3))
check("all nine angles are strictly positive and every triple sums to one",
all(all(t > 0 for t in block) and sum(block) == 1 for block in theta))
check("the specified affine character valuations for the three designated rows",
tuple(vartheta(h) for h in rows) == (0, -5, 1))
check("native lifted affine angle equations have right-hand side two",
tuple(vartheta(h)+s for h,s in zip(rows,(2,7,1))) == (2,2,2))
# Universal integer coordinates of the unsaturated moment lattice.
# k1+k2 is even; a=-k2, d=-(k1+k2)/2, c=k3-k1-k2.
# Then k=a*(1,-1,0)+d*(-2,0,-2)+c*(0,0,1).
KROWS = ((1,-1,0),(-2,0,-2),(0,0,1))
det = sum(KROWS[0][j]*(KROWS[1][(j+1)%3]*KROWS[2][(j+2)%3]
-KROWS[1][(j+2)%3]*KROWS[2][(j+1)%3]) for j in range(3))
check("moment basis has index two in the squared-w coordinate lattice", abs(det) == 2)
formal_a = (Q(0),Q(-1),Q(0))
formal_d = (Q(-1,2),Q(-1,2),Q(0))
formal_c = (Q(-1),Q(-1),Q(1))
reconstruction = tuple(tuple(sum(formal[j]*row[i] for formal,row in
zip((formal_a,formal_d,formal_c),KROWS)) for j in range(3)) for i in range(3))
check("universal lattice-coordinate reconstruction, not saturation",
reconstruction == ((1,0,0),(0,1,0),(0,0,1)))
check("the character exponent formula follows symbolically from the basis",
tuple(-5*formal_d[j]+formal_c[j] for j in range(3)) == (Q(3,2),Q(3,2),1))
check("the exact character sign is (-1)^k2 on that lattice",
tuple(formal_a[j]-(0,1,0)[j] for j in range(3)) == (0,-2,0))
# Six-root lifts are ordered z,z',z'',y,y',y'' in each block.
lifts = {
"edge1": (((0,0,1,0,0,1), (2,2,0,0,0,0), (0,0,0,0,0,0)), edge1, 2, -1),
"edge2": (((4,4,0,0,0,0), (0,0,0,0,0,0), (3,3,-1,0,0,0)), edge2, 7, 1),
"meridian": (((0,0,0,0,0,0), (0,0,0,0,0,0), (1,1,3,0,0,0)), meridian, 1, 1),
"longitude": (((-1,0,0,0,0,0), (-1,0,0,0,0,0), (0,-1,0,0,0,0)), longitude, -1, 1),
}
for name, (blocks, expected, exponent, sign) in lifts.items():
reduced, total_s, actual_sign = [], 0, 1
for j, u in enumerate(blocks):
r, s, t = (u[k]+u[k+3] for k in range(3))
reduced.extend((r-s,t-s))
total_s += s
if j == 0:
actual_sign *= (-1)**sum(u[3:])
check(f"exact six-root lift of {name}", tuple(reduced) == expected and total_s == exponent and actual_sign == sign)
check("witness cannot be an actual nonnegative edge-incidence presentation",
4+4 > 7)
check("positive second-edge coefficient violates incidence by a universal linear bound", -5+2*(2+2) == 3 and 3 > 2)
check("negative second-edge coefficient violates incidence by its valuation alone", 5 > 2)
check("admissible edge-lattice rows therefore span at most rank one", len(KROWS[:1]) < 2)
def delta(v):
return sum(v[3*j]*v[3*j+1]+v[3*j+1]*v[3*j+2]+v[3*j+2]*v[3*j] for j in range(len(v)//3))
def reduced(v):
out, minima = [], []
for a, b in zip(v[::2],v[1::2]):
triple = (-a,0,-b)
m = min(triple)
out.extend(t-m for t in triple)
minima.append(m)
return tuple(out), tuple(minima)
def seed_degree(m,e):
triple = (e,0,-m)
t = min(triple)
return 2*delta(tuple(a-t for a in triple))-2*t
def U(k):
return 2*k*k+Q(1,2)*k if k >= 0 else -Q(3,2)*k
def V(k):
return 2*k*k+k if k >= 0 else -k
def P(k):
return 2*k*k+Q(1,2)*k if k >= 0 else -Q(11,2)*k
def R(k):
return 2*k*k+5*k if k >= 0 else -k
# This symbolic piecewise derivation is encoded by polynomial coefficient
# identities, not inferred from samples of integer k.
check("unit degrees: positive first-block coefficients", (2, 2-Q(3,2), 0) == (2,Q(1,2),0))
check("shifted degrees: positive first-block coefficients", (2, 4-Q(7,2), 0) == (2,Q(1,2),0))
check("shifted degrees: negative first-block coefficients", -2-Q(7,2) == -Q(11,2))
check("shifted degrees: positive third-block coefficients", (2,4+1,2-2) == (2,5,0))
check("shifted degrees: negative third-block coefficients", (-2+1,2-2) == (-1,0))
check("both exact degree functions have a unique zero at the zero lattice point",
all(c > 0 for c in (Q(1,2),Q(3,2),Q(11,2),1,2,5)))
check("shifted zero-lattice summand has leading coefficient one",
(-1)*(-1) == 1)
@lru_cache(None)
def index_series(m,e,max_degree):
"""I_Delta in A degrees, with a rigorous quadratic-tail stopping rule."""
result = defaultdict(int)
n = max(0,-e)
while True:
base = 2*n*(n+1)-4*n*m-2*e*m
if n >= max(0,m) and base > max_degree:
break
bound = (max_degree-base)//4
if bound >= 0:
coefficients = [1]+[0]*bound
for factorial in (n,n+e):
for j in range(1,factorial+1):
for degree in range(j,bound+1):
coefficients[degree] += coefficients[degree-j]
for degree, c in enumerate(coefficients):
if c:
result[base+4*degree] += (-1)**n*c
n += 1
return {d:c for d,c in result.items() if c}
def convolution(a,b,bound):
out = defaultdict(int)
for i,c in a.items():
for j,d in b.items():
if i+j <= bound:
out[i+j] += c*d
return {n:c for n,c in out.items() if c}
def phase_i(n):
return ((1,0),(0,1),(-1,0),(0,-1))[n % 4]
def witness_series(shifted, bound):
out = defaultdict(lambda: [0,0])
count = 0
positive_bound = math.isqrt(bound//2)
negative_bound = (2*bound)//(11 if shifted else 3)
for k1 in range(-negative_bound,positive_bound+1):
for k2 in range(-negative_bound,positive_bound+1):
if (k1+k2) % 2:
continue
for k3 in range(-bound,positive_bound+1):
degree = (P(k1)+P(k2)+R(k3) if shifted else U(k1)+U(k2)+V(k3))
assert degree.denominator == 1 if isinstance(degree,Q) else True
degree = int(degree)
if degree > bound:
continue
count += 1
charge = 3*(k1+k2)//2+k3
factor_phase = -charge+2*k2+(2 if shifted else 0)
local = ((k1,1),(k2,1),(k3+1,-1)) if shifted else ((k1,0),(k2,0),(k3,0))
normalized = {0:1}
remainder = bound-degree
for m,e in local:
leading_degree = seed_degree(m,e)
series = index_series(m,e,leading_degree+remainder)
normalized = convolution(normalized,{d-leading_degree:c for d,c in series.items()},remainder)
re,im = phase_i(factor_phase)
for d,c in normalized.items():
out[degree+d][0] += re*c
out[degree+d][1] += im*c
return {str(d):v for d,v in sorted(out.items()) if v != [0,0]}, count
bound = 16
unit, unit_count = witness_series(False,bound)
shifted, shifted_count = witness_series(True,bound)
check("independent exact bounded-series check of all-order cancellation", unit == shifted)
check("the original algebraic cokernel unit is detected", unit.get("0") == [1,0])
check("the longitude difference is zero through the certified coefficient bound",
all(unit.get(str(n),[0,0]) == shifted.get(str(n),[0,0]) for n in range(bound+1)))
results = {
"status": "supporting ATTACK; actual triangulation gate remains open",
"exact_checks": len(checks),
"check_names": checks,
"all_orders_certificate": {"residual_monomials": len((1-l_squared-tetra_terms-moment_terms).terms),
"correct_sides": "tetrahedron relations multiplied on left; moment relations on right"},
"witness_lattice": {"squared_w_coordinates": "k1+k2 even", "index": 2,
"character": "(-1)^k2 B^(3(k1+k2)/2+k3)", "B": "i*A"},
"native_incidence_obstruction": {"second_edge_minimum_prime_total":8,"required_prime_total":7},
"series_sanity_check": {"maximum_A_degree":bound,"coefficient_format":"[real integer, imaginary integer]",
"unit_contributing_lattice_points":unit_count,"longitude_contributing_lattice_points":shifted_count,
"unit_coefficients":unit,"longitude_coefficients":shifted,"difference_coefficients":{}},
"limits": ["No actual manifold, filling, or triangulation counterexample",
"The zero certificate is for the specified sector, not every sign sector",
"Finite coefficients are not the all-orders proof",
"The specified signed edge cannot be an actual nonnegative incidence row",
"No unrestricted nonzero descended quantum trace"]
}
Path(__file__).with_name("exact-results.json").write_text(json.dumps(results,indent=2)+"\n")
print(f"\n{len(checks)} exact checks passed.")
print(f"All-orders certificate residual: {results['all_orders_certificate']['residual_monomials']} monomials.")
print(f"Certified series sanity bound: A^{bound}; unit and shifted longitude agree.")
print(json.dumps(unit,sort_keys=True))