src/HOL/Set.ML
author wenzelm
Wed Sep 29 16:45:04 1999 +0200 (1999-09-29)
changeset 7658 2d3445be4e91
parent 7499 23e090051cb8
child 7717 e7ecfa617443
permissions -rw-r--r--
CollectE;
AddXIs [subsetD, rev_subsetD, psubsetI];
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@5336
   138
Blast.overloaded ("op ``", 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
clasohm@923
   228
paulson@4159
   229
section "The universal set -- UNIV";
paulson@4159
   230
paulson@7031
   231
Goalw [UNIV_def] "x : UNIV";
paulson@7031
   232
by (rtac CollectI 1);
paulson@7031
   233
by (rtac TrueI 1);
paulson@7031
   234
qed "UNIV_I";
paulson@4159
   235
paulson@4434
   236
Addsimps [UNIV_I];
paulson@4434
   237
AddIs    [UNIV_I];  (*unsafe makes it less likely to cause problems*)
paulson@4159
   238
paulson@7031
   239
Goal "A <= UNIV";
paulson@7031
   240
by (rtac subsetI 1);
paulson@7031
   241
by (rtac UNIV_I 1);
paulson@7031
   242
qed "subset_UNIV";
paulson@4159
   243
paulson@4159
   244
(** Eta-contracting these two rules (to remove P) causes them to be ignored
paulson@4159
   245
    because of their interaction with congruence rules. **)
paulson@4159
   246
wenzelm@5069
   247
Goalw [Ball_def] "Ball UNIV P = All P";
paulson@4159
   248
by (Simp_tac 1);
paulson@4159
   249
qed "ball_UNIV";
paulson@4159
   250
wenzelm@5069
   251
Goalw [Bex_def] "Bex UNIV P = Ex P";
paulson@4159
   252
by (Simp_tac 1);
paulson@4159
   253
qed "bex_UNIV";
paulson@4159
   254
Addsimps [ball_UNIV, bex_UNIV];
paulson@4159
   255
paulson@4159
   256
paulson@2858
   257
section "The empty set -- {}";
paulson@2858
   258
paulson@7007
   259
Goalw [empty_def] "(c : {}) = False";
paulson@7007
   260
by (Blast_tac 1) ;
paulson@7007
   261
qed "empty_iff";
paulson@2858
   262
paulson@2858
   263
Addsimps [empty_iff];
paulson@2858
   264
paulson@7007
   265
Goal "a:{} ==> P";
paulson@7007
   266
by (Full_simp_tac 1);
paulson@7007
   267
qed "emptyE";
paulson@2858
   268
paulson@2858
   269
AddSEs [emptyE];
paulson@2858
   270
paulson@7007
   271
Goal "{} <= A";
paulson@7007
   272
by (Blast_tac 1) ;
paulson@7007
   273
qed "empty_subsetI";
paulson@2858
   274
paulson@5256
   275
(*One effect is to delete the ASSUMPTION {} <= A*)
paulson@5256
   276
AddIffs [empty_subsetI];
paulson@5256
   277
paulson@7031
   278
val [prem]= Goal "[| !!y. y:A ==> False |] ==> A={}";
paulson@7007
   279
by (blast_tac (claset() addIs [prem RS FalseE]) 1) ;
paulson@7007
   280
qed "equals0I";
paulson@2858
   281
paulson@5256
   282
(*Use for reasoning about disjointness: A Int B = {} *)
paulson@7007
   283
Goal "A={} ==> a ~: A";
paulson@7007
   284
by (Blast_tac 1) ;
paulson@7007
   285
qed "equals0D";
paulson@2858
   286
paulson@5450
   287
AddDs [equals0D, sym RS equals0D];
paulson@5256
   288
wenzelm@5069
   289
Goalw [Ball_def] "Ball {} P = True";
paulson@4159
   290
by (Simp_tac 1);
paulson@4159
   291
qed "ball_empty";
paulson@4159
   292
wenzelm@5069
   293
Goalw [Bex_def] "Bex {} P = False";
paulson@4159
   294
by (Simp_tac 1);
paulson@4159
   295
qed "bex_empty";
paulson@4159
   296
Addsimps [ball_empty, bex_empty];
paulson@4159
   297
wenzelm@5069
   298
Goal "UNIV ~= {}";
paulson@4159
   299
by (blast_tac (claset() addEs [equalityE]) 1);
paulson@4159
   300
qed "UNIV_not_empty";
paulson@4159
   301
AddIffs [UNIV_not_empty];
paulson@4159
   302
paulson@4159
   303
paulson@2858
   304
paulson@2858
   305
section "The Powerset operator -- Pow";
paulson@2858
   306
paulson@7007
   307
Goalw [Pow_def] "(A : Pow(B)) = (A <= B)";
paulson@7007
   308
by (Asm_simp_tac 1);
paulson@7007
   309
qed "Pow_iff";
paulson@2858
   310
paulson@2858
   311
AddIffs [Pow_iff]; 
paulson@2858
   312
paulson@7031
   313
Goalw [Pow_def] "A <= B ==> A : Pow(B)";
paulson@7007
   314
by (etac CollectI 1);
paulson@7007
   315
qed "PowI";
paulson@2858
   316
paulson@7031
   317
Goalw [Pow_def] "A : Pow(B)  ==>  A<=B";
paulson@7007
   318
by (etac CollectD 1);
paulson@7007
   319
qed "PowD";
paulson@7007
   320
paulson@2858
   321
paulson@2858
   322
val Pow_bottom = empty_subsetI RS PowI;        (* {}: Pow(B) *)
paulson@2858
   323
val Pow_top = subset_refl RS PowI;             (* A : Pow(A) *)
paulson@2858
   324
paulson@2858
   325
paulson@5931
   326
section "Set complement";
clasohm@923
   327
paulson@7031
   328
Goalw [Compl_def] "(c : -A) = (c~:A)";
paulson@7031
   329
by (Blast_tac 1);
paulson@7031
   330
qed "Compl_iff";
paulson@2499
   331
paulson@2499
   332
Addsimps [Compl_iff];
paulson@2499
   333
paulson@5490
   334
val prems = Goalw [Compl_def] "[| c:A ==> False |] ==> c : -A";
clasohm@923
   335
by (REPEAT (ares_tac (prems @ [CollectI,notI]) 1));
clasohm@923
   336
qed "ComplI";
clasohm@923
   337
clasohm@923
   338
(*This form, with negated conclusion, works well with the Classical prover.
clasohm@923
   339
  Negated assumptions behave like formulae on the right side of the notional
clasohm@923
   340
  turnstile...*)
paulson@5490
   341
Goalw [Compl_def] "c : -A ==> c~:A";
paulson@5316
   342
by (etac CollectD 1);
clasohm@923
   343
qed "ComplD";
clasohm@923
   344
clasohm@923
   345
val ComplE = make_elim ComplD;
clasohm@923
   346
paulson@2499
   347
AddSIs [ComplI];
paulson@2499
   348
AddSEs [ComplE];
paulson@1640
   349
clasohm@923
   350
nipkow@1548
   351
section "Binary union -- Un";
clasohm@923
   352
paulson@7031
   353
Goalw [Un_def] "(c : A Un B) = (c:A | c:B)";
paulson@7031
   354
by (Blast_tac 1);
paulson@7031
   355
qed "Un_iff";
paulson@2499
   356
Addsimps [Un_iff];
paulson@2499
   357
paulson@5143
   358
Goal "c:A ==> c : A Un B";
paulson@2499
   359
by (Asm_simp_tac 1);
clasohm@923
   360
qed "UnI1";
clasohm@923
   361
paulson@5143
   362
Goal "c:B ==> c : A Un B";
paulson@2499
   363
by (Asm_simp_tac 1);
clasohm@923
   364
qed "UnI2";
clasohm@923
   365
clasohm@923
   366
(*Classical introduction rule: no commitment to A vs B*)
paulson@7007
   367
paulson@7031
   368
val prems = Goal "(c~:B ==> c:A) ==> c : A Un B";
paulson@7007
   369
by (Simp_tac 1);
paulson@7007
   370
by (REPEAT (ares_tac (prems@[disjCI]) 1)) ;
paulson@7007
   371
qed "UnCI";
clasohm@923
   372
paulson@5316
   373
val major::prems = Goalw [Un_def]
clasohm@923
   374
    "[| c : A Un B;  c:A ==> P;  c:B ==> P |] ==> P";
clasohm@923
   375
by (rtac (major RS CollectD RS disjE) 1);
clasohm@923
   376
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   377
qed "UnE";
clasohm@923
   378
paulson@2499
   379
AddSIs [UnCI];
paulson@2499
   380
AddSEs [UnE];
paulson@1640
   381
clasohm@923
   382
nipkow@1548
   383
section "Binary intersection -- Int";
clasohm@923
   384
paulson@7031
   385
Goalw [Int_def] "(c : A Int B) = (c:A & c:B)";
paulson@7031
   386
by (Blast_tac 1);
paulson@7031
   387
qed "Int_iff";
paulson@2499
   388
Addsimps [Int_iff];
paulson@2499
   389
paulson@5143
   390
Goal "[| c:A;  c:B |] ==> c : A Int B";
paulson@2499
   391
by (Asm_simp_tac 1);
clasohm@923
   392
qed "IntI";
clasohm@923
   393
paulson@5143
   394
Goal "c : A Int B ==> c:A";
paulson@2499
   395
by (Asm_full_simp_tac 1);
clasohm@923
   396
qed "IntD1";
clasohm@923
   397
paulson@5143
   398
Goal "c : A Int B ==> c:B";
paulson@2499
   399
by (Asm_full_simp_tac 1);
clasohm@923
   400
qed "IntD2";
clasohm@923
   401
paulson@5316
   402
val [major,minor] = Goal
clasohm@923
   403
    "[| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P";
clasohm@923
   404
by (rtac minor 1);
clasohm@923
   405
by (rtac (major RS IntD1) 1);
clasohm@923
   406
by (rtac (major RS IntD2) 1);
clasohm@923
   407
qed "IntE";
clasohm@923
   408
paulson@2499
   409
AddSIs [IntI];
paulson@2499
   410
AddSEs [IntE];
clasohm@923
   411
nipkow@1548
   412
section "Set difference";
clasohm@923
   413
paulson@7031
   414
Goalw [set_diff_def] "(c : A-B) = (c:A & c~:B)";
paulson@7031
   415
by (Blast_tac 1);
paulson@7031
   416
qed "Diff_iff";
paulson@2499
   417
Addsimps [Diff_iff];
paulson@2499
   418
paulson@7007
   419
Goal "[| c : A;  c ~: B |] ==> c : A - B";
paulson@7007
   420
by (Asm_simp_tac 1) ;
paulson@7007
   421
qed "DiffI";
clasohm@923
   422
paulson@7007
   423
Goal "c : A - B ==> c : A";
paulson@7007
   424
by (Asm_full_simp_tac 1) ;
paulson@7007
   425
qed "DiffD1";
clasohm@923
   426
paulson@7007
   427
Goal "[| c : A - B;  c : B |] ==> P";
paulson@7007
   428
by (Asm_full_simp_tac 1) ;
paulson@7007
   429
qed "DiffD2";
paulson@2499
   430
paulson@7031
   431
val prems = Goal "[| c : A - B;  [| c:A; c~:B |] ==> P |] ==> P";
paulson@7007
   432
by (resolve_tac prems 1);
paulson@7007
   433
by (REPEAT (ares_tac (prems RL [DiffD1, DiffD2 RS notI]) 1)) ;
paulson@7007
   434
qed "DiffE";
clasohm@923
   435
paulson@2499
   436
AddSIs [DiffI];
paulson@2499
   437
AddSEs [DiffE];
clasohm@923
   438
clasohm@923
   439
nipkow@1548
   440
section "Augmenting a set -- insert";
clasohm@923
   441
paulson@7031
   442
Goalw [insert_def] "a : insert b A = (a=b | a:A)";
paulson@7031
   443
by (Blast_tac 1);
paulson@7031
   444
qed "insert_iff";
paulson@2499
   445
Addsimps [insert_iff];
clasohm@923
   446
paulson@7031
   447
Goal "a : insert a B";
paulson@7007
   448
by (Simp_tac 1);
paulson@7007
   449
qed "insertI1";
clasohm@923
   450
paulson@7007
   451
Goal "!!a. a : B ==> a : insert b B";
paulson@7007
   452
by (Asm_simp_tac 1);
paulson@7007
   453
qed "insertI2";
paulson@7007
   454
paulson@7007
   455
val major::prems = Goalw [insert_def]
paulson@7007
   456
    "[| a : insert b A;  a=b ==> P;  a:A ==> P |] ==> P";
paulson@7007
   457
by (rtac (major RS UnE) 1);
paulson@7007
   458
by (REPEAT (eresolve_tac (prems @ [CollectE]) 1));
paulson@7007
   459
qed "insertE";
clasohm@923
   460
clasohm@923
   461
(*Classical introduction rule*)
paulson@7031
   462
val prems = Goal "(a~:B ==> a=b) ==> a: insert b B";
paulson@7007
   463
by (Simp_tac 1);
paulson@7007
   464
by (REPEAT (ares_tac (prems@[disjCI]) 1)) ;
paulson@7007
   465
qed "insertCI";
paulson@2499
   466
paulson@2499
   467
AddSIs [insertCI]; 
paulson@2499
   468
AddSEs [insertE];
clasohm@923
   469
oheimb@7496
   470
Goal "A <= insert x B ==> A <= B & x ~: A | (? B'. A = insert x B' & B' <= B)";
oheimb@7496
   471
by (case_tac "x:A" 1);
oheimb@7496
   472
by  (Fast_tac 2);
wenzelm@7499
   473
by (rtac disjI2 1);
oheimb@7496
   474
by (res_inst_tac [("x","A-{x}")] exI 1);
oheimb@7496
   475
by (Fast_tac 1);
oheimb@7496
   476
qed "subset_insertD";
oheimb@7496
   477
nipkow@1548
   478
section "Singletons, using insert";
clasohm@923
   479
paulson@7007
   480
Goal "a : {a}";
paulson@7007
   481
by (rtac insertI1 1) ;
paulson@7007
   482
qed "singletonI";
clasohm@923
   483
paulson@5143
   484
Goal "b : {a} ==> b=a";
paulson@2891
   485
by (Blast_tac 1);
clasohm@923
   486
qed "singletonD";
clasohm@923
   487
oheimb@1776
   488
bind_thm ("singletonE", make_elim singletonD);
oheimb@1776
   489
paulson@7007
   490
Goal "(b : {a}) = (b=a)";
paulson@7007
   491
by (Blast_tac 1);
paulson@7007
   492
qed "singleton_iff";
clasohm@923
   493
paulson@5143
   494
Goal "{a}={b} ==> a=b";
wenzelm@4089
   495
by (blast_tac (claset() addEs [equalityE]) 1);
clasohm@923
   496
qed "singleton_inject";
clasohm@923
   497
paulson@2858
   498
(*Redundant? But unlike insertCI, it proves the subgoal immediately!*)
paulson@2858
   499
AddSIs [singletonI];   
paulson@2499
   500
AddSDs [singleton_inject];
paulson@3718
   501
AddSEs [singletonE];
paulson@2499
   502
oheimb@7496
   503
Goal "{b} = insert a A = (a = b & A <= {a})";
oheimb@7496
   504
by (safe_tac (claset() addSEs [equalityE]));
oheimb@7496
   505
by   (ALLGOALS Blast_tac);
oheimb@7496
   506
qed "singleton_insert_inj_eq";
oheimb@7496
   507
oheimb@7496
   508
Goal "A <= {x} ==> A={} | A = {x}";
oheimb@7496
   509
by (Fast_tac 1);
oheimb@7496
   510
qed "subset_singletonD";
oheimb@7496
   511
wenzelm@5069
   512
Goal "{x. x=a} = {a}";
wenzelm@4423
   513
by (Blast_tac 1);
nipkow@3582
   514
qed "singleton_conv";
nipkow@3582
   515
Addsimps [singleton_conv];
nipkow@1531
   516
nipkow@5600
   517
Goal "{x. a=x} = {a}";
paulson@6301
   518
by (Blast_tac 1);
nipkow@5600
   519
qed "singleton_conv2";
nipkow@5600
   520
Addsimps [singleton_conv2];
nipkow@5600
   521
nipkow@1531
   522
nipkow@1548
   523
section "Unions of families -- UNION x:A. B(x) is Union(B``A)";
clasohm@923
   524
wenzelm@5069
   525
Goalw [UNION_def] "(b: (UN x:A. B(x))) = (EX x:A. b: B(x))";
paulson@2891
   526
by (Blast_tac 1);
paulson@2499
   527
qed "UN_iff";
paulson@2499
   528
paulson@2499
   529
Addsimps [UN_iff];
paulson@2499
   530
clasohm@923
   531
(*The order of the premises presupposes that A is rigid; b may be flexible*)
paulson@5143
   532
Goal "[| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))";
paulson@4477
   533
by Auto_tac;
clasohm@923
   534
qed "UN_I";
clasohm@923
   535
paulson@5316
   536
val major::prems = Goalw [UNION_def]
clasohm@923
   537
    "[| b : (UN x:A. B(x));  !!x.[| x:A;  b: B(x) |] ==> R |] ==> R";
clasohm@923
   538
by (rtac (major RS CollectD RS bexE) 1);
clasohm@923
   539
by (REPEAT (ares_tac prems 1));
clasohm@923
   540
qed "UN_E";
clasohm@923
   541
paulson@2499
   542
AddIs  [UN_I];
paulson@2499
   543
AddSEs [UN_E];
paulson@2499
   544
paulson@6291
   545
val prems = Goalw [UNION_def]
clasohm@923
   546
    "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
clasohm@923
   547
\    (UN x:A. C(x)) = (UN x:B. D(x))";
paulson@6291
   548
by (asm_simp_tac (simpset() addsimps prems) 1);
clasohm@923
   549
qed "UN_cong";
clasohm@923
   550
clasohm@923
   551
nipkow@1548
   552
section "Intersections of families -- INTER x:A. B(x) is Inter(B``A)";
clasohm@923
   553
wenzelm@5069
   554
Goalw [INTER_def] "(b: (INT x:A. B(x))) = (ALL x:A. b: B(x))";
paulson@4477
   555
by Auto_tac;
paulson@2499
   556
qed "INT_iff";
paulson@2499
   557
paulson@2499
   558
Addsimps [INT_iff];
paulson@2499
   559
paulson@5316
   560
val prems = Goalw [INTER_def]
clasohm@923
   561
    "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))";
clasohm@923
   562
by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1));
clasohm@923
   563
