src/HOL/Probability/Sigma_Algebra.thy
author hoelzl
Fri Nov 02 14:23:40 2012 +0100 (2012-11-02)
changeset 50002 ce0d316b5b44
parent 49834 b27bbb021df1
child 50003 8c213922ed49
permissions -rw-r--r--
add measurability prover; add support for Borel sets
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
wenzelm@41413
    13
  "~~/src/HOL/Library/Countable"
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@39092
   255
section {* 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
hoelzl@38656
   301
lemma (in sigma_algebra) countable_UN[intro]:
hoelzl@38656
   302
  fixes A :: "'i::countable \<Rightarrow> 'a set"
hoelzl@47694
   303
  assumes "A`X \<subseteq> M"
hoelzl@47694
   304
  shows  "(\<Union>x\<in>X. A x) \<in> M"
hoelzl@38656
   305
proof -
wenzelm@46731
   306
  let ?A = "\<lambda>i. if i \<in> X then A i else {}"
hoelzl@47694
   307
  from assms have "range ?A \<subseteq> M" by auto
hoelzl@38656
   308
  with countable_nat_UN[of "?A \<circ> from_nat"] countable_UN_eq[of ?A M]
hoelzl@47694
   309
  have "(\<Union>x. ?A x) \<in> M" by auto
hoelzl@38656
   310
  moreover have "(\<Union>x. ?A x) = (\<Union>x\<in>X. A x)" by (auto split: split_if_asm)
hoelzl@38656
   311
  ultimately show ?thesis by simp
hoelzl@38656
   312
qed
hoelzl@38656
   313
paulson@33533
   314
lemma (in sigma_algebra) countable_INT [intro]:
hoelzl@38656
   315
  fixes A :: "'i::countable \<Rightarrow> 'a set"
hoelzl@47694
   316
  assumes A: "A`X \<subseteq> M" "X \<noteq> {}"
hoelzl@47694
   317
  shows "(\<Inter>i\<in>X. A i) \<in> M"
paulson@33271
   318
proof -
hoelzl@47694
   319
  from A have "\<forall>i\<in>X. A i \<in> M" by fast
hoelzl@47694
   320
  hence "\<Omega> - (\<Union>i\<in>X. \<Omega> - A i) \<in> M" by blast
paulson@33271
   321
  moreover
hoelzl@47694
   322
  have "(\<Inter>i\<in>X. A i) = \<Omega> - (\<Union>i\<in>X. \<Omega> - A i)" using space_closed A
paulson@33271
   323
    by blast
paulson@33271
   324
  ultimately show ?thesis by metis
paulson@33271
   325
qed
paulson@33271
   326
hoelzl@47694
   327
lemma ring_of_sets_Pow: "ring_of_sets sp (Pow sp)"
hoelzl@47762
   328
  by (auto simp: ring_of_sets_iff)
hoelzl@42145
   329
hoelzl@47694
   330
lemma algebra_Pow: "algebra sp (Pow sp)"
hoelzl@47762
   331
  by (auto simp: algebra_iff_Un)
hoelzl@38656
   332
hoelzl@38656
   333
lemma sigma_algebra_iff:
hoelzl@47694
   334
  "sigma_algebra \<Omega> M \<longleftrightarrow>
hoelzl@47694
   335
    algebra \<Omega> M \<and> (\<forall>A. range A \<subseteq> M \<longrightarrow> (\<Union>i::nat. A i) \<in> M)"
hoelzl@38656
   336
  by (simp add: sigma_algebra_def sigma_algebra_axioms_def)
paulson@33271
   337
hoelzl@47762
   338
lemma sigma_algebra_Pow: "sigma_algebra sp (Pow sp)"
hoelzl@47762
   339
  by (auto simp: sigma_algebra_iff algebra_iff_Int)
hoelzl@47762
   340
hoelzl@42867
   341
lemma (in sigma_algebra) sets_Collect_countable_All:
hoelzl@47694
   342
  assumes "\<And>i. {x\<in>\<Omega>. P i x} \<in> M"
hoelzl@47694
   343
  shows "{x\<in>\<Omega>. \<forall>i::'i::countable. P i x} \<in> M"
hoelzl@42867
   344
proof -
hoelzl@47694
   345
  have "{x\<in>\<Omega>. \<forall>i::'i::countable. P i x} = (\<Inter>i. {x\<in>\<Omega>. P i x})" by auto
hoelzl@42867
   346
  with assms show ?thesis by auto
hoelzl@42867
   347
qed
hoelzl@42867
   348
hoelzl@42867
   349
lemma (in sigma_algebra) sets_Collect_countable_Ex:
hoelzl@47694
   350
  assumes "\<And>i. {x\<in>\<Omega>. P i x} \<in> M"
hoelzl@47694
   351
  shows "{x\<in>\<Omega>. \<exists>i::'i::countable. P i x} \<in> M"
hoelzl@42867
   352
proof -
hoelzl@47694
   353
  have "{x\<in>\<Omega>. \<exists>i::'i::countable. P i x} = (\<Union>i. {x\<in>\<Omega>. P i x})" by auto
hoelzl@42867
   354
  with assms show ?thesis by auto
hoelzl@42867
   355
qed
hoelzl@42867
   356
hoelzl@42867
   357
lemmas (in sigma_algebra) sets_Collect =
hoelzl@42867
   358
  sets_Collect_imp sets_Collect_disj sets_Collect_conj sets_Collect_neg sets_Collect_const
hoelzl@42867
   359
  sets_Collect_countable_All sets_Collect_countable_Ex sets_Collect_countable_All
hoelzl@42867
   360
hoelzl@47694
   361
lemma (in sigma_algebra) sets_Collect_countable_Ball:
hoelzl@47694
   362
  assumes "\<And>i. {x\<in>\<Omega>. P i x} \<in> M"
hoelzl@47694
   363
  shows "{x\<in>\<Omega>. \<forall>i::'i::countable\<in>X. P i x} \<in> M"
hoelzl@47694
   364
  unfolding Ball_def by (intro sets_Collect assms)
hoelzl@47694
   365
hoelzl@47694
   366
lemma (in sigma_algebra) sets_Collect_countable_Bex:
hoelzl@47694
   367
  assumes "\<And>i. {x\<in>\<Omega>. P i x} \<in> M"
hoelzl@47694
   368
  shows "{x\<in>\<Omega>. \<exists>i::'i::countable\<in>X. P i x} \<in> M"
hoelzl@47694
   369
  unfolding Bex_def by (intro sets_Collect assms)
hoelzl@47694
   370
hoelzl@42984
   371
lemma sigma_algebra_single_set:
hoelzl@42984
   372
  assumes "X \<subseteq> S"
hoelzl@47694
   373
  shows "sigma_algebra S { {}, X, S - X, S }"
hoelzl@42984
   374
  using algebra.is_sigma_algebra[OF algebra_single_set[OF `X \<subseteq> S`]] by simp
hoelzl@42984
   375
paulson@33271
   376
subsection {* Binary Unions *}
paulson@33271
   377
paulson@33271
   378
definition binary :: "'a \<Rightarrow> 'a \<Rightarrow> nat \<Rightarrow> 'a"
paulson@33271
   379
  where "binary a b =  (\<lambda>\<^isup>x. b)(0 := a)"
paulson@33271
   380
hoelzl@38656
   381
lemma range_binary_eq: "range(binary a b) = {a,b}"
hoelzl@38656
   382
  by (auto simp add: binary_def)
paulson@33271
   383
hoelzl@38656
   384
lemma Un_range_binary: "a \<union> b = (\<Union>i::nat. binary a b i)"
haftmann@44106
   385
  by (simp add: SUP_def range_binary_eq)
paulson@33271
   386
hoelzl@38656
   387
lemma Int_range_binary: "a \<inter> b = (\<Inter>i::nat. binary a b i)"
haftmann@44106
   388
  by (simp add: INF_def range_binary_eq)
paulson@33271
   389
paulson@33271
   390
lemma sigma_algebra_iff2:
hoelzl@47694
   391
     "sigma_algebra \<Omega> M \<longleftrightarrow>
hoelzl@47694
   392
       M \<subseteq> Pow \<Omega> \<and>
hoelzl@47694
   393
       {} \<in> M \<and> (\<forall>s \<in> M. \<Omega> - s \<in> M) \<and>
hoelzl@47694
   394
       (\<forall>A. range A \<subseteq> M \<longrightarrow> (\<Union>i::nat. A i) \<in> M)"
hoelzl@38656
   395
  by (auto simp add: range_binary_eq sigma_algebra_def sigma_algebra_axioms_def
hoelzl@42065
   396
         algebra_iff_Un Un_range_binary)
paulson@33271
   397
paulson@33271
   398
subsection {* Initial Sigma Algebra *}
paulson@33271
   399
paulson@33271
   400
text {*Sigma algebras can naturally be created as the closure of any set of
hoelzl@47694
   401
  M with regard to the properties just postulated.  *}
paulson@33271
   402
paulson@33271
   403
inductive_set
paulson@33271
   404
  sigma_sets :: "'a set \<Rightarrow> 'a set set \<Rightarrow> 'a set set"
paulson@33271
   405
  for sp :: "'a set" and A :: "'a set set"
paulson@33271
   406
  where
hoelzl@47694
   407
    Basic[intro, simp]: "a \<in> A \<Longrightarrow> a \<in> sigma_sets sp A"
paulson@33271
   408
  | Empty: "{} \<in> sigma_sets sp A"
paulson@33271
   409
  | Compl: "a \<in> sigma_sets sp A \<Longrightarrow> sp - a \<in> sigma_sets sp A"
paulson@33271
   410
  | Union: "(\<And>i::nat. a i \<in> sigma_sets sp A) \<Longrightarrow> (\<Union>i. a i) \<in> sigma_sets sp A"
paulson@33271
   411
hoelzl@41543
   412
lemma (in sigma_algebra) sigma_sets_subset:
hoelzl@47694
   413
  assumes a: "a \<subseteq> M"
hoelzl@47694
   414
  shows "sigma_sets \<Omega> a \<subseteq> M"
hoelzl@41543
   415
proof
hoelzl@41543
   416
  fix x
hoelzl@47694
   417
  assume "x \<in> sigma_sets \<Omega> a"
hoelzl@47694
   418
  from this show "x \<in> M"
hoelzl@41543
   419
    by (induct rule: sigma_sets.induct, auto) (metis a subsetD)
hoelzl@41543
   420
qed
hoelzl@41543
   421
hoelzl@41543
   422
lemma sigma_sets_into_sp: "A \<subseteq> Pow sp \<Longrightarrow> x \<in> sigma_sets sp A \<Longrightarrow> x \<subseteq> sp"
hoelzl@41543
   423
  by (erule sigma_sets.induct, auto)
hoelzl@41543
   424
hoelzl@41543
   425
lemma sigma_algebra_sigma_sets:
hoelzl@47694
   426
     "a \<subseteq> Pow \<Omega> \<Longrightarrow> sigma_algebra \<Omega> (sigma_sets \<Omega> a)"
hoelzl@41543
   427
  by (auto simp add: sigma_algebra_iff2 dest: sigma_sets_into_sp
hoelzl@41543
   428
           intro!: sigma_sets.Union sigma_sets.Empty sigma_sets.Compl)
hoelzl@41543
   429
hoelzl@41543
   430
lemma sigma_sets_least_sigma_algebra:
hoelzl@41543
   431
  assumes "A \<subseteq> Pow S"
hoelzl@47694
   432
  shows "sigma_sets S A = \<Inter>{B. A \<subseteq> B \<and> sigma_algebra S B}"
hoelzl@41543
   433
proof safe
hoelzl@47694
   434
  fix B X assume "A \<subseteq> B" and sa: "sigma_algebra S B"
hoelzl@41543
   435
    and X: "X \<in> sigma_sets S A"
hoelzl@41543
   436
  from sigma_algebra.sigma_sets_subset[OF sa, simplified, OF `A \<subseteq> B`] X
hoelzl@41543
   437
  show "X \<in> B" by auto
hoelzl@41543
   438
next
hoelzl@47694
   439
  fix X assume "X \<in> \<Inter>{B. A \<subseteq> B \<and> sigma_algebra S B}"
hoelzl@47694
   440
  then have [intro!]: "\<And>B. A \<subseteq> B \<Longrightarrow> sigma_algebra S B \<Longrightarrow> X \<in> B"
hoelzl@41543
   441
     by simp
hoelzl@47694
   442
  have "A \<subseteq> sigma_sets S A" using assms by auto
hoelzl@47694
   443
  moreover have "sigma_algebra S (sigma_sets S A)"
hoelzl@41543
   444
    using assms by (intro sigma_algebra_sigma_sets[of A]) auto
hoelzl@41543
   445
  ultimately show "X \<in> sigma_sets S A" by auto
hoelzl@41543
   446
qed
paulson@33271
   447
paulson@33271
   448
lemma sigma_sets_top: "sp \<in> sigma_sets sp A"
paulson@33271
   449
  by (metis Diff_empty sigma_sets.Compl sigma_sets.Empty)
paulson@33271
   450
hoelzl@38656
   451
lemma sigma_sets_Un:
paulson@33271
   452
  "a \<in> sigma_sets sp A \<Longrightarrow> b \<in> sigma_sets sp A \<Longrightarrow> a \<union> b \<in> sigma_sets sp A"
hoelzl@38656
   453
apply (simp add: Un_range_binary range_binary_eq)
hoelzl@40859
   454
apply (rule Union, simp add: binary_def)
paulson@33271
   455
done
paulson@33271
   456
paulson@33271
   457
lemma sigma_sets_Inter:
paulson@33271
   458
  assumes Asb: "A \<subseteq> Pow sp"
paulson@33271
   459
  shows "(\<And>i::nat. a i \<in> sigma_sets sp A) \<Longrightarrow> (\<Inter>i. a i) \<in> sigma_sets sp A"
paulson@33271
   460
proof -
paulson@33271
   461
  assume ai: "\<And>i::nat. a i \<in> sigma_sets sp A"
hoelzl@38656
   462
  hence "\<And>i::nat. sp-(a i) \<in> sigma_sets sp A"
paulson@33271
   463
    by (rule sigma_sets.Compl)
hoelzl@38656
   464
  hence "(\<Union>i. sp-(a i)) \<in> sigma_sets sp A"
paulson@33271
   465
    by (rule sigma_sets.Union)
hoelzl@38656
   466
  hence "sp-(\<Union>i. sp-(a i)) \<in> sigma_sets sp A"
paulson@33271
   467
    by (rule sigma_sets.Compl)
hoelzl@38656
   468
  also have "sp-(\<Union>i. sp-(a i)) = sp Int (\<Inter>i. a i)"
paulson@33271
   469
    by auto
paulson@33271
   470
  also have "... = (\<Inter>i. a i)" using ai
hoelzl@38656
   471
    by (blast dest: sigma_sets_into_sp [OF Asb])
hoelzl@38656
   472
  finally show ?thesis .
paulson@33271
   473
qed
paulson@33271
   474
paulson@33271
   475
lemma sigma_sets_INTER:
hoelzl@38656
   476
  assumes Asb: "A \<subseteq> Pow sp"
paulson@33271
   477
      and ai: "\<And>i::nat. i \<in> S \<Longrightarrow> a i \<in> sigma_sets sp A" and non: "S \<noteq> {}"
paulson@33271
   478
  shows "(\<Inter>i\<in>S. a i) \<in> sigma_sets sp A"
paulson@33271
   479
proof -
paulson@33271
   480
  from ai have "\<And>i. (if i\<in>S then a i else sp) \<in> sigma_sets sp A"
hoelzl@47694
   481
    by (simp add: sigma_sets.intros(2-) sigma_sets_top)
paulson@33271
   482
  hence "(\<Inter>i. (if i\<in>S then a i else sp)) \<in> sigma_sets sp A"
paulson@33271
   483
    by (rule sigma_sets_Inter [OF Asb])
paulson@33271
   484
  also have "(\<Inter>i. (if i\<in>S then a i else sp)) = (\<Inter>i\<in>S. a i)"
paulson@33271
   485
    by auto (metis ai non sigma_sets_into_sp subset_empty subset_iff Asb)+
paulson@33271
   486
  finally show ?thesis .
paulson@33271
   487
qed
paulson@33271
   488
paulson@33271
   489
lemma (in sigma_algebra) sigma_sets_eq:
hoelzl@47694
   490
     "sigma_sets \<Omega> M = M"
paulson@33271
   491
proof
hoelzl@47694
   492
  show "M \<subseteq> sigma_sets \<Omega> M"
huffman@37032
   493
    by (metis Set.subsetI sigma_sets.Basic)
paulson@33271
   494
  next
hoelzl@47694
   495
  show "sigma_sets \<Omega> M \<subseteq> M"
paulson@33271
   496
    by (metis sigma_sets_subset subset_refl)
paulson@33271
   497
qed
paulson@33271
   498
hoelzl@42981
   499
lemma sigma_sets_eqI:
hoelzl@42981
   500
  assumes A: "\<And>a. a \<in> A \<Longrightarrow> a \<in> sigma_sets M B"
hoelzl@42981
   501
  assumes B: "\<And>b. b \<in> B \<Longrightarrow> b \<in> sigma_sets M A"
hoelzl@42981
   502
  shows "sigma_sets M A = sigma_sets M B"
hoelzl@42981
   503
proof (intro set_eqI iffI)
hoelzl@42981
   504
  fix a assume "a \<in> sigma_sets M A"
hoelzl@42981
   505
  from this A show "a \<in> sigma_sets M B"
hoelzl@47694
   506
    by induct (auto intro!: sigma_sets.intros(2-) del: sigma_sets.Basic)
hoelzl@42981
   507
next
hoelzl@42981
   508
  fix b assume "b \<in> sigma_sets M B"
hoelzl@42981
   509
  from this B show "b \<in> sigma_sets M A"
hoelzl@47694
   510
    by induct (auto intro!: sigma_sets.intros(2-) del: sigma_sets.Basic)
hoelzl@42981
   511
qed
hoelzl@42981
   512
hoelzl@42984
   513
lemma sigma_sets_subseteq: assumes "A \<subseteq> B" shows "sigma_sets X A \<subseteq> sigma_sets X B"
hoelzl@42984
   514
proof
hoelzl@42984
   515
  fix x assume "x \<in> sigma_sets X A" then show "x \<in> sigma_sets X B"
hoelzl@47694
   516
    by induct (insert `A \<subseteq> B`, auto intro: sigma_sets.intros(2-))
hoelzl@42984
   517
qed
hoelzl@42984
   518
hoelzl@47762
   519
lemma sigma_sets_mono: assumes "A \<subseteq> sigma_sets X B" shows "sigma_sets X A \<subseteq> sigma_sets X B"
hoelzl@47762
   520
proof
hoelzl@47762
   521
  fix x assume "x \<in> sigma_sets X A" then show "x \<in> sigma_sets X B"
hoelzl@47762
   522
    by induct (insert `A \<subseteq> sigma_sets X B`, auto intro: sigma_sets.intros(2-))
hoelzl@47762
   523
qed
hoelzl@47762
   524
hoelzl@47762
   525
lemma sigma_sets_mono': assumes "A \<subseteq> B" shows "sigma_sets X A \<subseteq> sigma_sets X B"
hoelzl@47762
   526
proof
hoelzl@47762
   527
  fix x assume "x \<in> sigma_sets X A" then show "x \<in> sigma_sets X B"
hoelzl@47762
   528
    by induct (insert `A \<subseteq> B`, auto intro: sigma_sets.intros(2-))
hoelzl@47762
   529
qed
hoelzl@47762
   530
hoelzl@47762
   531
lemma sigma_sets_superset_generator: "A \<subseteq> sigma_sets X A"
hoelzl@47762
   532
  by (auto intro: sigma_sets.Basic)
hoelzl@47762
   533
hoelzl@38656
   534
lemma (in sigma_algebra) restriction_in_sets:
hoelzl@38656
   535
  fixes A :: "nat \<Rightarrow> 'a set"
hoelzl@47694
   536
  assumes "S \<in> M"
hoelzl@47694
   537
  and *: "range A \<subseteq> (\<lambda>A. S \<inter> A) ` M" (is "_ \<subseteq> ?r")
hoelzl@47694
   538
  shows "range A \<subseteq> M" "(\<Union>i. A i) \<in> (\<lambda>A. S \<inter> A) ` M"
hoelzl@38656
   539
proof -
hoelzl@38656
   540
  { fix i have "A i \<in> ?r" using * by auto
hoelzl@47694
   541
    hence "\<exists>B. A i = B \<inter> S \<and> B \<in> M" by auto
hoelzl@47694
   542
    hence "A i \<subseteq> S" "A i \<in> M" using `S \<in> M` by auto }
hoelzl@47694
   543
  thus "range A \<subseteq> M" "(\<Union>i. A i) \<in> (\<lambda>A. S \<inter> A) ` M"
hoelzl@38656
   544
    by (auto intro!: image_eqI[of _ _ "(\<Union>i. A i)"])
hoelzl@38656
   545
qed
hoelzl@38656
   546
hoelzl@38656
   547
lemma (in sigma_algebra) restricted_sigma_algebra:
hoelzl@47694
   548
  assumes "S \<in> M"
hoelzl@47694
   549
  shows "sigma_algebra S (restricted_space S)"
hoelzl@38656
   550
  unfolding sigma_algebra_def sigma_algebra_axioms_def
hoelzl@38656
   551
proof safe
hoelzl@47694
   552
  show "algebra S (restricted_space S)" using restricted_algebra[OF assms] .
hoelzl@38656
   553
next
hoelzl@47694
   554
  fix A :: "nat \<Rightarrow> 'a set" assume "range A \<subseteq> restricted_space S"
hoelzl@38656
   555
  from restriction_in_sets[OF assms this[simplified]]
hoelzl@47694
   556
  show "(\<Union>i. A i) \<in> restricted_space S" by simp
hoelzl@38656
   557
qed
hoelzl@38656
   558
hoelzl@40859
   559
lemma sigma_sets_Int:
hoelzl@41689
   560
  assumes "A \<in> sigma_sets sp st" "A \<subseteq> sp"
hoelzl@41689
   561
  shows "op \<inter> A ` sigma_sets sp st = sigma_sets A (op \<inter> A ` st)"
hoelzl@40859
   562
proof (intro equalityI subsetI)
hoelzl@40859
   563
  fix x assume "x \<in> op \<inter> A ` sigma_sets sp st"
hoelzl@40859
   564
  then obtain y where "y \<in> sigma_sets sp st" "x = y \<inter> A" by auto
hoelzl@41689
   565
  then have "x \<in> sigma_sets (A \<inter> sp) (op \<inter> A ` st)"
hoelzl@40859
   566
  proof (induct arbitrary: x)
hoelzl@40859
   567
    case (Compl a)
hoelzl@40859
   568
    then show ?case
hoelzl@40859
   569
      by (force intro!: sigma_sets.Compl simp: Diff_Int_distrib ac_simps)
hoelzl@40859
   570
  next
hoelzl@40859
   571
    case (Union a)
hoelzl@40859
   572
    then show ?case
hoelzl@40859
   573
      by (auto intro!: sigma_sets.Union
hoelzl@40859
   574
               simp add: UN_extend_simps simp del: UN_simps)
hoelzl@47694
   575
  qed (auto intro!: sigma_sets.intros(2-))
hoelzl@41689
   576
  then show "x \<in> sigma_sets A (op \<inter> A ` st)"
hoelzl@41689
   577
    using `A \<subseteq> sp` by (simp add: Int_absorb2)
hoelzl@40859
   578
next
hoelzl@41689
   579
  fix x assume "x \<in> sigma_sets A (op \<inter> A ` st)"
hoelzl@40859
   580
  then show "x \<in> op \<inter> A ` sigma_sets sp st"
hoelzl@40859
   581
  proof induct
hoelzl@40859
   582
    case (Compl a)
hoelzl@40859
   583
    then obtain x where "a = A \<inter> x" "x \<in> sigma_sets sp st" by auto
hoelzl@41689
   584
    then show ?case using `A \<subseteq> sp`
hoelzl@40859
   585
      by (force simp add: image_iff intro!: bexI[of _ "sp - x"] sigma_sets.Compl)
hoelzl@40859
   586
  next
hoelzl@40859
   587
    case (Union a)
hoelzl@40859
   588
    then have "\<forall>i. \<exists>x. x \<in> sigma_sets sp st \<and> a i = A \<inter> x"
hoelzl@40859
   589
      by (auto simp: image_iff Bex_def)
hoelzl@40859
   590
    from choice[OF this] guess f ..
hoelzl@40859
   591
    then show ?case
hoelzl@40859
   592
      by (auto intro!: bexI[of _ "(\<Union>x. f x)"] sigma_sets.Union
hoelzl@40859
   593
               simp add: image_iff)
hoelzl@47694
   594
  qed (auto intro!: sigma_sets.intros(2-))
hoelzl@40859
   595
qed
hoelzl@40859
   596
hoelzl@47694
   597
lemma sigma_sets_empty_eq: "sigma_sets A {} = {{}, A}"
hoelzl@40859
   598
proof (intro set_eqI iffI)
hoelzl@47694
   599
  fix a assume "a \<in> sigma_sets A {}" then show "a \<in> {{}, A}"
hoelzl@47694
   600
    by induct blast+
hoelzl@47694
   601
qed (auto intro: sigma_sets.Empty sigma_sets_top)
hoelzl@47694
   602
hoelzl@47694
   603
lemma sigma_sets_single[simp]: "sigma_sets A {A} = {{}, A}"
hoelzl@47694
   604
proof (intro set_eqI iffI)
hoelzl@47694
   605
  fix x assume "x \<in> sigma_sets A {A}"
hoelzl@47694
   606
  then show "x \<in> {{}, A}"
hoelzl@47694
   607
    by induct blast+
hoelzl@40859
   608
next
hoelzl@47694
   609
  fix x assume "x \<in> {{}, A}"
hoelzl@47694
   610
  then show "x \<in> sigma_sets A {A}"
hoelzl@40859
   611
    by (auto intro: sigma_sets.Empty sigma_sets_top)
hoelzl@40859
   612
qed
hoelzl@40859
   613
hoelzl@42987
   614
lemma sigma_sets_sigma_sets_eq:
hoelzl@42987
   615
  "M \<subseteq> Pow S \<Longrightarrow> sigma_sets S (sigma_sets S M) = sigma_sets S M"
hoelzl@47694
   616
  by (rule sigma_algebra.sigma_sets_eq[OF sigma_algebra_sigma_sets, of M S]) auto
hoelzl@42987
   617
hoelzl@42984
   618
lemma sigma_sets_singleton:
hoelzl@42984
   619
  assumes "X \<subseteq> S"
hoelzl@42984
   620
  shows "sigma_sets S { X } = { {}, X, S - X, S }"
hoelzl@42984
   621
proof -
hoelzl@47694
   622
  interpret sigma_algebra S "{ {}, X, S - X, S }"
hoelzl@42984
   623
    by (rule sigma_algebra_single_set) fact
hoelzl@42984
   624
  have "sigma_sets S { X } \<subseteq> sigma_sets S { {}, X, S - X, S }"
hoelzl@42984
   625
    by (rule sigma_sets_subseteq) simp
hoelzl@42984
   626
  moreover have "\<dots> = { {}, X, S - X, S }"
hoelzl@47694
   627
    using sigma_sets_eq by simp
hoelzl@42984
   628
  moreover
hoelzl@42984
   629
  { fix A assume "A \<in> { {}, X, S - X, S }"
hoelzl@42984
   630
    then have "A \<in> sigma_sets S { X }"
hoelzl@47694
   631
      by (auto intro: sigma_sets.intros(2-) sigma_sets_top) }
hoelzl@42984
   632
  ultimately have "sigma_sets S { X } = sigma_sets S { {}, X, S - X, S }"
hoelzl@42984
   633
    by (intro antisym) auto
hoelzl@47694
   634
  with sigma_sets_eq show ?thesis by simp
hoelzl@42984
   635
qed
hoelzl@42984
   636
hoelzl@42863
   637
lemma restricted_sigma:
hoelzl@47694
   638
  assumes S: "S \<in> sigma_sets \<Omega> M" and M: "M \<subseteq> Pow \<Omega>"
hoelzl@47694
   639
  shows "algebra.restricted_space (sigma_sets \<Omega> M) S =
hoelzl@47694
   640
    sigma_sets S (algebra.restricted_space M S)"
hoelzl@42863
   641
proof -
hoelzl@42863
   642
  from S sigma_sets_into_sp[OF M]
hoelzl@47694
   643
  have "S \<in> sigma_sets \<Omega> M" "S \<subseteq> \<Omega>" by auto
hoelzl@42863
   644
  from sigma_sets_Int[OF this]
hoelzl@47694
   645
  show ?thesis by simp
hoelzl@42863
   646
qed
hoelzl@42863
   647
hoelzl@42987
   648
lemma sigma_sets_vimage_commute:
hoelzl@47694
   649
  assumes X: "X \<in> \<Omega> \<rightarrow> \<Omega>'"
hoelzl@47694
   650
  shows "{X -` A \<inter> \<Omega> |A. A \<in> sigma_sets \<Omega>' M'}
hoelzl@47694
   651
       = sigma_sets \<Omega> {X -` A \<inter> \<Omega> |A. A \<in> M'}" (is "?L = ?R")
hoelzl@42987
   652
proof
hoelzl@42987
   653
  show "?L \<subseteq> ?R"
hoelzl@42987
   654
  proof clarify
hoelzl@47694
   655
    fix A assume "A \<in> sigma_sets \<Omega>' M'"
hoelzl@47694
   656
    then show "X -` A \<inter> \<Omega> \<in> ?R"
hoelzl@42987
   657
    proof induct
hoelzl@42987
   658
      case Empty then show ?case
hoelzl@42987
   659
        by (auto intro!: sigma_sets.Empty)
hoelzl@42987
   660
    next
hoelzl@42987
   661
      case (Compl B)
hoelzl@47694
   662
      have [simp]: "X -` (\<Omega>' - B) \<inter> \<Omega> = \<Omega> - (X -` B \<inter> \<Omega>)"
hoelzl@42987
   663
        by (auto simp add: funcset_mem [OF X])
hoelzl@42987
   664
      with Compl show ?case
hoelzl@42987
   665
        by (auto intro!: sigma_sets.Compl)
hoelzl@42987
   666
    next
hoelzl@42987
   667
      case (Union F)
hoelzl@42987
   668
      then show ?case
hoelzl@42987
   669
        by (auto simp add: vimage_UN UN_extend_simps(4) simp del: UN_simps
hoelzl@42987
   670
                 intro!: sigma_sets.Union)
hoelzl@47694
   671
    qed auto
hoelzl@42987
   672
  qed
hoelzl@42987
   673
  show "?R \<subseteq> ?L"
hoelzl@42987
   674
  proof clarify
hoelzl@42987
   675
    fix A assume "A \<in> ?R"
hoelzl@47694
   676
    then show "\<exists>B. A = X -` B \<inter> \<Omega> \<and> B \<in> sigma_sets \<Omega>' M'"
hoelzl@42987
   677
    proof induct
hoelzl@42987
   678
      case (Basic B) then show ?case by auto
hoelzl@42987
   679
    next
hoelzl@42987
   680
      case Empty then show ?case
hoelzl@47694
   681
        by (auto intro!: sigma_sets.Empty exI[of _ "{}"])
hoelzl@42987
   682
    next
hoelzl@42987
   683
      case (Compl B)
hoelzl@47694
   684
      then obtain A where A: "B = X -` A \<inter> \<Omega>" "A \<in> sigma_sets \<Omega>' M'" by auto
hoelzl@47694
   685
      then have [simp]: "\<Omega> - B = X -` (\<Omega>' - A) \<inter> \<Omega>"
hoelzl@42987
   686
        by (auto simp add: funcset_mem [OF X])
hoelzl@42987
   687
      with A(2) show ?case
hoelzl@47694
   688
        by (auto intro: sigma_sets.Compl)
hoelzl@42987
   689
    next
hoelzl@42987
   690
      case (Union F)
hoelzl@47694
   691
      then have "\<forall>i. \<exists>B. F i = X -` B \<inter> \<Omega> \<and> B \<in> sigma_sets \<Omega>' M'" by auto
hoelzl@42987
   692
      from choice[OF this] guess A .. note A = this
hoelzl@42987
   693
      with A show ?case
hoelzl@47694
   694
        by (auto simp: vimage_UN[symmetric] intro: sigma_sets.Union)
hoelzl@42987
   695
    qed
hoelzl@42987
   696
  qed
hoelzl@42987
   697
qed
hoelzl@42987
   698
hoelzl@38656
   699
section "Disjoint families"
hoelzl@38656
   700
hoelzl@38656
   701
definition
hoelzl@38656
   702
  disjoint_family_on  where
hoelzl@38656
   703
  "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
   704
hoelzl@38656
   705
abbreviation
hoelzl@38656
   706
  "disjoint_family A \<equiv> disjoint_family_on A UNIV"
hoelzl@38656
   707
hoelzl@38656
   708
lemma range_subsetD: "range f \<subseteq> B \<Longrightarrow> f i \<in> B"
hoelzl@38656
   709
  by blast
hoelzl@38656
   710
hoelzl@38656
   711
lemma Int_Diff_disjoint: "A \<inter> B \<inter> (A - B) = {}"
hoelzl@38656
   712
  by blast
hoelzl@38656
   713
hoelzl@38656
   714
lemma Int_Diff_Un: "A \<inter> B \<union> (A - B) = A"
hoelzl@38656
   715
  by blast
hoelzl@38656
   716
hoelzl@38656
   717
lemma disjoint_family_subset:
hoelzl@38656
   718
     "disjoint_family A \<Longrightarrow> (!!x. B x \<subseteq> A x) \<Longrightarrow> disjoint_family B"
hoelzl@38656
   719
  by (force simp add: disjoint_family_on_def)
hoelzl@38656
   720
hoelzl@40859
   721
lemma disjoint_family_on_bisimulation:
hoelzl@40859
   722
  assumes "disjoint_family_on f S"
hoelzl@40859
   723
  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
   724
  shows "disjoint_family_on g S"
hoelzl@40859
   725
  using assms unfolding disjoint_family_on_def by auto
hoelzl@40859
   726
hoelzl@38656
   727
lemma disjoint_family_on_mono:
hoelzl@38656
   728
  "A \<subseteq> B \<Longrightarrow> disjoint_family_on f B \<Longrightarrow> disjoint_family_on f A"
hoelzl@38656
   729
  unfolding disjoint_family_on_def by auto
hoelzl@38656
   730
hoelzl@38656
   731
lemma disjoint_family_Suc:
hoelzl@38656
   732
  assumes Suc: "!!n. A n \<subseteq> A (Suc n)"
hoelzl@38656
   733
  shows "disjoint_family (\<lambda>i. A (Suc i) - A i)"
hoelzl@38656
   734
proof -
hoelzl@38656
   735
  {
hoelzl@38656
   736
    fix m
hoelzl@38656
   737
    have "!!n. A n \<subseteq> A (m+n)"
hoelzl@38656
   738
    proof (induct m)
hoelzl@38656
   739
      case 0 show ?case by simp
hoelzl@38656
   740
    next
hoelzl@38656
   741
      case (Suc m) thus ?case
hoelzl@38656
   742
        by (metis Suc_eq_plus1 assms nat_add_commute nat_add_left_commute subset_trans)
hoelzl@38656
   743
    qed
hoelzl@38656
   744
  }
hoelzl@38656
   745
  hence "!!m n. m < n \<Longrightarrow> A m \<subseteq> A n"
hoelzl@38656
   746
    by (metis add_commute le_add_diff_inverse nat_less_le)
hoelzl@38656
   747
  thus ?thesis
hoelzl@38656
   748
    by (auto simp add: disjoint_family_on_def)
hoelzl@38656
   749
      (metis insert_absorb insert_subset le_SucE le_antisym not_leE)
hoelzl@38656
   750
qed
hoelzl@38656
   751
hoelzl@39092
   752
lemma setsum_indicator_disjoint_family:
hoelzl@39092
   753
  fixes f :: "'d \<Rightarrow> 'e::semiring_1"
hoelzl@39092
   754
  assumes d: "disjoint_family_on A P" and "x \<in> A j" and "finite P" and "j \<in> P"
hoelzl@39092
   755
  shows "(\<Sum>i\<in>P. f i * indicator (A i) x) = f j"
hoelzl@39092
   756
proof -
hoelzl@39092
   757
  have "P \<inter> {i. x \<in> A i} = {j}"
hoelzl@39092
   758
    using d `x \<in> A j` `j \<in> P` unfolding disjoint_family_on_def
hoelzl@39092
   759
    by auto
hoelzl@39092
   760
  thus ?thesis
hoelzl@39092
   761
    unfolding indicator_def
hoelzl@39092
   762
    by (simp add: if_distrib setsum_cases[OF `finite P`])
hoelzl@39092
   763
qed
hoelzl@39092
   764
hoelzl@38656
   765
definition disjointed :: "(nat \<Rightarrow> 'a set) \<Rightarrow> nat \<Rightarrow> 'a set "
hoelzl@38656
   766
  where "disjointed A n = A n - (\<Union>i\<in>{0..<n}. A i)"
hoelzl@38656
   767
hoelzl@38656
   768
lemma finite_UN_disjointed_eq: "(\<Union>i\<in>{0..<n}. disjointed A i) = (\<Union>i\<in>{0..<n}. A i)"
hoelzl@38656
   769
proof (induct n)
hoelzl@38656
   770
  case 0 show ?case by simp
hoelzl@38656
   771
next
hoelzl@38656
   772
  case (Suc n)
hoelzl@38656
   773
  thus ?case by (simp add: atLeastLessThanSuc disjointed_def)
hoelzl@38656
   774
qed
hoelzl@38656
   775
hoelzl@38656
   776
lemma UN_disjointed_eq: "(\<Union>i. disjointed A i) = (\<Union>i. A i)"
hoelzl@38656
   777
  apply (rule UN_finite2_eq [where k=0])
hoelzl@38656
   778
  apply (simp add: finite_UN_disjointed_eq)
hoelzl@38656
   779
  done
hoelzl@38656
   780
hoelzl@38656
   781
lemma less_disjoint_disjointed: "m<n \<Longrightarrow> disjointed A m \<inter> disjointed A n = {}"
hoelzl@38656
   782
  by (auto simp add: disjointed_def)
hoelzl@38656
   783
hoelzl@38656
   784
lemma disjoint_family_disjointed: "disjoint_family (disjointed A)"
hoelzl@38656
   785
  by (simp add: disjoint_family_on_def)
hoelzl@38656
   786
     (metis neq_iff Int_commute less_disjoint_disjointed)
hoelzl@38656
   787
hoelzl@38656
   788
lemma disjointed_subset: "disjointed A n \<subseteq> A n"
hoelzl@38656
   789
  by (auto simp add: disjointed_def)
hoelzl@38656
   790
hoelzl@42065
   791
lemma (in ring_of_sets) UNION_in_sets:
hoelzl@38656
   792
  fixes A:: "nat \<Rightarrow> 'a set"
hoelzl@47694
   793
  assumes A: "range A \<subseteq> M"
hoelzl@47694
   794
  shows  "(\<Union>i\<in>{0..<n}. A i) \<in> M"
hoelzl@38656
   795
proof (induct n)
hoelzl@38656
   796
  case 0 show ?case by simp
hoelzl@38656
   797
next
hoelzl@38656
   798
  case (Suc n)
hoelzl@38656
   799
  thus ?case
hoelzl@38656
   800
    by (simp add: atLeastLessThanSuc) (metis A Un UNIV_I image_subset_iff)
hoelzl@38656
   801
qed
hoelzl@38656
   802
hoelzl@42065
   803
lemma (in ring_of_sets) range_disjointed_sets:
hoelzl@47694
   804
  assumes A: "range A \<subseteq> M"
hoelzl@47694
   805
  shows  "range (disjointed A) \<subseteq> M"
hoelzl@38656
   806
proof (auto simp add: disjointed_def)
hoelzl@38656
   807
  fix n
hoelzl@47694
   808
  show "A n - (\<Union>i\<in>{0..<n}. A i) \<in> M" using UNION_in_sets
hoelzl@38656
   809
    by (metis A Diff UNIV_I image_subset_iff)
hoelzl@38656
   810
qed
hoelzl@38656
   811
hoelzl@42065
   812
lemma (in algebra) range_disjointed_sets':
hoelzl@47694
   813
  "range A \<subseteq> M \<Longrightarrow> range (disjointed A) \<subseteq> M"
hoelzl@42065
   814
  using range_disjointed_sets .
hoelzl@42065
   815
hoelzl@42145
   816
lemma disjointed_0[simp]: "disjointed A 0 = A 0"
hoelzl@42145
   817
  by (simp add: disjointed_def)
hoelzl@42145
   818
hoelzl@42145
   819
lemma incseq_Un:
hoelzl@42145
   820
  "incseq A \<Longrightarrow> (\<Union>i\<le>n. A i) = A n"
hoelzl@42145
   821
  unfolding incseq_def by auto
hoelzl@42145
   822
hoelzl@42145
   823
lemma disjointed_incseq:
hoelzl@42145
   824
  "incseq A \<Longrightarrow> disjointed A (Suc n) = A (Suc n) - A n"
hoelzl@42145
   825
  using incseq_Un[of A]
hoelzl@42145
   826
  by (simp add: disjointed_def atLeastLessThanSuc_atLeastAtMost atLeast0AtMost)
hoelzl@42145
   827
hoelzl@38656
   828
lemma sigma_algebra_disjoint_iff:
hoelzl@47694
   829
  "sigma_algebra \<Omega> M \<longleftrightarrow> algebra \<Omega> M \<and>
hoelzl@47694
   830
    (\<forall>A. range A \<subseteq> M \<longrightarrow> disjoint_family A \<longrightarrow> (\<Union>i::nat. A i) \<in> M)"
hoelzl@38656
   831
proof (auto simp add: sigma_algebra_iff)
hoelzl@38656
   832
  fix A :: "nat \<Rightarrow> 'a set"
hoelzl@47694
   833
  assume M: "algebra \<Omega> M"
hoelzl@47694
   834
     and A: "range A \<subseteq> M"
hoelzl@47694
   835
     and UnA: "\<forall>A. range A \<subseteq> M \<longrightarrow> disjoint_family A \<longrightarrow> (\<Union>i::nat. A i) \<in> M"
hoelzl@47694
   836
  hence "range (disjointed A) \<subseteq> M \<longrightarrow>
hoelzl@38656
   837
         disjoint_family (disjointed A) \<longrightarrow>
hoelzl@47694
   838
         (\<Union>i. disjointed A i) \<in> M" by blast
hoelzl@47694
   839
  hence "(\<Union>i. disjointed A i) \<in> M"
hoelzl@47694
   840
    by (simp add: algebra.range_disjointed_sets'[of \<Omega>] M A disjoint_family_disjointed)
hoelzl@47694
   841
  thus "(\<Union>i::nat. A i) \<in> M" by (simp add: UN_disjointed_eq)
hoelzl@47694
   842
qed
hoelzl@47694
   843
hoelzl@47762
   844
lemma disjoint_family_on_disjoint_image:
hoelzl@47762
   845
  "disjoint_family_on A I \<Longrightarrow> disjoint (A ` I)"
hoelzl@47762
   846
  unfolding disjoint_family_on_def disjoint_def by force
hoelzl@47762
   847
hoelzl@47762
   848
lemma disjoint_image_disjoint_family_on:
hoelzl@47762
   849
  assumes d: "disjoint (A ` I)" and i: "inj_on A I"
hoelzl@47762
   850
  shows "disjoint_family_on A I"
hoelzl@47762
   851
  unfolding disjoint_family_on_def
hoelzl@47762
   852
proof (intro ballI impI)
hoelzl@47762
   853
  fix n m assume nm: "m \<in> I" "n \<in> I" and "n \<noteq> m"
hoelzl@47762
   854
  with i[THEN inj_onD, of n m] show "A n \<inter> A m = {}"
hoelzl@47762
   855
    by (intro disjointD[OF d]) auto
hoelzl@47762
   856
qed
hoelzl@47762
   857
hoelzl@47762
   858
section {* Ring generated by a semiring *}
hoelzl@47762
   859
hoelzl@47762
   860
definition (in semiring_of_sets)
hoelzl@47762
   861
  "generated_ring = { \<Union>C | C. C \<subseteq> M \<and> finite C \<and> disjoint C }"
hoelzl@47762
   862
hoelzl@47762
   863
lemma (in semiring_of_sets) generated_ringE[elim?]:
hoelzl@47762
   864
  assumes "a \<in> generated_ring"
hoelzl@47762
   865
  obtains C where "finite C" "disjoint C" "C \<subseteq> M" "a = \<Union>C"
hoelzl@47762
   866
  using assms unfolding generated_ring_def by auto
hoelzl@47762
   867
hoelzl@47762
   868
lemma (in semiring_of_sets) generated_ringI[intro?]:
hoelzl@47762
   869
  assumes "finite C" "disjoint C" "C \<subseteq> M" "a = \<Union>C"
hoelzl@47762
   870
  shows "a \<in> generated_ring"
hoelzl@47762
   871
  using assms unfolding generated_ring_def by auto
hoelzl@47762
   872
hoelzl@47762
   873
lemma (in semiring_of_sets) generated_ringI_Basic:
hoelzl@47762
   874
  "A \<in> M \<Longrightarrow> A \<in> generated_ring"
hoelzl@47762
   875
  by (rule generated_ringI[of "{A}"]) (auto simp: disjoint_def)
hoelzl@47762
   876
hoelzl@47762
   877
lemma (in semiring_of_sets) generated_ring_disjoint_Un[intro]:
hoelzl@47762
   878
  assumes a: "a \<in> generated_ring" and b: "b \<in> generated_ring"
hoelzl@47762
   879
  and "a \<inter> b = {}"
hoelzl@47762
   880
  shows "a \<union> b \<in> generated_ring"
hoelzl@47762
   881
proof -
hoelzl@47762
   882
  from a guess Ca .. note Ca = this
hoelzl@47762
   883
  from b guess Cb .. note Cb = this
hoelzl@47762
   884
  show ?thesis
hoelzl@47762
   885
  proof
hoelzl@47762
   886
    show "disjoint (Ca \<union> Cb)"
hoelzl@47762
   887
      using `a \<inter> b = {}` Ca Cb by (auto intro!: disjoint_union)
hoelzl@47762
   888
  qed (insert Ca Cb, auto)
hoelzl@47762
   889
qed
hoelzl@47762
   890
hoelzl@47762
   891
lemma (in semiring_of_sets) generated_ring_empty: "{} \<in> generated_ring"
hoelzl@47762
   892
  by (auto simp: generated_ring_def disjoint_def)
hoelzl@47762
   893
hoelzl@47762
   894
lemma (in semiring_of_sets) generated_ring_disjoint_Union:
hoelzl@47762
   895
  assumes "finite A" shows "A \<subseteq> generated_ring \<Longrightarrow> disjoint A \<Longrightarrow> \<Union>A \<in> generated_ring"
hoelzl@47762
   896
  using assms by (induct A) (auto simp: disjoint_def intro!: generated_ring_disjoint_Un generated_ring_empty)
hoelzl@47762
   897
hoelzl@47762
   898
lemma (in semiring_of_sets) generated_ring_disjoint_UNION:
hoelzl@47762
   899
  "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
   900
  unfolding SUP_def by (intro generated_ring_disjoint_Union) auto
hoelzl@47762
   901
hoelzl@47762
   902
lemma (in semiring_of_sets) generated_ring_Int:
hoelzl@47762
   903
  assumes a: "a \<in> generated_ring" and b: "b \<in> generated_ring"
hoelzl@47762
   904
  shows "a \<inter> b \<in> generated_ring"
hoelzl@47762
   905
proof -
hoelzl@47762
   906
  from a guess Ca .. note Ca = this
hoelzl@47762
   907
  from b guess Cb .. note Cb = this
hoelzl@47762
   908
  def C \<equiv> "(\<lambda>(a,b). a \<inter> b)` (Ca\<times>Cb)"
hoelzl@47762
   909
  show ?thesis
hoelzl@47762
   910
  proof
hoelzl@47762
   911
    show "disjoint C"
hoelzl@47762
   912
    proof (simp add: disjoint_def C_def, intro ballI impI)
hoelzl@47762
   913
      fix a1 b1 a2 b2 assume sets: "a1 \<in> Ca" "b1 \<in> Cb" "a2 \<in> Ca" "b2 \<in> Cb"
hoelzl@47762
   914
      assume "a1 \<inter> b1 \<noteq> a2 \<inter> b2"
hoelzl@47762
   915
      then have "a1 \<noteq> a2 \<or> b1 \<noteq> b2" by auto
hoelzl@47762
   916
      then show "(a1 \<inter> b1) \<inter> (a2 \<inter> b2) = {}"
hoelzl@47762
   917
      proof
hoelzl@47762
   918
        assume "a1 \<noteq> a2"
hoelzl@47762
   919
        with sets Ca have "a1 \<inter> a2 = {}"
hoelzl@47762
   920
          by (auto simp: disjoint_def)
hoelzl@47762
   921
        then show ?thesis by auto
hoelzl@47762
   922
      next
hoelzl@47762
   923
        assume "b1 \<noteq> b2"
hoelzl@47762
   924
        with sets Cb have "b1 \<inter> b2 = {}"
hoelzl@47762
   925
          by (auto simp: disjoint_def)
hoelzl@47762
   926
        then show ?thesis by auto
hoelzl@47762
   927
      qed
hoelzl@47762
   928
    qed
hoelzl@47762
   929
  qed (insert Ca Cb, auto simp: C_def)
hoelzl@47762
   930
qed
hoelzl@47762
   931
hoelzl@47762
   932
lemma (in semiring_of_sets) generated_ring_Inter:
hoelzl@47762
   933
  assumes "finite A" "A \<noteq> {}" shows "A \<subseteq> generated_ring \<Longrightarrow> \<Inter>A \<in> generated_ring"
hoelzl@47762
   934
  using assms by (induct A rule: finite_ne_induct) (auto intro: generated_ring_Int)
hoelzl@47762
   935
hoelzl@47762
   936
lemma (in semiring_of_sets) generated_ring_INTER:
hoelzl@47762
   937
  "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
   938
  unfolding INF_def by (intro generated_ring_Inter) auto
hoelzl@47762
   939
hoelzl@47762
   940
lemma (in semiring_of_sets) generating_ring:
hoelzl@47762
   941
  "ring_of_sets \<Omega> generated_ring"
hoelzl@47762
   942
proof (rule ring_of_setsI)
hoelzl@47762
   943
  let ?R = generated_ring
hoelzl@47762
   944
  show "?R \<subseteq> Pow \<Omega>"
hoelzl@47762
   945
    using sets_into_space by (auto simp: generated_ring_def generated_ring_empty)
hoelzl@47762
   946
  show "{} \<in> ?R" by (rule generated_ring_empty)
hoelzl@47762
   947
hoelzl@47762
   948
  { fix a assume a: "a \<in> ?R" then guess Ca .. note Ca = this
hoelzl@47762
   949
    fix b assume b: "b \<in> ?R" then guess Cb .. note Cb = this
hoelzl@47762
   950
  
hoelzl@47762
   951
    show "a - b \<in> ?R"
hoelzl@47762
   952
    proof cases
hoelzl@47762
   953
      assume "Cb = {}" with Cb `a \<in> ?R` show ?thesis
hoelzl@47762
   954
        by simp
hoelzl@47762
   955
    next
hoelzl@47762
   956
      assume "Cb \<noteq> {}"
hoelzl@47762
   957
      with Ca Cb have "a - b = (\<Union>a'\<in>Ca. \<Inter>b'\<in>Cb. a' - b')" by auto
hoelzl@47762
   958
      also have "\<dots> \<in> ?R"
hoelzl@47762
   959
      proof (intro generated_ring_INTER generated_ring_disjoint_UNION)
hoelzl@47762
   960
        fix a b assume "a \<in> Ca" "b \<in> Cb"
hoelzl@47762
   961
        with Ca Cb Diff_cover[of a b] show "a - b \<in> ?R"
hoelzl@47762
   962
          by (auto simp add: generated_ring_def)
hoelzl@47762
   963
      next
hoelzl@47762
   964
        show "disjoint ((\<lambda>a'. \<Inter>b'\<in>Cb. a' - b')`Ca)"
hoelzl@47762
   965
          using Ca by (auto simp add: disjoint_def `Cb \<noteq> {}`)
hoelzl@47762
   966
      next
hoelzl@47762
   967
        show "finite Ca" "finite Cb" "Cb \<noteq> {}" by fact+
hoelzl@47762
   968
      qed
hoelzl@47762
   969
      finally show "a - b \<in> ?R" .
hoelzl@47762
   970
    qed }
hoelzl@47762
   971
  note Diff = this
hoelzl@47762
   972
hoelzl@47762
   973
  fix a b assume sets: "a \<in> ?R" "b \<in> ?R"
hoelzl@47762
   974
  have "a \<union> b = (a - b) \<union> (a \<inter> b) \<union> (b - a)" by auto
hoelzl@47762
   975
  also have "\<dots> \<in> ?R"
hoelzl@47762
   976
    by (intro sets generated_ring_disjoint_Un generated_ring_Int Diff) auto
hoelzl@47762
   977
  finally show "a \<union> b \<in> ?R" .
hoelzl@47762
   978
qed
hoelzl@47762
   979
hoelzl@47762
   980
lemma (in semiring_of_sets) sigma_sets_generated_ring_eq: "sigma_sets \<Omega> generated_ring = sigma_sets \<Omega> M"
hoelzl@47762
   981
proof
hoelzl@47762
   982
  interpret M: sigma_algebra \<Omega> "sigma_sets \<Omega> M"
hoelzl@47762
   983
    using space_closed by (rule sigma_algebra_sigma_sets)
hoelzl@47762
   984
  show "sigma_sets \<Omega> generated_ring \<subseteq> sigma_sets \<Omega> M"
hoelzl@47762
   985
    by (blast intro!: sigma_sets_mono elim: generated_ringE)
hoelzl@47762
   986
qed (auto intro!: generated_ringI_Basic sigma_sets_mono)
hoelzl@47762
   987
hoelzl@47694
   988
section {* Measure type *}
hoelzl@47694
   989
hoelzl@47694
   990
definition positive :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> bool" where
hoelzl@47694
   991
  "positive M \<mu> \<longleftrightarrow> \<mu> {} = 0 \<and> (\<forall>A\<in>M. 0 \<le> \<mu> A)"
hoelzl@47694
   992
hoelzl@47694
   993
definition countably_additive :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> bool" where
hoelzl@47694
   994
  "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
   995
    (\<Sum>i. f (A i)) = f (\<Union>i. A i))"
hoelzl@47694
   996
hoelzl@47694
   997
definition measure_space :: "'a set \<Rightarrow> 'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> bool" where
hoelzl@47694
   998
  "measure_space \<Omega> A \<mu> \<longleftrightarrow> sigma_algebra \<Omega> A \<and> positive A \<mu> \<and> countably_additive A \<mu>"
hoelzl@47694
   999
wenzelm@49834
  1000
typedef 'a measure = "{(\<Omega>::'a set, A, \<mu>). (\<forall>a\<in>-A. \<mu> a = 0) \<and> measure_space \<Omega> A \<mu> }"
hoelzl@47694
  1001
