pull/54/head
Jon Eugster 3 years ago
parent 6cd71c93fe
commit 6e8911e5da

@ -1,9 +1,35 @@
import GameServer.Commands
import NNG.Levels.Tutorial
import NNG.Levels.Addition
import NNG.Levels.Multiplication
import NNG.Levels.Power
import NNG.Levels.Function
import NNG.Levels.Proposition
import NNG.Levels.AdvProposition
import NNG.Levels.AdvAddition
import NNG.Levels.AdvMultiplication
import NNG.Levels.Inequality
Game "NNG"
World "HelloWorld"
Level 1
Title "Natural Number Game"
Introduction
"
[intro text missing]
## Credits
* Content and Lean3-version: Kevin Buzzard, Mohammad Pedramfar
* Game Engine: Alexander Bentkamp, Jon Eugster, Patrick Massot
* Port to Lean 4: Chris Lovett
## Resources
* [Original Lean3 version](https://www.ma.imperial.ac.uk/~buzzard/xena/natural_number_game/)
* [Chris' translation to lean4](https://lovettsoftware.com/NaturalNumbers/TutorialWorld/Level1.lean.html)
"
Statement : 1 + 1 = 2 := rfl
Path Tutorial → Addition → Function → Proposition → AdvProposition → AdvAddition
Path AdvAddition → AdvMultiplication → Inequality
Path Addition → Multiplication → AdvMultiplication
Path Multiplication → Power
MakeGame

@ -0,0 +1,6 @@
import GameServer.Commands
DefinitionDoc MyNat as ""
"
The Natural Numbers.
"

@ -0,0 +1,31 @@
import GameServer.Commands
LemmaDoc MyNat.add_zero as "add_zero" in "Nat"
""
LemmaDoc MyNat.add_succ as "add_succ" in "Nat"
""
LemmaDoc MyNat.zero_add as "zero_add" in "Nat"
""
LemmaDoc MyNat.add_assoc as "add_assoc" in "Nat"
""
LemmaDoc MyNat.succ_add as "succ_add" in "Nat"
""
LemmaDoc MyNat.add_comm as "add_comm" in "Nat"
""
LemmaDoc MyNat.one_eq_succ_zero as "one_eq_succ_zero" in "Nat"
""
LemmaDoc not_iff_imp_false as "not_iff_imp_false" in "Prop"
""
LemmaDoc MyNat.succ_inj as "succ_inj" in "Nat"
""
LemmaDoc MyNat.zero_ne_succ as "zero_ne_succ" in "Nat"
""

@ -0,0 +1,57 @@
import GameServer.Commands
TacticDoc rfl
"
"
TacticDoc rewrite
"
"
TacticDoc rw
"
"
TacticDoc induction
"
"
TacticDoc exact
"
"
TacticDoc apply
"
"
TacticDoc intro
"
"
TacticDoc «have»
"
"
TacticDoc constructor
"
"
TacticDoc rcases
"
"
TacticDoc left
"
"
TacticDoc right
"
"
TacticDoc contradiction
"
"
TacticDoc exfalso
"
"

@ -0,0 +1,42 @@
import NNG.Levels.Addition.Level_1
import NNG.Levels.Addition.Level_2
import NNG.Levels.Addition.Level_3
import NNG.Levels.Addition.Level_4
import NNG.Levels.Addition.Level_5
import NNG.Levels.Addition.Level_6
Game "NNG"
World "Addition"
Title "Addition World"
Introduction
"
Welcome to Addition World. If you've done all four levels in tutorial world
and know about `rewrite` and `rfl`, then you're in the right place. Here's
a reminder of the things you're now equipped with which we'll need in this world.
## Data:
* a type called `` or `MyNat`.
* a term `0 : `, interpreted as the number zero.
* a function `succ : `, with `succ n` interpreted as \"the number after `n`\".
* Usual numerical notation `0,1,2` etc. (although `2` onwards will be of no use to us until much later ;-) ).
* Addition (with notation `a + b`).
## Theorems:
* `add_zero (a : ) : a + 0 = a`. Use with `rewrite [add_zero]`.
* `add_succ (a b : ) : a + succ(b) = succ(a + b)`. Use with `rewrite [add_succ]`.
* The principle of mathematical induction. Use with `induction` (which we learn about in this chapter).
## Tactics:
* `rfl` : proves goals of the form `X = X`.
* `rewrite [h]` : if `h` is a proof of `A = B`, changes all `A`'s in the goal to `B`'s.
* `induction n with d hd` : we're going to learn this right now.
You will also find all this information in your Inventory to read the documentation.
"

@ -0,0 +1,93 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Addition"
Level 1
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
```
zero_add (n : ) : 0 + n = n
```
Wait… what is going on here? Didn't we already prove that adding zero to $n$ gave us $n$?
No we didn't! We proved $n + 0 = n$, and that proof was called `add_zero`. We're now
trying to establish `zero_add`, the proof that $0 + n = n$.
But aren't these two theorems the same?
No they're not! It is *true* that `x + y = y + x`, but we haven't *proved* it yet,
and in fact we will need both `add_zero` and `zero_add` in order
to prove this. In fact `x + y = y + x` is the boss level for addition world,
and `induction` is the only other tactic you'll need to beat it.
Now `add_zero` is one of Peano's axioms, so we don't need to prove it, we already have it.
To prove `0 + n = n` we need to use induction on $n$. While we're here,
note that `zero_add` is about zero add something, and `add_zero` is about something add zero.
The names of the proofs tell you what the theorems are. Anyway, let's prove `0 + n = n`.
"
Statement zero_add
"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:
`induction n with d hd`.
If you use the `with` part, you can name your variable and induction hypothesis, otherwise
they get default names."
induction n with n hn
· Hint "Now you have two goals. Once you proved the first, you will jump to the second one.
This first goal is the base case $n = 0$.
Recall that you can use all lemmas that are visible in your inventory."
Hint (hidden := true) "try using `add_zero`."
rw [add_zero]
rfl
· Hint "Now you jumped to the second goal. Here you have the induction hypothesis
`{hn} : 0 + {n} = {n}` and you need to prove the statement for `succ {n}`."
Hint (hidden := true) "look at `add_succ`."
rw [add_succ]
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
NewTactic induction
Conclusion
"
## Now venture off on your own.
Those three tactics:
* `induction n with d hd`
* `rw [h]`
* `rfl`
will get you quite a long way through this game. Using only these tactics
you can beat Addition World level 4 (the boss level of Addition World),
all of Multiplication World including the boss level `a * b = b * a`,
and even all of Power World including the fiendish final boss. This route will
give you a good grounding in these three basic tactics; after that, if you
are still interested, there are other worlds to master, where you can learn
more tactics.
But we're getting ahead of ourselves, you still have to beat the rest of Addition World.
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.
Good luck! Click on \"Next\" to solve some levels on your own.
"

@ -0,0 +1,70 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Addition"
Level 2
Title "add_assoc (associativity of addition)"
open MyNat
theorem MyNat.zero_add (n : ) : 0 + n = n := by
induction n with n hn
· rw [add_zero]
rfl
· rw [add_succ]
rw [hn]
rfl
Introduction
"
It's well-known that $(1 + 2) + 3 = 1 + (2 + 3)$; if we have three numbers
to add up, it doesn't matter which of the additions we do first. This fact
is called *associativity of addition* by mathematicians, and it is *not*
obvious. For example, subtraction really is not associative: $(6 - 2) - 1$
is really not equal to $6 - (2 - 1)$. We are going to have to prove
that addition, as defined the way we've defined it, is associative.
See if you can prove associativity of addition.
"
Statement 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
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!).
Note that when Lean writes `a + b + c`, it means `(a + b) + c`. If it wants to talk
about `a + (b + c)` it will put the brackets in explictly."
Branch
induction a
Hint "Good luck with that…"
rw [zero_add, zero_add]
rfl
Branch
induction b
Hint "Good luck with that…"
induction c with c hc
Hint (hidden := true) "look at the lemma `add_zero`."
rw [add_zero]
Hint "`rw [add_zero]` only rewrites one term of the form `… + 0`, so you might to
use it multiple times."
rw [add_zero]
rfl
Hint (hidden := true) "`add_succ` might help here."
rw [add_succ]
rw [add_succ]
rw [add_succ]
Hint (hidden := true) "Now you can use the induction hypothesis."
rw [hc]
rfl
Conclusion
"
"
NewLemma MyNat.zero_add

