src/HOL/Probability/Measurable.thy
author hoelzl
Thu Jan 15 15:04:51 2015 +0100 (2015-01-15)
changeset 59361 fd5da2434be4
parent 59353 f0707dc3d9aa
child 60172 423273355b55
permissions -rw-r--r--
piecewise measurability using restrict_space; cleanup Borel_Space
wenzelm@50530
     1
(*  Title:      HOL/Probability/Measurable.thy
hoelzl@50387
     2
    Author:     Johannes Hölzl <hoelzl@in.tum.de>
hoelzl@50387
     3
*)
hoelzl@50387
     4
theory Measurable
hoelzl@56021
     5
  imports
hoelzl@56021
     6
    Sigma_Algebra
hoelzl@56021
     7
    "~~/src/HOL/Library/Order_Continuity"
hoelzl@50387
     8
begin
hoelzl@50387
     9
hoelzl@56021
    10
hide_const (open) Order_Continuity.continuous
hoelzl@56021
    11
hoelzl@50387
    12
subsection {* Measurability prover *}
hoelzl@50387
    13
hoelzl@50387
    14
lemma (in algebra) sets_Collect_finite_All:
hoelzl@50387
    15
  assumes "\<And>i. i \<in> S \<Longrightarrow> {x\<in>\<Omega>. P i x} \<in> M" "finite S"
hoelzl@50387
    16
  shows "{x\<in>\<Omega>. \<forall>i\<in>S. P i x} \<in> M"
hoelzl@50387
    17
proof -
hoelzl@50387
    18
  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@50387
    19
    by auto
hoelzl@50387
    20
  with assms show ?thesis by (auto intro!: sets_Collect_finite_All')
hoelzl@50387
    21
qed
hoelzl@50387
    22
hoelzl@50387
    23
abbreviation "pred M P \<equiv> P \<in> measurable M (count_space (UNIV::bool set))"
hoelzl@50387
    24
hoelzl@50387
    25
lemma pred_def: "pred M P \<longleftrightarrow> {x\<in>space M. P x} \<in> sets M"
hoelzl@50387
    26
proof
hoelzl@50387
    27
  assume "pred M P"
hoelzl@50387
    28
  then have "P -` {True} \<inter> space M \<in> sets M"
hoelzl@50387
    29
    by (auto simp: measurable_count_space_eq2)
hoelzl@50387
    30
  also have "P -` {True} \<inter> space M = {x\<in>space M. P x}" by auto
hoelzl@50387
    31
  finally show "{x\<in>space M. P x} \<in> sets M" .
hoelzl@50387
    32
next
hoelzl@50387
    33
  assume P: "{x\<in>space M. P x} \<in> sets M"
hoelzl@50387
    34
  moreover
hoelzl@50387
    35
  { fix X
hoelzl@50387
    36
    have "X \<in> Pow (UNIV :: bool set)" by simp
hoelzl@50387
    37
    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@50387
    38
      unfolding UNIV_bool Pow_insert Pow_empty by auto
hoelzl@50387
    39
    then have "P -` X \<inter> space M \<in> sets M"
hoelzl@50387
    40
      by (auto intro!: sets.sets_Collect_neg sets.sets_Collect_imp sets.sets_Collect_conj sets.sets_Collect_const P) }
hoelzl@50387
    41
  then show "pred M P"
hoelzl@50387
    42
    by (auto simp: measurable_def)
hoelzl@50387
    43
qed
hoelzl@50387
    44
hoelzl@50387
    45
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@50387
    46
  by (rule measurable_compose[where f=f and N=M]) (auto simp: pred_def)
hoelzl@50387
    47
hoelzl@50387
    48
lemma pred_sets2: "A \<in> sets N \<Longrightarrow> f \<in> measurable M N \<Longrightarrow> pred M (\<lambda>x. f x \<in> A)"
hoelzl@50387
    49
  by (rule measurable_compose[where f=f and N=N]) (auto simp: pred_def Int_def[symmetric])
hoelzl@50387
    50
hoelzl@50387
    51
ML_file "measurable.ML"
hoelzl@50387
    52
wenzelm@53043
    53
attribute_setup measurable = {*
hoelzl@59047
    54
  Scan.lift (
hoelzl@59047
    55
    (Args.add >> K true || Args.del >> K false || Scan.succeed true) --
hoelzl@59047
    56
    Scan.optional (Args.parens (
hoelzl@59047
    57
      Scan.optional (Args.$$$ "raw" >> K true) false --
Andreas@58965
    58
      Scan.optional (Args.$$$ "generic" >> K Measurable.Generic) Measurable.Concrete))
hoelzl@59047
    59
    (false, Measurable.Concrete) >>
hoelzl@59047
    60
    Measurable.measurable_thm_attr)
wenzelm@53043
    61
*} "declaration of measurability theorems"
wenzelm@53043
    62
hoelzl@59047
    63
attribute_setup measurable_dest = Measurable.dest_thm_attr
hoelzl@59048
    64
  "add dest rule to measurability prover"
wenzelm@53043
    65
hoelzl@59048
    66
attribute_setup measurable_cong = Measurable.cong_thm_attr
hoelzl@59048
    67
  "add congurence rules to measurability prover"
wenzelm@53043
    68
hoelzl@59047
    69
method_setup measurable = \<open> Scan.lift (Scan.succeed (METHOD o Measurable.measurable_tac)) \<close>
hoelzl@59047
    70
  "measurability prover"
wenzelm@53043
    71
hoelzl@50387
    72
simproc_setup measurable ("A \<in> sets M" | "f \<in> measurable M N") = {* K Measurable.simproc *}
hoelzl@50387
    73
Andreas@58965
    74
setup {*
hoelzl@59048
    75
  Global_Theory.add_thms_dynamic (@{binding measurable}, Measurable.get_all)
Andreas@58965
    76
*}
hoelzl@59353
    77
  
hoelzl@50387
    78
declare
hoelzl@50387
    79
  pred_sets1[measurable_dest]
hoelzl@50387
    80
  pred_sets2[measurable_dest]
hoelzl@50387
    81
  sets.sets_into_space[measurable_dest]
hoelzl@50387
    82
hoelzl@50387
    83
declare
hoelzl@50387
    84
  sets.top[measurable]
hoelzl@50387
    85
  sets.empty_sets[measurable (raw)]
hoelzl@50387
    86
  sets.Un[measurable (raw)]
hoelzl@50387
    87
  sets.Diff[measurable (raw)]
hoelzl@50387
    88
hoelzl@50387
    89
declare
hoelzl@50387
    90
  measurable_count_space[measurable (raw)]
hoelzl@50387
    91
  measurable_ident[measurable (raw)]
hoelzl@59048
    92
  measurable_id[measurable (raw)]
hoelzl@50387
    93
  measurable_const[measurable (raw)]
hoelzl@50387
    94
  measurable_If[measurable (raw)]
hoelzl@50387
    95
  measurable_comp[measurable (raw)]
hoelzl@50387
    96
  measurable_sets[measurable (raw)]
hoelzl@50387
    97
hoelzl@59048
    98
declare measurable_cong_sets[measurable_cong]
hoelzl@59048
    99
declare sets_restrict_space_cong[measurable_cong]
hoelzl@59361
   100
declare sets_restrict_UNIV[measurable_cong]
hoelzl@59048
   101
hoelzl@50387
   102
lemma predE[measurable (raw)]: 
hoelzl@50387
   103
  "pred M P \<Longrightarrow> {x\<in>space M. P x} \<in> sets M"
hoelzl@50387
   104
  unfolding pred_def .
hoelzl@50387
   105
hoelzl@50387
   106
lemma pred_intros_imp'[measurable (raw)]:
hoelzl@50387
   107
  "(K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. K \<longrightarrow> P x)"
hoelzl@50387
   108
  by (cases K) auto
hoelzl@50387
   109
hoelzl@50387
   110
lemma pred_intros_conj1'[measurable (raw)]:
hoelzl@50387
   111
  "(K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. K \<and> P x)"
hoelzl@50387
   112
  by (cases K) auto
hoelzl@50387
   113
hoelzl@50387
   114
lemma pred_intros_conj2'[measurable (raw)]:
hoelzl@50387
   115
  "(K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. P x \<and> K)"
hoelzl@50387
   116
  by (cases K) auto
hoelzl@50387
   117
hoelzl@50387
   118
lemma pred_intros_disj1'[measurable (raw)]:
hoelzl@50387
   119
  "(\<not> K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. K \<or> P x)"
hoelzl@50387
   120
  by (cases K) auto
hoelzl@50387
   121
hoelzl@50387
   122
lemma pred_intros_disj2'[measurable (raw)]:
hoelzl@50387
   123
  "(\<not> K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. P x \<or> K)"
hoelzl@50387
   124
  by (cases K) auto
hoelzl@50387
   125
hoelzl@50387
   126
lemma pred_intros_logic[measurable (raw)]:
hoelzl@50387
   127
  "pred M (\<lambda>x. x \<in> space M)"
hoelzl@50387
   128
  "pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. \<not> P x)"
hoelzl@50387
   129
  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x \<and> P x)"
