Recommended Free Tools
iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Run two candidate functions with the same inputs and compare what callers can observe. A mismatch gives you a concrete counterexample; matching results on a finite set of tests only show that the functions agree on those tests. Candidate discovery, behavioral testing, and formal proof are separate steps—and should not be treated as interchangeable.
What does it mean for two functions to be duplicates?
Two functions can have very different source code yet produce the same observable behavior within a defined context. To compare them, first decide what counts as observable: returned values alone may not be enough if callers also rely on exceptions, mutation, I/O, ordering, or other effects. The input domain and assumptions matter too; a claim about valid strings, for example, does not automatically cover malformed inputs.
Behavioral comparison is useful when source-based signals do not make the relationship obvious. Textual and structural techniques can help surface likely candidates, but coverage varies; substantially different syntax can conceal similar behavior. Neither source similarity nor a candidate cluster establishes equivalence.
How to find and test candidate pairs
1. Narrow the search to plausible candidates
Comparing every function with every other function in a large repository is usually impractical. Candidate-generation methods can prioritize pairs using structural or semantic signals. One JavaScript and TypeScript project, Ditto, documents extracting functions, generating fingerprints, and clustering likely matches before probing them. That is the project’s described architecture, not a universal standard or proof that clustered functions are duplicates: Ditto’s repository.
2. Run both functions on identical inputs
For a pair that can be executed safely, supply the same input to each and compare the observations you defined as relevant. If they disagree, the shared input is a counterexample to the hypothesis that they behave equivalently under those conditions. Record the input and both outcomes so the result can be reproduced.
Ditto’s documentation gives an example involving two truncation helpers: they reportedly agree at some boundary values but diverge at a nearby limit. This is the project’s own demonstration, not an independently reproduced test; it illustrates why testing a boundary and its neighbors can matter. The project documentation
3. Include boundaries and less typical inputs
A few ordinary inputs can miss differences hidden in branches, limits, or edge cases. Build a deliberate set of probes around the function’s input domain:
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →- Empty, minimal, and ordinary inputs.
- Values at a boundary and immediately below or above it.
- Negative values when they are valid inputs.
- Malformed or unusual values if the function is expected to handle them.
- Cases that exercise different branches and limits.
Randomized or generated inputs can broaden coverage beyond hand-picked examples. Use a reproducible seed or save each generated case, and retain any input that reveals a mismatch as a regression test. These are practical testing recommendations; no single probe checklist guarantees coverage.
4. Treat execution safety as part of the method
Running unknown code can trigger side effects or unsafe behavior. Ditto says it executes only pure functions in a sandbox and labels divergence for impure functions as predicted rather than executed. That is a stated design choice for this project, not a complete safety guarantee for other runtimes or execution environments. Before running a candidate pair, decide whether the functions can perform I/O, mutate shared state, or otherwise affect the environment, and isolate execution accordingly. Ditto’s repository
What a match or mismatch establishes
A mismatch on a shared input disproves equivalence for that input, according to the observations being compared. A match establishes agreement only for the tested inputs and conditions. If callers can observe exceptions or state changes, comparing only return values may miss a meaningful difference.
Rank #4
Finite testing cannot prove that two functions agree on every input in an unbounded domain. It can find counterexamples and increase confidence, but the strength of a conclusion depends on the test cases, the input assumptions, and the observations included.
When to use formal equivalence checking
Formal equivalence checking can support a stronger claim within an explicit model and its assumptions. Berkeley Roshan Churchill’s June 2019 Stanford dissertation describes a workflow that executes functions on supplied cases to infer alignment and invariants, uses separate test cases to challenge candidate models, and then checks proof obligations with an SMT solver. In that approach, executions contribute evidence and guide the analysis; they are not themselves the proof. Assumptions may be needed to avoid undefined behavior, and proof obligations can time out. Churchill’s dissertation, Blackbox Equivalence Checking of Program Optimizations
Best Value
In its evaluation, the dissertation reports successful verification of 55 of 56 vectorization benchmarks, with one timeout. That is a result for the dissertation’s particular method and benchmark suite, not a general accuracy rate for clone detectors or behavioral testing. The same work reports verifying an optimized libc strlen implementation against a simple reference implementation in a case study. The dissertation’s evaluation
| Approach | Question answered | Strength | Limit |
|---|---|---|---|
| Differential execution on selected inputs | Did these implementations differ on the cases run? | Can produce a concrete, reproducible counterexample. | Matching samples do not establish equivalence on untested inputs. |
| Formal equivalence checking informed by executions | Can the specified relationship be established under a model and its assumptions? | Can support a stronger equivalence claim within the modeled scope. | Requires suitable models, assumptions, and tractable proof obligations; timeouts are possible. |
How to use the method in code review
Use behavioral comparison to investigate plausible duplicate candidates, not as a stand-alone declaration that a pair is interchangeable. A practical review can separate the work into three decisions:
- Candidate: Identify functions worth comparing with repository knowledge or analysis signals.
- Behavior: Execute safe candidates on shared, meaningful inputs and examine all relevant observations. Preserve any disagreement as a reproducible test.
- Claim: Report whether the pair disagreed, matched on a stated test set, or was proved equivalent within a stated model. Do not label these outcomes with the same confidence.
When assessing a tool or method for this workflow, check which languages and function forms it supports, how it generates candidates and inputs, how it handles side effects, what execution boundaries it provides, and whether its output is a sampled match or a proof. These are evaluation questions, not evidence that any one tool performs better across projects.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteDitto reports that its own analysis covered 5,897 functions across five repositories, producing 163 duplicate clusters and 18 conflicts it says were proven by execution. These are self-reported project figures; independent validation of the counts was not established. They should not be read as an estimate of duplication prevalence or tool accuracy. Ditto’s repository
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

