src/HOL/Probability/Probability_Space.thy
changeset 38656 d5d342611edb
parent 36624 25153c08655e
child 39083 e46acc0ea1fe
equal deleted inserted replaced
38655:5001ed24e129 38656:d5d342611edb
     1 theory Probability_Space
     1 theory Probability_Space
     2 imports Lebesgue
     2 imports Lebesgue_Integration
     3 begin
     3 begin
     4 
     4 
       
     5 lemma (in measure_space) measure_inter_full_set:
       
     6   assumes "S \<in> sets M" "T \<in> sets M" and not_\<omega>: "\<mu> (T - S) \<noteq> \<omega>"
       
     7   assumes T: "\<mu> T = \<mu> (space M)"
       
     8   shows "\<mu> (S \<inter> T) = \<mu> S"
       
     9 proof (rule antisym)
       
    10   show " \<mu> (S \<inter> T) \<le> \<mu> S"
       
    11     using assms by (auto intro!: measure_mono)
       
    12 
       
    13   show "\<mu> S \<le> \<mu> (S \<inter> T)"
       
    14   proof (rule ccontr)
       
    15     assume contr: "\<not> ?thesis"
       
    16     have "\<mu> (space M) = \<mu> ((T - S) \<union> (S \<inter> T))"
       
    17       unfolding T[symmetric] by (auto intro!: arg_cong[where f="\<mu>"])
       
    18     also have "\<dots> \<le> \<mu> (T - S) + \<mu> (S \<inter> T)"
       
    19       using assms by (auto intro!: measure_subadditive)
       
    20     also have "\<dots> < \<mu> (T - S) + \<mu> S"
       
    21       by (rule pinfreal_less_add[OF not_\<omega>]) (insert contr, auto)
       
    22     also have "\<dots> = \<mu> (T \<union> S)"
       
    23       using assms by (subst measure_additive) auto
       
    24     also have "\<dots> \<le> \<mu> (space M)"
       
    25       using assms sets_into_space by (auto intro!: measure_mono)
       
    26     finally show False ..
       
    27   qed
       
    28 qed
       
    29 
       
    30 lemma (in finite_measure) finite_measure_inter_full_set:
       
    31   assumes "S \<in> sets M" "T \<in> sets M"
       
    32   assumes T: "\<mu> T = \<mu> (space M)"
       
    33   shows "\<mu> (S \<inter> T) = \<mu> S"
       
    34   using measure_inter_full_set[OF assms(1,2) finite_measure assms(3)] assms
       
    35   by auto
       
    36 
     5 locale prob_space = measure_space +
    37 locale prob_space = measure_space +
     6   assumes prob_space: "measure M (space M) = 1"
    38   assumes measure_space_1: "\<mu> (space M) = 1"
       
    39 
       
    40 sublocale prob_space < finite_measure
       
    41 proof
       
    42   from measure_space_1 show "\<mu> (space M) \<noteq> \<omega>" by simp
       
    43 qed
       
    44 
       
    45 context prob_space
     7 begin
    46 begin
     8 
    47 
     9 abbreviation "events \<equiv> sets M"
    48 abbreviation "events \<equiv> sets M"
    10 abbreviation "prob \<equiv> measure M"
    49 abbreviation "prob \<equiv> \<lambda>A. real (\<mu> A)"
    11 abbreviation "prob_preserving \<equiv> measure_preserving"
    50 abbreviation "prob_preserving \<equiv> measure_preserving"
    12 abbreviation "random_variable \<equiv> \<lambda> s X. X \<in> measurable M s"
    51 abbreviation "random_variable \<equiv> \<lambda> s X. X \<in> measurable M s"
    13 abbreviation "expectation \<equiv> integral"
    52 abbreviation "expectation \<equiv> integral"
    14 
    53 
    15 definition
    54 definition
    17 
    56 
    18 definition
    57 definition
    19   "indep_families F G \<longleftrightarrow> (\<forall> A \<in> F. \<forall> B \<in> G. indep A B)"
    58   "indep_families F G \<longleftrightarrow> (\<forall> A \<in> F. \<forall> B \<in> G. indep A B)"
    20 
    59 
    21 definition
    60 definition
    22   "distribution X = (\<lambda>s. prob ((X -` s) \<inter> (space M)))"
    61   "distribution X = (\<lambda>s. \<mu> ((X -` s) \<inter> (space M)))"
    23 
    62 
    24 abbreviation
    63 abbreviation
    25   "joint_distribution X Y \<equiv> distribution (\<lambda>x. (X x, Y x))"
    64   "joint_distribution X Y \<equiv> distribution (\<lambda>x. (X x, Y x))"
    26 
    65 
    27 (*
    66 lemma prob_space: "prob (space M) = 1"
    28 definition probably :: "('a \<Rightarrow> bool) \<Rightarrow> bool" (binder "\<forall>\<^sup>*" 10) where
    67   unfolding measure_space_1 by simp
    29   "probably P \<longleftrightarrow> { x. P x } \<in> events \<and> prob { x. P x } = 1"
    68 
    30 definition possibly :: "('a \<Rightarrow> bool) \<Rightarrow> bool" (binder "\<exists>\<^sup>*" 10) where
    69 lemma measure_le_1[simp, intro]:
    31   "possibly P \<longleftrightarrow> { x. P x } \<in> events \<and> prob { x. P x } \<noteq> 0"
    70   assumes "A \<in> events" shows "\<mu> A \<le> 1"
    32 *)
    71 proof -
    33 
    72   have "\<mu> A \<le> \<mu> (space M)"
    34 definition
    73     using assms sets_into_space by(auto intro!: measure_mono)
    35   "conditional_expectation X M' \<equiv> SOME f. f \<in> measurable M' borel_space \<and>
    74   also note measure_space_1
    36     (\<forall> g \<in> sets M'. measure_space.integral M' (\<lambda>x. f x * indicator_fn g x) =
    75   finally show ?thesis .
    37                     measure_space.integral M' (\<lambda>x. X x * indicator_fn g x))"
    76 qed
    38 
    77 
    39 definition
    78 lemma measure_finite[simp, intro]:
    40   "conditional_prob E M' \<equiv> conditional_expectation (indicator_fn E) M'"
    79   assumes "A \<in> events" shows "\<mu> A \<noteq> \<omega>"
    41 
    80   using measure_le_1[OF assms] by auto
    42 lemma positive': "positive M prob"
       
    43   unfolding positive_def using positive empty_measure by blast
       
    44 
    81 
    45 lemma prob_compl:
    82 lemma prob_compl:
    46   assumes "s \<in> events"
    83   assumes "A \<in> events"
    47   shows "prob (space M - s) = 1 - prob s"
    84   shows "prob (space M - A) = 1 - prob A"
    48 using assms
    85   using `A \<in> events`[THEN sets_into_space] `A \<in> events` measure_space_1
    49 proof -
    86   by (subst real_finite_measure_Diff) auto
    50   have "prob ((space M - s) \<union> s) = prob (space M - s) + prob s"
       
    51     using assms additive[unfolded additive_def] by blast
       
    52   thus ?thesis by (simp add:Un_absorb2[OF sets_into_space[OF assms]] prob_space)
       
    53 qed
       
    54 
    87 
    55 lemma indep_space:
    88 lemma indep_space:
    56   assumes "s \<in> events"
    89   assumes "s \<in> events"
    57   shows "indep (space M) s"
    90   shows "indep (space M) s"
    58 using assms prob_space
    91   using assms prob_space by (simp add: indep_def)
    59 unfolding indep_def by auto
    92 
    60 
    93 lemma prob_space_increasing: "increasing M prob"
    61 
    94   by (auto intro!: real_measure_mono simp: increasing_def)
    62 lemma prob_space_increasing:
       
    63   "increasing M prob"
       
    64 by (rule additive_increasing[OF positive' additive])
       
    65 
       
    66 lemma prob_subadditive:
       
    67   assumes "s \<in> events" "t \<in> events"
       
    68   shows "prob (s \<union> t) \<le> prob s + prob t"
       
    69 using assms
       
    70 proof -
       
    71   have "prob (s \<union> t) = prob ((s - t) \<union> t)" by simp
       
    72   also have "\<dots> = prob (s - t) + prob t"
       
    73     using additive[unfolded additive_def, rule_format, of "s-t" "t"] 
       
    74       assms by blast
       
    75   also have "\<dots> \<le> prob s + prob t"
       
    76     using prob_space_increasing[unfolded increasing_def, rule_format] assms
       
    77     by auto
       
    78   finally show ?thesis by simp
       
    79 qed
       
    80 
    95 
    81 lemma prob_zero_union:
    96 lemma prob_zero_union:
    82   assumes "s \<in> events" "t \<in> events" "prob t = 0"
    97   assumes "s \<in> events" "t \<in> events" "prob t = 0"
    83   shows "prob (s \<union> t) = prob s"
    98   shows "prob (s \<union> t) = prob s"
    84 using assms 
    99 using assms
    85 proof -
   100 proof -
    86   have "prob (s \<union> t) \<le> prob s"
   101   have "prob (s \<union> t) \<le> prob s"
    87     using prob_subadditive[of s t] assms by auto
   102     using real_finite_measure_subadditive[of s t] assms by auto
    88   moreover have "prob (s \<union> t) \<ge> prob s"
   103   moreover have "prob (s \<union> t) \<ge> prob s"
    89     using prob_space_increasing[unfolded increasing_def, rule_format] 
   104     using assms by (blast intro: real_measure_mono)
    90       assms by auto
       
    91   ultimately show ?thesis by simp
   105   ultimately show ?thesis by simp
    92 qed
   106 qed
    93 
   107 
    94 lemma prob_eq_compl:
   108 lemma prob_eq_compl:
    95   assumes "s \<in> events" "t \<in> events"
   109   assumes "s \<in> events" "t \<in> events"
    96   assumes "prob (space M - s) = prob (space M - t)"
   110   assumes "prob (space M - s) = prob (space M - t)"
    97   shows "prob s = prob t"
   111   shows "prob s = prob t"
    98 using assms prob_compl by auto
   112   using assms prob_compl by auto
    99 
   113 
   100 lemma prob_one_inter:
   114 lemma prob_one_inter:
   101   assumes events:"s \<in> events" "t \<in> events"
   115   assumes events:"s \<in> events" "t \<in> events"
   102   assumes "prob t = 1"
   116   assumes "prob t = 1"
   103   shows "prob (s \<inter> t) = prob s"
   117   shows "prob (s \<inter> t) = prob s"
   104 using assms
   118 proof -
   105 proof -
   119   have "prob ((space M - s) \<union> (space M - t)) = prob (space M - s)"
   106   have "prob ((space M - s) \<union> (space M - t)) = prob (space M - s)" 
   120     using events assms  prob_compl[of "t"] by (auto intro!: prob_zero_union)
   107     using prob_compl[of "t"] prob_zero_union assms by auto
   121   also have "(space M - s) \<union> (space M - t) = space M - (s \<inter> t)"
   108   then show "prob (s \<inter> t) = prob s" 
   122     by blast
   109     using prob_eq_compl[of "s \<inter> t"] events by (simp only: Diff_Int) auto
   123   finally show "prob (s \<inter> t) = prob s"
       
   124     using events by (auto intro!: prob_eq_compl[of "s \<inter> t" s])
   110 qed
   125 qed
   111 
   126 
   112 lemma prob_eq_bigunion_image:
   127 lemma prob_eq_bigunion_image:
   113   assumes "range f \<subseteq> events" "range g \<subseteq> events"
   128   assumes "range f \<subseteq> events" "range g \<subseteq> events"
   114   assumes "disjoint_family f" "disjoint_family g"
   129   assumes "disjoint_family f" "disjoint_family g"
   115   assumes "\<And> n :: nat. prob (f n) = prob (g n)"
   130   assumes "\<And> n :: nat. prob (f n) = prob (g n)"
   116   shows "(prob (\<Union> i. f i) = prob (\<Union> i. g i))"
   131   shows "(prob (\<Union> i. f i) = prob (\<Union> i. g i))"
   117 using assms 
   132 using assms
   118 proof -
   133 proof -
   119   have a: "(\<lambda> i. prob (f i)) sums (prob (\<Union> i. f i))" 
   134   have a: "(\<lambda> i. prob (f i)) sums (prob (\<Union> i. f i))"
   120     using ca[unfolded countably_additive_def] assms by blast
   135     by (rule real_finite_measure_UNION[OF assms(1,3)])
   121   have b: "(\<lambda> i. prob (g i)) sums (prob (\<Union> i. g i))"
   136   have b: "(\<lambda> i. prob (g i)) sums (prob (\<Union> i. g i))"
   122     using ca[unfolded countably_additive_def] assms by blast
   137     by (rule real_finite_measure_UNION[OF assms(2,4)])
   123   show ?thesis using sums_unique[OF b] sums_unique[OF a] assms by simp
   138   show ?thesis using sums_unique[OF b] sums_unique[OF a] assms by simp
   124 qed
       
   125 
       
   126 lemma prob_countably_subadditive: 
       
   127   assumes "range f \<subseteq> events" 
       
   128   assumes "summable (prob \<circ> f)"
       
   129   shows "prob (\<Union>i. f i) \<le> (\<Sum> i. prob (f i))"
       
   130 using assms
       
   131 proof -
       
   132   def f' == "\<lambda> i. f i - (\<Union> j \<in> {0 ..< i}. f j)"
       
   133   have "(\<Union> i. f' i) \<subseteq> (\<Union> i. f i)" unfolding f'_def by auto
       
   134   moreover have "(\<Union> i. f' i) \<supseteq> (\<Union> i. f i)"
       
   135   proof (rule subsetI)
       
   136     fix x assume "x \<in> (\<Union> i. f i)"
       
   137     then obtain k where "x \<in> f k" by blast
       
   138     hence k: "k \<in> {m. x \<in> f m}" by simp
       
   139     have "\<exists> l. x \<in> f l \<and> (\<forall> l' < l. x \<notin> f l')"
       
   140       using wfE_min[of "{(x, y). x < y}" "k" "{m. x \<in> f m}", 
       
   141         OF wf_less k] by auto
       
   142     thus "x \<in> (\<Union> i. f' i)" unfolding f'_def by auto
       
   143   qed
       
   144   ultimately have uf'f: "(\<Union> i. f' i) = (\<Union> i. f i)" by (rule equalityI)
       
   145 
       
   146   have df': "\<And> i j. i < j \<Longrightarrow> f' i \<inter> f' j = {}"
       
   147     unfolding f'_def by auto
       
   148   have "\<And> i j. i \<noteq> j \<Longrightarrow> f' i \<inter> f' j = {}"
       
   149     apply (drule iffD1[OF nat_neq_iff])
       
   150     using df' by auto
       
   151   hence df: "disjoint_family f'" unfolding disjoint_family_on_def by simp
       
   152 
       
   153   have rf': "\<And> i. f' i \<in> events"
       
   154   proof -
       
   155     fix i :: nat
       
   156     have "(\<Union> {f j | j. j \<in> {0 ..< i}}) = (\<Union> j \<in> {0 ..< i}. f j)" by blast
       
   157     hence "(\<Union> {f j | j. j \<in> {0 ..< i}}) \<in> events 
       
   158       \<Longrightarrow> (\<Union> j \<in> {0 ..< i}. f j) \<in> events" by auto
       
   159     thus "f' i \<in> events" 
       
   160       unfolding f'_def 
       
   161       using assms finite_union[of "{f j | j. j \<in> {0 ..< i}}"]
       
   162         Diff[of "f i" "\<Union> j \<in> {0 ..< i}. f j"] by auto
       
   163   qed
       
   164   hence uf': "(\<Union> range f') \<in> events" by auto
       
   165   
       
   166   have "\<And> i. prob (f' i) \<le> prob (f i)"
       
   167     using prob_space_increasing[unfolded increasing_def, rule_format, OF rf']
       
   168       assms rf' unfolding f'_def by blast
       
   169 
       
   170   hence absinc: "\<And> i. \<bar> prob (f' i) \<bar> \<le> prob (f i)"
       
   171     using abs_of_nonneg positive'[unfolded positive_def]
       
   172       assms rf' by auto
       
   173 
       
   174   have "prob (\<Union> i. f i) = prob (\<Union> i. f' i)" using uf'f by simp
       
   175 
       
   176   also have "\<dots> = (\<Sum> i. prob (f' i))"
       
   177     using ca[unfolded countably_additive_def, rule_format]
       
   178     sums_unique rf' uf' df
       
   179     by auto
       
   180   
       
   181   also have "\<dots> \<le> (\<Sum> i. prob (f i))"
       
   182     using summable_le2[of "\<lambda> i. prob (f' i)" "\<lambda> i. prob (f i)", 
       
   183       rule_format, OF absinc]
       
   184       assms[unfolded o_def] by auto
       
   185 
       
   186   finally show ?thesis by auto
       
   187 qed
   139 qed
   188 
   140 
   189 lemma prob_countably_zero:
   141 lemma prob_countably_zero:
   190   assumes "range c \<subseteq> events"
   142   assumes "range c \<subseteq> events"
   191   assumes "\<And> i. prob (c i) = 0"
   143   assumes "\<And> i. prob (c i) = 0"
   192   shows "(prob (\<Union> i :: nat. c i) = 0)"
   144   shows "prob (\<Union> i :: nat. c i) = 0"
   193   using assms
   145 proof (rule antisym)
   194 proof -
   146   show "prob (\<Union> i :: nat. c i) \<le> 0"
   195   have leq0: "0 \<le> prob (\<Union> i. c i)"
   147     using real_finite_measurable_countably_subadditive[OF assms(1)]
   196     using assms positive'[unfolded positive_def, rule_format] 
   148     by (simp add: assms(2) suminf_zero summable_zero)
   197     by auto
   149   show "0 \<le> prob (\<Union> i :: nat. c i)" by (rule real_pinfreal_nonneg)
   198 
       
   199   have "prob (\<Union> i. c i) \<le> (\<Sum> i. prob (c i))"
       
   200     using prob_countably_subadditive[of c, unfolded o_def]
       
   201       assms sums_zero sums_summable by auto
       
   202 
       
   203   also have "\<dots> = 0"
       
   204     using assms sums_zero 
       
   205       sums_unique[of "\<lambda> i. prob (c i)" "0"] by auto
       
   206 
       
   207   finally show "prob (\<Union> i. c i) = 0"
       
   208     using leq0 by auto
       
   209 qed
   150 qed
   210 
   151 
   211 lemma indep_sym:
   152 lemma indep_sym:
   212    "indep a b \<Longrightarrow> indep b a"
   153    "indep a b \<Longrightarrow> indep b a"
   213 unfolding indep_def using Int_commute[of a b] by auto
   154 unfolding indep_def using Int_commute[of a b] by auto
   216   assumes "a \<in> events"
   157   assumes "a \<in> events"
   217   shows "indep a a = (prob a = 0) \<or> (prob a = 1)"
   158   shows "indep a a = (prob a = 0) \<or> (prob a = 1)"
   218 using assms unfolding indep_def by auto
   159 using assms unfolding indep_def by auto
   219 
   160 
   220 lemma prob_equiprobable_finite_unions:
   161 lemma prob_equiprobable_finite_unions:
   221   assumes "s \<in> events" 
   162   assumes "s \<in> events"
   222   assumes "\<And>x. x \<in> s \<Longrightarrow> {x} \<in> events"
   163   assumes s_finite: "finite s" "\<And>x. x \<in> s \<Longrightarrow> {x} \<in> events"
   223   assumes "finite s"
       
   224   assumes "\<And> x y. \<lbrakk>x \<in> s; y \<in> s\<rbrakk> \<Longrightarrow> (prob {x} = prob {y})"
   164   assumes "\<And> x y. \<lbrakk>x \<in> s; y \<in> s\<rbrakk> \<Longrightarrow> (prob {x} = prob {y})"
   225   shows "prob s = of_nat (card s) * prob {SOME x. x \<in> s}"
   165   shows "prob s = real (card s) * prob {SOME x. x \<in> s}"
   226 using assms
       
   227 proof (cases "s = {}")
   166 proof (cases "s = {}")
   228   case True thus ?thesis by simp
   167   case False hence "\<exists> x. x \<in> s" by blast
   229 next
       
   230   case False hence " \<exists> x. x \<in> s" by blast
       
   231   from someI_ex[OF this] assms
   168   from someI_ex[OF this] assms
   232   have prob_some: "\<And> x. x \<in> s \<Longrightarrow> prob {x} = prob {SOME y. y \<in> s}" by blast
   169   have prob_some: "\<And> x. x \<in> s \<Longrightarrow> prob {x} = prob {SOME y. y \<in> s}" by blast
   233   have "prob s = (\<Sum> x \<in> s. prob {x})"
   170   have "prob s = (\<Sum> x \<in> s. prob {x})"
   234     using assms measure_real_sum_image by blast
   171     using real_finite_measure_finite_singelton[OF s_finite] by simp
   235   also have "\<dots> = (\<Sum> x \<in> s. prob {SOME y. y \<in> s})" using prob_some by auto
   172   also have "\<dots> = (\<Sum> x \<in> s. prob {SOME y. y \<in> s})" using prob_some by auto
   236   also have "\<dots> = of_nat (card s) * prob {(SOME x. x \<in> s)}"
   173   also have "\<dots> = real (card s) * prob {(SOME x. x \<in> s)}"
   237     using setsum_constant assms by auto
   174     using setsum_constant assms by (simp add: real_eq_of_nat)
   238   finally show ?thesis by simp
   175   finally show ?thesis by simp
   239 qed
   176 qed simp
   240 
   177 
   241 lemma prob_real_sum_image_fn:
   178 lemma prob_real_sum_image_fn:
   242   assumes "e \<in> events"
   179   assumes "e \<in> events"
   243   assumes "\<And> x. x \<in> s \<Longrightarrow> e \<inter> f x \<in> events"
   180   assumes "\<And> x. x \<in> s \<Longrightarrow> e \<inter> f x \<in> events"
   244   assumes "finite s"
   181   assumes "finite s"
   245   assumes "\<And> x y. \<lbrakk>x \<in> s ; y \<in> s ; x \<noteq> y\<rbrakk> \<Longrightarrow> f x \<inter> f y = {}"
   182   assumes disjoint: "\<And> x y. \<lbrakk>x \<in> s ; y \<in> s ; x \<noteq> y\<rbrakk> \<Longrightarrow> f x \<inter> f y = {}"
   246   assumes "space M \<subseteq> (\<Union> i \<in> s. f i)"
   183   assumes upper: "space M \<subseteq> (\<Union> i \<in> s. f i)"
   247   shows "prob e = (\<Sum> x \<in> s. prob (e \<inter> f x))"
   184   shows "prob e = (\<Sum> x \<in> s. prob (e \<inter> f x))"
   248 using assms
   185 proof -
   249 proof -
   186   have e: "e = (\<Union> i \<in> s. e \<inter> f i)"
   250   let ?S = "{0 ..< card s}"
   187     using `e \<in> events` sets_into_space upper by blast
   251   obtain g where "g ` ?S = s \<and> inj_on g ?S"
   188   hence "prob e = prob (\<Union> i \<in> s. e \<inter> f i)" by simp
   252     using ex_bij_betw_nat_finite[unfolded bij_betw_def, of s] assms by auto
   189   also have "\<dots> = (\<Sum> x \<in> s. prob (e \<inter> f x))"
   253   moreover hence gs: "g ` ?S = s" by simp
   190   proof (rule real_finite_measure_finite_Union)
   254   ultimately have ginj: "inj_on g ?S" by simp
   191     show "finite s" by fact
   255   let ?f' = "\<lambda> i. e \<inter> f (g i)"
   192     show "\<And>i. i \<in> s \<Longrightarrow> e \<inter> f i \<in> events" by fact
   256   have f': "?f' \<in> ?S \<rightarrow> events"
   193     show "disjoint_family_on (\<lambda>i. e \<inter> f i) s"
   257     using gs assms by blast
   194       using disjoint by (auto simp: disjoint_family_on_def)
   258   hence "\<And> i j. \<lbrakk>i \<in> ?S ; j \<in> ?S ; i \<noteq> j\<rbrakk> 
   195   qed
   259     \<Longrightarrow> ?f' i \<inter> ?f' j = {}" using assms ginj[unfolded inj_on_def] gs f' by blast
   196   finally show ?thesis .
   260   hence df': "\<And> i j. \<lbrakk>i < card s ; j < card s ; i \<noteq> j\<rbrakk> 
       
   261     \<Longrightarrow> ?f' i \<inter> ?f' j = {}" by simp
       
   262 
       
   263   have "e = e \<inter> space M" using assms sets_into_space by simp
       
   264   also hence "\<dots> = e \<inter> (\<Union> x \<in> s. f x)" using assms by blast
       
   265   also have "\<dots> = (\<Union> x \<in> g ` ?S. e \<inter> f x)" using gs by simp
       
   266   also have "\<dots> = (\<Union> i \<in> ?S. ?f' i)" by simp
       
   267   finally have "prob e = prob (\<Union> i \<in> ?S. ?f' i)" by simp
       
   268   also have "\<dots> = (\<Sum> i \<in> ?S. prob (?f' i))"
       
   269     apply (subst measure_finitely_additive'')
       
   270     using f' df' assms by (auto simp: disjoint_family_on_def)
       
   271   also have "\<dots> = (\<Sum> x \<in> g ` ?S. prob (e \<inter> f x))" 
       
   272     using setsum_reindex[of g "?S" "\<lambda> x. prob (e \<inter> f x)"]
       
   273       ginj by simp
       
   274   also have "\<dots> = (\<Sum> x \<in> s. prob (e \<inter> f x))" using gs by simp
       
   275   finally show ?thesis by simp
       
   276 qed
   197 qed
   277 
   198 
   278 lemma distribution_prob_space:
   199 lemma distribution_prob_space:
   279   assumes "random_variable s X"
   200   fixes S :: "('c, 'd) algebra_scheme"
   280   shows "prob_space \<lparr>space = space s, sets = sets s, measure = distribution X\<rparr>"
   201   assumes "sigma_algebra S" "random_variable S X"
   281 using assms
   202   shows "prob_space S (distribution X)"
   282 proof -
   203 proof -
   283   let ?N = "\<lparr>space = space s, sets = sets s, measure = distribution X\<rparr>"
   204   interpret S: sigma_algebra S by fact
   284   interpret s: sigma_algebra "s" using assms[unfolded measurable_def] by auto
   205   show ?thesis
   285   hence sigN: "sigma_algebra ?N" using s.sigma_algebra_extend by auto
   206   proof
   286 
   207     show "distribution X {} = 0" unfolding distribution_def by simp
   287   have pos: "\<And> e. e \<in> sets s \<Longrightarrow> distribution X e \<ge> 0"
   208     have "X -` space S \<inter> space M = space M"
   288     unfolding distribution_def
   209       using `random_variable S X` by (auto simp: measurable_def)
   289     using positive'[unfolded positive_def]
   210     then show "distribution X (space S) = 1" using measure_space_1 by (simp add: distribution_def)
   290     assms[unfolded measurable_def] by auto
   211 
   291 
   212     show "countably_additive S (distribution X)"
   292   have cas: "countably_additive ?N (distribution X)"
   213     proof (unfold countably_additive_def, safe)
   293   proof -
   214       fix A :: "nat \<Rightarrow> 'c set" assume "range A \<subseteq> sets S" "disjoint_family A"
   294     {
   215       hence *: "\<And>i. X -` A i \<inter> space M \<in> sets M"
   295       fix f :: "nat \<Rightarrow> 'c \<Rightarrow> bool"
   216         using `random_variable S X` by (auto simp: measurable_def)
   296       let ?g = "\<lambda> n. X -` f n \<inter> space M"
   217       moreover hence "\<And>i. \<mu> (X -` A i \<inter> space M) \<noteq> \<omega>"
   297       assume asm: "range f \<subseteq> sets s" "UNION UNIV f \<in> sets s" "disjoint_family f"
   218         using finite_measure by auto
   298       hence "range ?g \<subseteq> events" 
   219       moreover have "(\<Union>i. X -`  A i \<inter> space M) \<in> sets M"
   299         using assms unfolding measurable_def by blast
   220         using * by blast
   300       from ca[unfolded countably_additive_def, 
   221       moreover hence "\<mu> (\<Union>i. X -` A i \<inter> space M) \<noteq> \<omega>"
   301         rule_format, of ?g, OF this] countable_UN[OF this] asm
   222         using finite_measure by auto
   302       have "(\<lambda> n. prob (?g n)) sums prob (UNION UNIV ?g)"
   223       moreover have **: "disjoint_family (\<lambda>i. X -` A i \<inter> space M)"
   303         unfolding disjoint_family_on_def by blast
   224         using `disjoint_family A` by (auto simp: disjoint_family_on_def)
   304       moreover have "(X -` (\<Union> n. f n)) = (\<Union> n. X -` f n)" by blast
   225       ultimately show "(\<Sum>\<^isub>\<infinity> i. distribution X (A i)) = distribution X (\<Union>i. A i)"
   305       ultimately have "(\<lambda> n. distribution X (f n)) sums distribution X (UNION UNIV f)"
   226         using measure_countably_additive[OF _ **]
   306         unfolding distribution_def by simp
   227         by (auto simp: distribution_def Real_real comp_def vimage_UN)
   307     } thus ?thesis unfolding countably_additive_def by simp
   228     qed
   308   qed
   229   qed
   309 
       
   310   have ds0: "distribution X {} = 0"
       
   311     unfolding distribution_def by simp
       
   312 
       
   313   have "X -` space s \<inter> space M = space M"
       
   314     using assms[unfolded measurable_def] by auto
       
   315   hence ds1: "distribution X (space s) = 1"
       
   316     unfolding measurable_def distribution_def using prob_space by simp
       
   317 
       
   318   from ds0 ds1 cas pos sigN
       
   319   show "prob_space ?N"
       
   320     unfolding prob_space_def prob_space_axioms_def
       
   321     measure_space_def measure_space_axioms_def by simp
       
   322 qed
   230 qed
   323 
   231 
   324 lemma distribution_lebesgue_thm1:
   232 lemma distribution_lebesgue_thm1:
   325   assumes "random_variable s X"
   233   assumes "random_variable s X"
   326   assumes "A \<in> sets s"
   234   assumes "A \<in> sets s"
   327   shows "distribution X A = expectation (indicator_fn (X -` A \<inter> space M))"
   235   shows "real (distribution X A) = expectation (indicator (X -` A \<inter> space M))"
   328 unfolding distribution_def
   236 unfolding distribution_def
   329 using assms unfolding measurable_def
   237 using assms unfolding measurable_def
   330 using integral_indicator_fn by auto
   238 using integral_indicator by auto
   331 
   239 
   332 lemma distribution_lebesgue_thm2:
   240 lemma distribution_lebesgue_thm2:
   333   assumes "random_variable s X" "A \<in> sets s"
   241   assumes "sigma_algebra S" "random_variable S X" and "A \<in> sets S"
   334   shows "distribution X A = measure_space.integral \<lparr>space = space s, sets = sets s, measure = distribution X\<rparr> (indicator_fn A)"
   242   shows "distribution X A =
   335   (is "_ = measure_space.integral ?M _")
   243     measure_space.positive_integral S (distribution X) (indicator A)"
   336 proof -
   244   (is "_ = measure_space.positive_integral _ ?D _")
   337   interpret S: prob_space ?M using assms(1) by (rule distribution_prob_space)
   245 proof -
       
   246   interpret S: prob_space S "distribution X" using assms(1,2) by (rule distribution_prob_space)
   338 
   247 
   339   show ?thesis
   248   show ?thesis
   340     using S.integral_indicator_fn(1)
   249     using S.positive_integral_indicator(1)
   341     using assms unfolding distribution_def by auto
   250     using assms unfolding distribution_def by auto
   342 qed
   251 qed
   343 
   252 
   344 lemma finite_expectation1:
   253 lemma finite_expectation1:
       
   254   assumes "finite (X`space M)" and rv: "random_variable borel_space X"
       
   255   shows "expectation X = (\<Sum> r \<in> X ` space M. r * prob (X -` {r} \<inter> space M))"
       
   256 proof (rule integral_on_finite(2)[OF assms(2,1)])
       
   257   fix x have "X -` {x} \<inter> space M \<in> sets M"
       
   258     using rv unfolding measurable_def by auto
       
   259   thus "\<mu> (X -` {x} \<inter> space M) \<noteq> \<omega>" using finite_measure by simp
       
   260 qed
       
   261 
       
   262 lemma finite_expectation:
   345   assumes "finite (space M)" "random_variable borel_space X"
   263   assumes "finite (space M)" "random_variable borel_space X"
   346   shows "expectation X = (\<Sum> r \<in> X ` space M. r * prob (X -` {r} \<inter> space M))"
   264   shows "expectation X = (\<Sum> r \<in> X ` (space M). r * real (distribution X {r}))"
   347   using assms integral_finite measurable_def
   265   using assms unfolding distribution_def using finite_expectation1 by auto
   348   unfolding borel_measurable_def by auto
   266 
   349 
       
   350 lemma finite_expectation:
       
   351   assumes "finite (space M) \<and> random_variable borel_space X"
       
   352   shows "expectation X = (\<Sum> r \<in> X ` (space M). r * distribution X {r})"
       
   353 using assms unfolding distribution_def using finite_expectation1 by auto
       
   354 lemma prob_x_eq_1_imp_prob_y_eq_0:
   267 lemma prob_x_eq_1_imp_prob_y_eq_0:
   355   assumes "{x} \<in> events"
   268   assumes "{x} \<in> events"
   356   assumes "(prob {x} = 1)"
   269   assumes "prob {x} = 1"
   357   assumes "{y} \<in> events"
   270   assumes "{y} \<in> events"
   358   assumes "y \<noteq> x"
   271   assumes "y \<noteq> x"
   359   shows "prob {y} = 0"
   272   shows "prob {y} = 0"
   360   using prob_one_inter[of "{y}" "{x}"] assms by auto
   273   using prob_one_inter[of "{y}" "{x}"] assms by auto
   361 
   274 
       
   275 lemma distribution_empty[simp]: "distribution X {} = 0"
       
   276   unfolding distribution_def by simp
       
   277 
       
   278 lemma distribution_space[simp]: "distribution X (X ` space M) = 1"
       
   279 proof -
       
   280   have "X -` X ` space M \<inter> space M = space M" by auto
       
   281   thus ?thesis unfolding distribution_def by (simp add: measure_space_1)
       
   282 qed
       
   283 
       
   284 lemma distribution_one:
       
   285   assumes "random_variable M X" and "A \<in> events"
       
   286   shows "distribution X A \<le> 1"
       
   287 proof -
       
   288   have "distribution X A \<le> \<mu> (space M)" unfolding distribution_def
       
   289     using assms[unfolded measurable_def] by (auto intro!: measure_mono)
       
   290   thus ?thesis by (simp add: measure_space_1)
       
   291 qed
       
   292 
       
   293 lemma distribution_finite:
       
   294   assumes "random_variable M X" and "A \<in> events"
       
   295   shows "distribution X A \<noteq> \<omega>"
       
   296   using distribution_one[OF assms] by auto
       
   297 
   362 lemma distribution_x_eq_1_imp_distribution_y_eq_0:
   298 lemma distribution_x_eq_1_imp_distribution_y_eq_0:
   363   assumes X: "random_variable \<lparr>space = X ` (space M), sets = Pow (X ` (space M))\<rparr> X"
   299   assumes X: "random_variable \<lparr>space = X ` (space M), sets = Pow (X ` (space M))\<rparr> X"
   364   assumes "(distribution X {x} = 1)"
   300     (is "random_variable ?S X")
       
   301   assumes "distribution X {x} = 1"
   365   assumes "y \<noteq> x"
   302   assumes "y \<noteq> x"
   366   shows "distribution X {y} = 0"
   303   shows "distribution X {y} = 0"
   367 proof -
   304 proof -
   368   let ?S = "\<lparr>space = X ` (space M), sets = Pow (X ` (space M))\<rparr>"
   305   have "sigma_algebra ?S" by (rule sigma_algebra_Pow)
   369   let ?M = "\<lparr>space = X ` (space M), sets = Pow (X ` (space M)), measure = distribution X\<rparr>"
   306   from distribution_prob_space[OF this X]
   370   interpret S: prob_space ?M
   307   interpret S: prob_space ?S "distribution X" by simp
   371     using distribution_prob_space[OF X] by auto
   308 
   372   { assume "{x} \<notin> sets ?M"
   309   have x: "{x} \<in> sets ?S"
   373     hence "x \<notin> X ` space M" by auto
   310   proof (rule ccontr)
       
   311     assume "{x} \<notin> sets ?S"
   374     hence "X -` {x} \<inter> space M = {}" by auto
   312     hence "X -` {x} \<inter> space M = {}" by auto
   375     hence "distribution X {x} = 0" unfolding distribution_def by auto
   313     thus "False" using assms unfolding distribution_def by auto
   376     hence "False" using assms by auto }
   314   qed
   377   hence x: "{x} \<in> sets ?M" by auto
   315 
   378   { assume "{y} \<notin> sets ?M"
   316   have [simp]: "{y} \<inter> {x} = {}" "{x} - {y} = {x}" using `y \<noteq> x` by auto
   379     hence "y \<notin> X ` space M" by auto
   317 
       
   318   show ?thesis
       
   319   proof cases
       
   320     assume "{y} \<in> sets ?S"
       
   321     with `{x} \<in> sets ?S` assms show "distribution X {y} = 0"
       
   322       using S.measure_inter_full_set[of "{y}" "{x}"]
       
   323       by simp
       
   324   next
       
   325     assume "{y} \<notin> sets ?S"
   380     hence "X -` {y} \<inter> space M = {}" by auto
   326     hence "X -` {y} \<inter> space M = {}" by auto
   381     hence "distribution X {y} = 0" unfolding distribution_def by auto }
   327     thus "distribution X {y} = 0" unfolding distribution_def by auto
   382   moreover
   328   qed
   383   { assume "{y} \<in> sets ?M"
   329 qed
   384     hence "distribution X {y} = 0" using assms S.prob_x_eq_1_imp_prob_y_eq_0[OF x] by auto }
       
   385   ultimately show ?thesis by auto
       
   386 qed
       
   387 
       
   388 
   330 
   389 end
   331 end
   390 
   332 
   391 locale finite_prob_space = prob_space + finite_measure_space
   333 locale finite_prob_space = prob_space + finite_measure_space
   392 
   334 
   393 lemma finite_prob_space_eq:
   335 lemma finite_prob_space_eq:
   394   "finite_prob_space M \<longleftrightarrow> finite_measure_space M \<and> measure M (space M) = 1"
   336   "finite_prob_space M \<mu> \<longleftrightarrow> finite_measure_space M \<mu> \<and> \<mu> (space M) = 1"
   395   unfolding finite_prob_space_def finite_measure_space_def prob_space_def prob_space_axioms_def
   337   unfolding finite_prob_space_def finite_measure_space_def prob_space_def prob_space_axioms_def
   396   by auto
   338   by auto
   397 
   339 
   398 lemma (in prob_space) not_empty: "space M \<noteq> {}"
   340 lemma (in prob_space) not_empty: "space M \<noteq> {}"
   399   using prob_space empty_measure by auto
   341   using prob_space empty_measure by auto
   400 
   342 
   401 lemma (in finite_prob_space) sum_over_space_eq_1: "(\<Sum>x\<in>space M. measure M {x}) = 1"
   343 lemma (in finite_prob_space) sum_over_space_eq_1: "(\<Sum>x\<in>space M. \<mu> {x}) = 1"
   402   using prob_space sum_over_space by simp
   344   using measure_space_1 sum_over_space by simp
   403 
   345 
   404 lemma (in finite_prob_space) positive_distribution: "0 \<le> distribution X x"
   346 lemma (in finite_prob_space) positive_distribution: "0 \<le> distribution X x"
   405   unfolding distribution_def using positive sets_eq_Pow by simp
   347   unfolding distribution_def by simp
   406 
   348 
   407 lemma (in finite_prob_space) joint_distribution_restriction_fst:
   349 lemma (in finite_prob_space) joint_distribution_restriction_fst:
   408   "joint_distribution X Y A \<le> distribution X (fst ` A)"
   350   "joint_distribution X Y A \<le> distribution X (fst ` A)"
   409   unfolding distribution_def
   351   unfolding distribution_def
   410 proof (safe intro!: measure_mono)
   352 proof (safe intro!: measure_mono)
   437     joint_distribution_restriction_snd[of X Y "{(x, y)}"]
   379     joint_distribution_restriction_snd[of X Y "{(x, y)}"]
   438   by auto
   380   by auto
   439 
   381 
   440 lemma (in finite_prob_space) finite_product_measure_space:
   382 lemma (in finite_prob_space) finite_product_measure_space:
   441   assumes "finite s1" "finite s2"
   383   assumes "finite s1" "finite s2"
   442   shows "finite_measure_space \<lparr> space = s1 \<times> s2, sets = Pow (s1 \<times> s2), measure = joint_distribution X Y\<rparr>"
   384   shows "finite_measure_space \<lparr> space = s1 \<times> s2, sets = Pow (s1 \<times> s2)\<rparr> (joint_distribution X Y)"
   443     (is "finite_measure_space ?M")
   385     (is "finite_measure_space ?M ?D")
   444 proof (rule finite_Pow_additivity_sufficient)
   386 proof (rule finite_Pow_additivity_sufficient)
   445   show "positive ?M (measure ?M)"
   387   show "positive ?D"
   446     unfolding positive_def using positive'[unfolded positive_def] assms sets_eq_Pow
   388     unfolding positive_def using assms sets_eq_Pow
   447     by (simp add: distribution_def)
   389     by (simp add: distribution_def)
   448 
   390 
   449   show "additive ?M (measure ?M)" unfolding additive_def
   391   show "additive ?M ?D" unfolding additive_def
   450   proof safe
   392   proof safe
   451     fix x y
   393     fix x y
   452     have A: "((\<lambda>x. (X x, Y x)) -` x) \<inter> space M \<in> sets M" using assms sets_eq_Pow by auto
   394     have A: "((\<lambda>x. (X x, Y x)) -` x) \<inter> space M \<in> sets M" using assms sets_eq_Pow by auto
   453     have B: "((\<lambda>x. (X x, Y x)) -` y) \<inter> space M \<in> sets M" using assms sets_eq_Pow by auto
   395     have B: "((\<lambda>x. (X x, Y x)) -` y) \<inter> space M \<in> sets M" using assms sets_eq_Pow by auto
   454     assume "x \<inter> y = {}"
   396     assume "x \<inter> y = {}"
       
   397     hence "(\<lambda>x. (X x, Y x)) -` x \<inter> space M \<inter> ((\<lambda>x. (X x, Y x)) -` y \<inter> space M) = {}"
       
   398       by auto
   455     from additive[unfolded additive_def, rule_format, OF A B] this
   399     from additive[unfolded additive_def, rule_format, OF A B] this
   456     show "measure ?M (x \<union> y) = measure ?M x + measure ?M y"
   400       finite_measure[OF A] finite_measure[OF B]
       
   401     show "?D (x \<union> y) = ?D x + ?D y"
   457       apply (simp add: distribution_def)
   402       apply (simp add: distribution_def)
   458       apply (subst Int_Un_distrib2)
   403       apply (subst Int_Un_distrib2)
   459       by auto
   404       by (auto simp: real_of_pinfreal_add)
   460   qed
   405   qed
   461 
   406 
   462   show "finite (space ?M)"
   407   show "finite (space ?M)"
   463     using assms by auto
   408     using assms by auto
   464 
   409 
   465   show "sets ?M = Pow (space ?M)"
   410   show "sets ?M = Pow (space ?M)"
   466     by simp
   411     by simp
       
   412 
       
   413   { fix x assume "x \<in> space ?M" thus "?D {x} \<noteq> \<omega>"
       
   414     unfolding distribution_def by (auto intro!: finite_measure simp: sets_eq_Pow) }
   467 qed
   415 qed
   468 
   416 
   469 lemma (in finite_prob_space) finite_product_measure_space_of_images:
   417 lemma (in finite_prob_space) finite_product_measure_space_of_images:
   470   shows "finite_measure_space \<lparr> space = X ` space M \<times> Y ` space M,
   418   shows "finite_measure_space \<lparr> space = X ` space M \<times> Y ` space M,
   471                                 sets = Pow (X ` space M \<times> Y ` space M),
   419                                 sets = Pow (X ` space M \<times> Y ` space M) \<rparr>
   472                                 measure = joint_distribution X Y\<rparr>"
   420                               (joint_distribution X Y)"
   473     (is "finite_measure_space ?M")
       
   474   using finite_space by (auto intro!: finite_product_measure_space)
   421   using finite_space by (auto intro!: finite_product_measure_space)
   475 
   422 
   476 lemma (in finite_prob_space) finite_measure_space:
   423 lemma (in finite_prob_space) finite_measure_space:
   477   shows "finite_measure_space \<lparr> space = X ` space M, sets = Pow (X ` space M), measure = distribution X\<rparr>"
   424   shows "finite_measure_space \<lparr>space = X ` space M, sets = Pow (X ` space M)\<rparr> (distribution X)"
   478     (is "finite_measure_space ?S")
   425     (is "finite_measure_space ?S _")
   479 proof (rule finite_Pow_additivity_sufficient, simp_all)
   426 proof (rule finite_Pow_additivity_sufficient, simp_all)
   480   show "finite (X ` space M)" using finite_space by simp
   427   show "finite (X ` space M)" using finite_space by simp
   481 
   428 
   482   show "positive ?S (distribution X)" unfolding distribution_def
   429   show "positive (distribution X)"
   483     unfolding positive_def using positive'[unfolded positive_def] sets_eq_Pow by auto
   430     unfolding distribution_def positive_def using sets_eq_Pow by auto
   484 
   431 
   485   show "additive ?S (distribution X)" unfolding additive_def distribution_def
   432   show "additive ?S (distribution X)" unfolding additive_def distribution_def
   486   proof (simp, safe)
   433   proof (simp, safe)
   487     fix x y
   434     fix x y
   488     have x: "(X -` x) \<inter> space M \<in> sets M"
   435     have x: "(X -` x) \<inter> space M \<in> sets M"
   489       and y: "(X -` y) \<inter> space M \<in> sets M" using sets_eq_Pow by auto
   436       and y: "(X -` y) \<inter> space M \<in> sets M" using sets_eq_Pow by auto
   490     assume "x \<inter> y = {}"
   437     assume "x \<inter> y = {}"
       
   438     hence "X -` x \<inter> space M \<inter> (X -` y \<inter> space M) = {}" by auto
   491     from additive[unfolded additive_def, rule_format, OF x y] this
   439     from additive[unfolded additive_def, rule_format, OF x y] this
   492     have "prob (((X -` x) \<union> (X -` y)) \<inter> space M) =
   440       finite_measure[OF x] finite_measure[OF y]
   493       prob ((X -` x) \<inter> space M) + prob ((X -` y) \<inter> space M)"
   441     have "\<mu> (((X -` x) \<union> (X -` y)) \<inter> space M) =
   494       apply (subst Int_Un_distrib2)
   442       \<mu> ((X -` x) \<inter> space M) + \<mu> ((X -` y) \<inter> space M)"
       
   443       by (subst Int_Un_distrib2) auto
       
   444     thus "\<mu> ((X -` x \<union> X -` y) \<inter> space M) = \<mu> (X -` x \<inter> space M) + \<mu> (X -` y \<inter> space M)"
   495       by auto
   445       by auto
   496     thus "prob ((X -` x \<union> X -` y) \<inter> space M) = prob (X -` x \<inter> space M) + prob (X -` y \<inter> space M)"
   446   qed
   497       by auto
   447 
   498   qed
   448   { fix x assume "x \<in> X ` space M" thus "distribution X {x} \<noteq> \<omega>"
       
   449     unfolding distribution_def by (auto intro!: finite_measure simp: sets_eq_Pow) }
   499 qed
   450 qed
   500 
   451 
   501 lemma (in finite_prob_space) finite_prob_space_of_images:
   452 lemma (in finite_prob_space) finite_prob_space_of_images:
   502   "finite_prob_space \<lparr> space = X ` space M, sets = Pow (X ` space M), measure = distribution X\<rparr>"
   453   "finite_prob_space \<lparr> space = X ` space M, sets = Pow (X ` space M)\<rparr> (distribution X)"
   503   (is "finite_prob_space ?S")
   454   by (simp add: finite_prob_space_eq finite_measure_space)
   504 proof (simp add: finite_prob_space_eq, safe)
       
   505   show "finite_measure_space ?S" by (rule finite_measure_space)
       
   506   have "X -` X ` space M \<inter> space M = space M" by auto
       
   507   thus "distribution X (X`space M) = 1"
       
   508     by (simp add: distribution_def prob_space)
       
   509 qed
       
   510 
   455 
   511 lemma (in finite_prob_space) finite_product_prob_space_of_images:
   456 lemma (in finite_prob_space) finite_product_prob_space_of_images:
   512   "finite_prob_space \<lparr> space = X ` space M \<times> Y ` space M, sets = Pow (X ` space M \<times> Y ` space M), 
   457   "finite_prob_space \<lparr> space = X ` space M \<times> Y ` space M, sets = Pow (X ` space M \<times> Y ` space M)\<rparr>
   513     measure = joint_distribution X Y\<rparr>"
   458                      (joint_distribution X Y)"
   514   (is "finite_prob_space ?S")
   459   (is "finite_prob_space ?S _")
   515 proof (simp add: finite_prob_space_eq, safe)
   460 proof (simp add: finite_prob_space_eq finite_product_measure_space_of_images)
   516   show "finite_measure_space ?S" by (rule finite_product_measure_space_of_images)
       
   517 
       
   518   have "X -` X ` space M \<inter> Y -` Y ` space M \<inter> space M = space M" by auto
   461   have "X -` X ` space M \<inter> Y -` Y ` space M \<inter> space M = space M" by auto
   519   thus "joint_distribution X Y (X ` space M \<times> Y ` space M) = 1"
   462   thus "joint_distribution X Y (X ` space M \<times> Y ` space M) = 1"
   520     by (simp add: distribution_def prob_space vimage_Times comp_def)
   463     by (simp add: distribution_def prob_space vimage_Times comp_def measure_space_1)
   521 qed
   464 qed
   522 
   465 
   523 end
   466 end