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