Stage 08 · Step 36 of 50
Even plus even.
01The idea
Two even piles can each be split into matching halves. Put the piles together, and the halves combine too.
The witnesses make this argument precise.
02In maths
The sum of two even natural numbers is even.
Picture it
Swipe sideways to see the whole picture.
a is even” means a = r + r for some r: picture two equal rows. Put the rows of a and b side by side and you still have two equal rows, each of length r + s. That is the witness you hand to refine, and omega checks the arithmetic.03In Lean
This code comes directly from the file checked by Lean.
module
import Mathlib.Algebra.Ring.Parity
example (a b : ℕ) (ha : Even a) (hb : Even b) : Even (a + b) := by
obtain ⟨r, hr⟩ := ha
obtain ⟨s, hs⟩ := hb
refine ⟨r + s, ?_⟩
omega
A natural number is even when it is the sum of some natural number with itself.
The tactic obtain unpacks an existence proof into a witness and its property. The two even hypotheses supply two witnesses.
The tactic refine supplies a proof term with holes. Its question-mark hole becomes a new goal for the remaining equality.
04Step by step
Choose a line to see Lean’s recorded goal state after that line.
a b : ℕ ha : Even a hb : Even b ⊢ Even (a + b)
After line 5: example (a b : ℕ) (ha : Even a) (hb : Even b) : Even (a + b) := by
a b : ℕ ha : Even a hb : Even b ⊢ Even (a + b)
After line 6: obtain ⟨r, hr⟩ := ha
a b : ℕ hb : Even b r : ℕ hr : a = r + r ⊢ Even (a + b)
After line 7: obtain ⟨s, hs⟩ := hb
a b r : ℕ hr : a = r + r s : ℕ hs : b = s + s ⊢ Even (a + b)
After line 8: refine ⟨r + s, ?_⟩
a b r : ℕ hr : a = r + r s : ℕ hs : b = s + s ⊢ a + b = r + s + (r + s)
After line 9: 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.
module
import Mathlib.Algebra.Ring.Parity
example : Even (5 : ℕ) := by
exact ⟨2, rfl⟩
Application type mismatch: The argument rfl has type ?m.11 = ?m.11 but is expected to have type 5 = 2 + 2 in the application Exists.intro 2 rfl
The proposed witness doubles to four rather than five. Five is not even.
The fix: Use an even number and a witness whose double equals it.
07Your turn
sorry is a placeholder for unfinished work. Replace it as you solve each task. A finished proof has no placeholders.
- Warm-up
Give a witness showing that twelve is even.
Show a hint
Choose half of twelve.
One more hint
Package six with the arithmetic equality proof.
- A little stretch
Show that n plus itself is even for every natural number n.
Show a hint
The half-size witness is already visible.
One more hint
Use n as the witness.
module
import Mathlib.Algebra.Ring.Parity
example : Even (12 : ℕ) := by
sorry
example (n : ℕ) : Even (n + n) := 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.Algebra.Ring.Parity
example : Even (12 : ℕ) := by
exact ⟨6, rfl⟩
example (n : ℕ) : Even (n + n) := by
exact ⟨n, rfl⟩
no goals
08A quick check
09New words & tools
Take your time. Progress is yours to mark.