Skip to content

Commit

Permalink
Merge branch 'level-rewrite' of github.com:hhu-adam/NNG4 into level-r…
Browse files Browse the repository at this point in the history
…ewrite
  • Loading branch information
kbuzzard committed Oct 14, 2023
2 parents 6ec6907 + 378acfd commit 124aaae
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 115 deletions.
2 changes: 2 additions & 0 deletions Game/Levels/AdvAddition/levels
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions Game/Levels/LessOrEqual.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import Game.Levels.LessOrEqual.L01le_refl
import Game.Levels.LessOrEqual.L02zero_le
import Game.Levels.LessOrEqual.L03le_succ_self
import Game.Levels.LessOrEqual.L04le_zero
import Game.Levels.LessOrEqual.L05le_trans
import Game.Levels.LessOrEqual.L06le_antisymm
import Game.Levels.LessOrEqual.L07le_total

World "LessOrEqual"
Title "≤ World"
Expand Down
7 changes: 5 additions & 2 deletions Game/Levels/LessOrEqual/L02zero_le.lean
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ how to prove `a ≤ b` is to `use b - a`. See how you get on with this level,
which proves that every number in the game is at least 0.
"

/-- If $x$ is a number, then $0 \\le x$. -/
Statement le_refl (x : ℕ) : 0 ≤ x := by
LemmaDoc MyNat.zero_le as "zero_le" in "≤" "
`zero_le x` is a proof that `0 ≤ x`."

/-- If $x$ is a number, then $0 \le x$. -/
Statement zero_le (x : ℕ) : 0 ≤ x := by
use x
rw [zero_add]
rfl
Expand Down
14 changes: 12 additions & 2 deletions Game/Levels/LessOrEqual/L03le_succ_self.lean
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ LemmaDoc MyNat.le_succ_self as "le_succ_self" in "≤" "
`le_succ_self x` is a proof that `x ≤ succ x`.
"

/-- If $x$ is a number, then $x \\le \\mathoperator{succ}(x)$. -/
Statement le_succ_self (x : ℕ) : x ≤ succ x := by
/-- If $x$ is a number, then $x \le \operatorname{succ}(x)$. -/
Statement (x : ℕ) : x ≤ succ x := by
use 1
rw [succ_eq_add_one]
rfl

LemmaTab "≤"

Conclusion "
Here's a two-liner:
```
use 1
exact succ_eq_add_one x
```
This works because `succ_eq_add_one x` is a proof of `succ x = x + 1`.
"

/-
Introduction
"
Expand Down
22 changes: 10 additions & 12 deletions Game/Levels/LessOrEqual/L04le_zero.lean
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,22 @@ LemmaDoc MyNat.le_zero as "le_zero" in "≤" "

Introduction "
In this level, our inequality is a *hypothesis*. We have not seen this before.
The `rcases` tactic can be used to take `hx` apart.
"

LemmaDoc MyNat.le_zero as "le_zero" in "≤"
"`le_zero x` is a proof of the implication `x ≤ 0 → x = 0`. "

/-- If $x \leq 0$, then $x=0$. -/
Statement le_zero (x : ℕ) (hx : x ≤ 0) : x = 0 := by
Hint "Start with `cases hx with y hy`. You can get the funny pointy brackets with `\\<` and
`\\>`, or `\\<>` will give you both at once."
cases hx with y hy
Hint "Now `y` is what you have to add to `x` to get `0`, and `hy` is the proof of this."
Hint (hidden := true) "You want to use `eq_zero_of_add_right_eq_zero`, which you already
proved, but you'll have to start with `symm at hy`."
symm at hy
apply eq_zero_of_add_right_eq_zero at hy
exact hy

LemmaTab "≤"

/-
Introduction
"
Because constanly rewriting `zero_add` and `add_zero` is a bit dull,
let's unlock the `ring` tactic. This will prove any goal which is \"true
in the language of ring theory\", for example `a + b + c = c + b + a`.
It doesn't understand `succ` though, so use `succ_eq_add_one` in this
level to get rid of it.
"
-/
49 changes: 49 additions & 0 deletions Game/Levels/LessOrEqual/L05le_trans.lean
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 `ℕ`.
"
50 changes: 50 additions & 0 deletions Game/Levels/LessOrEqual/L06le_antisymm.lean
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.
"
68 changes: 68 additions & 0 deletions Game/Levels/LessOrEqual/L07le_total.lean
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 `ℕ`.
"
99 changes: 0 additions & 99 deletions Game/Levels/LessOrEqual/all_levels.lean

This file was deleted.

0 comments on commit 124aaae

Please sign in to comment.