src/HOL/Library/RBT_Set.thy
 changeset 53955 436649a2ed62 parent 53745 788730ab7da4 child 54263 c4159fe6fa46
1.1 --- a/src/HOL/Library/RBT_Set.thy	Fri Sep 27 15:38:23 2013 +0200
1.2 +++ b/src/HOL/Library/RBT_Set.thy	Fri Sep 27 16:48:47 2013 +0200
1.3 @@ -135,6 +135,9 @@
1.4  lemma [code, code del]:
1.5    "List.map_project = List.map_project" ..
1.7 +lemma [code, code del]:
1.8 +  "List.Bleast = List.Bleast" ..
1.9 +
1.10  section {* Lemmas *}
1.13 @@ -805,6 +808,28 @@
1.14    "sorted_list_of_set (Set t) = keys t"
1.15  by (auto simp add: set_keys intro: sorted_distinct_set_unique)
1.17 +lemma Bleast_code [code]:
1.18 + "Bleast (Set t) P = (case filter P (keys t) of
1.19 +    x#xs \<Rightarrow> x |
1.20 +    [] \<Rightarrow> abort_Bleast (Set t) P)"
1.21 +proof (cases "filter P (keys t)")
1.22 +  case Nil thus ?thesis by (simp add: Bleast_def abort_Bleast_def)
1.23 +next
1.24 +  case (Cons x ys)
1.25 +  have "(LEAST x. x \<in> Set t \<and> P x) = x"
1.26 +  proof (rule Least_equality)
1.27 +    show "x \<in> Set t \<and> P x" using Cons[symmetric]
1.28 +      by(auto simp add: set_keys Cons_eq_filter_iff)
1.29 +    next
1.30 +      fix y assume "y : Set t \<and> P y"
1.31 +      then show "x \<le> y" using Cons[symmetric]
1.32 +        by(auto simp add: set_keys Cons_eq_filter_iff)
1.33 +          (metis sorted_Cons sorted_append sorted_keys)
1.34 +  qed
1.35 +  thus ?thesis using Cons by (simp add: Bleast_def)
1.36 +qed
1.37 +
1.38 +
1.39  hide_const (open) RBT_Set.Set RBT_Set.Coset
1.41  end