-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'level-rewrite' of github.com:hhu-adam/NNG4 into level-r…
…ewrite
- Loading branch information
Showing
9 changed files
with
199 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ h2 : x+5y=6 | |
⊢ x=1 | ||
|
||
? | ||
|
||
example (x y : ℕ) (h1 : 2 * x + 3 * y = 5) (h2 : 4 * x + 5 * y = 9) : x = 1 := by |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Game.Levels.LessOrEqual.L04le_zero | ||
|
||
World "LessOrEqual" | ||
Level 5 | ||
Title "x ≤ y and y ≤ z implies x ≤ z" | ||
|
||
namespace MyNat | ||
|
||
Introduction " | ||
We have already proved that `x ≤ x`, i.e. that `≤` is *reflexive*. Now let's | ||
prove that it's *transitive*, i.e., that if `x ≤ y` and `y ≤ z` then `x ≤ z`. | ||
" | ||
|
||
LemmaDoc MyNat.le_trans as "le_trans" in "≤" " | ||
`le_trans x y z` is a proof that if `x ≤ y` and `y ≤ z` then `x ≤ z`. | ||
More precisely, it is a proof that `x ≤ y → (y ≤ z → x ≤ z)`. In words, | ||
If $x \\le y$ then (pause) if $y \\le z$ then $x \\le z$. | ||
## A note on associativity | ||
In Lean, `a + b + c` means `(a + b) + c`, because `+` is left associative. However | ||
`→` is right associative, meaning that `x ≤ y → y ≤ z → x ≤ z` means | ||
exactly that `≤` is transitive. | ||
" | ||
|
||
/-- If $x \leq y$ and $y \leq z$, then $x \leq z$. -/ | ||
Statement le_trans (x y z : ℕ) (hxy : x ≤ y) (hyz : y ≤ z) : x ≤ z := by | ||
Hint "If you start with `rcases hxy with ⟨a, ha⟩` then `ha` will be a proof that `y = x + a`. | ||
If you want to instead *define* `y` to be `x + a` then you can do `rcases hxy with ⟨a, rfl⟩`. | ||
This is a time-saving trick. " | ||
rcases hxy with ⟨a, rfl⟩ | ||
rcases hyz with ⟨b, rfl⟩ | ||
use a + b | ||
exact add_assoc x a b | ||
|
||
LemmaTab "≤" | ||
|
||
Conclusion " | ||
Here's a four line proof: | ||
``` | ||
rcases hxy with ⟨a, rfl⟩ | ||
rcases hyz with ⟨b, rfl⟩ | ||
use a + b | ||
exact add_assoc x a b | ||
``` | ||
A passing mathematician remarks that with reflexivity and transitivity out of the way, | ||
you have proved that `≤` is a *preorder* on `ℕ`. | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import Game.Levels.LessOrEqual.L05le_trans | ||
|
||
World "LessOrEqual" | ||
Level 6 | ||
Title "x ≤ y and y ≤ x implies x = y" | ||
|
||
namespace MyNat | ||
|
||
LemmaDoc MyNat.le_antisymm as "le_antisymm" in "≤" " | ||
`le_antisymm x y` is a proof that if `x ≤ y` and `y ≤ x` then `x = y`. | ||
" | ||
|
||
Introduction " | ||
This level asks you to prove *antisymmetry* of $\\leq$. | ||
In other words, if $x \\leq y$ and $y \\leq x$ then $x = y$. | ||
It's the trickiest one so far. Good luck! | ||
" | ||
|
||
/-- If $x \leq y$ and $y \leq x$, then $x = y$. -/ | ||
Statement le_antisymm (x y : ℕ) (hxy : x ≤ y) (hyx : y ≤ x) : x = y := by | ||
rcases hxy with ⟨a, rfl⟩ | ||
rcases hyx with ⟨b, hb⟩ | ||
rw [add_assoc] at hb | ||
symm at hb | ||
apply add_right_eq_self at hb | ||
apply eq_zero_of_add_right_eq_zero at hb | ||
rw [hb, add_zero] | ||
rfl | ||
|
||
LemmaTab "≤" | ||
|
||
Conclusion " | ||
Here's my proof: | ||
``` | ||
rcases hxy with ⟨a, rfl⟩ | ||
rcases hyx with ⟨b, hb⟩ | ||
rw [add_assoc] at hb | ||
symm at hb | ||
apply add_right_eq_self at hb | ||
apply eq_zero_of_add_right_eq_zero at hb | ||
rw [hb, add_zero] | ||
rfl | ||
``` | ||
A passing mathematician remarks that with antisymmetry as well, | ||
you have proved that `≤` is a *partial order* on `ℕ`. | ||
The next level, the boss level of this world, is to prove | ||
that `≤` is a total order. | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Game.Levels.LessOrEqual.L06le_antisymm | ||
|
||
World "LessOrEqual" | ||
Level 7 | ||
Title "x ≤ y or y ≤ x" | ||
|
||
namespace MyNat | ||
|
||
Introduction " | ||
This is I think the toughest level yet. We haven't talked about \"or\" at all, | ||
but here's everything you need to know. | ||
1) The notation for \"or\" is `∨`. You won't need to type it, but you can | ||
type it with `\\or`. | ||
2) If you have an \"or\" statement in the *goal*, then two tactics made | ||
progress: `left` and `right`. But don't choose a direction unless your | ||
hypotheses guarantee that it's the right one. | ||
3) If you have an \"or\" statement as a *hypothesis* `h`, then | ||
`rcases h with (h1 | h2)` will create two goals, one where you went left, | ||
and the other where you went right. | ||
" | ||
|
||
LemmaDoc MyNat.le_total as "le_total" in "≤" " | ||
`le_total x y` is a proof that `x ≤ y` or `y ≤ x`. | ||
" | ||
|
||
/-- If $x \leq y$ and $y \leq z$, then $x \leq z$. -/ | ||
Statement le_total (x y : ℕ) : x ≤ y ∨ y ≤ x := by | ||
induction y with d hd | ||
right | ||
exact zero_le x | ||
rcases hd with (h1 | h2) | ||
left | ||
rcases h1 with ⟨e, rfl⟩ | ||
use e + 1 | ||
rw [succ_eq_add_one, add_assoc] | ||
rfl | ||
rcases h2 with ⟨e, rfl⟩ | ||
rcases e with ⟨f⟩ | ||
left | ||
change d + 0 ≤ succ d | ||
rw [add_zero] | ||
use 1 | ||
exact succ_eq_add_one d | ||
right | ||
use a | ||
rw [add_succ, succ_add, add_comm] | ||
rfl | ||
|
||
|
||
|
||
|
||
LemmaTab "≤" | ||
|
||
Conclusion " | ||
Here's a four line proof: | ||
``` | ||
rcases hxy with ⟨a, rfl⟩ | ||
rcases hyz with ⟨b, rfl⟩ | ||
use a + b | ||
exact add_assoc x a b | ||
``` | ||
A passing mathematician remarks that with reflexivity and transitivity out of the way, | ||
you have proved that `≤` is a *preorder* on `ℕ`. | ||
" |
This file was deleted.
Oops, something went wrong.