src/HOL/Set.ML
author nipkow
Tue Jan 09 15:22:13 2001 +0100 (2001-01-09)
changeset 10832 e33b47e4246d
parent 10482 41de88cb2108
child 11007 438f31613093
permissions -rw-r--r--
`` -> and ``` -> ``
wenzelm@9422
     1
(*  Title:      HOL/Set.ML
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@9687
    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@9687
    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
wenzelm@9108
    32
bind_thm ("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]
paulson@9041
    41
    "[| !!x. x:A ==> P(x) |] ==> ALL x:A. P(x)";
clasohm@923
    42
by (REPEAT (ares_tac (prems @ [allI,impI]) 1));
clasohm@923
    43
qed "ballI";
clasohm@923
    44
wenzelm@8839
    45
bind_thms ("strip", [impI, allI, ballI]);
wenzelm@8839
    46
paulson@9041
    47
Goalw [Ball_def] "[| ALL 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]
paulson@9041
    52
    "[| ALL 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
paulson@9041
    57
(*Takes assumptions ALL 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@9041
    68
Goalw [Bex_def] "[| P(x);  x:A |] ==> EX 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@9041
    73
Goalw [Bex_def] "[| x:A;  P(x) |] ==> EX 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@9041
    78
   "[| ALL x:A. ~P(x) ==> P(a);  a:A |] ==> EX 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]
paulson@9041
    84
    "[| EX 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*)
paulson@9041
    93
Goal "(ALL x:A. P) = ((EX 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*)
paulson@9041
    98
Goal "(EX x:A. P) = ((EX 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) |] ==> \
paulson@9041
   108
\    (ALL x:A. P(x)) = (ALL 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) |] ==> \
paulson@9041
   114
\    (EX x:A. P(x)) = (EX 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
clasohm@923
   155
(*Classical elimination rule*)
paulson@5316
   156
val major::prems = Goalw [subset_def] 
clasohm@923
   157
    "[| A <= B;  c~:A ==> P;  c:B ==> P |] ==> P";
clasohm@923
   158
by (rtac (major RS ballE) 1);
clasohm@923
   159
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   160
qed "subsetCE";
clasohm@923
   161
clasohm@923
   162
(*Takes assumptions A<=B; c:A and creates the assumption c:B *)
clasohm@923
   163
fun set_mp_tac i = etac subsetCE i  THEN  mp_tac i;
clasohm@923
   164
paulson@2499
   165
AddSIs [subsetI];
paulson@2499
   166
AddEs  [subsetD, subsetCE];
clasohm@923
   167
paulson@10233
   168
Goal "[| A <= B; c ~: B |] ==> c ~: A";
paulson@10233
   169
by (Blast_tac 1);
paulson@10233
   170
qed "contra_subsetD";
paulson@10233
   171
paulson@7007
   172
Goal "A <= (A::'a set)";
paulson@7007
   173
by (Fast_tac 1);
paulson@10233
   174
qed "subset_refl";
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";
wenzelm@9108
   188
bind_thm ("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
oheimb@9338
   203
(*Be careful when adding this to the claset as subset_empty is in the simpset:
oheimb@9338
   204
  A={} goes to {}<=A and A<={} and then back to A={} !*)
paulson@5316
   205
val prems = Goal
clasohm@923
   206
    "[| A = B;  [| A<=B; B<=(A::'a set) |] ==> P |]  ==>  P";
clasohm@923
   207
by (resolve_tac prems 1);
clasohm@923
   208
by (REPEAT (resolve_tac (prems RL [equalityD1,equalityD2]) 1));
clasohm@923
   209
qed "equalityE";
clasohm@923
   210
paulson@5316
   211
val major::prems = Goal
clasohm@923
   212
    "[| A = B;  [| c:A; c:B |] ==> P;  [| c~:A; c~:B |] ==> P |]  ==>  P";
clasohm@923
   213
by (rtac (major RS equalityE) 1);
clasohm@923
   214
by (REPEAT (contr_tac 1 ORELSE eresolve_tac ([asm_rl,subsetCE]@prems) 1));
clasohm@923
   215
qed "equalityCE";
clasohm@923
   216
paulson@9186
   217
AddEs [equalityCE];
paulson@9186
   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
wenzelm@10482
   243
Goal "EX x. x : UNIV";
wenzelm@10482
   244
by (Simp_tac 1);
wenzelm@10482
   245
qed "UNIV_witness";
wenzelm@10482
   246
AddXIs [UNIV_witness];
wenzelm@10482
   247
paulson@7031
   248
Goal "A <= UNIV";
paulson@7031
   249
by (rtac subsetI 1);
paulson@7031
   250
by (rtac UNIV_I 1);
paulson@7031
   251
qed "subset_UNIV";
paulson@4159
   252
paulson@4159
   253
(** Eta-contracting these two rules (to remove P) causes them to be ignored
paulson@4159
   254
    because of their interaction with congruence rules. **)
paulson@4159
   255
wenzelm@5069
   256
Goalw [Ball_def] "Ball UNIV P = All P";
paulson@4159
   257
by (Simp_tac 1);
paulson@4159
   258
qed "ball_UNIV";
paulson@4159
   259
wenzelm@5069
   260
Goalw [Bex_def] "Bex UNIV P = Ex P";
paulson@4159
   261
by (Simp_tac 1);
paulson@4159
   262
qed "bex_UNIV";
paulson@4159
   263
Addsimps [ball_UNIV, bex_UNIV];
paulson@4159
   264
paulson@4159
   265
paulson@2858
   266
section "The empty set -- {}";
paulson@2858
   267
paulson@7007
   268
Goalw [empty_def] "(c : {}) = False";
paulson@7007
   269
by (Blast_tac 1) ;
paulson@7007
   270
qed "empty_iff";
paulson@2858
   271
paulson@2858
   272
Addsimps [empty_iff];
paulson@2858
   273
paulson@7007
   274
Goal "a:{} ==> P";
paulson@7007
   275
by (Full_simp_tac 1);
paulson@7007
   276
qed "emptyE";
paulson@2858
   277
paulson@2858
   278
AddSEs [emptyE];
paulson@2858
   279
paulson@7007
   280
Goal "{} <= A";
paulson@7007
   281
by (Blast_tac 1) ;
paulson@7007
   282
qed "empty_subsetI";
paulson@2858
   283
paulson@5256
   284
(*One effect is to delete the ASSUMPTION {} <= A*)
paulson@5256
   285
AddIffs [empty_subsetI];
paulson@5256
   286
paulson@7031
   287
val [prem]= Goal "[| !!y. y:A ==> False |] ==> A={}";
paulson@7007
   288
by (blast_tac (claset() addIs [prem RS FalseE]) 1) ;
paulson@7007
   289
qed "equals0I";
paulson@2858
   290
paulson@5256
   291
(*Use for reasoning about disjointness: A Int B = {} *)
paulson@7007
   292
Goal "A={} ==> a ~: A";
paulson@7007
   293
by (Blast_tac 1) ;
paulson@7007
   294
qed "equals0D";
paulson@2858
   295
wenzelm@5069
   296
Goalw [Ball_def] "Ball {} P = True";
paulson@4159
   297
by (Simp_tac 1);
paulson@4159
   298
qed "ball_empty";
paulson@4159
   299
wenzelm@5069
   300
Goalw [Bex_def] "Bex {} P = False";
paulson@4159
   301
by (Simp_tac 1);
paulson@4159
   302
qed "bex_empty";
paulson@4159
   303
Addsimps [ball_empty, bex_empty];
paulson@4159
   304
wenzelm@5069
   305
Goal "UNIV ~= {}";
paulson@4159
   306
by (blast_tac (claset() addEs [equalityE]) 1);
paulson@4159
   307
qed "UNIV_not_empty";
paulson@4159
   308
AddIffs [UNIV_not_empty];
paulson@4159
   309
paulson@4159
   310
paulson@2858
   311
paulson@2858
   312
section "The Powerset operator -- Pow";
paulson@2858
   313
paulson@7007
   314
Goalw [Pow_def] "(A : Pow(B)) = (A <= B)";
paulson@7007
   315
by (Asm_simp_tac 1);
paulson@7007
   316
qed "Pow_iff";
paulson@2858
   317
paulson@2858
   318
AddIffs [Pow_iff]; 
paulson@2858
   319
paulson@7031
   320
Goalw [Pow_def] "A <= B ==> A : Pow(B)";
paulson@7007
   321
by (etac CollectI 1);
paulson@7007
   322
qed "PowI";
paulson@2858
   323
paulson@7031
   324
Goalw [Pow_def] "A : Pow(B)  ==>  A<=B";
paulson@7007
   325
by (etac CollectD 1);
paulson@7007
   326
qed "PowD";
paulson@7007
   327
paulson@2858
   328
wenzelm@9108
   329
bind_thm ("Pow_bottom", empty_subsetI RS PowI);        (* {}: Pow(B) *)
wenzelm@9108
   330
bind_thm ("Pow_top", subset_refl RS PowI);             (* A : Pow(A) *)
paulson@2858
   331
paulson@2858
   332
paulson@5931
   333
section "Set complement";
clasohm@923
   334
paulson@7031
   335
Goalw [Compl_def] "(c : -A) = (c~:A)";
paulson@7031
   336
by (Blast_tac 1);
paulson@7031
   337
qed "Compl_iff";
paulson@2499
   338
paulson@2499
   339
Addsimps [Compl_iff];
paulson@2499
   340
paulson@5490
   341
val prems = Goalw [Compl_def] "[| c:A ==> False |] ==> c : -A";
clasohm@923
   342
by (REPEAT (ares_tac (prems @ [CollectI,notI]) 1));
clasohm@923
   343
qed "ComplI";
clasohm@923
   344
clasohm@923
   345
(*This form, with negated conclusion, works well with the Classical prover.
clasohm@923
   346
  Negated assumptions behave like formulae on the right side of the notional
clasohm@923
   347
  turnstile...*)
paulson@5490
   348
Goalw [Compl_def] "c : -A ==> c~:A";
paulson@5316
   349
by (etac CollectD 1);
clasohm@923
   350
qed "ComplD";
clasohm@923
   351
wenzelm@9108
   352
bind_thm ("ComplE", make_elim ComplD);
clasohm@923
   353
paulson@2499
   354
AddSIs [ComplI];
paulson@2499
   355
AddSEs [ComplE];
paulson@1640
   356
clasohm@923
   357
nipkow@1548
   358
section "Binary union -- Un";
clasohm@923
   359
paulson@7031
   360
Goalw [Un_def] "(c : A Un B) = (c:A | c:B)";
paulson@7031
   361
by (Blast_tac 1);
paulson@7031
   362
qed "Un_iff";
paulson@2499
   363
Addsimps [Un_iff];
paulson@2499
   364
paulson@5143
   365
Goal "c:A ==> c : A Un B";
paulson@2499
   366
by (Asm_simp_tac 1);
clasohm@923
   367
qed "UnI1";
clasohm@923
   368
paulson@5143
   369
Goal "c:B ==> c : A Un B";
paulson@2499
   370
by (Asm_simp_tac 1);
clasohm@923
   371
qed "UnI2";
clasohm@923
   372
wenzelm@9378
   373
AddXIs [UnI1, UnI2];
wenzelm@9378
   374
wenzelm@9378
   375
clasohm@923
   376
(*Classical introduction rule: no commitment to A vs B*)
paulson@7007
   377
paulson@7031
   378
val prems = Goal "(c~:B ==> c:A) ==> c : A Un B";
paulson@7007
   379
by (Simp_tac 1);
paulson@7007
   380
by (REPEAT (ares_tac (prems@[disjCI]) 1)) ;
paulson@7007
   381
qed "UnCI";
clasohm@923
   382
paulson@5316
   383
val major::prems = Goalw [Un_def]
clasohm@923
   384
    "[| c : A Un B;  c:A ==> P;  c:B ==> P |] ==> P";
clasohm@923
   385
by (rtac (major RS CollectD RS disjE) 1);
clasohm@923
   386
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   387
qed "UnE";
clasohm@923
   388
paulson@2499
   389
AddSIs [UnCI];
paulson@2499
   390
AddSEs [UnE];
paulson@1640
   391
clasohm@923
   392
nipkow@1548
   393
section "Binary intersection -- Int";
clasohm@923
   394
paulson@7031
   395
Goalw [Int_def] "(c : A Int B) = (c:A & c:B)";
paulson@7031
   396
by (Blast_tac 1);
paulson@7031
   397
qed "Int_iff";
paulson@2499
   398
Addsimps [Int_iff];
paulson@2499
   399
paulson@5143
   400
Goal "[| c:A;  c:B |] ==> c : A Int B";
paulson@2499
   401
by (Asm_simp_tac 1);
clasohm@923
   402
qed "IntI";
clasohm@923
   403
paulson@5143
   404
Goal "c : A Int B ==> c:A";
paulson@2499
   405
by (Asm_full_simp_tac 1);
clasohm@923
   406
qed "IntD1";
clasohm@923
   407
paulson@5143
   408
Goal "c : A Int B ==> c:B";
paulson@2499
   409
by (Asm_full_simp_tac 1);
clasohm@923
   410
qed "IntD2";
clasohm@923
   411
paulson@5316
   412
val [major,minor] = Goal
clasohm@923
   413
    "[| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P";
clasohm@923
   414
by (rtac minor 1);
clasohm@923
   415
by (rtac (major RS IntD1) 1);
clasohm@923
   416
by (rtac (major RS IntD2) 1);
clasohm@923
   417
qed "IntE";
clasohm@923
   418
paulson@2499
   419
AddSIs [IntI];
paulson@2499
   420
AddSEs [IntE];
clasohm@923
   421
nipkow@1548
   422
section "Set difference";
clasohm@923
   423
paulson@7031
   424
Goalw [set_diff_def] "(c : A-B) = (c:A & c~:B)";
paulson@7031
   425
by (Blast_tac 1);
paulson@7031
   426
qed "Diff_iff";
paulson@2499
   427
Addsimps [Diff_iff];
paulson@2499
   428
paulson@7007
   429
Goal "[| c : A;  c ~: B |] ==> c : A - B";
paulson@7007
   430
by (Asm_simp_tac 1) ;
paulson@7007
   431
qed "DiffI";
clasohm@923
   432
paulson@7007
   433
Goal "c : A - B ==> c : A";
paulson@7007
   434
by (Asm_full_simp_tac 1) ;
paulson@7007
   435
qed "DiffD1";
clasohm@923
   436
paulson@7007
   437
Goal "[| c : A - B;  c : B |] ==> P";
paulson@7007
   438
by (Asm_full_simp_tac 1) ;
paulson@7007
   439
qed "DiffD2";
paulson@2499
   440
paulson@7031
   441
val prems = Goal "[| c : A - B;  [| c:A; c~:B |] ==> P |] ==> P";
paulson@7007
   442
by (resolve_tac prems 1);
paulson@7007
   443
by (REPEAT (ares_tac (prems RL [DiffD1, DiffD2 RS notI]) 1)) ;
paulson@7007
   444
qed "DiffE";
clasohm@923
   445
paulson@2499
   446
AddSIs [DiffI];
paulson@2499
   447
AddSEs [DiffE];
clasohm@923
   448
clasohm@923
   449
nipkow@1548
   450
section "Augmenting a set -- insert";
clasohm@923
   451
paulson@7031
   452
Goalw [insert_def] "a : insert b A = (a=b | a:A)";
paulson@7031
   453
by (Blast_tac 1);
paulson@7031
   454
qed "insert_iff";
paulson@2499
   455
Addsimps [insert_iff];
clasohm@923
   456
paulson@7031
   457
Goal "a : insert a B";
paulson@7007
   458
by (Simp_tac 1);
paulson@7007
   459
qed "insertI1";
clasohm@923
   460
paulson@7007
   461
Goal "!!a. a : B ==> a : insert b B";
paulson@7007
   462
by (Asm_simp_tac 1);
paulson@7007
   463
qed "insertI2";
paulson@7007
   464
paulson@7007
   465
val major::prems = Goalw [insert_def]
paulson@7007
   466
    "[| a : insert b A;  a=b ==> P;  a:A ==> P |] ==> P";
paulson@7007
   467
by (rtac (major RS UnE) 1);
paulson@7007
   468
by (REPEAT (eresolve_tac (prems @ [CollectE]) 1));
paulson@7007
   469
qed "insertE";
clasohm@923
   470
clasohm@923
   471
(*Classical introduction rule*)
paulson@7031
   472
val prems = Goal "(a~:B ==> a=b) ==> a: insert b B";
paulson@7007
   473
by (Simp_tac 1);
paulson@7007
   474
by (REPEAT (ares_tac (prems@[disjCI]) 1)) ;
paulson@7007
   475
qed "insertCI";
paulson@2499
   476
paulson@2499
   477
AddSIs [insertCI]; 
paulson@2499
   478
AddSEs [insertE];
clasohm@923
   479
paulson@9088
   480
Goal "(A <= insert x B) = (if x:A then A-{x} <= B else A<=B)";
paulson@9088
   481
by Auto_tac; 
paulson@9088
   482
qed "subset_insert_iff";
oheimb@7496
   483
nipkow@1548
   484
section "Singletons, using insert";
clasohm@923
   485
paulson@7007
   486
Goal "a : {a}";
paulson@7007
   487
by (rtac insertI1 1) ;
paulson@7007
   488
qed "singletonI";
clasohm@923
   489
paulson@5143
   490
Goal "b : {a} ==> b=a";
paulson@2891
   491
by (Blast_tac 1);
clasohm@923
   492
qed "singletonD";
clasohm@923
   493
oheimb@1776
   494
bind_thm ("singletonE", make_elim singletonD);
oheimb@1776
   495
paulson@7007
   496
Goal "(b : {a}) = (b=a)";
paulson@7007
   497
by (Blast_tac 1);
paulson@7007
   498
qed "singleton_iff";
clasohm@923
   499
paulson@5143
   500
Goal "{a}={b} ==> a=b";
wenzelm@4089
   501
by (blast_tac (claset() addEs [equalityE]) 1);
clasohm@923
   502
qed "singleton_inject";
clasohm@923
   503
paulson@2858
   504
(*Redundant? But unlike insertCI, it proves the subgoal immediately!*)
paulson@2858
   505
AddSIs [singletonI];   
paulson@2499
   506
AddSDs [singleton_inject];
paulson@3718
   507
AddSEs [singletonE];
paulson@2499
   508
oheimb@7969
   509
Goal "{b} = insert a A = (a = b & A <= {b})";
paulson@8326
   510
by (blast_tac (claset() addSEs [equalityE]) 1);
oheimb@7496
   511
qed "singleton_insert_inj_eq";
oheimb@7496
   512
paulson@8326
   513
Goal "(insert a A = {b}) = (a = b & A <= {b})";
paulson@8326
   514
by (blast_tac (claset() addSEs [equalityE]) 1);
oheimb@7969
   515
qed "singleton_insert_inj_eq'";
oheimb@7969
   516
paulson@8326
   517
AddIffs [singleton_insert_inj_eq, singleton_insert_inj_eq'];
paulson@8326
   518
oheimb@7496
   519
Goal "A <= {x} ==> A={} | A = {x}";
oheimb@7496
   520
by (Fast_tac 1);
oheimb@7496
   521
qed "subset_singletonD";
oheimb@7496
   522
wenzelm@5069
   523
Goal "{x. x=a} = {a}";
wenzelm@4423
   524
by (Blast_tac 1);
nipkow@3582
   525
qed "singleton_conv";
nipkow@3582
   526
Addsimps [singleton_conv];
nipkow@1531
   527
nipkow@5600
   528
Goal "{x. a=x} = {a}";
paulson@6301
   529
by (Blast_tac 1);
nipkow@5600
   530
qed "singleton_conv2";
nipkow@5600
   531
Addsimps [singleton_conv2];
nipkow@5600
   532
nipkow@1531
   533
nipkow@10832
   534
section "Unions of families -- UNION x:A. B(x) is Union(B`A)";
clasohm@923
   535
