src/HOL/Probability/Probability_Space.thy
author hoelzl
Thu Sep 02 17:12:40 2010 +0200 (2010-09-02)
changeset 39092 98de40859858
parent 39091 11314c196e11
child 39096 111756225292
permissions -rw-r--r--
move lemmas to correct theory files
hoelzl@35582
     1
theory Probability_Space
hoelzl@39083
     2
imports Lebesgue_Integration Radon_Nikodym
hoelzl@35582
     3
begin
hoelzl@35582
     4
hoelzl@35582
     5
locale prob_space = measure_space +
hoelzl@38656
     6
  assumes measure_space_1: "\<mu> (space M) = 1"
hoelzl@38656
     7
hoelzl@38656
     8
sublocale prob_space < finite_measure
hoelzl@38656
     9
proof
hoelzl@38656
    10
  from measure_space_1 show "\<mu> (space M) \<noteq> \<omega>" by simp
hoelzl@38656
    11
qed
hoelzl@38656
    12
hoelzl@38656
    13
context prob_space
hoelzl@35582
    14
begin
hoelzl@35582
    15
hoelzl@35582
    16
abbreviation "events \<equiv> sets M"
hoelzl@38656
    17
abbreviation "prob \<equiv> \<lambda>A. real (\<mu> A)"
hoelzl@35582
    18
abbreviation "prob_preserving \<equiv> measure_preserving"
hoelzl@35582
    19
abbreviation "random_variable \<equiv> \<lambda> s X. X \<in> measurable M s"
hoelzl@35582
    20
abbreviation "expectation \<equiv> integral"
hoelzl@35582
    21
hoelzl@35582
    22
definition
hoelzl@35582
    23
  "indep A B \<longleftrightarrow> A \<in> events \<and> B \<in> events \<and> prob (A \<inter> B) = prob A * prob B"
hoelzl@35582
    24
hoelzl@35582
    25
definition
hoelzl@35582
    26
  "indep_families F G \<longleftrightarrow> (\<forall> A \<in> F. \<forall> B \<in> G. indep A B)"
hoelzl@35582
    27
hoelzl@35582
    28
definition
hoelzl@38656
    29
  "distribution X = (\<lambda>s. \<mu> ((X -` s) \<inter> (space M)))"
hoelzl@35582
    30
hoelzl@36624
    31
abbreviation
hoelzl@36624
    32
  "joint_distribution X Y \<equiv> distribution (\<lambda>x. (X x, Y x))"
hoelzl@35582
    33
hoelzl@38656
    34
lemma prob_space: "prob (space M) = 1"
hoelzl@38656
    35
  unfolding measure_space_1 by simp
hoelzl@35582
    36
hoelzl@38656
    37
lemma measure_le_1[simp, intro]:
hoelzl@38656
    38
  assumes "A \<in> events" shows "\<mu> A \<le> 1"
hoelzl@38656
    39
proof -
hoelzl@38656
    40
  have "\<mu> A \<le> \<mu> (space M)"
hoelzl@38656
    41
    using assms sets_into_space by(auto intro!: measure_mono)
hoelzl@38656
    42
  also note measure_space_1
hoelzl@38656
    43
  finally show ?thesis .
hoelzl@38656
    44
qed
hoelzl@35582
    45
hoelzl@35582
    46
lemma prob_compl:
hoelzl@38656
    47
  assumes "A \<in> events"
hoelzl@38656
    48
  shows "prob (space M - A) = 1 - prob A"
hoelzl@38656
    49
  using `A \<in> events`[THEN sets_into_space] `A \<in> events` measure_space_1
hoelzl@38656
    50
  by (subst real_finite_measure_Diff) auto
hoelzl@35582
    51
hoelzl@35582
    52
lemma indep_space:
hoelzl@35582
    53
  assumes "s \<in> events"
hoelzl@35582
    54
  shows "indep (space M) s"
hoelzl@38656
    55
  using assms prob_space by (simp add: indep_def)
hoelzl@35582
    56
hoelzl@38656
    57
lemma prob_space_increasing: "increasing M prob"
hoelzl@38656
    58
  by (auto intro!: real_measure_mono simp: increasing_def)
hoelzl@35582
    59
hoelzl@35582
    60
lemma prob_zero_union:
hoelzl@35582
    61
  assumes "s \<in> events" "t \<in> events" "prob t = 0"
hoelzl@35582
    62
  shows "prob (s \<union> t) = prob s"
hoelzl@38656
    63
using assms
hoelzl@35582
    64
proof -
hoelzl@35582
    65
  have "prob (s \<union> t) \<le> prob s"
hoelzl@38656
    66
    using real_finite_measure_subadditive[of s t] assms by auto
hoelzl@35582
    67
  moreover have "prob (s \<union> t) \<ge> prob s"
hoelzl@38656
    68
    using assms by (blast intro: real_measure_mono)
hoelzl@35582
    69
  ultimately show ?thesis by simp
hoelzl@35582
    70
qed
hoelzl@35582
    71
hoelzl@35582
    72
lemma prob_eq_compl:
hoelzl@35582
    73
  assumes "s \<in> events" "t \<in> events"
hoelzl@35582
    74
  assumes "prob (space M - s) = prob (space M - t)"
hoelzl@35582
    75
  shows "prob s = prob t"
hoelzl@38656
    76
  using assms prob_compl by auto
hoelzl@35582
    77
hoelzl@35582
    78
lemma prob_one_inter:
hoelzl@35582
    79
  assumes events:"s \<in> events" "t \<in> events"