hoelzl@50387
   130
  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x \<longrightarrow> P x)"
hoelzl@50387
   131
  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x \<or> P x)"
hoelzl@50387
   132
  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x = P x)"
hoelzl@50387
   133
  "pred M (\<lambda>x. f x \<in> UNIV)"
hoelzl@50387
   134
  "pred M (\<lambda>x. f x \<in> {})"
hoelzl@50387
   135
  "pred M (\<lambda>x. P' (f x) x) \<Longrightarrow> pred M (\<lambda>x. f x \<in> {y. P' y x})"
hoelzl@50387
   136
  "pred M (\<lambda>x. f x \<in> (B x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> - (B x))"
hoelzl@50387
   137
  "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@50387
   138
  "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@50387
   139
  "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@50387
   140
  "pred M (\<lambda>x. g x (f x) \<in> (X x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> (g x) -` (X x))"
hoelzl@50387
   141
  by (auto simp: iff_conv_conj_imp pred_def)
hoelzl@50387
   142
hoelzl@50387
   143
lemma pred_intros_countable[measurable (raw)]:
hoelzl@50387
   144
  fixes P :: "'a \<Rightarrow> 'i :: countable \<Rightarrow> bool"
hoelzl@50387
   145
  shows 
hoelzl@50387
   146
    "(\<And>i. pred M (\<lambda>x. P x i)) \<Longrightarrow> pred M (\<lambda>x. \<forall>i. P x i)"
hoelzl@50387
   147
    "(\<And>i. pred M (\<lambda>x. P x i)) \<Longrightarrow> pred M (\<lambda>x. \<exists>i. P x i)"
hoelzl@50387
   148
  by (auto intro!: sets.sets_Collect_countable_All sets.sets_Collect_countable_Ex simp: pred_def)
hoelzl@50387
   149
hoelzl@50387
   150
lemma pred_intros_countable_bounded[measurable (raw)]:
hoelzl@50387
   151
  fixes X :: "'i :: countable set"
hoelzl@50387
   152
  shows 
hoelzl@50387
   153
    "(\<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@50387
   154
    "(\<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@50387
   155
    "(\<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@50387
   156
    "(\<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@50387
   157
  by (auto simp: Bex_def Ball_def)
hoelzl@50387
   158
hoelzl@50387
   159
lemma pred_intros_finite[measurable (raw)]:
hoelzl@50387
   160
  "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@50387
   161
  "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@50387
   162
  "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@50387
   163
  "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@50387
   164
  by (auto intro!: sets.sets_Collect_finite_Ex sets.sets_Collect_finite_All simp: iff_conv_conj_imp pred_def)
hoelzl@50387
   165
hoelzl@50387
   166
lemma countable_Un_Int[measurable (raw)]:
hoelzl@50387
   167
  "(\<And>i :: 'i :: countable. i \<in> I \<Longrightarrow> N i \<in> sets M) \<Longrightarrow> (\<Union>i\<in>I. N i) \<in> sets M"
hoelzl@50387
   168
  "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@50387
   169
  by auto
hoelzl@50387
   170
hoelzl@50387
   171
declare
hoelzl@50387
   172
  finite_UN[measurable (raw)]
hoelzl@50387
   173
  finite_INT[measurable (raw)]
hoelzl@50387
   174
hoelzl@50387
   175
lemma sets_Int_pred[measurable (raw)]:
hoelzl@50387
   176
  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@50387
   177
  shows "A \<inter> B \<in> sets M"
