src/HOL/Probability/Probability_Space.thy
author hoelzl
Tue Mar 22 18:53:05 2011 +0100 (2011-03-22)
changeset 42066 6db76c88907a
parent 41981 cdf7693bbe08
child 42067 66c8281349ec
permissions -rw-r--r--
generalized Caratheodory from algebra to ring_of_sets
hoelzl@35582
     1
theory Probability_Space
hoelzl@40859
     2
imports Lebesgue_Integration Radon_Nikodym Product_Measure
hoelzl@35582
     3
begin
hoelzl@35582
     4
hoelzl@41981
     5
lemma real_of_extreal_inverse[simp]:
hoelzl@41981
     6
  fixes X :: extreal
hoelzl@40859
     7
  shows "real (inverse X) = 1 / real X"
hoelzl@40859
     8
  by (cases X) (auto simp: inverse_eq_divide)
hoelzl@40859
     9
hoelzl@41981
    10
lemma real_of_extreal_le_0[simp]: "real (X :: extreal) \<le> 0 \<longleftrightarrow> (X \<le> 0 \<or> X = \<infinity>)"
hoelzl@41981
    11
  by (cases X) auto
hoelzl@41981
    12
hoelzl@41981
    13
lemma abs_real_of_extreal[simp]: "\<bar>real (X :: extreal)\<bar> = real \<bar>X\<bar>"
hoelzl@40859
    14
  by (cases X) auto
hoelzl@40859
    15
hoelzl@41981
    16
lemma zero_less_real_of_extreal: "0 < real X \<longleftrightarrow> (0 < X \<and> X \<noteq> \<infinity>)"
hoelzl@40859
    17
  by (cases X) auto
hoelzl@40859
    18
hoelzl@41981
    19
lemma real_of_extreal_le_1: fixes X :: extreal shows "X \<le> 1 \<Longrightarrow> real X \<le> 1"
hoelzl@41981
    20
  by (cases X) (auto simp: one_extreal_def)
hoelzl@41981
    21
hoelzl@35582
    22
locale prob_space = measure_space +
hoelzl@41689
    23
  assumes measure_space_1: "measure M (space M) = 1"
hoelzl@38656
    24
hoelzl@38656
    25
sublocale prob_space < finite_measure
hoelzl@38656
    26
proof
hoelzl@41981
    27
  from measure_space_1 show "\<mu> (space M) \<noteq> \<infinity>" by simp
hoelzl@38656
    28
qed
hoelzl@38656
    29
hoelzl@40859
    30
abbreviation (in prob_space) "events \<equiv> sets M"
hoelzl@41981
    31
abbreviation (in prob_space) "prob \<equiv> \<mu>'"
hoelzl@40859
    32
abbreviation (in prob_space) "prob_preserving \<equiv> measure_preserving"
hoelzl@40859
    33
abbreviation (in prob_space) "random_variable M' X \<equiv> sigma_algebra M' \<and> X \<in> measurable M M'"
hoelzl@41689
    34
abbreviation (in prob_space) "expectation \<equiv> integral\<^isup>L M"
hoelzl@35582
    35
hoelzl@40859
    36
definition (in prob_space)
hoelzl@35582
    37
  "indep A B \<longleftrightarrow> A \<in> events \<and> B \<in> events \<and> prob (A \<inter> B) = prob A * prob B"
hoelzl@35582
    38
hoelzl@40859
    39
definition (in prob_space)
hoelzl@35582
    40
  "indep_families F G \<longleftrightarrow> (\<forall> A \<in> F. \<forall> B \<in> G. indep A B)"
hoelzl@35582
    41
hoelzl@40859
    42
definition (in prob_space)
hoelzl@41981
    43
  "distribution X A = \<mu>' (X -` A \<inter> space M)"
hoelzl@35582
    44
hoelzl@40859
    45
abbreviation (in prob_space)
hoelzl@36624
    46
  "joint_distribution X Y \<equiv> distribution (\<lambda>x. (X x, Y x))"
hoelzl@35582
    47
hoelzl@41981
    48
declare (in finite_measure) positive_measure'[intro, simp]
hoelzl@41981
    49
hoelzl@39097
    50
lemma (in prob_space) distribution_cong:
hoelzl@39097
    51
  assumes "\<And>x. x \<in> space M \<Longrightarrow> X x = Y x"
hoelzl@39097
    52
  shows "distribution X = distribution Y"
nipkow@39302
    53
  unfolding distribution_def fun_eq_iff
hoelzl@41981
    54
  using assms by (auto intro!: arg_cong[where f="\<mu>'"])
hoelzl@39097
    55
hoelzl@39097
    56
lemma (in prob_space) joint_distribution_cong:
hoelzl@39097
    57
  assumes "\<And>x. x \<in> space M \<Longrightarrow> X x = X' x"
hoelzl@39097
    58
  assumes "\<And>x. x \<in> space M \<Longrightarrow> Y x = Y' x"
hoelzl@39097
    59
  shows "joint_distribution X Y = joint_distribution X' Y'"
nipkow@39302
    60
  unfolding distribution_def fun_eq_iff
hoelzl@41981
    61
  using assms by (auto intro!: arg_cong[where f="\<mu>'"])
hoelzl@39097
    62
hoelzl@40859
    63
lemma (in prob_space) distribution_id[simp]:
hoelzl@41981
    64
  "N \<in> events \<Longrightarrow> distribution (\<lambda>x. x) N = prob N"
hoelzl@41981
    65
  by (auto simp: distribution_def intro!: arg_cong[where f=prob])
hoelzl@40859
    66
hoelzl@40859
    67
lemma (in prob_space) prob_space: "prob (space M) = 1"
hoelzl@41981
    68
  using measure_space_1 unfolding \<mu>'_def by (simp add: one_extreal_def)
hoelzl@41981
    69
hoelzl@41981
    70
lemma (in prob_space) prob_le_1[simp, intro]: "prob A \<le> 1"
hoelzl@41981
    71
  using bounded_measure[of A] by (simp add: prob_space)
hoelzl@41981
    72
hoelzl@41981
    73
lemma (in prob_space) distribution_positive[simp, intro]:
hoelzl@41981
    74
  "0 \<le> distribution X A" unfolding distribution_def by auto
hoelzl@35582
    75
hoelzl@41981
    76
lemma (in prob_space) joint_distribution_remove[simp]:
hoelzl@41981
    77
    "joint_distribution X X {(x, x)} = distribution X {x}"
