src/HOL/Probability/Measurable.thy
author hoelzl
Tue May 20 19:24:39 2014 +0200 (2014-05-20)
changeset 57025 e7fd64f82876
parent 56993 e5366291d6aa
child 58965 a62cdcc5344b
permissions -rw-r--r--
add various lemmas
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 = {*
wenzelm@53043
    54
  Scan.lift (Scan.optional (Args.parens (Scan.optional (Args.$$$ "raw" >> K true) false --
wenzelm@53043
    55
    Scan.optional (Args.$$$ "generic" >> K Measurable.Generic) Measurable.Concrete))
wenzelm@53043
    56
    (false, Measurable.Concrete) >> (Thm.declaration_attribute o Measurable.add_thm))
wenzelm@53043
    57
*} "declaration of measurability theorems"
wenzelm@53043
    58
wenzelm@53043
    59
attribute_setup measurable_dest = {*
wenzelm@53043
    60
  Scan.lift (Scan.succeed (Thm.declaration_attribute Measurable.add_dest))
wenzelm@53043
    61
*} "add dest rule for measurability prover"
wenzelm@53043
    62
wenzelm@53043
    63
attribute_setup measurable_app = {*
wenzelm@53043
    64
  Scan.lift (Scan.succeed (Thm.declaration_attribute Measurable.add_app))
wenzelm@53043
    65
*} "add application rule for measurability prover"
wenzelm@53043
    66
wenzelm@53043
    67
method_setup measurable = {*
wenzelm@53043
    68
  Scan.lift (Scan.succeed (fn ctxt => METHOD (fn facts => Measurable.measurable_tac ctxt facts)))
wenzelm@53043
    69
*} "measurability prover"
wenzelm@53043
    70
hoelzl@50387
    71
simproc_setup measurable ("A \<in> sets M" | "f \<in> measurable M N") = {* K Measurable.simproc *}
hoelzl@50387
    72
hoelzl@50387
    73
declare
hoelzl@50387
    74
  measurable_compose_rev[measurable_dest]
hoelzl@50387
    75
  pred_sets1[measurable_dest]
hoelzl@50387
    76
  pred_sets2[measurable_dest]
hoelzl@50387
    77
  sets.sets_into_space[measurable_dest]
hoelzl@50387
    78
hoelzl@50387
    79
declare
hoelzl@50387
    80
  sets.top[measurable]
hoelzl@50387
    81
  sets.empty_sets[measurable (raw)]
hoelzl@50387
    82
  sets.Un[measurable (raw)]
hoelzl@50387
    83
  sets.Diff[measurable (raw)]
hoelzl@50387
    84
hoelzl@50387
    85
declare
hoelzl@50387
    86
  measurable_count_space[measurable (raw)]
hoelzl@50387
    87
  measurable_ident[measurable (raw)]
hoelzl@50387
    88
  measurable_ident_sets[measurable (raw)]
hoelzl@50387
    89
  measurable_const[measurable (raw)]
hoelzl@50387
    90
  measurable_If[measurable (raw)]
hoelzl@50387
    91
  measurable_comp[measurable (raw)]
hoelzl@50387
    92
  measurable_sets[measurable (raw)]
hoelzl@50387
    93
hoelzl@50387
    94
lemma predE[measurable (raw)]: 
hoelzl@50387
    95
  "pred M P \<Longrightarrow> {x\<in>space M. P x} \<in> sets M"
hoelzl@50387
    96
  unfolding pred_def .
hoelzl@50387
    97
hoelzl@50387
    98
lemma pred_intros_imp'[measurable (raw)]:
hoelzl@50387
    99
  "(K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. K \<longrightarrow> P x)"
hoelzl@50387
   100
  by (cases K) auto
hoelzl@50387
   101
hoelzl@50387
   102
lemma pred_intros_conj1'[measurable (raw)]:
hoelzl@50387
   103
  "(K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. K \<and> P x)"
hoelzl@50387
   104
  by (cases K) auto
hoelzl@50387
   105
hoelzl@50387
   106
lemma pred_intros_conj2'[measurable (raw)]:
hoelzl@50387
   107
  "(K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. P x \<and> K)"
hoelzl@50387
   108
  by (cases K) auto