hoelzl@50387
   178
proof -
hoelzl@50387
   179
  have "{x\<in>space M. x \<in> A \<inter> B} \<in> sets M" by auto
hoelzl@50387
   180
  also have "{x\<in>space M. x \<in> A \<inter> B} = A \<inter> B"
hoelzl@50387
   181
    using space by auto
hoelzl@50387
   182
  finally show ?thesis .
hoelzl@50387
   183
qed
hoelzl@50387
   184
hoelzl@50387
   185
lemma [measurable (raw generic)]:
hoelzl@50387
   186
  assumes f: "f \<in> measurable M N" and c: "c \<in> space N \<Longrightarrow> {c} \<in> sets N"
hoelzl@50387
   187
  shows pred_eq_const1: "pred M (\<lambda>x. f x = c)"
hoelzl@50387
   188
    and pred_eq_const2: "pred M (\<lambda>x. c = f x)"
hoelzl@50387
   189
proof -
hoelzl@50387
   190
  show "pred M (\<lambda>x. f x = c)"
hoelzl@50387
   191
  proof cases
hoelzl@50387
   192
    assume "c \<in> space N"
hoelzl@50387
   193
    with measurable_sets[OF f c] show ?thesis
hoelzl@50387
   194
      by (auto simp: Int_def conj_commute pred_def)
hoelzl@50387
   195
  next
hoelzl@50387
   196
    assume "c \<notin> space N"
hoelzl@50387
   197
    with f[THEN measurable_space] have "{x \<in> space M. f x = c} = {}" by auto
hoelzl@50387
   198
    then show ?thesis by (auto simp: pred_def cong: conj_cong)
hoelzl@50387
   199
  qed
hoelzl@50387
   200
  then show "pred M (\<lambda>x. c = f x)"
hoelzl@50387
   201
    by (simp add: eq_commute)
hoelzl@50387
   202
qed
hoelzl@50387
   203
hoelzl@59000
   204
lemma pred_count_space_const1[measurable (raw)]:
hoelzl@59000
   205
  "f \<in> measurable M (count_space UNIV) \<Longrightarrow> Measurable.pred M (\<lambda>x. f x = c)"
hoelzl@59000
   206
  by (intro pred_eq_const1[where N="count_space UNIV"]) (auto )
hoelzl@59000
   207
hoelzl@59000
   208
lemma pred_count_space_const2[measurable (raw)]:
hoelzl@59000
   209
  "f \<in> measurable M (count_space UNIV) \<Longrightarrow> Measurable.pred M (\<lambda>x. c = f x)"
hoelzl@59000
   210
  by (intro pred_eq_const2[where N="count_space UNIV"]) (auto )
hoelzl@59000
   211
hoelzl@50387
   212
lemma pred_le_const[measurable (raw generic)]:
hoelzl@50387
   213
  assumes f: "f \<in> measurable M N" and c: "{.. c} \<in> sets N" shows "pred M (\<lambda>x. f x \<le> c)"
hoelzl@50387
   214
  using measurable_sets[OF f c]
hoelzl@50387
   215
  by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50387
   216
hoelzl@50387
   217
lemma pred_const_le[measurable (raw generic)]:
hoelzl@50387
   218
  assumes f: "f \<in> measurable M N" and c: "{c ..} \<in> sets N" shows "pred M (\<lambda>x. c \<le> f x)"
hoelzl@50387
   219
  using measurable_sets[OF f c]
hoelzl@50387
   220
  by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50387
   221
hoelzl@50387
   222
lemma pred_less_const[measurable (raw generic)]:
hoelzl@50387
   223
  assumes f: "f \<in> measurable M N" and c: "{..< c} \<in> sets N" shows "pred M (\<lambda>x. f x < c)"
hoelzl@50387
   224
  using measurable_sets[OF f c]
hoelzl@50387
   225
  by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50387
   226
hoelzl@50387
   227
lemma pred_const_less[measurable (raw generic)]:
hoelzl@50387
   228
  assumes f: "f \<in> measurable M N" and c: "{c <..} \<in> sets N" shows "pred M (\<lambda>x. c < f x)"
hoelzl@50387
   229
  using measurable_sets[OF f c]
hoelzl@50387
   230
  by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50387
   231
hoelzl@50387
   232
declare
hoelzl@50387
   233
  sets.Int[measurable (raw)]
hoelzl@50387
   234
hoelzl@50387
   235
lemma pred_in_If[measurable (raw)]:
hoelzl@50387
   236
  "(P \<Longrightarrow> pred M (\<lambda>x. x \<in> A x)) \<Longrightarrow> (\<not> P \<Longrightarrow> pred M (\<lambda>x. x \<in> B x)) \<Longrightarrow>
hoelzl@50387
   237
    pred M (\<lambda>x. x \<in> (if P then A x else B x))"
hoelzl@50387
   238
  by auto
hoelzl@50387
   239
hoelzl@50387
   240
lemma sets_range[measurable_dest]:
hoelzl@50387
   241
  "A ` I \<subseteq> sets M \<Longrightarrow> i \<in> I \<Longrightarrow> A i \<in> sets M"
hoelzl@50387
   242
  by auto
hoelzl@50387
   243
hoelzl@50387
   244
lemma pred_sets_range[measurable_dest]:
hoelzl@50387
   245
  "A ` I \<subseteq> sets N \<Longrightarrow> i \<in> I \<Longrightarrow> f \<in> measurable M N \<Longrightarrow> pred M (\<lambda>x. f x \<in> A i)"
hoelzl@50387
   246
  using pred_sets2[OF sets_range] by auto
hoelzl@50387
   247
hoelzl@50387
   248
lemma sets_All[measurable_dest]:
hoelzl@50387
   249
  "\<forall>i. A i \<in> sets (M i) \<Longrightarrow> A i \<in> sets (M i)"
hoelzl@50387
   250
  by auto
hoelzl@50387
   251
hoelzl@50387
   252
lemma pred_sets_All[measurable_dest]:
hoelzl@50387
   253
  "\<forall>i. A i \<in> sets (N i) \<Longrightarrow> f \<in> measurable M (N i) \<Longrightarrow> pred M (\<lambda>x. f x \<in> A i)"
hoelzl@50387
   254
  using pred_sets2[OF sets_All, of A N f] by auto
