src/HOL/Probability/Measure.thy
changeset 40859 de0b30e6c2d2
parent 39092 98de40859858
child 40871 688f6ff859e1
equal deleted inserted replaced
40854:f2c9ebbe04aa 40859:de0b30e6c2d2
     1 header {*Measures*}
     1 (* Author: Lawrence C Paulson; Armin Heller, Johannes Hoelzl, TU Muenchen *)
     2 
     2 
     3 theory Measure
     3 theory Measure
     4   imports Caratheodory
     4   imports Caratheodory
     5 begin
     5 begin
     6 
     6 
     7 text{*From the Hurd/Coble measure theory development, translated by Lawrence Paulson.*}
     7 lemma inj_on_image_eq_iff:
       
     8   assumes "inj_on f S"
       
     9   assumes "A \<subseteq> S" "B \<subseteq> S"
       
    10   shows "(f ` A = f ` B) \<longleftrightarrow> (A = B)"
       
    11 proof -
       
    12   have "inj_on f (A \<union> B)"
       
    13     using assms by (auto intro: subset_inj_on)
       
    14   from inj_on_Un_image_eq_iff[OF this]
       
    15   show ?thesis .
       
    16 qed
       
    17 
       
    18 lemma image_vimage_inter_eq:
       
    19   assumes "f ` S = T" "X \<subseteq> T"
       
    20   shows "f ` (f -` X \<inter> S) = X"
       
    21 proof (intro antisym)
       
    22   have "f ` (f -` X \<inter> S) \<subseteq> f ` (f -` X)" by auto
       
    23   also have "\<dots> = X \<inter> range f" by simp
       
    24   also have "\<dots> = X" using assms by auto
       
    25   finally show "f ` (f -` X \<inter> S) \<subseteq> X" by auto
       
    26 next
       
    27   show "X \<subseteq> f ` (f -` X \<inter> S)"
       
    28   proof
       
    29     fix x assume "x \<in> X"
       
    30     then have "x \<in> T" using `X \<subseteq> T` by auto
       
    31     then obtain y where "x = f y" "y \<in> S"
       
    32       using assms by auto
       
    33     then have "{y} \<subseteq> f -` X \<inter> S" using `x \<in> X` by auto
       
    34     moreover have "x \<in> f ` {y}" using `x = f y` by auto
       
    35     ultimately show "x \<in> f ` (f -` X \<inter> S)" by auto
       
    36   qed
       
    37 qed
       
    38 
       
    39 text {*
       
    40   This formalisation of measure theory is based on the work of Hurd/Coble wand
       
    41   was later translated by Lawrence Paulson to Isabelle/HOL. Later it was
       
    42   modified to use the positive infinite reals and to prove the uniqueness of
       
    43   cut stable measures.
       
    44 *}
     8 
    45 
     9 section {* Equations for the measure function @{text \<mu>} *}
    46 section {* Equations for the measure function @{text \<mu>} *}
    10 
    47 
    11 lemma (in measure_space) measure_countably_additive:
    48 lemma (in measure_space) measure_countably_additive:
    12   assumes "range A \<subseteq> sets M" "disjoint_family A"
    49   assumes "range A \<subseteq> sets M" "disjoint_family A"
   155   finally have "(SUP n. \<mu> (nat_case {} A n)) = \<mu> (\<Union>i. A i)" .
   192   finally have "(SUP n. \<mu> (nat_case {} A n)) = \<mu> (\<Union>i. A i)" .
   156   thus ?thesis unfolding meq * comp_def .
   193   thus ?thesis unfolding meq * comp_def .
   157 qed
   194 qed
   158 
   195 
   159 lemma (in measure_space) measure_up:
   196 lemma (in measure_space) measure_up:
   160   assumes "P \<in> sets M" "\<And>i. B i \<in> sets M" "B \<up> P"
   197   assumes "\<And>i. B i \<in> sets M" "B \<up> P"
   161   shows "(\<lambda>i. \<mu> (B i)) \<up> \<mu> P"
   198   shows "(\<lambda>i. \<mu> (B i)) \<up> \<mu> P"
   162   using assms unfolding isoton_def
   199   using assms unfolding isoton_def
   163   by (auto intro!: measure_mono continuity_from_below)
   200   by (auto intro!: measure_mono continuity_from_below)
   164 
   201 
       
   202 lemma (in measure_space) continuity_from_below':
       
   203   assumes A: "range A \<subseteq> sets M" "\<And>i. A i \<subseteq> A (Suc i)"
       
   204   shows "(\<lambda>i. (\<mu> (A i))) ----> (\<mu> (\<Union>i. A i))"
       
   205 proof- let ?A = "\<Union>i. A i"
       
   206   have " (\<lambda>i. \<mu> (A i)) \<up> \<mu> ?A" apply(rule measure_up)
       
   207     using assms unfolding complete_lattice_class.isoton_def by auto
       
   208   thus ?thesis by(rule isotone_Lim(1))
       
   209 qed
   165 
   210 
   166 lemma (in measure_space) continuity_from_above:
   211 lemma (in measure_space) continuity_from_above:
   167   assumes A: "range A \<subseteq> sets M"
   212   assumes A: "range A \<subseteq> sets M"
   168   and mono_Suc: "\<And>n.  A (Suc n) \<subseteq> A n"
   213   and mono_Suc: "\<And>n.  A (Suc n) \<subseteq> A n"
   169   and finite: "\<And>i. \<mu> (A i) \<noteq> \<omega>"
   214   and finite: "\<And>i. \<mu> (A i) \<noteq> \<omega>"
   194   finally show ?thesis
   239   finally show ?thesis
   195     by (rule pinfreal_diff_eq_diff_imp_eq[OF finite[of 0] le_IM le_MI])
   240     by (rule pinfreal_diff_eq_diff_imp_eq[OF finite[of 0] le_IM le_MI])
   196 qed
   241 qed
   197 
   242 
   198 lemma (in measure_space) measure_down:
   243 lemma (in measure_space) measure_down:
   199   assumes "P \<in> sets M" "\<And>i. B i \<in> sets M" "B \<down> P"
   244   assumes "\<And>i. B i \<in> sets M" "B \<down> P"
   200   and finite: "\<And>i. \<mu> (B i) \<noteq> \<omega>"
   245   and finite: "\<And>i. \<mu> (B i) \<noteq> \<omega>"
   201   shows "(\<lambda>i. \<mu> (B i)) \<down> \<mu> P"
   246   shows "(\<lambda>i. \<mu> (B i)) \<down> \<mu> P"
   202   using assms unfolding antiton_def
   247   using assms unfolding antiton_def
   203   by (auto intro!: measure_mono continuity_from_above)
   248   by (auto intro!: measure_mono continuity_from_above)
   204 lemma (in measure_space) measure_insert:
   249 lemma (in measure_space) measure_insert:
   412   also have "\<dots> \<le> \<mu> A + \<mu> B"
   457   also have "\<dots> \<le> \<mu> A + \<mu> B"
   413     using assms by (auto intro!: add_left_mono measure_mono)
   458     using assms by (auto intro!: add_left_mono measure_mono)
   414   finally show ?thesis .
   459   finally show ?thesis .
   415 qed
   460 qed
   416 
   461 
       
   462 lemma (in measure_space) measure_eq_0:
       
   463   assumes "N \<in> sets M" and "\<mu> N = 0" and "K \<subseteq> N" and "K \<in> sets M"
       
   464   shows "\<mu> K = 0"
       
   465 using measure_mono[OF assms(3,4,1)] assms(2) by auto
       
   466 
   417 lemma (in measure_space) measure_finitely_subadditive:
   467 lemma (in measure_space) measure_finitely_subadditive:
   418   assumes "finite I" "A ` I \<subseteq> sets M"
   468   assumes "finite I" "A ` I \<subseteq> sets M"
   419   shows "\<mu> (\<Union>i\<in>I. A i) \<le> (\<Sum>i\<in>I. \<mu> (A i))"
   469   shows "\<mu> (\<Union>i\<in>I. A i) \<le> (\<Sum>i\<in>I. \<mu> (A i))"
   420 using assms proof induct
   470 using assms proof induct
   421   case (insert i I)
   471   case (insert i I)
   425   also have "\<dots> \<le> (\<Sum>i\<in>insert i I. \<mu> (A i))"
   475   also have "\<dots> \<le> (\<Sum>i\<in>insert i I. \<mu> (A i))"
   426     using insert by (auto intro!: add_left_mono)
   476     using insert by (auto intro!: add_left_mono)
   427   finally show ?case .
   477   finally show ?case .
   428 qed simp
   478 qed simp
   429 
   479 
   430 lemma (in measure_space) measurable_countably_subadditive:
   480 lemma (in measure_space) measure_countably_subadditive:
   431   assumes "range f \<subseteq> sets M"
   481   assumes "range f \<subseteq> sets M"
   432   shows "\<mu> (\<Union>i. f i) \<le> (\<Sum>\<^isub>\<infinity> i. \<mu> (f i))"
   482   shows "\<mu> (\<Union>i. f i) \<le> (\<Sum>\<^isub>\<infinity> i. \<mu> (f i))"
   433 proof -
   483 proof -
   434   have "\<mu> (\<Union>i. f i) = \<mu> (\<Union>i. disjointed f i)"
   484   have "\<mu> (\<Union>i. f i) = \<mu> (\<Union>i. disjointed f i)"
   435     unfolding UN_disjointed_eq ..
   485     unfolding UN_disjointed_eq ..
   442     show "f i \<in> sets M" "disjointed f i \<in> sets M"
   492     show "f i \<in> sets M" "disjointed f i \<in> sets M"
   443       using assms range_disjointed_sets[OF assms] by auto
   493       using assms range_disjointed_sets[OF assms] by auto
   444   qed
   494   qed
   445   finally show ?thesis .
   495   finally show ?thesis .
   446 qed
   496 qed
       
   497 
       
   498 lemma (in measure_space) measure_UN_eq_0:
       
   499   assumes "\<And> i :: nat. \<mu> (N i) = 0" and "range N \<subseteq> sets M"
       
   500   shows "\<mu> (\<Union> i. N i) = 0"
       
   501 using measure_countably_subadditive[OF assms(2)] assms(1) by auto
   447 
   502 
   448 lemma (in measure_space) measure_inter_full_set:
   503 lemma (in measure_space) measure_inter_full_set:
   449   assumes "S \<in> sets M" "T \<in> sets M" and not_\<omega>: "\<mu> (T - S) \<noteq> \<omega>"
   504   assumes "S \<in> sets M" "T \<in> sets M" and not_\<omega>: "\<mu> (T - S) \<noteq> \<omega>"
   450   assumes T: "\<mu> T = \<mu> (space M)"
   505   assumes T: "\<mu> T = \<mu> (space M)"
   451   shows "\<mu> (S \<inter> T) = \<mu> S"
   506   shows "\<mu> (S \<inter> T) = \<mu> S"
   466       using assms by (subst measure_additive) auto
   521       using assms by (subst measure_additive) auto
   467     also have "\<dots> \<le> \<mu> (space M)"
   522     also have "\<dots> \<le> \<mu> (space M)"
   468       using assms sets_into_space by (auto intro!: measure_mono)
   523       using assms sets_into_space by (auto intro!: measure_mono)
   469     finally show False ..
   524     finally show False ..
   470   qed
   525   qed
       
   526 qed
       
   527 
       
   528 lemma measure_unique_Int_stable:
       
   529   fixes M E :: "'a algebra" and A :: "nat \<Rightarrow> 'a set"
       
   530   assumes "Int_stable E" "M = sigma E"
       
   531   and A: "range  A \<subseteq> sets E" "A \<up> space E"
       
   532   and ms: "measure_space M \<mu>" "measure_space M \<nu>"
       
   533   and eq: "\<And>X. X \<in> sets E \<Longrightarrow> \<mu> X = \<nu> X"
       
   534   and finite: "\<And>i. \<mu> (A i) \<noteq> \<omega>"
       
   535   assumes "X \<in> sets M"
       
   536   shows "\<mu> X = \<nu> X"
       
   537 proof -
       
   538   let "?D F" = "{D. D \<in> sets M \<and> \<mu> (F \<inter> D) = \<nu> (F \<inter> D)}"
       
   539   interpret M: measure_space M \<mu> by fact
       
   540   interpret M': measure_space M \<nu> by fact
       
   541   have "space E = space M"
       
   542     using `M = sigma E` by simp
       
   543   have sets_E: "sets E \<subseteq> Pow (space E)"
       
   544   proof
       
   545     fix X assume "X \<in> sets E"
       
   546     then have "X \<in> sets M" unfolding `M = sigma E`
       
   547       unfolding sigma_def by (auto intro!: sigma_sets.Basic)
       
   548     with M.sets_into_space show "X \<in> Pow (space E)"
       
   549       unfolding `space E = space M` by auto
       
   550   qed
       
   551   have A': "range A \<subseteq> sets M" using `M = sigma E` A
       
   552     by (auto simp: sets_sigma intro!: sigma_sets.Basic)
       
   553   { fix F assume "F \<in> sets E" and "\<mu> F \<noteq> \<omega>"
       
   554     then have [intro]: "F \<in> sets M" unfolding `M = sigma E` sets_sigma
       
   555       by (intro sigma_sets.Basic)
       
   556     have "\<nu> F \<noteq> \<omega>" using `\<mu> F \<noteq> \<omega>` `F \<in> sets E` eq by simp
       
   557     interpret D: dynkin_system "\<lparr>space=space E, sets=?D F\<rparr>"
       
   558     proof (rule dynkin_systemI, simp_all)
       
   559       fix A assume "A \<in> sets M \<and> \<mu> (F \<inter> A) = \<nu> (F \<inter> A)"
       
   560       then show "A \<subseteq> space E"
       
   561         unfolding `space E = space M` using M.sets_into_space by auto
       
   562     next
       
   563       have "F \<inter> space E = F" using `F \<in> sets E` sets_E by auto
       
   564       then show "space E \<in> sets M \<and> \<mu> (F \<inter> space E) = \<nu> (F \<inter> space E)"
       
   565         unfolding `space E = space M` using `F \<in> sets E` eq by auto
       
   566     next
       
   567       fix A assume *: "A \<in> sets M \<and> \<mu> (F \<inter> A) = \<nu> (F \<inter> A)"
       
   568       then have **: "F \<inter> (space M - A) = F - (F \<inter> A)"
       
   569         and [intro]: "F \<inter> A \<in> sets M"
       
   570         using `F \<in> sets E` sets_E `space E = space M` by auto
       
   571       have "\<nu> (F \<inter> A) \<le> \<nu> F" by (auto intro!: M'.measure_mono)
       
   572       then have "\<nu> (F \<inter> A) \<noteq> \<omega>" using `\<nu> F \<noteq> \<omega>` by auto
       
   573       have "\<mu> (F \<inter> A) \<le> \<mu> F" by (auto intro!: M.measure_mono)
       
   574       then have "\<mu> (F \<inter> A) \<noteq> \<omega>" using `\<mu> F \<noteq> \<omega>` by auto
       
   575       then have "\<mu> (F \<inter> (space M - A)) = \<mu> F - \<mu> (F \<inter> A)" unfolding **
       
   576         using `F \<inter> A \<in> sets M` by (auto intro!: M.measure_Diff)
       
   577       also have "\<dots> = \<nu> F - \<nu> (F \<inter> A)" using eq `F \<in> sets E` * by simp
       
   578       also have "\<dots> = \<nu> (F \<inter> (space M - A))" unfolding **
       
   579         using `F \<inter> A \<in> sets M` `\<nu> (F \<inter> A) \<noteq> \<omega>` by (auto intro!: M'.measure_Diff[symmetric])
       
   580       finally show "space E - A \<in> sets M \<and> \<mu> (F \<inter> (space E - A)) = \<nu> (F \<inter> (space E - A))"
       
   581         using `space E = space M` * by auto
       
   582     next
       
   583       fix A :: "nat \<Rightarrow> 'a set"
       
   584       assume "disjoint_family A" "range A \<subseteq> {X \<in> sets M. \<mu> (F \<inter> X) = \<nu> (F \<inter> X)}"
       
   585       then have A: "range (\<lambda>i. F \<inter> A i) \<subseteq> sets M" "F \<inter> (\<Union>x. A x) = (\<Union>x. F \<inter> A x)"
       
   586         "disjoint_family (\<lambda>i. F \<inter> A i)" "\<And>i. \<mu> (F \<inter> A i) = \<nu> (F \<inter> A i)" "range A \<subseteq> sets M"
       
   587         by ((fastsimp simp: disjoint_family_on_def)+)
       
   588       then show "(\<Union>x. A x) \<in> sets M \<and> \<mu> (F \<inter> (\<Union>x. A x)) = \<nu> (F \<inter> (\<Union>x. A x))"
       
   589         by (auto simp: M.measure_countably_additive[symmetric]
       
   590                        M'.measure_countably_additive[symmetric]
       
   591             simp del: UN_simps)
       
   592     qed
       
   593     have *: "sigma E = \<lparr>space = space E, sets = ?D F\<rparr>"
       
   594       using `M = sigma E` `F \<in> sets E` `Int_stable E`
       
   595       by (intro D.dynkin_lemma)
       
   596          (auto simp add: sets_sigma Int_stable_def eq intro: sigma_sets.Basic)
       
   597     have "\<And>D. D \<in> sets M \<Longrightarrow> \<mu> (F \<inter> D) = \<nu> (F \<inter> D)"
       
   598       unfolding `M = sigma E` by (auto simp: *) }
       
   599   note * = this
       
   600   { fix i have "\<mu> (A i \<inter> X) = \<nu> (A i \<inter> X)"
       
   601       using *[of "A i" X] `X \<in> sets M` A finite by auto }
       
   602   moreover
       
   603   have "(\<lambda>i. A i \<inter> X) \<up> X"
       
   604     using `X \<in> sets M` M.sets_into_space A `space E = space M`
       
   605     by (auto simp: isoton_def)
       
   606   then have "(\<lambda>i. \<mu> (A i \<inter> X)) \<up> \<mu> X" "(\<lambda>i. \<nu> (A i \<inter> X)) \<up> \<nu> X"
       
   607     using `X \<in> sets M` A' by (auto intro!: M.measure_up M'.measure_up M.Int)
       
   608   ultimately show ?thesis by (simp add: isoton_def)
       
   609 qed
       
   610 
       
   611 section "Isomorphisms between measure spaces"
       
   612 
       
   613 lemma (in measure_space) measure_space_isomorphic:
       
   614   fixes f :: "'c \<Rightarrow> 'a"
       
   615   assumes "bij_betw f S (space M)"
       
   616   shows "measure_space (vimage_algebra S f) (\<lambda>A. \<mu> (f ` A))"
       
   617     (is "measure_space ?T ?\<mu>")
       
   618 proof -
       
   619   have "f \<in> S \<rightarrow> space M" using assms unfolding bij_betw_def by auto
       
   620   then interpret T: sigma_algebra ?T by (rule sigma_algebra_vimage)
       
   621   show ?thesis
       
   622   proof
       
   623     show "\<mu> (f`{}) = 0" by simp
       
   624     show "countably_additive ?T (\<lambda>A. \<mu> (f ` A))"
       
   625     proof (unfold countably_additive_def, intro allI impI)
       
   626       fix A :: "nat \<Rightarrow> 'c set" assume "range A \<subseteq> sets ?T" "disjoint_family A"
       
   627       then have "\<forall>i. \<exists>F'. F' \<in> sets M \<and> A i = f -` F' \<inter> S"
       
   628         by (auto simp: image_iff image_subset_iff Bex_def vimage_algebra_def)
       
   629       from choice[OF this] obtain F where F: "\<And>i. F i \<in> sets M" and A: "\<And>i. A i = f -` F i \<inter> S" by auto
       
   630       then have [simp]: "\<And>i. f ` (A i) = F i"
       
   631         using sets_into_space assms
       
   632         by (force intro!: image_vimage_inter_eq[where T="space M"] simp: bij_betw_def)
       
   633       have "disjoint_family F"
       
   634       proof (intro disjoint_family_on_bisimulation[OF `disjoint_family A`])
       
   635         fix n m assume "A n \<inter> A m = {}"
       
   636         then have "f -` (F n \<inter> F m) \<inter> S = {}" unfolding A by auto
       
   637         moreover
       
   638         have "F n \<in> sets M" "F m \<in> sets M" using F by auto
       
   639         then have "f`S = space M" "F n \<inter> F m \<subseteq> space M"
       
   640           using sets_into_space assms by (auto simp: bij_betw_def)
       
   641         note image_vimage_inter_eq[OF this, symmetric]
       
   642         ultimately show "F n \<inter> F m = {}" by simp
       
   643       qed
       
   644       with F show "(\<Sum>\<^isub>\<infinity> i. \<mu> (f ` A i)) = \<mu> (f ` (\<Union>i. A i))"
       
   645         by (auto simp add: image_UN intro!: measure_countably_additive)
       
   646     qed
       
   647   qed
       
   648 qed
       
   649 
       
   650 section "@{text \<mu>}-null sets"
       
   651 
       
   652 abbreviation (in measure_space) "null_sets \<equiv> {N\<in>sets M. \<mu> N = 0}"
       
   653 
       
   654 definition (in measure_space)
       
   655   almost_everywhere :: "('a \<Rightarrow> bool) \<Rightarrow> bool" (binder "AE " 10) where
       
   656   "almost_everywhere P \<longleftrightarrow> (\<exists>N\<in>null_sets. { x \<in> space M. \<not> P x } \<subseteq> N)"
       
   657 
       
   658 lemma (in measure_space) AE_I':
       
   659   "N \<in> null_sets \<Longrightarrow> {x\<in>space M. \<not> P x} \<subseteq> N \<Longrightarrow> (AE x. P x)"
       
   660   unfolding almost_everywhere_def by auto
       
   661 
       
   662 lemma (in measure_space) AE_iff_null_set:
       
   663   assumes "{x\<in>space M. \<not> P x} \<in> sets M" (is "?P \<in> sets M")
       
   664   shows "(AE x. P x) \<longleftrightarrow> {x\<in>space M. \<not> P x} \<in> null_sets"
       
   665 proof
       
   666   assume "AE x. P x" then obtain N where N: "N \<in> sets M" "?P \<subseteq> N" "\<mu> N = 0"
       
   667     unfolding almost_everywhere_def by auto
       
   668   moreover have "\<mu> ?P \<le> \<mu> N"
       
   669     using assms N(1,2) by (auto intro: measure_mono)
       
   670   ultimately show "?P \<in> null_sets" using assms by auto
       
   671 next
       
   672   assume "?P \<in> null_sets" with assms show "AE x. P x" by (auto intro: AE_I')
       
   673 qed
       
   674 
       
   675 lemma (in measure_space) null_sets_Un[intro]:
       
   676   assumes "N \<in> null_sets" "N' \<in> null_sets"
       
   677   shows "N \<union> N' \<in> null_sets"
       
   678 proof (intro conjI CollectI)
       
   679   show "N \<union> N' \<in> sets M" using assms by auto
       
   680   have "\<mu> (N \<union> N') \<le> \<mu> N + \<mu> N'"
       
   681     using assms by (intro measure_subadditive) auto
       
   682   then show "\<mu> (N \<union> N') = 0"
       
   683     using assms by auto
       
   684 qed
       
   685 
       
   686 lemma UN_from_nat: "(\<Union>i. N i) = (\<Union>i. N (Countable.from_nat i))"
       
   687 proof -
       
   688   have "(\<Union>i. N i) = (\<Union>i. (N \<circ> Countable.from_nat) i)"
       
   689     unfolding SUPR_def image_compose
       
   690     unfolding surj_from_nat ..
       
   691   then show ?thesis by simp
       
   692 qed
       
   693 
       
   694 lemma (in measure_space) null_sets_UN[intro]:
       
   695   assumes "\<And>i::'i::countable. N i \<in> null_sets"
       
   696   shows "(\<Union>i. N i) \<in> null_sets"
       
   697 proof (intro conjI CollectI)
       
   698   show "(\<Union>i. N i) \<in> sets M" using assms by auto
       
   699   have "\<mu> (\<Union>i. N i) \<le> (\<Sum>\<^isub>\<infinity> n. \<mu> (N (Countable.from_nat n)))"
       
   700     unfolding UN_from_nat[of N]
       
   701     using assms by (intro measure_countably_subadditive) auto
       
   702   then show "\<mu> (\<Union>i. N i) = 0"
       
   703     using assms by auto
       
   704 qed
       
   705 
       
   706 lemma (in measure_space) null_set_Int1:
       
   707   assumes "B \<in> null_sets" "A \<in> sets M" shows "A \<inter> B \<in> null_sets"
       
   708 using assms proof (intro CollectI conjI)
       
   709   show "\<mu> (A \<inter> B) = 0" using assms by (intro measure_eq_0[of B "A \<inter> B"]) auto
       
   710 qed auto
       
   711 
       
   712 lemma (in measure_space) null_set_Int2:
       
   713   assumes "B \<in> null_sets" "A \<in> sets M" shows "B \<inter> A \<in> null_sets"
       
   714   using assms by (subst Int_commute) (rule null_set_Int1)
       
   715 
       
   716 lemma (in measure_space) measure_Diff_null_set:
       
   717   assumes "B \<in> null_sets" "A \<in> sets M"
       
   718   shows "\<mu> (A - B) = \<mu> A"
       
   719 proof -
       
   720   have *: "A - B = (A - (A \<inter> B))" by auto
       
   721   have "A \<inter> B \<in> null_sets" using assms by (rule null_set_Int1)
       
   722   then show ?thesis
       
   723     unfolding * using assms
       
   724     by (subst measure_Diff) auto
       
   725 qed
       
   726 
       
   727 lemma (in measure_space) null_set_Diff:
       
   728   assumes "B \<in> null_sets" "A \<in> sets M" shows "B - A \<in> null_sets"
       
   729 using assms proof (intro CollectI conjI)
       
   730   show "\<mu> (B - A) = 0" using assms by (intro measure_eq_0[of B "B - A"]) auto
       
   731 qed auto
       
   732 
       
   733 lemma (in measure_space) measure_Un_null_set:
       
   734   assumes "A \<in> sets M" "B \<in> null_sets"
       
   735   shows "\<mu> (A \<union> B) = \<mu> A"
       
   736 proof -
       
   737   have *: "A \<union> B = A \<union> (B - A)" by auto
       
   738   have "B - A \<in> null_sets" using assms(2,1) by (rule null_set_Diff)
       
   739   then show ?thesis
       
   740     unfolding * using assms
       
   741     by (subst measure_additive[symmetric]) auto
       
   742 qed
       
   743 
       
   744 lemma (in measure_space) AE_True[intro, simp]: "AE x. True"
       
   745   unfolding almost_everywhere_def by auto
       
   746 
       
   747 lemma (in measure_space) AE_E[consumes 1]:
       
   748   assumes "AE x. P x"
       
   749   obtains N where "{x \<in> space M. \<not> P x} \<subseteq> N" "\<mu> N = 0" "N \<in> sets M"
       
   750   using assms unfolding almost_everywhere_def by auto
       
   751 
       
   752 lemma (in measure_space) AE_I:
       
   753   assumes "{x \<in> space M. \<not> P x} \<subseteq> N" "\<mu> N = 0" "N \<in> sets M"
       
   754   shows "AE x. P x"
       
   755   using assms unfolding almost_everywhere_def by auto
       
   756 
       
   757 lemma (in measure_space) AE_mp:
       
   758   assumes AE_P: "AE x. P x" and AE_imp: "AE x. P x \<longrightarrow> Q x"
       
   759   shows "AE x. Q x"
       
   760 proof -
       
   761   from AE_P obtain A where P: "{x\<in>space M. \<not> P x} \<subseteq> A"
       
   762     and A: "A \<in> sets M" "\<mu> A = 0"
       
   763     by (auto elim!: AE_E)
       
   764 
       
   765   from AE_imp obtain B where imp: "{x\<in>space M. P x \<and> \<not> Q x} \<subseteq> B"
       
   766     and B: "B \<in> sets M" "\<mu> B = 0"
       
   767     by (auto elim!: AE_E)
       
   768 
       
   769   show ?thesis
       
   770   proof (intro AE_I)
       
   771     show "A \<union> B \<in> sets M" "\<mu> (A \<union> B) = 0" using A B
       
   772       using measure_subadditive[of A B] by auto
       
   773     show "{x\<in>space M. \<not> Q x} \<subseteq> A \<union> B"
       
   774       using P imp by auto
       
   775   qed
       
   776 qed
       
   777 
       
   778 lemma (in measure_space) AE_iffI:
       
   779   assumes P: "AE x. P x" and Q: "AE x. P x \<longleftrightarrow> Q x" shows "AE x. Q x"
       
   780   using AE_mp[OF Q, of "\<lambda>x. P x \<longrightarrow> Q x"] AE_mp[OF P, of Q] by auto
       
   781 
       
   782 lemma (in measure_space) AE_disjI1:
       
   783   assumes P: "AE x. P x" shows "AE x. P x \<or> Q x"
       
   784   by (rule AE_mp[OF P]) auto
       
   785 
       
   786 lemma (in measure_space) AE_disjI2:
       
   787   assumes P: "AE x. Q x" shows "AE x. P x \<or> Q x"
       
   788   by (rule AE_mp[OF P]) auto
       
   789 
       
   790 lemma (in measure_space) AE_conjI:
       
   791   assumes AE_P: "AE x. P x" and AE_Q: "AE x. Q x"
       
   792   shows "AE x. P x \<and> Q x"
       
   793 proof -
       
   794   from AE_P obtain A where P: "{x\<in>space M. \<not> P x} \<subseteq> A"
       
   795     and A: "A \<in> sets M" "\<mu> A = 0"
       
   796     by (auto elim!: AE_E)
       
   797 
       
   798   from AE_Q obtain B where Q: "{x\<in>space M. \<not> Q x} \<subseteq> B"
       
   799     and B: "B \<in> sets M" "\<mu> B = 0"
       
   800     by (auto elim!: AE_E)
       
   801 
       
   802   show ?thesis
       
   803   proof (intro AE_I)
       
   804     show "A \<union> B \<in> sets M" "\<mu> (A \<union> B) = 0" using A B
       
   805       using measure_subadditive[of A B] by auto
       
   806     show "{x\<in>space M. \<not> (P x \<and> Q x)} \<subseteq> A \<union> B"
       
   807       using P Q by auto
       
   808   qed
       
   809 qed
       
   810 
       
   811 lemma (in measure_space) AE_E2:
       
   812   assumes "AE x. P x" "{x\<in>space M. P x} \<in> sets M"
       
   813   shows "\<mu> {x\<in>space M. \<not> P x} = 0" (is "\<mu> ?P = 0")
       
   814 proof -
       
   815   obtain A where A: "?P \<subseteq> A" "A \<in> sets M" "\<mu> A = 0"
       
   816     using assms by (auto elim!: AE_E)
       
   817   have "?P = space M - {x\<in>space M. P x}" by auto
       
   818   then have "?P \<in> sets M" using assms by auto
       
   819   with assms `?P \<subseteq> A` `A \<in> sets M` have "\<mu> ?P \<le> \<mu> A"
       
   820     by (auto intro!: measure_mono)
       
   821   then show "\<mu> ?P = 0" using A by simp
       
   822 qed
       
   823 
       
   824 lemma (in measure_space) AE_space[simp, intro]: "AE x. x \<in> space M"
       
   825   by (rule AE_I[where N="{}"]) auto
       
   826 
       
   827 lemma (in measure_space) AE_cong:
       
   828   assumes "\<And>x. x \<in> space M \<Longrightarrow> P x" shows "AE x. P x"
       
   829 proof -
       
   830   have [simp]: "\<And>x. (x \<in> space M \<longrightarrow> P x) \<longleftrightarrow> True" using assms by auto
       
   831   show ?thesis
       
   832     by (rule AE_mp[OF AE_space]) auto
       
   833 qed
       
   834 
       
   835 lemma (in measure_space) AE_conj_iff[simp]:
       
   836   shows "(AE x. P x \<and> Q x) \<longleftrightarrow> (AE x. P x) \<and> (AE x. Q x)"
       
   837 proof (intro conjI iffI AE_conjI)
       
   838   assume *: "AE x. P x \<and> Q x"
       
   839   from * show "AE x. P x" by (rule AE_mp) auto
       
   840   from * show "AE x. Q x" by (rule AE_mp) auto
       
   841 qed auto
       
   842 
       
   843 lemma (in measure_space) all_AE_countable:
       
   844   "(\<forall>i::'i::countable. AE x. P i x) \<longleftrightarrow> (AE x. \<forall>i. P i x)"
       
   845 proof
       
   846   assume "\<forall>i. AE x. P i x"
       
   847   from this[unfolded almost_everywhere_def Bex_def, THEN choice]
       
   848   obtain N where N: "\<And>i. N i \<in> null_sets" "\<And>i. {x\<in>space M. \<not> P i x} \<subseteq> N i" by auto
       
   849   have "{x\<in>space M. \<not> (\<forall>i. P i x)} \<subseteq> (\<Union>i. {x\<in>space M. \<not> P i x})" by auto
       
   850   also have "\<dots> \<subseteq> (\<Union>i. N i)" using N by auto
       
   851   finally have "{x\<in>space M. \<not> (\<forall>i. P i x)} \<subseteq> (\<Union>i. N i)" .
       
   852   moreover from N have "(\<Union>i. N i) \<in> null_sets"
       
   853     by (intro null_sets_UN) auto
       
   854   ultimately show "AE x. \<forall>i. P i x"
       
   855     unfolding almost_everywhere_def by auto
       
   856 next
       
   857   assume *: "AE x. \<forall>i. P i x"
       
   858   show "\<forall>i. AE x. P i x"
       
   859     by (rule allI, rule AE_mp[OF *]) simp
   471 qed
   860 qed
   472 
   861 
   473 lemma (in measure_space) restricted_measure_space:
   862 lemma (in measure_space) restricted_measure_space:
   474   assumes "S \<in> sets M"
   863   assumes "S \<in> sets M"
   475   shows "measure_space (restricted_space S) \<mu>"
   864   shows "measure_space (restricted_space S) \<mu>"
   488       using measure_countably_additive by simp
   877       using measure_countably_additive by simp
   489   qed
   878   qed
   490 qed
   879 qed
   491 
   880 
   492 lemma (in measure_space) measure_space_vimage:
   881 lemma (in measure_space) measure_space_vimage:
       
   882   fixes M' :: "'b algebra"
   493   assumes "f \<in> measurable M M'"
   883   assumes "f \<in> measurable M M'"
   494   and "sigma_algebra M'"
   884   and "sigma_algebra M'"
   495   shows "measure_space M' (\<lambda>A. \<mu> (f -` A \<inter> space M))" (is "measure_space M' ?T")
   885   shows "measure_space M' (\<lambda>A. \<mu> (f -` A \<inter> space M))" (is "measure_space M' ?T")
   496 proof -
   886 proof -
   497   interpret M': sigma_algebra M' by fact
   887   interpret M': sigma_algebra M' by fact
   500   proof
   890   proof
   501     show "?T {} = 0" by simp
   891     show "?T {} = 0" by simp
   502 
   892 
   503     show "countably_additive M' ?T"
   893     show "countably_additive M' ?T"
   504     proof (unfold countably_additive_def, safe)
   894     proof (unfold countably_additive_def, safe)
   505       fix A :: "nat \<Rightarrow> 'c set" assume "range A \<subseteq> sets M'" "disjoint_family A"
   895       fix A :: "nat \<Rightarrow> 'b set" assume "range A \<subseteq> sets M'" "disjoint_family A"
   506       hence *: "\<And>i. f -` (A i) \<inter> space M \<in> sets M"
   896       hence *: "\<And>i. f -` (A i) \<inter> space M \<in> sets M"
   507         using `f \<in> measurable M M'` by (auto simp: measurable_def)
   897         using `f \<in> measurable M M'` by (auto simp: measurable_def)
   508       moreover have "(\<Union>i. f -`  A i \<inter> space M) \<in> sets M"
   898       moreover have "(\<Union>i. f -`  A i \<inter> space M) \<in> sets M"
   509         using * by blast
   899         using * by blast
   510       moreover have **: "disjoint_family (\<lambda>i. f -` A i \<inter> space M)"
   900       moreover have **: "disjoint_family (\<lambda>i. f -` A i \<inter> space M)"
   562     also have "\<dots> < \<omega>" using `\<mu> (A i) \<noteq> \<omega>` by (auto simp: pinfreal_less_\<omega>)
   952     also have "\<dots> < \<omega>" using `\<mu> (A i) \<noteq> \<omega>` by (auto simp: pinfreal_less_\<omega>)
   563     finally show "\<mu> (A i \<inter> S) \<noteq> \<omega>" by (auto simp: pinfreal_less_\<omega>)
   953     finally show "\<mu> (A i \<inter> S) \<noteq> \<omega>" by (auto simp: pinfreal_less_\<omega>)
   564   qed
   954   qed
   565 qed
   955 qed
   566 
   956 
       
   957 lemma (in sigma_finite_measure) sigma_finite_measure_cong:
       
   958   assumes cong: "\<And>A. A \<in> sets M \<Longrightarrow> \<mu>' A = \<mu> A"
       
   959   shows "sigma_finite_measure M \<mu>'"
       
   960 proof -
       
   961   interpret \<mu>': measure_space M \<mu>'
       
   962     using cong by (rule measure_space_cong)
       
   963   from sigma_finite guess A .. note A = this
       
   964   then have "\<And>i. A i \<in> sets M" by auto
       
   965   with A have fin: "(\<forall>i. \<mu>' (A i) \<noteq> \<omega>)" using cong by auto
       
   966   show ?thesis
       
   967     apply default
       
   968     using A fin by auto
       
   969 qed
       
   970 
   567 lemma (in sigma_finite_measure) disjoint_sigma_finite:
   971 lemma (in sigma_finite_measure) disjoint_sigma_finite:
   568   "\<exists>A::nat\<Rightarrow>'a set. range A \<subseteq> sets M \<and> (\<Union>i. A i) = space M \<and>
   972   "\<exists>A::nat\<Rightarrow>'a set. range A \<subseteq> sets M \<and> (\<Union>i. A i) = space M \<and>
   569     (\<forall>i. \<mu> (A i) \<noteq> \<omega>) \<and> disjoint_family A"
   973     (\<forall>i. \<mu> (A i) \<noteq> \<omega>) \<and> disjoint_family A"
   570 proof -
   974 proof -
   571   obtain A :: "nat \<Rightarrow> 'a set" where
   975   obtain A :: "nat \<Rightarrow> 'a set" where
   581       using measure[of i] by auto }
   985       using measure[of i] by auto }
   582   with disjoint_family_disjointed UN_disjointed_eq[of A] space range'
   986   with disjoint_family_disjointed UN_disjointed_eq[of A] space range'
   583   show ?thesis by (auto intro!: exI[of _ "disjointed A"])
   987   show ?thesis by (auto intro!: exI[of _ "disjointed A"])
   584 qed
   988 qed
   585 
   989 
       
   990 lemma (in sigma_finite_measure) sigma_finite_up:
       
   991   "\<exists>F. range F \<subseteq> sets M \<and> F \<up> space M \<and> (\<forall>i. \<mu> (F i) \<noteq> \<omega>)"
       
   992 proof -
       
   993   obtain F :: "nat \<Rightarrow> 'a set" where
       
   994     F: "range F \<subseteq> sets M" "(\<Union>i. F i) = space M" "\<And>i. \<mu> (F i) \<noteq> \<omega>"
       
   995     using sigma_finite by auto
       
   996   then show ?thesis unfolding isoton_def
       
   997   proof (intro exI[of _ "\<lambda>n. \<Union>i\<le>n. F i"] conjI allI)
       
   998     from F have "\<And>x. x \<in> space M \<Longrightarrow> \<exists>i. x \<in> F i" by auto
       
   999     then show "(\<Union>n. \<Union> i\<le>n. F i) = space M"
       
  1000       using F by fastsimp
       
  1001   next
       
  1002     fix n
       
  1003     have "\<mu> (\<Union> i\<le>n. F i) \<le> (\<Sum>i\<le>n. \<mu> (F i))" using F
       
  1004       by (auto intro!: measure_finitely_subadditive)
       
  1005     also have "\<dots> < \<omega>"
       
  1006       using F by (auto simp: setsum_\<omega>)
       
  1007     finally show "\<mu> (\<Union> i\<le>n. F i) \<noteq> \<omega>" by simp
       
  1008   qed force+
       
  1009 qed
       
  1010 
       
  1011 lemma (in sigma_finite_measure) sigma_finite_measure_isomorphic:
       
  1012   assumes f: "bij_betw f S (space M)"
       
  1013   shows "sigma_finite_measure (vimage_algebra S f) (\<lambda>A. \<mu> (f ` A))"
       
  1014 proof -
       
  1015   interpret M: measure_space "vimage_algebra S f" "\<lambda>A. \<mu> (f ` A)"
       
  1016     using f by (rule measure_space_isomorphic)
       
  1017   show ?thesis
       
  1018   proof default
       
  1019     from sigma_finite guess A::"nat \<Rightarrow> 'a set" .. note A = this
       
  1020     show "\<exists>A::nat\<Rightarrow>'b set. range A \<subseteq> sets (vimage_algebra S f) \<and> (\<Union>i. A i) = space (vimage_algebra S f) \<and> (\<forall>i. \<mu> (f ` A i) \<noteq> \<omega>)"
       
  1021     proof (intro exI conjI)
       
  1022       show "(\<Union>i::nat. f -` A i \<inter> S) = space (vimage_algebra S f)"
       
  1023         using A f[THEN bij_betw_imp_funcset] by (auto simp: vimage_UN[symmetric])
       
  1024       show "range (\<lambda>i. f -` A i \<inter> S) \<subseteq> sets (vimage_algebra S f)"
       
  1025         using A by (auto simp: vimage_algebra_def)
       
  1026       have "\<And>i. f ` (f -` A i \<inter> S) = A i"
       
  1027         using f A sets_into_space
       
  1028         by (intro image_vimage_inter_eq) (auto simp: bij_betw_def)
       
  1029       then show "\<forall>i. \<mu> (f ` (f -` A i \<inter> S)) \<noteq> \<omega>"  using A by simp
       
  1030     qed
       
  1031   qed
       
  1032 qed
       
  1033 
   586 section "Real measure values"
  1034 section "Real measure values"
   587 
  1035 
   588 lemma (in measure_space) real_measure_Union:
  1036 lemma (in measure_space) real_measure_Union:
   589   assumes finite: "\<mu> A \<noteq> \<omega>" "\<mu> B \<noteq> \<omega>"
  1037   assumes finite: "\<mu> A \<noteq> \<omega>" "\<mu> B \<noteq> \<omega>"
   590   and measurable: "A \<in> sets M" "B \<in> sets M" "A \<inter> B = {}"
  1038   and measurable: "A \<in> sets M" "B \<in> sets M" "A \<inter> B = {}"
   636   also have "\<dots> = real (\<mu> A) + real (\<mu> B)"
  1084   also have "\<dots> = real (\<mu> A) + real (\<mu> B)"
   637     using fin by (simp add: real_of_pinfreal_add)
  1085     using fin by (simp add: real_of_pinfreal_add)
   638   finally show ?thesis .
  1086   finally show ?thesis .
   639 qed
  1087 qed
   640 
  1088 
   641 lemma (in measure_space) real_measurable_countably_subadditive:
  1089 lemma (in measure_space) real_measure_countably_subadditive:
   642   assumes "range f \<subseteq> sets M" and "(\<Sum>\<^isub>\<infinity> i. \<mu> (f i)) \<noteq> \<omega>"
  1090   assumes "range f \<subseteq> sets M" and "(\<Sum>\<^isub>\<infinity> i. \<mu> (f i)) \<noteq> \<omega>"
   643   shows "real (\<mu> (\<Union>i. f i)) \<le> (\<Sum> i. real (\<mu> (f i)))"
  1091   shows "real (\<mu> (\<Union>i. f i)) \<le> (\<Sum> i. real (\<mu> (f i)))"
   644 proof -
  1092 proof -
   645   have "real (\<mu> (\<Union>i. f i)) \<le> real (\<Sum>\<^isub>\<infinity> i. \<mu> (f i))"
  1093   have "real (\<mu> (\<Union>i. f i)) \<le> real (\<Sum>\<^isub>\<infinity> i. \<mu> (f i))"
   646     using assms by (auto intro!: real_of_pinfreal_mono measurable_countably_subadditive)
  1094     using assms by (auto intro!: real_of_pinfreal_mono measure_countably_subadditive)
   647   also have "\<dots> = (\<Sum> i. real (\<mu> (f i)))"
  1095   also have "\<dots> = (\<Sum> i. real (\<mu> (f i)))"
   648     using assms by (auto intro!: sums_unique psuminf_imp_suminf)
  1096     using assms by (auto intro!: sums_unique psuminf_imp_suminf)
   649   finally show ?thesis .
  1097   finally show ?thesis .
   650 qed
  1098 qed
   651 
  1099 
   723   show "measure_space ?r \<mu>" using restricted_measure_space[OF assms] .
  1171   show "measure_space ?r \<mu>" using restricted_measure_space[OF assms] .
   724 next
  1172 next
   725   show "\<mu> (space ?r) \<noteq> \<omega>" using finite_measure[OF `S \<in> sets M`] by auto
  1173   show "\<mu> (space ?r) \<noteq> \<omega>" using finite_measure[OF `S \<in> sets M`] by auto
   726 qed
  1174 qed
   727 
  1175 
       
  1176 lemma (in measure_space) restricted_to_finite_measure:
       
  1177   assumes "S \<in> sets M" "\<mu> S \<noteq> \<omega>"
       
  1178   shows "finite_measure (restricted_space S) \<mu>"
       
  1179 proof -
       
  1180   have "measure_space (restricted_space S) \<mu>"
       
  1181     using `S \<in> sets M` by (rule restricted_measure_space)
       
  1182   then show ?thesis
       
  1183     unfolding finite_measure_def finite_measure_axioms_def
       
  1184     using assms by auto
       
  1185 qed
       
  1186 
   728 lemma (in finite_measure) real_finite_measure_Diff:
  1187 lemma (in finite_measure) real_finite_measure_Diff:
   729   assumes "A \<in> sets M" "B \<in> sets M" "B \<subseteq> A"
  1188   assumes "A \<in> sets M" "B \<in> sets M" "B \<subseteq> A"
   730   shows "real (\<mu> (A - B)) = real (\<mu> A) - real (\<mu> B)"
  1189   shows "real (\<mu> (A - B)) = real (\<mu> A) - real (\<mu> B)"
   731   using finite_measure[OF `A \<in> sets M`] by (rule real_measure_Diff[OF _ assms])
  1190   using finite_measure[OF `A \<in> sets M`] by (rule real_measure_Diff[OF _ assms])
   732 
  1191 
   759 lemma (in finite_measure) real_finite_measure_subadditive:
  1218 lemma (in finite_measure) real_finite_measure_subadditive:
   760   assumes measurable: "A \<in> sets M" "B \<in> sets M"
  1219   assumes measurable: "A \<in> sets M" "B \<in> sets M"
   761   shows "real (\<mu> (A \<union> B)) \<le> real (\<mu> A) + real (\<mu> B)"
  1220   shows "real (\<mu> (A \<union> B)) \<le> real (\<mu> A) + real (\<mu> B)"
   762   using measurable measurable[THEN finite_measure] by (rule real_measure_subadditive)
  1221   using measurable measurable[THEN finite_measure] by (rule real_measure_subadditive)
   763 
  1222 
   764 lemma (in finite_measure) real_finite_measurable_countably_subadditive:
  1223 lemma (in finite_measure) real_finite_measure_countably_subadditive:
   765   assumes "range f \<subseteq> sets M" and "summable (\<lambda>i. real (\<mu> (f i)))"
  1224   assumes "range f \<subseteq> sets M" and "summable (\<lambda>i. real (\<mu> (f i)))"
   766   shows "real (\<mu> (\<Union>i. f i)) \<le> (\<Sum> i. real (\<mu> (f i)))"
  1225   shows "real (\<mu> (\<Union>i. f i)) \<le> (\<Sum> i. real (\<mu> (f i)))"
   767 proof (rule real_measurable_countably_subadditive[OF assms(1)])
  1226 proof (rule real_measure_countably_subadditive[OF assms(1)])
   768   have *: "\<And>i. f i \<in> sets M" using assms by auto
  1227   have *: "\<And>i. f i \<in> sets M" using assms by auto
   769   have "(\<lambda>i. real (\<mu> (f i))) sums (\<Sum>i. real (\<mu> (f i)))"
  1228   have "(\<lambda>i. real (\<mu> (f i))) sums (\<Sum>i. real (\<mu> (f i)))"
   770     using assms(2) by (rule summable_sums)
  1229     using assms(2) by (rule summable_sums)
   771   from suminf_imp_psuminf[OF this]
  1230   from suminf_imp_psuminf[OF this]
   772   have "(\<Sum>\<^isub>\<infinity>i. \<mu> (f i)) = Real (\<Sum>i. real (\<mu> (f i)))"
  1231   have "(\<Sum>\<^isub>\<infinity>i. \<mu> (f i)) = Real (\<Sum>i. real (\<mu> (f i)))"
   815 
  1274 
   816 definition "measure_preserving A \<mu> B \<nu> =
  1275 definition "measure_preserving A \<mu> B \<nu> =
   817     {f \<in> measurable A B. (\<forall>y \<in> sets B. \<mu> (f -` y \<inter> space A) = \<nu> y)}"
  1276     {f \<in> measurable A B. (\<forall>y \<in> sets B. \<mu> (f -` y \<inter> space A) = \<nu> y)}"
   818 
  1277 
   819 lemma (in finite_measure) measure_preserving_lift:
  1278 lemma (in finite_measure) measure_preserving_lift:
   820   fixes f :: "'a \<Rightarrow> 'a2" and A :: "('a2, 'b2) algebra_scheme"
  1279   fixes f :: "'a \<Rightarrow> 'a2" and A :: "'a2 algebra"
   821   assumes "algebra A"
  1280   assumes "algebra A"
   822   assumes "finite_measure (sigma (space A) (sets A)) \<nu>" (is "finite_measure ?sA _")
  1281   assumes "finite_measure (sigma A) \<nu>" (is "finite_measure ?sA _")
   823   assumes fmp: "f \<in> measure_preserving M \<mu> A \<nu>"
  1282   assumes fmp: "f \<in> measure_preserving M \<mu> A \<nu>"
   824   shows "f \<in> measure_preserving M \<mu> (sigma (space A) (sets A)) \<nu>"
  1283   shows "f \<in> measure_preserving M \<mu> (sigma A) \<nu>"
   825 proof -
  1284 proof -
   826   interpret sA: finite_measure ?sA \<nu> by fact
  1285   interpret sA: finite_measure ?sA \<nu> by fact
   827   interpret A: algebra A by fact
  1286   interpret A: algebra A by fact
   828   show ?thesis using fmp
  1287   show ?thesis using fmp
   829     proof (clarsimp simp add: measure_preserving_def)
  1288     proof (clarsimp simp add: measure_preserving_def)
   914     qed
  1373     qed
   915 qed
  1374 qed
   916 
  1375 
   917 section "Finite spaces"
  1376 section "Finite spaces"
   918 
  1377 
   919 locale finite_measure_space = measure_space +
  1378 locale finite_measure_space = measure_space + finite_sigma_algebra +
   920   assumes finite_space: "finite (space M)"
  1379   assumes finite_single_measure[simp]: "\<And>x. x \<in> space M \<Longrightarrow> \<mu> {x} \<noteq> \<omega>"
   921   and sets_eq_Pow: "sets M = Pow (space M)"
       
   922   and finite_single_measure: "\<And>x. x \<in> space M \<Longrightarrow> \<mu> {x} \<noteq> \<omega>"
       
   923 
       
   924 lemma (in finite_measure_space) sets_image_space_eq_Pow:
       
   925   "sets (image_space X) = Pow (space (image_space X))"
       
   926 proof safe
       
   927   fix x S assume "S \<in> sets (image_space X)" "x \<in> S"
       
   928   then show "x \<in> space (image_space X)"
       
   929     using sets_into_space by (auto intro!: imageI simp: image_space_def)
       
   930 next
       
   931   fix S assume "S \<subseteq> space (image_space X)"
       
   932   then obtain S' where "S = X`S'" "S'\<in>sets M"
       
   933     by (auto simp: subset_image_iff sets_eq_Pow image_space_def)
       
   934   then show "S \<in> sets (image_space X)"
       
   935     by (auto simp: image_space_def)
       
   936 qed
       
   937 
  1380 
   938 lemma (in finite_measure_space) sum_over_space: "(\<Sum>x\<in>space M. \<mu> {x}) = \<mu> (space M)"
  1381 lemma (in finite_measure_space) sum_over_space: "(\<Sum>x\<in>space M. \<mu> {x}) = \<mu> (space M)"
   939   using measure_finitely_additive''[of "space M" "\<lambda>i. {i}"]
  1382   using measure_finitely_additive''[of "space M" "\<lambda>i. {i}"]
   940   by (simp add: sets_eq_Pow disjoint_family_on_def finite_space)
  1383   by (simp add: sets_eq_Pow disjoint_family_on_def finite_space)
   941 
  1384 
   943   assumes "finite (space M)" "sets M = Pow(space M)" and space: "\<mu> (space M) \<noteq> \<omega>"
  1386   assumes "finite (space M)" "sets M = Pow(space M)" and space: "\<mu> (space M) \<noteq> \<omega>"
   944     and add: "\<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"
  1387     and add: "\<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"
   945     and "\<mu> {} = 0"
  1388     and "\<mu> {} = 0"
   946   shows "finite_measure_space M \<mu>"
  1389   shows "finite_measure_space M \<mu>"
   947     unfolding finite_measure_space_def finite_measure_space_axioms_def
  1390     unfolding finite_measure_space_def finite_measure_space_axioms_def
   948 proof (safe del: notI)
  1391 proof (intro allI impI conjI)
   949   show "measure_space M \<mu>"
  1392   show "measure_space M \<mu>"
   950   proof (rule sigma_algebra.finite_additivity_sufficient)
  1393   proof (rule sigma_algebra.finite_additivity_sufficient)
       
  1394     have *: "\<lparr>space = space M, sets = sets M\<rparr> = M" by auto
   951     show "sigma_algebra M"
  1395     show "sigma_algebra M"
   952       apply (rule sigma_algebra_cong)
  1396       using sigma_algebra_Pow[of "space M" "more M"] assms(2)[symmetric] by (simp add: *)
   953       apply (rule sigma_algebra_Pow[of "space M"])
       
   954       using assms by simp_all
       
   955     show "finite (space M)" by fact
  1397     show "finite (space M)" by fact
   956     show "positive \<mu>" unfolding positive_def by fact
  1398     show "positive \<mu>" unfolding positive_def by fact
   957     show "additive M \<mu>" unfolding additive_def using assms by simp
  1399     show "additive M \<mu>" unfolding additive_def using assms by simp
   958   qed
  1400   qed
   959   show "finite (space M)" by fact
  1401   then interpret measure_space M \<mu> .
   960   { fix A x assume "A \<in> sets M" "x \<in> A" then show "x \<in> space M"
  1402   show "finite_sigma_algebra M"
   961       using assms by auto }
  1403   proof
   962   { fix A assume "A \<subseteq> space M" then show "A \<in> sets M"
  1404     show "finite (space M)" by fact
   963       using assms by auto }
  1405     show "sets M = Pow (space M)" using assms by auto
       
  1406   qed
   964   { fix x assume *: "x \<in> space M"
  1407   { fix x assume *: "x \<in> space M"
   965     with add[of "{x}" "space M - {x}"] space
  1408     with add[of "{x}" "space M - {x}"] space
   966     show "\<mu> {x} \<noteq> \<omega>" by (auto simp: insert_absorb[OF *] Diff_subset) }
  1409     show "\<mu> {x} \<noteq> \<omega>" by (auto simp: insert_absorb[OF *] Diff_subset) }
   967 qed
  1410 qed
   968 
  1411