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