src/HOL/Analysis/Set_Integral.thy
changeset 64911 f0e07600de47
parent 64284 f3b905b2eee2
child 66164 2d79288b042c
equal deleted inserted replaced
64910:6108dddad9f0 64911:f0e07600de47
    12 begin
    12 begin
    13 
    13 
    14 lemma bij_inv_eq_iff: "bij p \<Longrightarrow> x = inv p y \<longleftrightarrow> p x = y" (* COPIED FROM Permutations *)
    14 lemma bij_inv_eq_iff: "bij p \<Longrightarrow> x = inv p y \<longleftrightarrow> p x = y" (* COPIED FROM Permutations *)
    15   using surj_f_inv_f[of p] by (auto simp add: bij_def)
    15   using surj_f_inv_f[of p] by (auto simp add: bij_def)
    16 
    16 
    17 subsection {*Fun.thy*}
    17 subsection \<open>Fun.thy\<close>
    18 
    18 
    19 lemma inj_fn:
    19 lemma inj_fn:
    20   fixes f::"'a \<Rightarrow> 'a"
    20   fixes f::"'a \<Rightarrow> 'a"
    21   assumes "inj f"
    21   assumes "inj f"
    22   shows "inj (f^^n)"
    22   shows "inj (f^^n)"
   127   fixes K::"nat set"
   127   fixes K::"nat set"
   128   assumes "K \<noteq> {}"
   128   assumes "K \<noteq> {}"
   129   shows "Inf K \<in> K"
   129   shows "Inf K \<in> K"
   130 by (auto simp add: Min_def Inf_nat_def) (meson LeastI assms bot.extremum_unique subsetI)
   130 by (auto simp add: Min_def Inf_nat_def) (meson LeastI assms bot.extremum_unique subsetI)
   131 
   131 
   132 subsection {*Liminf-Limsup.thy*}
   132 subsection \<open>Liminf-Limsup.thy\<close>
   133 
   133 
   134 lemma limsup_shift:
   134 lemma limsup_shift:
   135   "limsup (\<lambda>n. u (n+1)) = limsup u"
   135   "limsup (\<lambda>n. u (n+1)) = limsup u"
   136 proof -
   136 proof -
   137   have "(SUP m:{n+1..}. u m) = (SUP m:{n..}. u (m + 1))" for n
   137   have "(SUP m:{n+1..}. u m) = (SUP m:{n..}. u (m + 1))" for n
   138     apply (rule SUP_eq) using Suc_le_D by auto
   138     apply (rule SUP_eq) using Suc_le_D by auto
   139   then have a: "(INF n. SUP m:{n..}. u (m + 1)) = (INF n. (SUP m:{n+1..}. u m))" by auto
   139   then have a: "(INF n. SUP m:{n..}. u (m + 1)) = (INF n. (SUP m:{n+1..}. u m))" by auto
   140   have b: "(INF n. (SUP m:{n+1..}. u m)) = (INF n:{1..}. (SUP m:{n..}. u m))"
   140   have b: "(INF n. (SUP m:{n+1..}. u m)) = (INF n:{1..}. (SUP m:{n..}. u m))"
   141     apply (rule INF_eq) using Suc_le_D by auto
   141     apply (rule INF_eq) using Suc_le_D by auto
   142   have "(INF n:{1..}. v n) = (INF n. v n)" if "decseq v" for v::"nat \<Rightarrow> 'a"
   142   have "(INF n:{1..}. v n) = (INF n. v n)" if "decseq v" for v::"nat \<Rightarrow> 'a"
   143     apply (rule INF_eq) using `decseq v` decseq_Suc_iff by auto
   143     apply (rule INF_eq) using \<open>decseq v\<close> decseq_Suc_iff by auto
   144   moreover have "decseq (\<lambda>n. (SUP m:{n..}. u m))" by (simp add: SUP_subset_mono decseq_def)
   144   moreover have "decseq (\<lambda>n. (SUP m:{n..}. u m))" by (simp add: SUP_subset_mono decseq_def)
   145   ultimately have c: "(INF n:{1..}. (SUP m:{n..}. u m)) = (INF n. (SUP m:{n..}. u m))" by simp
   145   ultimately have c: "(INF n:{1..}. (SUP m:{n..}. u m)) = (INF n. (SUP m:{n..}. u m))" by simp
   146   have "(INF n. SUPREMUM {n..} u) = (INF n. SUP m:{n..}. u (m + 1))" using a b c by simp
   146   have "(INF n. SUPREMUM {n..} u) = (INF n. SUP m:{n..}. u (m + 1))" using a b c by simp
   147   then show ?thesis by (auto cong: limsup_INF_SUP)
   147   then show ?thesis by (auto cong: limsup_INF_SUP)
   148 qed
   148 qed
   162     apply (rule INF_eq) using Suc_le_D by (auto)
   162     apply (rule INF_eq) using Suc_le_D by (auto)
   163   then have a: "(SUP n. INF m:{n..}. u (m + 1)) = (SUP n. (INF m:{n+1..}. u m))" by auto
   163   then have a: "(SUP n. INF m:{n..}. u (m + 1)) = (SUP n. (INF m:{n+1..}. u m))" by auto
   164   have b: "(SUP n. (INF m:{n+1..}. u m)) = (SUP n:{1..}. (INF m:{n..}. u m))"
   164   have b: "(SUP n. (INF m:{n+1..}. u m)) = (SUP n:{1..}. (INF m:{n..}. u m))"
   165     apply (rule SUP_eq) using Suc_le_D by (auto)
   165     apply (rule SUP_eq) using Suc_le_D by (auto)
   166   have "(SUP n:{1..}. v n) = (SUP n. v n)" if "incseq v" for v::"nat \<Rightarrow> 'a"
   166   have "(SUP n:{1..}. v n) = (SUP n. v n)" if "incseq v" for v::"nat \<Rightarrow> 'a"
   167     apply (rule SUP_eq) using `incseq v` incseq_Suc_iff by auto
   167     apply (rule SUP_eq) using \<open>incseq v\<close> incseq_Suc_iff by auto
   168   moreover have "incseq (\<lambda>n. (INF m:{n..}. u m))" by (simp add: INF_superset_mono mono_def)
   168   moreover have "incseq (\<lambda>n. (INF m:{n..}. u m))" by (simp add: INF_superset_mono mono_def)
   169   ultimately have c: "(SUP n:{1..}. (INF m:{n..}. u m)) = (SUP n. (INF m:{n..}. u m))" by simp
   169   ultimately have c: "(SUP n:{1..}. (INF m:{n..}. u m)) = (SUP n. (INF m:{n..}. u m))" by simp
   170   have "(SUP n. INFIMUM {n..} u) = (SUP n. INF m:{n..}. u (m + 1))" using a b c by simp
   170   have "(SUP n. INFIMUM {n..} u) = (SUP n. INF m:{n..}. u (m + 1))" using a b c by simp
   171   then show ?thesis by (auto cong: liminf_SUP_INF)
   171   then show ?thesis by (auto cong: liminf_SUP_INF)
   172 qed
   172 qed
   186 proof -
   186 proof -
   187   have "(INF P:{P. eventually P F}. SUP x:{x. P x}. u x) > c" using assms by (simp add: Limsup_def)
   187   have "(INF P:{P. eventually P F}. SUP x:{x. P x}. u x) > c" using assms by (simp add: Limsup_def)
   188   then show ?thesis by (metis eventually_True mem_Collect_eq less_INF_D less_SUP_iff)
   188   then show ?thesis by (metis eventually_True mem_Collect_eq less_INF_D less_SUP_iff)
   189 qed
   189 qed
   190 
   190 
   191 text {* 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.*}
   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. subseq r \<and> (u o r) \<longlonglongrightarrow> limsup u"
   197 proof (cases)
   197 proof (cases)
   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 where "subseq 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: subseq_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 `subseq r`)
   206   then have *: "(umax o r) \<longlonglongrightarrow> limsup u" by (simp add: LIMSEQ_subseq_LIMSEQ \<open>subseq 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 `subseq r` by blast
   211   then show ?thesis using \<open>subseq 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)
   217     fix x assume "N < x"
   217     fix x assume "N < x"
   218     then have a: "finite {N<..x}" "{N<..x} \<noteq> {}" by simp_all
   218     then have a: "finite {N<..x}" "{N<..x} \<noteq> {}" by simp_all
   219     have "Max {u i |i. i \<in> {N<..x}} \<in> {u i |i. i \<in> {N<..x}}" apply (rule Max_in) using a by (auto)
   219     have "Max {u i |i. i \<in> {N<..x}} \<in> {u i |i. i \<in> {N<..x}}" apply (rule Max_in) using a by (auto)
   220     then obtain p where "p \<in> {N<..x}" and upmax: "u p = Max{u i |i. i \<in> {N<..x}}" by auto
   220     then obtain p where "p \<in> {N<..x}" and upmax: "u p = Max{u i |i. i \<in> {N<..x}}" by auto
   221     define U where "U = {m. m > p \<and> u p < u m}"
   221     define U where "U = {m. m > p \<and> u p < u m}"
   222     have "U \<noteq> {}" unfolding U_def using N[of p] `p \<in> {N<..x}` by auto
   222     have "U \<noteq> {}" unfolding U_def using N[of p] \<open>p \<in> {N<..x}\<close> by auto
   223     define y where "y = Inf U"
   223     define y where "y = Inf U"
   224     then have "y \<in> U" using `U \<noteq> {}` by (simp add: Inf_nat_def1)
   224     then have "y \<in> U" using \<open>U \<noteq> {}\<close> by (simp add: Inf_nat_def1)
   225     have a: "\<And>i. i \<in> {N<..x} \<Longrightarrow> u i \<le> u p"
   225     have a: "\<And>i. i \<in> {N<..x} \<Longrightarrow> u i \<le> u p"
   226     proof -
   226     proof -
   227       fix i assume "i \<in> {N<..x}"
   227       fix i assume "i \<in> {N<..x}"
   228       then have "u i \<in> {u i |i. i \<in> {N<..x}}" by blast
   228       then have "u i \<in> {u i |i. i \<in> {N<..x}}" by blast
   229       then show "u i \<le> u p" using upmax by simp
   229       then show "u i \<le> u p" using upmax by simp
   230     qed
   230     qed
   231     moreover have "u p < u y" using `y \<in> U` U_def by auto
   231     moreover have "u p < u y" using \<open>y \<in> U\<close> U_def by auto
   232     ultimately have "y \<notin> {N<..x}" using not_le by blast
   232     ultimately have "y \<notin> {N<..x}" using not_le by blast
   233     moreover have "y > N" using `y \<in> U` U_def `p \<in> {N<..x}` by auto
   233     moreover have "y > N" using \<open>y \<in> U\<close> U_def \<open>p \<in> {N<..x}\<close> by auto
   234     ultimately have "y > x" by auto
   234     ultimately have "y > x" by auto
   235 
   235 
   236     have "\<And>i. i \<in> {N<..y} \<Longrightarrow> u i \<le> u y"
   236     have "\<And>i. i \<in> {N<..y} \<Longrightarrow> u i \<le> u y"
   237     proof -
   237     proof -
   238       fix i assume "i \<in> {N<..y}" show "u i \<le> u y"
   238       fix i assume "i \<in> {N<..y}" show "u i \<le> u y"
   239       proof (cases)
   239       proof (cases)
   240         assume "i = y"
   240         assume "i = y"
   241         then show ?thesis by simp
   241         then show ?thesis by simp
   242       next
   242       next
   243         assume "\<not>(i=y)"
   243         assume "\<not>(i=y)"
   244         then have i:"i \<in> {N<..<y}" using `i \<in> {N<..y}` by simp
   244         then have i:"i \<in> {N<..<y}" using \<open>i \<in> {N<..y}\<close> by simp
   245         have "u i \<le> u p"
   245         have "u i \<le> u p"
   246         proof (cases)
   246         proof (cases)
   247           assume "i \<le> x"
   247           assume "i \<le> x"
   248           then have "i \<in> {N<..x}" using i by simp
   248           then have "i \<in> {N<..x}" using i by simp
   249           then show ?thesis using a by simp
   249           then show ?thesis using a by simp
   250         next
   250         next
   251           assume "\<not>(i \<le> x)"
   251           assume "\<not>(i \<le> x)"
   252           then have "i > x" by simp
   252           then have "i > x" by simp
   253           then have *: "i > p" using `p \<in> {N<..x}` by simp
   253           then have *: "i > p" using \<open>p \<in> {N<..x}\<close> by simp
   254           have "i < Inf U" using i y_def by simp
   254           have "i < Inf U" using i y_def by simp
   255           then have "i \<notin> U" using Inf_nat_def not_less_Least by auto
   255           then have "i \<notin> U" using Inf_nat_def not_less_Least by auto
   256           then show ?thesis using U_def * by auto
   256           then show ?thesis using U_def * by auto
   257         qed
   257         qed
   258         then show "u i \<le> u y" using `u p < u y` by auto
   258         then show "u i \<le> u y" using \<open>u p < u y\<close> by auto
   259       qed
   259       qed
   260     qed
   260     qed
   261     then have "N < y \<and> x < y \<and> (\<forall>i\<in>{N<..y}. u i \<le> u y)" using `y > x` `y > N` 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 "subseq r" using r by (auto simp: subseq_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 `subseq r` by (simp add: limsup_subseq_mono)
   269   moreover have "limsup (u o r) \<le> limsup u" using \<open>subseq 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 `subseq r` using Suc_le_eq seq_suble by blast
   274     obtain n where "i < r (Suc n)" using \<open>subseq 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 `(SUP n. (u o r) n) \<le> limsup u` 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 `(u o r) \<longlonglongrightarrow> (SUP n. (u o r) n)` 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 `subseq r` by auto
   284   then show ?thesis using \<open>subseq 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. subseq r \<and> (u o r) \<longlonglongrightarrow> liminf u"
   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 where "subseq 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: subseq_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 `subseq r`)
   299   then have *: "(umin o r) \<longlonglongrightarrow> liminf u" by (simp add: LIMSEQ_subseq_LIMSEQ \<open>subseq 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 `subseq r` by blast
   304   then show ?thesis using \<open>subseq 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)
   310     fix x assume "N < x"
   310     fix x assume "N < x"
   311     then have a: "finite {N<..x}" "{N<..x} \<noteq> {}" by simp_all
   311     then have a: "finite {N<..x}" "{N<..x} \<noteq> {}" by simp_all
   312     have "Min {u i |i. i \<in> {N<..x}} \<in> {u i |i. i \<in> {N<..x}}" apply (rule Min_in) using a by (auto)
   312     have "Min {u i |i. i \<in> {N<..x}} \<in> {u i |i. i \<in> {N<..x}}" apply (rule Min_in) using a by (auto)
   313     then obtain p where "p \<in> {N<..x}" and upmin: "u p = Min{u i |i. i \<in> {N<..x}}" by auto
   313     then obtain p where "p \<in> {N<..x}" and upmin: "u p = Min{u i |i. i \<in> {N<..x}}" by auto
   314     define U where "U = {m. m > p \<and> u p > u m}"
   314     define U where "U = {m. m > p \<and> u p > u m}"
   315     have "U \<noteq> {}" unfolding U_def using N[of p] `p \<in> {N<..x}` by auto
   315     have "U \<noteq> {}" unfolding U_def using N[of p] \<open>p \<in> {N<..x}\<close> by auto
   316     define y where "y = Inf U"
   316     define y where "y = Inf U"
   317     then have "y \<in> U" using `U \<noteq> {}` by (simp add: Inf_nat_def1)
   317     then have "y \<in> U" using \<open>U \<noteq> {}\<close> by (simp add: Inf_nat_def1)
   318     have a: "\<And>i. i \<in> {N<..x} \<Longrightarrow> u i \<ge> u p"
   318     have a: "\<And>i. i \<in> {N<..x} \<Longrightarrow> u i \<ge> u p"
   319     proof -
   319     proof -
   320       fix i assume "i \<in> {N<..x}"
   320       fix i assume "i \<in> {N<..x}"
   321       then have "u i \<in> {u i |i. i \<in> {N<..x}}" by blast
   321       then have "u i \<in> {u i |i. i \<in> {N<..x}}" by blast
   322       then show "u i \<ge> u p" using upmin by simp
   322       then show "u i \<ge> u p" using upmin by simp
   323     qed
   323     qed
   324     moreover have "u p > u y" using `y \<in> U` U_def by auto
   324     moreover have "u p > u y" using \<open>y \<in> U\<close> U_def by auto
   325     ultimately have "y \<notin> {N<..x}" using not_le by blast
   325     ultimately have "y \<notin> {N<..x}" using not_le by blast
   326     moreover have "y > N" using `y \<in> U` U_def `p \<in> {N<..x}` by auto
   326     moreover have "y > N" using \<open>y \<in> U\<close> U_def \<open>p \<in> {N<..x}\<close> by auto
   327     ultimately have "y > x" by auto
   327     ultimately have "y > x" by auto
   328 
   328 
   329     have "\<And>i. i \<in> {N<..y} \<Longrightarrow> u i \<ge> u y"
   329     have "\<And>i. i \<in> {N<..y} \<Longrightarrow> u i \<ge> u y"
   330     proof -
   330     proof -
   331       fix i assume "i \<in> {N<..y}" show "u i \<ge> u y"
   331       fix i assume "i \<in> {N<..y}" show "u i \<ge> u y"
   332       proof (cases)
   332       proof (cases)
   333         assume "i = y"
   333         assume "i = y"
   334         then show ?thesis by simp
   334         then show ?thesis by simp
   335       next
   335       next
   336         assume "\<not>(i=y)"
   336         assume "\<not>(i=y)"
   337         then have i:"i \<in> {N<..<y}" using `i \<in> {N<..y}` by simp
   337         then have i:"i \<in> {N<..<y}" using \<open>i \<in> {N<..y}\<close> by simp
   338         have "u i \<ge> u p"
   338         have "u i \<ge> u p"
   339         proof (cases)
   339         proof (cases)
   340           assume "i \<le> x"
   340           assume "i \<le> x"
   341           then have "i \<in> {N<..x}" using i by simp
   341           then have "i \<in> {N<..x}" using i by simp
   342           then show ?thesis using a by simp
   342           then show ?thesis using a by simp
   343         next
   343         next
   344           assume "\<not>(i \<le> x)"
   344           assume "\<not>(i \<le> x)"
   345           then have "i > x" by simp
   345           then have "i > x" by simp
   346           then have *: "i > p" using `p \<in> {N<..x}` by simp
   346           then have *: "i > p" using \<open>p \<in> {N<..x}\<close> by simp
   347           have "i < Inf U" using i y_def by simp
   347           have "i < Inf U" using i y_def by simp
   348           then have "i \<notin> U" using Inf_nat_def not_less_Least by auto
   348           then have "i \<notin> U" using Inf_nat_def not_less_Least by auto
   349           then show ?thesis using U_def * by auto
   349           then show ?thesis using U_def * by auto
   350         qed
   350         qed
   351         then show "u i \<ge> u y" using `u p > u y` by auto
   351         then show "u i \<ge> u y" using \<open>u p > u y\<close> by auto
   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 `y > x` `y > N` 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 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
   358   have "subseq r" using r by (auto simp: subseq_Suc_iff)
   358   have "subseq r" using r by (auto simp: subseq_Suc_iff)
   359   have "decseq (u o r)" unfolding o_def using r by (simp add: decseq_SucI order.strict_implies_order)
   359   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
   360   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)
   361   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 `subseq r` by (simp add: liminf_subseq_mono)
   362   moreover have "liminf (u o r) \<ge> liminf u" using \<open>subseq r\<close> by (simp add: liminf_subseq_mono)
   363   ultimately have "(INF n. (u o r) n) \<ge> liminf u" by simp
   363   ultimately have "(INF n. (u o r) n) \<ge> liminf u" by simp
   364 
   364 
   365   {
   365   {
   366     fix i assume i: "i \<in> {N<..}"
   366     fix i assume i: "i \<in> {N<..}"
   367     obtain n where "i < r (Suc n)" using `subseq r` using Suc_le_eq seq_suble by blast
   367     obtain n where "i < r (Suc n)" using \<open>subseq r\<close> using Suc_le_eq seq_suble by blast
   368     then have "i \<in> {N<..r(Suc n)}" using i by simp
   368     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
   369     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)
   370     then have "u i \<ge> (INF n. (u o r) n)" unfolding o_def by (meson INF_lower2 UNIV_I)
   371   }
   371   }
   372   then have "(INF i:{N<..}. u i) \<ge> (INF n. (u o r) n)" using INF_greatest by blast
   372   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
   373   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)
   374     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 `(INF n. (u o r) n) \<ge> liminf u` by simp
   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 "(u o r) \<longlonglongrightarrow> liminf u" using `(u o r) \<longlonglongrightarrow> (INF n. (u o r) n)` 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 show ?thesis using `subseq r` by auto
   377   then show ?thesis using \<open>subseq r\<close> by auto
   378 qed
   378 qed
   379 
   379 
   380 
   380 
   381 subsection {*Extended-Real.thy*}
   381 subsection \<open>Extended-Real.thy\<close>
   382 
   382 
   383 text{* The proof of this one is copied from \verb+ereal_add_mono+. *}
   383 text\<open>The proof of this one is copied from \verb+ereal_add_mono+.\<close>
   384 lemma ereal_add_strict_mono2:
   384 lemma ereal_add_strict_mono2:
   385   fixes a b c d :: ereal
   385   fixes a b c d :: ereal
   386   assumes "a < b"
   386   assumes "a < b"
   387     and "c < d"
   387     and "c < d"
   388   shows "a + c < b + d"
   388   shows "a + c < b + d"
   390 apply (cases a)
   390 apply (cases a)
   391 apply (cases rule: ereal3_cases[of b c d], auto)
   391 apply (cases rule: ereal3_cases[of b c d], auto)
   392 apply (cases rule: ereal3_cases[of b c d], auto)
   392 apply (cases rule: ereal3_cases[of b c d], auto)
   393 done
   393 done
   394 
   394 
   395 text {* The next ones are analogues of \verb+mult_mono+ and \verb+mult_mono'+ in ereal.*}
   395 text \<open>The next ones are analogues of \verb+mult_mono+ and \verb+mult_mono'+ in ereal.\<close>
   396 
   396 
   397 lemma ereal_mult_mono:
   397 lemma ereal_mult_mono:
   398   fixes a b c d::ereal
   398   fixes a b c d::ereal
   399   assumes "b \<ge> 0" "c \<ge> 0" "a \<le> b" "c \<le> d"
   399   assumes "b \<ge> 0" "c \<ge> 0" "a \<le> b" "c \<le> d"
   400   shows "a * c \<le> b * d"
   400   shows "a * c \<le> b * d"
   409 lemma ereal_mult_mono_strict:
   409 lemma ereal_mult_mono_strict:
   410   fixes a b c d::ereal
   410   fixes a b c d::ereal
   411   assumes "b > 0" "c > 0" "a < b" "c < d"
   411   assumes "b > 0" "c > 0" "a < b" "c < d"
   412   shows "a * c < b * d"
   412   shows "a * c < b * d"
   413 proof -
   413 proof -
   414   have "c < \<infinity>" using `c < d` by auto
   414   have "c < \<infinity>" using \<open>c < d\<close> by auto
   415   then have "a * c < b * c" by (metis ereal_mult_strict_left_mono[OF assms(3) assms(2)] mult.commute)
   415   then have "a * c < b * c" by (metis ereal_mult_strict_left_mono[OF assms(3) assms(2)] mult.commute)
   416   moreover have "b * c \<le> b * d" using assms(2) assms(4) by (simp add: assms(1) ereal_mult_left_mono less_imp_le)
   416   moreover have "b * c \<le> b * d" using assms(2) assms(4) by (simp add: assms(1) ereal_mult_left_mono less_imp_le)
   417   ultimately show ?thesis by simp
   417   ultimately show ?thesis by simp
   418 qed
   418 qed
   419 
   419 
   463     done
   463     done
   464   then show ?thesis by (simp only: setcompr_eq_image[symmetric])
   464   then show ?thesis by (simp only: setcompr_eq_image[symmetric])
   465 qed
   465 qed
   466 
   466 
   467 
   467 
   468 subsubsection {*Continuity of addition*}
   468 subsubsection \<open>Continuity of addition\<close>
   469 
   469 
   470 text {*The next few lemmas remove an unnecessary assumption in \verb+tendsto_add_ereal+, culminating
   470 text \<open>The next few lemmas remove an unnecessary assumption in \verb+tendsto_add_ereal+, culminating
   471 in \verb+tendsto_add_ereal_general+ which essentially says that the addition
   471 in \verb+tendsto_add_ereal_general+ which essentially says that the addition
   472 is continuous on ereal times ereal, except at $(-\infty, \infty)$ and $(\infty, -\infty)$.
   472 is continuous on ereal times ereal, except at $(-\infty, \infty)$ and $(\infty, -\infty)$.
   473 It is much more convenient in many situations, see for instance the proof of
   473 It is much more convenient in many situations, see for instance the proof of
   474 \verb+tendsto_sum_ereal+ below. *}
   474 \verb+tendsto_sum_ereal+ below.\<close>
   475 
   475 
   476 lemma tendsto_add_ereal_PInf:
   476 lemma tendsto_add_ereal_PInf:
   477   fixes y :: ereal
   477   fixes y :: ereal
   478   assumes y: "y \<noteq> -\<infinity>"
   478   assumes y: "y \<noteq> -\<infinity>"
   479   assumes f: "(f \<longlongrightarrow> \<infinity>) F" and g: "(g \<longlongrightarrow> y) F"
   479   assumes f: "(f \<longlongrightarrow> \<infinity>) F" and g: "(g \<longlongrightarrow> y) F"
   505     ultimately have "eventually (\<lambda>x. f x + g x > ereal M) F" using eventually_mono by force
   505     ultimately have "eventually (\<lambda>x. f x + g x > ereal M) F" using eventually_mono by force
   506   }
   506   }
   507   then show ?thesis by (simp add: tendsto_PInfty)
   507   then show ?thesis by (simp add: tendsto_PInfty)
   508 qed
   508 qed
   509 
   509 
   510 text{* One would like to deduce the next lemma from the previous one, but the fact
   510 text\<open>One would like to deduce the next lemma from the previous one, but the fact
   511 that $-(x+y)$ is in general different from $(-x) + (-y)$ in ereal creates difficulties,
   511 that $-(x+y)$ is in general different from $(-x) + (-y)$ in ereal creates difficulties,
   512 so it is more efficient to copy the previous proof.*}
   512 so it is more efficient to copy the previous proof.\<close>
   513 
   513 
   514 lemma tendsto_add_ereal_MInf:
   514 lemma tendsto_add_ereal_MInf:
   515   fixes y :: ereal
   515   fixes y :: ereal
   516   assumes y: "y \<noteq> \<infinity>"
   516   assumes y: "y \<noteq> \<infinity>"
   517   assumes f: "(f \<longlongrightarrow> -\<infinity>) F" and g: "(g \<longlongrightarrow> y) F"
   517   assumes f: "(f \<longlongrightarrow> -\<infinity>) F" and g: "(g \<longlongrightarrow> y) F"
   572     using tendsto_add_ereal_general1[OF x, OF g, OF f] add.commute[of "y", of "x"] by simp
   572     using tendsto_add_ereal_general1[OF x, OF g, OF f] add.commute[of "y", of "x"] by simp
   573   moreover have "\<And>x. g x + f x = f x + g x" using add.commute by auto
   573   moreover have "\<And>x. g x + f x = f x + g x" using add.commute by auto
   574   ultimately show ?thesis by simp
   574   ultimately show ?thesis by simp
   575 qed
   575 qed
   576 
   576 
   577 text {* The next lemma says that the addition is continuous on ereal, except at
   577 text \<open>The next lemma says that the addition is continuous on ereal, except at
   578 the pairs $(-\infty, \infty)$ and $(\infty, -\infty)$. *}
   578 the pairs $(-\infty, \infty)$ and $(\infty, -\infty)$.\<close>
   579 
   579 
   580 lemma tendsto_add_ereal_general [tendsto_intros]:
   580 lemma tendsto_add_ereal_general [tendsto_intros]:
   581   fixes x y :: ereal
   581   fixes x y :: ereal
   582   assumes "\<not>((x=\<infinity> \<and> y=-\<infinity>) \<or> (x=-\<infinity> \<and> y=\<infinity>))"
   582   assumes "\<not>((x=\<infinity> \<and> y=-\<infinity>) \<or> (x=-\<infinity> \<and> y=\<infinity>))"
   583       and f: "(f \<longlongrightarrow> x) F" and g: "(g \<longlongrightarrow> y) F"
   583       and f: "(f \<longlongrightarrow> x) F" and g: "(g \<longlongrightarrow> y) F"
   594   case (MInf)
   594   case (MInf)
   595   then have "y \<noteq> \<infinity>" using assms by simp
   595   then have "y \<noteq> \<infinity>" using assms by simp
   596   then show ?thesis using tendsto_add_ereal_MInf MInf f g by (metis ereal_MInfty_eq_plus)
   596   then show ?thesis using tendsto_add_ereal_MInf MInf f g by (metis ereal_MInfty_eq_plus)
   597 qed
   597 qed
   598 
   598 
   599 subsubsection {*Continuity of multiplication*}
   599 subsubsection \<open>Continuity of multiplication\<close>
   600 
   600 
   601 text {* In the same way as for addition, we prove that the multiplication is continuous on
   601 text \<open>In the same way as for addition, we prove that the multiplication is continuous on
   602 ereal times ereal, except at $(\infty, 0)$ and $(-\infty, 0)$ and $(0, \infty)$ and $(0, -\infty)$,
   602 ereal times ereal, except at $(\infty, 0)$ and $(-\infty, 0)$ and $(0, \infty)$ and $(0, -\infty)$,
   603 starting with specific situations.*}
   603 starting with specific situations.\<close>
   604 
   604 
   605 lemma tendsto_mult_real_ereal:
   605 lemma tendsto_mult_real_ereal:
   606   assumes "(u \<longlongrightarrow> ereal l) F" "(v \<longlongrightarrow> ereal m) F"
   606   assumes "(u \<longlongrightarrow> ereal l) F" "(v \<longlongrightarrow> ereal m) F"
   607   shows "((\<lambda>n. u n * v n) \<longlongrightarrow> ereal l * ereal m) F"
   607   shows "((\<lambda>n. u n * v n) \<longlongrightarrow> ereal l * ereal m) F"
   608 proof -
   608 proof -
   629   fixes f g::"_ \<Rightarrow> ereal"
   629   fixes f g::"_ \<Rightarrow> ereal"
   630   assumes "(f \<longlongrightarrow> l) F" "l>0" "(g \<longlongrightarrow> \<infinity>) F"
   630   assumes "(f \<longlongrightarrow> l) F" "l>0" "(g \<longlongrightarrow> \<infinity>) F"
   631   shows "((\<lambda>x. f x * g x) \<longlongrightarrow> \<infinity>) F"
   631   shows "((\<lambda>x. f x * g x) \<longlongrightarrow> \<infinity>) F"
   632 proof -
   632 proof -
   633   obtain a::real where "0 < ereal a" "a < l" using assms(2) using ereal_dense2 by blast
   633   obtain a::real where "0 < ereal a" "a < l" using assms(2) using ereal_dense2 by blast
   634   have *: "eventually (\<lambda>x. f x > a) F" using `a < l` assms(1) by (simp add: order_tendsto_iff)
   634   have *: "eventually (\<lambda>x. f x > a) F" using \<open>a < l\<close> assms(1) by (simp add: order_tendsto_iff)
   635   {
   635   {
   636     fix K::real
   636     fix K::real
   637     define M where "M = max K 1"
   637     define M where "M = max K 1"
   638     then have "M > 0" by simp
   638     then have "M > 0" by simp
   639     then have "ereal(M/a) > 0" using `ereal a > 0` by simp
   639     then have "ereal(M/a) > 0" using \<open>ereal a > 0\<close> by simp
   640     then have "\<And>x. ((f x > a) \<and> (g x > M/a)) \<Longrightarrow> (f x * g x > ereal a * ereal(M/a))"
   640     then have "\<And>x. ((f x > a) \<and> (g x > M/a)) \<Longrightarrow> (f x * g x > ereal a * ereal(M/a))"
   641       using ereal_mult_mono_strict'[where ?c = "M/a", OF `0 < ereal a`] by auto
   641       using ereal_mult_mono_strict'[where ?c = "M/a", OF \<open>0 < ereal a\<close>] by auto
   642     moreover have "ereal a * ereal(M/a) = M" using `ereal a > 0` by simp
   642     moreover have "ereal a * ereal(M/a) = M" using \<open>ereal a > 0\<close> by simp
   643     ultimately have "\<And>x. ((f x > a) \<and> (g x > M/a)) \<Longrightarrow> (f x * g x > M)" by simp
   643     ultimately have "\<And>x. ((f x > a) \<and> (g x > M/a)) \<Longrightarrow> (f x * g x > M)" by simp
   644     moreover have "M \<ge> K" unfolding M_def by simp
   644     moreover have "M \<ge> K" unfolding M_def by simp
   645     ultimately have Imp: "\<And>x. ((f x > a) \<and> (g x > M/a)) \<Longrightarrow> (f x * g x > K)"
   645     ultimately have Imp: "\<And>x. ((f x > a) \<and> (g x > M/a)) \<Longrightarrow> (f x * g x > K)"
   646       using ereal_less_eq(3) le_less_trans by blast
   646       using ereal_less_eq(3) le_less_trans by blast
   647 
   647 
   672   qed
   672   qed
   673 next
   673 next
   674   assume "\<not>(l = \<infinity> \<or> m = \<infinity>)"
   674   assume "\<not>(l = \<infinity> \<or> m = \<infinity>)"
   675   then have "l < \<infinity>" "m < \<infinity>" by auto
   675   then have "l < \<infinity>" "m < \<infinity>" by auto
   676   then obtain lr mr where "l = ereal lr" "m = ereal mr"
   676   then obtain lr mr where "l = ereal lr" "m = ereal mr"
   677     using `l>0` `m>0` by (metis ereal_cases ereal_less(6) not_less_iff_gr_or_eq)
   677     using \<open>l>0\<close> \<open>m>0\<close> by (metis ereal_cases ereal_less(6) not_less_iff_gr_or_eq)
   678   then show ?thesis using tendsto_mult_real_ereal assms by auto
   678   then show ?thesis using tendsto_mult_real_ereal assms by auto
   679 qed
   679 qed
   680 
   680 
   681 text {*We reduce the general situation to the positive case by multiplying by suitable signs.
   681 text \<open>We reduce the general situation to the positive case by multiplying by suitable signs.
   682 Unfortunately, as ereal is not a ring, all the neat sign lemmas are not available there. We
   682 Unfortunately, as ereal is not a ring, all the neat sign lemmas are not available there. We
   683 give the bare minimum we need.*}
   683 give the bare minimum we need.\<close>
   684 
   684 
   685 lemma ereal_sgn_abs:
   685 lemma ereal_sgn_abs:
   686   fixes l::ereal
   686   fixes l::ereal
   687   shows "sgn(l) * l = abs(l)"
   687   shows "sgn(l) * l = abs(l)"
   688 apply (cases l) by (auto simp add: sgn_if ereal_less_uminus_reorder)
   688 apply (cases l) by (auto simp add: sgn_if ereal_less_uminus_reorder)
   718   ultimately have *: "((\<lambda>x. (sgn(l) * f x) * (sgn(m) * g x)) \<longlongrightarrow> (sgn(l) * l) * (sgn(m) * m)) F"
   718   ultimately have *: "((\<lambda>x. (sgn(l) * f x) * (sgn(m) * g x)) \<longlongrightarrow> (sgn(l) * l) * (sgn(m) * m)) F"
   719     using tendsto_mult_ereal_pos by force
   719     using tendsto_mult_ereal_pos by force
   720   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"
   720   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"
   721     by (rule tendsto_cmult_ereal, auto simp add: sgn_finite2 *)
   721     by (rule tendsto_cmult_ereal, auto simp add: sgn_finite2 *)
   722   moreover have "\<And>x. (sgn(l) * sgn(m)) * ((sgn(l) * f x) * (sgn(m) * g x)) = f x * g x"
   722   moreover have "\<And>x. (sgn(l) * sgn(m)) * ((sgn(l) * f x) * (sgn(m) * g x)) = f x * g x"
   723     by (metis mult.left_neutral sgn_squared_ereal[OF `l \<noteq> 0`] sgn_squared_ereal[OF `m \<noteq> 0`] mult.assoc mult.commute)
   723     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)
   724   moreover have "(sgn(l) * sgn(m)) * ((sgn(l) * l) * (sgn(m) * m)) = l * m"
   724   moreover have "(sgn(l) * sgn(m)) * ((sgn(l) * l) * (sgn(m) * m)) = l * m"
   725     by (metis mult.left_neutral sgn_squared_ereal[OF `l \<noteq> 0`] sgn_squared_ereal[OF `m \<noteq> 0`] mult.assoc mult.commute)
   725     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)
   726   ultimately show ?thesis by auto
   726   ultimately show ?thesis by auto
   727 qed
   727 qed
   728 
   728 
   729 lemma tendsto_cmult_ereal_general [tendsto_intros]:
   729 lemma tendsto_cmult_ereal_general [tendsto_intros]:
   730   fixes f::"_ \<Rightarrow> ereal" and c::ereal
   730   fixes f::"_ \<Rightarrow> ereal" and c::ereal
   731   assumes "(f \<longlongrightarrow> l) F" "\<not> (l=0 \<and> abs(c) = \<infinity>)"
   731   assumes "(f \<longlongrightarrow> l) F" "\<not> (l=0 \<and> abs(c) = \<infinity>)"
   732   shows "((\<lambda>x. c * f x) \<longlongrightarrow> c * l) F"
   732   shows "((\<lambda>x. c * f x) \<longlongrightarrow> c * l) F"
   733 by (cases "c = 0", auto simp add: assms tendsto_mult_ereal)
   733 by (cases "c = 0", auto simp add: assms tendsto_mult_ereal)
   734 
   734 
   735 
   735 
   736 subsubsection {*Continuity of division*}
   736 subsubsection \<open>Continuity of division\<close>
   737 
   737 
   738 lemma tendsto_inverse_ereal_PInf:
   738 lemma tendsto_inverse_ereal_PInf:
   739   fixes u::"_ \<Rightarrow> ereal"
   739   fixes u::"_ \<Rightarrow> ereal"
   740   assumes "(u \<longlongrightarrow> \<infinity>) F"
   740   assumes "(u \<longlongrightarrow> \<infinity>) F"
   741   shows "((\<lambda>x. 1/ u x) \<longlongrightarrow> 0) F"
   741   shows "((\<lambda>x. 1/ u x) \<longlongrightarrow> 0) F"
   745     have "1/e < \<infinity>" by auto
   745     have "1/e < \<infinity>" by auto
   746     then have "eventually (\<lambda>n. u n > 1/e) F" using assms(1) by (simp add: tendsto_PInfty)
   746     then have "eventually (\<lambda>n. u n > 1/e) F" using assms(1) by (simp add: tendsto_PInfty)
   747     moreover
   747     moreover
   748     {
   748     {
   749       fix z::ereal assume "z>1/e"
   749       fix z::ereal assume "z>1/e"
   750       then have "z>0" using `e>0` using less_le_trans not_le by fastforce
   750       then have "z>0" using \<open>e>0\<close> using less_le_trans not_le by fastforce
   751       then have "1/z \<ge> 0" by auto
   751       then have "1/z \<ge> 0" by auto
   752       moreover have "1/z < e" using `e>0` `z>1/e`
   752       moreover have "1/z < e" using \<open>e>0\<close> \<open>z>1/e\<close>
   753         apply (cases z) apply auto
   753         apply (cases z) apply auto
   754         by (metis (mono_tags, hide_lams) less_ereal.simps(2) less_ereal.simps(4) divide_less_eq ereal_divide_less_pos ereal_less(4)
   754         by (metis (mono_tags, hide_lams) less_ereal.simps(2) less_ereal.simps(4) divide_less_eq ereal_divide_less_pos ereal_less(4)
   755             ereal_less_eq(4) less_le_trans mult_eq_0_iff not_le not_one_less_zero times_ereal.simps(1))
   755             ereal_less_eq(4) less_le_trans mult_eq_0_iff not_le not_one_less_zero times_ereal.simps(1))
   756       ultimately have "1/z \<ge> 0" "1/z < e" by auto
   756       ultimately have "1/z \<ge> 0" "1/z < e" by auto
   757     }
   757     }
   763     then show "eventually (\<lambda>n. 1/u n > a) F" using *(2) eventually_mono less_le_trans linordered_field_no_ub by fastforce
   763     then show "eventually (\<lambda>n. 1/u n > a) F" using *(2) eventually_mono less_le_trans linordered_field_no_ub by fastforce
   764   next
   764   next
   765     fix a::ereal assume "a>0"
   765     fix a::ereal assume "a>0"
   766     then obtain e::real where "e>0" "a>e" using ereal_dense2 ereal_less(2) by blast
   766     then obtain e::real where "e>0" "a>e" using ereal_dense2 ereal_less(2) by blast
   767     then have "eventually (\<lambda>n. 1/u n < e) F" using *(1) by auto
   767     then have "eventually (\<lambda>n. 1/u n < e) F" using *(1) by auto
   768     then show "eventually (\<lambda>n. 1/u n < a) F" using `a>e` by (metis (mono_tags, lifting) eventually_mono less_trans)
   768     then show "eventually (\<lambda>n. 1/u n < a) F" using \<open>a>e\<close> by (metis (mono_tags, lifting) eventually_mono less_trans)
   769   qed
   769   qed
   770 qed
   770 qed
   771 
   771 
   772 text {* The next lemma deserves to exist by itself, as it is so common and useful. *}
   772 text \<open>The next lemma deserves to exist by itself, as it is so common and useful.\<close>
   773 
   773 
   774 lemma tendsto_inverse_real [tendsto_intros]:
   774 lemma tendsto_inverse_real [tendsto_intros]:
   775   fixes u::"_ \<Rightarrow> real"
   775   fixes u::"_ \<Rightarrow> real"
   776   shows "(u \<longlongrightarrow> l) F \<Longrightarrow> l \<noteq> 0 \<Longrightarrow> ((\<lambda>x. 1/ u x) \<longlongrightarrow> 1/l) F"
   776   shows "(u \<longlongrightarrow> l) F \<Longrightarrow> l \<noteq> 0 \<Longrightarrow> ((\<lambda>x. 1/ u x) \<longlongrightarrow> 1/l) F"
   777   using tendsto_inverse unfolding inverse_eq_divide .
   777   using tendsto_inverse unfolding inverse_eq_divide .
   834   moreover have "l * (1/m) = l/m" by (simp add: divide_ereal_def)
   834   moreover have "l * (1/m) = l/m" by (simp add: divide_ereal_def)
   835   ultimately show ?thesis unfolding h_def using Lim_transform_eventually by auto
   835   ultimately show ?thesis unfolding h_def using Lim_transform_eventually by auto
   836 qed
   836 qed
   837 
   837 
   838 
   838 
   839 subsubsection {*Further limits*}
   839 subsubsection \<open>Further limits\<close>
   840 
   840 
   841 lemma id_nat_ereal_tendsto_PInf [tendsto_intros]:
   841 lemma id_nat_ereal_tendsto_PInf [tendsto_intros]:
   842   "(\<lambda> n::nat. real n) \<longlonglongrightarrow> \<infinity>"
   842   "(\<lambda> n::nat. real n) \<longlonglongrightarrow> \<infinity>"
   843 by (simp add: filterlim_real_sequentially tendsto_PInfty_eq_at_top)
   843 by (simp add: filterlim_real_sequentially tendsto_PInfty_eq_at_top)
   844 
   844 
   858 
   858 
   859       have "N > C" if "u N \<ge> n" for N
   859       have "N > C" if "u N \<ge> n" for N
   860       proof (rule ccontr)
   860       proof (rule ccontr)
   861         assume "\<not>(N > C)"
   861         assume "\<not>(N > C)"
   862         have "u N \<le> Max {u n| n. n \<le> C}"
   862         have "u N \<le> Max {u n| n. n \<le> C}"
   863           apply (rule Max_ge) using `\<not>(N > C)` by auto
   863           apply (rule Max_ge) using \<open>\<not>(N > C)\<close> by auto
   864         then show False using `u N \<ge> n` `n \<ge> M` unfolding M_def by auto
   864         then show False using \<open>u N \<ge> n\<close> \<open>n \<ge> M\<close> unfolding M_def by auto
   865       qed
   865       qed
   866       then have **: "{N. u N \<ge> n} \<subseteq> {C..}" by fastforce
   866       then have **: "{N. u N \<ge> n} \<subseteq> {C..}" by fastforce
   867       have "Inf {N. u N \<ge> n} \<ge> C"
   867       have "Inf {N. u N \<ge> n} \<ge> C"
   868         by (metis "*" "**" Inf_nat_def1 atLeast_iff subset_eq)
   868         by (metis "*" "**" Inf_nat_def1 atLeast_iff subset_eq)
   869     }
   869     }
   979   moreover have "(\<lambda>n. (-1)* ereal(real n)) \<longlonglongrightarrow> -\<infinity>"
   979   moreover have "(\<lambda>n. (-1)* ereal(real n)) \<longlonglongrightarrow> -\<infinity>"
   980     using tendsto_cmult_ereal[of "-1", OF _ id_nat_ereal_tendsto_PInf] by (simp add: one_ereal_def)
   980     using tendsto_cmult_ereal[of "-1", OF _ id_nat_ereal_tendsto_PInf] by (simp add: one_ereal_def)
   981   ultimately show ?thesis using MInf by auto
   981   ultimately show ?thesis using MInf by auto
   982 qed (simp add: assms)
   982 qed (simp add: assms)
   983 
   983 
   984 text {* the next one is copied from \verb+tendsto_sum+. *}
   984 text \<open>the next one is copied from \verb+tendsto_sum+.\<close>
   985 lemma tendsto_sum_ereal [tendsto_intros]:
   985 lemma tendsto_sum_ereal [tendsto_intros]:
   986   fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> ereal"
   986   fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> ereal"
   987   assumes "\<And>i. i \<in> S \<Longrightarrow> (f i \<longlongrightarrow> a i) F"
   987   assumes "\<And>i. i \<in> S \<Longrightarrow> (f i \<longlongrightarrow> a i) F"
   988           "\<And>i. abs(a i) \<noteq> \<infinity>"
   988           "\<And>i. abs(a i) \<noteq> \<infinity>"
   989   shows "((\<lambda>x. \<Sum>i\<in>S. f i x) \<longlongrightarrow> (\<Sum>i\<in>S. a i)) F"
   989   shows "((\<lambda>x. \<Sum>i\<in>S. f i x) \<longlongrightarrow> (\<Sum>i\<in>S. a i)) F"
   990 proof (cases "finite S")
   990 proof (cases "finite S")
   991   assume "finite S" then show ?thesis using assms
   991   assume "finite S" then show ?thesis using assms
   992     by (induct, simp, simp add: tendsto_add_ereal_general2 assms)
   992     by (induct, simp, simp add: tendsto_add_ereal_general2 assms)
   993 qed(simp)
   993 qed(simp)
   994 
   994 
   995 subsubsection {*Limsups and liminfs*}
   995 subsubsection \<open>Limsups and liminfs\<close>
   996 
   996 
   997 lemma limsup_finite_then_bounded:
   997 lemma limsup_finite_then_bounded:
   998   fixes u::"nat \<Rightarrow> real"
   998   fixes u::"nat \<Rightarrow> real"
   999   assumes "limsup u < \<infinity>"
   999   assumes "limsup u < \<infinity>"
  1000   shows "\<exists>C. \<forall>n. u n \<le> C"
  1000   shows "\<exists>C. \<forall>n. u n \<le> C"
  1015       then show "u n \<le> D" unfolding D_def by linarith
  1015       then show "u n \<le> D" unfolding D_def by linarith
  1016     next
  1016     next
  1017       assume "\<not>(n \<le> N)"
  1017       assume "\<not>(n \<le> N)"
  1018       then have "n \<ge> N" by simp
  1018       then have "n \<ge> N" by simp
  1019       then have "u n < C" using N by auto
  1019       then have "u n < C" using N by auto
  1020       then have "u n < real_of_ereal C" using `C = ereal(real_of_ereal C)` less_ereal.simps(1) by fastforce
  1020       then have "u n < real_of_ereal C" using \<open>C = ereal(real_of_ereal C)\<close> less_ereal.simps(1) by fastforce
  1021       then show "u n \<le> D" unfolding D_def by linarith
  1021       then show "u n \<le> D" unfolding D_def by linarith
  1022     qed
  1022     qed
  1023   qed
  1023   qed
  1024   then show ?thesis by blast
  1024   then show ?thesis by blast
  1025 qed
  1025 qed
  1045       then show "u n \<ge> D" unfolding D_def by linarith
  1045       then show "u n \<ge> D" unfolding D_def by linarith
  1046     next
  1046     next
  1047       assume "\<not>(n \<le> N)"
  1047       assume "\<not>(n \<le> N)"
  1048       then have "n \<ge> N" by simp
  1048       then have "n \<ge> N" by simp
  1049       then have "u n > C" using N by auto
  1049       then have "u n > C" using N by auto
  1050       then have "u n > real_of_ereal C" using `C = ereal(real_of_ereal C)` less_ereal.simps(1) by fastforce
  1050       then have "u n > real_of_ereal C" using \<open>C = ereal(real_of_ereal C)\<close> less_ereal.simps(1) by fastforce
  1051       then show "u n \<ge> D" unfolding D_def by linarith
  1051       then show "u n \<ge> D" unfolding D_def by linarith
  1052     qed
  1052     qed
  1053   qed
  1053   qed
  1054   then show ?thesis by blast
  1054   then show ?thesis by blast
  1055 qed
  1055 qed
  1058   fixes u:: "nat \<Rightarrow> ereal"
  1058   fixes u:: "nat \<Rightarrow> ereal"
  1059   assumes "liminf u < l"
  1059   assumes "liminf u < l"
  1060   shows "\<exists>N>k. u N < l"
  1060   shows "\<exists>N>k. u N < l"
  1061 by (metis assms gt_ex less_le_trans liminf_bounded_iff not_less)
  1061 by (metis assms gt_ex less_le_trans liminf_bounded_iff not_less)
  1062 
  1062 
  1063 text {* The following statement about limsups is reduced to a statement about limits using
  1063 text \<open>The following statement about limsups is reduced to a statement about limits using
  1064 subsequences thanks to \verb+limsup_subseq_lim+. The statement for limits follows for instance from
  1064 subsequences thanks to \verb+limsup_subseq_lim+. The statement for limits follows for instance from
  1065 \verb+tendsto_add_ereal_general+.*}
  1065 \verb+tendsto_add_ereal_general+.\<close>
  1066 
  1066 
  1067 lemma ereal_limsup_add_mono:
  1067 lemma ereal_limsup_add_mono:
  1068   fixes u v::"nat \<Rightarrow> ereal"
  1068   fixes u v::"nat \<Rightarrow> ereal"
  1069   shows "limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v"
  1069   shows "limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v"
  1070 proof (cases)
  1070 proof (cases)
  1089   apply (metis (no_types, lifting) s(2) 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) t(2) a_def comp_assoc)
  1090   apply (metis (no_types, lifting) t(2) a_def comp_assoc)
  1091   done
  1091   done
  1092 
  1092 
  1093   have "limsup (u o r) \<le> limsup u" by (simp add: limsup_subseq_mono r(1))
  1093   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 `limsup u < \<infinity>` by auto
  1094   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)
  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   then have b: "limsup (v o r o s) \<noteq> \<infinity>" using `limsup v < \<infinity>` by auto
  1096   then have b: "limsup (v o r o s) \<noteq> \<infinity>" using \<open>limsup v < \<infinity>\<close> by auto
  1097 
  1097 
  1098   have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> limsup (u o r) + limsup (v o r o s)"
  1098   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
  1099     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
  1100   moreover have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto
  1101   ultimately have "(w o a) \<longlonglongrightarrow> limsup (u o r) + limsup (v o r o s)" by simp
  1101   ultimately have "(w o a) \<longlonglongrightarrow> limsup (u o r) + limsup (v o r o s)" by simp
  1102   then have "limsup w = limsup (u o r) + limsup (v o r o s)" using l(1) LIMSEQ_unique by blast
  1102   then have "limsup w = limsup (u o r) + limsup (v o r o s)" using l(1) LIMSEQ_unique by blast
  1103   then have "limsup w \<le> limsup u + limsup v"
  1103   then have "limsup w \<le> limsup u + limsup v"
  1104     using `limsup (u o r) \<le> limsup u` `limsup (v o r o s) \<le> limsup v` ereal_add_mono by simp
  1104     using \<open>limsup (u o r) \<le> limsup u\<close> \<open>limsup (v o r o s) \<le> limsup v\<close> ereal_add_mono by simp
  1105   then show ?thesis unfolding w_def by simp
  1105   then show ?thesis unfolding w_def by simp
  1106 qed
  1106 qed
  1107 
  1107 
  1108 text {* There is an asymmetry between liminfs and limsups in ereal, as $\infty + (-\infty) = \infty$.
  1108 text \<open>There is an asymmetry between liminfs and limsups in ereal, as $\infty + (-\infty) = \infty$.
  1109 This explains why there are more assumptions in the next lemma dealing with liminfs that in the
  1109 This explains why there are more assumptions in the next lemma dealing with liminfs that in the
  1110 previous one about limsups.*}
  1110 previous one about limsups.\<close>
  1111 
  1111 
  1112 lemma ereal_liminf_add_mono:
  1112 lemma ereal_liminf_add_mono:
  1113   fixes u v::"nat \<Rightarrow> ereal"
  1113   fixes u v::"nat \<Rightarrow> ereal"
  1114   assumes "\<not>((liminf u = \<infinity> \<and> liminf v = -\<infinity>) \<or> (liminf u = -\<infinity> \<and> liminf v = \<infinity>))"
  1114   assumes "\<not>((liminf u = \<infinity> \<and> liminf v = -\<infinity>) \<or> (liminf u = -\<infinity> \<and> liminf v = \<infinity>))"
  1115   shows "liminf (\<lambda>n. u n + v n) \<ge> liminf u + liminf v"
  1115   shows "liminf (\<lambda>n. u n + v n) \<ge> liminf u + liminf v"
  1135   apply (metis (no_types, lifting) s(2) 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)
  1136   apply (metis (no_types, lifting) t(2) a_def comp_assoc)
  1136   apply (metis (no_types, lifting) t(2) a_def comp_assoc)
  1137   done
  1137   done
  1138 
  1138 
  1139   have "liminf (u o r) \<ge> liminf u" by (simp add: liminf_subseq_mono r(1))
  1139   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 `liminf u > -\<infinity>` by auto
  1140   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)
  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)
  1142   then have b: "liminf (v o r o s) \<noteq> -\<infinity>" using `liminf v > -\<infinity>` by auto
  1142   then have b: "liminf (v o r o s) \<noteq> -\<infinity>" using \<open>liminf v > -\<infinity>\<close> by auto
  1143 
  1143 
  1144   have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> liminf (u o r) + liminf (v o r o s)"
  1144   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
  1145     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
  1146   moreover have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto
  1147   ultimately have "(w o a) \<longlonglongrightarrow> liminf (u o r) + liminf (v o r o s)" by simp
  1147   ultimately have "(w o a) \<longlonglongrightarrow> liminf (u o r) + liminf (v o r o s)" by simp
  1148   then have "liminf w = liminf (u o r) + liminf (v o r o s)" using l(1) LIMSEQ_unique by blast
  1148   then have "liminf w = liminf (u o r) + liminf (v o r o s)" using l(1) LIMSEQ_unique by blast
  1149   then have "liminf w \<ge> liminf u + liminf v"
  1149   then have "liminf w \<ge> liminf u + liminf v"
  1150     using `liminf (u o r) \<ge> liminf u` `liminf (v o r o s) \<ge> liminf v` ereal_add_mono by simp
  1150     using \<open>liminf (u o r) \<ge> liminf u\<close> \<open>liminf (v o r o s) \<ge> liminf v\<close> ereal_add_mono by simp
  1151   then show ?thesis unfolding w_def by simp
  1151   then show ?thesis unfolding w_def by simp
  1152 qed
  1152 qed
  1153 
  1153 
  1154 lemma ereal_limsup_lim_add:
  1154 lemma ereal_limsup_lim_add:
  1155   fixes u v::"nat \<Rightarrow> ereal"
  1155   fixes u v::"nat \<Rightarrow> ereal"
  1160   have "(\<lambda>n. -u n) \<longlonglongrightarrow> -a" using assms(1) by auto
  1160   have "(\<lambda>n. -u n) \<longlonglongrightarrow> -a" using assms(1) by auto
  1161   then have "limsup (\<lambda>n. -u n) = -a" using tendsto_iff_Liminf_eq_Limsup trivial_limit_at_top_linorder by blast
  1161   then have "limsup (\<lambda>n. -u n) = -a" using tendsto_iff_Liminf_eq_Limsup trivial_limit_at_top_linorder by blast
  1162 
  1162 
  1163   have "limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v"
  1163   have "limsup (\<lambda>n. u n + v n) \<le> limsup u + limsup v"
  1164     by (rule ereal_limsup_add_mono)
  1164     by (rule ereal_limsup_add_mono)
  1165   then have up: "limsup (\<lambda>n. u n + v n) \<le> a + limsup v" using `limsup u = a` by simp
  1165   then have up: "limsup (\<lambda>n. u n + v n) \<le> a + limsup v" using \<open>limsup u = a\<close> by simp
  1166 
  1166 
  1167   have a: "limsup (\<lambda>n. (u n + v n) + (-u n)) \<le> limsup (\<lambda>n. u n + v n) + limsup (\<lambda>n. -u n)"
  1167   have a: "limsup (\<lambda>n. (u n + v n) + (-u n)) \<le> limsup (\<lambda>n. u n + v n) + limsup (\<lambda>n. -u n)"
  1168     by (rule ereal_limsup_add_mono)
  1168     by (rule ereal_limsup_add_mono)
  1169   have "eventually (\<lambda>n. u n = ereal(real_of_ereal(u n))) sequentially" using assms
  1169   have "eventually (\<lambda>n. u n = ereal(real_of_ereal(u n))) sequentially" using assms
  1170     real_lim_then_eventually_real by auto
  1170     real_lim_then_eventually_real by auto
  1175   moreover have "\<And>n. u n + (-u n) = 0 \<Longrightarrow> u n + v n + (-u n) = v n"
  1175   moreover have "\<And>n. u n + (-u n) = 0 \<Longrightarrow> u n + v n + (-u n) = v n"
  1176     by (metis add.commute add.left_commute add.left_neutral)
  1176     by (metis add.commute add.left_commute add.left_neutral)
  1177   ultimately have "eventually (\<lambda>n. u n + v n + (-u n) = v n) sequentially"
  1177   ultimately have "eventually (\<lambda>n. u n + v n + (-u n) = v n) sequentially"
  1178     using eventually_mono by force
  1178     using eventually_mono by force
  1179   then have "limsup v = limsup (\<lambda>n. u n + v n + (-u n))" using Limsup_eq by force
  1179   then have "limsup v = limsup (\<lambda>n. u n + v n + (-u n))" using Limsup_eq by force
  1180   then have "limsup v \<le> limsup (\<lambda>n. u n + v n) -a" using a `limsup (\<lambda>n. -u n) = -a` by (simp add: minus_ereal_def)
  1180   then have "limsup v \<le> limsup (\<lambda>n. u n + v n) -a" using a \<open>limsup (\<lambda>n. -u n) = -a\<close> by (simp add: minus_ereal_def)
  1181   then have "limsup (\<lambda>n. u n + v n) \<ge> a + limsup v" using assms(2) by (metis add.commute ereal_le_minus)
  1181   then have "limsup (\<lambda>n. u n + v n) \<ge> a + limsup v" using assms(2) by (metis add.commute ereal_le_minus)
  1182   then show ?thesis using up by simp
  1182   then show ?thesis using up by simp
  1183 qed
  1183 qed
  1184 
  1184 
  1185 lemma ereal_limsup_lim_mult:
  1185 lemma ereal_limsup_lim_mult:
  1253   then have "liminf (\<lambda>n. -u n) = -a" using tendsto_iff_Liminf_eq_Limsup trivial_limit_at_top_linorder by blast
  1253   then have "liminf (\<lambda>n. -u n) = -a" using tendsto_iff_Liminf_eq_Limsup trivial_limit_at_top_linorder by blast
  1254   then have **: "abs(liminf (\<lambda>n. -u n)) \<noteq> \<infinity>" using assms(2) by auto
  1254   then have **: "abs(liminf (\<lambda>n. -u n)) \<noteq> \<infinity>" using assms(2) by auto
  1255 
  1255 
  1256   have "liminf (\<lambda>n. u n + v n) \<ge> liminf u + liminf v"
  1256   have "liminf (\<lambda>n. u n + v n) \<ge> liminf u + liminf v"
  1257     apply (rule ereal_liminf_add_mono) using * by auto
  1257     apply (rule ereal_liminf_add_mono) using * by auto
  1258   then have up: "liminf (\<lambda>n. u n + v n) \<ge> a + liminf v" using `liminf u = a` by simp
  1258   then have up: "liminf (\<lambda>n. u n + v n) \<ge> a + liminf v" using \<open>liminf u = a\<close> by simp
  1259 
  1259 
  1260   have a: "liminf (\<lambda>n. (u n + v n) + (-u n)) \<ge> liminf (\<lambda>n. u n + v n) + liminf (\<lambda>n. -u n)"
  1260   have a: "liminf (\<lambda>n. (u n + v n) + (-u n)) \<ge> liminf (\<lambda>n. u n + v n) + liminf (\<lambda>n. -u n)"
  1261     apply (rule ereal_liminf_add_mono) using ** by auto
  1261     apply (rule ereal_liminf_add_mono) using ** by auto
  1262   have "eventually (\<lambda>n. u n = ereal(real_of_ereal(u n))) sequentially" using assms
  1262   have "eventually (\<lambda>n. u n = ereal(real_of_ereal(u n))) sequentially" using assms
  1263     real_lim_then_eventually_real by auto
  1263     real_lim_then_eventually_real by auto
  1268   moreover have "\<And>n. u n + (-u n) = 0 \<Longrightarrow> u n + v n + (-u n) = v n"
  1268   moreover have "\<And>n. u n + (-u n) = 0 \<Longrightarrow> u n + v n + (-u n) = v n"
  1269     by (metis add.commute add.left_commute add.left_neutral)
  1269     by (metis add.commute add.left_commute add.left_neutral)
  1270   ultimately have "eventually (\<lambda>n. u n + v n + (-u n) = v n) sequentially"
  1270   ultimately have "eventually (\<lambda>n. u n + v n + (-u n) = v n) sequentially"
  1271     using eventually_mono by force
  1271     using eventually_mono by force
  1272   then have "liminf v = liminf (\<lambda>n. u n + v n + (-u n))" using Liminf_eq by force
  1272   then have "liminf v = liminf (\<lambda>n. u n + v n + (-u n))" using Liminf_eq by force
  1273   then have "liminf v \<ge> liminf (\<lambda>n. u n + v n) -a" using a `liminf (\<lambda>n. -u n) = -a` by (simp add: minus_ereal_def)
  1273   then have "liminf v \<ge> liminf (\<lambda>n. u n + v n) -a" using a \<open>liminf (\<lambda>n. -u n) = -a\<close> by (simp add: minus_ereal_def)
  1274   then have "liminf (\<lambda>n. u n + v n) \<le> a + liminf v" using assms(2) by (metis add.commute ereal_minus_le)
  1274   then have "liminf (\<lambda>n. u n + v n) \<le> a + liminf v" using assms(2) by (metis add.commute ereal_minus_le)
  1275   then show ?thesis using up by simp
  1275   then show ?thesis using up by simp
  1276 qed
  1276 qed
  1277 
  1277 
  1278 lemma ereal_liminf_limsup_add:
  1278 lemma ereal_liminf_limsup_add:
  1300   apply (metis (no_types, lifting) t(2) a_def comp_assoc)
  1300   apply (metis (no_types, lifting) t(2) a_def comp_assoc)
  1301   done
  1301   done
  1302 
  1302 
  1303   have "liminf (w o r) \<ge> liminf w" by (simp add: liminf_subseq_mono r(1))
  1303   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)
  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)
  1305   then have b: "limsup (v o r o s) < \<infinity>" using `limsup v < \<infinity>` by auto
  1305   then have b: "limsup (v o r o s) < \<infinity>" using \<open>limsup v < \<infinity>\<close> by auto
  1306 
  1306 
  1307   have "(\<lambda>n. (u o a) n + (v o a) n) \<longlonglongrightarrow> liminf u + limsup (v o r o s)"
  1307   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 `liminf u < \<infinity>` l(1) l(3) by force+
  1308     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
  1309   moreover have "(\<lambda>n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto
  1310   ultimately have "(w o a) \<longlonglongrightarrow> liminf u + limsup (v o r o s)" by simp
  1310   ultimately have "(w o a) \<longlonglongrightarrow> liminf u + limsup (v o r o s)" by simp
  1311   then have "liminf (w o r) = liminf u + limsup (v o r o s)" using l(2) using LIMSEQ_unique by blast
  1311   then have "liminf (w o r) = liminf u + limsup (v o r o s)" using l(2) using LIMSEQ_unique by blast
  1312   then have "liminf w \<le> liminf u + limsup v"
  1312   then have "liminf w \<le> liminf u + limsup v"
  1313     using `liminf (w o r) \<ge> liminf w` `limsup (v o r o s) \<le> limsup v`
  1313     using \<open>liminf (w o r) \<ge> liminf w\<close> \<open>limsup (v o r o s) \<le> limsup v\<close>
  1314     by (metis add_mono_thms_linordered_semiring(2) le_less_trans not_less)
  1314     by (metis add_mono_thms_linordered_semiring(2) le_less_trans not_less)
  1315   then show ?thesis unfolding w_def by simp
  1315   then show ?thesis unfolding w_def by simp
  1316 qed
  1316 qed
  1317 
  1317 
  1318 lemma ereal_liminf_limsup_minus:
  1318 lemma ereal_liminf_limsup_minus:
  1856   assumes "continuous_on {a..b} (f :: real \<Rightarrow> real)"
  1856   assumes "continuous_on {a..b} (f :: real \<Rightarrow> real)"
  1857   shows "set_borel_measurable borel {a..b} f"
  1857   shows "set_borel_measurable borel {a..b} f"
  1858   by (rule set_borel_measurable_continuous[OF _ assms]) simp
  1858   by (rule set_borel_measurable_continuous[OF _ assms]) simp
  1859 
  1859 
  1860 
  1860 
  1861 text{* This notation is from Sébastien Gouëzel: His use is not directly in line with the
  1861 text\<open>This notation is from Sébastien Gouëzel: His use is not directly in line with the
  1862 notations in this file, they are more in line with sum, and more readable he thinks. *}
  1862 notations in this file, they are more in line with sum, and more readable he thinks.\<close>
  1863 
  1863 
  1864 abbreviation "set_nn_integral M A f \<equiv> nn_integral M (\<lambda>x. f x * indicator A x)"
  1864 abbreviation "set_nn_integral M A f \<equiv> nn_integral M (\<lambda>x. f x * indicator A x)"
  1865 
  1865 
  1866 syntax
  1866 syntax
  1867 "_set_nn_integral" :: "pttrn => 'a set => 'a measure => ereal => ereal"
  1867 "_set_nn_integral" :: "pttrn => 'a set => 'a measure => ereal => ereal"
  1919   moreover have "(\<Sum>n. f x * indicator (B n) x) = f x * indicator (\<Union>n. B n) x" for x
  1919   moreover have "(\<Sum>n. f x * indicator (B n) x) = f x * indicator (\<Union>n. B n) x" for x
  1920   proof (cases)
  1920   proof (cases)
  1921     assume "x \<in> (\<Union>n. B n)"
  1921     assume "x \<in> (\<Union>n. B n)"
  1922     then obtain n where "x \<in> B n" by blast
  1922     then obtain n where "x \<in> B n" by blast
  1923     have a: "finite {n}" by simp
  1923     have a: "finite {n}" by simp
  1924     have "\<And>i. i \<noteq> n \<Longrightarrow> x \<notin> B i" using `x \<in> B n` assms(3) disjoint_family_on_def
  1924     have "\<And>i. i \<noteq> n \<Longrightarrow> x \<notin> B i" using \<open>x \<in> B n\<close> assms(3) disjoint_family_on_def
  1925       by (metis IntI UNIV_I empty_iff)
  1925       by (metis IntI UNIV_I empty_iff)
  1926     then have "\<And>i. i \<notin> {n} \<Longrightarrow> indicator (B i) x = (0::ennreal)" using indicator_def by simp
  1926     then have "\<And>i. i \<notin> {n} \<Longrightarrow> indicator (B i) x = (0::ennreal)" using indicator_def by simp
  1927     then have b: "\<And>i. i \<notin> {n} \<Longrightarrow> f x * indicator (B i) x = (0::ennreal)" by simp
  1927     then have b: "\<And>i. i \<notin> {n} \<Longrightarrow> f x * indicator (B i) x = (0::ennreal)" by simp
  1928 
  1928 
  1929     define h where "h = (\<lambda>i. f x * indicator (B i) x)"
  1929     define h where "h = (\<lambda>i. f x * indicator (B i) x)"
  1930     then have "\<And>i. i \<notin> {n} \<Longrightarrow> h i = 0" using b by simp
  1930     then have "\<And>i. i \<notin> {n} \<Longrightarrow> h i = 0" using b by simp
  1931     then have "(\<Sum>i. h i) = (\<Sum>i\<in>{n}. h i)"
  1931     then have "(\<Sum>i. h i) = (\<Sum>i\<in>{n}. h i)"
  1932       by (metis sums_unique[OF sums_finite[OF a]])
  1932       by (metis sums_unique[OF sums_finite[OF a]])
  1933     then have "(\<Sum>i. h i) = h n" by simp
  1933     then have "(\<Sum>i. h i) = h n" by simp
  1934     then have "(\<Sum>n. f x * indicator (B n) x) = f x * indicator (B n) x" using h_def by simp
  1934     then have "(\<Sum>n. f x * indicator (B n) x) = f x * indicator (B n) x" using h_def by simp
  1935     then have "(\<Sum>n. f x * indicator (B n) x) = f x" using `x \<in> B n` indicator_def by simp
  1935     then have "(\<Sum>n. f x * indicator (B n) x) = f x" using \<open>x \<in> B n\<close> indicator_def by simp
  1936     then show ?thesis using `x \<in> (\<Union>n. B n)` by auto
  1936     then show ?thesis using \<open>x \<in> (\<Union>n. B n)\<close> by auto
  1937   next
  1937   next
  1938     assume "x \<notin> (\<Union>n. B n)"
  1938     assume "x \<notin> (\<Union>n. B n)"
  1939     then have "\<And>n. f x * indicator (B n) x = 0" by simp
  1939     then have "\<And>n. f x * indicator (B n) x = 0" by simp
  1940     have "(\<Sum>n. f x * indicator (B n) x) = 0"
  1940     have "(\<Sum>n. f x * indicator (B n) x) = 0"
  1941       by (simp add: `\<And>n. f x * indicator (B n) x = 0`)
  1941       by (simp add: \<open>\<And>n. f x * indicator (B n) x = 0\<close>)
  1942     then show ?thesis using `x \<notin> (\<Union>n. B n)` by auto
  1942     then show ?thesis using \<open>x \<notin> (\<Union>n. B n)\<close> by auto
  1943   qed
  1943   qed
  1944   ultimately show ?thesis by simp
  1944   ultimately show ?thesis by simp
  1945 qed
  1945 qed
  1946 
  1946 
  1947 lemma nn_set_integral_add:
  1947 lemma nn_set_integral_add:
  2033       and "AE x\<in>A in M. f x > 0" "(\<integral>x\<in>A. f x \<partial>M) = (0::real)"
  2033       and "AE x\<in>A in M. f x > 0" "(\<integral>x\<in>A. f x \<partial>M) = (0::real)"
  2034   shows "A \<in> null_sets M"
  2034   shows "A \<in> null_sets M"
  2035 proof -
  2035 proof -
  2036   have "AE x in M. indicator A x * f x = 0"
  2036   have "AE x in M. indicator A x * f x = 0"
  2037     apply (subst integral_nonneg_eq_0_iff_AE[symmetric])
  2037     apply (subst integral_nonneg_eq_0_iff_AE[symmetric])
  2038     using assms integrable_mult_indicator[OF `A \<in> sets M` assms(1)] by auto
  2038     using assms integrable_mult_indicator[OF \<open>A \<in> sets M\<close> assms(1)] by auto
  2039   then have "AE x\<in>A in M. f x = 0" by auto
  2039   then have "AE x\<in>A in M. f x = 0" by auto
  2040   then have "AE x\<in>A in M. False" using assms(3) by auto
  2040   then have "AE x\<in>A in M. False" using assms(3) by auto
  2041   then show "A \<in> null_sets M" using assms(2) by (simp add: AE_iff_null_sets)
  2041   then show "A \<in> null_sets M" using assms(2) by (simp add: AE_iff_null_sets)
  2042 qed
  2042 qed
  2043 
  2043 
  2044 text{*The next lemma is a variant of \<open>density_unique\<close>. Note that it uses the notation
  2044 text\<open>The next lemma is a variant of \<open>density_unique\<close>. Note that it uses the notation
  2045 for nonnegative set integrals introduced earlier.*}
  2045 for nonnegative set integrals introduced earlier.\<close>
  2046 
  2046 
  2047 lemma (in sigma_finite_measure) density_unique2:
  2047 lemma (in sigma_finite_measure) density_unique2:
  2048   assumes [measurable]: "f \<in> borel_measurable M" "f' \<in> borel_measurable M"
  2048   assumes [measurable]: "f \<in> borel_measurable M" "f' \<in> borel_measurable M"
  2049   assumes density_eq: "\<And>A. A \<in> sets M \<Longrightarrow> (\<integral>\<^sup>+ x \<in> A. f x \<partial>M) = (\<integral>\<^sup>+ x \<in> A. f' x \<partial>M)"
  2049   assumes density_eq: "\<And>A. A \<in> sets M \<Longrightarrow> (\<integral>\<^sup>+ x \<in> A. f x \<partial>M) = (\<integral>\<^sup>+ x \<in> A. f' x \<partial>M)"
  2050   shows "AE x in M. f x = f' x"
  2050   shows "AE x in M. f x = f' x"
  2052   show "density M f = density M f'"
  2052   show "density M f = density M f'"
  2053     by (intro measure_eqI) (auto simp: emeasure_density intro!: density_eq)
  2053     by (intro measure_eqI) (auto simp: emeasure_density intro!: density_eq)
  2054 qed (auto simp add: assms)
  2054 qed (auto simp add: assms)
  2055 
  2055 
  2056 
  2056 
  2057 text {* The next lemma implies the same statement for Banach-space valued functions
  2057 text \<open>The next lemma implies the same statement for Banach-space valued functions
  2058 using Hahn-Banach theorem and linear forms. Since they are not yet easily available, I
  2058 using Hahn-Banach theorem and linear forms. Since they are not yet easily available, I
  2059 only formulate it for real-valued functions.*}
  2059 only formulate it for real-valued functions.\<close>
  2060 
  2060 
  2061 lemma density_unique_real:
  2061 lemma density_unique_real:
  2062   fixes f f'::"_ \<Rightarrow> real"
  2062   fixes f f'::"_ \<Rightarrow> real"
  2063   assumes [measurable]: "integrable M f" "integrable M f'"
  2063   assumes [measurable]: "integrable M f" "integrable M f'"
  2064   assumes density_eq: "\<And>A. A \<in> sets M \<Longrightarrow> (\<integral>x \<in> A. f x \<partial>M) = (\<integral>x \<in> A. f' x \<partial>M)"
  2064   assumes density_eq: "\<And>A. A \<in> sets M \<Longrightarrow> (\<integral>x \<in> A. f x \<partial>M) = (\<integral>x \<in> A. f' x \<partial>M)"
  2065   shows "AE x in M. f x = f' x"
  2065   shows "AE x in M. f x = f' x"
  2066 proof -
  2066 proof -
  2067   define A where "A = {x \<in> space M. f x < f' x}"
  2067   define A where "A = {x \<in> space M. f x < f' x}"
  2068   then have [measurable]: "A \<in> sets M" by simp
  2068   then have [measurable]: "A \<in> sets M" by simp
  2069   have "(\<integral>x \<in> A. (f' x - f x) \<partial>M) = (\<integral>x \<in> A. f' x \<partial>M) - (\<integral>x \<in> A. f x \<partial>M)"
  2069   have "(\<integral>x \<in> A. (f' x - f x) \<partial>M) = (\<integral>x \<in> A. f' x \<partial>M) - (\<integral>x \<in> A. f x \<partial>M)"
  2070     using `A \<in> sets M` assms(1) assms(2) integrable_mult_indicator by blast
  2070     using \<open>A \<in> sets M\<close> assms(1) assms(2) integrable_mult_indicator by blast
  2071   then have "(\<integral>x \<in> A. (f' x - f x) \<partial>M) = 0" using assms(3) by simp
  2071   then have "(\<integral>x \<in> A. (f' x - f x) \<partial>M) = 0" using assms(3) by simp
  2072   then have "A \<in> null_sets M"
  2072   then have "A \<in> null_sets M"
  2073     using A_def null_if_pos_func_has_zero_int[where ?f = "\<lambda>x. f' x - f x" and ?A = A] assms by auto
  2073     using A_def null_if_pos_func_has_zero_int[where ?f = "\<lambda>x. f' x - f x" and ?A = A] assms by auto
  2074   then have "AE x in M. x \<notin> A" by (simp add: AE_not_in)
  2074   then have "AE x in M. x \<notin> A" by (simp add: AE_not_in)
  2075   then have *: "AE x in M. f' x \<le> f x" unfolding A_def by auto
  2075   then have *: "AE x in M. f' x \<le> f x" unfolding A_def by auto
  2076 
  2076 
  2077 
  2077 
  2078   define B where "B = {x \<in> space M. f' x < f x}"
  2078   define B where "B = {x \<in> space M. f' x < f x}"
  2079   then have [measurable]: "B \<in> sets M" by simp
  2079   then have [measurable]: "B \<in> sets M" by simp
  2080   have "(\<integral>x \<in> B. (f x - f' x) \<partial>M) = (\<integral>x \<in> B. f x \<partial>M) - (\<integral>x \<in> B. f' x \<partial>M)"
  2080   have "(\<integral>x \<in> B. (f x - f' x) \<partial>M) = (\<integral>x \<in> B. f x \<partial>M) - (\<integral>x \<in> B. f' x \<partial>M)"
  2081     using `B \<in> sets M` assms(1) assms(2) integrable_mult_indicator by blast
  2081     using \<open>B \<in> sets M\<close> assms(1) assms(2) integrable_mult_indicator by blast
  2082   then have "(\<integral>x \<in> B. (f x - f' x) \<partial>M) = 0" using assms(3) by simp
  2082   then have "(\<integral>x \<in> B. (f x - f' x) \<partial>M) = 0" using assms(3) by simp
  2083   then have "B \<in> null_sets M"
  2083   then have "B \<in> null_sets M"
  2084     using B_def null_if_pos_func_has_zero_int[where ?f = "\<lambda>x. f x - f' x" and ?A = B] assms by auto
  2084     using B_def null_if_pos_func_has_zero_int[where ?f = "\<lambda>x. f x - f' x" and ?A = B] assms by auto
  2085   then have "AE x in M. x \<notin> B" by (simp add: AE_not_in)
  2085   then have "AE x in M. x \<notin> B" by (simp add: AE_not_in)
  2086   then have "AE x in M. f' x \<ge> f x" unfolding B_def by auto
  2086   then have "AE x in M. f' x \<ge> f x" unfolding B_def by auto
  2087 
  2087 
  2088   then show ?thesis using * by auto
  2088   then show ?thesis using * by auto
  2089 qed
  2089 qed
  2090 
  2090 
  2091 text {* The next lemma shows that $L^1$ convergence of a sequence of functions follows from almost
  2091 text \<open>The next lemma shows that $L^1$ convergence of a sequence of functions follows from almost
  2092 everywhere convergence and the weaker condition of the convergence of the integrated norms (or even
  2092 everywhere convergence and the weaker condition of the convergence of the integrated norms (or even
  2093 just the nontrivial inequality about them). Useful in a lot of contexts! This statement (or its
  2093 just the nontrivial inequality about them). Useful in a lot of contexts! This statement (or its
  2094 variations) are known as Scheffe lemma.
  2094 variations) are known as Scheffe lemma.
  2095 
  2095 
  2096 The formalization is more painful as one should jump back and forth between reals and ereals and justify
  2096 The formalization is more painful as one should jump back and forth between reals and ereals and justify
  2097 all the time positivity or integrability (thankfully, measurability is handled more or less automatically).*}
  2097 all the time positivity or integrability (thankfully, measurability is handled more or less automatically).\<close>
  2098 
  2098 
  2099 lemma Scheffe_lemma1:
  2099 lemma Scheffe_lemma1:
  2100   assumes "\<And>n. integrable M (F n)" "integrable M f"
  2100   assumes "\<And>n. integrable M (F n)" "integrable M f"
  2101           "AE x in M. (\<lambda>n. F n x) \<longlonglongrightarrow> f x"
  2101           "AE x in M. (\<lambda>n. F n x) \<longlonglongrightarrow> f x"
  2102           "limsup (\<lambda>n. \<integral>\<^sup>+ x. norm(F n x) \<partial>M) \<le> (\<integral>\<^sup>+ x. norm(f x) \<partial>M)"
  2102           "limsup (\<lambda>n. \<integral>\<^sup>+ x. norm(F n x) \<partial>M) \<le> (\<integral>\<^sup>+ x. norm(f x) \<partial>M)"