hoelzl@50387
   109
hoelzl@50387
   110
lemma pred_intros_disj1'[measurable (raw)]:
hoelzl@50387
   111
  "(\<not> K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. K \<or> P x)"
hoelzl@50387
   112
  by (cases K) auto
hoelzl@50387
   113
hoelzl@50387
   114
lemma pred_intros_disj2'[measurable (raw)]:
hoelzl@50387
   115
  "(\<not> K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. P x \<or> K)"
hoelzl@50387
   116
  by (cases K) auto
hoelzl@50387
   117
hoelzl@50387
   118
lemma pred_intros_logic[measurable (raw)]:
hoelzl@50387
   119
  "pred M (\<lambda>x. x \<in> space M)"
hoelzl@50387
   120
  "pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. \<not> P x)"
hoelzl@50387
   121
  "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
   122
  "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
   123
  "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
   124
  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x = P x)"
hoelzl@50387
   125
  "pred M (\<lambda>x. f x \<in> UNIV)"
hoelzl@50387
   126
  "pred M (\<lambda>x. f x \<in> {})"
hoelzl@50387
   127
  "pred M (\<lambda>x. P' (f x) x) \<Longrightarrow> pred M (\<lambda>x. f x \<in> {y. P' y x})"
hoelzl@50387
   128
  "pred M (\<lambda>x. f x \<in> (B x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> - (B x))"
hoelzl@50387
   129
  "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
   130
  "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
   131
  "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
   132
  "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
   133
  by (auto simp: iff_conv_conj_imp pred_def)
hoelzl@50387
   134
hoelzl@50387
   135
lemma pred_intros_countable[measurable (raw)]:
hoelzl@50387
   136
  fixes P :: "'a \<Rightarrow> 'i :: countable \<Rightarrow> bool"
hoelzl@50387
   137
  shows 
hoelzl@50387
   138
    "(\<And>i. pred M (\<lambda>x. P x i)) \<Longrightarrow> pred M (\<lambda>x. \<forall>i. P x i)"
hoelzl@50387
   139
    "(\<And>i. pred M (\<lambda>x. P x i)) \<Longrightarrow> pred M (\<lambda>x. \<exists>i. P x i)"
hoelzl@50387
   140
  by (auto intro!: sets.sets_Collect_countable_All sets.sets_Collect_countable_Ex simp: pred_def)
hoelzl@50387
   141
hoelzl@50387
   142
lemma pred_intros_countable_bounded[measurable (raw)]:
hoelzl@50387
   143
  fixes X :: "'i :: countable set"
hoelzl@50387
   144
  shows 
hoelzl@50387
   145
    "(\<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
   146
    "(\<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
   147
    "(\<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
   148
    "(\<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
   149
  by (auto simp: Bex_def Ball_def)
hoelzl@50387
   150
hoelzl@50387
   151
lemma pred_intros_finite[measurable (raw)]:
hoelzl@50387
   152
  "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
   153
  "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
   154
  "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
   155
  "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
   156
  by (auto intro!: sets.sets_Collect_finite_Ex sets.sets_Collect_finite_All simp: iff_conv_conj_imp pred_def)
hoelzl@50387
   157
hoelzl@50387
   158
lemma countable_Un_Int[measurable (raw)]:
hoelzl@50387
   159
  "(\<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
   160
  "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
   161
  by auto
hoelzl@50387
   162
hoelzl@50387
   163
declare
hoelzl@50387
   164
  finite_UN[measurable (raw)]
hoelzl@50387
   165
  finite_INT[measurable (raw)]
hoelzl@50387
   166
hoelzl@50387
   167
lemma sets_Int_pred[measurable (raw)]:
hoelzl@50387
   168
  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
   169
  shows "A \<inter> B \<in> sets M"
hoelzl@50387
   170
proof -
hoelzl@50387
   171
  have "{x\<in>space M. x \<in> A \<inter> B} \<in> sets M" by auto
hoelzl@50387
   172
  also have "{x\<in>space M. x \<in> A \<inter> B} = A \<inter> B"
hoelzl@50387
   173
    using space by auto
hoelzl@50387
   174
  finally show ?thesis .
hoelzl@50387
   175
qed
hoelzl@50387
   176
