src/HOL/Analysis/Elementary_Metric_Spaces.thy
changeset 70960 84f79d82df0a
parent 70951 678b2abe9f7d
child 71028 c2465b429e6e
equal deleted inserted replaced
70959:ba0b65d45aec 70960:84f79d82df0a
    82 
    82 
    83 lemma mem_cball_leI: "x \<in> cball y e \<Longrightarrow> e \<le> f \<Longrightarrow> x \<in> cball y f"
    83 lemma mem_cball_leI: "x \<in> cball y e \<Longrightarrow> e \<le> f \<Longrightarrow> x \<in> cball y f"
    84   by (auto simp: mem_ball mem_cball)
    84   by (auto simp: mem_ball mem_cball)
    85 
    85 
    86 lemma cball_trans: "y \<in> cball z b \<Longrightarrow> x \<in> cball y a \<Longrightarrow> x \<in> cball z (b + a)"
    86 lemma cball_trans: "y \<in> cball z b \<Longrightarrow> x \<in> cball y a \<Longrightarrow> x \<in> cball z (b + a)"
    87   unfolding mem_cball
    87   by metric
    88 proof -
       
    89   have "dist z x \<le> dist z y + dist y x"
       
    90     by (rule dist_triangle)
       
    91   also assume "dist z y \<le> b"
       
    92   also assume "dist y x \<le> a"
       
    93   finally show "dist z x \<le> b + a" by arith
       
    94 qed
       
    95 
    88 
    96 lemma ball_max_Un: "ball a (max r s) = ball a r \<union> ball a s"
    89 lemma ball_max_Un: "ball a (max r s) = ball a r \<union> ball a s"
    97   by (simp add: set_eq_iff) arith
    90   by (simp add: set_eq_iff) arith
    98 
    91 
    99 lemma ball_min_Int: "ball a (min r s) = ball a r \<inter> ball a s"
    92 lemma ball_min_Int: "ball a (min r s) = ball a r \<inter> ball a s"
   131 lemma open_contains_ball_eq: "open S \<Longrightarrow> x\<in>S \<longleftrightarrow> (\<exists>e>0. ball x e \<subseteq> S)"
   124 lemma open_contains_ball_eq: "open S \<Longrightarrow> x\<in>S \<longleftrightarrow> (\<exists>e>0. ball x e \<subseteq> S)"
   132   by (metis open_contains_ball subset_eq centre_in_ball)
   125   by (metis open_contains_ball subset_eq centre_in_ball)
   133 
   126 
   134 lemma ball_eq_empty[simp]: "ball x e = {} \<longleftrightarrow> e \<le> 0"
   127 lemma ball_eq_empty[simp]: "ball x e = {} \<longleftrightarrow> e \<le> 0"
   135   unfolding mem_ball set_eq_iff
   128   unfolding mem_ball set_eq_iff
   136   apply (simp add: not_less)
   129   by (simp add: not_less) metric
   137   apply (metis zero_le_dist order_trans dist_self)
       
   138   done
       
   139 
   130 
   140 lemma ball_empty: "e \<le> 0 \<Longrightarrow> ball x e = {}" by simp
   131 lemma ball_empty: "e \<le> 0 \<Longrightarrow> ball x e = {}" by simp
   141 
   132 
   142 lemma closed_cball [iff]: "closed (cball x e)"
   133 lemma closed_cball [iff]: "closed (cball x e)"
   143 proof -
   134 proof -
   249   apply (clarsimp simp add: islimpt_approachable)
   240   apply (clarsimp simp add: islimpt_approachable)
   250   apply (drule_tac x="e/2" in spec)
   241   apply (drule_tac x="e/2" in spec)
   251   apply (auto simp: simp del: less_divide_eq_numeral1)
   242   apply (auto simp: simp del: less_divide_eq_numeral1)
   252   apply (drule_tac x="dist x' x" in spec)
   243   apply (drule_tac x="dist x' x" in spec)
   253   apply (auto simp: zero_less_dist_iff simp del: less_divide_eq_numeral1)
   244   apply (auto simp: zero_less_dist_iff simp del: less_divide_eq_numeral1)
   254   apply (erule rev_bexI)
   245   apply metric
   255   apply (metis dist_commute dist_triangle_half_r less_trans less_irrefl)
       
   256   done
   246   done
   257 
   247 
   258 lemma closed_limpts:  "closed {x::'a::metric_space. x islimpt S}"
   248 lemma closed_limpts:  "closed {x::'a::metric_space. x islimpt S}"
   259   using closed_limpt limpt_of_limpts by blast
   249   using closed_limpt limpt_of_limpts by blast
   260 
   250 
   343   have False if C: "\<And>e. e>0 \<Longrightarrow> \<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e" for x
   333   have False if C: "\<And>e. e>0 \<Longrightarrow> \<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e" for x
   344   proof -
   334   proof -
   345     from e have e2: "e/2 > 0" by arith
   335     from e have e2: "e/2 > 0" by arith
   346     from C[rule_format, OF e2] obtain y where y: "y \<in> S" "y \<noteq> x" "dist y x < e/2"
   336     from C[rule_format, OF e2] obtain y where y: "y \<in> S" "y \<noteq> x" "dist y x < e/2"
   347       by blast
   337       by blast
   348     let ?m = "min (e/2) (dist x y) "
   338     from e2 y(2) have mp: "min (e/2) (dist x y) > 0"
   349     from e2 y(2) have mp: "?m > 0"
       
   350       by simp
   339       by simp
   351     from C[OF mp] obtain z where z: "z \<in> S" "z \<noteq> x" "dist z x < ?m"
   340     from d y C[OF mp] show ?thesis
   352       by blast
   341       by metric
   353     from z y have "dist z y < e"
       
   354       by (intro dist_triangle_lt [where z=x]) simp
       
   355     from d[rule_format, OF y(1) z(1) this] y z show ?thesis
       
   356       by (auto simp: dist_commute)
       
   357   qed
   342   qed
   358   then show ?thesis
   343   then show ?thesis
   359     by (metis islimpt_approachable closed_limpt [where 'a='a])
   344     by (metis islimpt_approachable closed_limpt [where 'a='a])
   360 qed
   345 qed
   361 
   346 
   540     {
   525     {
   541       fix y
   526       fix y
   542       assume "y \<in> f ` (ball x d \<inter> s)"
   527       assume "y \<in> f ` (ball x d \<inter> s)"
   543       then have "y \<in> ball (f x) e"
   528       then have "y \<in> ball (f x) e"
   544         using d(2)
   529         using d(2)
   545         apply (auto simp: dist_commute)
       
   546         apply (erule_tac x=xa in ballE, auto)
       
   547         using \<open>e > 0\<close>
   530         using \<open>e > 0\<close>
   548         apply auto
   531         by (auto simp: dist_commute)
   549         done
       
   550     }
   532     }
   551     then have "\<exists>d>0. f ` (ball x d \<inter> s) \<subseteq> ball (f x) e"
   533     then have "\<exists>d>0. f ` (ball x d \<inter> s) \<subseteq> ball (f x) e"
   552       using \<open>d > 0\<close>
   534       using \<open>d > 0\<close>
   553       unfolding subset_eq ball_def by (auto simp: dist_commute)
   535       unfolding subset_eq ball_def by (auto simp: dist_commute)
   554   }
   536   }
   831   by (meson bounded_ball bounded_subset)
   813   by (meson bounded_ball bounded_subset)
   832 
   814 
   833 lemma bounded_subset_ballD:
   815 lemma bounded_subset_ballD:
   834   assumes "bounded S" shows "\<exists>r. 0 < r \<and> S \<subseteq> ball x r"
   816   assumes "bounded S" shows "\<exists>r. 0 < r \<and> S \<subseteq> ball x r"
   835 proof -
   817 proof -
   836   obtain e::real and y where "S \<subseteq> cball y e"  "0 \<le> e"
   818   obtain e::real and y where "S \<subseteq> cball y e" "0 \<le> e"
   837     using assms by (auto simp: bounded_subset_cball)
   819     using assms by (auto simp: bounded_subset_cball)
   838   then show ?thesis
   820   then show ?thesis
   839     apply (rule_tac x="dist x y + e + 1" in exI)
   821     by (intro exI[where x="dist x y + e + 1"]) metric
   840     apply (simp add: add.commute add_pos_nonneg)
       
   841     apply (erule subset_trans)
       
   842     apply (clarsimp simp add: cball_def)
       
   843     by (metis add_le_cancel_right add_strict_increasing dist_commute dist_triangle_le zero_less_one)
       
   844 qed
   822 qed
   845 
   823 
   846 lemma finite_imp_bounded [intro]: "finite S \<Longrightarrow> bounded S"
   824 lemma finite_imp_bounded [intro]: "finite S \<Longrightarrow> bounded S"
   847   by (induct set: finite) simp_all
   825   by (induct set: finite) simp_all
   848 
   826 
   858 proof -
   836 proof -
   859   from assms obtain M1 M2 where *: "dist (f x) undefined \<le> M1" "dist undefined (g x) \<le> M2" if "x \<in> S" for x
   837   from assms obtain M1 M2 where *: "dist (f x) undefined \<le> M1" "dist undefined (g x) \<le> M2" if "x \<in> S" for x
   860     by (auto simp: bounded_any_center[of _ undefined] dist_commute)
   838     by (auto simp: bounded_any_center[of _ undefined] dist_commute)
   861   have "dist (f x) (g x) \<le> M1 + M2" if "x \<in> S" for x
   839   have "dist (f x) (g x) \<le> M1 + M2" if "x \<in> S" for x
   862     using *[OF that]
   840     using *[OF that]
   863     by (rule order_trans[OF dist_triangle add_mono])
   841     by metric
   864   then show ?thesis
   842   then show ?thesis
   865     by (auto intro!: boundedI)
   843     by (auto intro!: boundedI)
   866 qed
   844 qed
   867 
   845 
   868 lemma bounded_Times:
   846 lemma bounded_Times:
  1407       then obtain x where "x \<in> S0" and x: "y \<in> ball x (r x)"
  1385       then obtain x where "x \<in> S0" and x: "y \<in> ball x (r x)"
  1408         using \<open>S \<subseteq> \<Union>\<T>\<close> S0 that by blast
  1386         using \<open>S \<subseteq> \<Union>\<T>\<close> S0 that by blast
  1409       have "ball y \<delta> \<subseteq> ball y (r x)"
  1387       have "ball y \<delta> \<subseteq> ball y (r x)"
  1410         by (metis \<delta>_def \<open>S0 \<noteq> {}\<close> \<open>finite S0\<close> \<open>x \<in> S0\<close> empty_is_image finite_imageI finite_less_Inf_iff imageI less_irrefl not_le subset_ball)
  1388         by (metis \<delta>_def \<open>S0 \<noteq> {}\<close> \<open>finite S0\<close> \<open>x \<in> S0\<close> empty_is_image finite_imageI finite_less_Inf_iff imageI less_irrefl not_le subset_ball)
  1411       also have "... \<subseteq> ball x (2*r x)"
  1389       also have "... \<subseteq> ball x (2*r x)"
  1412         by clarsimp (metis dist_commute dist_triangle_less_add mem_ball mult_2 x)
  1390         using x by metric
  1413       finally obtain C where "C \<in> \<C>" "ball y \<delta> \<subseteq> C"
  1391       finally obtain C where "C \<in> \<C>" "ball y \<delta> \<subseteq> C"
  1414         by (meson r \<open>S0 \<subseteq> S\<close> \<open>x \<in> S0\<close> dual_order.trans subsetCE)
  1392         by (meson r \<open>S0 \<subseteq> S\<close> \<open>x \<in> S0\<close> dual_order.trans subsetCE)
  1415       have "bounded T"
  1393       have "bounded T"
  1416         using \<open>compact S\<close> bounded_subset compact_imp_bounded \<open>T \<subseteq> S\<close> by blast
  1394         using \<open>compact S\<close> bounded_subset compact_imp_bounded \<open>T \<subseteq> S\<close> by blast
  1417       then have "T \<subseteq> ball y \<delta>"
  1395       then have "T \<subseteq> ball y \<delta>"
  1634           using n M by auto
  1612           using n M by auto
  1635         moreover have "r n \<ge> N"
  1613         moreover have "r n \<ge> N"
  1636           using lr'[of n] n by auto
  1614           using lr'[of n] n by auto
  1637         then have "dist (f n) ((f \<circ> r) n) < e / 2"
  1615         then have "dist (f n) ((f \<circ> r) n) < e / 2"
  1638           using N and n by auto
  1616           using N and n by auto
  1639         ultimately have "dist (f n) l < e"
  1617         ultimately have "dist (f n) l < e" using n M
  1640           using dist_triangle_half_r[of "f (r n)" "f n" e l]
  1618           by metric
  1641           by (auto simp: dist_commute)
       
  1642       }
  1619       }
  1643       then have "\<exists>N. \<forall>n\<ge>N. dist (f n) l < e" by blast
  1620       then have "\<exists>N. \<forall>n\<ge>N. dist (f n) l < e" by blast
  1644     }
  1621     }
  1645     then have "\<exists>l\<in>s. (f \<longlongrightarrow> l) sequentially" using \<open>l\<in>s\<close>
  1622     then have "\<exists>l\<in>s. (f \<longlongrightarrow> l) sequentially" using \<open>l\<in>s\<close>
  1646       unfolding lim_sequentially by auto
  1623       unfolding lim_sequentially by auto
  1727         assume "1 / Suc N < r" "Suc N \<le> n" "Suc N \<le> m"
  1704         assume "1 / Suc N < r" "Suc N \<le> n" "Suc N \<le> m"
  1728         then have "(f \<circ> t) n \<in> F (Suc N)" "(f \<circ> t) m \<in> F (Suc N)" "2 * e N < r"
  1705         then have "(f \<circ> t) n \<in> F (Suc N)" "(f \<circ> t) m \<in> F (Suc N)" "2 * e N < r"
  1729           using F_dec t by (auto simp: e_def field_simps of_nat_Suc)
  1706           using F_dec t by (auto simp: e_def field_simps of_nat_Suc)
  1730         with F[of N] obtain x where "dist x ((f \<circ> t) n) < e N" "dist x ((f \<circ> t) m) < e N"
  1707         with F[of N] obtain x where "dist x ((f \<circ> t) n) < e N" "dist x ((f \<circ> t) m) < e N"
  1731           by (auto simp: subset_eq)
  1708           by (auto simp: subset_eq)
  1732         with dist_triangle[of "(f \<circ> t) m" "(f \<circ> t) n" x] \<open>2 * e N < r\<close>
  1709         with \<open>2 * e N < r\<close> show "dist ((f \<circ> t) m) ((f \<circ> t) n) < r"
  1733         show "dist ((f \<circ> t) m) ((f \<circ> t) n) < r"
  1710           by metric
  1734           by (simp add: dist_commute)
       
  1735       qed
  1711       qed
  1736 
  1712 
  1737       ultimately show "\<exists>l\<in>s. \<exists>r. strict_mono r \<and> (f \<circ> r) \<longlonglongrightarrow> l"
  1713       ultimately show "\<exists>l\<in>s. \<exists>r. strict_mono r \<and> (f \<circ> r) \<longlonglongrightarrow> l"
  1738         using assms unfolding complete_def by blast
  1714         using assms unfolding complete_def by blast
  1739     qed
  1715     qed
  2148 
  2124 
  2149     have "(ball x ((infdist x T)/2)) \<inter> (ball y ((infdist y S)/2)) = {}" if "x \<in> S" "y \<in> T" for x y
  2125     have "(ball x ((infdist x T)/2)) \<inter> (ball y ((infdist y S)/2)) = {}" if "x \<in> S" "y \<in> T" for x y
  2150     proof (auto)
  2126     proof (auto)
  2151       fix z assume H: "dist x z * 2 < infdist x T" "dist y z * 2 < infdist y S"
  2127       fix z assume H: "dist x z * 2 < infdist x T" "dist y z * 2 < infdist y S"
  2152       have "2 * dist x y \<le> 2 * dist x z + 2 * dist y z"
  2128       have "2 * dist x y \<le> 2 * dist x z + 2 * dist y z"
  2153         using dist_triangle[of x y z] by (auto simp add: dist_commute)
  2129         by metric
  2154       also have "... < infdist x T + infdist y S"
  2130       also have "... < infdist x T + infdist y S"
  2155         using H by auto
  2131         using H by auto
  2156       finally have "dist x y < infdist x T \<or> dist x y < infdist y S"
  2132       finally have "dist x y < infdist x T \<or> dist x y < infdist y S"
  2157         by auto
  2133         by auto
  2158       then show False
  2134       then show False
  2206   moreover
  2182   moreover
  2207   from assms obtain x0 b where b: "\<And>x. x \<in> A \<Longrightarrow> dist x0 x \<le> b" "closed A"
  2183   from assms obtain x0 b where b: "\<And>x. x \<in> A \<Longrightarrow> dist x0 x \<le> b" "closed A"
  2208     by (auto simp: compact_eq_bounded_closed bounded_def)
  2184     by (auto simp: compact_eq_bounded_closed bounded_def)
  2209   {
  2185   {
  2210     fix y
  2186     fix y
  2211     assume le: "infdist y A \<le> e"
  2187     assume "infdist y A \<le> e"
       
  2188     moreover
  2212     from infdist_attains_inf[OF \<open>closed A\<close> \<open>A \<noteq> {}\<close>, of y]
  2189     from infdist_attains_inf[OF \<open>closed A\<close> \<open>A \<noteq> {}\<close>, of y]
  2213     obtain z where z: "z \<in> A" "infdist y A = dist y z" by blast
  2190     obtain z where "z \<in> A" "infdist y A = dist y z" by blast
  2214     have "dist x0 y \<le> dist y z + dist x0 z"
  2191     ultimately
  2215       by (metis dist_commute dist_triangle)
  2192     have "dist x0 y \<le> b + e" using b by metric
  2216     also have "dist y z \<le> e" using le z by simp
       
  2217     also have "dist x0 z \<le> b" using b z by simp
       
  2218     finally have "dist x0 y \<le> b + e" by arith
       
  2219   } then
  2193   } then
  2220   have "bounded {x. infdist x A \<le> e}"
  2194   have "bounded {x. infdist x A \<le> e}"
  2221     by (auto simp: bounded_any_center[where a=x0] intro!: exI[where x="b + e"])
  2195     by (auto simp: bounded_any_center[where a=x0] intro!: exI[where x="b + e"])
  2222   ultimately show "compact {x. infdist x A \<le> e}"
  2196   ultimately show "compact {x. infdist x A \<le> e}"
  2223     by (simp add: compact_eq_bounded_closed)
  2197     by (simp add: compact_eq_bounded_closed)
  2432       using N2 \<open>0 < e\<close> by (simp add: field_simps)
  2406       using N2 \<open>0 < e\<close> by (simp add: field_simps)
  2433     finally have "dist (f (r (max N1 N2))) x < e / 2" .
  2407     finally have "dist (f (r (max N1 N2))) x < e / 2" .
  2434     moreover have "dist (f (r (max N1 N2))) l < e/2"
  2408     moreover have "dist (f (r (max N1 N2))) l < e/2"
  2435       using N1 max.cobounded1 by blast
  2409       using N1 max.cobounded1 by blast
  2436     ultimately have "dist x l < e"
  2410     ultimately have "dist x l < e"
  2437       using dist_triangle_half_r by blast
  2411       by metric
  2438     then show ?thesis
  2412     then show ?thesis
  2439       using e \<open>x \<notin> G\<close> by blast
  2413       using e \<open>x \<notin> G\<close> by blast
  2440   qed
  2414   qed
  2441   then show ?thesis
  2415   then show ?thesis
  2442     by (meson that)
  2416     by (meson that)
  2512         using R [of y "e/2"] \<open>0 < e\<close> y by auto
  2486         using R [of y "e/2"] \<open>0 < e\<close> y by auto
  2513       obtain z where "z \<in> S" and z: "dist z y < min \<delta>' \<delta> / 2"
  2487       obtain z where "z \<in> S" and z: "dist z y < min \<delta>' \<delta> / 2"
  2514         using closure_approachable y
  2488         using closure_approachable y
  2515         by (metis \<open>0 < \<delta>'\<close> \<open>0 < \<delta>\<close> divide_pos_pos min_less_iff_conj zero_less_numeral)
  2489         by (metis \<open>0 < \<delta>'\<close> \<open>0 < \<delta>\<close> divide_pos_pos min_less_iff_conj zero_less_numeral)
  2516       have "dist (f z) (f y) < e/2"
  2490       have "dist (f z) (f y) < e/2"
  2517         apply (rule \<delta>' [OF \<open>z \<in> S\<close>])
  2491         using \<delta>' [OF \<open>z \<in> S\<close>] z \<open>0 < \<delta>'\<close> by metric
  2518         using z \<open>0 < \<delta>'\<close> by linarith
       
  2519       moreover have "dist (f z) (f x) < e/2"
  2492       moreover have "dist (f z) (f x) < e/2"
  2520         apply (rule \<delta> [OF \<open>z \<in> S\<close>])
  2493         using \<delta>[OF \<open>z \<in> S\<close>] z dyx by metric
  2521         using z \<open>0 < \<delta>\<close>  dist_commute[of y z] dist_triangle_half_r [of y] dyx by auto
       
  2522       ultimately show ?thesis
  2494       ultimately show ?thesis
  2523         by (metis dist_commute dist_triangle_half_l less_imp_le)
  2495         by metric
  2524     qed
  2496     qed
  2525     then show "\<exists>d>0. \<forall>x'\<in>closure S. dist x' x < d \<longrightarrow> dist (f x') (f x) \<le> e"
  2497     then show "\<exists>d>0. \<forall>x'\<in>closure S. dist x' x < d \<longrightarrow> dist (f x') (f x) \<le> e"
  2526       by (rule_tac x="\<delta>/2" in exI) (simp add: \<open>\<delta> > 0\<close>)
  2498       by (rule_tac x="\<delta>/2" in exI) (simp add: \<open>\<delta> > 0\<close>)
  2527   qed
  2499   qed
  2528 qed
  2500 qed
  2566         using closure_approachable [of x S]
  2538         using closure_approachable [of x S]
  2567         by (metis \<open>0 < d1\<close> \<open>0 < d\<close> divide_pos_pos min_less_iff_conj x zero_less_numeral)
  2539         by (metis \<open>0 < d1\<close> \<open>0 < d\<close> divide_pos_pos min_less_iff_conj x zero_less_numeral)
  2568     obtain d2::real where "d2 > 0"
  2540     obtain d2::real where "d2 > 0"
  2569            and d2: "\<forall>w \<in> closure S. dist w y < d2 \<longrightarrow> dist (f w) (f y) < e/3"
  2541            and d2: "\<forall>w \<in> closure S. dist w y < d2 \<longrightarrow> dist (f w) (f y) < e/3"
  2570       using cont [unfolded continuous_on_iff, rule_format, of "y" "e/3"] \<open>0 < e\<close> y by auto
  2542       using cont [unfolded continuous_on_iff, rule_format, of "y" "e/3"] \<open>0 < e\<close> y by auto
  2571      obtain y' where "y' \<in> S" and y': "dist y' y < min d2 (d / 3)"
  2543     obtain y' where "y' \<in> S" and y': "dist y' y < min d2 (d / 3)"
  2572         using closure_approachable [of y S]
  2544       using closure_approachable [of y S]
  2573         by (metis \<open>0 < d2\<close> \<open>0 < d\<close> divide_pos_pos min_less_iff_conj y zero_less_numeral)
  2545       by (metis \<open>0 < d2\<close> \<open>0 < d\<close> divide_pos_pos min_less_iff_conj y zero_less_numeral)
  2574      have "dist x' x < d/3" using x' by auto
  2546     have "dist x' x < d/3" using x' by auto
  2575      moreover have "dist x y < d/3"
  2547     then have "dist x' y' < d"
  2576        by (metis dist_commute dyx less_divide_eq_numeral1(1))
  2548       using dyx y' by metric
  2577      moreover have "dist y y' < d/3"
  2549     then have "dist (f x') (f y') < e/3"
  2578        by (metis (no_types) dist_commute min_less_iff_conj y')
  2550       by (rule d [OF \<open>y' \<in> S\<close> \<open>x' \<in> S\<close>])
  2579      ultimately have "dist x' y' < d/3 + d/3 + d/3"
  2551     moreover have "dist (f x') (f x) < e/3" using \<open>x' \<in> S\<close> closure_subset x' d1
  2580        by (meson dist_commute_lessI dist_triangle_lt add_strict_mono)
  2552       by (simp add: closure_def)
  2581      then have "dist x' y' < d" by simp
  2553     moreover have "dist (f y') (f y) < e/3" using \<open>y' \<in> S\<close> closure_subset y' d2
  2582      then have "dist (f x') (f y') < e/3"
  2554       by (simp add: closure_def)
  2583        by (rule d [OF \<open>y' \<in> S\<close> \<open>x' \<in> S\<close>])
  2555     ultimately show "dist (f y) (f x) < e" by metric
  2584      moreover have "dist (f x') (f x) < e/3" using \<open>x' \<in> S\<close> closure_subset x' d1
       
  2585        by (simp add: closure_def)
       
  2586      moreover have "dist (f y') (f y) < e/3" using \<open>y' \<in> S\<close> closure_subset y' d2
       
  2587        by (simp add: closure_def)
       
  2588      ultimately have "dist (f y) (f x) < e/3 + e/3 + e/3"
       
  2589        by (meson dist_commute_lessI dist_triangle_lt add_strict_mono)
       
  2590     then show "dist (f y) (f x) < e" by simp
       
  2591   qed
  2556   qed
  2592 qed
  2557 qed
  2593 
  2558 
  2594 lemma uniformly_continuous_on_extension_at_closure:
  2559 lemma uniformly_continuous_on_extension_at_closure:
  2595   fixes f::"'a::metric_space \<Rightarrow> 'b::complete_space"
  2560   fixes f::"'a::metric_space \<Rightarrow> 'b::complete_space"
  2632       ultimately
  2597       ultimately
  2633       show "\<forall>\<^sub>F n in sequentially. dist (f (xs' n)) l < e"
  2598       show "\<forall>\<^sub>F n in sequentially. dist (f (xs' n)) l < e"
  2634       proof eventually_elim
  2599       proof eventually_elim
  2635         case (elim n)
  2600         case (elim n)
  2636         have "dist (f (xs' n)) l \<le> dist (f (xs n)) (f (xs' n)) + dist (f (xs n)) l"
  2601         have "dist (f (xs' n)) l \<le> dist (f (xs n)) (f (xs' n)) + dist (f (xs n)) l"
  2637           by (metis dist_triangle dist_commute)
  2602           by metric
  2638         also have "dist (f (xs n)) (f (xs' n)) < e'"
  2603         also have "dist (f (xs n)) (f (xs' n)) < e'"
  2639           by (auto intro!: d xs \<open>xs' _ \<in> _\<close> elim)
  2604           by (auto intro!: d xs \<open>xs' _ \<in> _\<close> elim)
  2640         also note \<open>dist (f (xs n)) l < e'\<close>
  2605         also note \<open>dist (f (xs n)) l < e'\<close>
  2641         also have "e' + e' = e" by (simp add: e'_def)
  2606         also have "e' + e' = e" by (simp add: e'_def)
  2642         finally show ?case by simp
  2607         finally show ?case by simp
  2697         case (elim n)
  2662         case (elim n)
  2698         have "dist (?g x') (?g x) \<le>
  2663         have "dist (?g x') (?g x) \<le>
  2699           dist (f (xs' n)) (?g x') + dist (f (xs' n)) (f (xs n)) + dist (f (xs n)) (?g x)"
  2664           dist (f (xs' n)) (?g x') + dist (f (xs' n)) (f (xs n)) + dist (f (xs n)) (?g x)"
  2700           by (metis add.commute add_le_cancel_left dist_commute dist_triangle dist_triangle_le)
  2665           by (metis add.commute add_le_cancel_left dist_commute dist_triangle dist_triangle_le)
  2701         also
  2666         also
  2702         {
  2667         from \<open>dist (xs' n) x' < d'\<close> \<open>dist x' x < d'\<close> \<open>dist (xs n) x < d'\<close>
  2703           have "dist (xs' n) (xs n) \<le> dist (xs' n) x' + dist x' x + dist (xs n) x"
  2668         have "dist (xs' n) (xs n) < d" unfolding d'_def by metric
  2704             by (metis add.commute add_le_cancel_left  dist_triangle dist_triangle_le)
       
  2705           also note \<open>dist (xs' n) x' < d'\<close>
       
  2706           also note \<open>dist x' x < d'\<close>
       
  2707           also note \<open>dist (xs n) x < d'\<close>
       
  2708           finally have "dist (xs' n) (xs n) < d" by (simp add: d'_def)
       
  2709         }
       
  2710         with \<open>xs _ \<in> X\<close> \<open>xs' _ \<in> X\<close> have "dist (f (xs' n)) (f (xs n)) < e'"
  2669         with \<open>xs _ \<in> X\<close> \<open>xs' _ \<in> X\<close> have "dist (f (xs' n)) (f (xs n)) < e'"
  2711           by (rule d)
  2670           by (rule d)
  2712         also note \<open>dist (f (xs' n)) (?g x') < e'\<close>
  2671         also note \<open>dist (f (xs' n)) (?g x') < e'\<close>
  2713         also note \<open>dist (f (xs n)) (?g x) < e'\<close>
  2672         also note \<open>dist (f (xs n)) (?g x) < e'\<close>
  2714         finally show ?case by (simp add: e'_def)
  2673         finally show ?case by (simp add: e'_def)