NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

What can Large Language Models Capture about Code Functional Equivalence?

Nickil Maveli, Antonio Vergari, Shay B. Cohen

Introduction

While Large Language Models (LLMs) have demonstrated remarkable proficiency in code generation, their ability to reason about "functional equivalence"—the property where two syntactically distinct code snippets perform the identical task—remains a significant challenge. This paper introduces SeqCoBench, a comprehensive benchmark designed to evaluate whether LLMs can distinguish between "semantic clones" (different code, same logic) and "semantic lookalikes" (similar code, different logic). Identifying functional equivalence is a cornerstone of software engineering tasks such as refactoring, optimization, and automated bug detection.

Methodology and the SeqCoBench Framework

The researchers developed a systematic framework to probe the "semantic gap" in LLMs using two primary categories of code transformations:

  1. Semantic-Preserving (SP): These changes alter the syntax while maintaining identical logic. Examples include variable renaming, swapping for loops for while loops, or inserting "dead code" that does not affect execution.
  2. Semantic-Altering (SA): These are subtle, adversarial changes that appear similar to the original code but break the underlying logic, such as flipping comparison operators or changing boolean constants.
Figure 1: Examples of zero-shot prompts and model failures on subtle semantic-altering transformations.

The SeqCoBench dataset was constructed using functions from the MBPP (Mostly Basic Python Problems) dataset, resulting in over 14,000 code pairs. The evaluation spanned several open-source models, including Llama2, CodeLlama, and StarCoder2, across zero-shot, few-shot, and fine-tuned settings.

Experimental Results

The study reveals a "surface-level trap" where LLMs are frequently misled by high textual similarity. For instance, models often fail to detect logic errors introduced by changing an is operator to is not, as illustrated in the zero-shot prompt examples.

Figure 6: Comparison of Average Precision (AP) across match-based metrics and LLM-based evaluators.

As shown in the results, code-specific pre-training is a critical factor. CodeLlama-13B emerged as the top performer with an Average Precision (AP) of 70.85, significantly outperforming the general-purpose Llama2-13B (43.32). Notably, simple match-based metrics like ChrF (55.25) often outperformed several LLM configurations, suggesting that many models rely on pattern matching rather than deep logical reasoning. Furthermore, while Parameter-Efficient Fine-Tuning (PEFT) improved invariance to SP changes, it struggled to enhance the detection of SA changes.

Discussion and Conclusion

The findings highlight a substantial gap between current LLM capabilities and true functional understanding. Existing LLM-based metrics show a weak correlation ($r \approx 0.31$) with actual execution-based correctness. Currently limited to Python and static analysis, future work should explore hybrid approaches that integrate neural models with formal logic or symbolic reasoning to better capture the execution flow of code.

Summary updated

BibTeX
@inproceedings{maveli2025what,
  author = {Nickil Maveli and Antonio Vergari and Shay B. Cohen},
  title = {{What can Large Language Models Capture about Code Functional Equivalence?}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.findings-naacl.382},
}
Figure