{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Assignment 2 - {true x:=1{x=2 i{x>x x:=5{x=6 j{y=5...

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

View Full Document Right Arrow Icon
CS536 Science of Programming Assignment #2 Spring 2010 Due date – Feb. 05, 2010 2PM. 1. Consider the following program. (15 points) ---------------------- {a≥0 and b≥0} x:=a; y:=b; { } while x≠y loop { } if x>y the x:=x-y else y:=y-x; { } end; g:=x; { } {g=gcd (a,b)} ---------------------- Where gcd(a,b) means the greatest common devisor of a and b Above program may be correct, partially correct or incorrect. Do following : If you think this program is incorrect with respect to its specification – show it. If you think the program is partially correct or totally correct with respect to its specification then add partial correctness assertions. 2. For the following assignment programs prove correctness or show incorrect. (20 points) a. { x + y = z } x := y { 2y = z } b. { x = 2 } x := 2 * x + 1 { odd(x) } c. { true } x := 3 { x = 3 } d. { true } x := 3 { odd(x) } e. { false } x := 0 { x = 1 } f. {even(x+y)} x := 5x-3y {even(x+y)} g. {true} x:=y {x≤ y} h.
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: {true} x:=1 {x=2} i. {x>x} x:=5 {x=6} j. {y=5} x:=5 {y=5 ^ x>y} 3. Compute following (8 points) a. wp( x:=2x+3, x=13) b. wp (x:=x+y, x < 2y) c. wp (x:=y*c, x*y = c) d. wp( x:= (x-y)*(x+y) , x+y*y ≠0) 4. For the following assignment programs prove correctness or show incorrect. ( 20 points) a. { z = 3 } x:=1 ; y:=2 { x + y ≤ z } b. { z < 3 } x:=1 ; y:=2 { x + y < z } c. { x ≠ y } x:=y ; y:=x{ x = y } d. { x = 0 } x:=5 ; x:=5 { x ≤ y } e. { y = z } x:=z; y:= z+2 { x = z } f. { true } x:=x+1; y:=x+1 { x = y } g. { x = 1 ^ y = 1 } x:=2y ; y:= 2x { x = y } h. {false} x:=2 ; y:=3 {y>x} i. {true} x:=2 ; y:=3 {y>x} j. {false} x:=1 ; x:=2 {false} 5. Compute following (12 pts) a. wp (x:=y;y:=x , x=y) b. wp (x:=x+1;y:=y+1 , x>y) c. wp (x:=y+1;y:=x+1 , x<y) d. wp( x := 2x+y -5;y:= 2x , y<100) e. wp ( x:=y; y:=z;z:=y;x:=z, even(x) ) f. wp ( x:=2y; x:= x+3k, x<z) 6. prove P => wp (S.R) {P} S {R}...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern