3 Author: Robert Himmelmann, TU München |
3 Author: Robert Himmelmann, TU München |
4 Author: Armin Heller, TU München |
4 Author: Armin Heller, TU München |
5 Author: Bogdan Grechuk, University of Edinburgh |
5 Author: Bogdan Grechuk, University of Edinburgh |
6 *) |
6 *) |
7 |
7 |
8 section {* Extended real number line *} |
8 section \<open>Extended real number line\<close> |
9 |
9 |
10 theory Extended_Real |
10 theory Extended_Real |
11 imports Complex_Main Extended_Nat Liminf_Limsup Order_Continuity |
11 imports Complex_Main Extended_Nat Liminf_Limsup Order_Continuity |
12 begin |
12 begin |
13 |
13 |
14 text {* |
14 text \<open> |
15 |
15 |
16 This should be part of @{theory Extended_Nat} or @{theory Order_Continuity}, but then the |
16 This should be part of @{theory Extended_Nat} or @{theory Order_Continuity}, but then the |
17 AFP-entry @{text "Jinja_Thread"} fails, as it does overload certain named from @{theory Complex_Main}. |
17 AFP-entry @{text "Jinja_Thread"} fails, as it does overload certain named from @{theory Complex_Main}. |
18 |
18 |
19 *} |
19 \<close> |
20 |
20 |
21 lemma continuous_at_left_imp_sup_continuous: |
21 lemma continuous_at_left_imp_sup_continuous: |
22 fixes f :: "'a \<Rightarrow> 'a::{complete_linorder, linorder_topology}" |
22 fixes f :: "'a \<Rightarrow> 'a::{complete_linorder, linorder_topology}" |
23 assumes "mono f" "\<And>x. continuous (at_left x) f" |
23 assumes "mono f" "\<And>x. continuous (at_left x) f" |
24 shows "sup_continuous f" |
24 shows "sup_continuous f" |
167 by auto |
167 by auto |
168 qed auto |
168 qed auto |
169 qed |
169 qed |
170 |
170 |
171 |
171 |
172 text {* |
172 text \<open> |
173 |
173 |
174 For more lemmas about the extended real numbers go to |
174 For more lemmas about the extended real numbers go to |
175 @{file "~~/src/HOL/Multivariate_Analysis/Extended_Real_Limits.thy"} |
175 @{file "~~/src/HOL/Multivariate_Analysis/Extended_Real_Limits.thy"} |
176 |
176 |
177 *} |
177 \<close> |
178 |
178 |
179 subsection {* Definition and basic properties *} |
179 subsection \<open>Definition and basic properties\<close> |
180 |
180 |
181 datatype ereal = ereal real | PInfty | MInfty |
181 datatype ereal = ereal real | PInfty | MInfty |
182 |
182 |
183 instantiation ereal :: uminus |
183 instantiation ereal :: uminus |
184 begin |
184 begin |
1119 } |
1119 } |
1120 moreover |
1120 moreover |
1121 { |
1121 { |
1122 assume "e \<noteq> \<infinity>" |
1122 assume "e \<noteq> \<infinity>" |
1123 then obtain r where "e = ereal r" |
1123 then obtain r where "e = ereal r" |
1124 using `e > 0` by (cases e) auto |
1124 using \<open>e > 0\<close> by (cases e) auto |
1125 then have "x \<le> y + e" |
1125 then have "x \<le> y + e" |
1126 using assms[rule_format, of r] `e>0` by auto |
1126 using assms[rule_format, of r] \<open>e>0\<close> by auto |
1127 } |
1127 } |
1128 ultimately have "x \<le> y + e" |
1128 ultimately have "x \<le> y + e" |
1129 by blast |
1129 by blast |
1130 } |
1130 } |
1131 then show ?thesis |
1131 then show ?thesis |
1197 then show ?thesis |
1197 then show ?thesis |
1198 by (simp add: one_ereal_def) |
1198 by (simp add: one_ereal_def) |
1199 qed |
1199 qed |
1200 |
1200 |
1201 |
1201 |
1202 subsubsection {* Power *} |
1202 subsubsection \<open>Power\<close> |
1203 |
1203 |
1204 lemma ereal_power[simp]: "(ereal x) ^ n = ereal (x^n)" |
1204 lemma ereal_power[simp]: "(ereal x) ^ n = ereal (x^n)" |
1205 by (induct n) (auto simp: one_ereal_def) |
1205 by (induct n) (auto simp: one_ereal_def) |
1206 |
1206 |
1207 lemma ereal_power_PInf[simp]: "(\<infinity>::ereal) ^ n = (if n = 0 then 1 else \<infinity>)" |
1207 lemma ereal_power_PInf[simp]: "(\<infinity>::ereal) ^ n = (if n = 0 then 1 else \<infinity>)" |
1221 assumes "0 \<le> a" |
1221 assumes "0 \<le> a" |
1222 shows "0 \<le> a ^ n" |
1222 shows "0 \<le> a ^ n" |
1223 using assms by (induct n) (auto simp: ereal_zero_le_0_iff) |
1223 using assms by (induct n) (auto simp: ereal_zero_le_0_iff) |
1224 |
1224 |
1225 |
1225 |
1226 subsubsection {* Subtraction *} |
1226 subsubsection \<open>Subtraction\<close> |
1227 |
1227 |
1228 lemma ereal_minus_minus_image[simp]: |
1228 lemma ereal_minus_minus_image[simp]: |
1229 fixes S :: "ereal set" |
1229 fixes S :: "ereal set" |
1230 shows "uminus ` uminus ` S = S" |
1230 shows "uminus ` uminus ` S = S" |
1231 by (auto simp: image_iff) |
1231 by (auto simp: image_iff) |
1625 then have "\<infinity> \<notin> S" |
1625 then have "\<infinity> \<notin> S" |
1626 by force |
1626 by force |
1627 show ?thesis |
1627 show ?thesis |
1628 proof (cases "S \<noteq> {-\<infinity>} \<and> S \<noteq> {}") |
1628 proof (cases "S \<noteq> {-\<infinity>} \<and> S \<noteq> {}") |
1629 case True |
1629 case True |
1630 with `\<infinity> \<notin> S` obtain x where x: "x \<in> S" "\<bar>x\<bar> \<noteq> \<infinity>" |
1630 with \<open>\<infinity> \<notin> S\<close> obtain x where x: "x \<in> S" "\<bar>x\<bar> \<noteq> \<infinity>" |
1631 by auto |
1631 by auto |
1632 obtain s where s: "\<forall>x\<in>ereal -` S. x \<le> s" "\<And>z. (\<forall>x\<in>ereal -` S. x \<le> z) \<Longrightarrow> s \<le> z" |
1632 obtain s where s: "\<forall>x\<in>ereal -` S. x \<le> s" "\<And>z. (\<forall>x\<in>ereal -` S. x \<le> z) \<Longrightarrow> s \<le> z" |
1633 proof (atomize_elim, rule complete_real) |
1633 proof (atomize_elim, rule complete_real) |
1634 show "\<exists>x. x \<in> ereal -` S" |
1634 show "\<exists>x. x \<in> ereal -` S" |
1635 using x by auto |
1635 using x by auto |
1638 qed |
1638 qed |
1639 show ?thesis |
1639 show ?thesis |
1640 proof (safe intro!: exI[of _ "ereal s"]) |
1640 proof (safe intro!: exI[of _ "ereal s"]) |
1641 fix y |
1641 fix y |
1642 assume "y \<in> S" |
1642 assume "y \<in> S" |
1643 with s `\<infinity> \<notin> S` show "y \<le> ereal s" |
1643 with s \<open>\<infinity> \<notin> S\<close> show "y \<le> ereal s" |
1644 by (cases y) auto |
1644 by (cases y) auto |
1645 next |
1645 next |
1646 fix z |
1646 fix z |
1647 assume "\<forall>y\<in>S. y \<le> z" |
1647 assume "\<forall>y\<in>S. y \<le> z" |
1648 with `S \<noteq> {-\<infinity>} \<and> S \<noteq> {}` show "ereal s \<le> z" |
1648 with \<open>S \<noteq> {-\<infinity>} \<and> S \<noteq> {}\<close> show "ereal s \<le> z" |
1649 by (cases z) (auto intro!: s) |
1649 by (cases z) (auto intro!: s) |
1650 qed |
1650 qed |
1651 next |
1651 next |
1652 case False |
1652 case False |
1653 then show ?thesis |
1653 then show ?thesis |
1771 proof cases |
1771 proof cases |
1772 assume "\<bar>c\<bar> = \<infinity>" |
1772 assume "\<bar>c\<bar> = \<infinity>" |
1773 show ?thesis |
1773 show ?thesis |
1774 proof (rule filterlim_cong[THEN iffD1, OF refl refl _ tendsto_const]) |
1774 proof (rule filterlim_cong[THEN iffD1, OF refl refl _ tendsto_const]) |
1775 have "0 < x \<or> x < 0" |
1775 have "0 < x \<or> x < 0" |
1776 using `x \<noteq> 0` by (auto simp add: neq_iff) |
1776 using \<open>x \<noteq> 0\<close> by (auto simp add: neq_iff) |
1777 then show "eventually (\<lambda>x'. c * x = c * f x') F" |
1777 then show "eventually (\<lambda>x'. c * x = c * f x') F" |
1778 proof |
1778 proof |
1779 assume "0 < x" from order_tendstoD(1)[OF f this] show ?thesis |
1779 assume "0 < x" from order_tendstoD(1)[OF f this] show ?thesis |
1780 by eventually_elim (insert `0<x` `\<bar>c\<bar> = \<infinity>`, auto) |
1780 by eventually_elim (insert \<open>0<x\<close> \<open>\<bar>c\<bar> = \<infinity>\<close>, auto) |
1781 next |
1781 next |
1782 assume "x < 0" from order_tendstoD(2)[OF f this] show ?thesis |
1782 assume "x < 0" from order_tendstoD(2)[OF f this] show ?thesis |
1783 by eventually_elim (insert `x<0` `\<bar>c\<bar> = \<infinity>`, auto) |
1783 by eventually_elim (insert \<open>x<0\<close> \<open>\<bar>c\<bar> = \<infinity>\<close>, auto) |
1784 qed |
1784 qed |
1785 qed |
1785 qed |
1786 qed (rule tendsto_cmult_ereal[OF _ f]) |
1786 qed (rule tendsto_cmult_ereal[OF _ f]) |
1787 |
1787 |
1788 lemma tendsto_cadd_ereal[tendsto_intros, simp, intro]: |
1788 lemma tendsto_cadd_ereal[tendsto_intros, simp, intro]: |
1939 proof cases |
1939 proof cases |
1940 assume "(SUP i:I. f i) = - \<infinity>" |
1940 assume "(SUP i:I. f i) = - \<infinity>" |
1941 moreover then have "\<And>i. i \<in> I \<Longrightarrow> f i = -\<infinity>" |
1941 moreover then have "\<And>i. i \<in> I \<Longrightarrow> f i = -\<infinity>" |
1942 unfolding Sup_eq_MInfty Sup_image_eq[symmetric] by auto |
1942 unfolding Sup_eq_MInfty Sup_image_eq[symmetric] by auto |
1943 ultimately show ?thesis |
1943 ultimately show ?thesis |
1944 by (cases c) (auto simp: `I \<noteq> {}`) |
1944 by (cases c) (auto simp: \<open>I \<noteq> {}\<close>) |
1945 next |
1945 next |
1946 assume "(SUP i:I. f i) \<noteq> - \<infinity>" then show ?thesis |
1946 assume "(SUP i:I. f i) \<noteq> - \<infinity>" then show ?thesis |
1947 unfolding Sup_image_eq[symmetric] |
1947 unfolding Sup_image_eq[symmetric] |
1948 by (subst continuous_at_Sup_mono[where f="\<lambda>x. x + c"]) |
1948 by (subst continuous_at_Sup_mono[where f="\<lambda>x. x + c"]) |
1949 (auto simp: continuous_at_within continuous_at mono_def ereal_add_mono `I \<noteq> {}` `c \<noteq> -\<infinity>`) |
1949 (auto simp: continuous_at_within continuous_at mono_def ereal_add_mono \<open>I \<noteq> {}\<close> \<open>c \<noteq> -\<infinity>\<close>) |
1950 qed |
1950 qed |
1951 |
1951 |
1952 lemma SUP_ereal_add_right: |
1952 lemma SUP_ereal_add_right: |
1953 fixes c :: ereal |
1953 fixes c :: ereal |
1954 shows "I \<noteq> {} \<Longrightarrow> c \<noteq> -\<infinity> \<Longrightarrow> (SUP i:I. c + f i) = c + (SUP i:I. f i)" |
1954 shows "I \<noteq> {} \<Longrightarrow> c \<noteq> -\<infinity> \<Longrightarrow> (SUP i:I. c + f i) = c + (SUP i:I. f i)" |
1961 by (simp add: ereal_SUP_uminus minus_ereal_def) |
1961 by (simp add: ereal_SUP_uminus minus_ereal_def) |
1962 |
1962 |
1963 lemma SUP_ereal_minus_left: |
1963 lemma SUP_ereal_minus_left: |
1964 assumes "I \<noteq> {}" "c \<noteq> \<infinity>" |
1964 assumes "I \<noteq> {}" "c \<noteq> \<infinity>" |
1965 shows "(SUP i:I. f i - c:: ereal) = (SUP i:I. f i) - c" |
1965 shows "(SUP i:I. f i - c:: ereal) = (SUP i:I. f i) - c" |
1966 using SUP_ereal_add_left[OF `I \<noteq> {}`, of "-c" f] by (simp add: `c \<noteq> \<infinity>` minus_ereal_def) |
1966 using SUP_ereal_add_left[OF \<open>I \<noteq> {}\<close>, of "-c" f] by (simp add: \<open>c \<noteq> \<infinity>\<close> minus_ereal_def) |
1967 |
1967 |
1968 lemma INF_ereal_minus_right: |
1968 lemma INF_ereal_minus_right: |
1969 assumes "I \<noteq> {}" and "\<bar>c\<bar> \<noteq> \<infinity>" |
1969 assumes "I \<noteq> {}" and "\<bar>c\<bar> \<noteq> \<infinity>" |
1970 shows "(INF i:I. c - f i) = c - (SUP i:I. f i::ereal)" |
1970 shows "(INF i:I. c - f i) = c - (SUP i:I. f i::ereal)" |
1971 proof - |
1971 proof - |
1972 { fix b have "(-c) + b = - (c - b)" |
1972 { fix b have "(-c) + b = - (c - b)" |
1973 using `\<bar>c\<bar> \<noteq> \<infinity>` by (cases c b rule: ereal2_cases) auto } |
1973 using \<open>\<bar>c\<bar> \<noteq> \<infinity>\<close> by (cases c b rule: ereal2_cases) auto } |
1974 note * = this |
1974 note * = this |
1975 show ?thesis |
1975 show ?thesis |
1976 using SUP_ereal_add_right[OF `I \<noteq> {}`, of "-c" f] `\<bar>c\<bar> \<noteq> \<infinity>` |
1976 using SUP_ereal_add_right[OF \<open>I \<noteq> {}\<close>, of "-c" f] \<open>\<bar>c\<bar> \<noteq> \<infinity>\<close> |
1977 by (auto simp add: * ereal_SUP_uminus_eq) |
1977 by (auto simp add: * ereal_SUP_uminus_eq) |
1978 qed |
1978 qed |
1979 |
1979 |
1980 lemma SUP_ereal_le_addI: |
1980 lemma SUP_ereal_le_addI: |
1981 fixes f :: "'i \<Rightarrow> ereal" |
1981 fixes f :: "'i \<Rightarrow> ereal" |
1982 assumes "\<And>i. f i + y \<le> z" and "y \<noteq> -\<infinity>" |
1982 assumes "\<And>i. f i + y \<le> z" and "y \<noteq> -\<infinity>" |
1983 shows "SUPREMUM UNIV f + y \<le> z" |
1983 shows "SUPREMUM UNIV f + y \<le> z" |
1984 unfolding SUP_ereal_add_left[OF UNIV_not_empty `y \<noteq> -\<infinity>`, symmetric] |
1984 unfolding SUP_ereal_add_left[OF UNIV_not_empty \<open>y \<noteq> -\<infinity>\<close>, symmetric] |
1985 by (rule SUP_least assms)+ |
1985 by (rule SUP_least assms)+ |
1986 |
1986 |
1987 lemma SUP_combine: |
1987 lemma SUP_combine: |
1988 fixes f :: "'a::semilattice_sup \<Rightarrow> 'a::semilattice_sup \<Rightarrow> 'b::complete_lattice" |
1988 fixes f :: "'a::semilattice_sup \<Rightarrow> 'a::semilattice_sup \<Rightarrow> 'b::complete_lattice" |
1989 assumes mono: "\<And>a b c d. a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> f a c \<le> f b d" |
1989 assumes mono: "\<And>a b c d. a \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> f a c \<le> f b d" |
2067 by simp |
2067 by simp |
2068 next |
2068 next |
2069 assume "(SUP i:I. f i) \<noteq> 0" then show ?thesis |
2069 assume "(SUP i:I. f i) \<noteq> 0" then show ?thesis |
2070 unfolding SUP_def |
2070 unfolding SUP_def |
2071 by (subst continuous_at_Sup_mono[where f="\<lambda>x. c * x"]) |
2071 by (subst continuous_at_Sup_mono[where f="\<lambda>x. c * x"]) |
2072 (auto simp: mono_def continuous_at continuous_at_within `I \<noteq> {}` |
2072 (auto simp: mono_def continuous_at continuous_at_within \<open>I \<noteq> {}\<close> |
2073 intro!: ereal_mult_left_mono c) |
2073 intro!: ereal_mult_left_mono c) |
2074 qed |
2074 qed |
2075 |
2075 |
2076 lemma countable_approach: |
2076 lemma countable_approach: |
2077 fixes x :: ereal |
2077 fixes x :: ereal |
2091 lemma Sup_countable_SUP: |
2091 lemma Sup_countable_SUP: |
2092 assumes "A \<noteq> {}" |
2092 assumes "A \<noteq> {}" |
2093 shows "\<exists>f::nat \<Rightarrow> ereal. incseq f \<and> range f \<subseteq> A \<and> Sup A = (SUP i. f i)" |
2093 shows "\<exists>f::nat \<Rightarrow> ereal. incseq f \<and> range f \<subseteq> A \<and> Sup A = (SUP i. f i)" |
2094 proof cases |
2094 proof cases |
2095 assume "Sup A = -\<infinity>" |
2095 assume "Sup A = -\<infinity>" |
2096 with `A \<noteq> {}` have "A = {-\<infinity>}" |
2096 with \<open>A \<noteq> {}\<close> have "A = {-\<infinity>}" |
2097 by (auto simp: Sup_eq_MInfty) |
2097 by (auto simp: Sup_eq_MInfty) |
2098 then show ?thesis |
2098 then show ?thesis |
2099 by (auto intro!: exI[of _ "\<lambda>_. -\<infinity>"] simp: bot_ereal_def) |
2099 by (auto intro!: exI[of _ "\<lambda>_. -\<infinity>"] simp: bot_ereal_def) |
2100 next |
2100 next |
2101 assume "Sup A \<noteq> -\<infinity>" |
2101 assume "Sup A \<noteq> -\<infinity>" |
2118 by (auto simp: incseq_Suc_iff) |
2118 by (auto simp: incseq_Suc_iff) |
2119 moreover |
2119 moreover |
2120 have "(SUP i. f i) = Sup A" |
2120 have "(SUP i. f i) = Sup A" |
2121 proof (rule tendsto_unique) |
2121 proof (rule tendsto_unique) |
2122 show "f ----> (SUP i. f i)" |
2122 show "f ----> (SUP i. f i)" |
2123 by (rule LIMSEQ_SUP `incseq f`)+ |
2123 by (rule LIMSEQ_SUP \<open>incseq f\<close>)+ |
2124 show "f ----> Sup A" |
2124 show "f ----> Sup A" |
2125 using l f |
2125 using l f |
2126 by (intro tendsto_sandwich[OF _ _ l_Sup tendsto_const]) |
2126 by (intro tendsto_sandwich[OF _ _ l_Sup tendsto_const]) |
2127 (auto simp: Sup_upper) |
2127 (auto simp: Sup_upper) |
2128 qed simp |
2128 qed simp |
2320 assumes "open S" |
2320 assumes "open S" |
2321 and "x \<in> S" |
2321 and "x \<in> S" |
2322 and "\<bar>x\<bar> \<noteq> \<infinity>" |
2322 and "\<bar>x\<bar> \<noteq> \<infinity>" |
2323 obtains e where "e > 0" and "{x-e <..< x+e} \<subseteq> S" |
2323 obtains e where "e > 0" and "{x-e <..< x+e} \<subseteq> S" |
2324 proof - |
2324 proof - |
2325 from `open S` |
2325 from \<open>open S\<close> |
2326 have "open (ereal -` S)" |
2326 have "open (ereal -` S)" |
2327 by (rule ereal_openE) |
2327 by (rule ereal_openE) |
2328 then obtain e where "e > 0" and e: "\<And>y. dist y (real x) < e \<Longrightarrow> ereal y \<in> S" |
2328 then obtain e where "e > 0" and e: "\<And>y. dist y (real x) < e \<Longrightarrow> ereal y \<in> S" |
2329 using assms unfolding open_dist by force |
2329 using assms unfolding open_dist by force |
2330 show thesis |
2330 show thesis |
2331 proof (intro that subsetI) |
2331 proof (intro that subsetI) |
2332 show "0 < ereal e" |
2332 show "0 < ereal e" |
2333 using `0 < e` by auto |
2333 using \<open>0 < e\<close> by auto |
2334 fix y |
2334 fix y |
2335 assume "y \<in> {x - ereal e<..<x + ereal e}" |
2335 assume "y \<in> {x - ereal e<..<x + ereal e}" |
2336 with assms obtain t where "y = ereal t" "dist t (real x) < e" |
2336 with assms obtain t where "y = ereal t" "dist t (real x) < e" |
2337 by (cases y) (auto simp: dist_real_def) |
2337 by (cases y) (auto simp: dist_real_def) |
2338 then show "y \<in> S" |
2338 then show "y \<in> S" |
2352 with that[of "x - e" "x + e"] ereal_between[OF x, of e] |
2352 with that[of "x - e" "x + e"] ereal_between[OF x, of e] |
2353 show thesis |
2353 show thesis |
2354 by auto |
2354 by auto |
2355 qed |
2355 qed |
2356 |
2356 |
2357 subsubsection {* Convergent sequences *} |
2357 subsubsection \<open>Convergent sequences\<close> |
2358 |
2358 |
2359 lemma lim_real_of_ereal[simp]: |
2359 lemma lim_real_of_ereal[simp]: |
2360 assumes lim: "(f ---> ereal x) net" |
2360 assumes lim: "(f ---> ereal x) net" |
2361 shows "((\<lambda>x. real (f x)) ---> x) net" |
2361 shows "((\<lambda>x. real (f x)) ---> x) net" |
2362 proof (intro topological_tendstoI) |
2362 proof (intro topological_tendstoI) |
2475 and tendsto: "((\<lambda>x. ereal (real (f x))) ---> x) net" |
2475 and tendsto: "((\<lambda>x. ereal (real (f x))) ---> x) net" |
2476 shows "(f ---> x) net" |
2476 shows "(f ---> x) net" |
2477 proof (intro topological_tendstoI) |
2477 proof (intro topological_tendstoI) |
2478 fix S |
2478 fix S |
2479 assume S: "open S" "x \<in> S" |
2479 assume S: "open S" "x \<in> S" |
2480 with `x \<noteq> 0` have "open (S - {0})" "x \<in> S - {0}" |
2480 with \<open>x \<noteq> 0\<close> have "open (S - {0})" "x \<in> S - {0}" |
2481 by auto |
2481 by auto |
2482 from tendsto[THEN topological_tendstoD, OF this] |
2482 from tendsto[THEN topological_tendstoD, OF this] |
2483 show "eventually (\<lambda>x. f x \<in> S) net" |
2483 show "eventually (\<lambda>x. f x \<in> S) net" |
2484 by (rule eventually_rev_mp) (auto simp: ereal_real) |
2484 by (rule eventually_rev_mp) (auto simp: ereal_real) |
2485 qed |
2485 qed |
2616 using assms by (cases x) auto |
2616 using assms by (cases x) auto |
2617 fix S |
2617 fix S |
2618 assume "open S" and "x \<in> S" |
2618 assume "open S" and "x \<in> S" |
2619 then have "open (ereal -` S)" |
2619 then have "open (ereal -` S)" |
2620 unfolding open_ereal_def by auto |
2620 unfolding open_ereal_def by auto |
2621 with `x \<in> S` obtain r where "0 < r" and dist: "\<And>y. dist y rx < r \<Longrightarrow> ereal y \<in> S" |
2621 with \<open>x \<in> S\<close> obtain r where "0 < r" and dist: "\<And>y. dist y rx < r \<Longrightarrow> ereal y \<in> S" |
2622 unfolding open_real_def rx by auto |
2622 unfolding open_real_def rx by auto |
2623 then obtain n where |
2623 then obtain n where |
2624 upper: "\<And>N. n \<le> N \<Longrightarrow> u N < x + ereal r" and |
2624 upper: "\<And>N. n \<le> N \<Longrightarrow> u N < x + ereal r" and |
2625 lower: "\<And>N. n \<le> N \<Longrightarrow> x < u N + ereal r" |
2625 lower: "\<And>N. n \<le> N \<Longrightarrow> x < u N + ereal r" |
2626 using assms(2)[of "ereal r"] by auto |
2626 using assms(2)[of "ereal r"] by auto |
2627 show "\<exists>N. \<forall>n\<ge>N. u n \<in> S" |
2627 show "\<exists>N. \<forall>n\<ge>N. u n \<in> S" |
2628 proof (safe intro!: exI[of _ n]) |
2628 proof (safe intro!: exI[of _ n]) |
2629 fix N |
2629 fix N |
2630 assume "n \<le> N" |
2630 assume "n \<le> N" |
2631 from upper[OF this] lower[OF this] assms `0 < r` |
2631 from upper[OF this] lower[OF this] assms \<open>0 < r\<close> |
2632 have "u N \<notin> {\<infinity>,(-\<infinity>)}" |
2632 have "u N \<notin> {\<infinity>,(-\<infinity>)}" |
2633 by auto |
2633 by auto |
2634 then obtain ra where ra_def: "(u N) = ereal ra" |
2634 then obtain ra where ra_def: "(u N) = ereal ra" |
2635 by (cases "u N") auto |
2635 by (cases "u N") auto |
2636 then have "rx < ra + r" and "ra < rx + r" |
2636 then have "rx < ra + r" and "ra < rx + r" |
2637 using rx assms `0 < r` lower[OF `n \<le> N`] upper[OF `n \<le> N`] |
2637 using rx assms \<open>0 < r\<close> lower[OF \<open>n \<le> N\<close>] upper[OF \<open>n \<le> N\<close>] |
2638 by auto |
2638 by auto |
2639 then have "dist (real (u N)) rx < r" |
2639 then have "dist (real (u N)) rx < r" |
2640 using rx ra_def |
2640 using rx ra_def |
2641 by (auto simp: dist_real_def abs_diff_less_iff field_simps) |
2641 by (auto simp: dist_real_def abs_diff_less_iff field_simps) |
2642 from dist[OF this] show "u N \<in> S" |
2642 from dist[OF this] show "u N \<in> S" |
2643 using `u N \<notin> {\<infinity>, -\<infinity>}` |
2643 using \<open>u N \<notin> {\<infinity>, -\<infinity>}\<close> |
2644 by (auto simp: ereal_real split: split_if_asm) |
2644 by (auto simp: ereal_real split: split_if_asm) |
2645 qed |
2645 qed |
2646 qed |
2646 qed |
2647 |
2647 |
2648 lemma tendsto_obtains_N: |
2648 lemma tendsto_obtains_N: |
2663 { |
2663 { |
2664 fix r :: ereal |
2664 fix r :: ereal |
2665 assume "r > 0" |
2665 assume "r > 0" |
2666 then obtain N where "\<forall>n\<ge>N. u n \<in> {x - r <..< x + r}" |
2666 then obtain N where "\<forall>n\<ge>N. u n \<in> {x - r <..< x + r}" |
2667 apply (subst tendsto_obtains_N[of u x "{x - r <..< x + r}"]) |
2667 apply (subst tendsto_obtains_N[of u x "{x - r <..< x + r}"]) |
2668 using lim ereal_between[of x r] assms `r > 0` |
2668 using lim ereal_between[of x r] assms \<open>r > 0\<close> |
2669 apply auto |
2669 apply auto |
2670 done |
2670 done |
2671 then have "\<exists>N. \<forall>n\<ge>N. u n < x + r \<and> x < u n + r" |
2671 then have "\<exists>N. \<forall>n\<ge>N. u n < x + r \<and> x < u n + r" |
2672 using ereal_minus_less[of r x] |
2672 using ereal_minus_less[of r x] |
2673 by (cases r) auto |
2673 by (cases r) auto |
2766 also have "(?lhs / x) * x = ?lhs" using False ereal_divide_eq mult.commute by force |
2766 also have "(?lhs / x) * x = ?lhs" using False ereal_divide_eq mult.commute by force |
2767 finally show "?lhs \<le> ?rhs" . |
2767 finally show "?lhs \<le> ?rhs" . |
2768 qed |
2768 qed |
2769 qed |
2769 qed |
2770 |
2770 |
2771 subsubsection {* Tests for code generator *} |
2771 subsubsection \<open>Tests for code generator\<close> |
2772 |
2772 |
2773 (* A small list of simple arithmetic expressions *) |
2773 (* A small list of simple arithmetic expressions *) |
2774 |
2774 |
2775 value "- \<infinity> :: ereal" |
2775 value "- \<infinity> :: ereal" |
2776 value "\<bar>-\<infinity>\<bar> :: ereal" |
2776 value "\<bar>-\<infinity>\<bar> :: ereal" |