# if - Notes on Proving Correctness Lecture 4 Maggie Myers...

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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Notes on Proving Correctness Lecture 4 January 24, 2008 Maggie Myers and Robert van de Geijn January 28, 2008 1 The IF Command We discuss how to establish the correctness of the IF command. 1.1 Syntax In the programming languages used in our class, the IF command has the following syntax: if B 1 → S 1 B 2 → S 2 . . . . . . . . . . . . B n → S n fi The B i s are called the guards . The execution of this command is as follows: • If at the time of execution any of the B i s is not well defined, abort is possible. • If at the time of execution all of the B i s are not well defined, abort is inevitable. • If at the time of execution all of the B i s are false , abort is inevitable. • If at the time of execution only one guard is true then the command associated with that guard is executed. • If at the time of execution more than one guard is true , then one of the commands associated with a true guard is executed. In this case the choice is nondeterministic (random). 1 1.2 Weakest precondition of the IF command Consider the IF command if B 1 → S 1 B 2 → S 2 . . . . . . . . . . . . B n → S n fi which we will also write as IF : if B 1 → S 1 ··· B n → S n fi Now let us consider under what conditions this command completes in a state where predicate R is true . We will assume that all of the guards are well defined. wp (IF , R ) = ( ∃ i | 1 ≤ i ≤ n : B i ) | {z } at least one of the guards is true ∧ ( ∀ i | 1 ≤ i ≤ n : B i → wp ( S i , R )) | {z } if B i is true , then before the IF statement the variables must be in a state such that S i establishes R Example 1 Determine wp ( “ if x ≥ → y := x x ≤ → y :=- x fi , y = | x | ) . wp ( “ if x ≥ → y := x x ≤ → y :=- x fi , y = | x | ) ↔ < definition of IF > ( x ≥ ∨ x ≤ 0) ∧ ( x ≥ → wp (“ y := x , y = | x | )) ∧ ( x ≤ → wp (“ y :=- x , y = | x | )) ↔ < excluded middle, definition of := > T ∧ ( x ≥ → ( x = | x | )) ∧ ( x ≤ → (- x = | x | )) ↔ < ∧-simplification > ( x ≥ → ( x = | x | )) ∧ ( x ≤ → (- x = | x | )) ↔ < definition of absolute value > T ∧ T ↔ < ∧-simplification > T End of example....
View Full Document

{[ snackBarMessage ]}

### Page1 / 8

if - Notes on Proving Correctness Lecture 4 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