wenzelm@5069
   536
Goalw [UNION_def] "(b: (UN x:A. B(x))) = (EX x:A. b: B(x))";
paulson@2891
   537
by (Blast_tac 1);
paulson@2499
   538
qed "UN_iff";
paulson@2499
   539
paulson@2499
   540
Addsimps [UN_iff];
paulson@2499
   541
clasohm@923
   542
(*The order of the premises presupposes that A is rigid; b may be flexible*)
paulson@5143
   543
Goal "[| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))";
paulson@4477
   544
by Auto_tac;
clasohm@923
   545
qed "UN_I";
clasohm@923
   546
paulson@5316
   547
val major::prems = Goalw [UNION_def]
clasohm@923
   548
    "[| b : (UN x:A. B(x));  !!x.[| x:A;  b: B(x) |] ==> R |] ==> R";
clasohm@923
   549
by (rtac (major RS CollectD RS bexE) 1);
clasohm@923
   550
by (REPEAT (ares_tac prems 1));
clasohm@923
   551
qed "UN_E";
clasohm@923
   552
paulson@2499
   553
AddIs  [UN_I];
paulson@2499
   554
AddSEs [UN_E];
paulson@2499
   555
paulson@6291
   556
val prems = Goalw [UNION_def]
clasohm@923
   557
    "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
