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
- Predicate Transformers ( and ) automate the “transport” of logic through code.
- Forward Analysis (): Tracks what we know as we execute.
- Backward Analysis (): Tracks what we need to know to reach a goal.
- for Assume: Conjunction ().
- for Assume: Implication ().
- Verification: To prove
{P} S {Q}, we check if (or if ).
Self-Check
- What is the intuitive difference between and ?
Answer
moves forward: given that holds before , it returns the strongest formula guaranteed to hold after . moves backward: given the desired postcondition , it returns the weakest precondition that guarantees holds after . They are duals: one starts from what you know, the other from what you want.
- Compute and simplify.
Answer
By the rule, . Substituting gives , and the existential disappears. So the strongest postcondition is .
- Compute .
Answer
, so , equivalently over integers (). This is exactly what the Hoare assignment axiom would give.
- Why is equal to rather than ?
Answer
The
assume Pfilter only keeps executions where holds; on paths where is false, the relation is empty so has nothing to prove. So the precondition need only guarantee in the case that is actually true, which is exactly the implication .
- State the verification condition for using or .
Answer
Use (everything reachable from through implies ), or equivalently (every initial state in satisfies the weakest precondition for ). Either implication, if valid, certifies the Hoare triple.
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