hoelzl@50387
   255
hoelzl@50387
   256
lemma sets_Ball[measurable_dest]:
hoelzl@50387
   257
  "\<forall>i\<in>I. A i \<in> sets (M i) \<Longrightarrow> i\<in>I \<Longrightarrow> A i \<in> sets (M i)"
hoelzl@50387
   258
  by auto
hoelzl@50387
   259
hoelzl@50387
   260
lemma pred_sets_Ball[measurable_dest]:
hoelzl@50387
   261
  "\<forall>i\<in>I. A i \<in> sets (N i) \<Longrightarrow> i\<in>I \<Longrightarrow> f \<in> measurable M (N i) \<Longrightarrow> pred M (\<lambda>x. f x \<in> A i)"
hoelzl@50387
   262
  using pred_sets2[OF sets_Ball, of _ _ _ f] by auto
hoelzl@50387
   263
hoelzl@50387
   264
lemma measurable_finite[measurable (raw)]:
hoelzl@50387
   265
  fixes S :: "'a \<Rightarrow> nat set"
hoelzl@50387
   266
  assumes [measurable]: "\<And>i. {x\<in>space M. i \<in> S x} \<in> sets M"
hoelzl@50387
   267
  shows "pred M (\<lambda>x. finite (S x))"
hoelzl@50387
   268
  unfolding finite_nat_set_iff_bounded by (simp add: Ball_def)
hoelzl@50387
   269
hoelzl@50387
   270
lemma measurable_Least[measurable]:
hoelzl@50387
   271
  assumes [measurable]: "(\<And>i::nat. (\<lambda>x. P i x) \<in> measurable M (count_space UNIV))"q
hoelzl@50387
   272
  shows "(\<lambda>x. LEAST i. P i x) \<in> measurable M (count_space UNIV)"
hoelzl@50387
   273
  unfolding measurable_def by (safe intro!: sets_Least) simp_all
hoelzl@50387
   274
hoelzl@56993
   275
lemma measurable_Max_nat[measurable (raw)]: 
hoelzl@56993
   276
  fixes P :: "nat \<Rightarrow> 'a \<Rightarrow> bool"
hoelzl@56993
   277
  assumes [measurable]: "\<And>i. Measurable.pred M (P i)"
hoelzl@56993
   278
  shows "(\<lambda>x. Max {i. P i x}) \<in> measurable M (count_space UNIV)"
hoelzl@56993
   279
  unfolding measurable_count_space_eq2_countable
hoelzl@56993
   280
proof safe
hoelzl@56993
   281
  fix n
hoelzl@56993
   282
hoelzl@56993
   283
  { fix x assume "\<forall>i. \<exists>n\<ge>i. P n x"
hoelzl@56993
   284
    then have "infinite {i. P i x}"
hoelzl@56993
   285
      unfolding infinite_nat_iff_unbounded_le by auto
hoelzl@56993
   286
    then have "Max {i. P i x} = the None"
hoelzl@56993
   287
      by (rule Max.infinite) }
hoelzl@56993
   288
  note 1 = this
hoelzl@56993
   289
hoelzl@56993
   290
  { fix x i j assume "P i x" "\<forall>n\<ge>j. \<not> P n x"
hoelzl@56993
   291
    then have "finite {i. P i x}"
hoelzl@56993
   292
      by (auto simp: subset_eq not_le[symmetric] finite_nat_iff_bounded)
hoelzl@56993
   293
    with `P i x` have "P (Max {i. P i x}) x" "i \<le> Max {i. P i x}" "finite {i. P i x}"
hoelzl@56993
   294
      using Max_in[of "{i. P i x}"] by auto }
hoelzl@56993
   295
  note 2 = this
hoelzl@56993
   296
hoelzl@56993
   297
  have "(\<lambda>x. Max {i. P i x}) -` {n} \<inter> space M = {x\<in>space M. Max {i. P i x} = n}"
hoelzl@56993
   298
    by auto
hoelzl@56993
   299
  also have "\<dots> = 
hoelzl@56993
   300
    {x\<in>space M. if (\<forall>i. \<exists>n\<ge>i. P n x) then the None = n else 
hoelzl@56993
   301
      if (\<exists>i. P i x) then P n x \<and> (\<forall>i>n. \<not> P i x)
hoelzl@56993
   302
      else Max {} = n}"
hoelzl@56993
   303
    by (intro arg_cong[where f=Collect] ext conj_cong)
hoelzl@56993
   304
       (auto simp add: 1 2 not_le[symmetric] intro!: Max_eqI)
hoelzl@56993
   305
  also have "\<dots> \<in> sets M"
hoelzl@56993
   306
    by measurable
hoelzl@56993
   307
  finally show "(\<lambda>x. Max {i. P i x}) -` {n} \<inter> space M \<in> sets M" .
hoelzl@56993
   308
qed simp
hoelzl@56993
   309
hoelzl@56993
   310
lemma measurable_Min_nat[measurable (raw)]: 
hoelzl@56993
   311
  fixes P :: "nat \<Rightarrow> 'a \<Rightarrow> bool"
hoelzl@56993
   312
  assumes [measurable]: "\<And>i. Measurable.pred M (P i)"
hoelzl@56993
   313
  shows "(\<lambda>x. Min {i. P i x}) \<in> measurable M (count_space UNIV)"
hoelzl@56993
   314
  unfolding measurable_count_space_eq2_countable
hoelzl@56993
   315
proof safe
hoelzl@56993
   316
  fix n
hoelzl@56993
   317
hoelzl@56993
   318
  { fix x assume "\<forall>i. \<exists>n\<ge>i. P n x"
hoelzl@56993
   319
    then have "infinite {i. P i x}"
hoelzl@56993
   320
      unfolding infinite_nat_iff_unbounded_le by auto
hoelzl@56993
   321
    then have "Min {i. P i x} = the None"
hoelzl@56993
   322
      by (rule Min.infinite) }
hoelzl@56993
   323
  note 1 = this
hoelzl@56993
   324
hoelzl@56993
   325
  { fix x i j assume "P i x" "\<forall>n\<ge>j. \<not> P n x"
hoelzl@56993
   326
    then have "finite {i. P i x}"
hoelzl@56993
   327
      by (auto simp: subset_eq not_le[symmetric] finite_nat_iff_bounded)
hoelzl@56993
   328
    with `P i x` have "P (Min {i. P i x}) x" "Min {i. P i x} \<le> i" "finite {i. P i x}"
hoelzl@56993
   329
      using Min_in[of "{i. P i x}"] by auto }