hoelzl@35582
    80
  assumes "prob t = 1"
hoelzl@35582
    81
  shows "prob (s \<inter> t) = prob s"
hoelzl@35582
    82
proof -
hoelzl@38656
    83
  have "prob ((space M - s) \<union> (space M - t)) = prob (space M - s)"
hoelzl@38656
    84
    using events assms  prob_compl[of "t"] by (auto intro!: prob_zero_union)
hoelzl@38656
    85
  also have "(space M - s) \<union> (space M - t) = space M - (s \<inter> t)"
hoelzl@38656
    86
    by blast
hoelzl@38656
    87
  finally show "prob (s \<inter> t) = prob s"
hoelzl@38656
    88
    using events by (auto intro!: prob_eq_compl[of "s \<inter> t" s])
hoelzl@35582
    89
qed
hoelzl@35582
    90
hoelzl@35582
    91
lemma prob_eq_bigunion_image:
hoelzl@35582
    92
  assumes "range f \<subseteq> events" "range g \<subseteq> events"
hoelzl@35582
    93
  assumes "disjoint_family f" "disjoint_family g"
hoelzl@35582
    94
  assumes "\<And> n :: nat. prob (f n) = prob (g n)"
hoelzl@35582
    95
  shows "(prob (\<Union> i. f i) = prob (\<Union> i. g i))"
hoelzl@35582
    96
using assms
hoelzl@35582
    97
proof -
hoelzl@38656
    98
  have a: "(\<lambda> i. prob (f i)) sums (prob (\<Union> i. f i))"
hoelzl@38656
    99
    by (rule real_finite_measure_UNION[OF assms(1,3)])
hoelzl@38656
   100
  have b: "(\<lambda> i. prob (g i)) sums (prob (\<Union> i. g i))"
hoelzl@38656
   101
    by (rule real_finite_measure_UNION[OF assms(2,4)])
hoelzl@38656
   102
  show ?thesis using sums_unique[OF b] sums_unique[OF a] assms by simp
hoelzl@35582
   103
qed
hoelzl@35582
   104
hoelzl@35582
   105
lemma prob_countably_zero:
hoelzl@35582
   106
  assumes "range c \<subseteq> events"
hoelzl@35582
   107
  assumes "\<And> i. prob (c i) = 0"
hoelzl@38656
   108
  shows "prob (\<Union> i :: nat. c i) = 0"
hoelzl@38656
   109
proof (rule antisym)
hoelzl@38656
   110
  show "prob (\<Union> i :: nat. c i) \<le> 0"
hoelzl@38656
   111
    using real_finite_measurable_countably_subadditive[OF assms(1)]
hoelzl@38656
   112
    by (simp add: assms(2) suminf_zero summable_zero)
hoelzl@38656
   113
  show "0 \<le> prob (\<Union> i :: nat. c i)" by (rule real_pinfreal_nonneg)
hoelzl@35582
   114
qed
hoelzl@35582
   115
hoelzl@35582
   116
lemma indep_sym:
hoelzl@35582
   117
   "indep a b \<Longrightarrow> indep b a"
hoelzl@35582
   118
unfolding indep_def using Int_commute[of a b] by auto
hoelzl@35582
   119
hoelzl@35582
   120
lemma indep_refl:
hoelzl@35582
   121
  assumes "a \<in> events"
hoelzl@35582
   122
  shows "indep a a = (prob a = 0) \<or> (prob a = 1)"
hoelzl@35582
   123
using assms unfolding indep_def by auto
hoelzl@35582
   124
hoelzl@35582
   125
lemma prob_equiprobable_finite_unions:
hoelzl@38656
   126
  assumes "s \<in> events"
hoelzl@38656
   127
  assumes s_finite: "finite s" "\<And>x. x \<in> s \<Longrightarrow> {x} \<in> events"
hoelzl@35582
   128
  assumes "\<And> x y. \<lbrakk>x \<in> s; y \<in> s\<rbrakk> \<Longrightarrow> (prob {x} = prob {y})"
hoelzl@38656
   129
  shows "prob s = real (card s) * prob {SOME x. x \<in> s}"
hoelzl@35582
   130
proof (cases "s = {}")
hoelzl@38656
   131
  case False hence "\<exists> x. x \<in> s" by blast
hoelzl@35582
   132
  from someI_ex[OF this] assms
hoelzl@35582
   133
  have prob_some: "\<And> x. x \<in> s \<Longrightarrow> prob {x} = prob {SOME y. y \<in> s}" by blast
hoelzl@35582
   134
  have "prob s = (\<Sum> x \<in> s. prob {x})"
hoelzl@38656
   135
    using real_finite_measure_finite_singelton[OF s_finite] by simp
hoelzl@35582
   136
  also have "\<dots> = (\<Sum> x \<in> s. prob {SOME y. y \<in> s})" using prob_some by auto
hoelzl@38656
   137
  also have "\<dots> = real (card s) * prob {(SOME x. x \<in> s)}"
hoelzl@38656
   138
    using setsum_constant assms by (simp add: real_eq_of_nat)
hoelzl@35582
   139
  finally show ?thesis by simp
hoelzl@38656
   140
qed simp
hoelzl@35582
   141
hoelzl@35582
   142
lemma prob_real_sum_image_fn:
hoelzl@35582
   143
  assumes "e \<in> events"
hoelzl@35582
   144
  assumes "\<And> x. x \<in> s \<Longrightarrow> e \<inter> f x \<in> events"
hoelzl@35582
   145
  assumes "finite s"