hoelzl@50387
   177
lemma [measurable (raw generic)]:
hoelzl@50387
   178
  assumes f: "f \<in> measurable M N" and c: "c \<in> space N \<Longrightarrow> {c} \<in> sets N"
hoelzl@50387
   179
  shows pred_eq_const1: "pred M (\<lambda>x. f x = c)"
hoelzl@50387
   180
    and pred_eq_const2: "pred M (\<lambda>x. c = f x)"
hoelzl@50387
   181
proof -
hoelzl@50387
   182
  show "pred M (\<lambda>x. f x = c)"
hoelzl@50387
   183
  proof cases
hoelzl@50387
   184
    assume "c \<in> space N"
hoelzl@50387
   185
    with measurable_sets[OF f c] show ?thesis
hoelzl@50387
   186
      by (auto simp: Int_def conj_commute pred_def)
hoelzl@50387
   187
  next
hoelzl@50387
   188
    assume "c \<notin> space N"
hoelzl@50387
   189
    with f[THEN measurable_space] have "{x \<in> space M. f x = c} = {}" by auto
hoelzl@50387
   190
    then show ?thesis by (auto simp: pred_def cong: conj_cong)
hoelzl@50387
   191
  qed
hoelzl@50387
   192
  then show "pred M (\<lambda>x. c = f x)"
hoelzl@50387
   193
    by (simp add: eq_commute)
hoelzl@50387
   194
qed
hoelzl@50387
   195
hoelzl@50387
   196
lemma pred_le_const[measurable (raw generic)]:
hoelzl@50387
   197
  assumes f: "f \<in> measurable M N" and c: "{.. c} \<in> sets N" shows "pred M (\<lambda>x. f x \<le> c)"
hoelzl@50387
   198
  using measurable_sets[OF f c]
hoelzl@50387
   199
  by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50387
   200
hoelzl@50387
   201
lemma pred_const_le[measurable (raw generic)]:
hoelzl@50387
   202
  assumes f: "f \<in> measurable M N" and c: "{c ..} \<in> sets N" shows "pred M (\<lambda>x. c \<le> f x)"
hoelzl@50387
   203
  using measurable_sets[OF f c]
hoelzl@50387
   204
  by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50387
   205
hoelzl@50387
   206
lemma pred_less_const[measurable (raw generic)]:
hoelzl@50387
   207
  assumes f: "f \<in> measurable M N" and c: "{..< c} \<in> sets N" shows "pred M (\<lambda>x. f x < c)"
hoelzl@50387
   208
  using measurable_sets[OF f c]
hoelzl@50387
   209
  by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50387
   210
hoelzl@50387
   211
lemma pred_const_less[measurable (raw generic)]:
hoelzl@50387
   212
  assumes f: "f \<in> measurable M N" and c: "{c <..} \<in> sets N" shows "pred M (\<lambda>x. c < f x)"
hoelzl@50387
   213
  using measurable_sets[OF f c]
hoelzl@50387
   214
  by (auto simp: Int_def conj_commute eq_commute pred_def)
hoelzl@50387
   215
hoelzl@50387
   216
declare
hoelzl@50387
   217
  sets.Int[measurable (raw)]
hoelzl@50387
   218
hoelzl@50387
   219
lemma pred_in_If[measurable (raw)]:
hoelzl@50387
   220
  "(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
   221
    pred M (\<lambda>x. x \<in> (if P then A x else B x))"
hoelzl@50387
   222
  by auto
hoelzl@50387
   223
hoelzl@50387
   224
lemma sets_range[measurable_dest]:
hoelzl@50387
   225
  "A ` I \<subseteq> sets M \<Longrightarrow> i \<in> I \<Longrightarrow> A i \<in> sets M"
hoelzl@50387
   226
  by auto
hoelzl@50387
   227
hoelzl@50387
   228
lemma pred_sets_range[measurable_dest]:
hoelzl@50387
   229
  "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
   230
  using pred_sets2[OF sets_range] by auto
hoelzl@50387
   231
hoelzl@50387
   232
lemma sets_All[measurable_dest]:
hoelzl@50387
   233
  "\<forall>i. A i \<in> sets (M i) \<Longrightarrow> A i \<in> sets (M i)"
