src/HOL/Probability/Probability_Space.thy
author hoelzl
Fri Mar 26 18:03:01 2010 +0100 (2010-03-26)
changeset 35977 30d42bfd0174
parent 35929 90f38c8831e2
child 36624 25153c08655e
permissions -rw-r--r--
Added finite measure space.
hoelzl@35582
     1
theory Probability_Space
hoelzl@35582
     2
imports Lebesgue
hoelzl@35582
     3
begin
hoelzl@35582
     4
hoelzl@35582
     5
locale prob_space = measure_space +
hoelzl@35582
     6
  assumes prob_space: "measure M (space M) = 1"
hoelzl@35582
     7
begin
hoelzl@35582
     8
hoelzl@35582
     9
abbreviation "events \<equiv> sets M"
hoelzl@35582
    10
abbreviation "prob \<equiv> measure M"
hoelzl@35582
    11
abbreviation "prob_preserving \<equiv> measure_preserving"
hoelzl@35582
    12
abbreviation "random_variable \<equiv> \<lambda> s X. X \<in> measurable M s"
hoelzl@35582
    13
abbreviation "expectation \<equiv> integral"
hoelzl@35582
    14
hoelzl@35582
    15
definition
hoelzl@35582
    16
  "indep A B \<longleftrightarrow> A \<in> events \<and> B \<in> events \<and> prob (A \<inter> B) = prob A * prob B"
hoelzl@35582
    17
hoelzl@35582
    18
definition
hoelzl@35582
    19
  "indep_families F G \<longleftrightarrow> (\<forall> A \<in> F. \<forall> B \<in> G. indep A B)"
hoelzl@35582
    20
hoelzl@35582
    21
definition
hoelzl@35582
    22
  "distribution X = (\<lambda>s. prob ((X -` s) \<inter> (space M)))"
hoelzl@35582
    23
hoelzl@35582
    24
definition
hoelzl@35582
    25
  "probably e \<longleftrightarrow> e \<in> events \<and> prob e = 1"
hoelzl@35582
    26
hoelzl@35582
    27
definition
hoelzl@35582
    28
  "possibly e \<longleftrightarrow> e \<in> events \<and> prob e \<noteq> 0"
hoelzl@35582
    29
hoelzl@35582
    30
definition
hoelzl@35582
    31
  "joint_distribution X Y \<equiv> (\<lambda>a. prob ((\<lambda>x. (X x, Y x)) -` a \<inter> space M))"
hoelzl@35582
    32
hoelzl@35582
    33
definition
hoelzl@35582
    34
  "conditional_expectation X s \<equiv> THE f. random_variable borel_space f \<and>
hoelzl@35582
    35
    (\<forall> g \<in> s. integral (\<lambda>x. f x * indicator_fn g x) =
hoelzl@35582
    36
              integral (\<lambda>x. X x * indicator_fn g x))"
hoelzl@35582
    37
hoelzl@35582
    38
definition
hoelzl@35582
    39
  "conditional_prob e1 e2 \<equiv> conditional_expectation (indicator_fn e1) e2"
hoelzl@35582
    40
hoelzl@35929
    41
lemma positive': "positive M prob"
hoelzl@35582
    42
  unfolding positive_def using positive empty_measure by blast
hoelzl@35582
    43
hoelzl@35582
    44
lemma prob_compl:
hoelzl@35582
    45
  assumes "s \<in> events"
hoelzl@35582
    46
  shows "prob (space M - s) = 1 - prob s"
hoelzl@35582
    47
using assms
hoelzl@35582
    48
proof -
hoelzl@35582
    49
  have "prob ((space M - s) \<union> s) = prob (space M - s) + prob s"
hoelzl@35582
    50
    using assms additive[unfolded additive_def] by blast
hoelzl@35582
    51
  thus ?thesis by (simp add:Un_absorb2[OF sets_into_space[OF assms]] prob_space)
hoelzl@35582
    52
qed
hoelzl@35582
    53
hoelzl@35582
    54
lemma indep_space:
hoelzl@35582
    55
  assumes "s \<in> events"
hoelzl@35582
    56
  shows "indep (space M) s"
hoelzl@35582
    57
using assms prob_space
hoelzl@35582
    58
unfolding indep_def by auto
hoelzl@35582
    59
hoelzl@35582
    60
hoelzl@35582
    61
lemma prob_space_increasing:
hoelzl@35582
    62
  "increasing M prob"
hoelzl@35929
    63
by (rule additive_increasing[OF positive' additive])
hoelzl@35582
    64
hoelzl@35582
    65
lemma prob_subadditive:
hoelzl@35582
    66
  assumes "s \<in> events" "t \<in> events"
hoelzl@35582
    67
  shows "prob (s \<union> t) \<le> prob s + prob t"
hoelzl@35582
    68
using assms
hoelzl@35582
    69
proof -
hoelzl@35582
    70
  have "prob (s \<union> t) = prob ((s - t) \<union> t)" by simp
hoelzl@35582
    71
  also have "\<dots> = prob (s - t) + prob t"
hoelzl@35582
    72
    using additive[unfolded additive_def, rule_format, of "s-t" "t"] 
hoelzl@35582
    73
      assms by blast
hoelzl@35582
    74
  also have "\<dots> \<le> prob s + prob t"
hoelzl@35582
    75
    using prob_space_increasing[unfolded increasing_def, rule_format] assms
hoelzl@35582
    76
    by auto
hoelzl@35582
    77
  finally show ?thesis by simp
hoelzl@35582
    78
qed
hoelzl@35582
    79
hoelzl@35582
    80
lemma prob_zero_union:
hoelzl@35582
    81
  assumes "s \<in> events" "t \<in> events" "prob t = 0"
hoelzl@35582
    82
  shows "prob (s \<union> t) = prob s"
hoelzl@35582
    83
using assms 
hoelzl@35582
    84
proof -
hoelzl@35582
    85
  have "prob (s \<union> t) \<le> prob s"
hoelzl@35582
    86
    using prob_subadditive[of s t] assms by auto
hoelzl@35582
    87
  moreover have "prob (s \<union> t) \<ge> prob s"
hoelzl@35582
    88
    using prob_space_increasing[unfolded increasing_def, rule_format] 
hoelzl@35582
    89
      assms by auto
hoelzl@35582
    90
  ultimately show ?thesis by simp
hoelzl@35582
    91
qed
hoelzl@35582
    92
hoelzl@35582
    93
lemma prob_eq_compl:
hoelzl@35582
    94
  assumes "s \<in> events" "t \<in> events"
hoelzl@35582
    95
  assumes "prob (space M - s) = prob (space M - t)"
hoelzl@35582
    96
  shows "prob s = prob t"
hoelzl@35582
    97
using assms prob_compl by auto
hoelzl@35582
    98
hoelzl@35582
    99
lemma prob_one_inter:
hoelzl@35582
   100
  assumes events:"s \<in> events" "t \<in> events"
hoelzl@35582
   101
  assumes "prob t = 1"
hoelzl@35582
   102
  shows "prob (s \<inter> t) = prob s"
hoelzl@35582
   103
using assms
hoelzl@35582
   104
proof -
hoelzl@35582
   105
  have "prob ((space M - s) \<union> (space M - t)) = prob (space M - s)" 
hoelzl@35582
   106
    using prob_compl[of "t"] prob_zero_union assms by auto
hoelzl@35582
   107
  then show "prob (s \<inter> t) = prob s" 
hoelzl@35582
   108
    using prob_eq_compl[of "s \<inter> t"] events by (simp only: Diff_Int) auto
hoelzl@35582
   109
qed
hoelzl@35582
   110
hoelzl@35582
   111
lemma prob_eq_bigunion_image:
hoelzl@35582
   112
  assumes "range f \<subseteq> events" "range g \<subseteq> events"
hoelzl@35582
   113
  assumes "disjoint_family f" "disjoint_family g"
hoelzl@35582
   114
  assumes "\<And> n :: nat. prob (f n) = prob (g n)"
hoelzl@35582
   115
  shows "(prob (\<Union> i. f i) = prob (\<Union> i. g i))"
hoelzl@35582
   116
using assms 
hoelzl@35582
   117
proof -
hoelzl@35582
   118
  have a: "(\<lambda> i. prob (f i)) sums (prob (\<Union> i. f i))" 
hoelzl@35582
   119
    using ca[unfolded countably_additive_def] assms by blast
hoelzl@35582
   120
  have b: "(\<lambda> i. prob (g i)) sums (prob (\<Union> i. g i))"
hoelzl@35582
   121
    using ca[unfolded countably_additive_def] assms by blast
hoelzl@35582
   122
  show ?thesis using sums_unique[OF b] sums_unique[OF a] assms by simp
hoelzl@35582
   123
qed
hoelzl@35582
   124
hoelzl@35582
   125
lemma prob_countably_subadditive: 
hoelzl@35582
   126
  assumes "range f \<subseteq> events" 
hoelzl@35582
   127
  assumes "summable (prob \<circ> f)"
hoelzl@35582
   128
  shows "prob (\<Union>i. f i) \<le> (\<Sum> i. prob (f i))"
hoelzl@35582
   129
using assms
hoelzl@35582
   130
proof -
hoelzl@35582
   131
  def f' == "\<lambda> i. f i - (\<Union> j \<in> {0 ..< i}. f j)"
hoelzl@35582
   132
  have "(\<Union> i. f' i) \<subseteq> (\<Union> i. f i)" unfolding f'_def by auto
hoelzl@35582
   133
  moreover have "(\<Union> i. f' i) \<supseteq> (\<Union> i. f i)"
hoelzl@35582
   134
  proof (rule subsetI)
hoelzl@35582
   135
    fix x assume "x \<in> (\<Union> i. f i)"
hoelzl@35582
   136
    then obtain k where "x \<in> f k" by blast
hoelzl@35582
   137
    hence k: "k \<in> {m. x \<in> f m}" by simp
hoelzl@35582
   138
    have "\<exists> l. x \<in> f l \<and> (\<forall> l' < l. x \<notin> f l')"
hoelzl@35582
   139
      using wfE_min[of "{(x, y). x < y}" "k" "{m. x \<in> f m}", 
hoelzl@35582
   140
        OF wf_less k] by auto
hoelzl@35582
   141
    thus "x \<in> (\<Union> i. f' i)" unfolding f'_def by auto
hoelzl@35582
   142
  qed
hoelzl@35582
   143
  ultimately have uf'f: "(\<Union> i. f' i) = (\<Union> i. f i)" by (rule equalityI)
hoelzl@35582
   144
hoelzl@35582
   145
  have df': "\<And> i j. i < j \<Longrightarrow> f' i \<inter> f' j = {}"
hoelzl@35582
   146
    unfolding f'_def by auto
hoelzl@35582
   147
  have "\<And> i j. i \<noteq> j \<Longrightarrow> f' i \<inter> f' j = {}"
hoelzl@35582
   148
    apply (drule iffD1[OF nat_neq_iff])
hoelzl@35582
   149
    using df' by auto
hoelzl@35582
   150
  hence df: "disjoint_family f'" unfolding disjoint_family_on_def by simp
hoelzl@35582
   151
hoelzl@35582
   152
  have rf': "\<And> i. f' i \<in> events"
hoelzl@35582
   153
  proof -
hoelzl@35582
   154
    fix i :: nat
hoelzl@35582
   155
    have "(\<Union> {f j | j. j \<in> {0 ..< i}}) = (\<Union> j \<in> {0 ..< i}. f j)" by blast
hoelzl@35582
   156
    hence "(\<Union> {f j | j. j \<in> {0 ..< i}}) \<in> events 
hoelzl@35582
   157
      \<Longrightarrow> (\<Union> j \<in> {0 ..< i}. f j) \<in> events" by auto
hoelzl@35582
   158
    thus "f' i \<in> events" 
hoelzl@35582
   159
      unfolding f'_def 
hoelzl@35582
   160
      using assms finite_union[of "{f j | j. j \<in> {0 ..< i}}"]
hoelzl@35582
   161
        Diff[of "f i" "\<Union> j \<in> {0 ..< i}. f j"] by auto
hoelzl@35582
   162
  qed
hoelzl@35582
   163
  hence uf': "(\<Union> range f') \<in> events" by auto
hoelzl@35582
   164
  
hoelzl@35582
   165
  have "\<And> i. prob (f' i) \<le> prob (f i)"
hoelzl@35582
   166
    using prob_space_increasing[unfolded increasing_def, rule_format, OF rf']
hoelzl@35582
   167
      assms rf' unfolding f'_def by blast
hoelzl@35582
   168
hoelzl@35582
   169
  hence absinc: "\<And> i. \<bar> prob (f' i) \<bar> \<le> prob (f i)"
hoelzl@35929
   170
    using abs_of_nonneg positive'[unfolded positive_def]
hoelzl@35582
   171
      assms rf' by auto
hoelzl@35582
   172
hoelzl@35582
   173
  have "prob (\<Union> i. f i) = prob (\<Union> i. f' i)" using uf'f by simp
hoelzl@35582
   174
hoelzl@35582
   175
  also have "\<dots> = (\<Sum> i. prob (f' i))"
hoelzl@35582
   176
    using ca[unfolded countably_additive_def, rule_format]
hoelzl@35582
   177
    sums_unique rf' uf' df
hoelzl@35582
   178
    by auto
hoelzl@35582
   179
  
hoelzl@35582
   180
  also have "\<dots> \<le> (\<Sum> i. prob (f i))"
hoelzl@35582
   181
    using summable_le2[of "\<lambda> i. prob (f' i)" "\<lambda> i. prob (f i)", 
hoelzl@35582
   182
      rule_format, OF absinc]
hoelzl@35582
   183
      assms[unfolded o_def] by auto
hoelzl@35582
   184
hoelzl@35582
   185
  finally show ?thesis by auto
hoelzl@35582
   186
qed
hoelzl@35582
   187
hoelzl@35582
   188
lemma prob_countably_zero:
hoelzl@35582
   189
  assumes "range c \<subseteq> events"
hoelzl@35582
   190
  assumes "\<And> i. prob (c i) = 0"
hoelzl@35582
   191
  shows "(prob (\<Union> i :: nat. c i) = 0)"
hoelzl@35582
   192
  using assms
hoelzl@35582
   193
proof -
hoelzl@35582
   194
  have leq0: "0 \<le> prob (\<Union> i. c i)"
hoelzl@35929
   195
    using assms positive'[unfolded positive_def, rule_format] 
hoelzl@35582
   196
    by auto
hoelzl@35582
   197
hoelzl@35582
   198
  have "prob (\<Union> i. c i) \<le> (\<Sum> i. prob (c i))"
hoelzl@35582
   199
    using prob_countably_subadditive[of c, unfolded o_def]
hoelzl@35582
   200
      assms sums_zero sums_summable by auto
hoelzl@35582
   201
hoelzl@35582
   202
  also have "\<dots> = 0"
hoelzl@35582
   203
    using assms sums_zero 
hoelzl@35582
   204
      sums_unique[of "\<lambda> i. prob (c i)" "0"] by auto
hoelzl@35582
   205
hoelzl@35582
   206
  finally show "prob (\<Union> i. c i) = 0"
hoelzl@35582
   207
    using leq0 by auto
hoelzl@35582
   208
qed
hoelzl@35582
   209
hoelzl@35582
   210
lemma indep_sym:
hoelzl@35582
   211
   "indep a b \<Longrightarrow> indep b a"
hoelzl@35582
   212
unfolding indep_def using Int_commute[of a b] by auto
hoelzl@35582
   213
hoelzl@35582
   214
lemma indep_refl:
hoelzl@35582
   215
  assumes "a \<in> events"
hoelzl@35582
   216
  shows "indep a a = (prob a = 0) \<or> (prob a = 1)"
hoelzl@35582
   217
using assms unfolding indep_def by auto
hoelzl@35582
   218
hoelzl@35582
   219
lemma prob_equiprobable_finite_unions:
hoelzl@35582
   220
  assumes "s \<in> events" 
hoelzl@35582
   221
  assumes "\<And>x. x \<in> s \<Longrightarrow> {x} \<in> events"
hoelzl@35582
   222
  assumes "finite s"
hoelzl@35582
   223
  assumes "\<And> x y. \<lbrakk>x \<in> s; y \<in> s\<rbrakk> \<Longrightarrow> (prob {x} = prob {y})"
hoelzl@35582
   224
  shows "prob s = of_nat (card s) * prob {SOME x. x \<in> s}"
hoelzl@35582
   225
using assms
hoelzl@35582
   226
proof (cases "s = {}")
hoelzl@35582
   227
  case True thus ?thesis by simp
hoelzl@35582
   228
next
hoelzl@35582
   229
  case False hence " \<exists> x. x \<in> s" by blast
hoelzl@35582
   230
  from someI_ex[OF this] assms
hoelzl@35582
   231
  have prob_some: "\<And> x. x \<in> s \<Longrightarrow> prob {x} = prob {SOME y. y \<in> s}" by blast
hoelzl@35582
   232
  have "prob s = (\<Sum> x \<in> s. prob {x})"
hoelzl@35582
   233
    using assms measure_real_sum_image by blast
hoelzl@35582
   234
  also have "\<dots> = (\<Sum> x \<in> s. prob {SOME y. y \<in> s})" using prob_some by auto
hoelzl@35582
   235
  also have "\<dots> = of_nat (card s) * prob {(SOME x. x \<in> s)}"
hoelzl@35582
   236
    using setsum_constant assms by auto
hoelzl@35582
   237
  finally show ?thesis by simp
hoelzl@35582
   238
qed
hoelzl@35582
   239
hoelzl@35582
   240
lemma prob_real_sum_image_fn:
hoelzl@35582
   241
  assumes "e \<in> events"
hoelzl@35582
   242
  assumes "\<And> x. x \<in> s \<Longrightarrow> e \<inter> f x \<in> events"
hoelzl@35582
   243
  assumes "finite s"
hoelzl@35582
   244
  assumes "\<And> x y. \<lbrakk>x \<in> s ; y \<in> s ; x \<noteq> y\<rbrakk> \<Longrightarrow> f x \<inter> f y = {}"
hoelzl@35582
   245
  assumes "space M \<subseteq> (\<Union> i \<in> s. f i)"
hoelzl@35582
   246
  shows "prob e = (\<Sum> x \<in> s. prob (e \<inter> f x))"
hoelzl@35582
   247
using assms
hoelzl@35582
   248
proof -
hoelzl@35582
   249
  let ?S = "{0 ..< card s}"
hoelzl@35582
   250
  obtain g where "g ` ?S = s \<and> inj_on g ?S"
hoelzl@35582
   251
    using ex_bij_betw_nat_finite[unfolded bij_betw_def, of s] assms by auto
hoelzl@35582
   252
  moreover hence gs: "g ` ?S = s" by simp
hoelzl@35582
   253
  ultimately have ginj: "inj_on g ?S" by simp
hoelzl@35582
   254
  let ?f' = "\<lambda> i. e \<inter> f (g i)"
hoelzl@35582
   255
  have f': "?f' \<in> ?S \<rightarrow> events"
hoelzl@35582
   256
    using gs assms by blast
hoelzl@35582
   257
  hence "\<And> i j. \<lbrakk>i \<in> ?S ; j \<in> ?S ; i \<noteq> j\<rbrakk> 
hoelzl@35582
   258
    \<Longrightarrow> ?f' i \<inter> ?f' j = {}" using assms ginj[unfolded inj_on_def] gs f' by blast
hoelzl@35582
   259
  hence df': "\<And> i j. \<lbrakk>i < card s ; j < card s ; i \<noteq> j\<rbrakk> 
hoelzl@35582
   260
    \<Longrightarrow> ?f' i \<inter> ?f' j = {}" by simp
hoelzl@35582
   261
hoelzl@35582
   262
  have "e = e \<inter> space M" using assms sets_into_space by simp
hoelzl@35582
   263
  also hence "\<dots> = e \<inter> (\<Union> x \<in> s. f x)" using assms by blast
hoelzl@35582
   264
  also have "\<dots> = (\<Union> x \<in> g ` ?S. e \<inter> f x)" using gs by simp
hoelzl@35582
   265
  also have "\<dots> = (\<Union> i \<in> ?S. ?f' i)" by simp
hoelzl@35582
   266
  finally have "prob e = prob (\<Union> i \<in> ?S. ?f' i)" by simp
hoelzl@35582
   267
  also have "\<dots> = (\<Sum> i \<in> ?S. prob (?f' i))"
hoelzl@35582
   268
    apply (subst measure_finitely_additive'')
hoelzl@35582
   269
    using f' df' assms by (auto simp: disjoint_family_on_def)
hoelzl@35582
   270
  also have "\<dots> = (\<Sum> x \<in> g ` ?S. prob (e \<inter> f x))" 
hoelzl@35582
   271
    using setsum_reindex[of g "?S" "\<lambda> x. prob (e \<inter> f x)"]
hoelzl@35582
   272
      ginj by simp
hoelzl@35582
   273
  also have "\<dots> = (\<Sum> x \<in> s. prob (e \<inter> f x))" using gs by simp
hoelzl@35582
   274
  finally show ?thesis by simp
hoelzl@35582
   275
qed
hoelzl@35582
   276
hoelzl@35582
   277
lemma distribution_prob_space:
hoelzl@35582
   278
  assumes "random_variable s X"
hoelzl@35582
   279
  shows "prob_space \<lparr>space = space s, sets = sets s, measure = distribution X\<rparr>"
hoelzl@35582
   280
using assms
hoelzl@35582
   281
proof -
hoelzl@35582
   282
  let ?N = "\<lparr>space = space s, sets = sets s, measure = distribution X\<rparr>"
hoelzl@35582
   283
  interpret s: sigma_algebra "s" using assms[unfolded measurable_def] by auto
hoelzl@35582
   284
  hence sigN: "sigma_algebra ?N" using s.sigma_algebra_extend by auto
hoelzl@35582
   285
hoelzl@35582
   286
  have pos: "\<And> e. e \<in> sets s \<Longrightarrow> distribution X e \<ge> 0"
hoelzl@35582
   287
    unfolding distribution_def
hoelzl@35929
   288
    using positive'[unfolded positive_def]
hoelzl@35582
   289
    assms[unfolded measurable_def] by auto
hoelzl@35582
   290
hoelzl@35582
   291
  have cas: "countably_additive ?N (distribution X)"
hoelzl@35582
   292
  proof -
hoelzl@35582
   293
    {
hoelzl@35582
   294
      fix f :: "nat \<Rightarrow> 'c \<Rightarrow> bool"
hoelzl@35582
   295
      let ?g = "\<lambda> n. X -` f n \<inter> space M"
hoelzl@35582
   296
      assume asm: "range f \<subseteq> sets s" "UNION UNIV f \<in> sets s" "disjoint_family f"
hoelzl@35582
   297
      hence "range ?g \<subseteq> events" 
hoelzl@35582
   298
        using assms unfolding measurable_def by blast
hoelzl@35582
   299
      from ca[unfolded countably_additive_def, 
hoelzl@35582
   300
        rule_format, of ?g, OF this] countable_UN[OF this] asm
hoelzl@35582
   301
      have "(\<lambda> n. prob (?g n)) sums prob (UNION UNIV ?g)"
hoelzl@35582
   302
        unfolding disjoint_family_on_def by blast
hoelzl@35582
   303
      moreover have "(X -` (\<Union> n. f n)) = (\<Union> n. X -` f n)" by blast
hoelzl@35582
   304
      ultimately have "(\<lambda> n. distribution X (f n)) sums distribution X (UNION UNIV f)"
hoelzl@35582
   305
        unfolding distribution_def by simp
hoelzl@35582
   306
    } thus ?thesis unfolding countably_additive_def by simp
hoelzl@35582
   307
  qed
hoelzl@35582
   308
hoelzl@35582
   309
  have ds0: "distribution X {} = 0"
hoelzl@35582
   310
    unfolding distribution_def by simp
hoelzl@35582
   311
hoelzl@35582
   312
  have "X -` space s \<inter> space M = space M"
hoelzl@35582
   313
    using assms[unfolded measurable_def] by auto
hoelzl@35582
   314
  hence ds1: "distribution X (space s) = 1"
hoelzl@35582
   315
    unfolding measurable_def distribution_def using prob_space by simp
hoelzl@35582
   316
hoelzl@35582
   317
  from ds0 ds1 cas pos sigN
hoelzl@35582
   318
  show "prob_space ?N"
hoelzl@35582
   319
    unfolding prob_space_def prob_space_axioms_def
hoelzl@35582
   320
    measure_space_def measure_space_axioms_def by simp
hoelzl@35582
   321
qed
hoelzl@35582
   322
hoelzl@35582
   323
lemma distribution_lebesgue_thm1:
hoelzl@35582
   324
  assumes "random_variable s X"
hoelzl@35582
   325
  assumes "A \<in> sets s"
hoelzl@35582
   326
  shows "distribution X A = expectation (indicator_fn (X -` A \<inter> space M))"
hoelzl@35582
   327
unfolding distribution_def
hoelzl@35582
   328
using assms unfolding measurable_def
hoelzl@35582
   329
using integral_indicator_fn by auto
hoelzl@35582
   330
hoelzl@35582
   331
lemma distribution_lebesgue_thm2:
hoelzl@35582
   332
  assumes "random_variable s X" "A \<in> sets s"
hoelzl@35582
   333
  shows "distribution X A = measure_space.integral \<lparr>space = space s, sets = sets s, measure = distribution X\<rparr> (indicator_fn A)"
hoelzl@35582
   334
  (is "_ = measure_space.integral ?M _")
hoelzl@35582
   335
proof -
hoelzl@35582
   336
  interpret S: prob_space ?M using assms(1) by (rule distribution_prob_space)
hoelzl@35582
   337
hoelzl@35582
   338
  show ?thesis
hoelzl@35582
   339
    using S.integral_indicator_fn(1)
hoelzl@35582
   340
    using assms unfolding distribution_def by auto
hoelzl@35582
   341
qed
hoelzl@35582
   342
hoelzl@35582
   343
lemma finite_expectation1:
hoelzl@35582
   344
  assumes "finite (space M)" "random_variable borel_space X"
hoelzl@35582
   345
  shows "expectation X = (\<Sum> r \<in> X ` space M. r * prob (X -` {r} \<inter> space M))"
hoelzl@35582
   346
  using assms integral_finite measurable_def
hoelzl@35582
   347
  unfolding borel_measurable_def by auto
hoelzl@35582
   348
hoelzl@35582
   349
lemma finite_expectation:
hoelzl@35582
   350
  assumes "finite (space M) \<and> random_variable borel_space X"
hoelzl@35582
   351
  shows "expectation X = (\<Sum> r \<in> X ` (space M). r * distribution X {r})"
hoelzl@35582
   352
using assms unfolding distribution_def using finite_expectation1 by auto
hoelzl@35582
   353
lemma prob_x_eq_1_imp_prob_y_eq_0:
hoelzl@35582
   354
  assumes "{x} \<in> events"
hoelzl@35582
   355
  assumes "(prob {x} = 1)"
hoelzl@35582
   356
  assumes "{y} \<in> events"
hoelzl@35582
   357
  assumes "y \<noteq> x"
hoelzl@35582
   358
  shows "prob {y} = 0"
hoelzl@35582
   359
  using prob_one_inter[of "{y}" "{x}"] assms by auto
hoelzl@35582
   360
hoelzl@35582
   361
lemma distribution_x_eq_1_imp_distribution_y_eq_0:
hoelzl@35582
   362
  assumes X: "random_variable \<lparr>space = X ` (space M), sets = Pow (X ` (space M))\<rparr> X"
hoelzl@35582
   363
  assumes "(distribution X {x} = 1)"
hoelzl@35582
   364
  assumes "y \<noteq> x"
hoelzl@35582
   365
  shows "distribution X {y} = 0"
hoelzl@35582
   366
proof -
hoelzl@35582
   367
  let ?S = "\<lparr>space = X ` (space M), sets = Pow (X ` (space M))\<rparr>"
hoelzl@35582
   368
  let ?M = "\<lparr>space = X ` (space M), sets = Pow (X ` (space M)), measure = distribution X\<rparr>"
hoelzl@35582
   369
  interpret S: prob_space ?M
hoelzl@35582
   370
    using distribution_prob_space[OF X] by auto
hoelzl@35582
   371
  { assume "{x} \<notin> sets ?M"
hoelzl@35582
   372
    hence "x \<notin> X ` space M" by auto
hoelzl@35582
   373
    hence "X -` {x} \<inter> space M = {}" by auto
hoelzl@35582
   374
    hence "distribution X {x} = 0" unfolding distribution_def by auto
hoelzl@35582
   375
    hence "False" using assms by auto }
hoelzl@35582
   376
  hence x: "{x} \<in> sets ?M" by auto
hoelzl@35582
   377
  { assume "{y} \<notin> sets ?M"
hoelzl@35582
   378
    hence "y \<notin> X ` space M" by auto
hoelzl@35582
   379
    hence "X -` {y} \<inter> space M = {}" by auto
hoelzl@35582
   380
    hence "distribution X {y} = 0" unfolding distribution_def by auto }
hoelzl@35582
   381
  moreover
hoelzl@35582
   382
  { assume "{y} \<in> sets ?M"
hoelzl@35582
   383
    hence "distribution X {y} = 0" using assms S.prob_x_eq_1_imp_prob_y_eq_0[OF x] by auto }
hoelzl@35582
   384
  ultimately show ?thesis by auto
hoelzl@35582
   385
qed
hoelzl@35582
   386
hoelzl@35977
   387
hoelzl@35582
   388
end
hoelzl@35582
   389
hoelzl@35977
   390
locale finite_prob_space = prob_space + finite_measure_space
hoelzl@35977
   391
hoelzl@35977
   392
lemma (in finite_prob_space) finite_marginal_product_space_POW2:
hoelzl@35977
   393
  assumes "finite s1" "finite s2"
hoelzl@35977
   394
  shows "finite_measure_space \<lparr> space = s1 \<times> s2, sets = Pow (s1 \<times> s2), measure = joint_distribution X Y\<rparr>"
hoelzl@35977
   395
    (is "finite_measure_space ?M")
hoelzl@35977
   396
proof (rule finite_Pow_additivity_sufficient)
hoelzl@35977
   397
  show "positive ?M (measure ?M)"
hoelzl@35977
   398
    unfolding positive_def using positive'[unfolded positive_def] assms sets_eq_Pow
hoelzl@35977
   399
    by (simp add: joint_distribution_def)
hoelzl@35977
   400
hoelzl@35977
   401
  show "additive ?M (measure ?M)" unfolding additive_def
hoelzl@35977
   402
  proof safe
hoelzl@35977
   403
    fix x y
hoelzl@35977
   404
    have A: "((\<lambda>x. (X x, Y x)) -` x) \<inter> space M \<in> sets M" using assms sets_eq_Pow by auto
hoelzl@35977
   405
    have B: "((\<lambda>x. (X x, Y x)) -` y) \<inter> space M \<in> sets M" using assms sets_eq_Pow by auto
hoelzl@35977
   406
    assume "x \<inter> y = {}"
hoelzl@35977
   407
    from additive[unfolded additive_def, rule_format, OF A B] this
hoelzl@35977
   408
    show "measure ?M (x \<union> y) = measure ?M x + measure ?M y"
hoelzl@35977
   409
      apply (simp add: joint_distribution_def)
hoelzl@35977
   410
      apply (subst Int_Un_distrib2)
hoelzl@35977
   411
      by auto
hoelzl@35977
   412
  qed
hoelzl@35977
   413
hoelzl@35977
   414
  show "finite (space ?M)"
hoelzl@35977
   415
    using assms by auto
hoelzl@35977
   416
hoelzl@35977
   417
  show "sets ?M = Pow (space ?M)"
hoelzl@35977
   418
    by simp
hoelzl@35977
   419
qed
hoelzl@35977
   420
hoelzl@35977
   421
lemma (in finite_prob_space) finite_marginal_product_space_POW:
hoelzl@35977
   422
  shows "finite_measure_space \<lparr> space = X ` space M \<times> Y ` space M,
hoelzl@35977
   423
                                sets = Pow (X ` space M \<times> Y ` space M),
hoelzl@35977
   424
                                measure = joint_distribution X Y\<rparr>"
hoelzl@35977
   425
    (is "finite_measure_space ?M")
hoelzl@35977
   426
  using finite_space by (auto intro!: finite_marginal_product_space_POW2)
hoelzl@35977
   427
hoelzl@35582
   428
end