Research-Stack/5-Applications/scripts/fixedpoint_wolfram_verify.py
Brandon Schneider c5b6a31a8b feat: add RDS probe tool, credential server, and Notion/Linear ingestion pipeline
New infrastructure components:
- rds_probe: Rust database inspection tool with IAM auth
- credential_server.py: REST credential provider server
- credential_provider.py: credential resolution chain
- ene_rds_fractal_fold.py / ene_rds_wiki_layer.py: RDS-backed ENE layers
- import_dumps_to_rds.py / export_linear_from_rds.py: ingestion pipeline
- recover_credential_server.sh: deployment script (sanitized)

Sanitize hardcoded secrets across codebase:
- Strip API keys from recover_credential_server.sh → env var lookups
- Replace hardcoded Wolfram appid (HYJE3R3R63) → env var in 5 scripts
- Strip fallback key values from config/index.js
- Add .claude/ and optimized_basis_v3.bin to .gitignore

Ingested 2,685 records into RDS: 2,421 Linear issues + 264 wiki pages
2026-05-18 00:31:44 -05:00

162 lines
5.7 KiB
Python

#!/usr/bin/env python3
"""
Wolfram Alpha Verification for FixedPoint.lean Theorems
Verifies the 9 FixedPoint.lean theorems using Wolfram Alpha API:
- mul_one, div_one, max_first_whenGe, max_second_whenLt
- min_first_whenLe, min_second_whenGt, neg_involutive, abs_nonNegative, sqrt_one
"""
import sys
import json
import os
import urllib.parse
import urllib.request
from pathlib import Path
class WolframAlphaVerifier:
"""Wolfram Alpha API client for mathematical verification."""
BASE_URL = "https://api.wolframalpha.com/v2/query"
def __init__(self, app_id: str):
self.app_id = app_id
def query(self, input_expr: str) -> dict:
"""Query Wolfram Alpha API."""
params = {
"input": input_expr,
"format": "plaintext",
"output": "JSON",
"appid": self.app_id,
}
url = f"{self.BASE_URL}?{urllib.parse.urlencode(params)}"
try:
with urllib.request.urlopen(url, timeout=30) as response:
return json.loads(response.read().decode("utf-8"))
except Exception as e:
return {"error": str(e)}
@staticmethod
def _norm(s: str) -> str:
return "".join(s.split()).lower()
def verify(self, equation: str, description: str, expected: str) -> dict:
"""Verify a mathematical equation."""
print(f"\n🔍 {description}")
print(f" Equation: {equation}")
print(f" Expected: {expected}")
result = self.query(equation)
if "error" in result:
print(f"❌ Error: {result['error']}")
return {"equation": equation, "description": description,
"expected": expected, "status": "error", "error": result["error"]}
qr = result.get("queryresult", {})
if not qr.get("success"):
print("❌ Query failed")
return {"equation": equation, "description": description,
"expected": expected, "status": "failed"}
pods = qr.get("pods", [])
all_texts = []
primary_text = None
for pod in pods:
for sub in pod.get("subpods", []):
txt = sub.get("plaintext", "")
if txt:
all_texts.append(txt)
if pod.get("primary") and primary_text is None:
primary_text = txt
expected_n = self._norm(expected)
haystack = self._norm(" ".join(all_texts))
matched = expected_n in haystack
observed = primary_text or (all_texts[0] if all_texts else "")
if matched:
print(f"✅ Result: {observed}")
return {"equation": equation, "description": description,
"expected": expected, "observed": observed, "status": "verified"}
else:
print(f"❌ MISMATCH — got: {observed}")
return {"equation": equation, "description": description,
"expected": expected, "observed": observed,
"status": "mismatch", "all_pods": all_texts}
def main():
print("=" * 70)
print("FIXEDPOINT.LEAN WOLFRAM ALPHA VERIFICATION")
print("Verifying 9 FixedPoint.lean theorems")
print("=" * 70)
app_id = os.environ.get("WOLFRAM_ALPHA_APPID", "")
verifier = WolframAlphaVerifier(app_id)
# FixedPoint.lean theorems to verify
# (equation, description, expected_substring)
theorems = [
# Arithmetic identities
("x * 1 = x", "mul_one: multiplication by identity", "x"),
("x / 1 = x", "div_one: division by identity", "x / 1 = x"),
("-(-x) = x", "neg_involutive: double negation", "x"),
# Max/min properties
("max(x, x) = x", "max_first_whenGe: max reflexive", "= x"),
("max(x, y) = y when x < y", "max_second_whenLt: max returns larger", "y"),
("min(x, x) = x", "min_first_whenLe: min reflexive", "= x"),
("min(x, y) = y when x > y", "min_second_whenGt: min returns smaller", "y"),
# Absolute value
("abs(x) >= 0", "abs_nonNegative: absolute value non-negative", ">= 0"),
# Square root
("sqrt(0) = 0", "sqrt_zero: square root of zero", "= 0"),
("sqrt(1) = 1", "sqrt_one: square root of one", "= 1"),
]
print(f"\nVerifying {len(theorems)} FixedPoint.lean theorems...")
results = [verifier.verify(eq, desc, exp) for eq, desc, exp in theorems]
# Summary
print("\n" + "=" * 70)
print("VERIFICATION SUMMARY")
print("=" * 70)
verified = sum(1 for r in results if r["status"] == "verified")
mismatch = sum(1 for r in results if r["status"] == "mismatch")
failed = sum(1 for r in results if r["status"] in ("error", "failed"))
total = len(results)
pass_rate = verified / total if total else 0.0
print(f"Total theorems: {total}")
print(f"✅ Verified: {verified}")
print(f"⚠️ Mismatch: {mismatch}")
print(f"❌ Failed: {failed}")
print(f"\nPass rate: {pass_rate:.1%}")
# Save results
output_file = Path("shared-data/data/fixedpoint_wolfram_verification.json")
output_file.parent.mkdir(parents=True, exist_ok=True)
with open(output_file, "w") as f:
json.dump({
"app_id": app_id,
"timestamp": Path(__file__).stat().st_mtime,
"total": total,
"verified": verified,
"mismatch": mismatch,
"failed": failed,
"pass_rate": pass_rate,
"results": results,
}, f, indent=2)
print(f"\nResults saved to: {output_file}")
print("=" * 70)
if __name__ == "__main__":
main()