@ -0,0 +1,66 @@
import NNG.Metadata
import NNG.MyNat.Addition
import NNG.Levels.Addition.Level_2
Game "NNG"
World "Addition"
Level 3
Title "succ_add"
open MyNat
theorem MyNat.add_assoc (a b c : ) : (a + b) + c = a + (b + c) := by
induction c with c hc
· rw [add_zero]
rw [add_zero]
rfl
· rw [add_succ]
rw [add_succ]
rw [add_succ]
rw [hc]
rfl
Introduction
"
Oh no! On the way to `add_comm`, a wild `succ_add` appears. `succ_add`
is the proof that `succ(a) + b = succ(a + b)` for `a` and `b` in your
natural number type. We need to prove this now, because we will need
to use this result in our proof that `a + b = b + a` in the next level.
NB: think about why computer scientists called this result `succ_add` .
There is a logic to all the names.
Note that if you want to be more precise about exactly where you want
to rewrite something like `add_succ` (the proof you already have),
you can do things like `rw [add_succ (succ a)]` or
`rw [add_succ (succ a) d]`, telling Lean explicitly what to use for
the input variables for the function `add_succ`. Indeed, `add_succ`
is a function: it takes as input two variables `a` and `b` and outputs a proof
that `a + succ(b) = succ(a + b)`. The tactic `rw [add_succ]` just says to Lean \"guess
what the variables are\".
"
Statement succ_add
"For all natural numbers $a, b$, we have
$ \\operatorname{succ}(a) + b = \\operatorname{succ}(a + b)$."
(a b : ) : succ a + b = succ (a + b) := by
Hint (hidden := true) "You might again want to start by induction
on the right-most variable."
Branch
induction a
Hint "Induction on `a` will not work."
induction b with d hd
· rw [add_zero]
rfl
· rw [add_succ]
rw [hd]
rw [add_succ]
rfl
NewLemma MyNat.add_assoc
Conclusion
"
"

