Analysis I, Section 2.3
This file is a translation of Section 2.3 of Analysis I to Lean 4. All numbering refers to the original text.
I have attempted to make the translation as faithful a paraphrasing as possible of the original text. When there is a choice between a more idiomatic Lean solution and a more faithful translation, I have generally chosen the latter. In particular, there will be places where the Lean code could be "golfed" to be more elegant and idiomatic, but I have consciously avoided doing so.
Main constructions and results of this section:
-
Definition of multiplication and exponentiation for the "Chapter 2" natural numbers,
Chapter2.Nat
Note: at the end of this chapter, the Chapter2.Nat class will be deprecated in favor of the standard Mathlib class _root_.Nat, or ℕ. However, we will develop the properties of Chapter2.Nat "by hand" for pedagogical purposes.
namespace Chapter2Definition 2.3.1 (Multiplication of natural numbers)
abbrev Nat.mul (n m : Nat) : Nat := Nat.recurse (fun _ prod ↦ prod + m) 0 ninstance Nat.instMul : Mul Nat where
mul := mulDefinition 2.3.1 (Multiplication of natural numbers)
theorem Nat.zero_mul (m: Nat) : 0 * m = 0 := recurse_zero (fun _ prod ↦ prod+m) _Definition 2.3.1 (Multiplication of natural numbers)
theorem Nat.succ_mul (n m: Nat) : (n++) * m = n * m + m := recurse_succ (fun _ prod ↦ prod+m) _ _theorem Nat.one_mul' (m: Nat) : 1 * m = 0 + m := m:Nat⊢ 1 * m = 0 + m
All goals completed! 🐙theorem Nat.one_mul (m: Nat) : 1 * m = m := m:Nat⊢ 1 * m = m
All goals completed! 🐙theorem Nat.two_mul (m: Nat) : 2 * m = 0 + m + m := m:Nat⊢ 2 * m = 0 + m + m
All goals completed! 🐙/-- This lemma will be useful to prove Lemma 2.3.2. -/
lemma Nat.mul_zero (n: Nat) : n * 0 = 0 := n:Nat⊢ n * 0 = 0
All goals completed! 🐙/-- This lemma will be useful to prove Lemma 2.3.2. -/
lemma Nat.mul_succ (n m:Nat) : n * m++ = n * m + n := n:Natm:Nat⊢ n * m++ = n * m + n
All goals completed! 🐙/-- Lemma 2.3.2 (Multiplication is commutative) / Exercise 2.3.1 -/
lemma Nat.mul_comm (n m: Nat) : n * m = m * n := n:Natm:Nat⊢ n * m = m * n
All goals completed! 🐙theorem Nat.mul_one (m: Nat) : m * 1 = m := m:Nat⊢ m * 1 = m
All goals completed! 🐙/-- Lemma 2.3.3 (Positive natural numbers have no zero divisors) / Exercise 2.3.2 -/
lemma Nat.mul_eq_zero_iff (n m: Nat) : n * m = 0 ↔ n = 0 ∨ m = 0 := n:Natm:Nat⊢ n * m = 0 ↔ n = 0 ∨ m = 0
All goals completed! 🐙lemma Nat.pos_mul_pos {n m: Nat} (h₁: n.isPos) (h₂: m.isPos) : (n * m).isPos := n:Natm:Nath₁:n.isPosh₂:m.isPos⊢ (n * m).isPos
All goals completed! 🐙Proposition 2.3.4 (Distributive law)
theorem Nat.mul_add (a b c: Nat) : a * (b + c) = a * b + a * c := a:Natb:Natc:Nat⊢ a * (b + c) = a * b + a * c
-- This proof is written to follow the structure of the original text.
a:Natb:Nat⊢ ∀ (c : Nat), a * (b + c) = a * b + a * c; a:Natb:Nat⊢ a * (b + 0) = a * b + a * 0a:Natb:Nat⊢ ∀ (n : Nat), a * (b + n) = a * b + a * n → a * (b + n++) = a * b + a * n++
a:Natb:Nat⊢ a * (b + 0) = a * b + a * 0 a:Natb:Nat⊢ a * b = a * b + a * 0
All goals completed! 🐙
a:Natb:Natc:Nathabc:a * (b + c) = a * b + a * c⊢ a * (b + c++) = a * b + a * c++
a:Natb:Natc:Nathabc:a * (b + c) = a * b + a * c⊢ a * (b + c) + a = a * b + a * c++
All goals completed! 🐙Proposition 2.3.4 (Distributive law)
theorem Nat.add_mul (a b c: Nat) : (a + b)*c = a*c + b*c := a:Natb:Natc:Nat⊢ (a + b) * c = a * c + b * c
All goals completed! 🐙Proposition 2.3.5 (Multiplication is associative) / Exercise 2.3.3
theorem Nat.mul_assoc (a b c: Nat) : (a * b) * c = a * (b * c) := a:Natb:Natc:Nat⊢ a * b * c = a * (b * c)
All goals completed! 🐙(Not from textbook) Nat is a commutative semiring.
instance Nat.instCommSemiring : CommSemiring Nat where
left_distrib := mul_add
right_distrib := add_mul
zero_mul := zero_mul
mul_zero := mul_zero
mul_assoc := mul_assoc
one_mul := one_mul
mul_one := mul_one
mul_comm := mul_commProposition 2.3.6 (Multiplication preserves order)
theorem Nat.mul_lt_mul_of_pos_right {a b c: Nat} (h: a < b) (hc: c.isPos) : a * c < b * c := a:Natb:Natc:Nath:a < bhc:c.isPos⊢ a * c < b * c
-- This proof is written to follow the structure of the original text.
a:Natb:Natc:Nath:∃ d, d.isPos ∧ b = a + dhc:c.isPos⊢ a * c < b * c
a:Natb:Natc:Nathc:c.isPosd:Nathdpos:d.isPoshd:b = a + d⊢ a * c < b * c
a:Natb:Natc:Nathc:c.isPosd:Nathdpos:d.isPoshd:b * c = (a + d) * c⊢ a * c < b * c
a:Natb:Natc:Nathc:c.isPosd:Nathdpos:d.isPoshd:b * c = a * c + d * c⊢ a * c < b * c
a:Natb:Natc:Nathc:c.isPosd:Nathdpos:d.isPoshd:b * c = a * c + d * chdcpos:(d * c).isPos⊢ a * c < b * c
a:Natb:Natc:Nathc:c.isPosd:Nathdpos:d.isPoshd:b * c = a * c + d * chdcpos:(d * c).isPos⊢ ∃ d, d.isPos ∧ b * c = a * c + d
All goals completed! 🐙Proposition 2.3.6 (Multiplication preserves order)
theorem Nat.mul_gt_mul_of_pos_right {a b c: Nat} (h: a > b) (hc: c.isPos) : a * c > b * c := mul_lt_mul_of_pos_right h hcProposition 2.3.6 (Multiplication preserves order)
theorem Nat.mul_lt_mul_of_pos_left {a b c: Nat} (h: a < b) (hc: c.isPos) : c * a < c * b := a:Natb:Natc:Nath:a < bhc:c.isPos⊢ c * a < c * b
a:Natb:Natc:Nath:a < bhc:c.isPos⊢ a * c < b * c
All goals completed! 🐙Proposition 2.3.6 (Multiplication preserves order)
theorem Nat.mul_gt_mul_of_pos_left {a b c: Nat} (h: a > b) (hc: c.isPos) : c * a > c * b := mul_lt_mul_of_pos_left h hc/-- Corollary 2.3.7 (Cancellation law) -/
lemma Nat.mul_cancel_right {a b c: Nat} (h: a * c = b * c) (hc: c.isPos) : a = b := a:Natb:Natc:Nath:a * c = b * chc:c.isPos⊢ a = b
-- This proof is written to follow the structure of the original text.
a:Natb:Natc:Nath:a * c = b * chc:c.isPosthis:a < b ∨ a = b ∨ a > b⊢ a = b
a:Natb:Natc:Nath:a * c = b * chc:c.isPoshlt:a < b⊢ a = ba:Natb:Natc:Nath:a * c = b * chc:c.isPosheq:a = b⊢ a = ba:Natb:Natc:Nath:a * c = b * chc:c.isPoshgt:a > b⊢ a = b
a:Natb:Natc:Nath:a * c = b * chc:c.isPoshlt:a < b⊢ a = b a:Natb:Natc:Nath:a * c = b * chc:c.isPoshlt:a * c < b * c⊢ a = b
a:Natb:Natc:Nath:a * c = b * chc:c.isPoshlt:a * c ≠ b * c⊢ a = b
All goals completed! 🐙
a:Natb:Natc:Nath:a * c = b * chc:c.isPosheq:a = b⊢ a = b All goals completed! 🐙
a:Natb:Natc:Nath:a * c = b * chc:c.isPoshgt:a * c > b * c⊢ a = b
a:Natb:Natc:Nath:a * c = b * chc:c.isPoshgt:a * c ≠ b * c⊢ a = b
All goals completed! 🐙(Not from textbook) Nat is an ordered semiring.
instance Nat.isOrderedRing : IsOrderedRing Nat where
zero_le_one := ⊢ 0 ≤ 1 All goals completed! 🐙
mul_le_mul_of_nonneg_left := ⊢ ∀ (a b c : Nat), a ≤ b → 0 ≤ c → c * a ≤ c * b All goals completed! 🐙
mul_le_mul_of_nonneg_right := ⊢ ∀ (a b c : Nat), a ≤ b → 0 ≤ c → a * c ≤ b * c All goals completed! 🐙Proposition 2.3.9 (Euclid's division lemma) / Exercise 2.3.5
theorem Nat.exists_div_mod (n :Nat) {q: Nat} (hq: q.isPos) : ∃ m r: Nat, 0 ≤ r ∧ r < q ∧ n = m * q + r := n:Natq:Nathq:q.isPos⊢ ∃ m r, 0 ≤ r ∧ r < q ∧ n = m * q + r
All goals completed! 🐙Definition 2.3.11 (Exponentiation for natural numbers)
abbrev Nat.pow (m n: Nat) : Nat := Nat.recurse (fun _ prod ↦ prod * m) 1 ninstance Nat.instPow : HomogeneousPow Nat where
pow := Nat.powDefinition 2.3.11 (Exponentiation for natural numbers)
theorem Nat.zero_pow_zero : (0:Nat) ^ 0 = 1 := recurse_zero (fun _ prod ↦ prod * 0) _Definition 2.3.11 (Exponentiation for natural numbers)
theorem Nat.pow_succ (m n: Nat) : (m:Nat) ^ n++ = m^n * m := recurse_succ (fun _ prod ↦ prod * m) _ _Exercise 2.3.4
theorem Nat.sq_add_eq (a b: Nat) : (a + b) ^ (2 : Nat) = a ^ (2 : Nat) + 2 * a * b + b ^ (2 : Nat) := a:Natb:Nat⊢ (a + b) ^ 2 = a ^ 2 + 2 * a * b + b ^ 2
All goals completed! 🐙end Chapter2