#!/usr/bin/env python3 """Recompute the arithmetic predicates in a fresh scratch copy.""" from argparse import ArgumentParser import json import os from pathlib import Path from shutil import copytree, ignore_patterns from subprocess import STDOUT, run import sys CHECKS = Path(__file__).resolve().parent def main(): parser = ArgumentParser(description=__doc__) parser.add_argument("--work", type=Path, required=True, help="fresh scratch directory") args = parser.parse_args() if not __debug__: parser.error("Enable Python assertions for the arithmetic replay.") work = args.work.resolve() release = CHECKS.parent.parent if release == work or release in work.parents: parser.error("Put the scratch directory outside the release directory.") work.mkdir(parents=True, exist_ok=False) source = work / "source" / "checks" copytree(CHECKS, source, ignore=ignore_patterns("lean", "__pycache__")) environment = os.environ.copy() environment.pop("PYTHONOPTIMIZE", None) environment["PYTHONDONTWRITEBYTECODE"] = "1" replayed = [] def check_command(label, command, cwd): log = work / f"{label}.log" print(f"Running {label}", flush=True) with log.open("xb") as output: result = run(command, cwd=cwd, env=environment, stdout=output, stderr=STDOUT) if result.returncode: raise ValueError(f"{label} failed (exit {result.returncode}). See {log}.") replayed.append(label) def check(label, relative): script = source / relative check_command(label, [sys.executable, "-B", str(script)], script.parent) check("reverse-symbolic-elimination", "symbolic/check_reverse.py") check("winding-stationarity-comparison", "symbolic/check_budget.py") check("master-secant-relation", "symbolic/check_secant.py") check("reverse-window-by-secants", "symbolic/check_reverse_secant.py") check("regular-and-mixed-examples", "symbolic/check_examples.py") check("forward-switch-comparison", "symbolic/check_forward_window.py") check("forward-minimum-coefficients", "symbolic/check_forward_minimum.py") check("stationarity-and-constants", "check_core.py") check("geometric-interfaces", "check_geometric_interfaces.py") check("finite-switching-identities", "check_finite_switching.py") check("reverse-and-terminal-identities", "reverse/check_identities.py") check("forward-angle-identities", "symbolic/check_winding_identities.py") check("forward-angle-certificate", "forward/check_winding.py") check("polar-and-turn-identities", "check_polar_and_turn.py") check("margin-area-normalization", "check_area_normalization.py") marked_center = CHECKS.parent / "section-8-marked-reverse-center.py" check_command("marked-center-notebook", [sys.executable, "-B", str(marked_center)], source) scope = "Exact computational checks for Claims V1 through V12 of reinhardt_v102." report = {"scope": scope, "completed": replayed} (work / "ARITHMETIC.json").write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8") print(f"PASS {scope} Logs: {work}") if __name__ == "__main__": try: main() except (OSError, ValueError) as exc: raise SystemExit(f"FAIL arithmetic replay: {exc}") from exc