author | kuncar |
Fri, 23 Mar 2012 14:18:43 +0100 | |
changeset 47093 | 0516a6c1ea59 |
parent 47092 | fa3538d6004b |
child 47097 | 987cb55cac44 |
permissions | -rw-r--r-- |
45577 | 1 |
(* Author: Lukas Bulwahn, TU Muenchen *) |
2 |
||
3 |
header {* Lifting operations of RBT trees *} |
|
4 |
||
5 |
theory Lift_RBT |
|
6 |
imports Main "~~/src/HOL/Library/RBT_Impl" |
|
7 |
begin |
|
8 |
||
47093 | 9 |
definition inv :: "('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" |
10 |
where [simp]: "inv R = (\<lambda>x y. R x \<and> x = y)" |
|
11 |
||
45577 | 12 |
subsection {* Type definition *} |
13 |
||
47093 | 14 |
quotient_type ('a, 'b) rbt = "('a\<Colon>linorder, 'b) RBT_Impl.rbt" / "inv is_rbt" morphisms impl_of RBT |
15 |
sorry |
|
45577 | 16 |
|
47093 | 17 |
(* |
45577 | 18 |
lemma rbt_eq_iff: |
19 |
"t1 = t2 \<longleftrightarrow> impl_of t1 = impl_of t2" |
|
20 |
by (simp add: impl_of_inject) |
|
21 |
||
22 |
lemma rbt_eqI: |
|
23 |
"impl_of t1 = impl_of t2 \<Longrightarrow> t1 = t2" |
|
24 |
by (simp add: rbt_eq_iff) |
|
25 |
||
26 |
lemma is_rbt_impl_of [simp, intro]: |
|
27 |
"is_rbt (impl_of t)" |
|
28 |
using impl_of [of t] by simp |
|
29 |
||
30 |
lemma RBT_impl_of [simp, code abstype]: |
|
31 |
"RBT (impl_of t) = t" |
|
32 |
by (simp add: impl_of_inverse) |
|
47093 | 33 |
*) |
45577 | 34 |
|
35 |
subsection {* Primitive operations *} |
|
36 |
||
37 |
quotient_definition lookup where "lookup :: ('a\<Colon>linorder, 'b) rbt \<Rightarrow> 'a \<rightharpoonup> 'b" is "RBT_Impl.lookup" |
|
47093 | 38 |
by simp |
45577 | 39 |
|
40 |
declare lookup_def[unfolded map_fun_def comp_def id_def, code] |
|
41 |
||
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
|
42 |
(* FIXME: quotient_definition at the moment requires that types variables match exactly, |
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
|
43 |
i.e., sort constraints must be annotated to the constant being lifted. |
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
|
44 |
But, it should be possible to infer the necessary sort constraints, making the explicit |
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
|
45 |
sort constraints unnecessary. |
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
|
46 |
|
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
|
47 |
Hence this unannotated quotient_definition fails: |
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
|
48 |
|
45577 | 49 |
quotient_definition empty where "empty :: ('a\<Colon>linorder, 'b) rbt" |
50 |
is "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
|
51 |
|
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
|
52 |
Similar issue for quotient_definition for entries, keys, map, and fold. |
45577 | 53 |
*) |
54 |
||
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
|
55 |
quotient_definition empty where "empty :: ('a\<Colon>linorder, 'b) rbt" |
47092 | 56 |
is "(RBT_Impl.Empty :: ('a\<Colon>linorder, 'b) RBT_Impl.rbt)" done |
45577 | 57 |
|
58 |
lemma impl_of_empty [code abstract]: |
|
59 |
"impl_of empty = RBT_Impl.Empty" |
|
60 |
by (simp add: empty_def RBT_inverse) |
|
61 |
||
62 |
quotient_definition insert where "insert :: 'a\<Colon>linorder \<Rightarrow> 'b \<Rightarrow> ('a, 'b) rbt \<Rightarrow> ('a, 'b) rbt" |
|
47092 | 63 |
is "RBT_Impl.insert" done |
45577 | 64 |
|
65 |
lemma impl_of_insert [code abstract]: |
|
66 |
"impl_of (insert k v t) = RBT_Impl.insert k v (impl_of t)" |
|
67 |
by (simp add: insert_def RBT_inverse) |
|
68 |
||
69 |
quotient_definition delete where "delete :: 'a\<Colon>linorder \<Rightarrow> ('a, 'b) rbt \<Rightarrow> ('a, 'b) rbt" |
|
47092 | 70 |
is "RBT_Impl.delete" done |
45577 | 71 |
|
72 |
lemma impl_of_delete [code abstract]: |
|
73 |
"impl_of (delete k t) = RBT_Impl.delete k (impl_of t)" |
|
74 |
by (simp add: delete_def RBT_inverse) |
|
75 |
||
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
|
76 |
(* FIXME: unnecessary type annotations *) |
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
|
77 |
quotient_definition "entries :: ('a\<Colon>linorder, 'b) rbt \<Rightarrow> ('a \<times> 'b) list" |
47092 | 78 |
is "RBT_Impl.entries :: ('a\<Colon>linorder, 'b) RBT_Impl.rbt \<Rightarrow> ('a \<times> 'b) list" done |
45577 | 79 |
|
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
|
80 |
lemma [code]: "entries t = RBT_Impl.entries (impl_of t)" |
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 |
unfolding entries_def map_fun_def comp_def id_def .. |
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 |
|
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 |
(* FIXME: unnecessary type annotations *) |
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 |
quotient_definition "keys :: ('a\<Colon>linorder, 'b) rbt \<Rightarrow> 'a list" |
47092 | 85 |
is "RBT_Impl.keys :: ('a\<Colon>linorder, 'b) RBT_Impl.rbt \<Rightarrow> 'a list" done |
45577 | 86 |
|
87 |
quotient_definition "bulkload :: ('a\<Colon>linorder \<times> 'b) list \<Rightarrow> ('a, 'b) rbt" |
|
47092 | 88 |
is "RBT_Impl.bulkload" done |
45577 | 89 |
|
90 |
lemma impl_of_bulkload [code abstract]: |
|
91 |
"impl_of (bulkload xs) = RBT_Impl.bulkload xs" |
|
92 |
by (simp add: bulkload_def RBT_inverse) |
|
93 |
||
94 |
quotient_definition "map_entry :: 'a \<Rightarrow> ('b \<Rightarrow> 'b) \<Rightarrow> ('a\<Colon>linorder, 'b) rbt \<Rightarrow> ('a, 'b) rbt" |
|
47092 | 95 |
is "RBT_Impl.map_entry" done |
45577 | 96 |
|
97 |
lemma impl_of_map_entry [code abstract]: |
|
98 |
"impl_of (map_entry k f t) = RBT_Impl.map_entry k f (impl_of t)" |
|
99 |
by (simp add: map_entry_def RBT_inverse) |
|
100 |
||
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
|
101 |
(* FIXME: unnecesary type annotations *) |
45577 | 102 |
quotient_definition map where "map :: ('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> ('a\<Colon>linorder, 'b) rbt \<Rightarrow> ('a, 'b) rbt" |
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 |
is "RBT_Impl.map :: ('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> ('a\<Colon>linorder, 'b) RBT_Impl.rbt \<Rightarrow> ('a, 'b) RBT_Impl.rbt" |
47092 | 104 |
done |
45577 | 105 |
|
106 |
lemma impl_of_map [code abstract]: |
|
107 |
"impl_of (map f t) = RBT_Impl.map f (impl_of t)" |
|
108 |
by (simp add: map_def RBT_inverse) |
|
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
|
109 |
|
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
|
110 |
(* FIXME: unnecessary type annotations *) |
47092 | 111 |
quotient_definition fold where "fold :: ('a \<Rightarrow> 'b \<Rightarrow> 'c \<Rightarrow> 'c) \<Rightarrow> ('a\<Colon>linorder, 'b) rbt \<Rightarrow> 'c \<Rightarrow> 'c" |
112 |
is "RBT_Impl.fold :: ('a \<Rightarrow> 'b \<Rightarrow> 'c \<Rightarrow> 'c) \<Rightarrow> ('a\<Colon>linorder, 'b) RBT_Impl.rbt \<Rightarrow> 'c \<Rightarrow> 'c" done |
|
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
|
113 |
|
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
|
114 |
lemma [code]: "fold f t = RBT_Impl.fold f (impl_of t)" |
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 |
unfolding fold_def map_fun_def comp_def id_def .. |
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 |
|
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 |
|
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
|
118 |
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
|
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 |
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
|
121 |
[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
|
122 |
|
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 |
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
|
125 |
|
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
|
126 |
(* TODO: obtain the following lemmas by lifting existing theorems. *) |
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_RBT: |
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 |
"is_rbt t \<Longrightarrow> lookup (RBT t) = RBT_Impl.lookup t" |
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
|
130 |
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
|
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_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
|
133 |
"RBT_Impl.lookup (impl_of t) = lookup t" |
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
|
134 |
by (simp add: lookup_def) |
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 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
|
137 |
"RBT_Impl.entries (impl_of t) = entries t" |
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
|
138 |
by (simp add: entries_def) |
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 |
|
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
|
140 |
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
|
141 |
"RBT_Impl.keys (impl_of t) = keys t" |
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
|
142 |
by (simp add: keys_def) |
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
|
143 |
|
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 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
|
145 |
"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
|
146 |
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
|
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 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
|
149 |
"lookup (insert k v t) = (lookup t)(k \<mapsto> v)" |
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 (simp add: insert_def lookup_RBT lookup_insert lookup_impl_of) |
45577 | 151 |
|
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
|
152 |
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
|
153 |
"lookup (delete k t) = (lookup t)(k := None)" |
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
|
154 |
by (simp add: delete_def lookup_RBT RBT_Impl.lookup_delete lookup_impl_of restrict_complement_singleton_eq) |
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 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
|
157 |
"map_of (entries t) = lookup t" |
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
|
158 |
by (simp add: entries_def map_of_entries lookup_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
|
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 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
|
161 |
"entries t1 = entries t2 \<longleftrightarrow> lookup t1 = lookup t2" |
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
|
162 |
by (simp add: entries_def lookup_def 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
|
163 |
|
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
|
164 |
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
|
165 |
"lookup (bulkload xs) = map_of xs" |
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
|
166 |
by (simp add: bulkload_def lookup_RBT RBT_Impl.lookup_bulkload) |
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
|
167 |
|
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
|
168 |
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
|
169 |
"lookup (map_entry k f t) = (lookup t)(k := Option.map f (lookup t k))" |
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
|
170 |
by (simp add: map_entry_def lookup_RBT RBT_Impl.lookup_map_entry lookup_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
|
171 |
|
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
|
172 |
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
|
173 |
"lookup (map f t) k = Option.map (f k) (lookup t k)" |
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
|
174 |
by (simp add: map_def lookup_RBT RBT_Impl.lookup_map lookup_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
|
175 |
|
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
|
176 |
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
|
177 |
"fold f t = List.fold (prod_case f) (entries 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
|
178 |
by (simp add: fold_def fun_eq_iff RBT_Impl.fold_def 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
|
179 |
|
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
|
180 |
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
|
181 |
"is_empty t \<longleftrightarrow> t = 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
|
182 |
by (simp add: rbt_eq_iff is_empty_def impl_of_empty split: rbt.split) |
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
|
183 |
|
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
|
184 |
lemma RBT_lookup_empty [simp]: (*FIXME*) |
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
|
185 |
"RBT_Impl.lookup t = Map.empty \<longleftrightarrow> t = RBT_Impl.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
|
186 |
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
|
187 |
|
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
|
188 |
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
|
189 |
"lookup t = Map.empty \<longleftrightarrow> t = 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
|
190 |
by (cases t) (simp add: empty_def lookup_def RBT_inject 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
|
191 |
|
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
|
192 |
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
|
193 |
"sorted (keys t)" |
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
|
194 |
by (simp add: keys_def RBT_Impl.keys_def sorted_entries) |
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
|
195 |
|
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
|
196 |
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
|
197 |
"distinct (keys t)" |
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
|
198 |
by (simp add: keys_def RBT_Impl.keys_def distinct_entries) |
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
|
199 |
|
45577 | 200 |
|
201 |
||
202 |
end |