clasohm@923
   558
\    (UN x:A. C(x)) = (UN x:B. D(x))";
paulson@6291
   559
by (asm_simp_tac (simpset() addsimps prems) 1);
clasohm@923
   560
qed "UN_cong";
paulson@9687
   561
Addcongs [UN_cong];
clasohm@923
   562
clasohm@923
   563
nipkow@10832
   564
section "Intersections of families -- INTER x:A. B(x) is Inter(B`A)";
clasohm@923
   565
wenzelm@5069
   566
Goalw [INTER_def] "(b: (INT x:A. B(x))) = (ALL x:A. b: B(x))";
paulson@4477
   567
by Auto_tac;
paulson@2499
   568
qed "INT_iff";
paulson@2499
   569
paulson@2499
   570
Addsimps [INT_iff];
paulson@2499
   571
paulson@5316
   572
val prems = Goalw [INTER_def]
clasohm@923
   573
    "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))";
clasohm@923
   574
by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1));
clasohm@923
   575
qed "INT_I";
clasohm@923
   576
paulson@5143
   577
Goal "[| b : (INT x:A. B(x));  a:A |] ==> b: B(a)";
paulson@4477
   578
by Auto_tac;
clasohm@923
   579
qed "INT_D";
clasohm@923
   580
clasohm@923
   581
