author | wenzelm |
Tue, 06 Aug 2002 11:22:05 +0200 | |
changeset 13462 | 56610e2ba220 |
parent 11015 | 55d95834c815 |
child 13811 | f39f67982854 |
permissions | -rw-r--r-- |
3981 | 1 |
(* Title: HOL/Map.ML |
2 |
ID: $Id$ |
|
3 |
Author: Tobias Nipkow |
|
4 |
Copyright 1997 TU Muenchen |
|
5 |
||
10973 | 6 |
Map lemmas. |
3981 | 7 |
*) |
8 |
||
5300 | 9 |
section "empty"; |
10 |
||
5069 | 11 |
Goalw [empty_def] "empty k = None"; |
4423 | 12 |
by (Simp_tac 1); |
3981 | 13 |
qed "empty_def2"; |
14 |
Addsimps [empty_def2]; |
|
15 |
||
10973 | 16 |
Goal "empty(x := None) = empty"; |
17 |
by (rtac ext 1); |
|
18 |
by (Simp_tac 1); |
|
19 |
qed "empty_upd_none"; |
|
20 |
Addsimps [empty_upd_none]; |
|
21 |
||
9342 | 22 |
Goal "sum_case empty empty = empty"; |
23 |
by (rtac ext 1); |
|
24 |
by (simp_tac (simpset() addsplits [sum.split]) 1); |
|
25 |
qed "sum_case_empty_empty"; |
|
26 |
Addsimps [sum_case_empty_empty]; |
|
27 |
||
5300 | 28 |
|
29 |
section "map_upd"; |
|
30 |
||
8529 | 31 |
Goal "t k = Some x ==> t(k|->x) = t"; |
32 |
by (rtac ext 1); |
|
33 |
by (Asm_simp_tac 1); |
|
34 |
qed "map_upd_triv"; |
|
5300 | 35 |
|
9400 | 36 |
Goal "t(k|->x) ~= empty"; |
37 |
by Safe_tac; |
|
38 |
by (dres_inst_tac [("x","k")] fun_cong 1); |
|
39 |
by (Full_simp_tac 1); |
|
40 |
qed "map_upd_nonempty"; |
|
41 |
Addsimps[map_upd_nonempty]; |
|
42 |
||
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
43 |
Goalw [image_def] "finite (range f) ==> finite (range (f(a|->b)))"; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
44 |
by (full_simp_tac (simpset() addsimps [full_SetCompr_eq]) 1); |
8254 | 45 |
by (rtac finite_subset 1); |
46 |
by (assume_tac 2); |
|
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
47 |
by Auto_tac; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
48 |
qed "finite_range_updI"; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
49 |
|
5300 | 50 |
|
11015
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
51 |
section "sum_case and empty/map_upd"; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
52 |
|
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
53 |
Goal "sum_case (m(k|->y)) empty = (sum_case m empty)(Inl k|->y)"; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
54 |
by (rtac ext 1); |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
55 |
by (simp_tac (simpset() addsplits [sum.split]) 1); |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
56 |
qed "sum_case_map_upd_empty"; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
57 |
Addsimps[sum_case_map_upd_empty]; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
58 |
|
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
59 |
Goal "sum_case empty (m(k|->y)) = (sum_case empty m)(Inr k|->y)"; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
60 |
by (rtac ext 1); |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
61 |
by (simp_tac (simpset() addsplits [sum.split]) 1); |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
62 |
qed "sum_case_empty_map_upd"; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
63 |
Addsimps[sum_case_empty_map_upd]; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
64 |
|
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
65 |
Goal "sum_case (m1(k1|->y1)) (m2(k2|->y2)) = (sum_case (m1(k1|->y1)) m2)(Inr k2|->y2)"; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
66 |
by (rtac ext 1); |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
67 |
by (simp_tac (simpset() addsplits [sum.split]) 1); |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
68 |
qed "sum_case_map_upd_map_upd"; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
69 |
Addsimps[sum_case_map_upd_map_upd]; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
70 |
|
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
71 |
|
5300 | 72 |
section "map_upds"; |
3981 | 73 |
|
5300 | 74 |
Goal "a ~: set as --> (!m bs. (m(a|->b)(as[|->]bs)) = (m(as[|->]bs)(a|->b)))"; |
75 |
by (induct_tac "as" 1); |
|
76 |
by (auto_tac (claset(), simpset() delsimps[fun_upd_apply])); |
|
77 |
by (REPEAT(dtac spec 1)); |
|
78 |
by (rotate_tac ~1 1); |
|
79 |
by (etac subst 1); |
|
80 |
by (etac (fun_upd_twist RS subst) 1); |
|
81 |
by (rtac refl 1); |
|
82 |
qed_spec_mp "map_upds_twist"; |
|
83 |
Addsimps [map_upds_twist]; |
|
84 |
||
85 |
||
86 |
section "chg_map"; |
|
87 |
||
8529 | 88 |
Goalw [chg_map_def] "m a = None ==> chg_map f a m = m"; |
89 |
by Auto_tac; |
|
90 |
qed "chg_map_new"; |
|
91 |
||
92 |
Goalw [chg_map_def] "m a = Some b ==> chg_map f a m = m(a|->f b)"; |
|
93 |
by Auto_tac; |
|
94 |
qed "chg_map_upd"; |
|
95 |
||
5300 | 96 |
Addsimps[chg_map_new, chg_map_upd]; |
97 |
||
4526
6be35399125a
added update_same, update_other, update_triv, and map_of_SomeD
oheimb
parents:
4423
diff
changeset
|
98 |
|
7958 | 99 |
section "map_of"; |
100 |
||
101 |
Goal "map_of xs k = Some y --> (k,y):set xs"; |
|
102 |
by (induct_tac "xs" 1); |
|
9018 | 103 |
by Auto_tac; |
7958 | 104 |
qed_spec_mp "map_of_SomeD"; |
105 |
||
9018 | 106 |
Goal "inj f ==> map_of t k = Some x --> \ |
107 |
\ map_of (map (split (%k. Pair (f k))) t) (f k) = Some x"; |
|
108 |
by (induct_tac "t" 1); |
|
109 |
by (auto_tac (claset(),simpset()addsimps[inj_eq])); |
|
110 |
qed_spec_mp "map_of_mapk_SomeI"; |
|
111 |
||
112 |
Goal "(k, x) : set l --> (? x. map_of l k = Some x)"; |
|
113 |
by (induct_tac "l" 1); |
|
114 |
by Auto_tac; |
|
115 |
qed_spec_mp "weak_map_of_SomeI"; |
|
116 |
||
11015
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
117 |
Goal |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
118 |
"[| map_of xs k = Some z; P k z |] ==> map_of (filter (split P) xs) k = Some z"; |
7961 | 119 |
by (rtac mp 1); |
11015
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
120 |
by (atac 2); |
7958 | 121 |
by (etac thin_rl 1); |
122 |
by (induct_tac "xs" 1); |
|
123 |
by Auto_tac; |
|
124 |
qed "map_of_filter_in"; |
|
125 |
||
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
126 |
Goal "finite (range (map_of l))"; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
127 |
by (induct_tac "l" 1); |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
128 |
by (ALLGOALS (simp_tac (simpset() addsimps [image_constant]))); |
8254 | 129 |
by (rtac finite_subset 1); |
130 |
by (assume_tac 2); |
|
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
131 |
by Auto_tac; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
132 |
qed "finite_range_map_of"; |
7958 | 133 |
|
11015
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
134 |
Goal "map_of (map (%(a,b). (a,f b)) xs) x = option_map f (map_of xs x)"; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
135 |
by (induct_tac "xs" 1); |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
136 |
by Auto_tac; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
137 |
qed "map_of_map"; |
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
138 |
|
9018 | 139 |
|
7958 | 140 |
section "option_map related"; |
4990 | 141 |
|
8529 | 142 |
Goal "option_map f o empty = empty"; |
143 |
by (rtac ext 1); |
|
144 |
by (Simp_tac 1); |
|
145 |
qed "option_map_o_empty"; |
|
4990 | 146 |
|
8529 | 147 |
Goal "option_map f o m(a|->b) = (option_map f o m)(a|->f b)"; |
148 |
by (rtac ext 1); |
|
149 |
by (Simp_tac 1); |
|
150 |
qed "option_map_o_map_upd"; |
|
151 |
||
5195 | 152 |
Addsimps[option_map_o_empty, option_map_o_map_upd]; |
4883 | 153 |
|
11015
55d95834c815
added sum_case_map_upd_empty, sum_case_empty_map_upd, and
oheimb
parents:
10973
diff
changeset
|
154 |
|
3981 | 155 |
section "++"; |
156 |
||
5069 | 157 |
Goalw [override_def] "m ++ empty = m"; |
4423 | 158 |
by (Simp_tac 1); |
3981 | 159 |
qed "override_empty"; |
160 |
Addsimps [override_empty]; |
|
161 |
||
5069 | 162 |
Goalw [override_def] "empty ++ m = m"; |
4423 | 163 |
by (Simp_tac 1); |
164 |
by (rtac ext 1); |
|
5183 | 165 |
by (split_tac [option.split] 1); |
4423 | 166 |
by (Simp_tac 1); |
3981 | 167 |
qed "empty_override"; |
168 |
Addsimps [empty_override]; |
|
169 |
||
5069 | 170 |
Goalw [override_def] |
3981 | 171 |
"((m ++ n) k = Some x) = (n k = Some x | n k = None & m k = Some x)"; |
5183 | 172 |
by (simp_tac (simpset() addsplits [option.split]) 1); |
3981 | 173 |
qed_spec_mp "override_Some_iff"; |
174 |
||
4926 | 175 |
bind_thm ("override_SomeD", standard(override_Some_iff RS iffD1)); |
5444 | 176 |
AddSDs[override_SomeD]; |
3981 | 177 |
|
7958 | 178 |
Goal "!!xx. n k = Some xx ==> (m ++ n) k = Some xx"; |
179 |
by (stac override_Some_iff 1); |
|
180 |
by (Fast_tac 1); |
|
181 |
qed "override_find_right"; |
|
182 |
Addsimps[override_find_right]; |
|
183 |
||
5444 | 184 |
Goalw [override_def] "((m ++ n) k = None) = (n k = None & m k = None)"; |
5183 | 185 |
by (simp_tac (simpset() addsplits [option.split]) 1); |
3981 | 186 |
qed "override_None"; |
187 |
AddIffs [override_None]; |
|
188 |
||
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
189 |
Goalw [override_def] "f ++ g(x|->y) = (f ++ g)(x|->y)"; |
8254 | 190 |
by (rtac ext 1); |
9357 | 191 |
by Auto_tac; |
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
192 |
qed "override_upd"; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
193 |
Addsimps[override_upd]; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
194 |
|
5444 | 195 |
Goalw [override_def] "map_of ys ++ map_of xs = map_of (xs@ys)"; |
196 |
by (rtac sym 1); |
|
4423 | 197 |
by (induct_tac "xs" 1); |
198 |
by (Simp_tac 1); |
|
199 |
by (rtac ext 1); |
|
5183 | 200 |
by (asm_simp_tac (simpset() addsplits [option.split]) 1); |
5444 | 201 |
qed "map_of_override"; |
202 |
Addsimps [map_of_override]; |
|
3981 | 203 |
|
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
204 |
Delsimps[fun_upd_apply]; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
205 |
Goal "finite (range f) ==> finite (range (f ++ map_of l))"; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
206 |
by (induct_tac "l" 1); |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
207 |
by Auto_tac; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
208 |
by (fold_goals_tac [empty_def]); |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
209 |
by (Asm_simp_tac 1); |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
210 |
by (etac finite_range_updI 1); |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
211 |
qed "finite_range_map_of_override"; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
212 |
Addsimps [fun_upd_apply]; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
213 |
|
5300 | 214 |
|
3981 | 215 |
section "dom"; |
216 |
||
8259 | 217 |
Goalw [dom_def] "m a = Some b ==> a : dom m"; |
218 |
by Auto_tac; |
|
219 |
qed "domI"; |
|
220 |
||
221 |
Goalw [dom_def] "a : dom m ==> ? b. m a = Some b"; |
|
222 |
by Auto_tac; |
|
223 |
qed "domD"; |
|
224 |
AddSDs [domD]; |
|
225 |
||
5069 | 226 |
Goalw [dom_def] "dom empty = {}"; |
4423 | 227 |
by (Simp_tac 1); |
3981 | 228 |
qed "dom_empty"; |
229 |
Addsimps [dom_empty]; |
|
230 |
||
5300 | 231 |
Goalw [dom_def] "dom(m(a|->b)) = insert a (dom m)"; |
4686 | 232 |
by (Simp_tac 1); |
4423 | 233 |
by (Blast_tac 1); |
5195 | 234 |
qed "dom_map_upd"; |
235 |
Addsimps [dom_map_upd]; |
|
3981 | 236 |
|
8529 | 237 |
Goalw [dom_def] "finite (dom (map_of l))"; |
238 |
by (induct_tac "l" 1); |
|
10973 | 239 |
by (auto_tac (claset(), |
240 |
simpset() addsimps [insert_Collect RS sym])); |
|
8529 | 241 |
qed "finite_dom_map_of"; |
4883 | 242 |
|
5069 | 243 |
Goalw [dom_def] "dom(m++n) = dom n Un dom m"; |
8529 | 244 |
by Auto_tac; |
3981 | 245 |
qed "dom_override"; |
246 |
Addsimps [dom_override]; |
|
247 |
||
248 |
section "ran"; |
|
249 |
||
5069 | 250 |
Goalw [ran_def] "ran empty = {}"; |
4423 | 251 |
by (Simp_tac 1); |
3981 | 252 |
qed "ran_empty"; |
253 |
Addsimps [ran_empty]; |
|
4883 | 254 |
|
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
255 |
Goalw [ran_def] "ran (%u. None) = {}"; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
256 |
by Auto_tac; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
257 |
qed "ran_empty'"; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
258 |
Addsimps[ran_empty']; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
259 |
|
5300 | 260 |
Goalw [ran_def] "m a = None ==> ran(m(a|->b)) = insert b (ran m)"; |
4883 | 261 |
by Auto_tac; |
262 |
by (subgoal_tac "~(aa = a)" 1); |
|
263 |
by Auto_tac; |
|
5195 | 264 |
qed "ran_map_upd"; |
265 |
Addsimps [ran_map_upd]; |