{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

assinment 4

# assinment 4 - Select even(x y =>(x,y:=(0,0 or odd(x y...

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

CS536 Science of Programming Assignment #4 Spring 2010 Due date March 15, 2010 1. Prove that the definition of “;” satisfies the 4 characteristics of defending WP(S, R) (8 points) 2. Prove that the definition of the SELECT statement satisfies the 4 characteristics of defending WP(S, R) (12 points) 3. Prove that the definition of LOOPSELECT satisfies the rule of exclusive miracle. (Proof is by induction on H(R)) (5 points) 4. Prove partial correctness of the prime number program. (12 points) {a 0 and b 0} (x,y,z) := (a,b,1); {z*x y = a b ^ x 0 ^ y 0 } While y 0 loop { z* x y = a b ^ y 0 } if odd(y) then (y,z) := (y-1, z*x); (x,y):= (x*x, y/2); { z* x y = a b } end; { z = a b } P:=z; { P = a b } 5. Prove following (8 points) { even(x) ^ odd(y)}

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: Select even (x+y) => (x,y) := (0,0) or odd(x+y) => (x,y) := (x-1,y+1) or odd(x) => (x,y) := (y,x) or odd(y) => (x,y := x+1 , y-1) end select { even(x) ^ odd(y)} 6. Prove following (8 points) {Nzeros = N i 1=< i <k : a[ i ] = 0} select a[k] = 0 => (Nzeros ,k := Nzeros +1 , k+1) or a[k] =! 0 => (Nzeros , k := Nzeros , k+1) end select {Nzeros = N i 1=< i <k : a[i] = 0} 7. Prove partial correctness of the following program M. {x ≥ 0} M {SQR 2 ≤ x < (SQR + 1) 2 } (12 points) {x ≥ 0} (y1, y2, y3) := (0,1,1) While y2 < = x loop (y1,y2, y3) := (y1+1,y2+y3+2, y3+2); End loop; SQR:= y1 {SQR 2 ≤ x < (SQR + 1) 2 } Hint: (a+b) 2 = a 2 +2ab+b 2 1+3+5+ … (2n+1) =(n+1) 2 If you can not find the invariant email Dr. Elrad...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

assinment 4 - Select even(x y =>(x,y:=(0,0 or odd(x y...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online