runtimeverification / k

K Framework Tools 7.0
BSD 3-Clause "New" or "Revised" License
452 stars 150 forks source link

Equivalence prover #4217

Open ehildenb opened 1 year ago

ehildenb commented 1 year ago

We want to bring back a KEQ like tool which enables proving that two programs in the same (or different) languages are equivalent.

We'll start with one that assumes the same programming language between the two executions.

Implementation ideas

An example we talked about:

$s = 3;
if (B) { $s = $s + 3 ; } else { $s = $s + 2 ; $s = $s + 1 };

ASTART => A1
A1 => A2
A2 => A3
A3 => BRANCH
BRANCH => END1
BRANCH => END2
$s = 3;
$s = $s + 3;

BSTART => END

Equivalence: ==P === $s ends the same.

Loose "should be same" predicate: (ASTART, BSTART), (END1, END), (END2, END) Tight "is the same" predicate: ASTART ==P BSTART, END1 \/ END2 ==P END

Some reference literature from @daejunpark

The general approach then was:

This worked pretty well, and I think even scaled to some larger algorithms. The linked paper is an early version of the work, which did not make it to publication (other than in Daejun's thesis). But eventually they made it work between LLVM and x86, not just LLVM -> optimized LLVM. Unfortunately, I think the larger work never really made it to publication. Here is Daejun's thesis: https://www.ideals.illinois.edu/items/111906

The biggest challenge this approach faced was the "make a product semantics of the two". This is difficult for all sorts of technical reasons, mostly related to joining the syntax (overlapping productions) and semantics (conflicting rules) of the two semantics in a way that didn't change the behavior of each other. The facilities the K compiler provides for this are very limited. Our approach will be different, as described. We'll instead just build the execution graph of each one separately, and then have the semantics-specific predicate saying "these two points should be in the simulation/bisimulation relation" run over all the nodes in the two graphs. Finally, after establishing that relationship, we'll check that the tighter simulation predicate (user-supplied, or we provide a default semantics-specific one) holds over those pairs of nodes.

palinatolmach commented 1 year ago

Returning to Backlog until @PetarMax is available.