author | blanchet |
Mon, 03 Mar 2014 12:48:20 +0100 | |
changeset 55855 | 98ad5680173a |
parent 55096 | 916b2ac758f4 |
child 56154 | f0a927235162 |
permissions | -rw-r--r-- |
12396 | 1 |
(* Title: HOL/Finite_Set.thy |
2 |
Author: Tobias Nipkow, Lawrence C Paulson and Markus Wenzel |
|
55020 | 3 |
with contributions by Jeremy Avigad and Andrei Popescu |
12396 | 4 |
*) |
5 |
||
6 |
header {* Finite sets *} |
|
7 |
||
15131 | 8 |
theory Finite_Set |
55096 | 9 |
imports Product_Type Sum_Type Nat |
15131 | 10 |
begin |
12396 | 11 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
12 |
subsection {* Predicate for finite sets *} |
12396 | 13 |
|
41656 | 14 |
inductive finite :: "'a set \<Rightarrow> bool" |
22262 | 15 |
where |
16 |
emptyI [simp, intro!]: "finite {}" |
|
41656 | 17 |
| insertI [simp, intro!]: "finite A \<Longrightarrow> finite (insert a A)" |
18 |
||
49764
9979d64b8016
moving simproc from Finite_Set to more appropriate Product_Type theory
bulwahn
parents:
49758
diff
changeset
|
19 |
simproc_setup finite_Collect ("finite (Collect P)") = {* K Set_Comprehension_Pointfree.simproc *} |
48109
0a58f7eefba2
Integrated set comprehension pointfree simproc.
Rafal Kolanski <rafal.kolanski@nicta.com.au>
parents:
48063
diff
changeset
|
20 |
|
54611
31afce809794
set_comprehension_pointfree simproc causes to many surprises if enabled by default
traytel
parents:
54570
diff
changeset
|
21 |
declare [[simproc del: finite_Collect]] |
31afce809794
set_comprehension_pointfree simproc causes to many surprises if enabled by default
traytel
parents:
54570
diff
changeset
|
22 |
|
41656 | 23 |
lemma finite_induct [case_names empty insert, induct set: finite]: |
24 |
-- {* Discharging @{text "x \<notin> F"} entails extra work. *} |
|
25 |
assumes "finite F" |
|
26 |
assumes "P {}" |
|
27 |
and insert: "\<And>x F. finite F \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)" |
|
28 |
shows "P F" |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
29 |
using `finite F` |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
30 |
proof induct |
41656 | 31 |
show "P {}" by fact |
32 |
fix x F assume F: "finite F" and P: "P F" |
|
33 |
show "P (insert x F)" |
|
34 |
proof cases |
|
35 |
assume "x \<in> F" |
|
36 |
hence "insert x F = F" by (rule insert_absorb) |
|
37 |
with P show ?thesis by (simp only:) |
|
38 |
next |
|
39 |
assume "x \<notin> F" |
|
40 |
from F this P show ?thesis by (rule insert) |
|
41 |
qed |
|
42 |
qed |
|
43 |
||
51622 | 44 |
lemma infinite_finite_induct [case_names infinite empty insert]: |
45 |
assumes infinite: "\<And>A. \<not> finite A \<Longrightarrow> P A" |
|
46 |
assumes empty: "P {}" |
|
47 |
assumes insert: "\<And>x F. finite F \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)" |
|
48 |
shows "P A" |
|
49 |
proof (cases "finite A") |
|
50 |
case False with infinite show ?thesis . |
|
51 |
next |
|
52 |
case True then show ?thesis by (induct A) (fact empty insert)+ |
|
53 |
qed |
|
54 |
||
41656 | 55 |
|
56 |
subsubsection {* Choice principles *} |
|
12396 | 57 |
|
13737 | 58 |
lemma ex_new_if_finite: -- "does not depend on def of finite at all" |
14661 | 59 |
assumes "\<not> finite (UNIV :: 'a set)" and "finite A" |
60 |
shows "\<exists>a::'a. a \<notin> A" |
|
61 |
proof - |
|
28823 | 62 |
from assms have "A \<noteq> UNIV" by blast |
41656 | 63 |
then show ?thesis by blast |
12396 | 64 |
qed |
65 |
||
41656 | 66 |
text {* A finite choice principle. Does not need the SOME choice operator. *} |
15484 | 67 |
|
29923 | 68 |
lemma finite_set_choice: |
41656 | 69 |
"finite A \<Longrightarrow> \<forall>x\<in>A. \<exists>y. P x y \<Longrightarrow> \<exists>f. \<forall>x\<in>A. P x (f x)" |
70 |
proof (induct rule: finite_induct) |
|
71 |
case empty then show ?case by simp |
|
29923 | 72 |
next |
73 |
case (insert a A) |
|
74 |
then obtain f b where f: "ALL x:A. P x (f x)" and ab: "P a b" by auto |
|
75 |
show ?case (is "EX f. ?P f") |
|
76 |
proof |
|
77 |
show "?P(%x. if x = a then b else f x)" using f ab by auto |
|
78 |
qed |
|
79 |
qed |
|
80 |
||
23878 | 81 |
|
41656 | 82 |
subsubsection {* Finite sets are the images of initial segments of natural numbers *} |
15392 | 83 |
|
15510 | 84 |
lemma finite_imp_nat_seg_image_inj_on: |
41656 | 85 |
assumes "finite A" |
86 |
shows "\<exists>(n::nat) f. A = f ` {i. i < n} \<and> inj_on f {i. i < n}" |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
87 |
using assms |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
88 |
proof induct |
15392 | 89 |
case empty |
41656 | 90 |
show ?case |
91 |
proof |
|
92 |
show "\<exists>f. {} = f ` {i::nat. i < 0} \<and> inj_on f {i. i < 0}" by simp |
|
15510 | 93 |
qed |
15392 | 94 |
next |
95 |
case (insert a A) |
|
23389 | 96 |
have notinA: "a \<notin> A" by fact |
15510 | 97 |
from insert.hyps obtain n f |
98 |
where "A = f ` {i::nat. i < n}" "inj_on f {i. i < n}" by blast |
|
99 |
hence "insert a A = f(n:=a) ` {i. i < Suc n}" |
|
100 |
"inj_on (f(n:=a)) {i. i < Suc n}" using notinA |
|
101 |
by (auto simp add: image_def Ball_def inj_on_def less_Suc_eq) |
|
15392 | 102 |
thus ?case by blast |
103 |
qed |
|
104 |
||
105 |
lemma nat_seg_image_imp_finite: |
|
41656 | 106 |
"A = f ` {i::nat. i < n} \<Longrightarrow> finite A" |
107 |
proof (induct n arbitrary: A) |
|
15392 | 108 |
case 0 thus ?case by simp |
109 |
next |
|
110 |
case (Suc n) |
|
111 |
let ?B = "f ` {i. i < n}" |
|
112 |
have finB: "finite ?B" by(rule Suc.hyps[OF refl]) |
|
113 |
show ?case |
|
114 |
proof cases |
|
115 |
assume "\<exists>k<n. f n = f k" |
|
116 |
hence "A = ?B" using Suc.prems by(auto simp:less_Suc_eq) |
|
117 |
thus ?thesis using finB by simp |
|
118 |
next |
|
119 |
assume "\<not>(\<exists> k<n. f n = f k)" |
|
120 |
hence "A = insert (f n) ?B" using Suc.prems by(auto simp:less_Suc_eq) |
|
121 |
thus ?thesis using finB by simp |
|
122 |
qed |
|
123 |
qed |
|
124 |
||
125 |
lemma finite_conv_nat_seg_image: |
|
41656 | 126 |
"finite A \<longleftrightarrow> (\<exists>(n::nat) f. A = f ` {i::nat. i < n})" |
127 |
by (blast intro: nat_seg_image_imp_finite dest: finite_imp_nat_seg_image_inj_on) |
|
15392 | 128 |
|
32988 | 129 |
lemma finite_imp_inj_to_nat_seg: |
41656 | 130 |
assumes "finite A" |
131 |
shows "\<exists>f n::nat. f ` A = {i. i < n} \<and> inj_on f A" |
|
32988 | 132 |
proof - |
133 |
from finite_imp_nat_seg_image_inj_on[OF `finite A`] |
|
134 |
obtain f and n::nat where bij: "bij_betw f {i. i<n} A" |
|
135 |
by (auto simp:bij_betw_def) |
|
33057 | 136 |
let ?f = "the_inv_into {i. i<n} f" |
32988 | 137 |
have "inj_on ?f A & ?f ` A = {i. i<n}" |
33057 | 138 |
by (fold bij_betw_def) (rule bij_betw_the_inv_into[OF bij]) |
32988 | 139 |
thus ?thesis by blast |
140 |
qed |
|
141 |
||
41656 | 142 |
lemma finite_Collect_less_nat [iff]: |
143 |
"finite {n::nat. n < k}" |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44835
diff
changeset
|
144 |
by (fastforce simp: finite_conv_nat_seg_image) |
29920 | 145 |
|
41656 | 146 |
lemma finite_Collect_le_nat [iff]: |
147 |
"finite {n::nat. n \<le> k}" |
|
148 |
by (simp add: le_eq_less_or_eq Collect_disj_eq) |
|
15392 | 149 |
|
41656 | 150 |
|
151 |
subsubsection {* Finiteness and common set operations *} |
|
12396 | 152 |
|
41656 | 153 |
lemma rev_finite_subset: |
154 |
"finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> finite A" |
|
155 |
proof (induct arbitrary: A rule: finite_induct) |
|
156 |
case empty |
|
157 |
then show ?case by simp |
|
158 |
next |
|
159 |
case (insert x F A) |
|
160 |
have A: "A \<subseteq> insert x F" and r: "A - {x} \<subseteq> F \<Longrightarrow> finite (A - {x})" by fact+ |
|
161 |
show "finite A" |
|
162 |
proof cases |
|
163 |
assume x: "x \<in> A" |
|
164 |
with A have "A - {x} \<subseteq> F" by (simp add: subset_insert_iff) |
|
165 |
with r have "finite (A - {x})" . |
|
166 |
hence "finite (insert x (A - {x}))" .. |
|
167 |
also have "insert x (A - {x}) = A" using x by (rule insert_Diff) |
|
168 |
finally show ?thesis . |
|
12396 | 169 |
next |
41656 | 170 |
show "A \<subseteq> F ==> ?thesis" by fact |
171 |
assume "x \<notin> A" |
|
172 |
with A show "A \<subseteq> F" by (simp add: subset_insert_iff) |
|
12396 | 173 |
qed |
174 |
qed |
|
175 |
||
41656 | 176 |
lemma finite_subset: |
177 |
"A \<subseteq> B \<Longrightarrow> finite B \<Longrightarrow> finite A" |
|
178 |
by (rule rev_finite_subset) |
|
29901 | 179 |
|
41656 | 180 |
lemma finite_UnI: |
181 |
assumes "finite F" and "finite G" |
|
182 |
shows "finite (F \<union> G)" |
|
183 |
using assms by induct simp_all |
|
31992 | 184 |
|
41656 | 185 |
lemma finite_Un [iff]: |
186 |
"finite (F \<union> G) \<longleftrightarrow> finite F \<and> finite G" |
|
187 |
by (blast intro: finite_UnI finite_subset [of _ "F \<union> G"]) |
|
31992 | 188 |
|
41656 | 189 |
lemma finite_insert [simp]: "finite (insert a A) \<longleftrightarrow> finite A" |
12396 | 190 |
proof - |
41656 | 191 |
have "finite {a} \<and> finite A \<longleftrightarrow> finite A" by simp |
192 |
then have "finite ({a} \<union> A) \<longleftrightarrow> finite A" by (simp only: finite_Un) |
|
23389 | 193 |
then show ?thesis by simp |
12396 | 194 |
qed |
195 |
||
41656 | 196 |
lemma finite_Int [simp, intro]: |
197 |
"finite F \<or> finite G \<Longrightarrow> finite (F \<inter> G)" |
|
198 |
by (blast intro: finite_subset) |
|
199 |
||
200 |
lemma finite_Collect_conjI [simp, intro]: |
|
201 |
"finite {x. P x} \<or> finite {x. Q x} \<Longrightarrow> finite {x. P x \<and> Q x}" |
|
202 |
by (simp add: Collect_conj_eq) |
|
203 |
||
204 |
lemma finite_Collect_disjI [simp]: |
|
205 |
"finite {x. P x \<or> Q x} \<longleftrightarrow> finite {x. P x} \<and> finite {x. Q x}" |
|
206 |
by (simp add: Collect_disj_eq) |
|
207 |
||
208 |
lemma finite_Diff [simp, intro]: |
|
209 |
"finite A \<Longrightarrow> finite (A - B)" |
|
210 |
by (rule finite_subset, rule Diff_subset) |
|
29901 | 211 |
|
212 |
lemma finite_Diff2 [simp]: |
|
41656 | 213 |
assumes "finite B" |
214 |
shows "finite (A - B) \<longleftrightarrow> finite A" |
|
29901 | 215 |
proof - |
41656 | 216 |
have "finite A \<longleftrightarrow> finite((A - B) \<union> (A \<inter> B))" by (simp add: Un_Diff_Int) |
217 |
also have "\<dots> \<longleftrightarrow> finite (A - B)" using `finite B` by simp |
|
29901 | 218 |
finally show ?thesis .. |
219 |
qed |
|
220 |
||
41656 | 221 |
lemma finite_Diff_insert [iff]: |
222 |
"finite (A - insert a B) \<longleftrightarrow> finite (A - B)" |
|
223 |
proof - |
|
224 |
have "finite (A - B) \<longleftrightarrow> finite (A - B - {a})" by simp |
|
225 |
moreover have "A - insert a B = A - B - {a}" by auto |
|
226 |
ultimately show ?thesis by simp |
|
227 |
qed |
|
228 |
||
29901 | 229 |
lemma finite_compl[simp]: |
41656 | 230 |
"finite (A :: 'a set) \<Longrightarrow> finite (- A) \<longleftrightarrow> finite (UNIV :: 'a set)" |
231 |
by (simp add: Compl_eq_Diff_UNIV) |
|
12396 | 232 |
|
29916 | 233 |
lemma finite_Collect_not[simp]: |
41656 | 234 |
"finite {x :: 'a. P x} \<Longrightarrow> finite {x. \<not> P x} \<longleftrightarrow> finite (UNIV :: 'a set)" |
235 |
by (simp add: Collect_neg_eq) |
|
236 |
||
237 |
lemma finite_Union [simp, intro]: |
|
238 |
"finite A \<Longrightarrow> (\<And>M. M \<in> A \<Longrightarrow> finite M) \<Longrightarrow> finite(\<Union>A)" |
|
239 |
by (induct rule: finite_induct) simp_all |
|
240 |
||
241 |
lemma finite_UN_I [intro]: |
|
242 |
"finite A \<Longrightarrow> (\<And>a. a \<in> A \<Longrightarrow> finite (B a)) \<Longrightarrow> finite (\<Union>a\<in>A. B a)" |
|
243 |
by (induct rule: finite_induct) simp_all |
|
29903 | 244 |
|
41656 | 245 |
lemma finite_UN [simp]: |
246 |
"finite A \<Longrightarrow> finite (UNION A B) \<longleftrightarrow> (\<forall>x\<in>A. finite (B x))" |
|
247 |
by (blast intro: finite_subset) |
|
248 |
||
249 |
lemma finite_Inter [intro]: |
|
250 |
"\<exists>A\<in>M. finite A \<Longrightarrow> finite (\<Inter>M)" |
|
251 |
by (blast intro: Inter_lower finite_subset) |
|
12396 | 252 |
|
41656 | 253 |
lemma finite_INT [intro]: |
254 |
"\<exists>x\<in>I. finite (A x) \<Longrightarrow> finite (\<Inter>x\<in>I. A x)" |
|
255 |
by (blast intro: INT_lower finite_subset) |
|
13825 | 256 |
|
41656 | 257 |
lemma finite_imageI [simp, intro]: |
258 |
"finite F \<Longrightarrow> finite (h ` F)" |
|
259 |
by (induct rule: finite_induct) simp_all |
|
13825 | 260 |
|
31768 | 261 |
lemma finite_image_set [simp]: |
262 |
"finite {x. P x} \<Longrightarrow> finite { f x | x. P x }" |
|
263 |
by (simp add: image_Collect [symmetric]) |
|
264 |
||
41656 | 265 |
lemma finite_imageD: |
42206 | 266 |
assumes "finite (f ` A)" and "inj_on f A" |
267 |
shows "finite A" |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
268 |
using assms |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
269 |
proof (induct "f ` A" arbitrary: A) |
42206 | 270 |
case empty then show ?case by simp |
271 |
next |
|
272 |
case (insert x B) |
|
273 |
then have B_A: "insert x B = f ` A" by simp |
|
274 |
then obtain y where "x = f y" and "y \<in> A" by blast |
|
275 |
from B_A `x \<notin> B` have "B = f ` A - {x}" by blast |
|
276 |
with B_A `x \<notin> B` `x = f y` `inj_on f A` `y \<in> A` have "B = f ` (A - {y})" by (simp add: inj_on_image_set_diff) |
|
277 |
moreover from `inj_on f A` have "inj_on f (A - {y})" by (rule inj_on_diff) |
|
278 |
ultimately have "finite (A - {y})" by (rule insert.hyps) |
|
279 |
then show "finite A" by simp |
|
280 |
qed |
|
12396 | 281 |
|
41656 | 282 |
lemma finite_surj: |
283 |
"finite A \<Longrightarrow> B \<subseteq> f ` A \<Longrightarrow> finite B" |
|
284 |
by (erule finite_subset) (rule finite_imageI) |
|
12396 | 285 |
|
41656 | 286 |
lemma finite_range_imageI: |
287 |
"finite (range g) \<Longrightarrow> finite (range (\<lambda>x. f (g x)))" |
|
288 |
by (drule finite_imageI) (simp add: range_composition) |
|
13825 | 289 |
|
41656 | 290 |
lemma finite_subset_image: |
291 |
assumes "finite B" |
|
292 |
shows "B \<subseteq> f ` A \<Longrightarrow> \<exists>C\<subseteq>A. finite C \<and> B = f ` C" |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
293 |
using assms |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
294 |
proof induct |
41656 | 295 |
case empty then show ?case by simp |
296 |
next |
|
297 |
case insert then show ?case |
|
298 |
by (clarsimp simp del: image_insert simp add: image_insert [symmetric]) |
|
299 |
blast |
|
300 |
qed |
|
301 |
||
43991 | 302 |
lemma finite_vimage_IntI: |
303 |
"finite F \<Longrightarrow> inj_on h A \<Longrightarrow> finite (h -` F \<inter> A)" |
|
41656 | 304 |
apply (induct rule: finite_induct) |
21575 | 305 |
apply simp_all |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
306 |
apply (subst vimage_insert) |
43991 | 307 |
apply (simp add: finite_subset [OF inj_on_vimage_singleton] Int_Un_distrib2) |
13825 | 308 |
done |
309 |
||
43991 | 310 |
lemma finite_vimageI: |
311 |
"finite F \<Longrightarrow> inj h \<Longrightarrow> finite (h -` F)" |
|
312 |
using finite_vimage_IntI[of F h UNIV] by auto |
|
313 |
||
34111
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
314 |
lemma finite_vimageD: |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
315 |
assumes fin: "finite (h -` F)" and surj: "surj h" |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
316 |
shows "finite F" |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
317 |
proof - |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
318 |
have "finite (h ` (h -` F))" using fin by (rule finite_imageI) |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
319 |
also have "h ` (h -` F) = F" using surj by (rule surj_image_vimage_eq) |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
320 |
finally show "finite F" . |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
321 |
qed |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
322 |
|
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
323 |
lemma finite_vimage_iff: "bij h \<Longrightarrow> finite (h -` F) \<longleftrightarrow> finite F" |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
324 |
unfolding bij_def by (auto elim: finite_vimageD finite_vimageI) |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
325 |
|
41656 | 326 |
lemma finite_Collect_bex [simp]: |
327 |
assumes "finite A" |
|
328 |
shows "finite {x. \<exists>y\<in>A. Q x y} \<longleftrightarrow> (\<forall>y\<in>A. finite {x. Q x y})" |
|
329 |
proof - |
|
330 |
have "{x. \<exists>y\<in>A. Q x y} = (\<Union>y\<in>A. {x. Q x y})" by auto |
|
331 |
with assms show ?thesis by simp |
|
332 |
qed |
|
12396 | 333 |
|
41656 | 334 |
lemma finite_Collect_bounded_ex [simp]: |
335 |
assumes "finite {y. P y}" |
|
336 |
shows "finite {x. \<exists>y. P y \<and> Q x y} \<longleftrightarrow> (\<forall>y. P y \<longrightarrow> finite {x. Q x y})" |
|
337 |
proof - |
|
338 |
have "{x. EX y. P y & Q x y} = (\<Union>y\<in>{y. P y}. {x. Q x y})" by auto |
|
339 |
with assms show ?thesis by simp |
|
340 |
qed |
|
29920 | 341 |
|
41656 | 342 |
lemma finite_Plus: |
343 |
"finite A \<Longrightarrow> finite B \<Longrightarrow> finite (A <+> B)" |
|
344 |
by (simp add: Plus_def) |
|
17022 | 345 |
|
31080 | 346 |
lemma finite_PlusD: |
347 |
fixes A :: "'a set" and B :: "'b set" |
|
348 |
assumes fin: "finite (A <+> B)" |
|
349 |
shows "finite A" "finite B" |
|
350 |
proof - |
|
351 |
have "Inl ` A \<subseteq> A <+> B" by auto |
|
41656 | 352 |
then have "finite (Inl ` A :: ('a + 'b) set)" using fin by (rule finite_subset) |
353 |
then show "finite A" by (rule finite_imageD) (auto intro: inj_onI) |
|
31080 | 354 |
next |
355 |
have "Inr ` B \<subseteq> A <+> B" by auto |
|
41656 | 356 |
then have "finite (Inr ` B :: ('a + 'b) set)" using fin by (rule finite_subset) |
357 |
then show "finite B" by (rule finite_imageD) (auto intro: inj_onI) |
|
31080 | 358 |
qed |
359 |
||
41656 | 360 |
lemma finite_Plus_iff [simp]: |
361 |
"finite (A <+> B) \<longleftrightarrow> finite A \<and> finite B" |
|
362 |
by (auto intro: finite_PlusD finite_Plus) |
|
31080 | 363 |
|
41656 | 364 |
lemma finite_Plus_UNIV_iff [simp]: |
365 |
"finite (UNIV :: ('a + 'b) set) \<longleftrightarrow> finite (UNIV :: 'a set) \<and> finite (UNIV :: 'b set)" |
|
366 |
by (subst UNIV_Plus_UNIV [symmetric]) (rule finite_Plus_iff) |
|
12396 | 367 |
|
40786
0a54cfc9add3
gave more standard finite set rules simp and intro attribute
nipkow
parents:
40716
diff
changeset
|
368 |
lemma finite_SigmaI [simp, intro]: |
41656 | 369 |
"finite A \<Longrightarrow> (\<And>a. a\<in>A \<Longrightarrow> finite (B a)) ==> finite (SIGMA a:A. B a)" |
40786
0a54cfc9add3
gave more standard finite set rules simp and intro attribute
nipkow
parents:
40716
diff
changeset
|
370 |
by (unfold Sigma_def) blast |
12396 | 371 |
|
51290 | 372 |
lemma finite_SigmaI2: |
373 |
assumes "finite {x\<in>A. B x \<noteq> {}}" |
|
374 |
and "\<And>a. a \<in> A \<Longrightarrow> finite (B a)" |
|
375 |
shows "finite (Sigma A B)" |
|
376 |
proof - |
|
377 |
from assms have "finite (Sigma {x\<in>A. B x \<noteq> {}} B)" by auto |
|
378 |
also have "Sigma {x:A. B x \<noteq> {}} B = Sigma A B" by auto |
|
379 |
finally show ?thesis . |
|
380 |
qed |
|
381 |
||
41656 | 382 |
lemma finite_cartesian_product: |
383 |
"finite A \<Longrightarrow> finite B \<Longrightarrow> finite (A \<times> B)" |
|
15402 | 384 |
by (rule finite_SigmaI) |
385 |
||
12396 | 386 |
lemma finite_Prod_UNIV: |
41656 | 387 |
"finite (UNIV :: 'a set) \<Longrightarrow> finite (UNIV :: 'b set) \<Longrightarrow> finite (UNIV :: ('a \<times> 'b) set)" |
388 |
by (simp only: UNIV_Times_UNIV [symmetric] finite_cartesian_product) |
|
12396 | 389 |
|
15409
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
paulson
parents:
15402
diff
changeset
|
390 |
lemma finite_cartesian_productD1: |
42207 | 391 |
assumes "finite (A \<times> B)" and "B \<noteq> {}" |
392 |
shows "finite A" |
|
393 |
proof - |
|
394 |
from assms obtain n f where "A \<times> B = f ` {i::nat. i < n}" |
|
395 |
by (auto simp add: finite_conv_nat_seg_image) |
|
396 |
then have "fst ` (A \<times> B) = fst ` f ` {i::nat. i < n}" by simp |
|
397 |
with `B \<noteq> {}` have "A = (fst \<circ> f) ` {i::nat. i < n}" |
|
398 |
by (simp add: image_compose) |
|
399 |
then have "\<exists>n f. A = f ` {i::nat. i < n}" by blast |
|
400 |
then show ?thesis |
|
401 |
by (auto simp add: finite_conv_nat_seg_image) |
|
402 |
qed |
|
15409
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
paulson
parents:
15402
diff
changeset
|
403 |
|
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
paulson
parents:
15402
diff
changeset
|
404 |
lemma finite_cartesian_productD2: |
42207 | 405 |
assumes "finite (A \<times> B)" and "A \<noteq> {}" |
406 |
shows "finite B" |
|
407 |
proof - |
|
408 |
from assms obtain n f where "A \<times> B = f ` {i::nat. i < n}" |
|
409 |
by (auto simp add: finite_conv_nat_seg_image) |
|
410 |
then have "snd ` (A \<times> B) = snd ` f ` {i::nat. i < n}" by simp |
|
411 |
with `A \<noteq> {}` have "B = (snd \<circ> f) ` {i::nat. i < n}" |
|
412 |
by (simp add: image_compose) |
|
413 |
then have "\<exists>n f. B = f ` {i::nat. i < n}" by blast |
|
414 |
then show ?thesis |
|
415 |
by (auto simp add: finite_conv_nat_seg_image) |
|
416 |
qed |
|
15409
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
paulson
parents:
15402
diff
changeset
|
417 |
|
48175
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
418 |
lemma finite_prod: |
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
419 |
"finite (UNIV :: ('a \<times> 'b) set) \<longleftrightarrow> finite (UNIV :: 'a set) \<and> finite (UNIV :: 'b set)" |
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
420 |
by(auto simp add: UNIV_Times_UNIV[symmetric] simp del: UNIV_Times_UNIV |
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
421 |
dest: finite_cartesian_productD1 finite_cartesian_productD2) |
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
422 |
|
41656 | 423 |
lemma finite_Pow_iff [iff]: |
424 |
"finite (Pow A) \<longleftrightarrow> finite A" |
|
12396 | 425 |
proof |
426 |
assume "finite (Pow A)" |
|
41656 | 427 |
then have "finite ((%x. {x}) ` A)" by (blast intro: finite_subset) |
428 |
then show "finite A" by (rule finite_imageD [unfolded inj_on_def]) simp |
|
12396 | 429 |
next |
430 |
assume "finite A" |
|
41656 | 431 |
then show "finite (Pow A)" |
35216 | 432 |
by induct (simp_all add: Pow_insert) |
12396 | 433 |
qed |
434 |
||
41656 | 435 |
corollary finite_Collect_subsets [simp, intro]: |
436 |
"finite A \<Longrightarrow> finite {B. B \<subseteq> A}" |
|
437 |
by (simp add: Pow_def [symmetric]) |
|
29918 | 438 |
|
48175
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
439 |
lemma finite_set: "finite (UNIV :: 'a set set) \<longleftrightarrow> finite (UNIV :: 'a set)" |
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
440 |
by(simp only: finite_Pow_iff Pow_UNIV[symmetric]) |
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
441 |
|
15392 | 442 |
lemma finite_UnionD: "finite(\<Union>A) \<Longrightarrow> finite A" |
41656 | 443 |
by (blast intro: finite_subset [OF subset_Pow_Union]) |
15392 | 444 |
|
53820 | 445 |
lemma finite_set_of_finite_funs: assumes "finite A" "finite B" |
446 |
shows "finite{f. \<forall>x. (x \<in> A \<longrightarrow> f x \<in> B) \<and> (x \<notin> A \<longrightarrow> f x = d)}" (is "finite ?S") |
|
447 |
proof- |
|
448 |
let ?F = "\<lambda>f. {(a,b). a \<in> A \<and> b = f a}" |
|
449 |
have "?F ` ?S \<subseteq> Pow(A \<times> B)" by auto |
|
450 |
from finite_subset[OF this] assms have 1: "finite (?F ` ?S)" by simp |
|
451 |
have 2: "inj_on ?F ?S" |
|
452 |
by(fastforce simp add: inj_on_def set_eq_iff fun_eq_iff) |
|
453 |
show ?thesis by(rule finite_imageD[OF 1 2]) |
|
454 |
qed |
|
15392 | 455 |
|
41656 | 456 |
subsubsection {* Further induction rules on finite sets *} |
457 |
||
458 |
lemma finite_ne_induct [case_names singleton insert, consumes 2]: |
|
459 |
assumes "finite F" and "F \<noteq> {}" |
|
460 |
assumes "\<And>x. P {x}" |
|
461 |
and "\<And>x F. finite F \<Longrightarrow> F \<noteq> {} \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)" |
|
462 |
shows "P F" |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
463 |
using assms |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
464 |
proof induct |
41656 | 465 |
case empty then show ?case by simp |
466 |
next |
|
467 |
case (insert x F) then show ?case by cases auto |
|
468 |
qed |
|
469 |
||
470 |
lemma finite_subset_induct [consumes 2, case_names empty insert]: |
|
471 |
assumes "finite F" and "F \<subseteq> A" |
|
472 |
assumes empty: "P {}" |
|
473 |
and insert: "\<And>a F. finite F \<Longrightarrow> a \<in> A \<Longrightarrow> a \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert a F)" |
|
474 |
shows "P F" |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
475 |
using `finite F` `F \<subseteq> A` |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
476 |
proof induct |
41656 | 477 |
show "P {}" by fact |
31441 | 478 |
next |
41656 | 479 |
fix x F |
480 |
assume "finite F" and "x \<notin> F" and |
|
481 |
P: "F \<subseteq> A \<Longrightarrow> P F" and i: "insert x F \<subseteq> A" |
|
482 |
show "P (insert x F)" |
|
483 |
proof (rule insert) |
|
484 |
from i show "x \<in> A" by blast |
|
485 |
from i have "F \<subseteq> A" by blast |
|
486 |
with P show "P F" . |
|
487 |
show "finite F" by fact |
|
488 |
show "x \<notin> F" by fact |
|
489 |
qed |
|
490 |
qed |
|
491 |
||
492 |
lemma finite_empty_induct: |
|
493 |
assumes "finite A" |
|
494 |
assumes "P A" |
|
495 |
and remove: "\<And>a A. finite A \<Longrightarrow> a \<in> A \<Longrightarrow> P A \<Longrightarrow> P (A - {a})" |
|
496 |
shows "P {}" |
|
497 |
proof - |
|
498 |
have "\<And>B. B \<subseteq> A \<Longrightarrow> P (A - B)" |
|
499 |
proof - |
|
500 |
fix B :: "'a set" |
|
501 |
assume "B \<subseteq> A" |
|
502 |
with `finite A` have "finite B" by (rule rev_finite_subset) |
|
503 |
from this `B \<subseteq> A` show "P (A - B)" |
|
504 |
proof induct |
|
505 |
case empty |
|
506 |
from `P A` show ?case by simp |
|
507 |
next |
|
508 |
case (insert b B) |
|
509 |
have "P (A - B - {b})" |
|
510 |
proof (rule remove) |
|
511 |
from `finite A` show "finite (A - B)" by induct auto |
|
512 |
from insert show "b \<in> A - B" by simp |
|
513 |
from insert show "P (A - B)" by simp |
|
514 |
qed |
|
515 |
also have "A - B - {b} = A - insert b B" by (rule Diff_insert [symmetric]) |
|
516 |
finally show ?case . |
|
517 |
qed |
|
518 |
qed |
|
519 |
then have "P (A - A)" by blast |
|
520 |
then show ?thesis by simp |
|
31441 | 521 |
qed |
522 |
||
26441 | 523 |
subsection {* Class @{text finite} *} |
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
524 |
|
29797 | 525 |
class finite = |
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
526 |
assumes finite_UNIV: "finite (UNIV \<Colon> 'a set)" |
27430 | 527 |
begin |
528 |
||
529 |
lemma finite [simp]: "finite (A \<Colon> 'a set)" |
|
26441 | 530 |
by (rule subset_UNIV finite_UNIV finite_subset)+ |
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
531 |
|
43866
8a50dc70cbff
moving UNIV = ... equations to their proper theories
haftmann
parents:
42875
diff
changeset
|
532 |
lemma finite_code [code]: "finite (A \<Colon> 'a set) \<longleftrightarrow> True" |
40922
4d0f96a54e76
adding code equation for finiteness of finite types
bulwahn
parents:
40786
diff
changeset
|
533 |
by simp |
4d0f96a54e76
adding code equation for finiteness of finite types
bulwahn
parents:
40786
diff
changeset
|
534 |
|
27430 | 535 |
end |
536 |
||
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
537 |
instance prod :: (finite, finite) finite |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
538 |
by default (simp only: UNIV_Times_UNIV [symmetric] finite_cartesian_product finite) |
26146 | 539 |
|
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
540 |
lemma inj_graph: "inj (%f. {(x, y). y = f x})" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
541 |
by (rule inj_onI, auto simp add: set_eq_iff fun_eq_iff) |
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
542 |
|
26146 | 543 |
instance "fun" :: (finite, finite) finite |
544 |
proof |
|
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
545 |
show "finite (UNIV :: ('a => 'b) set)" |
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
546 |
proof (rule finite_imageD) |
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
547 |
let ?graph = "%f::'a => 'b. {(x, y). y = f x}" |
26792 | 548 |
have "range ?graph \<subseteq> Pow UNIV" by simp |
549 |
moreover have "finite (Pow (UNIV :: ('a * 'b) set))" |
|
550 |
by (simp only: finite_Pow_iff finite) |
|
551 |
ultimately show "finite (range ?graph)" |
|
552 |
by (rule finite_subset) |
|
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
553 |
show "inj ?graph" by (rule inj_graph) |
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
554 |
qed |
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
555 |
qed |
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
556 |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
557 |
instance bool :: finite |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
558 |
by default (simp add: UNIV_bool) |
44831 | 559 |
|
45962 | 560 |
instance set :: (finite) finite |
561 |
by default (simp only: Pow_UNIV [symmetric] finite_Pow_iff finite) |
|
562 |
||
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
563 |
instance unit :: finite |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
564 |
by default (simp add: UNIV_unit) |
44831 | 565 |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
566 |
instance sum :: (finite, finite) finite |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
567 |
by default (simp only: UNIV_Plus_UNIV [symmetric] finite_Plus finite) |
27981 | 568 |
|
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
569 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
570 |
subsection {* A basic fold functional for finite sets *} |
15392 | 571 |
|
572 |
text {* The intended behaviour is |
|
53015
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents:
51622
diff
changeset
|
573 |
@{text "fold f z {x\<^sub>1, ..., x\<^sub>n} = f x\<^sub>1 (\<dots> (f x\<^sub>n z)\<dots>)"} |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
574 |
if @{text f} is ``left-commutative'': |
15392 | 575 |
*} |
576 |
||
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
577 |
locale comp_fun_commute = |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
578 |
fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
579 |
assumes comp_fun_commute: "f y \<circ> f x = f x \<circ> f y" |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
580 |
begin |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
581 |
|
51489 | 582 |
lemma fun_left_comm: "f y (f x z) = f x (f y z)" |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
583 |
using comp_fun_commute by (simp add: fun_eq_iff) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
584 |
|
51489 | 585 |
lemma commute_left_comp: |
586 |
"f y \<circ> (f x \<circ> g) = f x \<circ> (f y \<circ> g)" |
|
587 |
by (simp add: o_assoc comp_fun_commute) |
|
588 |
||
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
589 |
end |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
590 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
591 |
inductive fold_graph :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> bool" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
592 |
for f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" and z :: 'b where |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
593 |
emptyI [intro]: "fold_graph f z {} z" | |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
594 |
insertI [intro]: "x \<notin> A \<Longrightarrow> fold_graph f z A y |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
595 |
\<Longrightarrow> fold_graph f z (insert x A) (f x y)" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
596 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
597 |
inductive_cases empty_fold_graphE [elim!]: "fold_graph f z {} x" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
598 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
599 |
definition fold :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b" where |
51489 | 600 |
"fold f z A = (if finite A then (THE y. fold_graph f z A y) else z)" |
15392 | 601 |
|
15498 | 602 |
text{*A tempting alternative for the definiens is |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
603 |
@{term "if finite A then THE y. fold_graph f z A y else e"}. |
15498 | 604 |
It allows the removal of finiteness assumptions from the theorems |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
605 |
@{text fold_comm}, @{text fold_reindex} and @{text fold_distrib}. |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
606 |
The proofs become ugly. It is not worth the effort. (???) *} |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
607 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
608 |
lemma finite_imp_fold_graph: "finite A \<Longrightarrow> \<exists>x. fold_graph f z A x" |
41656 | 609 |
by (induct rule: finite_induct) auto |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
610 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
611 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
612 |
subsubsection{*From @{const fold_graph} to @{term fold}*} |
15392 | 613 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
614 |
context comp_fun_commute |
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
615 |
begin |
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
616 |
|
51489 | 617 |
lemma fold_graph_finite: |
618 |
assumes "fold_graph f z A y" |
|
619 |
shows "finite A" |
|
620 |
using assms by induct simp_all |
|
621 |
||
36045 | 622 |
lemma fold_graph_insertE_aux: |
623 |
"fold_graph f z A y \<Longrightarrow> a \<in> A \<Longrightarrow> \<exists>y'. y = f a y' \<and> fold_graph f z (A - {a}) y'" |
|
624 |
proof (induct set: fold_graph) |
|
625 |
case (insertI x A y) show ?case |
|
626 |
proof (cases "x = a") |
|
627 |
assume "x = a" with insertI show ?case by auto |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
628 |
next |
36045 | 629 |
assume "x \<noteq> a" |
630 |
then obtain y' where y: "y = f a y'" and y': "fold_graph f z (A - {a}) y'" |
|
631 |
using insertI by auto |
|
42875 | 632 |
have "f x y = f a (f x y')" |
36045 | 633 |
unfolding y by (rule fun_left_comm) |
42875 | 634 |
moreover have "fold_graph f z (insert x A - {a}) (f x y')" |
36045 | 635 |
using y' and `x \<noteq> a` and `x \<notin> A` |
636 |
by (simp add: insert_Diff_if fold_graph.insertI) |
|
42875 | 637 |
ultimately show ?case by fast |
15392 | 638 |
qed |
36045 | 639 |
qed simp |
640 |
||
641 |
lemma fold_graph_insertE: |
|
642 |
assumes "fold_graph f z (insert x A) v" and "x \<notin> A" |
|
643 |
obtains y where "v = f x y" and "fold_graph f z A y" |
|
644 |
using assms by (auto dest: fold_graph_insertE_aux [OF _ insertI1]) |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
645 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
646 |
lemma fold_graph_determ: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
647 |
"fold_graph f z A x \<Longrightarrow> fold_graph f z A y \<Longrightarrow> y = x" |
36045 | 648 |
proof (induct arbitrary: y set: fold_graph) |
649 |
case (insertI x A y v) |
|
650 |
from `fold_graph f z (insert x A) v` and `x \<notin> A` |
|
651 |
obtain y' where "v = f x y'" and "fold_graph f z A y'" |
|
652 |
by (rule fold_graph_insertE) |
|
653 |
from `fold_graph f z A y'` have "y' = y" by (rule insertI) |
|
654 |
with `v = f x y'` show "v = f x y" by simp |
|
655 |
qed fast |
|
15392 | 656 |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
657 |
lemma fold_equality: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
658 |
"fold_graph f z A y \<Longrightarrow> fold f z A = y" |
51489 | 659 |
by (cases "finite A") (auto simp add: fold_def intro: fold_graph_determ dest: fold_graph_finite) |
15392 | 660 |
|
42272 | 661 |
lemma fold_graph_fold: |
662 |
assumes "finite A" |
|
663 |
shows "fold_graph f z A (fold f z A)" |
|
664 |
proof - |
|
665 |
from assms have "\<exists>x. fold_graph f z A x" by (rule finite_imp_fold_graph) |
|
666 |
moreover note fold_graph_determ |
|
667 |
ultimately have "\<exists>!x. fold_graph f z A x" by (rule ex_ex1I) |
|
668 |
then have "fold_graph f z A (The (fold_graph f z A))" by (rule theI') |
|
51489 | 669 |
with assms show ?thesis by (simp add: fold_def) |
42272 | 670 |
qed |
36045 | 671 |
|
51489 | 672 |
text {* The base case for @{text fold}: *} |
15392 | 673 |
|
51489 | 674 |
lemma (in -) fold_infinite [simp]: |
675 |
assumes "\<not> finite A" |
|
676 |
shows "fold f z A = z" |
|
677 |
using assms by (auto simp add: fold_def) |
|
678 |
||
679 |
lemma (in -) fold_empty [simp]: |
|
680 |
"fold f z {} = z" |
|
681 |
by (auto simp add: fold_def) |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
682 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
683 |
text{* The various recursion equations for @{const fold}: *} |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
684 |
|
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
685 |
lemma fold_insert [simp]: |
42875 | 686 |
assumes "finite A" and "x \<notin> A" |
687 |
shows "fold f z (insert x A) = f x (fold f z A)" |
|
688 |
proof (rule fold_equality) |
|
51489 | 689 |
fix z |
42875 | 690 |
from `finite A` have "fold_graph f z A (fold f z A)" by (rule fold_graph_fold) |
51489 | 691 |
with `x \<notin> A` have "fold_graph f z (insert x A) (f x (fold f z A))" by (rule fold_graph.insertI) |
692 |
then show "fold_graph f z (insert x A) (f x (fold f z A))" by simp |
|
42875 | 693 |
qed |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
694 |
|
51489 | 695 |
declare (in -) empty_fold_graphE [rule del] fold_graph.intros [rule del] |
696 |
-- {* No more proofs involve these. *} |
|
697 |
||
698 |
lemma fold_fun_left_comm: |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
699 |
"finite A \<Longrightarrow> f x (fold f z A) = fold f (f x z) A" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
700 |
proof (induct rule: finite_induct) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
701 |
case empty then show ?case by simp |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
702 |
next |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
703 |
case (insert y A) then show ?case |
51489 | 704 |
by (simp add: fun_left_comm [of x]) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
705 |
qed |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
706 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
707 |
lemma fold_insert2: |
51489 | 708 |
"finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A" |
709 |
by (simp add: fold_fun_left_comm) |
|
15392 | 710 |
|
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
711 |
lemma fold_rec: |
42875 | 712 |
assumes "finite A" and "x \<in> A" |
713 |
shows "fold f z A = f x (fold f z (A - {x}))" |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
714 |
proof - |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
715 |
have A: "A = insert x (A - {x})" using `x \<in> A` by blast |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
716 |
then have "fold f z A = fold f z (insert x (A - {x}))" by simp |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
717 |
also have "\<dots> = f x (fold f z (A - {x}))" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
718 |
by (rule fold_insert) (simp add: `finite A`)+ |
15535 | 719 |
finally show ?thesis . |
720 |
qed |
|
721 |
||
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
722 |
lemma fold_insert_remove: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
723 |
assumes "finite A" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
724 |
shows "fold f z (insert x A) = f x (fold f z (A - {x}))" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
725 |
proof - |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
726 |
from `finite A` have "finite (insert x A)" by auto |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
727 |
moreover have "x \<in> insert x A" by auto |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
728 |
ultimately have "fold f z (insert x A) = f x (fold f z (insert x A - {x}))" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
729 |
by (rule fold_rec) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
730 |
then show ?thesis by simp |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
731 |
qed |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
732 |
|
51598
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
733 |
end |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
734 |
|
48619 | 735 |
text{* Other properties of @{const fold}: *} |
736 |
||
737 |
lemma fold_image: |
|
51598
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
738 |
assumes "inj_on g A" |
51489 | 739 |
shows "fold f z (g ` A) = fold (f \<circ> g) z A" |
51598
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
740 |
proof (cases "finite A") |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
741 |
case False with assms show ?thesis by (auto dest: finite_imageD simp add: fold_def) |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
742 |
next |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
743 |
case True |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
744 |
have "fold_graph f z (g ` A) = fold_graph (f \<circ> g) z A" |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
745 |
proof |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
746 |
fix w |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
747 |
show "fold_graph f z (g ` A) w \<longleftrightarrow> fold_graph (f \<circ> g) z A w" (is "?P \<longleftrightarrow> ?Q") |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
748 |
proof |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
749 |
assume ?P then show ?Q using assms |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
750 |
proof (induct "g ` A" w arbitrary: A) |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
751 |
case emptyI then show ?case by (auto intro: fold_graph.emptyI) |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
752 |
next |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
753 |
case (insertI x A r B) |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
754 |
from `inj_on g B` `x \<notin> A` `insert x A = image g B` obtain x' A' where |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
755 |
"x' \<notin> A'" and [simp]: "B = insert x' A'" "x = g x'" "A = g ` A'" |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
756 |
by (rule inj_img_insertE) |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
757 |
from insertI.prems have "fold_graph (f o g) z A' r" |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
758 |
by (auto intro: insertI.hyps) |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
759 |
with `x' \<notin> A'` have "fold_graph (f \<circ> g) z (insert x' A') ((f \<circ> g) x' r)" |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
760 |
by (rule fold_graph.insertI) |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
761 |
then show ?case by simp |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
762 |
qed |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
763 |
next |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
764 |
assume ?Q then show ?P using assms |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
765 |
proof induct |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
766 |
case emptyI thus ?case by (auto intro: fold_graph.emptyI) |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
767 |
next |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
768 |
case (insertI x A r) |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
769 |
from `x \<notin> A` insertI.prems have "g x \<notin> g ` A" by auto |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
770 |
moreover from insertI have "fold_graph f z (g ` A) r" by simp |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
771 |
ultimately have "fold_graph f z (insert (g x) (g ` A)) (f (g x) r)" |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
772 |
by (rule fold_graph.insertI) |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
773 |
then show ?case by simp |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
774 |
qed |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
775 |
qed |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
776 |
qed |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
777 |
with True assms show ?thesis by (auto simp add: fold_def) |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
778 |
qed |
15392 | 779 |
|
49724 | 780 |
lemma fold_cong: |
781 |
assumes "comp_fun_commute f" "comp_fun_commute g" |
|
782 |
assumes "finite A" and cong: "\<And>x. x \<in> A \<Longrightarrow> f x = g x" |
|
51489 | 783 |
and "s = t" and "A = B" |
784 |
shows "fold f s A = fold g t B" |
|
49724 | 785 |
proof - |
51489 | 786 |
have "fold f s A = fold g s A" |
49724 | 787 |
using `finite A` cong proof (induct A) |
788 |
case empty then show ?case by simp |
|
789 |
next |
|
790 |
case (insert x A) |
|
791 |
interpret f: comp_fun_commute f by (fact `comp_fun_commute f`) |
|
792 |
interpret g: comp_fun_commute g by (fact `comp_fun_commute g`) |
|
793 |
from insert show ?case by simp |
|
794 |
qed |
|
795 |
with assms show ?thesis by simp |
|
796 |
qed |
|
797 |
||
798 |
||
51489 | 799 |
text {* A simplified version for idempotent functions: *} |
15480 | 800 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
801 |
locale comp_fun_idem = comp_fun_commute + |
51489 | 802 |
assumes comp_fun_idem: "f x \<circ> f x = f x" |
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
803 |
begin |
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
804 |
|
42869
43b0f61f56d0
use point-free characterization for locale fun_left_comm_idem
haftmann
parents:
42809
diff
changeset
|
805 |
lemma fun_left_idem: "f x (f x z) = f x z" |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
806 |
using comp_fun_idem by (simp add: fun_eq_iff) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
807 |
|
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
808 |
lemma fold_insert_idem: |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
809 |
assumes fin: "finite A" |
51489 | 810 |
shows "fold f z (insert x A) = f x (fold f z A)" |
15480 | 811 |
proof cases |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
812 |
assume "x \<in> A" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
813 |
then obtain B where "A = insert x B" and "x \<notin> B" by (rule set_insert) |
51489 | 814 |
then show ?thesis using assms by (simp add: comp_fun_idem fun_left_idem) |
15480 | 815 |
next |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
816 |
assume "x \<notin> A" then show ?thesis using assms by simp |
15480 | 817 |
qed |
818 |
||
51489 | 819 |
declare fold_insert [simp del] fold_insert_idem [simp] |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
820 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
821 |
lemma fold_insert_idem2: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
822 |
"finite A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A" |
51489 | 823 |
by (simp add: fold_fun_left_comm) |
15484 | 824 |
|
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
825 |
end |
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
826 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
827 |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
828 |
subsubsection {* Liftings to @{text comp_fun_commute} etc. *} |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
829 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
830 |
lemma (in comp_fun_commute) comp_comp_fun_commute: |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
831 |
"comp_fun_commute (f \<circ> g)" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
832 |
proof |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
833 |
qed (simp_all add: comp_fun_commute) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
834 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
835 |
lemma (in comp_fun_idem) comp_comp_fun_idem: |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
836 |
"comp_fun_idem (f \<circ> g)" |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
837 |
by (rule comp_fun_idem.intro, rule comp_comp_fun_commute, unfold_locales) |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
838 |
(simp_all add: comp_fun_idem) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
839 |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
840 |
lemma (in comp_fun_commute) comp_fun_commute_funpow: |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
841 |
"comp_fun_commute (\<lambda>x. f x ^^ g x)" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
842 |
proof |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
843 |
fix y x |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
844 |
show "f y ^^ g y \<circ> f x ^^ g x = f x ^^ g x \<circ> f y ^^ g y" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
845 |
proof (cases "x = y") |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
846 |
case True then show ?thesis by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
847 |
next |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
848 |
case False show ?thesis |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
849 |
proof (induct "g x" arbitrary: g) |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
850 |
case 0 then show ?case by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
851 |
next |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
852 |
case (Suc n g) |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
853 |
have hyp1: "f y ^^ g y \<circ> f x = f x \<circ> f y ^^ g y" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
854 |
proof (induct "g y" arbitrary: g) |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
855 |
case 0 then show ?case by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
856 |
next |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
857 |
case (Suc n g) |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
858 |
def h \<equiv> "\<lambda>z. g z - 1" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
859 |
with Suc have "n = h y" by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
860 |
with Suc have hyp: "f y ^^ h y \<circ> f x = f x \<circ> f y ^^ h y" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
861 |
by auto |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
862 |
from Suc h_def have "g y = Suc (h y)" by simp |
49739 | 863 |
then show ?case by (simp add: comp_assoc hyp) |
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
864 |
(simp add: o_assoc comp_fun_commute) |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
865 |
qed |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
866 |
def h \<equiv> "\<lambda>z. if z = x then g x - 1 else g z" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
867 |
with Suc have "n = h x" by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
868 |
with Suc have "f y ^^ h y \<circ> f x ^^ h x = f x ^^ h x \<circ> f y ^^ h y" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
869 |
by auto |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
870 |
with False h_def have hyp2: "f y ^^ g y \<circ> f x ^^ h x = f x ^^ h x \<circ> f y ^^ g y" by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
871 |
from Suc h_def have "g x = Suc (h x)" by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
872 |
then show ?case by (simp del: funpow.simps add: funpow_Suc_right o_assoc hyp2) |
49739 | 873 |
(simp add: comp_assoc hyp1) |
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
874 |
qed |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
875 |
qed |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
876 |
qed |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
877 |
|
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
878 |
|
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
879 |
subsubsection {* Expressing set operations via @{const fold} *} |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
880 |
|
51489 | 881 |
lemma comp_fun_commute_const: |
882 |
"comp_fun_commute (\<lambda>_. f)" |
|
883 |
proof |
|
884 |
qed rule |
|
885 |
||
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
886 |
lemma comp_fun_idem_insert: |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
887 |
"comp_fun_idem insert" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
888 |
proof |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
889 |
qed auto |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
890 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
891 |
lemma comp_fun_idem_remove: |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
892 |
"comp_fun_idem Set.remove" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
893 |
proof |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
894 |
qed auto |
31992 | 895 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
896 |
lemma (in semilattice_inf) comp_fun_idem_inf: |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
897 |
"comp_fun_idem inf" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
898 |
proof |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
899 |
qed (auto simp add: inf_left_commute) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
900 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
901 |
lemma (in semilattice_sup) comp_fun_idem_sup: |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
902 |
"comp_fun_idem sup" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
903 |
proof |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
904 |
qed (auto simp add: sup_left_commute) |
31992 | 905 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
906 |
lemma union_fold_insert: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
907 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
908 |
shows "A \<union> B = fold insert B A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
909 |
proof - |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
910 |
interpret comp_fun_idem insert by (fact comp_fun_idem_insert) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
911 |
from `finite A` show ?thesis by (induct A arbitrary: B) simp_all |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
912 |
qed |
31992 | 913 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
914 |
lemma minus_fold_remove: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
915 |
assumes "finite A" |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
916 |
shows "B - A = fold Set.remove B A" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
917 |
proof - |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
918 |
interpret comp_fun_idem Set.remove by (fact comp_fun_idem_remove) |
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
919 |
from `finite A` have "fold Set.remove B A = B - A" by (induct A arbitrary: B) auto |
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
920 |
then show ?thesis .. |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
921 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
922 |
|
51489 | 923 |
lemma comp_fun_commute_filter_fold: |
924 |
"comp_fun_commute (\<lambda>x A'. if P x then Set.insert x A' else A')" |
|
48619 | 925 |
proof - |
926 |
interpret comp_fun_idem Set.insert by (fact comp_fun_idem_insert) |
|
927 |
show ?thesis by default (auto simp: fun_eq_iff) |
|
928 |
qed |
|
929 |
||
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
930 |
lemma Set_filter_fold: |
48619 | 931 |
assumes "finite A" |
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
932 |
shows "Set.filter P A = fold (\<lambda>x A'. if P x then Set.insert x A' else A') {} A" |
48619 | 933 |
using assms |
934 |
by (induct A) |
|
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
935 |
(auto simp add: Set.filter_def comp_fun_commute.fold_insert[OF comp_fun_commute_filter_fold]) |
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
936 |
|
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
937 |
lemma inter_Set_filter: |
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
938 |
assumes "finite B" |
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
939 |
shows "A \<inter> B = Set.filter (\<lambda>x. x \<in> A) B" |
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
940 |
using assms |
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
941 |
by (induct B) (auto simp: Set.filter_def) |
48619 | 942 |
|
943 |
lemma image_fold_insert: |
|
944 |
assumes "finite A" |
|
945 |
shows "image f A = fold (\<lambda>k A. Set.insert (f k) A) {} A" |
|
946 |
using assms |
|
947 |
proof - |
|
948 |
interpret comp_fun_commute "\<lambda>k A. Set.insert (f k) A" by default auto |
|
949 |
show ?thesis using assms by (induct A) auto |
|
950 |
qed |
|
951 |
||
952 |
lemma Ball_fold: |
|
953 |
assumes "finite A" |
|
954 |
shows "Ball A P = fold (\<lambda>k s. s \<and> P k) True A" |
|
955 |
using assms |
|
956 |
proof - |
|
957 |
interpret comp_fun_commute "\<lambda>k s. s \<and> P k" by default auto |
|
958 |
show ?thesis using assms by (induct A) auto |
|
959 |
qed |
|
960 |
||
961 |
lemma Bex_fold: |
|
962 |
assumes "finite A" |
|
963 |
shows "Bex A P = fold (\<lambda>k s. s \<or> P k) False A" |
|
964 |
using assms |
|
965 |
proof - |
|
966 |
interpret comp_fun_commute "\<lambda>k s. s \<or> P k" by default auto |
|
967 |
show ?thesis using assms by (induct A) auto |
|
968 |
qed |
|
969 |
||
970 |
lemma comp_fun_commute_Pow_fold: |
|
971 |
"comp_fun_commute (\<lambda>x A. A \<union> Set.insert x ` A)" |
|
972 |
by (clarsimp simp: fun_eq_iff comp_fun_commute_def) blast |
|
973 |
||
974 |
lemma Pow_fold: |
|
975 |
assumes "finite A" |
|
976 |
shows "Pow A = fold (\<lambda>x A. A \<union> Set.insert x ` A) {{}} A" |
|
977 |
using assms |
|
978 |
proof - |
|
979 |
interpret comp_fun_commute "\<lambda>x A. A \<union> Set.insert x ` A" by (rule comp_fun_commute_Pow_fold) |
|
980 |
show ?thesis using assms by (induct A) (auto simp: Pow_insert) |
|
981 |
qed |
|
982 |
||
983 |
lemma fold_union_pair: |
|
984 |
assumes "finite B" |
|
985 |
shows "(\<Union>y\<in>B. {(x, y)}) \<union> A = fold (\<lambda>y. Set.insert (x, y)) A B" |
|
986 |
proof - |
|
987 |
interpret comp_fun_commute "\<lambda>y. Set.insert (x, y)" by default auto |
|
988 |
show ?thesis using assms by (induct B arbitrary: A) simp_all |
|
989 |
qed |
|
990 |
||
991 |
lemma comp_fun_commute_product_fold: |
|
992 |
assumes "finite B" |
|
51489 | 993 |
shows "comp_fun_commute (\<lambda>x z. fold (\<lambda>y. Set.insert (x, y)) z B)" |
48619 | 994 |
by default (auto simp: fold_union_pair[symmetric] assms) |
995 |
||
996 |
lemma product_fold: |
|
997 |
assumes "finite A" |
|
998 |
assumes "finite B" |
|
51489 | 999 |
shows "A \<times> B = fold (\<lambda>x z. fold (\<lambda>y. Set.insert (x, y)) z B) {} A" |
48619 | 1000 |
using assms unfolding Sigma_def |
1001 |
by (induct A) |
|
1002 |
(simp_all add: comp_fun_commute.fold_insert[OF comp_fun_commute_product_fold] fold_union_pair) |
|
1003 |
||
1004 |
||
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1005 |
context complete_lattice |
31992 | 1006 |
begin |
1007 |
||
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1008 |
lemma inf_Inf_fold_inf: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1009 |
assumes "finite A" |
51489 | 1010 |
shows "inf (Inf A) B = fold inf B A" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1011 |
proof - |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1012 |
interpret comp_fun_idem inf by (fact comp_fun_idem_inf) |
51489 | 1013 |
from `finite A` fold_fun_left_comm show ?thesis by (induct A arbitrary: B) |
1014 |
(simp_all add: inf_commute fun_eq_iff) |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1015 |
qed |
31992 | 1016 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1017 |
lemma sup_Sup_fold_sup: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1018 |
assumes "finite A" |
51489 | 1019 |
shows "sup (Sup A) B = fold sup B A" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1020 |
proof - |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1021 |
interpret comp_fun_idem sup by (fact comp_fun_idem_sup) |
51489 | 1022 |
from `finite A` fold_fun_left_comm show ?thesis by (induct A arbitrary: B) |
1023 |
(simp_all add: sup_commute fun_eq_iff) |
|
31992 | 1024 |
qed |
1025 |
||
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1026 |
lemma Inf_fold_inf: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1027 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1028 |
shows "Inf A = fold inf top A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1029 |
using assms inf_Inf_fold_inf [of A top] by (simp add: inf_absorb2) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1030 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1031 |
lemma Sup_fold_sup: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1032 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1033 |
shows "Sup A = fold sup bot A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1034 |
using assms sup_Sup_fold_sup [of A bot] by (simp add: sup_absorb2) |
31992 | 1035 |
|
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1036 |
lemma inf_INF_fold_inf: |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1037 |
assumes "finite A" |
42873
da1253ff1764
point-free characterization of operations on finite sets
haftmann
parents:
42871
diff
changeset
|
1038 |
shows "inf B (INFI A f) = fold (inf \<circ> f) B A" (is "?inf = ?fold") |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1039 |
proof (rule sym) |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1040 |
interpret comp_fun_idem inf by (fact comp_fun_idem_inf) |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1041 |
interpret comp_fun_idem "inf \<circ> f" by (fact comp_comp_fun_idem) |
42873
da1253ff1764
point-free characterization of operations on finite sets
haftmann
parents:
42871
diff
changeset
|
1042 |
from `finite A` show "?fold = ?inf" |
42869
43b0f61f56d0
use point-free characterization for locale fun_left_comm_idem
haftmann
parents:
42809
diff
changeset
|
1043 |
by (induct A arbitrary: B) |
44928
7ef6505bde7f
renamed Complete_Lattices lemmas, removed legacy names
hoelzl
parents:
44919
diff
changeset
|
1044 |
(simp_all add: INF_def inf_left_commute) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1045 |
qed |
31992 | 1046 |
|
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1047 |
lemma sup_SUP_fold_sup: |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1048 |
assumes "finite A" |
42873
da1253ff1764
point-free characterization of operations on finite sets
haftmann
parents:
42871
diff
changeset
|
1049 |
shows "sup B (SUPR A f) = fold (sup \<circ> f) B A" (is "?sup = ?fold") |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1050 |
proof (rule sym) |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1051 |
interpret comp_fun_idem sup by (fact comp_fun_idem_sup) |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1052 |
interpret comp_fun_idem "sup \<circ> f" by (fact comp_comp_fun_idem) |
42873
da1253ff1764
point-free characterization of operations on finite sets
haftmann
parents:
42871
diff
changeset
|
1053 |
from `finite A` show "?fold = ?sup" |
42869
43b0f61f56d0
use point-free characterization for locale fun_left_comm_idem
haftmann
parents:
42809
diff
changeset
|
1054 |
by (induct A arbitrary: B) |
44928
7ef6505bde7f
renamed Complete_Lattices lemmas, removed legacy names
hoelzl
parents:
44919
diff
changeset
|
1055 |
(simp_all add: SUP_def sup_left_commute) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1056 |
qed |
31992 | 1057 |
|
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1058 |
lemma INF_fold_inf: |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1059 |
assumes "finite A" |
42873
da1253ff1764
point-free characterization of operations on finite sets
haftmann
parents:
42871
diff
changeset
|
1060 |
shows "INFI A f = fold (inf \<circ> f) top A" |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1061 |
using assms inf_INF_fold_inf [of A top] by simp |
31992 | 1062 |
|
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1063 |
lemma SUP_fold_sup: |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1064 |
assumes "finite A" |
42873
da1253ff1764
point-free characterization of operations on finite sets
haftmann
parents:
42871
diff
changeset
|
1065 |
shows "SUPR A f = fold (sup \<circ> f) bot A" |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1066 |
using assms sup_SUP_fold_sup [of A bot] by simp |
31992 | 1067 |
|
1068 |
end |
|
1069 |
||
1070 |
||
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1071 |
subsection {* Locales as mini-packages for fold operations *} |
34007
aea892559fc5
tuned lattices theory fragements; generlized some lemmas from sets to lattices
haftmann
parents:
33960
diff
changeset
|
1072 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1073 |
subsubsection {* The natural case *} |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1074 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1075 |
locale folding = |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1076 |
fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" |
51489 | 1077 |
fixes z :: "'b" |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1078 |
assumes comp_fun_commute: "f y \<circ> f x = f x \<circ> f y" |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1079 |
begin |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1080 |
|
54870 | 1081 |
interpretation fold?: comp_fun_commute f |
54867
c21a2465cac1
prefer ephemeral interpretation over interpretation in proof contexts;
haftmann
parents:
54611
diff
changeset
|
1082 |
by default (insert comp_fun_commute, simp add: fun_eq_iff) |
c21a2465cac1
prefer ephemeral interpretation over interpretation in proof contexts;
haftmann
parents:
54611
diff
changeset
|
1083 |
|
51489 | 1084 |
definition F :: "'a set \<Rightarrow> 'b" |
1085 |
where |
|
1086 |
eq_fold: "F A = fold f z A" |
|
1087 |
||
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1088 |
lemma empty [simp]: |
51489 | 1089 |
"F {} = z" |
1090 |
by (simp add: eq_fold) |
|
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1091 |
|
51489 | 1092 |
lemma infinite [simp]: |
1093 |
"\<not> finite A \<Longrightarrow> F A = z" |
|
1094 |
by (simp add: eq_fold) |
|
1095 |
||
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1096 |
lemma insert [simp]: |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1097 |
assumes "finite A" and "x \<notin> A" |
51489 | 1098 |
shows "F (insert x A) = f x (F A)" |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1099 |
proof - |
51489 | 1100 |
from fold_insert assms |
1101 |
have "fold f z (insert x A) = f x (fold f z A)" by simp |
|
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
1102 |
with `finite A` show ?thesis by (simp add: eq_fold fun_eq_iff) |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1103 |
qed |
51489 | 1104 |
|
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1105 |
lemma remove: |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1106 |
assumes "finite A" and "x \<in> A" |
51489 | 1107 |
shows "F A = f x (F (A - {x}))" |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1108 |
proof - |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1109 |
from `x \<in> A` obtain B where A: "A = insert x B" and "x \<notin> B" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1110 |
by (auto dest: mk_disjoint_insert) |
53374
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents:
53015
diff
changeset
|
1111 |
moreover from `finite A` A have "finite B" by simp |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1112 |
ultimately show ?thesis by simp |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1113 |
qed |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1114 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1115 |
lemma insert_remove: |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1116 |
assumes "finite A" |
51489 | 1117 |
shows "F (insert x A) = f x (F (A - {x}))" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1118 |
using assms by (cases "x \<in> A") (simp_all add: remove insert_absorb) |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1119 |
|
34007
aea892559fc5
tuned lattices theory fragements; generlized some lemmas from sets to lattices
haftmann
parents:
33960
diff
changeset
|
1120 |
end |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1121 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1122 |
|
51489 | 1123 |
subsubsection {* With idempotency *} |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1124 |
|
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1125 |
locale folding_idem = folding + |
51489 | 1126 |
assumes comp_fun_idem: "f x \<circ> f x = f x" |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1127 |
begin |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1128 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1129 |
declare insert [simp del] |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1130 |
|
54870 | 1131 |
interpretation fold?: comp_fun_idem f |
54867
c21a2465cac1
prefer ephemeral interpretation over interpretation in proof contexts;
haftmann
parents:
54611
diff
changeset
|
1132 |
by default (insert comp_fun_commute comp_fun_idem, simp add: fun_eq_iff) |
c21a2465cac1
prefer ephemeral interpretation over interpretation in proof contexts;
haftmann
parents:
54611
diff
changeset
|
1133 |
|
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1134 |
lemma insert_idem [simp]: |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1135 |
assumes "finite A" |
51489 | 1136 |
shows "F (insert x A) = f x (F A)" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1137 |
proof - |
51489 | 1138 |
from fold_insert_idem assms |
1139 |
have "fold f z (insert x A) = f x (fold f z A)" by simp |
|
1140 |
with `finite A` show ?thesis by (simp add: eq_fold fun_eq_iff) |
|
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1141 |
qed |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1142 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1143 |
end |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1144 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1145 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1146 |
subsection {* Finite cardinality *} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1147 |
|
51489 | 1148 |
text {* |
1149 |
The traditional definition |
|
1150 |
@{prop "card A \<equiv> LEAST n. EX f. A = {f i | i. i < n}"} |
|
1151 |
is ugly to work with. |
|
1152 |
But now that we have @{const fold} things are easy: |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1153 |
*} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1154 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1155 |
definition card :: "'a set \<Rightarrow> nat" where |
51489 | 1156 |
"card = folding.F (\<lambda>_. Suc) 0" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1157 |
|
51489 | 1158 |
interpretation card!: folding "\<lambda>_. Suc" 0 |
1159 |
where |
|
51546
2e26df807dc7
more uniform style for interpretation and sublocale declarations
haftmann
parents:
51489
diff
changeset
|
1160 |
"folding.F (\<lambda>_. Suc) 0 = card" |
51489 | 1161 |
proof - |
1162 |
show "folding (\<lambda>_. Suc)" by default rule |
|
1163 |
then interpret card!: folding "\<lambda>_. Suc" 0 . |
|
51546
2e26df807dc7
more uniform style for interpretation and sublocale declarations
haftmann
parents:
51489
diff
changeset
|
1164 |
from card_def show "folding.F (\<lambda>_. Suc) 0 = card" by rule |
51489 | 1165 |
qed |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1166 |
|
51489 | 1167 |
lemma card_infinite: |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1168 |
"\<not> finite A \<Longrightarrow> card A = 0" |
51489 | 1169 |
by (fact card.infinite) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1170 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1171 |
lemma card_empty: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1172 |
"card {} = 0" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1173 |
by (fact card.empty) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1174 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1175 |
lemma card_insert_disjoint: |
51489 | 1176 |
"finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> card (insert x A) = Suc (card A)" |
1177 |
by (fact card.insert) |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1178 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1179 |
lemma card_insert_if: |
51489 | 1180 |
"finite A \<Longrightarrow> card (insert x A) = (if x \<in> A then card A else Suc (card A))" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1181 |
by auto (simp add: card.insert_remove card.remove) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1182 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1183 |
lemma card_ge_0_finite: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1184 |
"card A > 0 \<Longrightarrow> finite A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1185 |
by (rule ccontr) simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1186 |
|
54148 | 1187 |
lemma card_0_eq [simp]: |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1188 |
"finite A \<Longrightarrow> card A = 0 \<longleftrightarrow> A = {}" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1189 |
by (auto dest: mk_disjoint_insert) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1190 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1191 |
lemma finite_UNIV_card_ge_0: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1192 |
"finite (UNIV :: 'a set) \<Longrightarrow> card (UNIV :: 'a set) > 0" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1193 |
by (rule ccontr) simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1194 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1195 |
lemma card_eq_0_iff: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1196 |
"card A = 0 \<longleftrightarrow> A = {} \<or> \<not> finite A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1197 |
by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1198 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1199 |
lemma card_gt_0_iff: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1200 |
"0 < card A \<longleftrightarrow> A \<noteq> {} \<and> finite A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1201 |
by (simp add: neq0_conv [symmetric] card_eq_0_iff) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1202 |
|
51489 | 1203 |
lemma card_Suc_Diff1: |
1204 |
"finite A \<Longrightarrow> x \<in> A \<Longrightarrow> Suc (card (A - {x})) = card A" |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1205 |
apply(rule_tac t = A in insert_Diff [THEN subst], assumption) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1206 |
apply(simp del:insert_Diff_single) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1207 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1208 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1209 |
lemma card_Diff_singleton: |
51489 | 1210 |
"finite A \<Longrightarrow> x \<in> A \<Longrightarrow> card (A - {x}) = card A - 1" |
1211 |
by (simp add: card_Suc_Diff1 [symmetric]) |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1212 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1213 |
lemma card_Diff_singleton_if: |
51489 | 1214 |
"finite A \<Longrightarrow> card (A - {x}) = (if x \<in> A then card A - 1 else card A)" |
1215 |
by (simp add: card_Diff_singleton) |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1216 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1217 |
lemma card_Diff_insert[simp]: |
51489 | 1218 |
assumes "finite A" and "a \<in> A" and "a \<notin> B" |
1219 |
shows "card (A - insert a B) = card (A - B) - 1" |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1220 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1221 |
have "A - insert a B = (A - B) - {a}" using assms by blast |
51489 | 1222 |
then show ?thesis using assms by(simp add: card_Diff_singleton) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1223 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1224 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1225 |
lemma card_insert: "finite A ==> card (insert x A) = Suc (card (A - {x}))" |
51489 | 1226 |
by (fact card.insert_remove) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1227 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1228 |
lemma card_insert_le: "finite A ==> card A <= card (insert x A)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1229 |
by (simp add: card_insert_if) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1230 |
|
41987 | 1231 |
lemma card_Collect_less_nat[simp]: "card{i::nat. i < n} = n" |
1232 |
by (induct n) (simp_all add:less_Suc_eq Collect_disj_eq) |
|
1233 |
||
41988 | 1234 |
lemma card_Collect_le_nat[simp]: "card{i::nat. i <= n} = Suc n" |
41987 | 1235 |
using card_Collect_less_nat[of "Suc n"] by(simp add: less_Suc_eq_le) |
1236 |
||
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1237 |
lemma card_mono: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1238 |
assumes "finite B" and "A \<subseteq> B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1239 |
shows "card A \<le> card B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1240 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1241 |
from assms have "finite A" by (auto intro: finite_subset) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1242 |
then show ?thesis using assms proof (induct A arbitrary: B) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1243 |
case empty then show ?case by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1244 |
next |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1245 |
case (insert x A) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1246 |
then have "x \<in> B" by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1247 |
from insert have "A \<subseteq> B - {x}" and "finite (B - {x})" by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1248 |
with insert.hyps have "card A \<le> card (B - {x})" by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1249 |
with `finite A` `x \<notin> A` `finite B` `x \<in> B` show ?case by simp (simp only: card.remove) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1250 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1251 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1252 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1253 |
lemma card_seteq: "finite B ==> (!!A. A <= B ==> card B <= card A ==> A = B)" |
41656 | 1254 |
apply (induct rule: finite_induct) |
1255 |
apply simp |
|
1256 |
apply clarify |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1257 |
apply (subgoal_tac "finite A & A - {x} <= F") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1258 |
prefer 2 apply (blast intro: finite_subset, atomize) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1259 |
apply (drule_tac x = "A - {x}" in spec) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1260 |
apply (simp add: card_Diff_singleton_if split add: split_if_asm) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1261 |
apply (case_tac "card A", auto) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1262 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1263 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1264 |
lemma psubset_card_mono: "finite B ==> A < B ==> card A < card B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1265 |
apply (simp add: psubset_eq linorder_not_le [symmetric]) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1266 |
apply (blast dest: card_seteq) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1267 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1268 |
|
51489 | 1269 |
lemma card_Un_Int: |
1270 |
assumes "finite A" and "finite B" |
|
1271 |
shows "card A + card B = card (A \<union> B) + card (A \<inter> B)" |
|
1272 |
using assms proof (induct A) |
|
1273 |
case empty then show ?case by simp |
|
1274 |
next |
|
1275 |
case (insert x A) then show ?case |
|
1276 |
by (auto simp add: insert_absorb Int_insert_left) |
|
1277 |
qed |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1278 |
|
51489 | 1279 |
lemma card_Un_disjoint: |
1280 |
assumes "finite A" and "finite B" |
|
1281 |
assumes "A \<inter> B = {}" |
|
1282 |
shows "card (A \<union> B) = card A + card B" |
|
1283 |
using assms card_Un_Int [of A B] by simp |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1284 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1285 |
lemma card_Diff_subset: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1286 |
assumes "finite B" and "B \<subseteq> A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1287 |
shows "card (A - B) = card A - card B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1288 |
proof (cases "finite A") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1289 |
case False with assms show ?thesis by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1290 |
next |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1291 |
case True with assms show ?thesis by (induct B arbitrary: A) simp_all |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1292 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1293 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1294 |
lemma card_Diff_subset_Int: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1295 |
assumes AB: "finite (A \<inter> B)" shows "card (A - B) = card A - card (A \<inter> B)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1296 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1297 |
have "A - B = A - A \<inter> B" by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1298 |
thus ?thesis |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1299 |
by (simp add: card_Diff_subset AB) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1300 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1301 |
|
40716 | 1302 |
lemma diff_card_le_card_Diff: |
1303 |
assumes "finite B" shows "card A - card B \<le> card(A - B)" |
|
1304 |
proof- |
|
1305 |
have "card A - card B \<le> card A - card (A \<inter> B)" |
|
1306 |
using card_mono[OF assms Int_lower2, of A] by arith |
|
1307 |
also have "\<dots> = card(A-B)" using assms by(simp add: card_Diff_subset_Int) |
|
1308 |
finally show ?thesis . |
|
1309 |
qed |
|
1310 |
||
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1311 |
lemma card_Diff1_less: "finite A ==> x: A ==> card (A - {x}) < card A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1312 |
apply (rule Suc_less_SucD) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1313 |
apply (simp add: card_Suc_Diff1 del:card_Diff_insert) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1314 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1315 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1316 |
lemma card_Diff2_less: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1317 |
"finite A ==> x: A ==> y: A ==> card (A - {x} - {y}) < card A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1318 |
apply (case_tac "x = y") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1319 |
apply (simp add: card_Diff1_less del:card_Diff_insert) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1320 |
apply (rule less_trans) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1321 |
prefer 2 apply (auto intro!: card_Diff1_less simp del:card_Diff_insert) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1322 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1323 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1324 |
lemma card_Diff1_le: "finite A ==> card (A - {x}) <= card A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1325 |
apply (case_tac "x : A") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1326 |
apply (simp_all add: card_Diff1_less less_imp_le) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1327 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1328 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1329 |
lemma card_psubset: "finite B ==> A \<subseteq> B ==> card A < card B ==> A < B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1330 |
by (erule psubsetI, blast) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1331 |
|
54413
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1332 |
lemma card_le_inj: |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1333 |
assumes fA: "finite A" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1334 |
and fB: "finite B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1335 |
and c: "card A \<le> card B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1336 |
shows "\<exists>f. f ` A \<subseteq> B \<and> inj_on f A" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1337 |
using fA fB c |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1338 |
proof (induct arbitrary: B rule: finite_induct) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1339 |
case empty |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1340 |
then show ?case by simp |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1341 |
next |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1342 |
case (insert x s t) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1343 |
then show ?case |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1344 |
proof (induct rule: finite_induct[OF "insert.prems"(1)]) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1345 |
case 1 |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1346 |
then show ?case by simp |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1347 |
next |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1348 |
case (2 y t) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1349 |
from "2.prems"(1,2,5) "2.hyps"(1,2) have cst: "card s \<le> card t" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1350 |
by simp |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1351 |
from "2.prems"(3) [OF "2.hyps"(1) cst] |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1352 |
obtain f where "f ` s \<subseteq> t" "inj_on f s" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1353 |
by blast |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1354 |
with "2.prems"(2) "2.hyps"(2) show ?case |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1355 |
apply - |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1356 |
apply (rule exI[where x = "\<lambda>z. if z = x then y else f z"]) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1357 |
apply (auto simp add: inj_on_def) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1358 |
done |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1359 |
qed |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1360 |
qed |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1361 |
|
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1362 |
lemma card_subset_eq: |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1363 |
assumes fB: "finite B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1364 |
and AB: "A \<subseteq> B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1365 |
and c: "card A = card B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1366 |
shows "A = B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1367 |
proof - |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1368 |
from fB AB have fA: "finite A" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1369 |
by (auto intro: finite_subset) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1370 |
from fA fB have fBA: "finite (B - A)" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1371 |
by auto |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1372 |
have e: "A \<inter> (B - A) = {}" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1373 |
by blast |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1374 |
have eq: "A \<union> (B - A) = B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1375 |
using AB by blast |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1376 |
from card_Un_disjoint[OF fA fBA e, unfolded eq c] have "card (B - A) = 0" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1377 |
by arith |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1378 |
then have "B - A = {}" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1379 |
unfolding card_eq_0_iff using fA fB by simp |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1380 |
with AB show "A = B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1381 |
by blast |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1382 |
qed |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1383 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1384 |
lemma insert_partition: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1385 |
"\<lbrakk> x \<notin> F; \<forall>c1 \<in> insert x F. \<forall>c2 \<in> insert x F. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {} \<rbrakk> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1386 |
\<Longrightarrow> x \<inter> \<Union> F = {}" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1387 |
by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1388 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1389 |
lemma finite_psubset_induct[consumes 1, case_names psubset]: |
36079
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1390 |
assumes fin: "finite A" |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1391 |
and major: "\<And>A. finite A \<Longrightarrow> (\<And>B. B \<subset> A \<Longrightarrow> P B) \<Longrightarrow> P A" |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1392 |
shows "P A" |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1393 |
using fin |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1394 |
proof (induct A taking: card rule: measure_induct_rule) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1395 |
case (less A) |
36079
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1396 |
have fin: "finite A" by fact |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1397 |
have ih: "\<And>B. \<lbrakk>card B < card A; finite B\<rbrakk> \<Longrightarrow> P B" by fact |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1398 |
{ fix B |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1399 |
assume asm: "B \<subset> A" |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1400 |
from asm have "card B < card A" using psubset_card_mono fin by blast |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1401 |
moreover |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1402 |
from asm have "B \<subseteq> A" by auto |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1403 |
then have "finite B" using fin finite_subset by blast |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1404 |
ultimately |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1405 |
have "P B" using ih by simp |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1406 |
} |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
1407 |
with fin show "P A" using major by blast |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1408 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1409 |
|
54413
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1410 |
lemma finite_induct_select[consumes 1, case_names empty select]: |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1411 |
assumes "finite S" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1412 |
assumes "P {}" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1413 |
assumes select: "\<And>T. T \<subset> S \<Longrightarrow> P T \<Longrightarrow> \<exists>s\<in>S - T. P (insert s T)" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1414 |
shows "P S" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1415 |
proof - |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1416 |
have "0 \<le> card S" by simp |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1417 |
then have "\<exists>T \<subseteq> S. card T = card S \<and> P T" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1418 |
proof (induct rule: dec_induct) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1419 |
case base with `P {}` show ?case |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1420 |
by (intro exI[of _ "{}"]) auto |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1421 |
next |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1422 |
case (step n) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1423 |
then obtain T where T: "T \<subseteq> S" "card T = n" "P T" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1424 |
by auto |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1425 |
with `n < card S` have "T \<subset> S" "P T" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1426 |
by auto |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1427 |
with select[of T] obtain s where "s \<in> S" "s \<notin> T" "P (insert s T)" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1428 |
by auto |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1429 |
with step(2) T `finite S` show ?case |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1430 |
by (intro exI[of _ "insert s T"]) (auto dest: finite_subset) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1431 |
qed |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1432 |
with `finite S` show "P S" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1433 |
by (auto dest: card_subset_eq) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1434 |
qed |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1435 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1436 |
text{* main cardinality theorem *} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1437 |
lemma card_partition [rule_format]: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1438 |
"finite C ==> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1439 |
finite (\<Union> C) --> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1440 |
(\<forall>c\<in>C. card c = k) --> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1441 |
(\<forall>c1 \<in> C. \<forall>c2 \<in> C. c1 \<noteq> c2 --> c1 \<inter> c2 = {}) --> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1442 |
k * card(C) = card (\<Union> C)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1443 |
apply (erule finite_induct, simp) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1444 |
apply (simp add: card_Un_disjoint insert_partition |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1445 |
finite_subset [of _ "\<Union> (insert x F)"]) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1446 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1447 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1448 |
lemma card_eq_UNIV_imp_eq_UNIV: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1449 |
assumes fin: "finite (UNIV :: 'a set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1450 |
and card: "card A = card (UNIV :: 'a set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1451 |
shows "A = (UNIV :: 'a set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1452 |
proof |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1453 |
show "A \<subseteq> UNIV" by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1454 |
show "UNIV \<subseteq> A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1455 |
proof |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1456 |
fix x |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1457 |
show "x \<in> A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1458 |
proof (rule ccontr) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1459 |
assume "x \<notin> A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1460 |
then have "A \<subset> UNIV" by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1461 |
with fin have "card A < card (UNIV :: 'a set)" by (fact psubset_card_mono) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1462 |
with card show False by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1463 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1464 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1465 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1466 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1467 |
text{*The form of a finite set of given cardinality*} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1468 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1469 |
lemma card_eq_SucD: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1470 |
assumes "card A = Suc k" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1471 |
shows "\<exists>b B. A = insert b B & b \<notin> B & card B = k & (k=0 \<longrightarrow> B={})" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1472 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1473 |
have fin: "finite A" using assms by (auto intro: ccontr) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1474 |
moreover have "card A \<noteq> 0" using assms by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1475 |
ultimately obtain b where b: "b \<in> A" by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1476 |
show ?thesis |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1477 |
proof (intro exI conjI) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1478 |
show "A = insert b (A-{b})" using b by blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1479 |
show "b \<notin> A - {b}" by blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1480 |
show "card (A - {b}) = k" and "k = 0 \<longrightarrow> A - {b} = {}" |
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44835
diff
changeset
|
1481 |
using assms b fin by(fastforce dest:mk_disjoint_insert)+ |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1482 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1483 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1484 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1485 |
lemma card_Suc_eq: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1486 |
"(card A = Suc k) = |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1487 |
(\<exists>b B. A = insert b B & b \<notin> B & card B = k & (k=0 \<longrightarrow> B={}))" |
54570 | 1488 |
apply(auto elim!: card_eq_SucD) |
1489 |
apply(subst card.insert) |
|
1490 |
apply(auto simp add: intro:ccontr) |
|
1491 |
done |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1492 |
|
44744 | 1493 |
lemma card_le_Suc_iff: "finite A \<Longrightarrow> |
1494 |
Suc n \<le> card A = (\<exists>a B. A = insert a B \<and> a \<notin> B \<and> n \<le> card B \<and> finite B)" |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44835
diff
changeset
|
1495 |
by (fastforce simp: card_Suc_eq less_eq_nat.simps(2) insert_eq_iff |
44744 | 1496 |
dest: subset_singletonD split: nat.splits if_splits) |
1497 |
||
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1498 |
lemma finite_fun_UNIVD2: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1499 |
assumes fin: "finite (UNIV :: ('a \<Rightarrow> 'b) set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1500 |
shows "finite (UNIV :: 'b set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1501 |
proof - |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1502 |
from fin have "\<And>arbitrary. finite (range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary))" |
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1503 |
by (rule finite_imageI) |
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1504 |
moreover have "\<And>arbitrary. UNIV = range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary)" |
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1505 |
by (rule UNIV_eq_I) auto |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1506 |
ultimately show "finite (UNIV :: 'b set)" by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1507 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1508 |
|
48063
f02b4302d5dd
remove duplicate lemma card_unit in favor of Finite_Set.card_UNIV_unit
huffman
parents:
47221
diff
changeset
|
1509 |
lemma card_UNIV_unit [simp]: "card (UNIV :: unit set) = 1" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1510 |
unfolding UNIV_unit by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1511 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1512 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1513 |
subsubsection {* Cardinality of image *} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1514 |
|
54570 | 1515 |
lemma card_image_le: "finite A ==> card (f ` A) \<le> card A" |
1516 |
by (induct rule: finite_induct) (simp_all add: le_SucI card_insert_if) |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1517 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1518 |
lemma card_image: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1519 |
assumes "inj_on f A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1520 |
shows "card (f ` A) = card A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1521 |
proof (cases "finite A") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1522 |
case True then show ?thesis using assms by (induct A) simp_all |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1523 |
next |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1524 |
case False then have "\<not> finite (f ` A)" using assms by (auto dest: finite_imageD) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1525 |
with False show ?thesis by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1526 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1527 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1528 |
lemma bij_betw_same_card: "bij_betw f A B \<Longrightarrow> card A = card B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1529 |
by(auto simp: card_image bij_betw_def) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1530 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1531 |
lemma endo_inj_surj: "finite A ==> f ` A \<subseteq> A ==> inj_on f A ==> f ` A = A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1532 |
by (simp add: card_seteq card_image) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1533 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1534 |
lemma eq_card_imp_inj_on: |
54570 | 1535 |
assumes "finite A" "card(f ` A) = card A" shows "inj_on f A" |
1536 |
using assms |
|
1537 |
proof (induct rule:finite_induct) |
|
1538 |
case empty show ?case by simp |
|
1539 |
next |
|
1540 |
case (insert x A) |
|
1541 |
then show ?case using card_image_le [of A f] |
|
1542 |
by (simp add: card_insert_if split: if_splits) |
|
1543 |
qed |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1544 |
|
54570 | 1545 |
lemma inj_on_iff_eq_card: "finite A \<Longrightarrow> inj_on f A \<longleftrightarrow> card(f ` A) = card A" |
1546 |
by (blast intro: card_image eq_card_imp_inj_on) |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1547 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1548 |
lemma card_inj_on_le: |
54570 | 1549 |
assumes "inj_on f A" "f ` A \<subseteq> B" "finite B" shows "card A \<le> card B" |
1550 |
proof - |
|
1551 |
have "finite A" using assms |
|
1552 |
by (blast intro: finite_imageD dest: finite_subset) |
|
1553 |
then show ?thesis using assms |
|
1554 |
by (force intro: card_mono simp: card_image [symmetric]) |
|
1555 |
qed |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1556 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1557 |
lemma card_bij_eq: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1558 |
"[|inj_on f A; f ` A \<subseteq> B; inj_on g B; g ` B \<subseteq> A; |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1559 |
finite A; finite B |] ==> card A = card B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1560 |
by (auto intro: le_antisym card_inj_on_le) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1561 |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
1562 |
lemma bij_betw_finite: |
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
1563 |
assumes "bij_betw f A B" |
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
1564 |
shows "finite A \<longleftrightarrow> finite B" |
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
1565 |
using assms unfolding bij_betw_def |
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
1566 |
using finite_imageD[of f A] by auto |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1567 |
|
55020 | 1568 |
lemma inj_on_finite: |
1569 |
assumes "inj_on f A" "f ` A \<le> B" "finite B" |
|
1570 |
shows "finite A" |
|
1571 |
using assms finite_imageD finite_subset by blast |
|
1572 |
||
41656 | 1573 |
|
37466 | 1574 |
subsubsection {* Pigeonhole Principles *} |
1575 |
||
40311 | 1576 |
lemma pigeonhole: "card A > card(f ` A) \<Longrightarrow> ~ inj_on f A " |
37466 | 1577 |
by (auto dest: card_image less_irrefl_nat) |
1578 |
||
1579 |
lemma pigeonhole_infinite: |
|
1580 |
assumes "~ finite A" and "finite(f`A)" |
|
1581 |
shows "EX a0:A. ~finite{a:A. f a = f a0}" |
|
1582 |
proof - |
|
1583 |
have "finite(f`A) \<Longrightarrow> ~ finite A \<Longrightarrow> EX a0:A. ~finite{a:A. f a = f a0}" |
|
1584 |
proof(induct "f`A" arbitrary: A rule: finite_induct) |
|
1585 |
case empty thus ?case by simp |
|
1586 |
next |
|
1587 |
case (insert b F) |
|
1588 |
show ?case |
|
1589 |
proof cases |
|
1590 |
assume "finite{a:A. f a = b}" |
|
1591 |
hence "~ finite(A - {a:A. f a = b})" using `\<not> finite A` by simp |
|
1592 |
also have "A - {a:A. f a = b} = {a:A. f a \<noteq> b}" by blast |
|
1593 |
finally have "~ finite({a:A. f a \<noteq> b})" . |
|
1594 |
from insert(3)[OF _ this] |
|
1595 |
show ?thesis using insert(2,4) by simp (blast intro: rev_finite_subset) |
|
1596 |
next |
|
1597 |
assume 1: "~finite{a:A. f a = b}" |
|
1598 |
hence "{a \<in> A. f a = b} \<noteq> {}" by force |
|
1599 |
thus ?thesis using 1 by blast |
|
1600 |
qed |
|
1601 |
qed |
|
1602 |
from this[OF assms(2,1)] show ?thesis . |
|
1603 |
qed |
|
1604 |
||
1605 |
lemma pigeonhole_infinite_rel: |
|
1606 |
assumes "~finite A" and "finite B" and "ALL a:A. EX b:B. R a b" |
|
1607 |
shows "EX b:B. ~finite{a:A. R a b}" |
|
1608 |
proof - |
|
1609 |
let ?F = "%a. {b:B. R a b}" |
|
1610 |
from finite_Pow_iff[THEN iffD2, OF `finite B`] |
|
1611 |
have "finite(?F ` A)" by(blast intro: rev_finite_subset) |
|
1612 |
from pigeonhole_infinite[where f = ?F, OF assms(1) this] |
|
1613 |
obtain a0 where "a0\<in>A" and 1: "\<not> finite {a\<in>A. ?F a = ?F a0}" .. |
|
1614 |
obtain b0 where "b0 : B" and "R a0 b0" using `a0:A` assms(3) by blast |
|
1615 |
{ assume "finite{a:A. R a b0}" |
|
1616 |
then have "finite {a\<in>A. ?F a = ?F a0}" |
|
1617 |
using `b0 : B` `R a0 b0` by(blast intro: rev_finite_subset) |
|
1618 |
} |
|
1619 |
with 1 `b0 : B` show ?thesis by blast |
|
1620 |
qed |
|
1621 |
||
1622 |
||
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1623 |
subsubsection {* Cardinality of sums *} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1624 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1625 |
lemma card_Plus: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1626 |
assumes "finite A" and "finite B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1627 |
shows "card (A <+> B) = card A + card B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1628 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1629 |
have "Inl`A \<inter> Inr`B = {}" by fast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1630 |
with assms show ?thesis |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1631 |
unfolding Plus_def |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1632 |
by (simp add: card_Un_disjoint card_image) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1633 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1634 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1635 |
lemma card_Plus_conv_if: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1636 |
"card (A <+> B) = (if finite A \<and> finite B then card A + card B else 0)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1637 |
by (auto simp add: card_Plus) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1638 |
|
41987 | 1639 |
text {* Relates to equivalence classes. Based on a theorem of F. Kamm\"uller. *} |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1640 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1641 |
lemma dvd_partition: |
54570 | 1642 |
assumes f: "finite (\<Union>C)" and "\<forall>c\<in>C. k dvd card c" "\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}" |
1643 |
shows "k dvd card (\<Union>C)" |
|
1644 |
proof - |
|
1645 |
have "finite C" |
|
1646 |
by (rule finite_UnionD [OF f]) |
|
1647 |
then show ?thesis using assms |
|
1648 |
proof (induct rule: finite_induct) |
|
1649 |
case empty show ?case by simp |
|
1650 |
next |
|
1651 |
case (insert c C) |
|
1652 |
then show ?case |
|
1653 |
apply simp |
|
1654 |
apply (subst card_Un_disjoint) |
|
1655 |
apply (auto simp add: disjoint_eq_subset_Compl) |
|
1656 |
done |
|
1657 |
qed |
|
1658 |
qed |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1659 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1660 |
subsubsection {* Relating injectivity and surjectivity *} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1661 |
|
54570 | 1662 |
lemma finite_surj_inj: assumes "finite A" "A \<subseteq> f ` A" shows "inj_on f A" |
1663 |
proof - |
|
1664 |
have "f ` A = A" |
|
1665 |
by (rule card_seteq [THEN sym]) (auto simp add: assms card_image_le) |
|
1666 |
then show ?thesis using assms |
|
1667 |
by (simp add: eq_card_imp_inj_on) |
|
1668 |
qed |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1669 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1670 |
lemma finite_UNIV_surj_inj: fixes f :: "'a \<Rightarrow> 'a" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1671 |
shows "finite(UNIV:: 'a set) \<Longrightarrow> surj f \<Longrightarrow> inj f" |
40702 | 1672 |
by (blast intro: finite_surj_inj subset_UNIV) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1673 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1674 |
lemma finite_UNIV_inj_surj: fixes f :: "'a \<Rightarrow> 'a" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1675 |
shows "finite(UNIV:: 'a set) \<Longrightarrow> inj f \<Longrightarrow> surj f" |
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44835
diff
changeset
|
1676 |
by(fastforce simp:surj_def dest!: endo_inj_surj) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1677 |
|
51489 | 1678 |
corollary infinite_UNIV_nat [iff]: |
1679 |
"\<not> finite (UNIV :: nat set)" |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1680 |
proof |
51489 | 1681 |
assume "finite (UNIV :: nat set)" |
1682 |
with finite_UNIV_inj_surj [of Suc] |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1683 |
show False by simp (blast dest: Suc_neq_Zero surjD) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1684 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1685 |
|
54147
97a8ff4e4ac9
killed most "no_atp", to make Sledgehammer more complete
blanchet
parents:
53820
diff
changeset
|
1686 |
lemma infinite_UNIV_char_0: |
51489 | 1687 |
"\<not> finite (UNIV :: 'a::semiring_char_0 set)" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1688 |
proof |
51489 | 1689 |
assume "finite (UNIV :: 'a set)" |
1690 |
with subset_UNIV have "finite (range of_nat :: 'a set)" |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1691 |
by (rule finite_subset) |
51489 | 1692 |
moreover have "inj (of_nat :: nat \<Rightarrow> 'a)" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1693 |
by (simp add: inj_on_def) |
51489 | 1694 |
ultimately have "finite (UNIV :: nat set)" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1695 |
by (rule finite_imageD) |
51489 | 1696 |
then show False |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1697 |
by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1698 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1699 |
|
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
1700 |
hide_const (open) Finite_Set.fold |
46033 | 1701 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1702 |
end |