src/HOL/Analysis/Extended_Real_Limits.thy
changeset 76876 c9ffd9cf58db
parent 73932 fd21b4a93043
child 76894 23f819af2d9f
equal deleted inserted replaced
76875:edf430326683 76876:c9ffd9cf58db
   173 qed
   173 qed
   174 
   174 
   175 lemma ereal_open_closed:
   175 lemma ereal_open_closed:
   176   fixes S :: "ereal set"
   176   fixes S :: "ereal set"
   177   shows "open S \<and> closed S \<longleftrightarrow> S = {} \<or> S = UNIV"
   177   shows "open S \<and> closed S \<longleftrightarrow> S = {} \<or> S = UNIV"
   178 proof -
   178   using ereal_open_closed_aux open_closed by auto
   179   {
       
   180     assume lhs: "open S \<and> closed S"
       
   181     {
       
   182       assume "-\<infinity> \<notin> S"
       
   183       then have "S = {}"
       
   184         using lhs ereal_open_closed_aux by auto
       
   185     }
       
   186     moreover
       
   187     {
       
   188       assume "-\<infinity> \<in> S"
       
   189       then have "- S = {}"
       
   190         using lhs ereal_open_closed_aux[of "-S"] by auto
       
   191     }
       
   192     ultimately have "S = {} \<or> S = UNIV"
       
   193       by auto
       
   194   }
       
   195   then show ?thesis
       
   196     by auto
       
   197 qed
       
   198 
   179 
   199 lemma ereal_open_atLeast:
   180 lemma ereal_open_atLeast:
   200   fixes x :: ereal
   181   fixes x :: ereal
   201   shows "open {x..} \<longleftrightarrow> x = -\<infinity>"
   182   shows "open {x..} \<longleftrightarrow> x = -\<infinity>"
   202 proof
   183   by (metis atLeast_eq_UNIV_iff bot_ereal_def closed_atLeast ereal_open_closed not_Ici_eq_empty)
   203   assume "x = -\<infinity>"
       
   204   then have "{x..} = UNIV"
       
   205     by auto
       
   206   then show "open {x..}"
       
   207     by auto
       
   208 next
       
   209   assume "open {x..}"
       
   210   then have "open {x..} \<and> closed {x..}"
       
   211     by auto
       
   212   then have "{x..} = UNIV"
       
   213     unfolding ereal_open_closed by auto
       
   214   then show "x = -\<infinity>"
       
   215     by (simp add: bot_ereal_def atLeast_eq_UNIV_iff)
       
   216 qed
       
   217 
   184 
   218 lemma mono_closed_real:
   185 lemma mono_closed_real:
   219   fixes S :: "real set"
   186   fixes S :: "real set"
   220   assumes mono: "\<forall>y z. y \<in> S \<and> y \<le> z \<longrightarrow> z \<in> S"
   187   assumes mono: "\<forall>y z. y \<in> S \<and> y \<le> z \<longrightarrow> z \<in> S"
   221     and "closed S"
   188     and "closed S"
   225     assume "S \<noteq> {}"
   192     assume "S \<noteq> {}"
   226     { assume ex: "\<exists>B. \<forall>x\<in>S. B \<le> x"
   193     { assume ex: "\<exists>B. \<forall>x\<in>S. B \<le> x"
   227       then have *: "\<forall>x\<in>S. Inf S \<le> x"
   194       then have *: "\<forall>x\<in>S. Inf S \<le> x"
   228         using cInf_lower[of _ S] ex by (metis bdd_below_def)
   195         using cInf_lower[of _ S] ex by (metis bdd_below_def)
   229       then have "Inf S \<in> S"
   196       then have "Inf S \<in> S"
   230         apply (subst closed_contains_Inf)
   197         by (meson \<open>S \<noteq> {}\<close> assms(2) bdd_belowI closed_contains_Inf)
   231         using ex \<open>S \<noteq> {}\<close> \<open>closed S\<close>
       
   232         apply auto
       
   233         done
       
   234       then have "\<forall>x. Inf S \<le> x \<longleftrightarrow> x \<in> S"
   198       then have "\<forall>x. Inf S \<le> x \<longleftrightarrow> x \<in> S"
   235         using mono[rule_format, of "Inf S"] *
   199         using mono[rule_format, of "Inf S"] *
   236         by auto
   200         by auto
   237       then have "S = {Inf S ..}"
   201       then have "S = {Inf S ..}"
   238         by auto
   202         by auto
   265   fixes S :: "real set"
   229   fixes S :: "real set"
   266   assumes mono: "\<forall>y z. y \<in> S \<and> y \<le> z \<longrightarrow> z \<in> S"
   230   assumes mono: "\<forall>y z. y \<in> S \<and> y \<le> z \<longrightarrow> z \<in> S"
   267     and "closed S"
   231     and "closed S"
   268   shows "\<exists>a. S = {x. a \<le> ereal x}"
   232   shows "\<exists>a. S = {x. a \<le> ereal x}"
   269 proof -
   233 proof -
   270   {
   234   consider "S = {} \<or> S = UNIV" | "(\<exists>a. S = {a..})"
   271     assume "S = {}"
   235     using assms(2) mono mono_closed_real by blast
   272     then have ?thesis
   236   then show ?thesis
   273       apply (rule_tac x=PInfty in exI)
   237   proof cases
   274       apply auto
   238     case 1
   275       done
   239     then show ?thesis
   276   }
   240       by (meson PInfty_neq_ereal(1) UNIV_eq_I bot.extremum empty_Collect_eq ereal_infty_less_eq(1) mem_Collect_eq)
   277   moreover
   241   next
   278   {
   242     case 2
   279     assume "S = UNIV"
   243     then show ?thesis
   280     then have ?thesis
   244       by (metis atLeast_iff ereal_less_eq(3) mem_Collect_eq subsetI subset_antisym)
   281       apply (rule_tac x="-\<infinity>" in exI)
   245   qed
   282       apply auto
       
   283       done
       
   284   }
       
   285   moreover
       
   286   {
       
   287     assume "\<exists>a. S = {a ..}"
       
   288     then obtain a where "S = {a ..}"
       
   289       by auto
       
   290     then have ?thesis
       
   291       apply (rule_tac x="ereal a" in exI)
       
   292       apply auto
       
   293       done
       
   294   }
       
   295   ultimately show ?thesis
       
   296     using mono_closed_real[of S] assms by auto
       
   297 qed
   246 qed
   298 
   247 
   299 lemma Liminf_within:
   248 lemma Liminf_within:
   300   fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_lattice"
   249   fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_lattice"
   301   shows "Liminf (at x within S) f = (SUP e\<in>{0<..}. INF y\<in>(S \<inter> ball x e - {x}). f y)"
   250   shows "Liminf (at x within S) f = (SUP e\<in>{0<..}. INF y\<in>(S \<inter> ball x e - {x}). f y)"
   347   using Limsup_within[of x UNIV f] by simp
   296   using Limsup_within[of x UNIV f] by simp
   348 
   297 
   349 lemma min_Liminf_at:
   298 lemma min_Liminf_at:
   350   fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_linorder"
   299   fixes f :: "'a::metric_space \<Rightarrow> 'b::complete_linorder"
   351   shows "min (f x) (Liminf (at x) f) = (SUP e\<in>{0<..}. INF y\<in>ball x e. f y)"
   300   shows "min (f x) (Liminf (at x) f) = (SUP e\<in>{0<..}. INF y\<in>ball x e. f y)"
   352   apply (simp add: inf_min [symmetric] Liminf_at)
   301   apply (simp add: inf_min [symmetric] Liminf_at inf_commute [of "f x"] SUP_inf)
   353   apply (subst inf_commute)
       
   354   apply (subst SUP_inf)
       
   355   apply auto
       
   356   apply (metis (no_types, lifting) INF_insert centre_in_ball greaterThan_iff image_cong inf_commute insert_Diff)
   302   apply (metis (no_types, lifting) INF_insert centre_in_ball greaterThan_iff image_cong inf_commute insert_Diff)
   357   done
   303   done
   358 
   304 
   359 
   305 
   360 subsection \<open>Extended-Real.thy\<close> (*FIX ME change title *)
   306 subsection \<open>Extended-Real.thy\<close> (*FIX ME change title *)
   361 
   307 
   362 lemma sum_constant_ereal:
   308 lemma sum_constant_ereal:
   363   fixes a::ereal
   309   fixes a::ereal
   364   shows "(\<Sum>i\<in>I. a) = a * card I"
   310   shows "(\<Sum>i\<in>I. a) = a * card I"
   365 apply (cases "finite I", induct set: finite, simp_all)
   311 proof (induction I rule: infinite_finite_induct)
   366 apply (cases a, auto, metis (no_types, opaque_lifting) add.commute mult.commute semiring_normalization_rules(3))
   312   case (insert i I)
   367 done
   313   then show ?case
       
   314     by (simp add: ereal_right_distrib flip: plus_ereal.simps)
       
   315 qed auto
   368 
   316 
   369 lemma real_lim_then_eventually_real:
   317 lemma real_lim_then_eventually_real:
   370   assumes "(u \<longlongrightarrow> ereal l) F"
   318   assumes "(u \<longlongrightarrow> ereal l) F"
   371   shows "eventually (\<lambda>n. u n = ereal(real_of_ereal(u n))) F"
   319   shows "eventually (\<lambda>n. u n = ereal(real_of_ereal(u n))) F"
   372 proof -
   320 proof -
   379 
   327 
   380 lemma ereal_Inf_cmult:
   328 lemma ereal_Inf_cmult:
   381   assumes "c>(0::real)"
   329   assumes "c>(0::real)"
   382   shows "Inf {ereal c * x |x. P x} = ereal c * Inf {x. P x}"
   330   shows "Inf {ereal c * x |x. P x} = ereal c * Inf {x. P x}"
   383 proof -
   331 proof -
   384   have "(\<lambda>x::ereal. c * x) (Inf {x::ereal. P x}) = Inf ((\<lambda>x::ereal. c * x)`{x::ereal. P x})"
   332   have "bij ((*) (ereal c))"
   385     apply (rule mono_bij_Inf)
   333     apply (rule bij_betw_byWitness[of _ "\<lambda>x. (x::ereal) / c"], auto simp: assms ereal_mult_divide)
   386     apply (simp add: assms ereal_mult_left_mono less_imp_le mono_def)
   334     using assms ereal_divide_eq by auto
   387     apply (rule bij_betw_byWitness[of _ "\<lambda>x. (x::ereal) / c"], auto simp add: assms ereal_mult_divide)
   335   then have "ereal c * Inf {x. P x} = Inf ((*) (ereal c) ` {x. P x})"
   388     using assms ereal_divide_eq apply auto
   336     by (simp add: assms ereal_mult_left_mono less_imp_le mono_def mono_bij_Inf)
   389     done
   337   then show ?thesis
   390   then show ?thesis by (simp only: setcompr_eq_image[symmetric])
   338     by (simp add: setcompr_eq_image)
   391 qed
   339 qed
   392 
   340 
   393 
   341 
   394 subsubsection\<^marker>\<open>tag important\<close> \<open>Continuity of addition\<close>
   342 subsubsection\<^marker>\<open>tag important\<close> \<open>Continuity of addition\<close>
   395 
   343 
   423 
   371 
   424   {
   372   {
   425     fix M::real
   373     fix M::real
   426     have "eventually (\<lambda>x. f x > ereal(M - C)) F" using f by (simp add: tendsto_PInfty)
   374     have "eventually (\<lambda>x. f x > ereal(M - C)) F" using f by (simp add: tendsto_PInfty)
   427     then have "eventually (\<lambda>x. (f x > ereal (M-C)) \<and> (g x > ereal C)) F"
   375     then have "eventually (\<lambda>x. (f x > ereal (M-C)) \<and> (g x > ereal C)) F"
   428       by (auto simp add: ge eventually_conj_iff)
   376       by (auto simp: ge eventually_conj_iff)
   429     moreover have "\<And>x. ((f x > ereal (M-C)) \<and> (g x > ereal C)) \<Longrightarrow> (f x + g x > ereal M)"
   377     moreover have "\<And>x. ((f x > ereal (M-C)) \<and> (g x > ereal C)) \<Longrightarrow> (f x + g x > ereal M)"
   430       using ereal_add_strict_mono2 by fastforce
   378       using ereal_add_strict_mono2 by fastforce
   431     ultimately have "eventually (\<lambda>x. f x + g x > ereal M) F" using eventually_mono by force
   379     ultimately have "eventually (\<lambda>x. f x + g x > ereal M) F" using eventually_mono by force
   432   }
   380   }
   433   then show ?thesis by (simp add: tendsto_PInfty)
   381   then show ?thesis by (simp add: tendsto_PInfty)
   460 
   408 
   461   {
   409   {
   462     fix M::real
   410     fix M::real
   463     have "eventually (\<lambda>x. f x < ereal(M - C)) F" using f by (simp add: tendsto_MInfty)
   411     have "eventually (\<lambda>x. f x < ereal(M - C)) F" using f by (simp add: tendsto_MInfty)
   464     then have "eventually (\<lambda>x. (f x < ereal (M- C)) \<and> (g x < ereal C)) F"
   412     then have "eventually (\<lambda>x. (f x < ereal (M- C)) \<and> (g x < ereal C)) F"
   465       by (auto simp add: ge eventually_conj_iff)
   413       by (auto simp: ge eventually_conj_iff)
   466     moreover have "\<And>x. ((f x < ereal (M-C)) \<and> (g x < ereal C)) \<Longrightarrow> (f x + g x < ereal M)"
   414     moreover have "\<And>x. ((f x < ereal (M-C)) \<and> (g x < ereal C)) \<Longrightarrow> (f x + g x < ereal M)"
   467       using ereal_add_strict_mono2 by fastforce
   415       using ereal_add_strict_mono2 by fastforce
   468     ultimately have "eventually (\<lambda>x. f x + g x < ereal M) F" using eventually_mono by force
   416     ultimately have "eventually (\<lambda>x. f x + g x < ereal M) F" using eventually_mono by force
   469   }
   417   }
   470   then show ?thesis by (simp add: tendsto_MInfty)
   418   then show ?thesis by (simp add: tendsto_MInfty)
   493   assumes x: "\<bar>x\<bar> \<noteq> \<infinity>"
   441   assumes x: "\<bar>x\<bar> \<noteq> \<infinity>"
   494       and f: "(f \<longlongrightarrow> x) F" and g: "(g \<longlongrightarrow> y) F"
   442       and f: "(f \<longlongrightarrow> x) F" and g: "(g \<longlongrightarrow> y) F"
   495   shows "((\<lambda>x. f x + g x) \<longlongrightarrow> x + y) F"
   443   shows "((\<lambda>x. f x + g x) \<longlongrightarrow> x + y) F"
   496 proof -
   444 proof -
   497   have "((\<lambda>x. g x + f x) \<longlongrightarrow> x + y) F"
   445   have "((\<lambda>x. g x + f x) \<longlongrightarrow> x + y) F"
   498     using tendsto_add_ereal_general1[OF x, OF g, OF f] add.commute[of "y", of "x"] by simp
   446     by (metis (full_types) add.commute f g tendsto_add_ereal_general1 x)
   499   moreover have "\<And>x. g x + f x = f x + g x" using add.commute by auto
   447   moreover have "\<And>x. g x + f x = f x + g x" using add.commute by auto
   500   ultimately show ?thesis by simp
   448   ultimately show ?thesis by simp
   501 qed
   449 qed
   502 
   450 
   503 text \<open>The next lemma says that the addition is continuous on \<open>ereal\<close>, except at
   451 text \<open>The next lemma says that the addition is continuous on \<open>ereal\<close>, except at
   509       and f: "(f \<longlongrightarrow> x) F" and g: "(g \<longlongrightarrow> y) F"
   457       and f: "(f \<longlongrightarrow> x) F" and g: "(g \<longlongrightarrow> y) F"
   510   shows "((\<lambda>x. f x + g x) \<longlongrightarrow> x + y) F"
   458   shows "((\<lambda>x. f x + g x) \<longlongrightarrow> x + y) F"
   511 proof (cases x)
   459 proof (cases x)
   512   case (real r)
   460   case (real r)
   513   show ?thesis
   461   show ?thesis
   514     apply (rule tendsto_add_ereal_general2) using real assms by auto
   462     using real assms
       
   463     by (intro tendsto_add_ereal_general2; auto)
   515 next
   464 next
   516   case (PInf)
   465   case (PInf)
   517   then have "y \<noteq> -\<infinity>" using assms by simp
   466   then have "y \<noteq> -\<infinity>" using assms by simp
   518   then show ?thesis using tendsto_add_ereal_PInf PInf assms by auto
   467   then show ?thesis using tendsto_add_ereal_PInf PInf assms by auto
   519 next
   468 next
   520   case (MInf)
   469   case (MInf)
   521   then have "y \<noteq> \<infinity>" using assms by simp
   470   then have "y \<noteq> \<infinity>" using assms by simp
   522   then show ?thesis using tendsto_add_ereal_MInf MInf f g by (metis ereal_MInfty_eq_plus)
   471   then show ?thesis 
       
   472     by (metis ereal_MInfty_eq_plus tendsto_add_ereal_MInf MInf f g)
   523 qed
   473 qed
   524 
   474 
   525 subsubsection\<^marker>\<open>tag important\<close> \<open>Continuity of multiplication\<close>
   475 subsubsection\<^marker>\<open>tag important\<close> \<open>Continuity of multiplication\<close>
   526 
   476 
   527 text \<open>In the same way as for addition, we prove that the multiplication is continuous on
   477 text \<open>In the same way as for addition, we prove that the multiplication is continuous on
   539   then have "((\<lambda>n. ereal(real_of_ereal(v n))) \<longlongrightarrow> ereal m) F" using assms by auto
   489   then have "((\<lambda>n. ereal(real_of_ereal(v n))) \<longlongrightarrow> ereal m) F" using assms by auto
   540   then have limv: "((\<lambda>n. real_of_ereal(v n)) \<longlongrightarrow> m) F" by auto
   490   then have limv: "((\<lambda>n. real_of_ereal(v n)) \<longlongrightarrow> m) F" by auto
   541 
   491 
   542   {
   492   {
   543     fix n assume "u n = ereal(real_of_ereal(u n))" "v n = ereal(real_of_ereal(v n))"
   493     fix n assume "u n = ereal(real_of_ereal(u n))" "v n = ereal(real_of_ereal(v n))"
   544     then have "ereal(real_of_ereal(u n) * real_of_ereal(v n)) = u n * v n" by (metis times_ereal.simps(1))
   494     then have "ereal(real_of_ereal(u n) * real_of_ereal(v n)) = u n * v n" 
       
   495       by (metis times_ereal.simps(1))
   545   }
   496   }
   546   then have *: "eventually (\<lambda>n. ereal(real_of_ereal(u n) * real_of_ereal(v n)) = u n * v n) F"
   497   then have *: "eventually (\<lambda>n. ereal(real_of_ereal(u n) * real_of_ereal(v n)) = u n * v n) F"
   547     using eventually_elim2[OF ureal vreal] by auto
   498     using eventually_elim2[OF ureal vreal] by auto
   548 
   499 
   549   have "((\<lambda>n. real_of_ereal(u n) * real_of_ereal(v n)) \<longlongrightarrow> l * m) F" using tendsto_mult[OF limu limv] by auto
   500   have "((\<lambda>n. real_of_ereal(u n) * real_of_ereal(v n)) \<longlongrightarrow> l * m) F" 
   550   then have "((\<lambda>n. ereal(real_of_ereal(u n)) * real_of_ereal(v n)) \<longlongrightarrow> ereal(l * m)) F" by auto
   501     using tendsto_mult[OF limu limv] by auto
       
   502   then have "((\<lambda>n. ereal(real_of_ereal(u n)) * real_of_ereal(v n)) \<longlongrightarrow> ereal(l * m)) F" 
       
   503     by auto
   551   then show ?thesis using * filterlim_cong by fastforce
   504   then show ?thesis using * filterlim_cong by fastforce
   552 qed
   505 qed
   553 
   506 
   554 lemma tendsto_mult_ereal_PInf:
   507 lemma tendsto_mult_ereal_PInf:
   555   fixes f g::"_ \<Rightarrow> ereal"
   508   fixes f g::"_ \<Rightarrow> ereal"
   556   assumes "(f \<longlongrightarrow> l) F" "l>0" "(g \<longlongrightarrow> \<infinity>) F"
   509   assumes "(f \<longlongrightarrow> l) F" "l>0" "(g \<longlongrightarrow> \<infinity>) F"
   557   shows "((\<lambda>x. f x * g x) \<longlongrightarrow> \<infinity>) F"
   510   shows "((\<lambda>x. f x * g x) \<longlongrightarrow> \<infinity>) F"
   558 proof -
   511 proof -
   559   obtain a::real where "0 < ereal a" "a < l" using assms(2) using ereal_dense2 by blast
   512   obtain a::real where "0 < ereal a" "a < l" 
   560   have *: "eventually (\<lambda>x. f x > a) F" using \<open>a < l\<close> assms(1) by (simp add: order_tendsto_iff)
   513     using assms(2) using ereal_dense2 by blast
       
   514   have *: "eventually (\<lambda>x. f x > a) F" 
       
   515     using \<open>a < l\<close> assms(1) by (simp add: order_tendsto_iff)
   561   {
   516   {
   562     fix K::real
   517     fix K::real
   563     define M where "M = max K 1"
   518     define M where "M = max K 1"
   564     then have "M > 0" by simp
   519     then have "M > 0" by simp
   565     then have "ereal(M/a) > 0" using \<open>ereal a > 0\<close> by simp
   520     then have "ereal(M/a) > 0" using \<open>ereal a > 0\<close> by simp
   571     ultimately have Imp: "\<And>x. ((f x > a) \<and> (g x > M/a)) \<Longrightarrow> (f x * g x > K)"
   526     ultimately have Imp: "\<And>x. ((f x > a) \<and> (g x > M/a)) \<Longrightarrow> (f x * g x > K)"
   572       using ereal_less_eq(3) le_less_trans by blast
   527       using ereal_less_eq(3) le_less_trans by blast
   573 
   528 
   574     have "eventually (\<lambda>x. g x > M/a) F" using assms(3) by (simp add: tendsto_PInfty)
   529     have "eventually (\<lambda>x. g x > M/a) F" using assms(3) by (simp add: tendsto_PInfty)
   575     then have "eventually (\<lambda>x. (f x > a) \<and> (g x > M/a)) F"
   530     then have "eventually (\<lambda>x. (f x > a) \<and> (g x > M/a)) F"
   576       using * by (auto simp add: eventually_conj_iff)
   531       using * by (auto simp: eventually_conj_iff)
   577     then have "eventually (\<lambda>x. f x * g x > K) F" using eventually_mono Imp by force
   532     then have "eventually (\<lambda>x. f x * g x > K) F" using eventually_mono Imp by force
   578   }
   533   }
   579   then show ?thesis by (auto simp add: tendsto_PInfty)
   534   then show ?thesis by (auto simp: tendsto_PInfty)
   580 qed
   535 qed
   581 
   536 
   582 lemma tendsto_mult_ereal_pos:
   537 lemma tendsto_mult_ereal_pos:
   583   fixes f g::"_ \<Rightarrow> ereal"
   538   fixes f g::"_ \<Rightarrow> ereal"
   584   assumes "(f \<longlongrightarrow> l) F" "(g \<longlongrightarrow> m) F" "l>0" "m>0"
   539   assumes "(f \<longlongrightarrow> l) F" "(g \<longlongrightarrow> m) F" "l>0" "m>0"
   609 give the bare minimum we need.\<close>
   564 give the bare minimum we need.\<close>
   610 
   565 
   611 lemma ereal_sgn_abs:
   566 lemma ereal_sgn_abs:
   612   fixes l::ereal
   567   fixes l::ereal
   613   shows "sgn(l) * l = abs(l)"
   568   shows "sgn(l) * l = abs(l)"
   614 apply (cases l) by (auto simp add: sgn_if ereal_less_uminus_reorder)
   569     by (cases l, auto simp: sgn_if ereal_less_uminus_reorder)
   615 
   570 
   616 lemma sgn_squared_ereal:
   571 lemma sgn_squared_ereal:
   617   assumes "l \<noteq> (0::ereal)"
   572   assumes "l \<noteq> (0::ereal)"
   618   shows "sgn(l) * sgn(l) = 1"
   573   shows "sgn(l) * sgn(l) = 1"
   619 apply (cases l) using assms by (auto simp add: one_ereal_def sgn_if)
   574   using assms by (cases l, auto simp: one_ereal_def sgn_if)
   620 
   575 
   621 lemma tendsto_mult_ereal [tendsto_intros]:
   576 lemma tendsto_mult_ereal [tendsto_intros]:
   622   fixes f g::"_ \<Rightarrow> ereal"
   577   fixes f g::"_ \<Rightarrow> ereal"
   623   assumes "(f \<longlongrightarrow> l) F" "(g \<longlongrightarrow> m) F" "\<not>((l=0 \<and> abs(m) = \<infinity>) \<or> (m=0 \<and> abs(l) = \<infinity>))"
   578   assumes "(f \<longlongrightarrow> l) F" "(g \<longlongrightarrow> m) F" "\<not>((l=0 \<and> abs(m) = \<infinity>) \<or> (m=0 \<and> abs(l) = \<infinity>))"
   624   shows "((\<lambda>x. f x * g x) \<longlongrightarrow> l * m) F"
   579   shows "((\<lambda>x. f x * g x) \<longlongrightarrow> l * m) F"
   636   then have "l \<noteq> 0" "m \<noteq> 0" by auto
   591   then have "l \<noteq> 0" "m \<noteq> 0" by auto
   637   then have "abs(l) > 0" "abs(m) > 0"
   592   then have "abs(l) > 0" "abs(m) > 0"
   638     by (metis abs_ereal_ge0 abs_ereal_less0 abs_ereal_pos ereal_uminus_uminus ereal_uminus_zero less_le not_less)+
   593     by (metis abs_ereal_ge0 abs_ereal_less0 abs_ereal_pos ereal_uminus_uminus ereal_uminus_zero less_le not_less)+
   639   then have "sgn(l) * l > 0" "sgn(m) * m > 0" using ereal_sgn_abs by auto
   594   then have "sgn(l) * l > 0" "sgn(m) * m > 0" using ereal_sgn_abs by auto
   640   moreover have "((\<lambda>x. sgn(l) * f x) \<longlongrightarrow> (sgn(l) * l)) F"
   595   moreover have "((\<lambda>x. sgn(l) * f x) \<longlongrightarrow> (sgn(l) * l)) F"
   641     by (rule tendsto_cmult_ereal, auto simp add: sgn_finite assms(1))
   596     by (rule tendsto_cmult_ereal, auto simp: sgn_finite assms(1))
   642   moreover have "((\<lambda>x. sgn(m) * g x) \<longlongrightarrow> (sgn(m) * m)) F"
   597   moreover have "((\<lambda>x. sgn(m) * g x) \<longlongrightarrow> (sgn(m) * m)) F"
   643     by (rule tendsto_cmult_ereal, auto simp add: sgn_finite assms(2))
   598     by (rule tendsto_cmult_ereal, auto simp: sgn_finite assms(2))
   644   ultimately have *: "((\<lambda>x. (sgn(l) * f x) * (sgn(m) * g x)) \<longlongrightarrow> (sgn(l) * l) * (sgn(m) * m)) F"
   599   ultimately have *: "((\<lambda>x. (sgn(l) * f x) * (sgn(m) * g x)) \<longlongrightarrow> (sgn(l) * l) * (sgn(m) * m)) F"
   645     using tendsto_mult_ereal_pos by force
   600     using tendsto_mult_ereal_pos by force
   646   have "((\<lambda>x. (sgn(l) * sgn(m)) * ((sgn(l) * f x) * (sgn(m) * g x))) \<longlongrightarrow> (sgn(l) * sgn(m)) * ((sgn(l) * l) * (sgn(m) * m))) F"
   601   have "((\<lambda>x. (sgn(l) * sgn(m)) * ((sgn(l) * f x) * (sgn(m) * g x))) \<longlongrightarrow> (sgn(l) * sgn(m)) * ((sgn(l) * l) * (sgn(m) * m))) F"
   647     by (rule tendsto_cmult_ereal, auto simp add: sgn_finite2 *)
   602     by (rule tendsto_cmult_ereal, auto simp: sgn_finite2 *)
   648   moreover have "\<And>x. (sgn(l) * sgn(m)) * ((sgn(l) * f x) * (sgn(m) * g x)) = f x * g x"
   603   moreover have "\<And>x. (sgn(l) * sgn(m)) * ((sgn(l) * f x) * (sgn(m) * g x)) = f x * g x"
   649     by (metis mult.left_neutral sgn_squared_ereal[OF \<open>l \<noteq> 0\<close>] sgn_squared_ereal[OF \<open>m \<noteq> 0\<close>] mult.assoc mult.commute)
   604     by (metis mult.left_neutral sgn_squared_ereal[OF \<open>l \<noteq> 0\<close>] sgn_squared_ereal[OF \<open>m \<noteq> 0\<close>] mult.assoc mult.commute)
   650   moreover have "(sgn(l) * sgn(m)) * ((sgn(l) * l) * (sgn(m) * m)) = l * m"
   605   moreover have "(sgn(l) * sgn(m)) * ((sgn(l) * l) * (sgn(m) * m)) = l * m"
   651     by (metis mult.left_neutral sgn_squared_ereal[OF \<open>l \<noteq> 0\<close>] sgn_squared_ereal[OF \<open>m \<noteq> 0\<close>] mult.assoc mult.commute)
   606     by (metis mult.left_neutral sgn_squared_ereal[OF \<open>l \<noteq> 0\<close>] sgn_squared_ereal[OF \<open>m \<noteq> 0\<close>] mult.assoc mult.commute)
   652   ultimately show ?thesis by auto
   607   ultimately show ?thesis by auto
   654 
   609 
   655 lemma tendsto_cmult_ereal_general [tendsto_intros]:
   610 lemma tendsto_cmult_ereal_general [tendsto_intros]:
   656   fixes f::"_ \<Rightarrow> ereal" and c::ereal
   611   fixes f::"_ \<Rightarrow> ereal" and c::ereal
   657   assumes "(f \<longlongrightarrow> l) F" "\<not> (l=0 \<and> abs(c) = \<infinity>)"
   612   assumes "(f \<longlongrightarrow> l) F" "\<not> (l=0 \<and> abs(c) = \<infinity>)"
   658   shows "((\<lambda>x. c * f x) \<longlongrightarrow> c * l) F"
   613   shows "((\<lambda>x. c * f x) \<longlongrightarrow> c * l) F"
   659 by (cases "c = 0", auto simp add: assms tendsto_mult_ereal)
   614 by (cases "c = 0", auto simp: assms tendsto_mult_ereal)
   660 
   615 
   661 
   616 
   662 subsubsection\<^marker>\<open>tag important\<close> \<open>Continuity of division\<close>
   617 subsubsection\<^marker>\<open>tag important\<close> \<open>Continuity of division\<close>
   663 
   618 
   664 lemma tendsto_inverse_ereal_PInf:
   619 lemma tendsto_inverse_ereal_PInf:
   673     moreover
   628     moreover
   674     {
   629     {
   675       fix z::ereal assume "z>1/e"
   630       fix z::ereal assume "z>1/e"
   676       then have "z>0" using \<open>e>0\<close> using less_le_trans not_le by fastforce
   631       then have "z>0" using \<open>e>0\<close> using less_le_trans not_le by fastforce
   677       then have "1/z \<ge> 0" by auto
   632       then have "1/z \<ge> 0" by auto
   678       moreover have "1/z < e" using \<open>e>0\<close> \<open>z>1/e\<close>
   633       moreover have "1/z < e" 
   679         apply (cases z) apply auto
   634       proof (cases z)
   680         by (metis (mono_tags, opaque_lifting) less_ereal.simps(2) less_ereal.simps(4) divide_less_eq ereal_divide_less_pos ereal_less(4)
   635         case (real r)
   681             ereal_less_eq(4) less_le_trans mult_eq_0_iff not_le not_one_less_zero times_ereal.simps(1))
   636         then show ?thesis
       
   637           using \<open>0 < e\<close> \<open>0 < z\<close> \<open>ereal (1 / e) < z\<close> divide_less_eq ereal_divide_less_pos by fastforce 
       
   638       qed (use \<open>0 < e\<close> \<open>0 < z\<close> in auto)
   682       ultimately have "1/z \<ge> 0" "1/z < e" by auto
   639       ultimately have "1/z \<ge> 0" "1/z < e" by auto
   683     }
   640     }
   684     ultimately have "eventually (\<lambda>n. 1/u n<e) F" "eventually (\<lambda>n. 1/u n\<ge>0) F" by (auto simp add: eventually_mono)
   641     ultimately have "eventually (\<lambda>n. 1/u n<e) F" "eventually (\<lambda>n. 1/u n\<ge>0) F" by (auto simp: eventually_mono)
   685   } note * = this
   642   } note * = this
   686   show ?thesis
   643   show ?thesis
   687   proof (subst order_tendsto_iff, auto)
   644   proof (subst order_tendsto_iff, auto)
   688     fix a::ereal assume "a<0"
   645     fix a::ereal assume "a<0"
   689     then show "eventually (\<lambda>n. 1/u n > a) F" using *(2) eventually_mono less_le_trans linordered_field_no_ub by fastforce
   646     then show "eventually (\<lambda>n. 1/u n > a) F" using *(2) eventually_mono less_le_trans linordered_field_no_ub by fastforce
   753   shows "((\<lambda>x. f x / g x) \<longlongrightarrow> l / m) F"
   710   shows "((\<lambda>x. f x / g x) \<longlongrightarrow> l / m) F"
   754 proof -
   711 proof -
   755   define h where "h = (\<lambda>x. 1/ g x)"
   712   define h where "h = (\<lambda>x. 1/ g x)"
   756   have *: "(h \<longlongrightarrow> 1/m) F" unfolding h_def using assms(2) assms(3) tendsto_inverse_ereal by auto
   713   have *: "(h \<longlongrightarrow> 1/m) F" unfolding h_def using assms(2) assms(3) tendsto_inverse_ereal by auto
   757   have "((\<lambda>x. f x * h x) \<longlongrightarrow> l * (1/m)) F"
   714   have "((\<lambda>x. f x * h x) \<longlongrightarrow> l * (1/m)) F"
   758     apply (rule tendsto_mult_ereal[OF assms(1) *]) using assms(3) assms(4) by (auto simp add: divide_ereal_def)
   715     apply (rule tendsto_mult_ereal[OF assms(1) *]) using assms(3) assms(4) by (auto simp: divide_ereal_def)
   759   moreover have "f x * h x = f x / g x" for x unfolding h_def by (simp add: divide_ereal_def)
   716   moreover have "f x * h x = f x / g x" for x unfolding h_def by (simp add: divide_ereal_def)
   760   moreover have "l * (1/m) = l/m" by (simp add: divide_ereal_def)
   717   moreover have "l * (1/m) = l/m" by (simp add: divide_ereal_def)
   761   ultimately show ?thesis unfolding h_def using Lim_transform_eventually by auto
   718   ultimately show ?thesis unfolding h_def using Lim_transform_eventually by auto
   762 qed
   719 qed
   763 
   720 
   769 lemma tendsto_diff_ereal_general [tendsto_intros]:
   726 lemma tendsto_diff_ereal_general [tendsto_intros]:
   770   fixes u v::"'a \<Rightarrow> ereal"
   727   fixes u v::"'a \<Rightarrow> ereal"
   771   assumes "(u \<longlongrightarrow> l) F" "(v \<longlongrightarrow> m) F" "\<not>((l = \<infinity> \<and> m = \<infinity>) \<or> (l = -\<infinity> \<and> m = -\<infinity>))"
   728   assumes "(u \<longlongrightarrow> l) F" "(v \<longlongrightarrow> m) F" "\<not>((l = \<infinity> \<and> m = \<infinity>) \<or> (l = -\<infinity> \<and> m = -\<infinity>))"
   772   shows "((\<lambda>n. u n - v n) \<longlongrightarrow> l - m) F"
   729   shows "((\<lambda>n. u n - v n) \<longlongrightarrow> l - m) F"
   773 proof -
   730 proof -
   774   have "((\<lambda>n. u n + (-v n)) \<longlongrightarrow> l + (-m)) F"
   731   have "\<infinity> = l \<longrightarrow> ((\<lambda>a. u a + - v a) \<longlongrightarrow> l + - m) F"
   775     apply (intro tendsto_intros assms) using assms by (auto simp add: ereal_uminus_eq_reorder)
   732       by (metis (no_types) assms ereal_uminus_uminus tendsto_add_ereal_general tendsto_uminus_ereal)
   776   then show ?thesis by (simp add: minus_ereal_def)
   733   then have "((\<lambda>n. u n + (-v n)) \<longlongrightarrow> l + (-m)) F"
       
   734     by (simp add: assms ereal_uminus_eq_reorder tendsto_add_ereal_general)
       
   735   then show ?thesis 
       
   736     by (simp add: minus_ereal_def)
   777 qed
   737 qed
   778 
   738 
   779 lemma id_nat_ereal_tendsto_PInf [tendsto_intros]:
   739 lemma id_nat_ereal_tendsto_PInf [tendsto_intros]:
   780   "(\<lambda> n::nat. real n) \<longlonglongrightarrow> \<infinity>"
   740   "(\<lambda> n::nat. real n) \<longlonglongrightarrow> \<infinity>"
   781 by (simp add: filterlim_real_sequentially tendsto_PInfty_eq_at_top)
   741 by (simp add: filterlim_real_sequentially tendsto_PInfty_eq_at_top)
   850   then have "min x n = x" if "n \<ge> K" for n apply (subst real, subst real, auto) using that eq_iff by fastforce
   810   then have "min x n = x" if "n \<ge> K" for n apply (subst real, subst real, auto) using that eq_iff by fastforce
   851   then have "eventually (\<lambda>n. min x n = x) sequentially" using eventually_at_top_linorder by blast
   811   then have "eventually (\<lambda>n. min x n = x) sequentially" using eventually_at_top_linorder by blast
   852   then show ?thesis by (simp add: tendsto_eventually)
   812   then show ?thesis by (simp add: tendsto_eventually)
   853 next
   813 next
   854   case (PInf)
   814   case (PInf)
   855   then have "min x n = n" for n::nat by (auto simp add: min_def)
   815   then have "min x n = n" for n::nat by (auto simp: min_def)
   856   then show ?thesis using id_nat_ereal_tendsto_PInf PInf by auto
   816   then show ?thesis using id_nat_ereal_tendsto_PInf PInf by auto
   857 next
   817 next
   858   case (MInf)
   818   case (MInf)
   859   then have "min x n = x" for n::nat by (auto simp add: min_def)
   819   then have "min x n = x" for n::nat by (auto simp: min_def)
   860   then show ?thesis by auto
   820   then show ?thesis by auto
   861 qed
   821 qed
   862 
   822 
   863 lemma ereal_truncation_real_top [tendsto_intros]:
   823 lemma ereal_truncation_real_top [tendsto_intros]:
   864   fixes x::ereal
   824   fixes x::ereal
   872   then have "eventually (\<lambda>n. real_of_ereal(min x n) = r) sequentially" using eventually_at_top_linorder by blast
   832   then have "eventually (\<lambda>n. real_of_ereal(min x n) = r) sequentially" using eventually_at_top_linorder by blast
   873   then have "(\<lambda>n. real_of_ereal(min x n)) \<longlonglongrightarrow> r" by (simp add: tendsto_eventually)
   833   then have "(\<lambda>n. real_of_ereal(min x n)) \<longlonglongrightarrow> r" by (simp add: tendsto_eventually)
   874   then show ?thesis using real by auto
   834   then show ?thesis using real by auto
   875 next
   835 next
   876   case (PInf)
   836   case (PInf)
   877   then have "real_of_ereal(min x n) = n" for n::nat by (auto simp add: min_def)
   837   then have "real_of_ereal(min x n) = n" for n::nat by (auto simp: min_def)
   878   then show ?thesis using id_nat_ereal_tendsto_PInf PInf by auto
   838   then show ?thesis using id_nat_ereal_tendsto_PInf PInf by auto
   879 qed (simp add: assms)
   839 qed (simp add: assms)
   880 
   840 
   881 lemma ereal_truncation_bottom [tendsto_intros]:
   841 lemma ereal_truncation_bottom [tendsto_intros]:
   882   fixes x::ereal
   842   fixes x::ereal
   887   then have "max x (-real n) = x" if "n \<ge> K" for n apply (subst real, subst real, auto) using that eq_iff by fastforce
   847   then have "max x (-real n) = x" if "n \<ge> K" for n apply (subst real, subst real, auto) using that eq_iff by fastforce
   888   then have "eventually (\<lambda>n. max x (-real n) = x) sequentially" using eventually_at_top_linorder by blast
   848   then have "eventually (\<lambda>n. max x (-real n) = x) sequentially" using eventually_at_top_linorder by blast
   889   then show ?thesis by (simp add: tendsto_eventually)
   849   then show ?thesis by (simp add: tendsto_eventually)
   890 next
   850 next
   891   case (MInf)
   851   case (MInf)
   892   then have "max x (-real n) = (-1)* ereal(real n)" for n::nat by (auto simp add: max_def)
   852   then have "max x (-real n) = (-1)* ereal(real n)" for n::nat by (auto simp: max_def)
   893   moreover have "(\<lambda>n. (-1)* ereal(real n)) \<longlonglongrightarrow> -\<infinity>"
   853   moreover have "(\<lambda>n. (-1)* ereal(real n)) \<longlonglongrightarrow> -\<infinity>"
   894     using tendsto_cmult_ereal[of "-1", OF _ id_nat_ereal_tendsto_PInf] by (simp add: one_ereal_def)
   854     using tendsto_cmult_ereal[of "-1", OF _ id_nat_ereal_tendsto_PInf] by (simp add: one_ereal_def)
   895   ultimately show ?thesis using MInf by auto
   855   ultimately show ?thesis using MInf by auto
   896 next
   856 next
   897   case (PInf)
   857   case (PInf)
   898   then have "max x (-real n) = x" for n::nat by (auto simp add: max_def)
   858   then have "max x (-real n) = x" for n::nat by (auto simp: max_def)
   899   then show ?thesis by auto
   859   then show ?thesis by auto
   900 qed
   860 qed
   901 
   861 
   902 lemma ereal_truncation_real_bottom [tendsto_intros]:
   862 lemma ereal_truncation_real_bottom [tendsto_intros]:
   903   fixes x::ereal
   863   fixes x::ereal
   911   then have "eventually (\<lambda>n. real_of_ereal(max x (-real n)) = r) sequentially" using eventually_at_top_linorder by blast
   871   then have "eventually (\<lambda>n. real_of_ereal(max x (-real n)) = r) sequentially" using eventually_at_top_linorder by blast
   912   then have "(\<lambda>n. real_of_ereal(max x (-real n))) \<longlonglongrightarrow> r" by (simp add: tendsto_eventually)
   872   then have "(\<lambda>n. real_of_ereal(max x (-real n))) \<longlonglongrightarrow> r" by (simp add: tendsto_eventually)
   913   then show ?thesis using real by auto
   873   then show ?thesis using real by auto
   914 next
   874 next
   915   case (MInf)
   875   case (MInf)
   916   then have "real_of_ereal(max x (-real n)) = (-1)* ereal(real n)" for n::nat by (auto simp add: max_def)
   876   then have "real_of_ereal(max x (-real n)) = (-1)* ereal(real n)" for n::nat by (auto simp: max_def)
   917   moreover have "(\<lambda>n. (-1)* ereal(real n)) \<longlonglongrightarrow> -\<infinity>"
   877   moreover have "(\<lambda>n. (-1)* ereal(real n)) \<longlonglongrightarrow> -\<infinity>"
   918     using tendsto_cmult_ereal[of "-1", OF _ id_nat_ereal_tendsto_PInf] by (simp add: one_ereal_def)
   878     using tendsto_cmult_ereal[of "-1", OF _ id_nat_ereal_tendsto_PInf] by (simp add: one_ereal_def)
   919   ultimately show ?thesis using MInf by auto
   879   ultimately show ?thesis using MInf by auto
   920 qed (simp add: assms)
   880 qed (simp add: assms)
   921 
   881 
   935   "continuous_on (UNIV::ereal set) abs"
   895   "continuous_on (UNIV::ereal set) abs"
   936 proof -
   896 proof -
   937   have "continuous_on ({..0} \<union> {(0::ereal)..}) abs"
   897   have "continuous_on ({..0} \<union> {(0::ereal)..}) abs"
   938     apply (rule continuous_on_closed_Un, auto)
   898     apply (rule continuous_on_closed_Un, auto)
   939     apply (rule iffD1[OF continuous_on_cong, of "{..0}" _ "\<lambda>x. -x"])
   899     apply (rule iffD1[OF continuous_on_cong, of "{..0}" _ "\<lambda>x. -x"])
   940     using less_eq_ereal_def apply (auto simp add: continuous_uminus_ereal)
   900     using less_eq_ereal_def apply (auto simp: continuous_uminus_ereal)
   941     apply (rule iffD1[OF continuous_on_cong, of "{0..}" _ "\<lambda>x. x"])
   901     apply (rule iffD1[OF continuous_on_cong, of "{0..}" _ "\<lambda>x. x"])
   942       apply (auto)
   902       apply (auto)
   943     done
   903     done
   944   moreover have "(UNIV::ereal set) = {..0} \<union> {(0::ereal)..}" by auto
   904   moreover have "(UNIV::ereal set) = {..0} \<union> {(0::ereal)..}" by auto
   945   ultimately show ?thesis by auto
   905   ultimately show ?thesis by auto
   977 proof -
   937 proof -
   978   have "((\<lambda>n. e2ennreal(enn2ereal (u n) * enn2ereal (v n))) \<longlongrightarrow> e2ennreal(enn2ereal l * enn2ereal m)) F"
   938   have "((\<lambda>n. e2ennreal(enn2ereal (u n) * enn2ereal (v n))) \<longlongrightarrow> e2ennreal(enn2ereal l * enn2ereal m)) F"
   979     apply (intro tendsto_intros) using assms apply auto
   939     apply (intro tendsto_intros) using assms apply auto
   980     using enn2ereal_inject zero_ennreal.rep_eq by fastforce+
   940     using enn2ereal_inject zero_ennreal.rep_eq by fastforce+
   981   moreover have "e2ennreal(enn2ereal (u n) * enn2ereal (v n)) = u n * v n" for n
   941   moreover have "e2ennreal(enn2ereal (u n) * enn2ereal (v n)) = u n * v n" for n
   982     by (subst times_ennreal.abs_eq[symmetric], auto simp add: eq_onp_same_args)
   942     by (subst times_ennreal.abs_eq[symmetric], auto simp: eq_onp_same_args)
   983   moreover have "e2ennreal(enn2ereal l * enn2ereal m)  = l * m"
   943   moreover have "e2ennreal(enn2ereal l * enn2ereal m)  = l * m"
   984     by (subst times_ennreal.abs_eq[symmetric], auto simp add: eq_onp_same_args)
   944     by (subst times_ennreal.abs_eq[symmetric], auto simp: eq_onp_same_args)
   985   ultimately show ?thesis
   945   ultimately show ?thesis
   986     by auto
   946     by auto
   987 qed
   947 qed
   988 
   948 
   989 
   949 
  1165   shows "\<exists>C. \<forall>n. u n \<le> C"
  1125   shows "\<exists>C. \<forall>n. u n \<le> C"
  1166 proof -
  1126 proof -
  1167   obtain C where C: "limsup u < C" "C < \<infinity>" using assms ereal_dense2 by blast
  1127   obtain C where C: "limsup u < C" "C < \<infinity>" using assms ereal_dense2 by blast
  1168   then have "C = ereal(real_of_ereal C)" using ereal_real by force
  1128   then have "C = ereal(real_of_ereal C)" using ereal_real by force
  1169   have "eventually (\<lambda>n. u n < C) sequentially" using C(1) unfolding Limsup_def
  1129   have "eventually (\<lambda>n. u n < C) sequentially" using C(1) unfolding Limsup_def
  1170     apply (auto simp add: INF_less_iff)
  1130     apply (auto simp: INF_less_iff)
  1171     using SUP_lessD eventually_mono by fastforce
  1131     using SUP_lessD eventually_mono by fastforce
  1172   then obtain N where N: "\<And>n. n \<ge> N \<Longrightarrow> u n < C" using eventually_sequentially by auto
  1132   then obtain N where N: "\<And>n. n \<ge> N \<Longrightarrow> u n < C" using eventually_sequentially by auto
  1173   define D where "D = max (real_of_ereal C) (Max {u n |n. n \<le> N})"
  1133   define D where "D = max (real_of_ereal C) (Max {u n |n. n \<le> N})"
  1174   have "\<And>n. u n \<le> D"
  1134   have "\<And>n. u n \<le> D"
  1175   proof -
  1135   proof -
  1176     fix n show "u n \<le> D"
  1136     fix n show "u n \<le> D"
  1177     proof (cases)
  1137     proof (cases)
  1178       assume *: "n \<le> N"
  1138       assume *: "n \<le> N"
  1179       have "u n \<le> Max {u n |n. n \<le> N}" by (rule Max_ge, auto simp add: *)
  1139       have "u n \<le> Max {u n |n. n \<le> N}" by (rule Max_ge, auto simp: *)
  1180       then show "u n \<le> D" unfolding D_def by linarith
  1140       then show "u n \<le> D" unfolding D_def by linarith
  1181     next
  1141     next
  1182       assume "\<not>(n \<le> N)"
  1142       assume "\<not>(n \<le> N)"
  1183       then have "n \<ge> N" by simp
  1143       then have "n \<ge> N" by simp
  1184       then have "u n < C" using N by auto
  1144       then have "u n < C" using N by auto
  1195   shows "\<exists>C. \<forall>n. u n \<ge> C"
  1155   shows "\<exists>C. \<forall>n. u n \<ge> C"
  1196 proof -
  1156 proof -
  1197   obtain C where C: "liminf u > C" "C > -\<infinity>" using assms using ereal_dense2 by blast
  1157   obtain C where C: "liminf u > C" "C > -\<infinity>" using assms using ereal_dense2 by blast
  1198   then have "C = ereal(real_of_ereal C)" using ereal_real by force
  1158   then have "C = ereal(real_of_ereal C)" using ereal_real by force
  1199   have "eventually (\<lambda>n. u n > C) sequentially" using C(1) unfolding Liminf_def
  1159   have "eventually (\<lambda>n. u n > C) sequentially" using C(1) unfolding Liminf_def
  1200     apply (auto simp add: less_SUP_iff)
  1160     apply (auto simp: less_SUP_iff)
  1201     using eventually_elim2 less_INF_D by fastforce
  1161     using eventually_elim2 less_INF_D by fastforce
  1202   then obtain N where N: "\<And>n. n \<ge> N \<Longrightarrow> u n > C" using eventually_sequentially by auto
  1162   then obtain N where N: "\<And>n. n \<ge> N \<Longrightarrow> u n > C" using eventually_sequentially by auto
  1203   define D where "D = min (real_of_ereal C) (Min {u n |n. n \<le> N})"
  1163   define D where "D = min (real_of_ereal C) (Min {u n |n. n \<le> N})"
  1204   have "\<And>n. u n \<ge> D"
  1164   have "\<And>n. u n \<ge> D"
  1205   proof -
  1165   proof -
  1206     fix n show "u n \<ge> D"
  1166     fix n show "u n \<ge> D"
  1207     proof (cases)
  1167     proof (cases)
  1208       assume *: "n \<le> N"
  1168       assume *: "n \<le> N"
  1209       have "u n \<ge> Min {u n |n. n \<le> N}" by (rule Min_le, auto simp add: *)
  1169       have "u n \<ge> Min {u n |n. n \<le> N}" by (rule Min_le, auto simp: *)
  1210       then show "u n \<ge> D" unfolding D_def by linarith
  1170       then show "u n \<ge> D" unfolding D_def by linarith
  1211     next
  1171     next
  1212       assume "\<not>(n \<le> N)"
  1172       assume "\<not>(n \<le> N)"
  1213       then have "n \<ge> N" by simp
  1173       then have "n \<ge> N" by simp
  1214       then have "u n > C" using N by auto
  1174       then have "u n > C" using N by auto
  1613   obtain s where s: "strict_mono s" "(w o s) \<longlonglongrightarrow> limsup w" using limsup_subseq_lim by auto
  1573   obtain s where s: "strict_mono s" "(w o s) \<longlonglongrightarrow> limsup w" using limsup_subseq_lim by auto
  1614   have *: "(u o s) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ s by auto
  1574   have *: "(u o s) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ s by auto
  1615   have "eventually (\<lambda>n. (u o s) n > 0) sequentially" using assms(2) * order_tendsto_iff by blast
  1575   have "eventually (\<lambda>n. (u o s) n > 0) sequentially" using assms(2) * order_tendsto_iff by blast
  1616   moreover have "eventually (\<lambda>n. (u o s) n < \<infinity>) sequentially" using assms(3) * order_tendsto_iff by blast
  1576   moreover have "eventually (\<lambda>n. (u o s) n < \<infinity>) sequentially" using assms(3) * order_tendsto_iff by blast
  1617   moreover have "(w o s) n / (u o s) n = (v o s) n" if "(u o s) n > 0" "(u o s) n < \<infinity>" for n
  1577   moreover have "(w o s) n / (u o s) n = (v o s) n" if "(u o s) n > 0" "(u o s) n < \<infinity>" for n
  1618     unfolding w_def using that by (auto simp add: ereal_divide_eq)
  1578     unfolding w_def using that by (auto simp: ereal_divide_eq)
  1619   ultimately have "eventually (\<lambda>n. (w o s) n / (u o s) n = (v o s) n) sequentially" using eventually_elim2 by force
  1579   ultimately have "eventually (\<lambda>n. (w o s) n / (u o s) n = (v o s) n) sequentially" using eventually_elim2 by force
  1620   moreover have "(\<lambda>n. (w o s) n / (u o s) n) \<longlonglongrightarrow> (limsup w) / a"
  1580   moreover have "(\<lambda>n. (w o s) n / (u o s) n) \<longlonglongrightarrow> (limsup w) / a"
  1621     apply (rule tendsto_divide_ereal[OF s(2) *]) using assms(2) assms(3) by auto
  1581     apply (rule tendsto_divide_ereal[OF s(2) *]) using assms(2) assms(3) by auto
  1622   ultimately have "(v o s) \<longlonglongrightarrow> (limsup w) / a" using Lim_transform_eventually by fastforce
  1582   ultimately have "(v o s) \<longlonglongrightarrow> (limsup w) / a" using Lim_transform_eventually by fastforce
  1623   then have "limsup (v o s) = (limsup w) / a" by (simp add: tendsto_iff_Liminf_eq_Limsup)
  1583   then have "limsup (v o s) = (limsup w) / a" by (simp add: tendsto_iff_Liminf_eq_Limsup)
  1643   obtain s where s: "strict_mono s" "(w o s) \<longlonglongrightarrow> liminf w" using liminf_subseq_lim by auto
  1603   obtain s where s: "strict_mono s" "(w o s) \<longlonglongrightarrow> liminf w" using liminf_subseq_lim by auto
  1644   have *: "(u o s) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ s by auto
  1604   have *: "(u o s) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ s by auto
  1645   have "eventually (\<lambda>n. (u o s) n > 0) sequentially" using assms(2) * order_tendsto_iff by blast
  1605   have "eventually (\<lambda>n. (u o s) n > 0) sequentially" using assms(2) * order_tendsto_iff by blast
  1646   moreover have "eventually (\<lambda>n. (u o s) n < \<infinity>) sequentially" using assms(3) * order_tendsto_iff by blast
  1606   moreover have "eventually (\<lambda>n. (u o s) n < \<infinity>) sequentially" using assms(3) * order_tendsto_iff by blast
  1647   moreover have "(w o s) n / (u o s) n = (v o s) n" if "(u o s) n > 0" "(u o s) n < \<infinity>" for n
  1607   moreover have "(w o s) n / (u o s) n = (v o s) n" if "(u o s) n > 0" "(u o s) n < \<infinity>" for n
  1648     unfolding w_def using that by (auto simp add: ereal_divide_eq)
  1608     unfolding w_def using that by (auto simp: ereal_divide_eq)
  1649   ultimately have "eventually (\<lambda>n. (w o s) n / (u o s) n = (v o s) n) sequentially" using eventually_elim2 by force
  1609   ultimately have "eventually (\<lambda>n. (w o s) n / (u o s) n = (v o s) n) sequentially" using eventually_elim2 by force
  1650   moreover have "(\<lambda>n. (w o s) n / (u o s) n) \<longlonglongrightarrow> (liminf w) / a"
  1610   moreover have "(\<lambda>n. (w o s) n / (u o s) n) \<longlonglongrightarrow> (liminf w) / a"
  1651     apply (rule tendsto_divide_ereal[OF s(2) *]) using assms(2) assms(3) by auto
  1611     apply (rule tendsto_divide_ereal[OF s(2) *]) using assms(2) assms(3) by auto
  1652   ultimately have "(v o s) \<longlonglongrightarrow> (liminf w) / a" using Lim_transform_eventually by fastforce
  1612   ultimately have "(v o s) \<longlonglongrightarrow> (liminf w) / a" using Lim_transform_eventually by fastforce
  1653   then have "liminf (v o s) = (liminf w) / a" by (simp add: tendsto_iff_Liminf_eq_Limsup)
  1613   then have "liminf (v o s) = (liminf w) / a" by (simp add: tendsto_iff_Liminf_eq_Limsup)