11 section "Relating predicates and sets"; |
11 section "Relating predicates and sets"; |
12 |
12 |
13 Addsimps [Collect_mem_eq]; |
13 Addsimps [Collect_mem_eq]; |
14 AddIffs [mem_Collect_eq]; |
14 AddIffs [mem_Collect_eq]; |
15 |
15 |
16 goal Set.thy "!!a. P(a) ==> a : {x. P(x)}"; |
16 Goal "!!a. P(a) ==> a : {x. P(x)}"; |
17 by (Asm_simp_tac 1); |
17 by (Asm_simp_tac 1); |
18 qed "CollectI"; |
18 qed "CollectI"; |
19 |
19 |
20 val prems = goal Set.thy "!!a. a : {x. P(x)} ==> P(a)"; |
20 val prems = goal Set.thy "!!a. a : {x. P(x)} ==> P(a)"; |
21 by (Asm_full_simp_tac 1); |
21 by (Asm_full_simp_tac 1); |
80 |
80 |
81 AddIs [bexI]; |
81 AddIs [bexI]; |
82 AddSEs [bexE]; |
82 AddSEs [bexE]; |
83 |
83 |
84 (*Trival rewrite rule*) |
84 (*Trival rewrite rule*) |
85 goal Set.thy "(! x:A. P) = ((? x. x:A) --> P)"; |
85 Goal "(! x:A. P) = ((? x. x:A) --> P)"; |
86 by (simp_tac (simpset() addsimps [Ball_def]) 1); |
86 by (simp_tac (simpset() addsimps [Ball_def]) 1); |
87 qed "ball_triv"; |
87 qed "ball_triv"; |
88 |
88 |
89 (*Dual form for existentials*) |
89 (*Dual form for existentials*) |
90 goal Set.thy "(? x:A. P) = ((? x. x:A) & P)"; |
90 Goal "(? x:A. P) = ((? x. x:A) & P)"; |
91 by (simp_tac (simpset() addsimps [Bex_def]) 1); |
91 by (simp_tac (simpset() addsimps [Bex_def]) 1); |
92 qed "bex_triv"; |
92 qed "bex_triv"; |
93 |
93 |
94 Addsimps [ball_triv, bex_triv]; |
94 Addsimps [ball_triv, bex_triv]; |
95 |
95 |
225 (fn _ => [rtac subsetI 1, rtac UNIV_I 1]); |
225 (fn _ => [rtac subsetI 1, rtac UNIV_I 1]); |
226 |
226 |
227 (** Eta-contracting these two rules (to remove P) causes them to be ignored |
227 (** Eta-contracting these two rules (to remove P) causes them to be ignored |
228 because of their interaction with congruence rules. **) |
228 because of their interaction with congruence rules. **) |
229 |
229 |
230 goalw Set.thy [Ball_def] "Ball UNIV P = All P"; |
230 Goalw [Ball_def] "Ball UNIV P = All P"; |
231 by (Simp_tac 1); |
231 by (Simp_tac 1); |
232 qed "ball_UNIV"; |
232 qed "ball_UNIV"; |
233 |
233 |
234 goalw Set.thy [Bex_def] "Bex UNIV P = Ex P"; |
234 Goalw [Bex_def] "Bex UNIV P = Ex P"; |
235 by (Simp_tac 1); |
235 by (Simp_tac 1); |
236 qed "bex_UNIV"; |
236 qed "bex_UNIV"; |
237 Addsimps [ball_UNIV, bex_UNIV]; |
237 Addsimps [ball_UNIV, bex_UNIV]; |
238 |
238 |
239 |
239 |
257 [ (blast_tac (claset() addIs [prem RS FalseE]) 1) ]); |
257 [ (blast_tac (claset() addIs [prem RS FalseE]) 1) ]); |
258 |
258 |
259 qed_goal "equals0D" Set.thy "!!a. [| A={}; a:A |] ==> P" |
259 qed_goal "equals0D" Set.thy "!!a. [| A={}; a:A |] ==> P" |
260 (fn _ => [ (Blast_tac 1) ]); |
260 (fn _ => [ (Blast_tac 1) ]); |
261 |
261 |
262 goalw Set.thy [Ball_def] "Ball {} P = True"; |
262 Goalw [Ball_def] "Ball {} P = True"; |
263 by (Simp_tac 1); |
263 by (Simp_tac 1); |
264 qed "ball_empty"; |
264 qed "ball_empty"; |
265 |
265 |
266 goalw Set.thy [Bex_def] "Bex {} P = False"; |
266 Goalw [Bex_def] "Bex {} P = False"; |
267 by (Simp_tac 1); |
267 by (Simp_tac 1); |
268 qed "bex_empty"; |
268 qed "bex_empty"; |
269 Addsimps [ball_empty, bex_empty]; |
269 Addsimps [ball_empty, bex_empty]; |
270 |
270 |
271 goal thy "UNIV ~= {}"; |
271 Goal "UNIV ~= {}"; |
272 by (blast_tac (claset() addEs [equalityE]) 1); |
272 by (blast_tac (claset() addEs [equalityE]) 1); |
273 qed "UNIV_not_empty"; |
273 qed "UNIV_not_empty"; |
274 AddIffs [UNIV_not_empty]; |
274 AddIffs [UNIV_not_empty]; |
275 |
275 |
276 |
276 |
323 qed_goalw "Un_iff" Set.thy [Un_def] "(c : A Un B) = (c:A | c:B)" |
323 qed_goalw "Un_iff" Set.thy [Un_def] "(c : A Un B) = (c:A | c:B)" |
324 (fn _ => [ Blast_tac 1 ]); |
324 (fn _ => [ Blast_tac 1 ]); |
325 |
325 |
326 Addsimps [Un_iff]; |
326 Addsimps [Un_iff]; |
327 |
327 |
328 goal Set.thy "!!c. c:A ==> c : A Un B"; |
328 Goal "!!c. c:A ==> c : A Un B"; |
329 by (Asm_simp_tac 1); |
329 by (Asm_simp_tac 1); |
330 qed "UnI1"; |
330 qed "UnI1"; |
331 |
331 |
332 goal Set.thy "!!c. c:B ==> c : A Un B"; |
332 Goal "!!c. c:B ==> c : A Un B"; |
333 by (Asm_simp_tac 1); |
333 by (Asm_simp_tac 1); |
334 qed "UnI2"; |
334 qed "UnI2"; |
335 |
335 |
336 (*Classical introduction rule: no commitment to A vs B*) |
336 (*Classical introduction rule: no commitment to A vs B*) |
337 qed_goal "UnCI" Set.thy "(c~:B ==> c:A) ==> c : A Un B" |
337 qed_goal "UnCI" Set.thy "(c~:B ==> c:A) ==> c : A Un B" |
354 qed_goalw "Int_iff" Set.thy [Int_def] "(c : A Int B) = (c:A & c:B)" |
354 qed_goalw "Int_iff" Set.thy [Int_def] "(c : A Int B) = (c:A & c:B)" |
355 (fn _ => [ (Blast_tac 1) ]); |
355 (fn _ => [ (Blast_tac 1) ]); |
356 |
356 |
357 Addsimps [Int_iff]; |
357 Addsimps [Int_iff]; |
358 |
358 |
359 goal Set.thy "!!c. [| c:A; c:B |] ==> c : A Int B"; |
359 Goal "!!c. [| c:A; c:B |] ==> c : A Int B"; |
360 by (Asm_simp_tac 1); |
360 by (Asm_simp_tac 1); |
361 qed "IntI"; |
361 qed "IntI"; |
362 |
362 |
363 goal Set.thy "!!c. c : A Int B ==> c:A"; |
363 Goal "!!c. c : A Int B ==> c:A"; |
364 by (Asm_full_simp_tac 1); |
364 by (Asm_full_simp_tac 1); |
365 qed "IntD1"; |
365 qed "IntD1"; |
366 |
366 |
367 goal Set.thy "!!c. c : A Int B ==> c:B"; |
367 Goal "!!c. c : A Int B ==> c:B"; |
368 by (Asm_full_simp_tac 1); |
368 by (Asm_full_simp_tac 1); |
369 qed "IntD2"; |
369 qed "IntD2"; |
370 |
370 |
371 val [major,minor] = goal Set.thy |
371 val [major,minor] = goal Set.thy |
372 "[| c : A Int B; [| c:A; c:B |] ==> P |] ==> P"; |
372 "[| c : A Int B; [| c:A; c:B |] ==> P |] ==> P"; |
434 section "Singletons, using insert"; |
434 section "Singletons, using insert"; |
435 |
435 |
436 qed_goal "singletonI" Set.thy "a : {a}" |
436 qed_goal "singletonI" Set.thy "a : {a}" |
437 (fn _=> [ (rtac insertI1 1) ]); |
437 (fn _=> [ (rtac insertI1 1) ]); |
438 |
438 |
439 goal Set.thy "!!a. b : {a} ==> b=a"; |
439 Goal "!!a. b : {a} ==> b=a"; |
440 by (Blast_tac 1); |
440 by (Blast_tac 1); |
441 qed "singletonD"; |
441 qed "singletonD"; |
442 |
442 |
443 bind_thm ("singletonE", make_elim singletonD); |
443 bind_thm ("singletonE", make_elim singletonD); |
444 |
444 |
445 qed_goal "singleton_iff" thy "(b : {a}) = (b=a)" |
445 qed_goal "singleton_iff" thy "(b : {a}) = (b=a)" |
446 (fn _ => [Blast_tac 1]); |
446 (fn _ => [Blast_tac 1]); |
447 |
447 |
448 goal Set.thy "!!a b. {a}={b} ==> a=b"; |
448 Goal "!!a b. {a}={b} ==> a=b"; |
449 by (blast_tac (claset() addEs [equalityE]) 1); |
449 by (blast_tac (claset() addEs [equalityE]) 1); |
450 qed "singleton_inject"; |
450 qed "singleton_inject"; |
451 |
451 |
452 (*Redundant? But unlike insertCI, it proves the subgoal immediately!*) |
452 (*Redundant? But unlike insertCI, it proves the subgoal immediately!*) |
453 AddSIs [singletonI]; |
453 AddSIs [singletonI]; |
454 AddSDs [singleton_inject]; |
454 AddSDs [singleton_inject]; |
455 AddSEs [singletonE]; |
455 AddSEs [singletonE]; |
456 |
456 |
457 goal Set.thy "{x. x=a} = {a}"; |
457 Goal "{x. x=a} = {a}"; |
458 by (Blast_tac 1); |
458 by (Blast_tac 1); |
459 qed "singleton_conv"; |
459 qed "singleton_conv"; |
460 Addsimps [singleton_conv]; |
460 Addsimps [singleton_conv]; |
461 |
461 |
462 |
462 |
463 section "Unions of families -- UNION x:A. B(x) is Union(B``A)"; |
463 section "Unions of families -- UNION x:A. B(x) is Union(B``A)"; |
464 |
464 |
465 goalw Set.thy [UNION_def] "(b: (UN x:A. B(x))) = (EX x:A. b: B(x))"; |
465 Goalw [UNION_def] "(b: (UN x:A. B(x))) = (EX x:A. b: B(x))"; |
466 by (Blast_tac 1); |
466 by (Blast_tac 1); |
467 qed "UN_iff"; |
467 qed "UN_iff"; |
468 |
468 |
469 Addsimps [UN_iff]; |
469 Addsimps [UN_iff]; |
470 |
470 |
471 (*The order of the premises presupposes that A is rigid; b may be flexible*) |
471 (*The order of the premises presupposes that A is rigid; b may be flexible*) |
472 goal Set.thy "!!b. [| a:A; b: B(a) |] ==> b: (UN x:A. B(x))"; |
472 Goal "!!b. [| a:A; b: B(a) |] ==> b: (UN x:A. B(x))"; |
473 by Auto_tac; |
473 by Auto_tac; |
474 qed "UN_I"; |
474 qed "UN_I"; |
475 |
475 |
476 val major::prems = goalw Set.thy [UNION_def] |
476 val major::prems = goalw Set.thy [UNION_def] |
477 "[| b : (UN x:A. B(x)); !!x.[| x:A; b: B(x) |] ==> R |] ==> R"; |
477 "[| b : (UN x:A. B(x)); !!x.[| x:A; b: B(x) |] ==> R |] ==> R"; |
491 qed "UN_cong"; |
491 qed "UN_cong"; |
492 |
492 |
493 |
493 |
494 section "Intersections of families -- INTER x:A. B(x) is Inter(B``A)"; |
494 section "Intersections of families -- INTER x:A. B(x) is Inter(B``A)"; |
495 |
495 |
496 goalw Set.thy [INTER_def] "(b: (INT x:A. B(x))) = (ALL x:A. b: B(x))"; |
496 Goalw [INTER_def] "(b: (INT x:A. B(x))) = (ALL x:A. b: B(x))"; |
497 by Auto_tac; |
497 by Auto_tac; |
498 qed "INT_iff"; |
498 qed "INT_iff"; |
499 |
499 |
500 Addsimps [INT_iff]; |
500 Addsimps [INT_iff]; |
501 |
501 |
502 val prems = goalw Set.thy [INTER_def] |
502 val prems = goalw Set.thy [INTER_def] |
503 "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))"; |
503 "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))"; |
504 by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1)); |
504 by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1)); |
505 qed "INT_I"; |
505 qed "INT_I"; |
506 |
506 |
507 goal Set.thy "!!b. [| b : (INT x:A. B(x)); a:A |] ==> b: B(a)"; |
507 Goal "!!b. [| b : (INT x:A. B(x)); a:A |] ==> b: B(a)"; |
508 by Auto_tac; |
508 by Auto_tac; |
509 qed "INT_D"; |
509 qed "INT_D"; |
510 |
510 |
511 (*"Classical" elimination -- by the Excluded Middle on a:A *) |
511 (*"Classical" elimination -- by the Excluded Middle on a:A *) |
512 val major::prems = goalw Set.thy [INTER_def] |
512 val major::prems = goalw Set.thy [INTER_def] |
527 qed "INT_cong"; |
527 qed "INT_cong"; |
528 |
528 |
529 |
529 |
530 section "Union"; |
530 section "Union"; |
531 |
531 |
532 goalw Set.thy [Union_def] "(A : Union(C)) = (EX X:C. A:X)"; |
532 Goalw [Union_def] "(A : Union(C)) = (EX X:C. A:X)"; |
533 by (Blast_tac 1); |
533 by (Blast_tac 1); |
534 qed "Union_iff"; |
534 qed "Union_iff"; |
535 |
535 |
536 Addsimps [Union_iff]; |
536 Addsimps [Union_iff]; |
537 |
537 |
538 (*The order of the premises presupposes that C is rigid; A may be flexible*) |
538 (*The order of the premises presupposes that C is rigid; A may be flexible*) |
539 goal Set.thy "!!X. [| X:C; A:X |] ==> A : Union(C)"; |
539 Goal "!!X. [| X:C; A:X |] ==> A : Union(C)"; |
540 by Auto_tac; |
540 by Auto_tac; |
541 qed "UnionI"; |
541 qed "UnionI"; |
542 |
542 |
543 val major::prems = goalw Set.thy [Union_def] |
543 val major::prems = goalw Set.thy [Union_def] |
544 "[| A : Union(C); !!X.[| A:X; X:C |] ==> R |] ==> R"; |
544 "[| A : Union(C); !!X.[| A:X; X:C |] ==> R |] ==> R"; |
563 by (REPEAT (ares_tac ([INT_I] @ prems) 1)); |
563 by (REPEAT (ares_tac ([INT_I] @ prems) 1)); |
564 qed "InterI"; |
564 qed "InterI"; |
565 |
565 |
566 (*A "destruct" rule -- every X in C contains A as an element, but |
566 (*A "destruct" rule -- every X in C contains A as an element, but |
567 A:X can hold when X:C does not! This rule is analogous to "spec". *) |
567 A:X can hold when X:C does not! This rule is analogous to "spec". *) |
568 goal Set.thy "!!X. [| A : Inter(C); X:C |] ==> A:X"; |
568 Goal "!!X. [| A : Inter(C); X:C |] ==> A:X"; |
569 by Auto_tac; |
569 by Auto_tac; |
570 qed "InterD"; |
570 qed "InterD"; |
571 |
571 |
572 (*"Classical" elimination rule -- does not require proving X:C *) |
572 (*"Classical" elimination rule -- does not require proving X:C *) |
573 val major::prems = goalw Set.thy [Inter_def] |
573 val major::prems = goalw Set.thy [Inter_def] |
598 qed "imageE"; |
598 qed "imageE"; |
599 |
599 |
600 AddIs [image_eqI]; |
600 AddIs [image_eqI]; |
601 AddSEs [imageE]; |
601 AddSEs [imageE]; |
602 |
602 |
603 goalw thy [o_def] "(f o g)``r = f``(g``r)"; |
603 Goalw [o_def] "(f o g)``r = f``(g``r)"; |
604 by (Blast_tac 1); |
604 by (Blast_tac 1); |
605 qed "image_compose"; |
605 qed "image_compose"; |
606 |
606 |
607 goal thy "f``(A Un B) = f``A Un f``B"; |
607 Goal "f``(A Un B) = f``A Un f``B"; |
608 by (Blast_tac 1); |
608 by (Blast_tac 1); |
609 qed "image_Un"; |
609 qed "image_Un"; |
610 |
610 |
611 goal thy "(z : f``A) = (EX x:A. z = f x)"; |
611 Goal "(z : f``A) = (EX x:A. z = f x)"; |
612 by (Blast_tac 1); |
612 by (Blast_tac 1); |
613 qed "image_iff"; |
613 qed "image_iff"; |
614 |
614 |
615 (*This rewrite rule would confuse users if made default.*) |
615 (*This rewrite rule would confuse users if made default.*) |
616 goal thy "(f``A <= B) = (ALL x:A. f(x): B)"; |
616 Goal "(f``A <= B) = (ALL x:A. f(x): B)"; |
617 by (Blast_tac 1); |
617 by (Blast_tac 1); |
618 qed "image_subset_iff"; |
618 qed "image_subset_iff"; |
619 |
619 |
620 (*Replaces the three steps subsetI, imageE, hyp_subst_tac, but breaks too |
620 (*Replaces the three steps subsetI, imageE, hyp_subst_tac, but breaks too |
621 many existing proofs.*) |
621 many existing proofs.*) |
624 qed "image_subsetI"; |
624 qed "image_subsetI"; |
625 |
625 |
626 |
626 |
627 (*** Range of a function -- just a translation for image! ***) |
627 (*** Range of a function -- just a translation for image! ***) |
628 |
628 |
629 goal thy "!!b. b=f(x) ==> b : range(f)"; |
629 Goal "!!b. b=f(x) ==> b : range(f)"; |
630 by (EVERY1 [etac image_eqI, rtac UNIV_I]); |
630 by (EVERY1 [etac image_eqI, rtac UNIV_I]); |
631 bind_thm ("range_eqI", UNIV_I RSN (2,image_eqI)); |
631 bind_thm ("range_eqI", UNIV_I RSN (2,image_eqI)); |
632 |
632 |
633 bind_thm ("rangeI", UNIV_I RS imageI); |
633 bind_thm ("rangeI", UNIV_I RS imageI); |
634 |
634 |
661 (*Each of these has ALREADY been added to simpset() above.*) |
661 (*Each of these has ALREADY been added to simpset() above.*) |
662 val mem_simps = [insert_iff, empty_iff, Un_iff, Int_iff, Compl_iff, Diff_iff, |
662 val mem_simps = [insert_iff, empty_iff, Un_iff, Int_iff, Compl_iff, Diff_iff, |
663 mem_Collect_eq, UN_iff, Union_iff, INT_iff, Inter_iff]; |
663 mem_Collect_eq, UN_iff, Union_iff, INT_iff, Inter_iff]; |
664 |
664 |
665 (*Not for Addsimps -- it can cause goals to blow up!*) |
665 (*Not for Addsimps -- it can cause goals to blow up!*) |
666 goal Set.thy "(a : (if Q then x else y)) = ((Q --> a:x) & (~Q --> a : y))"; |
666 Goal "(a : (if Q then x else y)) = ((Q --> a:x) & (~Q --> a : y))"; |
667 by (Simp_tac 1); |
667 by (Simp_tac 1); |
668 qed "mem_if"; |
668 qed "mem_if"; |
669 |
669 |
670 val mksimps_pairs = ("Ball",[bspec]) :: mksimps_pairs; |
670 val mksimps_pairs = ("Ball",[bspec]) :: mksimps_pairs; |
671 |
671 |
675 Addsimps[subset_UNIV, empty_subsetI, subset_refl]; |
675 Addsimps[subset_UNIV, empty_subsetI, subset_refl]; |
676 |
676 |
677 |
677 |
678 (*** < ***) |
678 (*** < ***) |
679 |
679 |
680 goalw Set.thy [psubset_def] "!!A::'a set. [| A <= B; A ~= B |] ==> A<B"; |
680 Goalw [psubset_def] "!!A::'a set. [| A <= B; A ~= B |] ==> A<B"; |
681 by (Blast_tac 1); |
681 by (Blast_tac 1); |
682 qed "psubsetI"; |
682 qed "psubsetI"; |
683 |
683 |
684 goalw Set.thy [psubset_def] |
684 Goalw [psubset_def] |
685 "!!x. A < insert x B ==> (x ~: A) & A<=B | x:A & A-{x}<B"; |
685 "!!x. A < insert x B ==> (x ~: A) & A<=B | x:A & A-{x}<B"; |
686 by Auto_tac; |
686 by Auto_tac; |
687 qed "psubset_insertD"; |
687 qed "psubset_insertD"; |
688 |
688 |
689 bind_thm ("psubset_eq", psubset_def RS meta_eq_to_obj_eq); |
689 bind_thm ("psubset_eq", psubset_def RS meta_eq_to_obj_eq); |