hoelzl@38656
   146
  assumes disjoint: "\<And> x y. \<lbrakk>x \<in> s ; y \<in> s ; x \<noteq> y\<rbrakk> \<Longrightarrow> f x \<inter> f y = {}"
hoelzl@38656
   147
  assumes upper: "space M \<subseteq> (\<Union> i \<in> s. f i)"
hoelzl@35582
   148
  shows "prob e = (\<Sum> x \<in> s. prob (e \<inter> f x))"
hoelzl@35582
   149
proof -
hoelzl@38656
   150
  have e: "e = (\<Union> i \<in> s. e \<inter> f i)"
hoelzl@38656
   151
    using `e \<in> events` sets_into_space upper by blast
hoelzl@38656
   152
  hence "prob e = prob (\<Union> i \<in> s. e \<inter> f i)" by simp
hoelzl@38656
   153
  also have "\<dots> = (\<Sum> x \<in> s. prob (e \<inter> f x))"
hoelzl@38656
   154
  proof (rule real_finite_measure_finite_Union)
hoelzl@38656
   155
    show "finite s" by fact
hoelzl@38656
   156
    show "\<And>i. i \<in> s \<Longrightarrow> e \<inter> f i \<in> events" by fact
hoelzl@38656
   157
    show "disjoint_family_on (\<lambda>i. e \<inter> f i) s"
hoelzl@38656
   158
      using disjoint by (auto simp: disjoint_family_on_def)
hoelzl@38656
   159
  qed
hoelzl@38656
   160
  finally show ?thesis .
hoelzl@35582
   161
qed
hoelzl@35582
   162
hoelzl@35582
   163
lemma distribution_prob_space:
hoelzl@39089
   164
  assumes S: "sigma_algebra S" "random_variable S X"
hoelzl@38656
   165
  shows "prob_space S (distribution X)"
hoelzl@35582
   166
proof -
hoelzl@39089
   167
  interpret S: measure_space S "distribution X"
hoelzl@39089
   168
    using measure_space_vimage[OF S(2,1)] unfolding distribution_def .
hoelzl@38656
   169
  show ?thesis
hoelzl@38656
   170
  proof
hoelzl@38656
   171
    have "X -` space S \<inter> space M = space M"
hoelzl@38656
   172
      using `random_variable S X` by (auto simp: measurable_def)
hoelzl@39089
   173
    then show "distribution X (space S) = 1"
hoelzl@39089
   174
      using measure_space_1 by (simp add: distribution_def)
hoelzl@35582
   175
  qed
hoelzl@35582
   176
qed
hoelzl@35582
   177
hoelzl@35582
   178
lemma distribution_lebesgue_thm1:
hoelzl@35582
   179
  assumes "random_variable s X"
hoelzl@35582
   180
  assumes "A \<in> sets s"
hoelzl@38656
   181
  shows "real (distribution X A) = expectation (indicator (X -` A \<inter> space M))"
hoelzl@35582
   182
unfolding distribution_def
hoelzl@35582
   183
using assms unfolding measurable_def
hoelzl@38656
   184
using integral_indicator by auto
hoelzl@35582
   185
hoelzl@35582
   186
lemma distribution_lebesgue_thm2:
hoelzl@38656
   187
  assumes "sigma_algebra S" "random_variable S X" and "A \<in> sets S"
hoelzl@38656
   188
  shows "distribution X A =
hoelzl@38656
   189
    measure_space.positive_integral S (distribution X) (indicator A)"
hoelzl@38656
   190
  (is "_ = measure_space.positive_integral _ ?D _")
hoelzl@35582
   191
proof -
hoelzl@38656
   192
  interpret S: prob_space S "distribution X" using assms(1,2) by (rule distribution_prob_space)
hoelzl@35582
   193
hoelzl@35582
   194
  show ?thesis
hoelzl@38656
   195
    using S.positive_integral_indicator(1)
hoelzl@35582
   196
    using assms unfolding distribution_def by auto
hoelzl@35582
   197
qed
hoelzl@35582
   198
hoelzl@35582
   199
lemma finite_expectation1:
hoelzl@38656
   200
  assumes "finite (X`space M)" and rv: "random_variable borel_space X"
hoelzl@35582
   201
  shows "expectation X = (\<Sum> r \<in> X ` space M. r * prob (X -` {r} \<inter> space M))"
hoelzl@38656
   202
proof (rule integral_on_finite(2)[OF assms(2,1)])
hoelzl@38656
   203
  fix x have "X -` {x} \<inter> space M \<in> sets M"
hoelzl@38656
   204
    using rv unfolding measurable_def by auto
hoelzl@38656
   205
  thus "\<mu> (X -` {x} \<inter> space M) \<noteq> \<omega>" using finite_measure by simp
hoelzl@38656
   206
qed
hoelzl@35582
   207
hoelzl@35582
   208
lemma finite_expectation:
hoelzl@38656
   209
  assumes "finite (space M)" "random_variable borel_space X"
hoelzl@38656
   210
  shows "expectation X = (\<Sum> r \<in> X ` (space M). r * real (distribution X {r}))"
hoelzl@38656
   211
  using assms unfolding distribution_def using finite_expectation1 by auto
hoelzl@38656
   212
hoelzl@35582
   213
lemma prob_x_eq_1_imp_prob_y_eq_0:
hoelzl@35582
   214
  assumes "{x} \<in> events"
hoelzl@38656
   215
  assumes "prob {x} = 1"
hoelzl@35582
   216
  assumes "{y} \<in> events"
hoelzl@35582
   217
  assumes "y \<noteq> x"