@ -0,0 +1,60 @@
import NNG.Metadata
import NNG.MyNat.Addition
import NNG.Levels.Addition.Level_3
Game "NNG"
World "Addition"
Level 4
Title "`add_comm` (boss level)"
open MyNat
theorem MyNat.succ_add (a b : ) : succ a + b = succ (a + b) := by
induction b with d hd
· rw [add_zero]
rfl
· rw [add_succ]
rw [hd]
rw [add_succ]
rfl
Introduction
"
[boss battle music]
Look in your inventory to see the proofs you have available.
These should be enough.
"
Statement add_comm
"On the set of natural numbers, addition is commutative.
In other words, for all natural numbers $a$ and $b$, we have
$a + b = b + a$."
(a b : ) : a + b = b + a := by
Branch
induction a with d hd
· rw [zero_add]
rw [add_zero]
rfl
· rw [succ_add]
rw [hd]
rw [add_succ]
rfl
induction b with d hd
· rw [zero_add]
rw [add_zero]
rfl
· rw [add_succ]
rw [hd]
rw [succ_add]
rfl
NewLemma MyNat.succ_add
Conclusion
"
If you got this far -- nice! You're nearly ready to make a choice:
Multiplication World or Function World. But there are just a couple
more useful lemmas in Addition World which you should prove first.
Press on to level 5.
"

@ -0,0 +1,54 @@
import NNG.Metadata
import NNG.MyNat.Addition
import NNG.Levels.Addition.Level_4
Game "NNG"
World "Addition"
Level 5
Title "succ_eq_add_one"
open MyNat
theorem MyNat.add_comm (a b : ) : a + b = b + a := by
induction b with d hd
· rw [zero_add]
rw [add_zero]
rfl
· rw [add_succ]
rw [hd]
rw [succ_add]
rfl
theorem MyNat.one_eq_succ_zero : (1 : ) = succ 0 := by
rfl
NewLemma MyNat.add_comm MyNat.one_eq_succ_zero
Introduction
"
I've just added `one_eq_succ_zero` (a proof of $1 = \\operatorname{succ}(0)$)
to your list of theorems; this is true
by definition of $1$, but we didn't need it until now.
Levels 5 and 6 are the two last levels in Addition World.
Level 5 involves the number $1$. When you see a $1$ in your goal,
you can write `rw [one_eq_succ_zero]` to get back
to something which only mentions `0`. This is a good move because $0$ is easier for us to
manipulate than $1$ right now, because we have
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 succ_eq_add_one
"For any natural number $n$, we have
$ \\operatorname{succ}(n) = n+1$ ."
(n : ) : succ n = n + 1 := by
rw [one_eq_succ_zero]
rw [add_succ]
rw [add_zero]
rfl
Conclusion
"
Well done! On to the last level!
"

