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