src/HOL/Library/Extended_Real.thy
changeset 61609 77b453bd616f
parent 61245 b77bf45efe21
child 61610 4f54d2759a0b
equal deleted inserted replaced
61553:933eb9e6a1cc 61609:77b453bd616f
   247 lemma ereal_uminus_eq_iff[simp]:
   247 lemma ereal_uminus_eq_iff[simp]:
   248   fixes a b :: ereal
   248   fixes a b :: ereal
   249   shows "-a = -b \<longleftrightarrow> a = b"
   249   shows "-a = -b \<longleftrightarrow> a = b"
   250   by (cases rule: ereal2_cases[of a b]) simp_all
   250   by (cases rule: ereal2_cases[of a b]) simp_all
   251 
   251 
   252 instantiation ereal :: real_of
   252 function real_of_ereal :: "ereal \<Rightarrow> real" where
   253 begin
   253   "real_of_ereal (ereal r) = r"
   254 
   254 | "real_of_ereal \<infinity> = 0"
   255 function real_ereal :: "ereal \<Rightarrow> real" where
   255 | "real_of_ereal (-\<infinity>) = 0"
   256   "real_ereal (ereal r) = r"
       
   257 | "real_ereal \<infinity> = 0"
       
   258 | "real_ereal (-\<infinity>) = 0"
       
   259   by (auto intro: ereal_cases)
   256   by (auto intro: ereal_cases)
   260 termination by standard (rule wf_empty)
   257 termination by standard (rule wf_empty)
   261 
   258 
   262 instance ..
       
   263 end
       
   264 
       
   265 lemma real_of_ereal[simp]:
   259 lemma real_of_ereal[simp]:
   266   "real (- x :: ereal) = - (real x)"
   260   "real_of_ereal (- x :: ereal) = - (real_of_ereal x)"
   267   by (cases x) simp_all
   261   by (cases x) simp_all
   268 
   262 
   269 lemma range_ereal[simp]: "range ereal = UNIV - {\<infinity>, -\<infinity>}"
   263 lemma range_ereal[simp]: "range ereal = UNIV - {\<infinity>, -\<infinity>}"
   270 proof safe
   264 proof safe
   271   fix x
   265   fix x
   376   and plus_ereal_0 [simp]: "x + ereal 0 = x"
   370   and plus_ereal_0 [simp]: "x + ereal 0 = x"
   377 by(simp_all add: zero_ereal_def[symmetric])
   371 by(simp_all add: zero_ereal_def[symmetric])
   378 
   372 
   379 instance ereal :: numeral ..
   373 instance ereal :: numeral ..
   380 
   374 
   381 lemma real_of_ereal_0[simp]: "real (0::ereal) = 0"
   375 lemma real_of_ereal_0[simp]: "real_of_ereal (0::ereal) = 0"
   382   unfolding zero_ereal_def by simp
   376   unfolding zero_ereal_def by simp
   383 
   377 
   384 lemma abs_ereal_zero[simp]: "\<bar>0\<bar> = (0::ereal)"
   378 lemma abs_ereal_zero[simp]: "\<bar>0\<bar> = (0::ereal)"
   385   unfolding zero_ereal_def abs_ereal.simps by simp
   379   unfolding zero_ereal_def abs_ereal.simps by simp
   386 
   380 
   412   fixes a b :: ereal
   406   fixes a b :: ereal
   413   assumes "a \<noteq> -\<infinity>"
   407   assumes "a \<noteq> -\<infinity>"
   414   shows "b + a = c + a \<longleftrightarrow> a = \<infinity> \<or> b = c"
   408   shows "b + a = c + a \<longleftrightarrow> a = \<infinity> \<or> b = c"
   415   using assms by (cases rule: ereal3_cases[of a b c]) auto
   409   using assms by (cases rule: ereal3_cases[of a b c]) auto
   416 
   410 
   417 lemma ereal_real: "ereal (real x) = (if \<bar>x\<bar> = \<infinity> then 0 else x)"
   411 lemma ereal_real: "ereal (real_of_ereal x) = (if \<bar>x\<bar> = \<infinity> then 0 else x)"
   418   by (cases x) simp_all
   412   by (cases x) simp_all
   419 
   413 
   420 lemma real_of_ereal_add:
   414 lemma real_of_ereal_add:
   421   fixes a b :: ereal
   415   fixes a b :: ereal
   422   shows "real (a + b) =
   416   shows "real_of_ereal (a + b) =
   423     (if (\<bar>a\<bar> = \<infinity>) \<and> (\<bar>b\<bar> = \<infinity>) \<or> (\<bar>a\<bar> \<noteq> \<infinity>) \<and> (\<bar>b\<bar> \<noteq> \<infinity>) then real a + real b else 0)"
   417     (if (\<bar>a\<bar> = \<infinity>) \<and> (\<bar>b\<bar> = \<infinity>) \<or> (\<bar>a\<bar> \<noteq> \<infinity>) \<and> (\<bar>b\<bar> \<noteq> \<infinity>) then real_of_ereal a + real_of_ereal b else 0)"
   424   by (cases rule: ereal2_cases[of a b]) auto
   418   by (cases rule: ereal2_cases[of a b]) auto
   425 
   419 
   426 
   420 
   427 subsubsection "Linear order on @{typ ereal}"
   421 subsubsection "Linear order on @{typ ereal}"
   428 
   422 
   519     by (cases rule: ereal3_cases[of a b c]) auto
   513     by (cases rule: ereal3_cases[of a b c]) auto
   520 qed
   514 qed
   521 
   515 
   522 lemma real_of_ereal_positive_mono:
   516 lemma real_of_ereal_positive_mono:
   523   fixes x y :: ereal
   517   fixes x y :: ereal
   524   shows "0 \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> y \<noteq> \<infinity> \<Longrightarrow> real x \<le> real y"
   518   shows "0 \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> y \<noteq> \<infinity> \<Longrightarrow> real_of_ereal x \<le> real_of_ereal y"
   525   by (cases rule: ereal2_cases[of x y]) auto
   519   by (cases rule: ereal2_cases[of x y]) auto
   526 
   520 
   527 lemma ereal_MInfty_lessI[intro, simp]:
   521 lemma ereal_MInfty_lessI[intro, simp]:
   528   fixes a :: ereal
   522   fixes a :: ereal
   529   shows "a \<noteq> -\<infinity> \<Longrightarrow> -\<infinity> < a"
   523   shows "a \<noteq> -\<infinity> \<Longrightarrow> -\<infinity> < a"
   566   fixes a b :: ereal
   560   fixes a b :: ereal
   567   shows "- a < - b \<longleftrightarrow> b < a"
   561   shows "- a < - b \<longleftrightarrow> b < a"
   568   by (cases rule: ereal2_cases[of a b]) auto
   562   by (cases rule: ereal2_cases[of a b]) auto
   569 
   563 
   570 lemma ereal_le_real_iff:
   564 lemma ereal_le_real_iff:
   571   "x \<le> real y \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x \<le> y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x \<le> 0)"
   565   "x \<le> real_of_ereal y \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x \<le> y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x \<le> 0)"
   572   by (cases y) auto
   566   by (cases y) auto
   573 
   567 
   574 lemma real_le_ereal_iff:
   568 lemma real_le_ereal_iff:
   575   "real y \<le> x \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y \<le> ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 \<le> x)"
   569   "real_of_ereal y \<le> x \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y \<le> ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 \<le> x)"
   576   by (cases y) auto
   570   by (cases y) auto
   577 
   571 
   578 lemma ereal_less_real_iff:
   572 lemma ereal_less_real_iff:
   579   "x < real y \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x < y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x < 0)"
   573   "x < real_of_ereal y \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x < y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x < 0)"
   580   by (cases y) auto
   574   by (cases y) auto
   581 
   575 
   582 lemma real_less_ereal_iff:
   576 lemma real_less_ereal_iff:
   583   "real y < x \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y < ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 < x)"
   577   "real_of_ereal y < x \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y < ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 < x)"
   584   by (cases y) auto
   578   by (cases y) auto
   585 
   579 
   586 lemma real_of_ereal_pos:
   580 lemma real_of_ereal_pos:
   587   fixes x :: ereal
   581   fixes x :: ereal
   588   shows "0 \<le> x \<Longrightarrow> 0 \<le> real x" by (cases x) auto
   582   shows "0 \<le> x \<Longrightarrow> 0 \<le> real_of_ereal x" by (cases x) auto
   589 
   583 
   590 lemmas real_of_ereal_ord_simps =
   584 lemmas real_of_ereal_ord_simps =
   591   ereal_le_real_iff real_le_ereal_iff ereal_less_real_iff real_less_ereal_iff
   585   ereal_le_real_iff real_le_ereal_iff ereal_less_real_iff real_less_ereal_iff
   592 
   586 
   593 lemma abs_ereal_ge0[simp]: "0 \<le> x \<Longrightarrow> \<bar>x :: ereal\<bar> = x"
   587 lemma abs_ereal_ge0[simp]: "0 \<le> x \<Longrightarrow> \<bar>x :: ereal\<bar> = x"
   597   by (cases x) auto
   591   by (cases x) auto
   598 
   592 
   599 lemma abs_ereal_pos[simp]: "0 \<le> \<bar>x :: ereal\<bar>"
   593 lemma abs_ereal_pos[simp]: "0 \<le> \<bar>x :: ereal\<bar>"
   600   by (cases x) auto
   594   by (cases x) auto
   601 
   595 
   602 lemma real_of_ereal_le_0[simp]: "real (x :: ereal) \<le> 0 \<longleftrightarrow> x \<le> 0 \<or> x = \<infinity>"
   596 lemma real_of_ereal_le_0[simp]: "real_of_ereal (x :: ereal) \<le> 0 \<longleftrightarrow> x \<le> 0 \<or> x = \<infinity>"
   603   by (cases x) auto
   597   by (cases x) auto
   604 
   598 
   605 lemma abs_real_of_ereal[simp]: "\<bar>real (x :: ereal)\<bar> = real \<bar>x\<bar>"
   599 lemma abs_real_of_ereal[simp]: "\<bar>real_of_ereal (x :: ereal)\<bar> = real_of_ereal \<bar>x\<bar>"
   606   by (cases x) auto
   600   by (cases x) auto
   607 
   601 
   608 lemma zero_less_real_of_ereal:
   602 lemma zero_less_real_of_ereal:
   609   fixes x :: ereal
   603   fixes x :: ereal
   610   shows "0 < real x \<longleftrightarrow> 0 < x \<and> x \<noteq> \<infinity>"
   604   shows "0 < real_of_ereal x \<longleftrightarrow> 0 < x \<and> x \<noteq> \<infinity>"
   611   by (cases x) auto
   605   by (cases x) auto
   612 
   606 
   613 lemma ereal_0_le_uminus_iff[simp]:
   607 lemma ereal_0_le_uminus_iff[simp]:
   614   fixes a :: ereal
   608   fixes a :: ereal
   615   shows "0 \<le> - a \<longleftrightarrow> a \<le> 0"
   609   shows "0 \<le> - a \<longleftrightarrow> a \<le> 0"
   806 qed
   800 qed
   807 
   801 
   808 lemma setsum_real_of_ereal:
   802 lemma setsum_real_of_ereal:
   809   fixes f :: "'i \<Rightarrow> ereal"
   803   fixes f :: "'i \<Rightarrow> ereal"
   810   assumes "\<And>x. x \<in> S \<Longrightarrow> \<bar>f x\<bar> \<noteq> \<infinity>"
   804   assumes "\<And>x. x \<in> S \<Longrightarrow> \<bar>f x\<bar> \<noteq> \<infinity>"
   811   shows "(\<Sum>x\<in>S. real (f x)) = real (setsum f S)"
   805   shows "(\<Sum>x\<in>S. real_of_ereal (f x)) = real_of_ereal (setsum f S)"
   812 proof -
   806 proof -
   813   have "\<forall>x\<in>S. \<exists>r. f x = ereal r"
   807   have "\<forall>x\<in>S. \<exists>r. f x = ereal r"
   814   proof
   808   proof
   815     fix x
   809     fix x
   816     assume "x \<in> S"
   810     assume "x \<in> S"
   884 end
   878 end
   885 
   879 
   886 lemma one_not_le_zero_ereal[simp]: "\<not> (1 \<le> (0::ereal))"
   880 lemma one_not_le_zero_ereal[simp]: "\<not> (1 \<le> (0::ereal))"
   887   by (simp add: one_ereal_def zero_ereal_def)
   881   by (simp add: one_ereal_def zero_ereal_def)
   888 
   882 
   889 lemma real_ereal_1[simp]: "real (1::ereal) = 1"
   883 lemma real_ereal_1[simp]: "real_of_ereal (1::ereal) = 1"
   890   unfolding one_ereal_def by simp
   884   unfolding one_ereal_def by simp
   891 
   885 
   892 lemma real_of_ereal_le_1:
   886 lemma real_of_ereal_le_1:
   893   fixes a :: ereal
   887   fixes a :: ereal
   894   shows "a \<le> 1 \<Longrightarrow> real a \<le> 1"
   888   shows "a \<le> 1 \<Longrightarrow> real_of_ereal a \<le> 1"
   895   by (cases a) (auto simp: one_ereal_def)
   889   by (cases a) (auto simp: one_ereal_def)
   896 
   890 
   897 lemma abs_ereal_one[simp]: "\<bar>1\<bar> = (1::ereal)"
   891 lemma abs_ereal_one[simp]: "\<bar>1\<bar> = (1::ereal)"
   898   unfolding one_ereal_def by simp
   892   unfolding one_ereal_def by simp
   899 
   893 
  1359   using assms
  1353   using assms
  1360   by (cases rule: ereal3_cases[case_product ereal_cases, of A B C D]) simp_all
  1354   by (cases rule: ereal3_cases[case_product ereal_cases, of A B C D]) simp_all
  1361 
  1355 
  1362 lemma real_of_ereal_minus:
  1356 lemma real_of_ereal_minus:
  1363   fixes a b :: ereal
  1357   fixes a b :: ereal
  1364   shows "real (a - b) = (if \<bar>a\<bar> = \<infinity> \<or> \<bar>b\<bar> = \<infinity> then 0 else real a - real b)"
  1358   shows "real_of_ereal (a - b) = (if \<bar>a\<bar> = \<infinity> \<or> \<bar>b\<bar> = \<infinity> then 0 else real_of_ereal a - real_of_ereal b)"
  1365   by (cases rule: ereal2_cases[of a b]) auto
  1359   by (cases rule: ereal2_cases[of a b]) auto
  1366 
  1360 
  1367 lemma real_of_ereal_minus': "\<bar>x\<bar> = \<infinity> \<longleftrightarrow> \<bar>y\<bar> = \<infinity> \<Longrightarrow> real x - real y = real (x - y :: ereal)"
  1361 lemma real_of_ereal_minus': "\<bar>x\<bar> = \<infinity> \<longleftrightarrow> \<bar>y\<bar> = \<infinity> \<Longrightarrow> real_of_ereal x - real_of_ereal y = real_of_ereal (x - y :: ereal)"
  1368 by(subst real_of_ereal_minus) auto
  1362 by(subst real_of_ereal_minus) auto
  1369 
  1363 
  1370 lemma ereal_diff_positive:
  1364 lemma ereal_diff_positive:
  1371   fixes a b :: ereal shows "a \<le> b \<Longrightarrow> 0 \<le> b - a"
  1365   fixes a b :: ereal shows "a \<le> b \<Longrightarrow> 0 \<le> b - a"
  1372   by (cases rule: ereal2_cases[of a b]) auto
  1366   by (cases rule: ereal2_cases[of a b]) auto
  1409 
  1403 
  1410 end
  1404 end
  1411 
  1405 
  1412 lemma real_of_ereal_inverse[simp]:
  1406 lemma real_of_ereal_inverse[simp]:
  1413   fixes a :: ereal
  1407   fixes a :: ereal
  1414   shows "real (inverse a) = 1 / real a"
  1408   shows "real_of_ereal (inverse a) = 1 / real_of_ereal a"
  1415   by (cases a) (auto simp: inverse_eq_divide)
  1409   by (cases a) (auto simp: inverse_eq_divide)
  1416 
  1410 
  1417 lemma ereal_inverse[simp]:
  1411 lemma ereal_inverse[simp]:
  1418   "inverse (0::ereal) = \<infinity>"
  1412   "inverse (0::ereal) = \<infinity>"
  1419   "inverse (1::ereal) = 1"
  1413   "inverse (1::ereal) = 1"
  2305 lemma eventually_finite:
  2299 lemma eventually_finite:
  2306   fixes x :: ereal
  2300   fixes x :: ereal
  2307   assumes "\<bar>x\<bar> \<noteq> \<infinity>" "(f ---> x) F"
  2301   assumes "\<bar>x\<bar> \<noteq> \<infinity>" "(f ---> x) F"
  2308   shows "eventually (\<lambda>x. \<bar>f x\<bar> \<noteq> \<infinity>) F"
  2302   shows "eventually (\<lambda>x. \<bar>f x\<bar> \<noteq> \<infinity>) F"
  2309 proof -
  2303 proof -
  2310   have "(f ---> ereal (real x)) F"
  2304   have "(f ---> ereal (real_of_ereal x)) F"
  2311     using assms by (cases x) auto
  2305     using assms by (cases x) auto
  2312   then have "eventually (\<lambda>x. f x \<in> ereal ` UNIV) F"
  2306   then have "eventually (\<lambda>x. f x \<in> ereal ` UNIV) F"
  2313     by (rule topological_tendstoD) (auto intro: open_ereal)
  2307     by (rule topological_tendstoD) (auto intro: open_ereal)
  2314   also have "(\<lambda>x. f x \<in> ereal ` UNIV) = (\<lambda>x. \<bar>f x\<bar> \<noteq> \<infinity>)"
  2308   also have "(\<lambda>x. f x \<in> ereal ` UNIV) = (\<lambda>x. \<bar>f x\<bar> \<noteq> \<infinity>)"
  2315     by auto
  2309     by auto
  2369   obtains e where "e > 0" and "{x-e <..< x+e} \<subseteq> S"
  2363   obtains e where "e > 0" and "{x-e <..< x+e} \<subseteq> S"
  2370 proof -
  2364 proof -
  2371   from \<open>open S\<close>
  2365   from \<open>open S\<close>
  2372   have "open (ereal -` S)"
  2366   have "open (ereal -` S)"
  2373     by (rule ereal_openE)
  2367     by (rule ereal_openE)
  2374   then obtain e where "e > 0" and e: "\<And>y. dist y (real x) < e \<Longrightarrow> ereal y \<in> S"
  2368   then obtain e where "e > 0" and e: "\<And>y. dist y (real_of_ereal x) < e \<Longrightarrow> ereal y \<in> S"
  2375     using assms unfolding open_dist by force
  2369     using assms unfolding open_dist by force
  2376   show thesis
  2370   show thesis
  2377   proof (intro that subsetI)
  2371   proof (intro that subsetI)
  2378     show "0 < ereal e"
  2372     show "0 < ereal e"
  2379       using \<open>0 < e\<close> by auto
  2373       using \<open>0 < e\<close> by auto
  2380     fix y
  2374     fix y
  2381     assume "y \<in> {x - ereal e<..<x + ereal e}"
  2375     assume "y \<in> {x - ereal e<..<x + ereal e}"
  2382     with assms obtain t where "y = ereal t" "dist t (real x) < e"
  2376     with assms obtain t where "y = ereal t" "dist t (real_of_ereal x) < e"
  2383       by (cases y) (auto simp: dist_real_def)
  2377       by (cases y) (auto simp: dist_real_def)
  2384     then show "y \<in> S"
  2378     then show "y \<in> S"
  2385       using e[of t] by auto
  2379       using e[of t] by auto
  2386   qed
  2380   qed
  2387 qed
  2381 qed
  2402 
  2396 
  2403 subsubsection \<open>Convergent sequences\<close>
  2397 subsubsection \<open>Convergent sequences\<close>
  2404 
  2398 
  2405 lemma lim_real_of_ereal[simp]:
  2399 lemma lim_real_of_ereal[simp]:
  2406   assumes lim: "(f ---> ereal x) net"
  2400   assumes lim: "(f ---> ereal x) net"
  2407   shows "((\<lambda>x. real (f x)) ---> x) net"
  2401   shows "((\<lambda>x. real_of_ereal (f x)) ---> x) net"
  2408 proof (intro topological_tendstoI)
  2402 proof (intro topological_tendstoI)
  2409   fix S
  2403   fix S
  2410   assume "open S" and "x \<in> S"
  2404   assume "open S" and "x \<in> S"
  2411   then have S: "open S" "ereal x \<in> ereal ` S"
  2405   then have S: "open S" "ereal x \<in> ereal ` S"
  2412     by (simp_all add: inj_image_mem_iff)
  2406     by (simp_all add: inj_image_mem_iff)
  2413   have "\<forall>x. f x \<in> ereal ` S \<longrightarrow> real (f x) \<in> S"
  2407   have "\<forall>x. f x \<in> ereal ` S \<longrightarrow> real_of_ereal (f x) \<in> S"
  2414     by auto
  2408     by auto
  2415   from this lim[THEN topological_tendstoD, OF open_ereal, OF S]
  2409   from this lim[THEN topological_tendstoD, OF open_ereal, OF S]
  2416   show "eventually (\<lambda>x. real (f x) \<in> S) net"
  2410   show "eventually (\<lambda>x. real_of_ereal (f x) \<in> S) net"
  2417     by (rule eventually_mono)
  2411     by (rule eventually_mono)
  2418 qed
  2412 qed
  2419 
  2413 
  2420 lemma lim_ereal[simp]: "((\<lambda>n. ereal (f n)) ---> ereal x) net \<longleftrightarrow> (f ---> x) net"
  2414 lemma lim_ereal[simp]: "((\<lambda>n. ereal (f n)) ---> ereal x) net \<longleftrightarrow> (f ---> x) net"
  2421   by (auto dest!: lim_real_of_ereal)
  2415   by (auto dest!: lim_real_of_ereal)
  2423 lemma tendsto_PInfty: "(f ---> \<infinity>) F \<longleftrightarrow> (\<forall>r. eventually (\<lambda>x. ereal r < f x) F)"
  2417 lemma tendsto_PInfty: "(f ---> \<infinity>) F \<longleftrightarrow> (\<forall>r. eventually (\<lambda>x. ereal r < f x) F)"
  2424 proof -
  2418 proof -
  2425   {
  2419   {
  2426     fix l :: ereal
  2420     fix l :: ereal
  2427     assume "\<forall>r. eventually (\<lambda>x. ereal r < f x) F"
  2421     assume "\<forall>r. eventually (\<lambda>x. ereal r < f x) F"
  2428     from this[THEN spec, of "real l"] have "l \<noteq> \<infinity> \<Longrightarrow> eventually (\<lambda>x. l < f x) F"
  2422     from this[THEN spec, of "real_of_ereal l"] have "l \<noteq> \<infinity> \<Longrightarrow> eventually (\<lambda>x. l < f x) F"
  2429       by (cases l) (auto elim: eventually_elim1)
  2423       by (cases l) (auto elim: eventually_elim1)
  2430   }
  2424   }
  2431   then show ?thesis
  2425   then show ?thesis
  2432     by (auto simp: order_tendsto_iff)
  2426     by (auto simp: order_tendsto_iff)
  2433 qed
  2427 qed
  2505   by (intro tendsto_le[OF trivial_limit_sequentially lim tendsto_const])
  2499   by (intro tendsto_le[OF trivial_limit_sequentially lim tendsto_const])
  2506      (auto simp: eventually_sequentially)
  2500      (auto simp: eventually_sequentially)
  2507 
  2501 
  2508 lemma real_of_ereal_mult[simp]:
  2502 lemma real_of_ereal_mult[simp]:
  2509   fixes a b :: ereal
  2503   fixes a b :: ereal
  2510   shows "real (a * b) = real a * real b"
  2504   shows "real_of_ereal (a * b) = real_of_ereal a * real_of_ereal b"
  2511   by (cases rule: ereal2_cases[of a b]) auto
  2505   by (cases rule: ereal2_cases[of a b]) auto
  2512 
  2506 
  2513 lemma real_of_ereal_eq_0:
  2507 lemma real_of_ereal_eq_0:
  2514   fixes x :: ereal
  2508   fixes x :: ereal
  2515   shows "real x = 0 \<longleftrightarrow> x = \<infinity> \<or> x = -\<infinity> \<or> x = 0"
  2509   shows "real_of_ereal x = 0 \<longleftrightarrow> x = \<infinity> \<or> x = -\<infinity> \<or> x = 0"
  2516   by (cases x) auto
  2510   by (cases x) auto
  2517 
  2511 
  2518 lemma tendsto_ereal_realD:
  2512 lemma tendsto_ereal_realD:
  2519   fixes f :: "'a \<Rightarrow> ereal"
  2513   fixes f :: "'a \<Rightarrow> ereal"
  2520   assumes "x \<noteq> 0"
  2514   assumes "x \<noteq> 0"
  2521     and tendsto: "((\<lambda>x. ereal (real (f x))) ---> x) net"
  2515     and tendsto: "((\<lambda>x. ereal (real_of_ereal (f x))) ---> x) net"
  2522   shows "(f ---> x) net"
  2516   shows "(f ---> x) net"
  2523 proof (intro topological_tendstoI)
  2517 proof (intro topological_tendstoI)
  2524   fix S
  2518   fix S
  2525   assume S: "open S" "x \<in> S"
  2519   assume S: "open S" "x \<in> S"
  2526   with \<open>x \<noteq> 0\<close> have "open (S - {0})" "x \<in> S - {0}"
  2520   with \<open>x \<noteq> 0\<close> have "open (S - {0})" "x \<in> S - {0}"
  2531 qed
  2525 qed
  2532 
  2526 
  2533 lemma tendsto_ereal_realI:
  2527 lemma tendsto_ereal_realI:
  2534   fixes f :: "'a \<Rightarrow> ereal"
  2528   fixes f :: "'a \<Rightarrow> ereal"
  2535   assumes x: "\<bar>x\<bar> \<noteq> \<infinity>" and tendsto: "(f ---> x) net"
  2529   assumes x: "\<bar>x\<bar> \<noteq> \<infinity>" and tendsto: "(f ---> x) net"
  2536   shows "((\<lambda>x. ereal (real (f x))) ---> x) net"
  2530   shows "((\<lambda>x. ereal (real_of_ereal (f x))) ---> x) net"
  2537 proof (intro topological_tendstoI)
  2531 proof (intro topological_tendstoI)
  2538   fix S
  2532   fix S
  2539   assume "open S" and "x \<in> S"
  2533   assume "open S" and "x \<in> S"
  2540   with x have "open (S - {\<infinity>, -\<infinity>})" "x \<in> S - {\<infinity>, -\<infinity>}"
  2534   with x have "open (S - {\<infinity>, -\<infinity>})" "x \<in> S - {\<infinity>, -\<infinity>}"
  2541     by auto
  2535     by auto
  2542   from tendsto[THEN topological_tendstoD, OF this]
  2536   from tendsto[THEN topological_tendstoD, OF this]
  2543   show "eventually (\<lambda>x. ereal (real (f x)) \<in> S) net"
  2537   show "eventually (\<lambda>x. ereal (real_of_ereal (f x)) \<in> S) net"
  2544     by (elim eventually_elim1) (auto simp: ereal_real)
  2538     by (elim eventually_elim1) (auto simp: ereal_real)
  2545 qed
  2539 qed
  2546 
  2540 
  2547 lemma ereal_mult_cancel_left:
  2541 lemma ereal_mult_cancel_left:
  2548   fixes a b c :: ereal
  2542   fixes a b c :: ereal
  2554   assumes x: "\<bar>x\<bar> \<noteq> \<infinity>" and y: "\<bar>y\<bar> \<noteq> \<infinity>"
  2548   assumes x: "\<bar>x\<bar> \<noteq> \<infinity>" and y: "\<bar>y\<bar> \<noteq> \<infinity>"
  2555   assumes f: "(f ---> x) F" and g: "(g ---> y) F"
  2549   assumes f: "(f ---> x) F" and g: "(g ---> y) F"
  2556   shows "((\<lambda>x. f x + g x) ---> x + y) F"
  2550   shows "((\<lambda>x. f x + g x) ---> x + y) F"
  2557 proof -
  2551 proof -
  2558   from x obtain r where x': "x = ereal r" by (cases x) auto
  2552   from x obtain r where x': "x = ereal r" by (cases x) auto
  2559   with f have "((\<lambda>i. real (f i)) ---> r) F" by simp
  2553   with f have "((\<lambda>i. real_of_ereal (f i)) ---> r) F" by simp
  2560   moreover
  2554   moreover
  2561   from y obtain p where y': "y = ereal p" by (cases y) auto
  2555   from y obtain p where y': "y = ereal p" by (cases y) auto
  2562   with g have "((\<lambda>i. real (g i)) ---> p) F" by simp
  2556   with g have "((\<lambda>i. real_of_ereal (g i)) ---> p) F" by simp
  2563   ultimately have "((\<lambda>i. real (f i) + real (g i)) ---> r + p) F"
  2557   ultimately have "((\<lambda>i. real_of_ereal (f i) + real_of_ereal (g i)) ---> r + p) F"
  2564     by (rule tendsto_add)
  2558     by (rule tendsto_add)
  2565   moreover
  2559   moreover
  2566   from eventually_finite[OF x f] eventually_finite[OF y g]
  2560   from eventually_finite[OF x f] eventually_finite[OF y g]
  2567   have "eventually (\<lambda>x. f x + g x = ereal (real (f x) + real (g x))) F"
  2561   have "eventually (\<lambda>x. f x + g x = ereal (real_of_ereal (f x) + real_of_ereal (g x))) F"
  2568     by eventually_elim auto
  2562     by eventually_elim auto
  2569   ultimately show ?thesis
  2563   ultimately show ?thesis
  2570     by (simp add: x' y' cong: filterlim_cong)
  2564     by (simp add: x' y' cong: filterlim_cong)
  2571 qed
  2565 qed
  2572 
  2566 
  2612 lemma ereal_mult_m1[simp]: "x * ereal (-1) = -x"
  2606 lemma ereal_mult_m1[simp]: "x * ereal (-1) = -x"
  2613   by (cases x) auto
  2607   by (cases x) auto
  2614 
  2608 
  2615 lemma ereal_real':
  2609 lemma ereal_real':
  2616   assumes "\<bar>x\<bar> \<noteq> \<infinity>"
  2610   assumes "\<bar>x\<bar> \<noteq> \<infinity>"
  2617   shows "ereal (real x) = x"
  2611   shows "ereal (real_of_ereal x) = x"
  2618   using assms by auto
  2612   using assms by auto
  2619 
  2613 
  2620 lemma real_ereal_id: "real \<circ> ereal = id"
  2614 lemma real_ereal_id: "real_of_ereal \<circ> ereal = id"
  2621 proof -
  2615 proof -
  2622   {
  2616   {
  2623     fix x
  2617     fix x
  2624     have "(real o ereal) x = id x"
  2618     have "(real_of_ereal o ereal) x = id x"
  2625       by auto
  2619       by auto
  2626   }
  2620   }
  2627   then show ?thesis
  2621   then show ?thesis
  2628     using ext by blast
  2622     using ext by blast
  2629 qed
  2623 qed
  2680     then obtain ra where ra_def: "(u N) = ereal ra"
  2674     then obtain ra where ra_def: "(u N) = ereal ra"
  2681       by (cases "u N") auto
  2675       by (cases "u N") auto
  2682     then have "rx < ra + r" and "ra < rx + r"
  2676     then have "rx < ra + r" and "ra < rx + r"
  2683       using rx assms \<open>0 < r\<close> lower[OF \<open>n \<le> N\<close>] upper[OF \<open>n \<le> N\<close>]
  2677       using rx assms \<open>0 < r\<close> lower[OF \<open>n \<le> N\<close>] upper[OF \<open>n \<le> N\<close>]
  2684       by auto
  2678       by auto
  2685     then have "dist (real (u N)) rx < r"
  2679     then have "dist (real_of_ereal (u N)) rx < r"
  2686       using rx ra_def
  2680       using rx ra_def
  2687       by (auto simp: dist_real_def abs_diff_less_iff field_simps)
  2681       by (auto simp: dist_real_def abs_diff_less_iff field_simps)
  2688     from dist[OF this] show "u N \<in> S"
  2682     from dist[OF this] show "u N \<in> S"
  2689       using \<open>u N  \<notin> {\<infinity>, -\<infinity>}\<close>
  2683       using \<open>u N  \<notin> {\<infinity>, -\<infinity>}\<close>
  2690       by (auto simp: ereal_real split: split_if_asm)
  2684       by (auto simp: ereal_real split: split_if_asm)
  3061 
  3055 
  3062 lemma summable_real_of_ereal:
  3056 lemma summable_real_of_ereal:
  3063   fixes f :: "nat \<Rightarrow> ereal"
  3057   fixes f :: "nat \<Rightarrow> ereal"
  3064   assumes f: "\<And>i. 0 \<le> f i"
  3058   assumes f: "\<And>i. 0 \<le> f i"
  3065     and fin: "(\<Sum>i. f i) \<noteq> \<infinity>"
  3059     and fin: "(\<Sum>i. f i) \<noteq> \<infinity>"
  3066   shows "summable (\<lambda>i. real (f i))"
  3060   shows "summable (\<lambda>i. real_of_ereal (f i))"
  3067 proof (rule summable_def[THEN iffD2])
  3061 proof (rule summable_def[THEN iffD2])
  3068   have "0 \<le> (\<Sum>i. f i)"
  3062   have "0 \<le> (\<Sum>i. f i)"
  3069     using assms by (auto intro: suminf_0_le)
  3063     using assms by (auto intro: suminf_0_le)
  3070   with fin obtain r where r: "ereal r = (\<Sum>i. f i)"
  3064   with fin obtain r where r: "ereal r = (\<Sum>i. f i)"
  3071     by (cases "(\<Sum>i. f i)") auto
  3065     by (cases "(\<Sum>i. f i)") auto
  3075       using f by (intro suminf_PInfty[OF _ fin]) auto
  3069       using f by (intro suminf_PInfty[OF _ fin]) auto
  3076     then have "\<bar>f i\<bar> \<noteq> \<infinity>"
  3070     then have "\<bar>f i\<bar> \<noteq> \<infinity>"
  3077       using f[of i] by auto
  3071       using f[of i] by auto
  3078   }
  3072   }
  3079   note fin = this
  3073   note fin = this
  3080   have "(\<lambda>i. ereal (real (f i))) sums (\<Sum>i. ereal (real (f i)))"
  3074   have "(\<lambda>i. ereal (real_of_ereal (f i))) sums (\<Sum>i. ereal (real_of_ereal (f i)))"
  3081     using f
  3075     using f
  3082     by (auto intro!: summable_ereal_pos simp: ereal_le_real_iff zero_ereal_def)
  3076     by (auto intro!: summable_ereal_pos simp: ereal_le_real_iff zero_ereal_def)
  3083   also have "\<dots> = ereal r"
  3077   also have "\<dots> = ereal r"
  3084     using fin r by (auto simp: ereal_real)
  3078     using fin r by (auto simp: ereal_real)
  3085   finally show "\<exists>r. (\<lambda>i. real (f i)) sums r"
  3079   finally show "\<exists>r. (\<lambda>i. real_of_ereal (f i)) sums r"
  3086     by (auto simp: sums_ereal)
  3080     by (auto simp: sums_ereal)
  3087 qed
  3081 qed
  3088 
  3082 
  3089 lemma suminf_SUP_eq:
  3083 lemma suminf_SUP_eq:
  3090   fixes f :: "nat \<Rightarrow> nat \<Rightarrow> ereal"
  3084   fixes f :: "nat \<Rightarrow> nat \<Rightarrow> ereal"
  3557 
  3551 
  3558 
  3552 
  3559 subsubsection \<open>Continuity\<close>
  3553 subsubsection \<open>Continuity\<close>
  3560 
  3554 
  3561 lemma continuous_at_of_ereal:
  3555 lemma continuous_at_of_ereal:
  3562   "\<bar>x0 :: ereal\<bar> \<noteq> \<infinity> \<Longrightarrow> continuous (at x0) real"
  3556   "\<bar>x0 :: ereal\<bar> \<noteq> \<infinity> \<Longrightarrow> continuous (at x0) real_of_ereal"
  3563   unfolding continuous_at
  3557   unfolding continuous_at
  3564   by (rule lim_real_of_ereal) (simp add: ereal_real)
  3558   by (rule lim_real_of_ereal) (simp add: ereal_real)
  3565 
  3559 
  3566 lemma nhds_ereal: "nhds (ereal r) = filtermap ereal (nhds r)"
  3560 lemma nhds_ereal: "nhds (ereal r) = filtermap ereal (nhds r)"
  3567   by (simp add: filtermap_nhds_open_map open_ereal continuous_at_of_ereal)
  3561   by (simp add: filtermap_nhds_open_map open_ereal continuous_at_of_ereal)
  3581   unfolding filter_eq_iff eventually_filtermap eventually_at_top_dense eventually_at_bot_dense
  3575   unfolding filter_eq_iff eventually_filtermap eventually_at_top_dense eventually_at_bot_dense
  3582     eventually_at_left[OF ereal_less(5)] eventually_at_right[OF ereal_less(6)]
  3576     eventually_at_left[OF ereal_less(5)] eventually_at_right[OF ereal_less(6)]
  3583   by (auto simp add: ereal_all_split ereal_ex_split)
  3577   by (auto simp add: ereal_all_split ereal_ex_split)
  3584 
  3578 
  3585 lemma ereal_tendsto_simps1:
  3579 lemma ereal_tendsto_simps1:
  3586   "((f \<circ> real) ---> y) (at_left (ereal x)) \<longleftrightarrow> (f ---> y) (at_left x)"
  3580   "((f \<circ> real_of_ereal) ---> y) (at_left (ereal x)) \<longleftrightarrow> (f ---> y) (at_left x)"
  3587   "((f \<circ> real) ---> y) (at_right (ereal x)) \<longleftrightarrow> (f ---> y) (at_right x)"
  3581   "((f \<circ> real_of_ereal) ---> y) (at_right (ereal x)) \<longleftrightarrow> (f ---> y) (at_right x)"
  3588   "((f \<circ> real) ---> y) (at_left (\<infinity>::ereal)) \<longleftrightarrow> (f ---> y) at_top"
  3582   "((f \<circ> real_of_ereal) ---> y) (at_left (\<infinity>::ereal)) \<longleftrightarrow> (f ---> y) at_top"
  3589   "((f \<circ> real) ---> y) (at_right (-\<infinity>::ereal)) \<longleftrightarrow> (f ---> y) at_bot"
  3583   "((f \<circ> real_of_ereal) ---> y) (at_right (-\<infinity>::ereal)) \<longleftrightarrow> (f ---> y) at_bot"
  3590   unfolding tendsto_compose_filtermap at_left_ereal at_right_ereal at_left_PInf at_right_MInf
  3584   unfolding tendsto_compose_filtermap at_left_ereal at_right_ereal at_left_PInf at_right_MInf
  3591   by (auto simp: filtermap_filtermap filtermap_ident)
  3585   by (auto simp: filtermap_filtermap filtermap_ident)
  3592 
  3586 
  3593 lemma ereal_tendsto_simps2:
  3587 lemma ereal_tendsto_simps2:
  3594   "((ereal \<circ> f) ---> ereal a) F \<longleftrightarrow> (f ---> a) F"
  3588   "((ereal \<circ> f) ---> ereal a) F \<longleftrightarrow> (f ---> a) F"
  3636   fixes f :: "'a::t2_space => real"
  3630   fixes f :: "'a::t2_space => real"
  3637   assumes "open A"
  3631   assumes "open A"
  3638   shows "continuous_on A f \<longleftrightarrow> continuous_on A (ereal \<circ> f)"
  3632   shows "continuous_on A f \<longleftrightarrow> continuous_on A (ereal \<circ> f)"
  3639   unfolding continuous_on_def comp_def lim_ereal ..
  3633   unfolding continuous_on_def comp_def lim_ereal ..
  3640 
  3634 
  3641 lemma continuous_on_real: "continuous_on (UNIV - {\<infinity>, -\<infinity>::ereal}) real"
  3635 lemma continuous_on_real: "continuous_on (UNIV - {\<infinity>, -\<infinity>::ereal}) real_of_ereal"
  3642   using continuous_at_of_ereal continuous_on_eq_continuous_at open_image_ereal
  3636   using continuous_at_of_ereal continuous_on_eq_continuous_at open_image_ereal
  3643   by auto
  3637   by auto
  3644 
  3638 
  3645 lemma continuous_on_iff_real:
  3639 lemma continuous_on_iff_real:
  3646   fixes f :: "'a::t2_space \<Rightarrow> ereal"
  3640   fixes f :: "'a::t2_space \<Rightarrow> ereal"
  3647   assumes *: "\<And>x. x \<in> A \<Longrightarrow> \<bar>f x\<bar> \<noteq> \<infinity>"
  3641   assumes *: "\<And>x. x \<in> A \<Longrightarrow> \<bar>f x\<bar> \<noteq> \<infinity>"
  3648   shows "continuous_on A f \<longleftrightarrow> continuous_on A (real \<circ> f)"
  3642   shows "continuous_on A f \<longleftrightarrow> continuous_on A (real_of_ereal \<circ> f)"
  3649 proof -
  3643 proof -
  3650   have "f ` A \<subseteq> UNIV - {\<infinity>, -\<infinity>}"
  3644   have "f ` A \<subseteq> UNIV - {\<infinity>, -\<infinity>}"
  3651     using assms by force
  3645     using assms by force
  3652   then have *: "continuous_on (f ` A) real"
  3646   then have *: "continuous_on (f ` A) real_of_ereal"
  3653     using continuous_on_real by (simp add: continuous_on_subset)
  3647     using continuous_on_real by (simp add: continuous_on_subset)
  3654   have **: "continuous_on ((real \<circ> f) ` A) ereal"
  3648   have **: "continuous_on ((real_of_ereal \<circ> f) ` A) ereal"
  3655     by (intro continuous_on_ereal continuous_on_id)
  3649     by (intro continuous_on_ereal continuous_on_id)
  3656   {
  3650   {
  3657     assume "continuous_on A f"
  3651     assume "continuous_on A f"
  3658     then have "continuous_on A (real \<circ> f)"
  3652     then have "continuous_on A (real_of_ereal \<circ> f)"
  3659       apply (subst continuous_on_compose)
  3653       apply (subst continuous_on_compose)
  3660       using *
  3654       using *
  3661       apply auto
  3655       apply auto
  3662       done
  3656       done
  3663   }
  3657   }
  3664   moreover
  3658   moreover
  3665   {
  3659   {
  3666     assume "continuous_on A (real \<circ> f)"
  3660     assume "continuous_on A (real_of_ereal \<circ> f)"
  3667     then have "continuous_on A (ereal \<circ> (real \<circ> f))"
  3661     then have "continuous_on A (ereal \<circ> (real_of_ereal \<circ> f))"
  3668       apply (subst continuous_on_compose)
  3662       apply (subst continuous_on_compose)
  3669       using **
  3663       using **
  3670       apply auto
  3664       apply auto
  3671       done
  3665       done
  3672     then have "continuous_on A f"
  3666     then have "continuous_on A f"
  3673       apply (subst continuous_on_cong[of _ A _ "ereal \<circ> (real \<circ> f)"])
  3667       apply (subst continuous_on_cong[of _ A _ "ereal \<circ> (real_of_ereal \<circ> f)"])
  3674       using assms ereal_real
  3668       using assms ereal_real
  3675       apply auto
  3669       apply auto
  3676       done
  3670       done
  3677   }
  3671   }
  3678   ultimately show ?thesis
  3672   ultimately show ?thesis
  3686 
  3680 
  3687 value "- \<infinity> :: ereal"
  3681 value "- \<infinity> :: ereal"
  3688 value "\<bar>-\<infinity>\<bar> :: ereal"
  3682 value "\<bar>-\<infinity>\<bar> :: ereal"
  3689 value "4 + 5 / 4 - ereal 2 :: ereal"
  3683 value "4 + 5 / 4 - ereal 2 :: ereal"
  3690 value "ereal 3 < \<infinity>"
  3684 value "ereal 3 < \<infinity>"
  3691 value "real (\<infinity>::ereal) = 0"
  3685 value "real_of_ereal (\<infinity>::ereal) = 0"
  3692 
  3686 
  3693 end
  3687 end