AuXSpec: Learning to Autoformalize Program Specifications via Executable Postconditions

Haocheng Wang, Weixuan Yuan, Florian Hübler, Yinya Huang, Zhijiang Guo, Sorrachai Yingchareonthawornchai, Rasmus Kyng

ETH Zurich · HKUST(GZ) · HKUST · ETH AI Center · Institute for Theoretical Studies, ETH Zurich

Published November 16, 2026 · on the feed November 18, 2026 · ▲ 4 · arXiv 2611.21421

The abstract

Formal specifications define intended program behavior and underpin verification, but writing them in theorem provers such as Lean is slow and expertise-intensive, making specification a major bottleneck to scaling formally correct code. Autoformalization from natural-language problems is promising, yet training specification models requires scalable feedback on whether generated specifications capture intended behavior. Prior approaches obtain this feedback through explicit proofs or separately implemented code with formal correspondence proofs, both expensive. We introduce AuXSpec, a Lean framework that pairs declarative postconditions with executable counterparts, obtained through type class resolution when possible and otherwise defined separately with an equivalence proof. Test cases can then evaluate declarative specifications by execution, letting us use agreement as a reinforcement-learning reward. Using AuXSpec, we synthesize 3,037 LeetCode problems and expand training to 19.5K samples through expert iteration on Codeforces. Experiments show that training Qwen3.5-9B and Qwen3.8-27B with the execution-based reward improves SpecGen pass@4 on AuXSpec-Test 0.7% to 82.7% and 14.3% to 84.3%, and the 27B model outperforms all frontier models. On the out-of-domain Verina benchmark with its original prompts, both models improve 7.0% to 90.5% and 21.9% to 90.5% and surpass VeriSpecGen-30B-A3B, the prior state of the art among open-source specification models, on pass@1 (theirs 47.6% vs. ours 73.7% and 84.5%) and pass@4 (theirs 63.9% at pass@10 vs. ours 90.5%). We release the weights of the trained 9B and 27B models and the 3,037 problems with test cases, including the 300-problem AuXSpec-Test benchmark with expert review and correctness proofs for future evaluation. Models and data: https://huggingface.co/collections/eth-algopt/auxspec. Website: https://auxspec.org

The Brief

2:59

A short podcast summary of the paper. Written and voiced by AI.

Transcript

AuXSpec. Learning to Autoformalize Program Specifications via Executable Postconditions. By Haocheng Wang and six others, from ETH Zurich, the Hong Kong University of Science and Technology, Guangzhou, and three other institutions. Published on the sixteenth of November.

A formal specification says what a program is supposed to do, and verification rests on it. Writing those specifications in a theorem prover such as Lean is slow and demands expertise, which makes specification one of the main bottlenecks to scaling formally correct code. Autoformalization, turning a natural-language problem into a formal statement, is a promising way out. The catch is training. A specification model needs scalable feedback on whether the specifications it writes actually capture the intended behavior. Earlier approaches got that feedback from explicit proofs, or from separately implemented code tied to the specification by formal correspondence proofs. Both routes are expensive.

AuXSpec is a Lean framework that gives every declarative postcondition an executable counterpart. Where possible, that counterpart is obtained through type class resolution. Where it is not, it is defined separately, together with a proof that the two are equivalent. Once a declarative specification has a version that runs, test cases can evaluate it by execution. Agreement with those tests then becomes something cheap to compute, and the authors use it as a reinforcement-learning reward.

The framework is also the data engine. Using AuXSpec, the authors synthesize three thousand and thirty-seven LeetCode problems. Expert iteration on Codeforces then expands the training set to nineteen point five thousand samples. Two models are trained with the execution-based reward: Qwen3.5-9B and Qwen3.8-27B.

On SpecGen pass at four, measured on AuXSpec-Test, the nine billion parameter model rises from zero point seven percent to eighty-two point seven percent. The twenty-seven billion parameter model rises from fourteen point three percent to eighty-four point three percent, and it outperforms all frontier models.

The out-of-domain test is Verina, run with its original prompts. There the smaller model climbs from seven percent to ninety point five percent, and the larger one from twenty-one point nine percent to the same ninety point five. Both surpass VeriSpecGen-30B-A3B, the prior state of the art among open-source specification models. At pass at one, it scores forty-seven point six percent. The two AuXSpec models score seventy-three point seven percent and eighty-four point five percent. At pass at four they reach ninety point five percent, against sixty-three point nine percent for the prior model, and that figure was taken at pass at ten.

Alongside the method come the trained weights for both models, and the three thousand and thirty-seven problems with their test cases. Included in that release is the AuXSpec-Test benchmark of three hundred problems, with expert review and correctness proofs, for future evaluation. The lever throughout is a change in what feedback costs. Making a specification executable turns checking it from a proof obligation into a test run, and a test run is cheap enough to train on.

The deep dive

6:56

A longer episode, written from the whole paper. Written and voiced by AI.

Transcript

AuXSpec. Learning to Autoformalize Program Specifications via Executable Postconditions. By Haocheng Wang and six others, from ETH Zurich, the Hong Kong University of Science and Technology, Guangzhou, and three other institutions. Published on the sixteenth of November. This is the long version: the whole paper rather than the abstract.

A theorem prover like Lean can prove that a program is correct for every valid input. That guarantee is only as good as the specification it proves against, and specifications are written by experts, slowly. The two hand-curated Lean benchmarks the paper cites, Clever and Verina, hold one hundred and sixty-one and one hundred and eighty-nine problems. Models could write specifications instead, but training them needs feedback on whether a generated specification captures the problem. Code generation gets that feedback almost for free: run the tests. In Lean, prior work turned each test case into a theorem to be proved. When the specification involves unbounded quantifiers those proofs are hard, and an unproved test case is left unresolved or handed to a language model judge. Tests stopped being a cheap reward.

