From Scientific Texts to Verifiable Code: Automating the Process with Transformers

Changjie Wang, Mariano Scazzariello, Marco Chiesa

TL;DR

This paper introduces PROMETHEUS, a prototype that uses Large Language Models (LLMs) to translate natural language scientific proofs into machine-verifiable code. By splitting the task into high-level structural translation and iterative low-level proof generation, the authors demonstrate a path toward automatically ensuring that the algorithms we implement actually match the mathematical guarantees promised in research papers.

What Problem Does This Paper Address?

There is a massive "verification gap" in software engineering. While computer science literature is filled with algorithms that come with rigorous mathematical proofs, the actual code running in our systems is rarely formally verified.

Formal verification—the process of using mathematical logic to prove a program's correctness—is notoriously difficult. It requires mastery of specialized languages like Dafny, and it is incredibly tedious. Even "obvious" steps in a human proof require dozens of lines of explicit, low-level logical "plumbing" for a computer to accept them. Furthermore, formal proofs are "brittle"; a simple variable rename can break a previously working proof. Current AI tools like GitHub Copilot can suggest code, but they don't guarantee that the code is correct or follows a specific formal proof.

Methods

The authors propose a "separation of responsibilities" approach implemented in a prototype called PROMETHEUS. Instead of asking an LLM (specifically Claude 3.5 Sonnet) to write a verified program in one go, they break the process into two stages:

  1. High-Level Skeleton Generation: The LLM reads a textual proof from a scientific paper and translates it into a high-level "skeleton" of verification code. This outline defines the main logic but leaves out the tedious, low-level details.
  2. Iterative Low-Level Synthesis: The system then focuses on the missing pieces (sub-lemmas). These are often the "intuitively obvious" steps that humans skip but verifiers require. PROMETHEUS interacts iteratively with the LLM: it runs the Dafny verifier, catches errors, and feeds those errors back to the LLM along with high-level hints (e.g., "try using induction" or "check for missing pre-conditions") to refine the proof until it passes.

Datasets

The paper does not use a massive pre-existing dataset. Instead, it evaluates the PROMETHEUS prototype on three fundamental lemmas from graph theory:

  • The Handshake Lemma: Proving the sum of vertex degrees is twice the number of edges.
  • Degree Bounds Lemma: Proving that the average degree of a graph lies between its minimum and maximum degrees.
  • Even Cycle Bipartite Lemma: Proving that every cycle in a bipartite graph has an even length.

The input for these tests consisted of formal specifications of graph data structures and the natural language proofs found in standard textbooks.

Key Insights and Ideas

  • LLMs as Translators, Not Just Coders: The authors argue that LLMs are uniquely suited for this because translating a human proof to a code skeleton is essentially a "language translation" task, which is a core strength of Transformer architectures.
  • The "Obviousness" Paradox: One of the biggest hurdles in formal verification is that things humans find trivial (like "adding an edge increases the degree count") are hard for machines to track. The authors found that LLMs are actually quite good at filling in this "boring" low-level logic if they are guided by a high-level structure.
  • Verifiers as the "Ground Truth": By using a formal verifier (Dafny) in the loop, the system overcomes the "hallucination" problem of LLMs. If the LLM generates a wrong proof, the verifier rejects it, and the system tries again.

Key Results

The authors compared PROMETHEUS against a "baseline" of zero-shot prompting (asking the LLM to generate the whole proof at once).

  • Baseline Performance: The zero-shot approach failed completely, scoring 0/5 successful runs for all three lemmas. The code produced was typically too short and lacked the necessary low-level inductive steps.
  • PROMETHEUS Performance: By using the iterative, two-stage approach, the success rate jumped significantly:
  • Handshake Lemma: 4/5 successful runs.
  • Degree Bounds: 3/5 successful runs.
  • Bipartite Lemma: 3/5 successful runs.

These results suggest that the "skeleton-first" approach is a viable strategy for automating formal verification.

Limitations and Future Work

While promising, the authors acknowledge several hurdles:

  • The "Ground Truth" Problem: For this study, the authors manually verified the initial formal definitions (like how a "graph" is defined in code). If the initial definition is wrong, the entire proof is built on a shaky foundation. Automating the generation of these initial specifications remains a challenge.
  • Scaling Complexity: The current tests involve relatively simple mathematical lemmas. It remains to be seen how this approach scales to massive, multi-file software systems or highly complex distributed algorithms.
  • Reasoning vs. Translation: The system currently translates existing human knowledge. It does not yet "invent" new proofs for unsolved problems, which would require deeper integration with reinforcement learning (similar to DeepMind's AlphaProof).

Summary updated

BibTeX
@inproceedings{wang2025from,
  author = {Changjie Wang and Mariano Scazzariello and Marco Chiesa},
  title = {{From Scientific Texts to Verifiable Code: Automating the Process with Transformers}},
  booktitle = {Llm4code@icse},
  year = {2025},
  doi = {10.1109/llm4code66737.2025.00032},
}
Figure