hoelzl@35582
   218
  shows "prob {y} = 0"
hoelzl@35582
   219
  using prob_one_inter[of "{y}" "{x}"] assms by auto
hoelzl@35582
   220
hoelzl@38656
   221
lemma distribution_empty[simp]: "distribution X {} = 0"
hoelzl@38656
   222
  unfolding distribution_def by simp
hoelzl@38656
   223
hoelzl@38656
   224
lemma distribution_space[simp]: "distribution X (X ` space M) = 1"
hoelzl@38656
   225
proof -
hoelzl@38656
   226
  have "X -` X ` space M \<inter> space M = space M" by auto
hoelzl@38656
   227
  thus ?thesis unfolding distribution_def by (simp add: measure_space_1)
hoelzl@38656
   228
qed
hoelzl@38656
   229
hoelzl@38656
   230
lemma distribution_one:
hoelzl@38656
   231
  assumes "random_variable M X" and "A \<in> events"
hoelzl@38656
   232
  shows "distribution X A \<le> 1"
hoelzl@38656
   233
proof -
hoelzl@38656
   234
  have "distribution X A \<le> \<mu> (space M)" unfolding distribution_def
hoelzl@38656
   235
    using assms[unfolded measurable_def] by (auto intro!: measure_mono)
hoelzl@38656
   236
  thus ?thesis by (simp add: measure_space_1)
hoelzl@38656
   237
qed
hoelzl@38656
   238
hoelzl@38656
   239
lemma distribution_finite:
hoelzl@38656
   240
  assumes "random_variable M X" and "A \<in> events"
hoelzl@38656
   241
  shows "distribution X A \<noteq> \<omega>"
hoelzl@38656
   242
  using distribution_one[OF assms] by auto
hoelzl@38656
   243
hoelzl@35582
   244
lemma distribution_x_eq_1_imp_distribution_y_eq_0:
hoelzl@35582
   245
  assumes X: "random_variable \<lparr>space = X ` (space M), sets = Pow (X ` (space M))\<rparr> X"
hoelzl@38656
   246
    (is "random_variable ?S X")
hoelzl@38656
   247
  assumes "distribution X {x} = 1"
hoelzl@35582
   248
  assumes "y \<noteq> x"
hoelzl@35582
   249
  shows "distribution X {y} = 0"
hoelzl@35582
   250
proof -
hoelzl@38656
   251
  have "sigma_algebra ?S" by (rule sigma_algebra_Pow)
hoelzl@38656
   252
  from distribution_prob_space[OF this X]
hoelzl@38656
   253
  interpret S: prob_space ?S "distribution X" by simp
hoelzl@38656
   254
hoelzl@38656
   255
  have x: "{x} \<in> sets ?S"
hoelzl@38656
   256
  proof (rule ccontr)
hoelzl@38656
   257
    assume "{x} \<notin> sets ?S"
hoelzl@35582
   258
    hence "X -` {x} \<inter> space M = {}" by auto
hoelzl@38656
   259
    thus "False" using assms unfolding distribution_def by auto
hoelzl@38656
   260
  qed
hoelzl@38656
   261
hoelzl@38656
   262
  have [simp]: "{y} \<inter> {x} = {}" "{x} - {y} = {x}" using `y \<noteq> x` by auto
hoelzl@38656
   263
hoelzl@38656
   264
  show ?thesis
hoelzl@38656
   265
  proof cases
hoelzl@38656
   266
    assume "{y} \<in> sets ?S"
hoelzl@38656
   267
    with `{x} \<in> sets ?S` assms show "distribution X {y} = 0"
hoelzl@38656
   268
      using S.measure_inter_full_set[of "{y}" "{x}"]
hoelzl@38656
   269
      by simp
hoelzl@38656
   270
  next
hoelzl@38656
   271
    assume "{y} \<notin> sets ?S"
hoelzl@35582
   272
    hence "X -` {y} \<inter> space M = {}" by auto
hoelzl@38656
   273
    thus "distribution X {y} = 0" unfolding distribution_def by auto
hoelzl@38656
   274
  qed
hoelzl@35582
   275
qed
hoelzl@35582
   276
hoelzl@35582
   277
end
hoelzl@35582
   278
hoelzl@35977
   279
locale finite_prob_space = prob_space + finite_measure_space
hoelzl@35977
   280
hoelzl@36624
   281
lemma finite_prob_space_eq:
hoelzl@38656
   282
  "finite_prob_space M \<mu> \<longleftrightarrow> finite_measure_space M \<mu> \<and> \<mu> (space M) = 1"
hoelzl@36624
   283
  unfolding finite_prob_space_def finite_measure_space_def prob_space_def prob_space_axioms_def
hoelzl@36624
   284
  by auto
hoelzl@36624
   285
hoelzl@36624
   286
lemma (in prob_space) not_empty: "space M \<noteq> {}"
hoelzl@36624
   287
  using prob_space empty_measure by auto
hoelzl@36624
   288
hoelzl@38656
   289
lemma (in finite_prob_space) sum_over_space_eq_1: "(\<Sum>x\<in>space M. \<mu> {x}) = 1"
hoelzl@38656
   290
  using measure_space_1 sum_over_space by simp
hoelzl@36624
   291
hoelzl@36624
   292
lemma (in finite_prob_space) positive_distribution: "0 \<le> distribution X x"
hoelzl@38656
   293
  unfolding distribution_def by simp
hoelzl@36624
   294
hoelzl@36624
   295
lemma (in finite_prob_space) joint_distribution_restriction_fst:
hoelzl@36624
   296
  "joint_distribution X Y A \<le> distribution X (fst ` A)"
hoelzl@36624
   297
  unfolding distribution_def
hoelzl@36624
   298
proof (safe intro!: measure_mono)
hoelzl@36624
   299
  fix x assume "x \<in> space M" and *: "(X x, Y x) \<in> A"
hoelzl@36624
   300
  show "x \<in> X -` fst ` A"
hoelzl@36624
   301
    by (auto intro!: image_eqI[OF _ *])
hoelzl@36624
   302
qed (simp_all add: sets_eq_Pow)
hoelzl@36624
   303
hoelzl@36624
   304
lemma (in finite_prob_space) joint_distribution_restriction_snd:
hoelzl@36624
   305
  "joint_distribution X Y A \<le> distribution Y (snd ` A)"
hoelzl@36624
   306
  unfolding distribution_def
hoelzl@36624
   307
proof (safe intro!: measure_mono)
hoelzl@36624
   308
  fix x assume "x \<in> space M" and *: "(X x, Y x) \<in> A"
hoelzl@36624
   309
  show "x \<in> Y -` snd ` A"
hoelzl@36624
   310
    by (auto intro!: image_eqI[OF _ *])
hoelzl@36624
   311
qed (simp_all add: sets_eq_Pow)
hoelzl@36624
   312
hoelzl@36624
   313
lemma (in finite_prob_space) distribution_order:
hoelzl@36624
   314
  shows "0 \<le> distribution X x'"
hoelzl@36624
   315
  and "(distribution X x' \<noteq> 0) \<longleftrightarrow> (0 < distribution X x')"
hoelzl@36624
   316
  and "r \<le> joint_distribution X Y {(x, y)} \<Longrightarrow> r \<le> distribution X {x}"
hoelzl@36624
   317
  and "r \<le> joint_distribution X Y {(x, y)} \<Longrightarrow> r \<le> distribution Y {y}"
hoelzl@36624
   318
  and "r < joint_distribution X Y {(x, y)} \<Longrightarrow> r < distribution X {x}"
hoelzl@36624
   319
  and "r < joint_distribution X Y {(x, y)} \<Longrightarrow> r < distribution Y {y}"
hoelzl@36624
   320
  and "distribution X {x} = 0 \<Longrightarrow> joint_distribution X Y {(x, y)} = 0"
hoelzl@36624
   321
  and "distribution Y {y} = 0 \<Longrightarrow> joint_distribution X Y {(x, y)} = 0"
