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