src/HOL/Probability/Binary_Product_Measure.thy
author hoelzl
Mon Apr 23 12:14:35 2012 +0200 (2012-04-23)
changeset 47694 05663f75964c
parent 46898 1570b30ee040
child 49776 199d1d5bb17e
permissions -rw-r--r--
reworked Probability theory
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
hoelzl@42146
     5
header {*Binary product measures*}
hoelzl@42067
     6
hoelzl@42146
     7
theory Binary_Product_Measure
hoelzl@38656
     8
imports Lebesgue_Integration
hoelzl@35833
     9
begin
hoelzl@35833
    10
hoelzl@42950
    11
lemma times_eq_iff: "A \<times> B = C \<times> D \<longleftrightarrow> A = C \<and> B = D \<or> ((A = {} \<or> B = {}) \<and> (C = {} \<or> D = {}))"
hoelzl@42950
    12
  by auto
hoelzl@42950
    13
hoelzl@40859
    14
lemma times_Int_times: "A \<times> B \<inter> C \<times> D = (A \<inter> C) \<times> (B \<inter> D)"
hoelzl@40859
    15
  by auto
hoelzl@40859
    16
hoelzl@40859
    17
lemma Pair_vimage_times[simp]: "\<And>A B x. Pair x -` (A \<times> B) = (if x \<in> A then B else {})"
hoelzl@40859
    18
  by auto
hoelzl@40859
    19
hoelzl@40859
    20
lemma rev_Pair_vimage_times[simp]: "\<And>A B y. (\<lambda>x. (x, y)) -` (A \<times> B) = (if y \<in> B then A else {})"
hoelzl@40859
    21
  by auto
hoelzl@40859
    22
hoelzl@40859
    23
lemma case_prod_distrib: "f (case x of (x, y) \<Rightarrow> g x y) = (case x of (x, y) \<Rightarrow> f (g x y))"
hoelzl@40859
    24
  by (cases x) simp
hoelzl@40859
    25
hoelzl@41026
    26
lemma split_beta': "(\<lambda>(x,y). f x y) = (\<lambda>x. f (fst x) (snd x))"
hoelzl@41026
    27
  by (auto simp: fun_eq_iff)
hoelzl@41026
    28
hoelzl@40859
    29
section "Binary products"
hoelzl@40859
    30
hoelzl@41689
    31
definition pair_measure (infixr "\<Otimes>\<^isub>M" 80) where
hoelzl@47694
    32
  "A \<Otimes>\<^isub>M B = measure_of (space A \<times> space B)
hoelzl@47694
    33
      {a \<times> b | a b. a \<in> sets A \<and> b \<in> sets B}
hoelzl@47694
    34
      (\<lambda>X. \<integral>\<^isup>+x. (\<integral>\<^isup>+y. indicator X (x,y) \<partial>B) \<partial>A)"
hoelzl@40859
    35
hoelzl@41689
    36
lemma space_pair_measure:
hoelzl@41689
    37
  "space (A \<Otimes>\<^isub>M B) = space A \<times> space B"
hoelzl@47694
    38
  unfolding pair_measure_def using space_closed[of A] space_closed[of B]
hoelzl@47694
    39
  by (intro space_measure_of) auto
hoelzl@47694
    40
hoelzl@47694
    41
lemma sets_pair_measure:
hoelzl@47694
    42
  "sets (A \<Otimes>\<^isub>M B) = sigma_sets (space A \<times> space B) {a \<times> b | a b. a \<in> sets A \<and> b \<in> sets B}"
hoelzl@47694
    43
  unfolding pair_measure_def using space_closed[of A] space_closed[of B]
hoelzl@47694
    44
  by (intro sets_measure_of) auto
hoelzl@41095
    45
hoelzl@47694
    46
lemma pair_measureI[intro, simp]:
hoelzl@47694
    47
  "x \<in> sets A \<Longrightarrow> y \<in> sets B \<Longrightarrow> x \<times> y \<in> sets (A \<Otimes>\<^isub>M B)"
hoelzl@47694
    48
  by (auto simp: sets_pair_measure)
hoelzl@41095
    49
hoelzl@47694
    50
lemma measurable_pair_measureI:
hoelzl@47694
    51
  assumes 1: "f \<in> space M \<rightarrow> space M1 \<times> space M2"
hoelzl@47694
    52
  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"
hoelzl@47694
    53
  shows "f \<in> measurable M (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
    54
  unfolding pair_measure_def using 1 2
hoelzl@47694
    55
  by (intro measurable_measure_of) (auto dest: sets_into_space)
hoelzl@41689
    56
hoelzl@47694
    57
lemma measurable_fst[intro!, simp]: "fst \<in> measurable (M1 \<Otimes>\<^isub>M M2) M1"
hoelzl@47694
    58
  unfolding measurable_def
hoelzl@47694
    59
proof safe
hoelzl@47694
    60
  fix A assume A: "A \<in> sets M1"
hoelzl@47694
    61
  from this[THEN sets_into_space] have "fst -` A \<inter> space M1 \<times> space M2 = A \<times> space M2" by auto
hoelzl@47694
    62
  with A show "fst -` A \<inter> space (M1 \<Otimes>\<^isub>M M2) \<in> sets (M1 \<Otimes>\<^isub>M M2)" by (simp add: space_pair_measure)
hoelzl@47694
    63
qed (simp add: space_pair_measure)
hoelzl@40859
    64
hoelzl@47694
    65
lemma measurable_snd[intro!, simp]: "snd \<in> measurable (M1 \<Otimes>\<^isub>M M2) M2"
hoelzl@47694
    66
  unfolding measurable_def
hoelzl@47694
    67
proof safe
hoelzl@47694
    68
  fix A assume A: "A \<in> sets M2"
hoelzl@47694
    69
  from this[THEN sets_into_space] have "snd -` A \<inter> space M1 \<times> space M2 = space M1 \<times> A" by auto
hoelzl@47694
    70
  with A show "snd -` A \<inter> space (M1 \<Otimes>\<^isub>M M2) \<in> sets (M1 \<Otimes>\<^isub>M M2)" by (simp add: space_pair_measure)
hoelzl@47694
    71
qed (simp add: space_pair_measure)
hoelzl@47694
    72
hoelzl@47694
    73
lemma measurable_fst': "f \<in> measurable M (N \<Otimes>\<^isub>M P) \<Longrightarrow> (\<lambda>x. fst (f x)) \<in> measurable M N"
hoelzl@47694
    74
  using measurable_comp[OF _ measurable_fst] by (auto simp: comp_def)
hoelzl@47694
    75
hoelzl@47694
    76
lemma measurable_snd': "f \<in> measurable M (N \<Otimes>\<^isub>M P) \<Longrightarrow> (\<lambda>x. snd (f x)) \<in> measurable M P"
hoelzl@47694
    77
    using measurable_comp[OF _ measurable_snd] by (auto simp: comp_def)
hoelzl@40859
    78
hoelzl@47694
    79
lemma measurable_fst'': "f \<in> measurable M N \<Longrightarrow> (\<lambda>x. f (fst x)) \<in> measurable (M \<Otimes>\<^isub>M P) N"
hoelzl@47694
    80
  using measurable_comp[OF measurable_fst _] by (auto simp: comp_def)
hoelzl@47694
    81
hoelzl@47694
    82
lemma measurable_snd'': "f \<in> measurable M N \<Longrightarrow> (\<lambda>x. f (snd x)) \<in> measurable (P \<Otimes>\<^isub>M M) N"
hoelzl@47694
    83
  using measurable_comp[OF measurable_snd _] by (auto simp: comp_def)
hoelzl@47694
    84
hoelzl@47694
    85
lemma measurable_pair_iff:
hoelzl@47694
    86
  "f \<in> measurable M (M1 \<Otimes>\<^isub>M M2) \<longleftrightarrow> (fst \<circ> f) \<in> measurable M M1 \<and> (snd \<circ> f) \<in> measurable M M2"
hoelzl@47694
    87
proof safe
hoelzl@47694
    88
  assume f: "(fst \<circ> f) \<in> measurable M M1" and s: "(snd \<circ> f) \<in> measurable M M2"
hoelzl@47694
    89
  show "f \<in> measurable M (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
    90
  proof (rule measurable_pair_measureI)
hoelzl@47694
    91
    show "f \<in> space M \<rightarrow> space M1 \<times> space M2"
hoelzl@47694
    92
      using f s by (auto simp: mem_Times_iff measurable_def comp_def)
hoelzl@47694
    93
    fix A B assume "A \<in> sets M1" "B \<in> sets M2"
hoelzl@47694
    94
    moreover have "(fst \<circ> f) -` A \<inter> space M \<in> sets M" "(snd \<circ> f) -` B \<inter> space M \<in> sets M"
hoelzl@47694
    95
      using f `A \<in> sets M1` s `B \<in> sets M2` by (auto simp: measurable_sets)
hoelzl@47694
    96
    moreover have "f -` (A \<times> B) \<inter> space M = ((fst \<circ> f) -` A \<inter> space M) \<inter> ((snd \<circ> f) -` B \<inter> space M)"
hoelzl@47694
    97
      by (auto simp: vimage_Times)
hoelzl@47694
    98
    ultimately show "f -` (A \<times> B) \<inter> space M \<in> sets M" by auto
hoelzl@40859
    99
  qed
hoelzl@47694
   100
qed auto
hoelzl@40859
   101
hoelzl@47694
   102
lemma measurable_pair:
hoelzl@47694
   103
  "(fst \<circ> f) \<in> measurable M M1 \<Longrightarrow> (snd \<circ> f) \<in> measurable M M2 \<Longrightarrow> f \<in> measurable M (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   104
  unfolding measurable_pair_iff by simp
hoelzl@40859
   105
hoelzl@47694
   106
lemma measurable_pair_swap': "(\<lambda>(x,y). (y, x)) \<in> measurable (M1 \<Otimes>\<^isub>M M2) (M2 \<Otimes>\<^isub>M M1)"
hoelzl@47694
   107
proof (rule measurable_pair_measureI)
hoelzl@47694
   108
  fix A B assume "A \<in> sets M2" "B \<in> sets M1"
hoelzl@47694
   109
  moreover then have "(\<lambda>(x, y). (y, x)) -` (A \<times> B) \<inter> space (M1 \<Otimes>\<^isub>M M2) = B \<times> A"
hoelzl@47694
   110
    by (auto dest: sets_into_space simp: space_pair_measure)
hoelzl@47694
   111
  ultimately show "(\<lambda>(x, y). (y, x)) -` (A \<times> B) \<inter> space (M1 \<Otimes>\<^isub>M M2) \<in> sets (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   112
    by auto
hoelzl@47694
   113
qed (auto simp add: space_pair_measure)
hoelzl@47694
   114
hoelzl@47694
   115
lemma measurable_pair_swap:
hoelzl@47694
   116
  assumes f: "f \<in> measurable (M1 \<Otimes>\<^isub>M M2) M" shows "(\<lambda>(x,y). f (y, x)) \<in> measurable (M2 \<Otimes>\<^isub>M M1) M"
hoelzl@47694
   117
proof -
hoelzl@47694
   118
  have "(\<lambda>x. f (case x of (x, y) \<Rightarrow> (y, x))) = (\<lambda>(x, y). f (y, x))" by auto
hoelzl@47694
   119
  then show ?thesis
