src/HOL/Probability/Measurable.thy
changeset 50387 3d8863c41fe8
child 50530 6266e44b3396
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Probability/Measurable.thy	Wed Dec 05 15:59:08 2012 +0100
     1.3 @@ -0,0 +1,247 @@
     1.4 +(*  Title:      HOL/Probability/measurable.ML
     1.5 +    Author:     Johannes Hölzl <hoelzl@in.tum.de>
     1.6 +*)
     1.7 +theory Measurable
     1.8 +  imports Sigma_Algebra
     1.9 +begin
    1.10 +
    1.11 +subsection {* Measurability prover *}
    1.12 +
    1.13 +lemma (in algebra) sets_Collect_finite_All:
    1.14 +  assumes "\<And>i. i \<in> S \<Longrightarrow> {x\<in>\<Omega>. P i x} \<in> M" "finite S"
    1.15 +  shows "{x\<in>\<Omega>. \<forall>i\<in>S. P i x} \<in> M"
    1.16 +proof -
    1.17 +  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})"
    1.18 +    by auto
    1.19 +  with assms show ?thesis by (auto intro!: sets_Collect_finite_All')
    1.20 +qed
    1.21 +
    1.22 +abbreviation "pred M P \<equiv> P \<in> measurable M (count_space (UNIV::bool set))"
    1.23 +
    1.24 +lemma pred_def: "pred M P \<longleftrightarrow> {x\<in>space M. P x} \<in> sets M"
    1.25 +proof
    1.26 +  assume "pred M P"
    1.27 +  then have "P -` {True} \<inter> space M \<in> sets M"
    1.28 +    by (auto simp: measurable_count_space_eq2)
    1.29 +  also have "P -` {True} \<inter> space M = {x\<in>space M. P x}" by auto
    1.30 +  finally show "{x\<in>space M. P x} \<in> sets M" .
    1.31 +next
    1.32 +  assume P: "{x\<in>space M. P x} \<in> sets M"
    1.33 +  moreover
    1.34 +  { fix X
    1.35 +    have "X \<in> Pow (UNIV :: bool set)" by simp
    1.36 +    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> {})}"
    1.37 +      unfolding UNIV_bool Pow_insert Pow_empty by auto
    1.38 +    then have "P -` X \<inter> space M \<in> sets M"
    1.39 +      by (auto intro!: sets.sets_Collect_neg sets.sets_Collect_imp sets.sets_Collect_conj sets.sets_Collect_const P) }
    1.40 +  then show "pred M P"
    1.41 +    by (auto simp: measurable_def)
    1.42 +qed
    1.43 +
    1.44 +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))"
    1.45 +  by (rule measurable_compose[where f=f and N=M]) (auto simp: pred_def)
    1.46 +
    1.47 +lemma pred_sets2: "A \<in> sets N \<Longrightarrow> f \<in> measurable M N \<Longrightarrow> pred M (\<lambda>x. f x \<in> A)"
    1.48 +  by (rule measurable_compose[where f=f and N=N]) (auto simp: pred_def Int_def[symmetric])
    1.49 +
    1.50 +ML_file "measurable.ML"
    1.51 +
    1.52 +attribute_setup measurable = {* Measurable.attr *} "declaration of measurability theorems"
    1.53 +attribute_setup measurable_dest = {* Measurable.dest_attr *} "add dest rule for measurability prover"
    1.54 +attribute_setup measurable_app = {* Measurable.app_attr *} "add application rule for measurability prover"
    1.55 +method_setup measurable = {* Measurable.method *} "measurability prover"
    1.56 +simproc_setup measurable ("A \<in> sets M" | "f \<in> measurable M N") = {* K Measurable.simproc *}
    1.57 +
    1.58 +declare
    1.59 +  measurable_compose_rev[measurable_dest]
    1.60 +  pred_sets1[measurable_dest]
    1.61 +  pred_sets2[measurable_dest]
    1.62 +  sets.sets_into_space[measurable_dest]
    1.63 +
    1.64 +declare
    1.65 +  sets.top[measurable]
    1.66 +  sets.empty_sets[measurable (raw)]
    1.67 +  sets.Un[measurable (raw)]
    1.68 +  sets.Diff[measurable (raw)]
    1.69 +
    1.70 +declare
    1.71 +  measurable_count_space[measurable (raw)]
    1.72 +  measurable_ident[measurable (raw)]
    1.73 +  measurable_ident_sets[measurable (raw)]
    1.74 +  measurable_const[measurable (raw)]
    1.75 +  measurable_If[measurable (raw)]
    1.76 +  measurable_comp[measurable (raw)]
    1.77 +  measurable_sets[measurable (raw)]
    1.78 +
    1.79 +lemma predE[measurable (raw)]: 
    1.80 +  "pred M P \<Longrightarrow> {x\<in>space M. P x} \<in> sets M"
    1.81 +  unfolding pred_def .
    1.82 +
    1.83 +lemma pred_intros_imp'[measurable (raw)]:
    1.84 +  "(K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. K \<longrightarrow> P x)"
    1.85 +  by (cases K) auto
    1.86 +
    1.87 +lemma pred_intros_conj1'[measurable (raw)]:
    1.88 +  "(K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. K \<and> P x)"
    1.89 +  by (cases K) auto
    1.90 +
    1.91 +lemma pred_intros_conj2'[measurable (raw)]:
    1.92 +  "(K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. P x \<and> K)"
    1.93 +  by (cases K) auto
    1.94 +
    1.95 +lemma pred_intros_disj1'[measurable (raw)]:
    1.96 +  "(\<not> K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. K \<or> P x)"
    1.97 +  by (cases K) auto
    1.98 +
    1.99 +lemma pred_intros_disj2'[measurable (raw)]:
   1.100 +  "(\<not> K \<Longrightarrow> pred M (\<lambda>x. P x)) \<Longrightarrow> pred M (\<lambda>x. P x \<or> K)"
   1.101 +  by (cases K) auto
   1.102 +
   1.103 +lemma pred_intros_logic[measurable (raw)]:
   1.104 +  "pred M (\<lambda>x. x \<in> space M)"
   1.105 +  "pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. \<not> P x)"
   1.106 +  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x \<and> P x)"
   1.107 +  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x \<longrightarrow> P x)"
   1.108 +  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x \<or> P x)"
   1.109 +  "pred M (\<lambda>x. Q x) \<Longrightarrow> pred M (\<lambda>x. P x) \<Longrightarrow> pred M (\<lambda>x. Q x = P x)"
   1.110 +  "pred M (\<lambda>x. f x \<in> UNIV)"
   1.111 +  "pred M (\<lambda>x. f x \<in> {})"
   1.112 +  "pred M (\<lambda>x. P' (f x) x) \<Longrightarrow> pred M (\<lambda>x. f x \<in> {y. P' y x})"
   1.113 +  "pred M (\<lambda>x. f x \<in> (B x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> - (B x))"
   1.114 +  "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))"
   1.115 +  "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))"
   1.116 +  "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))"
   1.117 +  "pred M (\<lambda>x. g x (f x) \<in> (X x)) \<Longrightarrow> pred M (\<lambda>x. f x \<in> (g x) -` (X x))"
   1.118 +  by (auto simp: iff_conv_conj_imp pred_def)
   1.119 +
   1.120 +lemma pred_intros_countable[measurable (raw)]:
   1.121 +  fixes P :: "'a \<Rightarrow> 'i :: countable \<Rightarrow> bool"
   1.122 +  shows 
   1.123 +    "(\<And>i. pred M (\<lambda>x. P x i)) \<Longrightarrow> pred M (\<lambda>x. \<forall>i. P x i)"
   1.124 +    "(\<And>i. pred M (\<lambda>x. P x i)) \<Longrightarrow> pred M (\<lambda>x. \<exists>i. P x i)"
   1.125 +  by (auto intro!: sets.sets_Collect_countable_All sets.sets_Collect_countable_Ex simp: pred_def)
   1.126 +
   1.127 +lemma pred_intros_countable_bounded[measurable (raw)]:
   1.128 +  fixes X :: "'i :: countable set"
   1.129 +  shows 
   1.130 +    "(\<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))"
   1.131 +    "(\<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))"
   1.132 +    "(\<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)"
   1.133 +    "(\<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)"
   1.134 +  by (auto simp: Bex_def Ball_def)
   1.135 +
   1.136 +lemma pred_intros_finite[measurable (raw)]:
   1.137 +  "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))"
   1.138 +  "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))"
   1.139 +  "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)"
   1.140 +  "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)"
   1.141 +  by (auto intro!: sets.sets_Collect_finite_Ex sets.sets_Collect_finite_All simp: iff_conv_conj_imp pred_def)
   1.142 +
   1.143 +lemma countable_Un_Int[measurable (raw)]:
   1.144 +  "(\<And>i :: 'i :: countable. i \<in> I \<Longrightarrow> N i \<in> sets M) \<Longrightarrow> (\<Union>i\<in>I. N i) \<in> sets M"
   1.145 +  "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"
   1.146 +  by auto
   1.147 +
   1.148 +declare
   1.149 +  finite_UN[measurable (raw)]
   1.150 +  finite_INT[measurable (raw)]
   1.151 +
   1.152 +lemma sets_Int_pred[measurable (raw)]:
   1.153 +  assumes space: "A \<inter> B \<subseteq> space M" and [measurable]: "pred M (\<lambda>x. x \<in> A)" "pred M (\<lambda>x. x \<in> B)"
   1.154 +  shows "A \<inter> B \<in> sets M"
   1.155 +proof -
   1.156 +  have "{x\<in>space M. x \<in> A \<inter> B} \<in> sets M" by auto
   1.157 +  also have "{x\<in>space M. x \<in> A \<inter> B} = A \<inter> B"
   1.158 +    using space by auto
   1.159 +  finally show ?thesis .
   1.160 +qed
   1.161 +
   1.162 +lemma [measurable (raw generic)]:
   1.163 +  assumes f: "f \<in> measurable M N" and c: "c \<in> space N \<Longrightarrow> {c} \<in> sets N"
   1.164 +  shows pred_eq_const1: "pred M (\<lambda>x. f x = c)"
   1.165 +    and pred_eq_const2: "pred M (\<lambda>x. c = f x)"
   1.166 +proof -
   1.167 +  show "pred M (\<lambda>x. f x = c)"
   1.168 +  proof cases
   1.169 +    assume "c \<in> space N"
   1.170 +    with measurable_sets[OF f c] show ?thesis
   1.171 +      by (auto simp: Int_def conj_commute pred_def)
   1.172 +  next
   1.173 +    assume "c \<notin> space N"
   1.174 +    with f[THEN measurable_space] have "{x \<in> space M. f x = c} = {}" by auto
   1.175 +    then show ?thesis by (auto simp: pred_def cong: conj_cong)
   1.176 +  qed
   1.177 +  then show "pred M (\<lambda>x. c = f x)"
   1.178 +    by (simp add: eq_commute)
   1.179 +qed
   1.180 +
   1.181 +lemma pred_le_const[measurable (raw generic)]:
   1.182 +  assumes f: "f \<in> measurable M N" and c: "{.. c} \<in> sets N" shows "pred M (\<lambda>x. f x \<le> c)"
   1.183 +  using measurable_sets[OF f c]
   1.184 +  by (auto simp: Int_def conj_commute eq_commute pred_def)
   1.185 +
   1.186 +lemma pred_const_le[measurable (raw generic)]:
   1.187 +  assumes f: "f \<in> measurable M N" and c: "{c ..} \<in> sets N" shows "pred M (\<lambda>x. c \<le> f x)"
   1.188 +  using measurable_sets[OF f c]
   1.189 +  by (auto simp: Int_def conj_commute eq_commute pred_def)
   1.190 +
   1.191 +lemma pred_less_const[measurable (raw generic)]:
   1.192 +  assumes f: "f \<in> measurable M N" and c: "{..< c} \<in> sets N" shows "pred M (\<lambda>x. f x < c)"
   1.193 +  using measurable_sets[OF f c]
   1.194 +  by (auto simp: Int_def conj_commute eq_commute pred_def)
   1.195 +
   1.196 +lemma pred_const_less[measurable (raw generic)]:
   1.197 +  assumes f: "f \<in> measurable M N" and c: "{c <..} \<in> sets N" shows "pred M (\<lambda>x. c < f x)"
   1.198 +  using measurable_sets[OF f c]
   1.199 +  by (auto simp: Int_def conj_commute eq_commute pred_def)
   1.200 +
   1.201 +declare
   1.202 +  sets.Int[measurable (raw)]
   1.203 +
   1.204 +lemma pred_in_If[measurable (raw)]:
   1.205 +  "(P \<Longrightarrow> pred M (\<lambda>x. x \<in> A x)) \<Longrightarrow> (\<not> P \<Longrightarrow> pred M (\<lambda>x. x \<in> B x)) \<Longrightarrow>
   1.206 +    pred M (\<lambda>x. x \<in> (if P then A x else B x))"
   1.207 +  by auto
   1.208 +
   1.209 +lemma sets_range[measurable_dest]:
   1.210 +  "A ` I \<subseteq> sets M \<Longrightarrow> i \<in> I \<Longrightarrow> A i \<in> sets M"
   1.211 +  by auto
   1.212 +
   1.213 +lemma pred_sets_range[measurable_dest]:
   1.214 +  "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)"
   1.215 +  using pred_sets2[OF sets_range] by auto
   1.216 +
   1.217 +lemma sets_All[measurable_dest]:
   1.218 +  "\<forall>i. A i \<in> sets (M i) \<Longrightarrow> A i \<in> sets (M i)"
   1.219 +  by auto
   1.220 +
   1.221 +lemma pred_sets_All[measurable_dest]:
   1.222 +  "\<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)"
   1.223 +  using pred_sets2[OF sets_All, of A N f] by auto
   1.224 +
   1.225 +lemma sets_Ball[measurable_dest]:
   1.226 +  "\<forall>i\<in>I. A i \<in> sets (M i) \<Longrightarrow> i\<in>I \<Longrightarrow> A i \<in> sets (M i)"
   1.227 +  by auto
   1.228 +
   1.229 +lemma pred_sets_Ball[measurable_dest]:
   1.230 +  "\<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)"
   1.231 +  using pred_sets2[OF sets_Ball, of _ _ _ f] by auto
   1.232 +
   1.233 +lemma measurable_finite[measurable (raw)]:
   1.234 +  fixes S :: "'a \<Rightarrow> nat set"
   1.235 +  assumes [measurable]: "\<And>i. {x\<in>space M. i \<in> S x} \<in> sets M"
   1.236 +  shows "pred M (\<lambda>x. finite (S x))"
   1.237 +  unfolding finite_nat_set_iff_bounded by (simp add: Ball_def)
   1.238 +
   1.239 +lemma measurable_Least[measurable]:
   1.240 +  assumes [measurable]: "(\<And>i::nat. (\<lambda>x. P i x) \<in> measurable M (count_space UNIV))"q
   1.241 +  shows "(\<lambda>x. LEAST i. P i x) \<in> measurable M (count_space UNIV)"
   1.242 +  unfolding measurable_def by (safe intro!: sets_Least) simp_all
   1.243 +
   1.244 +lemma measurable_count_space_insert[measurable (raw)]:
   1.245 +  "s \<in> S \<Longrightarrow> A \<in> sets (count_space S) \<Longrightarrow> insert s A \<in> sets (count_space S)"
   1.246 +  by simp
   1.247 +
   1.248 +hide_const (open) pred
   1.249 +
   1.250 +end