src/HOL/Probability/Borel_Space.thy
changeset 59361 fd5da2434be4
parent 59353 f0707dc3d9aa
child 59415 854fe701c984
equal deleted inserted replaced
59360:b1e5d552e8cc 59361:fd5da2434be4
   200       using u UN by (intro X.countable_UN' `countable U`) auto
   200       using u UN by (intro X.countable_UN' `countable U`) auto
   201     finally show "\<Union>K \<in> sigma_sets UNIV X" .
   201     finally show "\<Union>K \<in> sigma_sets UNIV X" .
   202   qed auto
   202   qed auto
   203 qed (auto simp: eq intro: generate_topology.Basis)
   203 qed (auto simp: eq intro: generate_topology.Basis)
   204 
   204 
   205 lemma borel_measurable_continuous_on_if:
   205 lemma borel_measurable_continuous_on_restrict:
   206   assumes A: "A \<in> sets borel" and f: "continuous_on A f" and g: "continuous_on (- A) g"
   206   fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
   207   shows "(\<lambda>x. if x \<in> A then f x else g x) \<in> borel_measurable borel"
   207   assumes f: "continuous_on A f"
       
   208   shows "f \<in> borel_measurable (restrict_space borel A)"
   208 proof (rule borel_measurableI)
   209 proof (rule borel_measurableI)
   209   fix S :: "'b set" assume "open S"
   210   fix S :: "'b set" assume "open S"
   210   have "(\<lambda>x. if x \<in> A then f x else g x) -` S \<inter> space borel = (f -` S \<inter> A) \<union> (g -` S \<inter> -A)"
   211   with f obtain T where "f -` S \<inter> A = T \<inter> A" "open T"
   211     by (auto split: split_if_asm)
   212     by (metis continuous_on_open_invariant)
   212   moreover obtain A' where "f -` S \<inter> A = A' \<inter> A" "open A'"
   213   then show "f -` S \<inter> space (restrict_space borel A) \<in> sets (restrict_space borel A)"
   213     using continuous_on_open_invariant[THEN iffD1, rule_format, OF f `open S`] by metis
   214     by (force simp add: sets_restrict_space space_restrict_space)
   214   moreover obtain B' where "g -` S \<inter> -A = B' \<inter> -A" "open B'"
   215 qed
   215     using continuous_on_open_invariant[THEN iffD1, rule_format, OF g `open S`] by metis
   216 
   216   ultimately show "(\<lambda>x. if x \<in> A then f x else g x) -` S \<inter> space borel \<in> sets borel"
   217 lemma borel_measurable_continuous_on1: "continuous_on UNIV f \<Longrightarrow> f \<in> borel_measurable borel"
   217     using A by auto
   218   by (drule borel_measurable_continuous_on_restrict) simp
   218 qed
   219 
       
   220 lemma borel_measurable_continuous_on_if:
       
   221   assumes [measurable]: "A \<in> sets borel" and f: "continuous_on A f" and g: "continuous_on (- A) g"
       
   222   shows "(\<lambda>x. if x \<in> A then f x else g x) \<in> borel_measurable borel"
       
   223   by (rule measurable_piecewise_restrict[where
       
   224        X="\<lambda>b. if b then A else - A" and I=UNIV and f="\<lambda>b x. if b then f x else g x"])
       
   225      (auto intro: f g borel_measurable_continuous_on_restrict)
   219 
   226 
   220 lemma borel_measurable_continuous_countable_exceptions:
   227 lemma borel_measurable_continuous_countable_exceptions:
   221   fixes f :: "'a::t1_space \<Rightarrow> 'b::topological_space"
   228   fixes f :: "'a::t1_space \<Rightarrow> 'b::topological_space"
   222   assumes X: "countable X"
   229   assumes X: "countable X"
   223   assumes "continuous_on (- X) f"
   230   assumes "continuous_on (- X) f"
   226   have "X \<in> sets borel"
   233   have "X \<in> sets borel"
   227     by (rule sets.countable[OF _ X]) auto
   234     by (rule sets.countable[OF _ X]) auto
   228   then show "(\<lambda>x. if x \<in> X then undefined else f x) \<in> borel_measurable borel"
   235   then show "(\<lambda>x. if x \<in> X then undefined else f x) \<in> borel_measurable borel"
   229     by (intro borel_measurable_continuous_on_if assms continuous_intros)
   236     by (intro borel_measurable_continuous_on_if assms continuous_intros)
   230 qed auto
   237 qed auto
   231 
       
   232 lemma borel_measurable_continuous_on1:
       
   233   "continuous_on UNIV f \<Longrightarrow> f \<in> borel_measurable borel"
       
   234   using borel_measurable_continuous_on_if[of UNIV f "\<lambda>_. undefined"]
       
   235   by (auto intro: continuous_on_const)
       
   236 
   238 
   237 lemma borel_measurable_continuous_on:
   239 lemma borel_measurable_continuous_on:
   238   assumes f: "continuous_on UNIV f" and g: "g \<in> borel_measurable M"
   240   assumes f: "continuous_on UNIV f" and g: "g \<in> borel_measurable M"
   239   shows "(\<lambda>x. f (g x)) \<in> borel_measurable M"
   241   shows "(\<lambda>x. f (g x)) \<in> borel_measurable M"
   240   using measurable_comp[OF g borel_measurable_continuous_on1[OF f]] by (simp add: comp_def)
   242   using measurable_comp[OF g borel_measurable_continuous_on1[OF f]] by (simp add: comp_def)
   634   have *: "?set = (\<Union>n. UNIV - {x\<Colon>'a. x \<bullet> i < a + 1 / real (Suc n)})"
   636   have *: "?set = (\<Union>n. UNIV - {x\<Colon>'a. x \<bullet> i < a + 1 / real (Suc n)})"
   635   proof (safe, simp_all add: not_less)
   637   proof (safe, simp_all add: not_less)
   636     fix x :: 'a assume "a < x \<bullet> i"
   638     fix x :: 'a assume "a < x \<bullet> i"
   637     with reals_Archimedean[of "x \<bullet> i - a"]
   639     with reals_Archimedean[of "x \<bullet> i - a"]
   638     obtain n where "a + 1 / real (Suc n) < x \<bullet> i"
   640     obtain n where "a + 1 / real (Suc n) < x \<bullet> i"
   639       by (auto simp: inverse_eq_divide field_simps)
   641       by (auto simp: field_simps)
   640     then show "\<exists>n. a + 1 / real (Suc n) \<le> x \<bullet> i"
   642     then show "\<exists>n. a + 1 / real (Suc n) \<le> x \<bullet> i"
   641       by (blast intro: less_imp_le)
   643       by (blast intro: less_imp_le)
   642   next
   644   next
   643     fix x n
   645     fix x n
   644     have "a < a + 1 / real (Suc n)" by auto
   646     have "a < a + 1 / real (Suc n)" by auto
   671   have *: "{x::'a. x\<bullet>i < a} = (\<Union>n. {x. x\<bullet>i \<le> a - 1/real (Suc n)})"
   673   have *: "{x::'a. x\<bullet>i < a} = (\<Union>n. {x. x\<bullet>i \<le> a - 1/real (Suc n)})"
   672   proof (safe, simp_all)
   674   proof (safe, simp_all)
   673     fix x::'a assume *: "x\<bullet>i < a"
   675     fix x::'a assume *: "x\<bullet>i < a"
   674     with reals_Archimedean[of "a - x\<bullet>i"]
   676     with reals_Archimedean[of "a - x\<bullet>i"]
   675     obtain n where "x \<bullet> i < a - 1 / (real (Suc n))"
   677     obtain n where "x \<bullet> i < a - 1 / (real (Suc n))"
   676       by (auto simp: field_simps inverse_eq_divide)
   678       by (auto simp: field_simps)
   677     then show "\<exists>n. x \<bullet> i \<le> a - 1 / (real (Suc n))"
   679     then show "\<exists>n. x \<bullet> i \<le> a - 1 / (real (Suc n))"
   678       by (blast intro: less_imp_le)
   680       by (blast intro: less_imp_le)
   679   next
   681   next
   680     fix x::'a and n
   682     fix x::'a and n
   681     assume "x\<bullet>i \<le> a - 1 / real (Suc n)"
   683     assume "x\<bullet>i \<le> a - 1 / real (Suc n)"
   682     also have "\<dots> < a" by auto
   684     also have "\<dots> < a" by auto
   683     finally show "x\<bullet>i < a" .
   685     finally show "x\<bullet>i < a" .
   684   qed
   686   qed
   685   show "{x. x\<bullet>i < a} \<in> ?SIGMA" unfolding *
   687   show "{x. x\<bullet>i < a} \<in> ?SIGMA" unfolding *
   686     by (safe intro!: sets.countable_UN) (auto intro: i)
   688     by (intro sets.countable_UN) (auto intro: i)
   687 qed auto
   689 qed auto
   688 
   690 
   689 lemma borel_eq_halfspace_ge:
   691 lemma borel_eq_halfspace_ge:
   690   "borel = sigma UNIV ((\<lambda> (a, i). {x\<Colon>'a\<Colon>euclidean_space. a \<le> x \<bullet> i}) ` (UNIV \<times> Basis))"
   692   "borel = sigma UNIV ((\<lambda> (a, i). {x\<Colon>'a\<Colon>euclidean_space. a \<le> x \<bullet> i}) ` (UNIV \<times> Basis))"
   691   (is "_ = ?SIGMA")
   693   (is "_ = ?SIGMA")
   692 proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
   694 proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
   693   fix a :: real and i :: 'a assume i: "(a, i) \<in> UNIV \<times> Basis"
   695   fix a :: real and i :: 'a assume i: "(a, i) \<in> UNIV \<times> Basis"
   694   have *: "{x::'a. x\<bullet>i < a} = space ?SIGMA - {x::'a. a \<le> x\<bullet>i}" by auto
   696   have *: "{x::'a. x\<bullet>i < a} = space ?SIGMA - {x::'a. a \<le> x\<bullet>i}" by auto
   695   show "{x. x\<bullet>i < a} \<in> ?SIGMA" unfolding *
   697   show "{x. x\<bullet>i < a} \<in> ?SIGMA" unfolding *
   696     using i by (safe intro!: sets.compl_sets) auto
   698     using i by (intro sets.compl_sets) auto
   697 qed auto
   699 qed auto
   698 
   700 
   699 lemma borel_eq_halfspace_greater:
   701 lemma borel_eq_halfspace_greater:
   700   "borel = sigma UNIV ((\<lambda> (a, i). {x\<Colon>'a\<Colon>euclidean_space. a < x \<bullet> i}) ` (UNIV \<times> Basis))"
   702   "borel = sigma UNIV ((\<lambda> (a, i). {x\<Colon>'a\<Colon>euclidean_space. a < x \<bullet> i}) ` (UNIV \<times> Basis))"
   701   (is "_ = ?SIGMA")
   703   (is "_ = ?SIGMA")
   702 proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_le])
   704 proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_le])
   703   fix a :: real and i :: 'a assume "(a, i) \<in> (UNIV \<times> Basis)"
   705   fix a :: real and i :: 'a assume "(a, i) \<in> (UNIV \<times> Basis)"
   704   then have i: "i \<in> Basis" by auto
   706   then have i: "i \<in> Basis" by auto
   705   have *: "{x::'a. x\<bullet>i \<le> a} = space ?SIGMA - {x::'a. a < x\<bullet>i}" by auto
   707   have *: "{x::'a. x\<bullet>i \<le> a} = space ?SIGMA - {x::'a. a < x\<bullet>i}" by auto
   706   show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA" unfolding *
   708   show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA" unfolding *
   707     by (safe intro!: sets.compl_sets) (auto intro: i)
   709     by (intro sets.compl_sets) (auto intro: i)
   708 qed auto
   710 qed auto
   709 
   711 
   710 lemma borel_eq_atMost:
   712 lemma borel_eq_atMost:
   711   "borel = sigma UNIV (range (\<lambda>a. {..a\<Colon>'a\<Colon>ordered_euclidean_space}))"
   713   "borel = sigma UNIV (range (\<lambda>a. {..a\<Colon>'a\<Colon>ordered_euclidean_space}))"
   712   (is "_ = ?SIGMA")
   714   (is "_ = ?SIGMA")
   721       by (subst (asm) Max_le_iff) auto
   723       by (subst (asm) Max_le_iff) auto
   722     then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> x \<bullet> ia \<le> real k"
   724     then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> x \<bullet> ia \<le> real k"
   723       by (auto intro!: exI[of _ k])
   725       by (auto intro!: exI[of _ k])
   724   qed
   726   qed
   725   show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA" unfolding *
   727   show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA" unfolding *
   726     by (safe intro!: sets.countable_UN) auto
   728     by (intro sets.countable_UN) auto
   727 qed auto
   729 qed auto
   728 
   730 
   729 lemma borel_eq_greaterThan:
   731 lemma borel_eq_greaterThan:
   730   "borel = sigma UNIV (range (\<lambda>a\<Colon>'a\<Colon>ordered_euclidean_space. {x. a <e x}))"
   732   "borel = sigma UNIV (range (\<lambda>a\<Colon>'a\<Colon>ordered_euclidean_space. {x. a <e x}))"
   731   (is "_ = ?SIGMA")
   733   (is "_ = ?SIGMA")
   746     then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> -real k < x \<bullet> ia"
   748     then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> -real k < x \<bullet> ia"
   747       by (auto intro!: exI[of _ k])
   749       by (auto intro!: exI[of _ k])
   748   qed
   750   qed
   749   finally show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA"
   751   finally show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA"
   750     apply (simp only:)
   752     apply (simp only:)
   751     apply (safe intro!: sets.countable_UN sets.Diff)
   753     apply (intro sets.countable_UN sets.Diff)
   752     apply (auto intro: sigma_sets_top)
   754     apply (auto intro: sigma_sets_top)
   753     done
   755     done
   754 qed auto
   756 qed auto
   755 
   757 
   756 lemma borel_eq_lessThan:
   758 lemma borel_eq_lessThan:
   772     then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> x \<bullet> ia < real k"
   774     then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> x \<bullet> ia < real k"
   773       by (auto intro!: exI[of _ k])
   775       by (auto intro!: exI[of _ k])
   774   qed
   776   qed
   775   finally show "{x. a \<le> x\<bullet>i} \<in> ?SIGMA"
   777   finally show "{x. a \<le> x\<bullet>i} \<in> ?SIGMA"
   776     apply (simp only:)
   778     apply (simp only:)
   777     apply (safe intro!: sets.countable_UN sets.Diff)
   779     apply (intro sets.countable_UN sets.Diff)
   778     apply (auto intro: sigma_sets_top )
   780     apply (auto intro: sigma_sets_top )
   779     done
   781     done
   780 qed auto
   782 qed auto
   781 
   783 
   782 lemma borel_eq_atLeastAtMost:
   784 lemma borel_eq_atLeastAtMost:
   795       then have "- real k \<le> x\<bullet>i" by simp }
   797       then have "- real k \<le> x\<bullet>i" by simp }
   796     then show "\<exists>n::nat. \<forall>i\<in>Basis. - real n \<le> x \<bullet> i"
   798     then show "\<exists>n::nat. \<forall>i\<in>Basis. - real n \<le> x \<bullet> i"
   797       by (auto intro!: exI[of _ k])
   799       by (auto intro!: exI[of _ k])
   798   qed
   800   qed
   799   show "{..a} \<in> ?SIGMA" unfolding *
   801   show "{..a} \<in> ?SIGMA" unfolding *
   800     by (safe intro!: sets.countable_UN)
   802     by (intro sets.countable_UN)
   801        (auto intro!: sigma_sets_top)
   803        (auto intro!: sigma_sets_top)
   802 qed auto
   804 qed auto
   803 
   805 
   804 lemma borel_sigma_sets_Ioc: "borel = sigma UNIV (range (\<lambda>(a, b). {a <.. b::real}))"
   806 lemma borel_sigma_sets_Ioc: "borel = sigma UNIV (range (\<lambda>(a, b). {a <.. b::real}))"
   805 proof (rule borel_eq_sigmaI5[OF borel_eq_atMost])
   807 proof (rule borel_eq_sigmaI5[OF borel_eq_atMost])
   820   have move_uminus: "\<And>x y::real. -x \<le> y \<longleftrightarrow> -y \<le> x" by auto
   822   have move_uminus: "\<And>x y::real. -x \<le> y \<longleftrightarrow> -y \<le> x" by auto
   821   fix x :: real
   823   fix x :: real
   822   have "{..<x} = (\<Union>i::nat. {-real i ..< x})"
   824   have "{..<x} = (\<Union>i::nat. {-real i ..< x})"
   823     by (auto simp: move_uminus real_arch_simple)
   825     by (auto simp: move_uminus real_arch_simple)
   824   then show "{y. y <e x} \<in> ?SIGMA"
   826   then show "{y. y <e x} \<in> ?SIGMA"
   825     by (auto intro: sigma_sets.intros simp: eucl_lessThan)
   827     by (auto intro: sigma_sets.intros(2-) simp: eucl_lessThan)
   826 qed auto
   828 qed auto
   827 
   829 
   828 lemma borel_eq_closed: "borel = sigma UNIV (Collect closed)"
   830 lemma borel_eq_closed: "borel = sigma UNIV (Collect closed)"
   829   unfolding borel_def
   831   unfolding borel_def
   830 proof (intro sigma_eqI sigma_sets_eqI, safe)
   832 proof (intro sigma_eqI sigma_sets_eqI, safe)
   831   fix x :: "'a set" assume "open x"
   833   fix x :: "'a set" assume "open x"
   832   hence "x = UNIV - (UNIV - x)" by auto
   834   hence "x = UNIV - (UNIV - x)" by auto
   833   also have "\<dots> \<in> sigma_sets UNIV (Collect closed)"
   835   also have "\<dots> \<in> sigma_sets UNIV (Collect closed)"
   834     by (rule sigma_sets.Compl)
   836     by (force intro: sigma_sets.Compl simp: `open x`)
   835        (auto intro!: sigma_sets.Basic simp: `open x`)
       
   836   finally show "x \<in> sigma_sets UNIV (Collect closed)" by simp
   837   finally show "x \<in> sigma_sets UNIV (Collect closed)" by simp
   837 next
   838 next
   838   fix x :: "'a set" assume "closed x"
   839   fix x :: "'a set" assume "closed x"
   839   hence "x = UNIV - (UNIV - x)" by auto
   840   hence "x = UNIV - (UNIV - x)" by auto
   840   also have "\<dots> \<in> sigma_sets UNIV (Collect open)"
   841   also have "\<dots> \<in> sigma_sets UNIV (Collect open)"
   841     by (rule sigma_sets.Compl)
   842     by (force intro: sigma_sets.Compl simp: `closed x`)
   842        (auto intro!: sigma_sets.Basic simp: `closed x`)
       
   843   finally show "x \<in> sigma_sets UNIV (Collect open)" by simp
   843   finally show "x \<in> sigma_sets UNIV (Collect open)" by simp
   844 qed simp_all
   844 qed simp_all
   845 
   845 
   846 lemma borel_measurable_halfspacesI:
   846 lemma borel_measurable_halfspacesI:
   847   fixes f :: "'a \<Rightarrow> 'c\<Colon>euclidean_space"
   847   fixes f :: "'a \<Rightarrow> 'c\<Colon>euclidean_space"
  1149 
  1149 
  1150 lemma borel_measurable_real_of_ereal[measurable (raw)]:
  1150 lemma borel_measurable_real_of_ereal[measurable (raw)]:
  1151   fixes f :: "'a \<Rightarrow> ereal" 
  1151   fixes f :: "'a \<Rightarrow> ereal" 
  1152   assumes f: "f \<in> borel_measurable M"
  1152   assumes f: "f \<in> borel_measurable M"
  1153   shows "(\<lambda>x. real (f x)) \<in> borel_measurable M"
  1153   shows "(\<lambda>x. real (f x)) \<in> borel_measurable M"
  1154 proof -
  1154   apply (rule measurable_compose[OF f])
  1155   have "(\<lambda>x. if f x \<in> UNIV - { \<infinity>, - \<infinity> } then real (f x) else 0) \<in> borel_measurable M"
  1155   apply (rule borel_measurable_continuous_countable_exceptions[of "{\<infinity>, -\<infinity> }"])
  1156     using continuous_on_real
  1156   apply (auto intro: continuous_on_real simp: Compl_eq_Diff_UNIV)
  1157     by (rule borel_measurable_continuous_on_open[OF _ _ f]) auto
  1157   done
  1158   also have "(\<lambda>x. if f x \<in> UNIV - { \<infinity>, - \<infinity> } then real (f x) else 0) = (\<lambda>x. real (f x))"
       
  1159     by auto
       
  1160   finally show ?thesis .
       
  1161 qed
       
  1162 
  1158 
  1163 lemma borel_measurable_ereal_cases:
  1159 lemma borel_measurable_ereal_cases:
  1164   fixes f :: "'a \<Rightarrow> ereal" 
  1160   fixes f :: "'a \<Rightarrow> ereal" 
  1165   assumes f: "f \<in> borel_measurable M"
  1161   assumes f: "f \<in> borel_measurable M"
  1166   assumes H: "(\<lambda>x. H (ereal (real (f x)))) \<in> borel_measurable M"
  1162   assumes H: "(\<lambda>x. H (ereal (real (f x)))) \<in> borel_measurable M"
  1227   have "?f \<in> borel_measurable M" using * ** by (intro measurable_If) auto
  1223   have "?f \<in> borel_measurable M" using * ** by (intro measurable_If) auto
  1228   also have "?f = f" by (auto simp: fun_eq_iff ereal_real)
  1224   also have "?f = f" by (auto simp: fun_eq_iff ereal_real)
  1229   finally show "f \<in> borel_measurable M" .
  1225   finally show "f \<in> borel_measurable M" .
  1230 qed simp_all
  1226 qed simp_all
  1231 
  1227 
  1232 lemma borel_measurable_eq_atMost_ereal:
  1228 lemma borel_measurable_ereal_iff_Iio:
  1233   fixes f :: "'a \<Rightarrow> ereal"
  1229   "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..< a} \<inter> space M \<in> sets M)"
  1234   shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..a} \<inter> space M \<in> sets M)"
  1230   by (auto simp: borel_Iio measurable_iff_measure_of)
  1235 proof (intro iffI allI)
  1231 
  1236   assume pos[rule_format]: "\<forall>a. f -` {..a} \<inter> space M \<in> sets M"
  1232 lemma borel_measurable_ereal_iff_Ioi:
  1237   show "f \<in> borel_measurable M"
  1233   "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a <..} \<inter> space M \<in> sets M)"
  1238     unfolding borel_measurable_ereal_iff_real borel_measurable_iff_le
  1234   by (auto simp: borel_Ioi measurable_iff_measure_of)
  1239   proof (intro conjI allI)
  1235 
  1240     fix a :: real
  1236 lemma vimage_sets_compl_iff:
  1241     { fix x :: ereal assume *: "\<forall>i::nat. real i < x"
  1237   "f -` A \<inter> space M \<in> sets M \<longleftrightarrow> f -` (- A) \<inter> space M \<in> sets M"
  1242       have "x = \<infinity>"
  1238 proof -
  1243       proof (rule ereal_top)
  1239   { fix A assume "f -` A \<inter> space M \<in> sets M"
  1244         fix B from reals_Archimedean2[of B] guess n ..
  1240     moreover have "f -` (- A) \<inter> space M = space M - f -` A \<inter> space M" by auto
  1245         then have "ereal B < real n" by auto
  1241     ultimately have "f -` (- A) \<inter> space M \<in> sets M" by auto }
  1246         with * show "B \<le> x" by (metis less_trans less_imp_le)
  1242   from this[of A] this[of "-A"] show ?thesis
  1247       qed }
  1243     by (metis double_complement)
  1248     then have "f -` {\<infinity>} \<inter> space M = space M - (\<Union>i::nat. f -` {.. real i} \<inter> space M)"
  1244 qed
  1249       by (auto simp: not_le)
  1245 
  1250     then show "f -` {\<infinity>} \<inter> space M \<in> sets M" using pos
  1246 lemma borel_measurable_iff_Iic_ereal:
  1251       by (auto simp del: UN_simps)
  1247   "(f::'a\<Rightarrow>ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..a} \<inter> space M \<in> sets M)"
  1252     moreover
  1248   unfolding borel_measurable_ereal_iff_Ioi vimage_sets_compl_iff[where A="{a <..}" for a] by simp
  1253     have "{-\<infinity>::ereal} = {..-\<infinity>}" by auto
  1249 
  1254     then show "f -` {-\<infinity>} \<inter> space M \<in> sets M" using pos by auto
  1250 lemma borel_measurable_iff_Ici_ereal:
  1255     moreover have "{x\<in>space M. f x \<le> ereal a} \<in> sets M"
       
  1256       using pos[of "ereal a"] by (simp add: vimage_def Int_def conj_commute)
       
  1257     moreover have "{w \<in> space M. real (f w) \<le> a} =
       
  1258       (if a < 0 then {w \<in> space M. f w \<le> ereal a} - f -` {-\<infinity>} \<inter> space M
       
  1259       else {w \<in> space M. f w \<le> ereal a} \<union> (f -` {\<infinity>} \<inter> space M) \<union> (f -` {-\<infinity>} \<inter> space M))" (is "?l = ?r")
       
  1260       proof (intro set_eqI) fix x show "x \<in> ?l \<longleftrightarrow> x \<in> ?r" by (cases "f x") auto qed
       
  1261     ultimately show "{w \<in> space M. real (f w) \<le> a} \<in> sets M" by auto
       
  1262   qed
       
  1263 qed (simp add: measurable_sets)
       
  1264 
       
  1265 lemma borel_measurable_eq_atLeast_ereal:
       
  1266   "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a..} \<inter> space M \<in> sets M)"
  1251   "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a..} \<inter> space M \<in> sets M)"
  1267 proof
  1252   unfolding borel_measurable_ereal_iff_Iio vimage_sets_compl_iff[where A="{..< a}" for a] by simp
  1268   assume pos: "\<forall>a. f -` {a..} \<inter> space M \<in> sets M"
       
  1269   moreover have "\<And>a. (\<lambda>x. - f x) -` {..a} = f -` {-a ..}"
       
  1270     by (auto simp: ereal_uminus_le_reorder)
       
  1271   ultimately have "(\<lambda>x. - f x) \<in> borel_measurable M"
       
  1272     unfolding borel_measurable_eq_atMost_ereal by auto
       
  1273   then show "f \<in> borel_measurable M" by simp
       
  1274 qed (simp add: measurable_sets)
       
  1275 
       
  1276 lemma greater_eq_le_measurable:
       
  1277   fixes f :: "'a \<Rightarrow> 'c::linorder"
       
  1278   shows "f -` {..< a} \<inter> space M \<in> sets M \<longleftrightarrow> f -` {a ..} \<inter> space M \<in> sets M"
       
  1279 proof
       
  1280   assume "f -` {a ..} \<inter> space M \<in> sets M"
       
  1281   moreover have "f -` {..< a} \<inter> space M = space M - f -` {a ..} \<inter> space M" by auto
       
  1282   ultimately show "f -` {..< a} \<inter> space M \<in> sets M" by auto
       
  1283 next
       
  1284   assume "f -` {..< a} \<inter> space M \<in> sets M"
       
  1285   moreover have "f -` {a ..} \<inter> space M = space M - f -` {..< a} \<inter> space M" by auto
       
  1286   ultimately show "f -` {a ..} \<inter> space M \<in> sets M" by auto
       
  1287 qed
       
  1288 
       
  1289 lemma borel_measurable_ereal_iff_less:
       
  1290   "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..< a} \<inter> space M \<in> sets M)"
       
  1291   unfolding borel_measurable_eq_atLeast_ereal greater_eq_le_measurable ..
       
  1292 
       
  1293 lemma less_eq_ge_measurable:
       
  1294   fixes f :: "'a \<Rightarrow> 'c::linorder"
       
  1295   shows "f -` {a <..} \<inter> space M \<in> sets M \<longleftrightarrow> f -` {..a} \<inter> space M \<in> sets M"
       
  1296 proof
       
  1297   assume "f -` {a <..} \<inter> space M \<in> sets M"
       
  1298   moreover have "f -` {..a} \<inter> space M = space M - f -` {a <..} \<inter> space M" by auto
       
  1299   ultimately show "f -` {..a} \<inter> space M \<in> sets M" by auto
       
  1300 next
       
  1301   assume "f -` {..a} \<inter> space M \<in> sets M"
       
  1302   moreover have "f -` {a <..} \<inter> space M = space M - f -` {..a} \<inter> space M" by auto
       
  1303   ultimately show "f -` {a <..} \<inter> space M \<in> sets M" by auto
       
  1304 qed
       
  1305 
       
  1306 lemma borel_measurable_ereal_iff_ge:
       
  1307   "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a <..} \<inter> space M \<in> sets M)"
       
  1308   unfolding borel_measurable_eq_atMost_ereal less_eq_ge_measurable ..
       
  1309 
  1253 
  1310 lemma borel_measurable_ereal2:
  1254 lemma borel_measurable_ereal2:
  1311   fixes f g :: "'a \<Rightarrow> ereal" 
  1255   fixes f g :: "'a \<Rightarrow> ereal" 
  1312   assumes f: "f \<in> borel_measurable M"
  1256   assumes f: "f \<in> borel_measurable M"
  1313   assumes g: "g \<in> borel_measurable M"
  1257   assumes g: "g \<in> borel_measurable M"
  1350 
  1294 
  1351 lemma borel_measurable_ereal_setsum[measurable (raw)]:
  1295 lemma borel_measurable_ereal_setsum[measurable (raw)]:
  1352   fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
  1296   fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
  1353   assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
  1297   assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
  1354   shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
  1298   shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
  1355 proof cases
  1299   using assms by (induction S rule: infinite_finite_induct) auto
  1356   assume "finite S"
       
  1357   thus ?thesis using assms
       
  1358     by induct auto
       
  1359 qed simp
       
  1360 
  1300 
  1361 lemma borel_measurable_ereal_setprod[measurable (raw)]:
  1301 lemma borel_measurable_ereal_setprod[measurable (raw)]:
  1362   fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
  1302   fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
  1363   assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
  1303   assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
  1364   shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
  1304   shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
  1365 proof cases
  1305   using assms by (induction S rule: infinite_finite_induct) auto
  1366   assume "finite S"
       
  1367   thus ?thesis using assms by induct auto
       
  1368 qed simp
       
  1369 
  1306 
  1370 lemma [measurable (raw)]:
  1307 lemma [measurable (raw)]:
  1371   fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
  1308   fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
  1372   assumes "\<And>i. f i \<in> borel_measurable M"
  1309   assumes "\<And>i. f i \<in> borel_measurable M"
  1373   shows borel_measurable_liminf: "(\<lambda>x. liminf (\<lambda>i. f i x)) \<in> borel_measurable M"
  1310   shows borel_measurable_liminf: "(\<lambda>x. liminf (\<lambda>i. f i x)) \<in> borel_measurable M"