src/HOL/Finite.ML
author paulson
Mon Oct 11 10:48:44 1999 +0200 (1999-10-11)
changeset 7821 a8717f53036c
parent 7499 23e090051cb8
child 7834 915be5b9dc6f
permissions -rw-r--r--
new thm card_Diff_singleton; tidied
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
paulson@5537
    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
nipkow@5626
   114
Goal "finite(A - insert a B) = finite(A-B)";
paulson@6162
   115
by (stac Diff_insert 1);
nipkow@5626
   116
by (case_tac "a : A-B" 1);
paulson@3457
   117
by (rtac (finite_insert RS sym RS trans) 1);
paulson@3368
   118
by (stac insert_Diff 1);
nipkow@5626
   119
by (ALLGOALS Asm_full_simp_tac);
nipkow@5626
   120
qed "finite_Diff_insert";
nipkow@5626
   121
AddIffs [finite_Diff_insert];
nipkow@5626
   122
nipkow@5626
   123
(* lemma merely for classical reasoner *)
nipkow@5626
   124
Goal "finite(A-{}) = finite A";
nipkow@5626
   125
by (Simp_tac 1);
nipkow@5626
   126
val lemma = result();
nipkow@5626
   127
AddSIs [lemma RS iffD2];
nipkow@5626
   128
AddSDs [lemma RS iffD1];
paulson@3368
   129
paulson@4059
   130
(*Lemma for proving finite_imageD*)
paulson@5143
   131
Goal "finite B ==> !A. f``A = B --> inj_on f A --> finite A";
paulson@1553
   132
by (etac finite_induct 1);
nipkow@3413
   133
 by (ALLGOALS Asm_simp_tac);
paulson@3708
   134
by (Clarify_tac 1);
nipkow@3413
   135
by (subgoal_tac "EX y:A. f y = x & F = f``(A-{y})" 1);
paulson@3708
   136
 by (Clarify_tac 1);
nipkow@4830
   137
 by (full_simp_tac (simpset() addsimps [inj_on_def]) 1);
nipkow@3413
   138
 by (Blast_tac 1);
paulson@3368
   139
by (thin_tac "ALL A. ?PP(A)" 1);
nipkow@3413
   140
by (forward_tac [[equalityD2, insertI1] MRS subsetD] 1);
paulson@3708
   141
by (Clarify_tac 1);
paulson@3368
   142
by (res_inst_tac [("x","xa")] bexI 1);
paulson@4059
   143
by (ALLGOALS 
nipkow@4830
   144
    (asm_full_simp_tac (simpset() addsimps [inj_on_image_set_diff])));
paulson@3368
   145
val lemma = result();
paulson@3368
   146
paulson@5143
   147
Goal "[| finite(f``A);  inj_on f A |] ==> finite A";
paulson@3457
   148
by (dtac lemma 1);
paulson@3368
   149
by (Blast_tac 1);
paulson@3368
   150
qed "finite_imageD";
paulson@3368
   151
nipkow@4014
   152
(** The finite UNION of finite sets **)
nipkow@4014
   153
paulson@5316
   154
Goal "finite A ==> (!a:A. finite(B a)) --> finite(UN a:A. B a)";
paulson@5316
   155
by (etac finite_induct 1);
paulson@4153
   156
by (ALLGOALS Asm_simp_tac);
nipkow@4014
   157
bind_thm("finite_UnionI", ballI RSN (2, result() RS mp));
nipkow@4014
   158
Addsimps [finite_UnionI];
nipkow@4014
   159
nipkow@4014
   160
(** Sigma of finite sets **)
nipkow@4014
   161
wenzelm@5069
   162
Goalw [Sigma_def]
paulson@5148
   163
 "[| finite A; !a:A. finite(B a) |] ==> finite(SIGMA a:A. B a)";
paulson@4153
   164
by (blast_tac (claset() addSIs [finite_UnionI]) 1);
nipkow@4014
   165
bind_thm("finite_SigmaI", ballI RSN (2,result()));
nipkow@4014
   166
Addsimps [finite_SigmaI];
paulson@3368
   167
paulson@3368
   168
(** The powerset of a finite set **)
paulson@3368
   169
paulson@5143
   170
Goal "finite(Pow A) ==> finite A";
paulson@3368
   171
by (subgoal_tac "finite ((%x.{x})``A)" 1);
paulson@3457
   172
by (rtac finite_subset 2);
paulson@3457
   173
by (assume_tac 3);
paulson@3368
   174
by (ALLGOALS
nipkow@4830
   175
    (fast_tac (claset() addSDs [rewrite_rule [inj_on_def] finite_imageD])));
paulson@3368
   176
val lemma = result();
paulson@3368
   177
wenzelm@5069
   178
Goal "finite(Pow A) = finite A";
paulson@3457
   179
by (rtac iffI 1);
paulson@3457
   180
by (etac lemma 1);
paulson@3368
   181
(*Opposite inclusion: finite A ==> finite (Pow A) *)
paulson@3340
   182
by (etac finite_induct 1);
paulson@3340
   183
by (ALLGOALS 
paulson@3340
   184
    (asm_simp_tac
wenzelm@4089
   185
     (simpset() addsimps [finite_UnI, finite_imageI, Pow_insert])));
paulson@3368
   186
qed "finite_Pow_iff";
paulson@3368
   187
AddIffs [finite_Pow_iff];
paulson@3340
   188
wenzelm@5069
   189
Goal "finite(r^-1) = finite r";
paulson@3457
   190
by (subgoal_tac "r^-1 = (%(x,y).(y,x))``r" 1);
paulson@3457
   191
 by (Asm_simp_tac 1);
