{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS336F104

# CS336F104 - Goal CS336 Lecture4 Furtherunderstandwp...

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

9/6/10 1 CS336 Lecture 4 Weakest Preconditions Goal Further understand wp How to prove an IF statement correct Why should we care? These are the techniques we will use to verify program then use these methods for developing programs via goal oriented programming. Hoare’s Triple {Q} S {R} S is the command sequence, the predicate Q is known as S’s pre condition , and R is known as its post condition . A program holds (is verified or proven correct) if we begin in any state satisfying Q,after we execute the commands, we end up in a state satisfying R in a finite amount of time. Our Approach wp(S,R) denotes the weakest (i.e. minimum) precondition necessary for the postcondition to be satisfied. We started with basic commands and look at the weakest precondition for these. Then we looked at how to deal with sequences of these commands. Skip The “do-nothin g” command (a “place- holder”): skip Definition . wp (“ skip ”, R) = R

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

View Full Document
9/6/10 2 Abort The “fatal-error ” command: abort Definition . wp (“ abort ”, R) = F Assignment The Assignment command: ‘ := Definition . That is, a textual substitution is made for x in R by replacing x with e. Sequential composition of commands ; Definition . wp (“S1 ; S2”, R) = wp (S1, wp (S2,R)) The Alternative Command if B then S0 else S1 , is if B S0 ¬ B S1 fi wp(“IF”,R)= (B wp(S0,R)) ( ¬ B wp(S1,R)) Example If x<0 then x:=0 {T} if x<0 x:=0 x≥0 Skip fi { x≥0 } Our approach: show T wp(“IF”, x≥0 ) Example {T} if x<0 x:=0 x≥0 Skip fi { x≥0 } wp(“IF”,R)= ( x<0 wp(“ x:=0” , x≥0 )) ( x≥0 wp(“Skip”, x≥0 ))
9/6/10 3 Example wp (“IF”,R) = <def> ( x<0 wp(“ x:=0” , x≥0 )) ( x≥0 wp(“Skip”, x≥0 )) <wp := and skip > ( x<0 0 0 ) ( x≥0 x≥0 ) <arith; identity> ( x<0 T ) T < ; -simp > T Now since T T, Q wp(“If”,R) The Alternative Command The general form (known as “ IF ”) : if B0 S0 B1 S1 B2 S2 . . . B n Sn fi General definition for WP of IF (—assumes all guards are defined). wp(“ IF” ,R) = ( i|1 i n: B i ) ( i| 1 i n: B i wp(S i ,R)) If we maintain our approach First, we would find the WP of IF and then show Q wp(IF,R) … Or Q ( i|1 i n: B i ) ( i| 1 i n: B i wp(S i ,R)) If we maintain our approach {Q} if B 0 S 0 B 1 S 1 fi {R}

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.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern