Research-Stack/scripts/math-first/test_require_math_evidence.py
Devin AI 0639eae30a chore(consolidation): integrate E8Sidon stack (PRs #79 #80 #81 #89) into one PR
Squash the four overlapping feature branches into a single change set against
main, eliminating cross-PR merge conflicts and the duplicated CI-fix scripts.

What this brings in (merge order #79 -> #80 -> #81 -> #89):
- #79 refactor(infra): shared utilities (4-Infrastructure/lib/*: q16, hashing,
  jsonl, fraction_utils) + the scripts/math-first/* validators that the
  math-check CI requires.
- #80 feat(lean): Semantics.E8Sidon (1025 lines) -- Eisenstein coefficient
  identity E4^2 = E8 and the Sidon framework. E4_sq_eq_E8_coeff is fully proved
  (all Fourier-coefficient extraction machine-checked); the single residual gap
  is pinned to E4_sq_eq_E8_qExpansion (Mathlib lacks the valence formula /
  dim M8 = 1). 4 sorries + 1 axiom (e8_additive_completeness), all TODO(lean-port).
- #81 refactor(lean): Float-free FixedPoint core (integer-only sqrt/log2/expNeg).
  E8Sidon.lean kept at #80's final 1025-line version (the #81 intermediate
  438-line copy was overridden by merge order).
- #89 feat(lean): Semantics.RRC.PolyFactorIdentity -- short-sleeve polynomial
  detection at the zerocopy limb boundary; now imports Semantics.E8Sidon for
  sigma3/sigma7/convolutionLHS (single source of truth) instead of inlining them.

Conflict resolution:
- flake.nix -> canonical rs-surface removal (Garnix shutdown).
- scripts/math-first/* -> byte-identical across branches, clean.
- .cursorrules / AGENTS.md -> unified; baselines + sorry inventory refreshed.

Verification:
- lake build (default aggregator): 3573 jobs, 0 errors.
- lake build Semantics.RRC.PolyFactorIdentity (E8Sidon + FixedPoint + PolyFactor):
  3655 jobs, 0 errors. Witnesses verified (sigma7 4 = 16513, convolutionLHS 6 = 2350).
- Python tests: 68/68 pass.

Note: the "Workers Builds: researchstack" check is a preexisting external
Cloudflare build unrelated to this change (no branch touches 4-Infrastructure/cloudflare/).

Build: 3573 jobs (default), 3655 jobs (narrow), 0 errors
Co-Authored-By: Allaun Silverfox <bigdataiscoming+9i37y6j2@protonmail.com>
2026-06-16 02:01:31 +00:00

115 lines
3.2 KiB
Python
Executable file

#!/usr/bin/env python3
"""Self-tests for require_math_evidence.py.
Tests the classification logic (is_math_track, is_evidence) without needing
a live git repo. Exits 0 on success, 1 on failure.
"""
from __future__ import annotations
import importlib.util
import sys
from pathlib import Path
SCRIPT_DIR = Path(__file__).resolve().parent
def _load_module():
"""Import require_math_evidence as a module (it has dashes in the dir name)."""
spec = importlib.util.spec_from_file_location(
"require_math_evidence",
SCRIPT_DIR / "require_math_evidence.py",
)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
def test_math_track_classification() -> bool:
"""Verify is_math_track correctly identifies math-track paths."""
mod = _load_module()
positives = [
"0-Core-Formalism/lean/Semantics/Semantics/E8Sidon.lean",
"6-Documentation/docs/distilled/ArithmeticSpec.md",
"shared-data/data/stack_solidification/receipt.md",
]
negatives = [
"4-Infrastructure/shim/some_script.py",
"scripts/math-first/validate_deepseek_receipts.py",
"README.md",
"flake.nix",
]
ok = True
for p in positives:
if not mod.is_math_track(p):
print(f"FAIL: {p} should be math-track but is not")
ok = False
for p in negatives:
if mod.is_math_track(p):
print(f"FAIL: {p} should NOT be math-track but is")
ok = False
if ok:
print("PASS: math-track classification")
return ok
def test_evidence_classification() -> bool:
"""Verify is_evidence correctly identifies evidence paths."""
mod = _load_module()
positives = [
"shared-data/artifacts/deepseek_review/foo.receipt.json",
"0-Core-Formalism/lean/Semantics/Semantics/E8Sidon.lean",
"claims.yaml",
]
negatives = [
"4-Infrastructure/shim/some_script.py",
"README.md",
]
ok = True
for p in positives:
if not mod.is_evidence(p):
print(f"FAIL: {p} should be evidence but is not")
ok = False
for p in negatives:
if mod.is_evidence(p):
print(f"FAIL: {p} should NOT be evidence but is")
ok = False
if ok:
print("PASS: evidence classification")
return ok
def test_lean_file_is_self_evidence() -> bool:
"""A Lean file IS its own evidence (under the evidence prefix)."""
mod = _load_module()
lean = "0-Core-Formalism/lean/Semantics/Semantics/E8Sidon.lean"
if not mod.is_math_track(lean):
print("FAIL: Lean file not detected as math-track")
return False
if not mod.is_evidence(lean):
print("FAIL: Lean file not detected as evidence")
return False
print("PASS: Lean file is both math-track and evidence (self-evidencing)")
return True
def main() -> int:
tests = [
test_math_track_classification,
test_evidence_classification,
test_lean_file_is_self_evidence,
]
passed = sum(1 for t in tests if t())
total = len(tests)
print(f"\n{passed}/{total} tests passed")
return 0 if passed == total else 1
if __name__ == "__main__":
raise SystemExit(main())