src/HOL/Probability/Binary_Product_Measure.thy
author hoelzl
Fri Feb 19 13:40:50 2016 +0100 (2016-02-19)
changeset 62378 85ed00c1fe7c
parent 62083 7582b39f51ed
child 62390 842917225d56
permissions -rw-r--r--
generalize more theorems to support enat and ennreal
hoelzl@42146
     1
(*  Title:      HOL/Probability/Binary_Product_Measure.thy
hoelzl@42067
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42067
     3
*)
hoelzl@42067
     4
wenzelm@61808
     5
section \<open>Binary product measures\<close>
hoelzl@42067
     6
hoelzl@42146
     7
theory Binary_Product_Measure
hoelzl@56993
     8
imports Nonnegative_Lebesgue_Integration
hoelzl@35833
     9
begin
hoelzl@35833
    10
hoelzl@50104
    11
lemma Pair_vimage_times[simp]: "Pair x -` (A \<times> B) = (if x \<in> A then B else {})"
hoelzl@40859
    12
  by auto
hoelzl@40859
    13
hoelzl@50104
    14
lemma rev_Pair_vimage_times[simp]: "(\<lambda>x. (x, y)) -` (A \<times> B) = (if y \<in> B then A else {})"
hoelzl@40859
    15
  by auto
hoelzl@40859
    16
hoelzl@56994
    17
subsection "Binary products"
hoelzl@40859
    18
wenzelm@53015
    19
definition pair_measure (infixr "\<Otimes>\<^sub>M" 80) where
wenzelm@53015
    20
  "A \<Otimes>\<^sub>M B = measure_of (space A \<times> space B)
hoelzl@47694
    21
      {a \<times> b | a b. a \<in> sets A \<and> b \<in> sets B}
wenzelm@53015
    22
      (\<lambda>X. \<integral>\<^sup>+x. (\<integral>\<^sup>+y. indicator X (x,y) \<partial>B) \<partial>A)"
hoelzl@40859
    23
hoelzl@49789
    24
lemma pair_measure_closed: "{a \<times> b | a b. a \<in> sets A \<and> b \<in> sets B} \<subseteq> Pow (space A \<times> space B)"
immler@50244
    25
  using sets.space_closed[of A] sets.space_closed[of B] by auto
hoelzl@49789
    26
hoelzl@41689
    27
lemma space_pair_measure:
wenzelm@53015
    28
  "space (A \<Otimes>\<^sub>M B) = space A \<times> space B"
hoelzl@49789
    29
  unfolding pair_measure_def using pair_measure_closed[of A B]
hoelzl@49789
    30
  by (rule space_measure_of)
hoelzl@47694
    31
hoelzl@59000
    32
lemma SIGMA_Collect_eq: "(SIGMA x:space M. {y\<in>space N. P x y}) = {x\<in>space (M \<Otimes>\<^sub>M N). P (fst x) (snd x)}"
hoelzl@59000
    33
  by (auto simp: space_pair_measure)
hoelzl@59000
    34
hoelzl@47694
    35
lemma sets_pair_measure:
wenzelm@53015
    36
  "sets (A \<Otimes>\<^sub>M B) = sigma_sets (space A \<times> space B) {a \<times> b | a b. a \<in> sets A \<and> b \<in> sets B}"
hoelzl@49789
    37
  unfolding pair_measure_def using pair_measure_closed[of A B]
hoelzl@49789
    38
  by (rule sets_measure_of)
hoelzl@41095
    39
hoelzl@58606
    40
lemma sets_pair_in_sets:
hoelzl@58606
    41
  assumes N: "space A \<times> space B = space N"
hoelzl@58606
    42
  assumes "\<And>a b. a \<in> sets A \<Longrightarrow> b \<in> sets B \<Longrightarrow> a \<times> b \<in> sets N"
hoelzl@58606
    43
  shows "sets (A \<Otimes>\<^sub>M B) \<subseteq> sets N"
hoelzl@58606
    44
  using assms by (auto intro!: sets.sigma_sets_subset simp: sets_pair_measure N)
hoelzl@58606
    45
hoelzl@59048
    46
lemma sets_pair_measure_cong[measurable_cong, cong]:
wenzelm@53015
    47
  "sets M1 = sets M1' \<Longrightarrow> sets M2 = sets M2' \<Longrightarrow> sets (M1 \<Otimes>\<^sub>M M2) = sets (M1' \<Otimes>\<^sub>M M2')"
hoelzl@49776
    48
  unfolding sets_pair_measure by (simp cong: sets_eq_imp_space_eq)
hoelzl@49776
    49
hoelzl@50003
    50
lemma pair_measureI[intro, simp, measurable]:
wenzelm@53015
    51
  "x \<in> sets A \<Longrightarrow> y \<in> sets B \<Longrightarrow> x \<times> y \<in> sets (A \<Otimes>\<^sub>M B)"
hoelzl@47694
    52
  by (auto simp: sets_pair_measure)
hoelzl@41095
    53
hoelzl@58606
    54
lemma sets_Pair: "{x} \<in> sets M1 \<Longrightarrow> {y} \<in> sets M2 \<Longrightarrow> {(x, y)} \<in> sets (M1 \<Otimes>\<^sub>M M2)"
hoelzl@58606
    55
  using pair_measureI[of "{x}" M1 "{y}" M2] by simp
hoelzl@58606
    56
hoelzl@47694
    57
lemma measurable_pair_measureI:
hoelzl@47694
    58
  assumes 1: "f \<in> space M \<rightarrow> space M1 \<times> space M2"
hoelzl@47694
    59
  assumes 2: "\<And>A B. A \<in> sets M1 \<Longrightarrow> B \<in> sets M2 \<Longrightarrow> f -` (A \<times> B) \<inter> space M \<in> sets M"
wenzelm@53015
    60
  shows "f \<in> measurable M (M1 \<Otimes>\<^sub>M M2)"
hoelzl@47694
    61
  unfolding pair_measure_def using 1 2
immler@50244
    62
  by (intro measurable_measure_of) (auto dest: sets.sets_into_space)
hoelzl@41689
    63
hoelzl@50003
    64
lemma measurable_split_replace[measurable (raw)]:
haftmann@61424
    65
  "(\<lambda>x. f x (fst (g x)) (snd (g x))) \<in> measurable M N \<Longrightarrow> (\<lambda>x. case_prod (f x) (g x)) \<in> measurable M N"
hoelzl@50003
    66
  unfolding split_beta' .
hoelzl@50003
    67
hoelzl@50003
    68
lemma measurable_Pair[measurable (raw)]:
hoelzl@49776
    69
  assumes f: "f \<in> measurable M M1" and g: "g \<in> measurable M M2"
wenzelm@53015
    70
  shows "(\<lambda>x. (f x, g x)) \<in> measurable M (M1 \<Otimes>\<^sub>M M2)"
hoelzl@49776
    71
proof (rule measurable_pair_measureI)
hoelzl@49776
    72
  show "(\<lambda>x. (f x, g x)) \<in> space M \<rightarrow> space M1 \<times> space M2"
hoelzl@49776
    73
    using f g by (auto simp: measurable_def)
hoelzl@49776
    74
  fix A B assume *: "A \<in> sets M1" "B \<in> sets M2"
hoelzl@49776
    75
  have "(\<lambda>x. (f x, g x)) -` (A \<times> B) \<inter> space M = (f -` A \<inter> space M) \<inter> (g -` B \<inter> space M)"
hoelzl@49776
    76
    by auto
hoelzl@49776
    77
  also have "\<dots> \<in> sets M"
immler@50244
    78
    by (rule sets.Int) (auto intro!: measurable_sets * f g)
hoelzl@49776
    79
  finally show "(\<lambda>x. (f x, g x)) -` (A \<times> B) \<inter> space M \<in> sets M" .
hoelzl@49776
    80
qed
hoelzl@49776
    81
wenzelm@53015
    82
lemma measurable_fst[intro!, simp, measurable]: "fst \<in> measurable (M1 \<Otimes>\<^sub>M M2) M1"
immler@50244
    83
  by (auto simp: fst_vimage_eq_Times space_pair_measure sets.sets_into_space times_Int_times
immler@50244
    84
    measurable_def)
hoelzl@40859
    85
wenzelm@53015
    86
lemma measurable_snd[intro!, simp, measurable]: "snd \<in> measurable (M1 \<Otimes>\<^sub>M M2) M2"
immler@50244
    87
  by (auto simp: snd_vimage_eq_Times space_pair_measure sets.sets_into_space times_Int_times
immler@50244
    88
    measurable_def)
hoelzl@47694
    89
hoelzl@59353
    90
lemma measurable_Pair_compose_split[measurable_dest]:
haftmann@61424
    91
  assumes f: "case_prod f \<in> measurable (M1 \<Otimes>\<^sub>M M2) N"
hoelzl@59353
    92
  assumes g: "g \<in> measurable M M1" and h: "h \<in> measurable M M2"
hoelzl@59353
    93
  shows "(\<lambda>x. f (g x) (h x)) \<in> measurable M N"
hoelzl@59353
    94
  using measurable_compose[OF measurable_Pair f, OF g h] by simp
hoelzl@59353
    95
hoelzl@59353
    96
lemma measurable_Pair1_compose[measurable_dest]:
hoelzl@59353
    97
  assumes f: "(\<lambda>x. (f x, g x)) \<in> measurable M (M1 \<Otimes>\<^sub>M M2)"
hoelzl@59353
    98
  assumes [measurable]: "h \<in> measurable N M"
hoelzl@59353
    99
  shows "(\<lambda>x. f (h x)) \<in> measurable N M1"
hoelzl@59353
   100
  using measurable_compose[OF f measurable_fst] by simp
hoelzl@59353
   101
hoelzl@59353
   102
lemma measurable_Pair2_compose[measurable_dest]:
hoelzl@59353
   103
  assumes f: "(\<lambda>x. (f x, g x)) \<in> measurable M (M1 \<Otimes>\<^sub>M M2)"
hoelzl@59353
   104
  assumes [measurable]: "h \<in> measurable N M"
hoelzl@59353
   105
  shows "(\<lambda>x. g (h x)) \<in> measurable N M2"
hoelzl@59353
   106
  using measurable_compose[OF f measurable_snd] by simp
hoelzl@59353
   107
hoelzl@59353
   108
lemma measurable_pair:
hoelzl@59353
   109
  assumes "(fst \<circ> f) \<in> measurable M M1" "(snd \<circ> f) \<in> measurable M M2"
hoelzl@59353
   110
  shows "f \<in> measurable M (M1 \<Otimes>\<^sub>M M2)"
hoelzl@59353
   111
  using measurable_Pair[OF assms] by simp
hoelzl@59353
   112
hoelzl@50003
   113
lemma 
wenzelm@53015
   114
  assumes f[measurable]: "f \<in> measurable M (N \<Otimes>\<^sub>M P)" 
hoelzl@50003
   115
  shows measurable_fst': "(\<lambda>x. fst (f x)) \<in> measurable M N"
hoelzl@50003
   116
    and measurable_snd': "(\<lambda>x. snd (f x)) \<in> measurable M P"
hoelzl@50003
   117
  by simp_all
hoelzl@40859
   118
hoelzl@50003
   119
lemma
hoelzl@50003
   120
  assumes f[measurable]: "f \<in> measurable M N"
wenzelm@53015
   121
  shows measurable_fst'': "(\<lambda>x. f (fst x)) \<in> measurable (M \<Otimes>\<^sub>M P) N"
wenzelm@53015
   122
    and measurable_snd'': "(\<lambda>x. f (snd x)) \<in> measurable (P \<Otimes>\<^sub>M M) N"
hoelzl@50003
   123
  by simp_all
hoelzl@47694
   124
hoelzl@58606
   125
lemma sets_pair_eq_sets_fst_snd:
hoelzl@58606
   126
  "sets (A \<Otimes>\<^sub>M B) = sets (Sup_sigma {vimage_algebra (space A \<times> space B) fst A, vimage_algebra (space A \<times> space B) snd B})"
hoelzl@58606
   127
    (is "?P = sets (Sup_sigma {?fst, ?snd})")
hoelzl@58606
   128
proof -
hoelzl@58606
   129
  { fix a b assume ab: "a \<in> sets A" "b \<in> sets B"
hoelzl@58606
   130
    then have "a \<times> b = (fst -` a \<inter> (space A \<times> space B)) \<inter> (snd -` b \<inter> (space A \<times> space B))"
hoelzl@58606
   131
      by (auto dest: sets.sets_into_space)
hoelzl@58606
   132
    also have "\<dots> \<in> sets (Sup_sigma {?fst, ?snd})"
hoelzl@58606
   133
      using ab by (auto intro: in_Sup_sigma in_vimage_algebra)
hoelzl@58606
   134
    finally have "a \<times> b \<in> sets (Sup_sigma {?fst, ?snd})" . }
hoelzl@58606
   135
  moreover have "sets ?fst \<subseteq> sets (A \<Otimes>\<^sub>M B)"
hoelzl@58606
   136
    by (rule sets_image_in_sets) (auto simp: space_pair_measure[symmetric])
hoelzl@58606
   137
  moreover have "sets ?snd \<subseteq> sets (A \<Otimes>\<^sub>M B)"  
hoelzl@58606
   138
    by (rule sets_image_in_sets) (auto simp: space_pair_measure)
hoelzl@58606
   139
  ultimately show ?thesis
hoelzl@58606
   140
    by (intro antisym[of "sets A" for A] sets_Sup_in_sets sets_pair_in_sets )
