src/HOL/Limits.thy
 author huffman Sun Aug 28 09:20:12 2011 -0700 (2011-08-28) changeset 44568 e6f291cb5810 parent 44342 8321948340ea child 44571 bd91b77c4cd6 permissions -rw-r--r--
discontinue many legacy theorems about LIM and LIMSEQ, in favor of tendsto theorems
1 (*  Title       : Limits.thy
2     Author      : Brian Huffman
3 *)
5 header {* Filters and Limits *}
7 theory Limits
8 imports RealVector
9 begin
11 subsection {* Filters *}
13 text {*
14   This definition also allows non-proper filters.
15 *}
17 locale is_filter =
18   fixes F :: "('a \<Rightarrow> bool) \<Rightarrow> bool"
19   assumes True: "F (\<lambda>x. True)"
20   assumes conj: "F (\<lambda>x. P x) \<Longrightarrow> F (\<lambda>x. Q x) \<Longrightarrow> F (\<lambda>x. P x \<and> Q x)"
21   assumes mono: "\<forall>x. P x \<longrightarrow> Q x \<Longrightarrow> F (\<lambda>x. P x) \<Longrightarrow> F (\<lambda>x. Q x)"
23 typedef (open) 'a filter = "{F :: ('a \<Rightarrow> bool) \<Rightarrow> bool. is_filter F}"
24 proof
25   show "(\<lambda>x. True) \<in> ?filter" by (auto intro: is_filter.intro)
26 qed
28 lemma is_filter_Rep_filter: "is_filter (Rep_filter F)"
29   using Rep_filter [of F] by simp
31 lemma Abs_filter_inverse':
32   assumes "is_filter F" shows "Rep_filter (Abs_filter F) = F"
33   using assms by (simp add: Abs_filter_inverse)
36 subsection {* Eventually *}
38 definition eventually :: "('a \<Rightarrow> bool) \<Rightarrow> 'a filter \<Rightarrow> bool"
39   where "eventually P F \<longleftrightarrow> Rep_filter F P"
41 lemma eventually_Abs_filter:
42   assumes "is_filter F" shows "eventually P (Abs_filter F) = F P"
43   unfolding eventually_def using assms by (simp add: Abs_filter_inverse)
45 lemma filter_eq_iff:
46   shows "F = F' \<longleftrightarrow> (\<forall>P. eventually P F = eventually P F')"
47   unfolding Rep_filter_inject [symmetric] fun_eq_iff eventually_def ..
49 lemma eventually_True [simp]: "eventually (\<lambda>x. True) F"
50   unfolding eventually_def
51   by (rule is_filter.True [OF is_filter_Rep_filter])
53 lemma always_eventually: "\<forall>x. P x \<Longrightarrow> eventually P F"
54 proof -
55   assume "\<forall>x. P x" hence "P = (\<lambda>x. True)" by (simp add: ext)
56   thus "eventually P F" by simp
57 qed
59 lemma eventually_mono:
60   "(\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> eventually P F \<Longrightarrow> eventually Q F"
61   unfolding eventually_def
62   by (rule is_filter.mono [OF is_filter_Rep_filter])
64 lemma eventually_conj:
65   assumes P: "eventually (\<lambda>x. P x) F"
66   assumes Q: "eventually (\<lambda>x. Q x) F"
67   shows "eventually (\<lambda>x. P x \<and> Q x) F"
68   using assms unfolding eventually_def
69   by (rule is_filter.conj [OF is_filter_Rep_filter])
71 lemma eventually_mp:
72   assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
73   assumes "eventually (\<lambda>x. P x) F"
74   shows "eventually (\<lambda>x. Q x) F"
75 proof (rule eventually_mono)
76   show "\<forall>x. (P x \<longrightarrow> Q x) \<and> P x \<longrightarrow> Q x" by simp
77   show "eventually (\<lambda>x. (P x \<longrightarrow> Q x) \<and> P x) F"
78     using assms by (rule eventually_conj)
79 qed
81 lemma eventually_rev_mp:
82   assumes "eventually (\<lambda>x. P x) F"
83   assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
84   shows "eventually (\<lambda>x. Q x) F"
85 using assms(2) assms(1) by (rule eventually_mp)
87 lemma eventually_conj_iff:
88   "eventually (\<lambda>x. P x \<and> Q x) F \<longleftrightarrow> eventually P F \<and> eventually Q F"
89   by (auto intro: eventually_conj elim: eventually_rev_mp)
91 lemma eventually_elim1:
92   assumes "eventually (\<lambda>i. P i) F"
93   assumes "\<And>i. P i \<Longrightarrow> Q i"
94   shows "eventually (\<lambda>i. Q i) F"
95   using assms by (auto elim!: eventually_rev_mp)
97 lemma eventually_elim2:
98   assumes "eventually (\<lambda>i. P i) F"
99   assumes "eventually (\<lambda>i. Q i) F"
100   assumes "\<And>i. P i \<Longrightarrow> Q i \<Longrightarrow> R i"
101   shows "eventually (\<lambda>i. R i) F"
102   using assms by (auto elim!: eventually_rev_mp)
104 subsection {* Finer-than relation *}
106 text {* @{term "F \<le> F'"} means that filter @{term F} is finer than
107 filter @{term F'}. *}
109 instantiation filter :: (type) complete_lattice
110 begin
112 definition le_filter_def:
113   "F \<le> F' \<longleftrightarrow> (\<forall>P. eventually P F' \<longrightarrow> eventually P F)"
115 definition
116   "(F :: 'a filter) < F' \<longleftrightarrow> F \<le> F' \<and> \<not> F' \<le> F"
118 definition
119   "top = Abs_filter (\<lambda>P. \<forall>x. P x)"
121 definition
122   "bot = Abs_filter (\<lambda>P. True)"
124 definition
125   "sup F F' = Abs_filter (\<lambda>P. eventually P F \<and> eventually P F')"
127 definition
128   "inf F F' = Abs_filter
129       (\<lambda>P. \<exists>Q R. eventually Q F \<and> eventually R F' \<and> (\<forall>x. Q x \<and> R x \<longrightarrow> P x))"
131 definition
132   "Sup S = Abs_filter (\<lambda>P. \<forall>F\<in>S. eventually P F)"
134 definition
135   "Inf S = Sup {F::'a filter. \<forall>F'\<in>S. F \<le> F'}"
137 lemma eventually_top [simp]: "eventually P top \<longleftrightarrow> (\<forall>x. P x)"
138   unfolding top_filter_def
139   by (rule eventually_Abs_filter, rule is_filter.intro, auto)
141 lemma eventually_bot [simp]: "eventually P bot"
142   unfolding bot_filter_def
143   by (subst eventually_Abs_filter, rule is_filter.intro, auto)
145 lemma eventually_sup:
146   "eventually P (sup F F') \<longleftrightarrow> eventually P F \<and> eventually P F'"
147   unfolding sup_filter_def
148   by (rule eventually_Abs_filter, rule is_filter.intro)
149      (auto elim!: eventually_rev_mp)
151 lemma eventually_inf:
152   "eventually P (inf F F') \<longleftrightarrow>
153    (\<exists>Q R. eventually Q F \<and> eventually R F' \<and> (\<forall>x. Q x \<and> R x \<longrightarrow> P x))"
154   unfolding inf_filter_def
155   apply (rule eventually_Abs_filter, rule is_filter.intro)
156   apply (fast intro: eventually_True)
157   apply clarify
158   apply (intro exI conjI)
159   apply (erule (1) eventually_conj)
160   apply (erule (1) eventually_conj)
161   apply simp
162   apply auto
163   done
165 lemma eventually_Sup:
166   "eventually P (Sup S) \<longleftrightarrow> (\<forall>F\<in>S. eventually P F)"
167   unfolding Sup_filter_def
168   apply (rule eventually_Abs_filter, rule is_filter.intro)
169   apply (auto intro: eventually_conj elim!: eventually_rev_mp)
170   done
172 instance proof
173   fix F F' F'' :: "'a filter" and S :: "'a filter set"
174   { show "F < F' \<longleftrightarrow> F \<le> F' \<and> \<not> F' \<le> F"
175     by (rule less_filter_def) }
176   { show "F \<le> F"
177     unfolding le_filter_def by simp }
178   { assume "F \<le> F'" and "F' \<le> F''" thus "F \<le> F''"
179     unfolding le_filter_def by simp }
180   { assume "F \<le> F'" and "F' \<le> F" thus "F = F'"
181     unfolding le_filter_def filter_eq_iff by fast }
182   { show "F \<le> top"
183     unfolding le_filter_def eventually_top by (simp add: always_eventually) }
184   { show "bot \<le> F"
185     unfolding le_filter_def by simp }
186   { show "F \<le> sup F F'" and "F' \<le> sup F F'"
187     unfolding le_filter_def eventually_sup by simp_all }
188   { assume "F \<le> F''" and "F' \<le> F''" thus "sup F F' \<le> F''"
189     unfolding le_filter_def eventually_sup by simp }
190   { show "inf F F' \<le> F" and "inf F F' \<le> F'"
191     unfolding le_filter_def eventually_inf by (auto intro: eventually_True) }
192   { assume "F \<le> F'" and "F \<le> F''" thus "F \<le> inf F' F''"
193     unfolding le_filter_def eventually_inf
194     by (auto elim!: eventually_mono intro: eventually_conj) }
195   { assume "F \<in> S" thus "F \<le> Sup S"
196     unfolding le_filter_def eventually_Sup by simp }
197   { assume "\<And>F. F \<in> S \<Longrightarrow> F \<le> F'" thus "Sup S \<le> F'"
198     unfolding le_filter_def eventually_Sup by simp }
199   { assume "F'' \<in> S" thus "Inf S \<le> F''"
200     unfolding le_filter_def Inf_filter_def eventually_Sup Ball_def by simp }
201   { assume "\<And>F'. F' \<in> S \<Longrightarrow> F \<le> F'" thus "F \<le> Inf S"
202     unfolding le_filter_def Inf_filter_def eventually_Sup Ball_def by simp }
203 qed
205 end
207 lemma filter_leD:
208   "F \<le> F' \<Longrightarrow> eventually P F' \<Longrightarrow> eventually P F"
209   unfolding le_filter_def by simp
211 lemma filter_leI:
212   "(\<And>P. eventually P F' \<Longrightarrow> eventually P F) \<Longrightarrow> F \<le> F'"
213   unfolding le_filter_def by simp
215 lemma eventually_False:
216   "eventually (\<lambda>x. False) F \<longleftrightarrow> F = bot"
217   unfolding filter_eq_iff by (auto elim: eventually_rev_mp)
219 abbreviation (input) trivial_limit :: "'a filter \<Rightarrow> bool"
220   where "trivial_limit F \<equiv> F = bot"
222 lemma trivial_limit_def: "trivial_limit F \<longleftrightarrow> eventually (\<lambda>x. False) F"
223   by (rule eventually_False [symmetric])
226 subsection {* Map function for filters *}
228 definition filtermap :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a filter \<Rightarrow> 'b filter"
229   where "filtermap f F = Abs_filter (\<lambda>P. eventually (\<lambda>x. P (f x)) F)"
231 lemma eventually_filtermap:
232   "eventually P (filtermap f F) = eventually (\<lambda>x. P (f x)) F"
233   unfolding filtermap_def
234   apply (rule eventually_Abs_filter)
235   apply (rule is_filter.intro)
236   apply (auto elim!: eventually_rev_mp)
237   done
239 lemma filtermap_ident: "filtermap (\<lambda>x. x) F = F"
240   by (simp add: filter_eq_iff eventually_filtermap)
242 lemma filtermap_filtermap:
243   "filtermap f (filtermap g F) = filtermap (\<lambda>x. f (g x)) F"
244   by (simp add: filter_eq_iff eventually_filtermap)
246 lemma filtermap_mono: "F \<le> F' \<Longrightarrow> filtermap f F \<le> filtermap f F'"
247   unfolding le_filter_def eventually_filtermap by simp
249 lemma filtermap_bot [simp]: "filtermap f bot = bot"
250   by (simp add: filter_eq_iff eventually_filtermap)
253 subsection {* Sequentially *}
255 definition sequentially :: "nat filter"
256   where "sequentially = Abs_filter (\<lambda>P. \<exists>k. \<forall>n\<ge>k. P n)"
258 lemma eventually_sequentially:
259   "eventually P sequentially \<longleftrightarrow> (\<exists>N. \<forall>n\<ge>N. P n)"
260 unfolding sequentially_def
261 proof (rule eventually_Abs_filter, rule is_filter.intro)
262   fix P Q :: "nat \<Rightarrow> bool"
263   assume "\<exists>i. \<forall>n\<ge>i. P n" and "\<exists>j. \<forall>n\<ge>j. Q n"
264   then obtain i j where "\<forall>n\<ge>i. P n" and "\<forall>n\<ge>j. Q n" by auto
265   then have "\<forall>n\<ge>max i j. P n \<and> Q n" by simp
266   then show "\<exists>k. \<forall>n\<ge>k. P n \<and> Q n" ..
267 qed auto
269 lemma sequentially_bot [simp, intro]: "sequentially \<noteq> bot"
270   unfolding filter_eq_iff eventually_sequentially by auto
272 lemmas trivial_limit_sequentially = sequentially_bot
274 lemma eventually_False_sequentially [simp]:
275   "\<not> eventually (\<lambda>n. False) sequentially"
276   by (simp add: eventually_False)
278 lemma le_sequentially:
279   "F \<le> sequentially \<longleftrightarrow> (\<forall>N. eventually (\<lambda>n. N \<le> n) F)"
280   unfolding le_filter_def eventually_sequentially
281   by (safe, fast, drule_tac x=N in spec, auto elim: eventually_rev_mp)
284 subsection {* Standard filters *}
286 definition within :: "'a filter \<Rightarrow> 'a set \<Rightarrow> 'a filter" (infixr "within" 70)
287   where "F within S = Abs_filter (\<lambda>P. eventually (\<lambda>x. x \<in> S \<longrightarrow> P x) F)"
289 definition (in topological_space) nhds :: "'a \<Rightarrow> 'a filter"
290   where "nhds a = Abs_filter (\<lambda>P. \<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
292 definition (in topological_space) at :: "'a \<Rightarrow> 'a filter"
293   where "at a = nhds a within - {a}"
295 lemma eventually_within:
296   "eventually P (F within S) = eventually (\<lambda>x. x \<in> S \<longrightarrow> P x) F"
297   unfolding within_def
298   by (rule eventually_Abs_filter, rule is_filter.intro)
299      (auto elim!: eventually_rev_mp)
301 lemma within_UNIV: "F within UNIV = F"
302   unfolding filter_eq_iff eventually_within by simp
304 lemma eventually_nhds:
305   "eventually P (nhds a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
306 unfolding nhds_def
307 proof (rule eventually_Abs_filter, rule is_filter.intro)
308   have "open UNIV \<and> a \<in> UNIV \<and> (\<forall>x\<in>UNIV. True)" by simp
309   thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. True)" by - rule
310 next
311   fix P Q
312   assume "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x)"
313      and "\<exists>T. open T \<and> a \<in> T \<and> (\<forall>x\<in>T. Q x)"
314   then obtain S T where
315     "open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x)"
316     "open T \<and> a \<in> T \<and> (\<forall>x\<in>T. Q x)" by auto
317   hence "open (S \<inter> T) \<and> a \<in> S \<inter> T \<and> (\<forall>x\<in>(S \<inter> T). P x \<and> Q x)"
318     by (simp add: open_Int)
319   thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x \<and> Q x)" by - rule
320 qed auto
322 lemma eventually_nhds_metric:
323   "eventually P (nhds a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. dist x a < d \<longrightarrow> P x)"
324 unfolding eventually_nhds open_dist
325 apply safe
326 apply fast
327 apply (rule_tac x="{x. dist x a < d}" in exI, simp)
328 apply clarsimp
329 apply (rule_tac x="d - dist x a" in exI, clarsimp)
330 apply (simp only: less_diff_eq)
331 apply (erule le_less_trans [OF dist_triangle])
332 done
334 lemma eventually_at_topological:
335   "eventually P (at a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. x \<noteq> a \<longrightarrow> P x))"
336 unfolding at_def eventually_within eventually_nhds by simp
338 lemma eventually_at:
339   fixes a :: "'a::metric_space"
340   shows "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> P x)"
341 unfolding at_def eventually_within eventually_nhds_metric by auto
344 subsection {* Boundedness *}
346 definition Bfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
347   where "Bfun f F = (\<exists>K>0. eventually (\<lambda>x. norm (f x) \<le> K) F)"
349 lemma BfunI:
350   assumes K: "eventually (\<lambda>x. norm (f x) \<le> K) F" shows "Bfun f F"
351 unfolding Bfun_def
352 proof (intro exI conjI allI)
353   show "0 < max K 1" by simp
354 next
355   show "eventually (\<lambda>x. norm (f x) \<le> max K 1) F"
356     using K by (rule eventually_elim1, simp)
357 qed
359 lemma BfunE:
360   assumes "Bfun f F"
361   obtains B where "0 < B" and "eventually (\<lambda>x. norm (f x) \<le> B) F"
362 using assms unfolding Bfun_def by fast
365 subsection {* Convergence to Zero *}
367 definition Zfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
368   where "Zfun f F = (\<forall>r>0. eventually (\<lambda>x. norm (f x) < r) F)"
370 lemma ZfunI:
371   "(\<And>r. 0 < r \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F) \<Longrightarrow> Zfun f F"
372   unfolding Zfun_def by simp
374 lemma ZfunD:
375   "\<lbrakk>Zfun f F; 0 < r\<rbrakk> \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F"
376   unfolding Zfun_def by simp
378 lemma Zfun_ssubst:
379   "eventually (\<lambda>x. f x = g x) F \<Longrightarrow> Zfun g F \<Longrightarrow> Zfun f F"
380   unfolding Zfun_def by (auto elim!: eventually_rev_mp)
382 lemma Zfun_zero: "Zfun (\<lambda>x. 0) F"
383   unfolding Zfun_def by simp
385 lemma Zfun_norm_iff: "Zfun (\<lambda>x. norm (f x)) F = Zfun (\<lambda>x. f x) F"
386   unfolding Zfun_def by simp
388 lemma Zfun_imp_Zfun:
389   assumes f: "Zfun f F"
390   assumes g: "eventually (\<lambda>x. norm (g x) \<le> norm (f x) * K) F"
391   shows "Zfun (\<lambda>x. g x) F"
392 proof (cases)
393   assume K: "0 < K"
394   show ?thesis
395   proof (rule ZfunI)
396     fix r::real assume "0 < r"
397     hence "0 < r / K"
398       using K by (rule divide_pos_pos)
399     then have "eventually (\<lambda>x. norm (f x) < r / K) F"
400       using ZfunD [OF f] by fast
401     with g show "eventually (\<lambda>x. norm (g x) < r) F"
402     proof (rule eventually_elim2)
403       fix x
404       assume *: "norm (g x) \<le> norm (f x) * K"
405       assume "norm (f x) < r / K"
406       hence "norm (f x) * K < r"
407         by (simp add: pos_less_divide_eq K)
408       thus "norm (g x) < r"
409         by (simp add: order_le_less_trans [OF *])
410     qed
411   qed
412 next
413   assume "\<not> 0 < K"
414   hence K: "K \<le> 0" by (simp only: not_less)
415   show ?thesis
416   proof (rule ZfunI)
417     fix r :: real
418     assume "0 < r"
419     from g show "eventually (\<lambda>x. norm (g x) < r) F"
420     proof (rule eventually_elim1)
421       fix x
422       assume "norm (g x) \<le> norm (f x) * K"
423       also have "\<dots> \<le> norm (f x) * 0"
424         using K norm_ge_zero by (rule mult_left_mono)
425       finally show "norm (g x) < r"
426         using `0 < r` by simp
427     qed
428   qed
429 qed
431 lemma Zfun_le: "\<lbrakk>Zfun g F; \<forall>x. norm (f x) \<le> norm (g x)\<rbrakk> \<Longrightarrow> Zfun f F"
432   by (erule_tac K="1" in Zfun_imp_Zfun, simp)
435   assumes f: "Zfun f F" and g: "Zfun g F"
436   shows "Zfun (\<lambda>x. f x + g x) F"
437 proof (rule ZfunI)
438   fix r::real assume "0 < r"
439   hence r: "0 < r / 2" by simp
440   have "eventually (\<lambda>x. norm (f x) < r/2) F"
441     using f r by (rule ZfunD)
442   moreover
443   have "eventually (\<lambda>x. norm (g x) < r/2) F"
444     using g r by (rule ZfunD)
445   ultimately
446   show "eventually (\<lambda>x. norm (f x + g x) < r) F"
447   proof (rule eventually_elim2)
448     fix x
449     assume *: "norm (f x) < r/2" "norm (g x) < r/2"
450     have "norm (f x + g x) \<le> norm (f x) + norm (g x)"
451       by (rule norm_triangle_ineq)
452     also have "\<dots> < r/2 + r/2"
453       using * by (rule add_strict_mono)
454     finally show "norm (f x + g x) < r"
455       by simp
456   qed
457 qed
459 lemma Zfun_minus: "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. - f x) F"
460   unfolding Zfun_def by simp
462 lemma Zfun_diff: "\<lbrakk>Zfun f F; Zfun g F\<rbrakk> \<Longrightarrow> Zfun (\<lambda>x. f x - g x) F"
463   by (simp only: diff_minus Zfun_add Zfun_minus)
465 lemma (in bounded_linear) Zfun:
466   assumes g: "Zfun g F"
467   shows "Zfun (\<lambda>x. f (g x)) F"
468 proof -
469   obtain K where "\<And>x. norm (f x) \<le> norm x * K"
470     using bounded by fast
471   then have "eventually (\<lambda>x. norm (f (g x)) \<le> norm (g x) * K) F"
472     by simp
473   with g show ?thesis
474     by (rule Zfun_imp_Zfun)
475 qed
477 lemma (in bounded_bilinear) Zfun:
478   assumes f: "Zfun f F"
479   assumes g: "Zfun g F"
480   shows "Zfun (\<lambda>x. f x ** g x) F"
481 proof (rule ZfunI)
482   fix r::real assume r: "0 < r"
483   obtain K where K: "0 < K"
484     and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
485     using pos_bounded by fast
486   from K have K': "0 < inverse K"
487     by (rule positive_imp_inverse_positive)
488   have "eventually (\<lambda>x. norm (f x) < r) F"
489     using f r by (rule ZfunD)
490   moreover
491   have "eventually (\<lambda>x. norm (g x) < inverse K) F"
492     using g K' by (rule ZfunD)
493   ultimately
494   show "eventually (\<lambda>x. norm (f x ** g x) < r) F"
495   proof (rule eventually_elim2)
496     fix x
497     assume *: "norm (f x) < r" "norm (g x) < inverse K"
498     have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
499       by (rule norm_le)
500     also have "norm (f x) * norm (g x) * K < r * inverse K * K"
501       by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero * K)
502     also from K have "r * inverse K * K = r"
503       by simp
504     finally show "norm (f x ** g x) < r" .
505   qed
506 qed
508 lemma (in bounded_bilinear) Zfun_left:
509   "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. f x ** a) F"
510   by (rule bounded_linear_left [THEN bounded_linear.Zfun])
512 lemma (in bounded_bilinear) Zfun_right:
513   "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. a ** f x) F"
514   by (rule bounded_linear_right [THEN bounded_linear.Zfun])
516 lemmas Zfun_mult = bounded_bilinear.Zfun [OF bounded_bilinear_mult]
517 lemmas Zfun_mult_right = bounded_bilinear.Zfun_right [OF bounded_bilinear_mult]
518 lemmas Zfun_mult_left = bounded_bilinear.Zfun_left [OF bounded_bilinear_mult]
521 subsection {* Limits *}
523 definition (in topological_space)
524   tendsto :: "('b \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'b filter \<Rightarrow> bool" (infixr "--->" 55) where
525   "(f ---> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
527 ML {*
528 structure Tendsto_Intros = Named_Thms
529 (
530   val name = "tendsto_intros"
531   val description = "introduction rules for tendsto"
532 )
533 *}
535 setup Tendsto_Intros.setup
537 lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f ---> l) F' \<Longrightarrow> (f ---> l) F"
538   unfolding tendsto_def le_filter_def by fast
540 lemma topological_tendstoI:
541   "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F)
542     \<Longrightarrow> (f ---> l) F"
543   unfolding tendsto_def by auto
545 lemma topological_tendstoD:
546   "(f ---> l) F \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
547   unfolding tendsto_def by auto
549 lemma tendstoI:
550   assumes "\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
551   shows "(f ---> l) F"
552   apply (rule topological_tendstoI)
553   apply (simp add: open_dist)
554   apply (drule (1) bspec, clarify)
555   apply (drule assms)
556   apply (erule eventually_elim1, simp)
557   done
559 lemma tendstoD:
560   "(f ---> l) F \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
561   apply (drule_tac S="{x. dist x l < e}" in topological_tendstoD)
562   apply (clarsimp simp add: open_dist)
563   apply (rule_tac x="e - dist x l" in exI, clarsimp)
564   apply (simp only: less_diff_eq)
565   apply (erule le_less_trans [OF dist_triangle])
566   apply simp
567   apply simp
568   done
570 lemma tendsto_iff:
571   "(f ---> l) F \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) F)"
572   using tendstoI tendstoD by fast
574 lemma tendsto_Zfun_iff: "(f ---> a) F = Zfun (\<lambda>x. f x - a) F"
575   by (simp only: tendsto_iff Zfun_def dist_norm)
577 lemma tendsto_ident_at [tendsto_intros]: "((\<lambda>x. x) ---> a) (at a)"
578   unfolding tendsto_def eventually_at_topological by auto
580 lemma tendsto_ident_at_within [tendsto_intros]:
581   "((\<lambda>x. x) ---> a) (at a within S)"
582   unfolding tendsto_def eventually_within eventually_at_topological by auto
584 lemma tendsto_const [tendsto_intros]: "((\<lambda>x. k) ---> k) F"
585   by (simp add: tendsto_def)
587 lemma tendsto_unique:
588   fixes f :: "'a \<Rightarrow> 'b::t2_space"
589   assumes "\<not> trivial_limit F" and "(f ---> a) F" and "(f ---> b) F"
590   shows "a = b"
591 proof (rule ccontr)
592   assume "a \<noteq> b"
593   obtain U V where "open U" "open V" "a \<in> U" "b \<in> V" "U \<inter> V = {}"
594     using hausdorff [OF `a \<noteq> b`] by fast
595   have "eventually (\<lambda>x. f x \<in> U) F"
596     using `(f ---> a) F` `open U` `a \<in> U` by (rule topological_tendstoD)
597   moreover
598   have "eventually (\<lambda>x. f x \<in> V) F"
599     using `(f ---> b) F` `open V` `b \<in> V` by (rule topological_tendstoD)
600   ultimately
601   have "eventually (\<lambda>x. False) F"
602   proof (rule eventually_elim2)
603     fix x
604     assume "f x \<in> U" "f x \<in> V"
605     hence "f x \<in> U \<inter> V" by simp
606     with `U \<inter> V = {}` show "False" by simp
607   qed
608   with `\<not> trivial_limit F` show "False"
609     by (simp add: trivial_limit_def)
610 qed
612 lemma tendsto_const_iff:
613   fixes a b :: "'a::t2_space"
614   assumes "\<not> trivial_limit F" shows "((\<lambda>x. a) ---> b) F \<longleftrightarrow> a = b"
615   by (safe intro!: tendsto_const tendsto_unique [OF assms tendsto_const])
617 lemma tendsto_compose:
618   assumes g: "(g ---> g l) (at l)"
619   assumes f: "(f ---> l) F"
620   shows "((\<lambda>x. g (f x)) ---> g l) F"
621 proof (rule topological_tendstoI)
622   fix B assume B: "open B" "g l \<in> B"
623   obtain A where A: "open A" "l \<in> A"
624     and gB: "\<forall>y. y \<in> A \<longrightarrow> g y \<in> B"
625     using topological_tendstoD [OF g B] B(2)
626     unfolding eventually_at_topological by fast
627   hence "\<forall>x. f x \<in> A \<longrightarrow> g (f x) \<in> B" by simp
628   from this topological_tendstoD [OF f A]
629   show "eventually (\<lambda>x. g (f x) \<in> B) F"
630     by (rule eventually_mono)
631 qed
633 lemma tendsto_compose_eventually:
634   assumes g: "(g ---> m) (at l)"
635   assumes f: "(f ---> l) F"
636   assumes inj: "eventually (\<lambda>x. f x \<noteq> l) F"
637   shows "((\<lambda>x. g (f x)) ---> m) F"
638 proof (rule topological_tendstoI)
639   fix B assume B: "open B" "m \<in> B"
640   obtain A where A: "open A" "l \<in> A"
641     and gB: "\<And>y. y \<in> A \<Longrightarrow> y \<noteq> l \<Longrightarrow> g y \<in> B"
642     using topological_tendstoD [OF g B]
643     unfolding eventually_at_topological by fast
644   show "eventually (\<lambda>x. g (f x) \<in> B) F"
645     using topological_tendstoD [OF f A] inj
646     by (rule eventually_elim2) (simp add: gB)
647 qed
649 lemma metric_tendsto_imp_tendsto:
650   assumes f: "(f ---> a) F"
651   assumes le: "eventually (\<lambda>x. dist (g x) b \<le> dist (f x) a) F"
652   shows "(g ---> b) F"
653 proof (rule tendstoI)
654   fix e :: real assume "0 < e"
655   with f have "eventually (\<lambda>x. dist (f x) a < e) F" by (rule tendstoD)
656   with le show "eventually (\<lambda>x. dist (g x) b < e) F"
657     using le_less_trans by (rule eventually_elim2)
658 qed
660 subsubsection {* Distance and norms *}
662 lemma tendsto_dist [tendsto_intros]:
663   assumes f: "(f ---> l) F" and g: "(g ---> m) F"
664   shows "((\<lambda>x. dist (f x) (g x)) ---> dist l m) F"
665 proof (rule tendstoI)
666   fix e :: real assume "0 < e"
667   hence e2: "0 < e/2" by simp
668   from tendstoD [OF f e2] tendstoD [OF g e2]
669   show "eventually (\<lambda>x. dist (dist (f x) (g x)) (dist l m) < e) F"
670   proof (rule eventually_elim2)
671     fix x assume "dist (f x) l < e/2" "dist (g x) m < e/2"
672     then show "dist (dist (f x) (g x)) (dist l m) < e"
673       unfolding dist_real_def
674       using dist_triangle2 [of "f x" "g x" "l"]
675       using dist_triangle2 [of "g x" "l" "m"]
676       using dist_triangle3 [of "l" "m" "f x"]
677       using dist_triangle [of "f x" "m" "g x"]
678       by arith
679   qed
680 qed
682 lemma norm_conv_dist: "norm x = dist x 0"
683   unfolding dist_norm by simp
685 lemma tendsto_norm [tendsto_intros]:
686   "(f ---> a) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> norm a) F"
687   unfolding norm_conv_dist by (intro tendsto_intros)
689 lemma tendsto_norm_zero:
690   "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> 0) F"
691   by (drule tendsto_norm, simp)
693 lemma tendsto_norm_zero_cancel:
694   "((\<lambda>x. norm (f x)) ---> 0) F \<Longrightarrow> (f ---> 0) F"
695   unfolding tendsto_iff dist_norm by simp
697 lemma tendsto_norm_zero_iff:
698   "((\<lambda>x. norm (f x)) ---> 0) F \<longleftrightarrow> (f ---> 0) F"
699   unfolding tendsto_iff dist_norm by simp
701 lemma tendsto_rabs [tendsto_intros]:
702   "(f ---> (l::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> \<bar>l\<bar>) F"
703   by (fold real_norm_def, rule tendsto_norm)
705 lemma tendsto_rabs_zero:
706   "(f ---> (0::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> 0) F"
707   by (fold real_norm_def, rule tendsto_norm_zero)
709 lemma tendsto_rabs_zero_cancel:
710   "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<Longrightarrow> (f ---> 0) F"
711   by (fold real_norm_def, rule tendsto_norm_zero_cancel)
713 lemma tendsto_rabs_zero_iff:
714   "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<longleftrightarrow> (f ---> 0) F"
715   by (fold real_norm_def, rule tendsto_norm_zero_iff)
717 subsubsection {* Addition and subtraction *}
719 lemma tendsto_add [tendsto_intros]:
720   fixes a b :: "'a::real_normed_vector"
721   shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> a + b) F"
725   fixes f g :: "'a::type \<Rightarrow> 'b::real_normed_vector"
726   shows "\<lbrakk>(f ---> 0) F; (g ---> 0) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> 0) F"
727   by (drule (1) tendsto_add, simp)
729 lemma tendsto_minus [tendsto_intros]:
730   fixes a :: "'a::real_normed_vector"
731   shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. - f x) ---> - a) F"
732   by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
734 lemma tendsto_minus_cancel:
735   fixes a :: "'a::real_normed_vector"
736   shows "((\<lambda>x. - f x) ---> - a) F \<Longrightarrow> (f ---> a) F"
737   by (drule tendsto_minus, simp)
739 lemma tendsto_diff [tendsto_intros]:
740   fixes a b :: "'a::real_normed_vector"
741   shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x - g x) ---> a - b) F"
742   by (simp add: diff_minus tendsto_add tendsto_minus)
744 lemma tendsto_setsum [tendsto_intros]:
745   fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
746   assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> a i) F"
747   shows "((\<lambda>x. \<Sum>i\<in>S. f i x) ---> (\<Sum>i\<in>S. a i)) F"
748 proof (cases "finite S")
749   assume "finite S" thus ?thesis using assms
751 next
752   assume "\<not> finite S" thus ?thesis
753     by (simp add: tendsto_const)
754 qed
756 subsubsection {* Linear operators and multiplication *}
758 lemma (in bounded_linear) tendsto:
759   "(g ---> a) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> f a) F"
760   by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
762 lemma (in bounded_linear) tendsto_zero:
763   "(g ---> 0) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> 0) F"
764   by (drule tendsto, simp only: zero)
766 lemma (in bounded_bilinear) tendsto:
767   "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x ** g x) ---> a ** b) F"
768   by (simp only: tendsto_Zfun_iff prod_diff_prod
769                  Zfun_add Zfun Zfun_left Zfun_right)
771 lemma (in bounded_bilinear) tendsto_zero:
772   assumes f: "(f ---> 0) F"
773   assumes g: "(g ---> 0) F"
774   shows "((\<lambda>x. f x ** g x) ---> 0) F"
775   using tendsto [OF f g] by (simp add: zero_left)
777 lemma (in bounded_bilinear) tendsto_left_zero:
778   "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. f x ** c) ---> 0) F"
779   by (rule bounded_linear.tendsto_zero [OF bounded_linear_left])
781 lemma (in bounded_bilinear) tendsto_right_zero:
782   "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. c ** f x) ---> 0) F"
783   by (rule bounded_linear.tendsto_zero [OF bounded_linear_right])
785 lemmas tendsto_of_real [tendsto_intros] =
786   bounded_linear.tendsto [OF bounded_linear_of_real]
788 lemmas tendsto_scaleR [tendsto_intros] =
789   bounded_bilinear.tendsto [OF bounded_bilinear_scaleR]
791 lemmas tendsto_mult [tendsto_intros] =
792   bounded_bilinear.tendsto [OF bounded_bilinear_mult]
794 lemmas tendsto_mult_zero =
795   bounded_bilinear.tendsto_zero [OF bounded_bilinear_mult]
797 lemmas tendsto_mult_left_zero =
798   bounded_bilinear.tendsto_left_zero [OF bounded_bilinear_mult]
800 lemmas tendsto_mult_right_zero =
801   bounded_bilinear.tendsto_right_zero [OF bounded_bilinear_mult]
803 lemma tendsto_power [tendsto_intros]:
804   fixes f :: "'a \<Rightarrow> 'b::{power,real_normed_algebra}"
805   shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. f x ^ n) ---> a ^ n) F"
806   by (induct n) (simp_all add: tendsto_const tendsto_mult)
808 lemma tendsto_setprod [tendsto_intros]:
809   fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
810   assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> L i) F"
811   shows "((\<lambda>x. \<Prod>i\<in>S. f i x) ---> (\<Prod>i\<in>S. L i)) F"
812 proof (cases "finite S")
813   assume "finite S" thus ?thesis using assms
814     by (induct, simp add: tendsto_const, simp add: tendsto_mult)
815 next
816   assume "\<not> finite S" thus ?thesis
817     by (simp add: tendsto_const)
818 qed
820 subsubsection {* Inverse and division *}
822 lemma (in bounded_bilinear) Zfun_prod_Bfun:
823   assumes f: "Zfun f F"
824   assumes g: "Bfun g F"
825   shows "Zfun (\<lambda>x. f x ** g x) F"
826 proof -
827   obtain K where K: "0 \<le> K"
828     and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
829     using nonneg_bounded by fast
830   obtain B where B: "0 < B"
831     and norm_g: "eventually (\<lambda>x. norm (g x) \<le> B) F"
832     using g by (rule BfunE)
833   have "eventually (\<lambda>x. norm (f x ** g x) \<le> norm (f x) * (B * K)) F"
834   using norm_g proof (rule eventually_elim1)
835     fix x
836     assume *: "norm (g x) \<le> B"
837     have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
838       by (rule norm_le)
839     also have "\<dots> \<le> norm (f x) * B * K"
840       by (intro mult_mono' order_refl norm_g norm_ge_zero
841                 mult_nonneg_nonneg K *)
842     also have "\<dots> = norm (f x) * (B * K)"
843       by (rule mult_assoc)
844     finally show "norm (f x ** g x) \<le> norm (f x) * (B * K)" .
845   qed
846   with f show ?thesis
847     by (rule Zfun_imp_Zfun)
848 qed
850 lemma (in bounded_bilinear) flip:
851   "bounded_bilinear (\<lambda>x y. y ** x)"
852   apply default
853   apply (rule add_right)
854   apply (rule add_left)
855   apply (rule scaleR_right)
856   apply (rule scaleR_left)
857   apply (subst mult_commute)
858   using bounded by fast
860 lemma (in bounded_bilinear) Bfun_prod_Zfun:
861   assumes f: "Bfun f F"
862   assumes g: "Zfun g F"
863   shows "Zfun (\<lambda>x. f x ** g x) F"
864   using flip g f by (rule bounded_bilinear.Zfun_prod_Bfun)
866 lemma Bfun_inverse_lemma:
867   fixes x :: "'a::real_normed_div_algebra"
868   shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
869   apply (subst nonzero_norm_inverse, clarsimp)
870   apply (erule (1) le_imp_inverse_le)
871   done
873 lemma Bfun_inverse:
874   fixes a :: "'a::real_normed_div_algebra"
875   assumes f: "(f ---> a) F"
876   assumes a: "a \<noteq> 0"
877   shows "Bfun (\<lambda>x. inverse (f x)) F"
878 proof -
879   from a have "0 < norm a" by simp
880   hence "\<exists>r>0. r < norm a" by (rule dense)
881   then obtain r where r1: "0 < r" and r2: "r < norm a" by fast
882   have "eventually (\<lambda>x. dist (f x) a < r) F"
883     using tendstoD [OF f r1] by fast
884   hence "eventually (\<lambda>x. norm (inverse (f x)) \<le> inverse (norm a - r)) F"
885   proof (rule eventually_elim1)
886     fix x
887     assume "dist (f x) a < r"
888     hence 1: "norm (f x - a) < r"
889       by (simp add: dist_norm)
890     hence 2: "f x \<noteq> 0" using r2 by auto
891     hence "norm (inverse (f x)) = inverse (norm (f x))"
892       by (rule nonzero_norm_inverse)
893     also have "\<dots> \<le> inverse (norm a - r)"
894     proof (rule le_imp_inverse_le)
895       show "0 < norm a - r" using r2 by simp
896     next
897       have "norm a - norm (f x) \<le> norm (a - f x)"
898         by (rule norm_triangle_ineq2)
899       also have "\<dots> = norm (f x - a)"
900         by (rule norm_minus_commute)
901       also have "\<dots> < r" using 1 .
902       finally show "norm a - r \<le> norm (f x)" by simp
903     qed
904     finally show "norm (inverse (f x)) \<le> inverse (norm a - r)" .
905   qed
906   thus ?thesis by (rule BfunI)
907 qed
909 lemma tendsto_inverse_lemma:
910   fixes a :: "'a::real_normed_div_algebra"
911   shows "\<lbrakk>(f ---> a) F; a \<noteq> 0; eventually (\<lambda>x. f x \<noteq> 0) F\<rbrakk>
912          \<Longrightarrow> ((\<lambda>x. inverse (f x)) ---> inverse a) F"
913   apply (subst tendsto_Zfun_iff)
914   apply (rule Zfun_ssubst)
915   apply (erule eventually_elim1)
916   apply (erule (1) inverse_diff_inverse)
917   apply (rule Zfun_minus)
918   apply (rule Zfun_mult_left)
919   apply (rule bounded_bilinear.Bfun_prod_Zfun [OF bounded_bilinear_mult])
920   apply (erule (1) Bfun_inverse)
921   apply (simp add: tendsto_Zfun_iff)
922   done
924 lemma tendsto_inverse [tendsto_intros]:
925   fixes a :: "'a::real_normed_div_algebra"
926   assumes f: "(f ---> a) F"
927   assumes a: "a \<noteq> 0"
928   shows "((\<lambda>x. inverse (f x)) ---> inverse a) F"
929 proof -
930   from a have "0 < norm a" by simp
931   with f have "eventually (\<lambda>x. dist (f x) a < norm a) F"
932     by (rule tendstoD)
933   then have "eventually (\<lambda>x. f x \<noteq> 0) F"
934     unfolding dist_norm by (auto elim!: eventually_elim1)
935   with f a show ?thesis
936     by (rule tendsto_inverse_lemma)
937 qed
939 lemma tendsto_divide [tendsto_intros]:
940   fixes a b :: "'a::real_normed_field"
941   shows "\<lbrakk>(f ---> a) F; (g ---> b) F; b \<noteq> 0\<rbrakk>
942     \<Longrightarrow> ((\<lambda>x. f x / g x) ---> a / b) F"
943   by (simp add: tendsto_mult tendsto_inverse divide_inverse)
945 lemma tendsto_sgn [tendsto_intros]:
946   fixes l :: "'a::real_normed_vector"
947   shows "\<lbrakk>(f ---> l) F; l \<noteq> 0\<rbrakk> \<Longrightarrow> ((\<lambda>x. sgn (f x)) ---> sgn l) F"
948   unfolding sgn_div_norm by (simp add: tendsto_intros)
950 end