import MyNat.Addition -- imports addition.
namespace MyNat
open MyNat
Addition world
Level 2: add_assoc
-- associativity of addition.
It's well-known that (1 + 2) + 3 = 1 + (2 + 3) -- if you have three numbers
to add up, it doesn't matter which of the additions you do first. This fact
is called associativity of addition by mathematicians, and it is not
obvious. For example, subtraction really is not associative: (6 - 2) - 1
is really not equal to 6 - (2 - 1)
. We are going to have to prove
that addition, as defined the way we've defined it, is associative.
To prove associativity of addition it is handy to recall that addition was defined
by recursion on the right-most variable. This means you can use induction on the right-most
variable (try other variables at your peril!). Note that when Lean writes a + b + c
,
it means (a + b) + c
. If it wants to talk about a + (b + c)
it will put the brackets
in explicitly.
Reminder: you are done when you see "Goals accomplished 🎉" in the InfoView, and no errors in the VS Code Problems list.
Lemma
On the set of natural numbers, addition is associative.
In other words, for all natural numbers a, b
and c
, we have
(a + b) + c = a + (b + c).
lemmaadd_assoc (add_assoc: ∀ (a b c : MyNat), a + b + c = a + (b + c)aa: MyNatbb: MyNatc :c: MyNatMyNat) : (MyNat: Typea +a: MyNatb) +b: MyNatc =c: MyNata + (a: MyNatb +b: MyNatc) :=c: MyNata, b, c: MyNata + b + c = a + (b + c)a, b, c: MyNata + b + c = a + (b + c)a, b: MyNat
zeroa + b + zero = a + (b + zero)a, b: MyNat
zeroa + b + zero = a + (b + zero)a, b: MyNat
zeroa + b + 0 = a + (b + 0)a, b: MyNat
zeroa + b + 0 = a + (b + 0)a, b: MyNat
zeroa + b + 0 = a + (b + 0)a, b: MyNat
zeroa + b = a + (b + 0)a, b: MyNat
zeroa + b = a + (b + 0)a, b: MyNat
zeroa + b = a + (b + 0)a, b: MyNat
zeroa + b = a + bGoals accomplished! 🐙a, b, c: MyNat
ih: a + b + c = a + (b + c)
succa + b + succ c = a + (b + succ c)a, b, c: MyNat
ih: a + b + c = a + (b + c)
succa + b + succ c = a + (b + succ c)a, b, c: MyNat
ih: a + b + c = a + (b + c)
succsucc (a + b + c) = a + (b + succ c)a, b, c: MyNat
ih: a + b + c = a + (b + c)
succsucc (a + b + c) = a + (b + succ c)a, b, c: MyNat
ih: a + b + c = a + (b + c)
succsucc (a + b + c) = a + (b + succ c)a, b, c: MyNat
ih: a + b + c = a + (b + c)
succsucc (a + b + c) = a + succ (b + c)a, b, c: MyNat
ih: a + b + c = a + (b + c)
succsucc (a + b + c) = a + succ (b + c)a, b, c: MyNat
ih: a + b + c = a + (b + c)
succsucc (a + b + c) = a + succ (b + c)a, b, c: MyNat
ih: a + b + c = a + (b + c)
succsucc (a + b + c) = succ (a + (b + c))a, b, c: MyNat
ih: a + b + c = a + (b + c)
succsucc (a + b + c) = succ (a + (b + c))a, b, c: MyNat
ih: a + b + c = a + (b + c)
succsucc (a + b + c) = succ (a + (b + c))a, b, c: MyNat
ih: a + b + c = a + (b + c)
succsucc (a + (b + c)) = succ (a + (b + c))Goals accomplished! 🐙
On to Level 3.