#!/bin/sh # Fetch Mathlib cache, build the Lean 4 project, and verify theorem axioms. # Usage: sh verify_lean.sh set -eu root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) if [ -d "$HOME/.elan/bin" ]; then PATH="$HOME/.elan/bin:$PATH" export PATH fi if ! command -v lake >/dev/null 2>&1; then cat >&2 <<'EOF' Error: 'lake' (Lean 4 build tool) was not found in PATH or $HOME/.elan/bin. To install elan (which automatically selects Lean 4.31.0 from lean/lean-toolchain), run: curl https://elan.lean-lang.org/elan-init.sh -sSf | sh Then restart your shell (or add "$HOME/.elan/bin" to PATH) and re-run: sh verify_lean.sh EOF exit 1 fi cd "$root/lean" echo "=== Fetching prebuilt Mathlib cache ===" lake exe cache get echo "=== Building RootTask (Lean 4.31.0) ===" lake build echo "=== Checking theorem axioms ===" axiom_out=$(lake env lean --stdin <<'EOF' import RootTask.VCDimSixFullTheorem #print axioms simple_polygon_vcdim_le_six #print axioms simple_polygon_vcdim_le_eleven EOF ) printf '%s\n' "$axiom_out" for thm in simple_polygon_vcdim_le_six simple_polygon_vcdim_le_eleven; do line=$(printf '%s\n' "$axiom_out" | grep -E "^'${thm}' depends on axioms:" || true) if [ -z "$line" ]; then echo "Error: missing axiom report for ${thm}." >&2 exit 1 fi case "$line" in *sorryAx*|*Lean.ofReduceBool*|*Lean.trustCompiler*) echo "Error: disallowed axiom in ${thm}: $line" >&2 exit 1 ;; esac # Strip expected prefix and allowed standard axioms, check nothing unexpected remains. rest=$(printf '%s\n' "$line" \ | sed -E "s/^'${thm}' depends on axioms: //; s/\[//; s/\]//; s/propext//g; s/Classical\.choice//g; s/Quot\.sound//g; s/[,[:space:]]+//g") if [ -n "$rest" ]; then echo "Error: unexpected axiom(s) in ${thm}: $line" >&2 exit 1 fi done echo "Lean verification succeeded: both theorems depend only on [propext, Classical.choice, Quot.sound]."