{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

CS536 Homework #3 CWID:A20193023 1A. {a≥0 and b≥0} x:=a; y:=b; { gcd(x,y)=gcd(a,b)} while x≠y loop { x ≠ y ^ 0<x<=a ^ 0<y<=b } if x>y the x:=x-y else y:=y-x; {((x ≤ y) v (y ≤ x)) ^ 0<=x<=a ^ 0<=y<=b } end; g:=x; { gcd(x,y)=gcd(a,b)=g } {g=gcd (a,b)} The program is partially correct because if a or b is 0,the program never terminates .Hence the program would be correct by adding the above assertions. 2A. a. { x + y = z } x := y { 2y = z } x+y=z => (2y= z) y x x+y=z => 2y= z Incorrect b. { x = 2 } x := 2 * x + 1 { odd(x) } x=2 =>(odd(x)) x 2x+1 x=2 =>odd(2x+1) odd(2*2+1) odd(5) Correct c. { true } x := 3 { x = 3 } True =>(x =3) 3 x True =>(3 =3) Correct d. { true } x := 3 { odd(x) } True => (odd(x)) 3 x True =>odd(3) Correct

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

View Full Document
e. { false } x := 0 { x = 1 } False =>(x =1) 0 x False => x= 0 Correct f. {even(x+y)} x := 5x-3y {even(x+y)} even(x+y)=> (even(x+y)) x 5x-3y even(x+y)=>(even(5x-3y+y) even(x+y)=>even(5x-2y) Incorrect g. {true} x:=y {x≤ y} True =>(x≤ y) y x True =>(y<y or y=y) Correct h. {true} x:=1 {x=2} True =>(x=2) 1 x True =>(1=2) Incorrect i. {x>x} x:=5 {x=6} x>x =>(x=6) x 5 x>x =>(5=6) Correct j. {y=5} x:=5 {y=5 ^ x>y} y=5 =>(y=5 ^ x>y) 5 x y=5 =>( y=5 ^ 5>y) y=5 =>( 5=5 ^ 5>5) Incorrect 3A.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}