hoelzl@50387
   234
  by auto
hoelzl@50387
   235
hoelzl@50387
   236
lemma pred_sets_All[measurable_dest]:
hoelzl@50387
   237
  "\<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
   238
  using pred_sets2[OF sets_All, of A N f] by auto
hoelzl@50387
   239
hoelzl@50387
   240
lemma sets_Ball[measurable_dest]:
hoelzl@50387
   241
  "\<forall>i\<in>I. A i \<in> sets (M i) \<Longrightarrow> i\<in>I \<Longrightarrow> A i \<in> sets (M i)"
hoelzl@50387
   242
  by auto
hoelzl@50387
   243
hoelzl@50387
   244
lemma pred_sets_Ball[measurable_dest]:
hoelzl@50387
   245
  "\<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
   246
  using pred_sets2[OF sets_Ball, of _ _ _ f] by auto
hoelzl@50387
   247
hoelzl@50387
   248
lemma measurable_finite[measurable (raw)]:
hoelzl@50387
   249
  fixes S :: "'a \<Rightarrow> nat set"
hoelzl@50387
   250
  assumes [measurable]: "\<And>i. {x\<in>space M. i \<in> S x} \<in> sets M"
hoelzl@50387
   251
  shows "pred M (\<lambda>x. finite (S x))"
hoelzl@50387
   252
  unfolding finite_nat_set_iff_bounded by (simp add: Ball_def)
hoelzl@50387
   253
hoelzl@50387
   254
lemma measurable_Least[measurable]:
hoelzl@50387
   255
  assumes [measurable]: "(\<And>i::nat. (\<lambda>x. P i x) \<in> measurable M (count_space UNIV))"q
hoelzl@50387
   256
  shows "(\<lambda>x. LEAST i. P i x) \<in> measurable M (count_space UNIV)"
hoelzl@50387
   257
  unfolding measurable_def by (safe intro!: sets_Least) simp_all
hoelzl@50387
   258
hoelzl@56993
   259
lemma measurable_Max_nat[measurable (raw)]: 
hoelzl@56993
   260
  fixes P :: "nat \<Rightarrow> 'a \<Rightarrow> bool"
hoelzl@56993
   261
  assumes [measurable]: "\<And>i. Measurable.pred M (P i)"
hoelzl@56993
   262
  shows "(\<lambda>x. Max {i. P i x}) \<in> measurable M (count_space UNIV)"
hoelzl@56993
   263
  unfolding measurable_count_space_eq2_countable
hoelzl@56993
   264
proof safe
hoelzl@56993
   265
  fix n
hoelzl@56993
   266
hoelzl@56993
   267
  { fix x assume "\<forall>i. \<exists>n\<ge>i. P n x"
hoelzl@56993
   268
    then have "infinite {i. P i x}"
hoelzl@56993
   269
      unfolding infinite_nat_iff_unbounded_le by auto
hoelzl@56993
   270
    then have "Max {i. P i x} = the None"
hoelzl@56993
   271
      by (rule Max.infinite) }
hoelzl@56993
   272
  note 1 = this
hoelzl@56993
   273
hoelzl@56993
   274
  { fix x i j assume "P i x" "\<forall>n\<ge>j. \<not> P n x"
hoelzl@56993
   275
    then have "finite {i. P i x}"
hoelzl@56993
   276
      by (auto simp: subset_eq not_le[symmetric] finite_nat_iff_bounded)
hoelzl@56993
   277
    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
   278
      using Max_in[of "{i. P i x}"] by auto }
hoelzl@56993
   279
  note 2 = this
hoelzl@56993
   280
hoelzl@56993
   281
  have "(\<lambda>x. Max {i. P i x}) -` {n} \<inter> space M = {x\<in>space M. Max {i. P i x} = n}"
hoelzl@56993
   282
    by auto
hoelzl@56993
   283
  also have "\<dots> = 
hoelzl@56993
   284
    {x\<in>space M. if (\<forall>i. \<exists>n\<ge>i. P n x) then the None = n else 
hoelzl@56993
   285
      if (\<exists>i. P i x) then P n x \<and> (\<forall>i>n. \<not> P i x)
hoelzl@56993
   286
      else Max {} = n}"
