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