cs245-asn7-soln

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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 (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...
View Full Document

Page1 / 8

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online