src/HOL/Probability/Finite_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/Finite_Product_Measure.thy
hoelzl@42067
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42067
     3
*)
hoelzl@42067
     4
hoelzl@42146
     5
header {*Finite product measures*}
hoelzl@42067
     6
hoelzl@42146
     7
theory Finite_Product_Measure
hoelzl@42146
     8
imports Binary_Product_Measure
hoelzl@35833
     9
begin
hoelzl@35833
    10
hoelzl@42146
    11
lemma Pi_iff: "f \<in> Pi I X \<longleftrightarrow> (\<forall>i\<in>I. f i \<in> X i)"
hoelzl@42146
    12
  unfolding Pi_def by auto
hoelzl@41026
    13
hoelzl@40859
    14
abbreviation
hoelzl@40859
    15
  "Pi\<^isub>E A B \<equiv> Pi A B \<inter> extensional A"
hellerar@39094
    16
hoelzl@41689
    17
syntax
hoelzl@41689
    18
  "_PiE"  :: "[pttrn, 'a set, 'b set] => ('a => 'b) set"  ("(3PIE _:_./ _)" 10)
hoelzl@41689
    19
hoelzl@41689
    20
syntax (xsymbols)
hoelzl@41689
    21
  "_PiE" :: "[pttrn, 'a set, 'b set] => ('a => 'b) set"  ("(3\<Pi>\<^isub>E _\<in>_./ _)"   10)
hoelzl@41689
    22
hoelzl@41689
    23
syntax (HTML output)
hoelzl@41689
    24
  "_PiE" :: "[pttrn, 'a set, 'b set] => ('a => 'b) set"  ("(3\<Pi>\<^isub>E _\<in>_./ _)"   10)
hoelzl@41689
    25
hoelzl@41689
    26
translations
hoelzl@41689
    27
  "PIE x:A. B" == "CONST Pi\<^isub>E A (%x. B)"
hoelzl@41689
    28
hoelzl@40859
    29
abbreviation
hoelzl@40859
    30
  funcset_extensional :: "['a set, 'b set] => ('a => 'b) set"
hoelzl@40859
    31
    (infixr "->\<^isub>E" 60) where
hoelzl@40859
    32
  "A ->\<^isub>E B \<equiv> Pi\<^isub>E A (%_. B)"
hoelzl@40859
    33
hoelzl@40859
    34
notation (xsymbols)
hoelzl@40859
    35
  funcset_extensional  (infixr "\<rightarrow>\<^isub>E" 60)
hoelzl@40859
    36
hoelzl@40859
    37
lemma extensional_empty[simp]: "extensional {} = {\<lambda>x. undefined}"
hoelzl@40859
    38
  by safe (auto simp add: extensional_def fun_eq_iff)
hoelzl@40859
    39
hoelzl@40859
    40
lemma extensional_insert[intro, simp]:
hoelzl@40859
    41
  assumes "a \<in> extensional (insert i I)"
hoelzl@40859
    42
  shows "a(i := b) \<in> extensional (insert i I)"
hoelzl@40859
    43
  using assms unfolding extensional_def by auto
hoelzl@40859
    44
hoelzl@40859
    45
lemma extensional_Int[simp]:
hoelzl@40859
    46
  "extensional I \<inter> extensional I' = extensional (I \<inter> I')"
hoelzl@40859
    47
  unfolding extensional_def by auto
hoelzl@38656
    48
hoelzl@35833
    49
definition
hoelzl@40859
    50
  "merge I x J y = (\<lambda>i. if i \<in> I then x i else if i \<in> J then y i else undefined)"
hoelzl@40859
    51
hoelzl@40859
    52
lemma merge_apply[simp]:
hoelzl@40859
    53
  "I \<inter> J = {} \<Longrightarrow> i \<in> I \<Longrightarrow> merge I x J y i = x i"
hoelzl@40859
    54
  "I \<inter> J = {} \<Longrightarrow> i \<in> J \<Longrightarrow> merge I x J y i = y i"
hoelzl@40859
    55
  "J \<inter> I = {} \<Longrightarrow> i \<in> I \<Longrightarrow> merge I x J y i = x i"
hoelzl@40859
    56
  "J \<inter> I = {} \<Longrightarrow> i \<in> J \<Longrightarrow> merge I x J y i = y i"
hoelzl@40859
    57
  "i \<notin> I \<Longrightarrow> i \<notin> J \<Longrightarrow> merge I x J y i = undefined"
hoelzl@40859
    58
  unfolding merge_def by auto
hoelzl@40859
    59
hoelzl@40859
    60
lemma merge_commute:
hoelzl@40859
    61
  "I \<inter> J = {} \<Longrightarrow> merge I x J y = merge J y I x"
hoelzl@40859
    62
  by (auto simp: merge_def intro!: ext)
hoelzl@40859
    63
hoelzl@40859
    64
lemma Pi_cancel_merge_range[simp]:
hoelzl@40859
    65
  "I \<inter> J = {} \<Longrightarrow> x \<in> Pi I (merge I A J B) \<longleftrightarrow> x \<in> Pi I A"
hoelzl@40859
    66
  "I \<inter> J = {} \<Longrightarrow> x \<in> Pi I (merge J B I A) \<longleftrightarrow> x \<in> Pi I A"
hoelzl@40859
    67
  "J \<inter> I = {} \<Longrightarrow> x \<in> Pi I (merge I A J B) \<longleftrightarrow> x \<in> Pi I A"
hoelzl@40859
    68
  "J \<inter> I = {} \<Longrightarrow> x \<in> Pi I (merge J B I A) \<longleftrightarrow> x \<in> Pi I A"
hoelzl@40859
    69
  by (auto simp: Pi_def)
hoelzl@40859
    70
hoelzl@40859
    71
lemma Pi_cancel_merge[simp]:
hoelzl@40859
    72
  "I \<inter> J = {} \<Longrightarrow> merge I x J y \<in> Pi I B \<longleftrightarrow> x \<in> Pi I B"
hoelzl@40859
    73
  "J \<inter> I = {} \<Longrightarrow> merge I x J y \<in> Pi I B \<longleftrightarrow> x \<in> Pi I B"
hoelzl@40859
    74
  "I \<inter> J = {} \<Longrightarrow> merge I x J y \<in> Pi J B \<longleftrightarrow> y \<in> Pi J B"
hoelzl@40859
    75
  "J \<inter> I = {} \<Longrightarrow> merge I x J y \<in> Pi J B \<longleftrightarrow> y \<in> Pi J B"
hoelzl@40859
    76
  by (auto simp: Pi_def)
hoelzl@40859
    77
hoelzl@40859
    78
lemma extensional_merge[simp]: "merge I x J y \<in> extensional (I \<union> J)"
hoelzl@40859
    79
  by (auto simp: extensional_def)
hoelzl@40859
    80
hoelzl@40859
    81
lemma restrict_Pi_cancel: "restrict x I \<in> Pi I A \<longleftrightarrow> x \<in> Pi I A"
hoelzl@40859
    82
  by (auto simp: restrict_def Pi_def)
hoelzl@40859
    83
hoelzl@40859
    84
lemma restrict_merge[simp]:
hoelzl@40859
    85
  "I \<inter> J = {} \<Longrightarrow> restrict (merge I x J y) I = restrict x I"
hoelzl@40859
    86
  "I \<inter> J = {} \<Longrightarrow> restrict (merge I x J y) J = restrict y J"
hoelzl@40859
    87
  "J \<inter> I = {} \<Longrightarrow> restrict (merge I x J y) I = restrict x I"
hoelzl@40859
    88
  "J \<inter> I = {} \<Longrightarrow> restrict (merge I x J y) J = restrict y J"
hoelzl@40859
    89
  by (auto simp: restrict_def intro!: ext)
hoelzl@40859
    90
hoelzl@40859
    91
lemma extensional_insert_undefined[intro, simp]:
hoelzl@40859
    92
  assumes "a \<in> extensional (insert i I)"
hoelzl@40859
    93
  shows "a(i := undefined) \<in> extensional I"
hoelzl@40859
    94
  using assms unfolding extensional_def by auto
hoelzl@40859
    95
hoelzl@40859
    96
lemma extensional_insert_cancel[intro, simp]:
hoelzl@40859
    97
  assumes "a \<in> extensional I"
hoelzl@40859
    98
  shows "a \<in> extensional (insert i I)"
hoelzl@40859
    99
  using assms unfolding extensional_def by auto
hoelzl@40859
   100
hoelzl@41095
   101
lemma merge_singleton[simp]: "i \<notin> I \<Longrightarrow> merge I x {i} y = restrict (x(i := y i)) (insert i I)"
hoelzl@41095
   102
  unfolding merge_def by (auto simp: fun_eq_iff)
hoelzl@41095
   103
hoelzl@41095
   104
lemma Pi_Int: "Pi I E \<inter> Pi I F = (\<Pi> i\<in>I. E i \<inter> F i)"
hoelzl@41095
   105
  by auto
hoelzl@41095
   106
hoelzl@40859
   107
lemma PiE_Int: "(Pi\<^isub>E I A) \<inter> (Pi\<^isub>E I B) = Pi\<^isub>E I (\<lambda>x. A x \<inter> B x)"
hoelzl@40859
   108
  by auto
hoelzl@40859
   109
hoelzl@40859
   110
lemma Pi_cancel_fupd_range[simp]: "i \<notin> I \<Longrightarrow> x \<in> Pi I (B(i := b)) \<longleftrightarrow> x \<in> Pi I B"
hoelzl@40859
   111
  by (auto simp: Pi_def)
hoelzl@40859
   112
hoelzl@40859
   113
lemma Pi_split_insert_domain[simp]: "x \<in> Pi (insert i I) X \<longleftrightarrow> x \<in> Pi I X \<and> x i \<in> X i"
hoelzl@40859
   114
  by (auto simp: Pi_def)
hoelzl@39088
   115
hoelzl@40859
   116
lemma Pi_split_domain[simp]: "x \<in> Pi (I \<union> J) X \<longleftrightarrow> x \<in> Pi I X \<and> x \<in> Pi J X"
hoelzl@40859
   117
  by (auto simp: Pi_def)
hoelzl@40859
   118
hoelzl@40859
   119
lemma Pi_cancel_fupd[simp]: "i \<notin> I \<Longrightarrow> x(i := a) \<in> Pi I B \<longleftrightarrow> x \<in> Pi I B"
hoelzl@40859
   120
  by (auto simp: Pi_def)
hoelzl@40859
   121
hoelzl@41095
   122
lemma restrict_vimage:
hoelzl@41095
   123
  assumes "I \<inter> J = {}"
hoelzl@41095
   124
  shows "(\<lambda>x. (restrict x I, restrict x J)) -` (Pi\<^isub>E I E \<times> Pi\<^isub>E J F) = Pi (I \<union> J) (merge I E J F)"
hoelzl@41095
   125
  using assms by (auto simp: restrict_Pi_cancel)
hoelzl@41095
   126
hoelzl@41095
   127
lemma merge_vimage:
hoelzl@41095
   128
  assumes "I \<inter> J = {}"
hoelzl@41095
   129
  shows "(\<lambda>(x,y). merge I x J y) -` Pi\<^isub>E (I \<union> J) E = Pi I E \<times> Pi J E"
hoelzl@41095
   130
  using assms by (auto simp: restrict_Pi_cancel)
hoelzl@41095
   131
hoelzl@41095
   132
lemma restrict_fupd[simp]: "i \<notin> I \<Longrightarrow> restrict (f (i := x)) I = restrict f I"
hoelzl@41095
   133
  by (auto simp: restrict_def intro!: ext)
hoelzl@41095
   134
hoelzl@41095
   135
lemma merge_restrict[simp]:
hoelzl@41095
   136
  "merge I (restrict x I) J y = merge I x J y"
hoelzl@41095
   137
  "merge I x J (restrict y J) = merge I x J y"
hoelzl@41095
   138
  unfolding merge_def by (auto intro!: ext)
hoelzl@41095
   139
hoelzl@41095
   140
