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