#!/usr/bin/env bash
# ADAM Laboratory — 60-Second Independent Verification Script
# License: Apache-2.0 | https://adamlaboratory.com
set -euo pipefail

echo "=== [1/3] Checking Quantum Teardrop & Spin-Star Benchmarks (Python 3 + NumPy) ==="
python3 - <<'PY'
from quantum_teardrop_tomography import (
    benchmark_teardrop_vs_outer_ellipse_dimer_chain,
    project_exact_quantum_teardrop,
)
from quantum_active_shell_tomography import run_4qubit_star_monogamy_benchmark

qx, qy = project_exact_quantum_teardrop(-1.0, -1.0)
print(f"Classical overshoot (-1, -1) -> Exact Quantum Teardrop projection: ({qx:.4f}, {qy:.4f})")
assert abs(qx - (-2.0 / 3.0)) < 1e-9 and abs(qy - (-2.0 / 3.0)) < 1e-9

sx, sy = project_exact_quantum_teardrop(-1.0, -0.35)
print(f"Singlet monogamy (-1, -0.35) -> Projected state: ({sx:.4f}, {sy:.4f})")

rep = benchmark_teardrop_vs_outer_ellipse_dimer_chain()
print("8-Qubit Majumdar-Ghosh Singlet-Dimer Benchmark:", rep)
assert rep["teardrop_gain_vs_outer_ellipse_x"] >= 1.4

star = run_4qubit_star_monogamy_benchmark()
print("4-Qubit Heisenberg Star Monogamy Benchmark:", star)
assert star["non_variational_overshoots_star"] == 0
PY

echo "=== [2/3] Checking Standalone Lean 4.27.0 Proof Archives (if lake/lean is installed) ==="
if command -v lake >/dev/null 2>&1; then
  for f in \
    proofs/quantum_hilbert_operators.lean \
    proofs/quantum_active_shell_bounds.lean \
    proofs/quantum_monge_foundations.lean \
    proofs/number_theory_lerch_radix.lean \
    proofs/polynomial_torsion_casorati.lean; do
    if [ -f "$f" ]; then
      echo "  -> Compiling $f ..."
      lake env lean "$f"
    fi
  done
  echo "All standalone Mathlib Lean 4 files compiled cleanly with 0 sorry!"
else
  echo "  [Info] 'lake' not detected on PATH. To run full Lean 4.27.0 kernel checks:"
  echo "         elan toolchain install leanprover/lean4:v4.27.0"
  echo "         lake +leanprover/lean4:v4.27.0 init verify_ws math && cd verify_ws && lake exe cache get"
fi

echo "=== [3/3] Verification Complete ==="
