#!/usr/bin/env python3 """The project's second judge, the check `improves`, which informs and does not block a merge: the pushed route's best certificate against the best the default branch holds (constructions/ and routes/ of the check's own checkout, the approved version) and against the best known bound. It says by how much the route improves on the default branch and passes when that is at least the minimum improvement, 1e-7 (EinsteinArena's for first place on this problem); a route at least that far below the best known bound is a new result. On the default branch itself it reports what it holds and passes.""" import json import os import pathlib import sys from fractions import Fraction from verify_overlap import CertificateError, certify, decimal_up MINIMUM = Fraction("1e-7") KNOWN = "0.3808564043546676" # the EinsteinArena leader, NIGHTFALL-DevinWright, 2026-10-20 (the README's known bounds) def show(x): return f"{float(x):.3g}".replace("e-0", "e-") def best(roots): out = None for root in roots: for path in sorted(root.rglob("*.json")) if root.exists() else []: try: cert = json.loads(path.read_text()) except Exception: continue if not isinstance(cert, dict) or "values" not in cert: continue try: result = certify(cert) except CertificateError: continue if out is None or result["bound"] < out[0]: out = (result["bound"], path) return out main_dir = pathlib.Path(sys.argv[2]) held = best([main_dir / "constructions", main_dir / "routes"]) if os.environ.get("SS_ROUTE_DIR", "") == "routes": print(f"the default branch holds best upper bound {decimal_up(held[0])}" if held else "the default branch holds no certificate") sys.exit(0) route = best([pathlib.Path(sys.argv[1])]) if not route: print("no certificate in this route to compare") sys.exit(1) this = f"best upper bound {decimal_up(route[0])} ({route[1].name})" known = f"a new result, {show(Fraction(KNOWN) - route[0])} below the best known {KNOWN}" if Fraction(KNOWN) - route[0] >= MINIMUM else f"not a new result: the best known is {KNOWN}" gain = held[0] - route[0] if held else None if gain is None: print(f"improves on the default branch, which holds no certificate: {this}; {known}") elif gain <= 0: print(f"no improvement: {this}; the default branch holds {decimal_up(held[0])}; {known}") sys.exit(1) elif gain < MINIMUM: print(f"improves on the default branch by {show(gain)}, less than the minimum {show(MINIMUM)}: {this}, against {decimal_up(held[0])}; {known}") sys.exit(1) else: print(f"improves on the default branch by {show(gain)} (at least {show(MINIMUM)}): {this}, against {decimal_up(held[0])}; {known}")