Every programmer knows the small anxiety of a refactor: you rewrite a function to be cleaner or faster, and you believe it does the same thing â but does it, on every input? That question â do two programs always produce identical outputs? â is program equivalence.
The obvious check is to test: run both on a bunch of inputs and compare. If they ever disagree, they're not equivalent. But if they always agree on your tests... you've proven nothing. There are infinitely many possible inputs, and a difference might hide at exactly the one you didn't try â the value 42, or every input above a million.
And here's the deep result: there is no general procedure that can decide, for arbitrary programs, whether they're equivalent. The problem is undecidable â a direct relative of the halting problem. Not slow: impossible.
Comments
Loading comments...