According to the assignment rule, what should be the precondition in the following program segment?
We substitute expression (in this case, x-2) into the postcondition, to
give
or
Verify the correctness of the following program segment with the precondition
and postcondition shown:
We need to inject a condition between the two code assignment statements
between the grand pre- and post-conditions:
and then check carry out the proof. We work backwards from the postcondition:
if we insert the second expression (in this case, x+y) into the
postcondition, we get
as the intervening condition. We then repeat one more times, using the first
assignment:
which is true, so the program is provably correct.
Practice 31