(*"Classical" elimination -- by the Excluded Middle on a:A *)
paulson@5316
   582
val major::prems = Goalw [INTER_def]
clasohm@923
   583
    "[| b : (INT x:A. B(x));  b: B(a) ==> R;  a~:A ==> R |] ==> R";
clasohm@923
   584
by (rtac (major RS CollectD RS ballE) 1);
clasohm@923
   585
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   586
qed "INT_E";
clasohm@923
   587
paulson@2499
   588
AddSIs [INT_I];
paulson@2499
   589
AddEs  [INT_D, INT_E];
paulson@2499
   590
paulson@6291
   591
val prems = Goalw [INTER_def]
clasohm@923
   592
    "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
clasohm@923
   593
\    (INT x:A. C(x)) = (INT x:B. D(x))";
paulson@6291
   594
by (asm_simp_tac (simpset() addsimps prems) 1);
clasohm@923
   595
qed "INT_cong";
paulson@9687
   596
Addcongs [INT_cong];
clasohm@923
   597
clasohm@923
   598
nipkow@1548
   599
section "Union";
clasohm@923
   600
wenzelm@5069
   601
Goalw [Union_def] "(A : Union(C)) = (EX X:C. A:X)";
paulson@2891
   602
by (Blast_tac 1);
paulson@2499
   603
