Stage 08 · Step 36 of 50

Even plus even.

Needs Mathlib12 minutesLean 4.36.0

01The idea

Two even piles can each be split into matching halves. Put the piles together, and the halves combine too.

Lemmi · Your guide for this idea
Lemmi pointing

The witnesses make this argument precise.

02In maths

The sum of two even natural numbers is even.

Picture it

Even plus even: two equal rows plus two equal rowsAn even number is drawn as two equal rows of squares. Left: a = r + r, two teal rows of r squares each (here r = 3). Middle: b = s + s, two coral rows of s squares each (here s = 2). Right: put them side by side and a + b is still two equal rows, each with r + s squares. So r + s is the witness, given with refine ⟨r + s, ?_⟩. Bottom: the remaining goal a + b = r + s + (r + s), with hypotheses hr : a = r + r and hs : b = s + s, is finished by omega, leaving no goals.hr : a = r + rhs : b = s + sa + brsr + srsr + s+each even number is two equal rowsstill two equal rows, of r + s eachrefine ⟨r + s, ?_⟩the witness for a + b:WHAT IS LEFT TO CHECKhr : a = r + rhs : b = s + s⊢ a + b = r + s + (r + s)omegano goals

Swipe sideways to see the whole picture.

In Lean, “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.

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

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

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

    Give a witness showing that twelve is even.

  2. A little stretch

    Show that n plus itself is even for every natural number n.

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

import Mathlib.Algebra.Ring.Parity

example : Even (12 : ℕ) := by
  sorry

example (n : ℕ) : Even (n + n) := by
  sorry

08A quick check

1. What information does Even a provide here?

Read the answer and explanation

A witness whose double is a. The predicate is expressed by an existence statement.

2. What witness works for the sum?

Read the answer and explanation

The sum of the original witnesses. Adding both halves gives half of the combined total.

One more idea in your toolkit.

Take your time. Progress is yours to mark.