1 (* Title: HOL/equalities
3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory
4 Copyright 1994 University of Cambridge
6 Equalities involving union, intersection, inclusion, etc.
9 writeln"File HOL/equalities";
15 (*supersedes Collect_False_empty*)
16 Goal "{s. P} = (if P then UNIV else {})";
19 Addsimps [Collect_const];
21 Goal "(A <= {}) = (A = {})";
24 Addsimps [subset_empty];
26 Goalw [psubset_def] "~ (A < {})";
28 qed "not_psubset_empty";
29 AddIffs [not_psubset_empty];
31 Goal "(Collect P = {}) = (!x. ~ P x)";
33 qed "Collect_empty_eq";
34 Addsimps[Collect_empty_eq];
36 Goal "{x. P x | Q x} = {x. P x} Un {x. Q x}";
38 qed "Collect_disj_eq";
40 Goal "{x. P x & Q x} = {x. P x} Int {x. Q x}";
42 qed "Collect_conj_eq";
44 Goal "{x. ALL y. P x y} = (INT y. {x. P x y})";
48 Goal "{x. ALL y: A. P x y} = (INT y: A. {x. P x y})";
50 qed "Collect_ball_eq";
52 Goal "{x. EX y. P x y} = (UN y. {x. P x y})";
56 Goal "{x. EX y: A. P x y} = (UN y: A. {x. P x y})";
63 (*NOT SUITABLE FOR REWRITING since {a} == insert a {}*)
64 Goal "insert a A = {a} Un A";
68 Goal "insert a A ~= {}";
69 by (blast_tac (claset() addEs [equalityCE]) 1);
70 qed"insert_not_empty";
71 Addsimps[insert_not_empty];
73 bind_thm("empty_not_insert",insert_not_empty RS not_sym);
74 Addsimps[empty_not_insert];
76 Goal "a:A ==> insert a A = A";
79 (* Addsimps [insert_absorb] causes recursive calls
80 when there are nested inserts, with QUADRATIC running time
83 Goal "insert x (insert x A) = insert x A";
86 Addsimps [insert_absorb2];
88 Goal "insert x (insert y A) = insert y (insert x A)";
92 Goal "(insert x A <= B) = (x:B & A <= B)";
95 Addsimps[insert_subset];
97 Goal "insert a A ~= insert a B ==> A ~= B";
101 (* use new B rather than (A-{a}) to avoid infinite unfolding *)
102 Goal "a:A ==> ? B. A = insert a B & a ~: B";
103 by (res_inst_tac [("x","A-{a}")] exI 1);
105 qed "mk_disjoint_insert";
107 bind_thm ("insert_Collect", prove_goal thy
108 "insert a (Collect P) = {u. u ~= a --> P u}" (K [Auto_tac]));
110 Goal "u: A ==> (UN x:A. insert a (B x)) = insert a (UN x:A. B x)";
112 qed "UN_insert_distrib";
119 Addsimps[image_empty];
121 Goal "f``insert a B = insert (f a) (f``B)";
124 Addsimps[image_insert];
126 Goal "x:A ==> (%x. c) `` A = {c}";
128 qed "image_constant";
130 Goal "f``(g``A) = (%x. f (g x)) `` A";
134 Goal "x:A ==> insert (f x) (f``A) = f``A";
137 Addsimps [insert_image];
139 Goal "(f``A = {}) = (A = {})";
140 by (blast_tac (claset() addSEs [equalityCE]) 1);
141 qed "image_is_empty";
142 AddIffs [image_is_empty];
144 Goal "f `` {x. P x} = {f x | x. P x}";
147 Addsimps [image_Collect];
149 Goalw [image_def] "(%x. if P x then f x else g x) `` S \
150 \ = (f `` (S Int {x. P x})) Un (g `` (S Int {x. ~(P x)}))";
153 qed "if_image_distrib";
154 Addsimps[if_image_distrib];
156 val prems = Goal "[|M = N; !!x. x:N ==> f x = g x|] ==> f``M = g``N";
157 by (simp_tac (simpset() addsimps image_def::prems) 1);
163 Goal "{u. ? x. u = f x} = range f";
165 qed "full_SetCompr_eq";
173 Addsimps[Int_absorb];
175 Goal "A Int (A Int B) = A Int B";
177 qed "Int_left_absorb";
179 Goal "A Int B = B Int A";
183 Goal "A Int (B Int C) = B Int (A Int C)";
185 qed "Int_left_commute";
187 Goal "(A Int B) Int C = A Int (B Int C)";
191 (*Intersection is an AC-operator*)
192 bind_thms ("Int_ac", [Int_assoc, Int_left_absorb, Int_commute, Int_left_commute]);
194 Goal "B<=A ==> A Int B = B";
198 Goal "A<=B ==> A Int B = A";
202 Goal "{} Int B = {}";
204 qed "Int_empty_left";
205 Addsimps[Int_empty_left];
207 Goal "A Int {} = {}";
209 qed "Int_empty_right";
210 Addsimps[Int_empty_right];
212 Goal "(A Int B = {}) = (A <= -B)";
213 by (blast_tac (claset() addSEs [equalityCE]) 1);
214 qed "disjoint_eq_subset_Compl";
216 Goal "(A Int B = {}) = (ALL x:A. ALL y:B. x ~= y)";
218 qed "disjoint_iff_not_equal";
220 Goal "UNIV Int B = B";
223 Addsimps[Int_UNIV_left];
225 Goal "A Int UNIV = A";
227 qed "Int_UNIV_right";
228 Addsimps[Int_UNIV_right];
230 Goal "A Int B = Inter{A,B}";
234 Goal "A Int (B Un C) = (A Int B) Un (A Int C)";
236 qed "Int_Un_distrib";
238 Goal "(B Un C) Int A = (B Int A) Un (C Int A)";
240 qed "Int_Un_distrib2";
242 Goal "(A Int B = UNIV) = (A = UNIV & B = UNIV)";
243 by (blast_tac (claset() addEs [equalityCE]) 1);
247 Goal "(C <= A Int B) = (C <= A & C <= B)";
249 qed "Int_subset_iff";
251 Goal "(x : A Int {x. P x}) = (x : A & P x)";
262 Goal " A Un (A Un B) = A Un B";
264 qed "Un_left_absorb";
266 Goal "A Un B = B Un A";
270 Goal "A Un (B Un C) = B Un (A Un C)";
272 qed "Un_left_commute";
274 Goal "(A Un B) Un C = A Un (B Un C)";
278 (*Union is an AC-operator*)
279 bind_thms ("Un_ac", [Un_assoc, Un_left_absorb, Un_commute, Un_left_commute]);
281 Goal "A<=B ==> A Un B = B";
285 Goal "B<=A ==> A Un B = A";
292 Addsimps[Un_empty_left];
296 qed "Un_empty_right";
297 Addsimps[Un_empty_right];
299 Goal "UNIV Un B = UNIV";
302 Addsimps[Un_UNIV_left];
304 Goal "A Un UNIV = UNIV";
307 Addsimps[Un_UNIV_right];
309 Goal "A Un B = Union{A,B}";
313 Goal "(insert a B) Un C = insert a (B Un C)";
315 qed "Un_insert_left";
316 Addsimps[Un_insert_left];
318 Goal "A Un (insert a B) = insert a (A Un B)";
320 qed "Un_insert_right";
321 Addsimps[Un_insert_right];
323 Goal "(insert a B) Int C = (if a:C then insert a (B Int C) \
327 qed "Int_insert_left";
329 Goal "A Int (insert a B) = (if a:A then insert a (A Int B) \
333 qed "Int_insert_right";
335 Goal "A Un (B Int C) = (A Un B) Int (A Un C)";
337 qed "Un_Int_distrib";
339 Goal "(B Int C) Un A = (B Un A) Int (C Un A)";
341 qed "Un_Int_distrib2";
343 Goal "(A Int B) Un (B Int C) Un (C Int A) = \
344 \ (A Un B) Int (B Un C) Int (C Un A)";
348 Goal "(A<=B) = (A Un B = B)";
349 by (blast_tac (claset() addSEs [equalityCE]) 1);
352 Goal "(A <= insert b C) = (A <= C | b:A & A-{b} <= C)";
354 qed "subset_insert_iff";
356 Goal "(A Un B = {}) = (A = {} & B = {})";
357 by (blast_tac (claset() addEs [equalityCE]) 1);
361 Goal "(A Un B <= C) = (A <= C & B <= C)";
365 Goal "(A - B) Un (A Int B) = A";
370 section "Set complement";
372 Goal "A Int (-A) = {}";
374 qed "Compl_disjoint";
375 Addsimps[Compl_disjoint];
377 Goal "A Un (-A) = UNIV";
379 qed "Compl_partition";
381 Goal "- (-A) = (A:: 'a set)";
383 qed "double_complement";
384 Addsimps[double_complement];
386 Goal "-(A Un B) = (-A) Int (-B)";
390 Goal "-(A Int B) = (-A) Un (-B)";
394 Goal "-(UN x:A. B(x)) = (INT x:A. -B(x))";
398 Goal "-(INT x:A. B(x)) = (UN x:A. -B(x))";
402 Addsimps [Compl_Un, Compl_Int, Compl_UN, Compl_INT];
404 (*Halmos, Naive Set Theory, page 16.*)
406 Goal "((A Int B) Un C = A Int (B Un C)) = (C<=A)";
407 by (blast_tac (claset() addSEs [equalityCE]) 1);
408 qed "Un_Int_assoc_eq";
413 Goal "Union({}) = {}";
416 Addsimps[Union_empty];
418 Goal "Union(UNIV) = UNIV";
421 Addsimps[Union_UNIV];
423 Goal "Union(insert a B) = a Un Union(B)";
426 Addsimps[Union_insert];
428 Goal "Union(A Un B) = Union(A) Un Union(B)";
430 qed "Union_Un_distrib";
431 Addsimps[Union_Un_distrib];
433 Goal "Union(A Int B) <= Union(A) Int Union(B)";
435 qed "Union_Int_subset";
437 Goal "(Union M = {}) = (! A : M. A = {})";
438 by (blast_tac (claset() addEs [equalityCE]) 1);
439 qed "Union_empty_conv";
440 AddIffs [Union_empty_conv];
442 Goal "(Union(C) Int A = {}) = (! B:C. B Int A = {})";
443 by (blast_tac (claset() addSEs [equalityCE]) 1);
444 qed "Union_disjoint";
448 Goal "Inter({}) = UNIV";
451 Addsimps[Inter_empty];
453 Goal "Inter(UNIV) = {}";
456 Addsimps[Inter_UNIV];
458 Goal "Inter(insert a B) = a Int Inter(B)";
461 Addsimps[Inter_insert];
463 Goal "Inter(A) Un Inter(B) <= Inter(A Int B)";
465 qed "Inter_Un_subset";
467 Goal "Inter(A Un B) = Inter(A) Int Inter(B)";
469 qed "Inter_Un_distrib";
471 section "UN and INT";
475 bind_thm ("not_empty", prove_goal thy "(A ~= {}) = (? x. x:A)" (K [Blast_tac 1]));
477 Goal "(UN x:{}. B x) = {}";
482 Goal "(UN x:A. {}) = {}";
487 Goal "(UN x:A. {x}) = A";
490 Addsimps [UN_singleton];
492 Goal "k:I ==> A k Un (UN i:I. A i) = (UN i:I. A i)";
496 Goal "(INT x:{}. B x) = UNIV";
501 Goal "k:I ==> A k Int (INT i:I. A i) = (INT i:I. A i)";
505 Goal "(UN x:insert a A. B x) = B a Un UNION A B";
510 Goal "(UN i: A Un B. M i) = (UN i: A. M i) Un (UN i:B. M i)";
514 Goal "(UN x : (UN y:A. B y). C x) = (UN y:A. UN x: B y. C x)";
518 Goal "((UN i:I. A i) <= B) = (ALL i:I. A i <= B)";
522 Goal "(B <= (INT i:I. A i)) = (ALL i:I. B <= A i)";
524 qed "INT_subset_iff";
526 Goal "(INT x:insert a A. B x) = B a Int INTER A B";
529 Addsimps[INT_insert];
531 Goal "(INT i: A Un B. M i) = (INT i: A. M i) Int (INT i:B. M i)";
535 Goal "u: A ==> (INT x:A. insert a (B x)) = insert a (INT x:A. B x)";
537 qed "INT_insert_distrib";
539 Goal "Union(B``A) = (UN x:A. B(x))";
541 qed "Union_image_eq";
542 Addsimps [Union_image_eq];
544 Goal "f `` Union S = (UN x:S. f `` x)";
546 qed "image_Union_eq";
548 Goal "Inter(B``A) = (INT x:A. B(x))";
550 qed "Inter_image_eq";
551 Addsimps [Inter_image_eq];
553 Goal "u: A ==> (UN y:A. c) = c";
556 Addsimps[UN_constant];
558 Goal "u: A ==> (INT y:A. c) = c";
561 Addsimps[INT_constant];
563 Goal "(UN x:A. B(x)) = Union({Y. ? x:A. Y=B(x)})";
567 (*Look: it has an EXISTENTIAL quantifier*)
568 Goal "(INT x:A. B(x)) = Inter({Y. ? x:A. Y=B(x)})";
573 (*Distributive laws...*)
575 Goal "A Int Union(B) = (UN C:B. A Int C)";
579 Goal "Union(B) Int A = (UN C:B. C Int A)";
583 (* Devlin, Fundamentals of Contemporary Set Theory, page 12, exercise 5:
584 Union of a family of unions **)
585 Goal "(UN x:C. A(x) Un B(x)) = Union(A``C) Un Union(B``C)";
587 qed "Un_Union_image";
589 (*Equivalent version*)
590 Goal "(UN i:I. A(i) Un B(i)) = (UN i:I. A(i)) Un (UN i:I. B(i))";
594 Goal "A Un Inter(B) = (INT C:B. A Un C)";
598 Goal "(INT x:C. A(x) Int B(x)) = Inter(A``C) Int Inter(B``C)";
600 qed "Int_Inter_image";
602 (*Equivalent version*)
603 Goal "(INT i:I. A(i) Int B(i)) = (INT i:I. A(i)) Int (INT i:I. B(i))";
605 qed "INT_Int_distrib";
607 (*Halmos, Naive Set Theory, page 35.*)
608 Goal "B Int (UN i:I. A(i)) = (UN i:I. B Int A(i))";
610 qed "Int_UN_distrib";
612 Goal "B Un (INT i:I. A(i)) = (INT i:I. B Un A(i))";
614 qed "Un_INT_distrib";
616 Goal "(UN i:I. A(i)) Int (UN j:J. B(j)) = (UN i:I. UN j:J. A(i) Int B(j))";
618 qed "Int_UN_distrib2";
620 Goal "(INT i:I. A(i)) Un (INT j:J. B(j)) = (INT i:I. INT j:J. A(i) Un B(j))";
622 qed "Un_INT_distrib2";
625 section"Bounded quantifiers";
627 (** The following are not added to the default simpset because
628 (a) they duplicate the body and (b) there are no similar rules for Int. **)
630 Goal "(ALL x:A Un B. P x) = ((ALL x:A. P x) & (ALL x:B. P x))";
634 Goal "(EX x:A Un B. P x) = ((EX x:A. P x) | (EX x:B. P x))";
638 Goal "(ALL z: UNION A B. P z) = (ALL x:A. ALL z:B x. P z)";
642 Goal "(EX z: UNION A B. P z) = (EX x:A. EX z:B x. P z)";
649 Goal "A-B = A Int (-B)";
653 Goal "(A-B = {}) = (A<=B)";
655 qed "Diff_eq_empty_iff";
656 Addsimps[Diff_eq_empty_iff];
661 Addsimps[Diff_cancel];
663 Goal "A Int B = {} ==> A-B = A";
664 by (blast_tac (claset() addEs [equalityE]) 1);
670 Addsimps[empty_Diff];
675 Addsimps[Diff_empty];
682 Goal "x~:A ==> A - insert x B = A-B";
685 Addsimps [Diff_insert0];
687 (*NOT SUITABLE FOR REWRITING since {a} == insert a 0*)
688 Goal "A - insert a B = A - B - {a}";
692 (*NOT SUITABLE FOR REWRITING since {a} == insert a 0*)
693 Goal "A - insert a B = A - {a} - B";
697 Goal "insert x A - B = (if x:B then A-B else insert x (A-B))";
700 qed "insert_Diff_if";
702 Goal "x:B ==> insert x A - B = A-B";
705 Addsimps [insert_Diff1];
707 Goal "a:A ==> insert a (A-{a}) = A";
711 Goal "x ~: A ==> (insert x A) - {x} = A";
713 qed "Diff_insert_absorb";
715 Goal "A Int (B-A) = {}";
718 Addsimps[Diff_disjoint];
720 Goal "A<=B ==> A Un (B-A) = B";
722 qed "Diff_partition";
724 Goal "[| A<=B; B<= C |] ==> (B - (C - A)) = (A :: 'a set)";
728 Goal "A Un (B-A) = A Un B";
730 qed "Un_Diff_cancel";
732 Goal "(B-A) Un A = B Un A";
734 qed "Un_Diff_cancel2";
736 Addsimps [Un_Diff_cancel, Un_Diff_cancel2];
738 Goal "A - (B Un C) = (A-B) Int (A-C)";
742 Goal "A - (B Int C) = (A-B) Un (A-C)";
746 Goal "(A Un B) - C = (A - C) Un (B - C)";
750 Goal "(A Int B) - C = A Int (B - C)";
754 Goal "C Int (A-B) = (C Int A) - (C Int B)";
756 qed "Diff_Int_distrib";
758 Goal "(A-B) Int C = (A Int C) - (B Int C)";
760 qed "Diff_Int_distrib2";
762 Goal "A - (- B) = A Int B";
765 Addsimps [Diff_Compl];
768 section "Quantification over type \"bool\"";
770 Goal "(ALL b::bool. P b) = (P True & P False)";
776 bind_thm ("bool_induct", conjI RS (all_bool_eq RS iffD2) RS spec);
778 Goal "(EX b::bool. P b) = (P True | P False)";
784 Goal "A Un B = (UN b. if b then A else B)";
785 by (auto_tac(claset(), simpset() addsimps [split_if_mem2]));
788 Goal "(UN b::bool. A b) = (A True Un A False)";
794 Goal "(INT b::bool. A b) = (A True Int A False)";
803 Goalw [Pow_def] "Pow {} = {{}}";
806 Addsimps [Pow_empty];
808 Goal "Pow (insert a A) = Pow A Un (insert a `` Pow A)";
811 by (res_inst_tac [("x", "x-{a}")] image_eqI 1);
812 by (ALLGOALS Blast_tac);
815 Goal "Pow (- A) = {-B |B. A: Pow B}";
818 by (res_inst_tac [("x", "-x")] exI 1);
819 by (ALLGOALS Blast_tac);
822 Goal "Pow UNIV = UNIV";
827 Goal "Pow(A) Un Pow(B) <= Pow(A Un B)";
831 Goal "(UN x:A. Pow(B(x))) <= Pow(UN x:A. B(x))";
835 Goal "A <= Pow(Union(A))";
837 qed "subset_Pow_Union";
839 Goal "Union(Pow(A)) = A";
843 Goal "Pow(A Int B) = Pow(A) Int Pow(B)";
847 Goal "Pow(INT x:A. B(x)) = (INT x:A. Pow(B(x)))";
851 Addsimps [Union_Pow_eq, Pow_Int_eq];
854 section "Miscellany";
856 Goal "(A = B) = ((A <= (B::'a set)) & (B<=A))";
860 Goal "A <= B = (! t. t:A --> t:B)";
864 Goalw [psubset_def] "((A::'a set) <= B) = ((A < B) | (A=B))";
866 qed "subset_iff_psubset_eq";
868 Goal "(!x. x ~: A) = (A={})";
870 qed "all_not_in_conv";
871 AddIffs [all_not_in_conv];
874 (** for datatypes **)
875 Goal "f x ~= f y ==> x ~= y";
877 qed "distinct_lemma";
880 (** Miniscoping: pushing in big Unions and Intersections **)
882 fun prover s = prove_goal thy s (fn _ => [Blast_tac 1])
884 val UN_simps = map prover
885 ["!!C. c: C ==> (UN x:C. insert a (B x)) = insert a (UN x:C. B x)",
886 "!!C. c: C ==> (UN x:C. A x Un B) = ((UN x:C. A x) Un B)",
887 "!!C. c: C ==> (UN x:C. A Un B x) = (A Un (UN x:C. B x))",
888 "(UN x:C. A x Int B) = ((UN x:C. A x) Int B)",
889 "(UN x:C. A Int B x) = (A Int (UN x:C. B x))",
890 "(UN x:C. A x - B) = ((UN x:C. A x) - B)",
891 "(UN x:C. A - B x) = (A - (INT x:C. B x))",
892 "(UN x: Union A. B x) = (UN y:A. UN x:y. B x)",
893 "(UN z: UNION A B. C z) = (UN x:A. UN z: B(x). C z)",
894 "(UN x:f``A. B x) = (UN a:A. B(f a))"];
896 val INT_simps = map prover
897 ["!!C. c: C ==> (INT x:C. A x Int B) = ((INT x:C. A x) Int B)",
898 "!!C. c: C ==> (INT x:C. A Int B x) = (A Int (INT x:C. B x))",
899 "!!C. c: C ==> (INT x:C. A x - B) = ((INT x:C. A x) - B)",
900 "!!C. c: C ==> (INT x:C. A - B x) = (A - (UN x:C. B x))",
901 "(INT x:C. insert a (B x)) = insert a (INT x:C. B x)",
902 "(INT x:C. A x Un B) = ((INT x:C. A x) Un B)",
903 "(INT x:C. A Un B x) = (A Un (INT x:C. B x))",
904 "(INT x: Union A. B x) = (INT y:A. INT x:y. B x)",
905 "(INT z: UNION A B. C z) = (INT x:A. INT z: B(x). C z)",
906 "(INT x:f``A. B x) = (INT a:A. B(f a))"];
909 val ball_simps = map prover
910 ["(ALL x:A. P x | Q) = ((ALL x:A. P x) | Q)",
911 "(ALL x:A. P | Q x) = (P | (ALL x:A. Q x))",
912 "(ALL x:A. P --> Q x) = (P --> (ALL x:A. Q x))",
913 "(ALL x:A. P x --> Q) = ((EX x:A. P x) --> Q)",
914 "(ALL x:{}. P x) = True",
915 "(ALL x:UNIV. P x) = (ALL x. P x)",
916 "(ALL x:insert a B. P x) = (P(a) & (ALL x:B. P x))",
917 "(ALL x:Union(A). P x) = (ALL y:A. ALL x:y. P x)",
918 "(ALL x: UNION A B. P x) = (ALL a:A. ALL x: B a. P x)",
919 "(ALL x:Collect Q. P x) = (ALL x. Q x --> P x)",
920 "(ALL x:f``A. P x) = (ALL x:A. P(f x))",
921 "(~(ALL x:A. P x)) = (EX x:A. ~P x)"];
923 val ball_conj_distrib =
924 prover "(ALL x:A. P x & Q x) = ((ALL x:A. P x) & (ALL x:A. Q x))";
926 val bex_simps = map prover
927 ["(EX x:A. P x & Q) = ((EX x:A. P x) & Q)",
928 "(EX x:A. P & Q x) = (P & (EX x:A. Q x))",
929 "(EX x:{}. P x) = False",
930 "(EX x:UNIV. P x) = (EX x. P x)",
931 "(EX x:insert a B. P x) = (P(a) | (EX x:B. P x))",
932 "(EX x:Union(A). P x) = (EX y:A. EX x:y. P x)",
933 "(EX x: UNION A B. P x) = (EX a:A. EX x: B a. P x)",
934 "(EX x:Collect Q. P x) = (EX x. Q x & P x)",
935 "(EX x:f``A. P x) = (EX x:A. P(f x))",
936 "(~(EX x:A. P x)) = (ALL x:A. ~P x)"];
938 val bex_disj_distrib =
939 prover "(EX x:A. P x | Q x) = ((EX x:A. P x) | (EX x:A. Q x))";
943 bind_thms ("UN_simps", UN_simps);
944 bind_thms ("INT_simps", INT_simps);
945 bind_thms ("ball_simps", ball_simps);
946 bind_thms ("bex_simps", bex_simps);
947 bind_thm ("ball_conj_distrib", ball_conj_distrib);
948 bind_thm ("bex_disj_distrib", bex_disj_distrib);
950 Addsimps (UN_simps @ INT_simps @ ball_simps @ bex_simps);