src/HOL/Set.ML
 author paulson Thu Jul 15 10:27:54 1999 +0200 (1999-07-15) changeset 7007 b46ccfee8e59 parent 6443 6d5d3ecedf50 child 7031 972b5f62f476 permissions -rw-r--r--
qed_goal -> 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 Set.thy
```
```    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 qed_goalw "UNIV_I" Set.thy [UNIV_def] "x : UNIV"
```
```   227   (fn _ => [rtac CollectI 1, rtac TrueI 1]);
```
```   228
```
```   229 Addsimps [UNIV_I];
```
```   230 AddIs    [UNIV_I];  (*unsafe makes it less likely to cause problems*)
```
```   231
```
```   232 qed_goal "subset_UNIV" Set.thy "A <= UNIV"
```
```   233   (fn _ => [rtac subsetI 1, rtac UNIV_I 1]);
```
```   234
```
```   235 (** Eta-contracting these two rules (to remove P) causes them to be ignored
```
```   236     because of their interaction with congruence rules. **)
```
```   237
```
```   238 Goalw [Ball_def] "Ball UNIV P = All P";
```
```   239 by (Simp_tac 1);
```
```   240 qed "ball_UNIV";
```
```   241
```
```   242 Goalw [Bex_def] "Bex UNIV P = Ex P";
```
```   243 by (Simp_tac 1);
```
```   244 qed "bex_UNIV";
```
```   245 Addsimps [ball_UNIV, bex_UNIV];
```
```   246
```
```   247
```
```   248 section "The empty set -- {}";
```
```   249
```
```   250 Goalw [empty_def] "(c : {}) = False";
```
```   251 by (Blast_tac 1) ;
```
```   252 qed "empty_iff";
```
```   253
```
```   254 Addsimps [empty_iff];
```
```   255
```
```   256 Goal "a:{} ==> P";
```
```   257 by (Full_simp_tac 1);
```
```   258 qed "emptyE";
```
```   259
```
```   260 AddSEs [emptyE];
```
```   261
```
```   262 Goal "{} <= A";
```
```   263 by (Blast_tac 1) ;
```
```   264 qed "empty_subsetI";
```
```   265
```
```   266 (*One effect is to delete the ASSUMPTION {} <= A*)
```
```   267 AddIffs [empty_subsetI];
```
```   268
```
```   269 val [prem]= goal Set.thy "[| !!y. y:A ==> False |] ==> A={}";
```
```   270 by (blast_tac (claset() addIs [prem RS FalseE]) 1) ;
```
```   271 qed "equals0I";
```
```   272
```
```   273 (*Use for reasoning about disjointness: A Int B = {} *)
```
```   274 Goal "A={} ==> a ~: A";
```
```   275 by (Blast_tac 1) ;
```
```   276 qed "equals0D";
```
```   277
```
```   278 AddDs [equals0D, sym RS equals0D];
```
```   279
```
```   280 Goalw [Ball_def] "Ball {} P = True";
```
```   281 by (Simp_tac 1);
```
```   282 qed "ball_empty";
```
```   283
```
```   284 Goalw [Bex_def] "Bex {} P = False";
```
```   285 by (Simp_tac 1);
```
```   286 qed "bex_empty";
```
```   287 Addsimps [ball_empty, bex_empty];
```
```   288
```
```   289 Goal "UNIV ~= {}";
```
```   290 by (blast_tac (claset() addEs [equalityE]) 1);
```
```   291 qed "UNIV_not_empty";
```
```   292 AddIffs [UNIV_not_empty];
```
```   293
```
```   294
```
```   295
```
```   296 section "The Powerset operator -- Pow";
```
```   297
```
```   298 Goalw [Pow_def] "(A : Pow(B)) = (A <= B)";
```
```   299 by (Asm_simp_tac 1);
```
```   300 qed "Pow_iff";
```
```   301
```
```   302 AddIffs [Pow_iff];
```
```   303
```
```   304 Goalw [Pow_def] "!!A B. A <= B ==> A : Pow(B)";
```
```   305 by (etac CollectI 1);
```
```   306 qed "PowI";
```
```   307
```
```   308 Goalw [Pow_def] "!!A B. A : Pow(B)  ==>  A<=B";
```
```   309 by (etac CollectD 1);
```
```   310 qed "PowD";
```
```   311
```
```   312
```
```   313 val Pow_bottom = empty_subsetI RS PowI;        (* {}: Pow(B) *)
```
```   314 val Pow_top = subset_refl RS PowI;             (* A : Pow(A) *)
```
```   315
```
```   316
```
```   317 section "Set complement";
```
```   318
```
```   319 qed_goalw "Compl_iff" Set.thy [Compl_def] "(c : -A) = (c~:A)"
```
```   320  (fn _ => [ (Blast_tac 1) ]);
```
```   321
```
```   322 Addsimps [Compl_iff];
```
```   323
```
```   324 val prems = Goalw [Compl_def] "[| c:A ==> False |] ==> c : -A";
```
```   325 by (REPEAT (ares_tac (prems @ [CollectI,notI]) 1));
```
```   326 qed "ComplI";
```
```   327
```
```   328 (*This form, with negated conclusion, works well with the Classical prover.
```
```   329   Negated assumptions behave like formulae on the right side of the notional
```
```   330   turnstile...*)
```
```   331 Goalw [Compl_def] "c : -A ==> c~:A";
```
```   332 by (etac CollectD 1);
```
```   333 qed "ComplD";
```
```   334
```
```   335 val ComplE = make_elim ComplD;
```
```   336
```
```   337 AddSIs [ComplI];
```
```   338 AddSEs [ComplE];
```
```   339
```
```   340
```
```   341 section "Binary union -- Un";
```
```   342
```
```   343 qed_goalw "Un_iff" Set.thy [Un_def] "(c : A Un B) = (c:A | c:B)"
```
```   344  (fn _ => [ Blast_tac 1 ]);
```
```   345
```
```   346 Addsimps [Un_iff];
```
```   347
```
```   348 Goal "c:A ==> c : A Un B";
```
```   349 by (Asm_simp_tac 1);
```
```   350 qed "UnI1";
```
```   351
```
```   352 Goal "c:B ==> c : A Un B";
```
```   353 by (Asm_simp_tac 1);
```
```   354 qed "UnI2";
```
```   355
```
```   356 (*Classical introduction rule: no commitment to A vs B*)
```
```   357
```
```   358 val prems= goal Set.thy "(c~:B ==> c:A) ==> c : A Un B";
```
```   359 by (Simp_tac 1);
```
```   360 by (REPEAT (ares_tac (prems@[disjCI]) 1)) ;
```
```   361 qed "UnCI";
```
```   362
```
```   363 val major::prems = Goalw [Un_def]
```
```   364     "[| c : A Un B;  c:A ==> P;  c:B ==> P |] ==> P";
```
```   365 by (rtac (major RS CollectD RS disjE) 1);
```
```   366 by (REPEAT (eresolve_tac prems 1));
```
```   367 qed "UnE";
```
```   368
```
```   369 AddSIs [UnCI];
```
```   370 AddSEs [UnE];
```
```   371
```
```   372
```
```   373 section "Binary intersection -- Int";
```
```   374
```
```   375 qed_goalw "Int_iff" Set.thy [Int_def] "(c : A Int B) = (c:A & c:B)"
```
```   376  (fn _ => [ (Blast_tac 1) ]);
```
```   377
```
```   378 Addsimps [Int_iff];
```
```   379
```
```   380 Goal "[| c:A;  c:B |] ==> c : A Int B";
```
```   381 by (Asm_simp_tac 1);
```
```   382 qed "IntI";
```
```   383
```
```   384 Goal "c : A Int B ==> c:A";
```
```   385 by (Asm_full_simp_tac 1);
```
```   386 qed "IntD1";
```
```   387
```
```   388 Goal "c : A Int B ==> c:B";
```
```   389 by (Asm_full_simp_tac 1);
```
```   390 qed "IntD2";
```
```   391
```
```   392 val [major,minor] = Goal
```
```   393     "[| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P";
```
```   394 by (rtac minor 1);
```
```   395 by (rtac (major RS IntD1) 1);
```
```   396 by (rtac (major RS IntD2) 1);
```
```   397 qed "IntE";
```
```   398
```
```   399 AddSIs [IntI];
```
```   400 AddSEs [IntE];
```
```   401
```
```   402 section "Set difference";
```
```   403
```
```   404 qed_goalw "Diff_iff" Set.thy [set_diff_def] "(c : A-B) = (c:A & c~:B)"
```
```   405  (fn _ => [ (Blast_tac 1) ]);
```
```   406
```
```   407 Addsimps [Diff_iff];
```
```   408
```
```   409 Goal "[| c : A;  c ~: B |] ==> c : A - B";
```
```   410 by (Asm_simp_tac 1) ;
```
```   411 qed "DiffI";
```
```   412
```
```   413 Goal "c : A - B ==> c : A";
```
```   414 by (Asm_full_simp_tac 1) ;
```
```   415 qed "DiffD1";
```
```   416
```
```   417 Goal "[| c : A - B;  c : B |] ==> P";
```
```   418 by (Asm_full_simp_tac 1) ;
```
```   419 qed "DiffD2";
```
```   420
```
```   421 val prems= goal Set.thy "[| c : A - B;  [| c:A; c~:B |] ==> P |] ==> P";
```
```   422 by (resolve_tac prems 1);
```
```   423 by (REPEAT (ares_tac (prems RL [DiffD1, DiffD2 RS notI]) 1)) ;
```
```   424 qed "DiffE";
```
```   425
```
```   426 AddSIs [DiffI];
```
```   427 AddSEs [DiffE];
```
```   428
```
```   429
```
```   430 section "Augmenting a set -- insert";
```
```   431
```
```   432 qed_goalw "insert_iff" Set.thy [insert_def] "a : insert b A = (a=b | a:A)"
```
```   433  (fn _ => [Blast_tac 1]);
```
```   434
```
```   435 Addsimps [insert_iff];
```
```   436
```
```   437 val _ = goal Set.thy "a : insert a B";
```
```   438 by (Simp_tac 1);
```
```   439 qed "insertI1";
```
```   440
```
```   441 Goal "!!a. a : B ==> a : insert b B";
```
```   442 by (Asm_simp_tac 1);
```
```   443 qed "insertI2";
```
```   444
```
```   445 val major::prems = Goalw [insert_def]
```
```   446     "[| a : insert b A;  a=b ==> P;  a:A ==> P |] ==> P";
```
```   447 by (rtac (major RS UnE) 1);
```
```   448 by (REPEAT (eresolve_tac (prems @ [CollectE]) 1));
```
```   449 qed "insertE";
```
```   450
```
```   451 (*Classical introduction rule*)
```
```   452 val prems= goal Set.thy "(a~:B ==> a=b) ==> a: insert b B";
```
```   453 by (Simp_tac 1);
```
```   454 by (REPEAT (ares_tac (prems@[disjCI]) 1)) ;
```
```   455 qed "insertCI";
```
```   456
```
```   457 AddSIs [insertCI];
```
```   458 AddSEs [insertE];
```
```   459
```
```   460 section "Singletons, using insert";
```
```   461
```
```   462 Goal "a : {a}";
```
```   463 by (rtac insertI1 1) ;
```
```   464 qed "singletonI";
```
```   465
```
```   466 Goal "b : {a} ==> b=a";
```
```   467 by (Blast_tac 1);
```
```   468 qed "singletonD";
```
```   469
```
```   470 bind_thm ("singletonE", make_elim singletonD);
```
```   471
```
```   472 Goal "(b : {a}) = (b=a)";
```
```   473 by (Blast_tac 1);
```
```   474 qed "singleton_iff";
```
```   475
```
```   476 Goal "{a}={b} ==> a=b";
```
```   477 by (blast_tac (claset() addEs [equalityE]) 1);
```
```   478 qed "singleton_inject";
```
```   479
```
```   480 (*Redundant? But unlike insertCI, it proves the subgoal immediately!*)
```
```   481 AddSIs [singletonI];
```
```   482 AddSDs [singleton_inject];
```
```   483 AddSEs [singletonE];
```
```   484
```
```   485 Goal "{x. x=a} = {a}";
```
```   486 by (Blast_tac 1);
```
```   487 qed "singleton_conv";
```
```   488 Addsimps [singleton_conv];
```
```   489
```
```   490 Goal "{x. a=x} = {a}";
```
```   491 by (Blast_tac 1);
```
```   492 qed "singleton_conv2";
```
```   493 Addsimps [singleton_conv2];
```
```   494
```
```   495
```
```   496 section "Unions of families -- UNION x:A. B(x) is Union(B``A)";
```
```   497
```
```   498 Goalw [UNION_def] "(b: (UN x:A. B(x))) = (EX x:A. b: B(x))";
```
```   499 by (Blast_tac 1);
```
```   500 qed "UN_iff";
```
```   501
```
```   502 Addsimps [UN_iff];
```
```   503
```
```   504 (*The order of the premises presupposes that A is rigid; b may be flexible*)
```
```   505 Goal "[| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))";
```
```   506 by Auto_tac;
```
```   507 qed "UN_I";
```
```   508
```
```   509 val major::prems = Goalw [UNION_def]
```
```   510     "[| b : (UN x:A. B(x));  !!x.[| x:A;  b: B(x) |] ==> R |] ==> R";
```
```   511 by (rtac (major RS CollectD RS bexE) 1);
```
```   512 by (REPEAT (ares_tac prems 1));
```
```   513 qed "UN_E";
```
```   514
```
```   515 AddIs  [UN_I];
```
```   516 AddSEs [UN_E];
```
```   517
```
```   518 val prems = Goalw [UNION_def]
```
```   519     "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
```
```   520 \    (UN x:A. C(x)) = (UN x:B. D(x))";
```
```   521 by (asm_simp_tac (simpset() addsimps prems) 1);
```
```   522 qed "UN_cong";
```
```   523
```
```   524
```
```   525 section "Intersections of families -- INTER x:A. B(x) is Inter(B``A)";
```
```   526
```
```   527 Goalw [INTER_def] "(b: (INT x:A. B(x))) = (ALL x:A. b: B(x))";
```
```   528 by Auto_tac;
```
```   529 qed "INT_iff";
```
```   530
```
```   531 Addsimps [INT_iff];
```
```   532
```
```   533 val prems = Goalw [INTER_def]
```
```   534     "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))";
```
```   535 by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1));
```
```   536 qed "INT_I";
```
```   537
```
```   538 Goal "[| b : (INT x:A. B(x));  a:A |] ==> b: B(a)";
```
```   539 by Auto_tac;
```
```   540 qed "INT_D";
```
```   541
```
```   542 (*"Classical" elimination -- by the Excluded Middle on a:A *)
```
```   543 val major::prems = Goalw [INTER_def]
```
```   544     "[| b : (INT x:A. B(x));  b: B(a) ==> R;  a~:A ==> R |] ==> R";
```
```   545 by (rtac (major RS CollectD RS ballE) 1);
```
```   546 by (REPEAT (eresolve_tac prems 1));
```
```   547 qed "INT_E";
```
```   548
```
```   549 AddSIs [INT_I];
```
```   550 AddEs  [INT_D, INT_E];
```
```   551
```
```   552 val prems = Goalw [INTER_def]
```
```   553     "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
```
```   554 \    (INT x:A. C(x)) = (INT x:B. D(x))";
```
```   555 by (asm_simp_tac (simpset() addsimps prems) 1);
```
```   556 qed "INT_cong";
```
```   557
```
```   558
```
```   559 section "Union";
```
```   560
```
```   561 Goalw [Union_def] "(A : Union(C)) = (EX X:C. A:X)";
```
```   562 by (Blast_tac 1);
```
```   563 qed "Union_iff";
```
```   564
```
```   565 Addsimps [Union_iff];
```
```   566
```
```   567 (*The order of the premises presupposes that C is rigid; A may be flexible*)
```
```   568 Goal "[| X:C;  A:X |] ==> A : Union(C)";
```
```   569 by Auto_tac;
```
```   570 qed "UnionI";
```
```   571
```
```   572 val major::prems = Goalw [Union_def]
```
```   573     "[| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R";
```
```   574 by (rtac (major RS UN_E) 1);
```
```   575 by (REPEAT (ares_tac prems 1));
```
```   576 qed "UnionE";
```
```   577
```
```   578 AddIs  [UnionI];
```
```   579 AddSEs [UnionE];
```
```   580
```
```   581
```
```   582 section "Inter";
```
```   583
```
```   584 Goalw [Inter_def] "(A : Inter(C)) = (ALL X:C. A:X)";
```
```   585 by (Blast_tac 1);
```
```   586 qed "Inter_iff";
```
```   587
```
```   588 Addsimps [Inter_iff];
```
```   589
```
```   590 val prems = Goalw [Inter_def]
```
```   591     "[| !!X. X:C ==> A:X |] ==> A : Inter(C)";
```
```   592 by (REPEAT (ares_tac ([INT_I] @ prems) 1));
```
```   593 qed "InterI";
```
```   594
```
```   595 (*A "destruct" rule -- every X in C contains A as an element, but
```
```   596   A:X can hold when X:C does not!  This rule is analogous to "spec". *)
```
```   597 Goal "[| A : Inter(C);  X:C |] ==> A:X";
```
```   598 by Auto_tac;
```
```   599 qed "InterD";
```
```   600
```
```   601 (*"Classical" elimination rule -- does not require proving X:C *)
```
```   602 val major::prems = Goalw [Inter_def]
```
```   603     "[| A : Inter(C);  X~:C ==> R;  A:X ==> R |] ==> R";
```
```   604 by (rtac (major RS INT_E) 1);
```
```   605 by (REPEAT (eresolve_tac prems 1));
```
```   606 qed "InterE";
```
```   607
```
```   608 AddSIs [InterI];
```
```   609 AddEs  [InterD, InterE];
```
```   610
```
```   611
```
```   612 (*** Image of a set under a function ***)
```
```   613
```
```   614 (*Frequently b does not have the syntactic form of f(x).*)
```
```   615 Goalw [image_def] "[| b=f(x);  x:A |] ==> b : f``A";
```
```   616 by (Blast_tac 1);
```
```   617 qed "image_eqI";
```
```   618 Addsimps [image_eqI];
```
```   619
```
```   620 bind_thm ("imageI", refl RS image_eqI);
```
```   621
```
```   622 (*The eta-expansion gives variable-name preservation.*)
```
```   623 val major::prems = Goalw [image_def]
```
```   624     "[| b : (%x. f(x))``A;  !!x.[| b=f(x);  x:A |] ==> P |] ==> P";
```
```   625 by (rtac (major RS CollectD RS bexE) 1);
```
```   626 by (REPEAT (ares_tac prems 1));
```
```   627 qed "imageE";
```
```   628
```
```   629 AddIs  [image_eqI];
```
```   630 AddSEs [imageE];
```
```   631
```
```   632 Goal "f``(A Un B) = f``A Un f``B";
```
```   633 by (Blast_tac 1);
```
```   634 qed "image_Un";
```
```   635
```
```   636 Goal "(z : f``A) = (EX x:A. z = f x)";
```
```   637 by (Blast_tac 1);
```
```   638 qed "image_iff";
```
```   639
```
```   640 (*This rewrite rule would confuse users if made default.*)
```
```   641 Goal "(f``A <= B) = (ALL x:A. f(x): B)";
```
```   642 by (Blast_tac 1);
```
```   643 qed "image_subset_iff";
```
```   644
```
```   645 (*Replaces the three steps subsetI, imageE, hyp_subst_tac, but breaks too
```
```   646   many existing proofs.*)
```
```   647 val prems = Goal "(!!x. x:A ==> f(x) : B) ==> f``A <= B";
```
```   648 by (blast_tac (claset() addIs prems) 1);
```
```   649 qed "image_subsetI";
```
```   650
```
```   651
```
```   652 (*** Range of a function -- just a translation for image! ***)
```
```   653
```
```   654 Goal "b=f(x) ==> b : range(f)";
```
```   655 by (EVERY1 [etac image_eqI, rtac UNIV_I]);
```
```   656 bind_thm ("range_eqI", UNIV_I RSN (2,image_eqI));
```
```   657
```
```   658 bind_thm ("rangeI", UNIV_I RS imageI);
```
```   659
```
```   660 val [major,minor] = Goal
```
```   661     "[| b : range(%x. f(x));  !!x. b=f(x) ==> P |] ==> P";
```
```   662 by (rtac (major RS imageE) 1);
```
```   663 by (etac minor 1);
```
```   664 qed "rangeE";
```
```   665
```
```   666
```
```   667 (*** Set reasoning tools ***)
```
```   668
```
```   669
```
```   670 (** Rewrite rules for boolean case-splitting: faster than
```
```   671 	addsplits[split_if]
```
```   672 **)
```
```   673
```
```   674 bind_thm ("split_if_eq1", read_instantiate [("P", "%x. x = ?b")] split_if);
```
```   675 bind_thm ("split_if_eq2", read_instantiate [("P", "%x. ?a = x")] split_if);
```
```   676
```
```   677 (*Split ifs on either side of the membership relation.
```
```   678 	Not for Addsimps -- can cause goals to blow up!*)
```
```   679 bind_thm ("split_if_mem1",
```
```   680     read_instantiate_sg (Theory.sign_of Set.thy) [("P", "%x. x : ?b")] split_if);
```
```   681 bind_thm ("split_if_mem2",
```
```   682     read_instantiate_sg (Theory.sign_of Set.thy) [("P", "%x. ?a : x")] split_if);
```
```   683
```
```   684 val split_ifs = [if_bool_eq_conj, split_if_eq1, split_if_eq2,
```
```   685 		  split_if_mem1, split_if_mem2];
```
```   686
```
```   687
```
```   688 (*Each of these has ALREADY been added to simpset() above.*)
```
```   689 val mem_simps = [insert_iff, empty_iff, Un_iff, Int_iff, Compl_iff, Diff_iff,
```
```   690                  mem_Collect_eq, UN_iff, Union_iff, INT_iff, Inter_iff];
```
```   691
```
```   692 val mksimps_pairs = ("Ball",[bspec]) :: mksimps_pairs;
```
```   693
```
```   694 simpset_ref() := simpset() setmksimps (mksimps mksimps_pairs);
```
```   695
```
```   696 Addsimps[subset_UNIV, subset_refl];
```
```   697
```
```   698
```
```   699 (*** < ***)
```
```   700
```
```   701 Goalw [psubset_def] "!!A::'a set. [| A <= B; A ~= B |] ==> A<B";
```
```   702 by (Blast_tac 1);
```
```   703 qed "psubsetI";
```
```   704
```
```   705 Goalw [psubset_def] "A < insert x B ==> (x ~: A) & A<=B | x:A & A-{x}<B";
```
```   706 by Auto_tac;
```
```   707 qed "psubset_insertD";
```
```   708
```
```   709 bind_thm ("psubset_eq", psubset_def RS meta_eq_to_obj_eq);
```
```   710
```
```   711 bind_thm ("psubset_imp_subset", psubset_eq RS iffD1 RS conjunct1);
```
```   712
```
```   713 Goal"[| (A::'a set) < B; B <= C |] ==> A < C";
```
```   714 by (auto_tac (claset(), simpset() addsimps [psubset_eq]));
```
```   715 qed "psubset_subset_trans";
```
```   716
```
```   717 Goal"[| (A::'a set) <= B; B < C|] ==> A < C";
```
```   718 by (auto_tac (claset(), simpset() addsimps [psubset_eq]));
```
```   719 qed "subset_psubset_trans";
```