NNG progress
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Multiplication
|
||||
import Std.Tactic.RCases
|
||||
import Mathlib.Tactic.LeftRight
|
||||
import NNG.Levels.Multiplication
|
||||
import NNG.Levels.AdvAddition
|
||||
|
||||
Game "NNG"
|
||||
World "AdvMultiplication"
|
||||
@@ -12,28 +10,24 @@ open MyNat
|
||||
|
||||
Introduction
|
||||
"
|
||||
Welcome to Advanced Multiplication World! Before attempting this
|
||||
world you should have completed seven other worlds, including
|
||||
Multiplication World and Advanced Addition World. There are four
|
||||
levels in this world.
|
||||
|
||||
Recall that if `b : mynat` is a hypothesis and you do `cases b with n`,
|
||||
your one goal will split into two goals,
|
||||
namely the cases `b = 0` and `b = succ(n)`. So `cases` here is like
|
||||
a weaker version of induction (you don't get the inductive hypothesis).
|
||||
|
||||
## Tricks
|
||||
|
||||
1) if your goal is `⊢ X ≠ Y` then `intro h` will give you `h : X = Y` and
|
||||
a goal of `⊢ false`. This is because `X ≠ Y` *means* `(X = Y) → false`.
|
||||
Conversely if your goal is `false` and you have `h : X ≠ Y` as a hypothesis
|
||||
1) if your goal is `X ≠ Y` then `intro h` will give you `h : X = Y` and
|
||||
a goal of `False`. This is because `X ≠ Y` *means* `(X = Y) → False`.
|
||||
Conversely if your goal is `False` and you have `h : X ≠ Y` as a hypothesis
|
||||
then `apply h` will turn the goal into `X = Y`.
|
||||
|
||||
2) if `hab : succ (3 * x + 2 * y + 1) = 0` is a hypothesis and your goal is `⊢ false`,
|
||||
2) if `hab : succ (3 * x + 2 * y + 1) = 0` is a hypothesis and your goal is `False`,
|
||||
then `exact succ_ne_zero _ hab` will solve the goal, because Lean will figure
|
||||
out that `_` is supposed to be `3 * x + 2 * y + 1`.
|
||||
|
||||
"
|
||||
-- TODO: cases
|
||||
-- Recall that if `b : ℕ` is a hypothesis and you do `cases b with n`,
|
||||
-- your one goal will split into two goals,
|
||||
-- namely the cases `b = 0` and `b = succ n`. So `cases` here is like
|
||||
-- a weaker version of induction (you don't get the inductive hypothesis).
|
||||
|
||||
|
||||
Statement
|
||||
"The product of two non-zero natural numbers is non-zero."
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Multiplication
|
||||
import Std.Tactic.RCases
|
||||
import Mathlib.Tactic.LeftRight
|
||||
import NNG.Levels.AdvMultiplication.Level_1
|
||||
|
||||
Game "NNG"
|
||||
World "AdvMultiplication"
|
||||
@@ -15,14 +12,14 @@ Introduction
|
||||
A variant on the previous level.
|
||||
"
|
||||
|
||||
Statement -- eq_zero_or_eq_zero_of_mul_eq_zero
|
||||
Statement MyNat.eq_zero_or_eq_zero_of_mul_eq_zero
|
||||
"If $ab = 0$, then at least one of $a$ or $b$ is equal to zero."
|
||||
(a b : ℕ) (h : a * b = 0) :
|
||||
a = 0 ∨ b = 0 := by
|
||||
induction a with d
|
||||
left
|
||||
rfl
|
||||
induction b with e he
|
||||
induction b with e
|
||||
right
|
||||
rfl
|
||||
exfalso
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Multiplication
|
||||
import Std.Tactic.RCases
|
||||
import Mathlib.Tactic.LeftRight
|
||||
import NNG.Levels.AdvMultiplication.Level_2
|
||||
|
||||
|
||||
Game "NNG"
|
||||
World "AdvMultiplication"
|
||||
@@ -15,13 +13,10 @@ Introduction
|
||||
Now you have `eq_zero_or_eq_zero_of_mul_eq_zero` this is pretty straightforward.
|
||||
"
|
||||
|
||||
axiom eq_zero_or_eq_zero_of_mul_eq_zero (a b : ℕ) (h : a * b = 0) : a = 0 ∨ b = 0
|
||||
axiom zero_mul (a : ℕ) : 0 * a = 0
|
||||
|
||||
Statement
|
||||
"$ab = 0$, if and only if at least one of $a$ or $b$ is equal to zero.
|
||||
"
|
||||
(a b : ℕ): a * b = 0 ↔ a = 0 ∨ b = 0 := by
|
||||
{a b : ℕ} : a * b = 0 ↔ a = 0 ∨ b = 0 := by
|
||||
constructor
|
||||
intro h
|
||||
exact eq_zero_or_eq_zero_of_mul_eq_zero a b h
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import NNG.Metadata
|
||||
import NNG.MyNat.Multiplication
|
||||
import Std.Tactic.RCases
|
||||
import Mathlib.Tactic.LeftRight
|
||||
import NNG.Levels.AdvMultiplication.Level_3
|
||||
|
||||
Game "NNG"
|
||||
World "AdvMultiplication"
|
||||
@@ -19,14 +16,17 @@ People find this level hard. I have probably had more questions about this
|
||||
level than all the other levels put together, in fact. Many levels in this
|
||||
game can just be solved by \"running at it\" -- do induction on one of the
|
||||
variables, keep your head, and you're done. In fact, if you like a challenge,
|
||||
it might be instructive if you stop reading after the end of this paragraph and try solving this level now by induction,
|
||||
seeing the trouble you run into, and reading the rest of these comments afterwards. This level
|
||||
it might be instructive if you stop reading after the end of this paragraph
|
||||
and try solving this level now by induction,
|
||||
seeing the trouble you run into, and reading the rest of these comments afterwards.
|
||||
This level
|
||||
has a sting in the tail. If you are a competent mathematician, try
|
||||
and figure out what is going on. Write down a maths proof of the
|
||||
theorem in this level. Exactly what statement do you want to prove
|
||||
by induction? It is subtle.
|
||||
|
||||
Ok so here are some spoilers. The problem with naively running at it, is that if you try induction on,
|
||||
Ok so here are some spoilers. The problem with naively running at it,
|
||||
is that if you try induction on,
|
||||
say, $c$, then you are imagining a and b as fixed, and your inductive
|
||||
hypothesis $P(c)$ is $ab=ac \\implies b=c$. So for your inductive step
|
||||
you will be able to assume $ab=ad \\implies b=d$ and your goal will
|
||||
@@ -36,30 +36,64 @@ $ab=ad$ is not true! The statement $P(c)$ (with $a$ and $b$ regarded
|
||||
as constants) is not provable by induction.
|
||||
|
||||
What you *can* prove by induction is the following *stronger* statement.
|
||||
Imagine $a\not=0$ as fixed, and then prove \"for all $b$, if $ab=ac$ then $b=c$\"
|
||||
Imagine $a\\ne 0$ as fixed, and then prove \"for all $b$, if $ab=ac$ then $b=c$\"
|
||||
by induction on $c$. This gives us the extra flexibility we require.
|
||||
Note that we are quantifying over all $b$ in the inductive hypothesis -- it
|
||||
is essential that $b$ is not fixed.
|
||||
is essential that $b$ is not fixed.
|
||||
|
||||
You can do this in two ways in Lean -- before you start the induction
|
||||
you can write `revert b,`. The `revert` tactic is the opposite of the `intro`
|
||||
you can write `revert b`. The `revert` tactic is the opposite of the `intro`
|
||||
tactic; it replaces the `b` in the hypotheses with \"for all $b$\" in the goal.
|
||||
|
||||
Alternatively, you can write `induction c with d hd
|
||||
generalizing b` as the first line of the proof.
|
||||
[TODO: The second way does not work yet in this game]
|
||||
|
||||
If you do not modify your technique in this way, then this level seems
|
||||
to be impossible (judging by the comments I've had about it!)
|
||||
"
|
||||
-- Alternatively, you can write `induction c with d hd
|
||||
-- generalizing b` as the first line of the proof.
|
||||
|
||||
Statement
|
||||
|
||||
Statement MyNat.mul_left_cancel
|
||||
"If $a \\neq 0$, $b$ and $c$ are natural numbers such that
|
||||
$ ab = ac, $
|
||||
then $b = c$."
|
||||
(a b c : ℕ) (ha : a ≠ 0) : a * b = a * c → b = c := by
|
||||
sorry
|
||||
Hint "NOTE: As is, this level is probably too hard and contains no hints yet.
|
||||
Good luck!
|
||||
|
||||
Your first step should be `revert b`!"
|
||||
revert b
|
||||
induction c with c hc
|
||||
· intro b hb
|
||||
rw [mul_zero] at hb
|
||||
rcases eq_zero_or_eq_zero_of_mul_eq_zero _ _ hb
|
||||
exfalso
|
||||
apply ha
|
||||
exact h
|
||||
exact h
|
||||
· intro b h
|
||||
induction b with b hb
|
||||
exfalso
|
||||
apply ha
|
||||
rw [mul_zero] at h
|
||||
rcases eq_zero_or_eq_zero_of_mul_eq_zero _ _ h.symm with h | h
|
||||
exact h
|
||||
exfalso
|
||||
exact succ_ne_zero _ h
|
||||
rw [mul_succ, mul_succ] at h
|
||||
have j : b = c
|
||||
apply hc
|
||||
exact add_right_cancel _ _ _ h
|
||||
rw [j]
|
||||
rfl
|
||||
-- TODO: generalizing b.
|
||||
|
||||
NewTactic revert
|
||||
|
||||
Conclusion
|
||||
"
|
||||
|
||||
"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user