merged
authornipkow
Fri Sep 27 17:20:02 2013 +0200 (2013-09-27)
changeset 53956967728367ad9
parent 53953 2f103a894ebe
parent 53955 436649a2ed62
child 53957 ce12e547e6bb
child 53958 50673b362324
merged
     1.1 --- a/src/HOL/Library/RBT_Set.thy	Fri Sep 27 14:43:26 2013 +0200
     1.2 +++ b/src/HOL/Library/RBT_Set.thy	Fri Sep 27 17:20:02 2013 +0200
     1.3 @@ -135,6 +135,9 @@
     1.4  lemma [code, code del]: 
     1.5    "List.map_project = List.map_project" ..
     1.6  
     1.7 +lemma [code, code del]: 
     1.8 +  "List.Bleast = List.Bleast" ..
     1.9 +
    1.10  section {* Lemmas *}
    1.11  
    1.12  
    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.16  
    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.40  
    1.41  end
     2.1 --- a/src/HOL/List.thy	Fri Sep 27 14:43:26 2013 +0200
     2.2 +++ b/src/HOL/List.thy	Fri Sep 27 17:20:02 2013 +0200
     2.3 @@ -5961,6 +5961,37 @@
     2.4    "setsum f (set [m..<n]) = listsum (map f [m..<n])"
     2.5    by (simp add: interv_listsum_conv_setsum_set_nat)
     2.6  
     2.7 +text{* Bounded @{text LEAST} operator: *}
     2.8 +
     2.9 +definition "Bleast S P = (LEAST x. x \<in> S \<and> P x)"
    2.10 +
    2.11 +definition "abort_Bleast S P = (LEAST x. x \<in> S \<and> P x)"
    2.12 +
    2.13 +code_abort abort_Bleast
    2.14 +
    2.15 +lemma Bleast_code [code]:
    2.16 + "Bleast (set xs) P = (case filter P (sort xs) of
    2.17 +    x#xs \<Rightarrow> x |
    2.18 +    [] \<Rightarrow> abort_Bleast (set xs) P)"
    2.19 +proof (cases "filter P (sort xs)")
    2.20 +  case Nil thus ?thesis by (simp add: Bleast_def abort_Bleast_def)
    2.21 +next
    2.22 +  case (Cons x ys)
    2.23 +  have "(LEAST x. x \<in> set xs \<and> P x) = x"
    2.24 +  proof (rule Least_equality)
    2.25 +    show "x \<in> set xs \<and> P x"
    2.26 +      by (metis Cons Cons_eq_filter_iff in_set_conv_decomp set_sort)
    2.27 +    next
    2.28 +      fix y assume "y : set xs \<and> P y"
    2.29 +      hence "y : set (filter P xs)" by auto
    2.30 +      thus "x \<le> y"
    2.31 +        by (metis Cons eq_iff filter_sort set_ConsD set_sort sorted_Cons sorted_sort)
    2.32 +  qed
    2.33 +  thus ?thesis using Cons by (simp add: Bleast_def)
    2.34 +qed
    2.35 +
    2.36 +declare Bleast_def[symmetric, code_unfold]
    2.37 +
    2.38  text {* Summation over ints. *}
    2.39  
    2.40  lemma greaterThanLessThan_upto [code_unfold]: