I started learning Dafny and I just learned invariants. I've got this code:
function pot(m:int, n:nat): int
{
if n==0 then 1
else if n==1 then m
else if m==0 then 0
else pot(m,n-1) * m
}
method Pot(m:int, n:nat) returns (x:int)
ensures x == pot(m,n)
{
x:=1;
var i:=0;
if n==0 {x:=1;}
while i<=n
invariant i<=n;
{
x:=m*x;
i:=i+1;
}
}
And the given error is the following: "This loop invariant might not be maintained by the loop." I think I might need another invariant, but I think my code is correct other than that (I guess). Any help is appreciated. Thanks in advance.