src/HOL/Probability/Sigma_Algebra.thy
author haftmann
Sun Jun 23 21:16:07 2013 +0200 (2013-06-23)
changeset 52435 6646bb548c6b
parent 51683 baefa3b461c2
child 53374 a14d2a854c02
permissions -rw-r--r--
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
wenzelm@41983
     1
(*  Title:      HOL/Probability/Sigma_Algebra.thy
hoelzl@42067
     2
    Author:     Stefan Richter, Markus Wenzel, TU München
hoelzl@42067
     3
    Author:     Johannes Hölzl, TU München
hoelzl@41981
     4
    Plus material from the Hurd/Coble measure theory development,
hoelzl@41981
     5
    translated by Lawrence Paulson.
paulson@33271
     6
*)
paulson@33271
     7
paulson@33271
     8
header {* Sigma Algebras *}
paulson@33271
     9
wenzelm@41413
    10
theory Sigma_Algebra
wenzelm@41413
    11
imports
hoelzl@42145
    12
  Complex_Main
immler@50245
    13
  "~~/src/HOL/Library/Countable_Set"
wenzelm@41413
    14
  "~~/src/HOL/Library/FuncSet"
wenzelm@41413
    15
  "~~/src/HOL/Library/Indicator_Function"
hoelzl@47694
    16
  "~~/src/HOL/Library/Extended_Real"
wenzelm@41413
    17
begin
paulson@33271
    18
paulson@33271
    19
text {* Sigma algebras are an elementary concept in measure
paulson@33271
    20
  theory. To measure --- that is to integrate --- functions, we first have
paulson@33271
    21
  to measure sets. Unfortunately, when dealing with a large universe,
paulson@33271
    22
  it is often not possible to consistently assign a measure to every
paulson@33271
    23
  subset. Therefore it is necessary to define the set of measurable
paulson@33271
    24
  subsets of the universe. A sigma algebra is such a set that has
paulson@33271
    25
  three very natural and desirable properties. *}
paulson@33271
    26
hoelzl@47762
    27
subsection {* Families of sets *}
paulson@33271
    28
hoelzl@47694
    29
locale subset_class =
hoelzl@47694
    30
  fixes \<Omega> :: "'a set" and M :: "'a set set"
hoelzl@47694
    31
  assumes space_closed: "M \<subseteq> Pow \<Omega>"
paulson@33271
    32
hoelzl@47694
    33
lemma (in subset_class) sets_into_space: "x \<in> M \<Longrightarrow> x \<subseteq> \<Omega>"
paulson@33271
    34
  by (metis PowD contra_subsetD space_closed)
paulson@33271
    35
hoelzl@47762
    36
subsection {* Semiring of sets *}
hoelzl@47762
    37
hoelzl@47762
    38
subsubsection {* Disjoint sets *}
hoelzl@47762
    39
hoelzl@47762
    40
definition "disjoint A \<longleftrightarrow> (\<forall>a\<in>A. \<forall>b\<in>A. a \<noteq> b \<longrightarrow> a \<inter> b = {})"
hoelzl@47762
    41
hoelzl@47762
    42
lemma disjointI:
hoelzl@47762
    43
  "(\<And>a b. a \<in> A \<Longrightarrow> b \<in> A \<Longrightarrow> a \<noteq> b \<Longrightarrow> a \<inter> b = {}) \<Longrightarrow> disjoint A"
hoelzl@47762
    44
  unfolding disjoint_def by auto
hoelzl@47762
    45
hoelzl@47762
    46
lemma disjointD:
hoelzl@47762
    47
  "disjoint A \<Longrightarrow> a \<in> A \<Longrightarrow> b \<in> A \<Longrightarrow> a \<noteq> b \<Longrightarrow> a \<inter> b = {}"
hoelzl@47762
    48
  unfolding disjoint_def by auto
hoelzl@47762
    49
hoelzl@47762
    50
lemma disjoint_empty[iff]: "disjoint {}"
hoelzl@47762
    51
  by (auto simp: disjoint_def)
hoelzl@42065
    52
hoelzl@47762
    53
lemma disjoint_union: 
hoelzl@47762
    54
  assumes C: "disjoint C" and B: "disjoint B" and disj: "\<Union>C \<inter> \<Union>B = {}"
hoelzl@47762
    55
  shows "disjoint (C \<union> B)"
hoelzl@47762
    56
proof (rule disjointI)
hoelzl@47762
    57
  fix c d assume sets: "c \<in> C \<union> B" "d \<in> C \<union> B" and "c \<noteq> d"
hoelzl@47762
    58
  show "c \<inter> d = {}"
hoelzl@47762
    59
  proof cases
hoelzl@47762
    60
    assume "(c \<in> C \<and> d \<in> C) \<or> (c \<in> B \<and> d \<in> B)"
hoelzl@47762
    61
    then show ?thesis
hoelzl@47762
    62
    proof 
hoelzl@47762
    63
      assume "c \<in> C \<and> d \<in> C" with `c \<noteq> d` C show "c \<inter> d = {}"
hoelzl@47762
    64
        by (auto simp: disjoint_def)
hoelzl@47762
    65
    next
hoelzl@47762
    66
      assume "c \<in> B \<and> d \<in> B" with `c \<noteq> d` B show "c \<inter> d = {}"
hoelzl@47762
    67
        by (auto simp: disjoint_def)
hoelzl@47762
    68
    qed
hoelzl@47762
    69
  next
hoelzl@47762
    70
    assume "\<not> ((c \<in> C \<and> d \<in> C) \<or> (c \<in> B \<and> d \<in> B))"
hoelzl@47762
    71
    with sets have "(c \<subseteq> \<Union>C \<and> d \<subseteq> \<Union>B) \<or> (c \<subseteq> \<Union>B \<and> d \<subseteq> \<Union>C)"
hoelzl@47762
    72
      by auto
hoelzl@47762
    73
    with disj show "c \<inter> d = {}" by auto
hoelzl@47762
    74
  qed
hoelzl@47762
    75
qed
hoelzl@47762
    76
hoelzl@47762
    77
locale semiring_of_sets = subset_class +
hoelzl@47762
    78
  assumes empty_sets[iff]: "{} \<in> M"
hoelzl@47762
    79
  assumes Int[intro]: "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> a \<inter> b \<in> M"
hoelzl@47762
    80
  assumes Diff_cover:
hoelzl@47762
    81
    "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> \<exists>C\<subseteq>M. finite C \<and> disjoint C \<and> a - b = \<Union>C"
hoelzl@47762
    82
hoelzl@47762
    83
lemma (in semiring_of_sets) finite_INT[intro]:
hoelzl@47762
    84
  assumes "finite I" "I \<noteq> {}" "\<And>i. i \<in> I \<Longrightarrow> A i \<in> M"
hoelzl@47762
    85
  shows "(\<Inter>i\<in>I. A i) \<in> M"
hoelzl@47762
    86
  using assms by (induct rule: finite_ne_induct) auto
hoelzl@47762
    87
hoelzl@47762
    88
lemma (in semiring_of_sets) Int_space_eq1 [simp]: "x \<in> M \<Longrightarrow> \<Omega> \<inter> x = x"
hoelzl@47762
    89
  by (metis Int_absorb1 sets_into_space)
hoelzl@47762
    90
hoelzl@47762
    91
lemma (in semiring_of_sets) Int_space_eq2 [simp]: "x \<in> M \<Longrightarrow> x \<inter> \<Omega> = x"
hoelzl@47762
    92
  by (metis Int_absorb2 sets_into_space)
hoelzl@47762
    93
hoelzl@47762
    94
lemma (in semiring_of_sets) sets_Collect_conj:
hoelzl@47762
    95
  assumes "{x\<in>\<Omega>. P x} \<in> M" "{x\<in>\<Omega>. Q x} \<in> M"
hoelzl@47762
    96
  shows "{x\<in>\<Omega>. Q x \<and> P x} \<in> M"
paulson@33271
    97
proof -
hoelzl@47762
    98
  have "{x\<in>\<Omega>. Q x \<and> P x} = {x\<in>\<Omega>. Q x} \<inter> {x\<in>\<Omega>. P x}"
hoelzl@42065
    99
    by auto
hoelzl@47762
   100
  with assms show ?thesis by auto
paulson@33271
   101
qed
paulson@33271
   102
hoelzl@50002
   103
lemma (in semiring_of_sets) sets_Collect_finite_All':
hoelzl@47762
   104
  assumes "\<And>i. i \<in> S \<Longrightarrow> {x\<in>\<Omega>. P i x} \<in> M" "finite S" "S \<noteq> {}"
hoelzl@47762
   105
  shows "{x\<in>\<Omega>. \<forall>i\<in>S. P i x} \<in> M"
hoelzl@47762
   106
proof -
hoelzl@47762
   107
  have "{x\<in>\<Omega>. \<forall>i\<in>S. P i x} = (\<Inter>i\<in>S. {x\<in>\<Omega>. P i x})"
hoelzl@47762
   108
    using `S \<noteq> {}` by auto
hoelzl@47762
   109
  with assms show ?thesis by auto
hoelzl@47762
   110
qed
hoelzl@47762
   111
hoelzl@47762
   112
locale ring_of_sets = semiring_of_sets +
hoelzl@47762
   113
  assumes Un [intro]: "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> a \<union> b \<in> M"
hoelzl@47762
   114
hoelzl@42065
   115
lemma (in ring_of_sets) finite_Union [intro]:
hoelzl@47694
   116
  "finite X \<Longrightarrow> X \<subseteq> M \<Longrightarrow> Union X \<in> M"
hoelzl@38656
   117
  by (induct set: finite) (auto simp add: Un)
paulson@33271
   118
hoelzl@42065
   119
lemma (in ring_of_sets) finite_UN[intro]:
hoelzl@47694
   120
  assumes "finite I" and "\<And>i. i \<in> I \<Longrightarrow> A i \<in> M"
hoelzl@47694
   121
  shows "(\<Union>i\<in>I. A i) \<in> M"
hoelzl@41981
   122
  using assms by induct auto
hoelzl@41981
   123
hoelzl@47762
   124
lemma (in ring_of_sets) Diff [intro]:
hoelzl@47762
   125
  assumes "a \<in> M" "b \<in> M" shows "a - b \<in> M"
hoelzl@47762
   126
  using Diff_cover[OF assms] by auto
hoelzl@47762
   127
hoelzl@47762
   128
lemma ring_of_setsI:
hoelzl@47762
   129
  assumes space_closed: "M \<subseteq> Pow \<Omega>"
hoelzl@47762
   130
  assumes empty_sets[iff]: "{} \<in> M"
hoelzl@47762
   131
  assumes Un[intro]: "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> a \<union> b \<in> M"
hoelzl@47762
   132
  assumes Diff[intro]: "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> a - b \<in> M"
hoelzl@47762
   133
  shows "ring_of_sets \<Omega> M"
hoelzl@47762
   134
proof
hoelzl@47762
   135
  fix a b assume ab: "a \<in> M" "b \<in> M"
hoelzl@47762
   136
  from ab show "\<exists>C\<subseteq>M. finite C \<and> disjoint C \<and> a - b = \<Union>C"
hoelzl@47762
   137
    by (intro exI[of _ "{a - b}"]) (auto simp: disjoint_def)
hoelzl@47762
   138
  have "a \<inter> b = a - (a - b)" by auto
hoelzl@47762
   139
  also have "\<dots> \<in> M" using ab by auto
hoelzl@47762
   140
  finally show "a \<inter> b \<in> M" .
hoelzl@47762
   141
qed fact+
hoelzl@47762
   142
hoelzl@47762
   143
lemma ring_of_sets_iff: "ring_of_sets \<Omega> M \<longleftrightarrow> M \<subseteq> Pow \<Omega> \<and> {} \<in> M \<and> (\<forall>a\<in>M. \<forall>b\<in>M. a \<union> b \<in> M) \<and> (\<forall>a\<in>M. \<forall>b\<in>M. a - b \<in> M)"
hoelzl@47762
   144
proof
hoelzl@47762
   145
  assume "ring_of_sets \<Omega> M"
hoelzl@47762
   146
  then interpret ring_of_sets \<Omega> M .
hoelzl@47762
   147
  show "M \<subseteq> Pow \<Omega> \<and> {} \<in> M \<and> (\<forall>a\<in>M. \<forall>b\<in>M. a \<union> b \<in> M) \<and> (\<forall>a\<in>M. \<forall>b\<in>M. a - b \<in> M)"
hoelzl@47762
   148
    using space_closed by auto
hoelzl@47762
   149
qed (auto intro!: ring_of_setsI)
hoelzl@41981
   150
hoelzl@42065
   151
lemma (in ring_of_sets) insert_in_sets:
hoelzl@47694
   152
  assumes "{x} \<in> M" "A \<in> M" shows "insert x A \<in> M"
hoelzl@38656
   153
proof -
hoelzl@47694
   154
  have "{x} \<union> A \<in> M" using assms by (rule Un)
hoelzl@38656
   155
  thus ?thesis by auto
hoelzl@38656
   156
qed
hoelzl@38656
   157
hoelzl@42867
   158
lemma (in ring_of_sets) sets_Collect_disj:
hoelzl@47694
   159
  assumes "{x\<in>\<Omega>. P x} \<in> M" "{x\<in>\<Omega>. Q x} \<in> M"
hoelzl@47694
   160
  shows "{x\<in>\<Omega>. Q x \<or> P x} \<in> M"
hoelzl@42867
   161
proof -
hoelzl@47694
   162
  have "{x\<in>\<Omega>. Q x \<or> P x} = {x\<in>\<Omega>. Q x} \<union> {x\<in>\<Omega>. P x}"
hoelzl@42867
   163
    by auto
hoelzl@42867
   164
  with assms show ?thesis by auto
hoelzl@42867
   165
qed
hoelzl@42867
   166
hoelzl@42867
   167
lemma (in ring_of_sets) sets_Collect_finite_Ex:
hoelzl@47694
   168
  assumes "\<And>i. i \<in> S \<Longrightarrow> {x\<in>\<Omega>. P i x} \<in> M" "finite S"
hoelzl@47694
   169
  shows "{x\<in>\<Omega>. \<exists>i\<in>S. P i x} \<in> M"
hoelzl@42867
   170
proof -
hoelzl@47694
   171
  have "{x\<in>\<Omega>. \<exists>i\<in>S. P i x} = (\<Union>i\<in>S. {x\<in>\<Omega>. P i x})"
hoelzl@42867
   172
    by auto
hoelzl@42867
   173
  with assms show ?thesis by auto
hoelzl@42867
   174
qed
hoelzl@42867
   175
hoelzl@42065
   176
locale algebra = ring_of_sets +
hoelzl@47694
   177
  assumes top [iff]: "\<Omega> \<in> M"
hoelzl@42065
   178
hoelzl@42065
   179
lemma (in algebra) compl_sets [intro]:
hoelzl@47694
   180
  "a \<in> M \<Longrightarrow> \<Omega> - a \<in> M"
hoelzl@42065
   181
  by auto
hoelzl@42065
   182
hoelzl@42065
   183
lemma algebra_iff_Un:
hoelzl@47694
   184
  "algebra \<Omega> M \<longleftrightarrow>
hoelzl@47694
   185
    M \<subseteq> Pow \<Omega> \<and>
hoelzl@47694
   186
    {} \<in> M \<and>
hoelzl@47694
   187
    (\<forall>a \<in> M. \<Omega> - a \<in> M) \<and>
hoelzl@47694
   188
    (\<forall>a \<in> M. \<forall> b \<in> M. a \<union> b \<in> M)" (is "_ \<longleftrightarrow> ?Un")
hoelzl@42065
   189
proof
hoelzl@47694
   190
  assume "algebra \<Omega> M"
hoelzl@47694
   191
  then interpret algebra \<Omega> M .
hoelzl@42065
   192
  show ?Un using sets_into_space by auto
hoelzl@42065
   193
next
hoelzl@42065
   194
  assume ?Un
hoelzl@47762
   195
  then have "\<Omega> \<in> M" by auto
hoelzl@47762
   196
  interpret ring_of_sets \<Omega> M
hoelzl@47762
   197
  proof (rule ring_of_setsI)
hoelzl@47762
   198
    show \<Omega>: "M \<subseteq> Pow \<Omega>" "{} \<in> M"
hoelzl@42065
   199
      using `?Un` by auto
hoelzl@47694
   200
    fix a b assume a: "a \<in> M" and b: "b \<in> M"
hoelzl@47694
   201
    then show "a \<union> b \<in> M" using `?Un` by auto
hoelzl@47694
   202
    have "a - b = \<Omega> - ((\<Omega> - a) \<union> b)"
hoelzl@47694
   203
      using \<Omega> a b by auto
hoelzl@47694
   204
    then show "a - b \<in> M"
hoelzl@42065
   205
      using a b  `?Un` by auto
hoelzl@42065
   206
  qed
hoelzl@47762
   207
  show "algebra \<Omega> M" proof qed fact
hoelzl@42065
   208
qed
hoelzl@42065
   209
hoelzl@42065
   210
lemma algebra_iff_Int:
hoelzl@47694
   211
     "algebra \<Omega> M \<longleftrightarrow>
hoelzl@47694
   212
       M \<subseteq> Pow \<Omega> & {} \<in> M &
hoelzl@47694
   213
       (\<forall>a \<in> M. \<Omega> - a \<in> M) &
hoelzl@47694
   214
       (\<forall>a \<in> M. \<forall> b \<in> M. a \<inter> b \<in> M)" (is "_ \<longleftrightarrow> ?Int")
hoelzl@42065
   215
proof
hoelzl@47694
   216
  assume "algebra \<Omega> M"
hoelzl@47694
   217
  then interpret algebra \<Omega> M .
hoelzl@42065
   218
  show ?Int using sets_into_space by auto
hoelzl@42065
   219
next
hoelzl@42065
   220
  assume ?Int
hoelzl@47694
   221
  show "algebra \<Omega> M"
hoelzl@42065
   222
  proof (unfold algebra_iff_Un, intro conjI ballI)
hoelzl@47694
   223
    show \<Omega>: "M \<subseteq> Pow \<Omega>" "{} \<in> M"
hoelzl@42065
   224
      using `?Int` by auto
hoelzl@47694
   225
    from `?Int` show "\<And>a. a \<in> M \<Longrightarrow> \<Omega> - a \<in> M" by auto
hoelzl@47694
   226
    fix a b assume M: "a \<in> M" "b \<in> M"
hoelzl@47694
   227
    hence "a \<union> b = \<Omega> - ((\<Omega> - a) \<inter> (\<Omega> - b))"
hoelzl@47694
   228
      using \<Omega> by blast
hoelzl@47694
   229
    also have "... \<in> M"
hoelzl@47694
   230
      using M `?Int` by auto
hoelzl@47694
   231
    finally show "a \<union> b \<in> M" .
hoelzl@42065
   232
  qed
hoelzl@42065
   233
qed
hoelzl@42065
   234
hoelzl@42867
   235
lemma (in algebra) sets_Collect_neg:
hoelzl@47694
   236
  assumes "{x\<in>\<Omega>. P x} \<in> M"
hoelzl@47694
   237
  shows "{x\<in>\<Omega>. \<not> P x} \<in> M"
hoelzl@42867
   238
proof -
hoelzl@47694
   239
  have "{x\<in>\<Omega>. \<not> P x} = \<Omega> - {x\<in>\<Omega>. P x}" by auto
hoelzl@42867
   240
  with assms show ?thesis by auto
hoelzl@42867
   241
qed
hoelzl@42867
   242
hoelzl@42867
   243
lemma (in algebra) sets_Collect_imp:
hoelzl@47694
   244
  "{x\<in>\<Omega>. P x} \<in> M \<Longrightarrow> {x\<in>\<Omega>. Q x} \<in> M \<Longrightarrow> {x\<in>\<Omega>. Q x \<longrightarrow> P x} \<in> M"
hoelzl@42867
   245
  unfolding imp_conv_disj by (intro sets_Collect_disj sets_Collect_neg)
hoelzl@42867
   246
hoelzl@42867
   247
lemma (in algebra) sets_Collect_const:
hoelzl@47694
   248
  "{x\<in>\<Omega>. P} \<in> M"
hoelzl@42867
   249
  by (cases P) auto
hoelzl@42867
   250
hoelzl@42984
   251
lemma algebra_single_set:
hoelzl@47762
   252
  "X \<subseteq> S \<Longrightarrow> algebra S { {}, X, S - X, S }"
hoelzl@47762
   253
  by (auto simp: algebra_iff_Int)
hoelzl@42984
   254
hoelzl@50387
   255
subsection {* Restricted algebras *}
hoelzl@39092
   256
hoelzl@39092
   257
abbreviation (in algebra)
hoelzl@47694
   258
  "restricted_space A \<equiv> (op \<inter> A) ` M"
hoelzl@39092
   259
hoelzl@38656
   260
lemma (in algebra) restricted_algebra:
hoelzl@47694
   261
  assumes "A \<in> M" shows "algebra A (restricted_space A)"
hoelzl@47762
   262
  using assms by (auto simp: algebra_iff_Int)
paulson@33271
   263
paulson@33271
   264
