Stage 08 · Step 38 of 50

Neighbors make an even product.

Needs Mathlib12 minutesLean 4.36.0

01The idea

Two neighboring whole numbers cannot both be odd. One has an even half-size witness.

Goalie · Your guide for this idea
Goalie pointing

That even factor makes their product divisible by two.

02In maths

For every natural number n, 2 divides n(n + 1).

Picture it

Neighbors: one of n and n + 1 is always evenTop: the goal 2 ∣ n * (n + 1), and the numbers 0 to 11 in a row with the even ones coloured gold. Any two neighbours, such as 4 and 5 or 7 and 8, contain exactly one gold tile. Bottom left, case inl with h : n % 2 = 0, so hn : 2 ∣ n. For n = 4 the product 4 times 5 is drawn as 4 rows of 5 dots, and a dashed line splits the 4 rows into two equal halves of 10 dots. Bottom right, case inr with h : n % 2 = 1, so hn : 2 ∣ n + 1. For n = 7 the product 7 times 8 is drawn as 7 rows of 8 dots, and a dashed line splits the 8 columns into two equal halves of 28 dots.⊢ 2 ∣ n * (n + 1)gold = even: neighbors always include one01234567891011n = 4n = 7CASE inl: n IS EVENh : n % 2 = 0hn : 2 ∣ n4 × 5 = 10 + 102 divides the left factor n:Nat.dvd_mul_right_of_dvdCASE inr: n IS ODDh : n % 2 = 1hn : 2 ∣ n + 17 × 8 = 28 + 282 divides the right factor n + 1:Nat.dvd_mul_left_of_dvd

Swipe sideways to see the whole picture.

Picture n * (n + 1) as a rectangle of dots with n rows and n + 1 columns. Of two neighbors, one is always even, so either the rows or the columns split into two equal halves. That is why the proof has exactly two cases, one for each remainder of n when divided by 2.

03In Lean

This code comes directly from the file checked by Lean.

E38.leanTry it live (opens official Lean editor)
module

import Mathlib.Data.Nat.Basic

example (n : ℕ) : 2 ∣ n * (n + 1) := by
  have h : n % 2 = 0 ∨ n % 2 = 1 := by omega
  rcases h with h | h
  · have hn : 2 ∣ n := Nat.dvd_of_mod_eq_zero h
    exact Nat.dvd_mul_right_of_dvd hn (n + 1)
  · have hn : 2 ∣ n + 1 := Nat.dvd_of_mod_eq_zero (by omega)
    exact Nat.dvd_mul_left_of_dvd hn n

The symbol ∣ means “divides.” Type it with \dvd. Divisibility provides a multiplication witness.

The tactic rcases is a convenient way to split the two alternatives of the remainder statement.

The proof uses natural-number-specific divisibility lemmas. Check the factor order against each lemma’s statement.

04Step by step

Choose a line to see Lean’s recorded goal state after that line.

After line 5
n : ℕ
⊢ 2 ∣ n * (n + 1)
After line 5: example (n : ℕ) : 2 ∣ n * (n + 1) := by
n : ℕ
⊢ 2 ∣ n * (n + 1)
After line 6: have h : n % 2 = 0 ∨ n % 2 = 1 := by omega
no goals
After line 7: rcases h with h | h
case inl
n : ℕ
h : n % 2 = 0
⊢ 2 ∣ n * (n + 1)

case inr
n : ℕ
h : n % 2 = 1
⊢ 2 ∣ n * (n + 1)
After line 8: · have hn : 2 ∣ n := Nat.dvd_of_mod_eq_zero h
case inl
n : ℕ
h : n % 2 = 0
hn : 2 ∣ n
⊢ 2 ∣ n * (n + 1)
After line 9: exact Nat.dvd_mul_right_of_dvd hn (n + 1)
no goals
After line 10: · have hn : 2 ∣ n + 1 := Nat.dvd_of_mod_eq_zero (by omega)
case inr
n : ℕ
h : n % 2 = 1
hn : 2 ∣ n + 1
⊢ 2 ∣ n * (n + 1)
After line 11: exact Nat.dvd_mul_left_of_dvd hn n
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

    Prove that two divides the displayed product of six and seven.

  2. A little stretch

    Use the even factor n to prove divisibility of the product.

Exercises/E38.leanTry it live (opens official Lean editor)
module

import Mathlib.Data.Nat.Basic

example : 2 ∣ (6 : ℕ) * 7 := by
  sorry

example (n : ℕ) (h : 2 ∣ n) : 2 ∣ n * (n + 1) := by
  sorry

08A quick check

1. What does 2 ∣ n mean?

Read the answer and explanation

Two divides n. It means n is two times some natural number. Type ∣ with \dvd.

2. Why are there only two remainder cases?

Read the answer and explanation

A natural-number remainder modulo two is below two. The possible remainders are zero and one.

One more idea in your toolkit.

Take your time. Progress is yours to mark.