proof
hoelzl@47694
  1002
  have "sigma_algebra UNIV {{}, UNIV}"
hoelzl@47762
  1003
    by (auto simp: sigma_algebra_iff2)
hoelzl@47694
  1004
  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
  1005
    by (auto simp: measure_space_def positive_def countably_additive_def)
hoelzl@47694
  1006
qed
hoelzl@47694
  1007
hoelzl@47694
  1008
definition space :: "'a measure \<Rightarrow> 'a set" where
hoelzl@47694
  1009
  "space M = fst (Rep_measure M)"
hoelzl@47694
  1010
hoelzl@47694
  1011
definition sets :: "'a measure \<Rightarrow> 'a set set" where
hoelzl@47694
  1012
  "sets M = fst (snd (Rep_measure M))"
hoelzl@47694
  1013
hoelzl@47694
  1014
definition emeasure :: "'a measure \<Rightarrow> 'a set \<Rightarrow> ereal" where
hoelzl@47694
  1015
  "emeasure M = snd (snd (Rep_measure M))"
hoelzl@47694
  1016
hoelzl@47694
  1017
definition measure :: "'a measure \<Rightarrow> 'a set \<Rightarrow> real" where
hoelzl@47694
  1018
  "measure M A = real (emeasure M A)"
hoelzl@47694
  1019
