author | oheimb |
Fri, 18 Feb 2000 20:24:40 +0100 | |
changeset 8259 | a8d2606f4921 |
parent 8254 | 84a5fe44520f |
child 8529 | 4656e8312ba9 |
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 |
||
5300 | 16 |
|
17 |
section "map_upd"; |
|
18 |
||
19 |
qed_goal "map_upd_triv" thy "!!X. t k = Some x ==> t(k|->x) = t" |
|
20 |
(K [rtac ext 1, Asm_simp_tac 1]); |
|
21 |
(*Addsimps [map_upd_triv];*) |
|
22 |
||
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
23 |
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
|
24 |
by (full_simp_tac (simpset() addsimps [full_SetCompr_eq]) 1); |
8254 | 25 |
by (rtac finite_subset 1); |
26 |
by (assume_tac 2); |
|
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
27 |
by Auto_tac; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
28 |
qed "finite_range_updI"; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
29 |
|
5300 | 30 |
|
31 |
section "map_upds"; |
|
3981 | 32 |
|
5300 | 33 |
Goal "a ~: set as --> (!m bs. (m(a|->b)(as[|->]bs)) = (m(as[|->]bs)(a|->b)))"; |
34 |
by (induct_tac "as" 1); |
|
35 |
by (auto_tac (claset(), simpset() delsimps[fun_upd_apply])); |
|
36 |
by (REPEAT(dtac spec 1)); |
|
37 |
by (rotate_tac ~1 1); |
|
38 |
by (etac subst 1); |
|
39 |
by (etac (fun_upd_twist RS subst) 1); |
|
40 |
by (rtac refl 1); |
|
41 |
qed_spec_mp "map_upds_twist"; |
|
42 |
Addsimps [map_upds_twist]; |
|
43 |
||
44 |
||
45 |
section "chg_map"; |
|
46 |
||
47 |
qed_goalw "chg_map_new" thy [chg_map_def] |
|
48 |
"!!s. m a = None ==> chg_map f a m = m" (K [Auto_tac]); |
|
49 |
qed_goalw "chg_map_upd" thy [chg_map_def] |
|
50 |
"!!s. m a = Some b ==> chg_map f a m = m(a|->f b)" (K [Auto_tac]); |
|
51 |
Addsimps[chg_map_new, chg_map_upd]; |
|
52 |
||
4526
6be35399125a
added update_same, update_other, update_triv, and map_of_SomeD
oheimb
parents:
4423
diff
changeset
|
53 |
|
7958 | 54 |
section "map_of"; |
55 |
||
56 |
Goal "map_of xs k = Some y --> (k,y):set xs"; |
|
57 |
by (induct_tac "xs" 1); |
|
58 |
by (Simp_tac 1); |
|
59 |
by (split_all_tac 1); |
|
60 |
by (Asm_simp_tac 1); |
|
61 |
qed_spec_mp "map_of_SomeD"; |
|
62 |
||
63 |
Goal "[| map_of xs k = Some z; P z |] ==> map_of [(k,z):xs . P z] k = Some z"; |
|
7961 | 64 |
by (rtac mp 1); |
65 |
by (assume_tac 2); |
|
7958 | 66 |
by (etac thin_rl 1); |
67 |
by (induct_tac "xs" 1); |
|
68 |
by Auto_tac; |
|
69 |
qed "map_of_filter_in"; |
|
70 |
||
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
71 |
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
|
72 |
by (induct_tac "l" 1); |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
73 |
by (ALLGOALS (simp_tac (simpset() addsimps [image_constant]))); |
8254 | 74 |
by (rtac finite_subset 1); |
75 |
by (assume_tac 2); |
|
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
76 |
by Auto_tac; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
77 |
qed "finite_range_map_of"; |
7958 | 78 |
|
79 |
section "option_map related"; |
|
4990 | 80 |
|
81 |
qed_goal "option_map_o_empty" thy |
|
82 |
"option_map f o empty = empty" (K [rtac ext 1, Simp_tac 1]); |
|
83 |
||
5195 | 84 |
qed_goal "option_map_o_map_upd" thy |
5300 | 85 |
"option_map f o m(a|->b) = (option_map f o m)(a|->f b)" |
4990 | 86 |
(K [rtac ext 1, Simp_tac 1]); |
5195 | 87 |
Addsimps[option_map_o_empty, option_map_o_map_upd]; |
4883 | 88 |
|
3981 | 89 |
section "++"; |
90 |
||
5069 | 91 |
Goalw [override_def] "m ++ empty = m"; |
4423 | 92 |
by (Simp_tac 1); |
3981 | 93 |
qed "override_empty"; |
94 |
Addsimps [override_empty]; |
|
95 |
||
5069 | 96 |
Goalw [override_def] "empty ++ m = m"; |
4423 | 97 |
by (Simp_tac 1); |
98 |
by (rtac ext 1); |
|
5183 | 99 |
by (split_tac [option.split] 1); |
4423 | 100 |
by (Simp_tac 1); |
3981 | 101 |
qed "empty_override"; |
102 |
Addsimps [empty_override]; |
|
103 |
||
5069 | 104 |
Goalw [override_def] |
3981 | 105 |
"((m ++ n) k = Some x) = (n k = Some x | n k = None & m k = Some x)"; |
5183 | 106 |
by (simp_tac (simpset() addsplits [option.split]) 1); |
3981 | 107 |
qed_spec_mp "override_Some_iff"; |
108 |
||
4926 | 109 |
bind_thm ("override_SomeD", standard(override_Some_iff RS iffD1)); |
5444 | 110 |
AddSDs[override_SomeD]; |
3981 | 111 |
|
7958 | 112 |
Goal "!!xx. n k = Some xx ==> (m ++ n) k = Some xx"; |
113 |
by (stac override_Some_iff 1); |
|
114 |
by (Fast_tac 1); |
|
115 |
qed "override_find_right"; |
|
116 |
Addsimps[override_find_right]; |
|
117 |
||
5444 | 118 |
Goalw [override_def] "((m ++ n) k = None) = (n k = None & m k = None)"; |
5183 | 119 |
by (simp_tac (simpset() addsplits [option.split]) 1); |
3981 | 120 |
qed "override_None"; |
121 |
AddIffs [override_None]; |
|
122 |
||
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
123 |
Goalw [override_def] "f ++ g(x|->y) = (f ++ g)(x|->y)"; |
8254 | 124 |
by (rtac ext 1); |
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
125 |
by (auto_tac (claset_of Map.thy, simpset_of Map.thy)); |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
126 |
qed "override_upd"; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
127 |
Addsimps[override_upd]; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
128 |
|
5444 | 129 |
Goalw [override_def] "map_of ys ++ map_of xs = map_of (xs@ys)"; |
130 |
by (rtac sym 1); |
|
4423 | 131 |
by (induct_tac "xs" 1); |
132 |
by (Simp_tac 1); |
|
133 |
by (rtac ext 1); |
|
5183 | 134 |
by (asm_simp_tac (simpset() addsplits [option.split]) 1); |
5444 | 135 |
qed "map_of_override"; |
136 |
Addsimps [map_of_override]; |
|
3981 | 137 |
|
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
138 |
Delsimps[fun_upd_apply]; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
139 |
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
|
140 |
by (induct_tac "l" 1); |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
141 |
by Auto_tac; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
142 |
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
|
143 |
by (Asm_simp_tac 1); |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
144 |
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
|
145 |
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
|
146 |
Addsimps [fun_upd_apply]; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
147 |
|
5300 | 148 |
|
3981 | 149 |
section "dom"; |
150 |
||
8259 | 151 |
Goalw [dom_def] "m a = Some b ==> a : dom m"; |
152 |
by Auto_tac; |
|
153 |
qed "domI"; |
|
154 |
||
155 |
Goalw [dom_def] "a : dom m ==> ? b. m a = Some b"; |
|
156 |
by Auto_tac; |
|
157 |
qed "domD"; |
|
158 |
AddSDs [domD]; |
|
159 |
||
5069 | 160 |
Goalw [dom_def] "dom empty = {}"; |
4423 | 161 |
by (Simp_tac 1); |
3981 | 162 |
qed "dom_empty"; |
163 |
Addsimps [dom_empty]; |
|
164 |
||
5300 | 165 |
Goalw [dom_def] "dom(m(a|->b)) = insert a (dom m)"; |
4686 | 166 |
by (Simp_tac 1); |
4423 | 167 |
by (Blast_tac 1); |
5195 | 168 |
qed "dom_map_upd"; |
169 |
Addsimps [dom_map_upd]; |
|
3981 | 170 |
|
4883 | 171 |
qed_goalw "finite_dom_map_of" Map.thy [dom_def] "finite (dom (map_of l))" (K[ |
5183 | 172 |
induct_tac "l" 1, |
4883 | 173 |
ALLGOALS Simp_tac, |
174 |
stac (insert_Collect RS sym) 1, |
|
5444 | 175 |
Asm_full_simp_tac 1]); |
4883 | 176 |
|
5069 | 177 |
Goalw [dom_def] "dom(m++n) = dom n Un dom m"; |
6301 | 178 |
by (Simp_tac 1); |
4423 | 179 |
by (Blast_tac 1); |
3981 | 180 |
qed "dom_override"; |
181 |
Addsimps [dom_override]; |
|
182 |
||
183 |
section "ran"; |
|
184 |
||
5069 | 185 |
Goalw [ran_def] "ran empty = {}"; |
4423 | 186 |
by (Simp_tac 1); |
3981 | 187 |
qed "ran_empty"; |
188 |
Addsimps [ran_empty]; |
|
4883 | 189 |
|
8160
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
190 |
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
|
191 |
by Auto_tac; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
192 |
qed "ran_empty'"; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
193 |
Addsimps[ran_empty']; |
837a6b515005
added finite_range_updI, finite_range_map_of, finite_range_map_of_override
oheimb
parents:
7961
diff
changeset
|
194 |
|
5300 | 195 |
Goalw [ran_def] "m a = None ==> ran(m(a|->b)) = insert b (ran m)"; |
4883 | 196 |
by Auto_tac; |
197 |
by (subgoal_tac "~(aa = a)" 1); |
|
198 |
by Auto_tac; |
|
5195 | 199 |
qed "ran_map_upd"; |
200 |
Addsimps [ran_map_upd]; |