src/CCL/set.ML
 changeset 0 a5a9c433f639 child 8 c3d2c6dcf3f0
```     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/CCL/set.ML	Thu Sep 16 12:20:38 1993 +0200
1.3 @@ -0,0 +1,355 @@
1.4 +(*  Title: 	set/set
1.5 +    ID:         \$Id\$
1.6 +
1.7 +For set.thy.
1.8 +
1.9 +Modified version of
1.10 +    Title: 	HOL/set
1.11 +    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
1.12 +    Copyright   1991  University of Cambridge
1.13 +
1.14 +For set.thy.  Set theory for higher-order logic.  A set is simply a predicate.
1.15 +*)
1.16 +
1.17 +open Set;
1.18 +
1.19 +val [prem] = goal Set.thy "[| P(a) |] ==> a : {x.P(x)}";
1.20 +by (rtac (mem_Collect_iff RS iffD2) 1);
1.21 +by (rtac prem 1);
1.22 +val CollectI = result();
1.23 +
1.24 +val prems = goal Set.thy "[| a : {x.P(x)} |] ==> P(a)";
1.25 +by (resolve_tac (prems RL [mem_Collect_iff  RS iffD1]) 1);
1.26 +val CollectD = result();
1.27 +
1.28 +val [prem] = goal Set.thy "[| !!x. x:A <-> x:B |] ==> A = B";
1.29 +by (rtac (set_extension RS iffD2) 1);
1.30 +by (rtac (prem RS allI) 1);
1.31 +val set_ext = result();
1.32 +
1.33 +val prems = goal Set.thy "[| !!x. P(x) <-> Q(x) |] ==> {x. P(x)} = {x. Q(x)}";
1.34 +by (REPEAT (ares_tac [set_ext,iffI,CollectI] 1 ORELSE
1.35 +            eresolve_tac ([CollectD] RL (prems RL [iffD1,iffD2])) 1));
1.36 +val Collect_cong = result();
1.37 +
1.38 +val CollectE = make_elim CollectD;
1.39 +
1.40 +(*** Bounded quantifiers ***)
1.41 +
1.42 +val prems = goalw Set.thy [Ball_def]
1.43 +    "[| !!x. x:A ==> P(x) |] ==> ALL x:A. P(x)";
1.44 +by (REPEAT (ares_tac (prems @ [allI,impI]) 1));
1.45 +val ballI = result();
1.46 +
1.47 +val [major,minor] = goalw Set.thy [Ball_def]
1.48 +    "[| ALL x:A. P(x);  x:A |] ==> P(x)";
1.49 +by (rtac (minor RS (major RS spec RS mp)) 1);
1.50 +val bspec = result();
1.51 +
1.52 +val major::prems = goalw Set.thy [Ball_def]
1.53 +    "[| ALL x:A. P(x);  P(x) ==> Q;  ~ x:A ==> Q |] ==> Q";
1.54 +by (rtac (major RS spec RS impCE) 1);
1.55 +by (REPEAT (eresolve_tac prems 1));
1.56 +val ballE = result();
1.57 +
1.58 +(*Takes assumptions ALL x:A.P(x) and a:A; creates assumption P(a)*)
1.59 +fun ball_tac i = etac ballE i THEN contr_tac (i+1);
1.60 +
1.61 +val prems = goalw Set.thy [Bex_def]
1.62 +    "[| P(x);  x:A |] ==> EX x:A. P(x)";
1.63 +by (REPEAT (ares_tac (prems @ [exI,conjI]) 1));
1.64 +val bexI = result();
1.65 +
1.66 +val bexCI = prove_goal Set.thy
1.67 +   "[| EX x:A. ~P(x) ==> P(a);  a:A |] ==> EX x:A.P(x)"
1.68 + (fn prems=>
1.69 +  [ (rtac classical 1),
1.70 +    (REPEAT (ares_tac (prems@[bexI,ballI,notI,notE]) 1))  ]);
1.71 +
1.72 +val major::prems = goalw Set.thy [Bex_def]
1.73 +    "[| EX x:A. P(x);  !!x. [| x:A; P(x) |] ==> Q  |] ==> Q";
1.74 +by (rtac (major RS exE) 1);
1.75 +by (REPEAT (eresolve_tac (prems @ [asm_rl,conjE]) 1));
1.76 +val bexE = result();
1.77 +
1.78 +(*Trival rewrite rule;   (! x:A.P)=P holds only if A is nonempty!*)
1.79 +val prems = goal Set.thy
1.80 +    "(ALL x:A. True) <-> True";
1.81 +by (REPEAT (ares_tac [TrueI,ballI,iffI] 1));
1.82 +val ball_rew = result();
1.83 +
1.84 +(** Congruence rules **)
1.85 +
1.86 +val prems = goal Set.thy
1.87 +    "[| A=A';  !!x. x:A' ==> P(x) <-> P'(x) |] ==> \
1.88 +\    (ALL x:A. P(x)) <-> (ALL x:A'. P'(x))";
1.89 +by (resolve_tac (prems RL [ssubst,iffD2]) 1);
1.90 +by (REPEAT (ares_tac [ballI,iffI] 1
1.91 +     ORELSE eresolve_tac ([make_elim bspec, mp] @ (prems RL [iffE])) 1));
1.92 +val ball_cong = result();
1.93 +
1.94 +val prems = goal Set.thy
1.95 +    "[| A=A';  !!x. x:A' ==> P(x) <-> P'(x) |] ==> \
1.96 +\    (EX x:A. P(x)) <-> (EX x:A'. P'(x))";
1.97 +by (resolve_tac (prems RL [ssubst,iffD2]) 1);
1.98 +by (REPEAT (etac bexE 1
1.99 +     ORELSE ares_tac ([bexI,iffI] @ (prems RL [iffD1,iffD2])) 1));
1.100 +val bex_cong = result();
1.101 +
1.102 +(*** Rules for subsets ***)
1.103 +
1.104 +val prems = goalw Set.thy [subset_def] "(!!x.x:A ==> x:B) ==> A <= B";
1.105 +by (REPEAT (ares_tac (prems @ [ballI]) 1));
1.106 +val subsetI = result();
1.107 +
1.108 +(*Rule in Modus Ponens style*)
1.109 +val major::prems = goalw Set.thy [subset_def] "[| A <= B;  c:A |] ==> c:B";
1.110 +by (rtac (major RS bspec) 1);
1.111 +by (resolve_tac prems 1);
1.112 +val subsetD = result();
1.113 +
1.114 +(*Classical elimination rule*)
1.115 +val major::prems = goalw Set.thy [subset_def]
1.116 +    "[| A <= B;  ~(c:A) ==> P;  c:B ==> P |] ==> P";
1.117 +by (rtac (major RS ballE) 1);
1.118 +by (REPEAT (eresolve_tac prems 1));
1.119 +val subsetCE = result();
1.120 +
1.121 +(*Takes assumptions A<=B; c:A and creates the assumption c:B *)
1.122 +fun set_mp_tac i = etac subsetCE i  THEN  mp_tac i;
1.123 +
1.124 +val subset_refl = prove_goal Set.thy "A <= A"
1.125 + (fn _=> [ (REPEAT (ares_tac [subsetI] 1)) ]);
1.126 +
1.127 +goal Set.thy "!!A B C. [| A<=B;  B<=C |] ==> A<=C";
1.128 +br subsetI 1;
1.129 +by (REPEAT (eresolve_tac [asm_rl, subsetD] 1));
1.130 +val subset_trans = result();
1.131 +
1.132 +
1.133 +(*** Rules for equality ***)
1.134 +
1.135 +(*Anti-symmetry of the subset relation*)
1.136 +val prems = goal Set.thy "[| A <= B;  B <= A |] ==> A = B";
1.137 +by (rtac (iffI RS set_ext) 1);
1.138 +by (REPEAT (ares_tac (prems RL [subsetD]) 1));
1.139 +val subset_antisym = result();
1.140 +val equalityI = subset_antisym;
1.141 +
1.142 +(* Equality rules from ZF set theory -- are they appropriate here? *)
1.143 +val prems = goal Set.thy "A = B ==> A<=B";
1.144 +by (resolve_tac (prems RL [subst]) 1);
1.145 +by (rtac subset_refl 1);
1.146 +val equalityD1 = result();
1.147 +
1.148 +val prems = goal Set.thy "A = B ==> B<=A";
1.149 +by (resolve_tac (prems RL [subst]) 1);
1.150 +by (rtac subset_refl 1);
1.151 +val equalityD2 = result();
1.152 +
1.153 +val prems = goal Set.thy
1.154 +    "[| A = B;  [| A<=B; B<=A |] ==> P |]  ==>  P";
1.155 +by (resolve_tac prems 1);
1.156 +by (REPEAT (resolve_tac (prems RL [equalityD1,equalityD2]) 1));
1.157 +val equalityE = result();
1.158 +
1.159 +val major::prems = goal Set.thy
1.160 +    "[| A = B;  [| c:A; c:B |] ==> P;  [| ~ c:A; ~ c:B |] ==> P |]  ==>  P";
1.161 +by (rtac (major RS equalityE) 1);
1.162 +by (REPEAT (contr_tac 1 ORELSE eresolve_tac ([asm_rl,subsetCE]@prems) 1));
1.163 +val equalityCE = result();
1.164 +
1.165 +(*Lemma for creating induction formulae -- for "pattern matching" on p
1.166 +  To make the induction hypotheses usable, apply "spec" or "bspec" to
1.167 +  put universal quantifiers over the free variables in p. *)
1.168 +val prems = goal Set.thy
1.169 +    "[| p:A;  !!z. z:A ==> p=z --> R |] ==> R";
1.170 +by (rtac mp 1);
1.171 +by (REPEAT (resolve_tac (refl::prems) 1));
1.172 +val setup_induction = result();
1.173 +
1.174 +goal Set.thy "{x.x:A} = A";
1.175 +by (REPEAT (ares_tac [equalityI,subsetI,CollectI] 1  ORELSE eresolve_tac [CollectD] 1));
1.176 +val trivial_set = result();
1.177 +
1.178 +(*** Rules for binary union -- Un ***)
1.179 +
1.180 +val prems = goalw Set.thy [Un_def] "c:A ==> c : A Un B";
1.181 +by (REPEAT (resolve_tac (prems @ [CollectI,disjI1]) 1));
1.182 +val UnI1 = result();
1.183 +
1.184 +val prems = goalw Set.thy [Un_def] "c:B ==> c : A Un B";
1.185 +by (REPEAT (resolve_tac (prems @ [CollectI,disjI2]) 1));
1.186 +val UnI2 = result();
1.187 +
1.188 +(*Classical introduction rule: no commitment to A vs B*)
1.189 +val UnCI = prove_goal Set.thy "(~c:B ==> c:A) ==> c : A Un B"
1.190 + (fn prems=>
1.191 +  [ (rtac classical 1),
1.192 +    (REPEAT (ares_tac (prems@[UnI1,notI]) 1)),
1.193 +    (REPEAT (ares_tac (prems@[UnI2,notE]) 1)) ]);
1.194 +
1.195 +val major::prems = goalw Set.thy [Un_def]
1.196 +    "[| c : A Un B;  c:A ==> P;  c:B ==> P |] ==> P";
1.197 +by (rtac (major RS CollectD RS disjE) 1);
1.198 +by (REPEAT (eresolve_tac prems 1));
1.199 +val UnE = result();
1.200 +
1.201 +
1.202 +(*** Rules for small intersection -- Int ***)
1.203 +
1.204 +val prems = goalw Set.thy [Int_def]
1.205 +    "[| c:A;  c:B |] ==> c : A Int B";
1.206 +by (REPEAT (resolve_tac (prems @ [CollectI,conjI]) 1));
1.207 +val IntI = result();
1.208 +
1.209 +val [major] = goalw Set.thy [Int_def] "c : A Int B ==> c:A";
1.210 +by (rtac (major RS CollectD RS conjunct1) 1);
1.211 +val IntD1 = result();
1.212 +
1.213 +val [major] = goalw Set.thy [Int_def] "c : A Int B ==> c:B";
1.214 +by (rtac (major RS CollectD RS conjunct2) 1);
1.215 +val IntD2 = result();
1.216 +
1.217 +val [major,minor] = goal Set.thy
1.218 +    "[| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P";
1.219 +by (rtac minor 1);
1.220 +by (rtac (major RS IntD1) 1);
1.221 +by (rtac (major RS IntD2) 1);
1.222 +val IntE = result();
1.223 +
1.224 +
1.225 +(*** Rules for set complement -- Compl ***)
1.226 +
1.227 +val prems = goalw Set.thy [Compl_def]
1.228 +    "[| c:A ==> False |] ==> c : Compl(A)";
1.229 +by (REPEAT (ares_tac (prems @ [CollectI,notI]) 1));
1.230 +val ComplI = result();
1.231 +
1.232 +(*This form, with negated conclusion, works well with the Classical prover.
1.233 +  Negated assumptions behave like formulae on the right side of the notional
1.234 +  turnstile...*)
1.235 +val major::prems = goalw Set.thy [Compl_def]
1.236 +    "[| c : Compl(A) |] ==> ~c:A";
1.237 +by (rtac (major RS CollectD) 1);
1.238 +val ComplD = result();
1.239 +
1.240 +val ComplE = make_elim ComplD;
1.241 +
1.242 +
1.243 +(*** Empty sets ***)
1.244 +
1.245 +goalw Set.thy [empty_def] "{x.False} = {}";
1.246 +br refl 1;
1.247 +val empty_eq = result();
1.248 +
1.249 +val [prem] = goalw Set.thy [empty_def] "a : {} ==> P";
1.250 +by (rtac (prem RS CollectD RS FalseE) 1);
1.251 +val emptyD = result();
1.252 +
1.253 +val emptyE = make_elim emptyD;
1.254 +
1.255 +val [prem] = goal Set.thy "~ A={} ==> (EX x.x:A)";
1.256 +br (prem RS swap) 1;
1.257 +br equalityI 1;
1.259 +val not_emptyD = result();
1.260 +
1.261 +(*** Singleton sets ***)
1.262 +
1.263 +goalw Set.thy [singleton_def] "a : {a}";
1.264 +by (rtac CollectI 1);
1.265 +by (rtac refl 1);
1.266 +val singletonI = result();
1.267 +
1.268 +val [major] = goalw Set.thy [singleton_def] "b : {a} ==> b=a";
1.269 +by (rtac (major RS CollectD) 1);
1.270 +val singletonD = result();
1.271 +
1.272 +val singletonE = make_elim singletonD;
1.273 +
1.274 +(*** Unions of families ***)
1.275 +
1.276 +(*The order of the premises presupposes that A is rigid; b may be flexible*)
1.277 +val prems = goalw Set.thy [UNION_def]
1.278 +    "[| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))";
1.279 +by (REPEAT (resolve_tac (prems @ [bexI,CollectI]) 1));
1.280 +val UN_I = result();
1.281 +
1.282 +val major::prems = goalw Set.thy [UNION_def]
1.283 +    "[| b : (UN x:A. B(x));  !!x.[| x:A;  b: B(x) |] ==> R |] ==> R";
1.284 +by (rtac (major RS CollectD RS bexE) 1);
1.285 +by (REPEAT (ares_tac prems 1));
1.286 +val UN_E = result();
1.287 +
1.288 +val prems = goal Set.thy
1.289 +    "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
1.290 +\    (UN x:A. C(x)) = (UN x:B. D(x))";
1.291 +by (REPEAT (etac UN_E 1
1.292 +     ORELSE ares_tac ([UN_I,equalityI,subsetI] @
1.293 +		      (prems RL [equalityD1,equalityD2] RL [subsetD])) 1));
1.294 +val UN_cong = result();
1.295 +
1.296 +(*** Intersections of families -- INTER x:A. B(x) is Inter(B)``A ) *)
1.297 +
1.298 +val prems = goalw Set.thy [INTER_def]
1.299 +    "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))";
1.300 +by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1));
1.301 +val INT_I = result();
1.302 +
1.303 +val major::prems = goalw Set.thy [INTER_def]
1.304 +    "[| b : (INT x:A. B(x));  a:A |] ==> b: B(a)";
1.305 +by (rtac (major RS CollectD RS bspec) 1);
1.306 +by (resolve_tac prems 1);
1.307 +val INT_D = result();
1.308 +
1.309 +(*"Classical" elimination rule -- does not require proving X:C *)
1.310 +val major::prems = goalw Set.thy [INTER_def]
1.311 +    "[| b : (INT x:A. B(x));  b: B(a) ==> R;  ~ a:A ==> R |] ==> R";
1.312 +by (rtac (major RS CollectD RS ballE) 1);
1.313 +by (REPEAT (eresolve_tac prems 1));
1.314 +val INT_E = result();
1.315 +
1.316 +val prems = goal Set.thy
1.317 +    "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
1.318 +\    (INT x:A. C(x)) = (INT x:B. D(x))";
1.319 +by (REPEAT_FIRST (resolve_tac [INT_I,equalityI,subsetI]));
1.320 +by (REPEAT (dtac INT_D 1
1.321 +     ORELSE ares_tac (prems RL [equalityD1,equalityD2] RL [subsetD]) 1));
1.322 +val INT_cong = result();
1.323 +
1.324 +(*** Rules for Unions ***)
1.325 +
1.326 +(*The order of the premises presupposes that C is rigid; A may be flexible*)
1.327 +val prems = goalw Set.thy [Union_def]
1.328 +    "[| X:C;  A:X |] ==> A : Union(C)";
1.329 +by (REPEAT (resolve_tac (prems @ [UN_I]) 1));
1.330 +val UnionI = result();
1.331 +
1.332 +val major::prems = goalw Set.thy [Union_def]
1.333 +    "[| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R";
1.334 +by (rtac (major RS UN_E) 1);
1.335 +by (REPEAT (ares_tac prems 1));
1.336 +val UnionE = result();
1.337 +
1.338 +(*** Rules for Inter ***)
1.339 +
1.340 +val prems = goalw Set.thy [Inter_def]
1.341 +    "[| !!X. X:C ==> A:X |] ==> A : Inter(C)";
1.342 +by (REPEAT (ares_tac ([INT_I] @ prems) 1));
1.343 +val InterI = result();
1.344 +
1.345 +(*A "destruct" rule -- every X in C contains A as an element, but
1.346 +  A:X can hold when X:C does not!  This rule is analogous to "spec". *)
1.347 +val major::prems = goalw Set.thy [Inter_def]
1.348 +    "[| A : Inter(C);  X:C |] ==> A:X";
1.349 +by (rtac (major RS INT_D) 1);
1.350 +by (resolve_tac prems 1);
1.351 +val InterD = result();
1.352 +
1.353 +(*"Classical" elimination rule -- does not require proving X:C *)
1.354 +val major::prems = goalw Set.thy [Inter_def]
1.355 +    "[| A : Inter(C);  A:X ==> R;  ~ X:C ==> R |] ==> R";
1.356 +by (rtac (major RS INT_E) 1);
1.357 +by (REPEAT (eresolve_tac prems 1));
1.358 +val InterE = result();
```