#!/usr/bin/env python3 from __future__ import annotations import json import math import sys from pathlib import Path def independent_bound(row: dict) -> float: eigenvalues = row["prior_eigenvalues"] d = row["d"] horizon = row["T"] q = 24.0 * math.log(horizon) / d c1 = math.sqrt(1.0 + max(q, math.sqrt(q))) c2 = 2.0 * c1 * math.sqrt(math.log(1.0 + row["radius"] ** 2 * max(eigenvalues) * horizon / (d * row["sigma"] ** 2))) return ( d * row["sigma"] * math.sqrt(horizon) * c2 + 3.0 * math.sqrt(2.0) * row["radius"] * math.sqrt(d) * sum(math.sqrt(value) for value in eigenvalues) * c1 + math.sqrt(2.0 * row["radius"] ** 2 * sum(eigenvalues)) ) def main() -> None: evidence = json.loads(Path(sys.argv[1]).read_text()) rows = evidence["rows"] relative_errors = [abs(independent_bound(row) - row["theorem_1_bound"]) / row["theorem_1_bound"] for row in rows] checks = { "all_covariance_eigenvalues_positive": all(min(row["prior_eigenvalues"]) > 0 for row in rows), "all_actions_use_positive_radius": all(row["radius"] > 0 for row in rows), "formula_reconstruction_matches": max(relative_errors) < 1e-12, "confidence_intervals_finite": all(math.isfinite(row["regret_ci95_low"]) and math.isfinite(row["regret_ci95_high"]) for row in rows), "legacy_column_has_exact_sqrt_T_multiplier": all(abs(row["legacy_multiplicative_burnin_scale"] / row["corollary_burnin_scale"] - math.sqrt(row["T"])) < 1e-12 for row in rows), } output = {"passed": all(checks.values()), "checks": checks, "max_formula_relative_error": max(relative_errors)} print(json.dumps(output, sort_keys=True)) raise SystemExit(0 if output["passed"] else 1) if __name__ == "__main__": main()