hoelzl@56993
   330
  note 2 = this
hoelzl@56993
   331
hoelzl@56993
   332
  have "(\<lambda>x. Min {i. P i x}) -` {n} \<inter> space M = {x\<in>space M. Min {i. P i x} = n}"
hoelzl@56993
   333
    by auto
hoelzl@56993
   334
  also have "\<dots> = 
hoelzl@56993
   335
    {x\<in>space M. if (\<forall>i. \<exists>n\<ge>i. P n x) then the None = n else 
hoelzl@56993
   336
      if (\<exists>i. P i x) then P n x \<and> (\<forall>i<n. \<not> P i x)
hoelzl@56993
   337
      else Min {} = n}"
hoelzl@56993
   338
    by (intro arg_cong[where f=Collect] ext conj_cong)
hoelzl@56993
   339
       (auto simp add: 1 2 not_le[symmetric] intro!: Min_eqI)
hoelzl@56993
   340
  also have "\<dots> \<in> sets M"
hoelzl@56993
   341
    by measurable
hoelzl@56993
   342
  finally show "(\<lambda>x. Min {i. P i x}) -` {n} \<inter> space M \<in> sets M" .
hoelzl@56993
   343
qed simp
hoelzl@56993
   344
hoelzl@50387
   345
lemma measurable_count_space_insert[measurable (raw)]:
hoelzl@50387
   346
  "s \<in> S \<Longrightarrow> A \<in> sets (count_space S) \<Longrightarrow> insert s A \<in> sets (count_space S)"
hoelzl@50387
   347
  by simp
hoelzl@50387
   348
hoelzl@59000
   349
lemma sets_UNIV [measurable (raw)]: "A \<in> sets (count_space UNIV)"
hoelzl@59000
   350
  by simp
hoelzl@59000
   351
hoelzl@57025
   352
lemma measurable_card[measurable]:
hoelzl@57025
   353
  fixes S :: "'a \<Rightarrow> nat set"
hoelzl@57025
   354
  assumes [measurable]: "\<And>i. {x\<in>space M. i \<in> S x} \<in> sets M"
hoelzl@57025
   355
  shows "(\<lambda>x. card (S x)) \<in> measurable M (count_space UNIV)"
hoelzl@57025
   356
  unfolding measurable_count_space_eq2_countable
hoelzl@57025
   357
proof safe
hoelzl@57025
   358
  fix n show "(\<lambda>x. card (S x)) -` {n} \<inter> space M \<in> sets M"
hoelzl@57025
   359
  proof (cases n)
hoelzl@57025
   360
    case 0
hoelzl@57025
   361
    then have "(\<lambda>x. card (S x)) -` {n} \<inter> space M = {x\<in>space M. infinite (S x) \<or> (\<forall>i. i \<notin> S x)}"
hoelzl@57025
   362
      by auto
hoelzl@57025
   363
    also have "\<dots> \<in> sets M"
hoelzl@57025
   364
      by measurable
hoelzl@57025
   365
    finally show ?thesis .
hoelzl@57025
   366
  next
hoelzl@57025
   367
    case (Suc i)
hoelzl@57025
   368
    then have "(\<lambda>x. card (S x)) -` {n} \<inter> space M =
hoelzl@57025
   369
      (\<Union>F\<in>{A\<in>{A. finite A}. card A = n}. {x\<in>space M. (\<forall>i. i \<in> S x \<longleftrightarrow> i \<in> F)})"
hoelzl@57025
   370
      unfolding set_eq_iff[symmetric] Collect_bex_eq[symmetric] by (auto intro: card_ge_0_finite)
hoelzl@57025
   371
    also have "\<dots> \<in> sets M"
