Stage 08 · Step 38 of 50
Neighbors make an even product.
01The idea
Two neighboring whole numbers cannot both be odd. One has an even half-size witness.
That even factor makes their product divisible by two.
02In maths
For every natural number n, 2 divides n(n + 1).
Picture it
Swipe sideways to see the whole 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.
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.
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
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.
example : 2 ∣ (7 : Nat) := by
exact ⟨3, rfl⟩
Application type mismatch: The argument rfl has type ?m.13 = ?m.13 but is expected to have type 7 = 2 * 3 in the application Exists.intro 3 rfl
The product of two and three is six, not seven.
The fix: Give a valid divisibility witness; seven has no natural-number half.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Prove that two divides the displayed product of six and seven.
Show a hint
Compute the product and find its half.
One more hint
Supply twenty-one as the divisibility witness.
- A little stretch
Use the even factor n to prove divisibility of the product.
Show a hint
The given hypothesis says two divides n.
One more hint
Use Nat.dvd_mul_right_of_dvd with the other factor.
module
import Mathlib.Data.Nat.Basic
example : 2 ∣ (6 : ℕ) * 7 := by
sorry
example (n : ℕ) (h : 2 ∣ n) : 2 ∣ n * (n + 1) := by
sorry
Compare with the checked solutions
There are often several valid proofs. These solutions were compiled with the same pinned Lean version.
module
import Mathlib.Data.Nat.Basic
example : 2 ∣ (6 : ℕ) * 7 := by
exact ⟨21, rfl⟩
example (n : ℕ) (h : 2 ∣ n) : 2 ∣ n * (n + 1) := by
exact Nat.dvd_mul_right_of_dvd h (n + 1)
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.