This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: {Q: 0 < n} i ,p:= 1, y; {P: 1in p=( j 1j<i: j)} 3. (36 points) Find the weakest precondition and simplify for the following: a. wp(i,j:= i+2, j3i, i = j) b. wp(i:= i+2; j:=j3i, i = j) c. wp( i,m:= 0, b[0], 0in ( 2200 j 0j<i: m=b[j]) d. wp( t :=ni; if =b[i] m m:= b[i] b[i]m skip fi; i:=i+1, t >ni) 4. (24 points) Consider the algorithm. { 0<n} i,p:= 0, 1; {0in p=q i } do i<n p:=p q; i:= i+1 od { p=q n } a) Prove that the invariant holds at the entry of the loop. b) Prove that if the program terminates, that it does so in a state that satisfies the post condition. 5. Let sum(w) denote the sum of all of the values in a ternary string w. Define the function sum inductively. (6 pts) Prove that sum(w 1 w 2 )= sum(w 1 ) + sum(w 2 ). (14 pts) Name_______________________________...
View Full
Document
 Spring '08
 Myers

Click to edit the document details