1050 unfolding is_rbt_def by (simp add: map_inv1 map_inv2 map_rbt_sorted map_color_of) |
1050 unfolding is_rbt_def by (simp add: map_inv1 map_inv2 map_rbt_sorted map_color_of) |
1051 |
1051 |
1052 end |
1052 end |
1053 |
1053 |
1054 theorem (in linorder) rbt_lookup_map: "rbt_lookup (map f t) x = map_option (f x) (rbt_lookup t x)" |
1054 theorem (in linorder) rbt_lookup_map: "rbt_lookup (map f t) x = map_option (f x) (rbt_lookup t x)" |
1055 apply(induct t) |
1055 by (induct t) (auto simp: antisym_conv3) |
1056 apply auto |
|
1057 apply(rename_tac a b c, subgoal_tac "x = a") |
|
1058 apply auto |
|
1059 done |
|
1060 (* FIXME: simproc "antisym less" does not work for linorder context, only for linorder type class |
1056 (* FIXME: simproc "antisym less" does not work for linorder context, only for linorder type class |
1061 by (induct t) auto *) |
1057 by (induct t) auto *) |
1062 |
1058 |
1063 hide_const (open) map |
1059 hide_const (open) map |
1064 |
1060 |
2506 (fastforce simp: rbt_split_min_set rbt_sorted_rbt_join set_rbt_join rbt_less_prop rbt_greater_prop |
2502 (fastforce simp: rbt_split_min_set rbt_sorted_rbt_join set_rbt_join rbt_less_prop rbt_greater_prop |
2507 split: if_splits prod.splits)+ |
2503 split: if_splits prod.splits)+ |
2508 |
2504 |
2509 lemma rbt_split_min_rbt_lookup: "rbt_split_min t = (a,b,t') \<Longrightarrow> rbt_sorted t \<Longrightarrow> t \<noteq> RBT_Impl.Empty \<Longrightarrow> |
2505 lemma rbt_split_min_rbt_lookup: "rbt_split_min t = (a,b,t') \<Longrightarrow> rbt_sorted t \<Longrightarrow> t \<noteq> RBT_Impl.Empty \<Longrightarrow> |
2510 rbt_lookup t k = (if k < a then None else if k = a then Some b else rbt_lookup t' k)" |
2506 rbt_lookup t k = (if k < a then None else if k = a then Some b else rbt_lookup t' k)" |
2511 by (induction t arbitrary: a b t') |
2507 apply (induction t arbitrary: a b t') |
2512 (auto simp: rbt_less_trans antisym_conv3 rbt_less_prop rbt_split_min_set rbt_lookup_rbt_join |
2508 apply(simp_all split: if_splits prod.splits) |
2513 rbt_split_min_rbt_sorted split!: if_splits prod.splits) |
2509 apply(auto simp: rbt_less_prop rbt_split_min_set rbt_lookup_rbt_join rbt_split_min_rbt_sorted) |
|
2510 done |
2514 |
2511 |
2515 lemma rbt_sorted_rbt_join2: "rbt_sorted l \<Longrightarrow> rbt_sorted r \<Longrightarrow> |
2512 lemma rbt_sorted_rbt_join2: "rbt_sorted l \<Longrightarrow> rbt_sorted r \<Longrightarrow> |
2516 \<forall>x \<in> set (RBT_Impl.keys l). \<forall>y \<in> set (RBT_Impl.keys r). x < y \<Longrightarrow> rbt_sorted (rbt_join2 l r)" |
2513 \<forall>x \<in> set (RBT_Impl.keys l). \<forall>y \<in> set (RBT_Impl.keys r). x < y \<Longrightarrow> rbt_sorted (rbt_join2 l r)" |
2517 by (simp add: rbt_join2_def rbt_sorted_rbt_join rbt_split_min_set rbt_split_min_rbt_sorted set_rbt_join |
2514 by (simp add: rbt_join2_def rbt_sorted_rbt_join rbt_split_min_set rbt_split_min_rbt_sorted set_rbt_join |
2518 rbt_greater_prop rbt_less_prop split: prod.split) |
2515 rbt_greater_prop rbt_less_prop split: prod.split) |
2526 |
2523 |
2527 lemma rbt_split_props: "rbt_split t x = (l,\<beta>,r) \<Longrightarrow> rbt_sorted t \<Longrightarrow> |
2524 lemma rbt_split_props: "rbt_split t x = (l,\<beta>,r) \<Longrightarrow> rbt_sorted t \<Longrightarrow> |
2528 set (RBT_Impl.keys l) = {a \<in> set (RBT_Impl.keys t). a < x} \<and> |
2525 set (RBT_Impl.keys l) = {a \<in> set (RBT_Impl.keys t). a < x} \<and> |
2529 set (RBT_Impl.keys r) = {a \<in> set (RBT_Impl.keys t). x < a} \<and> |
2526 set (RBT_Impl.keys r) = {a \<in> set (RBT_Impl.keys t). x < a} \<and> |
2530 rbt_sorted l \<and> rbt_sorted r" |
2527 rbt_sorted l \<and> rbt_sorted r" |
2531 by (induction t arbitrary: l r) |
2528 apply (induction t arbitrary: l r) |
2532 (force simp: Let_def set_rbt_join rbt_greater_prop rbt_less_prop |
2529 apply(simp_all split!: prod.splits if_splits) |
2533 split: if_splits prod.splits intro!: rbt_sorted_rbt_join)+ |
2530 apply(force simp: set_rbt_join rbt_greater_prop rbt_less_prop |
|
2531 intro: rbt_sorted_rbt_join)+ |
|
2532 done |
2534 |
2533 |
2535 lemma rbt_split_lookup: "rbt_split t x = (l,\<beta>,r) \<Longrightarrow> rbt_sorted t \<Longrightarrow> |
2534 lemma rbt_split_lookup: "rbt_split t x = (l,\<beta>,r) \<Longrightarrow> rbt_sorted t \<Longrightarrow> |
2536 rbt_lookup t k = (if k < x then rbt_lookup l k else if k = x then \<beta> else rbt_lookup r k)" |
2535 rbt_lookup t k = (if k < x then rbt_lookup l k else if k = x then \<beta> else rbt_lookup r k)" |
2537 proof (induction t arbitrary: x l \<beta> r) |
2536 proof (induction t arbitrary: x l \<beta> r) |
2538 case (Branch c t1 a b t2) |
2537 case (Branch c t1 a b t2) |
2882 have "rbt_lookup (rbt_minus_rec t1 t2) k = |
2881 have "rbt_lookup (rbt_minus_rec t1 t2) k = |
2883 (case rbt_lookup t1 k of None \<Rightarrow> None |
2882 (case rbt_lookup t1 k of None \<Rightarrow> None |
2884 | Some v \<Rightarrow> (case rbt_lookup t2 k of None \<Rightarrow> Some v | _ \<Rightarrow> None))" |
2883 | Some v \<Rightarrow> (case rbt_lookup t2 k of None \<Rightarrow> Some v | _ \<Rightarrow> None))" |
2885 using not_small rbt_lookup_iff_keys(2)[of l1] rbt_lookup_iff_keys(3)[of l1] |
2884 using not_small rbt_lookup_iff_keys(2)[of l1] rbt_lookup_iff_keys(3)[of l1] |
2886 rbt_lookup_iff_keys(3)[of r1] rbt_split_t1_props |
2885 rbt_lookup_iff_keys(3)[of r1] rbt_split_t1_props |
|
2886 using [[simp_depth_limit = 2]] |
2887 by (auto simp: rbt_minus_rec.simps[of t1] Branch rbt_split_t1 rbt_lookup_join2 |
2887 by (auto simp: rbt_minus_rec.simps[of t1] Branch rbt_split_t1 rbt_lookup_join2 |
2888 minus_l1_l2(2) minus_r1_r2(2) rbt_split_lookup[OF rbt_split_t1 1(4)] lookup_l1_r1_a |
2888 minus_l1_l2(2) minus_r1_r2(2) rbt_split_lookup[OF rbt_split_t1 1(4)] lookup_l1_r1_a |
2889 split: option.splits) |
2889 split: option.splits) |
2890 moreover have "rbt_sorted (rbt_minus_rec t1 t2)" |
2890 moreover have "rbt_sorted (rbt_minus_rec t1 t2)" |
2891 using not_small minus_l1_l2(1) minus_r1_r2(1) rbt_split_t1_props rbt_sorted_rbt_join2 |
2891 using not_small minus_l1_l2(1) minus_r1_r2(1) rbt_split_t1_props rbt_sorted_rbt_join2 |