用分阶段推理提升代码生成的正确性,让AI写出可验证的程序。
BRIDGE: Building Representations In Domain Guided Program Synthesis
- 分三步生成代码、规范和定理,用中间推理连接各环节。
- 在Lean中正确率最高提升近1.5倍,采样效率提高约2倍。
- 适合需要形式化验证的AI编程研究者和高可靠性系统开发者。
大型语言模型能生成看似合理的代码,但在形式化验证工具如Lean中仍显脆弱。核心挑战在于,验证性合成需要在多个耦合领域保持一致:可执行代码、形式化规范、定理陈述和证明尝试。现有方法常将这些产物分开处理。我们提出BRIDGE,一种结构化提示框架,用于多产物程序合成。BRIDGE将生成过程分解为代码、规范和定理/证明三个相互关联的领域,并使用领域特定的中间推理进行衔接。在Lean中,BRIDGE通常采用代码优先的工作流,以生成的实现作为下游规范、定理陈述和证明尝试生成的语义锚点。在178个算法问题和五种LLM上,BRIDGE将可执行代码正确率提升至直接提示的近1.5倍,且在相近生成长度下采样效率提升约2倍。此外,规范导向提示使Python通过率最高提升17.5个百分点。除了推理时提示,基于BRIDGE式推理轨迹的监督微调,其在Lean上的成功通过率比仅代码微调高出近1.5倍,表明这些中间表示提供了可学习的归纳偏置。BRIDGE为可扩展的形式化合成提供实用框架,同时揭示了可执行正确性与完整形式证明之间的差距。
原文摘要 · Abstract (English)
Large language models can generate plausible code, but remain brittle for formal verification in proof assistants such as Lean. A central scalability challenge is that verified synthesis requires consistent artifacts across several coupled domains: executable code, formal specifications, theorem statements, and proof attempts. Existing approaches often treat these artifacts separately. We present BRIDGE, a structured prompting framework for multi-artifact program synthesis. BRIDGE decomposes generation into three interconnected domains: Code, Specification, and Theorem/Proof, and uses domain-specific intermediate reasoning to connect them. In Lean, BRIDGE often follows a code-first workflow, using the generated implementation as a semantic anchor for downstream specification, theorem statement, and proof-attempt generation. Across 178 algorithmic problems and five LLMs, BRIDGE improves Lean executable correctness by up to nearly 1.5x over direct prompting and can be roughly 2x more sample efficient at comparable generation lengths. We further find that specification-oriented prompting improves Python pass rates by up to 17.5 percentage points. Beyond inference-time prompting, supervised fine-tuning on BRIDGE-style reasoning traces yields nearly 1.5x higher Lean pass success than code-only fine-tuning, suggesting that these intermediate representations provide a learnable inductive bias. BRIDGE provides a practical framework for scaling verified synthesis while highlighting the remaining gap between executable correctness and full formal proof generation.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。