@ -0,0 +1,47 @@
import NNG.Metadata
import NNG.MyNat.Addition
import NNG.Levels.Addition.Level_5
Game "NNG"
World "Addition"
Level 6
Title "add_right_comm"
open MyNat
Introduction
"
Lean sometimes writes `a + b + c`. What does it mean? The convention is
that if there are no brackets displayed in an addition formula, the brackets
are around the left most `+` (Lean's addition is \"left associative\").
So the goal in this level is `(a + b) + c = (a + c) + b`. This isn't
quite `add_assoc` or `add_comm`, it's something you'll have to prove
by putting these two theorems together.
If you hadn't picked up on this already, `rw [add_assoc]` will
change `(x + y) + z` to `x + (y + z)`, but to change it back
you will need `rw [← add_assoc]`. Get the left arrow by typing `\\l`
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
"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
rw [add_assoc]
rw [add_comm b c]
rw [←add_assoc]
rfl
Conclusion
"
"

@ -0,0 +1,22 @@
import NNG.Levels.AdvAddition.Level_1
import NNG.Levels.AdvAddition.Level_2
import NNG.Levels.AdvAddition.Level_3
import NNG.Levels.AdvAddition.Level_4
import NNG.Levels.AdvAddition.Level_5
import NNG.Levels.AdvAddition.Level_6
import NNG.Levels.AdvAddition.Level_7
import NNG.Levels.AdvAddition.Level_8
import NNG.Levels.AdvAddition.Level_9
import NNG.Levels.AdvAddition.Level_10
import NNG.Levels.AdvAddition.Level_11
import NNG.Levels.AdvAddition.Level_12
import NNG.Levels.AdvAddition.Level_13
Game "NNG"
World "AdvAddition"
Title "Advanced Addition World"
Introduction
"
"

@ -0,0 +1,30 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 1
Title ""
open MyNat
Introduction
"
"
theorem MyNat.succ_inj {a b : } : succ a = succ b → a = b := by simp only [succ.injEq, imp_self]
theorem MyNat.zero_ne_succ (a : ) : zero ≠ succ a := by simp only [ne_eq, not_false_iff]
Statement succ_inj'
""
{a b : } (hs : succ a = succ b) : a = b := by
exact succ_inj hs
NewLemma MyNat.succ_inj MyNat.zero_ne_succ
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 10
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 11
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 12
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 13
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 2
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 3
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 4
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 5
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 6
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 7
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 8
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvAddition"
Level 9
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,13 @@
import NNG.Levels.AdvMultiplication.Level_1
import NNG.Levels.AdvMultiplication.Level_2
import NNG.Levels.AdvMultiplication.Level_3
import NNG.Levels.AdvMultiplication.Level_4
Game "NNG"
World "AdvMultiplication"
Title "Advanced Multiplication World"
Introduction
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvMultiplication"
Level 1
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvMultiplication"
Level 2
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvMultiplication"
Level 3
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvMultiplication"
Level 4
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,19 @@
import NNG.Levels.AdvProposition.Level_1
import NNG.Levels.AdvProposition.Level_2
import NNG.Levels.AdvProposition.Level_3
import NNG.Levels.AdvProposition.Level_4
import NNG.Levels.AdvProposition.Level_5
import NNG.Levels.AdvProposition.Level_6
import NNG.Levels.AdvProposition.Level_7
import NNG.Levels.AdvProposition.Level_8
import NNG.Levels.AdvProposition.Level_9
import NNG.Levels.AdvProposition.Level_10
Game "NNG"
World "AdvProposition"
Title "Advanced Proposition World"
Introduction
"
"

@ -0,0 +1,28 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "AdvProposition"
Level 1
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q : Prop) (p : P) (q : Q) : P ∧ Q := by
constructor
exact p
exact q
NewTactic constructor
Conclusion
"
"

