theory RBT_add imports RBT begin (* The next two lemmas are in my standard simpset, however I made them explicit for this proof: *) lemma map_add_dom_app_simps: "\ m\dom l2 \ \ (l1++l2) m = l2 m" "\ m\dom l1 \ \ (l1++l2) m = l2 m" "\ m\dom l2 \ \ (l1++l2) m = l1 m" by (auto simp add: map_add_def split: option.split_asm) lemma map_add_upd2: "m\dom e2 \ e1(m \ u1) ++ e2 = (e1 ++ e2)(m \ u1)" apply (unfold map_add_def) apply (rule ext) apply (auto split: option.split) done lemma map_of_alist_of_aux: "st (Tr c t1 k v t2) \ RBT.map_of (Tr c t1 k v t2) = RBT.map_of t2 ++ [k\v] ++ RBT.map_of t1" proof (rule ext) fix x assume ST: "st (Tr c t1 k v t2)" let ?thesis = "RBT.map_of (Tr c t1 k v t2) x = (RBT.map_of t2 ++ [k \ v] ++ RBT.map_of t1) x" have DOM_T1: "!!k'. k'\dom (RBT.map_of t1) \ k>k'" proof - fix k' from ST have "t1 |\ k" by simp with tlt_prop have "\k'\keys t1. k>k'" by auto moreover assume "k'\dom (RBT.map_of t1)" ultimately show "k>k'" using RBT.mapof_keys ST by auto qed have DOM_T2: "!!k'. k'\dom (RBT.map_of t2) \ k| t2" by simp with tgt_prop have "\k'\keys t2. kdom (RBT.map_of t2)" ultimately show "kdom [k\v]" by simp moreover have "x\dom (RBT.map_of t2)" proof assume "x\dom (RBT.map_of t2)" with DOM_T2 have "k v] x" by simp moreover have "x\dom (RBT.map_of t1)" proof assume "x\dom (RBT.map_of t1)" with DOM_T1 have "k>x" by blast thus False by simp qed ultimately have ?thesis by (simp add: map_add_upd2 map_add_dom_app_simps) } moreover { assume C: "x>k" hence "RBT.map_of (Tr c t1 k v t2) x = RBT.map_of t2 x" by (simp add: less_not_sym[of k x]) moreover from C have "x\dom [k\v]" by simp moreover have "x\dom (RBT.map_of t1)" proof assume "x\dom (RBT.map_of t1)" with DOM_T1 have "k>x" by simp with C show False by simp qed ultimately have ?thesis by (simp add: map_add_upd2 map_add_dom_app_simps) } ultimately show ?thesis using less_linear by blast qed (* This one is marked with an oops in RBT.thy *) lemma map_of_alist_of: shows "st t \ Map.map_of (alist_of t) = map_of t" proof (induct t) case Empty thus ?case by (simp add: RBT.map_of_Empty) next case (Tr c t1 k v t2) hence "Map.map_of (alist_of (Tr c t1 k v t2)) = RBT.map_of t2 ++ [k \ v] ++ RBT.map_of t1" by simp also note map_of_alist_of_aux[OF Tr.prems,symmetric] finally show ?case . qed end