author | nipkow |
Sat, 05 Nov 2022 09:57:51 +0100 | |
changeset 76447 | 391b8db24c66 |
parent 76422 | 2612b3406b61 |
child 77695 | 93531ba2c784 |
permissions | -rw-r--r-- |
12396 | 1 |
(* Title: HOL/Finite_Set.thy |
63612 | 2 |
Author: Tobias Nipkow |
3 |
Author: Lawrence C Paulson |
|
4 |
Author: Markus Wenzel |
|
5 |
Author: Jeremy Avigad |
|
6 |
Author: Andrei Popescu |
|
12396 | 7 |
*) |
8 |
||
60758 | 9 |
section \<open>Finite sets\<close> |
12396 | 10 |
|
15131 | 11 |
theory Finite_Set |
63612 | 12 |
imports Product_Type Sum_Type Fields |
15131 | 13 |
begin |
12396 | 14 |
|
60758 | 15 |
subsection \<open>Predicate for finite sets\<close> |
12396 | 16 |
|
63612 | 17 |
context notes [[inductive_internals]] |
61681
ca53150406c9
option "inductive_defs" controls exposure of def and mono facts;
wenzelm
parents:
61605
diff
changeset
|
18 |
begin |
ca53150406c9
option "inductive_defs" controls exposure of def and mono facts;
wenzelm
parents:
61605
diff
changeset
|
19 |
|
41656 | 20 |
inductive finite :: "'a set \<Rightarrow> bool" |
63612 | 21 |
where |
22 |
emptyI [simp, intro!]: "finite {}" |
|
23 |
| insertI [simp, intro!]: "finite A \<Longrightarrow> finite (insert a A)" |
|
41656 | 24 |
|
61681
ca53150406c9
option "inductive_defs" controls exposure of def and mono facts;
wenzelm
parents:
61605
diff
changeset
|
25 |
end |
ca53150406c9
option "inductive_defs" controls exposure of def and mono facts;
wenzelm
parents:
61605
diff
changeset
|
26 |
|
60758 | 27 |
simproc_setup finite_Collect ("finite (Collect P)") = \<open>K Set_Comprehension_Pointfree.simproc\<close> |
48109
0a58f7eefba2
Integrated set comprehension pointfree simproc.
Rafal Kolanski <rafal.kolanski@nicta.com.au>
parents:
48063
diff
changeset
|
28 |
|
54611
31afce809794
set_comprehension_pointfree simproc causes to many surprises if enabled by default
traytel
parents:
54570
diff
changeset
|
29 |
declare [[simproc del: finite_Collect]] |
31afce809794
set_comprehension_pointfree simproc causes to many surprises if enabled by default
traytel
parents:
54570
diff
changeset
|
30 |
|
41656 | 31 |
lemma finite_induct [case_names empty insert, induct set: finite]: |
61799 | 32 |
\<comment> \<open>Discharging \<open>x \<notin> F\<close> entails extra work.\<close> |
41656 | 33 |
assumes "finite F" |
34 |
assumes "P {}" |
|
35 |
and insert: "\<And>x F. finite F \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)" |
|
36 |
shows "P F" |
|
63404 | 37 |
using \<open>finite F\<close> |
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
38 |
proof induct |
41656 | 39 |
show "P {}" by fact |
63404 | 40 |
next |
41 |
fix x F |
|
42 |
assume F: "finite F" and P: "P F" |
|
41656 | 43 |
show "P (insert x F)" |
44 |
proof cases |
|
45 |
assume "x \<in> F" |
|
63404 | 46 |
then have "insert x F = F" by (rule insert_absorb) |
41656 | 47 |
with P show ?thesis by (simp only:) |
48 |
next |
|
49 |
assume "x \<notin> F" |
|
50 |
from F this P show ?thesis by (rule insert) |
|
51 |
qed |
|
52 |
qed |
|
53 |
||
51622 | 54 |
lemma infinite_finite_induct [case_names infinite empty insert]: |
55 |
assumes infinite: "\<And>A. \<not> finite A \<Longrightarrow> P A" |
|
63404 | 56 |
and empty: "P {}" |
57 |
and insert: "\<And>x F. finite F \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)" |
|
51622 | 58 |
shows "P A" |
59 |
proof (cases "finite A") |
|
63404 | 60 |
case False |
61 |
with infinite show ?thesis . |
|
51622 | 62 |
next |
63404 | 63 |
case True |
64 |
then show ?thesis by (induct A) (fact empty insert)+ |
|
51622 | 65 |
qed |
66 |
||
41656 | 67 |
|
60758 | 68 |
subsubsection \<open>Choice principles\<close> |
12396 | 69 |
|
67443
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents:
63982
diff
changeset
|
70 |
lemma ex_new_if_finite: \<comment> \<open>does not depend on def of finite at all\<close> |
14661 | 71 |
assumes "\<not> finite (UNIV :: 'a set)" and "finite A" |
72 |
shows "\<exists>a::'a. a \<notin> A" |
|
73 |
proof - |
|
28823 | 74 |
from assms have "A \<noteq> UNIV" by blast |
41656 | 75 |
then show ?thesis by blast |
12396 | 76 |
qed |
77 |
||
60758 | 78 |
text \<open>A finite choice principle. Does not need the SOME choice operator.\<close> |
15484 | 79 |
|
63404 | 80 |
lemma finite_set_choice: "finite A \<Longrightarrow> \<forall>x\<in>A. \<exists>y. P x y \<Longrightarrow> \<exists>f. \<forall>x\<in>A. P x (f x)" |
41656 | 81 |
proof (induct rule: finite_induct) |
63404 | 82 |
case empty |
83 |
then show ?case by simp |
|
29923 | 84 |
next |
85 |
case (insert a A) |
|
63404 | 86 |
then obtain f b where f: "\<forall>x\<in>A. P x (f x)" and ab: "P a b" |
87 |
by auto |
|
88 |
show ?case (is "\<exists>f. ?P f") |
|
29923 | 89 |
proof |
63404 | 90 |
show "?P (\<lambda>x. if x = a then b else f x)" |
91 |
using f ab by auto |
|
29923 | 92 |
qed |
93 |
qed |
|
94 |
||
23878 | 95 |
|
60758 | 96 |
subsubsection \<open>Finite sets are the images of initial segments of natural numbers\<close> |
15392 | 97 |
|
15510 | 98 |
lemma finite_imp_nat_seg_image_inj_on: |
63404 | 99 |
assumes "finite A" |
41656 | 100 |
shows "\<exists>(n::nat) f. A = f ` {i. i < n} \<and> inj_on f {i. i < n}" |
63404 | 101 |
using assms |
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
102 |
proof induct |
15392 | 103 |
case empty |
41656 | 104 |
show ?case |
105 |
proof |
|
63404 | 106 |
show "\<exists>f. {} = f ` {i::nat. i < 0} \<and> inj_on f {i. i < 0}" |
107 |
by simp |
|
15510 | 108 |
qed |
15392 | 109 |
next |
110 |
case (insert a A) |
|
23389 | 111 |
have notinA: "a \<notin> A" by fact |
63404 | 112 |
from insert.hyps obtain n f where "A = f ` {i::nat. i < n}" "inj_on f {i. i < n}" |
113 |
by blast |
|
114 |
then have "insert a A = f(n:=a) ` {i. i < Suc n}" and "inj_on (f(n:=a)) {i. i < Suc n}" |
|
115 |
using notinA by (auto simp add: image_def Ball_def inj_on_def less_Suc_eq) |
|
116 |
then show ?case by blast |
|
15392 | 117 |
qed |
118 |
||
63404 | 119 |
lemma nat_seg_image_imp_finite: "A = f ` {i::nat. i < n} \<Longrightarrow> finite A" |
41656 | 120 |
proof (induct n arbitrary: A) |
63404 | 121 |
case 0 |
122 |
then show ?case by simp |
|
15392 | 123 |
next |
124 |
case (Suc n) |
|
125 |
let ?B = "f ` {i. i < n}" |
|
63404 | 126 |
have finB: "finite ?B" by (rule Suc.hyps[OF refl]) |
15392 | 127 |
show ?case |
63404 | 128 |
proof (cases "\<exists>k<n. f n = f k") |
129 |
case True |
|
130 |
then have "A = ?B" |
|
131 |
using Suc.prems by (auto simp:less_Suc_eq) |
|
132 |
then show ?thesis |
|
133 |
using finB by simp |
|
15392 | 134 |
next |
63404 | 135 |
case False |
136 |
then have "A = insert (f n) ?B" |
|
137 |
using Suc.prems by (auto simp:less_Suc_eq) |
|
138 |
then show ?thesis using finB by simp |
|
15392 | 139 |
qed |
140 |
qed |
|
141 |
||
63982 | 142 |
lemma finite_conv_nat_seg_image: "finite A \<longleftrightarrow> (\<exists>n f. A = f ` {i::nat. i < n})" |
41656 | 143 |
by (blast intro: nat_seg_image_imp_finite dest: finite_imp_nat_seg_image_inj_on) |
15392 | 144 |
|
32988 | 145 |
lemma finite_imp_inj_to_nat_seg: |
41656 | 146 |
assumes "finite A" |
63982 | 147 |
shows "\<exists>f n. f ` A = {i::nat. i < n} \<and> inj_on f A" |
32988 | 148 |
proof - |
63404 | 149 |
from finite_imp_nat_seg_image_inj_on [OF \<open>finite A\<close>] |
63612 | 150 |
obtain f and n :: nat where bij: "bij_betw f {i. i<n} A" |
63404 | 151 |
by (auto simp: bij_betw_def) |
33057 | 152 |
let ?f = "the_inv_into {i. i<n} f" |
63404 | 153 |
have "inj_on ?f A \<and> ?f ` A = {i. i<n}" |
33057 | 154 |
by (fold bij_betw_def) (rule bij_betw_the_inv_into[OF bij]) |
63404 | 155 |
then show ?thesis by blast |
32988 | 156 |
qed |
157 |
||
63404 | 158 |
lemma finite_Collect_less_nat [iff]: "finite {n::nat. n < k}" |
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44835
diff
changeset
|
159 |
by (fastforce simp: finite_conv_nat_seg_image) |
29920 | 160 |
|
63404 | 161 |
lemma finite_Collect_le_nat [iff]: "finite {n::nat. n \<le> k}" |
41656 | 162 |
by (simp add: le_eq_less_or_eq Collect_disj_eq) |
15392 | 163 |
|
41656 | 164 |
|
68975
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
165 |
subsection \<open>Finiteness and common set operations\<close> |
12396 | 166 |
|
63404 | 167 |
lemma rev_finite_subset: "finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> finite A" |
41656 | 168 |
proof (induct arbitrary: A rule: finite_induct) |
169 |
case empty |
|
170 |
then show ?case by simp |
|
171 |
next |
|
172 |
case (insert x F A) |
|
63404 | 173 |
have A: "A \<subseteq> insert x F" and r: "A - {x} \<subseteq> F \<Longrightarrow> finite (A - {x})" |
174 |
by fact+ |
|
41656 | 175 |
show "finite A" |
176 |
proof cases |
|
177 |
assume x: "x \<in> A" |
|
178 |
with A have "A - {x} \<subseteq> F" by (simp add: subset_insert_iff) |
|
179 |
with r have "finite (A - {x})" . |
|
63404 | 180 |
then have "finite (insert x (A - {x}))" .. |
181 |
also have "insert x (A - {x}) = A" |
|
182 |
using x by (rule insert_Diff) |
|
41656 | 183 |
finally show ?thesis . |
12396 | 184 |
next |
60595 | 185 |
show ?thesis when "A \<subseteq> F" |
186 |
using that by fact |
|
41656 | 187 |
assume "x \<notin> A" |
63404 | 188 |
with A show "A \<subseteq> F" |
189 |
by (simp add: subset_insert_iff) |
|
12396 | 190 |
qed |
191 |
qed |
|
192 |
||
63404 | 193 |
lemma finite_subset: "A \<subseteq> B \<Longrightarrow> finite B \<Longrightarrow> finite A" |
41656 | 194 |
by (rule rev_finite_subset) |
29901 | 195 |
|
76422 | 196 |
simproc_setup finite ("finite A") = \<open>fn _ => |
197 |
let |
|
198 |
val finite_subset = @{thm finite_subset} |
|
199 |
val Eq_TrueI = @{thm Eq_TrueI} |
|
200 |
||
201 |
fun is_subset A th = case Thm.prop_of th of |
|
202 |
(_ $ (Const (\<^const_name>\<open>less_eq\<close>, Type (\<^type_name>\<open>fun\<close>, [Type (\<^type_name>\<open>set\<close>, _), _])) $ A' $ B)) |
|
203 |
=> if A aconv A' then SOME(B,th) else NONE |
|
204 |
| _ => NONE; |
|
205 |
||
206 |
fun is_finite th = case Thm.prop_of th of |
|
207 |
(_ $ (Const (\<^const_name>\<open>finite\<close>, _) $ A)) => SOME(A,th) |
|
208 |
| _ => NONE; |
|
209 |
||
210 |
fun comb (A,sub_th) (A',fin_th) ths = if A aconv A' then (sub_th,fin_th) :: ths else ths |
|
211 |
||
212 |
fun proc ss ct = |
|
213 |
(let |
|
214 |
val _ $ A = Thm.term_of ct |
|
215 |
val prems = Simplifier.prems_of ss |
|
216 |
val fins = map_filter is_finite prems |
|
217 |
val subsets = map_filter (is_subset A) prems |
|
218 |
in case fold_product comb subsets fins [] of |
|
219 |
(sub_th,fin_th) :: _ => SOME((fin_th RS (sub_th RS finite_subset)) RS Eq_TrueI) |
|
220 |
| _ => NONE |
|
221 |
end) |
|
222 |
in proc end |
|
223 |
\<close> |
|
224 |
||
76447 | 225 |
(* Needs to be used with care *) |
226 |
declare [[simproc del: finite]] |
|
227 |
||
41656 | 228 |
lemma finite_UnI: |
229 |
assumes "finite F" and "finite G" |
|
230 |
shows "finite (F \<union> G)" |
|
231 |
using assms by induct simp_all |
|
31992 | 232 |
|
63404 | 233 |
lemma finite_Un [iff]: "finite (F \<union> G) \<longleftrightarrow> finite F \<and> finite G" |
41656 | 234 |
by (blast intro: finite_UnI finite_subset [of _ "F \<union> G"]) |
31992 | 235 |
|
41656 | 236 |
lemma finite_insert [simp]: "finite (insert a A) \<longleftrightarrow> finite A" |
12396 | 237 |
proof - |
41656 | 238 |
have "finite {a} \<and> finite A \<longleftrightarrow> finite A" by simp |
239 |
then have "finite ({a} \<union> A) \<longleftrightarrow> finite A" by (simp only: finite_Un) |
|
23389 | 240 |
then show ?thesis by simp |
12396 | 241 |
qed |
242 |
||
63404 | 243 |
lemma finite_Int [simp, intro]: "finite F \<or> finite G \<Longrightarrow> finite (F \<inter> G)" |
41656 | 244 |
by (blast intro: finite_subset) |
245 |
||
246 |
lemma finite_Collect_conjI [simp, intro]: |
|
247 |
"finite {x. P x} \<or> finite {x. Q x} \<Longrightarrow> finite {x. P x \<and> Q x}" |
|
248 |
by (simp add: Collect_conj_eq) |
|
249 |
||
250 |
lemma finite_Collect_disjI [simp]: |
|
251 |
"finite {x. P x \<or> Q x} \<longleftrightarrow> finite {x. P x} \<and> finite {x. Q x}" |
|
252 |
by (simp add: Collect_disj_eq) |
|
253 |
||
63404 | 254 |
lemma finite_Diff [simp, intro]: "finite A \<Longrightarrow> finite (A - B)" |
41656 | 255 |
by (rule finite_subset, rule Diff_subset) |
29901 | 256 |
|
257 |
lemma finite_Diff2 [simp]: |
|
41656 | 258 |
assumes "finite B" |
259 |
shows "finite (A - B) \<longleftrightarrow> finite A" |
|
29901 | 260 |
proof - |
63404 | 261 |
have "finite A \<longleftrightarrow> finite ((A - B) \<union> (A \<inter> B))" |
262 |
by (simp add: Un_Diff_Int) |
|
263 |
also have "\<dots> \<longleftrightarrow> finite (A - B)" |
|
264 |
using \<open>finite B\<close> by simp |
|
29901 | 265 |
finally show ?thesis .. |
266 |
qed |
|
267 |
||
63404 | 268 |
lemma finite_Diff_insert [iff]: "finite (A - insert a B) \<longleftrightarrow> finite (A - B)" |
41656 | 269 |
proof - |
270 |
have "finite (A - B) \<longleftrightarrow> finite (A - B - {a})" by simp |
|
271 |
moreover have "A - insert a B = A - B - {a}" by auto |
|
272 |
ultimately show ?thesis by simp |
|
273 |
qed |
|
274 |
||
63404 | 275 |
lemma finite_compl [simp]: |
41656 | 276 |
"finite (A :: 'a set) \<Longrightarrow> finite (- A) \<longleftrightarrow> finite (UNIV :: 'a set)" |
277 |
by (simp add: Compl_eq_Diff_UNIV) |
|
12396 | 278 |
|
63404 | 279 |
lemma finite_Collect_not [simp]: |
41656 | 280 |
"finite {x :: 'a. P x} \<Longrightarrow> finite {x. \<not> P x} \<longleftrightarrow> finite (UNIV :: 'a set)" |
281 |
by (simp add: Collect_neg_eq) |
|
282 |
||
283 |
lemma finite_Union [simp, intro]: |
|
63404 | 284 |
"finite A \<Longrightarrow> (\<And>M. M \<in> A \<Longrightarrow> finite M) \<Longrightarrow> finite (\<Union>A)" |
41656 | 285 |
by (induct rule: finite_induct) simp_all |
286 |
||
287 |
lemma finite_UN_I [intro]: |
|
288 |
"finite A \<Longrightarrow> (\<And>a. a \<in> A \<Longrightarrow> finite (B a)) \<Longrightarrow> finite (\<Union>a\<in>A. B a)" |
|
289 |
by (induct rule: finite_induct) simp_all |
|
29903 | 290 |
|
69275 | 291 |
lemma finite_UN [simp]: "finite A \<Longrightarrow> finite (\<Union>(B ` A)) \<longleftrightarrow> (\<forall>x\<in>A. finite (B x))" |
41656 | 292 |
by (blast intro: finite_subset) |
293 |
||
63404 | 294 |
lemma finite_Inter [intro]: "\<exists>A\<in>M. finite A \<Longrightarrow> finite (\<Inter>M)" |
41656 | 295 |
by (blast intro: Inter_lower finite_subset) |
12396 | 296 |
|
63404 | 297 |
lemma finite_INT [intro]: "\<exists>x\<in>I. finite (A x) \<Longrightarrow> finite (\<Inter>x\<in>I. A x)" |
41656 | 298 |
by (blast intro: INT_lower finite_subset) |
13825 | 299 |
|
63404 | 300 |
lemma finite_imageI [simp, intro]: "finite F \<Longrightarrow> finite (h ` F)" |
41656 | 301 |
by (induct rule: finite_induct) simp_all |
13825 | 302 |
|
63404 | 303 |
lemma finite_image_set [simp]: "finite {x. P x} \<Longrightarrow> finite {f x |x. P x}" |
31768 | 304 |
by (simp add: image_Collect [symmetric]) |
305 |
||
59504
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
59336
diff
changeset
|
306 |
lemma finite_image_set2: |
63404 | 307 |
"finite {x. P x} \<Longrightarrow> finite {y. Q y} \<Longrightarrow> finite {f x y |x y. P x \<and> Q y}" |
59504
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
59336
diff
changeset
|
308 |
by (rule finite_subset [where B = "\<Union>x \<in> {x. P x}. \<Union>y \<in> {y. Q y}. {f x y}"]) auto |
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
59336
diff
changeset
|
309 |
|
41656 | 310 |
lemma finite_imageD: |
42206 | 311 |
assumes "finite (f ` A)" and "inj_on f A" |
312 |
shows "finite A" |
|
63404 | 313 |
using assms |
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
314 |
proof (induct "f ` A" arbitrary: A) |
63404 | 315 |
case empty |
316 |
then show ?case by simp |
|
42206 | 317 |
next |
318 |
case (insert x B) |
|
63404 | 319 |
then have B_A: "insert x B = f ` A" |
320 |
by simp |
|
321 |
then obtain y where "x = f y" and "y \<in> A" |
|
322 |
by blast |
|
323 |
from B_A \<open>x \<notin> B\<close> have "B = f ` A - {x}" |
|
324 |
by blast |
|
325 |
with B_A \<open>x \<notin> B\<close> \<open>x = f y\<close> \<open>inj_on f A\<close> \<open>y \<in> A\<close> have "B = f ` (A - {y})" |
|
69286 | 326 |
by (simp add: inj_on_image_set_diff) |
63404 | 327 |
moreover from \<open>inj_on f A\<close> have "inj_on f (A - {y})" |
328 |
by (rule inj_on_diff) |
|
329 |
ultimately have "finite (A - {y})" |
|
330 |
by (rule insert.hyps) |
|
331 |
then show "finite A" |
|
332 |
by simp |
|
42206 | 333 |
qed |
12396 | 334 |
|
63404 | 335 |
lemma finite_image_iff: "inj_on f A \<Longrightarrow> finite (f ` A) \<longleftrightarrow> finite A" |
336 |
using finite_imageD by blast |
|
62618
f7f2467ab854
Refactoring (moving theorems into better locations), plus a bit of new material
paulson <lp15@cam.ac.uk>
parents:
62481
diff
changeset
|
337 |
|
63404 | 338 |
lemma finite_surj: "finite A \<Longrightarrow> B \<subseteq> f ` A \<Longrightarrow> finite B" |
41656 | 339 |
by (erule finite_subset) (rule finite_imageI) |
12396 | 340 |
|
63404 | 341 |
lemma finite_range_imageI: "finite (range g) \<Longrightarrow> finite (range (\<lambda>x. f (g x)))" |
41656 | 342 |
by (drule finite_imageI) (simp add: range_composition) |
13825 | 343 |
|
41656 | 344 |
lemma finite_subset_image: |
345 |
assumes "finite B" |
|
346 |
shows "B \<subseteq> f ` A \<Longrightarrow> \<exists>C\<subseteq>A. finite C \<and> B = f ` C" |
|
63404 | 347 |
using assms |
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
348 |
proof induct |
63404 | 349 |
case empty |
350 |
then show ?case by simp |
|
41656 | 351 |
next |
63404 | 352 |
case insert |
353 |
then show ?case |
|
71258
d67924987c34
a few new and tidier proofs (mostly about finite sets)
paulson <lp15@cam.ac.uk>
parents:
70723
diff
changeset
|
354 |
by (clarsimp simp del: image_insert simp add: image_insert [symmetric]) blast |
41656 | 355 |
qed |
356 |
||
68975
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
357 |
lemma all_subset_image: "(\<forall>B. B \<subseteq> f ` A \<longrightarrow> P B) \<longleftrightarrow> (\<forall>B. B \<subseteq> A \<longrightarrow> P(f ` B))" |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
358 |
by (safe elim!: subset_imageE) (use image_mono in \<open>blast+\<close>) (* slow *) |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
359 |
|
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
360 |
lemma all_finite_subset_image: |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
361 |
"(\<forall>B. finite B \<and> B \<subseteq> f ` A \<longrightarrow> P B) \<longleftrightarrow> (\<forall>B. finite B \<and> B \<subseteq> A \<longrightarrow> P (f ` B))" |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
362 |
proof safe |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
363 |
fix B :: "'a set" |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
364 |
assume B: "finite B" "B \<subseteq> f ` A" and P: "\<forall>B. finite B \<and> B \<subseteq> A \<longrightarrow> P (f ` B)" |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
365 |
show "P B" |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
366 |
using finite_subset_image [OF B] P by blast |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
367 |
qed blast |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
368 |
|
70178
4900351361b0
Lindelöf spaces and supporting material
paulson <lp15@cam.ac.uk>
parents:
70019
diff
changeset
|
369 |
lemma ex_finite_subset_image: |
68975
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
370 |
"(\<exists>B. finite B \<and> B \<subseteq> f ` A \<and> P B) \<longleftrightarrow> (\<exists>B. finite B \<and> B \<subseteq> A \<and> P (f ` B))" |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
371 |
proof safe |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
372 |
fix B :: "'a set" |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
373 |
assume B: "finite B" "B \<subseteq> f ` A" and "P B" |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
374 |
show "\<exists>B. finite B \<and> B \<subseteq> A \<and> P (f ` B)" |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
375 |
using finite_subset_image [OF B] \<open>P B\<close> by blast |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
376 |
qed blast |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
377 |
|
63404 | 378 |
lemma finite_vimage_IntI: "finite F \<Longrightarrow> inj_on h A \<Longrightarrow> finite (h -` F \<inter> A)" |
68975
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
379 |
proof (induct rule: finite_induct) |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
380 |
case (insert x F) |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
381 |
then show ?case |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
382 |
by (simp add: vimage_insert [of h x F] finite_subset [OF inj_on_vimage_singleton] Int_Un_distrib2) |
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
383 |
qed simp |
13825 | 384 |
|
61762
d50b993b4fb9
Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents:
61681
diff
changeset
|
385 |
lemma finite_finite_vimage_IntI: |
63612 | 386 |
assumes "finite F" |
387 |
and "\<And>y. y \<in> F \<Longrightarrow> finite ((h -` {y}) \<inter> A)" |
|
61762
d50b993b4fb9
Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents:
61681
diff
changeset
|
388 |
shows "finite (h -` F \<inter> A)" |
d50b993b4fb9
Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents:
61681
diff
changeset
|
389 |
proof - |
d50b993b4fb9
Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents:
61681
diff
changeset
|
390 |
have *: "h -` F \<inter> A = (\<Union> y\<in>F. (h -` {y}) \<inter> A)" |
d50b993b4fb9
Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents:
61681
diff
changeset
|
391 |
by blast |
d50b993b4fb9
Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents:
61681
diff
changeset
|
392 |
show ?thesis |
d50b993b4fb9
Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents:
61681
diff
changeset
|
393 |
by (simp only: * assms finite_UN_I) |
d50b993b4fb9
Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents:
61681
diff
changeset
|
394 |
qed |
d50b993b4fb9
Removal of redundant lemmas (diff_less_iff, diff_le_iff) and of the abbreviation Exp. Addition of some new material.
paulson <lp15@cam.ac.uk>
parents:
61681
diff
changeset
|
395 |
|
63404 | 396 |
lemma finite_vimageI: "finite F \<Longrightarrow> inj h \<Longrightarrow> finite (h -` F)" |
43991 | 397 |
using finite_vimage_IntI[of F h UNIV] by auto |
398 |
||
63404 | 399 |
lemma finite_vimageD': "finite (f -` A) \<Longrightarrow> A \<subseteq> range f \<Longrightarrow> finite A" |
400 |
by (auto simp add: subset_image_iff intro: finite_subset[rotated]) |
|
59519
2fb0c0fc62a3
add more general version of finite_vimageD
Andreas Lochbihler
parents:
59504
diff
changeset
|
401 |
|
63404 | 402 |
lemma finite_vimageD: "finite (h -` F) \<Longrightarrow> surj h \<Longrightarrow> finite F" |
403 |
by (auto dest: finite_vimageD') |
|
34111
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
404 |
|
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
405 |
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
|
406 |
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
|
407 |
|
74438
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
paulson <lp15@cam.ac.uk>
parents:
74223
diff
changeset
|
408 |
lemma finite_inverse_image_gen: |
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
paulson <lp15@cam.ac.uk>
parents:
74223
diff
changeset
|
409 |
assumes "finite A" "inj_on f D" |
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
paulson <lp15@cam.ac.uk>
parents:
74223
diff
changeset
|
410 |
shows "finite {j\<in>D. f j \<in> A}" |
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
paulson <lp15@cam.ac.uk>
parents:
74223
diff
changeset
|
411 |
using finite_vimage_IntI [OF assms] |
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
paulson <lp15@cam.ac.uk>
parents:
74223
diff
changeset
|
412 |
by (simp add: Collect_conj_eq inf_commute vimage_def) |
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
paulson <lp15@cam.ac.uk>
parents:
74223
diff
changeset
|
413 |
|
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
paulson <lp15@cam.ac.uk>
parents:
74223
diff
changeset
|
414 |
lemma finite_inverse_image: |
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
paulson <lp15@cam.ac.uk>
parents:
74223
diff
changeset
|
415 |
assumes "finite A" "inj f" |
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
paulson <lp15@cam.ac.uk>
parents:
74223
diff
changeset
|
416 |
shows "finite {j. f j \<in> A}" |
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
paulson <lp15@cam.ac.uk>
parents:
74223
diff
changeset
|
417 |
using finite_inverse_image_gen [OF assms] by simp |
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
paulson <lp15@cam.ac.uk>
parents:
74223
diff
changeset
|
418 |
|
41656 | 419 |
lemma finite_Collect_bex [simp]: |
420 |
assumes "finite A" |
|
421 |
shows "finite {x. \<exists>y\<in>A. Q x y} \<longleftrightarrow> (\<forall>y\<in>A. finite {x. Q x y})" |
|
422 |
proof - |
|
423 |
have "{x. \<exists>y\<in>A. Q x y} = (\<Union>y\<in>A. {x. Q x y})" by auto |
|
424 |
with assms show ?thesis by simp |
|
425 |
qed |
|
12396 | 426 |
|
41656 | 427 |
lemma finite_Collect_bounded_ex [simp]: |
428 |
assumes "finite {y. P y}" |
|
429 |
shows "finite {x. \<exists>y. P y \<and> Q x y} \<longleftrightarrow> (\<forall>y. P y \<longrightarrow> finite {x. Q x y})" |
|
430 |
proof - |
|
63404 | 431 |
have "{x. \<exists>y. P y \<and> Q x y} = (\<Union>y\<in>{y. P y}. {x. Q x y})" |
432 |
by auto |
|
433 |
with assms show ?thesis |
|
434 |
by simp |
|
41656 | 435 |
qed |
29920 | 436 |
|
63404 | 437 |
lemma finite_Plus: "finite A \<Longrightarrow> finite B \<Longrightarrow> finite (A <+> B)" |
41656 | 438 |
by (simp add: Plus_def) |
17022 | 439 |
|
63404 | 440 |
lemma finite_PlusD: |
31080 | 441 |
fixes A :: "'a set" and B :: "'b set" |
442 |
assumes fin: "finite (A <+> B)" |
|
443 |
shows "finite A" "finite B" |
|
444 |
proof - |
|
63404 | 445 |
have "Inl ` A \<subseteq> A <+> B" |
446 |
by auto |
|
447 |
then have "finite (Inl ` A :: ('a + 'b) set)" |
|
448 |
using fin by (rule finite_subset) |
|
449 |
then show "finite A" |
|
450 |
by (rule finite_imageD) (auto intro: inj_onI) |
|
31080 | 451 |
next |
63404 | 452 |
have "Inr ` B \<subseteq> A <+> B" |
453 |
by auto |
|
454 |
then have "finite (Inr ` B :: ('a + 'b) set)" |
|
455 |
using fin by (rule finite_subset) |
|
456 |
then show "finite B" |
|
457 |
by (rule finite_imageD) (auto intro: inj_onI) |
|
31080 | 458 |
qed |
459 |
||
63404 | 460 |
lemma finite_Plus_iff [simp]: "finite (A <+> B) \<longleftrightarrow> finite A \<and> finite B" |
41656 | 461 |
by (auto intro: finite_PlusD finite_Plus) |
31080 | 462 |
|
41656 | 463 |
lemma finite_Plus_UNIV_iff [simp]: |
464 |
"finite (UNIV :: ('a + 'b) set) \<longleftrightarrow> finite (UNIV :: 'a set) \<and> finite (UNIV :: 'b set)" |
|
465 |
by (subst UNIV_Plus_UNIV [symmetric]) (rule finite_Plus_iff) |
|
12396 | 466 |
|
40786
0a54cfc9add3
gave more standard finite set rules simp and intro attribute
nipkow
parents:
40716
diff
changeset
|
467 |
lemma finite_SigmaI [simp, intro]: |
63404 | 468 |
"finite A \<Longrightarrow> (\<And>a. a\<in>A \<Longrightarrow> finite (B a)) \<Longrightarrow> finite (SIGMA a:A. B a)" |
469 |
unfolding Sigma_def by blast |
|
12396 | 470 |
|
51290 | 471 |
lemma finite_SigmaI2: |
472 |
assumes "finite {x\<in>A. B x \<noteq> {}}" |
|
473 |
and "\<And>a. a \<in> A \<Longrightarrow> finite (B a)" |
|
474 |
shows "finite (Sigma A B)" |
|
475 |
proof - |
|
63404 | 476 |
from assms have "finite (Sigma {x\<in>A. B x \<noteq> {}} B)" |
477 |
by auto |
|
478 |
also have "Sigma {x:A. B x \<noteq> {}} B = Sigma A B" |
|
479 |
by auto |
|
51290 | 480 |
finally show ?thesis . |
481 |
qed |
|
482 |
||
63404 | 483 |
lemma finite_cartesian_product: "finite A \<Longrightarrow> finite B \<Longrightarrow> finite (A \<times> B)" |
15402 | 484 |
by (rule finite_SigmaI) |
485 |
||
12396 | 486 |
lemma finite_Prod_UNIV: |
41656 | 487 |
"finite (UNIV :: 'a set) \<Longrightarrow> finite (UNIV :: 'b set) \<Longrightarrow> finite (UNIV :: ('a \<times> 'b) set)" |
488 |
by (simp only: UNIV_Times_UNIV [symmetric] finite_cartesian_product) |
|
12396 | 489 |
|
15409
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
paulson
parents:
15402
diff
changeset
|
490 |
lemma finite_cartesian_productD1: |
42207 | 491 |
assumes "finite (A \<times> B)" and "B \<noteq> {}" |
492 |
shows "finite A" |
|
493 |
proof - |
|
494 |
from assms obtain n f where "A \<times> B = f ` {i::nat. i < n}" |
|
495 |
by (auto simp add: finite_conv_nat_seg_image) |
|
63404 | 496 |
then have "fst ` (A \<times> B) = fst ` f ` {i::nat. i < n}" |
497 |
by simp |
|
60758 | 498 |
with \<open>B \<noteq> {}\<close> have "A = (fst \<circ> f) ` {i::nat. i < n}" |
56154
f0a927235162
more complete set of lemmas wrt. image and composition
haftmann
parents:
55096
diff
changeset
|
499 |
by (simp add: image_comp) |
63404 | 500 |
then have "\<exists>n f. A = f ` {i::nat. i < n}" |
501 |
by blast |
|
42207 | 502 |
then show ?thesis |
503 |
by (auto simp add: finite_conv_nat_seg_image) |
|
504 |
qed |
|
15409
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
paulson
parents:
15402
diff
changeset
|
505 |
|
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
paulson
parents:
15402
diff
changeset
|
506 |
lemma finite_cartesian_productD2: |
42207 | 507 |
assumes "finite (A \<times> B)" and "A \<noteq> {}" |
508 |
shows "finite B" |
|
509 |
proof - |
|
510 |
from assms obtain n f where "A \<times> B = f ` {i::nat. i < n}" |
|
511 |
by (auto simp add: finite_conv_nat_seg_image) |
|
63404 | 512 |
then have "snd ` (A \<times> B) = snd ` f ` {i::nat. i < n}" |
513 |
by simp |
|
60758 | 514 |
with \<open>A \<noteq> {}\<close> have "B = (snd \<circ> f) ` {i::nat. i < n}" |
56154
f0a927235162
more complete set of lemmas wrt. image and composition
haftmann
parents:
55096
diff
changeset
|
515 |
by (simp add: image_comp) |
63404 | 516 |
then have "\<exists>n f. B = f ` {i::nat. i < n}" |
517 |
by blast |
|
42207 | 518 |
then show ?thesis |
519 |
by (auto simp add: finite_conv_nat_seg_image) |
|
520 |
qed |
|
15409
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
paulson
parents:
15402
diff
changeset
|
521 |
|
57025 | 522 |
lemma finite_cartesian_product_iff: |
523 |
"finite (A \<times> B) \<longleftrightarrow> (A = {} \<or> B = {} \<or> (finite A \<and> finite B))" |
|
524 |
by (auto dest: finite_cartesian_productD1 finite_cartesian_productD2 finite_cartesian_product) |
|
525 |
||
63404 | 526 |
lemma finite_prod: |
48175
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
527 |
"finite (UNIV :: ('a \<times> 'b) set) \<longleftrightarrow> finite (UNIV :: 'a set) \<and> finite (UNIV :: 'b set)" |
57025 | 528 |
using finite_cartesian_product_iff[of UNIV UNIV] by simp |
48175
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
529 |
|
63404 | 530 |
lemma finite_Pow_iff [iff]: "finite (Pow A) \<longleftrightarrow> finite A" |
12396 | 531 |
proof |
532 |
assume "finite (Pow A)" |
|
63404 | 533 |
then have "finite ((\<lambda>x. {x}) ` A)" |
63612 | 534 |
by (blast intro: finite_subset) (* somewhat slow *) |
63404 | 535 |
then show "finite A" |
536 |
by (rule finite_imageD [unfolded inj_on_def]) simp |
|
12396 | 537 |
next |
538 |
assume "finite A" |
|
41656 | 539 |
then show "finite (Pow A)" |
35216 | 540 |
by induct (simp_all add: Pow_insert) |
12396 | 541 |
qed |
542 |
||
63404 | 543 |
corollary finite_Collect_subsets [simp, intro]: "finite A \<Longrightarrow> finite {B. B \<subseteq> A}" |
41656 | 544 |
by (simp add: Pow_def [symmetric]) |
29918 | 545 |
|
48175
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
546 |
lemma finite_set: "finite (UNIV :: 'a set set) \<longleftrightarrow> finite (UNIV :: 'a set)" |
63404 | 547 |
by (simp only: finite_Pow_iff Pow_UNIV[symmetric]) |
48175
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
548 |
|
63404 | 549 |
lemma finite_UnionD: "finite (\<Union>A) \<Longrightarrow> finite A" |
41656 | 550 |
by (blast intro: finite_subset [OF subset_Pow_Union]) |
15392 | 551 |
|
67511
a6f5a78712af
include lemmas generally useful for combinatorial proofs
bulwahn
parents:
67457
diff
changeset
|
552 |
lemma finite_bind: |
a6f5a78712af
include lemmas generally useful for combinatorial proofs
bulwahn
parents:
67457
diff
changeset
|
553 |
assumes "finite S" |
a6f5a78712af
include lemmas generally useful for combinatorial proofs
bulwahn
parents:
67457
diff
changeset
|
554 |
assumes "\<forall>x \<in> S. finite (f x)" |
a6f5a78712af
include lemmas generally useful for combinatorial proofs
bulwahn
parents:
67457
diff
changeset
|
555 |
shows "finite (Set.bind S f)" |
a6f5a78712af
include lemmas generally useful for combinatorial proofs
bulwahn
parents:
67457
diff
changeset
|
556 |
using assms by (simp add: bind_UNION) |
a6f5a78712af
include lemmas generally useful for combinatorial proofs
bulwahn
parents:
67457
diff
changeset
|
557 |
|
68463
410818a69ee3
material on finite sets and maps
Lars Hupel <lars.hupel@mytum.de>
parents:
67511
diff
changeset
|
558 |
lemma finite_filter [simp]: "finite S \<Longrightarrow> finite (Set.filter P S)" |
410818a69ee3
material on finite sets and maps
Lars Hupel <lars.hupel@mytum.de>
parents:
67511
diff
changeset
|
559 |
unfolding Set.filter_def by simp |
410818a69ee3
material on finite sets and maps
Lars Hupel <lars.hupel@mytum.de>
parents:
67511
diff
changeset
|
560 |
|
63404 | 561 |
lemma finite_set_of_finite_funs: |
562 |
assumes "finite A" "finite B" |
|
563 |
shows "finite {f. \<forall>x. (x \<in> A \<longrightarrow> f x \<in> B) \<and> (x \<notin> A \<longrightarrow> f x = d)}" (is "finite ?S") |
|
564 |
proof - |
|
53820 | 565 |
let ?F = "\<lambda>f. {(a,b). a \<in> A \<and> b = f a}" |
63404 | 566 |
have "?F ` ?S \<subseteq> Pow(A \<times> B)" |
567 |
by auto |
|
568 |
from finite_subset[OF this] assms have 1: "finite (?F ` ?S)" |
|
569 |
by simp |
|
53820 | 570 |
have 2: "inj_on ?F ?S" |
63612 | 571 |
by (fastforce simp add: inj_on_def set_eq_iff fun_eq_iff) (* somewhat slow *) |
63404 | 572 |
show ?thesis |
573 |
by (rule finite_imageD [OF 1 2]) |
|
53820 | 574 |
qed |
15392 | 575 |
|
58195 | 576 |
lemma not_finite_existsD: |
577 |
assumes "\<not> finite {a. P a}" |
|
578 |
shows "\<exists>a. P a" |
|
579 |
proof (rule classical) |
|
63404 | 580 |
assume "\<not> ?thesis" |
58195 | 581 |
with assms show ?thesis by auto |
582 |
qed |
|
583 |
||
584 |
||
68975
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents:
68521
diff
changeset
|
585 |
subsection \<open>Further induction rules on finite sets\<close> |
41656 | 586 |
|
587 |
lemma finite_ne_induct [case_names singleton insert, consumes 2]: |
|
588 |
assumes "finite F" and "F \<noteq> {}" |
|
589 |
assumes "\<And>x. P {x}" |
|
590 |
and "\<And>x F. finite F \<Longrightarrow> F \<noteq> {} \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)" |
|
591 |
shows "P F" |
|
63404 | 592 |
using assms |
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
593 |
proof induct |
63404 | 594 |
case empty |
595 |
then show ?case by simp |
|
41656 | 596 |
next |
63404 | 597 |
case (insert x F) |
598 |
then show ?case by cases auto |
|
41656 | 599 |
qed |
600 |
||
601 |
lemma finite_subset_induct [consumes 2, case_names empty insert]: |
|
602 |
assumes "finite F" and "F \<subseteq> A" |
|
63612 | 603 |
and empty: "P {}" |
41656 | 604 |
and insert: "\<And>a F. finite F \<Longrightarrow> a \<in> A \<Longrightarrow> a \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert a F)" |
605 |
shows "P F" |
|
63404 | 606 |
using \<open>finite F\<close> \<open>F \<subseteq> A\<close> |
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
607 |
proof induct |
41656 | 608 |
show "P {}" by fact |
31441 | 609 |
next |
41656 | 610 |
fix x F |
63404 | 611 |
assume "finite F" and "x \<notin> F" and P: "F \<subseteq> A \<Longrightarrow> P F" and i: "insert x F \<subseteq> A" |
41656 | 612 |
show "P (insert x F)" |
613 |
proof (rule insert) |
|
614 |
from i show "x \<in> A" by blast |
|
615 |
from i have "F \<subseteq> A" by blast |
|
616 |
with P show "P F" . |
|
617 |
show "finite F" by fact |
|
618 |
show "x \<notin> F" by fact |
|
619 |
qed |
|
620 |
qed |
|
621 |
||
622 |
lemma finite_empty_induct: |
|
623 |
assumes "finite A" |
|
63612 | 624 |
and "P A" |
41656 | 625 |
and remove: "\<And>a A. finite A \<Longrightarrow> a \<in> A \<Longrightarrow> P A \<Longrightarrow> P (A - {a})" |
626 |
shows "P {}" |
|
627 |
proof - |
|
63404 | 628 |
have "P (A - B)" if "B \<subseteq> A" for B :: "'a set" |
41656 | 629 |
proof - |
63404 | 630 |
from \<open>finite A\<close> that have "finite B" |
631 |
by (rule rev_finite_subset) |
|
60758 | 632 |
from this \<open>B \<subseteq> A\<close> show "P (A - B)" |
41656 | 633 |
proof induct |
634 |
case empty |
|
60758 | 635 |
from \<open>P A\<close> show ?case by simp |
41656 | 636 |
next |
637 |
case (insert b B) |
|
638 |
have "P (A - B - {b})" |
|
639 |
proof (rule remove) |
|
63404 | 640 |
from \<open>finite A\<close> show "finite (A - B)" |
641 |
by induct auto |
|
642 |
from insert show "b \<in> A - B" |
|
643 |
by simp |
|
644 |
from insert show "P (A - B)" |
|
645 |
by simp |
|
41656 | 646 |
qed |
63404 | 647 |
also have "A - B - {b} = A - insert b B" |
648 |
by (rule Diff_insert [symmetric]) |
|
41656 | 649 |
finally show ?case . |
650 |
qed |
|
651 |
qed |
|
652 |
then have "P (A - A)" by blast |
|
653 |
then show ?thesis by simp |
|
31441 | 654 |
qed |
655 |
||
58195 | 656 |
lemma finite_update_induct [consumes 1, case_names const update]: |
657 |
assumes finite: "finite {a. f a \<noteq> c}" |
|
63404 | 658 |
and const: "P (\<lambda>a. c)" |
659 |
and update: "\<And>a b f. finite {a. f a \<noteq> c} \<Longrightarrow> f a = c \<Longrightarrow> b \<noteq> c \<Longrightarrow> P f \<Longrightarrow> P (f(a := b))" |
|
58195 | 660 |
shows "P f" |
63404 | 661 |
using finite |
662 |
proof (induct "{a. f a \<noteq> c}" arbitrary: f) |
|
663 |
case empty |
|
664 |
with const show ?case by simp |
|
58195 | 665 |
next |
666 |
case (insert a A) |
|
667 |
then have "A = {a'. (f(a := c)) a' \<noteq> c}" and "f a \<noteq> c" |
|
668 |
by auto |
|
60758 | 669 |
with \<open>finite A\<close> have "finite {a'. (f(a := c)) a' \<noteq> c}" |
58195 | 670 |
by simp |
671 |
have "(f(a := c)) a = c" |
|
672 |
by simp |
|
60758 | 673 |
from insert \<open>A = {a'. (f(a := c)) a' \<noteq> c}\<close> have "P (f(a := c))" |
58195 | 674 |
by simp |
63404 | 675 |
with \<open>finite {a'. (f(a := c)) a' \<noteq> c}\<close> \<open>(f(a := c)) a = c\<close> \<open>f a \<noteq> c\<close> |
676 |
have "P ((f(a := c))(a := f a))" |
|
58195 | 677 |
by (rule update) |
678 |
then show ?case by simp |
|
679 |
qed |
|
680 |
||
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63404
diff
changeset
|
681 |
lemma finite_subset_induct' [consumes 2, case_names empty insert]: |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63404
diff
changeset
|
682 |
assumes "finite F" and "F \<subseteq> A" |
63612 | 683 |
and empty: "P {}" |
684 |
and insert: "\<And>a F. \<lbrakk>finite F; a \<in> A; F \<subseteq> A; a \<notin> F; P F \<rbrakk> \<Longrightarrow> P (insert a F)" |
|
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63404
diff
changeset
|
685 |
shows "P F" |
63915 | 686 |
using assms(1,2) |
687 |
proof induct |
|
688 |
show "P {}" by fact |
|
689 |
next |
|
690 |
fix x F |
|
691 |
assume "finite F" and "x \<notin> F" and |
|
692 |
P: "F \<subseteq> A \<Longrightarrow> P F" and i: "insert x F \<subseteq> A" |
|
693 |
show "P (insert x F)" |
|
694 |
proof (rule insert) |
|
695 |
from i show "x \<in> A" by blast |
|
696 |
from i have "F \<subseteq> A" by blast |
|
697 |
with P show "P F" . |
|
698 |
show "finite F" by fact |
|
699 |
show "x \<notin> F" by fact |
|
700 |
show "F \<subseteq> A" by fact |
|
63561
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63404
diff
changeset
|
701 |
qed |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63404
diff
changeset
|
702 |
qed |
fba08009ff3e
add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents:
63404
diff
changeset
|
703 |
|
58195 | 704 |
|
61799 | 705 |
subsection \<open>Class \<open>finite\<close>\<close> |
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
|
706 |
|
63612 | 707 |
class finite = |
708 |
assumes finite_UNIV: "finite (UNIV :: 'a set)" |
|
27430 | 709 |
begin |
710 |
||
61076 | 711 |
lemma finite [simp]: "finite (A :: 'a set)" |
26441 | 712 |
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
|
713 |
|
61076 | 714 |
lemma finite_code [code]: "finite (A :: 'a set) \<longleftrightarrow> True" |
40922
4d0f96a54e76
adding code equation for finiteness of finite types
bulwahn
parents:
40786
diff
changeset
|
715 |
by simp |
4d0f96a54e76
adding code equation for finiteness of finite types
bulwahn
parents:
40786
diff
changeset
|
716 |
|
27430 | 717 |
end |
718 |
||
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
719 |
instance prod :: (finite, finite) finite |
61169 | 720 |
by standard (simp only: UNIV_Times_UNIV [symmetric] finite_cartesian_product finite) |
26146 | 721 |
|
63404 | 722 |
lemma inj_graph: "inj (\<lambda>f. {(x, y). y = f x})" |
723 |
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
|
724 |
|
26146 | 725 |
instance "fun" :: (finite, finite) finite |
726 |
proof |
|
63404 | 727 |
show "finite (UNIV :: ('a \<Rightarrow> 'b) set)" |
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
|
728 |
proof (rule finite_imageD) |
63404 | 729 |
let ?graph = "\<lambda>f::'a \<Rightarrow> 'b. {(x, y). y = f x}" |
730 |
have "range ?graph \<subseteq> Pow UNIV" |
|
731 |
by simp |
|
26792 | 732 |
moreover have "finite (Pow (UNIV :: ('a * 'b) set))" |
733 |
by (simp only: finite_Pow_iff finite) |
|
734 |
ultimately show "finite (range ?graph)" |
|
735 |
by (rule finite_subset) |
|
63404 | 736 |
show "inj ?graph" |
737 |
by (rule inj_graph) |
|
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
|
738 |
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
|
739 |
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
|
740 |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
741 |
instance bool :: finite |
61169 | 742 |
by standard (simp add: UNIV_bool) |
44831 | 743 |
|
45962 | 744 |
instance set :: (finite) finite |
61169 | 745 |
by standard (simp only: Pow_UNIV [symmetric] finite_Pow_iff finite) |
45962 | 746 |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
747 |
instance unit :: finite |
61169 | 748 |
by standard (simp add: UNIV_unit) |
44831 | 749 |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
750 |
instance sum :: (finite, finite) finite |
61169 | 751 |
by standard (simp only: UNIV_Plus_UNIV [symmetric] finite_Plus finite) |
27981 | 752 |
|
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
|
753 |
|
60758 | 754 |
subsection \<open>A basic fold functional for finite sets\<close> |
15392 | 755 |
|
73832 | 756 |
text \<open> |
757 |
The intended behaviour is \<open>fold f z {x\<^sub>1, \<dots>, x\<^sub>n} = f x\<^sub>1 (\<dots> (f x\<^sub>n z)\<dots>)\<close> |
|
758 |
if \<open>f\<close> is ``left-commutative''. |
|
759 |
The commutativity requirement is relativised to the carrier set \<open>S\<close>: |
|
60758 | 760 |
\<close> |
15392 | 761 |
|
73832 | 762 |
locale comp_fun_commute_on = |
763 |
fixes S :: "'a set" |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
764 |
fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" |
73832 | 765 |
assumes comp_fun_commute_on: "x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> 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
|
766 |
begin |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
767 |
|
73832 | 768 |
lemma fun_left_comm: "x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> f y (f x z) = f x (f y z)" |
769 |
using comp_fun_commute_on 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
|
770 |
|
73832 | 771 |
lemma commute_left_comp: "x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> f y \<circ> (f x \<circ> g) = f x \<circ> (f y \<circ> g)" |
772 |
by (simp add: o_assoc comp_fun_commute_on) |
|
51489 | 773 |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
774 |
end |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
775 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
776 |
inductive fold_graph :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> bool" |
63404 | 777 |
for f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" and z :: 'b |
63612 | 778 |
where |
779 |
emptyI [intro]: "fold_graph f z {} z" |
|
780 |
| insertI [intro]: "x \<notin> A \<Longrightarrow> fold_graph f z A y \<Longrightarrow> fold_graph f z (insert x A) (f x y)" |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
781 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
782 |
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
|
783 |
|
68521 | 784 |
lemma fold_graph_closed_lemma: |
785 |
"fold_graph f z A x \<and> x \<in> B" |
|
786 |
if "fold_graph g z A x" |
|
787 |
"\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> f a b = g a b" |
|
788 |
"\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> g a b \<in> B" |
|
789 |
"z \<in> B" |
|
790 |
using that(1-3) |
|
791 |
proof (induction rule: fold_graph.induct) |
|
792 |
case (insertI x A y) |
|
793 |
have "fold_graph f z A y" "y \<in> B" |
|
794 |
unfolding atomize_conj |
|
795 |
by (rule insertI.IH) (auto intro: insertI.prems) |
|
796 |
then have "g x y \<in> B" and f_eq: "f x y = g x y" |
|
797 |
by (auto simp: insertI.prems) |
|
798 |
moreover have "fold_graph f z (insert x A) (f x y)" |
|
799 |
by (rule fold_graph.insertI; fact) |
|
800 |
ultimately |
|
801 |
show ?case |
|
802 |
by (simp add: f_eq) |
|
803 |
qed (auto intro!: that) |
|
804 |
||
805 |
lemma fold_graph_closed_eq: |
|
806 |
"fold_graph f z A = fold_graph g z A" |
|
807 |
if "\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> f a b = g a b" |
|
808 |
"\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> g a b \<in> B" |
|
809 |
"z \<in> B" |
|
810 |
using fold_graph_closed_lemma[of f z A _ B g] fold_graph_closed_lemma[of g z A _ B f] that |
|
811 |
by auto |
|
812 |
||
63404 | 813 |
definition fold :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b" |
814 |
where "fold f z A = (if finite A then (THE y. fold_graph f z A y) else z)" |
|
15392 | 815 |
|
68521 | 816 |
lemma fold_closed_eq: "fold f z A = fold g z A" |
817 |
if "\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> f a b = g a b" |
|
818 |
"\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> g a b \<in> B" |
|
819 |
"z \<in> B" |
|
820 |
unfolding Finite_Set.fold_def |
|
821 |
by (subst fold_graph_closed_eq[where B=B and g=g]) (auto simp: that) |
|
822 |
||
63404 | 823 |
text \<open> |
73832 | 824 |
A tempting alternative for the definition is |
69593 | 825 |
\<^term>\<open>if finite A then THE y. fold_graph f z A y else e\<close>. |
63404 | 826 |
It allows the removal of finiteness assumptions from the theorems |
827 |
\<open>fold_comm\<close>, \<open>fold_reindex\<close> and \<open>fold_distrib\<close>. |
|
828 |
The proofs become ugly. It is not worth the effort. (???) |
|
829 |
\<close> |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
830 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
831 |
lemma finite_imp_fold_graph: "finite A \<Longrightarrow> \<exists>x. fold_graph f z A x" |
63404 | 832 |
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
|
833 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
834 |
|
69593 | 835 |
subsubsection \<open>From \<^const>\<open>fold_graph\<close> to \<^term>\<open>fold\<close>\<close> |
15392 | 836 |
|
73832 | 837 |
context comp_fun_commute_on |
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
|
838 |
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
|
839 |
|
51489 | 840 |
lemma fold_graph_finite: |
841 |
assumes "fold_graph f z A y" |
|
842 |
shows "finite A" |
|
843 |
using assms by induct simp_all |
|
844 |
||
36045 | 845 |
lemma fold_graph_insertE_aux: |
73832 | 846 |
assumes "A \<subseteq> S" |
847 |
assumes "fold_graph f z A y" "a \<in> A" |
|
848 |
shows "\<exists>y'. y = f a y' \<and> fold_graph f z (A - {a}) y'" |
|
849 |
using assms(2-,1) |
|
36045 | 850 |
proof (induct set: fold_graph) |
63404 | 851 |
case emptyI |
852 |
then show ?case by simp |
|
853 |
next |
|
854 |
case (insertI x A y) |
|
855 |
show ?case |
|
36045 | 856 |
proof (cases "x = a") |
63404 | 857 |
case True |
858 |
with insertI show ?thesis by auto |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
859 |
next |
63404 | 860 |
case False |
36045 | 861 |
then obtain y' where y: "y = f a y'" and y': "fold_graph f z (A - {a}) y'" |
862 |
using insertI by auto |
|
73832 | 863 |
from insertI have "x \<in> S" "a \<in> S" by auto |
864 |
then have "f x y = f a (f x y')" |
|
865 |
unfolding y by (intro fun_left_comm; simp) |
|
42875 | 866 |
moreover have "fold_graph f z (insert x A - {a}) (f x y')" |
60758 | 867 |
using y' and \<open>x \<noteq> a\<close> and \<open>x \<notin> A\<close> |
36045 | 868 |
by (simp add: insert_Diff_if fold_graph.insertI) |
63404 | 869 |
ultimately show ?thesis |
870 |
by fast |
|
15392 | 871 |
qed |
63404 | 872 |
qed |
36045 | 873 |
|
874 |
lemma fold_graph_insertE: |
|
73832 | 875 |
assumes "insert x A \<subseteq> S" |
36045 | 876 |
assumes "fold_graph f z (insert x A) v" and "x \<notin> A" |
877 |
obtains y where "v = f x y" and "fold_graph f z A y" |
|
73832 | 878 |
using assms by (auto dest: fold_graph_insertE_aux[OF \<open>insert x A \<subseteq> S\<close> _ insertI1]) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
879 |
|
73832 | 880 |
lemma fold_graph_determ: |
881 |
assumes "A \<subseteq> S" |
|
882 |
assumes "fold_graph f z A x" "fold_graph f z A y" |
|
883 |
shows "y = x" |
|
884 |
using assms(2-,1) |
|
36045 | 885 |
proof (induct arbitrary: y set: fold_graph) |
63404 | 886 |
case emptyI |
887 |
then show ?case by fast |
|
888 |
next |
|
36045 | 889 |
case (insertI x A y v) |
73832 | 890 |
from \<open>insert x A \<subseteq> S\<close> and \<open>fold_graph f z (insert x A) v\<close> and \<open>x \<notin> A\<close> |
36045 | 891 |
obtain y' where "v = f x y'" and "fold_graph f z A y'" |
892 |
by (rule fold_graph_insertE) |
|
73832 | 893 |
from \<open>fold_graph f z A y'\<close> insertI have "y' = y" |
894 |
by simp |
|
63404 | 895 |
with \<open>v = f x y'\<close> show "v = f x y" |
896 |
by simp |
|
897 |
qed |
|
15392 | 898 |
|
73832 | 899 |
lemma fold_equality: "A \<subseteq> S \<Longrightarrow> fold_graph f z A y \<Longrightarrow> fold f z A = y" |
51489 | 900 |
by (cases "finite A") (auto simp add: fold_def intro: fold_graph_determ dest: fold_graph_finite) |
15392 | 901 |
|
42272 | 902 |
lemma fold_graph_fold: |
73832 | 903 |
assumes "A \<subseteq> S" |
42272 | 904 |
assumes "finite A" |
905 |
shows "fold_graph f z A (fold f z A)" |
|
906 |
proof - |
|
73832 | 907 |
from \<open>finite A\<close> have "\<exists>x. fold_graph f z A x" |
63404 | 908 |
by (rule finite_imp_fold_graph) |
73832 | 909 |
moreover note fold_graph_determ[OF \<open>A \<subseteq> S\<close>] |
63404 | 910 |
ultimately have "\<exists>!x. fold_graph f z A x" |
911 |
by (rule ex_ex1I) |
|
912 |
then have "fold_graph f z A (The (fold_graph f z A))" |
|
913 |
by (rule theI') |
|
914 |
with assms show ?thesis |
|
915 |
by (simp add: fold_def) |
|
42272 | 916 |
qed |
36045 | 917 |
|
61799 | 918 |
text \<open>The base case for \<open>fold\<close>:\<close> |
15392 | 919 |
|
63404 | 920 |
lemma (in -) fold_infinite [simp]: "\<not> finite A \<Longrightarrow> fold f z A = z" |
921 |
by (auto simp: fold_def) |
|
51489 | 922 |
|
63404 | 923 |
lemma (in -) fold_empty [simp]: "fold f z {} = z" |
924 |
by (auto simp: fold_def) |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
925 |
|
69593 | 926 |
text \<open>The various recursion equations for \<^const>\<open>fold\<close>:\<close> |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
927 |
|
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
|
928 |
lemma fold_insert [simp]: |
73832 | 929 |
assumes "insert x A \<subseteq> S" |
42875 | 930 |
assumes "finite A" and "x \<notin> A" |
931 |
shows "fold f z (insert x A) = f x (fold f z A)" |
|
73832 | 932 |
proof (rule fold_equality[OF \<open>insert x A \<subseteq> S\<close>]) |
51489 | 933 |
fix z |
73832 | 934 |
from \<open>insert x A \<subseteq> S\<close> \<open>finite A\<close> have "fold_graph f z A (fold f z A)" |
935 |
by (blast intro: fold_graph_fold) |
|
63404 | 936 |
with \<open>x \<notin> A\<close> have "fold_graph f z (insert x A) (f x (fold f z A))" |
937 |
by (rule fold_graph.insertI) |
|
938 |
then show "fold_graph f z (insert x A) (f x (fold f z A))" |
|
939 |
by simp |
|
42875 | 940 |
qed |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
941 |
|
51489 | 942 |
declare (in -) empty_fold_graphE [rule del] fold_graph.intros [rule del] |
61799 | 943 |
\<comment> \<open>No more proofs involve these.\<close> |
51489 | 944 |
|
73832 | 945 |
lemma fold_fun_left_comm: |
946 |
assumes "insert x A \<subseteq> S" "finite A" |
|
947 |
shows "f x (fold f z A) = fold f (f x z) A" |
|
948 |
using assms(2,1) |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
949 |
proof (induct rule: finite_induct) |
63404 | 950 |
case empty |
951 |
then show ?case by simp |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
952 |
next |
73832 | 953 |
case (insert y F) |
954 |
then have "fold f (f x z) (insert y F) = f y (fold f (f x z) F)" |
|
955 |
by simp |
|
956 |
also have "\<dots> = f x (f y (fold f z F))" |
|
957 |
using insert by (simp add: fun_left_comm[where ?y=x]) |
|
958 |
also have "\<dots> = f x (fold f z (insert y F))" |
|
959 |
proof - |
|
960 |
from insert have "insert y F \<subseteq> S" by simp |
|
961 |
from fold_insert[OF this] insert show ?thesis by simp |
|
962 |
qed |
|
963 |
finally show ?case .. |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
964 |
qed |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
965 |
|
73832 | 966 |
lemma fold_insert2: |
967 |
"insert x A \<subseteq> S \<Longrightarrow> finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A" |
|
51489 | 968 |
by (simp add: fold_fun_left_comm) |
15392 | 969 |
|
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
|
970 |
lemma fold_rec: |
73832 | 971 |
assumes "A \<subseteq> S" |
42875 | 972 |
assumes "finite A" and "x \<in> A" |
973 |
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
|
974 |
proof - |
63404 | 975 |
have A: "A = insert x (A - {x})" |
976 |
using \<open>x \<in> A\<close> by blast |
|
977 |
then have "fold f z A = fold f z (insert x (A - {x}))" |
|
978 |
by simp |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
979 |
also have "\<dots> = f x (fold f z (A - {x}))" |
73832 | 980 |
by (rule fold_insert) (use assms in \<open>auto\<close>) |
15535 | 981 |
finally show ?thesis . |
982 |
qed |
|
983 |
||
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
984 |
lemma fold_insert_remove: |
73832 | 985 |
assumes "insert x A \<subseteq> S" |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
986 |
assumes "finite A" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
987 |
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
|
988 |
proof - |
63404 | 989 |
from \<open>finite A\<close> have "finite (insert x A)" |
990 |
by auto |
|
991 |
moreover have "x \<in> insert x A" |
|
992 |
by auto |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
993 |
ultimately have "fold f z (insert x A) = f x (fold f z (insert x A - {x}))" |
73832 | 994 |
using \<open>insert x A \<subseteq> S\<close> by (blast intro: fold_rec) |
63404 | 995 |
then show ?thesis |
996 |
by simp |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
997 |
qed |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
998 |
|
57598 | 999 |
lemma fold_set_union_disj: |
73832 | 1000 |
assumes "A \<subseteq> S" "B \<subseteq> S" |
57598 | 1001 |
assumes "finite A" "finite B" "A \<inter> B = {}" |
1002 |
shows "Finite_Set.fold f z (A \<union> B) = Finite_Set.fold f (Finite_Set.fold f z A) B" |
|
73832 | 1003 |
using \<open>finite B\<close> assms(1,2,3,5) |
1004 |
proof induct |
|
1005 |
case (insert x F) |
|
1006 |
have "fold f z (A \<union> insert x F) = f x (fold f (fold f z A) F)" |
|
1007 |
using insert by auto |
|
1008 |
also have "\<dots> = fold f (fold f z A) (insert x F)" |
|
1009 |
using insert by (blast intro: fold_insert[symmetric]) |
|
1010 |
finally show ?case . |
|
1011 |
qed simp |
|
1012 |
||
57598 | 1013 |
|
51598
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
1014 |
end |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
1015 |
|
69593 | 1016 |
text \<open>Other properties of \<^const>\<open>fold\<close>:\<close> |
48619 | 1017 |
|
73832 | 1018 |
lemma fold_graph_image: |
1019 |
assumes "inj_on g A" |
|
1020 |
shows "fold_graph f z (g ` A) = fold_graph (f \<circ> g) z A" |
|
1021 |
proof |
|
1022 |
fix w |
|
1023 |
show "fold_graph f z (g ` A) w = fold_graph (f o g) z A w" |
|
1024 |
proof |
|
1025 |
assume "fold_graph f z (g ` A) w" |
|
1026 |
then show "fold_graph (f \<circ> g) z A w" |
|
1027 |
using assms |
|
1028 |
proof (induct "g ` A" w arbitrary: A) |
|
1029 |
case emptyI |
|
1030 |
then show ?case by (auto intro: fold_graph.emptyI) |
|
1031 |
next |
|
1032 |
case (insertI x A r B) |
|
1033 |
from \<open>inj_on g B\<close> \<open>x \<notin> A\<close> \<open>insert x A = image g B\<close> obtain x' A' |
|
1034 |
where "x' \<notin> A'" and [simp]: "B = insert x' A'" "x = g x'" "A = g ` A'" |
|
1035 |
by (rule inj_img_insertE) |
|
1036 |
from insertI.prems have "fold_graph (f \<circ> g) z A' r" |
|
1037 |
by (auto intro: insertI.hyps) |
|
1038 |
with \<open>x' \<notin> A'\<close> have "fold_graph (f \<circ> g) z (insert x' A') ((f \<circ> g) x' r)" |
|
1039 |
by (rule fold_graph.insertI) |
|
1040 |
then show ?case |
|
1041 |
by simp |
|
1042 |
qed |
|
1043 |
next |
|
1044 |
assume "fold_graph (f \<circ> g) z A w" |
|
1045 |
then show "fold_graph f z (g ` A) w" |
|
1046 |
using assms |
|
1047 |
proof induct |
|
1048 |
case emptyI |
|
1049 |
then show ?case |
|
1050 |
by (auto intro: fold_graph.emptyI) |
|
1051 |
next |
|
1052 |
case (insertI x A r) |
|
1053 |
from \<open>x \<notin> A\<close> insertI.prems have "g x \<notin> g ` A" |
|
1054 |
by auto |
|
1055 |
moreover from insertI have "fold_graph f z (g ` A) r" |
|
1056 |
by simp |
|
1057 |
ultimately have "fold_graph f z (insert (g x) (g ` A)) (f (g x) r)" |
|
1058 |
by (rule fold_graph.insertI) |
|
1059 |
then show ?case |
|
1060 |
by simp |
|
1061 |
qed |
|
1062 |
qed |
|
1063 |
qed |
|
1064 |
||
48619 | 1065 |
lemma fold_image: |
51598
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
1066 |
assumes "inj_on g A" |
51489 | 1067 |
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
|
1068 |
proof (cases "finite A") |
63404 | 1069 |
case False |
1070 |
with assms show ?thesis |
|
1071 |
by (auto dest: finite_imageD simp add: fold_def) |
|
51598
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
1072 |
next |
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
1073 |
case True |
73832 | 1074 |
then show ?thesis |
1075 |
by (auto simp add: fold_def fold_graph_image[OF assms]) |
|
51598
5dbe537087aa
generalized lemma fold_image thanks to Peter Lammich
haftmann
parents:
51546
diff
changeset
|
1076 |
qed |
15392 | 1077 |
|
49724 | 1078 |
lemma fold_cong: |
73832 | 1079 |
assumes "comp_fun_commute_on S f" "comp_fun_commute_on S g" |
1080 |
and "A \<subseteq> S" "finite A" |
|
63404 | 1081 |
and cong: "\<And>x. x \<in> A \<Longrightarrow> f x = g x" |
51489 | 1082 |
and "s = t" and "A = B" |
1083 |
shows "fold f s A = fold g t B" |
|
49724 | 1084 |
proof - |
63404 | 1085 |
have "fold f s A = fold g s A" |
73832 | 1086 |
using \<open>finite A\<close> \<open>A \<subseteq> S\<close> cong |
63404 | 1087 |
proof (induct A) |
1088 |
case empty |
|
1089 |
then show ?case by simp |
|
49724 | 1090 |
next |
63404 | 1091 |
case insert |
73832 | 1092 |
interpret f: comp_fun_commute_on S f by (fact \<open>comp_fun_commute_on S f\<close>) |
1093 |
interpret g: comp_fun_commute_on S g by (fact \<open>comp_fun_commute_on S g\<close>) |
|
49724 | 1094 |
from insert show ?case by simp |
1095 |
qed |
|
1096 |
with assms show ?thesis by simp |
|
1097 |
qed |
|
1098 |
||
1099 |
||
60758 | 1100 |
text \<open>A simplified version for idempotent functions:\<close> |
15480 | 1101 |
|
73832 | 1102 |
locale comp_fun_idem_on = comp_fun_commute_on + |
1103 |
assumes comp_fun_idem_on: "x \<in> S \<Longrightarrow> 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
|
1104 |
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
|
1105 |
|
73832 | 1106 |
lemma fun_left_idem: "x \<in> S \<Longrightarrow> f x (f x z) = f x z" |
1107 |
using comp_fun_idem_on 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
|
1108 |
|
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
|
1109 |
lemma fold_insert_idem: |
73832 | 1110 |
assumes "insert x A \<subseteq> S" |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1111 |
assumes fin: "finite A" |
51489 | 1112 |
shows "fold f z (insert x A) = f x (fold f z A)" |
15480 | 1113 |
proof cases |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1114 |
assume "x \<in> A" |
63404 | 1115 |
then obtain B where "A = insert x B" and "x \<notin> B" |
1116 |
by (rule set_insert) |
|
1117 |
then show ?thesis |
|
73832 | 1118 |
using assms by (simp add: comp_fun_idem_on fun_left_idem) |
15480 | 1119 |
next |
63404 | 1120 |
assume "x \<notin> A" |
1121 |
then show ?thesis |
|
73832 | 1122 |
using assms by auto |
15480 | 1123 |
qed |
1124 |
||
51489 | 1125 |
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
|
1126 |
|
73832 | 1127 |
lemma fold_insert_idem2: "insert x A \<subseteq> S \<Longrightarrow> finite A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A" |
51489 | 1128 |
by (simp add: fold_fun_left_comm) |
15484 | 1129 |
|
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
|
1130 |
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
|
1131 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1132 |
|
73832 | 1133 |
subsubsection \<open>Liftings to \<open>comp_fun_commute_on\<close> etc.\<close> |
1134 |
||
1135 |
lemma (in comp_fun_commute_on) comp_comp_fun_commute_on: |
|
1136 |
"range g \<subseteq> S \<Longrightarrow> comp_fun_commute_on R (f \<circ> g)" |
|
1137 |
by standard (force intro: comp_fun_commute_on) |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1138 |
|
73832 | 1139 |
lemma (in comp_fun_idem_on) comp_comp_fun_idem_on: |
1140 |
assumes "range g \<subseteq> S" |
|
1141 |
shows "comp_fun_idem_on R (f \<circ> g)" |
|
1142 |
proof |
|
1143 |
interpret f_g: comp_fun_commute_on R "f o g" |
|
1144 |
by (fact comp_comp_fun_commute_on[OF \<open>range g \<subseteq> S\<close>]) |
|
1145 |
show "x \<in> R \<Longrightarrow> y \<in> R \<Longrightarrow> (f \<circ> g) y \<circ> (f \<circ> g) x = (f \<circ> g) x \<circ> (f \<circ> g) y" for x y |
|
1146 |
by (fact f_g.comp_fun_commute_on) |
|
1147 |
qed (use \<open>range g \<subseteq> S\<close> in \<open>force intro: comp_fun_idem_on\<close>) |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1148 |
|
73832 | 1149 |
lemma (in comp_fun_commute_on) comp_fun_commute_on_funpow: |
1150 |
"comp_fun_commute_on S (\<lambda>x. f x ^^ g x)" |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1151 |
proof |
73832 | 1152 |
fix x y assume "x \<in> S" "y \<in> S" |
1153 |
show "f y ^^ g y \<circ> f x ^^ g x = f x ^^ g x \<circ> f y ^^ g y" |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1154 |
proof (cases "x = y") |
63404 | 1155 |
case True |
1156 |
then show ?thesis by simp |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1157 |
next |
63404 | 1158 |
case False |
1159 |
show ?thesis |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1160 |
proof (induct "g x" arbitrary: g) |
63404 | 1161 |
case 0 |
1162 |
then show ?case by simp |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1163 |
next |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1164 |
case (Suc n g) |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1165 |
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
|
1166 |
proof (induct "g y" arbitrary: g) |
63404 | 1167 |
case 0 |
1168 |
then show ?case by simp |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1169 |
next |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1170 |
case (Suc n g) |
63040 | 1171 |
define h where "h z = g z - 1" for z |
63404 | 1172 |
with Suc have "n = h y" |
1173 |
by simp |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1174 |
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
|
1175 |
by auto |
63404 | 1176 |
from Suc h_def have "g y = Suc (h y)" |
1177 |
by simp |
|
73832 | 1178 |
with \<open>x \<in> S\<close> \<open>y \<in> S\<close> show ?case |
1179 |
by (simp add: comp_assoc hyp) (simp add: o_assoc comp_fun_commute_on) |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1180 |
qed |
63040 | 1181 |
define h where "h z = (if z = x then g x - 1 else g z)" for z |
63404 | 1182 |
with Suc have "n = h x" |
1183 |
by simp |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1184 |
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
|
1185 |
by auto |
63404 | 1186 |
with False h_def have hyp2: "f y ^^ g y \<circ> f x ^^ h x = f x ^^ h x \<circ> f y ^^ g y" |
1187 |
by simp |
|
1188 |
from Suc h_def have "g x = Suc (h x)" |
|
1189 |
by simp |
|
1190 |
then show ?case |
|
1191 |
by (simp del: funpow.simps add: funpow_Suc_right o_assoc hyp2) (simp add: comp_assoc hyp1) |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1192 |
qed |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1193 |
qed |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1194 |
qed |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1195 |
|
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1196 |
|
73832 | 1197 |
subsubsection \<open>\<^term>\<open>UNIV\<close> as carrier set\<close> |
1198 |
||
1199 |
locale comp_fun_commute = |
|
1200 |
fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" |
|
1201 |
assumes comp_fun_commute: "f y \<circ> f x = f x \<circ> f y" |
|
1202 |
begin |
|
1203 |
||
1204 |
lemma (in -) comp_fun_commute_def': "comp_fun_commute f = comp_fun_commute_on UNIV f" |
|
1205 |
unfolding comp_fun_commute_def comp_fun_commute_on_def by blast |
|
1206 |
||
1207 |
text \<open> |
|
1208 |
We abuse the \<open>rewrites\<close> functionality of locales to remove trivial assumptions that |
|
1209 |
result from instantiating the carrier set to \<^term>\<open>UNIV\<close>. |
|
1210 |
\<close> |
|
1211 |
sublocale comp_fun_commute_on UNIV f |
|
1212 |
rewrites "\<And>X. (X \<subseteq> UNIV) \<equiv> True" |
|
1213 |
and "\<And>x. x \<in> UNIV \<equiv> True" |
|
1214 |
and "\<And>P. (True \<Longrightarrow> P) \<equiv> Trueprop P" |
|
1215 |
and "\<And>P Q. (True \<Longrightarrow> PROP P \<Longrightarrow> PROP Q) \<equiv> (PROP P \<Longrightarrow> True \<Longrightarrow> PROP Q)" |
|
1216 |
proof - |
|
1217 |
show "comp_fun_commute_on UNIV f" |
|
1218 |
by standard (simp add: comp_fun_commute) |
|
1219 |
qed simp_all |
|
1220 |
||
1221 |
end |
|
1222 |
||
1223 |
lemma (in comp_fun_commute) comp_comp_fun_commute: "comp_fun_commute (f o g)" |
|
1224 |
unfolding comp_fun_commute_def' by (fact comp_comp_fun_commute_on) |
|
1225 |
||
1226 |
lemma (in comp_fun_commute) comp_fun_commute_funpow: "comp_fun_commute (\<lambda>x. f x ^^ g x)" |
|
1227 |
unfolding comp_fun_commute_def' by (fact comp_fun_commute_on_funpow) |
|
1228 |
||
1229 |
locale comp_fun_idem = comp_fun_commute + |
|
1230 |
assumes comp_fun_idem: "f x o f x = f x" |
|
1231 |
begin |
|
1232 |
||
1233 |
lemma (in -) comp_fun_idem_def': "comp_fun_idem f = comp_fun_idem_on UNIV f" |
|
1234 |
unfolding comp_fun_idem_on_def comp_fun_idem_def comp_fun_commute_def' |
|
1235 |
unfolding comp_fun_idem_axioms_def comp_fun_idem_on_axioms_def |
|
1236 |
by blast |
|
1237 |
||
1238 |
text \<open> |
|
1239 |
Again, we abuse the \<open>rewrites\<close> functionality of locales to remove trivial assumptions that |
|
1240 |
result from instantiating the carrier set to \<^term>\<open>UNIV\<close>. |
|
1241 |
\<close> |
|
1242 |
sublocale comp_fun_idem_on UNIV f |
|
1243 |
rewrites "\<And>X. (X \<subseteq> UNIV) \<equiv> True" |
|
1244 |
and "\<And>x. x \<in> UNIV \<equiv> True" |
|
1245 |
and "\<And>P. (True \<Longrightarrow> P) \<equiv> Trueprop P" |
|
1246 |
and "\<And>P Q. (True \<Longrightarrow> PROP P \<Longrightarrow> PROP Q) \<equiv> (PROP P \<Longrightarrow> True \<Longrightarrow> PROP Q)" |
|
1247 |
proof - |
|
1248 |
show "comp_fun_idem_on UNIV f" |
|
1249 |
by standard (simp_all add: comp_fun_idem comp_fun_commute) |
|
1250 |
qed simp_all |
|
1251 |
||
1252 |
end |
|
1253 |
||
1254 |
lemma (in comp_fun_idem) comp_comp_fun_idem: "comp_fun_idem (f o g)" |
|
1255 |
unfolding comp_fun_idem_def' by (fact comp_comp_fun_idem_on) |
|
1256 |
||
1257 |
||
69593 | 1258 |
subsubsection \<open>Expressing set operations via \<^const>\<open>fold\<close>\<close> |
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
1259 |
|
63404 | 1260 |
lemma comp_fun_commute_const: "comp_fun_commute (\<lambda>_. f)" |
75669
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
75668
diff
changeset
|
1261 |
by standard (rule refl) |
51489 | 1262 |
|
63404 | 1263 |
lemma comp_fun_idem_insert: "comp_fun_idem insert" |
1264 |
by standard auto |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1265 |
|
63404 | 1266 |
lemma comp_fun_idem_remove: "comp_fun_idem Set.remove" |
1267 |
by standard auto |
|
31992 | 1268 |
|
63404 | 1269 |
lemma (in semilattice_inf) comp_fun_idem_inf: "comp_fun_idem inf" |
1270 |
by standard (auto simp add: inf_left_commute) |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1271 |
|
63404 | 1272 |
lemma (in semilattice_sup) comp_fun_idem_sup: "comp_fun_idem sup" |
1273 |
by standard (auto simp add: sup_left_commute) |
|
31992 | 1274 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1275 |
lemma union_fold_insert: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1276 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1277 |
shows "A \<union> B = fold insert B A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1278 |
proof - |
63404 | 1279 |
interpret comp_fun_idem insert |
1280 |
by (fact comp_fun_idem_insert) |
|
1281 |
from \<open>finite A\<close> show ?thesis |
|
1282 |
by (induct A arbitrary: B) simp_all |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1283 |
qed |
31992 | 1284 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1285 |
lemma minus_fold_remove: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1286 |
assumes "finite A" |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1287 |
shows "B - A = fold Set.remove B A" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1288 |
proof - |
63404 | 1289 |
interpret comp_fun_idem Set.remove |
1290 |
by (fact comp_fun_idem_remove) |
|
1291 |
from \<open>finite A\<close> have "fold Set.remove B A = B - A" |
|
63612 | 1292 |
by (induct A arbitrary: B) auto (* slow *) |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1293 |
then show ?thesis .. |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1294 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1295 |
|
51489 | 1296 |
lemma comp_fun_commute_filter_fold: |
1297 |
"comp_fun_commute (\<lambda>x A'. if P x then Set.insert x A' else A')" |
|
63404 | 1298 |
proof - |
48619 | 1299 |
interpret comp_fun_idem Set.insert by (fact comp_fun_idem_insert) |
61169 | 1300 |
show ?thesis by standard (auto simp: fun_eq_iff) |
48619 | 1301 |
qed |
1302 |
||
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
1303 |
lemma Set_filter_fold: |
48619 | 1304 |
assumes "finite A" |
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
1305 |
shows "Set.filter P A = fold (\<lambda>x A'. if P x then Set.insert x A' else A') {} A" |
63404 | 1306 |
using assms |
73832 | 1307 |
proof - |
1308 |
interpret commute_insert: comp_fun_commute "(\<lambda>x A'. if P x then Set.insert x A' else A')" |
|
1309 |
by (fact comp_fun_commute_filter_fold) |
|
1310 |
from \<open>finite A\<close> show ?thesis |
|
1311 |
by induct (auto simp add: Set.filter_def) |
|
1312 |
qed |
|
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
1313 |
|
63404 | 1314 |
lemma inter_Set_filter: |
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
1315 |
assumes "finite B" |
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
1316 |
shows "A \<inter> B = Set.filter (\<lambda>x. x \<in> A) B" |
63404 | 1317 |
using assms |
1318 |
by induct (auto simp: Set.filter_def) |
|
48619 | 1319 |
|
1320 |
lemma image_fold_insert: |
|
1321 |
assumes "finite A" |
|
1322 |
shows "image f A = fold (\<lambda>k A. Set.insert (f k) A) {} A" |
|
1323 |
proof - |
|
63404 | 1324 |
interpret comp_fun_commute "\<lambda>k A. Set.insert (f k) A" |
1325 |
by standard auto |
|
1326 |
show ?thesis |
|
1327 |
using assms by (induct A) auto |
|
48619 | 1328 |
qed |
1329 |
||
1330 |
lemma Ball_fold: |
|
1331 |
assumes "finite A" |
|
1332 |
shows "Ball A P = fold (\<lambda>k s. s \<and> P k) True A" |
|
1333 |
proof - |
|
63404 | 1334 |
interpret comp_fun_commute "\<lambda>k s. s \<and> P k" |
1335 |
by standard auto |
|
1336 |
show ?thesis |
|
1337 |
using assms by (induct A) auto |
|
48619 | 1338 |
qed |
1339 |
||
1340 |
lemma Bex_fold: |
|
1341 |
assumes "finite A" |
|
1342 |
shows "Bex A P = fold (\<lambda>k s. s \<or> P k) False A" |
|
1343 |
proof - |
|
63404 | 1344 |
interpret comp_fun_commute "\<lambda>k s. s \<or> P k" |
1345 |
by standard auto |
|
1346 |
show ?thesis |
|
1347 |
using assms by (induct A) auto |
|
48619 | 1348 |
qed |
1349 |
||
63404 | 1350 |
lemma comp_fun_commute_Pow_fold: "comp_fun_commute (\<lambda>x A. A \<union> Set.insert x ` A)" |
73832 | 1351 |
by (clarsimp simp: fun_eq_iff comp_fun_commute_def) blast |
48619 | 1352 |
|
1353 |
lemma Pow_fold: |
|
1354 |
assumes "finite A" |
|
1355 |
shows "Pow A = fold (\<lambda>x A. A \<union> Set.insert x ` A) {{}} A" |
|
1356 |
proof - |
|
63404 | 1357 |
interpret comp_fun_commute "\<lambda>x A. A \<union> Set.insert x ` A" |
1358 |
by (rule comp_fun_commute_Pow_fold) |
|
1359 |
show ?thesis |
|
1360 |
using assms by (induct A) (auto simp: Pow_insert) |
|
48619 | 1361 |
qed |
1362 |
||
1363 |
lemma fold_union_pair: |
|
1364 |
assumes "finite B" |
|
1365 |
shows "(\<Union>y\<in>B. {(x, y)}) \<union> A = fold (\<lambda>y. Set.insert (x, y)) A B" |
|
1366 |
proof - |
|
63404 | 1367 |
interpret comp_fun_commute "\<lambda>y. Set.insert (x, y)" |
1368 |
by standard auto |
|
1369 |
show ?thesis |
|
1370 |
using assms by (induct arbitrary: A) simp_all |
|
48619 | 1371 |
qed |
1372 |
||
63404 | 1373 |
lemma comp_fun_commute_product_fold: |
1374 |
"finite B \<Longrightarrow> comp_fun_commute (\<lambda>x z. fold (\<lambda>y. Set.insert (x, y)) z B)" |
|
1375 |
by standard (auto simp: fold_union_pair [symmetric]) |
|
48619 | 1376 |
|
1377 |
lemma product_fold: |
|
63404 | 1378 |
assumes "finite A" "finite B" |
51489 | 1379 |
shows "A \<times> B = fold (\<lambda>x z. fold (\<lambda>y. Set.insert (x, y)) z B) {} A" |
73832 | 1380 |
proof - |
1381 |
interpret commute_product: comp_fun_commute "(\<lambda>x z. fold (\<lambda>y. Set.insert (x, y)) z B)" |
|
1382 |
by (fact comp_fun_commute_product_fold[OF \<open>finite B\<close>]) |
|
1383 |
from assms show ?thesis unfolding Sigma_def |
|
1384 |
by (induct A) (simp_all add: fold_union_pair) |
|
1385 |
qed |
|
48619 | 1386 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1387 |
context complete_lattice |
31992 | 1388 |
begin |
1389 |
||
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1390 |
lemma inf_Inf_fold_inf: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1391 |
assumes "finite A" |
51489 | 1392 |
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
|
1393 |
proof - |
63404 | 1394 |
interpret comp_fun_idem inf |
1395 |
by (fact comp_fun_idem_inf) |
|
1396 |
from \<open>finite A\<close> fold_fun_left_comm show ?thesis |
|
1397 |
by (induct A arbitrary: B) (simp_all add: inf_commute fun_eq_iff) |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1398 |
qed |
31992 | 1399 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1400 |
lemma sup_Sup_fold_sup: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1401 |
assumes "finite A" |
51489 | 1402 |
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
|
1403 |
proof - |
63404 | 1404 |
interpret comp_fun_idem sup |
1405 |
by (fact comp_fun_idem_sup) |
|
1406 |
from \<open>finite A\<close> fold_fun_left_comm show ?thesis |
|
1407 |
by (induct A arbitrary: B) (simp_all add: sup_commute fun_eq_iff) |
|
31992 | 1408 |
qed |
1409 |
||
63404 | 1410 |
lemma Inf_fold_inf: "finite A \<Longrightarrow> Inf A = fold inf top A" |
1411 |
using inf_Inf_fold_inf [of A top] by (simp add: inf_absorb2) |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1412 |
|
63404 | 1413 |
lemma Sup_fold_sup: "finite A \<Longrightarrow> Sup A = fold sup bot A" |
1414 |
using sup_Sup_fold_sup [of A bot] by (simp add: sup_absorb2) |
|
31992 | 1415 |
|
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1416 |
lemma inf_INF_fold_inf: |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1417 |
assumes "finite A" |
69275 | 1418 |
shows "inf B (\<Sqinter>(f ` A)) = fold (inf \<circ> f) B A" (is "?inf = ?fold") |
63404 | 1419 |
proof - |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1420 |
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
|
1421 |
interpret comp_fun_idem "inf \<circ> f" by (fact comp_comp_fun_idem) |
63404 | 1422 |
from \<open>finite A\<close> have "?fold = ?inf" |
1423 |
by (induct A arbitrary: B) (simp_all add: inf_left_commute) |
|
1424 |
then show ?thesis .. |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1425 |
qed |
31992 | 1426 |
|
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
1427 |
lemma sup_SUP_fold_sup: |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1428 |
assumes "finite A" |
69275 | 1429 |
shows "sup B (\<Squnion>(f ` A)) = fold (sup \<circ> f) B A" (is "?sup = ?fold") |
63404 | 1430 |
proof - |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1431 |
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
|
1432 |
interpret comp_fun_idem "sup \<circ> f" by (fact comp_comp_fun_idem) |
63404 | 1433 |
from \<open>finite A\<close> have "?fold = ?sup" |
1434 |
by (induct A arbitrary: B) (simp_all add: sup_left_commute) |
|
1435 |
then show ?thesis .. |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1436 |
qed |
31992 | 1437 |
|
69275 | 1438 |
lemma INF_fold_inf: "finite A \<Longrightarrow> \<Sqinter>(f ` A) = fold (inf \<circ> f) top A" |
63404 | 1439 |
using inf_INF_fold_inf [of A top] by simp |
31992 | 1440 |
|
69275 | 1441 |
lemma SUP_fold_sup: "finite A \<Longrightarrow> \<Squnion>(f ` A) = fold (sup \<circ> f) bot A" |
63404 | 1442 |
using sup_SUP_fold_sup [of A bot] by simp |
31992 | 1443 |
|
72097 | 1444 |
lemma finite_Inf_in: |
1445 |
assumes "finite A" "A\<noteq>{}" and inf: "\<And>x y. \<lbrakk>x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> inf x y \<in> A" |
|
1446 |
shows "Inf A \<in> A" |
|
1447 |
proof - |
|
1448 |
have "Inf B \<in> A" if "B \<le> A" "B\<noteq>{}" for B |
|
1449 |
using finite_subset [OF \<open>B \<subseteq> A\<close> \<open>finite A\<close>] that |
|
1450 |
by (induction B) (use inf in \<open>force+\<close>) |
|
1451 |
then show ?thesis |
|
1452 |
by (simp add: assms) |
|
1453 |
qed |
|
1454 |
||
1455 |
lemma finite_Sup_in: |
|
1456 |
assumes "finite A" "A\<noteq>{}" and sup: "\<And>x y. \<lbrakk>x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> sup x y \<in> A" |
|
1457 |
shows "Sup A \<in> A" |
|
1458 |
proof - |
|
1459 |
have "Sup B \<in> A" if "B \<le> A" "B\<noteq>{}" for B |
|
1460 |
using finite_subset [OF \<open>B \<subseteq> A\<close> \<open>finite A\<close>] that |
|
1461 |
by (induction B) (use sup in \<open>force+\<close>) |
|
1462 |
then show ?thesis |
|
1463 |
by (simp add: assms) |
|
1464 |
qed |
|
1465 |
||
31992 | 1466 |
end |
1467 |
||
1468 |
||
60758 | 1469 |
subsection \<open>Locales as mini-packages for fold operations\<close> |
34007
aea892559fc5
tuned lattices theory fragements; generlized some lemmas from sets to lattices
haftmann
parents:
33960
diff
changeset
|
1470 |
|
60758 | 1471 |
subsubsection \<open>The natural case\<close> |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1472 |
|
73832 | 1473 |
locale folding_on = |
1474 |
fixes S :: "'a set" |
|
63612 | 1475 |
fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" and z :: "'b" |
73832 | 1476 |
assumes comp_fun_commute_on: "x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> f y o f x = f x o f y" |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1477 |
begin |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1478 |
|
73832 | 1479 |
interpretation fold?: comp_fun_commute_on S f |
1480 |
by standard (simp add: comp_fun_commute_on) |
|
54867
c21a2465cac1
prefer ephemeral interpretation over interpretation in proof contexts;
haftmann
parents:
54611
diff
changeset
|
1481 |
|
51489 | 1482 |
definition F :: "'a set \<Rightarrow> 'b" |
73832 | 1483 |
where eq_fold: "F A = Finite_Set.fold f z A" |
51489 | 1484 |
|
73832 | 1485 |
lemma empty [simp]: "F {} = z" |
51489 | 1486 |
by (simp add: eq_fold) |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1487 |
|
61169 | 1488 |
lemma infinite [simp]: "\<not> finite A \<Longrightarrow> F A = z" |
51489 | 1489 |
by (simp add: eq_fold) |
63404 | 1490 |
|
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1491 |
lemma insert [simp]: |
73832 | 1492 |
assumes "insert x A \<subseteq> S" and "finite A" and "x \<notin> A" |
51489 | 1493 |
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
|
1494 |
proof - |
51489 | 1495 |
from fold_insert assms |
73832 | 1496 |
have "Finite_Set.fold f z (insert x A) |
1497 |
= f x (Finite_Set.fold f z A)" |
|
1498 |
by simp |
|
60758 | 1499 |
with \<open>finite A\<close> 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
|
1500 |
qed |
63404 | 1501 |
|
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1502 |
lemma remove: |
73832 | 1503 |
assumes "A \<subseteq> S" and "finite A" and "x \<in> A" |
51489 | 1504 |
shows "F A = f x (F (A - {x}))" |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1505 |
proof - |
60758 | 1506 |
from \<open>x \<in> A\<close> obtain B where A: "A = insert x B" and "x \<notin> B" |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1507 |
by (auto dest: mk_disjoint_insert) |
60758 | 1508 |
moreover from \<open>finite A\<close> A have "finite B" by simp |
73832 | 1509 |
ultimately show ?thesis |
1510 |
using \<open>A \<subseteq> S\<close> by auto |
|
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1511 |
qed |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1512 |
|
73832 | 1513 |
lemma insert_remove: |
1514 |
assumes "insert x A \<subseteq> S" and "finite A" |
|
1515 |
shows "F (insert x A) = f x (F (A - {x}))" |
|
1516 |
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
|
1517 |
|
34007
aea892559fc5
tuned lattices theory fragements; generlized some lemmas from sets to lattices
haftmann
parents:
33960
diff
changeset
|
1518 |
end |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1519 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1520 |
|
60758 | 1521 |
subsubsection \<open>With idempotency\<close> |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1522 |
|
73832 | 1523 |
locale folding_idem_on = folding_on + |
1524 |
assumes comp_fun_idem_on: "x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> f x \<circ> f x = f x" |
|
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1525 |
begin |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1526 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1527 |
declare insert [simp del] |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1528 |
|
73832 | 1529 |
interpretation fold?: comp_fun_idem_on S f |
1530 |
by standard (simp_all add: comp_fun_commute_on comp_fun_idem_on) |
|
54867
c21a2465cac1
prefer ephemeral interpretation over interpretation in proof contexts;
haftmann
parents:
54611
diff
changeset
|
1531 |
|
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1532 |
lemma insert_idem [simp]: |
73832 | 1533 |
assumes "insert x A \<subseteq> S" and "finite A" |
51489 | 1534 |
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
|
1535 |
proof - |
51489 | 1536 |
from fold_insert_idem assms |
1537 |
have "fold f z (insert x A) = f x (fold f z A)" by simp |
|
60758 | 1538 |
with \<open>finite A\<close> 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
|
1539 |
qed |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1540 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1541 |
end |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1542 |
|
73832 | 1543 |
subsubsection \<open>\<^term>\<open>UNIV\<close> as the carrier set\<close> |
1544 |
||
1545 |
locale folding = |
|
1546 |
fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" and z :: "'b" |
|
1547 |
assumes comp_fun_commute: "f y \<circ> f x = f x \<circ> f y" |
|
1548 |
begin |
|
1549 |
||
1550 |
lemma (in -) folding_def': "folding f = folding_on UNIV f" |
|
1551 |
unfolding folding_def folding_on_def by blast |
|
1552 |
||
1553 |
text \<open> |
|
1554 |
Again, we abuse the \<open>rewrites\<close> functionality of locales to remove trivial assumptions that |
|
1555 |
result from instantiating the carrier set to \<^term>\<open>UNIV\<close>. |
|
1556 |
\<close> |
|
1557 |
sublocale folding_on UNIV f |
|
1558 |
rewrites "\<And>X. (X \<subseteq> UNIV) \<equiv> True" |
|
1559 |
and "\<And>x. x \<in> UNIV \<equiv> True" |
|
1560 |
and "\<And>P. (True \<Longrightarrow> P) \<equiv> Trueprop P" |
|
1561 |
and "\<And>P Q. (True \<Longrightarrow> PROP P \<Longrightarrow> PROP Q) \<equiv> (PROP P \<Longrightarrow> True \<Longrightarrow> PROP Q)" |
|
1562 |
proof - |
|
1563 |
show "folding_on UNIV f" |
|
1564 |
by standard (simp add: comp_fun_commute) |
|
1565 |
qed simp_all |
|
1566 |
||
1567 |
end |
|
1568 |
||
1569 |
locale folding_idem = folding + |
|
1570 |
assumes comp_fun_idem: "f x \<circ> f x = f x" |
|
1571 |
begin |
|
1572 |
||
1573 |
lemma (in -) folding_idem_def': "folding_idem f = folding_idem_on UNIV f" |
|
1574 |
unfolding folding_idem_def folding_def' folding_idem_on_def |
|
1575 |
unfolding folding_idem_axioms_def folding_idem_on_axioms_def |
|
1576 |
by blast |
|
1577 |
||
1578 |
text \<open> |
|
1579 |
Again, we abuse the \<open>rewrites\<close> functionality of locales to remove trivial assumptions that |
|
1580 |
result from instantiating the carrier set to \<^term>\<open>UNIV\<close>. |
|
1581 |
\<close> |
|
1582 |
sublocale folding_idem_on UNIV f |
|
1583 |
rewrites "\<And>X. (X \<subseteq> UNIV) \<equiv> True" |
|
1584 |
and "\<And>x. x \<in> UNIV \<equiv> True" |
|
1585 |
and "\<And>P. (True \<Longrightarrow> P) \<equiv> Trueprop P" |
|
1586 |
and "\<And>P Q. (True \<Longrightarrow> PROP P \<Longrightarrow> PROP Q) \<equiv> (PROP P \<Longrightarrow> True \<Longrightarrow> PROP Q)" |
|
1587 |
proof - |
|
1588 |
show "folding_idem_on UNIV f" |
|
1589 |
by standard (simp add: comp_fun_idem) |
|
1590 |
qed simp_all |
|
1591 |
||
1592 |
end |
|
1593 |
||
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1594 |
|
60758 | 1595 |
subsection \<open>Finite cardinality\<close> |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1596 |
|
60758 | 1597 |
text \<open> |
51489 | 1598 |
The traditional definition |
69593 | 1599 |
\<^prop>\<open>card A \<equiv> LEAST n. \<exists>f. A = {f i |i. i < n}\<close> |
51489 | 1600 |
is ugly to work with. |
69593 | 1601 |
But now that we have \<^const>\<open>fold\<close> things are easy: |
60758 | 1602 |
\<close> |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1603 |
|
61890
f6ded81f5690
abandoned attempt to unify sublocale and interpretation into global theories
haftmann
parents:
61810
diff
changeset
|
1604 |
global_interpretation card: folding "\<lambda>_. Suc" 0 |
73832 | 1605 |
defines card = "folding_on.F (\<lambda>_. Suc) 0" |
75669
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
75668
diff
changeset
|
1606 |
by standard (rule refl) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1607 |
|
63404 | 1608 |
lemma card_insert_disjoint: "finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> card (insert x A) = Suc (card A)" |
51489 | 1609 |
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
|
1610 |
|
63404 | 1611 |
lemma card_insert_if: "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
|
1612 |
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
|
1613 |
|
63404 | 1614 |
lemma card_ge_0_finite: "card A > 0 \<Longrightarrow> finite A" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1615 |
by (rule ccontr) simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1616 |
|
63404 | 1617 |
lemma card_0_eq [simp]: "finite A \<Longrightarrow> card A = 0 \<longleftrightarrow> A = {}" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1618 |
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
|
1619 |
|
63404 | 1620 |
lemma finite_UNIV_card_ge_0: "finite (UNIV :: 'a set) \<Longrightarrow> card (UNIV :: 'a set) > 0" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1621 |
by (rule ccontr) simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1622 |
|
63404 | 1623 |
lemma card_eq_0_iff: "card A = 0 \<longleftrightarrow> A = {} \<or> \<not> finite A" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1624 |
by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1625 |
|
63404 | 1626 |
lemma card_range_greater_zero: "finite (range f) \<Longrightarrow> card (range f) > 0" |
63365 | 1627 |
by (rule ccontr) (simp add: card_eq_0_iff) |
1628 |
||
63404 | 1629 |
lemma card_gt_0_iff: "0 < card A \<longleftrightarrow> A \<noteq> {} \<and> finite A" |
1630 |
by (simp add: neq0_conv [symmetric] card_eq_0_iff) |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1631 |
|
72302
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1632 |
lemma card_Suc_Diff1: |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1633 |
assumes "finite A" "x \<in> A" shows "Suc (card (A - {x})) = card A" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1634 |
proof - |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1635 |
have "Suc (card (A - {x})) = card (insert x (A - {x}))" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1636 |
using assms by (simp add: card.insert_remove) |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1637 |
also have "... = card A" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1638 |
using assms by (simp add: card_insert_if) |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1639 |
finally show ?thesis . |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1640 |
qed |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1641 |
|
72302
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1642 |
lemma card_insert_le_m1: |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1643 |
assumes "n > 0" "card y \<le> n - 1" shows "card (insert x y) \<le> n" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1644 |
using assms |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1645 |
by (cases "finite y") (auto simp: card_insert_if) |
60762 | 1646 |
|
74223
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1647 |
lemma card_Diff_singleton: |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1648 |
assumes "x \<in> A" shows "card (A - {x}) = card A - 1" |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1649 |
proof (cases "finite A") |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1650 |
case True |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1651 |
with assms show ?thesis |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1652 |
by (simp add: card_Suc_Diff1 [symmetric]) |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1653 |
qed auto |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1654 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1655 |
lemma card_Diff_singleton_if: |
74223
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1656 |
"card (A - {x}) = (if x \<in> A then card A - 1 else card A)" |
51489 | 1657 |
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
|
1658 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1659 |
lemma card_Diff_insert[simp]: |
74223
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1660 |
assumes "a \<in> A" and "a \<notin> B" |
51489 | 1661 |
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
|
1662 |
proof - |
63404 | 1663 |
have "A - insert a B = (A - B) - {a}" |
1664 |
using assms by blast |
|
1665 |
then show ?thesis |
|
1666 |
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
|
1667 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1668 |
|
74223
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1669 |
lemma card_insert_le: "card A \<le> card (insert x A)" |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1670 |
proof (cases "finite A") |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1671 |
case True |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1672 |
then show ?thesis by (simp add: card_insert_if) |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1673 |
qed auto |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1674 |
|
63404 | 1675 |
lemma card_Collect_less_nat[simp]: "card {i::nat. i < n} = n" |
1676 |
by (induct n) (simp_all add:less_Suc_eq Collect_disj_eq) |
|
41987 | 1677 |
|
63404 | 1678 |
lemma card_Collect_le_nat[simp]: "card {i::nat. i \<le> n} = Suc n" |
1679 |
using card_Collect_less_nat[of "Suc n"] by (simp add: less_Suc_eq_le) |
|
41987 | 1680 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1681 |
lemma card_mono: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1682 |
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
|
1683 |
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
|
1684 |
proof - |
63404 | 1685 |
from assms have "finite A" |
1686 |
by (auto intro: finite_subset) |
|
1687 |
then show ?thesis |
|
1688 |
using assms |
|
1689 |
proof (induct A arbitrary: B) |
|
1690 |
case empty |
|
1691 |
then show ?case by simp |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1692 |
next |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1693 |
case (insert x A) |
63404 | 1694 |
then have "x \<in> B" |
1695 |
by simp |
|
1696 |
from insert have "A \<subseteq> B - {x}" and "finite (B - {x})" |
|
1697 |
by auto |
|
1698 |
with insert.hyps have "card A \<le> card (B - {x})" |
|
1699 |
by auto |
|
1700 |
with \<open>finite A\<close> \<open>x \<notin> A\<close> \<open>finite B\<close> \<open>x \<in> B\<close> show ?case |
|
1701 |
by simp (simp only: card.remove) |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1702 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1703 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1704 |
|
72302
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1705 |
lemma card_seteq: |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1706 |
assumes "finite B" and A: "A \<subseteq> B" "card B \<le> card A" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1707 |
shows "A = B" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1708 |
using assms |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1709 |
proof (induction arbitrary: A rule: finite_induct) |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1710 |
case (insert b B) |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1711 |
then have A: "finite A" "A - {b} \<subseteq> B" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1712 |
by force+ |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1713 |
then have "card B \<le> card (A - {b})" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1714 |
using insert by (auto simp add: card_Diff_singleton_if) |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1715 |
then have "A - {b} = B" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1716 |
using A insert.IH by auto |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1717 |
then show ?case |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1718 |
using insert.hyps insert.prems by auto |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1719 |
qed auto |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1720 |
|
63404 | 1721 |
lemma psubset_card_mono: "finite B \<Longrightarrow> A < B \<Longrightarrow> card A < card B" |
72302
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1722 |
using card_seteq [of B A] by (auto simp add: psubset_eq) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1723 |
|
51489 | 1724 |
lemma card_Un_Int: |
63404 | 1725 |
assumes "finite A" "finite B" |
51489 | 1726 |
shows "card A + card B = card (A \<union> B) + card (A \<inter> B)" |
63404 | 1727 |
using assms |
1728 |
proof (induct A) |
|
1729 |
case empty |
|
1730 |
then show ?case by simp |
|
51489 | 1731 |
next |
63404 | 1732 |
case insert |
1733 |
then show ?case |
|
51489 | 1734 |
by (auto simp add: insert_absorb Int_insert_left) |
1735 |
qed |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1736 |
|
63404 | 1737 |
lemma card_Un_disjoint: "finite A \<Longrightarrow> finite B \<Longrightarrow> A \<inter> B = {} \<Longrightarrow> card (A \<union> B) = card A + card B" |
1738 |
using 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
|
1739 |
|
72095
cfb6c22a5636
lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents:
71449
diff
changeset
|
1740 |
lemma card_Un_disjnt: "\<lbrakk>finite A; finite B; disjnt A B\<rbrakk> \<Longrightarrow> card (A \<union> B) = card A + card B" |
cfb6c22a5636
lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents:
71449
diff
changeset
|
1741 |
by (simp add: card_Un_disjoint disjnt_def) |
cfb6c22a5636
lemmas about sets and the enumerate operator
paulson <lp15@cam.ac.uk>
parents:
71449
diff
changeset
|
1742 |
|
59336 | 1743 |
lemma card_Un_le: "card (A \<union> B) \<le> card A + card B" |
70723
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
paulson <lp15@cam.ac.uk>
parents:
70178
diff
changeset
|
1744 |
proof (cases "finite A \<and> finite B") |
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
paulson <lp15@cam.ac.uk>
parents:
70178
diff
changeset
|
1745 |
case True |
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
paulson <lp15@cam.ac.uk>
parents:
70178
diff
changeset
|
1746 |
then show ?thesis |
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
paulson <lp15@cam.ac.uk>
parents:
70178
diff
changeset
|
1747 |
using le_iff_add card_Un_Int [of A B] by auto |
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
paulson <lp15@cam.ac.uk>
parents:
70178
diff
changeset
|
1748 |
qed auto |
59336 | 1749 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1750 |
lemma card_Diff_subset: |
63404 | 1751 |
assumes "finite B" |
1752 |
and "B \<subseteq> A" |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1753 |
shows "card (A - B) = card A - card B" |
63915 | 1754 |
using assms |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1755 |
proof (cases "finite A") |
63404 | 1756 |
case False |
1757 |
with assms show ?thesis |
|
1758 |
by simp |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1759 |
next |
63404 | 1760 |
case True |
1761 |
with assms show ?thesis |
|
1762 |
by (induct B arbitrary: A) simp_all |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1763 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1764 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1765 |
lemma card_Diff_subset_Int: |
63404 | 1766 |
assumes "finite (A \<inter> B)" |
1767 |
shows "card (A - B) = card A - card (A \<inter> B)" |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1768 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1769 |
have "A - B = A - A \<inter> B" by auto |
63404 | 1770 |
with assms show ?thesis |
1771 |
by (simp add: card_Diff_subset) |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1772 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1773 |
|
40716 | 1774 |
lemma diff_card_le_card_Diff: |
63404 | 1775 |
assumes "finite B" |
1776 |
shows "card A - card B \<le> card (A - B)" |
|
1777 |
proof - |
|
40716 | 1778 |
have "card A - card B \<le> card A - card (A \<inter> B)" |
1779 |
using card_mono[OF assms Int_lower2, of A] by arith |
|
63404 | 1780 |
also have "\<dots> = card (A - B)" |
1781 |
using assms by (simp add: card_Diff_subset_Int) |
|
40716 | 1782 |
finally show ?thesis . |
1783 |
qed |
|
1784 |
||
69312 | 1785 |
lemma card_le_sym_Diff: |
1786 |
assumes "finite A" "finite B" "card A \<le> card B" |
|
1787 |
shows "card(A - B) \<le> card(B - A)" |
|
1788 |
proof - |
|
1789 |
have "card(A - B) = card A - card (A \<inter> B)" using assms(1,2) by(simp add: card_Diff_subset_Int) |
|
1790 |
also have "\<dots> \<le> card B - card (A \<inter> B)" using assms(3) by linarith |
|
1791 |
also have "\<dots> = card(B - A)" using assms(1,2) by(simp add: card_Diff_subset_Int Int_commute) |
|
1792 |
finally show ?thesis . |
|
1793 |
qed |
|
1794 |
||
1795 |
lemma card_less_sym_Diff: |
|
1796 |
assumes "finite A" "finite B" "card A < card B" |
|
1797 |
shows "card(A - B) < card(B - A)" |
|
1798 |
proof - |
|
1799 |
have "card(A - B) = card A - card (A \<inter> B)" using assms(1,2) by(simp add: card_Diff_subset_Int) |
|
1800 |
also have "\<dots> < card B - card (A \<inter> B)" using assms(1,3) by (simp add: card_mono diff_less_mono) |
|
1801 |
also have "\<dots> = card(B - A)" using assms(1,2) by(simp add: card_Diff_subset_Int Int_commute) |
|
1802 |
finally show ?thesis . |
|
1803 |
qed |
|
1804 |
||
72302
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1805 |
lemma card_Diff1_less_iff: "card (A - {x}) < card A \<longleftrightarrow> finite A \<and> x \<in> A" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1806 |
proof (cases "finite A \<and> x \<in> A") |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1807 |
case True |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1808 |
then show ?thesis |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1809 |
by (auto simp: card_gt_0_iff intro: diff_less) |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1810 |
qed auto |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1811 |
|
63404 | 1812 |
lemma card_Diff1_less: "finite A \<Longrightarrow> x \<in> A \<Longrightarrow> card (A - {x}) < card A" |
72302
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1813 |
unfolding card_Diff1_less_iff by auto |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1814 |
|
72302
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1815 |
lemma card_Diff2_less: |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1816 |
assumes "finite A" "x \<in> A" "y \<in> A" shows "card (A - {x} - {y}) < card A" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1817 |
proof (cases "x = y") |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1818 |
case True |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1819 |
with assms show ?thesis |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1820 |
by (simp add: card_Diff1_less del: card_Diff_insert) |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1821 |
next |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1822 |
case False |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1823 |
then have "card (A - {x} - {y}) < card (A - {x})" "card (A - {x}) < card A" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1824 |
using assms by (intro card_Diff1_less; simp)+ |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1825 |
then show ?thesis |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1826 |
by (blast intro: less_trans) |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
1827 |
qed |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1828 |
|
74223
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1829 |
lemma card_Diff1_le: "card (A - {x}) \<le> card A" |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1830 |
proof (cases "finite A") |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1831 |
case True |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1832 |
then show ?thesis |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1833 |
by (cases "x \<in> A") (simp_all add: card_Diff1_less less_imp_le) |
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1834 |
qed auto |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1835 |
|
63404 | 1836 |
lemma card_psubset: "finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> card A < card B \<Longrightarrow> A < B" |
1837 |
by (erule psubsetI) blast |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1838 |
|
54413
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1839 |
lemma card_le_inj: |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1840 |
assumes fA: "finite A" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1841 |
and fB: "finite B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1842 |
and c: "card A \<le> card B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1843 |
shows "\<exists>f. f ` A \<subseteq> B \<and> inj_on f A" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1844 |
using fA fB c |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1845 |
proof (induct arbitrary: B rule: finite_induct) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1846 |
case empty |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1847 |
then show ?case by simp |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1848 |
next |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1849 |
case (insert x s t) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1850 |
then show ?case |
63404 | 1851 |
proof (induct rule: finite_induct [OF insert.prems(1)]) |
54413
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1852 |
case 1 |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1853 |
then show ?case by simp |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1854 |
next |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1855 |
case (2 y t) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1856 |
from "2.prems"(1,2,5) "2.hyps"(1,2) have cst: "card s \<le> card t" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1857 |
by simp |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1858 |
from "2.prems"(3) [OF "2.hyps"(1) cst] |
75669
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
75668
diff
changeset
|
1859 |
obtain f where *: "f ` s \<subseteq> t" "inj_on f s" |
54413
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1860 |
by blast |
75669
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
75668
diff
changeset
|
1861 |
let ?g = "(\<lambda>a. if a = x then y else f a)" |
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
75668
diff
changeset
|
1862 |
have "?g ` insert x s \<subseteq> insert y t \<and> inj_on ?g (insert x s)" |
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
75668
diff
changeset
|
1863 |
using * "2.prems"(2) "2.hyps"(2) unfolding inj_on_def by auto |
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
75668
diff
changeset
|
1864 |
then show ?case by (rule exI[where ?x="?g"]) |
54413
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1865 |
qed |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1866 |
qed |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1867 |
|
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1868 |
lemma card_subset_eq: |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1869 |
assumes fB: "finite B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1870 |
and AB: "A \<subseteq> B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1871 |
and c: "card A = card B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1872 |
shows "A = B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1873 |
proof - |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1874 |
from fB AB have fA: "finite A" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1875 |
by (auto intro: finite_subset) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1876 |
from fA fB have fBA: "finite (B - A)" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1877 |
by auto |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1878 |
have e: "A \<inter> (B - A) = {}" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1879 |
by blast |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1880 |
have eq: "A \<union> (B - A) = B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1881 |
using AB by blast |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1882 |
from card_Un_disjoint[OF fA fBA e, unfolded eq c] have "card (B - A) = 0" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1883 |
by arith |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1884 |
then have "B - A = {}" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1885 |
unfolding card_eq_0_iff using fA fB by simp |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1886 |
with AB show "A = B" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1887 |
by blast |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1888 |
qed |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1889 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1890 |
lemma insert_partition: |
63404 | 1891 |
"x \<notin> F \<Longrightarrow> \<forall>c1 \<in> insert x F. \<forall>c2 \<in> insert x F. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {} \<Longrightarrow> x \<inter> \<Union>F = {}" |
74223
527088d4a89b
strengthened a few lemmas about finite sets and added a code equation for complex_of_real
paulson <lp15@cam.ac.uk>
parents:
73832
diff
changeset
|
1892 |
by auto |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1893 |
|
63404 | 1894 |
lemma finite_psubset_induct [consumes 1, case_names psubset]: |
1895 |
assumes finite: "finite A" |
|
1896 |
and major: "\<And>A. finite A \<Longrightarrow> (\<And>B. B \<subset> A \<Longrightarrow> P B) \<Longrightarrow> P 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
|
1897 |
shows "P A" |
63404 | 1898 |
using finite |
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
|
1899 |
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
|
1900 |
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
|
1901 |
have fin: "finite A" by fact |
63404 | 1902 |
have ih: "card B < card A \<Longrightarrow> finite B \<Longrightarrow> P B" for B by fact |
1903 |
have "P B" if "B \<subset> A" for B |
|
1904 |
proof - |
|
1905 |
from that have "card B < card A" |
|
1906 |
using psubset_card_mono fin by blast |
|
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
|
1907 |
moreover |
63404 | 1908 |
from that have "B \<subseteq> A" |
1909 |
by auto |
|
1910 |
then have "finite B" |
|
1911 |
using fin finite_subset by blast |
|
1912 |
ultimately show ?thesis using ih by simp |
|
1913 |
qed |
|
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
|
1914 |
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
|
1915 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1916 |
|
63404 | 1917 |
lemma finite_induct_select [consumes 1, case_names empty select]: |
54413
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1918 |
assumes "finite S" |
63404 | 1919 |
and "P {}" |
1920 |
and select: "\<And>T. T \<subset> S \<Longrightarrow> P T \<Longrightarrow> \<exists>s\<in>S - T. P (insert s T)" |
|
54413
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1921 |
shows "P S" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1922 |
proof - |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1923 |
have "0 \<le> card S" by simp |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1924 |
then have "\<exists>T \<subseteq> S. card T = card S \<and> P T" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1925 |
proof (induct rule: dec_induct) |
63404 | 1926 |
case base with \<open>P {}\<close> |
1927 |
show ?case |
|
54413
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1928 |
by (intro exI[of _ "{}"]) auto |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1929 |
next |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1930 |
case (step n) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1931 |
then obtain T where T: "T \<subseteq> S" "card T = n" "P T" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1932 |
by auto |
60758 | 1933 |
with \<open>n < card S\<close> have "T \<subset> S" "P T" |
54413
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1934 |
by auto |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1935 |
with select[of T] obtain s where "s \<in> S" "s \<notin> T" "P (insert s T)" |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1936 |
by auto |
60758 | 1937 |
with step(2) T \<open>finite S\<close> show ?case |
54413
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1938 |
by (intro exI[of _ "insert s T"]) (auto dest: finite_subset) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1939 |
qed |
60758 | 1940 |
with \<open>finite S\<close> show "P S" |
54413
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1941 |
by (auto dest: card_subset_eq) |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1942 |
qed |
88a036a95967
add finite_select_induct; move generic lemmas from MV_Analysis/Linear_Algebra to the HOL image
hoelzl
parents:
54148
diff
changeset
|
1943 |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1944 |
lemma remove_induct [case_names empty infinite remove]: |
63404 | 1945 |
assumes empty: "P ({} :: 'a set)" |
1946 |
and infinite: "\<not> finite B \<Longrightarrow> P B" |
|
1947 |
and remove: "\<And>A. finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> P (A - {x})) \<Longrightarrow> P A" |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1948 |
shows "P B" |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1949 |
proof (cases "finite B") |
63612 | 1950 |
case False |
63404 | 1951 |
then show ?thesis by (rule infinite) |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1952 |
next |
63612 | 1953 |
case True |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1954 |
define A where "A = B" |
63612 | 1955 |
with True have "finite A" "A \<subseteq> B" |
1956 |
by simp_all |
|
63404 | 1957 |
then show "P A" |
1958 |
proof (induct "card A" arbitrary: A) |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1959 |
case 0 |
63404 | 1960 |
then have "A = {}" by auto |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1961 |
with empty show ?case by simp |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1962 |
next |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1963 |
case (Suc n A) |
63404 | 1964 |
from \<open>A \<subseteq> B\<close> and \<open>finite B\<close> have "finite A" |
1965 |
by (rule finite_subset) |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1966 |
moreover from Suc.hyps have "A \<noteq> {}" by auto |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1967 |
moreover note \<open>A \<subseteq> B\<close> |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1968 |
moreover have "P (A - {x})" if x: "x \<in> A" for x |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1969 |
using x Suc.prems \<open>Suc n = card A\<close> by (intro Suc) auto |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1970 |
ultimately show ?case by (rule remove) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1971 |
qed |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1972 |
qed |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1973 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1974 |
lemma finite_remove_induct [consumes 1, case_names empty remove]: |
63404 | 1975 |
fixes P :: "'a set \<Rightarrow> bool" |
63612 | 1976 |
assumes "finite B" |
1977 |
and "P {}" |
|
1978 |
and "\<And>A. finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> P (A - {x})) \<Longrightarrow> P A" |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1979 |
defines "B' \<equiv> B" |
63404 | 1980 |
shows "P B'" |
1981 |
by (induct B' rule: remove_induct) (simp_all add: assms) |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1982 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
1983 |
|
63404 | 1984 |
text \<open>Main cardinality theorem.\<close> |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1985 |
lemma card_partition [rule_format]: |
63404 | 1986 |
"finite C \<Longrightarrow> finite (\<Union>C) \<Longrightarrow> (\<forall>c\<in>C. card c = k) \<Longrightarrow> |
1987 |
(\<forall>c1 \<in> C. \<forall>c2 \<in> C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}) \<Longrightarrow> |
|
1988 |
k * card C = card (\<Union>C)" |
|
63612 | 1989 |
proof (induct rule: finite_induct) |
1990 |
case empty |
|
1991 |
then show ?case by simp |
|
1992 |
next |
|
1993 |
case (insert x F) |
|
1994 |
then show ?case |
|
1995 |
by (simp add: card_Un_disjoint insert_partition finite_subset [of _ "\<Union>(insert _ _)"]) |
|
1996 |
qed |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1997 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1998 |
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
|
1999 |
assumes fin: "finite (UNIV :: 'a set)" |
63404 | 2000 |
and card: "card A = card (UNIV :: 'a set)" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2001 |
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
|
2002 |
proof |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2003 |
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
|
2004 |
show "UNIV \<subseteq> A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2005 |
proof |
63404 | 2006 |
show "x \<in> A" for x |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2007 |
proof (rule ccontr) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2008 |
assume "x \<notin> A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2009 |
then have "A \<subset> UNIV" by auto |
63404 | 2010 |
with fin have "card A < card (UNIV :: 'a set)" |
2011 |
by (fact psubset_card_mono) |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2012 |
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
|
2013 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2014 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2015 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2016 |
|
63404 | 2017 |
text \<open>The form of a finite set of given cardinality\<close> |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2018 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2019 |
lemma card_eq_SucD: |
63404 | 2020 |
assumes "card A = Suc k" |
2021 |
shows "\<exists>b B. A = insert b B \<and> b \<notin> B \<and> card B = k \<and> (k = 0 \<longrightarrow> B = {})" |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2022 |
proof - |
63404 | 2023 |
have fin: "finite A" |
2024 |
using assms by (auto intro: ccontr) |
|
2025 |
moreover have "card A \<noteq> 0" |
|
2026 |
using assms by auto |
|
2027 |
ultimately obtain b where b: "b \<in> A" |
|
2028 |
by auto |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2029 |
show ?thesis |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2030 |
proof (intro exI conjI) |
63404 | 2031 |
show "A = insert b (A - {b})" |
2032 |
using b by blast |
|
2033 |
show "b \<notin> A - {b}" |
|
2034 |
by blast |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2035 |
show "card (A - {b}) = k" and "k = 0 \<longrightarrow> A - {b} = {}" |
63612 | 2036 |
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
|
2037 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2038 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2039 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2040 |
lemma card_Suc_eq: |
63404 | 2041 |
"card A = Suc k \<longleftrightarrow> |
2042 |
(\<exists>b B. A = insert b B \<and> b \<notin> B \<and> card B = k \<and> (k = 0 \<longrightarrow> B = {}))" |
|
72302
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2043 |
by (auto simp: card_insert_if card_gt_0_iff elim!: card_eq_SucD) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2044 |
|
73620 | 2045 |
lemma card_Suc_eq_finite: |
2046 |
"card A = Suc k \<longleftrightarrow> (\<exists>b B. A = insert b B \<and> b \<notin> B \<and> card B = k \<and> finite B)" |
|
2047 |
unfolding card_Suc_eq using card_gt_0_iff by fastforce |
|
2048 |
||
61518
ff12606337e9
new lemmas about topology, etc., for Cauchy integral formula
paulson
parents:
61169
diff
changeset
|
2049 |
lemma card_1_singletonE: |
63404 | 2050 |
assumes "card A = 1" |
2051 |
obtains x where "A = {x}" |
|
61518
ff12606337e9
new lemmas about topology, etc., for Cauchy integral formula
paulson
parents:
61169
diff
changeset
|
2052 |
using assms by (auto simp: card_Suc_eq) |
ff12606337e9
new lemmas about topology, etc., for Cauchy integral formula
paulson
parents:
61169
diff
changeset
|
2053 |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
2054 |
lemma is_singleton_altdef: "is_singleton A \<longleftrightarrow> card A = 1" |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
2055 |
unfolding is_singleton_def |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
2056 |
by (auto elim!: card_1_singletonE is_singletonE simp del: One_nat_def) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
63040
diff
changeset
|
2057 |
|
71258
d67924987c34
a few new and tidier proofs (mostly about finite sets)
paulson <lp15@cam.ac.uk>
parents:
70723
diff
changeset
|
2058 |
lemma card_1_singleton_iff: "card A = Suc 0 \<longleftrightarrow> (\<exists>x. A = {x})" |
d67924987c34
a few new and tidier proofs (mostly about finite sets)
paulson <lp15@cam.ac.uk>
parents:
70723
diff
changeset
|
2059 |
by (simp add: card_Suc_eq) |
d67924987c34
a few new and tidier proofs (mostly about finite sets)
paulson <lp15@cam.ac.uk>
parents:
70723
diff
changeset
|
2060 |
|
69312 | 2061 |
lemma card_le_Suc0_iff_eq: |
2062 |
assumes "finite A" |
|
2063 |
shows "card A \<le> Suc 0 \<longleftrightarrow> (\<forall>a1 \<in> A. \<forall>a2 \<in> A. a1 = a2)" (is "?C = ?A") |
|
2064 |
proof |
|
2065 |
assume ?C thus ?A using assms by (auto simp: le_Suc_eq dest: card_eq_SucD) |
|
2066 |
next |
|
2067 |
assume ?A |
|
2068 |
show ?C |
|
2069 |
proof cases |
|
2070 |
assume "A = {}" thus ?C using \<open>?A\<close> by simp |
|
2071 |
next |
|
2072 |
assume "A \<noteq> {}" |
|
2073 |
then obtain a where "A = {a}" using \<open>?A\<close> by blast |
|
2074 |
thus ?C by simp |
|
2075 |
qed |
|
2076 |
qed |
|
2077 |
||
63404 | 2078 |
lemma card_le_Suc_iff: |
69312 | 2079 |
"Suc n \<le> card A = (\<exists>a B. A = insert a B \<and> a \<notin> B \<and> n \<le> card B \<and> finite B)" |
72302
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2080 |
proof (cases "finite A") |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2081 |
case True |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2082 |
then show ?thesis |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2083 |
by (fastforce simp: card_Suc_eq less_eq_nat.simps split: nat.splits) |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2084 |
qed auto |
44744 | 2085 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2086 |
lemma finite_fun_UNIVD2: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2087 |
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
|
2088 |
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
|
2089 |
proof - |
63404 | 2090 |
from fin have "finite (range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary))" for arbitrary |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
2091 |
by (rule finite_imageI) |
63404 | 2092 |
moreover have "UNIV = range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary)" for arbitrary |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
2093 |
by (rule UNIV_eq_I) auto |
63404 | 2094 |
ultimately show "finite (UNIV :: 'b set)" |
2095 |
by simp |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2096 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2097 |
|
48063
f02b4302d5dd
remove duplicate lemma card_unit in favor of Finite_Set.card_UNIV_unit
huffman
parents:
47221
diff
changeset
|
2098 |
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
|
2099 |
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
|
2100 |
|
57447
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents:
57025
diff
changeset
|
2101 |
lemma infinite_arbitrarily_large: |
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents:
57025
diff
changeset
|
2102 |
assumes "\<not> finite A" |
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents:
57025
diff
changeset
|
2103 |
shows "\<exists>B. finite B \<and> card B = n \<and> B \<subseteq> A" |
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents:
57025
diff
changeset
|
2104 |
proof (induction n) |
63404 | 2105 |
case 0 |
2106 |
show ?case by (intro exI[of _ "{}"]) auto |
|
2107 |
next |
|
57447
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents:
57025
diff
changeset
|
2108 |
case (Suc n) |
63404 | 2109 |
then obtain B where B: "finite B \<and> card B = n \<and> B \<subseteq> A" .. |
60758 | 2110 |
with \<open>\<not> finite A\<close> have "A \<noteq> B" by auto |
57447
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents:
57025
diff
changeset
|
2111 |
with B have "B \<subset> A" by auto |
63404 | 2112 |
then have "\<exists>x. x \<in> A - B" |
2113 |
by (elim psubset_imp_ex_mem) |
|
2114 |
then obtain x where x: "x \<in> A - B" .. |
|
57447
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents:
57025
diff
changeset
|
2115 |
with B have "finite (insert x B) \<and> card (insert x B) = Suc n \<and> insert x B \<subseteq> A" |
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents:
57025
diff
changeset
|
2116 |
by auto |
63404 | 2117 |
then show "\<exists>B. finite B \<and> card B = Suc n \<and> B \<subseteq> A" .. |
57447
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents:
57025
diff
changeset
|
2118 |
qed |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2119 |
|
67457 | 2120 |
text \<open>Sometimes, to prove that a set is finite, it is convenient to work with finite subsets |
2121 |
and to show that their cardinalities are uniformly bounded. This possibility is formalized in |
|
2122 |
the next criterion.\<close> |
|
2123 |
||
2124 |
lemma finite_if_finite_subsets_card_bdd: |
|
2125 |
assumes "\<And>G. G \<subseteq> F \<Longrightarrow> finite G \<Longrightarrow> card G \<le> C" |
|
2126 |
shows "finite F \<and> card F \<le> C" |
|
2127 |
proof (cases "finite F") |
|
2128 |
case False |
|
2129 |
obtain n::nat where n: "n > max C 0" by auto |
|
2130 |
obtain G where G: "G \<subseteq> F" "card G = n" using infinite_arbitrarily_large[OF False] by auto |
|
72302
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2131 |
hence "finite G" using \<open>n > max C 0\<close> using card.infinite gr_implies_not0 by blast |
67457 | 2132 |
hence False using assms G n not_less by auto |
2133 |
thus ?thesis .. |
|
2134 |
next |
|
2135 |
case True thus ?thesis using assms[of F] by auto |
|
2136 |
qed |
|
2137 |
||
75668 | 2138 |
lemma obtain_subset_with_card_n: |
2139 |
assumes "n \<le> card S" |
|
2140 |
obtains T where "T \<subseteq> S" "card T = n" "finite T" |
|
2141 |
proof - |
|
2142 |
obtain n' where "card S = n + n'" |
|
2143 |
using le_Suc_ex[OF assms] by blast |
|
2144 |
with that show thesis |
|
2145 |
proof (induct n' arbitrary: S) |
|
2146 |
case 0 |
|
2147 |
thus ?case by (cases "finite S") auto |
|
2148 |
next |
|
2149 |
case Suc |
|
2150 |
thus ?case by (auto simp add: card_Suc_eq) |
|
2151 |
qed |
|
2152 |
qed |
|
2153 |
||
2154 |
lemma exists_subset_between: |
|
2155 |
assumes |
|
2156 |
"card A \<le> n" |
|
2157 |
"n \<le> card C" |
|
2158 |
"A \<subseteq> C" |
|
2159 |
"finite C" |
|
2160 |
shows "\<exists>B. A \<subseteq> B \<and> B \<subseteq> C \<and> card B = n" |
|
2161 |
using assms |
|
2162 |
proof (induct n arbitrary: A C) |
|
2163 |
case 0 |
|
2164 |
thus ?case using finite_subset[of A C] by (intro exI[of _ "{}"], auto) |
|
2165 |
next |
|
2166 |
case (Suc n A C) |
|
2167 |
show ?case |
|
2168 |
proof (cases "A = {}") |
|
2169 |
case True |
|
2170 |
from obtain_subset_with_card_n[OF Suc(3)] |
|
2171 |
obtain B where "B \<subseteq> C" "card B = Suc n" by blast |
|
2172 |
thus ?thesis unfolding True by blast |
|
2173 |
next |
|
2174 |
case False |
|
2175 |
then obtain a where a: "a \<in> A" by auto |
|
2176 |
let ?A = "A - {a}" |
|
2177 |
let ?C = "C - {a}" |
|
2178 |
have 1: "card ?A \<le> n" using Suc(2-) a |
|
2179 |
using finite_subset by fastforce |
|
2180 |
have 2: "card ?C \<ge> n" using Suc(2-) a by auto |
|
2181 |
from Suc(1)[OF 1 2 _ finite_subset[OF _ Suc(5)]] Suc(2-) |
|
2182 |
obtain B where "?A \<subseteq> B" "B \<subseteq> ?C" "card B = n" by blast |
|
2183 |
thus ?thesis using a Suc(2-) |
|
2184 |
by (intro exI[of _ "insert a B"], auto intro!: card_insert_disjoint finite_subset[of B C]) |
|
2185 |
qed |
|
2186 |
qed |
|
2187 |
||
63404 | 2188 |
|
60758 | 2189 |
subsubsection \<open>Cardinality of image\<close> |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2190 |
|
63404 | 2191 |
lemma card_image_le: "finite A \<Longrightarrow> card (f ` A) \<le> card A" |
54570 | 2192 |
by (induct rule: finite_induct) (simp_all add: le_SucI card_insert_if) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2193 |
|
63915 | 2194 |
lemma card_image: "inj_on f A \<Longrightarrow> card (f ` A) = card A" |
2195 |
proof (induct A rule: infinite_finite_induct) |
|
2196 |
case (infinite A) |
|
2197 |
then have "\<not> finite (f ` A)" by (auto dest: finite_imageD) |
|
2198 |
with infinite show ?case by simp |
|
2199 |
qed simp_all |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2200 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2201 |
lemma bij_betw_same_card: "bij_betw f A B \<Longrightarrow> card A = card B" |
63612 | 2202 |
by (auto simp: card_image bij_betw_def) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2203 |
|
63404 | 2204 |
lemma endo_inj_surj: "finite A \<Longrightarrow> f ` A \<subseteq> A \<Longrightarrow> inj_on f A \<Longrightarrow> f ` A = A" |
2205 |
by (simp add: card_seteq card_image) |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2206 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2207 |
lemma eq_card_imp_inj_on: |
63404 | 2208 |
assumes "finite A" "card(f ` A) = card A" |
2209 |
shows "inj_on f A" |
|
2210 |
using assms |
|
54570 | 2211 |
proof (induct rule:finite_induct) |
63404 | 2212 |
case empty |
2213 |
show ?case by simp |
|
54570 | 2214 |
next |
2215 |
case (insert x A) |
|
63404 | 2216 |
then show ?case |
2217 |
using card_image_le [of A f] by (simp add: card_insert_if split: if_splits) |
|
54570 | 2218 |
qed |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2219 |
|
63404 | 2220 |
lemma inj_on_iff_eq_card: "finite A \<Longrightarrow> inj_on f A \<longleftrightarrow> card (f ` A) = card A" |
54570 | 2221 |
by (blast intro: card_image eq_card_imp_inj_on) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2222 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2223 |
lemma card_inj_on_le: |
63404 | 2224 |
assumes "inj_on f A" "f ` A \<subseteq> B" "finite B" |
2225 |
shows "card A \<le> card B" |
|
54570 | 2226 |
proof - |
63404 | 2227 |
have "finite A" |
2228 |
using assms by (blast intro: finite_imageD dest: finite_subset) |
|
2229 |
then show ?thesis |
|
2230 |
using assms by (force intro: card_mono simp: card_image [symmetric]) |
|
54570 | 2231 |
qed |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2232 |
|
69235 | 2233 |
lemma inj_on_iff_card_le: |
2234 |
"\<lbrakk> finite A; finite B \<rbrakk> \<Longrightarrow> (\<exists>f. inj_on f A \<and> f ` A \<le> B) = (card A \<le> card B)" |
|
2235 |
using card_inj_on_le[of _ A B] card_le_inj[of A B] by blast |
|
2236 |
||
59504
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
59336
diff
changeset
|
2237 |
lemma surj_card_le: "finite A \<Longrightarrow> B \<subseteq> f ` A \<Longrightarrow> card B \<le> card A" |
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
59336
diff
changeset
|
2238 |
by (blast intro: card_image_le card_mono le_trans) |
8c6747dba731
New lemmas and a bit of tidying up.
paulson <lp15@cam.ac.uk>
parents:
59336
diff
changeset
|
2239 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2240 |
lemma card_bij_eq: |
63404 | 2241 |
"inj_on f A \<Longrightarrow> f ` A \<subseteq> B \<Longrightarrow> inj_on g B \<Longrightarrow> g ` B \<subseteq> A \<Longrightarrow> finite A \<Longrightarrow> finite B |
2242 |
\<Longrightarrow> card A = card B" |
|
2243 |
by (auto intro: le_antisym card_inj_on_le) |
|
2244 |
||
2245 |
lemma bij_betw_finite: "bij_betw f A B \<Longrightarrow> finite A \<longleftrightarrow> finite B" |
|
2246 |
unfolding bij_betw_def 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
|
2247 |
|
63404 | 2248 |
lemma inj_on_finite: "inj_on f A \<Longrightarrow> f ` A \<le> B \<Longrightarrow> finite B \<Longrightarrow> finite A" |
2249 |
using finite_imageD finite_subset by blast |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2250 |
|
74985 | 2251 |
lemma card_vimage_inj_on_le: |
2252 |
assumes "inj_on f D" "finite A" |
|
2253 |
shows "card (f-`A \<inter> D) \<le> card A" |
|
2254 |
proof (rule card_inj_on_le) |
|
2255 |
show "inj_on f (f -` A \<inter> D)" |
|
2256 |
by (blast intro: assms inj_on_subset) |
|
2257 |
qed (use assms in auto) |
|
2258 |
||
63404 | 2259 |
lemma card_vimage_inj: "inj f \<Longrightarrow> A \<subseteq> range f \<Longrightarrow> card (f -` A) = card A" |
2260 |
by (auto 4 3 simp: subset_image_iff inj_vimage_image_eq |
|
2261 |
intro: card_image[symmetric, OF subset_inj_on]) |
|
55020 | 2262 |
|
60758 | 2263 |
subsubsection \<open>Pigeonhole Principles\<close> |
37466 | 2264 |
|
63404 | 2265 |
lemma pigeonhole: "card A > card (f ` A) \<Longrightarrow> \<not> inj_on f A " |
2266 |
by (auto dest: card_image less_irrefl_nat) |
|
37466 | 2267 |
|
2268 |
lemma pigeonhole_infinite: |
|
63404 | 2269 |
assumes "\<not> finite A" and "finite (f`A)" |
2270 |
shows "\<exists>a0\<in>A. \<not> finite {a\<in>A. f a = f a0}" |
|
2271 |
using assms(2,1) |
|
2272 |
proof (induct "f`A" arbitrary: A rule: finite_induct) |
|
2273 |
case empty |
|
2274 |
then show ?case by simp |
|
2275 |
next |
|
2276 |
case (insert b F) |
|
2277 |
show ?case |
|
2278 |
proof (cases "finite {a\<in>A. f a = b}") |
|
2279 |
case True |
|
2280 |
with \<open>\<not> finite A\<close> have "\<not> finite (A - {a\<in>A. f a = b})" |
|
2281 |
by simp |
|
2282 |
also have "A - {a\<in>A. f a = b} = {a\<in>A. f a \<noteq> b}" |
|
2283 |
by blast |
|
2284 |
finally have "\<not> finite {a\<in>A. f a \<noteq> b}" . |
|
2285 |
from insert(3)[OF _ this] insert(2,4) show ?thesis |
|
2286 |
by simp (blast intro: rev_finite_subset) |
|
37466 | 2287 |
next |
63404 | 2288 |
case False |
2289 |
then have "{a \<in> A. f a = b} \<noteq> {}" by force |
|
2290 |
with False show ?thesis by blast |
|
37466 | 2291 |
qed |
2292 |
qed |
|
2293 |
||
2294 |
lemma pigeonhole_infinite_rel: |
|
63404 | 2295 |
assumes "\<not> finite A" |
2296 |
and "finite B" |
|
2297 |
and "\<forall>a\<in>A. \<exists>b\<in>B. R a b" |
|
2298 |
shows "\<exists>b\<in>B. \<not> finite {a:A. R a b}" |
|
37466 | 2299 |
proof - |
63404 | 2300 |
let ?F = "\<lambda>a. {b\<in>B. R a b}" |
2301 |
from finite_Pow_iff[THEN iffD2, OF \<open>finite B\<close>] have "finite (?F ` A)" |
|
2302 |
by (blast intro: rev_finite_subset) |
|
2303 |
from pigeonhole_infinite [where f = ?F, OF assms(1) this] |
|
63612 | 2304 |
obtain a0 where "a0 \<in> A" and infinite: "\<not> finite {a\<in>A. ?F a = ?F a0}" .. |
63404 | 2305 |
obtain b0 where "b0 \<in> B" and "R a0 b0" |
2306 |
using \<open>a0 \<in> A\<close> assms(3) by blast |
|
63612 | 2307 |
have "finite {a\<in>A. ?F a = ?F a0}" if "finite {a\<in>A. R a b0}" |
63404 | 2308 |
using \<open>b0 \<in> B\<close> \<open>R a0 b0\<close> that by (blast intro: rev_finite_subset) |
63612 | 2309 |
with infinite \<open>b0 \<in> B\<close> show ?thesis |
63404 | 2310 |
by blast |
37466 | 2311 |
qed |
2312 |
||
2313 |
||
60758 | 2314 |
subsubsection \<open>Cardinality of sums\<close> |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2315 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2316 |
lemma card_Plus: |
63404 | 2317 |
assumes "finite A" "finite B" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2318 |
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
|
2319 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2320 |
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
|
2321 |
with assms show ?thesis |
63404 | 2322 |
by (simp add: Plus_def card_Un_disjoint card_image) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2323 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2324 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2325 |
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
|
2326 |
"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
|
2327 |
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
|
2328 |
|
63404 | 2329 |
text \<open>Relates to equivalence classes. Based on a theorem of F. Kammüller.\<close> |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2330 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2331 |
lemma dvd_partition: |
63404 | 2332 |
assumes f: "finite (\<Union>C)" |
2333 |
and "\<forall>c\<in>C. k dvd card c" "\<forall>c1\<in>C. \<forall>c2\<in>C. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {}" |
|
2334 |
shows "k dvd card (\<Union>C)" |
|
54570 | 2335 |
proof - |
63404 | 2336 |
have "finite C" |
54570 | 2337 |
by (rule finite_UnionD [OF f]) |
63404 | 2338 |
then show ?thesis |
2339 |
using assms |
|
54570 | 2340 |
proof (induct rule: finite_induct) |
63404 | 2341 |
case empty |
2342 |
show ?case by simp |
|
54570 | 2343 |
next |
72302
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2344 |
case (insert c C) |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2345 |
then have "c \<inter> \<Union>C = {}" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2346 |
by auto |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2347 |
with insert show ?case |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2348 |
by (simp add: card_Un_disjoint) |
54570 | 2349 |
qed |
2350 |
qed |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2351 |
|
72384 | 2352 |
subsubsection \<open>Finite orders\<close> |
2353 |
||
2354 |
context order |
|
2355 |
begin |
|
2356 |
||
2357 |
lemma finite_has_maximal: |
|
2358 |
"\<lbrakk> finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> \<exists> m \<in> A. \<forall> b \<in> A. m \<le> b \<longrightarrow> m = b" |
|
2359 |
proof (induction rule: finite_psubset_induct) |
|
2360 |
case (psubset A) |
|
2361 |
from \<open>A \<noteq> {}\<close> obtain a where "a \<in> A" by auto |
|
2362 |
let ?B = "{b \<in> A. a < b}" |
|
2363 |
show ?case |
|
2364 |
proof cases |
|
2365 |
assume "?B = {}" |
|
2366 |
hence "\<forall> b \<in> A. a \<le> b \<longrightarrow> a = b" using le_neq_trans by blast |
|
2367 |
thus ?thesis using \<open>a \<in> A\<close> by blast |
|
2368 |
next |
|
2369 |
assume "?B \<noteq> {}" |
|
2370 |
have "a \<notin> ?B" by auto |
|
2371 |
hence "?B \<subset> A" using \<open>a \<in> A\<close> by blast |
|
2372 |
from psubset.IH[OF this \<open>?B \<noteq> {}\<close>] show ?thesis using order.strict_trans2 by blast |
|
2373 |
qed |
|
2374 |
qed |
|
2375 |
||
2376 |
lemma finite_has_maximal2: |
|
2377 |
"\<lbrakk> finite A; a \<in> A \<rbrakk> \<Longrightarrow> \<exists> m \<in> A. a \<le> m \<and> (\<forall> b \<in> A. m \<le> b \<longrightarrow> m = b)" |
|
2378 |
using finite_has_maximal[of "{b \<in> A. a \<le> b}"] by fastforce |
|
2379 |
||
2380 |
lemma finite_has_minimal: |
|
2381 |
"\<lbrakk> finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> \<exists> m \<in> A. \<forall> b \<in> A. b \<le> m \<longrightarrow> m = b" |
|
2382 |
proof (induction rule: finite_psubset_induct) |
|
2383 |
case (psubset A) |
|
2384 |
from \<open>A \<noteq> {}\<close> obtain a where "a \<in> A" by auto |
|
2385 |
let ?B = "{b \<in> A. b < a}" |
|
2386 |
show ?case |
|
2387 |
proof cases |
|
2388 |
assume "?B = {}" |
|
2389 |
hence "\<forall> b \<in> A. b \<le> a \<longrightarrow> a = b" using le_neq_trans by blast |
|
2390 |
thus ?thesis using \<open>a \<in> A\<close> by blast |
|
2391 |
next |
|
2392 |
assume "?B \<noteq> {}" |
|
2393 |
have "a \<notin> ?B" by auto |
|
2394 |
hence "?B \<subset> A" using \<open>a \<in> A\<close> by blast |
|
2395 |
from psubset.IH[OF this \<open>?B \<noteq> {}\<close>] show ?thesis using order.strict_trans1 by blast |
|
2396 |
qed |
|
2397 |
qed |
|
2398 |
||
2399 |
lemma finite_has_minimal2: |
|
2400 |
"\<lbrakk> finite A; a \<in> A \<rbrakk> \<Longrightarrow> \<exists> m \<in> A. m \<le> a \<and> (\<forall> b \<in> A. b \<le> m \<longrightarrow> m = b)" |
|
2401 |
using finite_has_minimal[of "{b \<in> A. b \<le> a}"] by fastforce |
|
2402 |
||
2403 |
end |
|
63404 | 2404 |
|
60758 | 2405 |
subsubsection \<open>Relating injectivity and surjectivity\<close> |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2406 |
|
63404 | 2407 |
lemma finite_surj_inj: |
2408 |
assumes "finite A" "A \<subseteq> f ` A" |
|
2409 |
shows "inj_on f A" |
|
54570 | 2410 |
proof - |
63404 | 2411 |
have "f ` A = A" |
54570 | 2412 |
by (rule card_seteq [THEN sym]) (auto simp add: assms card_image_le) |
2413 |
then show ?thesis using assms |
|
2414 |
by (simp add: eq_card_imp_inj_on) |
|
2415 |
qed |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2416 |
|
63612 | 2417 |
lemma finite_UNIV_surj_inj: "finite(UNIV:: 'a set) \<Longrightarrow> surj f \<Longrightarrow> inj f" |
2418 |
for f :: "'a \<Rightarrow> 'a" |
|
63404 | 2419 |
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
|
2420 |
|
63612 | 2421 |
lemma finite_UNIV_inj_surj: "finite(UNIV:: 'a set) \<Longrightarrow> inj f \<Longrightarrow> surj f" |
2422 |
for f :: "'a \<Rightarrow> 'a" |
|
63404 | 2423 |
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
|
2424 |
|
70019
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2425 |
lemma surjective_iff_injective_gen: |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2426 |
assumes fS: "finite S" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2427 |
and fT: "finite T" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2428 |
and c: "card S = card T" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2429 |
and ST: "f ` S \<subseteq> T" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2430 |
shows "(\<forall>y \<in> T. \<exists>x \<in> S. f x = y) \<longleftrightarrow> inj_on f S" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2431 |
(is "?lhs \<longleftrightarrow> ?rhs") |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2432 |
proof |
70019
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2433 |
assume h: "?lhs" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2434 |
{ |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2435 |
fix x y |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2436 |
assume x: "x \<in> S" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2437 |
assume y: "y \<in> S" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2438 |
assume f: "f x = f y" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2439 |
from x fS have S0: "card S \<noteq> 0" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2440 |
by auto |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2441 |
have "x = y" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2442 |
proof (rule ccontr) |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2443 |
assume xy: "\<not> ?thesis" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2444 |
have th: "card S \<le> card (f ` (S - {y}))" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2445 |
unfolding c |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2446 |
proof (rule card_mono) |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2447 |
show "finite (f ` (S - {y}))" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2448 |
by (simp add: fS) |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2449 |
have "\<lbrakk>x \<noteq> y; x \<in> S; z \<in> S; f x = f y\<rbrakk> |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2450 |
\<Longrightarrow> \<exists>x \<in> S. x \<noteq> y \<and> f z = f x" for z |
75669
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
Fabian Huch <huch@in.tum.de>
parents:
75668
diff
changeset
|
2451 |
by (cases "z = y \<longrightarrow> z = x") auto |
70019
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2452 |
then show "T \<subseteq> f ` (S - {y})" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2453 |
using h xy x y f by fastforce |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2454 |
qed |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2455 |
also have " \<dots> \<le> card (S - {y})" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2456 |
by (simp add: card_image_le fS) |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2457 |
also have "\<dots> \<le> card S - 1" using y fS by simp |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2458 |
finally show False using S0 by arith |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2459 |
qed |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2460 |
} |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2461 |
then show ?rhs |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2462 |
unfolding inj_on_def by blast |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2463 |
next |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2464 |
assume h: ?rhs |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2465 |
have "f ` S = T" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2466 |
by (simp add: ST c card_image card_subset_eq fT h) |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2467 |
then show ?lhs by blast |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2468 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2469 |
|
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
2470 |
hide_const (open) Finite_Set.fold |
46033 | 2471 |
|
61810 | 2472 |
|
63404 | 2473 |
subsection \<open>Infinite Sets\<close> |
61810 | 2474 |
|
2475 |
text \<open> |
|
2476 |
Some elementary facts about infinite sets, mostly by Stephan Merz. |
|
2477 |
Beware! Because "infinite" merely abbreviates a negation, these |
|
2478 |
lemmas may not work well with \<open>blast\<close>. |
|
2479 |
\<close> |
|
2480 |
||
2481 |
abbreviation infinite :: "'a set \<Rightarrow> bool" |
|
2482 |
where "infinite S \<equiv> \<not> finite S" |
|
2483 |
||
2484 |
text \<open> |
|
2485 |
Infinite sets are non-empty, and if we remove some elements from an |
|
2486 |
infinite set, the result is still infinite. |
|
2487 |
\<close> |
|
2488 |
||
70019
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2489 |
lemma infinite_UNIV_nat [iff]: "infinite (UNIV :: nat set)" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2490 |
proof |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2491 |
assume "finite (UNIV :: nat set)" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2492 |
with finite_UNIV_inj_surj [of Suc] show False |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2493 |
by simp (blast dest: Suc_neq_Zero surjD) |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2494 |
qed |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2495 |
|
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2496 |
lemma infinite_UNIV_char_0: "infinite (UNIV :: 'a::semiring_char_0 set)" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2497 |
proof |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2498 |
assume "finite (UNIV :: 'a set)" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2499 |
with subset_UNIV have "finite (range of_nat :: 'a set)" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2500 |
by (rule finite_subset) |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2501 |
moreover have "inj (of_nat :: nat \<Rightarrow> 'a)" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2502 |
by (simp add: inj_on_def) |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2503 |
ultimately have "finite (UNIV :: nat set)" |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2504 |
by (rule finite_imageD) |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2505 |
then show False |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2506 |
by simp |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2507 |
qed |
095dce9892e8
A few results in Algebra, and bits for Analysis
paulson <lp15@cam.ac.uk>
parents:
69735
diff
changeset
|
2508 |
|
61810 | 2509 |
lemma infinite_imp_nonempty: "infinite S \<Longrightarrow> S \<noteq> {}" |
2510 |
by auto |
|
2511 |
||
2512 |
lemma infinite_remove: "infinite S \<Longrightarrow> infinite (S - {a})" |
|
2513 |
by simp |
|
2514 |
||
2515 |
lemma Diff_infinite_finite: |
|
63404 | 2516 |
assumes "finite T" "infinite S" |
61810 | 2517 |
shows "infinite (S - T)" |
63404 | 2518 |
using \<open>finite T\<close> |
61810 | 2519 |
proof induct |
63404 | 2520 |
from \<open>infinite S\<close> show "infinite (S - {})" |
2521 |
by auto |
|
61810 | 2522 |
next |
2523 |
fix T x |
|
2524 |
assume ih: "infinite (S - T)" |
|
2525 |
have "S - (insert x T) = (S - T) - {x}" |
|
2526 |
by (rule Diff_insert) |
|
63404 | 2527 |
with ih show "infinite (S - (insert x T))" |
61810 | 2528 |
by (simp add: infinite_remove) |
2529 |
qed |
|
2530 |
||
2531 |
lemma Un_infinite: "infinite S \<Longrightarrow> infinite (S \<union> T)" |
|
2532 |
by simp |
|
2533 |
||
2534 |
lemma infinite_Un: "infinite (S \<union> T) \<longleftrightarrow> infinite S \<or> infinite T" |
|
2535 |
by simp |
|
2536 |
||
2537 |
lemma infinite_super: |
|
63404 | 2538 |
assumes "S \<subseteq> T" |
2539 |
and "infinite S" |
|
61810 | 2540 |
shows "infinite T" |
2541 |
proof |
|
2542 |
assume "finite T" |
|
63404 | 2543 |
with \<open>S \<subseteq> T\<close> have "finite S" by (simp add: finite_subset) |
2544 |
with \<open>infinite S\<close> show False by simp |
|
61810 | 2545 |
qed |
2546 |
||
2547 |
proposition infinite_coinduct [consumes 1, case_names infinite]: |
|
2548 |
assumes "X A" |
|
63404 | 2549 |
and step: "\<And>A. X A \<Longrightarrow> \<exists>x\<in>A. X (A - {x}) \<or> infinite (A - {x})" |
61810 | 2550 |
shows "infinite A" |
2551 |
proof |
|
2552 |
assume "finite A" |
|
63404 | 2553 |
then show False |
2554 |
using \<open>X A\<close> |
|
61810 | 2555 |
proof (induction rule: finite_psubset_induct) |
2556 |
case (psubset A) |
|
2557 |
then obtain x where "x \<in> A" "X (A - {x}) \<or> infinite (A - {x})" |
|
2558 |
using local.step psubset.prems by blast |
|
2559 |
then have "X (A - {x})" |
|
2560 |
using psubset.hyps by blast |
|
2561 |
show False |
|
72302
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2562 |
proof (rule psubset.IH [where B = "A - {x}"]) |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2563 |
show "A - {x} \<subset> A" |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2564 |
using \<open>x \<in> A\<close> by blast |
d7d90ed4c74e
fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents:
72097
diff
changeset
|
2565 |
qed fact |
61810 | 2566 |
qed |
2567 |
qed |
|
2568 |
||
2569 |
text \<open> |
|
2570 |
For any function with infinite domain and finite range there is some |
|
2571 |
element that is the image of infinitely many domain elements. In |
|
2572 |
particular, any infinite sequence of elements from a finite set |
|
2573 |
contains some element that occurs infinitely often. |
|
2574 |
\<close> |
|
2575 |
||
2576 |
lemma inf_img_fin_dom': |
|
63404 | 2577 |
assumes img: "finite (f ` A)" |
2578 |
and dom: "infinite A" |
|
61810 | 2579 |
shows "\<exists>y \<in> f ` A. infinite (f -` {y} \<inter> A)" |
2580 |
proof (rule ccontr) |
|
2581 |
have "A \<subseteq> (\<Union>y\<in>f ` A. f -` {y} \<inter> A)" by auto |
|
63404 | 2582 |
moreover assume "\<not> ?thesis" |
61810 | 2583 |
with img have "finite (\<Union>y\<in>f ` A. f -` {y} \<inter> A)" by blast |
63404 | 2584 |
ultimately have "finite A" by (rule finite_subset) |
61810 | 2585 |
with dom show False by contradiction |
2586 |
qed |
|
2587 |
||
2588 |
lemma inf_img_fin_domE': |
|
2589 |
assumes "finite (f ` A)" and "infinite A" |
|
2590 |
obtains y where "y \<in> f`A" and "infinite (f -` {y} \<inter> A)" |
|
2591 |
using assms by (blast dest: inf_img_fin_dom') |
|
2592 |
||
2593 |
lemma inf_img_fin_dom: |
|
2594 |
assumes img: "finite (f`A)" and dom: "infinite A" |
|
2595 |
shows "\<exists>y \<in> f`A. infinite (f -` {y})" |
|
63404 | 2596 |
using inf_img_fin_dom'[OF assms] by auto |
61810 | 2597 |
|
2598 |
lemma inf_img_fin_domE: |
|
2599 |
assumes "finite (f`A)" and "infinite A" |
|
2600 |
obtains y where "y \<in> f`A" and "infinite (f -` {y})" |
|
2601 |
using assms by (blast dest: inf_img_fin_dom) |
|
2602 |
||
63404 | 2603 |
proposition finite_image_absD: "finite (abs ` S) \<Longrightarrow> finite S" |
2604 |
for S :: "'a::linordered_ring set" |
|
61810 | 2605 |
by (rule ccontr) (auto simp: abs_eq_iff vimage_def dest: inf_img_fin_dom) |
2606 |
||
73555 | 2607 |
|
69735
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2608 |
subsection \<open>The finite powerset operator\<close> |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2609 |
|
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2610 |
definition Fpow :: "'a set \<Rightarrow> 'a set set" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2611 |
where "Fpow A \<equiv> {X. X \<subseteq> A \<and> finite X}" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2612 |
|
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2613 |
lemma Fpow_mono: "A \<subseteq> B \<Longrightarrow> Fpow A \<subseteq> Fpow B" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2614 |
unfolding Fpow_def by auto |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2615 |
|
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2616 |
lemma empty_in_Fpow: "{} \<in> Fpow A" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2617 |
unfolding Fpow_def by auto |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2618 |
|
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2619 |
lemma Fpow_not_empty: "Fpow A \<noteq> {}" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2620 |
using empty_in_Fpow by blast |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2621 |
|
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2622 |
lemma Fpow_subset_Pow: "Fpow A \<subseteq> Pow A" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2623 |
unfolding Fpow_def by auto |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2624 |
|
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2625 |
lemma Fpow_Pow_finite: "Fpow A = Pow A Int {A. finite A}" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2626 |
unfolding Fpow_def Pow_def by blast |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2627 |
|
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2628 |
lemma inj_on_image_Fpow: |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2629 |
assumes "inj_on f A" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2630 |
shows "inj_on (image f) (Fpow A)" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2631 |
using assms Fpow_subset_Pow[of A] subset_inj_on[of "image f" "Pow A"] |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2632 |
inj_on_image_Pow by blast |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2633 |
|
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2634 |
lemma image_Fpow_mono: |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2635 |
assumes "f ` A \<subseteq> B" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2636 |
shows "(image f) ` (Fpow A) \<subseteq> Fpow B" |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2637 |
using assms by(unfold Fpow_def, auto) |
8230dca028eb
the theory of Equipollence, and moving Fpow from Cardinals into Main
paulson <lp15@cam.ac.uk>
parents:
69593
diff
changeset
|
2638 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2639 |
end |