author | wenzelm |
Sat, 02 Sep 2000 21:56:24 +0200 | |
changeset 9811 | 39ffdb8cab03 |
parent 9422 | 4b6bc2b347e5 |
child 9838 | dc84dda48a5a |
permissions | -rw-r--r-- |
1465 | 1 |
(* Title: HOL/Fun |
923 | 2 |
ID: $Id$ |
1465 | 3 |
Author: Tobias Nipkow, Cambridge University Computer Laboratory |
923 | 4 |
Copyright 1993 University of Cambridge |
5 |
||
6 |
Lemmas about functions. |
|
7 |
*) |
|
8 |
||
7089 | 9 |
Goal "(f = g) = (! x. f(x)=g(x))"; |
923 | 10 |
by (rtac iffI 1); |
1264 | 11 |
by (Asm_simp_tac 1); |
12 |
by (rtac ext 1 THEN Asm_simp_tac 1); |
|
923 | 13 |
qed "expand_fun_eq"; |
14 |
||
5316 | 15 |
val prems = Goal |
923 | 16 |
"[| f(x)=u; !!x. P(x) ==> g(f(x)) = x; P(x) |] ==> x=g(u)"; |
17 |
by (rtac (arg_cong RS box_equals) 1); |
|
18 |
by (REPEAT (resolve_tac (prems@[refl]) 1)); |
|
19 |
qed "apply_inverse"; |
|
20 |
||
21 |
||
4656 | 22 |
(** "Axiom" of Choice, proved using the description operator **) |
23 |
||
5316 | 24 |
Goal "!!Q. ALL x. EX y. Q x y ==> EX f. ALL x. Q x (f x)"; |
4656 | 25 |
by (fast_tac (claset() addEs [selectI]) 1); |
26 |
qed "choice"; |
|
27 |
||
5316 | 28 |
Goal "!!S. ALL x:S. EX y. Q x y ==> EX f. ALL x:S. Q x (f x)"; |
4656 | 29 |
by (fast_tac (claset() addEs [selectI]) 1); |
30 |
qed "bchoice"; |
|
31 |
||
32 |
||
5608 | 33 |
section "id"; |
5441 | 34 |
|
7089 | 35 |
Goalw [id_def] "id x = x"; |
36 |
by (rtac refl 1); |
|
37 |
qed "id_apply"; |
|
5608 | 38 |
Addsimps [id_apply]; |
5441 | 39 |
|
8226 | 40 |
Goal "inv id = id"; |
41 |
by (simp_tac (simpset() addsimps [inv_def,id_def]) 1); |
|
42 |
qed "inv_id"; |
|
43 |
Addsimps [inv_id]; |
|
44 |
||
5441 | 45 |
|
5306 | 46 |
section "o"; |
47 |
||
7089 | 48 |
Goalw [o_def] "(f o g) x = f (g x)"; |
49 |
by (rtac refl 1); |
|
50 |
qed "o_apply"; |
|
5306 | 51 |
Addsimps [o_apply]; |
52 |
||
7089 | 53 |
Goalw [o_def] "f o (g o h) = f o g o h"; |
54 |
by (rtac ext 1); |
|
55 |
by (rtac refl 1); |
|
56 |
qed "o_assoc"; |
|
5306 | 57 |
|
7089 | 58 |
Goalw [id_def] "id o g = g"; |
59 |
by (rtac ext 1); |
|
60 |
by (Simp_tac 1); |
|
61 |
qed "id_o"; |
|
5608 | 62 |
Addsimps [id_o]; |
5306 | 63 |
|
7089 | 64 |
Goalw [id_def] "f o id = f"; |
65 |
by (rtac ext 1); |
|
66 |
by (Simp_tac 1); |
|
67 |
qed "o_id"; |
|
5608 | 68 |
Addsimps [o_id]; |
5306 | 69 |
|
70 |
Goalw [o_def] "(f o g)``r = f``(g``r)"; |
|
71 |
by (Blast_tac 1); |
|
72 |
qed "image_compose"; |
|
73 |
||
7916 | 74 |
Goal "f``A = (UN x:A. {f x})"; |
7536 | 75 |
by (Blast_tac 1); |
7916 | 76 |
qed "image_eq_UN"; |
7536 | 77 |
|
5852 | 78 |
Goalw [o_def] "UNION A (g o f) = UNION (f``A) g"; |
79 |
by (Blast_tac 1); |
|
6829
50459a995aa3
renamed UNION_o to UN_o (to fit the convention) and added image_UN, image_INT
paulson
parents:
6301
diff
changeset
|
80 |
qed "UN_o"; |
5852 | 81 |
|
7014
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6829
diff
changeset
|
82 |
(** lemma for proving injectivity of representation functions for **) |
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6829
diff
changeset
|
83 |
(** datatypes involving function types **) |
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6829
diff
changeset
|
84 |
|
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6829
diff
changeset
|
85 |
Goalw [o_def] |
7089 | 86 |
"[| ! x y. g (f x) = g y --> f x = y; g o f = g o fa |] ==> f = fa"; |
87 |
by (rtac ext 1); |
|
88 |
by (etac allE 1); |
|
89 |
by (etac allE 1); |
|
90 |
by (etac mp 1); |
|
91 |
by (etac fun_cong 1); |
|
7014
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6829
diff
changeset
|
92 |
qed "inj_fun_lemma"; |
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6829
diff
changeset
|
93 |
|
5306 | 94 |
|
95 |
section "inj"; |
|
6171 | 96 |
(**NB: inj now just translates to inj_on**) |
5306 | 97 |
|
923 | 98 |
(*** inj(f): f is a one-to-one function ***) |
99 |
||
6171 | 100 |
(*for Tools/datatype_rep_proofs*) |
101 |
val [prem] = Goalw [inj_on_def] |
|
102 |
"(!! x. ALL y. f(x) = f(y) --> x=y) ==> inj(f)"; |
|
103 |
by (blast_tac (claset() addIs [prem RS spec RS mp]) 1); |
|
104 |
qed "datatype_injI"; |
|
923 | 105 |
|
6171 | 106 |
Goalw [inj_on_def] "[| inj(f); f(x) = f(y) |] ==> x=y"; |
5316 | 107 |
by (Blast_tac 1); |
923 | 108 |
qed "injD"; |
109 |
||
110 |
(*Useful with the simplifier*) |
|
5316 | 111 |
Goal "inj(f) ==> (f(x) = f(y)) = (x=y)"; |
923 | 112 |
by (rtac iffI 1); |
5316 | 113 |
by (etac arg_cong 2); |
114 |
by (etac injD 1); |
|
5318 | 115 |
by (assume_tac 1); |
923 | 116 |
qed "inj_eq"; |
117 |
||
5316 | 118 |
Goal "inj(f) ==> (@x. f(x)=f(y)) = y"; |
119 |
by (etac injD 1); |
|
923 | 120 |
by (rtac selectI 1); |
121 |
by (rtac refl 1); |
|
122 |
qed "inj_select"; |
|
123 |
||
124 |
(*A one-to-one function has an inverse (given using select).*) |
|
5316 | 125 |
Goalw [inv_def] "inj(f) ==> inv f (f x) = x"; |
126 |
by (etac inj_select 1); |
|
2912 | 127 |
qed "inv_f_f"; |
7338 | 128 |
Addsimps [inv_f_f]; |
923 | 129 |
|
7338 | 130 |
Goal "[| inj(f); f x = y |] ==> inv f y = x"; |
131 |
by (etac subst 1); |
|
132 |
by (etac inv_f_f 1); |
|
133 |
qed "inv_f_eq"; |
|
6235 | 134 |
|
923 | 135 |
(* Useful??? *) |
5316 | 136 |
val [oneone,minor] = Goal |
2912 | 137 |
"[| inj(f); !!y. y: range(f) ==> P(inv f y) |] ==> P(x)"; |
138 |
by (res_inst_tac [("t", "x")] (oneone RS (inv_f_f RS subst)) 1); |
|
923 | 139 |
by (rtac (rangeI RS minor) 1); |
140 |
qed "inj_transfer"; |
|
141 |
||
7014
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6829
diff
changeset
|
142 |
Goalw [o_def] "[| inj f; f o g = f o h |] ==> g = h"; |
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6829
diff
changeset
|
143 |
by (rtac ext 1); |
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6829
diff
changeset
|
144 |
by (etac injD 1); |
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6829
diff
changeset
|
145 |
by (etac fun_cong 1); |
11ee650edcd2
Added some definitions and theorems needed for the
berghofe
parents:
6829
diff
changeset
|
146 |
qed "inj_o"; |
923 | 147 |
|
4830 | 148 |
(*** inj_on f A: f is one-to-one over A ***) |
923 | 149 |
|
5316 | 150 |
val prems = Goalw [inj_on_def] |
4830 | 151 |
"(!! x y. [| f(x) = f(y); x:A; y:A |] ==> x=y) ==> inj_on f A"; |
4089 | 152 |
by (blast_tac (claset() addIs prems) 1); |
4830 | 153 |
qed "inj_onI"; |
9108 | 154 |
bind_thm ("injI", inj_onI); (*for compatibility*) |
923 | 155 |
|
5316 | 156 |
val [major] = Goal |
4830 | 157 |
"(!!x. x:A ==> g(f(x)) = x) ==> inj_on f A"; |
158 |
by (rtac inj_onI 1); |
|
923 | 159 |
by (etac (apply_inverse RS trans) 1); |
160 |
by (REPEAT (eresolve_tac [asm_rl,major] 1)); |
|
4830 | 161 |
qed "inj_on_inverseI"; |
9108 | 162 |
bind_thm ("inj_inverseI", inj_on_inverseI); (*for compatibility*) |
923 | 163 |
|
8285 | 164 |
Goal "(inj f) = (inv f o f = id)"; |
165 |
by (asm_simp_tac (simpset() addsimps [o_def, expand_fun_eq]) 1); |
|
166 |
by (blast_tac (claset() addIs [inj_inverseI, inv_f_f]) 1); |
|
167 |
qed "inj_iff"; |
|
168 |
||
5316 | 169 |
Goalw [inj_on_def] "[| inj_on f A; f(x)=f(y); x:A; y:A |] ==> x=y"; |
170 |
by (Blast_tac 1); |
|
4830 | 171 |
qed "inj_onD"; |
923 | 172 |
|
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5069
diff
changeset
|
173 |
Goal "[| inj_on f A; x:A; y:A |] ==> (f(x)=f(y)) = (x=y)"; |
4830 | 174 |
by (blast_tac (claset() addSDs [inj_onD]) 1); |
175 |
qed "inj_on_iff"; |
|
923 | 176 |
|
5316 | 177 |
Goalw [inj_on_def] "[| inj_on f A; ~x=y; x:A; y:A |] ==> ~ f(x)=f(y)"; |
178 |
by (Blast_tac 1); |
|
4830 | 179 |
qed "inj_on_contraD"; |
923 | 180 |
|
8156 | 181 |
Goal "inj (%s. {s})"; |
8253 | 182 |
by (rtac injI 1); |
183 |
by (etac singleton_inject 1); |
|
8156 | 184 |
qed "inj_singleton"; |
185 |
||
5316 | 186 |
Goalw [inj_on_def] "[| A<=B; inj_on f B |] ==> inj_on f A"; |
3341 | 187 |
by (Blast_tac 1); |
4830 | 188 |
qed "subset_inj_on"; |
3341 | 189 |
|
923 | 190 |
|
6235 | 191 |
(** surj **) |
192 |
||
6267 | 193 |
val [prem] = Goalw [surj_def] "(!! x. g(f x) = x) ==> surj g"; |
194 |
by (blast_tac (claset() addIs [prem RS sym]) 1); |
|
6235 | 195 |
qed "surjI"; |
196 |
||
197 |
Goalw [surj_def] "surj f ==> range f = UNIV"; |
|
198 |
by Auto_tac; |
|
199 |
qed "surj_range"; |
|
200 |
||
6267 | 201 |
Goalw [surj_def] "surj f ==> EX x. y = f x"; |
202 |
by (Blast_tac 1); |
|
203 |
qed "surjD"; |
|
204 |
||
8253 | 205 |
Goal "inj f ==> surj (inv f)"; |
206 |
by (blast_tac (claset() addIs [surjI, inv_f_f]) 1); |
|
207 |
qed "inj_imp_surj_inv"; |
|
7374 | 208 |
|
209 |
||
6171 | 210 |
(*** Lemmas about injective functions and inv ***) |
923 | 211 |
|
7051 | 212 |
Goalw [o_def] "[| inj_on f A; inj_on g (f``A) |] ==> inj_on (g o f) A"; |
6171 | 213 |
by (fast_tac (claset() addIs [inj_onI] addEs [inj_onD]) 1); |
214 |
qed "comp_inj_on"; |
|
923 | 215 |
|
5316 | 216 |
Goalw [inv_def] "y : range(f) ==> f(inv f y) = y"; |
217 |
by (fast_tac (claset() addIs [selectI]) 1); |
|
2912 | 218 |
qed "f_inv_f"; |
923 | 219 |
|
6235 | 220 |
Goal "surj f ==> f(inv f y) = y"; |
221 |
by (asm_simp_tac (simpset() addsimps [f_inv_f, surj_range]) 1); |
|
222 |
qed "surj_f_inv_f"; |
|
223 |
||
6171 | 224 |
Goal "[| inv f x = inv f y; x: range(f); y: range(f) |] ==> x=y"; |
2912 | 225 |
by (rtac (arg_cong RS box_equals) 1); |
5316 | 226 |
by (REPEAT (ares_tac [f_inv_f] 1)); |
2912 | 227 |
qed "inv_injective"; |
228 |
||
6235 | 229 |
Goal "A <= range(f) ==> inj_on (inv f) A"; |
4830 | 230 |
by (fast_tac (claset() addIs [inj_onI] |
6235 | 231 |
addEs [inv_injective, injD]) 1); |
4830 | 232 |
qed "inj_on_inv"; |
923 | 233 |
|
6235 | 234 |
Goal "surj f ==> inj (inv f)"; |
235 |
by (asm_simp_tac (simpset() addsimps [inj_on_inv, surj_range]) 1); |
|
236 |
qed "surj_imp_inj_inv"; |
|
237 |
||
8285 | 238 |
Goal "(surj f) = (f o inv f = id)"; |
239 |
by (asm_simp_tac (simpset() addsimps [o_def, expand_fun_eq]) 1); |
|
240 |
by (blast_tac (claset() addIs [surjI, surj_f_inv_f]) 1); |
|
241 |
qed "surj_iff"; |
|
242 |
||
8253 | 243 |
|
244 |
(** Bijections **) |
|
245 |
||
246 |
Goalw [bij_def] "[| inj f; surj f |] ==> bij f"; |
|
247 |
by (Blast_tac 1); |
|
248 |
qed "bijI"; |
|
249 |
||
250 |
Goalw [bij_def] "bij f ==> inj f"; |
|
251 |
by (Blast_tac 1); |
|
252 |
qed "bij_is_inj"; |
|
253 |
||
254 |
Goalw [bij_def] "bij f ==> surj f"; |
|
255 |
by (Blast_tac 1); |
|
256 |
qed "bij_is_surj"; |
|
257 |
||
258 |
Goalw [bij_def] "bij f ==> bij (inv f)"; |
|
259 |
by (asm_simp_tac (simpset() addsimps [inj_imp_surj_inv, surj_imp_inj_inv]) 1); |
|
260 |
qed "bij_imp_bij_inv"; |
|
261 |
||
262 |
val prems = |
|
263 |
Goalw [inv_def] "[| !! x. g (f x) = x; !! y. f (g y) = y |] ==> inv f = g"; |
|
264 |
by (rtac ext 1); |
|
265 |
by (auto_tac (claset(), simpset() addsimps prems)); |
|
266 |
qed "inv_equality"; |
|
267 |
||
268 |
Goalw [bij_def] "bij f ==> inv (inv f) = f"; |
|
269 |
by (rtac inv_equality 1); |
|
270 |
by (auto_tac (claset(), simpset() addsimps [surj_f_inv_f])); |
|
271 |
qed "inv_inv_eq"; |
|
272 |
||
273 |
Goalw [bij_def] "[| bij f; bij g |] ==> inv (f o g) = inv g o inv f"; |
|
274 |
by (rtac (inv_equality) 1); |
|
275 |
by (auto_tac (claset(), simpset() addsimps [surj_f_inv_f])); |
|
276 |
qed "o_inv_distrib"; |
|
277 |
||
278 |
||
7514 | 279 |
(** We seem to need both the id-forms and the (%x. x) forms; the latter can |
280 |
arise by rewriting, while id may be used explicitly. **) |
|
281 |
||
282 |
Goal "(%x. x) `` Y = Y"; |
|
283 |
by (Blast_tac 1); |
|
284 |
qed "image_ident"; |
|
285 |
||
286 |
Goalw [id_def] "id `` Y = Y"; |
|
287 |
by (Blast_tac 1); |
|
288 |
qed "image_id"; |
|
289 |
Addsimps [image_ident, image_id]; |
|
290 |
||
291 |
Goal "(%x. x) -`` Y = Y"; |
|
292 |
by (Blast_tac 1); |
|
293 |
qed "vimage_ident"; |
|
294 |
||
295 |
Goalw [id_def] "id -`` A = A"; |
|
296 |
by Auto_tac; |
|
297 |
qed "vimage_id"; |
|
298 |
Addsimps [vimage_ident, vimage_id]; |
|
299 |
||
7876 | 300 |
Goal "f -`` (f `` A) = {y. EX x:A. f x = f y}"; |
301 |
by (blast_tac (claset() addIs [sym]) 1); |
|
302 |
qed "vimage_image_eq"; |
|
303 |
||
8173 | 304 |
Goal "f `` (f -`` A) <= A"; |
305 |
by (Blast_tac 1); |
|
306 |
qed "image_vimage_subset"; |
|
307 |
||
308 |
Goal "f `` (f -`` A) = A Int range f"; |
|
309 |
by (Blast_tac 1); |
|
310 |
qed "image_vimage_eq"; |
|
311 |
Addsimps [image_vimage_eq]; |
|
312 |
||
313 |
Goal "surj f ==> f `` (f -`` A) = A"; |
|
314 |
by (asm_simp_tac (simpset() addsimps [surj_range]) 1); |
|
315 |
qed "surj_image_vimage_eq"; |
|
316 |
||
8253 | 317 |
Goal "surj f ==> f `` (inv f `` A) = A"; |
318 |
by (asm_simp_tac (simpset() addsimps [image_eq_UN, surj_f_inv_f]) 1); |
|
319 |
qed "image_surj_f_inv_f"; |
|
320 |
||
8173 | 321 |
Goalw [inj_on_def] "inj f ==> f -`` (f `` A) = A"; |
322 |
by (Blast_tac 1); |
|
323 |
qed "inj_vimage_image_eq"; |
|
324 |
||
8253 | 325 |
Goal "inj f ==> (inv f) `` (f `` A) = A"; |
326 |
by (asm_simp_tac (simpset() addsimps [image_eq_UN]) 1); |
|
327 |
qed "image_inv_f_f"; |
|
328 |
||
8173 | 329 |
Goalw [surj_def] "surj f ==> f -`` B <= A ==> B <= f `` A"; |
330 |
by (blast_tac (claset() addIs [sym]) 1); |
|
331 |
qed "vimage_subsetD"; |
|
332 |
||
333 |
Goalw [inj_on_def] "inj f ==> B <= f `` A ==> f -`` B <= A"; |
|
334 |
by (Blast_tac 1); |
|
335 |
qed "vimage_subsetI"; |
|
336 |
||
337 |
Goalw [bij_def] "bij f ==> (f -`` B <= A) = (B <= f `` A)"; |
|
338 |
by (blast_tac (claset() delrules [subsetI] |
|
339 |
addIs [vimage_subsetI, vimage_subsetD]) 1); |
|
340 |
qed "vimage_subset_eq"; |
|
341 |
||
6290 | 342 |
Goal "f``(A Int B) <= f``A Int f``B"; |
343 |
by (Blast_tac 1); |
|
344 |
qed "image_Int_subset"; |
|
345 |
||
346 |
Goal "f``A - f``B <= f``(A - B)"; |
|
347 |
by (Blast_tac 1); |
|
348 |
qed "image_diff_subset"; |
|
349 |
||
5069 | 350 |
Goalw [inj_on_def] |
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5143
diff
changeset
|
351 |
"[| inj_on f C; A<=C; B<=C |] ==> f``(A Int B) = f``A Int f``B"; |
4059 | 352 |
by (Blast_tac 1); |
4830 | 353 |
qed "inj_on_image_Int"; |
4059 | 354 |
|
5069 | 355 |
Goalw [inj_on_def] |
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5143
diff
changeset
|
356 |
"[| inj_on f C; A<=C; B<=C |] ==> f``(A-B) = f``A - f``B"; |
4059 | 357 |
by (Blast_tac 1); |
4830 | 358 |
qed "inj_on_image_set_diff"; |
4059 | 359 |
|
6171 | 360 |
Goalw [inj_on_def] "inj f ==> f``(A Int B) = f``A Int f``B"; |
4059 | 361 |
by (Blast_tac 1); |
362 |
qed "image_Int"; |
|
363 |
||
6171 | 364 |
Goalw [inj_on_def] "inj f ==> f``(A-B) = f``A - f``B"; |
4059 | 365 |
by (Blast_tac 1); |
366 |
qed "image_set_diff"; |
|
367 |
||
6235 | 368 |
Goalw [image_def] "inj(f) ==> inv(f)``(f``X) = X"; |
369 |
by Auto_tac; |
|
370 |
qed "inv_image_comp"; |
|
5847 | 371 |
|
6301 | 372 |
Goal "inj f ==> (f a : f``A) = (a : A)"; |
373 |
by (blast_tac (claset() addDs [injD]) 1); |
|
374 |
qed "inj_image_mem_iff"; |
|
375 |
||
8253 | 376 |
Goalw [inj_on_def] "inj f ==> (f``A <= f``B) = (A<=B)"; |
377 |
by (Blast_tac 1); |
|
378 |
qed "inj_image_subset_iff"; |
|
379 |
||
6301 | 380 |
Goal "inj f ==> (f``A = f``B) = (A = B)"; |
381 |
by (blast_tac (claset() addSEs [equalityE] addDs [injD]) 1); |
|
382 |
qed "inj_image_eq_iff"; |
|
383 |
||
6829
50459a995aa3
renamed UNION_o to UN_o (to fit the convention) and added image_UN, image_INT
paulson
parents:
6301
diff
changeset
|
384 |
Goal "(f `` (UNION A B)) = (UN x:A.(f `` (B x)))"; |
50459a995aa3
renamed UNION_o to UN_o (to fit the convention) and added image_UN, image_INT
paulson
parents:
6301
diff
changeset
|
385 |
by (Blast_tac 1); |
50459a995aa3
renamed UNION_o to UN_o (to fit the convention) and added image_UN, image_INT
paulson
parents:
6301
diff
changeset
|
386 |
qed "image_UN"; |
50459a995aa3
renamed UNION_o to UN_o (to fit the convention) and added image_UN, image_INT
paulson
parents:
6301
diff
changeset
|
387 |
|
50459a995aa3
renamed UNION_o to UN_o (to fit the convention) and added image_UN, image_INT
paulson
parents:
6301
diff
changeset
|
388 |
(*injectivity's required. Left-to-right inclusion holds even if A is empty*) |
50459a995aa3
renamed UNION_o to UN_o (to fit the convention) and added image_UN, image_INT
paulson
parents:
6301
diff
changeset
|
389 |
Goalw [inj_on_def] |
50459a995aa3
renamed UNION_o to UN_o (to fit the convention) and added image_UN, image_INT
paulson
parents:
6301
diff
changeset
|
390 |
"[| inj_on f C; ALL x:A. B x <= C; j:A |] \ |
50459a995aa3
renamed UNION_o to UN_o (to fit the convention) and added image_UN, image_INT
paulson
parents:
6301
diff
changeset
|
391 |
\ ==> f `` (INTER A B) = (INT x:A. f `` B x)"; |
50459a995aa3
renamed UNION_o to UN_o (to fit the convention) and added image_UN, image_INT
paulson
parents:
6301
diff
changeset
|
392 |
by (Blast_tac 1); |
50459a995aa3
renamed UNION_o to UN_o (to fit the convention) and added image_UN, image_INT
paulson
parents:
6301
diff
changeset
|
393 |
qed "image_INT"; |
50459a995aa3
renamed UNION_o to UN_o (to fit the convention) and added image_UN, image_INT
paulson
parents:
6301
diff
changeset
|
394 |
|
8309 | 395 |
(*Compare with image_INT: no use of inj_on, and if f is surjective then |
396 |
it doesn't matter whether A is empty*) |
|
397 |
Goalw [bij_def] "bij f ==> f `` (INTER A B) = (INT x:A. f `` B x)"; |
|
398 |
by (force_tac (claset() addSIs [surj_f_inv_f RS sym RS image_eqI], |
|
399 |
simpset()) 1); |
|
400 |
qed "bij_image_INT"; |
|
401 |
||
402 |
Goal "bij f ==> f `` Collect P = {y. P (inv f y)}"; |
|
403 |
by Auto_tac; |
|
404 |
by (force_tac (claset(), simpset() addsimps [bij_is_inj]) 1); |
|
405 |
by (blast_tac (claset() addIs [bij_is_surj RS surj_f_inv_f RS sym]) 1); |
|
406 |
qed "bij_image_Collect_eq"; |
|
407 |
||
408 |
Goal "bij f ==> f -`` A = inv f `` A"; |
|
8767 | 409 |
by Safe_tac; |
8309 | 410 |
by (asm_simp_tac (simpset() addsimps [bij_is_surj RS surj_f_inv_f]) 2); |
411 |
by (blast_tac (claset() addIs [bij_is_inj RS inv_f_f RS sym]) 1); |
|
412 |
qed "bij_vimage_eq_inv_image"; |
|
413 |
||
4089 | 414 |
val set_cs = claset() delrules [equalityI]; |
5305 | 415 |
|
416 |
||
417 |
section "fun_upd"; |
|
418 |
||
419 |
Goalw [fun_upd_def] "(f(x:=y) = f) = (f x = y)"; |
|
420 |
by Safe_tac; |
|
421 |
by (etac subst 1); |
|
422 |
by (rtac ext 2); |
|
423 |
by Auto_tac; |
|
424 |
qed "fun_upd_idem_iff"; |
|
425 |
||
426 |
(* f x = y ==> f(x:=y) = f *) |
|
427 |
bind_thm("fun_upd_idem", fun_upd_idem_iff RS iffD2); |
|
428 |
||
429 |
(* f(x := f x) = f *) |
|
430 |
AddIffs [refl RS fun_upd_idem]; |
|
431 |
||
432 |
Goal "(f(x:=y))z = (if z=x then y else f z)"; |
|
433 |
by (simp_tac (simpset() addsimps [fun_upd_def]) 1); |
|
434 |
qed "fun_upd_apply"; |
|
435 |
Addsimps [fun_upd_apply]; |
|
436 |
||
9339 | 437 |
(* fun_upd_apply supersedes these two, but they are useful |
438 |
if fun_upd_apply is intentionally removed from the simpset *) |
|
7089 | 439 |
Goal "(f(x:=y)) x = y"; |
440 |
by (Simp_tac 1); |
|
441 |
qed "fun_upd_same"; |
|
442 |
||
443 |
Goal "z~=x ==> (f(x:=y)) z = f z"; |
|
444 |
by (Asm_simp_tac 1); |
|
445 |
qed "fun_upd_other"; |
|
446 |
||
7445 | 447 |
Goal "f(x:=y,x:=z) = f(x:=z)"; |
448 |
by (rtac ext 1); |
|
449 |
by (Simp_tac 1); |
|
450 |
qed "fun_upd_upd"; |
|
451 |
Addsimps [fun_upd_upd]; |
|
5305 | 452 |
|
9339 | 453 |
(* simplifies terms of the form f(...,x:=y,...,x:=z,...) to f(...,x:=z,...) *) |
454 |
local |
|
455 |
fun gen_fun_upd None T _ _ = None |
|
456 |
| gen_fun_upd (Some f) T x y = Some (Const ("Fun.fun_upd",T) $ f $ x $ y) |
|
457 |
fun dest_fun_T1 (Type (_,T::Ts)) = T |
|
458 |
fun find_double (t as Const ("Fun.fun_upd",T) $ f $ x $ y) = let |
|
459 |
fun find (Const ("Fun.fun_upd",T) $ g $ v $ w) = |
|
460 |
if v aconv x then Some g else gen_fun_upd (find g) T v w |
|
461 |
| find t = None |
|
462 |
in (dest_fun_T1 T, gen_fun_upd (find f) T x y) end |
|
9422 | 463 |
val ss = simpset (); |
9339 | 464 |
val fun_upd_prover = K [rtac eq_reflection 1, rtac ext 1, |
9422 | 465 |
simp_tac ss 1] |
9339 | 466 |
fun mk_eq_cterm sg T l r = Thm.cterm_of sg (equals T $ l $ r) |
467 |
in |
|
468 |
val fun_upd2_simproc = Simplifier.mk_simproc "fun_upd2" |
|
9422 | 469 |
[Thm.read_cterm (sign_of (the_context ())) ("f(v:=w,x:=y)", HOLogic.termT)] |
9339 | 470 |
(fn sg => (K (fn t => case find_double t of (T,None)=> None | (T,Some rhs)=> |
471 |
Some (prove_goalw_cterm [] (mk_eq_cterm sg T t rhs) fun_upd_prover)))) |
|
472 |
end; |
|
473 |
Addsimprocs[fun_upd2_simproc]; |
|
474 |
||
8258 | 475 |
Goal "a ~= c ==> (m(a:=b))(c:=d) = (m(c:=d))(a:=b)"; |
5305 | 476 |
by (rtac ext 1); |
7089 | 477 |
by Auto_tac; |
5305 | 478 |
qed "fun_upd_twist"; |
5852 | 479 |
|
480 |
||
481 |
(*** -> and Pi, by Florian Kammueller and LCP ***) |
|
482 |
||
483 |
val prems = Goalw [Pi_def] |
|
484 |
"[| !!x. x: A ==> f x: B x; !!x. x ~: A ==> f(x) = (@ y. True)|] \ |
|
485 |
\ ==> f: Pi A B"; |
|
486 |
by (auto_tac (claset(), simpset() addsimps prems)); |
|
487 |
qed "Pi_I"; |
|
488 |
||
489 |
val prems = Goal |
|
490 |
"[| !!x. x: A ==> f x: B; !!x. x ~: A ==> f(x) = (@ y. True)|] ==> f: A funcset B"; |
|
491 |
by (blast_tac (claset() addIs Pi_I::prems) 1); |
|
492 |
qed "funcsetI"; |
|
493 |
||
494 |
Goalw [Pi_def] "[|f: Pi A B; x: A|] ==> f x: B x"; |
|
495 |
by Auto_tac; |
|
496 |
qed "Pi_mem"; |
|
497 |
||
498 |
Goalw [Pi_def] "[|f: A funcset B; x: A|] ==> f x: B"; |
|
499 |
by Auto_tac; |
|
500 |
qed "funcset_mem"; |
|
501 |
||
502 |
Goalw [Pi_def] "[|f: Pi A B; x~: A|] ==> f x = (@ y. True)"; |
|
503 |
by Auto_tac; |
|
504 |
qed "apply_arb"; |
|
505 |
||
506 |
Goalw [Pi_def] "[| f: Pi A B; g: Pi A B; ! x: A. f x = g x |] ==> f = g"; |
|
507 |
by (rtac ext 1); |
|
508 |
by Auto_tac; |
|
9108 | 509 |
bind_thm ("Pi_extensionality", ballI RSN (3, result())); |
5852 | 510 |
|
8138 | 511 |
|
5852 | 512 |
(*** compose ***) |
513 |
||
514 |
Goalw [Pi_def, compose_def, restrict_def] |
|
515 |
"[| f: A funcset B; g: B funcset C |]==> compose A g f: A funcset C"; |
|
516 |
by Auto_tac; |
|
517 |
qed "funcset_compose"; |
|
518 |
||
519 |
Goal "[| f: A funcset B; g: B funcset C; h: C funcset D |]\ |
|
520 |
\ ==> compose A h (compose A g f) = compose A (compose B h g) f"; |
|
521 |
by (res_inst_tac [("A","A")] Pi_extensionality 1); |
|
522 |
by (blast_tac (claset() addIs [funcset_compose]) 1); |
|
523 |
by (blast_tac (claset() addIs [funcset_compose]) 1); |
|
524 |
by (rewrite_goals_tac [Pi_def, compose_def, restrict_def]); |
|
525 |
by Auto_tac; |
|
526 |
qed "compose_assoc"; |
|
527 |
||
528 |
Goal "[| f: A funcset B; g: B funcset C; x: A |]==> compose A g f x = g(f(x))"; |
|
529 |
by (asm_full_simp_tac (simpset() addsimps [compose_def, restrict_def]) 1); |
|
530 |
qed "compose_eq"; |
|
531 |
||
532 |
Goal "[| f : A funcset B; f `` A = B; g: B funcset C; g `` B = C |]\ |
|
533 |
\ ==> compose A g f `` A = C"; |
|
534 |
by (auto_tac (claset(), |
|
535 |
simpset() addsimps [image_def, compose_eq])); |
|
536 |
qed "surj_compose"; |
|
537 |
||
538 |
Goal "[| f : A funcset B; g: B funcset C; f `` A = B; inj_on f A; inj_on g B |]\ |
|
539 |
\ ==> inj_on (compose A g f) A"; |
|
540 |
by (auto_tac (claset(), |
|
8081 | 541 |
simpset() addsimps [inj_on_def, compose_eq])); |
5852 | 542 |
qed "inj_on_compose"; |
543 |
||
544 |
||
545 |
(*** restrict / lam ***) |
|
8138 | 546 |
|
547 |
Goal "f``A <= B ==> (lam x: A. f x) : A funcset B"; |
|
5852 | 548 |
by (auto_tac (claset(), |
549 |
simpset() addsimps [restrict_def, Pi_def])); |
|
550 |
qed "restrict_in_funcset"; |
|
551 |
||
552 |
val prems = Goalw [restrict_def, Pi_def] |
|
553 |
"(!!x. x: A ==> f x: B x) ==> (lam x: A. f x) : Pi A B"; |
|
554 |
by (asm_simp_tac (simpset() addsimps prems) 1); |
|
555 |
qed "restrictI"; |
|
556 |
||
557 |
Goal "x: A ==> (lam y: A. f y) x = f x"; |
|
558 |
by (asm_simp_tac (simpset() addsimps [restrict_def]) 1); |
|
559 |
qed "restrict_apply1"; |
|
560 |
||
561 |
Goal "[| x: A; f : A funcset B |] ==> (lam y: A. f y) x : B"; |
|
562 |
by (asm_full_simp_tac (simpset() addsimps [restrict_apply1,Pi_def]) 1); |
|
563 |
qed "restrict_apply1_mem"; |
|
564 |
||
565 |
Goal "x ~: A ==> (lam y: A. f y) x = (@ y. True)"; |
|
566 |
by (asm_simp_tac (simpset() addsimps [restrict_def]) 1); |
|
567 |
qed "restrict_apply2"; |
|
568 |
||
569 |
val prems = Goal |
|
570 |
"(!!x. x: A ==> f x = g x) ==> (lam x: A. f x) = (lam x: A. g x)"; |
|
571 |
by (rtac ext 1); |
|
572 |
by (auto_tac (claset(), |
|
573 |
simpset() addsimps prems@[restrict_def, Pi_def])); |
|
574 |
qed "restrict_ext"; |
|
575 |
||
8138 | 576 |
Goalw [inj_on_def, restrict_def] "inj_on (restrict f A) A = inj_on f A"; |
577 |
by Auto_tac; |
|
578 |
qed "inj_on_restrict_eq"; |
|
579 |
||
5852 | 580 |
|
581 |
(*** Inverse ***) |
|
582 |
||
583 |
Goal "[|f `` A = B; x: B |] ==> ? y: A. f y = x"; |
|
584 |
by (Blast_tac 1); |
|
585 |
qed "surj_image"; |
|
586 |
||
587 |
Goalw [Inv_def] "[| f `` A = B; f : A funcset B |] \ |
|
588 |
\ ==> (lam x: B. (Inv A f) x) : B funcset A"; |
|
589 |
by (fast_tac (claset() addIs [restrict_in_funcset, selectI2]) 1); |
|
590 |
qed "Inv_funcset"; |
|
591 |
||
592 |
||
593 |
Goal "[| f: A funcset B; inj_on f A; f `` A = B; x: A |] \ |
|
594 |
\ ==> (lam y: B. (Inv A f) y) (f x) = x"; |
|
595 |
by (asm_simp_tac (simpset() addsimps [restrict_apply1, funcset_mem]) 1); |
|
8081 | 596 |
by (asm_full_simp_tac (simpset() addsimps [Inv_def, inj_on_def]) 1); |
5852 | 597 |
by (rtac selectI2 1); |
598 |
by Auto_tac; |
|
599 |
qed "Inv_f_f"; |
|
600 |
||
601 |
Goal "[| f: A funcset B; f `` A = B; x: B |] \ |
|
602 |
\ ==> f ((lam y: B. (Inv A f y)) x) = x"; |
|
603 |
by (asm_simp_tac (simpset() addsimps [Inv_def, restrict_apply1]) 1); |
|
604 |
by (fast_tac (claset() addIs [selectI2]) 1); |
|
605 |
qed "f_Inv_f"; |
|
606 |
||
607 |
Goal "[| f: A funcset B; inj_on f A; f `` A = B |]\ |
|
608 |
\ ==> compose A (lam y:B. (Inv A f) y) f = (lam x: A. x)"; |
|
609 |
by (rtac Pi_extensionality 1); |
|
610 |
by (blast_tac (claset() addIs [funcset_compose, Inv_funcset]) 1); |
|
611 |
by (blast_tac (claset() addIs [restrict_in_funcset]) 1); |
|
612 |
by (asm_simp_tac |
|
613 |
(simpset() addsimps [restrict_apply1, compose_def, Inv_f_f]) 1); |
|
614 |
qed "compose_Inv_id"; |
|
615 |
||
616 |
||
617 |
(*** Pi and Applyall ***) |
|
618 |
||
619 |
Goalw [Pi_def] "[| B(x) = {}; x: A |] ==> (PI x: A. B x) = {}"; |
|
620 |
by Auto_tac; |
|
621 |
qed "Pi_eq_empty"; |
|
622 |
||
623 |
Goal "[| (PI x: A. B x) ~= {}; x: A |] ==> B(x) ~= {}"; |
|
624 |
by (blast_tac (HOL_cs addIs [Pi_eq_empty]) 1); |
|
625 |
qed "Pi_total1"; |
|
626 |
||
627 |
Goal "[| a : A; Pi A B ~= {} |] ==> Applyall (Pi A B) a = B a"; |
|
628 |
by (auto_tac (claset(), simpset() addsimps [Applyall_def, Pi_def])); |
|
629 |
by (rename_tac "g z" 1); |
|
630 |
by (res_inst_tac [("x","%y. if (y = a) then z else g y")] exI 1); |
|
631 |
by (auto_tac (claset(), simpset() addsimps [split_if_mem1, split_if_eq1])); |
|
632 |
qed "Applyall_beta"; |
|
633 |
||
5865
2303f5a3036d
moved some facts about Pi from ex/PiSets to Fun.ML
paulson
parents:
5852
diff
changeset
|
634 |
Goal "Pi {} B = { (%x. @ y. True) }"; |
2303f5a3036d
moved some facts about Pi from ex/PiSets to Fun.ML
paulson
parents:
5852
diff
changeset
|
635 |
by (auto_tac (claset() addIs [ext], simpset() addsimps [Pi_def])); |
2303f5a3036d
moved some facts about Pi from ex/PiSets to Fun.ML
paulson
parents:
5852
diff
changeset
|
636 |
qed "Pi_empty"; |
5852 | 637 |
|
5865
2303f5a3036d
moved some facts about Pi from ex/PiSets to Fun.ML
paulson
parents:
5852
diff
changeset
|
638 |
val [major] = Goalw [Pi_def] "(!!x. x: A ==> B x <= C x) ==> Pi A B <= Pi A C"; |
2303f5a3036d
moved some facts about Pi from ex/PiSets to Fun.ML
paulson
parents:
5852
diff
changeset
|
639 |
by (auto_tac (claset(), |
2303f5a3036d
moved some facts about Pi from ex/PiSets to Fun.ML
paulson
parents:
5852
diff
changeset
|
640 |
simpset() addsimps [impOfSubs major])); |
2303f5a3036d
moved some facts about Pi from ex/PiSets to Fun.ML
paulson
parents:
5852
diff
changeset
|
641 |
qed "Pi_mono"; |