paulson@3457
   192
 by (rtac iffI 1);
nipkow@4830
   193
  by (etac (rewrite_rule [inj_on_def] finite_imageD) 1);
nipkow@4830
   194
  by (simp_tac (simpset() addsplits [split_split]) 1);
paulson@3457
   195
 by (etac finite_imageI 1);
paulson@4746
   196
by (simp_tac (simpset() addsimps [converse_def,image_def]) 1);
paulson@4477
   197
by Auto_tac;
oheimb@5516
   198
by (rtac bexI 1);
oheimb@5516
   199
by  (assume_tac 2);
oheimb@4763
   200
by (Simp_tac 1);
paulson@4746
   201
qed "finite_converse";
paulson@4746
   202
AddIffs [finite_converse];
nipkow@1531
   203
nipkow@1548
   204
section "Finite cardinality -- 'card'";
nipkow@1531
   205
nipkow@5626
   206
(* Ugly proofs for the traditional definition 
nipkow@5626
   207
paulson@5316
   208
Goal "{f i |i. (P i | i=n)} = insert (f n) {f i|i. P i}";
paulson@2922
   209
by (Blast_tac 1);
nipkow@1531
   210
val Collect_conv_insert = result();
nipkow@1531
   211
wenzelm@5069
   212
Goalw [card_def] "card {} = 0";
paulson@1553
   213
by (rtac Least_equality 1);
paulson@1553
   214
by (ALLGOALS Asm_full_simp_tac);
nipkow@1531
   215
qed "card_empty";
nipkow@1531
   216
Addsimps [card_empty];
nipkow@1531
   217
paulson@5316
   218
Goal "finite A ==> ? (n::nat) f. A = {f i |i. i<n}";
paulson@5316
   219
by (etac finite_induct 1);
paulson@1553
   220
 by (res_inst_tac [("x","0")] exI 1);
paulson@1553
   221
 by (Simp_tac 1);
paulson@1553
   222
by (etac exE 1);
paulson@1553
   223
by (etac exE 1);
paulson@1553
   224
by (hyp_subst_tac 1);
paulson@1553
   225
by (res_inst_tac [("x","Suc n")] exI 1);
paulson@1553
   226
by (res_inst_tac [("x","%i. if i<n then f i else x")] exI 1);
wenzelm@4089
   227
by (asm_simp_tac (simpset() addsimps [Collect_conv_insert, less_Suc_eq]
nipkow@1548
   228
                          addcongs [rev_conj_cong]) 1);
nipkow@1531
   229
qed "finite_has_card";
nipkow@1531
   230
paulson@5278
   231
Goal "[| x ~: A; insert x A = {f i|i. i<n} |]  \
paulson@5278
   232
\     ==> ? m::nat. m<n & (? g. A = {g i|i. i<m})";
berghofe@5183
   233
by (exhaust_tac "n" 1);
paulson@1553
   234
 by (hyp_subst_tac 1);
paulson@1553
   235
 by (Asm_full_simp_tac 1);
paulson@1553
   236
by (rename_tac "m" 1);
paulson@1553
   237
by (hyp_subst_tac 1);
paulson@1553
   238
by (case_tac "? a. a:A" 1);
paulson@1553
   239
 by (res_inst_tac [("x","0")] exI 2);
paulson@1553
   240
 by (Simp_tac 2);
paulson@2922
   241
 by (Blast_tac 2);
paulson@1553
   242
by (etac exE 1);
wenzelm@4089
   243
by (simp_tac (simpset() addsimps [less_Suc_eq]) 1);
paulson@1553
   244
by (rtac exI 1);
paulson@1782
   245
by (rtac (refl RS disjI2 RS conjI) 1);
paulson@1553
   246
by (etac equalityE 1);
paulson@1553
   247
by (asm_full_simp_tac
wenzelm@4089
   248
     (simpset() addsimps [subset_insert,Collect_conv_insert, less_Suc_eq]) 1);
paulson@4153
   249
by Safe_tac;
paulson@1553
   250
  by (Asm_full_simp_tac 1);
paulson@1553
   251
  by (res_inst_tac [("x","%i. if f i = f m then a else f i")] exI 1);
paulson@4153
   252
  by (SELECT_GOAL Safe_tac 1);
paulson@1553
   253
   by (subgoal_tac "x ~= f m" 1);
paulson@2922
   254
    by (Blast_tac 2);
paulson@1553
   255
   by (subgoal_tac "? k. f k = x & k<m" 1);
paulson@2922
   256
    by (Blast_tac 2);
paulson@4153
   257
   by (SELECT_GOAL Safe_tac 1);
paulson@1553
   258
   by (res_inst_tac [("x","k")] exI 1);
paulson@1553
   259
   by (Asm_simp_tac 1);
nipkow@4686
   260
  by (Simp_tac 1);
paulson@2922
   261
  by (Blast_tac 1);
paulson@3457
   262
 by (dtac sym 1);
paulson@1553
   263
 by (rotate_tac ~1 1);
paulson@1553
   264
 by (Asm_full_simp_tac 1);
paulson@1553
   265
 by (res_inst_tac [("x","%i. if f i = f m then a else f i")] exI 1);
paulson@4153
   266
 by (SELECT_GOAL Safe_tac 1);
paulson@1553
   267
  by (subgoal_tac "x ~= f m" 1);
paulson@2922
   268
   by (Blast_tac 2);
paulson@1553
   269
  by (subgoal_tac "? k. f k = x & k<m" 1);
paulson@2922
   270
   by (Blast_tac 2);
paulson@4153
   271
  by (SELECT_GOAL Safe_tac 1);
paulson@1553
   272
  by (res_inst_tac [("x","k")] exI 1);
paulson@1553
   273
  by (Asm_simp_tac 1);
nipkow@4686
   274
 by (Simp_tac 1);
paulson@2922
   275
 by (Blast_tac 1);
paulson@1553
   276
by (res_inst_tac [("x","%j. if f j = f i then f m else f j")] exI 1);
paulson@4153
   277
by (SELECT_GOAL Safe_tac 1);
paulson@1553
   278
 by (subgoal_tac "x ~= f i" 1);
paulson@2922
   279
  by (Blast_tac 2);
paulson@1553
   280
 by (case_tac "x = f m" 1);
paulson@1553
   281
  by (res_inst_tac [("x","i")] exI 1);
paulson@1553
   282
  by (Asm_simp_tac 1);
paulson@1553
   283
 by (subgoal_tac "? k. f k = x & k<m" 1);
paulson@2922
   284
  by (Blast_tac 2);
paulson@4153
   285
 by (SELECT_GOAL Safe_tac 1);
paulson@1553
   286
 by (res_inst_tac [("x","k")] exI 1);
paulson@1553
   287
 by (Asm_simp_tac 1);
nipkow@4686
   288
by (Simp_tac 1);
paulson@2922
   289
by (Blast_tac 1);
nipkow@1531
   290
val lemma = result();
nipkow@1531
   291
paulson@5143
   292
Goal "[| finite A; x ~: A |] ==> \
wenzelm@3842
   293
\ (LEAST n. ? f. insert x A = {f i|i. i<n}) = Suc(LEAST n. ? f. A={f i|i. i<n})";
paulson@1553
   294
by (rtac Least_equality 1);
paulson@3457
   295
 by (dtac finite_has_card 1);
paulson@3457
   296
 by (etac exE 1);
wenzelm@3842
   297
 by (dres_inst_tac [("P","%n.? f. A={f i|i. i<n}")] LeastI 1);
paulson@3457
   298
 by (etac exE 1);
paulson@1553
   299
 by (res_inst_tac
nipkow@1531
   300
   [("x","%i. if i<(LEAST n. ? f. A={f i |i. i < n}) then f i else x")] exI 1);
paulson@1553
   301
 by (simp_tac
wenzelm@4089
   302
    (simpset() addsimps [Collect_conv_insert, less_Suc_eq] 
paulson@2031
   303
              addcongs [rev_conj_cong]) 1);
paulson@3457
   304
 by (etac subst 1);
paulson@3457
   305
 by (rtac refl 1);
paulson@1553
   306
by (rtac notI 1);
paulson@1553
   307
by (etac exE 1);
paulson@1553
   308
by (dtac lemma 1);
paulson@3457
   309
 by (assume_tac 1);
paulson@1553
   310
by (etac exE 1);
paulson@1553
   311
by (etac conjE 1);
paulson@1553
   312
by (dres_inst_tac [("P","%x. ? g. A = {g i |i. i < x}")] Least_le 1);
paulson@1553
   313
by (dtac le_less_trans 1 THEN atac 1);
wenzelm@4089
   314
by (asm_full_simp_tac (simpset() addsimps [less_Suc_eq]) 1);
paulson@1553
   315
by (etac disjE 1);
paulson@1553
   316
by (etac less_asym 1 THEN atac 1);
paulson@1553
   317
by (hyp_subst_tac 1);
paulson@1553
   318
by (Asm_full_simp_tac 1);
nipkow@1531
   319
val lemma = result();
nipkow@1531
   320
paulson@5416
   321
Goalw [card_def] "[| finite A; x ~: A |] ==> card(insert x A) = Suc(card A)";
paulson@1553
   322
by (etac lemma 1);
paulson@1553
   323
by (assume_tac 1);
nipkow@1531
   324
qed "card_insert_disjoint";
paulson@3352
   325
Addsimps [card_insert_disjoint];
nipkow@5626
   326
*)
nipkow@5626
   327
