src/HOL/Finite.ML
author berghofe
Tue, 30 May 2000 18:02:49 +0200
changeset 9001 93af64f54bf2
parent 8981 fe1f3d52e027
child 9002 a752f2499dae
permissions -rw-r--r--
the is now defined using primrec, avoiding explicit use of arbitrary.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
     1
(*  Title:      HOL/Finite.thy
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
     3
    Author:     Lawrence C Paulson & Tobias Nipkow
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
     4
    Copyright   1995  University of Cambridge & TU Muenchen
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
     6
Finite sets and their cardinality
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
     9
section "finite";
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    10
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
(*Discharging ~ x:y entails extra work*)
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5278
diff changeset
    12
val major::prems = Goal 
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    13
    "[| finite F;  P({}); \
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    14
\       !!F x. [| finite F;  x ~: F;  P(F) |] ==> P(insert x F) \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
\    |] ==> P(F)";
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    16
by (rtac (major RS Finites.induct) 1);
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    17
by (excluded_middle_tac "a:A" 2);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
by (etac (insert_absorb RS ssubst) 3 THEN assume_tac 3);   (*backtracking!*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
by (REPEAT (ares_tac prems 1));
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    20
qed "finite_induct";
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    21
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5278
diff changeset
    22
val major::subs::prems = Goal 
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    23
    "[| finite F;  F <= A; \
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    24
\       P({}); \
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    25
\       !!F a. [| finite F; a:A; a ~: F;  P(F) |] ==> P(insert a F) \
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    26
\    |] ==> P(F)";
4386
b3cff8adc213 Tidied proof of finite_subset_induct
paulson
parents: 4304
diff changeset
    27
by (rtac (subs RS rev_mp) 1);
b3cff8adc213 Tidied proof of finite_subset_induct
paulson
parents: 4304
diff changeset
    28
by (rtac (major RS finite_induct) 1);
b3cff8adc213 Tidied proof of finite_subset_induct
paulson
parents: 4304
diff changeset
    29
by (ALLGOALS (blast_tac (claset() addIs prems)));
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    30
qed "finite_subset_induct";
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    31
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    32
Addsimps Finites.intrs;
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    33
AddSIs Finites.intrs;
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
(*The union of two finite sets is finite*)
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5278
diff changeset
    36
Goal "[| finite F;  finite G |] ==> finite(F Un G)";
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5278
diff changeset
    37
by (etac finite_induct 1);
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5278
diff changeset
    38
by (ALLGOALS Asm_simp_tac);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    39
qed "finite_UnI";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
(*Every subset of a finite set is finite*)
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5069
diff changeset
    42
Goal "finite B ==> ALL A. A<=B --> finite A";
4304
af2a2cd9fa51 Tidying
paulson
parents: 4153
diff changeset
    43
by (etac finite_induct 1);
af2a2cd9fa51 Tidying
paulson
parents: 4153
diff changeset
    44
by (Simp_tac 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
    45
by (safe_tac (claset() addSDs [subset_insert_iff RS iffD1]));
4304
af2a2cd9fa51 Tidying
paulson
parents: 4153
diff changeset
    46
by (eres_inst_tac [("t","A")] (insert_Diff RS subst) 2);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 923
diff changeset
    47
by (ALLGOALS Asm_simp_tac);
4304
af2a2cd9fa51 Tidying
paulson
parents: 4153
diff changeset
    48
val lemma = result();
af2a2cd9fa51 Tidying
paulson
parents: 4153
diff changeset
    49
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5069
diff changeset
    50
Goal "[| A<=B;  finite B |] ==> finite A";
4423
a129b817b58a expandshort;
wenzelm
parents: 4386
diff changeset
    51
by (dtac lemma 1);
4304
af2a2cd9fa51 Tidying
paulson
parents: 4153
diff changeset
    52
by (Blast_tac 1);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    53
qed "finite_subset";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    55
Goal "finite(F Un G) = (finite F & finite G)";
4304
af2a2cd9fa51 Tidying
paulson
parents: 4153
diff changeset
    56
by (blast_tac (claset() 
8554
ba33995b87ff combined finite_Int1/2 as finite_Int. Deleted the awful "lemma" from the
paulson
parents: 8442
diff changeset
    57
	         addIs [inst "B" "?X Un ?Y" finite_subset, finite_UnI]) 1);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    58
qed "finite_Un";
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    59
AddIffs[finite_Un];
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    60
8554
ba33995b87ff combined finite_Int1/2 as finite_Int. Deleted the awful "lemma" from the
paulson
parents: 8442
diff changeset
    61
(*The converse obviously fails*)
ba33995b87ff combined finite_Int1/2 as finite_Int. Deleted the awful "lemma" from the
paulson
parents: 8442
diff changeset
    62
Goal "finite F | finite G ==> finite(F Int G)";
5413
9d11f2d39b13 New lemmas involving Int
paulson
parents: 5316
diff changeset
    63
by (blast_tac (claset() addIs [finite_subset]) 1);
8554
ba33995b87ff combined finite_Int1/2 as finite_Int. Deleted the awful "lemma" from the
paulson
parents: 8442
diff changeset
    64
qed "finite_Int";
5413
9d11f2d39b13 New lemmas involving Int
paulson
parents: 5316
diff changeset
    65
8554
ba33995b87ff combined finite_Int1/2 as finite_Int. Deleted the awful "lemma" from the
paulson
parents: 8442
diff changeset
    66
Addsimps [finite_Int];
ba33995b87ff combined finite_Int1/2 as finite_Int. Deleted the awful "lemma" from the
paulson
parents: 8442
diff changeset
    67
AddIs [finite_Int];
5413
9d11f2d39b13 New lemmas involving Int
paulson
parents: 5316
diff changeset
    68
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
    69
Goal "finite(insert a A) = finite A";
1553
4eb4a9c7d736 Ran expandshort
paulson
parents: 1548
diff changeset
    70
by (stac insert_is_Un 1);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    71
by (simp_tac (HOL_ss addsimps [finite_Un]) 1);
3427
e7cef2081106 Removed a few redundant additions of simprules or classical rules
paulson
parents: 3416
diff changeset
    72
by (Blast_tac 1);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    73
qed "finite_insert";
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    74
Addsimps[finite_insert];
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    75
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    76
(*The image of a finite set is finite *)
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5069
diff changeset
    77
Goal  "finite F ==> finite(h``F)";
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    78
by (etac finite_induct 1);
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 923
diff changeset
    79
by (Simp_tac 1);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    80
by (Asm_simp_tac 1);
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    81
qed "finite_imageI";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    82
8155
649c46adfccc added finite_range_imageI
oheimb
parents: 8140
diff changeset
    83
Goal "finite (range g) ==> finite (range (%x. f (g x)))";
649c46adfccc added finite_range_imageI
oheimb
parents: 8140
diff changeset
    84
by (Simp_tac 1);
649c46adfccc added finite_range_imageI
oheimb
parents: 8140
diff changeset
    85
by (etac finite_imageI 1);
649c46adfccc added finite_range_imageI
oheimb
parents: 8140
diff changeset
    86
qed "finite_range_imageI";
649c46adfccc added finite_range_imageI
oheimb
parents: 8140
diff changeset
    87
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5278
diff changeset
    88
val major::prems = Goal 
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    89
    "[| finite c;  finite b;                                  \
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1264
diff changeset
    90
\       P(b);                                                   \
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    91
\       !!x y. [| finite y;  x:y;  P(y) |] ==> P(y-{x}) \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    92
\    |] ==> c<=b --> P(b-c)";
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
    93
by (rtac (major RS finite_induct) 1);
2031
03a843f0f447 Ran expandshort
paulson
parents: 1786
diff changeset
    94
