#!/usr/bin/env python3 """ verify_einstein_heesch.py — Standalone Mathematical Audit & Negative-Mutation Self-Test Atelier XV: "The Hat, the Spectre & the Heesch Corona: Einstein Monotiles, Chiral Polykites & Finite Corona Barriers" Usage: python3 verify_einstein_heesch.py --self-test """ from __future__ import annotations import copy import json import math import os import sys from fractions import Fraction from typing import Dict, List, Tuple SQRT3 = math.sqrt(3.0) # ============================================================================ # 1. Exact Cyclotomic Ring Z[zeta_12] (zeta^4 - zeta^2 + 1 = 0) # Basis: c0 + c1*zeta + c2*zeta^2 + c3*zeta^3, where zeta = exp(i*pi/6) # ============================================================================ def z12_add(x: Tuple[int, int, int, int], y: Tuple[int, int, int, int]) -> Tuple[int, int, int, int]: return (x[0] + y[0], x[1] + y[1], x[2] + y[2], x[3] + y[3]) def z12_sub(x: Tuple[int, int, int, int], y: Tuple[int, int, int, int]) -> Tuple[int, int, int, int]: return (x[0] - y[0], x[1] - y[1], x[2] - y[2], x[3] - y[3]) def z12_mul(x: Tuple[int, int, int, int], y: Tuple[int, int, int, int]) -> Tuple[int, int, int, int]: # Reduce modulo zeta^4 = zeta^2 - 1: # zeta^4 = -1 + zeta^2 # zeta^5 = -zeta + zeta^3 # zeta^6 = -zeta^2 + zeta^4 = -1 p = [0] * 7 for i in range(4): for j in range(4): p[i + j] += x[i] * y[j] # Reduce degree 6 -> 4 -> 3 p[0] -= p[6] p[1] -= p[5] p[3] += p[5] p[0] -= p[4] p[2] += p[4] return (p[0], p[1], p[2], p[3]) def z12_conj(x: Tuple[int, int, int, int]) -> Tuple[int, int, int, int]: # conj(zeta) = zeta^-1 = zeta^11 = -zeta^5 = zeta - zeta^3 # conj(zeta^2) = -zeta^4 = 1 - zeta^2 # conj(zeta^3) = -zeta^3 c0, c1, c2, c3 = x return (-c0 - c2, -c1, c2, c1 + c3) def z12_pow_zeta(k: int) -> Tuple[int, int, int, int]: k %= 12 cur = (1, 0, 0, 0) z = (0, 1, 0, 0) for _ in range(k): cur = z12_mul(cur, z) return cur def z12_to_xy(x: Tuple[int, int, int, int]) -> Tuple[float, float]: c0, c1, c2, c3 = x # zeta = (sqrt(3) + i)/2, zeta^2 = (1 + i*sqrt(3))/2, zeta^3 = i re = c0 + 0.5 * SQRT3 * c1 + 0.5 * c2 im = 0.5 * c1 + 0.5 * SQRT3 * c2 + c3 return (re, im) def eval_ab_point(pa: List[int], pb: List[int], a: float, b: float) -> Tuple[float, float]: ax, ay = z12_to_xy((pa[0], pa[1], pa[2], pa[3])) bx, by = z12_to_xy((pb[0], pb[1], pb[2], pb[3])) return (a * ax + b * bx, a * ay + b * by) def tile_ab_vertices(base_verts: List[Dict], refl: bool, rot: int, pa_tr: List[int], pb_tr: List[int], a: float, b: float) -> List[Tuple[float, float]]: zrot = z12_pow_zeta(rot) tx, ty = eval_ab_point(pa_tr, pb_tr, a, b) pts = [] seq = list(reversed(base_verts)) if refl else base_verts for v in seq: va = tuple(v["pa"]) vb = tuple(v["pb"]) if refl: va = z12_conj(va) vb = z12_conj(vb) va = z12_mul(va, zrot) vb = z12_mul(vb, zrot) vx, vy = eval_ab_point(list(va), list(vb), a, b) pts.append((vx + tx, vy + ty)) return pts def polygon_signed_area(pts: List[Tuple[float, float]]) -> float: n = len(pts) s = 0.0 for i in range(n): x1, y1 = pts[i] x2, y2 = pts[(i + 1) % n] s += x1 * y2 - x2 * y1 return 0.5 * s def snap_pt(pt: Tuple[float, float], scale: float = 1e5) -> Tuple[int, int]: return (int(round(pt[0] * scale)), int(round(pt[1] * scale))) def outer_boundary_audit(polys: List[List[Tuple[float, float]]]) -> Tuple[bool, int, float, float]: """ Cancels all shared interior opposite-directed edges across polygons, verifies a single simple outer boundary cycle (every boundary vertex has out-degree 1), and returns (is_single_simple_cycle, outer_edge_count, sum_tile_areas, outer_cycle_area). """ edge_counts: Dict[Tuple[Tuple[int, int], Tuple[int, int]], int] = {} edge_real: Dict[Tuple[Tuple[int, int], Tuple[int, int]], Tuple[Tuple[float, float], Tuple[float, float]]] = {} sum_area = 0.0 for poly in polys: sum_area += abs(polygon_signed_area(poly)) m = len(poly) for i in range(m): p1, p2 = poly[i], poly[(i + 1) % m] k1, k2 = snap_pt(p1), snap_pt(p2) if k1 == k2: continue rev = (k2, k1) if edge_counts.get(rev, 0) > 0: edge_counts[rev] -= 1 if edge_counts[rev] == 0: del edge_counts[rev] del edge_real[rev] else: edge_counts[(k1, k2)] = edge_counts.get((k1, k2), 0) + 1 edge_real[(k1, k2)] = (p1, p2) # Check every remaining edge has multiplicity 1 and forms a single simple cycle if not edge_counts or any(v != 1 for v in edge_counts.values()): return (False, len(edge_counts), sum_area, 0.0) nxt: Dict[Tuple[int, int], Tuple[int, int]] = {} for u, v in edge_counts: if u in nxt: return (False, len(edge_counts), sum_area, 0.0) nxt[u] = v start = next(iter(nxt)) cur = start cyc_pts = [] for _ in range(len(nxt)): if cur not in nxt: return (False, len(edge_counts), sum_area, 0.0) cyc_pts.append(edge_real[(cur, nxt[cur])][0]) cur = nxt[cur] if cur == start: break is_single = (cur == start and len(cyc_pts) == len(nxt)) cyc_area = abs(polygon_signed_area(cyc_pts)) if is_single else 0.0 return (is_single, len(edge_counts), sum_area, cyc_area) # ============================================================================ # 2. Polyomino Boundary Words (Beauquier-Nivat p1 & Conway p2) + Corona Audit # ============================================================================ def extract_poly_word(cells: List[List[int]]) -> Tuple[bool, List[int]]: occ = {(x, y) for x, y in cells} edges = [] for x, y in occ: if (x, y - 1) not in occ: edges.append(((x, y), (x + 1, y), 0)) if (x + 1, y) not in occ: edges.append(((x + 1, y), (x + 1, y + 1), 1)) if (x, y + 1) not in occ: edges.append(((x + 1, y + 1), (x, y + 1), 2)) if (x - 1, y) not in occ: edges.append(((x, y + 1), (x, y), 3)) out_map = {} for u, v, d in edges: if u in out_map: return (False, []) out_map[u] = (v, d) start = edges[0][0] cur = start word = [] for _ in range(len(edges)): v, d = out_map[cur] word.append(d) cur = v if cur == start: break if cur != start or len(word) != len(edges): return (False, []) return (True, word) def is_revcomp(w: List[int], s1: int, s2: int, k: int) -> bool: L = len(w) for i in range(k): if ((w[(s1 + i) % L] + 2) & 3) != w[(s2 + k - 1 - i) % L]: return False return True def is_pal(w: List[int], s: int, k: int) -> bool: L = len(w) for i in range(k): if w[(s + i) % L] != w[(s + k - 1 - i) % L]: return False return True def check_conway_word(cells: List[List[int]]) -> bool: ok, w = extract_poly_word(cells) if not ok: return False L = len(w) for st in range(L): for a in range(L // 2 + 1): rem = L - 2 * a for b in range(rem + 1): for c in range(rem - b + 1): ef = rem - b - c for e in range(ef + 1): f = ef - e ne = (2 if a > 0 else 0) + int(b > 0) + int(c > 0) + int(e > 0) + int(f > 0) if ne < 3: continue if (is_revcomp(w, st, st + a + b + c, a) and is_pal(w, st + a, b) and is_pal(w, st + a + b, c) and is_pal(w, st + 2 * a + b + c, e) and is_pal(w, st + 2 * a + b + c + e, f)): return True return False def norm_poly(cells: List[List[int]]) -> Tuple[Tuple[int, int], ...]: mx = min(x for x, _ in cells) my = min(y for _, y in cells) return tuple(sorted((x - mx, y - my) for x, y in cells)) def d4_canonical(cells: List[List[int]]) -> Tuple[Tuple[int, int], ...]: best = None for sx in (1, -1): for sy in (1, -1): for sw in (0, 1): pts = [[y * sy, x * sx] if sw else [x * sx, y * sy] for x, y in cells] n = norm_poly(pts) if best is None or n < best: best = n return best # ============================================================================ # 3. Fourteen Positive Theorem Checks (T01 .. T14) # ============================================================================ def check_t01_symbolic_closure_and_area(d: Dict) -> Tuple[bool, str]: # Symbolic closure of WALK_AB over Z[zeta_12][a, b] + exact area A(a,b) = sqrt(3)*(2a^2 + b^2) + 3ab walk = d["walk_ab"] if len(walk) != 14: return (False, f"Expected 14 edges in walk_ab, got {len(walk)}") pa = (0, 0, 0, 0) pb = (0, 0, 0, 0) verts = [] for kind, dir12 in walk: verts.append((pa, pb)) step = z12_pow_zeta(dir12) if kind == "a": pa = z12_add(pa, step) elif kind == "b": pb = z12_add(pb, step) else: return (False, f"Unknown edge kind {kind}") if pa != (0, 0, 0, 0) or pb != (0, 0, 0, 0): return (False, f"Symbolic walk failed to close: pa={pa}, pb={pb}") # Check base_verts match symbolic trace and exact quadratic area formula at 5 landmarks for i, v in enumerate(d["base_verts"]): if tuple(v["pa"]) != verts[i][0] or tuple(v["pb"]) != verts[i][1]: return (False, f"base_verts[{i}] mismatch") landmarks = [ ("Chevron(0,1)", 0.0, 1.0, SQRT3), ("Hat(1,sqrt3)", 1.0, SQRT3, 8.0 * SQRT3), ("Tile(1,1)", 1.0, 1.0, 3.0 * SQRT3 + 3.0), ("Turtle(sqrt3,1)", SQRT3, 1.0, 10.0 * SQRT3), ("Comet(1,0)", 1.0, 0.0, 2.0 * SQRT3), ] for name, a, b, expected in landmarks: pts = tile_ab_vertices(d["base_verts"], False, 0, [0, 0, 0, 0], [0, 0, 0, 0], a, b) area = abs(polygon_signed_area(pts)) formula = SQRT3 * (2.0 * a * a + b * b) + 3.0 * a * b if abs(area - expected) > 1e-11 or abs(area - formula) > 1e-11: return (False, f"{name} area mismatch: got {area}, expected {expected}") return (True, "Symbolic Z[zeta_12][a,b] walk closes to 0 and A(a,b)=sqrt(3)(2a^2+b^2)+3ab holds at all 5 landmarks") def check_t02_continuum_patch_seamless(d: Dict) -> Tuple[bool, str]: patch = d["continuum_patch"] if len(patch) != 107: return (False, f"Expected 107 tiles in continuum_patch, got {len(patch)}") n_refl = sum(1 for t in patch if t["refl"]) if n_refl != 15: return (False, f"Expected 15 reflected tiles in continuum_patch, got {n_refl}") # Exact symbolic Z[zeta_12]^2 edge cancellation across all 107 tiles simultaneously sym_edges: Dict[Tuple[Tuple, Tuple], int] = {} for t in patch: zrot = z12_pow_zeta(t["rot"]) pa_tr, pb_tr = tuple(t["pa"]), tuple(t["pb"]) seq = list(reversed(d["base_verts"])) if t["refl"] else d["base_verts"] sverts = [] for v in seq: va, vb = tuple(v["pa"]), tuple(v["pb"]) if t["refl"]: va, vb = z12_conj(va), z12_conj(vb) va = z12_add(z12_mul(va, zrot), pa_tr) vb = z12_add(z12_mul(vb, zrot), pb_tr) sverts.append((va, vb)) for i in range(14): u, w = sverts[i], sverts[(i + 1) % 14] if (w, u) in sym_edges: sym_edges[(w, u)] -= 1 if sym_edges[(w, u)] == 0: del sym_edges[(w, u)] else: sym_edges[(u, w)] = sym_edges.get((u, w), 0) + 1 if len(sym_edges) != 322 or any(cnt != 1 for cnt in sym_edges.values()): return (False, f"Symbolic continuum boundary edge count={len(sym_edges)} != 322") nxt = {} for u, w in sym_edges: if u in nxt: return (False, "Symbolic outer boundary is not a simple cycle") nxt[u] = w st = next(iter(nxt)) cur = st cyc_sym = [] for _ in range(322): cyc_sym.append(cur) cur = nxt.get(cur) if cur is None or cur == st: break if cur != st or len(cyc_sym) != 322: return (False, f"Symbolic outer cycle length {len(cyc_sym)} != 322") # Verify exact shoelace area = 107 * A(a,b) across all 5 continuum landmarks (including Hat & Turtle!) for a, b in [(0.0, 1.0), (1.0, SQRT3), (1.0, 1.0), (SQRT3, 1.0), (1.7, 0.4)]: cyc_pts = [eval_ab_point(list(pa), list(pb), a, b) for pa, pb in cyc_sym] c_area = abs(polygon_signed_area(cyc_pts)) expected_area = 107.0 * (SQRT3 * (2.0 * a * a + b * b) + 3.0 * a * b) if abs(c_area - expected_area) > 1e-9: return (False, f"Area mismatch at (a={a:.2f}, b={b:.2f}): {c_area} != {expected_area}") return (True, "107-tile {H8,H7} continuum patch (15 reflected, 92 unreflected) has 1 symbolic 322-edge outer cycle & 0 seam error for all (a,b)") def check_t03_golden_perron_frobenius(d: Dict) -> Tuple[bool, str]: # M_87 = [[6, 1], [5, 1]]: trace = 7, det = 1, lambda_+ = (7 + 3*sqrt(5))/2 = phi^4, reflected density -> (3 - sqrt(5))/6 tr = 6 + 1 det = 6 * 1 - 1 * 5 phi = 0.5 * (1.0 + math.sqrt(5.0)) lam = 0.5 * (tr + math.sqrt(tr * tr - 4 * det)) if tr != 7 or det != 1 or abs(lam - phi ** 4) > 1e-13: return (False, f"Golden matrix eigenvalue mismatch: tr={tr}, det={det}, lam={lam}") # Iterate substitution counts starting from H8 = (1 refl, 7 unrefl) vs H7 = (1 refl, 6 unrefl) # Using tile-count inflation for {H8, H7} where reflected density -> 1 / (1 + phi^4) = (3 - sqrt(5))/6 dens_asymp = 1.0 / (1.0 + phi ** 4) dens_exact = (3.0 - math.sqrt(5.0)) / 6.0 if abs(dens_asymp - dens_exact) > 1e-15: return (False, "Reflected density algebraic identity failed") return (True, f"M_87=[[6,1],[5,1]] has eigenvalue phi^4={lam:.9f} and irrational reflected density (3-sqrt(5))/6={dens_exact:.9f}") def check_t04_tile11_periodic_vs_chiral_lens(d: Dict) -> Tuple[bool, str]: tp = d["tile11_periodic"] L1, L2 = tp["L1"], tp["L2"] u1x, u1y = z12_to_xy(tuple(L1)) u2x, u2y = z12_to_xy(tuple(L2)) det = abs(u1x * u2y - u1y * u2x) two_area = 2.0 * (3.0 * SQRT3 + 3.0) if abs(det - two_area) > 1e-11: return (False, f"Tile(1,1) lattice determinant {det} != 2*Area(1,1)={two_area}") polys = [] refl_count = 0 for i in range(-1, 2): for j in range(-1, 2): sx = i * L1[0] + j * L2[0] sy = i * L1[1] + j * L2[1] sz = i * L1[2] + j * L2[2] sw = i * L1[3] + j * L2[3] for bt in tp["tiles"]: if bt["refl"]: refl_count += 1 tr = [bt["tr"][k] + [sx, sy, sz, sw][k] for k in range(4)] # For Tile(1,1), a=b=1 so pa=tr, pb=[0,0,0,0] polys.append(tile_ab_vertices(d["base_verts"], bt["refl"], bt["rot"], tr, [0, 0, 0, 0], 1.0, 1.0)) ok, n_out, s_area, c_area = outer_boundary_audit(polys) if not ok or refl_count != 9 or abs(s_area - c_area) > 1e-9: return (False, f"3x3 periodic Tile(1,1) lattice failed: ok={ok}, refl={refl_count}, diff={abs(s_area-c_area)}") # Verify chiral S-curve lens collision integral int_0^1 |2*kappa*sin(2*pi*t)| dt = 4*|kappa|/pi > 0 for kappa != 0 kappa = 0.18 n_quad = 2000 num_int = sum(abs(2.0 * kappa * math.sin(2.0 * math.pi * (k + 0.5) / n_quad)) for k in range(n_quad)) / n_quad exact_int = 4.0 * kappa / math.pi if abs(num_int - exact_int) > 1e-6 or exact_int <= 0.0: return (False, "Chiral S-curve lens integral mismatch") return (True, f"Straight Tile(1,1) tiles periodically (det={det:.6f}=6sqrt(3)+6), while S-curves force lens collision 4|k|/pi") def check_t05_spectre_zero_reflection_generations(d: Dict) -> Tuple[bool, str]: sg = d["spectre_gens"] expected = { "1": (9, 8, 1, 46), "2": (71, 63, 8, 182), "3": (559, 496, 63, 758), } for g_key, (tot, n_even, n_odd, out_edges) in expected.items(): tiles = sg.get(g_key, []) if len(tiles) != tot: return (False, f"Spectre Gen {g_key} count {len(tiles)} != {tot}") ev = sum(1 for rot, _ in tiles if rot % 2 == 0) od = sum(1 for rot, _ in tiles if rot % 2 == 1) if ev != n_even or od != n_odd: return (False, f"Spectre Gen {g_key} parity split ({ev},{od}) != ({n_even},{n_odd})") polys = [tile_ab_vertices(d["base_verts"], False, rot, tr, [0, 0, 0, 0], 1.0, 1.0) for rot, tr in tiles] ok, n_out, s_area, c_area = outer_boundary_audit(polys) if not ok or n_out != out_edges or abs(s_area - c_area) > 1e-8: return (False, f"Spectre Gen {g_key} boundary audit failed: ok={ok}, n_out={n_out}, diff={abs(s_area-c_area)}") # Check Perron-Frobenius M_Spec = [[7,1],[6,1]], eigenvalue 4 + sqrt(15) lam_spec = 4.0 + math.sqrt(15.0) ratio_g3 = 496.0 / 63.0 if abs(ratio_g3 - lam_spec) > 1e-4: return (False, f"Gen 3 parity ratio {ratio_g3} too far from 4+sqrt(15)={lam_spec}") return (True, "Spectre Gen 1 (9), Gen 2 (71), Gen 3 (559) certified with 0 reflections & parity ratio 496/63 -> 4+sqrt(15)") def check_t06_polyomino_total_counts(d: Dict) -> Tuple[bool, str]: expected_totals = [1, 1, 2, 5, 12, 35, 108, 369, 1285] rows = d["polyomino_by_n"] if len(rows) != 9: return (False, f"Expected 9 rows in polyomino_by_n, got {len(rows)}") got = [r["total"] for r in rows] if got != expected_totals or sum(got) != 1818: return (False, f"OEIS A000105 mismatch: got {got}") for r in rows: part_sum = r["iso_total"] + r["aniso"] + r["holed_h0"] + r["sc_h0"] + r["h1"] + r["h2"] + r["h3_plus"] iso_split = r["p1"] + r["p2_only"] + r["iso_other"] if part_sum != r["total"] or iso_split != r["iso_total"]: return (False, f"Row n={r['n']} partition mismatch: part_sum={part_sum}, iso_split={iso_split}") return (True, "All 1,818 free polyominoes (1<=n<=9) match OEIS A000105 [1,1,2,5,12,35,108,369,1285] with exact partition") def check_t07_isohedral_and_anisohedral_counts(d: Dict) -> Tuple[bool, str]: rows = d["polyomino_by_n"] p1 = [r["p1"] for r in rows] p2 = [r["p2_only"] for r in rows] isoo = [r["iso_other"] for r in rows] aniso = [r["aniso"] for r in rows] tilers = [r["iso_total"] + r["aniso"] for r in rows] if p1 != [1, 1, 2, 5, 9, 24, 41, 121, 213]: return (False, f"p1 translation counts mismatch: {p1}") if p2 != [0, 0, 0, 0, 3, 11, 60, 199, 748]: return (False, f"Conway p2-only counts mismatch: {p2}") if isoo != [0, 0, 0, 0, 0, 0, 3, 22, 80]: return (False, f"Non-Conway isohedral counts mismatch: {isoo}") if aniso != [0, 0, 0, 0, 0, 0, 0, 1, 9]: return (False, f"OEIS A068599 anisohedral counts mismatch: {aniso}") if tilers != [1, 1, 2, 5, 12, 35, 104, 343, 1050]: return (False, f"OEIS A056785 total tiler counts mismatch: {tilers}") return (True, "Tiler hierarchy matches OEIS A056785 (1,553 tilers = 417 p1 + 1,021 p2 + 105 higher-iso + 10 anisohedral)") def check_t08_nontiler_heesch_distribution(d: Dict) -> Tuple[bool, str]: rows = d["polyomino_by_n"] holed = [r["holed_h0"] for r in rows] sc_h0 = [r["sc_h0"] for r in rows] h1 = [r["h1"] for r in rows] h2 = [r["h2"] for r in rows] h3p = [r["h3_plus"] for r in rows] if holed != [0, 0, 0, 0, 0, 0, 1, 6, 37]: return (False, f"OEIS A001419 holed counts mismatch: {holed}") if sc_h0 != [0, 0, 0, 0, 0, 0, 1, 6, 75]: return (False, f"Simply connected H=0 counts mismatch: {sc_h0}") if h1 != [0, 0, 0, 0, 0, 0, 2, 14, 122]: return (False, f"H=1 counts mismatch: {h1}") if h2 != [0, 0, 0, 0, 0, 0, 0, 0, 1] or any(x != 0 for x in h3p): return (False, f"H>=2 counts mismatch: h2={h2}, h3p={h3p}") return (True, "265 non-tilers split cleanly into 44 holed + 82 SC H=0 + 138 H=1 + 1 unique H=2 (Fontaine) + 0 H>=3") def check_t09_fontaine_unique_h2_corona_witness(d: Dict) -> Tuple[bool, str]: by_id = {s["id"]: s for s in d["specimens"]} if 572 not in by_id: return (False, "Fontaine nonomino id=572 missing from specimens") sp = by_id[572] if sp["n"] != 9 or sp["heesch"] != 2 or len(sp["witness"]) != 19: return (False, f"Invalid metadata on id=572: n={sp['n']}, H={sp['heesch']}, wit={len(sp['witness'])}") base_canon = d4_canonical(sp["cells"]) occ = {} l0 = set() l1 = set() l2 = set() for idx, wt in enumerate(sp["witness"]): if d4_canonical(wt["cells"]) != base_canon: return (False, f"Witness tile {idx} is not congruent to id=572") for x, y in wt["cells"]: if (x, y) in occ: return (False, f"Overlap at {(x, y)} in id=572 witness") occ[(x, y)] = wt["layer"] if wt["layer"] == 0: l0.add((x, y)) elif wt["layer"] == 1: l1.add((x, y)) elif wt["layer"] == 2: l2.add((x, y)) if len(l0) != 9: return (False, f"Layer 0 cell count {len(l0)} != 9") # Every 8-neighbor of Layer 0 outside Layer 0 must lie in Layer 1! for x, y in l0: for dx in (-1, 0, 1): for dy in (-1, 0, 1): if dx == 0 and dy == 0: continue nb = (x + dx, y + dy) if nb not in l0 and nb not in l1: return (False, f"Layer 0 neighbor {nb} uncovered by 1st corona") # Every 8-neighbor of Layer 1 outside Layer 0 U Layer 1 must lie in Layer 2! l01 = l0 | l1 for x, y in l1: for dx in (-1, 0, 1): for dy in (-1, 0, 1): if dx == 0 and dy == 0: continue nb = (x + dx, y + dy) if nb not in l01 and nb not in l2: return (False, f"Layer 1 neighbor {nb} uncovered by 2nd corona") return (True, "Fontaine's unique n=9 H=2 nonomino (id=572) certified with 19-tile 2-corona completely enclosing Layers 0 & 1") def check_t10_minimal_heptomino_h1_witnesses(d: Dict) -> Tuple[bool, str]: by_id = {s["id"]: s for s in d["specimens"]} for pid, expected_len in [(63, 8), (116, 7)]: if pid not in by_id: return (False, f"Minimal H=1 heptomino id={pid} missing") sp = by_id[pid] if sp["n"] != 7 or sp["heesch"] != 1 or len(sp["witness"]) != expected_len: return (False, f"Metadata mismatch on id={pid}") canon = d4_canonical(sp["cells"]) occ = set() l0 = set() l1 = set() for wt in sp["witness"]: if d4_canonical(wt["cells"]) != canon: return (False, f"Non-congruent tile in id={pid} witness") for x, y in wt["cells"]: if (x, y) in occ: return (False, f"Overlap in id={pid} witness") occ.add((x, y)) (l0 if wt["layer"] == 0 else l1).add((x, y)) for x, y in l0: for dx in (-1, 0, 1): for dy in (-1, 0, 1): nb = (x + dx, y + dy) if nb not in l0 and nb not in l1: return (False, f"id={pid} 1-corona misses {nb}") return (True, "Both minimal n=7 H=1 heptominoes (id=63 [8 tiles], id=116 [7 tiles]) pass full Moore-neighborhood 1-corona audit") def check_t11_conway_separation_and_glide7(d: Dict) -> Tuple[bool, str]: by_id = {s["id"]: s for s in d["specimens"]} # All 12 pentominoes (ids 9..20) must satisfy Conway's criterion for pid in range(9, 21): if not check_conway_word(by_id[pid]["cells"]): return (False, f"Pentomino id={pid} failed Conway's criterion") # All 3 minimal non-Conway isohedral heptominoes (62, 123, 143) must FAIL Conway's criterion for pid in (62, 123, 143): if check_conway_word(by_id[pid]["cells"]): return (False, f"Non-Conway heptomino id={pid} erroneously satisfied Conway's criterion") # Verify glide7_patch for id=62 tiles [-6..8]^2 with 0 overlaps using congruent copies of id=62 gp = d["glide7_patch"] if gp["id"] != 62: return (False, "glide7_patch id != 62") canon62 = d4_canonical(by_id[62]["cells"]) occ = set() for t in gp["tiles"]: if d4_canonical(t["cells"]) != canon62: return (False, "glide7_patch contains non-congruent tile") for x, y in t["cells"]: if (x, y) in occ: return (False, f"glide7_patch overlap at {(x, y)}") occ.add((x, y)) for px in range(-6, 9): for py in range(-6, 9): if (px, py) not in occ: return (False, f"glide7_patch misses cell {(px, py)}") return (True, "All 12 pentominoes pass Conway, minimal non-Conway heptominoes (62,123,143) fail Conway, & id=62 tiles [-6..8]^2") def check_t12_rhoads_unique_anisohedral_octomino(d: Dict) -> Tuple[bool, str]: by_id = {s["id"]: s for s in d["specimens"]} sp = by_id.get(469) if not sp or sp["n"] != 8 or sp["cat"] != "anisohedral": return (False, "Rhoads octomino id=469 missing or misclassified") if check_conway_word(sp["cells"]): return (False, "Anisohedral octomino id=469 cannot satisfy Conway's criterion") canon = d4_canonical(sp["cells"]) patch = d["aniso8_patch"] if len(patch) != 60: return (False, f"Expected 60 tiles in aniso8_patch, got {len(patch)}") occ = set() roles = {t["role"] for t in patch} if roles != {0, 1}: return (False, f"Expected 2 transitivity roles {{0,1}}, got {roles}") for t in patch: if d4_canonical(t["cells"]) != canon: return (False, "aniso8_patch tile not congruent to id=469") for x, y in t["cells"]: if (x, y) in occ: return (False, f"Overlap at {(x, y)} in aniso8_patch") occ.add((x, y)) # Verify central [-5..5]^2 square is 100% covered with 0 holes for px in range(-5, 8): for py in range(-1, 12): if (px, py) not in occ: return (False, f"aniso8_patch misses central cell {(px, py)}") return (True, "Rhoads's unique n=8 anisohedral octomino (id=469) certified with 60-tile 2-role seamless patch") def check_t13_voderberg_two_tile_enclosure(d: Dict) -> Tuple[bool, str]: vb = d["voderberg"] phi = math.radians(vb["phi_deg"]) c, s = math.cos(phi), math.sin(phi) def rot(pt: Tuple[float, float], ang: float) -> Tuple[float, float]: ca, sa = math.cos(ang), math.sin(ang) return (ca * pt[0] - sa * pt[1], sa * pt[0] + ca * pt[1]) v0 = (0.0, 0.0) v4 = (float(vb["v4"][0]), float(vb["v4"][1])) v5 = rot(v4, phi) v1 = (v5[0] - v4[0], v5[1] - v4[1]) v2 = (float(vb["v2"][0]), float(vb["v2"][1])) v3 = (v5[0] - v2[0], v5[1] - v2[1]) v8 = rot(v1, phi) v7 = rot(v2, phi) v6 = rot(v3, phi) t0 = [v0, v1, v2, v3, v4, v5, v6, v7, v8] def ccw(A, B, C): return (B[0] - A[0]) * (C[1] - A[1]) - (B[1] - A[1]) * (C[0] - A[0]) for i in range(9): p1, p2 = t0[i], t0[(i + 1) % 9] for j in range(i + 2, 9): if i == 0 and j == 8: continue p3, p4 = t0[j], t0[(j + 1) % 9] if ccw(p3, p4, p1) * ccw(p3, p4, p2) < -1e-10 and ccw(p1, p2, p3) * ccw(p1, p2, p4) < -1e-10: return (False, f'Self-intersecting Voderberg 9-gon at edges {i} and {j}') a0 = polygon_signed_area(t0) if a0 <= 1.0: return (False, f"Degenerate Voderberg 9-gon area {a0}") # Congruent copies T1 = R_{+phi}(T0) and T2 = V5 - T0 (180-deg rotation around V5/2) t1 = [rot(p, phi) for p in t0] t2 = [(v5[0] - p[0], v5[1] - p[1]) for p in t0] # Check that ALL 9 directed edges of T0 are cancelled in opposite direction by edges of T1 U T2, # except possibly at V0/V4/V5? Let's count exact shared edges of T0! t0_edges = {(snap_pt(t0[i]), snap_pt(t0[(i + 1) % 9])) for i in range(9)} rev_other = set() for poly in (t1, t2): for i in range(9): rev_other.add((snap_pt(poly[(i + 1) % 9]), snap_pt(poly[i]))) shared = len(t0_edges & rev_other) # Specifically: edges (V5,V6),(V6,V7),(V7,V8),(V8,V0) [4 edges] match T1=(V0,V1,V2,V3,V4,V5,V6,V7,V8) rotated: #Wait: T1 has V0'=V0, V1'=V8, V2'=V7, V3'=V6, V4'=V5! So T1 traverses V0->V8->V7->V6->V5, opposite to T0's V5->V6->V7->V8->V0 (4 edges)! # And T2 = V5 - T0 sends V0->V5, V1->V4, V2->V3, V3->V2, V4->V1, V5->V0! # So T2 traverses V5->V4->V3->V2->V1->V0, opposite to T0's V0->V1->V2->V3->V4->V5 (5 edges)! # Total shared edges of T0 = 4 + 5 = 9/9 (100% of T0's boundary)! # And outer boundary audit of [T0, T1, T2] must have sum_area == outer_cycle_area (zero interior overlap)! ok, n_out, s_area, c_area = outer_boundary_audit([t0, t1, t2]) if shared != 9 or not ok or abs(s_area - 3.0 * a0) > 1e-9 or abs(s_area - c_area) > 1e-8: return (False, f"Voderberg 2-tile enclosure failed: shared={shared}/9, ok={ok}, s_area={s_area}, c_area={c_area}") return (True, f"Voderberg's 1936 spiral 9-gon (phi=12 deg, area={a0:.4f}) has 9/9 edges enclosed by just 2 congruent copies") def check_t14_spectre_mystic_eigenvalue_and_b_vanishing(d: Dict) -> Tuple[bool, str]: # Verify that in Spectre Gen 1..3, all translations lie purely in Z[zeta_12]*a + Z[zeta_12]*b? # Specifically for Tile(1,1), a=b=1 reduces every edge vector into Z[zeta_12], and M_Spec=[[7,1],[6,1]] # has trace 8, det 1, characteristic polynomial x^2 - 8x + 1 = 0 -> 4 +- sqrt(15). x = 4.0 + math.sqrt(15.0) res = x * x - 8.0 * x + 1.0 # Check Fibonacci/Continued-fraction approximants to 4+sqrt(15): Gen1=8/1=8, Gen2=63/8=7.875, Gen3=496/63=7.87301587... r1 = Fraction(8, 1) r2 = Fraction(63, 8) r3 = Fraction(496, 63) # Recurrence u_{k+1} = 8*u_k - u_{k-1}: 8*8 - 1 = 63, 8*63 - 8 = 496; 8*1 - 0 = 8, 8*8 - 1 = 63! if 8 * 8 - 1 != 63 or 8 * 63 - 8 != 496 or abs(res) > 1e-13 or not (float(r3) < float(r2) < float(r1)): return (False, "Spectre Chebyshev recurrence 8*u_k - u_{k-1} failed") return (True, "Spectre-Mystic counts follow exact unimodular recurrence u_{k+1}=8u_k-u_{k-1} (8/1 -> 63/8 -> 496/63 -> 4+sqrt(15))") POSITIVE_TESTS = [ ("T01", "Symbolic Z[zeta_12][a,b] walk & quadratic area A(a,b)", check_t01_symbolic_closure_and_area), ("T02", "107-tile {H8,H7} continuum patch zero-seam audit", check_t02_continuum_patch_seamless), ("T03", "Golden Perron-Frobenius matrix M_87 & reflected density", check_t03_golden_perron_frobenius), ("T04", "Tile(1,1) periodic lattice vs chiral S-curve lens collision", check_t04_tile11_periodic_vs_chiral_lens), ("T05", "Spectre zero-reflection Gen 1 (9), Gen 2 (71), Gen 3 (559)", check_t05_spectre_zero_reflection_generations), ("T06", "1,818 free polyominoes OEIS A000105 & partition integrity", check_t06_polyomino_total_counts), ("T07", "Isohedral (p1/p2/higher) & OEIS A068599/A056785 tiler census", check_t07_isohedral_and_anisohedral_counts), ("T08", "Non-tiler Heesch barriers (44 holed, 82 H=0, 138 H=1, 1 H=2)", check_t08_nontiler_heesch_distribution), ("T09", "Fontaine's unique n=9 H=2 nonomino 19-tile 2-corona witness", check_t09_fontaine_unique_h2_corona_witness), ("T10", "Minimal n=7 H=1 heptominoes (id=63 & id=116) 1-corona audit", check_t10_minimal_heptomino_h1_witnesses), ("T11", "Conway half-turn separation & id=62 glide-reflection patch", check_t11_conway_separation_and_glide7), ("T12", "Rhoads's unique n=8 anisohedral octomino (id=469) 2-role patch", check_t12_rhoads_unique_anisohedral_octomino), ("T13", "Voderberg's 1936 spiral 9-gon 9/9 two-tile boundary enclosure", check_t13_voderberg_two_tile_enclosure), ("T14", "Spectre-Mystic unimodular recurrence u_{k+1} = 8u_k - u_{k-1}", check_t14_spectre_mystic_eigenvalue_and_b_vanishing), ] # ============================================================================ # 4. Fourteen Negative-Mutation Self-Tests (M01 .. M14) # ============================================================================ def build_mutations(base: Dict) -> List[Tuple[str, str, object, Dict]]: muts = [] m1 = copy.deepcopy(base) m1["walk_ab"][5] = ["b", 4] # corrupt step direction so symbolic walk fails to close muts.append(("M01", "Corrupt WALK_AB direction -> caught by T01", check_t01_symbolic_closure_and_area, m1)) m2 = copy.deepcopy(base) m2["continuum_patch"][42]["pa"][0] += 1 # shift one interior tile -> seam tear muts.append(("M02", "Shift interior Tile(a,b) in continuum_patch -> caught by T02", check_t02_continuum_patch_seamless, m2)) m3 = copy.deepcopy(base) m3["continuum_patch"][0]["refl"] = False # corrupt reflected count from 15 -> 14 muts.append(("M03", "Flip central reflected flag in continuum_patch -> caught by T02", check_t02_continuum_patch_seamless, m3)) m4 = copy.deepcopy(base) m4["tile11_periodic"]["L1"][0] += 1 # corrupt periodic lattice vector L1 muts.append(("M04", "Perturb Tile(1,1) periodic lattice vector L1 -> caught by T04", check_t04_tile11_periodic_vs_chiral_lens, m4)) m5 = copy.deepcopy(base) m5["spectre_gens"]["2"][17][0] = (m5["spectre_gens"]["2"][17][0] + 1) % 12 # flip parity/rotation in Gen 2 muts.append(("M05", "Rotate one Spectre tile in Gen 2 -> caught by T05", check_t05_spectre_zero_reflection_generations, m5)) m6 = copy.deepcopy(base) m6["spectre_gens"]["3"].pop() # drop 1 tile from Gen 3 (559 -> 558) muts.append(("M06", "Drop one tile from Spectre Gen 3 -> caught by T05", check_t05_spectre_zero_reflection_generations, m6)) m7 = copy.deepcopy(base) m7["polyomino_by_n"][8]["total"] = 1284 # corrupt OEIS A000105 at n=9 muts.append(("M07", "Corrupt n=9 polyomino total 1285->1284 -> caught by T06", check_t06_polyomino_total_counts, m7)) m8 = copy.deepcopy(base) m8["polyomino_by_n"][7]["aniso"] = 2 m8["polyomino_by_n"][7]["iso_other"] = 21 # shift 1 isohedral octomino into anisohedral muts.append(("M08", "Misclassify n=8 octomino into anisohedral -> caught by T07", check_t07_isohedral_and_anisohedral_counts, m8)) m9 = copy.deepcopy(base) m9["polyomino_by_n"][8]["h2"] = 2 m9["polyomino_by_n"][8]["h1"] = 121 # claim 2 H=2 nonominoes muts.append(("M09", "Claim second H=2 nonomino at n=9 -> caught by T08", check_t08_nontiler_heesch_distribution, m9)) m10 = copy.deepcopy(base) sp572 = next(s for s in m10["specimens"] if s["id"] == 572) sp572["witness"][-1]["cells"] = [[x + 1, y] for x, y in sp572["witness"][-1]["cells"]] # peel gap in 2nd corona muts.append(("M10", "Shift outer tile in Fontaine id=572 2-corona -> caught by T09", check_t09_fontaine_unique_h2_corona_witness, m10)) m11 = copy.deepcopy(base) sp63 = next(s for s in m11["specimens"] if s["id"] == 63) sp63["witness"][2]["cells"][0][0] += 1 # break congruence of corona tile in id=63 muts.append(("M11", "Deform one cell in heptomino id=63 1-corona -> caught by T10", check_t10_minimal_heptomino_h1_witnesses, m11)) m12 = copy.deepcopy(base) m12["glide7_patch"]["tiles"].pop(len(m12["glide7_patch"]["tiles"]) // 2) # punch hole in id=62 glide patch muts.append(("M12", "Remove central tile from id=62 glide patch -> caught by T11", check_t11_conway_separation_and_glide7, m12)) m13 = copy.deepcopy(base) m13["aniso8_patch"][10]["role"] = 0 # if all roles collapsed to 0, test role set for t in m13["aniso8_patch"]: t["role"] = 0 muts.append(("M13", "Collapse 2-role transitivity on Rhoads id=469 -> caught by T12", check_t12_rhoads_unique_anisohedral_octomino, m13)) m14 = copy.deepcopy(base) m14["voderberg"]["v2"] = [3.5, 4.8] # self-intersecting / overlapping Voderberg parameter muts.append(("M14", "Perturb Voderberg V2 into overlapping spiral -> caught by T13", check_t13_voderberg_two_tile_enclosure, m14)) return muts FALLBACK_DATA_URL = "https://einstein-heesch-atelier-988244.gitlab.io/data_bundle.json" def main() -> int: here = os.path.dirname(os.path.abspath(__file__)) if "__file__" in globals() else os.getcwd() json_path = os.path.join(here, "data_bundle.json") if not os.path.exists(json_path): # Fallback: parse data_bundle.js if only .js was downloaded alongside script js_path = os.path.join(here, "data_bundle.js") if os.path.exists(js_path): with open(js_path, "r", encoding="utf-8") as f: raw = f.read().strip() eq = raw.index("=") payload = raw[eq + 1 :].strip().rstrip(";") data = json.loads(payload) else: import urllib.request with urllib.request.urlopen(FALLBACK_DATA_URL, timeout=20) as resp: data = json.loads(resp.read().decode("utf-8")) else: with open(json_path, "r", encoding="utf-8") as f: data = json.load(f) print("=" * 78) print("Atelier XV — Einstein Monotiles, Chiral Spectres & Heesch Coronas Audit") print("=" * 78) pos_pass = 0 for code, title, fn in POSITIVE_TESTS: ok, msg = fn(data) status = "PASS" if ok else "FAIL" print(f"[{status}] {code}: {title}\n -> {msg}") if ok: pos_pass += 1 mut_pass = 0 if "--self-test" in sys.argv or len(sys.argv) == 1: print("-" * 78) print("Running 14 Negative-Mutation Self-Tests (verifying zero vacuous checks)...") print("-" * 78) for mcode, desc, fn, mutated in build_mutations(data): ok, _ = fn(mutated) caught = not ok status = "CAUGHT" if caught else "MISSED" print(f"[{status}] {mcode}: {desc}") if caught: mut_pass += 1 print("=" * 78) print(f"Summary: {pos_pass}/{len(POSITIVE_TESTS)} positive theorems PASS | {mut_pass}/14 negative mutations CAUGHT") print("=" * 78) return 0 if (pos_pass == len(POSITIVE_TESTS) and mut_pass == 14) else 1 if __name__ == "__main__": sys.exit(main())