FANS: Formal Answer Selection for LLM Natural Language Math Reasoning Using Lean4

Jiarui Yao, Ruida Wang, Tong ZhangEMNLP 2025

TL;DR

This paper introduces FANS, a novel framework that leverages the formal verification system Lean4 to improve the answer selection capabilities of Large Language Models (LLMs) in mathematical reasoning. By translating natural language math problems and LLM-generated answers into formal Lean4 statements, FANS uses Lean4 to verify proofs, providing a more trustworthy and robust method for selecting correct answers.

What Problem Does This Paper Address?

Large Language Models (LLMs) have shown impressive capabilities in various tasks, but their mathematical reasoning abilities are often debated. The inherent ambiguity of natural language (NL) makes LLM-generated mathematical answers lack coherence and trustworthy support, making it difficult to verify their correctness. Existing methods for answer selection, like majority voting or reward models, have limitations in terms of simplicity, generalization, and their inability to leverage the solid logical foundation of mathematics. This paper addresses the challenge of enhancing LLM math reasoning by introducing a method that bridges the gap between ambiguous natural language and the rigorous, verifiable proofs of formal languages.

Methods

FANS employs a three-stage pipeline:

  1. NL to FL Translation: The core of this stage is a novel "Long Chain-of-Thought" (Long-CoT) translator, named LeanTranslator. This translator is trained to convert natural language math questions and their corresponding answers into formal Lean4 theorem statements. The training leverages existing NL-FL aligned data and a transfer learning approach.
  2. Lean4 Proof Writing and Verification: The translated Lean4 statements are then fed to an advanced Lean4 prover to generate proofs. These proofs are subsequently verified by the Lean4 compiler. This step ensures that the formal statements are indeed provable and that the underlying logic is sound.
  3. Answer Selection and Output: The verification results from Lean4 are used to enhance existing answer selection methods. By having a computer-verifiable proof, the selected answers gain a solid foundation and increased trustworthiness. FANS can also fall back to other methods if formal proof fails or if translations are not perfectly faithful.

Datasets

  • Training Data: The authors utilized existing NL-FL aligned theorem statement data from "Lean-Workbook" and generated additional data using Qwen-2.5-72B from the "DeepSeek-Prover-v1 dataset's Lean4 theorem statements." This resulted in a dataset of 162,181 NL-FL aligned theorem statements.
  • Evaluation Datasets:
    • MATH500: A dataset of 500 high-school-level math problems across 7 major fields (precalculus, algebra, number theory, etc.).
  • AMC23: A dataset of 40 high-school-level math competition questions, described as harder and more versatile than MATH500.
  • Other datasets mentioned include Minverva Math and Olympiad Bench.

Key Insights and Ideas

  • Formal Verification as an Answer Selection Tool: The paper demonstrates that formal verification systems like Lean4 can be effectively used not just for proving theorems but also as a robust mechanism for selecting correct answers from LLM outputs.
  • Bridging the NL-FL Gap: The development of a specialized Long-CoT translator (LeanTranslator) is crucial for accurately converting ambiguous natural language math problems into precise formal language statements, which is a significant technical contribution.
  • Trustworthiness through Verifiability: By relying on Lean4's rigorous proof verification, FANS offers a level of trustworthiness and interpretability that is difficult to achieve with purely NL-based reasoning or reward models.
  • Domain-Specific Strengths: FANS shows particular effectiveness in sub-fields like number theory and algebra, where Lean4 has stronger library support, highlighting the potential for domain-specific formalization.
  • Generalizability: The framework's modular design allows it to work with different LLM backbones and provers, suggesting a generalizable approach to enhancing LLM reasoning.

Key Results

  • FANS consistently improves answer selection accuracy across various LLM base models.
  • On MATH500, FANS achieved an accuracy gain of up to 1.91% when combined with reward models (ORM).
  • On AMC23, FANS improved accuracy by up to 8.33%.
  • In specific sub-fields like number theory and algebra, FANS was able to select all correct solutions in some cases.
  • Qualitative studies showed that FANS enhances the trustworthiness of LLM-generated answers by providing a formal, verifiable backbone.
  • The Long-CoT translator was found to be significantly more effective than translators without Long-CoT.

Limitations and Future Work

  • False Positive Rate: A major limitation is the potential for a high false positive rate in NL-FL translation, which can lead to incorrect answer selection even if proofs are successfully generated. Errors in formalization or constraint handling can also cause misclassification.
  • Limited Domain Coverage: Lean4's current ecosystem is biased towards fields like algebra and number theory, limiting its applicability to other areas such as geometry and combinatorics.
  • Prover Capabilities: While provers are improving, they still struggle with a significant percentage of proof problems, indicating room for enhancement in their reasoning abilities.
  • Future Work:
    • Improving NL-FL Translation: Focus on making translations more accurate and robust to reduce false positives and better preserve problem constraints.
  • Expanding Prover Capabilities: Enhance Lean4's library support for broader mathematical domains and improve the proving capabilities of provers through fine-tuning and better proof-search strategies.
  • Scaling and Robustness: Explore ways to scale the formal proof ecosystem and improve robustness to handle more complex and diverse mathematical problems.

Summary updated

BibTeX
@inproceedings{yao2025fans,
  author = {Jiarui Yao and Ruida Wang and Tong Zhang},
  title = {{FANS: Formal Answer Selection for LLM Natural Language Math Reasoning Using Lean4}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
}
Figure