# HG changeset patch # User nipkow # Date 1485534908 -3600 # Node ID f9cfb10761ff4c1816e1b0a37e1c8e726b0e8054 # Parent f11e974b47e062276dfdbc684e4fb986465ad448 tuned name diff -r f11e974b47e0 -r f9cfb10761ff src/HOL/Data_Structures/RBT_Set.thy --- a/src/HOL/Data_Structures/RBT_Set.thy Fri Jan 27 17:28:10 2017 +0100 +++ b/src/HOL/Data_Structures/RBT_Set.thy Fri Jan 27 17:35:08 2017 +0100 @@ -106,15 +106,15 @@ "invc (Node c l a r) = (invc l \ invc r \ (c = Red \ color l = Black \ color r = Black))" -fun invc_sons :: "'a rbt \ bool" \ \Weaker version\ where -"invc_sons Leaf = True" | -"invc_sons (Node c l a r) = (invc l \ invc r)" +fun invc2 :: "'a rbt \ bool" \ \Weaker version\ where +"invc2 Leaf = True" | +"invc2 (Node c l a r) = (invc l \ invc r)" fun invh :: "'a rbt \ bool" where "invh Leaf = True" | "invh (Node c l x r) = (invh l \ invh r \ bheight l = bheight r)" -lemma invc_sonsI: "invc t \ invc_sons t" +lemma invc2I: "invc t \ invc2 t" by (cases t) simp+ definition rbt :: "'a rbt \ bool" where @@ -126,17 +126,17 @@ theorem rbt_Leaf: "rbt Leaf" by (simp add: rbt_def) -lemma paint_invc_sons: "invc_sons t \ invc_sons (paint c t)" +lemma paint_invc2: "invc2 t \ invc2 (paint c t)" by (cases t) auto -lemma invc_paint_Black: "invc_sons t \ invc (paint Black t)" +lemma invc_paint_Black: "invc2 t \ invc (paint Black t)" by (cases t) auto lemma invh_paint: "invh t \ invh (paint c t)" by (cases t) auto lemma invc_bal: - "\invc l \ invc_sons r \ invc_sons l \ invc r\ \ invc (bal l a r)" + "\invc l \ invc2 r \ invc2 l \ invc r\ \ invc (bal l a r)" by (induct l a r rule: bal.induct) auto lemma bheight_bal: @@ -151,9 +151,9 @@ subsubsection \Insertion\ lemma invc_ins: assumes "invc t" - shows "color t = Black \ invc (ins x t)" "invc_sons (ins x t)" + shows "color t = Black \ invc (ins x t)" "invc2 (ins x t)" using assms -by (induct x t rule: ins.induct) (auto simp: invc_bal invc_sonsI) +by (induct x t rule: ins.induct) (auto simp: invc_bal invc2I) lemma invh_ins: assumes "invh t" shows "invh (ins x t)" "bheight (ins x t) = bheight t" @@ -185,11 +185,11 @@ using assms by (induct lt a rt rule: balL.induct) (auto simp add: invh_bal bheight_bal) -lemma balL_invc: "\invc_sons l; invc r; color r = Black\ \ invc (balL l a r)" +lemma balL_invc: "\invc2 l; invc r; color r = Black\ \ invc (balL l a r)" by (induct l a r rule: balL.induct) (simp_all add: invc_bal) -lemma balL_invc_sons: "\ invc_sons lt; invc rt \ \ invc_sons (balL lt a rt)" -by (induct lt a rt rule: balL.induct) (auto simp: invc_bal paint_invc_sons invc_sonsI) +lemma balL_invc2: "\ invc2 lt; invc rt \ \ invc2 (balL lt a rt)" +by (induct lt a rt rule: balL.induct) (auto simp: invc_bal paint_invc2 invc2I) lemma balR_invh_with_invc: assumes "invh lt" "invh rt" "bheight lt = bheight rt + 1" "invc lt" @@ -198,11 +198,11 @@ by(induct lt a rt rule: balR.induct) (auto simp: invh_bal bheight_bal invh_paint bheight_paint_Red) -lemma invc_balR: "\invc a; invc_sons b; color a = Black\ \ invc (balR a x b)" +lemma invc_balR: "\invc a; invc2 b; color a = Black\ \ invc (balR a x b)" by (induct a x b rule: balR.induct) (simp_all add: invc_bal) -lemma invc_sons_balR: "\ invc lt; invc_sons rt \ \invc_sons (balR lt x rt)" -by (induct lt x rt rule: balR.induct) (auto simp: invc_bal paint_invc_sons invc_sonsI) +lemma invc2_balR: "\ invc lt; invc2 rt \ \invc2 (balR lt x rt)" +by (induct lt x rt rule: balR.induct) (auto simp: invc_bal paint_invc2 invc2I) lemma invh_combine: assumes "invh lt" "invh rt" "bheight lt = bheight rt" @@ -214,26 +214,26 @@ lemma invc_combine: assumes "invc lt" "invc rt" shows "color lt = Black \ color rt = Black \ invc (combine lt rt)" - "invc_sons (combine lt rt)" + "invc2 (combine lt rt)" using assms by (induct lt rt rule: combine.induct) - (auto simp: balL_invc invc_sonsI split: tree.splits color.splits) + (auto simp: balL_invc invc2I split: tree.splits color.splits) lemma assumes "invh lt" "invc lt" shows del_invc_invh: "invh (del x lt) \ (color lt = Red \ bheight (del x lt) = bheight lt \ invc (del x lt) - \ color lt = Black \ bheight (del x lt) = bheight lt - 1 \ invc_sons (del x lt))" + \ color lt = Black \ bheight (del x lt) = bheight lt - 1 \ invc2 (del x lt))" and "\invh rt; bheight lt = bheight rt; invc rt\ \ invh (delL x lt k rt) \ bheight (delL x lt k rt) = bheight lt \ (color lt = Black \ color rt = Black \ invc (delL x lt k rt) \ - (color lt \ Black \ color rt \ Black) \ invc_sons (delL x lt k rt))" + (color lt \ Black \ color rt \ Black) \ invc2 (delL x lt k rt))" and "\invh rt; bheight lt = bheight rt; invc rt\ \ invh (delR x lt k rt) \ bheight (delR x lt k rt) = bheight lt \ (color lt = Black \ color rt = Black \ invc (delR x lt k rt) \ - (color lt \ Black \ color rt \ Black) \ invc_sons (delR x lt k rt))" + (color lt \ Black \ color rt \ Black) \ invc2 (delR x lt k rt))" using assms proof (induct x lt and x lt k rt and x lt k rt rule: del_delL_delR.induct) case (2 y c _ y') @@ -244,23 +244,23 @@ by (cases c) (simp_all add: invh_combine invc_combine) next assume "y < y'" - with 2 show ?thesis by (cases c) (auto simp: invc_sonsI) + with 2 show ?thesis by (cases c) (auto simp: invc2I) next assume "y' < y" - with 2 show ?thesis by (cases c) (auto simp: invc_sonsI) + with 2 show ?thesis by (cases c) (auto simp: invc2I) qed next case (3 y lt z rta y' bb) - thus ?case by (cases "color (Node Black lt z rta) = Black \ color bb = Black") (simp add: balL_invh_with_invc balL_invc balL_invc_sons)+ + thus ?case by (cases "color (Node Black lt z rta) = Black \ color bb = Black") (simp add: balL_invh_with_invc balL_invc balL_invc2)+ next case (5 y a y' lt z rta) - thus ?case by (cases "color a = Black \ color (Node Black lt z rta) = Black") (simp add: balR_invh_with_invc invc_balR invc_sons_balR)+ + thus ?case by (cases "color a = Black \ color (Node Black lt z rta) = Black") (simp add: balR_invh_with_invc invc_balR invc2_balR)+ next case ("6_1" y a y') thus ?case by (cases "color a = Black \ color Leaf = Black") simp+ qed auto theorem rbt_delete: "rbt t \ rbt (delete k t)" -by (metis delete_def rbt_def color_paint_Black del_invc_invh invc_paint_Black invc_sonsI invh_paint) +by (metis delete_def rbt_def color_paint_Black del_invc_invh invc_paint_Black invc2I invh_paint) text \Overall correctness:\