Functionally Equivalent or Not? Graph-Grounded Differential Surrogate Execution for Code Equivalence
Organizations: AWS AI Labs Santa Clara, California, USA · AWS AI Labs New York, USA
Abstract
Determining whether two programs are functionally equivalent is central to code modernization, patch validation, refactoring, and code-generation evaluation. Yet the usual signals are incomplete: tests cover only finite inputs, textual similarity confuses implementation with behavior, and unconstrained LLM judgments are difficult to audit. Direct execution is often impossible when a program depends on an obsolete, licensed, unavailable, or unsafe environment. We introduce FEAgent, a selective equivalence assessor agent that combines typed program-graph evidence with differential surrogate execution. FEAgent first aligns public interfaces and behaviorally relevant graph anchors, then issues bounded queries over call-flow, control-flow, data-flow, type, import, and effect relations. Next, a branch-aware generator agent proposes discriminating inputs, and two blinded LLM surrogates independently predict source and target observables. Every claim and predicted divergence is recorded in an evidence ledger. A deterministic reconciler then returns EQUIVALENT, INEQUIVALENT, or UNCLEAR rather than forcing a verdict when paths are uncovered or evidence conflicts. We evaluate FEAgent on function-level equivalence and repository-level bug patches, where the existing oracle is a benchmark label or a passing test suite. Every disagreement with that oracle is adjudicated by direct execution, revealing errors in benchmark labels and behavioral divergences missed by unit-test-only scoring. On EquiBench, execution confirms FEAgent's disagreements with published labels on 216 of 1,200 evaluated pairs (18.0%); on SWE-bench Verified, 94 of 331 test-passing agent patches (28.4%) diverge from the reference patch. FEAgent thus serves as an audit layer between testing and formal verification, keeping its evidence reviewable and its uncertainty explicit without claiming a proof of equivalence.
Figures & tables
| Audit Set | Evaluated | Disagreement Rate | Verified Genuine | ECD |
|---|---|---|---|---|
| OJ_A | 400 | 116 (29%) | 111 (95.7%) | 27.8% |
| OJ_VA | 400 | 109 (27.25%) | 105 (96.3%) | 26.3% |
| OJ_V | 400 | 5 (1.25%) | 0 (0%) | 0% |
| EquiBench Total | 1,200 | 230 (19.2%) | 216 (93.9%) | 18.0% |
| SWE-bench Verified | 331 | 109 (32.9%) | 94 (86.2%) | 28.4% |
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
| Family | Required values | Core attributes |
|---|---|---|
| Nodes | repository, file, namespace, type, function, parameter, statement, variable, literal, external symbol | stable ID, language, qualified name, source span, parser confidence |
| Structural edges | contains, declares, imports, inherits, overrides | source, target, resolution status |
| Behavioral edges | calls, CFG successor, control-depends, defines, uses, reads, writes, returns, throws, mutates, emits effect | source, target, guard/label, static/dynamic confidence |
| Function attributes | signature, visibility, modifiers, return type, effect summary | normalized and original forms |
| Statement attributes | syntax kind, branch predicate, constants, operators | source text hash and span |
| External attributes | package/module, version constraint, contract source | resolved, unresolved, or assumed |
| Field | Representation | Default comparator |
|---|---|---|
| Return | typed, canonical value | exact after type-aware canonicalization; declared tolerance for floating point |
| Exception | type, message projection, phase | exact type; configurable message projection |
| External effects | ordered events over files, network, database, logs, processes, callbacks | order-sensitive unless specification declares commutativity |
| Input mutation | before/after reachable object projection | structural equality with alias identities retained |
| Persistent state | selected state projection | task-defined equality |
| Termination | normal, exception, timeout, divergence | exact class under resource policy |
| Dataset | Language | Pairs | Equiv. | Inequiv. | Labeling source |
|---|---|---|---|---|---|
| OJ_A | Python | 400 | 200 | 200 | EquiBench [ Wei et al., 2025 ] |
| OJ_V | Python | 400 | 200 | 200 | EquiBench [ Wei et al., 2025 ] |
| OJ_VA | Python | 400 | 200 | 200 | EquiBench [ Wei et al., 2025 ] |
Differential Testing
Differential testing compares programs or versions on the same inputs to find behavioral differences that may reveal bugs.
See all 17 papers