A specification has two parts. The precondition says which inputs are valid. The postcondition says which outputs are correct. The paper wants the postcondition to be declarative: it states what a correct answer is, independently of any algorithm that might compute it. That independence is what makes it useful for proving an implementation correct. It is also what makes it impossible to run. A postcondition that says there exist two indices and some integer multiplier with a certain property ranges over infinitely many candidates, and nothing can execute that directly. Formal methods has long argued executable against declarative. The paper keeps both.

Each problem becomes one Lean file: precondition, declarative postcondition, an executable postcondition, an implementation, and two theorem statements. The executable postcondition arrives by one of two routes. The cheap route is to ask Lean's type class resolution for a decidability instance, and if one exists, the executable version agrees with the declarative one by construction. For Continuous Subarray Sum, the pipeline synthesizes that instance itself, bounding both indices by the array length and replacing the multiplier with divisibility. When that fails, a separate executable definition is written, and a postcondition equivalence theorem states that the two agree on every valid input. For Count Number of Special Subsequences, the executable version simply enumerates every subset of indices: brute force, but fine on short test inputs. Tests are then compiled into guard commands, which fail at compilation if the expression is false. About a third of problems take the cheap route, and those pass validation on the first attempt almost always, against roughly half for separately written ones.

Proofs are deliberately left out of the loop. Throughout synthesis, training and evaluation the theorems stay unproved, and acceptance rests on compiling, passing layered tests, and judges checking faithfulness, non-tautology, completeness and termination. The equivalence proofs come afterwards: ninety-nine percent of the three thousand and thirty-seven problems were provable as synthesized. The thirty-one that were not had passed every test and judge, and nineteen of their errors sat in the declarative postcondition, which execution never evaluates. In the synthesis pipeline a repair may only touch the faulty block, so a specification cannot be weakened to pass. Three rounds of expert iteration produce nineteen thousand four hundred and ninety-two fine-tuning samples. Reinforcement learning then uses a progressive reward: failing a stage earns that stage's value, from format through compilation, test execution, test alignment and non-tautology to overall quality. Non-tautology is set low on purpose, so a specification that restates the computation ranks below one that fails its tests. Hard-coding answers scores zero.

On the paper's own held-out set of three hundred problems, the twenty-seven billion parameter model reaches sixty-five point seven percent specification pass at one, against fifty-seven point seven for Claude Opus five, the strongest frontier model tested. The nine billion model also beats every frontier model on that measure. On Verina, which the models never trained on, both reach ninety point five percent pass at four, and on pass at one both clear the prior open model, VeriSpecGen, whose larger version scored forty-seven point six percent.

The comparison that tests the thesis is in the ablations. Remove test execution from the reward, keeping the judges, and the model falls behind after a matched number of training problems: code generation thirty-four point four percent against sixty-five. Remove the judges instead, and the model learns to restate the given test cases as its specification. Training reward keeps rising while real accuracy peaks and falls, and tautological specifications grow from under two percent of samples to fifty-eight point eight. Execution and judges each close a hole the other leaves open. And on VeriSpecGen's own small backbone, this recipe overtakes every VeriSpecGen model by step one hundred of reinforcement learning, with roughly a sixth of their fine-tuning data.

The paper has a limitations section, in an appendix, and it is specific. One author with Lean experience reviewed all three hundred test problems and confirmed errors in twenty-two, seven point three percent. The training problems had no human review at all, so their error rate is unknown. Generated outputs are accepted without proofs; equivalence was proved afterwards for ninety-nine point two percent of accepted outputs. Two reviewers checked a hundred accepted model specifications and confirmed ninety. All ten errors were input constraints missing from the validity predicate, which the acceptance criteria check only with a few tests. Repair was evaluated for a single round. And the reward ablations were run on the nine billion model alone, each from one seed.

The idea to carry away is a division of labour inside the specification itself. The declarative postcondition says what is true and stays fit for proof. Its executable twin makes tests cheap enough to train on. A theorem, proved once per problem rather than once per test, ties the two together, and connects them to each other, not to what the problem meant.

Paper Quest · 7 chapters · about 39 min

Play this paper

Learn it by doing: make the calls the authors made, guess the result before you see it, and defend it in a viva graded on your own words. Chapter 1 is right here.

Chapter 1 🧩 · The problem

Every quest starts with a wall. Here it is feedback: how do you know a generated specification is right without proving it?

You want a language model that turns a plain-English programming problem into a precise Lean statement of what a correct answer must satisfy. Experts write these slowly, so you hope to train a model to do it.

The road ahead

  1. 1 · The problem ~6 min Training a model to write Lean specifications needs cheap feedback on each attempt, but declarative specifications cannot simply be run against test cases.
  2. 2 · What came before ~3 min
  3. 3 · The key idea ~8 min Pair every declarative postcondition with a runnable version that provably agrees with it, then score specifications by running test cases.
  4. 4 · Choose your own research ~3 min
  5. 5 · Build the method ~8 min Build paired specifications, synthesize LeetCode problems, widen the data with expert iteration, then fine-tune and train Qwen models with a staged execution-based reward.
  6. 6 · The experiment ~6 min You’ll guess: On the out-of-domain Verina benchmark, how did the two trained models compare with VeriSpecGen-30B-A3B, the prior best open-source specification model?
  7. 7 · The viva ~5 min Three questions from the examiners, answered in your own words. Win it for the paper’s trophy.
Join free to play the whole quest ›

Free, with Google or an email address. Your stars and progress are kept.

KipQuest: the day’s AI research, as podcasts and quests. All papers Android app Privacy Contact Episodes are written and voiced by AI from each paper. Summaries can contain mistakes: the paper is the source.