I understand that the general problem of program equivalence is undecidable, but I'm wondering what approaches exist to tackle the problem? I am familiar with Hoare-style verification, but are there any other frameworks for proving program equivalence?
2 Answers
One general approach to the problem is to prove program equivalence by showing the programs have the same semantics. Hoare-style verification, as you say, is one option categorized as axiomatic semantics. Have a look at this article which describes most of the semantic approaches out there, including denotational semantics and operational semantics.
- 937
- 6
- 23
Proving this via a detour to a semantics is unnecessary and cumbersome.
Hoare logic is for showing that correctness conditions (AKA Hoare triples) of the form $\{\phi\}P\{\psi\}$ hold. To show equivalence of $P$ and $Q$, you'd have to show that $$\{\phi\}P\{\psi\}$\quad\text{iff}\quad\{\phi\}Q\{\psi\}$$ for all pairs $(\phi,\psi)$ of pre- and postconditions. You could attempt that using a symbolic postcondition and then compare the two weakest preconditions. Dijkstra showed how to do that in the 70ies.
A more modern way of doing the same thing would be to use a refinement calculus to show that the two programs under consideration mutually refine each other. Consult any of the good books on the topic, e.g., Carroll Morgan's Programming from Specifications.
- 925
- 5
- 16