-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathSection_7_1.lean
More file actions
328 lines (277 loc) · 14.2 KB
/
Section_7_1.lean
File metadata and controls
328 lines (277 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
import Mathlib.Tactic
set_option doc.verso.suggestions false
/-!
# Analysis I, Section 7.1: Finite series
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.
Technical note: it is convenient in Lean to extend finite sequences (usually by zero) to be
functions on the entire integers.
Main constructions and results of this section:
-/
-- This makes available the convenient notation `∑ n ∈ A, f n` to denote summation of `f n` for
-- `n` ranging over a finite set `A`.
open BigOperators
/-!
- API for summation over finite sets (encoded using Mathlib's {name}`Finset` type), using the
{name}`Finset.sum` method and the `∑ n ∈ A, f n` notation.
- Fubini's theorem for finite series
We do not attempt to replicate the full API for {name}`Finset.sum` here, but in subsequent sections we
shall make liberal use of this API.
-/
-- This is a technical device to avoid Mathlib's insistence on decidable equality for finite sets.
open Classical
namespace Finset
-- We use `Finset.Icc` to describe finite intervals in the integers. `Finset.mem_Icc` is the
-- standard Mathlib tool for checking membership in such intervals.
#check mem_Icc
/-- Definition 7.1.1 -/
theorem sum_of_empty {n m:ℤ} (h: n < m) (a: ℤ → ℝ) : ∑ i ∈ Icc m n, a i = 0 := by
rw [sum_eq_zero]; intro _; rw [mem_Icc]; grind
/--
Definition 7.1.1. This is similar to Mathlib's {name}`Finset.sum_Icc_succ_top` except that the
latter involves summation over the natural numbers rather than integers.
-/
theorem sum_of_nonempty {n m:ℤ} (h: n ≥ m-1) (a: ℤ → ℝ) :
∑ i ∈ Icc m (n+1), a i = ∑ i ∈ Icc m n, a i + a (n+1) := by
rw [add_comm _ (a (n+1))]
convert sum_insert _
. ext; simp; omega
. infer_instance
simp
example (a: ℤ → ℝ) (m:ℤ) : ∑ i ∈ Icc m (m-2), a i = 0 := by sorry
example (a: ℤ → ℝ) (m:ℤ) : ∑ i ∈ Icc m (m-1), a i = 0 := by sorry
example (a: ℤ → ℝ) (m:ℤ) : ∑ i ∈ Icc m m, a i = a m := by sorry
example (a: ℤ → ℝ) (m:ℤ) : ∑ i ∈ Icc m (m+1), a i = a m + a (m+1) := by sorry
example (a: ℤ → ℝ) (m:ℤ) : ∑ i ∈ Icc m (m+2), a i = a m + a (m+1) + a (m+2) := by sorry
/-- Remark 7.1.3 -/
example (a: ℤ → ℝ) (m n:ℤ) : ∑ i ∈ Icc m n, a i = ∑ j ∈ Icc m n, a j := rfl
/-- Lemma 7.1.4(a) / Exercise 7.1.1 -/
theorem concat_finite_series {m n p:ℤ} (hmn: m ≤ n+1) (hpn : n ≤ p) (a: ℤ → ℝ) :
∑ i ∈ Icc m n, a i + ∑ i ∈ Icc (n+1) p, a i = ∑ i ∈ Icc m p, a i := by sorry
/-- Lemma 7.1.4(b) / Exercise 7.1.1 -/
theorem shift_finite_series {m n k:ℤ} (a: ℤ → ℝ) :
∑ i ∈ Icc m n, a i = ∑ i ∈ Icc (m+k) (n+k), a (i-k) := by sorry
/-- Lemma 7.1.4(c) / Exercise 7.1.1 -/
theorem finite_series_add {m n:ℤ} (a b: ℤ → ℝ) :
∑ i ∈ Icc m n, (a i + b i) = ∑ i ∈ Icc m n, a i + ∑ i ∈ Icc m n, b i := by sorry
/-- Lemma 7.1.4(d) / Exercise 7.1.1 -/
theorem finite_series_const_mul {m n:ℤ} (a: ℤ → ℝ) (c:ℝ) :
∑ i ∈ Icc m n, c * a i = c * ∑ i ∈ Icc m n, a i := by sorry
/-- Lemma 7.1.4(e) / Exercise 7.1.1 -/
theorem abs_finite_series_le {m n:ℤ} (a: ℤ → ℝ) :
|∑ i ∈ Icc m n, a i| ≤ ∑ i ∈ Icc m n, |a i| := by sorry
/-- Lemma 7.1.4(f) / Exercise 7.1.1 -/
theorem finite_series_of_le {m n:ℤ} {a b: ℤ → ℝ} (h: ∀ i, m ≤ i → i ≤ n → a i ≤ b i) :
∑ i ∈ Icc m n, a i ≤ ∑ i ∈ Icc m n, b i := by sorry
#check sum_congr
set_option maxHeartbeats 210000 in
/--
Proposition 7.1.8.
-/
theorem finite_series_of_rearrange {n:ℕ} {X':Type*} (X: Finset X') (hcard: X.card = n)
(f: X' → ℝ) (g h: Icc (1:ℤ) n → X) (hg: Function.Bijective g) (hh: Function.Bijective h) :
∑ i ∈ Icc (1:ℤ) n, (if hi:i ∈ Icc (1:ℤ) n then f (g ⟨ i, hi ⟩) else 0)
= ∑ i ∈ Icc (1:ℤ) n, (if hi: i ∈ Icc (1:ℤ) n then f (h ⟨ i, hi ⟩) else 0) := by
-- This proof is written to broadly follow the structure of the original text.
revert X n; intro n
induction' n with n hn
. simp
intro X hX g h hg hh
-- A technical step: we extend g, h to the entire integers using a slightly artificial map π
set π : ℤ → Icc (1:ℤ) (n+1) :=
fun i ↦ if hi: i ∈ Icc (1:ℤ) (n+1) then ⟨ i, hi ⟩ else ⟨ 1, by simp ⟩
have hπ (g : Icc (1:ℤ) (n+1) → X) :
∑ i ∈ Icc (1:ℤ) (n+1), (if hi:i ∈ Icc (1:ℤ) (n+1) then f (g ⟨ i, hi ⟩) else 0)
= ∑ i ∈ Icc (1:ℤ) (n+1), f (g (π i)) := by
apply sum_congr rfl _
intro i hi; simp [hi, π, -mem_Icc]
simp [-mem_Icc, hπ]
rw [sum_of_nonempty (by linarith) _]
set x := g (π (n+1))
have ⟨⟨j, hj'⟩, hj⟩ := hh.surjective x
simp at hj'; obtain ⟨ hj1, hj2 ⟩ := hj'
set h' : ℤ → X := fun i ↦ if (i:ℤ) < j then h (π i) else h (π (i+1))
have : ∑ i ∈ Icc (1:ℤ) (n + 1), f (h (π i)) = ∑ i ∈ Icc (1:ℤ) n, f (h' i) + f x := calc
_ = ∑ i ∈ Icc (1:ℤ) j, f (h (π i)) + ∑ i ∈ Icc (j+1:ℤ) (n + 1), f (h (π i)) := by
symm; apply concat_finite_series <;> linarith
_ = ∑ i ∈ Icc (1:ℤ) (j-1), f (h (π i)) + f ( h (π j) )
+ ∑ i ∈ Icc (j+1:ℤ) (n + 1), f (h (π i)) := by
congr; convert sum_of_nonempty _ _ <;> simp [hj1]
_ = ∑ i ∈ Icc (1:ℤ) (j-1), f (h (π i)) + f x + ∑ i ∈ Icc (j:ℤ) n, f (h (π (i+1))) := by
congr 1
. simp [←hj, π,hj1, hj2]
symm; convert shift_finite_series _; simp
_ = ∑ i ∈ Icc (1:ℤ) (j-1), f (h (π i)) + ∑ i ∈ Icc (j:ℤ) n, f (h (π (i+1))) + f x := by abel
_ = ∑ i ∈ Icc (1:ℤ) (j-1), f (h' i) + ∑ i ∈ Icc (j:ℤ) n, f (h' i) + f x := by
congr 2
all_goals apply sum_congr rfl _; intro i hi; simp [h'] at *
. simp [show i < j by linarith]
simp [show ¬ i < j by linarith]
_ = _ := by congr; convert concat_finite_series _ _ _ <;> linarith
rw [this]
congr 1
have g_ne_x {i:ℤ} (hi : i ∈ Icc (1:ℤ) n) : g (π i) ≠ x := by
simp at hi
simp [x, hg.injective.eq_iff, π, hi.1, show i ≤ n+1 by linarith]
linarith
have h'_ne_x {i:ℤ} (hi : i ∈ Icc (1:ℤ) n) : h' i ≠ x := by
simp at hi
have hi' : 0 ≤ i := by linarith
have hi'' : i ≤ n+1 := by linarith
by_cases hlt: i < j <;> by_contra! heq
all_goals simp [h', hlt, ←hj, hh.injective.eq_iff, ←Subtype.val_inj,
π, hi.1, hi.2, hi',hi''] at heq
. linarith
contrapose! hlt; linarith
set gtil : Icc (1:ℤ) n → X.erase x :=
fun i ↦ ⟨ (g (π i)).val, by simp [mem_erase, g_ne_x] ⟩
set htil : Icc (1:ℤ) n → X.erase x :=
fun i ↦ ⟨ (h' i).val, by simp [mem_erase, h'_ne_x] ⟩
set ftil : X.erase x → ℝ := fun y ↦ f y.val
have why : Function.Bijective gtil := by sorry
have why2 : Function.Bijective htil := by sorry
calc
_ = ∑ i ∈ Icc (1:ℤ) n, if hi: i ∈ Icc (1:ℤ) n then ftil (gtil ⟨ i, hi ⟩ ) else 0 := by
apply sum_congr rfl; grind
_ = ∑ i ∈ Icc (1:ℤ) n, if hi: i ∈ Icc (1:ℤ) n then ftil (htil ⟨ i, hi ⟩ ) else 0 := by
convert hn _ _ gtil htil why why2
rw [Finset.card_erase_of_mem _, hX] <;> simp
_ = _ := by apply sum_congr rfl; grind
/--
This fact ensures that Definition 7.1.6 would be well-defined even if we did not appeal to the
existing {name}`Finset.sum` method.
-/
theorem exist_bijection {n:ℕ} {Y:Type*} (X: Finset Y) (hcard: X.card = n) :
∃ g: Icc (1:ℤ) n → X, Function.Bijective g := by
have := Finset.equivOfCardEq (show (Icc (1:ℤ) n).card = X.card by simp [hcard])
exact ⟨ this, this.bijective ⟩
/-- Definition 7.1.6 -/
theorem finite_series_eq {n:ℕ} {Y:Type*} (X: Finset Y) (f: Y → ℝ) (g: Icc (1:ℤ) n → X)
(hg: Function.Bijective g) :
∑ i ∈ X, f i = ∑ i ∈ Icc (1:ℤ) n, (if hi:i ∈ Icc (1:ℤ) n then f (g ⟨ i, hi ⟩) else 0) := by
symm
convert sum_bij (t:=X) (fun i hi ↦ g ⟨ i, hi ⟩ ) _ _ _ _
. aesop
. intro _ _ _ _ h; simpa [Subtype.val_inj, hg.injective.eq_iff] using h
. intro b hb; have := hg.surjective ⟨ b, hb ⟩; grind
intros; simp_all
/-- Proposition 7.1.11(a) / Exercise 7.1.2 -/
theorem finite_series_of_empty {X':Type*} (f: X' → ℝ) : ∑ i ∈ ∅, f i = 0 := by sorry
/-- Proposition 7.1.11(b) / Exercise 7.1.2 -/
theorem finite_series_of_singleton {X':Type*} (f: X' → ℝ) (x₀:X') : ∑ i ∈ {x₀}, f i = f x₀ := by
sorry
/--
A technical lemma relating a sum over a finset with a sum over a fintype. Combines well with
tools such as `map_finite_series` below.
-/
theorem finite_series_of_fintype {X':Type*} (f: X' → ℝ) (X: Finset X') :
∑ x ∈ X, f x = ∑ x:X, f x.val := (sum_coe_sort X f).symm
/-- Proposition 7.1.11(c) / Exercise 7.1.2 -/
theorem map_finite_series {X:Type*} [Fintype X] [Fintype Y] (f: X → ℝ) {g:Y → X}
(hg: Function.Bijective g) :
∑ x, f x = ∑ y, f (g y) := by sorry
-- Proposition 7.1.11(d) is `rfl` in our formalism and is therefore omitted.
/-- Proposition 7.1.11(e) / Exercise 7.1.2 -/
theorem finite_series_of_disjoint_union {Z:Type*} {X Y: Finset Z} (hdisj: Disjoint X Y) (f: Z → ℝ) :
∑ z ∈ X ∪ Y, f z = ∑ z ∈ X, f z + ∑ z ∈ Y, f z := by sorry
/-- Proposition 7.1.11(f) / Exercise 7.1.2 -/
theorem finite_series_of_add {X':Type*} (f g: X' → ℝ) (X: Finset X') :
∑ x ∈ X, (f + g) x = ∑ x ∈ X, f x + ∑ x ∈ X, g x := by sorry
/-- Proposition 7.1.11(g) / Exercise 7.1.2 -/
theorem finite_series_of_const_mul {X':Type*} (f: X' → ℝ) (X: Finset X') (c:ℝ) :
∑ x ∈ X, c * f x = c * ∑ x ∈ X, f x := by sorry
/-- Proposition 7.1.11(h) / Exercise 7.1.2 -/
theorem finite_series_of_le' {X':Type*} (f g: X' → ℝ) (X: Finset X') (h: ∀ x ∈ X, f x ≤ g x) :
∑ x ∈ X, f x ≤ ∑ x ∈ X, g x := by sorry
/-- Proposition 7.1.11(i) / Exercise 7.1.2 -/
theorem abs_finite_series_le' {X':Type*} (f: X' → ℝ) (X: Finset X') :
|∑ x ∈ X, f x| ≤ ∑ x ∈ X, |f x| := by sorry
/-- Lemma 7.1.13 --/
theorem finite_series_of_finite_series {XX YY:Type*} (X: Finset XX) (Y: Finset YY)
(f: XX × YY → ℝ) :
∑ x ∈ X, ∑ y ∈ Y, f (x, y) = ∑ z ∈ X.product Y, f z := by
generalize h: X.card = n
revert X; induction' n with n hn
. sorry
intro X hX
have hnon : X.Nonempty := by grind [card_ne_zero]
choose x₀ hx₀ using hnon.exists_mem
set X' := X.erase x₀
have hcard : X'.card = n := by simp [X', card_erase_of_mem hx₀, hX]
have hunion : X = X' ∪ {x₀} := by ext x; by_cases x = x₀ <;> grind
have hdisj : Disjoint X' {x₀} := by simp [X']
calc
_ = ∑ x ∈ X', ∑ y ∈ Y, f (x, y) + ∑ x ∈ {x₀}, ∑ y ∈ Y, f (x, y) := by
convert finite_series_of_disjoint_union hdisj _
_ = ∑ x ∈ X', ∑ y ∈ Y, f (x, y) + ∑ y ∈ Y, f (x₀, y) := by
rw [finite_series_of_singleton]
_ = ∑ z ∈ X'.product Y, f z + ∑ y ∈ Y, f (x₀, y) := by rw [hn X' hcard]
_ = ∑ z ∈ X'.product Y, f z + ∑ z ∈ .product {x₀} Y, f z := by
congr 1
rw [finite_series_of_fintype, finite_series_of_fintype f]
set π : Finset.product {x₀} Y → Y :=
fun z ↦ ⟨ z.val.2, by obtain ⟨ z, hz ⟩ := z; simp at hz ⊢; grind ⟩
have hπ : Function.Bijective π := by
constructor
. intro ⟨ ⟨ x, y ⟩, hz ⟩ ⟨ ⟨ x', y' ⟩, hz' ⟩ hzz'; simp [π] at hz hz' hzz' ⊢; grind
intro ⟨ y, hy ⟩; use ⟨ (x₀, y), by simp [hy] ⟩
convert map_finite_series _ hπ with z
obtain ⟨⟨x, y⟩, hz ⟩ := z
simp at hz ⊢; grind
_ = _ := by
symm; convert finite_series_of_disjoint_union _ _
. sorry
sorry
/-- Corollary 7.1.14 (Fubini's theorem for finite series)-/
theorem finite_series_refl {XX YY:Type*} (X: Finset XX) (Y: Finset YY) (f: XX × YY → ℝ) :
∑ z ∈ X.product Y, f z = ∑ z ∈ Y.product X, f (z.2, z.1) := by
set h : Y.product X → X.product Y :=
fun z ↦ ⟨ (z.val.2, z.val.1), by obtain ⟨ z, hz ⟩ := z; simp at hz ⊢; tauto ⟩
have hh : Function.Bijective h := by
constructor
. intro ⟨ ⟨ _, _ ⟩, _ ⟩ ⟨ ⟨ _, _ ⟩, _ ⟩ _
simp_all [h]
intro ⟨ z, hz ⟩; simp at hz
use ⟨ (z.2, z.1), by simp [hz] ⟩
rw [finite_series_of_fintype]
nth_rewrite 2 [finite_series_of_fintype]
convert map_finite_series _ hh with z
theorem finite_series_comm {XX YY:Type*} (X: Finset XX) (Y: Finset YY) (f: XX × YY → ℝ) :
∑ x ∈ X, ∑ y ∈ Y, f (x, y) = ∑ y ∈ Y, ∑ x ∈ X, f (x, y) := by
rw [finite_series_of_finite_series, finite_series_refl,
finite_series_of_finite_series _ _ (fun z ↦ f (z.2, z.1))]
-- Exercise 7.1.3 : develop as many analogues as you can of the above theory for finite products
-- instead of finite sums.
#check Nat.factorial_zero
#check Nat.factorial_succ
/--
Exercise 7.1.4. Note: there may be some technicalities passing back and forth between natural
numbers and integers. Look into the tactics {tactic}`zify`, {tactic}`norm_cast`, and {tactic}`omega`
-/
theorem binomial_theorem (x y:ℝ) (n:ℕ) :
(x + y)^n
= ∑ j ∈ Icc (0:ℤ) n,
n.factorial / (j.toNat.factorial * (n-j).toNat.factorial) * x^j * y^(n - j) := by
sorry
/-- Exercise 7.1.5 -/
theorem lim_of_finite_series {X:Type*} [Fintype X] (a: X → ℕ → ℝ) (L : X → ℝ)
(h: ∀ x, Filter.atTop.Tendsto (a x) (nhds (L x))) :
Filter.atTop.Tendsto (fun n ↦ ∑ x, a x n) (nhds (∑ x, L x)) := by
sorry
/-- Exercise 7.1.6 -/
theorem sum_union_disjoint {n : ℕ} {S : Type*} [Fintype S]
(E : Fin n → Finset S)
(disj : ∀ i j : Fin n, i ≠ j → Disjoint (E i) (E j))
(cover : ∀ s : S, ∃ i, s ∈ E i)
(f : S → ℝ) :
∑ s, f s = ∑ i, ∑ s ∈ E i, f s := by
sorry
/-- {given}`aᵢ` Exercise 7.1.7. Uses {lean}`Fin m` (so {lean}`aᵢ < m`) instead of the book's {lean}`aᵢ ≤ m`;
the bound is baked into the type, and {kw (of := «term_<_»)}`<` replaces {kw (of := «term_≤_»)}`≤` to match the 0-indexed shift. -/
theorem sum_finite_col_row_counts {n m : ℕ} (a : Fin n → Fin m) :
∑ i, (a i : ℕ) = ∑ j : Fin m, {i : Fin n | j < a i}.toFinset.card := by
sorry
end Finset