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