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