arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2605.29822cs.SEcs.AI
收藏

从规约推断代码正确性

Inferring Code Correctness from Specification

University of Luxembourg(卢森堡大学)

Tambon Florian, Papadakis Mike

AI总结:

提出TRAILS方法,通过基于规约的类别划分生成测试输入并执行,利用LLM评估输入输出对是否符合规约,从而推断代码正确性,在LiveCodeBench和CoCoClaNeL数据集上相比基线方法提升了马修斯相关系数并增强了稳定性。

摘要:

大型语言模型(LLM)已成为现代软件开发不可或缺的一部分,实现了大规模自动代码生成。然而,验证LLM生成代码的正确性仍然是一个关键且基本未解决的挑战。现有方法要么依赖多个代码候选之间的动态共识——这使得它们成本高昂且难以扩展,要么依赖静态推理,容易受到动态错误和顺序偏差的影响。在本文中,我们提出TRAILS(通过输入和规约的目标推理一致性),一种将LLM推理与具体(输入,输出)对相结合的方法。TRAILS首先基于规约通过类别划分生成多样化的测试输入,然后针对候选代码执行这些输入,并提示LLM评估产生的输入输出对是否符合规约——而无需对代码本身进行推理。分数跨输入聚合,以确定程序是否可能正确。我们在两个数据集LiveCodeBench和CoCoClaNeL上,使用三个LLM(Qwen3Coder-30B、Devstral-Small-24B和Olmo3.1-Instruct)评估TRAILS,并与HoarePrompt和零样本思维链基线进行比较。TRAILS的马修斯相关系数相比零样本思维链提高了高达39%,并且始终优于HoarePrompt。除了准确性,TRAILS在多次运行中表现出更高的稳定性,降低了对LLM非确定性的敏感性,并且相比竞争方法为更多独特的代码样本分配了正确的标签。

英文摘要:

Large language models (LLMs) have become integral to modern software development, enabling automated code generation at scale. However, validating the correctness of LLM-generated code remains a critical and largely unsolved challenge. Existing approaches either rely on dynamic consensus across multiple code candidates - making them costly and difficult to scale - or on static reasoning that is susceptible to dynamic bugs and order bias. In this paper, we propose TRAILS~ (Targeted Reasoning Agreement via Inputs and Specifications), an approach that grounds LLM reasoning with concrete (input, output) pairs. TRAILS~ first generates diverse test inputs via category partitioning based on the specification, then executes them against the candidate code and prompts LLMs to assess whether the resulting input-output pairs conform to the specification - without ever reasoning over the code itself. Scores are aggregated across inputs, to determines whether the program is likely correct. We evaluate TRAILS~ on two datasets, LiveCodeBench and CoCoClaNeL, across three LLMs (Qwen3Coder-30B, Devstral-Small-24B, and Olmo3.1-Instruct), comparing against HoarePrompt and a Zero-Shot Chain-of-Thought baseline. TRAILS~ improves Matthew Correlation Coefficient by up to 39\% relative to Zero-Shot COT and consistently outperforms HoarePrompt. Beyond accuracy, TRAILS~ demonstrates greater stability across seeded runs, reducing sensitivity to LLM non-determinism, and assigns correct labels to a larger set of unique code samples than competing approaches.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