@ -0,0 +1,36 @@
import NNG.Metadata
import NNG.MyNat.Addition
import Std.Tactic.RCases
Game "NNG"
World "AdvProposition"
Level 10
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q : Prop) : (¬ Q → ¬ P) → (P → Q) := by
by_cases p : P
· by_cases q : Q
intro h p' -- cc
assumption
intro h p'
have g : ¬ P := h q
contradiction
· by_cases q : Q
intro h p
assumption
intro h p
contradiction
Conclusion
"
"

@ -0,0 +1,33 @@
import NNG.Metadata
import NNG.MyNat.Addition
import Std.Tactic.RCases
Game "NNG"
World "AdvProposition"
Level 2
Title ""
open MyNat
Introduction
"
"
set_option tactic.hygienic false
Statement and_symm
""
(P Q : Prop) : P ∧ Q → Q ∧ P := by
intro h
rcases h with ⟨p, q⟩
constructor
exact q
exact p
NewTactic rcases
Conclusion
"
"

@ -0,0 +1,31 @@
import NNG.Metadata
import NNG.MyNat.Addition
import Std.Tactic.RCases
Game "NNG"
World "AdvProposition"
Level 3
Title ""
open MyNat
Introduction
"
"
Statement and_trans
""
(P Q R : Prop) : P ∧ Q → Q ∧ R → P ∧ R := by
intro hpq
intro hqr
rcases hpq with ⟨p, q⟩
rcases hqr with ⟨q', r⟩
constructor
assumption
assumption
Conclusion
"
"

@ -0,0 +1,31 @@
import NNG.Metadata
import NNG.MyNat.Addition
import Std.Tactic.RCases
Game "NNG"
World "AdvProposition"
Level 4
Title ""
open MyNat
Introduction
"
"
Statement iff_trans
""
(P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) := by
intro hpq
intro hqr
rcases hpq with ⟨hpq, hqp⟩
rcases hqr with ⟨hqr, hrq⟩
constructor
exact fun x => hqr (hpq x) -- cc
exact fun x => hqp (hrq x) -- cc
Conclusion
"
"

@ -0,0 +1,34 @@
import NNG.Metadata
import NNG.MyNat.Addition
import Std.Tactic.RCases
Game "NNG"
World "AdvProposition"
Level 5
Title ""
open MyNat
Introduction
"
"
Statement iff_trans
""
(P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) := by
intro hpq hqr
constructor
intro p
apply hqr.1
apply hpq.1
assumption
intro r
apply hpq.2
apply hqr.2
assumption
Conclusion
"
"

@ -0,0 +1,31 @@
import NNG.Metadata
import NNG.MyNat.Addition
import Std.Tactic.RCases
import Mathlib.Tactic.LeftRight
--import Mathlib.Logic.Basic
Game "NNG"
World "AdvProposition"
Level 6
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q : Prop) : Q → (P Q) := by
intro q
right
assumption
NewTactic left right
Conclusion
"
"

@ -0,0 +1,31 @@
import NNG.Metadata
import NNG.MyNat.Addition
import Std.Tactic.RCases
import Mathlib.Tactic.LeftRight
Game "NNG"
World "AdvProposition"
Level 7
Title ""
open MyNat
Introduction
"
"
Statement or_symm
""
(P Q : Prop) : P Q → Q P := by
intro h
rcases h with p | q
right
exact p
left
exact q
Conclusion
"
"

@ -0,0 +1,49 @@
import NNG.Metadata
import NNG.MyNat.Addition
import Std.Tactic.RCases
import Mathlib.Tactic.LeftRight
Game "NNG"
World "AdvProposition"
Level 8
Title ""
open MyNat
Introduction
"
"
Statement and_or_distrib_left
""
(P Q R : Prop) : P ∧ (Q R) ↔ (P ∧ Q) (P ∧ R) := by
constructor
intro h
rcases h with ⟨hp, hqr⟩
rcases hqr with q | r
left
constructor
assumption
assumption
right
constructor
assumption
assumption
intro h
rcases h with hpq | hpr
rcases hpq with ⟨p, q⟩
constructor
assumption
left
assumption
rcases hpr with ⟨hp, hr⟩
constructor
assumption
right
assumption
Conclusion
"
"

