src/HOL/Set.ML
author wenzelm
Thu Jun 22 23:04:34 2000 +0200 (2000-06-22)
changeset 9108 9fff97d29837
parent 9088 453996655ac2
child 9161 cee6d5aee7c8
permissions -rw-r--r--
bind_thm(s);
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
wenzelm@7658
    22
bind_thm ("CollectE", make_elim CollectD);
wenzelm@7658
    23
paulson@5316
    24
val [prem] = Goal "[| !!x. (x:A) = (x:B) |] ==> A = B";
clasohm@923
    25
by (rtac (prem RS ext RS arg_cong RS box_equals) 1);
clasohm@923
    26
by (rtac Collect_mem_eq 1);
clasohm@923
    27
by (rtac Collect_mem_eq 1);
clasohm@923
    28
qed "set_ext";
clasohm@923
    29
paulson@5316
    30
val [prem] = Goal "[| !!x. P(x)=Q(x) |] ==> {x. P(x)} = {x. Q(x)}";
clasohm@923
    31
by (rtac (prem RS ext RS arg_cong) 1);
clasohm@923
    32
qed "Collect_cong";
clasohm@923
    33
wenzelm@9108
    34
bind_thm ("CollectE", make_elim CollectD);
clasohm@923
    35
paulson@2499
    36
AddSIs [CollectI];
paulson@2499
    37
AddSEs [CollectE];
paulson@2499
    38
paulson@2499
    39
nipkow@1548
    40
section "Bounded quantifiers";
clasohm@923
    41
paulson@5316
    42
val prems = Goalw [Ball_def]
paulson@9041
    43
    "[| !!x. x:A ==> P(x) |] ==> ALL x:A. P(x)";
clasohm@923
    44
by (REPEAT (ares_tac (prems @ [allI,impI]) 1));
clasohm@923
    45
qed "ballI";
clasohm@923
    46
wenzelm@8839
    47
bind_thms ("strip", [impI, allI, ballI]);
wenzelm@8839
    48
paulson@9041
    49
Goalw [Ball_def] "[| ALL x:A. P(x);  x:A |] ==> P(x)";
paulson@5316
    50
by (Blast_tac 1);
clasohm@923
    51
qed "bspec";
clasohm@923
    52
paulson@5316
    53
val major::prems = Goalw [Ball_def]
paulson@9041
    54
    "[| ALL x:A. P(x);  P(x) ==> Q;  x~:A ==> Q |] ==> Q";
clasohm@923
    55
by (rtac (major RS spec RS impCE) 1);
clasohm@923
    56
by (REPEAT (eresolve_tac prems 1));
clasohm@923
    57
qed "ballE";
clasohm@923
    58
paulson@9041
    59
(*Takes assumptions ALL x:A.P(x) and a:A; creates assumption P(a)*)
clasohm@923
    60
fun ball_tac i = etac ballE i THEN contr_tac (i+1);
clasohm@923
    61
paulson@2499
    62
AddSIs [ballI];
paulson@2499
    63
AddEs  [ballE];
wenzelm@7441
    64
AddXDs [bspec];
oheimb@5521
    65
(* gives better instantiation for bound: *)
oheimb@5521
    66
