# HG changeset patch # User hoelzl # Date 1358535659 -3600 # Node ID 5e3d3d6909753513bd05e7a801526d07162265aa # Parent 3e5b67f85bf9232dfa4fb9b1512a23fe5c60c3e9 tune prove compact_eq_totally_bounded diff -r 3e5b67f85bf9 -r 5e3d3d690975 src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy --- a/src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy Thu Jan 17 15:28:53 2013 -0800 +++ b/src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy Fri Jan 18 20:00:59 2013 +0100 @@ -9,7 +9,6 @@ theory Topology_Euclidean_Space imports Complex_Main - "~~/src/HOL/Library/Diagonal_Subsequence" "~~/src/HOL/Library/Countable_Set" "~~/src/HOL/Library/Glbs" "~~/src/HOL/Library/FuncSet" @@ -3417,10 +3416,120 @@ subsubsection{* Completeness *} -definition - complete :: "'a::metric_space set \ bool" where - "complete s \ (\f. (\n. f n \ s) \ Cauchy f - --> (\l \ s. (f ---> l) sequentially))" +definition complete :: "'a::metric_space set \ bool" where + "complete s \ (\f. (\n. f n \ s) \ Cauchy f \ (\l\s. f ----> l))" + +lemma compact_imp_complete: assumes "compact s" shows "complete s" +proof- + { fix f assume as: "(\n::nat. f n \ s)" "Cauchy f" + from as(1) obtain l r where lr: "l\s" "subseq r" "(f \ r) ----> l" + using assms unfolding compact_def by blast + + note lr' = seq_suble [OF lr(2)] + + { fix e::real assume "e>0" + from as(2) obtain N where N:"\m n. N \ m \ N \ n \ dist (f m) (f n) < e/2" unfolding cauchy_def using `e>0` apply (erule_tac x="e/2" in allE) by auto + from lr(3)[unfolded LIMSEQ_def, THEN spec[where x="e/2"]] obtain M where M:"\n\M. dist ((f \ r) n) l < e/2" using `e>0` by auto + { fix n::nat assume n:"n \ max N M" + have "dist ((f \ r) n) l < e/2" using n M by auto + moreover have "r n \ N" using lr'[of n] n by auto + hence "dist (f n) ((f \ r) n) < e / 2" using N using n by auto + ultimately have "dist (f n) l < e" using dist_triangle_half_r[of "f (r n)" "f n" e l] by (auto simp add: dist_commute) } + hence "\N. \n\N. dist (f n) l < e" by blast } + hence "\l\s. (f ---> l) sequentially" using `l\s` unfolding LIMSEQ_def by auto } + thus ?thesis unfolding complete_def by auto +qed + +lemma nat_approx_posE: + fixes e::real + assumes "0 < e" + obtains n::nat where "1 / (Suc n) < e" +proof atomize_elim + have " 1 / real (Suc (nat (ceiling (1/e)))) < 1 / (ceiling (1/e))" + by (rule divide_strict_left_mono) (auto intro!: mult_pos_pos simp: `0 < e`) + also have "1 / (ceiling (1/e)) \ 1 / (1/e)" + by (rule divide_left_mono) (auto intro!: divide_pos_pos simp: `0 < e`) + also have "\ = e" by simp + finally show "\n. 1 / real (Suc n) < e" .. +qed + +lemma compact_eq_totally_bounded: + "compact s \ complete s \ (\e>0. \k. finite k \ s \ (\((\x. ball x e) ` k)))" + (is "_ \ ?rhs") +proof + assume assms: "?rhs" + then obtain k where k: "\e. 0 < e \ finite (k e)" "\e. 0 < e \ s \ (\x\k e. ball x e)" + by (auto simp: choice_iff') + + show "compact s" + proof cases + assume "s = {}" thus "compact s" by (simp add: compact_def) + next + assume "s \ {}" + show ?thesis + unfolding compact_def + proof safe + fix f :: "nat \ 'a" assume f: "\n. f n \ s" + + def e \ "\n. 1 / (2 * Suc n)" + then have [simp]: "\n. 0 < e n" by auto + def B \ "\n U. SOME b. infinite {n. f n \ b} \ (\x. b \ ball x (e n) \ U)" + { fix n U assume "infinite {n. f n \ U}" + then have "\b\k (e n). infinite {i\{n. f n \ U}. f i \ ball b (e n)}" + using k f by (intro pigeonhole_infinite_rel) (auto simp: subset_eq) + then guess a .. + then have "\b. infinite {i. f i \ b} \ (\x. b \ ball x (e n) \ U)" + by (intro exI[of _ "ball a (e n) \ U"] exI[of _ a]) (auto simp: ac_simps) + from someI_ex[OF this] + have "infinite {i. f i \ B n U}" "\x. B n U \ ball x (e n) \ U" + unfolding B_def by auto } + note B = this + + def F \ "nat_rec (B 0 UNIV) B" + { fix n have "infinite {i. f i \ F n}" + by (induct n) (auto simp: F_def B) } + then have F: "\n. \x. F (Suc n) \ ball x (e n) \ F n" + using B by (simp add: F_def) + then have F_dec: "\m n. m \ n \ F n \ F m" + using decseq_SucI[of F] by (auto simp: decseq_def) + + obtain sel where sel: "\k i. i < sel k i" "\k i. f (sel k i) \ F k" + proof (atomize_elim, unfold all_conj_distrib[symmetric], intro choice allI) + fix k i + have "infinite ({n. f n \ F k} - {.. i})" + using `infinite {n. f n \ F k}` by auto + from infinite_imp_nonempty[OF this] + show "\x>i. f x \ F k" + by (simp add: set_eq_iff not_le conj_commute) + qed + + def t \ "nat_rec (sel 0 0) (\n i. sel (Suc n) i)" + have "subseq t" + unfolding subseq_Suc_iff by (simp add: t_def sel) + moreover have "\i. (f \ t) i \ s" + using f by auto + moreover + { fix n have "(f \ t) n \ F n" + by (cases n) (simp_all add: t_def sel) } + note t = this + + have "Cauchy (f \ t)" + proof (safe intro!: metric_CauchyI exI elim!: nat_approx_posE) + fix r :: real and N n m assume "1 / Suc N < r" "Suc N \ n" "Suc N \ m" + then have "(f \ t) n \ F (Suc N)" "(f \ t) m \ F (Suc N)" "2 * e N < r" + using F_dec t by (auto simp: e_def field_simps real_of_nat_Suc) + with F[of N] obtain x where "dist x ((f \ t) n) < e N" "dist x ((f \ t) m) < e N" + by (auto simp: subset_eq) + with dist_triangle[of "(f \ t) m" "(f \ t) n" x] `2 * e N < r` + show "dist ((f \ t) m) ((f \ t) n) < r" + by (simp add: dist_commute) + qed + + ultimately show "\l\s. \r. subseq r \ (f \ r) ----> l" + using assms unfolding complete_def by blast + qed + qed +qed (metis compact_imp_complete compact_imp_seq_compact seq_compact_imp_totally_bounded) lemma cauchy: "Cauchy s \ (\e>0.\ N::nat. \n\N. dist(s n)(s N) < e)" (is "?lhs = ?rhs") proof- @@ -3462,35 +3571,15 @@ apply(erule_tac x=y in allE) apply(erule_tac x=y in ballE) by auto qed -lemma seq_compact_imp_complete: assumes "seq_compact s" shows "complete s" -proof- - { fix f assume as: "(\n::nat. f n \ s)" "Cauchy f" - from as(1) obtain l r where lr: "l\s" "subseq r" "((f \ r) ---> l) sequentially" using assms unfolding seq_compact_def by blast - - note lr' = seq_suble [OF lr(2)] - - { fix e::real assume "e>0" - from as(2) obtain N where N:"\m n. N \ m \ N \ n \ dist (f m) (f n) < e/2" unfolding cauchy_def using `e>0` apply (erule_tac x="e/2" in allE) by auto - from lr(3)[unfolded LIMSEQ_def, THEN spec[where x="e/2"]] obtain M where M:"\n\M. dist ((f \ r) n) l < e/2" using `e>0` by auto - { fix n::nat assume n:"n \ max N M" - have "dist ((f \ r) n) l < e/2" using n M by auto - moreover have "r n \ N" using lr'[of n] n by auto - hence "dist (f n) ((f \ r) n) < e / 2" using N using n by auto - ultimately have "dist (f n) l < e" using dist_triangle_half_r[of "f (r n)" "f n" e l] by (auto simp add: dist_commute) } - hence "\N. \n\N. dist (f n) l < e" by blast } - hence "\l\s. (f ---> l) sequentially" using `l\s` unfolding LIMSEQ_def by auto } - thus ?thesis unfolding complete_def by auto -qed - instance heine_borel < complete_space proof fix f :: "nat \ 'a" assume "Cauchy f" hence "bounded (range f)" by (rule cauchy_imp_bounded) - hence "seq_compact (closure (range f))" - using bounded_closed_imp_seq_compact [of "closure (range f)"] by auto + hence "compact (closure (range f))" + unfolding compact_eq_bounded_closed by auto hence "complete (closure (range f))" - by (rule seq_compact_imp_complete) + by (rule compact_imp_complete) moreover have "\n. f n \ closure (range f)" using closure_subset [of "range f"] by auto ultimately have "\l\closure (range f). (f ---> l) sequentially" @@ -3543,154 +3632,6 @@ shows "(s ---> l) sequentially \ bounded (range s)" by (intro cauchy_imp_bounded LIMSEQ_imp_Cauchy) -lemma nat_approx_posE: - fixes e::real - assumes "0 < e" - obtains n::nat where "1 / (Suc n) < e" -proof atomize_elim - have " 1 / real (Suc (nat (ceiling (1/e)))) < 1 / (ceiling (1/e))" - by (rule divide_strict_left_mono) (auto intro!: mult_pos_pos simp: `0 < e`) - also have "1 / (ceiling (1/e)) \ 1 / (1/e)" - by (rule divide_left_mono) (auto intro!: divide_pos_pos simp: `0 < e`) - also have "\ = e" by simp - finally show "\n. 1 / real (Suc n) < e" .. -qed - -lemma compact_eq_totally_bounded: - "compact s \ complete s \ (\e>0. \k. finite k \ s \ (\((\x. ball x e) ` k)))" -proof (safe intro!: seq_compact_imp_complete[unfolded compact_eq_seq_compact_metric[symmetric]]) - fix e::real - def f \ "(\x::'a. ball x e) ` UNIV" - assume "0 < e" "compact s" - hence "(\t\f. open t) \ s \ \f \ (\f'\f. finite f' \ s \ \f')" - by (simp add: compact_eq_heine_borel) - moreover - have d0: "\x::'a. dist x x < e" using `0 < e` by simp - hence "(\t\f. open t) \ s \ \f" by (auto simp: f_def intro!: d0) - ultimately have "(\f'\f. finite f' \ s \ \f')" .. - then guess K .. note K = this - have "\K'\K. \k. K' = ball k e" using K by (auto simp: f_def) - then obtain k where "\K'. K' \ K \ K' = ball (k K') e" unfolding bchoice_iff by blast - thus "\k. finite k \ s \ \(\x. ball x e) ` k" using K - by (intro exI[where x="k ` K"]) (auto simp: f_def) -next - assume assms: "complete s" "\e>0. \k. finite k \ s \ \(\x. ball x e) ` k" - show "compact s" - proof cases - assume "s = {}" thus "compact s" by (simp add: compact_def) - next - assume "s \ {}" - show ?thesis - unfolding compact_def - proof safe - fix f::"nat \ _" assume "\n. f n \ s" hence f: "\n. f n \ s" by simp - from assms have "\e. \k. e>0 \ finite k \ s \ (\((\x. ball x e) ` k))" by simp - then obtain K where - K: "\e. e > 0 \ finite (K e) \ s \ (\((\x. ball x e) ` (K e)))" - unfolding choice_iff by blast - { - fix e::real and f' have f': "\n::nat. (f o f') n \ s" using f by auto - assume "e > 0" - from K[OF this] have K: "finite (K e)" "s \ (\((\x. ball x e) ` (K e)))" - by simp_all - have "\k\(K e). \r. subseq r \ (\i. (f o f' o r) i \ ball k e)" - proof (rule ccontr) - from K have "finite (K e)" "K e \ {}" "s \ (\((\x. ball x e) ` (K e)))" - using `s \ {}` - by auto - moreover - assume "\ (\k\K e. \r. subseq r \ (\i. (f \ f' o r) i \ ball k e))" - hence "\r k. k \ K e \ subseq r \ (\i. (f o f' o r) i \ ball k e)" by simp - ultimately - show False using f' - proof (induct arbitrary: s f f' rule: finite_ne_induct) - case (singleton x) - have "\i. (f \ f' o id) i \ ball x e" by (rule singleton) (auto simp: subseq_def) - thus ?case using singleton by (auto simp: ball_def) - next - case (insert x A) - show ?case - proof cases - have inf_ms: "infinite ((f o f') -` s)" using insert by (simp add: vimage_def) - have "infinite ((f o f') -` \((\x. ball x e) ` (insert x A)))" - using insert by (intro infinite_super[OF _ inf_ms]) auto - also have "((f o f') -` \((\x. ball x e) ` (insert x A))) = - {m. (f o f') m \ ball x e} \ {m. (f o f') m \ \((\x. ball x e) ` A)}" by auto - finally have "infinite \" . - moreover assume "finite {m. (f o f') m \ ball x e}" - ultimately have inf: "infinite {m. (f o f') m \ \((\x. ball x e) ` A)}" by blast - hence "A \ {}" by auto then obtain k where "k \ A" by auto - def r \ "enumerate {m. (f o f') m \ \((\x. ball x e) ` A)}" - have r_mono: "\n m. n < m \ r n < r m" - using enumerate_mono[OF _ inf] by (simp add: r_def) - hence "subseq r" by (simp add: subseq_def) - have r_in_set: "\n. r n \ {m. (f o f') m \ \((\x. ball x e) ` A)}" - using enumerate_in_set[OF inf] by (simp add: r_def) - show False - proof (rule insert) - show "\(\x. ball x e) ` A \ \(\x. ball x e) ` A" by simp - fix k s assume "k \ A" "subseq s" - thus "\i. (f o f' o r o s) i \ ball k e" using `subseq r` - by (subst (2) o_assoc[symmetric]) (intro insert(6) subseq_o, simp_all) - next - fix n show "(f \ f' o r) n \ \(\x. ball x e) ` A" using r_in_set by auto - qed - next - assume inf: "infinite {m. (f o f') m \ ball x e}" - def r \ "enumerate {m. (f o f') m \ ball x e}" - have r_mono: "\n m. n < m \ r n < r m" - using enumerate_mono[OF _ inf] by (simp add: r_def) - hence "subseq r" by (simp add: subseq_def) - from insert(6)[OF insertI1 this] obtain i where "(f o f') (r i) \ ball x e" by auto - moreover - have r_in_set: "\n. r n \ {m. (f o f') m \ ball x e}" - using enumerate_in_set[OF inf] by (simp add: r_def) - hence "(f o f') (r i) \ ball x e" by simp - ultimately show False by simp - qed - qed - qed - } - hence ex: "\f'. \e > 0. (\k\K e. \r. subseq r \ (\i. (f o f' \ r) i \ ball k e))" by simp - let ?e = "\n. 1 / real (Suc n)" - let ?P = "\n s. \k\K (?e n). (\i. (f o s) i \ ball k (?e n))" - interpret subseqs ?P using ex by unfold_locales force - from `complete s` have limI: "\f. (\n. f n \ s) \ Cauchy f \ (\l\s. f ----> l)" - by (simp add: complete_def) - have "\l\s. (f o diagseq) ----> l" - proof (intro limI metric_CauchyI) - fix e::real assume "0 < e" hence "0 < e / 2" by auto - from nat_approx_posE[OF this] guess n . note n = this - show "\M. \m\M. \n\M. dist ((f \ diagseq) m) ((f \ diagseq) n) < e" - proof (rule exI[where x="Suc n"], safe) - fix m mm assume "Suc n \ m" "Suc n \ mm" - let ?e = "1 / real (Suc n)" - from reducer_reduces[of n] obtain k where - "k\K ?e" "\i. (f o seqseq (Suc n)) i \ ball k ?e" - unfolding seqseq_reducer by auto - moreover - note diagseq_sub[OF `Suc n \ m`] diagseq_sub[OF `Suc n \ mm`] - ultimately have "{(f o diagseq) m, (f o diagseq) mm} \ ball k ?e" by auto - also have "\ \ ball k (e / 2)" using n by (intro subset_ball) simp - finally - have "dist k ((f \ diagseq) m) + dist k ((f \ diagseq) mm) < e / 2 + e /2" - by (intro add_strict_mono) auto - hence "dist ((f \ diagseq) m) k + dist ((f \ diagseq) mm) k < e" - by (simp add: dist_commute) - moreover have "dist ((f \ diagseq) m) ((f \ diagseq) mm) \ - dist ((f \ diagseq) m) k + dist ((f \ diagseq) mm) k" - by (rule dist_triangle2) - ultimately show "dist ((f \ diagseq) m) ((f \ diagseq) mm) < e" - by simp - qed - next - fix n show "(f o diagseq) n \ s" using f by simp - qed - thus "\l\s. \r. subseq r \ (f \ r) ----> l" using subseq_diagseq by auto - qed - qed -qed - lemma compact_cball[simp]: fixes x :: "'a::heine_borel" shows "compact(cball x e)" diff -r 3e5b67f85bf9 -r 5e3d3d690975 src/HOL/Probability/Projective_Limit.thy --- a/src/HOL/Probability/Projective_Limit.thy Thu Jan 17 15:28:53 2013 -0800 +++ b/src/HOL/Probability/Projective_Limit.thy Fri Jan 18 20:00:59 2013 +0100 @@ -11,7 +11,7 @@ Regularity Projective_Family Infinite_Product_Measure - "~~/src/HOL/Library/Countable_Set" + "~~/src/HOL/Library/Diagonal_Subsequence" begin subsection {* Sequences of Finite Maps in Compact Sets *}