arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2503.19599cs.SEcs.AI
收藏

HoarePrompt:关于程序正确性的自然语言结构化推理

HoarePrompt: Structural Reasoning About Program Correctness in Natural Language

Peking University(北京大学);Nankai University(南开大学);University College London(伦敦大学学院)

Dimitrios Stamatios Bouras, Yihan Dai, Tairan Wang, Yingfei Xiong, Sergey Mechtaev

AI总结:

提出HoarePrompt方法,将程序验证思想用于自然语言,通过LLM生成程序状态描述并评估正确性,显著提升分类性能。

摘要:

尽管软件需求通常以自然语言表达,但针对这些需求验证程序正确性是一个困难且尚未充分探索的问题。大型语言模型(LLM)是解决这一挑战的有前景的候选方案,然而我们的经验表明,它们在此任务上效果不佳,甚至常常无法检测出明显的错误。为弥补这一差距,我们提出了HoarePrompt,一种将程序验证的基本思想应用于自然语言工件的新方法。受最强后置条件演算的启发,HoarePrompt采用系统化、逐步的过程,由LLM生成代码各点可达程序状态的自然语言描述。为处理循环,我们提出了少样本驱动的k-归纳法,这是模型检查中广泛使用的k-归纳方法的一种改编。一旦程序状态被描述,HoarePrompt利用LLM评估带有这些状态描述注释的程序是否符合自然语言需求。为评估针对自然语言需求的程序正确性分类器的质量,我们构建了CoCoClaNeL,一个包含编程竞赛问题解决方案的具有挑战性的数据集。我们的实验表明,与直接使用Zero-shot-CoT提示进行正确性分类相比,HoarePrompt将MCC提高了61%。此外,HoarePrompt比通过基于LLM的测试生成来评估正确性的分类器在MCC上高出106%。归纳推理机制为MCC贡献了26%的提升,突显了其在处理循环方面的有效性。

英文摘要:

While software requirements are often expressed in natural language, verifying the correctness of a program against such requirements is a hard and underexplored problem. Large language models (LLMs) are promising candidates for addressing this challenge, however our experience shows that they are ineffective in this task, often failing to detect even straightforward bugs. To address this gap, we introduce HoarePrompt, a novel approach that adapts fundamental ideas from program verification to natural language artifacts. Inspired from the strongest postcondition calculus, HoarePrompt employs a systematic, step-by-step process in which an LLM generates natural language descriptions of reachable program states at various code points. To manage loops, we propose few-shot-driven k-induction, an adaptation of the k-induction method widely used in model checking. Once program states are described, HoarePrompt leverages the LLM to assess whether the program, annotated with these state descriptions, conforms to the natural language requirements. For evaluating the quality of classifiers of program correctness with respect to natural language requirements, we constructed CoCoClaNeL, a challenging dataset of solutions to programming competition problems. Our experiments show that HoarePrompt improves the MCC by 61% compared to directly using Zero-shot-CoT prompts for correctness classification. Furthermore, HoarePrompt outperforms a classifier that assesses correctness via LLM-based test generation by an MCC increase of 106%. The inductive reasoning mechanism contributes a 26% boost to MCC, underscoring its effectiveness in managing loops.

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

↑