"""Exact spectrum and second-moment bound for the 19-pair overlap reduction.""" from collections import Counter from itertools import combinations from pathlib import Path def dist(x): return min(x.bit_count(), 8-x.bit_count()) seed = sorted({min(x, x ^ 255) for x in (int(word, 2) for word in Path(__file__).with_name("q8_k40.csv").read_text().split())}) assert len(seed) == 20 shell = Counter(dist(x) for x in range(128)) pairs = Counter(dist(a ^ b) for a,b in combinations(seed, 2)) assert [shell[i] for i in range(1,5)] == [8,28,56,35] assert [pairs[i] for i in range(1,5)] == [8,20,88,74] w = [0] + [420*pairs[i]//shell[i] for i in range(1,5)] assert all(w[i]*shell[i] == 420*pairs[i] for i in range(5)) eig = [sum((-1)**((a&x).bit_count()%2)*w[dist(x)] for x in range(128)) for a in range(128)] assert [eig[(1< 128*420*19*20 print("PASS: overlap moment bound forces at least four retained seed pairs")