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