17. Sum of odd numbers
oddSum n adds up the first n odd numbers, 1 + 3 + … + (2n − 1). Prove that the result is always n * n.
Running and submitting solutions, the hints and the editorial come with the Academy Pass. The daily problem is open to every account.
1def oddSum : Nat → Nat
2 | 0 => 0
3 | n + 1 => oddSum n + (2 * n + 1)
4theorem solution (n : Nat) : oddSum n = n * n := by
givenLoading editor…
Type
\to in the editor, or click:Where you start. Everything above ⊢ may be assumed; the line below it is what you must prove.
n:Nat
⊢oddSum n = n * n
ReadyLn 1, Col 1Lean 4
Draft saved in this browser