claset_ref() := claset() addWrapper ("bspec", fn tac2 =>
oheimb@5521
    67
			 (dtac bspec THEN' atac) APPEND' tac2);
paulson@2499
    68
paulson@6006
    69
(*Normally the best argument order: P(x) constrains the choice of x:A*)
paulson@9041
    70
Goalw [Bex_def] "[| P(x);  x:A |] ==> EX x:A. P(x)";
paulson@5316
    71
by (Blast_tac 1);
clasohm@923
    72
qed "bexI";
clasohm@923
    73
paulson@6006
    74
(*The best argument order when there is only one x:A*)
paulson@9041
    75
Goalw [Bex_def] "[| x:A;  P(x) |] ==> EX x:A. P(x)";
paulson@6006
    76
by (Blast_tac 1);
paulson@6006
    77
qed "rev_bexI";
paulson@6006
    78
paulson@7031
    79
val prems = Goal 
paulson@9041
    80
   "[| ALL x:A. ~P(x) ==> P(a);  a:A |] ==> EX x:A. P(x)";
paulson@7007
    81
by (rtac classical 1);
paulson@7007
    82
by (REPEAT (ares_tac (prems@[bexI,ballI,notI,notE]) 1))  ;
paulson@7007
    83
qed "bexCI";
clasohm@923
    84
paulson@5316
    85
val major::prems = Goalw [Bex_def]
paulson@9041
    86
    "[| EX x:A. P(x);  !!x. [| x:A; P(x) |] ==> Q  |] ==> Q";
clasohm@923
    87
by (rtac (major RS exE) 1);
clasohm@923
    88
by (REPEAT (eresolve_tac (prems @ [asm_rl,conjE]) 1));
clasohm@923
    89
qed "bexE";
clasohm@923
    90
paulson@2499
    91
AddIs  [bexI];
paulson@2499
    92
AddSEs [bexE];
paulson@2499
    93
paulson@3420
    94
(*Trival rewrite rule*)
paulson@9041
    95
Goal "(ALL x:A. P) = ((EX x. x:A) --> P)";
wenzelm@4089
    96
by (simp_tac (simpset() addsimps [Ball_def]) 1);
paulson@3420
    97
qed "ball_triv";
paulson@1816
    98
paulson@1882
    99
(*Dual form for existentials*)
paulson@9041
   100
Goal "(EX x:A. P) = ((EX x. x:A) & P)";
wenzelm@4089
   101
by (simp_tac (simpset() addsimps [Bex_def]) 1);
paulson@3420
   102
qed "bex_triv";
paulson@1882
   103
paulson@3420
   104
Addsimps [ball_triv, bex_triv];
clasohm@923
   105
clasohm@923
   106
(** Congruence rules **)
clasohm@923
   107
paulson@6291
   108
val prems = Goalw [Ball_def]
clasohm@923
   109
    "[| A=B;  !!x. x:B ==> P(x) = Q(x) |] ==> \
paulson@9041
   110
\    (ALL x:A. P(x)) = (ALL x:B. Q(x))";
paulson@6291
   111
by (asm_simp_tac (simpset() addsimps prems) 1);
clasohm@923
   112
qed "ball_cong";
clasohm@923
   113
paulson@6291
   114
val prems = Goalw [Bex_def]
clasohm@923
   115
    "[| A=B;  !!x. x:B ==> P(x) = Q(x) |] ==> \
paulson@9041
   116
\    (EX x:A. P(x)) = (EX x:B. Q(x))";
paulson@6291
   117
by (asm_simp_tac (simpset() addcongs [conj_cong] addsimps prems) 1);
clasohm@923
   118
qed "bex_cong";
clasohm@923
   119
paulson@6291
   120
Addcongs [ball_cong,bex_cong];
paulson@6291
   121
nipkow@1548
   122
section "Subsets";
clasohm@923
   123
paulson@5316
   124
val prems = Goalw [subset_def] "(!!x. x:A ==> x:B) ==> A <= B";
clasohm@923
   125
by (REPEAT (ares_tac (prems @ [ballI]) 1));
clasohm@923
   126
qed "subsetI";
clasohm@923
   127
paulson@5649
   128
(*Map the type ('a set => anything) to just 'a.
paulson@5649
   129
  For overloading constants whose first argument has type "'a set" *)
paulson@5649
   130
fun overload_1st_set s = Blast.overloaded (s, HOLogic.dest_setT o domain_type);
paulson@5649
   131
paulson@4059
   132
(*While (:) is not, its type must be kept
paulson@4059
   133
  for overloading of = to work.*)
paulson@4240
   134
Blast.overloaded ("op :", domain_type);
paulson@5649
   135
paulson@5649
   136
overload_1st_set "Ball";		(*need UNION, INTER also?*)
paulson@5649
   137
overload_1st_set "Bex";
paulson@4059
   138
paulson@4469
   139
(*Image: retain the type of the set being expressed*)
paulson@8005
   140
Blast.overloaded ("image", domain_type);
paulson@2881
   141
clasohm@923
   142
(*Rule in Modus Ponens style*)
paulson@5316
   143
Goalw [subset_def] "[| A <= B;  c:A |] ==> c:B";
paulson@5316
   144
by (Blast_tac 1);
clasohm@923
   145
qed "subsetD";
wenzelm@7658
   146
AddXIs [subsetD];
clasohm@923
   147
clasohm@923
   148
(*The same, with reversed premises for use with etac -- cf rev_mp*)
paulson@7007
   149
Goal "[| c:A;  A <= B |] ==> c:B";
paulson@7007
   150
by (REPEAT (ares_tac [subsetD] 1)) ;
paulson@7007
   151
qed "rev_subsetD";
wenzelm@7658
   152
AddXIs [rev_subsetD];
clasohm@923
   153
paulson@1920
   154
(*Converts A<=B to x:A ==> x:B*)
paulson@1920
   155
fun impOfSubs th = th RSN (2, rev_subsetD);
paulson@1920
   156
paulson@7007
   157
Goal "[| A <= B; c ~: B |] ==> c ~: A";
paulson@7007
   158
by (REPEAT (eresolve_tac [asm_rl, contrapos, subsetD] 1)) ;
paulson@7007
   159
qed "contra_subsetD";
paulson@1841
   160
paulson@7007
   161
Goal "[| c ~: B;  A <= B |] ==> c ~: A";
paulson@7007
   162
by (REPEAT (eresolve_tac [asm_rl, contrapos, subsetD] 1)) ;
paulson@7007
   163
qed "rev_contra_subsetD";
paulson@1841
   164
clasohm@923
   165
(*Classical elimination rule*)
paulson@5316
   166
val major::prems = Goalw [subset_def] 
clasohm@923
   167
    "[| A <= B;  c~:A ==> P;  c:B ==> P |] ==> P";
clasohm@923
   168
by (rtac (major RS ballE) 1);
clasohm@923
   169
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   170
qed "subsetCE";
clasohm@923
   171
clasohm@923
   172
(*Takes assumptions A<=B; c:A and creates the assumption c:B *)
clasohm@923
   173
fun set_mp_tac i = etac subsetCE i  THEN  mp_tac i;
clasohm@923
   174
paulson@2499
   175
AddSIs [subsetI];
paulson@2499
   176
AddEs  [subsetD, subsetCE];
clasohm@923
   177
paulson@7007
   178
Goal "A <= (A::'a set)";
paulson@7007
   179
by (Fast_tac 1);
paulson@7007
   180
qed "subset_refl";		(*Blast_tac would try order_refl and fail*)
paulson@2499
   181
paulson@5316
   182
Goal "[| A<=B;  B<=C |] ==> A<=(C::'a set)";
paulson@2891
   183
by (Blast_tac 1);
clasohm@923
   184
qed "subset_trans";
clasohm@923
   185
clasohm@923
   186
nipkow@1548
   187
section "Equality";
clasohm@923
   188
clasohm@923
   189
(*Anti-symmetry of the subset relation*)
paulson@5316
   190
Goal "[| A <= B;  B <= A |] ==> A = (B::'a set)";
paulson@5318
   191
by (rtac set_ext 1);
paulson@5316
   192
by (blast_tac (claset() addIs [subsetD]) 1);
clasohm@923
   193
qed "subset_antisym";
wenzelm@9108
   194
bind_thm ("equalityI", subset_antisym);
clasohm@923
   195
berghofe@1762
   196
AddSIs [equalityI];
berghofe@1762
   197
clasohm@923
   198
(* Equality rules from ZF set theory -- are they appropriate here? *)
paulson@5316
   199
Goal "A = B ==> A<=(B::'a set)";
paulson@5316
   200
by (etac ssubst 1);
clasohm@923
   201
by (rtac subset_refl 1);
clasohm@923
   202
qed "equalityD1";
clasohm@923
   203
paulson@5316
   204
Goal "A = B ==> B<=(A::'a set)";
paulson@5316
   205
by (etac ssubst 1);
clasohm@923
   206
by (rtac subset_refl 1);
clasohm@923
   207
qed "equalityD2";
clasohm@923
   208
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@9075
   215
AddEs [equalityE];
paulson@9041
   216
paulson@5316
   217
val major::prems = Goal
clasohm@923
   218
    "[| A = B;  [| c:A; c:B |] ==> P;  [| c~:A; c~:B |] ==> P |]  ==>  P";
clasohm@923
   219
by (rtac (major RS equalityE) 1);
clasohm@923
   220
by (REPEAT (contr_tac 1 ORELSE eresolve_tac ([asm_rl,subsetCE]@prems) 1));
clasohm@923
   221
qed "equalityCE";
clasohm@923
   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
clasohm@923
   372
(*Classical introduction rule: no commitment to A vs B*)
paulson@7007
   373
paulson@7031
   374
val prems = Goal "(c~:B ==> c:A) ==> c : A Un B";
paulson@7007
   375
by (Simp_tac 1);
paulson@7007
   376
by (REPEAT (ares_tac (prems@[disjCI]) 1)) ;
paulson@7007
   377
qed "UnCI";
clasohm@923
   378
paulson@5316
   379
val major::prems = Goalw [Un_def]
clasohm@923
   380
    "[| c : A Un B;  c:A ==> P;  c:B ==> P |] ==> P";
clasohm@923
   381
by (rtac (major RS CollectD RS disjE) 1);
clasohm@923
   382
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   383
qed "UnE";
clasohm@923
   384
paulson@2499
   385
AddSIs [UnCI];
paulson@2499
   386
AddSEs [UnE];
paulson@1640
   387
clasohm@923
   388
nipkow@1548
   389
section "Binary intersection -- Int";
clasohm@923
   390
paulson@7031
   391
Goalw [Int_def] "(c : A Int B) = (c:A & c:B)";
paulson@7031
   392
by (Blast_tac 1);
paulson@7031
   393
qed "Int_iff";
paulson@2499
   394
Addsimps [Int_iff];
paulson@2499
   395
paulson@5143
   396
Goal "[| c:A;  c:B |] ==> c : A Int B";
paulson@2499
   397
by (Asm_simp_tac 1);
clasohm@923
   398
qed "IntI";
clasohm@923
   399
paulson@5143
   400
Goal "c : A Int B ==> c:A";
paulson@2499
   401
by (Asm_full_simp_tac 1);
clasohm@923
   402
qed "IntD1";
clasohm@923
   403
paulson@5143
   404
Goal "c : A Int B ==> c:B";
paulson@2499
   405
by (Asm_full_simp_tac 1);
clasohm@923
   406
qed "IntD2";
clasohm@923
   407
paulson@5316
   408
val [major,minor] = Goal
clasohm@923
   409
    "[| c : A Int B;  [| c:A; c:B |] ==> P |] ==> P";
clasohm@923
   410
by (rtac minor 1);
clasohm@923
   411
by (rtac (major RS IntD1) 1);
clasohm@923
   412
by (rtac (major RS IntD2) 1);
clasohm@923
   413
qed "IntE";
clasohm@923
   414
paulson@2499
   415
AddSIs [IntI];
paulson@2499
   416
AddSEs [IntE];
clasohm@923
   417
nipkow@1548
   418
section "Set difference";
clasohm@923
   419
paulson@7031
   420
Goalw [set_diff_def] "(c : A-B) = (c:A & c~:B)";
paulson@7031
   421
by (Blast_tac 1);
paulson@7031
   422
qed "Diff_iff";
paulson@2499
   423
Addsimps [Diff_iff];
paulson@2499
   424
paulson@7007
   425
Goal "[| c : A;  c ~: B |] ==> c : A - B";
paulson@7007
   426
by (Asm_simp_tac 1) ;
paulson@7007
   427
qed "DiffI";
clasohm@923
   428
paulson@7007
   429
Goal "c : A - B ==> c : A";
paulson@7007
   430
by (Asm_full_simp_tac 1) ;
paulson@7007
   431
qed "DiffD1";
clasohm@923
   432
paulson@7007
   433
Goal "[| c : A - B;  c : B |] ==> P";
paulson@7007
   434
by (Asm_full_simp_tac 1) ;
paulson@7007
   435
qed "DiffD2";
paulson@2499
   436
paulson@7031
   437
val prems = Goal "[| c : A - B;  [| c:A; c~:B |] ==> P |] ==> P";
paulson@7007
   438
by (resolve_tac prems 1);
paulson@7007
   439
by (REPEAT (ares_tac (prems RL [DiffD1, DiffD2 RS notI]) 1)) ;
paulson@7007
   440
qed "DiffE";
clasohm@923
   441
paulson@2499
   442
AddSIs [DiffI];
paulson@2499
   443
AddSEs [DiffE];
clasohm@923
   444
clasohm@923
   445
nipkow@1548
   446
section "Augmenting a set -- insert";
clasohm@923
   447
paulson@7031
   448
Goalw [insert_def] "a : insert b A = (a=b | a:A)";
paulson@7031
   449
by (Blast_tac 1);
paulson@7031
   450
qed "insert_iff";
paulson@2499
   451
Addsimps [insert_iff];
clasohm@923
   452
paulson@7031
   453
Goal "a : insert a B";
paulson@7007
   454
by (Simp_tac 1);
paulson@7007
   455
qed "insertI1";
clasohm@923
   456
paulson@7007
   457
Goal "!!a. a : B ==> a : insert b B";
paulson@7007
   458
by (Asm_simp_tac 1);
paulson@7007
   459
qed "insertI2";
paulson@7007
   460
paulson@7007
   461
val major::prems = Goalw [insert_def]
paulson@7007
   462
    "[| a : insert b A;  a=b ==> P;  a:A ==> P |] ==> P";
paulson@7007
   463
by (rtac (major RS UnE) 1);
paulson@7007
   464
by (REPEAT (eresolve_tac (prems @ [CollectE]) 1));
paulson@7007
   465
qed "insertE";
clasohm@923
   466
clasohm@923
   467
(*Classical introduction rule*)
paulson@7031
   468
val prems = Goal "(a~:B ==> a=b) ==> a: insert b B";
paulson@7007
   469
by (Simp_tac 1);
paulson@7007
   470
by (REPEAT (ares_tac (prems@[disjCI]) 1)) ;
paulson@7007
   471
qed "insertCI";
paulson@2499
   472
paulson@2499
   473
AddSIs [insertCI]; 
paulson@2499
   474
AddSEs [insertE];
clasohm@923
   475
paulson@9088
   476
Goal "(A <= insert x B) = (if x:A then A-{x} <= B else A<=B)";
paulson@9088
   477
by Auto_tac; 
paulson@9088
   478
qed "subset_insert_iff";
oheimb@7496
   479
nipkow@1548
   480
section "Singletons, using insert";
clasohm@923
   481
paulson@7007
   482
Goal "a : {a}";
paulson@7007
   483
by (rtac insertI1 1) ;
paulson@7007
   484
qed "singletonI";
clasohm@923
   485
paulson@5143
   486
Goal "b : {a} ==> b=a";
paulson@2891
   487
by (Blast_tac 1);
clasohm@923
   488
qed "singletonD";
clasohm@923
   489
oheimb@1776
   490
bind_thm ("singletonE", make_elim singletonD);
oheimb@1776
   491
paulson@7007
   492
Goal "(b : {a}) = (b=a)";
paulson@7007
   493
by (Blast_tac 1);
paulson@7007
   494
qed "singleton_iff";
clasohm@923
   495
paulson@5143
   496
Goal "{a}={b} ==> a=b";
wenzelm@4089
   497
by (blast_tac (claset() addEs [equalityE]) 1);
clasohm@923
   498
qed "singleton_inject";
clasohm@923
   499
paulson@2858
   500
(*Redundant? But unlike insertCI, it proves the subgoal immediately!*)
paulson@2858
   501
AddSIs [singletonI];   
paulson@2499
   502
AddSDs [singleton_inject];
paulson@3718
   503
AddSEs [singletonE];
paulson@2499
   504
oheimb@7969
   505
Goal "{b} = insert a A = (a = b & A <= {b})";
paulson@8326
   506
by (blast_tac (claset() addSEs [equalityE]) 1);
oheimb@7496
   507
qed "singleton_insert_inj_eq";
oheimb@7496
   508
paulson@8326
   509
Goal "(insert a A = {b}) = (a = b & A <= {b})";
paulson@8326
   510
by (blast_tac (claset() addSEs [equalityE]) 1);
oheimb@7969
   511
qed "singleton_insert_inj_eq'";
oheimb@7969
   512
paulson@8326
   513
AddIffs [singleton_insert_inj_eq, singleton_insert_inj_eq'];
paulson@8326
   514
oheimb@7496
   515
Goal "A <= {x} ==> A={} | A = {x}";
oheimb@7496
   516
by (Fast_tac 1);
oheimb@7496
   517
qed "subset_singletonD";
oheimb@7496
   518
wenzelm@5069
   519
Goal "{x. x=a} = {a}";
wenzelm@4423
   520
by (Blast_tac 1);
nipkow@3582
   521
qed "singleton_conv";
nipkow@3582
   522
Addsimps [singleton_conv];
nipkow@1531
   523
nipkow@5600
   524
Goal "{x. a=x} = {a}";
paulson@6301
   525
by (Blast_tac 1);
nipkow@5600
   526
qed "singleton_conv2";
nipkow@5600
   527
Addsimps [singleton_conv2];
nipkow@5600
   528
nipkow@1531
   529
nipkow@1548
   530
section "Unions of families -- UNION x:A. B(x) is Union(B``A)";
clasohm@923
   531
wenzelm@5069
   532
Goalw [UNION_def] "(b: (UN x:A. B(x))) = (EX x:A. b: B(x))";
paulson@2891
   533
by (Blast_tac 1);
paulson@2499
   534
qed "UN_iff";
paulson@2499
   535
paulson@2499
   536
Addsimps [UN_iff];
paulson@2499
   537
clasohm@923
   538
(*The order of the premises presupposes that A is rigid; b may be flexible*)
paulson@5143
   539
Goal "[| a:A;  b: B(a) |] ==> b: (UN x:A. B(x))";
paulson@4477
   540
by Auto_tac;
clasohm@923
   541
qed "UN_I";
clasohm@923
   542
paulson@5316
   543
val major::prems = Goalw [UNION_def]
clasohm@923
   544
    "[| b : (UN x:A. B(x));  !!x.[| x:A;  b: B(x) |] ==> R |] ==> R";
clasohm@923
   545
by (rtac (major RS CollectD RS bexE) 1);
clasohm@923
   546
by (REPEAT (ares_tac prems 1));
clasohm@923
   547
qed "UN_E";
clasohm@923
   548
paulson@2499
   549
AddIs  [UN_I];
paulson@2499
   550
AddSEs [UN_E];
paulson@2499
   551
paulson@6291
   552
val prems = Goalw [UNION_def]
clasohm@923
   553
    "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
clasohm@923
   554
\    (UN x:A. C(x)) = (UN x:B. D(x))";
paulson@6291
   555
by (asm_simp_tac (simpset() addsimps prems) 1);
clasohm@923
   556
qed "UN_cong";
clasohm@923
   557
clasohm@923
   558
nipkow@1548
   559
section "Intersections of families -- INTER x:A. B(x) is Inter(B``A)";
clasohm@923
   560
wenzelm@5069
   561
Goalw [INTER_def] "(b: (INT x:A. B(x))) = (ALL x:A. b: B(x))";
paulson@4477
   562
by Auto_tac;
paulson@2499
   563
qed "INT_iff";
paulson@2499
   564
paulson@2499
   565
Addsimps [INT_iff];
paulson@2499
   566
paulson@5316
   567
val prems = Goalw [INTER_def]
clasohm@923
   568
    "(!!x. x:A ==> b: B(x)) ==> b : (INT x:A. B(x))";
clasohm@923
   569
by (REPEAT (ares_tac ([CollectI,ballI] @ prems) 1));
clasohm@923
   570
qed "INT_I";
clasohm@923
   571
paulson@5143
   572
Goal "[| b : (INT x:A. B(x));  a:A |] ==> b: B(a)";
paulson@4477
   573
by Auto_tac;
clasohm@923
   574
qed "INT_D";
clasohm@923
   575
clasohm@923
   576
(*"Classical" elimination -- by the Excluded Middle on a:A *)
paulson@5316
   577
val major::prems = Goalw [INTER_def]
clasohm@923
   578
    "[| b : (INT x:A. B(x));  b: B(a) ==> R;  a~:A ==> R |] ==> R";
clasohm@923
   579
by (rtac (major RS CollectD RS ballE) 1);
clasohm@923
   580
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   581
qed "INT_E";
clasohm@923
   582
paulson@2499
   583
AddSIs [INT_I];
paulson@2499
   584
AddEs  [INT_D, INT_E];
paulson@2499
   585
paulson@6291
   586
val prems = Goalw [INTER_def]
clasohm@923
   587
    "[| A=B;  !!x. x:B ==> C(x) = D(x) |] ==> \
clasohm@923
   588
\    (INT x:A. C(x)) = (INT x:B. D(x))";
paulson@6291
   589
by (asm_simp_tac (simpset() addsimps prems) 1);
clasohm@923
   590
qed "INT_cong";
clasohm@923
   591
clasohm@923
   592
nipkow@1548
   593
section "Union";
clasohm@923
   594
wenzelm@5069
   595
Goalw [Union_def] "(A : Union(C)) = (EX X:C. A:X)";
paulson@2891
   596
by (Blast_tac 1);
paulson@2499
   597
qed "Union_iff";
paulson@2499
   598
paulson@2499
   599
Addsimps [Union_iff];
paulson@2499
   600
clasohm@923
   601
(*The order of the premises presupposes that C is rigid; A may be flexible*)
paulson@5143
   602
Goal "[| X:C;  A:X |] ==> A : Union(C)";
paulson@4477
   603
by Auto_tac;
clasohm@923
   604
qed "UnionI";
clasohm@923
   605
paulson@5316
   606
val major::prems = Goalw [Union_def]
clasohm@923
   607
    "[| A : Union(C);  !!X.[| A:X;  X:C |] ==> R |] ==> R";
clasohm@923
   608
by (rtac (major RS UN_E) 1);
clasohm@923
   609
by (REPEAT (ares_tac prems 1));
clasohm@923
   610
qed "UnionE";
clasohm@923
   611
paulson@2499
   612
AddIs  [UnionI];
paulson@2499
   613
AddSEs [UnionE];
paulson@2499
   614
paulson@2499
   615
nipkow@1548
   616
section "Inter";
clasohm@923
   617
wenzelm@5069
   618
Goalw [Inter_def] "(A : Inter(C)) = (ALL X:C. A:X)";
paulson@2891
   619
by (Blast_tac 1);
paulson@2499
   620
qed "Inter_iff";
paulson@2499
   621
paulson@2499
   622
Addsimps [Inter_iff];
paulson@2499
   623
paulson@5316
   624
val prems = Goalw [Inter_def]
clasohm@923
   625
    "[| !!X. X:C ==> A:X |] ==> A : Inter(C)";
clasohm@923
   626
by (REPEAT (ares_tac ([INT_I] @ prems) 1));
clasohm@923
   627
qed "InterI";
clasohm@923
   628
clasohm@923
   629
(*A "destruct" rule -- every X in C contains A as an element, but
clasohm@923
   630
  A:X can hold when X:C does not!  This rule is analogous to "spec". *)
paulson@5143
   631
Goal "[| A : Inter(C);  X:C |] ==> A:X";
paulson@4477
   632
by Auto_tac;
clasohm@923
   633
qed "InterD";
clasohm@923
   634
clasohm@923
   635
(*"Classical" elimination rule -- does not require proving X:C *)
paulson@5316
   636
val major::prems = Goalw [Inter_def]
paulson@2721
   637
    "[| A : Inter(C);  X~:C ==> R;  A:X ==> R |] ==> R";
clasohm@923
   638
by (rtac (major RS INT_E) 1);
clasohm@923
   639
by (REPEAT (eresolve_tac prems 1));
clasohm@923
   640
qed "InterE";
clasohm@923
   641
paulson@2499
   642
AddSIs [InterI];
paulson@2499
   643
AddEs  [InterD, InterE];
paulson@2499
   644
paulson@2499
   645
nipkow@2912
   646
(*** Image of a set under a function ***)
nipkow@2912
   647
nipkow@2912
   648
(*Frequently b does not have the syntactic form of f(x).*)
paulson@5316
   649
Goalw [image_def] "[| b=f(x);  x:A |] ==> b : f``A";
paulson@5316
   650
by (Blast_tac 1);
nipkow@2912
   651
qed "image_eqI";
nipkow@3909
   652
Addsimps [image_eqI];
nipkow@2912
   653
nipkow@2912
   654
bind_thm ("imageI", refl RS image_eqI);
nipkow@2912
   655
paulson@8025
   656
(*This version's more effective when we already have the required x*)
paulson@8025
   657
Goalw [image_def] "[| x:A;  b=f(x) |] ==> b : f``A";
paulson@8025
   658
by (Blast_tac 1);
paulson@8025
   659
qed "rev_image_eqI";
paulson@8025
   660
nipkow@2912
   661
(*The eta-expansion gives variable-name preservation.*)
paulson@5316
   662
val major::prems = Goalw [image_def]
wenzelm@3842
   663
    "[| b : (%x. f(x))``A;  !!x.[| b=f(x);  x:A |] ==> P |] ==> P"; 
nipkow@2912
   664
by (rtac (major RS CollectD RS bexE) 1);
nipkow@2912
   665
by (REPEAT (ares_tac prems 1));
nipkow@2912
   666
qed "imageE";
nipkow@2912
   667
nipkow@2912
   668
AddIs  [image_eqI];
nipkow@2912
   669
AddSEs [imageE]; 
nipkow@2912
   670
wenzelm@5069
   671
Goal "f``(A Un B) = f``A Un f``B";
paulson@2935
   672
by (Blast_tac 1);
nipkow@2912
   673
qed "image_Un";
nipkow@2912
   674
wenzelm@5069
   675
Goal "(z : f``A) = (EX x:A. z = f x)";
paulson@3960
   676
by (Blast_tac 1);
paulson@3960
   677
qed "image_iff";
paulson@3960
   678
paulson@4523
   679
(*This rewrite rule would confuse users if made default.*)
wenzelm@5069
   680
Goal "(f``A <= B) = (ALL x:A. f(x): B)";
paulson@4523
   681
by (Blast_tac 1);
paulson@4523
   682
qed "image_subset_iff";
paulson@4523
   683
paulson@4523
   684
(*Replaces the three steps subsetI, imageE, hyp_subst_tac, but breaks too
paulson@4523
   685
  many existing proofs.*)
paulson@5316
   686
val prems = Goal "(!!x. x:A ==> f(x) : B) ==> f``A <= B";
paulson@4510
   687
by (blast_tac (claset() addIs prems) 1);
paulson@4510
   688
qed "image_subsetI";
paulson@4510
   689
nipkow@2912
   690
nipkow@2912
   691
(*** Range of a function -- just a translation for image! ***)
nipkow@2912
   692
paulson@5143
   693
Goal "b=f(x) ==> b : range(f)";
nipkow@2912
   694
by (EVERY1 [etac image_eqI, rtac UNIV_I]);
nipkow@2912
   695
bind_thm ("range_eqI", UNIV_I RSN (2,image_eqI));
nipkow@2912
   696
nipkow@2912
   697
bind_thm ("rangeI", UNIV_I RS imageI);
nipkow@2912
   698
paulson@5316
   699
val [major,minor] = Goal 
wenzelm@3842
   700
    "[| b : range(%x. f(x));  !!x. b=f(x) ==> P |] ==> P"; 
nipkow@2912
   701
by (rtac (major RS imageE) 1);
nipkow@2912
   702
by (etac minor 1);
nipkow@2912
   703
qed "rangeE";
nipkow@2912
   704
oheimb@1776
   705
oheimb@1776
   706
(*** Set reasoning tools ***)
oheimb@1776
   707
oheimb@1776
   708
paulson@3912
   709
(** Rewrite rules for boolean case-splitting: faster than 
nipkow@4830
   710
	addsplits[split_if]
paulson@3912
   711
**)
paulson@3912
   712
nipkow@4830
   713
bind_thm ("split_if_eq1", read_instantiate [("P", "%x. x = ?b")] split_if);
nipkow@4830
   714
bind_thm ("split_if_eq2", read_instantiate [("P", "%x. ?a = x")] split_if);
paulson@3912
   715
paulson@5237
   716
(*Split ifs on either side of the membership relation.
paulson@5237
   717
	Not for Addsimps -- can cause goals to blow up!*)
nipkow@4830
   718
bind_thm ("split_if_mem1", 
wenzelm@6394
   719
    read_instantiate_sg (Theory.sign_of Set.thy) [("P", "%x. x : ?b")] split_if);
nipkow@4830
   720
bind_thm ("split_if_mem2", 
wenzelm@6394
   721
    read_instantiate_sg (Theory.sign_of Set.thy) [("P", "%x. ?a : x")] split_if);
paulson@3912
   722
wenzelm@9108
   723
bind_thms ("split_ifs", [if_bool_eq_conj, split_if_eq1, split_if_eq2,
wenzelm@9108
   724
		  split_if_mem1, split_if_mem2]);
paulson@3912
   725
paulson@3912
   726
wenzelm@4089
   727
(*Each of these has ALREADY been added to simpset() above.*)
wenzelm@9108
   728
bind_thms ("mem_simps", [insert_iff, empty_iff, Un_iff, Int_iff, Compl_iff, Diff_iff, 
wenzelm@9108
   729
                 mem_Collect_eq, UN_iff, Union_iff, INT_iff, Inter_iff]);
oheimb@1776
   730
paulson@9041
   731
(*Would like to add these, but the existing code only searches for the 
paulson@9041
   732
  outer-level constant, which in this case is just "op :"; we instead need
paulson@9041
   733
  to use term-nets to associate patterns with rules.  Also, if a rule fails to
paulson@9041
   734
  apply, then the formula should be kept.
paulson@9041
   735
  [("uminus", Compl_iff RS iffD1), ("op -", [Diff_iff RS iffD1]), 
paulson@9041
   736
   ("op Int", [IntD1,IntD2]),
paulson@9041
   737
   ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])]
paulson@9041
   738
 *)
paulson@9041
   739
val mksimps_pairs =
paulson@9041
   740
  [("Ball",[bspec])] @ mksimps_pairs;
oheimb@1776
   741
paulson@6291
   742
simpset_ref() := simpset() setmksimps (mksimps mksimps_pairs);
nipkow@3222
   743
paulson@5256
   744
Addsimps[subset_UNIV, subset_refl];
nipkow@3222
   745
nipkow@3222
   746
paulson@8001
   747
(*** The 'proper subset' relation (<) ***)
nipkow@3222
   748
wenzelm@5069
   749
Goalw [psubset_def] "!!A::'a set. [| A <= B; A ~= B |] ==> A<B";
nipkow@3222
   750
by (Blast_tac 1);
nipkow@3222
   751
qed "psubsetI";
paulson@8913
   752
AddSIs [psubsetI];
nipkow@3222
   753
paulson@9088
   754
Goalw [psubset_def]
paulson@9088
   755
  "(A < insert x B) = (if x:B then A<B else if x:A then A-{x} < B else A<=B)";
paulson@9088
   756
by (asm_simp_tac (simpset() addsimps [subset_insert_iff]) 1);
paulson@9088
   757
by (Blast_tac 1); 
paulson@9088
   758
qed "psubset_insert_iff";
paulson@4059
   759
paulson@4059
   760
bind_thm ("psubset_eq", psubset_def RS meta_eq_to_obj_eq);
wenzelm@6443
   761
wenzelm@6443
   762
bind_thm ("psubset_imp_subset", psubset_eq RS iffD1 RS conjunct1);
wenzelm@6443
   763
wenzelm@6443
   764
Goal"[| (A::'a set) < B; B <= C |] ==> A < C";
wenzelm@6443
   765
by (auto_tac (claset(), simpset() addsimps [psubset_eq]));
wenzelm@6443
   766
qed "psubset_subset_trans";
wenzelm@6443
   767
wenzelm@6443
   768
Goal"[| (A::'a set) <= B; B < C|] ==> A < C";
wenzelm@6443
   769
by (auto_tac (claset(), simpset() addsimps [psubset_eq]));
wenzelm@6443
   770
qed "subset_psubset_trans";
berghofe@7717
   771
paulson@8001
   772
Goalw [psubset_def] "A < B ==> EX b. b : (B - A)";
paulson@8001
   773
by (Blast_tac 1);
paulson@8001
   774
qed "psubset_imp_ex_mem";
paulson@8001
   775
berghofe@7717
   776
berghofe@7717
   777
(* attributes *)
berghofe@7717
   778
berghofe@7717
   779
local
berghofe@7717
   780
berghofe@7717
   781
fun gen_rulify_prems x =
berghofe@7717
   782
  Attrib.no_args (Drule.rule_attribute (fn _ => (standard o
berghofe@7717
   783
    rule_by_tactic (REPEAT (ALLGOALS (resolve_tac [allI, ballI, impI])))))) x;
berghofe@7717
   784
berghofe@7717
   785
in
berghofe@7717
   786
berghofe@7717
   787
val rulify_prems_attrib_setup =
berghofe@7717
   788
 [Attrib.add_attributes
berghofe@7717
   789
  [("rulify_prems", (gen_rulify_prems, gen_rulify_prems), "put theorem into standard rule form")]];
berghofe@7717
   790
berghofe@7717
   791
end;