hoelzl@57025
   372
      by (intro sets.countable_UN' countable_Collect countable_Collect_finite) auto
hoelzl@57025
   373
    finally show ?thesis .
hoelzl@57025
   374
  qed
hoelzl@57025
   375
qed rule
hoelzl@57025
   376
hoelzl@59088
   377
lemma measurable_pred_countable[measurable (raw)]:
hoelzl@59088
   378
  assumes "countable X"
hoelzl@59088
   379
  shows 
hoelzl@59088
   380
    "(\<And>i. i \<in> X \<Longrightarrow> Measurable.pred M (\<lambda>x. P x i)) \<Longrightarrow> Measurable.pred M (\<lambda>x. \<forall>i\<in>X. P x i)"
hoelzl@59088
   381
    "(\<And>i. i \<in> X \<Longrightarrow> Measurable.pred M (\<lambda>x. P x i)) \<Longrightarrow> Measurable.pred M (\<lambda>x. \<exists>i\<in>X. P x i)"
hoelzl@59088
   382
  unfolding pred_def
hoelzl@59088
   383
  by (auto intro!: sets.sets_Collect_countable_All' sets.sets_Collect_countable_Ex' assms)
hoelzl@59088
   384
hoelzl@56021
   385
subsection {* Measurability for (co)inductive predicates *}
hoelzl@56021
   386
hoelzl@59088
   387
lemma measurable_bot[measurable]: "bot \<in> measurable M (count_space UNIV)"
hoelzl@59088
   388
  by (simp add: bot_fun_def)
hoelzl@59088
   389
hoelzl@59088
   390
lemma measurable_top[measurable]: "top \<in> measurable M (count_space UNIV)"
hoelzl@59088
   391
  by (simp add: top_fun_def)
hoelzl@59088
   392
hoelzl@59088
   393
lemma measurable_SUP[measurable]:
hoelzl@59088
   394
  fixes F :: "'i \<Rightarrow> 'a \<Rightarrow> 'b::{complete_lattice, countable}"
hoelzl@59088
   395
  assumes [simp]: "countable I"
hoelzl@59088
   396
  assumes [measurable]: "\<And>i. i \<in> I \<Longrightarrow> F i \<in> measurable M (count_space UNIV)"
hoelzl@59088
   397
  shows "(\<lambda>x. SUP i:I. F i x) \<in> measurable M (count_space UNIV)"
hoelzl@59088
   398
  unfolding measurable_count_space_eq2_countable
hoelzl@59088
   399
proof (safe intro!: UNIV_I)
hoelzl@59088
   400
  fix a 
hoelzl@59088
   401
  have "(\<lambda>x. SUP i:I. F i x) -` {a} \<inter> space M =
hoelzl@59088
   402
    {x\<in>space M. (\<forall>i\<in>I. F i x \<le> a) \<and> (\<forall>b. (\<forall>i\<in>I. F i x \<le> b) \<longrightarrow> a \<le> b)}"
hoelzl@59088
   403
    unfolding SUP_le_iff[symmetric] by auto
hoelzl@59088
   404
  also have "\<dots> \<in> sets M"
hoelzl@59088
   405
    by measurable
hoelzl@59088
   406
  finally show "(\<lambda>x. SUP i:I. F i x) -` {a} \<inter> space M \<in> sets M" .
hoelzl@59088
   407
qed
hoelzl@59088
   408
hoelzl@59088
   409
lemma measurable_INF[measurable]:
hoelzl@59088
   410
  fixes F :: "'i \<Rightarrow> 'a \<Rightarrow> 'b::{complete_lattice, countable}"
hoelzl@59088
   411
  assumes [simp]: "countable I"
hoelzl@59088
   412
  assumes [measurable]: "\<And>i. i \<in> I \<Longrightarrow> F i \<in> measurable M (count_space UNIV)"
hoelzl@59088
   413
  shows "(\<lambda>x. INF i:I. F i x) \<in> measurable M (count_space UNIV)"
hoelzl@59088
   414
  unfolding measurable_count_space_eq2_countable
hoelzl@59088
   415
proof (safe intro!: UNIV_I)
hoelzl@59088
   416
  fix a 
hoelzl@59088
   417
  have "(\<lambda>x. INF i:I. F i x) -` {a} \<inter> space M =
hoelzl@59088
   418
    {x\<in>space M. (\<forall>i\<in>I. a \<le> F i x) \<and> (\<forall>b. (\<forall>i\<in>I. b \<le> F i x) \<longrightarrow> b \<le> a)}"
hoelzl@59088
   419
    unfolding le_INF_iff[symmetric] by auto
hoelzl@59088
   420
  also have "\<dots> \<in> sets M"
hoelzl@59088
   421
    by measurable
hoelzl@59088
   422
  finally show "(\<lambda>x. INF i:I. F i x) -` {a} \<inter> space M \<in> sets M" .
hoelzl@59088
   423
qed
hoelzl@59088
   424
hoelzl@59088
   425
lemma measurable_lfp_coinduct[consumes 1, case_names continuity step]:
hoelzl@59088
   426
  fixes F :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b::{complete_lattice, countable})"
hoelzl@59088
   427
  assumes "P M"
hoelzl@59088
   428
  assumes F: "Order_Continuity.continuous F"
hoelzl@59088
   429
  assumes *: "\<And>M A. P M \<Longrightarrow> (\<And>N. P N \<Longrightarrow> A \<in> measurable N (count_space UNIV)) \<Longrightarrow> F A \<in> measurable M (count_space UNIV)"
hoelzl@59088
   430
  shows "lfp F \<in> measurable M (count_space UNIV)"
hoelzl@59088
   431
proof -
hoelzl@59088
   432
  { fix i from `P M` have "((F ^^ i) bot) \<in> measurable M (count_space UNIV)"
hoelzl@59088
   433
      by (induct i arbitrary: M) (auto intro!: *) }
hoelzl@59088
   434
  then have "(\<lambda>x. SUP i. (F ^^ i) bot x) \<in> measurable M (count_space UNIV)"
hoelzl@59088
   435
    by measurable
hoelzl@59088
   436
  also have "(\<lambda>x. SUP i. (F ^^ i) bot x) = lfp F"
hoelzl@59088
   437
    by (subst continuous_lfp) (auto intro: F)
hoelzl@59088
   438
  finally show ?thesis .
hoelzl@59088
   439
qed
hoelzl@59088
   440
hoelzl@56021
   441
lemma measurable_lfp:
hoelzl@59088
   442
  fixes F :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b::{complete_lattice, countable})"
hoelzl@59088
   443
  assumes F: "Order_Continuity.continuous F"
hoelzl@59088
   444
  assumes *: "\<And>A. A \<in> measurable M (count_space UNIV) \<Longrightarrow> F A \<in> measurable M (count_space UNIV)"
hoelzl@59088
   445
  shows "lfp F \<in> measurable M (count_space UNIV)"
hoelzl@59088
   446
  by (coinduction rule: measurable_lfp_coinduct[OF _ F]) (blast intro: *)
hoelzl@59088
   447
hoelzl@59088
   448
lemma measurable_gfp_coinduct[consumes 1, case_names continuity step]:
hoelzl@59088
   449
  fixes F :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b::{complete_lattice, countable})"
hoelzl@59088
   450
  assumes "P M"
hoelzl@59088
   451
  assumes F: "Order_Continuity.down_continuous F"
hoelzl@59088
   452
  assumes *: "\<And>M A. P M \<Longrightarrow> (\<And>N. P N \<Longrightarrow> A \<in> measurable N (count_space UNIV)) \<Longrightarrow> F A \<in> measurable M (count_space UNIV)"
hoelzl@59088
   453
  shows "gfp F \<in> measurable M (count_space UNIV)"
hoelzl@56021
   454
proof -
hoelzl@59088
   455
  { fix i from `P M` have "((F ^^ i) top) \<in> measurable M (count_space UNIV)"
hoelzl@59088
   456
      by (induct i arbitrary: M) (auto intro!: *) }
hoelzl@59088
   457
  then have "(\<lambda>x. INF i. (F ^^ i) top x) \<in> measurable M (count_space UNIV)"
hoelzl@56021
   458
    by measurable
hoelzl@59088
   459
  also have "(\<lambda>x. INF i. (F ^^ i) top x) = gfp F"
hoelzl@59088
   460
    by (subst down_continuous_gfp) (auto intro: F)
hoelzl@56021
   461
  finally show ?thesis .
hoelzl@56021
   462
qed
hoelzl@56021
   463
hoelzl@56021
   464
lemma measurable_gfp:
hoelzl@59088
   465
  fixes F :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b::{complete_lattice, countable})"
