src/HOL/Analysis/Set_Integral.thy
changeset 66447 a1f5c5c26fa6
parent 66164 2d79288b042c
child 66456 621897f47fab
equal deleted inserted replaced
66445:407de0768126 66447:a1f5c5c26fa6
   191 text \<open>The next lemma is extremely useful, as it often makes it possible to reduce statements
   191 text \<open>The next lemma is extremely useful, as it often makes it possible to reduce statements
   192 about limsups to statements about limits.\<close>
   192 about limsups to statements about limits.\<close>
   193 
   193 
   194 lemma limsup_subseq_lim:
   194 lemma limsup_subseq_lim:
   195   fixes u::"nat \<Rightarrow> 'a :: {complete_linorder, linorder_topology}"
   195   fixes u::"nat \<Rightarrow> 'a :: {complete_linorder, linorder_topology}"
   196   shows "\<exists>r. subseq r \<and> (u o r) \<longlonglongrightarrow> limsup u"
   196   shows "\<exists>r::nat\<Rightarrow>nat. strict_mono r \<and> (u o r) \<longlonglongrightarrow> limsup u"
   197 proof (cases)
   197 proof (cases)
   198   assume "\<forall>n. \<exists>p>n. \<forall>m\<ge>p. u m \<le> u p"
   198   assume "\<forall>n. \<exists>p>n. \<forall>m\<ge>p. u m \<le> u p"
   199   then have "\<exists>r. \<forall>n. (\<forall>m\<ge>r n. u m \<le> u (r n)) \<and> r n < r (Suc n)"
   199   then have "\<exists>r. \<forall>n. (\<forall>m\<ge>r n. u m \<le> u (r n)) \<and> r n < r (Suc n)"
   200     by (intro dependent_nat_choice) (auto simp: conj_commute)
   200     by (intro dependent_nat_choice) (auto simp: conj_commute)
   201   then obtain r where "subseq r" and mono: "\<And>n m. r n \<le> m \<Longrightarrow> u m \<le> u (r n)"
   201   then obtain r :: "nat \<Rightarrow> nat" where "strict_mono r" and mono: "\<And>n m. r n \<le> m \<Longrightarrow> u m \<le> u (r n)"
   202     by (auto simp: subseq_Suc_iff)
   202     by (auto simp: strict_mono_Suc_iff)
   203   define umax where "umax = (\<lambda>n. (SUP m:{n..}. u m))"
   203   define umax where "umax = (\<lambda>n. (SUP m:{n..}. u m))"
   204   have "decseq umax" unfolding umax_def by (simp add: SUP_subset_mono antimono_def)
   204   have "decseq umax" unfolding umax_def by (simp add: SUP_subset_mono antimono_def)
   205   then have "umax \<longlonglongrightarrow> limsup u" unfolding umax_def by (metis LIMSEQ_INF limsup_INF_SUP)
   205   then have "umax \<longlonglongrightarrow> limsup u" unfolding umax_def by (metis LIMSEQ_INF limsup_INF_SUP)
   206   then have *: "(umax o r) \<longlonglongrightarrow> limsup u" by (simp add: LIMSEQ_subseq_LIMSEQ \<open>subseq r\<close>)
   206   then have *: "(umax o r) \<longlonglongrightarrow> limsup u" by (simp add: LIMSEQ_subseq_LIMSEQ \<open>strict_mono r\<close>)
   207   have "\<And>n. umax(r n) = u(r n)" unfolding umax_def using mono
   207   have "\<And>n. umax(r n) = u(r n)" unfolding umax_def using mono
   208     by (metis SUP_le_iff antisym atLeast_def mem_Collect_eq order_refl)
   208     by (metis SUP_le_iff antisym atLeast_def mem_Collect_eq order_refl)
   209   then have "umax o r = u o r" unfolding o_def by simp
   209   then have "umax o r = u o r" unfolding o_def by simp
   210   then have "(u o r) \<longlonglongrightarrow> limsup u" using * by simp
   210   then have "(u o r) \<longlonglongrightarrow> limsup u" using * by simp
   211   then show ?thesis using \<open>subseq r\<close> by blast
   211   then show ?thesis using \<open>strict_mono r\<close> by blast
   212 next
   212 next
   213   assume "\<not> (\<forall>n. \<exists>p>n. (\<forall>m\<ge>p. u m \<le> u p))"
   213   assume "\<not> (\<forall>n. \<exists>p>n. (\<forall>m\<ge>p. u m \<le> u p))"
   214   then obtain N where N: "\<And>p. p > N \<Longrightarrow> \<exists>m>p. u p < u m" by (force simp: not_le le_less)
   214   then obtain N where N: "\<And>p. p > N \<Longrightarrow> \<exists>m>p. u p < u m" by (force simp: not_le le_less)
   215   have "\<exists>r. \<forall>n. N < r n \<and> r n < r (Suc n) \<and> (\<forall>i\<in> {N<..r (Suc n)}. u i \<le> u (r (Suc n)))"
   215   have "\<exists>r. \<forall>n. N < r n \<and> r n < r (Suc n) \<and> (\<forall>i\<in> {N<..r (Suc n)}. u i \<le> u (r (Suc n)))"
   216   proof (rule dependent_nat_choice)
   216   proof (rule dependent_nat_choice)
   260     qed
   260     qed
   261     then have "N < y \<and> x < y \<and> (\<forall>i\<in>{N<..y}. u i \<le> u y)" using \<open>y > x\<close> \<open>y > N\<close> by auto
   261     then have "N < y \<and> x < y \<and> (\<forall>i\<in>{N<..y}. u i \<le> u y)" using \<open>y > x\<close> \<open>y > N\<close> by auto
   262     then show "\<exists>y>N. x < y \<and> (\<forall>i\<in>{N<..y}. u i \<le> u y)" by auto
   262     then show "\<exists>y>N. x < y \<and> (\<forall>i\<in>{N<..y}. u i \<le> u y)" by auto
   263   qed (auto)
   263   qed (auto)
   264   then obtain r where r: "\<forall>n. N < r n \<and> r n < r (Suc n) \<and> (\<forall>i\<in> {N<..r (Suc n)}. u i \<le> u (r (Suc n)))" by auto
   264   then obtain r where r: "\<forall>n. N < r n \<and> r n < r (Suc n) \<and> (\<forall>i\<in> {N<..r (Suc n)}. u i \<le> u (r (Suc n)))" by auto
   265   have "subseq r" using r by (auto simp: subseq_Suc_iff)
   265   have "strict_mono r" using r by (auto simp: strict_mono_Suc_iff)
   266   have "incseq (u o r)" unfolding o_def using r by (simp add: incseq_SucI order.strict_implies_order)
   266   have "incseq (u o r)" unfolding o_def using r by (simp add: incseq_SucI order.strict_implies_order)
   267   then have "(u o r) \<longlonglongrightarrow> (SUP n. (u o r) n)" using LIMSEQ_SUP by blast
   267   then have "(u o r) \<longlonglongrightarrow> (SUP n. (u o r) n)" using LIMSEQ_SUP by blast
   268   then have "limsup (u o r) = (SUP n. (u o r) n)" by (simp add: lim_imp_Limsup)
   268   then have "limsup (u o r) = (SUP n. (u o r) n)" by (simp add: lim_imp_Limsup)
   269   moreover have "limsup (u o r) \<le> limsup u" using \<open>subseq r\<close> by (simp add: limsup_subseq_mono)
   269   moreover have "limsup (u o r) \<le> limsup u" using \<open>strict_mono r\<close> by (simp add: limsup_subseq_mono)
   270   ultimately have "(SUP n. (u o r) n) \<le> limsup u" by simp
   270   ultimately have "(SUP n. (u o r) n) \<le> limsup u" by simp
   271 
   271 
   272   {
   272   {
   273     fix i assume i: "i \<in> {N<..}"
   273     fix i assume i: "i \<in> {N<..}"
   274     obtain n where "i < r (Suc n)" using \<open>subseq r\<close> using Suc_le_eq seq_suble by blast
   274     obtain n where "i < r (Suc n)" using \<open>strict_mono r\<close> using Suc_le_eq seq_suble by blast
   275     then have "i \<in> {N<..r(Suc n)}" using i by simp
   275     then have "i \<in> {N<..r(Suc n)}" using i by simp
   276     then have "u i \<le> u (r(Suc n))" using r by simp
   276     then have "u i \<le> u (r(Suc n))" using r by simp
   277     then have "u i \<le> (SUP n. (u o r) n)" unfolding o_def by (meson SUP_upper2 UNIV_I)
   277     then have "u i \<le> (SUP n. (u o r) n)" unfolding o_def by (meson SUP_upper2 UNIV_I)
   278   }
   278   }
   279   then have "(SUP i:{N<..}. u i) \<le> (SUP n. (u o r) n)" using SUP_least by blast
   279   then have "(SUP i:{N<..}. u i) \<le> (SUP n. (u o r) n)" using SUP_least by blast
   280   then have "limsup u \<le> (SUP n. (u o r) n)" unfolding Limsup_def
   280   then have "limsup u \<le> (SUP n. (u o r) n)" unfolding Limsup_def
   281     by (metis (mono_tags, lifting) INF_lower2 atLeast_Suc_greaterThan atLeast_def eventually_ge_at_top mem_Collect_eq)
   281     by (metis (mono_tags, lifting) INF_lower2 atLeast_Suc_greaterThan atLeast_def eventually_ge_at_top mem_Collect_eq)
   282   then have "limsup u = (SUP n. (u o r) n)" using \<open>(SUP n. (u o r) n) \<le> limsup u\<close> by simp
   282   then have "limsup u = (SUP n. (u o r) n)" using \<open>(SUP n. (u o r) n) \<le> limsup u\<close> by simp
   283   then have "(u o r) \<longlonglongrightarrow> limsup u" using \<open>(u o r) \<longlonglongrightarrow> (SUP n. (u o r) n)\<close> by simp
   283   then have "(u o r) \<longlonglongrightarrow> limsup u" using \<open>(u o r) \<longlonglongrightarrow> (SUP n. (u o r) n)\<close> by simp
   284   then show ?thesis using \<open>subseq r\<close> by auto
   284   then show ?thesis using \<open>strict_mono r\<close> by auto
   285 qed
   285 qed
   286 
   286 
   287 lemma liminf_subseq_lim:
   287 lemma liminf_subseq_lim:
   288   fixes u::"nat \<Rightarrow> 'a :: {complete_linorder, linorder_topology}"
   288   fixes u::"nat \<Rightarrow> 'a :: {complete_linorder, linorder_topology}"
   289   shows "\<exists>r. subseq r \<and> (u o r) \<longlonglongrightarrow> liminf u"
   289   shows "\<exists>r::nat\<Rightarrow>nat. strict_mono r \<and> (u o r) \<longlonglongrightarrow> liminf u"
   290 proof (cases)
   290 proof (cases)
   291   assume "\<forall>n. \<exists>p>n. \<forall>m\<ge>p. u m \<ge> u p"
   291   assume "\<forall>n. \<exists>p>n. \<forall>m\<ge>p. u m \<ge> u p"
   292   then have "\<exists>r. \<forall>n. (\<forall>m\<ge>r n. u m \<ge> u (r n)) \<and> r n < r (Suc n)"
   292   then have "\<exists>r. \<forall>n. (\<forall>m\<ge>r n. u m \<ge> u (r n)) \<and> r n < r (Suc n)"
   293     by (intro dependent_nat_choice) (auto simp: conj_commute)
   293     by (intro dependent_nat_choice) (auto simp: conj_commute)
   294   then obtain r where "subseq r" and mono: "\<And>n m. r n \<le> m \<Longrightarrow> u m \<ge> u (r n)"
   294   then obtain r :: "nat \<Rightarrow> nat" where "strict_mono r" and mono: "\<And>n m. r n \<le> m \<Longrightarrow> u m \<ge> u (r n)"
   295     by (auto simp: subseq_Suc_iff)
   295     by (auto simp: strict_mono_Suc_iff)
   296   define umin where "umin = (\<lambda>n. (INF m:{n..}. u m))"
   296   define umin where "umin = (\<lambda>n. (INF m:{n..}. u m))"
   297   have "incseq umin" unfolding umin_def by (simp add: INF_superset_mono incseq_def)
   297   have "incseq umin" unfolding umin_def by (simp add: INF_superset_mono incseq_def)
   298   then have "umin \<longlonglongrightarrow> liminf u" unfolding umin_def by (metis LIMSEQ_SUP liminf_SUP_INF)
   298   then have "umin \<longlonglongrightarrow> liminf u" unfolding umin_def by (metis LIMSEQ_SUP liminf_SUP_INF)
   299   then have *: "(umin o r) \<longlonglongrightarrow> liminf u" by (simp add: LIMSEQ_subseq_LIMSEQ \<open>subseq r\<close>)
   299   then have *: "(umin o r) \<longlonglongrightarrow> liminf u" by (simp add: LIMSEQ_subseq_LIMSEQ \<open>strict_mono r\<close>)
   300   have "\<And>n. umin(r n) = u(r n)" unfolding umin_def using mono
   300   have "\<And>n. umin(r n) = u(r n)" unfolding umin_def using mono
   301     by (metis le_INF_iff antisym atLeast_def mem_Collect_eq order_refl)
   301     by (metis le_INF_iff antisym atLeast_def mem_Collect_eq order_refl)
   302   then have "umin o r = u o r" unfolding o_def by simp
   302   then have "umin o r = u o r" unfolding o_def by simp
   303   then have "(u o r) \<longlonglongrightarrow> liminf u" using * by simp
   303   then have "(u o r) \<longlonglongrightarrow> liminf u" using * by simp
   304   then show ?thesis using \<open>subseq r\<close> by blast
   304   then show ?thesis using \<open>strict_mono r\<close> by blast
   305 next
   305 next
   306   assume "\<not> (\<forall>n. \<exists>p>n. (\<forall>m\<ge>p. u m \<ge> u p))"
   306   assume "\<not> (\<forall>n. \<exists>p>n. (\<forall>m\<ge>p. u m \<ge> u p))"
   307   then obtain N where N: "\<And>p. p > N \<Longrightarrow> \<exists>m>p. u p > u m" by (force simp: not_le le_less)
   307   then obtain N where N: "\<And>p. p > N \<Longrightarrow> \<exists>m>p. u p > u m" by (force simp: not_le le_less)
   308   have "\<exists>r. \<forall>n. N < r n \<and> r n < r (Suc n) \<and> (\<forall>i\<in> {N<..r (Suc n)}. u i \<ge> u (r (Suc n)))"
   308   have "\<exists>r. \<forall>n. N < r n \<and> r n < r (Suc n) \<and> (\<forall>i\<in> {N<..r (Suc n)}. u i \<ge> u (r (Suc n)))"
   309   proof (rule dependent_nat_choice)
   309   proof (rule dependent_nat_choice)
   352       qed
   352       qed
   353     qed
   353     qed
   354     then have "N < y \<and> x < y \<and> (\<forall>i\<in>{N<..y}. u i \<ge> u y)" using \<open>y > x\<close> \<open>y > N\<close> by auto
   354     then have "N < y \<and> x < y \<and> (\<forall>i\<in>{N<..y}. u i \<ge> u y)" using \<open>y > x\<close> \<open>y > N\<close> by auto
   355     then show "\<exists>y>N. x < y \<and> (\<forall>i\<in>{N<..y}. u i \<ge> u y)" by auto
   355     then show "\<exists>y>N. x < y \<and> (\<forall>i\<in>{N<..y}. u i \<ge> u y)" by auto
   356   qed (auto)
   356   qed (auto)
   357   then obtain r where r: "\<forall>n. N < r n \<and> r n < r (Suc n) \<and> (\<forall>i\<in> {N<..r (Suc n)}. u i \<ge> u (r (Suc n)))" by auto
   357   then obtain r :: "nat \<Rightarrow> nat" 
   358   have "subseq r" using r by (auto simp: subseq_Suc_iff)
   358     where r: "\<forall>n. N < r n \<and> r n < r (Suc n) \<and> (\<forall>i\<in> {N<..r (Suc n)}. u i \<ge> u (r (Suc n)))" by auto
       
   359   have "strict_mono r" using r by (auto simp: strict_mono_Suc_iff)
   359   have "decseq (u o r)" unfolding o_def using r by (simp add: decseq_SucI order.strict_implies_order)
   360   have "decseq (u o r)" unfolding o_def using r by (simp add: decseq_SucI order.strict_implies_order)
   360   then have "(u o r) \<longlonglongrightarrow> (INF n. (u o r) n)" using LIMSEQ_INF by blast
   361   then have "(u o r) \<longlonglongrightarrow> (INF n. (u o r) n)" using LIMSEQ_INF by blast
   361   then have "liminf (u o r) = (INF n. (u o r) n)" by (simp add: lim_imp_Liminf)
   362   then have "liminf (u o r) = (INF n. (u o r) n)" by (simp add: lim_imp_Liminf)
   362   moreover have "liminf (u o r) \<ge> liminf u" using \<open>subseq r\<close> by (simp add: liminf_subseq_mono)
   363   moreover have "liminf (u o r) \<ge> liminf u" using \<open>strict_mono r\<close> by (simp add: liminf_subseq_mono)
   363   ultimately have "(INF n. (u o r) n) \<ge> liminf u" by simp
   364   ultimately have "(INF n. (u o r) n) \<ge> liminf u" by simp
   364 
   365 
   365   {
   366   {
   366     fix i assume i: "i \<in> {N<..}"
   367     fix i assume i: "i \<in> {N<..}"
   367     obtain n where "i < r (Suc n)" using \<open>subseq r\<close> using Suc_le_eq seq_suble by blast
   368     obtain n where "i < r (Suc n)" using \<open>strict_mono r\<close> using Suc_le_eq seq_suble by blast
   368     then have "i \<in> {N<..r(Suc n)}" using i by simp
   369     then have "i \<in> {N<..r(Suc n)}" using i by simp
   369     then have "u i \<ge> u (r(Suc n))" using r by simp
   370     then have "u i \<ge> u (r(Suc n))" using r by simp
   370     then have "u i \<ge> (INF n. (u o r) n)" unfolding o_def by (meson INF_lower2 UNIV_I)
   371     then have "u i \<ge> (INF n. (u o r) n)" unfolding o_def by (meson INF_lower2 UNIV_I)
   371   }
   372   }
   372   then have "(INF i:{N<..}. u i) \<ge> (INF n. (u o r) n)" using INF_greatest by blast
   373   then have "(INF i:{N<..}. u i) \<ge> (INF n. (u o r) n)" using INF_greatest by blast
   373   then have "liminf u \<ge> (INF n. (u o r) n)" unfolding Liminf_def
   374   then have "liminf u \<ge> (INF n. (u o r) n)" unfolding Liminf_def
   374     by (metis (mono_tags, lifting) SUP_upper2 atLeast_Suc_greaterThan atLeast_def eventually_ge_at_top mem_Collect_eq)
   375     by (metis (mono_tags, lifting) SUP_upper2 atLeast_Suc_greaterThan atLeast_def eventually_ge_at_top mem_Collect_eq)
   375   then have "liminf u = (INF n. (u o r) n)" using \<open>(INF n. (u o r) n) \<ge> liminf u\<close> by simp
   376   then have "liminf u = (INF n. (u o r) n)" using \<open>(INF n. (u o r) n) \<ge> liminf u\<close> by simp
   376   then have "(u o r) \<longlonglongrightarrow> liminf u" using \<open>(u o r) \<longlonglongrightarrow> (INF n. (u o r) n)\<close> by simp
   377   then have "(u o r) \<longlonglongrightarrow> liminf u" using \<open>(u o r) \<longlonglongrightarrow> (INF n. (u o r) n)\<close> by simp
   377   then show ?thesis using \<open>subseq r\<close> by auto
   378   then show ?thesis using \<open>strict_mono r\<close> by auto
   378 qed
   379 qed
   379 
   380 
   380 
   381 
   381 subsection \<open>Extended-Real.thy\<close>
   382 subsection \<open>Extended-Real.thy\<close>
   382 
   383 
  1074 next
  1075 next
  1075   assume "\<not>((limsup u = \<infinity>) \<or> (limsup v = \<infinity>))"
  1076   assume "\<not>((limsup u = \<infinity>) \<or> (limsup v = \<infinity>))"
  1076   then have "limsup u < \<infinity>" "limsup v < \<infinity>" by auto
  1077   then have "limsup u < \<infinity>" "limsup v < \<infinity>" by auto
  1077 
  1078 
  1078   define w where "w = (\<lambda>n. u n + v n)"
  1079   define w where "w = (\<lambda>n. u n + v n)"
  1079   obtain r where r: "subseq r" "(w o r) \<longlonglongrightarrow> limsup w" using limsup_subseq_lim by auto
  1080   obtain r where r: "strict_mono r" "(w o r) \<longlonglongrightarrow> limsup w" using limsup_subseq_lim by auto
  1080   obtain s where s: "subseq s" "(u o r o s) \<longlonglongrightarrow> limsup (u o r)" using limsup_subseq_lim by auto
  1081   obtain s where s: "strict_mono s" "(u o r o s) \<longlonglongrightarrow> limsup (u o r)" using limsup_subseq_lim by auto
  1081   obtain t where t: "subseq t" "(v o r o s o t) \<longlonglongrightarrow> limsup (v o r o s)" using limsup_subseq_lim by auto
  1082   obtain t where t: "strict_mono t" "(v o r o s o t) \<longlonglongrightarrow> limsup (v o r o s)" using limsup_subseq_lim by auto
  1082 
  1083 
  1083   define a where "a = r o s o t"
  1084   define a where "a = r o s o t"
  1084   have "subseq a" using r s t by (simp add: a_def subseq_o)
  1085   have "strict_mono a" using r s t by (simp add: a_def strict_mono_o)
  1085   have l:"(w o a) \<longlonglongrightarrow> limsup w"
  1086   have l:"(w o a) \<longlonglongrightarrow> limsup w"
  1086          "(u o a) \<longlonglongrightarrow> limsup (u o r)"
  1087          "(u o a) \<longlonglongrightarrow> limsup (u o r)"
  1087          "(v o a) \<longlonglongrightarrow> limsup (v o r o s)"
  1088          "(v o a) \<longlonglongrightarrow> limsup (v o r o s)"
  1088   apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
  1089   apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
  1089   apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
  1090   apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
  1090   apply (metis (no_types, lifting) t(2) a_def comp_assoc)
  1091   apply (metis (no_types, lifting) t(2) a_def comp_assoc)
  1091   done
  1092   done
  1092 
  1093 
  1093   have "limsup (u o r) \<le> limsup u" by (simp add: limsup_subseq_mono r(1))
  1094   have "limsup (u o r) \<le> limsup u" by (simp add: limsup_subseq_mono r(1))
  1094   then have a: "limsup (u o r) \<noteq> \<infinity>" using \<open>limsup u < \<infinity>\<close> by auto
  1095   then have a: "limsup (u o r) \<noteq> \<infinity>" using \<open>limsup u < \<infinity>\<close> by auto
  1095   have "limsup (v o r o s) \<le> limsup v" by (simp add: comp_assoc limsup_subseq_mono r(1) s(1) subseq_o)
  1096   have "limsup (v o r o s) \<le> limsup v" 
       
  1097     by (simp add: comp_assoc limsup_subseq_mono r(1) s(1) strict_mono_o)
  1096   then have b: "limsup (v o r o s) \<noteq> \<infinity>" using \<open>limsup v < \<infinity>\<close> by auto
  1098   then have b: "limsup (v o r o s) \<noteq> \<infinity>" using \<open>limsup v < \<infinity>\<close> by auto
  1097 
  1099 
  1098   have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> limsup (u o r) + limsup (v o r o s)"
  1100   have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> limsup (u o r) + limsup (v o r o s)"
  1099     using l tendsto_add_ereal_general a b by fastforce
  1101     using l tendsto_add_ereal_general a b by fastforce
  1100   moreover have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto
  1102   moreover have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto
  1120 next
  1122 next
  1121   assume "\<not>((liminf u = -\<infinity>) \<or> (liminf v = -\<infinity>))"
  1123   assume "\<not>((liminf u = -\<infinity>) \<or> (liminf v = -\<infinity>))"
  1122   then have "liminf u > -\<infinity>" "liminf v > -\<infinity>" by auto
  1124   then have "liminf u > -\<infinity>" "liminf v > -\<infinity>" by auto
  1123 
  1125 
  1124   define w where "w = (\<lambda>n. u n + v n)"
  1126   define w where "w = (\<lambda>n. u n + v n)"
  1125   obtain r where r: "subseq r" "(w o r) \<longlonglongrightarrow> liminf w" using liminf_subseq_lim by auto
  1127   obtain r where r: "strict_mono r" "(w o r) \<longlonglongrightarrow> liminf w" using liminf_subseq_lim by auto
  1126   obtain s where s: "subseq s" "(u o r o s) \<longlonglongrightarrow> liminf (u o r)" using liminf_subseq_lim by auto
  1128   obtain s where s: "strict_mono s" "(u o r o s) \<longlonglongrightarrow> liminf (u o r)" using liminf_subseq_lim by auto
  1127   obtain t where t: "subseq t" "(v o r o s o t) \<longlonglongrightarrow> liminf (v o r o s)" using liminf_subseq_lim by auto
  1129   obtain t where t: "strict_mono t" "(v o r o s o t) \<longlonglongrightarrow> liminf (v o r o s)" using liminf_subseq_lim by auto
  1128 
  1130 
  1129   define a where "a = r o s o t"
  1131   define a where "a = r o s o t"
  1130   have "subseq a" using r s t by (simp add: a_def subseq_o)
  1132   have "strict_mono a" using r s t by (simp add: a_def strict_mono_o)
  1131   have l:"(w o a) \<longlonglongrightarrow> liminf w"
  1133   have l:"(w o a) \<longlonglongrightarrow> liminf w"
  1132          "(u o a) \<longlonglongrightarrow> liminf (u o r)"
  1134          "(u o a) \<longlonglongrightarrow> liminf (u o r)"
  1133          "(v o a) \<longlonglongrightarrow> liminf (v o r o s)"
  1135          "(v o a) \<longlonglongrightarrow> liminf (v o r o s)"
  1134   apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
  1136   apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
  1135   apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
  1137   apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
  1136   apply (metis (no_types, lifting) t(2) a_def comp_assoc)
  1138   apply (metis (no_types, lifting) t(2) a_def comp_assoc)
  1137   done
  1139   done
  1138 
  1140 
  1139   have "liminf (u o r) \<ge> liminf u" by (simp add: liminf_subseq_mono r(1))
  1141   have "liminf (u o r) \<ge> liminf u" by (simp add: liminf_subseq_mono r(1))
  1140   then have a: "liminf (u o r) \<noteq> -\<infinity>" using \<open>liminf u > -\<infinity>\<close> by auto
  1142   then have a: "liminf (u o r) \<noteq> -\<infinity>" using \<open>liminf u > -\<infinity>\<close> by auto
  1141   have "liminf (v o r o s) \<ge> liminf v" by (simp add: comp_assoc liminf_subseq_mono r(1) s(1) subseq_o)
  1143   have "liminf (v o r o s) \<ge> liminf v" 
       
  1144     by (simp add: comp_assoc liminf_subseq_mono r(1) s(1) strict_mono_o)
  1142   then have b: "liminf (v o r o s) \<noteq> -\<infinity>" using \<open>liminf v > -\<infinity>\<close> by auto
  1145   then have b: "liminf (v o r o s) \<noteq> -\<infinity>" using \<open>liminf v > -\<infinity>\<close> by auto
  1143 
  1146 
  1144   have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> liminf (u o r) + liminf (v o r o s)"
  1147   have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> liminf (u o r) + liminf (v o r o s)"
  1145     using l tendsto_add_ereal_general a b by fastforce
  1148     using l tendsto_add_ereal_general a b by fastforce
  1146   moreover have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto
  1149   moreover have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto
  1186   fixes u v::"nat \<Rightarrow> ereal"
  1189   fixes u v::"nat \<Rightarrow> ereal"
  1187   assumes "u \<longlonglongrightarrow> a" "a>0" "a \<noteq> \<infinity>"
  1190   assumes "u \<longlonglongrightarrow> a" "a>0" "a \<noteq> \<infinity>"
  1188   shows "limsup (\<lambda>n. u n * v n) = a * limsup v"
  1191   shows "limsup (\<lambda>n. u n * v n) = a * limsup v"
  1189 proof -
  1192 proof -
  1190   define w where "w = (\<lambda>n. u n * v n)"
  1193   define w where "w = (\<lambda>n. u n * v n)"
  1191   obtain r where r: "subseq r" "(v o r) \<longlonglongrightarrow> limsup v" using limsup_subseq_lim by auto
  1194   obtain r where r: "strict_mono r" "(v o r) \<longlonglongrightarrow> limsup v" using limsup_subseq_lim by auto
  1192   have "(u o r) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ r by auto
  1195   have "(u o r) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ r by auto
  1193   with tendsto_mult_ereal[OF this r(2)] have "(\<lambda>n. (u o r) n * (v o r) n) \<longlonglongrightarrow> a * limsup v" using assms(2) assms(3) by auto
  1196   with tendsto_mult_ereal[OF this r(2)] have "(\<lambda>n. (u o r) n * (v o r) n) \<longlonglongrightarrow> a * limsup v" using assms(2) assms(3) by auto
  1194   moreover have "\<And>n. (w o r) n = (u o r) n * (v o r) n" unfolding w_def by auto
  1197   moreover have "\<And>n. (w o r) n = (u o r) n * (v o r) n" unfolding w_def by auto
  1195   ultimately have "(w o r) \<longlonglongrightarrow> a * limsup v" unfolding w_def by presburger
  1198   ultimately have "(w o r) \<longlonglongrightarrow> a * limsup v" unfolding w_def by presburger
  1196   then have "limsup (w o r) = a * limsup v" by (simp add: tendsto_iff_Liminf_eq_Limsup)
  1199   then have "limsup (w o r) = a * limsup v" by (simp add: tendsto_iff_Liminf_eq_Limsup)
  1197   then have I: "limsup w \<ge> a * limsup v" by (metis limsup_subseq_mono r(1))
  1200   then have I: "limsup w \<ge> a * limsup v" by (metis limsup_subseq_mono r(1))
  1198 
  1201 
  1199   obtain s where s: "subseq s" "(w o s) \<longlonglongrightarrow> limsup w" using limsup_subseq_lim by auto
  1202   obtain s where s: "strict_mono s" "(w o s) \<longlonglongrightarrow> limsup w" using limsup_subseq_lim by auto
  1200   have *: "(u o s) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ s by auto
  1203   have *: "(u o s) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ s by auto
  1201   have "eventually (\<lambda>n. (u o s) n > 0) sequentially" using assms(2) * order_tendsto_iff by blast
  1204   have "eventually (\<lambda>n. (u o s) n > 0) sequentially" using assms(2) * order_tendsto_iff by blast
  1202   moreover have "eventually (\<lambda>n. (u o s) n < \<infinity>) sequentially" using assms(3) * order_tendsto_iff by blast
  1205   moreover have "eventually (\<lambda>n. (u o s) n < \<infinity>) sequentially" using assms(3) * order_tendsto_iff by blast
  1203   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
  1206   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
  1204     unfolding w_def using that by (auto simp add: ereal_divide_eq)
  1207     unfolding w_def using that by (auto simp add: ereal_divide_eq)
  1216   fixes u v::"nat \<Rightarrow> ereal"
  1219   fixes u v::"nat \<Rightarrow> ereal"
  1217   assumes "u \<longlonglongrightarrow> a" "a>0" "a \<noteq> \<infinity>"
  1220   assumes "u \<longlonglongrightarrow> a" "a>0" "a \<noteq> \<infinity>"
  1218   shows "liminf (\<lambda>n. u n * v n) = a * liminf v"
  1221   shows "liminf (\<lambda>n. u n * v n) = a * liminf v"
  1219 proof -
  1222 proof -
  1220   define w where "w = (\<lambda>n. u n * v n)"
  1223   define w where "w = (\<lambda>n. u n * v n)"
  1221   obtain r where r: "subseq r" "(v o r) \<longlonglongrightarrow> liminf v" using liminf_subseq_lim by auto
  1224   obtain r where r: "strict_mono r" "(v o r) \<longlonglongrightarrow> liminf v" using liminf_subseq_lim by auto
  1222   have "(u o r) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ r by auto
  1225   have "(u o r) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ r by auto
  1223   with tendsto_mult_ereal[OF this r(2)] have "(\<lambda>n. (u o r) n * (v o r) n) \<longlonglongrightarrow> a * liminf v" using assms(2) assms(3) by auto
  1226   with tendsto_mult_ereal[OF this r(2)] have "(\<lambda>n. (u o r) n * (v o r) n) \<longlonglongrightarrow> a * liminf v" using assms(2) assms(3) by auto
  1224   moreover have "\<And>n. (w o r) n = (u o r) n * (v o r) n" unfolding w_def by auto
  1227   moreover have "\<And>n. (w o r) n = (u o r) n * (v o r) n" unfolding w_def by auto
  1225   ultimately have "(w o r) \<longlonglongrightarrow> a * liminf v" unfolding w_def by presburger
  1228   ultimately have "(w o r) \<longlonglongrightarrow> a * liminf v" unfolding w_def by presburger
  1226   then have "liminf (w o r) = a * liminf v" by (simp add: tendsto_iff_Liminf_eq_Limsup)
  1229   then have "liminf (w o r) = a * liminf v" by (simp add: tendsto_iff_Liminf_eq_Limsup)
  1227   then have I: "liminf w \<le> a * liminf v" by (metis liminf_subseq_mono r(1))
  1230   then have I: "liminf w \<le> a * liminf v" by (metis liminf_subseq_mono r(1))
  1228 
  1231 
  1229   obtain s where s: "subseq s" "(w o s) \<longlonglongrightarrow> liminf w" using liminf_subseq_lim by auto
  1232   obtain s where s: "strict_mono s" "(w o s) \<longlonglongrightarrow> liminf w" using liminf_subseq_lim by auto
  1230   have *: "(u o s) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ s by auto
  1233   have *: "(u o s) \<longlonglongrightarrow> a" using assms(1) LIMSEQ_subseq_LIMSEQ s by auto
  1231   have "eventually (\<lambda>n. (u o s) n > 0) sequentially" using assms(2) * order_tendsto_iff by blast
  1234   have "eventually (\<lambda>n. (u o s) n > 0) sequentially" using assms(2) * order_tendsto_iff by blast
  1232   moreover have "eventually (\<lambda>n. (u o s) n < \<infinity>) sequentially" using assms(3) * order_tendsto_iff by blast
  1235   moreover have "eventually (\<lambda>n. (u o s) n < \<infinity>) sequentially" using assms(3) * order_tendsto_iff by blast
  1233   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
  1236   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
  1234     unfolding w_def using that by (auto simp add: ereal_divide_eq)
  1237     unfolding w_def using that by (auto simp add: ereal_divide_eq)
  1284 next
  1287 next
  1285   assume "\<not>(limsup v = \<infinity> \<or> liminf u = \<infinity>)"
  1288   assume "\<not>(limsup v = \<infinity> \<or> liminf u = \<infinity>)"
  1286   then have "limsup v < \<infinity>" "liminf u < \<infinity>" by auto
  1289   then have "limsup v < \<infinity>" "liminf u < \<infinity>" by auto
  1287 
  1290 
  1288   define w where "w = (\<lambda>n. u n + v n)"
  1291   define w where "w = (\<lambda>n. u n + v n)"
  1289   obtain r where r: "subseq r" "(u o r) \<longlonglongrightarrow> liminf u" using liminf_subseq_lim by auto
  1292   obtain r where r: "strict_mono r" "(u o r) \<longlonglongrightarrow> liminf u" using liminf_subseq_lim by auto
  1290   obtain s where s: "subseq s" "(w o r o s) \<longlonglongrightarrow> liminf (w o r)" using liminf_subseq_lim by auto
  1293   obtain s where s: "strict_mono s" "(w o r o s) \<longlonglongrightarrow> liminf (w o r)" using liminf_subseq_lim by auto
  1291   obtain t where t: "subseq t" "(v o r o s o t) \<longlonglongrightarrow> limsup (v o r o s)" using limsup_subseq_lim by auto
  1294   obtain t where t: "strict_mono t" "(v o r o s o t) \<longlonglongrightarrow> limsup (v o r o s)" using limsup_subseq_lim by auto
  1292 
  1295 
  1293   define a where "a = r o s o t"
  1296   define a where "a = r o s o t"
  1294   have "subseq a" using r s t by (simp add: a_def subseq_o)
  1297   have "strict_mono a" using r s t by (simp add: a_def strict_mono_o)
  1295   have l:"(u o a) \<longlonglongrightarrow> liminf u"
  1298   have l:"(u o a) \<longlonglongrightarrow> liminf u"
  1296          "(w o a) \<longlonglongrightarrow> liminf (w o r)"
  1299          "(w o a) \<longlonglongrightarrow> liminf (w o r)"
  1297          "(v o a) \<longlonglongrightarrow> limsup (v o r o s)"
  1300          "(v o a) \<longlonglongrightarrow> limsup (v o r o s)"
  1298   apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
  1301   apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
  1299   apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
  1302   apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc)
  1300   apply (metis (no_types, lifting) t(2) a_def comp_assoc)
  1303   apply (metis (no_types, lifting) t(2) a_def comp_assoc)
  1301   done
  1304   done
  1302 
  1305 
  1303   have "liminf (w o r) \<ge> liminf w" by (simp add: liminf_subseq_mono r(1))
  1306   have "liminf (w o r) \<ge> liminf w" by (simp add: liminf_subseq_mono r(1))
  1304   have "limsup (v o r o s) \<le> limsup v" by (simp add: comp_assoc limsup_subseq_mono r(1) s(1) subseq_o)
  1307   have "limsup (v o r o s) \<le> limsup v" 
       
  1308     by (simp add: comp_assoc limsup_subseq_mono r(1) s(1) strict_mono_o)
  1305   then have b: "limsup (v o r o s) < \<infinity>" using \<open>limsup v < \<infinity>\<close> by auto
  1309   then have b: "limsup (v o r o s) < \<infinity>" using \<open>limsup v < \<infinity>\<close> by auto
  1306 
  1310 
  1307   have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> liminf u + limsup (v o r o s)"
  1311   have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> liminf u + limsup (v o r o s)"
  1308     apply (rule tendsto_add_ereal_general) using b \<open>liminf u < \<infinity>\<close> l(1) l(3) by force+
  1312     apply (rule tendsto_add_ereal_general) using b \<open>liminf u < \<infinity>\<close> l(1) l(3) by force+
  1309   moreover have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto
  1313   moreover have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto