src/HOL/Finite.ML
author paulson
Thu Aug 13 18:14:26 1998 +0200 (1998-08-13)
changeset 5316 7a8975451a89
parent 5278 a903b66822e2
child 5413 9d11f2d39b13
permissions -rw-r--r--
even more tidying of Goal commands
clasohm@1465
     1
(*  Title:      HOL/Finite.thy
clasohm@923
     2
    ID:         $Id$
nipkow@1531
     3
    Author:     Lawrence C Paulson & Tobias Nipkow
nipkow@1531
     4
    Copyright   1995  University of Cambridge & TU Muenchen
clasohm@923
     5
nipkow@1531
     6
Finite sets and their cardinality
clasohm@923
     7
*)
clasohm@923
     8
clasohm@923
     9
open Finite;
clasohm@923
    10
nipkow@3413
    11
section "finite";
nipkow@1531
    12
clasohm@923
    13
(*Discharging ~ x:y entails extra work*)
paulson@5316
    14
val major::prems = Goal 
nipkow@3413
    15
    "[| finite F;  P({}); \
nipkow@3413
    16
\       !!F x. [| finite F;  x ~: F;  P(F) |] ==> P(insert x F) \
clasohm@923
    17
\    |] ==> P(F)";
nipkow@3413
    18
by (rtac (major RS Finites.induct) 1);
nipkow@3413
    19
by (excluded_middle_tac "a:A" 2);
clasohm@923
    20
by (etac (insert_absorb RS ssubst) 3 THEN assume_tac 3);   (*backtracking!*)
clasohm@923
    21
by (REPEAT (ares_tac prems 1));
nipkow@3413
    22
qed "finite_induct";
nipkow@3413
    23
paulson@5316
    24
val major::subs::prems = Goal 
nipkow@3413
    25
    "[| finite F;  F <= A; \
nipkow@3413
    26
\       P({}); \
nipkow@3413
    27
\       !!F a. [| finite F; a:A; a ~: F;  P(F) |] ==> P(insert a F) \
nipkow@3413
    28
\    |] ==> P(F)";
paulson@4386
    29
by (rtac (subs RS rev_mp) 1);
paulson@4386
    30
by (rtac (major RS finite_induct) 1);
paulson@4386
    31
by (ALLGOALS (blast_tac (claset() addIs prems)));
nipkow@3413
    32
qed "finite_subset_induct";
nipkow@3413
    33
nipkow@3413
    34
Addsimps Finites.intrs;
nipkow@3413
    35
AddSIs Finites.intrs;
clasohm@923
    36
clasohm@923
    37
(*The union of two finite sets is finite*)
paulson@5316
    38
Goal "[| finite F;  finite G |] ==> finite(F Un G)";
paulson@5316
    39
by (etac finite_induct 1);
paulson@5316
    40
by (ALLGOALS Asm_simp_tac);
nipkow@3413
    41
qed "finite_UnI";
clasohm@923
    42
clasohm@923
    43
(*Every subset of a finite set is finite*)
paulson@5143
    44
Goal "finite B ==> ALL A. A<=B --> finite A";
paulson@4304
    45
by (etac finite_induct 1);
paulson@4304
    46
by (Simp_tac 1);
wenzelm@4089
    47
by (safe_tac (claset() addSDs [subset_insert_iff RS iffD1]));
paulson@4304
    48
by (eres_inst_tac [("t","A")] (insert_Diff RS subst) 2);
clasohm@1264
    49
by (ALLGOALS Asm_simp_tac);
paulson@4304
    50
val lemma = result();
paulson@4304
    51
paulson@5143
    52
Goal "[| A<=B;  finite B |] ==> finite A";
wenzelm@4423
    53
by (dtac lemma 1);
paulson@4304
    54
by (Blast_tac 1);
nipkow@3413
    55
qed "finite_subset";
clasohm@923
    56
wenzelm@5069
    57
Goal "finite(F Un G) = (finite F & finite G)";
paulson@4304
    58
by (blast_tac (claset() 
paulson@4304
    59
	         addIs [read_instantiate [("B", "?AA Un ?BB")] finite_subset, 
paulson@4304
    60
			finite_UnI]) 1);
nipkow@3413
    61
qed "finite_Un";
nipkow@3413
    62
AddIffs[finite_Un];
nipkow@1531
    63
wenzelm@5069
    64
Goal "finite(insert a A) = finite A";
paulson@1553
    65
by (stac insert_is_Un 1);
nipkow@3413
    66
by (simp_tac (HOL_ss addsimps [finite_Un]) 1);
paulson@3427
    67
by (Blast_tac 1);
nipkow@3413
    68
qed "finite_insert";
nipkow@3413
    69
Addsimps[finite_insert];
nipkow@1531
    70
nipkow@3413
    71
(*The image of a finite set is finite *)
paulson@5143
    72
Goal  "finite F ==> finite(h``F)";
nipkow@3413
    73
by (etac finite_induct 1);
clasohm@1264
    74
by (Simp_tac 1);
nipkow@3413
    75
by (Asm_simp_tac 1);
nipkow@3413
    76
qed "finite_imageI";
clasohm@923
    77
paulson@5316
    78
val major::prems = Goal 
nipkow@3413
    79
    "[| finite c;  finite b;                                  \
clasohm@1465
    80
\       P(b);                                                   \
nipkow@3413
    81
\       !!x y. [| finite y;  x:y;  P(y) |] ==> P(y-{x}) \
clasohm@923
    82
\    |] ==> c<=b --> P(b-c)";
nipkow@3413
    83
by (rtac (major RS finite_induct) 1);
paulson@2031
    84
by (stac Diff_insert 2);
clasohm@923
    85
by (ALLGOALS (asm_simp_tac
wenzelm@4089
    86
                (simpset() addsimps (prems@[Diff_subset RS finite_subset]))));
nipkow@1531
    87
val lemma = result();
clasohm@923
    88
paulson@5316
    89
val prems = Goal 
nipkow@3413
    90
    "[| finite A;                                       \
nipkow@3413
    91
\       P(A);                                           \
nipkow@3413
    92
\       !!a A. [| finite A;  a:A;  P(A) |] ==> P(A-{a}) \
clasohm@923
    93
\    |] ==> P({})";
clasohm@923
    94
by (rtac (Diff_cancel RS subst) 1);
nipkow@1531
    95
by (rtac (lemma RS mp) 1);
clasohm@923
    96
by (REPEAT (ares_tac (subset_refl::prems) 1));
nipkow@3413
    97
qed "finite_empty_induct";
nipkow@1531
    98
nipkow@1531
    99
paulson@1618
   100
(* finite B ==> finite (B - Ba) *)
paulson@1618
   101
bind_thm ("finite_Diff", Diff_subset RS finite_subset);
nipkow@1531
   102
Addsimps [finite_Diff];
nipkow@1531
   103
wenzelm@5069
   104
Goal "finite(A-{a}) = finite(A)";
paulson@3368
   105
by (case_tac "a:A" 1);
paulson@3457
   106
by (rtac (finite_insert RS sym RS trans) 1);
paulson@3368
   107
by (stac insert_Diff 1);
paulson@3368
   108
by (ALLGOALS Asm_simp_tac);
paulson@3368
   109
qed "finite_Diff_singleton";
paulson@3368
   110
AddIffs [finite_Diff_singleton];
paulson@3368
   111
paulson@4059
   112
(*Lemma for proving finite_imageD*)
paulson@5143
   113
Goal "finite B ==> !A. f``A = B --> inj_on f A --> finite A";
paulson@1553
   114
by (etac finite_induct 1);
nipkow@3413
   115
 by (ALLGOALS Asm_simp_tac);
paulson@3708
   116
by (Clarify_tac 1);
nipkow@3413
   117
by (subgoal_tac "EX y:A. f y = x & F = f``(A-{y})" 1);
paulson@3708
   118
 by (Clarify_tac 1);
nipkow@4830
   119
 by (full_simp_tac (simpset() addsimps [inj_on_def]) 1);
nipkow@3413
   120
 by (Blast_tac 1);
paulson@3368
   121
by (thin_tac "ALL A. ?PP(A)" 1);
nipkow@3413
   122
by (forward_tac [[equalityD2, insertI1] MRS subsetD] 1);
paulson@3708
   123
by (Clarify_tac 1);
paulson@3368
   124
by (res_inst_tac [("x","xa")] bexI 1);
paulson@4059
   125
by (ALLGOALS 
nipkow@4830
   126
    (asm_full_simp_tac (simpset() addsimps [inj_on_image_set_diff])));
paulson@3368
   127
val lemma = result();
paulson@3368
   128
paulson@5143
   129
Goal "[| finite(f``A);  inj_on f A |] ==> finite A";
paulson@3457
   130
by (dtac lemma 1);
paulson@3368
   131
by (Blast_tac 1);
paulson@3368
   132
qed "finite_imageD";
paulson@3368
   133
nipkow@4014
   134
(** The finite UNION of finite sets **)
nipkow@4014
   135
paulson@5316
   136
Goal "finite A ==> (!a:A. finite(B a)) --> finite(UN a:A. B a)";
paulson@5316
   137
by (etac finite_induct 1);
paulson@4153
   138
by (ALLGOALS Asm_simp_tac);
nipkow@4014
   139
bind_thm("finite_UnionI", ballI RSN (2, result() RS mp));
nipkow@4014
   140
Addsimps [finite_UnionI];
nipkow@4014
   141
nipkow@4014
   142
(** Sigma of finite sets **)
nipkow@4014
   143
wenzelm@5069
   144
Goalw [Sigma_def]
paulson@5148
   145
 "[| finite A; !a:A. finite(B a) |] ==> finite(SIGMA a:A. B a)";
paulson@4153
   146
by (blast_tac (claset() addSIs [finite_UnionI]) 1);
nipkow@4014
   147
bind_thm("finite_SigmaI", ballI RSN (2,result()));
nipkow@4014
   148
Addsimps [finite_SigmaI];
paulson@3368
   149
paulson@3368
   150
(** The powerset of a finite set **)
paulson@3368
   151
paulson@5143
   152
Goal "finite(Pow A) ==> finite A";
paulson@3368
   153
by (subgoal_tac "finite ((%x.{x})``A)" 1);
paulson@3457
   154
by (rtac finite_subset 2);
paulson@3457
   155
by (assume_tac 3);
paulson@3368
   156
by (ALLGOALS
nipkow@4830
   157
    (fast_tac (claset() addSDs [rewrite_rule [inj_on_def] finite_imageD])));
paulson@3368
   158
val lemma = result();
paulson@3368
   159
wenzelm@5069
   160
Goal "finite(Pow A) = finite A";
paulson@3457
   161
by (rtac iffI 1);
paulson@3457
   162
by (etac lemma 1);
paulson@3368
   163
(*Opposite inclusion: finite A ==> finite (Pow A) *)
paulson@3340
   164
by (etac finite_induct 1);
paulson@3340
   165
by (ALLGOALS 
paulson@3340
   166
    (asm_simp_tac
wenzelm@4089
   167
     (simpset() addsimps [finite_UnI, finite_imageI, Pow_insert])));
paulson@3368
   168
qed "finite_Pow_iff";
paulson@3368
   169
AddIffs [finite_Pow_iff];
paulson@3340
   170
wenzelm@5069
   171
Goal "finite(r^-1) = finite r";
paulson@3457
   172
by (subgoal_tac "r^-1 = (%(x,y).(y,x))``r" 1);
paulson@3457
   173
 by (Asm_simp_tac 1);
paulson@3457
   174
 by (rtac iffI 1);
nipkow@4830
   175
  by (etac (rewrite_rule [inj_on_def] finite_imageD) 1);
nipkow@4830
   176
  by (simp_tac (simpset() addsplits [split_split]) 1);
paulson@3457
   177
 by (etac finite_imageI 1);
paulson@4746
   178
by (simp_tac (simpset() addsimps [converse_def,image_def]) 1);
paulson@4477
   179
by Auto_tac;
paulson@3457
   180
 by (rtac bexI 1);
paulson@3457
   181
 by (assume_tac 2);
oheimb@4763
   182
by (Simp_tac 1);
paulson@4746
   183
qed "finite_converse";
paulson@4746
   184
AddIffs [finite_converse];
nipkow@1531
   185
nipkow@1548
   186
section "Finite cardinality -- 'card'";
nipkow@1531
   187
paulson@5316
   188
Goal "{f i |i. (P i | i=n)} = insert (f n) {f i|i. P i}";
paulson@2922
   189
by (Blast_tac 1);
nipkow@1531
   190
val Collect_conv_insert = result();
nipkow@1531
   191
wenzelm@5069
   192
Goalw [card_def] "card {} = 0";
paulson@1553
   193
by (rtac Least_equality 1);
paulson@1553
   194
by (ALLGOALS Asm_full_simp_tac);
nipkow@1531
   195
qed "card_empty";
nipkow@1531
   196
Addsimps [card_empty];
nipkow@1531
   197
paulson@5316
   198
Goal "finite A ==> ? (n::nat) f. A = {f i |i. i<n}";
paulson@5316
   199
by (etac finite_induct 1);
paulson@1553
   200
 by (res_inst_tac [("x","0")] exI 1);
paulson@1553
   201
 by (Simp_tac 1);
paulson@1553
   202
by (etac exE 1);
paulson@1553
   203
by (etac exE 1);
paulson@1553
   204
by (hyp_subst_tac 1);
paulson@1553
   205
by (res_inst_tac [("x","Suc n")] exI 1);
paulson@1553
   206
by (res_inst_tac [("x","%i. if i<n then f i else x")] exI 1);
wenzelm@4089
   207
by (asm_simp_tac (simpset() addsimps [Collect_conv_insert, less_Suc_eq]
nipkow@1548
   208
                          addcongs [rev_conj_cong]) 1);
nipkow@1531
   209
qed "finite_has_card";
nipkow@1531
   210
paulson@5278
   211
Goal "[| x ~: A; insert x A = {f i|i. i<n} |]  \
paulson@5278
   212
\     ==> ? m::nat. m<n & (? g. A = {g i|i. i<m})";
berghofe@5183
   213
by (exhaust_tac "n" 1);
paulson@1553
   214
 by (hyp_subst_tac 1);
paulson@1553
   215
 by (Asm_full_simp_tac 1);
paulson@1553
   216
by (rename_tac "m" 1);
paulson@1553
   217
by (hyp_subst_tac 1);
paulson@1553
   218
by (case_tac "? a. a:A" 1);
paulson@1553
   219
 by (res_inst_tac [("x","0")] exI 2);
paulson@1553
   220
 by (Simp_tac 2);
paulson@2922
   221
 by (Blast_tac 2);
paulson@1553
   222
by (etac exE 1);
wenzelm@4089
   223
by (simp_tac (simpset() addsimps [less_Suc_eq]) 1);
paulson@1553
   224
by (rtac exI 1);
paulson@1782
   225
by (rtac (refl RS disjI2 RS conjI) 1);
paulson@1553
   226
by (etac equalityE 1);
paulson@1553
   227
by (asm_full_simp_tac
wenzelm@4089
   228
     (simpset() addsimps [subset_insert,Collect_conv_insert, less_Suc_eq]) 1);
paulson@4153
   229
by Safe_tac;
paulson@1553
   230
  by (Asm_full_simp_tac 1);
paulson@1553
   231
  by (res_inst_tac [("x","%i. if f i = f m then a else f i")] exI 1);
paulson@4153
   232
  by (SELECT_GOAL Safe_tac 1);
paulson@1553
   233
   by (subgoal_tac "x ~= f m" 1);
paulson@2922
   234
    by (Blast_tac 2);
paulson@1553
   235
   by (subgoal_tac "? k. f k = x & k<m" 1);
paulson@2922
   236
    by (Blast_tac 2);
paulson@4153
   237
   by (SELECT_GOAL Safe_tac 1);
paulson@1553
   238
   by (res_inst_tac [("x","k")] exI 1);
paulson@1553
   239
   by (Asm_simp_tac 1);
nipkow@4686
   240
  by (Simp_tac 1);
paulson@2922
   241
  by (Blast_tac 1);
paulson@3457
   242
 by (dtac sym 1);
paulson@1553
   243
 by (rotate_tac ~1 1);
paulson@1553
   244
 by (Asm_full_simp_tac 1);
paulson@1553
   245
 by (res_inst_tac [("x","%i. if f i = f m then a else f i")] exI 1);
paulson@4153
   246
 by (SELECT_GOAL Safe_tac 1);
paulson@1553
   247
  by (subgoal_tac "x ~= f m" 1);
paulson@2922
   248
   by (Blast_tac 2);
