till more exercises

This commit is contained in:
qwjyh 2025-01-08 01:27:21 +09:00
parent 2df3232863
commit 9a5863343d

115
basics/main.lean Normal file → Executable file
View file

@ -235,3 +235,118 @@ end Exercise1
--- Proof by Simplification --- Proof by Simplification
theorem plus_0_n : ∀ n : Nat, 0 + n = n := by
intros n
simp
#check ∀ n : Nat, 0 + n = n
example : ∀ n : Nat, 1 + n = .succ n := by
intros m
simp
apply Nat.add_comm 1 m
example : ∀ n : Nat, 0 * n = 0 := by
intros n
exact Nat.zero_mul n
--- Proof by Rewriting
example : ∀ n m : Nat, n = m → n + n = m + m := by
intros n m h
rw [h]
namespace Exercise1
theorem plus_id_exercise : ∀ n m o : Nat, n = m → m = o → n + m = m + o := by
intros n m o h₁ h₂
rw [h₁]
rw [h₂]
#check plus_0_n
theorem mult_n_1 : ∀ p : Nat, p * 1 = p := by
intros p
cases p
. rw [Nat.mul_one]
. rw [Nat.mul_one]
example : ∀ p : Nat, p * 1 = p := by
intros p
rw [Nat.mul_one]
#check Nat.mul_zero
#check Nat.mul_succ
example : ∀ p : Nat, p * 1 = p := by
intros
rw [Nat.mul_succ]
rw [Nat.mul_zero]
simp
end Exercise1
#eval (1).succ.succ.succ
#eval [1, 2, 3, 4].foldl (· + ·) 0
#print Array.foldl
#print optParam
--- Proof by Case Analysis
example : ∀ n : Nat, ((n + 1) = 0) = False := by
intros n
cases n
case zero => simp only [Nat.zero_add, Nat.add_one_ne_zero]
case succ => simp only [Nat.add_one_ne_zero]
example : ∀ b : Bool, ¬ (¬ b) = b := by
intros b
cases b
. simp
. rw [Lean.Grind.not_eq_prop]
example : ∀ b c : Bool, (b ∧ c) = (c ∧ b) := by
intros b c
cases b
. cases c
. simp only [Bool.false_eq_true, and_self]
. rw [@and_comm]
. rw [@and_comm]
#eval true ∧ true
#eval (true ∧ true) = (true ∧ true)
#eval true ∧ false = false ∧ true
#eval false ∧ false = false ∧ false
#eval (false ∧ false) = (false ∧ false)
#eval Bool.and true true
#eval Bool.true ∧ Bool.true
#eval true && false = false && true
#print and_comm
namespace Exercise
example : ∀ b c : Bool, (Bool.and b c = true) → (c = true) := by
intros b c
cases c
case true => exact fun _a => rfl
case false =>
cases b
case true =>
intros h
exact h
case false =>
intros h
exact h
#print id
#check Function.const
example : ∀ n : Nat, (0 == (n + 1)) = false := by
intros n
cases n
. simp only [Nat.zero_add, Nat.reduceBEq]
. simp only [Nat.reduceBeqDiff]
end Exercise
--- More on Notation
-- skipping
--- More Exercises