diff --git a/thys/Ergodic_Theory/SG_Library_Complement.thy b/thys/Ergodic_Theory/SG_Library_Complement.thy --- a/thys/Ergodic_Theory/SG_Library_Complement.thy +++ b/thys/Ergodic_Theory/SG_Library_Complement.thy @@ -1,2782 +1,2759 @@ (* Author: Sébastien Gouëzel sebastien.gouezel@univ-rennes1.fr License: BSD *) theory SG_Library_Complement -imports Complex_Main Topological_Spaces "~~/src/HOL/Multivariate_Analysis/Extended_Real_Limits" +imports Complex_Main Topological_Spaces "~~/src/HOL/Multivariate_Analysis/Extended_Real_Limits" "~~/src/HOL/Probability/Probability_Measure" "~~/src/HOL/Probability/Set_Integral" begin section {*SG Libary complements*} text {* In this file are included many statements that were useful to me, but belong rather naturally to existing theories. In a perfect world, some of these statements would get included into these files. I tried to indicate to which of these classical theories the statements could be added. *} subsection {*Basic logic*} text {* This one is certainly available, but I could not locate it... *} lemma equiv_neg: "\ P \ Q; \P \ \Q \ \ (P\Q)" by blast subsection {*Basic set theory*} abbreviation sym_diff :: "'a set \ 'a set \ 'a set" (infixl "\" 70) where "sym_diff A B \ ((A - B) \ (B-A))" text {* Not sure the next lemmas are useful, as they are proved solely by auto, so they could be reproved automatically whenever necessary.*} lemma sym_diff_inc: "A \ C \ A \ B \ B \ C" by auto lemma sym_diff_vimage [simp]: "f-`(A \ B) = (f-`A) \ (f-`B)" by auto subsection {*Set-Interval.thy*} text{* The next two lemmas belong naturally to \verb+Set_Interval.thy+, next to \verb+UN_le_add_shift+. They are not trivially equivalent to the corresponding lemmas with large inequalities, due to the difference when $n=0$. *} lemma UN_le_add_shift_strict: "(\ii\{k.. ?A" proof fix x assume "x \ ?B" then obtain i where i: "i \ {k.. M(i)" by auto hence "i - k < n \ x \ M((i-k) + k)" by auto thus "x \ ?A" using UN_le_add_shift by blast qed qed (fastforce) lemma UN_le_eq_Un0_strict: "(\ii\{1.. M 0" (is "?A = ?B") proof show "?A \ ?B" proof fix x assume "x \ ?A" then obtain i where i: "i M i" by auto show "x \ ?B" proof(cases i) case 0 with i show ?thesis by simp next case (Suc j) with i show ?thesis by auto qed qed qed (auto) text {* I use repeatedly this one, but I could not find it directly *} lemma union_insert_0: "(\n::nat. A n) = A 0 \ (\n\{1..}. A n)" by (metis UN_insert Un_insert_left sup_bot.left_neutral One_nat_def atLeast_0 atLeast_Suc_greaterThan ivl_disj_un_singleton(1)) text {*Next one could be close to \verb+setsum_nat_group+*} lemma setsum_arith_progression: "(\r<(N::nat). (\ijr j \ {i*N..riiri j \ {i*N..j 0" assumes "P 1" assumes "\n. n > 0 \ P n \ P (Suc n)" shows "P n" proof - have "(n = 0) \ P n" proof (induction n) case 0 thus ?case by auto next case (Suc k) { assume "Suc k = 1" hence ?case using assms(2) by auto } also { assume "Suc k > 1" then have "k > 0" by auto then have ?case using Suc.IH assms(3) by auto } ultimately show ?case by arith qed then show ?thesis using assms(1) by auto qed lemma Inf_nat_def0: fixes K::"nat set" assumes "n\K" "\ i. i i\K" shows "Inf K = n" using assms cInf_eq_minimum not_less by blast lemma Inf_nat_def1: fixes K::"nat set" assumes "K \ {}" shows "Inf K \ K" by (auto simp add: Min_def Inf_nat_def) (meson LeastI assms bot.extremum_unique subsetI) text{* This lemma is certainly available somewhere, but I couldn't locate it *} lemma tends_to_real_e: fixes u::"nat \ real" assumes "u \ l" "e>0" shows "\N. \n>N. abs(u n -l ) < e" proof- have "eventually (\n. dist (u n) l < e) sequentially" using assms tendstoD by auto hence "\\<^sub>F n in sequentially. abs(u n - l) < e" using dist_real_def by auto thus ?thesis by (simp add: eventually_at_top_dense) qed lemma nat_mod_cong: assumes "a=b+(c::nat)" "a mod n = b mod n" shows "c mod n = 0" proof - let ?k = "a mod n" obtain a1 where "a = a1*n + ?k" by (metis mod_div_equality) moreover obtain b1 where "b = b1*n + ?k" using assms(2) by (metis mod_div_equality) ultimately have "a1 * n + ?k = b1 * n + ?k + c" using assms(1) by arith then have "c = (a1 - b1) * n" by (simp add: diff_mult_distrib) then show ?thesis by simp qed text {*The next two lemmas are not directly equivalent, since $f$ might not be injective.*} lemma abs_Max_sum: fixes A::"real set" assumes "finite A" "A \ {}" shows "abs(Max A) \ (\a\A. abs(a))" using assms by (induct rule: finite_ne_induct, auto) lemma abs_Max_sum2: fixes f::"_ \ real" assumes "finite A" "A \ {}" shows "abs(Max (f`A)) \ (\a\A. abs(f a))" using assms by (induct rule: finite_ne_induct, auto) subsection {*Topological-spaces.thy*} lemma open_diagonal_complement: "open {(x,y) | x y. x \ (y::('a::t2_space))}" -proof (rule openI) +proof (rule topological_space_class.openI) fix t assume "t \ {(x, y) | x y. x \ (y::'a)}" then obtain x y where "t = (x,y)" "x \ y" by blast then obtain U V where *: "open U \ open V \ x \ U \ y \ V \ U \ V = {}" by (auto simp add: separation_t2) def T \ "U \ V" have "open T" using * open_Times T_def by auto moreover have "t \ T" unfolding T_def using `t = (x,y)` * by auto moreover have "T \ {(x, y) | x y. x \ y}" unfolding T_def using * by auto ultimately show "\T. open T \ t \ T \ T \ {(x, y) | x y. x \ y}" by auto qed lemma closed_diagonal: "closed {y. \ x::('a::t2_space). y = (x,x)}" proof - have "{y. \ x::'a. y = (x,x)} = UNIV - {(x,y) | x y. x \ y}" by auto then show ?thesis using open_diagonal_complement closed_Diff by auto qed lemma open_superdiagonal: "open {(x,y) | x y. x > (y::'a::{linorder_topology})}" -proof (rule openI) +proof (rule topological_space_class.openI) fix t assume "t \ {(x, y) | x y. y < (x::'a)}" then obtain x y where "t = (x, y)" "x > y" by blast show "\T. open T \ t \ T \ T \ {(x, y) | x y. y < x}" proof (cases) assume "\z. y < z \ z < x" then obtain z where z: "y < z \ z < x" by blast def T \ "{z<..} \ {.. T" using T_def z `t = (x,y)` by auto moreover have "T \ {(x, y) | x y. y < x}" unfolding T_def by auto ultimately show ?thesis by auto next assume "\(\z. y < z \ z < x)" then have *: "{x ..} = {y<..}" "{..< x} = {..y}" using `x > y` apply auto using leI by blast def T \ "{x ..} \ {.. y}" then have "T = {y<..} \ {..< x}" using * by simp then have "open T" unfolding T_def by (simp add: open_Times) moreover have "t \ T" using T_def `t = (x,y)` by auto moreover have "T \ {(x, y) | x y. y < x}" unfolding T_def using `x > y` by auto ultimately show ?thesis by auto qed qed lemma closed_subdiagonal: "closed {(x,y) | x y. x \ (y::'a::{linorder_topology})}" proof - have " {(x,y) | x y. x \ (y::'a)} = UNIV - {(x,y) | x y. x > (y::'a)}" by auto then show ?thesis using open_superdiagonal closed_Diff by auto qed lemma open_subdiagonal: "open {(x,y) | x y. x < (y::'a::{linorder_topology})}" -proof (rule openI) +proof (rule topological_space_class.openI) fix t assume "t \ {(x, y) | x y. y > (x::'a)}" then obtain x y where "t = (x, y)" "x < y" by blast show "\T. open T \ t \ T \ T \ {(x, y) | x y. y > x}" proof (cases) assume "\z. y > z \ z > x" then obtain z where z: "y > z \ z > x" by blast def T \ "{.. {z<..}" have "open T" unfolding T_def by (simp add: open_Times) moreover have "t \ T" using T_def z `t = (x,y)` by auto moreover have "T \ {(x, y) |x y. y > x}" unfolding T_def by auto ultimately show ?thesis by auto next assume "\(\z. y > z \ z > x)" then have *: "{..x} = {.. "{..x} \ {y..}" then have "T = {.. {x<..}" using * by simp then have "open T" unfolding T_def by (simp add: open_Times) moreover have "t \ T" using T_def `t = (x,y)` by auto moreover have "T \ {(x, y) |x y. y > x}" unfolding T_def using `x < y` by auto ultimately show ?thesis by auto qed qed lemma closed_superdiagonal: "closed {(x,y) | x y. x \ (y::('a::{linorder_topology}))}" proof - have " {(x,y) | x y. x \ (y::'a)} = UNIV - {(x,y) | x y. x < y}" by auto then show ?thesis using open_subdiagonal closed_Diff by auto qed text {*The next statements come from the same statements for true subsequences*} lemma eventually_weak_subseq: fixes u::"nat \ nat" assumes "(\n. real(u n)) \ \" "eventually P sequentially" shows "eventually (\n. P (u n)) sequentially" proof - obtain N where *: "\n\N. P n" using assms(2) unfolding eventually_sequentially by auto obtain M where "\m\M. ereal(u m) \ N" using assms(1) by (meson Lim_PInfty) then have "\m. m \ M \ u m \ N" by auto then have "\m. m \ M \ P(u m)" using `\n\N. P n` by simp then show ?thesis unfolding eventually_sequentially by auto qed lemma filterlim_weak_subseq: fixes u::"nat \ nat" assumes "(\n. real(u n)) \ \" shows "LIM n sequentially. u n:> at_top" unfolding filterlim_iff by (metis assms eventually_weak_subseq) lemma limit_along_weak_subseq: fixes u::"nat \ nat" and v::"nat \ _" assumes "(\n. real(u n)) \ \" "v \ l" shows "(\ n. v(u n)) \ l" using filterlim_compose[of v, OF _ filterlim_weak_subseq] assms by auto subsection {*Series*} text {*The next lemma is a more natural reformulation of \verb+ suminf_exist_split+*} context fixes f :: "nat \ 'a::real_normed_vector" begin lemma suminf_exist_split2: assumes "summable f" shows "(\n. (\k. f(k+n))) \ 0" by (subst lim_sequentially, auto simp add: dist_norm suminf_exist_split[OF _ assms]) end subsection {*Limits*} text {* The next lemma deserves to exist by itself, as it is so common and useful. Note that it is not a direct consequence of \verb+tendsto_inverse+, contrary to what might think at first...*} lemma tendsto_inverse_real [tendsto_intros]: fixes u::"_ \ real" assumes "(u \ l) F" "l \ 0" shows "((\x. 1/ u x) \ 1/l) F" by (rule tendsto_divide[OF _ assms, where ?f = "\_. 1" and ?a = 1], auto) text {*The next lemmas are not very natural, but I needed them several times*} lemma tendsto_shift_1_over_n: fixes f::"nat \ real" assumes "(\n. f n / n) \ l" shows "(\n. f (n+k) / n) \ l" proof - have "(1+k*(1/n))* (f(n+k)/(n+k)) = f(n+k)/n" if "n>0" for n using that by (auto simp add: divide_simps) with eventually_mono[OF eventually_gt_at_top[of "0::nat"] this] have "eventually (\n.(1+k*(1/n))* (f(n+k)/(n+k)) = f(n+k)/n) sequentially" by auto moreover have "(\n. (1+k*(1/n))* (f(n+k)/(n+k))) \ (1+real k*0) * l" apply (rule tendsto_mult) apply (rule tendsto_add, simp, rule tendsto_mult, simp, simp add: lim_1_over_n) apply (rule LIMSEQ_ignore_initial_segment[OF assms, of k]) done ultimately show ?thesis using Lim_transform_eventually by auto qed lemma tendsto_shift_1_over_n': fixes f::"nat \ real" assumes "(\n. f n / n) \ l" shows "(\n. f (n-k) / n) \ l" proof - have "(1-k*(1/(n+k)))* (f n/ n) = f n/(n+k)" if "n>0" for n using that by (auto simp add: divide_simps) with eventually_mono[OF eventually_gt_at_top[of "0::nat"] this] have "eventually (\n. (1-k*(1/(n+k)))* (f n/ n) = f n/(n+k)) sequentially" by auto moreover have "(\n. (1-k*(1/(n+k)))* (f n/ n)) \ (1-real k*0) * l" apply (rule tendsto_mult) apply (rule tendsto_diff, simp, rule tendsto_mult, simp, rule LIMSEQ_ignore_initial_segment[OF lim_1_over_n, of k]) apply (simp add: assms) done ultimately have "(\n. f n / (n+k)) \ l" using Lim_transform_eventually by auto then have a: "(\n. f(n-k)/(n-k+k)) \ l" using seq_offset_neg by auto - have "f(n-k)/(n-k+k) = f(n-k)/n" - if "n>k" for n using that by auto - with eventually_mono[OF eventually_gt_at_top[of k] this] - have "eventually (\n. f(n-k)/(n-k+k) = f(n-k)/n) sequentially" - by auto - with Lim_transform_eventually[OF this a] - show ?thesis by auto + have "f(n-k)/(n-k+k) = f(n-k)/n" + if "n>k" for n using that by auto + with eventually_mono[OF eventually_gt_at_top[of k] this] + have "eventually (\n. f(n-k)/(n-k+k) = f(n-k)/n) sequentially" + by auto + with Lim_transform_eventually[OF this a] + show ?thesis by auto qed subsection {*Topology-Euclidean-Space*} lemma countable_separating_set_linorder1: shows "\B::('a::{linorder_topology, second_countable_topology} set). countable B \ (\x y. x < y \ (\b \ B. x < b \ b \ y))" proof - obtain A::"'a set set" where "countable A" "topological_basis A" using ex_countable_basis by auto def B1 \ "{(LEAST x. x \ U)| U. U \ A}" then have "countable B1" using `countable A` by (simp add: simple_image) def B2 \ "{(SOME x. x \ U)| U. U \ A}" then have "countable B2" using `countable A` by (simp add: simple_image) - have "\x y. x < y \ (\b \ B1 \ B2. x < b \ b \ y)" - proof - - fix x y::'a assume "x < y" - show "\b \ B1 \ B2. x < b \ b \ y" - proof (cases) - assume "\z. x < z \ z < y" - then obtain z where z: "x < z \ z < y" by auto - def U \ "{x<.. U" using z U_def by simp - ultimately obtain "V" where "V \ A" "z \ V" "V \ U" using topological_basisE[OF `topological_basis A`] by auto - def w \ "(SOME x. x \ V)" - then have "w \ V" using `z \ V` by (metis someI2) - then have "x < w \ w \ y" using `w \ V` `V \ U` U_def by fastforce - moreover have "w \ B1 \ B2" using w_def B2_def `V \ A` by auto - ultimately show ?thesis by auto - next - assume "\(\z. x < z \ z < y)" - then have *: "\z. z > x \ z \ y" by auto - def U \ "{x<..}" - then have "open U" by simp - moreover have "y \ U" using `x < y` U_def by simp - ultimately obtain "V" where "V \ A" "y \ V" "V \ U" using topological_basisE[OF `topological_basis A`] by auto - have "U = {y..}" unfolding U_def using * `x < y` by auto - then have "V \ {y..}" using `V \ U` by simp - then have "(LEAST w. w \ V) = y" using `y \ V` by (meson Least_equality atLeast_iff subsetCE) - then have "y \ B1 \ B2" using `V \ A` B1_def by auto - moreover have "x < y \ y \ y" using `x < y` by simp - ultimately show ?thesis by auto - qed + have "\b \ B1 \ B2. x < b \ b \ y" if "x < y" for x y + proof (cases) + assume "\z. x < z \ z < y" + then obtain z where z: "x < z \ z < y" by auto + def U \ "{x<.. U" using z U_def by simp + ultimately obtain "V" where "V \ A" "z \ V" "V \ U" using topological_basisE[OF `topological_basis A`] by auto + def w \ "(SOME x. x \ V)" + then have "w \ V" using `z \ V` by (metis someI2) + then have "x < w \ w \ y" using `w \ V` `V \ U` U_def by fastforce + moreover have "w \ B1 \ B2" using w_def B2_def `V \ A` by auto + ultimately show ?thesis by auto + next + assume "\(\z. x < z \ z < y)" + then have *: "\z. z > x \ z \ y" by auto + def U \ "{x<..}" + then have "open U" by simp + moreover have "y \ U" using `x < y` U_def by simp + ultimately obtain "V" where "V \ A" "y \ V" "V \ U" using topological_basisE[OF `topological_basis A`] by auto + have "U = {y..}" unfolding U_def using * `x < y` by auto + then have "V \ {y..}" using `V \ U` by simp + then have "(LEAST w. w \ V) = y" using `y \ V` by (meson Least_equality atLeast_iff subsetCE) + then have "y \ B1 \ B2" using `V \ A` B1_def by auto + moreover have "x < y \ y \ y" using `x < y` by simp + ultimately show ?thesis by auto qed moreover have "countable (B1 \ B2)" using `countable B1` `countable B2` by simp ultimately show ?thesis by auto qed lemma countable_separating_set_linorder2: shows "\B::('a::{linorder_topology, second_countable_topology} set). countable B \ (\x y. x < y \ (\b \ B. x \ b \ b < y))" proof - obtain A::"'a set set" where "countable A" "topological_basis A" using ex_countable_basis by auto def B1 \ "{(GREATEST x. x \ U) | U. U \ A}" then have "countable B1" using `countable A` by (simp add: simple_image) def B2 \ "{(SOME x. x \ U)| U. U \ A}" then have "countable B2" using `countable A` by (simp add: simple_image) - have "\x y. x < y \ (\b \ B1 \ B2. x \ b \ b < y)" - proof - - fix x y::'a assume "x < y" - show "\b \ B1 \ B2. x \ b \ b < y" - proof (cases) - assume "\z. x < z \ z < y" - then obtain z where z: "x < z \ z < y" by auto - def U \ "{x<.. U" using z U_def by simp - ultimately obtain "V" where "V \ A" "z \ V" "V \ U" using topological_basisE[OF `topological_basis A`] by auto - def w \ "(SOME x. x \ V)" - then have "w \ V" using `z \ V` by (metis someI2) - then have "x \ w \ w < y" using `w \ V` `V \ U` U_def by fastforce - moreover have "w \ B1 \ B2" using w_def B2_def `V \ A` by auto - ultimately show ?thesis by auto - next - assume "\(\z. x < z \ z < y)" - then have *: "\z. z < y \ z \ x" using leI by blast - def U \ "{.. U" using `x < y` U_def by simp - ultimately obtain "V" where "V \ A" "x \ V" "V \ U" using topological_basisE[OF `topological_basis A`] by auto - have "U = {..x}" unfolding U_def using * `x < y` by auto - then have "V \ {..x}" using `V \ U` by simp - then have "(GREATEST x. x \ V) = x" using `x \ V` by (meson Greatest_equality atMost_iff subsetCE) - then have "x \ B1 \ B2" using `V \ A` B1_def by auto - moreover have "x \ x \ x < y" using `x < y` by simp - ultimately show ?thesis by auto - qed + have "\b \ B1 \ B2. x \ b \ b < y" if "x < y" for x y + proof (cases) + assume "\z. x < z \ z < y" + then obtain z where z: "x < z \ z < y" by auto + def U \ "{x<.. U" using z U_def by simp + ultimately obtain "V" where "V \ A" "z \ V" "V \ U" using topological_basisE[OF `topological_basis A`] by auto + def w \ "(SOME x. x \ V)" + then have "w \ V" using `z \ V` by (metis someI2) + then have "x \ w \ w < y" using `w \ V` `V \ U` U_def by fastforce + moreover have "w \ B1 \ B2" using w_def B2_def `V \ A` by auto + ultimately show ?thesis by auto + next + assume "\(\z. x < z \ z < y)" + then have *: "\z. z < y \ z \ x" using leI by blast + def U \ "{.. U" using `x < y` U_def by simp + ultimately obtain "V" where "V \ A" "x \ V" "V \ U" using topological_basisE[OF `topological_basis A`] by auto + have "U = {..x}" unfolding U_def using * `x < y` by auto + then have "V \ {..x}" using `V \ U` by simp + then have "(GREATEST x. x \ V) = x" using `x \ V` by (meson Greatest_equality atMost_iff subsetCE) + then have "x \ B1 \ B2" using `V \ A` B1_def by auto + moreover have "x \ x \ x < y" using `x < y` by simp + ultimately show ?thesis by auto qed moreover have "countable (B1 \ B2)" using `countable B1` `countable B2` by simp ultimately show ?thesis by auto qed subsection {*Liminf-Limsup.thy*} lemma limsup_shift: "limsup (\n. u (n+1)) = limsup u" proof - { fix n have "(SUP m:{n+1..}. u m) = (SUP m:{n..}. u (m + 1))" apply (rule SUP_eq) using Suc_le_D by (auto) } then have a: "(INF n. SUP m:{n..}. u (m + 1)) = (INF n. (SUP m:{n+1..}. u m))" by auto have b: "(INF n. (SUP m:{n+1..}. u m)) = (INF n:{1..}. (SUP m:{n..}. u m))" apply (rule INF_eq) using Suc_le_D by (auto) { fix v::"nat \ 'a" assume "decseq v" have "(INF n:{1..}. v n) = (INF n. v n)" apply (rule INF_eq) using `decseq v` decseq_Suc_iff by auto } moreover have "decseq (\n. (SUP m:{n..}. u m))" by (simp add: SUP_subset_mono decseq_def) ultimately have c: "(INF n:{1..}. (SUP m:{n..}. u m)) = (INF n. (SUP m:{n..}. u m))" by simp have "(INF n. SUPREMUM {n..} u) = (INF n. SUP m:{n..}. u (m + 1))" using a b c by simp then show ?thesis by (auto cong: limsup_INF_SUP) qed lemma limsup_shift_k: "limsup (\n. u (n+k)) = limsup u" proof (induction k) case (Suc k) have "limsup (\n. u (n+k+1)) = limsup (\n. u (n+k))" using limsup_shift[where ?u="\n. u(n+k)"] by simp then show ?case using Suc.IH by simp qed (auto) lemma liminf_shift: "liminf (\n. u (n+1)) = liminf u" proof - { fix n have "(INF m:{n+1..}. u m) = (INF m:{n..}. u (m + 1))" apply (rule INF_eq) using Suc_le_D by (auto) } then have a: "(SUP n. INF m:{n..}. u (m + 1)) = (SUP n. (INF m:{n+1..}. u m))" by auto have b: "(SUP n. (INF m:{n+1..}. u m)) = (SUP n:{1..}. (INF m:{n..}. u m))" apply (rule SUP_eq) using Suc_le_D by (auto) { fix v::"nat \ 'a" assume "incseq v" have "(SUP n:{1..}. v n) = (SUP n. v n)" apply (rule SUP_eq) using `incseq v` incseq_Suc_iff by auto } moreover have "incseq (\n. (INF m:{n..}. u m))" by (simp add: INF_superset_mono mono_def) ultimately have c: "(SUP n:{1..}. (INF m:{n..}. u m)) = (SUP n. (INF m:{n..}. u m))" by simp have "(SUP n. INFIMUM {n..} u) = (SUP n. INF m:{n..}. u (m + 1))" using a b c by simp then show ?thesis by (auto cong: liminf_SUP_INF) qed lemma liminf_shift_k: "liminf (\n. u (n+k)) = liminf u" proof (induction k) case (Suc k) have "liminf (\n. u (n+k+1)) = liminf (\n. u (n+k))" using liminf_shift[where ?u="\n. u(n+k)"] by simp then show ?case using Suc.IH by simp qed (auto) lemma Limsup_obtain: fixes u::"_ \ 'a :: complete_linorder" assumes "Limsup F u > c" shows "\i. u i > c" proof - have "(INF P:{P. eventually P F}. SUP x:{x. P x}. u x) > c" using assms by (simp add: Limsup_def) then show ?thesis by (metis eventually_True mem_Collect_eq less_INF_D less_SUP_iff) qed lemma Liminf_obtain: fixes u::"_ \ 'a :: complete_linorder" assumes "Liminf F u < c" shows "\i. u i < c" proof - have "(SUP P:{P. eventually P F}. INF x:{x. P x}. u x) < c" using assms by (simp add: Liminf_def) then show ?thesis by (metis eventually_True mem_Collect_eq SUP_lessD INF_less_iff) qed lemma Limsup_eventually_bounded: assumes "eventually (\x. u x \ l) F" shows "Limsup F u \ l" unfolding Limsup_def using assms by (simp add: INF_lower2 SUP_le_iff) lemma Liminf_eventually_bounded: assumes "eventually (\x. u x \ l) F" shows "Liminf F u \ l" unfolding Liminf_def using assms by (simp add: SUP_upper2 le_INF_iff) text {* The next lemma is extremely useful, as it often makes it possible to reduce statements about limsups to statements about limits.*} lemma limsup_subseq_lim: fixes u::"nat \ 'a :: {complete_linorder, linorder_topology}" shows "\r. subseq r \ (u o r) \ limsup u" proof (cases) assume "\n. \p>n. \m\p. u m \ u p" then have "\r. \n. (\m\r n. u m \ u (r n)) \ r n < r (Suc n)" by (intro dependent_nat_choice) (auto simp: conj_commute) then obtain r where "subseq r" and mono: "\n m. r n \ m \ u m \ u (r n)" by (auto simp: subseq_Suc_iff) def umax \ "\n. (SUP m:{n..}. u m)" have "decseq umax" unfolding umax_def by (simp add: SUP_subset_mono antimono_def) then have "umax \ limsup u" unfolding umax_def by (metis LIMSEQ_INF limsup_INF_SUP) then have *: "(umax o r) \ limsup u" by (simp add: LIMSEQ_subseq_LIMSEQ `subseq r`) have "\n. umax(r n) = u(r n)" unfolding umax_def using mono by (metis SUP_le_iff antisym atLeast_def mem_Collect_eq order_refl) then have "umax o r = u o r" unfolding o_def by simp then have "(u o r) \ limsup u" using * by simp then show ?thesis using `subseq r` by blast next assume "\ (\n. \p>n. (\m\p. u m \ u p))" then obtain N where N: "\p. p > N \ \m>p. u p < u m" by (force simp: not_le le_less) have "\r. \n. N < r n \ r n < r (Suc n) \ (\i\ {N<..r (Suc n)}. u i \ u (r (Suc n)))" proof (rule dependent_nat_choice) fix x assume "N < x" then have a: "finite {N<..x}" "{N<..x} \ {}" by simp_all have "Max {u i |i. i \ {N<..x}} \ {u i |i. i \ {N<..x}}" apply (rule Max_in) using a by (auto) then obtain p where "p \ {N<..x}" and upmax: "u p = Max{u i |i. i \ {N<..x}}" by auto def U \ "{m. m > p \ u p < u m}" have "U \ {}" unfolding U_def using N[of p] `p \ {N<..x}` by auto def y \ "Inf U" then have "y \ U" using `U \ {}` by (simp add: Inf_nat_def1) have a: "\i. i \ {N<..x} \ u i \ u p" proof - fix i assume "i \ {N<..x}" then have "u i \ {u i |i. i \ {N<..x}}" by blast then show "u i \ u p" using upmax by simp qed moreover have "u p < u y" using `y \ U` U_def by auto ultimately have "y \ {N<..x}" using not_le by blast moreover have "y > N" using `y \ U` U_def `p \ {N<..x}` by auto ultimately have "y > x" by auto have "\i. i \ {N<..y} \ u i \ u y" proof - fix i assume "i \ {N<..y}" show "u i \ u y" proof (cases) assume "i = y" then show ?thesis by simp next assume "\(i=y)" then have i:"i \ {N<.. {N<..y}` by simp have "u i \ u p" proof (cases) assume "i \ x" then have "i \ {N<..x}" using i by simp then show ?thesis using a by simp next assume "\(i \ x)" then have "i > x" by simp then have *: "i > p" using `p \ {N<..x}` by simp have "i < Inf U" using i y_def by simp then have "i \ U" using Inf_nat_def not_less_Least by auto then show ?thesis using U_def * by auto qed then show "u i \ u y" using `u p < u y` by auto qed qed then have "N < y \ x < y \ (\i\{N<..y}. u i \ u y)" using `y > x` `y > N` by auto then show "\y>N. x < y \ (\i\{N<..y}. u i \ u y)" by auto qed (auto) then obtain r where r: "\n. N < r n \ r n < r (Suc n) \ (\i\ {N<..r (Suc n)}. u i \ u (r (Suc n)))" by auto have "subseq r" using r by (auto simp: subseq_Suc_iff) have "incseq (u o r)" unfolding o_def using r by (simp add: incseq_SucI order.strict_implies_order) then have "(u o r) \ (SUP n. (u o r) n)" using LIMSEQ_SUP by blast then have "limsup (u o r) = (SUP n. (u o r) n)" by (simp add: lim_imp_Limsup) moreover have "limsup (u o r) \ limsup u" using `subseq r` by (simp add: limsup_subseq_mono) ultimately have "(SUP n. (u o r) n) \ limsup u" by simp { fix i assume i: "i \ {N<..}" obtain n where "i < r (Suc n)" using `subseq r` using Suc_le_eq seq_suble by blast then have "i \ {N<..r(Suc n)}" using i by simp then have "u i \ u (r(Suc n))" using r by simp then have "u i \ (SUP n. (u o r) n)" unfolding o_def by (meson SUP_upper2 UNIV_I) } then have "(SUP i:{N<..}. u i) \ (SUP n. (u o r) n)" using SUP_least by blast then have "limsup u \ (SUP n. (u o r) n)" unfolding Limsup_def by (metis (mono_tags, lifting) INF_lower2 atLeast_Suc_greaterThan atLeast_def eventually_ge_at_top mem_Collect_eq) then have "limsup u = (SUP n. (u o r) n)" using `(SUP n. (u o r) n) \ limsup u` by simp then have "(u o r) \ limsup u" using `(u o r) \ (SUP n. (u o r) n)` by simp then show ?thesis using `subseq r` by auto qed lemma liminf_subseq_lim: fixes u::"nat \ 'a :: {complete_linorder, linorder_topology}" shows "\r. subseq r \ (u o r) \ liminf u" proof (cases) assume "\n. \p>n. \m\p. u m \ u p" then have "\r. \n. (\m\r n. u m \ u (r n)) \ r n < r (Suc n)" by (intro dependent_nat_choice) (auto simp: conj_commute) then obtain r where "subseq r" and mono: "\n m. r n \ m \ u m \ u (r n)" by (auto simp: subseq_Suc_iff) def umin \ "\n. (INF m:{n..}. u m)" have "incseq umin" unfolding umin_def by (simp add: INF_superset_mono incseq_def) then have "umin \ liminf u" unfolding umin_def by (metis LIMSEQ_SUP liminf_SUP_INF) then have *: "(umin o r) \ liminf u" by (simp add: LIMSEQ_subseq_LIMSEQ `subseq r`) have "\n. umin(r n) = u(r n)" unfolding umin_def using mono by (metis le_INF_iff antisym atLeast_def mem_Collect_eq order_refl) then have "umin o r = u o r" unfolding o_def by simp then have "(u o r) \ liminf u" using * by simp then show ?thesis using `subseq r` by blast next assume "\ (\n. \p>n. (\m\p. u m \ u p))" then obtain N where N: "\p. p > N \ \m>p. u p > u m" by (force simp: not_le le_less) have "\r. \n. N < r n \ r n < r (Suc n) \ (\i\ {N<..r (Suc n)}. u i \ u (r (Suc n)))" proof (rule dependent_nat_choice) fix x assume "N < x" then have a: "finite {N<..x}" "{N<..x} \ {}" by simp_all have "Min {u i |i. i \ {N<..x}} \ {u i |i. i \ {N<..x}}" apply (rule Min_in) using a by (auto) then obtain p where "p \ {N<..x}" and upmin: "u p = Min{u i |i. i \ {N<..x}}" by auto def U \ "{m. m > p \ u p > u m}" have "U \ {}" unfolding U_def using N[of p] `p \ {N<..x}` by auto def y \ "Inf U" then have "y \ U" using `U \ {}` by (simp add: Inf_nat_def1) have a: "\i. i \ {N<..x} \ u i \ u p" proof - fix i assume "i \ {N<..x}" then have "u i \ {u i |i. i \ {N<..x}}" by blast then show "u i \ u p" using upmin by simp qed moreover have "u p > u y" using `y \ U` U_def by auto ultimately have "y \ {N<..x}" using not_le by blast moreover have "y > N" using `y \ U` U_def `p \ {N<..x}` by auto ultimately have "y > x" by auto have "\i. i \ {N<..y} \ u i \ u y" proof - fix i assume "i \ {N<..y}" show "u i \ u y" proof (cases) assume "i = y" then show ?thesis by simp next assume "\(i=y)" then have i:"i \ {N<.. {N<..y}` by simp have "u i \ u p" proof (cases) assume "i \ x" then have "i \ {N<..x}" using i by simp then show ?thesis using a by simp next assume "\(i \ x)" then have "i > x" by simp then have *: "i > p" using `p \ {N<..x}` by simp have "i < Inf U" using i y_def by simp then have "i \ U" using Inf_nat_def not_less_Least by auto then show ?thesis using U_def * by auto qed then show "u i \ u y" using `u p > u y` by auto qed qed then have "N < y \ x < y \ (\i\{N<..y}. u i \ u y)" using `y > x` `y > N` by auto then show "\y>N. x < y \ (\i\{N<..y}. u i \ u y)" by auto qed (auto) then obtain r where r: "\n. N < r n \ r n < r (Suc n) \ (\i\ {N<..r (Suc n)}. u i \ u (r (Suc n)))" by auto have "subseq r" using r by (auto simp: subseq_Suc_iff) have "decseq (u o r)" unfolding o_def using r by (simp add: decseq_SucI order.strict_implies_order) then have "(u o r) \ (INF n. (u o r) n)" using LIMSEQ_INF by blast then have "liminf (u o r) = (INF n. (u o r) n)" by (simp add: lim_imp_Liminf) moreover have "liminf (u o r) \ liminf u" using `subseq r` by (simp add: liminf_subseq_mono) ultimately have "(INF n. (u o r) n) \ liminf u" by simp { fix i assume i: "i \ {N<..}" obtain n where "i < r (Suc n)" using `subseq r` using Suc_le_eq seq_suble by blast then have "i \ {N<..r(Suc n)}" using i by simp then have "u i \ u (r(Suc n))" using r by simp then have "u i \ (INF n. (u o r) n)" unfolding o_def by (meson INF_lower2 UNIV_I) } then have "(INF i:{N<..}. u i) \ (INF n. (u o r) n)" using INF_greatest by blast then have "liminf u \ (INF n. (u o r) n)" unfolding Liminf_def by (metis (mono_tags, lifting) SUP_upper2 atLeast_Suc_greaterThan atLeast_def eventually_ge_at_top mem_Collect_eq) then have "liminf u = (INF n. (u o r) n)" using `(INF n. (u o r) n) \ liminf u` by simp then have "(u o r) \ liminf u" using `(u o r) \ (INF n. (u o r) n)` by simp then show ?thesis using `subseq r` by auto qed subsection {*Extended-Real.thy*} text{* The proof of this one is copied from \verb+ereal_add_mono+. *} lemma ereal_add_strict_mono2: fixes a b c d :: ereal assumes "a < b" and "c < d" shows "a + c < b + d" using assms apply (cases a) apply (cases rule: ereal3_cases[of b c d], auto) apply (cases rule: ereal3_cases[of b c d], auto) done text {* The next ones are analogues of \verb+mult_mono+ and \verb+mult_mono'+ in ereal.*} lemma ereal_mult_mono: fixes a b c d::ereal assumes "b \ 0" "c \ 0" "a \ b" "c \ d" shows "a * c \ b * d" by (metis ereal_mult_right_mono mult.commute order_trans assms) lemma ereal_mult_mono': fixes a b c d::ereal assumes "a \ 0" "c \ 0" "a \ b" "c \ d" shows "a * c \ b * d" by (metis ereal_mult_right_mono mult.commute order_trans assms) lemma ereal_mult_mono_strict: fixes a b c d::ereal assumes "b > 0" "c > 0" "a < b" "c < d" shows "a * c < b * d" proof - have "c < \" using `c < d` by auto then have "a * c < b * c" by (metis ereal_mult_strict_left_mono[OF assms(3) assms(2)] mult.commute) moreover have "b * c \ b * d" using assms(2) assms(4) by (simp add: assms(1) ereal_mult_left_mono less_imp_le) ultimately show ?thesis by simp qed lemma ereal_mult_mono_strict': fixes a b c d::ereal assumes "a > 0" "c > 0" "a < b" "c < d" shows "a * c < b * d" apply (rule ereal_mult_mono_strict, auto simp add: assms) using assms by auto lemma ereal_ineq_diff_add: assumes "b \ (-\::ereal)" "a \ b" shows "a = b + (a-b)" by (metis add.commute assms(1) assms(2) ereal_eq_minus_iff ereal_minus_le_iff ereal_plus_eq_PInfty) lemma ereal_abs_add: fixes a b::ereal shows "abs(a+b) \ abs a + abs b" by (cases rule: ereal2_cases[of a b]) (auto) lemma ereal_abs_diff: fixes a b::ereal shows "abs(a-b) \ abs a + abs b" by (cases rule: ereal2_cases[of a b]) (auto) lemma setsum_constant_ereal: fixes a::ereal shows "(\i\I. a) = a * card I" proof (cases "finite I", induct set: finite, simp_all) fix x :: 'a and F :: "'a set" have "\n. 0 \ real n" by linarith moreover have "(0::real) \ 1" by auto moreover have "\x0. (x0::real) + 1 = 1 + x0" by auto ultimately show "a + a * ereal (real (card F)) = a * ereal (1 + real (card F))" by (metis ereal_less_eq(5) ereal_plus_1(1) ereal_right_distrib one_ereal_def times_ereal_1) qed lemma real_lim_then_eventually_real: assumes "(u \ ereal l) F" shows "eventually (\n. u n = ereal(real_of_ereal(u n))) F" proof - have "ereal l \ {-\<..<(\::ereal)}" by simp moreover have "open {-\<..<(\::ereal)}" by simp ultimately have "eventually (\n. u n \ {-\<..<(\::ereal)}) F" using assms tendsto_def by blast moreover have "\x. x \ {-\<..<(\::ereal)} \ x = ereal(real_of_ereal x)" using ereal_real by auto ultimately show ?thesis by (metis (mono_tags, lifting) eventually_mono) qed subsubsection {*Continuity of addition*} text {*The next few lemmas remove an unnecessary assumption in \verb+tendsto_add_ereal+, culminating in \verb+tendsto_add_ereal_general+ which essentially says that the addition is continuous on ereal times ereal, except at $(-\infty, \infty)$ and $(\infty, -\infty)$. It is much more convenient in many situations, see for instance the proof of \verb+tendsto_setsum_ereal+ below. *} lemma tendsto_add_ereal_PInf: fixes y :: ereal assumes y: "y \ -\" assumes f: "(f \ \) F" and g: "(g \ y) F" shows "((\x. f x + g x) \ \) F" proof - have "\C. eventually (\x. g x > ereal C) F" proof (cases y) case (real r) have "y > y-1" using y real by (simp add: ereal_between(1)) hence "eventually (\x. g x > y - 1) F" using g y order_tendsto_iff by auto moreover have "y-1 = ereal(real_of_ereal(y-1))" by (metis real ereal_eq_1(1) ereal_minus(1) real_of_ereal.simps(1)) ultimately have "eventually (\x. g x > ereal(real_of_ereal(y - 1))) F" by simp thus ?thesis by auto next case (PInf) have "eventually (\x. g x > ereal 0) F" using g PInf by (simp add: tendsto_PInfty) thus ?thesis by auto qed (simp add: y) then obtain C::real where ge: "eventually (\x. g x > ereal C) F" by auto { fix M::real have "eventually (\x. f x > ereal(M - C)) F" using f by (simp add: tendsto_PInfty) hence "eventually (\x. (f x > ereal (M-C)) \ (g x > ereal C)) F" by (auto simp add: ge eventually_conj_iff) moreover have "\x. ((f x > ereal (M-C)) \ (g x > ereal C)) \ (f x + g x > ereal M)" using ereal_add_strict_mono2 by fastforce ultimately have "eventually (\x. f x + g x > ereal M) F" using eventually_mono by force } thus ?thesis by (simp add: tendsto_PInfty) qed text{* One would like to deduce the next lemma from the previous one, but the fact that $-(x+y)$ is in general different from $(-x) + (-y)$ in ereal creates difficulties, so it is more efficient to copy the previous proof.*} lemma tendsto_add_ereal_MInf: fixes y :: ereal assumes y: "y \ \" assumes f: "(f \ -\) F" and g: "(g \ y) F" shows "((\x. f x + g x) \ -\) F" proof - have "\C. eventually (\x. g x < ereal C) F" proof (cases y) case (real r) have "y < y+1" using y real by (simp add: ereal_between(1)) hence "eventually (\x. g x < y + 1) F" using g y order_tendsto_iff by force moreover have "y+1 = ereal( real_of_ereal (y+1))" by (simp add: real) ultimately have "eventually (\x. g x < ereal(real_of_ereal(y + 1))) F" by simp thus ?thesis by auto next case (MInf) have "eventually (\x. g x < ereal 0) F" using g MInf by (simp add: tendsto_MInfty) thus ?thesis by auto qed (simp add: y) then obtain C::real where ge: "eventually (\x. g x < ereal C) F" by auto { fix M::real have "eventually (\x. f x < ereal(M - C)) F" using f by (simp add: tendsto_MInfty) hence "eventually (\x. (f x < ereal (M- C)) \ (g x < ereal C)) F" by (auto simp add: ge eventually_conj_iff) moreover have "\x. ((f x < ereal (M-C)) \ (g x < ereal C)) \ (f x + g x < ereal M)" using ereal_add_strict_mono2 by fastforce ultimately have "eventually (\x. f x + g x < ereal M) F" using eventually_mono by force } thus ?thesis by (simp add: tendsto_MInfty) qed lemma tendsto_add_ereal_general1: fixes x y :: ereal assumes y: "\y\ \ \" assumes f: "(f \ x) F" and g: "(g \ y) F" shows "((\x. f x + g x) \ x + y) F" proof (cases x) case (real r) have a: "\x\ \ \" by (simp add: real) show ?thesis by (rule tendsto_add_ereal[OF a, OF y, OF f, OF g]) next case PInf thus ?thesis using tendsto_add_ereal_PInf assms by force next case MInf thus ?thesis using tendsto_add_ereal_MInf assms by (metis abs_ereal.simps(3) ereal_MInfty_eq_plus) qed lemma tendsto_add_ereal_general2: fixes x y :: ereal assumes x: "\x\ \ \" and f: "(f \ x) F" and g: "(g \ y) F" shows "((\x. f x + g x) \ x + y) F" proof - have "((\x. g x + f x) \ x + y) F" using tendsto_add_ereal_general1[OF x, OF g, OF f] add.commute[of "y", of "x"] by simp moreover have "\x. g x + f x = f x + g x" using add.commute by auto ultimately show ?thesis by simp qed text {* The next lemma says that the addition is continuous on ereal, except at the pairs $(-\infty, \infty)$ and $(\infty, -\infty)$. *} lemma tendsto_add_ereal_general: fixes x y :: ereal assumes "\((x=\ \ y=-\) \ (x=-\ \ y=\))" and f: "(f \ x) F" and g: "(g \ y) F" shows "((\x. f x + g x) \ x + y) F" proof (cases x) case (real r) show ?thesis apply (rule tendsto_add_ereal_general2) using real assms by auto next case (PInf) then have "y \ -\" using assms by simp then show ?thesis using tendsto_add_ereal_PInf PInf assms by auto next case (MInf) then have "y \ \" using assms by simp then show ?thesis using tendsto_add_ereal_MInf MInf f g by (metis ereal_MInfty_eq_plus) qed subsubsection {*Continuity of multiplication*} text {* In the same way as for addition, we prove that the multiplication is continuous on ereal times ereal, except at $(\infty, 0)$ and $(-\infty, 0)$ and $(0, \infty)$ and $(0, -\infty)$, starting with specific situations.*} lemma tendsto_mult_real_ereal: assumes "(u \ ereal l) F" "(v \ ereal m) F" shows "((\n. u n * v n) \ ereal l * ereal m) F" proof - have ureal: "eventually (\n. u n = ereal(real_of_ereal(u n))) F" by (rule real_lim_then_eventually_real[OF assms(1)]) then have "((\n. ereal(real_of_ereal(u n))) \ ereal l) F" using assms by auto then have limu: "((\n. real_of_ereal(u n)) \ l) F" by auto have vreal: "eventually (\n. v n = ereal(real_of_ereal(v n))) F" by (rule real_lim_then_eventually_real[OF assms(2)]) then have "((\n. ereal(real_of_ereal(v n))) \ ereal m) F" using assms by auto then have limv: "((\n. real_of_ereal(v n)) \ m) F" by auto { fix n assume "u n = ereal(real_of_ereal(u n))" "v n = ereal(real_of_ereal(v n))" then have "ereal(real_of_ereal(u n) * real_of_ereal(v n)) = u n * v n" by (metis times_ereal.simps(1)) } then have *: "eventually (\n. ereal(real_of_ereal(u n) * real_of_ereal(v n)) = u n * v n) F" using eventually_elim2[OF ureal vreal] by auto have "((\n. real_of_ereal(u n) * real_of_ereal(v n)) \ l * m) F" using tendsto_mult[OF limu limv] by auto then have "((\n. ereal(real_of_ereal(u n)) * real_of_ereal(v n)) \ ereal(l * m)) F" by auto then show ?thesis using * filterlim_cong by fastforce qed lemma tendsto_mult_ereal_PInf: fixes f g::"_ \ ereal" assumes "(f \ l) F" "l>0" "(g \ \) F" shows "((\x. f x * g x) \ \) F" proof - obtain a::real where "0 < ereal a" "a < l" using assms(2) using ereal_dense2 by blast have *: "eventually (\x. f x > a) F" using `a < l` assms(1) by (simp add: order_tendsto_iff) { fix K::real def M \ "max K 1" then have "M > 0" by simp then have "ereal(M/a) > 0" using `ereal a > 0` by simp then have "\x. ((f x > a) \ (g x > M/a)) \ (f x * g x > ereal a * ereal(M/a))" using ereal_mult_mono_strict'[where ?c = "M/a", OF `0 < ereal a`] by auto moreover have "ereal a * ereal(M/a) = M" using `ereal a > 0` by simp ultimately have "\x. ((f x > a) \ (g x > M/a)) \ (f x * g x > M)" by simp moreover have "M \ K" unfolding M_def by simp ultimately have Imp: "\x. ((f x > a) \ (g x > M/a)) \ (f x * g x > K)" using ereal_less_eq(3) le_less_trans by blast have "eventually (\x. g x > M/a) F" using assms(3) by (simp add: tendsto_PInfty) hence "eventually (\x. (f x > a) \ (g x > M/a)) F" using * by (auto simp add: eventually_conj_iff) then have "eventually (\x. f x * g x > K) F" using eventually_mono Imp by force } thus ?thesis by (auto simp add: tendsto_PInfty) qed lemma tendsto_mult_ereal_pos: fixes f g::"_ \ ereal" assumes "(f \ l) F" "(g \ m) F" "l>0" "m>0" shows "((\x. f x * g x) \ l * m) F" proof (cases) assume *: "l = \ \ m = \" then show ?thesis proof (cases) assume "m = \" then show ?thesis using tendsto_mult_ereal_PInf assms by auto next assume "\(m = \)" then have "l = \" using * by simp then have "((\x. g x * f x) \ l * m) F" using tendsto_mult_ereal_PInf assms by auto moreover have "\x. g x * f x = f x * g x" using mult.commute by auto ultimately show ?thesis by simp qed next assume "\(l = \ \ m = \)" then have "l < \" "m < \" by auto then obtain lr mr where "l = ereal lr" "m = ereal mr" using `l>0` `m>0` by (metis ereal_cases ereal_less(6) not_less_iff_gr_or_eq) then show ?thesis using tendsto_mult_real_ereal assms by auto qed text {*We reduce the general situation to the positive case by multiplying by suitable signs. Unfortunately, as ereal is not a ring, all the neat sign lemmas are not available there. We give the bare minimum we need.*} lemma ereal_sgn_abs: fixes l::ereal shows "sgn(l) * l = abs(l)" apply (cases l) using assms by (auto simp add: assms sgn_if ereal_less_uminus_reorder) lemma sgn_squared_ereal: assumes "l \ (0::ereal)" shows "sgn(l) * sgn(l) = 1" apply (cases l) using assms by (auto simp add: one_ereal_def sgn_if) lemma tendsto_mult_ereal: fixes f g::"_ \ ereal" assumes "(f \ l) F" "(g \ m) F" "\((l=0 \ abs(m) = \) \ (m=0 \ abs(l) = \))" shows "((\x. f x * g x) \ l * m) F" proof (cases) assume "l=0 \ m=0" then have "abs(l) \ \" "abs(m) \ \" using assms(3) by auto then obtain lr mr where "l = ereal lr" "m = ereal mr" by auto then show ?thesis using tendsto_mult_real_ereal assms by auto next have sgn_finite: "\a::ereal. abs(sgn a) \ \" by (metis MInfty_neq_ereal(2) PInfty_neq_ereal(2) abs_eq_infinity_cases ereal_times(1) ereal_times(3) ereal_uminus_eq_reorder sgn_ereal.elims) then have sgn_finite2: "\a b::ereal. abs(sgn a * sgn b) \ \" by (metis abs_eq_infinity_cases abs_ereal.simps(2) abs_ereal.simps(3) ereal_mult_eq_MInfty ereal_mult_eq_PInfty) assume "\(l=0 \ m=0)" then have "l \ 0" "m \ 0" by auto then have "abs(l) > 0" "abs(m) > 0" by (metis abs_ereal_ge0 abs_ereal_less0 abs_ereal_pos ereal_uminus_uminus ereal_uminus_zero less_le not_less)+ then have "sgn(l) * l > 0" "sgn(m) * m > 0" using ereal_sgn_abs by auto moreover have "((\x. sgn(l) * f x) \ (sgn(l) * l)) F" by (rule tendsto_cmult_ereal, auto simp add: sgn_finite assms(1)) moreover have "((\x. sgn(m) * g x) \ (sgn(m) * m)) F" by (rule tendsto_cmult_ereal, auto simp add: sgn_finite assms(2)) ultimately have *: "((\x. (sgn(l) * f x) * (sgn(m) * g x)) \ (sgn(l) * l) * (sgn(m) * m)) F" using tendsto_mult_ereal_pos by force have "((\x. (sgn(l) * sgn(m)) * ((sgn(l) * f x) * (sgn(m) * g x))) \ (sgn(l) * sgn(m)) * ((sgn(l) * l) * (sgn(m) * m))) F" by (rule tendsto_cmult_ereal, auto simp add: sgn_finite2 *) moreover have "\x. (sgn(l) * sgn(m)) * ((sgn(l) * f x) * (sgn(m) * g x)) = f x * g x" by (metis mult.left_neutral sgn_squared_ereal[OF `l \ 0`] sgn_squared_ereal[OF `m \ 0`] mult.assoc mult.commute) moreover have "(sgn(l) * sgn(m)) * ((sgn(l) * l) * (sgn(m) * m)) = l * m" by (metis mult.left_neutral sgn_squared_ereal[OF `l \ 0`] sgn_squared_ereal[OF `m \ 0`] mult.assoc mult.commute) ultimately show ?thesis by auto qed subsubsection {*Continuity of division*} lemma tendsto_inverse_ereal_PInf: fixes u::"_ \ ereal" assumes "(u \ \) F" shows "((\x. 1/ u x) \ 0) F" proof - { fix e::real assume "e>0" have "1/e < \" by auto then have "eventually (\n. u n > 1/e) F" using assms(1) by (simp add: tendsto_PInfty) moreover { fix z::ereal assume "z>1/e" then have "z>0" using `e>0` using less_le_trans not_le by fastforce then have "1/z \ 0" by auto moreover have "1/z < e" using `e>0` `z>1/e` apply (cases z) apply auto by (metis (mono_tags, hide_lams) less_ereal.simps(2) less_ereal.simps(4) divide_less_eq ereal_divide_less_pos ereal_less(4) ereal_less_eq(4) less_le_trans mult_eq_0_iff not_le not_one_less_zero times_ereal.simps(1)) ultimately have "1/z \ 0" "1/z < e" by auto } ultimately have "eventually (\n. 1/u nn. 1/u n\0) F" by (auto simp add: eventually_mono) } note * = this show ?thesis proof (subst order_tendsto_iff, auto) fix a::ereal assume "a<0" then show "eventually (\n. 1/u n > a) F" using *(2) eventually_mono less_le_trans linordered_field_no_ub by fastforce next fix a::ereal assume "a>0" then obtain e::real where "e>0" "a>e" using ereal_dense2 ereal_less(2) by blast then have "eventually (\n. 1/u n < e) F" using *(1) by auto then show "eventually (\n. 1/u n < a) F" using `a>e` by (metis (mono_tags, lifting) eventually_mono less_trans) qed qed lemma tendsto_inverse_ereal: fixes u::"_ \ ereal" assumes "(u \ l) F" "l \ 0" shows "((\x. 1/ u x) \ 1/l) F" proof (cases l) case (real r) then have "r \ 0" using assms(2) by auto then have "1/l = ereal(1/r)" using real by (simp add: one_ereal_def) def v \ "\n. real_of_ereal(u n)" have ureal: "eventually (\n. u n = ereal(v n)) F" unfolding v_def using real_lim_then_eventually_real assms(1) real by auto then have "((\n. ereal(v n)) \ ereal r) F" using assms real v_def by auto then have *: "((\n. v n) \ r) F" by auto then have "((\n. 1/v n) \ 1/r) F" using \r \ 0\ tendsto_inverse_real by auto then have lim: "((\n. ereal(1/v n)) \ 1/l) F" using \1/l = ereal(1/r)\ by auto have "r \ -{0}" "open (-{(0::real)})" using \r \ 0\ by auto then have "eventually (\n. v n \ -{0}) F" using * using topological_tendstoD by blast then have "eventually (\n. v n \ 0) F" by auto moreover { fix n assume H: "v n \ 0" "u n = ereal(v n)" then have "ereal(1/v n) = 1/ereal(v n)" by (simp add: one_ereal_def) then have "ereal(1/v n) = 1/u n" using H(2) by simp } ultimately have "eventually (\n. ereal(1/v n) = 1/u n) F" using ureal eventually_elim2 by force with Lim_transform_eventually[OF this lim] show ?thesis by simp next case (PInf) then have "1/l = 0" by auto then show ?thesis using tendsto_inverse_ereal_PInf assms PInf by auto next case (MInf) then have "1/l = 0" by auto have "1/z = -1/ -z" if "z < 0" for z::ereal apply (cases z) using divide_ereal_def \ z < 0 \ by auto moreover have "eventually (\n. u n < 0) F" by (metis (no_types) MInf assms(1) tendsto_MInfty zero_ereal_def) ultimately have *: "eventually (\n. -1/-u n = 1/u n) F" by (simp add: eventually_mono) def v \ "\n. - u n" have "(v \ \) F" unfolding v_def using MInf assms(1) tendsto_uminus_ereal by fastforce then have "((\n. 1/v n) \ 0) F" using tendsto_inverse_ereal_PInf by auto then have "((\n. -1/v n) \ 0) F" using tendsto_uminus_ereal by fastforce then show ?thesis unfolding v_def using Lim_transform_eventually[OF *] \ 1/l = 0 \ by auto qed lemma tendsto_divide_ereal: fixes f g::"_ \ ereal" assumes "(f \ l) F" "(g \ m) F" "m \ 0" "\(abs(l) = \ \ abs(m) = \)" shows "((\x. f x / g x) \ l / m) F" proof - def h \ "\x. 1/ g x" have *: "(h \ 1/m) F" unfolding h_def using assms(2) assms(3) tendsto_inverse_ereal by auto have "((\x. f x * h x) \ l * (1/m)) F" apply (rule tendsto_mult_ereal[OF assms(1) *]) using assms(3) assms(4) by (auto simp add: divide_ereal_def) moreover have "f x * h x = f x / g x" for x unfolding h_def by (simp add: divide_ereal_def) moreover have "l * (1/m) = l/m" by (simp add: divide_ereal_def) ultimately show ?thesis unfolding h_def using Lim_transform_eventually by auto qed subsubsection {*Further limits*} lemma id_nat_ereal_tendsto_PInf: "(\ n::nat. real n) \ \" by (simp add: filterlim_real_sequentially tendsto_PInfty_eq_at_top) lemma ereal_truncation_top: fixes x::ereal shows "(\n::nat. min x n) \ x" proof (cases x) case (real r) then obtain K::nat where "K>0" "K > abs(r)" using ex_less_of_nat gr0I by auto then have "min x n = x" if "n \ K" for n apply (subst real, subst real, auto) using that eq_iff by fastforce then have "eventually (\n. min x n = x) sequentially" using eventually_at_top_linorder by blast then show ?thesis by (simp add: Lim_eventually) next case (PInf) then have "min x n = n" for n::nat by (auto simp add: min_def) then show ?thesis using id_nat_ereal_tendsto_PInf PInf by auto next case (MInf) then have "min x n = x" for n::nat by (auto simp add: min_def) then show ?thesis by auto qed lemma ereal_truncation_real_top: fixes x::ereal assumes "x \ - \" shows "(\n::nat. real_of_ereal(min x n)) \ x" proof (cases x) case (real r) then obtain K::nat where "K>0" "K > abs(r)" using ex_less_of_nat gr0I by auto then have "min x n = x" if "n \ K" for n apply (subst real, subst real, auto) using that eq_iff by fastforce then have "real_of_ereal(min x n) = r" if "n \ K" for n using real that by auto then have "eventually (\n. real_of_ereal(min x n) = r) sequentially" using eventually_at_top_linorder by blast then have "(\n. real_of_ereal(min x n)) \ r" by (simp add: Lim_eventually) then show ?thesis using real by auto next case (PInf) then have "real_of_ereal(min x n) = n" for n::nat by (auto simp add: min_def) then show ?thesis using id_nat_ereal_tendsto_PInf PInf by auto qed (simp add: assms) lemma ereal_truncation_bottom: fixes x::ereal shows "(\n::nat. max x (- real n)) \ x" proof (cases x) case (real r) then obtain K::nat where "K>0" "K > abs(r)" using ex_less_of_nat gr0I by auto then have "max x (-real n) = x" if "n \ K" for n apply (subst real, subst real, auto) using that eq_iff by fastforce then have "eventually (\n. max x (-real n) = x) sequentially" using eventually_at_top_linorder by blast then show ?thesis by (simp add: Lim_eventually) next case (MInf) then have "max x (-real n) = (-1)* ereal(real n)" for n::nat by (auto simp add: max_def) moreover have "(\n. (-1)* ereal(real n)) \ -\" using tendsto_cmult_ereal[of "-1", OF _ id_nat_ereal_tendsto_PInf] by (simp add: one_ereal_def) ultimately show ?thesis using MInf by auto next case (PInf) then have "max x (-real n) = x" for n::nat by (auto simp add: max_def) then show ?thesis by auto qed lemma ereal_truncation_real_bottom: fixes x::ereal assumes "x \ \" shows "(\n::nat. real_of_ereal(max x (- real n))) \ x" proof (cases x) case (real r) then obtain K::nat where "K>0" "K > abs(r)" using ex_less_of_nat gr0I by auto then have "max x (-real n) = x" if "n \ K" for n apply (subst real, subst real, auto) using that eq_iff by fastforce then have "real_of_ereal(max x (-real n)) = r" if "n \ K" for n using real that by auto then have "eventually (\n. real_of_ereal(max x (-real n)) = r) sequentially" using eventually_at_top_linorder by blast then have "(\n. real_of_ereal(max x (-real n))) \ r" by (simp add: Lim_eventually) then show ?thesis using real by auto next case (MInf) then have "real_of_ereal(max x (-real n)) = (-1)* ereal(real n)" for n::nat by (auto simp add: max_def) moreover have "(\n. (-1)* ereal(real n)) \ -\" using tendsto_cmult_ereal[of "-1", OF _ id_nat_ereal_tendsto_PInf] by (simp add: one_ereal_def) ultimately show ?thesis using MInf by auto qed (simp add: assms) text {* the next one is copied from \verb+tendsto_setsum+. *} lemma tendsto_setsum_ereal: fixes f :: "'a \ 'b \ ereal" assumes "\i. i \ S \ (f i \ a i) F" "\i. abs(a i) \ \" shows "((\x. \i\S. f i x) \ (\i\S. a i)) F" proof (cases "finite S") assume "finite S" thus ?thesis using assms by (induct, simp, simp add: tendsto_add_ereal_general2 assms) qed(simp) subsubsection {*Limsups and liminfs*} lemma limsup_finite_then_bounded: fixes u::"nat \ real" assumes "limsup u < \" shows "\C. \n. u n \ C" proof - obtain C where C: "limsup u < C" "C < \" using assms ereal_dense2 by blast then have "C = ereal(real_of_ereal C)" using ereal_real by force have "eventually (\n. u n < C) sequentially" using C(1) unfolding Limsup_def apply (auto simp add: INF_less_iff) using SUP_lessD eventually_mono by fastforce then obtain N where N: "\n. n \ N \ u n < C" using eventually_sequentially by auto def D \ "max (real_of_ereal C) (Max {u n |n. n \ N})" have "\n. u n \ D" proof - fix n show "u n \ D" proof (cases) assume *: "n \ N" have "u n \ Max {u n |n. n \ N}" by (rule Max_ge, auto simp add: *) then show "u n \ D" unfolding D_def by linarith next assume "\(n \ N)" then have "n \ N" by simp then have "u n < C" using N by auto then have "u n < real_of_ereal C" using `C = ereal(real_of_ereal C)` less_ereal.simps(1) by fastforce then show "u n \ D" unfolding D_def by linarith qed qed then show ?thesis by blast qed lemma liminf_finite_then_bounded_below: fixes u::"nat \ real" assumes "liminf u > -\" shows "\C. \n. u n \ C" proof - obtain C where C: "liminf u > C" "C > -\" using assms using ereal_dense2 by blast then have "C = ereal(real_of_ereal C)" using ereal_real by force have "eventually (\n. u n > C) sequentially" using C(1) unfolding Liminf_def apply (auto simp add: less_SUP_iff) using eventually_elim2 less_INF_D by fastforce then obtain N where N: "\n. n \ N \ u n > C" using eventually_sequentially by auto def D \ "min (real_of_ereal C) (Min {u n |n. n \ N})" have "\n. u n \ D" proof - fix n show "u n \ D" proof (cases) assume *: "n \ N" have "u n \ Min {u n |n. n \ N}" by (rule Min_le, auto simp add: *) then show "u n \ D" unfolding D_def by linarith next assume "\(n \ N)" then have "n \ N" by simp then have "u n > C" using N by auto then have "u n > real_of_ereal C" using `C = ereal(real_of_ereal C)` less_ereal.simps(1) by fastforce then show "u n \ D" unfolding D_def by linarith qed qed then show ?thesis by blast qed lemma liminf_upper_bound: fixes u:: "nat \ ereal" assumes "liminf u < l" shows "\N>k. u N < l" by (metis assms gt_ex less_le_trans liminf_bounded_iff not_less) text {* The following statement about limsups is reduced to a statement about limits using subsequences thanks to \verb+limsup_subseq_lim+. The statement for limits follows for instance from \verb+tendsto_add_ereal_general+.*} lemma ereal_limsup_add_mono: fixes u v::"nat \ ereal" shows "limsup (\n. u n + v n) \ limsup u + limsup v" proof (cases) assume "(limsup u = \) \ (limsup v = \)" then have "limsup u + limsup v = \" by simp then show ?thesis by auto next assume "\((limsup u = \) \ (limsup v = \))" then have "limsup u < \" "limsup v < \" by auto def w \ "\n. u n + v n" obtain r where r: "subseq r" "(w o r) \ limsup w" using limsup_subseq_lim by auto obtain s where s: "subseq s" "(u o r o s) \ limsup (u o r)" using limsup_subseq_lim by auto obtain t where t: "subseq t" "(v o r o s o t) \ limsup (v o r o s)" using limsup_subseq_lim by auto def a \ "r o s o t" have "subseq a" using r s t by (simp add: a_def subseq_o) have l:"(w o a) \ limsup w" "(u o a) \ limsup (u o r)" "(v o a) \ limsup (v o r o s)" apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc) apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc) apply (metis (no_types, lifting) t(2) a_def comp_assoc) done have "limsup (u o r) \ limsup u" by (simp add: limsup_subseq_mono r(1)) then have a: "limsup (u o r) \ \" using `limsup u < \` by auto have "limsup (v o r o s) \ limsup v" by (simp add: comp_assoc limsup_subseq_mono r(1) s(1) subseq_o) then have b: "limsup (v o r o s) \ \" using `limsup v < \` by auto have "(\n. (u o a) n + (v o a) n) \ limsup (u o r) + limsup (v o r o s)" using l tendsto_add_ereal_general a b by fastforce moreover have "(\n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto ultimately have "(w o a) \ limsup (u o r) + limsup (v o r o s)" by simp then have "limsup w = limsup (u o r) + limsup (v o r o s)" using l(1) using LIMSEQ_unique by blast then have "limsup w \ limsup u + limsup v" using `limsup (u o r) \ limsup u` `limsup (v o r o s) \ limsup v` ereal_add_mono by simp then show ?thesis unfolding w_def by simp qed text {* There is an asymmetry between liminfs and limsups in ereal, as $\infty + (-\infty) = \infty$. This explains why there are more assumptions in the next lemma dealing with liminfs that in the previous one about limsups.*} lemma ereal_liminf_add_mono: fixes u v::"nat \ ereal" assumes "\((liminf u = \ \ liminf v = -\) \ (liminf u = -\ \ liminf v = \))" shows "liminf (\n. u n + v n) \ liminf u + liminf v" proof (cases) assume "(liminf u = -\) \ (liminf v = -\)" then have *: "liminf u + liminf v = -\" using assms by auto show ?thesis by (simp add: *) next assume "\((liminf u = -\) \ (liminf v = -\))" then have "liminf u > -\" "liminf v > -\" by auto def w \ "\n. u n + v n" obtain r where r: "subseq r" "(w o r) \ liminf w" using liminf_subseq_lim by auto obtain s where s: "subseq s" "(u o r o s) \ liminf (u o r)" using liminf_subseq_lim by auto obtain t where t: "subseq t" "(v o r o s o t) \ liminf (v o r o s)" using liminf_subseq_lim by auto def a \ "r o s o t" have "subseq a" using r s t by (simp add: a_def subseq_o) have l:"(w o a) \ liminf w" "(u o a) \ liminf (u o r)" "(v o a) \ liminf (v o r o s)" apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc) apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc) apply (metis (no_types, lifting) t(2) a_def comp_assoc) done have "liminf (u o r) \ liminf u" by (simp add: liminf_subseq_mono r(1)) then have a: "liminf (u o r) \ -\" using `liminf u > -\` by auto have "liminf (v o r o s) \ liminf v" by (simp add: comp_assoc liminf_subseq_mono r(1) s(1) subseq_o) then have b: "liminf (v o r o s) \ -\" using `liminf v > -\` by auto have "(\n. (u o a) n + (v o a) n) \ liminf (u o r) + liminf (v o r o s)" using l tendsto_add_ereal_general a b by fastforce moreover have "(\n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto ultimately have "(w o a) \ liminf (u o r) + liminf (v o r o s)" by simp then have "liminf w = liminf (u o r) + liminf (v o r o s)" using l(1) using LIMSEQ_unique by blast then have "liminf w \ liminf u + liminf v" using `liminf (u o r) \ liminf u` `liminf (v o r o s) \ liminf v` ereal_add_mono by simp then show ?thesis unfolding w_def by simp qed lemma ereal_limsup_lim_add: fixes u v::"nat \ ereal" assumes "u \ a" "abs(a) \ \" shows "limsup (\n. u n + v n) = a + limsup v" proof - have "limsup u = a" using assms(1) using tendsto_iff_Liminf_eq_Limsup trivial_limit_at_top_linorder by auto have "(\n. -u n) \ -a" using assms(1) by auto then have "limsup (\n. -u n) = -a" using tendsto_iff_Liminf_eq_Limsup trivial_limit_at_top_linorder by auto have "limsup (\n. u n + v n) \ limsup u + limsup v" by (rule ereal_limsup_add_mono) then have up: "limsup (\n. u n + v n) \ a + limsup v" using `limsup u = a` by simp have a: "limsup (\n. (u n + v n) + (-u n)) \ limsup (\n. u n + v n) + limsup (\n. -u n)" by (rule ereal_limsup_add_mono) have "eventually (\n. u n = ereal(real_of_ereal(u n))) sequentially" using assms real_lim_then_eventually_real by auto moreover have "\x. x = ereal(real_of_ereal(x)) \ x + (-x) = 0" by (metis plus_ereal.simps(1) right_minus uminus_ereal.simps(1) zero_ereal_def) ultimately have "eventually (\n. u n + (-u n) = 0) sequentially" by (metis (mono_tags, lifting) eventually_mono) moreover have "\n. u n + (-u n) = 0 \ u n + v n + (-u n) = v n" by (metis add.commute add.left_commute add.left_neutral) ultimately have "eventually (\n. u n + v n + (-u n) = v n) sequentially" using eventually_mono by force then have "limsup v = limsup (\n. u n + v n + (-u n))" using Limsup_eq by force then have "limsup v \ limsup (\n. u n + v n) -a" using a `limsup (\n. -u n) = -a` by (simp add: minus_ereal_def) then have "limsup (\n. u n + v n) \ a + limsup v" using assms(2) by (metis add.commute ereal_le_minus) then show ?thesis using up by simp qed lemma ereal_liminf_lim_add: fixes u v::"nat \ ereal" assumes "u \ a" "abs(a) \ \" shows "liminf (\n. u n + v n) = a + liminf v" proof - have "liminf u = a" using assms(1) using tendsto_iff_Liminf_eq_Limsup trivial_limit_at_top_linorder by auto then have *: "abs(liminf u) \ \" using assms(2) by auto have "(\n. -u n) \ -a" using assms(1) by auto then have "liminf (\n. -u n) = -a" using tendsto_iff_Liminf_eq_Limsup trivial_limit_at_top_linorder by auto then have **: "abs(liminf (\n. -u n)) \ \" using assms(2) by auto have "liminf (\n. u n + v n) \ liminf u + liminf v" apply (rule ereal_liminf_add_mono) using * by auto then have up: "liminf (\n. u n + v n) \ a + liminf v" using `liminf u = a` by simp have a: "liminf (\n. (u n + v n) + (-u n)) \ liminf (\n. u n + v n) + liminf (\n. -u n)" apply (rule ereal_liminf_add_mono) using ** by auto have "eventually (\n. u n = ereal(real_of_ereal(u n))) sequentially" using assms real_lim_then_eventually_real by auto moreover have "\x. x = ereal(real_of_ereal(x)) \ x + (-x) = 0" by (metis plus_ereal.simps(1) right_minus uminus_ereal.simps(1) zero_ereal_def) ultimately have "eventually (\n. u n + (-u n) = 0) sequentially" by (metis (mono_tags, lifting) eventually_mono) moreover have "\n. u n + (-u n) = 0 \ u n + v n + (-u n) = v n" by (metis add.commute add.left_commute add.left_neutral) ultimately have "eventually (\n. u n + v n + (-u n) = v n) sequentially" using eventually_mono by force then have "liminf v = liminf (\n. u n + v n + (-u n))" using Liminf_eq by force then have "liminf v \ liminf (\n. u n + v n) -a" using a `liminf (\n. -u n) = -a` by (simp add: minus_ereal_def) then have "liminf (\n. u n + v n) \ a + liminf v" using assms(2) by (metis add.commute ereal_minus_le) then show ?thesis using up by simp qed lemma ereal_liminf_limsup_add: fixes u v::"nat \ ereal" shows "liminf (\n. u n + v n) \ liminf u + limsup v" proof (cases) assume "limsup v = \ \ liminf u = \" then show ?thesis by auto next assume "\(limsup v = \ \ liminf u = \)" then have "limsup v < \" "liminf u < \" by auto def w \ "\n. u n + v n" obtain r where r: "subseq r" "(u o r) \ liminf u" using liminf_subseq_lim by auto obtain s where s: "subseq s" "(w o r o s) \ liminf (w o r)" using liminf_subseq_lim by auto obtain t where t: "subseq t" "(v o r o s o t) \ limsup (v o r o s)" using limsup_subseq_lim by auto def a \ "r o s o t" have "subseq a" using r s t by (simp add: a_def subseq_o) have l:"(u o a) \ liminf u" "(w o a) \ liminf (w o r)" "(v o a) \ limsup (v o r o s)" apply (metis (no_types, lifting) r(2) s(1) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc) apply (metis (no_types, lifting) s(2) t(1) LIMSEQ_subseq_LIMSEQ a_def comp_assoc) apply (metis (no_types, lifting) t(2) a_def comp_assoc) done have "liminf (w o r) \ liminf w" by (simp add: liminf_subseq_mono r(1)) have "limsup (v o r o s) \ limsup v" by (simp add: comp_assoc limsup_subseq_mono r(1) s(1) subseq_o) then have b: "limsup (v o r o s) < \" using `limsup v < \` by auto have "(\n. (u o a) n + (v o a) n) \ liminf u + limsup (v o r o s)" apply (rule tendsto_add_ereal_general) using b `liminf u < \` l(1) l(3) by force+ moreover have "(\n. (u o a) n + (v o a) n) = (w o a)" unfolding w_def by auto ultimately have "(w o a) \ liminf u + limsup (v o r o s)" by simp then have "liminf (w o r) = liminf u + limsup (v o r o s)" using l(2) using LIMSEQ_unique by blast then have "liminf w \ liminf u + limsup v" using `liminf (w o r) \ liminf w` `limsup (v o r o s) \ limsup v` by (metis add_mono_thms_linordered_semiring(2) le_less_trans not_less) then show ?thesis unfolding w_def by simp qed lemma ereal_limsup_lim_mult: fixes u v::"nat \ ereal" assumes "u \ a" "a>0" "a \ \" shows "limsup (\n. u n * v n) = a * limsup v" proof - def w \ "\n. u n * v n" obtain r where r: "subseq r" "(v o r) \ limsup v" using limsup_subseq_lim by auto have "(u o r) \ a" using assms(1) LIMSEQ_subseq_LIMSEQ r by auto with tendsto_mult_ereal[OF this r(2)] have "(\n. (u o r) n * (v o r) n) \ a * limsup v" using assms(2) assms(3) by auto moreover have "\n. (w o r) n = (u o r) n * (v o r) n" unfolding w_def by auto ultimately have "(w o r) \ a * limsup v" unfolding w_def by presburger then have "limsup (w o r) = a * limsup v" by (simp add: tendsto_iff_Liminf_eq_Limsup) then have I: "limsup w \ a * limsup v" by (metis limsup_subseq_mono r(1)) obtain s where s: "subseq s" "(w o s) \ limsup w" using limsup_subseq_lim by auto have *: "(u o s) \ a" using assms(1) LIMSEQ_subseq_LIMSEQ s by auto have "eventually (\n. (u o s) n > 0) sequentially" using assms(2) * order_tendsto_iff by blast moreover have "eventually (\n. (u o s) n < \) sequentially" using assms(3) * order_tendsto_iff by blast moreover { fix n assume "(u o s) n > 0" "(u o s) n < \" then have "(w o s) n / (u o s) n = (v o s) n" unfolding w_def by (auto simp add: ereal_divide_eq) } ultimately have "eventually (\n. (w o s) n / (u o s) n = (v o s) n) sequentially" using eventually_elim2 by force moreover have "(\n. (w o s) n / (u o s) n) \ (limsup w) / a" apply (rule tendsto_divide_ereal[OF s(2) *]) using assms(2) assms(3) by auto ultimately have "(v o s) \ (limsup w) / a" using Lim_transform_eventually by fastforce then have "limsup (v o s) = (limsup w) / a" by (simp add: tendsto_iff_Liminf_eq_Limsup) then have "limsup v \ (limsup w) / a" by (metis limsup_subseq_mono s(1)) then have "a * limsup v \ limsup w" using assms(2) assms(3) by (simp add: ereal_divide_le_pos) then show ?thesis using I unfolding w_def by auto qed lemma ereal_liminf_lim_mult: fixes u v::"nat \ ereal" assumes "u \ a" "a>0" "a \ \" shows "liminf (\n. u n * v n) = a * liminf v" proof - def w \ "\n. u n * v n" obtain r where r: "subseq r" "(v o r) \ liminf v" using liminf_subseq_lim by auto have "(u o r) \ a" using assms(1) LIMSEQ_subseq_LIMSEQ r by auto with tendsto_mult_ereal[OF this r(2)] have "(\n. (u o r) n * (v o r) n) \ a * liminf v" using assms(2) assms(3) by auto moreover have "\n. (w o r) n = (u o r) n * (v o r) n" unfolding w_def by auto ultimately have "(w o r) \ a * liminf v" unfolding w_def by presburger then have "liminf (w o r) = a * liminf v" by (simp add: tendsto_iff_Liminf_eq_Limsup) then have I: "liminf w \ a * liminf v" by (metis liminf_subseq_mono r(1)) obtain s where s: "subseq s" "(w o s) \ liminf w" using liminf_subseq_lim by auto have *: "(u o s) \ a" using assms(1) LIMSEQ_subseq_LIMSEQ s by auto have "eventually (\n. (u o s) n > 0) sequentially" using assms(2) * order_tendsto_iff by blast moreover have "eventually (\n. (u o s) n < \) sequentially" using assms(3) * order_tendsto_iff by blast moreover { fix n assume "(u o s) n > 0" "(u o s) n < \" then have "(w o s) n / (u o s) n = (v o s) n" unfolding w_def by (auto simp add: ereal_divide_eq) } ultimately have "eventually (\n. (w o s) n / (u o s) n = (v o s) n) sequentially" using eventually_elim2 by force moreover have "(\n. (w o s) n / (u o s) n) \ (liminf w) / a" apply (rule tendsto_divide_ereal[OF s(2) *]) using assms(2) assms(3) by auto ultimately have "(v o s) \ (liminf w) / a" using Lim_transform_eventually by fastforce then have "liminf (v o s) = (liminf w) / a" by (simp add: tendsto_iff_Liminf_eq_Limsup) then have "liminf v \ (liminf w) / a" by (metis liminf_subseq_mono s(1)) then have "a * liminf v \ liminf w" using assms(2) assms(3) by (simp add: ereal_le_divide_pos) then show ?thesis using I unfolding w_def by auto qed subsection {*sigma-algebra.thy*} lemma algebra_intersection: assumes "algebra \ A" "algebra \ B" shows "algebra \ (A \ B)" apply (subst algebra_iff_Un) using assms by (auto simp add: algebra_iff_Un) lemma sigma_algebra_intersection: assumes "sigma_algebra \ A" "sigma_algebra \ B" shows "sigma_algebra \ (A \ B)" apply (subst sigma_algebra_iff) using assms by (auto simp add: sigma_algebra_iff algebra_intersection) text {* The next one is \verb+disjoint_family_Suc+ with inclusions reversed.*} lemma disjoint_family_Suc2: assumes Suc: "\n. A (Suc n) \ A n" shows "disjoint_family (\i. A i - A (Suc i))" proof - { fix m have "\n. A (m+n) \ A n" proof (induct m) case 0 show ?case by simp next case (Suc m) thus ?case by (metis Suc_eq_plus1 assms add.commute add.left_commute subset_trans) qed } hence "\m n. m > n \ A m \ A n" by (metis add.commute le_add_diff_inverse nat_less_le) thus ?thesis by (auto simp add: disjoint_family_on_def) (metis insert_absorb insert_subset le_SucE le_antisym not_le_imp_less) qed text {* the next few lemmas give useful measurability statements*} text {* The next one is a reformulation of \verb+borel_measurable_Max+.*} lemma borel_measurable_Max2[measurable (raw)]: fixes f::"_ \ _ \ 'a::{second_countable_topology, dense_linorder, linorder_topology}" assumes "finite I" and [measurable]: "\i. f i \ borel_measurable M" shows "(\x. Max{f i x |i. i \ I}) \ borel_measurable M" proof - { fix x have "{f i x |i. i \ I} = (\i. f i x)`I" by blast then have "Max {f i x |i. i \ I} = Max ((\i. f i x)`I)" by simp } moreover have "(\x. Max ((\i. f i x)`I)) \ borel_measurable M" using borel_measurable_Max[OF assms(1), where ?f=f and ?M=M] assms by simp ultimately show ?thesis by simp qed lemma measurable_compose_n [measurable (raw)]: assumes "T \ measurable M M" shows "(T^^n) \ measurable M M" by (induction n, auto simp add: measurable_compose[OF _ assms]) lemma measurable_real_imp_nat: fixes f::"'a \ nat" assumes [measurable]: "(\x. real(f x)) \ borel_measurable M" shows "f \ measurable M (count_space UNIV)" proof - let ?g = "(\x. real(f x))" have "\(n::nat). ?g-`({real n}) \ space M = f-`{n} \ space M" by auto moreover have "\(n::nat). ?g-`({real n}) \ space M \ sets M" using assms by measurable ultimately have "\(n::nat). f-`{n} \ space M \ sets M" by simp thus ?thesis using measurable_count_space_eq2_countable by blast qed lemma measurable_equality_set [measurable]: fixes f g::"_\ 'a::{second_countable_topology, t2_space}" assumes [measurable]: "f \ borel_measurable M" "g \ borel_measurable M" shows "{x \ space M. f x = g x} \ sets M" proof - def A \ "{x \ space M. f x = g x}" def B \ "{y. \x::'a. y = (x,x)}" have "A = (\x. (f x, g x))-`B \ space M" unfolding A_def B_def by auto moreover have "(\x. (f x, g x)) \ borel_measurable M" by simp moreover have "B \ sets borel" unfolding B_def by (simp add: closed_diagonal) ultimately have "A \ sets M" by simp then show ?thesis unfolding A_def by simp qed lemma measurable_inequality_set [measurable]: fixes f g::"_ \ 'a::{second_countable_topology, linorder_topology}" assumes [measurable]: "f \ borel_measurable M" "g \ borel_measurable M" shows "{x \ space M. f x \ g x} \ sets M" "{x \ space M. f x < g x} \ sets M" "{x \ space M. f x \ g x} \ sets M" "{x \ space M. f x > g x} \ sets M" proof - def F \ "(\x. (f x, g x))" have * [measurable]: "F \ borel_measurable M" unfolding F_def by simp have "{x \ space M. f x \ g x} = F-`{(x, y) | x y. x \ y} \ space M" unfolding F_def by auto moreover have "{(x, y) | x y. x \ (y::'a)} \ sets borel" using closed_subdiagonal borel_closed by blast ultimately show "{x \ space M. f x \ g x} \ sets M" using * by (metis (mono_tags, lifting) measurable_sets) have "{x \ space M. f x < g x} = F-`{(x, y) | x y. x < y} \ space M" unfolding F_def by auto moreover have "{(x, y) | x y. x < (y::'a)} \ sets borel" using open_subdiagonal borel_open by blast ultimately show "{x \ space M. f x < g x} \ sets M" using * by (metis (mono_tags, lifting) measurable_sets) have "{x \ space M. f x \ g x} = F-`{(x, y) | x y. x \ y} \ space M" unfolding F_def by auto moreover have "{(x, y) | x y. x \ (y::'a)} \ sets borel" using closed_superdiagonal borel_closed by blast ultimately show "{x \ space M. f x \ g x} \ sets M" using * by (metis (mono_tags, lifting) measurable_sets) have "{x \ space M. f x > g x} = F-`{(x, y) | x y. x > y} \ space M" unfolding F_def by auto moreover have "{(x, y) | x y. x > (y::'a)} \ sets borel" using open_superdiagonal borel_open by blast ultimately show "{x \ space M. f x > g x} \ sets M" using * by (metis (mono_tags, lifting) measurable_sets) qed lemma measurable_limit [measurable]: fixes f::"nat \ 'a \ 'b::first_countable_topology" assumes [measurable]: "\n::nat. f n \ borel_measurable M" shows "Measurable.pred M (\x. (\n. f n x) \ c)" proof - obtain A :: "nat \ 'b set" where A: "\i. open (A i)" "\i. c \ A i" "\S. open S \ c \ S \ eventually (\i. A i \ S) sequentially" by (rule countable_basis_at_decseq) blast have [measurable]: "\N i. (f N)-`(A i) \ space M \ sets M" using A(1) by auto then have mes: "(\i. \n. \N\{n..}. (f N)-`(A i) \ space M) \ sets M" by blast { fix u::"nat \ 'b" have "(u \ c) \ (\i. eventually (\n. u n \ A i) sequentially)" proof assume "u \ c" - { - fix i - have "eventually (\n. u n \ A i) sequentially" using A(1)[of i] A(2)[of i] `u \ c` - by (simp add: topological_tendstoD) - } + then have "eventually (\n. u n \ A i) sequentially" for i using A(1)[of i] A(2)[of i] + by (simp add: topological_tendstoD) then show "(\i. eventually (\n. u n \ A i) sequentially)" by auto next assume H: "(\i. eventually (\n. u n \ A i) sequentially)" show "(u \ c)" proof (rule topological_tendstoI) fix S assume "open S" "c \ S" with A(3)[OF this] obtain i where "A i \ S" using eventually_False_sequentially eventually_mono by blast moreover have "eventually (\n. u n \ A i) sequentially" using H by simp ultimately show "\\<^sub>F n in sequentially. u n \ S" by (simp add: eventually_mono subset_eq) qed qed } then have "{x. (\n. f n x) \ c} = (\i. \n. \N\{n..}. (f N)-`(A i))" by (auto simp add: atLeast_def eventually_at_top_linorder) then have "{x \ space M. (\n. f n x) \ c} = (\i. \n. \N\{n..}. (f N)-`(A i) \ space M)" by auto then have "{x \ space M. (\n. f n x) \ c} \ sets M" using mes by simp then show ?thesis by auto qed lemma measurable_P_restriction [measurable (raw)]: assumes [measurable]: "Measurable.pred M P" "A \ sets M" shows "{x \ A. P x} \ sets M" proof - have "A \ space M" using sets.sets_into_space[OF assms(2)]. then have "{x \ A. P x} = A \ {x \ space M. P x}" by blast then show ?thesis by auto qed lemma measurable_setsum_nat [measurable (raw)]: fixes f :: "'c \ 'a \ nat" assumes "\i. i \ S \ f i \ measurable M (count_space UNIV)" shows "(\x. \i\S. f i x) \ measurable M (count_space UNIV)" proof cases assume "finite S" thus ?thesis using assms by induct auto qed simp lemma measurable_limsup [measurable (raw)]: assumes [measurable]: "\n. A n \ sets M" shows "limsup A \ sets M" by (subst limsup_INF_SUP, auto) lemma measurable_liminf [measurable (raw)]: assumes [measurable]: "\n. A n \ sets M" shows "liminf A \ sets M" by (subst liminf_SUP_INF, auto) text {* The next one is a variation around \verb+measurable_restrict_space+.*} lemma measurable_restrict_space3: assumes "f \ measurable M N" and "f \ A \ B" shows "f \ measurable (restrict_space M A) (restrict_space N B)" proof - have "f \ measurable (restrict_space M A) N" using assms(1) measurable_restrict_space1 by auto then show ?thesis by (metis Int_iff funcsetI funcset_mem measurable_restrict_space2[of f, of "restrict_space M A", of B, of N] assms(2) space_restrict_space) qed text {* The next one is a variation around \verb+measurable_piecewise_restrict+.*} lemma measurable_piecewise_restrict2: assumes [measurable]: "\n. A n \ sets M" and "space M = (\(n::nat). A n)" "\n. \h \ measurable M N. (\x \ A n. f x = h x)" shows "f \ measurable M N" proof (rule measurableI) fix B assume [measurable]: "B \ sets N" { fix n::nat obtain h where [measurable]: "h \ measurable M N" and "\x \ A n. f x = h x" using assms(3) by blast then have *: "f-`B \ A n = h-`B \ A n" by auto have "h-`B \ A n = h-`B \ space M \ A n" using assms(2) sets.sets_into_space by auto then have "h-`B \ A n \ sets M" by simp then have "f-`B \ A n \ sets M" using * by simp } then have "(\n. f-`B \ A n) \ sets M" by measurable moreover have "f-`B \ space M = (\n. f-`B \ A n)" using assms(2) by blast ultimately show "f-`B \ space M \ sets M" by simp next fix x assume "x \ space M" then obtain n where "x \ A n" using assms(2) by blast obtain h where [measurable]: "h \ measurable M N" and "\x \ A n. f x = h x" using assms(3) by blast then have "f x = h x" using `x \ A n` by blast moreover have "h x \ space N" by (metis measurable_space `x \ space M` `h \ measurable M N`) ultimately show "f x \ space N" by simp qed subsection {*Measure-Space.thy *} lemma emeasure_union_inter: assumes "A \ sets M" "B \ sets M" shows "emeasure M A + emeasure M B = emeasure M (A \ B) + emeasure M (A \ B)" proof - have "A = (A-B) \ (A \ B)" by auto then have 1: "emeasure M A = emeasure M (A-B) + emeasure M (A \ B)" by (metis Diff_Diff_Int Diff_disjoint assms(1) assms(2) plus_emeasure sets.Diff) have "A \ B = (A-B) \ B" by auto then have 2: "emeasure M (A \ B) = emeasure M (A-B) + emeasure M B" by (metis Diff_disjoint Int_commute assms(1) assms(2) plus_emeasure sets.Diff) show ?thesis using 1 2 by (metis add.assoc add.commute) qed lemma AE_E3: assumes "AE x in M. P x" obtains N where "\x. x \ space M - N \ P x" "N \ null_sets M" using assms unfolding eventually_ae_filter by auto lemma AE_equal_setsum: assumes "\i. AE x in M. f i x = g i x" shows "AE x in M. (\i\I. f i x) = (\i\I. g i x)" proof (cases) assume "finite I" have "\A. A \ null_sets M \ (\x\ (space M - A). f i x = g i x)" for i using assms(1)[of i] by (metis (mono_tags, lifting) AE_E3) then obtain A where A: "\i. A i \ null_sets M \ (\x\ (space M -A i). f i x = g i x)" by metis def B \ "(\i\I. A i)" have "B \ null_sets M" using `finite I` A B_def by blast then have "AE x in M. x \ space M - B" by (simp add: null_setsD_AE) moreover { fix x assume "x \ space M - B" then have "\i. i \ I \ f i x = g i x" unfolding B_def using A by auto then have "(\i\I. f i x) = (\i\I. g i x)" by auto } ultimately show ?thesis by auto qed (simp) lemma emeasure_pos_unionE: assumes "\ (N::nat). A N \ sets M" "emeasure M (\N. A N) > 0" shows "\N. emeasure M (A N) > 0" proof (rule ccontr) assume "\(\N. emeasure M (A N) > 0)" then have "\N. A N \ null_sets M" using assms(1) emeasure_less_0_iff linorder_cases by blast then have "(\N. A N) \ null_sets M" by auto then show False using assms(2) by auto qed lemma emeasure_union_summable: - assumes [measurable]: "\n. A n \ sets M" and "\n. emeasure M (A n) < \" "summable (\n. measure M (A n))" + assumes [measurable]: "\n. A n \ sets M" + and "\n. emeasure M (A n) < \" "summable (\n. measure M (A n))" shows "emeasure M (\n. A n) < \" "emeasure M (\n. A n) \ (\n. measure M (A n))" proof - def B \ "\N. (\n\{.. sets M" for N unfolding B_def by auto have "(\N. emeasure M (B N)) \ emeasure M (\N. B N)" apply (rule Lim_emeasure_incseq) unfolding B_def by (auto simp add: SUP_subset_mono incseq_def) moreover have "emeasure M (B N) \ ereal (\n. measure M (A n))" for N proof - have *: "(\n\{.. (\n. measure M (A n))" using assms(3) measure_nonneg setsum_le_suminf by blast have "emeasure M (B N) \ (\n\{..n\{..n\{.. ereal (\n. measure M (A n))" using * by auto finally show ?thesis by simp qed ultimately have "emeasure M (\N. B N) \ ereal (\n. measure M (A n))" by (simp add: Lim_bounded_ereal) then show "emeasure M (\n. A n) \ (\n. measure M (A n))" unfolding B_def by (metis UN_UN_flatten UN_lessThan_UNIV) then show "emeasure M (\n. A n) < \" by auto qed lemma (in sigma_finite_measure) approx_PInf_emeasure_with_finite: fixes C::real assumes W_meas: "W \ sets M" and W_inf: "emeasure M W = \" obtains Z where "Z \ sets M" "Z \ W" "emeasure M Z < \" "emeasure M Z > C" proof - obtain A :: "nat \ 'a set" where "range A \ sets M" "(\i. A i) = space M" "\i. emeasure M (A i) \ \" "incseq A" using sigma_finite_incseq by blast def B \ "\i. W \ A i" have B_meas: "\i. B i \ sets M" using W_meas `range A \ sets M` B_def by blast have b: "\i. B i \ W" using B_def by blast have "\i. emeasure M (A i) < \" using `\i. emeasure M (A i) \ \` by simp moreover have "\i. A i \ sets M" using `range A \ sets M` by simp ultimately have c: "\i. emeasure M (B i) < \" by (metis ereal_infty_less(1) ereal_infty_less_eq(1) le_inf_iff subsetI B_def emeasure_mono) have "W = (\i. B i)" using B_def `(\i. A i) = space M` W_meas by auto moreover have "incseq B" using B_def `incseq A` by (simp add: incseq_def subset_eq) ultimately have "(\i. emeasure M (B i)) \ emeasure M W" using W_meas B_meas by (simp add: B_meas Lim_emeasure_incseq image_subset_iff) then have "(\i. emeasure M (B i)) \ \" using W_inf by simp moreover have "C < \" by auto ultimately obtain i where d: "emeasure M (B i) > C" by (meson Lim_bounded_PInfty not_le) have "B i \ sets M" "B i \ W" "emeasure M (B i) < \" "emeasure M (B i) > C" using B_meas b c d by auto then show ?thesis using that by blast qed lemma null_sets_inc: assumes "A \ null_sets M" "B \ sets M" "B \ A" shows "B \ null_sets M" by (metis Int_absorb1 assms(1) assms(2) assms(3) null_set_Int2) lemma null_sym_diff_transitive: assumes "A \ B \ null_sets M" "B \ C \ null_sets M" and [measurable]: "A \ sets M" "C \ sets M" shows "A \ C \ null_sets M" proof - have "A \ B \ B \ C \ null_sets M" using assms(1) assms(2) by auto moreover have "A \ C \ A \ B \ B \ C" by auto ultimately show ?thesis by (meson null_sets_inc assms(3) assms(4) sets.Diff sets.Un) qed lemma Delta_null_of_null_is_null: assumes "B \ sets M" "A \ B \ null_sets M" "A \ null_sets M" shows "B \ null_sets M" proof - have "B \ A \ (A \ B)" by auto then show ?thesis using assms by (meson null_sets.Un null_sets_inc) qed lemma Delta_null_same_emeasure: assumes "A \ B \ null_sets M" and [measurable]: "A \ sets M" "B \ sets M" shows "emeasure M A = emeasure M B" proof - have "A = (A \ B) \ (A-B)" by blast moreover have "A-B \ null_sets M" using assms null_sets_inc by blast ultimately have a: "emeasure M A = emeasure M (A \ B)" using emeasure_Un_null_set by (metis assms(2) assms(3) sets.Int) have "B = (A \ B) \ (B-A)" by blast moreover have "B-A \ null_sets M" using assms null_sets_inc by blast ultimately have "emeasure M B = emeasure M (A \ B)" using emeasure_Un_null_set by (metis assms(2) assms(3) sets.Int) then show ?thesis using a by auto qed - lemma AE_count_union: assumes "\(N::nat). N \ I \ AE x in M. P N x" "countable I" shows "AE x in M. \N \ I. P N x" proof - def C \ "\N. {x. P N x}" have "AE x in M. x \ C N" if "N \ I" for N unfolding C_def using assms that by auto then have "\D. D \ null_sets M \ (space M - D) \ C N" if "N \ I" for N - by (metis that AE_E3 subsetI) + by (metis that AE_E3 subsetI) then obtain D where D: "\N. N \ I \ D N \ null_sets M" "\N. N \ I \(space M - D N) \ C N" by metis def E \ "(\N\I. D N)" have "E \ null_sets M" unfolding E_def using D(1) assms(2) by (simp add: null_sets_UN') then have "AE x in M. x \ space M - E" unfolding eventually_ae_filter by blast moreover { fix x assume "x \ space M - E" then have "x \ C N" if "N \ I" for N unfolding E_def using D(2) that by blast then have "\N\I. P N x" unfolding C_def by auto } ultimately show ?thesis by auto qed lemma AE_upper_bound_inf_ereal: fixes F G::"'a \ ereal" assumes "\e. e > 0 \ AE x in M. F x \ G x + e" shows "AE x in M. F x \ G x" proof - have "AE x in M. F x \ G x + 1/real (n+1)" for n::nat by (rule assms, auto) then have "AE x in M. \n::nat \ UNIV. F x \ G x + 1/real (n+1)" by (rule AE_count_union, auto) moreover { fix x assume i: "\n::nat \ UNIV. F x \ G x + 1/real (n+1)" have "(\n. (1/(real (n+1)))) \ 0" using lim_1_over_n LIMSEQ_ignore_initial_segment by blast then have *: "(\n. ereal(1/(real (n+1)))) \ 0" by (simp add: zero_ereal_def) have "(\n. G x + 1/real (n+1)) \ G x + 0" apply (rule tendsto_add_ereal_general) using * by auto then have "F x \ G x" using i LIMSEQ_le_const by fastforce } ultimately show ?thesis by auto qed lemma AE_upper_bound_inf_ereal2: fixes F G::"'a \ ereal" assumes "\e. e > (0::real) \ AE x in M. F x \ G x + e" shows "AE x in M. F x \ G x" proof - have "AE x in M. F x \ G x + e" if "e > (0::ereal)" for e apply (cases e) using `e > 0` assms by auto then show ?thesis using AE_upper_bound_inf_ereal by auto qed lemma AE_upper_bound_inf: fixes F G::"'a \ real" assumes "\e. e > 0 \ AE x in M. F x \ G x + e" shows "AE x in M. F x \ G x" proof - have "AE x in M. F x \ G x + 1/real (n+1)" for n::nat by (rule assms, auto) then have "AE x in M. \n::nat \ UNIV. F x \ G x + 1/real (n+1)" by (rule AE_count_union, auto) moreover { fix x assume i: "\n::nat \ UNIV. F x \ G x + 1/real (n+1)" - have *: "(\n. (1/(real (n+1)))) \ 0" using lim_1_over_n LIMSEQ_ignore_initial_segment by blast have "(\n. G x + 1/real (n+1)) \ G x + 0" - apply (rule tendsto_add) using * by auto + by (rule tendsto_add, simp, rule LIMSEQ_ignore_initial_segment[OF lim_1_over_n, of 1]) then have "F x \ G x" using i LIMSEQ_le_const by fastforce } ultimately show ?thesis by auto qed lemma not_AE_zero_ereal_E: fixes f::"'a \ ereal" assumes "AE x in M. f x \ 0" "\(AE x in M. f x = 0)" and [measurable]: "f \ borel_measurable M" shows "\A e. A \ sets M \ e>(0::real) \ emeasure M A > 0 \ (\x \ A. f x \ e)" proof - have "\e. e > (0::real) \ {x \ space M. f x \ e} \ null_sets M" proof (rule ccontr) assume *: "\(\e. e > (0::real) \ {x \ space M. f x \ e} \ null_sets M)" { fix e::real assume "e > 0" then have "{x \ space M. f x \ e} \ null_sets M" using * by blast then have "AE x in M. x \ {x \ space M. f x \ e}" using null_setsD_AE by blast then have "AE x in M. f x \ e" by auto } then have "AE x in M. f x \ 0" using AE_upper_bound_inf_ereal2[where ?F = f and ?G = "\x. 0" and ?M= M] by auto then have "AE x in M. f x = 0" using assms(1) by auto then show False using assms(2) by auto qed then obtain e::real where e: "e>0" "{x \ space M. f x \ e} \ null_sets M" by auto def A \ "{x \ space M. f x \ e}" have 1 [measurable]: "A \ sets M" unfolding A_def by auto have 2: "emeasure M A > 0" using e(2) A_def \A \ sets M\ emeasure_less_0_iff linorder_cases by blast have 3: "\x. x \ A \ f x \ e" unfolding A_def by auto show ?thesis using e(1) 1 2 3 by blast qed lemma not_AE_zero_E: fixes f::"'a \ real" assumes "AE x in M. f x \ 0" "\(AE x in M. f x = 0)" and [measurable]: "f \ borel_measurable M" shows "\A e. A \ sets M \ e>0 \ emeasure M A > 0 \ (\x \ A. f x \ e)" proof - have "\e. e > 0 \ {x \ space M. f x \ e} \ null_sets M" proof (rule ccontr) assume *: "\(\e. e > 0 \ {x \ space M. f x \ e} \ null_sets M)" { fix e::real assume "e > 0" then have "{x \ space M. f x \ e} \ null_sets M" using * by blast then have "AE x in M. x \ {x \ space M. f x \ e}" using null_setsD_AE by blast then have "AE x in M. f x \ e" by auto } then have "AE x in M. f x \ 0" by (rule AE_upper_bound_inf, auto) then have "AE x in M. f x = 0" using assms(1) by auto then show False using assms(2) by auto qed then obtain e where e: "e>0" "{x \ space M. f x \ e} \ null_sets M" by auto def A \ "{x \ space M. f x \ e}" have 1 [measurable]: "A \ sets M" unfolding A_def by auto have 2: "emeasure M A > 0" using e(2) A_def \A \ sets M\ emeasure_less_0_iff linorder_cases by blast have 3: "\x. x \ A \ f x \ e" unfolding A_def by auto show ?thesis using e(1) 1 2 3 by blast qed lemma borel_cantelli_limsup1: - assumes [measurable]: "\n. A n \ sets M" and "\n. emeasure M (A n) < \" "summable (\n. measure M (A n))" + assumes [measurable]: "\n. A n \ sets M" + and "\n. emeasure M (A n) < \" "summable (\n. measure M (A n))" shows "limsup A \ null_sets M" proof - have "(\n. (\k. measure M (A (k+n)))) \ 0" by (rule suminf_exist_split2[OF assms(3)]) then have "(\n. ereal (\k. measure M (A (k+n)))) \ 0" by (simp add: zero_ereal_def) moreover have "emeasure M (limsup A) \ (\k. measure M (A (k+n)))" for n proof - have I: "(\k\{n..}. A k) = (\k. A (k+n))" by (auto, metis le_add_diff_inverse2, fastforce) have "emeasure M (limsup A) \ emeasure M (\k\{n..}. A k)" by (rule emeasure_mono, auto simp add: limsup_INF_SUP) also have "... = emeasure M (\k. A (k+n))" using I by auto also have "... \ (\k. measure M (A (k+n)))" - apply (rule emeasure_union_summable) using assms summable_ignore_initial_segment[OF assms(3), of n] by auto + apply (rule emeasure_union_summable) + using assms summable_ignore_initial_segment[OF assms(3), of n] by auto finally show ?thesis by simp qed ultimately have "emeasure M (limsup A) \ 0" by (simp add: LIMSEQ_le_const) then show ?thesis using emeasure_le_0_iff assms(1) measurable_limsup by blast qed lemma borel_cantelli_AE1: - assumes [measurable]: "\n. A n \ sets M" and "\n. emeasure M (A n) < \" "summable (\n. measure M (A n))" + assumes [measurable]: "\n. A n \ sets M" + and "\n. emeasure M (A n) < \" "summable (\n. measure M (A n))" shows "AE x in M. eventually (\n. x \ space M - A n) sequentially" proof - - have "AE x in M. x \ limsup A" using borel_cantelli_limsup1[OF assms] unfolding eventually_ae_filter by auto + have "AE x in M. x \ limsup A" + using borel_cantelli_limsup1[OF assms] unfolding eventually_ae_filter by auto moreover { fix x assume "x \ limsup A" then obtain N where "x \ (\n\{N..}. A n)" unfolding limsup_INF_SUP by blast then have "eventually (\n. x \ A n) sequentially" using eventually_sequentially by auto } ultimately show ?thesis by auto qed subsection {*Nonnegative-Lebesgue-Integration.thy*} text{* The next lemma is a variant of \verb+nn_integral_density+, with the density on the right instead of the left, as seems more common. *} lemma nn_integral_densityR: assumes [measurable]: "f \ borel_measurable F" "g \ borel_measurable F" and "AE x in F. g x \ 0" shows "(\\<^sup>+ x. f x * g x \F) = (\\<^sup>+ x. f x \(density F g))" proof - have "(\\<^sup>+ x. f x * g x \F) = (\\<^sup>+ x. g x * f x \F)" by (simp add: mult.commute) also have "... = (\\<^sup>+ x. f x \(density F g))" - by (rule nn_integral_density[symmetric]) (simp_all add: assms) + by (rule nn_integral_density[symmetric], simp_all add: assms) finally show ?thesis by simp qed lemma not_AE_zero_int_ereal_E: fixes f::"'a \ ereal" assumes "AE x in M. f x \ 0" "(\\<^sup>+x. f x \M) > 0" and [measurable]: "f \ borel_measurable M" shows "\A e. A \ sets M \ e>(0::real) \ emeasure M A > 0 \ (\x \ A. f x \ e)" proof (rule not_AE_zero_ereal_E, auto simp add: assms) assume *: "AE x in M. f x = 0" have "(\\<^sup>+x. f x \M) = (\\<^sup>+x. 0 \M)" by (rule nn_integral_cong_AE, simp add: *) then have "(\\<^sup>+x. f x \M) = 0" by simp then show False using assms(2) by simp qed lemma (in finite_measure) nn_integral_bounded_eq_bound_then_AE: assumes "AE x in M. f x \ ereal c" "AE x in M. f x \ 0" "(\\<^sup>+x. f x \M) = c * emeasure M (space M)" and [measurable]: "f \ borel_measurable M" shows "AE x in M. f x = c" proof (cases) assume "emeasure M (space M) = 0" then show ?thesis using eventually_ae_filter by blast next assume "\(emeasure M (space M) = 0)" then have "c \ 0" by (metis assms(3) emeasure_le_0_iff ereal_less_eq(5) ereal_zero_le_0_iff nn_integral_nonneg) have fin: "AE x in M. abs(f x) \ \" using assms by auto def g \ "\x. c - f x" have [measurable]: "g \ borel_measurable M" unfolding g_def by auto have "(\\<^sup>+x. g x \M) = (\\<^sup>+x. c \M) - (\\<^sup>+x. f x \M)" unfolding g_def by (rule nn_integral_diff, auto simp add: assms) then have *: "(\\<^sup>+x. g x \M) = 0" using assms(3) `c \ 0` by auto have "AE x in M. g x \ 0" by (subst nn_integral_0_iff_AE[symmetric], auto simp add: *) then have "AE x in M. c \ f x" unfolding g_def using fin by auto then show ?thesis using assms(1) by auto qed subsection {*Lebesgue-Measure.thy*} text{* The next lemma is the same as \verb+lborel_distr_plus+ which is only formulated on the real line, but on any euclidean space *} lemma lborel_distr_plus2: fixes c :: "'a::euclidean_space" shows "distr lborel borel (op + c) = lborel" -by (subst lborel_affine[of 1 c]) (auto simp: density_1 one_ereal_def[symmetric]) +by (subst lborel_affine[of 1 c], auto simp: density_1 one_ereal_def[symmetric]) subsection {*Set-Integral.thy *} text{* I introduce a notation for positive set integrals, which is not available in \verb+Set_Integral.thy+. The notation I use is not directly in line with the notations in this file, they are more in line with setsum, and more readable I think. *} abbreviation "set_nn_integral M A f \ nn_integral M (\x. f x * indicator A x)" syntax "_set_nn_integral" :: "pttrn => 'a set => 'a measure => ereal => ereal" ("(\\<^sup>+((_)\(_)./ _)/\_)" [0,60,110,61] 60) "_set_lebesgue_integral" :: "pttrn => 'a set => 'a measure => ereal => ereal" ("(\((_)\(_)./ _)/\_)" [0,60,110,61] 60) translations "\\<^sup>+x \ A. f \M" == "CONST set_nn_integral M A (\x. f)" "\x \ A. f \M" == "CONST set_lebesgue_integral M A (\x. f)" lemma nn_integral_disjoint_pair: assumes [measurable]: "f \ borel_measurable M" and "AE x in M. f x \ 0" "B \ sets M" "C \ sets M" "B \ C = {}" shows "(\\<^sup>+x \ B \ C. f x \M) = (\\<^sup>+x \ B. f x \M) + (\\<^sup>+x \ C. f x \M)" proof - have mes: "\D. D \ sets M \ (\x. f x * indicator D x) \ borel_measurable M" by simp have pos: "\D. AE x in M. f x * indicator D x \ 0" using assms(2) by auto have "\x. f x * indicator (B \ C) x = f x * indicator B x + f x * indicator C x" using assms(5) by (metis ereal_indicator_nonneg ereal_right_distrib indicator_add) hence "(\\<^sup>+x. f x * indicator (B \ C) x \M) = (\\<^sup>+x. f x * indicator B x + f x * indicator C x \M)" by simp also have "... = (\\<^sup>+x. f x * indicator B x \M) + (\\<^sup>+x. f x * indicator C x \M)" by (rule nn_integral_add) (auto simp add: assms mes pos) finally show ?thesis by simp qed lemma nn_integral_disjoint_pair_countspace: assumes "\x. f x \ 0" "B \ C = {}" shows "(\\<^sup>+x \ B \ C. f x \count_space UNIV) = (\\<^sup>+x \ B. f x \count_space UNIV) + (\\<^sup>+x \ C. f x \count_space UNIV)" by (rule nn_integral_disjoint_pair) (simp_all add: assms) lemma nn_integral_null_delta: assumes "A \ sets M" "B \ sets M" "A \ B \ null_sets M" shows "(\\<^sup>+x \ A. f x \M) = (\\<^sup>+x \ B. f x \M)" proof (rule nn_integral_cong_AE, auto simp add: indicator_def) have *: "AE a in M. a \ A \ B" using assms(3) null_setsD_AE by blast thus "AE a in M. a \ A \ a \ B \ f a = 0" by auto show "AE x\A in M. x \ B \ f x = 0" using * by auto qed lemma nn_integral_disjoint_family: assumes [measurable]: "f \ borel_measurable M" "\(n::nat). B n \ sets M" and "disjoint_family B" "AE x in M. f x \ 0" shows "(\\<^sup>+x \ (\n. B n). f x \M) = (\n. (\\<^sup>+x \ B n. f x \M))" proof - - have [measurable]: "\n. (\x. f x * indicator (B n) x) \ borel_measurable M" by simp - moreover have "\n. AE x in M. f x * indicator (B n) x \ 0" using assms(4) by auto - ultimately have "(\\<^sup>+ x. (\n. f x * indicator (B n) x) \M) = (\n. (\\<^sup>+ x. f x * indicator (B n) x \M))" - by (rule nn_integral_suminf) - moreover have "\x. (\n. f x * indicator (B n) x) = f x * indicator (\n. B n) x" - proof - - fix x - show "(\n. f x * indicator (B n) x) = f x * indicator (\n. B n) x" - proof (cases) - assume "x \ (\n. B n)" - then obtain n where "x \ B n" by blast - have a: "finite {n}" by simp - have "\i. i \ n \ x \ B i" using `x \ B n` assms(3) disjoint_family_on_def - by (metis IntI UNIV_I empty_iff) - hence "\i. i \ {n} \ indicator (B i) x = (0::ereal)" using indicator_def by simp - hence b: "\i. i \ {n} \ f x * indicator (B i) x = (0::ereal)" by simp + have "(\\<^sup>+ x. (\n. f x * indicator (B n) x) \M) = (\n. (\\<^sup>+ x. f x * indicator (B n) x \M))" + apply (rule nn_integral_suminf, simp) using assms(4) by auto + moreover have "(\n. f x * indicator (B n) x) = f x * indicator (\n. B n) x" for x + proof (cases) + assume "x \ (\n. B n)" + then obtain n where "x \ B n" by blast + have a: "finite {n}" by simp + have "\i. i \ n \ x \ B i" using `x \ B n` assms(3) disjoint_family_on_def + by (metis IntI UNIV_I empty_iff) + hence "\i. i \ {n} \ indicator (B i) x = (0::ereal)" using indicator_def by simp + hence b: "\i. i \ {n} \ f x * indicator (B i) x = (0::ereal)" by simp - def h \ "\i. f x * indicator (B i) x" - hence "\i. i \ {n} \ h i = 0" using b by simp - hence "(\i. h i) = (\i\{n}. h i)" - by (metis sums_unique[OF sums_finite[OF a]]) - hence "(\i. h i) = h n" by simp - hence "(\n. f x * indicator (B n) x) = f x * indicator (B n) x" using h_def by simp - hence "(\n. f x * indicator (B n) x) = f x" using `x \ B n` indicator_def by simp - thus ?thesis using `x \ (\n. B n)` by auto - next - assume "x \ (\n. B n)" - hence "\n. f x * indicator (B n) x = 0" by simp - have "(\n. f x * indicator (B n) x) = 0" - by (simp add: `\n. f x * indicator (B n) x = 0`) - thus ?thesis using `x \ (\n. B n)` by auto - qed + def h \ "\i. f x * indicator (B i) x" + hence "\i. i \ {n} \ h i = 0" using b by simp + hence "(\i. h i) = (\i\{n}. h i)" + by (metis sums_unique[OF sums_finite[OF a]]) + hence "(\i. h i) = h n" by simp + hence "(\n. f x * indicator (B n) x) = f x * indicator (B n) x" using h_def by simp + hence "(\n. f x * indicator (B n) x) = f x" using `x \ B n` indicator_def by simp + thus ?thesis using `x \ (\n. B n)` by auto + next + assume "x \ (\n. B n)" + hence "\n. f x * indicator (B n) x = 0" by simp + have "(\n. f x * indicator (B n) x) = 0" + by (simp add: `\n. f x * indicator (B n) x = 0`) + thus ?thesis using `x \ (\n. B n)` by auto qed ultimately show ?thesis by simp qed lemma nn_set_integral_add: assumes "AE x in M. f x \ 0" "AE x in M. g x \ 0" and [measurable]: "f \ borel_measurable M" "g \ borel_measurable M" "A \ sets M" shows "(\\<^sup>+x \ A. (f x + g x) \M) = (\\<^sup>+x \ A. f x \M) + (\\<^sup>+x \ A. g x \M)" proof - have "(\\<^sup>+x \ A. (f x + g x) \M) = (\\<^sup>+x. (f x * indicator A x + g x * indicator A x) \M)" by (simp add: indicator_def nn_integral_cong_pos) also have "... = (\\<^sup>+x. f x * indicator A x \M) + (\\<^sup>+x. g x * indicator A x \M)" - proof (rule nn_integral_add) - show "AE x in M. 0 \ f x * indicator A x" using assms(1) by auto - show "AE x in M. 0 \ g x * indicator A x" using assms(2) by auto - qed (auto simp add: assms) + apply (rule nn_integral_add) using assms(1) assms(2) by auto finally show ?thesis by simp qed lemma nn_set_integral_cong: assumes "AE x in M. f x = g x" shows "(\\<^sup>+x \ A. f x \M) = (\\<^sup>+x \ A. g x \M)" -proof - - have "AE x in M. f x * indicator A x = g x * indicator A x" using assms(1) by auto - then show ?thesis by (rule nn_integral_cong_AE) -qed +apply (rule nn_integral_cong_AE) using assms(1) by auto lemma nn_set_integral_set_mono: assumes "A \ B" shows "(\\<^sup>+ x \ A. f x \M) \ (\\<^sup>+ x \ B. f x \M)" proof - def g \ "\x. max (f x) 0" have g_pos: "\x. g x \ 0" unfolding g_def by simp have "(\\<^sup>+ x \ A. f x \M) = (\\<^sup>+ x \ A. g x \M)" unfolding g_def by (simp add: indicator_def max_def nn_integral_cong_pos) also have "... \ (\\<^sup>+ x \ B. g x \M)" apply (rule nn_integral_mono_AE[where ?u = "\x. g x * indicator A x" and ?v = "\x. g x * indicator B x"] ) using assms by (simp add: g_pos ereal_mult_left_mono subset_eq) also have "... = (\\<^sup>+ x \ B. f x \M)" unfolding g_def by (simp add: indicator_def max_def nn_integral_cong_pos) finally show ?thesis by simp qed lemma nn_integral_count_compose_inj: assumes "inj_on g A" shows "(\\<^sup>+x \ A. f (g x) \count_space UNIV) = (\\<^sup>+y \ g`A. f y \count_space UNIV)" proof - have "(\\<^sup>+x \ A. f (g x) \count_space UNIV) = (\\<^sup>+x. f (g x) \count_space A)" by (auto simp add: nn_integral_count_space_indicator[symmetric]) also have "... = (\\<^sup>+y. f y \count_space (g`A))" by (simp add: assms nn_integral_bij_count_space inj_on_imp_bij_betw) also have "... = (\\<^sup>+y \ g`A. f y \count_space UNIV)" by (auto simp add: nn_integral_count_space_indicator[symmetric]) finally show ?thesis by simp qed lemma nn_integral_count_compose_bij: assumes "bij_betw g A B" shows "(\\<^sup>+x \ A. f (g x) \count_space UNIV) = (\\<^sup>+y \ B. f y \count_space UNIV)" proof - have "inj_on g A" using assms bij_betw_def by auto hence "(\\<^sup>+x \ A. f (g x) \count_space UNIV) = (\\<^sup>+y \ g`A. f y \count_space UNIV)" by (rule nn_integral_count_compose_inj) thus ?thesis using assms by (simp add: bij_betw_def) qed lemma set_integral_null_delta: fixes f::"_ \ _ :: {banach, second_countable_topology}" assumes [measurable]: "integrable M f" "A \ sets M" "B \ sets M" and "A \ B \ null_sets M" shows "(\x \ A. f x \M) = (\x \ B. f x \M)" proof (rule set_integral_cong_set, auto) have *: "AE a in M. a \ A \ B" using assms(4) null_setsD_AE by blast thus "AE x in M. (x \ B) = (x \ A)" by auto qed lemma set_integral_space: assumes "integrable M f" shows "(\ x \ space M. f x \M) = (\ x. f x \M)" by (metis (mono_tags, lifting) indicator_simps(1) integral_cong real_vector.scale_one) lemma null_if_pos_func_has_zero_nn_int: fixes f::"'a \ ereal" assumes [measurable]: "f \ borel_measurable M" "A \ sets M" and "AE x\A in M. f x > 0" "(\\<^sup>+x\A. f x \M) = 0" shows "A \ null_sets M" proof - have "AE x in M. f x * indicator A x \ 0" by (subst nn_integral_0_iff_AE[symmetric], auto simp add: assms(4)) then have "AE x\A in M. f x \ 0" by auto then have "AE x\A in M. False" using assms(3) by auto then show "A \ null_sets M" using assms(2) by (simp add: AE_iff_null_sets) qed subsection {*Radon-Nikodym.thy*} text{*The next lemma is a variant of \verb+density_unique+. Note that it uses the notation for nonnegative set integrals introduced earlier.*} lemma (in sigma_finite_measure) density_unique2: assumes f: "f \ borel_measurable M" "AE x in M. 0 \ f x" assumes f': "f' \ borel_measurable M" "AE x in M. 0 \ f' x" assumes density_eq: "\A. A \ sets M \ (\\<^sup>+ x \ A. f x \M) = (\\<^sup>+ x \ A. f' x \M)" shows "AE x in M. f x = f' x" proof (rule density_unique) show "density M f = density M f'" by (metis (no_types, lifting) density_eq emeasure_density f'(1) f(1) measure_eqI nn_integral_cong_pos sets_density) qed (auto simp add: assms) subsection {*Bochner-Integration.thy*} lemma not_AE_zero_int_E: fixes f::"'a \ real" assumes "AE x in M. f x \ 0" "(\x. f x \M) > 0" and [measurable]: "f \ borel_measurable M" shows "\A e. A \ sets M \ e>0 \ emeasure M A > 0 \ (\x \ A. f x \ e)" proof (rule not_AE_zero_E, auto simp add: assms) assume *: "AE x in M. f x = 0" have "(\x. f x \M) = (\x. 0 \M)" by (rule integral_cong_AE, auto simp add: *) then have "(\x. f x \M) = 0" by simp then show False using assms(2) by simp qed lemma null_if_pos_func_has_zero_int: assumes [measurable]: "integrable M f" "A \ sets M" and "AE x\A in M. f x > 0" "(\x\A. f x \M) = (0::real)" shows "A \ null_sets M" proof - have "AE x in M. indicator A x * f x = 0" apply (subst integral_nonneg_eq_0_iff_AE[symmetric]) using assms integrable_mult_indicator[OF `A \ sets M` assms(1)] by auto then have "AE x\A in M. f x = 0" by auto then have "AE x\A in M. False" using assms(3) by auto then show "A \ null_sets M" using assms(2) by (simp add: AE_iff_null_sets) qed lemma (in finite_measure) integral_bounded_eq_bound_then_AE: assumes "AE x in M. f x \ (c::real)" "integrable M f" "(\x. f x \M) = c * measure M (space M)" shows "AE x in M. f x = c" proof - def g \ "\x. c - f x" have "AE x in M. g x = 0" apply (subst integral_nonneg_eq_0_iff_AE[symmetric]) unfolding g_def using assms by auto then show ?thesis unfolding g_def by auto qed text {* The next lemma implies the same statement for Banach-space valued functions using Hahn-Banach theorem and linear forms. Since they are not yet easily available, I only formulate it for real-valued functions.*} lemma density_unique_real: fixes f f'::"_ \ real" assumes [measurable]: "integrable M f" "integrable M f'" assumes density_eq: "\A. A \ sets M \ (\x \ A. f x \M) = (\x \ A. f' x \M)" shows "AE x in M. f x = f' x" proof - def A \ "{x \ space M. f x < f' x}" then have [measurable]: "A \ sets M" by simp have "(\x \ A. (f' x - f x) \M) = (\x \ A. f' x \M) - (\x \ A. f x \M)" using `A \ sets M` assms(1) assms(2) integrable_mult_indicator by blast then have "(\x \ A. (f' x - f x) \M) = 0" using assms(3) by simp then have "A \ null_sets M" using A_def null_if_pos_func_has_zero_int[where ?f = "\x. f' x - f x" and ?A = A] assms by auto then have "AE x in M. x \ A" by (simp add: null_setsD_AE) then have *: "AE x in M. f' x \ f x" unfolding A_def by auto def B \ "{x \ space M. f' x < f x}" then have [measurable]: "B \ sets M" by simp have "(\x \ B. (f x - f' x) \M) = (\x \ B. f x \M) - (\x \ B. f' x \M)" using `B \ sets M` assms(1) assms(2) integrable_mult_indicator by blast then have "(\x \ B. (f x - f' x) \M) = 0" using assms(3) by simp then have "B \ null_sets M" using B_def null_if_pos_func_has_zero_int[where ?f = "\x. f x - f' x" and ?A = B] assms by auto then have "AE x in M. x \ B" by (simp add: null_setsD_AE) then have "AE x in M. f' x \ f x" unfolding B_def by auto then show ?thesis using * by auto qed lemma integrable_Max: fixes f::"_ \ 'a \ real" assumes [measurable]: "\i. integrable M (f i)" and "finite I" "I\{}" shows "integrable M (\x. Max {f i x|i. i\I})" proof (rule integrable_bound[where ?f = "\x. (\i\I. abs(f i x))"]) show "integrable M (\x. \i\I. \f i x\)" by (rule integrable_setsum, auto simp add: assms) - { - fix x - have "\Max {f i x |i. i \ I}\ \ (\i\I. \f i x\)" - by (metis simple_image abs_Max_sum2[OF assms(2) assms(3), of "\i. f i x"]) - } + have "\Max {f i x |i. i \ I}\ \ (\i\I. \f i x\)" for x + by (metis simple_image abs_Max_sum2[OF assms(2) assms(3), of "\i. f i x"]) then show "AE x in M. norm (Max {f i x |i. i \ I}) \ norm (\i\I. \f i x\)" by auto qed (simp add: assms) lemma tendsto_L1_int: fixes u :: "_ \ _ \ 'b::{banach, second_countable_topology}" assumes [measurable]: "\n. integrable M (u n)" "integrable M f" and "((\n. (\\<^sup>+x. norm(u n x - f x) \M)) \ 0) F" shows "((\n. (\x. u n x \M)) \ (\x. f x \M)) F" proof - have "((\n. norm((\x. u n x \M) - (\x. f x \M))) \ (0::ereal)) F" proof (rule tendsto_sandwich[of "\_. 0", where ?h = "\n. (\\<^sup>+x. norm(u n x - f x) \M)"], auto simp add: assms) { fix n have "(\x. u n x \M) - (\x. f x \M) = (\x. u n x - f x \M)" apply (rule integral_diff[symmetric]) using assms by auto then have "norm((\x. u n x \M) - (\x. f x \M)) = norm (\x. u n x - f x \M)" by auto also have "... \ (\x. norm(u n x - f x) \M)" apply (rule integral_norm_bound) using assms by auto finally have "ereal(norm((\x. u n x \M) - (\x. f x \M))) \ (\x. norm(u n x - f x) \M)" by simp also have "... = (\\<^sup>+x. norm(u n x - f x) \M)" apply (rule nn_integral_eq_integral[symmetric]) using assms by auto finally have "norm((\x. u n x \M) - (\x. f x \M)) \ (\\<^sup>+x. norm(u n x - f x) \M)" by simp } then show "eventually (\n. norm((\x. u n x \M) - (\x. f x \M)) \ (\\<^sup>+x. norm(u n x - f x) \M)) F" by auto qed then have "((\n. norm((\x. u n x \M) - (\x. f x \M))) \ 0) F" by (simp add: zero_ereal_def) then have "((\n. ((\x. u n x \M) - (\x. f x \M))) \ 0) F" using tendsto_norm_zero_iff by blast then show ?thesis using Lim_null by auto qed +text {*The next lemma asserts that, if a sequence of functions converges in $L^1$, then +it admits a subsequence that converges almost everywhere.*} + lemma tendsto_L1_AE_subseq: fixes u :: "nat \ 'a \ 'b::{banach, second_countable_topology}" assumes [measurable]: "\n. integrable M (u n)" and "(\n. (\x. norm(u n x) \M)) \ 0" shows "\r. subseq r \ (AE x in M. (\n. u (r n) x) \ 0)" proof - { fix k have "eventually (\n. (\x. norm(u n x) \M) < (1/2)^k) sequentially" using order_tendstoD(2)[OF assms(2)] by auto with eventually_elim2[OF eventually_gt_at_top[of k] this] have "\n>k. (\x. norm(u n x) \M) < (1/2)^k" by (metis eventually_False_sequentially) } then have "\r. \n. True \ (r (Suc n) > r n \ (\x. norm(u (r (Suc n)) x) \M) < (1/2)^(r n))" by (intro dependent_nat_choice, auto) then obtain r0 where r0: "subseq r0" "\n. (\x. norm(u (r0 (Suc n)) x) \M) < (1/2)^(r0 n)" by (auto simp: subseq_Suc_iff) def r \ "\n. r0(n+1)" have "subseq r" unfolding r_def using r0(1) by (simp add: subseq_Suc_iff) have I: "(\\<^sup>+x. norm(u (r n) x) \M) < ereal((1/2)^n)" for n proof - have "r0 n \ n" using `subseq r0` by (simp add: seq_suble) have "(1/2::real)^(r0 n) \ (1/2)^n" by (rule power_decreasing[OF `r0 n \ n`], auto) then have "(\x. norm(u (r0 (Suc n)) x) \M) < (1/2)^n" using r0(2) less_le_trans by auto then have "(\x. norm(u (r n) x) \M) < (1/2)^n" unfolding r_def by auto moreover have "(\\<^sup>+x. norm(u (r n) x) \M) = (\x. norm(u (r n) x) \M)" by (rule nn_integral_eq_integral, auto simp add: integrable_norm[OF assms(1)[of "r n"]]) ultimately show ?thesis by auto qed { fix e::real assume "e > 0" def A \ "\n. {x \ space M. norm(u (r n) x) \ e}" have A_meas [measurable]: "\n. A n \ sets M" unfolding A_def by auto have A_bound: "emeasure M (A n) < (1/e) * ereal((1/2)^n)" for n proof - have *: "indicator (A n) x \ (1/e) * ereal(norm(u (r n) x))" for x apply (cases "x \ A n") unfolding A_def using \0 < e\ by auto have "emeasure M (A n) = (\\<^sup>+x. indicator (A n) x \M)" by auto also have "... \ (\\<^sup>+x. (1/e) * ereal(norm(u (r n) x)) \M)" apply (rule nn_integral_mono) using * by auto also have "... = (1/e) * (\\<^sup>+x. norm(u (r n) x) \M)" apply (rule nn_integral_cmult) using `e > 0` by auto also have "... < (1/e) * ereal((1/2)^n)" apply (rule ereal_mult_strict_left_mono) using I[of n] `e > 0` by auto finally show ?thesis by simp qed then have A_fin: "emeasure M (A n) < \" for n using `e>0` by (metis ereal_infty_less(1) less_ereal.simps(2)) have A_sum: "summable (\n. measure M (A n))" proof (rule summable_comparison_test'[of "\n. (1/e) * (1/2)^n" 0]) have "summable (\n. (1/(2::real))^n)" by (simp add: summable_geometric) then show "summable (\n. (1/e) * (1/2)^n)" using summable_mult by blast fix n::nat assume "n \ 0" have "norm(measure M (A n)) = measure M (A n)" by (simp add: measure_nonneg) also have "... = real_of_ereal(emeasure M (A n))" unfolding measure_def by simp also have "... < real_of_ereal( (1/e) * ereal((1/2)^n))" using A_bound[of n] by (metis \\n. emeasure M (A n) < \\ emeasure_eq_ereal_measure ereal_infty_less(1) less_ereal.simps(1) real_of_ereal.simps(1) times_ereal.simps(1)) also have "... = (1/e) * (1/2)^n" by auto finally show "norm(measure M (A n)) \ (1/e) * (1/2)^n" by simp qed have "AE x in M. eventually (\n. x \ space M - A n) sequentially" by (rule borel_cantelli_AE1[OF A_meas A_fin A_sum]) moreover { fix x assume "eventually (\n. x \ space M - A n) sequentially" moreover have "norm(u (r n) x) \ ereal e" if "x \ space M - A n" for n using that unfolding A_def by auto ultimately have "eventually (\n. norm(u (r n) x) \ ereal e) sequentially" by (simp add: eventually_mono) then have "limsup (\n. norm(u (r n) x)) \ e" by (simp add: Limsup_bounded) } ultimately have "AE x in M. limsup (\n. norm(u (r n) x)) \ 0 + ereal e" by auto } with AE_upper_bound_inf_ereal2[OF this] have "AE x in M. limsup (\n. norm(u (r n) x)) \ 0" by auto moreover { fix x assume "limsup (\n. norm(u (r n) x)) \ 0" moreover have "liminf (\n. norm(u (r n) x)) \ 0" by (rule Liminf_bounded, auto) ultimately have "(\n. norm(u (r n) x)) \ (0::ereal)" by (simp add: limsup_le_liminf_real zero_ereal_def) then have "(\n. norm(u (r n) x)) \ 0" by (simp add: zero_ereal_def) then have "(\n. u (r n) x) \ 0" by (simp add: tendsto_norm_zero_iff) } ultimately have "AE x in M. (\n. u (r n) x) \ 0" by auto then show ?thesis using `subseq r` by auto qed text {* The next lemma shows that $L^1$ convergence of a sequence of functions follows from almost everywhere convergence and the weaker condition of the convergence of the integrated norms (or even just the nontrivial inequality about them). Useful in a lot of contexts! This statement (or its variations) are known as Scheffe lemma. Informal quick textbook proof: Let $G_n(x) = \norm{f x} + \norm{F_n x} - \norm{(f-F_n)(x)}$. Then $\int \liminf G_n \leq \liminf \int G_n$ by Fatou, i.e., $2 \int \norm{f} \leq 2 \int \norm{f} + \liminf (- \int \norm{f-F_n})$, hence $\limsup \int \norm{f-F_n} \leq 0$. QED The formalization is more painful as one should jump back and forth between reals and ereals and justify all the time positivity or integrability (thankfully, measurability is handled more or less automatically).*} lemma Scheffe_lemma1: - assumes "\ n. integrable M (F n)" "integrable M f" + assumes "\ n. integrable M (F n)" "integrable M f" "AE x in M. (\n. F n x) \ f x" "limsup (\n. \\<^sup>+ x. norm(F n x) \M) \ (\\<^sup>+ x. norm(f x) \M)" - shows "(\n. \\<^sup>+ x. norm(F n x - f x) \M) \ 0" + shows "(\n. \\<^sup>+ x. norm(F n x - f x) \M) \ 0" proof - have [measurable]: "\n. (\x. norm(F n x)) \ borel_measurable M" "(\x. norm(f x)) \ borel_measurable M" "\n. (\x. norm(F n x - f x)) \ borel_measurable M" using assms(1) assms(2) by simp_all def G \ "\n x. norm(f x) + norm(F n x) - norm(F n x - f x)" have [measurable]: "\n. G n \ borel_measurable M" unfolding G_def by simp have G_pos: "\n x. G n x \ 0" unfolding G_def by (metis ge_iff_diff_ge_0 norm_minus_commute norm_triangle_ineq4) have finint: "(\\<^sup>+ x. norm(f x) \M) \ \" using assms(2) ereal_infty_less(1) has_bochner_integral_implies_finite_norm has_bochner_integral_integrable by blast then have fin2: "abs(2 * (\\<^sup>+ x. norm(f x) \M)) \ \" by auto { fix x assume *: "(\n. F n x) \ f x" then have "(\n. norm(F n x)) \ norm(f x)" using tendsto_norm by blast moreover have "(\n. norm(F n x - f x)) \ 0" using * Lim_null tendsto_norm_zero_iff by fastforce ultimately have a: "(\n. norm(F n x) - norm(F n x - f x)) \ norm(f x)" using tendsto_diff by fastforce have "(\n. norm(f x) + (norm(F n x) - norm(F n x - f x))) \ norm(f x) + norm(f x)" by (rule tendsto_add) (auto simp add: a) moreover have "\n. G n x = norm(f x) + (norm(F n x) - norm(F n x - f x))" unfolding G_def by simp ultimately have "(\n. G n x) \ 2 * norm(f x)" by simp then have "(\n. ereal(G n x)) \ 2 * ereal(norm(f x))" by simp then have "liminf (\n. ereal(G n x)) = 2 * ereal(norm(f x))" using sequentially_bot tendsto_iff_Liminf_eq_Limsup by blast } then have "AE x in M. liminf (\n. ereal(G n x)) = 2 * ereal(norm(f x))" using assms(3) by auto then have "(\\<^sup>+ x. liminf (\n. G n x) \M) = (\\<^sup>+ x. 2 * ereal(norm(f x)) \M)" by (simp add: nn_integral_cong_AE) also have "... = 2 * (\\<^sup>+ x. norm(f x) \M)" by (rule nn_integral_cmult, auto) finally have int_liminf: "(\\<^sup>+ x. liminf (\n. G n x) \M) = 2 * (\\<^sup>+ x. norm(f x) \M)" by simp - { - fix n - have "(\\<^sup>+x. ereal(norm(f x)) + ereal(norm(F n x)) \M) = (\\<^sup>+x. norm(f x) \M) + (\\<^sup>+x. norm(F n x) \M)" - by (rule nn_integral_add) (auto simp add: assms) - } - then have "limsup (\n. (\\<^sup>+x. ereal(norm(f x)) + ereal(norm(F n x)) \M)) = limsup (\n. (\\<^sup>+x. norm(f x) \M) + (\\<^sup>+x. norm(F n x) \M))" + have "(\\<^sup>+x. ereal(norm(f x)) + ereal(norm(F n x)) \M) = (\\<^sup>+x. norm(f x) \M) + (\\<^sup>+x. norm(F n x) \M)" for n + by (rule nn_integral_add) (auto simp add: assms) + then have "limsup (\n. (\\<^sup>+x. ereal(norm(f x)) + ereal(norm(F n x)) \M)) = limsup (\n. (\\<^sup>+x. norm(f x) \M) + (\\<^sup>+x. norm(F n x) \M))" by simp also have "... = (\\<^sup>+x. norm(f x) \M) + limsup (\n. (\\<^sup>+x. norm(F n x) \M))" by (rule ereal_limsup_lim_add, auto simp add: finint) - also have "... \ (\\<^sup>+x. norm(f x) \M) + (\\<^sup>+x. norm(f x) \M)" + also have "... \ (\\<^sup>+x. norm(f x) \M) + (\\<^sup>+x. norm(f x) \M)" using assms(4) by (simp add: add_left_mono) also have "... = 2 * (\\<^sup>+x. norm(f x) \M)" by (metis ereal_left_distrib lambda_one one_add_one zero_less_one_ereal) ultimately have a: "limsup (\n. (\\<^sup>+x. ereal(norm(f x)) + ereal(norm(F n x)) \M)) \ 2 * (\\<^sup>+x. norm(f x) \M)" by simp { fix n have "\x. ereal(G n x) = ereal(norm(f x)) + ereal(norm(F n x)) - ereal(norm(F n x - f x))" unfolding G_def by simp moreover have "(\\<^sup>+x. ereal(norm(f x)) + ereal(norm(F n x)) - ereal(norm(F n x - f x)) \M) = (\\<^sup>+x. ereal(norm(f x)) + ereal(norm(F n x)) \M) - (\\<^sup>+x. norm(F n x - f x) \M)" proof (rule nn_integral_diff) have "\x. ereal (norm (F n x - f x)) \ ereal (norm (f x)) + ereal (norm (F n x))" by (simp add: norm_minus_commute norm_triangle_ineq4) then show "AE x in M. ereal (norm (F n x - f x)) \ ereal (norm (f x)) + ereal (norm (F n x))" by simp then have "(\\<^sup>+x. ereal (norm (F n x - f x)) \M) \ (\\<^sup>+x. ereal(norm(f x)) + ereal(norm(F n x)) \M)" by (simp add: nn_integral_mono_AE) then have "(\\<^sup>+x. ereal (norm (F n x - f x)) \M) < \" using assms(1) assms(2) by (metis has_bochner_integral_implies_finite_norm integrable.simps integrable_diff) then show "(\\<^sup>+x. ereal (norm (F n x - f x)) \M) \ \" by simp qed (auto simp add: assms) ultimately have "(\\<^sup>+x. G n x \M) = - (\\<^sup>+x. norm(F n x - f x) \M) + (\\<^sup>+x. ereal(norm(f x)) + ereal(norm(F n x)) \M)" using add.commute minus_ereal_def by auto } then have "liminf (\n. (\\<^sup>+x. G n x \M)) = liminf (\n. - (\\<^sup>+x. norm(F n x - f x) \M) + (\\<^sup>+x. ereal(norm(f x)) + ereal(norm(F n x)) \M))" by simp also have "... \ liminf (\n. - (\\<^sup>+x. norm(F n x - f x) \M)) + limsup (\n. (\\<^sup>+x. ereal(norm(f x)) + ereal(norm(F n x)) \M))" by (rule ereal_liminf_limsup_add) also have "... \ liminf (\n. - (\\<^sup>+x. norm(F n x - f x) \M)) + 2 * (\\<^sup>+x. norm(f x) \M)" using a by (simp add: add_left_mono) also have "... = - limsup (\n. (\\<^sup>+x. norm(F n x - f x) \M)) + 2 * (\\<^sup>+x. norm(f x) \M) " by (simp add: ereal_Liminf_uminus minus_ereal_def) finally have liminf_int: "liminf (\n. (\\<^sup>+x. G n x \M)) \ - limsup (\n. (\\<^sup>+x. norm(F n x - f x) \M)) + 2 * (\\<^sup>+x. norm(f x) \M) " using add.commute by simp have "(\\<^sup>+ x. liminf (\n. G n x) \M) \ liminf (\n. (\\<^sup>+x. G n x \M))" by (rule nn_integral_liminf) (auto simp add: G_pos) then have "2 * (\\<^sup>+x. norm(f x) \M) \ - limsup (\n. (\\<^sup>+x. norm(F n x - f x) \M)) + 2 * (\\<^sup>+x. norm(f x) \M)" using int_liminf liminf_int by simp then have "2 * (\\<^sup>+x. norm(f x) \M) - 2 * (\\<^sup>+x. norm(f x) \M) \ - limsup (\n. (\\<^sup>+x. norm(F n x - f x) \M))" using fin2 ereal_minus_le by presburger then have i: "limsup (\n. (\\<^sup>+x. norm(F n x - f x) \M)) \ 0" using fin2 by auto have r: "\a b. a \ b \ b \ (0::ereal) \ 0 \ a \ a = 0 \ b = 0" by auto have "liminf (\n. (\\<^sup>+x. norm(F n x - f x) \M)) = 0 \ limsup (\n. (\\<^sup>+x. norm(F n x - f x) \M)) = 0" proof (rule r) have *: "\n. (\\<^sup>+x. norm(F n x - f x) \M) \ 0" using nn_integral_nonneg by auto have "liminf (\n. (\\<^sup>+x. norm(F n x - f x) \M)) \ liminf (\n. 0)" using always_eventually[OF *] Liminf_mono by force then show "liminf (\n. (\\<^sup>+x. norm(F n x - f x) \M)) \ 0" by (metis (mono_tags) sequentially_bot tendsto_const tendsto_iff_Liminf_eq_Limsup) qed (auto simp add: Liminf_le_Limsup i) then show ?thesis using tendsto_iff_Liminf_eq_Limsup trivial_limit_sequentially by blast qed lemma Scheffe_lemma2: fixes F::"nat \ 'a \ 'b::{banach, second_countable_topology}" - assumes "\ n::nat. F n \ borel_measurable M" "integrable M f" - "AE x in M. (\n. F n x) \ f x" - "\n. (\\<^sup>+ x. norm(F n x) \M) \ (\\<^sup>+ x. norm(f x) \M)" - shows "(\n. \\<^sup>+ x. norm(F n x - f x) \M) \ 0" + assumes "\ n::nat. F n \ borel_measurable M" "integrable M f" + "AE x in M. (\n. F n x) \ f x" + "\n. (\\<^sup>+ x. norm(F n x) \M) \ (\\<^sup>+ x. norm(f x) \M)" + shows "(\n. \\<^sup>+ x. norm(F n x - f x) \M) \ 0" proof (rule Scheffe_lemma1) fix n::nat - have " (\\<^sup>+ x. norm(f x) \M) < \" using assms(2) by (metis has_bochner_integral_implies_finite_norm integrable.cases) - then have " (\\<^sup>+ x. norm(F n x) \M) < \" using assms(4)[of n] by auto + have "(\\<^sup>+ x. norm(f x) \M) < \" using assms(2) by (metis has_bochner_integral_implies_finite_norm integrable.cases) + then have "(\\<^sup>+ x. norm(F n x) \M) < \" using assms(4)[of n] by auto then show "integrable M (F n)" by (subst integrable_iff_bounded, simp add: assms(1)[of n]) qed (auto simp add: assms Limsup_bounded) end