Hi,
I've been given the following problem about loop invariants:
Consider
x=4;
for(i=5;i<k;i++) {
a=a+x+i;
x=x*2;
}
Define the appropiate loop invariant that utilizes a closed formula for a and x.
Now, How do you know you have the right loop invariant here? I mean you can set the loop invariant to be: "At j'th iteration 'x' is less than 'a'" which will be correct but will not use any closed formulas right?
How can a statement (the loop invariant) can be used to determine the value of "a" when the loop is over? All the examples I've seen just state the loop invariant and its not being used as a closed formula.
Any ideas?
Thanks for all of your help.