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