#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Rebuild the main STS(27) and check its residual-resolution certificate. Run python3 verify.py from any directory. An optional command-line path selects a certificate JSON. By default the checker uses certificate.json next to this script. The 49 checks cover the block construction, geometric and algebraic invariants, all 117 witnesses and the global integral search. The companion two_roots.py checks local compatibility and a fractional obstruction. The sample searches are provided in the full replication archive. """ import json import sys import time from itertools import combinations, permutations from pathlib import Path F3 = (0, 1, 2) N = 27 ok_all = True def check(label, condition, detail=""): global ok_all ok_all = ok_all and bool(condition) print(f" [{'PASS' if condition else 'FAIL'}] {label}" + (f" ({detail})" if detail else "")) return bool(condition) # ---------------------------------------------------------------- construction def base_lines(): pts = [(u, v) for u in F3 for v in F3] index = {p: i for i, p in enumerate(pts)} dirs = [(1, 0), (0, 1), (1, 1), (1, 2)] lines = set() for (u, v) in pts: for (du, dv) in dirs: q1 = ((u + du) % 3, (v + dv) % 3) q2 = ((u + 2 * du) % 3, (v + 2 * dv) % 3) lines.add(frozenset((index[u, v], index[q1], index[q2]))) return sorted(tuple(sorted(l)) for l in lines) def build_blocks(): blocks = [frozenset(3 * i + x for x in F3) for i in range(9)] for (i, j, k) in base_lines(): for x in F3: for y in F3: blocks.append(frozenset((3 * i + x, 3 * j + y, 3 * k + (x + y) % 3))) return blocks def untwisted_blocks(): """The untwisted tripling: coordinates summing to 0 on every base line.""" blocks = [frozenset(3 * i + x for x in F3) for i in range(9)] for (i, j, k) in base_lines(): for x in F3: for y in F3: blocks.append(frozenset((3 * i + x, 3 * j + y, 3 * k + (-x - y) % 3))) return blocks def affine_blocks(): pts = [(a, b, c) for a in F3 for b in F3 for c in F3] index = {p: i for i, p in enumerate(pts)} dirs = set() for a in F3: for b in F3: for c in F3: if (a, b, c) == (0, 0, 0): continue for t in (1, 2): e = tuple((t * x) % 3 for x in (a, b, c)) if [x for x in e if x][0] == 1: dirs.add(e) break blocks = set() for d in dirs: for p in pts: blocks.add(frozenset(index[tuple((p[i] + t * d[i]) % 3 for i in range(3))] for t in F3)) return sorted((frozenset(b) for b in blocks), key=lambda b: sorted(b)) def third_point_table(blocks): third = {} for b in blocks: for a, c, d in permutations(sorted(b)): third[a, c] = d return third def closure(third, seeds): seen = set(seeds) rounds = [] while len(seen) < N: gained = [] for a, b in combinations(sorted(seen), 2): c = third[a, b] if c not in seen: seen.add(c) gained.append((a, b, c)) if not gained: break rounds.append(gained) return rounds, seen def closure_sizes(blocks): """Multiset of the sizes of the closures of all triples of points.""" third = third_point_table(blocks) sizes = {} for a, b, c in combinations(range(N), 3): seen = {a, b, c} while True: old = len(seen) for x, y in combinations(sorted(seen), 2): z = third[x, y] if z not in seen: seen.add(z) if len(seen) == old: break sizes[len(seen)] = sizes.get(len(seen), 0) + 1 return sizes def rank_mod3(rows): rows = [list(r) for r in rows] nrows, ncols = len(rows), len(rows[0]) rank = 0 for col in range(ncols): piv = next((r for r in range(rank, nrows) if rows[r][col] % 3), None) if piv is None: continue rows[rank], rows[piv] = rows[piv], rows[rank] inv = pow(rows[rank][col] % 3, 1, 3) rows[rank] = [(v * inv) % 3 for v in rows[rank]] for r in range(nrows): if r != rank and rows[r][col] % 3: f = rows[r][col] % 3 rows[r] = [(rows[r][c] - f * rows[rank][c]) % 3 for c in range(ncols)] rank += 1 if rank == nrows: break return rank def incidence_rank(blocks): mat = [[0] * len(blocks) for _ in range(N)] for j, b in enumerate(blocks): for x in b: mat[x][j] = 1 return rank_mod3(mat) def parallel_classes(blocks, largest=False, count_only=False): """All parallel classes; branch on the smallest (or largest) free point.""" through = {p: [] for p in range(N)} for i, b in enumerate(blocks): for p in b: through[p].append(i) out = [] def rec(free, chosen): if not free: out.append(1 if count_only else tuple(sorted(chosen))) return p = max(free) if largest else min(free) for i in through[p]: b = blocks[i] if b <= free: rec(free - b, chosen + [i]) rec(frozenset(range(N)), []) return out # ------------------------------------------------------------ dancing links class DLX: """Knuth's Algorithm X with dancing links and the minimum-column rule.""" def __init__(self, n_cols, rows): self.root = n_cols n = n_cols + 1 self.L = [0] * n self.R = [0] * n self.U = [0] * n self.D = [0] * n self.C = [0] * n self.ROW = [-1] * n self.size = [0] * n_cols for j in range(n_cols): self.L[j] = j - 1 if j else self.root self.R[j] = j + 1 self.U[j] = self.D[j] = self.C[j] = j self.L[self.root] = n_cols - 1 self.R[self.root] = 0 self.U[self.root] = self.D[self.root] = self.C[self.root] = self.root for r, cols in enumerate(rows): first = None for c in cols: node = len(self.L) self.L.append(0) self.R.append(0) self.U.append(self.U[c]) self.D.append(c) self.C.append(c) self.ROW.append(r) self.D[self.U[c]] = node self.U[c] = node self.size[c] += 1 if first is None: first = node self.L[node] = self.R[node] = node else: last = self.L[first] self.L[node] = last self.R[node] = first self.R[last] = node self.L[first] = node def cover(self, c): L, R, U, D, C, size = self.L, self.R, self.U, self.D, self.C, self.size L[R[c]] = L[c] R[L[c]] = R[c] i = D[c] while i != c: j = R[i] while j != i: U[D[j]] = U[j] D[U[j]] = D[j] size[C[j]] -= 1 j = R[j] i = D[i] def uncover(self, c): L, R, U, D, C, size = self.L, self.R, self.U, self.D, self.C, self.size i = U[c] while i != c: j = L[i] while j != i: size[C[j]] += 1 U[D[j]] = j D[U[j]] = j j = L[j] i = U[i] L[R[c]] = c R[L[c]] = c def search(self, limit=1, deadline=None): import time as _t self.nodes = 0 self.exhausted = True self.found = 0 chosen = [] root = self.root def rec(): if self.R[root] == root: self.found += 1 yield list(chosen) return self.nodes += 1 if deadline is not None and _t.time() > deadline: self.exhausted = False return best, best_size = -1, 1 << 30 c = self.R[root] while c != root: if self.size[c] < best_size: best, best_size = c, self.size[c] if best_size <= 1: break c = self.R[c] self.cover(best) n = self.D[best] while n != best: chosen.append(self.ROW[n]) j = self.R[n] while j != n: self.cover(self.C[j]) j = self.R[j] yield from rec() j = self.L[n] while j != n: self.uncover(self.C[j]) j = self.L[j] chosen.pop() if (limit is not None and self.found >= limit) \ or not self.exhausted: break n = self.D[n] self.uncover(best) yield from rec() def subsystems_of_order_9(blocks): """All STS(9) subsystems, found by choosing a point and four of the thirteen blocks through it.""" through = {p: [i for i, b in enumerate(blocks) if p in b] for p in range(N)} found = set() for p in range(N): for four in combinations(through[p], 4): pts = set() for i in four: pts |= blocks[i] if len(pts) != 9: continue inner = tuple(sorted(i for i, b in enumerate(blocks) if b <= pts)) if len(inner) == 12: found.add((tuple(sorted(pts)), inner)) return sorted(found) # ------------------------------------------------------------------- checks def main(): here = Path(__file__).resolve().parent if len(sys.argv) > 1: cert_path = Path(sys.argv[1]) else: for cand in (here / "certificate.json", here / "data" / "certificate.json"): if cand.exists(): cert_path = cand break else: cert_path = here / "certificate.json" t_start = time.time() print("1. The construction") blocks = build_blocks() check("117 blocks of size 3", len(blocks) == 117 and all(len(b) == 3 for b in blocks)) pairs = {} for b in blocks: for a, c in combinations(sorted(b), 2): pairs[a, c] = pairs.get((a, c), 0) + 1 check("every pair of points lies in exactly one block", len(pairs) == 351 and set(pairs.values()) == {1}, f"{len(pairs)} pairs") check("the nine fibres form a parallel class", all(blocks[i] == frozenset((3 * i, 3 * i + 1, 3 * i + 2)) for i in range(9)) and len(set().union(*blocks[:9])) == 27) printed_lines = [(0, 1, 2), (0, 3, 6), (0, 4, 8), (0, 5, 7), (1, 3, 8), (1, 4, 7), (1, 5, 6), (2, 3, 7), (2, 4, 6), (2, 5, 8), (3, 4, 5), (6, 7, 8)] check("the twelve base lines printed in the paper are the lines used", sorted(base_lines()) == sorted(printed_lines)) print("2. The system is not AG(3,3)") third = third_point_table(blocks) rounds, final = closure(third, (0, 4, 9)) after2 = {0, 4, 9} | {c for _, _, c in rounds[0]} | {c for _, _, c in rounds[1]} check("the closure of {0,4,9} has 11 points after two rounds", len(after2) == 11, f"round 1 -> {sorted(c for _, _, c in rounds[0])}") check("round 1 uses (0,4),(0,9),(4,9) and gives 7, 18, 25", {(a, b) for a, b, _ in rounds[0]} == {(0, 4), (0, 9), (4, 9)} and [c for _, _, c in rounds[0]] == [7, 18, 25]) check("round 2 uses (0,25),(7,18),(7,25),(4,18),(7,9) and gives " "13, 14, 15, 17, 22", {(a, b) for a, b, _ in rounds[1]} == {(0, 25), (7, 18), (7, 25), (4, 18), (7, 9)} and sorted(c for _, _, c in rounds[1]) == [13, 14, 15, 17, 22]) check("the closure table of the paper is correct pair by pair", all(third[a, b] == c for (a, b), c in {(0, 4): 7, (0, 9): 18, (4, 9): 25, (0, 25): 13, (7, 18): 14, (7, 25): 15, (4, 18): 17, (7, 9): 22}.items())) check("the closure of {0,4,9} is all 27 points, after four rounds", len(final) == 27 and len(rounds) == 4, f"{len(rounds)} rounds") aff = affine_blocks() third_aff = third_point_table(aff) worst = 0 for a, b, c in combinations(range(N), 3): _, cl = closure(third_aff, (a, b, c)) worst = max(worst, len(cl)) check("in AG(3,3) three points close up to at most 9 points", worst <= 9, f"maximum {worst}") r_ours, r_aff = incidence_rank(blocks), incidence_rank(aff) check("3-rank 24 for this system, 23 for AG(3,3)", r_ours == 24 and r_aff == 23, f"{r_ours} / {r_aff}") sizes = closure_sizes(blocks) check("closure sizes of the 2925 triples are 3, 9 and 27", sizes == {3: 117, 9: 1080, 27: 1728}, f"{sorted(sizes.items())}") print("3. The untwisted tripling is AG(3,3)") unt = untwisted_blocks() check("the untwisted tripling is an STS(27)", len(unt) == 117 and len({(a, c) for b in unt for a, c in combinations(sorted(b), 2)}) == 351) check("its block set is exactly the block set of AG(3,3)", {frozenset(b) for b in unt} == {frozenset(b) for b in aff}) usizes = closure_sizes(unt) check("every triple closes up in 3 or 9 points (a Hall triple system)", usizes == {3: 117, 9: 2808}, f"{sorted(usizes.items())}") print("4. The certificate of residual resolvability") data = json.loads(cert_path.read_text(encoding="utf-8")) cert_blocks = [frozenset(b) for b in data["blocks"]] check("the certificate lists the same block table", cert_blocks == blocks) res = data["residual_resolutions"] check("one residual resolution for each of the 117 blocks", len(res) == 117 and all(len(row) == 10 for row in res)) good = 0 for t in range(117): bt = blocks[t] outside = set(range(N)) - bt used = set() ok = True for cls in res[t]: if len(cls) != 8: ok = False break pts = [p for b in cls for p in blocks[b]] if len(set(pts)) != 24 or set(pts) != outside: ok = False break for b in cls: if blocks[b] & bt: ok = False used.add(b) if ok and len(used) == 80: good += 1 check("each of the 117 blocks is residually resolvable", good == 117, f"{good}/117 roots verified") printed_class = [(3, 4, 5), (9, 10, 11), (12, 13, 14), (18, 19, 20), (21, 22, 23), (6, 17, 26), (7, 15, 25), (8, 16, 24)] first_class = [tuple(sorted(blocks[b])) for b in res[0][0]] check("the residual class printed in the paper is the certificate's first " "class at root 0", sorted(first_class) == sorted(printed_class)) print("5. Automorphism group, orbits and subsystems") seen = {0, 4, 9} steps = [] while len(seen) < N: old = len(seen) for a, b in combinations(sorted(seen), 2): c = third[a, b] if c not in seen: steps.append((a, b, c)) seen.add(c) if len(seen) == old: break block_id = {b: i for i, b in enumerate(blocks)} autos = [] for images in permutations(range(N), 3): mapping = dict(zip((0, 4, 9), images)) used = set(images) for a, b, c in steps: w = third[mapping[a], mapping[b]] if w in used: break mapping[c] = w used.add(w) else: if all(frozenset(mapping[x] for x in b) in block_id for b in blocks): autos.append(tuple(mapping[x] for x in range(N))) check("the automorphism group has order 72", len(autos) == 72, f"|Aut| = {len(autos)}") block_action = {g: tuple(block_id[frozenset(g[x] for x in b)] for b in blocks) for g in autos} orbits, rest = [], set(range(117)) while rest: i = min(rest) orb = sorted({g[i] for g in block_action.values()}) orbits.append(orb) rest -= set(orb) check("the 117 blocks form 11 orbits of the stated sizes", len(orbits) == 11 and sorted(len(o) for o in orbits) == sorted([6, 3, 9, 18, 6, 12, 18, 36, 1, 6, 2]), f"representatives {[o[0] for o in orbits]}") porbs, prest = [], set(range(N)) while prest: x = min(prest) orb = sorted({g[x] for g in autos}) porbs.append(orb) prest -= set(orb) check("the points form orbits of sizes 18, 3 and 6", sorted(len(o) for o in porbs) == [3, 6, 18], f"{[len(o) for o in porbs]}") printed_orbits = [(0, 1, 2, 3, 4, 5, 9, 10, 11, 12, 13, 14, 18, 19, 20, 21, 22, 23), (6, 15, 24), (7, 8, 16, 17, 25, 26)] check("the point orbits printed in the paper are the computed ones", sorted(tuple(o) for o in porbs) == sorted(printed_orbits)) printed_reps = [(0, 1, 2), (6, 7, 8), (0, 3, 6), (0, 4, 7), (0, 9, 18), (0, 10, 19), (0, 12, 24), (0, 13, 25), (6, 15, 24), (6, 16, 25), (7, 16, 26)] check("the representatives printed in the paper are the orbit " "representatives", sorted(tuple(sorted(blocks[o[0]])) for o in orbits) == sorted(printed_reps)) subs = subsystems_of_order_9(blocks) fibres = set(range(9)) fibre_line = sum(1 for pts, _ in subs if all(len(set(blocks[i]) & set(pts)) in (0, 3) for i in fibres)) transversal = [pts for pts, _ in subs if not all(len(set(blocks[i]) & set(pts)) in (0, 3) for i in fibres)] check("the system has 15 subsystems of order 9 (12 fibre-line, " "3 transversal)", len(subs) == 15 and fibre_line == 12 and len(transversal) == 3, f"{len(subs)} = {fibre_line} + " f"{len(transversal)}") check("the three further subsystems meet every fibre in exactly one point", all(len(set(blocks[i]) & set(pts)) == 1 for pts in transversal for i in fibres)) distinguished = (6, 7, 8, 15, 16, 17, 24, 25, 26) check("the subsystem on the two small point orbits is fixed setwise", any(pts == distinguished for pts, _ in subs) and all(set(g[x] for x in distinguished) == set(distinguished) for g in autos)) inner = sorted(i for i, b in enumerate(blocks) if b <= set(distinguished)) check("it consists of F_2, F_5, F_8 and the nine blocks on {2,5,8}", inner == [2, 5, 8] + list(range(90, 99))) check("block 90 is {6,15,24}", blocks[90] == frozenset((6, 15, 24))) check("the block {6,15,24} is fixed setwise by every automorphism", all(block_action[g][90] == 90 for g in autos)) print("6. Parallel classes and disjoint pairs") classes = parallel_classes(blocks) check("the system has 7009 parallel classes", len(classes) == 7009, f"{len(classes)}") classes2 = parallel_classes(blocks, largest=True) check("a second recursion order gives the same 7009 classes", set(classes2) == set(classes) and len(classes2) == 7009) ec = DLX(27, [sorted(b) for b in blocks]) ec_set = {tuple(sorted(sol)) for sol in ec.search(limit=None)} check("an exact-cover enumeration gives the same 7009 classes", ec_set == set(classes) and len(ec_set) == 7009) n_aff = len(parallel_classes(aff, count_only=True)) n_aff2 = len(parallel_classes(aff, largest=True, count_only=True)) ec_aff = DLX(27, [sorted(b) for b in aff]) n_aff3 = sum(1 for _ in ec_aff.search(limit=None)) check("AG(3,3) has 17641 parallel classes (published value)", n_aff == 17641 and n_aff2 == 17641 and n_aff3 == 17641, f"{n_aff} / {n_aff2} / {n_aff3}") through_block = {} for c in classes: for b in c: through_block[b] = through_block.get(b, 0) + 1 check("between 395 and 709 classes contain a given block", min(through_block.values()) == 395 and max(through_block.values()) == 709, f"{min(through_block.values())}..{max(through_block.values())}") expected_table = {0: (6, 469), 2: (3, 469), 9: (9, 481), 10: (18, 395), 18: (6, 623), 19: (12, 572), 27: (18, 543), 28: (36, 604), 90: (1, 709), 91: (6, 565), 94: (2, 601)} table_ok = all(len(orb) == expected_table[orb[0]][0] and through_block[orb[0]] == expected_table[orb[0]][1] for orb in orbits) check("Table 1: orbit size and classes through each representative", table_ok) disjoint = [(i, j) for i in range(117) for j in range(i + 1, 117) if not (blocks[i] & blocks[j])] check("4680 pairs of disjoint blocks", len(disjoint) == 4680, f"{len(disjoint)}") pair_index = {p: i for i, p in enumerate(disjoint)} rows = [[pair_index[p] for p in combinations(sorted(c), 2)] for c in classes] freq = {} for r in rows: for p in r: freq[p] = freq.get(p, 0) + 1 check("every disjoint pair lies in 26 to 90 parallel classes", len(freq) == 4680 and min(freq.values()) == 26 and max(freq.values()) == 90, f"{min(freq.values())}..{max(freq.values())}") local = [{u: frozenset([t, *c]) for c in res[t] for u in c} for t in range(117)] agree = sum(local[t][u] == local[u][t] for t, u in disjoint) check("the fixed choice agrees on 609 of the 4680 pairs", agree == 609, f"{agree}") class_set = set(classes) check("all 1170 residual classes are among the 7009 parallel classes", all(tuple(sorted([t, *c])) in class_set for t in range(117) for c in res[t])) # every root's resolution is the image of its representative's resolution transport_ok = True for orb in orbits: t = orb[0] for u in orb: want = {frozenset(c) for c in res[u]} found = False for g in autos: if block_action[g][t] != u: continue image = {frozenset(block_action[g][b] for b in c) for c in res[t]} if image == want: found = True break if not found: transport_ok = False check("every root's resolution is the image of its representative's " "resolution under some automorphism", transport_ok) print("7. The design is resolvable") res_dlx = DLX(117, [list(c) for c in classes]) sol = next(res_dlx.search(limit=1), None) check("13 parallel classes partition all 117 blocks", sol is not None and len(sol) == 13 and sorted(b for c in sol for b in classes[c]) == list(range(117))) print("8. Local restrictions and the mod-2 relaxation") subsys = [2, 5, 8] + list(range(90, 99)) for name, rs in (("nine fibres", list(range(9))), ("the subsystem of order 9", subsys), ("their union", sorted(set(range(9)) | set(subsys)))): rs = set(rs) cols = [p for p in disjoint if p[0] in rs and p[1] in rs] idx = {p: k for k, p in enumerate(cols)} sub_rows = [] for c in classes: r = [idx[p] for p in combinations(sorted(c), 2) if p in idx] if r: sub_rows.append(r) d = DLX(len(cols), sub_rows) found = next(d.search(limit=1), None) check(f"the restriction to {name} is satisfiable", found is not None, f"{len(cols)} pairs") # mod-2 rank of the pair-class matrix, with the all-ones right-hand side mask = [0] * len(disjoint) for ci, c in enumerate(classes): for p in combinations(sorted(c), 2): mask[pair_index[p]] |= 1 << ci rhs = 1 << len(classes) mask = [m | rhs for m in mask] rank = 0 for col in range(len(classes)): bit = 1 << col piv = next((r for r in range(rank, len(mask)) if mask[r] & bit), None) if piv is None: continue mask[rank], mask[piv] = mask[piv], mask[rank] p = mask[rank] for r in range(len(mask)): if r != rank and (mask[r] & bit): mask[r] ^= p rank += 1 if rank == len(mask): break inconsistent = any(mask[r] == rhs for r in range(rank, len(mask))) check("the mod-2 system has rank 2283 and is feasible", rank == 2283 and not inconsistent, f"rank {rank}") print("9. No class cover (exhaustive search, no SAT solver)") t0 = time.time() dlx = DLX(len(disjoint), rows) solutions = list(dlx.search(limit=1, deadline=time.time() + 3600)) check("the exact-cover instance has no solution", len(solutions) == 0, f"{dlx.nodes} search nodes, {time.time() - t0:.1f}s") check("the search space was exhausted", dlx.exhausted) check("the search visits 4885 nodes", dlx.nodes == 4885, f"{dlx.nodes}") print() print(f"total time {time.time() - t_start:.1f}s") print("ALL CHECKS PASSED" if ok_all else "SOME CHECKS FAILED") return 0 if ok_all else 1 if __name__ == "__main__": sys.setrecursionlimit(100000) try: sys.exit(main()) except Exception as exc: # report, never crash silently print(f"\nSOME CHECKS FAILED (exception: {type(exc).__name__}: {exc})") sys.exit(1)