hoelzl@58606
   141
       (auto simp add: space_Sup_sigma space_pair_measure)
hoelzl@58606
   142
qed
hoelzl@58606
   143
hoelzl@47694
   144
lemma measurable_pair_iff:
wenzelm@53015
   145
  "f \<in> measurable M (M1 \<Otimes>\<^sub>M M2) \<longleftrightarrow> (fst \<circ> f) \<in> measurable M M1 \<and> (snd \<circ> f) \<in> measurable M M2"
hoelzl@50003
   146
  by (auto intro: measurable_pair[of f M M1 M2]) 
hoelzl@40859
   147
hoelzl@49776
   148
lemma measurable_split_conv:
hoelzl@49776
   149
  "(\<lambda>(x, y). f x y) \<in> measurable A B \<longleftrightarrow> (\<lambda>x. f (fst x) (snd x)) \<in> measurable A B"
hoelzl@49776
   150
  by (intro arg_cong2[where f="op \<in>"]) auto
hoelzl@40859
   151
wenzelm@53015
   152
lemma measurable_pair_swap': "(\<lambda>(x,y). (y, x)) \<in> measurable (M1 \<Otimes>\<^sub>M M2) (M2 \<Otimes>\<^sub>M M1)"
hoelzl@49776
   153
  by (auto intro!: measurable_Pair simp: measurable_split_conv)
hoelzl@47694
   154
hoelzl@47694
   155
lemma measurable_pair_swap:
wenzelm@53015
   156
  assumes f: "f \<in> measurable (M1 \<Otimes>\<^sub>M M2) M" shows "(\<lambda>(x,y). f (y, x)) \<in> measurable (M2 \<Otimes>\<^sub>M M1) M"
hoelzl@49776
   157
  using measurable_comp[OF measurable_Pair f] by (auto simp: measurable_split_conv comp_def)
hoelzl@40859
   158
hoelzl@47694
   159
lemma measurable_pair_swap_iff:
wenzelm@53015
   160
  "f \<in> measurable (M2 \<Otimes>\<^sub>M M1) M \<longleftrightarrow> (\<lambda>(x,y). f (y,x)) \<in> measurable (M1 \<Otimes>\<^sub>M M2) M"
hoelzl@50003
   161
  by (auto dest: measurable_pair_swap)
hoelzl@49776
   162
wenzelm@53015
   163
lemma measurable_Pair1': "x \<in> space M1 \<Longrightarrow> Pair x \<in> measurable M2 (M1 \<Otimes>\<^sub>M M2)"
hoelzl@50003
   164
  by simp
hoelzl@40859
   165
hoelzl@50003
   166
lemma sets_Pair1[measurable (raw)]:
wenzelm@53015
   167
  assumes A: "A \<in> sets (M1 \<Otimes>\<^sub>M M2)" shows "Pair x -` A \<in> sets M2"
hoelzl@40859
   168
proof -
hoelzl@47694
   169
  have "Pair x -` A = (if x \<in> space M1 then Pair x -` A \<inter> space M2 else {})"
immler@50244
   170
    using A[THEN sets.sets_into_space] by (auto simp: space_pair_measure)
hoelzl@47694
   171
  also have "\<dots> \<in> sets M2"
