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