subsection {* Sigma Algebras *}
paulson@33271
   265
paulson@33271
   266
locale sigma_algebra = algebra +
hoelzl@47694
   267
  assumes countable_nat_UN [intro]: "\<And>A. range A \<subseteq> M \<Longrightarrow> (\<Union>i::nat. A i) \<in> M"
paulson@33271
   268
hoelzl@42984
   269
lemma (in algebra) is_sigma_algebra:
hoelzl@47694
   270
  assumes "finite M"
hoelzl@47694
   271
  shows "sigma_algebra \<Omega> M"
hoelzl@42984
   272
proof
hoelzl@47694
   273
  fix A :: "nat \<Rightarrow> 'a set" assume "range A \<subseteq> M"
hoelzl@47694
   274
  then have "(\<Union>i. A i) = (\<Union>s\<in>M \<inter> range A. s)"
hoelzl@42984
   275
    by auto
hoelzl@47694
   276
  also have "(\<Union>s\<in>M \<inter> range A. s) \<in> M"
hoelzl@47694
   277
    using `finite M` by auto
hoelzl@47694
   278
  finally show "(\<Union>i. A i) \<in> M" .
hoelzl@42984
   279
qed
hoelzl@42984
   280
hoelzl@38656
   281
lemma countable_UN_eq:
hoelzl@38656
   282
  fixes A :: "'i::countable \<Rightarrow> 'a set"
hoelzl@47694
   283
  shows "(range A \<subseteq> M \<longrightarrow> (\<Union>i. A i) \<in> M) \<longleftrightarrow>
hoelzl@47694
   284
    (range (A \<circ> from_nat) \<subseteq> M \<longrightarrow> (\<Union>i. (A \<circ> from_nat) i) \<in> M)"
hoelzl@38656
   285
proof -
hoelzl@38656
   286
  let ?A' = "A \<circ> from_nat"
hoelzl@38656
   287
  have *: "(\<Union>i. ?A' i) = (\<Union>i. A i)" (is "?l = ?r")
hoelzl@38656
   288
  proof safe
hoelzl@38656
   289
    fix x i assume "x \<in> A i" thus "x \<in> ?l"
hoelzl@38656
   290
      by (auto intro!: exI[of _ "to_nat i"])
hoelzl@38656
   291
  next
hoelzl@38656
   292
    fix x i assume "x \<in> ?A' i" thus "x \<in> ?r"
hoelzl@38656
   293
      by (auto intro!: exI[of _ "from_nat i"])
hoelzl@38656
   294
  qed
hoelzl@38656
   295
  have **: "range ?A' = range A"
hoelzl@40702
   296
    using surj_from_nat
hoelzl@38656
   297
    by (auto simp: image_compose intro!: imageI)
hoelzl@38656
   298
  show ?thesis unfolding * ** ..
hoelzl@38656
   299
qed
hoelzl@38656
   300
immler@50245
   301
lemma (in sigma_algebra) countable_Union [intro]:
immler@50245
   302
  assumes "countable X" "X \<subseteq> M" shows "Union X \<in> M"
immler@50245
   303
proof cases
immler@50245
   304
  assume "X \<noteq> {}"
immler@50245
   305
  hence "\<Union>X = (\<Union>n. from_nat_into X n)"
immler@50245
   306
    using assms by (auto intro: from_nat_into) (metis from_nat_into_surj)
immler@50245
   307
  also have "\<dots> \<in> M" using assms
immler@50245
   308
    by (auto intro!: countable_nat_UN) (metis `X \<noteq> {}` from_nat_into set_mp)
immler@50245
   309
  finally show ?thesis .
immler@50245
   310
qed simp
immler@50245
   311
hoelzl@38656
   312
lemma (in sigma_algebra) countable_UN[intro]:
hoelzl@38656
   313
  fixes A :: "'i::countable \<Rightarrow> 'a set"
hoelzl@47694
   314
  assumes "A`X \<subseteq> M"
hoelzl@47694
   315
  shows  "(\<Union>x\<in>X. A x) \<in> M"
hoelzl@38656
   316
proof -
wenzelm@46731
   317
  let ?A = "\<lambda>i. if i \<in> X then A i else {}"
hoelzl@47694
   318
  from assms have "range ?A \<subseteq> M" by auto
hoelzl@38656
   319
  with countable_nat_UN[of "?A \<circ> from_nat"] countable_UN_eq[of ?A M]
hoelzl@47694
   320
  have "(\<Union>x. ?A x) \<in> M" by auto
hoelzl@38656
   321
  moreover have "(\<Union>x. ?A x) = (\<Union>x\<in>X. A x)" by (auto split: split_if_asm)
hoelzl@38656
   322
  ultimately show ?thesis by simp
hoelzl@38656
   323
qed
hoelzl@38656
   324
hoelzl@50526
   325
lemma (in sigma_algebra) countable_UN':
hoelzl@50526
   326
  fixes A :: "'i \<Rightarrow> 'a set"
hoelzl@50526
   327
  assumes X: "countable X"
hoelzl@50526
   328
  assumes A: "A`X \<subseteq> M"
hoelzl@50526
   329
  shows  "(\<Union>x\<in>X. A x) \<in> M"
hoelzl@50526
   330
proof -
hoelzl@50526
   331
  have "(\<Union>x\<in>X. A x) = (\<Union>i\<in>to_nat_on X ` X. A (from_nat_into X i))"
hoelzl@50526
   332
    using X by auto
hoelzl@50526
   333
  also have "\<dots> \<in> M"
hoelzl@50526
   334
    using A X
hoelzl@50526
   335
    by (intro countable_UN) auto
hoelzl@50526
   336
  finally show ?thesis .
hoelzl@50526
   337
qed
hoelzl@50526
   338
paulson@33533
   339
lemma (in sigma_algebra) countable_INT [intro]:
hoelzl@38656
   340
  fixes A :: "'i::countable \<Rightarrow> 'a set"
hoelzl@47694
   341
  assumes A: "A`X \<subseteq> M" "X \<noteq> {}"
hoelzl@47694
   342
  shows "(\<Inter>i\<in>X. A i) \<in> M"
paulson@33271
   343
proof -
hoelzl@47694
   344
  from A have "\<forall>i\<in>X. A i \<in> M" by fast
hoelzl@47694
   345
  hence "\<Omega> - (\<Union>i\<in>X. \<Omega> - A i) \<in> M" by blast
paulson@33271
   346
  moreover
hoelzl@47694
   347
  have "(\<Inter>i\<in>X. A i) = \<Omega> - (\<Union>i\<in>X. \<Omega> - A i)" using space_closed A
paulson@33271
   348
    by blast
paulson@33271
   349
  ultimately show ?thesis by metis
paulson@33271
   350
qed
paulson@33271
   351
hoelzl@50526
   352
lemma (in sigma_algebra) countable_INT':
hoelzl@50526
   353
  fixes A :: "'i \<Rightarrow> 'a set"
hoelzl@50526
   354
  assumes X: "countable X" "X \<noteq> {}"
hoelzl@50526
   355
  assumes A: "A`X \<subseteq> M"
hoelzl@50526
   356
  shows  "(\<Inter>x\<in>X. A x) \<in> M"
hoelzl@50526
   357
proof -
hoelzl@50526
   358
  have "(\<Inter>x\<in>X. A x) = (\<Inter>i\<in>to_nat_on X ` X. A (from_nat_into X i))"
hoelzl@50526
   359
    using X by auto
hoelzl@50526
   360
  also have "\<dots> \<in> M"
hoelzl@50526
   361
    using A X
hoelzl@50526
   362
    by (intro countable_INT) auto
hoelzl@50526
   363
  finally show ?thesis .
hoelzl@50526
   364
qed
hoelzl@50526
   365
hoelzl@47694
   366
lemma ring_of_sets_Pow: "ring_of_sets sp (Pow sp)"
hoelzl@47762
   367
  by (auto simp: ring_of_sets_iff)
hoelzl@42145
   368
hoelzl@47694
   369
lemma algebra_Pow: "algebra sp (Pow sp)"
hoelzl@47762
   370
  by (auto simp: algebra_iff_Un)
hoelzl@38656
   371
hoelzl@38656
   372
lemma sigma_algebra_iff:
hoelzl@47694
   373
  "sigma_algebra \<Omega> M \<longleftrightarrow>
hoelzl@47694
   374
    algebra \<Omega> M \<and> (\<forall>A. range A \<subseteq> M \<longrightarrow> (\<Union>i::nat. A i) \<in> M)"
hoelzl@38656
   375
  by (simp add: sigma_algebra_def sigma_algebra_axioms_def)
paulson@33271
   376
hoelzl@47762
   377
lemma sigma_algebra_Pow: "sigma_algebra sp (Pow sp)"
hoelzl@47762
   378
  by (auto simp: sigma_algebra_iff algebra_iff_Int)
hoelzl@47762
   379
hoelzl@42867
   380
lemma (in sigma_algebra) sets_Collect_countable_All:
hoelzl@47694
   381
  assumes "\<And>i. {x\<in>\<Omega>. P i x} \<in> M"
hoelzl@47694
   382
  shows "{x\<in>\<Omega>. \<forall>i::'i::countable. P i x} \<in> M"
hoelzl@42867
   383
proof -
hoelzl@47694
   384
  have "{x\<in>\<Omega>. \<forall>i::'i::countable. P i x} = (\<Inter>i. {x\<in>\<Omega>. P i x})" by auto
hoelzl@42867
   385
  with assms show ?thesis by auto
hoelzl@42867
   386
qed
hoelzl@42867
   387
hoelzl@42867
   388
lemma (in sigma_algebra) sets_Collect_countable_Ex:
hoelzl@47694
   389
  assumes "\<And>i. {x\<in>\<Omega>. P i x} \<in> M"
hoelzl@47694
   390
  shows "{x\<in>\<Omega>. \<exists>i::'i::countable. P i x} \<in> M"
hoelzl@42867
   391
proof -
hoelzl@47694
   392
  have "{x\<in>\<Omega>. \<exists>i::'i::countable. P i x} = (\<Union>i. {x\<in>\<Omega>. P i x})" by auto
hoelzl@42867
   393
  with assms show ?thesis by auto
hoelzl@42867
   394
qed
hoelzl@42867
   395
hoelzl@50526
   396
lemma (in sigma_algebra) sets_Collect_countable_Ex':
hoelzl@50526
   397
  assumes "\<And>i. {x\<in>\<Omega>. P i x} \<in> M"
hoelzl@50526
   398
  assumes "countable I"
hoelzl@50526
   399
  shows "{x\<in>\<Omega>. \<exists>i\<in>I. P i x} \<in> M"
hoelzl@50526
   400
proof -
hoelzl@50526
   401
  have "{x\<in>\<Omega>. \<exists>i\<in>I. P i x} = (\<Union>i\<in>I. {x\<in>\<Omega>. P i x})" by auto
hoelzl@50526
   402
  with assms show ?thesis 
