author | kuncar |
Tue, 31 Jul 2012 13:55:39 +0200 | |
changeset 48621 | 877df57629e3 |
parent 47888 | 45bf22d8a81d |
child 48622 | caaa1a02c650 |
permissions | -rw-r--r-- |
47308 | 1 |
(* Title: HOL/Quotient_Examples/Lift_RBT.thy |
2 |
Author: Lukas Bulwahn and Ondrej Kuncar |
|
3 |
*) |
|
45577 | 4 |
|
5 |
header {* Lifting operations of RBT trees *} |
|
6 |
||
7 |
theory Lift_RBT |
|
8 |
imports Main "~~/src/HOL/Library/RBT_Impl" |
|
9 |
begin |
|
10 |
||
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
11 |
(* TODO: Replace the ancient Library/RBT theory by this example of the lifting and transfer mechanism. *) |
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
12 |
|
45577 | 13 |
subsection {* Type definition *} |
14 |
||
47097 | 15 |
typedef (open) ('a, 'b) rbt = "{t :: ('a\<Colon>linorder, 'b) RBT_Impl.rbt. is_rbt t}" |
16 |
morphisms impl_of RBT |
|
17 |
proof - |
|
18 |
have "RBT_Impl.Empty \<in> ?rbt" by simp |
|
19 |
then show ?thesis .. |
|
20 |
qed |
|
45577 | 21 |
|
22 |
lemma rbt_eq_iff: |
|
23 |
"t1 = t2 \<longleftrightarrow> impl_of t1 = impl_of t2" |
|
24 |
by (simp add: impl_of_inject) |
|
25 |
||
26 |
lemma rbt_eqI: |
|
27 |
"impl_of t1 = impl_of t2 \<Longrightarrow> t1 = t2" |
|
28 |
by (simp add: rbt_eq_iff) |
|
29 |
||
30 |
lemma is_rbt_impl_of [simp, intro]: |
|
31 |
"is_rbt (impl_of t)" |
|
32 |
using impl_of [of t] by simp |
|
33 |
||
34 |
lemma RBT_impl_of [simp, code abstype]: |
|
35 |
"RBT (impl_of t) = t" |
|
36 |
by (simp add: impl_of_inverse) |
|
37 |
||
38 |
subsection {* Primitive operations *} |
|
39 |
||
47097 | 40 |
setup_lifting type_definition_rbt |
41 |
||
47451 | 42 |
lift_definition lookup :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> 'a \<rightharpoonup> 'b" is "rbt_lookup" |
47308 | 43 |
by simp |
44 |
||
45 |
lift_definition empty :: "('a\<Colon>linorder, 'b) rbt" is RBT_Impl.Empty |
|
46 |
by (simp add: empty_def) |
|
47 |
||
47451 | 48 |
lift_definition insert :: "'a\<Colon>linorder \<Rightarrow> 'b \<Rightarrow> ('a, 'b) rbt \<Rightarrow> ('a, 'b) rbt" is "rbt_insert" |
47308 | 49 |
by simp |
50 |
||
47451 | 51 |
lift_definition delete :: "'a\<Colon>linorder \<Rightarrow> ('a, 'b) rbt \<Rightarrow> ('a, 'b) rbt" is "rbt_delete" |
47308 | 52 |
by simp |
53 |
||
54 |
lift_definition entries :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> ('a \<times> 'b) list" is RBT_Impl.entries |
|
47093 | 55 |
by simp |
45577 | 56 |
|
47308 | 57 |
lift_definition keys :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> 'a list" is RBT_Impl.keys |
58 |
by simp |
|
45577 | 59 |
|
47451 | 60 |
lift_definition bulkload :: "('a\<Colon>linorder \<times> 'b) list \<Rightarrow> ('a, 'b) rbt" is "rbt_bulkload" |
47097 | 61 |
by simp |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
62 |
|
47451 | 63 |
lift_definition map_entry :: "'a \<Rightarrow> ('b \<Rightarrow> 'b) \<Rightarrow> ('a\<Colon>linorder, 'b) rbt \<Rightarrow> ('a, 'b) rbt" is rbt_map_entry |
47308 | 64 |
by simp |
65 |
||
66 |
lift_definition map :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> ('a\<Colon>linorder, 'b) rbt \<Rightarrow> ('a, 'b) rbt" is RBT_Impl.map |
|
67 |
by simp |
|
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 |
|
70 |
by simp |
|
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
71 |
|
48621
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
72 |
lift_definition union :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> ('a, 'b) rbt \<Rightarrow> ('a, 'b) rbt" is "rbt_union" |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
73 |
by (simp add: rbt_union_is_rbt) |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
74 |
|
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
75 |
lift_definition foldi :: "('c \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> 'c \<Rightarrow> 'c) \<Rightarrow> ('a :: linorder, 'b) rbt \<Rightarrow> 'c \<Rightarrow> 'c" |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
76 |
is RBT_Impl.foldi by simp |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
77 |
|
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
78 |
export_code lookup empty insert delete entries keys bulkload map_entry map fold union foldi in SML |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
79 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
80 |
subsection {* Derived operations *} |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
81 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
82 |
definition is_empty :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> bool" where |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
83 |
[code]: "is_empty t = (case impl_of t of RBT_Impl.Empty \<Rightarrow> True | _ \<Rightarrow> False)" |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
84 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
85 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
86 |
subsection {* Abstract lookup properties *} |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
87 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
88 |
lemma lookup_RBT: |
47451 | 89 |
"is_rbt t \<Longrightarrow> lookup (RBT t) = rbt_lookup t" |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
90 |
by (simp add: lookup_def RBT_inverse) |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
91 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
92 |
lemma lookup_impl_of: |
47451 | 93 |
"rbt_lookup (impl_of t) = lookup t" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
94 |
by transfer (rule refl) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
95 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
96 |
lemma entries_impl_of: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
97 |
"RBT_Impl.entries (impl_of t) = entries t" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
98 |
by transfer (rule refl) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
99 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
100 |
lemma keys_impl_of: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
101 |
"RBT_Impl.keys (impl_of t) = keys t" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
102 |
by transfer (rule refl) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
103 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
104 |
lemma lookup_empty [simp]: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
105 |
"lookup empty = Map.empty" |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
106 |
by (simp add: empty_def lookup_RBT fun_eq_iff) |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
107 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
108 |
lemma lookup_insert [simp]: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
109 |
"lookup (insert k v t) = (lookup t)(k \<mapsto> v)" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
110 |
by transfer (rule rbt_lookup_rbt_insert) |
45577 | 111 |
|
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
112 |
lemma lookup_delete [simp]: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
113 |
"lookup (delete k t) = (lookup t)(k := None)" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
114 |
by transfer (simp add: rbt_lookup_rbt_delete restrict_complement_singleton_eq) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
115 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
116 |
lemma map_of_entries [simp]: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
117 |
"map_of (entries t) = lookup t" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
118 |
by transfer (simp add: map_of_entries) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
119 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
120 |
lemma entries_lookup: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
121 |
"entries t1 = entries t2 \<longleftrightarrow> lookup t1 = lookup t2" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
122 |
by transfer (simp add: entries_rbt_lookup) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
123 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
124 |
lemma lookup_bulkload [simp]: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
125 |
"lookup (bulkload xs) = map_of xs" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
126 |
by transfer (rule rbt_lookup_rbt_bulkload) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
127 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
128 |
lemma lookup_map_entry [simp]: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
129 |
"lookup (map_entry k f t) = (lookup t)(k := Option.map f (lookup t k))" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
130 |
by transfer (rule rbt_lookup_rbt_map_entry) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
131 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
132 |
lemma lookup_map [simp]: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
133 |
"lookup (map f t) k = Option.map (f k) (lookup t k)" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
134 |
by transfer (rule rbt_lookup_map) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
135 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
136 |
lemma fold_fold: |
46133
d9fe85d3d2cd
incorporated canonical fold combinator on lists into body of List theory; refactored passages on List.fold(l/r)
haftmann
parents:
45629
diff
changeset
|
137 |
"fold f t = List.fold (prod_case f) (entries t)" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
138 |
by transfer (rule RBT_Impl.fold_def) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
139 |
|
47097 | 140 |
lemma impl_of_empty: |
141 |
"impl_of empty = RBT_Impl.Empty" |
|
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
142 |
by transfer (rule refl) |
47097 | 143 |
|
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
144 |
lemma is_empty_empty [simp]: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
145 |
"is_empty t \<longleftrightarrow> t = empty" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
146 |
unfolding is_empty_def by transfer (simp split: rbt.split) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
147 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
148 |
lemma RBT_lookup_empty [simp]: (*FIXME*) |
47451 | 149 |
"rbt_lookup t = Map.empty \<longleftrightarrow> t = RBT_Impl.Empty" |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
150 |
by (cases t) (auto simp add: fun_eq_iff) |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
151 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
152 |
lemma lookup_empty_empty [simp]: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
153 |
"lookup t = Map.empty \<longleftrightarrow> t = empty" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
154 |
by transfer (rule RBT_lookup_empty) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
155 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
156 |
lemma sorted_keys [iff]: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
157 |
"sorted (keys t)" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
158 |
by transfer (simp add: RBT_Impl.keys_def rbt_sorted_entries) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
159 |
|
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
160 |
lemma distinct_keys [iff]: |
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
161 |
"distinct (keys t)" |
47888
45bf22d8a81d
using the new transfer method to obtain abstract properties of RBT trees
bulwahn
parents:
47451
diff
changeset
|
162 |
by transfer (simp add: RBT_Impl.keys_def distinct_entries) |
45629
ef08425dd2d5
improved example to only use quotient_definitions; added lemmas to serve as possible replacement for the existing RBT theory
bulwahn
parents:
45577
diff
changeset
|
163 |
|
48621
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
164 |
lemma finite_dom_lookup [simp, intro!]: "finite (dom (lookup t))" |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
165 |
by transfer simp |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
166 |
|
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
167 |
lemma lookup_union: "lookup (union s t) = lookup s ++ lookup t" |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
168 |
by transfer (simp add: rbt_lookup_rbt_union) |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
169 |
|
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
170 |
lemma lookup_in_tree: "(lookup t k = Some v) = ((k, v) \<in> set (entries t))" |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
171 |
by transfer (simp add: rbt_lookup_in_tree) |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
172 |
|
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
173 |
lemma keys_entries: "(k \<in> set (keys t)) = (\<exists>v. (k, v) \<in> set (entries t))" |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
174 |
by transfer (simp add: keys_entries) |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
175 |
|
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
176 |
lemma fold_def_alt: |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
177 |
"fold f t = List.fold (prod_case f) (entries t)" |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
178 |
by transfer (auto simp: RBT_Impl.fold_def) |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
179 |
|
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
180 |
lemma distinct_entries: "distinct (List.map fst (entries t))" |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
181 |
by transfer (simp add: distinct_entries) |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
182 |
|
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
183 |
lemma non_empty_keys: "t \<noteq> Lift_RBT.empty \<Longrightarrow> keys t \<noteq> []" |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
184 |
by transfer (simp add: non_empty_rbt_keys) |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
185 |
|
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
186 |
lemma keys_def_alt: |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
187 |
"keys t = List.map fst (entries t)" |
877df57629e3
a couple of additions to RBT formalization to allow us to implement RBT_Set
kuncar
parents:
47888
diff
changeset
|
188 |
by transfer (simp add: RBT_Impl.keys_def) |
45577 | 189 |
|
190 |
end |