Natural Number Game Sol
https://adam.math.hhu.de/#/g/leanprover-community/nng4
Tutorial World
Level 1 / 8 : The rfl tactic
rfl
Level 2 / 8 : the rw tactic
rw[h]
rfl
Level 3 / 8 : Numbers
rw[two_eq_succ_one]
rw[one_eq_succ_zero]
rfl
Level 4 / 8 : rewriting backwards
rw[← one_eq_succ_zero]
rw[← two_eq_succ_one]
rfl
Level 5 / 8 : Adding zero
rw[add_zero b]
rw[add_zero c]
rfl
Level 6 / 8 : Precision rewriting
rw[add_zero b]
rw[add_zero c]
rfl
Level 7 / 8 : add_succ
rw[one_eq_succ_zero]
rw[add_succ]
rw[add_zero]
rfl
Level 8 / 8 : 2+2=4
nth_rewrite 2 [two_eq_succ_one]
rw[add_succ 2]
nth_rewrite 1 [one_eq_succ_zero]
rw[add_succ 2]
rw[add_zero 2]
rw[<- three_eq_succ_two]
rw[<- four_eq_succ_three]
rfl
Addition World
Level 1 / 5 : zero_add
induction n with d hd
rw[add_zero]
rfl
rw[add_succ 0]
rw[hd]
rfl
Level 2 / 5 : succ_add
induction b with d hd
rw[succ_eq_add_one]
rw[succ_eq_add_one]
rw[add_zero]
rw[add_zero]
rfl
rw[add_succ]
rw[add_succ]
rw[hd]
rfl
Level 3 / 5 : add_comm (level boss)
induction b with d hd
rw[add_zero]
rw[zero_add]
rfl
rw[add_succ]
rw[hd]
rw[succ_add]
rfl
Level 4 / 5 : add_assoc (associativity of addition)
induction b with d hd
rw[add_zero]
rw[zero_add]
rfl
rw[succ_add]
rw[add_succ]
rw[succ_add]
rw[add_succ]
rw[hd]
rfl
Level 5 / 5 : add_right_comm
induction b with d hd
rw[add_zero]
rw[add_zero]
rfl
rw[add_succ]
rw[succ_add]
rw[hd]
rw[add_succ]
rfl
Multiplication World
Level 1 / 9 : mul_one
rw[one_eq_succ_zero]
rw[mul_succ]
rw[mul_zero]
rw[zero_add]
rfl
Level 2 / 9 : zero_mul
induction m with d hd
rw[mul_zero]
rfl
rw[mul_succ]
rw[hd]
rw[add_zero]
rfl
Level 3 / 9 : succ_mul
induction b with d hd
rw[mul_zero]
rw[mul_zero]
rw[add_zero]
rfl
rw[mul_succ]
rw[mul_succ]
rw[hd]
rw[add_assoc]
rw[add_comm]
nth_rewrite 2 [add_assoc]
nth_rewrite 3 [add_comm]
rw[succ_eq_add_one]
rw[succ_eq_add_one]
rw[← add_assoc]
rw[← add_assoc]
rw[add_assoc]
rw[add_comm]
nth_rewrite 3 [add_comm]
rw[add_comm]
rw[← add_assoc]
rfl
Level 4 / 9 : mul_comm
induction b with d hd
rw[mul_zero]
rw[zero_mul]
rfl
rw[succ_mul]
rw[mul_succ]
rw[hd]
rfl
Level 5 / 9 : one_mul
rw[mul_comm, mul_one]
rfl
Level 6 / 9 : two_mul
rw[mul_comm]
rw[two_eq_succ_one]
rw[mul_succ]
rw[mul_one]
rfl
Level 7 / 9 : mul_add
induction a with d hd
rw[zero_mul]
rw[zero_mul]
rw[zero_mul]
rw[add_zero]
rfl
rw[succ_mul]
rw[succ_mul]
rw[succ_mul]
rw[hd]
nth_rewrite 2 [← add_assoc]
nth_rewrite 1 [← add_assoc]
nth_rewrite 2 [add_right_comm]
rfl
Level 8 / 9 : add_mul
rw[mul_comm]
rw[mul_add]
rw[mul_comm]
nth_rewrite 2 [mul_comm]
rfl
Level 9 / 9 : mul_assoc
induction c with d hd
repeat rw[mul_zero]
rfl
rw[mul_succ]
rw[mul_succ]
rw[hd]
rw[mul_add]
rfl
Implication World
Level 1 / 11 : The exact tactic
exact h1
Level 2 / 11 : exact practice.
rw[zero_add] at h
rw[zero_add] at h
exact h
Level 3 / 11 : The apply tactic.
apply h2 at h1
exact h1
Level 4 / 11 : succ_inj : the successor function is injective
rw[four_eq_succ_three] at h
rw[← succ_eq_add_one] at h
apply succ_inj at h
exact h
Level 5 / 11 : Arguing backwards
apply succ_inj
rw[succ_eq_add_one]
rw[← four_eq_succ_three]
exact h
Level 6 / 11 : intro
intro h
exact h
Level 7 / 11 : intro practice
intro h
rw[← succ_eq_add_one] at h
rw[← succ_eq_add_one] at h
apply succ_inj at h
exact h
Level 8 / 11 : ≠
apply h2 at h1
exact h1
Level 9 / 11 : zero_ne_succ
rw[one_eq_succ_zero]
apply zero_ne_succ
Level 10 / 11 : 1 ≠ 0
intro h
symm at h
apply zero_ne_one at h
exact h
Level 11 / 11 : 2 + 2 ≠ 5
rw[add_succ]
rw[add_succ]
rw[add_zero]
intro h
apply succ_inj at h
apply succ_inj at h
apply succ_inj at h
apply succ_inj at h
apply zero_ne_succ at h
exact h
Power World
Level 1 / 10 : zero_pow_zero
rw[pow_zero]
rfl
Level 2 / 10 : zero_pow_succ
rw[pow_succ]
rw[mul_zero]
rfl
Level 3 / 10 : pow_one
rw[one_eq_succ_zero]
rw[pow_succ]
rw[pow_zero]
rw[one_mul]
rfl
Level 4 / 10 : one_pow
induction m with d hd
rw[pow_zero]
rfl
rw[pow_succ]
rw[hd]
rw[mul_one]
rfl
Level 5 / 10 : pow_two
rw[two_eq_succ_one]
rw[pow_succ]
rw[pow_one]
rfl
Level 6 / 10 : pow_add
induction n with d hd
rw[add_zero, pow_zero, mul_one]
rfl
rw[pow_succ,succ_eq_add_one,← add_assoc, ← succ_eq_add_one]
rw[pow_succ, hd, mul_assoc]
rfl
Level 7 / 10 : mul_pow
induction n with d hd
rw[pow_zero, pow_zero, pow_zero, mul_one]
rfl
rw[pow_succ, pow_succ, pow_succ, hd]
nth_rewrite 3 [mul_comm]
nth_rewrite 2 [mul_assoc]
nth_rewrite 5 [mul_comm]
nth_rewrite 2 [← mul_assoc]
nth_rewrite 2 [← mul_assoc]
nth_rewrite 1 [← mul_assoc]
rfl
Level 8 / 10 : pow_pow
induction n with d hd
rw[pow_zero]
rw[mul_zero]
rw[pow_zero]
rfl
rw[pow_succ]
rw[hd]
rw[mul_succ]
rw[pow_add]
rfl
Level 9 / 10 : add_sq
rw[pow_two]
rw[mul_add]
rw[add_mul]
rw[add_mul]
rw[← pow_two]
rw[← pow_two]
rw[← add_right_comm]
nth_rewrite 3 [add_comm]
rw[add_assoc]
nth_rewrite 2 [mul_comm]
rw[add_assoc]
rw[← add_mul]
rw[← two_mul]
rw[← add_assoc]
rfl
Level 10 / 10 : Fermat's Last Theorem
不会.
Advanced Addition World
Level 1 / 6 : add_right_cancel
induction n with d hd
rw[add_zero]
rw[add_zero]
intro h
exact h
rw[add_succ]
rw[add_succ]
intro hh
apply succ_inj at hh
apply hd at hh
exact hh
Level 2 / 6 : add_left_cancel
induction n with d hd
rw[zero_add]
rw[zero_add]
intro h
exact h
rw[succ_eq_add_one]
rw[add_right_comm]
rw[add_right_comm d 1 b]
rw[← succ_eq_add_one]
rw[← succ_eq_add_one]
intro h
apply succ_inj at h
apply hd at h
exact h
Level 3 / 6 : add_left_eq_self
induction y
rw[add_zero]
intro h
exact h
rw[add_succ]
intro h
apply succ_inj at h
apply n_ih at h
exact h
Level 4 / 6 : add_right_eq_self
induction x
rw[zero_add]
intro h
exact h
rw[succ_add]
intro h
apply succ_inj at h
apply n_ih at h
exact h
Level 5 / 6 : add_right_eq_zero
cases b with d
rw[add_zero]
intro h
exact h
intro h
induction a with e he
rw[zero_add] at h
symm at h
apply zero_ne_succ at h
cases h
rw[succ_add] at h
symm at h
apply zero_ne_succ at h
cases h
Level 6 / 6 : add_left_eq_zero
rw[add_comm]
apply add_right_eq_zero
Algorithm World
Level 1 / 9 : add_left_comm
rw[add_comm, ← add_assoc, add_assoc]
nth_rewrite 2 [add_comm]
rw[add_assoc]
rfl
Level 2 / 9 : making life easier
repeat rw[add_assoc]
nth_rewrite 2 [add_comm]
rw[add_assoc]
rfl
Level 3 / 9 : making life simple
simp only [add_assoc, add_left_comm, add_comm]
Level 4 / 9 : the simplest approach
simp_add
Level 5 / 9 : pred
rw[← pred_succ a]
rw[← pred_succ b]
rw[h]
rfl
Level 6 / 9 : is_zero
intro h
symm at h
apply zero_ne_succ at h
exact h
Level 7 / 9 : An algorithm for equality
contrapose! h
apply succ_inj at h
exact h
Level 8 / 9 : decide
decide
Level 9 / 9 : decide again
decide
≤ World
Level 1 / 11 : The use tactic
use 0
rw[add_zero]
rfl
Level 2 / 11 : 0 ≤ x
induction x with d hd
apply le_refl
rw[succ_eq_add_one]
use d+1
rw[zero_add]
rfl
Level 3 / 11 : x ≤ succ x
rw[succ_eq_add_one]
use 1
rfl
Level 4 / 11 : x ≤ y and y ≤ z implies x ≤ z
cases hxy with a ha
cases hyz with b hb
use a+b
rw[← add_assoc]
rw[← ha]
rw[← hb]
rfl
Level 5 / 11 : x ≤ 0 → x = 0
cases hx with c hc
symm at hc
apply add_right_eq_zero at hc
exact hc
Level 6 / 11 : x ≤ y and y ≤ x implies x = y
cases hxy with c hc
cases hyx with d hd
rw[hd] at hc
symm at hc
rw[add_assoc] at hc
apply add_right_eq_self at hc
apply add_right_eq_zero at hc
rw[hc] at hd
rw[add_zero] at hd
exact hd
Level 7 / 11 : Dealing with or
cases h with hx hy
right
exact hx
left
exact hy
Level 8 / 11 : x ≤ y or y ≤ x
induction y with d hd
right
apply zero_le
cases hd
left
cases h with c hc
rw[succ_eq_add_one]
rw[hc]
rw[add_assoc]
use c+1
rfl
cases h with c hc
cases c
rw[add_zero] at hc
rw[hc]
left
use 1
rw[succ_eq_add_one]
rfl
right
rw[add_succ] at hc
rw[hc]
use a
rw[succ_add]
rfl
Level 9 / 11 : succ x ≤ succ y → x ≤ y
cases hx with c hc
use c
rw[succ_add] at hc
apply succ_inj at hc
exact hc
Level 10 / 11 : x ≤ 1
cases x
left
rfl
rw[one_eq_succ_zero] at hx
apply succ_le_succ at hx
apply le_zero at hx
right
rw[one_eq_succ_zero]
rw[hx]
rfl
Level 11 / 11 : le_two
cases x
left
rfl
cases a
rw[one_eq_succ_zero]
right
left
rfl
right
right
rw[two_eq_succ_one] at hx
apply succ_le_succ at hx
rw[one_eq_succ_zero] at hx
apply succ_le_succ at hx
apply le_zero at hx
rw[hx]
rw[← one_eq_succ_zero]
rw[← two_eq_succ_one]
rfl
Advanced Multiplication World
Level 1 / 10 : mul_le_mul_right
cases h with d hd
use d*t
rw[← add_mul, hd]
rfl
Level 2 / 10 : mul_left_ne_zero
contrapose! h
rw[h,mul_zero]
rfl
Level 3 / 10 : eq_succ_of_ne_zero
cases a
tauto
use a_1
rfl
Level 4 / 10 : one_le_of_ne_zero
cases a
tauto
rw[one_eq_succ_zero]
use a_1
rw[← one_eq_succ_zero]
rw[succ_eq_add_one]
simp_add
Level 5 / 10 : le_mul_right
cases b
rw[mul_zero] at h
tauto
rw[succ_eq_add_one]
rw[mul_add]
rw[mul_one]
use a*a_1
simp_add
Level 6 / 10 : mul_right_eq_one
have h2 : x * y ≠ 0
rw[h]
tauto
apply le_mul_right at h2
rw[h] at h2
apply le_one at h2
cases h2
rw[h_1] at h
rw[zero_mul] at h
tauto
exact h_1
Level 7 / 10 : mul_ne_zero
apply eq_succ_of_ne_zero at ha
apply eq_succ_of_ne_zero at hb
cases a
contrapose! ha
apply zero_ne_succ
cases b
contrapose! hb
apply zero_ne_succ
rw[succ_eq_add_one]
rw[succ_eq_add_one]
rw[mul_add]
rw[add_mul]
rw[add_mul]
rw[mul_one]
rw[mul_one]
rw[one_mul]
rw[<- add_assoc]
rw[← succ_eq_add_one]
apply succ_ne_zero
Level 8 / 10 : mul_eq_zero
have h2 := mul_ne_zero a b
tauto
Level 9 / 10 : mul_left_cancel
induction b with d hd generalizing c
rw[mul_zero] at h
symm at h
apply mul_eq_zero at h
tauto
cases c with e
rw[mul_zero] at h
apply mul_eq_zero at h
tauto
rw[succ_eq_add_one] at h
rw[succ_eq_add_one] at h
rw[mul_add] at h
rw[mul_add] at h
rw[mul_one] at h
apply add_right_cancel at h
apply hd at h
rw[h]
rfl
Level 10 / 10 : mul_right_eq_self
nth_rewrite 2 [<- mul_one a] at h
apply mul_left_cancel at h
exact h
exact ha

浙公网安备 33010602011771号