src/HOL/Limits.thy
author huffman
Sun Aug 28 20:56:49 2011 -0700 (2011-08-28)
changeset 44571 bd91b77c4cd6
parent 44568 e6f291cb5810
child 44627 134c06282ae6
permissions -rw-r--r--
move class perfect_space into RealVector.thy;
use not_open_singleton as perfect_space class axiom;
generalize some lemmas to class perfect_space;
     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: "F within UNIV = F"
   302   unfolding filter_eq_iff eventually_within by simp
   303 
   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
   321 
   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
   333 
   334 lemma nhds_neq_bot [simp]: "nhds a \<noteq> bot"
   335   unfolding trivial_limit_def eventually_nhds by simp
   336 
   337 lemma eventually_at_topological:
   338   "eventually P (at a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. x \<noteq> a \<longrightarrow> P x))"
   339 unfolding at_def eventually_within eventually_nhds by simp
   340 
   341 lemma eventually_at:
   342   fixes a :: "'a::metric_space"
   343   shows "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> P x)"
   344 unfolding at_def eventually_within eventually_nhds_metric by auto
   345 
   346 lemma at_eq_bot_iff: "at a = bot \<longleftrightarrow> open {a}"
   347   unfolding trivial_limit_def eventually_at_topological
   348   by (safe, case_tac "S = {a}", simp, fast, fast)
   349 
   350 lemma at_neq_bot [simp]: "at (a::'a::perfect_space) \<noteq> bot"
   351   by (simp add: at_eq_bot_iff not_open_singleton)
   352 
   353 
   354 subsection {* Boundedness *}
   355 
   356 definition Bfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
   357   where "Bfun f F = (\<exists>K>0. eventually (\<lambda>x. norm (f x) \<le> K) F)"
   358 
   359 lemma BfunI:
   360   assumes K: "eventually (\<lambda>x. norm (f x) \<le> K) F" shows "Bfun f F"
   361 unfolding Bfun_def
   362 proof (intro exI conjI allI)
   363   show "0 < max K 1" by simp
   364 next
   365   show "eventually (\<lambda>x. norm (f x) \<le> max K 1) F"
   366     using K by (rule eventually_elim1, simp)
   367 qed
   368 
   369 lemma BfunE:
   370   assumes "Bfun f F"
   371   obtains B where "0 < B" and "eventually (\<lambda>x. norm (f x) \<le> B) F"
   372 using assms unfolding Bfun_def by fast
   373 
   374 
   375 subsection {* Convergence to Zero *}
   376 
   377 definition Zfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
   378   where "Zfun f F = (\<forall>r>0. eventually (\<lambda>x. norm (f x) < r) F)"
   379 
   380 lemma ZfunI:
   381   "(\<And>r. 0 < r \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F) \<Longrightarrow> Zfun f F"
   382   unfolding Zfun_def by simp
   383 
   384 lemma ZfunD:
   385   "\<lbrakk>Zfun f F; 0 < r\<rbrakk> \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F"
   386   unfolding Zfun_def by simp
   387 
   388 lemma Zfun_ssubst:
   389   "eventually (\<lambda>x. f x = g x) F \<Longrightarrow> Zfun g F \<Longrightarrow> Zfun f F"
   390   unfolding Zfun_def by (auto elim!: eventually_rev_mp)
   391 
   392 lemma Zfun_zero: "Zfun (\<lambda>x. 0) F"
   393   unfolding Zfun_def by simp
   394 
   395 lemma Zfun_norm_iff: "Zfun (\<lambda>x. norm (f x)) F = Zfun (\<lambda>x. f x) F"
   396   unfolding Zfun_def by simp
   397 
   398 lemma Zfun_imp_Zfun:
   399   assumes f: "Zfun f F"
   400   assumes g: "eventually (\<lambda>x. norm (g x) \<le> norm (f x) * K) F"
   401   shows "Zfun (\<lambda>x. g x) F"
   402 proof (cases)
   403   assume K: "0 < K"
   404   show ?thesis
   405   proof (rule ZfunI)
   406     fix r::real assume "0 < r"
   407     hence "0 < r / K"
   408       using K by (rule divide_pos_pos)
   409     then have "eventually (\<lambda>x. norm (f x) < r / K) F"
   410       using ZfunD [OF f] by fast
   411     with g show "eventually (\<lambda>x. norm (g x) < r) F"
   412     proof (rule eventually_elim2)
   413       fix x
   414       assume *: "norm (g x) \<le> norm (f x) * K"
   415       assume "norm (f x) < r / K"
   416       hence "norm (f x) * K < r"
   417         by (simp add: pos_less_divide_eq K)
   418       thus "norm (g x) < r"
   419         by (simp add: order_le_less_trans [OF *])
   420     qed
   421   qed
   422 next
   423   assume "\<not> 0 < K"
   424   hence K: "K \<le> 0" by (simp only: not_less)
   425   show ?thesis
   426   proof (rule ZfunI)
   427     fix r :: real
   428     assume "0 < r"
   429     from g show "eventually (\<lambda>x. norm (g x) < r) F"
   430     proof (rule eventually_elim1)
   431       fix x
   432       assume "norm (g x) \<le> norm (f x) * K"
   433       also have "\<dots> \<le> norm (f x) * 0"
   434         using K norm_ge_zero by (rule mult_left_mono)
   435       finally show "norm (g x) < r"
   436         using `0 < r` by simp
   437     qed
   438   qed
   439 qed
   440 
   441 lemma Zfun_le: "\<lbrakk>Zfun g F; \<forall>x. norm (f x) \<le> norm (g x)\<rbrakk> \<Longrightarrow> Zfun f F"
   442   by (erule_tac K="1" in Zfun_imp_Zfun, simp)
   443 
   444 lemma Zfun_add:
   445   assumes f: "Zfun f F" and g: "Zfun g F"
   446   shows "Zfun (\<lambda>x. f x + g x) F"
   447 proof (rule ZfunI)
   448   fix r::real assume "0 < r"
   449   hence r: "0 < r / 2" by simp
   450   have "eventually (\<lambda>x. norm (f x) < r/2) F"
   451     using f r by (rule ZfunD)
   452   moreover
   453   have "eventually (\<lambda>x. norm (g x) < r/2) F"
   454     using g r by (rule ZfunD)
   455   ultimately
   456   show "eventually (\<lambda>x. norm (f x + g x) < r) F"
   457   proof (rule eventually_elim2)
   458     fix x
   459     assume *: "norm (f x) < r/2" "norm (g x) < r/2"
   460     have "norm (f x + g x) \<le> norm (f x) + norm (g x)"
   461       by (rule norm_triangle_ineq)
   462     also have "\<dots> < r/2 + r/2"
   463       using * by (rule add_strict_mono)
   464     finally show "norm (f x + g x) < r"
   465       by simp
   466   qed
   467 qed
   468 
   469 lemma Zfun_minus: "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. - f x) F"
   470   unfolding Zfun_def by simp
   471 
   472 lemma Zfun_diff: "\<lbrakk>Zfun f F; Zfun g F\<rbrakk> \<Longrightarrow> Zfun (\<lambda>x. f x - g x) F"
   473   by (simp only: diff_minus Zfun_add Zfun_minus)
   474 
   475 lemma (in bounded_linear) Zfun:
   476   assumes g: "Zfun g F"
   477   shows "Zfun (\<lambda>x. f (g x)) F"
   478 proof -
   479   obtain K where "\<And>x. norm (f x) \<le> norm x * K"
   480     using bounded by fast
   481   then have "eventually (\<lambda>x. norm (f (g x)) \<le> norm (g x) * K) F"
   482     by simp
   483   with g show ?thesis
   484     by (rule Zfun_imp_Zfun)
   485 qed
   486 
   487 lemma (in bounded_bilinear) Zfun:
   488   assumes f: "Zfun f F"
   489   assumes g: "Zfun g F"
   490   shows "Zfun (\<lambda>x. f x ** g x) F"
   491 proof (rule ZfunI)
   492   fix r::real assume r: "0 < r"
   493   obtain K where K: "0 < K"
   494     and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
   495     using pos_bounded by fast
   496   from K have K': "0 < inverse K"
   497     by (rule positive_imp_inverse_positive)
   498   have "eventually (\<lambda>x. norm (f x) < r) F"
   499     using f r by (rule ZfunD)
   500   moreover
   501   have "eventually (\<lambda>x. norm (g x) < inverse K) F"
   502     using g K' by (rule ZfunD)
   503   ultimately
   504   show "eventually (\<lambda>x. norm (f x ** g x) < r) F"
   505   proof (rule eventually_elim2)
   506     fix x
   507     assume *: "norm (f x) < r" "norm (g x) < inverse K"
   508     have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
   509       by (rule norm_le)
   510     also have "norm (f x) * norm (g x) * K < r * inverse K * K"
   511       by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero * K)
   512     also from K have "r * inverse K * K = r"
   513       by simp
   514     finally show "norm (f x ** g x) < r" .
   515   qed
   516 qed
   517 
   518 lemma (in bounded_bilinear) Zfun_left:
   519   "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. f x ** a) F"
   520   by (rule bounded_linear_left [THEN bounded_linear.Zfun])
   521 
   522 lemma (in bounded_bilinear) Zfun_right:
   523   "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. a ** f x) F"
   524   by (rule bounded_linear_right [THEN bounded_linear.Zfun])
   525 
   526 lemmas Zfun_mult = bounded_bilinear.Zfun [OF bounded_bilinear_mult]
   527 lemmas Zfun_mult_right = bounded_bilinear.Zfun_right [OF bounded_bilinear_mult]
   528 lemmas Zfun_mult_left = bounded_bilinear.Zfun_left [OF bounded_bilinear_mult]
   529 
   530 
   531 subsection {* Limits *}
   532 
   533 definition (in topological_space)
   534   tendsto :: "('b \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'b filter \<Rightarrow> bool" (infixr "--->" 55) where
   535   "(f ---> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
   536 
   537 ML {*
   538 structure Tendsto_Intros = Named_Thms
   539 (
   540   val name = "tendsto_intros"
   541   val description = "introduction rules for tendsto"
   542 )
   543 *}
   544 
   545 setup Tendsto_Intros.setup
   546 
   547 lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f ---> l) F' \<Longrightarrow> (f ---> l) F"
   548   unfolding tendsto_def le_filter_def by fast
   549 
   550 lemma topological_tendstoI:
   551   "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F)
   552     \<Longrightarrow> (f ---> l) F"
   553   unfolding tendsto_def by auto
   554 
   555 lemma topological_tendstoD:
   556   "(f ---> l) F \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
   557   unfolding tendsto_def by auto
   558 
   559 lemma tendstoI:
   560   assumes "\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
   561   shows "(f ---> l) F"
   562   apply (rule topological_tendstoI)
   563   apply (simp add: open_dist)
   564   apply (drule (1) bspec, clarify)
   565   apply (drule assms)
   566   apply (erule eventually_elim1, simp)
   567   done
   568 
   569 lemma tendstoD:
   570   "(f ---> l) F \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
   571   apply (drule_tac S="{x. dist x l < e}" in topological_tendstoD)
   572   apply (clarsimp simp add: open_dist)
   573   apply (rule_tac x="e - dist x l" in exI, clarsimp)
   574   apply (simp only: less_diff_eq)
   575   apply (erule le_less_trans [OF dist_triangle])
   576   apply simp
   577   apply simp
   578   done
   579 
   580 lemma tendsto_iff:
   581   "(f ---> l) F \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) F)"
   582   using tendstoI tendstoD by fast
   583 
   584 lemma tendsto_Zfun_iff: "(f ---> a) F = Zfun (\<lambda>x. f x - a) F"
   585   by (simp only: tendsto_iff Zfun_def dist_norm)
   586 
   587 lemma tendsto_ident_at [tendsto_intros]: "((\<lambda>x. x) ---> a) (at a)"
   588   unfolding tendsto_def eventually_at_topological by auto
   589 
   590 lemma tendsto_ident_at_within [tendsto_intros]:
   591   "((\<lambda>x. x) ---> a) (at a within S)"
   592   unfolding tendsto_def eventually_within eventually_at_topological by auto
   593 
   594 lemma tendsto_const [tendsto_intros]: "((\<lambda>x. k) ---> k) F"
   595   by (simp add: tendsto_def)
   596 
   597 lemma tendsto_unique:
   598   fixes f :: "'a \<Rightarrow> 'b::t2_space"
   599   assumes "\<not> trivial_limit F" and "(f ---> a) F" and "(f ---> b) F"
   600   shows "a = b"
   601 proof (rule ccontr)
   602   assume "a \<noteq> b"
   603   obtain U V where "open U" "open V" "a \<in> U" "b \<in> V" "U \<inter> V = {}"
   604     using hausdorff [OF `a \<noteq> b`] by fast
   605   have "eventually (\<lambda>x. f x \<in> U) F"
   606     using `(f ---> a) F` `open U` `a \<in> U` by (rule topological_tendstoD)
   607   moreover
   608   have "eventually (\<lambda>x. f x \<in> V) F"
   609     using `(f ---> b) F` `open V` `b \<in> V` by (rule topological_tendstoD)
   610   ultimately
   611   have "eventually (\<lambda>x. False) F"
   612   proof (rule eventually_elim2)
   613     fix x
   614     assume "f x \<in> U" "f x \<in> V"
   615     hence "f x \<in> U \<inter> V" by simp
   616     with `U \<inter> V = {}` show "False" by simp
   617   qed
   618   with `\<not> trivial_limit F` show "False"
   619     by (simp add: trivial_limit_def)
   620 qed
   621 
   622 lemma tendsto_const_iff:
   623   fixes a b :: "'a::t2_space"
   624   assumes "\<not> trivial_limit F" shows "((\<lambda>x. a) ---> b) F \<longleftrightarrow> a = b"
   625   by (safe intro!: tendsto_const tendsto_unique [OF assms tendsto_const])
   626 
   627 lemma tendsto_compose:
   628   assumes g: "(g ---> g l) (at l)"
   629   assumes f: "(f ---> l) F"
   630   shows "((\<lambda>x. g (f x)) ---> g l) F"
   631 proof (rule topological_tendstoI)
   632   fix B assume B: "open B" "g l \<in> B"
   633   obtain A where A: "open A" "l \<in> A"
   634     and gB: "\<forall>y. y \<in> A \<longrightarrow> g y \<in> B"
   635     using topological_tendstoD [OF g B] B(2)
   636     unfolding eventually_at_topological by fast
   637   hence "\<forall>x. f x \<in> A \<longrightarrow> g (f x) \<in> B" by simp
   638   from this topological_tendstoD [OF f A]
   639   show "eventually (\<lambda>x. g (f x) \<in> B) F"
   640     by (rule eventually_mono)
   641 qed
   642 
   643 lemma tendsto_compose_eventually:
   644   assumes g: "(g ---> m) (at l)"
   645   assumes f: "(f ---> l) F"
   646   assumes inj: "eventually (\<lambda>x. f x \<noteq> l) F"
   647   shows "((\<lambda>x. g (f x)) ---> m) F"
   648 proof (rule topological_tendstoI)
   649   fix B assume B: "open B" "m \<in> B"
   650   obtain A where A: "open A" "l \<in> A"
   651     and gB: "\<And>y. y \<in> A \<Longrightarrow> y \<noteq> l \<Longrightarrow> g y \<in> B"
   652     using topological_tendstoD [OF g B]
   653     unfolding eventually_at_topological by fast
   654   show "eventually (\<lambda>x. g (f x) \<in> B) F"
   655     using topological_tendstoD [OF f A] inj
   656     by (rule eventually_elim2) (simp add: gB)
   657 qed
   658 
   659 lemma metric_tendsto_imp_tendsto:
   660   assumes f: "(f ---> a) F"
   661   assumes le: "eventually (\<lambda>x. dist (g x) b \<le> dist (f x) a) F"
   662   shows "(g ---> b) F"
   663 proof (rule tendstoI)
   664   fix e :: real assume "0 < e"
   665   with f have "eventually (\<lambda>x. dist (f x) a < e) F" by (rule tendstoD)
   666   with le show "eventually (\<lambda>x. dist (g x) b < e) F"
   667     using le_less_trans by (rule eventually_elim2)
   668 qed
   669 
   670 subsubsection {* Distance and norms *}
   671 
   672 lemma tendsto_dist [tendsto_intros]:
   673   assumes f: "(f ---> l) F" and g: "(g ---> m) F"
   674   shows "((\<lambda>x. dist (f x) (g x)) ---> dist l m) F"
   675 proof (rule tendstoI)
   676   fix e :: real assume "0 < e"
   677   hence e2: "0 < e/2" by simp
   678   from tendstoD [OF f e2] tendstoD [OF g e2]
   679   show "eventually (\<lambda>x. dist (dist (f x) (g x)) (dist l m) < e) F"
   680   proof (rule eventually_elim2)
   681     fix x assume "dist (f x) l < e/2" "dist (g x) m < e/2"
   682     then show "dist (dist (f x) (g x)) (dist l m) < e"
   683       unfolding dist_real_def
   684       using dist_triangle2 [of "f x" "g x" "l"]
   685       using dist_triangle2 [of "g x" "l" "m"]
   686       using dist_triangle3 [of "l" "m" "f x"]
   687       using dist_triangle [of "f x" "m" "g x"]
   688       by arith
   689   qed
   690 qed
   691 
   692 lemma norm_conv_dist: "norm x = dist x 0"
   693   unfolding dist_norm by simp
   694 
   695 lemma tendsto_norm [tendsto_intros]:
   696   "(f ---> a) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> norm a) F"
   697   unfolding norm_conv_dist by (intro tendsto_intros)
   698 
   699 lemma tendsto_norm_zero:
   700   "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> 0) F"
   701   by (drule tendsto_norm, simp)
   702 
   703 lemma tendsto_norm_zero_cancel:
   704   "((\<lambda>x. norm (f x)) ---> 0) F \<Longrightarrow> (f ---> 0) F"
   705   unfolding tendsto_iff dist_norm by simp
   706 
   707 lemma tendsto_norm_zero_iff:
   708   "((\<lambda>x. norm (f x)) ---> 0) F \<longleftrightarrow> (f ---> 0) F"
   709   unfolding tendsto_iff dist_norm by simp
   710 
   711 lemma tendsto_rabs [tendsto_intros]:
   712   "(f ---> (l::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> \<bar>l\<bar>) F"
   713   by (fold real_norm_def, rule tendsto_norm)
   714 
   715 lemma tendsto_rabs_zero:
   716   "(f ---> (0::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> 0) F"
   717   by (fold real_norm_def, rule tendsto_norm_zero)
   718 
   719 lemma tendsto_rabs_zero_cancel:
   720   "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<Longrightarrow> (f ---> 0) F"
   721   by (fold real_norm_def, rule tendsto_norm_zero_cancel)
   722 
   723 lemma tendsto_rabs_zero_iff:
   724   "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<longleftrightarrow> (f ---> 0) F"
   725   by (fold real_norm_def, rule tendsto_norm_zero_iff)
   726 
   727 subsubsection {* Addition and subtraction *}
   728 
   729 lemma tendsto_add [tendsto_intros]:
   730   fixes a b :: "'a::real_normed_vector"
   731   shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> a + b) F"
   732   by (simp only: tendsto_Zfun_iff add_diff_add Zfun_add)
   733 
   734 lemma tendsto_add_zero:
   735   fixes f g :: "'a::type \<Rightarrow> 'b::real_normed_vector"
   736   shows "\<lbrakk>(f ---> 0) F; (g ---> 0) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> 0) F"
   737   by (drule (1) tendsto_add, simp)
   738 
   739 lemma tendsto_minus [tendsto_intros]:
   740   fixes a :: "'a::real_normed_vector"
   741   shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. - f x) ---> - a) F"
   742   by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
   743 
   744 lemma tendsto_minus_cancel:
   745   fixes a :: "'a::real_normed_vector"
   746   shows "((\<lambda>x. - f x) ---> - a) F \<Longrightarrow> (f ---> a) F"
   747   by (drule tendsto_minus, simp)
   748 
   749 lemma tendsto_diff [tendsto_intros]:
   750   fixes a b :: "'a::real_normed_vector"
   751   shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x - g x) ---> a - b) F"
   752   by (simp add: diff_minus tendsto_add tendsto_minus)
   753 
   754 lemma tendsto_setsum [tendsto_intros]:
   755   fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
   756   assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> a i) F"
   757   shows "((\<lambda>x. \<Sum>i\<in>S. f i x) ---> (\<Sum>i\<in>S. a i)) F"
   758 proof (cases "finite S")
   759   assume "finite S" thus ?thesis using assms
   760     by (induct, simp add: tendsto_const, simp add: tendsto_add)
   761 next
   762   assume "\<not> finite S" thus ?thesis
   763     by (simp add: tendsto_const)
   764 qed
   765 
   766 subsubsection {* Linear operators and multiplication *}
   767 
   768 lemma (in bounded_linear) tendsto:
   769   "(g ---> a) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> f a) F"
   770   by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
   771 
   772 lemma (in bounded_linear) tendsto_zero:
   773   "(g ---> 0) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> 0) F"
   774   by (drule tendsto, simp only: zero)
   775 
   776 lemma (in bounded_bilinear) tendsto:
   777   "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x ** g x) ---> a ** b) F"
   778   by (simp only: tendsto_Zfun_iff prod_diff_prod
   779                  Zfun_add Zfun Zfun_left Zfun_right)
   780 
   781 lemma (in bounded_bilinear) tendsto_zero:
   782   assumes f: "(f ---> 0) F"
   783   assumes g: "(g ---> 0) F"
   784   shows "((\<lambda>x. f x ** g x) ---> 0) F"
   785   using tendsto [OF f g] by (simp add: zero_left)
   786 
   787 lemma (in bounded_bilinear) tendsto_left_zero:
   788   "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. f x ** c) ---> 0) F"
   789   by (rule bounded_linear.tendsto_zero [OF bounded_linear_left])
   790 
   791 lemma (in bounded_bilinear) tendsto_right_zero:
   792   "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. c ** f x) ---> 0) F"
   793   by (rule bounded_linear.tendsto_zero [OF bounded_linear_right])
   794 
   795 lemmas tendsto_of_real [tendsto_intros] =
   796   bounded_linear.tendsto [OF bounded_linear_of_real]
   797 
   798 lemmas tendsto_scaleR [tendsto_intros] =
   799   bounded_bilinear.tendsto [OF bounded_bilinear_scaleR]
   800 
   801 lemmas tendsto_mult [tendsto_intros] =
   802   bounded_bilinear.tendsto [OF bounded_bilinear_mult]
   803 
   804 lemmas tendsto_mult_zero =
   805   bounded_bilinear.tendsto_zero [OF bounded_bilinear_mult]
   806 
   807 lemmas tendsto_mult_left_zero =
   808   bounded_bilinear.tendsto_left_zero [OF bounded_bilinear_mult]
   809 
   810 lemmas tendsto_mult_right_zero =
   811   bounded_bilinear.tendsto_right_zero [OF bounded_bilinear_mult]
   812 
   813 lemma tendsto_power [tendsto_intros]:
   814   fixes f :: "'a \<Rightarrow> 'b::{power,real_normed_algebra}"
   815   shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. f x ^ n) ---> a ^ n) F"
   816   by (induct n) (simp_all add: tendsto_const tendsto_mult)
   817 
   818 lemma tendsto_setprod [tendsto_intros]:
   819   fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
   820   assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> L i) F"
   821   shows "((\<lambda>x. \<Prod>i\<in>S. f i x) ---> (\<Prod>i\<in>S. L i)) F"
   822 proof (cases "finite S")
   823   assume "finite S" thus ?thesis using assms
   824     by (induct, simp add: tendsto_const, simp add: tendsto_mult)
   825 next
   826   assume "\<not> finite S" thus ?thesis
   827     by (simp add: tendsto_const)
   828 qed
   829 
   830 subsubsection {* Inverse and division *}
   831 
   832 lemma (in bounded_bilinear) Zfun_prod_Bfun:
   833   assumes f: "Zfun f F"
   834   assumes g: "Bfun g F"
   835   shows "Zfun (\<lambda>x. f x ** g x) F"
   836 proof -
   837   obtain K where K: "0 \<le> K"
   838     and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
   839     using nonneg_bounded by fast
   840   obtain B where B: "0 < B"
   841     and norm_g: "eventually (\<lambda>x. norm (g x) \<le> B) F"
   842     using g by (rule BfunE)
   843   have "eventually (\<lambda>x. norm (f x ** g x) \<le> norm (f x) * (B * K)) F"
   844   using norm_g proof (rule eventually_elim1)
   845     fix x
   846     assume *: "norm (g x) \<le> B"
   847     have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
   848       by (rule norm_le)
   849     also have "\<dots> \<le> norm (f x) * B * K"
   850       by (intro mult_mono' order_refl norm_g norm_ge_zero
   851                 mult_nonneg_nonneg K *)
   852     also have "\<dots> = norm (f x) * (B * K)"
   853       by (rule mult_assoc)
   854     finally show "norm (f x ** g x) \<le> norm (f x) * (B * K)" .
   855   qed
   856   with f show ?thesis
   857     by (rule Zfun_imp_Zfun)
   858 qed
   859 
   860 lemma (in bounded_bilinear) flip:
   861   "bounded_bilinear (\<lambda>x y. y ** x)"
   862   apply default
   863   apply (rule add_right)
   864   apply (rule add_left)
   865   apply (rule scaleR_right)
   866   apply (rule scaleR_left)
   867   apply (subst mult_commute)
   868   using bounded by fast
   869 
   870 lemma (in bounded_bilinear) Bfun_prod_Zfun:
   871   assumes f: "Bfun f F"
   872   assumes g: "Zfun g F"
   873   shows "Zfun (\<lambda>x. f x ** g x) F"
   874   using flip g f by (rule bounded_bilinear.Zfun_prod_Bfun)
   875 
   876 lemma Bfun_inverse_lemma:
   877   fixes x :: "'a::real_normed_div_algebra"
   878   shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
   879   apply (subst nonzero_norm_inverse, clarsimp)
   880   apply (erule (1) le_imp_inverse_le)
   881   done
   882 
   883 lemma Bfun_inverse:
   884   fixes a :: "'a::real_normed_div_algebra"
   885   assumes f: "(f ---> a) F"
   886   assumes a: "a \<noteq> 0"
   887   shows "Bfun (\<lambda>x. inverse (f x)) F"
   888 proof -
   889   from a have "0 < norm a" by simp
   890   hence "\<exists>r>0. r < norm a" by (rule dense)
   891   then obtain r where r1: "0 < r" and r2: "r < norm a" by fast
   892   have "eventually (\<lambda>x. dist (f x) a < r) F"
   893     using tendstoD [OF f r1] by fast
   894   hence "eventually (\<lambda>x. norm (inverse (f x)) \<le> inverse (norm a - r)) F"
   895   proof (rule eventually_elim1)
   896     fix x
   897     assume "dist (f x) a < r"
   898     hence 1: "norm (f x - a) < r"
   899       by (simp add: dist_norm)
   900     hence 2: "f x \<noteq> 0" using r2 by auto
   901     hence "norm (inverse (f x)) = inverse (norm (f x))"
   902       by (rule nonzero_norm_inverse)
   903     also have "\<dots> \<le> inverse (norm a - r)"
   904     proof (rule le_imp_inverse_le)
   905       show "0 < norm a - r" using r2 by simp
   906     next
   907       have "norm a - norm (f x) \<le> norm (a - f x)"
   908         by (rule norm_triangle_ineq2)
   909       also have "\<dots> = norm (f x - a)"
   910         by (rule norm_minus_commute)
   911       also have "\<dots> < r" using 1 .
   912       finally show "norm a - r \<le> norm (f x)" by simp
   913     qed
   914     finally show "norm (inverse (f x)) \<le> inverse (norm a - r)" .
   915   qed
   916   thus ?thesis by (rule BfunI)
   917 qed
   918 
   919 lemma tendsto_inverse_lemma:
   920   fixes a :: "'a::real_normed_div_algebra"
   921   shows "\<lbrakk>(f ---> a) F; a \<noteq> 0; eventually (\<lambda>x. f x \<noteq> 0) F\<rbrakk>
   922          \<Longrightarrow> ((\<lambda>x. inverse (f x)) ---> inverse a) F"
   923   apply (subst tendsto_Zfun_iff)
   924   apply (rule Zfun_ssubst)
   925   apply (erule eventually_elim1)
   926   apply (erule (1) inverse_diff_inverse)
   927   apply (rule Zfun_minus)
   928   apply (rule Zfun_mult_left)
   929   apply (rule bounded_bilinear.Bfun_prod_Zfun [OF bounded_bilinear_mult])
   930   apply (erule (1) Bfun_inverse)
   931   apply (simp add: tendsto_Zfun_iff)
   932   done
   933 
   934 lemma tendsto_inverse [tendsto_intros]:
   935   fixes a :: "'a::real_normed_div_algebra"
   936   assumes f: "(f ---> a) F"
   937   assumes a: "a \<noteq> 0"
   938   shows "((\<lambda>x. inverse (f x)) ---> inverse a) F"
   939 proof -
   940   from a have "0 < norm a" by simp
   941   with f have "eventually (\<lambda>x. dist (f x) a < norm a) F"
   942     by (rule tendstoD)
   943   then have "eventually (\<lambda>x. f x \<noteq> 0) F"
   944     unfolding dist_norm by (auto elim!: eventually_elim1)
   945   with f a show ?thesis
   946     by (rule tendsto_inverse_lemma)
   947 qed
   948 
   949 lemma tendsto_divide [tendsto_intros]:
   950   fixes a b :: "'a::real_normed_field"
   951   shows "\<lbrakk>(f ---> a) F; (g ---> b) F; b \<noteq> 0\<rbrakk>
   952     \<Longrightarrow> ((\<lambda>x. f x / g x) ---> a / b) F"
   953   by (simp add: tendsto_mult tendsto_inverse divide_inverse)
   954 
   955 lemma tendsto_sgn [tendsto_intros]:
   956   fixes l :: "'a::real_normed_vector"
   957   shows "\<lbrakk>(f ---> l) F; l \<noteq> 0\<rbrakk> \<Longrightarrow> ((\<lambda>x. sgn (f x)) ---> sgn l) F"
   958   unfolding sgn_div_norm by (simp add: tendsto_intros)
   959 
   960 end