paulson@6141
   328
val cardR_emptyE = cardR.mk_cases "({},n) : cardR";
nipkow@5626
   329
AddSEs [cardR_emptyE];
paulson@6141
   330
val cardR_insertE = cardR.mk_cases "(insert a A,n) : cardR";
nipkow@5626
   331
AddSIs cardR.intrs;
nipkow@5626
   332
nipkow@5626
   333
Goal "[| (A,n) : cardR |] ==> a : A --> (? m. n = Suc m)";
paulson@6162
   334
by (etac cardR.induct 1);
paulson@6162
   335
 by (Blast_tac 1);
paulson@6162
   336
by (Blast_tac 1);
nipkow@5626
   337
qed "cardR_SucD";
nipkow@5626
   338
nipkow@5626
   339
Goal "(A,m): cardR ==> (!n a. m = Suc n --> a:A --> (A-{a},n) : cardR)";
paulson@6162
   340
by (etac cardR.induct 1);
paulson@6162
   341
 by (Auto_tac);
paulson@6162
   342
by (asm_simp_tac (simpset() addsimps [insert_Diff_if]) 1);
paulson@6162
   343
by (Auto_tac);
wenzelm@7499
   344
by (ftac cardR_SucD 1);
paulson@6162
   345
by (Blast_tac 1);
nipkow@5626
   346
val lemma = result();
nipkow@5626
   347
nipkow@5626
   348
Goal "[| (insert a A, Suc m) : cardR; a ~: A |] ==> (A,m) : cardR";
paulson@6162
   349
by (dtac lemma 1);
paulson@6162
   350
by (Asm_full_simp_tac 1);
nipkow@5626
   351
val lemma = result();
nipkow@5626
   352
nipkow@5626
   353
Goal "(A,m): cardR ==> (!n. (A,n) : cardR --> n=m)";
paulson@6162
   354