lemma merge_x_x_eq_restrict[simp]:
hoelzl@41095
   141
  "merge I x J x = restrict x (I \<union> J)"
hoelzl@41095
   142
  unfolding merge_def by (auto intro!: ext)
hoelzl@41095
   143
hoelzl@41095
   144
lemma Pi_fupd_iff: "i \<in> I \<Longrightarrow> f \<in> Pi I (B(i := A)) \<longleftrightarrow> f \<in> Pi (I - {i}) B \<and> f i \<in> A"
hoelzl@41095
   145
  apply auto
hoelzl@41095
   146
  apply (drule_tac x=x in Pi_mem)
hoelzl@41095
   147
  apply (simp_all split: split_if_asm)
hoelzl@41095
   148
  apply (drule_tac x=i in Pi_mem)
hoelzl@41095
   149
  apply (auto dest!: Pi_mem)
hoelzl@41095
   150
  done
hoelzl@41095
   151
hoelzl@41095
   152
lemma Pi_UN:
hoelzl@41095
   153
  fixes A :: "nat \<Rightarrow> 'i \<Rightarrow> 'a set"
hoelzl@41095
   154
  assumes "finite I" and mono: "\<And>i n m. i \<in> I \<Longrightarrow> n \<le> m \<Longrightarrow> A n i \<subseteq> A m i"
hoelzl@41095
   155
  shows "(\<Union>n. Pi I (A n)) = (\<Pi> i\<in>I. \<Union>n. A n i)"
hoelzl@41095
   156
proof (intro set_eqI iffI)
hoelzl@41095
   157
  fix f assume "f \<in> (\<Pi> i\<in>I. \<Union>n. A n i)"
hoelzl@41095
   158
  then have "\<forall>i\<in>I. \<exists>n. f i \<in> A n i" by auto
hoelzl@41095
   159
  from bchoice[OF this] obtain n where n: "\<And>i. i \<in> I \<Longrightarrow> f i \<in> (A (n i) i)" by auto
hoelzl@41095
   160
  obtain k where k: "\<And>i. i \<in> I \<Longrightarrow> n i \<le> k"
hoelzl@41095
   161
    using `finite I` finite_nat_set_iff_bounded_le[of "n`I"] by auto
hoelzl@41095
   162
  have "f \<in> Pi I (A k)"
hoelzl@41095
   163
  proof (intro Pi_I)
hoelzl@41095
   164
    fix i assume "i \<in> I"
hoelzl@41095
   165
    from mono[OF this, of "n i" k] k[OF this] n[OF this]
hoelzl@41095
   166
    show "f i \<in> A k i" by auto
hoelzl@41095
   167
  qed
hoelzl@41095
   168
  then show "f \<in> (\<Union>n. Pi I (A n))" by auto
hoelzl@41095
   169
qed auto
hoelzl@41095
   170
hoelzl@41095
   171
lemma PiE_cong:
hoelzl@41095
   172
  assumes "\<And>i. i\<in>I \<Longrightarrow> A i = B i"
hoelzl@41095
   173
  shows "Pi\<^isub>E I A = Pi\<^isub>E I B"
hoelzl@41095
   174
  using assms by (auto intro!: Pi_cong)
hoelzl@41095
   175
hoelzl@41095
   176
lemma restrict_upd[simp]:
hoelzl@41095
   177
  "i \<notin> I \<Longrightarrow> (restrict f I)(i := y) = restrict (f(i := y)) (insert i I)"
hoelzl@41095
   178
  by (auto simp: fun_eq_iff)
hoelzl@41095
   179
hoelzl@41689
   180
lemma Pi_eq_subset:
hoelzl@41689
   181
  assumes ne: "\<And>i. i \<in> I \<Longrightarrow> F i \<noteq> {}" "\<And>i. i \<in> I \<Longrightarrow> F' i \<noteq> {}"
hoelzl@41689
   182
  assumes eq: "Pi\<^isub>E I F = Pi\<^isub>E I F'" and "i \<in> I"
hoelzl@41689
   183
  shows "F i \<subseteq> F' i"
hoelzl@41689
   184
proof
hoelzl@41689
   185
  fix x assume "x \<in> F i"
hoelzl@41689
   186
  with ne have "\<forall>j. \<exists>y. ((j \<in> I \<longrightarrow> y \<in> F j \<and> (i = j \<longrightarrow> x = y)) \<and> (j \<notin> I \<longrightarrow> y = undefined))" by auto
hoelzl@41689
   187
  from choice[OF this] guess f .. note f = this
hoelzl@41689
   188
  then have "f \<in> Pi\<^isub>E I F" by (auto simp: extensional_def)
hoelzl@41689
   189
  then have "f \<in> Pi\<^isub>E I F'" using assms by simp
hoelzl@41689
   190
  then show "x \<in> F' i" using f `i \<in> I` by auto
hoelzl@41689
   191
qed
hoelzl@41689
   192
hoelzl@41689
   193
lemma Pi_eq_iff_not_empty:
hoelzl@41689
   194
  assumes ne: "\<And>i. i \<in> I \<Longrightarrow> F i \<noteq> {}" "\<And>i. i \<in> I \<Longrightarrow> F' i \<noteq> {}"
hoelzl@41689
   195
  shows "Pi\<^isub>E I F = Pi\<^isub>E I F' \<longleftrightarrow> (\<forall>i\<in>I. F i = F' i)"
hoelzl@41689
   196
proof (intro iffI ballI)
hoelzl@41689
   197
  fix i assume eq: "Pi\<^isub>E I F = Pi\<^isub>E I F'" and i: "i \<in> I"
hoelzl@41689
   198
  show "F i = F' i"
