From Informal to Formal - Incorporating and Evaluating LLMs on Natural Language Requirements to Verifiable Formal Proofs

Jialun Cao, Yaojie Lu, Meiziniu Li, Haoyang Ma, Haokun Li, Mengda He, Cheng Wen, Le Sun, Hongyu Zhang, Shengchao Qin, Shing-Chi Cheung, Cong Tian

Introduction

Formal verification represents the "gold standard" for ensuring the correctness of safety-critical systems. By mathematically proving that software or hardware meets its specifications, developers can eliminate entire classes of bugs. However, the process is notoriously labor-intensive and requires deep expertise in specialized formal specification languages like Coq, Lean4, or TLA+. While Large Language Models (LLMs) have shown promise in reasoning, existing benchmarks often treat formal verification as an end-to-end black box, making it difficult to identify whether failures stem from logical errors or syntactic misunderstandings.

Methodology: Decomposing the Verification Pipeline

To address these challenges, researchers have proposed a modular framework that breaks the "Informal-to-Formal" pipeline into six distinct sub-tasks. This decomposition allows for a more granular evaluation of LLM capabilities across different stages of the verification process:

  1. Requirement Analysis (ReqAna): Decomposing high-level goals into detailed natural language steps.
  2. Full Proof Generation (ProofGen): Directly translating requirements into complete formal proofs.
  3. Segment Proof Generation (SegGen): Writing specific proof components based on detailed descriptions.
  4. Proof Completion (ProofComp): Generating the "suffix" of a partial proof.
  5. Proof Infilling (ProofInfill): Filling in masked middle sections of a proof.
  6. Code-to-Proof (Cd2Prf): Generating formal specifications, such as loop invariants, directly from source code (specifically for ACSL).
The data construction pipeline and the six modular tasks for formal verification.

The researchers utilized GPT-4o to "distill" knowledge from existing open-source formal proofs, generating corresponding natural language descriptions to create a high-quality instruction-tuning dataset. This approach bridges the gap between informal human requirements and formal mathematical logic.

Datasets: FM-ALPACA and FM-BENCH

The study introduces two primary resources to the research community:

  • FM-ALPACA: A fine-tuning dataset comprising over 14,000 instruction-response pairs.
  • FM-BENCH: A benchmarking dataset with 4,000 pairs for rigorous evaluation.

Unlike previous benchmarks that often focus on a single language, these datasets cover five mainstream formal specification languages: Coq, Lean4, Dafny, ACSL, and TLA+. This multi-lingual coverage is essential for evaluating the generalizability of LLMs in formal reasoning.

Results and Key Insights

The evaluation revealed several critical findings regarding the current state of LLMs in formal reasoning:

  • Impact of Fine-tuning: Specialized fine-tuning yielded massive performance gains. Smaller models (7B-8B parameters) fine-tuned on FM-ALPACA frequently outperformed general-purpose models ten times their size. In some tasks, accuracy improved by nearly 300%.
  • DeepSeek-R1 Performance: Among base models, DeepSeek-R1 demonstrated superior reasoning capabilities, achieving the highest average accuracy (24.36%) without task-specific fine-tuning, likely due to its reasoning-oriented pre-training.
  • Syntax as a Bottleneck: Approximately 12.43% of failures were attributed to simple syntax errors. Formal languages have much stricter grammar than standard programming languages like Python, and models often struggle with these nuances.
  • Capability Migration: A significant discovery was that training on formal logic data improved the models' general performance on unrelated benchmarks like GSM-8K (mathematics) and HumanEval (coding). This suggests that the rigors of formal verification enhance a model's fundamental reasoning engine.
Performance comparison of various LLMs across different formal verification tasks.

Conclusion and Future Directions

While LLMs show great potential as "assistants" for generating proof segments, they still struggle with autonomous, end-to-end proof generation. Future work should focus on "closed-loop" systems where LLMs can interact with formal verifiers to iteratively correct syntax and logical errors in real-time. Additionally, addressing the reliance on synthetic descriptions will be crucial for real-world applicability where human requirements are often ambiguous.

The models and datasets are publicly available at the FM-Universe Hugging Face repository.

Summary updated

BibTeX
@inproceedings{cao2025from,
  author = {Jialun Cao and Yaojie Lu and Meiziniu Li and Haoyang Ma and Haokun Li and Mengda He and Cheng Wen and Le Sun and Hongyu Zhang and Shengchao Qin and Shing-Chi Cheung and Cong Tian},
  title = {{From Informal to Formal - Incorporating and Evaluating LLMs on Natural Language Requirements to Verifiable Formal Proofs}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure