int y = 0;
while(y<x){
y = y+1;
}
I wanted to prove that y is equal to x if x is > 0, otherwise it equals to 0. What's the loop invariant that allows me to prove that? For the case where x > 0, I came up with the invariant i <= x and y = i
where i
is an extra variable that I introduced to represent the current loop iteration. Is there a way to write the invariant w/o introducing the extra variable?