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