Skip to content

Commit f5f0565

Browse files
authored
Merge pull request #240 from teorth:Comment-2.3
add comments to Sec 2.3
2 parents 687a445 + d80c312 commit f5f0565

2 files changed

Lines changed: 44 additions & 17 deletions

File tree

analysis/Analysis/Section_2_3.lean

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,45 @@ abbrev Nat.mul (n m : Nat) : Nat := Nat.recurse (fun _ prod ↦ prod + m) 0 n
3232
instance 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` -/
3637
theorem 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` -/
3941
theorem Nat.succ_mul (n m: Nat) : (n++) * m = n * m + m := recurse_succ (fun _ prod ↦ prod+m) _ _
4042

4143
theorem 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` -/
4447
theorem Nat.one_mul (m: Nat) : 1 * m = m := by
4548
rw [one_mul', zero_add]
4649

4750
theorem 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` -/
5155
lemma 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` -/
5560
lemma 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` -/
5965
lemma Nat.mul_comm (n m: Nat) : n * m = m * n := by
6066
sorry
6167

68+
/-- Compare with Mathlib's `Nat.mul_one` -/
6269
theorem 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` -/
6674
lemma 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
7179
lemma 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` -/
7584
theorem 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` -/
8595
theorem 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` -/
89100
theorem 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
106117
example (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` -/
110122
theorem 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 *
121133
theorem 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` -/
125138
theorem 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
130143
theorem 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` -/
134148
lemma 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. -/
147162
instance 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. -/
152169
example (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` -/
158176
theorem 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
165183
instance 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]
169189
theorem 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]
172193
theorem 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` -/
175197
theorem 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-/
179206
theorem Nat.sq_add_eq (a b: Nat) :
180207
(a + b) ^ (2 : Nat) = a ^ (2 : Nat) + 2 * a * b + b ^ (2 : Nat) := by

analysis/Analysis/Section_3_6.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ theorem SetTheory.Set.card_erase {n:ℕ} (h: n ≥ 1) {X:Set} (hX: X.has_card n)
103103
have := SetTheory.Set.Fin.toNat_lt (f (ι x'))
104104
have : (f (ι x'):ℕ) ≠ m₀ := by
105105
have := x'.property
106-
simp [X'] at this; contrapose! this; intro hx'; simp [←this, Subtype.val_inj] at hm₀f
106+
simp [X'] at this; contrapose! this; intros; simp [←this, Subtype.val_inj] at hm₀f
107107
exact (congrArg Subtype.val (hf.1 hm₀f)).symm
108108
omega)
109109
have hg_def (x':X') : if (f (ι x'):ℕ) < m₀ then (g x':ℕ) = f (ι x') else (g x':ℕ) = f (ι x') - 1 := by

0 commit comments

Comments
 (0)