qed "INT_I";
clasohm@923
   564
paulson@5143
   565
Goal "[| b : (INT x:A. B(x));  a:A |] ==> b: B(a)";
paulson@4477
   566
by Auto_tac;
clasohm@923
   567
qed "INT_D";
clasohm@923
   568
clasohm@923
   569
(*"Classical" elimination -- by the Excluded Middle on a:A *)
paulson@5316
   570
val major::prems = Goalw [INTER_def]
clasohm@923
   571
    "[| b : (INT x:A. B(x));  b: B(a) ==> R;  a~:A ==> R |] ==> R";
clasohm@923
   572
by (rtac (major RS CollectD RS ballE) 1);
clasohm@923
   573
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   574
qed "INT_E";
clasohm@923
   575
paulson@2499
   576
AddSIs [INT_I];
paulson@2499
   577
AddEs  [INT_D, INT_E];
paulson@2499
   578
paulson@6291
   579
val prems = Goalw [INTER_def]
clasohm@923
   580
    "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
clasohm@923
   581
\    (INT x:A. C(x)) = (INT x:B. D(x))";
paulson@6291
   582
by (asm_simp_tac (simpset() addsimps prems) 1);
clasohm@923
   583
qed "INT_cong";
clasohm@923
   584
clasohm@923
   585