hoelzl@47694
   172
    using A by (auto simp add: measurable_Pair1' intro!: measurable_sets split: split_if_asm)
hoelzl@47694
   173
  finally show ?thesis .
hoelzl@40859
   174
qed
hoelzl@40859
   175
wenzelm@53015
   176
lemma measurable_Pair2': "y \<in> space M2 \<Longrightarrow> (\<lambda>x. (x, y)) \<in> measurable M1 (M1 \<Otimes>\<^sub>M M2)"
hoelzl@49776
   177
  by (auto intro!: measurable_Pair)
hoelzl@40859
   178
wenzelm@53015
   179
lemma sets_Pair2: assumes A: "A \<in> sets (M1 \<Otimes>\<^sub>M M2)" shows "(\<lambda>x. (x, y)) -` A \<in> sets M1"
hoelzl@47694
   180
proof -
hoelzl@47694
   181
  have "(\<lambda>x. (x, y)) -` A = (if y \<in> space M2 then (\<lambda>x. (x, y)) -` A \<inter> space M1 else {})"
immler@50244
   182
    using A[THEN sets.sets_into_space] by (auto simp: space_pair_measure)
hoelzl@47694
   183
  also have "\<dots> \<in> sets M1"
hoelzl@47694
   184
    using A by (auto simp add: measurable_Pair2' intro!: measurable_sets split: split_if_asm)
hoelzl@47694
   185
  finally show ?thesis .
hoelzl@40859
   186
qed
hoelzl@40859
   187
hoelzl@47694
   188
lemma measurable_Pair2:
wenzelm@53015
   189
  assumes f: "f \<in> measurable (M1 \<Otimes>\<^sub>M M2) M" and x: "x \<in> space M1"
hoelzl@47694
   190
  shows "(\<lambda>y. f (x, y)) \<in> measurable M2 M"
hoelzl@47694
   191
  using measurable_comp[OF measurable_Pair1' f, OF x]
hoelzl@47694
   192
  by (simp add: comp_def)
hoelzl@47694
   193
  
hoelzl@47694
   194
lemma measurable_Pair1:
wenzelm@53015
   195
  assumes f: "f \<in> measurable (M1 \<Otimes>\<^sub>M M2) M" and y: "y \<in> space M2"
hoelzl@40859
   196
  shows "(\<lambda>x. f (x, y)) \<in> measurable M1 M"
hoelzl@47694
   197
  using measurable_comp[OF measurable_Pair2' f, OF y]
hoelzl@47694
   198
  by (simp add: comp_def)
hoelzl@40859
   199
hoelzl@47694
   200
lemma Int_stable_pair_measure_generator: "Int_stable {a \<times> b | a b. a \<in> sets A \<and> b \<in> sets B}"
hoelzl@40859
   201
  unfolding Int_stable_def
hoelzl@47694
   202
  by safe (auto simp add: times_Int_times)
hoelzl@40859
   203
hoelzl@49776
   204
lemma (in finite_measure) finite_measure_cut_measurable:
wenzelm@53015
   205
  assumes [measurable]: "Q \<in> sets (N \<Otimes>\<^sub>M M)"
hoelzl@49776
   206
  shows "(\<lambda>x. emeasure M (Pair x -` Q)) \<in> borel_measurable N"
hoelzl@40859
   207
    (is "?s Q \<in> _")
hoelzl@49789
   208
  using Int_stable_pair_measure_generator pair_measure_closed assms
hoelzl@49789
   209
  unfolding sets_pair_measure
hoelzl@49789
   210
proof (induct rule: sigma_sets_induct_disjoint)
hoelzl@49789
   211
  case (compl A)
immler@50244
   212
  with sets.sets_into_space have "\<And>x. emeasure M (Pair x -` ((space N \<times> space M) - A)) =
hoelzl@49789
   213
      (if x \<in> space N then emeasure M (space M) - ?s A x else 0)"
hoelzl@49789
   214
    unfolding sets_pair_measure[symmetric]
hoelzl@49789
   215
    by (auto intro!: emeasure_compl simp: vimage_Diff sets_Pair1)
immler@50244
   216
  with compl sets.top show ?case
hoelzl@49789
   217
    by (auto intro!: measurable_If simp: space_pair_measure)
hoelzl@49789
   218
next
hoelzl@49789
   219
  case (union F)
wenzelm@53374
   220
  then have "\<And>x. emeasure M (Pair x -` (\<Union>i. F i)) = (\<Sum>i. ?s (F i) x)"
hoelzl@60727
   221
    by (simp add: suminf_emeasure disjoint_family_on_vimageI subset_eq vimage_UN sets_pair_measure[symmetric])
wenzelm@53374
   222
  with union show ?case
hoelzl@50003
   223
    unfolding sets_pair_measure[symmetric] by simp
hoelzl@49789
   224
qed (auto simp add: if_distrib Int_def[symmetric] intro!: measurable_If)
hoelzl@49776
   225
hoelzl@49776
   226
lemma (in sigma_finite_measure) measurable_emeasure_Pair:
wenzelm@53015
   227
  assumes Q: "Q \<in> sets (N \<Otimes>\<^sub>M M)" shows "(\<lambda>x. emeasure M (Pair x -` Q)) \<in> borel_measurable N" (is "?s Q \<in> _")
hoelzl@49776
   228
proof -
hoelzl@49776
   229
  from sigma_finite_disjoint guess F . note F = this
hoelzl@49776
   230
  then have F_sets: "\<And>i. F i \<in> sets M" by auto
hoelzl@49776
   231
  let ?C = "\<lambda>x i. F i \<inter> Pair x -` Q"
hoelzl@49776
   232
  { fix i
hoelzl@49776
   233
    have [simp]: "space N \<times> F i \<inter> space N \<times> space M = space N \<times> F i"
immler@50244
   234
      using F sets.sets_into_space by auto
hoelzl@49776
   235
    let ?R = "density M (indicator (F i))"
hoelzl@49776
   236
    have "finite_measure ?R"
hoelzl@49776
   237
      using F by (intro finite_measureI) (auto simp: emeasure_restricted subset_eq)
hoelzl@49776
   238
    then have "(\<lambda>x. emeasure ?R (Pair x -` (space N \<times> space ?R \<inter> Q))) \<in> borel_measurable N"
hoelzl@49776
   239
     by (rule finite_measure.finite_measure_cut_measurable) (auto intro: Q)
hoelzl@49776
   240
    moreover have "\<And>x. emeasure ?R (Pair x -` (space N \<times> space ?R \<inter> Q))
hoelzl@49776
   241
        = emeasure M (F i \<inter> Pair x -` (space N \<times> space ?R \<inter> Q))"
hoelzl@49776
   242
      using Q F_sets by (intro emeasure_restricted) (auto intro: sets_Pair1)
hoelzl@49776
   243
    moreover have "\<And>x. F i \<inter> Pair x -` (space N \<times> space ?R \<inter> Q) = ?C x i"
immler@50244
   244
      using sets.sets_into_space[OF Q] by (auto simp: space_pair_measure)
hoelzl@49776
   245
    ultimately have "(\<lambda>x. emeasure M (?C x i)) \<in> borel_measurable N"
hoelzl@49776
   246
      by simp }
hoelzl@49776
   247
  moreover
hoelzl@49776
   248
  { fix x
hoelzl@49776
   249
    have "(\<Sum>i. emeasure M (?C x i)) = emeasure M (\<Union>i. ?C x i)"
hoelzl@49776
   250
    proof (intro suminf_emeasure)
hoelzl@49776
   251
      show "range (?C x) \<subseteq> sets M"
wenzelm@61808
   252
        using F \<open>Q \<in> sets (N \<Otimes>\<^sub>M M)\<close> by (auto intro!: sets_Pair1)
hoelzl@49776
   253
      have "disjoint_family F" using F by auto
hoelzl@49776
   254
      show "disjoint_family (?C x)"
wenzelm@61808
   255
        by (rule disjoint_family_on_bisimulation[OF \<open>disjoint_family F\<close>]) auto
hoelzl@49776
   256
    qed
hoelzl@49776
   257
    also have "(\<Union>i. ?C x i) = Pair x -` Q"
wenzelm@61808
   258
      using F sets.sets_into_space[OF \<open>Q \<in> sets (N \<Otimes>\<^sub>M M)\<close>]
hoelzl@49776
   259
      by (auto simp: space_pair_measure)
hoelzl@49776
   260
    finally have "emeasure M (Pair x -` Q) = (\<Sum>i. emeasure M (?C x i))"
hoelzl@49776
   261
      by simp }
wenzelm@61808
   262
  ultimately show ?thesis using \<open>Q \<in> sets (N \<Otimes>\<^sub>M M)\<close> F_sets
hoelzl@49776
   263
    by auto
hoelzl@49776
   264
qed
hoelzl@49776
   265
hoelzl@50003
   266
lemma (in sigma_finite_measure) measurable_emeasure[measurable (raw)]:
hoelzl@50003
   267
  assumes space: "\<And>x. x \<in> space N \<Longrightarrow> A x \<subseteq> space M"
wenzelm@53015
   268
  assumes A: "{x\<in>space (N \<Otimes>\<^sub>M M). snd x \<in> A (fst x)} \<in> sets (N \<Otimes>\<^sub>M M)"
hoelzl@50003
   269
  shows "(\<lambda>x. emeasure M (A x)) \<in> borel_measurable N"
hoelzl@50003
   270
proof -
wenzelm@53015
   271
  from space have "\<And>x. x \<in> space N \<Longrightarrow> Pair x -` {x \<in> space (N \<Otimes>\<^sub>M M). snd x \<in> A (fst x)} = A x"
hoelzl@50003
   272
    by (auto simp: space_pair_measure)
hoelzl@50003
   273
  with measurable_emeasure_Pair[OF A] show ?thesis
hoelzl@50003
   274
    by (auto cong: measurable_cong)
hoelzl@50003
   275
qed
hoelzl@50003
   276
hoelzl@49776
   277
lemma (in sigma_finite_measure) emeasure_pair_measure:
wenzelm@53015
   278
  assumes "X \<in> sets (N \<Otimes>\<^sub>M M)"
wenzelm@53015
   279
  shows "emeasure (N \<Otimes>\<^sub>M M) X = (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. indicator X (x, y) \<partial>M \<partial>N)" (is "_ = ?\<mu> X")
hoelzl@49776
   280
proof (rule emeasure_measure_of[OF pair_measure_def])
wenzelm@53015
   281
  show "positive (sets (N \<Otimes>\<^sub>M M)) ?\<mu>"
hoelzl@56996
   282
    by (auto simp: positive_def nn_integral_nonneg)
hoelzl@49776
   283
  have eq[simp]: "\<And>A x y. indicator A (x, y) = indicator (Pair x -` A) y"
hoelzl@49776
   284
    by (auto simp: indicator_def)
wenzelm@53015
   285
  show "countably_additive (sets (N \<Otimes>\<^sub>M M)) ?\<mu>"
hoelzl@49776
   286
  proof (rule countably_additiveI)
wenzelm@53015
   287
    fix F :: "nat \<Rightarrow> ('b \<times> 'a) set" assume F: "range F \<subseteq> sets (N \<Otimes>\<^sub>M M)" "disjoint_family F"
hoelzl@59353
   288
    from F have *: "\<And>i. F i \<in> sets (N \<Otimes>\<^sub>M M)" by auto
hoelzl@49776
   289
    moreover have "\<And>x. disjoint_family (\<lambda>i. Pair x -` F i)"
hoelzl@49776
   290
      by (intro disjoint_family_on_bisimulation[OF F(2)]) auto
hoelzl@49776
   291
    moreover have "\<And>x. range (\<lambda>i. Pair x -` F i) \<subseteq> sets M"
hoelzl@49776
   292
      using F by (auto simp: sets_Pair1)
hoelzl@49776
   293
    ultimately show "(\<Sum>n. ?\<mu> (F n)) = ?\<mu> (\<Union>i. F i)"
hoelzl@59353
   294
      by (auto simp add: nn_integral_suminf[symmetric] vimage_UN suminf_emeasure emeasure_nonneg
hoelzl@56996
   295
               intro!: nn_integral_cong nn_integral_indicator[symmetric])
hoelzl@49776
   296
  qed
hoelzl@49776
   297
  show "{a \<times> b |a b. a \<in> sets N \<and> b \<in> sets M} \<subseteq> Pow (space N \<times> space M)"
immler@50244
   298
    using sets.space_closed[of N] sets.space_closed[of M] by auto
hoelzl@49776
   299
qed fact
hoelzl@49776
   300
hoelzl@49776
   301
lemma (in sigma_finite_measure) emeasure_pair_measure_alt:
wenzelm@53015
   302
  assumes X: "X \<in> sets (N \<Otimes>\<^sub>M M)"
wenzelm@53015
   303
  shows "emeasure (N  \<Otimes>\<^sub>M M) X = (\<integral>\<^sup>+x. emeasure M (Pair x -` X) \<partial>N)"
hoelzl@49776
   304
proof -
hoelzl@49776
   305
  have [simp]: "\<And>x y. indicator X (x, y) = indicator (Pair x -` X) y"
hoelzl@49776
   306
    by (auto simp: indicator_def)
hoelzl@49776
   307
  show ?thesis
hoelzl@56996
   308
    using X by (auto intro!: nn_integral_cong simp: emeasure_pair_measure sets_Pair1)
hoelzl@49776
   309
qed
hoelzl@49776
   310
hoelzl@49776
   311
lemma (in sigma_finite_measure) emeasure_pair_measure_Times:
hoelzl@49776
   312
  assumes A: "A \<in> sets N" and B: "B \<in> sets M"
wenzelm@53015
   313
  shows "emeasure (N \<Otimes>\<^sub>M M) (A \<times> B) = emeasure N A * emeasure M B"
hoelzl@49776
   314
proof -
wenzelm@53015
   315
  have "emeasure (N \<Otimes>\<^sub>M M) (A \<times> B) = (\<integral>\<^sup>+x. emeasure M B * indicator A x \<partial>N)"
hoelzl@56996
   316
    using A B by (auto intro!: nn_integral_cong simp: emeasure_pair_measure_alt)
hoelzl@49776
   317
  also have "\<dots> = emeasure M B * emeasure N A"
hoelzl@56996
   318
    using A by (simp add: emeasure_nonneg nn_integral_cmult_indicator)
hoelzl@49776
   319
  finally show ?thesis
hoelzl@49776
   320
    by (simp add: ac_simps)
hoelzl@40859
   321
qed
hoelzl@40859
   322
wenzelm@61808
   323
subsection \<open>Binary products of $\sigma$-finite emeasure spaces\<close>
hoelzl@40859
   324
ballarin@61565
   325
locale pair_sigma_finite = M1?: sigma_finite_measure M1 + M2?: sigma_finite_measure M2
hoelzl@47694
   326
  for M1 :: "'a measure" and M2 :: "'b measure"
hoelzl@40859
   327
hoelzl@47694
   328
lemma (in pair_sigma_finite) measurable_emeasure_Pair1:
wenzelm@53015
   329
  "Q \<in> sets (M1 \<Otimes>\<^sub>M M2) \<Longrightarrow> (\<lambda>x. emeasure M2 (Pair x -` Q)) \<in> borel_measurable M1"
hoelzl@49776
   330
  using M2.measurable_emeasure_Pair .
hoelzl@40859
   331
hoelzl@47694
   332
lemma (in pair_sigma_finite) measurable_emeasure_Pair2:
wenzelm@53015
   333
  assumes Q: "Q \<in> sets (M1 \<Otimes>\<^sub>M M2)" shows "(\<lambda>y. emeasure M1 ((\<lambda>x. (x, y)) -` Q)) \<in> borel_measurable M2"
hoelzl@40859
   334
proof -
wenzelm@53015
   335
  have "(\<lambda>(x, y). (y, x)) -` Q \<inter> space (M2 \<Otimes>\<^sub>M M1) \<in> sets (M2 \<Otimes>\<^sub>M M1)"
hoelzl@47694
   336
    using Q measurable_pair_swap' by (auto intro: measurable_sets)
hoelzl@49776
   337
  note M1.measurable_emeasure_Pair[OF this]
wenzelm@53015
   338
  moreover have "\<And>y. Pair y -` ((\<lambda>(x, y). (y, x)) -` Q \<inter> space (M2 \<Otimes>\<^sub>M M1)) = (\<lambda>x. (x, y)) -` Q"
immler@50244
   339
    using Q[THEN sets.sets_into_space] by (auto simp: space_pair_measure)
hoelzl@47694
   340
  ultimately show ?thesis by simp
hoelzl@39088
   341
qed
hoelzl@39088
   342
hoelzl@41689
   343
lemma (in pair_sigma_finite) sigma_finite_up_in_pair_measure_generator:
hoelzl@47694
   344
  defines "E \<equiv> {A \<times> B | A B. A \<in> sets M1 \<and> B \<in> sets M2}"
hoelzl@47694
   345
  shows "\<exists>F::nat \<Rightarrow> ('a \<times> 'b) set. range F \<subseteq> E \<and> incseq F \<and> (\<Union>i. F i) = space M1 \<times> space M2 \<and>
wenzelm@53015
   346
    (\<forall>i. emeasure (M1 \<Otimes>\<^sub>M M2) (F i) \<noteq> \<infinity>)"
hoelzl@40859
   347
proof -
hoelzl@47694
   348
  from M1.sigma_finite_incseq guess F1 . note F1 = this
hoelzl@47694
   349
  from M2.sigma_finite_incseq guess F2 . note F2 = this
hoelzl@47694
   350
  from F1 F2 have space: "space M1 = (\<Union>i. F1 i)" "space M2 = (\<Union>i. F2 i)" by auto
hoelzl@40859
   351
  let ?F = "\<lambda>i. F1 i \<times> F2 i"
hoelzl@47694
   352
  show ?thesis
hoelzl@40859
   353
  proof (intro exI[of _ ?F] conjI allI)
hoelzl@47694
   354
    show "range ?F \<subseteq> E" using F1 F2 by (auto simp: E_def) (metis range_subsetD)
hoelzl@40859
   355
  next
hoelzl@40859
   356
    have "space M1 \<times> space M2 \<subseteq> (\<Union>i. ?F i)"
hoelzl@40859
   357
    proof (intro subsetI)
hoelzl@40859
   358
      fix x assume "x \<in> space M1 \<times> space M2"
hoelzl@40859
   359
      then obtain i j where "fst x \<in> F1 i" "snd x \<in> F2 j"
hoelzl@40859
   360
        by (auto simp: space)
hoelzl@40859
   361
      then have "fst x \<in> F1 (max i j)" "snd x \<in> F2 (max j i)"
wenzelm@61808
   362
        using \<open>incseq F1\<close> \<open>incseq F2\<close> unfolding incseq_def
hoelzl@41981
   363
        by (force split: split_max)+
hoelzl@40859
   364
      then have "(fst x, snd x) \<in> F1 (max i j) \<times> F2 (max i j)"
haftmann@54863
   365
        by (intro SigmaI) (auto simp add: max.commute)
hoelzl@40859
   366
      then show "x \<in> (\<Union>i. ?F i)" by auto
hoelzl@40859
   367
    qed
hoelzl@47694
   368
    then show "(\<Union>i. ?F i) = space M1 \<times> space M2"
hoelzl@47694
   369
      using space by (auto simp: space)
hoelzl@40859
   370
  next
hoelzl@41981
   371
    fix i show "incseq (\<lambda>i. F1 i \<times> F2 i)"
wenzelm@61808
   372
      using \<open>incseq F1\<close> \<open>incseq F2\<close> unfolding incseq_Suc_iff by auto
hoelzl@40859
   373
  next
hoelzl@40859
   374
    fix i
hoelzl@40859
   375
    from F1 F2 have "F1 i \<in> sets M1" "F2 i \<in> sets M2" by auto
hoelzl@47694
   376
    with F1 F2 emeasure_nonneg[of M1 "F1 i"] emeasure_nonneg[of M2 "F2 i"]
wenzelm@53015
   377
    show "emeasure (M1 \<Otimes>\<^sub>M M2) (F1 i \<times> F2 i) \<noteq> \<infinity>"
hoelzl@47694
   378
      by (auto simp add: emeasure_pair_measure_Times)
hoelzl@47694
   379
  qed
hoelzl@47694
   380
qed
hoelzl@47694
   381
ballarin@61565
   382
sublocale pair_sigma_finite \<subseteq> P?: sigma_finite_measure "M1 \<Otimes>\<^sub>M M2"
hoelzl@47694
   383
proof
hoelzl@57447
   384
  from M1.sigma_finite_countable guess F1 ..
hoelzl@57447
   385
  moreover from M2.sigma_finite_countable guess F2 ..
hoelzl@57447
   386
  ultimately show
hoelzl@57447
   387
    "\<exists>A. countable A \<and> A \<subseteq> sets (M1 \<Otimes>\<^sub>M M2) \<and> \<Union>A = space (M1 \<Otimes>\<^sub>M M2) \<and> (\<forall>a\<in>A. emeasure (M1 \<Otimes>\<^sub>M M2) a \<noteq> \<infinity>)"
hoelzl@57447
   388
    by (intro exI[of _ "(\<lambda>(a, b). a \<times> b) ` (F1 \<times> F2)"] conjI)
hoelzl@57447
   389
       (auto simp: M2.emeasure_pair_measure_Times space_pair_measure set_eq_iff subset_eq
hoelzl@57447
   390
             dest: sets.sets_into_space)
hoelzl@40859
   391
qed
hoelzl@40859
   392
hoelzl@47694
   393
lemma sigma_finite_pair_measure:
hoelzl@47694
   394
  assumes A: "sigma_finite_measure A" and B: "sigma_finite_measure B"
wenzelm@53015
   395
  shows "sigma_finite_measure (A \<Otimes>\<^sub>M B)"
hoelzl@47694
   396
proof -
hoelzl@47694
   397
  interpret A: sigma_finite_measure A by fact
hoelzl@47694
   398
  interpret B: sigma_finite_measure B by fact
hoelzl@47694
   399
  interpret AB: pair_sigma_finite A  B ..
hoelzl@47694
   400
  show ?thesis ..
hoelzl@40859
   401
qed
hoelzl@39088
   402
hoelzl@47694
   403
lemma sets_pair_swap:
wenzelm@53015
   404
  assumes "A \<in> sets (M1 \<Otimes>\<^sub>M M2)"
wenzelm@53015
   405
  shows "(\<lambda>(x, y). (y, x)) -` A \<inter> space (M2 \<Otimes>\<^sub>M M1) \<in> sets (M2 \<Otimes>\<^sub>M M1)"
hoelzl@47694
   406
  using measurable_pair_swap' assms by (rule measurable_sets)
hoelzl@41661
   407
hoelzl@47694
   408
lemma (in pair_sigma_finite) distr_pair_swap:
wenzelm@53015
   409
  "M1 \<Otimes>\<^sub>M M2 = distr (M2 \<Otimes>\<^sub>M M1) (M1 \<Otimes>\<^sub>M M2) (\<lambda>(x, y). (y, x))" (is "?P = ?D")
hoelzl@40859
   410
proof -
hoelzl@41689
   411
  from sigma_finite_up_in_pair_measure_generator guess F :: "nat \<Rightarrow> ('a \<times> 'b) set" .. note F = this
hoelzl@47694
   412
  let ?E = "{a \<times> b |a b. a \<in> sets M1 \<and> b \<in> sets M2}"
hoelzl@47694
   413
  show ?thesis
hoelzl@47694
   414
  proof (rule measure_eqI_generator_eq[OF Int_stable_pair_measure_generator[of M1 M2]])
hoelzl@47694
   415
    show "?E \<subseteq> Pow (space ?P)"
immler@50244
   416
      using sets.space_closed[of M1] sets.space_closed[of M2] by (auto simp: space_pair_measure)
hoelzl@47694
   417
    show "sets ?P = sigma_sets (space ?P) ?E"
hoelzl@47694
   418
      by (simp add: sets_pair_measure space_pair_measure)
hoelzl@47694
   419
    then show "sets ?D = sigma_sets (space ?P) ?E"
hoelzl@47694
   420
      by simp
hoelzl@47694
   421
  next
hoelzl@49784
   422
    show "range F \<subseteq> ?E" "(\<Union>i. F i) = space ?P" "\<And>i. emeasure ?P (F i) \<noteq> \<infinity>"
hoelzl@47694
   423
      using F by (auto simp: space_pair_measure)
hoelzl@47694
   424
  next
hoelzl@47694
   425
    fix X assume "X \<in> ?E"
hoelzl@47694
   426
    then obtain A B where X[simp]: "X = A \<times> B" and A: "A \<in> sets M1" and B: "B \<in> sets M2" by auto
wenzelm@53015
   427
    have "(\<lambda>(y, x). (x, y)) -` X \<inter> space (M2 \<Otimes>\<^sub>M M1) = B \<times> A"
immler@50244
   428
      using sets.sets_into_space[OF A] sets.sets_into_space[OF B] by (auto simp: space_pair_measure)
wenzelm@53015
   429
    with A B show "emeasure (M1 \<Otimes>\<^sub>M M2) X = emeasure ?D X"
hoelzl@49776
   430
      by (simp add: M2.emeasure_pair_measure_Times M1.emeasure_pair_measure_Times emeasure_distr
hoelzl@47694
   431
                    measurable_pair_swap' ac_simps)
hoelzl@41689
   432
  qed
hoelzl@41689
   433
qed
hoelzl@41689
   434
hoelzl@47694
   435
lemma (in pair_sigma_finite) emeasure_pair_measure_alt2:
wenzelm@53015
   436
  assumes A: "A \<in> sets (M1 \<Otimes>\<^sub>M M2)"
wenzelm@53015
   437
  shows "emeasure (M1 \<Otimes>\<^sub>M M2) A = (\<integral>\<^sup>+y. emeasure M1 ((\<lambda>x. (x, y)) -` A) \<partial>M2)"
hoelzl@47694
   438
    (is "_ = ?\<nu> A")
hoelzl@41689
   439
proof -
wenzelm@53015
   440
  have [simp]: "\<And>y. (Pair y -` ((\<lambda>(x, y). (y, x)) -` A \<inter> space (M2 \<Otimes>\<^sub>M M1))) = (\<lambda>x. (x, y)) -` A"
immler@50244
   441
    using sets.sets_into_space[OF A] by (auto simp: space_pair_measure)
hoelzl@47694
   442
  show ?thesis using A
hoelzl@47694
   443
    by (subst distr_pair_swap)
hoelzl@47694
   444
       (simp_all del: vimage_Int add: measurable_sets[OF measurable_pair_swap']
hoelzl@49776
   445
                 M1.emeasure_pair_measure_alt emeasure_distr[OF measurable_pair_swap' A])
hoelzl@49776
   446
qed
hoelzl@49776
   447
hoelzl@49776
   448
lemma (in pair_sigma_finite) AE_pair:
wenzelm@53015
   449
  assumes "AE x in (M1 \<Otimes>\<^sub>M M2). Q x"
hoelzl@49776
   450
  shows "AE x in M1. (AE y in M2. Q (x, y))"
hoelzl@49776
   451
proof -
wenzelm@53015
   452
  obtain N where N: "N \<in> sets (M1 \<Otimes>\<^sub>M M2)" "emeasure (M1 \<Otimes>\<^sub>M M2) N = 0" "{x\<in>space (M1 \<Otimes>\<^sub>M M2). \<not> Q x} \<subseteq> N"
hoelzl@49776
   453
    using assms unfolding eventually_ae_filter by auto
hoelzl@49776
   454
  show ?thesis
hoelzl@49776
   455
  proof (rule AE_I)
wenzelm@61808
   456
    from N measurable_emeasure_Pair1[OF \<open>N \<in> sets (M1 \<Otimes>\<^sub>M M2)\<close>]
hoelzl@49776
   457
    show "emeasure M1 {x\<in>space M1. emeasure M2 (Pair x -` N) \<noteq> 0} = 0"
hoelzl@56996
   458
      by (auto simp: M2.emeasure_pair_measure_alt nn_integral_0_iff emeasure_nonneg)
hoelzl@49776
   459
    show "{x \<in> space M1. emeasure M2 (Pair x -` N) \<noteq> 0} \<in> sets M1"
hoelzl@49776
   460
      by (intro borel_measurable_ereal_neq_const measurable_emeasure_Pair1 N)
hoelzl@49776
   461
    { fix x assume "x \<in> space M1" "emeasure M2 (Pair x -` N) = 0"
hoelzl@49776
   462
      have "AE y in M2. Q (x, y)"
hoelzl@49776
   463
      proof (rule AE_I)
hoelzl@49776
   464
        show "emeasure M2 (Pair x -` N) = 0" by fact
hoelzl@49776
   465
        show "Pair x -` N \<in> sets M2" using N(1) by (rule sets_Pair1)
hoelzl@49776
   466
        show "{y \<in> space M2. \<not> Q (x, y)} \<subseteq> Pair x -` N"
wenzelm@61808
   467
          using N \<open>x \<in> space M1\<close> unfolding space_pair_measure by auto
hoelzl@49776
   468
      qed }
hoelzl@49776
   469
    then show "{x \<in> space M1. \<not> (AE y in M2. Q (x, y))} \<subseteq> {x \<in> space M1. emeasure M2 (Pair x -` N) \<noteq> 0}"
hoelzl@49776
   470
      by auto
hoelzl@49776
   471
  qed
hoelzl@49776
   472
qed
hoelzl@49776
   473
hoelzl@49776
   474
lemma (in pair_sigma_finite) AE_pair_measure:
wenzelm@53015
   475
  assumes "{x\<in>space (M1 \<Otimes>\<^sub>M M2). P x} \<in> sets (M1 \<Otimes>\<^sub>M M2)"
hoelzl@49776
   476
  assumes ae: "AE x in M1. AE y in M2. P (x, y)"
wenzelm@53015
   477
  shows "AE x in M1 \<Otimes>\<^sub>M M2. P x"
hoelzl@49776
   478
proof (subst AE_iff_measurable[OF _ refl])
wenzelm@53015
   479
  show "{x\<in>space (M1 \<Otimes>\<^sub>M M2). \<not> P x} \<in> sets (M1 \<Otimes>\<^sub>M M2)"
immler@50244
   480
    by (rule sets.sets_Collect) fact
wenzelm@53015
   481
  then have "emeasure (M1 \<Otimes>\<^sub>M M2) {x \<in> space (M1 \<Otimes>\<^sub>M M2). \<not> P x} =
wenzelm@53015
   482
      (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. indicator {x \<in> space (M1 \<Otimes>\<^sub>M M2). \<not> P x} (x, y) \<partial>M2 \<partial>M1)"
hoelzl@49776
   483
    by (simp add: M2.emeasure_pair_measure)
wenzelm@53015
   484
  also have "\<dots> = (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. 0 \<partial>M2 \<partial>M1)"
hoelzl@49776
   485
    using ae
hoelzl@56996
   486
    apply (safe intro!: nn_integral_cong_AE)
hoelzl@49776
   487
    apply (intro AE_I2)
hoelzl@56996
   488
    apply (safe intro!: nn_integral_cong_AE)
hoelzl@49776
   489
    apply auto
hoelzl@49776
   490
    done
wenzelm@53015
   491
  finally show "emeasure (M1 \<Otimes>\<^sub>M M2) {x \<in> space (M1 \<Otimes>\<^sub>M M2). \<not> P x} = 0" by simp
hoelzl@49776
   492
qed
hoelzl@49776
   493
hoelzl@49776
   494
lemma (in pair_sigma_finite) AE_pair_iff:
wenzelm@53015
   495
  "{x\<in>space (M1 \<Otimes>\<^sub>M M2). P (fst x) (snd x)} \<in> sets (M1 \<Otimes>\<^sub>M M2) \<Longrightarrow>
wenzelm@53015
   496
    (AE x in M1. AE y in M2. P x y) \<longleftrightarrow> (AE x in (M1 \<Otimes>\<^sub>M M2). P (fst x) (snd x))"
hoelzl@49776
   497
  using AE_pair[of "\<lambda>x. P (fst x) (snd x)"] AE_pair_measure[of "\<lambda>x. P (fst x) (snd x)"] by auto
hoelzl@49776
   498
hoelzl@49776
   499
lemma (in pair_sigma_finite) AE_commute:
wenzelm@53015
   500
  assumes P: "{x\<in>space (M1 \<Otimes>\<^sub>M M2). P (fst x) (snd x)} \<in> sets (M1 \<Otimes>\<^sub>M M2)"
hoelzl@49776
   501
  shows "(AE x in M1. AE y in M2. P x y) \<longleftrightarrow> (AE y in M2. AE x in M1. P x y)"
hoelzl@49776
   502
proof -
hoelzl@49776
   503
  interpret Q: pair_sigma_finite M2 M1 ..
hoelzl@49776
   504
  have [simp]: "\<And>x. (fst (case x of (x, y) \<Rightarrow> (y, x))) = snd x" "\<And>x. (snd (case x of (x, y) \<Rightarrow> (y, x))) = fst x"
hoelzl@49776
   505
    by auto
wenzelm@53015
   506
  have "{x \<in> space (M2 \<Otimes>\<^sub>M M1). P (snd x) (fst x)} =
wenzelm@53015
   507
    (\<lambda>(x, y). (y, x)) -` {x \<in> space (M1 \<Otimes>\<^sub>M M2). P (fst x) (snd x)} \<inter> space (M2 \<Otimes>\<^sub>M M1)"
hoelzl@49776
   508
    by (auto simp: space_pair_measure)
wenzelm@53015
   509
  also have "\<dots> \<in> sets (M2 \<Otimes>\<^sub>M M1)"
hoelzl@49776
   510
    by (intro sets_pair_swap P)
hoelzl@49776
   511
  finally show ?thesis
hoelzl@49776
   512
    apply (subst AE_pair_iff[OF P])
hoelzl@49776
   513
    apply (subst distr_pair_swap)
hoelzl@49776
   514
    apply (subst AE_distr_iff[OF measurable_pair_swap' P])
hoelzl@49776
   515
    apply (subst Q.AE_pair_iff)
hoelzl@49776
   516
    apply simp_all
hoelzl@49776
   517
    done
hoelzl@40859
   518
qed
hoelzl@40859
   519
hoelzl@56994
   520
subsection "Fubinis theorem"
hoelzl@40859
   521
hoelzl@49800
   522
lemma measurable_compose_Pair1:
wenzelm@53015
   523
  "x \<in> space M1 \<Longrightarrow> g \<in> measurable (M1 \<Otimes>\<^sub>M M2) L \<Longrightarrow> (\<lambda>y. g (x, y)) \<in> measurable M2 L"
hoelzl@50003
   524
  by simp
hoelzl@49800
   525
hoelzl@56996
   526
lemma (in sigma_finite_measure) borel_measurable_nn_integral_fst':
wenzelm@53015
   527
  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M)" "\<And>x. 0 \<le> f x"
wenzelm@53015
   528
  shows "(\<lambda>x. \<integral>\<^sup>+ y. f (x, y) \<partial>M) \<in> borel_measurable M1"
hoelzl@49800
   529
using f proof induct
hoelzl@49800
   530
  case (cong u v)
hoelzl@49999
   531
  then have "\<And>w x. w \<in> space M1 \<Longrightarrow> x \<in> space M \<Longrightarrow> u (w, x) = v (w, x)"
hoelzl@49800
   532
    by (auto simp: space_pair_measure)
hoelzl@49800
   533
  show ?case
hoelzl@49800
   534
    apply (subst measurable_cong)
hoelzl@56996
   535
    apply (rule nn_integral_cong)
hoelzl@49800
   536
    apply fact+
hoelzl@49800
   537
    done
hoelzl@49800
   538
next
hoelzl@49800
   539
  case (set Q)
hoelzl@49800
   540
  have [simp]: "\<And>x y. indicator Q (x, y) = indicator (Pair x -` Q) y"
hoelzl@49800
   541
    by (auto simp: indicator_def)
wenzelm@53015
   542
  have "\<And>x. x \<in> space M1 \<Longrightarrow> emeasure M (Pair x -` Q) = \<integral>\<^sup>+ y. indicator Q (x, y) \<partial>M"
hoelzl@49800
   543
    by (simp add: sets_Pair1[OF set])
hoelzl@49999
   544
  from this measurable_emeasure_Pair[OF set] show ?case
hoelzl@49800
   545
    by (rule measurable_cong[THEN iffD1])
hoelzl@56996
   546
qed (simp_all add: nn_integral_add nn_integral_cmult measurable_compose_Pair1
hoelzl@56996
   547
                   nn_integral_monotone_convergence_SUP incseq_def le_fun_def
hoelzl@49800
   548
              cong: measurable_cong)
hoelzl@49800
   549
hoelzl@56996
   550
lemma (in sigma_finite_measure) nn_integral_fst':
wenzelm@53015
   551
  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M)" "\<And>x. 0 \<le> f x"
hoelzl@56996
   552
  shows "(\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. f (x, y) \<partial>M \<partial>M1) = integral\<^sup>N (M1 \<Otimes>\<^sub>M M) f" (is "?I f = _")
hoelzl@49800
   553
using f proof induct
hoelzl@49800
   554
  case (cong u v)
wenzelm@53374
   555
  then have "?I u = ?I v"
hoelzl@56996
   556
    by (intro nn_integral_cong) (auto simp: space_pair_measure)
wenzelm@53374
   557
  with cong show ?case
hoelzl@56996
   558
    by (simp cong: nn_integral_cong)
hoelzl@56996
   559
qed (simp_all add: emeasure_pair_measure nn_integral_cmult nn_integral_add
hoelzl@56996
   560
                   nn_integral_monotone_convergence_SUP
hoelzl@56996
   561
                   measurable_compose_Pair1 nn_integral_nonneg
hoelzl@56996
   562
                   borel_measurable_nn_integral_fst' nn_integral_mono incseq_def le_fun_def
hoelzl@56996
   563
              cong: nn_integral_cong)
hoelzl@40859
   564
hoelzl@56996
   565
lemma (in sigma_finite_measure) nn_integral_fst:
wenzelm@53015
   566
  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M)"
hoelzl@56996
   567
  shows "(\<integral>\<^sup>+ x. (\<integral>\<^sup>+ y. f (x, y) \<partial>M) \<partial>M1) = integral\<^sup>N (M1 \<Otimes>\<^sub>M M) f"
hoelzl@49800
   568
  using f
hoelzl@56996
   569
    borel_measurable_nn_integral_fst'[of "\<lambda>x. max 0 (f x)"]
hoelzl@56996
   570
    nn_integral_fst'[of "\<lambda>x. max 0 (f x)"]
hoelzl@56996
   571
  unfolding nn_integral_max_0 by auto
hoelzl@40859
   572
hoelzl@56996
   573
lemma (in sigma_finite_measure) borel_measurable_nn_integral[measurable (raw)]:
haftmann@61424
   574
  "case_prod f \<in> borel_measurable (N \<Otimes>\<^sub>M M) \<Longrightarrow> (\<lambda>x. \<integral>\<^sup>+ y. f x y \<partial>M) \<in> borel_measurable N"
haftmann@61424
   575
  using borel_measurable_nn_integral_fst'[of "\<lambda>x. max 0 (case_prod f x)" N]
hoelzl@56996
   576
  by (simp add: nn_integral_max_0)
hoelzl@50003
   577
hoelzl@56996
   578
lemma (in pair_sigma_finite) nn_integral_snd:
wenzelm@53015
   579
  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M2)"
hoelzl@56996
   580
  shows "(\<integral>\<^sup>+ y. (\<integral>\<^sup>+ x. f (x, y) \<partial>M1) \<partial>M2) = integral\<^sup>N (M1 \<Otimes>\<^sub>M M2) f"
hoelzl@41661
   581
proof -
hoelzl@47694
   582
  note measurable_pair_swap[OF f]
hoelzl@56996
   583
  from M1.nn_integral_fst[OF this]
wenzelm@53015
   584
  have "(\<integral>\<^sup>+ y. (\<integral>\<^sup>+ x. f (x, y) \<partial>M1) \<partial>M2) = (\<integral>\<^sup>+ (x, y). f (y, x) \<partial>(M2 \<Otimes>\<^sub>M M1))"
hoelzl@40859
   585
    by simp
hoelzl@56996
   586
  also have "(\<integral>\<^sup>+ (x, y). f (y, x) \<partial>(M2 \<Otimes>\<^sub>M M1)) = integral\<^sup>N (M1 \<Otimes>\<^sub>M M2) f"
hoelzl@47694
   587
    by (subst distr_pair_swap)
hoelzl@56996
   588
       (auto simp: nn_integral_distr[OF measurable_pair_swap' f] intro!: nn_integral_cong)
hoelzl@40859
   589
  finally show ?thesis .
hoelzl@40859
   590
qed
hoelzl@40859
   591
hoelzl@40859
   592
lemma (in pair_sigma_finite) Fubini:
wenzelm@53015
   593
  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M2)"
wenzelm@53015
   594
  shows "(\<integral>\<^sup>+ y. (\<integral>\<^sup>+ x. f (x, y) \<partial>M1) \<partial>M2) = (\<integral>\<^sup>+ x. (\<integral>\<^sup>+ y. f (x, y) \<partial>M2) \<partial>M1)"
hoelzl@56996
   595
  unfolding nn_integral_snd[OF assms] M2.nn_integral_fst[OF assms] ..
hoelzl@41026
   596
hoelzl@57235
   597
lemma (in pair_sigma_finite) Fubini':
haftmann@61424
   598
  assumes f: "case_prod f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M2)"
hoelzl@57235
   599
  shows "(\<integral>\<^sup>+ y. (\<integral>\<^sup>+ x. f x y \<partial>M1) \<partial>M2) = (\<integral>\<^sup>+ x. (\<integral>\<^sup>+ y. f x y \<partial>M2) \<partial>M1)"
hoelzl@57235
   600
  using Fubini[OF f] by simp
hoelzl@57235
   601
wenzelm@61808
   602
subsection \<open>Products on counting spaces, densities and distributions\<close>
hoelzl@40859
   603
hoelzl@59088
   604
lemma sigma_prod:
hoelzl@59088
   605
  assumes X_cover: "\<exists>E\<subseteq>A. countable E \<and> X = \<Union>E" and A: "A \<subseteq> Pow X"
hoelzl@59088
   606
  assumes Y_cover: "\<exists>E\<subseteq>B. countable E \<and> Y = \<Union>E" and B: "B \<subseteq> Pow Y"
hoelzl@59088
   607
  shows "sigma X A \<Otimes>\<^sub>M sigma Y B = sigma (X \<times> Y) {a \<times> b | a b. a \<in> A \<and> b \<in> B}"
hoelzl@59088
   608
    (is "?P = ?S")
hoelzl@59088
   609
proof (rule measure_eqI)
hoelzl@59088
   610
  have [simp]: "snd \<in> X \<times> Y \<rightarrow> Y" "fst \<in> X \<times> Y \<rightarrow> X"
hoelzl@59088
   611
    by auto
hoelzl@59088
   612
  let ?XY = "{{fst -` a \<inter> X \<times> Y | a. a \<in> A}, {snd -` b \<inter> X \<times> Y | b. b \<in> B}}"
hoelzl@59088
   613
  have "sets ?P = 
hoelzl@59088
   614
    sets (\<Squnion>\<^sub>\<sigma> xy\<in>?XY. sigma (X \<times> Y) xy)"
hoelzl@59088
   615
    by (simp add: vimage_algebra_sigma sets_pair_eq_sets_fst_snd A B)
hoelzl@59088
   616
  also have "\<dots> = sets (sigma (X \<times> Y) (\<Union>?XY))"
hoelzl@59088
   617
    by (intro Sup_sigma_sigma arg_cong[where f=sets]) auto
hoelzl@59088
   618
  also have "\<dots> = sets ?S"
hoelzl@59088
   619
  proof (intro arg_cong[where f=sets] sigma_eqI sigma_sets_eqI) 
hoelzl@59088
   620
    show "\<Union>?XY \<subseteq> Pow (X \<times> Y)" "{a \<times> b |a b. a \<in> A \<and> b \<in> B} \<subseteq> Pow (X \<times> Y)"
hoelzl@59088
   621
      using A B by auto
hoelzl@59088
   622
  next
hoelzl@59088
   623
    interpret XY: sigma_algebra "X \<times> Y" "sigma_sets (X \<times> Y) {a \<times> b |a b. a \<in> A \<and> b \<in> B}"
hoelzl@59088
   624
      using A B by (intro sigma_algebra_sigma_sets) auto
hoelzl@59088
   625
    fix Z assume "Z \<in> \<Union>?XY"
hoelzl@59088
   626
    then show "Z \<in> sigma_sets (X \<times> Y) {a \<times> b |a b. a \<in> A \<and> b \<in> B}"
hoelzl@59088
   627
    proof safe
hoelzl@59088
   628
      fix a assume "a \<in> A"
hoelzl@59088
   629
      from Y_cover obtain E where E: "E \<subseteq> B" "countable E" and "Y = \<Union>E"
hoelzl@59088
   630
        by auto
wenzelm@61808
   631
      with \<open>a \<in> A\<close> A have eq: "fst -` a \<inter> X \<times> Y = (\<Union>e\<in>E. a \<times> e)"
hoelzl@59088
   632
        by auto
hoelzl@59088
   633
      show "fst -` a \<inter> X \<times> Y \<in> sigma_sets (X \<times> Y) {a \<times> b |a b. a \<in> A \<and> b \<in> B}"
wenzelm@61808
   634
        using \<open>a \<in> A\<close> E unfolding eq by (auto intro!: XY.countable_UN')
hoelzl@59088
   635
    next
hoelzl@59088
   636
      fix b assume "b \<in> B"
hoelzl@59088
   637
      from X_cover obtain E where E: "E \<subseteq> A" "countable E" and "X = \<Union>E"
hoelzl@59088
   638
        by auto
wenzelm@61808
   639
      with \<open>b \<in> B\<close> B have eq: "snd -` b \<inter> X \<times> Y = (\<Union>e\<in>E. e \<times> b)"
hoelzl@59088
   640
        by auto
hoelzl@59088
   641
      show "snd -` b \<inter> X \<times> Y \<in> sigma_sets (X \<times> Y) {a \<times> b |a b. a \<in> A \<and> b \<in> B}"
wenzelm@61808
   642
        using \<open>b \<in> B\<close> E unfolding eq by (auto intro!: XY.countable_UN')
hoelzl@59088
   643
    qed
hoelzl@59088
   644
  next
hoelzl@59088
   645
    fix Z assume "Z \<in> {a \<times> b |a b. a \<in> A \<and> b \<in> B}"
hoelzl@59088
   646
    then obtain a b where "Z = a \<times> b" and ab: "a \<in> A" "b \<in> B"
hoelzl@59088
   647
      by auto
hoelzl@59088
   648
    then have Z: "Z = (fst -` a \<inter> X \<times> Y) \<inter> (snd -` b \<inter> X \<times> Y)"
hoelzl@59088
   649
      using A B by auto
hoelzl@59088
   650
    interpret XY: sigma_algebra "X \<times> Y" "sigma_sets (X \<times> Y) (\<Union>?XY)"
hoelzl@59088
   651
      by (intro sigma_algebra_sigma_sets) auto
hoelzl@59088
   652
    show "Z \<in> sigma_sets (X \<times> Y) (\<Union>?XY)"
hoelzl@59088
   653
      unfolding Z by (rule XY.Int) (blast intro: ab)+
hoelzl@59088
   654
  qed
hoelzl@59088
   655
  finally show "sets ?P = sets ?S" .
hoelzl@59088
   656
next
hoelzl@59088
   657
  interpret finite_measure "sigma X A" for X A
hoelzl@59088
   658
    proof qed (simp add: emeasure_sigma)
hoelzl@59088
   659
  fix A assume "A \<in> sets ?P" then show "emeasure ?P A = emeasure ?S A"
hoelzl@59088
   660
    by (simp add: emeasure_pair_measure_alt emeasure_sigma)
hoelzl@59088
   661
qed
hoelzl@59088
   662
hoelzl@41689
   663
lemma sigma_sets_pair_measure_generator_finite:
hoelzl@38656
   664
  assumes "finite A" and "finite B"
hoelzl@47694
   665
  shows "sigma_sets (A \<times> B) { a \<times> b | a b. a \<subseteq> A \<and> b \<subseteq> B} = Pow (A \<times> B)"
hoelzl@40859
   666
  (is "sigma_sets ?prod ?sets = _")
hoelzl@38656
   667
proof safe
hoelzl@38656
   668
  have fin: "finite (A \<times> B)" using assms by (rule finite_cartesian_product)
hoelzl@38656
   669
  fix x assume subset: "x \<subseteq> A \<times> B"
hoelzl@38656
   670
  hence "finite x" using fin by (rule finite_subset)
hoelzl@40859
   671
  from this subset show "x \<in> sigma_sets ?prod ?sets"
hoelzl@38656
   672
  proof (induct x)
hoelzl@38656
   673
    case empty show ?case by (rule sigma_sets.Empty)
hoelzl@38656
   674
  next
hoelzl@38656
   675
    case (insert a x)
hoelzl@47694
   676
    hence "{a} \<in> sigma_sets ?prod ?sets" by auto
hoelzl@38656
   677
    moreover have "x \<in> sigma_sets ?prod ?sets" using insert by auto
hoelzl@38656
   678
    ultimately show ?case unfolding insert_is_Un[of a x] by (rule sigma_sets_Un)
hoelzl@38656
   679
  qed
hoelzl@38656
   680
next
hoelzl@38656
   681
  fix x a b
hoelzl@40859
   682
  assume "x \<in> sigma_sets ?prod ?sets" and "(a, b) \<in> x"
hoelzl@38656
   683
  from sigma_sets_into_sp[OF _ this(1)] this(2)
hoelzl@40859
   684
  show "a \<in> A" and "b \<in> B" by auto
hoelzl@35833
   685
qed
hoelzl@35833
   686
hoelzl@59088
   687
lemma borel_prod:
hoelzl@59088
   688
  "(borel \<Otimes>\<^sub>M borel) = (borel :: ('a::second_countable_topology \<times> 'b::second_countable_topology) measure)"
hoelzl@59088
   689
  (is "?P = ?B")
hoelzl@59088
   690
proof -
hoelzl@59088
   691
  have "?B = sigma UNIV {A \<times> B | A B. open A \<and> open B}"
hoelzl@59088
   692
    by (rule second_countable_borel_measurable[OF open_prod_generated])
hoelzl@59088
   693
  also have "\<dots> = ?P"
hoelzl@59088
   694
    unfolding borel_def
hoelzl@59088
   695
    by (subst sigma_prod) (auto intro!: exI[of _ "{UNIV}"])
hoelzl@59088
   696
  finally show ?thesis ..
hoelzl@59088
   697
qed
hoelzl@59088
   698
hoelzl@47694
   699
lemma pair_measure_count_space:
hoelzl@47694
   700
  assumes A: "finite A" and B: "finite B"
wenzelm@53015
   701
  shows "count_space A \<Otimes>\<^sub>M count_space B = count_space (A \<times> B)" (is "?P = ?C")
hoelzl@47694
   702
proof (rule measure_eqI)
hoelzl@47694
   703
  interpret A: finite_measure "count_space A" by (rule finite_measure_count_space) fact
hoelzl@47694
   704
  interpret B: finite_measure "count_space B" by (rule finite_measure_count_space) fact
wenzelm@61169
   705
  interpret P: pair_sigma_finite "count_space A" "count_space B" ..
hoelzl@47694
   706
  show eq: "sets ?P = sets ?C"
hoelzl@47694
   707
    by (simp add: sets_pair_measure sigma_sets_pair_measure_generator_finite A B)
hoelzl@47694
   708
  fix X assume X: "X \<in> sets ?P"
hoelzl@47694
   709
  with eq have X_subset: "X \<subseteq> A \<times> B" by simp
hoelzl@47694
   710
  with A B have fin_Pair: "\<And>x. finite (Pair x -` X)"
hoelzl@47694
   711
    by (intro finite_subset[OF _ B]) auto
hoelzl@47694
   712
  have fin_X: "finite X" using X_subset by (rule finite_subset) (auto simp: A B)
hoelzl@47694
   713
  show "emeasure ?P X = emeasure ?C X"
hoelzl@49776
   714
    apply (subst B.emeasure_pair_measure_alt[OF X])
hoelzl@47694
   715
    apply (subst emeasure_count_space)
hoelzl@47694
   716
    using X_subset apply auto []
hoelzl@47694
   717
    apply (simp add: fin_Pair emeasure_count_space X_subset fin_X)
hoelzl@56996
   718
    apply (subst nn_integral_count_space)
hoelzl@47694
   719
    using A apply simp
lp15@61609
   720
    apply (simp del: of_nat_setsum add: of_nat_setsum[symmetric])
hoelzl@47694
   721
    apply (subst card_gt_0_iff)
hoelzl@47694
   722
    apply (simp add: fin_Pair)
hoelzl@47694
   723
    apply (subst card_SigmaI[symmetric])
hoelzl@47694
   724
    using A apply simp
hoelzl@47694
   725
    using fin_Pair apply simp
hoelzl@47694
   726
    using X_subset apply (auto intro!: arg_cong[where f=card])
hoelzl@47694
   727
    done
hoelzl@45777
   728
qed
hoelzl@35833
   729
hoelzl@59426
   730
hoelzl@59426
   731
lemma emeasure_prod_count_space:
hoelzl@59426
   732
  assumes A: "A \<in> sets (count_space UNIV \<Otimes>\<^sub>M M)" (is "A \<in> sets (?A \<Otimes>\<^sub>M ?B)")
hoelzl@59426
   733
  shows "emeasure (?A \<Otimes>\<^sub>M ?B) A = (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. indicator A (x, y) \<partial>?B \<partial>?A)"
hoelzl@59426
   734
  by (rule emeasure_measure_of[OF pair_measure_def])
hoelzl@59426
   735
     (auto simp: countably_additive_def positive_def suminf_indicator nn_integral_nonneg A
hoelzl@59426
   736
                 nn_integral_suminf[symmetric] dest: sets.sets_into_space)
hoelzl@59426
   737
hoelzl@59426
   738
lemma emeasure_prod_count_space_single[simp]: "emeasure (count_space UNIV \<Otimes>\<^sub>M count_space UNIV) {x} = 1"
hoelzl@59426
   739
proof -
hoelzl@59426
   740
  have [simp]: "\<And>a b x y. indicator {(a, b)} (x, y) = (indicator {a} x * indicator {b} y::ereal)"
hoelzl@59426
   741
    by (auto split: split_indicator)
hoelzl@59426
   742
  show ?thesis
hoelzl@59426
   743
    by (cases x)
hoelzl@59426
   744
       (auto simp: emeasure_prod_count_space nn_integral_cmult sets_Pair nn_integral_max_0 one_ereal_def[symmetric])
hoelzl@59426
   745
qed
hoelzl@59426
   746
hoelzl@59426
   747
lemma emeasure_count_space_prod_eq:
hoelzl@59426
   748
  fixes A :: "('a \<times> 'b) set"
hoelzl@59426
   749
  assumes A: "A \<in> sets (count_space UNIV \<Otimes>\<^sub>M count_space UNIV)" (is "A \<in> sets (?A \<Otimes>\<^sub>M ?B)")
hoelzl@59426
   750
  shows "emeasure (?A \<Otimes>\<^sub>M ?B) A = emeasure (count_space UNIV) A"
hoelzl@59426
   751
proof -
hoelzl@59426
   752
  { fix A :: "('a \<times> 'b) set" assume "countable A"
hoelzl@59426
   753
    then have "emeasure (?A \<Otimes>\<^sub>M ?B) (\<Union>a\<in>A. {a}) = (\<integral>\<^sup>+a. emeasure (?A \<Otimes>\<^sub>M ?B) {a} \<partial>count_space A)"
hoelzl@59426
   754
      by (intro emeasure_UN_countable) (auto simp: sets_Pair disjoint_family_on_def)
hoelzl@59426
   755
    also have "\<dots> = (\<integral>\<^sup>+a. indicator A a \<partial>count_space UNIV)"
hoelzl@59426
   756
      by (subst nn_integral_count_space_indicator) auto
hoelzl@59426
   757
    finally have "emeasure (?A \<Otimes>\<^sub>M ?B) A = emeasure (count_space UNIV) A"
hoelzl@59426
   758
      by simp }
hoelzl@59426
   759
  note * = this
hoelzl@59426
   760
hoelzl@59426
   761
  show ?thesis
hoelzl@59426
   762
  proof cases
hoelzl@59426
   763
    assume "finite A" then show ?thesis
hoelzl@59426
   764
      by (intro * countable_finite)
hoelzl@59426
   765
  next
hoelzl@59426
   766
    assume "infinite A"
hoelzl@59426
   767
    then obtain C where "countable C" and "infinite C" and "C \<subseteq> A"
hoelzl@59426
   768
      by (auto dest: infinite_countable_subset')
hoelzl@59426
   769
    with A have "emeasure (?A \<Otimes>\<^sub>M ?B) C \<le> emeasure (?A \<Otimes>\<^sub>M ?B) A"
hoelzl@59426
   770
      by (intro emeasure_mono) auto
hoelzl@59426
   771
    also have "emeasure (?A \<Otimes>\<^sub>M ?B) C = emeasure (count_space UNIV) C"
wenzelm@61808
   772
      using \<open>countable C\<close> by (rule *)
hoelzl@59426
   773
    finally show ?thesis
wenzelm@61808
   774
      using \<open>infinite C\<close> \<open>infinite A\<close> by simp
hoelzl@59426
   775
  qed
hoelzl@59426
   776
qed
hoelzl@59426
   777
hoelzl@59426
   778
lemma nn_intergal_count_space_prod_eq':
hoelzl@59426
   779
  assumes [simp]: "\<And>x. 0 \<le> f x"
hoelzl@59426
   780
  shows "nn_integral (count_space UNIV \<Otimes>\<^sub>M count_space UNIV) f = nn_integral (count_space UNIV) f"
hoelzl@59426
   781
    (is "nn_integral ?P f = _")
hoelzl@59426
   782
proof cases
hoelzl@59426
   783
  assume cntbl: "countable {x. f x \<noteq> 0}"
hoelzl@59426
   784
  have [simp]: "\<And>x. ereal (real (card ({x} \<inter> {x. f x \<noteq> 0}))) = indicator {x. f x \<noteq> 0} x"
hoelzl@59426
   785
    by (auto split: split_indicator)
hoelzl@59426
   786
  have [measurable]: "\<And>y. (\<lambda>x. indicator {y} x) \<in> borel_measurable ?P"
hoelzl@59426
   787
    by (rule measurable_discrete_difference[of "\<lambda>x. 0" _ borel "{y}" "\<lambda>x. indicator {y} x" for y])
hoelzl@59426
   788
       (auto intro: sets_Pair)
hoelzl@59426
   789
hoelzl@59426
   790
  have "(\<integral>\<^sup>+x. f x \<partial>?P) = (\<integral>\<^sup>+x. \<integral>\<^sup>+x'. f x * indicator {x} x' \<partial>count_space {x. f x \<noteq> 0} \<partial>?P)"
hoelzl@59426
   791
    by (auto simp add: nn_integral_cmult nn_integral_indicator' intro!: nn_integral_cong split: split_indicator)
hoelzl@59426
   792
  also have "\<dots> = (\<integral>\<^sup>+x. \<integral>\<^sup>+x'. f x' * indicator {x'} x \<partial>count_space {x. f x \<noteq> 0} \<partial>?P)"
hoelzl@59426
   793
    by (auto intro!: nn_integral_cong split: split_indicator)
hoelzl@59426
   794
  also have "\<dots> = (\<integral>\<^sup>+x'. \<integral>\<^sup>+x. f x' * indicator {x'} x \<partial>?P \<partial>count_space {x. f x \<noteq> 0})"
hoelzl@59426
   795
    by (intro nn_integral_count_space_nn_integral cntbl) auto
hoelzl@59426
   796
  also have "\<dots> = (\<integral>\<^sup>+x'. f x' \<partial>count_space {x. f x \<noteq> 0})"
hoelzl@59426
   797
    by (intro nn_integral_cong) (auto simp: nn_integral_cmult sets_Pair)
hoelzl@59426
   798
  finally show ?thesis
hoelzl@59426
   799
    by (auto simp add: nn_integral_count_space_indicator intro!: nn_integral_cong split: split_indicator)
hoelzl@59426
   800
next
hoelzl@59426
   801
  { fix x assume "f x \<noteq> 0"
wenzelm@61808
   802
    with \<open>0 \<le> f x\<close> have "(\<exists>r. 0 < r \<and> f x = ereal r) \<or> f x = \<infinity>"
hoelzl@59426
   803
      by (cases "f x") (auto simp: less_le)
hoelzl@59426
   804
    then have "\<exists>n. ereal (1 / real (Suc n)) \<le> f x"
hoelzl@59426
   805
      by (auto elim!: nat_approx_posE intro!: less_imp_le) }
hoelzl@59426
   806
  note * = this
hoelzl@59426
   807
hoelzl@59426
   808
  assume cntbl: "uncountable {x. f x \<noteq> 0}"
hoelzl@59426
   809
  also have "{x. f x \<noteq> 0} = (\<Union>n. {x. 1/Suc n \<le> f x})"
hoelzl@59426
   810
    using * by auto
hoelzl@59426
   811
  finally obtain n where "infinite {x. 1/Suc n \<le> f x}"
hoelzl@59426
   812
    by (meson countableI_type countable_UN uncountable_infinite)
hoelzl@59426
   813
  then obtain C where C: "C \<subseteq> {x. 1/Suc n \<le> f x}" and "countable C" "infinite C"
hoelzl@59426
   814
    by (metis infinite_countable_subset')
hoelzl@59426
   815
hoelzl@59426
   816
  have [measurable]: "C \<in> sets ?P"
wenzelm@61808
   817
    using sets.countable[OF _ \<open>countable C\<close>, of ?P] by (auto simp: sets_Pair)
hoelzl@59426
   818
hoelzl@59426
   819
  have "(\<integral>\<^sup>+x. ereal (1/Suc n) * indicator C x \<partial>?P) \<le> nn_integral ?P f"
hoelzl@59426
   820
    using C by (intro nn_integral_mono) (auto split: split_indicator simp: zero_ereal_def[symmetric])
hoelzl@59426
   821
  moreover have "(\<integral>\<^sup>+x. ereal (1/Suc n) * indicator C x \<partial>?P) = \<infinity>"
wenzelm@61808
   822
    using \<open>infinite C\<close> by (simp add: nn_integral_cmult emeasure_count_space_prod_eq)
hoelzl@59426
   823
  moreover have "(\<integral>\<^sup>+x. ereal (1/Suc n) * indicator C x \<partial>count_space UNIV) \<le> nn_integral (count_space UNIV) f"
hoelzl@59426
   824
    using C by (intro nn_integral_mono) (auto split: split_indicator simp: zero_ereal_def[symmetric])
hoelzl@59426
   825
  moreover have "(\<integral>\<^sup>+x. ereal (1/Suc n) * indicator C x \<partial>count_space UNIV) = \<infinity>"
wenzelm@61808
   826
    using \<open>infinite C\<close> by (simp add: nn_integral_cmult)
hoelzl@59426
   827
  ultimately show ?thesis
hoelzl@59426
   828
    by simp
hoelzl@59426
   829
qed
hoelzl@59426
   830
hoelzl@59426
   831
lemma nn_intergal_count_space_prod_eq:
hoelzl@59426
   832
  "nn_integral (count_space UNIV \<Otimes>\<^sub>M count_space UNIV) f = nn_integral (count_space UNIV) f"
hoelzl@59426
   833
  by (subst (1 2) nn_integral_max_0[symmetric]) (auto intro!: nn_intergal_count_space_prod_eq')
hoelzl@59426
   834
hoelzl@47694
   835
lemma pair_measure_density:
hoelzl@47694
   836
  assumes f: "f \<in> borel_measurable M1" "AE x in M1. 0 \<le> f x"
hoelzl@47694
   837
  assumes g: "g \<in> borel_measurable M2" "AE x in M2. 0 \<le> g x"
hoelzl@50003
   838
  assumes "sigma_finite_measure M2" "sigma_finite_measure (density M2 g)"
wenzelm@53015
   839
  shows "density M1 f \<Otimes>\<^sub>M density M2 g = density (M1 \<Otimes>\<^sub>M M2) (\<lambda>(x,y). f x * g y)" (is "?L = ?R")
hoelzl@47694
   840
proof (rule measure_eqI)
hoelzl@47694
   841
  interpret M2: sigma_finite_measure M2 by fact
hoelzl@47694
   842
  interpret D2: sigma_finite_measure "density M2 g" by fact
hoelzl@47694
   843
hoelzl@47694
   844
  fix A assume A: "A \<in> sets ?L"
wenzelm@53015
   845
  with f g have "(\<integral>\<^sup>+ x. f x * \<integral>\<^sup>+ y. g y * indicator A (x, y) \<partial>M2 \<partial>M1) =
wenzelm@53015
   846
    (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. f x * g y * indicator A (x, y) \<partial>M2 \<partial>M1)"
hoelzl@56996
   847
    by (intro nn_integral_cong_AE)
hoelzl@56996
   848
       (auto simp add: nn_integral_cmult[symmetric] ac_simps)
hoelzl@50003
   849
  with A f g show "emeasure ?L A = emeasure ?R A"
hoelzl@56996
   850
    by (simp add: D2.emeasure_pair_measure emeasure_density nn_integral_density
hoelzl@56996
   851
                  M2.nn_integral_fst[symmetric]
hoelzl@56996
   852
             cong: nn_integral_cong)
hoelzl@47694
   853
qed simp
hoelzl@47694
   854
hoelzl@47694
   855
lemma sigma_finite_measure_distr:
hoelzl@47694
   856
  assumes "sigma_finite_measure (distr M N f)" and f: "f \<in> measurable M N"
hoelzl@47694
   857
  shows "sigma_finite_measure M"
hoelzl@40859
   858
proof -
hoelzl@47694
   859
  interpret sigma_finite_measure "distr M N f" by fact
hoelzl@57447
   860
  from sigma_finite_countable guess A .. note A = this
hoelzl@47694
   861
  show ?thesis
hoelzl@57447
   862
  proof
hoelzl@57447
   863
    show "\<exists>A. countable A \<and> A \<subseteq> sets M \<and> \<Union>A = space M \<and> (\<forall>a\<in>A. emeasure M a \<noteq> \<infinity>)"
hoelzl@57447
   864
      using A f
hoelzl@57447
   865
      by (intro exI[of _ "(\<lambda>a. f -` a \<inter> space M) ` A"])
hoelzl@57447
   866
         (auto simp: emeasure_distr set_eq_iff subset_eq intro: measurable_space)
hoelzl@47694
   867
  qed
hoelzl@38656
   868
qed
hoelzl@38656
   869
hoelzl@47694
   870
lemma pair_measure_distr:
hoelzl@47694
   871
  assumes f: "f \<in> measurable M S" and g: "g \<in> measurable N T"
hoelzl@50003
   872
  assumes "sigma_finite_measure (distr N T g)"
wenzelm@53015
   873
  shows "distr M S f \<Otimes>\<^sub>M distr N T g = distr (M \<Otimes>\<^sub>M N) (S \<Otimes>\<^sub>M T) (\<lambda>(x, y). (f x, g y))" (is "?P = ?D")
hoelzl@47694
   874
proof (rule measure_eqI)
hoelzl@47694
   875
  interpret T: sigma_finite_measure "distr N T g" by fact
hoelzl@47694
   876
  interpret N: sigma_finite_measure N by (rule sigma_finite_measure_distr) fact+
hoelzl@50003
   877
hoelzl@47694
   878
  fix A assume A: "A \<in> sets ?P"
hoelzl@50003
   879
  with f g show "emeasure ?P A = emeasure ?D A"
hoelzl@50003
   880
    by (auto simp add: N.emeasure_pair_measure_alt space_pair_measure emeasure_distr
hoelzl@56996
   881
                       T.emeasure_pair_measure_alt nn_integral_distr
hoelzl@56996
   882
             intro!: nn_integral_cong arg_cong[where f="emeasure N"])
hoelzl@50003
   883
qed simp
hoelzl@39097
   884
hoelzl@50104
   885
lemma pair_measure_eqI:
hoelzl@50104
   886
  assumes "sigma_finite_measure M1" "sigma_finite_measure M2"
wenzelm@53015
   887
  assumes sets: "sets (M1 \<Otimes>\<^sub>M M2) = sets M"
hoelzl@50104
   888
  assumes emeasure: "\<And>A B. A \<in> sets M1 \<Longrightarrow> B \<in> sets M2 \<Longrightarrow> emeasure M1 A * emeasure M2 B = emeasure M (A \<times> B)"
wenzelm@53015
   889
  shows "M1 \<Otimes>\<^sub>M M2 = M"
hoelzl@50104
   890
proof -
hoelzl@50104
   891
  interpret M1: sigma_finite_measure M1 by fact
hoelzl@50104
   892
  interpret M2: sigma_finite_measure M2 by fact
wenzelm@61169
   893
  interpret pair_sigma_finite M1 M2 ..
hoelzl@50104
   894
  from sigma_finite_up_in_pair_measure_generator guess F :: "nat \<Rightarrow> ('a \<times> 'b) set" .. note F = this
hoelzl@50104
   895
  let ?E = "{a \<times> b |a b. a \<in> sets M1 \<and> b \<in> sets M2}"
wenzelm@53015
   896
  let ?P = "M1 \<Otimes>\<^sub>M M2"
hoelzl@50104
   897
  show ?thesis
hoelzl@50104
   898
  proof (rule measure_eqI_generator_eq[OF Int_stable_pair_measure_generator[of M1 M2]])
hoelzl@50104
   899
    show "?E \<subseteq> Pow (space ?P)"
immler@50244
   900
      using sets.space_closed[of M1] sets.space_closed[of M2] by (auto simp: space_pair_measure)
hoelzl@50104
   901
    show "sets ?P = sigma_sets (space ?P) ?E"
hoelzl@50104
   902
      by (simp add: sets_pair_measure space_pair_measure)
hoelzl@50104
   903
    then show "sets M = sigma_sets (space ?P) ?E"
hoelzl@50104
   904
      using sets[symmetric] by simp
hoelzl@50104
   905
  next
hoelzl@50104
   906
    show "range F \<subseteq> ?E" "(\<Union>i. F i) = space ?P" "\<And>i. emeasure ?P (F i) \<noteq> \<infinity>"
hoelzl@50104
   907
      using F by (auto simp: space_pair_measure)
hoelzl@50104
   908
  next
hoelzl@50104
   909
    fix X assume "X \<in> ?E"
hoelzl@50104
   910
    then obtain A B where X[simp]: "X = A \<times> B" and A: "A \<in> sets M1" and B: "B \<in> sets M2" by auto
hoelzl@50104
   911
    then have "emeasure ?P X = emeasure M1 A * emeasure M2 B"
hoelzl@50104
   912
       by (simp add: M2.emeasure_pair_measure_Times)
hoelzl@50104
   913
    also have "\<dots> = emeasure M (A \<times> B)"
hoelzl@50104
   914
      using A B emeasure by auto
hoelzl@50104
   915
    finally show "emeasure ?P X = emeasure M X"
hoelzl@50104
   916
      by simp
hoelzl@50104
   917
  qed
hoelzl@50104
   918
qed
hoelzl@57025
   919
  
hoelzl@57025
   920
lemma sets_pair_countable:
hoelzl@57025
   921
  assumes "countable S1" "countable S2"
hoelzl@57025
   922
  assumes M: "sets M = Pow S1" and N: "sets N = Pow S2"
hoelzl@57025
   923
  shows "sets (M \<Otimes>\<^sub>M N) = Pow (S1 \<times> S2)"
hoelzl@57025
   924
proof auto
hoelzl@57025
   925
  fix x a b assume x: "x \<in> sets (M \<Otimes>\<^sub>M N)" "(a, b) \<in> x"
hoelzl@57025
   926
  from sets.sets_into_space[OF x(1)] x(2)
hoelzl@57025
   927
    sets_eq_imp_space_eq[of N "count_space S2"] sets_eq_imp_space_eq[of M "count_space S1"] M N
hoelzl@57025
   928
  show "a \<in> S1" "b \<in> S2"
hoelzl@57025
   929
    by (auto simp: space_pair_measure)
hoelzl@57025
   930
next
hoelzl@57025
   931
  fix X assume X: "X \<subseteq> S1 \<times> S2"
hoelzl@57025
   932
  then have "countable X"
wenzelm@61808
   933
    by (metis countable_subset \<open>countable S1\<close> \<open>countable S2\<close> countable_SIGMA)
hoelzl@57025
   934
  have "X = (\<Union>(a, b)\<in>X. {a} \<times> {b})" by auto
hoelzl@57025
   935
  also have "\<dots> \<in> sets (M \<Otimes>\<^sub>M N)"
hoelzl@57025
   936
    using X
wenzelm@61808
   937
    by (safe intro!: sets.countable_UN' \<open>countable X\<close> subsetI pair_measureI) (auto simp: M N)
hoelzl@57025
   938
  finally show "X \<in> sets (M \<Otimes>\<^sub>M N)" .
hoelzl@57025
   939
qed
hoelzl@57025
   940
hoelzl@57025
   941
lemma pair_measure_countable:
hoelzl@57025
   942
  assumes "countable S1" "countable S2"
hoelzl@57025
   943
  shows "count_space S1 \<Otimes>\<^sub>M count_space S2 = count_space (S1 \<times> S2)"
hoelzl@57025
   944
proof (rule pair_measure_eqI)
hoelzl@57025
   945
  show "sigma_finite_measure (count_space S1)" "sigma_finite_measure (count_space S2)"
hoelzl@57025
   946
    using assms by (auto intro!: sigma_finite_measure_count_space_countable)
hoelzl@57025
   947
  show "sets (count_space S1 \<Otimes>\<^sub>M count_space S2) = sets (count_space (S1 \<times> S2))"
hoelzl@57025
   948
    by (subst sets_pair_countable[OF assms]) auto
hoelzl@57025
   949
next
hoelzl@57025
   950
  fix A B assume "A \<in> sets (count_space S1)" "B \<in> sets (count_space S2)"
hoelzl@57025
   951
  then show "emeasure (count_space S1) A * emeasure (count_space S2) B = 
hoelzl@57025
   952
    emeasure (count_space (S1 \<times> S2)) (A \<times> B)"
hoelzl@57025
   953
    by (subst (1 2 3) emeasure_count_space) (auto simp: finite_cartesian_product_iff)
hoelzl@57025
   954
qed
hoelzl@50104
   955
Andreas@59489
   956
lemma nn_integral_fst_count_space':
Andreas@59489
   957
  assumes nonneg: "\<And>xy. 0 \<le> f xy"
Andreas@59489
   958
  shows "(\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. f (x, y) \<partial>count_space UNIV \<partial>count_space UNIV) = integral\<^sup>N (count_space UNIV) f"
Andreas@59489
   959
  (is "?lhs = ?rhs")
Andreas@59489
   960
proof(cases)
Andreas@59489
   961
  assume *: "countable {xy. f xy \<noteq> 0}"
Andreas@59489
   962
  let ?A = "fst ` {xy. f xy \<noteq> 0}"
Andreas@59489
   963
  let ?B = "snd ` {xy. f xy \<noteq> 0}"
Andreas@59489
   964
  from * have [simp]: "countable ?A" "countable ?B" by(rule countable_image)+
Andreas@59489
   965
  from nonneg have f_neq_0: "\<And>xy. f xy \<noteq> 0 \<longleftrightarrow> f xy > 0"
Andreas@59489
   966
    by(auto simp add: order.order_iff_strict)
Andreas@59489
   967
  have "?lhs = (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. f (x, y) \<partial>count_space UNIV \<partial>count_space ?A)"
Andreas@59489
   968
    by(rule nn_integral_count_space_eq)
Andreas@59489
   969
      (auto simp add: f_neq_0 nn_integral_0_iff_AE AE_count_space not_le intro: rev_image_eqI)
Andreas@59489
   970
  also have "\<dots> = (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. f (x, y) \<partial>count_space ?B \<partial>count_space ?A)"
Andreas@59489
   971
    by(intro nn_integral_count_space_eq nn_integral_cong)(auto intro: rev_image_eqI)
Andreas@59489
   972
  also have "\<dots> = (\<integral>\<^sup>+ xy. f xy \<partial>count_space (?A \<times> ?B))"
Andreas@59489
   973
    by(subst sigma_finite_measure.nn_integral_fst)
Andreas@59489
   974
      (simp_all add: sigma_finite_measure_count_space_countable pair_measure_countable)
Andreas@59489
   975
  also have "\<dots> = ?rhs"
Andreas@59489
   976
    by(rule nn_integral_count_space_eq)(auto intro: rev_image_eqI)
Andreas@59489
   977
  finally show ?thesis .
Andreas@59489
   978
next
Andreas@59489
   979
  { fix xy assume "f xy \<noteq> 0"
wenzelm@61808
   980
    with \<open>0 \<le> f xy\<close> have "(\<exists>r. 0 < r \<and> f xy = ereal r) \<or> f xy = \<infinity>"
Andreas@59489
   981
      by (cases "f xy") (auto simp: less_le)
Andreas@59489
   982
    then have "\<exists>n. ereal (1 / real (Suc n)) \<le> f xy"
Andreas@59489
   983
      by (auto elim!: nat_approx_posE intro!: less_imp_le) }
Andreas@59489
   984
  note * = this
Andreas@59489
   985
Andreas@59489
   986
  assume cntbl: "uncountable {xy. f xy \<noteq> 0}"
Andreas@59489
   987
  also have "{xy. f xy \<noteq> 0} = (\<Union>n. {xy. 1/Suc n \<le> f xy})"
Andreas@59489
   988
    using * by auto
Andreas@59489
   989
  finally obtain n where "infinite {xy. 1/Suc n \<le> f xy}"
Andreas@59489
   990
    by (meson countableI_type countable_UN uncountable_infinite)
Andreas@59489
   991
  then obtain C where C: "C \<subseteq> {xy. 1/Suc n \<le> f xy}" and "countable C" "infinite C"
Andreas@59489
   992
    by (metis infinite_countable_subset')
Andreas@59489
   993
Andreas@59489
   994
  have "\<infinity> = (\<integral>\<^sup>+ xy. ereal (1 / Suc n) * indicator C xy \<partial>count_space UNIV)"
Andreas@59489
   995
    using \<open>infinite C\<close> by(simp add: nn_integral_cmult)
Andreas@59489
   996
  also have "\<dots> \<le> ?rhs" using C
Andreas@59489
   997
    by(intro nn_integral_mono)(auto split: split_indicator simp add: nonneg)
Andreas@59489
   998
  finally have "?rhs = \<infinity>" by simp
Andreas@59489
   999
  moreover have "?lhs = \<infinity>"
Andreas@59489
  1000
  proof(cases "finite (fst ` C)")
Andreas@59489
  1001
    case True
Andreas@59489
  1002
    then obtain x C' where x: "x \<in> fst ` C" 
Andreas@59489
  1003
      and C': "C' = fst -` {x} \<inter> C"
Andreas@59489
  1004
      and "infinite C'"
Andreas@59489
  1005
      using \<open>infinite C\<close> by(auto elim!: inf_img_fin_domE')
Andreas@59489
  1006
    from x C C' have **: "C' \<subseteq> {xy. 1 / Suc n \<le> f xy}" by auto
Andreas@59489
  1007
Andreas@59489
  1008
    from C' \<open>infinite C'\<close> have "infinite (snd ` C')"
Andreas@59489
  1009
      by(auto dest!: finite_imageD simp add: inj_on_def)
Andreas@59489
  1010
    then have "\<infinity> = (\<integral>\<^sup>+ y. ereal (1 / Suc n) * indicator (snd ` C') y \<partial>count_space UNIV)"
Andreas@59489
  1011
      by(simp add: nn_integral_cmult)
Andreas@59489
  1012
    also have "\<dots> = (\<integral>\<^sup>+ y. ereal (1 / Suc n) * indicator C' (x, y) \<partial>count_space UNIV)"
Andreas@59489
  1013
      by(rule nn_integral_cong)(force split: split_indicator intro: rev_image_eqI simp add: C')
Andreas@59489
  1014
    also have "\<dots> = (\<integral>\<^sup>+ x'. (\<integral>\<^sup>+ y. ereal (1 / Suc n) * indicator C' (x, y) \<partial>count_space UNIV) * indicator {x} x' \<partial>count_space UNIV)"
hoelzl@62083
  1015
      by(simp add: one_ereal_def[symmetric] nn_integral_nonneg max_def)
Andreas@59489
  1016
    also have "\<dots> \<le> (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. ereal (1 / Suc n) * indicator C' (x, y) \<partial>count_space UNIV \<partial>count_space UNIV)"
Andreas@59489
  1017
      by(rule nn_integral_mono)(simp split: split_indicator add: nn_integral_nonneg)
Andreas@59489
  1018
    also have "\<dots> \<le> ?lhs" using **
Andreas@59489
  1019
      by(intro nn_integral_mono)(auto split: split_indicator simp add: nonneg)
Andreas@59489
  1020
    finally show ?thesis by simp
Andreas@59489
  1021
  next
Andreas@59489
  1022
    case False
Andreas@59489
  1023
    def C' \<equiv> "fst ` C"
Andreas@59489
  1024
    have "\<infinity> = \<integral>\<^sup>+ x. ereal (1 / Suc n) * indicator C' x \<partial>count_space UNIV"
Andreas@59489
  1025
      using C'_def False by(simp add: nn_integral_cmult)
Andreas@59489
  1026
    also have "\<dots> = \<integral>\<^sup>+ x. \<integral>\<^sup>+ y. ereal (1 / Suc n) * indicator C' x * indicator {SOME y. (x, y) \<in> C} y \<partial>count_space UNIV \<partial>count_space UNIV"
hoelzl@62083
  1027
      by(auto simp add: one_ereal_def[symmetric] max_def intro: nn_integral_cong)
Andreas@59489
  1028
    also have "\<dots> \<le> \<integral>\<^sup>+ x. \<integral>\<^sup>+ y. ereal (1 / Suc n) * indicator C (x, y) \<partial>count_space UNIV \<partial>count_space UNIV"
Andreas@59489
  1029
      by(intro nn_integral_mono)(auto simp add: C'_def split: split_indicator intro: someI)
Andreas@59489
  1030
    also have "\<dots> \<le> ?lhs" using C
Andreas@59489
  1031
      by(intro nn_integral_mono)(auto split: split_indicator simp add: nonneg)
Andreas@59489
  1032
    finally show ?thesis by simp
Andreas@59489
  1033
  qed
Andreas@59489
  1034
  ultimately show ?thesis by simp
Andreas@59489
  1035
qed
Andreas@59489
  1036
Andreas@59489
  1037
lemma nn_integral_fst_count_space:
Andreas@59489
  1038
  "(\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. f (x, y) \<partial>count_space UNIV \<partial>count_space UNIV) = integral\<^sup>N (count_space UNIV) f"
Andreas@59489
  1039
by(subst (2 3) nn_integral_max_0[symmetric])(rule nn_integral_fst_count_space', simp)
Andreas@59489
  1040
Andreas@59491
  1041
lemma nn_integral_snd_count_space:
Andreas@59491
  1042
  "(\<integral>\<^sup>+ y. \<integral>\<^sup>+ x. f (x, y) \<partial>count_space UNIV \<partial>count_space UNIV) = integral\<^sup>N (count_space UNIV) f"
Andreas@59491
  1043
  (is "?lhs = ?rhs")
Andreas@59491
  1044
proof -
Andreas@59491
  1045
  have "?lhs = (\<integral>\<^sup>+ y. \<integral>\<^sup>+ x. (\<lambda>(y, x). f (x, y)) (y, x) \<partial>count_space UNIV \<partial>count_space UNIV)"
Andreas@59491
  1046
    by(simp)
Andreas@59491
  1047
  also have "\<dots> = \<integral>\<^sup>+ yx. (\<lambda>(y, x). f (x, y)) yx \<partial>count_space UNIV"
Andreas@59491
  1048
    by(rule nn_integral_fst_count_space)
Andreas@59491
  1049
  also have "\<dots> = \<integral>\<^sup>+ xy. f xy \<partial>count_space ((\<lambda>(x, y). (y, x)) ` UNIV)"
Andreas@59491
  1050
    by(subst nn_integral_bij_count_space[OF inj_on_imp_bij_betw, symmetric])
Andreas@59491
  1051
      (simp_all add: inj_on_def split_def)
Andreas@59491
  1052
  also have "\<dots> = ?rhs" by(rule nn_integral_count_space_eq) auto
Andreas@59491
  1053
  finally show ?thesis .
Andreas@59491
  1054
qed
Andreas@59491
  1055
Andreas@60066
  1056
lemma measurable_pair_measure_countable1:
Andreas@60066
  1057
  assumes "countable A"
Andreas@60066
  1058
  and [measurable]: "\<And>x. x \<in> A \<Longrightarrow> (\<lambda>y. f (x, y)) \<in> measurable N K"
Andreas@60066
  1059
  shows "f \<in> measurable (count_space A \<Otimes>\<^sub>M N) K"
Andreas@60066
  1060
using _ _ assms(1)
Andreas@60066
  1061
by(rule measurable_compose_countable'[where f="\<lambda>a b. f (a, snd b)" and g=fst and I=A, simplified])simp_all
Andreas@60066
  1062
wenzelm@61808
  1063
subsection \<open>Product of Borel spaces\<close>
hoelzl@57235
  1064
hoelzl@57235
  1065
lemma borel_Times:
hoelzl@57235
  1066
  fixes A :: "'a::topological_space set" and B :: "'b::topological_space set"
hoelzl@57235
  1067
  assumes A: "A \<in> sets borel" and B: "B \<in> sets borel"
hoelzl@57235
  1068
  shows "A \<times> B \<in> sets borel"
hoelzl@57235
  1069
proof -
hoelzl@57235
  1070
  have "A \<times> B = (A\<times>UNIV) \<inter> (UNIV \<times> B)"
hoelzl@57235
  1071
    by auto
hoelzl@57235
  1072
  moreover
hoelzl@57235
  1073
  { have "A \<in> sigma_sets UNIV {S. open S}" using A by (simp add: sets_borel)
hoelzl@57235
  1074
    then have "A\<times>UNIV \<in> sets borel"
hoelzl@57235
  1075
    proof (induct A)
hoelzl@57235
  1076
      case (Basic S) then show ?case
hoelzl@57235
  1077
        by (auto intro!: borel_open open_Times)
hoelzl@57235
  1078
    next
hoelzl@57235
  1079
      case (Compl A)
hoelzl@57235
  1080
      moreover have *: "(UNIV - A) \<times> UNIV = UNIV - (A \<times> UNIV)"
hoelzl@57235
  1081
        by auto
hoelzl@57235
  1082
      ultimately show ?case
hoelzl@57235
  1083
        unfolding * by auto
hoelzl@57235
  1084
    next
hoelzl@57235
  1085
      case (Union A)
hoelzl@57235
  1086
      moreover have *: "(UNION UNIV A) \<times> UNIV = UNION UNIV (\<lambda>i. A i \<times> UNIV)"
hoelzl@57235
  1087
        by auto
hoelzl@57235
  1088
      ultimately show ?case
hoelzl@57235
  1089
        unfolding * by auto
hoelzl@57235
  1090
    qed simp }
hoelzl@57235
  1091
  moreover
hoelzl@57235
  1092
  { have "B \<in> sigma_sets UNIV {S. open S}" using B by (simp add: sets_borel)
hoelzl@57235
  1093
    then have "UNIV\<times>B \<in> sets borel"
hoelzl@57235
  1094
    proof (induct B)
hoelzl@57235
  1095
      case (Basic S) then show ?case
hoelzl@57235
  1096
        by (auto intro!: borel_open open_Times)
hoelzl@57235
  1097
    next
hoelzl@57235
  1098
      case (Compl B)
hoelzl@57235
  1099
      moreover have *: "UNIV \<times> (UNIV - B) = UNIV - (UNIV \<times> B)"
hoelzl@57235
  1100
        by auto
hoelzl@57235
  1101
      ultimately show ?case
hoelzl@57235
  1102
        unfolding * by auto
hoelzl@57235
  1103
    next
hoelzl@57235
  1104
      case (Union B)
hoelzl@57235
  1105
      moreover have *: "UNIV \<times> (UNION UNIV B) = UNION UNIV (\<lambda>i. UNIV \<times> B i)"
hoelzl@57235
  1106
        by auto
hoelzl@57235
  1107
      ultimately show ?case
hoelzl@57235
  1108
        unfolding * by auto
hoelzl@57235
  1109
    qed simp }
hoelzl@57235
  1110
  ultimately show ?thesis
hoelzl@57235
  1111
    by auto
hoelzl@57235
  1112
qed
hoelzl@57235
  1113
hoelzl@57235
  1114
lemma finite_measure_pair_measure:
hoelzl@57235
  1115
  assumes "finite_measure M" "finite_measure N"
hoelzl@57235
  1116
  shows "finite_measure (N  \<Otimes>\<^sub>M M)"
hoelzl@57235
  1117
proof (rule finite_measureI)
hoelzl@57235
  1118
  interpret M: finite_measure M by fact
hoelzl@57235
  1119
  interpret N: finite_measure N by fact
hoelzl@57235
  1120
  show "emeasure (N  \<Otimes>\<^sub>M M) (space (N  \<Otimes>\<^sub>M M)) \<noteq> \<infinity>"
hoelzl@57235
  1121
    by (auto simp: space_pair_measure M.emeasure_pair_measure_Times)
hoelzl@57235
  1122
qed
hoelzl@57235
  1123
hoelzl@62083
  1124
end