(* Title: HOL/HOLCF/Library/Option_Cpo.thy Author: Brian Huffman *)
section‹Cpo class instance for HOL option type›
theory Option_Cpo imports HOLCF Sum_Cpo begin
subsection‹Ordering on option type›
instantiation option :: (below) below begin
definition below_option_def: "x ⊑ y ≡ case x of None ==> (case y of None ==> True | Some b ==> False) | Some a ==> (case y of None ==> False | Some b ==> a ⊑ b)"
instance .. end
lemma None_below_None [simp]: "None ⊑ None" unfolding below_option_def by simp
lemma Some_below_Some [simp]: "Some x ⊑ Some y ⟷ x ⊑ y" unfolding below_option_def by simp
lemma Some_below_None [simp]: "¬ Some x ⊑ None" unfolding below_option_def by simp
lemma None_below_Some [simp]: "¬ None ⊑ Some y" unfolding below_option_def by simp
lemma Some_mono: "x ⊑ y ==> Some x ⊑ Some y" by simp
lemma None_below_iff [simp]: "None ⊑ x ⟷ x = None" by (cases x, simp_all)
lemma below_None_iff [simp]: "x ⊑ None ⟷ x = None" by (cases x, simp_all)
lemma option_below_cases: assumes"x ⊑ y" obtains"x = None"and"y = None"
| a b where"x = Some a"and"y = Some b"and"a ⊑ b" using assms unfolding below_option_def by (simp split: option.split_asm)
subsection‹Option type is a complete partial order›
instance option :: (po) po proof fix x :: "'a option" show"x ⊑ x" unfolding below_option_def by (simp split: option.split) next fix x y :: "'a option" assume"x ⊑ y"and"y ⊑ x"thus"x = y" unfolding below_option_def by (auto split: option.split_asm intro: below_antisym) next fix x y z :: "'a option" assume"x ⊑ y"and"y ⊑ z"thus"x ⊑ z" unfolding below_option_def by (auto split: option.split_asm intro: below_trans) qed
lemma monofun_the: "monofun the" by (rule monofunI, erule option_below_cases, simp_all)
lemma option_chain_cases: assumes Y: "chain Y" obtains"Y = (λi. None)" | A where"chain A"and"Y = (λi. Some (A i))" apply (cases "Y 0") apply (rule that(1)) apply (rule ext) apply (cut_tac j=i in chain_mono [OF Y le0], simp) apply (rule that(2)) apply (rule ch2ch_monofun [OF monofun_the Y]) apply (rule ext) apply (cut_tac j=i in chain_mono [OF Y le0], simp) apply (case_tac "Y i", simp_all) done
lemma is_lub_Some: "range S <<| x ==> range (λi. Some (S i)) <<| Some x" apply (rule is_lubI) apply (rule ub_rangeI) apply (simp add: is_lub_rangeD1) apply (frule ub_rangeD [where i=arbitrary]) apply (case_tac u, simp_all) apply (erule is_lubD2) apply (rule ub_rangeI) apply (drule ub_rangeD, simp) done
lemma cont2cont_case_option: assumes f: "cont (λx. f x)" assumes g: "cont (λx. g x)" assumes h1: "∧a. cont (λx. h x a)" assumes h2: "∧x. cont (λa. h x a)" shows"cont (λx. case f x of None ==> g x | Some a ==> h x a)" apply (rule cont_apply [OF f]) apply (rule contI) apply (erule option_chain_cases) apply (simp add: is_lub_const) apply (simp add: lub_Some) apply (simp add: cont2contlubE [OF h2]) apply (rule cpo_lubI, rule chainI) apply (erule cont2monofunE [OF h2 chainE]) apply (case_tac y, simp_all add: g h1) done
lemma cont2cont_case_option' [simp, cont2cont]: assumes f: "cont (λx. f x)" assumes g: "cont (λx. g x)" assumes h: "cont (λp. h (fst p) (snd p))" shows"cont (λx. case f x of None ==> g x | Some a ==> h x a)" using assms by (simp add: cont2cont_case_option prod_cont_iff)
text‹Simple version for when the element type is not a cpo.›
lemma cont2cont_case_option_simple [simp, cont2cont]: assumes"cont (λx. f x)" assumes"∧a. cont (λx. g x a)" shows"cont (λx. case z of None ==> f x | Some a ==> g x a)" using assms by (cases z) auto
text‹Continuity rule for map.›
lemma cont2cont_map_option [simp, cont2cont]: assumes f: "cont (λ(x, y). f x y)" assumes g: "cont (λx. g x)" shows"cont (λx. map_option (λy. f x y) (g x))" using assms by (simp add: prod_cont_iff map_option_case)
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.