paulson@1553
   249
  by (subgoal_tac "? k. f k = x & k<m" 1);
paulson@2922
   250
   by (Blast_tac 2);
paulson@4153
   251
  by (SELECT_GOAL Safe_tac 1);
paulson@1553
   252
  by (res_inst_tac [("x","k")] exI 1);
paulson@1553
   253
  by (Asm_simp_tac 1);
nipkow@4686
   254
 by (Simp_tac 1);
paulson@2922
   255
 by (Blast_tac 1);
paulson@1553
   256
by (res_inst_tac [("x","%j. if f j = f i then f m else f j")] exI 1);
paulson@4153
   257
by (SELECT_GOAL Safe_tac 1);
paulson@1553
   258
 by (subgoal_tac "x ~= f i" 1);
paulson@2922
   259
  by (Blast_tac 2);
paulson@1553
   260
 by (case_tac "x = f m" 1);
paulson@1553
   261
  by (res_inst_tac [("x","i")] exI 1);
paulson@1553
   262
  by (Asm_simp_tac 1);
paulson@1553
   263
 by (subgoal_tac "? k. f k = x & k<m" 1);
paulson@2922
   264
  by (Blast_tac 2);
paulson@4153
   265
 by (SELECT_GOAL Safe_tac 1);
paulson@1553
   266
 by (res_inst_tac [("x","k")] exI 1);
paulson@1553
   267
 by (Asm_simp_tac 1);
nipkow@4686
   268
by (Simp_tac 1);
paulson@2922
   269
by (Blast_tac 1);
nipkow@1531
   270
val lemma = result();
nipkow@1531
   271
paulson@5143
   272
Goal "[| finite A; x ~: A |] ==> \
wenzelm@3842
   273
\ (LEAST n. ? f. insert x A = {f i|i. i<n}) = Suc(LEAST n. ? f. A={f i|i. i<n})";
paulson@1553
   274
by (rtac Least_equality 1);
paulson@3457
   275
 by (dtac finite_has_card 1);
paulson@3457
   276
 by (etac exE 1);
wenzelm@3842
   277
 by (dres_inst_tac [("P","%n.? f. A={f i|i. i<n}")] LeastI 1);
paulson@3457
   278
 by (etac exE 1);
paulson@1553
   279
 by (res_inst_tac
nipkow@1531
   280
   [("x","%i. if i<(LEAST n. ? f. A={f i |i. i < n}) then f i else x")] exI 1);
paulson@1553
   281
 by (simp_tac
wenzelm@4089
   282
    (simpset() addsimps [Collect_conv_insert, less_Suc_eq] 
paulson@2031
   283
              addcongs [rev_conj_cong]) 1);
paulson@3457
   284
 by (etac subst 1);
paulson@3457
   285
 by (rtac refl 1);
paulson@1553
   286
by (rtac notI 1);
paulson@1553
   287
by (etac exE 1);
paulson@1553
   288
by (dtac lemma 1);
paulson@3457
   289
 by (assume_tac 1);
paulson@1553
   290
by (etac exE 1);
paulson@1553
   291
by (etac conjE 1);
paulson@1553
   292
by (dres_inst_tac [("P","%x. ? g. A = {g i |i. i < x}")] Least_le 1);
paulson@1553
   293
by (dtac le_less_trans 1 THEN atac 1);
wenzelm@4089
   294
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1);
paulson@1553
   295
by (etac disjE 1);
paulson@1553
   296
by (etac less_asym 1 THEN atac 1);
paulson@1553
   297
by (hyp_subst_tac 1);
paulson@1553
   298
by (Asm_full_simp_tac 1);
nipkow@1531
   299
val lemma = result();
nipkow@1531
   300
wenzelm@5069
   301
Goalw [card_def]
paulson@5148
   302
  "[| finite A; x ~: A |] ==> card(insert x A) = Suc(card A)";
paulson@1553
   303
by (etac lemma 1);
paulson@1553
   304
by (assume_tac 1);
nipkow@1531
   305
qed "card_insert_disjoint";
paulson@3352
   306
Addsimps [card_insert_disjoint];
paulson@3352
   307
paulson@5143
   308
Goal "finite A ==> card A <= card (insert x A)";
paulson@4768
   309
by (case_tac "x: A" 1);
paulson@4768
   310
