src/HOL/Quotient_Examples/Lift_RBT.thy
changeset 48621 877df57629e3
parent 47888 45bf22d8a81d
child 48622 caaa1a02c650
equal deleted inserted replaced
48620:fc9be489e2fb 48621:877df57629e3
    67 by simp
    67 by simp
    68 
    68 
    69 lift_definition fold :: "('a \<Rightarrow> 'b \<Rightarrow> 'c \<Rightarrow> 'c) \<Rightarrow> ('a\<Colon>linorder, 'b) rbt \<Rightarrow> 'c \<Rightarrow> 'c"  is RBT_Impl.fold 
    69 lift_definition fold :: "('a \<Rightarrow> 'b \<Rightarrow> 'c \<Rightarrow> 'c) \<Rightarrow> ('a\<Colon>linorder, 'b) rbt \<Rightarrow> 'c \<Rightarrow> 'c"  is RBT_Impl.fold 
    70 by simp
    70 by simp
    71 
    71 
    72 export_code lookup empty insert delete entries keys bulkload map_entry map fold in SML
    72 lift_definition union :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> ('a, 'b) rbt \<Rightarrow> ('a, 'b) rbt" is "rbt_union"
       
    73 by (simp add: rbt_union_is_rbt)
       
    74 
       
    75 lift_definition foldi :: "('c \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> 'c \<Rightarrow> 'c) \<Rightarrow> ('a :: linorder, 'b) rbt \<Rightarrow> 'c \<Rightarrow> 'c"
       
    76   is RBT_Impl.foldi by simp
       
    77 
       
    78 export_code lookup empty insert delete entries keys bulkload map_entry map fold union foldi in SML
    73 
    79 
    74 subsection {* Derived operations *}
    80 subsection {* Derived operations *}
    75 
    81 
    76 definition is_empty :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> bool" where
    82 definition is_empty :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> bool" where
    77   [code]: "is_empty t = (case impl_of t of RBT_Impl.Empty \<Rightarrow> True | _ \<Rightarrow> False)"
    83   [code]: "is_empty t = (case impl_of t of RBT_Impl.Empty \<Rightarrow> True | _ \<Rightarrow> False)"
   153 
   159 
   154 lemma distinct_keys [iff]:
   160 lemma distinct_keys [iff]:
   155   "distinct (keys t)"
   161   "distinct (keys t)"
   156   by transfer (simp add: RBT_Impl.keys_def distinct_entries)
   162   by transfer (simp add: RBT_Impl.keys_def distinct_entries)
   157 
   163 
       
   164 lemma finite_dom_lookup [simp, intro!]: "finite (dom (lookup t))"
       
   165   by transfer simp
       
   166 
       
   167 lemma lookup_union: "lookup (union s t) = lookup s ++ lookup t"
       
   168   by transfer (simp add: rbt_lookup_rbt_union)
       
   169 
       
   170 lemma lookup_in_tree: "(lookup t k = Some v) = ((k, v) \<in> set (entries t))"
       
   171   by transfer (simp add: rbt_lookup_in_tree)
       
   172 
       
   173 lemma keys_entries: "(k \<in> set (keys t)) = (\<exists>v. (k, v) \<in> set (entries t))"
       
   174   by transfer (simp add: keys_entries)
       
   175 
       
   176 lemma fold_def_alt:
       
   177   "fold f t = List.fold (prod_case f) (entries t)"
       
   178   by transfer (auto simp: RBT_Impl.fold_def)
       
   179 
       
   180 lemma distinct_entries: "distinct (List.map fst (entries t))"
       
   181   by transfer (simp add: distinct_entries)
       
   182 
       
   183 lemma non_empty_keys: "t \<noteq> Lift_RBT.empty \<Longrightarrow> keys t \<noteq> []"
       
   184   by transfer (simp add: non_empty_rbt_keys)
       
   185 
       
   186 lemma keys_def_alt:
       
   187   "keys t = List.map fst (entries t)"
       
   188   by transfer (simp add: RBT_Impl.keys_def)
   158 
   189 
   159 end
   190 end