@ -0,0 +1,36 @@
import NNG.Metadata
import NNG.MyNat.Addition
import Std.Tactic.RCases
import NNG.MyNat.Theorems.Proposition
Game "NNG"
World "AdvProposition"
Level 9
Title ""
open MyNat
Introduction
"
"
Statement contra
""
(P Q : Prop) : (P ∧ ¬ P) → Q := by
intro h
rcases h with ⟨p, np ⟩
contradiction
-- rw [not_iff_imp_false] at np
-- exfalso
-- apply np
-- exact p
NewTactic exfalso contradiction
Conclusion
"
"

@ -0,0 +1,18 @@
import NNG.Levels.Function.Level_1
import NNG.Levels.Function.Level_2
import NNG.Levels.Function.Level_3
import NNG.Levels.Function.Level_4
import NNG.Levels.Function.Level_5
import NNG.Levels.Function.Level_6
import NNG.Levels.Function.Level_7
import NNG.Levels.Function.Level_8
import NNG.Levels.Function.Level_9
Game "NNG"
World "Function"
Title "Function World"
Introduction
"
"

@ -0,0 +1,27 @@
import NNG.Metadata
import NNG.MyNat.Theorems.Addition
import NNG.MyNat.Multiplication
Game "NNG"
World "Function"
Level 1
Title ""
open MyNat
Introduction
"
"
Statement
"If $P$ is true, and $P\\implies Q$ is also true, then $Q$ is true."
(P Q : Prop) (p : P) (h : P → Q) : Q := by
exact h p
NewTactic exact
Conclusion
"
"

@ -0,0 +1,28 @@
import NNG.Metadata
import NNG.MyNat.Theorems.Addition
import NNG.MyNat.Multiplication
Game "NNG"
World "Function"
Level 2
Title ""
open MyNat
Introduction
"
"
Statement
""
: := by
intro n
exact 3 * n + 2
NewTactic intro
Conclusion
"
"

@ -0,0 +1,31 @@
import NNG.Metadata
import NNG.MyNat.Theorems.Addition
import NNG.MyNat.Multiplication
Game "NNG"
World "Function"
Level 3
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q R S T U: Type) (p : P) (h : P → Q) (i : Q → R) (j : Q → T) (k : S → T) (l : T → U) :
U := by
have q := h p
have t : T := j q
have u : U := l t
exact u
NewTactic «have»
Conclusion
"
"

@ -0,0 +1,37 @@
import NNG.Metadata
import NNG.MyNat.Theorems.Addition
import NNG.MyNat.Multiplication
Game "NNG"
World "Function"
Level 4
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q R S T U: Type)
(p : P)
(h : P → Q)
(i : Q → R)
(j : Q → T)
(k : S → T)
(l : T → U) : U :=
by
apply l
apply j
apply h
exact p
NewTactic apply
Conclusion
"
"

@ -0,0 +1,27 @@
import NNG.Metadata
import NNG.MyNat.Theorems.Addition
import NNG.MyNat.Multiplication
Game "NNG"
World "Function"
Level 5
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q : Type) : P → (Q → P) := by
intro p
intro q
exact p
Conclusion
"
"

@ -0,0 +1,30 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Function"
Level 6
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q R : Type) : (P → (Q → R)) → ((P → Q) → (P → R)) := by
intro f
intro h
intro p
have j : Q → R := f p
apply j
apply h
exact p
Conclusion
"
"

@ -0,0 +1,29 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Function"
Level 7
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q F : Type) : (P → Q) → ((Q → F) → (P → F)) := by
intro f
intro h
intro p
apply h
apply f
exact p
Conclusion
"
"

@ -0,0 +1,27 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Function"
Level 8
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q : Type) : (P → Q) → ((Q → empty) → (P → empty)) := by
intros f h p
apply h
apply f
exact p
Conclusion
"
"

@ -0,0 +1,36 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Function"
Level 9
Title ""
open MyNat
Introduction
"
"
Statement
""
(A B C D E F G H I J K L : Type)
(f1 : A → B) (f2 : B → E) (f3 : E → D) (f4 : D → A) (f5 : E → F)
(f6 : F → C) (f7 : B → C) (f8 : F → G) (f9 : G → J) (f10 : I → J)
(f11 : J → I) (f12 : I → H) (f13 : E → H) (f14 : H → K) (f15 : I → L) : A → L := by
intro a
apply f15
apply f11
apply f9
apply f8
apply f5
apply f2
apply f1
exact a
Conclusion
"
"

