author | wenzelm |
Wed, 03 Feb 1999 20:25:53 +0100 | |
changeset 6219 | b360065c2b07 |
parent 5143 | b94cd208f073 |
child 17456 | bcf7544875b2 |
permissions | -rw-r--r-- |
1459 | 1 |
(* Title: set/set |
0 | 2 |
ID: $Id$ |
3 |
||
4 |
For set.thy. |
|
5 |
||
6 |
Modified version of |
|
1459 | 7 |
Title: HOL/set |
8 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
0 | 9 |
Copyright 1991 University of Cambridge |
10 |
||
11 |
For set.thy. Set theory for higher-order logic. A set is simply a predicate. |
|
12 |
*) |
|
13 |
||
14 |
open Set; |
|
15 |
||
3837 | 16 |
val [prem] = goal Set.thy "[| P(a) |] ==> a : {x. P(x)}"; |
0 | 17 |
by (rtac (mem_Collect_iff RS iffD2) 1); |
18 |
by (rtac prem 1); |
|
757 | 19 |
qed "CollectI"; |
0 | 20 |
|
3837 | 21 |
val prems = goal Set.thy "[| a : {x. P(x)} |] ==> P(a)"; |
0 | 22 |
by (resolve_tac (prems RL [mem_Collect_iff RS iffD1]) 1); |
757 | 23 |
qed "CollectD"; |
0 | 24 |
|
8
c3d2c6dcf3f0
Installation of new simplfier. Previously appeared to set up the old
lcp
parents:
0
diff
changeset
|
25 |
val CollectE = make_elim CollectD; |
c3d2c6dcf3f0
Installation of new simplfier. Previously appeared to set up the old
lcp
parents:
0
diff
changeset
|
26 |
|
0 | 27 |
val [prem] = goal Set.thy "[| !!x. x:A <-> x:B |] ==> A = B"; |
28 |
by (rtac (set_extension RS iffD2) 1); |
|
29 |
by (rtac (prem RS allI) 1); |
|
757 | 30 |
qed "set_ext"; |
0 | 31 |
|
32 |
(*** Bounded quantifiers ***) |
|
33 |
||
34 |
val prems = goalw Set.thy [Ball_def] |
|
35 |
"[| !!x. x:A ==> P(x) |] ==> ALL x:A. P(x)"; |
|
36 |
by (REPEAT (ares_tac (prems @ [allI,impI]) 1)); |
|
757 | 37 |
qed "ballI"; |
0 | 38 |
|
39 |
val [major,minor] = goalw Set.thy [Ball_def] |
|
40 |
"[| ALL x:A. P(x); x:A |] ==> P(x)"; |
|
41 |
by (rtac (minor RS (major RS spec RS mp)) 1); |
|
757 | 42 |
qed "bspec"; |
0 | 43 |
|
44 |
val major::prems = goalw Set.thy [Ball_def] |
|
45 |
"[| ALL x:A. P(x); P(x) ==> Q; ~ x:A ==> Q |] ==> Q"; |
|
46 |
by (rtac (major RS spec RS impCE) 1); |
|
47 |
by (REPEAT (eresolve_tac prems 1)); |
|
757 | 48 |
qed "ballE"; |
0 | 49 |
|
50 |
(*Takes assumptions ALL x:A.P(x) and a:A; creates assumption P(a)*) |
|
51 |
fun ball_tac i = etac ballE i THEN contr_tac (i+1); |
|
52 |
||
53 |
val prems = goalw Set.thy [Bex_def] |
|
54 |
"[| P(x); x:A |] ==> EX x:A. P(x)"; |
|
55 |
by (REPEAT (ares_tac (prems @ [exI,conjI]) 1)); |
|
757 | 56 |
qed "bexI"; |
0 | 57 |
|
757 | 58 |
qed_goal "bexCI" Set.thy |
3837 | 59 |
"[| EX x:A. ~P(x) ==> P(a); a:A |] ==> EX x:A. P(x)" |
0 | 60 |
(fn prems=> |
61 |
[ (rtac classical 1), |
|
62 |
(REPEAT (ares_tac (prems@[bexI,ballI,notI,notE]) 1)) ]); |
|
63 |
||
64 |
val major::prems = goalw Set.thy [Bex_def] |
|
65 |
"[| EX x:A. P(x); !!x. [| x:A; P(x) |] ==> Q |] ==> Q"; |
|
66 |
by (rtac (major RS exE) 1); |
|
67 |
by (REPEAT (eresolve_tac (prems @ [asm_rl,conjE]) 1)); |
|
757 | 68 |
qed "bexE"; |
0 | 69 |
|
70 |
(*Trival rewrite rule; (! x:A.P)=P holds only if A is nonempty!*) |
|
71 |
val prems = goal Set.thy |
|
72 |
"(ALL x:A. True) <-> True"; |
|
73 |
by (REPEAT (ares_tac [TrueI,ballI,iffI] 1)); |
|
757 | 74 |
qed "ball_rew"; |
0 | 75 |
|
76 |
(** Congruence rules **) |
|
77 |
||
78 |
val prems = goal Set.thy |
|
79 |
"[| A=A'; !!x. x:A' ==> P(x) <-> P'(x) |] ==> \ |
|
80 |
\ (ALL x:A. P(x)) <-> (ALL x:A'. P'(x))"; |
|
81 |
by (resolve_tac (prems RL [ssubst,iffD2]) 1); |
|
82 |
by (REPEAT (ares_tac [ballI,iffI] 1 |
|
83 |
ORELSE eresolve_tac ([make_elim bspec, mp] @ (prems RL [iffE])) 1)); |
|
757 | 84 |
qed "ball_cong"; |
0 | 85 |
|
86 |
val prems = goal Set.thy |
|
87 |
"[| A=A'; !!x. x:A' ==> P(x) <-> P'(x) |] ==> \ |
|
88 |
\ (EX x:A. P(x)) <-> (EX x:A'. P'(x))"; |
|
89 |
by (resolve_tac (prems RL [ssubst,iffD2]) 1); |
|
90 |
by (REPEAT (etac bexE 1 |
|
91 |
ORELSE ares_tac ([bexI,iffI] @ (prems RL [iffD1,iffD2])) 1)); |
|
757 | 92 |
qed "bex_cong"; |
0 | 93 |
|
94 |
(*** Rules for subsets ***) |
|
95 |
||
3837 | 96 |
val prems = goalw Set.thy [subset_def] "(!!x. x:A ==> x:B) ==> A <= B"; |
0 | 97 |
by (REPEAT (ares_tac (prems @ [ballI]) 1)); |
757 | 98 |
qed "subsetI"; |
0 | 99 |
|
100 |
(*Rule in Modus Ponens style*) |
|
101 |
val major::prems = goalw Set.thy [subset_def] "[| A <= B; c:A |] ==> c:B"; |
|
102 |
by (rtac (major RS bspec) 1); |
|
103 |
by (resolve_tac prems 1); |
|
757 | 104 |
qed "subsetD"; |
0 | 105 |
|
106 |
(*Classical elimination rule*) |
|
107 |
val major::prems = goalw Set.thy [subset_def] |
|
108 |
"[| A <= B; ~(c:A) ==> P; c:B ==> P |] ==> P"; |
|
109 |
by (rtac (major RS ballE) 1); |
|
110 |
by (REPEAT (eresolve_tac prems 1)); |
|
757 | 111 |
qed "subsetCE"; |
0 | 112 |
|
113 |
(*Takes assumptions A<=B; c:A and creates the assumption c:B *) |
|
114 |
fun set_mp_tac i = etac subsetCE i THEN mp_tac i; |
|
115 |
||
757 | 116 |
qed_goal "subset_refl" Set.thy "A <= A" |
0 | 117 |
(fn _=> [ (REPEAT (ares_tac [subsetI] 1)) ]); |
118 |
||
5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5062
diff
changeset
|
119 |
Goal "[| A<=B; B<=C |] ==> A<=C"; |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
8
diff
changeset
|
120 |
by (rtac subsetI 1); |
0 | 121 |
by (REPEAT (eresolve_tac [asm_rl, subsetD] 1)); |
757 | 122 |
qed "subset_trans"; |
0 | 123 |
|
124 |
||
125 |
(*** Rules for equality ***) |
|
126 |
||
127 |
(*Anti-symmetry of the subset relation*) |
|
128 |
val prems = goal Set.thy "[| A <= B; B <= A |] ==> A = B"; |
|
129 |
by (rtac (iffI RS set_ext) 1); |
|
130 |
by (REPEAT (ares_tac (prems RL [subsetD]) 1)); |
|
757 | 131 |
qed "subset_antisym"; |
0 | 132 |
val equalityI = subset_antisym; |
133 |
||
134 |
(* Equality rules from ZF set theory -- are they appropriate here? *) |
|
135 |
val prems = goal Set.thy "A = B ==> A<=B"; |
|
136 |
by (resolve_tac (prems RL [subst]) 1); |
|
137 |
by (rtac subset_refl 1); |
|
757 | 138 |
qed "equalityD1"; |
0 | 139 |
|
140 |
val prems = goal Set.thy "A = B ==> B<=A"; |
|
141 |
by (resolve_tac (prems RL [subst]) 1); |
|
142 |
by (rtac subset_refl 1); |
|
757 | 143 |
qed "equalityD2"; |
0 | 144 |
|
145 |
val prems = goal Set.thy |
|
146 |
"[| A = B; [| A<=B; B<=A |] ==> P |] ==> P"; |
|
147 |
by (resolve_tac prems 1); |
|
148 |
by (REPEAT (resolve_tac (prems RL [equalityD1,equalityD2]) 1)); |
|
757 | 149 |
qed "equalityE"; |
0 | 150 |
|
151 |
val major::prems = goal Set.thy |
|
152 |
"[| A = B; [| c:A; c:B |] ==> P; [| ~ c:A; ~ c:B |] ==> P |] ==> P"; |
|
153 |
by (rtac (major RS equalityE) 1); |
|
154 |
by (REPEAT (contr_tac 1 ORELSE eresolve_tac ([asm_rl,subsetCE]@prems) 1)); |
|
757 | 155 |
qed "equalityCE"; |
0 | 156 |
|
157 |
(*Lemma for creating induction formulae -- for "pattern matching" on p |
|
158 |
To make the induction hypotheses usable, apply "spec" or "bspec" to |
|
159 |
put universal quantifiers over the free variables in p. *) |
|
160 |
val prems = goal Set.thy |
|
161 |
"[| p:A; !!z. z:A ==> p=z --> R |] ==> R"; |
|
162 |
by (rtac mp 1); |
|
163 |
by (REPEAT (resolve_tac (refl::prems) 1)); |
|
757 | 164 |
qed "setup_induction"; |
0 | 165 |
|
5062 | 166 |
Goal "{x. x:A} = A"; |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
8
diff
changeset
|
167 |
by (REPEAT (ares_tac [equalityI,subsetI,CollectI] 1 ORELSE etac CollectD 1)); |
757 | 168 |
qed "trivial_set"; |
0 | 169 |
|
170 |
(*** Rules for binary union -- Un ***) |
|
171 |
||
172 |
val prems = goalw Set.thy [Un_def] "c:A ==> c : A Un B"; |
|
173 |
by (REPEAT (resolve_tac (prems @ [CollectI,disjI1]) 1)); |
|
757 | 174 |
qed "UnI1"; |
0 | 175 |
|
176 |
val prems = goalw Set.thy [Un_def] "c:B ==> c : A Un B"; |
|
177 |
by (REPEAT (resolve_tac (prems @ [CollectI,disjI2]) 1)); |
|
757 | 178 |
qed "UnI2"; |
0 | 179 |
|
180 |
(*Classical introduction rule: no commitment to A vs B*) |
|
757 | 181 |
qed_goal "UnCI" Set.thy "(~c:B ==> c:A) ==> c : A Un B" |
0 | 182 |
(fn prems=> |
183 |
[ (rtac classical 1), |
|
184 |
(REPEAT (ares_tac (prems@[UnI1,notI]) 1)), |
|
185 |
(REPEAT (ares_tac (prems@[UnI2,notE]) 1)) ]); |
|
186 |
||
187 |
val major::prems = goalw Set.thy [Un_def] |
|
188 |
"[| c : A Un B; c:A ==> P; c:B ==> P |] ==> P"; |
|
189 |
by (rtac (major RS CollectD RS disjE) 1); |
|
190 |
by (REPEAT (eresolve_tac prems 1)); |
|
757 | 191 |
qed "UnE"; |
0 | 192 |
|
193 |
||
194 |
(*** Rules for small intersection -- Int ***) |
|
195 |
||
196 |
val prems = goalw Set.thy [Int_def] |
|
197 |
"[| c:A; c:B |] ==> c : A Int B"; |
|
198 |
by (REPEAT (resolve_tac (prems @ [CollectI,conjI]) 1)); |
|
757 | 199 |
qed "IntI"; |
0 | 200 |
|
201 |
val [major] = goalw Set.thy [Int_def] "c : A Int B ==> c:A"; |
|
202 |
by (rtac (major RS CollectD RS conjunct1) 1); |
|
757 | 203 |
qed "IntD1"; |
0 | 204 |
|
205 |
val [major] = goalw Set.thy [Int_def] "c : A Int B ==> c:B"; |
|
206 |
by (rtac (major RS CollectD RS conjunct2) 1); |
|
757 | 207 |
qed "IntD2"; |
0 | 208 |
|
209 |
val [major,minor] = goal Set.thy |
|
210 |
"[| c : A Int B; [| c:A; c:B |] ==> P |] ==> P"; |
|
211 |
by (rtac minor 1); |
|
212 |
by (rtac (major RS IntD1) 1); |
|
213 |
by (rtac (major RS IntD2) 1); |
|
757 | 214 |
qed "IntE"; |
0 | 215 |
|
216 |
||
217 |
(*** Rules for set complement -- Compl ***) |
|
218 |
||
219 |
val prems = goalw Set.thy [Compl_def] |
|
220 |
"[| c:A ==> False |] ==> c : Compl(A)"; |
|
221 |
by (REPEAT (ares_tac (prems @ [CollectI,notI]) 1)); |
|
757 | 222 |
qed "ComplI"; |
0 | 223 |
|
224 |
(*This form, with negated conclusion, works well with the Classical prover. |
|
225 |
Negated assumptions behave like formulae on the right side of the notional |
|
226 |
turnstile...*) |
|
227 |
val major::prems = goalw Set.thy [Compl_def] |
|
228 |
"[| c : Compl(A) |] ==> ~c:A"; |
|
229 |
by (rtac (major RS CollectD) 1); |
|
757 | 230 |
qed "ComplD"; |
0 | 231 |
|
232 |
val ComplE = make_elim ComplD; |
|
233 |
||
234 |
||
235 |
(*** Empty sets ***) |
|
236 |
||
5062 | 237 |
Goalw [empty_def] "{x. False} = {}"; |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
8
diff
changeset
|
238 |
by (rtac refl 1); |
757 | 239 |
qed "empty_eq"; |
0 | 240 |
|
241 |
val [prem] = goalw Set.thy [empty_def] "a : {} ==> P"; |
|
242 |
by (rtac (prem RS CollectD RS FalseE) 1); |
|
757 | 243 |
qed "emptyD"; |
0 | 244 |
|
245 |
val emptyE = make_elim emptyD; |
|
246 |
||
3837 | 247 |
val [prem] = goal Set.thy "~ A={} ==> (EX x. x:A)"; |
642
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
8
diff
changeset
|
248 |
by (rtac (prem RS swap) 1); |
0db578095e6a
CCL/Gfp/coinduct2, coinduct3: modified proofs to suppress deep unification
lcp
parents:
8
diff
changeset
|
249 |
by (rtac equalityI 1); |
0 | 250 |
by (ALLGOALS (fast_tac (FOL_cs addSIs [subsetI] addSEs [emptyD]))); |
757 | 251 |
qed "not_emptyD"; |
0 | 252 |
|
253 |
(*** Singleton sets ***) |
|
254 |
||
5062 | 255 |
Goalw [singleton_def] "a : {a}"; |
0 | 256 |
by (rtac CollectI 1); |
257 |
by (rtac refl 1); |
|
757 | 258 |
qed "singletonI"; |
0 | 259 |
|
260 |
val [major] = goalw Set.thy [singleton_def] "b : {a} ==> b=a"; |
|
261 |
by (rtac (major RS CollectD) 1); |
|
757 | 262 |
qed "singletonD"; |
0 | 263 |
|
264 |
val singletonE = make_elim singletonD; |
|
265 |
||
266 |
(*** Unions of families ***) |
|
267 |
||
268 |
(*The order of the premises presupposes that A is rigid; b may be flexible*) |
|
269 |
val prems = goalw Set.thy [UNION_def] |
|
270 |
"[| a:A; b: B(a) |] ==> b: (UN x:A. B(x))"; |
|
271 |
by (REPEAT (resolve_tac (prems @ [bexI,CollectI]) 1)); |
|
757 | 272 |
qed "UN_I"; |
0 | 273 |
|
274 |
val major::prems = goalw Set.thy [UNION_def] |
|
275 |
"[| b : (UN x:A. B(x)); !!x.[| x:A; b: B(x) |] ==> R |] ==> R"; |
|
276 |
by (rtac (major RS CollectD RS bexE) 1); |
|
277 |
by (REPEAT (ares_tac prems 1)); |
|
757 | 278 |
qed "UN_E"; |
0 | 279 |
|
280 |
val prems = goal Set.thy |
|
281 |
"[| A=B; !!x. x:B ==> C(x) = D(x) |] ==> \ |
|
282 |
\ (UN x:A. C(x)) = (UN x:B. D(x))"; |
|
283 |
by (REPEAT (etac UN_E 1 |
|
284 |
ORELSE ares_tac ([UN_I,equalityI,subsetI] @ |
|
1459 | 285 |
(prems RL [equalityD1,equalityD2] RL [subsetD])) 1)); |
757 | 286 |
qed "UN_cong"; |
0 | 287 |
|
288 |
(*** Intersections of families -- INTER x:A. B(x) is Inter(B)``A ) *) |
|
289 |
||
290 |
val prems = goalw Set.thy [INTER_def] |
|
291 |
"(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))"; |
|
292 |
by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1)); |
|
757 | 293 |
qed "INT_I"; |
0 | 294 |
|
295 |
val major::prems = goalw Set.thy [INTER_def] |
|
296 |
"[| b : (INT x:A. B(x)); a:A |] ==> b: B(a)"; |
|
297 |
by (rtac (major RS CollectD RS bspec) 1); |
|
298 |
by (resolve_tac prems 1); |
|
757 | 299 |
qed "INT_D"; |
0 | 300 |
|
301 |
(*"Classical" elimination rule -- does not require proving X:C *) |
|
302 |
val major::prems = goalw Set.thy [INTER_def] |
|
303 |
"[| b : (INT x:A. B(x)); b: B(a) ==> R; ~ a:A ==> R |] ==> R"; |
|
304 |
by (rtac (major RS CollectD RS ballE) 1); |
|
305 |
by (REPEAT (eresolve_tac prems 1)); |
|
757 | 306 |
qed "INT_E"; |
0 | 307 |
|
308 |
val prems = goal Set.thy |
|
309 |
"[| A=B; !!x. x:B ==> C(x) = D(x) |] ==> \ |
|
310 |
\ (INT x:A. C(x)) = (INT x:B. D(x))"; |
|
311 |
by (REPEAT_FIRST (resolve_tac [INT_I,equalityI,subsetI])); |
|
312 |
by (REPEAT (dtac INT_D 1 |
|
313 |
ORELSE ares_tac (prems RL [equalityD1,equalityD2] RL [subsetD]) 1)); |
|
757 | 314 |
qed "INT_cong"; |
0 | 315 |
|
316 |
(*** Rules for Unions ***) |
|
317 |
||
318 |
(*The order of the premises presupposes that C is rigid; A may be flexible*) |
|
319 |
val prems = goalw Set.thy [Union_def] |
|
320 |
"[| X:C; A:X |] ==> A : Union(C)"; |
|
321 |
by (REPEAT (resolve_tac (prems @ [UN_I]) 1)); |
|
757 | 322 |
qed "UnionI"; |
0 | 323 |
|
324 |
val major::prems = goalw Set.thy [Union_def] |
|
325 |
"[| A : Union(C); !!X.[| A:X; X:C |] ==> R |] ==> R"; |
|
326 |
by (rtac (major RS UN_E) 1); |
|
327 |
by (REPEAT (ares_tac prems 1)); |
|
757 | 328 |
qed "UnionE"; |
0 | 329 |
|
330 |
(*** Rules for Inter ***) |
|
331 |
||
332 |
val prems = goalw Set.thy [Inter_def] |
|
333 |
"[| !!X. X:C ==> A:X |] ==> A : Inter(C)"; |
|
334 |
by (REPEAT (ares_tac ([INT_I] @ prems) 1)); |
|
757 | 335 |
qed "InterI"; |
0 | 336 |
|
337 |
(*A "destruct" rule -- every X in C contains A as an element, but |
|
338 |
A:X can hold when X:C does not! This rule is analogous to "spec". *) |
|
339 |
val major::prems = goalw Set.thy [Inter_def] |
|
340 |
"[| A : Inter(C); X:C |] ==> A:X"; |
|
341 |
by (rtac (major RS INT_D) 1); |
|
342 |
by (resolve_tac prems 1); |
|
757 | 343 |
qed "InterD"; |
0 | 344 |
|
345 |
(*"Classical" elimination rule -- does not require proving X:C *) |
|
346 |
val major::prems = goalw Set.thy [Inter_def] |
|
347 |
"[| A : Inter(C); A:X ==> R; ~ X:C ==> R |] ==> R"; |
|
348 |
by (rtac (major RS INT_E) 1); |
|
349 |
by (REPEAT (eresolve_tac prems 1)); |
|
757 | 350 |
qed "InterE"; |