# HG changeset patch # User nipkow # Date 1566287302 -7200 # Node ID 17909568216ef9460accbb8ff8f22b380a424efe # Parent ea860617fac193bcbf7223d35cf4b900e375c9e0# Parent 7beee08eb16334d1a36b6a4331e5272e79a13aa5 merged diff -r ea860617fac1 -r 17909568216e src/HOL/Data_Structures/Set2_Join.thy --- a/src/HOL/Data_Structures/Set2_Join.thy Mon Aug 19 21:37:34 2019 +0200 +++ b/src/HOL/Data_Structures/Set2_Join.thy Tue Aug 20 09:48:22 2019 +0200 @@ -23,12 +23,10 @@ fixes join :: "('a::linorder,'b) tree \ 'a \ ('a,'b) tree \ ('a,'b) tree" fixes inv :: "('a,'b) tree \ bool" assumes set_join: "set_tree (join l a r) = set_tree l \ {a} \ set_tree r" -assumes bst_join: - "\ bst l; bst r; \x \ set_tree l. x < a; \y \ set_tree r. a < y \ - \ bst (join l a r)" +assumes bst_join: "bst (Node l a b r) \ bst (join l a r)" assumes inv_Leaf: "inv \\" assumes inv_join: "\ inv l; inv r \ \ inv (join l a r)" -assumes inv_Node: "\ inv (Node l a h r) \ \ inv l \ inv r" +assumes inv_Node: "\ inv (Node l a b r) \ \ inv l \ inv r" begin declare set_join [simp] @@ -40,7 +38,7 @@ (if l = Leaf then (a,r) else let (m,l') = split_min l in (m, join l' a r))" lemma split_min_set: - "\ split_min t = (m,t'); t \ Leaf \ \ m \ set_tree t \ set_tree t = Set.insert m (set_tree t')" + "\ split_min t = (m,t'); t \ Leaf \ \ m \ set_tree t \ set_tree t = {m} \ set_tree t'" proof(induction t arbitrary: t') case Node thus ?case by(auto split: prod.splits if_splits dest: inv_Node) next @@ -115,7 +113,7 @@ definition insert :: "'a \ ('a,'b) tree \ ('a,'b) tree" where "insert x t = (let (l,_,r) = split t x in join l x r)" -lemma set_tree_insert: "bst t \ set_tree (insert x t) = Set.insert x (set_tree t)" +lemma set_tree_insert: "bst t \ set_tree (insert x t) = {x} \ set_tree t" by(auto simp add: insert_def split split: prod.split) lemma bst_insert: "bst t \ bst (insert x t)" diff -r ea860617fac1 -r 17909568216e src/HOL/Data_Structures/Set2_Join_RBT.thy --- a/src/HOL/Data_Structures/Set2_Join_RBT.thy Mon Aug 19 21:37:34 2019 +0200 +++ b/src/HOL/Data_Structures/Set2_Join_RBT.thy Tue Aug 20 09:48:22 2019 +0200 @@ -168,32 +168,32 @@ by(simp add: set_joinL set_joinR set_paint) lemma bst_baliL: - "\bst l; bst r; \x\set_tree l. x < k; \x\set_tree r. k < x\ - \ bst (baliL l k r)" -by(cases "(l,k,r)" rule: baliL.cases) (auto simp: ball_Un) + "\bst l; bst r; \x\set_tree l. x < a; \x\set_tree r. a < x\ + \ bst (baliL l a r)" +by(cases "(l,a,r)" rule: baliL.cases) (auto simp: ball_Un) lemma bst_baliR: - "\bst l; bst r; \x\set_tree l. x < k; \x\set_tree r. k < x\ - \ bst (baliR l k r)" -by(cases "(l,k,r)" rule: baliR.cases) (auto simp: ball_Un) + "\bst l; bst r; \x\set_tree l. x < a; \x\set_tree r. a < x\ + \ bst (baliR l a r)" +by(cases "(l,a,r)" rule: baliR.cases) (auto simp: ball_Un) lemma bst_joinL: - "\bst l; bst r; \x\set_tree l. x < k; \y\set_tree r. k < y; bheight l \ bheight r\ - \ bst (joinL l k r)" -proof(induction l k r rule: joinL.induct) - case (1 l x r) + "\bst (Node l a n r); bheight l \ bheight r\ + \ bst (joinL l a r)" +proof(induction l a r rule: joinL.induct) + case (1 l a r) thus ?case - by(auto simp: set_baliL joinL.simps[of l x r] set_joinL ball_Un intro!: bst_baliL + by(auto simp: set_baliL joinL.simps[of l a r] set_joinL ball_Un intro!: bst_baliL split!: tree.splits color.splits) qed lemma bst_joinR: - "\bst l; bst r; \x\set_tree l. x < k; \y\set_tree r. k < y \ - \ bst (joinR l k r)" -proof(induction l k r rule: joinR.induct) - case (1 l x r) + "\bst l; bst r; \x\set_tree l. x < a; \y\set_tree r. a < y \ + \ bst (joinR l a r)" +proof(induction l a r rule: joinR.induct) + case (1 l a r) thus ?case - by(auto simp: set_baliR joinR.simps[of l x r] set_joinR ball_Un intro!: bst_baliR + by(auto simp: set_baliR joinR.simps[of l a r] set_joinR ball_Un intro!: bst_baliR split!: tree.splits color.splits) qed @@ -201,10 +201,11 @@ by(cases t) auto lemma bst_join: - "\bst l; bst r; \x\set_tree l. x < k; \y\set_tree r. k < y \ - \ bst (join l k r)" + "bst (Node l a n r) \ bst (join l a r)" by(auto simp: bst_paint bst_joinL bst_joinR) +lemma inv_join: "\ invc l; invh l; invc r; invh r \ \ invc(join l x r) \ invh(join l x r)" +by (simp add: invc2_joinL invc2_joinR invc_paint_Black invh_joinL invh_joinR invh_paint) subsubsection "Interpretation of \<^locale>\Set2_Join\ with Red-Black Tree" @@ -215,12 +216,11 @@ proof (standard, goal_cases) case 1 show ?case by (rule set_join) next - case 2 thus ?case by (rule bst_join) + case 2 thus ?case by (simp add: bst_join del: join.simps) next case 3 show ?case by simp next - case 4 thus ?case - by (simp add: invc2_joinL invc2_joinR invc_paint_Black invh_joinL invh_joinR invh_paint) + case 4 thus ?case by (simp add: inv_join del: join.simps) next case 5 thus ?case by simp qed