hoelzl@47694
  1020
declare [[coercion sets]]
hoelzl@47694
  1021
hoelzl@47694
  1022
declare [[coercion measure]]
hoelzl@47694
  1023
hoelzl@47694
  1024
declare [[coercion emeasure]]
hoelzl@47694
  1025
hoelzl@47694
  1026
lemma measure_space: "measure_space (space M) (sets M) (emeasure M)"
hoelzl@47694
  1027
  by (cases M) (auto simp: space_def sets_def emeasure_def Abs_measure_inverse)
hoelzl@47694
  1028
hoelzl@47694
  1029
interpretation sigma_algebra "space M" "sets M" for M :: "'a measure"
hoelzl@47694
  1030
  using measure_space[of M] by (auto simp: measure_space_def)
hoelzl@47694
  1031
hoelzl@47694
  1032
definition measure_of :: "'a set \<Rightarrow> 'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> 'a measure" where
hoelzl@47694
  1033
  "measure_of \<Omega> A \<mu> = Abs_measure (\<Omega>, sigma_sets \<Omega> A,
hoelzl@47694
  1034
    \<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
  1035
hoelzl@47694
  1036
abbreviation "sigma \<Omega> A \<equiv> measure_of \<Omega> A (\<lambda>x. 0)"
hoelzl@47694
  1037
