The Hoare Triple law for assignment says
Example: Prove {P1 ∧ P2} x, y := x*x, y div 2 {P1}, where
Solution: By the Hoare Triple law for assignment, it suffices to prove P1 ∧ P2 ⇒ P1(x,y := x*x, y div 2). The usual approach is to assume the antecedant and to show the consequent:
Assume P1 ∧ P2
P1(x,y := x*x, y div 2)
= < defn of P1 and textual substitution >
C = (x*x)y div 2
= < algebra: x*x = x2 >
C = (x2)y div 2
= < algebra: (ab)c = abc >
C = x2(y div 2)
= < assumption P2 implies y div 2 = y/2 >
C = x2(y/2)
= < algebra: a(b/a) = b (for a != 0) >
C = xy
= < assumption P1 >
true
Now suppose that we use the wp approach instead of the Hoare Triple approach. The relationship between wp and Hoare Triples is
Furthermore, the wp assignment rule is [wp.(x:=E).Q ≡ Q(x:=E)].
Hence, to prove {P1 ∧ P2} x,y := x*x, y div 2 {P1} we show the equivalent
The usual approach is to assume the antecedant and to show the consequent:
Assume P1 ∧ P2.
wp.(x,y := x*x, y div 2).P1
= < wp assignment rule >
P1(x,y := x*x, y div 2)
= < defn of P1 and textual substitution >
C = (x*x)y div 2
As this is the second line of the proof above, we simply continue
as in that proof.