qed "Union_iff";
paulson@2499
   604
paulson@2499
   605
Addsimps [Union_iff];
paulson@2499
   606
clasohm@923
   607
(*The order of the premises presupposes that C is rigid; A may be flexible*)
paulson@5143
   608
Goal "[| X:C;  A:X |] ==> A : Union(C)";
paulson@4477
   609
by Auto_tac;
clasohm@923
   610
qed "UnionI";
clasohm@923
   611
paulson@5316
   612
val major::prems = Goalw [Union_def]
clasohm@923
   613
    "[| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R";
clasohm@923
   614
by (rtac (major RS UN_E) 1);
clasohm@923
   615
by (REPEAT (ares_tac prems 1));
clasohm@923
   616
qed "UnionE";
clasohm@923
   617
paulson@2499
   618
AddIs  [UnionI];
paulson@2499
   619
AddSEs [UnionE];
paulson@2499
   620
paulson@2499
   621
nipkow@1548
   622
section "Inter";
clasohm@923
   623
wenzelm@5069
   624
Goalw [Inter_def] "(A : Inter(C)) = (ALL X:C. A:X)";
paulson@2891
   625
by (Blast_tac 1);
paulson@2499
   626
qed "Inter_iff";
paulson@2499
   627
paulson@2499
   628
