NNG progress
This commit is contained in:
@@ -8,8 +8,6 @@ Title "the induction tactic."
|
||||
|
||||
open MyNat
|
||||
|
||||
set_option tactic.hygienic false
|
||||
|
||||
Introduction
|
||||
"
|
||||
OK so let's see induction in action. We're going to prove
|
||||
@@ -36,7 +34,7 @@ note that `zero_add` is about zero add something, and `add_zero` is about someth
|
||||
The names of the proofs tell you what the theorems are. Anyway, let's prove `0 + n = n`.
|
||||
"
|
||||
|
||||
Statement MyNat.zero_add
|
||||
Statement MyNat.zero_add (attr := simp)
|
||||
"For all natural numbers $n$, we have $0 + n = n$."
|
||||
(n : ℕ) : 0 + n = n := by
|
||||
Hint "You can start a proof by induction over `n` by typing:
|
||||
@@ -56,20 +54,25 @@ Statement MyNat.zero_add
|
||||
`{hn} : 0 + {n} = {n}` and you need to prove the statement for `succ {n}`."
|
||||
Hint (hidden := true) "look at `add_succ`."
|
||||
rw [add_succ]
|
||||
Branch
|
||||
simp? -- TODO
|
||||
Hint (hidden := true) "At this point you see the term `0 + {n}`, so you can use the
|
||||
induction hypothesis with `rw [{hn}]`."
|
||||
rw [hn]
|
||||
rfl
|
||||
|
||||
attribute [simp] MyNat.zero_add
|
||||
|
||||
NewTactic induction
|
||||
LemmaTab "Add"
|
||||
|
||||
Conclusion
|
||||
"
|
||||
## Now venture off on your own.
|
||||
|
||||
Those three tactics:
|
||||
Those three tactics:
|
||||
|
||||
* `induction n with d hd`
|
||||
* `induction n with d hd`
|
||||
* `rw [h]`
|
||||
* `rfl`
|
||||
|
||||
@@ -86,8 +89,7 @@ We're going to stop explaining stuff carefully now. If you get stuck or want
|
||||
to know more about Lean (e.g. how to do much harder maths in Lean),
|
||||
ask in `#new members` at
|
||||
[the Lean chat](https://leanprover.zulipchat.com)
|
||||
(login required, real name preferred). Kevin or Mohammad or one of the other
|
||||
people there might be able to help.
|
||||
(login required, real name preferred). Any of the people there might be able to help.
|
||||
|
||||
Good luck! Click on \"Next\" to solve some levels on your own.
|
||||
"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import NNG.Metadata
|
||||
import NNG.Levels.Addition.Level_1
|
||||
|
||||
Game "NNG"
|
||||
@@ -25,7 +24,7 @@ Statement MyNat.add_assoc
|
||||
"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). $"
|
||||
(a b c : ℕ) : (a + b) + c = a + (b + c) := by
|
||||
(a b c : ℕ) : (a + b) + c = a + (b + c) := by
|
||||
Hint "Because addition was defined by recursion on the right-most variable,
|
||||
use induction on the right-most variable (try other variables at your peril!).
|
||||
|
||||
@@ -34,8 +33,9 @@ $ (a + b) + c = a + (b + c). $"
|
||||
Branch
|
||||
induction a
|
||||
Hint "Good luck with that…"
|
||||
rw [zero_add, zero_add]
|
||||
rfl
|
||||
simp?
|
||||
--rw [zero_add, zero_add]
|
||||
--rfl
|
||||
Branch
|
||||
induction b
|
||||
Hint "Good luck with that…"
|
||||
@@ -54,10 +54,5 @@ $ (a + b) + c = a + (b + c). $"
|
||||
rw [hc]
|
||||
rfl
|
||||
|
||||
|
||||
Conclusion
|
||||
"
|
||||
|
||||
"
|
||||
|
||||
NewLemma MyNat.zero_add
|
||||
NewLemma MyNat.zero_add
|
||||
LemmaTab "Add"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import NNG.Metadata
|
||||
import NNG.Levels.Addition.Level_2
|
||||
|
||||
Game "NNG"
|
||||
@@ -46,6 +45,8 @@ $ \\operatorname{succ}(a) + b = \\operatorname{succ}(a + b)$."
|
||||
rw [add_succ]
|
||||
rfl
|
||||
|
||||
LemmaTab "Add"
|
||||
|
||||
Conclusion
|
||||
"
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import NNG.Metadata
|
||||
import NNG.Levels.Addition.Level_3
|
||||
|
||||
Game "NNG"
|
||||
@@ -21,6 +20,7 @@ Statement MyNat.add_comm
|
||||
In other words, for all natural numbers $a$ and $b$, we have
|
||||
$a + b = b + a$."
|
||||
(a b : ℕ) : a + b = b + a := by
|
||||
Hint (hidden := true) "You might want to start by induction."
|
||||
Branch
|
||||
induction a with d hd
|
||||
· rw [zero_add]
|
||||
@@ -39,6 +39,8 @@ $a + b = b + a$."
|
||||
rw [succ_add]
|
||||
rfl
|
||||
|
||||
LemmaTab "Add"
|
||||
|
||||
Conclusion
|
||||
"
|
||||
If you got this far -- nice! You're nearly ready to make a choice:
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Addition
|
||||
import NNG.Levels.Addition.Level_4
|
||||
|
||||
Game "NNG"
|
||||
@@ -9,13 +7,11 @@ Title "succ_eq_add_one"
|
||||
|
||||
open MyNat
|
||||
|
||||
theorem one_eq_succ_zero : (1 : ℕ) = succ 0 := by simp only
|
||||
|
||||
NewLemma MyNat.one_eq_succ_zero
|
||||
axiom MyNat.one_eq_succ_zero : (1 : ℕ) = succ 0
|
||||
|
||||
Introduction
|
||||
"
|
||||
I've just added `one_eq_succ_zero` (a proof of $1 = \\operatorname{succ}(0)$)
|
||||
I've just added `one_eq_succ_zero` (a proof of `1 = succc 0`)
|
||||
to your list of theorems; this is true
|
||||
by definition of $1$, but we didn't need it until now.
|
||||
|
||||
@@ -28,7 +24,7 @@ some theorems about $0$ (`zero_add`, `add_zero`), but, other than `1 = succ 0`,
|
||||
no theorems at all which mention $1$. Let's prove one now.
|
||||
"
|
||||
|
||||
Statement --MyNat.succ_eq_add_one
|
||||
Statement MyNat.succ_eq_add_one
|
||||
"For any natural number $n$, we have
|
||||
$ \\operatorname{succ}(n) = n+1$ ."
|
||||
(n : ℕ) : succ n = n + 1 := by
|
||||
@@ -37,6 +33,10 @@ $ \\operatorname{succ}(n) = n+1$ ."
|
||||
rw [add_zero]
|
||||
rfl
|
||||
|
||||
NewLemma MyNat.one_eq_succ_zero
|
||||
NewDefinition One
|
||||
LemmaTab "Add"
|
||||
|
||||
Conclusion
|
||||
"
|
||||
Well done! On to the last level!
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Addition
|
||||
import NNG.Levels.Addition.Level_5
|
||||
|
||||
Game "NNG"
|
||||
@@ -25,23 +23,92 @@ then the space bar (note that this is L for left, not a number 1).
|
||||
Similarly, if `h : a = b` then `rw [h]` will change `a`'s to `b`'s
|
||||
and `rw [← h]` will change `b`'s to `a`'s.
|
||||
|
||||
Also, you can be (and will need to be, in this level) more precise
|
||||
about where to rewrite theorems. `rw add_comm,` will just find the
|
||||
first `? + ?` it sees and swap it around. You can target more specific
|
||||
additions like this: `rw add_comm a` will swap around
|
||||
additions of the form `a + ?`, and `rw add_comm a b,` will only
|
||||
swap additions of the form `a + b`.
|
||||
|
||||
"
|
||||
|
||||
Statement --add_right_comm
|
||||
Statement MyNat.add_right_comm
|
||||
"For all natural numbers $a, b$ and $c$, we have
|
||||
$a + b + c = a + c + b$."
|
||||
(a b c : ℕ) : a + b + c = a + c + b := by
|
||||
Hint (hidden := true) "You want to change your goal to `a + (b + c) = _`
|
||||
so that you can then use commutativity."
|
||||
rw [add_assoc]
|
||||
Hint "Here you need to be more precise about where to rewrite theorems.
|
||||
`rw [add_comm]` will just find the
|
||||
first `_ + _` it sees and swap it around. You can target more specific
|
||||
additions like this: `rw [add_comm a]` will swap around
|
||||
additions of the form `a + _`, and `rw [add_comm a b]` will only
|
||||
swap additions of the form `a + b`."
|
||||
Branch
|
||||
rw [add_comm]
|
||||
Hint "`rw [add_comm]` just rewrites to first instance of `_ + _` it finds, which
|
||||
is not what you want to do here. Instead you can provide the arguments explicitely:
|
||||
|
||||
* `rw [add_comm b c]`
|
||||
* `rw [add_comm b]`
|
||||
* `rw [add_comm b _]`
|
||||
* `rw [add_comm _ c]`
|
||||
|
||||
would all have worked. You should go back and try again.
|
||||
"
|
||||
rw [add_comm b c]
|
||||
Branch
|
||||
rw [add_assoc]
|
||||
rfl
|
||||
rw [←add_assoc]
|
||||
rfl
|
||||
|
||||
LemmaTab "Add"
|
||||
|
||||
Conclusion
|
||||
"
|
||||
If you have got this far, then you have become very good at
|
||||
manipulating equalities in Lean. You can also now collect
|
||||
four collectibles (or `instance`s, as Lean calls them)
|
||||
|
||||
```
|
||||
MyNat.addSemigroup -- (after level 2)
|
||||
MyNat.addMonoid -- (after level 2)
|
||||
MyNat.addCommSemigroup -- (after level 4)
|
||||
MyNat.addCommMonoid -- (after level 4)
|
||||
```
|
||||
|
||||
These say that `ℕ` is a commutative semigroup/monoid.
|
||||
|
||||
In Multiplication World you will be able to collect such
|
||||
advanced collectibles as `MyNat.commSemiring` and
|
||||
`MyNat.distrib`, and then move on to power world and
|
||||
the famous collectible at the end of it.
|
||||
|
||||
One last thing -- didn't you think that solving this level
|
||||
`add_right_comm` was boring? Check out this AI that can do it for us.
|
||||
|
||||
From now on, the `simp` AI becomes accessible (it's just an advanced
|
||||
tactic really), and can nail some really tedious-for-a-human-to-solve
|
||||
goals. For example check out this one-line proof:
|
||||
|
||||
```
|
||||
example (a b c d e : ℕ ) :
|
||||
(((a + b) + c) + d) + e = (c + ((b + e) + a)) + d := by
|
||||
simp
|
||||
```
|
||||
|
||||
Imagine having to do that one by hand! The AI closes the goal
|
||||
because it knows how to use associativity and commutativity
|
||||
sensibly in a commutative monoid.
|
||||
|
||||
You are now done with addition world. Go back to the main menu (top left)
|
||||
and decide whether to press on with multiplication world and power world
|
||||
(which can be solved with `rw`, `refl` and `induction`), or to go on
|
||||
to Function World where you can learn the tactics needed to prove
|
||||
goals of the form $P\\implies Q$, thus enabling you to solve more
|
||||
advanced addition world levels such as $a+t=b+t\\implies a=b$. Note that
|
||||
Function World is more challenging mathematically; but if you can do Addition
|
||||
World you can surely do Multiplication World and Power World.
|
||||
"
|
||||
|
||||
-- First we have to get the `AddCommMonoid` collectible,
|
||||
-- which we do by saying the magic words which make Lean's type class inference
|
||||
-- system give it to us.
|
||||
-- -/
|
||||
-- instance : add_comm_monoid mynat := by structure_helper
|
||||
|
||||
Reference in New Issue
Block a user