src/HOL/Limits.thy
author kuncar
Fri Dec 09 18:07:04 2011 +0100 (2011-12-09)
changeset 45802 b16f976db515
parent 45294 3c5d3d286055
child 45892 8dcf6692433f
permissions -rw-r--r--
Quotient_Info stores only relation maps
     1 (*  Title       : Limits.thy
     2     Author      : Brian Huffman
     3 *)
     4 
     5 header {* Filters and Limits *}
     6 
     7 theory Limits
     8 imports RealVector
     9 begin
    10 
    11 subsection {* Filters *}
    12 
    13 text {*
    14   This definition also allows non-proper filters.
    15 *}
    16 
    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)"
    22 
    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
    27 
    28 lemma is_filter_Rep_filter: "is_filter (Rep_filter F)"
    29   using Rep_filter [of F] by simp
    30 
    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)
    34 
    35 
    36 subsection {* Eventually *}
    37 
    38 definition eventually :: "('a \<Rightarrow> bool) \<Rightarrow> 'a filter \<Rightarrow> bool"
    39   where "eventually P F \<longleftrightarrow> Rep_filter F P"
    40 
    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)
    44 
    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 ..
    48 
    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])
    52 
    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
    58 
    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])
    63 
    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])
    70 
    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
    80 
    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)
    86 
    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)
    90 
    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)
    96 
    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)
   103 
   104 subsection {* Finer-than relation *}
   105 
   106 text {* @{term "F \<le> F'"} means that filter @{term F} is finer than
   107 filter @{term F'}. *}
   108 
   109 instantiation filter :: (type) complete_lattice
   110 begin
   111 
   112 definition le_filter_def:
   113   "F \<le> F' \<longleftrightarrow> (\<forall>P. eventually P F' \<longrightarrow> eventually P F)"
   114 
   115 definition
   116   "(F :: 'a filter) < F' \<longleftrightarrow> F \<le> F' \<and> \<not> F' \<le> F"
   117 
   118 definition
   119   "top = Abs_filter (\<lambda>P. \<forall>x. P x)"
   120 
   121 definition
   122   "bot = Abs_filter (\<lambda>P. True)"
   123 
   124 definition
   125   "sup F F' = Abs_filter (\<lambda>P. eventually P F \<and> eventually P F')"
   126 
   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))"
   130 
   131 definition
   132   "Sup S = Abs_filter (\<lambda>P. \<forall>F\<in>S. eventually P F)"
   133 
   134 definition
   135   "Inf S = Sup {F::'a filter. \<forall>F'\<in>S. F \<le> F'}"
   136 
   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)
   140 
   141 lemma eventually_bot [simp]: "eventually P bot"
   142   unfolding bot_filter_def
   143   by (subst eventually_Abs_filter, rule is_filter.intro, auto)
   144 
   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)
   150 
   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
   164 
   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
   171 
   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
   204 
   205 end
   206 
   207 lemma filter_leD:
   208   "F \<le> F' \<Longrightarrow> eventually P F' \<Longrightarrow> eventually P F"
   209   unfolding le_filter_def by simp
   210 
   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
   214 
   215 lemma eventually_False:
   216   "eventually (\<lambda>x. False) F \<longleftrightarrow> F = bot"
   217   unfolding filter_eq_iff by (auto elim: eventually_rev_mp)
   218 
   219 abbreviation (input) trivial_limit :: "'a filter \<Rightarrow> bool"
   220   where "trivial_limit F \<equiv> F = bot"
   221 
   222 lemma trivial_limit_def: "trivial_limit F \<longleftrightarrow> eventually (\<lambda>x. False) F"
   223   by (rule eventually_False [symmetric])
   224 
   225 
   226 subsection {* Map function for filters *}
   227 
   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)"
   230 
   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
   238 
   239 lemma filtermap_ident: "filtermap (\<lambda>x. x) F = F"
   240   by (simp add: filter_eq_iff eventually_filtermap)
   241 
   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)
   245 
   246 lemma filtermap_mono: "F \<le> F' \<Longrightarrow> filtermap f F \<le> filtermap f F'"
   247   unfolding le_filter_def eventually_filtermap by simp
   248 
   249 lemma filtermap_bot [simp]: "filtermap f bot = bot"
   250   by (simp add: filter_eq_iff eventually_filtermap)
   251 
   252 
   253 subsection {* Sequentially *}
   254 
   255 definition sequentially :: "nat filter"
   256   where "sequentially = Abs_filter (\<lambda>P. \<exists>k. \<forall>n\<ge>k. P n)"
   257 
   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
   268 
   269 lemma sequentially_bot [simp, intro]: "sequentially \<noteq> bot"
   270   unfolding filter_eq_iff eventually_sequentially by auto
   271 
   272 lemmas trivial_limit_sequentially = sequentially_bot
   273 
   274 lemma eventually_False_sequentially [simp]:
   275   "\<not> eventually (\<lambda>n. False) sequentially"
   276   by (simp add: eventually_False)
   277 
   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)
   282 
   283 
   284 subsection {* Standard filters *}
   285 
   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)"
   288 
   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))"
   291 
   292 definition (in topological_space) at :: "'a \<Rightarrow> 'a filter"
   293   where "at a = nhds a within - {a}"
   294 
   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)
   300 
   301 lemma within_UNIV [simp]: "F within UNIV = F"
   302   unfolding filter_eq_iff eventually_within by simp
   303 
   304 lemma within_empty [simp]: "F within {} = bot"
   305   unfolding filter_eq_iff eventually_within by simp
   306 
   307 lemma eventually_nhds:
   308   "eventually P (nhds a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
   309 unfolding nhds_def
   310 proof (rule eventually_Abs_filter, rule is_filter.intro)
   311   have "open UNIV \<and> a \<in> UNIV \<and> (\<forall>x\<in>UNIV. True)" by simp
   312   thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. True)" by - rule
   313 next
   314   fix P Q
   315   assume "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x)"
   316      and "\<exists>T. open T \<and> a \<in> T \<and> (\<forall>x\<in>T. Q x)"
   317   then obtain S T where
   318     "open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x)"
   319     "open T \<and> a \<in> T \<and> (\<forall>x\<in>T. Q x)" by auto
   320   hence "open (S \<inter> T) \<and> a \<in> S \<inter> T \<and> (\<forall>x\<in>(S \<inter> T). P x \<and> Q x)"
   321     by (simp add: open_Int)
   322   thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x \<and> Q x)" by - rule
   323 qed auto
   324 
   325 lemma eventually_nhds_metric:
   326   "eventually P (nhds a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. dist x a < d \<longrightarrow> P x)"
   327 unfolding eventually_nhds open_dist
   328 apply safe
   329 apply fast
   330 apply (rule_tac x="{x. dist x a < d}" in exI, simp)
   331 apply clarsimp
   332 apply (rule_tac x="d - dist x a" in exI, clarsimp)
   333 apply (simp only: less_diff_eq)
   334 apply (erule le_less_trans [OF dist_triangle])
   335 done
   336 
   337 lemma nhds_neq_bot [simp]: "nhds a \<noteq> bot"
   338   unfolding trivial_limit_def eventually_nhds by simp
   339 
   340 lemma eventually_at_topological:
   341   "eventually P (at a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. x \<noteq> a \<longrightarrow> P x))"
   342 unfolding at_def eventually_within eventually_nhds by simp
   343 
   344 lemma eventually_at:
   345   fixes a :: "'a::metric_space"
   346   shows "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> P x)"
   347 unfolding at_def eventually_within eventually_nhds_metric by auto
   348 
   349 lemma at_eq_bot_iff: "at a = bot \<longleftrightarrow> open {a}"
   350   unfolding trivial_limit_def eventually_at_topological
   351   by (safe, case_tac "S = {a}", simp, fast, fast)
   352 
   353 lemma at_neq_bot [simp]: "at (a::'a::perfect_space) \<noteq> bot"
   354   by (simp add: at_eq_bot_iff not_open_singleton)
   355 
   356 
   357 subsection {* Boundedness *}
   358 
   359 definition Bfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
   360   where "Bfun f F = (\<exists>K>0. eventually (\<lambda>x. norm (f x) \<le> K) F)"
   361 
   362 lemma BfunI:
   363   assumes K: "eventually (\<lambda>x. norm (f x) \<le> K) F" shows "Bfun f F"
   364 unfolding Bfun_def
   365 proof (intro exI conjI allI)
   366   show "0 < max K 1" by simp
   367 next
   368   show "eventually (\<lambda>x. norm (f x) \<le> max K 1) F"
   369     using K by (rule eventually_elim1, simp)
   370 qed
   371 
   372 lemma BfunE:
   373   assumes "Bfun f F"
   374   obtains B where "0 < B" and "eventually (\<lambda>x. norm (f x) \<le> B) F"
   375 using assms unfolding Bfun_def by fast
   376 
   377 
   378 subsection {* Convergence to Zero *}
   379 
   380 definition Zfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
   381   where "Zfun f F = (\<forall>r>0. eventually (\<lambda>x. norm (f x) < r) F)"
   382 
   383 lemma ZfunI:
   384   "(\<And>r. 0 < r \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F) \<Longrightarrow> Zfun f F"
   385   unfolding Zfun_def by simp
   386 
   387 lemma ZfunD:
   388   "\<lbrakk>Zfun f F; 0 < r\<rbrakk> \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F"
   389   unfolding Zfun_def by simp
   390 
   391 lemma Zfun_ssubst:
   392   "eventually (\<lambda>x. f x = g x) F \<Longrightarrow> Zfun g F \<Longrightarrow> Zfun f F"
   393   unfolding Zfun_def by (auto elim!: eventually_rev_mp)
   394 
   395 lemma Zfun_zero: "Zfun (\<lambda>x. 0) F"
   396   unfolding Zfun_def by simp
   397 
   398 lemma Zfun_norm_iff: "Zfun (\<lambda>x. norm (f x)) F = Zfun (\<lambda>x. f x) F"
   399   unfolding Zfun_def by simp
   400 
   401 lemma Zfun_imp_Zfun:
   402   assumes f: "Zfun f F"
   403   assumes g: "eventually (\<lambda>x. norm (g x) \<le> norm (f x) * K) F"
   404   shows "Zfun (\<lambda>x. g x) F"
   405 proof (cases)
   406   assume K: "0 < K"
   407   show ?thesis
   408   proof (rule ZfunI)
   409     fix r::real assume "0 < r"
   410     hence "0 < r / K"
   411       using K by (rule divide_pos_pos)
   412     then have "eventually (\<lambda>x. norm (f x) < r / K) F"
   413       using ZfunD [OF f] by fast
   414     with g show "eventually (\<lambda>x. norm (g x) < r) F"
   415     proof (rule eventually_elim2)
   416       fix x
   417       assume *: "norm (g x) \<le> norm (f x) * K"
   418       assume "norm (f x) < r / K"
   419       hence "norm (f x) * K < r"
   420         by (simp add: pos_less_divide_eq K)
   421       thus "norm (g x) < r"
   422         by (simp add: order_le_less_trans [OF *])
   423     qed
   424   qed
   425 next
   426   assume "\<not> 0 < K"
   427   hence K: "K \<le> 0" by (simp only: not_less)
   428   show ?thesis
   429   proof (rule ZfunI)
   430     fix r :: real
   431     assume "0 < r"
   432     from g show "eventually (\<lambda>x. norm (g x) < r) F"
   433     proof (rule eventually_elim1)
   434       fix x
   435       assume "norm (g x) \<le> norm (f x) * K"
   436       also have "\<dots> \<le> norm (f x) * 0"
   437         using K norm_ge_zero by (rule mult_left_mono)
   438       finally show "norm (g x) < r"
   439         using `0 < r` by simp
   440     qed
   441   qed
   442 qed
   443 
   444 lemma Zfun_le: "\<lbrakk>Zfun g F; \<forall>x. norm (f x) \<le> norm (g x)\<rbrakk> \<Longrightarrow> Zfun f F"
   445   by (erule_tac K="1" in Zfun_imp_Zfun, simp)
   446 
   447 lemma Zfun_add:
   448   assumes f: "Zfun f F" and g: "Zfun g F"
   449   shows "Zfun (\<lambda>x. f x + g x) F"
   450 proof (rule ZfunI)
   451   fix r::real assume "0 < r"
   452   hence r: "0 < r / 2" by simp
   453   have "eventually (\<lambda>x. norm (f x) < r/2) F"
   454     using f r by (rule ZfunD)
   455   moreover
   456   have "eventually (\<lambda>x. norm (g x) < r/2) F"
   457     using g r by (rule ZfunD)
   458   ultimately
   459   show "eventually (\<lambda>x. norm (f x + g x) < r) F"
   460   proof (rule eventually_elim2)
   461     fix x
   462     assume *: "norm (f x) < r/2" "norm (g x) < r/2"
   463     have "norm (f x + g x) \<le> norm (f x) + norm (g x)"
   464       by (rule norm_triangle_ineq)
   465     also have "\<dots> < r/2 + r/2"
   466       using * by (rule add_strict_mono)
   467     finally show "norm (f x + g x) < r"
   468       by simp
   469   qed
   470 qed
   471 
   472 lemma Zfun_minus: "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. - f x) F"
   473   unfolding Zfun_def by simp
   474 
   475 lemma Zfun_diff: "\<lbrakk>Zfun f F; Zfun g F\<rbrakk> \<Longrightarrow> Zfun (\<lambda>x. f x - g x) F"
   476   by (simp only: diff_minus Zfun_add Zfun_minus)
   477 
   478 lemma (in bounded_linear) Zfun:
   479   assumes g: "Zfun g F"
   480   shows "Zfun (\<lambda>x. f (g x)) F"
   481 proof -
   482   obtain K where "\<And>x. norm (f x) \<le> norm x * K"
   483     using bounded by fast
   484   then have "eventually (\<lambda>x. norm (f (g x)) \<le> norm (g x) * K) F"
   485     by simp
   486   with g show ?thesis
   487     by (rule Zfun_imp_Zfun)
   488 qed
   489 
   490 lemma (in bounded_bilinear) Zfun:
   491   assumes f: "Zfun f F"
   492   assumes g: "Zfun g F"
   493   shows "Zfun (\<lambda>x. f x ** g x) F"
   494 proof (rule ZfunI)
   495   fix r::real assume r: "0 < r"
   496   obtain K where K: "0 < K"
   497     and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
   498     using pos_bounded by fast
   499   from K have K': "0 < inverse K"
   500     by (rule positive_imp_inverse_positive)
   501   have "eventually (\<lambda>x. norm (f x) < r) F"
   502     using f r by (rule ZfunD)
   503   moreover
   504   have "eventually (\<lambda>x. norm (g x) < inverse K) F"
   505     using g K' by (rule ZfunD)
   506   ultimately
   507   show "eventually (\<lambda>x. norm (f x ** g x) < r) F"
   508   proof (rule eventually_elim2)
   509     fix x
   510     assume *: "norm (f x) < r" "norm (g x) < inverse K"
   511     have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
   512       by (rule norm_le)
   513     also have "norm (f x) * norm (g x) * K < r * inverse K * K"
   514       by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero * K)
   515     also from K have "r * inverse K * K = r"
   516       by simp
   517     finally show "norm (f x ** g x) < r" .
   518   qed
   519 qed
   520 
   521 lemma (in bounded_bilinear) Zfun_left:
   522   "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. f x ** a) F"
   523   by (rule bounded_linear_left [THEN bounded_linear.Zfun])
   524 
   525 lemma (in bounded_bilinear) Zfun_right:
   526   "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. a ** f x) F"
   527   by (rule bounded_linear_right [THEN bounded_linear.Zfun])
   528 
   529 lemmas Zfun_mult = bounded_bilinear.Zfun [OF bounded_bilinear_mult]
   530 lemmas Zfun_mult_right = bounded_bilinear.Zfun_right [OF bounded_bilinear_mult]
   531 lemmas Zfun_mult_left = bounded_bilinear.Zfun_left [OF bounded_bilinear_mult]
   532 
   533 
   534 subsection {* Limits *}
   535 
   536 definition (in topological_space)
   537   tendsto :: "('b \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'b filter \<Rightarrow> bool" (infixr "--->" 55) where
   538   "(f ---> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
   539 
   540 ML {*
   541 structure Tendsto_Intros = Named_Thms
   542 (
   543   val name = @{binding tendsto_intros}
   544   val description = "introduction rules for tendsto"
   545 )
   546 *}
   547 
   548 setup Tendsto_Intros.setup
   549 
   550 lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f ---> l) F' \<Longrightarrow> (f ---> l) F"
   551   unfolding tendsto_def le_filter_def by fast
   552 
   553 lemma topological_tendstoI:
   554   "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F)
   555     \<Longrightarrow> (f ---> l) F"
   556   unfolding tendsto_def by auto
   557 
   558 lemma topological_tendstoD:
   559   "(f ---> l) F \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
   560   unfolding tendsto_def by auto
   561 
   562 lemma tendstoI:
   563   assumes "\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
   564   shows "(f ---> l) F"
   565   apply (rule topological_tendstoI)
   566   apply (simp add: open_dist)
   567   apply (drule (1) bspec, clarify)
   568   apply (drule assms)
   569   apply (erule eventually_elim1, simp)
   570   done
   571 
   572 lemma tendstoD:
   573   "(f ---> l) F \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
   574   apply (drule_tac S="{x. dist x l < e}" in topological_tendstoD)
   575   apply (clarsimp simp add: open_dist)
   576   apply (rule_tac x="e - dist x l" in exI, clarsimp)
   577   apply (simp only: less_diff_eq)
   578   apply (erule le_less_trans [OF dist_triangle])
   579   apply simp
   580   apply simp
   581   done
   582 
   583 lemma tendsto_iff:
   584   "(f ---> l) F \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) F)"
   585   using tendstoI tendstoD by fast
   586 
   587 lemma tendsto_Zfun_iff: "(f ---> a) F = Zfun (\<lambda>x. f x - a) F"
   588   by (simp only: tendsto_iff Zfun_def dist_norm)
   589 
   590 lemma tendsto_bot [simp]: "(f ---> a) bot"
   591   unfolding tendsto_def by simp
   592 
   593 lemma tendsto_ident_at [tendsto_intros]: "((\<lambda>x. x) ---> a) (at a)"
   594   unfolding tendsto_def eventually_at_topological by auto
   595 
   596 lemma tendsto_ident_at_within [tendsto_intros]:
   597   "((\<lambda>x. x) ---> a) (at a within S)"
   598   unfolding tendsto_def eventually_within eventually_at_topological by auto
   599 
   600 lemma tendsto_const [tendsto_intros]: "((\<lambda>x. k) ---> k) F"
   601   by (simp add: tendsto_def)
   602 
   603 lemma tendsto_unique:
   604   fixes f :: "'a \<Rightarrow> 'b::t2_space"
   605   assumes "\<not> trivial_limit F" and "(f ---> a) F" and "(f ---> b) F"
   606   shows "a = b"
   607 proof (rule ccontr)
   608   assume "a \<noteq> b"
   609   obtain U V where "open U" "open V" "a \<in> U" "b \<in> V" "U \<inter> V = {}"
   610     using hausdorff [OF `a \<noteq> b`] by fast
   611   have "eventually (\<lambda>x. f x \<in> U) F"
   612     using `(f ---> a) F` `open U` `a \<in> U` by (rule topological_tendstoD)
   613   moreover
   614   have "eventually (\<lambda>x. f x \<in> V) F"
   615     using `(f ---> b) F` `open V` `b \<in> V` by (rule topological_tendstoD)
   616   ultimately
   617   have "eventually (\<lambda>x. False) F"
   618   proof (rule eventually_elim2)
   619     fix x
   620     assume "f x \<in> U" "f x \<in> V"
   621     hence "f x \<in> U \<inter> V" by simp
   622     with `U \<inter> V = {}` show "False" by simp
   623   qed
   624   with `\<not> trivial_limit F` show "False"
   625     by (simp add: trivial_limit_def)
   626 qed
   627 
   628 lemma tendsto_const_iff:
   629   fixes a b :: "'a::t2_space"
   630   assumes "\<not> trivial_limit F" shows "((\<lambda>x. a) ---> b) F \<longleftrightarrow> a = b"
   631   by (safe intro!: tendsto_const tendsto_unique [OF assms tendsto_const])
   632 
   633 lemma tendsto_compose:
   634   assumes g: "(g ---> g l) (at l)"
   635   assumes f: "(f ---> l) F"
   636   shows "((\<lambda>x. g (f x)) ---> g l) F"
   637 proof (rule topological_tendstoI)
   638   fix B assume B: "open B" "g l \<in> B"
   639   obtain A where A: "open A" "l \<in> A"
   640     and gB: "\<forall>y. y \<in> A \<longrightarrow> g y \<in> B"
   641     using topological_tendstoD [OF g B] B(2)
   642     unfolding eventually_at_topological by fast
   643   hence "\<forall>x. f x \<in> A \<longrightarrow> g (f x) \<in> B" by simp
   644   from this topological_tendstoD [OF f A]
   645   show "eventually (\<lambda>x. g (f x) \<in> B) F"
   646     by (rule eventually_mono)
   647 qed
   648 
   649 lemma tendsto_compose_eventually:
   650   assumes g: "(g ---> m) (at l)"
   651   assumes f: "(f ---> l) F"
   652   assumes inj: "eventually (\<lambda>x. f x \<noteq> l) F"
   653   shows "((\<lambda>x. g (f x)) ---> m) F"
   654 proof (rule topological_tendstoI)
   655   fix B assume B: "open B" "m \<in> B"
   656   obtain A where A: "open A" "l \<in> A"
   657     and gB: "\<And>y. y \<in> A \<Longrightarrow> y \<noteq> l \<Longrightarrow> g y \<in> B"
   658     using topological_tendstoD [OF g B]
   659     unfolding eventually_at_topological by fast
   660   show "eventually (\<lambda>x. g (f x) \<in> B) F"
   661     using topological_tendstoD [OF f A] inj
   662     by (rule eventually_elim2) (simp add: gB)
   663 qed
   664 
   665 lemma metric_tendsto_imp_tendsto:
   666   assumes f: "(f ---> a) F"
   667   assumes le: "eventually (\<lambda>x. dist (g x) b \<le> dist (f x) a) F"
   668   shows "(g ---> b) F"
   669 proof (rule tendstoI)
   670   fix e :: real assume "0 < e"
   671   with f have "eventually (\<lambda>x. dist (f x) a < e) F" by (rule tendstoD)
   672   with le show "eventually (\<lambda>x. dist (g x) b < e) F"
   673     using le_less_trans by (rule eventually_elim2)
   674 qed
   675 
   676 subsubsection {* Distance and norms *}
   677 
   678 lemma tendsto_dist [tendsto_intros]:
   679   assumes f: "(f ---> l) F" and g: "(g ---> m) F"
   680   shows "((\<lambda>x. dist (f x) (g x)) ---> dist l m) F"
   681 proof (rule tendstoI)
   682   fix e :: real assume "0 < e"
   683   hence e2: "0 < e/2" by simp
   684   from tendstoD [OF f e2] tendstoD [OF g e2]
   685   show "eventually (\<lambda>x. dist (dist (f x) (g x)) (dist l m) < e) F"
   686   proof (rule eventually_elim2)
   687     fix x assume "dist (f x) l < e/2" "dist (g x) m < e/2"
   688     then show "dist (dist (f x) (g x)) (dist l m) < e"
   689       unfolding dist_real_def
   690       using dist_triangle2 [of "f x" "g x" "l"]
   691       using dist_triangle2 [of "g x" "l" "m"]
   692       using dist_triangle3 [of "l" "m" "f x"]
   693       using dist_triangle [of "f x" "m" "g x"]
   694       by arith
   695   qed
   696 qed
   697 
   698 lemma norm_conv_dist: "norm x = dist x 0"
   699   unfolding dist_norm by simp
   700 
   701 lemma tendsto_norm [tendsto_intros]:
   702   "(f ---> a) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> norm a) F"
   703   unfolding norm_conv_dist by (intro tendsto_intros)
   704 
   705 lemma tendsto_norm_zero:
   706   "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> 0) F"
   707   by (drule tendsto_norm, simp)
   708 
   709 lemma tendsto_norm_zero_cancel:
   710   "((\<lambda>x. norm (f x)) ---> 0) F \<Longrightarrow> (f ---> 0) F"
   711   unfolding tendsto_iff dist_norm by simp
   712 
   713 lemma tendsto_norm_zero_iff:
   714   "((\<lambda>x. norm (f x)) ---> 0) F \<longleftrightarrow> (f ---> 0) F"
   715   unfolding tendsto_iff dist_norm by simp
   716 
   717 lemma tendsto_rabs [tendsto_intros]:
   718   "(f ---> (l::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> \<bar>l\<bar>) F"
   719   by (fold real_norm_def, rule tendsto_norm)
   720 
   721 lemma tendsto_rabs_zero:
   722   "(f ---> (0::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> 0) F"
   723   by (fold real_norm_def, rule tendsto_norm_zero)
   724 
   725 lemma tendsto_rabs_zero_cancel:
   726   "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<Longrightarrow> (f ---> 0) F"
   727   by (fold real_norm_def, rule tendsto_norm_zero_cancel)
   728 
   729 lemma tendsto_rabs_zero_iff:
   730   "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<longleftrightarrow> (f ---> 0) F"
   731   by (fold real_norm_def, rule tendsto_norm_zero_iff)
   732 
   733 subsubsection {* Addition and subtraction *}
   734 
   735 lemma tendsto_add [tendsto_intros]:
   736   fixes a b :: "'a::real_normed_vector"
   737   shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> a + b) F"
   738   by (simp only: tendsto_Zfun_iff add_diff_add Zfun_add)
   739 
   740 lemma tendsto_add_zero:
   741   fixes f g :: "'a::type \<Rightarrow> 'b::real_normed_vector"
   742   shows "\<lbrakk>(f ---> 0) F; (g ---> 0) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> 0) F"
   743   by (drule (1) tendsto_add, simp)
   744 
   745 lemma tendsto_minus [tendsto_intros]:
   746   fixes a :: "'a::real_normed_vector"
   747   shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. - f x) ---> - a) F"
   748   by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
   749 
   750 lemma tendsto_minus_cancel:
   751   fixes a :: "'a::real_normed_vector"
   752   shows "((\<lambda>x. - f x) ---> - a) F \<Longrightarrow> (f ---> a) F"
   753   by (drule tendsto_minus, simp)
   754 
   755 lemma tendsto_diff [tendsto_intros]:
   756   fixes a b :: "'a::real_normed_vector"
   757   shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x - g x) ---> a - b) F"
   758   by (simp add: diff_minus tendsto_add tendsto_minus)
   759 
   760 lemma tendsto_setsum [tendsto_intros]:
   761   fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
   762   assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> a i) F"
   763   shows "((\<lambda>x. \<Sum>i\<in>S. f i x) ---> (\<Sum>i\<in>S. a i)) F"
   764 proof (cases "finite S")
   765   assume "finite S" thus ?thesis using assms
   766     by (induct, simp add: tendsto_const, simp add: tendsto_add)
   767 next
   768   assume "\<not> finite S" thus ?thesis
   769     by (simp add: tendsto_const)
   770 qed
   771 
   772 subsubsection {* Linear operators and multiplication *}
   773 
   774 lemma (in bounded_linear) tendsto:
   775   "(g ---> a) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> f a) F"
   776   by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
   777 
   778 lemma (in bounded_linear) tendsto_zero:
   779   "(g ---> 0) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> 0) F"
   780   by (drule tendsto, simp only: zero)
   781 
   782 lemma (in bounded_bilinear) tendsto:
   783   "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x ** g x) ---> a ** b) F"
   784   by (simp only: tendsto_Zfun_iff prod_diff_prod
   785                  Zfun_add Zfun Zfun_left Zfun_right)
   786 
   787 lemma (in bounded_bilinear) tendsto_zero:
   788   assumes f: "(f ---> 0) F"
   789   assumes g: "(g ---> 0) F"
   790   shows "((\<lambda>x. f x ** g x) ---> 0) F"
   791   using tendsto [OF f g] by (simp add: zero_left)
   792 
   793 lemma (in bounded_bilinear) tendsto_left_zero:
   794   "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. f x ** c) ---> 0) F"
   795   by (rule bounded_linear.tendsto_zero [OF bounded_linear_left])
   796 
   797 lemma (in bounded_bilinear) tendsto_right_zero:
   798   "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. c ** f x) ---> 0) F"
   799   by (rule bounded_linear.tendsto_zero [OF bounded_linear_right])
   800 
   801 lemmas tendsto_of_real [tendsto_intros] =
   802   bounded_linear.tendsto [OF bounded_linear_of_real]
   803 
   804 lemmas tendsto_scaleR [tendsto_intros] =
   805   bounded_bilinear.tendsto [OF bounded_bilinear_scaleR]
   806 
   807 lemmas tendsto_mult [tendsto_intros] =
   808   bounded_bilinear.tendsto [OF bounded_bilinear_mult]
   809 
   810 lemmas tendsto_mult_zero =
   811   bounded_bilinear.tendsto_zero [OF bounded_bilinear_mult]
   812 
   813 lemmas tendsto_mult_left_zero =
   814   bounded_bilinear.tendsto_left_zero [OF bounded_bilinear_mult]
   815 
   816 lemmas tendsto_mult_right_zero =
   817   bounded_bilinear.tendsto_right_zero [OF bounded_bilinear_mult]
   818 
   819 lemma tendsto_power [tendsto_intros]:
   820   fixes f :: "'a \<Rightarrow> 'b::{power,real_normed_algebra}"
   821   shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. f x ^ n) ---> a ^ n) F"
   822   by (induct n) (simp_all add: tendsto_const tendsto_mult)
   823 
   824 lemma tendsto_setprod [tendsto_intros]:
   825   fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
   826   assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> L i) F"
   827   shows "((\<lambda>x. \<Prod>i\<in>S. f i x) ---> (\<Prod>i\<in>S. L i)) F"
   828 proof (cases "finite S")
   829   assume "finite S" thus ?thesis using assms
   830     by (induct, simp add: tendsto_const, simp add: tendsto_mult)
   831 next
   832   assume "\<not> finite S" thus ?thesis
   833     by (simp add: tendsto_const)
   834 qed
   835 
   836 subsubsection {* Inverse and division *}
   837 
   838 lemma (in bounded_bilinear) Zfun_prod_Bfun:
   839   assumes f: "Zfun f F"
   840   assumes g: "Bfun g F"
   841   shows "Zfun (\<lambda>x. f x ** g x) F"
   842 proof -
   843   obtain K where K: "0 \<le> K"
   844     and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
   845     using nonneg_bounded by fast
   846   obtain B where B: "0 < B"
   847     and norm_g: "eventually (\<lambda>x. norm (g x) \<le> B) F"
   848     using g by (rule BfunE)
   849   have "eventually (\<lambda>x. norm (f x ** g x) \<le> norm (f x) * (B * K)) F"
   850   using norm_g proof (rule eventually_elim1)
   851     fix x
   852     assume *: "norm (g x) \<le> B"
   853     have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
   854       by (rule norm_le)
   855     also have "\<dots> \<le> norm (f x) * B * K"
   856       by (intro mult_mono' order_refl norm_g norm_ge_zero
   857                 mult_nonneg_nonneg K *)
   858     also have "\<dots> = norm (f x) * (B * K)"
   859       by (rule mult_assoc)
   860     finally show "norm (f x ** g x) \<le> norm (f x) * (B * K)" .
   861   qed
   862   with f show ?thesis
   863     by (rule Zfun_imp_Zfun)
   864 qed
   865 
   866 lemma (in bounded_bilinear) flip:
   867   "bounded_bilinear (\<lambda>x y. y ** x)"
   868   apply default
   869   apply (rule add_right)
   870   apply (rule add_left)
   871   apply (rule scaleR_right)
   872   apply (rule scaleR_left)
   873   apply (subst mult_commute)
   874   using bounded by fast
   875 
   876 lemma (in bounded_bilinear) Bfun_prod_Zfun:
   877   assumes f: "Bfun f F"
   878   assumes g: "Zfun g F"
   879   shows "Zfun (\<lambda>x. f x ** g x) F"
   880   using flip g f by (rule bounded_bilinear.Zfun_prod_Bfun)
   881 
   882 lemma Bfun_inverse_lemma:
   883   fixes x :: "'a::real_normed_div_algebra"
   884   shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
   885   apply (subst nonzero_norm_inverse, clarsimp)
   886   apply (erule (1) le_imp_inverse_le)
   887   done
   888 
   889 lemma Bfun_inverse:
   890   fixes a :: "'a::real_normed_div_algebra"
   891   assumes f: "(f ---> a) F"
   892   assumes a: "a \<noteq> 0"
   893   shows "Bfun (\<lambda>x. inverse (f x)) F"
   894 proof -
   895   from a have "0 < norm a" by simp
   896   hence "\<exists>r>0. r < norm a" by (rule dense)
   897   then obtain r where r1: "0 < r" and r2: "r < norm a" by fast
   898   have "eventually (\<lambda>x. dist (f x) a < r) F"
   899     using tendstoD [OF f r1] by fast
   900   hence "eventually (\<lambda>x. norm (inverse (f x)) \<le> inverse (norm a - r)) F"
   901   proof (rule eventually_elim1)
   902     fix x
   903     assume "dist (f x) a < r"
   904     hence 1: "norm (f x - a) < r"
   905       by (simp add: dist_norm)
   906     hence 2: "f x \<noteq> 0" using r2 by auto
   907     hence "norm (inverse (f x)) = inverse (norm (f x))"
   908       by (rule nonzero_norm_inverse)
   909     also have "\<dots> \<le> inverse (norm a - r)"
   910     proof (rule le_imp_inverse_le)
   911       show "0 < norm a - r" using r2 by simp
   912     next
   913       have "norm a - norm (f x) \<le> norm (a - f x)"
   914         by (rule norm_triangle_ineq2)
   915       also have "\<dots> = norm (f x - a)"
   916         by (rule norm_minus_commute)
   917       also have "\<dots> < r" using 1 .
   918       finally show "norm a - r \<le> norm (f x)" by simp
   919     qed
   920     finally show "norm (inverse (f x)) \<le> inverse (norm a - r)" .
   921   qed
   922   thus ?thesis by (rule BfunI)
   923 qed
   924 
   925 lemma tendsto_inverse [tendsto_intros]:
   926   fixes a :: "'a::real_normed_div_algebra"
   927   assumes f: "(f ---> a) F"
   928   assumes a: "a \<noteq> 0"
   929   shows "((\<lambda>x. inverse (f x)) ---> inverse a) F"
   930 proof -
   931   from a have "0 < norm a" by simp
   932   with f have "eventually (\<lambda>x. dist (f x) a < norm a) F"
   933     by (rule tendstoD)
   934   then have "eventually (\<lambda>x. f x \<noteq> 0) F"
   935     unfolding dist_norm by (auto elim!: eventually_elim1)
   936   with a have "eventually (\<lambda>x. inverse (f x) - inverse a =
   937     - (inverse (f x) * (f x - a) * inverse a)) F"
   938     by (auto elim!: eventually_elim1 simp: inverse_diff_inverse)
   939   moreover have "Zfun (\<lambda>x. - (inverse (f x) * (f x - a) * inverse a)) F"
   940     by (intro Zfun_minus Zfun_mult_left
   941       bounded_bilinear.Bfun_prod_Zfun [OF bounded_bilinear_mult]
   942       Bfun_inverse [OF f a] f [unfolded tendsto_Zfun_iff])
   943   ultimately show ?thesis
   944     unfolding tendsto_Zfun_iff by (rule Zfun_ssubst)
   945 qed
   946 
   947 lemma tendsto_divide [tendsto_intros]:
   948   fixes a b :: "'a::real_normed_field"
   949   shows "\<lbrakk>(f ---> a) F; (g ---> b) F; b \<noteq> 0\<rbrakk>
   950     \<Longrightarrow> ((\<lambda>x. f x / g x) ---> a / b) F"
   951   by (simp add: tendsto_mult tendsto_inverse divide_inverse)
   952 
   953 lemma tendsto_sgn [tendsto_intros]:
   954   fixes l :: "'a::real_normed_vector"
   955   shows "\<lbrakk>(f ---> l) F; l \<noteq> 0\<rbrakk> \<Longrightarrow> ((\<lambda>x. sgn (f x)) ---> sgn l) F"
   956   unfolding sgn_div_norm by (simp add: tendsto_intros)
   957 
   958 end