nipkow@1548
   586
section "Union";
clasohm@923
   587
wenzelm@5069
   588
Goalw [Union_def] "(A : Union(C)) = (EX X:C. A:X)";
paulson@2891
   589
by (Blast_tac 1);
paulson@2499
   590
qed "Union_iff";
paulson@2499
   591
paulson@2499
   592
Addsimps [Union_iff];
paulson@2499
   593
clasohm@923
   594
(*The order of the premises presupposes that C is rigid; A may be flexible*)
paulson@5143
   595
Goal "[| X:C;  A:X |] ==> A : Union(C)";
paulson@4477
   596
by Auto_tac;
clasohm@923
   597
qed "UnionI";
clasohm@923
   598
paulson@5316
   599
val major::prems = Goalw [Union_def]
clasohm@923
   600
    "[| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R";
clasohm@923
   601
by (rtac (major RS UN_E) 1);
clasohm@923
   602
by (REPEAT (ares_tac prems 1));
clasohm@923
   603
qed "UnionE";
clasohm@923
   604
paulson@2499
   605
AddIs  [UnionI];
paulson@2499
   606
AddSEs [UnionE];
paulson@2499
   607
paulson@2499
   608
nipkow@1548
   609
section "Inter";
clasohm@923
   610
wenzelm@5069
   611