hoelzl@50526
   403
    by (auto intro!: countable_UN')
hoelzl@50526
   404
qed
hoelzl@50526
   405
hoelzl@42867
   406
lemmas (in sigma_algebra) sets_Collect =
hoelzl@42867
   407
  sets_Collect_imp sets_Collect_disj sets_Collect_conj sets_Collect_neg sets_Collect_const
hoelzl@42867
   408
  sets_Collect_countable_All sets_Collect_countable_Ex sets_Collect_countable_All
hoelzl@42867
   409
hoelzl@47694
   410
lemma (in sigma_algebra) sets_Collect_countable_Ball:
hoelzl@47694
   411
  assumes "\<And>i. {x\<in>\<Omega>. P i x} \<in> M"
hoelzl@47694
   412
  shows "{x\<in>\<Omega>. \<forall>i::'i::countable\<in>X. P i x} \<in> M"
hoelzl@47694
   413
  unfolding Ball_def by (intro sets_Collect assms)
hoelzl@47694
   414
hoelzl@47694
   415
lemma (in sigma_algebra) sets_Collect_countable_Bex:
hoelzl@47694
   416
  assumes "\<And>i. {x\<in>\<Omega>. P i x} \<in> M"
hoelzl@47694
   417
  shows "{x\<in>\<Omega>. \<exists>i::'i::countable\<in>X. P i x} \<in> M"
hoelzl@47694
   418
  unfolding Bex_def by (intro sets_Collect assms)
hoelzl@47694
   419
hoelzl@42984
   420
lemma sigma_algebra_single_set:
hoelzl@42984
   421
  assumes "X \<subseteq> S"
hoelzl@47694
   422
  shows "sigma_algebra S { {}, X, S - X, S }"
hoelzl@42984
   423
  using algebra.is_sigma_algebra[OF algebra_single_set[OF `X \<subseteq> S`]] by simp
hoelzl@42984
   424
paulson@33271
   425
subsection {* Binary Unions *}
paulson@33271
   426
paulson@33271
   427
definition binary :: "'a \<Rightarrow> 'a \<Rightarrow> nat \<Rightarrow> 'a"
wenzelm@50252
   428
  where "binary a b =  (\<lambda>x. b)(0 := a)"
paulson@33271
   429
hoelzl@38656
   430
lemma range_binary_eq: "range(binary a b) = {a,b}"
hoelzl@38656
   431
  by (auto simp add: binary_def)
paulson@33271
   432
hoelzl@38656
   433
lemma Un_range_binary: "a \<union> b = (\<Union>i::nat. binary a b i)"
haftmann@44106
   434
  by (simp add: SUP_def range_binary_eq)
paulson@33271
   435
hoelzl@38656
   436
lemma Int_range_binary: "a \<inter> b = (\<Inter>i::nat. binary a b i)"
haftmann@44106
   437
  by (simp add: INF_def range_binary_eq)
paulson@33271
   438
paulson@33271
   439
lemma sigma_algebra_iff2:
hoelzl@47694
   440
     "sigma_algebra \<Omega> M \<longleftrightarrow>
hoelzl@47694
   441
       M \<subseteq> Pow \<Omega> \<and>
hoelzl@47694
   442
       {} \<in> M \<and> (\<forall>s \<in> M. \<Omega> - s \<in> M) \<and>
hoelzl@47694
   443
       (\<forall>A. range A \<subseteq> M \<longrightarrow> (\<Union>i::nat. A i) \<in> M)"
hoelzl@38656
   444
  by (auto simp add: range_binary_eq sigma_algebra_def sigma_algebra_axioms_def
hoelzl@42065
   445
         algebra_iff_Un Un_range_binary)
paulson@33271
   446
paulson@33271
   447
subsection {* Initial Sigma Algebra *}
paulson@33271
   448
paulson@33271
   449
text {*Sigma algebras can naturally be created as the closure of any set of
hoelzl@47694
   450
  M with regard to the properties just postulated.  *}
paulson@33271
   451
hoelzl@51683
   452
inductive_set sigma_sets :: "'a set \<Rightarrow> 'a set set \<Rightarrow> 'a set set"
paulson@33271
   453
  for sp :: "'a set" and A :: "'a set set"
paulson@33271
   454
  where
hoelzl@47694
   455
    Basic[intro, simp]: "a \<in> A \<Longrightarrow> a \<in> sigma_sets sp A"
paulson@33271
   456
  | Empty: "{} \<in> sigma_sets sp A"
paulson@33271
   457
  | Compl: "a \<in> sigma_sets sp A \<Longrightarrow> sp - a \<in> sigma_sets sp A"
paulson@33271
   458
  | Union: "(\<And>i::nat. a i \<in> sigma_sets sp A) \<Longrightarrow> (\<Union>i. a i) \<in> sigma_sets sp A"
paulson@33271
   459
hoelzl@41543
   460
lemma (in sigma_algebra) sigma_sets_subset:
hoelzl@47694
   461
  assumes a: "a \<subseteq> M"
hoelzl@47694
   462
  shows "sigma_sets \<Omega> a \<subseteq> M"
hoelzl@41543
   463
proof
hoelzl@41543
   464
  fix x
hoelzl@47694
   465
  assume "x \<in> sigma_sets \<Omega> a"
hoelzl@47694
   466
  from this show "x \<in> M"
hoelzl@41543
   467
    by (induct rule: sigma_sets.induct, auto) (metis a subsetD)
hoelzl@41543
   468
qed
hoelzl@41543
   469
hoelzl@41543
   470
lemma sigma_sets_into_sp: "A \<subseteq> Pow sp \<Longrightarrow> x \<in> sigma_sets sp A \<Longrightarrow> x \<subseteq> sp"
hoelzl@41543
   471
  by (erule sigma_sets.induct, auto)
hoelzl@41543
   472
hoelzl@41543
   473
lemma sigma_algebra_sigma_sets:
hoelzl@47694
   474
     "a \<subseteq> Pow \<Omega> \<Longrightarrow> sigma_algebra \<Omega> (sigma_sets \<Omega> a)"
hoelzl@41543
   475
  by (auto simp add: sigma_algebra_iff2 dest: sigma_sets_into_sp
hoelzl@41543
   476
           intro!: sigma_sets.Union sigma_sets.Empty sigma_sets.Compl)
hoelzl@41543
   477
hoelzl@41543
   478
lemma sigma_sets_least_sigma_algebra:
hoelzl@41543
   479
  assumes "A \<subseteq> Pow S"
hoelzl@47694
   480
  shows "sigma_sets S A = \<Inter>{B. A \<subseteq> B \<and> sigma_algebra S B}"
hoelzl@41543
   481
proof safe
hoelzl@47694
   482
  fix B X assume "A \<subseteq> B" and sa: "sigma_algebra S B"
hoelzl@41543
   483
    and X: "X \<in> sigma_sets S A"
hoelzl@41543
   484
  from sigma_algebra.sigma_sets_subset[OF sa, simplified, OF `A \<subseteq> B`] X
hoelzl@41543
   485
  show "X \<in> B" by auto
hoelzl@41543
   486
next
hoelzl@47694
   487
  fix X assume "X \<in> \<Inter>{B. A \<subseteq> B \<and> sigma_algebra S B}"
hoelzl@47694
   488
  then have [intro!]: "\<And>B. A \<subseteq> B \<Longrightarrow> sigma_algebra S B \<Longrightarrow> X \<in> B"
hoelzl@41543
   489
     by simp
hoelzl@47694
   490
  have "A \<subseteq> sigma_sets S A" using assms by auto
hoelzl@47694
   491
  moreover have "sigma_algebra S (sigma_sets S A)"
hoelzl@41543
   492
    using assms by (intro sigma_algebra_sigma_sets[of A]) auto
hoelzl@41543
   493
  ultimately show "X \<in> sigma_sets S A" by auto
hoelzl@41543
   494
qed
paulson@33271
   495
paulson@33271
   496
lemma sigma_sets_top: "sp \<in> sigma_sets sp A"
paulson@33271
   497
  by (metis Diff_empty sigma_sets.Compl sigma_sets.Empty)
paulson@33271
   498
hoelzl@38656
   499
lemma sigma_sets_Un:
paulson@33271
   500
  "a \<in> sigma_sets sp A \<Longrightarrow> b \<in> sigma_sets sp A \<Longrightarrow> a \<union> b \<in> sigma_sets sp A"
hoelzl@38656
   501
apply (simp add: Un_range_binary range_binary_eq)
hoelzl@40859
   502
apply (rule Union, simp add: binary_def)
paulson@33271
   503
done
paulson@33271
   504
paulson@33271
   505
lemma sigma_sets_Inter:
paulson@33271
   506
  assumes Asb: "A \<subseteq> Pow sp"
paulson@33271
   507
  shows "(\<And>i::nat. a i \<in> sigma_sets sp A) \<Longrightarrow> (\<Inter>i. a i) \<in> sigma_sets sp A"
paulson@33271
   508
proof -
paulson@33271
   509
  assume ai: "\<And>i::nat. a i \<in> sigma_sets sp A"
hoelzl@38656
   510
  hence "\<And>i::nat. sp-(a i) \<in> sigma_sets sp A"
paulson@33271
   511
    by (rule sigma_sets.Compl)
hoelzl@38656
   512
  hence "(\<Union>i. sp-(a i)) \<in> sigma_sets sp A"
paulson@33271
   513
    by (rule sigma_sets.Union)
hoelzl@38656
   514
  hence "sp-(\<Union>i. sp-(a i)) \<in> sigma_sets sp A"
paulson@33271
   515
    by (rule sigma_sets.Compl)
hoelzl@38656
   516
  also have "sp-(\<Union>i. sp-(a i)) = sp Int (\<Inter>i. a i)"
paulson@33271
   517
    by auto
paulson@33271
   518
  also have "... = (\<Inter>i. a i)" using ai
hoelzl@38656
   519
    by (blast dest: sigma_sets_into_sp [OF Asb])
hoelzl@38656
   520
  finally show ?thesis .
paulson@33271
   521
qed
paulson@33271
   522
paulson@33271
   523
lemma sigma_sets_INTER:
hoelzl@38656
   524
  assumes Asb: "A \<subseteq> Pow sp"
paulson@33271
   525
      and ai: "\<And>i::nat. i \<in> S \<Longrightarrow> a i \<in> sigma_sets sp A" and non: "S \<noteq> {}"
paulson@33271
   526
  shows "(\<Inter>i\<in>S. a i) \<in> sigma_sets sp A"
paulson@33271
   527
proof -
paulson@33271
   528
  from ai have "\<And>i. (if i\<in>S then a i else sp) \<in> sigma_sets sp A"
hoelzl@47694
   529
    by (simp add: sigma_sets.intros(2-) sigma_sets_top)
paulson@33271
   530
  hence "(\<Inter>i. (if i\<in>S then a i else sp)) \<in> sigma_sets sp A"
paulson@33271
   531
    by (rule sigma_sets_Inter [OF Asb])
paulson@33271
   532
  also have "(\<Inter>i. (if i\<in>S then a i else sp)) = (\<Inter>i\<in>S. a i)"
paulson@33271
   533
    by auto (metis ai non sigma_sets_into_sp subset_empty subset_iff Asb)+
paulson@33271
   534
  finally show ?thesis .
paulson@33271
   535
qed
paulson@33271
   536
hoelzl@51683
   537
lemma sigma_sets_UNION: "countable B \<Longrightarrow> (\<And>b. b \<in> B \<Longrightarrow> b \<in> sigma_sets X A) \<Longrightarrow> (\<Union>B) \<in> sigma_sets X A"
hoelzl@51683
   538
  using from_nat_into[of B] range_from_nat_into[of B] sigma_sets.Union[of "from_nat_into B" X A]
hoelzl@51683
   539
  apply (cases "B = {}")
hoelzl@51683
   540
  apply (simp add: sigma_sets.Empty)
hoelzl@51683
   541
  apply (simp del: Union_image_eq add: Union_image_eq[symmetric])
hoelzl@51683
   542
  done
hoelzl@51683
   543
paulson@33271
   544
lemma (in sigma_algebra) sigma_sets_eq:
hoelzl@47694
   545
     "sigma_sets \<Omega> M = M"
paulson@33271
   546
proof
hoelzl@47694
   547
  show "M \<subseteq> sigma_sets \<Omega> M"
huffman@37032
   548
    by (metis Set.subsetI sigma_sets.Basic)
paulson@33271
   549
  next
hoelzl@47694
   550
  show "sigma_sets \<Omega> M \<subseteq> M"
paulson@33271
   551
    by (metis sigma_sets_subset subset_refl)
paulson@33271
   552
qed
paulson@33271
   553
hoelzl@42981
   554
lemma sigma_sets_eqI:
hoelzl@42981
   555
  assumes A: "\<And>a. a \<in> A \<Longrightarrow> a \<in> sigma_sets M B"
hoelzl@42981
   556
  assumes B: "\<And>b. b \<in> B \<Longrightarrow> b \<in> sigma_sets M A"
hoelzl@42981
   557
  shows "sigma_sets M A = sigma_sets M B"
hoelzl@42981
   558
proof (intro set_eqI iffI)
hoelzl@42981
   559
  fix a assume "a \<in> sigma_sets M A"
hoelzl@42981
   560
  from this A show "a \<in> sigma_sets M B"
hoelzl@47694
   561
    by induct (auto intro!: sigma_sets.intros(2-) del: sigma_sets.Basic)
hoelzl@42981
   562
next
hoelzl@42981
   563
  fix b assume "b \<in> sigma_sets M B"
hoelzl@42981
   564
  from this B show "b \<in> sigma_sets M A"
hoelzl@47694
   565
    by induct (auto intro!: sigma_sets.intros(2-) del: sigma_sets.Basic)
hoelzl@42981
   566
qed
hoelzl@42981
   567
hoelzl@42984
   568
lemma sigma_sets_subseteq: assumes "A \<subseteq> B" shows "sigma_sets X A \<subseteq> sigma_sets X B"
hoelzl@42984
   569
proof
hoelzl@42984
   570
  fix x assume "x \<in> sigma_sets X A" then show "x \<in> sigma_sets X B"
hoelzl@47694
   571
    by induct (insert `A \<subseteq> B`, auto intro: sigma_sets.intros(2-))
hoelzl@42984
   572
qed
hoelzl@42984
   573
hoelzl@47762
   574
lemma sigma_sets_mono: assumes "A \<subseteq> sigma_sets X B" shows "sigma_sets X A \<subseteq> sigma_sets X B"
hoelzl@47762
   575
proof
hoelzl@47762
   576
  fix x assume "x \<in> sigma_sets X A" then show "x \<in> sigma_sets X B"
hoelzl@47762
   577
    by induct (insert `A \<subseteq> sigma_sets X B`, auto intro: sigma_sets.intros(2-))
hoelzl@47762
   578
qed
hoelzl@47762
   579
hoelzl@47762
   580
lemma sigma_sets_mono': assumes "A \<subseteq> B" shows "sigma_sets X A \<subseteq> sigma_sets X B"
hoelzl@47762
   581
proof
hoelzl@47762
   582
  fix x assume "x \<in> sigma_sets X A" then show "x \<in> sigma_sets X B"
hoelzl@47762
   583
    by induct (insert `A \<subseteq> B`, auto intro: sigma_sets.intros(2-))
hoelzl@47762
   584
qed
hoelzl@47762
   585
hoelzl@47762
   586
lemma sigma_sets_superset_generator: "A \<subseteq> sigma_sets X A"
hoelzl@47762
   587
  by (auto intro: sigma_sets.Basic)
hoelzl@47762
   588
hoelzl@38656
   589
lemma (in sigma_algebra) restriction_in_sets:
hoelzl@38656
   590
  fixes A :: "nat \<Rightarrow> 'a set"
hoelzl@47694
   591
  assumes "S \<in> M"
hoelzl@47694
   592
  and *: "range A \<subseteq> (\<lambda>A. S \<inter> A) ` M" (is "_ \<subseteq> ?r")
hoelzl@47694
   593
  shows "range A \<subseteq> M" "(\<Union>i. A i) \<in> (\<lambda>A. S \<inter> A) ` M"
hoelzl@38656
   594
proof -
hoelzl@38656
   595
  { fix i have "A i \<in> ?r" using * by auto
hoelzl@47694
   596
    hence "\<exists>B. A i = B \<inter> S \<and> B \<in> M" by auto
hoelzl@47694
   597
    hence "A i \<subseteq> S" "A i \<in> M" using `S \<in> M` by auto }
hoelzl@47694
   598
  thus "range A \<subseteq> M" "(\<Union>i. A i) \<in> (\<lambda>A. S \<inter> A) ` M"
hoelzl@38656
   599
    by (auto intro!: image_eqI[of _ _ "(\<Union>i. A i)"])
hoelzl@38656
   600
qed
hoelzl@38656
   601
hoelzl@38656
   602
lemma (in sigma_algebra) restricted_sigma_algebra:
hoelzl@47694
   603
  assumes "S \<in> M"
hoelzl@47694
   604
  shows "sigma_algebra S (restricted_space S)"
hoelzl@38656
   605
  unfolding sigma_algebra_def sigma_algebra_axioms_def
hoelzl@38656
   606
proof safe
hoelzl@47694
   607
  show "algebra S (restricted_space S)" using restricted_algebra[OF assms] .
hoelzl@38656
   608
next
hoelzl@47694
   609
  fix A :: "nat \<Rightarrow> 'a set" assume "range A \<subseteq> restricted_space S"
hoelzl@38656
   610
  from restriction_in_sets[OF assms this[simplified]]
hoelzl@47694
   611
  show "(\<Union>i. A i) \<in> restricted_space S" by simp
hoelzl@38656
   612
qed
hoelzl@38656
   613
hoelzl@40859
   614
lemma sigma_sets_Int:
hoelzl@41689
   615
  assumes "A \<in> sigma_sets sp st" "A \<subseteq> sp"
hoelzl@41689
   616
  shows "op \<inter> A ` sigma_sets sp st = sigma_sets A (op \<inter> A ` st)"
hoelzl@40859
   617
proof (intro equalityI subsetI)
hoelzl@40859
   618
  fix x assume "x \<in> op \<inter> A ` sigma_sets sp st"
hoelzl@40859
   619
  then obtain y where "y \<in> sigma_sets sp st" "x = y \<inter> A" by auto
hoelzl@41689
   620
  then have "x \<in> sigma_sets (A \<inter> sp) (op \<inter> A ` st)"
hoelzl@40859
   621
  proof (induct arbitrary: x)
hoelzl@40859
   622
    case (Compl a)
hoelzl@40859
   623
    then show ?case
hoelzl@40859
   624
      by (force intro!: sigma_sets.Compl simp: Diff_Int_distrib ac_simps)
hoelzl@40859
   625
  next
hoelzl@40859
   626
    case (Union a)
hoelzl@40859
   627
    then show ?case
hoelzl@40859
   628
      by (auto intro!: sigma_sets.Union
hoelzl@40859
   629
               simp add: UN_extend_simps simp del: UN_simps)
hoelzl@47694
   630
  qed (auto intro!: sigma_sets.intros(2-))
hoelzl@41689
   631
  then show "x \<in> sigma_sets A (op \<inter> A ` st)"
hoelzl@41689
   632
    using `A \<subseteq> sp` by (simp add: Int_absorb2)
hoelzl@40859
   633
next
hoelzl@41689
   634
  fix x assume "x \<in> sigma_sets A (op \<inter> A ` st)"
hoelzl@40859
   635
  then show "x \<in> op \<inter> A ` sigma_sets sp st"
hoelzl@40859
   636
  proof induct
hoelzl@40859
   637
    case (Compl a)
hoelzl@40859
   638
    then obtain x where "a = A \<inter> x" "x \<in> sigma_sets sp st" by auto
hoelzl@41689
   639
    then show ?case using `A \<subseteq> sp`
hoelzl@40859
   640
      by (force simp add: image_iff intro!: bexI[of _ "sp - x"] sigma_sets.Compl)
hoelzl@40859
   641
  next
hoelzl@40859
   642
    case (Union a)
hoelzl@40859
   643
    then have "\<forall>i. \<exists>x. x \<in> sigma_sets sp st \<and> a i = A \<inter> x"
hoelzl@40859
   644
      by (auto simp: image_iff Bex_def)
hoelzl@40859
   645
    from choice[OF this] guess f ..
hoelzl@40859
   646
    then show ?case
hoelzl@40859
   647
      by (auto intro!: bexI[of _ "(\<Union>x. f x)"] sigma_sets.Union
hoelzl@40859
   648
               simp add: image_iff)
hoelzl@47694
   649
  qed (auto intro!: sigma_sets.intros(2-))
hoelzl@40859
   650
qed
hoelzl@40859
   651
hoelzl@47694
   652
lemma sigma_sets_empty_eq: "sigma_sets A {} = {{}, A}"
hoelzl@40859
   653
proof (intro set_eqI iffI)
hoelzl@47694
   654
  fix a assume "a \<in> sigma_sets A {}" then show "a \<in> {{}, A}"
hoelzl@47694
   655
    by induct blast+
hoelzl@47694
   656
qed (auto intro: sigma_sets.Empty sigma_sets_top)
hoelzl@47694
   657
hoelzl@47694
   658
lemma sigma_sets_single[simp]: "sigma_sets A {A} = {{}, A}"
hoelzl@47694
   659
proof (intro set_eqI iffI)
hoelzl@47694
   660
  fix x assume "x \<in> sigma_sets A {A}"
hoelzl@47694
   661
  then show "x \<in> {{}, A}"
hoelzl@47694
   662
    by induct blast+
hoelzl@40859
   663
next
hoelzl@47694
   664
  fix x assume "x \<in> {{}, A}"
hoelzl@47694
   665
  then show "x \<in> sigma_sets A {A}"
hoelzl@40859
   666
    by (auto intro: sigma_sets.Empty sigma_sets_top)
hoelzl@40859
   667
qed
hoelzl@40859
   668
hoelzl@42987
   669
lemma sigma_sets_sigma_sets_eq:
hoelzl@42987
   670
  "M \<subseteq> Pow S \<Longrightarrow> sigma_sets S (sigma_sets S M) = sigma_sets S M"
hoelzl@47694
   671
  by (rule sigma_algebra.sigma_sets_eq[OF sigma_algebra_sigma_sets, of M S]) auto
hoelzl@42987
   672
hoelzl@42984
   673
lemma sigma_sets_singleton:
hoelzl@42984
   674
  assumes "X \<subseteq> S"
hoelzl@42984
   675
  shows "sigma_sets S { X } = { {}, X, S - X, S }"
hoelzl@42984
   676
proof -
hoelzl@47694
   677
  interpret sigma_algebra S "{ {}, X, S - X, S }"
hoelzl@42984
   678
    by (rule sigma_algebra_single_set) fact
hoelzl@42984
   679
  have "sigma_sets S { X } \<subseteq> sigma_sets S { {}, X, S - X, S }"
hoelzl@42984
   680
    by (rule sigma_sets_subseteq) simp
hoelzl@42984
   681
  moreover have "\<dots> = { {}, X, S - X, S }"
hoelzl@47694
   682
    using sigma_sets_eq by simp
hoelzl@42984
   683
  moreover
hoelzl@42984
   684
  { fix A assume "A \<in> { {}, X, S - X, S }"
hoelzl@42984
   685
    then have "A \<in> sigma_sets S { X }"
hoelzl@47694
   686
      by (auto intro: sigma_sets.intros(2-) sigma_sets_top) }
hoelzl@42984
   687
  ultimately have "sigma_sets S { X } = sigma_sets S { {}, X, S - X, S }"
hoelzl@42984
   688
    by (intro antisym) auto
hoelzl@47694
   689
  with sigma_sets_eq show ?thesis by simp
hoelzl@42984
   690
qed
hoelzl@42984
   691
hoelzl@42863
   692
lemma restricted_sigma:
hoelzl@47694
   693
  assumes S: "S \<in> sigma_sets \<Omega> M" and M: "M \<subseteq> Pow \<Omega>"
hoelzl@47694
   694
  shows "algebra.restricted_space (sigma_sets \<Omega> M) S =
hoelzl@47694
   695
    sigma_sets S (algebra.restricted_space M S)"
hoelzl@42863
   696
proof -
hoelzl@42863
   697
  from S sigma_sets_into_sp[OF M]
hoelzl@47694
   698
  have "S \<in> sigma_sets \<Omega> M" "S \<subseteq> \<Omega>" by auto
hoelzl@42863
   699
  from sigma_sets_Int[OF this]
hoelzl@47694
   700
  show ?thesis by simp
hoelzl@42863
   701
qed
hoelzl@42863
   702
hoelzl@42987
   703
lemma sigma_sets_vimage_commute:
hoelzl@47694
   704
  assumes X: "X \<in> \<Omega> \<rightarrow> \<Omega>'"
hoelzl@47694
   705
  shows "{X -` A \<inter> \<Omega> |A. A \<in> sigma_sets \<Omega>' M'}
hoelzl@47694
   706
       = sigma_sets \<Omega> {X -` A \<inter> \<Omega> |A. A \<in> M'}" (is "?L = ?R")
hoelzl@42987
   707
proof
hoelzl@42987
   708
  show "?L \<subseteq> ?R"
hoelzl@42987
   709
  proof clarify
hoelzl@47694
   710
    fix A assume "A \<in> sigma_sets \<Omega>' M'"
hoelzl@47694
   711
    then show "X -` A \<inter> \<Omega> \<in> ?R"
hoelzl@42987
   712
    proof induct
hoelzl@42987
   713
      case Empty then show ?case
hoelzl@42987
   714
        by (auto intro!: sigma_sets.Empty)
hoelzl@42987
   715
    next
hoelzl@42987
   716
      case (Compl B)
hoelzl@47694
   717
      have [simp]: "X -` (\<Omega>' - B) \<inter> \<Omega> = \<Omega> - (X -` B \<inter> \<Omega>)"
hoelzl@42987
   718
        by (auto simp add: funcset_mem [OF X])
hoelzl@42987
   719
      with Compl show ?case
hoelzl@42987
   720
        by (auto intro!: sigma_sets.Compl)
hoelzl@42987
   721
    next
hoelzl@42987
   722
      case (Union F)
hoelzl@42987
   723
      then show ?case
hoelzl@42987
   724
        by (auto simp add: vimage_UN UN_extend_simps(4) simp del: UN_simps
hoelzl@42987
   725
                 intro!: sigma_sets.Union)
hoelzl@47694
   726
    qed auto
hoelzl@42987
   727
  qed
hoelzl@42987
   728
  show "?R \<subseteq> ?L"
hoelzl@42987
   729
  proof clarify
hoelzl@42987
   730
    fix A assume "A \<in> ?R"
hoelzl@47694
   731
    then show "\<exists>B. A = X -` B \<inter> \<Omega> \<and> B \<in> sigma_sets \<Omega>' M'"
hoelzl@42987
   732
    proof induct
hoelzl@42987
   733
      case (Basic B) then show ?case by auto
hoelzl@42987
   734
    next
hoelzl@42987
   735
      case Empty then show ?case
hoelzl@47694
   736
        by (auto intro!: sigma_sets.Empty exI[of _ "{}"])
hoelzl@42987
   737
    next
hoelzl@42987
   738
      case (Compl B)
hoelzl@47694
   739
      then obtain A where A: "B = X -` A \<inter> \<Omega>" "A \<in> sigma_sets \<Omega>' M'" by auto
hoelzl@47694
   740
      then have [simp]: "\<Omega> - B = X -` (\<Omega>' - A) \<inter> \<Omega>"
hoelzl@42987
   741
        by (auto simp add: funcset_mem [OF X])
hoelzl@42987
   742
      with A(2) show ?case
hoelzl@47694
   743
        by (auto intro: sigma_sets.Compl)
hoelzl@42987
   744
    next
hoelzl@42987
   745
      case (Union F)
hoelzl@47694
   746
      then have "\<forall>i. \<exists>B. F i = X -` B \<inter> \<Omega> \<and> B \<in> sigma_sets \<Omega>' M'" by auto
hoelzl@42987
   747
      from choice[OF this] guess A .. note A = this
hoelzl@42987
   748
      with A show ?case
hoelzl@47694
   749
        by (auto simp: vimage_UN[symmetric] intro: sigma_sets.Union)
hoelzl@42987
   750
    qed
hoelzl@42987
   751
  qed
hoelzl@42987
   752
qed
hoelzl@42987
   753
hoelzl@50387
   754
subsection "Disjoint families"
hoelzl@38656
   755
hoelzl@38656
   756
definition
hoelzl@38656
   757
  disjoint_family_on  where
hoelzl@38656
   758
  "disjoint_family_on A S \<longleftrightarrow> (\<forall>m\<in>S. \<forall>n\<in>S. m \<noteq> n \<longrightarrow> A m \<inter> A n = {})"
hoelzl@38656
   759
hoelzl@38656
   760
abbreviation
hoelzl@38656
   761
  "disjoint_family A \<equiv> disjoint_family_on A UNIV"
hoelzl@38656
   762
hoelzl@38656
   763
lemma range_subsetD: "range f \<subseteq> B \<Longrightarrow> f i \<in> B"
hoelzl@38656
   764
  by blast
hoelzl@38656
   765
hoelzl@38656
   766
lemma Int_Diff_disjoint: "A \<inter> B \<inter> (A - B) = {}"
hoelzl@38656
   767
  by blast
hoelzl@38656
   768
hoelzl@38656
   769
lemma Int_Diff_Un: "A \<inter> B \<union> (A - B) = A"
hoelzl@38656
   770
  by blast
hoelzl@38656
   771
hoelzl@38656
   772
lemma disjoint_family_subset:
hoelzl@38656
   773
     "disjoint_family A \<Longrightarrow> (!!x. B x \<subseteq> A x) \<Longrightarrow> disjoint_family B"
hoelzl@38656
   774
  by (force simp add: disjoint_family_on_def)
hoelzl@38656
   775
hoelzl@40859
   776
lemma disjoint_family_on_bisimulation:
hoelzl@40859
   777
  assumes "disjoint_family_on f S"
hoelzl@40859
   778
  and "\<And>n m. n \<in> S \<Longrightarrow> m \<in> S \<Longrightarrow> n \<noteq> m \<Longrightarrow> f n \<inter> f m = {} \<Longrightarrow> g n \<inter> g m = {}"
hoelzl@40859
   779
  shows "disjoint_family_on g S"
hoelzl@40859
   780
  using assms unfolding disjoint_family_on_def by auto
hoelzl@40859
   781
hoelzl@38656
   782
lemma disjoint_family_on_mono:
hoelzl@38656
   783
  "A \<subseteq> B \<Longrightarrow> disjoint_family_on f B \<Longrightarrow> disjoint_family_on f A"
hoelzl@38656
   784
  unfolding disjoint_family_on_def by auto
hoelzl@38656
   785
hoelzl@38656
   786
lemma disjoint_family_Suc:
hoelzl@38656
   787
  assumes Suc: "!!n. A n \<subseteq> A (Suc n)"
hoelzl@38656
   788
  shows "disjoint_family (\<lambda>i. A (Suc i) - A i)"
hoelzl@38656
   789
proof -
hoelzl@38656
   790
  {
hoelzl@38656
   791
    fix m
hoelzl@38656
   792
    have "!!n. A n \<subseteq> A (m+n)"
hoelzl@38656
   793
    proof (induct m)
hoelzl@38656
   794
      case 0 show ?case by simp
hoelzl@38656
   795
    next
hoelzl@38656
   796
      case (Suc m) thus ?case
hoelzl@38656
   797
        by (metis Suc_eq_plus1 assms nat_add_commute nat_add_left_commute subset_trans)
hoelzl@38656
   798
    qed
hoelzl@38656
   799
  }
hoelzl@38656
   800
  hence "!!m n. m < n \<Longrightarrow> A m \<subseteq> A n"
hoelzl@38656
   801
    by (metis add_commute le_add_diff_inverse nat_less_le)
hoelzl@38656
   802
  thus ?thesis
hoelzl@38656
   803
    by (auto simp add: disjoint_family_on_def)
hoelzl@38656
   804
      (metis insert_absorb insert_subset le_SucE le_antisym not_leE)
hoelzl@38656
   805
qed
hoelzl@38656
   806
hoelzl@39092
   807
lemma setsum_indicator_disjoint_family:
hoelzl@39092
   808
  fixes f :: "'d \<Rightarrow> 'e::semiring_1"
hoelzl@39092
   809
  assumes d: "disjoint_family_on A P" and "x \<in> A j" and "finite P" and "j \<in> P"
hoelzl@39092
   810
  shows "(\<Sum>i\<in>P. f i * indicator (A i) x) = f j"
hoelzl@39092
   811
proof -
hoelzl@39092
   812
  have "P \<inter> {i. x \<in> A i} = {j}"
hoelzl@39092
   813
    using d `x \<in> A j` `j \<in> P` unfolding disjoint_family_on_def
hoelzl@39092
   814
    by auto
hoelzl@39092
   815
  thus ?thesis
hoelzl@39092
   816
    unfolding indicator_def
hoelzl@39092
   817
    by (simp add: if_distrib setsum_cases[OF `finite P`])
hoelzl@39092
   818
qed
hoelzl@39092
   819
hoelzl@38656
   820
definition disjointed :: "(nat \<Rightarrow> 'a set) \<Rightarrow> nat \<Rightarrow> 'a set "
hoelzl@38656
   821
  where "disjointed A n = A n - (\<Union>i\<in>{0..<n}. A i)"
hoelzl@38656
   822
hoelzl@38656
   823
lemma finite_UN_disjointed_eq: "(\<Union>i\<in>{0..<n}. disjointed A i) = (\<Union>i\<in>{0..<n}. A i)"
hoelzl@38656
   824
proof (induct n)
hoelzl@38656
   825
  case 0 show ?case by simp
hoelzl@38656
   826
next
hoelzl@38656
   827
  case (Suc n)
hoelzl@38656
   828
  thus ?case by (simp add: atLeastLessThanSuc disjointed_def)
hoelzl@38656
   829
qed
hoelzl@38656
   830
hoelzl@38656
   831
lemma UN_disjointed_eq: "(\<Union>i. disjointed A i) = (\<Union>i. A i)"
hoelzl@38656
   832
  apply (rule UN_finite2_eq [where k=0])
hoelzl@38656
   833
  apply (simp add: finite_UN_disjointed_eq)
hoelzl@38656
   834
  done
hoelzl@38656
   835
hoelzl@38656
   836
lemma less_disjoint_disjointed: "m<n \<Longrightarrow> disjointed A m \<inter> disjointed A n = {}"
hoelzl@38656
   837
  by (auto simp add: disjointed_def)
hoelzl@38656
   838
hoelzl@38656
   839
lemma disjoint_family_disjointed: "disjoint_family (disjointed A)"
hoelzl@38656
   840
  by (simp add: disjoint_family_on_def)
hoelzl@38656
   841
     (metis neq_iff Int_commute less_disjoint_disjointed)
hoelzl@38656
   842
hoelzl@38656
   843
lemma disjointed_subset: "disjointed A n \<subseteq> A n"
hoelzl@38656
   844
  by (auto simp add: disjointed_def)
hoelzl@38656
   845
hoelzl@42065
   846
lemma (in ring_of_sets) UNION_in_sets:
hoelzl@38656
   847
  fixes A:: "nat \<Rightarrow> 'a set"
hoelzl@47694
   848
  assumes A: "range A \<subseteq> M"
hoelzl@47694
   849
  shows  "(\<Union>i\<in>{0..<n}. A i) \<in> M"
hoelzl@38656
   850
proof (induct n)
hoelzl@38656
   851
  case 0 show ?case by simp
hoelzl@38656
   852
next
hoelzl@38656
   853
  case (Suc n)
hoelzl@38656
   854
  thus ?case
hoelzl@38656
   855
    by (simp add: atLeastLessThanSuc) (metis A Un UNIV_I image_subset_iff)
hoelzl@38656
   856
qed
hoelzl@38656
   857
hoelzl@42065
   858
lemma (in ring_of_sets) range_disjointed_sets:
hoelzl@47694
   859
  assumes A: "range A \<subseteq> M"
hoelzl@47694
   860
  shows  "range (disjointed A) \<subseteq> M"
hoelzl@38656
   861
proof (auto simp add: disjointed_def)
hoelzl@38656
   862
  fix n
hoelzl@47694
   863
  show "A n - (\<Union>i\<in>{0..<n}. A i) \<in> M" using UNION_in_sets
hoelzl@38656
   864
    by (metis A Diff UNIV_I image_subset_iff)
hoelzl@38656
   865
qed
hoelzl@38656
   866
hoelzl@42065
   867
lemma (in algebra) range_disjointed_sets':
hoelzl@47694
   868
  "range A \<subseteq> M \<Longrightarrow> range (disjointed A) \<subseteq> M"
hoelzl@42065
   869
  using range_disjointed_sets .
hoelzl@42065
   870
hoelzl@42145
   871
lemma disjointed_0[simp]: "disjointed A 0 = A 0"
hoelzl@42145
   872
  by (simp add: disjointed_def)
hoelzl@42145
   873
hoelzl@42145
   874
lemma incseq_Un:
hoelzl@42145
   875
  "incseq A \<Longrightarrow> (\<Union>i\<le>n. A i) = A n"
hoelzl@42145
   876
  unfolding incseq_def by auto
hoelzl@42145
   877
hoelzl@42145
   878
lemma disjointed_incseq:
hoelzl@42145
   879
  "incseq A \<Longrightarrow> disjointed A (Suc n) = A (Suc n) - A n"
hoelzl@42145
   880
  using incseq_Un[of A]
hoelzl@42145
   881
  by (simp add: disjointed_def atLeastLessThanSuc_atLeastAtMost atLeast0AtMost)
hoelzl@42145
   882
hoelzl@38656
   883
lemma sigma_algebra_disjoint_iff:
hoelzl@47694
   884
  "sigma_algebra \<Omega> M \<longleftrightarrow> algebra \<Omega> M \<and>
hoelzl@47694
   885
    (\<forall>A. range A \<subseteq> M \<longrightarrow> disjoint_family A \<longrightarrow> (\<Union>i::nat. A i) \<in> M)"
hoelzl@38656
   886
proof (auto simp add: sigma_algebra_iff)
hoelzl@38656
   887
  fix A :: "nat \<Rightarrow> 'a set"
hoelzl@47694
   888
  assume M: "algebra \<Omega> M"
hoelzl@47694
   889
     and A: "range A \<subseteq> M"
hoelzl@47694
   890
     and UnA: "\<forall>A. range A \<subseteq> M \<longrightarrow> disjoint_family A \<longrightarrow> (\<Union>i::nat. A i) \<in> M"
hoelzl@47694
   891
  hence "range (disjointed A) \<subseteq> M \<longrightarrow>
hoelzl@38656
   892
         disjoint_family (disjointed A) \<longrightarrow>
hoelzl@47694
   893
         (\<Union>i. disjointed A i) \<in> M" by blast
hoelzl@47694
   894
  hence "(\<Union>i. disjointed A i) \<in> M"
hoelzl@47694
   895
    by (simp add: algebra.range_disjointed_sets'[of \<Omega>] M A disjoint_family_disjointed)
hoelzl@47694
   896
  thus "(\<Union>i::nat. A i) \<in> M" by (simp add: UN_disjointed_eq)
hoelzl@47694
   897
qed
hoelzl@47694
   898
hoelzl@47762
   899
lemma disjoint_family_on_disjoint_image:
hoelzl@47762
   900
  "disjoint_family_on A I \<Longrightarrow> disjoint (A ` I)"
hoelzl@47762
   901
  unfolding disjoint_family_on_def disjoint_def by force
hoelzl@47762
   902
hoelzl@47762
   903
lemma disjoint_image_disjoint_family_on:
hoelzl@47762
   904
  assumes d: "disjoint (A ` I)" and i: "inj_on A I"
hoelzl@47762
   905
  shows "disjoint_family_on A I"
hoelzl@47762
   906
  unfolding disjoint_family_on_def
hoelzl@47762
   907
proof (intro ballI impI)
hoelzl@47762
   908
  fix n m assume nm: "m \<in> I" "n \<in> I" and "n \<noteq> m"
hoelzl@47762
   909
  with i[THEN inj_onD, of n m] show "A n \<inter> A m = {}"
hoelzl@47762
   910
    by (intro disjointD[OF d]) auto
hoelzl@47762
   911
qed
hoelzl@47762
   912
hoelzl@50387
   913
subsection {* Ring generated by a semiring *}
hoelzl@47762
   914
hoelzl@47762
   915
definition (in semiring_of_sets)
hoelzl@47762
   916
  "generated_ring = { \<Union>C | C. C \<subseteq> M \<and> finite C \<and> disjoint C }"
hoelzl@47762
   917
hoelzl@47762
   918
lemma (in semiring_of_sets) generated_ringE[elim?]:
hoelzl@47762
   919
  assumes "a \<in> generated_ring"
hoelzl@47762
   920
  obtains C where "finite C" "disjoint C" "C \<subseteq> M" "a = \<Union>C"
hoelzl@47762
   921
  using assms unfolding generated_ring_def by auto
hoelzl@47762
   922
hoelzl@47762
   923
lemma (in semiring_of_sets) generated_ringI[intro?]:
hoelzl@47762
   924
  assumes "finite C" "disjoint C" "C \<subseteq> M" "a = \<Union>C"
hoelzl@47762
   925
  shows "a \<in> generated_ring"
hoelzl@47762
   926
  using assms unfolding generated_ring_def by auto
hoelzl@47762
   927
hoelzl@47762
   928
lemma (in semiring_of_sets) generated_ringI_Basic:
hoelzl@47762
   929
  "A \<in> M \<Longrightarrow> A \<in> generated_ring"
hoelzl@47762
   930
  by (rule generated_ringI[of "{A}"]) (auto simp: disjoint_def)
hoelzl@47762
   931
hoelzl@47762
   932
lemma (in semiring_of_sets) generated_ring_disjoint_Un[intro]:
hoelzl@47762
   933
  assumes a: "a \<in> generated_ring" and b: "b \<in> generated_ring"
hoelzl@47762
   934
  and "a \<inter> b = {}"
hoelzl@47762
   935
  shows "a \<union> b \<in> generated_ring"
hoelzl@47762
   936
proof -
hoelzl@47762
   937
  from a guess Ca .. note Ca = this
hoelzl@47762
   938
  from b guess Cb .. note Cb = this
hoelzl@47762
   939
  show ?thesis
hoelzl@47762
   940
  proof
hoelzl@47762
   941
    show "disjoint (Ca \<union> Cb)"
hoelzl@47762
   942
      using `a \<inter> b = {}` Ca Cb by (auto intro!: disjoint_union)
hoelzl@47762
   943
  qed (insert Ca Cb, auto)
hoelzl@47762
   944
qed
hoelzl@47762
   945
hoelzl@47762
   946
lemma (in semiring_of_sets) generated_ring_empty: "{} \<in> generated_ring"
hoelzl@47762
   947
  by (auto simp: generated_ring_def disjoint_def)
hoelzl@47762
   948
hoelzl@47762
   949
lemma (in semiring_of_sets) generated_ring_disjoint_Union:
hoelzl@47762
   950
  assumes "finite A" shows "A \<subseteq> generated_ring \<Longrightarrow> disjoint A \<Longrightarrow> \<Union>A \<in> generated_ring"
hoelzl@47762
   951
  using assms by (induct A) (auto simp: disjoint_def intro!: generated_ring_disjoint_Un generated_ring_empty)
hoelzl@47762
   952
hoelzl@47762
   953
lemma (in semiring_of_sets) generated_ring_disjoint_UNION:
hoelzl@47762
   954
  "finite I \<Longrightarrow> disjoint (A ` I) \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> A i \<in> generated_ring) \<Longrightarrow> UNION I A \<in> generated_ring"
hoelzl@47762
   955
  unfolding SUP_def by (intro generated_ring_disjoint_Union) auto
hoelzl@47762
   956
hoelzl@47762
   957
lemma (in semiring_of_sets) generated_ring_Int:
hoelzl@47762
   958
  assumes a: "a \<in> generated_ring" and b: "b \<in> generated_ring"
hoelzl@47762
   959
  shows "a \<inter> b \<in> generated_ring"
hoelzl@47762
   960
proof -
hoelzl@47762
   961
  from a guess Ca .. note Ca = this
hoelzl@47762
   962
  from b guess Cb .. note Cb = this
hoelzl@47762
   963
  def C \<equiv> "(\<lambda>(a,b). a \<inter> b)` (Ca\<times>Cb)"
hoelzl@47762
   964
  show ?thesis
hoelzl@47762
   965
  proof
hoelzl@47762
   966
    show "disjoint C"
hoelzl@47762
   967
    proof (simp add: disjoint_def C_def, intro ballI impI)
hoelzl@47762
   968
      fix a1 b1 a2 b2 assume sets: "a1 \<in> Ca" "b1 \<in> Cb" "a2 \<in> Ca" "b2 \<in> Cb"
hoelzl@47762
   969
      assume "a1 \<inter> b1 \<noteq> a2 \<inter> b2"
hoelzl@47762
   970
      then have "a1 \<noteq> a2 \<or> b1 \<noteq> b2" by auto
hoelzl@47762
   971
      then show "(a1 \<inter> b1) \<inter> (a2 \<inter> b2) = {}"
hoelzl@47762
   972
      proof
hoelzl@47762
   973
        assume "a1 \<noteq> a2"
hoelzl@47762
   974
        with sets Ca have "a1 \<inter> a2 = {}"
hoelzl@47762
   975
          by (auto simp: disjoint_def)
hoelzl@47762
   976
        then show ?thesis by auto
hoelzl@47762
   977
      next
hoelzl@47762
   978
        assume "b1 \<noteq> b2"
hoelzl@47762
   979
        with sets Cb have "b1 \<inter> b2 = {}"
hoelzl@47762
   980
          by (auto simp: disjoint_def)
hoelzl@47762
   981
        then show ?thesis by auto
hoelzl@47762
   982
      qed
hoelzl@47762
   983
    qed
hoelzl@47762
   984
  qed (insert Ca Cb, auto simp: C_def)
hoelzl@47762
   985
qed
hoelzl@47762
   986
hoelzl@47762
   987
lemma (in semiring_of_sets) generated_ring_Inter:
hoelzl@47762
   988
  assumes "finite A" "A \<noteq> {}" shows "A \<subseteq> generated_ring \<Longrightarrow> \<Inter>A \<in> generated_ring"
hoelzl@47762
   989
  using assms by (induct A rule: finite_ne_induct) (auto intro: generated_ring_Int)
hoelzl@47762
   990
hoelzl@47762
   991
lemma (in semiring_of_sets) generated_ring_INTER:
hoelzl@47762
   992
  "finite I \<Longrightarrow> I \<noteq> {} \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> A i \<in> generated_ring) \<Longrightarrow> INTER I A \<in> generated_ring"
hoelzl@47762
   993
  unfolding INF_def by (intro generated_ring_Inter) auto
hoelzl@47762
   994
hoelzl@47762
   995
lemma (in semiring_of_sets) generating_ring:
hoelzl@47762
   996
  "ring_of_sets \<Omega> generated_ring"
hoelzl@47762
   997
proof (rule ring_of_setsI)
hoelzl@47762
   998
  let ?R = generated_ring
hoelzl@47762
   999
  show "?R \<subseteq> Pow \<Omega>"
hoelzl@47762
  1000
    using sets_into_space by (auto simp: generated_ring_def generated_ring_empty)
hoelzl@47762
  1001
  show "{} \<in> ?R" by (rule generated_ring_empty)
hoelzl@47762
  1002
hoelzl@47762
  1003
  { fix a assume a: "a \<in> ?R" then guess Ca .. note Ca = this
hoelzl@47762
  1004
    fix b assume b: "b \<in> ?R" then guess Cb .. note Cb = this
hoelzl@47762
  1005
  
hoelzl@47762
  1006
    show "a - b \<in> ?R"
hoelzl@47762
  1007
    proof cases
hoelzl@47762
  1008
      assume "Cb = {}" with Cb `a \<in> ?R` show ?thesis
hoelzl@47762
  1009
        by simp
hoelzl@47762
  1010
    next
hoelzl@47762
  1011
      assume "Cb \<noteq> {}"
hoelzl@47762
  1012
      with Ca Cb have "a - b = (\<Union>a'\<in>Ca. \<Inter>b'\<in>Cb. a' - b')" by auto
hoelzl@47762
  1013
      also have "\<dots> \<in> ?R"
hoelzl@47762
  1014
      proof (intro generated_ring_INTER generated_ring_disjoint_UNION)
hoelzl@47762
  1015
        fix a b assume "a \<in> Ca" "b \<in> Cb"
hoelzl@47762
  1016
        with Ca Cb Diff_cover[of a b] show "a - b \<in> ?R"
hoelzl@47762
  1017
          by (auto simp add: generated_ring_def)
hoelzl@47762
  1018
      next
hoelzl@47762
  1019
        show "disjoint ((\<lambda>a'. \<Inter>b'\<in>Cb. a' - b')`Ca)"
hoelzl@47762
  1020
          using Ca by (auto simp add: disjoint_def `Cb \<noteq> {}`)
hoelzl@47762
  1021
      next
hoelzl@47762
  1022
        show "finite Ca" "finite Cb" "Cb \<noteq> {}" by fact+
hoelzl@47762
  1023
      qed
hoelzl@47762
  1024
      finally show "a - b \<in> ?R" .
hoelzl@47762
  1025
    qed }
hoelzl@47762
  1026
  note Diff = this
hoelzl@47762
  1027
hoelzl@47762
  1028
  fix a b assume sets: "a \<in> ?R" "b \<in> ?R"
hoelzl@47762
  1029
  have "a \<union> b = (a - b) \<union> (a \<inter> b) \<union> (b - a)" by auto
hoelzl@47762
  1030
  also have "\<dots> \<in> ?R"
hoelzl@47762
  1031
    by (intro sets generated_ring_disjoint_Un generated_ring_Int Diff) auto
hoelzl@47762
  1032
  finally show "a \<union> b \<in> ?R" .
hoelzl@47762
  1033
qed
hoelzl@47762
  1034
hoelzl@47762
  1035
lemma (in semiring_of_sets) sigma_sets_generated_ring_eq: "sigma_sets \<Omega> generated_ring = sigma_sets \<Omega> M"
hoelzl@47762
  1036
proof
hoelzl@47762
  1037
  interpret M: sigma_algebra \<Omega> "sigma_sets \<Omega> M"
hoelzl@47762
  1038
    using space_closed by (rule sigma_algebra_sigma_sets)
hoelzl@47762
  1039
  show "sigma_sets \<Omega> generated_ring \<subseteq> sigma_sets \<Omega> M"
hoelzl@47762
  1040
    by (blast intro!: sigma_sets_mono elim: generated_ringE)
hoelzl@47762
  1041
qed (auto intro!: generated_ringI_Basic sigma_sets_mono)
hoelzl@47762
  1042
hoelzl@50387
  1043
subsection {* Measure type *}
hoelzl@47694
  1044
hoelzl@47694
  1045
definition positive :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> bool" where
hoelzl@47694
  1046
  "positive M \<mu> \<longleftrightarrow> \<mu> {} = 0 \<and> (\<forall>A\<in>M. 0 \<le> \<mu> A)"
hoelzl@47694
  1047
hoelzl@47694
  1048
definition countably_additive :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> bool" where
hoelzl@47694
  1049
  "countably_additive M f \<longleftrightarrow> (\<forall>A. range A \<subseteq> M \<longrightarrow> disjoint_family A \<longrightarrow> (\<Union>i. A i) \<in> M \<longrightarrow>
hoelzl@47694
  1050
    (\<Sum>i. f (A i)) = f (\<Union>i. A i))"
hoelzl@47694
  1051
hoelzl@47694
  1052
definition measure_space :: "'a set \<Rightarrow> 'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> bool" where
hoelzl@47694
  1053
  "measure_space \<Omega> A \<mu> \<longleftrightarrow> sigma_algebra \<Omega> A \<and> positive A \<mu> \<and> countably_additive A \<mu>"
hoelzl@47694
  1054
wenzelm@49834
  1055
typedef 'a measure = "{(\<Omega>::'a set, A, \<mu>). (\<forall>a\<in>-A. \<mu> a = 0) \<and> measure_space \<Omega> A \<mu> }"
hoelzl@47694
  1056
