arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2602.06098cs.SEcs.AIcs.LG
收藏

测试驱动代码生成的理论分析

A Theoretical Analysis of Test-Driven Code Generation

Nicolas Menet, Michael Hersche, Andreas Krause, Abbas Rahimi

AI总结:

本文提出概率框架分析测试驱动开发中代码生成与选择策略,证明模糊功能相似性估计器在信号噪声比上优于功能等价性估计器,并通过实验验证了回提示在任务描述模糊性下的有效性。

摘要:

代码助手在测试驱动软件开发中被广泛应用,但其环境交互策略的理论机制尚不明确。本文为两种主流范式提供概率框架:生成代码后的执行环境选择和基于环境反馈的代码生成。首先,将几种已建立的选择启发法形式化为环境感知的代码正确性估计器。理论证明基于模糊功能相似性的估计器具有归纳偏置,并在信噪比上严格优于基于功能等价性的估计器。其次,将回提示框架为上下文近似版的汤普森采样。推导出奖励函数具有不可观测组件的新型遗憾界,理论解释了回提示效果受限于非正式任务描述模糊性(不可约遗憾)。使用五种最先进的开放权重模型,在BigCodeBenchHard、LeetCodeDataset和QiskitHumanEvalSim上验证这些发现。我们的形式化也提出了如何有效改进任务描述的方法,从而产生新的基准QiskitHumanEvalSimX。

英文摘要:

Code assistants are increasingly utilized in test-driven software development, yet the theoretical mechanisms behind their environment-interaction strategies remain underexplored. We provide a probabilistic framework for two dominant paradigms: code selection after generation using the execution environment, and code generation conditioned on environment feedback. First, we formalize several well-established selection heuristics as environment-aware estimators of code correctness. We theoretically prove that estimators based on fuzzy functional similarity add an inductive bias and strictly dominate estimators based on functional equivalence in terms of signal-to-noise ratio. Second, we frame backprompting as an in-context approximation of Thompson sampling. We derive a novel regret bound for reward functions with unobservable components, theoretically explaining why the effectiveness of backprompting is limited by the ambiguity of the informal task description (an irreducible regret). Using seven state-of-the-art open weight models, we corroborate these findings across BigCodeBenchHard, LeetCodeDataset, QiskitHumanEvalSim, and SWE-bench Verified. Our formalization also suggests how to improve task descriptions effectively, leading to an improved benchmark for LLM-assisted quantum programming, QiskitHumanEvalSimX.

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

↑