hoelzl@56993
   287
    by (intro arg_cong[where f=Collect] ext conj_cong)
hoelzl@56993
   288
       (auto simp add: 1 2 not_le[symmetric] intro!: Max_eqI)
hoelzl@56993
   289
  also have "\<dots> \<in> sets M"
hoelzl@56993
   290
    by measurable
hoelzl@56993
   291
  finally show "(\<lambda>x. Max {i. P i x}) -` {n} \<inter> space M \<in> sets M" .
hoelzl@56993
   292
qed simp
hoelzl@56993
   293
hoelzl@56993
   294
lemma measurable_Min_nat[measurable (raw)]: 
hoelzl@56993
   295
  fixes P :: "nat \<Rightarrow> 'a \<Rightarrow> bool"
hoelzl@56993
   296
  assumes [measurable]: "\<And>i. Measurable.pred M (P i)"
hoelzl@56993
   297
  shows "(\<lambda>x. Min {i. P i x}) \<in> measurable M (count_space UNIV)"
hoelzl@56993
   298
  unfolding measurable_count_space_eq2_countable
hoelzl@56993
   299
proof safe
hoelzl@56993
   300
  fix n
hoelzl@56993
   301
hoelzl@56993
   302
  { fix x assume "\<forall>i. \<exists>n\<ge>i. P n x"
hoelzl@56993
   303
    then have "infinite {i. P i x}"
hoelzl@56993
   304
      unfolding infinite_nat_iff_unbounded_le by auto
hoelzl@56993
   305
    then have "Min {i. P i x} = the None"
hoelzl@56993
   306
      by (rule Min.infinite) }
hoelzl@56993
   307
  note 1 = this
hoelzl@56993
   308
hoelzl@56993
   309
  { fix x i j assume "P i x" "\<forall>n\<ge>j. \<not> P n x"
hoelzl@56993
   310
    then have "finite {i. P i x}"
hoelzl@56993
   311
      by (auto simp: subset_eq not_le[symmetric] finite_nat_iff_bounded)
hoelzl@56993
   312
    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
   313
      using Min_in[of "{i. P i x}"] by auto }
hoelzl@56993
   314
  note 2 = this
hoelzl@56993
   315
hoelzl@56993
   316
  have "(\<lambda>x. Min {i. P i x}) -` {n} \<inter> space M = {x\<in>space M. Min {i. P i x} = n}"
hoelzl@56993
   317
    by auto
hoelzl@56993
   318
  also have "\<dots> = 
hoelzl@56993
   319
    {x\<in>space M. if (\<forall>i. \<exists>n\<ge>i. P n x) then the None = n else 
hoelzl@56993
   320
      if (\<exists>i. P i x) then P n x \<and> (\<forall>i<n. \<not> P i x)
hoelzl@56993
   321
      else Min {} = n}"
hoelzl@56993
   322
    by (intro arg_cong[where f=Collect] ext conj_cong)
hoelzl@56993
   323
       (auto simp add: 1 2 not_le[symmetric] intro!: Min_eqI)
hoelzl@56993
   324
  also have "\<dots> \<in> sets M"
hoelzl@56993
   325
    by measurable
hoelzl@56993
   326
  finally show "(\<lambda>x. Min {i. P i x}) -` {n} \<inter> space M \<in> sets M" .
hoelzl@56993
   327
qed simp
hoelzl@56993
   328
hoelzl@50387
   329
lemma measurable_count_space_insert[measurable (raw)]:
hoelzl@50387
   330
  "s \<in> S \<Longrightarrow> A \<in> sets (count_space S) \<Longrightarrow> insert s A \<in> sets (count_space S)"
hoelzl@50387
   331
  by simp
hoelzl@50387
   332
hoelzl@57025
   333
lemma measurable_card[measurable]:
hoelzl@57025
   334
  fixes S :: "'a \<Rightarrow> nat set"
hoelzl@57025
   335
  assumes [measurable]: "\<And>i. {x\<in>space M. i \<in> S x} \<in> sets M"
hoelzl@57025
   336
  shows "(\<lambda>x. card (S x)) \<in> measurable M (count_space UNIV)"
hoelzl@57025
   337
  unfolding measurable_count_space_eq2_countable
