src/HOL/Library/Topology_Euclidean_Space.thy
changeset 31558 e7a282113145
parent 31537 feec2711da4e
child 31559 ca9e56897403
equal deleted inserted replaced
31538:16068eb224c0 31558:e7a282113145
  1243   shows "((\<lambda>x. h (f x)) ---> h l) net"
  1243   shows "((\<lambda>x. h (f x)) ---> h l) net"
  1244 using `linear h` `(f ---> l) net`
  1244 using `linear h` `(f ---> l) net`
  1245 unfolding linear_conv_bounded_linear
  1245 unfolding linear_conv_bounded_linear
  1246 by (rule bounded_linear.tendsto)
  1246 by (rule bounded_linear.tendsto)
  1247 
  1247 
       
  1248 lemma Lim_ident_at: "((\<lambda>x. x) ---> a) (at a)"
       
  1249   unfolding tendsto_def Limits.eventually_at_topological by fast
       
  1250 
  1248 lemma Lim_const: "((\<lambda>x. a) ---> a) net"
  1251 lemma Lim_const: "((\<lambda>x. a) ---> a) net"
  1249   by (rule tendsto_const)
  1252   by (rule tendsto_const)
  1250 
  1253 
  1251 lemma Lim_cmul:
  1254 lemma Lim_cmul:
  1252   fixes f :: "'a \<Rightarrow> real ^ 'n::finite"
  1255   fixes f :: "'a \<Rightarrow> real ^ 'n::finite"
  1269 lemma Lim_sub:
  1272 lemma Lim_sub:
  1270   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  1273   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  1271   shows "(f ---> l) net \<Longrightarrow> (g ---> m) net \<Longrightarrow> ((\<lambda>x. f(x) - g(x)) ---> l - m) net"
  1274   shows "(f ---> l) net \<Longrightarrow> (g ---> m) net \<Longrightarrow> ((\<lambda>x. f(x) - g(x)) ---> l - m) net"
  1272   by (rule tendsto_diff)
  1275   by (rule tendsto_diff)
  1273 
  1276 
       
  1277 lemma dist_triangle3: (* TODO: move *)
       
  1278   fixes x y :: "'a::metric_space"
       
  1279   shows "dist x y \<le> dist a x + dist a y"
       
  1280 using dist_triangle2 [of x y a]
       
  1281 by (simp add: dist_commute)
       
  1282 
       
  1283 lemma tendsto_dist: (* TODO: move *)
       
  1284   assumes f: "(f ---> l) net" and g: "(g ---> m) net"
       
  1285   shows "((\<lambda>x. dist (f x) (g x)) ---> dist l m) net"
       
  1286 proof (rule tendstoI)
       
  1287   fix e :: real assume "0 < e"
       
  1288   hence e2: "0 < e/2" by simp
       
  1289   from tendstoD [OF f e2] tendstoD [OF g e2]
       
  1290   show "eventually (\<lambda>x. dist (dist (f x) (g x)) (dist l m) < e) net"
       
  1291   proof (rule eventually_elim2)
       
  1292     fix x assume x: "dist (f x) l < e/2" "dist (g x) m < e/2"
       
  1293     have "dist (f x) (g x) - dist l m \<le> dist (f x) l + dist (g x) m"
       
  1294       using dist_triangle2 [of "f x" "g x" "l"]
       
  1295       using dist_triangle2 [of "g x" "l" "m"]
       
  1296       by arith
       
  1297     moreover
       
  1298     have "dist l m - dist (f x) (g x) \<le> dist (f x) l + dist (g x) m"
       
  1299       using dist_triangle3 [of "l" "m" "f x"]
       
  1300       using dist_triangle [of "f x" "m" "g x"]
       
  1301       by arith
       
  1302     ultimately
       
  1303     have "dist (dist (f x) (g x)) (dist l m) \<le> dist (f x) l + dist (g x) m"
       
  1304       unfolding dist_norm real_norm_def by arith
       
  1305     with x show "dist (dist (f x) (g x)) (dist l m) < e"
       
  1306       by arith
       
  1307   qed
       
  1308 qed
       
  1309 
  1274 lemma Lim_null:
  1310 lemma Lim_null:
  1275   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  1311   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  1276   shows "(f ---> l) net \<longleftrightarrow> ((\<lambda>x. f(x) - l) ---> 0) net" by (simp add: Lim dist_norm)
  1312   shows "(f ---> l) net \<longleftrightarrow> ((\<lambda>x. f(x) - l) ---> 0) net" by (simp add: Lim dist_norm)
  1277 
  1313 
  1278 lemma Lim_null_norm:
  1314 lemma Lim_null_norm:
  1279   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  1315   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  1280   shows "(f ---> 0) net \<longleftrightarrow> ((\<lambda>x. vec1(norm(f x))) ---> 0) net"
  1316   shows "(f ---> 0) net \<longleftrightarrow> ((\<lambda>x. norm(f x)) ---> 0) net"
  1281   by (simp add: Lim dist_norm norm_vec1)
  1317   by (simp add: Lim dist_norm)
  1282 
  1318 
  1283 lemma Lim_null_comparison:
  1319 lemma Lim_null_comparison:
  1284   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  1320   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  1285   assumes "eventually (\<lambda>x. norm(f x) <= g x) net" "((\<lambda>x. vec1(g x)) ---> 0) net"
  1321   assumes "eventually (\<lambda>x. norm (f x) \<le> g x) net" "(g ---> 0) net"
  1286   shows "(f ---> 0) net"
  1322   shows "(f ---> 0) net"
  1287 proof(simp add: tendsto_iff, rule+)
  1323 proof(simp add: tendsto_iff, rule+)
  1288   fix e::real assume "0<e"
  1324   fix e::real assume "0<e"
  1289   { fix x
  1325   { fix x
  1290     assume "norm (f x) \<le> g x" "dist (vec1 (g x)) 0 < e"
  1326     assume "norm (f x) \<le> g x" "dist (g x) 0 < e"
  1291     hence "dist (f x) 0 < e"  unfolding vec_def using dist_vec1[of "g x" "0"]
  1327     hence "dist (f x) 0 < e" by (simp add: dist_norm)
  1292       by (vector dist_norm norm_vec1 real_vector_norm_def dot_def vec1_def)
       
  1293   }
  1328   }
  1294   thus "eventually (\<lambda>x. dist (f x) 0 < e) net"
  1329   thus "eventually (\<lambda>x. dist (f x) 0 < e) net"
  1295     using eventually_and[of "\<lambda>x. norm(f x) <= g x" "\<lambda>x. dist (vec1 (g x)) 0 < e" net]
  1330     using eventually_and[of "\<lambda>x. norm(f x) <= g x" "\<lambda>x. dist (g x) 0 < e" net]
  1296     using eventually_mono[of "(\<lambda>x. norm (f x) \<le> g x \<and> dist (vec1 (g x)) 0 < e)" "(\<lambda>x. dist (f x) 0 < e)" net]
  1331     using eventually_mono[of "(\<lambda>x. norm (f x) \<le> g x \<and> dist (g x) 0 < e)" "(\<lambda>x. dist (f x) 0 < e)" net]
  1297     using assms `e>0` unfolding tendsto_iff by auto
  1332     using assms `e>0` unfolding tendsto_iff by auto
  1298 qed
  1333 qed
  1299 
  1334 
  1300 lemma Lim_component: "(f ---> l) net
  1335 lemma Lim_component:
  1301                       ==> ((\<lambda>a. vec1((f a :: real ^'n::finite)$i)) ---> vec1(l$i)) net"
  1336   fixes f :: "'a \<Rightarrow> 'b::metric_space ^ 'n::finite"
       
  1337   shows "(f ---> l) net \<Longrightarrow> ((\<lambda>a. f a $i) ---> l$i) net"
  1302   unfolding tendsto_iff
  1338   unfolding tendsto_iff
  1303   apply (simp add: dist_norm vec1_sub[symmetric] norm_vec1  vector_minus_component[symmetric] del: vector_minus_component)
  1339   apply (clarify)
  1304   apply (auto simp del: vector_minus_component)
  1340   apply (drule spec, drule (1) mp)
  1305   apply (erule_tac x=e in allE)
  1341   apply (erule eventually_elim1)
  1306   apply clarify
  1342   apply (erule le_less_trans [OF dist_nth_le])
  1307   apply (erule eventually_rev_mono)
  1343   done
  1308   apply (auto simp del: vector_minus_component)
       
  1309   apply (rule order_le_less_trans)
       
  1310   apply (rule component_le_norm)
       
  1311   by auto
       
  1312 
  1344 
  1313 lemma Lim_transform_bound:
  1345 lemma Lim_transform_bound:
  1314   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  1346   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
  1315   fixes g :: "'a \<Rightarrow> 'c::real_normed_vector"
  1347   fixes g :: "'a \<Rightarrow> 'c::real_normed_vector"
  1316   assumes "eventually (\<lambda>n. norm(f n) <= norm(g n)) net"  "(g ---> 0) net"
  1348   assumes "eventually (\<lambda>n. norm(f n) <= norm(g n)) net"  "(g ---> 0) net"
  1502 
  1534 
  1503 definition
  1535 definition
  1504   netlimit :: "'a::metric_space net \<Rightarrow> 'a" where
  1536   netlimit :: "'a::metric_space net \<Rightarrow> 'a" where
  1505   "netlimit net = (SOME a. \<forall>r>0. eventually (\<lambda>x. dist x a < r) net)"
  1537   "netlimit net = (SOME a. \<forall>r>0. eventually (\<lambda>x. dist x a < r) net)"
  1506 
  1538 
  1507 lemma dist_triangle3:
       
  1508   fixes x y :: "'a::metric_space"
       
  1509   shows "dist x y \<le> dist a x + dist a y"
       
  1510 using dist_triangle2 [of x y a]
       
  1511 by (simp add: dist_commute)
       
  1512 
       
  1513 lemma netlimit_within:
  1539 lemma netlimit_within:
  1514   assumes "\<not> trivial_limit (at a within S)"
  1540   assumes "\<not> trivial_limit (at a within S)"
  1515   shows "netlimit (at a within S) = a"
  1541   shows "netlimit (at a within S) = a"
  1516 using assms
  1542 using assms
  1517 apply (simp add: trivial_limit_within)
  1543 apply (simp add: trivial_limit_within)
  1692   apply (drule (2) topological_tendstoD)
  1718   apply (drule (2) topological_tendstoD)
  1693   apply (simp only: eventually_sequentially)
  1719   apply (simp only: eventually_sequentially)
  1694   apply (subgoal_tac "\<And>N k (n::nat). N + k <= n ==> N <= n - k \<and> (n - k) + k = n")
  1720   apply (subgoal_tac "\<And>N k (n::nat). N + k <= n ==> N <= n - k \<and> (n - k) + k = n")
  1695   by metis arith
  1721   by metis arith
  1696 
  1722 
  1697 lemma seq_harmonic: "((\<lambda>n. vec1(inverse (real n))) ---> 0) sequentially"
  1723 lemma seq_harmonic: "((\<lambda>n. inverse (real n)) ---> 0) sequentially"
  1698 proof-
  1724 proof-
  1699   { fix e::real assume "e>0"
  1725   { fix e::real assume "e>0"
  1700     hence "\<exists>N::nat. \<forall>n::nat\<ge>N. inverse (real n) < e"
  1726     hence "\<exists>N::nat. \<forall>n::nat\<ge>N. inverse (real n) < e"
  1701       using real_arch_inv[of e] apply auto apply(rule_tac x=n in exI)
  1727       using real_arch_inv[of e] apply auto apply(rule_tac x=n in exI)
  1702       by (metis dlo_simps(4) le_imp_inverse_le linorder_not_less real_of_nat_gt_zero_cancel_iff real_of_nat_less_iff xt1(7))
  1728       by (metis not_le le_imp_inverse_le not_less real_of_nat_gt_zero_cancel_iff real_of_nat_less_iff xt1(7))
  1703   }
  1729   }
  1704   thus ?thesis unfolding Lim_sequentially dist_norm apply simp unfolding norm_vec1 by auto
  1730   thus ?thesis unfolding Lim_sequentially dist_norm by simp
  1705 qed
  1731 qed
  1706 
  1732 
  1707 text{* More properties of closed balls. *}
  1733 text{* More properties of closed balls. *}
  1708 
  1734 
  1709 lemma closed_cball: "closed (cball x e)"
  1735 lemma closed_cball: "closed (cball x e)"
  2121 qed
  2147 qed
  2122 
  2148 
  2123 
  2149 
  2124 text{* Some theorems on sups and infs using the notion "bounded". *}
  2150 text{* Some theorems on sups and infs using the notion "bounded". *}
  2125 
  2151 
  2126 lemma bounded_vec1:
  2152 lemma bounded_real:
  2127   fixes S :: "real set"
  2153   fixes S :: "real set"
  2128   shows "bounded(vec1 ` S) \<longleftrightarrow>  (\<exists>a. \<forall>x\<in>S. abs x <= a)"
  2154   shows "bounded S \<longleftrightarrow>  (\<exists>a. \<forall>x\<in>S. abs x <= a)"
  2129   by (simp add: bounded_iff forall_vec1 norm_vec1 vec1_in_image_vec1)
  2155   by (simp add: bounded_iff)
  2130 
  2156 
  2131 lemma bounded_has_rsup: assumes "bounded(vec1 ` S)" "S \<noteq> {}"
  2157 lemma bounded_has_rsup: assumes "bounded S" "S \<noteq> {}"
  2132   shows "\<forall>x\<in>S. x <= rsup S" and "\<forall>b. (\<forall>x\<in>S. x <= b) \<longrightarrow> rsup S <= b"
  2158   shows "\<forall>x\<in>S. x <= rsup S" and "\<forall>b. (\<forall>x\<in>S. x <= b) \<longrightarrow> rsup S <= b"
  2133 proof
  2159 proof
  2134   fix x assume "x\<in>S"
  2160   fix x assume "x\<in>S"
  2135   from assms(1) obtain a where a:"\<forall>x\<in>S. \<bar>x\<bar> \<le> a" unfolding bounded_vec1 by auto
  2161   from assms(1) obtain a where a:"\<forall>x\<in>S. \<bar>x\<bar> \<le> a" unfolding bounded_real by auto
  2136   hence *:"S *<= a" using setleI[of S a] by (metis abs_le_interval_iff mem_def)
  2162   hence *:"S *<= a" using setleI[of S a] by (metis abs_le_interval_iff mem_def)
  2137   thus "x \<le> rsup S" using rsup[OF `S\<noteq>{}`] using assms(1)[unfolded bounded_vec1] using isLubD2[of UNIV S "rsup S" x] using `x\<in>S` by auto
  2163   thus "x \<le> rsup S" using rsup[OF `S\<noteq>{}`] using assms(1)[unfolded bounded_real] using isLubD2[of UNIV S "rsup S" x] using `x\<in>S` by auto
  2138 next
  2164 next
  2139   show "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> rsup S \<le> b" using assms
  2165   show "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> rsup S \<le> b" using assms
  2140   using rsup[of S, unfolded isLub_def isUb_def leastP_def setle_def setge_def]
  2166   using rsup[of S, unfolded isLub_def isUb_def leastP_def setle_def setge_def]
  2141   apply (auto simp add: bounded_vec1)
  2167   apply (auto simp add: bounded_real)
  2142   by (auto simp add: isLub_def isUb_def leastP_def setle_def setge_def)
  2168   by (auto simp add: isLub_def isUb_def leastP_def setle_def setge_def)
  2143 qed
  2169 qed
  2144 
  2170 
  2145 lemma rsup_insert: assumes "bounded (vec1 ` S)"
  2171 lemma rsup_insert: assumes "bounded S"
  2146   shows "rsup(insert x S) = (if S = {} then x else max x (rsup S))"
  2172   shows "rsup(insert x S) = (if S = {} then x else max x (rsup S))"
  2147 proof(cases "S={}")
  2173 proof(cases "S={}")
  2148   case True thus ?thesis using rsup_finite_in[of "{x}"] by auto
  2174   case True thus ?thesis using rsup_finite_in[of "{x}"] by auto
  2149 next
  2175 next
  2150   let ?S = "insert x S"
  2176   let ?S = "insert x S"
  2166   apply (rule rsup_insert)
  2192   apply (rule rsup_insert)
  2167   apply (rule finite_imp_bounded)
  2193   apply (rule finite_imp_bounded)
  2168   by simp
  2194   by simp
  2169 
  2195 
  2170 lemma bounded_has_rinf:
  2196 lemma bounded_has_rinf:
  2171   assumes "bounded(vec1 ` S)"  "S \<noteq> {}"
  2197   assumes "bounded S"  "S \<noteq> {}"
  2172   shows "\<forall>x\<in>S. x >= rinf S" and "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> rinf S >= b"
  2198   shows "\<forall>x\<in>S. x >= rinf S" and "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> rinf S >= b"
  2173 proof
  2199 proof
  2174   fix x assume "x\<in>S"
  2200   fix x assume "x\<in>S"
  2175   from assms(1) obtain a where a:"\<forall>x\<in>S. \<bar>x\<bar> \<le> a" unfolding bounded_vec1 by auto
  2201   from assms(1) obtain a where a:"\<forall>x\<in>S. \<bar>x\<bar> \<le> a" unfolding bounded_real by auto
  2176   hence *:"- a <=* S" using setgeI[of S "-a"] unfolding abs_le_interval_iff by auto
  2202   hence *:"- a <=* S" using setgeI[of S "-a"] unfolding abs_le_interval_iff by auto
  2177   thus "x \<ge> rinf S" using rinf[OF `S\<noteq>{}`] using isGlbD2[of UNIV S "rinf S" x] using `x\<in>S` by auto
  2203   thus "x \<ge> rinf S" using rinf[OF `S\<noteq>{}`] using isGlbD2[of UNIV S "rinf S" x] using `x\<in>S` by auto
  2178 next
  2204 next
  2179   show "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> rinf S \<ge> b" using assms
  2205   show "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> rinf S \<ge> b" using assms
  2180   using rinf[of S, unfolded isGlb_def isLb_def greatestP_def setle_def setge_def]
  2206   using rinf[of S, unfolded isGlb_def isLb_def greatestP_def setle_def setge_def]
  2181   apply (auto simp add: bounded_vec1)
  2207   apply (auto simp add: bounded_real)
  2182   by (auto simp add: isGlb_def isLb_def greatestP_def setle_def setge_def)
  2208   by (auto simp add: isGlb_def isLb_def greatestP_def setle_def setge_def)
  2183 qed
  2209 qed
  2184 
  2210 
  2185 (* TODO: Move this to RComplete.thy -- would need to include Glb into RComplete *)
  2211 (* TODO: Move this to RComplete.thy -- would need to include Glb into RComplete *)
  2186 lemma real_isGlb_unique: "[| isGlb R S x; isGlb R S y |] ==> x = (y::real)"
  2212 lemma real_isGlb_unique: "[| isGlb R S x; isGlb R S y |] ==> x = (y::real)"
  2187   apply (frule isGlb_isLb)
  2213   apply (frule isGlb_isLb)
  2188   apply (frule_tac x = y in isGlb_isLb)
  2214   apply (frule_tac x = y in isGlb_isLb)
  2189   apply (blast intro!: order_antisym dest!: isGlb_le_isLb)
  2215   apply (blast intro!: order_antisym dest!: isGlb_le_isLb)
  2190   done
  2216   done
  2191 
  2217 
  2192 lemma rinf_insert: assumes "bounded (vec1 ` S)"
  2218 lemma rinf_insert: assumes "bounded S"
  2193   shows "rinf(insert x S) = (if S = {} then x else min x (rinf S))" (is "?lhs = ?rhs")
  2219   shows "rinf(insert x S) = (if S = {} then x else min x (rinf S))" (is "?lhs = ?rhs")
  2194 proof(cases "S={}")
  2220 proof(cases "S={}")
  2195   case True thus ?thesis using rinf_finite_in[of "{x}"] by auto
  2221   case True thus ?thesis using rinf_finite_in[of "{x}"] by auto
  2196 next
  2222 next
  2197   let ?S = "insert x S"
  2223   let ?S = "insert x S"
  4048   using bilinear_continuous_within_compose[of _ s f g h] by auto
  4074   using bilinear_continuous_within_compose[of _ s f g h] by auto
  4049 
  4075 
  4050 subsection{* Topological stuff lifted from and dropped to R                            *}
  4076 subsection{* Topological stuff lifted from and dropped to R                            *}
  4051 
  4077 
  4052 
  4078 
  4053 lemma open_vec1:
  4079 lemma open_real:
  4054   fixes s :: "real set" shows
  4080   fixes s :: "real set" shows
  4055  "open(vec1 ` s) \<longleftrightarrow>
  4081  "open s \<longleftrightarrow>
  4056         (\<forall>x \<in> s. \<exists>e>0. \<forall>x'. abs(x' - x) < e --> x' \<in> s)" (is "?lhs = ?rhs")
  4082         (\<forall>x \<in> s. \<exists>e>0. \<forall>x'. abs(x' - x) < e --> x' \<in> s)" (is "?lhs = ?rhs")
  4057   unfolding open_dist apply simp unfolding forall_vec1 dist_vec1 vec1_in_image_vec1 by simp
  4083   unfolding open_dist dist_norm by simp
  4058 
  4084 
  4059 lemma islimpt_approachable_vec1:
  4085 lemma islimpt_approachable_real:
  4060   fixes s :: "real set" shows
  4086   fixes s :: "real set"
  4061  "(vec1 x) islimpt (vec1 ` s) \<longleftrightarrow>
  4087   shows "x islimpt s \<longleftrightarrow> (\<forall>e>0.  \<exists>x'\<in> s. x' \<noteq> x \<and> abs(x' - x) < e)"
  4062          (\<forall>e>0.  \<exists>x'\<in> s. x' \<noteq> x \<and> abs(x' - x) < e)"
  4088   unfolding islimpt_approachable dist_norm by simp
  4063   by (auto simp add: islimpt_approachable dist_vec1 vec1_eq)
  4089 
  4064 
  4090 lemma closed_real:
  4065 lemma closed_vec1:
  4091   fixes s :: "real set"
  4066   fixes s :: "real set" shows
  4092   shows "closed s \<longleftrightarrow>
  4067  "closed (vec1 ` s) \<longleftrightarrow>
       
  4068         (\<forall>x. (\<forall>e>0.  \<exists>x' \<in> s. x' \<noteq> x \<and> abs(x' - x) < e)
  4093         (\<forall>x. (\<forall>e>0.  \<exists>x' \<in> s. x' \<noteq> x \<and> abs(x' - x) < e)
  4069             --> x \<in> s)"
  4094             --> x \<in> s)"
  4070   unfolding closed_limpt islimpt_approachable forall_vec1 apply simp
  4095   unfolding closed_limpt islimpt_approachable dist_norm by simp
  4071   unfolding dist_vec1 vec1_in_image_vec1 abs_minus_commute by auto
  4096 
  4072 
  4097 lemma continuous_at_real_range:
  4073 lemma continuous_at_vec1_range:
  4098   fixes f :: "'a::real_normed_vector \<Rightarrow> real"
  4074   fixes f :: "real ^ _ \<Rightarrow> real"
  4099   shows "continuous (at x) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0.
  4075   shows "continuous (at x) (vec1 o f) \<longleftrightarrow> (\<forall>e>0. \<exists>d>0.
       
  4076         \<forall>x'. norm(x' - x) < d --> abs(f x' - f x) < e)"
  4100         \<forall>x'. norm(x' - x) < d --> abs(f x' - f x) < e)"
  4077   unfolding continuous_at unfolding Lim_at apply simp unfolding dist_vec1 unfolding dist_nz[THEN sym] unfolding dist_norm apply auto
  4101   unfolding continuous_at unfolding Lim_at
       
  4102   unfolding dist_nz[THEN sym] unfolding dist_norm apply auto
  4078   apply(erule_tac x=e in allE) apply auto apply (rule_tac x=d in exI) apply auto apply (erule_tac x=x' in allE) apply auto
  4103   apply(erule_tac x=e in allE) apply auto apply (rule_tac x=d in exI) apply auto apply (erule_tac x=x' in allE) apply auto
  4079   apply(erule_tac x=e in allE) by auto
  4104   apply(erule_tac x=e in allE) by auto
  4080 
  4105 
  4081 lemma continuous_on_vec1_range:
  4106 lemma continuous_on_real_range:
  4082   fixes f :: "'a::real_normed_vector \<Rightarrow> real"
  4107   fixes f :: "'a::real_normed_vector \<Rightarrow> real"
  4083   shows "continuous_on s (vec1 o f) \<longleftrightarrow> (\<forall>x \<in> s. \<forall>e>0. \<exists>d>0. (\<forall>x' \<in> s. norm(x' - x) < d --> abs(f x' - f x) < e))"
  4108   shows "continuous_on s f \<longleftrightarrow> (\<forall>x \<in> s. \<forall>e>0. \<exists>d>0. (\<forall>x' \<in> s. norm(x' - x) < d --> abs(f x' - f x) < e))"
  4084   unfolding continuous_on_def apply (simp del: dist_commute) unfolding dist_vec1 unfolding dist_norm ..
  4109   unfolding continuous_on_def dist_norm by simp
  4085 
  4110 
  4086 lemma continuous_at_vec1_norm:
  4111 lemma continuous_at_norm: "continuous (at x) norm"
  4087   fixes x :: "real ^ _"
  4112   unfolding continuous_at by (intro tendsto_norm Lim_ident_at)
  4088   shows "continuous (at x) (vec1 o norm)"
  4113 
  4089   unfolding continuous_at_vec1_range using real_abs_sub_norm order_le_less_trans by blast
  4114 lemma continuous_on_norm: "continuous_on s norm"
  4090 
  4115 unfolding continuous_on by (intro ballI tendsto_norm Lim_at_within Lim_ident_at)
  4091 lemma continuous_on_vec1_norm:
  4116 
  4092   fixes s :: "(real ^ _) set"
  4117 lemma continuous_at_component: "continuous (at a) (\<lambda>x. x $ i)"
  4093   shows "continuous_on s (vec1 o norm)"
  4118 unfolding continuous_at by (intro Lim_component Lim_ident_at)
  4094 unfolding continuous_on_vec1_range norm_vec1[THEN sym] by (metis norm_vec1 order_le_less_trans real_abs_sub_norm)
  4119 
  4095 
  4120 lemma continuous_on_component: "continuous_on s (\<lambda>x. x $ i)"
  4096 lemma continuous_at_vec1_component:
  4121 unfolding continuous_on by (intro ballI Lim_component Lim_at_within Lim_ident_at)
  4097   shows "continuous (at (a::real^'a::finite)) (\<lambda> x. vec1(x$i))"
  4122 
  4098 proof-
  4123 lemma continuous_at_infnorm: "continuous (at x) infnorm"
  4099   { fix e::real and x assume "0 < dist x a" "dist x a < e" "e>0"
  4124   unfolding continuous_at Lim_at o_def unfolding dist_norm
  4100     hence "\<bar>x $ i - a $ i\<bar> < e" using component_le_norm[of "x - a" i] unfolding dist_norm by auto  }
       
  4101   thus ?thesis unfolding continuous_at tendsto_iff eventually_at dist_vec1 by auto
       
  4102 qed
       
  4103 
       
  4104 lemma continuous_on_vec1_component:
       
  4105   shows "continuous_on s (\<lambda> x::real^'a::finite. vec1(x$i))"
       
  4106 proof-
       
  4107   { fix e::real and x xa assume "x\<in>s" "e>0" "xa\<in>s" "0 < norm (xa - x) \<and> norm (xa - x) < e"
       
  4108     hence "\<bar>xa $ i - x $ i\<bar> < e" using component_le_norm[of "xa - x" i] by auto  }
       
  4109   thus ?thesis unfolding continuous_on Lim_within dist_vec1 unfolding dist_norm by auto
       
  4110 qed
       
  4111 
       
  4112 lemma continuous_at_vec1_infnorm:
       
  4113  "continuous (at x) (vec1 o infnorm)"
       
  4114   unfolding continuous_at Lim_at o_def unfolding dist_vec1 unfolding dist_norm
       
  4115   apply auto apply (rule_tac x=e in exI) apply auto
  4125   apply auto apply (rule_tac x=e in exI) apply auto
  4116   using order_trans[OF real_abs_sub_infnorm infnorm_le_norm, of _ x] by (metis xt1(7))
  4126   using order_trans[OF real_abs_sub_infnorm infnorm_le_norm, of _ x] by (metis xt1(7))
  4117 
  4127 
  4118 text{* Hence some handy theorems on distance, diameter etc. of/from a set.       *}
  4128 text{* Hence some handy theorems on distance, diameter etc. of/from a set.       *}
  4119 
  4129 
  4120 lemma compact_attains_sup:
  4130 lemma compact_attains_sup:
  4121   fixes s :: "real set"
  4131   fixes s :: "real set"
  4122   assumes "compact (vec1 ` s)"  "s \<noteq> {}"
  4132   assumes "compact s"  "s \<noteq> {}"
  4123   shows "\<exists>x \<in> s. \<forall>y \<in> s. y \<le> x"
  4133   shows "\<exists>x \<in> s. \<forall>y \<in> s. y \<le> x"
  4124 proof-
  4134 proof-
  4125   from assms(1) have a:"bounded (vec1 ` s)" "closed (vec1 ` s)" unfolding compact_eq_bounded_closed by auto
  4135   from assms(1) have a:"bounded s" "closed s" unfolding compact_eq_bounded_closed by auto
  4126   { fix e::real assume as: "\<forall>x\<in>s. x \<le> rsup s" "rsup s \<notin> s"  "0 < e" "\<forall>x'\<in>s. x' = rsup s \<or> \<not> rsup s - x' < e"
  4136   { fix e::real assume as: "\<forall>x\<in>s. x \<le> rsup s" "rsup s \<notin> s"  "0 < e" "\<forall>x'\<in>s. x' = rsup s \<or> \<not> rsup s - x' < e"
  4127     have "isLub UNIV s (rsup s)" using rsup[OF assms(2)] unfolding setle_def using as(1) by auto
  4137     have "isLub UNIV s (rsup s)" using rsup[OF assms(2)] unfolding setle_def using as(1) by auto
  4128     moreover have "isUb UNIV s (rsup s - e)" unfolding isUb_def unfolding setle_def using as(4,2) by auto
  4138     moreover have "isUb UNIV s (rsup s - e)" unfolding isUb_def unfolding setle_def using as(4,2) by auto
  4129     ultimately have False using isLub_le_isUb[of UNIV s "rsup s" "rsup s - e"] using `e>0` by auto  }
  4139     ultimately have False using isLub_le_isUb[of UNIV s "rsup s" "rsup s - e"] using `e>0` by auto  }
  4130   thus ?thesis using bounded_has_rsup(1)[OF a(1) assms(2)] using a(2)[unfolded closed_vec1, THEN spec[where x="rsup s"]]
  4140   thus ?thesis using bounded_has_rsup(1)[OF a(1) assms(2)] using a(2)[unfolded closed_real, THEN spec[where x="rsup s"]]
  4131     apply(rule_tac x="rsup s" in bexI) by auto
  4141     apply(rule_tac x="rsup s" in bexI) by auto
  4132 qed
  4142 qed
  4133 
  4143 
  4134 lemma compact_attains_inf:
  4144 lemma compact_attains_inf:
  4135   fixes s :: "real set"
  4145   fixes s :: "real set"
  4136   assumes "compact (vec1 ` s)" "s \<noteq> {}"  shows "\<exists>x \<in> s. \<forall>y \<in> s. x \<le> y"
  4146   assumes "compact s" "s \<noteq> {}"  shows "\<exists>x \<in> s. \<forall>y \<in> s. x \<le> y"
  4137 proof-
  4147 proof-
  4138   from assms(1) have a:"bounded (vec1 ` s)" "closed (vec1 ` s)" unfolding compact_eq_bounded_closed by auto
  4148   from assms(1) have a:"bounded s" "closed s" unfolding compact_eq_bounded_closed by auto
  4139   { fix e::real assume as: "\<forall>x\<in>s. x \<ge> rinf s"  "rinf s \<notin> s"  "0 < e"
  4149   { fix e::real assume as: "\<forall>x\<in>s. x \<ge> rinf s"  "rinf s \<notin> s"  "0 < e"
  4140       "\<forall>x'\<in>s. x' = rinf s \<or> \<not> abs (x' - rinf s) < e"
  4150       "\<forall>x'\<in>s. x' = rinf s \<or> \<not> abs (x' - rinf s) < e"
  4141     have "isGlb UNIV s (rinf s)" using rinf[OF assms(2)] unfolding setge_def using as(1) by auto
  4151     have "isGlb UNIV s (rinf s)" using rinf[OF assms(2)] unfolding setge_def using as(1) by auto
  4142     moreover
  4152     moreover
  4143     { fix x assume "x \<in> s"
  4153     { fix x assume "x \<in> s"
  4144       hence *:"abs (x - rinf s) = x - rinf s" using as(1)[THEN bspec[where x=x]] by auto
  4154       hence *:"abs (x - rinf s) = x - rinf s" using as(1)[THEN bspec[where x=x]] by auto
  4145       have "rinf s + e \<le> x" using as(4)[THEN bspec[where x=x]] using as(2) `x\<in>s` unfolding * by auto }
  4155       have "rinf s + e \<le> x" using as(4)[THEN bspec[where x=x]] using as(2) `x\<in>s` unfolding * by auto }
  4146     hence "isLb UNIV s (rinf s + e)" unfolding isLb_def and setge_def by auto
  4156     hence "isLb UNIV s (rinf s + e)" unfolding isLb_def and setge_def by auto
  4147     ultimately have False using isGlb_le_isLb[of UNIV s "rinf s" "rinf s + e"] using `e>0` by auto  }
  4157     ultimately have False using isGlb_le_isLb[of UNIV s "rinf s" "rinf s + e"] using `e>0` by auto  }
  4148   thus ?thesis using bounded_has_rinf(1)[OF a(1) assms(2)] using a(2)[unfolded closed_vec1, THEN spec[where x="rinf s"]]
  4158   thus ?thesis using bounded_has_rinf(1)[OF a(1) assms(2)] using a(2)[unfolded closed_real, THEN spec[where x="rinf s"]]
  4149     apply(rule_tac x="rinf s" in bexI) by auto
  4159     apply(rule_tac x="rinf s" in bexI) by auto
  4150 qed
  4160 qed
  4151 
  4161 
  4152 lemma continuous_attains_sup:
  4162 lemma continuous_attains_sup:
  4153   fixes f :: "'a::metric_space \<Rightarrow> real"
  4163   fixes f :: "'a::metric_space \<Rightarrow> real"
  4154   shows "compact s \<Longrightarrow> s \<noteq> {} \<Longrightarrow> continuous_on s (vec1 o f)
  4164   shows "compact s \<Longrightarrow> s \<noteq> {} \<Longrightarrow> continuous_on s f
  4155         ==> (\<exists>x \<in> s. \<forall>y \<in> s.  f y \<le> f x)"
  4165         ==> (\<exists>x \<in> s. \<forall>y \<in> s.  f y \<le> f x)"
  4156   using compact_attains_sup[of "f ` s"]
  4166   using compact_attains_sup[of "f ` s"]
  4157   using compact_continuous_image[of s "vec1 \<circ> f"] unfolding image_compose by auto
  4167   using compact_continuous_image[of s f] by auto
  4158 
  4168 
  4159 lemma continuous_attains_inf:
  4169 lemma continuous_attains_inf:
  4160   fixes f :: "'a::metric_space \<Rightarrow> real"
  4170   fixes f :: "'a::metric_space \<Rightarrow> real"
  4161   shows "compact s \<Longrightarrow> s \<noteq> {} \<Longrightarrow> continuous_on s (vec1 o f)
  4171   shows "compact s \<Longrightarrow> s \<noteq> {} \<Longrightarrow> continuous_on s f
  4162         \<Longrightarrow> (\<exists>x \<in> s. \<forall>y \<in> s. f x \<le> f y)"
  4172         \<Longrightarrow> (\<exists>x \<in> s. \<forall>y \<in> s. f x \<le> f y)"
  4163   using compact_attains_inf[of "f ` s"]
  4173   using compact_attains_inf[of "f ` s"]
  4164   using compact_continuous_image[of s "vec1 \<circ> f"] unfolding image_compose by auto
  4174   using compact_continuous_image[of s f] by auto
  4165 
  4175 
  4166 lemma distance_attains_sup:
  4176 lemma distance_attains_sup:
  4167   fixes s :: "(real ^ _) set"
       
  4168   assumes "compact s" "s \<noteq> {}"
  4177   assumes "compact s" "s \<noteq> {}"
  4169   shows "\<exists>x \<in> s. \<forall>y \<in> s. dist a y \<le> dist a x"
  4178   shows "\<exists>x \<in> s. \<forall>y \<in> s. dist a y \<le> dist a x"
  4170 proof-
  4179 proof (rule continuous_attains_sup [OF assms])
  4171   { fix x assume "x\<in>s" fix e::real assume "e>0"
  4180   { fix x assume "x\<in>s"
  4172     { fix x' assume "x'\<in>s" and as:"norm (x' - x) < e"
  4181     have "(dist a ---> dist a x) (at x within s)"
  4173       hence "\<bar>norm (x' - a) - norm (x - a)\<bar> < e"
  4182       by (intro tendsto_dist tendsto_const Lim_at_within Lim_ident_at)
  4174 	using real_abs_sub_norm[of "x' - a" "x - a"]  by auto  }
  4183   }
  4175     hence "\<exists>d>0. \<forall>x'\<in>s. norm (x' - x) < d \<longrightarrow> \<bar>dist x' a - dist x a\<bar> < e" using `e>0` unfolding dist_norm by auto }
  4184   thus "continuous_on s (dist a)"
  4176   thus ?thesis using assms
  4185     unfolding continuous_on ..
  4177     using continuous_attains_sup[of s "\<lambda>x. dist a x"]
       
  4178     unfolding continuous_on_vec1_range by (auto simp add: dist_commute)
       
  4179 qed
  4186 qed
  4180 
  4187 
  4181 text{* For *minimal* distance, we only need closure, not compactness.            *}
  4188 text{* For *minimal* distance, we only need closure, not compactness.            *}
  4182 
  4189 
  4183 lemma distance_attains_inf:
  4190 lemma distance_attains_inf:
  4184   fixes a :: "real ^ _" (* FIXME: generalize *)
  4191   fixes a :: "'a::heine_borel"
  4185   assumes "closed s"  "s \<noteq> {}"
  4192   assumes "closed s"  "s \<noteq> {}"
  4186   shows "\<exists>x \<in> s. \<forall>y \<in> s. dist a x \<le> dist a y"
  4193   shows "\<exists>x \<in> s. \<forall>y \<in> s. dist a x \<le> dist a y"
  4187 proof-
  4194 proof-
  4188   from assms(2) obtain b where "b\<in>s" by auto
  4195   from assms(2) obtain b where "b\<in>s" by auto
  4189   let ?B = "cball a (dist b a) \<inter> s"
  4196   let ?B = "cball a (dist b a) \<inter> s"
  4190   have "b \<in> ?B" using `b\<in>s` by (simp add: dist_commute)
  4197   have "b \<in> ?B" using `b\<in>s` by (simp add: dist_commute)
  4191   hence "?B \<noteq> {}" by auto
  4198   hence "?B \<noteq> {}" by auto
  4192   moreover
  4199   moreover
  4193   { fix x assume "x\<in>?B"
  4200   { fix x assume "x\<in>?B"
  4194     fix e::real assume "e>0"
  4201     fix e::real assume "e>0"
  4195     { fix x' assume "x'\<in>?B" and as:"norm (x' - x) < e"
  4202     { fix x' assume "x'\<in>?B" and as:"dist x' x < e"
  4196       hence "\<bar>norm (x' - a) - norm (x - a)\<bar> < e"
  4203       from as have "\<bar>dist a x' - dist a x\<bar> < e"
  4197 	using real_abs_sub_norm[of "x' - a" "x - a"]  by auto  }
  4204         unfolding abs_less_iff minus_diff_eq
  4198     hence "\<exists>d>0. \<forall>x'\<in>?B. norm (x' - x) < d \<longrightarrow> \<bar>dist x' a - dist x a\<bar> < e" using `e>0` unfolding dist_norm by auto }
  4205         using dist_triangle2 [of a x' x]
  4199   hence "continuous_on (cball a (dist b a) \<inter> s) (vec1 \<circ> dist a)" unfolding continuous_on_vec1_range
  4206         using dist_triangle [of a x x']
  4200     by (auto  simp add: dist_commute)
  4207         by arith
  4201   moreover have "compact ?B" using compact_cball[of a "dist b a"] unfolding compact_eq_bounded_closed using bounded_Int and closed_Int and assms(1) by auto
  4208     }
  4202   ultimately obtain x where "x\<in>cball a (dist b a) \<inter> s" "\<forall>y\<in>cball a (dist b a) \<inter> s. dist a x \<le> dist a y" using continuous_attains_inf[of ?B "dist a"] by fastsimp
  4209     hence "\<exists>d>0. \<forall>x'\<in>?B. dist x' x < d \<longrightarrow> \<bar>dist a x' - dist a x\<bar> < e"
       
  4210       using `e>0` by auto
       
  4211   }
       
  4212   hence "continuous_on (cball a (dist b a) \<inter> s) (dist a)"
       
  4213     unfolding continuous_on Lim_within dist_norm real_norm_def
       
  4214     by fast
       
  4215   moreover have "compact ?B"
       
  4216     using compact_cball[of a "dist b a"]
       
  4217     unfolding compact_eq_bounded_closed
       
  4218     using bounded_Int and closed_Int and assms(1) by auto
       
  4219   ultimately obtain x where "x\<in>cball a (dist b a) \<inter> s" "\<forall>y\<in>cball a (dist b a) \<inter> s. dist a x \<le> dist a y"
       
  4220     using continuous_attains_inf[of ?B "dist a"] by fastsimp
  4203   thus ?thesis by fastsimp
  4221   thus ?thesis by fastsimp
  4204 qed
  4222 qed
  4205 
  4223 
  4206 subsection{* We can now extend limit compositions to consider the scalar multiplier.   *}
  4224 subsection{* We can now extend limit compositions to consider the scalar multiplier.   *}
  4207 
  4225 
  4208 lemma Lim_mul:
  4226 lemma Lim_mul:
  4209   fixes f :: "'a \<Rightarrow> real ^ _"
  4227   fixes f :: "'a \<Rightarrow> real ^ _"
  4210   assumes "((vec1 o c) ---> vec1 d) net"  "(f ---> l) net"
  4228   assumes "(c ---> d) net"  "(f ---> l) net"
  4211   shows "((\<lambda>x. c(x) *s f x) ---> (d *s l)) net"
  4229   shows "((\<lambda>x. c(x) *s f x) ---> (d *s l)) net"
  4212 proof-
  4230   unfolding smult_conv_scaleR using assms by (rule scaleR.tendsto)
  4213   have "bilinear (\<lambda>x. op *s (dest_vec1 (x::real^1)))" unfolding bilinear_def linear_def
       
  4214     unfolding dest_vec1_add dest_vec1_cmul
       
  4215     apply vector apply auto unfolding semiring_class.right_distrib semiring_class.left_distrib by auto
       
  4216   thus ?thesis using Lim_bilinear[OF assms, of "\<lambda>x y. (dest_vec1 x) *s y"] by auto
       
  4217 qed
       
  4218 
  4231 
  4219 lemma Lim_vmul:
  4232 lemma Lim_vmul:
  4220   fixes c :: "'a \<Rightarrow> real"
  4233   fixes c :: "'a \<Rightarrow> real"
  4221   shows "((vec1 o c) ---> vec1 d) net ==> ((\<lambda>x. c(x) *s v) ---> d *s v) net"
  4234   shows "(c ---> d) net ==> ((\<lambda>x. c(x) *s v) ---> d *s v) net"
  4222   using Lim_mul[of c d net "\<lambda>x. v" v] using Lim_const[of v] by auto
  4235   using Lim_mul[of c d net "\<lambda>x. v" v] using Lim_const[of v] by auto
  4223 
  4236 
  4224 lemma continuous_vmul:
  4237 lemma continuous_vmul:
  4225   fixes c :: "'a::metric_space \<Rightarrow> real"
  4238   fixes c :: "'a::metric_space \<Rightarrow> real"
  4226   shows "continuous net (vec1 o c) ==> continuous net (\<lambda>x. c(x) *s v)"
  4239   shows "continuous net c ==> continuous net (\<lambda>x. c(x) *s v)"
  4227   unfolding continuous_def using Lim_vmul[of c] by auto
  4240   unfolding continuous_def using Lim_vmul[of c] by auto
  4228 
  4241 
  4229 lemma continuous_mul:
  4242 lemma continuous_mul:
  4230   fixes c :: "'a::metric_space \<Rightarrow> real"
  4243   fixes c :: "'a::metric_space \<Rightarrow> real"
  4231   shows "continuous net (vec1 o c) \<Longrightarrow> continuous net f
  4244   shows "continuous net c \<Longrightarrow> continuous net f
  4232              ==> continuous net (\<lambda>x. c(x) *s f x) "
  4245              ==> continuous net (\<lambda>x. c(x) *s f x) "
  4233   unfolding continuous_def using Lim_mul[of c] by auto
  4246   unfolding continuous_def using Lim_mul[of c] by auto
  4234 
  4247 
  4235 lemma continuous_on_vmul:
  4248 lemma continuous_on_vmul:
  4236   fixes c :: "'a::metric_space \<Rightarrow> real"
  4249   fixes c :: "'a::metric_space \<Rightarrow> real"
  4237   shows "continuous_on s (vec1 o c) ==> continuous_on s (\<lambda>x. c(x) *s v)"
  4250   shows "continuous_on s c ==> continuous_on s (\<lambda>x. c(x) *s v)"
  4238   unfolding continuous_on_eq_continuous_within using continuous_vmul[of _ c] by auto
  4251   unfolding continuous_on_eq_continuous_within using continuous_vmul[of _ c] by auto
  4239 
  4252 
  4240 lemma continuous_on_mul:
  4253 lemma continuous_on_mul:
  4241   fixes c :: "'a::metric_space \<Rightarrow> real"
  4254   fixes c :: "'a::metric_space \<Rightarrow> real"
  4242   shows "continuous_on s (vec1 o c) \<Longrightarrow> continuous_on s f
  4255   shows "continuous_on s c \<Longrightarrow> continuous_on s f
  4243              ==> continuous_on s (\<lambda>x. c(x) *s f x)"
  4256              ==> continuous_on s (\<lambda>x. c(x) *s f x)"
  4244   unfolding continuous_on_eq_continuous_within using continuous_mul[of _ c] by auto
  4257   unfolding continuous_on_eq_continuous_within using continuous_mul[of _ c] by auto
  4245 
  4258 
  4246 text{* And so we have continuity of inverse.                                     *}
  4259 text{* And so we have continuity of inverse.                                     *}
  4247 
  4260 
  4248 lemma Lim_inv:
  4261 lemma Lim_inv:
  4249   fixes f :: "'a \<Rightarrow> real"
  4262   fixes f :: "'a \<Rightarrow> real"
  4250   assumes "((vec1 o f) ---> vec1 l) (net::'a net)"  "l \<noteq> 0"
  4263   assumes "(f ---> l) (net::'a net)"  "l \<noteq> 0"
  4251   shows "((vec1 o inverse o f) ---> vec1(inverse l)) net"
  4264   shows "((inverse o f) ---> inverse l) net"
  4252 proof -
  4265   unfolding o_def using assms by (rule tendsto_inverse)
  4253   { fix e::real assume "e>0"
       
  4254     let ?d = "min (\<bar>l\<bar> / 2) (l\<twosuperior> * e / 2)"
       
  4255     have "0 < ?d" using `l\<noteq>0` `e>0` mult_pos_pos[of "l^2" "e/2"] by auto
       
  4256     with assms(1) have "eventually (\<lambda>x. dist ((vec1 o f) x) (vec1 l) < ?d) net"
       
  4257       by (rule tendstoD)
       
  4258     moreover
       
  4259     { fix x assume "dist ((vec1 o f) x) (vec1 l) < ?d"
       
  4260       hence *:"\<bar>f x - l\<bar> < min (\<bar>l\<bar> / 2) (l\<twosuperior> * e / 2)" unfolding o_def dist_vec1 by auto
       
  4261       hence fx0:"f x \<noteq> 0" using `l \<noteq> 0` by auto
       
  4262       hence fxl0: "(f x) * l \<noteq> 0" using `l \<noteq> 0` by auto
       
  4263       from * have **:"\<bar>f x - l\<bar> < l\<twosuperior> * e / 2" by auto
       
  4264       have "\<bar>f x\<bar> * 2 \<ge> \<bar>l\<bar>" using * by (auto simp del: less_divide_eq_number_of1)
       
  4265       hence "\<bar>f x\<bar> * 2 * \<bar>l\<bar>  \<ge> \<bar>l\<bar> * \<bar>l\<bar>" unfolding mult_le_cancel_right by auto
       
  4266       hence "\<bar>f x * l\<bar> * 2  \<ge> \<bar>l\<bar>^2" unfolding real_mult_commute and power2_eq_square by auto
       
  4267       hence ***:"inverse \<bar>f x * l\<bar> \<le> inverse (l\<twosuperior> / 2)" using fxl0
       
  4268 	using le_imp_inverse_le[of "l^2 / 2" "\<bar>f x * l\<bar>"]  by auto
       
  4269 
       
  4270       have "dist ((vec1 \<circ> inverse \<circ> f) x) (vec1 (inverse l)) < e" unfolding o_def unfolding dist_vec1
       
  4271 	unfolding inverse_diff_inverse[OF fx0 `l\<noteq>0`] apply simp
       
  4272 	unfolding mult_commute[of "inverse (f x)"]
       
  4273 	unfolding real_divide_def[THEN sym]
       
  4274 	unfolding divide_divide_eq_left
       
  4275 	unfolding nonzero_abs_divide[OF fxl0]
       
  4276 	using mult_less_le_imp_less[OF **, of "inverse \<bar>f x * l\<bar>", of "inverse (l^2 / 2)"] using *** using fx0 `l\<noteq>0`
       
  4277 	unfolding inverse_eq_divide using `e>0` by auto
       
  4278     }
       
  4279     ultimately
       
  4280     have "eventually (\<lambda>x. dist ((vec1 o inverse o f) x) (vec1(inverse l)) < e) net"
       
  4281       by (auto elim: eventually_rev_mono)
       
  4282   }
       
  4283   thus ?thesis unfolding tendsto_iff by auto
       
  4284 qed
       
  4285 
  4266 
  4286 lemma continuous_inv:
  4267 lemma continuous_inv:
  4287   fixes f :: "'a::metric_space \<Rightarrow> real"
  4268   fixes f :: "'a::metric_space \<Rightarrow> real"
  4288   shows "continuous net (vec1 o f) \<Longrightarrow> f(netlimit net) \<noteq> 0
  4269   shows "continuous net f \<Longrightarrow> f(netlimit net) \<noteq> 0
  4289            ==> continuous net (vec1 o inverse o f)"
  4270            ==> continuous net (inverse o f)"
  4290   unfolding continuous_def using Lim_inv by auto
  4271   unfolding continuous_def using Lim_inv by auto
  4291 
  4272 
  4292 lemma continuous_at_within_inv:
  4273 lemma continuous_at_within_inv:
  4293   fixes f :: "real ^ _ \<Rightarrow> real"
  4274   fixes f :: "real ^ _ \<Rightarrow> real"
  4294   assumes "continuous (at a within s) (vec1 o f)" "f a \<noteq> 0"
  4275   assumes "continuous (at a within s) f" "f a \<noteq> 0"
  4295   shows "continuous (at a within s) (vec1 o inverse o f)"
  4276   shows "continuous (at a within s) (inverse o f)"
  4296   using assms unfolding continuous_within o_apply
  4277   using assms unfolding continuous_within o_apply
  4297   by (rule Lim_inv)
  4278   by (rule Lim_inv)
  4298 
  4279 
  4299 lemma continuous_at_inv:
  4280 lemma continuous_at_inv:
  4300   fixes f :: "real ^ _ \<Rightarrow> real"
  4281   fixes f :: "real ^ _ \<Rightarrow> real"
  4301   shows "continuous (at a) (vec1 o f) \<Longrightarrow> f a \<noteq> 0
  4282   shows "continuous (at a) f \<Longrightarrow> f a \<noteq> 0
  4302          ==> continuous (at a) (vec1 o inverse o f) "
  4283          ==> continuous (at a) (inverse o f) "
  4303   using within_UNIV[THEN sym, of "at a"] using continuous_at_within_inv[of a UNIV] by auto
  4284   using within_UNIV[THEN sym, of "at a"] using continuous_at_within_inv[of a UNIV] by auto
  4304 
  4285 
  4305 subsection{* Preservation properties for pasted sets.                                  *}
  4286 subsection{* Preservation properties for pasted sets.                                  *}
  4306 
  4287 
  4307 lemma bounded_pastecart:
  4288 lemma bounded_pastecart:
  4405 qed
  4386 qed
  4406 
  4387 
  4407 text{* Hence we get the following.                                               *}
  4388 text{* Hence we get the following.                                               *}
  4408 
  4389 
  4409 lemma compact_sup_maxdistance:
  4390 lemma compact_sup_maxdistance:
  4410   fixes s :: "(real ^ _) set"
  4391   fixes s :: "(real ^ 'n::finite) set"
  4411   assumes "compact s"  "s \<noteq> {}"
  4392   assumes "compact s"  "s \<noteq> {}"
  4412   shows "\<exists>x\<in>s. \<exists>y\<in>s. \<forall>u\<in>s. \<forall>v\<in>s. norm(u - v) \<le> norm(x - y)"
  4393   shows "\<exists>x\<in>s. \<exists>y\<in>s. \<forall>u\<in>s. \<forall>v\<in>s. norm(u - v) \<le> norm(x - y)"
  4413 proof-
  4394 proof-
  4414   have "{x - y | x y . x\<in>s \<and> y\<in>s} \<noteq> {}" using `s \<noteq> {}` by auto
  4395   have "{x - y | x y . x\<in>s \<and> y\<in>s} \<noteq> {}" using `s \<noteq> {}` by auto
  4415   then obtain x where x:"x\<in>{x - y |x y. x \<in> s \<and> y \<in> s}"  "\<forall>y\<in>{x - y |x y. x \<in> s \<and> y \<in> s}. norm y \<le> norm x"
  4396   then obtain x where x:"x\<in>{x - y |x y. x \<in> s \<and> y \<in> s}"  "\<forall>y\<in>{x - y |x y. x \<in> s \<and> y \<in> s}. norm y \<le> norm x"
  4416     using compact_differences[OF assms(1) assms(1)]
  4397     using compact_differences[OF assms(1) assms(1)]
  4417     using distance_attains_sup[unfolded dist_norm, of "{x - y | x y . x\<in>s \<and> y\<in>s}" 0] by(auto simp add: norm_minus_cancel)
  4398     using distance_attains_sup[where 'a="real ^ 'n", unfolded dist_norm, of "{x - y | x y . x\<in>s \<and> y\<in>s}" 0] by(auto simp add: norm_minus_cancel)
  4418   from x(1) obtain a b where "a\<in>s" "b\<in>s" "x = a - b" by auto
  4399   from x(1) obtain a b where "a\<in>s" "b\<in>s" "x = a - b" by auto
  4419   thus ?thesis using x(2)[unfolded `x = a - b`] by blast
  4400   thus ?thesis using x(2)[unfolded `x = a - b`] by blast
  4420 qed
  4401 qed
  4421 
  4402 
  4422 text{* We can state this in terms of diameter of a set.                          *}
  4403 text{* We can state this in terms of diameter of a set.                          *}
  4963       { fix e::real assume "e>0"
  4944       { fix e::real assume "e>0"
  4964 	hence "\<exists>N::nat. inverse (real (N + 1)) < e" using real_arch_inv[of e] apply (auto simp add: Suc_pred') apply(rule_tac x="n - 1" in exI) by auto
  4945 	hence "\<exists>N::nat. inverse (real (N + 1)) < e" using real_arch_inv[of e] apply (auto simp add: Suc_pred') apply(rule_tac x="n - 1" in exI) by auto
  4965 	then obtain N::nat where "inverse (real (N + 1)) < e" by auto
  4946 	then obtain N::nat where "inverse (real (N + 1)) < e" by auto
  4966 	hence "\<forall>n\<ge>N. inverse (real n + 1) < e" by (auto, metis Suc_le_mono le_SucE less_imp_inverse_less nat_le_real_less order_less_trans real_of_nat_Suc real_of_nat_Suc_gt_zero)
  4947 	hence "\<forall>n\<ge>N. inverse (real n + 1) < e" by (auto, metis Suc_le_mono le_SucE less_imp_inverse_less nat_le_real_less order_less_trans real_of_nat_Suc real_of_nat_Suc_gt_zero)
  4967 	hence "\<exists>N::nat. \<forall>n\<ge>N. inverse (real n + 1) < e" by auto  }
  4948 	hence "\<exists>N::nat. \<forall>n\<ge>N. inverse (real n + 1) < e" by auto  }
  4968       hence "((vec1 \<circ> (\<lambda>n. inverse (real n + 1))) ---> vec1 0) sequentially"
  4949       hence "((\<lambda>n. inverse (real n + 1)) ---> 0) sequentially"
  4969 	unfolding Lim_sequentially by(auto simp add: dist_vec1)
  4950 	unfolding Lim_sequentially by(auto simp add: dist_norm)
  4970       hence "(f ---> x) sequentially" unfolding f_def
  4951       hence "(f ---> x) sequentially" unfolding f_def
  4971 	using Lim_add[OF Lim_const, of "\<lambda>n::nat. (inverse (real n + 1)) *s ((1 / 2) *s (a + b) - x)" 0 sequentially x]
  4952 	using Lim_add[OF Lim_const, of "\<lambda>n::nat. (inverse (real n + 1)) *s ((1 / 2) *s (a + b) - x)" 0 sequentially x]
  4972 	using Lim_vmul[of "\<lambda>n::nat. inverse (real n + 1)" 0 sequentially "((1 / 2) *s (a + b) - x)"] by auto  }
  4953 	using Lim_vmul[of "\<lambda>n::nat. inverse (real n + 1)" 0 sequentially "((1 / 2) *s (a + b) - x)"] by auto  }
  4973     ultimately have "x \<in> closure {a<..<b}"
  4954     ultimately have "x \<in> closure {a<..<b}"
  4974       using as and open_interval_midpoint[OF assms] unfolding closure_def unfolding islimpt_sequential by(cases "x=?c")auto  }
  4955       using as and open_interval_midpoint[OF assms] unfolding closure_def unfolding islimpt_sequential by(cases "x=?c")auto  }