src/HOL/Set.ML
 author paulson Wed Sep 25 11:14:18 1996 +0200 (1996-09-25) changeset 2024 909153d8318f parent 1985 84cf16192e03 child 2031 03a843f0f447 permissions -rw-r--r--
Rationalized the rewriting of membership for {} and insert
by deleting the redundant theorems in_empty and in_insert
```     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 val [prem] = goal Set.thy "P(a) ==> a : {x.P(x)}";
```
```    14 by (rtac (mem_Collect_eq RS ssubst) 1);
```
```    15 by (rtac prem 1);
```
```    16 qed "CollectI";
```
```    17
```
```    18 val prems = goal Set.thy "[| a : {x.P(x)} |] ==> P(a)";
```
```    19 by (resolve_tac (prems RL [mem_Collect_eq  RS subst]) 1);
```
```    20 qed "CollectD";
```
```    21
```
```    22 val [prem] = goal Set.thy "[| !!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 Set.thy "[| !!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 section "Bounded quantifiers";
```
```    35
```
```    36 val prems = goalw Set.thy [Ball_def]
```
```    37     "[| !!x. x:A ==> P(x) |] ==> ! x:A. P(x)";
```
```    38 by (REPEAT (ares_tac (prems @ [allI,impI]) 1));
```
```    39 qed "ballI";
```
```    40
```
```    41 val [major,minor] = goalw Set.thy [Ball_def]
```
```    42     "[| ! x:A. P(x);  x:A |] ==> P(x)";
```
```    43 by (rtac (minor RS (major RS spec RS mp)) 1);
```
```    44 qed "bspec";
```
```    45
```
```    46 val major::prems = goalw Set.thy [Ball_def]
```
```    47     "[| ! x:A. P(x);  P(x) ==> Q;  x~:A ==> Q |] ==> Q";
```
```    48 by (rtac (major RS spec RS impCE) 1);
```
```    49 by (REPEAT (eresolve_tac prems 1));
```
```    50 qed "ballE";
```
```    51
```
```    52 (*Takes assumptions ! x:A.P(x) and a:A; creates assumption P(a)*)
```
```    53 fun ball_tac i = etac ballE i THEN contr_tac (i+1);
```
```    54
```
```    55 val prems = goalw Set.thy [Bex_def]
```
```    56     "[| P(x);  x:A |] ==> ? x:A. P(x)";
```
```    57 by (REPEAT (ares_tac (prems @ [exI,conjI]) 1));
```
```    58 qed "bexI";
```
```    59
```
```    60 qed_goal "bexCI" Set.thy
```
```    61    "[| ! x:A. ~P(x) ==> P(a);  a:A |] ==> ? x:A.P(x)"
```
```    62  (fn prems=>
```
```    63   [ (rtac classical 1),
```
```    64     (REPEAT (ares_tac (prems@[bexI,ballI,notI,notE]) 1))  ]);
```
```    65
```
```    66 val major::prems = goalw Set.thy [Bex_def]
```
```    67     "[| ? x:A. P(x);  !!x. [| x:A; P(x) |] ==> Q  |] ==> Q";
```
```    68 by (rtac (major RS exE) 1);
```
```    69 by (REPEAT (eresolve_tac (prems @ [asm_rl,conjE]) 1));
```
```    70 qed "bexE";
```
```    71
```
```    72 (*Trival rewrite rule;   (! x:A.P)=P holds only if A is nonempty!*)
```
```    73 goalw Set.thy [Ball_def] "(! x:A. True) = True";
```
```    74 by (Simp_tac 1);
```
```    75 qed "ball_True";
```
```    76
```
```    77 (*Dual form for existentials*)
```
```    78 goalw Set.thy [Bex_def] "(? x:A. False) = False";
```
```    79 by (Simp_tac 1);
```
```    80 qed "bex_False";
```
```    81
```
```    82 Addsimps [ball_True, bex_False];
```
```    83
```
```    84 (** Congruence rules **)
```
```    85
```
```    86 val prems = goal Set.thy
```
```    87     "[| A=B;  !!x. x:B ==> P(x) = Q(x) |] ==> \
```
```    88 \    (! x:A. P(x)) = (! x:B. Q(x))";
```
```    89 by (resolve_tac (prems RL [ssubst]) 1);
```
```    90 by (REPEAT (ares_tac [ballI,iffI] 1
```
```    91      ORELSE eresolve_tac ([make_elim bspec, mp] @ (prems RL [iffE])) 1));
```
```    92 qed "ball_cong";
```
```    93
```
```    94 val prems = goal Set.thy
```
```    95     "[| A=B;  !!x. x:B ==> P(x) = Q(x) |] ==> \
```
```    96 \    (? x:A. P(x)) = (? x:B. Q(x))";
```
```    97 by (resolve_tac (prems RL [ssubst]) 1);
```
```    98 by (REPEAT (etac bexE 1
```
```    99      ORELSE ares_tac ([bexI,iffI] @ (prems RL [iffD1,iffD2])) 1));
```
```   100 qed "bex_cong";
```
```   101
```
```   102 section "Subsets";
```
```   103
```
```   104 val prems = goalw Set.thy [subset_def] "(!!x.x:A ==> x:B) ==> A <= B";
```
```   105 by (REPEAT (ares_tac (prems @ [ballI]) 1));
```
```   106 qed "subsetI";
```
```   107
```
```   108 (*Rule in Modus Ponens style*)
```
```   109 val major::prems = goalw Set.thy [subset_def] "[| A <= B;  c:A |] ==> c:B";
```
```   110 by (rtac (major RS bspec) 1);
```
```   111 by (resolve_tac prems 1);
```
```   112 qed "subsetD";
```
```   113
```
```   114 (*The same, with reversed premises for use with etac -- cf rev_mp*)
```
```   115 qed_goal "rev_subsetD" Set.thy "[| c:A;  A <= B |] ==> c:B"
```
```   116  (fn prems=>  [ (REPEAT (resolve_tac (prems@[subsetD]) 1)) ]);
```
```   117
```
```   118 (*Converts A<=B to x:A ==> x:B*)
```
```   119 fun impOfSubs th = th RSN (2, rev_subsetD);
```
```   120
```
```   121 qed_goal "contra_subsetD" Set.thy "!!c. [| A <= B; c ~: B |] ==> c ~: A"
```
```   122  (fn prems=>  [ (REPEAT (eresolve_tac [asm_rl, contrapos, subsetD] 1)) ]);
```
```   123
```
```   124 qed_goal "rev_contra_subsetD" Set.thy "!!c. [| c ~: B;  A <= B |] ==> c ~: A"
```
```   125  (fn prems=>  [ (REPEAT (eresolve_tac [asm_rl, contrapos, subsetD] 1)) ]);
```
```   126
```
```   127 (*Classical elimination rule*)
```
```   128 val major::prems = goalw Set.thy [subset_def]
```
```   129     "[| A <= B;  c~:A ==> P;  c:B ==> P |] ==> P";
```
```   130 by (rtac (major RS ballE) 1);
```
```   131 by (REPEAT (eresolve_tac prems 1));
```
```   132 qed "subsetCE";
```
```   133
```
```   134 (*Takes assumptions A<=B; c:A and creates the assumption c:B *)
```
```   135 fun set_mp_tac i = etac subsetCE i  THEN  mp_tac i;
```
```   136
```
```   137 qed_goal "subset_refl" Set.thy "A <= (A::'a set)"
```
```   138  (fn _=> [ (REPEAT (ares_tac [subsetI] 1)) ]);
```
```   139
```
```   140 val prems = goal Set.thy "[| A<=B;  B<=C |] ==> A<=(C::'a set)";
```
```   141 by (cut_facts_tac prems 1);
```
```   142 by (REPEAT (ares_tac [subsetI] 1 ORELSE set_mp_tac 1));
```
```   143 qed "subset_trans";
```
```   144
```
```   145
```
```   146 section "Equality";
```
```   147
```
```   148 (*Anti-symmetry of the subset relation*)
```
```   149 val prems = goal Set.thy "[| A <= B;  B <= A |] ==> A = (B::'a set)";
```
```   150 by (rtac (iffI RS set_ext) 1);
```
```   151 by (REPEAT (ares_tac (prems RL [subsetD]) 1));
```
```   152 qed "subset_antisym";
```
```   153 val equalityI = subset_antisym;
```
```   154
```
```   155 AddSIs [equalityI];
```
```   156
```
```   157 (* Equality rules from ZF set theory -- are they appropriate here? *)
```
```   158 val prems = goal Set.thy "A = B ==> A<=(B::'a set)";
```
```   159 by (resolve_tac (prems RL [subst]) 1);
```
```   160 by (rtac subset_refl 1);
```
```   161 qed "equalityD1";
```
```   162
```
```   163 val prems = goal Set.thy "A = B ==> B<=(A::'a set)";
```
```   164 by (resolve_tac (prems RL [subst]) 1);
```
```   165 by (rtac subset_refl 1);
```
```   166 qed "equalityD2";
```
```   167
```
```   168 val prems = goal Set.thy
```
```   169     "[| A = B;  [| A<=B; B<=(A::'a set) |] ==> P |]  ==>  P";
```
```   170 by (resolve_tac prems 1);
```
```   171 by (REPEAT (resolve_tac (prems RL [equalityD1,equalityD2]) 1));
```
```   172 qed "equalityE";
```
```   173
```
```   174 val major::prems = goal Set.thy
```
```   175     "[| A = B;  [| c:A; c:B |] ==> P;  [| c~:A; c~:B |] ==> P |]  ==>  P";
```
```   176 by (rtac (major RS equalityE) 1);
```
```   177 by (REPEAT (contr_tac 1 ORELSE eresolve_tac ([asm_rl,subsetCE]@prems) 1));
```
```   178 qed "equalityCE";
```
```   179
```
```   180 (*Lemma for creating induction formulae -- for "pattern matching" on p
```
```   181   To make the induction hypotheses usable, apply "spec" or "bspec" to
```
```   182   put universal quantifiers over the free variables in p. *)
```
```   183 val prems = goal Set.thy
```
```   184     "[| p:A;  !!z. z:A ==> p=z --> R |] ==> R";
```
```   185 by (rtac mp 1);
```
```   186 by (REPEAT (resolve_tac (refl::prems) 1));
```
```   187 qed "setup_induction";
```
```   188
```
```   189
```
```   190 section "Set complement -- Compl";
```
```   191
```
```   192 val prems = goalw Set.thy [Compl_def]
```
```   193     "[| c:A ==> False |] ==> c : Compl(A)";
```
```   194 by (REPEAT (ares_tac (prems @ [CollectI,notI]) 1));
```
```   195 qed "ComplI";
```
```   196
```
```   197 (*This form, with negated conclusion, works well with the Classical prover.
```
```   198   Negated assumptions behave like formulae on the right side of the notional
```
```   199   turnstile...*)
```
```   200 val major::prems = goalw Set.thy [Compl_def]
```
```   201     "[| c : Compl(A) |] ==> c~:A";
```
```   202 by (rtac (major RS CollectD) 1);
```
```   203 qed "ComplD";
```
```   204
```
```   205 val ComplE = make_elim ComplD;
```
```   206
```
```   207 qed_goal "Compl_iff" Set.thy "(c : Compl(A)) = (c~:A)"
```
```   208  (fn _ => [ (fast_tac (!claset addSIs [ComplI] addSEs [ComplE]) 1) ]);
```
```   209
```
```   210
```
```   211 section "Binary union -- Un";
```
```   212
```
```   213 val prems = goalw Set.thy [Un_def] "c:A ==> c : A Un B";
```
```   214 by (REPEAT (resolve_tac (prems @ [CollectI,disjI1]) 1));
```
```   215 qed "UnI1";
```
```   216
```
```   217 val prems = goalw Set.thy [Un_def] "c:B ==> c : A Un B";
```
```   218 by (REPEAT (resolve_tac (prems @ [CollectI,disjI2]) 1));
```
```   219 qed "UnI2";
```
```   220
```
```   221 (*Classical introduction rule: no commitment to A vs B*)
```
```   222 qed_goal "UnCI" Set.thy "(c~:B ==> c:A) ==> c : A Un B"
```
```   223  (fn prems=>
```
```   224   [ (rtac classical 1),
```
```   225     (REPEAT (ares_tac (prems@[UnI1,notI]) 1)),
```
```   226     (REPEAT (ares_tac (prems@[UnI2,notE]) 1)) ]);
```
```   227
```
```   228 val major::prems = goalw Set.thy [Un_def]
```
```   229     "[| c : A Un B;  c:A ==> P;  c:B ==> P |] ==> P";
```
```   230 by (rtac (major RS CollectD RS disjE) 1);
```
```   231 by (REPEAT (eresolve_tac prems 1));
```
```   232 qed "UnE";
```
```   233
```
```   234 qed_goal "Un_iff" Set.thy "(c : A Un B) = (c:A | c:B)"
```
```   235  (fn _ => [ (fast_tac (!claset addSIs [UnCI] addSEs [UnE]) 1) ]);
```
```   236
```
```   237
```
```   238 section "Binary intersection -- Int";
```
```   239
```
```   240 val prems = goalw Set.thy [Int_def]
```
```   241     "[| c:A;  c:B |] ==> c : A Int B";
```
```   242 by (REPEAT (resolve_tac (prems @ [CollectI,conjI]) 1));
```
```   243 qed "IntI";
```
```   244
```
```   245 val [major] = goalw Set.thy [Int_def] "c : A Int B ==> c:A";
```
```   246 by (rtac (major RS CollectD RS conjunct1) 1);
```
```   247 qed "IntD1";
```
```   248
```
```   249 val [major] = goalw Set.thy [Int_def] "c : A Int B ==> c:B";
```
```   250 by (rtac (major RS CollectD RS conjunct2) 1);
```
```   251 qed "IntD2";
```
```   252
```
```   253 val [major,minor] = goal Set.thy
```
```   254     "[| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P";
```
```   255 by (rtac minor 1);
```
```   256 by (rtac (major RS IntD1) 1);
```
```   257 by (rtac (major RS IntD2) 1);
```
```   258 qed "IntE";
```
```   259
```
```   260 qed_goal "Int_iff" Set.thy "(c : A Int B) = (c:A & c:B)"
```
```   261  (fn _ => [ (fast_tac (!claset addSIs [IntI] addSEs [IntE]) 1) ]);
```
```   262
```
```   263
```
```   264 section "Set difference";
```
```   265
```
```   266 qed_goalw "DiffI" Set.thy [set_diff_def]
```
```   267     "[| c : A;  c ~: B |] ==> c : A - B"
```
```   268  (fn prems=> [ (REPEAT (resolve_tac (prems @ [CollectI,conjI]) 1)) ]);
```
```   269
```
```   270 qed_goalw "DiffD1" Set.thy [set_diff_def]
```
```   271     "c : A - B ==> c : A"
```
```   272  (fn [major]=> [ (rtac (major RS CollectD RS conjunct1) 1) ]);
```
```   273
```
```   274 qed_goalw "DiffD2" Set.thy [set_diff_def]
```
```   275     "[| c : A - B;  c : B |] ==> P"
```
```   276  (fn [major,minor]=>
```
```   277      [rtac (minor RS (major RS CollectD RS conjunct2 RS notE)) 1]);
```
```   278
```
```   279 qed_goal "DiffE" Set.thy
```
```   280     "[| c : A - B;  [| c:A; c~:B |] ==> P |] ==> P"
```
```   281  (fn prems=>
```
```   282   [ (resolve_tac prems 1),
```
```   283     (REPEAT (ares_tac (prems RL [DiffD1, DiffD2 RS notI]) 1)) ]);
```
```   284
```
```   285 qed_goal "Diff_iff" Set.thy "(c : A-B) = (c:A & c~:B)"
```
```   286  (fn _ => [ (fast_tac (!claset addSIs [DiffI] addSEs [DiffE]) 1) ]);
```
```   287
```
```   288 section "The empty set -- {}";
```
```   289
```
```   290 qed_goalw "emptyE" Set.thy [empty_def] "a:{} ==> P"
```
```   291  (fn [prem] => [rtac (prem RS CollectD RS FalseE) 1]);
```
```   292
```
```   293 qed_goal "empty_subsetI" Set.thy "{} <= A"
```
```   294  (fn _ => [ (REPEAT (ares_tac [equalityI,subsetI,emptyE] 1)) ]);
```
```   295
```
```   296 qed_goal "equals0I" Set.thy "[| !!y. y:A ==> False |] ==> A={}"
```
```   297  (fn prems=>
```
```   298   [ (REPEAT (ares_tac (prems@[empty_subsetI,subsetI,equalityI]) 1
```
```   299       ORELSE eresolve_tac (prems RL [FalseE]) 1)) ]);
```
```   300
```
```   301 qed_goal "equals0D" Set.thy "[| A={};  a:A |] ==> P"
```
```   302  (fn [major,minor]=>
```
```   303   [ (rtac (minor RS (major RS equalityD1 RS subsetD RS emptyE)) 1) ]);
```
```   304
```
```   305 qed_goal "empty_iff" Set.thy "(c : {}) = False"
```
```   306  (fn _ => [ (fast_tac (!claset addSEs [emptyE]) 1) ]);
```
```   307
```
```   308 goal Set.thy "Ball {} P = True";
```
```   309 by (simp_tac (HOL_ss addsimps [mem_Collect_eq, Ball_def, empty_def]) 1);
```
```   310 qed "ball_empty";
```
```   311
```
```   312 goal Set.thy "Bex {} P = False";
```
```   313 by (simp_tac (HOL_ss addsimps [mem_Collect_eq, Bex_def, empty_def]) 1);
```
```   314 qed "bex_empty";
```
```   315 Addsimps [ball_empty, bex_empty];
```
```   316
```
```   317
```
```   318 section "Augmenting a set -- insert";
```
```   319
```
```   320 qed_goalw "insertI1" Set.thy [insert_def] "a : insert a B"
```
```   321  (fn _ => [rtac (CollectI RS UnI1) 1, rtac refl 1]);
```
```   322
```
```   323 qed_goalw "insertI2" Set.thy [insert_def] "a : B ==> a : insert b B"
```
```   324  (fn [prem]=> [ (rtac (prem RS UnI2) 1) ]);
```
```   325
```
```   326 qed_goalw "insertE" Set.thy [insert_def]
```
```   327     "[| a : insert b A;  a=b ==> P;  a:A ==> P |] ==> P"
```
```   328  (fn major::prems=>
```
```   329   [ (rtac (major RS UnE) 1),
```
```   330     (REPEAT (eresolve_tac (prems @ [CollectE]) 1)) ]);
```
```   331
```
```   332 qed_goal "insert_iff" Set.thy "a : insert b A = (a=b | a:A)"
```
```   333  (fn _ => [fast_tac (!claset addIs [insertI1,insertI2] addSEs [insertE]) 1]);
```
```   334
```
```   335 (*Classical introduction rule*)
```
```   336 qed_goal "insertCI" Set.thy "(a~:B ==> a=b) ==> a: insert b B"
```
```   337  (fn [prem]=>
```
```   338   [ (rtac (disjCI RS (insert_iff RS iffD2)) 1),
```
```   339     (etac prem 1) ]);
```
```   340
```
```   341 section "Singletons, using insert";
```
```   342
```
```   343 qed_goal "singletonI" Set.thy "a : {a}"
```
```   344  (fn _=> [ (rtac insertI1 1) ]);
```
```   345
```
```   346 goalw Set.thy [insert_def] "!!a. b : {a} ==> b=a";
```
```   347 by (fast_tac (!claset addSEs [emptyE,CollectE,UnE]) 1);
```
```   348 qed "singletonD";
```
```   349
```
```   350 bind_thm ("singletonE", make_elim singletonD);
```
```   351
```
```   352 qed_goal "singleton_iff" thy "(b : {a}) = (b=a)" (fn _ => [
```
```   353 	rtac iffI 1,
```
```   354 	etac singletonD 1,
```
```   355 	hyp_subst_tac 1,
```
```   356 	rtac singletonI 1]);
```
```   357
```
```   358 val [major] = goal Set.thy "{a}={b} ==> a=b";
```
```   359 by (rtac (major RS equalityD1 RS subsetD RS singletonD) 1);
```
```   360 by (rtac singletonI 1);
```
```   361 qed "singleton_inject";
```
```   362
```
```   363
```
```   364 section "The universal set -- UNIV";
```
```   365
```
```   366 qed_goal "UNIV_I" Set.thy "x : UNIV"
```
```   367   (fn _ => [rtac ComplI 1, etac emptyE 1]);
```
```   368
```
```   369 qed_goal "subset_UNIV" Set.thy "A <= UNIV"
```
```   370   (fn _ => [rtac subsetI 1, rtac UNIV_I 1]);
```
```   371
```
```   372
```
```   373 section "Unions of families -- UNION x:A. B(x) is Union(B``A)";
```
```   374
```
```   375 (*The order of the premises presupposes that A is rigid; b may be flexible*)
```
```   376 val prems = goalw Set.thy [UNION_def]
```
```   377     "[| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))";
```
```   378 by (REPEAT (resolve_tac (prems @ [bexI,CollectI]) 1));
```
```   379 qed "UN_I";
```
```   380
```
```   381 val major::prems = goalw Set.thy [UNION_def]
```
```   382     "[| b : (UN x:A. B(x));  !!x.[| x:A;  b: B(x) |] ==> R |] ==> R";
```
```   383 by (rtac (major RS CollectD RS bexE) 1);
```
```   384 by (REPEAT (ares_tac prems 1));
```
```   385 qed "UN_E";
```
```   386
```
```   387 val prems = goal Set.thy
```
```   388     "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
```
```   389 \    (UN x:A. C(x)) = (UN x:B. D(x))";
```
```   390 by (REPEAT (etac UN_E 1
```
```   391      ORELSE ares_tac ([UN_I,equalityI,subsetI] @
```
```   392                       (prems RL [equalityD1,equalityD2] RL [subsetD])) 1));
```
```   393 qed "UN_cong";
```
```   394
```
```   395
```
```   396 section "Intersections of families -- INTER x:A. B(x) is Inter(B``A)";
```
```   397
```
```   398 val prems = goalw Set.thy [INTER_def]
```
```   399     "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))";
```
```   400 by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1));
```
```   401 qed "INT_I";
```
```   402
```
```   403 val major::prems = goalw Set.thy [INTER_def]
```
```   404     "[| b : (INT x:A. B(x));  a:A |] ==> b: B(a)";
```
```   405 by (rtac (major RS CollectD RS bspec) 1);
```
```   406 by (resolve_tac prems 1);
```
```   407 qed "INT_D";
```
```   408
```
```   409 (*"Classical" elimination -- by the Excluded Middle on a:A *)
```
```   410 val major::prems = goalw Set.thy [INTER_def]
```
```   411     "[| b : (INT x:A. B(x));  b: B(a) ==> R;  a~:A ==> R |] ==> R";
```
```   412 by (rtac (major RS CollectD RS ballE) 1);
```
```   413 by (REPEAT (eresolve_tac prems 1));
```
```   414 qed "INT_E";
```
```   415
```
```   416 val prems = goal Set.thy
```
```   417     "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
```
```   418 \    (INT x:A. C(x)) = (INT x:B. D(x))";
```
```   419 by (REPEAT_FIRST (resolve_tac [INT_I,equalityI,subsetI]));
```
```   420 by (REPEAT (dtac INT_D 1
```
```   421      ORELSE ares_tac (prems RL [equalityD1,equalityD2] RL [subsetD]) 1));
```
```   422 qed "INT_cong";
```
```   423
```
```   424
```
```   425 section "Unions over a type; UNION1(B) = Union(range(B))";
```
```   426
```
```   427 (*The order of the premises presupposes that A is rigid; b may be flexible*)
```
```   428 val prems = goalw Set.thy [UNION1_def]
```
```   429     "b: B(x) ==> b: (UN x. B(x))";
```
```   430 by (REPEAT (resolve_tac (prems @ [TrueI, CollectI RS UN_I]) 1));
```
```   431 qed "UN1_I";
```
```   432
```
```   433 val major::prems = goalw Set.thy [UNION1_def]
```
```   434     "[| b : (UN x. B(x));  !!x. b: B(x) ==> R |] ==> R";
```
```   435 by (rtac (major RS UN_E) 1);
```
```   436 by (REPEAT (ares_tac prems 1));
```
```   437 qed "UN1_E";
```
```   438
```
```   439
```
```   440 section "Intersections over a type; INTER1(B) = Inter(range(B))";
```
```   441
```
```   442 val prems = goalw Set.thy [INTER1_def]
```
```   443     "(!!x. b: B(x)) ==> b : (INT x. B(x))";
```
```   444 by (REPEAT (ares_tac (INT_I::prems) 1));
```
```   445 qed "INT1_I";
```
```   446
```
```   447 val [major] = goalw Set.thy [INTER1_def]
```
```   448     "b : (INT x. B(x)) ==> b: B(a)";
```
```   449 by (rtac (TrueI RS (CollectI RS (major RS INT_D))) 1);
```
```   450 qed "INT1_D";
```
```   451
```
```   452 section "Union";
```
```   453
```
```   454 (*The order of the premises presupposes that C is rigid; A may be flexible*)
```
```   455 val prems = goalw Set.thy [Union_def]
```
```   456     "[| X:C;  A:X |] ==> A : Union(C)";
```
```   457 by (REPEAT (resolve_tac (prems @ [UN_I]) 1));
```
```   458 qed "UnionI";
```
```   459
```
```   460 val major::prems = goalw Set.thy [Union_def]
```
```   461     "[| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R";
```
```   462 by (rtac (major RS UN_E) 1);
```
```   463 by (REPEAT (ares_tac prems 1));
```
```   464 qed "UnionE";
```
```   465
```
```   466 section "Inter";
```
```   467
```
```   468 val prems = goalw Set.thy [Inter_def]
```
```   469     "[| !!X. X:C ==> A:X |] ==> A : Inter(C)";
```
```   470 by (REPEAT (ares_tac ([INT_I] @ prems) 1));
```
```   471 qed "InterI";
```
```   472
```
```   473 (*A "destruct" rule -- every X in C contains A as an element, but
```
```   474   A:X can hold when X:C does not!  This rule is analogous to "spec". *)
```
```   475 val major::prems = goalw Set.thy [Inter_def]
```
```   476     "[| A : Inter(C);  X:C |] ==> A:X";
```
```   477 by (rtac (major RS INT_D) 1);
```
```   478 by (resolve_tac prems 1);
```
```   479 qed "InterD";
```
```   480
```
```   481 (*"Classical" elimination rule -- does not require proving X:C *)
```
```   482 val major::prems = goalw Set.thy [Inter_def]
```
```   483     "[| A : Inter(C);  A:X ==> R;  X~:C ==> R |] ==> R";
```
```   484 by (rtac (major RS INT_E) 1);
```
```   485 by (REPEAT (eresolve_tac prems 1));
```
```   486 qed "InterE";
```
```   487
```
```   488 section "The Powerset operator -- Pow";
```
```   489
```
```   490 qed_goalw "PowI" Set.thy [Pow_def] "!!A B. A <= B ==> A : Pow(B)"
```
```   491  (fn _ => [ (etac CollectI 1) ]);
```
```   492
```
```   493 qed_goalw "PowD" Set.thy [Pow_def] "!!A B. A : Pow(B)  ==>  A<=B"
```
```   494  (fn _=> [ (etac CollectD 1) ]);
```
```   495
```
```   496 val Pow_bottom = empty_subsetI RS PowI;        (* {}: Pow(B) *)
```
```   497 val Pow_top = subset_refl RS PowI;             (* A : Pow(A) *)
```
```   498
```
```   499
```
```   500
```
```   501 (*** Set reasoning tools ***)
```
```   502
```
```   503
```
```   504 val mem_simps = [insert_iff, empty_iff, Un_iff, Int_iff, Compl_iff, Diff_iff,
```
```   505 		 mem_Collect_eq];
```
```   506
```
```   507 (*Not for Addsimps -- it can cause goals to blow up!*)
```
```   508 goal Set.thy "(a : (if Q then x else y)) = ((Q --> a:x) & (~Q --> a : y))";
```
```   509 by (simp_tac (!simpset setloop split_tac [expand_if]) 1);
```
```   510 qed "mem_if";
```
```   511
```
```   512 val mksimps_pairs = ("Ball",[bspec]) :: mksimps_pairs;
```
```   513
```
```   514 simpset := !simpset addsimps mem_simps
```
```   515                     addcongs [ball_cong,bex_cong]
```
```   516                     setmksimps (mksimps mksimps_pairs);
```