hoelzl@47694
   120
    using measurable_comp[OF measurable_pair_swap' f] by (simp add: comp_def)
hoelzl@40859
   121
qed
hoelzl@40859
   122
hoelzl@47694
   123
lemma measurable_pair_swap_iff:
hoelzl@47694
   124
  "f \<in> measurable (M2 \<Otimes>\<^isub>M M1) M \<longleftrightarrow> (\<lambda>(x,y). f (y,x)) \<in> measurable (M1 \<Otimes>\<^isub>M M2) M"
hoelzl@47694
   125
  using measurable_pair_swap[of "\<lambda>(x,y). f (y, x)"]
hoelzl@47694
   126
  by (auto intro!: measurable_pair_swap)
hoelzl@40859
   127
hoelzl@47694
   128
lemma measurable_Pair1': "x \<in> space M1 \<Longrightarrow> Pair x \<in> measurable M2 (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   129
proof (rule measurable_pair_measureI)
hoelzl@47694
   130
  fix A B assume "A \<in> sets M1" "B \<in> sets M2"
hoelzl@47694
   131
  moreover then have "Pair x -` (A \<times> B) \<inter> space M2 = (if x \<in> A then B else {})"
hoelzl@47694
   132
    by (auto dest: sets_into_space simp: space_pair_measure)
hoelzl@47694
   133
  ultimately show "Pair x -` (A \<times> B) \<inter> space M2 \<in> sets M2"
hoelzl@47694
   134
    by auto
hoelzl@47694
   135
qed (auto simp add: space_pair_measure)
hoelzl@40859
   136
hoelzl@47694
   137
lemma sets_Pair1: assumes A: "A \<in> sets (M1 \<Otimes>\<^isub>M M2)" shows "Pair x -` A \<in> sets M2"
hoelzl@40859
   138
proof -
hoelzl@47694
   139
  have "Pair x -` A = (if x \<in> space M1 then Pair x -` A \<inter> space M2 else {})"
hoelzl@47694
   140
    using A[THEN sets_into_space] by (auto simp: space_pair_measure)
hoelzl@47694
   141
  also have "\<dots> \<in> sets M2"
hoelzl@47694
   142
    using A by (auto simp add: measurable_Pair1' intro!: measurable_sets split: split_if_asm)
hoelzl@47694
   143
  finally show ?thesis .
hoelzl@40859
   144
qed
hoelzl@40859
   145
hoelzl@47694
   146
lemma measurable_Pair2': "y \<in> space M2 \<Longrightarrow> (\<lambda>x. (x, y)) \<in> measurable M1 (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   147
  using measurable_comp[OF measurable_Pair1' measurable_pair_swap', of y M2 M1]
hoelzl@47694
   148
  by (simp add: comp_def)
hoelzl@40859
   149
hoelzl@47694
   150
lemma sets_Pair2: assumes A: "A \<in> sets (M1 \<Otimes>\<^isub>M M2)" shows "(\<lambda>x. (x, y)) -` A \<in> sets M1"
hoelzl@47694
   151
proof -
hoelzl@47694
   152
  have "(\<lambda>x. (x, y)) -` A = (if y \<in> space M2 then (\<lambda>x. (x, y)) -` A \<inter> space M1 else {})"
hoelzl@47694
   153
    using A[THEN sets_into_space] by (auto simp: space_pair_measure)
hoelzl@47694
   154
  also have "\<dots> \<in> sets M1"
hoelzl@47694
   155
    using A by (auto simp add: measurable_Pair2' intro!: measurable_sets split: split_if_asm)
hoelzl@47694
   156
  finally show ?thesis .
hoelzl@40859
   157
qed
hoelzl@40859
   158
hoelzl@47694
   159
lemma measurable_Pair2:
hoelzl@47694
   160
  assumes f: "f \<in> measurable (M1 \<Otimes>\<^isub>M M2) M" and x: "x \<in> space M1"
hoelzl@47694
   161
  shows "(\<lambda>y. f (x, y)) \<in> measurable M2 M"
hoelzl@47694
   162
  using measurable_comp[OF measurable_Pair1' f, OF x]
hoelzl@47694
   163
  by (simp add: comp_def)
hoelzl@47694
   164
  
hoelzl@47694
   165
lemma measurable_Pair1:
hoelzl@47694
   166
  assumes f: "f \<in> measurable (M1 \<Otimes>\<^isub>M M2) M" and y: "y \<in> space M2"
hoelzl@40859
   167
  shows "(\<lambda>x. f (x, y)) \<in> measurable M1 M"
hoelzl@47694
   168
  using measurable_comp[OF measurable_Pair2' f, OF y]
hoelzl@47694
   169
  by (simp add: comp_def)
hoelzl@40859
   170
hoelzl@47694
   171
lemma Int_stable_pair_measure_generator: "Int_stable {a \<times> b | a b. a \<in> sets A \<and> b \<in> sets B}"
hoelzl@40859
   172
  unfolding Int_stable_def
hoelzl@47694
   173
  by safe (auto simp add: times_Int_times)
hoelzl@40859
   174
hoelzl@40859
   175
lemma finite_measure_cut_measurable:
hoelzl@41689
   176
  assumes "sigma_finite_measure M1" "finite_measure M2"
hoelzl@41689
   177
  assumes "Q \<in> sets (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   178
  shows "(\<lambda>x. emeasure M2 (Pair x -` Q)) \<in> borel_measurable M1"
hoelzl@40859
   179
    (is "?s Q \<in> _")
hoelzl@40859
   180
proof -
hoelzl@41689
   181
  interpret M1: sigma_finite_measure M1 by fact
hoelzl@41689
   182
  interpret M2: finite_measure M2 by fact
hoelzl@47694
   183
  let ?\<Omega> = "space M1 \<times> space M2" and ?D = "{A\<in>sets (M1 \<Otimes>\<^isub>M M2). ?s A \<in> borel_measurable M1}"
hoelzl@41689
   184
  note space_pair_measure[simp]
hoelzl@47694
   185
  interpret dynkin_system ?\<Omega> ?D
hoelzl@40859
   186
  proof (intro dynkin_systemI)
hoelzl@47694
   187
    fix A assume "A \<in> ?D" then show "A \<subseteq> ?\<Omega>"
hoelzl@47694
   188
      using sets_into_space[of A "M1 \<Otimes>\<^isub>M M2"] by simp
hoelzl@40859
   189
  next
hoelzl@47694
   190
    from top show "?\<Omega> \<in> ?D"
hoelzl@47694
   191
      by (auto simp add: if_distrib intro!: measurable_If)
hoelzl@40859
   192
  next
hoelzl@47694
   193
    fix A assume "A \<in> ?D"
hoelzl@47694
   194
    with sets_into_space have "\<And>x. emeasure M2 (Pair x -` (?\<Omega> - A)) =
hoelzl@47694
   195
        (if x \<in> space M1 then emeasure M2 (space M2) - ?s A x else 0)"
hoelzl@47694
   196
      by (auto intro!: emeasure_compl simp: vimage_Diff sets_Pair1)
hoelzl@47694
   197
    with `A \<in> ?D` top show "?\<Omega> - A \<in> ?D"
hoelzl@47694
   198
      by (auto intro!: measurable_If)
hoelzl@40859
   199
  next
hoelzl@47694
   200
    fix F :: "nat \<Rightarrow> ('a\<times>'b) set" assume "disjoint_family F" "range F \<subseteq> ?D"
hoelzl@47694
   201
    moreover then have "\<And>x. emeasure M2 (\<Union>i. Pair x -` F i) = (\<Sum>i. ?s (F i) x)"
hoelzl@47694
   202
      by (intro suminf_emeasure[symmetric]) (auto simp: disjoint_family_on_def sets_Pair1)
hoelzl@47694
   203
    ultimately show "(\<Union>i. F i) \<in> ?D"
hoelzl@47694
   204
      by (auto simp: vimage_UN intro!: borel_measurable_psuminf)
hoelzl@40859
   205
  qed
hoelzl@47694
   206
  let ?G = "{a \<times> b | a b. a \<in> sets M1 \<and> b \<in> sets M2}"
hoelzl@47694
   207
  have "sigma_sets ?\<Omega> ?G = ?D"
hoelzl@47694
   208
  proof (rule dynkin_lemma)
hoelzl@47694
   209
    show "?G \<subseteq> ?D"
hoelzl@47694
   210
      by (auto simp: if_distrib Int_def[symmetric] intro!: measurable_If)
hoelzl@47694
   211
  qed (auto simp: sets_pair_measure  Int_stable_pair_measure_generator)
hoelzl@47694
   212
  with `Q \<in> sets (M1 \<Otimes>\<^isub>M M2)` have "Q \<in> ?D"
hoelzl@47694
   213
    by (simp add: sets_pair_measure[symmetric])
hoelzl@40859
   214
  then show "?s Q \<in> borel_measurable M1" by simp
hoelzl@40859
   215
qed
hoelzl@40859
   216
hoelzl@47694
   217
subsection {* Binary products of $\sigma$-finite emeasure spaces *}
hoelzl@40859
   218
hoelzl@47694
   219
locale pair_sigma_finite = M1: sigma_finite_measure M1 + M2: sigma_finite_measure M2
hoelzl@47694
   220
  for M1 :: "'a measure" and M2 :: "'b measure"
hoelzl@40859
   221
hoelzl@47694
   222
lemma sets_pair_measure_cong[cong]:
hoelzl@47694
   223
  "sets M1 = sets M1' \<Longrightarrow> sets M2 = sets M2' \<Longrightarrow> sets (M1 \<Otimes>\<^isub>M M2) = sets (M1' \<Otimes>\<^isub>M M2')"
hoelzl@47694
   224
  unfolding sets_pair_measure by (simp cong: sets_eq_imp_space_eq)
hoelzl@47694
   225
hoelzl@47694
   226
lemma (in pair_sigma_finite) measurable_emeasure_Pair1:
hoelzl@47694
   227
  assumes Q: "Q \<in> sets (M1 \<Otimes>\<^isub>M M2)" shows "(\<lambda>x. emeasure M2 (Pair x -` Q)) \<in> borel_measurable M1" (is "?s Q \<in> _")
hoelzl@40859
   228
proof -
hoelzl@47694
   229
  from M2.sigma_finite_disjoint guess F . note F = this
hoelzl@41981
   230
  then have F_sets: "\<And>i. F i \<in> sets M2" by auto
hoelzl@47694
   231
  have M1: "sigma_finite_measure M1" ..
wenzelm@46731
   232
  let ?C = "\<lambda>x i. F i \<inter> Pair x -` Q"
hoelzl@40859
   233
  { fix i
hoelzl@40859
   234
    have [simp]: "space M1 \<times> F i \<inter> space M1 \<times> space M2 = space M1 \<times> F i"
hoelzl@47694
   235
      using F sets_into_space by auto
hoelzl@47694
   236
    let ?R = "density M2 (indicator (F i))"
hoelzl@47694
   237
    have "(\<lambda>x. emeasure ?R (Pair x -` (space M1 \<times> space ?R \<inter> Q))) \<in> borel_measurable M1"
hoelzl@40859
   238
    proof (intro finite_measure_cut_measurable[OF M1])
hoelzl@47694
   239
      show "finite_measure ?R"
hoelzl@47694
   240
        using F by (intro finite_measureI) (auto simp: emeasure_restricted subset_eq)
hoelzl@47694
   241
      show "(space M1 \<times> space ?R) \<inter> Q \<in> sets (M1 \<Otimes>\<^isub>M ?R)"
hoelzl@47694
   242
        using Q by (simp add: Int)
hoelzl@40859
   243
    qed
hoelzl@47694
   244
    moreover have "\<And>x. emeasure ?R (Pair x -` (space M1 \<times> space ?R \<inter> Q))
hoelzl@47694
   245
        = emeasure M2 (F i \<inter> Pair x -` (space M1 \<times> space ?R \<inter> Q))"
hoelzl@47694
   246
      using Q F_sets by (intro emeasure_restricted) (auto intro: sets_Pair1)
hoelzl@47694
   247
    moreover have "\<And>x. F i \<inter> Pair x -` (space M1 \<times> space ?R \<inter> Q) = ?C x i"
hoelzl@47694
   248
      using sets_into_space[OF Q] by (auto simp: space_pair_measure)
hoelzl@47694
   249
    ultimately have "(\<lambda>x. emeasure M2 (?C x i)) \<in> borel_measurable M1"
hoelzl@40859
   250
      by simp }
hoelzl@40859
   251
  moreover
hoelzl@40859
   252
  { fix x
hoelzl@47694
   253
    have "(\<Sum>i. emeasure M2 (?C x i)) = emeasure M2 (\<Union>i. ?C x i)"
hoelzl@47694
   254
    proof (intro suminf_emeasure)
hoelzl@40859
   255
      show "range (?C x) \<subseteq> sets M2"
hoelzl@47694
   256
        using F `Q \<in> sets (M1 \<Otimes>\<^isub>M M2)` by (auto intro!: sets_Pair1)
hoelzl@40859
   257
      have "disjoint_family F" using F by auto
hoelzl@40859
   258
      show "disjoint_family (?C x)"
hoelzl@40859
   259
        by (rule disjoint_family_on_bisimulation[OF `disjoint_family F`]) auto
hoelzl@40859
   260
    qed
hoelzl@40859
   261
    also have "(\<Union>i. ?C x i) = Pair x -` Q"
hoelzl@47694
   262
      using F sets_into_space[OF `Q \<in> sets (M1 \<Otimes>\<^isub>M M2)`]
hoelzl@41689
   263
      by (auto simp: space_pair_measure)
hoelzl@47694
   264
    finally have "emeasure M2 (Pair x -` Q) = (\<Sum>i. emeasure M2 (?C x i))"
hoelzl@40859
   265
      by simp }
hoelzl@47694
   266
  ultimately show ?thesis using `Q \<in> sets (M1 \<Otimes>\<^isub>M M2)` F_sets
hoelzl@47694
   267
    by auto
hoelzl@40859
   268
qed
hoelzl@40859
   269
hoelzl@47694
   270
lemma (in pair_sigma_finite) measurable_emeasure_Pair2:
hoelzl@47694
   271
  assumes Q: "Q \<in> sets (M1 \<Otimes>\<^isub>M M2)" shows "(\<lambda>y. emeasure M1 ((\<lambda>x. (x, y)) -` Q)) \<in> borel_measurable M2"
hoelzl@40859
   272
proof -
hoelzl@41689
   273
  interpret Q: pair_sigma_finite M2 M1 by default
hoelzl@47694
   274
  have "(\<lambda>(x, y). (y, x)) -` Q \<inter> space (M2 \<Otimes>\<^isub>M M1) \<in> sets (M2 \<Otimes>\<^isub>M M1)"
hoelzl@47694
   275
    using Q measurable_pair_swap' by (auto intro: measurable_sets)
hoelzl@47694
   276
  note Q.measurable_emeasure_Pair1[OF this]
hoelzl@47694
   277
  moreover have "\<And>y. Pair y -` ((\<lambda>(x, y). (y, x)) -` Q \<inter> space (M2 \<Otimes>\<^isub>M M1)) = (\<lambda>x. (x, y)) -` Q"
hoelzl@47694
   278
    using Q[THEN sets_into_space] by (auto simp: space_pair_measure)
hoelzl@47694
   279
  ultimately show ?thesis by simp
hoelzl@39088
   280
qed
hoelzl@39088
   281
hoelzl@47694
   282
lemma (in pair_sigma_finite) emeasure_pair_measure:
hoelzl@47694
   283
  assumes "X \<in> sets (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   284
  shows "emeasure (M1 \<Otimes>\<^isub>M M2) X = (\<integral>\<^isup>+ x. \<integral>\<^isup>+ y. indicator X (x, y) \<partial>M2 \<partial>M1)" (is "_ = ?\<mu> X")
hoelzl@47694
   285
proof (rule emeasure_measure_of[OF pair_measure_def])
hoelzl@47694
   286
  show "positive (sets (M1 \<Otimes>\<^isub>M M2)) ?\<mu>"
hoelzl@47694
   287
    by (auto simp: positive_def positive_integral_positive)
hoelzl@47694
   288
  have eq[simp]: "\<And>A x y. indicator A (x, y) = indicator (Pair x -` A) y"
hoelzl@47694
   289
    by (auto simp: indicator_def)
hoelzl@47694
   290
  show "countably_additive (sets (M1 \<Otimes>\<^isub>M M2)) ?\<mu>"
hoelzl@47694
   291
  proof (rule countably_additiveI)
hoelzl@47694
   292
    fix F :: "nat \<Rightarrow> ('a \<times> 'b) set" assume F: "range F \<subseteq> sets (M1 \<Otimes>\<^isub>M M2)" "disjoint_family F"
hoelzl@47694
   293
    from F have *: "\<And>i. F i \<in> sets (M1 \<Otimes>\<^isub>M M2)" "(\<Union>i. F i) \<in> sets (M1 \<Otimes>\<^isub>M M2)" by auto
hoelzl@47694
   294
    moreover from F have "\<And>i. (\<lambda>x. emeasure M2 (Pair x -` F i)) \<in> borel_measurable M1"
hoelzl@47694
   295
      by (intro measurable_emeasure_Pair1) auto
hoelzl@47694
   296
    moreover have "\<And>x. disjoint_family (\<lambda>i. Pair x -` F i)"
hoelzl@47694
   297
      by (intro disjoint_family_on_bisimulation[OF F(2)]) auto
hoelzl@47694
   298
    moreover have "\<And>x. range (\<lambda>i. Pair x -` F i) \<subseteq> sets M2"
hoelzl@47694
   299
      using F by (auto simp: sets_Pair1)
hoelzl@47694
   300
    ultimately show "(\<Sum>n. ?\<mu> (F n)) = ?\<mu> (\<Union>i. F i)"
hoelzl@47694
   301
      by (auto simp add: vimage_UN positive_integral_suminf[symmetric] suminf_emeasure subset_eq emeasure_nonneg sets_Pair1
hoelzl@47694
   302
               intro!: positive_integral_cong positive_integral_indicator[symmetric])
hoelzl@47694
   303
  qed
hoelzl@47694
   304
  show "{a \<times> b |a b. a \<in> sets M1 \<and> b \<in> sets M2} \<subseteq> Pow (space M1 \<times> space M2)"
hoelzl@47694
   305
    using space_closed[of M1] space_closed[of M2] by auto
hoelzl@47694
   306
qed fact
hoelzl@47694
   307
hoelzl@47694
   308
lemma (in pair_sigma_finite) emeasure_pair_measure_alt:
hoelzl@47694
   309
  assumes X: "X \<in> sets (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   310
  shows "emeasure (M1  \<Otimes>\<^isub>M M2) X = (\<integral>\<^isup>+x. emeasure M2 (Pair x -` X) \<partial>M1)"
hoelzl@47694
   311
proof -
hoelzl@47694
   312
  have [simp]: "\<And>x y. indicator X (x, y) = indicator (Pair x -` X) y"
hoelzl@47694
   313
    by (auto simp: indicator_def)
hoelzl@47694
   314
  show ?thesis
hoelzl@47694
   315
    using X by (auto intro!: positive_integral_cong simp: emeasure_pair_measure sets_Pair1)
hoelzl@40859
   316
qed
hoelzl@40859
   317
hoelzl@47694
   318
lemma (in pair_sigma_finite) emeasure_pair_measure_Times:
hoelzl@47694
   319
  assumes A: "A \<in> sets M1" and B: "B \<in> sets M2"
hoelzl@47694
   320
  shows "emeasure (M1 \<Otimes>\<^isub>M M2) (A \<times> B) = emeasure M1 A * emeasure M2 B"
hoelzl@40859
   321
proof -
hoelzl@47694
   322
  have "emeasure (M1 \<Otimes>\<^isub>M M2) (A \<times> B) = (\<integral>\<^isup>+x. emeasure M2 B * indicator A x \<partial>M1)"
hoelzl@47694
   323
    using A B by (auto intro!: positive_integral_cong simp: emeasure_pair_measure_alt)
hoelzl@47694
   324
  also have "\<dots> = emeasure M2 B * emeasure M1 A"
hoelzl@47694
   325
    using A by (simp add: emeasure_nonneg positive_integral_cmult_indicator)
hoelzl@47694
   326
  finally show ?thesis
hoelzl@47694
   327
    by (simp add: ac_simps)
hoelzl@40859
   328
qed
hoelzl@40859
   329
hoelzl@41689
   330
lemma (in pair_sigma_finite) sigma_finite_up_in_pair_measure_generator:
hoelzl@47694
   331
  defines "E \<equiv> {A \<times> B | A B. A \<in> sets M1 \<and> B \<in> sets M2}"
hoelzl@47694
   332
  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>
hoelzl@47694
   333
    (\<forall>i. emeasure (M1 \<Otimes>\<^isub>M M2) (F i) \<noteq> \<infinity>)"
hoelzl@40859
   334
proof -
hoelzl@47694
   335
  from M1.sigma_finite_incseq guess F1 . note F1 = this
hoelzl@47694
   336
  from M2.sigma_finite_incseq guess F2 . note F2 = this
hoelzl@47694
   337
  from F1 F2 have space: "space M1 = (\<Union>i. F1 i)" "space M2 = (\<Union>i. F2 i)" by auto
hoelzl@40859
   338
  let ?F = "\<lambda>i. F1 i \<times> F2 i"
hoelzl@47694
   339
  show ?thesis
hoelzl@40859
   340
  proof (intro exI[of _ ?F] conjI allI)
hoelzl@47694
   341
    show "range ?F \<subseteq> E" using F1 F2 by (auto simp: E_def) (metis range_subsetD)
hoelzl@40859
   342
  next
hoelzl@40859
   343
    have "space M1 \<times> space M2 \<subseteq> (\<Union>i. ?F i)"
hoelzl@40859
   344
    proof (intro subsetI)
hoelzl@40859
   345
      fix x assume "x \<in> space M1 \<times> space M2"
hoelzl@40859
   346
      then obtain i j where "fst x \<in> F1 i" "snd x \<in> F2 j"
hoelzl@40859
   347
        by (auto simp: space)
hoelzl@40859
   348
      then have "fst x \<in> F1 (max i j)" "snd x \<in> F2 (max j i)"
hoelzl@41981
   349
        using `incseq F1` `incseq F2` unfolding incseq_def
hoelzl@41981
   350
        by (force split: split_max)+
hoelzl@40859
   351
      then have "(fst x, snd x) \<in> F1 (max i j) \<times> F2 (max i j)"
hoelzl@40859
   352
        by (intro SigmaI) (auto simp add: min_max.sup_commute)
hoelzl@40859
   353
      then show "x \<in> (\<Union>i. ?F i)" by auto
hoelzl@40859
   354
    qed
hoelzl@47694
   355
    then show "(\<Union>i. ?F i) = space M1 \<times> space M2"
hoelzl@47694
   356
      using space by (auto simp: space)
hoelzl@40859
   357
  next
hoelzl@41981
   358
    fix i show "incseq (\<lambda>i. F1 i \<times> F2 i)"
hoelzl@41981
   359
      using `incseq F1` `incseq F2` unfolding incseq_Suc_iff by auto
hoelzl@40859
   360
  next
hoelzl@40859
   361
    fix i
hoelzl@40859
   362
    from F1 F2 have "F1 i \<in> sets M1" "F2 i \<in> sets M2" by auto
hoelzl@47694
   363
    with F1 F2 emeasure_nonneg[of M1 "F1 i"] emeasure_nonneg[of M2 "F2 i"]
hoelzl@47694
   364
    show "emeasure (M1 \<Otimes>\<^isub>M M2) (F1 i \<times> F2 i) \<noteq> \<infinity>"
hoelzl@47694
   365
      by (auto simp add: emeasure_pair_measure_Times)
hoelzl@47694
   366
  qed
hoelzl@47694
   367
qed
hoelzl@47694
   368
hoelzl@47694
   369
sublocale pair_sigma_finite \<subseteq> sigma_finite_measure "M1 \<Otimes>\<^isub>M M2"
hoelzl@47694
   370
proof
hoelzl@47694
   371
  from sigma_finite_up_in_pair_measure_generator guess F :: "nat \<Rightarrow> ('a \<times> 'b) set" .. note F = this
hoelzl@47694
   372
  show "\<exists>F::nat \<Rightarrow> ('a \<times> 'b) set. range F \<subseteq> sets (M1 \<Otimes>\<^isub>M M2) \<and> (\<Union>i. F i) = space (M1 \<Otimes>\<^isub>M M2) \<and> (\<forall>i. emeasure (M1 \<Otimes>\<^isub>M M2) (F i) \<noteq> \<infinity>)"
hoelzl@47694
   373
  proof (rule exI[of _ F], intro conjI)
hoelzl@47694
   374
    show "range F \<subseteq> sets (M1 \<Otimes>\<^isub>M M2)" using F by (auto simp: pair_measure_def)
hoelzl@47694
   375
    show "(\<Union>i. F i) = space (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   376
      using F by (auto simp: space_pair_measure)
hoelzl@47694
   377
    show "\<forall>i. emeasure (M1 \<Otimes>\<^isub>M M2) (F i) \<noteq> \<infinity>" using F by auto
hoelzl@40859
   378
  qed
hoelzl@40859
   379
qed
hoelzl@40859
   380
hoelzl@47694
   381
lemma sigma_finite_pair_measure:
hoelzl@47694
   382
  assumes A: "sigma_finite_measure A" and B: "sigma_finite_measure B"
hoelzl@47694
   383
  shows "sigma_finite_measure (A \<Otimes>\<^isub>M B)"
hoelzl@47694
   384
proof -
hoelzl@47694
   385
  interpret A: sigma_finite_measure A by fact
hoelzl@47694
   386
  interpret B: sigma_finite_measure B by fact
hoelzl@47694
   387
  interpret AB: pair_sigma_finite A  B ..
hoelzl@47694
   388
  show ?thesis ..
hoelzl@40859
   389
qed
hoelzl@39088
   390
hoelzl@47694
   391
lemma sets_pair_swap:
hoelzl@47694
   392
  assumes "A \<in> sets (M1 \<Otimes>\<^isub>M M2)"
hoelzl@41689
   393
  shows "(\<lambda>(x, y). (y, x)) -` A \<inter> space (M2 \<Otimes>\<^isub>M M1) \<in> sets (M2 \<Otimes>\<^isub>M M1)"
hoelzl@47694
   394
  using measurable_pair_swap' assms by (rule measurable_sets)
hoelzl@41661
   395
hoelzl@47694
   396
lemma (in pair_sigma_finite) distr_pair_swap:
hoelzl@47694
   397
  "M1 \<Otimes>\<^isub>M M2 = distr (M2 \<Otimes>\<^isub>M M1) (M1 \<Otimes>\<^isub>M M2) (\<lambda>(x, y). (y, x))" (is "?P = ?D")
hoelzl@40859
   398
proof -
hoelzl@41706
   399
  interpret Q: pair_sigma_finite M2 M1 by default
hoelzl@41689
   400
  from sigma_finite_up_in_pair_measure_generator guess F :: "nat \<Rightarrow> ('a \<times> 'b) set" .. note F = this
hoelzl@47694
   401
  let ?E = "{a \<times> b |a b. a \<in> sets M1 \<and> b \<in> sets M2}"
hoelzl@47694
   402
  show ?thesis
hoelzl@47694
   403
  proof (rule measure_eqI_generator_eq[OF Int_stable_pair_measure_generator[of M1 M2]])
hoelzl@47694
   404
    show "?E \<subseteq> Pow (space ?P)"
hoelzl@47694
   405
      using space_closed[of M1] space_closed[of M2] by (auto simp: space_pair_measure)
hoelzl@47694
   406
    show "sets ?P = sigma_sets (space ?P) ?E"
hoelzl@47694
   407
      by (simp add: sets_pair_measure space_pair_measure)
hoelzl@47694
   408
    then show "sets ?D = sigma_sets (space ?P) ?E"
hoelzl@47694
   409
      by simp
hoelzl@47694
   410
  next
hoelzl@47694
   411
    show "range F \<subseteq> ?E" "incseq F" "(\<Union>i. F i) = space ?P" "\<And>i. emeasure ?P (F i) \<noteq> \<infinity>"
hoelzl@47694
   412
      using F by (auto simp: space_pair_measure)
hoelzl@47694
   413
  next
hoelzl@47694
   414
    fix X assume "X \<in> ?E"
hoelzl@47694
   415
    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@47694
   416
    have "(\<lambda>(y, x). (x, y)) -` X \<inter> space (M2 \<Otimes>\<^isub>M M1) = B \<times> A"
hoelzl@47694
   417
      using sets_into_space[OF A] sets_into_space[OF B] by (auto simp: space_pair_measure)
hoelzl@47694
   418
    with A B show "emeasure (M1 \<Otimes>\<^isub>M M2) X = emeasure ?D X"
hoelzl@47694
   419
      by (simp add: emeasure_pair_measure_Times Q.emeasure_pair_measure_Times emeasure_distr
hoelzl@47694
   420
                    measurable_pair_swap' ac_simps)
hoelzl@41689
   421
  qed
hoelzl@41689
   422
qed
hoelzl@41689
   423
hoelzl@47694
   424
lemma (in pair_sigma_finite) emeasure_pair_measure_alt2:
hoelzl@47694
   425
  assumes A: "A \<in> sets (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   426
  shows "emeasure (M1 \<Otimes>\<^isub>M M2) A = (\<integral>\<^isup>+y. emeasure M1 ((\<lambda>x. (x, y)) -` A) \<partial>M2)"
hoelzl@47694
   427
    (is "_ = ?\<nu> A")
hoelzl@41689
   428
proof -
hoelzl@47694
   429
  interpret Q: pair_sigma_finite M2 M1 by default
hoelzl@47694
   430
  have [simp]: "\<And>y. (Pair y -` ((\<lambda>(x, y). (y, x)) -` A \<inter> space (M2 \<Otimes>\<^isub>M M1))) = (\<lambda>x. (x, y)) -` A"
hoelzl@47694
   431
    using sets_into_space[OF A] by (auto simp: space_pair_measure)
hoelzl@47694
   432
  show ?thesis using A
hoelzl@47694
   433
    by (subst distr_pair_swap)
hoelzl@47694
   434
       (simp_all del: vimage_Int add: measurable_sets[OF measurable_pair_swap']
hoelzl@47694
   435
                 Q.emeasure_pair_measure_alt emeasure_distr[OF measurable_pair_swap' A])
hoelzl@40859
   436
qed
hoelzl@40859
   437
hoelzl@40859
   438
section "Fubinis theorem"
hoelzl@40859
   439
hoelzl@40859
   440
lemma (in pair_sigma_finite) simple_function_cut:
hoelzl@47694
   441
  assumes f: "simple_function (M1 \<Otimes>\<^isub>M M2) f" "\<And>x. 0 \<le> f x"
hoelzl@41689
   442
  shows "(\<lambda>x. \<integral>\<^isup>+y. f (x, y) \<partial>M2) \<in> borel_measurable M1"
hoelzl@47694
   443
    and "(\<integral>\<^isup>+ x. (\<integral>\<^isup>+ y. f (x, y) \<partial>M2) \<partial>M1) = integral\<^isup>P (M1 \<Otimes>\<^isub>M M2) f"
hoelzl@40859
   444
proof -
hoelzl@47694
   445
  have f_borel: "f \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)"
hoelzl@41981
   446
    using f(1) by (rule borel_measurable_simple_function)
hoelzl@47694
   447
  let ?F = "\<lambda>z. f -` {z} \<inter> space (M1 \<Otimes>\<^isub>M M2)"
wenzelm@46731
   448
  let ?F' = "\<lambda>x z. Pair x -` ?F z"
hoelzl@40859
   449
  { fix x assume "x \<in> space M1"
hoelzl@40859
   450
    have [simp]: "\<And>z y. indicator (?F z) (x, y) = indicator (?F' x z) y"
hoelzl@40859
   451
      by (auto simp: indicator_def)
hoelzl@47694
   452
    have "\<And>y. y \<in> space M2 \<Longrightarrow> (x, y) \<in> space (M1 \<Otimes>\<^isub>M M2)" using `x \<in> space M1`
hoelzl@41689
   453
      by (simp add: space_pair_measure)
hoelzl@40859
   454
    moreover have "\<And>x z. ?F' x z \<in> sets M2" using f_borel
hoelzl@47694
   455
      by (rule sets_Pair1[OF measurable_sets]) auto
hoelzl@41689
   456
    ultimately have "simple_function M2 (\<lambda> y. f (x, y))"
hoelzl@47694
   457
      apply (rule_tac simple_function_cong[THEN iffD2, OF _])
hoelzl@41981
   458
      apply (rule simple_function_indicator_representation[OF f(1)])
hoelzl@47694
   459
      using `x \<in> space M1` by auto }
hoelzl@40859
   460
  note M2_sf = this
hoelzl@40859
   461
  { fix x assume x: "x \<in> space M1"
hoelzl@47694
   462
    then have "(\<integral>\<^isup>+y. f (x, y) \<partial>M2) = (\<Sum>z\<in>f ` space (M1 \<Otimes>\<^isub>M M2). z * emeasure M2 (?F' x z))"
hoelzl@47694
   463
      unfolding positive_integral_eq_simple_integral[OF M2_sf[OF x] f(2)]
hoelzl@41689
   464
      unfolding simple_integral_def
hoelzl@40859
   465
    proof (safe intro!: setsum_mono_zero_cong_left)
hoelzl@47694
   466
      from f(1) show "finite (f ` space (M1 \<Otimes>\<^isub>M M2))" by (rule simple_functionD)
hoelzl@40859
   467
    next
hoelzl@47694
   468
      fix y assume "y \<in> space M2" then show "f (x, y) \<in> f ` space (M1 \<Otimes>\<^isub>M M2)"
hoelzl@41689
   469
        using `x \<in> space M1` by (auto simp: space_pair_measure)
hoelzl@40859
   470
    next
hoelzl@47694
   471
      fix x' y assume "(x', y) \<in> space (M1 \<Otimes>\<^isub>M M2)"
hoelzl@40859
   472
        "f (x', y) \<notin> (\<lambda>y. f (x, y)) ` space M2"
hoelzl@40859
   473
      then have *: "?F' x (f (x', y)) = {}"
hoelzl@41689
   474
        by (force simp: space_pair_measure)
hoelzl@47694
   475
      show  "f (x', y) * emeasure M2 (?F' x (f (x', y))) = 0"
hoelzl@40859
   476
        unfolding * by simp
hoelzl@40859
   477
    qed (simp add: vimage_compose[symmetric] comp_def
hoelzl@41689
   478
                   space_pair_measure) }
hoelzl@40859
   479
  note eq = this
hoelzl@47694
   480
  moreover have "\<And>z. ?F z \<in> sets (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   481
    by (auto intro!: f_borel borel_measurable_vimage)
hoelzl@47694
   482
  moreover then have "\<And>z. (\<lambda>x. emeasure M2 (?F' x z)) \<in> borel_measurable M1"
hoelzl@47694
   483
    by (auto intro!: measurable_emeasure_Pair1 simp del: vimage_Int)
hoelzl@47694
   484
  moreover have *: "\<And>i x. 0 \<le> emeasure M2 (Pair x -` (f -` {i} \<inter> space (M1 \<Otimes>\<^isub>M M2)))"
hoelzl@47694
   485
    using f(1)[THEN simple_functionD(2)] f(2) by (intro emeasure_nonneg)
hoelzl@47694
   486
  moreover { fix i assume "i \<in> f`space (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   487
    with * have "\<And>x. 0 \<le> i * emeasure M2 (Pair x -` (f -` {i} \<inter> space (M1 \<Otimes>\<^isub>M M2)))"
hoelzl@41981
   488
      using f(2) by auto }
hoelzl@40859
   489
  ultimately
hoelzl@41689
   490
  show "(\<lambda>x. \<integral>\<^isup>+y. f (x, y) \<partial>M2) \<in> borel_measurable M1"
hoelzl@47694
   491
    and "(\<integral>\<^isup>+ x. (\<integral>\<^isup>+ y. f (x, y) \<partial>M2) \<partial>M1) = integral\<^isup>P (M1 \<Otimes>\<^isub>M M2) f" using f(2)
hoelzl@47694
   492
    by (auto simp del: vimage_Int cong: measurable_cong intro!: setsum_cong
hoelzl@47694
   493
             simp add: positive_integral_setsum simple_integral_def
hoelzl@47694
   494
                       positive_integral_cmult
hoelzl@47694
   495
                       positive_integral_cong[OF eq]
hoelzl@40859
   496
                       positive_integral_eq_simple_integral[OF f]
hoelzl@47694
   497
                       emeasure_pair_measure_alt[symmetric])
hoelzl@40859
   498
qed
hoelzl@40859
   499
hoelzl@40859
   500
lemma (in pair_sigma_finite) positive_integral_fst_measurable:
hoelzl@47694
   501
  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)"
hoelzl@41689
   502
  shows "(\<lambda>x. \<integral>\<^isup>+ y. f (x, y) \<partial>M2) \<in> borel_measurable M1"
hoelzl@40859
   503
      (is "?C f \<in> borel_measurable M1")
hoelzl@47694
   504
    and "(\<integral>\<^isup>+ x. (\<integral>\<^isup>+ y. f (x, y) \<partial>M2) \<partial>M1) = integral\<^isup>P (M1 \<Otimes>\<^isub>M M2) f"
hoelzl@40859
   505
proof -
hoelzl@41981
   506
  from borel_measurable_implies_simple_function_sequence'[OF f] guess F . note F = this
hoelzl@47694
   507
  then have F_borel: "\<And>i. F i \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)"
hoelzl@40859
   508
    by (auto intro: borel_measurable_simple_function)
hoelzl@41981
   509
  note sf = simple_function_cut[OF F(1,5)]
hoelzl@41097
   510
  then have "(\<lambda>x. SUP i. ?C (F i) x) \<in> borel_measurable M1"
hoelzl@41097
   511
    using F(1) by auto
hoelzl@40859
   512
  moreover
hoelzl@40859
   513
  { fix x assume "x \<in> space M1"
hoelzl@47694
   514
    from F measurable_Pair2[OF F_borel `x \<in> space M1`]
hoelzl@41981
   515
    have "(\<integral>\<^isup>+y. (SUP i. F i (x, y)) \<partial>M2) = (SUP i. ?C (F i) x)"
hoelzl@47694
   516
      by (intro positive_integral_monotone_convergence_SUP)
hoelzl@41981
   517
         (auto simp: incseq_Suc_iff le_fun_def)
hoelzl@41981
   518
    then have "(SUP i. ?C (F i) x) = ?C f x"
hoelzl@41981
   519
      unfolding F(4) positive_integral_max_0 by simp }
hoelzl@40859
   520
  note SUPR_C = this
hoelzl@40859
   521
  ultimately show "?C f \<in> borel_measurable M1"
hoelzl@41097
   522
    by (simp cong: measurable_cong)
hoelzl@47694
   523
  have "(\<integral>\<^isup>+x. (SUP i. F i x) \<partial>(M1 \<Otimes>\<^isub>M M2)) = (SUP i. integral\<^isup>P (M1 \<Otimes>\<^isub>M M2) (F i))"
hoelzl@41981
   524
    using F_borel F
hoelzl@41981
   525
    by (intro positive_integral_monotone_convergence_SUP) auto
hoelzl@47694
   526
  also have "(SUP i. integral\<^isup>P (M1 \<Otimes>\<^isub>M M2) (F i)) = (SUP i. \<integral>\<^isup>+ x. (\<integral>\<^isup>+ y. F i (x, y) \<partial>M2) \<partial>M1)"
hoelzl@40859
   527
    unfolding sf(2) by simp
hoelzl@41981
   528
  also have "\<dots> = \<integral>\<^isup>+ x. (SUP i. \<integral>\<^isup>+ y. F i (x, y) \<partial>M2) \<partial>M1" using F sf(1)
hoelzl@47694
   529
    by (intro positive_integral_monotone_convergence_SUP[symmetric])
hoelzl@47694
   530
       (auto intro!: positive_integral_mono positive_integral_positive
hoelzl@47694
   531
             simp: incseq_Suc_iff le_fun_def)
hoelzl@41689
   532
  also have "\<dots> = \<integral>\<^isup>+ x. (\<integral>\<^isup>+ y. (SUP i. F i (x, y)) \<partial>M2) \<partial>M1"
hoelzl@41981
   533
    using F_borel F(2,5)
hoelzl@47694
   534
    by (auto intro!: positive_integral_cong positive_integral_monotone_convergence_SUP[symmetric] measurable_Pair2
hoelzl@47694
   535
             simp: incseq_Suc_iff le_fun_def)
hoelzl@47694
   536
  finally show "(\<integral>\<^isup>+ x. (\<integral>\<^isup>+ y. f (x, y) \<partial>M2) \<partial>M1) = integral\<^isup>P (M1 \<Otimes>\<^isub>M M2) f"
hoelzl@41981
   537
    using F by (simp add: positive_integral_max_0)
hoelzl@40859
   538
qed
hoelzl@40859
   539
hoelzl@47694
   540
lemma (in pair_sigma_finite) positive_integral_snd_measurable:
hoelzl@47694
   541
  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   542
  shows "(\<integral>\<^isup>+ y. (\<integral>\<^isup>+ x. f (x, y) \<partial>M1) \<partial>M2) = integral\<^isup>P (M1 \<Otimes>\<^isub>M M2) f"
hoelzl@41661
   543
proof -
hoelzl@41689
   544
  interpret Q: pair_sigma_finite M2 M1 by default
hoelzl@47694
   545
  note measurable_pair_swap[OF f]
hoelzl@40859
   546
  from Q.positive_integral_fst_measurable[OF this]
hoelzl@47694
   547
  have "(\<integral>\<^isup>+ y. (\<integral>\<^isup>+ x. f (x, y) \<partial>M1) \<partial>M2) = (\<integral>\<^isup>+ (x, y). f (y, x) \<partial>(M2 \<Otimes>\<^isub>M M1))"
hoelzl@40859
   548
    by simp
hoelzl@47694
   549
  also have "(\<integral>\<^isup>+ (x, y). f (y, x) \<partial>(M2 \<Otimes>\<^isub>M M1)) = integral\<^isup>P (M1 \<Otimes>\<^isub>M M2) f"
hoelzl@47694
   550
    by (subst distr_pair_swap)
hoelzl@47694
   551
       (auto simp: positive_integral_distr[OF measurable_pair_swap' f] intro!: positive_integral_cong)
hoelzl@40859
   552
  finally show ?thesis .
hoelzl@40859
   553
qed
hoelzl@40859
   554
hoelzl@40859
   555
lemma (in pair_sigma_finite) Fubini:
hoelzl@47694
   556
  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)"
hoelzl@41689
   557
  shows "(\<integral>\<^isup>+ y. (\<integral>\<^isup>+ x. f (x, y) \<partial>M1) \<partial>M2) = (\<integral>\<^isup>+ x. (\<integral>\<^isup>+ y. f (x, y) \<partial>M2) \<partial>M1)"
hoelzl@40859
   558
  unfolding positive_integral_snd_measurable[OF assms]
hoelzl@40859
   559
  unfolding positive_integral_fst_measurable[OF assms] ..
hoelzl@40859
   560
hoelzl@40859
   561
lemma (in pair_sigma_finite) AE_pair:
hoelzl@47694
   562
  assumes "AE x in (M1 \<Otimes>\<^isub>M M2). Q x"
hoelzl@41981
   563
  shows "AE x in M1. (AE y in M2. Q (x, y))"
hoelzl@40859
   564
proof -
hoelzl@47694
   565
  obtain N where N: "N \<in> sets (M1 \<Otimes>\<^isub>M M2)" "emeasure (M1 \<Otimes>\<^isub>M M2) N = 0" "{x\<in>space (M1 \<Otimes>\<^isub>M M2). \<not> Q x} \<subseteq> N"
hoelzl@47694
   566
    using assms unfolding eventually_ae_filter by auto
hoelzl@40859
   567
  show ?thesis
hoelzl@47694
   568
  proof (rule AE_I)
hoelzl@47694
   569
    from N measurable_emeasure_Pair1[OF `N \<in> sets (M1 \<Otimes>\<^isub>M M2)`]
hoelzl@47694
   570
    show "emeasure M1 {x\<in>space M1. emeasure M2 (Pair x -` N) \<noteq> 0} = 0"
hoelzl@47694
   571
      by (auto simp: emeasure_pair_measure_alt positive_integral_0_iff emeasure_nonneg)
hoelzl@47694
   572
    show "{x \<in> space M1. emeasure M2 (Pair x -` N) \<noteq> 0} \<in> sets M1"
hoelzl@47694
   573
      by (intro borel_measurable_ereal_neq_const measurable_emeasure_Pair1 N)
hoelzl@47694
   574
    { fix x assume "x \<in> space M1" "emeasure M2 (Pair x -` N) = 0"
hoelzl@47694
   575
      have "AE y in M2. Q (x, y)"
hoelzl@47694
   576
      proof (rule AE_I)
hoelzl@47694
   577
        show "emeasure M2 (Pair x -` N) = 0" by fact
hoelzl@47694
   578
        show "Pair x -` N \<in> sets M2" using N(1) by (rule sets_Pair1)
hoelzl@40859
   579
        show "{y \<in> space M2. \<not> Q (x, y)} \<subseteq> Pair x -` N"
hoelzl@47694
   580
          using N `x \<in> space M1` unfolding space_pair_measure by auto
hoelzl@40859
   581
      qed }
hoelzl@47694
   582
    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@40859
   583
      by auto
hoelzl@39088
   584
  qed
hoelzl@39088
   585
qed
hoelzl@35833
   586
hoelzl@47694
   587
lemma (in pair_sigma_finite) AE_pair_measure:
hoelzl@47694
   588
  assumes "{x\<in>space (M1 \<Otimes>\<^isub>M M2). P x} \<in> sets (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   589
  assumes ae: "AE x in M1. AE y in M2. P (x, y)"
hoelzl@47694
   590
  shows "AE x in M1 \<Otimes>\<^isub>M M2. P x"
hoelzl@47694
   591
proof (subst AE_iff_measurable[OF _ refl])
hoelzl@47694
   592
  show "{x\<in>space (M1 \<Otimes>\<^isub>M M2). \<not> P x} \<in> sets (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   593
    by (rule sets_Collect) fact
hoelzl@47694
   594
  then have "emeasure (M1 \<Otimes>\<^isub>M M2) {x \<in> space (M1 \<Otimes>\<^isub>M M2). \<not> P x} =
hoelzl@47694
   595
      (\<integral>\<^isup>+ x. \<integral>\<^isup>+ y. indicator {x \<in> space (M1 \<Otimes>\<^isub>M M2). \<not> P x} (x, y) \<partial>M2 \<partial>M1)"
hoelzl@47694
   596
    by (simp add: emeasure_pair_measure)
hoelzl@47694
   597
  also have "\<dots> = (\<integral>\<^isup>+ x. \<integral>\<^isup>+ y. 0 \<partial>M2 \<partial>M1)"
hoelzl@47694
   598
    using ae
hoelzl@47694
   599
    apply (safe intro!: positive_integral_cong_AE)
hoelzl@47694
   600
    apply (intro AE_I2)
hoelzl@47694
   601
    apply (safe intro!: positive_integral_cong_AE)
hoelzl@47694
   602
    apply auto
hoelzl@47694
   603
    done
hoelzl@47694
   604
  finally show "emeasure (M1 \<Otimes>\<^isub>M M2) {x \<in> space (M1 \<Otimes>\<^isub>M M2). \<not> P x} = 0" by simp
hoelzl@47694
   605
qed
hoelzl@47694
   606
hoelzl@47694
   607
lemma (in pair_sigma_finite) AE_pair_iff:
hoelzl@47694
   608
  "{x\<in>space (M1 \<Otimes>\<^isub>M M2). P (fst x) (snd x)} \<in> sets (M1 \<Otimes>\<^isub>M M2) \<Longrightarrow>
hoelzl@47694
   609
    (AE x in M1. AE y in M2. P x y) \<longleftrightarrow> (AE x in (M1 \<Otimes>\<^isub>M M2). P (fst x) (snd x))"
hoelzl@47694
   610
  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@47694
   611
hoelzl@47694
   612
lemma AE_distr_iff:
hoelzl@47694
   613
  assumes f: "f \<in> measurable M N" and P: "{x \<in> space N. P x} \<in> sets N"
hoelzl@47694
   614
  shows "(AE x in distr M N f. P x) \<longleftrightarrow> (AE x in M. P (f x))"
hoelzl@47694
   615
proof (subst (1 2) AE_iff_measurable[OF _ refl])
hoelzl@47694
   616
  from P show "{x \<in> space (distr M N f). \<not> P x} \<in> sets (distr M N f)"
hoelzl@47694
   617
    by (auto intro!: sets_Collect_neg)
hoelzl@47694
   618
  moreover
hoelzl@47694
   619
  have "f -` {x \<in> space N. P x} \<inter> space M = {x \<in> space M. P (f x)}"
hoelzl@47694
   620
    using f by (auto dest: measurable_space)
hoelzl@47694
   621
  then show "{x \<in> space M. \<not> P (f x)} \<in> sets M"
hoelzl@47694
   622
    using measurable_sets[OF f P] by (auto intro!: sets_Collect_neg)
hoelzl@47694
   623
  moreover have "f -` {x\<in>space N. \<not> P x} \<inter> space M = {x \<in> space M. \<not> P (f x)}"
hoelzl@47694
   624
    using f by (auto dest: measurable_space)
hoelzl@47694
   625
  ultimately show "(emeasure (distr M N f) {x \<in> space (distr M N f). \<not> P x} = 0) =
hoelzl@47694
   626
    (emeasure M {x \<in> space M. \<not> P (f x)} = 0)"
hoelzl@47694
   627
    using f by (simp add: emeasure_distr)
hoelzl@47694
   628
qed
hoelzl@47694
   629
hoelzl@47694
   630
lemma (in pair_sigma_finite) AE_commute:
hoelzl@47694
   631
  assumes P: "{x\<in>space (M1 \<Otimes>\<^isub>M M2). P (fst x) (snd x)} \<in> sets (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   632
  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@41026
   633
proof -
hoelzl@47694
   634
  interpret Q: pair_sigma_finite M2 M1 ..
hoelzl@47694
   635
  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@47694
   636
    by auto
hoelzl@47694
   637
  have "{x \<in> space (M2 \<Otimes>\<^isub>M M1). P (snd x) (fst x)} =
hoelzl@47694
   638
    (\<lambda>(x, y). (y, x)) -` {x \<in> space (M1 \<Otimes>\<^isub>M M2). P (fst x) (snd x)} \<inter> space (M2 \<Otimes>\<^isub>M M1)"
hoelzl@47694
   639
    by (auto simp: space_pair_measure)
hoelzl@47694
   640
  also have "\<dots> \<in> sets (M2 \<Otimes>\<^isub>M M1)"
hoelzl@47694
   641
    by (intro sets_pair_swap P)
hoelzl@47694
   642
  finally show ?thesis
hoelzl@47694
   643
    apply (subst AE_pair_iff[OF P])
hoelzl@47694
   644
    apply (subst distr_pair_swap)
hoelzl@47694
   645
    apply (subst AE_distr_iff[OF measurable_pair_swap' P])
hoelzl@47694
   646
    apply (subst Q.AE_pair_iff)
hoelzl@47694
   647
    apply simp_all
hoelzl@47694
   648
    done
hoelzl@41026
   649
qed
hoelzl@41026
   650
hoelzl@41026
   651
lemma (in pair_sigma_finite) integrable_product_swap:
hoelzl@47694
   652
  assumes "integrable (M1 \<Otimes>\<^isub>M M2) f"
hoelzl@41689
   653
  shows "integrable (M2 \<Otimes>\<^isub>M M1) (\<lambda>(x,y). f (y,x))"
hoelzl@41026
   654
proof -
hoelzl@41689
   655
  interpret Q: pair_sigma_finite M2 M1 by default
hoelzl@41661
   656
  have *: "(\<lambda>(x,y). f (y,x)) = (\<lambda>x. f (case x of (x,y)\<Rightarrow>(y,x)))" by (auto simp: fun_eq_iff)
hoelzl@41661
   657
  show ?thesis unfolding *
hoelzl@47694
   658
    by (rule integrable_distr[OF measurable_pair_swap'])
hoelzl@47694
   659
       (simp add: distr_pair_swap[symmetric] assms)
hoelzl@41661
   660
qed
hoelzl@41661
   661
hoelzl@41661
   662
lemma (in pair_sigma_finite) integrable_product_swap_iff:
hoelzl@47694
   663
  "integrable (M2 \<Otimes>\<^isub>M M1) (\<lambda>(x,y). f (y,x)) \<longleftrightarrow> integrable (M1 \<Otimes>\<^isub>M M2) f"
hoelzl@41661
   664
proof -
hoelzl@41689
   665
  interpret Q: pair_sigma_finite M2 M1 by default
hoelzl@41661
   666
  from Q.integrable_product_swap[of "\<lambda>(x,y). f (y,x)"] integrable_product_swap[of f]
hoelzl@41661
   667
  show ?thesis by auto
hoelzl@41026
   668
qed
hoelzl@41026
   669
hoelzl@41026
   670
lemma (in pair_sigma_finite) integral_product_swap:
hoelzl@47694
   671
  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   672
  shows "(\<integral>(x,y). f (y,x) \<partial>(M2 \<Otimes>\<^isub>M M1)) = integral\<^isup>L (M1 \<Otimes>\<^isub>M M2) f"
hoelzl@41026
   673
proof -
hoelzl@41661
   674
  have *: "(\<lambda>(x,y). f (y,x)) = (\<lambda>x. f (case x of (x,y)\<Rightarrow>(y,x)))" by (auto simp: fun_eq_iff)
hoelzl@47694
   675
  show ?thesis unfolding *
hoelzl@47694
   676
    by (simp add: integral_distr[symmetric, OF measurable_pair_swap' f] distr_pair_swap[symmetric])
hoelzl@41026
   677
qed
hoelzl@41026
   678
hoelzl@41026
   679
lemma (in pair_sigma_finite) integrable_fst_measurable:
hoelzl@47694
   680
  assumes f: "integrable (M1 \<Otimes>\<^isub>M M2) f"
hoelzl@47694
   681
  shows "AE x in M1. integrable M2 (\<lambda> y. f (x, y))" (is "?AE")
hoelzl@47694
   682
    and "(\<integral>x. (\<integral>y. f (x, y) \<partial>M2) \<partial>M1) = integral\<^isup>L (M1 \<Otimes>\<^isub>M M2) f" (is "?INT")
hoelzl@41026
   683
proof -
hoelzl@47694
   684
  have f_borel: "f \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   685
    using f by auto
wenzelm@46731
   686
  let ?pf = "\<lambda>x. ereal (f x)" and ?nf = "\<lambda>x. ereal (- f x)"
hoelzl@41026
   687
  have
hoelzl@47694
   688
    borel: "?nf \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)""?pf \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)" and
hoelzl@47694
   689
    int: "integral\<^isup>P (M1 \<Otimes>\<^isub>M M2) ?nf \<noteq> \<infinity>" "integral\<^isup>P (M1 \<Otimes>\<^isub>M M2) ?pf \<noteq> \<infinity>"
hoelzl@41026
   690
    using assms by auto
hoelzl@43920
   691
  have "(\<integral>\<^isup>+x. (\<integral>\<^isup>+y. ereal (f (x, y)) \<partial>M2) \<partial>M1) \<noteq> \<infinity>"
hoelzl@43920
   692
     "(\<integral>\<^isup>+x. (\<integral>\<^isup>+y. ereal (- f (x, y)) \<partial>M2) \<partial>M1) \<noteq> \<infinity>"
hoelzl@41026
   693
    using borel[THEN positive_integral_fst_measurable(1)] int
hoelzl@41026
   694
    unfolding borel[THEN positive_integral_fst_measurable(2)] by simp_all
hoelzl@41026
   695
  with borel[THEN positive_integral_fst_measurable(1)]
hoelzl@43920
   696
  have AE_pos: "AE x in M1. (\<integral>\<^isup>+y. ereal (f (x, y)) \<partial>M2) \<noteq> \<infinity>"
hoelzl@43920
   697
    "AE x in M1. (\<integral>\<^isup>+y. ereal (- f (x, y)) \<partial>M2) \<noteq> \<infinity>"
hoelzl@47694
   698
    by (auto intro!: positive_integral_PInf_AE )
hoelzl@43920
   699
  then have AE: "AE x in M1. \<bar>\<integral>\<^isup>+y. ereal (f (x, y)) \<partial>M2\<bar> \<noteq> \<infinity>"
hoelzl@43920
   700
    "AE x in M1. \<bar>\<integral>\<^isup>+y. ereal (- f (x, y)) \<partial>M2\<bar> \<noteq> \<infinity>"
hoelzl@47694
   701
    by (auto simp: positive_integral_positive)
hoelzl@41981
   702
  from AE_pos show ?AE using assms
hoelzl@47694
   703
    by (simp add: measurable_Pair2[OF f_borel] integrable_def)
hoelzl@43920
   704
  { fix f have "(\<integral>\<^isup>+ x. - \<integral>\<^isup>+ y. ereal (f x y) \<partial>M2 \<partial>M1) = (\<integral>\<^isup>+x. 0 \<partial>M1)"
hoelzl@47694
   705
      using positive_integral_positive
hoelzl@47694
   706
      by (intro positive_integral_cong_pos) (auto simp: ereal_uminus_le_reorder)
hoelzl@43920
   707
    then have "(\<integral>\<^isup>+ x. - \<integral>\<^isup>+ y. ereal (f x y) \<partial>M2 \<partial>M1) = 0" by simp }
hoelzl@41981
   708
  note this[simp]
hoelzl@47694
   709
  { fix f assume borel: "(\<lambda>x. ereal (f x)) \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   710
      and int: "integral\<^isup>P (M1 \<Otimes>\<^isub>M M2) (\<lambda>x. ereal (f x)) \<noteq> \<infinity>"
hoelzl@47694
   711
      and AE: "AE x in M1. (\<integral>\<^isup>+y. ereal (f (x, y)) \<partial>M2) \<noteq> \<infinity>"
hoelzl@43920
   712
    have "integrable M1 (\<lambda>x. real (\<integral>\<^isup>+y. ereal (f (x, y)) \<partial>M2))" (is "integrable M1 ?f")
hoelzl@41705
   713
    proof (intro integrable_def[THEN iffD2] conjI)
hoelzl@41705
   714
      show "?f \<in> borel_measurable M1"
hoelzl@47694
   715
        using borel by (auto intro!: positive_integral_fst_measurable)
hoelzl@43920
   716
      have "(\<integral>\<^isup>+x. ereal (?f x) \<partial>M1) = (\<integral>\<^isup>+x. (\<integral>\<^isup>+y. ereal (f (x, y))  \<partial>M2) \<partial>M1)"
hoelzl@47694
   717
        using AE positive_integral_positive[of M2]
hoelzl@47694
   718
        by (auto intro!: positive_integral_cong_AE simp: ereal_real)
hoelzl@43920
   719
      then show "(\<integral>\<^isup>+x. ereal (?f x) \<partial>M1) \<noteq> \<infinity>"
hoelzl@41705
   720
        using positive_integral_fst_measurable[OF borel] int by simp
hoelzl@43920
   721
      have "(\<integral>\<^isup>+x. ereal (- ?f x) \<partial>M1) = (\<integral>\<^isup>+x. 0 \<partial>M1)"
hoelzl@47694
   722
        by (intro positive_integral_cong_pos)
hoelzl@47694
   723
           (simp add: positive_integral_positive real_of_ereal_pos)
hoelzl@43920
   724
      then show "(\<integral>\<^isup>+x. ereal (- ?f x) \<partial>M1) \<noteq> \<infinity>" by simp
hoelzl@41705
   725
    qed }
hoelzl@41981
   726
  with this[OF borel(1) int(1) AE_pos(2)] this[OF borel(2) int(2) AE_pos(1)]
hoelzl@41705
   727
  show ?INT
hoelzl@47694
   728
    unfolding lebesgue_integral_def[of "M1 \<Otimes>\<^isub>M M2"] lebesgue_integral_def[of M2]
hoelzl@41026
   729
      borel[THEN positive_integral_fst_measurable(2), symmetric]
hoelzl@47694
   730
    using AE[THEN integral_real]
hoelzl@41981
   731
    by simp
hoelzl@41026
   732
qed
hoelzl@41026
   733
hoelzl@41026
   734
lemma (in pair_sigma_finite) integrable_snd_measurable:
hoelzl@47694
   735
  assumes f: "integrable (M1 \<Otimes>\<^isub>M M2) f"
hoelzl@47694
   736
  shows "AE y in M2. integrable M1 (\<lambda>x. f (x, y))" (is "?AE")
hoelzl@47694
   737
    and "(\<integral>y. (\<integral>x. f (x, y) \<partial>M1) \<partial>M2) = integral\<^isup>L (M1 \<Otimes>\<^isub>M M2) f" (is "?INT")
hoelzl@41026
   738
proof -
hoelzl@41689
   739
  interpret Q: pair_sigma_finite M2 M1 by default
hoelzl@47694
   740
  have Q_int: "integrable (M2 \<Otimes>\<^isub>M M1) (\<lambda>(x, y). f (y, x))"
hoelzl@41661
   741
    using f unfolding integrable_product_swap_iff .
hoelzl@41026
   742
  show ?INT
hoelzl@41026
   743
    using Q.integrable_fst_measurable(2)[OF Q_int]
hoelzl@47694
   744
    using integral_product_swap[of f] f by auto
hoelzl@41026
   745
  show ?AE
hoelzl@41026
   746
    using Q.integrable_fst_measurable(1)[OF Q_int]
hoelzl@41026
   747
    by simp
hoelzl@41026
   748
qed
hoelzl@41026
   749
hoelzl@47694
   750
lemma (in pair_sigma_finite) positive_integral_fst_measurable':
hoelzl@47694
   751
  assumes f: "(\<lambda>x. f (fst x) (snd x)) \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   752
  shows "(\<lambda>x. \<integral>\<^isup>+ y. f x y \<partial>M2) \<in> borel_measurable M1"
hoelzl@47694
   753
  using positive_integral_fst_measurable(1)[OF f] by simp
hoelzl@47694
   754
hoelzl@47694
   755
lemma (in pair_sigma_finite) integral_fst_measurable:
hoelzl@47694
   756
  "(\<lambda>x. f (fst x) (snd x)) \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2) \<Longrightarrow> (\<lambda>x. \<integral> y. f x y \<partial>M2) \<in> borel_measurable M1"
hoelzl@47694
   757
  by (auto simp: lebesgue_integral_def intro!: borel_measurable_diff positive_integral_fst_measurable')
hoelzl@47694
   758
hoelzl@47694
   759
lemma (in pair_sigma_finite) positive_integral_snd_measurable':
hoelzl@47694
   760
  assumes f: "(\<lambda>x. f (fst x) (snd x)) \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   761
  shows "(\<lambda>y. \<integral>\<^isup>+ x. f x y \<partial>M1) \<in> borel_measurable M2"
hoelzl@47694
   762
proof -
hoelzl@47694
   763
  interpret Q: pair_sigma_finite M2 M1 ..
hoelzl@47694
   764
  show ?thesis
hoelzl@47694
   765
    using measurable_pair_swap[OF f]
hoelzl@47694
   766
    by (intro Q.positive_integral_fst_measurable') (simp add: split_beta')
hoelzl@47694
   767
qed
hoelzl@47694
   768
hoelzl@47694
   769
lemma (in pair_sigma_finite) integral_snd_measurable:
hoelzl@47694
   770
  "(\<lambda>x. f (fst x) (snd x)) \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2) \<Longrightarrow> (\<lambda>y. \<integral> x. f x y \<partial>M1) \<in> borel_measurable M2"
hoelzl@47694
   771
  by (auto simp: lebesgue_integral_def intro!: borel_measurable_diff positive_integral_snd_measurable')
hoelzl@47694
   772
hoelzl@41026
   773
lemma (in pair_sigma_finite) Fubini_integral:
hoelzl@47694
   774
  assumes f: "integrable (M1 \<Otimes>\<^isub>M M2) f"
hoelzl@41689
   775
  shows "(\<integral>y. (\<integral>x. f (x, y) \<partial>M1) \<partial>M2) = (\<integral>x. (\<integral>y. f (x, y) \<partial>M2) \<partial>M1)"
hoelzl@41026
   776
  unfolding integrable_snd_measurable[OF assms]
hoelzl@41026
   777
  unfolding integrable_fst_measurable[OF assms] ..
hoelzl@41026
   778
hoelzl@47694
   779
section {* Products on counting spaces, densities and distributions *}
hoelzl@40859
   780
hoelzl@41689
   781
lemma sigma_sets_pair_measure_generator_finite:
hoelzl@38656
   782
  assumes "finite A" and "finite B"
hoelzl@47694
   783
  shows "sigma_sets (A \<times> B) { a \<times> b | a b. a \<subseteq> A \<and> b \<subseteq> B} = Pow (A \<times> B)"
hoelzl@40859
   784
  (is "sigma_sets ?prod ?sets = _")
hoelzl@38656
   785
proof safe
hoelzl@38656
   786
  have fin: "finite (A \<times> B)" using assms by (rule finite_cartesian_product)
hoelzl@38656
   787
  fix x assume subset: "x \<subseteq> A \<times> B"
hoelzl@38656
   788
  hence "finite x" using fin by (rule finite_subset)
hoelzl@40859
   789
  from this subset show "x \<in> sigma_sets ?prod ?sets"
hoelzl@38656
   790
  proof (induct x)
hoelzl@38656
   791
    case empty show ?case by (rule sigma_sets.Empty)
hoelzl@38656
   792
  next
hoelzl@38656
   793
    case (insert a x)
hoelzl@47694
   794
    hence "{a} \<in> sigma_sets ?prod ?sets" by auto
hoelzl@38656
   795
    moreover have "x \<in> sigma_sets ?prod ?sets" using insert by auto
hoelzl@38656
   796
    ultimately show ?case unfolding insert_is_Un[of a x] by (rule sigma_sets_Un)
hoelzl@38656
   797
  qed
hoelzl@38656
   798
next
hoelzl@38656
   799
  fix x a b
hoelzl@40859
   800
  assume "x \<in> sigma_sets ?prod ?sets" and "(a, b) \<in> x"
hoelzl@38656
   801
  from sigma_sets_into_sp[OF _ this(1)] this(2)
hoelzl@40859
   802
  show "a \<in> A" and "b \<in> B" by auto
hoelzl@35833
   803
qed
hoelzl@35833
   804
hoelzl@47694
   805
lemma pair_measure_count_space:
hoelzl@47694
   806
  assumes A: "finite A" and B: "finite B"
hoelzl@47694
   807
  shows "count_space A \<Otimes>\<^isub>M count_space B = count_space (A \<times> B)" (is "?P = ?C")
hoelzl@47694
   808
proof (rule measure_eqI)
hoelzl@47694
   809
  interpret A: finite_measure "count_space A" by (rule finite_measure_count_space) fact
hoelzl@47694
   810
  interpret B: finite_measure "count_space B" by (rule finite_measure_count_space) fact
hoelzl@47694
   811
  interpret P: pair_sigma_finite "count_space A" "count_space B" by default
hoelzl@47694
   812
  show eq: "sets ?P = sets ?C"
hoelzl@47694
   813
    by (simp add: sets_pair_measure sigma_sets_pair_measure_generator_finite A B)
hoelzl@47694
   814
  fix X assume X: "X \<in> sets ?P"
hoelzl@47694
   815
  with eq have X_subset: "X \<subseteq> A \<times> B" by simp
hoelzl@47694
   816
  with A B have fin_Pair: "\<And>x. finite (Pair x -` X)"
hoelzl@47694
   817
    by (intro finite_subset[OF _ B]) auto
hoelzl@47694
   818
  have fin_X: "finite X" using X_subset by (rule finite_subset) (auto simp: A B)
hoelzl@47694
   819
  show "emeasure ?P X = emeasure ?C X"
hoelzl@47694
   820
    apply (subst P.emeasure_pair_measure_alt[OF X])
hoelzl@47694
   821
    apply (subst emeasure_count_space)
hoelzl@47694
   822
    using X_subset apply auto []
hoelzl@47694
   823
    apply (simp add: fin_Pair emeasure_count_space X_subset fin_X)
hoelzl@47694
   824
    apply (subst positive_integral_count_space)
hoelzl@47694
   825
    using A apply simp
hoelzl@47694
   826
    apply (simp del: real_of_nat_setsum add: real_of_nat_setsum[symmetric])
hoelzl@47694
   827
    apply (subst card_gt_0_iff)
hoelzl@47694
   828
    apply (simp add: fin_Pair)
hoelzl@47694
   829
    apply (subst card_SigmaI[symmetric])
hoelzl@47694
   830
    using A apply simp
hoelzl@47694
   831
    using fin_Pair apply simp
hoelzl@47694
   832
    using X_subset apply (auto intro!: arg_cong[where f=card])
hoelzl@47694
   833
    done
hoelzl@45777
   834
qed
hoelzl@35833
   835
hoelzl@47694
   836
lemma pair_measure_density:
hoelzl@47694
   837
  assumes f: "f \<in> borel_measurable M1" "AE x in M1. 0 \<le> f x"
hoelzl@47694
   838
  assumes g: "g \<in> borel_measurable M2" "AE x in M2. 0 \<le> g x"
hoelzl@47694
   839
  assumes "sigma_finite_measure M1" "sigma_finite_measure M2"
hoelzl@47694
   840
  assumes "sigma_finite_measure (density M1 f)" "sigma_finite_measure (density M2 g)"
hoelzl@47694
   841
  shows "density M1 f \<Otimes>\<^isub>M density M2 g = density (M1 \<Otimes>\<^isub>M M2) (\<lambda>(x,y). f x * g y)" (is "?L = ?R")
hoelzl@47694
   842
proof (rule measure_eqI)
hoelzl@47694
   843
  interpret M1: sigma_finite_measure M1 by fact
hoelzl@47694
   844
  interpret M2: sigma_finite_measure M2 by fact
hoelzl@47694
   845
  interpret D1: sigma_finite_measure "density M1 f" by fact
hoelzl@47694
   846
  interpret D2: sigma_finite_measure "density M2 g" by fact
hoelzl@47694
   847
  interpret L: pair_sigma_finite "density M1 f" "density M2 g" ..
hoelzl@47694
   848
  interpret R: pair_sigma_finite M1 M2 ..
hoelzl@47694
   849
hoelzl@47694
   850
  fix A assume A: "A \<in> sets ?L"
hoelzl@47694
   851
  then have indicator_eq: "\<And>x y. indicator A (x, y) = indicator (Pair x -` A) y"
hoelzl@47694
   852
   and Pair_A: "\<And>x. Pair x -` A \<in> sets M2"
hoelzl@47694
   853
    by (auto simp: indicator_def sets_Pair1)
hoelzl@47694
   854
  have f_fst: "(\<lambda>p. f (fst p)) \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   855
    using measurable_comp[OF measurable_fst f(1)] by (simp add: comp_def)
hoelzl@47694
   856
  have g_snd: "(\<lambda>p. g (snd p)) \<in> borel_measurable (M1 \<Otimes>\<^isub>M M2)"
hoelzl@47694
   857
    using measurable_comp[OF measurable_snd g(1)] by (simp add: comp_def)
hoelzl@47694
   858
  have "(\<lambda>x. \<integral>\<^isup>+ y. g (snd (x, y)) * indicator A (x, y) \<partial>M2) \<in> borel_measurable M1"
hoelzl@47694
   859
    using g_snd Pair_A A by (intro R.positive_integral_fst_measurable) auto
hoelzl@47694
   860
  then have int_g: "(\<lambda>x. \<integral>\<^isup>+ y. g y * indicator A (x, y) \<partial>M2) \<in> borel_measurable M1"
hoelzl@47694
   861
    by simp
hoelzl@38656
   862
hoelzl@47694
   863
  show "emeasure ?L A = emeasure ?R A"
hoelzl@47694
   864
    apply (subst L.emeasure_pair_measure[OF A])
hoelzl@47694
   865
    apply (subst emeasure_density)
hoelzl@47694
   866
        using f_fst g_snd apply (simp add: split_beta')
hoelzl@47694
   867
      using A apply simp
hoelzl@47694
   868
    apply (subst positive_integral_density[OF g])
hoelzl@47694
   869
      apply (simp add: indicator_eq Pair_A)
hoelzl@47694
   870
    apply (subst positive_integral_density[OF f])
hoelzl@47694
   871
      apply (rule int_g)
hoelzl@47694
   872
    apply (subst R.positive_integral_fst_measurable(2)[symmetric])
hoelzl@47694
   873
      using f g A Pair_A f_fst g_snd
hoelzl@47694
   874
      apply (auto intro!: positive_integral_cong_AE R.measurable_emeasure_Pair1
hoelzl@47694
   875
                  simp: positive_integral_cmult indicator_eq split_beta')
hoelzl@47694
   876
    apply (intro AE_I2 impI)
hoelzl@47694
   877
    apply (subst mult_assoc)
hoelzl@47694
   878
    apply (subst positive_integral_cmult)
hoelzl@47694
   879
          apply auto
hoelzl@47694
   880
    done
hoelzl@47694
   881
qed simp
hoelzl@47694
   882
hoelzl@47694
   883
lemma sigma_finite_measure_distr:
hoelzl@47694
   884
  assumes "sigma_finite_measure (distr M N f)" and f: "f \<in> measurable M N"
hoelzl@47694
   885
  shows "sigma_finite_measure M"
hoelzl@40859
   886
proof -
hoelzl@47694
   887
  interpret sigma_finite_measure "distr M N f" by fact
hoelzl@47694
   888
  from sigma_finite_disjoint guess A . note A = this
hoelzl@47694
   889
  show ?thesis
hoelzl@47694
   890
  proof (unfold_locales, intro conjI exI allI)
hoelzl@47694
   891
    show "range (\<lambda>i. f -` A i \<inter> space M) \<subseteq> sets M"
hoelzl@47694
   892
      using A f by (auto intro!: measurable_sets)
hoelzl@47694
   893
    show "(\<Union>i. f -` A i \<inter> space M) = space M"
hoelzl@47694
   894
      using A(1) A(2)[symmetric] f by (auto simp: measurable_def Pi_def)
hoelzl@47694
   895
    fix i show "emeasure M (f -` A i \<inter> space M) \<noteq> \<infinity>"
hoelzl@47694
   896
      using f A(1,2) A(3)[of i] by (simp add: emeasure_distr subset_eq)
hoelzl@47694
   897
  qed
hoelzl@38656
   898
qed
hoelzl@38656
   899
hoelzl@47694
   900
lemma measurable_cong':
hoelzl@47694
   901
  assumes sets: "sets M = sets M'" "sets N = sets N'"
hoelzl@47694
   902
  shows "measurable M N = measurable M' N'"
hoelzl@47694
   903
  using sets[THEN sets_eq_imp_space_eq] sets by (simp add: measurable_def)
hoelzl@38656
   904
hoelzl@47694
   905
lemma pair_measure_distr:
hoelzl@47694
   906
  assumes f: "f \<in> measurable M S" and g: "g \<in> measurable N T"
hoelzl@47694
   907
  assumes "sigma_finite_measure (distr M S f)" "sigma_finite_measure (distr N T g)"
hoelzl@47694
   908
  shows "distr M S f \<Otimes>\<^isub>M distr N T g = distr (M \<Otimes>\<^isub>M N) (S \<Otimes>\<^isub>M T) (\<lambda>(x, y). (f x, g y))" (is "?P = ?D")
hoelzl@47694
   909
proof (rule measure_eqI)
hoelzl@47694
   910
  show "sets ?P = sets ?D"
hoelzl@47694
   911
    by simp
hoelzl@47694
   912
  interpret S: sigma_finite_measure "distr M S f" by fact
hoelzl@47694
   913
  interpret T: sigma_finite_measure "distr N T g" by fact
hoelzl@47694
   914
  interpret ST: pair_sigma_finite "distr M S f"  "distr N T g" ..
hoelzl@47694
   915
  interpret M: sigma_finite_measure M by (rule sigma_finite_measure_distr) fact+
hoelzl@47694
   916
  interpret N: sigma_finite_measure N by (rule sigma_finite_measure_distr) fact+
hoelzl@47694
   917
  interpret MN: pair_sigma_finite M N ..
hoelzl@47694
   918
  interpret SN: pair_sigma_finite "distr M S f" N ..
hoelzl@47694
   919
  have [simp]: 
hoelzl@47694
   920
    "\<And>f g. fst \<circ> (\<lambda>(x, y). (f x, g y)) = f \<circ> fst" "\<And>f g. snd \<circ> (\<lambda>(x, y). (f x, g y)) = g \<circ> snd"
hoelzl@47694
   921
    by auto
hoelzl@47694
   922
  then have fg: "(\<lambda>(x, y). (f x, g y)) \<in> measurable (M \<Otimes>\<^isub>M N) (S \<Otimes>\<^isub>M T)"
hoelzl@47694
   923
    using measurable_comp[OF measurable_fst f] measurable_comp[OF measurable_snd g]
hoelzl@47694
   924
    by (auto simp: measurable_pair_iff)
hoelzl@47694
   925
  fix A assume A: "A \<in> sets ?P"
hoelzl@47694
   926
  then have "emeasure ?P A = (\<integral>\<^isup>+x. emeasure (distr N T g) (Pair x -` A) \<partial>distr M S f)"
hoelzl@47694
   927
    by (rule ST.emeasure_pair_measure_alt)
hoelzl@47694
   928
  also have "\<dots> = (\<integral>\<^isup>+x. emeasure N (g -` (Pair x -` A) \<inter> space N) \<partial>distr M S f)"
hoelzl@47694
   929
    using g A by (simp add: sets_Pair1 emeasure_distr)
hoelzl@47694
   930
  also have "\<dots> = (\<integral>\<^isup>+x. emeasure N (g -` (Pair (f x) -` A) \<inter> space N) \<partial>M)"
hoelzl@47694
   931
    using f g A ST.measurable_emeasure_Pair1[OF A]
hoelzl@47694
   932
    by (intro positive_integral_distr) (auto simp add: sets_Pair1 emeasure_distr)
hoelzl@47694
   933
  also have "\<dots> = (\<integral>\<^isup>+x. emeasure N (Pair x -` ((\<lambda>(x, y). (f x, g y)) -` A \<inter> space (M \<Otimes>\<^isub>M N))) \<partial>M)"
hoelzl@47694
   934
    by (intro positive_integral_cong arg_cong2[where f=emeasure]) (auto simp: space_pair_measure)
hoelzl@47694
   935
  also have "\<dots> = emeasure (M \<Otimes>\<^isub>M N) ((\<lambda>(x, y). (f x, g y)) -` A \<inter> space (M \<Otimes>\<^isub>M N))"
hoelzl@47694
   936
    using fg by (intro MN.emeasure_pair_measure_alt[symmetric] measurable_sets[OF _ A])
hoelzl@47694
   937
                (auto cong: measurable_cong')
hoelzl@47694
   938
  also have "\<dots> = emeasure ?D A"
hoelzl@47694
   939
    using fg A by (subst emeasure_distr) auto
hoelzl@47694
   940
  finally show "emeasure ?P A = emeasure ?D A" .
hoelzl@45777
   941
qed
hoelzl@39097
   942
hoelzl@40859
   943
end