src/HOL/Set.ML
author paulson
Thu Sep 23 13:06:31 1999 +0200 (1999-09-23)
changeset 7584 5be4bb8e4e3f
parent 7499 23e090051cb8
child 7658 2d3445be4e91
permissions -rw-r--r--
tidied; added lemma restrict_to_left
     1 (*  Title:      HOL/set
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1991  University of Cambridge
     5 
     6 Set theory for higher-order logic.  A set is simply a predicate.
     7 *)
     8 
     9 section "Relating predicates and sets";
    10 
    11 Addsimps [Collect_mem_eq];
    12 AddIffs  [mem_Collect_eq];
    13 
    14 Goal "P(a) ==> a : {x. P(x)}";
    15 by (Asm_simp_tac 1);
    16 qed "CollectI";
    17 
    18 Goal "a : {x. P(x)} ==> P(a)";
    19 by (Asm_full_simp_tac 1);
    20 qed "CollectD";
    21 
    22 val [prem] = Goal "[| !!x. (x:A) = (x:B) |] ==> A = B";
    23 by (rtac (prem RS ext RS arg_cong RS box_equals) 1);
    24 by (rtac Collect_mem_eq 1);
    25 by (rtac Collect_mem_eq 1);
    26 qed "set_ext";
    27 
    28 val [prem] = Goal "[| !!x. P(x)=Q(x) |] ==> {x. P(x)} = {x. Q(x)}";
    29 by (rtac (prem RS ext RS arg_cong) 1);
    30 qed "Collect_cong";
    31 
    32 val CollectE = make_elim CollectD;
    33 
    34 AddSIs [CollectI];
    35 AddSEs [CollectE];
    36 
    37 
    38 section "Bounded quantifiers";
    39 
    40 val prems = Goalw [Ball_def]
    41     "[| !!x. x:A ==> P(x) |] ==> ! x:A. P(x)";
    42 by (REPEAT (ares_tac (prems @ [allI,impI]) 1));
    43 qed "ballI";
    44 
    45 Goalw [Ball_def] "[| ! x:A. P(x);  x:A |] ==> P(x)";
    46 by (Blast_tac 1);
    47 qed "bspec";
    48 
    49 val major::prems = Goalw [Ball_def]
    50     "[| ! x:A. P(x);  P(x) ==> Q;  x~:A ==> Q |] ==> Q";
    51 by (rtac (major RS spec RS impCE) 1);
    52 by (REPEAT (eresolve_tac prems 1));
    53 qed "ballE";
    54 
    55 (*Takes assumptions ! x:A.P(x) and a:A; creates assumption P(a)*)
    56 fun ball_tac i = etac ballE i THEN contr_tac (i+1);
    57 
    58 AddSIs [ballI];
    59 AddEs  [ballE];
    60 AddXDs [bspec];
    61 (* gives better instantiation for bound: *)
    62 claset_ref() := claset() addWrapper ("bspec", fn tac2 =>
    63 			 (dtac bspec THEN' atac) APPEND' tac2);
    64 
    65 (*Normally the best argument order: P(x) constrains the choice of x:A*)
    66 Goalw [Bex_def] "[| P(x);  x:A |] ==> ? x:A. P(x)";
    67 by (Blast_tac 1);
    68 qed "bexI";
    69 
    70 (*The best argument order when there is only one x:A*)
    71 Goalw [Bex_def] "[| x:A;  P(x) |] ==> ? x:A. P(x)";
    72 by (Blast_tac 1);
    73 qed "rev_bexI";
    74 
    75 val prems = Goal 
    76    "[| ! x:A. ~P(x) ==> P(a);  a:A |] ==> ? x:A. P(x)";
    77 by (rtac classical 1);
    78 by (REPEAT (ares_tac (prems@[bexI,ballI,notI,notE]) 1))  ;
    79 qed "bexCI";
    80 
    81 val major::prems = Goalw [Bex_def]
    82     "[| ? x:A. P(x);  !!x. [| x:A; P(x) |] ==> Q  |] ==> Q";
    83 by (rtac (major RS exE) 1);
    84 by (REPEAT (eresolve_tac (prems @ [asm_rl,conjE]) 1));
    85 qed "bexE";
    86 
    87 AddIs  [bexI];
    88 AddSEs [bexE];
    89 
    90 (*Trival rewrite rule*)
    91 Goal "(! x:A. P) = ((? x. x:A) --> P)";
    92 by (simp_tac (simpset() addsimps [Ball_def]) 1);
    93 qed "ball_triv";
    94 
    95 (*Dual form for existentials*)
    96 Goal "(? x:A. P) = ((? x. x:A) & P)";
    97 by (simp_tac (simpset() addsimps [Bex_def]) 1);
    98 qed "bex_triv";
    99 
   100 Addsimps [ball_triv, bex_triv];
   101 
   102 (** Congruence rules **)
   103 
   104 val prems = Goalw [Ball_def]
   105     "[| A=B;  !!x. x:B ==> P(x) = Q(x) |] ==> \
   106 \    (! x:A. P(x)) = (! x:B. Q(x))";
   107 by (asm_simp_tac (simpset() addsimps prems) 1);
   108 qed "ball_cong";
   109 
   110 val prems = Goalw [Bex_def]
   111     "[| A=B;  !!x. x:B ==> P(x) = Q(x) |] ==> \
   112 \    (? x:A. P(x)) = (? x:B. Q(x))";
   113 by (asm_simp_tac (simpset() addcongs [conj_cong] addsimps prems) 1);
   114 qed "bex_cong";
   115 
   116 Addcongs [ball_cong,bex_cong];
   117 
   118 section "Subsets";
   119 
   120 val prems = Goalw [subset_def] "(!!x. x:A ==> x:B) ==> A <= B";
   121 by (REPEAT (ares_tac (prems @ [ballI]) 1));
   122 qed "subsetI";
   123 
   124 (*Map the type ('a set => anything) to just 'a.
   125   For overloading constants whose first argument has type "'a set" *)
   126 fun overload_1st_set s = Blast.overloaded (s, HOLogic.dest_setT o domain_type);
   127 
   128 (*While (:) is not, its type must be kept
   129   for overloading of = to work.*)
   130 Blast.overloaded ("op :", domain_type);
   131 
   132 overload_1st_set "Ball";		(*need UNION, INTER also?*)
   133 overload_1st_set "Bex";
   134 
   135 (*Image: retain the type of the set being expressed*)
   136 Blast.overloaded ("op ``", domain_type);
   137 
   138 (*Rule in Modus Ponens style*)
   139 Goalw [subset_def] "[| A <= B;  c:A |] ==> c:B";
   140 by (Blast_tac 1);
   141 qed "subsetD";
   142 
   143 (*The same, with reversed premises for use with etac -- cf rev_mp*)
   144 Goal "[| c:A;  A <= B |] ==> c:B";
   145 by (REPEAT (ares_tac [subsetD] 1)) ;
   146 qed "rev_subsetD";
   147 
   148 (*Converts A<=B to x:A ==> x:B*)
   149 fun impOfSubs th = th RSN (2, rev_subsetD);
   150 
   151 Goal "[| A <= B; c ~: B |] ==> c ~: A";
   152 by (REPEAT (eresolve_tac [asm_rl, contrapos, subsetD] 1)) ;
   153 qed "contra_subsetD";
   154 
   155 Goal "[| c ~: B;  A <= B |] ==> c ~: A";
   156 by (REPEAT (eresolve_tac [asm_rl, contrapos, subsetD] 1)) ;
   157 qed "rev_contra_subsetD";
   158 
   159 (*Classical elimination rule*)
   160 val major::prems = Goalw [subset_def] 
   161     "[| A <= B;  c~:A ==> P;  c:B ==> P |] ==> P";
   162 by (rtac (major RS ballE) 1);
   163 by (REPEAT (eresolve_tac prems 1));
   164 qed "subsetCE";
   165 
   166 (*Takes assumptions A<=B; c:A and creates the assumption c:B *)
   167 fun set_mp_tac i = etac subsetCE i  THEN  mp_tac i;
   168 
   169 AddSIs [subsetI];
   170 AddEs  [subsetD, subsetCE];
   171 
   172 Goal "A <= (A::'a set)";
   173 by (Fast_tac 1);
   174 qed "subset_refl";		(*Blast_tac would try order_refl and fail*)
   175 
   176 Goal "[| A<=B;  B<=C |] ==> A<=(C::'a set)";
   177 by (Blast_tac 1);
   178 qed "subset_trans";
   179 
   180 
   181 section "Equality";
   182 
   183 (*Anti-symmetry of the subset relation*)
   184 Goal "[| A <= B;  B <= A |] ==> A = (B::'a set)";
   185 by (rtac set_ext 1);
   186 by (blast_tac (claset() addIs [subsetD]) 1);
   187 qed "subset_antisym";
   188 val equalityI = subset_antisym;
   189 
   190 AddSIs [equalityI];
   191 
   192 (* Equality rules from ZF set theory -- are they appropriate here? *)
   193 Goal "A = B ==> A<=(B::'a set)";
   194 by (etac ssubst 1);
   195 by (rtac subset_refl 1);
   196 qed "equalityD1";
   197 
   198 Goal "A = B ==> B<=(A::'a set)";
   199 by (etac ssubst 1);
   200 by (rtac subset_refl 1);
   201 qed "equalityD2";
   202 
   203 val prems = Goal
   204     "[| A = B;  [| A<=B; B<=(A::'a set) |] ==> P |]  ==>  P";
   205 by (resolve_tac prems 1);
   206 by (REPEAT (resolve_tac (prems RL [equalityD1,equalityD2]) 1));
   207 qed "equalityE";
   208 
   209 val major::prems = Goal
   210     "[| A = B;  [| c:A; c:B |] ==> P;  [| c~:A; c~:B |] ==> P |]  ==>  P";
   211 by (rtac (major RS equalityE) 1);
   212 by (REPEAT (contr_tac 1 ORELSE eresolve_tac ([asm_rl,subsetCE]@prems) 1));
   213 qed "equalityCE";
   214 
   215 (*Lemma for creating induction formulae -- for "pattern matching" on p
   216   To make the induction hypotheses usable, apply "spec" or "bspec" to
   217   put universal quantifiers over the free variables in p. *)
   218 val prems = Goal 
   219     "[| p:A;  !!z. z:A ==> p=z --> R |] ==> R";
   220 by (rtac mp 1);
   221 by (REPEAT (resolve_tac (refl::prems) 1));
   222 qed "setup_induction";
   223 
   224 
   225 section "The universal set -- UNIV";
   226 
   227 Goalw [UNIV_def] "x : UNIV";
   228 by (rtac CollectI 1);
   229 by (rtac TrueI 1);
   230 qed "UNIV_I";
   231 
   232 Addsimps [UNIV_I];
   233 AddIs    [UNIV_I];  (*unsafe makes it less likely to cause problems*)
   234 
   235 Goal "A <= UNIV";
   236 by (rtac subsetI 1);
   237 by (rtac UNIV_I 1);
   238 qed "subset_UNIV";
   239 
   240 (** Eta-contracting these two rules (to remove P) causes them to be ignored
   241     because of their interaction with congruence rules. **)
   242 
   243 Goalw [Ball_def] "Ball UNIV P = All P";
   244 by (Simp_tac 1);
   245 qed "ball_UNIV";
   246 
   247 Goalw [Bex_def] "Bex UNIV P = Ex P";
   248 by (Simp_tac 1);
   249 qed "bex_UNIV";
   250 Addsimps [ball_UNIV, bex_UNIV];
   251 
   252 
   253 section "The empty set -- {}";
   254 
   255 Goalw [empty_def] "(c : {}) = False";
   256 by (Blast_tac 1) ;
   257 qed "empty_iff";
   258 
   259 Addsimps [empty_iff];
   260 
   261 Goal "a:{} ==> P";
   262 by (Full_simp_tac 1);
   263 qed "emptyE";
   264 
   265 AddSEs [emptyE];
   266 
   267 Goal "{} <= A";
   268 by (Blast_tac 1) ;
   269 qed "empty_subsetI";
   270 
   271 (*One effect is to delete the ASSUMPTION {} <= A*)
   272 AddIffs [empty_subsetI];
   273 
   274 val [prem]= Goal "[| !!y. y:A ==> False |] ==> A={}";
   275 by (blast_tac (claset() addIs [prem RS FalseE]) 1) ;
   276 qed "equals0I";
   277 
   278 (*Use for reasoning about disjointness: A Int B = {} *)
   279 Goal "A={} ==> a ~: A";
   280 by (Blast_tac 1) ;
   281 qed "equals0D";
   282 
   283 AddDs [equals0D, sym RS equals0D];
   284 
   285 Goalw [Ball_def] "Ball {} P = True";
   286 by (Simp_tac 1);
   287 qed "ball_empty";
   288 
   289 Goalw [Bex_def] "Bex {} P = False";
   290 by (Simp_tac 1);
   291 qed "bex_empty";
   292 Addsimps [ball_empty, bex_empty];
   293 
   294 Goal "UNIV ~= {}";
   295 by (blast_tac (claset() addEs [equalityE]) 1);
   296 qed "UNIV_not_empty";
   297 AddIffs [UNIV_not_empty];
   298 
   299 
   300 
   301 section "The Powerset operator -- Pow";
   302 
   303 Goalw [Pow_def] "(A : Pow(B)) = (A <= B)";
   304 by (Asm_simp_tac 1);
   305 qed "Pow_iff";
   306 
   307 AddIffs [Pow_iff]; 
   308 
   309 Goalw [Pow_def] "A <= B ==> A : Pow(B)";
   310 by (etac CollectI 1);
   311 qed "PowI";
   312 
   313 Goalw [Pow_def] "A : Pow(B)  ==>  A<=B";
   314 by (etac CollectD 1);
   315 qed "PowD";
   316 
   317 
   318 val Pow_bottom = empty_subsetI RS PowI;        (* {}: Pow(B) *)
   319 val Pow_top = subset_refl RS PowI;             (* A : Pow(A) *)
   320 
   321 
   322 section "Set complement";
   323 
   324 Goalw [Compl_def] "(c : -A) = (c~:A)";
   325 by (Blast_tac 1);
   326 qed "Compl_iff";
   327 
   328 Addsimps [Compl_iff];
   329 
   330 val prems = Goalw [Compl_def] "[| c:A ==> False |] ==> c : -A";
   331 by (REPEAT (ares_tac (prems @ [CollectI,notI]) 1));
   332 qed "ComplI";
   333 
   334 (*This form, with negated conclusion, works well with the Classical prover.
   335   Negated assumptions behave like formulae on the right side of the notional
   336   turnstile...*)
   337 Goalw [Compl_def] "c : -A ==> c~:A";
   338 by (etac CollectD 1);
   339 qed "ComplD";
   340 
   341 val ComplE = make_elim ComplD;
   342 
   343 AddSIs [ComplI];
   344 AddSEs [ComplE];
   345 
   346 
   347 section "Binary union -- Un";
   348 
   349 Goalw [Un_def] "(c : A Un B) = (c:A | c:B)";
   350 by (Blast_tac 1);
   351 qed "Un_iff";
   352 Addsimps [Un_iff];
   353 
   354 Goal "c:A ==> c : A Un B";
   355 by (Asm_simp_tac 1);
   356 qed "UnI1";
   357 
   358 Goal "c:B ==> c : A Un B";
   359 by (Asm_simp_tac 1);
   360 qed "UnI2";
   361 
   362 (*Classical introduction rule: no commitment to A vs B*)
   363 
   364 val prems = Goal "(c~:B ==> c:A) ==> c : A Un B";
   365 by (Simp_tac 1);
   366 by (REPEAT (ares_tac (prems@[disjCI]) 1)) ;
   367 qed "UnCI";
   368 
   369 val major::prems = Goalw [Un_def]
   370     "[| c : A Un B;  c:A ==> P;  c:B ==> P |] ==> P";
   371 by (rtac (major RS CollectD RS disjE) 1);
   372 by (REPEAT (eresolve_tac prems 1));
   373 qed "UnE";
   374 
   375 AddSIs [UnCI];
   376 AddSEs [UnE];
   377 
   378 
   379 section "Binary intersection -- Int";
   380 
   381 Goalw [Int_def] "(c : A Int B) = (c:A & c:B)";
   382 by (Blast_tac 1);
   383 qed "Int_iff";
   384 Addsimps [Int_iff];
   385 
   386 Goal "[| c:A;  c:B |] ==> c : A Int B";
   387 by (Asm_simp_tac 1);
   388 qed "IntI";
   389 
   390 Goal "c : A Int B ==> c:A";
   391 by (Asm_full_simp_tac 1);
   392 qed "IntD1";
   393 
   394 Goal "c : A Int B ==> c:B";
   395 by (Asm_full_simp_tac 1);
   396 qed "IntD2";
   397 
   398 val [major,minor] = Goal
   399     "[| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P";
   400 by (rtac minor 1);
   401 by (rtac (major RS IntD1) 1);
   402 by (rtac (major RS IntD2) 1);
   403 qed "IntE";
   404 
   405 AddSIs [IntI];
   406 AddSEs [IntE];
   407 
   408 section "Set difference";
   409 
   410 Goalw [set_diff_def] "(c : A-B) = (c:A & c~:B)";
   411 by (Blast_tac 1);
   412 qed "Diff_iff";
   413 Addsimps [Diff_iff];
   414 
   415 Goal "[| c : A;  c ~: B |] ==> c : A - B";
   416 by (Asm_simp_tac 1) ;
   417 qed "DiffI";
   418 
   419 Goal "c : A - B ==> c : A";
   420 by (Asm_full_simp_tac 1) ;
   421 qed "DiffD1";
   422 
   423 Goal "[| c : A - B;  c : B |] ==> P";
   424 by (Asm_full_simp_tac 1) ;
   425 qed "DiffD2";
   426 
   427 val prems = Goal "[| c : A - B;  [| c:A; c~:B |] ==> P |] ==> P";
   428 by (resolve_tac prems 1);
   429 by (REPEAT (ares_tac (prems RL [DiffD1, DiffD2 RS notI]) 1)) ;
   430 qed "DiffE";
   431 
   432 AddSIs [DiffI];
   433 AddSEs [DiffE];
   434 
   435 
   436 section "Augmenting a set -- insert";
   437 
   438 Goalw [insert_def] "a : insert b A = (a=b | a:A)";
   439 by (Blast_tac 1);
   440 qed "insert_iff";
   441 Addsimps [insert_iff];
   442 
   443 Goal "a : insert a B";
   444 by (Simp_tac 1);
   445 qed "insertI1";
   446 
   447 Goal "!!a. a : B ==> a : insert b B";
   448 by (Asm_simp_tac 1);
   449 qed "insertI2";
   450 
   451 val major::prems = Goalw [insert_def]
   452     "[| a : insert b A;  a=b ==> P;  a:A ==> P |] ==> P";
   453 by (rtac (major RS UnE) 1);
   454 by (REPEAT (eresolve_tac (prems @ [CollectE]) 1));
   455 qed "insertE";
   456 
   457 (*Classical introduction rule*)
   458 val prems = Goal "(a~:B ==> a=b) ==> a: insert b B";
   459 by (Simp_tac 1);
   460 by (REPEAT (ares_tac (prems@[disjCI]) 1)) ;
   461 qed "insertCI";
   462 
   463 AddSIs [insertCI]; 
   464 AddSEs [insertE];
   465 
   466 Goal "A <= insert x B ==> A <= B & x ~: A | (? B'. A = insert x B' & B' <= B)";
   467 by (case_tac "x:A" 1);
   468 by  (Fast_tac 2);
   469 by (rtac disjI2 1);
   470 by (res_inst_tac [("x","A-{x}")] exI 1);
   471 by (Fast_tac 1);
   472 qed "subset_insertD";
   473 
   474 section "Singletons, using insert";
   475 
   476 Goal "a : {a}";
   477 by (rtac insertI1 1) ;
   478 qed "singletonI";
   479 
   480 Goal "b : {a} ==> b=a";
   481 by (Blast_tac 1);
   482 qed "singletonD";
   483 
   484 bind_thm ("singletonE", make_elim singletonD);
   485 
   486 Goal "(b : {a}) = (b=a)";
   487 by (Blast_tac 1);
   488 qed "singleton_iff";
   489 
   490 Goal "{a}={b} ==> a=b";
   491 by (blast_tac (claset() addEs [equalityE]) 1);
   492 qed "singleton_inject";
   493 
   494 (*Redundant? But unlike insertCI, it proves the subgoal immediately!*)
   495 AddSIs [singletonI];   
   496 AddSDs [singleton_inject];
   497 AddSEs [singletonE];
   498 
   499 Goal "{b} = insert a A = (a = b & A <= {a})";
   500 by (safe_tac (claset() addSEs [equalityE]));
   501 by   (ALLGOALS Blast_tac);
   502 qed "singleton_insert_inj_eq";
   503 
   504 Goal "A <= {x} ==> A={} | A = {x}";
   505 by (Fast_tac 1);
   506 qed "subset_singletonD";
   507 
   508 Goal "{x. x=a} = {a}";
   509 by (Blast_tac 1);
   510 qed "singleton_conv";
   511 Addsimps [singleton_conv];
   512 
   513 Goal "{x. a=x} = {a}";
   514 by (Blast_tac 1);
   515 qed "singleton_conv2";
   516 Addsimps [singleton_conv2];
   517 
   518 
   519 section "Unions of families -- UNION x:A. B(x) is Union(B``A)";
   520 
   521 Goalw [UNION_def] "(b: (UN x:A. B(x))) = (EX x:A. b: B(x))";
   522 by (Blast_tac 1);
   523 qed "UN_iff";
   524 
   525 Addsimps [UN_iff];
   526 
   527 (*The order of the premises presupposes that A is rigid; b may be flexible*)
   528 Goal "[| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))";
   529 by Auto_tac;
   530 qed "UN_I";
   531 
   532 val major::prems = Goalw [UNION_def]
   533     "[| b : (UN x:A. B(x));  !!x.[| x:A;  b: B(x) |] ==> R |] ==> R";
   534 by (rtac (major RS CollectD RS bexE) 1);
   535 by (REPEAT (ares_tac prems 1));
   536 qed "UN_E";
   537 
   538 AddIs  [UN_I];
   539 AddSEs [UN_E];
   540 
   541 val prems = Goalw [UNION_def]
   542     "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
   543 \    (UN x:A. C(x)) = (UN x:B. D(x))";
   544 by (asm_simp_tac (simpset() addsimps prems) 1);
   545 qed "UN_cong";
   546 
   547 
   548 section "Intersections of families -- INTER x:A. B(x) is Inter(B``A)";
   549 
   550 Goalw [INTER_def] "(b: (INT x:A. B(x))) = (ALL x:A. b: B(x))";
   551 by Auto_tac;
   552 qed "INT_iff";
   553 
   554 Addsimps [INT_iff];
   555 
   556 val prems = Goalw [INTER_def]
   557     "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))";
   558 by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1));
   559 qed "INT_I";
   560 
   561 Goal "[| b : (INT x:A. B(x));  a:A |] ==> b: B(a)";
   562 by Auto_tac;
   563 qed "INT_D";
   564 
   565 (*"Classical" elimination -- by the Excluded Middle on a:A *)
   566 val major::prems = Goalw [INTER_def]
   567     "[| b : (INT x:A. B(x));  b: B(a) ==> R;  a~:A ==> R |] ==> R";
   568 by (rtac (major RS CollectD RS ballE) 1);
   569 by (REPEAT (eresolve_tac prems 1));
   570 qed "INT_E";
   571 
   572 AddSIs [INT_I];
   573 AddEs  [INT_D, INT_E];
   574 
   575 val prems = Goalw [INTER_def]
   576     "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
   577 \    (INT x:A. C(x)) = (INT x:B. D(x))";
   578 by (asm_simp_tac (simpset() addsimps prems) 1);
   579 qed "INT_cong";
   580 
   581 
   582 section "Union";
   583 
   584 Goalw [Union_def] "(A : Union(C)) = (EX X:C. A:X)";
   585 by (Blast_tac 1);
   586 qed "Union_iff";
   587 
   588 Addsimps [Union_iff];
   589 
   590 (*The order of the premises presupposes that C is rigid; A may be flexible*)
   591 Goal "[| X:C;  A:X |] ==> A : Union(C)";
   592 by Auto_tac;
   593 qed "UnionI";
   594 
   595 val major::prems = Goalw [Union_def]
   596     "[| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R";
   597 by (rtac (major RS UN_E) 1);
   598 by (REPEAT (ares_tac prems 1));
   599 qed "UnionE";
   600 
   601 AddIs  [UnionI];
   602 AddSEs [UnionE];
   603 
   604 
   605 section "Inter";
   606 
   607 Goalw [Inter_def] "(A : Inter(C)) = (ALL X:C. A:X)";
   608 by (Blast_tac 1);
   609 qed "Inter_iff";
   610 
   611 Addsimps [Inter_iff];
   612 
   613 val prems = Goalw [Inter_def]
   614     "[| !!X. X:C ==> A:X |] ==> A : Inter(C)";
   615 by (REPEAT (ares_tac ([INT_I] @ prems) 1));
   616 qed "InterI";
   617 
   618 (*A "destruct" rule -- every X in C contains A as an element, but
   619   A:X can hold when X:C does not!  This rule is analogous to "spec". *)
   620 Goal "[| A : Inter(C);  X:C |] ==> A:X";
   621 by Auto_tac;
   622 qed "InterD";
   623 
   624 (*"Classical" elimination rule -- does not require proving X:C *)
   625 val major::prems = Goalw [Inter_def]
   626     "[| A : Inter(C);  X~:C ==> R;  A:X ==> R |] ==> R";
   627 by (rtac (major RS INT_E) 1);
   628 by (REPEAT (eresolve_tac prems 1));
   629 qed "InterE";
   630 
   631 AddSIs [InterI];
   632 AddEs  [InterD, InterE];
   633 
   634 
   635 (*** Image of a set under a function ***)
   636 
   637 (*Frequently b does not have the syntactic form of f(x).*)
   638 Goalw [image_def] "[| b=f(x);  x:A |] ==> b : f``A";
   639 by (Blast_tac 1);
   640 qed "image_eqI";
   641 Addsimps [image_eqI];
   642 
   643 bind_thm ("imageI", refl RS image_eqI);
   644 
   645 (*The eta-expansion gives variable-name preservation.*)
   646 val major::prems = Goalw [image_def]
   647     "[| b : (%x. f(x))``A;  !!x.[| b=f(x);  x:A |] ==> P |] ==> P"; 
   648 by (rtac (major RS CollectD RS bexE) 1);
   649 by (REPEAT (ares_tac prems 1));
   650 qed "imageE";
   651 
   652 AddIs  [image_eqI];
   653 AddSEs [imageE]; 
   654 
   655 Goal "f``(A Un B) = f``A Un f``B";
   656 by (Blast_tac 1);
   657 qed "image_Un";
   658 
   659 Goal "(z : f``A) = (EX x:A. z = f x)";
   660 by (Blast_tac 1);
   661 qed "image_iff";
   662 
   663 (*This rewrite rule would confuse users if made default.*)
   664 Goal "(f``A <= B) = (ALL x:A. f(x): B)";
   665 by (Blast_tac 1);
   666 qed "image_subset_iff";
   667 
   668 (*Replaces the three steps subsetI, imageE, hyp_subst_tac, but breaks too
   669   many existing proofs.*)
   670 val prems = Goal "(!!x. x:A ==> f(x) : B) ==> f``A <= B";
   671 by (blast_tac (claset() addIs prems) 1);
   672 qed "image_subsetI";
   673 
   674 
   675 (*** Range of a function -- just a translation for image! ***)
   676 
   677 Goal "b=f(x) ==> b : range(f)";
   678 by (EVERY1 [etac image_eqI, rtac UNIV_I]);
   679 bind_thm ("range_eqI", UNIV_I RSN (2,image_eqI));
   680 
   681 bind_thm ("rangeI", UNIV_I RS imageI);
   682 
   683 val [major,minor] = Goal 
   684     "[| b : range(%x. f(x));  !!x. b=f(x) ==> P |] ==> P"; 
   685 by (rtac (major RS imageE) 1);
   686 by (etac minor 1);
   687 qed "rangeE";
   688 
   689 
   690 (*** Set reasoning tools ***)
   691 
   692 
   693 (** Rewrite rules for boolean case-splitting: faster than 
   694 	addsplits[split_if]
   695 **)
   696 
   697 bind_thm ("split_if_eq1", read_instantiate [("P", "%x. x = ?b")] split_if);
   698 bind_thm ("split_if_eq2", read_instantiate [("P", "%x. ?a = x")] split_if);
   699 
   700 (*Split ifs on either side of the membership relation.
   701 	Not for Addsimps -- can cause goals to blow up!*)
   702 bind_thm ("split_if_mem1", 
   703     read_instantiate_sg (Theory.sign_of Set.thy) [("P", "%x. x : ?b")] split_if);
   704 bind_thm ("split_if_mem2", 
   705     read_instantiate_sg (Theory.sign_of Set.thy) [("P", "%x. ?a : x")] split_if);
   706 
   707 val split_ifs = [if_bool_eq_conj, split_if_eq1, split_if_eq2,
   708 		  split_if_mem1, split_if_mem2];
   709 
   710 
   711 (*Each of these has ALREADY been added to simpset() above.*)
   712 val mem_simps = [insert_iff, empty_iff, Un_iff, Int_iff, Compl_iff, Diff_iff, 
   713                  mem_Collect_eq, UN_iff, Union_iff, INT_iff, Inter_iff];
   714 
   715 val mksimps_pairs = ("Ball",[bspec]) :: mksimps_pairs;
   716 
   717 simpset_ref() := simpset() setmksimps (mksimps mksimps_pairs);
   718 
   719 Addsimps[subset_UNIV, subset_refl];
   720 
   721 
   722 (*** < ***)
   723 
   724 Goalw [psubset_def] "!!A::'a set. [| A <= B; A ~= B |] ==> A<B";
   725 by (Blast_tac 1);
   726 qed "psubsetI";
   727 
   728 Goalw [psubset_def] "A < insert x B ==> (x ~: A) & A<=B | x:A & A-{x}<B";
   729 by Auto_tac;
   730 qed "psubset_insertD";
   731 
   732 bind_thm ("psubset_eq", psubset_def RS meta_eq_to_obj_eq);
   733 
   734 bind_thm ("psubset_imp_subset", psubset_eq RS iffD1 RS conjunct1);
   735 
   736 Goal"[| (A::'a set) < B; B <= C |] ==> A < C";
   737 by (auto_tac (claset(), simpset() addsimps [psubset_eq]));
   738 qed "psubset_subset_trans";
   739 
   740 Goal"[| (A::'a set) <= B; B < C|] ==> A < C";
   741 by (auto_tac (claset(), simpset() addsimps [psubset_eq]));
   742 qed "subset_psubset_trans";