nng levels
This commit is contained in:
@@ -4,31 +4,29 @@ import NNG.MyNat.Multiplication
|
||||
Game "NNG"
|
||||
World "Tutorial"
|
||||
Level 2
|
||||
Title "the rewrite (rw) tactic"
|
||||
Title "the rw tactic"
|
||||
|
||||
Introduction
|
||||
"
|
||||
In this level, you also get \"Assumptions\" about your objects. These are hypotheses of which
|
||||
you assume (or know) that they are true.
|
||||
|
||||
The `rewrite` tactic is the way to \"substitute in\" the value of a variable.
|
||||
The \"rewrite\" tactic `rw` is the way to \"substitute in\" the value of a variable.
|
||||
If you have a hypothesis of the form `A = B`, and your goal mentions
|
||||
the left hand side `A` somewhere,
|
||||
then the rewrite tactic will replace the `A` in your goal with a `B`.
|
||||
|
||||
*(Note: For this game, `rw` is a shorthand for `rewrite`. Out in the real world, `rw` tries to call
|
||||
`rfl` automatically afterwards.)*
|
||||
Here is a theorem which cannot be proved using rfl -- you need a rewrite first.
|
||||
"
|
||||
|
||||
Statement
|
||||
"If $x$ and $y$ are natural numbers, and $y = x + 7$, then $2y = 2(x + 7)$."
|
||||
(x y : ℕ) (h : y = x + 7) : 2 * y = 2 * (x + 7) := by
|
||||
Hint "You can use `rewrite [h]` to replace the `{y}` with `x + 7`.
|
||||
Hint "You can use `rw [h]` to replace the `{y}` with `x + 7`.
|
||||
Note that the assumption `h` is written
|
||||
inside square brackets: `[h]`."
|
||||
rw [h]
|
||||
Hint "In this game not all hints are directly shown. If you need help finishing the proof, click
|
||||
on \"More Help\" below!"
|
||||
Hint "Not all hints are directly shown. If you are stuck and need more help
|
||||
finishing the proof, click on \"More Help\" below!"
|
||||
Hint (hidden := true)
|
||||
"Now both sides are identical, so you can use `rfl` to close the goal."
|
||||
rfl
|
||||
|
||||
@@ -40,13 +40,13 @@ on the natural numbers, for example addition, multiplication and so on.
|
||||
|
||||
This game is all about seeing how far these axioms of Peano can take us.
|
||||
|
||||
Now let us practise the use of `rewrite` with this new function `succ`:
|
||||
Now let us practise the use of `rw` with this new function `succ`:
|
||||
"
|
||||
|
||||
Statement
|
||||
"If $\\operatorname{succ}(a) = b$, then $\\operatorname{succ}(\\operatorname{succ}(a)) = \\operatorname{succ}(a)$."
|
||||
(a b : ℕ) (h : (succ a) = b) : succ (succ a) = succ b := by
|
||||
Hint "You can use `rewrite` and your assumption `{h}` to substitute `succ a` with `b`.
|
||||
Hint "You can use `rw` and your assumption `{h}` to substitute `succ a` with `b`.
|
||||
|
||||
Notes:
|
||||
|
||||
@@ -54,7 +54,7 @@ Statement
|
||||
them in mathematics: `succ b` means $\\operatorname\{succ}(b)$.
|
||||
2) If you would want to substitute instead `b` with `succ a`, you can do that
|
||||
writing a small `←` (`\\l`, i.e. backslash + small letter L + space)
|
||||
before `h` like this: `rewrite [← h]`."
|
||||
before `h` like this: `rw [← h]`."
|
||||
Branch
|
||||
rewrite [← h]
|
||||
Hint (hidden := true) "Now both sides are identical…"
|
||||
|
||||
@@ -21,9 +21,9 @@ theorem. Note the name of this proof. Mathematicians sometimes call it
|
||||
\"Lemma 2.1\" or \"Hypothesis P6\" or something.
|
||||
But computer scientists call it `add_zero` because it tells you what the answer to
|
||||
\"x add zero\" is. It's a much better name than \"Lemma 2.1\".
|
||||
Even better, you can use the `rewrite` tactic
|
||||
Even better, you can use the `rw` tactic
|
||||
with `add_zero`. If you ever see `x + 0` in your goal,
|
||||
`rewrite [add_zero]` should simplify it to `x`. This is
|
||||
`rw [add_zero]` should simplify it to `x`. This is
|
||||
because `add_zero` is a proof that `x + 0 = x`
|
||||
(more precisely, `add_zero x` is a proof that `x + 0 = x` but
|
||||
Lean can figure out the `x` from the context).
|
||||
@@ -38,23 +38,24 @@ What's going on here is that we assume `a + d` is already defined, and we define
|
||||
Note the name of this proof too: `add_succ` tells you how to add a successor
|
||||
to something.
|
||||
If you ever see `… + succ …` in your goal, you should be able to use
|
||||
`rewrite [add_succ]`, to make progress.
|
||||
`rw [add_succ]` to make progress.
|
||||
"
|
||||
|
||||
Statement
|
||||
"For all natural numbers $a$, we have $a + \\operatorname{succ}(0) = a$."
|
||||
(a : ℕ) : a + succ 0 = succ a := by
|
||||
Hint "You find `{a} + succ …` in the goal, so you can use `rewrite` and `add_succ`
|
||||
Hint "You find `{a} + succ …` in the goal, so you can use `rw` and `add_succ`
|
||||
to make progress."
|
||||
Hint (hidden := true) "Explicitely, type `rewrite [add_succ]`!"
|
||||
rewrite [add_succ]
|
||||
Hint (hidden := true) "Explicitely, type `rw [add_succ]`!"
|
||||
rw [add_succ]
|
||||
Hint "Now you see a term of the form `… + 0`, so you can use `add_zero`."
|
||||
Hint (hidden := true) "Explicitely, type `rewrite [add_zero]`!"
|
||||
rewrite [add_zero]
|
||||
Hint (hidden := true) "Explicitely, type `rw [add_zero]`!"
|
||||
rw [add_zero]
|
||||
Hint (hidden := true) "Finally both sides are identical."
|
||||
rfl
|
||||
|
||||
NewLemma MyNat.add_succ MyNat.add_zero
|
||||
NewDefinition Add
|
||||
|
||||
Conclusion
|
||||
"
|
||||
|
||||
Reference in New Issue
Block a user