feat: Add Lean formalization via lean-dojo for powerful theorem proving#1
feat: Add Lean formalization via lean-dojo for powerful theorem proving#1Ash-Blanc wants to merge 3 commits intoevalops:mainfrom
Conversation
This file implements a Lean translator that converts natural language claims into Lean 4 formalizations, utilizing pattern-based translation strategies for various claim types such as arithmetic and algorithms.
Implement Lean 4 theorem prover using LeanDojo API for automated proof search and verification.
Implement hybrid resolver for Lean and Coq theorem proving.
| # Fallback to Coq | ||
| if self.use_fallback: | ||
| coq_result = self._try_coq_proof(claims) | ||
| if coq_result.get("proven"): |
There was a problem hiding this comment.
Bug: The code calls .get() on a ProofResult dataclass object, which lacks this method, causing an AttributeError. The object is incorrectly assumed to be a dictionary.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The function _try_coq_proof is type-hinted to return a Dict but returns a ProofResult dataclass object on a successful proof. The calling code at line 73 and 83 attempts to use the .get("proven") method on the returned object. Since dataclass objects do not have a .get() method, this will raise an AttributeError whenever the Coq prover is used as a fallback. This will cause the hybrid resolver functionality to fail.
💡 Suggested Fix
Access the proven attribute directly on the ProofResult object using coq_result.proven instead of coq_result.get("proven"). Additionally, correct the return type hint for _try_coq_proof to Union[ProofResult, Dict] to accurately reflect its possible return types.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: formal_verification/hybrid_lean_coq_resolver.py#L73
Potential issue: The function `_try_coq_proof` is type-hinted to return a `Dict` but
returns a `ProofResult` dataclass object on a successful proof. The calling code at line
73 and 83 attempts to use the `.get("proven")` method on the returned object. Since
dataclass objects do not have a `.get()` method, this will raise an `AttributeError`
whenever the Coq prover is used as a fallback. This will cause the hybrid resolver
functionality to fail.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7743576
Bug Analysis & FixesGreat catch by the AI reviewer! I've analyzed the bugs in detail. Here's a comprehensive breakdown: Root CauseThe
The code at lines 73 and 83 assumes the return is always a dict and calls Bugs FoundBug #1 - Line 73: Bug #2 - Line 83: Fixes RequiredBest Solution: To: Also update return type hint on line 128: This ensures consistent handling with .get() calls on lines 73 and 83. |
Overview
This PR introduces Lean 4 formalization via the LeanDojo framework as a powerful complement to the existing Coq-based theorem proving system. Lean offers superior proof automation, better support for inductive reasoning, and a more expressive type system, making it an excellent choice for resolving complex cognitive dissonance scenarios.
Motivation
While Coq provides solid formal verification capabilities, Lean 4 + LeanDojo brings several advantages:
Changes
Adds three new modules to
formal_verification/:1.
lean_translator.py2.
lean_prover.pyleancommand3.
hybrid_lean_coq_resolver.pyBenefits
✅ Extended proof coverage: Claims unprovable in Coq may be provable in Lean
✅ Better automation: Less reliance on manual proof strategies
✅ Cross-verification: Multiple provers increase confidence in results
✅ Type-safety: Lean's type system catches more errors earlier
✅ Future-proof: Lean's growing ecosystem and LeanDojo support
Integration
The hybrid resolver seamlessly integrates with existing DSPy agents:
Dependencies
Requires installation of:
lean(Lean 4 theorem prover)leandojo(Python package for LeanDojo API)coq(already required)Testing
All modules include:
Related Issues
Closes/References roadmap item: "Integration with LeanDojo/APOLLO for cross-prover validation"
Future Work