{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Notes #4

# Notes #4 - Individual steps(p3 x = 100 p4 easy{p1 read x{p2...

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

Individual steps: ( p 3 x = 100) p 4 : easy. { p 1 } read x { p 2 } : easy from the read axiom. p 2 p 3 : easy from math logic. { p 3 x 6 = 100 } write x ; read x { p 3 } : { p 0 3 } write x ; read x { p 3 } where p 0 3 [ OUT ˆ x ˆ head ( IN tail ( IN ) = h 1 , 2 , . . . , 100 i ] and it is easy to see: ( p 3 x 6 = 100) p 0 3 . (Do we need x 6 = 100 on the leftside of the above implication?) 57

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

View Full Document
To derive: { IN = h 1 , 2 , 3 , . . . , 100 i } s := 0; read x ; while x 6 = 100 do s := s + x ; read x ; end { s = Σ 99 k =0 k } Proof Outline: { IN = h 1 , 2 , 3 , . . . , 100 i } s := 0; read x ; { s = 0 x = 1 IN = h 2 , 3 , . . . , 100 i } { # IN = 100 - x ∧ ∀ k # IN.IN [ k ] = x + k 1 x 100 s = Σ x - 1 k =0 k } while x 6 = 100 do s := s + x ; read x ; end { s = Σ 99 k =0 k } A more intuitive loop invariant: IN = h x + 1 , . . . , 100 i ∧ 1 x 100 . . . We will use p 1 , p 2 , p 3 , p 4 to denote the pre-condition, the post-condition of the first read , the loop invariant, and the post-condition of the pro- gram, respectively. 58
The individual steps: { p 1 } s := 0; read x { p 2 } : easy exercise. p 2 p 3 : easy. ( p 3 x = 100) p 4 : easy. { p 3 x 6 = 100 } s := s + x ; read x { p 3 } : From read ax., assign ax., seq. comp., { p 0 3 } s := s + x ; read x { p 3 } where p 0 3 [# tail ( IN ) = 100 - head ( IN ) ∧∀ k 100 - head ( IN ) .tail ( IN )[ k ] = head ( IN )+ k 1 head ( IN ) 100 s + x = Σ head ( IN ) - 1 k =0 k ] We can easily see [( p 3 x 6 = 100) p 0 3 ]. The clause ( head ( IN ) = x + 1) which can be derived from k 100 - x.IN [ k ] = x + 1 of p 3 , plays an important role in establishing this implication. 59

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

View Full Document
Incompleteness : Our rule for while : p q, { q b } S { q } , ( q ∧ ¬ b ) r { p } while b do S { r } A simpler rule: p q, { q } S { q } , ( q ∧ ¬ b ) r { p } while b do S { r } We can derive: { x = 0 } while x 6 = 10 do x := x + 1 { x = 10 } Take p ( x = 0) , q true , r ( x = 10) 1. p q (easy) 2. { true } x :=
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