ENع
←Proofs and induction
Lesson 09 · Logic and sets

Proofs and induction

12 min9 steps5 questionsBeginner
About this lesson

A proof shows that a claim is true in every case, not just the ones you tried. Follow one claim, 1 + 2 + … + n = n(n+1)/2, from checking examples to a full proof by induction: a base case that starts the chain, and an inductive step that passes the truth from each case to the next, like a row of falling dominoes.

You'll learn to

Tick what you feel confident about. These self-checks do not affect your lesson score.

Fig 9 · Interactive
01 / 09

A claim for every n

A proof shows a claim is true in every case. Our claim, called P(n): 1 + 2 + … + n = n(n+1)/2 for every whole number n ≥ 1. The formula row works out the right side for n = 1 to 5.

>>> def f(n):
...     return n * (n + 1) // 2
...
>>> [f(n) for n in range(1, 6)]
[1, 3, 6, 10, 15]
Loading figure…
or ← →
Read the lesson step by step
  1. A claim for every n

    A proof shows a claim is true in every case. Our claim, called P(n): 1 + 2 + … + n = n(n+1)/2 for every whole number n ≥ 1. The formula row works out the right side for n = 1 to 5.

    >>> def f(n):
    ...     return n * (n + 1) // 2
    ...
    >>> [f(n) for n in range(1, 6)]
    [1, 3, 6, 10, 15]
  2. Examples are not a proof

    Now add up the left side: 1, then 1 + 2 = 3, then 6, 10 and 15. All five match the formula. But the claim is about every n, and there are infinitely many. Checking cases, however many, can never cover them all.

    >>> [sum(range(1, n + 1)) for n in range(1, 6)]
    [1, 3, 6, 10, 15]
    >>> all(sum(range(1, n + 1)) == n * (n + 1) // 2 for n in range(1, 1001))
    True
  3. The domino idea

    Proof by induction works like a row of dominoes. Show two things. Base case: the first domino falls. Inductive step: whenever one domino falls, it knocks over the next. Then every domino falls, however long the row.

    >>> sum(range(1, 101))        # 1 + 2 + ... + 100
    5050
    >>> 100 * 101 // 2
    5050
  4. Base case: n = 1

    Base case: check P(1). The left side is just 1. The right side is 1 × 2 / 2 = 1. Both sides are equal, so P(1) is true. The first lamp lights: the first domino falls.

    >>> n = 1
    >>> sum(range(1, n + 1)), n * (n + 1) // 2
    (1, 1)
  5. Assume P(k)

    Inductive step. Pick any whole number k ≥ 1 and assume P(k) is true: 1 + … + k = k(k+1)/2. This assumption is called the inductive hypothesis. Now ask: if P(k) is true, must P(k + 1) be true too?

    >>> k = 10                    # one example k; the proof works for any k
    >>> sum(range(1, k + 1)) == k * (k + 1) // 2
    True
  6. Add the next number

    The left side of P(k + 1) is 1 + … + k + (k + 1). Its first k terms are exactly the left side of P(k), so the hypothesis lets us swap them for k(k+1)/2. That leaves k(k+1)/2 + (k + 1).

    >>> k = 10
    >>> sum(range(1, k + 2)) == k * (k + 1) // 2 + (k + 1)
    True
  7. Tidy up the algebra

    Take out the common factor (k + 1): k(k+1)/2 + (k + 1) = (k + 1)(k/2 + 1) = (k + 1)(k + 2)/2. That is the formula with n = k + 1. So if P(k) is true, P(k + 1) is true.

    >>> k = 10
    >>> k * (k + 1) // 2 + (k + 1), (k + 1) * (k + 2) // 2
    (66, 66)
  8. The dominoes fall

    Now put the two parts together. P(1) is true. The step with k = 1 gives P(2), with k = 2 it gives P(3), then P(4), P(5) and on forever. Every n is reached, so P(n) is true for all n ≥ 1.

    >>> for n in range(1, 6):
    ...     print(n, sum(range(1, n + 1)), n * (n + 1) // 2)
    ...
    1 1 1
    2 3 3
    3 6 6
    4 10 10
    5 15 15
  9. Both parts are needed

    Drop either part and the proof fails. The false claim n = n + 1 has a working step: if n = n + 1, then n + 1 = n + 2. But no case is true, so nothing starts the chain.

    >>> n = 1
    >>> n == n + 1               # the base case fails
    False

Quiz Unlocks after the last step.