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