"""Reproduce the Q8 antipodal exclusion using only this deposit's files.""" from math import comb from pathlib import Path import os import re import subprocess import sys from tempfile import TemporaryDirectory HERE = Path(__file__).resolve().parent ORBIT_COUNTS = (3, 9, 22, 64, 147, 321, 567, 891, 1133, 1252, 1133, 891, 567, 321, 147, 64) def main(): if not __debug__: raise RuntimeError("Run Python without -O") for check in ("check_witness.py", "check_overlap_moment.py"): subprocess.run([sys.executable, "-B", str(HERE / check)], check=True) tex = (HERE.parent / "main.tex").read_text(encoding="utf-8") block = tex.split("% Q8-CPP-BEGIN\n", 1)[1].split("% Q8-CPP-END\n", 1)[0] opening, sep, body = block.partition("\n") code, closing, tail = body.rpartition("\\end{lstlisting}\n") if not opening.startswith(r"\begin{lstlisting}") or not sep or not closing or tail: raise RuntimeError("Unexpected C++ listing format") with TemporaryDirectory(prefix="q8-replay-") as work: work = Path(work) src, exe = work / "antipodal_orbits.cpp", work / "search" src.write_text(code, encoding="utf-8") subprocess.run([os.environ.get("CXX", "c++"), "-O3", "-std=c++17", str(src), "-o", str(exe)], check=True) for start, stop in ((1, 13), (14, 16)): result = subprocess.run( [str(exe), str(HERE / "q8_k40.csv"), str(start), str(stop)], check=True, text=True, capture_output=True) print(result.stdout, end="", flush=True) rows = re.findall( r"^k=(\d+) subsets=(\d+) orbits=(\d+) nodes=\d+ no improvement(?: \((maximum-overlap case)\) outsider-range=\d+\.\.\d+)?$", result.stdout, re.M) expected = [(str(k), str(comb(20, k)), str(ORBIT_COUNTS[k-1]), "maximum-overlap case" if start == 14 else "") for k in range(start, stop+1)] if rows != expected or "positive repair control passed" not in result.stdout: raise RuntimeError(f"Unexpected replay results for layers {start}–{stop}") print("PASS: full antipodal exclusion, layers 1–16") if __name__ == "__main__": main()