diff -r 3de230ed0547 -r c9adb50f74ad src/HOL/Library/Extended_Real.thy --- a/src/HOL/Library/Extended_Real.thy Thu Jan 31 11:31:27 2013 +0100 +++ b/src/HOL/Library/Extended_Real.thy Thu Jan 31 11:31:30 2013 +0100 @@ -8,9 +8,32 @@ header {* Extended real number line *} theory Extended_Real -imports Complex_Main Extended_Nat +imports "~~/src/HOL/Complex_Main" Extended_Nat begin +lemma LIMSEQ_SUP: + fixes X :: "nat \ 'a :: {complete_linorder, linorder_topology}" + assumes "incseq X" + shows "X ----> (SUP i. X i)" + using `incseq X` + by (intro increasing_tendsto) + (auto simp: SUP_upper less_SUP_iff incseq_def eventually_sequentially intro: less_le_trans) + +lemma eventually_const: "\ trivial_limit net \ eventually (\x. P) net \ P" + by (cases P) (simp_all add: eventually_False) + +lemma (in complete_lattice) Inf_le_Sup: + assumes "A \ {}" shows "Inf A \ Sup A" +proof - + from `A \ {}` obtain x where "x \ A" by auto + then show ?thesis + by (metis Sup_upper2 Inf_lower) +qed + +lemma (in complete_lattice) INF_le_SUP: + "A \ {} \ INFI A f \ SUPR A f" + unfolding INF_def SUP_def by (rule Inf_le_Sup) auto + text {* For more lemmas about the extended real numbers go to @@ -18,6 +41,26 @@ *} +lemma (in complete_lattice) Sup_eqI: + assumes "\y. y \ A \ y \ x" + assumes "\y. (\z. z \ A \ z \ y) \ x \ y" + shows "Sup A = x" + by (metis antisym Sup_least Sup_upper assms) + +lemma (in complete_lattice) Inf_eqI: + assumes "\i. i \ A \ x \ i" + assumes "\y. (\i. i \ A \ y \ i) \ y \ x" + shows "Inf A = x" + by (metis antisym Inf_greatest Inf_lower assms) + +lemma (in complete_lattice) SUP_eqI: + "(\i. i \ A \ f i \ x) \ (\y. (\i. i \ A \ f i \ y) \ x \ y) \ (SUP i:A. f i) = x" + unfolding SUP_def by (rule Sup_eqI) auto + +lemma (in complete_lattice) INF_eqI: + "(\i. i \ A \ x \ f i) \ (\y. (\i. i \ A \ f i \ y) \ x \ y) \ (INF i:A. f i) = x" + unfolding INF_def by (rule Inf_eqI) auto + lemma (in complete_lattice) atLeast_eq_UNIV_iff: "{x..} = UNIV \ x = bot" proof assume "{x..} = UNIV" @@ -1353,22 +1396,6 @@ unfolding Sup_ereal_def by (auto intro!: Least_equality) -lemma ereal_SUPI: - fixes x :: ereal - assumes "!!i. i : A ==> f i <= x" - assumes "!!y. (!!i. i : A ==> f i <= y) ==> x <= y" - shows "(SUP i:A. f i) = x" - unfolding SUP_def Sup_ereal_def - using assms by (auto intro!: Least_equality) - -lemma ereal_INFI: - fixes x :: ereal - assumes "!!i. i : A ==> f i >= x" - assumes "!!y. (!!i. i : A ==> f i >= y) ==> x >= y" - shows "(INF i:A. f i) = x" - unfolding INF_def Inf_ereal_def - using assms by (auto intro!: Greatest_equality) - lemma Sup_ereal_close: fixes e :: ereal assumes "0 < e" and S: "\Sup S\ \ \" "S \ {}" @@ -1476,6 +1503,17 @@ using assms by (metis SUP_least SUP_upper2) qed +lemma INFI_eq: + assumes "\i\A. \j\B. f i \ g j" + assumes "\j\B. \i\A. g j \ f i" + shows "(INF i:A. f i) = (INF j:B. g j)" +proof (intro antisym) + show "(INF i:A. f i) \ (INF j:B. g j)" + using assms by (metis INF_greatest INF_lower2) + show "(INF i:B. g i) \ (INF j:A. f j)" + using assms by (metis INF_greatest INF_lower2) +qed + lemma SUP_ereal_le_addI: fixes f :: "'i \ ereal" assumes "\i. f i + y \ z" and "y \ -\" @@ -1491,7 +1529,7 @@ fixes f g :: "nat \ ereal" assumes "incseq f" "incseq g" and pos: "\i. f i \ -\" "\i. g i \ -\" shows "(SUP i. f i + g i) = SUPR UNIV f + SUPR UNIV g" -proof (rule ereal_SUPI) +proof (rule SUP_eqI) fix y assume *: "\i. i \ UNIV \ f i + g i \ y" have f: "SUPR UNIV f \ -\" using pos unfolding SUP_def Sup_eq_MInfty by (auto dest: image_eqD) @@ -1531,7 +1569,7 @@ lemma SUPR_ereal_cmult: fixes f :: "nat \ ereal" assumes "\i. 0 \ f i" "0 \ c" shows "(SUP i. c * f i) = c * SUPR UNIV f" -proof (rule ereal_SUPI) +proof (rule SUP_eqI) fix i have "f i \ SUPR UNIV f" by (rule SUP_upper) auto then show "c * f i \ c * SUPR UNIV f" using `0 \ c` by (rule ereal_mult_left_mono) @@ -1598,7 +1636,7 @@ qed from choice[OF this] guess f .. note f = this have "SUPR UNIV f = Sup A" - proof (rule ereal_SUPI) + proof (rule SUP_eqI) fix i show "f i \ Sup A" using f by (auto intro!: complete_lattice_class.Sup_upper) next @@ -1801,18 +1839,84 @@ subsubsection "Topological space" -instantiation ereal :: topological_space +instantiation ereal :: linorder_topology begin -definition "open A \ open (ereal -` A) - \ (\ \ A \ (\x. {ereal x <..} \ A)) - \ (-\ \ A \ (\x. {.. A))" +definition "open_ereal" :: "ereal set \ bool" where + open_ereal_generated: "open_ereal = generate_topology (range lessThan \ range greaterThan)" + +instance + by default (simp add: open_ereal_generated) +end lemma open_PInfty: "open A \ \ \ A \ (\x. {ereal x<..} \ A)" - unfolding open_ereal_def by auto + unfolding open_ereal_generated +proof (induct rule: generate_topology.induct) + case (Int A B) + moreover then obtain x z where "\ \ A \ {ereal x <..} \ A" "\ \ B \ {ereal z <..} \ B" + by auto + ultimately show ?case + by (intro exI[of _ "max x z"]) fastforce +next + { fix x have "x \ \ \ \t. x \ ereal t" by (cases x) auto } + moreover case (Basis S) + ultimately show ?case + by (auto split: ereal.split) +qed (fastforce simp add: vimage_Union)+ lemma open_MInfty: "open A \ -\ \ A \ (\x. {.. A)" - unfolding open_ereal_def by auto + unfolding open_ereal_generated +proof (induct rule: generate_topology.induct) + case (Int A B) + moreover then obtain x z where "-\ \ A \ {..< ereal x} \ A" "-\ \ B \ {..< ereal z} \ B" + by auto + ultimately show ?case + by (intro exI[of _ "min x z"]) fastforce +next + { fix x have "x \ - \ \ \t. ereal t \ x" by (cases x) auto } + moreover case (Basis S) + ultimately show ?case + by (auto split: ereal.split) +qed (fastforce simp add: vimage_Union)+ + +lemma open_ereal_vimage: "open S \ open (ereal -` S)" + unfolding open_ereal_generated +proof (induct rule: generate_topology.induct) + case (Int A B) then show ?case by auto +next + { fix x have + "ereal -` {.. UNIV | MInfty \ {} | ereal r \ {.. {} | MInfty \ UNIV | ereal r \ {r<..})" + by (induct x) auto } + moreover case (Basis S) + ultimately show ?case + by (auto split: ereal.split) +qed (fastforce simp add: vimage_Union)+ + +lemma open_ereal: "open S \ open (ereal ` S)" + unfolding open_generated_order[where 'a=real] +proof (induct rule: generate_topology.induct) + case (Basis S) + moreover { fix x have "ereal ` {..< x} = { -\ <..< ereal x }" by auto (case_tac xa, auto) } + moreover { fix x have "ereal ` {x <..} = { ereal x <..< \ }" by auto (case_tac xa, auto) } + ultimately show ?case + by auto +qed (auto simp add: image_Union image_Int) + +lemma open_ereal_def: "open A \ open (ereal -` A) \ (\ \ A \ (\x. {ereal x <..} \ A)) \ (-\ \ A \ (\x. {.. A))" + (is "open A \ ?rhs") +proof + assume "open A" then show ?rhs + using open_PInfty open_MInfty open_ereal_vimage by auto +next + assume "?rhs" + then obtain x y where A: "open (ereal -` A)" "\ \ A \ {ereal x<..} \ A" "-\ \ A \ {..< ereal y} \ A" + by auto + have *: "A = ereal ` (ereal -` A) \ (if \ \ A then {ereal x<..} else {}) \ (if -\ \ A then {..< ereal y} else {})" + using A(2,3) by auto + from open_ereal[OF A(1)] show "open A" + by (subst *) (auto simp: open_Un) +qed lemma open_PInfty2: assumes "open A" "\ \ A" obtains x where "{ereal x<..} \ A" using open_PInfty[OF assms] by auto @@ -1821,85 +1925,17 @@ using open_MInfty[OF assms] by auto lemma ereal_openE: assumes "open A" obtains x y where - "open (ereal -` A)" - "\ \ A \ {ereal x<..} \ A" - "-\ \ A \ {.. A" + "open (ereal -` A)" "\ \ A \ {ereal x<..} \ A" "-\ \ A \ {.. A" using assms open_ereal_def by auto -instance -proof - let ?U = "UNIV::ereal set" - show "open ?U" unfolding open_ereal_def - by (auto intro!: exI[of _ 0]) -next - fix S T::"ereal set" assume "open S" and "open T" - from `open S`[THEN ereal_openE] guess xS yS . - moreover from `open T`[THEN ereal_openE] guess xT yT . - ultimately have - "open (ereal -` (S \ T))" - "\ \ S \ T \ {ereal (max xS xT) <..} \ S \ T" - "-\ \ S \ T \ {..< ereal (min yS yT)} \ S \ T" - by auto - then show "open (S Int T)" unfolding open_ereal_def by blast -next - fix K :: "ereal set set" assume "\S\K. open S" - then have *: "\S. \x y. S \ K \ open (ereal -` S) \ - (\ \ S \ {ereal x <..} \ S) \ (-\ \ S \ {..< ereal y} \ S)" - by (auto simp: open_ereal_def) - then show "open (Union K)" unfolding open_ereal_def - proof (intro conjI impI) - show "open (ereal -` \K)" - using *[THEN choice] by (auto simp: vimage_Union) - qed ((metis UnionE Union_upper subset_trans *)+) -qed -end - -lemma open_ereal: "open S \ open (ereal ` S)" - by (auto simp: inj_vimage_image_eq open_ereal_def) - -lemma open_ereal_vimage: "open S \ open (ereal -` S)" - unfolding open_ereal_def by auto - -lemma open_ereal_lessThan[intro, simp]: "open {..< a :: ereal}" -proof - - have "\x. ereal -` {..} = UNIV" "ereal -` {..< -\} = {}" by auto - then show ?thesis by (cases a) (auto simp: open_ereal_def) -qed - -lemma open_ereal_greaterThan[intro, simp]: - "open {a :: ereal <..}" -proof - - have "\x. ereal -` {ereal x<..} = {x<..}" - "ereal -` {\<..} = {}" "ereal -` {-\<..} = UNIV" by auto - then show ?thesis by (cases a) (auto simp: open_ereal_def) -qed - -lemma ereal_open_greaterThanLessThan[intro, simp]: "open {a::ereal <..< b}" - unfolding greaterThanLessThan_def by auto - -lemma closed_ereal_atLeast[simp, intro]: "closed {a :: ereal ..}" -proof - - have "- {a ..} = {..< a}" by auto - then show "closed {a ..}" - unfolding closed_def using open_ereal_lessThan by auto -qed - -lemma closed_ereal_atMost[simp, intro]: "closed {.. b :: ereal}" -proof - - have "- {.. b} = {b <..}" by auto - then show "closed {.. b}" - unfolding closed_def using open_ereal_greaterThan by auto -qed - -lemma closed_ereal_atLeastAtMost[simp, intro]: - shows "closed {a :: ereal .. b}" - unfolding atLeastAtMost_def by auto - -lemma closed_ereal_singleton: - "closed {a :: ereal}" -by (metis atLeastAtMost_singleton closed_ereal_atLeastAtMost) - +lemmas open_ereal_lessThan = open_lessThan[where 'a=ereal] +lemmas open_ereal_greaterThan = open_greaterThan[where 'a=ereal] +lemmas ereal_open_greaterThanLessThan = open_greaterThanLessThan[where 'a=ereal] +lemmas closed_ereal_atLeast = closed_atLeast[where 'a=ereal] +lemmas closed_ereal_atMost = closed_atMost[where 'a=ereal] +lemmas closed_ereal_atLeastAtMost = closed_atLeastAtMost[where 'a=ereal] +lemmas closed_ereal_singleton = closed_singleton[where 'a=ereal] + lemma ereal_open_cont_interval: fixes S :: "ereal set" assumes "open S" "x \ S" "\x\ \ \" @@ -1928,28 +1964,6 @@ show thesis by auto qed -instance ereal :: t2_space -proof - fix x y :: ereal assume "x ~= y" - let "?P x (y::ereal)" = "EX U V. open U & open V & x : U & y : V & U Int V = {}" - - { fix x y :: ereal assume "x < y" - from ereal_dense[OF this] obtain z where z: "x < z" "z < y" by auto - have "?P x y" - apply (rule exI[of _ "{.. \ <-> (ALL B. EX N. ALL n>=N. f n >= ereal B)" (is "?l = ?r") -proof - assume ?r - show ?l - apply(rule topological_tendstoI) - unfolding eventually_sequentially - proof- - fix S :: "ereal set" assume "open S" "\ : S" - from open_PInfty[OF this] guess B .. note B=this - from `?r`[rule_format,of "B+1"] guess N .. note N=this - show "EX N. ALL n>=N. f n : S" apply(rule_tac x=N in exI) - proof safe case goal1 - have "ereal B < ereal (B + 1)" by auto - also have "... <= f n" using goal1 N by auto - finally show ?case using B by fastforce - qed - qed +lemma tendsto_PInfty: "(f ---> \) F \ (\r. eventually (\x. ereal r < f x) F)" + unfolding tendsto_def +proof safe + fix S :: "ereal set" assume "open S" "\ \ S" + from open_PInfty[OF this] guess B .. note B = this + moreover + assume "\r::real. eventually (\z. r < f z) F" + then have "eventually (\z. f z \ {B <..}) F" by auto + ultimately show "eventually (\z. f z \ S) F" by (auto elim!: eventually_elim1) next - assume ?l - show ?r - proof fix B::real have "open {ereal B<..}" "\ : {ereal B<..}" by auto - from topological_tendstoD[OF `?l` this,unfolded eventually_sequentially] - guess N .. note N=this - show "EX N. ALL n>=N. ereal B <= f n" apply(rule_tac x=N in exI) using N by auto - qed + fix x assume "\S. open S \ \ \ S \ eventually (\x. f x \ S) F" + from this[rule_format, of "{ereal x <..}"] + show "eventually (\y. ereal x < f y) F" by auto qed - -lemma Lim_MInfty: "f ----> (-\) <-> (ALL B. EX N. ALL n>=N. f n <= ereal B)" (is "?l = ?r") -proof - assume ?r - show ?l - apply(rule topological_tendstoI) - unfolding eventually_sequentially - proof- - fix S :: "ereal set" - assume "open S" "(-\) : S" - from open_MInfty[OF this] guess B .. note B=this - from `?r`[rule_format,of "B-(1::real)"] guess N .. note N=this - show "EX N. ALL n>=N. f n : S" apply(rule_tac x=N in exI) - proof safe case goal1 - have "ereal (B - 1) >= f n" using goal1 N by auto - also have "... < ereal B" by auto - finally show ?case using B by fastforce - qed - qed -next assume ?l show ?r - proof fix B::real have "open {..) : {..=N. ereal B >= f n" apply(rule_tac x=N in exI) using N by auto - qed +lemma tendsto_MInfty: "(f ---> -\) F \ (\r. eventually (\x. f x < ereal r) F)" + unfolding tendsto_def +proof safe + fix S :: "ereal set" assume "open S" "-\ \ S" + from open_MInfty[OF this] guess B .. note B = this + moreover + assume "\r::real. eventually (\z. f z < r) F" + then have "eventually (\z. f z \ {..< B}) F" by auto + ultimately show "eventually (\z. f z \ S) F" by (auto elim!: eventually_elim1) +next + fix x assume "\S. open S \ -\ \ S \ eventually (\x. f x \ S) F" + from this[rule_format, of "{..< ereal x}"] + show "eventually (\y. f y < ereal x) F" by auto qed - -lemma Lim_bounded_PInfty: assumes lim:"f ----> l" and "!!n. f n <= ereal B" shows "l ~= \" -proof(rule ccontr,unfold not_not) let ?B = "B + 1" assume as:"l=\" - from lim[unfolded this Lim_PInfty,rule_format,of "?B"] - guess N .. note N=this[rule_format,OF le_refl] - hence "ereal ?B <= ereal B" using assms(2)[of N] by(rule order_trans) - hence "ereal ?B < ereal ?B" apply (rule le_less_trans) by auto - thus False by auto -qed +lemma Lim_PInfty: "f ----> \ \ (\B. \N. \n\N. f n \ ereal B)" + unfolding tendsto_PInfty eventually_sequentially +proof safe + fix r assume "\r. \N. \n\N. ereal r \ f n" + from this[rule_format, of "r+1"] guess N .. + moreover have "ereal r < ereal (r + 1)" by auto + ultimately show "\N. \n\N. ereal r < f n" + by (blast intro: less_le_trans) +qed (blast intro: less_imp_le) +lemma Lim_MInfty: "f ----> -\ \ (\B. \N. \n\N. ereal B \ f n)" + unfolding tendsto_MInfty eventually_sequentially +proof safe + fix r assume "\r. \N. \n\N. f n \ ereal r" + from this[rule_format, of "r - 1"] guess N .. + moreover have "ereal (r - 1) < ereal r" by auto + ultimately show "\N. \n\N. f n < ereal r" + by (blast intro: le_less_trans) +qed (blast intro: less_imp_le) -lemma Lim_bounded_MInfty: assumes lim:"f ----> l" and "!!n. f n >= ereal B" shows "l ~= (-\)" -proof(rule ccontr,unfold not_not) let ?B = "B - 1" assume as:"l=(-\)" - from lim[unfolded this Lim_MInfty,rule_format,of "?B"] - guess N .. note N=this[rule_format,OF le_refl] - hence "ereal B <= ereal ?B" using assms(2)[of N] order_trans[of "ereal B" "f N" "ereal(B - 1)"] by blast - thus False by auto -qed +lemma Lim_bounded_PInfty: "f ----> l \ (\n. f n \ ereal B) \ l \ \" + using LIMSEQ_le_const2[of f l "ereal B"] by auto +lemma Lim_bounded_MInfty: "f ----> l \ (\n. ereal B \ f n) \ l \ -\" + using LIMSEQ_le_const[of f l "ereal B"] by auto lemma tendsto_explicit: "f ----> f0 <-> (ALL S. open S --> f0 : S --> (EX N. ALL n>=N. f n : S))" unfolding tendsto_def eventually_sequentially by auto - -lemma tendsto_obtains_N: - assumes "f ----> f0" - assumes "open S" "f0 : S" - obtains N where "ALL n>=N. f n : S" - using tendsto_explicit[of f f0] assms by auto - - -lemma tail_same_limit: - fixes X Y N - assumes "X ----> L" "ALL n>=N. X n = Y n" - shows "Y ----> L" -proof- -{ fix S assume "open S" and "L:S" - then obtain N1 where "ALL n>=N1. X n : S" - using assms unfolding tendsto_def eventually_sequentially by auto - hence "ALL n>=max N N1. Y n : S" using assms by auto - hence "EX N. ALL n>=N. Y n : S" apply(rule_tac x="max N N1" in exI) by auto -} -thus ?thesis using tendsto_explicit by auto -qed - - lemma Lim_bounded_PInfty2: -assumes lim:"f ----> l" and "ALL n>=N. f n <= ereal B" -shows "l ~= \" -proof- - def g == "(%n. if n>=N then f n else ereal B)" - hence "g ----> l" using tail_same_limit[of f l N g] lim by auto - moreover have "!!n. g n <= ereal B" using g_def assms by auto - ultimately show ?thesis using Lim_bounded_PInfty by auto -qed + "f ----> l \ ALL n>=N. f n <= ereal B \ l ~= \" + using LIMSEQ_le_const2[of f l "ereal B"] by fastforce -lemma Lim_bounded_ereal: - assumes lim:"f ----> (l :: ereal)" - and "ALL n>=M. f n <= C" - shows "l<=C" -proof- -{ assume "l=(-\)" hence ?thesis by auto } -moreover -{ assume "~(l=(-\))" - { assume "C=\" hence ?thesis by auto } - moreover - { assume "C=(-\)" hence "ALL n>=M. f n = (-\)" using assms by auto - hence "l=(-\)" using assms - tendsto_unique[OF trivial_limit_sequentially] tail_same_limit[of "\n. -\" "-\" M f, OF tendsto_const] by auto - hence ?thesis by auto } - moreover - { assume "EX B. C = ereal B" - then obtain B where B_def: "C=ereal B" by auto - hence "~(l=\)" using Lim_bounded_PInfty2 assms by auto - then obtain m where m_def: "ereal m=l" using `~(l=(-\))` by (cases l) auto - then obtain N where N_def: "ALL n>=N. f n : {ereal(m - 1) <..< ereal(m+1)}" - apply (subst tendsto_obtains_N[of f l "{ereal(m - 1) <..< ereal(m+1)}"]) using assms by auto - { fix n assume "n>=N" - hence "EX r. ereal r = f n" using N_def by (cases "f n") auto - } then obtain g where g_def: "ALL n>=N. ereal (g n) = f n" by metis - hence "(%n. ereal (g n)) ----> l" using tail_same_limit[of f l N] assms by auto - hence *: "(%n. g n) ----> m" using m_def by auto - { fix n assume "n>=max N M" - hence "ereal (g n) <= ereal B" using assms g_def B_def by auto - hence "g n <= B" by auto - } hence "EX N. ALL n>=N. g n <= B" by blast - hence "m<=B" using * LIMSEQ_le_const2[of g m B] by auto - hence ?thesis using m_def B_def by auto - } ultimately have ?thesis by (cases C) auto -} ultimately show ?thesis by blast -qed +lemma Lim_bounded_ereal: "f ----> (l :: ereal) \ ALL n>=M. f n <= C \ l<=C" + by (intro LIMSEQ_le_const2) auto lemma real_of_ereal_mult[simp]: fixes a b :: ereal shows "real (a * b) = real a * real b" @@ -2204,349 +2138,6 @@ lemma ereal_mult_m1[simp]: "x * ereal (-1) = -x" by (cases x) auto -lemma ereal_LimI_finite: - fixes x :: ereal - assumes "\x\ \ \" - assumes "!!r. 0 < r ==> EX N. ALL n>=N. u n < x + r & x < u n + r" - shows "u ----> x" -proof (rule topological_tendstoI, unfold eventually_sequentially) - obtain rx where rx_def: "x=ereal rx" using assms by (cases x) auto - fix S assume "open S" "x : S" - then have "open (ereal -` S)" unfolding open_ereal_def by auto - with `x \ S` obtain r where "0 < r" and dist: "!!y. dist y rx < r ==> ereal y \ S" - unfolding open_real_def rx_def by auto - then obtain n where - upper: "!!N. n <= N ==> u N < x + ereal r" and - lower: "!!N. n <= N ==> x < u N + ereal r" using assms(2)[of "ereal r"] by auto - show "EX N. ALL n>=N. u n : S" - proof (safe intro!: exI[of _ n]) - fix N assume "n <= N" - from upper[OF this] lower[OF this] assms `0 < r` - have "u N ~: {\,(-\)}" by auto - then obtain ra where ra_def: "(u N) = ereal ra" by (cases "u N") auto - hence "rx < ra + r" and "ra < rx + r" - using rx_def assms `0 < r` lower[OF `n <= N`] upper[OF `n <= N`] by auto - hence "dist (real (u N)) rx < r" - using rx_def ra_def - by (auto simp: dist_real_def abs_diff_less_iff field_simps) - from dist[OF this] show "u N : S" using `u N ~: {\, -\}` - by (auto simp: ereal_real split: split_if_asm) - qed -qed - -lemma ereal_LimI_finite_iff: - fixes x :: ereal - assumes "\x\ \ \" - shows "u ----> x <-> (ALL r. 0 < r --> (EX N. ALL n>=N. u n < x + r & x < u n + r))" - (is "?lhs <-> ?rhs") -proof - assume lim: "u ----> x" - { fix r assume "(r::ereal)>0" - then obtain N where N_def: "ALL n>=N. u n : {x - r <..< x + r}" - apply (subst tendsto_obtains_N[of u x "{x - r <..< x + r}"]) - using lim ereal_between[of x r] assms `r>0` by auto - hence "EX N. ALL n>=N. u n < x + r & x < u n + r" - using ereal_minus_less[of r x] by (cases r) auto - } then show "?rhs" by auto -next - assume ?rhs then show "u ----> x" - using ereal_LimI_finite[of x] assms by auto -qed - - -subsubsection {* @{text Liminf} and @{text Limsup} *} - -definition - "Liminf net f = (GREATEST l. \yx. y < f x) net)" - -definition - "Limsup net f = (LEAST l. \y>l. eventually (\x. f x < y) net)" - -lemma Liminf_Sup: - fixes f :: "'a => 'b::complete_linorder" - shows "Liminf net f = Sup {l. \yx. y < f x) net}" - by (auto intro!: Greatest_equality complete_lattice_class.Sup_upper simp: less_Sup_iff Liminf_def) - -lemma Limsup_Inf: - fixes f :: "'a => 'b::complete_linorder" - shows "Limsup net f = Inf {l. \y>l. eventually (\x. f x < y) net}" - by (auto intro!: Least_equality complete_lattice_class.Inf_lower simp: Inf_less_iff Limsup_def) - -lemma ereal_SupI: - fixes x :: ereal - assumes "\y. y \ A \ y \ x" - assumes "\y. (\z. z \ A \ z \ y) \ x \ y" - shows "Sup A = x" - unfolding Sup_ereal_def - using assms by (auto intro!: Least_equality) - -lemma ereal_InfI: - fixes x :: ereal - assumes "\i. i \ A \ x \ i" - assumes "\y. (\i. i \ A \ y \ i) \ y \ x" - shows "Inf A = x" - unfolding Inf_ereal_def - using assms by (auto intro!: Greatest_equality) - -lemma Limsup_const: - fixes c :: "'a::complete_linorder" - assumes ntriv: "\ trivial_limit net" - shows "Limsup net (\x. c) = c" - unfolding Limsup_Inf -proof (safe intro!: antisym complete_lattice_class.Inf_greatest complete_lattice_class.Inf_lower) - fix x assume *: "\y>x. eventually (\_. c < y) net" - show "c \ x" - proof (rule ccontr) - assume "\ c \ x" then have "x < c" by auto - then show False using ntriv * by (auto simp: trivial_limit_def) - qed -qed auto - -lemma Liminf_const: - fixes c :: "'a::complete_linorder" - assumes ntriv: "\ trivial_limit net" - shows "Liminf net (\x. c) = c" - unfolding Liminf_Sup -proof (safe intro!: antisym complete_lattice_class.Sup_least complete_lattice_class.Sup_upper) - fix x assume *: "\y_. y < c) net" - show "x \ c" - proof (rule ccontr) - assume "\ x \ c" then have "c < x" by auto - then show False using ntriv * by (auto simp: trivial_limit_def) - qed -qed auto - -definition (in order) mono_set: - "mono_set S \ (\x y. x \ y \ x \ S \ y \ S)" - -lemma (in order) mono_greaterThan [intro, simp]: "mono_set {B<..}" unfolding mono_set by auto -lemma (in order) mono_atLeast [intro, simp]: "mono_set {B..}" unfolding mono_set by auto -lemma (in order) mono_UNIV [intro, simp]: "mono_set UNIV" unfolding mono_set by auto -lemma (in order) mono_empty [intro, simp]: "mono_set {}" unfolding mono_set by auto - -lemma (in complete_linorder) mono_set_iff: - fixes S :: "'a set" - defines "a \ Inf S" - shows "mono_set S \ (S = {a <..} \ S = {a..})" (is "_ = ?c") -proof - assume "mono_set S" - then have mono: "\x y. x \ y \ x \ S \ y \ S" by (auto simp: mono_set) - show ?c - proof cases - assume "a \ S" - show ?c - using mono[OF _ `a \ S`] - by (auto intro: Inf_lower simp: a_def) - next - assume "a \ S" - have "S = {a <..}" - proof safe - fix x assume "x \ S" - then have "a \ x" unfolding a_def by (rule Inf_lower) - then show "a < x" using `x \ S` `a \ S` by (cases "a = x") auto - next - fix x assume "a < x" - then obtain y where "y < x" "y \ S" unfolding a_def Inf_less_iff .. - with mono[of y x] show "x \ S" by auto - qed - then show ?c .. - qed -qed auto - -lemma lim_imp_Liminf: - fixes f :: "'a \ ereal" - assumes ntriv: "\ trivial_limit net" - assumes lim: "(f ---> f0) net" - shows "Liminf net f = f0" - unfolding Liminf_Sup -proof (safe intro!: ereal_SupI) - fix y assume *: "\y'x. y' < f x) net" - show "y \ f0" - proof (rule ereal_le_ereal) - fix B assume "B < y" - { assume "f0 < B" - then have "eventually (\x. f x < B \ B < f x) net" - using topological_tendstoD[OF lim, of "{..x. f x < B \ B < f x) = (\x. False)" by (auto simp: fun_eq_iff) - finally have False using ntriv[unfolded trivial_limit_def] by auto - } then show "B \ f0" by (metis linorder_le_less_linear) - qed -next - fix y assume *: "\z. z \ {l. \yx. y < f x) net} \ z \ y" - show "f0 \ y" - proof (safe intro!: *[rule_format]) - fix y assume "y < f0" then show "eventually (\x. y < f x) net" - using lim[THEN topological_tendstoD, of "{y <..}"] by auto - qed -qed - -lemma ereal_Liminf_le_Limsup: - fixes f :: "'a \ ereal" - assumes ntriv: "\ trivial_limit net" - shows "Liminf net f \ Limsup net f" - unfolding Limsup_Inf Liminf_Sup -proof (safe intro!: complete_lattice_class.Inf_greatest complete_lattice_class.Sup_least) - fix u v assume *: "\yx. y < f x) net" "\y>v. eventually (\x. f x < y) net" - show "u \ v" - proof (rule ccontr) - assume "\ u \ v" - then obtain t where "t < u" "v < t" - using ereal_dense[of v u] by (auto simp: not_le) - then have "eventually (\x. t < f x \ f x < t) net" - using * by (auto intro: eventually_conj) - also have "(\x. t < f x \ f x < t) = (\x. False)" by (auto simp: fun_eq_iff) - finally show False using ntriv by (auto simp: trivial_limit_def) - qed -qed - -lemma Liminf_mono: - fixes f g :: "'a => ereal" - assumes ev: "eventually (\x. f x \ g x) net" - shows "Liminf net f \ Liminf net g" - unfolding Liminf_Sup -proof (safe intro!: Sup_mono bexI) - fix a y assume "\yx. y < f x) net" and "y < a" - then have "eventually (\x. y < f x) net" by auto - then show "eventually (\x. y < g x) net" - by (rule eventually_rev_mp) (rule eventually_mono[OF _ ev], auto) -qed simp - -lemma Liminf_eq: - fixes f g :: "'a \ ereal" - assumes "eventually (\x. f x = g x) net" - shows "Liminf net f = Liminf net g" - by (intro antisym Liminf_mono eventually_mono[OF _ assms]) auto - -lemma Liminf_mono_all: - fixes f g :: "'a \ ereal" - assumes "\x. f x \ g x" - shows "Liminf net f \ Liminf net g" - using assms by (intro Liminf_mono always_eventually) auto - -lemma Limsup_mono: - fixes f g :: "'a \ ereal" - assumes ev: "eventually (\x. f x \ g x) net" - shows "Limsup net f \ Limsup net g" - unfolding Limsup_Inf -proof (safe intro!: Inf_mono bexI) - fix a y assume "\y>a. eventually (\x. g x < y) net" and "a < y" - then have "eventually (\x. g x < y) net" by auto - then show "eventually (\x. f x < y) net" - by (rule eventually_rev_mp) (rule eventually_mono[OF _ ev], auto) -qed simp - -lemma Limsup_mono_all: - fixes f g :: "'a \ ereal" - assumes "\x. f x \ g x" - shows "Limsup net f \ Limsup net g" - using assms by (intro Limsup_mono always_eventually) auto - -lemma Limsup_eq: - fixes f g :: "'a \ ereal" - assumes "eventually (\x. f x = g x) net" - shows "Limsup net f = Limsup net g" - by (intro antisym Limsup_mono eventually_mono[OF _ assms]) auto - -abbreviation "liminf \ Liminf sequentially" - -abbreviation "limsup \ Limsup sequentially" - -lemma liminf_SUPR_INFI: - fixes f :: "nat \ ereal" - shows "liminf f = (SUP n. INF m:{n..}. f m)" - unfolding Liminf_Sup eventually_sequentially -proof (safe intro!: antisym complete_lattice_class.Sup_least) - fix x assume *: "\yN. \n\N. y < f n" show "x \ (SUP n. INF m:{n..}. f m)" - proof (rule ereal_le_ereal) - fix y assume "y < x" - with * obtain N where "\n. N \ n \ y < f n" by auto - then have "y \ (INF m:{N..}. f m)" by (force simp: le_INF_iff) - also have "\ \ (SUP n. INF m:{n..}. f m)" by (intro SUP_upper) auto - finally show "y \ (SUP n. INF m:{n..}. f m)" . - qed -next - show "(SUP n. INF m:{n..}. f m) \ Sup {l. \yN. \n\N. y < f n}" - proof (unfold SUP_def, safe intro!: Sup_mono bexI) - fix y n assume "y < INFI {n..} f" - from less_INF_D[OF this] show "\N. \n\N. y < f n" by (intro exI[of _ n]) auto - qed (rule order_refl) -qed - -lemma tail_same_limsup: - fixes X Y :: "nat => ereal" - assumes "\n. N \ n \ X n = Y n" - shows "limsup X = limsup Y" - using Limsup_eq[of X Y sequentially] eventually_sequentially assms by auto - -lemma tail_same_liminf: - fixes X Y :: "nat => ereal" - assumes "\n. N \ n \ X n = Y n" - shows "liminf X = liminf Y" - using Liminf_eq[of X Y sequentially] eventually_sequentially assms by auto - -lemma liminf_mono: - fixes X Y :: "nat \ ereal" - assumes "\n. N \ n \ X n <= Y n" - shows "liminf X \ liminf Y" - using Liminf_mono[of X Y sequentially] eventually_sequentially assms by auto - -lemma limsup_mono: - fixes X Y :: "nat => ereal" - assumes "\n. N \ n \ X n <= Y n" - shows "limsup X \ limsup Y" - using Limsup_mono[of X Y sequentially] eventually_sequentially assms by auto - -lemma - fixes X :: "nat \ ereal" - shows ereal_incseq_uminus[simp]: "incseq (\i. - X i) = decseq X" - and ereal_decseq_uminus[simp]: "decseq (\i. - X i) = incseq X" - unfolding incseq_def decseq_def by auto - -lemma liminf_bounded: - fixes X Y :: "nat \ ereal" - assumes "\n. N \ n \ C \ X n" - shows "C \ liminf X" - using liminf_mono[of N "\n. C" X] assms Liminf_const[of sequentially C] by simp - -lemma limsup_bounded: - fixes X Y :: "nat => ereal" - assumes "\n. N \ n \ X n <= C" - shows "limsup X \ C" - using limsup_mono[of N X "\n. C"] assms Limsup_const[of sequentially C] by simp - -lemma liminf_bounded_iff: - fixes x :: "nat \ ereal" - shows "C \ liminf x \ (\BN. \n\N. B < x n)" (is "?lhs <-> ?rhs") -proof safe - fix B assume "B < C" "C \ liminf x" - then have "B < liminf x" by auto - then obtain N where "B < (INF m:{N..}. x m)" - unfolding liminf_SUPR_INFI SUP_def less_Sup_iff by auto - from less_INF_D[OF this] show "\N. \n\N. B < x n" by auto -next - assume *: "\BN. \n\N. B < x n" - { fix B assume "Bn\N. B < x n" using `?rhs` by auto - hence "B \ (INF m:{N..}. x m)" by (intro INF_greatest) auto - also have "... \ liminf x" unfolding liminf_SUPR_INFI by (intro SUP_upper) simp - finally have "B \ liminf x" . - } then show "?lhs" by (metis * leD liminf_bounded linorder_le_less_linear) -qed - -lemma liminf_subseq_mono: - fixes X :: "nat \ ereal" - assumes "subseq r" - shows "liminf X \ liminf (X \ r) " -proof- - have "\n. (INF m:{n..}. X m) \ (INF m:{n..}. (X \ r) m)" - proof (safe intro!: INF_mono) - fix n m :: nat assume "n \ m" then show "\ma\{n..}. X ma \ (X \ r) m" - using seq_suble[OF `subseq r`, of m] by (intro bexI[of _ "r m"]) auto - qed - then show ?thesis by (auto intro!: SUP_mono simp: liminf_SUPR_INFI comp_def) -qed - lemma ereal_real': assumes "\x\ \ \" shows "ereal (real x) = x" using assms by auto @@ -2618,6 +2209,333 @@ "[| (a::ereal) <= x; c <= x |] ==> max a c <= x" by (metis sup_ereal_def sup_least) + +lemma ereal_LimI_finite: + fixes x :: ereal + assumes "\x\ \ \" + assumes "!!r. 0 < r ==> EX N. ALL n>=N. u n < x + r & x < u n + r" + shows "u ----> x" +proof (rule topological_tendstoI, unfold eventually_sequentially) + obtain rx where rx_def: "x=ereal rx" using assms by (cases x) auto + fix S assume "open S" "x : S" + then have "open (ereal -` S)" unfolding open_ereal_def by auto + with `x \ S` obtain r where "0 < r" and dist: "!!y. dist y rx < r ==> ereal y \ S" + unfolding open_real_def rx_def by auto + then obtain n where + upper: "!!N. n <= N ==> u N < x + ereal r" and + lower: "!!N. n <= N ==> x < u N + ereal r" using assms(2)[of "ereal r"] by auto + show "EX N. ALL n>=N. u n : S" + proof (safe intro!: exI[of _ n]) + fix N assume "n <= N" + from upper[OF this] lower[OF this] assms `0 < r` + have "u N ~: {\,(-\)}" by auto + then obtain ra where ra_def: "(u N) = ereal ra" by (cases "u N") auto + hence "rx < ra + r" and "ra < rx + r" + using rx_def assms `0 < r` lower[OF `n <= N`] upper[OF `n <= N`] by auto + hence "dist (real (u N)) rx < r" + using rx_def ra_def + by (auto simp: dist_real_def abs_diff_less_iff field_simps) + from dist[OF this] show "u N : S" using `u N ~: {\, -\}` + by (auto simp: ereal_real split: split_if_asm) + qed +qed + +lemma tendsto_obtains_N: + assumes "f ----> f0" + assumes "open S" "f0 : S" + obtains N where "ALL n>=N. f n : S" + using tendsto_explicit[of f f0] assms by auto + +lemma ereal_LimI_finite_iff: + fixes x :: ereal + assumes "\x\ \ \" + shows "u ----> x <-> (ALL r. 0 < r --> (EX N. ALL n>=N. u n < x + r & x < u n + r))" + (is "?lhs <-> ?rhs") +proof + assume lim: "u ----> x" + { fix r assume "(r::ereal)>0" + then obtain N where N_def: "ALL n>=N. u n : {x - r <..< x + r}" + apply (subst tendsto_obtains_N[of u x "{x - r <..< x + r}"]) + using lim ereal_between[of x r] assms `r>0` by auto + hence "EX N. ALL n>=N. u n < x + r & x < u n + r" + using ereal_minus_less[of r x] by (cases r) auto + } then show "?rhs" by auto +next + assume ?rhs then show "u ----> x" + using ereal_LimI_finite[of x] assms by auto +qed + + +subsubsection {* @{text Liminf} and @{text Limsup} *} + +definition + "Liminf F f = (SUP P:{P. eventually P F}. INF x:{x. P x}. f x)" + +definition + "Limsup F f = (INF P:{P. eventually P F}. SUP x:{x. P x}. f x)" + +abbreviation "liminf \ Liminf sequentially" + +abbreviation "limsup \ Limsup sequentially" + +lemma Liminf_eqI: + "(\P. eventually P F \ INFI (Collect P) f \ x) \ + (\y. (\P. eventually P F \ INFI (Collect P) f \ y) \ x \ y) \ Liminf F f = x" + unfolding Liminf_def by (auto intro!: SUP_eqI) + +lemma Limsup_eqI: + "(\P. eventually P F \ x \ SUPR (Collect P) f) \ + (\y. (\P. eventually P F \ y \ SUPR (Collect P) f) \ y \ x) \ Limsup F f = x" + unfolding Limsup_def by (auto intro!: INF_eqI) + +lemma liminf_SUPR_INFI: + fixes f :: "nat \ 'a :: complete_lattice" + shows "liminf f = (SUP n. INF m:{n..}. f m)" + unfolding Liminf_def eventually_sequentially + by (rule SUPR_eq) (auto simp: atLeast_def intro!: INF_mono) + +lemma limsup_INFI_SUPR: + fixes f :: "nat \ 'a :: complete_lattice" + shows "limsup f = (INF n. SUP m:{n..}. f m)" + unfolding Limsup_def eventually_sequentially + by (rule INFI_eq) (auto simp: atLeast_def intro!: SUP_mono) + +lemma Limsup_const: + assumes ntriv: "\ trivial_limit F" + shows "Limsup F (\x. c) = (c::'a::complete_lattice)" +proof - + have *: "\P. Ex P \ P \ (\x. False)" by auto + have "\P. eventually P F \ (SUP x : {x. P x}. c) = c" + using ntriv by (intro SUP_const) (auto simp: eventually_False *) + then show ?thesis + unfolding Limsup_def using eventually_True + by (subst INF_cong[where D="\x. c"]) + (auto intro!: INF_const simp del: eventually_True) +qed + +lemma Liminf_const: + assumes ntriv: "\ trivial_limit F" + shows "Liminf F (\x. c) = (c::'a::complete_lattice)" +proof - + have *: "\P. Ex P \ P \ (\x. False)" by auto + have "\P. eventually P F \ (INF x : {x. P x}. c) = c" + using ntriv by (intro INF_const) (auto simp: eventually_False *) + then show ?thesis + unfolding Liminf_def using eventually_True + by (subst SUP_cong[where D="\x. c"]) + (auto intro!: SUP_const simp del: eventually_True) +qed + +lemma Liminf_mono: + fixes f g :: "'a => 'b :: complete_lattice" + assumes ev: "eventually (\x. f x \ g x) F" + shows "Liminf F f \ Liminf F g" + unfolding Liminf_def +proof (safe intro!: SUP_mono) + fix P assume "eventually P F" + with ev have "eventually (\x. f x \ g x \ P x) F" (is "eventually ?Q F") by (rule eventually_conj) + then show "\Q\{P. eventually P F}. INFI (Collect P) f \ INFI (Collect Q) g" + by (intro bexI[of _ ?Q]) (auto intro!: INF_mono) +qed + +lemma Liminf_eq: + fixes f g :: "'a \ 'b :: complete_lattice" + assumes "eventually (\x. f x = g x) F" + shows "Liminf F f = Liminf F g" + by (intro antisym Liminf_mono eventually_mono[OF _ assms]) auto + +lemma Limsup_mono: + fixes f g :: "'a \ 'b :: complete_lattice" + assumes ev: "eventually (\x. f x \ g x) F" + shows "Limsup F f \ Limsup F g" + unfolding Limsup_def +proof (safe intro!: INF_mono) + fix P assume "eventually P F" + with ev have "eventually (\x. f x \ g x \ P x) F" (is "eventually ?Q F") by (rule eventually_conj) + then show "\Q\{P. eventually P F}. SUPR (Collect Q) f \ SUPR (Collect P) g" + by (intro bexI[of _ ?Q]) (auto intro!: SUP_mono) +qed + +lemma Limsup_eq: + fixes f g :: "'a \ 'b :: complete_lattice" + assumes "eventually (\x. f x = g x) net" + shows "Limsup net f = Limsup net g" + by (intro antisym Limsup_mono eventually_mono[OF _ assms]) auto + +lemma Liminf_le_Limsup: + fixes f :: "'a \ 'b::complete_lattice" + assumes ntriv: "\ trivial_limit F" + shows "Liminf F f \ Limsup F f" + unfolding Limsup_def Liminf_def + apply (rule complete_lattice_class.SUP_least) + apply (rule complete_lattice_class.INF_greatest) +proof safe + fix P Q assume "eventually P F" "eventually Q F" + then have "eventually (\x. P x \ Q x) F" (is "eventually ?C F") by (rule eventually_conj) + then have not_False: "(\x. P x \ Q x) \ (\x. False)" + using ntriv by (auto simp add: eventually_False) + have "INFI (Collect P) f \ INFI (Collect ?C) f" + by (rule INF_mono) auto + also have "\ \ SUPR (Collect ?C) f" + using not_False by (intro INF_le_SUP) auto + also have "\ \ SUPR (Collect Q) f" + by (rule SUP_mono) auto + finally show "INFI (Collect P) f \ SUPR (Collect Q) f" . +qed + +lemma + fixes X :: "nat \ ereal" + shows ereal_incseq_uminus[simp]: "incseq (\i. - X i) = decseq X" + and ereal_decseq_uminus[simp]: "decseq (\i. - X i) = incseq X" + unfolding incseq_def decseq_def by auto + +lemma Liminf_bounded: + fixes X Y :: "'a \ 'b::complete_lattice" + assumes ntriv: "\ trivial_limit F" + assumes le: "eventually (\n. C \ X n) F" + shows "C \ Liminf F X" + using Liminf_mono[OF le] Liminf_const[OF ntriv, of C] by simp + +lemma Limsup_bounded: + fixes X Y :: "'a \ 'b::complete_lattice" + assumes ntriv: "\ trivial_limit F" + assumes le: "eventually (\n. X n \ C) F" + shows "Limsup F X \ C" + using Limsup_mono[OF le] Limsup_const[OF ntriv, of C] by simp + +lemma liminf_bounded_iff: + fixes x :: "nat \ ereal" + shows "C \ liminf x \ (\BN. \n\N. B < x n)" (is "?lhs <-> ?rhs") +proof safe + fix B assume "B < C" "C \ liminf x" + then have "B < liminf x" by auto + then obtain N where "B < (INF m:{N..}. x m)" + unfolding liminf_SUPR_INFI SUP_def less_Sup_iff by auto + from less_INF_D[OF this] show "\N. \n\N. B < x n" by auto +next + assume *: "\BN. \n\N. B < x n" + { fix B assume "Bn\N. B < x n" using `?rhs` by auto + hence "B \ (INF m:{N..}. x m)" by (intro INF_greatest) auto + also have "... \ liminf x" unfolding liminf_SUPR_INFI by (intro SUP_upper) simp + finally have "B \ liminf x" . + } then show "?lhs" + by (metis * leD Liminf_bounded[OF sequentially_bot] linorder_le_less_linear eventually_sequentially) +qed + +lemma liminf_subseq_mono: + fixes X :: "nat \ 'a :: complete_linorder" + assumes "subseq r" + shows "liminf X \ liminf (X \ r) " +proof- + have "\n. (INF m:{n..}. X m) \ (INF m:{n..}. (X \ r) m)" + proof (safe intro!: INF_mono) + fix n m :: nat assume "n \ m" then show "\ma\{n..}. X ma \ (X \ r) m" + using seq_suble[OF `subseq r`, of m] by (intro bexI[of _ "r m"]) auto + qed + then show ?thesis by (auto intro!: SUP_mono simp: liminf_SUPR_INFI comp_def) +qed + +lemma limsup_subseq_mono: + fixes X :: "nat \ 'a :: complete_linorder" + assumes "subseq r" + shows "limsup (X \ r) \ limsup X" +proof- + have "\n. (SUP m:{n..}. (X \ r) m) \ (SUP m:{n..}. X m)" + proof (safe intro!: SUP_mono) + fix n m :: nat assume "n \ m" then show "\ma\{n..}. (X \ r) m \ X ma" + using seq_suble[OF `subseq r`, of m] by (intro bexI[of _ "r m"]) auto + qed + then show ?thesis by (auto intro!: INF_mono simp: limsup_INFI_SUPR comp_def) +qed + +lemma lim_imp_Liminf: + fixes f :: "'a \ ereal" (* generalize to inner dense, complete_linorder, order_topology *) + assumes ntriv: "\ trivial_limit F" + assumes lim: "(f ---> f0) F" + shows "Liminf F f = f0" +proof (rule Liminf_eqI) + fix y assume *: "\P. eventually P F \ INFI (Collect P) f \ y" + show "f0 \ y" + proof (rule ereal_le_ereal) + fix B + assume "B < f0" + have "B \ INFI {x. B < f x} f" + by (rule INF_greatest) simp + also have "INFI {x. B < f x} f \ y" + using lim[THEN topological_tendstoD, of "{B <..}"] `B < f0` * by auto + finally show "B \ y" . + qed +next + fix P assume P: "eventually P F" + then have "eventually (\x. INFI (Collect P) f \ f x) F" + by eventually_elim (auto intro!: INF_lower) + then show "INFI (Collect P) f \ f0" + by (rule tendsto_le[OF ntriv lim tendsto_const]) +qed + +lemma lim_imp_Limsup: + fixes f :: "'a \ ereal" (* generalize to inner dense, complete_linorder, order_topology *) + assumes ntriv: "\ trivial_limit F" + assumes lim: "(f ---> f0) F" + shows "Limsup F f = f0" +proof (rule Limsup_eqI) + fix y assume *: "\P. eventually P F \ y \ SUPR (Collect P) f" + show "y \ f0" + proof (rule ereal_ge_ereal, safe) + fix B + assume "f0 < B" + have "y \ SUPR {x. f x < B} f" + using lim[THEN topological_tendstoD, of "{..< B}"] `f0 < B` * by auto + also have "SUPR {x. f x < B} f \ B" + by (rule SUP_least) simp + finally show "y \ B" . + qed +next + fix P assume P: "eventually P F" + then have "eventually (\x. f x \ SUPR (Collect P) f) F" + by eventually_elim (auto intro!: SUP_upper) + then show "f0 \ SUPR (Collect P) f" + by (rule tendsto_le[OF ntriv tendsto_const lim]) +qed + +definition (in order) mono_set: + "mono_set S \ (\x y. x \ y \ x \ S \ y \ S)" + +lemma (in order) mono_greaterThan [intro, simp]: "mono_set {B<..}" unfolding mono_set by auto +lemma (in order) mono_atLeast [intro, simp]: "mono_set {B..}" unfolding mono_set by auto +lemma (in order) mono_UNIV [intro, simp]: "mono_set UNIV" unfolding mono_set by auto +lemma (in order) mono_empty [intro, simp]: "mono_set {}" unfolding mono_set by auto + +lemma (in complete_linorder) mono_set_iff: + fixes S :: "'a set" + defines "a \ Inf S" + shows "mono_set S \ (S = {a <..} \ S = {a..})" (is "_ = ?c") +proof + assume "mono_set S" + then have mono: "\x y. x \ y \ x \ S \ y \ S" by (auto simp: mono_set) + show ?c + proof cases + assume "a \ S" + show ?c + using mono[OF _ `a \ S`] + by (auto intro: Inf_lower simp: a_def) + next + assume "a \ S" + have "S = {a <..}" + proof safe + fix x assume "x \ S" + then have "a \ x" unfolding a_def by (rule Inf_lower) + then show "a < x" using `x \ S` `a \ S` by (cases "a = x") auto + next + fix x assume "a < x" + then obtain y where "y < x" "y \ S" unfolding a_def Inf_less_iff .. + with mono[of y x] show "x \ S" by auto + qed + then show ?c .. + qed +qed auto + subsubsection {* Tests for code generator *} (* A small list of simple arithmetic expressions *)