This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 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 3 } write x ; read x { p 3 } where p 3 ≡ [ OUT ˆ x ˆ head ( IN )ˆ tail ( IN ) = h 1 , 2 ,..., 100 i ] and it is easy to see: ( p 3 ∧ x 6 = 100) ⇒ p 3 . (Do we need x 6 = 100 on the leftside of the above implication?) 57 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 precondition, the postcondition of the first read , the loop invariant, and the postcondition 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 3 } s := s + x ; read x { p 3 } where p 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 3 ]....
View
Full
Document
This note was uploaded on 04/10/2008 for the course CSE 755 taught by Professor Neelamsoundarajan during the Winter '05 term at Ohio State.
 Winter '05
 NeelamSoundarajan

Click to edit the document details