Practice 30

According to the assignment rule, what should be the precondition in the following program segment?

displaymath137

We substitute expression (in this case, x-2) into the postcondition, to give

displaymath138

or

displaymath139

Practice 31

Verify the correctness of the following program segment with the precondition and postcondition shown:

displaymath147

We need to inject a condition between the two code assignment statements between the grand pre- and post-conditions:

displaymath148

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

displaymath149

as the intervening condition. We then repeat one more times, using the first assignment:

displaymath150

which is true, so the program is provably correct.

Practice 32

Verify the correctness of the following program segment with the precondition and postcondition shown:

displaymath159

We need to demonstrate two implications: that tex2html_wrap_inline161 and tex2html_wrap_inline163 are true.

The latter is easy, since the antecedent is false! We're done with that one.

For the former, we need to use the assignment rule: we replace y=3 using y=x-1, to arrive at x-1=3, from which we deduce that x=4. From x=4 we deduce that x<5, and hence tex2html_wrap_inline177 .



LONG ANDREW E
Thu Jan 24 00:10:57 EST 2002