src/HOL/Set.ML
author paulson
Thu Mar 02 10:26:22 2000 +0100 (2000-03-02)
changeset 8326 0e329578b0ef
parent 8053 37ebdaf3bb91
child 8839 31da5b9790c0
permissions -rw-r--r--
tidied the proofs of singleton_insert_inj_eq, singleton_insert_inj_eq' and
installed them by AddIffs, since they are an important special case of
equalityE.
clasohm@1465
     1
(*  Title:      HOL/set
clasohm@923
     2
    ID:         $Id$
clasohm@1465
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@923
     4
    Copyright   1991  University of Cambridge
clasohm@923
     5
paulson@1985
     6
Set theory for higher-order logic.  A set is simply a predicate.
clasohm@923
     7
*)
clasohm@923
     8
nipkow@1548
     9
section "Relating predicates and sets";
nipkow@1548
    10
paulson@3469
    11
Addsimps [Collect_mem_eq];
paulson@3469
    12
AddIffs  [mem_Collect_eq];
paulson@2499
    13
paulson@5143
    14
Goal "P(a) ==> a : {x. P(x)}";
paulson@2499
    15
by (Asm_simp_tac 1);
clasohm@923
    16
qed "CollectI";
clasohm@923
    17
paulson@5316
    18
Goal "a : {x. P(x)} ==> P(a)";
paulson@2499
    19
by (Asm_full_simp_tac 1);
clasohm@923
    20
qed "CollectD";
clasohm@923
    21
wenzelm@7658
    22
bind_thm ("CollectE", make_elim CollectD);
wenzelm@7658
    23
paulson@5316
    24
val [prem] = Goal "[| !!x. (x:A) = (x:B) |] ==> A = B";
clasohm@923
    25
by (rtac (prem RS ext RS arg_cong RS box_equals) 1);
clasohm@923
    26
by (rtac Collect_mem_eq 1);
clasohm@923
    27
by (rtac Collect_mem_eq 1);
clasohm@923
    28
qed "set_ext";
clasohm@923
    29
paulson@5316
    30
val [prem] = Goal "[| !!x. P(x)=Q(x) |] ==> {x. P(x)} = {x. Q(x)}";
clasohm@923
    31
by (rtac (prem RS ext RS arg_cong) 1);
clasohm@923
    32
qed "Collect_cong";
clasohm@923
    33
clasohm@923
    34
val CollectE = make_elim CollectD;
clasohm@923
    35
paulson@2499
    36
AddSIs [CollectI];
paulson@2499
    37
AddSEs [CollectE];
paulson@2499
    38
paulson@2499
    39
nipkow@1548
    40
section "Bounded quantifiers";
clasohm@923
    41
paulson@5316
    42
val prems = Goalw [Ball_def]
clasohm@923
    43
    "[| !!x. x:A ==> P(x) |] ==> ! x:A. P(x)";
clasohm@923
    44
by (REPEAT (ares_tac (prems @ [allI,impI]) 1));
clasohm@923
    45
qed "ballI";
clasohm@923
    46
paulson@5316
    47
Goalw [Ball_def] "[| ! x:A. P(x);  x:A |] ==> P(x)";
paulson@5316
    48
by (Blast_tac 1);
clasohm@923
    49
qed "bspec";
clasohm@923
    50
paulson@5316
    51
val major::prems = Goalw [Ball_def]
clasohm@923
    52
    "[| ! x:A. P(x);  P(x) ==> Q;  x~:A ==> Q |] ==> Q";
clasohm@923
    53
by (rtac (major RS spec RS impCE) 1);
clasohm@923
    54
by (REPEAT (eresolve_tac prems 1));
clasohm@923
    55
qed "ballE";
clasohm@923
    56
clasohm@923
    57
(*Takes assumptions ! x:A.P(x) and a:A; creates assumption P(a)*)
clasohm@923
    58
fun ball_tac i = etac ballE i THEN contr_tac (i+1);
clasohm@923
    59
paulson@2499
    60
AddSIs [ballI];
paulson@2499
    61
AddEs  [ballE];
wenzelm@7441
    62
AddXDs [bspec];
oheimb@5521
    63
(* gives better instantiation for bound: *)
oheimb@5521
    64
