Stage 05 · Step 24 of 50

Add a whole staircase.

Core Lean8 minutesLean 4.36.0

01The idea

Stack blocks in rows of lengths zero, one, two, and so on. Two copies fit into a rectangle.

Indy · Your guide for this idea
Indy pointing

The formula records the same count algebraically.

02In maths

If S(n) = 0 + 1 + … + n, then 2S(n) = n(n + 1).

Picture it

Two copies of a staircase fill an n by n + 1 rectangleLeft: one staircase for n = 4, with rows of 1, 2, 3 and 4 teal blocks, so stairSum 4 = 0 + 1 + 2 + 3 + 4 = 10. Middle: a second copy in gold, turned around, with rows of 4, 3, 2 and 1 blocks. Right: the two copies slide together into a rectangle with 4 rows and 5 columns, 20 blocks in all. Below: the goal 2 * stairSum n = n * (n + 1); for n = 4 it says 2 × 10 = 4 × 5.stairSum 40 + 1 + 2 + 3 + 4 = 10+a copy, turned aroundalso 10together: a rectangle5 columns = n + 14 rows = n4 × 5 = 20 blocks⊢ 2 * stairSum n = n * (n + 1)for n = 4: 2 × 10 = 4 × 5

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.

E24.leanTry it live (opens official Lean editor)
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.

After line 5
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

Captured from Lean 4.36.0
no goals

A goal is what remains to prove. The symbol ⊢ points to it. Meet the turnstile.

07Your turn

sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.

  1. Warm-up

    Check the formula for the concrete staircase ending at four.

  2. A little stretch

    Complete the arithmetic step from the supplied relation between s and n.

Exercises/E24.leanTry it live (opens official Lean editor)
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

08A quick check

1. Why state twice the sum?

Read the answer and explanation

It avoids natural-number division in the formula. The equation is equivalent to the usual triangular-number formula, without a division operation.

2. What does the recursive step add to the previous sum?

Read the answer and explanation

The new final term n + 1. The new row has n + 1 blocks.

One more idea in your toolkit.

Take your time. Progress is yours to mark.