I was wondering what invariant condition (and where) I need to add to a recursive function
func compute_sum(n: felt) -> (sum: felt) {
if (n == 0) {
// When 0 is reached, return 0.
return (sum=0);
}
// @invariant n >= 0
loop:
let (sum) = compute_sum(n=n - 1);
let new_sum = sum + n;
return (sum=new_sum);
}
func main() {
let (res) = compute_sum(n=10);
return();
}
I was wondering what invariant condition (and where) I need to add to a recursive function