自然数游戏答案合集
· 阅读需 9 分钟
自然数游戏(Natual Number Game)地址:https://game.leanprover.cn/
代码高亮使用 PrismJs PR #3765 方案
教程世界
- rfl 策略
- rw 策略
- 数字
- 逆向重写
- 加零
- 精准重写
- add_succ
- 2+2=4
rfl
rw [h]
rfl
rw[two_eq_succ_one]
rw[one_eq_succ_zero]
rfl
rw[← one_eq_succ_zero]
rw[← two_eq_succ_one]
rfl
-- rw[add_zero b]
-- rw[add_zero c]
repeat rw [add_zero]
rfl
rw [add_zero b]
rw [add_zero c]
rfl
rw [one_eq_succ_zero]
rw [add_succ n 0]
rw [add_zero]
rfl
nth_rewrite 2 [two_eq_succ_one]
rw [add_succ 2 1]
rw [← succ_eq_add_one]
rw [← three_eq_succ_two]
rw [four_eq_succ_three]
rfl
加法世界
- zero_add
- succ_add
- add_comm(关卡Boss)
- add_assoc(加法结合律)
- add_right_comm
induction n with d hd
-- 0 + 0 = 0
rw [add_zero]
rfl
-- 0 + succ d = succ d
rw [add_succ]
rw [hd]
rfl
induction b with d hd
-- succ a + 0 = succ (a + 0)
repeat rw [add_zero]
rfl
-- hd: succ a + d = succ (a + d); succ a + succ d = succ (a + succ d)
rw [add_succ]
rw [add_succ a d]
rw [hd]
rfl
induction a with d hd
-- 0 + b = b + 0
rw [add_zero]
rw [zero_add]
rfl
-- hd: d+b=b+d; succ d + b = b + succ d
rw [add_succ b d]
rw [succ_add d b]
rw [hd]
rfl
induction b with d hd
rw [zero_add]
rw [add_zero]
rfl
rw [add_succ]
repeat rw [succ_add]
rw [add_succ]
rw [hd]
rfl
repeat rw [add_assoc]
rw [add_comm b c]
rfl
乘法世界
- mul_one
- zero_mul
- succ_mul
- mul_comm
- one_mul
- two_mul
- mul_add
- add_mul
- mul_assoc
rw [one_eq_succ_zero]
rw [mul_succ]
rw [mul_zero]
rw [zero_add]
rfl
induction m with d hd
apply mul_zero
rw [mul_succ, hd, zero_add]
rfl
induction b with c hc
repeat rw [mul_zero]
rw [zero_add]
rfl
repeat rw [mul_succ]
rw [hc]
repeat rw [add_succ]
rw [add_right_comm]
rfl
induction a with c hc
rw [zero_mul, mul_zero]
rfl
rw [succ_mul, mul_succ, hc]
rfl
rw [one_eq_succ_zero, succ_mul, zero_mul, zero_add]
rfl
rw [two_eq_succ_one, one_eq_succ_zero]
repeat rw [succ_mul]
rw [zero_mul, zero_add]
rfl
induction b with d hd
rw [zero_add, mul_zero, zero_add]
rfl
rw [succ_add]
repeat rw [mul_succ]
rw [add_right_comm, hd]
rfl
rw [mul_comm, mul_add, mul_comm, mul_comm c b]
rfl
induction a with d hd
repeat rw [zero_mul]
rfl
repeat rw [succ_mul]
rw [add_mul, hd]
rfl
蕴含世界
- exact 策略
- exact 练习
- apply 策略
- succ_inj :后继数是单射的
- 从后向前证明
- intro
- 练习 intro 策略
- ≠
- zero_ne_succ
- 1 ≠ 0
- 2 + 2 ≠ 5
exact h1
repeat rw [zero_add] at h
exact h
apply h2 at h1
exact h1
rw [four_eq_succ_three] at h
rw [← succ_eq_add_one] at h
apply succ_inj at h
exact h
apply succ_inj
rw [succ_eq_add_one]
rw [← four_eq_succ_three]
exact h
intro h
exact h
intro h
repeat rw [← succ_eq_add_one] at h
apply succ_inj at h
exact h
apply h2
exact h1
intro h
rw [one_eq_succ_zero] at h
apply zero_ne_succ at h
exact h
symm
apply zero_ne_one
repeat rw [succ_eq_add_one]
repeat rw [zero_add]
rw [← add_assoc]
repeat rw [← succ_eq_add_one]
repeat rw [one_eq_succ_zero]
intro h
repeat apply succ_inj at h
apply zero_ne_succ at h
exact h
幂世界
- zero_pow_zero
- zero_pow_succ
- pow_one
- one_pow
- pow_two
- pow_add
- mul_pow
- pow_pow
- add_sq
- 费马大定理
rw [pow_zero]
rfl
rw [pow_succ, mul_zero]
rfl
rw [one_eq_succ_zero, pow_succ, pow_zero, one_mul]
rfl
induction m with a ha
rw [pow_zero]
rfl
rw [pow_succ, mul_one, ha]
rfl
rw [two_eq_succ_one, pow_succ, pow_one]
rfl
induction n with b hb
rw [add_zero, pow_zero, mul_one]
rfl
rw [add_succ, pow_succ, hb, pow_succ,← mul_assoc]
rfl
induction n with c hc
repeat rw [pow_zero]
rw [one_mul]
rfl
repeat rw [pow_succ]
repeat rw [← mul_assoc]
nth_rewrite 5 [mul_comm]
rw [← mul_assoc]
nth_rewrite 6 [mul_comm]
rw [hc]
rfl
induction n with b hb
rw [mul_zero]
repeat rw [pow_zero]
rfl
rw [mul_succ, pow_add, pow_succ, hb]
rfl
nth_rewrite 1 [two_eq_succ_one, pow_succ, pow_one, add_mul]
repeat rw [mul_add, ← pow_two]
nth_rewrite 2 [mul_comm]
rw [← add_assoc]
nth_rewrite 5 [two_eq_succ_one]
rw [succ_eq_add_one]
repeat rw [add_mul]
repeat rw [one_mul]
rw [add_right_comm]
nth_rewrite 2 [add_right_comm]
rw [add_assoc]
rfl
-- 这里空间太小,我写不下 /doge
高级加法世界
- add_right_cancel
- add_left_cancel
- add_left_eq_self
- add_right_eq_self
- add_right_eq_zero
- add_left_eq_zero
induction n with d hd
repeat rw [add_zero]
intro h
exact h
repeat rw [add_succ]
intro h
apply hd
apply succ_inj
exact h
rw [add_comm n a]
rw [add_comm n b]
intro h
apply add_right_cancel a b n
exact h
nth_rewrite 2 [← zero_add y]
exact add_right_cancel x 0 y
rw [add_comm]
exact add_left_eq_self y x
cases b with d
rw [add_zero]
intro h
exact h
rw [add_succ]
intro h
symm at h
apply zero_ne_succ at h
cases h
rw [add_comm]
exact add_right_eq_zero b a
算法世界
- add_left_comm
- 让生活更轻松
- 让生活变得简单
- 最简单的方法
- pred
- is_zero
- 用于证明等价的算法
- decide
- 还是 decide
repeat rw [← add_assoc]
rw [add_comm b a]
rfl
repeat rw [add_assoc]
rw [add_left_comm b c, add_comm d b]
rfl
simp only [add_assoc, add_left_comm, add_comm]
simp_add
rw [← pred_succ a, h, pred]
rfl
-- symm
-- apply zero_ne_succ
intro h
rw [← is_zero_succ a, h, is_zero_zero]
trivial
contrapose! h
apply succ_inj at h
exact h
decide
decide
≤ 世界
- use 策略
- 0 ≤ x
- x ≤ succ x
- x ≤ y 且 y ≤ z 意味着 x ≤ z
- x ≤ 0 → x = 0
- x ≤ y 且 y ≤ x 意味着 x = y
- 处理 or
- x ≤ y 或 y ≤ x
- succ x ≤ succ y → x ≤ y
- x≤1
- le_two
use 0
rw [add_zero]
rfl
use x
rw [zero_add]
rfl
use 1
rw [succ_eq_add_one]
rfl
cases hxy with a ha
cases hyz with b hb
rw [ha] at hb
rw [hb]
use a+b
rw [add_assoc]
rfl
cases hx with a ha
symm at ha
apply add_right_eq_zero at ha
exact ha
cases hxy with a ha
cases hyx with b hb
rw [hb, add_assoc] at ha
nth_rewrite 1 [← add_zero y] at ha
apply add_left_cancel at ha
symm at ha
apply add_right_eq_zero at ha
rw [ha, add_zero] at hb
exact hb
cases h with hx hy
right
exact hx
left
exact hy
induction y with d hd
right
use x
rw [zero_add]
rfl
cases hd with h1 h2
left
cases h1 with e h1
use e+1
rw [h1, succ_eq_add_one, add_assoc]
rfl
cases h2 with e h2
cases e with a
left
use 1
rw [h2, succ_eq_add_one, add_zero]
rfl
right
use a
rw [h2, add_succ, succ_add]
rfl
cases hx with a ha
rw [succ_add] at ha
apply succ_inj at ha
use a
rw [ha]
rfl
cases hx with a ha
cases x with b hb
left
rfl
rw [one_eq_succ_zero, succ_add] at ha
apply succ_inj at ha
symm at ha
apply add_right_eq_zero at ha
right
rw [one_eq_succ_zero, ha]
rfl
cases hx with a ha
cases x with b hb
left
rfl
cases b with c hc
right
left
rw [← one_eq_succ_zero]
rfl
repeat rw [succ_add] at ha
rw [two_eq_succ_one, one_eq_succ_zero] at ha
apply succ_inj at ha
apply succ_inj at ha
symm at ha
apply add_right_eq_zero at ha
right
right
rw [ha, ← one_eq_succ_zero, ← two_eq_succ_one]
rfl
高级乘法世界
- mul_le_mul_right
- mul_left_ne_zero
- eq_succ_of_ne_zero
- one_le_of_ne_zero
- le_mul_right
- mul_right_eq_one
- mul_ne_zero
- mul_eq_zero
- mul_left_cancel
- mul_right_eq_self
cases h with c hc
use c*t
rw [hc, add_mul]
rfl
contrapose! h
rw [h, mul_zero]
rfl
cases a with b hb
tauto
tauto
apply eq_succ_of_ne_zero at ha
cases ha with n hn
use n
rw [hn, succ_eq_add_one, add_comm]
rfl
apply mul_left_ne_zero at h
apply eq_succ_of_ne_zero at h
cases h with c hc
use a*c
rw [hc, mul_succ, add_comm]
rfl
have h1 : x * y ≠ 0
rw [h]
exact one_ne_zero
apply le_mul_right at h1
rw [h] at h1
apply le_one at h1
cases h1 with hl hr
rw [hl, zero_mul] at h
tauto
exact hr
apply eq_succ_of_ne_zero at ha
apply eq_succ_of_ne_zero at hb
cases ha with c hc
cases hb with d hd
rw [hc, hd, mul_succ, add_succ]
symm
apply zero_ne_succ
contrapose! h
have h1 := mul_ne_zero a b
tauto
induction b with d hd generalizing c
rw [mul_zero] at h
symm at h
apply mul_eq_zero at h
tauto
rw [mul_succ] at h
cases c with e
rw [mul_zero] at h
apply add_left_eq_zero at h
tauto
rw [mul_succ] at h
apply add_right_cancel at h
apply hd at h
rw [h]
rfl
nth_rewrite 2 [← mul_one a] at h
apply mul_left_cancel at h
exact h
exact ha