import MyNat.Definition
import MyNat.Inequality -- le_iff_exists_add
import Mathlib.Tactic.Use -- use tactic
import AdditionWorld.Level4 -- add_comm
namespace MyNat
open MyNat
Inequality world.
Level 3: le_succ_of_le
We have seen how the use
tactic makes progress on goals of the form ⊢ ∃ c, ...
.
But what do we do when we have a hypothesis of the form h : ∃ c, ...
?
The hypothesis claims that there exists some natural number c
with some
property. How are we going to get to that natural number c
? It turns out
that the cases
tactic can be used (just like it was used to extract
information from ∧
and ∨
and ↔
hypotheses). Let me talk you through
the proof of a ≤ b ⟹ a ≤ succ b
.
The goal is an implication so we clearly want to start with
intro h
After this, if you want, you can do something like
rw [le_iff_exists_add] at h ⊢
(get the sideways T with \|-
or \goal
then space). This rw
changes the ≤
into
its ∃
form in h
and the goal -- but if you are happy with just
imagining the ∃
whenever you read a ≤
then you don't need to do this line.
Our hypothesis h
is now ∃ (c : MyNat), b = a + c
(or a ≤ b
if you
elected not to do the definitional rewriting) so
cases h with | _ c hc => ..
gives you the natural number c
and the hypothesis hc : b = a + c
.
Now use use
wisely and you're home.
Lemma : le_succ
For all naturals a
, b
, if a ≤ b
then a ≤ succ b
.
theoremle_succ (le_succ: ∀ (a b : MyNat), a ≤ b → a ≤ succ baa: MyNatb :b: MyNatMyNat) :MyNat: Typea ≤a: MyNatb →b: MyNata ≤ (a: MyNatsuccsucc: MyNat → MyNatb) :=b: MyNata, b: MyNata ≤ b → a ≤ succ ba, b: MyNat
h: a ≤ ba ≤ succ ba, b: MyNat
h: a ≤ ba ≤ succ ba, b, c: MyNat
hc: b = a + c
introa ≤ succ ba, b, c: MyNat
hc: b = a + c
introa ≤ succ ba, b, c: MyNat
hc: b = a + c
introa ≤ succ (a + c)a, b, c: MyNat
hc: b = a + c
introa ≤ succ (a + c)Goals accomplished! 🐙
You can use succ c
or c + 1
or 1 + c
. Those numbers are all
equal, right? Try these variations and see what happens.
Now what about if you do use 1 + c
? Can you work out
what is going on? Does it help if I tell you that the definition
of 1
is succ 0
?
Next up Level 4