src/HOL/Limits.thy
 author huffman Sat May 01 09:43:40 2010 -0700 (2010-05-01) changeset 36629 de62713aec6e parent 36360 9d8f7efd9289 child 36630 aa1f8acdcc1c permissions -rw-r--r--
swap ordering on nets, so x <= y means 'x is finer than y'
1 (*  Title       : Limits.thy
2     Author      : Brian Huffman
3 *)
5 header {* Filters and Limits *}
7 theory Limits
8 imports RealVector RComplete
9 begin
11 subsection {* Nets *}
13 text {*
14   A net is now defined simply as a filter.
15   The definition also allows non-proper filters.
16 *}
18 locale is_filter =
19   fixes net :: "('a \<Rightarrow> bool) \<Rightarrow> bool"
20   assumes True: "net (\<lambda>x. True)"
21   assumes conj: "net (\<lambda>x. P x) \<Longrightarrow> net (\<lambda>x. Q x) \<Longrightarrow> net (\<lambda>x. P x \<and> Q x)"
22   assumes mono: "\<forall>x. P x \<longrightarrow> Q x \<Longrightarrow> net (\<lambda>x. P x) \<Longrightarrow> net (\<lambda>x. Q x)"
24 typedef (open) 'a net =
25   "{net :: ('a \<Rightarrow> bool) \<Rightarrow> bool. is_filter net}"
26 proof
27   show "(\<lambda>x. True) \<in> ?net" by (auto intro: is_filter.intro)
28 qed
30 lemma is_filter_Rep_net: "is_filter (Rep_net net)"
31 using Rep_net [of net] by simp
33 lemma Abs_net_inverse':
34   assumes "is_filter net" shows "Rep_net (Abs_net net) = net"
35 using assms by (simp add: Abs_net_inverse)
38 subsection {* Eventually *}
40 definition
41   eventually :: "('a \<Rightarrow> bool) \<Rightarrow> 'a net \<Rightarrow> bool" where
42   [code del]: "eventually P net \<longleftrightarrow> Rep_net net P"
44 lemma eventually_Abs_net:
45   assumes "is_filter net" shows "eventually P (Abs_net net) = net P"
46 unfolding eventually_def using assms by (simp add: Abs_net_inverse)
48 lemma expand_net_eq:
49   shows "net = net' \<longleftrightarrow> (\<forall>P. eventually P net = eventually P net')"
50 unfolding Rep_net_inject [symmetric] expand_fun_eq eventually_def ..
52 lemma eventually_True [simp]: "eventually (\<lambda>x. True) net"
53 unfolding eventually_def
54 by (rule is_filter.True [OF is_filter_Rep_net])
56 lemma eventually_mono:
57   "(\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> eventually P net \<Longrightarrow> eventually Q net"
58 unfolding eventually_def
59 by (rule is_filter.mono [OF is_filter_Rep_net])
61 lemma eventually_conj:
62   assumes P: "eventually (\<lambda>x. P x) net"
63   assumes Q: "eventually (\<lambda>x. Q x) net"
64   shows "eventually (\<lambda>x. P x \<and> Q x) net"
65 using assms unfolding eventually_def
66 by (rule is_filter.conj [OF is_filter_Rep_net])
68 lemma eventually_mp:
69   assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) net"
70   assumes "eventually (\<lambda>x. P x) net"
71   shows "eventually (\<lambda>x. Q x) net"
72 proof (rule eventually_mono)
73   show "\<forall>x. (P x \<longrightarrow> Q x) \<and> P x \<longrightarrow> Q x" by simp
74   show "eventually (\<lambda>x. (P x \<longrightarrow> Q x) \<and> P x) net"
75     using assms by (rule eventually_conj)
76 qed
78 lemma eventually_rev_mp:
79   assumes "eventually (\<lambda>x. P x) net"
80   assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) net"
81   shows "eventually (\<lambda>x. Q x) net"
82 using assms(2) assms(1) by (rule eventually_mp)
84 lemma eventually_conj_iff:
85   "eventually (\<lambda>x. P x \<and> Q x) net \<longleftrightarrow> eventually P net \<and> eventually Q net"
86 by (auto intro: eventually_conj elim: eventually_rev_mp)
88 lemma eventually_elim1:
89   assumes "eventually (\<lambda>i. P i) net"
90   assumes "\<And>i. P i \<Longrightarrow> Q i"
91   shows "eventually (\<lambda>i. Q i) net"
92 using assms by (auto elim!: eventually_rev_mp)
94 lemma eventually_elim2:
95   assumes "eventually (\<lambda>i. P i) net"
96   assumes "eventually (\<lambda>i. Q i) net"
97   assumes "\<And>i. P i \<Longrightarrow> Q i \<Longrightarrow> R i"
98   shows "eventually (\<lambda>i. R i) net"
99 using assms by (auto elim!: eventually_rev_mp)
102 subsection {* Finer-than relation *}
104 text {* @{term "net \<le> net'"} means that @{term net} is finer than
105 @{term net'}. *}
107 instantiation net :: (type) "{order,bot}"
108 begin
110 definition
111   le_net_def [code del]:
112     "net \<le> net' \<longleftrightarrow> (\<forall>P. eventually P net' \<longrightarrow> eventually P net)"
114 definition
115   less_net_def [code del]:
116     "(net :: 'a net) < net' \<longleftrightarrow> net \<le> net' \<and> \<not> net' \<le> net"
118 definition
119   bot_net_def [code del]:
120     "bot = Abs_net (\<lambda>P. True)"
122 lemma eventually_bot [simp]: "eventually P bot"
123 unfolding bot_net_def
124 by (subst eventually_Abs_net, rule is_filter.intro, auto)
126 instance proof
127   fix x y :: "'a net" show "x < y \<longleftrightarrow> x \<le> y \<and> \<not> y \<le> x"
128     by (rule less_net_def)
129 next
130   fix x :: "'a net" show "x \<le> x"
131     unfolding le_net_def by simp
132 next
133   fix x y z :: "'a net" assume "x \<le> y" and "y \<le> z" thus "x \<le> z"
134     unfolding le_net_def by simp
135 next
136   fix x y :: "'a net" assume "x \<le> y" and "y \<le> x" thus "x = y"
137     unfolding le_net_def expand_net_eq by fast
138 next
139   fix x :: "'a net" show "bot \<le> x"
140     unfolding le_net_def by simp
141 qed
143 end
145 lemma net_leD:
146   "net \<le> net' \<Longrightarrow> eventually P net' \<Longrightarrow> eventually P net"
147 unfolding le_net_def by simp
149 lemma net_leI:
150   "(\<And>P. eventually P net' \<Longrightarrow> eventually P net) \<Longrightarrow> net \<le> net'"
151 unfolding le_net_def by simp
153 lemma eventually_False:
154   "eventually (\<lambda>x. False) net \<longleftrightarrow> net = bot"
155 unfolding expand_net_eq by (auto elim: eventually_rev_mp)
158 subsection {* Standard Nets *}
160 definition
161   sequentially :: "nat net"
162 where [code del]:
163   "sequentially = Abs_net (\<lambda>P. \<exists>k. \<forall>n\<ge>k. P n)"
165 definition
166   within :: "'a net \<Rightarrow> 'a set \<Rightarrow> 'a net" (infixr "within" 70)
167 where [code del]:
168   "net within S = Abs_net (\<lambda>P. eventually (\<lambda>x. x \<in> S \<longrightarrow> P x) net)"
170 definition
171   at :: "'a::topological_space \<Rightarrow> 'a net"
172 where [code del]:
173   "at a = Abs_net (\<lambda>P. \<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. x \<noteq> a \<longrightarrow> P x))"
175 lemma eventually_sequentially:
176   "eventually P sequentially \<longleftrightarrow> (\<exists>N. \<forall>n\<ge>N. P n)"
177 unfolding sequentially_def
178 proof (rule eventually_Abs_net, rule is_filter.intro)
179   fix P Q :: "nat \<Rightarrow> bool"
180   assume "\<exists>i. \<forall>n\<ge>i. P n" and "\<exists>j. \<forall>n\<ge>j. Q n"
181   then obtain i j where "\<forall>n\<ge>i. P n" and "\<forall>n\<ge>j. Q n" by auto
182   then have "\<forall>n\<ge>max i j. P n \<and> Q n" by simp
183   then show "\<exists>k. \<forall>n\<ge>k. P n \<and> Q n" ..
184 qed auto
186 lemma eventually_within:
187   "eventually P (net within S) = eventually (\<lambda>x. x \<in> S \<longrightarrow> P x) net"
188 unfolding within_def
189 by (rule eventually_Abs_net, rule is_filter.intro)
190    (auto elim!: eventually_rev_mp)
192 lemma within_UNIV: "net within UNIV = net"
193   unfolding expand_net_eq eventually_within by simp
195 lemma eventually_at_topological:
196   "eventually P (at a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. x \<noteq> a \<longrightarrow> P x))"
197 unfolding at_def
198 proof (rule eventually_Abs_net, rule is_filter.intro)
199   have "open UNIV \<and> a \<in> UNIV \<and> (\<forall>x\<in>UNIV. x \<noteq> a \<longrightarrow> True)" by simp
200   thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. x \<noteq> a \<longrightarrow> True)" by - rule
201 next
202   fix P Q
203   assume "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. x \<noteq> a \<longrightarrow> P x)"
204      and "\<exists>T. open T \<and> a \<in> T \<and> (\<forall>x\<in>T. x \<noteq> a \<longrightarrow> Q x)"
205   then obtain S T where
206     "open S \<and> a \<in> S \<and> (\<forall>x\<in>S. x \<noteq> a \<longrightarrow> P x)"
207     "open T \<and> a \<in> T \<and> (\<forall>x\<in>T. x \<noteq> a \<longrightarrow> Q x)" by auto
208   hence "open (S \<inter> T) \<and> a \<in> S \<inter> T \<and> (\<forall>x\<in>(S \<inter> T). x \<noteq> a \<longrightarrow> P x \<and> Q x)"
209     by (simp add: open_Int)
210   thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. x \<noteq> a \<longrightarrow> P x \<and> Q x)" by - rule
211 qed auto
213 lemma eventually_at:
214   fixes a :: "'a::metric_space"
215   shows "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> P x)"
216 unfolding eventually_at_topological open_dist
217 apply safe
218 apply fast
219 apply (rule_tac x="{x. dist x a < d}" in exI, simp)
220 apply clarsimp
221 apply (rule_tac x="d - dist x a" in exI, clarsimp)
222 apply (simp only: less_diff_eq)
223 apply (erule le_less_trans [OF dist_triangle])
224 done
227 subsection {* Boundedness *}
229 definition
230   Bfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a net \<Rightarrow> bool" where
231   [code del]: "Bfun f net = (\<exists>K>0. eventually (\<lambda>x. norm (f x) \<le> K) net)"
233 lemma BfunI:
234   assumes K: "eventually (\<lambda>x. norm (f x) \<le> K) net" shows "Bfun f net"
235 unfolding Bfun_def
236 proof (intro exI conjI allI)
237   show "0 < max K 1" by simp
238 next
239   show "eventually (\<lambda>x. norm (f x) \<le> max K 1) net"
240     using K by (rule eventually_elim1, simp)
241 qed
243 lemma BfunE:
244   assumes "Bfun f net"
245   obtains B where "0 < B" and "eventually (\<lambda>x. norm (f x) \<le> B) net"
246 using assms unfolding Bfun_def by fast
249 subsection {* Convergence to Zero *}
251 definition
252   Zfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a net \<Rightarrow> bool" where
253   [code del]: "Zfun f net = (\<forall>r>0. eventually (\<lambda>x. norm (f x) < r) net)"
255 lemma ZfunI:
256   "(\<And>r. 0 < r \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) net) \<Longrightarrow> Zfun f net"
257 unfolding Zfun_def by simp
259 lemma ZfunD:
260   "\<lbrakk>Zfun f net; 0 < r\<rbrakk> \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) net"
261 unfolding Zfun_def by simp
263 lemma Zfun_ssubst:
264   "eventually (\<lambda>x. f x = g x) net \<Longrightarrow> Zfun g net \<Longrightarrow> Zfun f net"
265 unfolding Zfun_def by (auto elim!: eventually_rev_mp)
267 lemma Zfun_zero: "Zfun (\<lambda>x. 0) net"
268 unfolding Zfun_def by simp
270 lemma Zfun_norm_iff: "Zfun (\<lambda>x. norm (f x)) net = Zfun (\<lambda>x. f x) net"
271 unfolding Zfun_def by simp
273 lemma Zfun_imp_Zfun:
274   assumes f: "Zfun f net"
275   assumes g: "eventually (\<lambda>x. norm (g x) \<le> norm (f x) * K) net"
276   shows "Zfun (\<lambda>x. g x) net"
277 proof (cases)
278   assume K: "0 < K"
279   show ?thesis
280   proof (rule ZfunI)
281     fix r::real assume "0 < r"
282     hence "0 < r / K"
283       using K by (rule divide_pos_pos)
284     then have "eventually (\<lambda>x. norm (f x) < r / K) net"
285       using ZfunD [OF f] by fast
286     with g show "eventually (\<lambda>x. norm (g x) < r) net"
287     proof (rule eventually_elim2)
288       fix x
289       assume *: "norm (g x) \<le> norm (f x) * K"
290       assume "norm (f x) < r / K"
291       hence "norm (f x) * K < r"
292         by (simp add: pos_less_divide_eq K)
293       thus "norm (g x) < r"
294         by (simp add: order_le_less_trans [OF *])
295     qed
296   qed
297 next
298   assume "\<not> 0 < K"
299   hence K: "K \<le> 0" by (simp only: not_less)
300   show ?thesis
301   proof (rule ZfunI)
302     fix r :: real
303     assume "0 < r"
304     from g show "eventually (\<lambda>x. norm (g x) < r) net"
305     proof (rule eventually_elim1)
306       fix x
307       assume "norm (g x) \<le> norm (f x) * K"
308       also have "\<dots> \<le> norm (f x) * 0"
309         using K norm_ge_zero by (rule mult_left_mono)
310       finally show "norm (g x) < r"
311         using `0 < r` by simp
312     qed
313   qed
314 qed
316 lemma Zfun_le: "\<lbrakk>Zfun g net; \<forall>x. norm (f x) \<le> norm (g x)\<rbrakk> \<Longrightarrow> Zfun f net"
317 by (erule_tac K="1" in Zfun_imp_Zfun, simp)
320   assumes f: "Zfun f net" and g: "Zfun g net"
321   shows "Zfun (\<lambda>x. f x + g x) net"
322 proof (rule ZfunI)
323   fix r::real assume "0 < r"
324   hence r: "0 < r / 2" by simp
325   have "eventually (\<lambda>x. norm (f x) < r/2) net"
326     using f r by (rule ZfunD)
327   moreover
328   have "eventually (\<lambda>x. norm (g x) < r/2) net"
329     using g r by (rule ZfunD)
330   ultimately
331   show "eventually (\<lambda>x. norm (f x + g x) < r) net"
332   proof (rule eventually_elim2)
333     fix x
334     assume *: "norm (f x) < r/2" "norm (g x) < r/2"
335     have "norm (f x + g x) \<le> norm (f x) + norm (g x)"
336       by (rule norm_triangle_ineq)
337     also have "\<dots> < r/2 + r/2"
338       using * by (rule add_strict_mono)
339     finally show "norm (f x + g x) < r"
340       by simp
341   qed
342 qed
344 lemma Zfun_minus: "Zfun f net \<Longrightarrow> Zfun (\<lambda>x. - f x) net"
345 unfolding Zfun_def by simp
347 lemma Zfun_diff: "\<lbrakk>Zfun f net; Zfun g net\<rbrakk> \<Longrightarrow> Zfun (\<lambda>x. f x - g x) net"
348 by (simp only: diff_minus Zfun_add Zfun_minus)
350 lemma (in bounded_linear) Zfun:
351   assumes g: "Zfun g net"
352   shows "Zfun (\<lambda>x. f (g x)) net"
353 proof -
354   obtain K where "\<And>x. norm (f x) \<le> norm x * K"
355     using bounded by fast
356   then have "eventually (\<lambda>x. norm (f (g x)) \<le> norm (g x) * K) net"
357     by simp
358   with g show ?thesis
359     by (rule Zfun_imp_Zfun)
360 qed
362 lemma (in bounded_bilinear) Zfun:
363   assumes f: "Zfun f net"
364   assumes g: "Zfun g net"
365   shows "Zfun (\<lambda>x. f x ** g x) net"
366 proof (rule ZfunI)
367   fix r::real assume r: "0 < r"
368   obtain K where K: "0 < K"
369     and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
370     using pos_bounded by fast
371   from K have K': "0 < inverse K"
372     by (rule positive_imp_inverse_positive)
373   have "eventually (\<lambda>x. norm (f x) < r) net"
374     using f r by (rule ZfunD)
375   moreover
376   have "eventually (\<lambda>x. norm (g x) < inverse K) net"
377     using g K' by (rule ZfunD)
378   ultimately
379   show "eventually (\<lambda>x. norm (f x ** g x) < r) net"
380   proof (rule eventually_elim2)
381     fix x
382     assume *: "norm (f x) < r" "norm (g x) < inverse K"
383     have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
384       by (rule norm_le)
385     also have "norm (f x) * norm (g x) * K < r * inverse K * K"
386       by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero * K)
387     also from K have "r * inverse K * K = r"
388       by simp
389     finally show "norm (f x ** g x) < r" .
390   qed
391 qed
393 lemma (in bounded_bilinear) Zfun_left:
394   "Zfun f net \<Longrightarrow> Zfun (\<lambda>x. f x ** a) net"
395 by (rule bounded_linear_left [THEN bounded_linear.Zfun])
397 lemma (in bounded_bilinear) Zfun_right:
398   "Zfun f net \<Longrightarrow> Zfun (\<lambda>x. a ** f x) net"
399 by (rule bounded_linear_right [THEN bounded_linear.Zfun])
401 lemmas Zfun_mult = mult.Zfun
402 lemmas Zfun_mult_right = mult.Zfun_right
403 lemmas Zfun_mult_left = mult.Zfun_left
406 subsection {* Limits *}
408 definition
409   tendsto :: "('a \<Rightarrow> 'b::topological_space) \<Rightarrow> 'b \<Rightarrow> 'a net \<Rightarrow> bool"
410     (infixr "--->" 55)
411 where [code del]:
412   "(f ---> l) net \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) net)"
414 ML {*
415 structure Tendsto_Intros = Named_Thms
416 (
417   val name = "tendsto_intros"
418   val description = "introduction rules for tendsto"
419 )
420 *}
422 setup Tendsto_Intros.setup
424 lemma topological_tendstoI:
425   "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) net)
426     \<Longrightarrow> (f ---> l) net"
427   unfolding tendsto_def by auto
429 lemma topological_tendstoD:
430   "(f ---> l) net \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) net"
431   unfolding tendsto_def by auto
433 lemma tendstoI:
434   assumes "\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) net"
435   shows "(f ---> l) net"
436 apply (rule topological_tendstoI)
437 apply (simp add: open_dist)
438 apply (drule (1) bspec, clarify)
439 apply (drule assms)
440 apply (erule eventually_elim1, simp)
441 done
443 lemma tendstoD:
444   "(f ---> l) net \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) net"
445 apply (drule_tac S="{x. dist x l < e}" in topological_tendstoD)
446 apply (clarsimp simp add: open_dist)
447 apply (rule_tac x="e - dist x l" in exI, clarsimp)
448 apply (simp only: less_diff_eq)
449 apply (erule le_less_trans [OF dist_triangle])
450 apply simp
451 apply simp
452 done
454 lemma tendsto_iff:
455   "(f ---> l) net \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) net)"
456 using tendstoI tendstoD by fast
458 lemma tendsto_Zfun_iff: "(f ---> a) net = Zfun (\<lambda>x. f x - a) net"
459 by (simp only: tendsto_iff Zfun_def dist_norm)
461 lemma tendsto_ident_at [tendsto_intros]: "((\<lambda>x. x) ---> a) (at a)"
462 unfolding tendsto_def eventually_at_topological by auto
464 lemma tendsto_ident_at_within [tendsto_intros]:
465   "a \<in> S \<Longrightarrow> ((\<lambda>x. x) ---> a) (at a within S)"
466 unfolding tendsto_def eventually_within eventually_at_topological by auto
468 lemma tendsto_const [tendsto_intros]: "((\<lambda>x. k) ---> k) net"
469 by (simp add: tendsto_def)
471 lemma tendsto_dist [tendsto_intros]:
472   assumes f: "(f ---> l) net" and g: "(g ---> m) net"
473   shows "((\<lambda>x. dist (f x) (g x)) ---> dist l m) net"
474 proof (rule tendstoI)
475   fix e :: real assume "0 < e"
476   hence e2: "0 < e/2" by simp
477   from tendstoD [OF f e2] tendstoD [OF g e2]
478   show "eventually (\<lambda>x. dist (dist (f x) (g x)) (dist l m) < e) net"
479   proof (rule eventually_elim2)
480     fix x assume "dist (f x) l < e/2" "dist (g x) m < e/2"
481     then show "dist (dist (f x) (g x)) (dist l m) < e"
482       unfolding dist_real_def
483       using dist_triangle2 [of "f x" "g x" "l"]
484       using dist_triangle2 [of "g x" "l" "m"]
485       using dist_triangle3 [of "l" "m" "f x"]
486       using dist_triangle [of "f x" "m" "g x"]
487       by arith
488   qed
489 qed
491 lemma tendsto_norm [tendsto_intros]:
492   "(f ---> a) net \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> norm a) net"
493 apply (simp add: tendsto_iff dist_norm, safe)
494 apply (drule_tac x="e" in spec, safe)
495 apply (erule eventually_elim1)
496 apply (erule order_le_less_trans [OF norm_triangle_ineq3])
497 done
500   fixes a b c d :: "'a::ab_group_add"
501   shows "(a + c) - (b + d) = (a - b) + (c - d)"
502 by simp
504 lemma minus_diff_minus:
505   fixes a b :: "'a::ab_group_add"
506   shows "(- a) - (- b) = - (a - b)"
507 by simp
509 lemma tendsto_add [tendsto_intros]:
510   fixes a b :: "'a::real_normed_vector"
511   shows "\<lbrakk>(f ---> a) net; (g ---> b) net\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> a + b) net"
514 lemma tendsto_minus [tendsto_intros]:
515   fixes a :: "'a::real_normed_vector"
516   shows "(f ---> a) net \<Longrightarrow> ((\<lambda>x. - f x) ---> - a) net"
517 by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
519 lemma tendsto_minus_cancel:
520   fixes a :: "'a::real_normed_vector"
521   shows "((\<lambda>x. - f x) ---> - a) net \<Longrightarrow> (f ---> a) net"
522 by (drule tendsto_minus, simp)
524 lemma tendsto_diff [tendsto_intros]:
525   fixes a b :: "'a::real_normed_vector"
526   shows "\<lbrakk>(f ---> a) net; (g ---> b) net\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x - g x) ---> a - b) net"
527 by (simp add: diff_minus tendsto_add tendsto_minus)
529 lemma tendsto_setsum [tendsto_intros]:
530   fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
531   assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> a i) net"
532   shows "((\<lambda>x. \<Sum>i\<in>S. f i x) ---> (\<Sum>i\<in>S. a i)) net"
533 proof (cases "finite S")
534   assume "finite S" thus ?thesis using assms
535   proof (induct set: finite)
536     case empty show ?case
537       by (simp add: tendsto_const)
538   next
539     case (insert i F) thus ?case
541   qed
542 next
543   assume "\<not> finite S" thus ?thesis
544     by (simp add: tendsto_const)
545 qed
547 lemma (in bounded_linear) tendsto [tendsto_intros]:
548   "(g ---> a) net \<Longrightarrow> ((\<lambda>x. f (g x)) ---> f a) net"
549 by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
551 lemma (in bounded_bilinear) tendsto [tendsto_intros]:
552   "\<lbrakk>(f ---> a) net; (g ---> b) net\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x ** g x) ---> a ** b) net"
553 by (simp only: tendsto_Zfun_iff prod_diff_prod
554                Zfun_add Zfun Zfun_left Zfun_right)
557 subsection {* Continuity of Inverse *}
559 lemma (in bounded_bilinear) Zfun_prod_Bfun:
560   assumes f: "Zfun f net"
561   assumes g: "Bfun g net"
562   shows "Zfun (\<lambda>x. f x ** g x) net"
563 proof -
564   obtain K where K: "0 \<le> K"
565     and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
566     using nonneg_bounded by fast
567   obtain B where B: "0 < B"
568     and norm_g: "eventually (\<lambda>x. norm (g x) \<le> B) net"
569     using g by (rule BfunE)
570   have "eventually (\<lambda>x. norm (f x ** g x) \<le> norm (f x) * (B * K)) net"
571   using norm_g proof (rule eventually_elim1)
572     fix x
573     assume *: "norm (g x) \<le> B"
574     have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
575       by (rule norm_le)
576     also have "\<dots> \<le> norm (f x) * B * K"
577       by (intro mult_mono' order_refl norm_g norm_ge_zero
578                 mult_nonneg_nonneg K *)
579     also have "\<dots> = norm (f x) * (B * K)"
580       by (rule mult_assoc)
581     finally show "norm (f x ** g x) \<le> norm (f x) * (B * K)" .
582   qed
583   with f show ?thesis
584     by (rule Zfun_imp_Zfun)
585 qed
587 lemma (in bounded_bilinear) flip:
588   "bounded_bilinear (\<lambda>x y. y ** x)"
589 apply default
590 apply (rule add_right)
591 apply (rule add_left)
592 apply (rule scaleR_right)
593 apply (rule scaleR_left)
594 apply (subst mult_commute)
595 using bounded by fast
597 lemma (in bounded_bilinear) Bfun_prod_Zfun:
598   assumes f: "Bfun f net"
599   assumes g: "Zfun g net"
600   shows "Zfun (\<lambda>x. f x ** g x) net"
601 using flip g f by (rule bounded_bilinear.Zfun_prod_Bfun)
603 lemma inverse_diff_inverse:
604   "\<lbrakk>(a::'a::division_ring) \<noteq> 0; b \<noteq> 0\<rbrakk>
605    \<Longrightarrow> inverse a - inverse b = - (inverse a * (a - b) * inverse b)"
606 by (simp add: algebra_simps)
608 lemma Bfun_inverse_lemma:
609   fixes x :: "'a::real_normed_div_algebra"
610   shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
611 apply (subst nonzero_norm_inverse, clarsimp)
612 apply (erule (1) le_imp_inverse_le)
613 done
615 lemma Bfun_inverse:
616   fixes a :: "'a::real_normed_div_algebra"
617   assumes f: "(f ---> a) net"
618   assumes a: "a \<noteq> 0"
619   shows "Bfun (\<lambda>x. inverse (f x)) net"
620 proof -
621   from a have "0 < norm a" by simp
622   hence "\<exists>r>0. r < norm a" by (rule dense)
623   then obtain r where r1: "0 < r" and r2: "r < norm a" by fast
624   have "eventually (\<lambda>x. dist (f x) a < r) net"
625     using tendstoD [OF f r1] by fast
626   hence "eventually (\<lambda>x. norm (inverse (f x)) \<le> inverse (norm a - r)) net"
627   proof (rule eventually_elim1)
628     fix x
629     assume "dist (f x) a < r"
630     hence 1: "norm (f x - a) < r"
631       by (simp add: dist_norm)
632     hence 2: "f x \<noteq> 0" using r2 by auto
633     hence "norm (inverse (f x)) = inverse (norm (f x))"
634       by (rule nonzero_norm_inverse)
635     also have "\<dots> \<le> inverse (norm a - r)"
636     proof (rule le_imp_inverse_le)
637       show "0 < norm a - r" using r2 by simp
638     next
639       have "norm a - norm (f x) \<le> norm (a - f x)"
640         by (rule norm_triangle_ineq2)
641       also have "\<dots> = norm (f x - a)"
642         by (rule norm_minus_commute)
643       also have "\<dots> < r" using 1 .
644       finally show "norm a - r \<le> norm (f x)" by simp
645     qed
646     finally show "norm (inverse (f x)) \<le> inverse (norm a - r)" .
647   qed
648   thus ?thesis by (rule BfunI)
649 qed
651 lemma tendsto_inverse_lemma:
652   fixes a :: "'a::real_normed_div_algebra"
653   shows "\<lbrakk>(f ---> a) net; a \<noteq> 0; eventually (\<lambda>x. f x \<noteq> 0) net\<rbrakk>
654          \<Longrightarrow> ((\<lambda>x. inverse (f x)) ---> inverse a) net"
655 apply (subst tendsto_Zfun_iff)
656 apply (rule Zfun_ssubst)
657 apply (erule eventually_elim1)
658 apply (erule (1) inverse_diff_inverse)
659 apply (rule Zfun_minus)
660 apply (rule Zfun_mult_left)
661 apply (rule mult.Bfun_prod_Zfun)
662 apply (erule (1) Bfun_inverse)
663 apply (simp add: tendsto_Zfun_iff)
664 done
666 lemma tendsto_inverse [tendsto_intros]:
667   fixes a :: "'a::real_normed_div_algebra"
668   assumes f: "(f ---> a) net"
669   assumes a: "a \<noteq> 0"
670   shows "((\<lambda>x. inverse (f x)) ---> inverse a) net"
671 proof -
672   from a have "0 < norm a" by simp
673   with f have "eventually (\<lambda>x. dist (f x) a < norm a) net"
674     by (rule tendstoD)
675   then have "eventually (\<lambda>x. f x \<noteq> 0) net"
676     unfolding dist_norm by (auto elim!: eventually_elim1)
677   with f a show ?thesis
678     by (rule tendsto_inverse_lemma)
679 qed
681 lemma tendsto_divide [tendsto_intros]:
682   fixes a b :: "'a::real_normed_field"
683   shows "\<lbrakk>(f ---> a) net; (g ---> b) net; b \<noteq> 0\<rbrakk>
684     \<Longrightarrow> ((\<lambda>x. f x / g x) ---> a / b) net"
685 by (simp add: mult.tendsto tendsto_inverse divide_inverse)
687 end