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