Stage 05 · Step 24 of 50
Add a whole staircase.
01The idea
Stack blocks in rows of lengths zero, one, two, and so on. Two copies fit into a rectangle.
The formula records the same count algebraically.
02In maths
If S(n) = 0 + 1 + … + n, then 2S(n) = n(n + 1).
Picture it
Swipe sideways to see the whole picture.
stairSum n stacks rows of 0, 1, 2, …, n blocks. Turn a second copy around and slide it alongside: together they fill a rectangle with n rows and n + 1 columns. So two staircases hold exactly n × (n + 1) blocks, which is the statement, with no dividing by 2 needed. Lean proves it for every n by induction, and omega finishes the arithmetic in the step.03In Lean
This code comes directly from the file checked by Lean.
def stairSum : Nat → Nat
| 0 => 0
| n + 1 => stairSum n + (n + 1)
theorem twice_stairSum (n : Nat) : 2 * stairSum n = n * (n + 1) := by
induction n with
| zero => rfl
| succ n ih =>
simp only [stairSum, Nat.mul_add, Nat.add_mul, Nat.mul_one, Nat.one_mul, ih]
omega
The function stairSum defines a sum recursively: its value at the next number uses its previous value.
The familiar formula divides the product by two. Our division-free equation is easier to prove over natural numbers.
The tactic simp applies the listed rewrite rules. Expansion reduces the arithmetic to repeated products and linear combinations. omega, introduced next, finishes that linear part.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
n : Nat ⊢ 2 * stairSum n = n * (n + 1)
After line 5: theorem twice_stairSum (n : Nat) : 2 * stairSum n = n * (n + 1) := by
n : Nat ⊢ 2 * stairSum n = n * (n + 1)
After line 6: induction n with
n : Nat ⊢ 2 * stairSum n = n * (n + 1)
After line 7: | zero => rfl
no goals
After line 8: | succ n ih =>
case succ n : Nat ih : 2 * stairSum n = n * (n + 1) ⊢ 2 * stairSum (n + 1) = (n + 1) * (n + 1 + 1)
After line 9: simp only [stairSum, Nat.mul_add, Nat.add_mul, Nat.mul_one, Nat.one_mul, ih]
case succ n : Nat ih : 2 * stairSum n = n * (n + 1) ⊢ n * n + n + (2 * n + 2) = n * n + n + (n + 1) + (n + 1)
After line 10: omega
no goals
05Lean says
no goals
A goal is what remains to prove. The symbol ⊢ points to it. Meet the turnstile.
06A common slip
Lean is telling us something useful here.
def badStairSum : Nat → Nat
| 0 => 0
| n + 1 => badStairSum n + (n + 1)
example (n : Nat) : 2 * badStairSum n = n * (n + 1) := by
induction n with
| zero => rfl
| succ n ih => rfl
Tactic `rfl` failed: The left-hand side 2 * badStairSum (n + 1) is not definitionally equal to the right-hand side (n + 1) * (n + 1 + 1) case succ n : Nat ih : 2 * badStairSum n = n * (n + 1) ⊢ 2 * badStairSum (n + 1) = (n + 1) * (n + 1 + 1)
The successor equation needs the induction hypothesis and arithmetic reasoning.
The fix: Expose the smaller sum, rewrite using the hypothesis, and finish the arithmetic.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Check the formula for the concrete staircase ending at four.
Show a hint
Add the five terms on the left.
One more hint
This finite arithmetic statement is decidable.
- A little stretch
Complete the arithmetic step from the supplied relation between s and n.
Show a hint
Expand multiplication over addition in both the hypothesis and target.
One more hint
After expansion, omega can treat the repeated nonlinear product as one shared expression.
example : 2 * (0 + 1 + 2 + 3 + 4) = 4 * (4 + 1) := by
sorry
example (n s : Nat) (h : 2 * s = n * (n + 1)) : 2 * (s + (n + 1)) = (n + 1) * (n + 2) := by
sorry
Compare with the checked solutions
There are often several valid proofs. These solutions were compiled with the same pinned Lean version.
example : 2 * (0 + 1 + 2 + 3 + 4) = 4 * (4 + 1) := by
decide
example (n s : Nat) (h : 2 * s = n * (n + 1)) : 2 * (s + (n + 1)) = (n + 1) * (n + 2) := by
simp only [Nat.mul_add, Nat.add_mul, Nat.mul_one, Nat.one_mul] at h ⊢
omega
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.