by (etac cardR.induct 1);
paulson@6162
   355
 by (safe_tac (claset() addSEs [cardR_insertE]));
paulson@6162
   356
by (rename_tac "B b m" 1);
paulson@6162
   357
by (case_tac "a = b" 1);
paulson@6162
   358
 by (subgoal_tac "A = B" 1);
paulson@6162
   359
  by (blast_tac (claset() addEs [equalityE]) 2);
paulson@6162
   360
 by (Blast_tac 1);
paulson@6162
   361
by (subgoal_tac "? C. A = insert b C & B = insert a C" 1);
paulson@6162
   362
 by (res_inst_tac [("x","A Int B")] exI 2);
paulson@6162
   363
 by (blast_tac (claset() addEs [equalityE]) 2);
paulson@6162
   364
by (forw_inst_tac [("A","B")] cardR_SucD 1);
paulson@6162
   365
by (blast_tac (claset() addDs [lemma]) 1);
nipkow@5626
   366
qed_spec_mp "cardR_determ";
nipkow@5626
   367
nipkow@5626
   368
Goal "(A,n) : cardR ==> finite(A)";
nipkow@5626
   369
by (etac cardR.induct 1);
nipkow@5626
   370
by Auto_tac;
nipkow@5626
   371
qed "cardR_imp_finite";
nipkow@5626
   372
nipkow@5626
   373
Goal "finite(A) ==> EX n. (A, n) : cardR";
nipkow@5626
   374
by (etac finite_induct 1);
nipkow@5626
   375
by Auto_tac;
nipkow@5626
   376
qed "finite_imp_cardR";
nipkow@5626
   377
nipkow@5626
   378
Goalw [card_def] "(A,n) : cardR ==> card A = n";
nipkow@5626
   379
by (blast_tac (claset() addIs [cardR_determ]) 1);
nipkow@5626
   380
qed "card_equality";
nipkow@5626
   381
nipkow@5626
   382
Goalw [card_def] "card {} = 0";
nipkow@5626
   383
by (Blast_tac 1);
nipkow@5626
   384
qed "card_empty";
nipkow@5626
   385
Addsimps [card_empty];
nipkow@5626
   386
nipkow@5626
   387
Goal "x ~: A ==> \
nipkow@5626
   388
\     ((insert x A, n) : cardR) =  \
nipkow@5626
   389
\     (EX m. (A, m) : cardR & n = Suc m)";
nipkow@5626
   390
by Auto_tac;
nipkow@5626
   391
by (res_inst_tac [("A1", "A")] (finite_imp_cardR RS exE) 1);
nipkow@5626
   392
by (force_tac (claset() addDs [cardR_imp_finite], simpset()) 1);
nipkow@5626
   393
by (blast_tac (claset() addIs [cardR_determ]) 1);
nipkow@5626
   394
val lemma = result();
nipkow@5626
   395
nipkow@5626
   396
Goalw [card_def]
nipkow@5626
   397
     "[| finite A; x ~: A |] ==> card (insert x A) = Suc(card A)";
nipkow@5626
   398
by (asm_simp_tac (simpset() addsimps [lemma]) 1);
nipkow@5626
   399
by (rtac select_equality 1);
nipkow@5626
   400
by (auto_tac (claset() addIs [finite_imp_cardR],
nipkow@5626
   401
	      simpset() addcongs [conj_cong]
nipkow@5626
   402
		        addsimps [symmetric card_def,
nipkow@5626
   403
				  card_equality]));
nipkow@5626
   404
qed "card_insert_disjoint";
nipkow@5626
   405
Addsimps [card_insert_disjoint];
nipkow@5626
   406
nipkow@5626
   407
(* Delete rules to do with cardR relation: obsolete *)
nipkow@5626
   408
Delrules [cardR_emptyE];
nipkow@5626
   409
Delrules cardR.intrs;
nipkow@5626
   410
nipkow@5626
   411
Goal "finite A ==> card(insert x A) = (if x:A then card A else Suc(card(A)))";
nipkow@5626
   412
by (asm_simp_tac (simpset() addsimps [insert_absorb]) 1);
nipkow@5626
   413
qed "card_insert_if";
nipkow@5626
   414
paulson@7821
   415
Goal "[| finite A; x: A |] ==> Suc (card (A-{x})) = card A";
nipkow@5626
   416
by (res_inst_tac [("t", "A")] (insert_Diff RS subst) 1);
nipkow@5626
   417
by (assume_tac 1);
nipkow@5626
   418
by (Asm_simp_tac 1);
nipkow@5626
   419
qed "card_Suc_Diff1";
nipkow@5626
   420
paulson@7821
   421
Goal "[| finite A; x: A |] ==> card (A-{x}) = card A - 1";
paulson@7821
   422
by (asm_simp_tac (simpset() addsimps [card_Suc_Diff1 RS sym]) 1);
paulson@7821
   423
qed "card_Diff_singleton";
paulson@7821
   424
nipkow@5626
   425
Goal "finite A ==> card(insert x A) = Suc(card(A-{x}))";
nipkow@5626
   426
by (asm_simp_tac (simpset() addsimps [card_insert_if,card_Suc_Diff1]) 1);
nipkow@5626
   427
qed "card_insert";
paulson@3352
   428
paulson@5143
   429
Goal "finite A ==> card A <= card (insert x A)";
nipkow@5626
   430
by (asm_simp_tac (simpset() addsimps [card_insert_if]) 1);
paulson@4768
   431
qed "card_insert_le";
paulson@4768
   432
paulson@5143
   433
Goal  "finite A ==> !B. B <= A --> card(B) <= card(A)";
paulson@3352
   434