Goalw [Inter_def] "(A : Inter(C)) = (ALL X:C. A:X)";
paulson@2891
   612
by (Blast_tac 1);
paulson@2499
   613
qed "Inter_iff";
paulson@2499
   614
paulson@2499
   615
Addsimps [Inter_iff];
paulson@2499
   616
paulson@5316
   617
val prems = Goalw [Inter_def]
clasohm@923
   618
    "[| !!X. X:C ==> A:X |] ==> A : Inter(C)";
clasohm@923
   619
by (REPEAT (ares_tac ([INT_I] @ prems) 1));
clasohm@923
   620
qed "InterI";
clasohm@923
   621
clasohm@923
   622
(*A "destruct" rule -- every X in C contains A as an element, but
clasohm@923
   623
  A:X can hold when X:C does not!  This rule is analogous to "spec". *)
paulson@5143
   624
Goal "[| A : Inter(C);  X:C |] ==> A:X";
paulson@4477
   625
by Auto_tac;
clasohm@923
   626
qed "InterD";
clasohm@923
   627
clasohm@923
   628
(*"Classical" elimination rule -- does not require proving X:C *)
paulson@5316
   629
val major::prems = Goalw [Inter_def]
paulson@2721
   630
    "[| A : Inter(C);  X~:C ==> R;  A:X ==> R |] ==> R";
