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:

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 Chapter2

Definition 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 := mul

Definition 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:Nat1 * m = 0 + m All goals completed! 🐙theorem Nat.one_mul (m: Nat) : 1 * m = m := m:Nat1 * m = m All goals completed! 🐙theorem Nat.two_mul (m: Nat) : 2 * m = 0 + m + m := m:Nat2 * m = 0 + m + m All goals completed! 🐙/-- This lemma will be useful to prove Lemma 2.3.2. -/ lemma declaration uses 'sorry'Nat.mul_zero (n: Nat) : n * 0 = 0 := n:Natn * 0 = 0 All goals completed! 🐙/-- This lemma will be useful to prove Lemma 2.3.2. -/ lemma declaration uses 'sorry'Nat.mul_succ (n m:Nat) : n * m++ = n * m + n := n:Natm:Natn * m++ = n * m + n All goals completed! 🐙/-- Lemma 2.3.2 (Multiplication is commutative) / Exercise 2.3.1 -/ lemma declaration uses 'sorry'Nat.mul_comm (n m: Nat) : n * m = m * n := n:Natm:Natn * m = m * n All goals completed! 🐙theorem Nat.mul_one (m: Nat) : m * 1 = m := m:Natm * 1 = m All goals completed! 🐙/-- Lemma 2.3.3 (Positive natural numbers have no zero divisors) / Exercise 2.3.2 -/ lemma declaration uses 'sorry'Nat.mul_eq_zero_iff (n m: Nat) : n * m = 0 n = 0 m = 0 := n:Natm:Natn * m = 0n = 0m = 0 All goals completed! 🐙lemma declaration uses 'sorry'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:Nata * (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:Nata * (b + 0) = a * b + a * 0a:Natb:Nat∀ (n : Nat), a * (b + n) = a * b + a * na * (b + n++) = a * b + a * n++ a:Natb:Nata * (b + 0) = a * b + a * 0 a:Natb:Nata * b = a * b + a * 0 All goals completed! 🐙 a:Natb:Natc:Nathabc:a * (b + c) = a * b + a * ca * (b + c++) = a * b + a * c++ a:Natb:Natc:Nathabc:a * (b + c) = a * b + a * ca * (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 declaration uses 'sorry'Nat.mul_assoc (a b c: Nat) : (a * b) * c = a * (b * c) := a:Natb:Natc:Nata * 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_comm

Proposition 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.isPosa * c < b * c -- This proof is written to follow the structure of the original text. a:Natb:Natc:Nath:d, d.isPosb = a + dhc:c.isPosa * c < b * c a:Natb:Natc:Nathc:c.isPosd:Nathdpos:d.isPoshd:b = a + da * c < b * c a:Natb:Natc:Nathc:c.isPosd:Nathdpos:d.isPoshd:b * c = (a + d) * ca * c < b * c a:Natb:Natc:Nathc:c.isPosd:Nathdpos:d.isPoshd:b * c = a * c + d * ca * c < b * c a:Natb:Natc:Nathc:c.isPosd:Nathdpos:d.isPoshd:b * c = a * c + d * chdcpos:(d * c).isPosa * c < b * c a:Natb:Natc:Nathc:c.isPosd:Nathdpos:d.isPoshd:b * c = a * c + d * chdcpos:(d * c).isPosd, d.isPosb * 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 hc

Proposition 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.isPosc * a < c * b a:Natb:Natc:Nath:a < bhc:c.isPosa * 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.isPosa = b -- This proof is written to follow the structure of the original text. a:Natb:Natc:Nath:a * c = b * chc:c.isPosthis:a < ba = ba > ba = b a:Natb:Natc:Nath:a * c = b * chc:c.isPoshlt:a < ba = ba:Natb:Natc:Nath:a * c = b * chc:c.isPosheq:a = ba = ba:Natb:Natc:Nath:a * c = b * chc:c.isPoshgt:a > ba = b a:Natb:Natc:Nath:a * c = b * chc:c.isPoshlt:a < ba = b a:Natb:Natc:Nath:a * c = b * chc:c.isPoshlt:a * c < b * ca = b a:Natb:Natc:Nath:a * c = b * chc:c.isPoshlt:a * cb * ca = b All goals completed! 🐙 a:Natb:Natc:Nath:a * c = b * chc:c.isPosheq:a = ba = b All goals completed! 🐙 a:Natb:Natc:Nath:a * c = b * chc:c.isPoshgt:a * c > b * ca = b a:Natb:Natc:Nath:a * c = b * chc:c.isPoshgt:a * cb * ca = b All goals completed! 🐙

(Not from textbook) Nat is an ordered semiring.

instance declaration uses 'sorry'Nat.isOrderedRing : IsOrderedRing Nat where zero_le_one := 01 All goals completed! 🐙 mul_le_mul_of_nonneg_left := ∀ (a b c : Nat), ab → 0cc * ac * b All goals completed! 🐙 mul_le_mul_of_nonneg_right := ∀ (a b c : Nat), ab → 0ca * cb * c All goals completed! 🐙

Proposition 2.3.9 (Euclid's division lemma) / Exercise 2.3.5

theorem declaration uses 'sorry'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.isPosm r, 0rr < qn = 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.pow

Definition 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 declaration uses 'sorry'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