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