NNG progress
This commit is contained in:
@@ -1,24 +1,35 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Addition
|
||||
import NNG.MyNat.Multiplication
|
||||
import NNG.Levels.Addition
|
||||
|
||||
Game "NNG"
|
||||
World "Multiplication"
|
||||
Level 1
|
||||
Title ""
|
||||
Title "zero_mul"
|
||||
|
||||
open MyNat
|
||||
|
||||
Introduction
|
||||
"
|
||||
As a side note, the lemmas about addition are still available in your inventory
|
||||
in the lemma tab \"Add\" while the new lemmas about multiplication appear in the
|
||||
tab \"Mul\".
|
||||
|
||||
We are given `mul_zero`, and the first thing to prove is `zero_mul`.
|
||||
Like `zero_add`, we of course prove it by induction.
|
||||
"
|
||||
|
||||
Statement
|
||||
""
|
||||
: true := by
|
||||
trivial
|
||||
Statement MyNat.zero_mul
|
||||
"For all natural numbers $m$, we have $ 0 \\cdot m = 0$."
|
||||
(m : ℕ) : 0 * m = 0 := by
|
||||
induction m
|
||||
rw [mul_zero]
|
||||
rfl
|
||||
rw [mul_succ]
|
||||
rw [n_ih]
|
||||
rw [add_zero]
|
||||
rfl
|
||||
|
||||
Conclusion
|
||||
"
|
||||
|
||||
"
|
||||
NewTactic simp
|
||||
NewLemma MyNat.mul_zero MyNat.mul_succ
|
||||
NewDefinition Mul
|
||||
LemmaTab "Mul"
|
||||
|
||||
@@ -1,24 +1,31 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Addition
|
||||
import NNG.Levels.Multiplication.Level_1
|
||||
|
||||
Game "NNG"
|
||||
World "Multiplication"
|
||||
Level 2
|
||||
Title ""
|
||||
Title "mul_one"
|
||||
|
||||
open MyNat
|
||||
|
||||
Introduction
|
||||
"
|
||||
In this level we'll need to use
|
||||
|
||||
* `one_eq_succ_zero : 1 = succ 0 `
|
||||
|
||||
which was mentioned back in Addition World (see \"Add\" tab in your inventory) and
|
||||
which will be a useful thing to rewrite right now, as we
|
||||
begin to prove a couple of lemmas about how `1` behaves
|
||||
with respect to multiplication.
|
||||
"
|
||||
|
||||
Statement
|
||||
""
|
||||
: true := by
|
||||
trivial
|
||||
Statement MyNat.mul_one
|
||||
"For any natural number $m$, we have $ m \\cdot 1 = m$."
|
||||
(m : ℕ) : m * 1 = m := by
|
||||
rw [one_eq_succ_zero]
|
||||
rw [mul_succ]
|
||||
rw [mul_zero]
|
||||
rw [zero_add]
|
||||
rfl
|
||||
|
||||
Conclusion
|
||||
"
|
||||
|
||||
"
|
||||
LemmaTab "Mul"
|
||||
|
||||
@@ -1,24 +1,38 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Addition
|
||||
import NNG.Levels.Multiplication.Level_2
|
||||
|
||||
Game "NNG"
|
||||
World "Multiplication"
|
||||
Level 3
|
||||
Title ""
|
||||
Title "one_mul"
|
||||
|
||||
open MyNat
|
||||
|
||||
Introduction
|
||||
"
|
||||
These proofs from addition world might be useful here:
|
||||
|
||||
* `one_eq_succ_zero : 1 = succ 0`
|
||||
* `succ_eq_add_one a : succ a = a + 1`
|
||||
|
||||
We just proved `mul_one`, now let's prove `one_mul`.
|
||||
Then we will have proved, in fancy terms,
|
||||
that 1 is a \"left and right identity\"
|
||||
for multiplication (just like we showed that
|
||||
0 is a left and right identity for addition
|
||||
with `add_zero` and `zero_add`).
|
||||
"
|
||||
|
||||
Statement
|
||||
""
|
||||
: true := by
|
||||
trivial
|
||||
Statement MyNat.one_mul
|
||||
"For any natural number $m$, we have $ 1 \\cdot m = m$."
|
||||
(m : ℕ): 1 * m = m := by
|
||||
induction m with d hd
|
||||
· rw [mul_zero]
|
||||
rfl
|
||||
· rw [mul_succ]
|
||||
rw [hd]
|
||||
rw [succ_eq_add_one]
|
||||
rfl
|
||||
|
||||
Conclusion
|
||||
"
|
||||
LemmaTab "Mul"
|
||||
|
||||
"
|
||||
Conclusion ""
|
||||
|
||||
@@ -1,24 +1,44 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Addition
|
||||
import NNG.Levels.Multiplication.Level_3
|
||||
|
||||
Game "NNG"
|
||||
World "Multiplication"
|
||||
Level 4
|
||||
Title ""
|
||||
Title "mul_add"
|
||||
|
||||
open MyNat
|
||||
|
||||
Introduction
|
||||
"
|
||||
Where are we going? Well we want to prove `mul_comm`
|
||||
and `mul_assoc`, i.e. that `a * b = b * a` and
|
||||
`(a * b) * c = a * (b * c)`. But we *also* want to
|
||||
establish the way multiplication interacts with addition,
|
||||
i.e. we want to prove that we can \"expand out the brackets\"
|
||||
and show `a * (b + c) = (a * b) + (a * c)`.
|
||||
The technical term for this is \"left distributivity of
|
||||
multiplication over addition\" (there is also right distributivity,
|
||||
which we'll get to later).
|
||||
|
||||
Note the name of this proof -- `mul_add`. And note the left
|
||||
hand side -- `a * (b + c)`, a multiplication and then an addition.
|
||||
I think `mul_add` is much easier to remember than \"`left_distrib`\",
|
||||
an alternative name for the proof of this lemma.
|
||||
"
|
||||
|
||||
Statement
|
||||
""
|
||||
: true := by
|
||||
trivial
|
||||
Statement MyNat.mul_add
|
||||
"Multiplication is distributive over addition.
|
||||
In other words, for all natural numbers $a$, $b$ and $t$, we have
|
||||
$t(a + b) = ta + tb$."
|
||||
(t a b : ℕ) : t * (a + b) = t * a + t * b := by
|
||||
induction b with d hd
|
||||
· rw [add_zero, mul_zero, add_zero]
|
||||
rfl
|
||||
· rw [add_succ]
|
||||
rw [mul_succ]
|
||||
rw [hd]
|
||||
rw [mul_succ]
|
||||
rw [add_assoc]
|
||||
rfl
|
||||
|
||||
Conclusion
|
||||
"
|
||||
LemmaTab "Mul"
|
||||
|
||||
"
|
||||
|
||||
@@ -1,22 +1,41 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Addition
|
||||
import NNG.Levels.Multiplication.Level_4
|
||||
|
||||
Game "NNG"
|
||||
World "Multiplication"
|
||||
Level 5
|
||||
Title ""
|
||||
Title "mul_assoc"
|
||||
|
||||
open MyNat
|
||||
|
||||
Introduction
|
||||
"
|
||||
We now have enough to prove that multiplication is associative.
|
||||
|
||||
## Random tactic hint
|
||||
|
||||
You can do `repeat rw [mul_succ]` to repeat a tactic as often as possible.
|
||||
|
||||
"
|
||||
|
||||
Statement
|
||||
""
|
||||
: true := by
|
||||
trivial
|
||||
Statement MyNat.mul_assoc
|
||||
"Multiplication is associative.
|
||||
In other words, for all natural numbers $a$, $b$ and $c$, we have
|
||||
$(ab)c = a(bc)$."
|
||||
(a b c : ℕ) : (a * b) * c = a * (b * c) := by
|
||||
induction c with d hd
|
||||
· repeat rw [mul_zero]
|
||||
rfl
|
||||
· rw [mul_succ]
|
||||
rw [mul_succ]
|
||||
rw [hd]
|
||||
rw [mul_add]
|
||||
rfl
|
||||
|
||||
NewTactic «repeat»
|
||||
LemmaTab "Mul"
|
||||
|
||||
-- TODO: old version introduced `rwa` here, but it would need to be modified
|
||||
-- as our `rw` does not call `rfl` at the end.
|
||||
|
||||
Conclusion
|
||||
"
|
||||
|
||||
@@ -1,22 +1,50 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Addition
|
||||
import NNG.Levels.Multiplication.Level_5
|
||||
|
||||
Game "NNG"
|
||||
World "Multiplication"
|
||||
Level 6
|
||||
Title ""
|
||||
Title "succ_mul"
|
||||
|
||||
open MyNat
|
||||
|
||||
Introduction
|
||||
"
|
||||
We now begin our journey to `mul_comm`, the proof that `a * b = b * a`.
|
||||
We'll get there in level 8. Until we're there, it is frustrating
|
||||
but true that we cannot assume commutativity. We have `mul_succ`
|
||||
but we're going to need `succ_mul` (guess what it says -- maybe you
|
||||
are getting the hang of Lean's naming conventions).
|
||||
|
||||
Remember also that we have tools like
|
||||
|
||||
* `add_right_comm a b c : a + b + c = a + c + b`
|
||||
|
||||
These things are the tools we need to slowly build up the results
|
||||
which we will need to do mathematics \"normally\".
|
||||
We also now have access to Lean's `simp` tactic,
|
||||
which will solve any goal which just needs a bunch
|
||||
of rewrites of `add_assoc` and `add_comm`. Use if
|
||||
you're getting lazy!
|
||||
"
|
||||
|
||||
Statement
|
||||
""
|
||||
: true := by
|
||||
trivial
|
||||
Statement MyNat.succ_mul
|
||||
"For all natural numbers $a$ and $b$, we have
|
||||
$\\operatorname{succ}(a) \\cdot b = ab + b$."
|
||||
(a b : ℕ) : succ a * b = a * b + b := by
|
||||
induction b with d hd
|
||||
· rw [mul_zero]
|
||||
rw [mul_zero]
|
||||
rw [add_zero]
|
||||
rfl
|
||||
· rw [mul_succ]
|
||||
rw [mul_succ]
|
||||
rw [hd]
|
||||
rw [add_succ]
|
||||
rw [add_succ]
|
||||
rw [add_right_comm]
|
||||
rfl
|
||||
|
||||
LemmaTab "Mul"
|
||||
|
||||
Conclusion
|
||||
"
|
||||
|
||||
@@ -1,22 +1,44 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Addition
|
||||
import NNG.Levels.Multiplication.Level_6
|
||||
|
||||
Game "NNG"
|
||||
World "Multiplication"
|
||||
Level 7
|
||||
Title ""
|
||||
Title "add_mul"
|
||||
|
||||
open MyNat
|
||||
|
||||
Introduction
|
||||
"
|
||||
|
||||
We proved `mul_add` already, but because we don't have commutativity yet
|
||||
we also need to prove `add_mul`. We have a bunch of tools now, so this won't
|
||||
be too hard. You know what -- you can do this one by induction on any of
|
||||
the variables. Try them all! Which works best? If you can't face
|
||||
doing all the commutativity and associativity, remember the high-powered
|
||||
`simp` tactic mentioned at the bottom of Addition World level 6,
|
||||
which will solve any puzzle which needs only commutativity
|
||||
and associativity. If your goal looks like `a + (b + c) = c + b + a` or something,
|
||||
don't mess around doing it explicitly with `add_comm` and `add_assoc`,
|
||||
just try `simp`.
|
||||
"
|
||||
|
||||
Statement
|
||||
""
|
||||
: true := by
|
||||
trivial
|
||||
Statement MyNat.add_mul
|
||||
"Addition is distributive over multiplication.
|
||||
In other words, for all natural numbers $a$, $b$ and $t$, we have
|
||||
$(a + b) \times t = at + bt$."
|
||||
(a b t : ℕ) : (a + b) * t = a * t + b * t := by
|
||||
induction b with d hd
|
||||
· rw [zero_mul]
|
||||
rw [add_zero]
|
||||
rw [add_zero]
|
||||
rfl
|
||||
· rw [add_succ]
|
||||
rw [succ_mul]
|
||||
rw [hd]
|
||||
rw [succ_mul]
|
||||
rw [add_assoc]
|
||||
rfl
|
||||
|
||||
LemmaTab "Mul"
|
||||
|
||||
Conclusion
|
||||
"
|
||||
|
||||
@@ -1,24 +1,46 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Addition
|
||||
import NNG.Levels.Multiplication.Level_7
|
||||
|
||||
Game "NNG"
|
||||
World "Multiplication"
|
||||
Level 8
|
||||
Title ""
|
||||
Title "mul_comm"
|
||||
|
||||
open MyNat
|
||||
|
||||
Introduction
|
||||
"
|
||||
|
||||
Finally, the boss level of multiplication world. But (assuming you
|
||||
didn't cheat) you are well-prepared for it -- you have `zero_mul`
|
||||
and `mul_zero`, as well as `succ_mul` and `mul_succ`. After this
|
||||
level you can of course throw away one of each pair if you like,
|
||||
but I would recommend you hold on to them, sometimes it's convenient
|
||||
to have exactly the right tools to do a job.
|
||||
"
|
||||
|
||||
Statement
|
||||
""
|
||||
: true := by
|
||||
trivial
|
||||
Statement MyNat.mul_comm
|
||||
"Multiplication is commutative."
|
||||
(a b : ℕ) : a * b = b * a := by
|
||||
induction b with d hd
|
||||
· rw [zero_mul]
|
||||
rw [mul_zero]
|
||||
rfl
|
||||
· rw [succ_mul]
|
||||
rw [← hd]
|
||||
rw [mul_succ]
|
||||
rfl
|
||||
|
||||
LemmaTab "Mul"
|
||||
|
||||
Conclusion
|
||||
"
|
||||
You've now proved that the natural numbers are a commutative semiring!
|
||||
That's the last collectible in Multiplication World.
|
||||
|
||||
* `CommSemiring ℕ`
|
||||
|
||||
But don't leave multiplication just yet -- prove `mul_left_comm`, the last
|
||||
level of the world, and then we can beef up the power of `simp`.
|
||||
"
|
||||
|
||||
-- TODO: collectible
|
||||
-- instance mynat.comm_semiring : comm_semiring mynat := by structure_helper
|
||||
@@ -1,24 +1,57 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Addition
|
||||
import NNG.Levels.Multiplication.Level_8
|
||||
|
||||
Game "NNG"
|
||||
World "Multiplication"
|
||||
Level 9
|
||||
Title ""
|
||||
Title "mul_left_comm"
|
||||
|
||||
open MyNat
|
||||
|
||||
Introduction
|
||||
"
|
||||
You are equipped with
|
||||
|
||||
* `mul_assoc (a b c : ℕ) : (a * b) * c = a * (b * c)`
|
||||
* `mul_comm (a b : ℕ) : a * b = b * a`
|
||||
|
||||
Re-read the docs for `rw` so you know all the tricks.
|
||||
You can see them in your inventory on the right.
|
||||
|
||||
"
|
||||
|
||||
Statement
|
||||
""
|
||||
: true := by
|
||||
trivial
|
||||
Statement MyNat.mul_left_comm
|
||||
"For all natural numbers $a$ $b$ and $c$, we have $a(bc)=b(ac)$."
|
||||
(a b c : ℕ) : a * (b * c) = b * (a * c) := by
|
||||
rw [← mul_assoc]
|
||||
rw [mul_comm a]
|
||||
rw [mul_assoc]
|
||||
rfl
|
||||
|
||||
LemmaTab "Mul"
|
||||
|
||||
-- TODO: make simp work:
|
||||
-- attribute [simp] mul_assoc mul_comm mul_left_comm
|
||||
|
||||
Conclusion
|
||||
"
|
||||
And now I whisper a magic incantation
|
||||
|
||||
```
|
||||
attribute [simp] mul_assoc mul_comm mul_left_comm
|
||||
```
|
||||
|
||||
and all of a sudden Lean can automatically do levels which are
|
||||
very boring for a human, for example
|
||||
|
||||
```
|
||||
example (a b c d e : ℕ) :
|
||||
(((a * b) * c) * d) * e = (c * ((b * e) * a)) * d := by
|
||||
simp
|
||||
```
|
||||
|
||||
If you feel like attempting Advanced Multiplication world
|
||||
you'll have to do Function World and the Proposition Worlds first.
|
||||
These worlds assume a certain amount of mathematical maturity
|
||||
(perhaps 1st year undergraduate level).
|
||||
Your other possibility is Power World, with the \"final boss\".
|
||||
"
|
||||
|
||||
Reference in New Issue
Block a user