HoarePrompt: Structural Reasoning About Program Correctness in Natural Language

Fuente: arXiv
Guardado en:
Detalles Bibliográficos
Autores principales: Bouras, Dimitrios Stamatios, Dai, Yihan, Wang, Tairan, Xiong, Yingfei, Mechtaev, Sergey
Formato: Preprint
Publicado: 2025
Materias:
Acceso en línea:
Etiquetas: Agregar Etiqueta
Sin Etiquetas, Sea el primero en etiquetar este registro!
_version_ 1866914001396432896
author Bouras, Dimitrios Stamatios
Dai, Yihan
Wang, Tairan
Xiong, Yingfei
Mechtaev, Sergey
author_facet Bouras, Dimitrios Stamatios
Dai, Yihan
Wang, Tairan
Xiong, Yingfei
Mechtaev, Sergey
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2503_19599
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle HoarePrompt: Structural Reasoning About Program Correctness in Natural Language
Bouras, Dimitrios Stamatios
Dai, Yihan
Wang, Tairan
Xiong, Yingfei
Mechtaev, Sergey
Software Engineering
Artificial Intelligence
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.
title HoarePrompt: Structural Reasoning About Program Correctness in Natural Language
topic Software Engineering
Artificial Intelligence
url https://arxiv.org/abs/2503.19599