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