Back to Program Verification Index | Previous: (y-12) Control-Flow Graphs | Next: (y-14) Bounded Model Checking

Mental Model for Predicate Transformers

  • Automated Reasoning: Hoare Logic is great for humans, but machines need something more mechanical. Predicate Transformers are functions that take a formula and a statement and “transform” it into a new formula.
  • Strongest Postcondition (): Moving forward. If is true before , what is the most specific thing we can say is true after ?
  • Weakest Precondition (): Moving backward. If we want to be true after , what is the most general thing that must be true before ?
  • The Engine of Solvers: Tools like Boogie use these transformers to turn a program’s path into a single logic formula that can be sent to Z3.

Strongest Postcondition ()

calculates the set of all states reachable from by executing .

1. Assignment: x := expr

  • Intuition: We “save” the old value of as . The new state is one where the old was true (using ) and the new is the result of the expression.

2. Havoc: havoc x

  • Intuition: We lose all specific information about , but everything else in remains true.

3. Assume: assume P

  • Intuition: We simply add the assumed fact to our knowledge base.

Weakest Precondition ()

calculates the “least restrictive” condition required to guarantee after .

1. Assignment: x := expr

  • Intuition: This is exactly the same as the Hoare Assignment Axiom! Just substitute the expression into the postcondition.

2. Assume: assume P

  • Intuition: If the assumption holds, then must hold. If is false, the execution is ignored (vacuously true).

The Problem of Quantifiers

When we compute forward, we often end up with many existential quantifiers ().

  • Example: becomes .
  • Quantifier Elimination: We can simplify this to .
  • Solvers use techniques like Destructive Equality Resolution to “solve” these quantifiers and keep the formulas small.

Summary

  1. Predicate Transformers ( and ) automate the “transport” of logic through code.
  2. Forward Analysis (): Tracks what we know as we execute.
  3. Backward Analysis (): Tracks what we need to know to reach a goal.
  4. for Assume: Conjunction ().
  5. for Assume: Implication ().
  6. Verification: To prove {P} S {Q}, we check if (or if ).

Self-Check

  1. What is the intuitive difference between and ?
  1. Compute and simplify.
  1. Compute .
  1. Why is equal to rather than ?
  1. State the verification condition for using or .

Back to Program Verification Index | Previous: (y-12) Control-Flow Graphs | Next: (y-14) Bounded Model Checking | (y) Return to Notes | (y) Return to Home