Incorrect Answer.

We consider the program P
y = x - y - 1;
x = x + 1;
y = 2*x + y;

This answer claims that the precondition y = y + 3 guarantees that, after the program has run and terminated, x = y. In order to determine whether this is true or not, we can compute the weakest precondition for the program which quarantees the postcondition x = y. To obtain that, we push x = y upwards through the assignments in the program and simplify if need be:

y = 2x Weakest Precondition
(x + 1) = 2(x + 1) + (x - y - 1) Implied
y = x - y - 1;
(x + 1) = 2(x + 1) + y Assignment
x = x + 1;
x = 2x + y Assignment
y = 2x + y;
x = y Assignment

(For which combinations of x and y values is this an implication nonetheless?)

Back to Question.
Next Question.


Back to Question.
Next Question.