proof
hoelzl@47694
  1057
  have "sigma_algebra UNIV {{}, UNIV}"
hoelzl@47762
  1058
    by (auto simp: sigma_algebra_iff2)
hoelzl@47694
  1059
  then show "(UNIV, {{}, UNIV}, \<lambda>A. 0) \<in> {(\<Omega>, A, \<mu>). (\<forall>a\<in>-A. \<mu> a = 0) \<and> measure_space \<Omega> A \<mu>} "
hoelzl@47694
  1060
    by (auto simp: measure_space_def positive_def countably_additive_def)
hoelzl@47694
  1061
qed
hoelzl@47694
  1062
hoelzl@47694
  1063
definition space :: "'a measure \<Rightarrow> 'a set" where
hoelzl@47694
  1064
  "space M = fst (Rep_measure M)"
hoelzl@47694
  1065
hoelzl@47694
  1066
definition sets :: "'a measure \<Rightarrow> 'a set set" where
hoelzl@47694
  1067
  "sets M = fst (snd (Rep_measure M))"
hoelzl@47694
  1068
hoelzl@47694
  1069
definition emeasure :: "'a measure \<Rightarrow> 'a set \<Rightarrow> ereal" where
hoelzl@47694
  1070
  "emeasure M = snd (snd (Rep_measure M))"
