Incorrect Answer.

We consider the body of the program's only while-statement
      z = z + x;
      a = a + 1;

To see whether x = y * a is an invariant for the while-statement, we place it as a postcondition at the bottom of the loop-body and push it upwards through that body to determine the weakest precondition that guarantees x = y * a to hold after the execution of the loop's body:

x = y * (a + 1) Weakest Precondition
z = z + x;
x = y * (a + 1) Assignment
a = a + 1;
x = y * a Assignment



Back to Question.
Next Question.