src/HOL/Probability/Borel_Space.thy
 author haftmann Tue Mar 18 22:11:46 2014 +0100 (2014-03-18) changeset 56212 3253aaf73a01 parent 54775 2d3df8633dad child 56371 fb9ae0727548 permissions -rw-r--r--
consolidated theorem names containing INFI and SUPR: have INF and SUP instead uniformly
```     1 (*  Title:      HOL/Probability/Borel_Space.thy
```
```     2     Author:     Johannes Hölzl, TU München
```
```     3     Author:     Armin Heller, TU München
```
```     4 *)
```
```     5
```
```     6 header {*Borel spaces*}
```
```     7
```
```     8 theory Borel_Space
```
```     9 imports
```
```    10   Measurable
```
```    11   "~~/src/HOL/Multivariate_Analysis/Multivariate_Analysis"
```
```    12 begin
```
```    13
```
```    14 section "Generic Borel spaces"
```
```    15
```
```    16 definition borel :: "'a::topological_space measure" where
```
```    17   "borel = sigma UNIV {S. open S}"
```
```    18
```
```    19 abbreviation "borel_measurable M \<equiv> measurable M borel"
```
```    20
```
```    21 lemma in_borel_measurable:
```
```    22    "f \<in> borel_measurable M \<longleftrightarrow>
```
```    23     (\<forall>S \<in> sigma_sets UNIV {S. open S}. f -` S \<inter> space M \<in> sets M)"
```
```    24   by (auto simp add: measurable_def borel_def)
```
```    25
```
```    26 lemma in_borel_measurable_borel:
```
```    27    "f \<in> borel_measurable M \<longleftrightarrow>
```
```    28     (\<forall>S \<in> sets borel.
```
```    29       f -` S \<inter> space M \<in> sets M)"
```
```    30   by (auto simp add: measurable_def borel_def)
```
```    31
```
```    32 lemma space_borel[simp]: "space borel = UNIV"
```
```    33   unfolding borel_def by auto
```
```    34
```
```    35 lemma space_in_borel[measurable]: "UNIV \<in> sets borel"
```
```    36   unfolding borel_def by auto
```
```    37
```
```    38 lemma pred_Collect_borel[measurable (raw)]: "Measurable.pred borel P \<Longrightarrow> {x. P x} \<in> sets borel"
```
```    39   unfolding borel_def pred_def by auto
```
```    40
```
```    41 lemma borel_open[measurable (raw generic)]:
```
```    42   assumes "open A" shows "A \<in> sets borel"
```
```    43 proof -
```
```    44   have "A \<in> {S. open S}" unfolding mem_Collect_eq using assms .
```
```    45   thus ?thesis unfolding borel_def by auto
```
```    46 qed
```
```    47
```
```    48 lemma borel_closed[measurable (raw generic)]:
```
```    49   assumes "closed A" shows "A \<in> sets borel"
```
```    50 proof -
```
```    51   have "space borel - (- A) \<in> sets borel"
```
```    52     using assms unfolding closed_def by (blast intro: borel_open)
```
```    53   thus ?thesis by simp
```
```    54 qed
```
```    55
```
```    56 lemma borel_singleton[measurable]:
```
```    57   "A \<in> sets borel \<Longrightarrow> insert x A \<in> sets (borel :: 'a::t1_space measure)"
```
```    58   unfolding insert_def by (rule sets.Un) auto
```
```    59
```
```    60 lemma borel_comp[measurable]: "A \<in> sets borel \<Longrightarrow> - A \<in> sets borel"
```
```    61   unfolding Compl_eq_Diff_UNIV by simp
```
```    62
```
```    63 lemma borel_measurable_vimage:
```
```    64   fixes f :: "'a \<Rightarrow> 'x::t2_space"
```
```    65   assumes borel[measurable]: "f \<in> borel_measurable M"
```
```    66   shows "f -` {x} \<inter> space M \<in> sets M"
```
```    67   by simp
```
```    68
```
```    69 lemma borel_measurableI:
```
```    70   fixes f :: "'a \<Rightarrow> 'x\<Colon>topological_space"
```
```    71   assumes "\<And>S. open S \<Longrightarrow> f -` S \<inter> space M \<in> sets M"
```
```    72   shows "f \<in> borel_measurable M"
```
```    73   unfolding borel_def
```
```    74 proof (rule measurable_measure_of, simp_all)
```
```    75   fix S :: "'x set" assume "open S" thus "f -` S \<inter> space M \<in> sets M"
```
```    76     using assms[of S] by simp
```
```    77 qed
```
```    78
```
```    79 lemma borel_measurable_const:
```
```    80   "(\<lambda>x. c) \<in> borel_measurable M"
```
```    81   by auto
```
```    82
```
```    83 lemma borel_measurable_indicator:
```
```    84   assumes A: "A \<in> sets M"
```
```    85   shows "indicator A \<in> borel_measurable M"
```
```    86   unfolding indicator_def [abs_def] using A
```
```    87   by (auto intro!: measurable_If_set)
```
```    88
```
```    89 lemma borel_measurable_count_space[measurable (raw)]:
```
```    90   "f \<in> borel_measurable (count_space S)"
```
```    91   unfolding measurable_def by auto
```
```    92
```
```    93 lemma borel_measurable_indicator'[measurable (raw)]:
```
```    94   assumes [measurable]: "{x\<in>space M. f x \<in> A x} \<in> sets M"
```
```    95   shows "(\<lambda>x. indicator (A x) (f x)) \<in> borel_measurable M"
```
```    96   unfolding indicator_def[abs_def]
```
```    97   by (auto intro!: measurable_If)
```
```    98
```
```    99 lemma borel_measurable_indicator_iff:
```
```   100   "(indicator A :: 'a \<Rightarrow> 'x::{t1_space, zero_neq_one}) \<in> borel_measurable M \<longleftrightarrow> A \<inter> space M \<in> sets M"
```
```   101     (is "?I \<in> borel_measurable M \<longleftrightarrow> _")
```
```   102 proof
```
```   103   assume "?I \<in> borel_measurable M"
```
```   104   then have "?I -` {1} \<inter> space M \<in> sets M"
```
```   105     unfolding measurable_def by auto
```
```   106   also have "?I -` {1} \<inter> space M = A \<inter> space M"
```
```   107     unfolding indicator_def [abs_def] by auto
```
```   108   finally show "A \<inter> space M \<in> sets M" .
```
```   109 next
```
```   110   assume "A \<inter> space M \<in> sets M"
```
```   111   moreover have "?I \<in> borel_measurable M \<longleftrightarrow>
```
```   112     (indicator (A \<inter> space M) :: 'a \<Rightarrow> 'x) \<in> borel_measurable M"
```
```   113     by (intro measurable_cong) (auto simp: indicator_def)
```
```   114   ultimately show "?I \<in> borel_measurable M" by auto
```
```   115 qed
```
```   116
```
```   117 lemma borel_measurable_subalgebra:
```
```   118   assumes "sets N \<subseteq> sets M" "space N = space M" "f \<in> borel_measurable N"
```
```   119   shows "f \<in> borel_measurable M"
```
```   120   using assms unfolding measurable_def by auto
```
```   121
```
```   122 lemma borel_measurable_continuous_on1:
```
```   123   fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
```
```   124   assumes "continuous_on UNIV f"
```
```   125   shows "f \<in> borel_measurable borel"
```
```   126   apply(rule borel_measurableI)
```
```   127   using continuous_open_preimage[OF assms] unfolding vimage_def by auto
```
```   128
```
```   129 lemma borel_eq_countable_basis:
```
```   130   fixes B::"'a::topological_space set set"
```
```   131   assumes "countable B"
```
```   132   assumes "topological_basis B"
```
```   133   shows "borel = sigma UNIV B"
```
```   134   unfolding borel_def
```
```   135 proof (intro sigma_eqI sigma_sets_eqI, safe)
```
```   136   interpret countable_basis using assms by unfold_locales
```
```   137   fix X::"'a set" assume "open X"
```
```   138   from open_countable_basisE[OF this] guess B' . note B' = this
```
```   139   then show "X \<in> sigma_sets UNIV B"
```
```   140     by (blast intro: sigma_sets_UNION `countable B` countable_subset)
```
```   141 next
```
```   142   fix b assume "b \<in> B"
```
```   143   hence "open b" by (rule topological_basis_open[OF assms(2)])
```
```   144   thus "b \<in> sigma_sets UNIV (Collect open)" by auto
```
```   145 qed simp_all
```
```   146
```
```   147 lemma borel_measurable_Pair[measurable (raw)]:
```
```   148   fixes f :: "'a \<Rightarrow> 'b::second_countable_topology" and g :: "'a \<Rightarrow> 'c::second_countable_topology"
```
```   149   assumes f[measurable]: "f \<in> borel_measurable M"
```
```   150   assumes g[measurable]: "g \<in> borel_measurable M"
```
```   151   shows "(\<lambda>x. (f x, g x)) \<in> borel_measurable M"
```
```   152 proof (subst borel_eq_countable_basis)
```
```   153   let ?B = "SOME B::'b set set. countable B \<and> topological_basis B"
```
```   154   let ?C = "SOME B::'c set set. countable B \<and> topological_basis B"
```
```   155   let ?P = "(\<lambda>(b, c). b \<times> c) ` (?B \<times> ?C)"
```
```   156   show "countable ?P" "topological_basis ?P"
```
```   157     by (auto intro!: countable_basis topological_basis_prod is_basis)
```
```   158
```
```   159   show "(\<lambda>x. (f x, g x)) \<in> measurable M (sigma UNIV ?P)"
```
```   160   proof (rule measurable_measure_of)
```
```   161     fix S assume "S \<in> ?P"
```
```   162     then obtain b c where "b \<in> ?B" "c \<in> ?C" and S: "S = b \<times> c" by auto
```
```   163     then have borel: "open b" "open c"
```
```   164       by (auto intro: is_basis topological_basis_open)
```
```   165     have "(\<lambda>x. (f x, g x)) -` S \<inter> space M = (f -` b \<inter> space M) \<inter> (g -` c \<inter> space M)"
```
```   166       unfolding S by auto
```
```   167     also have "\<dots> \<in> sets M"
```
```   168       using borel by simp
```
```   169     finally show "(\<lambda>x. (f x, g x)) -` S \<inter> space M \<in> sets M" .
```
```   170   qed auto
```
```   171 qed
```
```   172
```
```   173 lemma borel_measurable_continuous_on:
```
```   174   fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
```
```   175   assumes f: "continuous_on UNIV f" and g: "g \<in> borel_measurable M"
```
```   176   shows "(\<lambda>x. f (g x)) \<in> borel_measurable M"
```
```   177   using measurable_comp[OF g borel_measurable_continuous_on1[OF f]] by (simp add: comp_def)
```
```   178
```
```   179 lemma borel_measurable_continuous_on_open':
```
```   180   fixes f :: "'a::topological_space \<Rightarrow> 'b::t1_space"
```
```   181   assumes cont: "continuous_on A f" "open A"
```
```   182   shows "(\<lambda>x. if x \<in> A then f x else c) \<in> borel_measurable borel" (is "?f \<in> _")
```
```   183 proof (rule borel_measurableI)
```
```   184   fix S :: "'b set" assume "open S"
```
```   185   then have "open {x\<in>A. f x \<in> S}"
```
```   186     by (intro continuous_open_preimage[OF cont]) auto
```
```   187   then have *: "{x\<in>A. f x \<in> S} \<in> sets borel" by auto
```
```   188   have "?f -` S \<inter> space borel =
```
```   189     {x\<in>A. f x \<in> S} \<union> (if c \<in> S then space borel - A else {})"
```
```   190     by (auto split: split_if_asm)
```
```   191   also have "\<dots> \<in> sets borel"
```
```   192     using * `open A` by auto
```
```   193   finally show "?f -` S \<inter> space borel \<in> sets borel" .
```
```   194 qed
```
```   195
```
```   196 lemma borel_measurable_continuous_on_open:
```
```   197   fixes f :: "'a::topological_space \<Rightarrow> 'b::t1_space"
```
```   198   assumes cont: "continuous_on A f" "open A"
```
```   199   assumes g: "g \<in> borel_measurable M"
```
```   200   shows "(\<lambda>x. if g x \<in> A then f (g x) else c) \<in> borel_measurable M"
```
```   201   using measurable_comp[OF g borel_measurable_continuous_on_open'[OF cont], of c]
```
```   202   by (simp add: comp_def)
```
```   203
```
```   204 lemma borel_measurable_continuous_Pair:
```
```   205   fixes f :: "'a \<Rightarrow> 'b::second_countable_topology" and g :: "'a \<Rightarrow> 'c::second_countable_topology"
```
```   206   assumes [measurable]: "f \<in> borel_measurable M"
```
```   207   assumes [measurable]: "g \<in> borel_measurable M"
```
```   208   assumes H: "continuous_on UNIV (\<lambda>x. H (fst x) (snd x))"
```
```   209   shows "(\<lambda>x. H (f x) (g x)) \<in> borel_measurable M"
```
```   210 proof -
```
```   211   have eq: "(\<lambda>x. H (f x) (g x)) = (\<lambda>x. (\<lambda>x. H (fst x) (snd x)) (f x, g x))" by auto
```
```   212   show ?thesis
```
```   213     unfolding eq by (rule borel_measurable_continuous_on[OF H]) auto
```
```   214 qed
```
```   215
```
```   216 section "Borel spaces on euclidean spaces"
```
```   217
```
```   218 lemma borel_measurable_inner[measurable (raw)]:
```
```   219   fixes f g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_inner}"
```
```   220   assumes "f \<in> borel_measurable M"
```
```   221   assumes "g \<in> borel_measurable M"
```
```   222   shows "(\<lambda>x. f x \<bullet> g x) \<in> borel_measurable M"
```
```   223   using assms
```
```   224   by (rule borel_measurable_continuous_Pair) (intro continuous_on_intros)
```
```   225
```
```   226 lemma [measurable]:
```
```   227   fixes a b :: "'a\<Colon>linorder_topology"
```
```   228   shows lessThan_borel: "{..< a} \<in> sets borel"
```
```   229     and greaterThan_borel: "{a <..} \<in> sets borel"
```
```   230     and greaterThanLessThan_borel: "{a<..<b} \<in> sets borel"
```
```   231     and atMost_borel: "{..a} \<in> sets borel"
```
```   232     and atLeast_borel: "{a..} \<in> sets borel"
```
```   233     and atLeastAtMost_borel: "{a..b} \<in> sets borel"
```
```   234     and greaterThanAtMost_borel: "{a<..b} \<in> sets borel"
```
```   235     and atLeastLessThan_borel: "{a..<b} \<in> sets borel"
```
```   236   unfolding greaterThanAtMost_def atLeastLessThan_def
```
```   237   by (blast intro: borel_open borel_closed open_lessThan open_greaterThan open_greaterThanLessThan
```
```   238                    closed_atMost closed_atLeast closed_atLeastAtMost)+
```
```   239
```
```   240 notation
```
```   241   eucl_less (infix "<e" 50)
```
```   242
```
```   243 lemma box_oc: "{x. a <e x \<and> x \<le> b} = {x. a <e x} \<inter> {..b}"
```
```   244   and box_co: "{x. a \<le> x \<and> x <e b} = {a..} \<inter> {x. x <e b}"
```
```   245   by auto
```
```   246
```
```   247 lemma eucl_ivals[measurable]:
```
```   248   fixes a b :: "'a\<Colon>ordered_euclidean_space"
```
```   249   shows "{x. x <e a} \<in> sets borel"
```
```   250     and "{x. a <e x} \<in> sets borel"
```
```   251     and "box a b \<in> sets borel"
```
```   252     and "{..a} \<in> sets borel"
```
```   253     and "{a..} \<in> sets borel"
```
```   254     and "{a..b} \<in> sets borel"
```
```   255     and  "{x. a <e x \<and> x \<le> b} \<in> sets borel"
```
```   256     and "{x. a \<le> x \<and>  x <e b} \<in> sets borel"
```
```   257   unfolding box_oc box_co
```
```   258   by (auto intro: borel_open borel_closed)
```
```   259
```
```   260 lemma open_Collect_less:
```
```   261   fixes f g :: "'i::topological_space \<Rightarrow> 'a :: {dense_linorder, linorder_topology}"
```
```   262   assumes "continuous_on UNIV f"
```
```   263   assumes "continuous_on UNIV g"
```
```   264   shows "open {x. f x < g x}"
```
```   265 proof -
```
```   266   have "open (\<Union>y. {x \<in> UNIV. f x \<in> {..< y}} \<inter> {x \<in> UNIV. g x \<in> {y <..}})" (is "open ?X")
```
```   267     by (intro open_UN ballI open_Int continuous_open_preimage assms) auto
```
```   268   also have "?X = {x. f x < g x}"
```
```   269     by (auto intro: dense)
```
```   270   finally show ?thesis .
```
```   271 qed
```
```   272
```
```   273 lemma closed_Collect_le:
```
```   274   fixes f g :: "'i::topological_space \<Rightarrow> 'a :: {dense_linorder, linorder_topology}"
```
```   275   assumes f: "continuous_on UNIV f"
```
```   276   assumes g: "continuous_on UNIV g"
```
```   277   shows "closed {x. f x \<le> g x}"
```
```   278   using open_Collect_less[OF g f] unfolding not_less[symmetric] Collect_neg_eq open_closed .
```
```   279
```
```   280 lemma borel_measurable_less[measurable]:
```
```   281   fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, dense_linorder, linorder_topology}"
```
```   282   assumes "f \<in> borel_measurable M"
```
```   283   assumes "g \<in> borel_measurable M"
```
```   284   shows "{w \<in> space M. f w < g w} \<in> sets M"
```
```   285 proof -
```
```   286   have "{w \<in> space M. f w < g w} = (\<lambda>x. (f x, g x)) -` {x. fst x < snd x} \<inter> space M"
```
```   287     by auto
```
```   288   also have "\<dots> \<in> sets M"
```
```   289     by (intro measurable_sets[OF borel_measurable_Pair borel_open, OF assms open_Collect_less]
```
```   290               continuous_on_intros)
```
```   291   finally show ?thesis .
```
```   292 qed
```
```   293
```
```   294 lemma
```
```   295   fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, dense_linorder, linorder_topology}"
```
```   296   assumes f[measurable]: "f \<in> borel_measurable M"
```
```   297   assumes g[measurable]: "g \<in> borel_measurable M"
```
```   298   shows borel_measurable_le[measurable]: "{w \<in> space M. f w \<le> g w} \<in> sets M"
```
```   299     and borel_measurable_eq[measurable]: "{w \<in> space M. f w = g w} \<in> sets M"
```
```   300     and borel_measurable_neq: "{w \<in> space M. f w \<noteq> g w} \<in> sets M"
```
```   301   unfolding eq_iff not_less[symmetric]
```
```   302   by measurable
```
```   303
```
```   304 lemma
```
```   305   fixes i :: "'a::{second_countable_topology, real_inner}"
```
```   306   shows hafspace_less_borel: "{x. a < x \<bullet> i} \<in> sets borel"
```
```   307     and hafspace_greater_borel: "{x. x \<bullet> i < a} \<in> sets borel"
```
```   308     and hafspace_less_eq_borel: "{x. a \<le> x \<bullet> i} \<in> sets borel"
```
```   309     and hafspace_greater_eq_borel: "{x. x \<bullet> i \<le> a} \<in> sets borel"
```
```   310   by simp_all
```
```   311
```
```   312 subsection "Borel space equals sigma algebras over intervals"
```
```   313
```
```   314 lemma borel_sigma_sets_subset:
```
```   315   "A \<subseteq> sets borel \<Longrightarrow> sigma_sets UNIV A \<subseteq> sets borel"
```
```   316   using sets.sigma_sets_subset[of A borel] by simp
```
```   317
```
```   318 lemma borel_eq_sigmaI1:
```
```   319   fixes F :: "'i \<Rightarrow> 'a::topological_space set" and X :: "'a::topological_space set set"
```
```   320   assumes borel_eq: "borel = sigma UNIV X"
```
```   321   assumes X: "\<And>x. x \<in> X \<Longrightarrow> x \<in> sets (sigma UNIV (F ` A))"
```
```   322   assumes F: "\<And>i. i \<in> A \<Longrightarrow> F i \<in> sets borel"
```
```   323   shows "borel = sigma UNIV (F ` A)"
```
```   324   unfolding borel_def
```
```   325 proof (intro sigma_eqI antisym)
```
```   326   have borel_rev_eq: "sigma_sets UNIV {S::'a set. open S} = sets borel"
```
```   327     unfolding borel_def by simp
```
```   328   also have "\<dots> = sigma_sets UNIV X"
```
```   329     unfolding borel_eq by simp
```
```   330   also have "\<dots> \<subseteq> sigma_sets UNIV (F`A)"
```
```   331     using X by (intro sigma_algebra.sigma_sets_subset[OF sigma_algebra_sigma_sets]) auto
```
```   332   finally show "sigma_sets UNIV {S. open S} \<subseteq> sigma_sets UNIV (F`A)" .
```
```   333   show "sigma_sets UNIV (F`A) \<subseteq> sigma_sets UNIV {S. open S}"
```
```   334     unfolding borel_rev_eq using F by (intro borel_sigma_sets_subset) auto
```
```   335 qed auto
```
```   336
```
```   337 lemma borel_eq_sigmaI2:
```
```   338   fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set"
```
```   339     and G :: "'l \<Rightarrow> 'k \<Rightarrow> 'a::topological_space set"
```
```   340   assumes borel_eq: "borel = sigma UNIV ((\<lambda>(i, j). G i j)`B)"
```
```   341   assumes X: "\<And>i j. (i, j) \<in> B \<Longrightarrow> G i j \<in> sets (sigma UNIV ((\<lambda>(i, j). F i j) ` A))"
```
```   342   assumes F: "\<And>i j. (i, j) \<in> A \<Longrightarrow> F i j \<in> sets borel"
```
```   343   shows "borel = sigma UNIV ((\<lambda>(i, j). F i j) ` A)"
```
```   344   using assms
```
```   345   by (intro borel_eq_sigmaI1[where X="(\<lambda>(i, j). G i j) ` B" and F="(\<lambda>(i, j). F i j)"]) auto
```
```   346
```
```   347 lemma borel_eq_sigmaI3:
```
```   348   fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set" and X :: "'a::topological_space set set"
```
```   349   assumes borel_eq: "borel = sigma UNIV X"
```
```   350   assumes X: "\<And>x. x \<in> X \<Longrightarrow> x \<in> sets (sigma UNIV ((\<lambda>(i, j). F i j) ` A))"
```
```   351   assumes F: "\<And>i j. (i, j) \<in> A \<Longrightarrow> F i j \<in> sets borel"
```
```   352   shows "borel = sigma UNIV ((\<lambda>(i, j). F i j) ` A)"
```
```   353   using assms by (intro borel_eq_sigmaI1[where X=X and F="(\<lambda>(i, j). F i j)"]) auto
```
```   354
```
```   355 lemma borel_eq_sigmaI4:
```
```   356   fixes F :: "'i \<Rightarrow> 'a::topological_space set"
```
```   357     and G :: "'l \<Rightarrow> 'k \<Rightarrow> 'a::topological_space set"
```
```   358   assumes borel_eq: "borel = sigma UNIV ((\<lambda>(i, j). G i j)`A)"
```
```   359   assumes X: "\<And>i j. (i, j) \<in> A \<Longrightarrow> G i j \<in> sets (sigma UNIV (range F))"
```
```   360   assumes F: "\<And>i. F i \<in> sets borel"
```
```   361   shows "borel = sigma UNIV (range F)"
```
```   362   using assms by (intro borel_eq_sigmaI1[where X="(\<lambda>(i, j). G i j) ` A" and F=F]) auto
```
```   363
```
```   364 lemma borel_eq_sigmaI5:
```
```   365   fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set" and G :: "'l \<Rightarrow> 'a::topological_space set"
```
```   366   assumes borel_eq: "borel = sigma UNIV (range G)"
```
```   367   assumes X: "\<And>i. G i \<in> sets (sigma UNIV (range (\<lambda>(i, j). F i j)))"
```
```   368   assumes F: "\<And>i j. F i j \<in> sets borel"
```
```   369   shows "borel = sigma UNIV (range (\<lambda>(i, j). F i j))"
```
```   370   using assms by (intro borel_eq_sigmaI1[where X="range G" and F="(\<lambda>(i, j). F i j)"]) auto
```
```   371
```
```   372 lemma borel_eq_box:
```
```   373   "borel = sigma UNIV (range (\<lambda> (a, b). box a b :: 'a \<Colon> euclidean_space set))"
```
```   374     (is "_ = ?SIGMA")
```
```   375 proof (rule borel_eq_sigmaI1[OF borel_def])
```
```   376   fix M :: "'a set" assume "M \<in> {S. open S}"
```
```   377   then have "open M" by simp
```
```   378   show "M \<in> ?SIGMA"
```
```   379     apply (subst open_UNION_box[OF `open M`])
```
```   380     apply (safe intro!: sets.countable_UN' countable_PiE countable_Collect)
```
```   381     apply (auto intro: countable_rat)
```
```   382     done
```
```   383 qed (auto simp: box_def)
```
```   384
```
```   385 lemma halfspace_gt_in_halfspace:
```
```   386   assumes i: "i \<in> A"
```
```   387   shows "{x\<Colon>'a. a < x \<bullet> i} \<in>
```
```   388     sigma_sets UNIV ((\<lambda> (a, i). {x\<Colon>'a\<Colon>euclidean_space. x \<bullet> i < a}) ` (UNIV \<times> A))"
```
```   389   (is "?set \<in> ?SIGMA")
```
```   390 proof -
```
```   391   interpret sigma_algebra UNIV ?SIGMA
```
```   392     by (intro sigma_algebra_sigma_sets) simp_all
```
```   393   have *: "?set = (\<Union>n. UNIV - {x\<Colon>'a. x \<bullet> i < a + 1 / real (Suc n)})"
```
```   394   proof (safe, simp_all add: not_less)
```
```   395     fix x :: 'a assume "a < x \<bullet> i"
```
```   396     with reals_Archimedean[of "x \<bullet> i - a"]
```
```   397     obtain n where "a + 1 / real (Suc n) < x \<bullet> i"
```
```   398       by (auto simp: inverse_eq_divide field_simps)
```
```   399     then show "\<exists>n. a + 1 / real (Suc n) \<le> x \<bullet> i"
```
```   400       by (blast intro: less_imp_le)
```
```   401   next
```
```   402     fix x n
```
```   403     have "a < a + 1 / real (Suc n)" by auto
```
```   404     also assume "\<dots> \<le> x"
```
```   405     finally show "a < x" .
```
```   406   qed
```
```   407   show "?set \<in> ?SIGMA" unfolding *
```
```   408     by (auto del: Diff intro!: Diff i)
```
```   409 qed
```
```   410
```
```   411 lemma borel_eq_halfspace_less:
```
```   412   "borel = sigma UNIV ((\<lambda>(a, i). {x::'a::euclidean_space. x \<bullet> i < a}) ` (UNIV \<times> Basis))"
```
```   413   (is "_ = ?SIGMA")
```
```   414 proof (rule borel_eq_sigmaI2[OF borel_eq_box])
```
```   415   fix a b :: 'a
```
```   416   have "box a b = {x\<in>space ?SIGMA. \<forall>i\<in>Basis. a \<bullet> i < x \<bullet> i \<and> x \<bullet> i < b \<bullet> i}"
```
```   417     by (auto simp: box_def)
```
```   418   also have "\<dots> \<in> sets ?SIGMA"
```
```   419     by (intro sets.sets_Collect_conj sets.sets_Collect_finite_All sets.sets_Collect_const)
```
```   420        (auto intro!: halfspace_gt_in_halfspace countable_PiE countable_rat)
```
```   421   finally show "box a b \<in> sets ?SIGMA" .
```
```   422 qed auto
```
```   423
```
```   424 lemma borel_eq_halfspace_le:
```
```   425   "borel = sigma UNIV ((\<lambda> (a, i). {x::'a::euclidean_space. x \<bullet> i \<le> a}) ` (UNIV \<times> Basis))"
```
```   426   (is "_ = ?SIGMA")
```
```   427 proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
```
```   428   fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
```
```   429   then have i: "i \<in> Basis" by auto
```
```   430   have *: "{x::'a. x\<bullet>i < a} = (\<Union>n. {x. x\<bullet>i \<le> a - 1/real (Suc n)})"
```
```   431   proof (safe, simp_all)
```
```   432     fix x::'a assume *: "x\<bullet>i < a"
```
```   433     with reals_Archimedean[of "a - x\<bullet>i"]
```
```   434     obtain n where "x \<bullet> i < a - 1 / (real (Suc n))"
```
```   435       by (auto simp: field_simps inverse_eq_divide)
```
```   436     then show "\<exists>n. x \<bullet> i \<le> a - 1 / (real (Suc n))"
```
```   437       by (blast intro: less_imp_le)
```
```   438   next
```
```   439     fix x::'a and n
```
```   440     assume "x\<bullet>i \<le> a - 1 / real (Suc n)"
```
```   441     also have "\<dots> < a" by auto
```
```   442     finally show "x\<bullet>i < a" .
```
```   443   qed
```
```   444   show "{x. x\<bullet>i < a} \<in> ?SIGMA" unfolding *
```
```   445     by (safe intro!: sets.countable_UN) (auto intro: i)
```
```   446 qed auto
```
```   447
```
```   448 lemma borel_eq_halfspace_ge:
```
```   449   "borel = sigma UNIV ((\<lambda> (a, i). {x\<Colon>'a\<Colon>euclidean_space. a \<le> x \<bullet> i}) ` (UNIV \<times> Basis))"
```
```   450   (is "_ = ?SIGMA")
```
```   451 proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
```
```   452   fix a :: real and i :: 'a assume i: "(a, i) \<in> UNIV \<times> Basis"
```
```   453   have *: "{x::'a. x\<bullet>i < a} = space ?SIGMA - {x::'a. a \<le> x\<bullet>i}" by auto
```
```   454   show "{x. x\<bullet>i < a} \<in> ?SIGMA" unfolding *
```
```   455     using i by (safe intro!: sets.compl_sets) auto
```
```   456 qed auto
```
```   457
```
```   458 lemma borel_eq_halfspace_greater:
```
```   459   "borel = sigma UNIV ((\<lambda> (a, i). {x\<Colon>'a\<Colon>euclidean_space. a < x \<bullet> i}) ` (UNIV \<times> Basis))"
```
```   460   (is "_ = ?SIGMA")
```
```   461 proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_le])
```
```   462   fix a :: real and i :: 'a assume "(a, i) \<in> (UNIV \<times> Basis)"
```
```   463   then have i: "i \<in> Basis" by auto
```
```   464   have *: "{x::'a. x\<bullet>i \<le> a} = space ?SIGMA - {x::'a. a < x\<bullet>i}" by auto
```
```   465   show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA" unfolding *
```
```   466     by (safe intro!: sets.compl_sets) (auto intro: i)
```
```   467 qed auto
```
```   468
```
```   469 lemma borel_eq_atMost:
```
```   470   "borel = sigma UNIV (range (\<lambda>a. {..a\<Colon>'a\<Colon>ordered_euclidean_space}))"
```
```   471   (is "_ = ?SIGMA")
```
```   472 proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_le])
```
```   473   fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
```
```   474   then have "i \<in> Basis" by auto
```
```   475   then have *: "{x::'a. x\<bullet>i \<le> a} = (\<Union>k::nat. {.. (\<Sum>n\<in>Basis. (if n = i then a else real k)*\<^sub>R n)})"
```
```   476   proof (safe, simp_all add: eucl_le[where 'a='a] split: split_if_asm)
```
```   477     fix x :: 'a
```
```   478     from real_arch_simple[of "Max ((\<lambda>i. x\<bullet>i)`Basis)"] guess k::nat ..
```
```   479     then have "\<And>i. i \<in> Basis \<Longrightarrow> x\<bullet>i \<le> real k"
```
```   480       by (subst (asm) Max_le_iff) auto
```
```   481     then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> x \<bullet> ia \<le> real k"
```
```   482       by (auto intro!: exI[of _ k])
```
```   483   qed
```
```   484   show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA" unfolding *
```
```   485     by (safe intro!: sets.countable_UN) auto
```
```   486 qed auto
```
```   487
```
```   488 lemma borel_eq_greaterThan:
```
```   489   "borel = sigma UNIV (range (\<lambda>a\<Colon>'a\<Colon>ordered_euclidean_space. {x. a <e x}))"
```
```   490   (is "_ = ?SIGMA")
```
```   491 proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_le])
```
```   492   fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
```
```   493   then have i: "i \<in> Basis" by auto
```
```   494   have "{x::'a. x\<bullet>i \<le> a} = UNIV - {x::'a. a < x\<bullet>i}" by auto
```
```   495   also have *: "{x::'a. a < x\<bullet>i} =
```
```   496       (\<Union>k::nat. {x. (\<Sum>n\<in>Basis. (if n = i then a else -real k) *\<^sub>R n) <e x})" using i
```
```   497   proof (safe, simp_all add: eucl_less_def split: split_if_asm)
```
```   498     fix x :: 'a
```
```   499     from reals_Archimedean2[of "Max ((\<lambda>i. -x\<bullet>i)`Basis)"]
```
```   500     guess k::nat .. note k = this
```
```   501     { fix i :: 'a assume "i \<in> Basis"
```
```   502       then have "-x\<bullet>i < real k"
```
```   503         using k by (subst (asm) Max_less_iff) auto
```
```   504       then have "- real k < x\<bullet>i" by simp }
```
```   505     then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> -real k < x \<bullet> ia"
```
```   506       by (auto intro!: exI[of _ k])
```
```   507   qed
```
```   508   finally show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA"
```
```   509     apply (simp only:)
```
```   510     apply (safe intro!: sets.countable_UN sets.Diff)
```
```   511     apply (auto intro: sigma_sets_top)
```
```   512     done
```
```   513 qed auto
```
```   514
```
```   515 lemma borel_eq_lessThan:
```
```   516   "borel = sigma UNIV (range (\<lambda>a\<Colon>'a\<Colon>ordered_euclidean_space. {x. x <e a}))"
```
```   517   (is "_ = ?SIGMA")
```
```   518 proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_ge])
```
```   519   fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
```
```   520   then have i: "i \<in> Basis" by auto
```
```   521   have "{x::'a. a \<le> x\<bullet>i} = UNIV - {x::'a. x\<bullet>i < a}" by auto
```
```   522   also have *: "{x::'a. x\<bullet>i < a} = (\<Union>k::nat. {x. x <e (\<Sum>n\<in>Basis. (if n = i then a else real k) *\<^sub>R n)})" using `i\<in> Basis`
```
```   523   proof (safe, simp_all add: eucl_less_def split: split_if_asm)
```
```   524     fix x :: 'a
```
```   525     from reals_Archimedean2[of "Max ((\<lambda>i. x\<bullet>i)`Basis)"]
```
```   526     guess k::nat .. note k = this
```
```   527     { fix i :: 'a assume "i \<in> Basis"
```
```   528       then have "x\<bullet>i < real k"
```
```   529         using k by (subst (asm) Max_less_iff) auto
```
```   530       then have "x\<bullet>i < real k" by simp }
```
```   531     then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> x \<bullet> ia < real k"
```
```   532       by (auto intro!: exI[of _ k])
```
```   533   qed
```
```   534   finally show "{x. a \<le> x\<bullet>i} \<in> ?SIGMA"
```
```   535     apply (simp only:)
```
```   536     apply (safe intro!: sets.countable_UN sets.Diff)
```
```   537     apply (auto intro: sigma_sets_top )
```
```   538     done
```
```   539 qed auto
```
```   540
```
```   541 lemma borel_eq_atLeastAtMost:
```
```   542   "borel = sigma UNIV (range (\<lambda>(a,b). {a..b} \<Colon>'a\<Colon>ordered_euclidean_space set))"
```
```   543   (is "_ = ?SIGMA")
```
```   544 proof (rule borel_eq_sigmaI5[OF borel_eq_atMost])
```
```   545   fix a::'a
```
```   546   have *: "{..a} = (\<Union>n::nat. {- real n *\<^sub>R One .. a})"
```
```   547   proof (safe, simp_all add: eucl_le[where 'a='a])
```
```   548     fix x :: 'a
```
```   549     from real_arch_simple[of "Max ((\<lambda>i. - x\<bullet>i)`Basis)"]
```
```   550     guess k::nat .. note k = this
```
```   551     { fix i :: 'a assume "i \<in> Basis"
```
```   552       with k have "- x\<bullet>i \<le> real k"
```
```   553         by (subst (asm) Max_le_iff) (auto simp: field_simps)
```
```   554       then have "- real k \<le> x\<bullet>i" by simp }
```
```   555     then show "\<exists>n::nat. \<forall>i\<in>Basis. - real n \<le> x \<bullet> i"
```
```   556       by (auto intro!: exI[of _ k])
```
```   557   qed
```
```   558   show "{..a} \<in> ?SIGMA" unfolding *
```
```   559     by (safe intro!: sets.countable_UN)
```
```   560        (auto intro!: sigma_sets_top)
```
```   561 qed auto
```
```   562
```
```   563 lemma eucl_lessThan: "{x::real. x <e a} = lessThan a"
```
```   564   by (simp add: eucl_less_def lessThan_def)
```
```   565
```
```   566 lemma borel_eq_atLeastLessThan:
```
```   567   "borel = sigma UNIV (range (\<lambda>(a, b). {a ..< b :: real}))" (is "_ = ?SIGMA")
```
```   568 proof (rule borel_eq_sigmaI5[OF borel_eq_lessThan])
```
```   569   have move_uminus: "\<And>x y::real. -x \<le> y \<longleftrightarrow> -y \<le> x" by auto
```
```   570   fix x :: real
```
```   571   have "{..<x} = (\<Union>i::nat. {-real i ..< x})"
```
```   572     by (auto simp: move_uminus real_arch_simple)
```
```   573   then show "{y. y <e x} \<in> ?SIGMA"
```
```   574     by (auto intro: sigma_sets.intros simp: eucl_lessThan)
```
```   575 qed auto
```
```   576
```
```   577 lemma borel_eq_closed: "borel = sigma UNIV (Collect closed)"
```
```   578   unfolding borel_def
```
```   579 proof (intro sigma_eqI sigma_sets_eqI, safe)
```
```   580   fix x :: "'a set" assume "open x"
```
```   581   hence "x = UNIV - (UNIV - x)" by auto
```
```   582   also have "\<dots> \<in> sigma_sets UNIV (Collect closed)"
```
```   583     by (rule sigma_sets.Compl)
```
```   584        (auto intro!: sigma_sets.Basic simp: `open x`)
```
```   585   finally show "x \<in> sigma_sets UNIV (Collect closed)" by simp
```
```   586 next
```
```   587   fix x :: "'a set" assume "closed x"
```
```   588   hence "x = UNIV - (UNIV - x)" by auto
```
```   589   also have "\<dots> \<in> sigma_sets UNIV (Collect open)"
```
```   590     by (rule sigma_sets.Compl)
```
```   591        (auto intro!: sigma_sets.Basic simp: `closed x`)
```
```   592   finally show "x \<in> sigma_sets UNIV (Collect open)" by simp
```
```   593 qed simp_all
```
```   594
```
```   595 lemma borel_measurable_halfspacesI:
```
```   596   fixes f :: "'a \<Rightarrow> 'c\<Colon>euclidean_space"
```
```   597   assumes F: "borel = sigma UNIV (F ` (UNIV \<times> Basis))"
```
```   598   and S_eq: "\<And>a i. S a i = f -` F (a,i) \<inter> space M"
```
```   599   shows "f \<in> borel_measurable M = (\<forall>i\<in>Basis. \<forall>a::real. S a i \<in> sets M)"
```
```   600 proof safe
```
```   601   fix a :: real and i :: 'b assume i: "i \<in> Basis" and f: "f \<in> borel_measurable M"
```
```   602   then show "S a i \<in> sets M" unfolding assms
```
```   603     by (auto intro!: measurable_sets simp: assms(1))
```
```   604 next
```
```   605   assume a: "\<forall>i\<in>Basis. \<forall>a. S a i \<in> sets M"
```
```   606   then show "f \<in> borel_measurable M"
```
```   607     by (auto intro!: measurable_measure_of simp: S_eq F)
```
```   608 qed
```
```   609
```
```   610 lemma borel_measurable_iff_halfspace_le:
```
```   611   fixes f :: "'a \<Rightarrow> 'c\<Colon>euclidean_space"
```
```   612   shows "f \<in> borel_measurable M = (\<forall>i\<in>Basis. \<forall>a. {w \<in> space M. f w \<bullet> i \<le> a} \<in> sets M)"
```
```   613   by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_le]) auto
```
```   614
```
```   615 lemma borel_measurable_iff_halfspace_less:
```
```   616   fixes f :: "'a \<Rightarrow> 'c\<Colon>euclidean_space"
```
```   617   shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i\<in>Basis. \<forall>a. {w \<in> space M. f w \<bullet> i < a} \<in> sets M)"
```
```   618   by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_less]) auto
```
```   619
```
```   620 lemma borel_measurable_iff_halfspace_ge:
```
```   621   fixes f :: "'a \<Rightarrow> 'c\<Colon>euclidean_space"
```
```   622   shows "f \<in> borel_measurable M = (\<forall>i\<in>Basis. \<forall>a. {w \<in> space M. a \<le> f w \<bullet> i} \<in> sets M)"
```
```   623   by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_ge]) auto
```
```   624
```
```   625 lemma borel_measurable_iff_halfspace_greater:
```
```   626   fixes f :: "'a \<Rightarrow> 'c\<Colon>euclidean_space"
```
```   627   shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i\<in>Basis. \<forall>a. {w \<in> space M. a < f w \<bullet> i} \<in> sets M)"
```
```   628   by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_greater]) auto
```
```   629
```
```   630 lemma borel_measurable_iff_le:
```
```   631   "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w \<le> a} \<in> sets M)"
```
```   632   using borel_measurable_iff_halfspace_le[where 'c=real] by simp
```
```   633
```
```   634 lemma borel_measurable_iff_less:
```
```   635   "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w < a} \<in> sets M)"
```
```   636   using borel_measurable_iff_halfspace_less[where 'c=real] by simp
```
```   637
```
```   638 lemma borel_measurable_iff_ge:
```
```   639   "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a \<le> f w} \<in> sets M)"
```
```   640   using borel_measurable_iff_halfspace_ge[where 'c=real]
```
```   641   by simp
```
```   642
```
```   643 lemma borel_measurable_iff_greater:
```
```   644   "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a < f w} \<in> sets M)"
```
```   645   using borel_measurable_iff_halfspace_greater[where 'c=real] by simp
```
```   646
```
```   647 lemma borel_measurable_euclidean_space:
```
```   648   fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
```
```   649   shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i\<in>Basis. (\<lambda>x. f x \<bullet> i) \<in> borel_measurable M)"
```
```   650 proof safe
```
```   651   assume f: "\<forall>i\<in>Basis. (\<lambda>x. f x \<bullet> i) \<in> borel_measurable M"
```
```   652   then show "f \<in> borel_measurable M"
```
```   653     by (subst borel_measurable_iff_halfspace_le) auto
```
```   654 qed auto
```
```   655
```
```   656 subsection "Borel measurable operators"
```
```   657
```
```   658 lemma borel_measurable_uminus[measurable (raw)]:
```
```   659   fixes g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
```
```   660   assumes g: "g \<in> borel_measurable M"
```
```   661   shows "(\<lambda>x. - g x) \<in> borel_measurable M"
```
```   662   by (rule borel_measurable_continuous_on[OF _ g]) (intro continuous_on_intros)
```
```   663
```
```   664 lemma borel_measurable_add[measurable (raw)]:
```
```   665   fixes f g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
```
```   666   assumes f: "f \<in> borel_measurable M"
```
```   667   assumes g: "g \<in> borel_measurable M"
```
```   668   shows "(\<lambda>x. f x + g x) \<in> borel_measurable M"
```
```   669   using f g by (rule borel_measurable_continuous_Pair) (intro continuous_on_intros)
```
```   670
```
```   671 lemma borel_measurable_setsum[measurable (raw)]:
```
```   672   fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
```
```   673   assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
```
```   674   shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
```
```   675 proof cases
```
```   676   assume "finite S"
```
```   677   thus ?thesis using assms by induct auto
```
```   678 qed simp
```
```   679
```
```   680 lemma borel_measurable_diff[measurable (raw)]:
```
```   681   fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
```
```   682   assumes f: "f \<in> borel_measurable M"
```
```   683   assumes g: "g \<in> borel_measurable M"
```
```   684   shows "(\<lambda>x. f x - g x) \<in> borel_measurable M"
```
```   685   using borel_measurable_add [of f M "- g"] assms by (simp add: fun_Compl_def)
```
```   686
```
```   687 lemma borel_measurable_times[measurable (raw)]:
```
```   688   fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_algebra}"
```
```   689   assumes f: "f \<in> borel_measurable M"
```
```   690   assumes g: "g \<in> borel_measurable M"
```
```   691   shows "(\<lambda>x. f x * g x) \<in> borel_measurable M"
```
```   692   using f g by (rule borel_measurable_continuous_Pair) (intro continuous_on_intros)
```
```   693
```
```   694 lemma borel_measurable_setprod[measurable (raw)]:
```
```   695   fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> 'b::{second_countable_topology, real_normed_field}"
```
```   696   assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
```
```   697   shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
```
```   698 proof cases
```
```   699   assume "finite S"
```
```   700   thus ?thesis using assms by induct auto
```
```   701 qed simp
```
```   702
```
```   703 lemma borel_measurable_dist[measurable (raw)]:
```
```   704   fixes g f :: "'a \<Rightarrow> 'b::{second_countable_topology, metric_space}"
```
```   705   assumes f: "f \<in> borel_measurable M"
```
```   706   assumes g: "g \<in> borel_measurable M"
```
```   707   shows "(\<lambda>x. dist (f x) (g x)) \<in> borel_measurable M"
```
```   708   using f g by (rule borel_measurable_continuous_Pair) (intro continuous_on_intros)
```
```   709
```
```   710 lemma borel_measurable_scaleR[measurable (raw)]:
```
```   711   fixes g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
```
```   712   assumes f: "f \<in> borel_measurable M"
```
```   713   assumes g: "g \<in> borel_measurable M"
```
```   714   shows "(\<lambda>x. f x *\<^sub>R g x) \<in> borel_measurable M"
```
```   715   using f g by (rule borel_measurable_continuous_Pair) (intro continuous_on_intros)
```
```   716
```
```   717 lemma affine_borel_measurable_vector:
```
```   718   fixes f :: "'a \<Rightarrow> 'x::real_normed_vector"
```
```   719   assumes "f \<in> borel_measurable M"
```
```   720   shows "(\<lambda>x. a + b *\<^sub>R f x) \<in> borel_measurable M"
```
```   721 proof (rule borel_measurableI)
```
```   722   fix S :: "'x set" assume "open S"
```
```   723   show "(\<lambda>x. a + b *\<^sub>R f x) -` S \<inter> space M \<in> sets M"
```
```   724   proof cases
```
```   725     assume "b \<noteq> 0"
```
```   726     with `open S` have "open ((\<lambda>x. (- a + x) /\<^sub>R b) ` S)" (is "open ?S")
```
```   727       using open_affinity [of S "inverse b" "- a /\<^sub>R b"]
```
```   728       by (auto simp: algebra_simps)
```
```   729     hence "?S \<in> sets borel" by auto
```
```   730     moreover
```
```   731     from `b \<noteq> 0` have "(\<lambda>x. a + b *\<^sub>R f x) -` S = f -` ?S"
```
```   732       apply auto by (rule_tac x="a + b *\<^sub>R f x" in image_eqI, simp_all)
```
```   733     ultimately show ?thesis using assms unfolding in_borel_measurable_borel
```
```   734       by auto
```
```   735   qed simp
```
```   736 qed
```
```   737
```
```   738 lemma borel_measurable_const_scaleR[measurable (raw)]:
```
```   739   "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. b *\<^sub>R f x ::'a::real_normed_vector) \<in> borel_measurable M"
```
```   740   using affine_borel_measurable_vector[of f M 0 b] by simp
```
```   741
```
```   742 lemma borel_measurable_const_add[measurable (raw)]:
```
```   743   "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. a + f x ::'a::real_normed_vector) \<in> borel_measurable M"
```
```   744   using affine_borel_measurable_vector[of f M a 1] by simp
```
```   745
```
```   746 lemma borel_measurable_inverse[measurable (raw)]:
```
```   747   fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_div_algebra}"
```
```   748   assumes f: "f \<in> borel_measurable M"
```
```   749   shows "(\<lambda>x. inverse (f x)) \<in> borel_measurable M"
```
```   750 proof -
```
```   751   have "(\<lambda>x::'b. if x \<in> UNIV - {0} then inverse x else inverse 0) \<in> borel_measurable borel"
```
```   752     by (intro borel_measurable_continuous_on_open' continuous_on_intros) auto
```
```   753   also have "(\<lambda>x::'b. if x \<in> UNIV - {0} then inverse x else inverse 0) = inverse"
```
```   754     by (intro ext) auto
```
```   755   finally show ?thesis using f by simp
```
```   756 qed
```
```   757
```
```   758 lemma borel_measurable_divide[measurable (raw)]:
```
```   759   "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow>
```
```   760     (\<lambda>x. f x / g x::'b::{second_countable_topology, real_normed_field}) \<in> borel_measurable M"
```
```   761   by (simp add: field_divide_inverse)
```
```   762
```
```   763 lemma borel_measurable_max[measurable (raw)]:
```
```   764   "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. max (g x) (f x) :: 'b::{second_countable_topology, dense_linorder, linorder_topology}) \<in> borel_measurable M"
```
```   765   by (simp add: max_def)
```
```   766
```
```   767 lemma borel_measurable_min[measurable (raw)]:
```
```   768   "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. min (g x) (f x) :: 'b::{second_countable_topology, dense_linorder, linorder_topology}) \<in> borel_measurable M"
```
```   769   by (simp add: min_def)
```
```   770
```
```   771 lemma borel_measurable_abs[measurable (raw)]:
```
```   772   "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. \<bar>f x :: real\<bar>) \<in> borel_measurable M"
```
```   773   unfolding abs_real_def by simp
```
```   774
```
```   775 lemma borel_measurable_nth[measurable (raw)]:
```
```   776   "(\<lambda>x::real^'n. x \$ i) \<in> borel_measurable borel"
```
```   777   by (simp add: cart_eq_inner_axis)
```
```   778
```
```   779 lemma convex_measurable:
```
```   780   fixes A :: "'a :: ordered_euclidean_space set"
```
```   781   assumes X: "X \<in> borel_measurable M" "X ` space M \<subseteq> A" "open A"
```
```   782   assumes q: "convex_on A q"
```
```   783   shows "(\<lambda>x. q (X x)) \<in> borel_measurable M"
```
```   784 proof -
```
```   785   have "(\<lambda>x. if X x \<in> A then q (X x) else 0) \<in> borel_measurable M" (is "?qX")
```
```   786   proof (rule borel_measurable_continuous_on_open[OF _ _ X(1)])
```
```   787     show "open A" by fact
```
```   788     from this q show "continuous_on A q"
```
```   789       by (rule convex_on_continuous)
```
```   790   qed
```
```   791   also have "?qX \<longleftrightarrow> (\<lambda>x. q (X x)) \<in> borel_measurable M"
```
```   792     using X by (intro measurable_cong) auto
```
```   793   finally show ?thesis .
```
```   794 qed
```
```   795
```
```   796 lemma borel_measurable_ln[measurable (raw)]:
```
```   797   assumes f: "f \<in> borel_measurable M"
```
```   798   shows "(\<lambda>x. ln (f x)) \<in> borel_measurable M"
```
```   799 proof -
```
```   800   { fix x :: real assume x: "x \<le> 0"
```
```   801     { fix x::real assume "x \<le> 0" then have "\<And>u. exp u = x \<longleftrightarrow> False" by auto }
```
```   802     from this[of x] x this[of 0] have "ln 0 = ln x"
```
```   803       by (auto simp: ln_def) }
```
```   804   note ln_imp = this
```
```   805   have "(\<lambda>x. if f x \<in> {0<..} then ln (f x) else ln 0) \<in> borel_measurable M"
```
```   806   proof (rule borel_measurable_continuous_on_open[OF _ _ f])
```
```   807     show "continuous_on {0<..} ln"
```
```   808       by (auto intro!: continuous_at_imp_continuous_on DERIV_ln DERIV_isCont)
```
```   809     show "open ({0<..}::real set)" by auto
```
```   810   qed
```
```   811   also have "(\<lambda>x. if x \<in> {0<..} then ln x else ln 0) = ln"
```
```   812     by (simp add: fun_eq_iff not_less ln_imp)
```
```   813   finally show ?thesis .
```
```   814 qed
```
```   815
```
```   816 lemma borel_measurable_log[measurable (raw)]:
```
```   817   "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. log (g x) (f x)) \<in> borel_measurable M"
```
```   818   unfolding log_def by auto
```
```   819
```
```   820 lemma borel_measurable_exp[measurable]: "exp \<in> borel_measurable borel"
```
```   821   by (intro borel_measurable_continuous_on1 continuous_at_imp_continuous_on ballI isCont_exp)
```
```   822
```
```   823 lemma measurable_count_space_eq2_countable:
```
```   824   fixes f :: "'a => 'c::countable"
```
```   825   shows "f \<in> measurable M (count_space A) \<longleftrightarrow> (f \<in> space M \<rightarrow> A \<and> (\<forall>a\<in>A. f -` {a} \<inter> space M \<in> sets M))"
```
```   826 proof -
```
```   827   { fix X assume "X \<subseteq> A" "f \<in> space M \<rightarrow> A"
```
```   828     then have "f -` X \<inter> space M = (\<Union>a\<in>X. f -` {a} \<inter> space M)"
```
```   829       by auto
```
```   830     moreover assume "\<And>a. a\<in>A \<Longrightarrow> f -` {a} \<inter> space M \<in> sets M"
```
```   831     ultimately have "f -` X \<inter> space M \<in> sets M"
```
```   832       using `X \<subseteq> A` by (simp add: subset_eq del: UN_simps) }
```
```   833   then show ?thesis
```
```   834     unfolding measurable_def by auto
```
```   835 qed
```
```   836
```
```   837 lemma measurable_real_floor[measurable]:
```
```   838   "(floor :: real \<Rightarrow> int) \<in> measurable borel (count_space UNIV)"
```
```   839 proof -
```
```   840   have "\<And>a x. \<lfloor>x\<rfloor> = a \<longleftrightarrow> (real a \<le> x \<and> x < real (a + 1))"
```
```   841     by (auto intro: floor_eq2)
```
```   842   then show ?thesis
```
```   843     by (auto simp: vimage_def measurable_count_space_eq2_countable)
```
```   844 qed
```
```   845
```
```   846 lemma measurable_real_natfloor[measurable]:
```
```   847   "(natfloor :: real \<Rightarrow> nat) \<in> measurable borel (count_space UNIV)"
```
```   848   by (simp add: natfloor_def[abs_def])
```
```   849
```
```   850 lemma measurable_real_ceiling[measurable]:
```
```   851   "(ceiling :: real \<Rightarrow> int) \<in> measurable borel (count_space UNIV)"
```
```   852   unfolding ceiling_def[abs_def] by simp
```
```   853
```
```   854 lemma borel_measurable_real_floor: "(\<lambda>x::real. real \<lfloor>x\<rfloor>) \<in> borel_measurable borel"
```
```   855   by simp
```
```   856
```
```   857 lemma borel_measurable_real_natfloor:
```
```   858   "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. real (natfloor (f x))) \<in> borel_measurable M"
```
```   859   by simp
```
```   860
```
```   861 subsection "Borel space on the extended reals"
```
```   862
```
```   863 lemma borel_measurable_ereal[measurable (raw)]:
```
```   864   assumes f: "f \<in> borel_measurable M" shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
```
```   865   using continuous_on_ereal f by (rule borel_measurable_continuous_on)
```
```   866
```
```   867 lemma borel_measurable_real_of_ereal[measurable (raw)]:
```
```   868   fixes f :: "'a \<Rightarrow> ereal"
```
```   869   assumes f: "f \<in> borel_measurable M"
```
```   870   shows "(\<lambda>x. real (f x)) \<in> borel_measurable M"
```
```   871 proof -
```
```   872   have "(\<lambda>x. if f x \<in> UNIV - { \<infinity>, - \<infinity> } then real (f x) else 0) \<in> borel_measurable M"
```
```   873     using continuous_on_real
```
```   874     by (rule borel_measurable_continuous_on_open[OF _ _ f]) auto
```
```   875   also have "(\<lambda>x. if f x \<in> UNIV - { \<infinity>, - \<infinity> } then real (f x) else 0) = (\<lambda>x. real (f x))"
```
```   876     by auto
```
```   877   finally show ?thesis .
```
```   878 qed
```
```   879
```
```   880 lemma borel_measurable_ereal_cases:
```
```   881   fixes f :: "'a \<Rightarrow> ereal"
```
```   882   assumes f: "f \<in> borel_measurable M"
```
```   883   assumes H: "(\<lambda>x. H (ereal (real (f x)))) \<in> borel_measurable M"
```
```   884   shows "(\<lambda>x. H (f x)) \<in> borel_measurable M"
```
```   885 proof -
```
```   886   let ?F = "\<lambda>x. if f x = \<infinity> then H \<infinity> else if f x = - \<infinity> then H (-\<infinity>) else H (ereal (real (f x)))"
```
```   887   { fix x have "H (f x) = ?F x" by (cases "f x") auto }
```
```   888   with f H show ?thesis by simp
```
```   889 qed
```
```   890
```
```   891 lemma
```
```   892   fixes f :: "'a \<Rightarrow> ereal" assumes f[measurable]: "f \<in> borel_measurable M"
```
```   893   shows borel_measurable_ereal_abs[measurable(raw)]: "(\<lambda>x. \<bar>f x\<bar>) \<in> borel_measurable M"
```
```   894     and borel_measurable_ereal_inverse[measurable(raw)]: "(\<lambda>x. inverse (f x) :: ereal) \<in> borel_measurable M"
```
```   895     and borel_measurable_uminus_ereal[measurable(raw)]: "(\<lambda>x. - f x :: ereal) \<in> borel_measurable M"
```
```   896   by (auto simp del: abs_real_of_ereal simp: borel_measurable_ereal_cases[OF f] measurable_If)
```
```   897
```
```   898 lemma borel_measurable_uminus_eq_ereal[simp]:
```
```   899   "(\<lambda>x. - f x :: ereal) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M" (is "?l = ?r")
```
```   900 proof
```
```   901   assume ?l from borel_measurable_uminus_ereal[OF this] show ?r by simp
```
```   902 qed auto
```
```   903
```
```   904 lemma set_Collect_ereal2:
```
```   905   fixes f g :: "'a \<Rightarrow> ereal"
```
```   906   assumes f: "f \<in> borel_measurable M"
```
```   907   assumes g: "g \<in> borel_measurable M"
```
```   908   assumes H: "{x \<in> space M. H (ereal (real (f x))) (ereal (real (g x)))} \<in> sets M"
```
```   909     "{x \<in> space borel. H (-\<infinity>) (ereal x)} \<in> sets borel"
```
```   910     "{x \<in> space borel. H (\<infinity>) (ereal x)} \<in> sets borel"
```
```   911     "{x \<in> space borel. H (ereal x) (-\<infinity>)} \<in> sets borel"
```
```   912     "{x \<in> space borel. H (ereal x) (\<infinity>)} \<in> sets borel"
```
```   913   shows "{x \<in> space M. H (f x) (g x)} \<in> sets M"
```
```   914 proof -
```
```   915   let ?G = "\<lambda>y x. if g x = \<infinity> then H y \<infinity> else if g x = -\<infinity> then H y (-\<infinity>) else H y (ereal (real (g x)))"
```
```   916   let ?F = "\<lambda>x. if f x = \<infinity> then ?G \<infinity> x else if f x = -\<infinity> then ?G (-\<infinity>) x else ?G (ereal (real (f x))) x"
```
```   917   { fix x have "H (f x) (g x) = ?F x" by (cases "f x" "g x" rule: ereal2_cases) auto }
```
```   918   note * = this
```
```   919   from assms show ?thesis
```
```   920     by (subst *) (simp del: space_borel split del: split_if)
```
```   921 qed
```
```   922
```
```   923 lemma borel_measurable_ereal_iff:
```
```   924   shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M"
```
```   925 proof
```
```   926   assume "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
```
```   927   from borel_measurable_real_of_ereal[OF this]
```
```   928   show "f \<in> borel_measurable M" by auto
```
```   929 qed auto
```
```   930
```
```   931 lemma borel_measurable_ereal_iff_real:
```
```   932   fixes f :: "'a \<Rightarrow> ereal"
```
```   933   shows "f \<in> borel_measurable M \<longleftrightarrow>
```
```   934     ((\<lambda>x. real (f x)) \<in> borel_measurable M \<and> f -` {\<infinity>} \<inter> space M \<in> sets M \<and> f -` {-\<infinity>} \<inter> space M \<in> sets M)"
```
```   935 proof safe
```
```   936   assume *: "(\<lambda>x. real (f x)) \<in> borel_measurable M" "f -` {\<infinity>} \<inter> space M \<in> sets M" "f -` {-\<infinity>} \<inter> space M \<in> sets M"
```
```   937   have "f -` {\<infinity>} \<inter> space M = {x\<in>space M. f x = \<infinity>}" "f -` {-\<infinity>} \<inter> space M = {x\<in>space M. f x = -\<infinity>}" by auto
```
```   938   with * have **: "{x\<in>space M. f x = \<infinity>} \<in> sets M" "{x\<in>space M. f x = -\<infinity>} \<in> sets M" by simp_all
```
```   939   let ?f = "\<lambda>x. if f x = \<infinity> then \<infinity> else if f x = -\<infinity> then -\<infinity> else ereal (real (f x))"
```
```   940   have "?f \<in> borel_measurable M" using * ** by (intro measurable_If) auto
```
```   941   also have "?f = f" by (auto simp: fun_eq_iff ereal_real)
```
```   942   finally show "f \<in> borel_measurable M" .
```
```   943 qed simp_all
```
```   944
```
```   945 lemma borel_measurable_eq_atMost_ereal:
```
```   946   fixes f :: "'a \<Rightarrow> ereal"
```
```   947   shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..a} \<inter> space M \<in> sets M)"
```
```   948 proof (intro iffI allI)
```
```   949   assume pos[rule_format]: "\<forall>a. f -` {..a} \<inter> space M \<in> sets M"
```
```   950   show "f \<in> borel_measurable M"
```
```   951     unfolding borel_measurable_ereal_iff_real borel_measurable_iff_le
```
```   952   proof (intro conjI allI)
```
```   953     fix a :: real
```
```   954     { fix x :: ereal assume *: "\<forall>i::nat. real i < x"
```
```   955       have "x = \<infinity>"
```
```   956       proof (rule ereal_top)
```
```   957         fix B from reals_Archimedean2[of B] guess n ..
```
```   958         then have "ereal B < real n" by auto
```
```   959         with * show "B \<le> x" by (metis less_trans less_imp_le)
```
```   960       qed }
```
```   961     then have "f -` {\<infinity>} \<inter> space M = space M - (\<Union>i::nat. f -` {.. real i} \<inter> space M)"
```
```   962       by (auto simp: not_le)
```
```   963     then show "f -` {\<infinity>} \<inter> space M \<in> sets M" using pos
```
```   964       by (auto simp del: UN_simps)
```
```   965     moreover
```
```   966     have "{-\<infinity>::ereal} = {..-\<infinity>}" by auto
```
```   967     then show "f -` {-\<infinity>} \<inter> space M \<in> sets M" using pos by auto
```
```   968     moreover have "{x\<in>space M. f x \<le> ereal a} \<in> sets M"
```
```   969       using pos[of "ereal a"] by (simp add: vimage_def Int_def conj_commute)
```
```   970     moreover have "{w \<in> space M. real (f w) \<le> a} =
```
```   971       (if a < 0 then {w \<in> space M. f w \<le> ereal a} - f -` {-\<infinity>} \<inter> space M
```
```   972       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")
```
```   973       proof (intro set_eqI) fix x show "x \<in> ?l \<longleftrightarrow> x \<in> ?r" by (cases "f x") auto qed
```
```   974     ultimately show "{w \<in> space M. real (f w) \<le> a} \<in> sets M" by auto
```
```   975   qed
```
```   976 qed (simp add: measurable_sets)
```
```   977
```
```   978 lemma borel_measurable_eq_atLeast_ereal:
```
```   979   "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a..} \<inter> space M \<in> sets M)"
```
```   980 proof
```
```   981   assume pos: "\<forall>a. f -` {a..} \<inter> space M \<in> sets M"
```
```   982   moreover have "\<And>a. (\<lambda>x. - f x) -` {..a} = f -` {-a ..}"
```
```   983     by (auto simp: ereal_uminus_le_reorder)
```
```   984   ultimately have "(\<lambda>x. - f x) \<in> borel_measurable M"
```
```   985     unfolding borel_measurable_eq_atMost_ereal by auto
```
```   986   then show "f \<in> borel_measurable M" by simp
```
```   987 qed (simp add: measurable_sets)
```
```   988
```
```   989 lemma greater_eq_le_measurable:
```
```   990   fixes f :: "'a \<Rightarrow> 'c::linorder"
```
```   991   shows "f -` {..< a} \<inter> space M \<in> sets M \<longleftrightarrow> f -` {a ..} \<inter> space M \<in> sets M"
```
```   992 proof
```
```   993   assume "f -` {a ..} \<inter> space M \<in> sets M"
```
```   994   moreover have "f -` {..< a} \<inter> space M = space M - f -` {a ..} \<inter> space M" by auto
```
```   995   ultimately show "f -` {..< a} \<inter> space M \<in> sets M" by auto
```
```   996 next
```
```   997   assume "f -` {..< a} \<inter> space M \<in> sets M"
```
```   998   moreover have "f -` {a ..} \<inter> space M = space M - f -` {..< a} \<inter> space M" by auto
```
```   999   ultimately show "f -` {a ..} \<inter> space M \<in> sets M" by auto
```
```  1000 qed
```
```  1001
```
```  1002 lemma borel_measurable_ereal_iff_less:
```
```  1003   "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..< a} \<inter> space M \<in> sets M)"
```
```  1004   unfolding borel_measurable_eq_atLeast_ereal greater_eq_le_measurable ..
```
```  1005
```
```  1006 lemma less_eq_ge_measurable:
```
```  1007   fixes f :: "'a \<Rightarrow> 'c::linorder"
```
```  1008   shows "f -` {a <..} \<inter> space M \<in> sets M \<longleftrightarrow> f -` {..a} \<inter> space M \<in> sets M"
```
```  1009 proof
```
```  1010   assume "f -` {a <..} \<inter> space M \<in> sets M"
```
```  1011   moreover have "f -` {..a} \<inter> space M = space M - f -` {a <..} \<inter> space M" by auto
```
```  1012   ultimately show "f -` {..a} \<inter> space M \<in> sets M" by auto
```
```  1013 next
```
```  1014   assume "f -` {..a} \<inter> space M \<in> sets M"
```
```  1015   moreover have "f -` {a <..} \<inter> space M = space M - f -` {..a} \<inter> space M" by auto
```
```  1016   ultimately show "f -` {a <..} \<inter> space M \<in> sets M" by auto
```
```  1017 qed
```
```  1018
```
```  1019 lemma borel_measurable_ereal_iff_ge:
```
```  1020   "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a <..} \<inter> space M \<in> sets M)"
```
```  1021   unfolding borel_measurable_eq_atMost_ereal less_eq_ge_measurable ..
```
```  1022
```
```  1023 lemma borel_measurable_ereal2:
```
```  1024   fixes f g :: "'a \<Rightarrow> ereal"
```
```  1025   assumes f: "f \<in> borel_measurable M"
```
```  1026   assumes g: "g \<in> borel_measurable M"
```
```  1027   assumes H: "(\<lambda>x. H (ereal (real (f x))) (ereal (real (g x)))) \<in> borel_measurable M"
```
```  1028     "(\<lambda>x. H (-\<infinity>) (ereal (real (g x)))) \<in> borel_measurable M"
```
```  1029     "(\<lambda>x. H (\<infinity>) (ereal (real (g x)))) \<in> borel_measurable M"
```
```  1030     "(\<lambda>x. H (ereal (real (f x))) (-\<infinity>)) \<in> borel_measurable M"
```
```  1031     "(\<lambda>x. H (ereal (real (f x))) (\<infinity>)) \<in> borel_measurable M"
```
```  1032   shows "(\<lambda>x. H (f x) (g x)) \<in> borel_measurable M"
```
```  1033 proof -
```
```  1034   let ?G = "\<lambda>y x. if g x = \<infinity> then H y \<infinity> else if g x = - \<infinity> then H y (-\<infinity>) else H y (ereal (real (g x)))"
```
```  1035   let ?F = "\<lambda>x. if f x = \<infinity> then ?G \<infinity> x else if f x = - \<infinity> then ?G (-\<infinity>) x else ?G (ereal (real (f x))) x"
```
```  1036   { fix x have "H (f x) (g x) = ?F x" by (cases "f x" "g x" rule: ereal2_cases) auto }
```
```  1037   note * = this
```
```  1038   from assms show ?thesis unfolding * by simp
```
```  1039 qed
```
```  1040
```
```  1041 lemma
```
```  1042   fixes f :: "'a \<Rightarrow> ereal" assumes f: "f \<in> borel_measurable M"
```
```  1043   shows borel_measurable_ereal_eq_const: "{x\<in>space M. f x = c} \<in> sets M"
```
```  1044     and borel_measurable_ereal_neq_const: "{x\<in>space M. f x \<noteq> c} \<in> sets M"
```
```  1045   using f by auto
```
```  1046
```
```  1047 lemma [measurable(raw)]:
```
```  1048   fixes f :: "'a \<Rightarrow> ereal"
```
```  1049   assumes [measurable]: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
```
```  1050   shows borel_measurable_ereal_add: "(\<lambda>x. f x + g x) \<in> borel_measurable M"
```
```  1051     and borel_measurable_ereal_times: "(\<lambda>x. f x * g x) \<in> borel_measurable M"
```
```  1052     and borel_measurable_ereal_min: "(\<lambda>x. min (g x) (f x)) \<in> borel_measurable M"
```
```  1053     and borel_measurable_ereal_max: "(\<lambda>x. max (g x) (f x)) \<in> borel_measurable M"
```
```  1054   by (simp_all add: borel_measurable_ereal2 min_def max_def)
```
```  1055
```
```  1056 lemma [measurable(raw)]:
```
```  1057   fixes f g :: "'a \<Rightarrow> ereal"
```
```  1058   assumes "f \<in> borel_measurable M"
```
```  1059   assumes "g \<in> borel_measurable M"
```
```  1060   shows borel_measurable_ereal_diff: "(\<lambda>x. f x - g x) \<in> borel_measurable M"
```
```  1061     and borel_measurable_ereal_divide: "(\<lambda>x. f x / g x) \<in> borel_measurable M"
```
```  1062   using assms by (simp_all add: minus_ereal_def divide_ereal_def)
```
```  1063
```
```  1064 lemma borel_measurable_ereal_setsum[measurable (raw)]:
```
```  1065   fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
```
```  1066   assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
```
```  1067   shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
```
```  1068 proof cases
```
```  1069   assume "finite S"
```
```  1070   thus ?thesis using assms
```
```  1071     by induct auto
```
```  1072 qed simp
```
```  1073
```
```  1074 lemma borel_measurable_ereal_setprod[measurable (raw)]:
```
```  1075   fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
```
```  1076   assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
```
```  1077   shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
```
```  1078 proof cases
```
```  1079   assume "finite S"
```
```  1080   thus ?thesis using assms by induct auto
```
```  1081 qed simp
```
```  1082
```
```  1083 lemma borel_measurable_SUP[measurable (raw)]:
```
```  1084   fixes f :: "'d\<Colon>countable \<Rightarrow> 'a \<Rightarrow> ereal"
```
```  1085   assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<in> borel_measurable M"
```
```  1086   shows "(\<lambda>x. SUP i : A. f i x) \<in> borel_measurable M" (is "?sup \<in> borel_measurable M")
```
```  1087   unfolding borel_measurable_ereal_iff_ge
```
```  1088 proof
```
```  1089   fix a
```
```  1090   have "?sup -` {a<..} \<inter> space M = (\<Union>i\<in>A. {x\<in>space M. a < f i x})"
```
```  1091     by (auto simp: less_SUP_iff)
```
```  1092   then show "?sup -` {a<..} \<inter> space M \<in> sets M"
```
```  1093     using assms by auto
```
```  1094 qed
```
```  1095
```
```  1096 lemma borel_measurable_INF[measurable (raw)]:
```
```  1097   fixes f :: "'d :: countable \<Rightarrow> 'a \<Rightarrow> ereal"
```
```  1098   assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<in> borel_measurable M"
```
```  1099   shows "(\<lambda>x. INF i : A. f i x) \<in> borel_measurable M" (is "?inf \<in> borel_measurable M")
```
```  1100   unfolding borel_measurable_ereal_iff_less
```
```  1101 proof
```
```  1102   fix a
```
```  1103   have "?inf -` {..<a} \<inter> space M = (\<Union>i\<in>A. {x\<in>space M. f i x < a})"
```
```  1104     by (auto simp: INF_less_iff)
```
```  1105   then show "?inf -` {..<a} \<inter> space M \<in> sets M"
```
```  1106     using assms by auto
```
```  1107 qed
```
```  1108
```
```  1109 lemma [measurable (raw)]:
```
```  1110   fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
```
```  1111   assumes "\<And>i. f i \<in> borel_measurable M"
```
```  1112   shows borel_measurable_liminf: "(\<lambda>x. liminf (\<lambda>i. f i x)) \<in> borel_measurable M"
```
```  1113     and borel_measurable_limsup: "(\<lambda>x. limsup (\<lambda>i. f i x)) \<in> borel_measurable M"
```
```  1114   unfolding liminf_SUP_INF limsup_INF_SUP using assms by auto
```
```  1115
```
```  1116 lemma sets_Collect_eventually_sequentially[measurable]:
```
```  1117   "(\<And>i. {x\<in>space M. P x i} \<in> sets M) \<Longrightarrow> {x\<in>space M. eventually (P x) sequentially} \<in> sets M"
```
```  1118   unfolding eventually_sequentially by simp
```
```  1119
```
```  1120 lemma sets_Collect_ereal_convergent[measurable]:
```
```  1121   fixes f :: "nat \<Rightarrow> 'a => ereal"
```
```  1122   assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
```
```  1123   shows "{x\<in>space M. convergent (\<lambda>i. f i x)} \<in> sets M"
```
```  1124   unfolding convergent_ereal by auto
```
```  1125
```
```  1126 lemma borel_measurable_extreal_lim[measurable (raw)]:
```
```  1127   fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
```
```  1128   assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
```
```  1129   shows "(\<lambda>x. lim (\<lambda>i. f i x)) \<in> borel_measurable M"
```
```  1130 proof -
```
```  1131   have "\<And>x. lim (\<lambda>i. f i x) = (if convergent (\<lambda>i. f i x) then limsup (\<lambda>i. f i x) else (THE i. False))"
```
```  1132     by (simp add: lim_def convergent_def convergent_limsup_cl)
```
```  1133   then show ?thesis
```
```  1134     by simp
```
```  1135 qed
```
```  1136
```
```  1137 lemma borel_measurable_ereal_LIMSEQ:
```
```  1138   fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
```
```  1139   assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) ----> u' x"
```
```  1140   and u: "\<And>i. u i \<in> borel_measurable M"
```
```  1141   shows "u' \<in> borel_measurable M"
```
```  1142 proof -
```
```  1143   have "\<And>x. x \<in> space M \<Longrightarrow> u' x = liminf (\<lambda>n. u n x)"
```
```  1144     using u' by (simp add: lim_imp_Liminf[symmetric])
```
```  1145   with u show ?thesis by (simp cong: measurable_cong)
```
```  1146 qed
```
```  1147
```
```  1148 lemma borel_measurable_extreal_suminf[measurable (raw)]:
```
```  1149   fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
```
```  1150   assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
```
```  1151   shows "(\<lambda>x. (\<Sum>i. f i x)) \<in> borel_measurable M"
```
```  1152   unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
```
```  1153
```
```  1154 section "LIMSEQ is borel measurable"
```
```  1155
```
```  1156 lemma borel_measurable_LIMSEQ:
```
```  1157   fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> real"
```
```  1158   assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) ----> u' x"
```
```  1159   and u: "\<And>i. u i \<in> borel_measurable M"
```
```  1160   shows "u' \<in> borel_measurable M"
```
```  1161 proof -
```
```  1162   have "\<And>x. x \<in> space M \<Longrightarrow> liminf (\<lambda>n. ereal (u n x)) = ereal (u' x)"
```
```  1163     using u' by (simp add: lim_imp_Liminf)
```
```  1164   moreover from u have "(\<lambda>x. liminf (\<lambda>n. ereal (u n x))) \<in> borel_measurable M"
```
```  1165     by auto
```
```  1166   ultimately show ?thesis by (simp cong: measurable_cong add: borel_measurable_ereal_iff)
```
```  1167 qed
```
```  1168
```
```  1169 lemma sets_Collect_Cauchy[measurable]:
```
```  1170   fixes f :: "nat \<Rightarrow> 'a => real"
```
```  1171   assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
```
```  1172   shows "{x\<in>space M. Cauchy (\<lambda>i. f i x)} \<in> sets M"
```
```  1173   unfolding Cauchy_iff2 using f by auto
```
```  1174
```
```  1175 lemma borel_measurable_lim[measurable (raw)]:
```
```  1176   fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> real"
```
```  1177   assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
```
```  1178   shows "(\<lambda>x. lim (\<lambda>i. f i x)) \<in> borel_measurable M"
```
```  1179 proof -
```
```  1180   def u' \<equiv> "\<lambda>x. lim (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
```
```  1181   then have *: "\<And>x. lim (\<lambda>i. f i x) = (if Cauchy (\<lambda>i. f i x) then u' x else (THE x. False))"
```
```  1182     by (auto simp: lim_def convergent_eq_cauchy[symmetric])
```
```  1183   have "u' \<in> borel_measurable M"
```
```  1184   proof (rule borel_measurable_LIMSEQ)
```
```  1185     fix x
```
```  1186     have "convergent (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
```
```  1187       by (cases "Cauchy (\<lambda>i. f i x)")
```
```  1188          (auto simp add: convergent_eq_cauchy[symmetric] convergent_def)
```
```  1189     then show "(\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0) ----> u' x"
```
```  1190       unfolding u'_def
```
```  1191       by (rule convergent_LIMSEQ_iff[THEN iffD1])
```
```  1192   qed measurable
```
```  1193   then show ?thesis
```
```  1194     unfolding * by measurable
```
```  1195 qed
```
```  1196
```
```  1197 lemma borel_measurable_suminf[measurable (raw)]:
```
```  1198   fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> real"
```
```  1199   assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
```
```  1200   shows "(\<lambda>x. suminf (\<lambda>i. f i x)) \<in> borel_measurable M"
```
```  1201   unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
```
```  1202
```
```  1203 no_notation
```
```  1204   eucl_less (infix "<e" 50)
```
```  1205
```
```  1206 end
```