by (etac finite_induct 1);
paulson@3352
   435
by (Simp_tac 1);
paulson@3708
   436
by (Clarify_tac 1);
paulson@3352
   437
by (case_tac "x:B" 1);
nipkow@3413
   438
 by (dres_inst_tac [("A","B")] mk_disjoint_insert 1);
oheimb@5476
   439
 by (asm_full_simp_tac (simpset() addsimps [subset_insert_iff]) 2);
paulson@4775
   440
by (fast_tac (claset() addss
oheimb@5477
   441
	      (simpset() addsimps [subset_insert_iff, finite_subset]
oheimb@5477
   442
			 delsimps [insert_subset])) 1);
paulson@3352
   443
qed_spec_mp "card_mono";
paulson@3352
   444
paulson@5416
   445
paulson@5416
   446
Goal "[| finite A; finite B |] \
paulson@5416
   447
\     ==> card A + card B = card (A Un B) + card (A Int B)";
paulson@3352
   448
by (etac finite_induct 1);
paulson@5416
   449
by (Simp_tac 1);
paulson@5416
   450
by (asm_simp_tac (simpset() addsimps [insert_absorb, Int_insert_left]) 1);
paulson@5416
   451
qed "card_Un_Int";
paulson@5416
   452
paulson@5416
   453
Goal "[| finite A; finite B; A Int B = {} |] \
paulson@5416
   454
\     ==> card (A Un B) = card A + card B";
paulson@5416
   455
by (asm_simp_tac (simpset() addsimps [card_Un_Int]) 1);
paulson@5416
   456
qed "card_Un_disjoint";
paulson@3352
   457
paulson@5143
   458
Goal "[| finite A; B<=A |] ==> card A - card B = card (A - B)";
paulson@3352
   459
by (subgoal_tac "(A-B) Un B = A" 1);
paulson@3352
   460
by (Blast_tac 2);
paulson@3457
   461
by (rtac (add_right_cancel RS iffD1) 1);
paulson@3457
   462
by (rtac (card_Un_disjoint RS subst) 1);
paulson@3457
   463
by (etac ssubst 4);
paulson@3352
   464
by (Blast_tac 3);
paulson@3352
   465
by (ALLGOALS 
paulson@3352
   466
    (asm_simp_tac
wenzelm@4089
   467
     (simpset() addsimps [add_commute, not_less_iff_le, 
paulson@5416
   468
			  add_diff_inverse, card_mono, finite_subset])));
paulson@3352
   469
qed "card_Diff_subset";
nipkow@1531
   470
paulson@5143
   471
Goal "[| finite A; x: A |] ==> card(A-{x}) < card A";
paulson@2031
   472
by (rtac Suc_less_SucD 1);
nipkow@5626
   473
by (asm_simp_tac (simpset() addsimps [card_Suc_Diff1]) 1);
nipkow@5626
   474
qed "card_Diff1_less";
paulson@1618
   475
paulson@5143
   476
Goal "finite A ==> card(A-{x}) <= card A";
paulson@4768
   477
by (case_tac "x: A" 1);
nipkow@5626
   478
by (ALLGOALS (asm_simp_tac (simpset() addsimps [card_Diff1_less, less_imp_le])));
nipkow@5626
   479
qed "card_Diff1_le";
nipkow@1531
   480
paulson@5148
   481
Goalw [psubset_def] "finite B ==> !A. A < B --> card(A) < card(B)";
nipkow@3222
   482
by (etac finite_induct 1);
nipkow@3222
   483
by (Simp_tac 1);
paulson@3708
   484
by (Clarify_tac 1);
nipkow@3222
   485
by (case_tac "x:A" 1);
nipkow@3222
   486
(*1*)
nipkow@3413
   487
by (dres_inst_tac [("A","A")]mk_disjoint_insert 1);
paulson@4775
   488
by (Clarify_tac 1);
paulson@4775
   489
by (rotate_tac ~3 1);
paulson@4775
   490
by (asm_full_simp_tac (simpset() addsimps [finite_subset]) 1);
paulson@3708
   491
by (Blast_tac 1);
nipkow@3222
   492
(*2*)
paulson@3708
   493
by (eres_inst_tac [("P","?a<?b")] notE 1);
paulson@4775
   494
by (asm_full_simp_tac (simpset() addsimps [subset_insert_iff]) 1);
nipkow@3222
   495
by (case_tac "A=F" 1);
paulson@3708
   496
by (ALLGOALS Asm_simp_tac);
nipkow@3222
   497
qed_spec_mp "psubset_card" ;
paulson@3368
   498
paulson@7821
   499
Goal "[| A <= B; card B <= card A; finite B |] ==> A = B";
nipkow@5626
   500
by (case_tac "A < B" 1);
oheimb@7497
   501
by (datac psubset_card 1 1);
nipkow@5626
   502
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [psubset_eq])));
nipkow@5626
   503
qed "card_seteq";
nipkow@5626
   504
nipkow@5626
   505
Goal "[| finite B; A <= B; card A < card B |] ==> A < B";
nipkow@5626
   506
by (etac psubsetI 1);
nipkow@5626
   507
by (Blast_tac 1);
nipkow@5626
   508
qed "card_psubset";
nipkow@5626
   509
nipkow@5626
   510
(*** Cardinality of image ***)
nipkow@5626
   511
nipkow@5626
   512
Goal "finite A ==> card (f `` A) <= card A";
nipkow@5626
   513
by (etac finite_induct 1);
nipkow@5626
   514
by (Simp_tac 1);
nipkow@5626
   515
by (asm_simp_tac (simpset() addsimps [finite_imageI,card_insert_if]) 1);
nipkow@5626
   516
