Specifications & State · Page 4 of 6
Invariants & Counterexamples (DieHard)
A model checker explores reachable states breadth-first, so when an Invariant
fails, it gives you a shortest counterexample trace from an initial state to
the violation.
In the movie Die Hard with a Vengeance (and Leslie Lamport's famous TLA⁺ lecture), you have a 3-gallon jug and a 5-gallon jug and must measure out exactly 4 gallons.
How do we ask a model checker to solve the puzzle? Claim the opposite as an invariant:
not_solved=Invariant(lambda s: s.big != 4). When the checker disproves
not_solved, its counterexample trace is the shortest solution!
Try it: Click Check to watch the checker discover the
6-step solution to the DieHard puzzle. Then change
s.big != 4 to
s.big != 6 (impossible!) and verify that the model now passes.