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