qed "card_image_le";
nipkow@5626
   517
nipkow@5626
   518
Goal "finite(A) ==> inj_on f A --> card (f `` A) = card A";
nipkow@5626
   519
by (etac finite_induct 1);
nipkow@5626
   520
by (ALLGOALS Asm_simp_tac);
nipkow@5626
   521
by Safe_tac;
nipkow@5626
   522
by (rewtac inj_on_def);
nipkow@5626
   523
by (Blast_tac 1);
nipkow@5626
   524
by (stac card_insert_disjoint 1);
nipkow@5626
   525
by (etac finite_imageI 1);
nipkow@5626
   526
by (Blast_tac 1);
nipkow@5626
   527
by (Blast_tac 1);
nipkow@5626
   528
qed_spec_mp "card_image";
nipkow@5626
   529
nipkow@5626
   530
Goal "[| finite A; f``A <= A; inj_on f A |] ==> f``A = A";
oheimb@7497
   531
by (etac card_seteq 1);
oheimb@7497
   532
by (dtac (card_image RS sym) 1);
oheimb@7497
   533
by Auto_tac;
nipkow@5626
   534
qed "endo_inj_surj";
nipkow@5626
   535
nipkow@5626
   536
(*** Cardinality of the Powerset ***)
nipkow@5626
   537
nipkow@5626
   538
Goal "finite A ==> card (Pow A) = 2 ^ card A";
nipkow@5626
   539
by (etac finite_induct 1);
nipkow@5626
   540
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Pow_insert])));
nipkow@5626
   541
by (stac card_Un_disjoint 1);
nipkow@5626
   542
by (EVERY (map (blast_tac (claset() addIs [finite_imageI])) [3,2,1]));
nipkow@5626
   543
by (subgoal_tac "inj_on (insert x) (Pow F)" 1);
nipkow@5626
   544
by (asm_simp_tac (simpset() addsimps [card_image, Pow_insert]) 1);
nipkow@5626
   545
by (rewtac inj_on_def);
nipkow@5626
   546
by (blast_tac (claset() addSEs [equalityE]) 1);
nipkow@5626
   547
qed "card_Pow";
nipkow@5626
   548
Addsimps [card_Pow];
nipkow@5626
   549
paulson@3368
   550
wenzelm@3430
   551
(*Relates to equivalence classes.   Based on a theorem of F. Kammueller's.
paulson@3368
   552
  The "finite C" premise is redundant*)
paulson@5143
   553
Goal "finite C ==> finite (Union C) --> \
paulson@3368
   554
\          (! c : C. k dvd card c) -->  \
paulson@3368
   555
\          (! c1: C. ! c2: C. c1 ~= c2 --> c1 Int c2 = {}) \
paulson@3368
   556
\          --> k dvd card(Union C)";
paulson@3368
   557
by (etac finite_induct 1);
paulson@3368
   558
by (ALLGOALS Asm_simp_tac);
paulson@3708
   559
by (Clarify_tac 1);
paulson@3368
   560
by (stac card_Un_disjoint 1);
paulson@3368
   561
by (ALLGOALS
wenzelm@4089
   562
    (asm_full_simp_tac (simpset()
paulson@3368
   563
			 addsimps [dvd_add, disjoint_eq_subset_Compl])));
paulson@3368
   564
by (thin_tac "!c:F. ?PP(c)" 1);
paulson@3368
   565
by (thin_tac "!c:F. ?PP(c) & ?QQ(c)" 1);
paulson@3708
   566
by (Clarify_tac 1);
paulson@3368
   567
by (ball_tac 1);
paulson@3368
   568
by (Blast_tac 1);
paulson@3368
   569
qed_spec_mp "dvd_partition";
paulson@3368
   570
nipkow@5616
   571
nipkow@5616
   572
(*** foldSet ***)
nipkow@5616
   573
paulson@6141
   574
val empty_foldSetE = foldSet.mk_cases "({}, x) : foldSet f e";
nipkow@5616
   575
nipkow@5616
   576
AddSEs [empty_foldSetE];
nipkow@5616
   577
AddIs foldSet.intrs;
nipkow@5616
   578
nipkow@5616
   579
Goal "[| (A-{x},y) : foldSet f e;  x: A |] ==> (A, f x y) : foldSet f e";
nipkow@5616
   580
by (etac (insert_Diff RS subst) 1 THEN resolve_tac foldSet.intrs 1);
nipkow@5616
   581
by Auto_tac;
nipkow@5626
   582
qed "Diff1_foldSet";
nipkow@5616
   583
nipkow@5616
   584
Goal "(A, x) : foldSet f e ==> finite(A)";
nipkow@5616
   585
by (eresolve_tac [foldSet.induct] 1);
nipkow@5616
   586
by Auto_tac;
nipkow@5616
   587
qed "foldSet_imp_finite";
nipkow@5616
   588
nipkow@5616
   589
Addsimps [foldSet_imp_finite];
nipkow@5616
   590
nipkow@5616
   591
nipkow@5616
   592
Goal "finite(A) ==> EX x. (A, x) : foldSet f e";
nipkow@5616
   593
by (etac finite_induct 1);
nipkow@5616
   594
by Auto_tac;
nipkow@5616
   595
qed "finite_imp_foldSet";
nipkow@5616
   596
nipkow@5616
   597
nipkow@5616
   598
Open_locale "LC"; 
nipkow@5616
   599
paulson@5782
   600
val f_lcomm = thm "lcomm";
nipkow@5616
   601
nipkow@5616
   602
nipkow@5616
   603
Goal "ALL A x. card(A) < n --> (A, x) : foldSet f e --> \
nipkow@5616
   604