by (ALLGOALS (asm_simp_tac (simpset() addsimps [insert_absorb])));
paulson@4768
   311
qed "card_insert_le";
paulson@4768
   312
paulson@5143
   313
Goal  "finite A ==> !B. B <= A --> card(B) <= card(A)";
paulson@3352
   314
by (etac finite_induct 1);
paulson@3352
   315
by (Simp_tac 1);
paulson@3708
   316
by (Clarify_tac 1);
paulson@3352
   317
by (case_tac "x:B" 1);
nipkow@3413
   318
 by (dres_inst_tac [("A","B")] mk_disjoint_insert 1);
paulson@4775
   319
by (asm_full_simp_tac (simpset() addsimps [subset_insert_iff]) 2);
paulson@4775
   320
by (fast_tac (claset() addss
paulson@4775
   321
	      (simpset() addsimps [subset_insert_iff, finite_subset])) 1);
paulson@3352
   322
qed_spec_mp "card_mono";
paulson@3352
   323
paulson@5143
   324
Goal "[| finite A; finite B |]\
paulson@3352
   325
\                       ==> A Int B = {} --> card(A Un B) = card A + card B";
paulson@3352
   326
by (etac finite_induct 1);
nipkow@4686
   327
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Int_insert_left])));
paulson@3352
   328
qed_spec_mp "card_Un_disjoint";
paulson@3352
   329
paulson@5143
   330
Goal "[| finite A; B<=A |] ==> card A - card B = card (A - B)";
paulson@3352
   331
by (subgoal_tac "(A-B) Un B = A" 1);
paulson@3352
   332
by (Blast_tac 2);
paulson@3457
   333
by (rtac (add_right_cancel RS iffD1) 1);
paulson@3457
   334
by (rtac (card_Un_disjoint RS subst) 1);
paulson@3457
   335
by (etac ssubst 4);
paulson@3352
   336
by (Blast_tac 3);
paulson@3352
   337
by (ALLGOALS 
paulson@3352
   338
    (asm_simp_tac
wenzelm@4089
   339
     (simpset() addsimps [add_commute, not_less_iff_le, 
paulson@3352
   340
			 add_diff_inverse, card_mono, finite_subset])));
paulson@3352
   341
qed "card_Diff_subset";
nipkow@1531
   342
paulson@5143
   343
Goal "[| finite A; x: A |] ==> Suc(card(A-{x})) = card A";
paulson@1618
   344
by (res_inst_tac [("t", "A")] (insert_Diff RS subst) 1);
paulson@1618
   345
by (assume_tac 1);
paulson@3352
   346
by (Asm_simp_tac 1);
paulson@1618
   347
qed "card_Suc_Diff";
paulson@1618
   348
paulson@5143
   349
Goal "[| finite A; x: A |] ==> card(A-{x}) < card A";
paulson@2031
   350
by (rtac Suc_less_SucD 1);
wenzelm@4089
   351
by (asm_simp_tac (simpset() addsimps [card_Suc_Diff]) 1);
paulson@1618
   352
qed "card_Diff";
paulson@1618
   353
paulson@5143
   354
Goal "finite A ==> card(A-{x}) <= card A";
paulson@4768
   355
by (case_tac "x: A" 1);
paulson@4768
   356
by (ALLGOALS (asm_simp_tac (simpset() addsimps [card_Diff, less_imp_le])));
paulson@4768
   357
qed "card_Diff_le";
paulson@4768
   358
paulson@3389
   359
paulson@3389
   360
(*** Cardinality of the Powerset ***)
paulson@3389
   361
paulson@5143
   362
Goal "finite A ==> card(insert x A) = Suc(card(A-{x}))";
paulson@1553
   363
by (case_tac "x:A" 1);
paulson@4768
   364
by (ALLGOALS 
paulson@4768
   365
    (asm_simp_tac (simpset() addsimps [card_Suc_Diff, insert_absorb])));
nipkow@1531
   366
qed "card_insert";
nipkow@1531
   367
Addsimps [card_insert];
nipkow@1531
   368
paulson@5143
   369
Goal "finite(A) ==> inj_on f A --> card (f `` A) = card A";
paulson@3340
   370
by (etac finite_induct 1);
paulson@3340
   371
by (ALLGOALS Asm_simp_tac);
paulson@3724
   372