hoelzl@36624
   322
  using positive_distribution[of X x']
hoelzl@36624
   323
    positive_distribution[of "\<lambda>x. (X x, Y x)" "{(x, y)}"]
hoelzl@36624
   324
    joint_distribution_restriction_fst[of X Y "{(x, y)}"]
hoelzl@36624
   325
    joint_distribution_restriction_snd[of X Y "{(x, y)}"]
hoelzl@36624
   326
  by auto
hoelzl@36624
   327
hoelzl@39092
   328
lemma (in finite_prob_space) finite_prob_space_of_images:
hoelzl@39092
   329
  "finite_prob_space \<lparr> space = X ` space M, sets = Pow (X ` space M)\<rparr> (distribution X)"
hoelzl@39092
   330
  by (simp add: finite_prob_space_eq finite_measure_space)
hoelzl@35977
   331
hoelzl@39092
   332
lemma (in finite_prob_space) finite_product_prob_space_of_images:
hoelzl@39092
   333
  "finite_prob_space \<lparr> space = X ` space M \<times> Y ` space M, sets = Pow (X ` space M \<times> Y ` space M)\<rparr>
hoelzl@39092
   334
                     (joint_distribution X Y)"
hoelzl@39092
   335
  (is "finite_prob_space ?S _")
hoelzl@39092
   336
proof (simp add: finite_prob_space_eq finite_product_measure_space_of_images)
hoelzl@39092
   337
  have "X -` X ` space M \<inter> Y -` Y ` space M \<inter> space M = space M" by auto
hoelzl@39092
   338
  thus "joint_distribution X Y (X ` space M \<times> Y ` space M) = 1"
hoelzl@39092
   339
    by (simp add: distribution_def prob_space vimage_Times comp_def measure_space_1)
hoelzl@39092
   340
qed
hoelzl@35977
   341
hoelzl@39092
   342
lemma (in prob_space) prob_space_subalgebra:
hoelzl@39092
   343
  assumes "N \<subseteq> sets M" "sigma_algebra (M\<lparr> sets := N \<rparr>)"
hoelzl@39092
   344
  shows "prob_space (M\<lparr> sets := N \<rparr>) \<mu>"
hoelzl@39092
   345
proof -
hoelzl@39092
   346
  interpret N: measure_space "M\<lparr> sets := N \<rparr>" \<mu>
hoelzl@39092
   347
    using measure_space_subalgebra[OF assms] .
hoelzl@39092
   348
  show ?thesis
hoelzl@39092
   349
    proof qed (simp add: measure_space_1)
hoelzl@35977
   350
qed
hoelzl@35977
   351
hoelzl@39092
   352
lemma (in prob_space) prob_space_of_restricted_space:
hoelzl@39092
   353
  assumes "\<mu> A \<noteq> 0" "\<mu> A \<noteq> \<omega>" "A \<in> sets M"
hoelzl@39092
   354
  shows "prob_space (restricted_space A) (\<lambda>S. \<mu> S / \<mu> A)"
hoelzl@39092
   355
  unfolding prob_space_def prob_space_axioms_def
hoelzl@39092
   356
proof
hoelzl@39092
   357
  show "\<mu> (space (restricted_space A)) / \<mu> A = 1"
hoelzl@39092
   358
    using `\<mu> A \<noteq> 0` `\<mu> A \<noteq> \<omega>` by (auto simp: pinfreal_noteq_omega_Ex)
hoelzl@39092
   359
  have *: "\<And>S. \<mu> S / \<mu> A = inverse (\<mu> A) * \<mu> S" by (simp add: mult_commute)
hoelzl@39092
   360
  interpret A: measure_space "restricted_space A" \<mu>
hoelzl@39092
   361
    using `A \<in> sets M` by (rule restricted_measure_space)
hoelzl@39092
   362
  show "measure_space (restricted_space A) (\<lambda>S. \<mu> S / \<mu> A)"
hoelzl@39092
   363
  proof
hoelzl@39092
   364
    show "\<mu> {} / \<mu> A = 0" by auto
hoelzl@39092
   365
    show "countably_additive (restricted_space A) (\<lambda>S. \<mu> S / \<mu> A)"
hoelzl@39092
   366
        unfolding countably_additive_def psuminf_cmult_right *
hoelzl@39092
   367
        using A.measure_countably_additive by auto
hoelzl@39092
   368
  qed
hoelzl@39092
   369
qed
hoelzl@39092
   370
hoelzl@39092
   371
lemma finite_prob_spaceI:
hoelzl@39092
   372
  assumes "finite (space M)" "sets M = Pow(space M)" "\<mu> (space M) = 1" "\<mu> {} = 0"
hoelzl@39092
   373
    and "\<And>A B. A\<subseteq>space M \<Longrightarrow> B\<subseteq>space M \<Longrightarrow> A \<inter> B = {} \<Longrightarrow> \<mu> (A \<union> B) = \<mu> A + \<mu> B"
hoelzl@39092
   374
  shows "finite_prob_space M \<mu>"
hoelzl@39092
   375
  unfolding finite_prob_space_eq
hoelzl@39092
   376
proof
hoelzl@39092
   377
  show "finite_measure_space M \<mu>" using assms
hoelzl@39092
   378
     by (auto intro!: finite_measure_spaceI)
hoelzl@39092
   379
  show "\<mu> (space M) = 1" by fact
hoelzl@39092
   380
qed
hoelzl@36624
   381
hoelzl@36624
   382
lemma (in finite_prob_space) finite_measure_space:
hoelzl@38656
   383
  shows "finite_measure_space \<lparr>space = X ` space M, sets = Pow (X ` space M)\<rparr> (distribution X)"
hoelzl@38656
   384
    (is "finite_measure_space ?S _")
hoelzl@39092
   385
proof (rule finite_measure_spaceI, simp_all)
hoelzl@36624
   386
  show "finite (X ` space M)" using finite_space by simp
hoelzl@36624
   387
hoelzl@38656
   388
  show "positive (distribution X)"
hoelzl@38656
   389
    unfolding distribution_def positive_def using sets_eq_Pow by auto
hoelzl@36624
   390
hoelzl@36624
   391
  show "additive ?S (distribution X)" unfolding additive_def distribution_def
hoelzl@36624
   392
  proof (simp, safe)
hoelzl@36624
   393
    fix x y
hoelzl@36624
   394
    have x: "(X -` x) \<inter> space M \<in> sets M"
hoelzl@36624
   395
      and y: "(X -` y) \<inter> space M \<in> sets M" using sets_eq_Pow by auto
hoelzl@36624
   396
    assume "x \<inter> y = {}"
hoelzl@38656
   397
    hence "X -` x \<inter> space M \<inter> (X -` y \<inter> space M) = {}" by auto
hoelzl@36624
   398
    from additive[unfolded additive_def, rule_format, OF x y] this
hoelzl@38656
   399
      finite_measure[OF x] finite_measure[OF y]
hoelzl@38656
   400
    have "\<mu> (((X -` x) \<union> (X -` y)) \<inter> space M) =
hoelzl@38656
   401
      \<mu> ((X -` x) \<inter> space M) + \<mu> ((X -` y) \<inter> space M)"
hoelzl@38656
   402
      by (subst Int_Un_distrib2) auto
hoelzl@38656
   403
    thus "\<mu> ((X -` x \<union> X -` y) \<inter> space M) = \<mu> (X -` x \<inter> space M) + \<mu> (X -` y \<inter> space M)"
hoelzl@36624
   404
      by auto
hoelzl@36624
   405
  qed
hoelzl@38656
   406
hoelzl@38656
   407
  { fix x assume "x \<in> X ` space M" thus "distribution X {x} \<noteq> \<omega>"
hoelzl@38656
   408
    unfolding distribution_def by (auto intro!: finite_measure simp: sets_eq_Pow) }
hoelzl@36624
   409
qed
hoelzl@36624
   410
hoelzl@39085
   411
section "Conditional Expectation and Probability"
hoelzl@39085
   412
hoelzl@39085
   413
lemma (in prob_space) conditional_expectation_exists:
hoelzl@39083
   414
  fixes X :: "'a \<Rightarrow> pinfreal"
hoelzl@39083
   415
  assumes borel: "X \<in> borel_measurable M"
hoelzl@39083
   416
  and N_subalgebra: "N \<subseteq> sets M" "sigma_algebra (M\<lparr> sets := N \<rparr>)"
hoelzl@39083
   417
  shows "\<exists>Y\<in>borel_measurable (M\<lparr> sets := N \<rparr>). \<forall>C\<in>N.
hoelzl@39083
   418
      positive_integral (\<lambda>x. Y x * indicator C x) = positive_integral (\<lambda>x. X x * indicator C x)"
hoelzl@39083
   419
proof -
hoelzl@39083
   420
  interpret P: prob_space "M\<lparr> sets := N \<rparr>" \<mu>
hoelzl@39083
   421
    using prob_space_subalgebra[OF N_subalgebra] .
hoelzl@39083
   422
hoelzl@39083
   423
  let "?f A" = "\<lambda>x. X x * indicator A x"
hoelzl@39083
   424
  let "?Q A" = "positive_integral (?f A)"
hoelzl@39083
   425
hoelzl@39083
   426
  from measure_space_density[OF borel]
hoelzl@39083
   427
  have Q: "measure_space (M\<lparr> sets := N \<rparr>) ?Q"
hoelzl@39083
   428
    by (rule measure_space.measure_space_subalgebra[OF _ N_subalgebra])
hoelzl@39083
   429
  then interpret Q: measure_space "M\<lparr> sets := N \<rparr>" ?Q .
hoelzl@39083
   430
hoelzl@39083
   431
  have "P.absolutely_continuous ?Q"
hoelzl@39083
   432
    unfolding P.absolutely_continuous_def
hoelzl@39083
   433
  proof (safe, simp)
hoelzl@39083
   434
    fix A assume "A \<in> N" "\<mu> A = 0"
hoelzl@39083
   435
    moreover then have f_borel: "?f A \<in> borel_measurable M"
hoelzl@39083
   436
      using borel N_subalgebra by (auto intro: borel_measurable_indicator)
hoelzl@39083
   437
    moreover have "{x\<in>space M. ?f A x \<noteq> 0} = (?f A -` {0<..} \<inter> space M) \<inter> A"
hoelzl@39083
   438
      by (auto simp: indicator_def)
hoelzl@39083
   439
    moreover have "\<mu> \<dots> \<le> \<mu> A"
hoelzl@39083
   440
      using `A \<in> N` N_subalgebra f_borel
hoelzl@39083
   441
      by (auto intro!: measure_mono Int[of _ A] measurable_sets)
hoelzl@39083
   442
    ultimately show "?Q A = 0"
hoelzl@39083
   443
      by (simp add: positive_integral_0_iff)
hoelzl@39083
   444
  qed
hoelzl@39083
   445
  from P.Radon_Nikodym[OF Q this]
hoelzl@39083
   446
  obtain Y where Y: "Y \<in> borel_measurable (M\<lparr>sets := N\<rparr>)"
hoelzl@39083
   447
    "\<And>A. A \<in> sets (M\<lparr>sets:=N\<rparr>) \<Longrightarrow> ?Q A = P.positive_integral (\<lambda>x. Y x * indicator A x)"
hoelzl@39083
   448
    by blast
hoelzl@39084
   449
  with N_subalgebra show ?thesis
hoelzl@39084
   450
    by (auto intro!: bexI[OF _ Y(1)])
hoelzl@39083
   451
qed
hoelzl@39083
   452
hoelzl@39085
   453
definition (in prob_space)
hoelzl@39085
   454
  "conditional_expectation N X = (SOME Y. Y\<in>borel_measurable (M\<lparr>sets:=N\<rparr>)
hoelzl@39085
   455
    \<and> (\<forall>C\<in>N. positive_integral (\<lambda>x. Y x * indicator C x) = positive_integral (\<lambda>x. X x * indicator C x)))"