Addsimps [Inter_iff];
paulson@2499
   629
paulson@5316
   630
val prems = Goalw [Inter_def]
clasohm@923
   631
    "[| !!X. X:C ==> A:X |] ==> A : Inter(C)";
clasohm@923
   632
by (REPEAT (ares_tac ([INT_I] @ prems) 1));
clasohm@923
   633
qed "InterI";
clasohm@923
   634
clasohm@923
   635
(*A "destruct" rule -- every X in C contains A as an element, but
clasohm@923
   636
  A:X can hold when X:C does not!  This rule is analogous to "spec". *)
paulson@5143
   637
Goal "[| A : Inter(C);  X:C |] ==> A:X";
paulson@4477
   638
by Auto_tac;
clasohm@923
   639
qed "InterD";
clasohm@923
   640
clasohm@923
   641
(*"Classical" elimination rule -- does not require proving X:C *)
paulson@5316
   642
val major::prems = Goalw [Inter_def]
paulson@2721
   643
    "[| A : Inter(C);  X~:C ==> R;  A:X ==> R |] ==> R";
clasohm@923
   644
by (rtac (major RS INT_E) 1);
clasohm@923
   645
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   646
qed "InterE";
clasohm@923
   647
paulson@2499
   648
AddSIs [InterI];
paulson@2499
   649
AddEs  [InterD, InterE];
paulson@2499
   650
paulson@2499
   651
nipkow@2912
   652
(*** Image of a set under a function ***)
nipkow@2912
   653
nipkow@2912
   654
(*Frequently b does not have the syntactic form of f(x).*)
nipkow@10832
   655
Goalw [image_def] "[| b=f(x);  x:A |] ==> b : f`A";
paulson@5316
   656
by (Blast_tac 1);
nipkow@2912
   657
qed "image_eqI";
nipkow@3909
   658
Addsimps [image_eqI];
nipkow@2912
   659
nipkow@2912
   660
bind_thm ("imageI", refl RS image_eqI);
nipkow@2912
   661
