LLM agent for formal theorem proving in Lean 4
LeanAgent is an LLM-based agent for automated theorem proving in Lean 4, a modern proof assistant. It combines LLM reasoning with formal verification — proposing proof steps that are verified by Lean's type checker. Can prove novel theorems, not just benchmarks, by exploring proof strategies, backtracking on failures, and learning from successful proofs.
Theorem Statement (Lean 4)
↓
Goal Analysis Agent (understand proof obligations)
↓
Tactic Suggestion Agent (propose proof steps)
↓
Lean 4 Verification (check tactic correctness)
↓
Backtracking (if tactic fails, try alternatives)
↓
Proof or timeout
from lean_agent import LeanAgent
agent = LeanAgent(
llm_provider="anthropic",
lean_path="/path/to/lean4",
)
# Prove a theorem
result = agent.prove(
theorem="""
theorem add_comm (m n : Nat) : m + n = n + m := by
sorry
""",
max_attempts=50,
timeout=120,
)
if result.proved:
print("Proof found!")
print(result.proof)