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