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