hoelzl@57025
   338
proof safe
hoelzl@57025
   339
  fix n show "(\<lambda>x. card (S x)) -` {n} \<inter> space M \<in> sets M"
hoelzl@57025
   340
  proof (cases n)
hoelzl@57025
   341
    case 0
hoelzl@57025
   342
    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
   343
      by auto
hoelzl@57025
   344
    also have "\<dots> \<in> sets M"
hoelzl@57025
   345
      by measurable
hoelzl@57025
   346
    finally show ?thesis .
hoelzl@57025
   347
  next
hoelzl@57025
   348
    case (Suc i)
hoelzl@57025
   349
    then have "(\<lambda>x. card (S x)) -` {n} \<inter> space M =
hoelzl@57025
   350
      (\<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
   351
      unfolding set_eq_iff[symmetric] Collect_bex_eq[symmetric] by (auto intro: card_ge_0_finite)
hoelzl@57025
   352
    also have "\<dots> \<in> sets M"
hoelzl@57025
   353
      by (intro sets.countable_UN' countable_Collect countable_Collect_finite) auto
hoelzl@57025
   354
    finally show ?thesis .
hoelzl@57025
   355
  qed
hoelzl@57025
   356
qed rule
hoelzl@57025
   357
hoelzl@56021
   358
subsection {* Measurability for (co)inductive predicates *}
hoelzl@56021
   359
hoelzl@56021
   360
lemma measurable_lfp:
hoelzl@56021
   361
  assumes "Order_Continuity.continuous F"
hoelzl@56021
   362
  assumes *: "\<And>A. pred M A \<Longrightarrow> pred M (F A)"
hoelzl@56045
   363
  shows "pred M (lfp F)"
hoelzl@56021
   364
proof -
hoelzl@56021
   365
  { fix i have "Measurable.pred M (\<lambda>x. (F ^^ i) (\<lambda>x. False) x)"
hoelzl@56021
   366
      by (induct i) (auto intro!: *) }
hoelzl@56021
   367
  then have "Measurable.pred M (\<lambda>x. \<exists>i. (F ^^ i) (\<lambda>x. False) x)"
hoelzl@56021
   368
    by measurable
hoelzl@56021
   369
  also have "(\<lambda>x. \<exists>i. (F ^^ i) (\<lambda>x. False) x) = (SUP i. (F ^^ i) bot)"
hoelzl@56021
   370
    by (auto simp add: bot_fun_def)
hoelzl@56045
   371
  also have "\<dots> = lfp F"
hoelzl@56045
   372
    by (rule continuous_lfp[symmetric]) fact
hoelzl@56021
   373
  finally show ?thesis .
hoelzl@56021
   374
qed
hoelzl@56021
   375
hoelzl@56021
   376
lemma measurable_gfp:
hoelzl@56021
   377
  assumes "Order_Continuity.down_continuous F"
hoelzl@56021
   378
  assumes *: "\<And>A. pred M A \<Longrightarrow> pred M (F A)"
hoelzl@56045
   379
  shows "pred M (gfp F)"
hoelzl@56021
   380
proof -
hoelzl@56021
   381
  { fix i have "Measurable.pred M (\<lambda>x. (F ^^ i) (\<lambda>x. True) x)"
hoelzl@56021
   382
      by (induct i) (auto intro!: *) }
hoelzl@56021
   383
  then have "Measurable.pred M (\<lambda>x. \<forall>i. (F ^^ i) (\<lambda>x. True) x)"
hoelzl@56021
   384
    by measurable
hoelzl@56021
   385
  also have "(\<lambda>x. \<forall>i. (F ^^ i) (\<lambda>x. True) x) = (INF i. (F ^^ i) top)"
hoelzl@56021
   386
    by (auto simp add: top_fun_def)
hoelzl@56045
   387
  also have "\<dots> = gfp F"
hoelzl@56045
   388
    by (rule down_continuous_gfp[symmetric]) fact
hoelzl@56021
   389
  finally show ?thesis .
hoelzl@56021
   390
qed
hoelzl@56021
   391
hoelzl@50387
   392
hide_const (open) pred
hoelzl@50387
   393
hoelzl@50387
   394
end