claset_ref() := claset() addWrapper ("bspec", fn tac2 =>
oheimb@5521
    65
			 (dtac bspec THEN' atac) APPEND' tac2);
paulson@2499
    66
paulson@6006
    67
(*Normally the best argument order: P(x) constrains the choice of x:A*)
paulson@5316
    68
Goalw [Bex_def] "[| P(x);  x:A |] ==> ? x:A. P(x)";
paulson@5316
    69
by (Blast_tac 1);
clasohm@923
    70
qed "bexI";
clasohm@923
    71
paulson@6006
    72
(*The best argument order when there is only one x:A*)
paulson@6006
    73
Goalw [Bex_def] "[| x:A;  P(x) |] ==> ? x:A. P(x)";
paulson@6006
    74
by (Blast_tac 1);
paulson@6006
    75
qed "rev_bexI";
paulson@6006
    76
paulson@7031
    77
val prems = Goal 
paulson@7007
    78
   "[| ! x:A. ~P(x) ==> P(a);  a:A |] ==> ? x:A. P(x)";
paulson@7007
    79
by (rtac classical 1);
paulson@7007
    80
by (REPEAT (ares_tac (prems@[bexI,ballI,notI,notE]) 1))  ;
paulson@7007
    81
qed "bexCI";
clasohm@923
    82
paulson@5316
    83
val major::prems = Goalw [Bex_def]
clasohm@923
    84
    "[| ? x:A. P(x);  !!x. [| x:A; P(x) |] ==> Q  |] ==> Q";
clasohm@923
    85
by (rtac (major RS exE) 1);
clasohm@923
    86
by (REPEAT (eresolve_tac (prems @ [asm_rl,conjE]) 1));
clasohm@923
    87
qed "bexE";
clasohm@923
    88
paulson@2499
    89
AddIs  [bexI];
paulson@2499
    90
AddSEs [bexE];
paulson@2499
    91
paulson@3420
    92
(*Trival rewrite rule*)
wenzelm@5069
    93
Goal "(! x:A. P) = ((? x. x:A) --> P)";
wenzelm@4089
    94
by (simp_tac (simpset() addsimps [Ball_def]) 1);
paulson@3420
    95
qed "ball_triv";
paulson@1816
    96
paulson@1882
    97
(*Dual form for existentials*)
wenzelm@5069
    98
Goal "(? x:A. P) = ((? x. x:A) & P)";
wenzelm@4089
    99
by (simp_tac (simpset() addsimps [Bex_def]) 1);
paulson@3420
   100
qed "bex_triv";
paulson@1882
   101
paulson@3420
   102
Addsimps [ball_triv, bex_triv];
clasohm@923
   103
clasohm@923
   104
(** Congruence rules **)
clasohm@923
   105
paulson@6291
   106
val prems = Goalw [Ball_def]
clasohm@923
   107
    "[| A=B;  !!x. x:B ==> P(x) = Q(x) |] ==> \
clasohm@923
   108
\    (! x:A. P(x)) = (! x:B. Q(x))";
paulson@6291
   109
by (asm_simp_tac (simpset() addsimps prems) 1);
clasohm@923
   110
qed "ball_cong";
clasohm@923
   111
paulson@6291
   112
val prems = Goalw [Bex_def]
clasohm@923
   113
    "[| A=B;  !!x. x:B ==> P(x) = Q(x) |] ==> \
clasohm@923
   114
\    (? x:A. P(x)) = (? x:B. Q(x))";
paulson@6291
   115
by (asm_simp_tac (simpset() addcongs [conj_cong] addsimps prems) 1);
clasohm@923
   116
qed "bex_cong";
clasohm@923
   117
paulson@6291
   118
Addcongs [ball_cong,bex_cong];
paulson@6291
   119
nipkow@1548
   120
section "Subsets";
clasohm@923
   121
paulson@5316
   122
val prems = Goalw [subset_def] "(!!x. x:A ==> x:B) ==> A <= B";
clasohm@923
   123
by (REPEAT (ares_tac (prems @ [ballI]) 1));
clasohm@923
   124
qed "subsetI";
clasohm@923
   125
paulson@5649
   126
(*Map the type ('a set => anything) to just 'a.
paulson@5649
   127
  For overloading constants whose first argument has type "'a set" *)
paulson@5649
   128
fun overload_1st_set s = Blast.overloaded (s, HOLogic.dest_setT o domain_type);
paulson@5649
   129
paulson@4059
   130
(*While (:) is not, its type must be kept
paulson@4059
   131
  for overloading of = to work.*)
paulson@4240
   132
Blast.overloaded ("op :", domain_type);
paulson@5649
   133
paulson@5649
   134
overload_1st_set "Ball";		(*need UNION, INTER also?*)
paulson@5649
   135
overload_1st_set "Bex";
paulson@4059
   136
paulson@4469
   137
(*Image: retain the type of the set being expressed*)
paulson@8005
   138
Blast.overloaded ("image", domain_type);
paulson@2881
   139
clasohm@923
   140
(*Rule in Modus Ponens style*)
paulson@5316
   141
Goalw [subset_def] "[| A <= B;  c:A |] ==> c:B";
paulson@5316
   142
by (Blast_tac 1);
clasohm@923
   143
qed "subsetD";
wenzelm@7658
   144
AddXIs [subsetD];
clasohm@923
   145
clasohm@923
   146
(*The same, with reversed premises for use with etac -- cf rev_mp*)
paulson@7007
   147
Goal "[| c:A;  A <= B |] ==> c:B";
paulson@7007
   148
by (REPEAT (ares_tac [subsetD] 1)) ;
paulson@7007
   149
qed "rev_subsetD";
wenzelm@7658
   150
AddXIs [rev_subsetD];
clasohm@923
   151
paulson@1920
   152
(*Converts A<=B to x:A ==> x:B*)
paulson@1920
   153
fun impOfSubs th = th RSN (2, rev_subsetD);
paulson@1920
   154
paulson@7007
   155
Goal "[| A <= B; c ~: B |] ==> c ~: A";
paulson@7007
   156
by (REPEAT (eresolve_tac [asm_rl, contrapos, subsetD] 1)) ;
paulson@7007
   157
qed "contra_subsetD";
paulson@1841
   158
paulson@7007
   159
Goal "[| c ~: B;  A <= B |] ==> c ~: A";
paulson@7007
   160
by (REPEAT (eresolve_tac [asm_rl, contrapos, subsetD] 1)) ;
paulson@7007
   161
qed "rev_contra_subsetD";
paulson@1841
   162
clasohm@923
   163
(*Classical elimination rule*)
paulson@5316
   164
val major::prems = Goalw [subset_def] 
clasohm@923
   165
    "[| A <= B;  c~:A ==> P;  c:B ==> P |] ==> P";
clasohm@923
   166
by (rtac (major RS ballE) 1);
clasohm@923
   167
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   168
qed "subsetCE";
clasohm@923
   169
clasohm@923
   170
(*Takes assumptions A<=B; c:A and creates the assumption c:B *)
clasohm@923
   171
fun set_mp_tac i = etac subsetCE i  THEN  mp_tac i;
clasohm@923
   172
paulson@2499
   173
AddSIs [subsetI];
paulson@2499
   174
AddEs  [subsetD, subsetCE];
clasohm@923
   175
paulson@7007
   176
Goal "A <= (A::'a set)";
paulson@7007
   177
by (Fast_tac 1);
paulson@7007
   178
qed "subset_refl";		(*Blast_tac would try order_refl and fail*)
paulson@2499
   179
paulson@5316
   180
Goal "[| A<=B;  B<=C |] ==> A<=(C::'a set)";
paulson@2891
   181
by (Blast_tac 1);
clasohm@923
   182
qed "subset_trans";
clasohm@923
   183
clasohm@923
   184
nipkow@1548
   185
section "Equality";
clasohm@923
   186
clasohm@923
   187
(*Anti-symmetry of the subset relation*)
paulson@5316
   188
Goal "[| A <= B;  B <= A |] ==> A = (B::'a set)";
paulson@5318
   189
by (rtac set_ext 1);
paulson@5316
   190
by (blast_tac (claset() addIs [subsetD]) 1);
clasohm@923
   191
qed "subset_antisym";
clasohm@923
   192
val equalityI = subset_antisym;
clasohm@923
   193
berghofe@1762
   194
AddSIs [equalityI];
berghofe@1762
   195
clasohm@923
   196
(* Equality rules from ZF set theory -- are they appropriate here? *)
paulson@5316
   197
Goal "A = B ==> A<=(B::'a set)";
paulson@5316
   198
by (etac ssubst 1);
clasohm@923
   199
by (rtac subset_refl 1);
clasohm@923
   200
qed "equalityD1";
clasohm@923
   201
paulson@5316
   202
Goal "A = B ==> B<=(A::'a set)";
paulson@5316
   203
by (etac ssubst 1);
clasohm@923
   204
by (rtac subset_refl 1);
clasohm@923
   205
qed "equalityD2";
clasohm@923
   206
paulson@5316
   207
val prems = Goal
clasohm@923
   208
    "[| A = B;  [| A<=B; B<=(A::'a set) |] ==> P |]  ==>  P";
clasohm@923
   209
by (resolve_tac prems 1);
clasohm@923
   210
by (REPEAT (resolve_tac (prems RL [equalityD1,equalityD2]) 1));
clasohm@923
   211
qed "equalityE";
clasohm@923
   212
paulson@5316
   213
val major::prems = Goal
clasohm@923
   214
    "[| A = B;  [| c:A; c:B |] ==> P;  [| c~:A; c~:B |] ==> P |]  ==>  P";
clasohm@923
   215
by (rtac (major RS equalityE) 1);
clasohm@923
   216
by (REPEAT (contr_tac 1 ORELSE eresolve_tac ([asm_rl,subsetCE]@prems) 1));
clasohm@923
   217
qed "equalityCE";
clasohm@923
   218
clasohm@923
   219
(*Lemma for creating induction formulae -- for "pattern matching" on p
clasohm@923
   220
  To make the induction hypotheses usable, apply "spec" or "bspec" to
clasohm@923
   221
  put universal quantifiers over the free variables in p. *)
paulson@5316
   222
val prems = Goal 
clasohm@923
   223
    "[| p:A;  !!z. z:A ==> p=z --> R |] ==> R";
clasohm@923
   224
by (rtac mp 1);
clasohm@923
   225
by (REPEAT (resolve_tac (refl::prems) 1));
clasohm@923
   226
qed "setup_induction";
clasohm@923
   227
paulson@8053
   228
Goal "A = B ==> (x : A) = (x : B)";
paulson@8053
   229
by (Asm_simp_tac 1);
paulson@8053
   230
qed "eqset_imp_iff";
paulson@8053
   231
clasohm@923
   232
paulson@4159
   233
section "The universal set -- UNIV";
paulson@4159
   234
paulson@7031
   235
Goalw [UNIV_def] "x : UNIV";
paulson@7031
   236
by (rtac CollectI 1);
paulson@7031
   237
by (rtac TrueI 1);
paulson@7031
   238
qed "UNIV_I";
paulson@4159
   239
paulson@4434
   240
Addsimps [UNIV_I];
paulson@4434
   241
AddIs    [UNIV_I];  (*unsafe makes it less likely to cause problems*)
paulson@4159
   242
paulson@7031
   243
Goal "A <= UNIV";
paulson@7031
   244
by (rtac subsetI 1);
paulson@7031
   245
by (rtac UNIV_I 1);
paulson@7031
   246
qed "subset_UNIV";
paulson@4159
   247
paulson@4159
   248
(** Eta-contracting these two rules (to remove P) causes them to be ignored
paulson@4159
   249
    because of their interaction with congruence rules. **)
paulson@4159
   250
wenzelm@5069
   251
Goalw [Ball_def] "Ball UNIV P = All P";
paulson@4159
   252
by (Simp_tac 1);
paulson@4159
   253
qed "ball_UNIV";
paulson@4159
   254
wenzelm@5069
   255
Goalw [Bex_def] "Bex UNIV P = Ex P";
paulson@4159
   256
by (Simp_tac 1);
paulson@4159
   257
qed "bex_UNIV";
paulson@4159
   258
Addsimps [ball_UNIV, bex_UNIV];
paulson@4159
   259
paulson@4159
   260
paulson@2858
   261
section "The empty set -- {}";
paulson@2858
   262
paulson@7007
   263
Goalw [empty_def] "(c : {}) = False";
paulson@7007
   264
by (Blast_tac 1) ;
paulson@7007
   265
qed "empty_iff";
paulson@2858
   266
paulson@2858
   267
Addsimps [empty_iff];
paulson@2858
   268
paulson@7007
   269
Goal "a:{} ==> P";
paulson@7007
   270
by (Full_simp_tac 1);
paulson@7007
   271
qed "emptyE";
paulson@2858
   272
paulson@2858
   273
AddSEs [emptyE];
paulson@2858
   274
paulson@7007
   275
Goal "{} <= A";
paulson@7007
   276
by (Blast_tac 1) ;
paulson@7007
   277
qed "empty_subsetI";
paulson@2858
   278
paulson@5256
   279
(*One effect is to delete the ASSUMPTION {} <= A*)
paulson@5256
   280
AddIffs [empty_subsetI];
paulson@5256
   281
paulson@7031
   282
val [prem]= Goal "[| !!y. y:A ==> False |] ==> A={}";
paulson@7007
   283
by (blast_tac (claset() addIs [prem RS FalseE]) 1) ;
paulson@7007
   284
qed "equals0I";
paulson@2858
   285
paulson@5256
   286
(*Use for reasoning about disjointness: A Int B = {} *)
paulson@7007
   287
Goal "A={} ==> a ~: A";
paulson@7007
   288
by (Blast_tac 1) ;
paulson@7007
   289
qed "equals0D";
paulson@2858
   290
paulson@5450
   291
AddDs [equals0D, sym RS equals0D];
paulson@5256
   292
wenzelm@5069
   293
Goalw [Ball_def] "Ball {} P = True";
paulson@4159
   294
by (Simp_tac 1);
paulson@4159
   295
qed "ball_empty";
paulson@4159
   296
wenzelm@5069
   297
Goalw [Bex_def] "Bex {} P = False";
paulson@4159
   298
by (Simp_tac 1);
paulson@4159
   299
qed "bex_empty";
paulson@4159
   300
Addsimps [ball_empty, bex_empty];
paulson@4159
   301
wenzelm@5069
   302
Goal "UNIV ~= {}";
paulson@4159
   303
by (blast_tac (claset() addEs [equalityE]) 1);
paulson@4159
   304
qed "UNIV_not_empty";
paulson@4159
   305
AddIffs [UNIV_not_empty];
paulson@4159
   306
paulson@4159
   307
paulson@2858
   308
paulson@2858
   309
section "The Powerset operator -- Pow";
paulson@2858
   310
paulson@7007
   311
Goalw [Pow_def] "(A : Pow(B)) = (A <= B)";
paulson@7007
   312
by (Asm_simp_tac 1);
paulson@7007
   313
qed "Pow_iff";
paulson@2858
   314
paulson@2858
   315
AddIffs [Pow_iff]; 
paulson@2858
   316
paulson@7031
   317
Goalw [Pow_def] "A <= B ==> A : Pow(B)";
paulson@7007
   318
by (etac CollectI 1);
paulson@7007
   319
qed "PowI";
paulson@2858
   320
paulson@7031
   321
Goalw [Pow_def] "A : Pow(B)  ==>  A<=B";
paulson@7007
   322
by (etac CollectD 1);
paulson@7007
   323
qed "PowD";
paulson@7007
   324
paulson@2858
   325
paulson@2858
   326
val Pow_bottom = empty_subsetI RS PowI;        (* {}: Pow(B) *)
paulson@2858
   327
val Pow_top = subset_refl RS PowI;             (* A : Pow(A) *)
paulson@2858
   328
paulson@2858
   329
paulson@5931
   330
section "Set complement";
clasohm@923
   331
paulson@7031
   332
Goalw [Compl_def] "(c : -A) = (c~:A)";
paulson@7031
   333
by (Blast_tac 1);
paulson@7031
   334
qed "Compl_iff";
paulson@2499
   335
paulson@2499
   336
Addsimps [Compl_iff];
paulson@2499
   337
paulson@5490
   338
val prems = Goalw [Compl_def] "[| c:A ==> False |] ==> c : -A";
clasohm@923
   339
by (REPEAT (ares_tac (prems @ [CollectI,notI]) 1));
clasohm@923
   340
qed "ComplI";
clasohm@923
   341
clasohm@923
   342
(*This form, with negated conclusion, works well with the Classical prover.
clasohm@923
   343
  Negated assumptions behave like formulae on the right side of the notional
clasohm@923
   344
  turnstile...*)
paulson@5490
   345
Goalw [Compl_def] "c : -A ==> c~:A";
paulson@5316
   346
by (etac CollectD 1);
clasohm@923
   347
qed "ComplD";
clasohm@923
   348
clasohm@923
   349
val ComplE = make_elim ComplD;
clasohm@923
   350
paulson@2499
   351
AddSIs [ComplI];
paulson@2499
   352
AddSEs [ComplE];
paulson@1640
   353
clasohm@923
   354
nipkow@1548
   355
section "Binary union -- Un";
clasohm@923
   356
paulson@7031
   357
Goalw [Un_def] "(c : A Un B) = (c:A | c:B)";
paulson@7031
   358
by (Blast_tac 1);
paulson@7031
   359
qed "Un_iff";
paulson@2499
   360
Addsimps [Un_iff];
paulson@2499
   361
paulson@5143
   362
Goal "c:A ==> c : A Un B";
paulson@2499
   363
by (Asm_simp_tac 1);
clasohm@923
   364
qed "UnI1";
clasohm@923
   365
paulson@5143
   366
Goal "c:B ==> c : A Un B";
paulson@2499
   367
by (Asm_simp_tac 1);
clasohm@923
   368
qed "UnI2";
clasohm@923
   369
clasohm@923
   370
(*Classical introduction rule: no commitment to A vs B*)
paulson@7007
   371
paulson@7031
   372
val prems = Goal "(c~:B ==> c:A) ==> c : A Un B";
paulson@7007
   373
by (Simp_tac 1);
paulson@7007
   374
by (REPEAT (ares_tac (prems@[disjCI]) 1)) ;
paulson@7007
   375
qed "UnCI";
clasohm@923
   376
paulson@5316
   377
val major::prems = Goalw [Un_def]
clasohm@923
   378
    "[| c : A Un B;  c:A ==> P;  c:B ==> P |] ==> P";
clasohm@923
   379
by (rtac (major RS CollectD RS disjE) 1);
clasohm@923
   380
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   381
qed "UnE";
clasohm@923
   382
paulson@2499
   383
AddSIs [UnCI];
paulson@2499
   384
AddSEs [UnE];
paulson@1640
   385
clasohm@923
   386
nipkow@1548
   387
section "Binary intersection -- Int";
clasohm@923
   388
paulson@7031
   389
Goalw [Int_def] "(c : A Int B) = (c:A & c:B)";
paulson@7031
   390
by (Blast_tac 1);
paulson@7031
   391
qed "Int_iff";
paulson@2499
   392
Addsimps [Int_iff];
paulson@2499
   393
paulson@5143
   394
Goal "[| c:A;  c:B |] ==> c : A Int B";
paulson@2499
   395
by (Asm_simp_tac 1);
clasohm@923
   396
qed "IntI";
clasohm@923
   397
paulson@5143
   398
Goal "c : A Int B ==> c:A";
paulson@2499
   399
by (Asm_full_simp_tac 1);
clasohm@923
   400
qed "IntD1";
clasohm@923
   401
paulson@5143
   402
Goal "c : A Int B ==> c:B";
paulson@2499
   403
by (Asm_full_simp_tac 1);
clasohm@923
   404
qed "IntD2";
clasohm@923
   405
paulson@5316
   406
val [major,minor] = Goal
clasohm@923
   407
    "[| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P";
clasohm@923
   408
by (rtac minor 1);
clasohm@923
   409
by (rtac (major RS IntD1) 1);
clasohm@923
   410
by (rtac (major RS IntD2) 1);
clasohm@923
   411
qed "IntE";
clasohm@923
   412
paulson@2499
   413
AddSIs [IntI];
paulson@2499
   414
AddSEs [IntE];
clasohm@923
   415
nipkow@1548
   416
section "Set difference";
clasohm@923
   417
paulson@7031
   418
Goalw [set_diff_def] "(c : A-B) = (c:A & c~:B)";
paulson@7031
   419
by (Blast_tac 1);
paulson@7031
   420
qed "Diff_iff";
paulson@2499
   421
Addsimps [Diff_iff];
paulson@2499
   422
paulson@7007
   423
Goal "[| c : A;  c ~: B |] ==> c : A - B";
paulson@7007
   424
by (Asm_simp_tac 1) ;
paulson@7007
   425
qed "DiffI";
clasohm@923
   426
paulson@7007
   427
Goal "c : A - B ==> c : A";
paulson@7007
   428
by (Asm_full_simp_tac 1) ;
paulson@7007
   429
qed "DiffD1";
clasohm@923
   430
paulson@7007
   431
Goal "[| c : A - B;  c : B |] ==> P";
paulson@7007
   432
by (Asm_full_simp_tac 1) ;
paulson@7007
   433
qed "DiffD2";
paulson@2499
   434
paulson@7031
   435
val prems = Goal "[| c : A - B;  [| c:A; c~:B |] ==> P |] ==> P";
paulson@7007
   436
by (resolve_tac prems 1);
paulson@7007
   437
by (REPEAT (ares_tac (prems RL [DiffD1, DiffD2 RS notI]) 1)) ;
paulson@7007
   438
qed "DiffE";
clasohm@923
   439
paulson@2499
   440
AddSIs [DiffI];
paulson@2499
   441
AddSEs [DiffE];
clasohm@923
   442
clasohm@923
   443
nipkow@1548
   444
section "Augmenting a set -- insert";
clasohm@923
   445
paulson@7031
   446
Goalw [insert_def] "a : insert b A = (a=b | a:A)";
paulson@7031
   447
by (Blast_tac 1);
paulson@7031
   448
qed "insert_iff";
paulson@2499
   449
Addsimps [insert_iff];
clasohm@923
   450
paulson@7031
   451
Goal "a : insert a B";
paulson@7007
   452
by (Simp_tac 1);
paulson@7007
   453
qed "insertI1";
clasohm@923
   454
paulson@7007
   455
Goal "!!a. a : B ==> a : insert b B";
paulson@7007
   456
by (Asm_simp_tac 1);
paulson@7007
   457
qed "insertI2";
paulson@7007
   458
paulson@7007
   459
val major::prems = Goalw [insert_def]
paulson@7007
   460
    "[| a : insert b A;  a=b ==> P;  a:A ==> P |] ==> P";
paulson@7007
   461
by (rtac (major RS UnE) 1);
paulson@7007
   462
by (REPEAT (eresolve_tac (prems @ [CollectE]) 1));
paulson@7007
   463
qed "insertE";
clasohm@923
   464
clasohm@923
   465
(*Classical introduction rule*)
paulson@7031
   466
val prems = Goal "(a~:B ==> a=b) ==> a: insert b B";
paulson@7007
   467
by (Simp_tac 1);
paulson@7007
   468
by (REPEAT (ares_tac (prems@[disjCI]) 1)) ;
paulson@7007
   469
qed "insertCI";
paulson@2499
   470
paulson@2499
   471
AddSIs [insertCI]; 
paulson@2499
   472
AddSEs [insertE];
clasohm@923
   473
oheimb@7496
   474
Goal "A <= insert x B ==> A <= B & x ~: A | (? B'. A = insert x B' & B' <= B)";
oheimb@7496
   475
by (case_tac "x:A" 1);
oheimb@7496
   476
by  (Fast_tac 2);
wenzelm@7499
   477
by (rtac disjI2 1);
oheimb@7496
   478
by (res_inst_tac [("x","A-{x}")] exI 1);
oheimb@7496
   479
by (Fast_tac 1);
oheimb@7496
   480
qed "subset_insertD";
oheimb@7496
   481
nipkow@1548
   482
section "Singletons, using insert";
clasohm@923
   483
paulson@7007
   484
Goal "a : {a}";
paulson@7007
   485
by (rtac insertI1 1) ;
paulson@7007
   486
qed "singletonI";
clasohm@923
   487
paulson@5143
   488
Goal "b : {a} ==> b=a";
paulson@2891
   489
by (Blast_tac 1);
clasohm@923
   490
qed "singletonD";
clasohm@923
   491
oheimb@1776
   492
bind_thm ("singletonE", make_elim singletonD);
oheimb@1776
   493
paulson@7007
   494
Goal "(b : {a}) = (b=a)";
paulson@7007
   495
by (Blast_tac 1);
paulson@7007
   496
qed "singleton_iff";
clasohm@923
   497
paulson@5143
   498
Goal "{a}={b} ==> a=b";
wenzelm@4089
   499
by (blast_tac (claset() addEs [equalityE]) 1);
clasohm@923
   500
qed "singleton_inject";
clasohm@923
   501
paulson@2858
   502
(*Redundant? But unlike insertCI, it proves the subgoal immediately!*)
paulson@2858
   503
AddSIs [singletonI];   
paulson@2499
   504
AddSDs [singleton_inject];
paulson@3718
   505
AddSEs [singletonE];
paulson@2499
   506
oheimb@7969
   507
Goal "{b} = insert a A = (a = b & A <= {b})";
paulson@8326
   508
by (blast_tac (claset() addSEs [equalityE]) 1);
oheimb@7496
   509
qed "singleton_insert_inj_eq";
oheimb@7496
   510
paulson@8326
   511
Goal "(insert a A = {b}) = (a = b & A <= {b})";
paulson@8326
   512
by (blast_tac (claset() addSEs [equalityE]) 1);
oheimb@7969
   513
qed "singleton_insert_inj_eq'";
oheimb@7969
   514
paulson@8326
   515
AddIffs [singleton_insert_inj_eq, singleton_insert_inj_eq'];
paulson@8326
   516
oheimb@7496
   517
Goal "A <= {x} ==> A={} | A = {x}";
oheimb@7496
   518
by (Fast_tac 1);
oheimb@7496
   519
qed "subset_singletonD";
oheimb@7496
   520
wenzelm@5069
   521
Goal "{x. x=a} = {a}";
wenzelm@4423
   522
by (Blast_tac 1);
nipkow@3582
   523
qed "singleton_conv";
nipkow@3582
   524
Addsimps [singleton_conv];
nipkow@1531
   525
nipkow@5600
   526
Goal "{x. a=x} = {a}";
paulson@6301
   527
by (Blast_tac 1);
nipkow@5600
   528
qed "singleton_conv2";
nipkow@5600
   529
Addsimps [singleton_conv2];
nipkow@5600
   530
nipkow@1531
   531
nipkow@1548
   532
section "Unions of families -- UNION x:A. B(x) is Union(B``A)";
clasohm@923
   533
wenzelm@5069
   534
Goalw [UNION_def] "(b: (UN x:A. B(x))) = (EX x:A. b: B(x))";
paulson@2891
   535
by (Blast_tac 1);
paulson@2499
   536
qed "UN_iff";
paulson@2499
   537
paulson@2499
   538
Addsimps [UN_iff];
paulson@2499
   539
clasohm@923
   540
(*The order of the premises presupposes that A is rigid; b may be flexible*)
paulson@5143
   541
Goal "[| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))";
paulson@4477
   542
by Auto_tac;
clasohm@923
   543
qed "UN_I";
clasohm@923
   544
paulson@5316
   545
val major::prems = Goalw [UNION_def]
clasohm@923
   546
    "[| b : (UN x:A. B(x));  !!x.[| x:A;  b: B(x) |] ==> R |] ==> R";
clasohm@923
   547
by (rtac (major RS CollectD RS bexE) 1);
clasohm@923
   548
by (REPEAT (ares_tac prems 1));
clasohm@923
   549
qed "UN_E";
clasohm@923
   550
paulson@2499
   551
AddIs  [UN_I];
paulson@2499
   552
AddSEs [UN_E];
paulson@2499
   553
paulson@6291
   554
val prems = Goalw [UNION_def]
clasohm@923
   555
    "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
clasohm@923
   556
\    (UN x:A. C(x)) = (UN x:B. D(x))";
paulson@6291
   557
by (asm_simp_tac (simpset() addsimps prems) 1);
clasohm@923
   558
qed "UN_cong";
clasohm@923
   559
clasohm@923
   560
nipkow@1548
   561
section "Intersections of families -- INTER x:A. B(x) is Inter(B``A)";
clasohm@923
   562
wenzelm@5069
   563
Goalw [INTER_def] "(b: (INT x:A. B(x))) = (ALL x:A. b: B(x))";
paulson@4477
   564
by Auto_tac;
paulson@2499
   565
qed "INT_iff";
paulson@2499
   566
paulson@2499
   567
Addsimps [INT_iff];
paulson@2499
   568
paulson@5316
   569
val prems = Goalw [INTER_def]
clasohm@923
   570
    "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))";
clasohm@923
   571
by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1));
clasohm@923
   572
qed "INT_I";
clasohm@923
   573
paulson@5143
   574
Goal "[| b : (INT x:A. B(x));  a:A |] ==> b: B(a)";
paulson@4477
   575
by Auto_tac;
clasohm@923
   576
qed "INT_D";
clasohm@923
   577
clasohm@923
   578
(*"Classical" elimination -- by the Excluded Middle on a:A *)
paulson@5316
   579
val major::prems = Goalw [INTER_def]
clasohm@923
   580
    "[| b : (INT x:A. B(x));  b: B(a) ==> R;  a~:A ==> R |] ==> R";
clasohm@923
   581
by (rtac (major RS CollectD RS ballE) 1);
clasohm@923
   582
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   583
qed "INT_E";
clasohm@923
   584
paulson@2499
   585
AddSIs [INT_I];
paulson@2499
   586
AddEs  [INT_D, INT_E];
paulson@2499
   587
paulson@6291
   588
val prems = Goalw [INTER_def]
clasohm@923
   589
    "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
clasohm@923
   590
\    (INT x:A. C(x)) = (INT x:B. D(x))";
paulson@6291
   591
by (asm_simp_tac (simpset() addsimps prems) 1);
clasohm@923
   592
qed "INT_cong";
clasohm@923
   593
clasohm@923
   594
nipkow@1548
   595
section "Union";
clasohm@923
   596
wenzelm@5069
   597
Goalw [Union_def] "(A : Union(C)) = (EX X:C. A:X)";
paulson@2891
   598
by (Blast_tac 1);
paulson@2499
   599
qed "Union_iff";
paulson@2499
   600
paulson@2499
   601
Addsimps [Union_iff];
paulson@2499
   602
clasohm@923
   603
(*The order of the premises presupposes that C is rigid; A may be flexible*)
paulson@5143
   604
Goal "[| X:C;  A:X |] ==> A : Union(C)";
paulson@4477
   605
by Auto_tac;
clasohm@923
   606
qed "UnionI";
clasohm@923
   607
paulson@5316
   608
val major::prems = Goalw [Union_def]
clasohm@923
   609
    "[| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R";
clasohm@923
   610
by (rtac (major RS UN_E) 1);
clasohm@923
   611
by (REPEAT (ares_tac prems 1));
clasohm@923
   612
qed "UnionE";
clasohm@923
   613
paulson@2499
   614
AddIs  [UnionI];
paulson@2499
   615
AddSEs [UnionE];
paulson@2499
   616
paulson@2499
   617
nipkow@1548
   618
section "Inter";
clasohm@923
   619
wenzelm@5069
   620
Goalw [Inter_def] "(A : Inter(C)) = (ALL X:C. A:X)";
paulson@2891
   621
by (Blast_tac 1);
paulson@2499
   622
qed "Inter_iff";
paulson@2499
   623
paulson@2499
   624
Addsimps [Inter_iff];
paulson@2499
   625
paulson@5316
   626
val prems = Goalw [Inter_def]
clasohm@923
   627
    "[| !!X. X:C ==> A:X |] ==> A : Inter(C)";
clasohm@923
   628
by (REPEAT (ares_tac ([INT_I] @ prems) 1));
clasohm@923
   629
qed "InterI";
clasohm@923
   630
clasohm@923
   631
(*A "destruct" rule -- every X in C contains A as an element, but
clasohm@923
   632
  A:X can hold when X:C does not!  This rule is analogous to "spec". *)
paulson@5143
   633
Goal "[| A : Inter(C);  X:C |] ==> A:X";
paulson@4477
   634
by Auto_tac;
clasohm@923
   635
qed "InterD";
clasohm@923
   636
clasohm@923
   637
(*"Classical" elimination rule -- does not require proving X:C *)
paulson@5316
   638
val major::prems = Goalw [Inter_def]
paulson@2721
   639
    "[| A : Inter(C);  X~:C ==> R;  A:X ==> R |] ==> R";
clasohm@923
   640
by (rtac (major RS INT_E) 1);
clasohm@923
   641
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   642
qed "InterE";
clasohm@923
   643
paulson@2499
   644
AddSIs [InterI];
paulson@2499
   645
AddEs  [InterD, InterE];
paulson@2499
   646
paulson@2499
   647
nipkow@2912
   648
(*** Image of a set under a function ***)
nipkow@2912
   649
nipkow@2912
   650
(*Frequently b does not have the syntactic form of f(x).*)
paulson@5316
   651
Goalw [image_def] "[| b=f(x);  x:A |] ==> b : f``A";
paulson@5316
   652
by (Blast_tac 1);
nipkow@2912
   653
qed "image_eqI";
nipkow@3909
   654
Addsimps [image_eqI];
nipkow@2912
   655
nipkow@2912
   656
bind_thm ("imageI", refl RS image_eqI);
nipkow@2912
   657
paulson@8025
   658
(*This version's more effective when we already have the required x*)
paulson@8025
   659
Goalw [image_def] "[| x:A;  b=f(x) |] ==> b : f``A";
paulson@8025
   660
by (Blast_tac 1);
paulson@8025
   661
qed "rev_image_eqI";
paulson@8025
   662
nipkow@2912
   663
(*The eta-expansion gives variable-name preservation.*)
paulson@5316
   664
val major::prems = Goalw [image_def]
wenzelm@3842
   665
    "[| b : (%x. f(x))``A;  !!x.[| b=f(x);  x:A |] ==> P |] ==> P"; 
nipkow@2912
   666
by (rtac (major RS CollectD RS bexE) 1);
nipkow@2912
   667
by (REPEAT (ares_tac prems 1));
nipkow@2912
   668
qed "imageE";
nipkow@2912
   669
nipkow@2912
   670
AddIs  [image_eqI];
nipkow@2912
   671
AddSEs [imageE]; 
nipkow@2912
   672
wenzelm@5069
   673
Goal "f``(A Un B) = f``A Un f``B";
paulson@2935
   674
by (Blast_tac 1);
nipkow@2912
   675
qed "image_Un";
nipkow@2912
   676
wenzelm@5069
   677
Goal "(z : f``A) = (EX x:A. z = f x)";
paulson@3960
   678
by (Blast_tac 1);
paulson@3960
   679
qed "image_iff";
paulson@3960
   680
paulson@4523
   681
(*This rewrite rule would confuse users if made default.*)
wenzelm@5069
   682
Goal "(f``A <= B) = (ALL x:A. f(x): B)";
paulson@4523
   683
by (Blast_tac 1);
paulson@4523
   684
qed "image_subset_iff";
paulson@4523
   685
paulson@4523
   686
(*Replaces the three steps subsetI, imageE, hyp_subst_tac, but breaks too
paulson@4523
   687
  many existing proofs.*)
paulson@5316
   688
val prems = Goal "(!!x. x:A ==> f(x) : B) ==> f``A <= B";
paulson@4510
   689
by (blast_tac (claset() addIs prems) 1);
paulson@4510
   690
qed "image_subsetI";
paulson@4510
   691
nipkow@2912
   692
nipkow@2912
   693
(*** Range of a function -- just a translation for image! ***)
nipkow@2912
   694
paulson@5143
   695
Goal "b=f(x) ==> b : range(f)";
nipkow@2912
   696
by (EVERY1 [etac image_eqI, rtac UNIV_I]);
nipkow@2912
   697
bind_thm ("range_eqI", UNIV_I RSN (2,image_eqI));
nipkow@2912
   698
nipkow@2912
   699
bind_thm ("rangeI", UNIV_I RS imageI);
nipkow@2912
   700
paulson@5316
   701
val [major,minor] = Goal 
wenzelm@3842
   702
    "[| b : range(%x. f(x));  !!x. b=f(x) ==> P |] ==> P"; 
nipkow@2912
   703
by (rtac (major RS imageE) 1);
nipkow@2912
   704
by (etac minor 1);
nipkow@2912
   705
qed "rangeE";
nipkow@2912
   706
oheimb@1776
   707
oheimb@1776
   708
(*** Set reasoning tools ***)
oheimb@1776
   709
oheimb@1776
   710
paulson@3912
   711
(** Rewrite rules for boolean case-splitting: faster than 
nipkow@4830
   712
	addsplits[split_if]
paulson@3912
   713
**)
paulson@3912
   714
nipkow@4830
   715
bind_thm ("split_if_eq1", read_instantiate [("P", "%x. x = ?b")] split_if);
nipkow@4830
   716
bind_thm ("split_if_eq2", read_instantiate [("P", "%x. ?a = x")] split_if);
paulson@3912
   717
paulson@5237
   718
(*Split ifs on either side of the membership relation.
paulson@5237
   719
	Not for Addsimps -- can cause goals to blow up!*)
nipkow@4830
   720
bind_thm ("split_if_mem1", 
wenzelm@6394
   721
    read_instantiate_sg (Theory.sign_of Set.thy) [("P", "%x. x : ?b")] split_if);
nipkow@4830
   722
bind_thm ("split_if_mem2", 
wenzelm@6394
   723
    read_instantiate_sg (Theory.sign_of Set.thy) [("P", "%x. ?a : x")] split_if);
paulson@3912
   724
nipkow@4830
   725
val split_ifs = [if_bool_eq_conj, split_if_eq1, split_if_eq2,
nipkow@4830
   726
		  split_if_mem1, split_if_mem2];
paulson@3912
   727
paulson@3912
   728
wenzelm@4089
   729
(*Each of these has ALREADY been added to simpset() above.*)
paulson@2024
   730
val mem_simps = [insert_iff, empty_iff, Un_iff, Int_iff, Compl_iff, Diff_iff, 
paulson@4159
   731
                 mem_Collect_eq, UN_iff, Union_iff, INT_iff, Inter_iff];
oheimb@1776
   732
oheimb@1776
   733
val mksimps_pairs = ("Ball",[bspec]) :: mksimps_pairs;
oheimb@1776
   734
paulson@6291
   735
simpset_ref() := simpset() setmksimps (mksimps mksimps_pairs);
nipkow@3222
   736
paulson@5256
   737
Addsimps[subset_UNIV, subset_refl];
nipkow@3222
   738
nipkow@3222
   739
paulson@8001
   740
(*** The 'proper subset' relation (<) ***)
nipkow@3222
   741
wenzelm@5069
   742
Goalw [psubset_def] "!!A::'a set. [| A <= B; A ~= B |] ==> A<B";
nipkow@3222
   743
by (Blast_tac 1);
nipkow@3222
   744
qed "psubsetI";
wenzelm@7658
   745
AddXIs [psubsetI];
nipkow@3222
   746
paulson@5148
   747
Goalw [psubset_def] "A < insert x B ==> (x ~: A) & A<=B | x:A & A-{x}<B";
paulson@4477
   748
by Auto_tac;
nipkow@3222
   749
qed "psubset_insertD";
paulson@4059
   750
paulson@4059
   751
bind_thm ("psubset_eq", psubset_def RS meta_eq_to_obj_eq);
wenzelm@6443
   752
wenzelm@6443
   753
bind_thm ("psubset_imp_subset", psubset_eq RS iffD1 RS conjunct1);
wenzelm@6443
   754
wenzelm@6443
   755
Goal"[| (A::'a set) < B; B <= C |] ==> A < C";
wenzelm@6443
   756
by (auto_tac (claset(), simpset() addsimps [psubset_eq]));
wenzelm@6443
   757
qed "psubset_subset_trans";
wenzelm@6443
   758
wenzelm@6443
   759
Goal"[| (A::'a set) <= B; B < C|] ==> A < C";
wenzelm@6443
   760
by (auto_tac (claset(), simpset() addsimps [psubset_eq]));
wenzelm@6443
   761
qed "subset_psubset_trans";
berghofe@7717
   762
paulson@8001
   763
Goalw [psubset_def] "A < B ==> EX b. b : (B - A)";
paulson@8001
   764
by (Blast_tac 1);
paulson@8001
   765
qed "psubset_imp_ex_mem";
paulson@8001
   766
berghofe@7717
   767
berghofe@7717
   768
(* attributes *)
berghofe@7717
   769
berghofe@7717
   770
local
berghofe@7717
   771
berghofe@7717
   772
fun gen_rulify_prems x =
berghofe@7717
   773
  Attrib.no_args (Drule.rule_attribute (fn _ => (standard o
berghofe@7717
   774
    rule_by_tactic (REPEAT (ALLGOALS (resolve_tac [allI, ballI, impI])))))) x;
berghofe@7717
   775
berghofe@7717
   776
in
berghofe@7717
   777
berghofe@7717
   778
val rulify_prems_attrib_setup =
berghofe@7717
   779
 [Attrib.add_attributes
berghofe@7717
   780
  [("rulify_prems", (gen_rulify_prems, gen_rulify_prems), "put theorem into standard rule form")]];
berghofe@7717
   781
berghofe@7717
   782
end;