Exam2 (S06)

Exam2 (S06) - or a(k) >0 => (k, a(k))...

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

View Full Document Right Arrow Icon
MIDTERM II CS536: Science of Programming Spring 2006 Semester Monday April 3, 2006 Time - 3:15 pm - 4:30 pm Q1 a 10 Q1 b 10 Q1 c 10 Q2 a 5 Q2 b 5 Q2 c 10 Q3 a 10 Q3 b 10 Q3 c 5 Q4 a 5 Q4 b 10 Total 90 1a. (10 points) For a program construct S What are the four laws that a formal weakest precondition of S must satisfy? 1b. (10 points) Prove that the formal definition of the “;” satisfies the law of distributivity of disjunction. 1c. (10 points) Prove that the WP definition of a SELECT statement satisfies the law of excluded miracle. 2a. (5 points) Compute WP(S, Q). Show your steps. Where S is: select (zero number of guards) end select 2b. (5 points) Compute WP(S, Q). Show your steps. Where S is loopselect (zero number of guards) end loopselect 2c. (10 points) Construct a simple program S such that
Background image of page 1

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

View Full DocumentRight Arrow Icon
WP(S,P) U WP(S,Q) ≠ WP (S, P U Q) for some assertions P and Q. Q-3 Do following 3a. (10 points) Prove correctness. { 2200 i: 1 i < k; a(k) 0 } select a(k) = 0 => (k, a(k)) := (k + 1, 1)
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: or a(k) &gt;0 =&gt; (k, a(k)) := (k + 1, a(k)) or a(k) &lt;0 =&gt; (k, a(k)) := (k + 1, a(k)) end select { 2200 i: 1 i &lt; k; a(k) 0 } Note: prove invariant correctness only for one guard. 3b Prove partial correctness (10 points) Note: you must find the invariant prove invariant correctness only for one guard. {true} (a,b,c,d) :=(A,B,C,D): loopselect a b =&gt; swap(a, b) or b c =&gt; swap(b, c) or c d =&gt; swap(c, d) end loopselect; { (a,b,c,d) = permutation (A,B,C,D) and a&lt;=b&lt;=c&lt;=d } 3C Is the program in 3b is totally correct? Explain! (5 points) 4a. Explain the steps needed to prove loop termination for a loopselect statement . Do not assume a fair scheduling. (5 pts) 4.b Prove termination only of the following program. (10 points) {x &gt; y AND even (x) AND even (y)} Loopselect x y =&gt; x := x-2; or x y =&gt; y := y+2 end loopselect. { x=y}...
View Full Document

Page1 / 2

Exam2 (S06) - or a(k) &amp;amp;gt;0 =&amp;amp;gt; (k, a(k))...

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

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