hoelzl@59088
   466
  assumes F: "Order_Continuity.down_continuous F"
hoelzl@59088
   467
  assumes *: "\<And>A. A \<in> measurable M (count_space UNIV) \<Longrightarrow> F A \<in> measurable M (count_space UNIV)"
hoelzl@59088
   468
  shows "gfp F \<in> measurable M (count_space UNIV)"
hoelzl@59088
   469
  by (coinduction rule: measurable_gfp_coinduct[OF _ F]) (blast intro: *)
hoelzl@59000
   470
hoelzl@59000
   471
lemma measurable_lfp2_coinduct[consumes 1, case_names continuity step]:
hoelzl@59088
   472
  fixes F :: "('a \<Rightarrow> 'c \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'c \<Rightarrow> 'b::{complete_lattice, countable})"
hoelzl@59000
   473
  assumes "P M s"
hoelzl@59088
   474
  assumes F: "Order_Continuity.continuous F"
hoelzl@59088
   475
  assumes *: "\<And>M A s. P M s \<Longrightarrow> (\<And>N t. P N t \<Longrightarrow> A t \<in> measurable N (count_space UNIV)) \<Longrightarrow> F A s \<in> measurable M (count_space UNIV)"
hoelzl@59088
   476
  shows "lfp F s \<in> measurable M (count_space UNIV)"
hoelzl@59000
   477
proof -
hoelzl@59088
   478
  { fix i from `P M s` have "(\<lambda>x. (F ^^ i) bot s x) \<in> measurable M (count_space UNIV)"
hoelzl@59000
   479
      by (induct i arbitrary: M s) (auto intro!: *) }
hoelzl@59088
   480
  then have "(\<lambda>x. SUP i. (F ^^ i) bot s x) \<in> measurable M (count_space UNIV)"
hoelzl@59000
   481
    by measurable
hoelzl@59088
   482
  also have "(\<lambda>x. SUP i. (F ^^ i) bot s x) = lfp F s"
hoelzl@59088
   483
    by (subst continuous_lfp) (auto simp: F)
hoelzl@59000
   484
  finally show ?thesis .
hoelzl@59000
   485
qed
hoelzl@59000
   486
hoelzl@59000
   487
lemma measurable_gfp2_coinduct[consumes 1, case_names continuity step]:
hoelzl@59088
   488
  fixes F :: "('a \<Rightarrow> 'c \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'c \<Rightarrow> 'b::{complete_lattice, countable})"
hoelzl@59000
   489
  assumes "P M s"
hoelzl@59088
   490
  assumes F: "Order_Continuity.down_continuous F"
hoelzl@59088
   491
  assumes *: "\<And>M A s. P M s \<Longrightarrow> (\<And>N t. P N t \<Longrightarrow> A t \<in> measurable N (count_space UNIV)) \<Longrightarrow> F A s \<in> measurable M (count_space UNIV)"
hoelzl@59088
   492
  shows "gfp F s \<in> measurable M (count_space UNIV)"
hoelzl@59000
   493
proof -
hoelzl@59088
   494
  { fix i from `P M s` have "(\<lambda>x. (F ^^ i) top s x) \<in> measurable M (count_space UNIV)"
hoelzl@59000
   495
      by (induct i arbitrary: M s) (auto intro!: *) }
hoelzl@59088
   496
  then have "(\<lambda>x. INF i. (F ^^ i) top s x) \<in> measurable M (count_space UNIV)"
hoelzl@59000
   497
    by measurable
hoelzl@59088
   498
  also have "(\<lambda>x. INF i. (F ^^ i) top s x) = gfp F s"
hoelzl@59088
   499
    by (subst down_continuous_gfp) (auto simp: F)
hoelzl@59000
   500
  finally show ?thesis .
hoelzl@59000
   501
qed
hoelzl@59000
   502
hoelzl@59000
   503
lemma measurable_enat_coinduct:
hoelzl@59000
   504
  fixes f :: "'a \<Rightarrow> enat"
hoelzl@59000
   505
  assumes "R f"
hoelzl@59000
   506
  assumes *: "\<And>f. R f \<Longrightarrow> \<exists>g h i P. R g \<and> f = (\<lambda>x. if P x then h x else eSuc (g (i x))) \<and> 
hoelzl@59000
   507
    Measurable.pred M P \<and>
hoelzl@59000
   508
    i \<in> measurable M M \<and>
hoelzl@59000
   509
    h \<in> measurable M (count_space UNIV)"
hoelzl@59000
   510
  shows "f \<in> measurable M (count_space UNIV)"
hoelzl@59000
   511
proof (simp add: measurable_count_space_eq2_countable, rule )
hoelzl@59000
   512
  fix a :: enat
hoelzl@59000
   513
  have "f -` {a} \<inter> space M = {x\<in>space M. f x = a}"
hoelzl@59000
   514
    by auto
hoelzl@59000
   515
  { fix i :: nat
hoelzl@59000
   516
    from `R f` have "Measurable.pred M (\<lambda>x. f x = enat i)"
hoelzl@59000
   517
    proof (induction i arbitrary: f)
hoelzl@59000
   518
      case 0
hoelzl@59000
   519
      from *[OF this] obtain g h i P
hoelzl@59000
   520
        where f: "f = (\<lambda>x. if P x then h x else eSuc (g (i x)))" and
hoelzl@59000
   521
          [measurable]: "Measurable.pred M P" "i \<in> measurable M M" "h \<in> measurable M (count_space UNIV)"
hoelzl@59000
   522
        by auto
hoelzl@59000
   523
      have "Measurable.pred M (\<lambda>x. P x \<and> h x = 0)"
hoelzl@59000
   524
        by measurable
hoelzl@59000
   525
      also have "(\<lambda>x. P x \<and> h x = 0) = (\<lambda>x. f x = enat 0)"
hoelzl@59000
   526
        by (auto simp: f zero_enat_def[symmetric])
hoelzl@59000
   527
      finally show ?case .
hoelzl@59000
   528
    next
hoelzl@59000
   529
      case (Suc n)
hoelzl@59000
   530
      from *[OF Suc.prems] obtain g h i P
hoelzl@59000
   531
        where f: "f = (\<lambda>x. if P x then h x else eSuc (g (i x)))" and "R g" and
hoelzl@59000
   532
          M[measurable]: "Measurable.pred M P" "i \<in> measurable M M" "h \<in> measurable M (count_space UNIV)"
hoelzl@59000
   533
        by auto
hoelzl@59000
   534
      have "(\<lambda>x. f x = enat (Suc n)) =
hoelzl@59000
   535
        (\<lambda>x. (P x \<longrightarrow> h x = enat (Suc n)) \<and> (\<not> P x \<longrightarrow> g (i x) = enat n))"
hoelzl@59000
   536
        by (auto simp: f zero_enat_def[symmetric] eSuc_enat[symmetric])
hoelzl@59000
   537
      also have "Measurable.pred M \<dots>"
hoelzl@59000
   538
        by (intro pred_intros_logic measurable_compose[OF M(2)] Suc `R g`) measurable
hoelzl@59000
   539
      finally show ?case .
hoelzl@59000
   540
    qed
hoelzl@59000
   541
    then have "f -` {enat i} \<inter> space M \<in> sets M"
hoelzl@59000
   542
      by (simp add: pred_def Int_def conj_commute) }
