author | wenzelm |
Sat, 13 May 2006 02:51:48 +0200 | |
changeset 19635 | f7aa7d174343 |
parent 19537 | 213ff8b0c60c |
child 19656 | 09be06943252 |
permissions | -rw-r--r-- |
14442 | 1 |
(* Title: HOL/Infnite_Set.thy |
2 |
ID: $Id$ |
|
14896 | 3 |
Author: Stephan Merz |
14442 | 4 |
*) |
5 |
||
19457 | 6 |
header {* Infinite Sets and Related Concepts*} |
14442 | 7 |
|
15131 | 8 |
theory Infinite_Set |
16733
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
15140
diff
changeset
|
9 |
imports Hilbert_Choice Binomial |
15131 | 10 |
begin |
14442 | 11 |
|
12 |
subsection "Infinite Sets" |
|
13 |
||
14 |
text {* Some elementary facts about infinite sets, by Stefan Merz. *} |
|
15 |
||
19363 | 16 |
abbreviation |
17 |
infinite :: "'a set \<Rightarrow> bool" |
|
18 |
"infinite S == \<not> finite S" |
|
14442 | 19 |
|
20 |
text {* |
|
21 |
Infinite sets are non-empty, and if we remove some elements |
|
22 |
from an infinite set, the result is still infinite. |
|
23 |
*} |
|
24 |
||
25 |
lemma infinite_nonempty: |
|
26 |
"\<not> (infinite {})" |
|
19537 | 27 |
by simp |
14442 | 28 |
|
29 |
lemma infinite_remove: |
|
30 |
"infinite S \<Longrightarrow> infinite (S - {a})" |
|
19537 | 31 |
by simp |
14442 | 32 |
|
33 |
lemma Diff_infinite_finite: |
|
34 |
assumes T: "finite T" and S: "infinite S" |
|
35 |
shows "infinite (S-T)" |
|
19537 | 36 |
using T |
37 |
proof induct |
|
14442 | 38 |
from S |
39 |
show "infinite (S - {})" by auto |
|
40 |
next |
|
41 |
fix T x |
|
42 |
assume ih: "infinite (S-T)" |
|
43 |
have "S - (insert x T) = (S-T) - {x}" |
|
44 |
by (rule Diff_insert) |
|
45 |
with ih |
|
46 |
show "infinite (S - (insert x T))" |
|
47 |
by (simp add: infinite_remove) |
|
48 |
qed |
|
49 |
||
50 |
lemma Un_infinite: |
|
51 |
"infinite S \<Longrightarrow> infinite (S \<union> T)" |
|
19537 | 52 |
by simp |
14442 | 53 |
|
54 |
lemma infinite_super: |
|
55 |
assumes T: "S \<subseteq> T" and S: "infinite S" |
|
56 |
shows "infinite T" |
|
57 |
proof (rule ccontr) |
|
58 |
assume "\<not>(infinite T)" |
|
19537 | 59 |
with T have "finite S" by (simp add: finite_subset) |
60 |
with S show False by simp |
|
14442 | 61 |
qed |
62 |
||
63 |
text {* |
|
64 |
As a concrete example, we prove that the set of natural |
|
65 |
numbers is infinite. |
|
66 |
*} |
|
67 |
||
68 |
lemma finite_nat_bounded: |
|
69 |
assumes S: "finite (S::nat set)" |
|
15045 | 70 |
shows "\<exists>k. S \<subseteq> {..<k}" (is "\<exists>k. ?bounded S k") |
14442 | 71 |
using S |
72 |
proof (induct) |
|
73 |
have "?bounded {} 0" by simp |
|
74 |
thus "\<exists>k. ?bounded {} k" .. |
|
75 |
next |
|
76 |
fix S x |
|
77 |
assume "\<exists>k. ?bounded S k" |
|
78 |
then obtain k where k: "?bounded S k" .. |
|
79 |
show "\<exists>k. ?bounded (insert x S) k" |
|
80 |
proof (cases "x<k") |
|
81 |
case True |
|
82 |
with k show ?thesis by auto |
|
83 |
next |
|
84 |
case False |
|
85 |
with k have "?bounded S (Suc x)" by auto |
|
86 |
thus ?thesis by auto |
|
87 |
qed |
|
88 |
qed |
|
89 |
||
90 |
lemma finite_nat_iff_bounded: |
|
15045 | 91 |
"finite (S::nat set) = (\<exists>k. S \<subseteq> {..<k})" (is "?lhs = ?rhs") |
14442 | 92 |
proof |
93 |
assume ?lhs |
|
94 |
thus ?rhs by (rule finite_nat_bounded) |
|
95 |
next |
|
96 |
assume ?rhs |
|
15045 | 97 |
then obtain k where "S \<subseteq> {..<k}" .. |
14442 | 98 |
thus "finite S" |
99 |
by (rule finite_subset, simp) |
|
100 |
qed |
|
101 |
||
102 |
lemma finite_nat_iff_bounded_le: |
|
103 |
"finite (S::nat set) = (\<exists>k. S \<subseteq> {..k})" (is "?lhs = ?rhs") |
|
104 |
proof |
|
105 |
assume ?lhs |
|
15045 | 106 |
then obtain k where "S \<subseteq> {..<k}" |
14442 | 107 |
by (blast dest: finite_nat_bounded) |
108 |
hence "S \<subseteq> {..k}" by auto |
|
109 |
thus ?rhs .. |
|
110 |
next |
|
111 |
assume ?rhs |
|
112 |
then obtain k where "S \<subseteq> {..k}" .. |
|
113 |
thus "finite S" |
|
114 |
by (rule finite_subset, simp) |
|
115 |
qed |
|
116 |
||
117 |
lemma infinite_nat_iff_unbounded: |
|
118 |
"infinite (S::nat set) = (\<forall>m. \<exists>n. m<n \<and> n\<in>S)" |
|
119 |
(is "?lhs = ?rhs") |
|
120 |
proof |
|
121 |
assume inf: ?lhs |
|
122 |
show ?rhs |
|
123 |
proof (rule ccontr) |
|
124 |
assume "\<not> ?rhs" |
|
125 |
then obtain m where m: "\<forall>n. m<n \<longrightarrow> n\<notin>S" by blast |
|
126 |
hence "S \<subseteq> {..m}" |
|
16796 | 127 |
by (auto simp add: sym[OF linorder_not_less]) |
14442 | 128 |
with inf show "False" |
129 |
by (simp add: finite_nat_iff_bounded_le) |
|
130 |
qed |
|
131 |
next |
|
132 |
assume unbounded: ?rhs |
|
133 |
show ?lhs |
|
134 |
proof |
|
135 |
assume "finite S" |
|
136 |
then obtain m where "S \<subseteq> {..m}" |
|
137 |
by (auto simp add: finite_nat_iff_bounded_le) |
|
138 |
hence "\<forall>n. m<n \<longrightarrow> n\<notin>S" by auto |
|
139 |
with unbounded show "False" by blast |
|
140 |
qed |
|
141 |
qed |
|
142 |
||
143 |
lemma infinite_nat_iff_unbounded_le: |
|
144 |
"infinite (S::nat set) = (\<forall>m. \<exists>n. m\<le>n \<and> n\<in>S)" |
|
145 |
(is "?lhs = ?rhs") |
|
146 |
proof |
|
147 |
assume inf: ?lhs |
|
148 |
show ?rhs |
|
149 |
proof |
|
150 |
fix m |
|
151 |
from inf obtain n where "m<n \<and> n\<in>S" |
|
152 |
by (auto simp add: infinite_nat_iff_unbounded) |
|
153 |
hence "m\<le>n \<and> n\<in>S" by auto |
|
154 |
thus "\<exists>n. m \<le> n \<and> n \<in> S" .. |
|
155 |
qed |
|
156 |
next |
|
157 |
assume unbounded: ?rhs |
|
158 |
show ?lhs |
|
159 |
proof (auto simp add: infinite_nat_iff_unbounded) |
|
160 |
fix m |
|
161 |
from unbounded obtain n where "(Suc m)\<le>n \<and> n\<in>S" |
|
162 |
by blast |
|
163 |
hence "m<n \<and> n\<in>S" by auto |
|
164 |
thus "\<exists>n. m < n \<and> n \<in> S" .. |
|
165 |
qed |
|
166 |
qed |
|
167 |
||
168 |
text {* |
|
169 |
For a set of natural numbers to be infinite, it is enough |
|
14957 | 170 |
to know that for any number larger than some @{text k}, there |
14442 | 171 |
is some larger number that is an element of the set. |
172 |
*} |
|
173 |
||
174 |
lemma unbounded_k_infinite: |
|
175 |
assumes k: "\<forall>m. k<m \<longrightarrow> (\<exists>n. m<n \<and> n\<in>S)" |
|
176 |
shows "infinite (S::nat set)" |
|
177 |
proof (auto simp add: infinite_nat_iff_unbounded) |
|
178 |
fix m show "\<exists>n. m<n \<and> n\<in>S" |
|
179 |
proof (cases "k<m") |
|
180 |
case True |
|
181 |
with k show ?thesis by blast |
|
182 |
next |
|
183 |
case False |
|
184 |
from k obtain n where "Suc k < n \<and> n\<in>S" by auto |
|
185 |
with False have "m<n \<and> n\<in>S" by auto |
|
186 |
thus ?thesis .. |
|
187 |
qed |
|
188 |
qed |
|
189 |
||
190 |
theorem nat_infinite [simp]: |
|
191 |
"infinite (UNIV :: nat set)" |
|
192 |
by (auto simp add: infinite_nat_iff_unbounded) |
|
193 |
||
194 |
theorem nat_not_finite [elim]: |
|
195 |
"finite (UNIV::nat set) \<Longrightarrow> R" |
|
196 |
by simp |
|
197 |
||
198 |
text {* |
|
199 |
Every infinite set contains a countable subset. More precisely |
|
14957 | 200 |
we show that a set @{text S} is infinite if and only if there exists |
201 |
an injective function from the naturals into @{text S}. |
|
14442 | 202 |
*} |
203 |
||
204 |
lemma range_inj_infinite: |
|
205 |
"inj (f::nat \<Rightarrow> 'a) \<Longrightarrow> infinite (range f)" |
|
206 |
proof |
|
207 |
assume "inj f" |
|
208 |
and "finite (range f)" |
|
209 |
hence "finite (UNIV::nat set)" |
|
210 |
by (auto intro: finite_imageD simp del: nat_infinite) |
|
211 |
thus "False" by simp |
|
212 |
qed |
|
213 |
||
214 |
text {* |
|
215 |
The ``only if'' direction is harder because it requires the |
|
216 |
construction of a sequence of pairwise different elements of |
|
14957 | 217 |
an infinite set @{text S}. The idea is to construct a sequence of |
218 |
non-empty and infinite subsets of @{text S} obtained by successively |
|
219 |
removing elements of @{text S}. |
|
14442 | 220 |
*} |
221 |
||
222 |
lemma linorder_injI: |
|
223 |
assumes hyp: "\<forall>x y. x < (y::'a::linorder) \<longrightarrow> f x \<noteq> f y" |
|
224 |
shows "inj f" |
|
225 |
proof (rule inj_onI) |
|
226 |
fix x y |
|
227 |
assume f_eq: "f x = f y" |
|
228 |
show "x = y" |
|
229 |
proof (rule linorder_cases) |
|
230 |
assume "x < y" |
|
231 |
with hyp have "f x \<noteq> f y" by blast |
|
232 |
with f_eq show ?thesis by simp |
|
233 |
next |
|
234 |
assume "x = y" |
|
235 |
thus ?thesis . |
|
236 |
next |
|
237 |
assume "y < x" |
|
238 |
with hyp have "f y \<noteq> f x" by blast |
|
239 |
with f_eq show ?thesis by simp |
|
240 |
qed |
|
241 |
qed |
|
242 |
||
243 |
lemma infinite_countable_subset: |
|
244 |
assumes inf: "infinite (S::'a set)" |
|
245 |
shows "\<exists>f. inj (f::nat \<Rightarrow> 'a) \<and> range f \<subseteq> S" |
|
246 |
proof - |
|
14766 | 247 |
def Sseq \<equiv> "nat_rec S (\<lambda>n T. T - {SOME e. e \<in> T})" |
248 |
def pick \<equiv> "\<lambda>n. (SOME e. e \<in> Sseq n)" |
|
14442 | 249 |
have Sseq_inf: "\<And>n. infinite (Sseq n)" |
250 |
proof - |
|
251 |
fix n |
|
252 |
show "infinite (Sseq n)" |
|
253 |
proof (induct n) |
|
254 |
from inf show "infinite (Sseq 0)" |
|
255 |
by (simp add: Sseq_def) |
|
256 |
next |
|
257 |
fix n |
|
258 |
assume "infinite (Sseq n)" thus "infinite (Sseq (Suc n))" |
|
259 |
by (simp add: Sseq_def infinite_remove) |
|
260 |
qed |
|
261 |
qed |
|
262 |
have Sseq_S: "\<And>n. Sseq n \<subseteq> S" |
|
263 |
proof - |
|
264 |
fix n |
|
265 |
show "Sseq n \<subseteq> S" |
|
266 |
by (induct n, auto simp add: Sseq_def) |
|
267 |
qed |
|
268 |
have Sseq_pick: "\<And>n. pick n \<in> Sseq n" |
|
269 |
proof - |
|
270 |
fix n |
|
271 |
show "pick n \<in> Sseq n" |
|
272 |
proof (unfold pick_def, rule someI_ex) |
|
273 |
from Sseq_inf have "infinite (Sseq n)" . |
|
274 |
hence "Sseq n \<noteq> {}" by auto |
|
275 |
thus "\<exists>x. x \<in> Sseq n" by auto |
|
276 |
qed |
|
277 |
qed |
|
278 |
with Sseq_S have rng: "range pick \<subseteq> S" |
|
279 |
by auto |
|
280 |
have pick_Sseq_gt: "\<And>n m. pick n \<notin> Sseq (n + Suc m)" |
|
281 |
proof - |
|
282 |
fix n m |
|
283 |
show "pick n \<notin> Sseq (n + Suc m)" |
|
284 |
by (induct m, auto simp add: Sseq_def pick_def) |
|
285 |
qed |
|
286 |
have pick_pick: "\<And>n m. pick n \<noteq> pick (n + Suc m)" |
|
287 |
proof - |
|
288 |
fix n m |
|
289 |
from Sseq_pick have "pick (n + Suc m) \<in> Sseq (n + Suc m)" . |
|
290 |
moreover from pick_Sseq_gt |
|
291 |
have "pick n \<notin> Sseq (n + Suc m)" . |
|
292 |
ultimately show "pick n \<noteq> pick (n + Suc m)" |
|
293 |
by auto |
|
294 |
qed |
|
295 |
have inj: "inj pick" |
|
296 |
proof (rule linorder_injI) |
|
297 |
show "\<forall>i j. i<(j::nat) \<longrightarrow> pick i \<noteq> pick j" |
|
298 |
proof (clarify) |
|
299 |
fix i j |
|
300 |
assume ij: "i<(j::nat)" |
|
301 |
and eq: "pick i = pick j" |
|
302 |
from ij obtain k where "j = i + (Suc k)" |
|
303 |
by (auto simp add: less_iff_Suc_add) |
|
304 |
with pick_pick have "pick i \<noteq> pick j" by simp |
|
305 |
with eq show "False" by simp |
|
306 |
qed |
|
307 |
qed |
|
308 |
from rng inj show ?thesis by auto |
|
309 |
qed |
|
310 |
||
311 |
theorem infinite_iff_countable_subset: |
|
312 |
"infinite S = (\<exists>f. inj (f::nat \<Rightarrow> 'a) \<and> range f \<subseteq> S)" |
|
313 |
(is "?lhs = ?rhs") |
|
314 |
by (auto simp add: infinite_countable_subset |
|
315 |
range_inj_infinite infinite_super) |
|
316 |
||
317 |
text {* |
|
318 |
For any function with infinite domain and finite range |
|
319 |
there is some element that is the image of infinitely |
|
320 |
many domain elements. In particular, any infinite sequence |
|
321 |
of elements from a finite set contains some element that |
|
322 |
occurs infinitely often. |
|
323 |
*} |
|
324 |
||
325 |
theorem inf_img_fin_dom: |
|
326 |
assumes img: "finite (f`A)" and dom: "infinite A" |
|
327 |
shows "\<exists>y \<in> f`A. infinite (f -` {y})" |
|
328 |
proof (rule ccontr) |
|
329 |
assume "\<not> (\<exists>y\<in>f ` A. infinite (f -` {y}))" |
|
330 |
with img have "finite (UN y:f`A. f -` {y})" |
|
331 |
by (blast intro: finite_UN_I) |
|
332 |
moreover have "A \<subseteq> (UN y:f`A. f -` {y})" by auto |
|
333 |
moreover note dom |
|
334 |
ultimately show "False" |
|
335 |
by (simp add: infinite_super) |
|
336 |
qed |
|
337 |
||
338 |
theorems inf_img_fin_domE = inf_img_fin_dom[THEN bexE] |
|
339 |
||
340 |
||
341 |
subsection "Infinitely Many and Almost All" |
|
342 |
||
343 |
text {* |
|
344 |
We often need to reason about the existence of infinitely many |
|
345 |
(resp., all but finitely many) objects satisfying some predicate, |
|
346 |
so we introduce corresponding binders and their proof rules. |
|
347 |
*} |
|
348 |
||
349 |
consts |
|
350 |
Inf_many :: "('a \<Rightarrow> bool) \<Rightarrow> bool" (binder "INF " 10) |
|
351 |
Alm_all :: "('a \<Rightarrow> bool) \<Rightarrow> bool" (binder "MOST " 10) |
|
352 |
||
353 |
defs |
|
354 |
INF_def: "Inf_many P \<equiv> infinite {x. P x}" |
|
355 |
MOST_def: "Alm_all P \<equiv> \<not>(INF x. \<not> P x)" |
|
356 |
||
19537 | 357 |
abbreviation (xsymbols) |
358 |
Inf_many1 (binder "\<exists>\<^sub>\<infinity>" 10) |
|
359 |
"Inf_many1 == Inf_many" |
|
360 |
Alm_all1 (binder "\<forall>\<^sub>\<infinity>" 10) |
|
361 |
"Alm_all1 == Alm_all" |
|
14442 | 362 |
|
19537 | 363 |
abbreviation (HTML output) |
364 |
Inf_many2 (binder "\<exists>\<^sub>\<infinity>" 10) |
|
365 |
"Inf_many2 == Inf_many" |
|
366 |
Alm_all2 (binder "\<forall>\<^sub>\<infinity>" 10) |
|
367 |
"Alm_all2 == Alm_all" |
|
14565 | 368 |
|
14442 | 369 |
lemma INF_EX: |
370 |
"(\<exists>\<^sub>\<infinity>x. P x) \<Longrightarrow> (\<exists>x. P x)" |
|
371 |
proof (unfold INF_def, rule ccontr) |
|
372 |
assume inf: "infinite {x. P x}" |
|
373 |
and notP: "\<not>(\<exists>x. P x)" |
|
374 |
from notP have "{x. P x} = {}" by simp |
|
375 |
hence "finite {x. P x}" by simp |
|
376 |
with inf show "False" by simp |
|
377 |
qed |
|
378 |
||
379 |
lemma MOST_iff_finiteNeg: |
|
380 |
"(\<forall>\<^sub>\<infinity>x. P x) = finite {x. \<not> P x}" |
|
381 |
by (simp add: MOST_def INF_def) |
|
382 |
||
383 |
lemma ALL_MOST: |
|
384 |
"\<forall>x. P x \<Longrightarrow> \<forall>\<^sub>\<infinity>x. P x" |
|
385 |
by (simp add: MOST_iff_finiteNeg) |
|
386 |
||
387 |
lemma INF_mono: |
|
388 |
assumes inf: "\<exists>\<^sub>\<infinity>x. P x" and q: "\<And>x. P x \<Longrightarrow> Q x" |
|
389 |
shows "\<exists>\<^sub>\<infinity>x. Q x" |
|
390 |
proof - |
|
391 |
from inf have "infinite {x. P x}" by (unfold INF_def) |
|
392 |
moreover from q have "{x. P x} \<subseteq> {x. Q x}" by auto |
|
393 |
ultimately show ?thesis |
|
394 |
by (simp add: INF_def infinite_super) |
|
395 |
qed |
|
396 |
||
397 |
lemma MOST_mono: |
|
398 |
"\<lbrakk> \<forall>\<^sub>\<infinity>x. P x; \<And>x. P x \<Longrightarrow> Q x \<rbrakk> \<Longrightarrow> \<forall>\<^sub>\<infinity>x. Q x" |
|
399 |
by (unfold MOST_def, blast intro: INF_mono) |
|
400 |
||
401 |
lemma INF_nat: "(\<exists>\<^sub>\<infinity>n. P (n::nat)) = (\<forall>m. \<exists>n. m<n \<and> P n)" |
|
402 |
by (simp add: INF_def infinite_nat_iff_unbounded) |
|
403 |
||
404 |
lemma INF_nat_le: "(\<exists>\<^sub>\<infinity>n. P (n::nat)) = (\<forall>m. \<exists>n. m\<le>n \<and> P n)" |
|
405 |
by (simp add: INF_def infinite_nat_iff_unbounded_le) |
|
406 |
||
407 |
lemma MOST_nat: "(\<forall>\<^sub>\<infinity>n. P (n::nat)) = (\<exists>m. \<forall>n. m<n \<longrightarrow> P n)" |
|
408 |
by (simp add: MOST_def INF_nat) |
|
409 |
||
410 |
lemma MOST_nat_le: "(\<forall>\<^sub>\<infinity>n. P (n::nat)) = (\<exists>m. \<forall>n. m\<le>n \<longrightarrow> P n)" |
|
411 |
by (simp add: MOST_def INF_nat_le) |
|
412 |
||
413 |
||
414 |
subsection "Miscellaneous" |
|
415 |
||
416 |
text {* |
|
417 |
A few trivial lemmas about sets that contain at most one element. |
|
418 |
These simplify the reasoning about deterministic automata. |
|
419 |
*} |
|
420 |
||
421 |
constdefs |
|
422 |
atmost_one :: "'a set \<Rightarrow> bool" |
|
423 |
"atmost_one S \<equiv> \<forall>x y. x\<in>S \<and> y\<in>S \<longrightarrow> x=y" |
|
424 |
||
425 |
lemma atmost_one_empty: "S={} \<Longrightarrow> atmost_one S" |
|
19537 | 426 |
by (simp add: atmost_one_def) |
14442 | 427 |
|
428 |
lemma atmost_one_singleton: "S = {x} \<Longrightarrow> atmost_one S" |
|
19537 | 429 |
by (simp add: atmost_one_def) |
14442 | 430 |
|
431 |
lemma atmost_one_unique [elim]: "\<lbrakk> atmost_one S; x \<in> S; y \<in> S \<rbrakk> \<Longrightarrow> y=x" |
|
19537 | 432 |
by (simp add: atmost_one_def) |
14442 | 433 |
|
434 |
end |