clasohm@923
   631
by (rtac (major RS INT_E) 1);
clasohm@923
   632
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   633
qed "InterE";
clasohm@923
   634
paulson@2499
   635
AddSIs [InterI];
paulson@2499
   636
AddEs  [InterD, InterE];
paulson@2499
   637
paulson@2499
   638
nipkow@2912
   639
(*** Image of a set under a function ***)
nipkow@2912
   640
nipkow@2912
   641
(*Frequently b does not have the syntactic form of f(x).*)
paulson@5316
   642
Goalw [image_def] "[| b=f(x);  x:A |] ==> b : f``A";
paulson@5316
   643
by (Blast_tac 1);
nipkow@2912
   644
qed "image_eqI";
nipkow@3909
   645
Addsimps [image_eqI];
nipkow@2912
   646
nipkow@2912
   647
bind_thm ("imageI", refl RS image_eqI);
nipkow@2912
   648
nipkow@2912
   649
(*The eta-expansion gives variable-name preservation.*)
paulson@5316
   650
val major::prems = Goalw [image_def]
wenzelm@3842
   651
    "[| b : (%x. f(x))``A;  !!x.[| b=f(x);  x:A |] ==> P |] ==> P"; 
nipkow@2912
   652
by (rtac (major RS CollectD RS bexE) 1);
nipkow@2912
   653