hoelzl@47694
  1038
lemma measure_space_0: "A \<subseteq> Pow \<Omega> \<Longrightarrow> measure_space \<Omega> (sigma_sets \<Omega> A) (\<lambda>x. 0)"
hoelzl@47694
  1039
  unfolding measure_space_def
hoelzl@47694
  1040
  by (auto intro!: sigma_algebra_sigma_sets simp: positive_def countably_additive_def)
hoelzl@47694
  1041
hoelzl@47694
  1042
lemma (in ring_of_sets) positive_cong_eq:
hoelzl@47694
  1043
  "(\<And>a. a \<in> M \<Longrightarrow> \<mu>' a = \<mu> a) \<Longrightarrow> positive M \<mu>' = positive M \<mu>"
hoelzl@47694
  1044
  by (auto simp add: positive_def)
hoelzl@47694
  1045
hoelzl@47694
  1046
lemma (in sigma_algebra) countably_additive_eq:
hoelzl@47694
  1047
  "(\<And>a. a \<in> M \<Longrightarrow> \<mu>' a = \<mu> a) \<Longrightarrow> countably_additive M \<mu>' = countably_additive M \<mu>"
hoelzl@47694
  1048
  unfolding countably_additive_def
hoelzl@47694
  1049
  by (intro arg_cong[where f=All] ext) (auto simp add: countably_additive_def subset_eq)
hoelzl@47694
  1050
hoelzl@47694
  1051
lemma measure_space_eq:
hoelzl@47694
  1052
  assumes closed: "A \<subseteq> Pow \<Omega>" and eq: "\<And>a. a \<in> sigma_sets \<Omega> A \<Longrightarrow> \<mu> a = \<mu>' a"
hoelzl@47694
  1053
  shows "measure_space \<Omega> (sigma_sets \<Omega> A) \<mu> = measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>'"
hoelzl@47694
  1054
proof -
hoelzl@47694
  1055
  interpret sigma_algebra \<Omega> "sigma_sets \<Omega> A" using closed by (rule sigma_algebra_sigma_sets)
hoelzl@47694
  1056
  from positive_cong_eq[OF eq, of "\<lambda>i. i"] countably_additive_eq[OF eq, of "\<lambda>i. i"] show ?thesis
hoelzl@47694
  1057
    by (auto simp: measure_space_def)
hoelzl@47694
  1058
qed
hoelzl@47694
  1059
hoelzl@47694
  1060
lemma measure_of_eq:
hoelzl@47694
  1061
  assumes closed: "A \<subseteq> Pow \<Omega>" and eq: "(\<And>a. a \<in> sigma_sets \<Omega> A \<Longrightarrow> \<mu> a = \<mu>' a)"
hoelzl@47694
  1062
  shows "measure_of \<Omega> A \<mu> = measure_of \<Omega> A \<mu>'"
hoelzl@47694
  1063
proof -
hoelzl@47694
  1064
  have "measure_space \<Omega> (sigma_sets \<Omega> A) \<mu> = measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>'"
hoelzl@47694
  1065
    using assms by (rule measure_space_eq)
hoelzl@47694
  1066
  with eq show ?thesis
hoelzl@47694
  1067
    by (auto simp add: measure_of_def intro!: arg_cong[where f=Abs_measure])
hoelzl@47694
  1068
qed
hoelzl@47694
  1069
hoelzl@47694
  1070
lemma
hoelzl@47694
  1071
  assumes A: "A \<subseteq> Pow \<Omega>"
hoelzl@47694
  1072
  shows sets_measure_of[simp]: "sets (measure_of \<Omega> A \<mu>) = sigma_sets \<Omega> A" (is ?sets)
hoelzl@47694
  1073
    and space_measure_of[simp]: "space (measure_of \<Omega> A \<mu>) = \<Omega>" (is ?space)
hoelzl@47694
  1074
proof -
hoelzl@47694
  1075
  have "?sets \<and> ?space"
hoelzl@47694
  1076
  proof cases
hoelzl@47694
  1077
    assume "measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>"
hoelzl@47694
  1078
    moreover have "measure_space \<Omega> (sigma_sets \<Omega> A) \<mu> = measure_space \<Omega> (sigma_sets \<Omega> A)
hoelzl@47694
  1079
       (\<lambda>a. if a \<in> sigma_sets \<Omega> A then \<mu> a else 0)"
hoelzl@47694
  1080
      using A by (rule measure_space_eq) auto
hoelzl@47694
  1081
    ultimately show "?sets \<and> ?space"
hoelzl@47694
  1082
      by (auto simp: Abs_measure_inverse measure_of_def sets_def space_def)
hoelzl@47694
  1083
  next
hoelzl@47694
  1084
    assume "\<not> measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>"
hoelzl@47694
  1085
    with A show "?sets \<and> ?space"
hoelzl@47694
  1086
      by (auto simp: Abs_measure_inverse measure_of_def sets_def space_def measure_space_0)
hoelzl@47694
  1087
  qed
hoelzl@47694
  1088
  then show ?sets ?space by auto
hoelzl@47694
  1089
qed
hoelzl@47694
  1090
hoelzl@47694
  1091
lemma (in sigma_algebra) sets_measure_of_eq[simp]:
hoelzl@47694
  1092
  "sets (measure_of \<Omega> M \<mu>) = M"
hoelzl@47694
  1093
  using space_closed by (auto intro!: sigma_sets_eq)
hoelzl@47694
  1094
hoelzl@47694
  1095
lemma (in sigma_algebra) space_measure_of_eq[simp]:
hoelzl@47694
  1096
  "space (measure_of \<Omega> M \<mu>) = \<Omega>"
hoelzl@47694
  1097
  using space_closed by (auto intro!: sigma_sets_eq)
hoelzl@47694
  1098
hoelzl@47694
  1099
lemma measure_of_subset:
hoelzl@47694
  1100
  "M \<subseteq> Pow \<Omega> \<Longrightarrow> M' \<subseteq> M \<Longrightarrow> sets (measure_of \<Omega> M' \<mu>) \<subseteq> sets (measure_of \<Omega> M \<mu>')"
hoelzl@47694
  1101
  by (auto intro!: sigma_sets_subseteq)
hoelzl@47694
  1102
hoelzl@47756
  1103
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
  1104
  by auto
hoelzl@47694
  1105
hoelzl@47694
  1106
section {* Constructing simple @{typ "'a measure"} *}
hoelzl@47694
  1107
hoelzl@47694
  1108
lemma emeasure_measure_of:
hoelzl@47694
  1109
  assumes M: "M = measure_of \<Omega> A \<mu>"
hoelzl@47694
  1110
  assumes ms: "A \<subseteq> Pow \<Omega>" "positive (sets M) \<mu>" "countably_additive (sets M) \<mu>"
hoelzl@47694
  1111
  assumes X: "X \<in> sets M"
hoelzl@47694
  1112
  shows "emeasure M X = \<mu> X"
hoelzl@47694
  1113
proof -
hoelzl@47694
  1114
  interpret sigma_algebra \<Omega> "sigma_sets \<Omega> A" by (rule sigma_algebra_sigma_sets) fact
hoelzl@47694
  1115
  have "measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>"
hoelzl@47694
  1116
    using ms M by (simp add: measure_space_def sigma_algebra_sigma_sets)
hoelzl@47694
  1117
  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
  1118
    = measure_space \<Omega> (sigma_sets \<Omega> A) \<mu>"
hoelzl@47694
  1119
    using ms(1) by (rule measure_space_eq) auto
hoelzl@47694
  1120
  moreover have "X \<in> sigma_sets \<Omega> A"
hoelzl@47694
  1121
    using X M ms by simp
hoelzl@47694
  1122
  ultimately show ?thesis
hoelzl@47694
  1123
    unfolding emeasure_def measure_of_def M
hoelzl@47694
  1124
    by (subst Abs_measure_inverse) (simp_all add: sigma_sets_eq)
hoelzl@47694
  1125
qed
hoelzl@47694
  1126
hoelzl@47694
  1127
lemma emeasure_measure_of_sigma:
hoelzl@47694
  1128
  assumes ms: "sigma_algebra \<Omega> M" "positive M \<mu>" "countably_additive M \<mu>"
hoelzl@47694
  1129
  assumes A: "A \<in> M"
hoelzl@47694
  1130
  shows "emeasure (measure_of \<Omega> M \<mu>) A = \<mu> A"
hoelzl@47694
  1131
proof -
hoelzl@47694
  1132
  interpret sigma_algebra \<Omega> M by fact
hoelzl@47694
  1133
  have "measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>"
hoelzl@47694
  1134
    using ms sigma_sets_eq by (simp add: measure_space_def)
hoelzl@47694
  1135
  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
  1136
    = measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>"
hoelzl@47694
  1137
    using space_closed by (rule measure_space_eq) auto
hoelzl@47694
  1138
  ultimately show ?thesis using A
hoelzl@47694
  1139
    unfolding emeasure_def measure_of_def
hoelzl@47694
  1140
    by (subst Abs_measure_inverse) (simp_all add: sigma_sets_eq)
hoelzl@47694
  1141
qed
hoelzl@47694
  1142
hoelzl@47694
  1143
lemma measure_cases[cases type: measure]:
hoelzl@47694
  1144
  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
  1145
  by atomize_elim (cases x, auto)
hoelzl@47694
  1146
hoelzl@47694
  1147
lemma sets_eq_imp_space_eq:
hoelzl@47694
  1148
  "sets M = sets M' \<Longrightarrow> space M = space M'"
hoelzl@47694
  1149
  using top[of M] top[of M'] space_closed[of M] space_closed[of M']
hoelzl@47694
  1150
  by blast
hoelzl@47694
  1151
hoelzl@47694
  1152
lemma emeasure_notin_sets: "A \<notin> sets M \<Longrightarrow> emeasure M A = 0"
hoelzl@47694
  1153
  by (cases M) (auto simp: sets_def emeasure_def Abs_measure_inverse measure_space_def)
hoelzl@47694
  1154
hoelzl@47694
  1155
lemma measure_notin_sets: "A \<notin> sets M \<Longrightarrow> measure M A = 0"
hoelzl@47694
  1156
  by (simp add: measure_def emeasure_notin_sets)
hoelzl@47694
  1157
hoelzl@47694
  1158
lemma measure_eqI:
hoelzl@47694
  1159
  fixes M N :: "'a measure"
hoelzl@47694
  1160
  assumes "sets M = sets N" and eq: "\<And>A. A \<in> sets M \<Longrightarrow> emeasure M A = emeasure N A"
hoelzl@47694
  1161
  shows "M = N"
hoelzl@47694
  1162
