equal
deleted
inserted
replaced
904 with \<open>xx = yy\<close> 2 \<open>xx = k\<close> show ?thesis by (simp add: combine_in_tree) |
904 with \<open>xx = yy\<close> 2 \<open>xx = k\<close> show ?thesis by (simp add: combine_in_tree) |
905 qed (simp add: combine_in_tree) |
905 qed (simp add: combine_in_tree) |
906 qed simp+ |
906 qed simp+ |
907 next |
907 next |
908 case (3 xx lta zz vv rta yy ss bb) |
908 case (3 xx lta zz vv rta yy ss bb) |
909 def mt[simp]: mt == "Branch B lta zz vv rta" |
909 define mt where [simp]: "mt = Branch B lta zz vv rta" |
910 from 3 have "inv2 mt \<and> inv1 mt" by simp |
910 from 3 have "inv2 mt \<and> inv1 mt" by simp |
911 hence "inv2 (rbt_del xx mt) \<and> (color_of mt = R \<and> bheight (rbt_del xx mt) = bheight mt \<and> inv1 (rbt_del xx mt) \<or> color_of mt = B \<and> bheight (rbt_del xx mt) = bheight mt - 1 \<and> inv1l (rbt_del xx mt))" by (blast dest: rbt_del_inv1_inv2) |
911 hence "inv2 (rbt_del xx mt) \<and> (color_of mt = R \<and> bheight (rbt_del xx mt) = bheight mt \<and> inv1 (rbt_del xx mt) \<or> color_of mt = B \<and> bheight (rbt_del xx mt) = bheight mt - 1 \<and> inv1l (rbt_del xx mt))" by (blast dest: rbt_del_inv1_inv2) |
912 with 3 have 4: "entry_in_tree k v (rbt_del_from_left xx mt yy ss bb) = (False \<or> xx \<noteq> k \<and> entry_in_tree k v mt \<or> (k = yy \<and> v = ss) \<or> entry_in_tree k v bb)" by (simp add: balance_left_in_tree) |
912 with 3 have 4: "entry_in_tree k v (rbt_del_from_left xx mt yy ss bb) = (False \<or> xx \<noteq> k \<and> entry_in_tree k v mt \<or> (k = yy \<and> v = ss) \<or> entry_in_tree k v bb)" by (simp add: balance_left_in_tree) |
913 thus ?case proof (cases "xx = k") |
913 thus ?case proof (cases "xx = k") |
914 case True |
914 case True |
934 hence "k \<guillemotleft>| bb" by (blast dest: rbt_greater_trans) |
934 hence "k \<guillemotleft>| bb" by (blast dest: rbt_greater_trans) |
935 with True "4_2" show ?thesis by (auto simp: rbt_greater_nit) |
935 with True "4_2" show ?thesis by (auto simp: rbt_greater_nit) |
936 qed auto |
936 qed auto |
937 next |
937 next |
938 case (5 xx aa yy ss lta zz vv rta) |
938 case (5 xx aa yy ss lta zz vv rta) |
939 def mt[simp]: mt == "Branch B lta zz vv rta" |
939 define mt where [simp]: "mt = Branch B lta zz vv rta" |
940 from 5 have "inv2 mt \<and> inv1 mt" by simp |
940 from 5 have "inv2 mt \<and> inv1 mt" by simp |
941 hence "inv2 (rbt_del xx mt) \<and> (color_of mt = R \<and> bheight (rbt_del xx mt) = bheight mt \<and> inv1 (rbt_del xx mt) \<or> color_of mt = B \<and> bheight (rbt_del xx mt) = bheight mt - 1 \<and> inv1l (rbt_del xx mt))" by (blast dest: rbt_del_inv1_inv2) |
941 hence "inv2 (rbt_del xx mt) \<and> (color_of mt = R \<and> bheight (rbt_del xx mt) = bheight mt \<and> inv1 (rbt_del xx mt) \<or> color_of mt = B \<and> bheight (rbt_del xx mt) = bheight mt - 1 \<and> inv1l (rbt_del xx mt))" by (blast dest: rbt_del_inv1_inv2) |
942 with 5 have 3: "entry_in_tree k v (rbt_del_from_right xx aa yy ss mt) = (entry_in_tree k v aa \<or> (k = yy \<and> v = ss) \<or> False \<or> xx \<noteq> k \<and> entry_in_tree k v mt)" by (simp add: balance_right_in_tree) |
942 with 5 have 3: "entry_in_tree k v (rbt_del_from_right xx aa yy ss mt) = (entry_in_tree k v aa \<or> (k = yy \<and> v = ss) \<or> False \<or> xx \<noteq> k \<and> entry_in_tree k v mt)" by (simp add: balance_right_in_tree) |
943 thus ?case proof (cases "xx = k") |
943 thus ?case proof (cases "xx = k") |
944 case True |
944 case True |
1922 |
1922 |
1923 lemma is_rbt_fold_rbt_insertwk: |
1923 lemma is_rbt_fold_rbt_insertwk: |
1924 assumes "is_rbt t1" |
1924 assumes "is_rbt t1" |
1925 shows "is_rbt (fold (rbt_insert_with_key f) t2 t1)" |
1925 shows "is_rbt (fold (rbt_insert_with_key f) t2 t1)" |
1926 proof - |
1926 proof - |
1927 def xs \<equiv> "entries t2" |
1927 define xs where "xs = entries t2" |
1928 from assms show ?thesis unfolding fold_def xs_def[symmetric] |
1928 from assms show ?thesis unfolding fold_def xs_def[symmetric] |
1929 by(induct xs rule: rev_induct)(auto simp add: rbt_insertwk_is_rbt) |
1929 by(induct xs rule: rev_induct)(auto simp add: rbt_insertwk_is_rbt) |
1930 qed |
1930 qed |
1931 |
1931 |
1932 lemma rbt_lookup_fold_rbt_insertwk: |
1932 lemma rbt_lookup_fold_rbt_insertwk: |
1934 shows "rbt_lookup (fold (rbt_insert_with_key f) t1 t2) k = |
1934 shows "rbt_lookup (fold (rbt_insert_with_key f) t1 t2) k = |
1935 (case rbt_lookup t1 k of None \<Rightarrow> rbt_lookup t2 k |
1935 (case rbt_lookup t1 k of None \<Rightarrow> rbt_lookup t2 k |
1936 | Some v \<Rightarrow> case rbt_lookup t2 k of None \<Rightarrow> Some v |
1936 | Some v \<Rightarrow> case rbt_lookup t2 k of None \<Rightarrow> Some v |
1937 | Some w \<Rightarrow> Some (f k w v))" |
1937 | Some w \<Rightarrow> Some (f k w v))" |
1938 proof - |
1938 proof - |
1939 def xs \<equiv> "entries t1" |
1939 define xs where "xs = entries t1" |
1940 hence dt1: "distinct (map fst xs)" using t1 by(simp add: distinct_entries) |
1940 hence dt1: "distinct (map fst xs)" using t1 by(simp add: distinct_entries) |
1941 with t2 show ?thesis |
1941 with t2 show ?thesis |
1942 unfolding fold_def map_of_entries[OF t1, symmetric] |
1942 unfolding fold_def map_of_entries[OF t1, symmetric] |
1943 xs_def[symmetric] distinct_map_of_rev[OF dt1, symmetric] |
1943 xs_def[symmetric] distinct_map_of_rev[OF dt1, symmetric] |
1944 apply(induct xs rule: rev_induct) |
1944 apply(induct xs rule: rev_induct) |