LeanReasoner: Boosting Complex Logical Reasoning with Lean

Dongwei Jiang, Marcio Fonseca, Shay B. Cohen

Abstract

Large Language Models (LLMs) often struggle with rigorous logical deduction, frequently falling prey to hallucinations and spurious reasoning. This paper introduces LeanReasoner, a framework that integrates LLMs with the Lean theorem prover to enhance logical consistency. By formalizing natural language premises into Lean code and utilizing a specialized tactic generator, LeanReasoner achieves state-of-the-art performance on complex logical datasets like FOLIO and ProofWriter, demonstrating significant improvements in multi-step reasoning with minimal training data.

Introduction: The Challenge of Logical Inconsistency

While LLMs excel at natural language tasks, they are often "vibe-based" reasoners that lack the precision required for formal logic. In complex scenarios involving nested deductions or contradictions, LLMs may produce correct answers through flawed reasoning or fail entirely. Previous attempts to address this using symbolic solvers like Prolog or Z3 often lacked the flexibility to handle the nuances of natural language. LeanReasoner bridges this gap by leveraging the flexibility of LLMs for formalization and the absolute verification of the Lean theorem prover.

Methodology: The LeanReasoner Pipeline

LeanReasoner operates through a four-stage pipeline designed to translate, solve, and verify logical problems:

  1. The Formalizer: Utilizing GPT-4, the system translates natural language premises and queries into Lean axioms and theorems. The inclusion of descriptive textual comments within the formal code helps the model bridge the semantic gap between raw text and formal logic.
  2. The Tactic Generator: Rather than using a static solver, a Byte-T5-based model generates "tactics"—specific commands Lean uses to progress through a proof.
  3. Proof Search: Using the LeanDoJo framework, the system performs a tree search to explore potential proof paths, prioritizing steps based on cumulative log probabilities.
  4. Result Interpreter: The system attempts to prove both the target statement and its negation. The final answer is determined based on which proof (if any) succeeds: "True," "False," or "Unknown."
The LeanReasoner pipeline: from natural language to formal proof verification.

Datasets and Evaluation

The framework was evaluated on two primary benchmarks:

  • ProofWriter: A deductive reasoning dataset. The study focused on the "depth-5" subset, representing the most challenging deductive chains.
  • FOLIO: A complex dataset based on first-order logic with naturalistic wording and intricate relationships.

Notably, the tactic generator was fine-tuned on a remarkably small "gold standard" dataset—only 100 samples for ProofWriter and 27 for FOLIO—demonstrating the efficiency of the approach.

Key Insights: Math as a Foundation for Logic

A significant finding of the research is that pre-training on mathlib (Lean’s extensive mathematical library) substantially improves performance on general logic puzzles. This suggests that the reasoning patterns found in formal mathematics are highly transferable to broader logical deduction.

Furthermore, the authors explored the impact of proof styles on model performance. They found that concise proofs—which use compound tactics to reduce the number of steps—are superior for training compared to "intuitive" step-by-step proofs. Long, intuitive proofs often caused the model to lose focus or become trapped in redundant logical loops.

Comparison of proof styles: Concise proofs reduce the LLM's workload and prevent confusion from excessive lemmas.

Results and Performance

LeanReasoner established new state-of-the-art (SOTA) benchmarks:

  • FOLIO: Achieved 82.6% accuracy, surpassing previous leaders such as Logic-LM (74.5%) and Lean Z3 (77.5%).
  • ProofWriter: Reached 98.3% accuracy on the depth-5 subset, matching or exceeding models trained on much larger datasets.
  • Formalization: GPT-4 demonstrated high accuracy in formalizing ProofWriter (99%), though the linguistic complexity of FOLIO presented a greater challenge (75%).

Limitations and Future Directions

While LeanReasoner marks a significant advancement, it operates under a "closed-world" assumption, struggling with tasks that require external commonsense knowledge. Additionally, as a theorem prover, it is not optimized for numerical arithmetic or specific constraint satisfaction problems. Future research will focus on better integrating deep language understanding with formal verification to tackle increasingly complex, real-world reasoning tasks.

Summary updated

BibTeX
@inproceedings{jiang2024leanreasoner,
  author = {Dongwei Jiang and Marcio Fonseca and Shay B. Cohen},
  title = {{LeanReasoner: Boosting Complex Logical Reasoning with Lean}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.naacl-long.416},
}
Figure