"""Stable, source-bound envelopes for the workbench's finite computations. Each program retains its exact arithmetic certificate under ``result``. The envelope identifies the executable and this serializer by SHA-256, records the statement scope, and distinguishes a finite computation from an asymptotic or formal proof. No wall-clock field is included, so expected outputs are stable. Run the whole suite with ``python3 run_checks.py`` from the version directory. """ from __future__ import annotations import hashlib import inspect import json from pathlib import Path STATEMENTS = { "check_tang_17_3.py": ["GRH-P009", "GRH-P011", "GRH-P012"], "check_kummer_examples.py": ["GRH-P001", "GRH-P004", "GRH-P021"], "check_elliptic_17_3.py": ["GRH-P024"], "derive_cm_inputs.py": ["GRH-P037"], "check_cm_15_135.py": ["GRH-P037"], "check_sextic_cm_endpoint_17.py": ["GRH-P113", "GRH-P119"], "check_fixed_wild_r5.py": ["GRH-P139"], "check_small_cofactor_cubic.py": ["GRH-P129", "GRH-P131"], "verify_higher_three_power.py": ["GRH-P122", "GRH-P123", "GRH-P124"], "verify_fixed_cm_torsion.py": ["GRH-P135", "GRH-P136"], "verify_restricted_volcano.py": ["GRH-P055", "GRH-P064", "GRH-P065"], "verify_ordinary_quartic.py": ["GRH-P072", "GRH-P080", "GRH-P081"], "verify_supersingular_point.py": ["GRH-P096"], "probe_cubic_routes.py": [], } def sha256(path: Path) -> str: return hashlib.sha256(path.read_bytes()).hexdigest() def envelope(result, source_path: str | Path) -> dict: source = Path(source_path).resolve() return { "schema": "finite-computation-certificate/2", "program": source.name, "program_sha256": sha256(source), "serializer_sha256": sha256(Path(__file__).resolve()), "statement_scope": STATEMENTS.get(source.name, []), "verification_type": "finite exact computation; not a formal certificate or a proof of a uniform complexity bound", "result": result, } def emit_json(serialized: str) -> None: caller = inspect.currentframe().f_back source = caller.f_globals["__file__"] print(json.dumps(envelope(json.loads(serialized), source), indent=2, sort_keys=True)) def write_certificate(path: str | Path, result, source_path: str | Path) -> None: Path(path).write_text( json.dumps(envelope(result, source_path), indent=2, sort_keys=True) + "\n", encoding="utf-8", )