# HG changeset patch # User hoelzl # Date 1452271259 -3600 # Node ID 26c0a70f78a3d4e5f2b10c13df1ee2ca49558de8 # Parent 7a5754afe170fd2216cb2ac213bb9ee0587ee0e6 add uniform spaces diff -r 7a5754afe170 -r 26c0a70f78a3 NEWS --- a/NEWS Fri Jan 08 16:37:56 2016 +0100 +++ b/NEWS Fri Jan 08 17:40:59 2016 +0100 @@ -606,6 +606,14 @@ terms for sup and inf. For example, "sup x (sup y (- x))" simplifies to "top". INCOMPATIBILITY. +* Class uniform_space introduces uniform spaces btw topological spaces +and metric spaces. Minor INCOMPATIBILITY: open__def needs to be +introduced in the form of an uniformity. Some constants are more +general now, it may be necessary to add type class constraints. + + open_real_def \ open_dist + open_complex_def \ open_dist + * Library/Monad_Syntax: notation uses symbols \ and \. INCOMPATIBILITY. * Library/Multiset: diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Complex.thy --- a/src/HOL/Complex.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Complex.thy Fri Jan 08 17:40:59 2016 +0100 @@ -264,8 +264,11 @@ definition dist_complex_def: "dist x y = cmod (x - y)" -definition open_complex_def: - "open (S :: complex set) \ (\x\S. \e>0. \y. dist y x < e \ y \ S)" +definition uniformity_complex_def [code del]: + "(uniformity :: (complex \ complex) filter) = (INF e:{0 <..}. principal {(x, y). dist x y < e})" + +definition open_complex_def [code del]: + "open (U :: complex set) \ (\x\U. eventually (\(x', y). x' = x \ y \ U) uniformity)" instance proof fix r :: real and x y :: complex and S :: "complex set" @@ -277,7 +280,7 @@ by (simp add: norm_complex_def complex_eq_iff power_mult_distrib distrib_left [symmetric] real_sqrt_mult) show "norm (x * y) = norm x * norm y" by (simp add: norm_complex_def complex_eq_iff real_sqrt_mult [symmetric] power2_eq_square algebra_simps) -qed (rule complex_sgn_def dist_complex_def open_complex_def)+ +qed (rule complex_sgn_def dist_complex_def open_complex_def uniformity_complex_def)+ end diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Filter.thy --- a/src/HOL/Filter.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Filter.thy Fri Jan 08 17:40:59 2016 +0100 @@ -529,6 +529,8 @@ unfolding le_filter_def eventually_filtermap by (subst (1 2) eventually_INF) auto qed + + subsubsection \Standard filters\ definition principal :: "'a set \ 'a filter" where @@ -743,6 +745,52 @@ by (blast intro: finite_subset) qed +subsubsection \Product of filters\ + +lemma filtermap_sequentually_ne_bot: "filtermap f sequentially \ bot" + by (auto simp add: filter_eq_iff eventually_filtermap eventually_sequentially) + +definition prod_filter :: "'a filter \ 'b filter \ ('a \ 'b) filter" (infixr "\\<^sub>F" 80) where + "prod_filter F G = + (INF (P, Q):{(P, Q). eventually P F \ eventually Q G}. principal {(x, y). P x \ Q y})" + +lemma eventually_prod_filter: "eventually P (F \\<^sub>F G) \ + (\Pf Pg. eventually Pf F \ eventually Pg G \ (\x y. Pf x \ Pg y \ P (x, y)))" + unfolding prod_filter_def +proof (subst eventually_INF_base, goal_cases) + case 2 + moreover have "eventually Pf F \ eventually Qf F \ eventually Pg G \ eventually Qg G \ + \P Q. eventually P F \ eventually Q G \ + Collect P \ Collect Q \ Collect Pf \ Collect Pg \ Collect Qf \ Collect Qg" for Pf Pg Qf Qg + by (intro conjI exI[of _ "inf Pf Qf"] exI[of _ "inf Pg Qg"]) + (auto simp: inf_fun_def eventually_conj) + ultimately show ?case + by auto +qed (auto simp: eventually_principal intro: eventually_True) + +lemma prod_filter_mono: "F \ F' \ G \ G' \ F \\<^sub>F G \ F' \\<^sub>F G'" + by (auto simp: le_filter_def eventually_prod_filter) + +lemma eventually_prod_same: "eventually P (F \\<^sub>F F) \ + (\Q. eventually Q F \ (\x y. Q x \ Q y \ P (x, y)))" + unfolding eventually_prod_filter + apply safe + apply (rule_tac x="inf Pf Pg" in exI) + apply (auto simp: inf_fun_def intro!: eventually_conj) + done + +lemma eventually_prod_sequentially: + "eventually P (sequentially \\<^sub>F sequentially) \ (\N. \m \ N. \n \ N. P (n, m))" + unfolding eventually_prod_same eventually_sequentially by auto + +lemma principal_prod_principal: "principal A \\<^sub>F principal B = principal (A \ B)" + apply (simp add: filter_eq_iff eventually_prod_filter eventually_principal) + apply safe + apply blast + apply (intro conjI exI[of _ "\x. x \ A"] exI[of _ "\x. x \ B"]) + apply auto + done + subsection \Limits\ definition filterlim :: "('a \ 'b) \ 'b filter \ 'a filter \ bool" where diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Library/Extended_Real.thy --- a/src/HOL/Library/Extended_Real.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Library/Extended_Real.thy Fri Jan 08 17:40:59 2016 +0100 @@ -2769,7 +2769,7 @@ then have "open (ereal -` S)" unfolding open_ereal_def by auto with \x \ S\ obtain r where "0 < r" and dist: "\y. dist y rx < r \ ereal y \ S" - unfolding open_real_def rx by auto + unfolding open_dist rx by auto then obtain n where upper: "\N. n \ N \ u N < x + ereal r" and lower: "\N. n \ N \ x < u N + ereal r" diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Library/Formal_Power_Series.thy --- a/src/HOL/Library/Formal_Power_Series.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Library/Formal_Power_Series.thy Fri Jan 08 17:40:59 2016 +0100 @@ -815,13 +815,14 @@ instantiation fps :: (comm_ring_1) metric_space begin -definition open_fps_def: "open (S :: 'a fps set) = (\a \ S. \r. r >0 \ ball a r \ S)" - +definition uniformity_fps_def [code del]: + "(uniformity :: ('a fps \ 'a fps) filter) = (INF e:{0 <..}. principal {(x, y). dist x y < e})" + +definition open_fps_def' [code del]: + "open (U :: 'a fps set) \ (\x\U. eventually (\(x', y). x' = x \ y \ U) uniformity)" instance proof - show "open S = (\x\S. \e>0. \y. dist y x < e \ y \ S)" for S :: "'a fps set" - by (auto simp add: open_fps_def ball_def subset_eq) show th: "dist a b = 0 \ a = b" for a b :: "'a fps" by (simp add: dist_fps_def split: split_if_asm) then have th'[simp]: "dist a a = 0" for a :: "'a fps" by simp @@ -853,10 +854,12 @@ qed thus ?thesis by (auto simp add: not_le[symmetric]) qed -qed +qed (rule open_fps_def' uniformity_fps_def)+ end +lemma open_fps_def: "open (S :: 'a::comm_ring_1 fps set) = (\a \ S. \r. r >0 \ ball a r \ S)" + unfolding open_dist ball_def subset_eq by simp text \The infinite sums and justification of the notation in textbooks.\ diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Library/Inner_Product.thy --- a/src/HOL/Library/Inner_Product.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Library/Inner_Product.thy Fri Jan 08 17:40:59 2016 +0100 @@ -11,7 +11,7 @@ subsection \Real inner product spaces\ text \ - Temporarily relax type constraints for @{term "open"}, + Temporarily relax type constraints for @{term "open"}, @{term "uniformity"}, @{term dist}, and @{term norm}. \ @@ -22,9 +22,12 @@ (@{const_name dist}, SOME @{typ "'a::dist \ 'a \ real"})\ setup \Sign.add_const_constraint + (@{const_name uniformity}, SOME @{typ "('a::uniformity \ 'a) filter"})\ + +setup \Sign.add_const_constraint (@{const_name norm}, SOME @{typ "'a::norm \ real"})\ -class real_inner = real_vector + sgn_div_norm + dist_norm + open_dist + +class real_inner = real_vector + sgn_div_norm + dist_norm + uniformity_dist + open_uniformity + fixes inner :: "'a \ 'a \ real" assumes inner_commute: "inner x y = inner y x" and inner_add_left: "inner (x + y) z = inner x z + inner y z" @@ -166,7 +169,7 @@ by (metis inner_commute inner_divide_left) text \ - Re-enable constraints for @{term "open"}, + Re-enable constraints for @{term "open"}, @{term "uniformity"}, @{term dist}, and @{term norm}. \ @@ -174,6 +177,9 @@ (@{const_name "open"}, SOME @{typ "'a::topological_space set \ bool"})\ setup \Sign.add_const_constraint + (@{const_name uniformity}, SOME @{typ "('a::uniform_space \ 'a) filter"})\ + +setup \Sign.add_const_constraint (@{const_name dist}, SOME @{typ "'a::metric_space \ 'a \ real"})\ setup \Sign.add_const_constraint diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Library/Product_Vector.thy --- a/src/HOL/Library/Product_Vector.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Library/Product_Vector.thy Fri Jan 08 17:40:59 2016 +0100 @@ -229,9 +229,6 @@ subsubsection \Separation axioms\ -lemma mem_Times_iff: "x \ A \ B \ fst x \ A \ snd x \ B" - by (induct x) simp (* TODO: move elsewhere *) - instance prod :: (t0_space, t0_space) t0_space proof fix x y :: "'a \ 'b" assume "x \ y" @@ -264,12 +261,31 @@ subsection \Product is a metric space\ -instantiation prod :: (metric_space, metric_space) metric_space +(* TODO: Product of uniform spaces and compatibility with metric_spaces! *) + +instantiation prod :: (metric_space, metric_space) dist begin definition dist_prod_def[code del]: "dist x y = sqrt ((dist (fst x) (fst y))\<^sup>2 + (dist (snd x) (snd y))\<^sup>2)" +instance .. +end + +instantiation prod :: (metric_space, metric_space) uniformity_dist +begin + +definition [code del]: + "(uniformity :: (('a \ 'b) \ ('a \ 'b)) filter) = + (INF e:{0 <..}. principal {(x, y). dist x y < e})" + +instance + by standard (rule uniformity_prod_def) +end + +instantiation prod :: (metric_space, metric_space) metric_space +begin + lemma dist_Pair_Pair: "dist (a, b) (c, d) = sqrt ((dist a c)\<^sup>2 + (dist b d)\<^sup>2)" unfolding dist_prod_def by simp @@ -292,7 +308,7 @@ real_sqrt_le_mono add_mono power_mono dist_triangle2 zero_le_dist) next fix S :: "('a \ 'b) set" - show "open S \ (\x\S. \e>0. \y. dist y x < e \ y \ S)" + have *: "open S \ (\x\S. \e>0. \y. dist y x < e \ y \ S)" proof assume "open S" show "\x\S. \e>0. \y. dist y x < e \ y \ S" proof @@ -351,6 +367,9 @@ ultimately show "\A B. open A \ open B \ x \ A \ B \ A \ B \ S" by fast qed qed + show "open S = (\x\S. \\<^sub>F (x', y) in uniformity. x' = x \ y \ S)" + unfolding * eventually_uniformity_metric + by (simp del: split_paired_All add: dist_prod_def dist_commute) qed end diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Limits.thy --- a/src/HOL/Limits.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Limits.thy Fri Jan 08 17:40:59 2016 +0100 @@ -1624,16 +1624,6 @@ using tendsto_mult [OF tendsto_const LIMSEQ_inverse_real_of_nat_add_minus [of 1]] by auto -lemma lim_1_over_n: "((\n. 1 / of_nat n) \ (0::'a::real_normed_field)) sequentially" -proof (subst lim_sequentially, intro allI impI exI) - fix e :: real assume e: "e > 0" - fix n :: nat assume n: "n \ nat \inverse e + 1\" - have "inverse e < of_nat (nat \inverse e + 1\)" by linarith - also note n - finally show "dist (1 / of_nat n :: 'a) 0 < e" using e - by (simp add: divide_simps mult.commute norm_conv_dist[symmetric] norm_divide) -qed - lemma lim_inverse_n: "((\n. inverse(of_nat n)) \ (0::'a::real_normed_field)) sequentially" using lim_1_over_n by (simp add: inverse_eq_divide) @@ -2236,7 +2226,7 @@ then have "x \ \C" using C by auto with C(2) obtain c where "x \ c" "open c" "c \ C" by auto then obtain e where "0 < e" "{x - e <..< x + e} \ c" - by (auto simp: open_real_def dist_real_def subset_eq Ball_def abs_less_iff) + by (auto simp: open_dist dist_real_def subset_eq Ball_def abs_less_iff) with \c \ C\ show ?case by (safe intro!: exI[of _ "e/2"] exI[of _ "{c}"]) auto qed diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Multivariate_Analysis/Bounded_Continuous_Function.thy --- a/src/HOL/Multivariate_Analysis/Bounded_Continuous_Function.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Multivariate_Analysis/Bounded_Continuous_Function.thy Fri Jan 08 17:40:59 2016 +0100 @@ -36,14 +36,18 @@ using Rep_bcontfun[of x] by (auto simp: bcontfun_def intro: continuous_on_subset) +(* TODO: Generalize to uniform spaces? *) instantiation bcontfun :: (topological_space, metric_space) metric_space begin definition dist_bcontfun :: "('a, 'b) bcontfun \ ('a, 'b) bcontfun \ real" where "dist_bcontfun f g = (SUP x. dist (Rep_bcontfun f x) (Rep_bcontfun g x))" +definition uniformity_bcontfun :: "(('a, 'b) bcontfun \ ('a, 'b) bcontfun) filter" + where "uniformity_bcontfun = (INF e:{0 <..}. principal {(x, y). dist x y < e})" + definition open_bcontfun :: "('a, 'b) bcontfun set \ bool" - where "open_bcontfun S = (\x\S. \e>0. \y. dist y x < e \ y \ S)" + where "open_bcontfun S = (\x\S. \\<^sub>F (x', y) in uniformity. x' = x \ y \ S)" lemma dist_bounded: fixes f :: "('a, 'b) bcontfun" @@ -126,7 +130,7 @@ finally show "dist (Rep_bcontfun f x) (Rep_bcontfun g x) \ dist f h + dist g h" by simp qed -qed (simp add: open_bcontfun_def) +qed (rule open_bcontfun_def uniformity_bcontfun_def)+ end diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Multivariate_Analysis/Bounded_Linear_Function.thy --- a/src/HOL/Multivariate_Analysis/Bounded_Linear_Function.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Multivariate_Analysis/Bounded_Linear_Function.thy Fri Jan 08 17:40:59 2016 +0100 @@ -122,8 +122,11 @@ definition dist_blinfun :: "'a \\<^sub>L 'b \ 'a \\<^sub>L 'b \ real" where "dist_blinfun a b = norm (a - b)" +definition [code del]: + "(uniformity :: (('a \\<^sub>L 'b) \ ('a \\<^sub>L 'b)) filter) = (INF e:{0 <..}. principal {(x, y). dist x y < e})" + definition open_blinfun :: "('a \\<^sub>L 'b) set \ bool" - where "open_blinfun S \ (\x\S. \e>0. \y. dist y x < e \ y \ S)" + where [code del]: "open_blinfun S = (\x\S. \\<^sub>F (x', y) in uniformity. x' = x \ y \ S)" lift_definition uminus_blinfun :: "'a \\<^sub>L 'b \ 'a \\<^sub>L 'b" is "\f x. - f x" by (rule bounded_linear_minus) @@ -143,8 +146,8 @@ instance apply standard - unfolding dist_blinfun_def open_blinfun_def sgn_blinfun_def - apply (transfer, force simp: onorm_triangle onorm_scaleR onorm_eq_0 algebra_simps)+ + unfolding dist_blinfun_def open_blinfun_def sgn_blinfun_def uniformity_blinfun_def + apply (rule refl | (transfer, force simp: onorm_triangle onorm_scaleR onorm_eq_0 algebra_simps))+ done end diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Multivariate_Analysis/Cauchy_Integral_Thm.thy --- a/src/HOL/Multivariate_Analysis/Cauchy_Integral_Thm.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Multivariate_Analysis/Cauchy_Integral_Thm.thy Fri Jan 08 17:40:59 2016 +0100 @@ -4106,7 +4106,7 @@ done } then show ?thesis - by (auto simp: Complex.open_complex_def) + by (auto simp: open_dist) qed subsection\Winding number is zero "outside" a curve, in various senses\ diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Multivariate_Analysis/Derivative.thy --- a/src/HOL/Multivariate_Analysis/Derivative.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Multivariate_Analysis/Derivative.thy Fri Jan 08 17:40:59 2016 +0100 @@ -874,8 +874,7 @@ unfolding eventually_at_topological by metis from \open S\ obtain d where d: "\x. dist x y < d \ x \ S" "d > 0" - by (force simp: dist_commute open_real_def ball_def - dest!: bspec[OF _ \y \ S\]) + by (force simp: dist_commute open_dist ball_def dest!: bspec[OF _ \y \ S\]) def d' \ "min ((y + b)/2) (y + (d/2))" have "d' \ A" unfolding A_def @@ -939,8 +938,7 @@ where S: "open S" "y \ S" "\x. x\S \ x \ {y..b} \ ?le x" by metis from \open S\ obtain d where d: "\x. dist x y < d \ x \ S" "d > 0" - by (force simp: dist_commute open_real_def ball_def - dest!: bspec[OF _ \y \ S\]) + by (force simp: dist_commute open_dist ball_def dest!: bspec[OF _ \y \ S\]) def d' \ "min b (y + (d/2))" have "d' \ A" unfolding A_def diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Multivariate_Analysis/Finite_Cartesian_Product.thy --- a/src/HOL/Multivariate_Analysis/Finite_Cartesian_Product.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Multivariate_Analysis/Finite_Cartesian_Product.thy Fri Jan 08 17:40:59 2016 +0100 @@ -142,7 +142,7 @@ instantiation vec :: (topological_space, finite) topological_space begin -definition +definition [code del]: "open (S :: ('a ^ 'b) set) \ (\x\S. \A. (\i. open (A i) \ x$i \ A i) \ (\y. (\i. y$i \ A i) \ y \ S))" @@ -260,13 +260,31 @@ subsection \Metric space\ +(* TODO: Product of uniform spaces and compatibility with metric_spaces! *) -instantiation vec :: (metric_space, finite) metric_space +instantiation vec :: (metric_space, finite) dist begin definition "dist x y = setL2 (\i. dist (x$i) (y$i)) UNIV" +instance .. +end + +instantiation vec :: (metric_space, finite) uniformity_dist +begin + +definition [code del]: + "(uniformity :: (('a, 'b) vec \ ('a, 'b) vec) filter) = + (INF e:{0 <..}. principal {(x, y). dist x y < e})" + +instance + by standard (rule uniformity_vec_def) +end + +instantiation vec :: (metric_space, finite) metric_space +begin + lemma dist_vec_nth_le: "dist (x $ i) (y $ i) \ dist x y" unfolding dist_vec_def by (rule member_le_setL2) simp_all @@ -284,7 +302,7 @@ done next fix S :: "('a ^ 'b) set" - show "open S \ (\x\S. \e>0. \y. dist y x < e \ y \ S)" + have *: "open S \ (\x\S. \e>0. \y. dist y x < e \ y \ S)" proof assume "open S" show "\x\S. \e>0. \y. dist y x < e \ y \ S" proof @@ -322,6 +340,9 @@ (\y. (\i. y $ i \ A i) \ y \ S)" by metis qed qed + show "open S = (\x\S. \\<^sub>F (x', y) in uniformity. x' = x \ y \ S)" + unfolding * eventually_uniformity_metric + by (simp del: split_paired_All add: dist_vec_def dist_commute) qed end diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy --- a/src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy Fri Jan 08 17:40:59 2016 +0100 @@ -13,7 +13,6 @@ "~~/src/HOL/Library/FuncSet" Linear_Algebra Norm_Arith - begin lemma image_affinity_interval: @@ -4573,20 +4572,19 @@ subsubsection \Completeness\ -definition complete :: "'a::metric_space set \ bool" - where "complete s \ (\f. (\n. f n \ s) \ Cauchy f \ (\l\s. f \ l))" - -lemma completeI: +lemma (in metric_space) completeI: assumes "\f. \n. f n \ s \ Cauchy f \ \l\s. f \ l" shows "complete s" using assms unfolding complete_def by fast -lemma completeE: +lemma (in metric_space) completeE: assumes "complete s" and "\n. f n \ s" and "Cauchy f" obtains l where "l \ s" and "f \ l" using assms unfolding complete_def by fast +(* TODO: generalize to uniform spaces *) lemma compact_imp_complete: + fixes s :: "'a::metric_space set" assumes "compact s" shows "complete s" proof - @@ -4816,6 +4814,7 @@ qed lemma complete_imp_closed: + fixes s :: "'a::metric_space set" assumes "complete s" shows "closed s" proof (unfold closed_sequential_limits, clarify) @@ -4831,6 +4830,7 @@ qed lemma complete_inter_closed: + fixes s :: "'a::metric_space set" assumes "complete s" and "closed t" shows "complete (s \ t)" proof (rule completeI) @@ -4846,6 +4846,7 @@ qed lemma complete_closed_subset: + fixes s :: "'a::metric_space set" assumes "closed s" and "s \ t" and "complete t" shows "complete s" using assms complete_inter_closed [of t s] by (simp add: Int_absorb1) @@ -5225,9 +5226,13 @@ unfolding continuous_on_def Lim_within by (metis dist_pos_lt dist_self) -definition uniformly_continuous_on :: "'a set \ ('a::metric_space \ 'b::metric_space) \ bool" - where "uniformly_continuous_on s f \ +lemma uniformly_continuous_on_def: + fixes f :: "'a::metric_space \ 'b::metric_space" + shows "uniformly_continuous_on s f \ (\e>0. \d>0. \x\s. \x'\s. dist x' x < d \ dist (f x') (f x) < e)" + unfolding uniformly_continuous_on_uniformity + uniformity_dist filterlim_INF filterlim_principal eventually_inf_principal + by (force simp: Ball_def uniformity_dist[symmetric] eventually_uniformity_metric) text\Some simple consequential lemmas.\ @@ -5242,10 +5247,6 @@ using assms by (auto simp: uniformly_continuous_on_def) -lemma uniformly_continuous_imp_continuous: - "uniformly_continuous_on s f \ continuous_on s f" - unfolding uniformly_continuous_on_def continuous_on_iff by blast - lemma continuous_at_imp_continuous_within: "continuous (at x) f \ continuous (at x within s) f" unfolding continuous_within continuous_at using Lim_at_imp_Lim_at_within by auto @@ -5331,8 +5332,7 @@ lemma uniformly_continuous_on_sequentially: "uniformly_continuous_on s f \ (\x y. (\n. x n \ s) \ (\n. y n \ s) \ - ((\n. dist (x n) (y n)) \ 0) sequentially - \ ((\n. dist (f(x n)) (f(y n))) \ 0) sequentially)" (is "?lhs = ?rhs") + (\n. dist (x n) (y n)) \ 0 \ (\n. dist (f(x n)) (f(y n))) \ 0)" (is "?lhs = ?rhs") proof assume ?lhs { @@ -5421,7 +5421,7 @@ using assms unfolding continuous_within by (force simp add: intro: Lim_transform_within) - + subsubsection \Structural rules for pointwise continuity\ @@ -5462,14 +5462,6 @@ subsubsection \Structural rules for uniform continuity\ -lemma uniformly_continuous_on_id[continuous_intros]: - "uniformly_continuous_on s (\x. x)" - unfolding uniformly_continuous_on_def by auto - -lemma uniformly_continuous_on_const[continuous_intros]: - "uniformly_continuous_on s (\x. c)" - unfolding uniformly_continuous_on_def by simp - lemma uniformly_continuous_on_dist[continuous_intros]: fixes f g :: "'a::metric_space \ 'b::metric_space" assumes "uniformly_continuous_on s f" @@ -5497,12 +5489,14 @@ qed lemma uniformly_continuous_on_norm[continuous_intros]: + fixes f :: "'a :: metric_space \ 'b :: real_normed_vector" assumes "uniformly_continuous_on s f" shows "uniformly_continuous_on s (\x. norm (f x))" unfolding norm_conv_dist using assms by (intro uniformly_continuous_on_dist uniformly_continuous_on_const) lemma (in bounded_linear) uniformly_continuous_on[continuous_intros]: + fixes g :: "_::metric_space \ _" assumes "uniformly_continuous_on s g" shows "uniformly_continuous_on s (\x. f (g x))" using assms unfolding uniformly_continuous_on_sequentially @@ -5544,30 +5538,9 @@ using assms uniformly_continuous_on_add [of s f "- g"] by (simp add: fun_Compl_def uniformly_continuous_on_minus) -text\Continuity of all kinds is preserved under composition.\ - lemmas continuous_at_compose = isCont_o -lemma uniformly_continuous_on_compose[continuous_intros]: - assumes "uniformly_continuous_on s f" "uniformly_continuous_on (f ` s) g" - shows "uniformly_continuous_on s (g \ f)" -proof - - { - fix e :: real - assume "e > 0" - then obtain d where "d > 0" - and d: "\x\f ` s. \x'\f ` s. dist x' x < d \ dist (g x') (g x) < e" - using assms(2) unfolding uniformly_continuous_on_def by auto - obtain d' where "d'>0" "\x\s. \x'\s. dist x' x < d' \ dist (f x') (f x) < d" - using \d > 0\ using assms(1) unfolding uniformly_continuous_on_def by auto - then have "\d>0. \x\s. \x'\s. dist x' x < d \ dist ((g \ f) x') ((g \ f) x) < e" - using \d>0\ using d by auto - } - then show ?thesis - using assms unfolding uniformly_continuous_on_def by auto -qed - -text\Continuity in terms of open preimages.\ +text \Continuity in terms of open preimages.\ lemma continuous_at_open: "continuous (at x) f \ (\t. open t \ f x \ t --> (\s. open s \ x \ s \ (\x' \ s. (f x') \ t)))" @@ -6124,6 +6097,7 @@ text \Continuity implies uniform continuity on a compact domain.\ lemma compact_uniformly_continuous: + fixes f :: "'a :: metric_space \ 'b :: metric_space" assumes f: "continuous_on s f" and s: "compact s" shows "uniformly_continuous_on s f" diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Probability/Discrete_Topology.thy --- a/src/HOL/Probability/Discrete_Topology.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Probability/Discrete_Topology.thy Fri Jan 08 17:40:59 2016 +0100 @@ -12,24 +12,24 @@ morphisms of_discrete discrete .. -instantiation discrete :: (type) topological_space -begin - -definition open_discrete::"'a discrete set \ bool" - where "open_discrete s = True" - -instance proof qed (auto simp: open_discrete_def) -end - instantiation discrete :: (type) metric_space begin -definition dist_discrete::"'a discrete \ 'a discrete \ real" +definition dist_discrete :: "'a discrete \ 'a discrete \ real" where "dist_discrete n m = (if n = m then 0 else 1)" -instance proof qed (auto simp: open_discrete_def dist_discrete_def intro: exI[where x=1]) +definition uniformity_discrete :: "('a discrete \ 'a discrete) filter" where + "(uniformity::('a discrete \ 'a discrete) filter) = (INF e:{0 <..}. principal {(x, y). dist x y < e})" + +definition "open_discrete" :: "'a discrete set \ bool" where + "(open::'a discrete set \ bool) U \ (\x\U. eventually (\(x', y). x' = x \ y \ U) uniformity)" + +instance proof qed (auto simp: uniformity_discrete_def open_discrete_def dist_discrete_def intro: exI[where x=1]) end +lemma open_discrete: "open (S :: 'a discrete set)" + unfolding open_dist dist_discrete_def by (auto intro!: exI[of _ "1 / 2"]) + instance discrete :: (type) complete_space proof fix X::"nat\'a discrete" assume "Cauchy X" @@ -54,7 +54,7 @@ have "\S. generate_topology ?B (\x\S. {x})" by (intro generate_topology_Union) (auto intro: generate_topology.intros) then have "open = generate_topology ?B" - by (auto intro!: ext simp: open_discrete_def) + by (auto intro!: ext simp: open_discrete) moreover have "countable ?B" by simp ultimately show "\B::'a discrete set set. countable B \ open = generate_topology B" by blast qed diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Probability/Fin_Map.thy --- a/src/HOL/Probability/Fin_Map.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Probability/Fin_Map.thy Fri Jan 08 17:40:59 2016 +0100 @@ -150,7 +150,7 @@ begin definition open_finmap :: "('a \\<^sub>F 'b) set \ bool" where - "open_finmap = generate_topology {Pi' a b|a b. \i\a. open (b i)}" + [code del]: "open_finmap = generate_topology {Pi' a b|a b. \i\a. open (b i)}" lemma open_Pi'I: "(\i. i \ I \ open (A i)) \ open (Pi' I A)" by (auto intro: generate_topology.Basis simp: open_finmap_def) @@ -254,12 +254,31 @@ subsection \Metric Space of Finite Maps\ -instantiation finmap :: (type, metric_space) metric_space +(* TODO: Product of uniform spaces and compatibility with metric_spaces! *) + +instantiation finmap :: (type, metric_space) dist begin definition dist_finmap where "dist P Q = Max (range (\i. dist ((P)\<^sub>F i) ((Q)\<^sub>F i))) + (if domain P = domain Q then 0 else 1)" +instance .. +end + +instantiation finmap :: (type, metric_space) uniformity_dist +begin + +definition [code del]: + "(uniformity :: (('a, 'b) finmap \ ('a, 'b) finmap) filter) = + (INF e:{0 <..}. principal {(x, y). dist x y < e})" + +instance + by standard (rule uniformity_finmap_def) +end + +instantiation finmap :: (type, metric_space) metric_space +begin + lemma finite_proj_image': "x \ domain P \ finite ((P)\<^sub>F ` S)" by (rule finite_subset[of _ "proj P ` (domain P \ S \ {x})"]) auto @@ -308,7 +327,7 @@ instance proof fix S::"('a \\<^sub>F 'b) set" - show "open S = (\x\S. \e>0. \y. dist y x < e \ y \ S)" (is "_ = ?od") + have *: "open S = (\x\S. \e>0. \y. dist y x < e \ y \ S)" (is "_ = ?od") proof assume "open S" thus ?od @@ -387,6 +406,9 @@ by (intro generate_topology.UN) (auto intro: generate_topology.Basis) finally show "open S" . qed + show "open S = (\x\S. \\<^sub>F (x', y) in uniformity. x' = x \ y \ S)" + unfolding * eventually_uniformity_metric + by (simp del: split_paired_All add: dist_finmap_def dist_commute eq_commute) next fix P Q::"'a \\<^sub>F 'b" have Max_eq_iff: "\A m. finite A \ A \ {} \ (Max A = m) = (m \ A \ (\a\A. a \ m))" diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Product_Type.thy --- a/src/HOL/Product_Type.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Product_Type.thy Fri Jan 08 17:40:59 2016 +0100 @@ -1068,6 +1068,9 @@ lemma mem_Sigma_iff [iff]: "((a,b): Sigma A B) = (a:A & b:B(a))" by blast +lemma mem_Times_iff: "x \ A \ B \ fst x \ A \ snd x \ B" + by (induct x) simp + lemma Sigma_empty_iff: "(SIGMA i:I. X i) = {} \ (\i\I. X i = {})" by auto diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Real_Vector_Spaces.thy --- a/src/HOL/Real_Vector_Spaces.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Real_Vector_Spaces.thy Fri Jan 08 17:40:59 2016 +0100 @@ -191,7 +191,7 @@ fixes x :: "'a::real_vector" shows "scaleR (-1) x = - x" using scaleR_minus_left [of 1 x] by simp - + class real_algebra = real_vector + ring + assumes mult_scaleR_left [simp]: "scaleR a x * y = scaleR a (x * y)" and mult_scaleR_right [simp]: "x * scaleR a y = scaleR a (x * y)" @@ -662,10 +662,19 @@ class dist_norm = dist + norm + minus + assumes dist_norm: "dist x y = norm (x - y)" -class open_dist = "open" + dist + - assumes open_dist: "open S \ (\x\S. \e>0. \y. dist y x < e \ y \ S)" +class uniformity_dist = dist + uniformity + + assumes uniformity_dist: "uniformity = (INF e:{0 <..}. principal {(x, y). dist x y < e})" +begin -class real_normed_vector = real_vector + sgn_div_norm + dist_norm + open_dist + +lemma eventually_uniformity_metric: + "eventually P uniformity \ (\e>0. \x y. dist x y < e \ P (x, y))" + unfolding uniformity_dist + by (subst eventually_INF_base) + (auto simp: eventually_principal subset_eq intro: bexI[of _ "min _ _"]) + +end + +class real_normed_vector = real_vector + sgn_div_norm + dist_norm + uniformity_dist + open_uniformity + assumes norm_eq_zero [simp]: "norm x = 0 \ x = 0" and norm_triangle_ineq: "norm (x + y) \ norm x + norm y" and norm_scaleR [simp]: "norm (scaleR a x) = \a\ * norm x" @@ -686,8 +695,8 @@ class real_normed_algebra_1 = real_algebra_1 + real_normed_algebra + assumes norm_one [simp]: "norm 1 = 1" - -lemma (in real_normed_algebra_1) scaleR_power [simp]: + +lemma (in real_normed_algebra_1) scaleR_power [simp]: "(scaleR x y) ^ n = scaleR (x^n) (y^n)" by (induction n) (simp_all add: scaleR_one scaleR_scaleR mult_ac) @@ -1010,7 +1019,7 @@ subsection \Metric spaces\ -class metric_space = open_dist + +class metric_space = uniformity_dist + open_uniformity + assumes dist_eq_0_iff [simp]: "dist x y = 0 \ x = y" assumes dist_triangle2: "dist x y \ dist x z + dist y z" begin @@ -1074,26 +1083,23 @@ shows "dist y x1 < e / 2 \ dist y x2 < e / 2 \ dist x1 x2 < e" by (rule dist_triangle_half_l, simp_all add: dist_commute) -subclass topological_space +subclass uniform_space proof - have "\e::real. 0 < e" - by (blast intro: zero_less_one) - then show "open UNIV" - unfolding open_dist by simp -next - fix S T assume "open S" "open T" - then show "open (S \ T)" - unfolding open_dist - apply clarify - apply (drule (1) bspec)+ - apply (clarify, rename_tac r s) - apply (rule_tac x="min r s" in exI, simp) - done -next - fix K assume "\S\K. open S" thus "open (\K)" - unfolding open_dist by (meson UnionE UnionI) + fix E x assume "eventually E uniformity" + then obtain e where E: "0 < e" "\x y. dist x y < e \ E (x, y)" + unfolding eventually_uniformity_metric by auto + then show "E (x, x)" "\\<^sub>F (x, y) in uniformity. E (y, x)" + unfolding eventually_uniformity_metric by (auto simp: dist_commute) + + show "\D. eventually D uniformity \ (\x y z. D (x, y) \ D (y, z) \ E (x, z))" + using E dist_triangle_half_l[where e=e] unfolding eventually_uniformity_metric + by (intro exI[of _ "\(x, y). dist x y < e / 2"] exI[of _ "e/2"] conjI) + (auto simp: dist_commute) qed +lemma open_dist: "open S \ (\x\S. \e>0. \y. dist y x < e \ y \ S)" + unfolding open_uniformity eventually_uniformity_metric by (simp add: dist_commute) + lemma open_ball: "open {y. dist x y < d}" proof (unfold open_dist, intro ballI) fix y assume *: "y \ {y. dist x y < d}" @@ -1156,8 +1162,11 @@ definition dist_real_def: "dist x y = \x - y\" +definition uniformity_real_def [code del]: + "(uniformity :: (real \ real) filter) = (INF e:{0 <..}. principal {(x, y). dist x y < e})" + definition open_real_def [code del]: - "open (S :: real set) \ (\x\S. \e>0. \y. dist y x < e \ y \ S)" + "open (U :: real set) \ (\x\U. eventually (\(x', y). x' = x \ y \ U) uniformity)" definition real_norm_def [simp]: "norm r = \r\" @@ -1165,8 +1174,9 @@ instance apply (intro_classes, unfold real_norm_def real_scaleR_def) apply (rule dist_real_def) +apply (simp add: sgn_real_def) +apply (rule uniformity_real_def) apply (rule open_real_def) -apply (simp add: sgn_real_def) apply (rule abs_eq_0) apply (rule abs_triangle_ineq) apply (rule abs_mult) @@ -1188,7 +1198,7 @@ proof (rule ext, safe) fix S :: "real set" assume "open S" then obtain f where "\x\S. 0 < f x \ (\y. dist y x < f x \ y \ S)" - unfolding open_real_def bchoice_iff .. + unfolding open_dist bchoice_iff .. then have *: "S = (\x\S. {x - f x <..} \ {..< x + f x})" by (fastforce simp: dist_real_def) show "generate_topology (range lessThan \ range greaterThan) S" @@ -1199,14 +1209,14 @@ next fix S :: "real set" assume "generate_topology (range lessThan \ range greaterThan) S" moreover have "\a::real. open {.. (\y. \y - x\ < a - x \ y \ {..e>0. \y. \y - x\ < e \ y \ {..a::real. open {a <..}" - unfolding open_real_def dist_real_def + unfolding open_dist dist_real_def proof clarify fix x a :: real assume "a < x" hence "0 < x - a \ (\y. \y - x\ < x - a \ y \ {a<..})" by auto @@ -1233,6 +1243,11 @@ setup \Sign.add_const_constraint (@{const_name "open"}, SOME @{typ "'a::topological_space set \ bool"})\ +text \Only allow @{term "uniformity"} in class \uniform_space\.\ + +setup \Sign.add_const_constraint + (@{const_name "uniformity"}, SOME @{typ "('a::uniformity \ 'a) filter"})\ + text \Only allow @{term dist} in class \metric_space\.\ setup \Sign.add_const_constraint @@ -1786,10 +1801,22 @@ subsection \Cauchy sequences\ -definition (in metric_space) Cauchy :: "(nat \ 'a) \ bool" where - "Cauchy X = (\e>0. \M. \m \ M. \n \ M. dist (X m) (X n) < e)" +lemma (in metric_space) Cauchy_def: "Cauchy X = (\e>0. \M. \m\M. \n\M. dist (X m) (X n) < e)" +proof - + have *: "eventually P (INF M. principal {(X m, X n) | n m. m \ M \ n \ M}) = + (\M. \m\M. \n\M. P (X m, X n))" for P + proof (subst eventually_INF_base, goal_cases) + case (2 a b) then show ?case + by (intro bexI[of _ "max a b"]) (auto simp: eventually_principal subset_eq) + qed (auto simp: eventually_principal, blast) + have "Cauchy X \ (INF M. principal {(X m, X n) | n m. m \ M \ n \ M}) \ uniformity" + unfolding Cauchy_uniform_iff le_filter_def * .. + also have "\ = (\e>0. \M. \m\M. \n\M. dist (X m) (X n) < e)" + unfolding uniformity_dist le_INF_iff by (auto simp: * le_principal) + finally show ?thesis . +qed -lemma Cauchy_altdef: +lemma (in metric_space) Cauchy_altdef: "Cauchy f = (\e>0. \M. \m\M. \n>m. dist (f m) (f n) < e)" proof assume A: "\e>0. \M. \m\M. \n>m. dist (f m) (f n) < e" @@ -1812,18 +1839,18 @@ qed qed -lemma metric_CauchyI: +lemma (in metric_space) metric_CauchyI: "(\e. 0 < e \ \M. \m\M. \n\M. dist (X m) (X n) < e) \ Cauchy X" by (simp add: Cauchy_def) -lemma CauchyI': "(\e. 0 < e \ \M. \m\M. \n>m. dist (X m) (X n) < e) \ Cauchy X" +lemma (in metric_space) CauchyI': "(\e. 0 < e \ \M. \m\M. \n>m. dist (X m) (X n) < e) \ Cauchy X" unfolding Cauchy_altdef by blast -lemma metric_CauchyD: +lemma (in metric_space) metric_CauchyD: "Cauchy X \ 0 < e \ \M. \m\M. \n\M. dist (X m) (X n) < e" by (simp add: Cauchy_def) -lemma metric_Cauchy_iff2: +lemma (in metric_space) metric_Cauchy_iff2: "Cauchy X = (\j. (\M. \m \ M. \n \ M. dist (X m) (X n) < inverse(real (Suc j))))" apply (simp add: Cauchy_def, auto) apply (drule reals_Archimedean, safe) @@ -1837,40 +1864,118 @@ "Cauchy X = (\j. (\M. \m \ M. \n \ M. \X m - X n\ < inverse(real (Suc j))))" unfolding metric_Cauchy_iff2 dist_real_def .. -lemma Cauchy_subseq_Cauchy: - "\ Cauchy X; subseq f \ \ Cauchy (X o f)" -apply (auto simp add: Cauchy_def) -apply (drule_tac x=e in spec, clarify) -apply (rule_tac x=M in exI, clarify) -apply (blast intro: le_trans [OF _ seq_suble] dest!: spec) -done - -theorem LIMSEQ_imp_Cauchy: - assumes X: "X \ a" shows "Cauchy X" -proof (rule metric_CauchyI) - fix e::real assume "0 < e" - hence "0 < e/2" by simp - with X have "\N. \n\N. dist (X n) a < e/2" by (rule metric_LIMSEQ_D) - then obtain N where N: "\n\N. dist (X n) a < e/2" .. - show "\N. \m\N. \n\N. dist (X m) (X n) < e" - proof (intro exI allI impI) - fix m assume "N \ m" - hence m: "dist (X m) a < e/2" using N by blast - fix n assume "N \ n" - hence n: "dist (X n) a < e/2" using N by blast - have "dist (X m) (X n) \ dist (X m) a + dist (X n) a" - by (rule dist_triangle2) - also from m n have "\ < e" by simp - finally show "dist (X m) (X n) < e" . - qed +lemma lim_1_over_n: "((\n. 1 / of_nat n) \ (0::'a::real_normed_field)) sequentially" +proof (subst lim_sequentially, intro allI impI exI) + fix e :: real assume e: "e > 0" + fix n :: nat assume n: "n \ nat \inverse e + 1\" + have "inverse e < of_nat (nat \inverse e + 1\)" by linarith + also note n + finally show "dist (1 / of_nat n :: 'a) 0 < e" using e + by (simp add: divide_simps mult.commute norm_conv_dist[symmetric] norm_divide) qed -lemma convergent_Cauchy: "convergent X \ Cauchy X" -unfolding convergent_def -by (erule exE, erule LIMSEQ_imp_Cauchy) +lemma (in metric_space) complete_def: + shows "complete S = (\f. (\n. f n \ S) \ Cauchy f \ (\l\S. f \ l))" + unfolding complete_uniform +proof safe + fix f :: "nat \ 'a" assume f: "\n. f n \ S" "Cauchy f" + and *: "\F\principal S. F \ bot \ cauchy_filter F \ (\x\S. F \ nhds x)" + then show "\l\S. f \ l" + unfolding filterlim_def using f + by (intro *[rule_format]) + (auto simp: filtermap_sequentually_ne_bot le_principal eventually_filtermap Cauchy_uniform) +next + fix F :: "'a filter" assume "F \ principal S" "F \ bot" "cauchy_filter F" + assume seq: "\f. (\n. f n \ S) \ Cauchy f \ (\l\S. f \ l)" + + from \F \ principal S\ \cauchy_filter F\ have FF_le: "F \\<^sub>F F \ uniformity_on S" + by (simp add: cauchy_filter_def principal_prod_principal[symmetric] prod_filter_mono) + + let ?P = "\P e. eventually P F \ (\x. P x \ x \ S) \ (\x y. P x \ P y \ dist x y < e)" + + { fix \ :: real assume "0 < \" + then have "eventually (\(x, y). x \ S \ y \ S \ dist x y < \) (uniformity_on S)" + unfolding eventually_inf_principal eventually_uniformity_metric by auto + from filter_leD[OF FF_le this] have "\P. ?P P \" + unfolding eventually_prod_same by auto } + note P = this + + have "\P. \n. ?P (P n) (1 / Suc n) \ P (Suc n) \ P n" + proof (rule dependent_nat_choice) + show "\P. ?P P (1 / Suc 0)" + using P[of 1] by auto + next + fix P n assume "?P P (1/Suc n)" + moreover obtain Q where "?P Q (1 / Suc (Suc n))" + using P[of "1/Suc (Suc n)"] by auto + ultimately show "\Q. ?P Q (1 / Suc (Suc n)) \ Q \ P" + by (intro exI[of _ "\x. P x \ Q x"]) (auto simp: eventually_conj_iff) + qed + then obtain P where P: "\n. eventually (P n) F" "\n x. P n x \ x \ S" + "\n x y. P n x \ P n y \ dist x y < 1 / Suc n" "\n. P (Suc n) \ P n" + by metis + have "antimono P" + using P(4) unfolding decseq_Suc_iff le_fun_def by blast + + obtain X where X: "\n. P n (X n)" + using P(1)[THEN eventually_happens'[OF \F \ bot\]] by metis + have "Cauchy X" + unfolding metric_Cauchy_iff2 inverse_eq_divide + proof (intro exI allI impI) + fix j m n :: nat assume "j \ m" "j \ n" + with \antimono P\ X have "P j (X m)" "P j (X n)" + by (auto simp: antimono_def) + then show "dist (X m) (X n) < 1 / Suc j" + by (rule P) + qed + moreover have "\n. X n \ S" + using P(2) X by auto + ultimately obtain x where "X \ x" "x \ S" + using seq by blast + + show "\x\S. F \ nhds x" + proof (rule bexI) + { fix e :: real assume "0 < e" + then have "(\n. 1 / Suc n :: real) \ 0 \ 0 < e / 2" + by (subst LIMSEQ_Suc_iff) (auto intro!: lim_1_over_n) + then have "\\<^sub>F n in sequentially. dist (X n) x < e / 2 \ 1 / Suc n < e / 2" + using \X \ x\ unfolding tendsto_iff order_tendsto_iff[where 'a=real] eventually_conj_iff by blast + then obtain n where "dist x (X n) < e / 2" "1 / Suc n < e / 2" + by (auto simp: eventually_sequentially dist_commute) + have "eventually (\y. dist y x < e) F" + using \eventually (P n) F\ + proof eventually_elim + fix y assume "P n y" + then have "dist y (X n) < 1 / Suc n" + by (intro X P) + also have "\ < e / 2" by fact + finally show "dist y x < e" + by (rule dist_triangle_half_l) fact + qed } + then show "F \ nhds x" + unfolding nhds_metric le_INF_iff le_principal by auto + qed fact +qed + +lemma (in metric_space) totally_bounded_metric: + "totally_bounded S \ (\e>0. \k. finite k \ S \ (\x\k. {y. dist x y < e}))" + unfolding totally_bounded_def eventually_uniformity_metric imp_ex + apply (subst all_comm) + apply (intro arg_cong[where f=All] ext) + apply safe + subgoal for e + apply (erule allE[of _ "\(x, y). dist x y < e"]) + apply auto + done + subgoal for e P k + apply (intro exI[of _ k]) + apply (force simp: subset_eq) + done + done subsubsection \Cauchy Sequences are Convergent\ +(* TODO: update to uniform_space *) class complete_space = metric_space + assumes Cauchy_convergent: "Cauchy X \ convergent X" diff -r 7a5754afe170 -r 26c0a70f78a3 src/HOL/Topological_Spaces.thy --- a/src/HOL/Topological_Spaces.thy Fri Jan 08 16:37:56 2016 +0100 +++ b/src/HOL/Topological_Spaces.thy Fri Jan 08 17:40:59 2016 +0100 @@ -11,7 +11,6 @@ named_theorems continuous_intros "structural introduction rules for continuity" - subsection \Topological space\ class "open" = @@ -693,8 +692,6 @@ by (rule tendsto_le [OF F tendsto_const x a]) - - subsubsection \Rules about @{const Lim}\ lemma tendsto_Lim: @@ -2435,4 +2432,173 @@ qed qed (intro cSUP_least \antimono f\[THEN antimonoD] cInf_lower S) +subsection \Uniform spaces\ + +class uniformity = + fixes uniformity :: "('a \ 'a) filter" +begin + +abbreviation uniformity_on :: "'a set \ ('a \ 'a) filter" where + "uniformity_on s \ inf uniformity (principal (s\s))" + end + +class open_uniformity = "open" + uniformity + + assumes open_uniformity: "\U. open U \ (\x\U. eventually (\(x', y). x' = x \ y \ U) uniformity)" + +class uniform_space = open_uniformity + + assumes uniformity_refl: "eventually E uniformity \ E (x, x)" + assumes uniformity_sym: "eventually E uniformity \ eventually (\(x, y). E (y, x)) uniformity" + assumes uniformity_trans: "eventually E uniformity \ \D. eventually D uniformity \ (\x y z. D (x, y) \ D (y, z) \ E (x, z))" +begin + +subclass topological_space + proof qed (force elim: eventually_mono eventually_elim2 simp: split_beta' open_uniformity)+ + +lemma uniformity_bot: "uniformity \ bot" + using uniformity_refl by auto + +lemma uniformity_trans': + "eventually E uniformity \ eventually (\((x, y), (y', z)). y = y' \ E (x, z)) (uniformity \\<^sub>F uniformity)" + by (drule uniformity_trans) (auto simp add: eventually_prod_same) + +lemma uniformity_transE: + assumes E: "eventually E uniformity" + obtains D where "eventually D uniformity" "\x y z. D (x, y) \ D (y, z) \ E (x, z)" + using uniformity_trans[OF E] by auto + +lemma eventually_nhds_uniformity: + "eventually P (nhds x) \ eventually (\(x', y). x' = x \ P y) uniformity" (is "_ \ ?N P x") + unfolding eventually_nhds +proof safe + assume *: "?N P x" + { fix x assume "?N P x" + then guess D by (rule uniformity_transE) note D = this + from D(1) have "?N (?N P) x" + by eventually_elim (insert D, force elim: eventually_mono split: prod.split) } + then have "open {x. ?N P x}" + by (simp add: open_uniformity) + then show "\S. open S \ x \ S \ (\x\S. P x)" + by (intro exI[of _ "{x. ?N P x}"]) (auto dest: uniformity_refl simp: *) +qed (force simp add: open_uniformity elim: eventually_mono) + +subsubsection \Totally bounded sets\ + +definition totally_bounded :: "'a set \ bool" where + "totally_bounded S \ + (\E. eventually E uniformity \ (\X. finite X \ (\s\S. \x\X. E (x, s))))" + +lemma totally_bounded_empty[iff]: "totally_bounded {}" + by (auto simp add: totally_bounded_def) + +lemma totally_bounded_subset: "totally_bounded S \ T \ S \ totally_bounded T" + by (force simp add: totally_bounded_def) + +lemma totally_bounded_Union[intro]: + assumes M: "finite M" "\S. S \ M \ totally_bounded S" shows "totally_bounded (\M)" + unfolding totally_bounded_def +proof safe + fix E assume "eventually E uniformity" + with M obtain X where "\S\M. finite (X S) \ (\s\S. \x\X S. E (x, s))" + by (metis totally_bounded_def) + with `finite M` show "\X. finite X \ (\s\\M. \x\X. E (x, s))" + by (intro exI[of _ "\S\M. X S"]) force +qed + +subsubsection \Cauchy filter\ + +definition cauchy_filter :: "'a filter \ bool" where + "cauchy_filter F \ F \\<^sub>F F \ uniformity" + +definition Cauchy :: "(nat \ 'a) \ bool" where + Cauchy_uniform: "Cauchy X = cauchy_filter (filtermap X sequentially)" + +lemma Cauchy_uniform_iff: + "Cauchy X \ (\P. eventually P uniformity \ (\N. \n\N. \m\N. P (X n, X m)))" + unfolding Cauchy_uniform cauchy_filter_def le_filter_def eventually_prod_same + eventually_filtermap eventually_sequentially +proof safe + let ?U = "\P. eventually P uniformity" + { fix P assume "?U P" "\P. ?U P \ (\Q. (\N. \n\N. Q (X n)) \ (\x y. Q x \ Q y \ P (x, y)))" + then obtain Q N where "\n. n \ N \ Q (X n)" "\x y. Q x \ Q y \ P (x, y)" + by metis + then show "\N. \n\N. \m\N. P (X n, X m)" + by blast } + { fix P assume "?U P" and P: "\P. ?U P \ (\N. \n\N. \m\N. P (X n, X m))" + then obtain Q where "?U Q" and Q: "\x y z. Q (x, y) \ Q (y, z) \ P (x, z)" + by (auto elim: uniformity_transE) + then have "?U (\x. Q x \ (\(x, y). Q (y, x)) x)" + unfolding eventually_conj_iff by (simp add: uniformity_sym) + from P[rule_format, OF this] + obtain N where N: "\n m. n \ N \ m \ N \ Q (X n, X m) \ Q (X m, X n)" + by auto + show "\Q. (\N. \n\N. Q (X n)) \ (\x y. Q x \ Q y \ P (x, y))" + proof (safe intro!: exI[of _ "\x. \n\N. Q (x, X n) \ Q (X n, x)"] exI[of _ N] N) + fix x y assume "\n\N. Q (x, X n) \ Q (X n, x)" "\n\N. Q (y, X n) \ Q (X n, y)" + then have "Q (x, X N)" "Q (X N, y)" by auto + then show "P (x, y)" + by (rule Q) + qed } +qed + +lemma nhds_imp_cauchy_filter: + assumes *: "F \ nhds x" shows "cauchy_filter F" +proof - + have "F \\<^sub>F F \ nhds x \\<^sub>F nhds x" + by (intro prod_filter_mono *) + also have "\ \ uniformity" + unfolding le_filter_def eventually_nhds_uniformity eventually_prod_same + proof safe + fix P assume "eventually P uniformity" + then guess Ql by (rule uniformity_transE) note Ql = this + moreover note Ql(1)[THEN uniformity_sym] + ultimately show "\Q. eventually (\(x', y). x' = x \ Q y) uniformity \ (\x y. Q x \ Q y \ P (x, y))" + by (rule_tac exI[of _ "\y. Ql (y, x) \ Ql (x, y)"]) (fastforce elim: eventually_elim2) + qed + finally show ?thesis + by (simp add: cauchy_filter_def) +qed + +lemma LIMSEQ_imp_Cauchy: "X \ x \ Cauchy X" + unfolding Cauchy_uniform filterlim_def by (intro nhds_imp_cauchy_filter) + +lemma Cauchy_subseq_Cauchy: assumes "Cauchy X" "subseq f" shows "Cauchy (X \ f)" + unfolding Cauchy_uniform comp_def filtermap_filtermap[symmetric] cauchy_filter_def + by (rule order_trans[OF _ \Cauchy X\[unfolded Cauchy_uniform cauchy_filter_def]]) + (intro prod_filter_mono filtermap_mono filterlim_subseq[OF \subseq f\, unfolded filterlim_def]) + +lemma convergent_Cauchy: "convergent X \ Cauchy X" + unfolding convergent_def by (erule exE, erule LIMSEQ_imp_Cauchy) + +definition complete :: "'a set \ bool" where + complete_uniform: "complete S \ (\F \ principal S. F \ bot \ cauchy_filter F \ (\x\S. F \ nhds x))" + +end + +subsubsection \Uniformly continuous functions\ + +definition uniformly_continuous_on :: "'a set \ ('a::uniform_space \ 'b::uniform_space) \ bool" where + uniformly_continuous_on_uniformity: "uniformly_continuous_on s f \ + (LIM (x, y) (uniformity_on s). (f x, f y) :> uniformity)" + +lemma uniformly_continuous_onD: + "uniformly_continuous_on s f \ eventually E uniformity + \ eventually (\(x, y). x \ s \ y \ s \ E (f x, f y)) uniformity" + by (simp add: uniformly_continuous_on_uniformity filterlim_iff eventually_inf_principal split_beta' mem_Times_iff imp_conjL) + +lemma uniformly_continuous_on_const[continuous_intros]: "uniformly_continuous_on s (\x. c)" + by (auto simp: uniformly_continuous_on_uniformity filterlim_iff uniformity_refl) + +lemma uniformly_continuous_on_id[continuous_intros]: "uniformly_continuous_on s (\x. x)" + by (auto simp: uniformly_continuous_on_uniformity filterlim_def) + +lemma uniformly_continuous_on_compose[continuous_intros]: + "uniformly_continuous_on s g \ uniformly_continuous_on (g`s) f \ uniformly_continuous_on s (\x. f (g x))" + using filterlim_compose[of "\(x, y). (f x, f y)" uniformity "uniformity_on (g`s)" "\(x, y). (g x, g y)" "uniformity_on s"] + by (simp add: split_beta' uniformly_continuous_on_uniformity filterlim_inf filterlim_principal eventually_inf_principal mem_Times_iff) + +lemma uniformly_continuous_imp_continuous: assumes f: "uniformly_continuous_on s f" shows "continuous_on s f" + by (auto simp: filterlim_iff eventually_at_filter eventually_nhds_uniformity continuous_on_def + elim: eventually_mono dest!: uniformly_continuous_onD[OF f]) + +end