hoelzl@59000
   543
  note fin = this
hoelzl@59000
   544
  show "f -` {a} \<inter> space M \<in> sets M"
hoelzl@59000
   545
  proof (cases a)
hoelzl@59000
   546
    case infinity
hoelzl@59000
   547
    then have "f -` {a} \<inter> space M = space M - (\<Union>n. f -` {enat n} \<inter> space M)"
hoelzl@59000
   548
      by auto
hoelzl@59000
   549
    also have "\<dots> \<in> sets M"
hoelzl@59000
   550
      by (intro sets.Diff sets.top sets.Un sets.countable_UN) (auto intro!: fin)
hoelzl@59000
   551
    finally show ?thesis .
hoelzl@59000
   552
  qed (simp add: fin)
hoelzl@59000
   553
qed
hoelzl@59000
   554
hoelzl@59000
   555
lemma measurable_THE:
hoelzl@59000
   556
  fixes P :: "'a \<Rightarrow> 'b \<Rightarrow> bool"
hoelzl@59000
   557
  assumes [measurable]: "\<And>i. Measurable.pred M (P i)"
hoelzl@59000
   558
  assumes I[simp]: "countable I" "\<And>i x. x \<in> space M \<Longrightarrow> P i x \<Longrightarrow> i \<in> I"
hoelzl@59000
   559
  assumes unique: "\<And>x i j. x \<in> space M \<Longrightarrow> P i x \<Longrightarrow> P j x \<Longrightarrow> i = j"
hoelzl@59000
   560
  shows "(\<lambda>x. THE i. P i x) \<in> measurable M (count_space UNIV)"
hoelzl@59000
   561
  unfolding measurable_def
hoelzl@59000
   562
proof safe
hoelzl@59000
   563
  fix X
hoelzl@59000
   564
  def f \<equiv> "\<lambda>x. THE i. P i x" def undef \<equiv> "THE i::'a. False"
hoelzl@59000
   565
  { fix i x assume "x \<in> space M" "P i x" then have "f x = i"
hoelzl@59000
   566
      unfolding f_def using unique by auto }
hoelzl@59000
   567
  note f_eq = this
hoelzl@59000
   568
  { fix x assume "x \<in> space M" "\<forall>i\<in>I. \<not> P i x"
hoelzl@59000
   569
    then have "\<And>i. \<not> P i x"
hoelzl@59000
   570
      using I(2)[of x] by auto
hoelzl@59000
   571
    then have "f x = undef"
hoelzl@59000
   572
      by (auto simp: undef_def f_def) }
hoelzl@59000
   573
  then have "f -` X \<inter> space M = (\<Union>i\<in>I \<inter> X. {x\<in>space M. P i x}) \<union>
hoelzl@59000
   574
     (if undef \<in> X then space M - (\<Union>i\<in>I. {x\<in>space M. P i x}) else {})"
hoelzl@59000
   575
    by (auto dest: f_eq)
hoelzl@59000
   576
  also have "\<dots> \<in> sets M"
hoelzl@59000
   577
    by (auto intro!: sets.Diff sets.countable_UN')
hoelzl@59000
   578
  finally show "f -` X \<inter> space M \<in> sets M" .
hoelzl@59000
   579
qed simp
hoelzl@59000
   580
hoelzl@59000
   581
lemma measurable_Ex1[measurable (raw)]:
hoelzl@59000
   582
  assumes [simp]: "countable I" and [measurable]: "\<And>i. i \<in> I \<Longrightarrow> Measurable.pred M (P i)"
hoelzl@59000
   583
  shows "Measurable.pred M (\<lambda>x. \<exists>!i\<in>I. P i x)"
hoelzl@59000
   584
  unfolding bex1_def by measurable
hoelzl@59000
   585
hoelzl@59000
   586
lemma measurable_split_if[measurable (raw)]:
hoelzl@59000
   587
  "(c \<Longrightarrow> Measurable.pred M f) \<Longrightarrow> (\<not> c \<Longrightarrow> Measurable.pred M g) \<Longrightarrow>
hoelzl@59000
   588
   Measurable.pred M (if c then f else g)"
hoelzl@59000
   589
  by simp
hoelzl@59000
   590
hoelzl@59000
   591
lemma pred_restrict_space:
hoelzl@59000
   592
  assumes "S \<in> sets M"
hoelzl@59000
   593
  shows "Measurable.pred (restrict_space M S) P \<longleftrightarrow> Measurable.pred M (\<lambda>x. x \<in> S \<and> P x)"
hoelzl@59000
   594
  unfolding pred_def sets_Collect_restrict_space_iff[OF assms] ..
hoelzl@59000
   595
hoelzl@59000
   596
lemma measurable_predpow[measurable]:
hoelzl@59000
   597
  assumes "Measurable.pred M T"
hoelzl@59000
   598
  assumes "\<And>Q. Measurable.pred M Q \<Longrightarrow> Measurable.pred M (R Q)"
hoelzl@59000
   599
  shows "Measurable.pred M ((R ^^ n) T)"
hoelzl@59000
   600
  by (induct n) (auto intro: assms)
hoelzl@59000
   601
hoelzl@50387
   602
hide_const (open) pred
hoelzl@50387
   603
hoelzl@50387
   604
end
hoelzl@59048
   605