hoelzl@47694
  1071
hoelzl@47694
  1072
definition measure :: "'a measure \<Rightarrow> 'a set \<Rightarrow> real" where
hoelzl@47694
  1073
  "measure M A = real (emeasure M A)"
hoelzl@47694
  1074
hoelzl@47694
  1075
declare [[coercion sets]]
hoelzl@47694
  1076
hoelzl@47694
  1077
declare [[coercion measure]]
hoelzl@47694
  1078
hoelzl@47694
  1079
declare [[coercion emeasure]]
hoelzl@47694
  1080
hoelzl@47694
  1081
lemma measure_space: "measure_space (space M) (sets M) (emeasure M)"
hoelzl@47694
  1082
  by (cases M) (auto simp: space_def sets_def emeasure_def Abs_measure_inverse)
hoelzl@47694
  1083
immler@50244
  1084
interpretation sets!: sigma_algebra "space M" "sets M" for M :: "'a measure"
hoelzl@47694
  1085
  using measure_space[of M] by (auto simp: measure_space_def)
hoelzl@47694
  1086
hoelzl@47694
  1087
definition measure_of :: "'a set \<Rightarrow> 'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> 'a measure" where
hoelzl@47694
  1088
  "measure_of \<Omega> A \<mu> = Abs_measure (\<Omega>, sigma_sets \<Omega> A,
hoelzl@47694
  1089
    \<lambda>a. if a \<in> sigma_sets \<Omega> A \<and> measure_space \<Omega> (sigma_sets \<Omega> A) \<mu> then \<mu> a else 0)"
hoelzl@47694
  1090
hoelzl@47694
  1091
abbreviation "sigma \<Omega> A \<equiv> measure_of \<Omega> A (\<lambda>x. 0)"
hoelzl@47694
  1092
hoelzl@47694
  1093
lemma measure_space_0: "A \<subseteq> Pow \<Omega> \<Longrightarrow> measure_space \<Omega> (sigma_sets \<Omega> A) (\<lambda>x. 0)"
hoelzl@47694
  1094
  unfolding measure_space_def
hoelzl@47694
  1095
  by (auto intro!: sigma_algebra_sigma_sets simp: positive_def countably_additive_def)
hoelzl@47694
  1096
hoelzl@47694
  1097
lemma (in ring_of_sets) positive_cong_eq:
hoelzl@47694
  1098
  "(\<And>a. a \<in> M \<Longrightarrow> \<mu>' a = \<mu> a) \<Longrightarrow> positive M \<mu>' = positive M \<mu>"
hoelzl@47694
  1099
  by (auto simp add: positive_def)
hoelzl@47694
  1100
hoelzl@47694
  1101
lemma (in sigma_algebra) countably_additive_eq:
hoelzl@47694
  1102
  "(\<And>a. a \<in> M \<Longrightarrow> \<mu>' a = \<mu> a) \<Longrightarrow> countably_additive M \<mu>' = countably_additive M \<mu>"
hoelzl@47694
  1103
  unfolding countably_additive_def
hoelzl@47694
  1104
  by (intro arg_cong[where f=All] ext) (auto simp add: countably_additive_def subset_eq)
hoelzl@47694
  1105
hoelzl@47694
  1106
lemma measure_space_eq:
hoelzl@47694
  1107
  assumes closed: "A \<subseteq> Pow \<Omega>" and eq: "\<And>a. a \<in> sigma_sets \<Omega> A \<Longrightarrow> \<mu> a = \<mu>' a"
hoelzl@47694
  1108
  shows "measure_space \<Omega> (sigma_sets \<Omega> A) \<mu> = measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>'"
hoelzl@47694
  1109
proof -
hoelzl@47694
  1110
  interpret sigma_algebra \<Omega> "sigma_sets \<Omega> A" using closed by (rule sigma_algebra_sigma_sets)
hoelzl@47694
  1111
  from positive_cong_eq[OF eq, of "\<lambda>i. i"] countably_additive_eq[OF eq, of "\<lambda>i. i"] show ?thesis
hoelzl@47694
  1112
    by (auto simp: measure_space_def)
hoelzl@47694
  1113
qed
hoelzl@47694
  1114
hoelzl@47694
  1115
lemma measure_of_eq:
hoelzl@47694
  1116
  assumes closed: "A \<subseteq> Pow \<Omega>" and eq: "(\<And>a. a \<in> sigma_sets \<Omega> A \<Longrightarrow> \<mu> a = \<mu>' a)"
hoelzl@47694
  1117
  shows "measure_of \<Omega> A \<mu> = measure_of \<Omega> A \<mu>'"
hoelzl@47694
  1118
proof -
hoelzl@47694
  1119
  have "measure_space \<Omega> (sigma_sets \<Omega> A) \<mu> = measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>'"
hoelzl@47694
  1120
    using assms by (rule measure_space_eq)
hoelzl@47694
  1121
  with eq show ?thesis
hoelzl@47694
  1122
    by (auto simp add: measure_of_def intro!: arg_cong[where f=Abs_measure])
hoelzl@47694
  1123
qed
hoelzl@47694
  1124
hoelzl@47694
  1125
lemma
hoelzl@47694
  1126
  assumes A: "A \<subseteq> Pow \<Omega>"
hoelzl@47694
  1127
  shows sets_measure_of[simp]: "sets (measure_of \<Omega> A \<mu>) = sigma_sets \<Omega> A" (is ?sets)
hoelzl@47694
  1128
    and space_measure_of[simp]: "space (measure_of \<Omega> A \<mu>) = \<Omega>" (is ?space)
hoelzl@47694
  1129
proof -
hoelzl@47694
  1130
  have "?sets \<and> ?space"
hoelzl@47694
  1131
  proof cases
hoelzl@47694
  1132
    assume "measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>"
hoelzl@47694
  1133
    moreover have "measure_space \<Omega> (sigma_sets \<Omega> A) \<mu> = measure_space \<Omega> (sigma_sets \<Omega> A)
hoelzl@47694
  1134
       (\<lambda>a. if a \<in> sigma_sets \<Omega> A then \<mu> a else 0)"
hoelzl@47694
  1135
      using A by (rule measure_space_eq) auto
hoelzl@47694
  1136
    ultimately show "?sets \<and> ?space"
hoelzl@47694
  1137
      by (auto simp: Abs_measure_inverse measure_of_def sets_def space_def)
hoelzl@47694
  1138
  next
hoelzl@47694
  1139
    assume "\<not> measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>"
hoelzl@47694
  1140
    with A show "?sets \<and> ?space"
hoelzl@47694
  1141
      by (auto simp: Abs_measure_inverse measure_of_def sets_def space_def measure_space_0)
hoelzl@47694
  1142
  qed
hoelzl@47694
  1143
  then show ?sets ?space by auto
hoelzl@47694
  1144
qed
hoelzl@47694
  1145
hoelzl@47694
  1146
lemma (in sigma_algebra) sets_measure_of_eq[simp]:
hoelzl@47694
  1147
  "sets (measure_of \<Omega> M \<mu>) = M"
hoelzl@47694
  1148
  using space_closed by (auto intro!: sigma_sets_eq)
hoelzl@47694
  1149
hoelzl@47694
  1150
lemma (in sigma_algebra) space_measure_of_eq[simp]:
hoelzl@47694
  1151
  "space (measure_of \<Omega> M \<mu>) = \<Omega>"
hoelzl@47694
  1152
  using space_closed by (auto intro!: sigma_sets_eq)
hoelzl@47694
  1153
hoelzl@47694
  1154
lemma measure_of_subset:
hoelzl@47694
  1155
  "M \<subseteq> Pow \<Omega> \<Longrightarrow> M' \<subseteq> M \<Longrightarrow> sets (measure_of \<Omega> M' \<mu>) \<subseteq> sets (measure_of \<Omega> M \<mu>')"
hoelzl@47694
  1156
  by (auto intro!: sigma_sets_subseteq)
hoelzl@47694
  1157
immler@50245
  1158
lemma sigma_sets_mono'':
immler@50245
  1159
  assumes "A \<in> sigma_sets C D"
immler@50245
  1160
  assumes "B \<subseteq> D"
immler@50245
  1161
  assumes "D \<subseteq> Pow C"
immler@50245
  1162
  shows "sigma_sets A B \<subseteq> sigma_sets C D"
immler@50245
  1163
proof
immler@50245
  1164
  fix x assume "x \<in> sigma_sets A B"
immler@50245
  1165
  thus "x \<in> sigma_sets C D"
immler@50245
  1166
  proof induct
immler@50245
  1167
    case (Basic a) with assms have "a \<in> D" by auto
immler@50245
  1168
    thus ?case ..
immler@50245
  1169
  next
immler@50245
  1170
    case Empty show ?case by (rule sigma_sets.Empty)
immler@50245
  1171
  next
immler@50245
  1172
    from assms have "A \<in> sets (sigma C D)" by (subst sets_measure_of[OF `D \<subseteq> Pow C`])
immler@50245
  1173
    moreover case (Compl a) hence "a \<in> sets (sigma C D)" by (subst sets_measure_of[OF `D \<subseteq> Pow C`])
immler@50245
  1174
    ultimately have "A - a \<in> sets (sigma C D)" ..
immler@50245
  1175
    thus ?case by (subst (asm) sets_measure_of[OF `D \<subseteq> Pow C`])
immler@50245
  1176
  next
immler@50245
  1177
    case (Union a)
immler@50245
  1178
    thus ?case by (intro sigma_sets.Union)
immler@50245
  1179
  qed
immler@50245
  1180
qed
immler@50245
  1181
hoelzl@47756
  1182
lemma in_measure_of[intro, simp]: "M \<subseteq> Pow \<Omega> \<Longrightarrow> A \<in> M \<Longrightarrow> A \<in> sets (measure_of \<Omega> M \<mu>)"
hoelzl@47694
  1183
  by auto
hoelzl@47694
  1184
hoelzl@50387
  1185
subsection {* Constructing simple @{typ "'a measure"} *}
hoelzl@47694
  1186
hoelzl@47694
  1187
lemma emeasure_measure_of:
hoelzl@47694
  1188
  assumes M: "M = measure_of \<Omega> A \<mu>"
hoelzl@47694
  1189
  assumes ms: "A \<subseteq> Pow \<Omega>" "positive (sets M) \<mu>" "countably_additive (sets M) \<mu>"
hoelzl@47694
  1190
  assumes X: "X \<in> sets M"
hoelzl@47694
  1191
  shows "emeasure M X = \<mu> X"
hoelzl@47694
  1192
proof -
hoelzl@47694
  1193
  interpret sigma_algebra \<Omega> "sigma_sets \<Omega> A" by (rule sigma_algebra_sigma_sets) fact
hoelzl@47694
  1194
  have "measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>"
hoelzl@47694
  1195
    using ms M by (simp add: measure_space_def sigma_algebra_sigma_sets)
hoelzl@47694
  1196
  moreover have "measure_space \<Omega> (sigma_sets \<Omega> A) (\<lambda>a. if a \<in> sigma_sets \<Omega> A then \<mu> a else 0)
hoelzl@47694
  1197
    = measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>"
hoelzl@47694
  1198
    using ms(1) by (rule measure_space_eq) auto
hoelzl@47694
  1199
  moreover have "X \<in> sigma_sets \<Omega> A"
hoelzl@47694
  1200
    using X M ms by simp
hoelzl@47694
  1201
  ultimately show ?thesis
hoelzl@47694
  1202
    unfolding emeasure_def measure_of_def M
hoelzl@47694
  1203
    by (subst Abs_measure_inverse) (simp_all add: sigma_sets_eq)
hoelzl@47694
  1204
qed
hoelzl@47694
  1205
hoelzl@47694
  1206
lemma emeasure_measure_of_sigma:
hoelzl@47694
  1207
  assumes ms: "sigma_algebra \<Omega> M" "positive M \<mu>" "countably_additive M \<mu>"
hoelzl@47694
  1208
  assumes A: "A \<in> M"
hoelzl@47694
  1209
  shows "emeasure (measure_of \<Omega> M \<mu>) A = \<mu> A"
hoelzl@47694
  1210
proof -
hoelzl@47694
  1211
  interpret sigma_algebra \<Omega> M by fact
hoelzl@47694
  1212
  have "measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>"
hoelzl@47694
  1213
    using ms sigma_sets_eq by (simp add: measure_space_def)
hoelzl@47694
  1214
  moreover have "measure_space \<Omega> (sigma_sets \<Omega> M) (\<lambda>a. if a \<in> sigma_sets \<Omega> M then \<mu> a else 0)
hoelzl@47694
  1215
    = measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>"
hoelzl@47694
  1216
    using space_closed by (rule measure_space_eq) auto
hoelzl@47694
  1217
  ultimately show ?thesis using A
hoelzl@47694
  1218
    unfolding emeasure_def measure_of_def
hoelzl@47694
  1219
    by (subst Abs_measure_inverse) (simp_all add: sigma_sets_eq)
hoelzl@47694
  1220
qed
hoelzl@47694
  1221
hoelzl@47694
  1222
lemma measure_cases[cases type: measure]:
hoelzl@47694
  1223
  obtains (measure) \<Omega> A \<mu> where "x = Abs_measure (\<Omega>, A, \<mu>)" "\<forall>a\<in>-A. \<mu> a = 0" "measure_space \<Omega> A \<mu>"
hoelzl@47694
  1224
  by atomize_elim (cases x, auto)
hoelzl@47694
  1225
hoelzl@47694
  1226
lemma sets_eq_imp_space_eq:
hoelzl@47694
  1227
  "sets M = sets M' \<Longrightarrow> space M = space M'"
immler@50244
  1228
  using sets.top[of M] sets.top[of M'] sets.space_closed[of M] sets.space_closed[of M']
hoelzl@47694
  1229
  by blast
hoelzl@47694
  1230
hoelzl@47694
  1231
lemma emeasure_notin_sets: "A \<notin> sets M \<Longrightarrow> emeasure M A = 0"
hoelzl@47694
  1232
  by (cases M) (auto simp: sets_def emeasure_def Abs_measure_inverse measure_space_def)
hoelzl@47694
  1233
hoelzl@47694
  1234
lemma measure_notin_sets: "A \<notin> sets M \<Longrightarrow> measure M A = 0"
hoelzl@47694
  1235
  by (simp add: measure_def emeasure_notin_sets)
hoelzl@47694
  1236
hoelzl@47694
  1237
lemma measure_eqI:
hoelzl@47694
  1238
  fixes M N :: "'a measure"
hoelzl@47694
  1239
  assumes "sets M = sets N" and eq: "\<And>A. A \<in> sets M \<Longrightarrow> emeasure M A = emeasure N A"
hoelzl@47694
  1240
  shows "M = N"
hoelzl@47694
  1241