paulson@8025
   662
(*This version's more effective when we already have the required x*)
nipkow@10832
   663
Goalw [image_def] "[| x:A;  b=f(x) |] ==> b : f`A";
paulson@8025
   664
by (Blast_tac 1);
paulson@8025
   665
qed "rev_image_eqI";
paulson@8025
   666
nipkow@2912
   667
(*The eta-expansion gives variable-name preservation.*)
paulson@5316
   668
val major::prems = Goalw [image_def]
nipkow@10832
   669
    "[| b : (%x. f(x))`A;  !!x.[| b=f(x);  x:A |] ==> P |] ==> P"; 
nipkow@2912
   670
by (rtac (major RS CollectD RS bexE) 1);
nipkow@2912
   671
by (REPEAT (ares_tac prems 1));
nipkow@2912
   672
qed "imageE";
nipkow@2912
   673
nipkow@2912
   674
AddIs  [image_eqI];
nipkow@2912
   675
AddSEs [imageE]; 
nipkow@2912
   676
nipkow@10832
   677
Goal "f`(A Un B) = f`A Un f`B";
paulson@2935
   678
by (Blast_tac 1);
nipkow@2912
   679
qed "image_Un";
nipkow@2912
   680
nipkow@10832
   681
Goal "(z : f`A) = (EX x:A. z = f x)";
paulson@3960
   682
by (Blast_tac 1);
paulson@3960
   683
qed "image_iff";
paulson@3960
   684
paulson@4523
   685
(*This rewrite rule would confuse users if made default.*)
nipkow@10832
   686
Goal "(f`A <= B) = (ALL x:A. f(x): B)";
paulson@4523
   687
by (Blast_tac 1);
paulson@4523
   688
qed "image_subset_iff";
paulson@4523
   689
paulson@4523
   690
(*Replaces the three steps subsetI, imageE, hyp_subst_tac, but breaks too
paulson@4523
   691
  many existing proofs.*)
nipkow@10832
   692
val prems = Goal "(!!x. x:A ==> f(x) : B) ==> f`A <= B";
paulson@4510
   693
by (blast_tac (claset() addIs prems) 1);
paulson@4510
   694
qed "image_subsetI";
paulson@4510
   695
nipkow@2912
   696
nipkow@2912
   697
(*** Range of a function -- just a translation for image! ***)
nipkow@2912
   698
paulson@5143
   699
Goal "b=f(x) ==> b : range(f)";
nipkow@2912
   700
by (EVERY1 [etac image_eqI, rtac UNIV_I]);
nipkow@2912
   701
bind_thm ("range_eqI", UNIV_I RSN (2,image_eqI));
nipkow@2912
   702
nipkow@2912
   703
bind_thm ("rangeI", UNIV_I RS imageI);
nipkow@2912
   704
paulson@5316
   705
val [major,minor] = Goal 
wenzelm@3842
   706
    "[| b : range(%x. f(x));  !!x. b=f(x) ==> P |] ==> P"; 
nipkow@2912
   707
by (rtac (major RS imageE) 1);
nipkow@2912
   708
by (etac minor 1);
nipkow@2912
   709
qed "rangeE";
wenzelm@10482
   710
AddXEs [rangeE];
nipkow@2912
   711
oheimb@1776
   712
oheimb@1776
   713
(*** Set reasoning tools ***)
oheimb@1776
   714
oheimb@1776
   715
paulson@3912
   716
(** Rewrite rules for boolean case-splitting: faster than 
nipkow@4830
   717
	addsplits[split_if]
paulson@3912
   718
**)
paulson@3912
   719
nipkow@4830
   720
bind_thm ("split_if_eq1", read_instantiate [("P", "%x. x = ?b")] split_if);
nipkow@4830
   721
bind_thm ("split_if_eq2", read_instantiate [("P", "%x. ?a = x")] split_if);
paulson@3912
   722
paulson@5237
   723
(*Split ifs on either side of the membership relation.
paulson@5237
   724
	Not for Addsimps -- can cause goals to blow up!*)
paulson@9969
   725
bind_thm ("split_if_mem1", inst "P" "%x. x : ?b" split_if);
paulson@9969
   726
bind_thm ("split_if_mem2", inst "P" "%x. ?a : x" split_if);
paulson@3912
   727
wenzelm@9108
   728
bind_thms ("split_ifs", [if_bool_eq_conj, split_if_eq1, split_if_eq2,
paulson@9969
   729
			 split_if_mem1, split_if_mem2]);
paulson@3912
   730
paulson@3912
   731
wenzelm@4089
   732
(*Each of these has ALREADY been added to simpset() above.*)
wenzelm@9108
   733
bind_thms ("mem_simps", [insert_iff, empty_iff, Un_iff, Int_iff, Compl_iff, Diff_iff, 
wenzelm@9108
   734
                 mem_Collect_eq, UN_iff, Union_iff, INT_iff, Inter_iff]);
oheimb@1776
   735
paulson@9041
   736
(*Would like to add these, but the existing code only searches for the 
paulson@9041
   737
  outer-level constant, which in this case is just "op :"; we instead need
paulson@9041
   738
  to use term-nets to associate patterns with rules.  Also, if a rule fails to
paulson@9041
   739
  apply, then the formula should be kept.
paulson@9041
   740
  [("uminus", Compl_iff RS iffD1), ("op -", [Diff_iff RS iffD1]), 
paulson@9041
   741
   ("op Int", [IntD1,IntD2]),
paulson@9041
   742
   ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])]
