AuXSpec:学习通过可执行后置条件自动形式化程序规范
研究论文 · 2026/11/18
AuXSpec 是一个 Lean 框架,通过将声明式后条件与可执行对应物配对(优先通过类型类解析获得,否则单独定义并证明等价性),利用测试用例执行来评估声明式规范,并将执行结果的一致性作为强化学习奖励。基于此,作者从 LeetCode 合成了 3,037 个问题,并通过在 Codeforces 上的专家迭代将训练数据扩展到 19.5K 样本。实验表明,使用基于执行的奖励训练 Qwen3.5-9B 和 Qwen3.8-27B,在 AuXSpec-Test 上 SpecGen pass@4 分别从 0.7% 提升到 82.7% 和从 14.3% 提升到 84.3%,且 27B 模型优于所有前沿模型。在域外 Verina 基准上,两个模型分别从 7.0% 提升到 90.5% 和从 21.9% 提升到 90.5%,并在 pass@1 和 pass@4 上超越了先前开源规范模型的最佳水平 VeriSpecGen-30B-A3B。作者发布了训练好的 9B 和 27B 模型权重、3,037 个带测试用例的问题(包括经专家评审和正确性证明的 300 问题 AuXSpec-Test 基准)。
该工作解决了自动形式化中缺乏可扩展反馈的关键瓶颈,通过可执行后条件将规范正确性转化为可自动评估的奖励信号,显著提升了规范生成模型的性能,并发布了模型与基准数据,对形式化验证和代码生成领域具有重要推动意义。
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