by Safe_tac;
nipkow@4830
   373
by (rewtac inj_on_def);
paulson@3340
   374
by (Blast_tac 1);
paulson@3340
   375
by (stac card_insert_disjoint 1);
paulson@3340
   376
by (etac finite_imageI 1);
paulson@3340
   377
by (Blast_tac 1);
paulson@3340
   378
by (Blast_tac 1);
paulson@3340
   379
qed_spec_mp "card_image";
paulson@3340
   380
paulson@5143
   381
Goal "finite A ==> card (Pow A) = 2 ^ card A";
paulson@3389
   382
by (etac finite_induct 1);
wenzelm@4089
   383
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Pow_insert])));
paulson@3389
   384
by (stac card_Un_disjoint 1);
wenzelm@4089
   385
by (EVERY (map (blast_tac (claset() addIs [finite_imageI])) [3,2,1]));
nipkow@4830
   386
by (subgoal_tac "inj_on (insert x) (Pow F)" 1);
wenzelm@4089
   387
by (asm_simp_tac (simpset() addsimps [card_image, Pow_insert]) 1);
nipkow@4830
   388
by (rewtac inj_on_def);
wenzelm@4089
   389
by (blast_tac (claset() addSEs [equalityE]) 1);
paulson@3389
   390
qed "card_Pow";
paulson@3389
   391
Addsimps [card_Pow];
paulson@3340
   392
paulson@3389
   393
paulson@3389
   394
(*Proper subsets*)
paulson@5148
   395
Goalw [psubset_def] "finite B ==> !A. A < B --> card(A) < card(B)";
nipkow@3222
   396
by (etac finite_induct 1);
nipkow@3222
   397
by (Simp_tac 1);
paulson@3708
   398
by (Clarify_tac 1);
nipkow@3222
   399
by (case_tac "x:A" 1);
nipkow@3222
   400
(*1*)
nipkow@3413
   401
by (dres_inst_tac [("A","A")]mk_disjoint_insert 1);
paulson@4775
   402
by (Clarify_tac 1);
paulson@4775
   403
by (rotate_tac ~3 1);
paulson@4775
   404
by (asm_full_simp_tac (simpset() addsimps [finite_subset]) 1);
paulson@3708
   405
by (Blast_tac 1);
nipkow@3222
   406
(*2*)
paulson@3708
   407
by (eres_inst_tac [("P","?a<?b")] notE 1);
paulson@4775
   408
by (asm_full_simp_tac (simpset() addsimps [subset_insert_iff]) 1);
nipkow@3222
   409
by (case_tac "A=F" 1);
paulson@3708
   410
by (ALLGOALS Asm_simp_tac);
nipkow@3222
   411
qed_spec_mp "psubset_card" ;
paulson@3368
   412
paulson@3368
   413
wenzelm@3430
   414
(*Relates to equivalence classes.   Based on a theorem of F. Kammueller's.
paulson@3368
   415
  The "finite C" premise is redundant*)
paulson@5143
   416
Goal "finite C ==> finite (Union C) --> \
paulson@3368
   417
\          (! c : C. k dvd card c) -->  \
paulson@3368
   418
\          (! c1: C. ! c2: C. c1 ~= c2 --> c1 Int c2 = {}) \
paulson@3368
   419
\          --> k dvd card(Union C)";
paulson@3368
   420
by (etac finite_induct 1);
paulson@3368
   421
by (ALLGOALS Asm_simp_tac);
paulson@3708
   422
by (Clarify_tac 1);
paulson@3368
   423
by (stac card_Un_disjoint 1);
paulson@3368
   424
by (ALLGOALS
wenzelm@4089
   425
    (asm_full_simp_tac (simpset()
paulson@3368
   426
			 addsimps [dvd_add, disjoint_eq_subset_Compl])));
paulson@3368
   427
by (thin_tac "!c:F. ?PP(c)" 1);
paulson@3368
   428
by (thin_tac "!c:F. ?PP(c) & ?QQ(c)" 1);
paulson@3708
   429
by (Clarify_tac 1);
paulson@3368
   430
by (ball_tac 1);
paulson@3368
   431
by (Blast_tac 1);
paulson@3368
   432
qed_spec_mp "dvd_partition";
paulson@3368
   433