Weakest con
Dr. Yawar
Some Slides are taken from VU Formal Methods for SE
Explanation
Example
• {x+1=43}y:=x+1 {y=43}
And
{y=43}z:=y {z=43}
Using the sequencing rule, we have
{x+1=43}y:=x+1;z:=y {z=43}
Explanation
Rule of Sequential Composition
wp(S1;S2,Q) wp(S1, wp(S2,Q))
Rule of Sequential Composition
wp(S1;S2,Q) wp(S1, wp(S2,Q))
wp((x:= x+1; y := y+1), x = y)
Rule of Sequential Composition
wp(S1;S2,Q) wp(S1, wp(S2,Q))
wp((x:= x+1; y := y+1), x = y)
wp(x := x+1, wp(y := y+1, x = y))
Rule of Sequential Composition
wp(S1;S2,Q) wp(S1, wp(S2,Q))
wp((x:= x+1; y := y+1), x = y)
wp(x := x+1, wp(y := y+1, x = y))
wp(x := x+1, x = y+1)
Rule of Sequential Composition
wp(S1;S2,Q) wp(S1, wp(S2,Q))
wp((x:= x+1; y := y+1), x = y)
wp(x := x+1, wp(y := y+1, x = y))
wp(x := x+1, x = y+1)
x+1 = y+1
Rule of Sequential Composition
wp(S1;S2,Q) wp(S1, wp(S2,Q))
wp((x:= x+1; y := y+1), x = y)
wp(x := x+1, wp(y := y+1, x = y))
wp(x := x+1, x = y+1)
x+1 = y+1
x=y
Rule of Sequential Composition
wp((x:= 2*x+1; y := y-1), y = 3*x)
Rule of Sequential Composition
wp((x:= 2*x+1; y := y-1), y = 3*x)
wp(x := 2*x+1, wp(y := y-1, y = 3*x))
Rule of Sequential Composition
wp((x:= 2*x+1; y := y-1), y = 3*x)
wp(x := 2*x+1, wp(y := y-1, y = 3*x))
wp(x := 2*x+1, y-1 = 3*x))
Rule of Sequential Composition
wp((x:= 2*x+1; y := y-1), y = 3*x)
wp(x := 2*x+1, wp(y := y-1, y = 3*x))
wp(x := 2*x+1, y-1 = 3*x))
y-1 = 3*(2*x+1)
Rule of Sequential Composition
wp((x:= 2*x+1; y := y-1), y = 3*x)
wp(x := 2*x+1, wp(y := y-1, y = 3*x))
wp(x := 2*x+1, y-1 = 3*x))
y-1 = 3*(2*x+1)
y = 6*x + 4
Summary
Hoare-style proofs have been extensively used over the past few
decades to prove subtle properties of complicated programs
This approach works best with programmer-provided annotations
The use of automated theorem provers and programmer
annotations
has allowed application of Hoare-style reasoning to medium sized
programs quite successfully.
Key-Hoare (from Chalmers University): A tool suite for
teaching/learning about Hoare logic Scalability of Hoare-style
reasoning is sometimes an issue Yet, this is one of the most elegant
techniques available for proving properties of programs.