primcorec bind_resumption :: "('a, 'out, 'in) resumption ==> ('a ==> ('b, 'out, 'in) resumption) ==> ('b, 'out, 'in) resumption" where "[ is_Done x; result x ≠ None ⟶ is_Done (f (the (result x))) ]==> is_Done (bind_resumption x f)"
| "result (bind_resumption x f) = result x 🍋 result ∘ f"
| "output (bind_resumption x f) = (if is_Done x then output (f (the (result x))) else output x)"
| "resume (bind_resumption x f) = (λinp. if is_Done x then resume (f (the (result x))) inp else bind_resumption (resume x inp) f)"
lemma [simp]: shows is_Done_DONE: "is_Done (DONE a)" and is_Done_ABORT: "is_Done ABORT" and result_DONE: "result (DONE a) = Some a" and result_ABORT: "result ABORT = None" and DONE_inject: "DONE a = DONE b ⟷ a = b" and DONE_neq_ABORT: "DONE a ≠ ABORT" and ABORT_neq_DONE: "ABORT ≠ DONE a" and ABORT_eq_Done: "∧a. ABORT = Done a ⟷ a = None" and Done_eq_ABORT: "∧a. Done a = ABORT ⟷ a = None" and DONE_eq_Done: "∧b. DONE a = Done b ⟷ b = Some a" and Done_eq_DONE: "∧b. Done b = DONE a ⟷ b = Some a" and DONE_neq_Pause: "DONE a ≠ Pause out c" and Pause_neq_DONE: "Pause out c ≠ DONE a" and ABORT_neq_Pause: "ABORT ≠ Pause out c" and Pause_neq_ABORT: "Pause out c ≠ ABORT" by(auto simp add: DONE_def ABORT_def)
lemma bind_resumption_is_Done: "is_Done f ==> f 🍋 g = (if result f = None then ABORT else g (the (result f)))" by(rule resumption.expand) auto
lemma bind_resumption_eq_Done_iff [simp]: "f 🍋 g = Done x ⟷ (∃y. f = DONE y ∧ g y = Done x) ∨ f = ABORT ∧ x = None" by(cases f)(auto simp add: Done_bind split: option.split)
lemma bind_resumption_cong: assumes"x = y" and"∧z. z ∈ results y ==> f z = g z" shows"x 🍋 f = y 🍋 g" using assms(2) unfolding‹x = y› proof(coinduction arbitrary: y rule: resumption.coinduct_strong) case Eq_resumption thus ?case by(auto intro: resumption.set_sel simp add: is_Done_def rel_fun_def)
(fastforce del: exI intro!: exI intro: resumption.set_sel(2) simp add: is_Done_def) qed
lemma results_bind_resumption: (* Move to Resumption *) "results (bind_resumption x f) = (∪a∈results x. results (f a))"
(is"?lhs = ?rhs") proof(intro set_eqI iffI) show"z ∈ ?rhs"if"z ∈ ?lhs"for z using that proof(induction r≡"x 🍋 f" arbitrary: x) case (Done z z' x) fromDone(1) Done(2)[symmetric] show ?caseby(auto) next case (Pause out c r z x) thenshow ?case proof(cases x) case (Done x') show ?thesis proof(cases x') case None withDone Pause(4) show ?thesis by(auto simp add: ABORT_def[symmetric]) next case (Some x'') thus ?thesis using Pause(1,2,4) Done by(auto 43 simp add: DONE_def[unfolded o_def, symmetric, unfolded fun_eq_iff] dest: sym) qed qed(fastforce) qed next fix z assume"z ∈ ?rhs" thenobtain z' where z': "z' ∈ results x" and z: "z ∈ results (f z')"by blast from z' show"z ∈ ?lhs" proof(induction z'≡z' x) case (Done r) thenshow ?caseusing z by(auto simp add: DONE_def[unfolded o_def, symmetric, unfolded fun_eq_iff]) qed auto qed
lemma outputs_bind_resumption [simp]: "outputs (bind_resumption r f) = outputs r ∪ (∪x∈results r. outputs (f x))"
(is"?lhs = ?rhs") proof(rule set_eqI iffI)+ show"x ∈ ?rhs"if"x ∈ ?lhs"for x using that proof(induction r'≡"bind_resumption r f" arbitrary: r) case (Pause1 out c) thus ?caseby(cases r)(auto simp add: Done_bind split: option.split_asm dest: sym) next case (Pause2 out c r' x) thus ?caseby(cases r)(auto 43 simp add: Done_bind split: option.split_asm dest: sym) qed next fix x assume"x ∈ ?rhs" then consider (left) "x ∈ outputs r" | (right) a where"a ∈ results r""x ∈ outputs (f a)"by auto thenshow"x ∈ ?lhs" proof cases
{ case left thus ?thesis byinduction auto }
{ case right thus ?thesis byinduction(auto simp add: Done_bind) } qed qed
coinductive resumption_ord :: "('a, 'out, 'in) resumption ==> ('a, 'out, 'in) resumption ==> bool" where
Done_Done: "flat_ord None a a' ==> resumption_ord (Done a) (Done a')"
| Done_Pause: "resumption_ord ABORT (Pause out c)"
| Pause_Pause: "((=) ===> resumption_ord) c c' ==> resumption_ord (Pause out c) (Pause out c')"
inductive_simps resumption_ord_simps [simp]: "resumption_ord (Pause out c) r" "resumption_ord r (Done a)"
lemma resumption_ord_antisym: "[ resumption_ord r r'; resumption_ord r' r ] ==> r = r'" proof(coinduction arbitrary: r r' rule: resumption.coinduct_strong) case (Eq_resumption r r') thus ?case by cases(auto simp add: flat_ord_def rel_fun_def) qed
lemma resumption_ord_trans: "[ resumption_ord r r'; resumption_ord r' r'' ] ==> resumption_ord r r''" proof(coinduction arbitrary: r r' r'') case (Done r r' r'') thus ?caseby(auto 44 elim: resumption_ord.cases simp add: flat_ord_def) next case (Abort r r' r'') thus ?caseby(auto 44 elim: resumption_ord.cases simp add: flat_ord_def) next case (Pause r r' r'') hence"resumption_ord r r'""resumption_ord r' r''"by simp_all thus ?caseusing‹¬ is_Done r›‹¬ is_Done r''› by(cases)(auto simp add: rel_fun_def) qed
primcorec resumption_lub :: "('a, 'out, 'in) resumption set ==> ('a, 'out, 'in) resumption" where "∀r ∈ R. is_Done r ==> is_Done (resumption_lub R)"
| "result (resumption_lub R) = flat_lub None (result ` R)"
| "output (resumption_lub R) = (THE out. out ∈ output ` (R ∩ {r. ¬ is_Done r}))"
| "resume (resumption_lub R) = (λinp. resumption_lub ((λc. c inp) ` resume ` (R ∩ {r. ¬ is_Done r})))"
lemma bind_resumption_mono [partial_function_mono]: assumes mf: "mono_resumption B" and mg: "∧y. mono_resumption (C y)" shows"mono_resumption (λf. do { y ← B f; C y f })" proof(rule monotoneI) fix f g :: "'a ==> ('b, 'c, 'd) resumption" assume *: "fun_ord resumption_ord f g"
define f' where"f' ≡ B f" define g' where"g' ≡ B g"
define h where"h ≡ λx. C x f" define k where"k ≡ λx. C x g" from mf[THEN monotoneD, OF *] mg[THEN monotoneD, OF *] f'_def g'_def h_def k_def have"resumption_ord f' g'""∧x. resumption_ord (h x) (k x)"by auto thus"resumption_ord (f' 🍋 h) (g' 🍋 k)" proof(coinduction arbitrary: f' g' h k) case (Done f' g' h k) hence le: "resumption_ord f' g'" and mg: "∧y. resumption_ord (h y) (k y)"by simp_all from‹is_Done (g' 🍋 k)› have done_Bg: "is_Done g'" and"result g' ≠ None ==> is_Done (k (the (result g')))"by simp_all moreover have"is_Done f'"using le done_Bg by(rule resumption_ord_is_DoneD) moreover from le done_Bg have"flat_ord None (result f') (result g')" by(rule resumption_ord_resultD) hence"result f' ≠ None ==> result g' = result f'" by(auto simp add: flat_ord_def) moreover have"resumption_ord (h (the (result f'))) (k (the (result f')))"by(rule mg) ultimatelyshow ?case by(subst (12) result_bind_resumption)(auto dest: resumption_ord_is_DoneD resumption_ord_resultD simp add: flat_ord_def bind_eq_None_conv) next case (Abort f' g' h k) hence"resumption_ord (h (the (result f'))) (k (the (result f')))"by simp thus ?caseusing Abort by(cases "is_Done g'")(auto 44 simp add: bind_eq_None_conv flat_ord_def dest: resumption_ord_abort resumption_ord_resultD resumption_ord_is_DoneD) next case (Pause f' g' h k) hence ?output by(auto 44 dest: resumption_ord_outputD resumption_ord_is_DoneD resumption_ord_resultD resumption_ord_abort simp add: flat_ord_def) moreoverhave ?resume proof(cases "is_Done f'") case False with Pause show ?thesis by(auto simp add: rel_fun_def dest: resumption_ord_is_DoneD intro: resumption_ord_resumeD[THEN rel_funD] del: exI intro!: exI) next case True hence"is_Done g'"using Pause by(auto dest: resumption_ord_abort) thus ?thesis using True Pause resumption_ord_resultD[OF ‹resumption_ord f' g'›] by(auto del: rel_funI intro!: rel_funI simp add: bind_resumption_is_Done flat_ord_def intro: resumption_ord_resumeD[THEN rel_funD] exI[where x=f'] exI[where x=g']) qed ultimatelyshow ?case .. qed qed
lemmafixes f F defines"F ≡ λresults r. case r of resumption.Done x ==> set_option x | resumption.Pause out c ==>∪input. results (c input)" shows results_conv_fixp: "results ≡ ccpo.fixp (fun_lub Union) (fun_ord (⊆)) F" (is"_ ≡ ?fixp") and results_mono: "∧x. monotone (fun_ord (⊆)) (⊆) (λf. F f x)" (is"PROP ?mono") proof(rule eq_reflection ext antisym subsetI)+ show mono: "PROP ?mono"unfolding F_def by(tactic ‹Partial_Function.mono_tac @{context} 1›) fix x r show"?fixp r ⊆ results r" by(induction arbitrary: r rule: lfp.fixp_induct_uc[of "λx. x" F "λx. x", OF mono reflexive refl])
(fastforce simp add: F_def split: resumption.split_asm)+
assume"x ∈ results r" thus"x ∈ ?fixp r"by induct(subst lfp.mono_body_fixp[OF mono]; auto simp add: F_def)+ qed
lemma mcont_case_resumption: fixes f g defines"h ≡ λr. if is_Done r then f (result r) else g (output r) (resume r) r" assumes mcont1: "mcont (flat_lub None) option_ord lub ord f" and mcont2: "∧out. mcont (fun_lub resumption_lub) (fun_ord resumption_ord) lub ord (λc. g out c (Pause out c))" and ccpo: "class.ccpo lub ord (mk_less ord)" and bot: "∧x. ord (f None) x" shows"mcont resumption_lub resumption_ord lub ord (λr. case r of Done x ==> f x | Pause out c ==> g out c r)"
(is"mcont ?lub ?ord _ _ ?f") proof(rule resumption.mcont_if_bot[OF ccpo bot, where bound=ABORT and f=h]) show"?f x = (if ?ord x ABORT then f None else h x)"for x by(simp add: h_def split: resumption.split) show"ord (h x) (h y)"if"?ord x y""¬ ?ord x ABORT"for x y using that by(cases x)(simp_all add: h_def mcont_monoD[OF mcont1] fun_ord_conv_rel_fun mcont_monoD[OF mcont2])
fix Y :: "('a, 'b, 'c) resumption set" assume chain: "Complete_Partial_Order.chain ?ord Y" and Y: "Y ≠ {}" and nbot: "∧x. x ∈ Y ==>¬ ?ord x ABORT" show"h (?lub Y) = lub (h ` Y)" proof(cases "∃x. DONE x ∈ Y") case True thenobtain x where x: "DONE x ∈ Y" .. have is_Done: "is_Done r"if"r ∈ Y"for r using chainD[OF chain that x] by(auto dest: resumption_ord_is_DoneD) from is_Done have chain': "Complete_Partial_Order.chain (flat_ord None) (result ` Y)" by(auto 52 intro!: chainI elim: chainE[OF chain] dest: resumption_ord_resultD) from is_Done have"is_Done (?lub Y)""Y ∩ {r. is_Done r} = Y""Y ∩ {r. ¬ is_Done r} = {}"by auto thenshow ?thesis using Y by(simp add: h_def mcont_contD[OF mcont1 chain'] image_image) next case False have is_Done: "¬ is_Done r"if"r ∈ Y"for r using that False nbot by(auto elim!: is_Done_cases) from Y obtain out c where Pause: "Pause out c ∈ Y" by(auto 52 dest: is_Done iff: not_is_Done_conv_Pause)
have out: "(THE out. out ∈ output ` (Y ∩ {r. ¬ is_Done r})) = out"using Pause by(auto 43 intro: rev_image_eqI iff: not_is_Done_conv_Pause dest: chainD[OF chain]) have"(λr. g (output r) (resume r) r) ` (Y ∩ {r. ¬ is_Done r}) = (λr. g out (resume r) r) ` (Y ∩ {r. ¬ is_Done r})" by(auto 43 simp add: not_is_Done_conv_Pause dest: chainD[OF chain Pause] intro: rev_image_eqI) moreoverhave"¬ is_Done (?lub Y)"using Y is_Done by(auto) moreoverfrom is_Done have"Y ∩ {r. is_Done r} = {}""Y ∩ {r. ¬ is_Done r} = Y"by auto moreoverhave"(λinp. resumption_lub ((λx. resume x inp) ` Y)) = fun_lub resumption_lub (resume ` Y)" by(auto simp add: fun_lub_def fun_eq_iff intro!: arg_cong[where f="resumption_lub"]) moreoverhave"resumption_lub Y = Pause out (fun_lub resumption_lub (resume ` Y))" using Y is_Done out by(intro resumption.expand)(auto simp add: fun_lub_def fun_eq_iff image_image intro!: arg_cong[where f=resumption_lub]) moreoverhave chain': "Complete_Partial_Order.chain resumption.le_fun (resume ` Y)"using chain by(rule chain_imageI)(auto dest!: is_Done simp add: not_is_Done_conv_Pause fun_ord_conv_rel_fun) moreoverhave"(λr. g out (resume r) (Pause out (resume r))) ` Y = (λr. g out (resume r) r) ` Y" by(intro image_cong[OF refl])(frule nbot; auto dest!: chainD[OF chain Pause] elim: resumption_ord.cases) ultimatelyshow ?thesis using False out Y by(simp add: h_def image_image mcont_contD[OF mcont2]) qed qed
lemmafixes f F defines"F ≡ λoutputs xs. case xs of resumption.Done x ==> {} | resumption.Pause out c ==> insert out (∪input. outputs (c input))" shows outputs_conv_fixp: "outputs ≡ ccpo.fixp (fun_lub Union) (fun_ord (⊆)) F" (is"_ ≡ ?fixp") and outputs_mono: "∧x. monotone (fun_ord (⊆)) (⊆) (λf. F f x)" (is"PROP ?mono") proof(rule eq_reflection ext antisym subsetI)+ show mono: "PROP ?mono"unfolding F_def by(tactic ‹Partial_Function.mono_tac @{context} 1›) show"?fixp r ⊆ outputs r"for r by(induct arbitrary: r rule: lfp.fixp_induct_uc[of "λx. x" F "λx. x", OF mono reflexive refl])(auto simp add: F_def split: resumption.split) show"x ∈ ?fixp r"if"x ∈ outputs r"for x r using that by induct(subst lfp.mono_body_fixp[OF mono]; auto simp add: F_def; fail)+ qed
lemma pred_resumption_antimono: assumes r: "pred_resumption A C r'" and le: "resumption_ord r r'" shows"pred_resumption A C r" using r monotoneD[OF monotone_results le] monotoneD[OF monotone_outputs le] by(auto simp add: pred_resumption_def)
lemma rel_resumption_OO [relator_distr]: "rel_resumption A B OO rel_resumption C D = rel_resumption (A OO C) (B OO D)" by(simp add: resumption.rel_compp)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.