"""Independent enumeration of the local step patterns for (H1), compared with the certified list. Raw configuration: statuses of e, N, W, s, c0..c3: v uniform, keeps v-e, v-N, v-W (arrival bond v-s dropped); s: X, or D keeping exactly 2 of {s-c2, s-c3, s-tip}; e, N, W, corners: U (keeps all 4 bonds/legs), D (keeps exactly 2 of its 4 bonds/legs), X; (C) a bond between two non-removed template sites (v included, tips excluded) is kept by both ends or by neither. Tips: the d1-tip bond is present iff the d1 site is non-removed and keeps it, regardless of the status of the tip. Corner legs: slots. Effective pattern = (out, kinds of the sites incident to a present bond, present bonds), up to the mirror x -> -x. Out = any of e, N, W whose v-bond is present.""" import itertools, json, sys V = (0, 0) e, N, W, s = (1, 0), (0, 1), (-1, 0), (0, -1) c0, c1, c2, c3 = (1, 1), (-1, 1), (-1, -1), (1, -1) tip = {e: (2, 0), N: (0, 2), W: (-2, 0), s: (0, -2)} D1 = [e, N, W, s] CO = [c0, c1, c2, c3] def B(a, b): return tuple(sorted((a, b))) def nb(x): return [(x[0] + 1, x[1]), (x[0] - 1, x[1]), (x[0], x[1] + 1), (x[0], x[1] - 1)] def options(x): bonds = [B(x, y) for y in nb(x)] # 4 bonds or legs of x (legs of corners included as bonds to outside) if x == s: nonv = [b for b in bonds if V not in b] return [('x', frozenset())] + [('d', frozenset(K)) for K in itertools.combinations(nonv, 2)] return [('u', frozenset(bonds)), ('x', frozenset())] + [('d', frozenset(K)) for K in itertools.combinations(bonds, 2)] TEMPLATE = set([V] + D1 + CO) def effective(st): keep = {x: st[x][1] for x in st} keep[V] = frozenset([B(V, e), B(V, N), B(V, W)]) alive = {x: st[x][0] != 'x' for x in st} alive[V] = True # consistency (C) between non-removed template sites (tips excluded) allb = set() for x in TEMPLATE: for y in nb(x): if y in TEMPLATE: allb.add(B(x, y)) for b in allb: x, y = b if alive[x] and alive[y] and ((b in keep[x]) != (b in keep[y])): return None present = set() for b in allb: x, y = b if alive[x] and alive[y] and b in keep[x] and b in keep[y]: present.add(b) for x in D1: if alive[x] and B(x, tip[x]) in keep[x]: present.add(B(x, tip[x])) rel = set() for b in present: rel |= set(b) kinds = {x: st[x][0] for x in st if x in rel} return kinds, frozenset(present) def mir(p): return (-p[0], p[1]) def canon(out, kinds, present): def form(f): return (f(out), tuple(sorted((f(x), k) for x, k in kinds.items())), tuple(sorted(B(f(a), f(b)) for a, b in present))) a, b = form(lambda p: p), form(mir) if out == W: return b if out == e: return a return min(a, b) def enumerate_all(): sites = [e, N, W, s] + CO reps = {} nraw = 0 for combo in itertools.product(*[options(x) for x in sites]): st = dict(zip(sites, combo)) r = effective(st) if r is None: continue nraw += 1 kinds, present = r for out in (e, N, W): if B(V, out) in present: reps.setdefault(canon(out, kinds, present), 0) reps[canon(out, kinds, present)] += 1 return reps, nraw if __name__ == '__main__': reps, nraw = enumerate_all() ns = sum(1 for k in reps if k[0] == N) print('consistent raw configurations', nraw, 'effective patterns', len(reps), 'straight', ns, 'turn', len(reps) - ns) import os fn = sys.argv[1] if len(sys.argv) > 1 else os.path.join(os.path.dirname(os.path.abspath(__file__)), 'patterns.json') P = json.load(open(fn)) import ast keys = [] for r in P: out = tuple(r['out']) kinds = {ast.literal_eval(k): c for k, c in r['kinds'].items()} present = frozenset(B(tuple(a), tuple(b)) for a, b in r['present']) keys.append(canon(out, kinds, present)) ks = set(keys) print('certified list: records', len(keys), 'distinct canonical keys', len(ks)) print('in enumeration but not in list:', len(set(reps) - ks), ' in list but not in enumeration:', len(ks - set(reps))) for k in list(set(reps) - ks)[:5]: print(' missing', k) for k in list(ks - set(reps))[:5]: print(' extra', k)