Disproving Program Equivalence with LLMs

Miltiadis Allamanis, Pengcheng YinarXiv 2025 · DOI

Abstract

Determining semantic equivalence between code snippets is a fundamental challenge in software engineering and AI-assisted coding. While traditional unit tests often fail to capture subtle logical differences, this paper introduces PROBEGEN, a white-box method leveraging Large Language Models (LLMs) to generate counterexample "probes." By iteratively analyzing source code and execution feedback, PROBEGEN identifies semantic discrepancies in 18% of code samples that previously passed human-written tests. Our results demonstrate that LLMs can act as effective informal symbolic reasoners, significantly improving the evaluation and self-consistency of generated code.

Introduction

In AI-assisted coding, verifying if two code snippets are semantically identical is critical for evaluating model correctness and ensuring safe refactoring. Traditionally, developers rely on unit tests; however, these are often "weak," missing edge cases or implementation-specific bugs. While proving perfect equivalence is undecidable, disproving it requires only a single divergent input. PROBEGEN addresses this by using LLMs to find these elusive counterexamples.

The PROBEGEN Framework

PROBEGEN treats counterexample generation as a multi-turn search process, utilizing the LLM as a "white-box" debugger. Unlike "black-box" fuzzers that guess random inputs, PROBEGEN provides the LLM with the source code of both implementations to find inputs that might trigger divergent behaviors.

The PROBEGEN pipeline: from task description and implementations to filtered counterexamples.

The framework consists of several key stages:

  1. White-Box Probing: The LLM inspects the source code of both implementations to hypothesize inputs that might trigger different execution paths.
  2. Iterative Feedback: If a generated "probe" (an input without a hard-coded expected output) fails to differentiate the programs, the LLM receives the execution feedback to refine its next attempt.
  3. Spurious Filtering: To avoid flagging irrelevant differences (e.g., output sorting when order is not specified), a second LLM pass filters counterexamples based on the natural language task description.

Search Strategies and Efficiency

The authors explored various tree-search strategies to optimize the discovery of counterexamples. A "Decreasing" strategy—starting with a broad search and narrowing down in later turns—was found to be the most cost-effective.

Comparison of search strategies and their success probability relative to inference cost.

As shown in the results, the "Decreasing" strategy achieved a high success rate while requiring significantly less compute than exhaustive "Full" searches. Specifically, it reached a 90% success rate with 4x less compute cost than a full search.

Key Insights and Results

The study, conducted on the LBPP (Python) benchmark, revealed several critical findings:

  • The Weakness of Human Tests: 18.7% of programs that passed all benchmark unit tests were actually semantically different from the ground truth. This suggests current metrics significantly overestimate model performance.
  • Performance Boost: By using PROBEGEN to cluster semantically identical solutions (semantic self-consistency), the researchers improved the pass@1 accuracy of the underlying model from 40.6% to 44.6%.
  • LLMs as Symbolic Reasoners: The success of white-box probing suggests that modern LLMs can perform informal symbolic execution, reasoning about code branches to find divergent inputs.

Limitations and Future Work

While powerful, PROBEGEN's LLM-based approach is more computationally expensive than traditional testing. It also assumes determinism and struggles with side effects like file I/O. Future work may involve using these probes to provide automated feedback to students or developers, explaining exactly why two implementations differ through concrete, divergent examples.

Summary updated

BibTeX
@misc{allamanis2025disproving,
  author = {Miltiadis Allamanis and Pengcheng Yin},
  title = {{Disproving Program Equivalence with LLMs}},
  year = {2025},
  eprint = {2502.18473},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.18473},
}
Figure