hoelzl@41981
    78
  unfolding distribution_def by (auto intro!: arg_cong[where f=\<mu>'])
hoelzl@41981
    79
hoelzl@41981
    80
lemma (in prob_space) distribution_1:
hoelzl@41981
    81
  "distribution X A \<le> 1"
hoelzl@41981
    82
  unfolding distribution_def by simp
hoelzl@35582
    83
hoelzl@40859
    84
lemma (in prob_space) prob_compl:
hoelzl@41981
    85
  assumes A: "A \<in> events"
hoelzl@38656
    86
  shows "prob (space M - A) = 1 - prob A"
hoelzl@41981
    87
  using finite_measure_compl[OF A] by (simp add: prob_space)
hoelzl@35582
    88
hoelzl@41981
    89
lemma (in prob_space) indep_space: "s \<in> events \<Longrightarrow> indep (space M) s"
hoelzl@41981
    90
  by (simp add: indep_def prob_space)
hoelzl@35582
    91
hoelzl@40859
    92
lemma (in prob_space) prob_space_increasing: "increasing M prob"
hoelzl@41981
    93
  by (auto intro!: finite_measure_mono simp: increasing_def)
hoelzl@35582
    94
hoelzl@40859
    95
lemma (in prob_space) prob_zero_union:
hoelzl@35582
    96
  assumes "s \<in> events" "t \<in> events" "prob t = 0"
hoelzl@35582
    97
  shows "prob (s \<union> t) = prob s"
hoelzl@38656
    98
using assms
hoelzl@35582
    99
proof -
hoelzl@35582
   100
  have "prob (s \<union> t) \<le> prob s"
hoelzl@41981
   101
    using finite_measure_subadditive[of s t] assms by auto
hoelzl@35582
   102
  moreover have "prob (s \<union> t) \<ge> prob s"
hoelzl@41981
   103
    using assms by (blast intro: finite_measure_mono)
hoelzl@35582
   104
  ultimately show ?thesis by simp
hoelzl@35582
   105
qed
hoelzl@35582
   106
hoelzl@40859
   107
lemma (in prob_space) prob_eq_compl:
hoelzl@35582
   108
  assumes "s \<in> events" "t \<in> events"
hoelzl@35582
   109
  assumes "prob (space M - s) = prob (space M - t)"
hoelzl@35582
   110
  shows "prob s = prob t"
hoelzl@38656
   111
  using assms prob_compl by auto
hoelzl@35582
   112
hoelzl@40859
   113
lemma (in prob_space) prob_one_inter:
hoelzl@35582
   114
  assumes events:"s \<in> events" "t \<in> events"
hoelzl@35582
   115
  assumes "prob t = 1"
hoelzl@35582
   116
  shows "prob (s \<inter> t) = prob s"
hoelzl@35582
   117
proof -
hoelzl@38656
   118
  have "prob ((space M - s) \<union> (space M - t)) = prob (space M - s)"
hoelzl@38656
   119
    using events assms  prob_compl[of "t"] by (auto intro!: prob_zero_union)
hoelzl@38656
   120
  also have "(space M - s) \<union> (space M - t) = space M - (s \<inter> t)"
hoelzl@38656
   121
    by blast
hoelzl@38656
   122
  finally show "prob (s \<inter> t) = prob s"
hoelzl@38656
   123
    using events by (auto intro!: prob_eq_compl[of "s \<inter> t" s])
hoelzl@35582
   124
qed
hoelzl@35582
   125
hoelzl@40859
   126
lemma (in prob_space) prob_eq_bigunion_image:
hoelzl@35582
   127
  assumes "range f \<subseteq> events" "range g \<subseteq> events"
hoelzl@35582
   128
  assumes "disjoint_family f" "disjoint_family g"
hoelzl@35582
   129
  assumes "\<And> n :: nat. prob (f n) = prob (g n)"
hoelzl@35582
   130
  shows "(prob (\<Union> i. f i) = prob (\<Union> i. g i))"
hoelzl@35582
   131
using assms
hoelzl@35582
   132
proof -
hoelzl@38656
   133
  have a: "(\<lambda> i. prob (f i)) sums (prob (\<Union> i. f i))"
hoelzl@41981
   134
    by (rule finite_measure_UNION[OF assms(1,3)])
hoelzl@38656
   135
  have b: "(\<lambda> i. prob (g i)) sums (prob (\<Union> i. g i))"
hoelzl@41981
   136
    by (rule finite_measure_UNION[OF assms(2,4)])
hoelzl@38656
   137
  show ?thesis using sums_unique[OF b] sums_unique[OF a] assms by simp
hoelzl@35582
   138
qed
hoelzl@35582
   139
hoelzl@40859
   140
lemma (in prob_space) prob_countably_zero:
hoelzl@35582
   141
  assumes "range c \<subseteq> events"
hoelzl@35582
   142
  assumes "\<And> i. prob (c i) = 0"
hoelzl@38656
   143
  shows "prob (\<Union> i :: nat. c i) = 0"
hoelzl@38656
   144
proof (rule antisym)
hoelzl@38656
   145
  show "prob (\<Union> i :: nat. c i) \<le> 0"
hoelzl@41981
   146
    using finite_measure_countably_subadditive[OF assms(1)]
hoelzl@38656
   147
    by (simp add: assms(2) suminf_zero summable_zero)
hoelzl@41981
   148
qed simp
hoelzl@35582
   149
hoelzl@40859
   150
lemma (in prob_space) indep_sym:
hoelzl@35582
   151
   "indep a b \<Longrightarrow> indep b a"
hoelzl@35582
   152
unfolding indep_def using Int_commute[of a b] by auto
hoelzl@35582
   153
hoelzl@40859
   154
lemma (in prob_space) indep_refl:
hoelzl@35582
   155
  assumes "a \<in> events"
hoelzl@35582
   156
  shows "indep a a = (prob a = 0) \<or> (prob a = 1)"
hoelzl@35582
   157
using assms unfolding indep_def by auto
hoelzl@35582
   158
hoelzl@40859
   159
lemma (in prob_space) prob_equiprobable_finite_unions:
hoelzl@38656
   160
  assumes "s \<in> events"
hoelzl@38656
   161
  assumes s_finite: "finite s" "\<And>x. x \<in> s \<Longrightarrow> {x} \<in> events"
hoelzl@35582
   162
  assumes "\<And> x y. \<lbrakk>x \<in> s; y \<in> s\<rbrakk> \<Longrightarrow> (prob {x} = prob {y})"
hoelzl@38656
   163
  shows "prob s = real (card s) * prob {SOME x. x \<in> s}"
hoelzl@35582
   164
proof (cases "s = {}")
hoelzl@38656
   165
  case False hence "\<exists> x. x \<in> s" by blast
hoelzl@35582
   166
  from someI_ex[OF this] assms
hoelzl@35582
   167
  have prob_some: "\<And> x. x \<in> s \<Longrightarrow> prob {x} = prob {SOME y. y \<in> s}" by blast
hoelzl@35582
   168
  have "prob s = (\<Sum> x \<in> s. prob {x})"
hoelzl@41981
   169
    using finite_measure_finite_singleton[OF s_finite] by simp
hoelzl@35582
   170
  also have "\<dots> = (\<Sum> x \<in> s. prob {SOME y. y \<in> s})" using prob_some by auto
hoelzl@38656
   171
  also have "\<dots> = real (card s) * prob {(SOME x. x \<in> s)}"
hoelzl@38656
   172
    using setsum_constant assms by (simp add: real_eq_of_nat)
hoelzl@35582
   173
  finally show ?thesis by simp
hoelzl@38656
   174
qed simp
hoelzl@35582
   175
hoelzl@40859
   176
lemma (in prob_space) prob_real_sum_image_fn:
hoelzl@35582
   177
  assumes "e \<in> events"
hoelzl@35582
   178
  assumes "\<And> x. x \<in> s \<Longrightarrow> e \<inter> f x \<in> events"
hoelzl@35582
   179
  assumes "finite s"
hoelzl@38656
   180
  assumes disjoint: "\<And> x y. \<lbrakk>x \<in> s ; y \<in> s ; x \<noteq> y\<rbrakk> \<Longrightarrow> f x \<inter> f y = {}"
hoelzl@38656
   181
  assumes upper: "space M \<subseteq> (\<Union> i \<in> s. f i)"
hoelzl@35582
   182
  shows "prob e = (\<Sum> x \<in> s. prob (e \<inter> f x))"
hoelzl@35582
   183
proof -
hoelzl@38656
   184
  have e: "e = (\<Union> i \<in> s. e \<inter> f i)"
hoelzl@38656
   185
    using `e \<in> events` sets_into_space upper by blast
hoelzl@38656
   186
  hence "prob e = prob (\<Union> i \<in> s. e \<inter> f i)" by simp
hoelzl@38656
   187
  also have "\<dots> = (\<Sum> x \<in> s. prob (e \<inter> f x))"
hoelzl@41981
   188
  proof (rule finite_measure_finite_Union)
hoelzl@38656
   189
    show "finite s" by fact
hoelzl@38656
   190
    show "\<And>i. i \<in> s \<Longrightarrow> e \<inter> f i \<in> events" by fact
hoelzl@38656
   191
    show "disjoint_family_on (\<lambda>i. e \<inter> f i) s"
hoelzl@38656
   192
      using disjoint by (auto simp: disjoint_family_on_def)
hoelzl@38656
   193
  qed
hoelzl@38656
   194
  finally show ?thesis .
hoelzl@35582
   195
qed
hoelzl@35582
   196
hoelzl@40859
   197
lemma (in prob_space) distribution_prob_space:
hoelzl@40859
   198
  assumes "random_variable S X"
hoelzl@41981
   199
  shows "prob_space (S\<lparr>measure := extreal \<circ> distribution X\<rparr>)"
hoelzl@35582
   200
proof -
hoelzl@41981
   201
  interpret S: measure_space "S\<lparr>measure := extreal \<circ> distribution X\<rparr>"
hoelzl@41981
   202
  proof (rule measure_space.measure_space_cong)
hoelzl@41981
   203
    show "measure_space (S\<lparr> measure := \<lambda>A. \<mu> (X -` A \<inter> space M) \<rparr>)"
hoelzl@41981
   204
      using assms by (auto intro!: measure_space_vimage simp: measure_preserving_def)
hoelzl@41981
   205
  qed (insert assms, auto simp add: finite_measure_eq distribution_def measurable_sets)
hoelzl@38656
   206
  show ?thesis
hoelzl@41689
   207
  proof (default, simp)
hoelzl@38656
   208
    have "X -` space S \<inter> space M = space M"
hoelzl@38656
   209
      using `random_variable S X` by (auto simp: measurable_def)
hoelzl@41981
   210
    then show "extreal (distribution X (space S)) = 1"
hoelzl@41981
   211
      by (simp add: distribution_def one_extreal_def prob_space)
hoelzl@35582
   212
  qed
hoelzl@35582
   213
qed
hoelzl@35582
   214
hoelzl@40859
   215
lemma (in prob_space) AE_distribution:
hoelzl@41981
   216
  assumes X: "random_variable MX X" and "AE x in MX\<lparr>measure := extreal \<circ> distribution X\<rparr>. Q x"
hoelzl@40859
   217
  shows "AE x. Q (X x)"
hoelzl@40859
   218
proof -
hoelzl@41981
   219
  interpret X: prob_space "MX\<lparr>measure := extreal \<circ> distribution X\<rparr>" using X by (rule distribution_prob_space)
hoelzl@40859
   220
  obtain N where N: "N \<in> sets MX" "distribution X N = 0" "{x\<in>space MX. \<not> Q x} \<subseteq> N"
hoelzl@40859
   221
    using assms unfolding X.almost_everywhere_def by auto
hoelzl@41981
   222
  from X[unfolded measurable_def] N show "AE x. Q (X x)"
hoelzl@41981
   223
    by (intro AE_I'[where N="X -` N \<inter> space M"])
hoelzl@41981
   224
       (auto simp: finite_measure_eq distribution_def measurable_sets)
hoelzl@40859
   225
qed
hoelzl@40859
   226
hoelzl@41981
   227
lemma (in prob_space) distribution_eq_integral:
hoelzl@41981
   228
  "random_variable S X \<Longrightarrow> A \<in> sets S \<Longrightarrow> distribution X A = expectation (indicator (X -` A \<inter> space M))"
hoelzl@41981
   229
  using finite_measure_eq[of "X -` A \<inter> space M"]
hoelzl@41981
   230
  by (auto simp: measurable_sets distribution_def)
hoelzl@35582
   231
hoelzl@41981
   232
lemma (in prob_space) distribution_eq_translated_integral:
hoelzl@41981
   233
  assumes "random_variable S X" "A \<in> sets S"
hoelzl@41981
   234
  shows "distribution X A = integral\<^isup>P (S\<lparr>measure := extreal \<circ> distribution X\<rparr>) (indicator A)"
hoelzl@35582
   235
proof -
hoelzl@41981
   236
  interpret S: prob_space "S\<lparr>measure := extreal \<circ> distribution X\<rparr>"
hoelzl@41689
   237
    using assms(1) by (rule distribution_prob_space)
hoelzl@35582
   238
  show ?thesis
hoelzl@41981
   239
    using S.positive_integral_indicator(1)[of A] assms by simp
hoelzl@35582
   240
qed
hoelzl@35582
   241
hoelzl@40859
   242
lemma (in prob_space) finite_expectation1:
hoelzl@40859
   243
  assumes f: "finite (X`space M)" and rv: "random_variable borel X"
hoelzl@41981
   244
  shows "expectation X = (\<Sum>r \<in> X ` space M. r * prob (X -` {r} \<inter> space M))" (is "_ = ?r")
hoelzl@41981
   245
proof (subst integral_on_finite)
hoelzl@41981
   246
  show "X \<in> borel_measurable M" "finite (X`space M)" using assms by auto
hoelzl@41981
   247
  show "(\<Sum> r \<in> X ` space M. r * real (\<mu> (X -` {r} \<inter> space M))) = ?r"
hoelzl@41981
   248
    "\<And>x. \<mu> (X -` {x} \<inter> space M) \<noteq> \<infinity>"
hoelzl@41981
   249
    using finite_measure_eq[OF borel_measurable_vimage, of X] rv by auto
hoelzl@38656
   250
qed
hoelzl@35582
   251
hoelzl@40859
   252
lemma (in prob_space) finite_expectation:
hoelzl@41689
   253
  assumes "finite (X`space M)" "random_variable borel X"
hoelzl@41981
   254
  shows "expectation X = (\<Sum> r \<in> X ` (space M). r * distribution X {r})"
hoelzl@38656
   255
  using assms unfolding distribution_def using finite_expectation1 by auto
hoelzl@38656
   256
hoelzl@40859
   257
lemma (in prob_space) prob_x_eq_1_imp_prob_y_eq_0:
hoelzl@35582
   258
  assumes "{x} \<in> events"
hoelzl@38656
   259
  assumes "prob {x} = 1"
hoelzl@35582
   260
  assumes "{y} \<in> events"
hoelzl@35582
   261
  assumes "y \<noteq> x"
hoelzl@35582
   262
  shows "prob {y} = 0"
hoelzl@35582
   263
  using prob_one_inter[of "{y}" "{x}"] assms by auto
hoelzl@35582
   264
hoelzl@40859
   265
lemma (in prob_space) distribution_empty[simp]: "distribution X {} = 0"
hoelzl@38656
   266
  unfolding distribution_def by simp
hoelzl@38656
   267
hoelzl@40859
   268
lemma (in prob_space) distribution_space[simp]: "distribution X (X ` space M) = 1"
hoelzl@38656
   269
proof -
hoelzl@38656
   270
  have "X -` X ` space M \<inter> space M = space M" by auto
hoelzl@41981
   271
  thus ?thesis unfolding distribution_def by (simp add: prob_space)
hoelzl@38656
   272
qed
hoelzl@38656
   273
hoelzl@40859
   274
lemma (in prob_space) distribution_one:
hoelzl@40859
   275
  assumes "random_variable M' X" and "A \<in> sets M'"
hoelzl@38656
   276
  shows "distribution X A \<le> 1"
hoelzl@38656
   277
proof -
hoelzl@41981
   278
  have "distribution X A \<le> \<mu>' (space M)" unfolding distribution_def
hoelzl@41981
   279
    using assms[unfolded measurable_def] by (auto intro!: finite_measure_mono)
hoelzl@41981
   280
  thus ?thesis by (simp add: prob_space)
hoelzl@38656
   281
qed
hoelzl@38656
   282
hoelzl@40859
   283
lemma (in prob_space) distribution_x_eq_1_imp_distribution_y_eq_0:
hoelzl@35582
   284
  assumes X: "random_variable \<lparr>space = X ` (space M), sets = Pow (X ` (space M))\<rparr> X"
hoelzl@38656
   285
    (is "random_variable ?S X")
hoelzl@38656
   286
  assumes "distribution X {x} = 1"
hoelzl@35582
   287
  assumes "y \<noteq> x"
hoelzl@35582
   288
  shows "distribution X {y} = 0"
hoelzl@41689
   289
proof cases
hoelzl@41689
   290
  { fix x have "X -` {x} \<inter> space M \<in> sets M"
hoelzl@41689
   291
    proof cases
hoelzl@41689
   292
      assume "x \<in> X`space M" with X show ?thesis
hoelzl@41689
   293
        by (auto simp: measurable_def image_iff)
hoelzl@41689
   294
    next
hoelzl@41689
   295
      assume "x \<notin> X`space M" then have "X -` {x} \<inter> space M = {}" by auto
hoelzl@41689
   296
      then show ?thesis by auto
hoelzl@41689
   297
    qed } note single = this
hoelzl@41689
   298
  have "X -` {x} \<inter> space M - X -` {y} \<inter> space M = X -` {x} \<inter> space M"
hoelzl@41689
   299
    "X -` {y} \<inter> space M \<inter> (X -` {x} \<inter> space M) = {}"
hoelzl@41689
   300
    using `y \<noteq> x` by auto
hoelzl@41981
   301
  with finite_measure_inter_full_set[OF single single, of x y] assms(2)
hoelzl@41981
   302
  show ?thesis by (auto simp: distribution_def prob_space)
hoelzl@41689
   303
next
hoelzl@41689
   304
  assume "{y} \<notin> sets ?S"
hoelzl@41689
   305
  then have "X -` {y} \<inter> space M = {}" by auto
hoelzl@41689
   306
  thus "distribution X {y} = 0" unfolding distribution_def by auto
hoelzl@35582
   307
qed
hoelzl@35582
   308
hoelzl@40859
   309
lemma (in prob_space) joint_distribution_Times_le_fst:
hoelzl@40859
   310
  assumes X: "random_variable MX X" and Y: "random_variable MY Y"
hoelzl@40859
   311
    and A: "A \<in> sets MX" and B: "B \<in> sets MY"
hoelzl@40859
   312
  shows "joint_distribution X Y (A \<times> B) \<le> distribution X A"
hoelzl@40859
   313
  unfolding distribution_def
hoelzl@41981
   314
proof (intro finite_measure_mono)
hoelzl@40859
   315
  show "(\<lambda>x. (X x, Y x)) -` (A \<times> B) \<inter> space M \<subseteq> X -` A \<inter> space M" by force
hoelzl@40859
   316
  show "X -` A \<inter> space M \<in> events"
hoelzl@40859
   317
    using X A unfolding measurable_def by simp
hoelzl@40859
   318
  have *: "(\<lambda>x. (X x, Y x)) -` (A \<times> B) \<inter> space M =
hoelzl@40859
   319
    (X -` A \<inter> space M) \<inter> (Y -` B \<inter> space M)" by auto
hoelzl@40859
   320
qed
hoelzl@40859
   321
hoelzl@40859
   322
lemma (in prob_space) joint_distribution_commute:
hoelzl@40859
   323
  "joint_distribution X Y x = joint_distribution Y X ((\<lambda>(x,y). (y,x))`x)"
hoelzl@41981
   324
  unfolding distribution_def by (auto intro!: arg_cong[where f=\<mu>'])
hoelzl@40859
   325
hoelzl@40859
   326
lemma (in prob_space) joint_distribution_Times_le_snd:
hoelzl@40859
   327
  assumes X: "random_variable MX X" and Y: "random_variable MY Y"
hoelzl@40859
   328
    and A: "A \<in> sets MX" and B: "B \<in> sets MY"
hoelzl@40859
   329
  shows "joint_distribution X Y (A \<times> B) \<le> distribution Y B"
hoelzl@40859
   330
  using assms
hoelzl@40859
   331
  by (subst joint_distribution_commute)
hoelzl@40859
   332
     (simp add: swap_product joint_distribution_Times_le_fst)
hoelzl@40859
   333
hoelzl@40859
   334
lemma (in prob_space) random_variable_pairI:
hoelzl@40859
   335
  assumes "random_variable MX X"
hoelzl@40859
   336
  assumes "random_variable MY Y"
hoelzl@41689
   337
  shows "random_variable (MX \<Otimes>\<^isub>M MY) (\<lambda>x. (X x, Y x))"
hoelzl@40859
   338
proof
hoelzl@40859
   339
  interpret MX: sigma_algebra MX using assms by simp
hoelzl@40859
   340
  interpret MY: sigma_algebra MY using assms by simp
hoelzl@40859
   341
  interpret P: pair_sigma_algebra MX MY by default
hoelzl@41689
   342
  show "sigma_algebra (MX \<Otimes>\<^isub>M MY)" by default
hoelzl@40859
   343
  have sa: "sigma_algebra M" by default
hoelzl@41689
   344
  show "(\<lambda>x. (X x, Y x)) \<in> measurable M (MX \<Otimes>\<^isub>M MY)"
hoelzl@41095
   345
    unfolding P.measurable_pair_iff[OF sa] using assms by (simp add: comp_def)
hoelzl@40859
   346
qed
hoelzl@40859
   347
hoelzl@40859
   348
lemma (in prob_space) joint_distribution_commute_singleton:
hoelzl@40859
   349
  "joint_distribution X Y {(x, y)} = joint_distribution Y X {(y, x)}"
hoelzl@41981
   350
  unfolding distribution_def by (auto intro!: arg_cong[where f=\<mu>'])
hoelzl@40859
   351
hoelzl@40859
   352
lemma (in prob_space) joint_distribution_assoc_singleton:
hoelzl@40859
   353
  "joint_distribution X (\<lambda>x. (Y x, Z x)) {(x, y, z)} =
hoelzl@40859
   354
   joint_distribution (\<lambda>x. (X x, Y x)) Z {((x, y), z)}"
hoelzl@41981
   355
  unfolding distribution_def by (auto intro!: arg_cong[where f=\<mu>'])
hoelzl@40859
   356
hoelzl@41689
   357
locale pair_prob_space = M1: prob_space M1 + M2: prob_space M2 for M1 M2
hoelzl@40859
   358
hoelzl@41689
   359
sublocale pair_prob_space \<subseteq> pair_sigma_finite M1 M2 by default
hoelzl@41689
   360
hoelzl@41689
   361
sublocale pair_prob_space \<subseteq> P: prob_space P
hoelzl@41689
   362
by default (simp add: pair_measure_times M1.measure_space_1 M2.measure_space_1 space_pair_measure)
hoelzl@40859
   363
hoelzl@40859
   364
lemma countably_additiveI[case_names countably]:
hoelzl@40859
   365
  assumes "\<And>A. \<lbrakk> range A \<subseteq> sets M ; disjoint_family A ; (\<Union>i. A i) \<in> sets M\<rbrakk> \<Longrightarrow>
hoelzl@41981
   366
    (\<Sum>n. \<mu> (A n)) = \<mu> (\<Union>i. A i)"
hoelzl@40859
   367
  shows "countably_additive M \<mu>"
hoelzl@40859
   368
  using assms unfolding countably_additive_def by auto
hoelzl@40859
   369
hoelzl@40859
   370
lemma (in prob_space) joint_distribution_prob_space:
hoelzl@40859
   371
  assumes "random_variable MX X" "random_variable MY Y"
hoelzl@41981
   372
  shows "prob_space ((MX \<Otimes>\<^isub>M MY) \<lparr> measure := extreal \<circ> joint_distribution X Y\<rparr>)"
hoelzl@41689
   373
  using random_variable_pairI[OF assms] by (rule distribution_prob_space)
hoelzl@40859
   374
hoelzl@40859
   375
section "Probability spaces on finite sets"
hoelzl@35582
   376
hoelzl@35977
   377
locale finite_prob_space = prob_space + finite_measure_space
hoelzl@35977
   378
hoelzl@40859
   379
abbreviation (in prob_space) "finite_random_variable M' X \<equiv> finite_sigma_algebra M' \<and> X \<in> measurable M M'"
hoelzl@40859
   380
hoelzl@40859
   381
lemma (in prob_space) finite_random_variableD:
hoelzl@40859
   382
  assumes "finite_random_variable M' X" shows "random_variable M' X"
hoelzl@40859
   383
proof -
hoelzl@40859
   384
  interpret M': finite_sigma_algebra M' using assms by simp
hoelzl@40859
   385
  then show "random_variable M' X" using assms by simp default
hoelzl@40859
   386
qed
hoelzl@40859
   387
hoelzl@40859
   388
lemma (in prob_space) distribution_finite_prob_space:
hoelzl@40859
   389
  assumes "finite_random_variable MX X"
hoelzl@41981
   390
  shows "finite_prob_space (MX\<lparr>measure := extreal \<circ> distribution X\<rparr>)"
hoelzl@40859
   391
proof -
hoelzl@41981
   392
  interpret X: prob_space "MX\<lparr>measure := extreal \<circ> distribution X\<rparr>"
hoelzl@40859
   393
    using assms[THEN finite_random_variableD] by (rule distribution_prob_space)
hoelzl@40859
   394
  interpret MX: finite_sigma_algebra MX
hoelzl@41689
   395
    using assms by auto
hoelzl@41981
   396
  show ?thesis by default (simp_all add: MX.finite_space)
hoelzl@40859
   397
qed
hoelzl@40859
   398
hoelzl@40859
   399
lemma (in prob_space) simple_function_imp_finite_random_variable[simp, intro]:
hoelzl@41689
   400
  assumes "simple_function M X"
hoelzl@41689
   401
  shows "finite_random_variable \<lparr> space = X`space M, sets = Pow (X`space M), \<dots> = x \<rparr> X"
hoelzl@41689
   402
    (is "finite_random_variable ?X _")
hoelzl@40859
   403
proof (intro conjI)
hoelzl@40859
   404
  have [simp]: "finite (X ` space M)" using assms unfolding simple_function_def by simp
hoelzl@41689
   405
  interpret X: sigma_algebra ?X by (rule sigma_algebra_Pow)
hoelzl@41689
   406
  show "finite_sigma_algebra ?X"
hoelzl@40859
   407
    by default auto
hoelzl@41689
   408
  show "X \<in> measurable M ?X"
hoelzl@40859
   409
  proof (unfold measurable_def, clarsimp)
hoelzl@40859
   410
    fix A assume A: "A \<subseteq> X`space M"
hoelzl@40859
   411
    then have "finite A" by (rule finite_subset) simp
hoelzl@40859
   412
    then have "X -` (\<Union>a\<in>A. {a}) \<inter> space M \<in> events"
hoelzl@40859
   413
      unfolding vimage_UN UN_extend_simps
hoelzl@40859
   414
      apply (rule finite_UN)
hoelzl@40859
   415
      using A assms unfolding simple_function_def by auto
hoelzl@40859
   416
    then show "X -` A \<inter> space M \<in> events" by simp
hoelzl@40859
   417
  qed
hoelzl@40859
   418
qed
hoelzl@40859
   419
hoelzl@40859
   420
lemma (in prob_space) simple_function_imp_random_variable[simp, intro]:
hoelzl@41689
   421
  assumes "simple_function M X"
hoelzl@41689
   422
  shows "random_variable \<lparr> space = X`space M, sets = Pow (X`space M), \<dots> = ext \<rparr> X"
hoelzl@41689
   423
  using simple_function_imp_finite_random_variable[OF assms, of ext]
hoelzl@40859
   424
  by (auto dest!: finite_random_variableD)
hoelzl@40859
   425
hoelzl@40859
   426
lemma (in prob_space) sum_over_space_real_distribution:
hoelzl@41981
   427
  "simple_function M X \<Longrightarrow> (\<Sum>x\<in>X`space M. distribution X {x}) = 1"
hoelzl@40859
   428
  unfolding distribution_def prob_space[symmetric]
hoelzl@41981
   429
  by (subst finite_measure_finite_Union[symmetric])
hoelzl@40859
   430
     (auto simp add: disjoint_family_on_def simple_function_def
hoelzl@40859
   431
           intro!: arg_cong[where f=prob])
hoelzl@40859
   432
hoelzl@40859
   433
lemma (in prob_space) finite_random_variable_pairI:
hoelzl@40859
   434
  assumes "finite_random_variable MX X"
hoelzl@40859
   435
  assumes "finite_random_variable MY Y"
hoelzl@41689
   436
  shows "finite_random_variable (MX \<Otimes>\<^isub>M MY) (\<lambda>x. (X x, Y x))"
hoelzl@40859
   437
proof
hoelzl@40859
   438
  interpret MX: finite_sigma_algebra MX using assms by simp
hoelzl@40859
   439
  interpret MY: finite_sigma_algebra MY using assms by simp
hoelzl@40859
   440
  interpret P: pair_finite_sigma_algebra MX MY by default
hoelzl@41689
   441
  show "finite_sigma_algebra (MX \<Otimes>\<^isub>M MY)" by default
hoelzl@40859
   442
  have sa: "sigma_algebra M" by default
hoelzl@41689
   443
  show "(\<lambda>x. (X x, Y x)) \<in> measurable M (MX \<Otimes>\<^isub>M MY)"
hoelzl@41095
   444
    unfolding P.measurable_pair_iff[OF sa] using assms by (simp add: comp_def)
hoelzl@40859
   445
qed
hoelzl@40859
   446
hoelzl@40859
   447
lemma (in prob_space) finite_random_variable_imp_sets:
hoelzl@40859
   448
  "finite_random_variable MX X \<Longrightarrow> x \<in> space MX \<Longrightarrow> {x} \<in> sets MX"
hoelzl@40859
   449
  unfolding finite_sigma_algebra_def finite_sigma_algebra_axioms_def by simp
hoelzl@40859
   450
hoelzl@41981
   451
lemma (in prob_space) finite_random_variable_measurable:
hoelzl@40859
   452
  assumes X: "finite_random_variable MX X" shows "X -` A \<inter> space M \<in> events"
hoelzl@40859
   453
proof -
hoelzl@40859
   454
  interpret X: finite_sigma_algebra MX using X by simp
hoelzl@40859
   455
  from X have vimage: "\<And>A. A \<subseteq> space MX \<Longrightarrow> X -` A \<inter> space M \<in> events" and
hoelzl@40859
   456
    "X \<in> space M \<rightarrow> space MX"
hoelzl@40859
   457
    by (auto simp: measurable_def)
hoelzl@40859
   458
  then have *: "X -` A \<inter> space M = X -` (A \<inter> space MX) \<inter> space M"
hoelzl@40859
   459
    by auto
hoelzl@40859
   460
  show "X -` A \<inter> space M \<in> events"
hoelzl@40859
   461
    unfolding * by (intro vimage) auto
hoelzl@40859
   462
qed
hoelzl@40859
   463
hoelzl@40859
   464
lemma (in prob_space) joint_distribution_finite_Times_le_fst:
hoelzl@40859
   465
  assumes X: "finite_random_variable MX X" and Y: "finite_random_variable MY Y"
hoelzl@40859
   466
  shows "joint_distribution X Y (A \<times> B) \<le> distribution X A"
hoelzl@40859
   467
  unfolding distribution_def
hoelzl@41981
   468
proof (intro finite_measure_mono)
hoelzl@40859
   469
  show "(\<lambda>x. (X x, Y x)) -` (A \<times> B) \<inter> space M \<subseteq> X -` A \<inter> space M" by force
hoelzl@40859
   470
  show "X -` A \<inter> space M \<in> events"
hoelzl@41981
   471
    using finite_random_variable_measurable[OF X] .
hoelzl@40859
   472
  have *: "(\<lambda>x. (X x, Y x)) -` (A \<times> B) \<inter> space M =
hoelzl@40859
   473
    (X -` A \<inter> space M) \<inter> (Y -` B \<inter> space M)" by auto
hoelzl@40859
   474
qed
hoelzl@40859
   475
hoelzl@40859
   476
lemma (in prob_space) joint_distribution_finite_Times_le_snd:
hoelzl@40859
   477
  assumes X: "finite_random_variable MX X" and Y: "finite_random_variable MY Y"
hoelzl@40859
   478
  shows "joint_distribution X Y (A \<times> B) \<le> distribution Y B"
hoelzl@40859
   479
  using assms
hoelzl@40859
   480
  by (subst joint_distribution_commute)
hoelzl@40859
   481
     (simp add: swap_product joint_distribution_finite_Times_le_fst)
hoelzl@40859
   482
hoelzl@40859
   483
lemma (in prob_space) finite_distribution_order:
hoelzl@41981
   484
  fixes MX :: "('c, 'd) measure_space_scheme" and MY :: "('e, 'f) measure_space_scheme"
hoelzl@40859
   485
  assumes "finite_random_variable MX X" "finite_random_variable MY Y"
hoelzl@40859
   486
  shows "r \<le> joint_distribution X Y {(x, y)} \<Longrightarrow> r \<le> distribution X {x}"
hoelzl@40859
   487
    and "r \<le> joint_distribution X Y {(x, y)} \<Longrightarrow> r \<le> distribution Y {y}"
hoelzl@40859
   488
    and "r < joint_distribution X Y {(x, y)} \<Longrightarrow> r < distribution X {x}"
hoelzl@40859
   489
    and "r < joint_distribution X Y {(x, y)} \<Longrightarrow> r < distribution Y {y}"
hoelzl@40859
   490
    and "distribution X {x} = 0 \<Longrightarrow> joint_distribution X Y {(x, y)} = 0"
hoelzl@40859
   491
    and "distribution Y {y} = 0 \<Longrightarrow> joint_distribution X Y {(x, y)} = 0"
hoelzl@40859
   492
  using joint_distribution_finite_Times_le_snd[OF assms, of "{x}" "{y}"]
hoelzl@40859
   493
  using joint_distribution_finite_Times_le_fst[OF assms, of "{x}" "{y}"]
hoelzl@41981
   494
  by (auto intro: antisym)
hoelzl@40859
   495
hoelzl@40859
   496
lemma (in prob_space) setsum_joint_distribution:
hoelzl@40859
   497
  assumes X: "finite_random_variable MX X"
hoelzl@40859
   498
  assumes Y: "random_variable MY Y" "B \<in> sets MY"
hoelzl@40859
   499
  shows "(\<Sum>a\<in>space MX. joint_distribution X Y ({a} \<times> B)) = distribution Y B"
hoelzl@40859
   500
  unfolding distribution_def
hoelzl@41981
   501
proof (subst finite_measure_finite_Union[symmetric])
hoelzl@40859
   502
  interpret MX: finite_sigma_algebra MX using X by auto
hoelzl@40859
   503
  show "finite (space MX)" using MX.finite_space .
hoelzl@40859
   504
  let "?d i" = "(\<lambda>x. (X x, Y x)) -` ({i} \<times> B) \<inter> space M"
hoelzl@40859
   505
  { fix i assume "i \<in> space MX"
hoelzl@40859
   506
    moreover have "?d i = (X -` {i} \<inter> space M) \<inter> (Y -` B \<inter> space M)" by auto
hoelzl@40859
   507
    ultimately show "?d i \<in> events"
hoelzl@40859
   508
      using measurable_sets[of X M MX] measurable_sets[of Y M MY B] X Y
hoelzl@40859
   509
      using MX.sets_eq_Pow by auto }
hoelzl@40859
   510
  show "disjoint_family_on ?d (space MX)" by (auto simp: disjoint_family_on_def)
hoelzl@41981
   511
  show "\<mu>' (\<Union>i\<in>space MX. ?d i) = \<mu>' (Y -` B \<inter> space M)"
hoelzl@41981
   512
    using X[unfolded measurable_def] by (auto intro!: arg_cong[where f=\<mu>'])
hoelzl@40859
   513
qed
hoelzl@40859
   514
hoelzl@40859
   515
lemma (in prob_space) setsum_joint_distribution_singleton:
hoelzl@40859
   516
  assumes X: "finite_random_variable MX X"
hoelzl@40859
   517
  assumes Y: "finite_random_variable MY Y" "b \<in> space MY"
hoelzl@40859
   518
  shows "(\<Sum>a\<in>space MX. joint_distribution X Y {(a, b)}) = distribution Y {b}"
hoelzl@40859
   519
  using setsum_joint_distribution[OF X
hoelzl@40859
   520
    finite_random_variableD[OF Y(1)]
hoelzl@40859
   521
    finite_random_variable_imp_sets[OF Y]] by simp
hoelzl@40859
   522
hoelzl@41689
   523
locale pair_finite_prob_space = M1: finite_prob_space M1 + M2: finite_prob_space M2 for M1 M2
hoelzl@40859
   524
hoelzl@41689
   525
sublocale pair_finite_prob_space \<subseteq> pair_prob_space M1 M2 by default
hoelzl@41689
   526
sublocale pair_finite_prob_space \<subseteq> pair_finite_space M1 M2  by default
hoelzl@41689
   527
sublocale pair_finite_prob_space \<subseteq> finite_prob_space P by default
hoelzl@40859
   528
hoelzl@40859
   529
lemma (in prob_space) joint_distribution_finite_prob_space:
hoelzl@40859
   530
  assumes X: "finite_random_variable MX X"
hoelzl@40859
   531
  assumes Y: "finite_random_variable MY Y"
hoelzl@41981
   532
  shows "finite_prob_space ((MX \<Otimes>\<^isub>M MY)\<lparr> measure := extreal \<circ> joint_distribution X Y\<rparr>)"
hoelzl@41689
   533
  by (intro distribution_finite_prob_space finite_random_variable_pairI X Y)
hoelzl@40859
   534
hoelzl@36624
   535
lemma finite_prob_space_eq:
hoelzl@41689
   536
  "finite_prob_space M \<longleftrightarrow> finite_measure_space M \<and> measure M (space M) = 1"
hoelzl@36624
   537
  unfolding finite_prob_space_def finite_measure_space_def prob_space_def prob_space_axioms_def
hoelzl@36624
   538
  by auto
hoelzl@36624
   539
hoelzl@36624
   540
lemma (in prob_space) not_empty: "space M \<noteq> {}"
hoelzl@41981
   541
  using prob_space empty_measure' by auto
hoelzl@36624
   542
hoelzl@38656
   543
lemma (in finite_prob_space) sum_over_space_eq_1: "(\<Sum>x\<in>space M. \<mu> {x}) = 1"
hoelzl@38656
   544
  using measure_space_1 sum_over_space by simp
hoelzl@36624
   545
hoelzl@36624
   546
lemma (in finite_prob_space) joint_distribution_restriction_fst:
hoelzl@36624
   547
  "joint_distribution X Y A \<le> distribution X (fst ` A)"
hoelzl@36624
   548
  unfolding distribution_def
hoelzl@41981
   549
proof (safe intro!: finite_measure_mono)
hoelzl@36624
   550
  fix x assume "x \<in> space M" and *: "(X x, Y x) \<in> A"
hoelzl@36624
   551
  show "x \<in> X -` fst ` A"
hoelzl@36624
   552
    by (auto intro!: image_eqI[OF _ *])
hoelzl@36624
   553
qed (simp_all add: sets_eq_Pow)
hoelzl@36624
   554
hoelzl@36624
   555
lemma (in finite_prob_space) joint_distribution_restriction_snd:
hoelzl@36624
   556
  "joint_distribution X Y A \<le> distribution Y (snd ` A)"
hoelzl@36624
   557
  unfolding distribution_def
hoelzl@41981
   558
proof (safe intro!: finite_measure_mono)
hoelzl@36624
   559
  fix x assume "x \<in> space M" and *: "(X x, Y x) \<in> A"
hoelzl@36624
   560
  show "x \<in> Y -` snd ` A"
hoelzl@36624
   561
    by (auto intro!: image_eqI[OF _ *])
hoelzl@36624
   562
qed (simp_all add: sets_eq_Pow)
hoelzl@36624
   563
hoelzl@36624
   564
lemma (in finite_prob_space) distribution_order:
hoelzl@36624
   565
  shows "0 \<le> distribution X x'"
hoelzl@36624
   566
  and "(distribution X x' \<noteq> 0) \<longleftrightarrow> (0 < distribution X x')"
hoelzl@36624
   567
  and "r \<le> joint_distribution X Y {(x, y)} \<Longrightarrow> r \<le> distribution X {x}"
hoelzl@36624
   568
  and "r \<le> joint_distribution X Y {(x, y)} \<Longrightarrow> r \<le> distribution Y {y}"
hoelzl@36624
   569
  and "r < joint_distribution X Y {(x, y)} \<Longrightarrow> r < distribution X {x}"
hoelzl@36624
   570
  and "r < joint_distribution X Y {(x, y)} \<Longrightarrow> r < distribution Y {y}"
hoelzl@36624
   571
  and "distribution X {x} = 0 \<Longrightarrow> joint_distribution X Y {(x, y)} = 0"
hoelzl@36624
   572
  and "distribution Y {y} = 0 \<Longrightarrow> joint_distribution X Y {(x, y)} = 0"
hoelzl@41981
   573
  using
hoelzl@36624
   574
    joint_distribution_restriction_fst[of X Y "{(x, y)}"]
hoelzl@36624
   575
    joint_distribution_restriction_snd[of X Y "{(x, y)}"]
hoelzl@41981
   576
  by (auto intro: antisym)
hoelzl@36624
   577
hoelzl@39097
   578
lemma (in finite_prob_space) distribution_mono:
hoelzl@39097
   579
  assumes "\<And>t. \<lbrakk> t \<in> space M ; X t \<in> x \<rbrakk> \<Longrightarrow> Y t \<in> y"
hoelzl@39097
   580
  shows "distribution X x \<le> distribution Y y"
hoelzl@39097
   581
  unfolding distribution_def
hoelzl@41981
   582
  using assms by (auto simp: sets_eq_Pow intro!: finite_measure_mono)
hoelzl@39097
   583
hoelzl@39097
   584
lemma (in finite_prob_space) distribution_mono_gt_0:
hoelzl@39097
   585
  assumes gt_0: "0 < distribution X x"
hoelzl@39097
   586
  assumes *: "\<And>t. \<lbrakk> t \<in> space M ; X t \<in> x \<rbrakk> \<Longrightarrow> Y t \<in> y"
hoelzl@39097
   587
  shows "0 < distribution Y y"
hoelzl@39097
   588
  by (rule less_le_trans[OF gt_0 distribution_mono]) (rule *)
hoelzl@39097
   589
hoelzl@39097
   590
lemma (in finite_prob_space) sum_over_space_distrib:
hoelzl@39097
   591
  "(\<Sum>x\<in>X`space M. distribution X {x}) = 1"
hoelzl@41981
   592
  unfolding distribution_def prob_space[symmetric] using finite_space
hoelzl@41981
   593
  by (subst finite_measure_finite_Union[symmetric])
hoelzl@41981
   594
     (auto simp add: disjoint_family_on_def sets_eq_Pow
hoelzl@41981
   595
           intro!: arg_cong[where f=\<mu>'])
hoelzl@39097
   596
hoelzl@39097
   597
lemma (in finite_prob_space) sum_over_space_real_distribution:
hoelzl@41981
   598
  "(\<Sum>x\<in>X`space M. distribution X {x}) = 1"
hoelzl@39097
   599
  unfolding distribution_def prob_space[symmetric] using finite_space
hoelzl@41981
   600
  by (subst finite_measure_finite_Union[symmetric])
hoelzl@39097
   601
     (auto simp add: disjoint_family_on_def sets_eq_Pow intro!: arg_cong[where f=prob])
hoelzl@39097
   602
hoelzl@39097
   603
lemma (in finite_prob_space) finite_sum_over_space_eq_1:
hoelzl@41981
   604
  "(\<Sum>x\<in>space M. prob {x}) = 1"
hoelzl@41981
   605
  using prob_space finite_space
hoelzl@41981
   606
  by (subst (asm) finite_measure_finite_singleton) auto
hoelzl@39097
   607
hoelzl@39097
   608
lemma (in prob_space) distribution_remove_const:
hoelzl@39097
   609
  shows "joint_distribution X (\<lambda>x. ()) {(x, ())} = distribution X {x}"
hoelzl@39097
   610
  and "joint_distribution (\<lambda>x. ()) X {((), x)} = distribution X {x}"
hoelzl@39097
   611
  and "joint_distribution X (\<lambda>x. (Y x, ())) {(x, y, ())} = joint_distribution X Y {(x, y)}"
hoelzl@39097
   612
  and "joint_distribution X (\<lambda>x. ((), Y x)) {(x, (), y)} = joint_distribution X Y {(x, y)}"
hoelzl@39097
   613
  and "distribution (\<lambda>x. ()) {()} = 1"
hoelzl@41981
   614
  by (auto intro!: arg_cong[where f=\<mu>'] simp: distribution_def prob_space[symmetric])
hoelzl@35977
   615
hoelzl@39097
   616
lemma (in finite_prob_space) setsum_distribution_gen:
hoelzl@39097
   617
  assumes "Z -` {c} \<inter> space M = (\<Union>x \<in> X`space M. Y -` {f x}) \<inter> space M"
hoelzl@39097
   618
  and "inj_on f (X`space M)"
hoelzl@39097
   619
  shows "(\<Sum>x \<in> X`space M. distribution Y {f x}) = distribution Z {c}"
hoelzl@39097
   620
  unfolding distribution_def assms
hoelzl@39097
   621
  using finite_space assms
hoelzl@41981
   622
  by (subst finite_measure_finite_Union[symmetric])
hoelzl@39097
   623
     (auto simp add: disjoint_family_on_def sets_eq_Pow inj_on_def
hoelzl@39097
   624
      intro!: arg_cong[where f=prob])
hoelzl@39097
   625
hoelzl@39097
   626
lemma (in finite_prob_space) setsum_distribution:
hoelzl@39097
   627
  "(\<Sum>x \<in> X`space M. joint_distribution X Y {(x, y)}) = distribution Y {y}"
hoelzl@39097
   628
  "(\<Sum>y \<in> Y`space M. joint_distribution X Y {(x, y)}) = distribution X {x}"
hoelzl@39097
   629
  "(\<Sum>x \<in> X`space M. joint_distribution X (\<lambda>x. (Y x, Z x)) {(x, y, z)}) = joint_distribution Y Z {(y, z)}"
hoelzl@39097
   630
  "(\<Sum>y \<in> Y`space M. joint_distribution X (\<lambda>x. (Y x, Z x)) {(x, y, z)}) = joint_distribution X Z {(x, z)}"
hoelzl@39097
   631
  "(\<Sum>z \<in> Z`space M. joint_distribution X (\<lambda>x. (Y x, Z x)) {(x, y, z)}) = joint_distribution X Y {(x, y)}"
hoelzl@39097
   632
  by (auto intro!: inj_onI setsum_distribution_gen)
hoelzl@39097
   633
hoelzl@39097
   634
lemma (in finite_prob_space) uniform_prob:
hoelzl@39097
   635
  assumes "x \<in> space M"
hoelzl@39097
   636
  assumes "\<And> x y. \<lbrakk>x \<in> space M ; y \<in> space M\<rbrakk> \<Longrightarrow> prob {x} = prob {y}"
hoelzl@41981
   637
  shows "prob {x} = 1 / card (space M)"
hoelzl@39097
   638
proof -
hoelzl@39097
   639
  have prob_x: "\<And> y. y \<in> space M \<Longrightarrow> prob {y} = prob {x}"
hoelzl@39097
   640
    using assms(2)[OF _ `x \<in> space M`] by blast
hoelzl@39097
   641
  have "1 = prob (space M)"
hoelzl@39097
   642
    using prob_space by auto
hoelzl@39097
   643
  also have "\<dots> = (\<Sum> x \<in> space M. prob {x})"
hoelzl@41981
   644
    using finite_measure_finite_Union[of "space M" "\<lambda> x. {x}", simplified]
hoelzl@39097
   645
      sets_eq_Pow inj_singleton[unfolded inj_on_def, rule_format]
hoelzl@39097
   646
      finite_space unfolding disjoint_family_on_def  prob_space[symmetric]
hoelzl@39097
   647
    by (auto simp add:setsum_restrict_set)
hoelzl@39097
   648
  also have "\<dots> = (\<Sum> y \<in> space M. prob {x})"
hoelzl@39097
   649
    using prob_x by auto
hoelzl@39097
   650
  also have "\<dots> = real_of_nat (card (space M)) * prob {x}" by simp
hoelzl@39097
   651
  finally have one: "1 = real (card (space M)) * prob {x}"
hoelzl@39097
   652
    using real_eq_of_nat by auto
hoelzl@39097
   653
  hence two: "real (card (space M)) \<noteq> 0" by fastsimp 
hoelzl@39097
   654
  from one have three: "prob {x} \<noteq> 0" by fastsimp
hoelzl@39097
   655
  thus ?thesis using one two three divide_cancel_right
hoelzl@39097
   656
    by (auto simp:field_simps)
hoelzl@39092
   657
qed
hoelzl@35977
   658
hoelzl@39092
   659
lemma (in prob_space) prob_space_subalgebra:
hoelzl@41545
   660
  assumes "sigma_algebra N" "sets N \<subseteq> sets M" "space N = space M"
hoelzl@41689
   661
    and "\<And>A. A \<in> sets N \<Longrightarrow> measure N A = \<mu> A"
hoelzl@41689
   662
  shows "prob_space N"
hoelzl@39092
   663
proof -
hoelzl@41689
   664
  interpret N: measure_space N
hoelzl@41689
   665
    by (rule measure_space_subalgebra[OF assms])
hoelzl@39092
   666
  show ?thesis
hoelzl@41689
   667
  proof qed (insert assms(4)[OF N.top], simp add: assms measure_space_1)
hoelzl@35977
   668
qed
hoelzl@35977
   669
hoelzl@39092
   670
lemma (in prob_space) prob_space_of_restricted_space:
hoelzl@41981
   671
  assumes "\<mu> A \<noteq> 0" "A \<in> sets M"
hoelzl@41689
   672
  shows "prob_space (restricted_space A \<lparr>measure := \<lambda>S. \<mu> S / \<mu> A\<rparr>)"
hoelzl@41689
   673
    (is "prob_space ?P")
hoelzl@41689
   674
proof -
hoelzl@41689
   675
  interpret A: measure_space "restricted_space A"
hoelzl@39092
   676
    using `A \<in> sets M` by (rule restricted_measure_space)
hoelzl@41689
   677
  interpret A': sigma_algebra ?P
hoelzl@41689
   678
    by (rule A.sigma_algebra_cong) auto
hoelzl@41689
   679
  show "prob_space ?P"
hoelzl@39092
   680
  proof
hoelzl@41689
   681
    show "measure ?P (space ?P) = 1"
hoelzl@41981
   682
      using real_measure[OF `A \<in> events`] `\<mu> A \<noteq> 0` by auto
hoelzl@41981
   683
    show "positive ?P (measure ?P)"
hoelzl@41981
   684
    proof (simp add: positive_def, safe)
hoelzl@41981
   685
      show "0 / \<mu> A = 0" using `\<mu> A \<noteq> 0` by (cases "\<mu> A") (auto simp: zero_extreal_def)
hoelzl@41981
   686
      fix B assume "B \<in> events"
hoelzl@41981
   687
      with real_measure[of "A \<inter> B"] real_measure[OF `A \<in> events`] `A \<in> sets M`
hoelzl@41981
   688
      show "0 \<le> \<mu> (A \<inter> B) / \<mu> A" by (auto simp: Int)
hoelzl@41981
   689
    qed
hoelzl@41981
   690
    show "countably_additive ?P (measure ?P)"
hoelzl@41981
   691
    proof (simp add: countably_additive_def, safe)
hoelzl@41981
   692
      fix B and F :: "nat \<Rightarrow> 'a set"
hoelzl@41981
   693
      assume F: "range F \<subseteq> op \<inter> A ` events" "disjoint_family F"
hoelzl@41981
   694
      { fix i
hoelzl@41981
   695
        from F have "F i \<in> op \<inter> A ` events" by auto
hoelzl@41981
   696
        with `A \<in> events` have "F i \<in> events" by auto }
hoelzl@41981
   697
      moreover then have "range F \<subseteq> events" by auto
hoelzl@41981
   698
      moreover have "\<And>S. \<mu> S / \<mu> A = inverse (\<mu> A) * \<mu> S"
hoelzl@41981
   699
        by (simp add: mult_commute divide_extreal_def)
hoelzl@41981
   700
      moreover have "0 \<le> inverse (\<mu> A)"
hoelzl@41981
   701
        using real_measure[OF `A \<in> events`] by auto
hoelzl@41981
   702
      ultimately show "(\<Sum>i. \<mu> (F i) / \<mu> A) = \<mu> (\<Union>i. F i) / \<mu> A"
hoelzl@41981
   703
        using measure_countably_additive[of F] F
hoelzl@41981
   704
        by (auto simp: suminf_cmult_extreal)
hoelzl@41981
   705
    qed
hoelzl@39092
   706
  qed
hoelzl@39092
   707
qed
hoelzl@39092
   708
hoelzl@39092
   709
lemma finite_prob_spaceI:
hoelzl@41981
   710
  assumes "finite (space M)" "sets M = Pow(space M)"
hoelzl@41981
   711
    and "measure M (space M) = 1" "measure M {} = 0" "\<And>A. A \<subseteq> space M \<Longrightarrow> 0 \<le> measure M A"
hoelzl@41689
   712
    and "\<And>A B. A\<subseteq>space M \<Longrightarrow> B\<subseteq>space M \<Longrightarrow> A \<inter> B = {} \<Longrightarrow> measure M (A \<union> B) = measure M A + measure M B"
hoelzl@41689
   713
  shows "finite_prob_space M"
hoelzl@39092
   714
  unfolding finite_prob_space_eq
hoelzl@39092
   715
proof
hoelzl@41689
   716
  show "finite_measure_space M" using assms
hoelzl@41981
   717
    by (auto intro!: finite_measure_spaceI)
hoelzl@41689
   718
  show "measure M (space M) = 1" by fact
hoelzl@39092
   719
qed
hoelzl@36624
   720
hoelzl@36624
   721
lemma (in finite_prob_space) finite_measure_space:
hoelzl@39097
   722
  fixes X :: "'a \<Rightarrow> 'x"
hoelzl@41981
   723
  shows "finite_measure_space \<lparr>space = X ` space M, sets = Pow (X ` space M), measure = extreal \<circ> distribution X\<rparr>"
hoelzl@41689
   724
    (is "finite_measure_space ?S")
hoelzl@39092
   725
proof (rule finite_measure_spaceI, simp_all)
hoelzl@36624
   726
  show "finite (X ` space M)" using finite_space by simp
hoelzl@39097
   727
next
hoelzl@39097
   728
  fix A B :: "'x set" assume "A \<inter> B = {}"
hoelzl@39097
   729
  then show "distribution X (A \<union> B) = distribution X A + distribution X B"
hoelzl@39097
   730
    unfolding distribution_def
hoelzl@41981
   731
    by (subst finite_measure_Union[symmetric])
hoelzl@41981
   732
       (auto intro!: arg_cong[where f=\<mu>'] simp: sets_eq_Pow)
hoelzl@36624
   733
qed
hoelzl@36624
   734
hoelzl@39097
   735
lemma (in finite_prob_space) finite_prob_space_of_images:
hoelzl@41981
   736
  "finite_prob_space \<lparr> space = X ` space M, sets = Pow (X ` space M), measure = extreal \<circ> distribution X \<rparr>"
hoelzl@41981
   737
  by (simp add: finite_prob_space_eq finite_measure_space measure_space_1 one_extreal_def)
hoelzl@39097
   738
hoelzl@39096
   739
lemma (in finite_prob_space) finite_product_measure_space:
hoelzl@39097
   740
  fixes X :: "'a \<Rightarrow> 'x" and Y :: "'a \<Rightarrow> 'y"
hoelzl@39096
   741
  assumes "finite s1" "finite s2"
hoelzl@41981
   742
  shows "finite_measure_space \<lparr> space = s1 \<times> s2, sets = Pow (s1 \<times> s2), measure = extreal \<circ> joint_distribution X Y\<rparr>"
hoelzl@41689
   743
    (is "finite_measure_space ?M")
hoelzl@39097
   744
proof (rule finite_measure_spaceI, simp_all)
hoelzl@39097
   745
  show "finite (s1 \<times> s2)"
hoelzl@39096
   746
    using assms by auto
hoelzl@39097
   747
next
hoelzl@39097
   748
  fix A B :: "('x*'y) set" assume "A \<inter> B = {}"
hoelzl@39097
   749
  then show "joint_distribution X Y (A \<union> B) = joint_distribution X Y A + joint_distribution X Y B"
hoelzl@39097
   750
    unfolding distribution_def
hoelzl@41981
   751
    by (subst finite_measure_Union[symmetric])
hoelzl@41981
   752
       (auto intro!: arg_cong[where f=\<mu>'] simp: sets_eq_Pow)
hoelzl@39096
   753
qed
hoelzl@39096
   754
hoelzl@39097
   755
lemma (in finite_prob_space) finite_product_measure_space_of_images:
hoelzl@39096
   756
  shows "finite_measure_space \<lparr> space = X ` space M \<times> Y ` space M,
hoelzl@41689
   757
                                sets = Pow (X ` space M \<times> Y ` space M),
hoelzl@41981
   758
                                measure = extreal \<circ> joint_distribution X Y \<rparr>"
hoelzl@39096
   759
  using finite_space by (auto intro!: finite_product_measure_space)
hoelzl@39096
   760
hoelzl@40859
   761
lemma (in finite_prob_space) finite_product_prob_space_of_images:
hoelzl@41689
   762
  "finite_prob_space \<lparr> space = X ` space M \<times> Y ` space M, sets = Pow (X ` space M \<times> Y ` space M),
hoelzl@41981
   763
                       measure = extreal \<circ> joint_distribution X Y \<rparr>"
hoelzl@41689
   764
  (is "finite_prob_space ?S")
hoelzl@41981
   765
proof (simp add: finite_prob_space_eq finite_product_measure_space_of_images one_extreal_def)
hoelzl@40859
   766
  have "X -` X ` space M \<inter> Y -` Y ` space M \<inter> space M = space M" by auto
hoelzl@40859
   767
  thus "joint_distribution X Y (X ` space M \<times> Y ` space M) = 1"
hoelzl@40859
   768
    by (simp add: distribution_def prob_space vimage_Times comp_def measure_space_1)
hoelzl@40859
   769
qed
hoelzl@40859
   770
hoelzl@39085
   771
section "Conditional Expectation and Probability"
hoelzl@39085
   772
hoelzl@39085
   773
lemma (in prob_space) conditional_expectation_exists:
hoelzl@41981
   774
  fixes X :: "'a \<Rightarrow> extreal" and N :: "('a, 'b) measure_space_scheme"
hoelzl@41981
   775
  assumes borel: "X \<in> borel_measurable M" "AE x. 0 \<le> X x"
hoelzl@41689
   776
  and N: "sigma_algebra N" "sets N \<subseteq> sets M" "space N = space M" "\<And>A. measure N A = \<mu> A"
hoelzl@41981
   777
  shows "\<exists>Y\<in>borel_measurable N. (\<forall>x. 0 \<le> Y x) \<and> (\<forall>C\<in>sets N.
hoelzl@41981
   778
      (\<integral>\<^isup>+x. Y x * indicator C x \<partial>M) = (\<integral>\<^isup>+x. X x * indicator C x \<partial>M))"
hoelzl@39083
   779
proof -
hoelzl@41689
   780
  note N(4)[simp]
hoelzl@41689
   781
  interpret P: prob_space N
hoelzl@41545
   782
    using prob_space_subalgebra[OF N] .
hoelzl@39083
   783
hoelzl@39083
   784
  let "?f A" = "\<lambda>x. X x * indicator A x"
hoelzl@41689
   785
  let "?Q A" = "integral\<^isup>P M (?f A)"
hoelzl@39083
   786
hoelzl@39083
   787
  from measure_space_density[OF borel]
hoelzl@41689
   788
  have Q: "measure_space (N\<lparr> measure := ?Q \<rparr>)"
hoelzl@41689
   789
    apply (rule measure_space.measure_space_subalgebra[of "M\<lparr> measure := ?Q \<rparr>"])
hoelzl@41689
   790
    using N by (auto intro!: P.sigma_algebra_cong)
hoelzl@41689
   791
  then interpret Q: measure_space "N\<lparr> measure := ?Q \<rparr>" .
hoelzl@39083
   792
hoelzl@39083
   793
  have "P.absolutely_continuous ?Q"
hoelzl@39083
   794
    unfolding P.absolutely_continuous_def
hoelzl@41545
   795
  proof safe
hoelzl@41689
   796
    fix A assume "A \<in> sets N" "P.\<mu> A = 0"
hoelzl@41981
   797
    then have f_borel: "?f A \<in> borel_measurable M" "AE x. x \<notin> A"
hoelzl@41981
   798
      using borel N by (auto intro!: borel_measurable_indicator AE_not_in)
hoelzl@41981
   799
    then show "?Q A = 0"
hoelzl@41981
   800
      by (auto simp add: positive_integral_0_iff_AE)
hoelzl@39083
   801
  qed
hoelzl@39083
   802
  from P.Radon_Nikodym[OF Q this]
hoelzl@41981
   803
  obtain Y where Y: "Y \<in> borel_measurable N" "\<And>x. 0 \<le> Y x"
hoelzl@41689
   804
    "\<And>A. A \<in> sets N \<Longrightarrow> ?Q A =(\<integral>\<^isup>+x. Y x * indicator A x \<partial>N)"
hoelzl@39083
   805
    by blast
hoelzl@41545
   806
  with N(2) show ?thesis
hoelzl@41981
   807
    by (auto intro!: bexI[OF _ Y(1)] simp: positive_integral_subalgebra[OF _ _ N(2,3,4,1)])
hoelzl@39083
   808
qed
hoelzl@39083
   809
hoelzl@39085
   810
definition (in prob_space)
hoelzl@41981
   811
  "conditional_expectation N X = (SOME Y. Y\<in>borel_measurable N \<and> (\<forall>x. 0 \<le> Y x)
hoelzl@41689
   812
    \<and> (\<forall>C\<in>sets N. (\<integral>\<^isup>+x. Y x * indicator C x\<partial>M) = (\<integral>\<^isup>+x. X x * indicator C x\<partial>M)))"
hoelzl@39085
   813
hoelzl@39085
   814
abbreviation (in prob_space)
hoelzl@39092
   815
  "conditional_prob N A \<equiv> conditional_expectation N (indicator A)"
hoelzl@39085
   816
hoelzl@39085
   817
lemma (in prob_space)
hoelzl@41981
   818
  fixes X :: "'a \<Rightarrow> extreal" and N :: "('a, 'b) measure_space_scheme"
hoelzl@41981
   819
  assumes borel: "X \<in> borel_measurable M" "AE x. 0 \<le> X x"
hoelzl@41689
   820
  and N: "sigma_algebra N" "sets N \<subseteq> sets M" "space N = space M" "\<And>A. measure N A = \<mu> A"
hoelzl@39085
   821
  shows borel_measurable_conditional_expectation:
hoelzl@41545
   822
    "conditional_expectation N X \<in> borel_measurable N"
hoelzl@41545
   823
  and conditional_expectation: "\<And>C. C \<in> sets N \<Longrightarrow>
hoelzl@41689
   824
      (\<integral>\<^isup>+x. conditional_expectation N X x * indicator C x \<partial>M) =
hoelzl@41689
   825
      (\<integral>\<^isup>+x. X x * indicator C x \<partial>M)"
hoelzl@41545
   826
   (is "\<And>C. C \<in> sets N \<Longrightarrow> ?eq C")
hoelzl@39085
   827
proof -
hoelzl@39085
   828
  note CE = conditional_expectation_exists[OF assms, unfolded Bex_def]
hoelzl@41545
   829
  then show "conditional_expectation N X \<in> borel_measurable N"
hoelzl@39085
   830
    unfolding conditional_expectation_def by (rule someI2_ex) blast
hoelzl@39085
   831
hoelzl@41545
   832
  from CE show "\<And>C. C \<in> sets N \<Longrightarrow> ?eq C"
hoelzl@39085
   833
    unfolding conditional_expectation_def by (rule someI2_ex) blast
hoelzl@39085
   834
qed
hoelzl@39085
   835
hoelzl@41981
   836
lemma (in sigma_algebra) factorize_measurable_function_pos:
hoelzl@41981
   837
  fixes Z :: "'a \<Rightarrow> extreal" and Y :: "'a \<Rightarrow> 'c"
hoelzl@39091
   838
  assumes "sigma_algebra M'" and "Y \<in> measurable M M'" "Z \<in> borel_measurable M"
hoelzl@41981
   839
  assumes Z: "Z \<in> borel_measurable (sigma_algebra.vimage_algebra M' (space M) Y)"
hoelzl@41981
   840
  shows "\<exists>g\<in>borel_measurable M'. \<forall>x\<in>space M. max 0 (Z x) = g (Y x)"
hoelzl@41981
   841
proof -
hoelzl@39091
   842
  interpret M': sigma_algebra M' by fact
hoelzl@39091
   843
  have Y: "Y \<in> space M \<rightarrow> space M'" using assms unfolding measurable_def by auto
hoelzl@39091
   844
  from M'.sigma_algebra_vimage[OF this]
hoelzl@39091
   845
  interpret va: sigma_algebra "M'.vimage_algebra (space M) Y" .
hoelzl@39091
   846
hoelzl@41981
   847
  from va.borel_measurable_implies_simple_function_sequence'[OF Z] guess f . note f = this
hoelzl@39091
   848
hoelzl@41689
   849
  have "\<forall>i. \<exists>g. simple_function M' g \<and> (\<forall>x\<in>space M. f i x = g (Y x))"
hoelzl@39091
   850
  proof
hoelzl@39091
   851
    fix i
hoelzl@41981
   852
    from f(1)[of i] have "finite (f i`space M)" and B_ex:
hoelzl@39091
   853
      "\<forall>z\<in>(f i)`space M. \<exists>B. B \<in> sets M' \<and> (f i) -` {z} \<inter> space M = Y -` B \<inter> space M"
hoelzl@41689
   854
      unfolding simple_function_def by auto
hoelzl@39091
   855
    from B_ex[THEN bchoice] guess B .. note B = this
hoelzl@39091
   856
hoelzl@39091
   857
    let ?g = "\<lambda>x. \<Sum>z\<in>f i`space M. z * indicator (B z) x"
hoelzl@39091
   858
hoelzl@41689
   859
    show "\<exists>g. simple_function M' g \<and> (\<forall>x\<in>space M. f i x = g (Y x))"
hoelzl@39091
   860
    proof (intro exI[of _ ?g] conjI ballI)
hoelzl@41689
   861
      show "simple_function M' ?g" using B by auto
hoelzl@39091
   862
hoelzl@39091
   863
      fix x assume "x \<in> space M"
hoelzl@41981
   864
      then have "\<And>z. z \<in> f i`space M \<Longrightarrow> indicator (B z) (Y x) = (indicator (f i -` {z} \<inter> space M) x::extreal)"
hoelzl@39091
   865
        unfolding indicator_def using B by auto
hoelzl@41981
   866
      then show "f i x = ?g (Y x)" using `x \<in> space M` f(1)[of i]
hoelzl@39091
   867
        by (subst va.simple_function_indicator_representation) auto
hoelzl@39091
   868
    qed
hoelzl@39091
   869
  qed
hoelzl@39091
   870
  from choice[OF this] guess g .. note g = this
hoelzl@39091
   871
hoelzl@41981
   872
  show ?thesis
hoelzl@39091
   873
  proof (intro ballI bexI)
hoelzl@41097
   874
    show "(\<lambda>x. SUP i. g i x) \<in> borel_measurable M'"
hoelzl@39091
   875
      using g by (auto intro: M'.borel_measurable_simple_function)
hoelzl@39091
   876
    fix x assume "x \<in> space M"
hoelzl@41981
   877
    have "max 0 (Z x) = (SUP i. f i x)" using f by simp
hoelzl@41981
   878
    also have "\<dots> = (SUP i. g i (Y x))"
hoelzl@39091
   879
      using g `x \<in> space M` by simp
hoelzl@41981
   880
    finally show "max 0 (Z x) = (SUP i. g i (Y x))" .
hoelzl@41981
   881
  qed
hoelzl@41981
   882
qed
hoelzl@41981
   883
hoelzl@41981
   884
lemma extreal_0_le_iff_le_0[simp]:
hoelzl@41981
   885
  fixes a :: extreal shows "0 \<le> -a \<longleftrightarrow> a \<le> 0"
hoelzl@41981
   886
  by (cases rule: extreal2_cases[of a]) auto
hoelzl@41981
   887
hoelzl@41981
   888
lemma (in sigma_algebra) factorize_measurable_function:
hoelzl@41981
   889
  fixes Z :: "'a \<Rightarrow> extreal" and Y :: "'a \<Rightarrow> 'c"
hoelzl@41981
   890
  assumes "sigma_algebra M'" and "Y \<in> measurable M M'" "Z \<in> borel_measurable M"
hoelzl@41981
   891
  shows "Z \<in> borel_measurable (sigma_algebra.vimage_algebra M' (space M) Y)
hoelzl@41981
   892
    \<longleftrightarrow> (\<exists>g\<in>borel_measurable M'. \<forall>x\<in>space M. Z x = g (Y x))"
hoelzl@41981
   893
proof safe
hoelzl@41981
   894
  interpret M': sigma_algebra M' by fact
hoelzl@41981
   895
  have Y: "Y \<in> space M \<rightarrow> space M'" using assms unfolding measurable_def by auto
hoelzl@41981
   896
  from M'.sigma_algebra_vimage[OF this]
hoelzl@41981
   897
  interpret va: sigma_algebra "M'.vimage_algebra (space M) Y" .
hoelzl@41981
   898
hoelzl@41981
   899
  { fix g :: "'c \<Rightarrow> extreal" assume "g \<in> borel_measurable M'"
hoelzl@41981
   900
    with M'.measurable_vimage_algebra[OF Y]
hoelzl@41981
   901
    have "g \<circ> Y \<in> borel_measurable (M'.vimage_algebra (space M) Y)"
hoelzl@41981
   902
      by (rule measurable_comp)
hoelzl@41981
   903
    moreover assume "\<forall>x\<in>space M. Z x = g (Y x)"
hoelzl@41981
   904
    then have "Z \<in> borel_measurable (M'.vimage_algebra (space M) Y) \<longleftrightarrow>
hoelzl@41981
   905
       g \<circ> Y \<in> borel_measurable (M'.vimage_algebra (space M) Y)"
hoelzl@41981
   906
       by (auto intro!: measurable_cong)
hoelzl@41981
   907
    ultimately show "Z \<in> borel_measurable (M'.vimage_algebra (space M) Y)"
hoelzl@41981
   908
      by simp }
hoelzl@41981
   909
hoelzl@41981
   910
  assume Z: "Z \<in> borel_measurable (M'.vimage_algebra (space M) Y)"
hoelzl@41981
   911
  with assms have "(\<lambda>x. - Z x) \<in> borel_measurable M"
hoelzl@41981
   912
    "(\<lambda>x. - Z x) \<in> borel_measurable (M'.vimage_algebra (space M) Y)"
hoelzl@41981
   913
    by auto
hoelzl@41981
   914
  from factorize_measurable_function_pos[OF assms(1,2) this] guess n .. note n = this
hoelzl@41981
   915
  from factorize_measurable_function_pos[OF assms Z] guess p .. note p = this
hoelzl@41981
   916
  let "?g x" = "p x - n x"
hoelzl@41981
   917
  show "\<exists>g\<in>borel_measurable M'. \<forall>x\<in>space M. Z x = g (Y x)"
hoelzl@41981
   918
  proof (intro bexI ballI)
hoelzl@41981
   919
    show "?g \<in> borel_measurable M'" using p n by auto
hoelzl@41981
   920
    fix x assume "x \<in> space M"
hoelzl@41981
   921
    then have "p (Y x) = max 0 (Z x)" "n (Y x) = max 0 (- Z x)"
hoelzl@41981
   922
      using p n by auto
hoelzl@41981
   923
    then show "Z x = ?g (Y x)"
hoelzl@41981
   924
      by (auto split: split_max)
hoelzl@39091
   925
  qed
hoelzl@39091
   926
qed
hoelzl@39090
   927
hoelzl@35582
   928
end