Consider the following code, assuming that i, x, y, and n are integers, with n >= 0.
State a non-trivial loop invariant for variable x.
Prove the loop invariant. Be sure that the proof includes the final conditions after the loop has ended.
Note: a correct proof of an incorrect invariant will still receive partial credit.
Give the final value of x in terms of n.
Hint: is the pattern close to (e.g. off by one) from some other pattern you might recognize?
Hint: you might need to include a condition for y somewhere within your proof.
i = 0;
x = 1;
// (the invariant goes here)
while i != n do
//
y = x + 2;
//
i = i + 1;
//
x = x * y;
//
//
After the loop, x =
Consider the following code, assuming that i, m, y, and n are integers, with n > 0.
State a non-trivial loop invariant for variable m. Prove the loop invariant. Be sure that the proof includes the final conditions after the loop has ended. Note: a correct proof of an incorrect invariant will still receive partial credit. Give the final value of m in terms of n Hint: is the pattern close to (e.g. off by one) from some other pattern you might recognize? Hint: you might need to include a condition for y somewhere within your proof. i = 0; x = 1; // while i < n do // y = x + 2; // i = i + 1; // x = x * y; // // (the invariant goes here) After the loop, m =