\            (ALL y. (A, y) : foldSet f e --> y=x)";
nipkow@5616
   605
by (induct_tac "n" 1);
nipkow@5616
   606
by (auto_tac (claset(), simpset() addsimps [less_Suc_eq]));
nipkow@5616
   607
by (etac foldSet.elim 1);
nipkow@5616
   608
by (Blast_tac 1);
nipkow@5616
   609
by (etac foldSet.elim 1);
nipkow@5616
   610
by (Blast_tac 1);
nipkow@5616
   611
by (Clarify_tac 1);
nipkow@5616
   612
(*force simplification of "card A < card (insert ...)"*)
nipkow@5616
   613
by (etac rev_mp 1);
nipkow@5616
   614
by (asm_simp_tac (simpset() addsimps [less_Suc_eq_le]) 1);
nipkow@5616
   615
by (rtac impI 1);
nipkow@5616
   616
(** LEVEL 10 **)
nipkow@5616
   617
by (rename_tac "Aa xa ya Ab xb yb" 1);
nipkow@5616
   618
 by (case_tac "xa=xb" 1);
nipkow@5616
   619
 by (subgoal_tac "Aa = Ab" 1);
nipkow@5616
   620
 by (blast_tac (claset() addEs [equalityE]) 2);
nipkow@5616
   621
 by (Blast_tac 1);
nipkow@5616
   622
(*case xa ~= xb*)
nipkow@5616
   623
by (subgoal_tac "Aa-{xb} = Ab-{xa} & xb : Aa & xa : Ab" 1);
nipkow@5616
   624
 by (blast_tac (claset() addEs [equalityE]) 2);
nipkow@5616
   625
by (Clarify_tac 1);
nipkow@5616
   626
by (subgoal_tac "Aa = insert xb Ab - {xa}" 1);
nipkow@5616
   627
 by (blast_tac (claset() addEs [equalityE]) 2);
nipkow@5616
   628
(** LEVEL 20 **)
nipkow@5616
   629
by (subgoal_tac "card Aa <= card Ab" 1);
nipkow@5616
   630
 by (rtac (Suc_le_mono RS subst) 2);
nipkow@5626
   631
 by (asm_simp_tac (simpset() addsimps [card_Suc_Diff1]) 2);
nipkow@5616
   632
by (res_inst_tac [("A1", "Aa-{xb}"), ("f1","f")] 
nipkow@5616
   633
    (finite_imp_foldSet RS exE) 1);
nipkow@5616
   634
by (blast_tac (claset() addIs [foldSet_imp_finite, finite_Diff]) 1);
wenzelm@7499
   635
by (ftac Diff1_foldSet 1 THEN assume_tac 1);
nipkow@5616
   636
by (subgoal_tac "ya = f xb x" 1);
nipkow@5616
   637
 by (Blast_tac 2);
nipkow@5616
   638
by (subgoal_tac "(Ab - {xa}, x) : foldSet f e" 1);
nipkow@5616
   639
 by (Asm_full_simp_tac 2);
nipkow@5616
   640
by (subgoal_tac "yb = f xa x" 1);
nipkow@5626
   641
 by (blast_tac (claset() addDs [Diff1_foldSet]) 2);
nipkow@5616
   642
by (asm_simp_tac (simpset() addsimps [f_lcomm]) 1);
nipkow@5616
   643
val lemma = result();
nipkow@5616
   644
nipkow@5616
   645
nipkow@5616
   646
Goal "[| (A, x) : foldSet f e;  (A, y) : foldSet f e |] ==> y=x";
nipkow@5616
   647
by (blast_tac (claset() addIs [normalize_thm [RSspec, RSmp] lemma]) 1);
nipkow@5616
   648
qed "foldSet_determ";
nipkow@5616
   649
nipkow@5616
   650
Goalw [fold_def] "(A,y) : foldSet f e ==> fold f e A = y";
nipkow@5616
   651
by (blast_tac (claset() addIs [foldSet_determ]) 1);
nipkow@5616
   652
qed "fold_equality";
nipkow@5616
   653
nipkow@5616
   654
Goalw [fold_def] "fold f e {} = e";
nipkow@5616
   655
by (Blast_tac 1);
nipkow@5616
   656
qed "fold_empty";
nipkow@5616
   657
Addsimps [fold_empty];
nipkow@5616
   658
nipkow@5626
   659
nipkow@5616
   660
Goal "x ~: A ==> \
nipkow@5616
   661
\     ((insert x A, v) : foldSet f e) =  \
nipkow@5616
   662
\     (EX y. (A, y) : foldSet f e & v = f x y)";
nipkow@5616
   663
by Auto_tac;
nipkow@5616
   664
by (res_inst_tac [("A1", "A"), ("f1","f")] (finite_imp_foldSet RS exE) 1);
nipkow@5616
   665
by (force_tac (claset() addDs [foldSet_imp_finite], simpset()) 1);
nipkow@5616
   666
by (blast_tac (claset() addIs [foldSet_determ]) 1);
nipkow@5616
   667
val lemma = result();
nipkow@5616
   668
nipkow@5616
   669
Goalw [fold_def]
nipkow@5616
   670
     "[| finite A; x ~: A |] ==> fold f e (insert x A) = f x (fold f e A)";
nipkow@5616
   671
by (asm_simp_tac (simpset() addsimps [lemma]) 1);
nipkow@5616
   672
by (rtac select_equality 1);
nipkow@5616
   673
by (auto_tac (claset() addIs [finite_imp_foldSet],
nipkow@5616
   674
	      simpset() addcongs [conj_cong]
nipkow@5616
   675
		        addsimps [symmetric fold_def,
nipkow@5616
   676
				  fold_equality]));
