next up previous
Next: About this document ...

Correctness (with loops) in one page1

Say we are given a program that looks like $\{S_1; loop; S_2\}$. Furthermore, for the loop we are given its condition $B$, an invariant $p$, and a bound condition $d$.

To prove the program is partially correct with respect to some intial condition $I$ and some final condition $F$, we need to show:

(1)
$I \Rightarrow wp(S_1, p)$
(2)
$p \wedge B \Rightarrow wp(\hbox{{\em loop-body}}, p)$
(3)
$p \wedge \neg B \Rightarrow wp(S_2, F)$

To prove the program is totally correct with respect to those condtions, we need to further show:

(4)
$I \Rightarrow wp(S_1, d \ge 0)$
(5)
$(d \ge 0) \wedge B \Rightarrow wp(\hbox{{\em loop-body}}, d \ge 0)$
(6)
$(d=d_{old}) \wedge B \Rightarrow wp(\hbox{{\em loop-body}}, d < d_{old})$





Benjamin A. Wiedermann 2003-05-05