SilverSight/scripts/wolfram_verify.py
allaun f6cbddcbf2 feat(tests): Python AVM port rewrite + test harness, Go test harness
Python port rewritten to match spec:
- Added Q0_16, PUSH_Q0, PUSH_BOOL as separate opcodes
- Added V6 comparison (lt_q16_v6)
- Added floor division (Lean Int.ediv)
- Added stack depth limit (AVM_MAX_STACK = 1024)
- Added type checking in exec_prim
- All 10 tests passing

Go AVM port: added test_avm_test.go with 8 test cases

Milestone: Python → , Go → 🔄
2026-06-30 17:56:09 -05:00

95 lines
4.4 KiB
Python

#!/usr/bin/env python3
"""
Wolfram Alpha Mathematical Verification — SilverSight
Verifies all core mathematical claims of the project.
"""
import urllib.request, urllib.parse, json, sys, os, hashlib
APPID = "HYJE3R3R63"
QUERIES = {
# ── Q16_16 fixed-point arithmetic ─────────────────────────────
"q16_scale_factor": "65536",
"q16_mul_identity": "simplify (a * b / 65536) when a = 65536",
"q16_saturation_bounds": "range of int32 signed integer",
# ── Rossby/Kelvin wave correspondence ─────────────────────────
"rossby_dispersion": "omega = -beta * k / (k^2 + l^2) Rossby wave dispersion",
"kelvin_wave_nondispersive": "omega = k * sqrt(g * H) Kelvin wave",
"rossby_deformation_radius": "L_D = sqrt(g * H) / f Rossby deformation radius",
# ── Golden ratio / corkscrew ──────────────────────────────────
"golden_ratio_conjugate": "solve x^2 - x - 1 = 0",
"corkscrew_angle": "2 * pi / ((1 + sqrt(5)) / 2)^2",
# ── Fisher information metric ─────────────────────────────────
"fisher_metric_simplex": "arccos(sum sqrt(p_i * q_i))",
"fisher_distance": "2 * arccos(sqrt(p * q)) Fisher distance",
"cauchy_schwarz_fisher": "sum sqrt(p_i * q_i) <= 1 for probability distributions",
# ── Eigensolid convergence ────────────────────────────────────
"pair_averaging_idempotent": "simplify ((a+b)/2 + (c+d)/2) / 2",
"pair_averaging_contractive": "prove |(a+b)/2 - (c+d)/2| < |a-c| + |b-d|",
"chaos_game_contraction": "prove (1-eps)^k < 2^(-k) for 0 < eps < 1",
# ── NUVMAP projection ─────────────────────────────────────────
"nuvmap_eigenmass": "limit lambda * v * S * L / (R + epsilon) as R -> 0",
"bekenstein_bound": "A / (4 * L_p^2) Bekenstein bound",
"eigenvalue_power_iteration": "Rayleigh quotient convergence power iteration",
# ── Sidon sets ────────────────────────────────────────────────
"sidon_condition": "powers of 2 pairwise distinct sums",
"sidon_slack_128": "128 - 2^7 =",
"binary_sidon_max_sum": "max sum of distinct powers of 2 from 1,2,4,...,128",
}
def query_wolfram(query):
encoded = urllib.parse.quote_plus(query)
url = f"http://api.wolframalpha.com/v2/query?appid={APPID}&input={encoded}&format=plaintext&output=JSON"
try:
req = urllib.request.Request(url, headers={'User-Agent': 'SilverSight/1.0'})
with urllib.request.urlopen(req, timeout=15) as resp:
return json.loads(resp.read().decode('utf-8'))
except Exception as e:
return {"error": str(e)}
def extract_result(res):
if "error" in res:
return f"[ERROR: {res['error']}]"
if "queryresult" not in res:
return "[no queryresult]"
qr = res["queryresult"]
for pod in qr.get("pods", []):
for subpod in pod.get("subpods", []):
if "plaintext" in subpod and subpod["plaintext"]:
return subpod["plaintext"]
return "[no plaintext result]"
def main():
results = {}
for name, query in QUERIES.items():
print(f" {name}...", end=" ", flush=True)
resp = query_wolfram(query)
text = extract_result(resp)
results[name] = {"query": query, "result": text}
print(text[:80] if text else "(empty)")
# Build receipt
receipt = {
"schema": "wolfram_verification_v2",
"generated_at": __import__('datetime').datetime.utcnow().isoformat(),
"n_queries": len(QUERIES),
"queries": results,
"claim_boundary": "wolfram-alpha-algebraic-verification-only",
}
payload = json.dumps(results, sort_keys=True).encode()
receipt["receipt_hash"] = hashlib.sha256(payload).hexdigest()[:16]
path = os.path.expanduser("~/SilverSight/signatures/wolfram_verification_receipt.json")
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w") as f:
json.dump(receipt, f, indent=2)
print(f"\nReceipt: {path}")
if __name__ == "__main__":
main()