73 |
73 |
74 val [prem] = goalw Perm.thy [id_def] "A<=B ==> id(A) <= id(B)"; |
74 val [prem] = goalw Perm.thy [id_def] "A<=B ==> id(A) <= id(B)"; |
75 by (rtac (prem RS lam_mono) 1); |
75 by (rtac (prem RS lam_mono) 1); |
76 val id_mono = result(); |
76 val id_mono = result(); |
77 |
77 |
78 goalw Perm.thy [inj_def,id_def] "id(A): inj(A,A)"; |
78 goalw Perm.thy [inj_def,id_def] "!!A B. A<=B ==> id(A): inj(A,B)"; |
79 by (REPEAT (ares_tac [CollectI,lam_type] 1)); |
79 by (REPEAT (ares_tac [CollectI,lam_type] 1)); |
|
80 by (etac subsetD 1 THEN assume_tac 1); |
80 by (simp_tac ZF_ss 1); |
81 by (simp_tac ZF_ss 1); |
81 val id_inj = result(); |
82 val id_subset_inj = result(); |
|
83 |
|
84 val id_inj = subset_refl RS id_subset_inj; |
82 |
85 |
83 goalw Perm.thy [id_def,surj_def] "id(A): surj(A,A)"; |
86 goalw Perm.thy [id_def,surj_def] "id(A): surj(A,A)"; |
84 by (fast_tac (ZF_cs addIs [lam_type,beta]) 1); |
87 by (fast_tac (ZF_cs addIs [lam_type,beta]) 1); |
85 val id_surj = result(); |
88 val id_surj = result(); |
86 |
89 |
109 val prems = goal Perm.thy |
112 val prems = goal Perm.thy |
110 "[| f: A->B; converse(f): C->A; a: A |] ==> converse(f)`(f`a) = a"; |
113 "[| f: A->B; converse(f): C->A; a: A |] ==> converse(f)`(f`a) = a"; |
111 by (fast_tac (ZF_cs addIs (prems@[apply_Pair,apply_equality,converseI])) 1); |
114 by (fast_tac (ZF_cs addIs (prems@[apply_Pair,apply_equality,converseI])) 1); |
112 val left_inverse_lemma = result(); |
115 val left_inverse_lemma = result(); |
113 |
116 |
114 val prems = goal Perm.thy |
117 goal Perm.thy |
115 "[| f: inj(A,B); a: A |] ==> converse(f)`(f`a) = a"; |
118 "!!f. [| f: inj(A,B); a: A |] ==> converse(f)`(f`a) = a"; |
116 by (fast_tac (ZF_cs addIs (prems@ |
119 by (fast_tac (ZF_cs addIs [left_inverse_lemma,inj_converse_fun,inj_is_fun]) 1); |
117 [left_inverse_lemma,inj_converse_fun,inj_is_fun])) 1); |
|
118 val left_inverse = result(); |
120 val left_inverse = result(); |
|
121 |
|
122 val left_inverse_bij = bij_is_inj RS left_inverse; |
119 |
123 |
120 val prems = goal Perm.thy |
124 val prems = goal Perm.thy |
121 "[| f: A->B; converse(f): C->A; b: C |] ==> f`(converse(f)`b) = b"; |
125 "[| f: A->B; converse(f): C->A; b: C |] ==> f`(converse(f)`b) = b"; |
122 by (rtac (apply_Pair RS (converseD RS apply_equality)) 1); |
126 by (rtac (apply_Pair RS (converseD RS apply_equality)) 1); |
123 by (REPEAT (resolve_tac prems 1)); |
127 by (REPEAT (resolve_tac prems 1)); |
124 val right_inverse_lemma = result(); |
128 val right_inverse_lemma = result(); |
125 |
129 |
126 val prems = goal Perm.thy |
130 goal Perm.thy |
127 "[| f: inj(A,B); b: range(f) |] ==> f`(converse(f)`b) = b"; |
131 "!!f. [| f: inj(A,B); b: range(f) |] ==> f`(converse(f)`b) = b"; |
128 by (rtac right_inverse_lemma 1); |
132 by (rtac right_inverse_lemma 1); |
129 by (REPEAT (resolve_tac (prems@ [inj_converse_fun,inj_is_fun]) 1)); |
133 by (REPEAT (ares_tac [inj_converse_fun,inj_is_fun] 1)); |
130 val right_inverse = result(); |
134 val right_inverse = result(); |
|
135 |
|
136 goalw Perm.thy [bij_def] |
|
137 "!!f. [| f: bij(A,B); b: B |] ==> f`(converse(f)`b) = b"; |
|
138 by (EVERY1 [etac IntE, etac right_inverse, |
|
139 etac (surj_range RS ssubst), |
|
140 assume_tac]); |
|
141 val right_inverse_bij = result(); |
131 |
142 |
132 val prems = goal Perm.thy |
143 val prems = goal Perm.thy |
133 "f: inj(A,B) ==> converse(f): inj(range(f), A)"; |
144 "f: inj(A,B) ==> converse(f): inj(range(f), A)"; |
134 bw inj_def; (*rewrite subgoal but not prems!!*) |
145 bw inj_def; (*rewrite subgoal but not prems!!*) |
135 by (cut_facts_tac prems 1); |
146 by (cut_facts_tac prems 1); |
234 |
245 |
235 goal Perm.thy "!!f g. [| g: A->B; f: B->C |] ==> (f O g) : A->C"; |
246 goal Perm.thy "!!f g. [| g: A->B; f: B->C |] ==> (f O g) : A->C"; |
236 by (REPEAT (ares_tac [PiI,comp_rel,ex1I,compI] 1 |
247 by (REPEAT (ares_tac [PiI,comp_rel,ex1I,compI] 1 |
237 ORELSE eresolve_tac [fun_is_rel,apply_Pair,apply_type] 1)); |
248 ORELSE eresolve_tac [fun_is_rel,apply_Pair,apply_type] 1)); |
238 by (fast_tac (comp_cs addDs [apply_equality]) 1); |
249 by (fast_tac (comp_cs addDs [apply_equality]) 1); |
239 val comp_func = result(); |
250 val comp_fun = result(); |
240 |
251 |
241 goal Perm.thy "!!f g. [| g: A->B; f: B->C; a:A |] ==> (f O g)`a = f`(g`a)"; |
252 goal Perm.thy "!!f g. [| g: A->B; f: B->C; a:A |] ==> (f O g)`a = f`(g`a)"; |
242 by (REPEAT (ares_tac [comp_func,apply_equality,compI, |
253 by (REPEAT (ares_tac [comp_fun,apply_equality,compI, |
243 apply_Pair,apply_type] 1)); |
254 apply_Pair,apply_type] 1)); |
244 val comp_func_apply = result(); |
255 val comp_fun_apply = result(); |
245 |
256 |
246 goalw Perm.thy [inj_def] |
257 goalw Perm.thy [inj_def] |
247 "!!f g. [| g: inj(A,B); f: inj(B,C) |] ==> (f O g) : inj(A,C)"; |
258 "!!f g. [| g: inj(A,B); f: inj(B,C) |] ==> (f O g) : inj(A,C)"; |
248 by (REPEAT (eresolve_tac [bspec RS bspec RS mp, box_equals] 1 |
259 by (REPEAT (eresolve_tac [bspec RS bspec RS mp, box_equals] 1 |
249 ORELSE step_tac (ZF_cs addSIs [comp_func,apply_type,comp_func_apply]) 1)); |
260 ORELSE step_tac (ZF_cs addSIs [comp_fun,apply_type,comp_fun_apply]) 1)); |
250 val comp_inj = result(); |
261 val comp_inj = result(); |
251 |
262 |
252 goalw Perm.thy [surj_def] |
263 goalw Perm.thy [surj_def] |
253 "!!f g. [| g: surj(A,B); f: surj(B,C) |] ==> (f O g) : surj(A,C)"; |
264 "!!f g. [| g: surj(A,B); f: surj(B,C) |] ==> (f O g) : surj(A,C)"; |
254 by (best_tac (ZF_cs addSIs [comp_func,comp_func_apply]) 1); |
265 by (best_tac (ZF_cs addSIs [comp_fun,comp_fun_apply]) 1); |
255 val comp_surj = result(); |
266 val comp_surj = result(); |
256 |
267 |
257 goalw Perm.thy [bij_def] |
268 goalw Perm.thy [bij_def] |
258 "!!f g. [| g: bij(A,B); f: bij(B,C) |] ==> (f O g) : bij(A,C)"; |
269 "!!f g. [| g: bij(A,B); f: bij(B,C) |] ==> (f O g) : bij(A,C)"; |
259 by (fast_tac (ZF_cs addIs [comp_inj,comp_surj]) 1); |
270 by (fast_tac (ZF_cs addIs [comp_inj,comp_surj]) 1); |
266 |
277 |
267 goalw Perm.thy [inj_def] |
278 goalw Perm.thy [inj_def] |
268 "!!f g. [| (f O g): inj(A,C); g: A->B; f: B->C |] ==> g: inj(A,B)"; |
279 "!!f g. [| (f O g): inj(A,C); g: A->B; f: B->C |] ==> g: inj(A,B)"; |
269 by (safe_tac comp_cs); |
280 by (safe_tac comp_cs); |
270 by (REPEAT (eresolve_tac [asm_rl, bspec RS bspec RS mp] 1)); |
281 by (REPEAT (eresolve_tac [asm_rl, bspec RS bspec RS mp] 1)); |
271 by (asm_simp_tac (FOL_ss addsimps [comp_func_apply]) 1); |
282 by (asm_simp_tac (FOL_ss addsimps [comp_fun_apply]) 1); |
272 val comp_mem_injD1 = result(); |
283 val comp_mem_injD1 = result(); |
273 |
284 |
274 goalw Perm.thy [inj_def,surj_def] |
285 goalw Perm.thy [inj_def,surj_def] |
275 "!!f g. [| (f O g): inj(A,C); g: surj(A,B); f: B->C |] ==> f: inj(B,C)"; |
286 "!!f g. [| (f O g): inj(A,C); g: surj(A,B); f: B->C |] ==> f: inj(B,C)"; |
276 by (safe_tac comp_cs); |
287 by (safe_tac comp_cs); |
278 by (eres_inst_tac [("x1", "w")] (bspec RS bexE) 3); |
289 by (eres_inst_tac [("x1", "w")] (bspec RS bexE) 3); |
279 by (REPEAT (assume_tac 1)); |
290 by (REPEAT (assume_tac 1)); |
280 by (safe_tac comp_cs); |
291 by (safe_tac comp_cs); |
281 by (res_inst_tac [("t", "op `(g)")] subst_context 1); |
292 by (res_inst_tac [("t", "op `(g)")] subst_context 1); |
282 by (REPEAT (eresolve_tac [asm_rl, bspec RS bspec RS mp] 1)); |
293 by (REPEAT (eresolve_tac [asm_rl, bspec RS bspec RS mp] 1)); |
283 by (asm_simp_tac (FOL_ss addsimps [comp_func_apply]) 1); |
294 by (asm_simp_tac (FOL_ss addsimps [comp_fun_apply]) 1); |
284 val comp_mem_injD2 = result(); |
295 val comp_mem_injD2 = result(); |
285 |
296 |
286 goalw Perm.thy [surj_def] |
297 goalw Perm.thy [surj_def] |
287 "!!f g. [| (f O g): surj(A,C); g: A->B; f: B->C |] ==> f: surj(B,C)"; |
298 "!!f g. [| (f O g): surj(A,C); g: A->B; f: B->C |] ==> f: surj(B,C)"; |
288 by (fast_tac (comp_cs addSIs [comp_func_apply RS sym, apply_type]) 1); |
299 by (fast_tac (comp_cs addSIs [comp_fun_apply RS sym, apply_type]) 1); |
289 val comp_mem_surjD1 = result(); |
300 val comp_mem_surjD1 = result(); |
290 |
301 |
291 goal Perm.thy |
302 goal Perm.thy |
292 "!!f g. [| (f O g)`a = c; g: A->B; f: B->C; a:A |] ==> f`(g`a) = c"; |
303 "!!f g. [| (f O g)`a = c; g: A->B; f: B->C; a:A |] ==> f`(g`a) = c"; |
293 by (REPEAT (ares_tac [comp_func_apply RS sym RS trans] 1)); |
304 by (REPEAT (ares_tac [comp_fun_apply RS sym RS trans] 1)); |
294 val comp_func_applyD = result(); |
305 val comp_fun_applyD = result(); |
295 |
306 |
296 goalw Perm.thy [inj_def,surj_def] |
307 goalw Perm.thy [inj_def,surj_def] |
297 "!!f g. [| (f O g): surj(A,C); g: A->B; f: inj(B,C) |] ==> g: surj(A,B)"; |
308 "!!f g. [| (f O g): surj(A,C); g: A->B; f: inj(B,C) |] ==> g: surj(A,B)"; |
298 by (safe_tac comp_cs); |
309 by (safe_tac comp_cs); |
299 by (eres_inst_tac [("x1", "f`y")] (bspec RS bexE) 1); |
310 by (eres_inst_tac [("x1", "f`y")] (bspec RS bexE) 1); |
300 by (REPEAT (ares_tac [apply_type] 1 ORELSE dtac comp_func_applyD 1)); |
311 by (REPEAT (ares_tac [apply_type] 1 ORELSE dtac comp_fun_applyD 1)); |
301 by (best_tac (comp_cs addSIs [apply_type]) 1); |
312 by (best_tac (comp_cs addSIs [apply_type]) 1); |
302 val comp_mem_surjD2 = result(); |
313 val comp_mem_surjD2 = result(); |
303 |
314 |
304 |
315 |
305 (** inverses of composition **) |
316 (** inverses of composition **) |
322 by (cut_facts_tac [prem] 1); |
333 by (cut_facts_tac [prem] 1); |
323 by (rtac equalityI 1); |
334 by (rtac equalityI 1); |
324 by (best_tac (comp_cs addEs [domain_type, range_type, make_elim appfD]) 1); |
335 by (best_tac (comp_cs addEs [domain_type, range_type, make_elim appfD]) 1); |
325 by (best_tac (comp_cs addIs [apply_Pair]) 1); |
336 by (best_tac (comp_cs addIs [apply_Pair]) 1); |
326 val right_comp_inverse = result(); |
337 val right_comp_inverse = result(); |
|
338 |
|
339 (** Proving that a function is a bijection **) |
|
340 |
|
341 val prems = |
|
342 goalw Perm.thy [bij_def, inj_def, surj_def] |
|
343 "[| !!x. x:A ==> c(x): B; \ |
|
344 \ !!y. y:B ==> d(y): A; \ |
|
345 \ !!x. x:A ==> d(c(x)) = x; \ |
|
346 \ !!y. y:B ==> c(d(y)) = y \ |
|
347 \ |] ==> (lam x:A.c(x)) : bij(A,B)"; |
|
348 by (simp_tac (ZF_ss addsimps ([lam_type]@prems)) 1); |
|
349 by (safe_tac ZF_cs); |
|
350 (*Apply d to both sides then simplify (type constraint is essential) *) |
|
351 by (dres_inst_tac [("t", "d::i=>i")] subst_context 1); |
|
352 by (asm_full_simp_tac (ZF_ss addsimps prems) 1); |
|
353 by (fast_tac (ZF_cs addIs prems) 1); |
|
354 val lam_bijective = result(); |
|
355 |
|
356 goalw Perm.thy [id_def] |
|
357 "!!f A B. [| f: A->B; g: B->A |] ==> \ |
|
358 \ f O g = id(B) <-> (ALL y:B. f`(g`y)=y)"; |
|
359 by (safe_tac ZF_cs); |
|
360 by (dres_inst_tac [("t", "%h.h`y ")] subst_context 1); |
|
361 by (asm_full_simp_tac (ZF_ss addsimps [comp_fun_apply]) 1); |
|
362 br fun_extension 1; |
|
363 by (REPEAT (ares_tac [comp_fun, lam_type] 1)); |
|
364 by (asm_simp_tac (ZF_ss addsimps [comp_fun_apply]) 1); |
|
365 val comp_eq_id_iff = result(); |
|
366 |
|
367 goalw Perm.thy [bij_def, inj_def, surj_def] |
|
368 "!!f A B. [| f: A->B; g: B->A; f O g = id(B); g O f = id(A) \ |
|
369 \ |] ==> f : bij(A,B)"; |
|
370 by (asm_full_simp_tac (ZF_ss addsimps [comp_eq_id_iff]) 1); |
|
371 by (safe_tac ZF_cs); |
|
372 (*Apply g to both sides then simplify*) |
|
373 by (dres_inst_tac [("t", "op `(g)"), ("a", "f`x")] subst_context 1); |
|
374 by (asm_full_simp_tac ZF_ss 1); |
|
375 by (fast_tac (ZF_cs addIs [apply_type]) 1); |
|
376 val fg_imp_bijective = result(); |
|
377 |
|
378 goal Perm.thy "!!f A. [| f: A->A; f O f = id(A) |] ==> f : bij(A,A)"; |
|
379 by (REPEAT (ares_tac [fg_imp_bijective] 1)); |
|
380 val nilpotent_imp_bijective = result(); |
327 |
381 |
328 (*Injective case applies converse(f) to both sides then simplifies |
382 (*Injective case applies converse(f) to both sides then simplifies |
329 using left_inverse_lemma*) |
383 using left_inverse_lemma*) |
330 goalw Perm.thy [bij_def,inj_def,surj_def] |
384 goalw Perm.thy [bij_def,inj_def,surj_def] |
331 "!!f A B. [| converse(f): B->A; f: A->B |] ==> f : bij(A,B)"; |
385 "!!f A B. [| converse(f): B->A; f: A->B |] ==> f : bij(A,B)"; |