src/HOL/Finite.ML
author nipkow
Fri Oct 09 11:15:07 1998 +0200 (1998-10-09)
changeset 5626 f67c34721486
parent 5616 497eeeace3fc
child 5782 7559f116cb10
permissions -rw-r--r--
New inductive definition of `card'
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)";
nipkow@5626
   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
nipkow@5626
   328
val cardR_emptyE = cardR.mk_cases [] "({},n) : cardR";
nipkow@5626
   329
AddSEs [cardR_emptyE];
nipkow@5626
   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)";
nipkow@5626
   334
be cardR.induct 1;
nipkow@5626
   335
 by(Blast_tac 1);
nipkow@5626
   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)";
nipkow@5626
   340
be cardR.induct 1;
nipkow@5626
   341
 by(Auto_tac);
nipkow@5626
   342
by(asm_simp_tac (simpset() addsimps [insert_Diff_if]) 1);
nipkow@5626
   343
by(Auto_tac);
nipkow@5626
   344
by(forward_tac [cardR_SucD] 1);
nipkow@5626
   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";
nipkow@5626
   349
bd lemma 1;
nipkow@5626
   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)";
nipkow@5626
   354
be cardR.induct 1;
nipkow@5626
   355
 by(safe_tac (claset() addSEs [cardR_insertE]));
nipkow@5626
   356
by(rename_tac "B b m" 1);
nipkow@5626
   357
by(case_tac "a = b" 1);
nipkow@5626
   358
 by(subgoal_tac "A = B" 1);
nipkow@5626
   359
  by(blast_tac (claset() addEs [equalityE]) 2);
nipkow@5626
   360
 by(Blast_tac 1);
nipkow@5626
   361
by(subgoal_tac "? C. A = insert b C & B = insert a C" 1);
nipkow@5626
   362
 by(res_inst_tac [("x","A Int B")] exI 2);
nipkow@5626
   363
 by(blast_tac (claset() addEs [equalityE]) 2);
nipkow@5626
   364
by(forw_inst_tac [("A","B")] cardR_SucD 1);
nipkow@5626
   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
nipkow@5626
   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
nipkow@5626
   421
Goal "finite A ==> card(insert x A) = Suc(card(A-{x}))";
nipkow@5626
   422
by (asm_simp_tac (simpset() addsimps [card_insert_if,card_Suc_Diff1]) 1);
nipkow@5626
   423
qed "card_insert";
paulson@3352
   424
paulson@5143
   425
Goal "finite A ==> card A <= card (insert x A)";
nipkow@5626
   426
by (asm_simp_tac (simpset() addsimps [card_insert_if]) 1);
paulson@4768
   427
qed "card_insert_le";
paulson@4768
   428
paulson@5143
   429
Goal  "finite A ==> !B. B <= A --> card(B) <= card(A)";
paulson@3352
   430
by (etac finite_induct 1);
paulson@3352
   431
by (Simp_tac 1);
paulson@3708
   432
by (Clarify_tac 1);
paulson@3352
   433
by (case_tac "x:B" 1);
nipkow@3413
   434
 by (dres_inst_tac [("A","B")] mk_disjoint_insert 1);
oheimb@5476
   435
 by (asm_full_simp_tac (simpset() addsimps [subset_insert_iff]) 2);
paulson@4775
   436
by (fast_tac (claset() addss
oheimb@5477
   437
	      (simpset() addsimps [subset_insert_iff, finite_subset]
oheimb@5477
   438
			 delsimps [insert_subset])) 1);
paulson@3352
   439
qed_spec_mp "card_mono";
paulson@3352
   440
paulson@5416
   441
paulson@5416
   442
Goal "[| finite A; finite B |] \
paulson@5416
   443
\     ==> card A + card B = card (A Un B) + card (A Int B)";
paulson@3352
   444
by (etac finite_induct 1);
paulson@5416
   445
by (Simp_tac 1);
paulson@5416
   446
by (asm_simp_tac (simpset() addsimps [insert_absorb, Int_insert_left]) 1);
paulson@5416
   447
qed "card_Un_Int";
paulson@5416
   448
paulson@5416
   449
Goal "[| finite A; finite B; A Int B = {} |] \
paulson@5416
   450
\     ==> card (A Un B) = card A + card B";
paulson@5416
   451
by (asm_simp_tac (simpset() addsimps [card_Un_Int]) 1);
paulson@5416
   452
qed "card_Un_disjoint";
paulson@3352
   453
paulson@5143
   454
Goal "[| finite A; B<=A |] ==> card A - card B = card (A - B)";
paulson@3352
   455
by (subgoal_tac "(A-B) Un B = A" 1);
paulson@3352
   456
by (Blast_tac 2);
paulson@3457
   457
by (rtac (add_right_cancel RS iffD1) 1);
paulson@3457
   458
by (rtac (card_Un_disjoint RS subst) 1);
paulson@3457
   459
by (etac ssubst 4);
paulson@3352
   460
by (Blast_tac 3);
paulson@3352
   461
by (ALLGOALS 
paulson@3352
   462
    (asm_simp_tac
wenzelm@4089
   463
     (simpset() addsimps [add_commute, not_less_iff_le, 
paulson@5416
   464
			  add_diff_inverse, card_mono, finite_subset])));
paulson@3352
   465
qed "card_Diff_subset";
nipkow@1531
   466
paulson@5143
   467
Goal "[| finite A; x: A |] ==> card(A-{x}) < card A";
paulson@2031
   468
by (rtac Suc_less_SucD 1);
nipkow@5626
   469
by (asm_simp_tac (simpset() addsimps [card_Suc_Diff1]) 1);
nipkow@5626
   470
qed "card_Diff1_less";
paulson@1618
   471
paulson@5143
   472
Goal "finite A ==> card(A-{x}) <= card A";
paulson@4768
   473
by (case_tac "x: A" 1);
nipkow@5626
   474
by (ALLGOALS (asm_simp_tac (simpset() addsimps [card_Diff1_less, less_imp_le])));
nipkow@5626
   475
qed "card_Diff1_le";
nipkow@1531
   476
paulson@5148
   477
Goalw [psubset_def] "finite B ==> !A. A < B --> card(A) < card(B)";
nipkow@3222
   478
by (etac finite_induct 1);
nipkow@3222
   479
by (Simp_tac 1);
paulson@3708
   480
by (Clarify_tac 1);
nipkow@3222
   481
by (case_tac "x:A" 1);
nipkow@3222
   482
(*1*)
nipkow@3413
   483
by (dres_inst_tac [("A","A")]mk_disjoint_insert 1);
paulson@4775
   484
by (Clarify_tac 1);
paulson@4775
   485
by (rotate_tac ~3 1);
paulson@4775
   486
by (asm_full_simp_tac (simpset() addsimps [finite_subset]) 1);
paulson@3708
   487
by (Blast_tac 1);
nipkow@3222
   488
(*2*)
paulson@3708
   489
by (eres_inst_tac [("P","?a<?b")] notE 1);
paulson@4775
   490
by (asm_full_simp_tac (simpset() addsimps [subset_insert_iff]) 1);
nipkow@3222
   491
by (case_tac "A=F" 1);
paulson@3708
   492
by (ALLGOALS Asm_simp_tac);
nipkow@3222
   493
qed_spec_mp "psubset_card" ;
paulson@3368
   494
nipkow@5626
   495
Goal "[| finite B; A <= B; card A = card B |] ==> A = B";
nipkow@5626
   496
by (case_tac "A < B" 1);
nipkow@5626
   497
by ((dtac psubset_card 1) THEN (atac 1));
nipkow@5626
   498
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [psubset_eq])));
nipkow@5626
   499
qed "card_seteq";
nipkow@5626
   500
nipkow@5626
   501
Goal "[| finite B; A <= B; card A < card B |] ==> A < B";
nipkow@5626
   502
by (etac psubsetI 1);
nipkow@5626
   503
by (Blast_tac 1);
nipkow@5626
   504
qed "card_psubset";
nipkow@5626
   505
nipkow@5626
   506
(*** Cardinality of image ***)
nipkow@5626
   507
nipkow@5626
   508
Goal "finite A ==> card (f `` A) <= card A";
nipkow@5626
   509
by (etac finite_induct 1);
nipkow@5626
   510
by (Simp_tac 1);
nipkow@5626
   511
by (asm_simp_tac (simpset() addsimps [finite_imageI,card_insert_if]) 1);
nipkow@5626
   512
qed "card_image_le";
nipkow@5626
   513
nipkow@5626
   514
Goal "finite(A) ==> inj_on f A --> card (f `` A) = card A";
nipkow@5626
   515
by (etac finite_induct 1);
nipkow@5626
   516
by (ALLGOALS Asm_simp_tac);
nipkow@5626
   517
by Safe_tac;
nipkow@5626
   518
by (rewtac inj_on_def);
nipkow@5626
   519
by (Blast_tac 1);
nipkow@5626
   520
by (stac card_insert_disjoint 1);
nipkow@5626
   521
by (etac finite_imageI 1);
nipkow@5626
   522
by (Blast_tac 1);
nipkow@5626
   523
by (Blast_tac 1);
nipkow@5626
   524
qed_spec_mp "card_image";
nipkow@5626
   525
nipkow@5626
   526
Goal "[| finite A; f``A <= A; inj_on f A |] ==> f``A = A";
nipkow@5626
   527
by (REPEAT (ares_tac [card_seteq,card_image] 1));
nipkow@5626
   528
qed "endo_inj_surj";
nipkow@5626
   529
nipkow@5626
   530
(*** Cardinality of the Powerset ***)
nipkow@5626
   531
nipkow@5626
   532
Goal "finite A ==> card (Pow A) = 2 ^ card A";
nipkow@5626
   533
by (etac finite_induct 1);
nipkow@5626
   534
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Pow_insert])));
nipkow@5626
   535
by (stac card_Un_disjoint 1);
nipkow@5626
   536
by (EVERY (map (blast_tac (claset() addIs [finite_imageI])) [3,2,1]));
nipkow@5626
   537
by (subgoal_tac "inj_on (insert x) (Pow F)" 1);
nipkow@5626
   538
by (asm_simp_tac (simpset() addsimps [card_image, Pow_insert]) 1);
nipkow@5626
   539
by (rewtac inj_on_def);
nipkow@5626
   540
by (blast_tac (claset() addSEs [equalityE]) 1);
nipkow@5626
   541
qed "card_Pow";
nipkow@5626
   542
Addsimps [card_Pow];
nipkow@5626
   543
paulson@3368
   544
wenzelm@3430
   545
(*Relates to equivalence classes.   Based on a theorem of F. Kammueller's.
paulson@3368
   546
  The "finite C" premise is redundant*)
paulson@5143
   547
Goal "finite C ==> finite (Union C) --> \
paulson@3368
   548
\          (! c : C. k dvd card c) -->  \
paulson@3368
   549
\          (! c1: C. ! c2: C. c1 ~= c2 --> c1 Int c2 = {}) \
paulson@3368
   550
\          --> k dvd card(Union C)";
paulson@3368
   551
by (etac finite_induct 1);
paulson@3368
   552
by (ALLGOALS Asm_simp_tac);
paulson@3708
   553
by (Clarify_tac 1);
paulson@3368
   554
by (stac card_Un_disjoint 1);
paulson@3368
   555
by (ALLGOALS
wenzelm@4089
   556
    (asm_full_simp_tac (simpset()
paulson@3368
   557
			 addsimps [dvd_add, disjoint_eq_subset_Compl])));
paulson@3368
   558
by (thin_tac "!c:F. ?PP(c)" 1);
paulson@3368
   559
by (thin_tac "!c:F. ?PP(c) & ?QQ(c)" 1);
paulson@3708
   560
by (Clarify_tac 1);
paulson@3368
   561
by (ball_tac 1);
paulson@3368
   562
by (Blast_tac 1);
paulson@3368
   563
qed_spec_mp "dvd_partition";
paulson@3368
   564
nipkow@5616
   565
nipkow@5616
   566
(*** foldSet ***)
nipkow@5616
   567
nipkow@5616
   568
val empty_foldSetE = foldSet.mk_cases [] "({}, x) : foldSet f e";
nipkow@5616
   569
nipkow@5616
   570
AddSEs [empty_foldSetE];
nipkow@5616
   571
AddIs foldSet.intrs;
nipkow@5616
   572
nipkow@5616
   573
Goal "[| (A-{x},y) : foldSet f e;  x: A |] ==> (A, f x y) : foldSet f e";
nipkow@5616
   574
by (etac (insert_Diff RS subst) 1 THEN resolve_tac foldSet.intrs 1);
nipkow@5616
   575
by Auto_tac;
nipkow@5626
   576
qed "Diff1_foldSet";
nipkow@5616
   577
nipkow@5616
   578
Goal "(A, x) : foldSet f e ==> finite(A)";
nipkow@5616
   579
by (eresolve_tac [foldSet.induct] 1);
nipkow@5616
   580
by Auto_tac;
nipkow@5616
   581
qed "foldSet_imp_finite";
nipkow@5616
   582
nipkow@5616
   583
Addsimps [foldSet_imp_finite];
nipkow@5616
   584
nipkow@5616
   585
nipkow@5616
   586
Goal "finite(A) ==> EX x. (A, x) : foldSet f e";
nipkow@5616
   587
by (etac finite_induct 1);
nipkow@5616
   588
by Auto_tac;
nipkow@5616
   589
qed "finite_imp_foldSet";
nipkow@5616
   590
nipkow@5616
   591
nipkow@5616
   592
Open_locale "LC"; 
nipkow@5616
   593
nipkow@5616
   594
(*Strip meta-quantifiers: perhaps the locale should do this?*)
nipkow@5616
   595
val f_lcomm = forall_elim_vars 0 (thm "lcomm");
nipkow@5616
   596
nipkow@5616
   597
nipkow@5616
   598
Goal "ALL A x. card(A) < n --> (A, x) : foldSet f e --> \
nipkow@5616
   599
\            (ALL y. (A, y) : foldSet f e --> y=x)";
nipkow@5616
   600
by (induct_tac "n" 1);
nipkow@5616
   601
by (auto_tac (claset(), simpset() addsimps [less_Suc_eq]));
nipkow@5616
   602
by (etac foldSet.elim 1);
nipkow@5616
   603
by (Blast_tac 1);
nipkow@5616
   604
by (etac foldSet.elim 1);
nipkow@5616
   605
by (Blast_tac 1);
nipkow@5616
   606
by (Clarify_tac 1);
nipkow@5616
   607
(*force simplification of "card A < card (insert ...)"*)
nipkow@5616
   608
by (etac rev_mp 1);
nipkow@5616
   609
by (asm_simp_tac (simpset() addsimps [less_Suc_eq_le]) 1);
nipkow@5616
   610
by (rtac impI 1);
nipkow@5616
   611
(** LEVEL 10 **)
nipkow@5616
   612
by (rename_tac "Aa xa ya Ab xb yb" 1);
nipkow@5616
   613
 by (case_tac "xa=xb" 1);
nipkow@5616
   614
 by (subgoal_tac "Aa = Ab" 1);
nipkow@5616
   615
 by (blast_tac (claset() addEs [equalityE]) 2);
nipkow@5616
   616
 by (Blast_tac 1);
nipkow@5616
   617
(*case xa ~= xb*)
nipkow@5616
   618
by (subgoal_tac "Aa-{xb} = Ab-{xa} & xb : Aa & xa : Ab" 1);
nipkow@5616
   619
 by (blast_tac (claset() addEs [equalityE]) 2);
nipkow@5616
   620
by (Clarify_tac 1);
nipkow@5616
   621
by (subgoal_tac "Aa = insert xb Ab - {xa}" 1);
nipkow@5616
   622
 by (blast_tac (claset() addEs [equalityE]) 2);
nipkow@5616
   623
(** LEVEL 20 **)
nipkow@5616
   624
by (subgoal_tac "card Aa <= card Ab" 1);
nipkow@5616
   625
 by (rtac (Suc_le_mono RS subst) 2);
nipkow@5626
   626
 by (asm_simp_tac (simpset() addsimps [card_Suc_Diff1]) 2);
nipkow@5616
   627
by (res_inst_tac [("A1", "Aa-{xb}"), ("f1","f")] 
nipkow@5616
   628
    (finite_imp_foldSet RS exE) 1);
nipkow@5616
   629
by (blast_tac (claset() addIs [foldSet_imp_finite, finite_Diff]) 1);
nipkow@5626
   630
by (forward_tac [Diff1_foldSet] 1 THEN assume_tac 1);
nipkow@5616
   631
by (subgoal_tac "ya = f xb x" 1);
nipkow@5616
   632
 by (Blast_tac 2);
nipkow@5616
   633
by (subgoal_tac "(Ab - {xa}, x) : foldSet f e" 1);
nipkow@5616
   634
 by (Asm_full_simp_tac 2);
nipkow@5616
   635
by (subgoal_tac "yb = f xa x" 1);
nipkow@5626
   636
 by (blast_tac (claset() addDs [Diff1_foldSet]) 2);
nipkow@5616
   637
by (asm_simp_tac (simpset() addsimps [f_lcomm]) 1);
nipkow@5616
   638
val lemma = result();
nipkow@5616
   639
nipkow@5616
   640
nipkow@5616
   641
Goal "[| (A, x) : foldSet f e;  (A, y) : foldSet f e |] ==> y=x";
nipkow@5616
   642
by (blast_tac (claset() addIs [normalize_thm [RSspec, RSmp] lemma]) 1);
nipkow@5616
   643
qed "foldSet_determ";
nipkow@5616
   644
nipkow@5616
   645
Goalw [fold_def] "(A,y) : foldSet f e ==> fold f e A = y";
nipkow@5616
   646
by (blast_tac (claset() addIs [foldSet_determ]) 1);
nipkow@5616
   647
qed "fold_equality";
nipkow@5616
   648
nipkow@5616
   649
Goalw [fold_def] "fold f e {} = e";
nipkow@5616
   650
by (Blast_tac 1);
nipkow@5616
   651
qed "fold_empty";
nipkow@5616
   652
Addsimps [fold_empty];
nipkow@5616
   653
nipkow@5626
   654
nipkow@5616
   655
Goal "x ~: A ==> \
nipkow@5616
   656
\     ((insert x A, v) : foldSet f e) =  \
nipkow@5616
   657
\     (EX y. (A, y) : foldSet f e & v = f x y)";
nipkow@5616
   658
by Auto_tac;
nipkow@5616
   659
by (res_inst_tac [("A1", "A"), ("f1","f")] (finite_imp_foldSet RS exE) 1);
nipkow@5616
   660
by (force_tac (claset() addDs [foldSet_imp_finite], simpset()) 1);
nipkow@5616
   661
by (blast_tac (claset() addIs [foldSet_determ]) 1);
nipkow@5616
   662
val lemma = result();
nipkow@5616
   663
nipkow@5616
   664
Goalw [fold_def]
nipkow@5616
   665
     "[| finite A; x ~: A |] ==> fold f e (insert x A) = f x (fold f e A)";
nipkow@5616
   666
by (asm_simp_tac (simpset() addsimps [lemma]) 1);
nipkow@5616
   667
by (rtac select_equality 1);
nipkow@5616
   668
by (auto_tac (claset() addIs [finite_imp_foldSet],
nipkow@5616
   669
	      simpset() addcongs [conj_cong]
nipkow@5616
   670
		        addsimps [symmetric fold_def,
nipkow@5616
   671
				  fold_equality]));
nipkow@5616
   672
qed "fold_insert";
nipkow@5616
   673
nipkow@5626
   674
(* Delete rules to do with foldSet relation: obsolete *)
nipkow@5626
   675
Delsimps [foldSet_imp_finite];
nipkow@5626
   676
Delrules [empty_foldSetE];
nipkow@5626
   677
Delrules foldSet.intrs;
nipkow@5626
   678
nipkow@5616
   679
Close_locale();
nipkow@5616
   680
nipkow@5616
   681
Open_locale "ACe"; 
nipkow@5616
   682
nipkow@5616
   683
(*Strip meta-quantifiers: perhaps the locale should do this?*)
nipkow@5616
   684
val f_ident   = forall_elim_vars 0 (thm "ident");
nipkow@5616
   685
val f_commute = forall_elim_vars 0 (thm "commute");
nipkow@5616
   686
val f_assoc   = forall_elim_vars 0 (thm "assoc");
nipkow@5616
   687
nipkow@5616
   688
nipkow@5616
   689
Goal "f x (f y z) = f y (f x z)";
nipkow@5616
   690
by (rtac (f_commute RS trans) 1);
nipkow@5616
   691
by (rtac (f_assoc RS trans) 1);
nipkow@5616
   692
by (rtac (f_commute RS arg_cong) 1);
nipkow@5616
   693
qed "f_left_commute";
nipkow@5616
   694
nipkow@5616
   695
val f_ac = [f_assoc, f_commute, f_left_commute];
nipkow@5616
   696
nipkow@5616
   697
Goal "f e x = x";
nipkow@5616
   698
by (stac f_commute 1);
nipkow@5616
   699
by (rtac f_ident 1);
nipkow@5616
   700
qed "f_left_ident";
nipkow@5616
   701
nipkow@5616
   702
val f_idents = [f_left_ident, f_ident];
nipkow@5616
   703
nipkow@5616
   704
Goal "[| finite A; finite B |] \
nipkow@5616
   705
\     ==> f (fold f e A) (fold f e B) =  \
nipkow@5616
   706
\         f (fold f e (A Un B)) (fold f e (A Int B))";
nipkow@5616
   707
by (etac finite_induct 1);
nipkow@5616
   708
by (simp_tac (simpset() addsimps f_idents) 1);
nipkow@5616
   709
by (asm_simp_tac (simpset() addsimps f_ac @ f_idents @
nipkow@5616
   710
           [export fold_insert,insert_absorb, Int_insert_left]) 1);
nipkow@5616
   711
qed "fold_Un_Int";
nipkow@5616
   712
nipkow@5616
   713
Goal "[| finite A; finite B; A Int B = {} |] \
nipkow@5616
   714
\     ==> fold f e (A Un B) = f (fold f e A) (fold f e B)";
nipkow@5616
   715
by (asm_simp_tac (simpset() addsimps fold_Un_Int::f_idents) 1);
nipkow@5616
   716
qed "fold_Un_disjoint";
nipkow@5616
   717
nipkow@5616
   718
Goal
nipkow@5616
   719
 "[| finite A; finite B |] ==> A Int B = {} --> \
nipkow@5616
   720
\ fold (f o g) e (A Un B) = f (fold (f o g) e A) (fold (f o g) e B)";
nipkow@5616
   721
by (etac finite_induct 1);
nipkow@5616
   722
by (simp_tac (simpset() addsimps f_idents) 1);
nipkow@5616
   723
by (asm_full_simp_tac (simpset() addsimps f_ac @ f_idents @
nipkow@5616
   724
           [export fold_insert,insert_absorb, Int_insert_left]) 1);
nipkow@5616
   725
qed "fold_Un_disjoint2";
nipkow@5616
   726
nipkow@5616
   727
Close_locale();
nipkow@5616
   728
nipkow@5616
   729
Delrules ([empty_foldSetE] @ foldSet.intrs);
nipkow@5616
   730
Delsimps [foldSet_imp_finite];
nipkow@5616
   731
nipkow@5616
   732
(*** setsum ***)
nipkow@5616
   733
nipkow@5616
   734
Goalw [setsum_def] "setsum f {} = 0";
nipkow@5616
   735
by(Simp_tac 1);
nipkow@5616
   736
qed "setsum_empty";
nipkow@5616
   737
Addsimps [setsum_empty];
nipkow@5616
   738
nipkow@5616
   739
Goalw [setsum_def]
nipkow@5616
   740
 "[| finite F; a ~: F |] ==> setsum f (insert a F) = f(a) + setsum f F";
nipkow@5616
   741
by(asm_simp_tac (simpset() addsimps [export fold_insert]) 1);
nipkow@5616
   742
qed "setsum_insert";
nipkow@5616
   743
Addsimps [setsum_insert];
nipkow@5616
   744
nipkow@5616
   745
Goalw [setsum_def]
nipkow@5616
   746
 "[| finite A; finite B; A Int B = {} |] ==> \
nipkow@5616
   747
\ setsum f (A Un B) = setsum f A + setsum f B";
nipkow@5616
   748
by(asm_simp_tac (simpset() addsimps [export fold_Un_disjoint2]) 1);
nipkow@5616
   749
qed_spec_mp "setsum_disj_Un";
nipkow@5616
   750
nipkow@5616
   751
Goal "[| finite F |] ==> \
nipkow@5616
   752
\     setsum f (F-{a}) = (if a:F then setsum f F - f a else setsum f F)";
nipkow@5616
   753
be finite_induct 1;
nipkow@5616
   754
by(auto_tac (claset(), simpset() addsimps [insert_Diff_if]));
nipkow@5616
   755
by(dres_inst_tac [("a","a")] mk_disjoint_insert 1);
nipkow@5616
   756
by(Auto_tac);
nipkow@5616
   757
qed_spec_mp "setsum_diff1";