by (REPEAT (ares_tac prems 1));
nipkow@2912
   654
qed "imageE";
nipkow@2912
   655
nipkow@2912
   656
AddIs  [image_eqI];
nipkow@2912
   657
AddSEs [imageE]; 
nipkow@2912
   658
wenzelm@5069
   659
Goal "f``(A Un B) = f``A Un f``B";
paulson@2935
   660
by (Blast_tac 1);
nipkow@2912
   661
qed "image_Un";
nipkow@2912
   662
wenzelm@5069
   663
Goal "(z : f``A) = (EX x:A. z = f x)";
paulson@3960
   664
by (Blast_tac 1);
paulson@3960
   665
qed "image_iff";
paulson@3960
   666
paulson@4523
   667
(*This rewrite rule would confuse users if made default.*)
wenzelm@5069
   668
Goal "(f``A <= B) = (ALL x:A. f(x): B)";
paulson@4523
   669
by (Blast_tac 1);
paulson@4523
   670
qed "image_subset_iff";
paulson@4523
   671
paulson@4523
   672
(*Replaces the three steps subsetI, imageE, hyp_subst_tac, but breaks too
paulson@4523
   673
  many existing proofs.*)
paulson@5316
   674
val prems = Goal "(!!x. x:A ==> f(x) : B) ==> f``A <= B";
paulson@4510
   675
by (blast_tac (claset() addIs prems) 1);
paulson@4510
   676
qed "image_subsetI";
paulson@4510
   677
nipkow@2912
   678
nipkow@2912
   679
(*** Range of a function -- just a translation for image! ***)
nipkow@2912
   680
paulson@5143
   681
Goal "b=f(x) ==> b : range(f)";
nipkow@2912
   682
by (EVERY1 [etac image_eqI, rtac UNIV_I]);
nipkow@2912
   683
bind_thm ("range_eqI", UNIV_I RSN (2,image_eqI));
nipkow@2912
   684
