Dylan Cant
·
2026-10-27
1import Game.MyNat
2
3/-!
4# Tutorial World
5
6Each level is a theorem. The line `example (x y : ℕ) (h : y = x + 7) :
72 * y = 2 * (x + 7) := by` says: given numbers `x`, `y` and a hypothesis `h`
8that `y = x + 7`, prove the goal `2 * y = 2 * (x + 7)`. After `by` comes the
9proof: a list of *tactics*, one per line, each indented by two spaces. Each
10tactic changes the goal, and the level is done when no goal is left.
11
12At first each proof is `sorry`, a keyword that "proves" anything for free.
13Lean accepts it, with a warning. Replace it with a real proof. Put the cursor
14in a proof to see the current goal and hypotheses (see the README).
15
16Tactics in this world:
17* `rfl` proves a goal of the form `X = X`, where both sides are identical.
18* `rw [h]`, where `h : A = B`, replaces every `A` in the goal by `B`.
19 `rw [← h]` (type `\l` for `←`) goes the other way, `B` to `A`.
20 After rewriting, `rw` tries `rfl` by itself, so it often finishes the
21 level. A `rfl` after that fails with "no goals": delete it.
22* `rw [h₁, h₂]` is `rw [h₁]` followed by `rw [h₂]`.
23
24`rw` also takes theorems, such as `add_zero`, which says `a + 0 = a` for
25every `a`. `rw [add_zero]` rewrites the first `_ + 0` it finds, and every
26copy of that same sum. To pick another one, say which:
27`rw [add_zero c]` rewrites `c + 0` only.
28
29A level stated as `theorem name …` can be used in all the later levels, like
30`add_zero`; one stated as `example …` is only an exercise.
31-/
32
33namespace MyNat
34
35-- Level 1: both sides are the same, so `rfl` proves it.
36example (x q : ℕ) : 37 * x + q = 37 * x + q := by
37 sorry
38
39-- Level 2: the goal has a `y`, and `h` says what `y` is: `rw [h]`.
40example (x y : ℕ) (h : y = x + 7) : 2 * y = 2 * (x + 7) := by
41 sorry
42
43-- Level 3: numerals. `2` is defined as `succ 1`, and `1` as `succ 0`: the
44-- theorems `two_eq_succ_one : 2 = succ 1` and `one_eq_succ_zero : 1 = succ 0`
45-- (`three_eq_succ_two` and `four_eq_succ_three` too). Rewrite with them.
46example : 2 = succ (succ 0) := by
47 sorry
48
49-- Level 4: the same goal, rewriting backwards this time: turn `succ 0` into
50-- `1` with `rw [← one_eq_succ_zero]`, then `succ 1` into `2`.
51example : 2 = succ (succ 0) := by
52 sorry
53
54-- Level 5: `add_zero a : a + 0 = a`. Rewrite with it until both sides agree.
55example (a b c : ℕ) : a + (b + 0) + (c + 0) = a + b + c := by
56 sorry
57
58-- Level 6: the same goal, but now rewrite `c + 0` first, then `b + 0`:
59-- `rw [add_zero c]`.
60example (a b c : ℕ) : a + (b + 0) + (c + 0) = a + b + c := by
61 sorry
62
63-- Level 7: `add_succ a d : a + succ d = succ (a + d)`, the definition of
64-- addition. Write the `1` as `succ 0` first.
65theorem succ_eq_add_one (n : ℕ) : succ n = n + 1 := by
66 sorry
67
68-- Level 8: unfold both sides into `succ`s (start with the `4`, then the
69-- `3`, then all the `2`s at once), then use `add_succ` and `add_zero`.
70example : (2 : ℕ) + 2 = 4 := by
71 sorry
72
73end MyNat