src/HOL/Probability/Borel_Space.thy
changeset 62372 4fe872ff91bf
parent 62083 7582b39f51ed
child 62390 842917225d56
equal deleted inserted replaced
62371:7c288c0c7300 62372:4fe872ff91bf
    17 lemma open_prod_generated: "open = generate_topology {A \<times> B | A B. open A \<and> open B}"
    17 lemma open_prod_generated: "open = generate_topology {A \<times> B | A B. open A \<and> open B}"
    18 proof -
    18 proof -
    19   have "{A \<times> B :: ('a \<times> 'b) set | A B. open A \<and> open B} = ((\<lambda>(a, b). a \<times> b) ` ({A. open A} \<times> {A. open A}))"
    19   have "{A \<times> B :: ('a \<times> 'b) set | A B. open A \<and> open B} = ((\<lambda>(a, b). a \<times> b) ` ({A. open A} \<times> {A. open A}))"
    20     by auto
    20     by auto
    21   then show ?thesis
    21   then show ?thesis
    22     by (auto intro: topological_basis_prod topological_basis_trivial topological_basis_imp_subbasis)  
    22     by (auto intro: topological_basis_prod topological_basis_trivial topological_basis_imp_subbasis)
    23 qed
    23 qed
    24 
    24 
    25 definition "mono_on f A \<equiv> \<forall>r s. r \<in> A \<and> s \<in> A \<and> r \<le> s \<longrightarrow> f r \<le> f s"
    25 definition "mono_on f A \<equiv> \<forall>r s. r \<in> A \<and> s \<in> A \<and> r \<le> s \<longrightarrow> f r \<le> f s"
    26 
    26 
    27 lemma mono_onI:
    27 lemma mono_onI:
    74   shows "inj_on f A"
    74   shows "inj_on f A"
    75 proof (rule inj_onI)
    75 proof (rule inj_onI)
    76   fix x y assume "x \<in> A" "y \<in> A" "f x = f y"
    76   fix x y assume "x \<in> A" "y \<in> A" "f x = f y"
    77   thus "x = y"
    77   thus "x = y"
    78     by (cases x y rule: linorder_cases)
    78     by (cases x y rule: linorder_cases)
    79        (auto dest: strict_mono_onD[OF assms, of x y] strict_mono_onD[OF assms, of y x]) 
    79        (auto dest: strict_mono_onD[OF assms, of x y] strict_mono_onD[OF assms, of y x])
    80 qed
    80 qed
    81 
    81 
    82 lemma strict_mono_on_leD:
    82 lemma strict_mono_on_leD:
    83   assumes "strict_mono_on (f :: (_ :: linorder) \<Rightarrow> _ :: preorder) A" "x \<in> A" "y \<in> A" "x \<le> y"
    83   assumes "strict_mono_on (f :: (_ :: linorder) \<Rightarrow> _ :: preorder) A" "x \<in> A" "y \<in> A" "x \<le> y"
    84   shows "f x \<le> f y"
    84   shows "f x \<le> f y"
   119       by (cases h rule: linorder_cases[of _ 0])
   119       by (cases h rule: linorder_cases[of _ 0])
   120          (simp_all add: divide_nonpos_neg divide_nonneg_pos mono_onD field_simps)
   120          (simp_all add: divide_nonpos_neg divide_nonneg_pos mono_onD field_simps)
   121   qed
   121   qed
   122 qed simp
   122 qed simp
   123 
   123 
   124 lemma strict_mono_on_imp_mono_on: 
   124 lemma strict_mono_on_imp_mono_on:
   125   "strict_mono_on (f :: (_ :: linorder) \<Rightarrow> _ :: preorder) A \<Longrightarrow> mono_on f A"
   125   "strict_mono_on (f :: (_ :: linorder) \<Rightarrow> _ :: preorder) A \<Longrightarrow> mono_on f A"
   126   by (rule mono_onI, rule strict_mono_on_leD)
   126   by (rule mono_onI, rule strict_mono_on_leD)
   127 
   127 
   128 lemma mono_on_ctble_discont:
   128 lemma mono_on_ctble_discont:
   129   fixes f :: "real \<Rightarrow> real"
   129   fixes f :: "real \<Rightarrow> real"
   151         fix x assume "x \<in> A" "x < a"
   151         fix x assume "x \<in> A" "x < a"
   152         with q2 *[of "a - x"] show "f x < real_of_rat q2"
   152         with q2 *[of "a - x"] show "f x < real_of_rat q2"
   153           apply (auto simp add: dist_real_def not_less)
   153           apply (auto simp add: dist_real_def not_less)
   154           apply (subgoal_tac "f x \<le> f xa")
   154           apply (subgoal_tac "f x \<le> f xa")
   155           by (auto intro: mono)
   155           by (auto intro: mono)
   156       qed 
   156       qed
   157       thus ?thesis by auto
   157       thus ?thesis by auto
   158     next
   158     next
   159       fix u assume "u > f a"
   159       fix u assume "u > f a"
   160       then obtain q2 where q2: "f a < of_rat q2" "of_rat q2 < u"
   160       then obtain q2 where q2: "f a < of_rat q2" "of_rat q2 < u"
   161         using of_rat_dense by blast
   161         using of_rat_dense by blast
   165         fix x assume "x \<in> A" "x > a"
   165         fix x assume "x \<in> A" "x > a"
   166         with q2 *[of "x - a"] show "f x > real_of_rat q2"
   166         with q2 *[of "x - a"] show "f x > real_of_rat q2"
   167           apply (auto simp add: dist_real_def)
   167           apply (auto simp add: dist_real_def)
   168           apply (subgoal_tac "f x \<ge> f xa")
   168           apply (subgoal_tac "f x \<ge> f xa")
   169           by (auto intro: mono)
   169           by (auto intro: mono)
   170       qed 
   170       qed
   171       thus ?thesis by auto
   171       thus ?thesis by auto
   172     qed
   172     qed
   173   qed
   173   qed
   174   hence "\<exists>g :: real \<Rightarrow> nat \<times> rat . \<forall>a \<in> {a\<in>A. \<not> continuous (at a within A) f}. 
   174   hence "\<exists>g :: real \<Rightarrow> nat \<times> rat . \<forall>a \<in> {a\<in>A. \<not> continuous (at a within A) f}.
   175       (fst (g a) = 0 \<and> of_rat (snd (g a)) < f a \<and> (\<forall>x \<in> A. x < a \<longrightarrow> f x < of_rat (snd (g a)))) |
   175       (fst (g a) = 0 \<and> of_rat (snd (g a)) < f a \<and> (\<forall>x \<in> A. x < a \<longrightarrow> f x < of_rat (snd (g a)))) |
   176       (fst (g a) = 1 \<and> of_rat (snd (g a)) > f a \<and> (\<forall>x \<in> A. x > a \<longrightarrow> f x > of_rat (snd (g a))))"
   176       (fst (g a) = 1 \<and> of_rat (snd (g a)) > f a \<and> (\<forall>x \<in> A. x > a \<longrightarrow> f x > of_rat (snd (g a))))"
   177     by (rule bchoice)
   177     by (rule bchoice)
   178   then guess g ..
   178   then guess g ..
   179   hence g: "\<And>a x. a \<in> A \<Longrightarrow> \<not> continuous (at a within A) f \<Longrightarrow> x \<in> A \<Longrightarrow>
   179   hence g: "\<And>a x. a \<in> A \<Longrightarrow> \<not> continuous (at a within A) f \<Longrightarrow> x \<in> A \<Longrightarrow>
   184   proof (auto simp add: inj_on_def)
   184   proof (auto simp add: inj_on_def)
   185     fix w z
   185     fix w z
   186     assume 1: "w \<in> A" and 2: "\<not> continuous (at w within A) f" and
   186     assume 1: "w \<in> A" and 2: "\<not> continuous (at w within A) f" and
   187            3: "z \<in> A" and 4: "\<not> continuous (at z within A) f" and
   187            3: "z \<in> A" and 4: "\<not> continuous (at z within A) f" and
   188            5: "g w = g z"
   188            5: "g w = g z"
   189     from g [OF 1 2 3] g [OF 3 4 1] 5 
   189     from g [OF 1 2 3] g [OF 3 4 1] 5
   190     show "w = z" by auto
   190     show "w = z" by auto
   191   qed
   191   qed
   192   thus ?thesis 
   192   thus ?thesis
   193     by (rule countableI') 
   193     by (rule countableI')
   194 qed
   194 qed
   195 
   195 
   196 lemma mono_on_ctble_discont_open:
   196 lemma mono_on_ctble_discont_open:
   197   fixes f :: "real \<Rightarrow> real"
   197   fixes f :: "real \<Rightarrow> real"
   198   fixes A :: "real set"
   198   fixes A :: "real set"
   224 lemma closure_contains_Sup:
   224 lemma closure_contains_Sup:
   225   fixes S :: "real set"
   225   fixes S :: "real set"
   226   assumes "S \<noteq> {}" "bdd_above S"
   226   assumes "S \<noteq> {}" "bdd_above S"
   227   shows "Sup S \<in> closure S"
   227   shows "Sup S \<in> closure S"
   228 proof-
   228 proof-
   229   have "Inf (uminus ` S) \<in> closure (uminus ` S)" 
   229   have "Inf (uminus ` S) \<in> closure (uminus ` S)"
   230       using assms by (intro closure_contains_Inf) auto
   230       using assms by (intro closure_contains_Inf) auto
   231   also have "Inf (uminus ` S) = -Sup S" by (simp add: Inf_real_def)
   231   also have "Inf (uminus ` S) = -Sup S" by (simp add: Inf_real_def)
   232   also have "closure (uminus ` S) = uminus ` closure S"
   232   also have "closure (uminus ` S) = uminus ` closure S"
   233       by (rule sym, intro closure_injective_linear_image) (auto intro: linearI)
   233       by (rule sym, intro closure_injective_linear_image) (auto intro: linearI)
   234   finally show ?thesis by auto
   234   finally show ?thesis by auto
   245   assumes ab: "a \<le> b"
   245   assumes ab: "a \<le> b"
   246   shows "g a \<le> g b"
   246   shows "g a \<le> g b"
   247 proof (cases "a < b")
   247 proof (cases "a < b")
   248   assume "a < b"
   248   assume "a < b"
   249   from deriv have "\<forall>x. x \<ge> a \<and> x \<le> b \<longrightarrow> (g has_real_derivative g' x) (at x)" by simp
   249   from deriv have "\<forall>x. x \<ge> a \<and> x \<le> b \<longrightarrow> (g has_real_derivative g' x) (at x)" by simp
   250   from MVT2[OF \<open>a < b\<close> this] and deriv 
   250   from MVT2[OF \<open>a < b\<close> this] and deriv
   251     obtain \<xi> where \<xi>_ab: "\<xi> > a" "\<xi> < b" and g_ab: "g b - g a = (b - a) * g' \<xi>" by blast
   251     obtain \<xi> where \<xi>_ab: "\<xi> > a" "\<xi> < b" and g_ab: "g b - g a = (b - a) * g' \<xi>" by blast
   252   from \<xi>_ab ab nonneg have "(b - a) * g' \<xi> \<ge> 0" by simp
   252   from \<xi>_ab ab nonneg have "(b - a) * g' \<xi> \<ge> 0" by simp
   253   with g_ab show ?thesis by simp
   253   with g_ab show ?thesis by simp
   254 qed (insert ab, simp)
   254 qed (insert ab, simp)
   255 
   255 
   257   assumes "continuous_on {a::real..b} g" and mono: "\<And>x y. a \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> y \<le> b \<Longrightarrow> g x \<le> g y"
   257   assumes "continuous_on {a::real..b} g" and mono: "\<And>x y. a \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> y \<le> b \<Longrightarrow> g x \<le> g y"
   258   assumes "a \<le> b" "(c::real) \<le> d" "{c..d} \<subseteq> {g a..g b}"
   258   assumes "a \<le> b" "(c::real) \<le> d" "{c..d} \<subseteq> {g a..g b}"
   259   obtains c' d' where "{a..b} \<inter> g -` {c..d} = {c'..d'}" "c' \<le> d'" "g c' = c" "g d' = d"
   259   obtains c' d' where "{a..b} \<inter> g -` {c..d} = {c'..d'}" "c' \<le> d'" "g c' = c" "g d' = d"
   260 proof-
   260 proof-
   261     let ?A = "{a..b} \<inter> g -` {c..d}"
   261     let ?A = "{a..b} \<inter> g -` {c..d}"
   262     from IVT'[of g a c b, OF _ _ \<open>a \<le> b\<close> assms(1)] assms(4,5) 
   262     from IVT'[of g a c b, OF _ _ \<open>a \<le> b\<close> assms(1)] assms(4,5)
   263          obtain c'' where c'': "c'' \<in> ?A" "g c'' = c" by auto
   263          obtain c'' where c'': "c'' \<in> ?A" "g c'' = c" by auto
   264     from IVT'[of g a d b, OF _ _ \<open>a \<le> b\<close> assms(1)] assms(4,5) 
   264     from IVT'[of g a d b, OF _ _ \<open>a \<le> b\<close> assms(1)] assms(4,5)
   265          obtain d'' where d'': "d'' \<in> ?A" "g d'' = d" by auto
   265          obtain d'' where d'': "d'' \<in> ?A" "g d'' = d" by auto
   266     hence [simp]: "?A \<noteq> {}" by blast
   266     hence [simp]: "?A \<noteq> {}" by blast
   267 
   267 
   268     def c' \<equiv> "Inf ?A" and d' \<equiv> "Sup ?A"
   268     def c' \<equiv> "Inf ?A" and d' \<equiv> "Sup ?A"
   269     have "?A \<subseteq> {c'..d'}" unfolding c'_def d'_def
   269     have "?A \<subseteq> {c'..d'}" unfolding c'_def d'_def
   270         by (intro subsetI) (auto intro: cInf_lower cSup_upper)
   270         by (intro subsetI) (auto intro: cInf_lower cSup_upper)
   271     moreover from assms have "closed ?A" 
   271     moreover from assms have "closed ?A"
   272         using continuous_on_closed_vimage[of "{a..b}" g] by (subst Int_commute) simp
   272         using continuous_on_closed_vimage[of "{a..b}" g] by (subst Int_commute) simp
   273     hence c'd'_in_set: "c' \<in> ?A" "d' \<in> ?A" unfolding c'_def d'_def
   273     hence c'd'_in_set: "c' \<in> ?A" "d' \<in> ?A" unfolding c'_def d'_def
   274         by ((intro closed_contains_Inf closed_contains_Sup, simp_all)[])+
   274         by ((intro closed_contains_Inf closed_contains_Sup, simp_all)[])+
   275     hence "{c'..d'} \<subseteq> ?A" using assms 
   275     hence "{c'..d'} \<subseteq> ?A" using assms
   276         by (intro subsetI)
   276         by (intro subsetI)
   277            (auto intro!: order_trans[of c "g c'" "g x" for x] order_trans[of "g x" "g d'" d for x] 
   277            (auto intro!: order_trans[of c "g c'" "g x" for x] order_trans[of "g x" "g d'" d for x]
   278                  intro!: mono)
   278                  intro!: mono)
   279     moreover have "c' \<le> d'" using c'd'_in_set(2) unfolding c'_def by (intro cInf_lower) auto
   279     moreover have "c' \<le> d'" using c'd'_in_set(2) unfolding c'_def by (intro cInf_lower) auto
   280     moreover have "g c' \<le> c" "g d' \<ge> d"
   280     moreover have "g c' \<le> c" "g d' \<ge> d"
   281       apply (insert c'' d'' c'd'_in_set)
   281       apply (insert c'' d'' c'd'_in_set)
   282       apply (subst c''(2)[symmetric])
   282       apply (subst c''(2)[symmetric])
   288     ultimately show ?thesis using that by blast
   288     ultimately show ?thesis using that by blast
   289 qed
   289 qed
   290 
   290 
   291 subsection \<open>Generic Borel spaces\<close>
   291 subsection \<open>Generic Borel spaces\<close>
   292 
   292 
   293 definition borel :: "'a::topological_space measure" where
   293 definition (in topological_space) borel :: "'a measure" where
   294   "borel = sigma UNIV {S. open S}"
   294   "borel = sigma UNIV {S. open S}"
   295 
   295 
   296 abbreviation "borel_measurable M \<equiv> measurable M borel"
   296 abbreviation "borel_measurable M \<equiv> measurable M borel"
   297 
   297 
   298 lemma in_borel_measurable:
   298 lemma in_borel_measurable:
   796     and borel_measurable_eq[measurable]: "{w \<in> space M. f w = g w} \<in> sets M"
   796     and borel_measurable_eq[measurable]: "{w \<in> space M. f w = g w} \<in> sets M"
   797     and borel_measurable_neq: "{w \<in> space M. f w \<noteq> g w} \<in> sets M"
   797     and borel_measurable_neq: "{w \<in> space M. f w \<noteq> g w} \<in> sets M"
   798   unfolding eq_iff not_less[symmetric]
   798   unfolding eq_iff not_less[symmetric]
   799   by measurable
   799   by measurable
   800 
   800 
   801 lemma 
   801 lemma
   802   fixes i :: "'a::{second_countable_topology, real_inner}"
   802   fixes i :: "'a::{second_countable_topology, real_inner}"
   803   shows hafspace_less_borel: "{x. a < x \<bullet> i} \<in> sets borel"
   803   shows hafspace_less_borel: "{x. a < x \<bullet> i} \<in> sets borel"
   804     and hafspace_greater_borel: "{x. x \<bullet> i < a} \<in> sets borel"
   804     and hafspace_greater_borel: "{x. x \<bullet> i < a} \<in> sets borel"
   805     and hafspace_less_eq_borel: "{x. a \<le> x \<bullet> i} \<in> sets borel"
   805     and hafspace_less_eq_borel: "{x. a \<le> x \<bullet> i} \<in> sets borel"
   806     and hafspace_greater_eq_borel: "{x. x \<bullet> i \<le> a} \<in> sets borel"
   806     and hafspace_greater_eq_borel: "{x. x \<bullet> i \<le> a} \<in> sets borel"
   879     done
   879     done
   880 qed (auto simp: box_def)
   880 qed (auto simp: box_def)
   881 
   881 
   882 lemma halfspace_gt_in_halfspace:
   882 lemma halfspace_gt_in_halfspace:
   883   assumes i: "i \<in> A"
   883   assumes i: "i \<in> A"
   884   shows "{x::'a. a < x \<bullet> i} \<in> 
   884   shows "{x::'a. a < x \<bullet> i} \<in>
   885     sigma_sets UNIV ((\<lambda> (a, i). {x::'a::euclidean_space. x \<bullet> i < a}) ` (UNIV \<times> A))"
   885     sigma_sets UNIV ((\<lambda> (a, i). {x::'a::euclidean_space. x \<bullet> i < a}) ` (UNIV \<times> A))"
   886   (is "?set \<in> ?SIGMA")
   886   (is "?set \<in> ?SIGMA")
   887 proof -
   887 proof -
   888   interpret sigma_algebra UNIV ?SIGMA
   888   interpret sigma_algebra UNIV ?SIGMA
   889     by (intro sigma_algebra_sigma_sets) simp_all
   889     by (intro sigma_algebra_sigma_sets) simp_all
  1061 proof (rule borel_eq_sigmaI5[OF borel_eq_atMost])
  1061 proof (rule borel_eq_sigmaI5[OF borel_eq_atMost])
  1062   fix i :: real
  1062   fix i :: real
  1063   have "{..i} = (\<Union>j::nat. {-j <.. i})"
  1063   have "{..i} = (\<Union>j::nat. {-j <.. i})"
  1064     by (auto simp: minus_less_iff reals_Archimedean2)
  1064     by (auto simp: minus_less_iff reals_Archimedean2)
  1065   also have "\<dots> \<in> sets (sigma UNIV (range (\<lambda>(i, j). {i<..j})))"
  1065   also have "\<dots> \<in> sets (sigma UNIV (range (\<lambda>(i, j). {i<..j})))"
  1066     by (intro sets.countable_nat_UN) auto 
  1066     by (intro sets.countable_nat_UN) auto
  1067   finally show "{..i} \<in> sets (sigma UNIV (range (\<lambda>(i, j). {i<..j})))" .
  1067   finally show "{..i} \<in> sets (sigma UNIV (range (\<lambda>(i, j). {i<..j})))" .
  1068 qed simp
  1068 qed simp
  1069 
  1069 
  1070 lemma eucl_lessThan: "{x::real. x <e a} = lessThan a"
  1070 lemma eucl_lessThan: "{x::real. x <e a} = lessThan a"
  1071   by (simp add: eucl_less_def lessThan_def)
  1071   by (simp add: eucl_less_def lessThan_def)
  1098 qed simp_all
  1098 qed simp_all
  1099 
  1099 
  1100 lemma borel_measurable_halfspacesI:
  1100 lemma borel_measurable_halfspacesI:
  1101   fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
  1101   fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
  1102   assumes F: "borel = sigma UNIV (F ` (UNIV \<times> Basis))"
  1102   assumes F: "borel = sigma UNIV (F ` (UNIV \<times> Basis))"
  1103   and S_eq: "\<And>a i. S a i = f -` F (a,i) \<inter> space M" 
  1103   and S_eq: "\<And>a i. S a i = f -` F (a,i) \<inter> space M"
  1104   shows "f \<in> borel_measurable M = (\<forall>i\<in>Basis. \<forall>a::real. S a i \<in> sets M)"
  1104   shows "f \<in> borel_measurable M = (\<forall>i\<in>Basis. \<forall>a::real. S a i \<in> sets M)"
  1105 proof safe
  1105 proof safe
  1106   fix a :: real and i :: 'b assume i: "i \<in> Basis" and f: "f \<in> borel_measurable M"
  1106   fix a :: real and i :: 'b assume i: "i \<in> Basis" and f: "f \<in> borel_measurable M"
  1107   then show "S a i \<in> sets M" unfolding assms
  1107   then show "S a i \<in> sets M" unfolding assms
  1108     by (auto intro!: measurable_sets simp: assms(1))
  1108     by (auto intro!: measurable_sets simp: assms(1))
  1157   then show "f \<in> borel_measurable M"
  1157   then show "f \<in> borel_measurable M"
  1158     by (subst borel_measurable_iff_halfspace_le) auto
  1158     by (subst borel_measurable_iff_halfspace_le) auto
  1159 qed auto
  1159 qed auto
  1160 
  1160 
  1161 lemma borel_set_induct[consumes 1, case_names empty interval compl union]:
  1161 lemma borel_set_induct[consumes 1, case_names empty interval compl union]:
  1162   assumes "A \<in> sets borel" 
  1162   assumes "A \<in> sets borel"
  1163   assumes empty: "P {}" and int: "\<And>a b. a \<le> b \<Longrightarrow> P {a..b}" and compl: "\<And>A. A \<in> sets borel \<Longrightarrow> P A \<Longrightarrow> P (-A)" and
  1163   assumes empty: "P {}" and int: "\<And>a b. a \<le> b \<Longrightarrow> P {a..b}" and compl: "\<And>A. A \<in> sets borel \<Longrightarrow> P A \<Longrightarrow> P (-A)" and
  1164           un: "\<And>f. disjoint_family f \<Longrightarrow> (\<And>i. f i \<in> sets borel) \<Longrightarrow>  (\<And>i. P (f i)) \<Longrightarrow> P (\<Union>i::nat. f i)"
  1164           un: "\<And>f. disjoint_family f \<Longrightarrow> (\<And>i. f i \<in> sets borel) \<Longrightarrow>  (\<And>i. P (f i)) \<Longrightarrow> P (\<Union>i::nat. f i)"
  1165   shows "P (A::real set)"
  1165   shows "P (A::real set)"
  1166 proof-
  1166 proof-
  1167   let ?G = "range (\<lambda>(a,b). {a..b::real})"
  1167   let ?G = "range (\<lambda>(a,b). {a..b::real})"
  1168   have "Int_stable ?G" "?G \<subseteq> Pow UNIV" "A \<in> sigma_sets UNIV ?G" 
  1168   have "Int_stable ?G" "?G \<subseteq> Pow UNIV" "A \<in> sigma_sets UNIV ?G"
  1169       using assms(1) by (auto simp add: borel_eq_atLeastAtMost Int_stable_def)
  1169       using assms(1) by (auto simp add: borel_eq_atLeastAtMost Int_stable_def)
  1170   thus ?thesis
  1170   thus ?thesis
  1171   proof (induction rule: sigma_sets_induct_disjoint) 
  1171   proof (induction rule: sigma_sets_induct_disjoint)
  1172     case (union f)
  1172     case (union f)
  1173       from union.hyps(2) have "\<And>i. f i \<in> sets borel" by (auto simp: borel_eq_atLeastAtMost)
  1173       from union.hyps(2) have "\<And>i. f i \<in> sets borel" by (auto simp: borel_eq_atLeastAtMost)
  1174       with union show ?case by (auto intro: un)
  1174       with union show ?case by (auto intro: un)
  1175   next
  1175   next
  1176     case (basic A)
  1176     case (basic A)
  1238   fixes g f :: "'a \<Rightarrow> 'b::{second_countable_topology, metric_space}"
  1238   fixes g f :: "'a \<Rightarrow> 'b::{second_countable_topology, metric_space}"
  1239   assumes f: "f \<in> borel_measurable M"
  1239   assumes f: "f \<in> borel_measurable M"
  1240   assumes g: "g \<in> borel_measurable M"
  1240   assumes g: "g \<in> borel_measurable M"
  1241   shows "(\<lambda>x. dist (f x) (g x)) \<in> borel_measurable M"
  1241   shows "(\<lambda>x. dist (f x) (g x)) \<in> borel_measurable M"
  1242   using f g by (rule borel_measurable_continuous_Pair) (intro continuous_intros)
  1242   using f g by (rule borel_measurable_continuous_Pair) (intro continuous_intros)
  1243   
  1243 
  1244 lemma borel_measurable_scaleR[measurable (raw)]:
  1244 lemma borel_measurable_scaleR[measurable (raw)]:
  1245   fixes g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
  1245   fixes g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
  1246   assumes f: "f \<in> borel_measurable M"
  1246   assumes f: "f \<in> borel_measurable M"
  1247   assumes g: "g \<in> borel_measurable M"
  1247   assumes g: "g \<in> borel_measurable M"
  1248   shows "(\<lambda>x. f x *\<^sub>R g x) \<in> borel_measurable M"
  1248   shows "(\<lambda>x. f x *\<^sub>R g x) \<in> borel_measurable M"
  1321   "(\<lambda>x::real^'n. x $ i) \<in> borel_measurable borel"
  1321   "(\<lambda>x::real^'n. x $ i) \<in> borel_measurable borel"
  1322   by (simp add: cart_eq_inner_axis)
  1322   by (simp add: cart_eq_inner_axis)
  1323 
  1323 
  1324 lemma convex_measurable:
  1324 lemma convex_measurable:
  1325   fixes A :: "'a :: euclidean_space set"
  1325   fixes A :: "'a :: euclidean_space set"
  1326   shows "X \<in> borel_measurable M \<Longrightarrow> X ` space M \<subseteq> A \<Longrightarrow> open A \<Longrightarrow> convex_on A q \<Longrightarrow> 
  1326   shows "X \<in> borel_measurable M \<Longrightarrow> X ` space M \<subseteq> A \<Longrightarrow> open A \<Longrightarrow> convex_on A q \<Longrightarrow>
  1327     (\<lambda>x. q (X x)) \<in> borel_measurable M"
  1327     (\<lambda>x. q (X x)) \<in> borel_measurable M"
  1328   by (rule measurable_compose[where f=X and N="restrict_space borel A"])
  1328   by (rule measurable_compose[where f=X and N="restrict_space borel A"])
  1329      (auto intro!: borel_measurable_continuous_on_restrict convex_on_continuous measurable_restrict_space2)
  1329      (auto intro!: borel_measurable_continuous_on_restrict convex_on_continuous measurable_restrict_space2)
  1330 
  1330 
  1331 lemma borel_measurable_ln[measurable (raw)]:
  1331 lemma borel_measurable_ln[measurable (raw)]:
  1404 lemma borel_measurable_ereal[measurable (raw)]:
  1404 lemma borel_measurable_ereal[measurable (raw)]:
  1405   assumes f: "f \<in> borel_measurable M" shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
  1405   assumes f: "f \<in> borel_measurable M" shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
  1406   using continuous_on_ereal f by (rule borel_measurable_continuous_on) (rule continuous_on_id)
  1406   using continuous_on_ereal f by (rule borel_measurable_continuous_on) (rule continuous_on_id)
  1407 
  1407 
  1408 lemma borel_measurable_real_of_ereal[measurable (raw)]:
  1408 lemma borel_measurable_real_of_ereal[measurable (raw)]:
  1409   fixes f :: "'a \<Rightarrow> ereal" 
  1409   fixes f :: "'a \<Rightarrow> ereal"
  1410   assumes f: "f \<in> borel_measurable M"
  1410   assumes f: "f \<in> borel_measurable M"
  1411   shows "(\<lambda>x. real_of_ereal (f x)) \<in> borel_measurable M"
  1411   shows "(\<lambda>x. real_of_ereal (f x)) \<in> borel_measurable M"
  1412   apply (rule measurable_compose[OF f])
  1412   apply (rule measurable_compose[OF f])
  1413   apply (rule borel_measurable_continuous_countable_exceptions[of "{\<infinity>, -\<infinity> }"])
  1413   apply (rule borel_measurable_continuous_countable_exceptions[of "{\<infinity>, -\<infinity> }"])
  1414   apply (auto intro: continuous_on_real simp: Compl_eq_Diff_UNIV)
  1414   apply (auto intro: continuous_on_real simp: Compl_eq_Diff_UNIV)
  1415   done
  1415   done
  1416 
  1416 
  1417 lemma borel_measurable_ereal_cases:
  1417 lemma borel_measurable_ereal_cases:
  1418   fixes f :: "'a \<Rightarrow> ereal" 
  1418   fixes f :: "'a \<Rightarrow> ereal"
  1419   assumes f: "f \<in> borel_measurable M"
  1419   assumes f: "f \<in> borel_measurable M"
  1420   assumes H: "(\<lambda>x. H (ereal (real_of_ereal (f x)))) \<in> borel_measurable M"
  1420   assumes H: "(\<lambda>x. H (ereal (real_of_ereal (f x)))) \<in> borel_measurable M"
  1421   shows "(\<lambda>x. H (f x)) \<in> borel_measurable M"
  1421   shows "(\<lambda>x. H (f x)) \<in> borel_measurable M"
  1422 proof -
  1422 proof -
  1423   let ?F = "\<lambda>x. if f x = \<infinity> then H \<infinity> else if f x = - \<infinity> then H (-\<infinity>) else H (ereal (real_of_ereal (f x)))"
  1423   let ?F = "\<lambda>x. if f x = \<infinity> then H \<infinity> else if f x = - \<infinity> then H (-\<infinity>) else H (ereal (real_of_ereal (f x)))"
  1437 proof
  1437 proof
  1438   assume ?l from borel_measurable_uminus_ereal[OF this] show ?r by simp
  1438   assume ?l from borel_measurable_uminus_ereal[OF this] show ?r by simp
  1439 qed auto
  1439 qed auto
  1440 
  1440 
  1441 lemma set_Collect_ereal2:
  1441 lemma set_Collect_ereal2:
  1442   fixes f g :: "'a \<Rightarrow> ereal" 
  1442   fixes f g :: "'a \<Rightarrow> ereal"
  1443   assumes f: "f \<in> borel_measurable M"
  1443   assumes f: "f \<in> borel_measurable M"
  1444   assumes g: "g \<in> borel_measurable M"
  1444   assumes g: "g \<in> borel_measurable M"
  1445   assumes H: "{x \<in> space M. H (ereal (real_of_ereal (f x))) (ereal (real_of_ereal (g x)))} \<in> sets M"
  1445   assumes H: "{x \<in> space M. H (ereal (real_of_ereal (f x))) (ereal (real_of_ereal (g x)))} \<in> sets M"
  1446     "{x \<in> space borel. H (-\<infinity>) (ereal x)} \<in> sets borel"
  1446     "{x \<in> space borel. H (-\<infinity>) (ereal x)} \<in> sets borel"
  1447     "{x \<in> space borel. H (\<infinity>) (ereal x)} \<in> sets borel"
  1447     "{x \<in> space borel. H (\<infinity>) (ereal x)} \<in> sets borel"
  1508 lemma borel_measurable_iff_Ici_ereal:
  1508 lemma borel_measurable_iff_Ici_ereal:
  1509   "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a..} \<inter> space M \<in> sets M)"
  1509   "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a..} \<inter> space M \<in> sets M)"
  1510   unfolding borel_measurable_ereal_iff_Iio vimage_sets_compl_iff[where A="{..< a}" for a] by simp
  1510   unfolding borel_measurable_ereal_iff_Iio vimage_sets_compl_iff[where A="{..< a}" for a] by simp
  1511 
  1511 
  1512 lemma borel_measurable_ereal2:
  1512 lemma borel_measurable_ereal2:
  1513   fixes f g :: "'a \<Rightarrow> ereal" 
  1513   fixes f g :: "'a \<Rightarrow> ereal"
  1514   assumes f: "f \<in> borel_measurable M"
  1514   assumes f: "f \<in> borel_measurable M"
  1515   assumes g: "g \<in> borel_measurable M"
  1515   assumes g: "g \<in> borel_measurable M"
  1516   assumes H: "(\<lambda>x. H (ereal (real_of_ereal (f x))) (ereal (real_of_ereal (g x)))) \<in> borel_measurable M"
  1516   assumes H: "(\<lambda>x. H (ereal (real_of_ereal (f x))) (ereal (real_of_ereal (g x)))) \<in> borel_measurable M"
  1517     "(\<lambda>x. H (-\<infinity>) (ereal (real_of_ereal (g x)))) \<in> borel_measurable M"
  1517     "(\<lambda>x. H (-\<infinity>) (ereal (real_of_ereal (g x)))) \<in> borel_measurable M"
  1518     "(\<lambda>x. H (\<infinity>) (ereal (real_of_ereal (g x)))) \<in> borel_measurable M"
  1518     "(\<lambda>x. H (\<infinity>) (ereal (real_of_ereal (g x)))) \<in> borel_measurable M"
  1571 
  1571 
  1572 lemma sets_Collect_eventually_sequentially[measurable]:
  1572 lemma sets_Collect_eventually_sequentially[measurable]:
  1573   "(\<And>i. {x\<in>space M. P x i} \<in> sets M) \<Longrightarrow> {x\<in>space M. eventually (P x) sequentially} \<in> sets M"
  1573   "(\<And>i. {x\<in>space M. P x i} \<in> sets M) \<Longrightarrow> {x\<in>space M. eventually (P x) sequentially} \<in> sets M"
  1574   unfolding eventually_sequentially by simp
  1574   unfolding eventually_sequentially by simp
  1575 
  1575 
  1576 lemma sets_Collect_ereal_convergent[measurable]: 
  1576 lemma sets_Collect_ereal_convergent[measurable]:
  1577   fixes f :: "nat \<Rightarrow> 'a => ereal"
  1577   fixes f :: "nat \<Rightarrow> 'a => ereal"
  1578   assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
  1578   assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
  1579   shows "{x\<in>space M. convergent (\<lambda>i. f i x)} \<in> sets M"
  1579   shows "{x\<in>space M. convergent (\<lambda>i. f i x)} \<in> sets M"
  1580   unfolding convergent_ereal by auto
  1580   unfolding convergent_ereal by auto
  1581 
  1581 
  1627   assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
  1627   assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
  1628   assumes lim: "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. f i x) \<longlonglongrightarrow> g x"
  1628   assumes lim: "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. f i x) \<longlonglongrightarrow> g x"
  1629   shows "g \<in> borel_measurable M"
  1629   shows "g \<in> borel_measurable M"
  1630   unfolding borel_eq_closed
  1630   unfolding borel_eq_closed
  1631 proof (safe intro!: measurable_measure_of)
  1631 proof (safe intro!: measurable_measure_of)
  1632   fix A :: "'b set" assume "closed A" 
  1632   fix A :: "'b set" assume "closed A"
  1633 
  1633 
  1634   have [measurable]: "(\<lambda>x. infdist (g x) A) \<in> borel_measurable M"
  1634   have [measurable]: "(\<lambda>x. infdist (g x) A) \<in> borel_measurable M"
  1635   proof (rule borel_measurable_LIMSEQ)
  1635   proof (rule borel_measurable_LIMSEQ)
  1636     show "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. infdist (f i x) A) \<longlonglongrightarrow> infdist (g x) A"
  1636     show "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. infdist (f i x) A) \<longlonglongrightarrow> infdist (g x) A"
  1637       by (intro tendsto_infdist lim)
  1637       by (intro tendsto_infdist lim)
  1651       by measurable
  1651       by measurable
  1652     finally show ?thesis .
  1652     finally show ?thesis .
  1653   qed simp
  1653   qed simp
  1654 qed auto
  1654 qed auto
  1655 
  1655 
  1656 lemma sets_Collect_Cauchy[measurable]: 
  1656 lemma sets_Collect_Cauchy[measurable]:
  1657   fixes f :: "nat \<Rightarrow> 'a => 'b::{metric_space, second_countable_topology}"
  1657   fixes f :: "nat \<Rightarrow> 'a => 'b::{metric_space, second_countable_topology}"
  1658   assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
  1658   assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
  1659   shows "{x\<in>space M. Cauchy (\<lambda>i. f i x)} \<in> sets M"
  1659   shows "{x\<in>space M. Cauchy (\<lambda>i. f i x)} \<in> sets M"
  1660   unfolding metric_Cauchy_iff2 using f by auto
  1660   unfolding metric_Cauchy_iff2 using f by auto
  1661 
  1661 
  1672     fix x
  1672     fix x
  1673     have "convergent (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
  1673     have "convergent (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
  1674       by (cases "Cauchy (\<lambda>i. f i x)")
  1674       by (cases "Cauchy (\<lambda>i. f i x)")
  1675          (auto simp add: convergent_eq_cauchy[symmetric] convergent_def)
  1675          (auto simp add: convergent_eq_cauchy[symmetric] convergent_def)
  1676     then show "(\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0) \<longlonglongrightarrow> u' x"
  1676     then show "(\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0) \<longlonglongrightarrow> u' x"
  1677       unfolding u'_def 
  1677       unfolding u'_def
  1678       by (rule convergent_LIMSEQ_iff[THEN iffD1])
  1678       by (rule convergent_LIMSEQ_iff[THEN iffD1])
  1679   qed measurable
  1679   qed measurable
  1680   then show ?thesis
  1680   then show ?thesis
  1681     unfolding * by measurable
  1681     unfolding * by measurable
  1682 qed
  1682 qed
  1729         by (metis reals_Archimedean)
  1729         by (metis reals_Archimedean)
  1730       assume "\<forall>i. \<exists>j. \<forall>y z. dist x y < ?I j \<and> dist x z < ?I j \<longrightarrow> dist (f y) (f z) \<le> ?I i"
  1730       assume "\<forall>i. \<exists>j. \<forall>y z. dist x y < ?I j \<and> dist x z < ?I j \<longrightarrow> dist (f y) (f z) \<le> ?I i"
  1731       from this[THEN spec, of "Suc n"]
  1731       from this[THEN spec, of "Suc n"]
  1732       obtain j where j: "\<And>y z. dist x y < ?I j \<Longrightarrow> dist x z < ?I j \<Longrightarrow> dist (f y) (f z) \<le> ?I (Suc n)"
  1732       obtain j where j: "\<And>y z. dist x y < ?I j \<Longrightarrow> dist x z < ?I j \<Longrightarrow> dist (f y) (f z) \<le> ?I (Suc n)"
  1733         by auto
  1733         by auto
  1734       
  1734 
  1735       show "\<exists>d>0. \<forall>y. dist y x < d \<longrightarrow> dist (f y) (f x) < e"
  1735       show "\<exists>d>0. \<forall>y. dist y x < d \<longrightarrow> dist (f y) (f x) < e"
  1736       proof (safe intro!: exI[of _ "?I j"])
  1736       proof (safe intro!: exI[of _ "?I j"])
  1737         fix y assume "dist y x < ?I j"
  1737         fix y assume "dist y x < ?I j"
  1738         then have "dist (f y) (f x) \<le> ?I (Suc n)"
  1738         then have "dist (f y) (f x) \<le> ?I (Suc n)"
  1739           by (intro j) (auto simp: dist_commute)
  1739           by (intro j) (auto simp: dist_commute)
  1787   assumes "mono_on f A"
  1787   assumes "mono_on f A"
  1788   shows "f \<in> borel_measurable (restrict_space borel A)"
  1788   shows "f \<in> borel_measurable (restrict_space borel A)"
  1789   apply (rule measurable_restrict_countable[OF mono_on_ctble_discont[OF assms]])
  1789   apply (rule measurable_restrict_countable[OF mono_on_ctble_discont[OF assms]])
  1790   apply (auto intro!: image_eqI[where x="{x}" for x] simp: sets_restrict_space)
  1790   apply (auto intro!: image_eqI[where x="{x}" for x] simp: sets_restrict_space)
  1791   apply (auto simp add: sets_restrict_restrict_space continuous_on_eq_continuous_within
  1791   apply (auto simp add: sets_restrict_restrict_space continuous_on_eq_continuous_within
  1792               cong: measurable_cong_sets 
  1792               cong: measurable_cong_sets
  1793               intro!: borel_measurable_continuous_on_restrict intro: continuous_within_subset)
  1793               intro!: borel_measurable_continuous_on_restrict intro: continuous_within_subset)
  1794   done
  1794   done
  1795 
  1795 
  1796 lemma borel_measurable_mono:
  1796 lemma borel_measurable_mono:
  1797   fixes f :: "real \<Rightarrow> real"
  1797   fixes f :: "real \<Rightarrow> real"