@ -0,0 +1,25 @@
import NNG.Levels.Inequality.Level_1
import NNG.Levels.Inequality.Level_2
import NNG.Levels.Inequality.Level_3
import NNG.Levels.Inequality.Level_4
import NNG.Levels.Inequality.Level_5
import NNG.Levels.Inequality.Level_6
import NNG.Levels.Inequality.Level_7
import NNG.Levels.Inequality.Level_8
import NNG.Levels.Inequality.Level_9
import NNG.Levels.Inequality.Level_10
import NNG.Levels.Inequality.Level_11
import NNG.Levels.Inequality.Level_12
import NNG.Levels.Inequality.Level_13
import NNG.Levels.Inequality.Level_14
import NNG.Levels.Inequality.Level_15
import NNG.Levels.Inequality.Level_16
import NNG.Levels.Inequality.Level_17
Game "NNG"
World "Inequality"
Title "Inequality World"
Introduction
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 1
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 10
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 11
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 12
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 13
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 14
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 15
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 16
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 17
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 2
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 3
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 4
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 5
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 6
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 7
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 8
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Inequality"
Level 9
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,18 @@
import NNG.Levels.Multiplication.Level_1
import NNG.Levels.Multiplication.Level_2
import NNG.Levels.Multiplication.Level_3
import NNG.Levels.Multiplication.Level_4
import NNG.Levels.Multiplication.Level_5
import NNG.Levels.Multiplication.Level_6
import NNG.Levels.Multiplication.Level_7
import NNG.Levels.Multiplication.Level_8
import NNG.Levels.Multiplication.Level_9
Game "NNG"
World "Multiplication"
Title "Multiplication World"
Introduction
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Multiplication"
Level 1
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Multiplication"
Level 2
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Multiplication"
Level 3
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Multiplication"
Level 4
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Multiplication"
Level 5
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Multiplication"
Level 6
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Multiplication"
Level 7
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Multiplication"
Level 8
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Multiplication"
Level 9
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,16 @@
import NNG.Levels.Power.Level_1
import NNG.Levels.Power.Level_2
import NNG.Levels.Power.Level_3
import NNG.Levels.Power.Level_4
import NNG.Levels.Power.Level_5
import NNG.Levels.Power.Level_6
import NNG.Levels.Power.Level_7
import NNG.Levels.Power.Level_8
Game "NNG"
World "Power"
Title "Power World"
Introduction
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Power"
Level 1
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Power"
Level 2
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Power"
Level 3
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Power"
Level 4
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Power"
Level 5
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Power"
Level 6
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Power"
Level 7
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Power"
Level 8
Title ""
open MyNat
Introduction
"
"
Statement
""
: true := by
trivial
Conclusion
"
"

@ -0,0 +1,18 @@
import NNG.Levels.Proposition.Level_1
import NNG.Levels.Proposition.Level_2
import NNG.Levels.Proposition.Level_3
import NNG.Levels.Proposition.Level_4
import NNG.Levels.Proposition.Level_5
import NNG.Levels.Proposition.Level_6
import NNG.Levels.Proposition.Level_7
import NNG.Levels.Proposition.Level_8
-- import NNG.Levels.Proposition.Level_9 -- `cc` is not ported
Game "NNG"
World "Proposition"
Title "Proposition World"
Introduction
"
"

@ -0,0 +1,24 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Proposition"
Level 1
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q : Prop) (p : P) (h : P → Q) : Q := by
exact h p
Conclusion
"
"

@ -0,0 +1,25 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Proposition"
Level 2
Title ""
open MyNat
Introduction
"
"
Statement
""
: P → P := by
intro p
exact p
Conclusion
"
"

@ -0,0 +1,30 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Proposition"
Level 3
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q R S T U: Prop) (p : P) (h : P → Q) (i : Q → R)
(j : Q → T) (k : S → T) (l : T → U) : U := by
have q := h p
have t := j q
have u := l t
exact u
DisabledTactic apply
Conclusion
"
"