paulson@9041
   743
 *)
paulson@9041
   744
val mksimps_pairs =
paulson@9041
   745
  [("Ball",[bspec])] @ mksimps_pairs;
oheimb@1776
   746
paulson@6291
   747
simpset_ref() := simpset() setmksimps (mksimps mksimps_pairs);
nipkow@3222
   748
paulson@5256
   749
Addsimps[subset_UNIV, subset_refl];
nipkow@3222
   750
nipkow@3222
   751
paulson@8001
   752
(*** The 'proper subset' relation (<) ***)
nipkow@3222
   753
wenzelm@5069
   754
Goalw [psubset_def] "!!A::'a set. [| A <= B; A ~= B |] ==> A<B";
nipkow@3222
   755
by (Blast_tac 1);
nipkow@3222
   756
qed "psubsetI";
paulson@8913
   757
AddSIs [psubsetI];
nipkow@3222
   758
paulson@9088
   759
Goalw [psubset_def]
paulson@9088
   760
  "(A < insert x B) = (if x:B then A<B else if x:A then A-{x} < B else A<=B)";
paulson@9088
   761
by (asm_simp_tac (simpset() addsimps [subset_insert_iff]) 1);
paulson@9088
   762
by (Blast_tac 1); 
paulson@9088
   763
qed "psubset_insert_iff";
paulson@4059
   764
paulson@4059
   765
bind_thm ("psubset_eq", psubset_def RS meta_eq_to_obj_eq);
wenzelm@6443
   766
wenzelm@6443
   767
bind_thm ("psubset_imp_subset", psubset_eq RS iffD1 RS conjunct1);
wenzelm@6443
   768
wenzelm@6443
   769
Goal"[| (A::'a set) < B; B <= C |] ==> A < C";
wenzelm@6443
   770
by (auto_tac (claset(), simpset() addsimps [psubset_eq]));
wenzelm@6443
   771
qed "psubset_subset_trans";
wenzelm@6443
   772
wenzelm@6443
   773
Goal"[| (A::'a set) <= B; B < C|] ==> A < C";
wenzelm@6443
   774
by (auto_tac (claset(), simpset() addsimps [psubset_eq]));
wenzelm@6443
   775
qed "subset_psubset_trans";
berghofe@7717
   776
paulson@8001
   777
Goalw [psubset_def] "A < B ==> EX b. b : (B - A)";
paulson@8001
   778
by (Blast_tac 1);
paulson@8001
   779
qed "psubset_imp_ex_mem";
paulson@8001
   780
berghofe@7717
   781
wenzelm@9892
   782
(* rulify setup *)
wenzelm@9892
   783
wenzelm@9892
   784
Goal "(!!x. x:A ==> P x) == Trueprop (ALL x:A. P x)";
wenzelm@9892
   785
by (simp_tac (simpset () addsimps (Ball_def :: thms "atomize")) 1);
wenzelm@9892
   786
qed "ball_eq";
berghofe@7717
   787
berghofe@7717
   788
local
wenzelm@9892
   789
  val ss = HOL_basic_ss addsimps
wenzelm@9892
   790
    (Drule.norm_hhf_eq :: map Thm.symmetric (ball_eq :: thms "atomize"));
berghofe@7717
   791
in
berghofe@7717
   792
wenzelm@9892
   793
structure Rulify = RulifyFun
wenzelm@9892
   794
 (val make_meta = Simplifier.simplify ss
wenzelm@9892
   795
  val full_make_meta = Simplifier.full_simplify ss);
wenzelm@9892
   796
wenzelm@9892
   797
structure BasicRulify: BASIC_RULIFY = Rulify;
wenzelm@9892
   798
open BasicRulify;
berghofe@7717
   799
berghofe@7717
   800
end;