@@ -32,37 +32,45 @@ abbrev Nat.mul (n m : Nat) : Nat := Nat.recurse (fun _ prod ↦ prod + m) 0 n
3232instance Nat.instMul : Mul Nat where
3333 mul := mul
3434
35- /-- Definition 2.3.1 (Multiplication of natural numbers) -/
35+ /-- Definition 2.3.1 (Multiplication of natural numbers)
36+ Compare with Mathlib's `Nat.zero_mul` -/
3637theorem Nat.zero_mul (m: Nat) : 0 * m = 0 := recurse_zero (fun _ prod ↦ prod+m) _
3738
38- /-- Definition 2.3.1 (Multiplication of natural numbers) -/
39+ /-- Definition 2.3.1 (Multiplication of natural numbers)
40+ Compare with Mathlib's `Nat.succ_mul` -/
3941theorem Nat.succ_mul (n m: Nat) : (n++) * m = n * m + m := recurse_succ (fun _ prod ↦ prod+m) _ _
4042
4143theorem Nat.one_mul' (m: Nat) : 1 * m = 0 + m := by
4244 rw [←zero_succ, succ_mul, zero_mul]
4345
46+ /-- Compare with Mathlib's `Nat.one_mul` -/
4447theorem Nat.one_mul (m: Nat) : 1 * m = m := by
4548 rw [one_mul', zero_add]
4649
4750theorem Nat.two_mul (m: Nat) : 2 * m = 0 + m + m := by
4851 rw [←one_succ, succ_mul, one_mul']
4952
50- /-- This lemma will be useful to prove Lemma 2.3.2. -/
53+ /-- This lemma will be useful to prove Lemma 2.3.2.
54+ Compare with Mathlib's `Nat.mul_zero` -/
5155lemma Nat.mul_zero (n: Nat) : n * 0 = 0 := by
5256 sorry
5357
54- /-- This lemma will be useful to prove Lemma 2.3.2. -/
58+ /-- This lemma will be useful to prove Lemma 2.3.2.
59+ Compare with Mathlib's `Nat.mul_succ` -/
5560lemma Nat.mul_succ (n m:Nat) : n * m++ = n * m + n := by
5661 sorry
5762
58- /-- Lemma 2.3.2 (Multiplication is commutative) / Exercise 2.3.1 -/
63+ /-- Lemma 2.3.2 (Multiplication is commutative) / Exercise 2.3.1
64+ Compare with Mathlib's `Nat.mul_comm` -/
5965lemma Nat.mul_comm (n m: Nat) : n * m = m * n := by
6066 sorry
6167
68+ /-- Compare with Mathlib's `Nat.mul_one` -/
6269theorem Nat.mul_one (m: Nat) : m * 1 = m := by
6370 rw [mul_comm, one_mul]
6471
65- /-- This lemma will be useful to prove Lemma 2.3.3. -/
72+ /-- This lemma will be useful to prove Lemma 2.3.3.
73+ Compare with Mathlib's `Nat.mul_pos` -/
6674lemma Nat.pos_mul_pos {n m: Nat} (h₁: n.IsPos) (h₂: m.IsPos) : (n * m).IsPos := by
6775 sorry
6876
@@ -71,7 +79,8 @@ lemma Nat.pos_mul_pos {n m: Nat} (h₁: n.IsPos) (h₂: m.IsPos) : (n * m).IsPos
7179lemma Nat.mul_eq_zero (n m: Nat) : n * m = 0 ↔ n = 0 ∨ m = 0 := by
7280 sorry
7381
74- /-- Proposition 2.3.4 (Distributive law)-/
82+ /-- Proposition 2.3.4 (Distributive law)
83+ Compare with Mathlib's `Nat.mul_add` -/
7584theorem Nat.mul_add (a b c: Nat) : a * (b + c) = a * b + a * c := by
7685 -- This proof is written to follow the structure of the original text.
7786 revert c; apply induction
@@ -81,11 +90,13 @@ theorem Nat.mul_add (a b c: Nat) : a * (b + c) = a * b + a * c := by
8190 rw [add_succ, mul_succ]
8291 rw [mul_succ, ←add_assoc, ←habc]
8392
84- /-- Proposition 2.3.4 (Distributive law)-/
93+ /-- Proposition 2.3.4 (Distributive law)
94+ Compare with Mathlib's `Nat.add_mul` -/
8595theorem Nat.add_mul (a b c: Nat) : (a + b)*c = a*c + b*c := by
8696 simp only [mul_comm, mul_add]
8797
88- /-- Proposition 2.3.5 (Multiplication is associative) / Exercise 2.3.3 -/
98+ /-- Proposition 2.3.5 (Multiplication is associative) / Exercise 2.3.3
99+ Compare with Mathlib's `Nat.mul_assoc` -/
89100theorem Nat.mul_assoc (a b c: Nat) : (a * b) * c = a * (b * c) := by
90101 sorry
91102
@@ -106,7 +117,8 @@ instance Nat.instCommSemiring : CommSemiring Nat where
106117example (a b c d:ℕ) : (a+b)*1 *(c+d) = d*b+a*c+c*b+a*d+0 := by ring
107118
108119
109- /-- Proposition 2.3.6 (Multiplication preserves order) -/
120+ /-- Proposition 2.3.6 (Multiplication preserves order)
121+ Compare with Mathlib's `Nat.mul_lt_mul_of_pos_right` -/
110122theorem Nat.mul_lt_mul_of_pos_right {a b c: Nat} (h: a < b) (hc: c.IsPos) : a * c < b * c := by
111123 -- This proof is written to follow the structure of the original text.
112124 rw [lt_iff_add_pos] at h
@@ -121,7 +133,8 @@ theorem Nat.mul_lt_mul_of_pos_right {a b c: Nat} (h: a < b) (hc: c.IsPos) : a *
121133theorem Nat.mul_gt_mul_of_pos_right {a b c: Nat} (h: a > b) (hc: c.IsPos) :
122134 a * c > b * c := mul_lt_mul_of_pos_right h hc
123135
124- /-- Proposition 2.3.6 (Multiplication preserves order) -/
136+ /-- Proposition 2.3.6 (Multiplication preserves order)
137+ Compare with Mathlib's `Nat.mul_lt_mul_of_pos_left` -/
125138theorem Nat.mul_lt_mul_of_pos_left {a b c: Nat} (h: a < b) (hc: c.IsPos) : c * a < c * b := by
126139 simp [mul_comm]
127140 exact mul_lt_mul_of_pos_right h hc
@@ -130,7 +143,8 @@ theorem Nat.mul_lt_mul_of_pos_left {a b c: Nat} (h: a < b) (hc: c.IsPos) : c * a
130143theorem Nat.mul_gt_mul_of_pos_left {a b c: Nat} (h: a > b) (hc: c.IsPos) :
131144 c * a > c * b := mul_lt_mul_of_pos_left h hc
132145
133- /-- Corollary 2.3.7 (Cancellation law) -/
146+ /-- Corollary 2.3.7 (Cancellation law)
147+ Compare with Mathlib's `Nat.mul_right_cancel` -/
134148lemma Nat.mul_cancel_right {a b c: Nat} (h: a * c = b * c) (hc: c.IsPos) : a = b := by
135149 -- This proof is written to follow the structure of the original text.
136150 have := trichotomous a b
@@ -143,18 +157,22 @@ lemma Nat.mul_cancel_right {a b c: Nat} (h: a * c = b * c) (hc: c.IsPos) : a = b
143157 replace hgt := ne_of_gt _ _ hgt
144158 contradiction
145159
146- /-- (Not from textbook) Nat is an ordered semiring. -/
160+ /-- (Not from textbook) Nat is an ordered semiring.
161+ This allows tactics such as `gcongr` to apply to the Chapter 2 natural numbers. -/
147162instance Nat.isOrderedRing : IsOrderedRing Nat where
148163 zero_le_one := by sorry
149164 mul_le_mul_of_nonneg_left := by sorry
150165 mul_le_mul_of_nonneg_right := by sorry
151166
167+ /-- This illustration of the `gcongr` tactic is not from the
168+ textbook. -/
152169example (a b c d:Nat) (hab: a ≤ b) : c*a*d ≤ c*b*d := by
153170 gcongr
154171 . exact d.zero_le
155172 exact c.zero_le
156173
157- /-- Proposition 2.3.9 (Euclid's division lemma) / Exercise 2.3.5 -/
174+ /-- Proposition 2.3.9 (Euclid's division lemma) / Exercise 2.3.5
175+ Compare with Mathlib's `Nat.mod_eq_iff` -/
158176theorem Nat.exists_div_mod (n:Nat) {q: Nat} (hq: q.IsPos) :
159177 ∃ m r: Nat, 0 ≤ r ∧ r < q ∧ n = m * q + r := by
160178 sorry
@@ -165,16 +183,25 @@ abbrev Nat.pow (m n: Nat) : Nat := Nat.recurse (fun _ prod ↦ prod * m) 1 n
165183instance Nat.instPow : HomogeneousPow Nat where
166184 pow := Nat.pow
167185
168- /-- Definition 2.3.11 (Exponentiation for natural numbers) -/
186+ /-- Definition 2.3.11 (Exponentiation for natural numbers)
187+ Compare with Mathlib's `Nat.pow_zero` -/
188+ @[simp]
169189theorem Nat.pow_zero (m: Nat) : m ^ (0 :Nat) = 1 := recurse_zero (fun _ prod ↦ prod * m) _
170190
171191/-- Definition 2.3.11 (Exponentiation for natural numbers) -/
192+ @[simp]
172193theorem Nat.zero_pow_zero : (0 :Nat) ^ 0 = 1 := recurse_zero (fun _ prod ↦ prod * 0 ) _
173194
174- /-- Definition 2.3.11 (Exponentiation for natural numbers) -/
195+ /-- Definition 2.3.11 (Exponentiation for natural numbers)
196+ Compare with Mathlib's `Nat.pow_succ` -/
175197theorem Nat.pow_succ (m n: Nat) : (m:Nat) ^ n++ = m^n * m :=
176198 recurse_succ (fun _ prod ↦ prod * m) _ _
177199
200+ /-- Compare with Mathlib's `Nat.pow_one` -/
201+ @[simp]
202+ theorem Nat.pow_one (m: Nat) : m ^ (1 :Nat) = m := by
203+ rw [←zero_succ, pow_succ]; simp
204+
178205/-- Exercise 2.3.4-/
179206theorem Nat.sq_add_eq (a b: Nat) :
180207 (a + b) ^ (2 : Nat) = a ^ (2 : Nat) + 2 * a * b + b ^ (2 : Nat) := by
0 commit comments