@ -0,0 +1,30 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Proposition"
Level 4
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q R S T U: Prop) (p : P) (h : P → Q) (i : Q → R)
(j : Q → T) (k : S → T) (l : T → U) : U := by
apply l
apply j
apply h
exact p
DisabledTactic «have»
Conclusion
"
"

@ -0,0 +1,27 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Proposition"
Level 5
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q : Prop) : P → (Q → P) := by
intro p
intro q
exact p
rfl
Conclusion
"
"

@ -0,0 +1,30 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Proposition"
Level 6
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q R : Prop) : (P → (Q → R)) → ((P → Q) → (P → R)) := by
intro f
intro h
intro p
have j : Q → R := f p
apply j
apply h
exact p
Conclusion
"
"

@ -0,0 +1,28 @@
import NNG.Metadata
import NNG.MyNat.Addition
Game "NNG"
World "Proposition"
Level 7
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q R : Prop) : (P → Q) → ((Q → R) → (P → R)) := by
intro hpq hqr
intro p
apply hqr
apply hpq
exact p
Conclusion
"
"

@ -0,0 +1,35 @@
import NNG.Metadata
import NNG.MyNat.Addition
import NNG.MyNat.Theorems.Proposition
Game "NNG"
World "Proposition"
Level 8
Title ""
open MyNat
Introduction
"
"
Statement
""
(P Q : Prop) : (P → Q) → (¬ Q → ¬ P) := by
rw [not_iff_imp_false]
rw [not_iff_imp_false]
intro f
intro h
intro p
apply h
apply f
exact p
NewLemma not_iff_imp_false
Conclusion
"
"

@ -0,0 +1,29 @@
import NNG.Metadata
import NNG.MyNat.Addition
import NNG.MyNat.Theorems.Proposition
Game "NNG"
World "Proposition"
Level 9
Title ""
open MyNat
Introduction
"
"
Statement
""
(A B C D E F G H I J K L : Prop)
(f1 : A → B) (f2 : B → E) (f3 : E → D) (f4 : D → A) (f5 : E → F)
(f6 : F → C) (f7 : B → C) (f8 : F → G) (f9 : G → J) (f10 : I → J)
(f11 : J → I) (f12 : I → H) (f13 : E → H) (f14 : H → K) (f15 : I → L) : A → L := by
-- cc -- TODO: `cc` is not ported yet.
sorry
Conclusion
"
"

@ -0,0 +1,12 @@
import NNG.Levels.Tutorial.Level_1
import NNG.Levels.Tutorial.Level_2
import NNG.Levels.Tutorial.Level_3
import NNG.Levels.Tutorial.Level_4
Game "NNG"
World "Tutorial"
Title "Tutorial World"
Introduction
"
"

@ -0,0 +1,42 @@
import NNG.Metadata
import NNG.MyNat.Multiplication
Game "NNG"
World "Tutorial"
Level 1
Title "The rfl tactic"
Introduction
"
Each level in this game involves proving a mathematical statement. In this first level
you have three natural numbers $x, y, z$ (listed under \"Objects\") and you want to prove
$x \\cdot y + z = x \\cdot y + z$ (displayed under \"Goal\").
You can modify the Goal using *Tactics* until you can close (i.e. prove) it.
The first tactic is called `rfl`, which stands for \"reflexivity\",
a fancy way of saying that it will prove any goal of the form `A = A`. It doesn't matter how
complicated `A` is, all that matters is that the left hand side is exactly equal to the right hand
side (a computer scientist would say \"definitionally equal\"). I really mean \"press the same buttons
on your computer in the same order\" equal. For example, `x * y + z = x * y + z` can be proved by `rfl`,
but `x + y = y + x` cannot.
"
Statement
"For all natural numbers $x, y$ and $z$, we have $xy + z = xy + z$."
(x y z : ) : x * y + z = x * y + z := by
Hint "In order to use the tactic `rfl` you can enter it above and hit \"Execute\"."
rfl
NewTactic rfl
NewDefinition MyNat
Conclusion
"
Congratulations! You completed your first verified proof!
If you want to be reminded about the `rfl` tactic, your inventory on the right contains useful
information about things you've learned.
Now click on \"Next\" to continue the journey.
"

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save