author | haftmann |
Fri, 15 Feb 2013 08:31:31 +0100 | |
changeset 51143 | 0a2371e7ced3 |
parent 49806 | acb6fa98e310 |
child 51290 | c48477e76de5 |
permissions | -rw-r--r-- |
12396 | 1 |
(* Title: HOL/Finite_Set.thy |
2 |
Author: Tobias Nipkow, Lawrence C Paulson and Markus Wenzel |
|
16775
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents:
16760
diff
changeset
|
3 |
with contributions by Jeremy Avigad |
12396 | 4 |
*) |
5 |
||
6 |
header {* Finite sets *} |
|
7 |
||
15131 | 8 |
theory Finite_Set |
38400
9bfcb1507c6b
import swap prevents strange failure of SML code generator for datatypes
haftmann
parents:
37770
diff
changeset
|
9 |
imports Option Power |
15131 | 10 |
begin |
12396 | 11 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
12 |
subsection {* Predicate for finite sets *} |
12396 | 13 |
|
41656 | 14 |
inductive finite :: "'a set \<Rightarrow> bool" |
22262 | 15 |
where |
16 |
emptyI [simp, intro!]: "finite {}" |
|
41656 | 17 |
| insertI [simp, intro!]: "finite A \<Longrightarrow> finite (insert a A)" |
18 |
||
49764
9979d64b8016
moving simproc from Finite_Set to more appropriate Product_Type theory
bulwahn
parents:
49758
diff
changeset
|
19 |
simproc_setup finite_Collect ("finite (Collect P)") = {* K Set_Comprehension_Pointfree.simproc *} |
48109
0a58f7eefba2
Integrated set comprehension pointfree simproc.
Rafal Kolanski <rafal.kolanski@nicta.com.au>
parents:
48063
diff
changeset
|
20 |
|
41656 | 21 |
lemma finite_induct [case_names empty insert, induct set: finite]: |
22 |
-- {* Discharging @{text "x \<notin> F"} entails extra work. *} |
|
23 |
assumes "finite F" |
|
24 |
assumes "P {}" |
|
25 |
and insert: "\<And>x F. finite F \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)" |
|
26 |
shows "P F" |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
27 |
using `finite F` |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
28 |
proof induct |
41656 | 29 |
show "P {}" by fact |
30 |
fix x F assume F: "finite F" and P: "P F" |
|
31 |
show "P (insert x F)" |
|
32 |
proof cases |
|
33 |
assume "x \<in> F" |
|
34 |
hence "insert x F = F" by (rule insert_absorb) |
|
35 |
with P show ?thesis by (simp only:) |
|
36 |
next |
|
37 |
assume "x \<notin> F" |
|
38 |
from F this P show ?thesis by (rule insert) |
|
39 |
qed |
|
40 |
qed |
|
41 |
||
42 |
||
43 |
subsubsection {* Choice principles *} |
|
12396 | 44 |
|
13737 | 45 |
lemma ex_new_if_finite: -- "does not depend on def of finite at all" |
14661 | 46 |
assumes "\<not> finite (UNIV :: 'a set)" and "finite A" |
47 |
shows "\<exists>a::'a. a \<notin> A" |
|
48 |
proof - |
|
28823 | 49 |
from assms have "A \<noteq> UNIV" by blast |
41656 | 50 |
then show ?thesis by blast |
12396 | 51 |
qed |
52 |
||
41656 | 53 |
text {* A finite choice principle. Does not need the SOME choice operator. *} |
15484 | 54 |
|
29923 | 55 |
lemma finite_set_choice: |
41656 | 56 |
"finite A \<Longrightarrow> \<forall>x\<in>A. \<exists>y. P x y \<Longrightarrow> \<exists>f. \<forall>x\<in>A. P x (f x)" |
57 |
proof (induct rule: finite_induct) |
|
58 |
case empty then show ?case by simp |
|
29923 | 59 |
next |
60 |
case (insert a A) |
|
61 |
then obtain f b where f: "ALL x:A. P x (f x)" and ab: "P a b" by auto |
|
62 |
show ?case (is "EX f. ?P f") |
|
63 |
proof |
|
64 |
show "?P(%x. if x = a then b else f x)" using f ab by auto |
|
65 |
qed |
|
66 |
qed |
|
67 |
||
23878 | 68 |
|
41656 | 69 |
subsubsection {* Finite sets are the images of initial segments of natural numbers *} |
15392 | 70 |
|
15510 | 71 |
lemma finite_imp_nat_seg_image_inj_on: |
41656 | 72 |
assumes "finite A" |
73 |
shows "\<exists>(n::nat) f. A = f ` {i. i < n} \<and> inj_on f {i. i < n}" |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
74 |
using assms |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
75 |
proof induct |
15392 | 76 |
case empty |
41656 | 77 |
show ?case |
78 |
proof |
|
79 |
show "\<exists>f. {} = f ` {i::nat. i < 0} \<and> inj_on f {i. i < 0}" by simp |
|
15510 | 80 |
qed |
15392 | 81 |
next |
82 |
case (insert a A) |
|
23389 | 83 |
have notinA: "a \<notin> A" by fact |
15510 | 84 |
from insert.hyps obtain n f |
85 |
where "A = f ` {i::nat. i < n}" "inj_on f {i. i < n}" by blast |
|
86 |
hence "insert a A = f(n:=a) ` {i. i < Suc n}" |
|
87 |
"inj_on (f(n:=a)) {i. i < Suc n}" using notinA |
|
88 |
by (auto simp add: image_def Ball_def inj_on_def less_Suc_eq) |
|
15392 | 89 |
thus ?case by blast |
90 |
qed |
|
91 |
||
92 |
lemma nat_seg_image_imp_finite: |
|
41656 | 93 |
"A = f ` {i::nat. i < n} \<Longrightarrow> finite A" |
94 |
proof (induct n arbitrary: A) |
|
15392 | 95 |
case 0 thus ?case by simp |
96 |
next |
|
97 |
case (Suc n) |
|
98 |
let ?B = "f ` {i. i < n}" |
|
99 |
have finB: "finite ?B" by(rule Suc.hyps[OF refl]) |
|
100 |
show ?case |
|
101 |
proof cases |
|
102 |
assume "\<exists>k<n. f n = f k" |
|
103 |
hence "A = ?B" using Suc.prems by(auto simp:less_Suc_eq) |
|
104 |
thus ?thesis using finB by simp |
|
105 |
next |
|
106 |
assume "\<not>(\<exists> k<n. f n = f k)" |
|
107 |
hence "A = insert (f n) ?B" using Suc.prems by(auto simp:less_Suc_eq) |
|
108 |
thus ?thesis using finB by simp |
|
109 |
qed |
|
110 |
qed |
|
111 |
||
112 |
lemma finite_conv_nat_seg_image: |
|
41656 | 113 |
"finite A \<longleftrightarrow> (\<exists>(n::nat) f. A = f ` {i::nat. i < n})" |
114 |
by (blast intro: nat_seg_image_imp_finite dest: finite_imp_nat_seg_image_inj_on) |
|
15392 | 115 |
|
32988 | 116 |
lemma finite_imp_inj_to_nat_seg: |
41656 | 117 |
assumes "finite A" |
118 |
shows "\<exists>f n::nat. f ` A = {i. i < n} \<and> inj_on f A" |
|
32988 | 119 |
proof - |
120 |
from finite_imp_nat_seg_image_inj_on[OF `finite A`] |
|
121 |
obtain f and n::nat where bij: "bij_betw f {i. i<n} A" |
|
122 |
by (auto simp:bij_betw_def) |
|
33057 | 123 |
let ?f = "the_inv_into {i. i<n} f" |
32988 | 124 |
have "inj_on ?f A & ?f ` A = {i. i<n}" |
33057 | 125 |
by (fold bij_betw_def) (rule bij_betw_the_inv_into[OF bij]) |
32988 | 126 |
thus ?thesis by blast |
127 |
qed |
|
128 |
||
41656 | 129 |
lemma finite_Collect_less_nat [iff]: |
130 |
"finite {n::nat. n < k}" |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44835
diff
changeset
|
131 |
by (fastforce simp: finite_conv_nat_seg_image) |
29920 | 132 |
|
41656 | 133 |
lemma finite_Collect_le_nat [iff]: |
134 |
"finite {n::nat. n \<le> k}" |
|
135 |
by (simp add: le_eq_less_or_eq Collect_disj_eq) |
|
15392 | 136 |
|
41656 | 137 |
|
138 |
subsubsection {* Finiteness and common set operations *} |
|
12396 | 139 |
|
41656 | 140 |
lemma rev_finite_subset: |
141 |
"finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> finite A" |
|
142 |
proof (induct arbitrary: A rule: finite_induct) |
|
143 |
case empty |
|
144 |
then show ?case by simp |
|
145 |
next |
|
146 |
case (insert x F A) |
|
147 |
have A: "A \<subseteq> insert x F" and r: "A - {x} \<subseteq> F \<Longrightarrow> finite (A - {x})" by fact+ |
|
148 |
show "finite A" |
|
149 |
proof cases |
|
150 |
assume x: "x \<in> A" |
|
151 |
with A have "A - {x} \<subseteq> F" by (simp add: subset_insert_iff) |
|
152 |
with r have "finite (A - {x})" . |
|
153 |
hence "finite (insert x (A - {x}))" .. |
|
154 |
also have "insert x (A - {x}) = A" using x by (rule insert_Diff) |
|
155 |
finally show ?thesis . |
|
12396 | 156 |
next |
41656 | 157 |
show "A \<subseteq> F ==> ?thesis" by fact |
158 |
assume "x \<notin> A" |
|
159 |
with A show "A \<subseteq> F" by (simp add: subset_insert_iff) |
|
12396 | 160 |
qed |
161 |
qed |
|
162 |
||
41656 | 163 |
lemma finite_subset: |
164 |
"A \<subseteq> B \<Longrightarrow> finite B \<Longrightarrow> finite A" |
|
165 |
by (rule rev_finite_subset) |
|
29901 | 166 |
|
41656 | 167 |
lemma finite_UnI: |
168 |
assumes "finite F" and "finite G" |
|
169 |
shows "finite (F \<union> G)" |
|
170 |
using assms by induct simp_all |
|
31992 | 171 |
|
41656 | 172 |
lemma finite_Un [iff]: |
173 |
"finite (F \<union> G) \<longleftrightarrow> finite F \<and> finite G" |
|
174 |
by (blast intro: finite_UnI finite_subset [of _ "F \<union> G"]) |
|
31992 | 175 |
|
41656 | 176 |
lemma finite_insert [simp]: "finite (insert a A) \<longleftrightarrow> finite A" |
12396 | 177 |
proof - |
41656 | 178 |
have "finite {a} \<and> finite A \<longleftrightarrow> finite A" by simp |
179 |
then have "finite ({a} \<union> A) \<longleftrightarrow> finite A" by (simp only: finite_Un) |
|
23389 | 180 |
then show ?thesis by simp |
12396 | 181 |
qed |
182 |
||
41656 | 183 |
lemma finite_Int [simp, intro]: |
184 |
"finite F \<or> finite G \<Longrightarrow> finite (F \<inter> G)" |
|
185 |
by (blast intro: finite_subset) |
|
186 |
||
187 |
lemma finite_Collect_conjI [simp, intro]: |
|
188 |
"finite {x. P x} \<or> finite {x. Q x} \<Longrightarrow> finite {x. P x \<and> Q x}" |
|
189 |
by (simp add: Collect_conj_eq) |
|
190 |
||
191 |
lemma finite_Collect_disjI [simp]: |
|
192 |
"finite {x. P x \<or> Q x} \<longleftrightarrow> finite {x. P x} \<and> finite {x. Q x}" |
|
193 |
by (simp add: Collect_disj_eq) |
|
194 |
||
195 |
lemma finite_Diff [simp, intro]: |
|
196 |
"finite A \<Longrightarrow> finite (A - B)" |
|
197 |
by (rule finite_subset, rule Diff_subset) |
|
29901 | 198 |
|
199 |
lemma finite_Diff2 [simp]: |
|
41656 | 200 |
assumes "finite B" |
201 |
shows "finite (A - B) \<longleftrightarrow> finite A" |
|
29901 | 202 |
proof - |
41656 | 203 |
have "finite A \<longleftrightarrow> finite((A - B) \<union> (A \<inter> B))" by (simp add: Un_Diff_Int) |
204 |
also have "\<dots> \<longleftrightarrow> finite (A - B)" using `finite B` by simp |
|
29901 | 205 |
finally show ?thesis .. |
206 |
qed |
|
207 |
||
41656 | 208 |
lemma finite_Diff_insert [iff]: |
209 |
"finite (A - insert a B) \<longleftrightarrow> finite (A - B)" |
|
210 |
proof - |
|
211 |
have "finite (A - B) \<longleftrightarrow> finite (A - B - {a})" by simp |
|
212 |
moreover have "A - insert a B = A - B - {a}" by auto |
|
213 |
ultimately show ?thesis by simp |
|
214 |
qed |
|
215 |
||
29901 | 216 |
lemma finite_compl[simp]: |
41656 | 217 |
"finite (A :: 'a set) \<Longrightarrow> finite (- A) \<longleftrightarrow> finite (UNIV :: 'a set)" |
218 |
by (simp add: Compl_eq_Diff_UNIV) |
|
12396 | 219 |
|
29916 | 220 |
lemma finite_Collect_not[simp]: |
41656 | 221 |
"finite {x :: 'a. P x} \<Longrightarrow> finite {x. \<not> P x} \<longleftrightarrow> finite (UNIV :: 'a set)" |
222 |
by (simp add: Collect_neg_eq) |
|
223 |
||
224 |
lemma finite_Union [simp, intro]: |
|
225 |
"finite A \<Longrightarrow> (\<And>M. M \<in> A \<Longrightarrow> finite M) \<Longrightarrow> finite(\<Union>A)" |
|
226 |
by (induct rule: finite_induct) simp_all |
|
227 |
||
228 |
lemma finite_UN_I [intro]: |
|
229 |
"finite A \<Longrightarrow> (\<And>a. a \<in> A \<Longrightarrow> finite (B a)) \<Longrightarrow> finite (\<Union>a\<in>A. B a)" |
|
230 |
by (induct rule: finite_induct) simp_all |
|
29903 | 231 |
|
41656 | 232 |
lemma finite_UN [simp]: |
233 |
"finite A \<Longrightarrow> finite (UNION A B) \<longleftrightarrow> (\<forall>x\<in>A. finite (B x))" |
|
234 |
by (blast intro: finite_subset) |
|
235 |
||
236 |
lemma finite_Inter [intro]: |
|
237 |
"\<exists>A\<in>M. finite A \<Longrightarrow> finite (\<Inter>M)" |
|
238 |
by (blast intro: Inter_lower finite_subset) |
|
12396 | 239 |
|
41656 | 240 |
lemma finite_INT [intro]: |
241 |
"\<exists>x\<in>I. finite (A x) \<Longrightarrow> finite (\<Inter>x\<in>I. A x)" |
|
242 |
by (blast intro: INT_lower finite_subset) |
|
13825 | 243 |
|
41656 | 244 |
lemma finite_imageI [simp, intro]: |
245 |
"finite F \<Longrightarrow> finite (h ` F)" |
|
246 |
by (induct rule: finite_induct) simp_all |
|
13825 | 247 |
|
31768 | 248 |
lemma finite_image_set [simp]: |
249 |
"finite {x. P x} \<Longrightarrow> finite { f x | x. P x }" |
|
250 |
by (simp add: image_Collect [symmetric]) |
|
251 |
||
41656 | 252 |
lemma finite_imageD: |
42206 | 253 |
assumes "finite (f ` A)" and "inj_on f A" |
254 |
shows "finite A" |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
255 |
using assms |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
256 |
proof (induct "f ` A" arbitrary: A) |
42206 | 257 |
case empty then show ?case by simp |
258 |
next |
|
259 |
case (insert x B) |
|
260 |
then have B_A: "insert x B = f ` A" by simp |
|
261 |
then obtain y where "x = f y" and "y \<in> A" by blast |
|
262 |
from B_A `x \<notin> B` have "B = f ` A - {x}" by blast |
|
263 |
with B_A `x \<notin> B` `x = f y` `inj_on f A` `y \<in> A` have "B = f ` (A - {y})" by (simp add: inj_on_image_set_diff) |
|
264 |
moreover from `inj_on f A` have "inj_on f (A - {y})" by (rule inj_on_diff) |
|
265 |
ultimately have "finite (A - {y})" by (rule insert.hyps) |
|
266 |
then show "finite A" by simp |
|
267 |
qed |
|
12396 | 268 |
|
41656 | 269 |
lemma finite_surj: |
270 |
"finite A \<Longrightarrow> B \<subseteq> f ` A \<Longrightarrow> finite B" |
|
271 |
by (erule finite_subset) (rule finite_imageI) |
|
12396 | 272 |
|
41656 | 273 |
lemma finite_range_imageI: |
274 |
"finite (range g) \<Longrightarrow> finite (range (\<lambda>x. f (g x)))" |
|
275 |
by (drule finite_imageI) (simp add: range_composition) |
|
13825 | 276 |
|
41656 | 277 |
lemma finite_subset_image: |
278 |
assumes "finite B" |
|
279 |
shows "B \<subseteq> f ` A \<Longrightarrow> \<exists>C\<subseteq>A. finite C \<and> B = f ` C" |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
280 |
using assms |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
281 |
proof induct |
41656 | 282 |
case empty then show ?case by simp |
283 |
next |
|
284 |
case insert then show ?case |
|
285 |
by (clarsimp simp del: image_insert simp add: image_insert [symmetric]) |
|
286 |
blast |
|
287 |
qed |
|
288 |
||
43991 | 289 |
lemma finite_vimage_IntI: |
290 |
"finite F \<Longrightarrow> inj_on h A \<Longrightarrow> finite (h -` F \<inter> A)" |
|
41656 | 291 |
apply (induct rule: finite_induct) |
21575 | 292 |
apply simp_all |
14430
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
paulson
parents:
14331
diff
changeset
|
293 |
apply (subst vimage_insert) |
43991 | 294 |
apply (simp add: finite_subset [OF inj_on_vimage_singleton] Int_Un_distrib2) |
13825 | 295 |
done |
296 |
||
43991 | 297 |
lemma finite_vimageI: |
298 |
"finite F \<Longrightarrow> inj h \<Longrightarrow> finite (h -` F)" |
|
299 |
using finite_vimage_IntI[of F h UNIV] by auto |
|
300 |
||
34111
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
301 |
lemma finite_vimageD: |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
302 |
assumes fin: "finite (h -` F)" and surj: "surj h" |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
303 |
shows "finite F" |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
304 |
proof - |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
305 |
have "finite (h ` (h -` F))" using fin by (rule finite_imageI) |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
306 |
also have "h ` (h -` F) = F" using surj by (rule surj_image_vimage_eq) |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
307 |
finally show "finite F" . |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
308 |
qed |
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
309 |
|
1b015caba46c
add lemmas rev_finite_subset, finite_vimageD, finite_vimage_iff
huffman
parents:
34007
diff
changeset
|
310 |
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
|
311 |
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
|
312 |
|
41656 | 313 |
lemma finite_Collect_bex [simp]: |
314 |
assumes "finite A" |
|
315 |
shows "finite {x. \<exists>y\<in>A. Q x y} \<longleftrightarrow> (\<forall>y\<in>A. finite {x. Q x y})" |
|
316 |
proof - |
|
317 |
have "{x. \<exists>y\<in>A. Q x y} = (\<Union>y\<in>A. {x. Q x y})" by auto |
|
318 |
with assms show ?thesis by simp |
|
319 |
qed |
|
12396 | 320 |
|
41656 | 321 |
lemma finite_Collect_bounded_ex [simp]: |
322 |
assumes "finite {y. P y}" |
|
323 |
shows "finite {x. \<exists>y. P y \<and> Q x y} \<longleftrightarrow> (\<forall>y. P y \<longrightarrow> finite {x. Q x y})" |
|
324 |
proof - |
|
325 |
have "{x. EX y. P y & Q x y} = (\<Union>y\<in>{y. P y}. {x. Q x y})" by auto |
|
326 |
with assms show ?thesis by simp |
|
327 |
qed |
|
29920 | 328 |
|
41656 | 329 |
lemma finite_Plus: |
330 |
"finite A \<Longrightarrow> finite B \<Longrightarrow> finite (A <+> B)" |
|
331 |
by (simp add: Plus_def) |
|
17022 | 332 |
|
31080 | 333 |
lemma finite_PlusD: |
334 |
fixes A :: "'a set" and B :: "'b set" |
|
335 |
assumes fin: "finite (A <+> B)" |
|
336 |
shows "finite A" "finite B" |
|
337 |
proof - |
|
338 |
have "Inl ` A \<subseteq> A <+> B" by auto |
|
41656 | 339 |
then have "finite (Inl ` A :: ('a + 'b) set)" using fin by (rule finite_subset) |
340 |
then show "finite A" by (rule finite_imageD) (auto intro: inj_onI) |
|
31080 | 341 |
next |
342 |
have "Inr ` B \<subseteq> A <+> B" by auto |
|
41656 | 343 |
then have "finite (Inr ` B :: ('a + 'b) set)" using fin by (rule finite_subset) |
344 |
then show "finite B" by (rule finite_imageD) (auto intro: inj_onI) |
|
31080 | 345 |
qed |
346 |
||
41656 | 347 |
lemma finite_Plus_iff [simp]: |
348 |
"finite (A <+> B) \<longleftrightarrow> finite A \<and> finite B" |
|
349 |
by (auto intro: finite_PlusD finite_Plus) |
|
31080 | 350 |
|
41656 | 351 |
lemma finite_Plus_UNIV_iff [simp]: |
352 |
"finite (UNIV :: ('a + 'b) set) \<longleftrightarrow> finite (UNIV :: 'a set) \<and> finite (UNIV :: 'b set)" |
|
353 |
by (subst UNIV_Plus_UNIV [symmetric]) (rule finite_Plus_iff) |
|
12396 | 354 |
|
40786
0a54cfc9add3
gave more standard finite set rules simp and intro attribute
nipkow
parents:
40716
diff
changeset
|
355 |
lemma finite_SigmaI [simp, intro]: |
41656 | 356 |
"finite A \<Longrightarrow> (\<And>a. a\<in>A \<Longrightarrow> finite (B a)) ==> finite (SIGMA a:A. B a)" |
40786
0a54cfc9add3
gave more standard finite set rules simp and intro attribute
nipkow
parents:
40716
diff
changeset
|
357 |
by (unfold Sigma_def) blast |
12396 | 358 |
|
41656 | 359 |
lemma finite_cartesian_product: |
360 |
"finite A \<Longrightarrow> finite B \<Longrightarrow> finite (A \<times> B)" |
|
15402 | 361 |
by (rule finite_SigmaI) |
362 |
||
12396 | 363 |
lemma finite_Prod_UNIV: |
41656 | 364 |
"finite (UNIV :: 'a set) \<Longrightarrow> finite (UNIV :: 'b set) \<Longrightarrow> finite (UNIV :: ('a \<times> 'b) set)" |
365 |
by (simp only: UNIV_Times_UNIV [symmetric] finite_cartesian_product) |
|
12396 | 366 |
|
15409
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
paulson
parents:
15402
diff
changeset
|
367 |
lemma finite_cartesian_productD1: |
42207 | 368 |
assumes "finite (A \<times> B)" and "B \<noteq> {}" |
369 |
shows "finite A" |
|
370 |
proof - |
|
371 |
from assms obtain n f where "A \<times> B = f ` {i::nat. i < n}" |
|
372 |
by (auto simp add: finite_conv_nat_seg_image) |
|
373 |
then have "fst ` (A \<times> B) = fst ` f ` {i::nat. i < n}" by simp |
|
374 |
with `B \<noteq> {}` have "A = (fst \<circ> f) ` {i::nat. i < n}" |
|
375 |
by (simp add: image_compose) |
|
376 |
then have "\<exists>n f. A = f ` {i::nat. i < n}" by blast |
|
377 |
then show ?thesis |
|
378 |
by (auto simp add: finite_conv_nat_seg_image) |
|
379 |
qed |
|
15409
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
paulson
parents:
15402
diff
changeset
|
380 |
|
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
paulson
parents:
15402
diff
changeset
|
381 |
lemma finite_cartesian_productD2: |
42207 | 382 |
assumes "finite (A \<times> B)" and "A \<noteq> {}" |
383 |
shows "finite B" |
|
384 |
proof - |
|
385 |
from assms obtain n f where "A \<times> B = f ` {i::nat. i < n}" |
|
386 |
by (auto simp add: finite_conv_nat_seg_image) |
|
387 |
then have "snd ` (A \<times> B) = snd ` f ` {i::nat. i < n}" by simp |
|
388 |
with `A \<noteq> {}` have "B = (snd \<circ> f) ` {i::nat. i < n}" |
|
389 |
by (simp add: image_compose) |
|
390 |
then have "\<exists>n f. B = f ` {i::nat. i < n}" by blast |
|
391 |
then show ?thesis |
|
392 |
by (auto simp add: finite_conv_nat_seg_image) |
|
393 |
qed |
|
15409
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
paulson
parents:
15402
diff
changeset
|
394 |
|
48175
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
395 |
lemma finite_prod: |
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
396 |
"finite (UNIV :: ('a \<times> 'b) set) \<longleftrightarrow> finite (UNIV :: 'a set) \<and> finite (UNIV :: 'b set)" |
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
397 |
by(auto simp add: UNIV_Times_UNIV[symmetric] simp del: UNIV_Times_UNIV |
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
398 |
dest: finite_cartesian_productD1 finite_cartesian_productD2) |
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
399 |
|
41656 | 400 |
lemma finite_Pow_iff [iff]: |
401 |
"finite (Pow A) \<longleftrightarrow> finite A" |
|
12396 | 402 |
proof |
403 |
assume "finite (Pow A)" |
|
41656 | 404 |
then have "finite ((%x. {x}) ` A)" by (blast intro: finite_subset) |
405 |
then show "finite A" by (rule finite_imageD [unfolded inj_on_def]) simp |
|
12396 | 406 |
next |
407 |
assume "finite A" |
|
41656 | 408 |
then show "finite (Pow A)" |
35216 | 409 |
by induct (simp_all add: Pow_insert) |
12396 | 410 |
qed |
411 |
||
41656 | 412 |
corollary finite_Collect_subsets [simp, intro]: |
413 |
"finite A \<Longrightarrow> finite {B. B \<subseteq> A}" |
|
414 |
by (simp add: Pow_def [symmetric]) |
|
29918 | 415 |
|
48175
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
416 |
lemma finite_set: "finite (UNIV :: 'a set set) \<longleftrightarrow> finite (UNIV :: 'a set)" |
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
417 |
by(simp only: finite_Pow_iff Pow_UNIV[symmetric]) |
fea68365c975
add finiteness lemmas for 'a * 'b and 'a set
Andreas Lochbihler
parents:
48128
diff
changeset
|
418 |
|
15392 | 419 |
lemma finite_UnionD: "finite(\<Union>A) \<Longrightarrow> finite A" |
41656 | 420 |
by (blast intro: finite_subset [OF subset_Pow_Union]) |
15392 | 421 |
|
422 |
||
41656 | 423 |
subsubsection {* Further induction rules on finite sets *} |
424 |
||
425 |
lemma finite_ne_induct [case_names singleton insert, consumes 2]: |
|
426 |
assumes "finite F" and "F \<noteq> {}" |
|
427 |
assumes "\<And>x. P {x}" |
|
428 |
and "\<And>x F. finite F \<Longrightarrow> F \<noteq> {} \<Longrightarrow> x \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert x F)" |
|
429 |
shows "P F" |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
430 |
using assms |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
431 |
proof induct |
41656 | 432 |
case empty then show ?case by simp |
433 |
next |
|
434 |
case (insert x F) then show ?case by cases auto |
|
435 |
qed |
|
436 |
||
437 |
lemma finite_subset_induct [consumes 2, case_names empty insert]: |
|
438 |
assumes "finite F" and "F \<subseteq> A" |
|
439 |
assumes empty: "P {}" |
|
440 |
and insert: "\<And>a F. finite F \<Longrightarrow> a \<in> A \<Longrightarrow> a \<notin> F \<Longrightarrow> P F \<Longrightarrow> P (insert a F)" |
|
441 |
shows "P F" |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
442 |
using `finite F` `F \<subseteq> A` |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
443 |
proof induct |
41656 | 444 |
show "P {}" by fact |
31441 | 445 |
next |
41656 | 446 |
fix x F |
447 |
assume "finite F" and "x \<notin> F" and |
|
448 |
P: "F \<subseteq> A \<Longrightarrow> P F" and i: "insert x F \<subseteq> A" |
|
449 |
show "P (insert x F)" |
|
450 |
proof (rule insert) |
|
451 |
from i show "x \<in> A" by blast |
|
452 |
from i have "F \<subseteq> A" by blast |
|
453 |
with P show "P F" . |
|
454 |
show "finite F" by fact |
|
455 |
show "x \<notin> F" by fact |
|
456 |
qed |
|
457 |
qed |
|
458 |
||
459 |
lemma finite_empty_induct: |
|
460 |
assumes "finite A" |
|
461 |
assumes "P A" |
|
462 |
and remove: "\<And>a A. finite A \<Longrightarrow> a \<in> A \<Longrightarrow> P A \<Longrightarrow> P (A - {a})" |
|
463 |
shows "P {}" |
|
464 |
proof - |
|
465 |
have "\<And>B. B \<subseteq> A \<Longrightarrow> P (A - B)" |
|
466 |
proof - |
|
467 |
fix B :: "'a set" |
|
468 |
assume "B \<subseteq> A" |
|
469 |
with `finite A` have "finite B" by (rule rev_finite_subset) |
|
470 |
from this `B \<subseteq> A` show "P (A - B)" |
|
471 |
proof induct |
|
472 |
case empty |
|
473 |
from `P A` show ?case by simp |
|
474 |
next |
|
475 |
case (insert b B) |
|
476 |
have "P (A - B - {b})" |
|
477 |
proof (rule remove) |
|
478 |
from `finite A` show "finite (A - B)" by induct auto |
|
479 |
from insert show "b \<in> A - B" by simp |
|
480 |
from insert show "P (A - B)" by simp |
|
481 |
qed |
|
482 |
also have "A - B - {b} = A - insert b B" by (rule Diff_insert [symmetric]) |
|
483 |
finally show ?case . |
|
484 |
qed |
|
485 |
qed |
|
486 |
then have "P (A - A)" by blast |
|
487 |
then show ?thesis by simp |
|
31441 | 488 |
qed |
489 |
||
490 |
||
26441 | 491 |
subsection {* Class @{text finite} *} |
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
492 |
|
29797 | 493 |
class finite = |
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
494 |
assumes finite_UNIV: "finite (UNIV \<Colon> 'a set)" |
27430 | 495 |
begin |
496 |
||
497 |
lemma finite [simp]: "finite (A \<Colon> 'a set)" |
|
26441 | 498 |
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
|
499 |
|
43866
8a50dc70cbff
moving UNIV = ... equations to their proper theories
haftmann
parents:
42875
diff
changeset
|
500 |
lemma finite_code [code]: "finite (A \<Colon> 'a set) \<longleftrightarrow> True" |
40922
4d0f96a54e76
adding code equation for finiteness of finite types
bulwahn
parents:
40786
diff
changeset
|
501 |
by simp |
4d0f96a54e76
adding code equation for finiteness of finite types
bulwahn
parents:
40786
diff
changeset
|
502 |
|
27430 | 503 |
end |
504 |
||
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
505 |
instance prod :: (finite, finite) finite |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
506 |
by default (simp only: UNIV_Times_UNIV [symmetric] finite_cartesian_product finite) |
26146 | 507 |
|
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
|
508 |
lemma inj_graph: "inj (%f. {(x, y). y = f x})" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
509 |
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
|
510 |
|
26146 | 511 |
instance "fun" :: (finite, finite) finite |
512 |
proof |
|
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
513 |
show "finite (UNIV :: ('a => 'b) set)" |
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
514 |
proof (rule finite_imageD) |
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
515 |
let ?graph = "%f::'a => 'b. {(x, y). y = f x}" |
26792 | 516 |
have "range ?graph \<subseteq> Pow UNIV" by simp |
517 |
moreover have "finite (Pow (UNIV :: ('a * 'b) set))" |
|
518 |
by (simp only: finite_Pow_iff finite) |
|
519 |
ultimately show "finite (range ?graph)" |
|
520 |
by (rule finite_subset) |
|
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
521 |
show "inj ?graph" by (rule inj_graph) |
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
522 |
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
|
523 |
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
|
524 |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
525 |
instance bool :: finite |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
526 |
by default (simp add: UNIV_bool) |
44831 | 527 |
|
45962 | 528 |
instance set :: (finite) finite |
529 |
by default (simp only: Pow_UNIV [symmetric] finite_Pow_iff finite) |
|
530 |
||
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
531 |
instance unit :: finite |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
532 |
by default (simp add: UNIV_unit) |
44831 | 533 |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
534 |
instance sum :: (finite, finite) finite |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
535 |
by default (simp only: UNIV_Plus_UNIV [symmetric] finite_Plus finite) |
27981 | 536 |
|
44831 | 537 |
lemma finite_option_UNIV [simp]: |
538 |
"finite (UNIV :: 'a option set) = finite (UNIV :: 'a set)" |
|
539 |
by (auto simp add: UNIV_option_conv elim: finite_imageD intro: inj_Some) |
|
540 |
||
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
541 |
instance option :: (finite) finite |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
542 |
by default (simp add: UNIV_option_conv) |
44831 | 543 |
|
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
544 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
545 |
subsection {* A basic fold functional for finite sets *} |
15392 | 546 |
|
547 |
text {* The intended behaviour is |
|
31916
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
wenzelm
parents:
31907
diff
changeset
|
548 |
@{text "fold f z {x\<^isub>1, ..., x\<^isub>n} = f x\<^isub>1 (\<dots> (f x\<^isub>n z)\<dots>)"} |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
549 |
if @{text f} is ``left-commutative'': |
15392 | 550 |
*} |
551 |
||
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
552 |
locale comp_fun_commute = |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
553 |
fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
554 |
assumes comp_fun_commute: "f y \<circ> f x = f x \<circ> f y" |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
555 |
begin |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
556 |
|
42809
5b45125b15ba
use pointfree characterisation for fold_set locale
haftmann
parents:
42715
diff
changeset
|
557 |
lemma fun_left_comm: "f x (f y z) = f y (f x z)" |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
558 |
using comp_fun_commute by (simp add: fun_eq_iff) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
559 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
560 |
end |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
561 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
562 |
inductive fold_graph :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> bool" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
563 |
for f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" and z :: 'b where |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
564 |
emptyI [intro]: "fold_graph f z {} z" | |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
565 |
insertI [intro]: "x \<notin> A \<Longrightarrow> fold_graph f z A y |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
566 |
\<Longrightarrow> fold_graph f z (insert x A) (f x y)" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
567 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
568 |
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
|
569 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
570 |
definition fold :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b" where |
37767 | 571 |
"fold f z A = (THE y. fold_graph f z A y)" |
15392 | 572 |
|
15498 | 573 |
text{*A tempting alternative for the definiens is |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
574 |
@{term "if finite A then THE y. fold_graph f z A y else e"}. |
15498 | 575 |
It allows the removal of finiteness assumptions from the theorems |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
576 |
@{text fold_comm}, @{text fold_reindex} and @{text fold_distrib}. |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
577 |
The proofs become ugly. It is not worth the effort. (???) *} |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
578 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
579 |
lemma finite_imp_fold_graph: "finite A \<Longrightarrow> \<exists>x. fold_graph f z A x" |
41656 | 580 |
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
|
581 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
582 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
583 |
subsubsection{*From @{const fold_graph} to @{term fold}*} |
15392 | 584 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
585 |
context comp_fun_commute |
26041
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
haftmann
parents:
25571
diff
changeset
|
586 |
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
|
587 |
|
36045 | 588 |
lemma fold_graph_insertE_aux: |
589 |
"fold_graph f z A y \<Longrightarrow> a \<in> A \<Longrightarrow> \<exists>y'. y = f a y' \<and> fold_graph f z (A - {a}) y'" |
|
590 |
proof (induct set: fold_graph) |
|
591 |
case (insertI x A y) show ?case |
|
592 |
proof (cases "x = a") |
|
593 |
assume "x = a" with insertI show ?case by auto |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
594 |
next |
36045 | 595 |
assume "x \<noteq> a" |
596 |
then obtain y' where y: "y = f a y'" and y': "fold_graph f z (A - {a}) y'" |
|
597 |
using insertI by auto |
|
42875 | 598 |
have "f x y = f a (f x y')" |
36045 | 599 |
unfolding y by (rule fun_left_comm) |
42875 | 600 |
moreover have "fold_graph f z (insert x A - {a}) (f x y')" |
36045 | 601 |
using y' and `x \<noteq> a` and `x \<notin> A` |
602 |
by (simp add: insert_Diff_if fold_graph.insertI) |
|
42875 | 603 |
ultimately show ?case by fast |
15392 | 604 |
qed |
36045 | 605 |
qed simp |
606 |
||
607 |
lemma fold_graph_insertE: |
|
608 |
assumes "fold_graph f z (insert x A) v" and "x \<notin> A" |
|
609 |
obtains y where "v = f x y" and "fold_graph f z A y" |
|
610 |
using assms by (auto dest: fold_graph_insertE_aux [OF _ insertI1]) |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
611 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
612 |
lemma fold_graph_determ: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
613 |
"fold_graph f z A x \<Longrightarrow> fold_graph f z A y \<Longrightarrow> y = x" |
36045 | 614 |
proof (induct arbitrary: y set: fold_graph) |
615 |
case (insertI x A y v) |
|
616 |
from `fold_graph f z (insert x A) v` and `x \<notin> A` |
|
617 |
obtain y' where "v = f x y'" and "fold_graph f z A y'" |
|
618 |
by (rule fold_graph_insertE) |
|
619 |
from `fold_graph f z A y'` have "y' = y" by (rule insertI) |
|
620 |
with `v = f x y'` show "v = f x y" by simp |
|
621 |
qed fast |
|
15392 | 622 |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
623 |
lemma fold_equality: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
624 |
"fold_graph f z A y \<Longrightarrow> fold f z A = y" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
625 |
by (unfold fold_def) (blast intro: fold_graph_determ) |
15392 | 626 |
|
42272 | 627 |
lemma fold_graph_fold: |
628 |
assumes "finite A" |
|
629 |
shows "fold_graph f z A (fold f z A)" |
|
630 |
proof - |
|
631 |
from assms have "\<exists>x. fold_graph f z A x" by (rule finite_imp_fold_graph) |
|
632 |
moreover note fold_graph_determ |
|
633 |
ultimately have "\<exists>!x. fold_graph f z A x" by (rule ex_ex1I) |
|
634 |
then have "fold_graph f z A (The (fold_graph f z A))" by (rule theI') |
|
635 |
then show ?thesis by (unfold fold_def) |
|
636 |
qed |
|
36045 | 637 |
|
15392 | 638 |
text{* The base case for @{text fold}: *} |
639 |
||
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
640 |
lemma (in -) fold_empty [simp]: "fold f z {} = z" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
641 |
by (unfold fold_def) blast |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
642 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
643 |
text{* The various recursion equations for @{const fold}: *} |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
644 |
|
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
|
645 |
lemma fold_insert [simp]: |
42875 | 646 |
assumes "finite A" and "x \<notin> A" |
647 |
shows "fold f z (insert x A) = f x (fold f z A)" |
|
648 |
proof (rule fold_equality) |
|
649 |
from `finite A` have "fold_graph f z A (fold f z A)" by (rule fold_graph_fold) |
|
650 |
with `x \<notin> A`show "fold_graph f z (insert x A) (f x (fold f z A))" by (rule fold_graph.insertI) |
|
651 |
qed |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
652 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
653 |
lemma fold_fun_comm: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
654 |
"finite A \<Longrightarrow> f x (fold f z A) = fold f (f x z) A" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
655 |
proof (induct rule: finite_induct) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
656 |
case empty then show ?case by simp |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
657 |
next |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
658 |
case (insert y A) then show ?case |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
659 |
by (simp add: fun_left_comm[of x]) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
660 |
qed |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
661 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
662 |
lemma fold_insert2: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
663 |
"finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A" |
35216 | 664 |
by (simp add: fold_fun_comm) |
15392 | 665 |
|
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
|
666 |
lemma fold_rec: |
42875 | 667 |
assumes "finite A" and "x \<in> A" |
668 |
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
|
669 |
proof - |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
670 |
have A: "A = insert x (A - {x})" using `x \<in> A` by blast |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
671 |
then have "fold f z A = fold f z (insert x (A - {x}))" by simp |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
672 |
also have "\<dots> = f x (fold f z (A - {x}))" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
673 |
by (rule fold_insert) (simp add: `finite A`)+ |
15535 | 674 |
finally show ?thesis . |
675 |
qed |
|
676 |
||
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
677 |
lemma fold_insert_remove: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
678 |
assumes "finite A" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
679 |
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
|
680 |
proof - |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
681 |
from `finite A` have "finite (insert x A)" by auto |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
682 |
moreover have "x \<in> insert x A" by auto |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
683 |
ultimately have "fold f z (insert x A) = f x (fold f z (insert x A - {x}))" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
684 |
by (rule fold_rec) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
685 |
then show ?thesis by simp |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
686 |
qed |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
687 |
|
48619 | 688 |
text{* Other properties of @{const fold}: *} |
689 |
||
690 |
lemma fold_image: |
|
691 |
assumes "finite A" and "inj_on g A" |
|
692 |
shows "fold f x (g ` A) = fold (f \<circ> g) x A" |
|
693 |
using assms |
|
694 |
proof induction |
|
695 |
case (insert a F) |
|
696 |
interpret comp_fun_commute "\<lambda>x. f (g x)" by default (simp add: comp_fun_commute) |
|
697 |
from insert show ?case by auto |
|
698 |
qed (simp) |
|
699 |
||
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
|
700 |
end |
15392 | 701 |
|
49724 | 702 |
lemma fold_cong: |
703 |
assumes "comp_fun_commute f" "comp_fun_commute g" |
|
704 |
assumes "finite A" and cong: "\<And>x. x \<in> A \<Longrightarrow> f x = g x" |
|
705 |
and "A = B" and "s = t" |
|
706 |
shows "Finite_Set.fold f s A = Finite_Set.fold g t B" |
|
707 |
proof - |
|
708 |
have "Finite_Set.fold f s A = Finite_Set.fold g s A" |
|
709 |
using `finite A` cong proof (induct A) |
|
710 |
case empty then show ?case by simp |
|
711 |
next |
|
712 |
case (insert x A) |
|
713 |
interpret f: comp_fun_commute f by (fact `comp_fun_commute f`) |
|
714 |
interpret g: comp_fun_commute g by (fact `comp_fun_commute g`) |
|
715 |
from insert show ?case by simp |
|
716 |
qed |
|
717 |
with assms show ?thesis by simp |
|
718 |
qed |
|
719 |
||
720 |
||
15480 | 721 |
text{* A simplified version for idempotent functions: *} |
722 |
||
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
723 |
locale comp_fun_idem = comp_fun_commute + |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
724 |
assumes comp_fun_idem: "f x o 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
|
725 |
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
|
726 |
|
42869
43b0f61f56d0
use point-free characterization for locale fun_left_comm_idem
haftmann
parents:
42809
diff
changeset
|
727 |
lemma fun_left_idem: "f x (f x z) = f x z" |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
728 |
using comp_fun_idem by (simp add: fun_eq_iff) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
729 |
|
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
|
730 |
lemma fold_insert_idem: |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
731 |
assumes fin: "finite A" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
732 |
shows "fold f z (insert x A) = f x (fold f z A)" |
15480 | 733 |
proof cases |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
734 |
assume "x \<in> A" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
735 |
then obtain B where "A = insert x B" and "x \<notin> B" by (rule set_insert) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
736 |
then show ?thesis using assms by (simp add:fun_left_idem) |
15480 | 737 |
next |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
738 |
assume "x \<notin> A" then show ?thesis using assms by simp |
15480 | 739 |
qed |
740 |
||
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
741 |
declare fold_insert[simp del] fold_insert_idem[simp] |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
742 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
743 |
lemma fold_insert_idem2: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
744 |
"finite A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
745 |
by(simp add:fold_fun_comm) |
15484 | 746 |
|
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
|
747 |
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
|
748 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
749 |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
750 |
subsubsection {* Liftings to @{text comp_fun_commute} etc. *} |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
751 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
752 |
lemma (in comp_fun_commute) comp_comp_fun_commute: |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
753 |
"comp_fun_commute (f \<circ> g)" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
754 |
proof |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
755 |
qed (simp_all add: comp_fun_commute) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
756 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
757 |
lemma (in comp_fun_idem) comp_comp_fun_idem: |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
758 |
"comp_fun_idem (f \<circ> g)" |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
759 |
by (rule comp_fun_idem.intro, rule comp_comp_fun_commute, unfold_locales) |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
760 |
(simp_all add: comp_fun_idem) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
761 |
|
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
762 |
lemma (in comp_fun_commute) comp_fun_commute_funpow: |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
763 |
"comp_fun_commute (\<lambda>x. f x ^^ g x)" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
764 |
proof |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
765 |
fix y x |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
766 |
show "f y ^^ g y \<circ> f x ^^ g x = f x ^^ g x \<circ> f y ^^ g y" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
767 |
proof (cases "x = y") |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
768 |
case True then show ?thesis by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
769 |
next |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
770 |
case False show ?thesis |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
771 |
proof (induct "g x" arbitrary: g) |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
772 |
case 0 then show ?case by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
773 |
next |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
774 |
case (Suc n g) |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
775 |
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
|
776 |
proof (induct "g y" arbitrary: g) |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
777 |
case 0 then show ?case by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
778 |
next |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
779 |
case (Suc n g) |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
780 |
def h \<equiv> "\<lambda>z. g z - 1" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
781 |
with Suc have "n = h y" by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
782 |
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
|
783 |
by auto |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
784 |
from Suc h_def have "g y = Suc (h y)" by simp |
49739 | 785 |
then show ?case by (simp add: comp_assoc hyp) |
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
786 |
(simp add: o_assoc comp_fun_commute) |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
787 |
qed |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
788 |
def h \<equiv> "\<lambda>z. if z = x then g x - 1 else g z" |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
789 |
with Suc have "n = h x" by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
790 |
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
|
791 |
by auto |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
792 |
with False h_def have hyp2: "f y ^^ g y \<circ> f x ^^ h x = f x ^^ h x \<circ> f y ^^ g y" by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
793 |
from Suc h_def have "g x = Suc (h x)" by simp |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
794 |
then show ?case by (simp del: funpow.simps add: funpow_Suc_right o_assoc hyp2) |
49739 | 795 |
(simp add: comp_assoc hyp1) |
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
796 |
qed |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
797 |
qed |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
798 |
qed |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
799 |
|
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
800 |
|
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
801 |
subsubsection {* Expressing set operations via @{const fold} *} |
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
802 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
803 |
lemma comp_fun_idem_insert: |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
804 |
"comp_fun_idem insert" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
805 |
proof |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
806 |
qed auto |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
807 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
808 |
lemma comp_fun_idem_remove: |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
809 |
"comp_fun_idem Set.remove" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
810 |
proof |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
811 |
qed auto |
31992 | 812 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
813 |
lemma (in semilattice_inf) comp_fun_idem_inf: |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
814 |
"comp_fun_idem inf" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
815 |
proof |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
816 |
qed (auto simp add: inf_left_commute) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
817 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
818 |
lemma (in semilattice_sup) comp_fun_idem_sup: |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
819 |
"comp_fun_idem sup" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
820 |
proof |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
821 |
qed (auto simp add: sup_left_commute) |
31992 | 822 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
823 |
lemma union_fold_insert: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
824 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
825 |
shows "A \<union> B = fold insert B A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
826 |
proof - |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
827 |
interpret comp_fun_idem insert by (fact comp_fun_idem_insert) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
828 |
from `finite A` show ?thesis by (induct A arbitrary: B) simp_all |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
829 |
qed |
31992 | 830 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
831 |
lemma minus_fold_remove: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
832 |
assumes "finite A" |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
833 |
shows "B - A = fold Set.remove B A" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
834 |
proof - |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
835 |
interpret comp_fun_idem Set.remove by (fact comp_fun_idem_remove) |
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
836 |
from `finite A` have "fold Set.remove B A = B - A" by (induct A arbitrary: B) auto |
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
837 |
then show ?thesis .. |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
838 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
839 |
|
48619 | 840 |
lemma comp_fun_commute_filter_fold: "comp_fun_commute (\<lambda>x A'. if P x then Set.insert x A' else A')" |
841 |
proof - |
|
842 |
interpret comp_fun_idem Set.insert by (fact comp_fun_idem_insert) |
|
843 |
show ?thesis by default (auto simp: fun_eq_iff) |
|
844 |
qed |
|
845 |
||
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
846 |
lemma Set_filter_fold: |
48619 | 847 |
assumes "finite A" |
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
848 |
shows "Set.filter P A = fold (\<lambda>x A'. if P x then Set.insert x A' else A') {} A" |
48619 | 849 |
using assms |
850 |
by (induct A) |
|
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
851 |
(auto simp add: Set.filter_def comp_fun_commute.fold_insert[OF comp_fun_commute_filter_fold]) |
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
852 |
|
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
853 |
lemma inter_Set_filter: |
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
854 |
assumes "finite B" |
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
855 |
shows "A \<inter> B = Set.filter (\<lambda>x. x \<in> A) B" |
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
856 |
using assms |
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
857 |
by (induct B) (auto simp: Set.filter_def) |
48619 | 858 |
|
859 |
lemma image_fold_insert: |
|
860 |
assumes "finite A" |
|
861 |
shows "image f A = fold (\<lambda>k A. Set.insert (f k) A) {} A" |
|
862 |
using assms |
|
863 |
proof - |
|
864 |
interpret comp_fun_commute "\<lambda>k A. Set.insert (f k) A" by default auto |
|
865 |
show ?thesis using assms by (induct A) auto |
|
866 |
qed |
|
867 |
||
868 |
lemma Ball_fold: |
|
869 |
assumes "finite A" |
|
870 |
shows "Ball A P = fold (\<lambda>k s. s \<and> P k) True A" |
|
871 |
using assms |
|
872 |
proof - |
|
873 |
interpret comp_fun_commute "\<lambda>k s. s \<and> P k" by default auto |
|
874 |
show ?thesis using assms by (induct A) auto |
|
875 |
qed |
|
876 |
||
877 |
lemma Bex_fold: |
|
878 |
assumes "finite A" |
|
879 |
shows "Bex A P = fold (\<lambda>k s. s \<or> P k) False A" |
|
880 |
using assms |
|
881 |
proof - |
|
882 |
interpret comp_fun_commute "\<lambda>k s. s \<or> P k" by default auto |
|
883 |
show ?thesis using assms by (induct A) auto |
|
884 |
qed |
|
885 |
||
886 |
lemma comp_fun_commute_Pow_fold: |
|
887 |
"comp_fun_commute (\<lambda>x A. A \<union> Set.insert x ` A)" |
|
888 |
by (clarsimp simp: fun_eq_iff comp_fun_commute_def) blast |
|
889 |
||
890 |
lemma Pow_fold: |
|
891 |
assumes "finite A" |
|
892 |
shows "Pow A = fold (\<lambda>x A. A \<union> Set.insert x ` A) {{}} A" |
|
893 |
using assms |
|
894 |
proof - |
|
895 |
interpret comp_fun_commute "\<lambda>x A. A \<union> Set.insert x ` A" by (rule comp_fun_commute_Pow_fold) |
|
896 |
show ?thesis using assms by (induct A) (auto simp: Pow_insert) |
|
897 |
qed |
|
898 |
||
899 |
lemma fold_union_pair: |
|
900 |
assumes "finite B" |
|
901 |
shows "(\<Union>y\<in>B. {(x, y)}) \<union> A = fold (\<lambda>y. Set.insert (x, y)) A B" |
|
902 |
proof - |
|
903 |
interpret comp_fun_commute "\<lambda>y. Set.insert (x, y)" by default auto |
|
904 |
show ?thesis using assms by (induct B arbitrary: A) simp_all |
|
905 |
qed |
|
906 |
||
907 |
lemma comp_fun_commute_product_fold: |
|
908 |
assumes "finite B" |
|
909 |
shows "comp_fun_commute (\<lambda>x A. fold (\<lambda>y. Set.insert (x, y)) A B)" |
|
910 |
by default (auto simp: fold_union_pair[symmetric] assms) |
|
911 |
||
912 |
lemma product_fold: |
|
913 |
assumes "finite A" |
|
914 |
assumes "finite B" |
|
915 |
shows "A \<times> B = fold (\<lambda>x A. fold (\<lambda>y. Set.insert (x, y)) A B) {} A" |
|
916 |
using assms unfolding Sigma_def |
|
917 |
by (induct A) |
|
918 |
(simp_all add: comp_fun_commute.fold_insert[OF comp_fun_commute_product_fold] fold_union_pair) |
|
919 |
||
920 |
||
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
921 |
context complete_lattice |
31992 | 922 |
begin |
923 |
||
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
924 |
lemma inf_Inf_fold_inf: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
925 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
926 |
shows "inf B (Inf A) = fold inf B A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
927 |
proof - |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
928 |
interpret comp_fun_idem inf by (fact comp_fun_idem_inf) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
929 |
from `finite A` show ?thesis by (induct A arbitrary: B) |
44919 | 930 |
(simp_all add: inf_commute fold_fun_comm) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
931 |
qed |
31992 | 932 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
933 |
lemma sup_Sup_fold_sup: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
934 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
935 |
shows "sup B (Sup A) = fold sup B A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
936 |
proof - |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
937 |
interpret comp_fun_idem sup by (fact comp_fun_idem_sup) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
938 |
from `finite A` show ?thesis by (induct A arbitrary: B) |
44919 | 939 |
(simp_all add: sup_commute fold_fun_comm) |
31992 | 940 |
qed |
941 |
||
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
942 |
lemma Inf_fold_inf: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
943 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
944 |
shows "Inf A = fold inf top A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
945 |
using assms inf_Inf_fold_inf [of A top] by (simp add: inf_absorb2) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
946 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
947 |
lemma Sup_fold_sup: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
948 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
949 |
shows "Sup A = fold sup bot A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
950 |
using assms sup_Sup_fold_sup [of A bot] by (simp add: sup_absorb2) |
31992 | 951 |
|
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
952 |
lemma inf_INF_fold_inf: |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
953 |
assumes "finite A" |
42873
da1253ff1764
point-free characterization of operations on finite sets
haftmann
parents:
42871
diff
changeset
|
954 |
shows "inf B (INFI A f) = fold (inf \<circ> f) B A" (is "?inf = ?fold") |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
955 |
proof (rule sym) |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
956 |
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
|
957 |
interpret comp_fun_idem "inf \<circ> f" by (fact comp_comp_fun_idem) |
42873
da1253ff1764
point-free characterization of operations on finite sets
haftmann
parents:
42871
diff
changeset
|
958 |
from `finite A` show "?fold = ?inf" |
42869
43b0f61f56d0
use point-free characterization for locale fun_left_comm_idem
haftmann
parents:
42809
diff
changeset
|
959 |
by (induct A arbitrary: B) |
44928
7ef6505bde7f
renamed Complete_Lattices lemmas, removed legacy names
hoelzl
parents:
44919
diff
changeset
|
960 |
(simp_all add: INF_def inf_left_commute) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
961 |
qed |
31992 | 962 |
|
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
963 |
lemma sup_SUP_fold_sup: |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
964 |
assumes "finite A" |
42873
da1253ff1764
point-free characterization of operations on finite sets
haftmann
parents:
42871
diff
changeset
|
965 |
shows "sup B (SUPR A f) = fold (sup \<circ> f) B A" (is "?sup = ?fold") |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
966 |
proof (rule sym) |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
967 |
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
|
968 |
interpret comp_fun_idem "sup \<circ> f" by (fact comp_comp_fun_idem) |
42873
da1253ff1764
point-free characterization of operations on finite sets
haftmann
parents:
42871
diff
changeset
|
969 |
from `finite A` show "?fold = ?sup" |
42869
43b0f61f56d0
use point-free characterization for locale fun_left_comm_idem
haftmann
parents:
42809
diff
changeset
|
970 |
by (induct A arbitrary: B) |
44928
7ef6505bde7f
renamed Complete_Lattices lemmas, removed legacy names
hoelzl
parents:
44919
diff
changeset
|
971 |
(simp_all add: SUP_def sup_left_commute) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
972 |
qed |
31992 | 973 |
|
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
974 |
lemma INF_fold_inf: |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
975 |
assumes "finite A" |
42873
da1253ff1764
point-free characterization of operations on finite sets
haftmann
parents:
42871
diff
changeset
|
976 |
shows "INFI A f = fold (inf \<circ> f) top A" |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
977 |
using assms inf_INF_fold_inf [of A top] by simp |
31992 | 978 |
|
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
979 |
lemma SUP_fold_sup: |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
980 |
assumes "finite A" |
42873
da1253ff1764
point-free characterization of operations on finite sets
haftmann
parents:
42871
diff
changeset
|
981 |
shows "SUPR A f = fold (sup \<circ> f) bot A" |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
982 |
using assms sup_SUP_fold_sup [of A bot] by simp |
31992 | 983 |
|
984 |
end |
|
985 |
||
986 |
||
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
987 |
subsection {* The derived combinator @{text fold_image} *} |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
988 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
989 |
definition fold_image :: "('b \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b" |
42875 | 990 |
where "fold_image f g = fold (\<lambda>x y. f (g x) y)" |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
991 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
992 |
lemma fold_image_empty[simp]: "fold_image f g z {} = z" |
42875 | 993 |
by (simp add:fold_image_def) |
15392 | 994 |
|
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
|
995 |
context ab_semigroup_mult |
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
|
996 |
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
|
997 |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
998 |
lemma fold_image_insert[simp]: |
42875 | 999 |
assumes "finite A" and "a \<notin> A" |
1000 |
shows "fold_image times g z (insert a A) = g a * (fold_image times g z A)" |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1001 |
proof - |
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1002 |
interpret comp_fun_commute "%x y. (g x) * y" |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1003 |
by default (simp add: fun_eq_iff mult_ac) |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1004 |
from assms show ?thesis by (simp add: fold_image_def) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1005 |
qed |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1006 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1007 |
lemma fold_image_reindex: |
42875 | 1008 |
assumes "finite A" |
1009 |
shows "inj_on h A \<Longrightarrow> fold_image times g z (h ` A) = fold_image times (g \<circ> h) z A" |
|
1010 |
using assms by induct auto |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1011 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1012 |
lemma fold_image_cong: |
42875 | 1013 |
assumes "finite A" and g_h: "\<And>x. x\<in>A \<Longrightarrow> g x = h x" |
1014 |
shows "fold_image times g z A = fold_image times h z A" |
|
1015 |
proof - |
|
1016 |
from `finite A` |
|
1017 |
have "\<And>C. C <= A --> (ALL x:C. g x = h x) --> fold_image times g z C = fold_image times h z C" |
|
1018 |
proof (induct arbitrary: C) |
|
1019 |
case empty then show ?case by simp |
|
1020 |
next |
|
1021 |
case (insert x F) then show ?case apply - |
|
1022 |
apply (simp add: subset_insert_iff, clarify) |
|
1023 |
apply (subgoal_tac "finite C") |
|
48125
602dc0215954
tuned proofs -- prefer direct "rotated" instead of old-style COMP;
wenzelm
parents:
48124
diff
changeset
|
1024 |
prefer 2 apply (blast dest: finite_subset [rotated]) |
42875 | 1025 |
apply (subgoal_tac "C = insert x (C - {x})") |
1026 |
prefer 2 apply blast |
|
1027 |
apply (erule ssubst) |
|
1028 |
apply (simp add: Ball_def del: insert_Diff_single) |
|
1029 |
done |
|
1030 |
qed |
|
1031 |
with g_h show ?thesis by simp |
|
1032 |
qed |
|
15392 | 1033 |
|
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
|
1034 |
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
|
1035 |
|
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
|
1036 |
context comm_monoid_mult |
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
|
1037 |
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
|
1038 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1039 |
lemma fold_image_1: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1040 |
"finite S \<Longrightarrow> (\<forall>x\<in>S. f x = 1) \<Longrightarrow> fold_image op * f 1 S = 1" |
41656 | 1041 |
apply (induct rule: finite_induct) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1042 |
apply simp by auto |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1043 |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1044 |
lemma fold_image_Un_Int: |
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
|
1045 |
"finite A ==> finite B ==> |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1046 |
fold_image times g 1 A * fold_image times g 1 B = |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1047 |
fold_image times g 1 (A Un B) * fold_image times g 1 (A Int B)" |
41656 | 1048 |
apply (induct rule: finite_induct) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1049 |
by (induct set: finite) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1050 |
(auto simp add: mult_ac insert_absorb Int_insert_left) |
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
|
1051 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1052 |
lemma fold_image_Un_one: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1053 |
assumes fS: "finite S" and fT: "finite T" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1054 |
and I0: "\<forall>x \<in> S\<inter>T. f x = 1" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1055 |
shows "fold_image (op *) f 1 (S \<union> T) = fold_image (op *) f 1 S * fold_image (op *) f 1 T" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1056 |
proof- |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1057 |
have "fold_image op * f 1 (S \<inter> T) = 1" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1058 |
apply (rule fold_image_1) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1059 |
using fS fT I0 by auto |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1060 |
with fold_image_Un_Int[OF fS fT] show ?thesis by simp |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1061 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1062 |
|
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
|
1063 |
corollary fold_Un_disjoint: |
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
|
1064 |
"finite A ==> finite B ==> A Int B = {} ==> |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1065 |
fold_image times g 1 (A Un B) = |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1066 |
fold_image times g 1 A * fold_image times g 1 B" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1067 |
by (simp add: fold_image_Un_Int) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1068 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1069 |
lemma fold_image_UN_disjoint: |
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
|
1070 |
"\<lbrakk> finite I; ALL i:I. finite (A i); |
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
|
1071 |
ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {} \<rbrakk> |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1072 |
\<Longrightarrow> fold_image times g 1 (UNION I A) = |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1073 |
fold_image times (%i. fold_image times g 1 (A i)) 1 I" |
41656 | 1074 |
apply (induct rule: finite_induct) |
1075 |
apply simp |
|
1076 |
apply atomize |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1077 |
apply (subgoal_tac "ALL i:F. x \<noteq> i") |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1078 |
prefer 2 apply blast |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1079 |
apply (subgoal_tac "A x Int UNION F A = {}") |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1080 |
prefer 2 apply blast |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1081 |
apply (simp add: fold_Un_disjoint) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1082 |
done |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1083 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1084 |
lemma fold_image_Sigma: "finite A ==> ALL x:A. finite (B x) ==> |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1085 |
fold_image times (%x. fold_image times (g x) 1 (B x)) 1 A = |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1086 |
fold_image times (split g) 1 (SIGMA x:A. B x)" |
15392 | 1087 |
apply (subst Sigma_def) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1088 |
apply (subst fold_image_UN_disjoint, assumption, simp) |
15392 | 1089 |
apply blast |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1090 |
apply (erule fold_image_cong) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1091 |
apply (subst fold_image_UN_disjoint, simp, simp) |
15392 | 1092 |
apply blast |
15506 | 1093 |
apply simp |
15392 | 1094 |
done |
1095 |
||
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1096 |
lemma fold_image_distrib: "finite A \<Longrightarrow> |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1097 |
fold_image times (%x. g x * h x) 1 A = |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1098 |
fold_image times g 1 A * fold_image times h 1 A" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1099 |
by (erule finite_induct) (simp_all add: mult_ac) |
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
|
1100 |
|
30260
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1101 |
lemma fold_image_related: |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1102 |
assumes Re: "R e e" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1103 |
and Rop: "\<forall>x1 y1 x2 y2. R x1 x2 \<and> R y1 y2 \<longrightarrow> R (x1 * y1) (x2 * y2)" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1104 |
and fS: "finite S" and Rfg: "\<forall>x\<in>S. R (h x) (g x)" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1105 |
shows "R (fold_image (op *) h e S) (fold_image (op *) g e S)" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1106 |
using fS by (rule finite_subset_induct) (insert assms, auto) |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1107 |
|
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1108 |
lemma fold_image_eq_general: |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1109 |
assumes fS: "finite S" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1110 |
and h: "\<forall>y\<in>S'. \<exists>!x. x\<in> S \<and> h(x) = y" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1111 |
and f12: "\<forall>x\<in>S. h x \<in> S' \<and> f2(h x) = f1 x" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1112 |
shows "fold_image (op *) f1 e S = fold_image (op *) f2 e S'" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1113 |
proof- |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1114 |
from h f12 have hS: "h ` S = S'" by auto |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1115 |
{fix x y assume H: "x \<in> S" "y \<in> S" "h x = h y" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1116 |
from f12 h H have "x = y" by auto } |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1117 |
hence hinj: "inj_on h S" unfolding inj_on_def Ex1_def by blast |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1118 |
from f12 have th: "\<And>x. x \<in> S \<Longrightarrow> (f2 \<circ> h) x = f1 x" by auto |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1119 |
from hS have "fold_image (op *) f2 e S' = fold_image (op *) f2 e (h ` S)" by simp |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1120 |
also have "\<dots> = fold_image (op *) (f2 o h) e S" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1121 |
using fold_image_reindex[OF fS hinj, of f2 e] . |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1122 |
also have "\<dots> = fold_image (op *) f1 e S " using th fold_image_cong[OF fS, of "f2 o h" f1 e] |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1123 |
by blast |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1124 |
finally show ?thesis .. |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1125 |
qed |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1126 |
|
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1127 |
lemma fold_image_eq_general_inverses: |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1128 |
assumes fS: "finite S" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1129 |
and kh: "\<And>y. y \<in> T \<Longrightarrow> k y \<in> S \<and> h (k y) = y" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1130 |
and hk: "\<And>x. x \<in> S \<Longrightarrow> h x \<in> T \<and> k (h x) = x \<and> g (h x) = f x" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1131 |
shows "fold_image (op *) f e S = fold_image (op *) g e T" |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1132 |
(* metis solves it, but not yet available here *) |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1133 |
apply (rule fold_image_eq_general[OF fS, of T h g f e]) |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1134 |
apply (rule ballI) |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1135 |
apply (frule kh) |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1136 |
apply (rule ex1I[]) |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1137 |
apply blast |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1138 |
apply clarsimp |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1139 |
apply (drule hk) apply simp |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1140 |
apply (rule sym) |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1141 |
apply (erule conjunct1[OF conjunct2[OF hk]]) |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1142 |
apply (rule ballI) |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1143 |
apply (drule hk) |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1144 |
apply blast |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1145 |
done |
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
chaieb
parents:
29966
diff
changeset
|
1146 |
|
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
|
1147 |
end |
22917 | 1148 |
|
25162 | 1149 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1150 |
subsection {* A fold functional for non-empty sets *} |
15392 | 1151 |
|
1152 |
text{* Does not require start value. *} |
|
12396 | 1153 |
|
23736 | 1154 |
inductive |
22262 | 1155 |
fold1Set :: "('a => 'a => 'a) => 'a set => 'a => bool" |
1156 |
for f :: "'a => 'a => 'a" |
|
1157 |
where |
|
15506 | 1158 |
fold1Set_insertI [intro]: |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1159 |
"\<lbrakk> fold_graph f a A x; a \<notin> A \<rbrakk> \<Longrightarrow> fold1Set f (insert a A) x" |
12396 | 1160 |
|
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
35267
diff
changeset
|
1161 |
definition fold1 :: "('a => 'a => 'a) => 'a set => 'a" where |
22262 | 1162 |
"fold1 f A == THE x. fold1Set f A x" |
15506 | 1163 |
|
1164 |
lemma fold1Set_nonempty: |
|
22917 | 1165 |
"fold1Set f A x \<Longrightarrow> A \<noteq> {}" |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1166 |
by(erule fold1Set.cases, simp_all) |
15392 | 1167 |
|
23736 | 1168 |
inductive_cases empty_fold1SetE [elim!]: "fold1Set f {} x" |
1169 |
||
1170 |
inductive_cases insert_fold1SetE [elim!]: "fold1Set f (insert a X) x" |
|
22262 | 1171 |
|
1172 |
||
1173 |
lemma fold1Set_sing [iff]: "(fold1Set f {a} b) = (a = b)" |
|
35216 | 1174 |
by (blast elim: fold_graph.cases) |
15392 | 1175 |
|
22917 | 1176 |
lemma fold1_singleton [simp]: "fold1 f {a} = a" |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1177 |
by (unfold fold1_def) blast |
12396 | 1178 |
|
15508 | 1179 |
lemma finite_nonempty_imp_fold1Set: |
22262 | 1180 |
"\<lbrakk> finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> EX x. fold1Set f A x" |
15508 | 1181 |
apply (induct A rule: finite_induct) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1182 |
apply (auto dest: finite_imp_fold_graph [of _ f]) |
15508 | 1183 |
done |
15506 | 1184 |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1185 |
text{*First, some lemmas about @{const fold_graph}.*} |
15392 | 1186 |
|
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
|
1187 |
context ab_semigroup_mult |
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
|
1188 |
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
|
1189 |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1190 |
lemma comp_fun_commute: "comp_fun_commute (op *)" |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1191 |
by default (simp add: fun_eq_iff mult_ac) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1192 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1193 |
lemma fold_graph_insert_swap: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1194 |
assumes fold: "fold_graph times (b::'a) A y" and "b \<notin> A" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1195 |
shows "fold_graph times z (insert b A) (z * y)" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1196 |
proof - |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1197 |
interpret comp_fun_commute "op *::'a \<Rightarrow> 'a \<Rightarrow> 'a" by (rule comp_fun_commute) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1198 |
from assms show ?thesis |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1199 |
proof (induct rule: fold_graph.induct) |
36045 | 1200 |
case emptyI show ?case by (subst mult_commute [of z b], fast) |
15508 | 1201 |
next |
22262 | 1202 |
case (insertI x A y) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1203 |
have "fold_graph times z (insert x (insert b A)) (x * (z * y))" |
15521 | 1204 |
using insertI by force --{*how does @{term id} get unfolded?*} |
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
|
1205 |
thus ?case by (simp add: insert_commute mult_ac) |
15508 | 1206 |
qed |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1207 |
qed |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1208 |
|
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1209 |
lemma fold_graph_permute_diff: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1210 |
assumes fold: "fold_graph times b A x" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1211 |
shows "!!a. \<lbrakk>a \<in> A; b \<notin> A\<rbrakk> \<Longrightarrow> fold_graph times a (insert b (A-{a})) x" |
15508 | 1212 |
using fold |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1213 |
proof (induct rule: fold_graph.induct) |
15508 | 1214 |
case emptyI thus ?case by simp |
1215 |
next |
|
22262 | 1216 |
case (insertI x A y) |
15521 | 1217 |
have "a = x \<or> a \<in> A" using insertI by simp |
1218 |
thus ?case |
|
1219 |
proof |
|
1220 |
assume "a = x" |
|
1221 |
with insertI show ?thesis |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1222 |
by (simp add: id_def [symmetric], blast intro: fold_graph_insert_swap) |
15521 | 1223 |
next |
1224 |
assume ainA: "a \<in> A" |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1225 |
hence "fold_graph times a (insert x (insert b (A - {a}))) (x * y)" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1226 |
using insertI by force |
15521 | 1227 |
moreover |
1228 |
have "insert x (insert b (A - {a})) = insert b (insert x A - {a})" |
|
1229 |
using ainA insertI by blast |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1230 |
ultimately show ?thesis by simp |
15508 | 1231 |
qed |
1232 |
qed |
|
1233 |
||
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
|
1234 |
lemma fold1_eq_fold: |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1235 |
assumes "finite A" "a \<notin> A" shows "fold1 times (insert a A) = fold times a A" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1236 |
proof - |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1237 |
interpret comp_fun_commute "op *::'a \<Rightarrow> 'a \<Rightarrow> 'a" by (rule comp_fun_commute) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1238 |
from assms show ?thesis |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1239 |
apply (simp add: fold1_def fold_def) |
15508 | 1240 |
apply (rule the_equality) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1241 |
apply (best intro: fold_graph_determ theI dest: finite_imp_fold_graph [of _ times]) |
15508 | 1242 |
apply (rule sym, clarify) |
1243 |
apply (case_tac "Aa=A") |
|
35216 | 1244 |
apply (best intro: fold_graph_determ) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1245 |
apply (subgoal_tac "fold_graph times a A x") |
35216 | 1246 |
apply (best intro: fold_graph_determ) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1247 |
apply (subgoal_tac "insert aa (Aa - {a}) = A") |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1248 |
prefer 2 apply (blast elim: equalityE) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1249 |
apply (auto dest: fold_graph_permute_diff [where a=a]) |
15508 | 1250 |
done |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1251 |
qed |
15508 | 1252 |
|
15521 | 1253 |
lemma nonempty_iff: "(A \<noteq> {}) = (\<exists>x B. A = insert x B & x \<notin> B)" |
1254 |
apply safe |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1255 |
apply simp |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1256 |
apply (drule_tac x=x in spec) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1257 |
apply (drule_tac x="A-{x}" in spec, auto) |
15508 | 1258 |
done |
1259 |
||
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
|
1260 |
lemma fold1_insert: |
15521 | 1261 |
assumes nonempty: "A \<noteq> {}" and A: "finite A" "x \<notin> A" |
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
|
1262 |
shows "fold1 times (insert x A) = x * fold1 times A" |
15521 | 1263 |
proof - |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1264 |
interpret comp_fun_commute "op *::'a \<Rightarrow> 'a \<Rightarrow> 'a" by (rule comp_fun_commute) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1265 |
from nonempty obtain a A' where "A = insert a A' & a ~: A'" |
15521 | 1266 |
by (auto simp add: nonempty_iff) |
1267 |
with A show ?thesis |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1268 |
by (simp add: insert_commute [of x] fold1_eq_fold eq_commute) |
15521 | 1269 |
qed |
1270 |
||
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
|
1271 |
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
|
1272 |
|
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
|
1273 |
context ab_semigroup_idem_mult |
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
|
1274 |
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
|
1275 |
|
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1276 |
lemma comp_fun_idem: "comp_fun_idem (op *)" |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1277 |
by default (simp_all add: fun_eq_iff mult_left_commute) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1278 |
|
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
|
1279 |
lemma fold1_insert_idem [simp]: |
15521 | 1280 |
assumes nonempty: "A \<noteq> {}" and A: "finite A" |
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
|
1281 |
shows "fold1 times (insert x A) = x * fold1 times A" |
15521 | 1282 |
proof - |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1283 |
interpret comp_fun_idem "op *::'a \<Rightarrow> 'a \<Rightarrow> 'a" |
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1284 |
by (rule comp_fun_idem) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1285 |
from nonempty obtain a A' where A': "A = insert a A' & a ~: A'" |
15521 | 1286 |
by (auto simp add: nonempty_iff) |
1287 |
show ?thesis |
|
1288 |
proof cases |
|
41550 | 1289 |
assume a: "a = x" |
1290 |
show ?thesis |
|
15521 | 1291 |
proof cases |
1292 |
assume "A' = {}" |
|
41550 | 1293 |
with A' a show ?thesis by simp |
15521 | 1294 |
next |
1295 |
assume "A' \<noteq> {}" |
|
41550 | 1296 |
with A A' a show ?thesis |
35216 | 1297 |
by (simp add: fold1_insert mult_assoc [symmetric]) |
15521 | 1298 |
qed |
1299 |
next |
|
1300 |
assume "a \<noteq> x" |
|
41550 | 1301 |
with A A' show ?thesis |
35216 | 1302 |
by (simp add: insert_commute fold1_eq_fold) |
15521 | 1303 |
qed |
1304 |
qed |
|
15506 | 1305 |
|
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
|
1306 |
lemma hom_fold1_commute: |
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
|
1307 |
assumes hom: "!!x y. h (x * y) = h x * h y" |
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
|
1308 |
and N: "finite N" "N \<noteq> {}" shows "h (fold1 times N) = fold1 times (h ` N)" |
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1309 |
using N |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1310 |
proof (induct rule: finite_ne_induct) |
22917 | 1311 |
case singleton thus ?case by simp |
1312 |
next |
|
1313 |
case (insert n N) |
|
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
|
1314 |
then have "h (fold1 times (insert n N)) = h (n * fold1 times N)" by simp |
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
|
1315 |
also have "\<dots> = h n * h (fold1 times N)" by(rule hom) |
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
|
1316 |
also have "h (fold1 times N) = fold1 times (h ` N)" by(rule insert) |
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
|
1317 |
also have "times (h n) \<dots> = fold1 times (insert (h n) (h ` N))" |
22917 | 1318 |
using insert by(simp) |
1319 |
also have "insert (h n) (h ` N) = h ` insert n N" by simp |
|
1320 |
finally show ?case . |
|
1321 |
qed |
|
1322 |
||
32679 | 1323 |
lemma fold1_eq_fold_idem: |
1324 |
assumes "finite A" |
|
1325 |
shows "fold1 times (insert a A) = fold times a A" |
|
1326 |
proof (cases "a \<in> A") |
|
1327 |
case False |
|
1328 |
with assms show ?thesis by (simp add: fold1_eq_fold) |
|
1329 |
next |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1330 |
interpret comp_fun_idem times by (fact comp_fun_idem) |
32679 | 1331 |
case True then obtain b B |
1332 |
where A: "A = insert a B" and "a \<notin> B" by (rule set_insert) |
|
1333 |
with assms have "finite B" by auto |
|
1334 |
then have "fold times a (insert a B) = fold times (a * a) B" |
|
1335 |
using `a \<notin> B` by (rule fold_insert2) |
|
1336 |
then show ?thesis |
|
1337 |
using `a \<notin> B` `finite B` by (simp add: fold1_eq_fold A) |
|
1338 |
qed |
|
1339 |
||
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
|
1340 |
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
|
1341 |
|
15506 | 1342 |
|
15508 | 1343 |
text{* Now the recursion rules for definitions: *} |
1344 |
||
22917 | 1345 |
lemma fold1_singleton_def: "g = fold1 f \<Longrightarrow> g {a} = a" |
35216 | 1346 |
by simp |
15508 | 1347 |
|
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
|
1348 |
lemma (in ab_semigroup_mult) fold1_insert_def: |
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
|
1349 |
"\<lbrakk> g = fold1 times; finite A; x \<notin> A; A \<noteq> {} \<rbrakk> \<Longrightarrow> g (insert x A) = x * g A" |
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
|
1350 |
by (simp add:fold1_insert) |
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
|
1351 |
|
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
|
1352 |
lemma (in ab_semigroup_idem_mult) fold1_insert_idem_def: |
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
|
1353 |
"\<lbrakk> g = fold1 times; finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> g (insert x A) = x * g A" |
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
|
1354 |
by simp |
15508 | 1355 |
|
1356 |
subsubsection{* Determinacy for @{term fold1Set} *} |
|
1357 |
||
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1358 |
(*Not actually used!!*) |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1359 |
(* |
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
|
1360 |
context ab_semigroup_mult |
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
|
1361 |
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
|
1362 |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1363 |
lemma fold_graph_permute: |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1364 |
"[|fold_graph times id b (insert a A) x; a \<notin> A; b \<notin> A|] |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1365 |
==> fold_graph times id a (insert b A) 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
|
1366 |
apply (cases "a=b") |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1367 |
apply (auto dest: fold_graph_permute_diff) |
15506 | 1368 |
done |
15376 | 1369 |
|
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
|
1370 |
lemma fold1Set_determ: |
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
|
1371 |
"fold1Set times A x ==> fold1Set times A y ==> y = x" |
15506 | 1372 |
proof (clarify elim!: fold1Set.cases) |
1373 |
fix A x B y a b |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1374 |
assume Ax: "fold_graph times id a A x" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1375 |
assume By: "fold_graph times id b B y" |
15506 | 1376 |
assume anotA: "a \<notin> A" |
1377 |
assume bnotB: "b \<notin> B" |
|
1378 |
assume eq: "insert a A = insert b B" |
|
1379 |
show "y=x" |
|
1380 |
proof cases |
|
1381 |
assume same: "a=b" |
|
1382 |
hence "A=B" using anotA bnotB eq by (blast elim!: equalityE) |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1383 |
thus ?thesis using Ax By same by (blast intro: fold_graph_determ) |
15392 | 1384 |
next |
15506 | 1385 |
assume diff: "a\<noteq>b" |
1386 |
let ?D = "B - {a}" |
|
1387 |
have B: "B = insert a ?D" and A: "A = insert b ?D" |
|
1388 |
and aB: "a \<in> B" and bA: "b \<in> A" |
|
1389 |
using eq anotA bnotB diff by (blast elim!:equalityE)+ |
|
1390 |
with aB bnotB By |
|
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1391 |
have "fold_graph times id a (insert b ?D) y" |
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1392 |
by (auto intro: fold_graph_permute simp add: insert_absorb) |
15506 | 1393 |
moreover |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1394 |
have "fold_graph times id a (insert b ?D) x" |
15506 | 1395 |
by (simp add: A [symmetric] Ax) |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1396 |
ultimately show ?thesis by (blast intro: fold_graph_determ) |
15392 | 1397 |
qed |
12396 | 1398 |
qed |
1399 |
||
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
|
1400 |
lemma fold1Set_equality: "fold1Set times A y ==> fold1 times A = y" |
15506 | 1401 |
by (unfold fold1_def) (blast intro: fold1Set_determ) |
1402 |
||
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
|
1403 |
end |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1404 |
*) |
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
|
1405 |
|
15506 | 1406 |
declare |
28853
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
nipkow
parents:
28823
diff
changeset
|
1407 |
empty_fold_graphE [rule del] fold_graph.intros [rule del] |
15506 | 1408 |
empty_fold1SetE [rule del] insert_fold1SetE [rule del] |
19931
fb32b43e7f80
Restructured locales with predicates: import is now an interpretation.
ballarin
parents:
19870
diff
changeset
|
1409 |
-- {* No more proofs involve these relations. *} |
15376 | 1410 |
|
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
|
1411 |
subsubsection {* Lemmas about @{text fold1} *} |
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
|
1412 |
|
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
|
1413 |
context ab_semigroup_mult |
22917 | 1414 |
begin |
1415 |
||
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
|
1416 |
lemma fold1_Un: |
15484 | 1417 |
assumes A: "finite A" "A \<noteq> {}" |
1418 |
shows "finite B \<Longrightarrow> B \<noteq> {} \<Longrightarrow> A Int B = {} \<Longrightarrow> |
|
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
|
1419 |
fold1 times (A Un B) = fold1 times A * fold1 times B" |
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
|
1420 |
using A by (induct rule: finite_ne_induct) |
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
|
1421 |
(simp_all add: fold1_insert mult_assoc) |
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
|
1422 |
|
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
|
1423 |
lemma fold1_in: |
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
|
1424 |
assumes A: "finite (A)" "A \<noteq> {}" and elem: "\<And>x y. x * y \<in> {x,y}" |
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
|
1425 |
shows "fold1 times A \<in> A" |
15484 | 1426 |
using A |
1427 |
proof (induct rule:finite_ne_induct) |
|
15506 | 1428 |
case singleton thus ?case by simp |
15484 | 1429 |
next |
1430 |
case insert thus ?case using elem by (force simp add:fold1_insert) |
|
1431 |
qed |
|
1432 |
||
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
|
1433 |
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
|
1434 |
|
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
|
1435 |
lemma (in ab_semigroup_idem_mult) fold1_Un2: |
15497
53bca254719a
Added semi-lattice locales and reorganized fold1 lemmas
nipkow
parents:
15487
diff
changeset
|
1436 |
assumes A: "finite A" "A \<noteq> {}" |
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
|
1437 |
shows "finite B \<Longrightarrow> B \<noteq> {} \<Longrightarrow> |
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
|
1438 |
fold1 times (A Un B) = fold1 times A * fold1 times B" |
15497
53bca254719a
Added semi-lattice locales and reorganized fold1 lemmas
nipkow
parents:
15487
diff
changeset
|
1439 |
using A |
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
|
1440 |
proof(induct rule:finite_ne_induct) |
15497
53bca254719a
Added semi-lattice locales and reorganized fold1 lemmas
nipkow
parents:
15487
diff
changeset
|
1441 |
case singleton thus ?case by simp |
15484 | 1442 |
next |
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
|
1443 |
case insert thus ?case by (simp add: mult_assoc) |
18423 | 1444 |
qed |
1445 |
||
1446 |
||
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1447 |
subsection {* Locales as mini-packages for fold operations *} |
34007
aea892559fc5
tuned lattices theory fragements; generlized some lemmas from sets to lattices
haftmann
parents:
33960
diff
changeset
|
1448 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1449 |
subsubsection {* The natural case *} |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1450 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1451 |
locale folding = |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1452 |
fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1453 |
fixes F :: "'a set \<Rightarrow> 'b \<Rightarrow> 'b" |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1454 |
assumes comp_fun_commute: "f y \<circ> f x = f x \<circ> f y" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1455 |
assumes eq_fold: "finite A \<Longrightarrow> F A s = fold f s A" |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1456 |
begin |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1457 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1458 |
lemma empty [simp]: |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1459 |
"F {} = id" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
1460 |
by (simp add: eq_fold fun_eq_iff) |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1461 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1462 |
lemma insert [simp]: |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1463 |
assumes "finite A" and "x \<notin> A" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1464 |
shows "F (insert x A) = F A \<circ> f x" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1465 |
proof - |
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1466 |
interpret comp_fun_commute f |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1467 |
by default (insert comp_fun_commute, simp add: fun_eq_iff) |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1468 |
from fold_insert2 assms |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1469 |
have "\<And>s. fold f s (insert x A) = fold f (f x s) A" . |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
1470 |
with `finite A` show ?thesis by (simp add: eq_fold fun_eq_iff) |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1471 |
qed |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1472 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1473 |
lemma remove: |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1474 |
assumes "finite A" and "x \<in> A" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1475 |
shows "F A = F (A - {x}) \<circ> f x" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1476 |
proof - |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1477 |
from `x \<in> A` obtain B where A: "A = insert x B" and "x \<notin> B" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1478 |
by (auto dest: mk_disjoint_insert) |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1479 |
moreover from `finite A` this have "finite B" by simp |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1480 |
ultimately show ?thesis by simp |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1481 |
qed |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1482 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1483 |
lemma insert_remove: |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1484 |
assumes "finite A" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1485 |
shows "F (insert x A) = F (A - {x}) \<circ> f x" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1486 |
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
|
1487 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1488 |
lemma commute_left_comp: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1489 |
"f y \<circ> (f x \<circ> g) = f x \<circ> (f y \<circ> g)" |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1490 |
by (simp add: o_assoc comp_fun_commute) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1491 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1492 |
lemma comp_fun_commute': |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1493 |
assumes "finite A" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1494 |
shows "f x \<circ> F A = F A \<circ> f x" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1495 |
using assms by (induct A) |
49739 | 1496 |
(simp, simp del: o_apply add: o_assoc, simp del: o_apply add: comp_assoc comp_fun_commute) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1497 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1498 |
lemma commute_left_comp': |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1499 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1500 |
shows "f x \<circ> (F A \<circ> g) = F A \<circ> (f x \<circ> g)" |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1501 |
using assms by (simp add: o_assoc comp_fun_commute') |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1502 |
|
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1503 |
lemma comp_fun_commute'': |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1504 |
assumes "finite A" and "finite B" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1505 |
shows "F B \<circ> F A = F A \<circ> F B" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1506 |
using assms by (induct A) |
49739 | 1507 |
(simp_all add: o_assoc, simp add: comp_assoc comp_fun_commute') |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1508 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1509 |
lemma commute_left_comp'': |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1510 |
assumes "finite A" and "finite B" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1511 |
shows "F B \<circ> (F A \<circ> g) = F A \<circ> (F B \<circ> g)" |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1512 |
using assms by (simp add: o_assoc comp_fun_commute'') |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1513 |
|
49739 | 1514 |
lemmas comp_fun_commutes = comp_assoc comp_fun_commute commute_left_comp |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1515 |
comp_fun_commute' commute_left_comp' comp_fun_commute'' commute_left_comp'' |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1516 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1517 |
lemma union_inter: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1518 |
assumes "finite A" and "finite B" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1519 |
shows "F (A \<union> B) \<circ> F (A \<inter> B) = F A \<circ> F B" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1520 |
using assms by (induct A) |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1521 |
(simp_all del: o_apply add: insert_absorb Int_insert_left comp_fun_commutes, |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1522 |
simp add: o_assoc) |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1523 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1524 |
lemma union: |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1525 |
assumes "finite A" and "finite B" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1526 |
and "A \<inter> B = {}" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1527 |
shows "F (A \<union> B) = F A \<circ> F B" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1528 |
proof - |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1529 |
from union_inter `finite A` `finite B` have "F (A \<union> B) \<circ> F (A \<inter> B) = F A \<circ> F B" . |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1530 |
with `A \<inter> B = {}` show ?thesis by simp |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1531 |
qed |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1532 |
|
34007
aea892559fc5
tuned lattices theory fragements; generlized some lemmas from sets to lattices
haftmann
parents:
33960
diff
changeset
|
1533 |
end |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1534 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1535 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1536 |
subsubsection {* The natural case with idempotency *} |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1537 |
|
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1538 |
locale folding_idem = folding + |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1539 |
assumes idem_comp: "f x \<circ> f x = f x" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1540 |
begin |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1541 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1542 |
lemma idem_left_comp: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1543 |
"f x \<circ> (f x \<circ> g) = f x \<circ> g" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1544 |
by (simp add: o_assoc idem_comp) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1545 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1546 |
lemma in_comp_idem: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1547 |
assumes "finite A" and "x \<in> A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1548 |
shows "F A \<circ> f x = F A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1549 |
using assms by (induct A) |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1550 |
(auto simp add: comp_fun_commutes idem_comp, simp add: commute_left_comp' [symmetric] comp_fun_commute') |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1551 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1552 |
lemma subset_comp_idem: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1553 |
assumes "finite A" and "B \<subseteq> A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1554 |
shows "F A \<circ> F B = F A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1555 |
proof - |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1556 |
from assms have "finite B" by (blast dest: finite_subset) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1557 |
then show ?thesis using `B \<subseteq> A` by (induct B) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1558 |
(simp_all add: o_assoc in_comp_idem `finite A`) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1559 |
qed |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1560 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1561 |
declare insert [simp del] |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1562 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1563 |
lemma insert_idem [simp]: |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1564 |
assumes "finite A" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1565 |
shows "F (insert x A) = F A \<circ> f x" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1566 |
using assms by (cases "x \<in> A") (simp_all add: insert in_comp_idem insert_absorb) |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1567 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1568 |
lemma union_idem: |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1569 |
assumes "finite A" and "finite B" |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1570 |
shows "F (A \<union> B) = F A \<circ> F B" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1571 |
proof - |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1572 |
from assms have "finite (A \<union> B)" and "A \<inter> B \<subseteq> A \<union> B" by auto |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1573 |
then have "F (A \<union> B) \<circ> F (A \<inter> B) = F (A \<union> B)" by (rule subset_comp_idem) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1574 |
with assms show ?thesis by (simp add: union_inter) |
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1575 |
qed |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1576 |
|
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1577 |
end |
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1578 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1579 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1580 |
subsubsection {* The image case with fixed function *} |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1581 |
|
35796 | 1582 |
no_notation times (infixl "*" 70) |
1583 |
no_notation Groups.one ("1") |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1584 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1585 |
locale folding_image_simple = comm_monoid + |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1586 |
fixes g :: "('b \<Rightarrow> 'a)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1587 |
fixes F :: "'b set \<Rightarrow> 'a" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1588 |
assumes eq_fold_g: "finite A \<Longrightarrow> F A = fold_image f g 1 A" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1589 |
begin |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1590 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1591 |
lemma empty [simp]: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1592 |
"F {} = 1" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1593 |
by (simp add: eq_fold_g) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1594 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1595 |
lemma insert [simp]: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1596 |
assumes "finite A" and "x \<notin> A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1597 |
shows "F (insert x A) = g x * F A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1598 |
proof - |
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1599 |
interpret comp_fun_commute "%x y. (g x) * y" |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1600 |
by default (simp add: ac_simps fun_eq_iff) |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1601 |
from assms have "fold_image (op *) g 1 (insert x A) = g x * fold_image (op *) g 1 A" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1602 |
by (simp add: fold_image_def) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1603 |
with `finite A` show ?thesis by (simp add: eq_fold_g) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1604 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1605 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1606 |
lemma remove: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1607 |
assumes "finite A" and "x \<in> A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1608 |
shows "F A = g x * F (A - {x})" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1609 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1610 |
from `x \<in> A` obtain B where A: "A = insert x B" and "x \<notin> B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1611 |
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
|
1612 |
moreover from `finite A` this have "finite B" by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1613 |
ultimately show ?thesis by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1614 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1615 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1616 |
lemma insert_remove: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1617 |
assumes "finite A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1618 |
shows "F (insert x A) = g x * F (A - {x})" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1619 |
using assms by (cases "x \<in> A") (simp_all add: remove insert_absorb) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1620 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1621 |
lemma neutral: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1622 |
assumes "finite A" and "\<forall>x\<in>A. g x = 1" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1623 |
shows "F A = 1" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1624 |
using assms by (induct A) simp_all |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1625 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1626 |
lemma union_inter: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1627 |
assumes "finite A" and "finite B" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1628 |
shows "F (A \<union> B) * F (A \<inter> B) = F A * F B" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1629 |
using assms proof (induct A) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1630 |
case empty then show ?case by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1631 |
next |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1632 |
case (insert x A) then show ?case |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1633 |
by (auto simp add: insert_absorb Int_insert_left commute [of _ "g x"] assoc left_commute) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1634 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1635 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1636 |
corollary union_inter_neutral: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1637 |
assumes "finite A" and "finite B" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1638 |
and I0: "\<forall>x \<in> A\<inter>B. g x = 1" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1639 |
shows "F (A \<union> B) = F A * F B" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1640 |
using assms by (simp add: union_inter [symmetric] neutral) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1641 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1642 |
corollary union_disjoint: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1643 |
assumes "finite A" and "finite B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1644 |
assumes "A \<inter> B = {}" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1645 |
shows "F (A \<union> B) = F A * F B" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1646 |
using assms by (simp add: union_inter_neutral) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1647 |
|
35719
99b6152aedf5
split off theory Big_Operators from theory Finite_Set
haftmann
parents:
35577
diff
changeset
|
1648 |
end |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1649 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1650 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1651 |
subsubsection {* The image case with flexible function *} |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1652 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1653 |
locale folding_image = comm_monoid + |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1654 |
fixes F :: "('b \<Rightarrow> 'a) \<Rightarrow> 'b set \<Rightarrow> 'a" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1655 |
assumes eq_fold: "\<And>g. finite A \<Longrightarrow> F g A = fold_image f g 1 A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1656 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1657 |
sublocale folding_image < folding_image_simple "op *" 1 g "F g" proof |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1658 |
qed (fact eq_fold) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1659 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1660 |
context folding_image |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1661 |
begin |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1662 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1663 |
lemma reindex: (* FIXME polymorhism *) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1664 |
assumes "finite A" and "inj_on h A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1665 |
shows "F g (h ` A) = F (g \<circ> h) A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1666 |
using assms by (induct A) auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1667 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1668 |
lemma cong: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1669 |
assumes "finite A" and "\<And>x. x \<in> A \<Longrightarrow> g x = h x" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1670 |
shows "F g A = F h A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1671 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1672 |
from assms have "ALL C. C <= A --> (ALL x:C. g x = h x) --> F g C = F h C" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1673 |
apply - apply (erule finite_induct) apply simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1674 |
apply (simp add: subset_insert_iff, clarify) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1675 |
apply (subgoal_tac "finite C") |
48125
602dc0215954
tuned proofs -- prefer direct "rotated" instead of old-style COMP;
wenzelm
parents:
48124
diff
changeset
|
1676 |
prefer 2 apply (blast dest: finite_subset [rotated]) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1677 |
apply (subgoal_tac "C = insert x (C - {x})") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1678 |
prefer 2 apply blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1679 |
apply (erule ssubst) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1680 |
apply (drule spec) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1681 |
apply (erule (1) notE impE) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1682 |
apply (simp add: Ball_def del: insert_Diff_single) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1683 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1684 |
with assms show ?thesis by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1685 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1686 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1687 |
lemma UNION_disjoint: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1688 |
assumes "finite I" and "\<forall>i\<in>I. finite (A i)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1689 |
and "\<forall>i\<in>I. \<forall>j\<in>I. i \<noteq> j \<longrightarrow> A i \<inter> A j = {}" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1690 |
shows "F g (UNION I A) = F (F g \<circ> A) I" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1691 |
apply (insert assms) |
41656 | 1692 |
apply (induct rule: finite_induct) |
1693 |
apply simp |
|
1694 |
apply atomize |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1695 |
apply (subgoal_tac "\<forall>i\<in>Fa. x \<noteq> i") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1696 |
prefer 2 apply blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1697 |
apply (subgoal_tac "A x Int UNION Fa A = {}") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1698 |
prefer 2 apply blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1699 |
apply (simp add: union_disjoint) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1700 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1701 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1702 |
lemma distrib: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1703 |
assumes "finite A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1704 |
shows "F (\<lambda>x. g x * h x) A = F g A * F h A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1705 |
using assms by (rule finite_induct) (simp_all add: assoc commute left_commute) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1706 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1707 |
lemma related: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1708 |
assumes Re: "R 1 1" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1709 |
and Rop: "\<forall>x1 y1 x2 y2. R x1 x2 \<and> R y1 y2 \<longrightarrow> R (x1 * y1) (x2 * y2)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1710 |
and fS: "finite S" and Rfg: "\<forall>x\<in>S. R (h x) (g x)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1711 |
shows "R (F h S) (F g S)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1712 |
using fS by (rule finite_subset_induct) (insert assms, auto) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1713 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1714 |
lemma eq_general: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1715 |
assumes fS: "finite S" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1716 |
and h: "\<forall>y\<in>S'. \<exists>!x. x \<in> S \<and> h x = y" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1717 |
and f12: "\<forall>x\<in>S. h x \<in> S' \<and> f2 (h x) = f1 x" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1718 |
shows "F f1 S = F f2 S'" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1719 |
proof- |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1720 |
from h f12 have hS: "h ` S = S'" by blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1721 |
{fix x y assume H: "x \<in> S" "y \<in> S" "h x = h y" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1722 |
from f12 h H have "x = y" by auto } |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1723 |
hence hinj: "inj_on h S" unfolding inj_on_def Ex1_def by blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1724 |
from f12 have th: "\<And>x. x \<in> S \<Longrightarrow> (f2 \<circ> h) x = f1 x" by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1725 |
from hS have "F f2 S' = F f2 (h ` S)" by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1726 |
also have "\<dots> = F (f2 o h) S" using reindex [OF fS hinj, of f2] . |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1727 |
also have "\<dots> = F f1 S " using th cong [OF fS, of "f2 o h" f1] |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1728 |
by blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1729 |
finally show ?thesis .. |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1730 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1731 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1732 |
lemma eq_general_inverses: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1733 |
assumes fS: "finite S" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1734 |
and kh: "\<And>y. y \<in> T \<Longrightarrow> k y \<in> S \<and> h (k y) = y" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1735 |
and hk: "\<And>x. x \<in> S \<Longrightarrow> h x \<in> T \<and> k (h x) = x \<and> g (h x) = j x" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1736 |
shows "F j S = F g T" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1737 |
(* metis solves it, but not yet available here *) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1738 |
apply (rule eq_general [OF fS, of T h g j]) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1739 |
apply (rule ballI) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1740 |
apply (frule kh) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1741 |
apply (rule ex1I[]) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1742 |
apply blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1743 |
apply clarsimp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1744 |
apply (drule hk) apply simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1745 |
apply (rule sym) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1746 |
apply (erule conjunct1[OF conjunct2[OF hk]]) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1747 |
apply (rule ballI) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1748 |
apply (drule hk) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1749 |
apply blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1750 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1751 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1752 |
end |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1753 |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1754 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1755 |
subsubsection {* The image case with fixed function and idempotency *} |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1756 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1757 |
locale folding_image_simple_idem = folding_image_simple + |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1758 |
assumes idem: "x * x = x" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1759 |
|
49756
28e37eab4e6f
added some ad-hoc namespace prefixes to avoid duplicate facts;
wenzelm
parents:
49739
diff
changeset
|
1760 |
sublocale folding_image_simple_idem < semilattice: semilattice proof |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1761 |
qed (fact idem) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1762 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1763 |
context folding_image_simple_idem |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1764 |
begin |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1765 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1766 |
lemma in_idem: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1767 |
assumes "finite A" and "x \<in> A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1768 |
shows "g x * F A = F A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1769 |
using assms by (induct A) (auto simp add: left_commute) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1770 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1771 |
lemma subset_idem: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1772 |
assumes "finite A" and "B \<subseteq> A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1773 |
shows "F B * F A = F A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1774 |
proof - |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1775 |
from assms have "finite B" by (blast dest: finite_subset) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1776 |
then show ?thesis using `B \<subseteq> A` by (induct B) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1777 |
(auto simp add: assoc in_idem `finite A`) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1778 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1779 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1780 |
declare insert [simp del] |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1781 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1782 |
lemma insert_idem [simp]: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1783 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1784 |
shows "F (insert x A) = g x * F A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1785 |
using assms by (cases "x \<in> A") (simp_all add: insert in_idem insert_absorb) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1786 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1787 |
lemma union_idem: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1788 |
assumes "finite A" and "finite B" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1789 |
shows "F (A \<union> B) = F A * F B" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1790 |
proof - |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1791 |
from assms have "finite (A \<union> B)" and "A \<inter> B \<subseteq> A \<union> B" by auto |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1792 |
then have "F (A \<inter> B) * F (A \<union> B) = F (A \<union> B)" by (rule subset_idem) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1793 |
with assms show ?thesis by (simp add: union_inter [of A B, symmetric] commute) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1794 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1795 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1796 |
end |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1797 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1798 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1799 |
subsubsection {* The image case with flexible function and idempotency *} |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1800 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1801 |
locale folding_image_idem = folding_image + |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1802 |
assumes idem: "x * x = x" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1803 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1804 |
sublocale folding_image_idem < folding_image_simple_idem "op *" 1 g "F g" proof |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1805 |
qed (fact idem) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1806 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1807 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1808 |
subsubsection {* The neutral-less case *} |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1809 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1810 |
locale folding_one = abel_semigroup + |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1811 |
fixes F :: "'a set \<Rightarrow> 'a" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1812 |
assumes eq_fold: "finite A \<Longrightarrow> F A = fold1 f A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1813 |
begin |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1814 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1815 |
lemma singleton [simp]: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1816 |
"F {x} = x" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1817 |
by (simp add: eq_fold) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1818 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1819 |
lemma eq_fold': |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1820 |
assumes "finite A" and "x \<notin> A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1821 |
shows "F (insert x A) = fold (op *) x A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1822 |
proof - |
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1823 |
interpret ab_semigroup_mult "op *" by default (simp_all add: ac_simps) |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1824 |
from assms show ?thesis by (simp add: eq_fold fold1_eq_fold) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1825 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1826 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1827 |
lemma insert [simp]: |
36637 | 1828 |
assumes "finite A" and "x \<notin> A" and "A \<noteq> {}" |
1829 |
shows "F (insert x A) = x * F A" |
|
1830 |
proof - |
|
1831 |
from `A \<noteq> {}` obtain b where "b \<in> A" by blast |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1832 |
then obtain B where *: "A = insert b B" "b \<notin> B" by (blast dest: mk_disjoint_insert) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1833 |
with `finite A` have "finite B" by simp |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1834 |
interpret fold: folding "op *" "\<lambda>a b. fold (op *) b a" proof |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
1835 |
qed (simp_all add: fun_eq_iff ac_simps) |
42871
1c0b99f950d9
names of fold_set locales resemble name of characteristic property more closely
haftmann
parents:
42869
diff
changeset
|
1836 |
from `finite B` fold.comp_fun_commute' [of B x] |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1837 |
have "op * x \<circ> (\<lambda>b. fold op * b B) = (\<lambda>b. fold op * b B) \<circ> op * x" by simp |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
1838 |
then have A: "x * fold op * b B = fold op * (b * x) B" by (simp add: fun_eq_iff commute) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1839 |
from `finite B` * fold.insert [of B b] |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1840 |
have "(\<lambda>x. fold op * x (insert b B)) = (\<lambda>x. fold op * x B) \<circ> op * b" by simp |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
1841 |
then have B: "fold op * x (insert b B) = fold op * (b * x) B" by (simp add: fun_eq_iff) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1842 |
from A B assms * show ?thesis by (simp add: eq_fold' del: fold.insert) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1843 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1844 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1845 |
lemma remove: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1846 |
assumes "finite A" and "x \<in> A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1847 |
shows "F A = (if A - {x} = {} then x else x * F (A - {x}))" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1848 |
proof - |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1849 |
from assms obtain B where "A = insert x B" and "x \<notin> B" by (blast dest: mk_disjoint_insert) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1850 |
with assms show ?thesis by simp |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1851 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1852 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1853 |
lemma insert_remove: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1854 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1855 |
shows "F (insert x A) = (if A - {x} = {} then x else x * F (A - {x}))" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1856 |
using assms by (cases "x \<in> A") (simp_all add: insert_absorb remove) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1857 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1858 |
lemma union_disjoint: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1859 |
assumes "finite A" "A \<noteq> {}" and "finite B" "B \<noteq> {}" and "A \<inter> B = {}" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1860 |
shows "F (A \<union> B) = F A * F B" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1861 |
using assms by (induct A rule: finite_ne_induct) (simp_all add: ac_simps) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1862 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1863 |
lemma union_inter: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1864 |
assumes "finite A" and "finite B" and "A \<inter> B \<noteq> {}" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1865 |
shows "F (A \<union> B) * F (A \<inter> B) = F A * F B" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1866 |
proof - |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1867 |
from assms have "A \<noteq> {}" and "B \<noteq> {}" by auto |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1868 |
from `finite A` `A \<noteq> {}` `A \<inter> B \<noteq> {}` show ?thesis proof (induct A rule: finite_ne_induct) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1869 |
case (singleton x) then show ?case by (simp add: insert_absorb ac_simps) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1870 |
next |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1871 |
case (insert x A) show ?case proof (cases "x \<in> B") |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1872 |
case True then have "B \<noteq> {}" by auto |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1873 |
with insert True `finite B` show ?thesis by (cases "A \<inter> B = {}") |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1874 |
(simp_all add: insert_absorb ac_simps union_disjoint) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1875 |
next |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1876 |
case False with insert have "F (A \<union> B) * F (A \<inter> B) = F A * F B" by simp |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1877 |
moreover from False `finite B` insert have "finite (A \<union> B)" "x \<notin> A \<union> B" "A \<union> B \<noteq> {}" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1878 |
by auto |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1879 |
ultimately show ?thesis using False `finite A` `x \<notin> A` `A \<noteq> {}` by (simp add: assoc) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1880 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1881 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1882 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1883 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1884 |
lemma closed: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1885 |
assumes "finite A" "A \<noteq> {}" and elem: "\<And>x y. x * y \<in> {x, y}" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1886 |
shows "F A \<in> A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1887 |
using `finite A` `A \<noteq> {}` proof (induct rule: finite_ne_induct) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1888 |
case singleton then show ?case by simp |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1889 |
next |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1890 |
case insert with elem show ?case by force |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1891 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1892 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1893 |
end |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1894 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1895 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1896 |
subsubsection {* The neutral-less case with idempotency *} |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1897 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1898 |
locale folding_one_idem = folding_one + |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1899 |
assumes idem: "x * x = x" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1900 |
|
49756
28e37eab4e6f
added some ad-hoc namespace prefixes to avoid duplicate facts;
wenzelm
parents:
49739
diff
changeset
|
1901 |
sublocale folding_one_idem < semilattice: semilattice proof |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1902 |
qed (fact idem) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1903 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1904 |
context folding_one_idem |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1905 |
begin |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1906 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1907 |
lemma in_idem: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1908 |
assumes "finite A" and "x \<in> A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1909 |
shows "x * F A = F A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1910 |
proof - |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1911 |
from assms have "A \<noteq> {}" by auto |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1912 |
with `finite A` show ?thesis using `x \<in> A` by (induct A rule: finite_ne_induct) (auto simp add: ac_simps) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1913 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1914 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1915 |
lemma subset_idem: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1916 |
assumes "finite A" "B \<noteq> {}" and "B \<subseteq> A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1917 |
shows "F B * F A = F A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1918 |
proof - |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1919 |
from assms have "finite B" by (blast dest: finite_subset) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1920 |
then show ?thesis using `B \<noteq> {}` `B \<subseteq> A` by (induct B rule: finite_ne_induct) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1921 |
(simp_all add: assoc in_idem `finite A`) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1922 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1923 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1924 |
lemma eq_fold_idem': |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1925 |
assumes "finite A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1926 |
shows "F (insert a A) = fold (op *) a A" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1927 |
proof - |
46898
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1928 |
interpret ab_semigroup_idem_mult "op *" by default (simp_all add: ac_simps) |
1570b30ee040
tuned proofs -- eliminated pointless chaining of facts after 'interpret';
wenzelm
parents:
46146
diff
changeset
|
1929 |
from assms show ?thesis by (simp add: eq_fold fold1_eq_fold_idem) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1930 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1931 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1932 |
lemma insert_idem [simp]: |
36637 | 1933 |
assumes "finite A" and "A \<noteq> {}" |
1934 |
shows "F (insert x A) = x * F A" |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1935 |
proof (cases "x \<in> A") |
36637 | 1936 |
case False from `finite A` `x \<notin> A` `A \<noteq> {}` show ?thesis by (rule insert) |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1937 |
next |
36637 | 1938 |
case True |
1939 |
from `finite A` `A \<noteq> {}` show ?thesis by (simp add: in_idem insert_absorb True) |
|
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1940 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1941 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1942 |
lemma union_idem: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1943 |
assumes "finite A" "A \<noteq> {}" and "finite B" "B \<noteq> {}" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1944 |
shows "F (A \<union> B) = F A * F B" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1945 |
proof (cases "A \<inter> B = {}") |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1946 |
case True with assms show ?thesis by (simp add: union_disjoint) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1947 |
next |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1948 |
case False |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1949 |
from assms have "finite (A \<union> B)" and "A \<inter> B \<subseteq> A \<union> B" by auto |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1950 |
with False have "F (A \<inter> B) * F (A \<union> B) = F (A \<union> B)" by (auto intro: subset_idem) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1951 |
with assms False show ?thesis by (simp add: union_inter [of A B, symmetric] commute) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1952 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1953 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1954 |
lemma hom_commute: |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1955 |
assumes hom: "\<And>x y. h (x * y) = h x * h y" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1956 |
and N: "finite N" "N \<noteq> {}" shows "h (F N) = F (h ` N)" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1957 |
using N proof (induct rule: finite_ne_induct) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1958 |
case singleton thus ?case by simp |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1959 |
next |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1960 |
case (insert n N) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1961 |
then have "h (F (insert n N)) = h (n * F N)" by simp |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1962 |
also have "\<dots> = h n * h (F N)" by (rule hom) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1963 |
also have "h (F N) = F (h ` N)" by(rule insert) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1964 |
also have "h n * \<dots> = F (insert (h n) (h ` N))" |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1965 |
using insert by(simp) |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1966 |
also have "insert (h n) (h ` N) = h ` insert n N" by simp |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1967 |
finally show ?case . |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1968 |
qed |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1969 |
|
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1970 |
end |
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
1971 |
|
35796 | 1972 |
notation times (infixl "*" 70) |
1973 |
notation Groups.one ("1") |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1974 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1975 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1976 |
subsection {* Finite cardinality *} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1977 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1978 |
text {* This definition, although traditional, is ugly to work with: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1979 |
@{text "card A == LEAST n. EX f. A = {f i | i. i < n}"}. |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1980 |
But now that we have @{text fold_image} things are easy: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1981 |
*} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1982 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1983 |
definition card :: "'a set \<Rightarrow> nat" where |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1984 |
"card A = (if finite A then fold_image (op +) (\<lambda>x. 1) 0 A else 0)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1985 |
|
37770
cddb3106adb8
avoid explicit mandatory prefix markers when prefixes are mandatory implicitly
haftmann
parents:
37767
diff
changeset
|
1986 |
interpretation card: folding_image_simple "op +" 0 "\<lambda>x. 1" card proof |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1987 |
qed (simp add: card_def) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1988 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1989 |
lemma card_infinite [simp]: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1990 |
"\<not> finite A \<Longrightarrow> card A = 0" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1991 |
by (simp add: card_def) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1992 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1993 |
lemma card_empty: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1994 |
"card {} = 0" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1995 |
by (fact card.empty) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1996 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1997 |
lemma card_insert_disjoint: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1998 |
"finite A ==> x \<notin> A ==> card (insert x A) = Suc (card A)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
1999 |
by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2000 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2001 |
lemma card_insert_if: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2002 |
"finite A ==> card (insert x A) = (if x \<in> A then card A else Suc (card A))" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2003 |
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
|
2004 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2005 |
lemma card_ge_0_finite: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2006 |
"card A > 0 \<Longrightarrow> finite A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2007 |
by (rule ccontr) simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2008 |
|
35828
46cfc4b8112e
now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents:
35796
diff
changeset
|
2009 |
lemma card_0_eq [simp, no_atp]: |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2010 |
"finite A \<Longrightarrow> card A = 0 \<longleftrightarrow> A = {}" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2011 |
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
|
2012 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2013 |
lemma finite_UNIV_card_ge_0: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2014 |
"finite (UNIV :: 'a set) \<Longrightarrow> card (UNIV :: 'a set) > 0" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2015 |
by (rule ccontr) simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2016 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2017 |
lemma card_eq_0_iff: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2018 |
"card A = 0 \<longleftrightarrow> A = {} \<or> \<not> finite A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2019 |
by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2020 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2021 |
lemma card_gt_0_iff: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2022 |
"0 < card A \<longleftrightarrow> A \<noteq> {} \<and> finite A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2023 |
by (simp add: neq0_conv [symmetric] card_eq_0_iff) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2024 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2025 |
lemma card_Suc_Diff1: "finite A ==> x: A ==> Suc (card (A - {x})) = card A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2026 |
apply(rule_tac t = A in insert_Diff [THEN subst], assumption) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2027 |
apply(simp del:insert_Diff_single) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2028 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2029 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2030 |
lemma card_Diff_singleton: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2031 |
"finite A ==> x: A ==> card (A - {x}) = card A - 1" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2032 |
by (simp add: card_Suc_Diff1 [symmetric]) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2033 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2034 |
lemma card_Diff_singleton_if: |
45166 | 2035 |
"finite A ==> card (A - {x}) = (if x : A then card A - 1 else card A)" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2036 |
by (simp add: card_Diff_singleton) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2037 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2038 |
lemma card_Diff_insert[simp]: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2039 |
assumes "finite A" and "a:A" and "a ~: B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2040 |
shows "card(A - insert a B) = card(A - B) - 1" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2041 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2042 |
have "A - insert a B = (A - B) - {a}" using assms by blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2043 |
then show ?thesis using assms by(simp add:card_Diff_singleton) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2044 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2045 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2046 |
lemma card_insert: "finite A ==> card (insert x A) = Suc (card (A - {x}))" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2047 |
by (simp add: card_insert_if card_Suc_Diff1 del:card_Diff_insert) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2048 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2049 |
lemma card_insert_le: "finite A ==> card A <= card (insert x A)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2050 |
by (simp add: card_insert_if) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2051 |
|
41987 | 2052 |
lemma card_Collect_less_nat[simp]: "card{i::nat. i < n} = n" |
2053 |
by (induct n) (simp_all add:less_Suc_eq Collect_disj_eq) |
|
2054 |
||
41988 | 2055 |
lemma card_Collect_le_nat[simp]: "card{i::nat. i <= n} = Suc n" |
41987 | 2056 |
using card_Collect_less_nat[of "Suc n"] by(simp add: less_Suc_eq_le) |
2057 |
||
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2058 |
lemma card_mono: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2059 |
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
|
2060 |
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
|
2061 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2062 |
from assms have "finite A" by (auto intro: finite_subset) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2063 |
then show ?thesis using assms proof (induct A arbitrary: B) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2064 |
case empty then show ?case by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2065 |
next |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2066 |
case (insert x A) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2067 |
then have "x \<in> B" by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2068 |
from insert have "A \<subseteq> B - {x}" and "finite (B - {x})" by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2069 |
with insert.hyps have "card A \<le> card (B - {x})" by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2070 |
with `finite A` `x \<notin> A` `finite B` `x \<in> B` show ?case by simp (simp only: card.remove) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2071 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2072 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2073 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2074 |
lemma card_seteq: "finite B ==> (!!A. A <= B ==> card B <= card A ==> A = B)" |
41656 | 2075 |
apply (induct rule: finite_induct) |
2076 |
apply simp |
|
2077 |
apply clarify |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2078 |
apply (subgoal_tac "finite A & A - {x} <= F") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2079 |
prefer 2 apply (blast intro: finite_subset, atomize) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2080 |
apply (drule_tac x = "A - {x}" in spec) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2081 |
apply (simp add: card_Diff_singleton_if split add: split_if_asm) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2082 |
apply (case_tac "card A", auto) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2083 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2084 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2085 |
lemma psubset_card_mono: "finite B ==> A < B ==> card A < card B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2086 |
apply (simp add: psubset_eq linorder_not_le [symmetric]) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2087 |
apply (blast dest: card_seteq) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2088 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2089 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2090 |
lemma card_Un_Int: "finite A ==> finite B |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2091 |
==> card A + card B = card (A Un B) + card (A Int B)" |
35817
d8b8527102f5
added locales folding_one_(idem); various streamlining and tuning
haftmann
parents:
35796
diff
changeset
|
2092 |
by (fact card.union_inter [symmetric]) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2093 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2094 |
lemma card_Un_disjoint: "finite A ==> finite B |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2095 |
==> A Int B = {} ==> card (A Un 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
|
2096 |
by (fact card.union_disjoint) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2097 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2098 |
lemma card_Diff_subset: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2099 |
assumes "finite B" and "B \<subseteq> A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2100 |
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
|
2101 |
proof (cases "finite A") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2102 |
case False with assms show ?thesis by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2103 |
next |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2104 |
case True with assms show ?thesis by (induct B arbitrary: A) simp_all |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2105 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2106 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2107 |
lemma card_Diff_subset_Int: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2108 |
assumes AB: "finite (A \<inter> B)" shows "card (A - B) = card A - card (A \<inter> B)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2109 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2110 |
have "A - B = A - A \<inter> B" by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2111 |
thus ?thesis |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2112 |
by (simp add: card_Diff_subset AB) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2113 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2114 |
|
40716 | 2115 |
lemma diff_card_le_card_Diff: |
2116 |
assumes "finite B" shows "card A - card B \<le> card(A - B)" |
|
2117 |
proof- |
|
2118 |
have "card A - card B \<le> card A - card (A \<inter> B)" |
|
2119 |
using card_mono[OF assms Int_lower2, of A] by arith |
|
2120 |
also have "\<dots> = card(A-B)" using assms by(simp add: card_Diff_subset_Int) |
|
2121 |
finally show ?thesis . |
|
2122 |
qed |
|
2123 |
||
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2124 |
lemma card_Diff1_less: "finite A ==> x: A ==> card (A - {x}) < card A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2125 |
apply (rule Suc_less_SucD) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2126 |
apply (simp add: card_Suc_Diff1 del:card_Diff_insert) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2127 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2128 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2129 |
lemma card_Diff2_less: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2130 |
"finite A ==> x: A ==> y: A ==> card (A - {x} - {y}) < card A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2131 |
apply (case_tac "x = y") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2132 |
apply (simp add: card_Diff1_less del:card_Diff_insert) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2133 |
apply (rule less_trans) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2134 |
prefer 2 apply (auto intro!: card_Diff1_less simp del:card_Diff_insert) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2135 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2136 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2137 |
lemma card_Diff1_le: "finite A ==> card (A - {x}) <= card A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2138 |
apply (case_tac "x : A") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2139 |
apply (simp_all add: card_Diff1_less less_imp_le) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2140 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2141 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2142 |
lemma card_psubset: "finite B ==> A \<subseteq> B ==> card A < card B ==> A < B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2143 |
by (erule psubsetI, blast) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2144 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2145 |
lemma insert_partition: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2146 |
"\<lbrakk> x \<notin> F; \<forall>c1 \<in> insert x F. \<forall>c2 \<in> insert x F. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {} \<rbrakk> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2147 |
\<Longrightarrow> x \<inter> \<Union> F = {}" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2148 |
by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2149 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2150 |
lemma finite_psubset_induct[consumes 1, case_names psubset]: |
36079
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2151 |
assumes fin: "finite A" |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2152 |
and major: "\<And>A. finite A \<Longrightarrow> (\<And>B. B \<subset> A \<Longrightarrow> P B) \<Longrightarrow> P A" |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2153 |
shows "P A" |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2154 |
using fin |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2155 |
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
|
2156 |
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
|
2157 |
have fin: "finite A" by fact |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2158 |
have ih: "\<And>B. \<lbrakk>card B < card A; finite B\<rbrakk> \<Longrightarrow> P B" by fact |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2159 |
{ fix B |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2160 |
assume asm: "B \<subset> A" |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2161 |
from asm have "card B < card A" using psubset_card_mono fin by blast |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2162 |
moreover |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2163 |
from asm have "B \<subseteq> A" by auto |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2164 |
then have "finite B" using fin finite_subset by blast |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2165 |
ultimately |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2166 |
have "P B" using ih by simp |
fa0e354e6a39
simplified induction case in finite_psubset_induct; tuned the proof that uses this induction principle
Christian Urban <urbanc@in.tum.de>
parents:
36045
diff
changeset
|
2167 |
} |
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
|
2168 |
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
|
2169 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2170 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2171 |
text{* main cardinality theorem *} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2172 |
lemma card_partition [rule_format]: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2173 |
"finite C ==> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2174 |
finite (\<Union> C) --> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2175 |
(\<forall>c\<in>C. card c = k) --> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2176 |
(\<forall>c1 \<in> C. \<forall>c2 \<in> C. c1 \<noteq> c2 --> c1 \<inter> c2 = {}) --> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2177 |
k * card(C) = card (\<Union> C)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2178 |
apply (erule finite_induct, simp) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2179 |
apply (simp add: card_Un_disjoint insert_partition |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2180 |
finite_subset [of _ "\<Union> (insert x F)"]) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2181 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2182 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2183 |
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
|
2184 |
assumes fin: "finite (UNIV :: 'a set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2185 |
and card: "card A = card (UNIV :: 'a set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2186 |
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
|
2187 |
proof |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2188 |
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
|
2189 |
show "UNIV \<subseteq> A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2190 |
proof |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2191 |
fix x |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2192 |
show "x \<in> A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2193 |
proof (rule ccontr) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2194 |
assume "x \<notin> A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2195 |
then have "A \<subset> UNIV" by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2196 |
with fin have "card A < card (UNIV :: 'a set)" by (fact psubset_card_mono) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2197 |
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
|
2198 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2199 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2200 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2201 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2202 |
text{*The form of a finite set of given cardinality*} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2203 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2204 |
lemma card_eq_SucD: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2205 |
assumes "card A = Suc k" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2206 |
shows "\<exists>b B. A = insert b B & b \<notin> B & card B = k & (k=0 \<longrightarrow> B={})" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2207 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2208 |
have fin: "finite A" using assms by (auto intro: ccontr) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2209 |
moreover have "card A \<noteq> 0" using assms by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2210 |
ultimately obtain b where b: "b \<in> A" by auto |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2211 |
show ?thesis |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2212 |
proof (intro exI conjI) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2213 |
show "A = insert b (A-{b})" using b by blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2214 |
show "b \<notin> A - {b}" by blast |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2215 |
show "card (A - {b}) = k" and "k = 0 \<longrightarrow> A - {b} = {}" |
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44835
diff
changeset
|
2216 |
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
|
2217 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2218 |
qed |
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_Suc_eq: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2221 |
"(card A = Suc k) = |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2222 |
(\<exists>b B. A = insert b B & b \<notin> B & card B = k & (k=0 \<longrightarrow> B={}))" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2223 |
apply(rule iffI) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2224 |
apply(erule card_eq_SucD) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2225 |
apply(auto) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2226 |
apply(subst card_insert) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2227 |
apply(auto intro:ccontr) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2228 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2229 |
|
44744 | 2230 |
lemma card_le_Suc_iff: "finite A \<Longrightarrow> |
2231 |
Suc n \<le> card A = (\<exists>a B. A = insert a B \<and> a \<notin> B \<and> n \<le> card B \<and> finite B)" |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44835
diff
changeset
|
2232 |
by (fastforce simp: card_Suc_eq less_eq_nat.simps(2) insert_eq_iff |
44744 | 2233 |
dest: subset_singletonD split: nat.splits if_splits) |
2234 |
||
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2235 |
lemma finite_fun_UNIVD2: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2236 |
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
|
2237 |
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
|
2238 |
proof - |
46146
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
2239 |
from fin have "\<And>arbitrary. finite (range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary))" |
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
2240 |
by (rule finite_imageI) |
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
2241 |
moreover have "\<And>arbitrary. UNIV = range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary)" |
6baea4fca6bd
incorporated various theorems from theory More_Set into corpus
haftmann
parents:
46033
diff
changeset
|
2242 |
by (rule UNIV_eq_I) auto |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2243 |
ultimately show "finite (UNIV :: 'b set)" by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2244 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2245 |
|
48063
f02b4302d5dd
remove duplicate lemma card_unit in favor of Finite_Set.card_UNIV_unit
huffman
parents:
47221
diff
changeset
|
2246 |
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
|
2247 |
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
|
2248 |
|
47210
b1dd32b2a505
move lemma card_UNIV_bool from Nat_Numeral.thy to Finite_Set.thy
huffman
parents:
46898
diff
changeset
|
2249 |
lemma card_UNIV_bool [simp]: "card (UNIV :: bool set) = 2" |
b1dd32b2a505
move lemma card_UNIV_bool from Nat_Numeral.thy to Finite_Set.thy
huffman
parents:
46898
diff
changeset
|
2250 |
unfolding UNIV_bool by simp |
b1dd32b2a505
move lemma card_UNIV_bool from Nat_Numeral.thy to Finite_Set.thy
huffman
parents:
46898
diff
changeset
|
2251 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2252 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2253 |
subsubsection {* Cardinality of image *} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2254 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2255 |
lemma card_image_le: "finite A ==> card (f ` A) <= card A" |
41656 | 2256 |
apply (induct rule: finite_induct) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2257 |
apply simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2258 |
apply (simp add: le_SucI card_insert_if) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2259 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2260 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2261 |
lemma card_image: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2262 |
assumes "inj_on f A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2263 |
shows "card (f ` A) = card A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2264 |
proof (cases "finite A") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2265 |
case True then show ?thesis using assms by (induct A) simp_all |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2266 |
next |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2267 |
case False then have "\<not> finite (f ` A)" using assms by (auto dest: finite_imageD) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2268 |
with False show ?thesis by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2269 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2270 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2271 |
lemma bij_betw_same_card: "bij_betw f A B \<Longrightarrow> card A = card B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2272 |
by(auto simp: card_image bij_betw_def) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2273 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2274 |
lemma endo_inj_surj: "finite A ==> f ` A \<subseteq> A ==> inj_on f A ==> f ` A = A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2275 |
by (simp add: card_seteq card_image) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2276 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2277 |
lemma eq_card_imp_inj_on: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2278 |
"[| finite A; card(f ` A) = card A |] ==> inj_on f A" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2279 |
apply (induct rule:finite_induct) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2280 |
apply simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2281 |
apply(frule card_image_le[where f = f]) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2282 |
apply(simp add:card_insert_if split:if_splits) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2283 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2284 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2285 |
lemma inj_on_iff_eq_card: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2286 |
"finite A ==> inj_on f A = (card(f ` A) = card A)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2287 |
by(blast intro: card_image eq_card_imp_inj_on) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2288 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2289 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2290 |
lemma card_inj_on_le: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2291 |
"[|inj_on f A; f ` A \<subseteq> B; finite B |] ==> card A \<le> card B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2292 |
apply (subgoal_tac "finite A") |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2293 |
apply (force intro: card_mono simp add: card_image [symmetric]) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2294 |
apply (blast intro: finite_imageD dest: finite_subset) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2295 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2296 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2297 |
lemma card_bij_eq: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2298 |
"[|inj_on f A; f ` A \<subseteq> B; inj_on g B; g ` B \<subseteq> A; |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2299 |
finite A; finite B |] ==> card A = card B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2300 |
by (auto intro: le_antisym card_inj_on_le) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2301 |
|
40703
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
2302 |
lemma bij_betw_finite: |
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
2303 |
assumes "bij_betw f A B" |
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
2304 |
shows "finite A \<longleftrightarrow> finite B" |
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
2305 |
using assms unfolding bij_betw_def |
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
hoelzl
parents:
40702
diff
changeset
|
2306 |
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
|
2307 |
|
41656 | 2308 |
|
37466 | 2309 |
subsubsection {* Pigeonhole Principles *} |
2310 |
||
40311 | 2311 |
lemma pigeonhole: "card A > card(f ` A) \<Longrightarrow> ~ inj_on f A " |
37466 | 2312 |
by (auto dest: card_image less_irrefl_nat) |
2313 |
||
2314 |
lemma pigeonhole_infinite: |
|
2315 |
assumes "~ finite A" and "finite(f`A)" |
|
2316 |
shows "EX a0:A. ~finite{a:A. f a = f a0}" |
|
2317 |
proof - |
|
2318 |
have "finite(f`A) \<Longrightarrow> ~ finite A \<Longrightarrow> EX a0:A. ~finite{a:A. f a = f a0}" |
|
2319 |
proof(induct "f`A" arbitrary: A rule: finite_induct) |
|
2320 |
case empty thus ?case by simp |
|
2321 |
next |
|
2322 |
case (insert b F) |
|
2323 |
show ?case |
|
2324 |
proof cases |
|
2325 |
assume "finite{a:A. f a = b}" |
|
2326 |
hence "~ finite(A - {a:A. f a = b})" using `\<not> finite A` by simp |
|
2327 |
also have "A - {a:A. f a = b} = {a:A. f a \<noteq> b}" by blast |
|
2328 |
finally have "~ finite({a:A. f a \<noteq> b})" . |
|
2329 |
from insert(3)[OF _ this] |
|
2330 |
show ?thesis using insert(2,4) by simp (blast intro: rev_finite_subset) |
|
2331 |
next |
|
2332 |
assume 1: "~finite{a:A. f a = b}" |
|
2333 |
hence "{a \<in> A. f a = b} \<noteq> {}" by force |
|
2334 |
thus ?thesis using 1 by blast |
|
2335 |
qed |
|
2336 |
qed |
|
2337 |
from this[OF assms(2,1)] show ?thesis . |
|
2338 |
qed |
|
2339 |
||
2340 |
lemma pigeonhole_infinite_rel: |
|
2341 |
assumes "~finite A" and "finite B" and "ALL a:A. EX b:B. R a b" |
|
2342 |
shows "EX b:B. ~finite{a:A. R a b}" |
|
2343 |
proof - |
|
2344 |
let ?F = "%a. {b:B. R a b}" |
|
2345 |
from finite_Pow_iff[THEN iffD2, OF `finite B`] |
|
2346 |
have "finite(?F ` A)" by(blast intro: rev_finite_subset) |
|
2347 |
from pigeonhole_infinite[where f = ?F, OF assms(1) this] |
|
2348 |
obtain a0 where "a0\<in>A" and 1: "\<not> finite {a\<in>A. ?F a = ?F a0}" .. |
|
2349 |
obtain b0 where "b0 : B" and "R a0 b0" using `a0:A` assms(3) by blast |
|
2350 |
{ assume "finite{a:A. R a b0}" |
|
2351 |
then have "finite {a\<in>A. ?F a = ?F a0}" |
|
2352 |
using `b0 : B` `R a0 b0` by(blast intro: rev_finite_subset) |
|
2353 |
} |
|
2354 |
with 1 `b0 : B` show ?thesis by blast |
|
2355 |
qed |
|
2356 |
||
2357 |
||
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2358 |
subsubsection {* Cardinality of sums *} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2359 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2360 |
lemma card_Plus: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2361 |
assumes "finite A" and "finite B" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2362 |
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
|
2363 |
proof - |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2364 |
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
|
2365 |
with assms show ?thesis |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2366 |
unfolding Plus_def |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2367 |
by (simp add: card_Un_disjoint card_image) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2368 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2369 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2370 |
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
|
2371 |
"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
|
2372 |
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
|
2373 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2374 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2375 |
subsubsection {* Cardinality of the Powerset *} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2376 |
|
47221
7205eb4a0a05
rephrase lemma card_Pow using '2' instead of 'Suc (Suc 0)'
huffman
parents:
47210
diff
changeset
|
2377 |
lemma card_Pow: "finite A ==> card (Pow A) = 2 ^ card A" |
41656 | 2378 |
apply (induct rule: finite_induct) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2379 |
apply (simp_all add: Pow_insert) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2380 |
apply (subst card_Un_disjoint, blast) |
40786
0a54cfc9add3
gave more standard finite set rules simp and intro attribute
nipkow
parents:
40716
diff
changeset
|
2381 |
apply (blast, blast) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2382 |
apply (subgoal_tac "inj_on (insert x) (Pow F)") |
47221
7205eb4a0a05
rephrase lemma card_Pow using '2' instead of 'Suc (Suc 0)'
huffman
parents:
47210
diff
changeset
|
2383 |
apply (subst mult_2) |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2384 |
apply (simp add: card_image Pow_insert) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2385 |
apply (unfold inj_on_def) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2386 |
apply (blast elim!: equalityE) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2387 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2388 |
|
41987 | 2389 |
text {* Relates to equivalence classes. Based on a theorem of F. Kamm\"uller. *} |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2390 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2391 |
lemma dvd_partition: |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2392 |
"finite (Union C) ==> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2393 |
ALL c : C. k dvd card c ==> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2394 |
(ALL c1: C. ALL c2: C. c1 \<noteq> c2 --> c1 Int c2 = {}) ==> |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2395 |
k dvd card (Union C)" |
41656 | 2396 |
apply (frule finite_UnionD) |
2397 |
apply (rotate_tac -1) |
|
2398 |
apply (induct rule: finite_induct) |
|
2399 |
apply simp_all |
|
2400 |
apply clarify |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2401 |
apply (subst card_Un_disjoint) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2402 |
apply (auto simp add: disjoint_eq_subset_Compl) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2403 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2404 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2405 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2406 |
subsubsection {* Relating injectivity and surjectivity *} |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2407 |
|
41656 | 2408 |
lemma finite_surj_inj: "finite A \<Longrightarrow> A \<subseteq> f ` A \<Longrightarrow> inj_on f A" |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2409 |
apply(rule eq_card_imp_inj_on, assumption) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2410 |
apply(frule finite_imageI) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2411 |
apply(drule (1) card_seteq) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2412 |
apply(erule card_image_le) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2413 |
apply simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2414 |
done |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2415 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2416 |
lemma finite_UNIV_surj_inj: fixes f :: "'a \<Rightarrow> 'a" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2417 |
shows "finite(UNIV:: 'a set) \<Longrightarrow> surj f \<Longrightarrow> inj f" |
40702 | 2418 |
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
|
2419 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2420 |
lemma finite_UNIV_inj_surj: fixes f :: "'a \<Rightarrow> 'a" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2421 |
shows "finite(UNIV:: 'a set) \<Longrightarrow> inj f \<Longrightarrow> surj f" |
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44835
diff
changeset
|
2422 |
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
|
2423 |
|
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2424 |
corollary infinite_UNIV_nat[iff]: "~finite(UNIV::nat set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2425 |
proof |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2426 |
assume "finite(UNIV::nat set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2427 |
with finite_UNIV_inj_surj[of Suc] |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2428 |
show False by simp (blast dest: Suc_neq_Zero surjD) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2429 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2430 |
|
35828
46cfc4b8112e
now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents:
35796
diff
changeset
|
2431 |
(* Often leads to bogus ATP proofs because of reduced type information, hence no_atp *) |
46cfc4b8112e
now use "Named_Thms" for "noatp", and renamed "noatp" to "no_atp"
blanchet
parents:
35796
diff
changeset
|
2432 |
lemma infinite_UNIV_char_0[no_atp]: |
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2433 |
"\<not> finite (UNIV::'a::semiring_char_0 set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2434 |
proof |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2435 |
assume "finite (UNIV::'a set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2436 |
with subset_UNIV have "finite (range of_nat::'a set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2437 |
by (rule finite_subset) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2438 |
moreover have "inj (of_nat::nat \<Rightarrow> 'a)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2439 |
by (simp add: inj_on_def) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2440 |
ultimately have "finite (UNIV::nat set)" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2441 |
by (rule finite_imageD) |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2442 |
then show "False" |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2443 |
by simp |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2444 |
qed |
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2445 |
|
49758
718f10c8bbfc
use Set.filter instead of Finite_Set.filter, which is removed then
kuncar
parents:
49757
diff
changeset
|
2446 |
hide_const (open) Finite_Set.fold |
46033 | 2447 |
|
35722
69419a09a7ff
moved cardinality to Finite_Set as far as appropriate; added locales for fold_image
haftmann
parents:
35719
diff
changeset
|
2448 |
end |
49723
bbc2942ba09f
alternative simplification of ^^ to the righthand side;
haftmann
parents:
48891
diff
changeset
|
2449 |