cs245-asn7-soln

# cs245-asn7-soln - CS 245 Winter 2009 Assignment 7 Due Thu...

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

CS 245 Winter 2009 Assignment 7 Due: Thu 26 Mar 2009 10am in the CS245 Drop Boxes 40 marks SOLUTION SET There may be multiple correct answers to this question. 1. (40 marks) For each of the following programs, if the program satisfies its specification for partial correctness, use program correctness techniques to show it is correct. State any loop invariants. Use natural deduction (without transformational proof rules for propositional and predicate logic) to prove any verification conditions. If the program does not satisfy its specification, provide a counterexample and demonstrate that your counterexample does not satisfy the specification. 1

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

View Full Document
(a) (18 marks) ( | true | ) x = 2 * x; if (y > = 0) { if (y=0) { y = x + y; } else { y = 2 * y; } } else { y = x + 2; } ( | ∃ w y = 2 w | ) Annotated Program: ( | true | ) x = 2 * x; ( | ∃ w x = 2 w | ) Derived Asn (VC 1) if (y > = 0) { ( | ( w x = 2 w ) ( y greaterorequalslant 0) | ) If-then-else if (y=0) { ( | ( w x = 2 w ) ( y greaterorequalslant 0) ( y = 0) | ) If-then-else ( | ∃ w x + y = 2 w | ) Implied (VC 2) y = x + y; ( | ∃ w y = 2 w | ) } else { ( | ( w x = 2 w ) ( y greaterorequalslant 0) ∧ ¬ ( y = 0) | ) If-then-else ( | ∃ w 2 y = 2 w | ) Implied (VC 3) y = 2 * y; ( | ∃ w y = 2 w | ) Asn } ( | ∃ w y = 2 w | ) } else { ( | ( w x = 2 w ) ∧ ¬ ( y greaterorequalslant 0) | ) If-then-else ( | ∃ w x + 2 = 2 w | ) Implied (VC 4)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern