mirror of
https://github.com/tomasriveral/ZeroToLean.git
synced 2026-08-11 18:28:39 +02:00
119 lines
2.1 KiB
Lean4
119 lines
2.1 KiB
Lean4
-- learned from this video https://www.youtube.com/watch?v=0QZI_m8WZ0Q --
|
||
|
||
import Mathlib
|
||
|
||
theorem th (h: 2=2)
|
||
: 2 = 2 :=
|
||
h
|
||
|
||
|
||
#check th
|
||
|
||
|
||
|
||
theorem th2
|
||
: 2 = 2 := by
|
||
norm_num
|
||
|
||
#check Nat.add_comm
|
||
|
||
theorem one_plus_two_commutative
|
||
: 1 + 2 = 2 + 1 := by
|
||
exact Nat.add_comm 1 2
|
||
|
||
theorem plus_comm
|
||
: ∀ (a b: Nat), a + b = b + a := by
|
||
intro a b
|
||
have h := Nat.add_comm a b
|
||
exact h
|
||
|
||
theorem alg
|
||
: ∀ (a b c : Nat),
|
||
a * (b + c) = a* (c + b) := by
|
||
intro a b c
|
||
have h : b + c = c + b := by
|
||
exact plus_comm b c
|
||
rw [h]
|
||
|
||
|
||
theorem factorisation
|
||
: ∀ (a b : Nat),
|
||
a^2 + 2*a*b + b^2 = (a + b)^2 := by
|
||
intro a b
|
||
ring
|
||
|
||
|
||
theorem ev20
|
||
: Even 20 := by
|
||
unfold Even
|
||
use 10
|
||
|
||
|
||
theorem two_div_even
|
||
: ∀ n : Nat, Even n → 2 ∣ n := by
|
||
intro n
|
||
intro n_even
|
||
unfold Even at n_even
|
||
obtain ⟨r, hr⟩ := n_even
|
||
have n_eq_2r : n = 2 * r := by
|
||
rw [hr]
|
||
ring
|
||
rw[n_eq_2r]
|
||
simp
|
||
|
||
|
||
|
||
def PrimeNum (n : Nat) : Prop :=
|
||
n ≥ 2 ∧ (M: Nat), m ∣ n → , = 1 ∨ m = n
|
||
|
||
theorem not_prime1
|
||
: ¬ PrimeNum 1 := by
|
||
-- proof by contradiction --
|
||
intro pr1
|
||
unfold PrimeNum at pr1
|
||
obtain ⟨prop_left, prop_right⟩ := pr1
|
||
contradiction
|
||
|
||
theorem not_prime9
|
||
: ¬ PrimeNum 9 := by
|
||
intro pr9
|
||
unfold PrimeNum at pr9
|
||
obtain ⟨hl, hr⟩ := pr9
|
||
have hr_3 := hr 3
|
||
have div : 3 ∣ 9 := by norm_num
|
||
have or_cases := hr_3 div
|
||
rcases or_cases with c1 ∣ c2
|
||
· contradiction
|
||
· contradiction
|
||
|
||
theorem prime_5
|
||
: PrimeNum 5 := by
|
||
unfold PrimeNum
|
||
have g1 : 5 ≥ 2 := by
|
||
norm_num
|
||
have g2
|
||
: ∀ m : Nat,
|
||
m ∣ 5 → m = 1 ∨ m = 5 := by
|
||
intro m h_m_div_5
|
||
match m with
|
||
| 0 => contradiction
|
||
| 1 =>
|
||
have h : 1 = 1 := by norm_num
|
||
exact Or.inl h
|
||
| 2 => contradiction
|
||
| 3 => contradiction
|
||
| 4 => contradiction
|
||
| 5 =>
|
||
have h : 5 = 5 := by norm_num
|
||
exact Or.inr h
|
||
| n + 6 =>
|
||
have h1 : 5 < n + 6 := by norm_num
|
||
have h2 :=
|
||
Nat.eq_zero_of_dvd_of_lt h_m_div_5 h1
|
||
contradiction
|
||
exact ⟨g1,g2⟩
|
||
|
||
|
||
#check Nat.eq_zero_of_dvd_of_lt
|
||
|