Given the following summation function:
function sum :: "nat ⇒ nat ⇒ nat" where
"sum i N = (if i > N then 0 else i + sum (Suc i) N)"
by pat_completeness auto
termination sum
apply (relation "measure (λ(i,N). N + 1 - i)")
apply auto
done
The stop condition is based on the N and i. I normally perform the induction on lists so I do not really know how to prove this function.
Can you please provide a solution and explanation of the next proof?
lemma sum_general[simp] : "c ≤ n ⟹ 2 * sum c n + (c - 1) * c = n * (n + 1)