nipkow@2912
   685
bind_thm ("rangeI", UNIV_I RS imageI);
nipkow@2912
   686
paulson@5316
   687
val [major,minor] = Goal 
wenzelm@3842
   688
    "[| b : range(%x. f(x));  !!x. b=f(x) ==> P |] ==> P"; 
nipkow@2912
   689
by (rtac (major RS imageE) 1);
nipkow@2912
   690
by (etac minor 1);
nipkow@2912
   691
qed "rangeE";
nipkow@2912
   692
oheimb@1776
   693
oheimb@1776
   694
(*** Set reasoning tools ***)
oheimb@1776
   695
oheimb@1776
   696
paulson@3912
   697
(** Rewrite rules for boolean case-splitting: faster than 
nipkow@4830
   698
	addsplits[split_if]
paulson@3912
   699
**)
paulson@3912
   700
nipkow@4830
   701
bind_thm ("split_if_eq1", read_instantiate [("P", "%x. x = ?b")] split_if);
nipkow@4830
   702
bind_thm ("split_if_eq2", read_instantiate [("P", "%x. ?a = x")] split_if);
paulson@3912
   703
paulson@5237
   704
(*Split ifs on either side of the membership relation.
paulson@5237
   705
	Not for Addsimps -- can cause goals to blow up!*)
nipkow@4830
   706
bind_thm ("split_if_mem1", 
wenzelm@6394
   707
    read_instantiate_sg (Theory.sign_of Set.thy) [("P", "%x. x : ?b")] split_if);
nipkow@4830
   708
bind_thm ("split_if_mem2", 
wenzelm@6394
   709
    read_instantiate_sg (Theory.sign_of Set.thy) [("P", "%x. ?a : x")] split_if);
paulson@3912
   710
nipkow@4830
   711
val split_ifs = [if_bool_eq_conj, split_if_eq1, split_if_eq2,
nipkow@4830
   712
		  split_if_mem1, split_if_mem2];
paulson@3912
   713
paulson@3912
   714
wenzelm@4089
   715
(*Each of these has ALREADY been added to simpset() above.*)
paulson@2024
   716
val mem_simps = [insert_iff, empty_iff, Un_iff, Int_iff, Compl_iff, Diff_iff, 
paulson@4159
   717
                 mem_Collect_eq, UN_iff, Union_iff, INT_iff, Inter_iff];
oheimb@1776
   718
oheimb@1776
   719
val mksimps_pairs = ("Ball",[bspec]) :: mksimps_pairs;
oheimb@1776
   720
paulson@6291
   721
simpset_ref() := simpset() setmksimps (mksimps mksimps_pairs);
nipkow@3222
   722
paulson@5256
   723
Addsimps[subset_UNIV, subset_refl];
nipkow@3222
   724
nipkow@3222
   725
nipkow@3222
   726
(*** < ***)
nipkow@3222
   727
wenzelm@5069
   728
Goalw [psubset_def] "!!A::'a set. [| A <= B; A ~= B |] ==> A<B";
nipkow@3222
   729
by (Blast_tac 1);
nipkow@3222
   730
qed "psubsetI";
wenzelm@7658
   731
AddXIs [psubsetI];
nipkow@3222
   732
paulson@5148
   733
Goalw [psubset_def] "A < insert x B ==> (x ~: A) & A<=B | x:A & A-{x}<B";
paulson@4477
   734
by Auto_tac;
nipkow@3222
   735
qed "psubset_insertD";
paulson@4059
   736
paulson@4059
   737
bind_thm ("psubset_eq", psubset_def RS meta_eq_to_obj_eq);
wenzelm@6443
   738
wenzelm@6443
   739
bind_thm ("psubset_imp_subset", psubset_eq RS iffD1 RS conjunct1);
wenzelm@6443
   740
wenzelm@6443
   741
Goal"[| (A::'a set) < B; B <= C |] ==> A < C";
wenzelm@6443
   742
by (auto_tac (claset(), simpset() addsimps [psubset_eq]));
wenzelm@6443
   743
qed "psubset_subset_trans";
wenzelm@6443
   744
wenzelm@6443
   745
Goal"[| (A::'a set) <= B; B < C|] ==> A < C";
wenzelm@6443
   746
by (auto_tac (claset(), simpset() addsimps [psubset_eq]));
wenzelm@6443
   747
qed "subset_psubset_trans";