hoelzl@39085
   456
hoelzl@39085
   457
abbreviation (in prob_space)
hoelzl@39092
   458
  "conditional_prob N A \<equiv> conditional_expectation N (indicator A)"
hoelzl@39085
   459
hoelzl@39085
   460
lemma (in prob_space)
hoelzl@39085
   461
  fixes X :: "'a \<Rightarrow> pinfreal"
hoelzl@39085
   462
  assumes borel: "X \<in> borel_measurable M"
hoelzl@39085
   463
  and N_subalgebra: "N \<subseteq> sets M" "sigma_algebra (M\<lparr> sets := N \<rparr>)"
hoelzl@39085
   464
  shows borel_measurable_conditional_expectation:
hoelzl@39085
   465
    "conditional_expectation N X \<in> borel_measurable (M\<lparr> sets := N \<rparr>)"
hoelzl@39085
   466
  and conditional_expectation: "\<And>C. C \<in> N \<Longrightarrow>
hoelzl@39085
   467
      positive_integral (\<lambda>x. conditional_expectation N X x * indicator C x) =
hoelzl@39085
   468
      positive_integral (\<lambda>x. X x * indicator C x)"
hoelzl@39085
   469
   (is "\<And>C. C \<in> N \<Longrightarrow> ?eq C")
hoelzl@39085
   470
proof -
hoelzl@39085
   471
  note CE = conditional_expectation_exists[OF assms, unfolded Bex_def]
hoelzl@39085
   472
  then show "conditional_expectation N X \<in> borel_measurable (M\<lparr> sets := N \<rparr>)"
hoelzl@39085
   473
    unfolding conditional_expectation_def by (rule someI2_ex) blast
hoelzl@39085
   474
hoelzl@39085
   475
  from CE show "\<And>C. C\<in>N \<Longrightarrow> ?eq C"
hoelzl@39085
   476
    unfolding conditional_expectation_def by (rule someI2_ex) blast
hoelzl@39085
   477
qed
hoelzl@39085
   478
