Professional Documents
Culture Documents
Reasoning About Programs - May 2003 (PAST PAPER)
Reasoning About Programs - May 2003 (PAST PAPER)
UNIVERSITY OF MANCHESTER
[PTO]
2 CS1112
i) an atomic formula;
ii) a logical connective;
iii) a quantifier;
iv) a well-formed formula;
v) a sentence.
b) Assume that x and y are real numbers, and let P(x,y) be the predicate x + y = 0.
i) x (y (P(x,y)))
ii) y (x (P(x,y)))
iii) x (y (P(x,y)))
translate it into English and explain what it means. Is it true? Explain why or
why not. (6 marks)
c) Suppose the function abs(x) gives the absolute value of a real number x.
Translate the following sentences:
i) “If the sum of two real numbers is zero, then they have the same
absolute value.”
ii) “It is only possible for the sum of two real numbers to be zero if they
have the same absolute value.”
into first-order logic sentences, using the predicate P(x,y) from (b), and explain if
they are true. (You should explain all the extra symbols that you may have
used.) (4 marks)
b) For each of the following, is the given program correct with respect to its
specification? Explain why or why not.
i) {x = 5} y := x + 1; x := x - 1; {x = y}
ii) {true} if x > 0 then x := -x else x := x - 1; {x < 0}
iii) {n = 1, x = 0} while n < 2 do begin x := x + n; n := n + 1 end; {x = n}
iv) {x < 2} x := x + 8 {x > 10}
v) {x = y} if x > y then z := x else z := y; {z = x} (10 marks)
3 CS1112
3. a) In SPARK, what are verification conditions? How are they generated? (6 marks)