From ac957c4a236828feec259ec58168a34e24024dcb Mon Sep 17 00:00:00 2001 From: Simon Foster Date: Mon, 15 Jul 2024 10:57:19 +0100 Subject: [PATCH] Started an experiment on an alternative way of characterising external choice. --- UTP/ITree_CSP_DivChoice.thy | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 UTP/ITree_CSP_DivChoice.thy diff --git a/UTP/ITree_CSP_DivChoice.thy b/UTP/ITree_CSP_DivChoice.thy new file mode 100644 index 0000000..90e9561 --- /dev/null +++ b/UTP/ITree_CSP_DivChoice.thy @@ -0,0 +1,81 @@ +theory ITree_CSP_DivChoice + imports ITree_CSP +begin + +text \ An alternative way of characterising external choice that avoids introducing non-determinism. + Instead of ignoring choices where the event is present on both sides, we instead diverge + after making that choice. This introduces more overhead, but has a simpler domain and is + likely associative. \ + +hide_const Map.dom + +definition dcmerge :: "('e, 'r) chomerge" (infixr "\" 100) where +"dcmerge F G = (\ x\pdom F \ pdom G \ if x \ pdom G then F(x)\<^sub>p else if x \ pdom F then G(x)\<^sub>p else diverge)" + +lemma dcmerge_alt_def: "f \ g = (pdom(g) \ f) \ (pdom(f) \ g) \ (\ x\pdom(f) \ pdom(g) \ diverge)" + by (auto simp add: dcmerge_def pfun_eq_iff) + +lemma dcmerge_commute: "x \ y = y \ x" + by (auto simp add: dcmerge_def pfun_eq_iff) + +lemma dcmerge_empty [simp]: "x \ {}\<^sub>p = x" "{}\<^sub>p \ x = x" + by (simp_all add: dcmerge_def pfun_eq_iff) + +lemma dcmerge_update: + "f(x \ v)\<^sub>p \ g = + (if (x \ pdom(g)) then (f \ g)(x \ v)\<^sub>p else (f \ g)(x \ diverge)\<^sub>p)" + by (auto simp add: dcmerge_def pfun_eq_iff) + +lemma dcmerge_as_ovrd: + assumes "pdom(f) \ pdom(g) = {}" + shows "f \ g = f \ g" + using assms by (auto simp add: dcmerge_def pfun_eq_iff) + +lemma dcmerge_pfun_of_map [code]: + "dcmerge (pfun_of_map f) (pfun_of_map g) = + pfun_of_map (\ x. case (f x, g x) of + (Some _, Some _) \ Some diverge | + (Some y, None) \ Some y | + (None, Some y) \ Some y | + (None, None) \ None)" + by (simp add: dcmerge_def pfun_eq_iff) + (auto simp add: option.case_eq_if pdom_def pdom_res_def) + + +lemma dcmerge_lemma: + "fst ` set xs \ fst ` set ys = set (filter (\x. x \ set (map fst xs)) (map fst ys))" + by auto + +lemma excl_comb_pfun_of_alist [code]: + "dcmerge (pfun_of_alist xs) (pfun_of_alist ys) = + pfun_of_alist ( map (\ x. (x, diverge)) (filter (\x. x \ set (map fst xs)) (map fst ys)) + @ AList.restrict (- fst ` set xs) ys + @ AList.restrict (- fst ` set ys) xs)" + apply (simp add: dcmerge_alt_def pdom_res_alist plus_pfun_alist pabs_set) + apply (simp only: dcmerge_lemma pabs_set plus_pfun_alist) + apply simp + done + +(* +lemma excl_comb_pfun_of_map_alist [code]: "(pfun_of_map f) \ (pfun_of_alist xs) + = pfun_of_map + (\x. case f x of None \ (case map_of xs x of None \ None | Some x \ Some x) + | Some xa \ (case map_of xs x of None \ Some xa | Some x \ Map.empty x))" + by (simp add: pfun_of_alist.abs_eq excl_comb_pfun_of_map) + +lemma excl_comb_pfun_of_alist_map [code]: "(pfun_of_alist xs) \ (pfun_of_map p) + = pfun_of_map + (\x. case map_of xs x of None \ (case p x of None \ None | Some x \ Some x) + | Some xa \ (case p x of None \ Some xa | Some x \ Map.empty x))" + by (simp add: pfun_of_alist.abs_eq excl_comb_pfun_of_map) + +lemma excl_comb_Nil_alist [code]: + "(pfun_of_alist []) \ P = P" + "P \ (pfun_of_alist []) = P" + by simp_all + +definition excl_combs :: "('a \ 'b) list \ 'a \ 'b" where +"excl_combs Ps = foldr (\) Ps {}\<^sub>p" +*) + +end \ No newline at end of file