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