hoelzl@39091
   479
lemma (in sigma_algebra) factorize_measurable_function:
hoelzl@39091
   480
  fixes Z :: "'a \<Rightarrow> pinfreal" and Y :: "'a \<Rightarrow> 'c"
hoelzl@39091
   481
  assumes "sigma_algebra M'" and "Y \<in> measurable M M'" "Z \<in> borel_measurable M"
hoelzl@39091
   482
  shows "Z \<in> borel_measurable (sigma_algebra.vimage_algebra M' (space M) Y)
hoelzl@39091
   483
    \<longleftrightarrow> (\<exists>g\<in>borel_measurable M'. \<forall>x\<in>space M. Z x = g (Y x))"
hoelzl@39091
   484
proof safe
hoelzl@39091
   485
  interpret M': sigma_algebra M' by fact
hoelzl@39091
   486
  have Y: "Y \<in> space M \<rightarrow> space M'" using assms unfolding measurable_def by auto
hoelzl@39091
   487
  from M'.sigma_algebra_vimage[OF this]
hoelzl@39091
   488
  interpret va: sigma_algebra "M'.vimage_algebra (space M) Y" .
hoelzl@39091
   489
hoelzl@39091
   490
  { fix g :: "'c \<Rightarrow> pinfreal" assume "g \<in> borel_measurable M'"
hoelzl@39091
   491
    with M'.measurable_vimage_algebra[OF Y]
hoelzl@39091
   492
    have "g \<circ> Y \<in> borel_measurable (M'.vimage_algebra (space M) Y)"
hoelzl@39091
   493
      by (rule measurable_comp)
hoelzl@39091
   494
    moreover assume "\<forall>x\<in>space M. Z x = g (Y x)"
hoelzl@39091
   495
    then have "Z \<in> borel_measurable (M'.vimage_algebra (space M) Y) \<longleftrightarrow>
hoelzl@39091
   496
       g \<circ> Y \<in> borel_measurable (M'.vimage_algebra (space M) Y)"
hoelzl@39091
   497
       by (auto intro!: measurable_cong)
hoelzl@39091
   498
    ultimately show "Z \<in> borel_measurable (M'.vimage_algebra (space M) Y)"
hoelzl@39091
   499
      by simp }
hoelzl@39091
   500
hoelzl@39091
   501
  assume "Z \<in> borel_measurable (M'.vimage_algebra (space M) Y)"
hoelzl@39091
   502
  from va.borel_measurable_implies_simple_function_sequence[OF this]
hoelzl@39091
   503
  obtain f where f: "\<And>i. va.simple_function (f i)" and "f \<up> Z" by blast
hoelzl@39091
   504
hoelzl@39091
   505
  have "\<forall>i. \<exists>g. M'.simple_function g \<and> (\<forall>x\<in>space M. f i x = g (Y x))"
hoelzl@39091
   506
  proof
hoelzl@39091
   507
    fix i
hoelzl@39091
   508
    from f[of i] have "finite (f i`space M)" and B_ex:
hoelzl@39091
   509
      "\<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@39091
   510
      unfolding va.simple_function_def by auto
hoelzl@39091
   511
    from B_ex[THEN bchoice] guess B .. note B = this
hoelzl@39091
   512
hoelzl@39091
   513
    let ?g = "\<lambda>x. \<Sum>z\<in>f i`space M. z * indicator (B z) x"
hoelzl@39091
   514
hoelzl@39091
   515
    show "\<exists>g. M'.simple_function g \<and> (\<forall>x\<in>space M. f i x = g (Y x))"
hoelzl@39091
   516
    proof (intro exI[of _ ?g] conjI ballI)
hoelzl@39091
   517
      show "M'.simple_function ?g" using B by auto
hoelzl@39091
   518
hoelzl@39091
   519
      fix x assume "x \<in> space M"
hoelzl@39091
   520
      then have "\<And>z. z \<in> f i`space M \<Longrightarrow> indicator (B z) (Y x) = (indicator (f i -` {z} \<inter> space M) x::pinfreal)"
hoelzl@39091
   521
        unfolding indicator_def using B by auto
hoelzl@39091
   522
      then show "f i x = ?g (Y x)" using `x \<in> space M` f[of i]
hoelzl@39091
   523
        by (subst va.simple_function_indicator_representation) auto
hoelzl@39091
   524
    qed
hoelzl@39091
   525
  qed
hoelzl@39091
   526
  from choice[OF this] guess g .. note g = this
hoelzl@39091
   527
hoelzl@39091
   528
  show "\<exists>g\<in>borel_measurable M'. \<forall>x\<in>space M. Z x = g (Y x)"
hoelzl@39091
   529
  proof (intro ballI bexI)
hoelzl@39091
   530
    show "(SUP i. g i) \<in> borel_measurable M'"
hoelzl@39091
   531
      using g by (auto intro: M'.borel_measurable_simple_function)
hoelzl@39091
   532
    fix x assume "x \<in> space M"
hoelzl@39091
   533
    have "Z x = (SUP i. f i) x" using `f \<up> Z` unfolding isoton_def by simp
hoelzl@39091
   534
    also have "\<dots> = (SUP i. g i) (Y x)" unfolding SUPR_fun_expand
hoelzl@39091
   535
      using g `x \<in> space M` by simp
hoelzl@39091
   536
    finally show "Z x = (SUP i. g i) (Y x)" .
hoelzl@39091
   537
  qed
hoelzl@39091
   538
qed
hoelzl@39090
   539
hoelzl@35582
   540
end