Abstract
Mathematical autoformalization—the translation of natural language mathematics into machine-verifiable code—is hindered by a lack of high-quality parallel datasets. This paper introduces TopoAlign, a framework that utilizes the structural similarities between software engineering and formal mathematics to generate synthetic training data. By topologically decomposing Python repositories into docstrings, function bodies, and dependency trees, TopoAlign creates a "structural analogue" for formal math. Experimental results demonstrate that training on this aligned code data significantly improves the performance of Large Language Models (LLMs) on formal math benchmarks, with type-checking rates increasing by up to 68%.
Introduction
While Large Language Models (LLMs) have shown remarkable proficiency in informal mathematical reasoning, they frequently struggle with formalization—the process of writing code that can be verified by proof assistants like Lean 4 or Isabelle. The primary bottleneck is data scarcity; while general-purpose code is abundant, high-quality datasets pairing informal math problems with formal proofs are rare. TopoAlign addresses this by treating programming code as a structural proxy for formal math, allowing models to learn the compositional patterns of logical verification from open-source software.
The TopoAlign Framework
The core hypothesis of TopoAlign is that a software function is structurally analogous to a mathematical theorem. Both consist of a high-level description (docstring vs. informal statement), a core logic (function body vs. formal statement), and a set of external requirements (dependencies vs. library lemmata).
Methodology
The framework operates through three primary stages:
- Topological Decomposition: Using a custom parser, the authors extract function-level dependency trees from Python repositories. This process breaks code into its constituent parts: docstrings, main functions, and dependency functions.
- LLM Augmentation: Standard code docstrings often focus on usage rather than logic. To make them more "math-like," an LLM (Qwen3-14B) is used to generate concise summaries of the function's logical intent.
- Code Autoformalization (CAF): A training objective is established where the model must generate a formal function body given its informal description and its dependencies.
Experimental Setup and Datasets
The authors trained models using a combination of code from the Stack v2 dataset (filtered for structural complexity) and the Herald Statements corpus (a synthetic math dataset). Evaluation was conducted on three rigorous benchmarks:
- MiniF2F: High-school competition math.
- ProofNet: Undergraduate-level textbook theorems.
- Putnam: Problems from the William Lowell Putnam Mathematical Competition.
Key Results
Testing on DeepSeek-Math and HERALD (7B parameter models) revealed significant performance gains:
- Semantic Accuracy: On the MiniF2F-test benchmark, TopoAlign improved Bidirectional Equivalence (BEq@10) by 17.77%.
- Syntactic Correctness: The "Typecheck" rate—the ability of the model to produce code that actually compiles—saw dramatic improvements. On the Putnam benchmark, the type-check rate for DeepSeek-Math rose from a baseline of 0% to 42.14%.
- Compositional Learning: The results suggest that models can learn the "compositional pattern" of breaking down high-level goals into verifiable sub-steps by observing code structure, even if the domain (e.g., database management) differs from pure mathematics.
Discussion and Limitations
A notable challenge identified was the "type mismatch" between dynamically typed languages like Python and strictly typed proof assistants like Lean 4. For instance, models occasionally confused integers ($\mathbb{Z}$) with natural numbers ($\mathbb{N}$). Future work will explore the use of strictly typed programming languages (such as Java or C++) within the TopoAlign framework to mitigate these errors and expand the scope from formalizing statements to formalizing entire proofs.
Conclusion
TopoAlign demonstrates that aligned code is a viable and powerful substitute for scarce mathematical data. By leveraging the topological structure of software, the framework provides a scalable path toward improving the formal reasoning capabilities of LLMs, bridging the gap between human language and machine-verifiable logic.
Summary updated