proof (cases M N rule: measure_cases[case_product measure_cases])
hoelzl@47694
  1163
  case (measure_measure \<Omega> A \<mu> \<Omega>' A' \<mu>')
hoelzl@47694
  1164
  interpret M: sigma_algebra \<Omega> A using measure_measure by (auto simp: measure_space_def)
hoelzl@47694
  1165
  interpret N: sigma_algebra \<Omega>' A' using measure_measure by (auto simp: measure_space_def)
hoelzl@47694
  1166
  have "A = sets M" "A' = sets N"
hoelzl@47694
  1167
    using measure_measure by (simp_all add: sets_def Abs_measure_inverse)
hoelzl@47694
  1168
  with `sets M = sets N` have "A = A'" by simp
hoelzl@47694
  1169
  moreover with M.top N.top M.space_closed N.space_closed have "\<Omega> = \<Omega>'" by auto
hoelzl@47694
  1170
  moreover { fix B have "\<mu> B = \<mu>' B"
hoelzl@47694
  1171
    proof cases
hoelzl@47694
  1172
      assume "B \<in> A"
hoelzl@47694
  1173
      with eq `A = sets M` have "emeasure M B = emeasure N B" by simp
hoelzl@47694
  1174
      with measure_measure show "\<mu> B = \<mu>' B"
hoelzl@47694
  1175
        by (simp add: emeasure_def Abs_measure_inverse)
hoelzl@47694
  1176
    next
hoelzl@47694
  1177
      assume "B \<notin> A"
hoelzl@47694
  1178
      with `A = sets M` `A' = sets N` `A = A'` have "B \<notin> sets M" "B \<notin> sets N"
hoelzl@47694
  1179
        by auto
hoelzl@47694
  1180
      then have "emeasure M B = 0" "emeasure N B = 0"
hoelzl@47694
  1181
        by (simp_all add: emeasure_notin_sets)
hoelzl@47694
  1182
      with measure_measure show "\<mu> B = \<mu>' B"
hoelzl@47694
  1183
        by (simp add: emeasure_def Abs_measure_inverse)
hoelzl@47694
  1184
    qed }
hoelzl@47694
  1185
  then have "\<mu> = \<mu>'" by auto
hoelzl@47694
  1186
  ultimately show "M = N"
hoelzl@47694
  1187
    by (simp add: measure_measure)
hoelzl@38656
  1188
qed
hoelzl@38656
  1189
hoelzl@47694
  1190
lemma emeasure_sigma: "A \<subseteq> Pow \<Omega> \<Longrightarrow> emeasure (sigma \<Omega> A) = (\<lambda>_. 0)"
hoelzl@47694
  1191
  using measure_space_0[of A \<Omega>]
hoelzl@47694
  1192
  by (simp add: measure_of_def emeasure_def Abs_measure_inverse)
hoelzl@47694
  1193
hoelzl@47694
  1194
lemma sigma_eqI:
hoelzl@47694
  1195
  assumes [simp]: "M \<subseteq> Pow \<Omega>" "N \<subseteq> Pow \<Omega>" "sigma_sets \<Omega> M = sigma_sets \<Omega> N"
hoelzl@47694
  1196
  shows "sigma \<Omega> M = sigma \<Omega> N"
hoelzl@47694
  1197
  by (rule measure_eqI) (simp_all add: emeasure_sigma)
hoelzl@47694
  1198
hoelzl@47694
  1199
section {* Measurable functions *}
hoelzl@47694
  1200
hoelzl@47694
  1201
definition measurable :: "'a measure \<Rightarrow> 'b measure \<Rightarrow> ('a \<Rightarrow> 'b) set" where
hoelzl@47694
  1202
  "measurable A B = {f \<in> space A -> space B. \<forall>y \<in> sets B. f -` y \<inter> space A \<in> sets A}"
hoelzl@47694
  1203
hoelzl@47694
  1204
lemma measurable_space:
hoelzl@47694
  1205
  "f \<in> measurable M A \<Longrightarrow> x \<in> space M \<Longrightarrow> f x \<in> space A"
hoelzl@47694
  1206
   unfolding measurable_def by auto
hoelzl@47694
  1207
hoelzl@47694
  1208
lemma measurable_sets:
hoelzl@47694
  1209
  "f \<in> measurable M A \<Longrightarrow> S \<in> sets A \<Longrightarrow> f -` S \<inter> space M \<in> sets M"
hoelzl@47694
  1210
   unfolding measurable_def by auto
hoelzl@47694
  1211
hoelzl@50002
  1212
lemma measurable_sets_Collect:
hoelzl@50002
  1213
  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
  1214
proof -
hoelzl@50002
  1215
  have "f -` {x \<in> space N. P x} \<inter> space M = {x\<in>space M. P (f x)}"
hoelzl@50002
  1216
    using measurable_space[OF f] by auto
hoelzl@50002
  1217
  with measurable_sets[OF f P] show ?thesis
hoelzl@50002
  1218
    by simp
hoelzl@50002
  1219
qed
hoelzl@50002
  1220
hoelzl@47694
  1221
lemma measurable_sigma_sets:
hoelzl@47694
  1222
  assumes B: "sets N = sigma_sets \<Omega> A" "A \<subseteq> Pow \<Omega>"
hoelzl@47694
  1223
      and f: "f \<in> space M \<rightarrow> \<Omega>"
hoelzl@47694
  1224
      and ba: "\<And>y. y \<in> A \<Longrightarrow> (f -` y) \<inter> space M \<in> sets M"
hoelzl@47694
  1225
  shows "f \<in> measurable M N"
hoelzl@47694
  1226
proof -
hoelzl@47694
  1227
  interpret A: sigma_algebra \<Omega> "sigma_sets \<Omega> A" using B(2) by (rule sigma_algebra_sigma_sets)
hoelzl@47694
  1228
  from B top[of N] A.top space_closed[of N] A.space_closed have \<Omega>: "\<Omega> = space N" by force
hoelzl@47694
  1229
  
hoelzl@47694
  1230
  { fix X assume "X \<in> sigma_sets \<Omega> A"
hoelzl@47694
  1231
    then have "f -` X \<inter> space M \<in> sets M \<and> X \<subseteq> \<Omega>"
hoelzl@47694
  1232
      proof induct
hoelzl@47694
  1233
        case (Basic a) then show ?case
hoelzl@47694
  1234
          by (auto simp add: ba) (metis B(2) subsetD PowD)
hoelzl@47694
  1235
      next
hoelzl@47694
  1236
        case (Compl a)
hoelzl@47694
  1237
        have [simp]: "f -` \<Omega> \<inter> space M = space M"
hoelzl@47694
  1238
          by (auto simp add: funcset_mem [OF f])
hoelzl@47694
  1239
        then show ?case
hoelzl@47694
  1240
          by (auto simp add: vimage_Diff Diff_Int_distrib2 compl_sets Compl)
hoelzl@47694
  1241
      next
hoelzl@47694
  1242
        case (Union a)
hoelzl@47694
  1243
        then show ?case
hoelzl@47694
  1244
          by (simp add: vimage_UN, simp only: UN_extend_simps(4)) blast
hoelzl@47694
  1245
      qed auto }
hoelzl@47694
  1246
  with f show ?thesis
hoelzl@47694
  1247
    by (auto simp add: measurable_def B \<Omega>)
hoelzl@47694
  1248
qed
hoelzl@47694
  1249
hoelzl@47694
  1250
lemma measurable_measure_of:
hoelzl@47694
  1251
  assumes B: "N \<subseteq> Pow \<Omega>"
hoelzl@47694
  1252
      and f: "f \<in> space M \<rightarrow> \<Omega>"
hoelzl@47694
  1253
      and ba: "\<And>y. y \<in> N \<Longrightarrow> (f -` y) \<inter> space M \<in> sets M"
hoelzl@47694
  1254
  shows "f \<in> measurable M (measure_of \<Omega> N \<mu>)"
hoelzl@47694
  1255
proof -
hoelzl@47694
  1256
  have "sets (measure_of \<Omega> N \<mu>) = sigma_sets \<Omega> N"
hoelzl@47694
  1257
    using B by (rule sets_measure_of)
hoelzl@47694
  1258
  from this assms show ?thesis by (rule measurable_sigma_sets)
hoelzl@47694
  1259
qed
hoelzl@47694
  1260
hoelzl@47694
  1261
lemma measurable_iff_measure_of:
hoelzl@47694
  1262
  assumes "N \<subseteq> Pow \<Omega>" "f \<in> space M \<rightarrow> \<Omega>"
hoelzl@47694
  1263
  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
  1264
  by (metis assms in_measure_of measurable_measure_of assms measurable_sets)
hoelzl@47694
  1265
hoelzl@47694
  1266
lemma measurable_cong:
hoelzl@47694
  1267
  assumes "\<And> w. w \<in> space M \<Longrightarrow> f w = g w"
hoelzl@47694
  1268
  shows "f \<in> measurable M M' \<longleftrightarrow> g \<in> measurable M M'"
hoelzl@47694
  1269
  unfolding measurable_def using assms
hoelzl@47694
  1270
  by (simp cong: vimage_inter_cong Pi_cong)
hoelzl@47694
  1271
hoelzl@47694
  1272
lemma measurable_eqI:
hoelzl@47694
  1273
     "\<lbrakk> space m1 = space m1' ; space m2 = space m2' ;
hoelzl@47694
  1274
        sets m1 = sets m1' ; sets m2 = sets m2' \<rbrakk>
hoelzl@47694
  1275
      \<Longrightarrow> measurable m1 m2 = measurable m1' m2'"
hoelzl@47694
  1276
  by (simp add: measurable_def sigma_algebra_iff2)
hoelzl@47694
  1277
hoelzl@47694
  1278
lemma measurable_const[intro, simp]:
hoelzl@47694
  1279
  "c \<in> space M' \<Longrightarrow> (\<lambda>x. c) \<in> measurable M M'"
hoelzl@47694
  1280
  by (auto simp add: measurable_def)
hoelzl@47694
  1281
hoelzl@47694
  1282
lemma measurable_If:
hoelzl@47694
  1283
  assumes measure: "f \<in> measurable M M'" "g \<in> measurable M M'"
hoelzl@47694
  1284
  assumes P: "{x\<in>space M. P x} \<in> sets M"
hoelzl@47694
  1285
  shows "(\<lambda>x. if P x then f x else g x) \<in> measurable M M'"
hoelzl@47694
  1286
  unfolding measurable_def
hoelzl@47694
  1287
proof safe
hoelzl@47694
  1288
  fix x assume "x \<in> space M"
hoelzl@47694
  1289
  thus "(if P x then f x else g x) \<in> space M'"
hoelzl@47694
  1290
    using measure unfolding measurable_def by auto
hoelzl@47694
  1291
next
hoelzl@47694
  1292
  fix A assume "A \<in> sets M'"
hoelzl@47694
  1293
  hence *: "(\<lambda>x. if P x then f x else g x) -` A \<inter> space M =
hoelzl@47694
  1294
    ((f -` A \<inter> space M) \<inter> {x\<in>space M. P x}) \<union>
hoelzl@47694
  1295
    ((g -` A \<inter> space M) \<inter> (space M - {x\<in>space M. P x}))"
hoelzl@47694
  1296
    using measure unfolding measurable_def by (auto split: split_if_asm)
hoelzl@47694
  1297
  show "(\<lambda>x. if P x then f x else g x) -` A \<inter> space M \<in> sets M"
hoelzl@47694
  1298
    using `A \<in> sets M'` measure P unfolding * measurable_def
hoelzl@47694
  1299
    by (auto intro!: Un)
hoelzl@47694
  1300
qed
hoelzl@47694
  1301
hoelzl@47694
  1302
lemma measurable_If_set:
hoelzl@47694
  1303
  assumes measure: "f \<in> measurable M M'" "g \<in> measurable M M'"
hoelzl@49773
  1304
  assumes P: "A \<inter> space M \<in> sets M"
hoelzl@47694
  1305
  shows "(\<lambda>x. if x \<in> A then f x else g x) \<in> measurable M M'"
hoelzl@47694
  1306
proof (rule measurable_If[OF measure])
hoelzl@49773
  1307
  have "{x \<in> space M. x \<in> A} = A \<inter> space M" by auto
hoelzl@49773
  1308
  thus "{x \<in> space M. x \<in> A} \<in> sets M" using `A \<inter> space M \<in> sets M` by auto
hoelzl@47694
  1309
qed
hoelzl@47694
  1310
hoelzl@47694
  1311
lemma measurable_ident[intro, simp]: "id \<in> measurable M M"
hoelzl@47694
  1312
  by (auto simp add: measurable_def)
hoelzl@47694
  1313
hoelzl@50002
  1314
lemma measurable_ident'[intro, simp]: "(\<lambda>x. x) \<in> measurable M M"
hoelzl@50002
  1315
  by (auto simp add: measurable_def)
hoelzl@50002
  1316
hoelzl@47694
  1317
lemma measurable_comp[intro]:
hoelzl@47694
  1318
  fixes f :: "'a \<Rightarrow> 'b" and g :: "'b \<Rightarrow> 'c"
hoelzl@47694
  1319
  shows "f \<in> measurable a b \<Longrightarrow> g \<in> measurable b c \<Longrightarrow> (g o f) \<in> measurable a c"
hoelzl@47694
  1320
  apply (auto simp add: measurable_def vimage_compose)
hoelzl@47694
  1321
  apply (subgoal_tac "f -` g -` y \<inter> space a = f -` (g -` y \<inter> space b) \<inter> space a")
hoelzl@47694
  1322
  apply force+
hoelzl@47694
  1323
  done
hoelzl@47694
  1324
hoelzl@49782
  1325
lemma measurable_compose:
hoelzl@49782
  1326
  "f \<in> measurable M N \<Longrightarrow> g \<in> measurable N L \<Longrightarrow> (\<lambda>x. g (f x)) \<in> measurable M L"
hoelzl@49782
  1327
  using measurable_comp[of f M N g L] by (simp add: comp_def)
hoelzl@49782
  1328
hoelzl@50002
  1329
lemma sets_Least:
hoelzl@47694
  1330
  assumes meas: "\<And>i::nat. {x\<in>space M. P i x} \<in> M"
hoelzl@47694
  1331
  shows "(\<lambda>x. LEAST j. P j x) -` A \<inter> space M \<in> sets M"
hoelzl@47694
  1332
proof -
hoelzl@47694
  1333
  { fix i have "(\<lambda>x. LEAST j. P j x) -` {i} \<inter> space M \<in> sets M"
hoelzl@47694
  1334
    proof cases
hoelzl@47694
  1335
      assume i: "(LEAST j. False) = i"
hoelzl@47694
  1336
      have "(\<lambda>x. LEAST j. P j x) -` {i} \<inter> space M =
hoelzl@47694
  1337
        {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
  1338
        by (simp add: set_eq_iff, safe)
hoelzl@47694
  1339
           (insert i, auto dest: Least_le intro: LeastI intro!: Least_equality)
hoelzl@47694
  1340
      with meas show ?thesis
hoelzl@47694
  1341
        by (auto intro!: Int)
hoelzl@47694
  1342
    next
hoelzl@47694
  1343
      assume i: "(LEAST j. False) \<noteq> i"
hoelzl@47694
  1344
      then have "(\<lambda>x. LEAST j. P j x) -` {i} \<inter> space M =
hoelzl@47694
  1345
        {x\<in>space M. P i x} \<inter> (space M - (\<Union>j<i. {x\<in>space M. P j x}))"
hoelzl@47694
  1346
      proof (simp add: set_eq_iff, safe)
hoelzl@47694
  1347
        fix x assume neq: "(LEAST j. False) \<noteq> (LEAST j. P j x)"
hoelzl@47694
  1348
        have "\<exists>j. P j x"
hoelzl@47694
  1349
          by (rule ccontr) (insert neq, auto)
hoelzl@47694
  1350
        then show "P (LEAST j. P j x) x" by (rule LeastI_ex)
hoelzl@47694
  1351
      qed (auto dest: Least_le intro!: Least_equality)
hoelzl@47694
  1352
      with meas show ?thesis
hoelzl@47694
  1353
        by auto
hoelzl@47694
  1354
    qed }
hoelzl@47694
  1355
  then have "(\<Union>i\<in>A. (\<lambda>x. LEAST j. P j x) -` {i} \<inter> space M) \<in> sets M"
hoelzl@47694
  1356
    by (intro countable_UN) auto
hoelzl@47694
  1357
  moreover have "(\<Union>i\<in>A. (\<lambda>x. LEAST j. P j x) -` {i} \<inter> space M) =
hoelzl@47694
  1358
    (\<lambda>x. LEAST j. P j x) -` A \<inter> space M" by auto
hoelzl@47694
  1359
  ultimately show ?thesis by auto
hoelzl@47694
  1360
qed
hoelzl@47694
  1361
hoelzl@47694
  1362
lemma measurable_strong:
hoelzl@47694
  1363
  fixes f :: "'a \<Rightarrow> 'b" and g :: "'b \<Rightarrow> 'c"
hoelzl@47694
  1364
  assumes f: "f \<in> measurable a b" and g: "g \<in> space b \<rightarrow> space c"
hoelzl@47694
  1365
      and t: "f ` (space a) \<subseteq> t"
hoelzl@47694
  1366
      and cb: "\<And>s. s \<in> sets c \<Longrightarrow> (g -` s) \<inter> t \<in> sets b"
hoelzl@47694
  1367
  shows "(g o f) \<in> measurable a c"
hoelzl@47694
  1368
proof -
hoelzl@47694
  1369
  have fab: "f \<in> (space a -> space b)"
hoelzl@47694
  1370
   and ba: "\<And>y. y \<in> sets b \<Longrightarrow> (f -` y) \<inter> (space a) \<in> sets a" using f
hoelzl@47694
  1371
     by (auto simp add: measurable_def)
hoelzl@47694
  1372
  have eq: "\<And>y. f -` g -` y \<inter> space a = f -` (g -` y \<inter> t) \<inter> space a" using t
hoelzl@47694
  1373
    by force
hoelzl@47694
  1374
  show ?thesis
hoelzl@47694
  1375
    apply (auto simp add: measurable_def vimage_compose)
hoelzl@47694
  1376
    apply (metis funcset_mem fab g)
hoelzl@47694
  1377
    apply (subst eq, metis ba cb)
hoelzl@47694
  1378
    done
hoelzl@47694
  1379
qed
hoelzl@47694
  1380
hoelzl@47694
  1381
lemma measurable_mono1:
hoelzl@47694
  1382
  "M' \<subseteq> Pow \<Omega> \<Longrightarrow> M \<subseteq> M' \<Longrightarrow>
hoelzl@47694
  1383
    measurable (measure_of \<Omega> M \<mu>) N \<subseteq> measurable (measure_of \<Omega> M' \<mu>') N"
hoelzl@47694
  1384
  using measure_of_subset[of M' \<Omega> M] by (auto simp add: measurable_def)
hoelzl@47694
  1385
hoelzl@50002
  1386
section {* Counting space *}
hoelzl@50002
  1387
hoelzl@50002
  1388
definition count_space :: "'a set \<Rightarrow> 'a measure" where
hoelzl@50002
  1389
  "count_space \<Omega> = measure_of \<Omega> (Pow \<Omega>) (\<lambda>A. if finite A then ereal (card A) else \<infinity>)"
hoelzl@50002
  1390
hoelzl@50002
  1391
lemma 
hoelzl@50002
  1392
  shows space_count_space[simp]: "space (count_space \<Omega>) = \<Omega>"
hoelzl@50002
  1393
    and sets_count_space[simp]: "sets (count_space \<Omega>) = Pow \<Omega>"
hoelzl@50002
  1394
  using sigma_sets_into_sp[of "Pow \<Omega>" \<Omega>]
hoelzl@50002
  1395
  by (auto simp: count_space_def)
hoelzl@50002
  1396
hoelzl@50002
  1397
lemma measurable_count_space_eq1[simp]:
hoelzl@50002
  1398
  "f \<in> measurable (count_space A) M \<longleftrightarrow> f \<in> A \<rightarrow> space M"
hoelzl@50002
  1399
 unfolding measurable_def by simp
hoelzl@50002
  1400
hoelzl@50002
  1401
lemma measurable_count_space_eq2:
hoelzl@50002
  1402
  assumes "finite A"
hoelzl@50002
  1403
  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
  1404
proof -
hoelzl@50002
  1405
  { fix X assume "X \<subseteq> A" "f \<in> space M \<rightarrow> A"
hoelzl@50002
  1406
    with `finite A` have "f -` X \<inter> space M = (\<Union>a\<in>X. f -` {a} \<inter> space M)" "finite X"
hoelzl@50002
  1407
      by (auto dest: finite_subset)
hoelzl@50002
  1408
    moreover assume "\<forall>a\<in>A. f -` {a} \<inter> space M \<in> sets M"
hoelzl@50002
  1409
    ultimately have "f -` X \<inter> space M \<in> sets M"
hoelzl@50002
  1410
      using `X \<subseteq> A` by (auto intro!: finite_UN simp del: UN_simps) }
hoelzl@50002
  1411
  then show ?thesis
hoelzl@50002
  1412
    unfolding measurable_def by auto
hoelzl@50002
  1413
qed
hoelzl@50002
  1414
hoelzl@50002
  1415
lemma measurable_compose_countable:
hoelzl@50002
  1416
  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
  1417
  shows "(\<lambda>x. f (g x) x) \<in> measurable M N"
hoelzl@50002
  1418
  unfolding measurable_def
hoelzl@50002
  1419
proof safe
hoelzl@50002
  1420
  fix x assume "x \<in> space M" then show "f (g x) x \<in> space N"
hoelzl@50002
  1421
    using f[THEN measurable_space] g[THEN measurable_space] by auto
hoelzl@50002
  1422
next
hoelzl@50002
  1423
  fix A assume A: "A \<in> sets N"
hoelzl@50002
  1424
  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
  1425
    by auto
hoelzl@50002
  1426
  also have "\<dots> \<in> sets M" using f[THEN measurable_sets, OF A] g[THEN measurable_sets]
hoelzl@50002
  1427
    by (auto intro!: countable_UN measurable_sets)
hoelzl@50002
  1428
  finally show "(\<lambda>x. f (g x) x) -` A \<inter> space M \<in> sets M" .
hoelzl@50002
  1429
qed
hoelzl@50002
  1430
hoelzl@50002
  1431
subsection {* Measurable method *}
hoelzl@50002
  1432
hoelzl@50002
  1433
lemma (in algebra) sets_Collect_finite_All:
hoelzl@50002
  1434
  assumes "\<And>i. i \<in> S \<Longrightarrow> {x\<in>\<Omega>. P i x} \<in> M" "finite S"
hoelzl@50002
  1435
  shows "{x\<in>\<Omega>. \<forall>i\<in>S. P i x} \<in> M"
hoelzl@50002
  1436
proof -
hoelzl@50002
  1437
  have "{x\<in>\<Omega>. \<forall>i\<in>S. P i x} = (if S = {} then \<Omega> else \<Inter>i\<in>S. {x\<in>\<Omega>. P i x})"
hoelzl@50002
  1438
    by auto
hoelzl@50002
  1439
  with assms show ?thesis by (auto intro!: sets_Collect_finite_All')
hoelzl@50002
  1440
qed
hoelzl@50002
  1441
hoelzl@50002
  1442
abbreviation "pred M P \<equiv> P \<in> measurable M (count_space (UNIV::bool set))"
hoelzl@50002
  1443
hoelzl@50002
  1444
lemma pred_def: "pred M P \<longleftrightarrow> {x\<in>space M. P x} \<in> sets M"
hoelzl@50002
  1445
proof
hoelzl@50002
  1446
  assume "pred M P"
hoelzl@50002
  1447
  then have "P -` {True} \<inter> space M \<in> sets M"
hoelzl@50002
  1448
    by (auto simp: measurable_count_space_eq2)
hoelzl@50002
  1449
  also have "P -` {True} \<inter> space M = {x\<in>space M. P x}" by auto
hoelzl@50002
  1450
  finally show "{x\<in>space M. P x} \<in> sets M" .
hoelzl@50002
  1451
next
hoelzl@50002
  1452
  assume P: "{x\<in>space M. P x} \<in> sets M"
hoelzl@50002
  1453
  moreover
hoelzl@50002
  1454
  { fix X
hoelzl@50002
  1455
    have "X \<in> Pow (UNIV :: bool set)" by simp
hoelzl@50002
  1456
    then have "P -` X \<inter> space M = {x\<in>space M. ((X = {True} \<longrightarrow> P x) \<and> (X = {False} \<longrightarrow> \<not> P x) \<and> X \<noteq> {})}"
hoelzl@50002
  1457
      unfolding UNIV_bool Pow_insert Pow_empty by auto
hoelzl@50002
  1458
    then have "P -` X \<inter> space M \<in> sets M"
hoelzl@50002
  1459
      by (auto intro!: sets_Collect_neg sets_Collect_imp sets_Collect_conj sets_Collect_const P) }
hoelzl@50002
  1460
  then show "pred M P"
hoelzl@50002
  1461
    by (auto simp: measurable_def)
hoelzl@50002
  1462
qed
hoelzl@50002
  1463
hoelzl@50002
  1464
lemma pred_sets1: "{x\<in>space M. P x} \<in> sets M \<Longrightarrow> f \<in> measurable N M \<Longrightarrow> pred N (\<lambda>x. P (f x))"
hoelzl@50002
  1465
  by (rule measurable_compose[where f=f and N=M]) (auto simp: pred_def)
hoelzl@50002
  1466
hoelzl@50002
  1467
lemma pred_sets2: "A \<in> sets N \<Longrightarrow> f \<in> measurable M N \<Longrightarrow> pred M (\<lambda>x. f x \<in> A)"
hoelzl@50002
  1468
  by (rule measurable_compose[where f=f and N=N]) (auto simp: pred_def Int_def[symmetric])
hoelzl@50002
  1469
hoelzl@50002
  1470
lemma measurable_count_space_const:
hoelzl@50002
  1471
  "(\<lambda>x. c) \<in> measurable M (count_space UNIV)"
hoelzl@50002
  1472
  by auto
hoelzl@50002
  1473
hoelzl@50002
  1474
lemma measurable_count_space:
hoelzl@50002
  1475
  "f \<in> measurable (count_space A) (count_space UNIV)"
hoelzl@50002
  1476
  by simp
hoelzl@50002
  1477
hoelzl@50002
  1478
lemma measurable_compose_rev:
hoelzl@50002
  1479
  assumes f: "f \<in> measurable L N" and g: "g \<in> measurable M L"
hoelzl@50002
  1480
  shows "(\<lambda>x. f (g x)) \<in> measurable M N"
hoelzl@50002
  1481
  using measurable_compose[OF g f] .
hoelzl@50002
  1482
hoelzl@50002
  1483
ML {*
hoelzl@50002
  1484
hoelzl@50002
  1485
structure Measurable =
hoelzl@50002
  1486
struct
hoelzl@50002
  1487
hoelzl@50002
  1488
datatype level = Concrete | Generic;
hoelzl@50002
  1489
hoelzl@50002
  1490
structure Data = Generic_Data
hoelzl@50002
  1491
(
hoelzl@50002
  1492
  type T = thm list * thm list;
hoelzl@50002
  1493
  val empty = ([], []);
hoelzl@50002
  1494
  val extend = I;
hoelzl@50002
  1495
  val merge = fn ((a, b), (c, d)) => (a @ c, b @ d);
hoelzl@50002
  1496
);
hoelzl@50002
  1497
hoelzl@50002
  1498
val debug =
hoelzl@50002
  1499
  Attrib.setup_config_bool @{binding measurable_debug} (K false)
hoelzl@50002
  1500
hoelzl@50002
  1501
val backtrack =
hoelzl@50002
  1502
  Attrib.setup_config_int @{binding measurable_backtrack} (K 40)
hoelzl@50002
  1503
hoelzl@50002
  1504
fun get lv = (case lv of Concrete => fst | Generic => snd) o Data.get o Context.Proof; 
hoelzl@50002
  1505
fun get_all ctxt = get Concrete ctxt @ get Generic ctxt;
hoelzl@50002
  1506
hoelzl@50002
  1507
fun update f lv = Data.map (case lv of Concrete => apfst f | Generic => apsnd f);
hoelzl@50002
  1508
fun add thms' = update (fn thms => thms @ thms');
hoelzl@50002
  1509
hoelzl@50002
  1510
fun TRYALL' tacs = fold_rev (curry op APPEND') tacs (K no_tac);
hoelzl@50002
  1511
hoelzl@50002
  1512
fun is_too_generic thm =
hoelzl@50002
  1513
  let 
hoelzl@50002
  1514
    val concl = concl_of thm
hoelzl@50002
  1515
    val concl' = HOLogic.dest_Trueprop concl handle TERM _ => concl
hoelzl@50002
  1516
  in is_Var (head_of concl') end
hoelzl@50002
  1517
hoelzl@50002
  1518
fun import_theorem thm = if is_too_generic thm then [] else
hoelzl@50002
  1519
  [thm] @ map_filter (try (fn th' => thm RS th'))
hoelzl@50002
  1520
    [@{thm measurable_compose_rev}, @{thm pred_sets1}, @{thm pred_sets2}, @{thm sets_into_space}];
hoelzl@50002
  1521
hoelzl@50002
  1522
fun add_thm (raw, lv) thm = add (if raw then [thm] else import_theorem thm) lv;
hoelzl@50002
  1523
hoelzl@50002
  1524
fun debug_tac ctxt msg f = if Config.get ctxt debug then K (print_tac (msg ())) THEN' f else f
hoelzl@50002
  1525
hoelzl@50002
  1526
fun TAKE n f thm = Seq.take n (f thm)
hoelzl@50002
  1527
hoelzl@50002
  1528
fun nth_hol_goal thm i =
hoelzl@50002
  1529
  HOLogic.dest_Trueprop (Logic.strip_imp_concl (strip_all_body (nth (prems_of thm) (i - 1))))
hoelzl@50002
  1530
hoelzl@50002
  1531
fun dest_measurable_fun t =
hoelzl@50002
  1532
  (case t of
hoelzl@50002
  1533
    (Const (@{const_name "Set.member"}, _) $ f $ (Const (@{const_name "measurable"}, _) $ _ $ _)) => f
hoelzl@50002
  1534
  | _ => raise (TERM ("not a measurability predicate", [t])))
hoelzl@50002
  1535
hoelzl@50002
  1536
fun indep (Bound i) t b = i < b orelse t <= i
hoelzl@50002
  1537
  | indep (f $ t) top bot = indep f top bot andalso indep t top bot
hoelzl@50002
  1538
  | indep (Abs (_,_,t)) top bot = indep t (top + 1) (bot + 1)
hoelzl@50002
  1539
  | indep _ _ _ = true;
hoelzl@50002
  1540
hoelzl@50002
  1541
fun cnt_prefixes ctxt (Abs (n, T, t)) = let
hoelzl@50002
  1542
      fun is_countable t = Type.of_sort (Proof_Context.tsig_of ctxt) (t, @{sort countable})
hoelzl@50002
  1543
      fun cnt_walk (Abs (ns, T, t)) Ts =
hoelzl@50002
  1544
          map (fn (t', t'') => (Abs (ns, T, t'), t'')) (cnt_walk t (T::Ts))
hoelzl@50002
  1545
        | cnt_walk (f $ g) Ts = let
hoelzl@50002
  1546
            val n = length Ts - 1
hoelzl@50002
  1547
          in
hoelzl@50002
  1548
            map (fn (f', t) => (f' $ g, t)) (cnt_walk f Ts) @
hoelzl@50002
  1549
            map (fn (g', t) => (f $ g', t)) (cnt_walk g Ts) @
hoelzl@50002
  1550
            (if is_countable (fastype_of1 (Ts, g)) andalso loose_bvar1 (g, n)
hoelzl@50002
  1551
                andalso indep g n 0 andalso g <> Bound n
hoelzl@50002
  1552
              then [(f $ Bound (n + 1), incr_boundvars (~ n) g)]
hoelzl@50002
  1553
              else [])
hoelzl@50002
  1554
          end
hoelzl@50002
  1555
        | cnt_walk _ _ = []
hoelzl@50002
  1556
    in map (fn (t1, t2) => let
hoelzl@50002
  1557
        val T1 = fastype_of1 ([T], t2)
hoelzl@50002
  1558
        val T2 = fastype_of1 ([T], t)
hoelzl@50002
  1559
      in ([SOME (Abs (n, T1, Abs (n, T, t1))), NONE, NONE, SOME (Abs (n, T, t2))],
hoelzl@50002
  1560
        [SOME T1, SOME T, SOME T2])
hoelzl@50002
  1561
      end) (cnt_walk t [T])
hoelzl@50002
  1562
    end
hoelzl@50002
  1563
  | cnt_prefixes _ _ = []
hoelzl@50002
  1564
hoelzl@50002
  1565
val split_fun_tac =
hoelzl@50002
  1566
  Subgoal.FOCUS (fn {context = ctxt, ...} => SUBGOAL (fn (t, i) =>
hoelzl@50002
  1567
    let
hoelzl@50002
  1568
      val f = dest_measurable_fun (HOLogic.dest_Trueprop t)
hoelzl@50002
  1569
      fun cert f = map (Option.map (f (Proof_Context.theory_of ctxt)))
hoelzl@50002
  1570
      fun inst t (ts, Ts) = Drule.instantiate' (cert ctyp_of Ts) (cert cterm_of ts) t
hoelzl@50002
  1571
      val cps = cnt_prefixes ctxt f |> map (inst @{thm measurable_compose_countable})
hoelzl@50002
  1572
    in if null cps then no_tac else debug_tac ctxt (K "split fun") (resolve_tac cps) i end
hoelzl@50002
  1573
    handle TERM _ => no_tac) 1)
hoelzl@50002
  1574
hoelzl@50002
  1575
fun single_measurable_tac ctxt facts =
hoelzl@50002
  1576
  debug_tac ctxt (fn () => "single + " ^ Pretty.str_of (Pretty.block (map (Syntax.pretty_term ctxt o prop_of) facts)))
hoelzl@50002
  1577
  (resolve_tac ((maps (import_theorem o Simplifier.norm_hhf) facts) @ get_all ctxt)
hoelzl@50002
  1578
    APPEND' (split_fun_tac ctxt));
hoelzl@50002
  1579
hoelzl@50002
  1580
fun is_cond_formlua n thm = if length (prems_of thm) < n then false else
hoelzl@50002
  1581
  (case nth_hol_goal thm n of
hoelzl@50002
  1582
    (Const (@{const_name "Set.member"}, _) $ _ $ (Const (@{const_name "sets"}, _) $ _)) => false
hoelzl@50002
  1583
  | (Const (@{const_name "Set.member"}, _) $ _ $ (Const (@{const_name "measurable"}, _) $ _ $ _)) => false
hoelzl@50002
  1584
  | _ => true)
hoelzl@50002
  1585
  handle TERM _ => true;
hoelzl@50002
  1586
hoelzl@50002
  1587
fun measurable_tac' ctxt ss facts n =
hoelzl@50002
  1588
  TAKE (Config.get ctxt backtrack)
hoelzl@50002
  1589
  ((single_measurable_tac ctxt facts THEN'
hoelzl@50002
  1590
   REPEAT o (single_measurable_tac ctxt facts APPEND'
hoelzl@50002
  1591
             SOLVED' (fn n => COND (is_cond_formlua n) (debug_tac ctxt (K "simp") (asm_full_simp_tac ss) n) no_tac))) n);
hoelzl@50002
  1592
hoelzl@50002
  1593
fun measurable_tac ctxt = measurable_tac' ctxt (simpset_of ctxt);
hoelzl@50002
  1594
hoelzl@50002
  1595
val attr_add = Thm.declaration_attribute o add_thm;
hoelzl@50002
  1596
hoelzl@50002
  1597
val attr : attribute context_parser =
hoelzl@50002
  1598
  Scan.lift (Scan.optional (Args.parens (Scan.optional (Args.$$$ "raw" >> K true) false --
hoelzl@50002
  1599
     Scan.optional (Args.$$$ "generic" >> K Generic) Concrete)) (false, Concrete) >> attr_add);
hoelzl@50002
  1600
hoelzl@50002
  1601
val method : (Proof.context -> Method.method) context_parser =
hoelzl@50002
  1602
  Scan.lift (Scan.succeed (fn ctxt => METHOD (fn facts => measurable_tac ctxt facts 1)));
hoelzl@50002
  1603
hoelzl@50002
  1604
fun simproc ss redex = let
hoelzl@50002
  1605
    val ctxt = Simplifier.the_context ss;
hoelzl@50002
  1606
    val t = HOLogic.mk_Trueprop (term_of redex);
hoelzl@50002
  1607
    fun tac {context = ctxt, ...} =
hoelzl@50002
  1608
      SOLVE (measurable_tac' ctxt ss (Simplifier.prems_of ss) 1);
hoelzl@50002
  1609
  in try (fn () => Goal.prove ctxt [] [] t tac RS @{thm Eq_TrueI}) () end;
hoelzl@50002
  1610
hoelzl@50002
  1611
end
hoelzl@50002
  1612
hoelzl@50002
  1613
*}
hoelzl@50002
  1614
hoelzl@50002
  1615
attribute_setup measurable = {* Measurable.attr *} "declaration of measurability theorems"
hoelzl@50002
  1616
method_setup measurable = {* Measurable.method *} "measurability prover"
hoelzl@50002
  1617
simproc_setup measurable ("A \<in> sets M" | "f \<in> measurable M N") = {* K Measurable.simproc *}
hoelzl@50002
  1618
hoelzl@50002
  1619
declare
hoelzl@50002
  1620
  top[measurable]
hoelzl@50002
  1621
  empty_sets[measurable (raw)]
hoelzl@50002
  1622
  Un[measurable (raw)]
hoelzl@50002
  1623
  Diff[measurable (raw)]
hoelzl@50002
  1624
hoelzl@50002
  1625
declare
hoelzl@50002
  1626
  measurable_count_space[measurable (raw)]
hoelzl@50002
  1627
  measurable_ident[measurable (raw)]
hoelzl@50002
  1628
  measurable_ident'[measurable (raw)]
hoelzl@50002
  1629
  measurable_count_space_const[measurable (raw)]
hoelzl@50002
  1630
  measurable_const[measurable (raw)]
hoelzl@50002
  1631
  measurable_If[measurable (raw)]
hoelzl@50002
  1632
  measurable_comp[measurable (raw)]
hoelzl@50002
  1633
  measurable_sets[measurable (raw)]
hoelzl@50002
  1634
hoelzl@50002
  1635
lemma predE[measurable (raw)]: 
hoelzl@50002
  1636
  "pred M P \<Longrightarrow> {x\<in>space M. P x} \<in> sets M"
hoelzl@50002
  1637
  unfolding pred_def .
hoelzl@50002
  1638
hoelzl@50002
  1639
lemma pred_intros_imp'[measurable (raw)]:
hoelzl@50002
  1640
  "(K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. K \<longrightarrow> P x)"
hoelzl@50002
  1641
  by (cases K) auto
hoelzl@50002
  1642
hoelzl@50002
  1643
lemma pred_intros_conj1'[measurable (raw)]:
hoelzl@50002
  1644
  "(K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. K \<and> P x)"
hoelzl@50002
  1645
  by (cases K) auto
hoelzl@50002
  1646
hoelzl@50002
  1647
lemma pred_intros_conj2'[measurable (raw)]:
hoelzl@50002
  1648
  "(K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. P x \<and> K)"
hoelzl@50002
  1649
  by (cases K) auto
hoelzl@50002
  1650
hoelzl@50002
  1651
lemma pred_intros_disj1'[measurable (raw)]:
hoelzl@50002
  1652
  "(\<not> K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. K \<or> P x)"
hoelzl@50002
  1653
  by (cases K) auto
hoelzl@50002
  1654
hoelzl@50002
  1655
lemma pred_intros_disj2'[measurable (raw)]:
hoelzl@50002
  1656
  "(\<not> K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. P x \<or> K)"
hoelzl@50002
  1657
  by (cases K) auto
hoelzl@50002
  1658
hoelzl@50002
  1659
lemma pred_intros_logic[measurable (raw)]:
hoelzl@50002
  1660
  "pred M (\<lambda>x. x \<in> space M)"
hoelzl@50002
  1661
  "pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. \<not> P x)"
hoelzl@50002
  1662
  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x \<and> P x)"
hoelzl@50002
  1663
  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x \<longrightarrow> P x)"
hoelzl@50002
  1664
  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x \<or> P x)"
hoelzl@50002
  1665
  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x = P x)"
hoelzl@50002
  1666
  "pred M (\<lambda>x. f x \<in> UNIV)"
hoelzl@50002
  1667
  "pred M (\<lambda>x. f x \<in> {})"
hoelzl@50002
  1668
  "pred M (\<lambda>x. f x \<in> (B x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> - (B x))"
hoelzl@50002
  1669
  "pred M (\<lambda>x. f x \<in> (A x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> (B x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> (A x) - (B x))"
hoelzl@50002
  1670
  "pred M (\<lambda>x. f x \<in> (A x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> (B x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> (A x) \<inter> (B x))"
hoelzl@50002
  1671
  "pred M (\<lambda>x. f x \<in> (A x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> (B x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> (A x) \<union> (B x))"
hoelzl@50002
  1672
  "pred M (\<lambda>x. g x (f x) \<in> (X x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> (g x) -` (X x))"
hoelzl@50002
  1673
  by (auto intro!: sets_Collect simp: iff_conv_conj_imp pred_def)
hoelzl@50002
  1674
hoelzl@50002
  1675
lemma pred_intros_countable[measurable (raw)]:
hoelzl@50002
  1676
  fixes P :: "'a \<Rightarrow> 'i :: countable \<Rightarrow> bool"
hoelzl@50002
  1677
  shows 
hoelzl@50002
  1678
    "(\<And>i. pred M (\<lambda>x. P x i)) \<Longrightarrow> pred M (\<lambda>x. \<forall>i. P x i)"
hoelzl@50002
  1679
    "(\<And>i. pred M (\<lambda>x. P x i)) \<Longrightarrow> pred M (\<lambda>x. \<exists>i. P x i)"
hoelzl@50002
  1680
  by (auto intro!: sets_Collect_countable_All sets_Collect_countable_Ex simp: pred_def)
hoelzl@50002
  1681
hoelzl@50002
  1682
lemma pred_intros_countable_bounded[measurable (raw)]:
hoelzl@50002
  1683
  fixes X :: "'i :: countable set"
hoelzl@50002
  1684
  shows 
hoelzl@50002
  1685
    "(\<And>i. i \<in> X \<Longrightarrow> pred M (\<lambda>x. x \<in> N x i)) \<Longrightarrow> pred M (\<lambda>x. x \<in> (\<Inter>i\<in>X. N x i))"
hoelzl@50002
  1686
    "(\<And>i. i \<in> X \<Longrightarrow> pred M (\<lambda>x. x \<in> N x i)) \<Longrightarrow> pred M (\<lambda>x. x \<in> (\<Union>i\<in>X. N x i))"
hoelzl@50002
  1687
    "(\<And>i. i \<in> X \<Longrightarrow> pred M (\<lambda>x. P x i)) \<Longrightarrow> pred M (\<lambda>x. \<forall>i\<in>X. P x i)"
hoelzl@50002
  1688
    "(\<And>i. i \<in> X \<Longrightarrow> pred M (\<lambda>x. P x i)) \<Longrightarrow> pred M (\<lambda>x. \<exists>i\<in>X. P x i)"
hoelzl@50002
  1689
  by (auto simp: Bex_def Ball_def)
hoelzl@50002
  1690
hoelzl@50002
  1691
lemma pred_intros_finite[measurable (raw)]:
hoelzl@50002
  1692
  "finite I \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> pred M (\<lambda>x. x \<in> N x i)) \<Longrightarrow> pred M (\<lambda>x. x \<in> (\<Inter>i\<in>I. N x i))"
hoelzl@50002
  1693
  "finite I \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> pred M (\<lambda>x. x \<in> N x i)) \<Longrightarrow> pred M (\<lambda>x. x \<in> (\<Union>i\<in>I. N x i))"
hoelzl@50002
  1694
  "finite I \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> pred M (\<lambda>x. P x i)) \<Longrightarrow> pred M (\<lambda>x. \<forall>i\<in>I. P x i)"
hoelzl@50002
  1695
  "finite I \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> pred M (\<lambda>x. P x i)) \<Longrightarrow> pred M (\<lambda>x. \<exists>i\<in>I. P x i)"
hoelzl@50002
  1696
  by (auto intro!: sets_Collect_finite_Ex sets_Collect_finite_All simp: iff_conv_conj_imp pred_def)
hoelzl@50002
  1697
hoelzl@50002
  1698
lemma countable_Un_Int[measurable (raw)]:
hoelzl@50002
  1699
  "(\<And>i :: 'i :: countable. i \<in> I \<Longrightarrow> N i \<in> sets M) \<Longrightarrow> (\<Union>i\<in>I. N i) \<in> sets M"
hoelzl@50002
  1700
  "I \<noteq> {} \<Longrightarrow> (\<And>i :: 'i :: countable. i \<in> I \<Longrightarrow> N i \<in> sets M) \<Longrightarrow> (\<Inter>i\<in>I. N i) \<in> sets M"
hoelzl@50002
  1701
  by auto
hoelzl@50002
  1702
hoelzl@50002
  1703
declare
hoelzl@50002
  1704
  finite_UN[measurable (raw)]
hoelzl@50002
  1705
  finite_INT[measurable (raw)]
hoelzl@50002
  1706
hoelzl@50002
  1707
lemma sets_Int_pred[measurable (raw)]:
hoelzl@50002
  1708
  assumes space: "A \<inter> B \<subseteq> space M" and [measurable]: "pred M (\<lambda>x. x \<in> A)" "pred M (\<lambda>x. x \<in> B)"
hoelzl@50002
  1709
  shows "A \<inter> B \<in> sets M"
hoelzl@50002
  1710
proof -
hoelzl@50002
  1711
  have "{x\<in>space M. x \<in> A \<inter> B} \<in> sets M" by auto
hoelzl@50002
  1712
  also have "{x\<in>space M. x \<in> A \<inter> B} = A \<inter> B"
hoelzl@50002
  1713
    using space by auto
hoelzl@50002
  1714
  finally show ?thesis .
hoelzl@50002
  1715
qed
hoelzl@50002
  1716
hoelzl@50002
  1717
lemma [measurable (raw generic)]:
hoelzl@50002
  1718
  assumes f: "f \<in> measurable M N" and c: "{c} \<in> sets N"
hoelzl@50002
  1719
  shows pred_eq_const1: "pred M (\<lambda>x. f x = c)"
hoelzl@50002
  1720
    and pred_eq_const2: "pred M (\<lambda>x. c = f x)"
hoelzl@50002
  1721
  using measurable_sets[OF f c] by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50002
  1722
hoelzl@50002
  1723
lemma pred_le_const[measurable (raw generic)]:
hoelzl@50002
  1724
  assumes f: "f \<in> measurable M N" and c: "{.. c} \<in> sets N" shows "pred M (\<lambda>x. f x \<le> c)"
hoelzl@50002
  1725
  using measurable_sets[OF f c]
hoelzl@50002
  1726
  by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50002
  1727
hoelzl@50002
  1728
lemma pred_const_le[measurable (raw generic)]:
hoelzl@50002
  1729
  assumes f: "f \<in> measurable M N" and c: "{c ..} \<in> sets N" shows "pred M (\<lambda>x. c \<le> f x)"
hoelzl@50002
  1730
  using measurable_sets[OF f c]
hoelzl@50002
  1731
  by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50002
  1732
hoelzl@50002
  1733
lemma pred_less_const[measurable (raw generic)]:
hoelzl@50002
  1734
  assumes f: "f \<in> measurable M N" and c: "{..< c} \<in> sets N" shows "pred M (\<lambda>x. f x < c)"
hoelzl@50002
  1735
  using measurable_sets[OF f c]
hoelzl@50002
  1736
  by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50002
  1737
hoelzl@50002
  1738
lemma pred_const_less[measurable (raw generic)]:
hoelzl@50002
  1739
  assumes f: "f \<in> measurable M N" and c: "{c <..} \<in> sets N" shows "pred M (\<lambda>x. c < f x)"
hoelzl@50002
  1740
  using measurable_sets[OF f c]
hoelzl@50002
  1741
  by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50002
  1742
hoelzl@50002
  1743
declare
hoelzl@50002
  1744
  Int[measurable (raw)]
hoelzl@50002
  1745
hoelzl@50002
  1746
hide_const (open) pred
hoelzl@50002
  1747
hoelzl@47694
  1748
subsection {* Extend measure *}
hoelzl@47694
  1749
hoelzl@47694
  1750
definition "extend_measure \<Omega> I G \<mu> =
hoelzl@47694
  1751
  (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
  1752
      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
  1753
      else measure_of \<Omega> (G`I) (\<lambda>_. 0))"
hoelzl@47694
  1754
hoelzl@47694
  1755
lemma space_extend_measure: "G ` I \<subseteq> Pow \<Omega> \<Longrightarrow> space (extend_measure \<Omega> I G \<mu>) = \<Omega>"
hoelzl@47694
  1756
  unfolding extend_measure_def by simp
hoelzl@47694
  1757
hoelzl@47694
  1758
lemma sets_extend_measure: "G ` I \<subseteq> Pow \<Omega> \<Longrightarrow> sets (extend_measure \<Omega> I G \<mu>) = sigma_sets \<Omega> (G`I)"
hoelzl@47694
  1759
  unfolding extend_measure_def by simp
hoelzl@47694
  1760
hoelzl@47694
  1761
lemma emeasure_extend_measure:
hoelzl@47694
  1762
  assumes M: "M = extend_measure \<Omega> I G \<mu>"
hoelzl@47694
  1763
    and eq: "\<And>i. i \<in> I \<Longrightarrow> \<mu>' (G i) = \<mu> i"
hoelzl@47694
  1764
    and ms: "G ` I \<subseteq> Pow \<Omega>" "positive (sets M) \<mu>'" "countably_additive (sets M) \<mu>'"
hoelzl@47694
  1765
    and "i \<in> I"
hoelzl@47694
  1766
  shows "emeasure M (G i) = \<mu> i"
hoelzl@47694
  1767
proof cases
hoelzl@47694
  1768
  assume *: "(\<forall>i\<in>I. \<mu> i = 0)"
hoelzl@47694
  1769
  with M have M_eq: "M = measure_of \<Omega> (G`I) (\<lambda>_. 0)"
hoelzl@47694
  1770
   by (simp add: extend_measure_def)
hoelzl@47694
  1771
  from measure_space_0[OF ms(1)] ms `i\<in>I`
hoelzl@47694
  1772
  have "emeasure M (G i) = 0"
hoelzl@47694
  1773
    by (intro emeasure_measure_of[OF M_eq]) (auto simp add: M measure_space_def sets_extend_measure)
hoelzl@47694
  1774
  with `i\<in>I` * show ?thesis
hoelzl@47694
  1775
    by simp
hoelzl@47694
  1776
next
hoelzl@47694
  1777
  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
  1778
  assume "\<not> (\<forall>i\<in>I. \<mu> i = 0)"
hoelzl@47694
  1779
  moreover
hoelzl@47694
  1780
  have "measure_space (space M) (sets M) \<mu>'"
hoelzl@47694
  1781
    using ms unfolding measure_space_def by auto default
hoelzl@47694
  1782
  with ms eq have "\<exists>\<mu>'. P \<mu>'"
hoelzl@47694
  1783
    unfolding P_def
hoelzl@47694
  1784
    by (intro exI[of _ \<mu>']) (auto simp add: M space_extend_measure sets_extend_measure)
hoelzl@47694
  1785
  ultimately have M_eq: "M = measure_of \<Omega> (G`I) (Eps P)"
hoelzl@47694
  1786
    by (simp add: M extend_measure_def P_def[symmetric])
hoelzl@47694
  1787
hoelzl@47694
  1788
  from `\<exists>\<mu>'. P \<mu>'` have P: "P (Eps P)" by (rule someI_ex)
hoelzl@47694
  1789
  show "emeasure M (G i) = \<mu> i"
hoelzl@47694
  1790
  proof (subst emeasure_measure_of[OF M_eq])
hoelzl@47694
  1791
    have sets_M: "sets M = sigma_sets \<Omega> (G`I)"
hoelzl@47694
  1792
      using M_eq ms by (auto simp: sets_extend_measure)
hoelzl@47694
  1793
    then show "G i \<in> sets M" using `i \<in> I` by auto
hoelzl@47694
  1794
    show "positive (sets M) (Eps P)" "countably_additive (sets M) (Eps P)" "Eps P (G i) = \<mu> i"
hoelzl@47694
  1795
      using P `i\<in>I` by (auto simp add: sets_M measure_space_def P_def)
hoelzl@47694
  1796
  qed fact
hoelzl@47694
  1797
qed
hoelzl@47694
  1798
hoelzl@47694
  1799
lemma emeasure_extend_measure_Pair:
hoelzl@47694
  1800
  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
  1801
    and eq: "\<And>i j. I i j \<Longrightarrow> \<mu>' (G i j) = \<mu> i j"
hoelzl@47694
  1802
    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
  1803
    and "I i j"
hoelzl@47694
  1804
  shows "emeasure M (G i j) = \<mu> i j"
hoelzl@47694
  1805
  using emeasure_extend_measure[OF M _ _ ms(2,3), of "(i,j)"] eq ms(1) `I i j`
hoelzl@47694
  1806
  by (auto simp: subset_eq)
hoelzl@47694
  1807
hoelzl@39090
  1808
subsection {* Sigma algebra generated by function preimages *}
hoelzl@39090
  1809
hoelzl@47694
  1810
definition
hoelzl@47694
  1811
  "vimage_algebra M S f = sigma S ((\<lambda>A. f -` A \<inter> S) ` sets M)"
hoelzl@39090
  1812
hoelzl@47694
  1813
lemma sigma_algebra_preimages:
hoelzl@40859
  1814
  fixes f :: "'x \<Rightarrow> 'a"
hoelzl@47694
  1815
  assumes "f \<in> S \<rightarrow> space M"
hoelzl@47694
  1816
  shows "sigma_algebra S ((\<lambda>A. f -` A \<inter> S) ` sets M)"
hoelzl@47694
  1817
    (is "sigma_algebra _ (?F ` sets M)")
hoelzl@40859
  1818
proof (simp add: sigma_algebra_iff2, safe)
hoelzl@40859
  1819
  show "{} \<in> ?F ` sets M" by blast
hoelzl@40859
  1820
next
hoelzl@47694
  1821
  fix A assume "A \<in> sets M"
hoelzl@47694
  1822
  moreover have "S - ?F A = ?F (space M - A)"
hoelzl@40859
  1823
    using assms by auto
hoelzl@47694
  1824
  ultimately show "S - ?F A \<in> ?F ` sets M"
hoelzl@40859
  1825
    by blast
hoelzl@40859
  1826
next
hoelzl@47694
  1827
  fix A :: "nat \<Rightarrow> 'x set" assume *: "range A \<subseteq> ?F ` M"
hoelzl@47694
  1828
  have "\<forall>i. \<exists>b. b \<in> M \<and> A i = ?F b"
hoelzl@40859
  1829
  proof safe
hoelzl@40859
  1830
    fix i
hoelzl@47694
  1831
    have "A i \<in> ?F ` M" using * by auto
hoelzl@47694
  1832
    then show "\<exists>b. b \<in> M \<and> A i = ?F b" by auto
hoelzl@40859
  1833
  qed
hoelzl@47694
  1834
  from choice[OF this] obtain b where b: "range b \<subseteq> M" "\<And>i. A i = ?F (b i)"
hoelzl@40859
  1835
    by auto
hoelzl@47694
  1836
  then have "(\<Union>i. A i) = ?F (\<Union>i. b i)" by auto
hoelzl@47694
  1837
  then show "(\<Union>i. A i) \<in> ?F ` M" using b(1) by blast
hoelzl@40859
  1838
qed
hoelzl@40859
  1839
hoelzl@47694
  1840
lemma sets_vimage_algebra[simp]:
hoelzl@47694
  1841
  "f \<in> S \<rightarrow> space M \<Longrightarrow> sets (vimage_algebra M S f) = (\<lambda>A. f -` A \<inter> S) ` sets M"
hoelzl@47694
  1842
  using sigma_algebra.sets_measure_of_eq[OF sigma_algebra_preimages, of f S M]
hoelzl@47694
  1843
  by (simp add: vimage_algebra_def)
hoelzl@47694
  1844
hoelzl@47694
  1845
lemma space_vimage_algebra[simp]:
hoelzl@47694
  1846
  "f \<in> S \<rightarrow> space M \<Longrightarrow> space (vimage_algebra M S f) = S"
hoelzl@47694
  1847
  using sigma_algebra.space_measure_of_eq[OF sigma_algebra_preimages, of f S M]
hoelzl@47694
  1848
  by (simp add: vimage_algebra_def)
hoelzl@47694
  1849
hoelzl@47694
  1850
lemma in_vimage_algebra[simp]:
hoelzl@47694
  1851
  "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
  1852
  by (simp add: image_iff)
hoelzl@47694
  1853
hoelzl@47694
  1854
lemma measurable_vimage_algebra:
hoelzl@39090
  1855
  fixes S :: "'c set" assumes "f \<in> S \<rightarrow> space M"
hoelzl@47694
  1856
  shows "f \<in> measurable (vimage_algebra M S f) M"
hoelzl@47694
  1857
  unfolding measurable_def using assms by force
hoelzl@39090
  1858
hoelzl@47694
  1859
lemma measurable_vimage:
hoelzl@40859
  1860
  fixes g :: "'a \<Rightarrow> 'c" and f :: "'d \<Rightarrow> 'a"
hoelzl@40859
  1861
  assumes "g \<in> measurable M M2" "f \<in> S \<rightarrow> space M"
hoelzl@47694
  1862
  shows "(\<lambda>x. g (f x)) \<in> measurable (vimage_algebra M S f) M2"
hoelzl@40859
  1863
proof -
hoelzl@40859
  1864
  note measurable_vimage_algebra[OF assms(2)]
hoelzl@40859
  1865
  from measurable_comp[OF this assms(1)]
hoelzl@40859
  1866
  show ?thesis by (simp add: comp_def)
hoelzl@40859
  1867
qed
hoelzl@40859
  1868
hoelzl@40859
  1869
lemma sigma_sets_vimage:
hoelzl@40859
  1870
  assumes "f \<in> S' \<rightarrow> S" and "A \<subseteq> Pow S"
hoelzl@40859
  1871
  shows "sigma_sets S' ((\<lambda>X. f -` X \<inter> S') ` A) = (\<lambda>X. f -` X \<inter> S') ` sigma_sets S A"
hoelzl@40859
  1872
proof (intro set_eqI iffI)
hoelzl@40859
  1873
  let ?F = "\<lambda>X. f -` X \<inter> S'"
hoelzl@40859
  1874
  fix X assume "X \<in> sigma_sets S' (?F ` A)"
hoelzl@40859
  1875
  then show "X \<in> ?F ` sigma_sets S A"
hoelzl@40859
  1876
  proof induct
hoelzl@40859
  1877
    case (Basic X) then obtain X' where "X = ?F X'" "X' \<in> A"
hoelzl@40859
  1878
      by auto
hoelzl@47694
  1879
    then show ?case by auto
hoelzl@40859
  1880
  next
hoelzl@40859
  1881
    case Empty then show ?case
hoelzl@40859
  1882
      by (auto intro!: image_eqI[of _ _ "{}"] sigma_sets.Empty)
hoelzl@40859
  1883
  next
hoelzl@40859
  1884
    case (Compl X) then obtain X' where X: "X = ?F X'" and "X' \<in> sigma_sets S A"
hoelzl@40859
  1885
      by auto
hoelzl@40859
  1886
    then have "S - X' \<in> sigma_sets S A"
hoelzl@40859
  1887
      by (auto intro!: sigma_sets.Compl)
hoelzl@40859
  1888
    then show ?case
hoelzl@40859
  1889
      using X assms by (auto intro!: image_eqI[where x="S - X'"])
hoelzl@40859
  1890
  next
hoelzl@40859
  1891
    case (Union F)
hoelzl@40859
  1892
    then have "\<forall>i. \<exists>F'.  F' \<in> sigma_sets S A \<and> F i = f -` F' \<inter> S'"
hoelzl@40859
  1893
      by (auto simp: image_iff Bex_def)
hoelzl@40859
  1894
    from choice[OF this] obtain F' where
hoelzl@40859
  1895
      "\<And>i. F' i \<in> sigma_sets S A" and "\<And>i. F i = f -` F' i \<inter> S'"
hoelzl@40859
  1896
      by auto
hoelzl@40859
  1897
    then show ?case
hoelzl@40859
  1898
      by (auto intro!: sigma_sets.Union image_eqI[where x="\<Union>i. F' i"])
hoelzl@40859
  1899
  qed
hoelzl@40859
  1900
next
hoelzl@40859
  1901
  let ?F = "\<lambda>X. f -` X \<inter> S'"
hoelzl@40859
  1902
  fix X assume "X \<in> ?F ` sigma_sets S A"
hoelzl@40859
  1903
  then obtain X' where "X' \<in> sigma_sets S A" "X = ?F X'" by auto
hoelzl@40859
  1904
  then show "X \<in> sigma_sets S' (?F ` A)"
hoelzl@40859
  1905
  proof (induct arbitrary: X)
hoelzl@40859
  1906
    case Empty then show ?case by (auto intro: sigma_sets.Empty)
hoelzl@40859
  1907
  next
hoelzl@40859
  1908
    case (Compl X')
hoelzl@40859
  1909
    have "S' - (S' - X) \<in> sigma_sets S' (?F ` A)"
hoelzl@40859
  1910
      apply (rule sigma_sets.Compl)
hoelzl@40859
  1911
      using assms by (auto intro!: Compl.hyps simp: Compl.prems)
hoelzl@40859
  1912
    also have "S' - (S' - X) = X"
hoelzl@40859
  1913
      using assms Compl by auto
hoelzl@40859
  1914
    finally show ?case .
hoelzl@40859
  1915
  next
hoelzl@40859
  1916
    case (Union F)
hoelzl@40859
  1917
    have "(\<Union>i. f -` F i \<inter> S') \<in> sigma_sets S' (?F ` A)"
hoelzl@40859
  1918
      by (intro sigma_sets.Union Union.hyps) simp
hoelzl@40859
  1919
    also have "(\<Union>i. f -` F i \<inter> S') = X"
hoelzl@40859
  1920
      using assms Union by auto
hoelzl@40859
  1921
    finally show ?case .
hoelzl@47694
  1922
  qed auto
hoelzl@39092
  1923
qed
hoelzl@39092
  1924
hoelzl@38656
  1925
subsection {* A Two-Element Series *}
hoelzl@38656
  1926
hoelzl@38656
  1927
definition binaryset :: "'a set \<Rightarrow> 'a set \<Rightarrow> nat \<Rightarrow> 'a set "
hoelzl@38656
  1928
  where "binaryset A B = (\<lambda>\<^isup>x. {})(0 := A, Suc 0 := B)"
hoelzl@38656
  1929
hoelzl@38656
  1930
lemma range_binaryset_eq: "range(binaryset A B) = {A,B,{}}"
hoelzl@38656
  1931
  apply (simp add: binaryset_def)
nipkow@39302
  1932
  apply (rule set_eqI)
hoelzl@38656
  1933
  apply (auto simp add: image_iff)
hoelzl@38656
  1934
  done
hoelzl@38656
  1935
hoelzl@38656
  1936
lemma UN_binaryset_eq: "(\<Union>i. binaryset A B i) = A \<union> B"
haftmann@44106
  1937
  by (simp add: SUP_def range_binaryset_eq)
hoelzl@38656
  1938
hoelzl@38656
  1939
section {* Closed CDI *}
hoelzl@38656
  1940
hoelzl@47694
  1941
definition closed_cdi where
hoelzl@47694
  1942
  "closed_cdi \<Omega> M \<longleftrightarrow>
hoelzl@47694
  1943
   M \<subseteq> Pow \<Omega> &
hoelzl@47694
  1944
   (\<forall>s \<in> M. \<Omega> - s \<in> M) &
hoelzl@47694
  1945
   (\<forall>A. (range A \<subseteq> M) & (A 0 = {}) & (\<forall>n. A n \<subseteq> A (Suc n)) \<longrightarrow>
hoelzl@47694
  1946
        (\<Union>i. A i) \<in> M) &
hoelzl@47694
  1947
   (\<forall>A. (range A \<subseteq> M) & disjoint_family A \<longrightarrow> (\<Union>i::nat. A i) \<in> M)"
hoelzl@38656
  1948
hoelzl@38656
  1949
inductive_set
hoelzl@47694
  1950
  smallest_ccdi_sets :: "'a set \<Rightarrow> 'a set set \<Rightarrow> 'a set set"
hoelzl@47694
  1951
  for \<Omega> M
hoelzl@38656
  1952
  where
hoelzl@38656
  1953
    Basic [intro]:
hoelzl@47694
  1954
      "a \<in> M \<Longrightarrow> a \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1955
  | Compl [intro]:
hoelzl@47694
  1956
      "a \<in> smallest_ccdi_sets \<Omega> M \<Longrightarrow> \<Omega> - a \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1957
  | Inc:
hoelzl@47694
  1958
      "range A \<in> Pow(smallest_ccdi_sets \<Omega> M) \<Longrightarrow> A 0 = {} \<Longrightarrow> (\<And>n. A n \<subseteq> A (Suc n))
hoelzl@47694
  1959
       \<Longrightarrow> (\<Union>i. A i) \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1960
  | Disj:
hoelzl@47694
  1961
      "range A \<in> Pow(smallest_ccdi_sets \<Omega> M) \<Longrightarrow> disjoint_family A
hoelzl@47694
  1962
       \<Longrightarrow> (\<Union>i::nat. A i) \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  1963
hoelzl@47694
  1964
lemma (in subset_class) smallest_closed_cdi1: "M \<subseteq> smallest_ccdi_sets \<Omega> M"
hoelzl@47694
  1965
  by auto
hoelzl@38656
  1966
hoelzl@47694
  1967
lemma (in subset_class) smallest_ccdi_sets: "smallest_ccdi_sets \<Omega> M \<subseteq> Pow \<Omega>"
hoelzl@38656
  1968
  apply (rule subsetI)
hoelzl@38656
  1969
  apply (erule smallest_ccdi_sets.induct)
hoelzl@38656
  1970
  apply (auto intro: range_subsetD dest: sets_into_space)
hoelzl@38656
  1971
  done
hoelzl@38656
  1972
hoelzl@47694
  1973
lemma (in subset_class) smallest_closed_cdi2: "closed_cdi \<Omega> (smallest_ccdi_sets \<Omega> M)"
hoelzl@47694
  1974
  apply (auto simp add: closed_cdi_def smallest_ccdi_sets)
hoelzl@38656
  1975
  apply (blast intro: smallest_ccdi_sets.Inc smallest_ccdi_sets.Disj) +
hoelzl@38656
  1976
  done
hoelzl@38656
  1977
hoelzl@47694
  1978
lemma closed_cdi_subset: "closed_cdi \<Omega> M \<Longrightarrow> M \<subseteq> Pow \<Omega>"
hoelzl@38656
  1979
  by (simp add: closed_cdi_def)
hoelzl@38656
  1980
hoelzl@47694
  1981
lemma closed_cdi_Compl: "closed_cdi \<Omega> M \<Longrightarrow> s \<in> M \<Longrightarrow> \<Omega> - s \<in> M"
hoelzl@38656
  1982
  by (simp add: closed_cdi_def)
hoelzl@38656
  1983
hoelzl@38656
  1984
lemma closed_cdi_Inc:
hoelzl@47694
  1985
  "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
  1986
  by (simp add: closed_cdi_def)
hoelzl@38656
  1987
hoelzl@38656
  1988
lemma closed_cdi_Disj:
hoelzl@47694
  1989
  "closed_cdi \<Omega> M \<Longrightarrow> range A \<subseteq> M \<Longrightarrow> disjoint_family A \<Longrightarrow> (\<Union>i::nat. A i) \<in> M"
hoelzl@38656
  1990
  by (simp add: closed_cdi_def)
hoelzl@38656
  1991
hoelzl@38656
  1992
lemma closed_cdi_Un:
hoelzl@47694
  1993
  assumes cdi: "closed_cdi \<Omega> M" and empty: "{} \<in> M"
hoelzl@47694
  1994
      and A: "A \<in> M" and B: "B \<in> M"
hoelzl@38656
  1995
      and disj: "A \<inter> B = {}"
hoelzl@47694
  1996
    shows "A \<union> B \<in> M"
hoelzl@38656
  1997
proof -
hoelzl@47694
  1998
  have ra: "range (binaryset A B) \<subseteq> M"
hoelzl@38656
  1999
   by (simp add: range_binaryset_eq empty A B)
hoelzl@38656
  2000
 have di:  "disjoint_family (binaryset A B)" using disj
hoelzl@38656
  2001
   by (simp add: disjoint_family_on_def binaryset_def Int_commute)
hoelzl@38656
  2002
 from closed_cdi_Disj [OF cdi ra di]
hoelzl@38656
  2003
 show ?thesis
hoelzl@38656
  2004
   by (simp add: UN_binaryset_eq)
hoelzl@38656
  2005
qed
hoelzl@38656
  2006
hoelzl@38656
  2007
lemma (in algebra) smallest_ccdi_sets_Un:
hoelzl@47694
  2008
  assumes A: "A \<in> smallest_ccdi_sets \<Omega> M" and B: "B \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  2009
      and disj: "A \<inter> B = {}"
hoelzl@47694
  2010
    shows "A \<union> B \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  2011
proof -
hoelzl@47694
  2012
  have ra: "range (binaryset A B) \<in> Pow (smallest_ccdi_sets \<Omega> M)"
hoelzl@38656
  2013
    by (simp add: range_binaryset_eq  A B smallest_ccdi_sets.Basic)
hoelzl@38656
  2014
  have di:  "disjoint_family (binaryset A B)" using disj
hoelzl@38656
  2015
    by (simp add: disjoint_family_on_def binaryset_def Int_commute)
hoelzl@38656
  2016
  from Disj [OF ra di]
hoelzl@38656
  2017
  show ?thesis
hoelzl@38656
  2018
    by (simp add: UN_binaryset_eq)
hoelzl@38656
  2019
qed
hoelzl@38656
  2020
hoelzl@38656
  2021
lemma (in algebra) smallest_ccdi_sets_Int1:
hoelzl@47694
  2022
  assumes a: "a \<in> M"
hoelzl@47694
  2023
  shows "b \<in> smallest_ccdi_sets \<Omega> M \<Longrightarrow> a \<inter> b \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  2024
proof (induct rule: smallest_ccdi_sets.induct)
hoelzl@38656
  2025
  case (Basic x)
hoelzl@38656
  2026
  thus ?case
hoelzl@38656
  2027
    by (metis a Int smallest_ccdi_sets.Basic)
hoelzl@38656
  2028
next
hoelzl@38656
  2029
  case (Compl x)
hoelzl@47694
  2030
  have "a \<inter> (\<Omega> - x) = \<Omega> - ((\<Omega> - a) \<union> (a \<inter> x))"
hoelzl@38656
  2031
    by blast
hoelzl@47694
  2032
  also have "... \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  2033
    by (metis smallest_ccdi_sets.Compl a Compl(2) Diff_Int2 Diff_Int_distrib2
hoelzl@47694
  2034
           Diff_disjoint Int_Diff Int_empty_right smallest_ccdi_sets_Un
hoelzl@47694
  2035
           smallest_ccdi_sets.Basic smallest_ccdi_sets.Compl)
hoelzl@38656
  2036
  finally show ?case .
hoelzl@38656
  2037
next
hoelzl@38656
  2038
  case (Inc A)
hoelzl@38656
  2039
  have 1: "(\<Union>i. (\<lambda>i. a \<inter> A i) i) = a \<inter> (\<Union>i. A i)"
hoelzl@38656
  2040
    by blast
hoelzl@47694
  2041
  have "range (\<lambda>i. a \<inter> A i) \<in> Pow(smallest_ccdi_sets \<Omega> M)" using Inc
hoelzl@38656
  2042
    by blast
hoelzl@38656
  2043
  moreover have "(\<lambda>i. a \<inter> A i) 0 = {}"
hoelzl@38656
  2044
    by (simp add: Inc)
hoelzl@38656
  2045
  moreover have "!!n. (\<lambda>i. a \<inter> A i) n \<subseteq> (\<lambda>i. a \<inter> A i) (Suc n)" using Inc
hoelzl@38656
  2046
    by blast
hoelzl@47694
  2047
  ultimately have 2: "(\<Union>i. (\<lambda>i. a \<inter> A i) i) \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  2048
    by (rule smallest_ccdi_sets.Inc)
hoelzl@38656
  2049
  show ?case
hoelzl@38656
  2050
    by (metis 1 2)
hoelzl@38656
  2051
next
hoelzl@38656
  2052
  case (Disj A)
hoelzl@38656
  2053
  have 1: "(\<Union>i. (\<lambda>i. a \<inter> A i) i) = a \<inter> (\<Union>i. A i)"
hoelzl@38656
  2054
    by blast
hoelzl@47694
  2055
  have "range (\<lambda>i. a \<inter> A i) \<in> Pow(smallest_ccdi_sets \<Omega> M)" using Disj
hoelzl@38656
  2056
    by blast
hoelzl@38656
  2057
  moreover have "disjoint_family (\<lambda>i. a \<inter> A i)" using Disj
hoelzl@38656
  2058
    by (auto simp add: disjoint_family_on_def)
hoelzl@47694
  2059
  ultimately have 2: "(\<Union>i. (\<lambda>i. a \<inter> A i) i) \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  2060
    by (rule smallest_ccdi_sets.Disj)
hoelzl@38656
  2061
  show ?case
hoelzl@38656
  2062
    by (metis 1 2)
hoelzl@38656
  2063
qed
hoelzl@38656
  2064
hoelzl@38656
  2065
hoelzl@38656
  2066
lemma (in algebra) smallest_ccdi_sets_Int:
hoelzl@47694
  2067
  assumes b: "b \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@47694
  2068
  shows "a \<in> smallest_ccdi_sets \<Omega> M \<Longrightarrow> a \<inter> b \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  2069
proof (induct rule: smallest_ccdi_sets.induct)
hoelzl@38656
  2070
  case (Basic x)
hoelzl@38656
  2071
  thus ?case
hoelzl@38656
  2072
    by (metis b smallest_ccdi_sets_Int1)
hoelzl@38656
  2073
next
hoelzl@38656
  2074
  case (Compl x)
hoelzl@47694
  2075
  have "(\<Omega> - x) \<inter> b = \<Omega> - (x \<inter> b \<union> (\<Omega> - b))"
hoelzl@38656
  2076
    by blast
hoelzl@47694
  2077
  also have "... \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  2078
    by (metis Compl(2) Diff_disjoint Int_Diff Int_commute Int_empty_right b
hoelzl@38656
  2079
           smallest_ccdi_sets.Compl smallest_ccdi_sets_Un)
hoelzl@38656
  2080
  finally show ?case .
hoelzl@38656
  2081
next
hoelzl@38656
  2082
  case (Inc A)
hoelzl@38656
  2083
  have 1: "(\<Union>i. (\<lambda>i. A i \<inter> b) i) = (\<Union>i. A i) \<inter> b"
hoelzl@38656
  2084
    by blast
hoelzl@47694
  2085
  have "range (\<lambda>i. A i \<inter> b) \<in> Pow(smallest_ccdi_sets \<Omega> M)" using Inc
hoelzl@38656
  2086
    by blast
hoelzl@38656
  2087
  moreover have "(\<lambda>i. A i \<inter> b) 0 = {}"
hoelzl@38656
  2088
    by (simp add: Inc)
hoelzl@38656
  2089
  moreover have "!!n. (\<lambda>i. A i \<inter> b) n \<subseteq> (\<lambda>i. A i \<inter> b) (Suc n)" using Inc
hoelzl@38656
  2090
    by blast
hoelzl@47694
  2091
  ultimately have 2: "(\<Union>i. (\<lambda>i. A i \<inter> b) i) \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  2092
    by (rule smallest_ccdi_sets.Inc)
hoelzl@38656
  2093
  show ?case
hoelzl@38656
  2094
    by (metis 1 2)
hoelzl@38656
  2095
next
hoelzl@38656
  2096
  case (Disj A)
hoelzl@38656
  2097
  have 1: "(\<Union>i. (\<lambda>i. A i \<inter> b) i) = (\<Union>i. A i) \<inter> b"
hoelzl@38656
  2098
    by blast
hoelzl@47694
  2099
  have "range (\<lambda>i. A i \<inter> b) \<in> Pow(smallest_ccdi_sets \<Omega> M)" using Disj
hoelzl@38656
  2100
    by blast
hoelzl@38656
  2101
  moreover have "disjoint_family (\<lambda>i. A i \<inter> b)" using Disj
hoelzl@38656
  2102
    by (auto simp add: disjoint_family_on_def)
hoelzl@47694
  2103
  ultimately have 2: "(\<Union>i. (\<lambda>i. A i \<inter> b) i) \<in> smallest_ccdi_sets \<Omega> M"
hoelzl@38656
  2104
    by (rule smallest_ccdi_sets.Disj)
hoelzl@38656
  2105
  show ?case
hoelzl@38656
  2106
    by (metis 1 2)
hoelzl@38656
  2107
qed
hoelzl@38656
  2108
hoelzl@38656
  2109
lemma (in algebra) sigma_property_disjoint_lemma:
hoelzl@47694
  2110
  assumes sbC: "M \<subseteq> C"
hoelzl@47694
  2111
      and ccdi: "closed_cdi \<Omega> C"
hoelzl@47694
  2112
  shows "sigma_sets \<Omega> M \<subseteq> C"
hoelzl@38656
  2113
proof -
hoelzl@47694
  2114
  have "smallest_ccdi_sets \<Omega> M \<in> {B . M \<subseteq> B \<and> sigma_algebra \<Omega> B}"
hoelzl@38656
  2115
    apply (auto simp add: sigma_algebra_disjoint_iff algebra_iff_Int