nipkow@5616
   677
qed "fold_insert";
nipkow@5616
   678
nipkow@5626
   679
(* Delete rules to do with foldSet relation: obsolete *)
nipkow@5626
   680
Delsimps [foldSet_imp_finite];
nipkow@5626
   681
Delrules [empty_foldSetE];
nipkow@5626
   682
Delrules foldSet.intrs;
nipkow@5626
   683
paulson@6024
   684
Close_locale "LC";
nipkow@5616
   685
nipkow@5616
   686
Open_locale "ACe"; 
nipkow@5616
   687
paulson@5782
   688
val f_ident   = thm "ident";
paulson@5782
   689
val f_commute = thm "commute";
paulson@5782
   690
val f_assoc   = thm "assoc";
nipkow@5616
   691
nipkow@5616
   692
nipkow@5616
   693
Goal "f x (f y z) = f y (f x z)";
nipkow@5616
   694
by (rtac (f_commute RS trans) 1);
nipkow@5616
   695
by (rtac (f_assoc RS trans) 1);
nipkow@5616
   696
by (rtac (f_commute RS arg_cong) 1);
nipkow@5616
   697
qed "f_left_commute";
nipkow@5616
   698
nipkow@5616
   699
val f_ac = [f_assoc, f_commute, f_left_commute];
nipkow@5616
   700
nipkow@5616
   701
Goal "f e x = x";
nipkow@5616
   702
by (stac f_commute 1);
nipkow@5616
   703
by (rtac f_ident 1);
nipkow@5616
   704
qed "f_left_ident";
nipkow@5616
   705
nipkow@5616
   706
val f_idents = [f_left_ident, f_ident];
nipkow@5616
   707
nipkow@5616
   708
Goal "[| finite A; finite B |] \
nipkow@5616
   709
\     ==> f (fold f e A) (fold f e B) =  \
nipkow@5616
   710
\         f (fold f e (A Un B)) (fold f e (A Int B))";
nipkow@5616
   711
by (etac finite_induct 1);
nipkow@5616
   712
by (simp_tac (simpset() addsimps f_idents) 1);
nipkow@5616
   713
by (asm_simp_tac (simpset() addsimps f_ac @ f_idents @
nipkow@5616
   714
           [export fold_insert,insert_absorb, Int_insert_left]) 1);
nipkow@5616
   715
qed "fold_Un_Int";
nipkow@5616
   716
nipkow@5616
   717
Goal "[| finite A; finite B; A Int B = {} |] \
nipkow@5616
   718
\     ==> fold f e (A Un B) = f (fold f e A) (fold f e B)";
nipkow@5616
   719
by (asm_simp_tac (simpset() addsimps fold_Un_Int::f_idents) 1);
nipkow@5616
   720
qed "fold_Un_disjoint";
nipkow@5616
   721
nipkow@5616
   722
Goal
nipkow@5616
   723
 "[| finite A; finite B |] ==> A Int B = {} --> \
nipkow@5616
   724
\ fold (f o g) e (A Un B) = f (fold (f o g) e A) (fold (f o g) e B)";
nipkow@5616
   725
by (etac finite_induct 1);
nipkow@5616
   726
by (simp_tac (simpset() addsimps f_idents) 1);
nipkow@5616
   727
by (asm_full_simp_tac (simpset() addsimps f_ac @ f_idents @
nipkow@5616
   728
           [export fold_insert,insert_absorb, Int_insert_left]) 1);
nipkow@5616
   729
qed "fold_Un_disjoint2";
nipkow@5616
   730
paulson@6024
   731
Close_locale "ACe";
nipkow@5616
   732
nipkow@5616
   733
Delrules ([empty_foldSetE] @ foldSet.intrs);
nipkow@5616
   734
Delsimps [foldSet_imp_finite];
nipkow@5616
   735
nipkow@5616
   736
(*** setsum ***)
nipkow@5616
   737
nipkow@5616
   738
Goalw [setsum_def] "setsum f {} = 0";
paulson@6162
   739
by (Simp_tac 1);
nipkow@5616
   740
qed "setsum_empty";
nipkow@5616
   741
Addsimps [setsum_empty];
nipkow@5616
   742
nipkow@5616
   743
Goalw [setsum_def]
nipkow@5616
   744
 "[| finite F; a ~: F |] ==> setsum f (insert a F) = f(a) + setsum f F";
paulson@6162
   745
by (asm_simp_tac (simpset() addsimps [export fold_insert]) 1);
nipkow@5616
   746
qed "setsum_insert";
nipkow@5616
   747
Addsimps [setsum_insert];
nipkow@5616
   748
nipkow@5616
   749
Goalw [setsum_def]
nipkow@5616
   750
 "[| finite A; finite B; A Int B = {} |] ==> \
nipkow@5616
   751
\ setsum f (A Un B) = setsum f A + setsum f B";
paulson@6162
   752
by (asm_simp_tac (simpset() addsimps [export fold_Un_disjoint2]) 1);
nipkow@5616
   753
qed_spec_mp "setsum_disj_Un";
nipkow@5616
   754
nipkow@5616
   755
Goal "[| finite F |] ==> \
nipkow@5616
   756
\     setsum f (F-{a}) = (if a:F then setsum f F - f a else setsum f F)";
paulson@6162
   757
by (etac finite_induct 1);
paulson@6162
   758
by (auto_tac (claset(), simpset() addsimps [insert_Diff_if]));
paulson@6162
   759
by (dres_inst_tac [("a","a")] mk_disjoint_insert 1);
paulson@6162
   760
by (Auto_tac);
nipkow@5616
   761
qed_spec_mp "setsum_diff1";