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