by (stac Diff_insert 2);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    95
by (ALLGOALS (asm_simp_tac
5537
c2bd39a2c0ee deleted needless parentheses
paulson
parents: 5516
diff changeset
    96
                (simpset() addsimps prems@[Diff_subset RS finite_subset])));
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
    97
val lemma = result();
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    98
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5278
diff changeset
    99
val prems = Goal 
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
   100
    "[| finite A;                                       \
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
   101
\       P(A);                                           \
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
   102
\       !!a A. [| finite A;  a:A;  P(A) |] ==> P(A-{a}) \
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   103
\    |] ==> P({})";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   104
by (rtac (Diff_cancel RS subst) 1);
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   105
by (rtac (lemma RS mp) 1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   106
by (REPEAT (ares_tac (subset_refl::prems) 1));
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
   107
qed "finite_empty_induct";
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   108
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   109
1618
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1553
diff changeset
   110
(* finite B ==> finite (B - Ba) *)
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1553
diff changeset
   111
bind_thm ("finite_Diff", Diff_subset RS finite_subset);
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   112
Addsimps [finite_Diff];
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   113
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   114
Goal "finite(A - insert a B) = finite(A-B)";
6162
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   115
by (stac Diff_insert 1);
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   116
by (case_tac "a : A-B" 1);
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   117
by (rtac (finite_insert RS sym RS trans) 1);
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   118
by (stac insert_Diff 1);
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   119
by (ALLGOALS Asm_full_simp_tac);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   120
qed "finite_Diff_insert";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   121
AddIffs [finite_Diff_insert];
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   122
8554
ba33995b87ff combined finite_Int1/2 as finite_Int. Deleted the awful "lemma" from the
paulson
parents: 8442
diff changeset
   123
(*lemma merely for classical reasoner in the proof below: force_tac can't
ba33995b87ff combined finite_Int1/2 as finite_Int. Deleted the awful "lemma" from the
paulson
parents: 8442
diff changeset
   124
  prove it.*)
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   125
Goal "finite(A-{}) = finite A";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   126
by (Simp_tac 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   127
val lemma = result();
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   128
4059
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 4014
diff changeset
   129
(*Lemma for proving finite_imageD*)
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5069
diff changeset
   130
Goal "finite B ==> !A. f``A = B --> inj_on f A --> finite A";
1553
4eb4a9c7d736 Ran expandshort
paulson
parents: 1548
diff changeset
   131
by (etac finite_induct 1);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
   132
 by (ALLGOALS Asm_simp_tac);
3708
56facaebf3e3 Changed some proofs to use Clarify_tac
paulson
parents: 3517
diff changeset
   133
by (Clarify_tac 1);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
   134
by (subgoal_tac "EX y:A. f y = x & F = f``(A-{y})" 1);
3708
56facaebf3e3 Changed some proofs to use Clarify_tac
paulson
parents: 3517
diff changeset
   135
 by (Clarify_tac 1);
8081
1c8de414b45d removed inj_eq from the default simpset again
oheimb
parents: 7958
diff changeset
   136
 by (full_simp_tac (simpset() addsimps [inj_on_def]) 1);
8554
ba33995b87ff combined finite_Int1/2 as finite_Int. Deleted the awful "lemma" from the
paulson
parents: 8442
diff changeset
   137
 by (blast_tac (claset() addSDs [lemma RS iffD1]) 1);
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   138
by (thin_tac "ALL A. ?PP(A)" 1);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
   139
by (forward_tac [[equalityD2, insertI1] MRS subsetD] 1);
3708
56facaebf3e3 Changed some proofs to use Clarify_tac
paulson
parents: 3517
diff changeset
   140
by (Clarify_tac 1);
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   141
by (res_inst_tac [("x","xa")] bexI 1);
4059
59c1422c9da5 New Blast_tac (and minor tidying...)
paulson
parents: 4014
diff changeset
   142
by (ALLGOALS 
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4775
diff changeset
   143
    (asm_full_simp_tac (simpset() addsimps [inj_on_image_set_diff])));
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   144
val lemma = result();
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   145
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5069
diff changeset
   146
Goal "[| finite(f``A);  inj_on f A |] ==> finite A";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   147
by (dtac lemma 1);
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   148
by (Blast_tac 1);
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   149
qed "finite_imageD";
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   150
4014
df6cd80b6387 Added finite_UNION/SigmaI.
nipkow
parents: 3919
diff changeset
   151
(** The finite UNION of finite sets **)
df6cd80b6387 Added finite_UNION/SigmaI.
nipkow
parents: 3919
diff changeset
   152
5316
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5278
diff changeset
   153
Goal "finite A ==> (!a:A. finite(B a)) --> finite(UN a:A. B a)";
7a8975451a89 even more tidying of Goal commands
paulson
parents: 5278
diff changeset
   154
by (etac finite_induct 1);
4153
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4089
diff changeset
   155
by (ALLGOALS Asm_simp_tac);
4014
df6cd80b6387 Added finite_UNION/SigmaI.
nipkow
parents: 3919
diff changeset
   156
bind_thm("finite_UnionI", ballI RSN (2, result() RS mp));
df6cd80b6387 Added finite_UNION/SigmaI.
nipkow
parents: 3919
diff changeset
   157
Addsimps [finite_UnionI];
df6cd80b6387 Added finite_UNION/SigmaI.
nipkow
parents: 3919
diff changeset
   158
df6cd80b6387 Added finite_UNION/SigmaI.
nipkow
parents: 3919
diff changeset
   159
(** Sigma of finite sets **)
df6cd80b6387 Added finite_UNION/SigmaI.
nipkow
parents: 3919
diff changeset
   160
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   161
Goalw [Sigma_def]
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5143
diff changeset
   162
 "[| finite A; !a:A. finite(B a) |] ==> finite(SIGMA a:A. B a)";
4153
e534c4c32d54 Ran expandshort, especially to introduce Safe_tac
paulson
parents: 4089
diff changeset
   163
by (blast_tac (claset() addSIs [finite_UnionI]) 1);
4014
df6cd80b6387 Added finite_UNION/SigmaI.
nipkow
parents: 3919
diff changeset
   164
bind_thm("finite_SigmaI", ballI RSN (2,result()));
df6cd80b6387 Added finite_UNION/SigmaI.
nipkow
parents: 3919
diff changeset
   165
Addsimps [finite_SigmaI];
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   166
8262
08ad0a986db2 added instance declaration for finite product
oheimb
parents: 8155
diff changeset
   167
Goal "[| finite (UNIV::'a set); finite (UNIV::'b set)|] ==> finite (UNIV::('a * 'b) set)"; 
08ad0a986db2 added instance declaration for finite product
oheimb
parents: 8155
diff changeset
   168
by (subgoal_tac "(UNIV::('a * 'b) set) = Sigma UNIV (%x. UNIV)" 1);
08ad0a986db2 added instance declaration for finite product
oheimb
parents: 8155
diff changeset
   169
by  (etac ssubst 1);
08ad0a986db2 added instance declaration for finite product
oheimb
parents: 8155
diff changeset
   170
by  (etac finite_SigmaI 1);
08ad0a986db2 added instance declaration for finite product
oheimb
parents: 8155
diff changeset
   171
by  Auto_tac;
08ad0a986db2 added instance declaration for finite product
oheimb
parents: 8155
diff changeset
   172
qed "finite_Prod_UNIV";
08ad0a986db2 added instance declaration for finite product
oheimb
parents: 8155
diff changeset
   173
08ad0a986db2 added instance declaration for finite product
oheimb
parents: 8155
diff changeset
   174
Goal "finite (UNIV :: ('a::finite * 'b::finite) set)";
8320
073144bed7da expandshort
paulson
parents: 8262
diff changeset
   175
by (rtac (finite_Prod_UNIV) 1);
073144bed7da expandshort
paulson
parents: 8262
diff changeset
   176
by (rtac finite 1);
073144bed7da expandshort
paulson
parents: 8262
diff changeset
   177
by (rtac finite 1);
8262
08ad0a986db2 added instance declaration for finite product
oheimb
parents: 8155
diff changeset
   178
qed "finite_Prod";
08ad0a986db2 added instance declaration for finite product
oheimb
parents: 8155
diff changeset
   179
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   180
(** The powerset of a finite set **)
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   181
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5069
diff changeset
   182
Goal "finite(Pow A) ==> finite A";
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   183
by (subgoal_tac "finite ((%x.{x})``A)" 1);
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   184
by (rtac finite_subset 2);
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   185
by (assume_tac 3);
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   186
by (ALLGOALS
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4775
diff changeset
   187
    (fast_tac (claset() addSDs [rewrite_rule [inj_on_def] finite_imageD])));
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   188
val lemma = result();
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   189
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   190
Goal "finite(Pow A) = finite A";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   191
by (rtac iffI 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   192
by (etac lemma 1);
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   193
(*Opposite inclusion: finite A ==> finite (Pow A) *)
3340
a886795c9dce Two results suggested by Florian Kammueller
paulson
parents: 3222
diff changeset
   194
by (etac finite_induct 1);
a886795c9dce Two results suggested by Florian Kammueller
paulson
parents: 3222
diff changeset
   195
by (ALLGOALS 
a886795c9dce Two results suggested by Florian Kammueller
paulson
parents: 3222
diff changeset
   196
    (asm_simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   197
     (simpset() addsimps [finite_UnI, finite_imageI, Pow_insert])));
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   198
qed "finite_Pow_iff";
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   199
AddIffs [finite_Pow_iff];
3340
a886795c9dce Two results suggested by Florian Kammueller
paulson
parents: 3222
diff changeset
   200
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4830
diff changeset
   201
Goal "finite(r^-1) = finite r";
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   202
by (subgoal_tac "r^-1 = (%(x,y).(y,x))``r" 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   203
 by (Asm_simp_tac 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   204
 by (rtac iffI 1);
4830
bd73675adbed Added a few lemmas.
nipkow
parents: 4775
diff changeset
   205
  by (etac (rewrite_rule [inj_on_def] finite_imageD) 1);
bd73675adbed Added a few lemmas.
nipkow
parents: 4775
diff changeset
   206
  by (simp_tac (simpset() addsplits [split_split]) 1);
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   207
 by (etac finite_imageI 1);
4746
a5dcd7e4a37d inverse -> converse
paulson
parents: 4686
diff changeset
   208
by (simp_tac (simpset() addsimps [converse_def,image_def]) 1);
4477
b3e5857d8d99 New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents: 4423
diff changeset
   209
by Auto_tac;
5516
d80e9aeb4a2b added indentation
oheimb
parents: 5477
diff changeset
   210
by (rtac bexI 1);
d80e9aeb4a2b added indentation
oheimb
parents: 5477
diff changeset
   211
by  (assume_tac 2);
4763
56072b72d730 adapted proof of finite_converse
oheimb
parents: 4746
diff changeset
   212
by (Simp_tac 1);
4746
a5dcd7e4a37d inverse -> converse
paulson
parents: 4686
diff changeset
   213
qed "finite_converse";
a5dcd7e4a37d inverse -> converse
paulson
parents: 4686
diff changeset
   214
AddIffs [finite_converse];
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   215
8963
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   216
Goal "finite (lessThan (k::nat))";
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   217
by (induct_tac "k" 1);
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   218
by (simp_tac (simpset() addsimps [lessThan_Suc]) 2);
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   219
by Auto_tac;
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   220
qed "finite_lessThan";
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   221
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   222
Goal "finite (atMost (k::nat))";
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   223
by (induct_tac "k" 1);
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   224
by (simp_tac (simpset() addsimps [atMost_Suc]) 2);
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   225
by Auto_tac;
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   226
qed "finite_atMost";
8971
881853835a37 new default rules
paulson
parents: 8963
diff changeset
   227
AddIffs [finite_lessThan, finite_atMost];
8963
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   228
8889
2ec6371fde54 added lemma.
nipkow
parents: 8789
diff changeset
   229
(* A bounded set of natural numbers is finite *)
8963
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   230
Goal "(!i:N. i<(n::nat)) ==> finite N";
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   231
by (rtac finite_subset 1);
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   232
 by (rtac finite_lessThan 2);
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   233
by Auto_tac;
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   234
qed "bounded_nat_set_is_finite";
8889
2ec6371fde54 added lemma.
nipkow
parents: 8789
diff changeset
   235
2ec6371fde54 added lemma.
nipkow
parents: 8789
diff changeset
   236
1548
afe750876848 Added 'section' commands
nipkow
parents: 1531
diff changeset
   237
section "Finite cardinality -- 'card'";
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   238
8981
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   239
val cardR_emptyE = cardR.mk_cases "({},n) : cardR";
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   240
val cardR_insertE = cardR.mk_cases "(insert a A,n) : cardR";
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   241
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   242
AddSEs [cardR_emptyE];
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   243
AddSIs cardR.intrs;
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   244
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   245
Goal "[| (A,n) : cardR |] ==> a : A --> (? m. n = Suc m)";
6162
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   246
by (etac cardR.induct 1);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   247
 by (Blast_tac 1);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   248
by (Blast_tac 1);
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   249
qed "cardR_SucD";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   250
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   251
Goal "(A,m): cardR ==> (!n a. m = Suc n --> a:A --> (A-{a},n) : cardR)";
6162
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   252
by (etac cardR.induct 1);
8911
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   253
 by Auto_tac;
6162
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   254
by (asm_simp_tac (simpset() addsimps [insert_Diff_if]) 1);
8911
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   255
by Auto_tac;
7499
23e090051cb8 isatool expandshort;
wenzelm
parents: 7497
diff changeset
   256
by (ftac cardR_SucD 1);
6162
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   257
by (Blast_tac 1);
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   258
val lemma = result();
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   259
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   260
Goal "[| (insert a A, Suc m) : cardR; a ~: A |] ==> (A,m) : cardR";
6162
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   261
by (dtac lemma 1);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   262
by (Asm_full_simp_tac 1);
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   263
val lemma = result();
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   264
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   265
Goal "(A,m): cardR ==> (!n. (A,n) : cardR --> n=m)";
6162
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   266
by (etac cardR.induct 1);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   267
 by (safe_tac (claset() addSEs [cardR_insertE]));
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   268
by (rename_tac "B b m" 1);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   269
by (case_tac "a = b" 1);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   270
 by (subgoal_tac "A = B" 1);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   271
  by (blast_tac (claset() addEs [equalityE]) 2);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   272
 by (Blast_tac 1);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   273
by (subgoal_tac "? C. A = insert b C & B = insert a C" 1);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   274
 by (res_inst_tac [("x","A Int B")] exI 2);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   275
 by (blast_tac (claset() addEs [equalityE]) 2);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   276
by (forw_inst_tac [("A","B")] cardR_SucD 1);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   277
by (blast_tac (claset() addDs [lemma]) 1);
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   278
qed_spec_mp "cardR_determ";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   279
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   280
Goal "(A,n) : cardR ==> finite(A)";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   281
by (etac cardR.induct 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   282
by Auto_tac;
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   283
qed "cardR_imp_finite";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   284
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   285
Goal "finite(A) ==> EX n. (A, n) : cardR";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   286
by (etac finite_induct 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   287
by Auto_tac;
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   288
qed "finite_imp_cardR";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   289
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   290
Goalw [card_def] "(A,n) : cardR ==> card A = n";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   291
by (blast_tac (claset() addIs [cardR_determ]) 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   292
qed "card_equality";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   293
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   294
Goalw [card_def] "card {} = 0";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   295
by (Blast_tac 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   296
qed "card_empty";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   297
Addsimps [card_empty];
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   298
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   299
Goal "x ~: A ==> \
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   300
\     ((insert x A, n) : cardR) =  \
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   301
\     (EX m. (A, m) : cardR & n = Suc m)";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   302
by Auto_tac;
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   303
by (res_inst_tac [("A1", "A")] (finite_imp_cardR RS exE) 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   304
by (force_tac (claset() addDs [cardR_imp_finite], simpset()) 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   305
by (blast_tac (claset() addIs [cardR_determ]) 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   306
val lemma = result();
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   307
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   308
Goalw [card_def]
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   309
     "[| finite A; x ~: A |] ==> card (insert x A) = Suc(card A)";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   310
by (asm_simp_tac (simpset() addsimps [lemma]) 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   311
by (rtac select_equality 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   312
by (auto_tac (claset() addIs [finite_imp_cardR],
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   313
	      simpset() addcongs [conj_cong]
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   314
		        addsimps [symmetric card_def,
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   315
				  card_equality]));
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   316
qed "card_insert_disjoint";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   317
Addsimps [card_insert_disjoint];
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   318
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   319
(* Delete rules to do with cardR relation: obsolete *)
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   320
Delrules [cardR_emptyE];
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   321
Delrules cardR.intrs;
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   322
7958
f531589c9fc1 added various little lemmas
oheimb
parents: 7842
diff changeset
   323
Goal "finite A ==> (card A = 0) = (A = {})";
f531589c9fc1 added various little lemmas
oheimb
parents: 7842
diff changeset
   324
by Auto_tac;
f531589c9fc1 added various little lemmas
oheimb
parents: 7842
diff changeset
   325
by (dres_inst_tac [("a","x")] mk_disjoint_insert 1);
f531589c9fc1 added various little lemmas
oheimb
parents: 7842
diff changeset
   326
by (Clarify_tac 1);
f531589c9fc1 added various little lemmas
oheimb
parents: 7842
diff changeset
   327
by (rotate_tac ~1 1);
f531589c9fc1 added various little lemmas
oheimb
parents: 7842
diff changeset
   328
by Auto_tac;
f531589c9fc1 added various little lemmas
oheimb
parents: 7842
diff changeset
   329
qed "card_0_eq";
f531589c9fc1 added various little lemmas
oheimb
parents: 7842
diff changeset
   330
Addsimps[card_0_eq];
f531589c9fc1 added various little lemmas
oheimb
parents: 7842
diff changeset
   331
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   332
Goal "finite A ==> card(insert x A) = (if x:A then card A else Suc(card(A)))";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   333
by (asm_simp_tac (simpset() addsimps [insert_absorb]) 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   334
qed "card_insert_if";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   335
7821
a8717f53036c new thm card_Diff_singleton; tidied
paulson
parents: 7499
diff changeset
   336
Goal "[| finite A; x: A |] ==> Suc (card (A-{x})) = card A";
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   337
by (res_inst_tac [("t", "A")] (insert_Diff RS subst) 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   338
by (assume_tac 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   339
by (Asm_simp_tac 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   340
qed "card_Suc_Diff1";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   341
7821
a8717f53036c new thm card_Diff_singleton; tidied
paulson
parents: 7499
diff changeset
   342
Goal "[| finite A; x: A |] ==> card (A-{x}) = card A - 1";
a8717f53036c new thm card_Diff_singleton; tidied
paulson
parents: 7499
diff changeset
   343
by (asm_simp_tac (simpset() addsimps [card_Suc_Diff1 RS sym]) 1);
a8717f53036c new thm card_Diff_singleton; tidied
paulson
parents: 7499
diff changeset
   344
qed "card_Diff_singleton";
a8717f53036c new thm card_Diff_singleton; tidied
paulson
parents: 7499
diff changeset
   345
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   346
Goal "finite A ==> card(insert x A) = Suc(card(A-{x}))";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   347
by (asm_simp_tac (simpset() addsimps [card_insert_if,card_Suc_Diff1]) 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   348
qed "card_insert";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   349
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5069
diff changeset
   350
Goal "finite A ==> card A <= card (insert x A)";
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   351
by (asm_simp_tac (simpset() addsimps [card_insert_if]) 1);
4768
c342d63173e9 New theorems card_Diff_le and card_insert_le; tidied
paulson
parents: 4763
diff changeset
   352
qed "card_insert_le";
c342d63173e9 New theorems card_Diff_le and card_insert_le; tidied
paulson
parents: 4763
diff changeset
   353
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5069
diff changeset
   354
Goal  "finite A ==> !B. B <= A --> card(B) <= card(A)";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   355
by (etac finite_induct 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   356
by (Simp_tac 1);
3708
56facaebf3e3 Changed some proofs to use Clarify_tac
paulson
parents: 3517
diff changeset
   357
by (Clarify_tac 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   358
by (case_tac "x:B" 1);
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
   359
 by (dres_inst_tac [("A","B")] mk_disjoint_insert 1);
8741
61bc5ed22b62 removal of less_SucI, le_SucI from default simpset
paulson
parents: 8554
diff changeset
   360
 by (asm_full_simp_tac (simpset() addsimps [le_SucI, subset_insert_iff]) 2);
61bc5ed22b62 removal of less_SucI, le_SucI from default simpset
paulson
parents: 8554
diff changeset
   361
by (force_tac (claset(),
61bc5ed22b62 removal of less_SucI, le_SucI from default simpset
paulson
parents: 8554
diff changeset
   362
	       simpset() addsimps [subset_insert_iff, finite_subset]
61bc5ed22b62 removal of less_SucI, le_SucI from default simpset
paulson
parents: 8554
diff changeset
   363
			 delsimps [insert_subset]) 1);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   364
qed_spec_mp "card_mono";
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   365
5416
9f029e382b5d New law card_Un_Int. Removed card_insert from simpset
paulson
parents: 5413
diff changeset
   366
9f029e382b5d New law card_Un_Int. Removed card_insert from simpset
paulson
parents: 5413
diff changeset
   367
Goal "[| finite A; finite B |] \
9f029e382b5d New law card_Un_Int. Removed card_insert from simpset
paulson
parents: 5413
diff changeset
   368
\     ==> card A + card B = card (A Un B) + card (A Int B)";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   369
by (etac finite_induct 1);
5416
9f029e382b5d New law card_Un_Int. Removed card_insert from simpset
paulson
parents: 5413
diff changeset
   370
by (Simp_tac 1);
9f029e382b5d New law card_Un_Int. Removed card_insert from simpset
paulson
parents: 5413
diff changeset
   371
by (asm_simp_tac (simpset() addsimps [insert_absorb, Int_insert_left]) 1);
9f029e382b5d New law card_Un_Int. Removed card_insert from simpset
paulson
parents: 5413
diff changeset
   372
qed "card_Un_Int";
9f029e382b5d New law card_Un_Int. Removed card_insert from simpset
paulson
parents: 5413
diff changeset
   373
9f029e382b5d New law card_Un_Int. Removed card_insert from simpset
paulson
parents: 5413
diff changeset
   374
Goal "[| finite A; finite B; A Int B = {} |] \
9f029e382b5d New law card_Un_Int. Removed card_insert from simpset
paulson
parents: 5413
diff changeset
   375
\     ==> card (A Un B) = card A + card B";
9f029e382b5d New law card_Un_Int. Removed card_insert from simpset
paulson
parents: 5413
diff changeset
   376
by (asm_simp_tac (simpset() addsimps [card_Un_Int]) 1);
9f029e382b5d New law card_Un_Int. Removed card_insert from simpset
paulson
parents: 5413
diff changeset
   377
qed "card_Un_disjoint";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   378
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5069
diff changeset
   379
Goal "[| finite A; B<=A |] ==> card A - card B = card (A - B)";
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   380
by (subgoal_tac "(A-B) Un B = A" 1);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   381
by (Blast_tac 2);
3457
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   382
by (rtac (add_right_cancel RS iffD1) 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   383
by (rtac (card_Un_disjoint RS subst) 1);
a8ab7c64817c Ran expandshort
paulson
parents: 3439
diff changeset
   384
by (etac ssubst 4);
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   385
by (Blast_tac 3);
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   386
by (ALLGOALS 
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   387
    (asm_simp_tac
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   388
     (simpset() addsimps [add_commute, not_less_iff_le, 
5416
9f029e382b5d New law card_Un_Int. Removed card_insert from simpset
paulson
parents: 5413
diff changeset
   389
			  add_diff_inverse, card_mono, finite_subset])));
3352
04502e5431fb New theorems suggested by Florian Kammueller
paulson
parents: 3340
diff changeset
   390
qed "card_Diff_subset";
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   391
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5069
diff changeset
   392
Goal "[| finite A; x: A |] ==> card(A-{x}) < card A";
2031
03a843f0f447 Ran expandshort
paulson
parents: 1786
diff changeset
   393
by (rtac Suc_less_SucD 1);
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   394
by (asm_simp_tac (simpset() addsimps [card_Suc_Diff1]) 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   395
qed "card_Diff1_less";
1618
372880456b5b Library changes for mutilated checkerboard
paulson
parents: 1553
diff changeset
   396
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5069
diff changeset
   397
Goal "finite A ==> card(A-{x}) <= card A";
4768
c342d63173e9 New theorems card_Diff_le and card_insert_le; tidied
paulson
parents: 4763
diff changeset
   398
by (case_tac "x: A" 1);
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   399
by (ALLGOALS (asm_simp_tac (simpset() addsimps [card_Diff1_less, less_imp_le])));
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   400
qed "card_Diff1_le";
1531
e5eb247ad13c Added a constant UNIV == {x.True}
nipkow
parents: 1465
diff changeset
   401
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5143
diff changeset
   402
Goalw [psubset_def] "finite B ==> !A. A < B --> card(A) < card(B)";
3222
726a9b069947 Distributed Psubset stuff to basic set theory files, incl Finite.
nipkow
parents: 2922
diff changeset
   403
by (etac finite_induct 1);
726a9b069947 Distributed Psubset stuff to basic set theory files, incl Finite.
nipkow
parents: 2922
diff changeset
   404
by (Simp_tac 1);
3708
56facaebf3e3 Changed some proofs to use Clarify_tac
paulson
parents: 3517
diff changeset
   405
by (Clarify_tac 1);
3222
726a9b069947 Distributed Psubset stuff to basic set theory files, incl Finite.
nipkow
parents: 2922
diff changeset
   406
by (case_tac "x:A" 1);
726a9b069947 Distributed Psubset stuff to basic set theory files, incl Finite.
nipkow
parents: 2922
diff changeset
   407
(*1*)
3413
c1f63cc3a768 Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents: 3389
diff changeset
   408
by (dres_inst_tac [("A","A")]mk_disjoint_insert 1);
4775
66b1a7c42d94 Tidied proofs
paulson
parents: 4768
diff changeset
   409
by (Clarify_tac 1);
66b1a7c42d94 Tidied proofs
paulson
parents: 4768
diff changeset
   410
by (rotate_tac ~3 1);
66b1a7c42d94 Tidied proofs
paulson
parents: 4768
diff changeset
   411
by (asm_full_simp_tac (simpset() addsimps [finite_subset]) 1);
3708
56facaebf3e3 Changed some proofs to use Clarify_tac
paulson
parents: 3517
diff changeset
   412
by (Blast_tac 1);
3222
726a9b069947 Distributed Psubset stuff to basic set theory files, incl Finite.
nipkow
parents: 2922
diff changeset
   413
(*2*)
3708
56facaebf3e3 Changed some proofs to use Clarify_tac
paulson
parents: 3517
diff changeset
   414
by (eres_inst_tac [("P","?a<?b")] notE 1);
4775
66b1a7c42d94 Tidied proofs
paulson
parents: 4768
diff changeset
   415
by (asm_full_simp_tac (simpset() addsimps [subset_insert_iff]) 1);
3222
726a9b069947 Distributed Psubset stuff to basic set theory files, incl Finite.
nipkow
parents: 2922
diff changeset
   416
by (case_tac "A=F" 1);
8741
61bc5ed22b62 removal of less_SucI, le_SucI from default simpset
paulson
parents: 8554
diff changeset
   417
by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_SucI])));
3222
726a9b069947 Distributed Psubset stuff to basic set theory files, incl Finite.
nipkow
parents: 2922
diff changeset
   418
qed_spec_mp "psubset_card" ;
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   419
7821
a8717f53036c new thm card_Diff_singleton; tidied
paulson
parents: 7499
diff changeset
   420
Goal "[| A <= B; card B <= card A; finite B |] ==> A = B";
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   421
by (case_tac "A < B" 1);
7497
a18f3bce7198 strengthened card_seteq
oheimb
parents: 6162
diff changeset
   422
by (datac psubset_card 1 1);
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   423
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [psubset_eq])));
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   424
qed "card_seteq";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   425
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   426
Goal "[| finite B; A <= B; card A < card B |] ==> A < B";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   427
by (etac psubsetI 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   428
by (Blast_tac 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   429
qed "card_psubset";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   430
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   431
(*** Cardinality of image ***)
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   432
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   433
Goal "finite A ==> card (f `` A) <= card A";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   434
by (etac finite_induct 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   435
by (Simp_tac 1);
8741
61bc5ed22b62 removal of less_SucI, le_SucI from default simpset
paulson
parents: 8554
diff changeset
   436
by (asm_simp_tac (simpset() addsimps [le_SucI,finite_imageI,card_insert_if]) 1);
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   437
qed "card_image_le";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   438
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   439
Goal "finite(A) ==> inj_on f A --> card (f `` A) = card A";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   440
by (etac finite_induct 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   441
by (ALLGOALS Asm_simp_tac);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   442
by Safe_tac;
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   443
by (rewtac inj_on_def);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   444
by (Blast_tac 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   445
by (stac card_insert_disjoint 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   446
by (etac finite_imageI 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   447
by (Blast_tac 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   448
by (Blast_tac 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   449
qed_spec_mp "card_image";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   450
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   451
Goal "[| finite A; f``A <= A; inj_on f A |] ==> f``A = A";
7497
a18f3bce7198 strengthened card_seteq
oheimb
parents: 6162
diff changeset
   452
by (etac card_seteq 1);
a18f3bce7198 strengthened card_seteq
oheimb
parents: 6162
diff changeset
   453
by (dtac (card_image RS sym) 1);
a18f3bce7198 strengthened card_seteq
oheimb
parents: 6162
diff changeset
   454
by Auto_tac;
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   455
qed "endo_inj_surj";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   456
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   457
(*** Cardinality of the Powerset ***)
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   458
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   459
Goal "finite A ==> card (Pow A) = 2 ^ card A";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   460
by (etac finite_induct 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   461
by (ALLGOALS (asm_simp_tac (simpset() addsimps [Pow_insert])));
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   462
by (stac card_Un_disjoint 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   463
by (EVERY (map (blast_tac (claset() addIs [finite_imageI])) [3,2,1]));
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   464
by (subgoal_tac "inj_on (insert x) (Pow F)" 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   465
by (asm_simp_tac (simpset() addsimps [card_image, Pow_insert]) 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   466
by (rewtac inj_on_def);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   467
by (blast_tac (claset() addSEs [equalityE]) 1);
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   468
qed "card_Pow";
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   469
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   470
3430
d21b920363ab eliminated non-ASCII;
wenzelm
parents: 3427
diff changeset
   471
(*Relates to equivalence classes.   Based on a theorem of F. Kammueller's.
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   472
  The "finite C" premise is redundant*)
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5069
diff changeset
   473
Goal "finite C ==> finite (Union C) --> \
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   474
\          (! c : C. k dvd card c) -->  \
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   475
\          (! c1: C. ! c2: C. c1 ~= c2 --> c1 Int c2 = {}) \
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   476
\          --> k dvd card(Union C)";
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   477
by (etac finite_induct 1);
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   478
by (ALLGOALS Asm_simp_tac);
3708
56facaebf3e3 Changed some proofs to use Clarify_tac
paulson
parents: 3517
diff changeset
   479
by (Clarify_tac 1);
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   480
by (stac card_Un_disjoint 1);
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   481
by (ALLGOALS
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 4059
diff changeset
   482
    (asm_full_simp_tac (simpset()
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   483
			 addsimps [dvd_add, disjoint_eq_subset_Compl])));
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   484
by (thin_tac "!c:F. ?PP(c)" 1);
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   485
by (thin_tac "!c:F. ?PP(c) & ?QQ(c)" 1);
3708
56facaebf3e3 Changed some proofs to use Clarify_tac
paulson
parents: 3517
diff changeset
   486
by (Clarify_tac 1);
3368
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   487
by (ball_tac 1);
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   488
by (Blast_tac 1);
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   489
qed_spec_mp "dvd_partition";
be517d000c02 Many new theorems about cardinality
paulson
parents: 3352
diff changeset
   490
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   491
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   492
(*** foldSet ***)
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   493
6141
a6922171b396 removal of the (thm list) argument of mk_cases
paulson
parents: 6024
diff changeset
   494
val empty_foldSetE = foldSet.mk_cases "({}, x) : foldSet f e";
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   495
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   496
AddSEs [empty_foldSetE];
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   497
AddIs foldSet.intrs;
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   498
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   499
Goal "[| (A-{x},y) : foldSet f e;  x: A |] ==> (A, f x y) : foldSet f e";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   500
by (etac (insert_Diff RS subst) 1 THEN resolve_tac foldSet.intrs 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   501
by Auto_tac;
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   502
qed "Diff1_foldSet";
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   503
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   504
Goal "(A, x) : foldSet f e ==> finite(A)";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   505
by (eresolve_tac [foldSet.induct] 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   506
by Auto_tac;
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   507
qed "foldSet_imp_finite";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   508
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   509
Addsimps [foldSet_imp_finite];
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   510
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   511
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   512
Goal "finite(A) ==> EX x. (A, x) : foldSet f e";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   513
by (etac finite_induct 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   514
by Auto_tac;
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   515
qed "finite_imp_foldSet";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   516
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   517
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   518
Open_locale "LC"; 
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   519
5782
7559f116cb10 locales now implicitly quantify over free variables
paulson
parents: 5626
diff changeset
   520
val f_lcomm = thm "lcomm";
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   521
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   522
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   523
Goal "ALL A x. card(A) < n --> (A, x) : foldSet f e --> \
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   524
\            (ALL y. (A, y) : foldSet f e --> y=x)";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   525
by (induct_tac "n" 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   526
by (auto_tac (claset(), simpset() addsimps [less_Suc_eq]));
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   527
by (etac foldSet.elim 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   528
by (Blast_tac 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   529
by (etac foldSet.elim 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   530
by (Blast_tac 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   531
by (Clarify_tac 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   532
(*force simplification of "card A < card (insert ...)"*)
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   533
by (etac rev_mp 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   534
by (asm_simp_tac (simpset() addsimps [less_Suc_eq_le]) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   535
by (rtac impI 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   536
(** LEVEL 10 **)
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   537
by (rename_tac "Aa xa ya Ab xb yb" 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   538
 by (case_tac "xa=xb" 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   539
 by (subgoal_tac "Aa = Ab" 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   540
 by (blast_tac (claset() addEs [equalityE]) 2);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   541
 by (Blast_tac 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   542
(*case xa ~= xb*)
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   543
by (subgoal_tac "Aa-{xb} = Ab-{xa} & xb : Aa & xa : Ab" 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   544
 by (blast_tac (claset() addEs [equalityE]) 2);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   545
by (Clarify_tac 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   546
by (subgoal_tac "Aa = insert xb Ab - {xa}" 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   547
 by (blast_tac (claset() addEs [equalityE]) 2);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   548
(** LEVEL 20 **)
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   549
by (subgoal_tac "card Aa <= card Ab" 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   550
 by (rtac (Suc_le_mono RS subst) 2);
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   551
 by (asm_simp_tac (simpset() addsimps [card_Suc_Diff1]) 2);
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   552
by (res_inst_tac [("A1", "Aa-{xb}"), ("f1","f")] 
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   553
    (finite_imp_foldSet RS exE) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   554
by (blast_tac (claset() addIs [foldSet_imp_finite, finite_Diff]) 1);
7499
23e090051cb8 isatool expandshort;
wenzelm
parents: 7497
diff changeset
   555
by (ftac Diff1_foldSet 1 THEN assume_tac 1);
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   556
by (subgoal_tac "ya = f xb x" 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   557
 by (Blast_tac 2);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   558
by (subgoal_tac "(Ab - {xa}, x) : foldSet f e" 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   559
 by (Asm_full_simp_tac 2);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   560
by (subgoal_tac "yb = f xa x" 1);
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   561
 by (blast_tac (claset() addDs [Diff1_foldSet]) 2);
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   562
by (asm_simp_tac (simpset() addsimps [f_lcomm]) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   563
val lemma = result();
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   564
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   565
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   566
Goal "[| (A, x) : foldSet f e;  (A, y) : foldSet f e |] ==> y=x";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   567
by (blast_tac (claset() addIs [normalize_thm [RSspec, RSmp] lemma]) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   568
qed "foldSet_determ";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   569
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   570
Goalw [fold_def] "(A,y) : foldSet f e ==> fold f e A = y";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   571
by (blast_tac (claset() addIs [foldSet_determ]) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   572
qed "fold_equality";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   573
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   574
Goalw [fold_def] "fold f e {} = e";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   575
by (Blast_tac 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   576
qed "fold_empty";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   577
Addsimps [fold_empty];
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   578
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   579
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   580
Goal "x ~: A ==> \
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   581
\     ((insert x A, v) : foldSet f e) =  \
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   582
\     (EX y. (A, y) : foldSet f e & v = f x y)";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   583
by Auto_tac;
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   584
by (res_inst_tac [("A1", "A"), ("f1","f")] (finite_imp_foldSet RS exE) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   585
by (force_tac (claset() addDs [foldSet_imp_finite], simpset()) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   586
by (blast_tac (claset() addIs [foldSet_determ]) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   587
val lemma = result();
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   588
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   589
Goalw [fold_def]
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   590
     "[| finite A; x ~: A |] ==> fold f e (insert x A) = f x (fold f e A)";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   591
by (asm_simp_tac (simpset() addsimps [lemma]) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   592
by (rtac select_equality 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   593
by (auto_tac (claset() addIs [finite_imp_foldSet],
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   594
	      simpset() addcongs [conj_cong]
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   595
		        addsimps [symmetric fold_def,
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   596
				  fold_equality]));
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   597
qed "fold_insert";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   598
8911
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   599
Goal "finite A ==> ALL e. f x (fold f e A) = fold f (f x e) A";
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   600
by (etac finite_induct 1);
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   601
by (Simp_tac 1);
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   602
by (asm_simp_tac (simpset() addsimps [f_lcomm, fold_insert]) 1);
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   603
qed_spec_mp "fold_commute";
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   604
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   605
Goal "[| finite A; finite B |] \
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   606
\     ==> fold f (fold f e B) A  =  fold f (fold f e (A Int B)) (A Un B)";
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   607
by (etac finite_induct 1);
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   608
by (Simp_tac 1);
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   609
by (asm_simp_tac (simpset() addsimps [fold_insert, fold_commute, 
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   610
	                              Int_insert_left, insert_absorb]) 1);
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   611
qed "fold_nest_Un_Int";
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   612
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   613
Goal "[| finite A; finite B; A Int B = {} |] \
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   614
\     ==> fold f e (A Un B)  =  fold f (fold f e B) A";
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   615
by (asm_simp_tac (simpset() addsimps [fold_nest_Un_Int]) 1);
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   616
qed "fold_nest_Un_disjoint";
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   617
5626
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   618
(* Delete rules to do with foldSet relation: obsolete *)
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   619
Delsimps [foldSet_imp_finite];
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   620
Delrules [empty_foldSetE];
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   621
Delrules foldSet.intrs;
f67c34721486 New inductive definition of `card'
nipkow
parents: 5616
diff changeset
   622
6024
cb87f103d114 new Close_locale synatx
paulson
parents: 5782
diff changeset
   623
Close_locale "LC";
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   624
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   625
Open_locale "ACe"; 
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   626
8911
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   627
(*We enter a more restrictive framework, with f :: ['a,'a] => 'a
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   628
    instead of ['b,'a] => 'a 
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   629
  At present, none of these results are used!*)
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   630
5782
7559f116cb10 locales now implicitly quantify over free variables
paulson
parents: 5626
diff changeset
   631
val f_ident   = thm "ident";
7559f116cb10 locales now implicitly quantify over free variables
paulson
parents: 5626
diff changeset
   632
val f_commute = thm "commute";
7559f116cb10 locales now implicitly quantify over free variables
paulson
parents: 5626
diff changeset
   633
val f_assoc   = thm "assoc";
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   634
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   635
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   636
Goal "f x (f y z) = f y (f x z)";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   637
by (rtac (f_commute RS trans) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   638
by (rtac (f_assoc RS trans) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   639
by (rtac (f_commute RS arg_cong) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   640
qed "f_left_commute";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   641
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   642
val f_ac = [f_assoc, f_commute, f_left_commute];
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   643
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   644
Goal "f e x = x";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   645
by (stac f_commute 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   646
by (rtac f_ident 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   647
qed "f_left_ident";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   648
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   649
val f_idents = [f_left_ident, f_ident];
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   650
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   651
Goal "[| finite A; finite B |] \
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   652
\     ==> f (fold f e A) (fold f e B) =  \
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   653
\         f (fold f e (A Un B)) (fold f e (A Int B))";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   654
by (etac finite_induct 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   655
by (simp_tac (simpset() addsimps f_idents) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   656
by (asm_simp_tac (simpset() addsimps f_ac @ f_idents @
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   657
           [export fold_insert,insert_absorb, Int_insert_left]) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   658
qed "fold_Un_Int";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   659
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   660
Goal "[| finite A; finite B; A Int B = {} |] \
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   661
\     ==> fold f e (A Un B) = f (fold f e A) (fold f e B)";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   662
by (asm_simp_tac (simpset() addsimps fold_Un_Int::f_idents) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   663
qed "fold_Un_disjoint";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   664
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   665
Goal
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   666
 "[| finite A; finite B |] ==> A Int B = {} --> \
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   667
\ fold (f o g) e (A Un B) = f (fold (f o g) e A) (fold (f o g) e B)";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   668
by (etac finite_induct 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   669
by (simp_tac (simpset() addsimps f_idents) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   670
by (asm_full_simp_tac (simpset() addsimps f_ac @ f_idents @
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   671
           [export fold_insert,insert_absorb, Int_insert_left]) 1);
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   672
qed "fold_Un_disjoint2";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   673
6024
cb87f103d114 new Close_locale synatx
paulson
parents: 5782
diff changeset
   674
Close_locale "ACe";
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   675
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   676
8981
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   677
(*** setsum: generalized summation over a set ***)
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   678
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   679
Goalw [setsum_def] "setsum f {} = 0";
6162
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   680
by (Simp_tac 1);
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   681
qed "setsum_empty";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   682
Addsimps [setsum_empty];
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   683
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   684
Goalw [setsum_def]
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   685
 "[| finite F; a ~: F |] ==> setsum f (insert a F) = f(a) + setsum f F";
8963
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   686
by (asm_simp_tac (simpset() addsimps [export fold_insert,
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   687
				      thm "plus_ac0_left_commute"]) 1);
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   688
qed "setsum_insert";
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   689
Addsimps [setsum_insert];
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   690
8911
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   691
(*Could allow many "card" proofs to be simplified*)
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   692
Goal "finite A ==> card A = setsum (%x. 1) A";
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   693
by (etac finite_induct 1);
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   694
by Auto_tac;
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   695
qed "card_eq_setsum";
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   696
8911
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   697
Goal "[| finite A; finite B |] \
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   698
\     ==> setsum g (A Un B) + setsum g (A Int B) = setsum g A + setsum g B";
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   699
by (etac finite_induct 1);
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   700
by (Simp_tac 1);
8963
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   701
by (asm_full_simp_tac (simpset() addsimps (thms "plus_ac0") @ 
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   702
                                          [Int_insert_left, insert_absorb]) 1);
8911
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   703
qed "setsum_Un_Int";
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   704
8981
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   705
Goal "[| finite A; finite B; A Int B = {} |] \
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   706
\     ==> setsum g (A Un B) = setsum g A + setsum g B";  
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   707
by (stac (setsum_Un_Int RS sym) 1);
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   708
by Auto_tac;
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   709
qed "setsum_Un_disjoint";
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   710
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   711
Goal "[| finite I |] \
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   712
\     ==> (ALL i:I. finite (A i)) --> (ALL i:I. ALL j:I. A i Int A j = {}) \
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   713
\         --> setsum f (UNION I A) = setsum (%i. setsum f (A i)) I"; 
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   714
by (etac finite_induct 1);
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   715
by (Simp_tac 1);
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   716
by (asm_simp_tac (simpset() addsimps [setsum_Un_disjoint]) 1);
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   717
qed_spec_mp "setsum_UN_disjoint";
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   718
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   719
Goal "finite A ==> setsum (%x. f x + g x) A = setsum f A + setsum g A";
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   720
by (etac finite_induct 1);
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   721
by Auto_tac;
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   722
by (simp_tac (simpset() addsimps (thms "plus_ac0")) 1);
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   723
qed "setsum_addf";
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   724
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   725
(** For the natural numbers, we have subtraction **)
fe1f3d52e027 new setsum results
paulson
parents: 8971
diff changeset
   726
8911
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   727
Goal "[| finite A; finite B |] \
8963
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   728
\     ==> (setsum f (A Un B) :: nat) = \
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   729
\         setsum f A + setsum f B - setsum f (A Int B)";
8911
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   730
by (stac (setsum_Un_Int RS sym) 1);
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   731
by Auto_tac;
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   732
qed "setsum_Un";
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   733
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   734
Goal "finite F \
8963
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   735
\     ==> (setsum f (F-{a}) :: nat) = \
0d4abacae6aa setsum is now overloaded on plus_ac0; lemmas about lessThan, etc.
paulson
parents: 8911
diff changeset
   736
\         (if a:F then setsum f F - f a else setsum f F)";
6162
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   737
by (etac finite_induct 1);
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   738
by (auto_tac (claset(), simpset() addsimps [insert_Diff_if]));
484adda70b65 expandshort
paulson
parents: 6141
diff changeset
   739
by (dres_inst_tac [("a","a")] mk_disjoint_insert 1);
8911
c35b74bad518 fold_commute, fold_nest_Un_Int, setsum_Un and other new results
paulson
parents: 8889
diff changeset
   740
by Auto_tac;
5616
497eeeace3fc Merges FoldSet into Finite
nipkow
parents: 5537
diff changeset
   741
qed_spec_mp "setsum_diff1";
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   742
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   743
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   744
(*** Basic theorem about "choose".  By Florian Kammueller, tidied by LCP ***)
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   745
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   746
Goal "finite S ==> (card S = 0) = (S = {})"; 
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   747
by (auto_tac (claset() addDs [card_Suc_Diff1],
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   748
	      simpset()));
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   749
qed "card_0_empty_iff";
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   750
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   751
Goal "finite A ==> card {B. B <= A & card B = 0} = 1";
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   752
by (asm_simp_tac (simpset() addcongs [conj_cong]
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   753
	 	            addsimps [finite_subset RS card_0_empty_iff]) 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   754
by (simp_tac (simpset() addcongs [rev_conj_cong]) 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   755
qed "card_s_0_eq_empty";
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   756
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   757
Goal "[| finite M; x ~: M |] \
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   758
\  ==> {s. s <= insert x M & card(s) = Suc k} \
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   759
\      = {s. s <= M & card(s) = Suc k} Un \
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   760
\        {s. EX t. t <= M & card(t) = k & s = insert x t}";
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   761
by Safe_tac;
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   762
by (auto_tac (claset() addIs [finite_subset RS card_insert_disjoint], 
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   763
	      simpset()));
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   764
by (dres_inst_tac [("x","xa - {x}")] spec 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   765
by (subgoal_tac ("x ~: xa") 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   766
by Auto_tac;
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   767
by (etac rev_mp 1 THEN stac card_Diff_singleton 1);
7958
f531589c9fc1 added various little lemmas
oheimb
parents: 7842
diff changeset
   768
by (auto_tac (claset() addIs [finite_subset], simpset()));
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   769
qed "choose_deconstruct";
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   770
8140
80a24574dced replaced f : A funcset B by f``A <= B.
nipkow
parents: 8081
diff changeset
   771
Goal "[| finite(A); finite(B);  f``A <= B;  inj_on f A |] \
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   772
\     ==> card A <= card B";
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   773
by (auto_tac (claset() addIs [card_mono], 
8140
80a24574dced replaced f : A funcset B by f``A <= B.
nipkow
parents: 8081
diff changeset
   774
	      simpset() addsimps [card_image RS sym]));
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   775
qed "card_inj_on_le";
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   776
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   777
Goal "[| finite A; finite B; \
8140
80a24574dced replaced f : A funcset B by f``A <= B.
nipkow
parents: 8081
diff changeset
   778
\        f``A <= B; inj_on f A; g``B <= A; inj_on g B |] \
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   779
\     ==> card(A) = card(B)";
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   780
by (auto_tac (claset() addIs [le_anti_sym,card_inj_on_le], simpset()));
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   781
qed "card_bij_eq";
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   782
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   783
Goal "[| finite M; x ~: M |]  \
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   784
\     ==> card{s. EX t. t <= M & card(t) = k & s = insert x t} = \
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   785
\         card {s. s <= M & card(s) = k}";
8140
80a24574dced replaced f : A funcset B by f``A <= B.
nipkow
parents: 8081
diff changeset
   786
by (res_inst_tac [("f", "%s. s - {x}"), ("g","insert x")] card_bij_eq 1);
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   787
by (res_inst_tac [("B","Pow(insert x M)")] finite_subset 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   788
by (res_inst_tac [("B","Pow(M)")] finite_subset 3);
8320
073144bed7da expandshort
paulson
parents: 8262
diff changeset
   789
by (REPEAT(Fast_tac 1));
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   790
(* arity *)
8140
80a24574dced replaced f : A funcset B by f``A <= B.
nipkow
parents: 8081
diff changeset
   791
by (auto_tac (claset() addSEs [equalityE], simpset() addsimps [inj_on_def]));
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   792
by (stac Diff_insert0 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   793
by Auto_tac;
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   794
qed "constr_bij";
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   795
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   796
(* Main theorem: combinatorial theorem about number of subsets of a set *)
7842
6858c98385c3 simplified and generalized n_sub_lemma and n_subsets
paulson
parents: 7834
diff changeset
   797
Goal "(ALL A. finite A --> card {s. s <= A & card s = k} = (card A choose k))";
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   798
by (induct_tac "k" 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   799
by (simp_tac (simpset() addsimps [card_s_0_eq_empty]) 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   800
(* first 0 case finished *)
7842
6858c98385c3 simplified and generalized n_sub_lemma and n_subsets
paulson
parents: 7834
diff changeset
   801
(* prepare finite set induction *)
6858c98385c3 simplified and generalized n_sub_lemma and n_subsets
paulson
parents: 7834
diff changeset
   802
by (rtac allI 1 THEN rtac impI 1);
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   803
(* second induction *)
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   804
by (etac finite_induct 1);
7842
6858c98385c3 simplified and generalized n_sub_lemma and n_subsets
paulson
parents: 7834
diff changeset
   805
by (ALLGOALS
6858c98385c3 simplified and generalized n_sub_lemma and n_subsets
paulson
parents: 7834
diff changeset
   806
    (simp_tac (simpset() addcongs [conj_cong] addsimps [card_s_0_eq_empty])));
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   807
by (stac choose_deconstruct 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   808
by (assume_tac 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   809
by (assume_tac 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   810
by (stac card_Un_disjoint 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   811
by (Force_tac 3);
7842
6858c98385c3 simplified and generalized n_sub_lemma and n_subsets
paulson
parents: 7834
diff changeset
   812
(** LEVEL 10 **)
6858c98385c3 simplified and generalized n_sub_lemma and n_subsets
paulson
parents: 7834
diff changeset
   813
(* use bijection *)
6858c98385c3 simplified and generalized n_sub_lemma and n_subsets
paulson
parents: 7834
diff changeset
   814
by (force_tac (claset(), simpset() addsimps [constr_bij]) 3);
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   815
(* finite goal *)
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   816
by (res_inst_tac [("B","Pow F")] finite_subset 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   817
by (Blast_tac 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   818
by (etac (finite_Pow_iff RS iffD2) 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   819
(* finite goal *)
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   820
by (res_inst_tac [("B","Pow (insert x F)")] finite_subset 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   821
by (Blast_tac 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   822
by (blast_tac (claset() addIs [finite_Pow_iff RS iffD2]) 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   823
qed "n_sub_lemma";
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   824
7842
6858c98385c3 simplified and generalized n_sub_lemma and n_subsets
paulson
parents: 7834
diff changeset
   825
Goal "finite M ==> card {s. s <= M & card(s) = k} = ((card M) choose k)";
7834
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   826
by (asm_simp_tac (simpset() addsimps [n_sub_lemma]) 1);
915be5b9dc6f new "choose" lemmas by Florian Kammueller
paulson
parents: 7821
diff changeset
   827
qed "n_subsets";