#!/usr/bin/env python3 """Replay all three finite inputs using the Python scripts supplied in this ZIP.""" from pathlib import Path import argparse import json import subprocess import sys HERE = Path(__file__).resolve().parent def normalize(value): if isinstance(value, dict): return {k: normalize(v) for k, v in value.items() if k != "seconds"} if isinstance(value, list): return [normalize(v) for v in value] return value def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--with-product", action="store_true", help="also regenerate both product seeds; requires python-flint==0.9.0") args = parser.parse_args() reports = ["fifteen-certificate.json", "phase-polynomial-certificate.json", "fifteen-seed-second-check.json"] if args.with_product: reports += ["fifteen-seed-p10007.json", "fifteen-seed-p10009.json", "fifteen-seed-rows-p10007.json", "fifteen-seed-rows-p10009.json"] expected = {name: normalize(json.loads((HERE/name).read_text())) for name in reports} commands = [["certify_fifteen.py"], ["certify_phase_polynomial.py"]] if args.with_product: commands += [["seed_fifteen.py", "--prime", str(p)] for p in (10007, 10009)] commands += [["verify_fifteen_seed.py"]] for command in commands: result = subprocess.run([sys.executable, "-B", str(HERE/command[0]), *command[1:]], cwd=HERE, text=True, capture_output=True) if result.returncode: raise SystemExit(result.stdout + result.stderr) print(command[0] + ": passed", flush=True) for name in reports: assert normalize(json.loads((HERE/name).read_text())) == expected[name], name result = {"status": "passed", "reports_matched": reports, "arithmetic_intervals": 38371, "seed_coefficients": 4154, "scope": "Finite-input replay; not a mathematical audit or formal verification."} (HERE/"hexagon-check-report.json").write_text(json.dumps(result, indent=2)+"\n") print("All supplied mathematical outputs reproduced exactly (timings excluded).") if __name__ == "__main__": main()