hoelzl@41689
   199
    using Pi_eq_subset[of I F F', OF ne eq i]
hoelzl@41689
   200
    using Pi_eq_subset[of I F' F, OF ne(2,1) eq[symmetric] i]
hoelzl@41689
   201
    by auto
hoelzl@41689
   202
qed auto
hoelzl@41689
   203
hoelzl@41689
   204
lemma Pi_eq_empty_iff:
hoelzl@41689
   205
  "Pi\<^isub>E I F = {} \<longleftrightarrow> (\<exists>i\<in>I. F i = {})"
hoelzl@41689
   206
proof
hoelzl@41689
   207
  assume "Pi\<^isub>E I F = {}"
hoelzl@41689
   208
  show "\<exists>i\<in>I. F i = {}"
hoelzl@41689
   209
  proof (rule ccontr)
hoelzl@41689
   210
    assume "\<not> ?thesis"
hoelzl@41689
   211
    then have "\<forall>i. \<exists>y. (i \<in> I \<longrightarrow> y \<in> F i) \<and> (i \<notin> I \<longrightarrow> y = undefined)" by auto
hoelzl@41689
   212
    from choice[OF this] guess f ..
hoelzl@41689
   213
    then have "f \<in> Pi\<^isub>E I F" by (auto simp: extensional_def)
hoelzl@41689
   214
    with `Pi\<^isub>E I F = {}` show False by auto
hoelzl@41689
   215
  qed
hoelzl@41689
   216
qed auto
hoelzl@41689
   217
hoelzl@41689
   218
lemma Pi_eq_iff:
hoelzl@41689
   219
  "Pi\<^isub>E I F = Pi\<^isub>E I F' \<longleftrightarrow> (\<forall>i\<in>I. F i = F' i) \<or> ((\<exists>i\<in>I. F i = {}) \<and> (\<exists>i\<in>I. F' i = {}))"
hoelzl@41689
   220
proof (intro iffI disjCI)
hoelzl@41689
   221
  assume eq[simp]: "Pi\<^isub>E I F = Pi\<^isub>E I F'"
hoelzl@41689
   222
  assume "\<not> ((\<exists>i\<in>I. F i = {}) \<and> (\<exists>i\<in>I. F' i = {}))"
hoelzl@41689
   223
  then have "(\<forall>i\<in>I. F i \<noteq> {}) \<and> (\<forall>i\<in>I. F' i \<noteq> {})"
hoelzl@41689
   224
    using Pi_eq_empty_iff[of I F] Pi_eq_empty_iff[of I F'] by auto
hoelzl@41689
   225
  with Pi_eq_iff_not_empty[of I F F'] show "\<forall>i\<in>I. F i = F' i" by auto
hoelzl@41689
   226
next
hoelzl@41689
   227
  assume "(\<forall>i\<in>I. F i = F' i) \<or> (\<exists>i\<in>I. F i = {}) \<and> (\<exists>i\<in>I. F' i = {})"
hoelzl@41689
   228
  then show "Pi\<^isub>E I F = Pi\<^isub>E I F'"
hoelzl@41689
   229
    using Pi_eq_empty_iff[of I F] Pi_eq_empty_iff[of I F'] by auto
hoelzl@41689
   230
qed
hoelzl@41689
   231
hoelzl@40859
   232
section "Finite product spaces"
hoelzl@40859
   233
hoelzl@40859
   234
section "Products"
hoelzl@40859
   235
hoelzl@40859
   236
locale product_sigma_algebra =
hoelzl@41689
   237
  fixes M :: "'i \<Rightarrow> ('a, 'b) measure_space_scheme"
hoelzl@40859
   238
  assumes sigma_algebras: "\<And>i. sigma_algebra (M i)"
hoelzl@40859
   239
hoelzl@41689
   240
locale finite_product_sigma_algebra = product_sigma_algebra M
hoelzl@41689
   241
  for M :: "'i \<Rightarrow> ('a, 'b) measure_space_scheme" +
hoelzl@40859
   242
  fixes I :: "'i set"
hoelzl@40859
   243
  assumes finite_index: "finite I"
hoelzl@40859
   244
hoelzl@41689
   245
definition
hoelzl@41689
   246
  "product_algebra_generator I M = \<lparr> space = (\<Pi>\<^isub>E i \<in> I. space (M i)),
hoelzl@41689
   247
    sets = Pi\<^isub>E I ` (\<Pi> i \<in> I. sets (M i)),
hoelzl@41689
   248
    measure = \<lambda>A. (\<Prod>i\<in>I. measure (M i) ((SOME F. A = Pi\<^isub>E I F) i)) \<rparr>"
hoelzl@41689
   249
hoelzl@41689
   250
definition product_algebra_def:
hoelzl@41689
   251
  "Pi\<^isub>M I M = sigma (product_algebra_generator I M)
hoelzl@41689
   252
    \<lparr> measure := (SOME \<mu>. sigma_finite_measure (sigma (product_algebra_generator I M) \<lparr> measure := \<mu> \<rparr>) \<and>
hoelzl@41689
   253
      (\<forall>A\<in>\<Pi> i\<in>I. sets (M i). \<mu> (Pi\<^isub>E I A) = (\<Prod>i\<in>I. measure (M i) (A i))))\<rparr>"
hoelzl@41689
   254
hoelzl@40859
   255
syntax
hoelzl@41689
   256
  "_PiM"  :: "[pttrn, 'i set, ('a, 'b) measure_space_scheme] =>
hoelzl@41689
   257
              ('i => 'a, 'b) measure_space_scheme"  ("(3PIM _:_./ _)" 10)
hoelzl@40859
   258
hoelzl@40859
   259
syntax (xsymbols)
hoelzl@41689
   260
  "_PiM" :: "[pttrn, 'i set, ('a, 'b) measure_space_scheme] =>
hoelzl@41689
   261
             ('i => 'a, 'b) measure_space_scheme"  ("(3\<Pi>\<^isub>M _\<in>_./ _)"   10)
hoelzl@40859
   262
hoelzl@40859
   263
syntax (HTML output)
hoelzl@41689
   264
  "_PiM" :: "[pttrn, 'i set, ('a, 'b) measure_space_scheme] =>
hoelzl@41689
   265
             ('i => 'a, 'b) measure_space_scheme"  ("(3\<Pi>\<^isub>M _\<in>_./ _)"   10)
hoelzl@40859
   266
hoelzl@40859
   267
translations
hoelzl@41689
   268
  "PIM x:I. M" == "CONST Pi\<^isub>M I (%x. M)"
hoelzl@40859
   269
hoelzl@41689
   270
abbreviation (in finite_product_sigma_algebra) "G \<equiv> product_algebra_generator I M"
hoelzl@41689
   271
abbreviation (in finite_product_sigma_algebra) "P \<equiv> Pi\<^isub>M I M"
hoelzl@40859
   272
hoelzl@40859
   273
sublocale product_sigma_algebra \<subseteq> M: sigma_algebra "M i" for i by (rule sigma_algebras)
hoelzl@40859
   274
hoelzl@41689
   275
lemma sigma_into_space:
hoelzl@41689
   276
  assumes "sets M \<subseteq> Pow (space M)"
hoelzl@41689
   277
  shows "sets (sigma M) \<subseteq> Pow (space M)"
hoelzl@41689
   278
  using sigma_sets_into_sp[OF assms] unfolding sigma_def by auto
hoelzl@41689
   279
hoelzl@41689
   280
lemma (in product_sigma_algebra) product_algebra_generator_into_space:
hoelzl@41689
   281
  "sets (product_algebra_generator I M) \<subseteq> Pow (space (product_algebra_generator I M))"
hoelzl@41689
   282
  using M.sets_into_space unfolding product_algebra_generator_def
hoelzl@40859
   283
  by auto blast
hoelzl@40859
   284
hoelzl@41689
   285
lemma (in product_sigma_algebra) product_algebra_into_space:
hoelzl@41689
   286
  "sets (Pi\<^isub>M I M) \<subseteq> Pow (space (Pi\<^isub>M I M))"
hoelzl@41689
   287
  using product_algebra_generator_into_space
hoelzl@41689
   288
  by (auto intro!: sigma_into_space simp add: product_algebra_def)
hoelzl@41689
   289
hoelzl@41689
   290
lemma (in product_sigma_algebra) sigma_algebra_product_algebra: "sigma_algebra (Pi\<^isub>M I M)"
hoelzl@41689
   291
  using product_algebra_generator_into_space unfolding product_algebra_def
hoelzl@41689
   292
  by (rule sigma_algebra.sigma_algebra_cong[OF sigma_algebra_sigma]) simp_all
hoelzl@41689
   293
hoelzl@40859
   294
sublocale finite_product_sigma_algebra \<subseteq> sigma_algebra P
hoelzl@41689
   295
  using sigma_algebra_product_algebra .
hoelzl@40859
   296
hoelzl@41095
   297
lemma product_algebraE:
hoelzl@41689
   298
  assumes "A \<in> sets (product_algebra_generator I M)"
hoelzl@41095
   299
  obtains E where "A = Pi\<^isub>E I E" "E \<in> (\<Pi> i\<in>I. sets (M i))"
hoelzl@41689
   300
  using assms unfolding product_algebra_generator_def by auto
hoelzl@41095
   301
hoelzl@41689
   302
lemma product_algebra_generatorI[intro]:
hoelzl@41095
   303
  assumes "E \<in> (\<Pi> i\<in>I. sets (M i))"
hoelzl@41689
   304
  shows "Pi\<^isub>E I E \<in> sets (product_algebra_generator I M)"
hoelzl@41689
   305
  using assms unfolding product_algebra_generator_def by auto
hoelzl@41689
   306
hoelzl@41689
   307
lemma space_product_algebra_generator[simp]:
hoelzl@41689
   308
  "space (product_algebra_generator I M) = Pi\<^isub>E I (\<lambda>i. space (M i))"
hoelzl@41689
   309
  unfolding product_algebra_generator_def by simp
hoelzl@41095
   310
hoelzl@40859
   311
lemma space_product_algebra[simp]:
hoelzl@41689
   312
  "space (Pi\<^isub>M I M) = (\<Pi>\<^isub>E i\<in>I. space (M i))"
hoelzl@41689
   313
  unfolding product_algebra_def product_algebra_generator_def by simp
hoelzl@40859
   314
hoelzl@41689
   315
lemma sets_product_algebra:
hoelzl@41689
   316
  "sets (Pi\<^isub>M I M) = sets (sigma (product_algebra_generator I M))"
hoelzl@41689
   317
  unfolding product_algebra_def sigma_def by simp
hoelzl@41689
   318
hoelzl@41689
   319
lemma product_algebra_generator_sets_into_space:
hoelzl@41095
   320
  assumes "\<And>i. i\<in>I \<Longrightarrow> sets (M i) \<subseteq> Pow (space (M i))"
hoelzl@41689
   321
  shows "sets (product_algebra_generator I M) \<subseteq> Pow (space (product_algebra_generator I M))"
hoelzl@41689
   322
  using assms by (auto simp: product_algebra_generator_def) blast
hoelzl@40859
   323
hoelzl@40859
   324
lemma (in finite_product_sigma_algebra) in_P[simp, intro]:
hoelzl@40859
   325
  "\<lbrakk> \<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (M i) \<rbrakk> \<Longrightarrow> Pi\<^isub>E I A \<in> sets P"
hoelzl@41689
   326
  by (auto simp: sets_product_algebra)
hoelzl@41026
   327
hoelzl@40859
   328
section "Generating set generates also product algebra"
hoelzl@40859
   329
hoelzl@40859
   330
lemma sigma_product_algebra_sigma_eq:
hoelzl@40859
   331
  assumes "finite I"
hoelzl@41981
   332
  assumes mono: "\<And>i. i \<in> I \<Longrightarrow> incseq (S i)"
hoelzl@41981
   333
  assumes union: "\<And>i. i \<in> I \<Longrightarrow> (\<Union>j. S i j) = space (E i)"
hoelzl@40859
   334
  assumes sets_into: "\<And>i. i \<in> I \<Longrightarrow> range (S i) \<subseteq> sets (E i)"
hoelzl@40859
   335
  and E: "\<And>i. sets (E i) \<subseteq> Pow (space (E i))"
hoelzl@41689
   336
  shows "sets (\<Pi>\<^isub>M i\<in>I. sigma (E i)) = sets (\<Pi>\<^isub>M i\<in>I. E i)"
hoelzl@41689
   337
    (is "sets ?S = sets ?E")
hoelzl@40859
   338
proof cases
hoelzl@41689
   339
  assume "I = {}" then show ?thesis
hoelzl@41689
   340
    by (simp add: product_algebra_def product_algebra_generator_def)
hoelzl@40859
   341
next
hoelzl@40859
   342
  assume "I \<noteq> {}"
hoelzl@40859
   343
  interpret E: sigma_algebra "sigma (E i)" for i
hoelzl@40859
   344
    using E by (rule sigma_algebra_sigma)
hoelzl@40859
   345
  have into_space[intro]: "\<And>i x A. A \<in> sets (E i) \<Longrightarrow> x i \<in> A \<Longrightarrow> x i \<in> space (E i)"
hoelzl@40859
   346
    using E by auto
hoelzl@40859
   347
  interpret G: sigma_algebra ?E
hoelzl@41689
   348
    unfolding product_algebra_def product_algebra_generator_def using E
hoelzl@41689
   349
    by (intro sigma_algebra.sigma_algebra_cong[OF sigma_algebra_sigma]) (auto dest: Pi_mem)
hoelzl@40859
   350
  { fix A i assume "i \<in> I" and A: "A \<in> sets (E i)"
hoelzl@40859
   351
    then have "(\<lambda>x. x i) -` A \<inter> space ?E = (\<Pi>\<^isub>E j\<in>I. if j = i then A else \<Union>n. S j n) \<inter> space ?E"
hoelzl@41981
   352
      using mono union unfolding incseq_Suc_iff space_product_algebra
hoelzl@41689
   353
      by (auto dest: Pi_mem)
hoelzl@40859
   354
    also have "\<dots> = (\<Union>n. (\<Pi>\<^isub>E j\<in>I. if j = i then A else S j n))"
hoelzl@41689
   355
      unfolding space_product_algebra
hoelzl@40859
   356
      apply simp
hoelzl@40859
   357
      apply (subst Pi_UN[OF `finite I`])
hoelzl@41981
   358
      using mono[THEN incseqD] apply simp
hoelzl@40859
   359
      apply (simp add: PiE_Int)
hoelzl@40859
   360
      apply (intro PiE_cong)
hoelzl@40859
   361
      using A sets_into by (auto intro!: into_space)
hoelzl@41689
   362
    also have "\<dots> \<in> sets ?E"
hoelzl@40859
   363
      using sets_into `A \<in> sets (E i)`
hoelzl@41689
   364
      unfolding sets_product_algebra sets_sigma
hoelzl@40859
   365
      by (intro sigma_sets.Union)
hoelzl@40859
   366
         (auto simp: image_subset_iff intro!: sigma_sets.Basic)
hoelzl@40859
   367
    finally have "(\<lambda>x. x i) -` A \<inter> space ?E \<in> sets ?E" . }
hoelzl@40859
   368
  then have proj:
hoelzl@40859
   369
    "\<And>i. i\<in>I \<Longrightarrow> (\<lambda>x. x i) \<in> measurable ?E (sigma (E i))"
hoelzl@40859
   370
    using E by (subst G.measurable_iff_sigma)
hoelzl@41689
   371
               (auto simp: sets_product_algebra sets_sigma)
hoelzl@40859
   372
  { fix A assume A: "\<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (sigma (E i))"
hoelzl@40859
   373
    with proj have basic: "\<And>i. i \<in> I \<Longrightarrow> (\<lambda>x. x i) -` (A i) \<inter> space ?E \<in> sets ?E"
hoelzl@40859
   374
      unfolding measurable_def by simp
hoelzl@40859
   375
    have "Pi\<^isub>E I A = (\<Inter>i\<in>I. (\<lambda>x. x i) -` (A i) \<inter> space ?E)"
hoelzl@40859
   376
      using A E.sets_into_space `I \<noteq> {}` unfolding product_algebra_def by auto blast
hoelzl@40859
   377
    then have "Pi\<^isub>E I A \<in> sets ?E"
hoelzl@40859
   378
      using G.finite_INT[OF `finite I` `I \<noteq> {}` basic, of "\<lambda>i. i"] by simp }
hoelzl@41689
   379
  then have "sigma_sets (space ?E) (sets (product_algebra_generator I (\<lambda>i. sigma (E i)))) \<subseteq> sets ?E"
hoelzl@41689
   380
    by (intro G.sigma_sets_subset) (auto simp add: product_algebra_generator_def)
hoelzl@40859
   381
  then have subset: "sets ?S \<subseteq> sets ?E"
hoelzl@41689
   382
    by (simp add: sets_sigma sets_product_algebra)
hoelzl@41689
   383
  show "sets ?S = sets ?E"
hoelzl@40859
   384
  proof (intro set_eqI iffI)
hoelzl@40859
   385
    fix A assume "A \<in> sets ?E" then show "A \<in> sets ?S"
hoelzl@41689
   386
      unfolding sets_sigma sets_product_algebra
hoelzl@40859
   387
    proof induct
hoelzl@40859
   388
      case (Basic A) then show ?case
hoelzl@41689
   389
        by (auto simp: sets_sigma product_algebra_generator_def intro: sigma_sets.Basic)
hoelzl@41689
   390
    qed (auto intro: sigma_sets.intros simp: product_algebra_generator_def)
hoelzl@40859
   391
  next
hoelzl@40859
   392
    fix A assume "A \<in> sets ?S" then show "A \<in> sets ?E" using subset by auto
hoelzl@40859
   393
  qed
hoelzl@41689
   394
qed
hoelzl@41689
   395
hoelzl@41689
   396
lemma product_algebraI[intro]:
hoelzl@41689
   397
    "E \<in> (\<Pi> i\<in>I. sets (M i)) \<Longrightarrow> Pi\<^isub>E I E \<in> sets (Pi\<^isub>M I M)"
hoelzl@41689
   398
  using assms unfolding product_algebra_def by (auto intro: product_algebra_generatorI)
hoelzl@41689
   399
hoelzl@41689
   400
lemma (in product_sigma_algebra) measurable_component_update:
hoelzl@41689
   401
  assumes "x \<in> space (Pi\<^isub>M I M)" and "i \<notin> I"
hoelzl@41689
   402
  shows "(\<lambda>v. x(i := v)) \<in> measurable (M i) (Pi\<^isub>M (insert i I) M)" (is "?f \<in> _")
hoelzl@41689
   403
  unfolding product_algebra_def apply simp
hoelzl@41689
   404
proof (intro measurable_sigma)
hoelzl@41689
   405
  let ?G = "product_algebra_generator (insert i I) M"
hoelzl@41689
   406
  show "sets ?G \<subseteq> Pow (space ?G)" using product_algebra_generator_into_space .
hoelzl@41689
   407
  show "?f \<in> space (M i) \<rightarrow> space ?G"
hoelzl@41689
   408
    using M.sets_into_space assms by auto
hoelzl@41689
   409
  fix A assume "A \<in> sets ?G"
hoelzl@41689
   410
  from product_algebraE[OF this] guess E . note E = this
hoelzl@41689
   411
  then have "?f -` A \<inter> space (M i) = E i \<or> ?f -` A \<inter> space (M i) = {}"
hoelzl@41689
   412
    using M.sets_into_space assms by auto
hoelzl@41689
   413
  then show "?f -` A \<inter> space (M i) \<in> sets (M i)"
hoelzl@41689
   414
    using E by (auto intro!: product_algebraI)
hoelzl@40859
   415
qed
hoelzl@40859
   416
hoelzl@41689
   417
lemma (in product_sigma_algebra) measurable_add_dim:
hoelzl@41689
   418
  assumes "i \<notin> I"
hoelzl@41689
   419
  shows "(\<lambda>(f, y). f(i := y)) \<in> measurable (Pi\<^isub>M I M \<Otimes>\<^isub>M M i) (Pi\<^isub>M (insert i I) M)"
hoelzl@41689
   420
proof -
hoelzl@41689
   421
  let ?f = "(\<lambda>(f, y). f(i := y))" and ?G = "product_algebra_generator (insert i I) M"
hoelzl@41689
   422
  interpret Ii: pair_sigma_algebra "Pi\<^isub>M I M" "M i"
hoelzl@41689
   423
    unfolding pair_sigma_algebra_def
hoelzl@41689
   424
    by (intro sigma_algebra_product_algebra sigma_algebras conjI)
hoelzl@41689
   425
  have "?f \<in> measurable Ii.P (sigma ?G)"
hoelzl@41689
   426
  proof (rule Ii.measurable_sigma)
hoelzl@41689
   427
    show "sets ?G \<subseteq> Pow (space ?G)"
hoelzl@41689
   428
      using product_algebra_generator_into_space .
hoelzl@41689
   429
    show "?f \<in> space (Pi\<^isub>M I M \<Otimes>\<^isub>M M i) \<rightarrow> space ?G"
hoelzl@41689
   430
      by (auto simp: space_pair_measure)
hoelzl@41689
   431
  next
hoelzl@41689
   432
    fix A assume "A \<in> sets ?G"
hoelzl@41689
   433
    then obtain F where "A = Pi\<^isub>E (insert i I) F"
hoelzl@41689
   434
      and F: "\<And>j. j \<in> I \<Longrightarrow> F j \<in> sets (M j)" "F i \<in> sets (M i)"
hoelzl@41689
   435
      by (auto elim!: product_algebraE)
hoelzl@41689
   436
    then have "?f -` A \<inter> space (Pi\<^isub>M I M \<Otimes>\<^isub>M M i) = Pi\<^isub>E I F \<times> (F i)"
hoelzl@41689
   437
      using sets_into_space `i \<notin> I`
hoelzl@41689
   438
      by (auto simp add: space_pair_measure) blast+
hoelzl@41689
   439
    then show "?f -` A \<inter> space (Pi\<^isub>M I M \<Otimes>\<^isub>M M i) \<in> sets (Pi\<^isub>M I M \<Otimes>\<^isub>M M i)"
hoelzl@41689
   440
      using F by (auto intro!: pair_measureI)
hoelzl@41689
   441
  qed
hoelzl@41689
   442
  then show ?thesis
hoelzl@41689
   443
    by (simp add: product_algebra_def)
hoelzl@41689
   444
qed
hoelzl@41095
   445
hoelzl@41095
   446
lemma (in product_sigma_algebra) measurable_merge:
hoelzl@41095
   447
  assumes [simp]: "I \<inter> J = {}"
hoelzl@41689
   448
  shows "(\<lambda>(x, y). merge I x J y) \<in> measurable (Pi\<^isub>M I M \<Otimes>\<^isub>M Pi\<^isub>M J M) (Pi\<^isub>M (I \<union> J) M)"
hoelzl@40859
   449
proof -
hoelzl@41689
   450
  let ?I = "Pi\<^isub>M I M" and ?J = "Pi\<^isub>M J M"
hoelzl@41689
   451
  interpret P: sigma_algebra "?I \<Otimes>\<^isub>M ?J"
hoelzl@41689
   452
    by (intro sigma_algebra_pair_measure product_algebra_into_space)
hoelzl@41689
   453
  let ?f = "\<lambda>(x, y). merge I x J y"
hoelzl@41689
   454
  let ?G = "product_algebra_generator (I \<union> J) M"
hoelzl@41689
   455
  have "?f \<in> measurable (?I \<Otimes>\<^isub>M ?J) (sigma ?G)"
hoelzl@41689
   456
  proof (rule P.measurable_sigma)
hoelzl@41689
   457
    fix A assume "A \<in> sets ?G"
hoelzl@41689
   458
    from product_algebraE[OF this]
hoelzl@41689
   459
    obtain E where E: "A = Pi\<^isub>E (I \<union> J) E" "E \<in> (\<Pi> i\<in>I \<union> J. sets (M i))" .
hoelzl@41689
   460
    then have *: "?f -` A \<inter> space (?I \<Otimes>\<^isub>M ?J) = Pi\<^isub>E I E \<times> Pi\<^isub>E J E"
hoelzl@41689
   461
      using sets_into_space `I \<inter> J = {}`
hoelzl@41981
   462
      by (auto simp add: space_pair_measure) fast+
hoelzl@41689
   463
    then show "?f -` A \<inter> space (?I \<Otimes>\<^isub>M ?J) \<in> sets (?I \<Otimes>\<^isub>M ?J)"
hoelzl@41689
   464
      using E unfolding * by (auto intro!: pair_measureI in_sigma product_algebra_generatorI
hoelzl@41689
   465
        simp: product_algebra_def)
hoelzl@41689
   466
  qed (insert product_algebra_generator_into_space, auto simp: space_pair_measure)
hoelzl@41689
   467
  then show "?f \<in> measurable (?I \<Otimes>\<^isub>M ?J) (Pi\<^isub>M (I \<union> J) M)"
hoelzl@41689
   468
    unfolding product_algebra_def[of "I \<union> J"] by simp
hoelzl@40859
   469
qed
hoelzl@40859
   470
hoelzl@41095
   471
lemma (in product_sigma_algebra) measurable_component_singleton:
hoelzl@41689
   472
  assumes "i \<in> I" shows "(\<lambda>x. x i) \<in> measurable (Pi\<^isub>M I M) (M i)"
hoelzl@41689
   473
proof (unfold measurable_def, intro CollectI conjI ballI)
hoelzl@41689
   474
  fix A assume "A \<in> sets (M i)"
hoelzl@41689
   475
  then have "(\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>M I M) = (\<Pi>\<^isub>E j\<in>I. if i = j then A else space (M j))"
hoelzl@41689
   476
    using M.sets_into_space `i \<in> I` by (fastsimp dest: Pi_mem split: split_if_asm)
hoelzl@41689
   477
  then show "(\<lambda>x. x i) -` A \<inter> space (Pi\<^isub>M I M) \<in> sets (Pi\<^isub>M I M)"
hoelzl@41689
   478
    using `A \<in> sets (M i)` by (auto intro!: product_algebraI)
hoelzl@41689
   479
qed (insert `i \<in> I`, auto)
hoelzl@41661
   480
hoelzl@40859
   481
locale product_sigma_finite =
hoelzl@41689
   482
  fixes M :: "'i \<Rightarrow> ('a,'b) measure_space_scheme"
hoelzl@41689
   483
  assumes sigma_finite_measures: "\<And>i. sigma_finite_measure (M i)"
hoelzl@40859
   484
hoelzl@41689
   485
locale finite_product_sigma_finite = product_sigma_finite M
hoelzl@41689
   486
  for M :: "'i \<Rightarrow> ('a,'b) measure_space_scheme" +
hoelzl@41689
   487
  fixes I :: "'i set" assumes finite_index'[intro]: "finite I"
hoelzl@40859
   488
hoelzl@41689
   489
sublocale product_sigma_finite \<subseteq> M: sigma_finite_measure "M i" for i
hoelzl@40859
   490
  by (rule sigma_finite_measures)
hoelzl@40859
   491
hoelzl@40859
   492
sublocale product_sigma_finite \<subseteq> product_sigma_algebra
hoelzl@40859
   493
  by default
hoelzl@40859
   494
hoelzl@40859
   495
sublocale finite_product_sigma_finite \<subseteq> finite_product_sigma_algebra
hoelzl@40859
   496
  by default (fact finite_index')
hoelzl@40859
   497
hoelzl@41981
   498
lemma setprod_extreal_0:
hoelzl@41981
   499
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@41981
   500
  shows "(\<Prod>i\<in>A. f i) = 0 \<longleftrightarrow> (finite A \<and> (\<exists>i\<in>A. f i = 0))"
hoelzl@41981
   501
proof cases
hoelzl@41981
   502
  assume "finite A"
hoelzl@41981
   503
  then show ?thesis by (induct A) auto
hoelzl@41981
   504
qed auto
hoelzl@41981
   505
hoelzl@41981
   506
lemma setprod_extreal_pos:
hoelzl@41981
   507
  fixes f :: "'a \<Rightarrow> extreal" assumes pos: "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i" shows "0 \<le> (\<Prod>i\<in>I. f i)"
hoelzl@41981
   508
proof cases
hoelzl@41981
   509
  assume "finite I" from this pos show ?thesis by induct auto
hoelzl@41981
   510
qed simp
hoelzl@41981
   511
hoelzl@41981
   512
lemma setprod_PInf:
hoelzl@41981
   513
  assumes "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i"
hoelzl@41981
   514
  shows "(\<Prod>i\<in>I. f i) = \<infinity> \<longleftrightarrow> finite I \<and> (\<exists>i\<in>I. f i = \<infinity>) \<and> (\<forall>i\<in>I. f i \<noteq> 0)"
hoelzl@41981
   515
proof cases
hoelzl@41981
   516
  assume "finite I" from this assms show ?thesis
hoelzl@41981
   517
  proof (induct I)
hoelzl@41981
   518
    case (insert i I)
hoelzl@41981
   519
    then have pos: "0 \<le> f i" "0 \<le> setprod f I" by (auto intro!: setprod_extreal_pos)
hoelzl@41981
   520
    from insert have "(\<Prod>j\<in>insert i I. f j) = \<infinity> \<longleftrightarrow> setprod f I * f i = \<infinity>" by auto
hoelzl@41981
   521
    also have "\<dots> \<longleftrightarrow> (setprod f I = \<infinity> \<or> f i = \<infinity>) \<and> f i \<noteq> 0 \<and> setprod f I \<noteq> 0"
hoelzl@41981
   522
      using setprod_extreal_pos[of I f] pos
hoelzl@41981
   523
      by (cases rule: extreal2_cases[of "f i" "setprod f I"]) auto
hoelzl@41981
   524
    also have "\<dots> \<longleftrightarrow> finite (insert i I) \<and> (\<exists>j\<in>insert i I. f j = \<infinity>) \<and> (\<forall>j\<in>insert i I. f j \<noteq> 0)"
hoelzl@41981
   525
      using insert by (auto simp: setprod_extreal_0)
hoelzl@41981
   526
    finally show ?case .
hoelzl@41981
   527
  qed simp
hoelzl@41981
   528
qed simp
hoelzl@41981
   529
hoelzl@41981
   530
lemma setprod_extreal: "(\<Prod>i\<in>A. extreal (f i)) = extreal (setprod f A)"
hoelzl@41981
   531
proof cases
hoelzl@41981
   532
  assume "finite A" then show ?thesis
hoelzl@41981
   533
    by induct (auto simp: one_extreal_def)
hoelzl@41981
   534
qed (simp add: one_extreal_def)
hoelzl@41981
   535
hoelzl@41689
   536
lemma (in finite_product_sigma_finite) product_algebra_generator_measure:
hoelzl@41689
   537
  assumes "Pi\<^isub>E I F \<in> sets G"
hoelzl@41689
   538
  shows "measure G (Pi\<^isub>E I F) = (\<Prod>i\<in>I. M.\<mu> i (F i))"
hoelzl@41689
   539
proof cases
hoelzl@41689
   540
  assume ne: "\<forall>i\<in>I. F i \<noteq> {}"
hoelzl@41689
   541
  have "\<forall>i\<in>I. (SOME F'. Pi\<^isub>E I F = Pi\<^isub>E I F') i = F i"
hoelzl@41689
   542
    by (rule someI2[where P="\<lambda>F'. Pi\<^isub>E I F = Pi\<^isub>E I F'"])
hoelzl@41689
   543
       (insert ne, auto simp: Pi_eq_iff)
hoelzl@41689
   544
  then show ?thesis
hoelzl@41689
   545
    unfolding product_algebra_generator_def by simp
hoelzl@41689
   546
next
hoelzl@41689
   547
  assume empty: "\<not> (\<forall>j\<in>I. F j \<noteq> {})"
hoelzl@41689
   548
  then have "(\<Prod>j\<in>I. M.\<mu> j (F j)) = 0"
hoelzl@41981
   549
    by (auto simp: setprod_extreal_0 intro!: bexI)
hoelzl@41689
   550
  moreover
hoelzl@41689
   551
  have "\<exists>j\<in>I. (SOME F'. Pi\<^isub>E I F = Pi\<^isub>E I F') j = {}"
hoelzl@41689
   552
    by (rule someI2[where P="\<lambda>F'. Pi\<^isub>E I F = Pi\<^isub>E I F'"])
hoelzl@41689
   553
       (insert empty, auto simp: Pi_eq_empty_iff[symmetric])
hoelzl@41689
   554
  then have "(\<Prod>j\<in>I. M.\<mu> j ((SOME F'. Pi\<^isub>E I F = Pi\<^isub>E I F') j)) = 0"
hoelzl@41981
   555
    by (auto simp: setprod_extreal_0 intro!: bexI)
hoelzl@41689
   556
  ultimately show ?thesis
hoelzl@41689
   557
    unfolding product_algebra_generator_def by simp
hoelzl@41689
   558
qed
hoelzl@41689
   559
hoelzl@40859
   560
lemma (in finite_product_sigma_finite) sigma_finite_pairs:
hoelzl@40859
   561
  "\<exists>F::'i \<Rightarrow> nat \<Rightarrow> 'a set.
hoelzl@40859
   562
    (\<forall>i\<in>I. range (F i) \<subseteq> sets (M i)) \<and>
hoelzl@41981
   563
    (\<forall>k. \<forall>i\<in>I. \<mu> i (F i k) \<noteq> \<infinity>) \<and> incseq (\<lambda>k. \<Pi>\<^isub>E i\<in>I. F i k) \<and>
hoelzl@41981
   564
    (\<Union>k. \<Pi>\<^isub>E i\<in>I. F i k) = space G"
hoelzl@40859
   565
proof -
hoelzl@41981
   566
  have "\<forall>i::'i. \<exists>F::nat \<Rightarrow> 'a set. range F \<subseteq> sets (M i) \<and> incseq F \<and> (\<Union>i. F i) = space (M i) \<and> (\<forall>k. \<mu> i (F k) \<noteq> \<infinity>)"
hoelzl@40859
   567
    using M.sigma_finite_up by simp
hoelzl@40859
   568
  from choice[OF this] guess F :: "'i \<Rightarrow> nat \<Rightarrow> 'a set" ..
hoelzl@41981
   569
  then have F: "\<And>i. range (F i) \<subseteq> sets (M i)" "\<And>i. incseq (F i)" "\<And>i. (\<Union>j. F i j) = space (M i)" "\<And>i k. \<mu> i (F i k) \<noteq> \<infinity>"
hoelzl@40859
   570
    by auto
hoelzl@40859
   571
  let ?F = "\<lambda>k. \<Pi>\<^isub>E i\<in>I. F i k"
hoelzl@40859
   572
  note space_product_algebra[simp]
hoelzl@40859
   573
  show ?thesis
hoelzl@41981
   574
  proof (intro exI[of _ F] conjI allI incseq_SucI set_eqI iffI ballI)
hoelzl@40859
   575
    fix i show "range (F i) \<subseteq> sets (M i)" by fact
hoelzl@40859
   576
  next
hoelzl@41981
   577
    fix i k show "\<mu> i (F i k) \<noteq> \<infinity>" by fact
hoelzl@40859
   578
  next
hoelzl@40859
   579
    fix A assume "A \<in> (\<Union>i. ?F i)" then show "A \<in> space G"
hoelzl@41831
   580
      using `\<And>i. range (F i) \<subseteq> sets (M i)` M.sets_into_space
hoelzl@41831
   581
      by (force simp: image_subset_iff)
hoelzl@40859
   582
  next
hoelzl@40859
   583
    fix f assume "f \<in> space G"
hoelzl@41981
   584
    with Pi_UN[OF finite_index, of "\<lambda>k i. F i k"] F
hoelzl@41981
   585
    show "f \<in> (\<Union>i. ?F i)" by (auto simp: incseq_def)
hoelzl@40859
   586
  next
hoelzl@40859
   587
    fix i show "?F i \<subseteq> ?F (Suc i)"
hoelzl@41981
   588
      using `\<And>i. incseq (F i)`[THEN incseq_SucD] by auto
hoelzl@40859
   589
  qed
hoelzl@40859
   590
qed
hoelzl@40859
   591
hoelzl@41831
   592
lemma sets_pair_cancel_measure[simp]:
hoelzl@41831
   593
  "sets (M1\<lparr>measure := m1\<rparr> \<Otimes>\<^isub>M M2) = sets (M1 \<Otimes>\<^isub>M M2)"
hoelzl@41831
   594
  "sets (M1 \<Otimes>\<^isub>M M2\<lparr>measure := m2\<rparr>) = sets (M1 \<Otimes>\<^isub>M M2)"
hoelzl@41831
   595
  unfolding pair_measure_def pair_measure_generator_def sets_sigma
hoelzl@41831
   596
  by simp_all
hoelzl@41831
   597
hoelzl@41831
   598
lemma measurable_pair_cancel_measure[simp]:
hoelzl@41831
   599
  "measurable (M1\<lparr>measure := m1\<rparr> \<Otimes>\<^isub>M M2) M = measurable (M1 \<Otimes>\<^isub>M M2) M"
hoelzl@41831
   600
  "measurable (M1 \<Otimes>\<^isub>M M2\<lparr>measure := m2\<rparr>) M = measurable (M1 \<Otimes>\<^isub>M M2) M"
hoelzl@41831
   601
  "measurable M (M1\<lparr>measure := m3\<rparr> \<Otimes>\<^isub>M M2) = measurable M (M1 \<Otimes>\<^isub>M M2)"
hoelzl@41831
   602
  "measurable M (M1 \<Otimes>\<^isub>M M2\<lparr>measure := m4\<rparr>) = measurable M (M1 \<Otimes>\<^isub>M M2)"
hoelzl@41831
   603
  unfolding measurable_def by (auto simp add: space_pair_measure)
hoelzl@41831
   604
hoelzl@40859
   605
lemma (in product_sigma_finite) product_measure_exists:
hoelzl@40859
   606
  assumes "finite I"
hoelzl@41689
   607
  shows "\<exists>\<nu>. sigma_finite_measure (sigma (product_algebra_generator I M) \<lparr> measure := \<nu> \<rparr>) \<and>
hoelzl@41689
   608
    (\<forall>A\<in>\<Pi> i\<in>I. sets (M i). \<nu> (Pi\<^isub>E I A) = (\<Prod>i\<in>I. M.\<mu> i (A i)))"
hoelzl@40859
   609
using `finite I` proof induct
hoelzl@41689
   610
  case empty
hoelzl@41689
   611
  interpret finite_product_sigma_finite M "{}" by default simp
hoelzl@41981
   612
  let ?\<nu> = "(\<lambda>A. if A = {} then 0 else 1) :: 'd set \<Rightarrow> extreal"
hoelzl@41689
   613
  show ?case
hoelzl@41689
   614
  proof (intro exI conjI ballI)
hoelzl@41689
   615
    have "sigma_algebra (sigma G \<lparr>measure := ?\<nu>\<rparr>)"
hoelzl@41689
   616
      by (rule sigma_algebra_cong) (simp_all add: product_algebra_def)
hoelzl@41689
   617
    then have "measure_space (sigma G\<lparr>measure := ?\<nu>\<rparr>)"
hoelzl@41689
   618
      by (rule finite_additivity_sufficient)
hoelzl@41689
   619
         (simp_all add: positive_def additive_def sets_sigma
hoelzl@41689
   620
                        product_algebra_generator_def image_constant)
hoelzl@41689
   621
    then show "sigma_finite_measure (sigma G\<lparr>measure := ?\<nu>\<rparr>)"
hoelzl@41689
   622
      by (auto intro!: exI[of _ "\<lambda>i. {\<lambda>_. undefined}"]
hoelzl@41689
   623
               simp: sigma_finite_measure_def sigma_finite_measure_axioms_def
hoelzl@41689
   624
                     product_algebra_generator_def)
hoelzl@41689
   625
  qed auto
hoelzl@40859
   626
next
hoelzl@40859
   627
  case (insert i I)
hoelzl@41689
   628
  interpret finite_product_sigma_finite M I by default fact
hoelzl@40859
   629
  have "finite (insert i I)" using `finite I` by auto
hoelzl@41689
   630
  interpret I': finite_product_sigma_finite M "insert i I" by default fact
hoelzl@40859
   631
  from insert obtain \<nu> where
hoelzl@41689
   632
    prod: "\<And>A. A \<in> (\<Pi> i\<in>I. sets (M i)) \<Longrightarrow> \<nu> (Pi\<^isub>E I A) = (\<Prod>i\<in>I. M.\<mu> i (A i))" and
hoelzl@41689
   633
    "sigma_finite_measure (sigma G\<lparr> measure := \<nu> \<rparr>)" by auto
hoelzl@41689
   634
  then interpret I: sigma_finite_measure "P\<lparr> measure := \<nu>\<rparr>" unfolding product_algebra_def by simp
hoelzl@41689
   635
  interpret P: pair_sigma_finite "P\<lparr> measure := \<nu>\<rparr>" "M i" ..
hoelzl@41661
   636
  let ?h = "(\<lambda>(f, y). f(i := y))"
hoelzl@41689
   637
  let ?\<nu> = "\<lambda>A. P.\<mu> (?h -` A \<inter> space P.P)"
hoelzl@41689
   638
  have I': "sigma_algebra (I'.P\<lparr> measure := ?\<nu> \<rparr>)"
hoelzl@41689
   639
    by (rule I'.sigma_algebra_cong) simp_all
hoelzl@41689
   640
  interpret I'': measure_space "I'.P\<lparr> measure := ?\<nu> \<rparr>"
hoelzl@41689
   641
    using measurable_add_dim[OF `i \<notin> I`]
hoelzl@41831
   642
    by (intro P.measure_space_vimage[OF I']) (auto simp add: measure_preserving_def)
hoelzl@40859
   643
  show ?case
hoelzl@40859
   644
  proof (intro exI[of _ ?\<nu>] conjI ballI)
hoelzl@41689
   645
    let "?m A" = "measure (Pi\<^isub>M I M\<lparr>measure := \<nu>\<rparr> \<Otimes>\<^isub>M M i) (?h -` A \<inter> space P.P)"
hoelzl@40859
   646
    { fix A assume A: "A \<in> (\<Pi> i\<in>insert i I. sets (M i))"
hoelzl@41661
   647
      then have *: "?h -` Pi\<^isub>E (insert i I) A \<inter> space P.P = Pi\<^isub>E I A \<times> A i"
hoelzl@41689
   648
        using `i \<notin> I` M.sets_into_space by (auto simp: space_pair_measure space_product_algebra) blast
hoelzl@41689
   649
      show "?m (Pi\<^isub>E (insert i I) A) = (\<Prod>i\<in>insert i I. M.\<mu> i (A i))"
hoelzl@41661
   650
        unfolding * using A
hoelzl@40859
   651
        apply (subst P.pair_measure_times)
hoelzl@41661
   652
        using A apply fastsimp
hoelzl@41661
   653
        using A apply fastsimp
hoelzl@41661
   654
        using `i \<notin> I` `finite I` prod[of A] A by (auto simp: ac_simps) }
hoelzl@40859
   655
    note product = this
hoelzl@41689
   656
    have *: "sigma I'.G\<lparr> measure := ?\<nu> \<rparr> = I'.P\<lparr> measure := ?\<nu> \<rparr>"
hoelzl@41689
   657
      by (simp add: product_algebra_def)
hoelzl@41689
   658
    show "sigma_finite_measure (sigma I'.G\<lparr> measure := ?\<nu> \<rparr>)"
hoelzl@41689
   659
    proof (unfold *, default, simp)
hoelzl@40859
   660
      from I'.sigma_finite_pairs guess F :: "'i \<Rightarrow> nat \<Rightarrow> 'a set" ..
hoelzl@40859
   661
      then have F: "\<And>j. j \<in> insert i I \<Longrightarrow> range (F j) \<subseteq> sets (M j)"
hoelzl@41981
   662
        "incseq (\<lambda>k. \<Pi>\<^isub>E j \<in> insert i I. F j k)"
hoelzl@41981
   663
        "(\<Union>k. \<Pi>\<^isub>E j \<in> insert i I. F j k) = space I'.G"
hoelzl@41981
   664
        "\<And>k. \<And>j. j \<in> insert i I \<Longrightarrow> \<mu> j (F j k) \<noteq> \<infinity>"
hoelzl@40859
   665
        by blast+
hoelzl@40859
   666
      let "?F k" = "\<Pi>\<^isub>E j \<in> insert i I. F j k"
hoelzl@40859
   667
      show "\<exists>F::nat \<Rightarrow> ('i \<Rightarrow> 'a) set. range F \<subseteq> sets I'.P \<and>
hoelzl@41981
   668
          (\<Union>i. F i) = (\<Pi>\<^isub>E i\<in>insert i I. space (M i)) \<and> (\<forall>i. ?m (F i) \<noteq> \<infinity>)"
hoelzl@40859
   669
      proof (intro exI[of _ ?F] conjI allI)
hoelzl@40859
   670
        show "range ?F \<subseteq> sets I'.P" using F(1) by auto
hoelzl@40859
   671
      next
hoelzl@41981
   672
        from F(3) show "(\<Union>i. ?F i) = (\<Pi>\<^isub>E i\<in>insert i I. space (M i))" by simp
hoelzl@40859
   673
      next
hoelzl@40859
   674
        fix j
hoelzl@41981
   675
        have "\<And>k. k \<in> insert i I \<Longrightarrow> 0 \<le> measure (M k) (F k j)"
hoelzl@41981
   676
          using F(1) by auto
hoelzl@41981
   677
        with F `finite I` setprod_PInf[of "insert i I", OF this] show "?\<nu> (?F j) \<noteq> \<infinity>"
hoelzl@41981
   678
          by (subst product) auto
hoelzl@40859
   679
      qed
hoelzl@40859
   680
    qed
hoelzl@40859
   681
  qed
hoelzl@40859
   682
qed
hoelzl@40859
   683
hoelzl@41689
   684
sublocale finite_product_sigma_finite \<subseteq> sigma_finite_measure P
hoelzl@41689
   685
  unfolding product_algebra_def
hoelzl@41689
   686
  using product_measure_exists[OF finite_index]
hoelzl@41689
   687
  by (rule someI2_ex) auto
hoelzl@40859
   688
hoelzl@40859
   689
lemma (in finite_product_sigma_finite) measure_times:
hoelzl@40859
   690
  assumes "\<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (M i)"
hoelzl@41689
   691
  shows "\<mu> (Pi\<^isub>E I A) = (\<Prod>i\<in>I. M.\<mu> i (A i))"
hoelzl@41689
   692
  unfolding product_algebra_def
hoelzl@41689
   693
  using product_measure_exists[OF finite_index]
hoelzl@41689
   694
  proof (rule someI2_ex, elim conjE)
hoelzl@41689
   695
    fix \<nu> assume *: "\<forall>A\<in>\<Pi> i\<in>I. sets (M i). \<nu> (Pi\<^isub>E I A) = (\<Prod>i\<in>I. M.\<mu> i (A i))"
hoelzl@40859
   696
    have "Pi\<^isub>E I A = Pi\<^isub>E I (\<lambda>i\<in>I. A i)" by (auto dest: Pi_mem)
hoelzl@40859
   697
    then have "\<nu> (Pi\<^isub>E I A) = \<nu> (Pi\<^isub>E I (\<lambda>i\<in>I. A i))" by simp
hoelzl@41689
   698
    also have "\<dots> = (\<Prod>i\<in>I. M.\<mu> i ((\<lambda>i\<in>I. A i) i))" using assms * by auto
hoelzl@41689
   699
    finally show "measure (sigma G\<lparr>measure := \<nu>\<rparr>) (Pi\<^isub>E I A) = (\<Prod>i\<in>I. M.\<mu> i (A i))"
hoelzl@41689
   700
      by (simp add: sigma_def)
hoelzl@40859
   701
  qed
hoelzl@41096
   702
hoelzl@41096
   703
lemma (in product_sigma_finite) product_measure_empty[simp]:
hoelzl@41689
   704
  "measure (Pi\<^isub>M {} M) {\<lambda>x. undefined} = 1"
hoelzl@41096
   705
proof -
hoelzl@41689
   706
  interpret finite_product_sigma_finite M "{}" by default auto
hoelzl@41096
   707
  from measure_times[of "\<lambda>x. {}"] show ?thesis by simp
hoelzl@41096
   708
qed
hoelzl@41096
   709
hoelzl@41689
   710
lemma (in finite_product_sigma_algebra) P_empty:
hoelzl@41689
   711
  assumes "I = {}"
hoelzl@41689
   712
  shows "space P = {\<lambda>k. undefined}" "sets P = { {}, {\<lambda>k. undefined} }"
hoelzl@41689
   713
  unfolding product_algebra_def product_algebra_generator_def `I = {}`
hoelzl@41689
   714
  by (simp_all add: sigma_def image_constant)
hoelzl@41689
   715
hoelzl@40859
   716
lemma (in product_sigma_finite) positive_integral_empty:
hoelzl@41981
   717
  assumes pos: "0 \<le> f (\<lambda>k. undefined)"
hoelzl@41981
   718
  shows "integral\<^isup>P (Pi\<^isub>M {} M) f = f (\<lambda>k. undefined)"
hoelzl@40859
   719
proof -
hoelzl@41689
   720
  interpret finite_product_sigma_finite M "{}" by default (fact finite.emptyI)
hoelzl@41689
   721
  have "\<And>A. measure (Pi\<^isub>M {} M) (Pi\<^isub>E {} A) = 1"
hoelzl@40859
   722
    using assms by (subst measure_times) auto
hoelzl@40859
   723
  then show ?thesis
hoelzl@40873
   724
    unfolding positive_integral_def simple_function_def simple_integral_def_raw
hoelzl@40859
   725
  proof (simp add: P_empty, intro antisym)
hoelzl@41981
   726
    show "f (\<lambda>k. undefined) \<le> (SUP f:{g. g \<le> max 0 \<circ> f}. f (\<lambda>k. undefined))"
hoelzl@41981
   727
      by (intro le_SUPI) (auto simp: le_fun_def split: split_max)
hoelzl@41981
   728
    show "(SUP f:{g. g \<le> max 0 \<circ> f}. f (\<lambda>k. undefined)) \<le> f (\<lambda>k. undefined)" using pos
hoelzl@41981
   729
      by (intro SUP_leI) (auto simp: le_fun_def simp: max_def split: split_if_asm)
hoelzl@40859
   730
  qed
hoelzl@40859
   731
qed
hoelzl@40859
   732
hoelzl@41026
   733
lemma (in product_sigma_finite) measure_fold:
hoelzl@40859
   734
  assumes IJ[simp]: "I \<inter> J = {}" and fin: "finite I" "finite J"
hoelzl@41689
   735
  assumes A: "A \<in> sets (Pi\<^isub>M (I \<union> J) M)"
hoelzl@41706
   736
  shows "measure (Pi\<^isub>M (I \<union> J) M) A =
hoelzl@41706
   737
    measure (Pi\<^isub>M I M \<Otimes>\<^isub>M Pi\<^isub>M J M) ((\<lambda>(x,y). merge I x J y) -` A \<inter> space (Pi\<^isub>M I M \<Otimes>\<^isub>M Pi\<^isub>M J M))"
hoelzl@40859
   738
proof -
hoelzl@41689
   739
  interpret I: finite_product_sigma_finite M I by default fact
hoelzl@41689
   740
  interpret J: finite_product_sigma_finite M J by default fact
hoelzl@40859
   741
  have "finite (I \<union> J)" using fin by auto
hoelzl@41689
   742
  interpret IJ: finite_product_sigma_finite M "I \<union> J" by default fact
hoelzl@41689
   743
  interpret P: pair_sigma_finite I.P J.P by default
hoelzl@41661
   744
  let ?g = "\<lambda>(x,y). merge I x J y"
hoelzl@41661
   745
  let "?X S" = "?g -` S \<inter> space P.P"
hoelzl@41661
   746
  from IJ.sigma_finite_pairs obtain F where
hoelzl@41661
   747
    F: "\<And>i. i\<in> I \<union> J \<Longrightarrow> range (F i) \<subseteq> sets (M i)"
hoelzl@41981
   748
       "incseq (\<lambda>k. \<Pi>\<^isub>E i\<in>I \<union> J. F i k)"
hoelzl@41981
   749
       "(\<Union>k. \<Pi>\<^isub>E i\<in>I \<union> J. F i k) = space IJ.G"
hoelzl@41981
   750
       "\<And>k. \<forall>i\<in>I\<union>J. \<mu> i (F i k) \<noteq> \<infinity>"
hoelzl@41661
   751
    by auto
hoelzl@41661
   752
  let ?F = "\<lambda>k. \<Pi>\<^isub>E i\<in>I \<union> J. F i k"
hoelzl@41706
   753
  show "IJ.\<mu> A = P.\<mu> (?X A)"
hoelzl@41706
   754
  proof (rule measure_unique_Int_stable_vimage)
hoelzl@41706
   755
    show "measure_space IJ.P" "measure_space P.P" by default
hoelzl@41706
   756
    show "sets (sigma IJ.G) = sets IJ.P" "space IJ.G = space IJ.P" "A \<in> sets (sigma IJ.G)"
hoelzl@41689
   757
      using A unfolding product_algebra_def by auto
hoelzl@41706
   758
  next
hoelzl@41689
   759
    show "Int_stable IJ.G"
hoelzl@41689
   760
      by (simp add: PiE_Int Int_stable_def product_algebra_def
hoelzl@41689
   761
                    product_algebra_generator_def)
hoelzl@41689
   762
          auto
hoelzl@41689
   763
    show "range ?F \<subseteq> sets IJ.G" using F
hoelzl@41689
   764
      by (simp add: image_subset_iff product_algebra_def
hoelzl@41689
   765
                    product_algebra_generator_def)
hoelzl@41981
   766
    show "incseq ?F" "(\<Union>i. ?F i) = space IJ.G " by fact+
hoelzl@41981
   767
  next
hoelzl@41981
   768
    fix k
hoelzl@41981
   769
    have "\<And>j. j \<in> I \<union> J \<Longrightarrow> 0 \<le> measure (M j) (F j k)"
hoelzl@41981
   770
      using F(1) by auto
hoelzl@41981
   771
    with F `finite I` setprod_PInf[of "I \<union> J", OF this]
hoelzl@41981
   772
    show "IJ.\<mu> (?F k) \<noteq> \<infinity>" by (subst IJ.measure_times) auto
hoelzl@41661
   773
  next
hoelzl@41661
   774
    fix A assume "A \<in> sets IJ.G"
hoelzl@41706
   775
    then obtain F where A: "A = Pi\<^isub>E (I \<union> J) F"
hoelzl@41661
   776
      and F: "\<And>i. i \<in> I \<union> J \<Longrightarrow> F i \<in> sets (M i)"
hoelzl@41689
   777
      by (auto simp: product_algebra_generator_def)
hoelzl@41706
   778
    then have X: "?X A = (Pi\<^isub>E I F \<times> Pi\<^isub>E J F)"
hoelzl@41689
   779
      using sets_into_space by (auto simp: space_pair_measure) blast+
hoelzl@41689
   780
    then have "P.\<mu> (?X A) = (\<Prod>i\<in>I. \<mu> i (F i)) * (\<Prod>i\<in>J. \<mu> i (F i))"
hoelzl@41661
   781
      using `finite J` `finite I` F
hoelzl@41661
   782
      by (simp add: P.pair_measure_times I.measure_times J.measure_times)
hoelzl@41661
   783
    also have "\<dots> = (\<Prod>i\<in>I \<union> J. \<mu> i (F i))"
hoelzl@41661
   784
      using `finite J` `finite I` `I \<inter> J = {}`  by (simp add: setprod_Un_one)
hoelzl@41689
   785
    also have "\<dots> = IJ.\<mu> A"
hoelzl@41661
   786
      using `finite J` `finite I` F unfolding A
hoelzl@41661
   787
      by (intro IJ.measure_times[symmetric]) auto
hoelzl@41706
   788
    finally show "IJ.\<mu> A = P.\<mu> (?X A)" by (rule sym)
hoelzl@41981
   789
  qed (rule measurable_merge[OF IJ])
hoelzl@41661
   790
qed
hoelzl@41026
   791
hoelzl@41831
   792
lemma (in product_sigma_finite) measure_preserving_merge:
hoelzl@41831
   793
  assumes IJ: "I \<inter> J = {}" and "finite I" "finite J"
hoelzl@41831
   794
  shows "(\<lambda>(x,y). merge I x J y) \<in> measure_preserving (Pi\<^isub>M I M \<Otimes>\<^isub>M Pi\<^isub>M J M) (Pi\<^isub>M (I \<union> J) M)"
hoelzl@41831
   795
  by (intro measure_preservingI measurable_merge[OF IJ] measure_fold[symmetric] assms)
hoelzl@41831
   796
hoelzl@41026
   797
lemma (in product_sigma_finite) product_positive_integral_fold:
hoelzl@41831
   798
  assumes IJ[simp]: "I \<inter> J = {}" "finite I" "finite J"
hoelzl@41689
   799
  and f: "f \<in> borel_measurable (Pi\<^isub>M (I \<union> J) M)"
hoelzl@41689
   800
  shows "integral\<^isup>P (Pi\<^isub>M (I \<union> J) M) f =
hoelzl@41689
   801
    (\<integral>\<^isup>+ x. (\<integral>\<^isup>+ y. f (merge I x J y) \<partial>(Pi\<^isub>M J M)) \<partial>(Pi\<^isub>M I M))"
hoelzl@41026
   802
proof -
hoelzl@41689
   803
  interpret I: finite_product_sigma_finite M I by default fact
hoelzl@41689
   804
  interpret J: finite_product_sigma_finite M J by default fact
hoelzl@41831
   805
  interpret P: pair_sigma_finite "Pi\<^isub>M I M" "Pi\<^isub>M J M" by default
hoelzl@41831
   806
  interpret IJ: finite_product_sigma_finite M "I \<union> J" by default simp
hoelzl@41026
   807
  have P_borel: "(\<lambda>x. f (case x of (x, y) \<Rightarrow> merge I x J y)) \<in> borel_measurable P.P"
hoelzl@41831
   808
    using measurable_comp[OF measurable_merge[OF IJ(1)] f] by (simp add: comp_def)
hoelzl@41661
   809
  show ?thesis
hoelzl@41026
   810
    unfolding P.positive_integral_fst_measurable[OF P_borel, simplified]
hoelzl@41661
   811
  proof (rule P.positive_integral_vimage)
hoelzl@41661
   812
    show "sigma_algebra IJ.P" by default
hoelzl@41831
   813
    show "(\<lambda>(x, y). merge I x J y) \<in> measure_preserving P.P IJ.P"
hoelzl@41831
   814
      using IJ by (rule measure_preserving_merge)
hoelzl@41689
   815
    show "f \<in> borel_measurable IJ.P" using f by simp
hoelzl@41661
   816
  qed
hoelzl@40859
   817
qed
hoelzl@40859
   818
hoelzl@41831
   819
lemma (in product_sigma_finite) measure_preserving_component_singelton:
hoelzl@41831
   820
  "(\<lambda>x. x i) \<in> measure_preserving (Pi\<^isub>M {i} M) (M i)"
hoelzl@41831
   821
proof (intro measure_preservingI measurable_component_singleton)
hoelzl@41831
   822
  interpret I: finite_product_sigma_finite M "{i}" by default simp
hoelzl@41831
   823
  fix A let ?P = "(\<lambda>x. x i) -` A \<inter> space I.P"
hoelzl@41831
   824
  assume A: "A \<in> sets (M i)"
hoelzl@41831
   825
  then have *: "?P = {i} \<rightarrow>\<^isub>E A" using sets_into_space by auto
hoelzl@41831
   826
  show "I.\<mu> ?P = M.\<mu> i A" unfolding *
hoelzl@41831
   827
    using A I.measure_times[of "\<lambda>_. A"] by auto
hoelzl@41831
   828
qed auto
hoelzl@41831
   829
hoelzl@41026
   830
lemma (in product_sigma_finite) product_positive_integral_singleton:
hoelzl@40859
   831
  assumes f: "f \<in> borel_measurable (M i)"
hoelzl@41689
   832
  shows "integral\<^isup>P (Pi\<^isub>M {i} M) (\<lambda>x. f (x i)) = integral\<^isup>P (M i) f"
hoelzl@40859
   833
proof -
hoelzl@41689
   834
  interpret I: finite_product_sigma_finite M "{i}" by default simp
hoelzl@41689
   835
  show ?thesis
hoelzl@41689
   836
  proof (rule I.positive_integral_vimage[symmetric])
hoelzl@41689
   837
    show "sigma_algebra (M i)" by (rule sigma_algebras)
hoelzl@41831
   838
    show "(\<lambda>x. x i) \<in> measure_preserving (Pi\<^isub>M {i} M) (M i)"
hoelzl@41831
   839
      by (rule measure_preserving_component_singelton)
hoelzl@41689
   840
    show "f \<in> borel_measurable (M i)" by fact
hoelzl@41661
   841
  qed
hoelzl@40859
   842
qed
hoelzl@40859
   843
hoelzl@41096
   844
lemma (in product_sigma_finite) product_positive_integral_insert:
hoelzl@41096
   845
  assumes [simp]: "finite I" "i \<notin> I"
hoelzl@41689
   846
    and f: "f \<in> borel_measurable (Pi\<^isub>M (insert i I) M)"
hoelzl@41689
   847
  shows "integral\<^isup>P (Pi\<^isub>M (insert i I) M) f = (\<integral>\<^isup>+ x. (\<integral>\<^isup>+ y. f (x(i := y)) \<partial>(M i)) \<partial>(Pi\<^isub>M I M))"
hoelzl@41096
   848
proof -
hoelzl@41689
   849
  interpret I: finite_product_sigma_finite M I by default auto
hoelzl@41689
   850
  interpret i: finite_product_sigma_finite M "{i}" by default auto
hoelzl@41096
   851
  interpret P: pair_sigma_algebra I.P i.P ..
hoelzl@41689
   852
  have IJ: "I \<inter> {i} = {}" and insert: "I \<union> {i} = insert i I"
hoelzl@41689
   853
    using f by auto
hoelzl@41096
   854
  show ?thesis
hoelzl@41689
   855
    unfolding product_positive_integral_fold[OF IJ, unfolded insert, simplified, OF f]
hoelzl@41096
   856
  proof (rule I.positive_integral_cong, subst product_positive_integral_singleton)
hoelzl@41096
   857
    fix x assume x: "x \<in> space I.P"
hoelzl@41096
   858
    let "?f y" = "f (restrict (x(i := y)) (insert i I))"
hoelzl@41096
   859
    have f'_eq: "\<And>y. ?f y = f (x(i := y))"
hoelzl@41096
   860
      using x by (auto intro!: arg_cong[where f=f] simp: fun_eq_iff extensional_def)
hoelzl@41689
   861
    show "?f \<in> borel_measurable (M i)" unfolding f'_eq
hoelzl@41689
   862
      using measurable_comp[OF measurable_component_update f] x `i \<notin> I`
hoelzl@41689
   863
      by (simp add: comp_def)
hoelzl@41689
   864
    show "integral\<^isup>P (M i) ?f = \<integral>\<^isup>+ y. f (x(i:=y)) \<partial>M i"
hoelzl@41096
   865
      unfolding f'_eq by simp
hoelzl@41096
   866
  qed
hoelzl@41096
   867
qed
hoelzl@41096
   868
hoelzl@41096
   869
lemma (in product_sigma_finite) product_positive_integral_setprod:
hoelzl@41981
   870
  fixes f :: "'i \<Rightarrow> 'a \<Rightarrow> extreal"
hoelzl@41096
   871
  assumes "finite I" and borel: "\<And>i. i \<in> I \<Longrightarrow> f i \<in> borel_measurable (M i)"
hoelzl@41981
   872
  and pos: "\<And>i x. i \<in> I \<Longrightarrow> 0 \<le> f i x"
hoelzl@41689
   873
  shows "(\<integral>\<^isup>+ x. (\<Prod>i\<in>I. f i (x i)) \<partial>Pi\<^isub>M I M) = (\<Prod>i\<in>I. integral\<^isup>P (M i) (f i))"
hoelzl@41096
   874
using assms proof induct
hoelzl@41096
   875
  case empty
hoelzl@41689
   876
  interpret finite_product_sigma_finite M "{}" by default auto
hoelzl@41096
   877
  then show ?case by simp
hoelzl@41096
   878
next
hoelzl@41096
   879
  case (insert i I)
hoelzl@41096
   880
  note `finite I`[intro, simp]
hoelzl@41689
   881
  interpret I: finite_product_sigma_finite M I by default auto
hoelzl@41096
   882
  have *: "\<And>x y. (\<Prod>j\<in>I. f j (if j = i then y else x j)) = (\<Prod>j\<in>I. f j (x j))"
hoelzl@41096
   883
    using insert by (auto intro!: setprod_cong)
hoelzl@41689
   884
  have prod: "\<And>J. J \<subseteq> insert i I \<Longrightarrow> (\<lambda>x. (\<Prod>i\<in>J. f i (x i))) \<in> borel_measurable (Pi\<^isub>M J M)"
hoelzl@41096
   885
    using sets_into_space insert
hoelzl@41981
   886
    by (intro sigma_algebra.borel_measurable_extreal_setprod sigma_algebra_product_algebra
hoelzl@41689
   887
              measurable_comp[OF measurable_component_singleton, unfolded comp_def])
hoelzl@41096
   888
       auto
hoelzl@41981
   889
  then show ?case
hoelzl@41981
   890
    apply (simp add: product_positive_integral_insert[OF insert(1,2) prod])
hoelzl@41981
   891
    apply (simp add: insert * pos borel setprod_extreal_pos M.positive_integral_multc)
hoelzl@41981
   892
    apply (subst I.positive_integral_cmult)
hoelzl@41981
   893
    apply (auto simp add: pos borel insert setprod_extreal_pos positive_integral_positive)
hoelzl@41981
   894
    done
hoelzl@41096
   895
qed
hoelzl@41096
   896
hoelzl@41026
   897
lemma (in product_sigma_finite) product_integral_singleton:
hoelzl@41026
   898
  assumes f: "f \<in> borel_measurable (M i)"
hoelzl@41689
   899
  shows "(\<integral>x. f (x i) \<partial>Pi\<^isub>M {i} M) = integral\<^isup>L (M i) f"
hoelzl@41026
   900
proof -
hoelzl@41689
   901
  interpret I: finite_product_sigma_finite M "{i}" by default simp
hoelzl@41981
   902
  have *: "(\<lambda>x. extreal (f x)) \<in> borel_measurable (M i)"
hoelzl@41981
   903
    "(\<lambda>x. extreal (- f x)) \<in> borel_measurable (M i)"
hoelzl@41026
   904
    using assms by auto
hoelzl@41026
   905
  show ?thesis
hoelzl@41689
   906
    unfolding lebesgue_integral_def *[THEN product_positive_integral_singleton] ..
hoelzl@41026
   907
qed
hoelzl@41026
   908
hoelzl@41026
   909
lemma (in product_sigma_finite) product_integral_fold:
hoelzl@41026
   910
  assumes IJ[simp]: "I \<inter> J = {}" and fin: "finite I" "finite J"
hoelzl@41689
   911
  and f: "integrable (Pi\<^isub>M (I \<union> J) M) f"
hoelzl@41689
   912
  shows "integral\<^isup>L (Pi\<^isub>M (I \<union> J) M) f = (\<integral>x. (\<integral>y. f (merge I x J y) \<partial>Pi\<^isub>M J M) \<partial>Pi\<^isub>M I M)"
hoelzl@41026
   913
proof -
hoelzl@41689
   914
  interpret I: finite_product_sigma_finite M I by default fact
hoelzl@41689
   915
  interpret J: finite_product_sigma_finite M J by default fact
hoelzl@41026
   916
  have "finite (I \<union> J)" using fin by auto
hoelzl@41689
   917
  interpret IJ: finite_product_sigma_finite M "I \<union> J" by default fact
hoelzl@41689
   918
  interpret P: pair_sigma_finite I.P J.P by default
hoelzl@41689
   919
  let ?M = "\<lambda>(x, y). merge I x J y"
hoelzl@41689
   920
  let ?f = "\<lambda>x. f (?M x)"
hoelzl@41026
   921
  show ?thesis
hoelzl@41689
   922
  proof (subst P.integrable_fst_measurable(2)[of ?f, simplified])
hoelzl@41689
   923
    have 1: "sigma_algebra IJ.P" by default
hoelzl@41831
   924
    have 2: "?M \<in> measure_preserving P.P IJ.P" using measure_preserving_merge[OF assms(1,2,3)] .
hoelzl@41831
   925
    have 3: "integrable (Pi\<^isub>M (I \<union> J) M) f" by fact
hoelzl@41831
   926
    then have 4: "f \<in> borel_measurable (Pi\<^isub>M (I \<union> J) M)"
hoelzl@41831
   927
      by (simp add: integrable_def)
hoelzl@41689
   928
    show "integrable P.P ?f"
hoelzl@41831
   929
      by (rule P.integrable_vimage[where f=f, OF 1 2 3])
hoelzl@41689
   930
    show "integral\<^isup>L IJ.P f = integral\<^isup>L P.P ?f"
hoelzl@41831
   931
      by (rule P.integral_vimage[where f=f, OF 1 2 4])
hoelzl@41689
   932
  qed
hoelzl@41026
   933
qed
hoelzl@41026
   934
hoelzl@41096
   935
lemma (in product_sigma_finite) product_integral_insert:
hoelzl@41096
   936
  assumes [simp]: "finite I" "i \<notin> I"
hoelzl@41689
   937
    and f: "integrable (Pi\<^isub>M (insert i I) M) f"
hoelzl@41689
   938
  shows "integral\<^isup>L (Pi\<^isub>M (insert i I) M) f = (\<integral>x. (\<integral>y. f (x(i:=y)) \<partial>M i) \<partial>Pi\<^isub>M I M)"
hoelzl@41096
   939
proof -
hoelzl@41689
   940
  interpret I: finite_product_sigma_finite M I by default auto
hoelzl@41689
   941
  interpret I': finite_product_sigma_finite M "insert i I" by default auto
hoelzl@41689
   942
  interpret i: finite_product_sigma_finite M "{i}" by default auto
hoelzl@41689
   943
  interpret P: pair_sigma_finite I.P i.P ..
hoelzl@41096
   944
  have IJ: "I \<inter> {i} = {}" by auto
hoelzl@41096
   945
  show ?thesis
hoelzl@41096
   946
    unfolding product_integral_fold[OF IJ, simplified, OF f]
hoelzl@41096
   947
  proof (rule I.integral_cong, subst product_integral_singleton)
hoelzl@41096
   948
    fix x assume x: "x \<in> space I.P"
hoelzl@41096
   949
    let "?f y" = "f (restrict (x(i := y)) (insert i I))"
hoelzl@41096
   950
    have f'_eq: "\<And>y. ?f y = f (x(i := y))"
hoelzl@41096
   951
      using x by (auto intro!: arg_cong[where f=f] simp: fun_eq_iff extensional_def)
hoelzl@41689
   952
    have f: "f \<in> borel_measurable I'.P" using f unfolding integrable_def by auto
hoelzl@41096
   953
    show "?f \<in> borel_measurable (M i)"
hoelzl@41689
   954
      unfolding measurable_cong[OF f'_eq]
hoelzl@41689
   955
      using measurable_comp[OF measurable_component_update f] x `i \<notin> I`
hoelzl@41689
   956
      by (simp add: comp_def)
hoelzl@41689
   957
    show "integral\<^isup>L (M i) ?f = integral\<^isup>L (M i) (\<lambda>y. f (x(i := y)))"
hoelzl@41096
   958
      unfolding f'_eq by simp
hoelzl@41096
   959
  qed
hoelzl@41096
   960
qed
hoelzl@41096
   961
hoelzl@41096
   962
lemma (in product_sigma_finite) product_integrable_setprod:
hoelzl@41096
   963
  fixes f :: "'i \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@41689
   964
  assumes [simp]: "finite I" and integrable: "\<And>i. i \<in> I \<Longrightarrow> integrable (M i) (f i)"
hoelzl@41689
   965
  shows "integrable (Pi\<^isub>M I M) (\<lambda>x. (\<Prod>i\<in>I. f i (x i)))" (is "integrable _ ?f")
hoelzl@41096
   966
proof -
hoelzl@41689
   967
  interpret finite_product_sigma_finite M I by default fact
hoelzl@41096
   968
  have f: "\<And>i. i \<in> I \<Longrightarrow> f i \<in> borel_measurable (M i)"
hoelzl@41689
   969
    using integrable unfolding integrable_def by auto
hoelzl@41096
   970
  then have borel: "?f \<in> borel_measurable P"
hoelzl@41689
   971
    using measurable_comp[OF measurable_component_singleton f]
hoelzl@41689
   972
    by (auto intro!: borel_measurable_setprod simp: comp_def)
hoelzl@41689
   973
  moreover have "integrable (Pi\<^isub>M I M) (\<lambda>x. \<bar>\<Prod>i\<in>I. f i (x i)\<bar>)"
hoelzl@41096
   974
  proof (unfold integrable_def, intro conjI)
hoelzl@41096
   975
    show "(\<lambda>x. abs (?f x)) \<in> borel_measurable P"
hoelzl@41096
   976
      using borel by auto
hoelzl@41981
   977
    have "(\<integral>\<^isup>+x. extreal (abs (?f x)) \<partial>P) = (\<integral>\<^isup>+x. (\<Prod>i\<in>I. extreal (abs (f i (x i)))) \<partial>P)"
hoelzl@41981
   978
      by (simp add: setprod_extreal abs_setprod)
hoelzl@41981
   979
    also have "\<dots> = (\<Prod>i\<in>I. (\<integral>\<^isup>+x. extreal (abs (f i x)) \<partial>M i))"
hoelzl@41096
   980
      using f by (subst product_positive_integral_setprod) auto
hoelzl@41981
   981
    also have "\<dots> < \<infinity>"
hoelzl@41096
   982
      using integrable[THEN M.integrable_abs]
hoelzl@41981
   983
      by (simp add: setprod_PInf integrable_def M.positive_integral_positive)
hoelzl@41981
   984
    finally show "(\<integral>\<^isup>+x. extreal (abs (?f x)) \<partial>P) \<noteq> \<infinity>" by auto
hoelzl@41981
   985
    have "(\<integral>\<^isup>+x. extreal (- abs (?f x)) \<partial>P) = (\<integral>\<^isup>+x. 0 \<partial>P)"
hoelzl@41981
   986
      by (intro positive_integral_cong_pos) auto
hoelzl@41981
   987
    then show "(\<integral>\<^isup>+x. extreal (- abs (?f x)) \<partial>P) \<noteq> \<infinity>" by simp
hoelzl@41096
   988
  qed
hoelzl@41096
   989
  ultimately show ?thesis
hoelzl@41096
   990
    by (rule integrable_abs_iff[THEN iffD1])
hoelzl@41096
   991
qed
hoelzl@41096
   992
hoelzl@41096
   993
lemma (in product_sigma_finite) product_integral_setprod:
hoelzl@41096
   994
  fixes f :: "'i \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@41689
   995
  assumes "finite I" "I \<noteq> {}" and integrable: "\<And>i. i \<in> I \<Longrightarrow> integrable (M i) (f i)"
hoelzl@41689
   996
  shows "(\<integral>x. (\<Prod>i\<in>I. f i (x i)) \<partial>Pi\<^isub>M I M) = (\<Prod>i\<in>I. integral\<^isup>L (M i) (f i))"
hoelzl@41096
   997
using assms proof (induct rule: finite_ne_induct)
hoelzl@41096
   998
  case (singleton i)
hoelzl@41096
   999
  then show ?case by (simp add: product_integral_singleton integrable_def)
hoelzl@41096
  1000
next
hoelzl@41096
  1001
  case (insert i I)
hoelzl@41096
  1002
  then have iI: "finite (insert i I)" by auto
hoelzl@41096
  1003
  then have prod: "\<And>J. J \<subseteq> insert i I \<Longrightarrow>
hoelzl@41689
  1004
    integrable (Pi\<^isub>M J M) (\<lambda>x. (\<Prod>i\<in>J. f i (x i)))"
hoelzl@41096
  1005
    by (intro product_integrable_setprod insert(5)) (auto intro: finite_subset)
hoelzl@41689
  1006
  interpret I: finite_product_sigma_finite M I by default fact
hoelzl@41096
  1007
  have *: "\<And>x y. (\<Prod>j\<in>I. f j (if j = i then y else x j)) = (\<Prod>j\<in>I. f j (x j))"
hoelzl@41096
  1008
    using `i \<notin> I` by (auto intro!: setprod_cong)
hoelzl@41096
  1009
  show ?case
hoelzl@41096
  1010
    unfolding product_integral_insert[OF insert(1,3) prod[OF subset_refl]]
hoelzl@41096
  1011
    by (simp add: * insert integral_multc I.integral_cmult[OF prod] subset_insertI)
hoelzl@41096
  1012
qed
hoelzl@41096
  1013
hoelzl@40859
  1014
end