{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# do - Notes on Proving Correctness Lecture 5 Maggie Myers...

This preview shows pages 1–3. Sign up to view the full content.

Notes on Proving Correctness Lecture 5 January 30, 2008 Maggie Myers and Robert van de Geijn 2 The DO Command In the programming languages used in our class, the DO command has the following syntax: do B 1 S 1 [] B 2 S 2 . . . . . . . . . . . . [] B n S n od The B i s are called the (loop) guards . Together, this command will be indicated by DO. The symbol BB will be used to denote B 1 B 2 ∨ · · · ∨ B n , in other words, ( i | 1 i n : B i ). Thus, BB is the condition under which the loop does not yet terminate. The command executes as follows: The loop is executed until none of the guards evaluate to true , in other words, until ¬ BB . Each time through the loop, a guard that evaluates to true is randomly selected, and the statement associated with it is executed. 2.1 Weakest precondition The weakest precondition of the DO command is very messy to define. We will not bother, since the DO-Theorem, discussed next, is what is used in practice. 2.2 Motivation To motivate theorems regarding a DO command (which we will not prove), let us consider the simpler loop: do BB S od 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
We would like to establish { Q } do BB S od { R } To do so, we introduce a predicate P , the invariant, which will be true before and after each iteration of the loop. If you think about this a bit, this means P must hold at all the places indicated below: { Q } { P } do { P } BB S { P } od { P } { R } Now, If Q P , then P hold immediately before the do . If P is true immediately before the do it is true immediately after the do the first time the loop is executed, since no assignment to any variables occurs in between. If BB holds, S is executed. Then S is executed in a state where P BB holds. We want to show that it completes in a state where P again holds. This means that P BB wp ( S, P ) must hold. If this can be shown, then P will again hold just before od . And thus, it will hold again right after do the second time the loop is executed. By Mathematical Induction, it will hold
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 7

do - Notes on Proving Correctness Lecture 5 Maggie Myers...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online