159 |
159 |
160 context includes lifting_syntax |
160 context includes lifting_syntax |
161 begin |
161 begin |
162 |
162 |
163 definition rel_pred :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'b set \<Rightarrow> bool" |
163 definition rel_pred :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'b set \<Rightarrow> bool" |
164 where "rel_pred R A B = (R ===> op =) (\<lambda>x. x \<in> A) (\<lambda>y. y \<in> B)" |
164 where "rel_pred R A B = (R ===> (=)) (\<lambda>x. x \<in> A) (\<lambda>y. y \<in> B)" |
165 |
165 |
166 lemma rel_predI: "(R ===> op =) (\<lambda>x. x \<in> A) (\<lambda>y. y \<in> B) \<Longrightarrow> rel_pred R A B" |
166 lemma rel_predI: "(R ===> (=)) (\<lambda>x. x \<in> A) (\<lambda>y. y \<in> B) \<Longrightarrow> rel_pred R A B" |
167 by(simp add: rel_pred_def) |
167 by(simp add: rel_pred_def) |
168 |
168 |
169 lemma rel_predD: "\<lbrakk> rel_pred R A B; R x y \<rbrakk> \<Longrightarrow> x \<in> A \<longleftrightarrow> y \<in> B" |
169 lemma rel_predD: "\<lbrakk> rel_pred R A B; R x y \<rbrakk> \<Longrightarrow> x \<in> A \<longleftrightarrow> y \<in> B" |
170 by(simp add: rel_pred_def rel_fun_def) |
170 by(simp add: rel_pred_def rel_fun_def) |
171 |
171 |
172 lemma Collect_parametric: "((A ===> op =) ===> rel_pred A) Collect Collect" |
172 lemma Collect_parametric: "((A ===> (=)) ===> rel_pred A) Collect Collect" |
173 \<comment> \<open>Declare this rule as @{attribute transfer_rule} only locally |
173 \<comment> \<open>Declare this rule as @{attribute transfer_rule} only locally |
174 because it blows up the search space for @{method transfer} |
174 because it blows up the search space for @{method transfer} |
175 (in combination with @{thm [source] Collect_transfer})\<close> |
175 (in combination with @{thm [source] Collect_transfer})\<close> |
176 by(simp add: rel_funI rel_predI) |
176 by(simp add: rel_funI rel_predI) |
177 |
177 |
178 end |
178 end |
179 |
179 |
180 subsubsection \<open>Monotonicity rules\<close> |
180 subsubsection \<open>Monotonicity rules\<close> |
181 |
181 |
182 lemma monotone_gfp_eadd1: "monotone op \<ge> op \<ge> (\<lambda>x. x + y :: enat)" |
182 lemma monotone_gfp_eadd1: "monotone (\<ge>) (\<ge>) (\<lambda>x. x + y :: enat)" |
183 by(auto intro!: monotoneI) |
183 by(auto intro!: monotoneI) |
184 |
184 |
185 lemma monotone_gfp_eadd2: "monotone op \<ge> op \<ge> (\<lambda>y. x + y :: enat)" |
185 lemma monotone_gfp_eadd2: "monotone (\<ge>) (\<ge>) (\<lambda>y. x + y :: enat)" |
186 by(auto intro!: monotoneI) |
186 by(auto intro!: monotoneI) |
187 |
187 |
188 lemma mono2mono_gfp_eadd[THEN gfp.mono2mono2, cont_intro, simp]: |
188 lemma mono2mono_gfp_eadd[THEN gfp.mono2mono2, cont_intro, simp]: |
189 shows monotone_eadd: "monotone (rel_prod op \<ge> op \<ge>) op \<ge> (\<lambda>(x, y). x + y :: enat)" |
189 shows monotone_eadd: "monotone (rel_prod (\<ge>) (\<ge>)) (\<ge>) (\<lambda>(x, y). x + y :: enat)" |
190 by(simp add: monotone_gfp_eadd1 monotone_gfp_eadd2) |
190 by(simp add: monotone_gfp_eadd1 monotone_gfp_eadd2) |
191 |
191 |
192 lemma eadd_gfp_partial_function_mono [partial_function_mono]: |
192 lemma eadd_gfp_partial_function_mono [partial_function_mono]: |
193 "\<lbrakk> monotone (fun_ord op \<ge>) op \<ge> f; monotone (fun_ord op \<ge>) op \<ge> g \<rbrakk> |
193 "\<lbrakk> monotone (fun_ord (\<ge>)) (\<ge>) f; monotone (fun_ord (\<ge>)) (\<ge>) g \<rbrakk> |
194 \<Longrightarrow> monotone (fun_ord op \<ge>) op \<ge> (\<lambda>x. f x + g x :: enat)" |
194 \<Longrightarrow> monotone (fun_ord (\<ge>)) (\<ge>) (\<lambda>x. f x + g x :: enat)" |
195 by(rule mono2mono_gfp_eadd) |
195 by(rule mono2mono_gfp_eadd) |
196 |
196 |
197 lemma mono2mono_ereal[THEN lfp.mono2mono]: |
197 lemma mono2mono_ereal[THEN lfp.mono2mono]: |
198 shows monotone_ereal: "monotone op \<le> op \<le> ereal" |
198 shows monotone_ereal: "monotone (\<le>) (\<le>) ereal" |
199 by(rule monotoneI) simp |
199 by(rule monotoneI) simp |
200 |
200 |
201 lemma mono2mono_ennreal[THEN lfp.mono2mono]: |
201 lemma mono2mono_ennreal[THEN lfp.mono2mono]: |
202 shows monotone_ennreal: "monotone op \<le> op \<le> ennreal" |
202 shows monotone_ennreal: "monotone (\<le>) (\<le>) ennreal" |
203 by(rule monotoneI)(simp add: ennreal_leI) |
203 by(rule monotoneI)(simp add: ennreal_leI) |
204 |
204 |
205 subsubsection \<open>Bijections\<close> |
205 subsubsection \<open>Bijections\<close> |
206 |
206 |
207 lemma bi_unique_rel_set_bij_betw: |
207 lemma bi_unique_rel_set_bij_betw: |
764 context includes lifting_syntax |
764 context includes lifting_syntax |
765 begin |
765 begin |
766 |
766 |
767 text \<open>We do not yet have a relator for @{typ "'a measure"}, so we combine @{const measure} and @{const measure_pmf}\<close> |
767 text \<open>We do not yet have a relator for @{typ "'a measure"}, so we combine @{const measure} and @{const measure_pmf}\<close> |
768 lemma measure_pmf_parametric: |
768 lemma measure_pmf_parametric: |
769 "(rel_pmf A ===> rel_pred A ===> op =) (\<lambda>p. measure (measure_pmf p)) (\<lambda>q. measure (measure_pmf q))" |
769 "(rel_pmf A ===> rel_pred A ===> (=)) (\<lambda>p. measure (measure_pmf p)) (\<lambda>q. measure (measure_pmf q))" |
770 proof(rule rel_funI)+ |
770 proof(rule rel_funI)+ |
771 fix p q X Y |
771 fix p q X Y |
772 assume "rel_pmf A p q" and "rel_pred A X Y" |
772 assume "rel_pmf A p q" and "rel_pred A X Y" |
773 from this(1) obtain pq where A: "\<And>x y. (x, y) \<in> set_pmf pq \<Longrightarrow> A x y" |
773 from this(1) obtain pq where A: "\<And>x y. (x, y) \<in> set_pmf pq \<Longrightarrow> A x y" |
774 and p: "p = map_pmf fst pq" and q: "q = map_pmf snd pq" by cases auto |
774 and p: "p = map_pmf fst pq" and q: "q = map_pmf snd pq" by cases auto |
775 show "measure p X = measure q Y" unfolding p q measure_map_pmf |
775 show "measure p X = measure q Y" unfolding p q measure_map_pmf |
776 by(rule measure_pmf.finite_measure_eq_AE)(auto simp add: AE_measure_pmf_iff dest!: A rel_predD[OF \<open>rel_pred _ _ _\<close>]) |
776 by(rule measure_pmf.finite_measure_eq_AE)(auto simp add: AE_measure_pmf_iff dest!: A rel_predD[OF \<open>rel_pred _ _ _\<close>]) |
777 qed |
777 qed |
778 |
778 |
779 lemma measure_spmf_parametric: |
779 lemma measure_spmf_parametric: |
780 "(rel_spmf A ===> rel_pred A ===> op =) (\<lambda>p. measure (measure_spmf p)) (\<lambda>q. measure (measure_spmf q))" |
780 "(rel_spmf A ===> rel_pred A ===> (=)) (\<lambda>p. measure (measure_spmf p)) (\<lambda>q. measure (measure_spmf q))" |
781 unfolding measure_measure_spmf_conv_measure_pmf[abs_def] |
781 unfolding measure_measure_spmf_conv_measure_pmf[abs_def] |
782 apply(rule rel_funI)+ |
782 apply(rule rel_funI)+ |
783 apply(erule measure_pmf_parametric[THEN rel_funD, THEN rel_funD]) |
783 apply(erule measure_pmf_parametric[THEN rel_funD, THEN rel_funD]) |
784 apply(auto simp add: rel_pred_def rel_fun_def elim: option.rel_cases) |
784 apply(auto simp add: rel_pred_def rel_fun_def elim: option.rel_cases) |
785 done |
785 done |
1181 ennreal (pmf pq (None, Some y)) * indicator {None} x \<partial>count_space UNIV)" |
1181 ennreal (pmf pq (None, Some y)) * indicator {None} x \<partial>count_space UNIV)" |
1182 by(rule nn_integral_cong)(auto split: split_indicator) |
1182 by(rule nn_integral_cong)(auto split: split_indicator) |
1183 also have "\<dots> = (\<integral>\<^sup>+ x. ennreal (pmf pq (x, Some y)) * indicator (range Some) x \<partial>count_space UNIV) + pmf pq (None, Some y)" |
1183 also have "\<dots> = (\<integral>\<^sup>+ x. ennreal (pmf pq (x, Some y)) * indicator (range Some) x \<partial>count_space UNIV) + pmf pq (None, Some y)" |
1184 by(subst nn_integral_add)(simp_all) |
1184 by(subst nn_integral_add)(simp_all) |
1185 also have "\<dots> = (\<integral>\<^sup>+ x. ennreal (spmf p y) * indicator {Some y} x \<partial>count_space UNIV) + (spmf q y - spmf p y)" |
1185 also have "\<dots> = (\<integral>\<^sup>+ x. ennreal (spmf p y) * indicator {Some y} x \<partial>count_space UNIV) + (spmf q y - spmf p y)" |
1186 by(auto simp add: pq_def pmf_embed_pmf[OF f] one_ereal_def[symmetric] simp del: nn_integral_indicator_singleton intro!: arg_cong2[where f="op +"] nn_integral_cong split: option.split) |
1186 by(auto simp add: pq_def pmf_embed_pmf[OF f] one_ereal_def[symmetric] simp del: nn_integral_indicator_singleton intro!: arg_cong2[where f="(+)"] nn_integral_cong split: option.split) |
1187 also have "\<dots> = spmf q y" by(simp add: ennreal_minus[symmetric] le) |
1187 also have "\<dots> = spmf q y" by(simp add: ennreal_minus[symmetric] le) |
1188 finally show ?thesis using Some by simp |
1188 finally show ?thesis using Some by simp |
1189 qed |
1189 qed |
1190 finally show "pmf (map_pmf snd pq) i = pmf q i" by simp |
1190 finally show "pmf (map_pmf snd pq) i = pmf q i" by simp |
1191 qed |
1191 qed |
1192 qed |
1192 qed |
1193 |
1193 |
1194 lemma ord_spmf_eq_leD: |
1194 lemma ord_spmf_eq_leD: |
1195 assumes "ord_spmf op = p q" |
1195 assumes "ord_spmf (=) p q" |
1196 shows "spmf p x \<le> spmf q x" |
1196 shows "spmf p x \<le> spmf q x" |
1197 proof(cases "x \<in> set_spmf p") |
1197 proof(cases "x \<in> set_spmf p") |
1198 case False |
1198 case False |
1199 thus ?thesis by(simp add: in_set_spmf_iff_spmf) |
1199 thus ?thesis by(simp add: in_set_spmf_iff_spmf) |
1200 next |
1200 next |
1201 case True |
1201 case True |
1202 from assms obtain pq |
1202 from assms obtain pq |
1203 where pq: "\<And>x y. (x, y) \<in> set_pmf pq \<Longrightarrow> ord_option op = x y" |
1203 where pq: "\<And>x y. (x, y) \<in> set_pmf pq \<Longrightarrow> ord_option (=) x y" |
1204 and p: "p = map_pmf fst pq" |
1204 and p: "p = map_pmf fst pq" |
1205 and q: "q = map_pmf snd pq" by cases auto |
1205 and q: "q = map_pmf snd pq" by cases auto |
1206 have "ennreal (spmf p x) = integral\<^sup>N pq (indicator (fst -` {Some x}))" |
1206 have "ennreal (spmf p x) = integral\<^sup>N pq (indicator (fst -` {Some x}))" |
1207 using p by(simp add: ennreal_pmf_map) |
1207 using p by(simp add: ennreal_pmf_map) |
1208 also have "\<dots> = integral\<^sup>N pq (indicator {(Some x, Some x)})" |
1208 also have "\<dots> = integral\<^sup>N pq (indicator {(Some x, Some x)})" |
1211 by(rule nn_integral_mono) simp |
1211 by(rule nn_integral_mono) simp |
1212 also have "\<dots> = ennreal (spmf q x)" using q by(simp add: ennreal_pmf_map) |
1212 also have "\<dots> = ennreal (spmf q x)" using q by(simp add: ennreal_pmf_map) |
1213 finally show ?thesis by simp |
1213 finally show ?thesis by simp |
1214 qed |
1214 qed |
1215 |
1215 |
1216 lemma ord_spmf_eqD_set_spmf: "ord_spmf op = p q \<Longrightarrow> set_spmf p \<subseteq> set_spmf q" |
1216 lemma ord_spmf_eqD_set_spmf: "ord_spmf (=) p q \<Longrightarrow> set_spmf p \<subseteq> set_spmf q" |
1217 by(rule subsetI)(drule_tac x=x in ord_spmf_eq_leD, auto simp add: in_set_spmf_iff_spmf) |
1217 by(rule subsetI)(drule_tac x=x in ord_spmf_eq_leD, auto simp add: in_set_spmf_iff_spmf) |
1218 |
1218 |
1219 lemma ord_spmf_eqD_emeasure: |
1219 lemma ord_spmf_eqD_emeasure: |
1220 "ord_spmf op = p q \<Longrightarrow> emeasure (measure_spmf p) A \<le> emeasure (measure_spmf q) A" |
1220 "ord_spmf (=) p q \<Longrightarrow> emeasure (measure_spmf p) A \<le> emeasure (measure_spmf q) A" |
1221 by(auto intro!: nn_integral_mono split: split_indicator dest: ord_spmf_eq_leD simp add: nn_integral_measure_spmf nn_integral_indicator[symmetric]) |
1221 by(auto intro!: nn_integral_mono split: split_indicator dest: ord_spmf_eq_leD simp add: nn_integral_measure_spmf nn_integral_indicator[symmetric]) |
1222 |
1222 |
1223 lemma ord_spmf_eqD_measure_spmf: "ord_spmf op = p q \<Longrightarrow> measure_spmf p \<le> measure_spmf q" |
1223 lemma ord_spmf_eqD_measure_spmf: "ord_spmf (=) p q \<Longrightarrow> measure_spmf p \<le> measure_spmf q" |
1224 by (subst le_measure) (auto simp: ord_spmf_eqD_emeasure) |
1224 by (subst le_measure) (auto simp: ord_spmf_eqD_emeasure) |
1225 |
1225 |
1226 subsection \<open>CCPO structure for the flat ccpo @{term "ord_option op ="}\<close> |
1226 subsection \<open>CCPO structure for the flat ccpo @{term "ord_option (=)"}\<close> |
1227 |
1227 |
1228 context fixes Y :: "'a spmf set" begin |
1228 context fixes Y :: "'a spmf set" begin |
1229 |
1229 |
1230 definition lub_spmf :: "'a spmf" |
1230 definition lub_spmf :: "'a spmf" |
1231 where "lub_spmf = embed_spmf (\<lambda>x. enn2real (SUP p : Y. ennreal (spmf p x)))" |
1231 where "lub_spmf = embed_spmf (\<lambda>x. enn2real (SUP p : Y. ennreal (spmf p x)))" |
1232 \<comment> \<open>We go through @{typ ennreal} to have a sensible definition even if @{term Y} is empty.\<close> |
1232 \<comment> \<open>We go through @{typ ennreal} to have a sensible definition even if @{term Y} is empty.\<close> |
1233 |
1233 |
1234 lemma lub_spmf_empty [simp]: "SPMF.lub_spmf {} = return_pmf None" |
1234 lemma lub_spmf_empty [simp]: "SPMF.lub_spmf {} = return_pmf None" |
1235 by(simp add: SPMF.lub_spmf_def bot_ereal_def) |
1235 by(simp add: SPMF.lub_spmf_def bot_ereal_def) |
1236 |
1236 |
1237 context assumes chain: "Complete_Partial_Order.chain (ord_spmf op =) Y" begin |
1237 context assumes chain: "Complete_Partial_Order.chain (ord_spmf (=)) Y" begin |
1238 |
1238 |
1239 lemma chain_ord_spmf_eqD: "Complete_Partial_Order.chain (op \<le>) ((\<lambda>p x. ennreal (spmf p x)) ` Y)" |
1239 lemma chain_ord_spmf_eqD: "Complete_Partial_Order.chain (\<le>) ((\<lambda>p x. ennreal (spmf p x)) ` Y)" |
1240 (is "Complete_Partial_Order.chain _ (?f ` _)") |
1240 (is "Complete_Partial_Order.chain _ (?f ` _)") |
1241 proof(rule chainI) |
1241 proof(rule chainI) |
1242 fix f g |
1242 fix f g |
1243 assume "f \<in> ?f ` Y" "g \<in> ?f ` Y" |
1243 assume "f \<in> ?f ` Y" "g \<in> ?f ` Y" |
1244 then obtain p q where f: "f = ?f p" "p \<in> Y" and g: "g = ?f q" "q \<in> Y" by blast |
1244 then obtain p q where f: "f = ?f p" "p \<in> Y" and g: "g = ?f q" "q \<in> Y" by blast |
1245 from chain \<open>p \<in> Y\<close> \<open>q \<in> Y\<close> have "ord_spmf op = p q \<or> ord_spmf op = q p" by(rule chainD) |
1245 from chain \<open>p \<in> Y\<close> \<open>q \<in> Y\<close> have "ord_spmf (=) p q \<or> ord_spmf (=) q p" by(rule chainD) |
1246 thus "f \<le> g \<or> g \<le> f" |
1246 thus "f \<le> g \<or> g \<le> f" |
1247 proof |
1247 proof |
1248 assume "ord_spmf op = p q" |
1248 assume "ord_spmf (=) p q" |
1249 hence "\<And>x. spmf p x \<le> spmf q x" by(rule ord_spmf_eq_leD) |
1249 hence "\<And>x. spmf p x \<le> spmf q x" by(rule ord_spmf_eq_leD) |
1250 hence "f \<le> g" unfolding f g by(auto intro: le_funI) |
1250 hence "f \<le> g" unfolding f g by(auto intro: le_funI) |
1251 thus ?thesis .. |
1251 thus ?thesis .. |
1252 next |
1252 next |
1253 assume "ord_spmf op = q p" |
1253 assume "ord_spmf (=) q p" |
1254 hence "\<And>x. spmf q x \<le> spmf p x" by(rule ord_spmf_eq_leD) |
1254 hence "\<And>x. spmf q x \<le> spmf p x" by(rule ord_spmf_eq_leD) |
1255 hence "g \<le> f" unfolding f g by(auto intro: le_funI) |
1255 hence "g \<le> f" unfolding f g by(auto intro: le_funI) |
1256 thus ?thesis .. |
1256 thus ?thesis .. |
1257 qed |
1257 qed |
1258 qed |
1258 qed |
1259 |
1259 |
1260 lemma ord_spmf_eq_pmf_None_eq: |
1260 lemma ord_spmf_eq_pmf_None_eq: |
1261 assumes le: "ord_spmf op = p q" |
1261 assumes le: "ord_spmf (=) p q" |
1262 and None: "pmf p None = pmf q None" |
1262 and None: "pmf p None = pmf q None" |
1263 shows "p = q" |
1263 shows "p = q" |
1264 proof(rule spmf_eqI) |
1264 proof(rule spmf_eqI) |
1265 fix i |
1265 fix i |
1266 from le have le': "\<And>x. spmf p x \<le> spmf q x" by(rule ord_spmf_eq_leD) |
1266 from le have le': "\<And>x. spmf p x \<le> spmf q x" by(rule ord_spmf_eq_leD) |
1290 \<close> |
1290 \<close> |
1291 lemma spmf_chain_countable: "countable (\<Union>p\<in>Y. set_spmf p)" |
1291 lemma spmf_chain_countable: "countable (\<Union>p\<in>Y. set_spmf p)" |
1292 proof(cases "Y = {}") |
1292 proof(cases "Y = {}") |
1293 case Y: False |
1293 case Y: False |
1294 show ?thesis |
1294 show ?thesis |
1295 proof(cases "\<exists>x\<in>Y. \<forall>y\<in>Y. ord_spmf op = y x") |
1295 proof(cases "\<exists>x\<in>Y. \<forall>y\<in>Y. ord_spmf (=) y x") |
1296 case True |
1296 case True |
1297 then obtain x where x: "x \<in> Y" and upper: "\<And>y. y \<in> Y \<Longrightarrow> ord_spmf op = y x" by blast |
1297 then obtain x where x: "x \<in> Y" and upper: "\<And>y. y \<in> Y \<Longrightarrow> ord_spmf (=) y x" by blast |
1298 hence "(\<Union>x\<in>Y. set_spmf x) \<subseteq> set_spmf x" by(auto dest: ord_spmf_eqD_set_spmf) |
1298 hence "(\<Union>x\<in>Y. set_spmf x) \<subseteq> set_spmf x" by(auto dest: ord_spmf_eqD_set_spmf) |
1299 thus ?thesis by(rule countable_subset) simp |
1299 thus ?thesis by(rule countable_subset) simp |
1300 next |
1300 next |
1301 case False |
1301 case False |
1302 define N :: "'a option pmf \<Rightarrow> real" where "N p = pmf p None" for p |
1302 define N :: "'a option pmf \<Rightarrow> real" where "N p = pmf p None" for p |
1303 |
1303 |
1304 have N_less_imp_le_spmf: "\<lbrakk> x \<in> Y; y \<in> Y; N y < N x \<rbrakk> \<Longrightarrow> ord_spmf op = x y" for x y |
1304 have N_less_imp_le_spmf: "\<lbrakk> x \<in> Y; y \<in> Y; N y < N x \<rbrakk> \<Longrightarrow> ord_spmf (=) x y" for x y |
1305 using chainD[OF chain, of x y] ord_spmf_eqD_pmf_None[of x y] ord_spmf_eqD_pmf_None[of y x] |
1305 using chainD[OF chain, of x y] ord_spmf_eqD_pmf_None[of x y] ord_spmf_eqD_pmf_None[of y x] |
1306 by (auto simp: N_def) |
1306 by (auto simp: N_def) |
1307 have N_eq_imp_eq: "\<lbrakk> x \<in> Y; y \<in> Y; N y = N x \<rbrakk> \<Longrightarrow> x = y" for x y |
1307 have N_eq_imp_eq: "\<lbrakk> x \<in> Y; y \<in> Y; N y = N x \<rbrakk> \<Longrightarrow> x = y" for x y |
1308 using chainD[OF chain, of x y] by(auto simp add: N_def dest: ord_spmf_eq_pmf_None_eq) |
1308 using chainD[OF chain, of x y] by(auto simp add: N_def dest: ord_spmf_eq_pmf_None_eq) |
1309 |
1309 |
1392 lemma ennreal_spmf_lub_spmf: "Y \<noteq> {} \<Longrightarrow> ennreal (spmf lub_spmf x) = (SUP p:Y. ennreal (spmf p x))" |
1392 lemma ennreal_spmf_lub_spmf: "Y \<noteq> {} \<Longrightarrow> ennreal (spmf lub_spmf x) = (SUP p:Y. ennreal (spmf p x))" |
1393 unfolding spmf_lub_spmf by(subst ennreal_SUP)(simp_all add: SUP_spmf_neq_top' del: SUP_eq_top_iff Sup_eq_top_iff) |
1393 unfolding spmf_lub_spmf by(subst ennreal_SUP)(simp_all add: SUP_spmf_neq_top' del: SUP_eq_top_iff Sup_eq_top_iff) |
1394 |
1394 |
1395 lemma lub_spmf_upper: |
1395 lemma lub_spmf_upper: |
1396 assumes p: "p \<in> Y" |
1396 assumes p: "p \<in> Y" |
1397 shows "ord_spmf op = p lub_spmf" |
1397 shows "ord_spmf (=) p lub_spmf" |
1398 proof(rule ord_pmf_increaseI) |
1398 proof(rule ord_pmf_increaseI) |
1399 fix x |
1399 fix x |
1400 from p have [simp]: "Y \<noteq> {}" by auto |
1400 from p have [simp]: "Y \<noteq> {}" by auto |
1401 from p have "ennreal (spmf p x) \<le> (SUP p:Y. ennreal (spmf p x))" by(rule SUP_upper) |
1401 from p have "ennreal (spmf p x) \<le> (SUP p:Y. ennreal (spmf p x))" by(rule SUP_upper) |
1402 also have "\<dots> = ennreal (spmf lub_spmf x)" using p |
1402 also have "\<dots> = ennreal (spmf lub_spmf x)" using p |
1403 by(subst spmf_lub_spmf)(auto simp add: ennreal_SUP SUP_spmf_neq_top' simp del: SUP_eq_top_iff Sup_eq_top_iff) |
1403 by(subst spmf_lub_spmf)(auto simp add: ennreal_SUP SUP_spmf_neq_top' simp del: SUP_eq_top_iff Sup_eq_top_iff) |
1404 finally show "spmf p x \<le> spmf lub_spmf x" by simp |
1404 finally show "spmf p x \<le> spmf lub_spmf x" by simp |
1405 qed simp |
1405 qed simp |
1406 |
1406 |
1407 lemma lub_spmf_least: |
1407 lemma lub_spmf_least: |
1408 assumes z: "\<And>x. x \<in> Y \<Longrightarrow> ord_spmf op = x z" |
1408 assumes z: "\<And>x. x \<in> Y \<Longrightarrow> ord_spmf (=) x z" |
1409 shows "ord_spmf op = lub_spmf z" |
1409 shows "ord_spmf (=) lub_spmf z" |
1410 proof(cases "Y = {}") |
1410 proof(cases "Y = {}") |
1411 case nonempty: False |
1411 case nonempty: False |
1412 show ?thesis |
1412 show ?thesis |
1413 proof(rule ord_pmf_increaseI) |
1413 proof(rule ord_pmf_increaseI) |
1414 fix x |
1414 fix x |
1449 by(simp add: spmf_lub_spmf assms ennreal_SUP[OF SUP_spmf_neq_top'] SUP_mult_right_ennreal) |
1449 by(simp add: spmf_lub_spmf assms ennreal_SUP[OF SUP_spmf_neq_top'] SUP_mult_right_ennreal) |
1450 also from assms have "\<dots> = (SUP y:Y. \<integral>\<^sup>+ x. ennreal (spmf y x) * indicator A x \<partial>?M)" |
1450 also from assms have "\<dots> = (SUP y:Y. \<integral>\<^sup>+ x. ennreal (spmf y x) * indicator A x \<partial>?M)" |
1451 proof(rule nn_integral_monotone_convergence_SUP_countable) |
1451 proof(rule nn_integral_monotone_convergence_SUP_countable) |
1452 have "(\<lambda>i x. ennreal (spmf i x) * indicator A x) ` Y = (\<lambda>f x. f x * indicator A x) ` (\<lambda>p x. ennreal (spmf p x)) ` Y" |
1452 have "(\<lambda>i x. ennreal (spmf i x) * indicator A x) ` Y = (\<lambda>f x. f x * indicator A x) ` (\<lambda>p x. ennreal (spmf p x)) ` Y" |
1453 by(simp add: image_image) |
1453 by(simp add: image_image) |
1454 also have "Complete_Partial_Order.chain op \<le> \<dots>" using chain_ord_spmf_eqD |
1454 also have "Complete_Partial_Order.chain (\<le>) \<dots>" using chain_ord_spmf_eqD |
1455 by(rule chain_imageI)(auto simp add: le_fun_def split: split_indicator) |
1455 by(rule chain_imageI)(auto simp add: le_fun_def split: split_indicator) |
1456 finally show "Complete_Partial_Order.chain op \<le> ((\<lambda>i x. ennreal (spmf i x) * indicator A x) ` Y)" . |
1456 finally show "Complete_Partial_Order.chain (\<le>) ((\<lambda>i x. ennreal (spmf i x) * indicator A x) ` Y)" . |
1457 qed simp |
1457 qed simp |
1458 also have "\<dots> = (SUP y:Y. \<integral>\<^sup>+ x. ennreal (spmf y x) * indicator A x \<partial>count_space UNIV)" |
1458 also have "\<dots> = (SUP y:Y. \<integral>\<^sup>+ x. ennreal (spmf y x) * indicator A x \<partial>count_space UNIV)" |
1459 by(auto simp add: nn_integral_count_space_indicator set_lub_spmf spmf_eq_0_set_spmf split: split_indicator intro!: SUP_cong nn_integral_cong) |
1459 by(auto simp add: nn_integral_count_space_indicator set_lub_spmf spmf_eq_0_set_spmf split: split_indicator intro!: SUP_cong nn_integral_cong) |
1460 also have "\<dots> = ?rhs" |
1460 also have "\<dots> = ?rhs" |
1461 by(auto simp add: nn_integral_indicator[symmetric] nn_integral_measure_spmf) |
1461 by(auto simp add: nn_integral_indicator[symmetric] nn_integral_measure_spmf) |
1482 lemma measure_spmf_lub_spmf: |
1482 lemma measure_spmf_lub_spmf: |
1483 assumes Y: "Y \<noteq> {}" |
1483 assumes Y: "Y \<noteq> {}" |
1484 shows "measure_spmf lub_spmf = (SUP p:Y. measure_spmf p)" (is "?lhs = ?rhs") |
1484 shows "measure_spmf lub_spmf = (SUP p:Y. measure_spmf p)" (is "?lhs = ?rhs") |
1485 proof(rule measure_eqI) |
1485 proof(rule measure_eqI) |
1486 from assms obtain p where p: "p \<in> Y" by auto |
1486 from assms obtain p where p: "p \<in> Y" by auto |
1487 from chain have chain': "Complete_Partial_Order.chain op \<le> (measure_spmf ` Y)" |
1487 from chain have chain': "Complete_Partial_Order.chain (\<le>) (measure_spmf ` Y)" |
1488 by(rule chain_imageI)(rule ord_spmf_eqD_measure_spmf) |
1488 by(rule chain_imageI)(rule ord_spmf_eqD_measure_spmf) |
1489 show "sets ?lhs = sets ?rhs" |
1489 show "sets ?lhs = sets ?rhs" |
1490 using Y by (subst sets_SUP) auto |
1490 using Y by (subst sets_SUP) auto |
1491 show "emeasure ?lhs A = emeasure ?rhs A" for A |
1491 show "emeasure ?lhs A = emeasure ?rhs A" for A |
1492 using chain' Y p by (subst emeasure_SUP_chain) (auto simp: emeasure_lub_spmf) |
1492 using chain' Y p by (subst emeasure_SUP_chain) (auto simp: emeasure_lub_spmf) |
1519 assume "Complete_Partial_Order.chain ?R Y" "\<And>x. x \<in> Y \<Longrightarrow> ?R x z" |
1519 assume "Complete_Partial_Order.chain ?R Y" "\<And>x. x \<in> Y \<Longrightarrow> ?R x z" |
1520 then show "?R (lub_spmf Y) z" |
1520 then show "?R (lub_spmf Y) z" |
1521 by(cases "Y = {}")(simp_all add: lub_spmf_least) |
1521 by(cases "Y = {}")(simp_all add: lub_spmf_least) |
1522 qed |
1522 qed |
1523 |
1523 |
1524 lemma ccpo_spmf: "class.ccpo lub_spmf (ord_spmf op =) (mk_less (ord_spmf op =))" |
1524 lemma ccpo_spmf: "class.ccpo lub_spmf (ord_spmf (=)) (mk_less (ord_spmf (=)))" |
1525 by(rule ccpo partial_function_definitions_spmf)+ |
1525 by(rule ccpo partial_function_definitions_spmf)+ |
1526 |
1526 |
1527 interpretation spmf: partial_function_definitions "ord_spmf op =" "lub_spmf" |
1527 interpretation spmf: partial_function_definitions "ord_spmf (=)" "lub_spmf" |
1528 rewrites "lub_spmf {} \<equiv> return_pmf None" |
1528 rewrites "lub_spmf {} \<equiv> return_pmf None" |
1529 by(rule partial_function_definitions_spmf) simp |
1529 by(rule partial_function_definitions_spmf) simp |
1530 |
1530 |
1531 declaration \<open>Partial_Function.init "spmf" @{term spmf.fixp_fun} |
1531 declaration \<open>Partial_Function.init "spmf" @{term spmf.fixp_fun} |
1532 @{term spmf.mono_body} @{thm spmf.fixp_rule_uc} @{thm spmf.fixp_induct_uc} |
1532 @{term spmf.mono_body} @{thm spmf.fixp_rule_uc} @{thm spmf.fixp_induct_uc} |
1533 NONE\<close> |
1533 NONE\<close> |
1534 |
1534 |
1535 declare spmf.leq_refl[simp] |
1535 declare spmf.leq_refl[simp] |
1536 declare admissible_leI[OF ccpo_spmf, cont_intro] |
1536 declare admissible_leI[OF ccpo_spmf, cont_intro] |
1537 |
1537 |
1538 abbreviation "mono_spmf \<equiv> monotone (fun_ord (ord_spmf op =)) (ord_spmf op =)" |
1538 abbreviation "mono_spmf \<equiv> monotone (fun_ord (ord_spmf (=))) (ord_spmf (=))" |
1539 |
1539 |
1540 lemma lub_spmf_const [simp]: "lub_spmf {p} = p" |
1540 lemma lub_spmf_const [simp]: "lub_spmf {p} = p" |
1541 by(rule spmf_eqI)(simp add: spmf_lub_spmf[OF ccpo.chain_singleton[OF ccpo_spmf]]) |
1541 by(rule spmf_eqI)(simp add: spmf_lub_spmf[OF ccpo.chain_singleton[OF ccpo_spmf]]) |
1542 |
1542 |
1543 lemma bind_spmf_mono': |
1543 lemma bind_spmf_mono': |
1544 assumes fg: "ord_spmf op = f g" |
1544 assumes fg: "ord_spmf (=) f g" |
1545 and hk: "\<And>x :: 'a. ord_spmf op = (h x) (k x)" |
1545 and hk: "\<And>x :: 'a. ord_spmf (=) (h x) (k x)" |
1546 shows "ord_spmf op = (f \<bind> h) (g \<bind> k)" |
1546 shows "ord_spmf (=) (f \<bind> h) (g \<bind> k)" |
1547 unfolding bind_spmf_def using assms(1) |
1547 unfolding bind_spmf_def using assms(1) |
1548 by(rule rel_pmf_bindI)(auto split: option.split simp add: hk) |
1548 by(rule rel_pmf_bindI)(auto split: option.split simp add: hk) |
1549 |
1549 |
1550 lemma bind_spmf_mono [partial_function_mono]: |
1550 lemma bind_spmf_mono [partial_function_mono]: |
1551 assumes mf: "mono_spmf B" and mg: "\<And>y. mono_spmf (\<lambda>f. C y f)" |
1551 assumes mf: "mono_spmf B" and mg: "\<And>y. mono_spmf (\<lambda>f. C y f)" |
1552 shows "mono_spmf (\<lambda>f. bind_spmf (B f) (\<lambda>y. C y f))" |
1552 shows "mono_spmf (\<lambda>f. bind_spmf (B f) (\<lambda>y. C y f))" |
1553 proof (rule monotoneI) |
1553 proof (rule monotoneI) |
1554 fix f g :: "'a \<Rightarrow> 'b spmf" |
1554 fix f g :: "'a \<Rightarrow> 'b spmf" |
1555 assume fg: "fun_ord (ord_spmf op =) f g" |
1555 assume fg: "fun_ord (ord_spmf (=)) f g" |
1556 with mf have "ord_spmf op = (B f) (B g)" by (rule monotoneD[of _ _ _ f g]) |
1556 with mf have "ord_spmf (=) (B f) (B g)" by (rule monotoneD[of _ _ _ f g]) |
1557 moreover from mg have "\<And>y'. ord_spmf op = (C y' f) (C y' g)" |
1557 moreover from mg have "\<And>y'. ord_spmf (=) (C y' f) (C y' g)" |
1558 by (rule monotoneD) (rule fg) |
1558 by (rule monotoneD) (rule fg) |
1559 ultimately show "ord_spmf op = (bind_spmf (B f) (\<lambda>y. C y f)) (bind_spmf (B g) (\<lambda>y'. C y' g))" |
1559 ultimately show "ord_spmf (=) (bind_spmf (B f) (\<lambda>y. C y f)) (bind_spmf (B g) (\<lambda>y'. C y' g))" |
1560 by(rule bind_spmf_mono') |
1560 by(rule bind_spmf_mono') |
1561 qed |
1561 qed |
1562 |
1562 |
1563 lemma monotone_bind_spmf1: "monotone (ord_spmf op =) (ord_spmf op =) (\<lambda>y. bind_spmf y g)" |
1563 lemma monotone_bind_spmf1: "monotone (ord_spmf (=)) (ord_spmf (=)) (\<lambda>y. bind_spmf y g)" |
1564 by(rule monotoneI)(simp add: bind_spmf_mono' ord_spmf_reflI) |
1564 by(rule monotoneI)(simp add: bind_spmf_mono' ord_spmf_reflI) |
1565 |
1565 |
1566 lemma monotone_bind_spmf2: |
1566 lemma monotone_bind_spmf2: |
1567 assumes g: "\<And>x. monotone ord (ord_spmf op =) (\<lambda>y. g y x)" |
1567 assumes g: "\<And>x. monotone ord (ord_spmf (=)) (\<lambda>y. g y x)" |
1568 shows "monotone ord (ord_spmf op =) (\<lambda>y. bind_spmf p (g y))" |
1568 shows "monotone ord (ord_spmf (=)) (\<lambda>y. bind_spmf p (g y))" |
1569 by(rule monotoneI)(auto intro: bind_spmf_mono' monotoneD[OF g] ord_spmf_reflI) |
1569 by(rule monotoneI)(auto intro: bind_spmf_mono' monotoneD[OF g] ord_spmf_reflI) |
1570 |
1570 |
1571 lemma bind_lub_spmf: |
1571 lemma bind_lub_spmf: |
1572 assumes chain: "Complete_Partial_Order.chain (ord_spmf op =) Y" |
1572 assumes chain: "Complete_Partial_Order.chain (ord_spmf (=)) Y" |
1573 shows "bind_spmf (lub_spmf Y) f = lub_spmf ((\<lambda>p. bind_spmf p f) ` Y)" (is "?lhs = ?rhs") |
1573 shows "bind_spmf (lub_spmf Y) f = lub_spmf ((\<lambda>p. bind_spmf p f) ` Y)" (is "?lhs = ?rhs") |
1574 proof(cases "Y = {}") |
1574 proof(cases "Y = {}") |
1575 case Y: False |
1575 case Y: False |
1576 show ?thesis |
1576 show ?thesis |
1577 proof(rule spmf_eqI) |
1577 proof(rule spmf_eqI) |
1578 fix i |
1578 fix i |
1579 have chain': "Complete_Partial_Order.chain op \<le> ((\<lambda>p x. ennreal (spmf p x * spmf (f x) i)) ` Y)" |
1579 have chain': "Complete_Partial_Order.chain (\<le>) ((\<lambda>p x. ennreal (spmf p x * spmf (f x) i)) ` Y)" |
1580 using chain by(rule chain_imageI)(auto simp add: le_fun_def dest: ord_spmf_eq_leD intro: mult_right_mono) |
1580 using chain by(rule chain_imageI)(auto simp add: le_fun_def dest: ord_spmf_eq_leD intro: mult_right_mono) |
1581 have chain'': "Complete_Partial_Order.chain (ord_spmf op =) ((\<lambda>p. p \<bind> f) ` Y)" |
1581 have chain'': "Complete_Partial_Order.chain (ord_spmf (=)) ((\<lambda>p. p \<bind> f) ` Y)" |
1582 using chain by(rule chain_imageI)(auto intro!: monotoneI bind_spmf_mono' ord_spmf_reflI) |
1582 using chain by(rule chain_imageI)(auto intro!: monotoneI bind_spmf_mono' ord_spmf_reflI) |
1583 let ?M = "count_space (set_spmf (lub_spmf Y))" |
1583 let ?M = "count_space (set_spmf (lub_spmf Y))" |
1584 have "ennreal (spmf ?lhs i) = \<integral>\<^sup>+ x. ennreal (spmf (lub_spmf Y) x) * ennreal (spmf (f x) i) \<partial>?M" |
1584 have "ennreal (spmf ?lhs i) = \<integral>\<^sup>+ x. ennreal (spmf (lub_spmf Y) x) * ennreal (spmf (f x) i) \<partial>?M" |
1585 by(auto simp add: ennreal_spmf_lub_spmf ennreal_spmf_bind nn_integral_measure_spmf') |
1585 by(auto simp add: ennreal_spmf_lub_spmf ennreal_spmf_bind nn_integral_measure_spmf') |
1586 also have "\<dots> = \<integral>\<^sup>+ x. (SUP p:Y. ennreal (spmf p x * spmf (f x) i)) \<partial>?M" |
1586 also have "\<dots> = \<integral>\<^sup>+ x. (SUP p:Y. ennreal (spmf p x * spmf (f x) i)) \<partial>?M" |
1593 finally show "spmf ?lhs i = spmf ?rhs i" by simp |
1593 finally show "spmf ?lhs i = spmf ?rhs i" by simp |
1594 qed |
1594 qed |
1595 qed simp |
1595 qed simp |
1596 |
1596 |
1597 lemma map_lub_spmf: |
1597 lemma map_lub_spmf: |
1598 "Complete_Partial_Order.chain (ord_spmf op =) Y |
1598 "Complete_Partial_Order.chain (ord_spmf (=)) Y |
1599 \<Longrightarrow> map_spmf f (lub_spmf Y) = lub_spmf (map_spmf f ` Y)" |
1599 \<Longrightarrow> map_spmf f (lub_spmf Y) = lub_spmf (map_spmf f ` Y)" |
1600 unfolding map_spmf_conv_bind_spmf[abs_def] by(simp add: bind_lub_spmf o_def) |
1600 unfolding map_spmf_conv_bind_spmf[abs_def] by(simp add: bind_lub_spmf o_def) |
1601 |
1601 |
1602 lemma mcont_bind_spmf1: "mcont lub_spmf (ord_spmf op =) lub_spmf (ord_spmf op =) (\<lambda>y. bind_spmf y f)" |
1602 lemma mcont_bind_spmf1: "mcont lub_spmf (ord_spmf (=)) lub_spmf (ord_spmf (=)) (\<lambda>y. bind_spmf y f)" |
1603 using monotone_bind_spmf1 by(rule mcontI)(rule contI, simp add: bind_lub_spmf) |
1603 using monotone_bind_spmf1 by(rule mcontI)(rule contI, simp add: bind_lub_spmf) |
1604 |
1604 |
1605 lemma bind_lub_spmf2: |
1605 lemma bind_lub_spmf2: |
1606 assumes chain: "Complete_Partial_Order.chain ord Y" |
1606 assumes chain: "Complete_Partial_Order.chain ord Y" |
1607 and g: "\<And>y. monotone ord (ord_spmf op =) (g y)" |
1607 and g: "\<And>y. monotone ord (ord_spmf (=)) (g y)" |
1608 shows "bind_spmf x (\<lambda>y. lub_spmf (g y ` Y)) = lub_spmf ((\<lambda>p. bind_spmf x (\<lambda>y. g y p)) ` Y)" |
1608 shows "bind_spmf x (\<lambda>y. lub_spmf (g y ` Y)) = lub_spmf ((\<lambda>p. bind_spmf x (\<lambda>y. g y p)) ` Y)" |
1609 (is "?lhs = ?rhs") |
1609 (is "?lhs = ?rhs") |
1610 proof(cases "Y = {}") |
1610 proof(cases "Y = {}") |
1611 case Y: False |
1611 case Y: False |
1612 show ?thesis |
1612 show ?thesis |
1613 proof(rule spmf_eqI) |
1613 proof(rule spmf_eqI) |
1614 fix i |
1614 fix i |
1615 have chain': "\<And>y. Complete_Partial_Order.chain (ord_spmf op =) (g y ` Y)" |
1615 have chain': "\<And>y. Complete_Partial_Order.chain (ord_spmf (=)) (g y ` Y)" |
1616 using chain g[THEN monotoneD] by(rule chain_imageI) |
1616 using chain g[THEN monotoneD] by(rule chain_imageI) |
1617 have chain'': "Complete_Partial_Order.chain op \<le> ((\<lambda>p y. ennreal (spmf x y * spmf (g y p) i)) ` Y)" |
1617 have chain'': "Complete_Partial_Order.chain (\<le>) ((\<lambda>p y. ennreal (spmf x y * spmf (g y p) i)) ` Y)" |
1618 using chain by(rule chain_imageI)(auto simp add: le_fun_def dest: ord_spmf_eq_leD monotoneD[OF g] intro!: mult_left_mono) |
1618 using chain by(rule chain_imageI)(auto simp add: le_fun_def dest: ord_spmf_eq_leD monotoneD[OF g] intro!: mult_left_mono) |
1619 have chain''': "Complete_Partial_Order.chain (ord_spmf op =) ((\<lambda>p. bind_spmf x (\<lambda>y. g y p)) ` Y)" |
1619 have chain''': "Complete_Partial_Order.chain (ord_spmf (=)) ((\<lambda>p. bind_spmf x (\<lambda>y. g y p)) ` Y)" |
1620 using chain by(rule chain_imageI)(rule monotone_bind_spmf2[OF g, THEN monotoneD]) |
1620 using chain by(rule chain_imageI)(rule monotone_bind_spmf2[OF g, THEN monotoneD]) |
1621 |
1621 |
1622 have "ennreal (spmf ?lhs i) = \<integral>\<^sup>+ y. (SUP p:Y. ennreal (spmf x y * spmf (g y p) i)) \<partial>count_space (set_spmf x)" |
1622 have "ennreal (spmf ?lhs i) = \<integral>\<^sup>+ y. (SUP p:Y. ennreal (spmf x y * spmf (g y p) i)) \<partial>count_space (set_spmf x)" |
1623 by(simp add: ennreal_spmf_bind ennreal_spmf_lub_spmf[OF chain'] Y nn_integral_measure_spmf' SUP_mult_left_ennreal ennreal_mult) |
1623 by(simp add: ennreal_spmf_bind ennreal_spmf_lub_spmf[OF chain'] Y nn_integral_measure_spmf' SUP_mult_left_ennreal ennreal_mult) |
1624 also have "\<dots> = (SUP p:Y. \<integral>\<^sup>+ y. ennreal (spmf x y * spmf (g y p) i) \<partial>count_space (set_spmf x))" |
1624 also have "\<dots> = (SUP p:Y. \<integral>\<^sup>+ y. ennreal (spmf x y * spmf (g y p) i) \<partial>count_space (set_spmf x))" |
1631 finally show "spmf ?lhs i = spmf ?rhs i" by simp |
1631 finally show "spmf ?lhs i = spmf ?rhs i" by simp |
1632 qed |
1632 qed |
1633 qed simp |
1633 qed simp |
1634 |
1634 |
1635 lemma mcont_bind_spmf [cont_intro]: |
1635 lemma mcont_bind_spmf [cont_intro]: |
1636 assumes f: "mcont luba orda lub_spmf (ord_spmf op =) f" |
1636 assumes f: "mcont luba orda lub_spmf (ord_spmf (=)) f" |
1637 and g: "\<And>y. mcont luba orda lub_spmf (ord_spmf op =) (g y)" |
1637 and g: "\<And>y. mcont luba orda lub_spmf (ord_spmf (=)) (g y)" |
1638 shows "mcont luba orda lub_spmf (ord_spmf op =) (\<lambda>x. bind_spmf (f x) (\<lambda>y. g y x))" |
1638 shows "mcont luba orda lub_spmf (ord_spmf (=)) (\<lambda>x. bind_spmf (f x) (\<lambda>y. g y x))" |
1639 proof(rule spmf.mcont2mcont'[OF _ _ f]) |
1639 proof(rule spmf.mcont2mcont'[OF _ _ f]) |
1640 fix z |
1640 fix z |
1641 show "mcont lub_spmf (ord_spmf op =) lub_spmf (ord_spmf op =) (\<lambda>x. bind_spmf x (\<lambda>y. g y z))" |
1641 show "mcont lub_spmf (ord_spmf (=)) lub_spmf (ord_spmf (=)) (\<lambda>x. bind_spmf x (\<lambda>y. g y z))" |
1642 by(rule mcont_bind_spmf1) |
1642 by(rule mcont_bind_spmf1) |
1643 next |
1643 next |
1644 fix x |
1644 fix x |
1645 let ?f = "\<lambda>z. bind_spmf x (\<lambda>y. g y z)" |
1645 let ?f = "\<lambda>z. bind_spmf x (\<lambda>y. g y z)" |
1646 have "monotone orda (ord_spmf op =) ?f" using mcont_mono[OF g] by(rule monotone_bind_spmf2) |
1646 have "monotone orda (ord_spmf (=)) ?f" using mcont_mono[OF g] by(rule monotone_bind_spmf2) |
1647 moreover have "cont luba orda lub_spmf (ord_spmf op =) ?f" |
1647 moreover have "cont luba orda lub_spmf (ord_spmf (=)) ?f" |
1648 proof(rule contI) |
1648 proof(rule contI) |
1649 fix Y |
1649 fix Y |
1650 assume chain: "Complete_Partial_Order.chain orda Y" and Y: "Y \<noteq> {}" |
1650 assume chain: "Complete_Partial_Order.chain orda Y" and Y: "Y \<noteq> {}" |
1651 have "bind_spmf x (\<lambda>y. g y (luba Y)) = bind_spmf x (\<lambda>y. lub_spmf (g y ` Y))" |
1651 have "bind_spmf x (\<lambda>y. g y (luba Y)) = bind_spmf x (\<lambda>y. lub_spmf (g y ` Y))" |
1652 by(rule bind_spmf_cong)(simp_all add: mcont_contD[OF g chain Y]) |
1652 by(rule bind_spmf_cong)(simp_all add: mcont_contD[OF g chain Y]) |
1653 also have "\<dots> = lub_spmf ((\<lambda>p. x \<bind> (\<lambda>y. g y p)) ` Y)" using chain |
1653 also have "\<dots> = lub_spmf ((\<lambda>p. x \<bind> (\<lambda>y. g y p)) ` Y)" using chain |
1654 by(rule bind_lub_spmf2)(rule mcont_mono[OF g]) |
1654 by(rule bind_lub_spmf2)(rule mcont_mono[OF g]) |
1655 finally show "bind_spmf x (\<lambda>y. g y (luba Y)) = \<dots>" . |
1655 finally show "bind_spmf x (\<lambda>y. g y (luba Y)) = \<dots>" . |
1656 qed |
1656 qed |
1657 ultimately show "mcont luba orda lub_spmf (ord_spmf op =) ?f" by(rule mcontI) |
1657 ultimately show "mcont luba orda lub_spmf (ord_spmf (=)) ?f" by(rule mcontI) |
1658 qed |
1658 qed |
1659 |
1659 |
1660 lemma bind_pmf_mono [partial_function_mono]: |
1660 lemma bind_pmf_mono [partial_function_mono]: |
1661 "(\<And>y. mono_spmf (\<lambda>f. C y f)) \<Longrightarrow> mono_spmf (\<lambda>f. bind_pmf p (\<lambda>x. C x f))" |
1661 "(\<And>y. mono_spmf (\<lambda>f. C y f)) \<Longrightarrow> mono_spmf (\<lambda>f. bind_pmf p (\<lambda>x. C x f))" |
1662 using bind_spmf_mono[of "\<lambda>_. spmf_of_pmf p" C] by simp |
1662 using bind_spmf_mono[of "\<lambda>_. spmf_of_pmf p" C] by simp |
1663 |
1663 |
1664 lemma map_spmf_mono [partial_function_mono]: "mono_spmf B \<Longrightarrow> mono_spmf (\<lambda>g. map_spmf f (B g))" |
1664 lemma map_spmf_mono [partial_function_mono]: "mono_spmf B \<Longrightarrow> mono_spmf (\<lambda>g. map_spmf f (B g))" |
1665 unfolding map_spmf_conv_bind_spmf by(rule bind_spmf_mono) simp_all |
1665 unfolding map_spmf_conv_bind_spmf by(rule bind_spmf_mono) simp_all |
1666 |
1666 |
1667 lemma mcont_map_spmf [cont_intro]: |
1667 lemma mcont_map_spmf [cont_intro]: |
1668 "mcont luba orda lub_spmf (ord_spmf op =) g |
1668 "mcont luba orda lub_spmf (ord_spmf (=)) g |
1669 \<Longrightarrow> mcont luba orda lub_spmf (ord_spmf op =) (\<lambda>x. map_spmf f (g x))" |
1669 \<Longrightarrow> mcont luba orda lub_spmf (ord_spmf (=)) (\<lambda>x. map_spmf f (g x))" |
1670 unfolding map_spmf_conv_bind_spmf by(rule mcont_bind_spmf) simp_all |
1670 unfolding map_spmf_conv_bind_spmf by(rule mcont_bind_spmf) simp_all |
1671 |
1671 |
1672 lemma monotone_set_spmf: "monotone (ord_spmf op =) op \<subseteq> set_spmf" |
1672 lemma monotone_set_spmf: "monotone (ord_spmf (=)) (\<subseteq>) set_spmf" |
1673 by(rule monotoneI)(rule ord_spmf_eqD_set_spmf) |
1673 by(rule monotoneI)(rule ord_spmf_eqD_set_spmf) |
1674 |
1674 |
1675 lemma cont_set_spmf: "cont lub_spmf (ord_spmf op =) Union op \<subseteq> set_spmf" |
1675 lemma cont_set_spmf: "cont lub_spmf (ord_spmf (=)) Union (\<subseteq>) set_spmf" |
1676 by(rule contI)(subst set_lub_spmf; simp) |
1676 by(rule contI)(subst set_lub_spmf; simp) |
1677 |
1677 |
1678 lemma mcont2mcont_set_spmf[THEN mcont2mcont, cont_intro]: |
1678 lemma mcont2mcont_set_spmf[THEN mcont2mcont, cont_intro]: |
1679 shows mcont_set_spmf: "mcont lub_spmf (ord_spmf op =) Union op \<subseteq> set_spmf" |
1679 shows mcont_set_spmf: "mcont lub_spmf (ord_spmf (=)) Union (\<subseteq>) set_spmf" |
1680 by(rule mcontI monotone_set_spmf cont_set_spmf)+ |
1680 by(rule mcontI monotone_set_spmf cont_set_spmf)+ |
1681 |
1681 |
1682 lemma monotone_spmf: "monotone (ord_spmf op =) op \<le> (\<lambda>p. spmf p x)" |
1682 lemma monotone_spmf: "monotone (ord_spmf (=)) (\<le>) (\<lambda>p. spmf p x)" |
1683 by(rule monotoneI)(simp add: ord_spmf_eq_leD) |
1683 by(rule monotoneI)(simp add: ord_spmf_eq_leD) |
1684 |
1684 |
1685 lemma cont_spmf: "cont lub_spmf (ord_spmf op =) Sup op \<le> (\<lambda>p. spmf p x)" |
1685 lemma cont_spmf: "cont lub_spmf (ord_spmf (=)) Sup (\<le>) (\<lambda>p. spmf p x)" |
1686 by(rule contI)(simp add: spmf_lub_spmf) |
1686 by(rule contI)(simp add: spmf_lub_spmf) |
1687 |
1687 |
1688 lemma mcont_spmf: "mcont lub_spmf (ord_spmf op =) Sup op \<le> (\<lambda>p. spmf p x)" |
1688 lemma mcont_spmf: "mcont lub_spmf (ord_spmf (=)) Sup (\<le>) (\<lambda>p. spmf p x)" |
1689 by(rule mcontI monotone_spmf cont_spmf)+ |
1689 by(rule mcontI monotone_spmf cont_spmf)+ |
1690 |
1690 |
1691 lemma cont_ennreal_spmf: "cont lub_spmf (ord_spmf op =) Sup op \<le> (\<lambda>p. ennreal (spmf p x))" |
1691 lemma cont_ennreal_spmf: "cont lub_spmf (ord_spmf (=)) Sup (\<le>) (\<lambda>p. ennreal (spmf p x))" |
1692 by(rule contI)(simp add: ennreal_spmf_lub_spmf) |
1692 by(rule contI)(simp add: ennreal_spmf_lub_spmf) |
1693 |
1693 |
1694 lemma mcont2mcont_ennreal_spmf [THEN mcont2mcont, cont_intro]: |
1694 lemma mcont2mcont_ennreal_spmf [THEN mcont2mcont, cont_intro]: |
1695 shows mcont_ennreal_spmf: "mcont lub_spmf (ord_spmf op =) Sup op \<le> (\<lambda>p. ennreal (spmf p x))" |
1695 shows mcont_ennreal_spmf: "mcont lub_spmf (ord_spmf (=)) Sup (\<le>) (\<lambda>p. ennreal (spmf p x))" |
1696 by(rule mcontI mono2mono_ennreal monotone_spmf cont_ennreal_spmf)+ |
1696 by(rule mcontI mono2mono_ennreal monotone_spmf cont_ennreal_spmf)+ |
1697 |
1697 |
1698 lemma nn_integral_map_spmf [simp]: "nn_integral (measure_spmf (map_spmf f p)) g = nn_integral (measure_spmf p) (g \<circ> f)" |
1698 lemma nn_integral_map_spmf [simp]: "nn_integral (measure_spmf (map_spmf f p)) g = nn_integral (measure_spmf p) (g \<circ> f)" |
1699 by(auto 4 3 simp add: measure_spmf_def nn_integral_distr nn_integral_restrict_space intro: nn_integral_cong split: split_indicator) |
1699 by(auto 4 3 simp add: measure_spmf_def nn_integral_distr nn_integral_restrict_space intro: nn_integral_cong split: split_indicator) |
1700 |
1700 |
1754 (auto 4 3 intro!: arg_cong2[where f=measure] simp add: option_rel_Some1 option_rel_Some2 A'_def intro: rev_bexI elim: option.rel_cases) |
1754 (auto 4 3 intro!: arg_cong2[where f=measure] simp add: option_rel_Some1 option_rel_Some2 A'_def intro: rev_bexI elim: option.rel_cases) |
1755 finally show "measure (measure_pmf p) A \<le> \<dots>" . |
1755 finally show "measure (measure_pmf p) A \<le> \<dots>" . |
1756 qed |
1756 qed |
1757 |
1757 |
1758 lemma admissible_rel_spmf: |
1758 lemma admissible_rel_spmf: |
1759 "ccpo.admissible (prod_lub lub_spmf lub_spmf) (rel_prod (ord_spmf op =) (ord_spmf op =)) (case_prod (rel_spmf R))" |
1759 "ccpo.admissible (prod_lub lub_spmf lub_spmf) (rel_prod (ord_spmf (=)) (ord_spmf (=))) (case_prod (rel_spmf R))" |
1760 (is "ccpo.admissible ?lub ?ord ?P") |
1760 (is "ccpo.admissible ?lub ?ord ?P") |
1761 proof(rule ccpo.admissibleI) |
1761 proof(rule ccpo.admissibleI) |
1762 fix Y |
1762 fix Y |
1763 assume chain: "Complete_Partial_Order.chain ?ord Y" |
1763 assume chain: "Complete_Partial_Order.chain ?ord Y" |
1764 and Y: "Y \<noteq> {}" |
1764 and Y: "Y \<noteq> {}" |
1765 and R: "\<forall>(p, q) \<in> Y. rel_spmf R p q" |
1765 and R: "\<forall>(p, q) \<in> Y. rel_spmf R p q" |
1766 from R have R: "\<And>p q. (p, q) \<in> Y \<Longrightarrow> rel_spmf R p q" by auto |
1766 from R have R: "\<And>p q. (p, q) \<in> Y \<Longrightarrow> rel_spmf R p q" by auto |
1767 have chain1: "Complete_Partial_Order.chain (ord_spmf op =) (fst ` Y)" |
1767 have chain1: "Complete_Partial_Order.chain (ord_spmf (=)) (fst ` Y)" |
1768 and chain2: "Complete_Partial_Order.chain (ord_spmf op =) (snd ` Y)" |
1768 and chain2: "Complete_Partial_Order.chain (ord_spmf (=)) (snd ` Y)" |
1769 using chain by(rule chain_imageI; clarsimp)+ |
1769 using chain by(rule chain_imageI; clarsimp)+ |
1770 from Y have Y1: "fst ` Y \<noteq> {}" and Y2: "snd ` Y \<noteq> {}" by auto |
1770 from Y have Y1: "fst ` Y \<noteq> {}" and Y2: "snd ` Y \<noteq> {}" by auto |
1771 |
1771 |
1772 have "rel_spmf R (lub_spmf (fst ` Y)) (lub_spmf (snd ` Y))" |
1772 have "rel_spmf R (lub_spmf (fst ` Y)) (lub_spmf (snd ` Y))" |
1773 proof(rule rel_spmf_measureI) |
1773 proof(rule rel_spmf_measureI) |
1785 qed |
1785 qed |
1786 then show "?P (?lub Y)" by(simp add: prod_lub_def) |
1786 then show "?P (?lub Y)" by(simp add: prod_lub_def) |
1787 qed |
1787 qed |
1788 |
1788 |
1789 lemma admissible_rel_spmf_mcont [cont_intro]: |
1789 lemma admissible_rel_spmf_mcont [cont_intro]: |
1790 "\<lbrakk> mcont lub ord lub_spmf (ord_spmf op =) f; mcont lub ord lub_spmf (ord_spmf op =) g \<rbrakk> |
1790 "\<lbrakk> mcont lub ord lub_spmf (ord_spmf (=)) f; mcont lub ord lub_spmf (ord_spmf (=)) g \<rbrakk> |
1791 \<Longrightarrow> ccpo.admissible lub ord (\<lambda>x. rel_spmf R (f x) (g x))" |
1791 \<Longrightarrow> ccpo.admissible lub ord (\<lambda>x. rel_spmf R (f x) (g x))" |
1792 by(rule admissible_subst[OF admissible_rel_spmf, where f="\<lambda>x. (f x, g x)", simplified])(rule mcont_Pair) |
1792 by(rule admissible_subst[OF admissible_rel_spmf, where f="\<lambda>x. (f x, g x)", simplified])(rule mcont_Pair) |
1793 |
1793 |
1794 context includes lifting_syntax |
1794 context includes lifting_syntax |
1795 begin |
1795 begin |
1796 |
1796 |
1797 lemma fixp_spmf_parametric': |
1797 lemma fixp_spmf_parametric': |
1798 assumes f: "\<And>x. monotone (ord_spmf op =) (ord_spmf op =) F" |
1798 assumes f: "\<And>x. monotone (ord_spmf (=)) (ord_spmf (=)) F" |
1799 and g: "\<And>x. monotone (ord_spmf op =) (ord_spmf op =) G" |
1799 and g: "\<And>x. monotone (ord_spmf (=)) (ord_spmf (=)) G" |
1800 and param: "(rel_spmf R ===> rel_spmf R) F G" |
1800 and param: "(rel_spmf R ===> rel_spmf R) F G" |
1801 shows "(rel_spmf R) (ccpo.fixp lub_spmf (ord_spmf op =) F) (ccpo.fixp lub_spmf (ord_spmf op =) G)" |
1801 shows "(rel_spmf R) (ccpo.fixp lub_spmf (ord_spmf (=)) F) (ccpo.fixp lub_spmf (ord_spmf (=)) G)" |
1802 by(rule parallel_fixp_induct[OF ccpo_spmf ccpo_spmf _ f g])(auto intro: param[THEN rel_funD]) |
1802 by(rule parallel_fixp_induct[OF ccpo_spmf ccpo_spmf _ f g])(auto intro: param[THEN rel_funD]) |
1803 |
1803 |
1804 lemma fixp_spmf_parametric: |
1804 lemma fixp_spmf_parametric: |
1805 assumes f: "\<And>x. mono_spmf (\<lambda>f. F f x)" |
1805 assumes f: "\<And>x. mono_spmf (\<lambda>f. F f x)" |
1806 and g: "\<And>x. mono_spmf (\<lambda>f. G f x)" |
1806 and g: "\<And>x. mono_spmf (\<lambda>f. G f x)" |
1807 and param: "((A ===> rel_spmf R) ===> A ===> rel_spmf R) F G" |
1807 and param: "((A ===> rel_spmf R) ===> A ===> rel_spmf R) F G" |
1808 shows "(A ===> rel_spmf R) (spmf.fixp_fun F) (spmf.fixp_fun G)" |
1808 shows "(A ===> rel_spmf R) (spmf.fixp_fun F) (spmf.fixp_fun G)" |
1809 using f g |
1809 using f g |
1810 proof(rule parallel_fixp_induct_1_1[OF partial_function_definitions_spmf partial_function_definitions_spmf _ _ reflexive reflexive, where P="(A ===> rel_spmf R)"]) |
1810 proof(rule parallel_fixp_induct_1_1[OF partial_function_definitions_spmf partial_function_definitions_spmf _ _ reflexive reflexive, where P="(A ===> rel_spmf R)"]) |
1811 show "ccpo.admissible (prod_lub (fun_lub lub_spmf) (fun_lub lub_spmf)) (rel_prod (fun_ord (ord_spmf op =)) (fun_ord (ord_spmf op =))) (\<lambda>x. (A ===> rel_spmf R) (fst x) (snd x))" |
1811 show "ccpo.admissible (prod_lub (fun_lub lub_spmf) (fun_lub lub_spmf)) (rel_prod (fun_ord (ord_spmf (=))) (fun_ord (ord_spmf (=)))) (\<lambda>x. (A ===> rel_spmf R) (fst x) (snd x))" |
1812 unfolding rel_fun_def |
1812 unfolding rel_fun_def |
1813 apply(rule admissible_all admissible_imp admissible_rel_spmf_mcont)+ |
1813 apply(rule admissible_all admissible_imp admissible_rel_spmf_mcont)+ |
1814 apply(rule spmf.mcont2mcont[OF mcont_call]) |
1814 apply(rule spmf.mcont2mcont[OF mcont_call]) |
1815 apply(rule mcont_fst) |
1815 apply(rule mcont_fst) |
1816 apply(rule spmf.mcont2mcont[OF mcont_call]) |
1816 apply(rule spmf.mcont2mcont[OF mcont_call]) |
2712 lemma assumes "rel_spmf (\<lambda>x y. bad1 x = bad2 y \<and> (\<not> bad2 y \<longrightarrow> A x \<longleftrightarrow> B y)) p q" (is "rel_spmf ?A _ _") |
2712 lemma assumes "rel_spmf (\<lambda>x y. bad1 x = bad2 y \<and> (\<not> bad2 y \<longrightarrow> A x \<longleftrightarrow> B y)) p q" (is "rel_spmf ?A _ _") |
2713 shows fundamental_lemma_bad: "measure (measure_spmf p) {x. bad1 x} = measure (measure_spmf q) {y. bad2 y}" (is "?bad") |
2713 shows fundamental_lemma_bad: "measure (measure_spmf p) {x. bad1 x} = measure (measure_spmf q) {y. bad2 y}" (is "?bad") |
2714 and fundamental_lemma: "\<bar>measure (measure_spmf p) {x. A x} - measure (measure_spmf q) {y. B y}\<bar> \<le> |
2714 and fundamental_lemma: "\<bar>measure (measure_spmf p) {x. A x} - measure (measure_spmf q) {y. B y}\<bar> \<le> |
2715 measure (measure_spmf p) {x. bad1 x}" (is ?fundamental) |
2715 measure (measure_spmf p) {x. bad1 x}" (is ?fundamental) |
2716 proof - |
2716 proof - |
2717 have good: "rel_fun ?A op = (\<lambda>x. A x \<and> \<not> bad1 x) (\<lambda>y. B y \<and> \<not> bad2 y)" by(auto simp add: rel_fun_def) |
2717 have good: "rel_fun ?A (=) (\<lambda>x. A x \<and> \<not> bad1 x) (\<lambda>y. B y \<and> \<not> bad2 y)" by(auto simp add: rel_fun_def) |
2718 from assms have 1: "measure (measure_spmf p) {x. A x \<and> \<not> bad1 x} = measure (measure_spmf q) {y. B y \<and> \<not> bad2 y}" |
2718 from assms have 1: "measure (measure_spmf p) {x. A x \<and> \<not> bad1 x} = measure (measure_spmf q) {y. B y \<and> \<not> bad2 y}" |
2719 by(rule measure_spmf_parametric[THEN rel_funD, THEN rel_funD])(rule Collect_parametric[THEN rel_funD, OF good]) |
2719 by(rule measure_spmf_parametric[THEN rel_funD, THEN rel_funD])(rule Collect_parametric[THEN rel_funD, OF good]) |
2720 |
2720 |
2721 have bad: "rel_fun ?A op = bad1 bad2" by(simp add: rel_fun_def) |
2721 have bad: "rel_fun ?A (=) bad1 bad2" by(simp add: rel_fun_def) |
2722 show 2: ?bad using assms |
2722 show 2: ?bad using assms |
2723 by(rule measure_spmf_parametric[THEN rel_funD, THEN rel_funD])(rule Collect_parametric[THEN rel_funD, OF bad]) |
2723 by(rule measure_spmf_parametric[THEN rel_funD, THEN rel_funD])(rule Collect_parametric[THEN rel_funD, OF bad]) |
2724 |
2724 |
2725 let ?\<mu>p = "measure (measure_spmf p)" and ?\<mu>q = "measure (measure_spmf q)" |
2725 let ?\<mu>p = "measure (measure_spmf p)" and ?\<mu>q = "measure (measure_spmf q)" |
2726 have "{x. A x \<and> bad1 x} \<union> {x. A x \<and> \<not> bad1 x} = {x. A x}" |
2726 have "{x. A x \<and> bad1 x} \<union> {x. A x \<and> \<not> bad1 x} = {x. A x}" |