proof (cases M N rule: measure_cases[case_product measure_cases])
hoelzl@47694
  1242
  case (measure_measure \<Omega> A \<mu> \<Omega>' A' \<mu>')
hoelzl@47694
  1243
  interpret M: sigma_algebra \<Omega> A using measure_measure by (auto simp: measure_space_def)
hoelzl@47694
  1244
  interpret N: sigma_algebra \<Omega>' A' using measure_measure by (auto simp: measure_space_def)
hoelzl@47694
  1245
  have "A = sets M" "A' = sets N"
hoelzl@47694
  1246
    using measure_measure by (simp_all add: sets_def Abs_measure_inverse)
hoelzl@47694
  1247
  with `sets M = sets N` have "A = A'" by simp
hoelzl@47694
  1248
  moreover with M.top N.top M.space_closed N.space_closed have "\<Omega> = \<Omega>'" by auto
hoelzl@47694
  1249
  moreover { fix B have "\<mu> B = \<mu>' B"
hoelzl@47694
  1250
    proof cases
hoelzl@47694
  1251
      assume "B \<in> A"
hoelzl@47694
  1252
      with eq `A = sets M` have "emeasure M B = emeasure N B" by simp
hoelzl@47694
  1253
      with measure_measure show "\<mu> B = \<mu>' B"
hoelzl@47694
  1254
        by (simp add: emeasure_def Abs_measure_inverse)
hoelzl@47694
  1255
    next
hoelzl@47694
  1256
      assume "B \<notin> A"
hoelzl@47694
  1257
      with `A = sets M` `A' = sets N` `A = A'` have "B \<notin> sets M" "B \<notin> sets N"
hoelzl@47694
  1258
        by auto
hoelzl@47694
  1259
      then have "emeasure M B = 0" "emeasure N B = 0"
hoelzl@47694
  1260
        by (simp_all add: emeasure_notin_sets)
hoelzl@47694
  1261
      with measure_measure show "\<mu> B = \<mu>' B"
hoelzl@47694
  1262
        by (simp add: emeasure_def Abs_measure_inverse)
hoelzl@47694
  1263
    qed }
hoelzl@47694
  1264
  then have "\<mu> = \<mu>'" by auto
hoelzl@47694
  1265
  ultimately show "M = N"
hoelzl@47694
  1266
    by (simp add: measure_measure)
hoelzl@38656
  1267
qed
hoelzl@38656
  1268
hoelzl@47694
  1269
lemma emeasure_sigma: "A \<subseteq> Pow \<Omega> \<Longrightarrow> emeasure (sigma \<Omega> A) = (\<lambda>_. 0)"
hoelzl@47694
  1270
  using measure_space_0[of A \<Omega>]
hoelzl@47694
  1271
  by (simp add: measure_of_def emeasure_def Abs_measure_inverse)
hoelzl@47694
  1272
hoelzl@47694
  1273
lemma sigma_eqI:
hoelzl@47694
  1274
  assumes [simp]: "M \<subseteq> Pow \<Omega>" "N \<subseteq> Pow \<Omega>" "sigma_sets \<Omega> M = sigma_sets \<Omega> N"
hoelzl@47694
  1275
  shows "sigma \<Omega> M = sigma \<Omega> N"
hoelzl@47694
  1276
  by (rule measure_eqI) (simp_all add: emeasure_sigma)
hoelzl@47694
  1277
hoelzl@50387
  1278
subsection {* Measurable functions *}
hoelzl@47694
  1279
hoelzl@47694
  1280
definition measurable :: "'a measure \<Rightarrow> 'b measure \<Rightarrow> ('a \<Rightarrow> 'b) set" where
hoelzl@47694
  1281
  "measurable A B = {f \<in> space A -> space B. \<forall>y \<in> sets B. f -` y \<inter> space A \<in> sets A}"
hoelzl@47694
  1282
hoelzl@47694
  1283
lemma measurable_space:
hoelzl@47694
  1284
  "f \<in> measurable M A \<Longrightarrow> x \<in> space M \<Longrightarrow> f x \<in> space A"
hoelzl@47694
  1285
   unfolding measurable_def by auto
hoelzl@47694
  1286
hoelzl@47694
  1287
lemma measurable_sets:
hoelzl@47694
  1288
  "f \<in> measurable M A \<Longrightarrow> S \<in> sets A \<Longrightarrow> f -` S \<inter> space M \<in> sets M"
hoelzl@47694
  1289
   unfolding measurable_def by auto
hoelzl@47694
  1290
hoelzl@50002
  1291
lemma measurable_sets_Collect:
hoelzl@50002
  1292
  assumes f: "f \<in> measurable M N" and P: "{x\<in>space N. P x} \<in> sets N" shows "{x\<in>space M. P (f x)} \<in> sets M"
hoelzl@50002
  1293
proof -
hoelzl@50002
  1294
  have "f -` {x \<in> space N. P x} \<inter> space M = {x\<in>space M. P (f x)}"
hoelzl@50002
  1295
    using measurable_space[OF f] by auto
hoelzl@50002
  1296
  with measurable_sets[OF f P] show ?thesis
hoelzl@50002
  1297
    by simp
hoelzl@50002
  1298
qed
hoelzl@50002
  1299
hoelzl@47694
  1300
lemma measurable_sigma_sets:
hoelzl@47694
  1301
  assumes B: "sets N = sigma_sets \<Omega> A" "A \<subseteq> Pow \<Omega>"
hoelzl@47694
  1302
      and f: "f \<in> space M \<rightarrow> \<Omega>"
hoelzl@47694
  1303
      and ba: "\<And>y. y \<in> A \<Longrightarrow> (f -` y) \<inter> space M \<in> sets M"
hoelzl@47694
  1304
  shows "f \<in> measurable M N"
hoelzl@47694
  1305
proof -
hoelzl@47694
  1306
  interpret A: sigma_algebra \<Omega> "sigma_sets \<Omega> A" using B(2) by (rule sigma_algebra_sigma_sets)
immler@50244
  1307
  from B sets.top[of N] A.top sets.space_closed[of N] A.space_closed have \<Omega>: "\<Omega> = space N" by force
hoelzl@47694
  1308
  
hoelzl@47694
  1309
  { fix X assume "X \<in> sigma_sets \<Omega> A"
hoelzl@47694
  1310
    then have "f -` X \<inter> space M \<in> sets M \<and> X \<subseteq> \<Omega>"
hoelzl@47694
  1311
      proof induct
hoelzl@47694
  1312
        case (Basic a) then show ?case
hoelzl@47694
  1313
          by (auto simp add: ba) (metis B(2) subsetD PowD)
hoelzl@47694
  1314
      next
hoelzl@47694
  1315
        case (Compl a)
hoelzl@47694
  1316
        have [simp]: "f -` \<Omega> \<inter> space M = space M"
hoelzl@47694
  1317
          by (auto simp add: funcset_mem [OF f])
hoelzl@47694
  1318
        then show ?case
immler@50244
  1319
          by (auto simp add: vimage_Diff Diff_Int_distrib2 sets.compl_sets Compl)
hoelzl@47694
  1320
      next
hoelzl@47694
  1321
        case (Union a)
hoelzl@47694
  1322
        then show ?case
hoelzl@47694
  1323
          by (simp add: vimage_UN, simp only: UN_extend_simps(4)) blast
hoelzl@47694
  1324
      qed auto }
hoelzl@47694
  1325
  with f show ?thesis
hoelzl@47694
  1326
    by (auto simp add: measurable_def B \<Omega>)
hoelzl@47694
  1327
qed
hoelzl@47694
  1328
hoelzl@47694
  1329
lemma measurable_measure_of:
hoelzl@47694
  1330
  assumes B: "N \<subseteq> Pow \<Omega>"
hoelzl@47694
  1331
      and f: "f \<in> space M \<rightarrow> \<Omega>"
hoelzl@47694
  1332
      and ba: "\<And>y. y \<in> N \<Longrightarrow> (f -` y) \<inter> space M \<in> sets M"
hoelzl@47694
  1333
  shows "f \<in> measurable M (measure_of \<Omega> N \<mu>)"
hoelzl@47694
  1334
proof -
hoelzl@47694
  1335
  have "sets (measure_of \<Omega> N \<mu>) = sigma_sets \<Omega> N"
hoelzl@47694
  1336
    using B by (rule sets_measure_of)
hoelzl@47694
  1337
  from this assms show ?thesis by (rule measurable_sigma_sets)
hoelzl@47694
  1338
qed
hoelzl@47694
  1339
hoelzl@47694
  1340
lemma measurable_iff_measure_of:
hoelzl@47694
  1341
  assumes "N \<subseteq> Pow \<Omega>" "f \<in> space M \<rightarrow> \<Omega>"
hoelzl@47694
  1342
  shows "f \<in> measurable M (measure_of \<Omega> N \<mu>) \<longleftrightarrow> (\<forall>A\<in>N. f -` A \<inter> space M \<in> sets M)"
hoelzl@47756
  1343
  by (metis assms in_measure_of measurable_measure_of assms measurable_sets)
hoelzl@47694
  1344
hoelzl@50003
  1345
lemma measurable_cong_sets:
hoelzl@50003
  1346
  assumes sets: "sets M = sets M'" "sets N = sets N'"
hoelzl@50003
  1347
  shows "measurable M N = measurable M' N'"
hoelzl@50003
  1348
  using sets[THEN sets_eq_imp_space_eq] sets by (simp add: measurable_def)
hoelzl@50003
  1349
hoelzl@47694
  1350
lemma measurable_cong:
hoelzl@47694
  1351
  assumes "\<And> w. w \<in> space M \<Longrightarrow> f w = g w"
hoelzl@47694
  1352
  shows "f \<in> measurable M M' \<longleftrightarrow> g \<in> measurable M M'"
hoelzl@47694
  1353
  unfolding measurable_def using assms
hoelzl@47694
  1354
  by (simp cong: vimage_inter_cong Pi_cong)
hoelzl@47694
  1355
hoelzl@47694
  1356
lemma measurable_eqI:
hoelzl@47694
  1357
     "\<lbrakk> space m1 = space m1' ; space m2 = space m2' ;
hoelzl@47694
  1358
        sets m1 = sets m1' ; sets m2 = sets m2' \<rbrakk>
hoelzl@47694
  1359
      \<Longrightarrow> measurable m1 m2 = measurable m1' m2'"
hoelzl@47694
  1360
  by (simp add: measurable_def sigma_algebra_iff2)
hoelzl@47694
  1361
hoelzl@50003
  1362
lemma measurable_compose:
hoelzl@50003
  1363
  assumes f: "f \<in> measurable M N" and g: "g \<in> measurable N L"
hoelzl@50003
  1364
  shows "(\<lambda>x. g (f x)) \<in> measurable M L"
hoelzl@50003
  1365
proof -
hoelzl@50003
  1366
  have "\<And>A. (\<lambda>x. g (f x)) -` A \<inter> space M = f -` (g -` A \<inter> space N) \<inter> space M"
hoelzl@50003
  1367
    using measurable_space[OF f] by auto
hoelzl@50003
  1368
  with measurable_space[OF f] measurable_space[OF g] show ?thesis
hoelzl@50003
  1369
    by (auto intro: measurable_sets[OF f] measurable_sets[OF g]
hoelzl@50003
  1370
             simp del: vimage_Int simp add: measurable_def)
hoelzl@50003
  1371
qed
hoelzl@50003
  1372
hoelzl@50003
  1373
lemma measurable_comp:
hoelzl@50003
  1374
  "f \<in> measurable M N \<Longrightarrow> g \<in> measurable N L \<Longrightarrow> g \<circ> f \<in> measurable M L"
hoelzl@50003
  1375
  using measurable_compose[of f M N g L] by (simp add: comp_def)
hoelzl@50003
  1376
hoelzl@50003
  1377
lemma measurable_const:
hoelzl@47694
  1378
  "c \<in> space M' \<Longrightarrow> (\<lambda>x. c) \<in> measurable M M'"
hoelzl@47694
  1379
  by (auto simp add: measurable_def)
hoelzl@47694
  1380
hoelzl@47694
  1381
lemma measurable_If:
hoelzl@47694
  1382
  assumes measure: "f \<in> measurable M M'" "g \<in> measurable M M'"
hoelzl@47694
  1383
  assumes P: "{x\<in>space M. P x} \<in> sets M"
hoelzl@47694
  1384
  shows "(\<lambda>x. if P x then f x else g x) \<in> measurable M M'"
hoelzl@47694
  1385
  unfolding measurable_def
hoelzl@47694
  1386
proof safe
hoelzl@47694
  1387
  fix x assume "x \<in> space M"
hoelzl@47694
  1388
  thus "(if P x then f x else g x) \<in> space M'"
hoelzl@47694
  1389
    using measure unfolding measurable_def by auto
hoelzl@47694
  1390
next
hoelzl@47694
  1391
  fix A assume "A \<in> sets M'"
hoelzl@47694
  1392
  hence *: "(\<lambda>x. if P x then f x else g x) -` A \<inter> space M =
hoelzl@47694
  1393
    ((f -` A \<inter> space M) \<inter> {x\<in>space M. P x}) \<union>
hoelzl@47694
  1394
    ((g -` A \<inter> space M) \<inter> (space M - {x\<in>space M. P x}))"
hoelzl@47694
  1395
    using measure unfolding measurable_def by (auto split: split_if_asm)
hoelzl@47694
  1396
  show "(\<lambda>x. if P x then f x else g x) -` A \<inter> space M \<in> sets M"
hoelzl@47694
  1397
    using `A \<in> sets M'` measure P unfolding * measurable_def
immler@50244
  1398
    by (auto intro!: sets.Un)
hoelzl@47694
  1399
qed
hoelzl@47694
  1400
hoelzl@47694
  1401
lemma measurable_If_set:
hoelzl@47694
  1402
  assumes measure: "f \<in> measurable M M'" "g \<in> measurable M M'"
hoelzl@49773
  1403
  assumes P: "A \<inter> space M \<in> sets M"
hoelzl@47694
  1404
  shows "(\<lambda>x. if x \<in> A then f x else g x) \<in> measurable M M'"
hoelzl@47694
  1405
proof (rule measurable_If[OF measure])
hoelzl@49773
  1406
  have "{x \<in> space M. x \<in> A} = A \<inter> space M" by auto
hoelzl@49773
  1407
  thus "{x \<in> space M. x \<in> A} \<in> sets M" using `A \<inter> space M \<in> sets M` by auto
hoelzl@47694
  1408
qed
hoelzl@47694
  1409
hoelzl@50003
  1410
lemma measurable_ident: "id \<in> measurable M M"
hoelzl@50002
  1411
  by (auto simp add: measurable_def)
hoelzl@50002
  1412
hoelzl@50021
  1413
lemma measurable_ident_sets:
hoelzl@50021
  1414
  assumes eq: "sets M = sets M'" shows "(\<lambda>x. x) \<in> measurable M M'"
hoelzl@50021
  1415
  using measurable_ident[of M]
hoelzl@50021
  1416
  unfolding id_def measurable_def eq sets_eq_imp_space_eq[OF eq] .
hoelzl@49782
  1417
hoelzl@50002
  1418
lemma sets_Least:
hoelzl@47694
  1419
  assumes meas: "\<And>i::nat. {x\<in>space M. P i x} \<in> M"
hoelzl@47694
  1420
  shows "(\<lambda>x. LEAST j. P j x) -` A \<inter> space M \<in> sets M"
hoelzl@47694
  1421
proof -
hoelzl@47694
  1422
  { fix i have "(\<lambda>x. LEAST j. P j x) -` {i} \<inter> space M \<in> sets M"
hoelzl@47694
  1423
    proof cases
hoelzl@47694
  1424
      assume i: "(LEAST j. False) = i"
hoelzl@47694
  1425
      have "(\<lambda>x. LEAST j. P j x) -` {i} \<inter> space M =
hoelzl@47694
  1426
        {x\<in>space M. P i x} \<inter> (space M - (\<Union>j<i. {x\<in>space M. P j x})) \<union> (space M - (\<Union>i. {x\<in>space M. P i x}))"
hoelzl@47694
  1427
        by (simp add: set_eq_iff, safe)
hoelzl@47694
  1428
           (insert i, auto dest: Least_le intro: LeastI intro!: Least_equality)
hoelzl@47694
  1429
      with meas show ?thesis
immler@50244
  1430
        by (auto intro!: sets.Int)
hoelzl@47694
  1431
    next
hoelzl@47694
  1432
      assume i: "(LEAST j. False) \<noteq> i"
hoelzl@47694
  1433
      then have "(\<lambda>x. LEAST j. P j x) -` {i} \<inter> space M =
hoelzl@47694
  1434
        {x\<in>space M. P i x} \<inter> (space M - (\<Union>j<i. {x\<in>space M. P j x}))"
hoelzl@47694
  1435
      proof (simp add: set_eq_iff, safe)
hoelzl@47694
  1436
        fix x assume neq: "(LEAST j. False) \<noteq> (LEAST j. P j x)"
hoelzl@47694
  1437
        have "\<exists>j. P j x"
hoelzl@47694
  1438
          by (rule ccontr) (insert neq, auto)
hoelzl@47694
  1439
        then show "P (LEAST j. P j x) x" by (rule LeastI_ex)
hoelzl@47694
  1440
      qed (auto dest: Least_le intro!: Least_equality)
hoelzl@47694
  1441
      with meas show ?thesis
hoelzl@47694
  1442
        by auto
hoelzl@47694
  1443
    qed }
hoelzl@47694
  1444
  then have "(\<Union>i\<in>A. (\<lambda>x. LEAST j. P j x) -` {i} \<inter> space M) \<in> sets M"
immler@50244
  1445
    by (intro sets.countable_UN) auto
hoelzl@47694
  1446
  moreover have "(\<Union>i\<in>A. (\<lambda>x. LEAST j. P j x) -` {i} \<inter> space M) =
hoelzl@47694
  1447
    (\<lambda>x. LEAST j. P j x) -` A \<inter> space M" by auto
hoelzl@47694
  1448
  ultimately show ?thesis by auto
hoelzl@47694
  1449
qed
hoelzl@47694
  1450
hoelzl@47694
  1451
lemma measurable_strong:
hoelzl@47694
  1452
  fixes f :: "'a \<Rightarrow> 'b" and g :: "'b \<Rightarrow> 'c"
hoelzl@47694
  1453
  assumes f: "f \<in> measurable a b" and g: "g \<in> space b \<rightarrow> space c"
hoelzl@47694
  1454
      and t: "f ` (space a) \<subseteq> t"
hoelzl@47694
  1455
      and cb: "\<And>s. s \<in> sets c \<Longrightarrow> (g -` s) \<inter> t \<in> sets b"
hoelzl@47694
  1456
  shows "(g o f) \<in> measurable a c"
hoelzl@47694
  1457
proof -
hoelzl@47694
  1458
  have fab: "f \<in> (space a -> space b)"
hoelzl@47694
  1459
   and ba: "\<And>y. y \<in> sets b \<Longrightarrow> (f -` y) \<inter> (space a) \<in> sets a" using f
hoelzl@47694
  1460
     by (auto simp add: measurable_def)
hoelzl@47694
  1461
  have eq: "\<And>y. f -` g -` y \<inter> space a = f -` (g -` y \<inter> t) \<inter> space a" using t
hoelzl@47694
  1462
    by force
hoelzl@47694
  1463
  show ?thesis
hoelzl@47694
  1464
    apply (auto simp add: measurable_def vimage_compose)
hoelzl@47694
  1465
    apply (metis funcset_mem fab g)
hoelzl@47694
  1466
    apply (subst eq, metis ba cb)
hoelzl@47694
  1467
    done
hoelzl@47694
  1468
qed
hoelzl@47694
  1469
hoelzl@47694
  1470
lemma measurable_mono1:
hoelzl@47694
  1471
  "M' \<subseteq> Pow \<Omega> \<Longrightarrow> M \<subseteq> M' \<Longrightarrow>
hoelzl@47694
  1472
    measurable (measure_of \<Omega> M \<mu>) N \<subseteq> measurable (measure_of \<Omega> M' \<mu>') N"
hoelzl@47694
  1473
  using measure_of_subset[of M' \<Omega> M] by (auto simp add: measurable_def)
hoelzl@47694
  1474
hoelzl@50387
  1475
subsection {* Counting space *}
hoelzl@50002
  1476
hoelzl@50002
  1477
definition count_space :: "'a set \<Rightarrow> 'a measure" where
hoelzl@50002
  1478
  "count_space \<Omega> = measure_of \<Omega> (Pow \<Omega>) (\<lambda>A. if finite A then ereal (card A) else \<infinity>)"
hoelzl@50002
  1479
hoelzl@50002
  1480
lemma 
hoelzl@50002
  1481
  shows space_count_space[simp]: "space (count_space \<Omega>) = \<Omega>"
hoelzl@50002
  1482
    and sets_count_space[simp]: "sets (count_space \<Omega>) = Pow \<Omega>"
hoelzl@50002
  1483
  using sigma_sets_into_sp[of "Pow \<Omega>" \<Omega>]
hoelzl@50002
  1484
  by (auto simp: count_space_def)
hoelzl@50002
  1485
hoelzl@50002
  1486
lemma measurable_count_space_eq1[simp]:
hoelzl@50002
  1487
  "f \<in> measurable (count_space A) M \<longleftrightarrow> f \<in> A \<rightarrow> space M"
hoelzl@50002
  1488
 unfolding measurable_def by simp
hoelzl@50002
  1489
hoelzl@50002
  1490
lemma measurable_count_space_eq2:
hoelzl@50002
  1491
  assumes "finite A"
hoelzl@50002
  1492
  shows "f \<in> measurable M (count_space A) \<longleftrightarrow> (f \<in> space M \<rightarrow> A \<and> (\<forall>a\<in>A. f -` {a} \<inter> space M \<in> sets M))"
hoelzl@50002
  1493
proof -
hoelzl@50002
  1494
  { fix X assume "X \<subseteq> A" "f \<in> space M \<rightarrow> A"
hoelzl@50002
  1495
    with `finite A` have "f -` X \<inter> space M = (\<Union>a\<in>X. f -` {a} \<inter> space M)" "finite X"
hoelzl@50002
  1496
      by (auto dest: finite_subset)
hoelzl@50002
  1497
    moreover assume "\<forall>a\<in>A. f -` {a} \<inter> space M \<in> sets M"
hoelzl@50002
  1498
    ultimately have "f -` X \<inter> space M \<in> sets M"
immler@50244
  1499
      using `X \<subseteq> A` by (auto intro!: sets.finite_UN simp del: UN_simps) }
hoelzl@50002
  1500
  then show ?thesis
hoelzl@50002
  1501
    unfolding measurable_def by auto
hoelzl@50002
  1502
qed
hoelzl@50002
  1503
hoelzl@50002
  1504
lemma measurable_compose_countable:
hoelzl@50002
  1505
  assumes f: "\<And>i::'i::countable. (\<lambda>x. f i x) \<in> measurable M N" and g: "g \<in> measurable M (count_space UNIV)"
hoelzl@50002
  1506
  shows "(\<lambda>x. f (g x) x) \<in> measurable M N"
hoelzl@50002
  1507
  unfolding measurable_def
hoelzl@50002
  1508
proof safe
hoelzl@50002
  1509
  fix x assume "x \<in> space M" then show "f (g x) x \<in> space N"
hoelzl@50002
  1510
    using f[THEN measurable_space] g[THEN measurable_space] by auto
hoelzl@50002
  1511
next
hoelzl@50002
  1512
  fix A assume A: "A \<in> sets N"
hoelzl@50002
  1513
  have "(\<lambda>x. f (g x) x) -` A \<inter> space M = (\<Union>i. (g -` {i} \<inter> space M) \<inter> (f i -` A \<inter> space M))"
hoelzl@50002
  1514
    by auto
hoelzl@50002
  1515
  also have "\<dots> \<in> sets M" using f[THEN measurable_sets, OF A] g[THEN measurable_sets]
immler@50244
  1516
    by (auto intro!: sets.countable_UN measurable_sets)
hoelzl@50002
  1517
  finally show "(\<lambda>x. f (g x) x) -` A \<inter> space M \<in> sets M" .
hoelzl@50002
  1518
qed
hoelzl@50002
  1519
hoelzl@50002
  1520
lemma measurable_count_space_const:
hoelzl@50002
  1521
  "(\<lambda>x. c) \<in> measurable M (count_space UNIV)"
hoelzl@50003
  1522
  by (simp add: measurable_const)
hoelzl@50002
  1523
hoelzl@50002
  1524
lemma measurable_count_space:
hoelzl@50002
  1525
  "f \<in> measurable (count_space A) (count_space UNIV)"
hoelzl@50002
  1526
  by simp
hoelzl@50002
  1527
hoelzl@50002
  1528
lemma measurable_compose_rev:
hoelzl@50002
  1529
  assumes f: "f \<in> measurable L N" and g: "g \<in> measurable M L"
hoelzl@50002
  1530
  shows "(\<lambda>x. f (g x)) \<in> measurable M N"
hoelzl@50002
  1531
  using measurable_compose[OF g f] .
hoelzl@50002
  1532
hoelzl@50002
  1533
hoelzl@47694
  1534
subsection {* Extend measure *}
hoelzl@47694
  1535
hoelzl@47694
  1536
definition "extend_measure \<Omega> I G \<mu> =
hoelzl@47694
  1537
  (if (\<exists>\<mu>'. (\<forall>i\<in>I. \<mu>' (G i) = \<mu> i) \<and> measure_space \<Omega> (sigma_sets \<Omega> (G`I)) \<mu>') \<and> \<not> (\<forall>i\<in>I. \<mu> i = 0)
hoelzl@47694
  1538
      then measure_of \<Omega> (G`I) (SOME \<mu>'. (\<forall>i\<in>I. \<mu>' (G i) = \<mu> i) \<and> measure_space \<Omega> (sigma_sets \<Omega> (G`I)) \<mu>')
hoelzl@47694
  1539
      else measure_of \<Omega> (G`I) (\<lambda>_. 0))"
hoelzl@47694
  1540
hoelzl@47694
  1541
lemma space_extend_measure: "G ` I \<subseteq> Pow \<Omega> \<Longrightarrow> space (extend_measure \<Omega> I G \<mu>) = \<Omega>"
hoelzl@47694
  1542
  unfolding extend_measure_def by simp
hoelzl@47694
  1543
hoelzl@47694
  1544
lemma sets_extend_measure: "G ` I \<subseteq> Pow \<Omega> \<Longrightarrow> sets (extend_measure \<Omega> I G \<mu>) = sigma_sets \<Omega> (G`I)"
hoelzl@47694
  1545
  unfolding extend_measure_def by simp
hoelzl@47694
  1546
hoelzl@47694
  1547
lemma emeasure_extend_measure:
hoelzl@47694
  1548
  assumes M: "M = extend_measure \<Omega> I G \<mu>"
hoelzl@47694
  1549
    and eq: "\<And>i. i \<in> I \<Longrightarrow> \<mu>' (G i) = \<mu> i"
hoelzl@47694
  1550
    and ms: "G ` I \<subseteq> Pow \<Omega>" "positive (sets M) \<mu>'" "countably_additive (sets M) \<mu>'"
hoelzl@47694
  1551
    and "i \<in> I"
hoelzl@47694
  1552
  shows "emeasure M (G i) = \<mu> i"
hoelzl@47694
  1553
proof cases
hoelzl@47694
  1554
  assume *: "(\<forall>i\<in>I. \<mu> i = 0)"
hoelzl@47694
  1555
  with M have M_eq: "M = measure_of \<Omega> (G`I) (\<lambda>_. 0)"
hoelzl@47694
  1556
   by (simp add: extend_measure_def)
hoelzl@47694
  1557
  from measure_space_0[OF ms(1)] ms `i\<in>I`
hoelzl@47694
  1558
  have "emeasure M (G i) = 0"
hoelzl@47694
  1559
    by (intro emeasure_measure_of[OF M_eq]) (auto simp add: M measure_space_def sets_extend_measure)
hoelzl@47694
  1560
  with `i\<in>I` * show ?thesis
hoelzl@47694
  1561
    by simp
hoelzl@47694
  1562
next
hoelzl@47694
  1563
  def P \<equiv> "\<lambda>\<mu>'. (\<forall>i\<in>I. \<mu>' (G i) = \<mu> i) \<and> measure_space \<Omega> (sigma_sets \<Omega> (G`I)) \<mu>'"
hoelzl@47694
  1564
  assume "\<not> (\<forall>i\<in>I. \<mu> i = 0)"
hoelzl@47694
  1565
  moreover
hoelzl@47694
  1566
  have "measure_space (space M) (sets M) \<mu>'"
hoelzl@47694
  1567
    using ms unfolding measure_space_def by auto default
hoelzl@47694
  1568
  with ms eq have "\<exists>\<mu>'. P \<mu>'"
hoelzl@47694
  1569
    unfolding P_def
hoelzl@47694
  1570
    by (intro exI[of _ \<mu>']) (auto simp add: M space_extend_measure sets_extend_measure)
hoelzl@47694
  1571
  ultimately have M_eq: "M = measure_of \<Omega> (G`I) (Eps P)"
hoelzl@47694
  1572
    by (simp add: M extend_measure_def P_def[symmetric])
hoelzl@47694
  1573
hoelzl@47694
  1574
  from `\<exists>\<mu>'. P \<mu>'` have P: "P (Eps P)" by (rule someI_ex)
hoelzl@47694
  1575
  show "emeasure M (G i) = \<mu> i"
hoelzl@47694
  1576
  proof (subst emeasure_measure_of[OF M_eq])
hoelzl@47694
  1577
    have sets_M: "sets M = sigma_sets \<Omega> (G`I)"
hoelzl@47694
  1578
      using M_eq ms by (auto simp: sets_extend_measure)
hoelzl@47694
  1579
    then show "G i \<in> sets M" using `i \<in> I` by auto
hoelzl@47694
  1580
    show "positive (sets M) (Eps P)" "countably_additive (sets M) (Eps P)" "Eps P (G i) = \<mu> i"
hoelzl@47694
  1581
      using P `i\<in>I` by (auto simp add: sets_M measure_space_def P_def)
hoelzl@47694
  1582
  qed fact
hoelzl@47694
  1583
qed
hoelzl@47694
  1584
hoelzl@47694
  1585
lemma emeasure_extend_measure_Pair:
hoelzl@47694
  1586
  assumes M: "M = extend_measure \<Omega> {(i, j). I i j} (\<lambda>(i, j). G i j) (\<lambda>(i, j). \<mu> i j)"
hoelzl@47694
  1587
    and eq: "\<And>i j. I i j \<Longrightarrow> \<mu>' (G i j) = \<mu> i j"
hoelzl@47694
  1588
    and ms: "\<And>i j. I i j \<Longrightarrow> G i j \<in> Pow \<Omega>" "positive (sets M) \<mu>'" "countably_additive (sets M) \<mu>'"
hoelzl@47694
  1589
    and "I i j"
hoelzl@47694
  1590
  shows "emeasure M (G i j) = \<mu> i j"
hoelzl@47694
  1591
  using emeasure_extend_measure[OF M _ _ ms(2,3), of "(i,j)"] eq ms(1) `I i j`
hoelzl@47694
  1592
  by (auto simp: subset_eq)
hoelzl@47694
  1593
hoelzl@39090
  1594
subsection {* Sigma algebra generated by function preimages *}
hoelzl@39090
  1595
hoelzl@47694
  1596
definition
hoelzl@47694
  1597
  "vimage_algebra M S f = sigma S ((\<lambda>A. f -` A \<inter> S) ` sets M)"
hoelzl@39090
  1598
hoelzl@47694
  1599
lemma sigma_algebra_preimages:
hoelzl@40859
  1600
  fixes f :: "'x \<Rightarrow> 'a"
hoelzl@47694
  1601
  assumes "f \<in> S \<rightarrow> space M"
hoelzl@47694
  1602
  shows "sigma_algebra S ((\<lambda>A. f -` A \<inter> S) ` sets M)"
hoelzl@47694
  1603
    (is "sigma_algebra _ (?F ` sets M)")
hoelzl@40859
  1604
proof (simp add: sigma_algebra_iff2, safe)
hoelzl@40859
  1605
  show "{} \<in> ?F ` sets M" by blast
hoelzl@40859
  1606
next
hoelzl@47694
  1607
  fix A assume "A \<in> sets M"
hoelzl@47694
  1608
  moreover have "S - ?F A = ?F (space M - A)"
hoelzl@40859
  1609
    using assms by auto
hoelzl@47694
  1610
  ultimately show "S - ?F A \<in> ?F ` sets M"
hoelzl@40859
  1611
    by blast
hoelzl@40859
  1612
next
hoelzl@47694
  1613
  fix A :: "nat \<Rightarrow> 'x set" assume *: "range A \<subseteq> ?F ` M"
hoelzl@47694
  1614
  have "\<forall>i. \<exists>b. b \<in> M \<and> A i = ?F b"
hoelzl@40859
  1615
  proof safe
hoelzl@40859
  1616
    fix i
hoelzl@47694
  1617
    have "A i \<in> ?F ` M" using * by auto
hoelzl@47694
  1618
    then show "\<exists>b. b \<in> M \<and> A i = ?F b" by auto
hoelzl@40859
  1619
  qed
hoelzl@47694
  1620
  from choice[OF this] obtain b where b: "range b \<subseteq> M" "\<And>i. A i = ?F (b i)"
hoelzl@40859
  1621
    by auto
hoelzl@47694
  1622
  then have "(\<Union>i. A i) = ?F (\<Union>i. b i)" by auto
hoelzl@47694
  1623
  then show "(\<Union>i. A i) \<in> ?F ` M" using b(1) by blast
hoelzl@40859
  1624
qed
hoelzl@40859
  1625
hoelzl@47694
  1626
lemma sets_vimage_algebra[simp]:
hoelzl@47694
  1627
  "f \<in> S \<rightarrow> space M \<Longrightarrow> sets (vimage_algebra M S f) = (\<lambda>A. f -` A \<inter> S) ` sets M"
hoelzl@47694
  1628
  using sigma_algebra.sets_measure_of_eq[OF sigma_algebra_preimages, of f S M]
hoelzl@47694
  1629
  by (simp add: vimage_algebra_def)
hoelzl@47694
  1630
hoelzl@47694
  1631
lemma space_vimage_algebra[simp]:
hoelzl@47694
  1632
  "f \<in> S \<rightarrow> space M \<Longrightarrow> space (vimage_algebra M S f) = S"
hoelzl@47694
  1633
  using sigma_algebra.space_measure_of_eq[OF sigma_algebra_preimages, of f S M]
hoelzl@47694
  1634
  by (simp add: vimage_algebra_def)
hoelzl@47694
  1635
hoelzl@47694
  1636
lemma in_vimage_algebra[simp]:
hoelzl@47694
  1637
  "f \<in> S \<rightarrow> space M \<Longrightarrow> A \<in> sets (vimage_algebra M S f) \<longleftrightarrow> (\<exists>B\<in>sets M. A = f -` B \<inter> S)"
hoelzl@47694
  1638
  by (simp add: image_iff)
hoelzl@47694
  1639
hoelzl@47694
  1640
lemma measurable_vimage_algebra:
hoelzl@39090
  1641
  fixes S :: "'c set" assumes "f \<in> S \<rightarrow> space M"
hoelzl@47694
  1642
  shows "f \<in> measurable (vimage_algebra M S f) M"
hoelzl@47694
  1643
  unfolding measurable_def using assms by force
hoelzl@39090
  1644
hoelzl@47694
  1645
lemma measurable_vimage:
hoelzl@40859
  1646
  fixes g :: "'a \<Rightarrow> 'c" and f :: "'d \<Rightarrow> 'a"
hoelzl@40859
  1647
  assumes "g \<in> measurable M M2" "f \<in> S \<rightarrow> space M"
hoelzl@47694
  1648
  shows "(\<lambda>x. g (f x)) \<in> measurable (vimage_algebra M S f) M2"
hoelzl@40859
  1649
proof -
hoelzl@40859
  1650
  note measurable_vimage_algebra[OF assms(2)]
hoelzl@40859
  1651
  from measurable_comp[OF this assms(1)]
hoelzl@40859
  1652
  show ?thesis by (simp add: comp_def)
hoelzl@40859
  1653
qed
hoelzl@40859
  1654
hoelzl@40859
  1655
lemma sigma_sets_vimage:
hoelzl@40859
  1656
  assumes "f \<in> S' \<rightarrow> S" and "A \<subseteq> Pow S"
hoelzl@40859
  1657
  shows "sigma_sets S' ((\<lambda>X. f -` X \<inter> S') ` A) = (\<lambda>X. f -` X \<inter> S') ` sigma_sets S A"
hoelzl@40859
  1658
proof (intro set_eqI iffI)
hoelzl@40859
  1659
  let ?F = "\<lambda>X. f -` X \<inter> S'"
hoelzl@40859
  1660
  fix X assume "X \<in> sigma_sets S' (?F ` A)"
hoelzl@40859
  1661
  then show "X \<in> ?F ` sigma_sets S A"
hoelzl@40859
  1662
  proof induct
hoelzl@40859
  1663
    case (Basic X) then obtain X' where "X = ?F X'" "X' \<in> A"
hoelzl@40859
  1664
      by auto
hoelzl@47694
  1665
    then show ?case by auto
hoelzl@40859
  1666
  next
hoelzl@40859
  1667
    case Empty then show ?case
hoelzl@40859
  1668
      by (auto intro!: image_eqI[of _ _ "{}"] sigma_sets.Empty)
hoelzl@40859
  1669
  next
hoelzl@40859
  1670
    case (Compl X) then obtain X' where X: "X = ?F X'" and "X' \<in> sigma_sets S A"
hoelzl@40859
  1671
      by auto
hoelzl@40859
  1672
    then have "S - X' \<in> sigma_sets S A"
hoelzl@40859
  1673
      by (auto intro!: sigma_sets.Compl)
hoelzl@40859
  1674
    then show ?case
hoelzl@40859
  1675
      using X assms by (auto intro!: image_eqI[where x="S - X'"])
hoelzl@40859
  1676
  next
hoelzl@40859
  1677
    case (Union F)
hoelzl@40859
  1678
    then have "\<forall>i. \<exists>F'.  F' \<in> sigma_sets S A \<and> F i = f -` F' \<inter> S'"
hoelzl@40859
  1679
      by (auto simp: image_iff Bex_def)
hoelzl@40859
  1680
    from choice[OF this] obtain F' where
hoelzl@40859
  1681
      "\<And>i. F' i \<in> sigma_sets S A" and "\<And>i. F i = f -` F' i \<inter> S'"
hoelzl@40859
  1682
      by auto
hoelzl@40859
  1683
    then show ?case
hoelzl@40859
  1684
      by (auto intro!: sigma_sets.Union image_eqI[where x="\<Union>i. F' i"])
hoelzl@40859
  1685
  qed
hoelzl@40859
  1686
next
hoelzl@40859
  1687
  let ?F = "\<lambda>X. f -` X \<inter> S'"
hoelzl@40859
  1688
  fix X assume "X \<in> ?F ` sigma_sets S A"
hoelzl@40859
  1689
  then obtain X' where "X' \<in> sigma_sets S A" "X = ?F X'" by auto
hoelzl@40859
  1690
  then show "X \<in> sigma_sets S' (?F ` A)"
hoelzl@40859
  1691
  proof (induct arbitrary: X)
hoelzl@40859
  1692
    case Empty then show ?case by (auto intro: sigma_sets.Empty)
hoelzl@40859
  1693
  next
hoelzl@40859
  1694
    case (Compl X')
hoelzl@40859
  1695
    have "S' - (S' - X) \<in> sigma_sets S' (?F ` A)"
hoelzl@40859
  1696
      apply (rule sigma_sets.Compl)
hoelzl@40859
  1697
      using assms by (auto intro!: Compl.hyps simp: Compl.prems)
hoelzl@40859
  1698
    also have "S' - (S' - X) = X"
hoelzl@40859
  1699
      using assms Compl by auto
hoelzl@40859
  1700
    finally show ?case .
hoelzl@40859
  1701
  next
hoelzl@40859
  1702
    case (Union F)
hoelzl@40859
  1703
    have "(\<Union>i. f -` F i \<inter> S') \<in> sigma_sets S' (?F ` A)"
hoelzl@40859
  1704
      by (intro sigma_sets.Union Union.hyps) simp
hoelzl@40859
  1705
    also have "(\<Union>i. f -` F i \<inter> S') = X"
hoelzl@40859
  1706
      using assms Union by auto
hoelzl@40859
  1707
    finally show ?case .
hoelzl@47694
  1708
  qed auto
hoelzl@39092
  1709
qed
hoelzl@39092
  1710
hoelzl@38656
  1711
subsection {* A Two-Element Series *}
hoelzl@38656
  1712
hoelzl@38656
  1713
definition binaryset :: "'a set \<Rightarrow> 'a set \<Rightarrow> nat \<Rightarrow> 'a set "
wenzelm@50252
  1714
  where "binaryset A B = (\<lambda>x. {})(0 := A, Suc 0 := B)"
hoelzl@38656
  1715
hoelzl@38656
  1716
lemma range_binaryset_eq: "range(binaryset A B) = {A,B,{}}"
hoelzl@38656
  1717
  apply (simp add: binaryset_def)
nipkow@39302
  1718
  apply (rule set_eqI)
hoelzl@38656
  1719
  apply (auto simp add: image_iff)
hoelzl@38656
  1720
  done
hoelzl@38656
  1721
hoelzl@38656
  1722
lemma UN_binaryset_eq: "(\<Union>i. binaryset A B i) = A \<union> B"
haftmann@44106
  1723
  by (simp add: SUP_def range_binaryset_eq)
hoelzl@38656
  1724
hoelzl@38656
  1725
section {* Closed CDI *}
hoelzl@38656
  1726
hoelzl@47694
  1727
definition closed_cdi where
hoelzl@47694
  1728
  "closed_cdi \<Omega> M \<longleftrightarrow>
hoelzl@47694
  1729
   M \<subseteq> Pow \<Omega> &
hoelzl@47694
  1730
   (\<forall>s \<in> M. \<Omega> - s \<in> M) &
hoelzl@47694
  1731
   (\<forall>A. (range A \<subseteq> M) & (A 0 = {}) & (\<forall>n. A n \<subseteq> A (Suc n)) \<longrightarrow>
hoelzl@47694
  1732
        (\<Union>i. A i) \<in> M) &
hoelzl@47694
  1733
   (\<forall>A. (range A \<subseteq> M) & disjoint_family A \<longrightarrow> (\<Union>i::nat. A i) \<in> M)"
hoelzl@38656
  1734
hoelzl@38656
  1735
inductive_set
hoelzl@47694
  1736
  smallest_ccdi_sets :: "'a set \<Rightarrow> 'a set set \<Rightarrow> 'a set set"
hoelzl@47694
  1737
  for \<Omega> M
hoelzl@38656
  1738
  where
hoelzl@38656
  1739
    Basic [intro]:
hoelzl@47694
  1740
      "a \<in> M \<Longrightarrow> a \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1741
  | Compl [intro]:
hoelzl@47694
  1742
      "a \<in> smallest_ccdi_sets \<Omega> M \<Longrightarrow> \<Omega> - a \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1743
  | Inc:
hoelzl@47694
  1744
      "range A \<in> Pow(smallest_ccdi_sets \<Omega> M) \<Longrightarrow> A 0 = {} \<Longrightarrow> (\<And>n. A n \<subseteq> A (Suc n))
hoelzl@47694
  1745
       \<Longrightarrow> (\<Union>i. A i) \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1746
  | Disj:
hoelzl@47694
  1747
      "range A \<in> Pow(smallest_ccdi_sets \<Omega> M) \<Longrightarrow> disjoint_family A
hoelzl@47694
  1748
       \<Longrightarrow> (\<Union>i::nat. A i) \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1749
hoelzl@47694
  1750
lemma (in subset_class) smallest_closed_cdi1: "M \<subseteq> smallest_ccdi_sets \<Omega> M"
hoelzl@47694
  1751
  by auto
hoelzl@38656
  1752
hoelzl@47694
  1753
lemma (in subset_class) smallest_ccdi_sets: "smallest_ccdi_sets \<Omega> M \<subseteq> Pow \<Omega>"
hoelzl@38656
  1754
  apply (rule subsetI)
hoelzl@38656
  1755
  apply (erule smallest_ccdi_sets.induct)
hoelzl@38656
  1756
  apply (auto intro: range_subsetD dest: sets_into_space)
hoelzl@38656
  1757
  done
hoelzl@38656
  1758
hoelzl@47694
  1759
lemma (in subset_class) smallest_closed_cdi2: "closed_cdi \<Omega> (smallest_ccdi_sets \<Omega> M)"
hoelzl@47694
  1760
  apply (auto simp add: closed_cdi_def smallest_ccdi_sets)
hoelzl@38656
  1761
  apply (blast intro: smallest_ccdi_sets.Inc smallest_ccdi_sets.Disj) +
hoelzl@38656
  1762
  done
hoelzl@38656
  1763
hoelzl@47694
  1764
lemma closed_cdi_subset: "closed_cdi \<Omega> M \<Longrightarrow> M \<subseteq> Pow \<Omega>"
hoelzl@38656
  1765
  by (simp add: closed_cdi_def)
hoelzl@38656
  1766
hoelzl@47694
  1767
lemma closed_cdi_Compl: "closed_cdi \<Omega> M \<Longrightarrow> s \<in> M \<Longrightarrow> \<Omega> - s \<in> M"
hoelzl@38656
  1768
  by (simp add: closed_cdi_def)
hoelzl@38656
  1769
hoelzl@38656
  1770
lemma closed_cdi_Inc:
hoelzl@47694
  1771
  "closed_cdi \<Omega> M \<Longrightarrow> range A \<subseteq> M \<Longrightarrow> A 0 = {} \<Longrightarrow> (!!n. A n \<subseteq> A (Suc n)) \<Longrightarrow> (\<Union>i. A i) \<in> M"
hoelzl@38656
  1772
  by (simp add: closed_cdi_def)
hoelzl@38656
  1773
hoelzl@38656
  1774
lemma closed_cdi_Disj:
hoelzl@47694
  1775
  "closed_cdi \<Omega> M \<Longrightarrow> range A \<subseteq> M \<Longrightarrow> disjoint_family A \<Longrightarrow> (\<Union>i::nat. A i) \<in> M"
hoelzl@38656
  1776
  by (simp add: closed_cdi_def)
hoelzl@38656
  1777
hoelzl@38656
  1778
lemma closed_cdi_Un:
hoelzl@47694
  1779
  assumes cdi: "closed_cdi \<Omega> M" and empty: "{} \<in> M"
hoelzl@47694
  1780
      and A: "A \<in> M" and B: "B \<in> M"
hoelzl@38656
  1781
      and disj: "A \<inter> B = {}"
hoelzl@47694
  1782
    shows "A \<union> B \<in> M"
hoelzl@38656
  1783
proof -
hoelzl@47694
  1784
  have ra: "range (binaryset A B) \<subseteq> M"
hoelzl@38656
  1785
   by (simp add: range_binaryset_eq empty A B)
hoelzl@38656
  1786
 have di:  "disjoint_family (binaryset A B)" using disj
hoelzl@38656
  1787
   by (simp add: disjoint_family_on_def binaryset_def Int_commute)
hoelzl@38656
  1788
 from closed_cdi_Disj [OF cdi ra di]
hoelzl@38656
  1789
 show ?thesis
hoelzl@38656
  1790
   by (simp add: UN_binaryset_eq)
hoelzl@38656
  1791
qed
hoelzl@38656
  1792
hoelzl@38656
  1793
lemma (in algebra) smallest_ccdi_sets_Un:
hoelzl@47694
  1794
  assumes A: "A \<in> smallest_ccdi_sets \<Omega> M" and B: "B \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1795
      and disj: "A \<inter> B = {}"
hoelzl@47694
  1796
    shows "A \<union> B \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1797
proof -
hoelzl@47694
  1798
  have ra: "range (binaryset A B) \<in> Pow (smallest_ccdi_sets \<Omega> M)"
hoelzl@38656
  1799
    by (simp add: range_binaryset_eq  A B smallest_ccdi_sets.Basic)
hoelzl@38656
  1800
  have di:  "disjoint_family (binaryset A B)" using disj
hoelzl@38656
  1801
    by (simp add: disjoint_family_on_def binaryset_def Int_commute)
hoelzl@38656
  1802
  from Disj [OF ra di]
hoelzl@38656
  1803
  show ?thesis
hoelzl@38656
  1804
    by (simp add: UN_binaryset_eq)
hoelzl@38656
  1805
qed
hoelzl@38656
  1806
hoelzl@38656
  1807
lemma (in algebra) smallest_ccdi_sets_Int1:
hoelzl@47694
  1808
  assumes a: "a \<in> M"
hoelzl@47694
  1809
  shows "b \<in> smallest_ccdi_sets \<Omega> M \<Longrightarrow> a \<inter> b \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1810
proof (induct rule: smallest_ccdi_sets.induct)
hoelzl@38656
  1811
  case (Basic x)
hoelzl@38656
  1812
  thus ?case
hoelzl@38656
  1813
    by (metis a Int smallest_ccdi_sets.Basic)
hoelzl@38656
  1814
next
hoelzl@38656
  1815
  case (Compl x)
hoelzl@47694
  1816
  have "a \<inter> (\<Omega> - x) = \<Omega> - ((\<Omega> - a) \<union> (a \<inter> x))"
hoelzl@38656
  1817
    by blast
hoelzl@47694
  1818
  also have "... \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1819
    by (metis smallest_ccdi_sets.Compl a Compl(2) Diff_Int2 Diff_Int_distrib2
hoelzl@47694
  1820
           Diff_disjoint Int_Diff Int_empty_right smallest_ccdi_sets_Un
hoelzl@47694
  1821
           smallest_ccdi_sets.Basic smallest_ccdi_sets.Compl)
hoelzl@38656
  1822
  finally show ?case .
hoelzl@38656
  1823
next
hoelzl@38656
  1824
  case (Inc A)
hoelzl@38656
  1825
  have 1: "(\<Union>i. (\<lambda>i. a \<inter> A i) i) = a \<inter> (\<Union>i. A i)"
hoelzl@38656
  1826
    by blast
hoelzl@47694
  1827
  have "range (\<lambda>i. a \<inter> A i) \<in> Pow(smallest_ccdi_sets \<Omega> M)" using Inc
hoelzl@38656
  1828
    by blast
hoelzl@38656
  1829
  moreover have "(\<lambda>i. a \<inter> A i) 0 = {}"
hoelzl@38656
  1830
    by (simp add: Inc)
hoelzl@38656
  1831
  moreover have "!!n. (\<lambda>i. a \<inter> A i) n \<subseteq> (\<lambda>i. a \<inter> A i) (Suc n)" using Inc
hoelzl@38656
  1832
    by blast
hoelzl@47694
  1833
  ultimately have 2: "(\<Union>i. (\<lambda>i. a \<inter> A i) i) \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1834
    by (rule smallest_ccdi_sets.Inc)
hoelzl@38656
  1835
  show ?case
hoelzl@38656
  1836
    by (metis 1 2)
hoelzl@38656
  1837
next
hoelzl@38656
  1838
  case (Disj A)
hoelzl@38656
  1839
  have 1: "(\<Union>i. (\<lambda>i. a \<inter> A i) i) = a \<inter> (\<Union>i. A i)"
hoelzl@38656
  1840
    by blast
hoelzl@47694
  1841
  have "range (\<lambda>i. a \<inter> A i) \<in> Pow(smallest_ccdi_sets \<Omega> M)" using Disj
hoelzl@38656
  1842
    by blast
hoelzl@38656
  1843
  moreover have "disjoint_family (\<lambda>i. a \<inter> A i)" using Disj
hoelzl@38656
  1844
    by (auto simp add: disjoint_family_on_def)
hoelzl@47694
  1845
  ultimately have 2: "(\<Union>i. (\<lambda>i. a \<inter> A i) i) \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1846
    by (rule smallest_ccdi_sets.Disj)
hoelzl@38656
  1847
  show ?case
hoelzl@38656
  1848
    by (metis 1 2)
hoelzl@38656
  1849
qed
hoelzl@38656
  1850
hoelzl@38656
  1851
hoelzl@38656
  1852
lemma (in algebra) smallest_ccdi_sets_Int:
hoelzl@47694
  1853
  assumes b: "b \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@47694
  1854
  shows "a \<in> smallest_ccdi_sets \<Omega> M \<Longrightarrow> a \<inter> b \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1855
proof (induct rule: smallest_ccdi_sets.induct)
hoelzl@38656
  1856
  case (Basic x)
hoelzl@38656
  1857
  thus ?case
hoelzl@38656
  1858
    by (metis b smallest_ccdi_sets_Int1)
hoelzl@38656
  1859
next
hoelzl@38656
  1860
  case (Compl x)
hoelzl@47694
  1861
  have "(\<Omega> - x) \<inter> b = \<Omega> - (x \<inter> b \<union> (\<Omega> - b))"
hoelzl@38656
  1862
    by blast
hoelzl@47694
  1863
  also have "... \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1864
    by (metis Compl(2) Diff_disjoint Int_Diff Int_commute Int_empty_right b
hoelzl@38656
  1865
           smallest_ccdi_sets.Compl smallest_ccdi_sets_Un)
hoelzl@38656
  1866
  finally show ?case .
hoelzl@38656
  1867
next
hoelzl@38656
  1868
  case (Inc A)
hoelzl@38656
  1869
  have 1: "(\<Union>i. (\<lambda>i. A i \<inter> b) i) = (\<Union>i. A i) \<inter> b"
hoelzl@38656
  1870
    by blast
hoelzl@47694
  1871
  have "range (\<lambda>i. A i \<inter> b) \<in> Pow(smallest_ccdi_sets \<Omega> M)" using Inc
hoelzl@38656
  1872
    by blast
hoelzl@38656
  1873
  moreover have "(\<lambda>i. A i \<inter> b) 0 = {}"
hoelzl@38656
  1874
    by (simp add: Inc)
hoelzl@38656
  1875
  moreover have "!!n. (\<lambda>i. A i \<inter> b) n \<subseteq> (\<lambda>i. A i \<inter> b) (Suc n)" using Inc
hoelzl@38656
  1876
    by blast
hoelzl@47694
  1877
  ultimately have 2: "(\<Union>i. (\<lambda>i. A i \<inter> b) i) \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1878
    by (rule smallest_ccdi_sets.Inc)
hoelzl@38656
  1879
  show ?case
hoelzl@38656
  1880
    by (metis 1 2)
hoelzl@38656
  1881
next
hoelzl@38656
  1882
  case (Disj A)
hoelzl@38656
  1883
  have 1: "(\<Union>i. (\<lambda>i. A i \<inter> b) i) = (\<Union>i. A i) \<inter> b"
hoelzl@38656
  1884
    by blast
hoelzl@47694
  1885
  have "range (\<lambda>i. A i \<inter> b) \<in> Pow(smallest_ccdi_sets \<Omega> M)" using Disj
hoelzl@38656
  1886
    by blast
hoelzl@38656
  1887
  moreover have "disjoint_family (\<lambda>i. A i \<inter> b)" using Disj
hoelzl@38656
  1888
    by (auto simp add: disjoint_family_on_def)
hoelzl@47694
  1889
  ultimately have 2: "(\<Union>i. (\<lambda>i. A i \<inter> b) i) \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1890
    by (rule smallest_ccdi_sets.Disj)
hoelzl@38656
  1891
  show ?case
hoelzl@38656
  1892
    by (metis 1 2)
hoelzl@38656
  1893
qed
hoelzl@38656
  1894
hoelzl@38656
  1895
lemma (in algebra) sigma_property_disjoint_lemma:
hoelzl@47694
  1896
  assumes sbC: "M \<subseteq> C"
hoelzl@47694
  1897
      and ccdi: "closed_cdi \<Omega> C"
hoelzl@47694
  1898
  shows "sigma_sets \<Omega> M \<subseteq> C"
hoelzl@38656
  1899
proof -
hoelzl@47694
  1900
  have "smallest_ccdi_sets \<Omega> M \<in> {B . M \<subseteq> B \<and> sigma_algebra \<Omega> B}"
hoelzl@38656
  1901
    apply (auto simp add: sigma_algebra_disjoint_iff algebra_iff_Int
hoelzl@38656
  1902
            smallest_ccdi_sets_Int)
hoelzl@38656
  1903
    apply (metis Union_Pow_eq Union_upper subsetD smallest_ccdi_sets)
hoelzl@38656
  1904
    apply (blast intro: smallest_ccdi_sets.Disj)
hoelzl@38656
  1905
    done
hoelzl@47694
  1906
  hence "sigma_sets (\<Omega>) (M) \<subseteq> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1907
    by clarsimp
hoelzl@47694
  1908
       (drule sigma_algebra.sigma_sets_subset [where a="M"], auto)
hoelzl@38656
  1909
  also have "...  \<subseteq> C"
hoelzl@38656
  1910
    proof
hoelzl@38656
  1911
      fix x
hoelzl@47694
  1912
      assume x: "x \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1913
      thus "x \<in> C"
hoelzl@38656
  1914
        proof (induct rule: smallest_ccdi_sets.induct)
hoelzl@38656
  1915
          case (Basic x)
hoelzl@38656
  1916
          thus ?case
hoelzl@38656
  1917
            by (metis Basic subsetD sbC)
hoelzl@38656
  1918
        next
hoelzl@38656
  1919
          case (Compl x)
hoelzl@38656
  1920
          thus ?case
hoelzl@38656
  1921
            by (blast intro: closed_cdi_Compl [OF ccdi, simplified])
hoelzl@38656
  1922
        next
hoelzl@38656
  1923
          case (Inc A)
hoelzl@38656
  1924
          thus ?case
hoelzl@38656
  1925
               by (auto intro: closed_cdi_Inc [OF ccdi, simplified])
hoelzl@38656
  1926
        next
hoelzl@38656
  1927
          case (Disj A)
hoelzl@38656
  1928
          thus ?case
hoelzl@38656
  1929
               by (auto intro: closed_cdi_Disj [OF ccdi, simplified])
hoelzl@38656
  1930
        qed
hoelzl@38656
  1931
    qed
hoelzl@38656
  1932
  finally show ?thesis .
hoelzl@38656
  1933
qed
hoelzl@38656
  1934
hoelzl@38656
  1935
lemma (in algebra) sigma_property_disjoint:
hoelzl@47694
  1936
  assumes sbC: "M \<subseteq> C"
hoelzl@47694
  1937
      and compl: "!!s. s \<in> C \<inter> sigma_sets (\<Omega>) (M) \<Longrightarrow> \<Omega> - s \<in> C"
hoelzl@47694
  1938
      and inc: "!!A. range A \<subseteq> C \<inter> sigma_sets (\<Omega>) (M)
hoelzl@38656
  1939
                     \<Longrightarrow> A 0 = {} \<Longrightarrow> (!!n. A n \<subseteq> A (Suc n))
hoelzl@38656
  1940
                     \<Longrightarrow> (\<Union>i. A i) \<in> C"
hoelzl@47694
  1941
      and disj: "!!A. range A \<subseteq> C \<inter> sigma_sets (\<Omega>) (M)
hoelzl@38656
  1942
                      \<Longrightarrow> disjoint_family A \<Longrightarrow> (\<Union>i::nat. A i) \<in> C"
hoelzl@47694
  1943
  shows "sigma_sets (\<Omega>) (M) \<subseteq> C"
hoelzl@38656
  1944
proof -
hoelzl@47694
  1945
  have "sigma_sets (\<Omega>) (M) \<subseteq> C \<inter> sigma_sets (\<Omega>) (M)"
hoelzl@38656
  1946
    proof (rule sigma_property_disjoint_lemma)
hoelzl@47694
  1947
      show "M \<subseteq> C \<inter> sigma_sets (\<Omega>) (M)"
hoelzl@38656
  1948
        by (metis Int_greatest Set.subsetI sbC sigma_sets.Basic)
hoelzl@38656
  1949
    next
hoelzl@47694
  1950
      show "closed_cdi \<Omega> (C \<inter> sigma_sets (\<Omega>) (M))"
hoelzl@38656
  1951
        by (simp add: closed_cdi_def compl inc disj)
hoelzl@38656
  1952
           (metis PowI Set.subsetI le_infI2 sigma_sets_into_sp space_closed
hoelzl@38656
  1953
             IntE sigma_sets.Compl range_subsetD sigma_sets.Union)
hoelzl@38656
  1954
    qed
hoelzl@38656
  1955
  thus ?thesis
hoelzl@38656
  1956
    by blast
hoelzl@38656
  1957
qed
hoelzl@38656
  1958
hoelzl@50387
  1959
subsection {* Dynkin systems *}
hoelzl@40859
  1960
hoelzl@42065
  1961
locale dynkin_system = subset_class +
hoelzl@47694
  1962
  assumes space: "\<Omega> \<in> M"
hoelzl@47694
  1963
    and   compl[intro!]: "\<And>A. A \<in> M \<Longrightarrow> \<Omega> - A \<in> M"
hoelzl@47694
  1964
    and   UN[intro!]: "\<And>A. disjoint_family A \<Longrightarrow> range A \<subseteq> M
hoelzl@47694
  1965
                           \<Longrightarrow> (\<Union>i::nat. A i) \<in> M"
hoelzl@40859
  1966
hoelzl@47694
  1967
lemma (in dynkin_system) empty[intro, simp]: "{} \<in> M"
hoelzl@47694
  1968
  using space compl[of "\<Omega>"] by simp
hoelzl@40859
  1969
hoelzl@40859
  1970
lemma (in dynkin_system) diff:
hoelzl@47694
  1971
  assumes sets: "D \<in> M" "E \<in> M" and "D \<subseteq> E"
hoelzl@47694
  1972
  shows "E - D \<in> M"
hoelzl@40859
  1973
proof -
hoelzl@47694
  1974
  let ?f = "\<lambda>x. if x = 0 then D else if x = Suc 0 then \<Omega> - E else {}"
hoelzl@47694
  1975
  have "range ?f = {D, \<Omega> - E, {}}"
hoelzl@40859
  1976
    by (auto simp: image_iff)
hoelzl@47694
  1977
  moreover have "D \<union> (\<Omega> - E) = (\<Union>i. ?f i)"
hoelzl@40859
  1978
    by (auto simp: image_iff split: split_if_asm)
hoelzl@40859
  1979
  moreover
hoelzl@40859
  1980
  then have "disjoint_family ?f" unfolding disjoint_family_on_def
hoelzl@47694
  1981
    using `D \<in> M`[THEN sets_into_space] `D \<subseteq> E` by auto
hoelzl@47694
  1982
  ultimately have "\<Omega> - (D \<union> (\<Omega> - E)) \<in> M"
hoelzl@40859
  1983
    using sets by auto
hoelzl@47694
  1984
  also have "\<Omega> - (D \<union> (\<Omega> - E)) = E - D"
hoelzl@40859
  1985
    using assms sets_into_space by auto
hoelzl@40859
  1986
  finally show ?thesis .
hoelzl@40859
  1987
qed
hoelzl@40859
  1988
hoelzl@40859
  1989
lemma dynkin_systemI:
hoelzl@47694
  1990
  assumes "\<And> A. A \<in> M \<Longrightarrow> A \<subseteq> \<Omega>" "\<Omega> \<in> M"
hoelzl@47694
  1991
  assumes "\<And> A. A \<in> M \<Longrightarrow> \<Omega> - A \<in> M"
hoelzl@47694
  1992
  assumes "\<And> A. disjoint_family A \<Longrightarrow> range A \<subseteq> M
hoelzl@47694
  1993
          \<Longrightarrow> (\<Union>i::nat. A i) \<in> M"
hoelzl@47694
  1994
  shows "dynkin_system \<Omega> M"
hoelzl@42065
  1995
  using assms by (auto simp: dynkin_system_def dynkin_system_axioms_def subset_class_def)
hoelzl@40859
  1996
hoelzl@42988
  1997
lemma dynkin_systemI':
hoelzl@47694
  1998
  assumes 1: "\<And> A. A \<in> M \<Longrightarrow> A \<subseteq> \<Omega>"
hoelzl@47694
  1999
  assumes empty: "{} \<in> M"
hoelzl@47694
  2000
  assumes Diff: "\<And> A. A \<in> M \<Longrightarrow> \<Omega> - A \<in> M"
hoelzl@47694
  2001
  assumes 2: "\<And> A. disjoint_family A \<Longrightarrow> range A \<subseteq> M
hoelzl@47694
  2002
          \<Longrightarrow> (\<Union>i::nat. A i) \<in> M"
hoelzl@47694
  2003
  shows "dynkin_system \<Omega> M"
hoelzl@42988
  2004
proof -
hoelzl@47694
  2005
  from Diff[OF empty] have "\<Omega> \<in> M" by auto
hoelzl@42988
  2006
  from 1 this Diff 2 show ?thesis
hoelzl@42988
  2007
    by (intro dynkin_systemI) auto
hoelzl@42988
  2008
qed
hoelzl@42988
  2009
hoelzl@40859
  2010
lemma dynkin_system_trivial:
hoelzl@47694
  2011
  shows "dynkin_system A (Pow A)"
hoelzl@40859
  2012
  by (rule dynkin_systemI) auto
hoelzl@40859
  2013
hoelzl@40859
  2014
lemma sigma_algebra_imp_dynkin_system:
hoelzl@47694
  2015
  assumes "sigma_algebra \<Omega> M" shows "dynkin_system \<Omega> M"
hoelzl@40859
  2016
proof -
hoelzl@47694
  2017
  interpret sigma_algebra \<Omega> M by fact
nipkow@44890
  2018
  show ?thesis using sets_into_space by (fastforce intro!: dynkin_systemI)
hoelzl@40859
  2019
qed
hoelzl@40859
  2020
hoelzl@40859
  2021
subsection "Intersection stable algebras"
hoelzl@40859
  2022
hoelzl@47694
  2023
definition "Int_stable M \<longleftrightarrow> (\<forall> a \<in> M. \<forall> b \<in> M. a \<inter> b \<in> M)"
hoelzl@40859
  2024
hoelzl@40859
  2025
lemma (in algebra) Int_stable: "Int_stable M"
hoelzl@40859
  2026
  unfolding Int_stable_def by auto
hoelzl@40859
  2027
hoelzl@42981
  2028
lemma Int_stableI:
hoelzl@47694
  2029
  "(\<And>a b. a \<in> A \<Longrightarrow> b \<in> A \<Longrightarrow> a \<inter> b \<in> A) \<Longrightarrow> Int_stable A"
hoelzl@42981
  2030
  unfolding Int_stable_def by auto
hoelzl@42981
  2031
hoelzl@42981
  2032
lemma Int_stableD:
hoelzl@47694
  2033
  "Int_stable M \<Longrightarrow> a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> a \<inter> b \<in> M"
hoelzl@42981
  2034
  unfolding Int_stable_def by auto
hoelzl@42981
  2035
hoelzl@40859
  2036
lemma (in dynkin_system) sigma_algebra_eq_Int_stable:
hoelzl@47694
  2037
  "sigma_algebra \<Omega> M \<longleftrightarrow> Int_stable M"
hoelzl@40859
  2038
proof
hoelzl@47694
  2039
  assume "sigma_algebra \<Omega> M" then show "Int_stable M"
hoelzl@40859
  2040
    unfolding sigma_algebra_def using algebra.Int_stable by auto
hoelzl@40859
  2041
next
hoelzl@40859
  2042
  assume "Int_stable M"
hoelzl@47694
  2043
  show "sigma_algebra \<Omega> M"
hoelzl@42065
  2044
    unfolding sigma_algebra_disjoint_iff algebra_iff_Un
hoelzl@40859
  2045
  proof (intro conjI ballI allI impI)
hoelzl@47694
  2046
    show "M \<subseteq> Pow (\<Omega>)" using sets_into_space by auto
hoelzl@40859
  2047
  next