author wenzelm Thu Aug 29 19:20:35 2013 +0200 (2013-08-29) changeset 53282 9d6e263fa921 parent 53281 251e1a2aa792 child 53283 be0491d86d19
tuned proofs;
```     1.1 --- a/src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy	Thu Aug 29 15:53:56 2013 +0200
1.2 +++ b/src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy	Thu Aug 29 19:20:35 2013 +0200
1.3 @@ -30,7 +30,7 @@
1.4
1.5  lemmas real_isGlb_unique = isGlb_unique[where 'a=real]
1.6
1.7 -lemma countable_PiE:
1.8 +lemma countable_PiE:
1.9    "finite I \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> countable (F i)) \<Longrightarrow> countable (PiE I F)"
1.10    by (induct I arbitrary: F rule: finite_induct) (auto simp: PiE_insert_eq)
1.11
1.12 @@ -77,45 +77,48 @@
1.13  proof safe
1.14    fix O' and x::'a
1.15    assume H: "topological_basis B" "open O'" "x \<in> O'"
1.16 -  hence "(\<exists>B'\<subseteq>B. \<Union>B' = O')" by (simp add: topological_basis_def)
1.17 +  then have "(\<exists>B'\<subseteq>B. \<Union>B' = O')" by (simp add: topological_basis_def)
1.18    then obtain B' where "B' \<subseteq> B" "O' = \<Union>B'" by auto
1.19 -  thus "\<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'" using H by auto
1.20 +  then show "\<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'" using H by auto
1.21  next
1.22    assume H: ?rhs
1.23 -  show "topological_basis B" using assms unfolding topological_basis_def
1.24 +  show "topological_basis B"
1.25 +    using assms unfolding topological_basis_def
1.26    proof safe
1.27 -    fix O'::"'a set" assume "open O'"
1.28 +    fix O'::"'a set"
1.29 +    assume "open O'"
1.30      with H obtain f where "\<forall>x\<in>O'. f x \<in> B \<and> x \<in> f x \<and> f x \<subseteq> O'"
1.31        by (force intro: bchoice simp: Bex_def)
1.32 -    thus "\<exists>B'\<subseteq>B. \<Union>B' = O'"
1.33 +    then show "\<exists>B'\<subseteq>B. \<Union>B' = O'"
1.34        by (auto intro: exI[where x="{f x |x. x \<in> O'}"])
1.35    qed
1.36  qed
1.37
1.38  lemma topological_basisI:
1.39    assumes "\<And>B'. B' \<in> B \<Longrightarrow> open B'"
1.40 -  assumes "\<And>O' x. open O' \<Longrightarrow> x \<in> O' \<Longrightarrow> \<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'"
1.41 +    and "\<And>O' x. open O' \<Longrightarrow> x \<in> O' \<Longrightarrow> \<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'"
1.42    shows "topological_basis B"
1.43    using assms by (subst topological_basis_iff) auto
1.44
1.45  lemma topological_basisE:
1.46    fixes O'
1.47    assumes "topological_basis B"
1.48 -  assumes "open O'"
1.49 -  assumes "x \<in> O'"
1.50 +    and "open O'"
1.51 +    and "x \<in> O'"
1.52    obtains B' where "B' \<in> B" "x \<in> B'" "B' \<subseteq> O'"
1.53  proof atomize_elim
1.54 -  from assms have "\<And>B'. B'\<in>B \<Longrightarrow> open B'" by (simp add: topological_basis_def)
1.55 +  from assms have "\<And>B'. B'\<in>B \<Longrightarrow> open B'"
1.56 +    by (simp add: topological_basis_def)
1.57    with topological_basis_iff assms
1.58 -  show  "\<exists>B'. B' \<in> B \<and> x \<in> B' \<and> B' \<subseteq> O'" using assms by (simp add: Bex_def)
1.59 +  show  "\<exists>B'. B' \<in> B \<and> x \<in> B' \<and> B' \<subseteq> O'"
1.60 +    using assms by (simp add: Bex_def)
1.61  qed
1.62
1.63  lemma topological_basis_open:
1.64    assumes "topological_basis B"
1.65 -  assumes "X \<in> B"
1.66 +    and "X \<in> B"
1.67    shows "open X"
1.68 -  using assms
1.69 -  by (simp add: topological_basis_def)
1.70 +  using assms by (simp add: topological_basis_def)
1.71
1.72  lemma topological_basis_imp_subbasis:
1.73    assumes B: "topological_basis B"
1.74 @@ -179,7 +182,7 @@
1.75  locale countable_basis =
1.76    fixes B::"'a::topological_space set set"
1.77    assumes is_basis: "topological_basis B"
1.78 -  assumes countable_basis: "countable B"
1.79 +    and countable_basis: "countable B"
1.80  begin
1.81
1.82  lemma open_countable_basis_ex:
1.83 @@ -275,7 +278,8 @@
1.84    fix x :: "'a \<times> 'b"
1.85    from first_countable_basisE[of "fst x"] guess A :: "'a set set" . note A = this
1.86    from first_countable_basisE[of "snd x"] guess B :: "'b set set" . note B = this
1.87 -  show "\<exists>A::nat \<Rightarrow> ('a \<times> 'b) set. (\<forall>i. x \<in> A i \<and> open (A i)) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>i. A i \<subseteq> S))"
1.88 +  show "\<exists>A::nat \<Rightarrow> ('a \<times> 'b) set.
1.89 +    (\<forall>i. x \<in> A i \<and> open (A i)) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>i. A i \<subseteq> S))"
1.90    proof (rule first_countableI[of "(\<lambda>(a, b). a \<times> b) ` (A \<times> B)"], safe)
1.91      fix a b
1.92      assume x: "a \<in> A" "b \<in> B"
1.93 @@ -293,7 +297,8 @@
1.94  qed
1.95
1.96  class second_countable_topology = topological_space +
1.97 -  assumes ex_countable_subbasis: "\<exists>B::'a::topological_space set set. countable B \<and> open = generate_topology B"
1.98 +  assumes ex_countable_subbasis:
1.99 +    "\<exists>B::'a::topological_space set set. countable B \<and> open = generate_topology B"
1.100  begin
1.101
1.102  lemma ex_countable_basis: "\<exists>B::'a set set. countable B \<and> topological_basis B"
1.103 @@ -337,7 +342,7 @@
1.104          unfolding subset_image_iff by blast }
1.105      then show "topological_basis ?B"
1.106        unfolding topological_space_class.topological_basis_def
1.107 -      by (safe intro!: topological_space_class.open_Inter)
1.108 +      by (safe intro!: topological_space_class.open_Inter)
1.109           (simp_all add: B generate_topology.Basis subset_eq)
1.110    qed
1.111  qed
1.112 @@ -368,7 +373,8 @@
1.113    then have B: "countable B" "topological_basis B"
1.114      using countable_basis is_basis
1.115      by (auto simp: countable_basis is_basis)
1.116 -  then show "\<exists>A::nat \<Rightarrow> 'a set. (\<forall>i. x \<in> A i \<and> open (A i)) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>i. A i \<subseteq> S))"
1.117 +  then show "\<exists>A::nat \<Rightarrow> 'a set.
1.118 +    (\<forall>i. x \<in> A i \<and> open (A i)) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>i. A i \<subseteq> S))"
1.119      by (intro first_countableI[of "{b\<in>B. x \<in> b}"])
1.120         (fastforce simp: topological_space_class.topological_basis_def)+
1.121  qed
1.122 @@ -418,11 +424,11 @@
1.123
1.124  lemma openin_clauses:
1.125    fixes U :: "'a topology"
1.126 -  shows "openin U {}"
1.127 -  "\<And>S T. openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S\<inter>T)"
1.128 -  "\<And>K. (\<forall>S \<in> K. openin U S) \<Longrightarrow> openin U (\<Union>K)"
1.129 -  using openin[of U] unfolding istopology_def mem_Collect_eq
1.130 -  by fast+
1.131 +  shows
1.132 +    "openin U {}"
1.133 +    "\<And>S T. openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S\<inter>T)"
1.134 +    "\<And>K. (\<forall>S \<in> K. openin U S) \<Longrightarrow> openin U (\<Union>K)"
1.135 +  using openin[of U] unfolding istopology_def mem_Collect_eq by fast+
1.136
1.137  lemma openin_subset[intro]: "openin U S \<Longrightarrow> S \<subseteq> topspace U"
1.138    unfolding topspace_def by blast
1.139 @@ -502,7 +508,8 @@
1.140  proof -
1.141    have "S - T = S \<inter> (topspace U - T)" using openin_subset[of U S]  oS cT
1.142      by (auto simp add: topspace_def openin_subset)
1.143 -  then show ?thesis using oS cT by (auto simp add: closedin_def)
1.144 +  then show ?thesis using oS cT
1.145 +    by (auto simp add: closedin_def)
1.146  qed
1.147
1.148  lemma closedin_diff[intro]:
1.149 @@ -511,8 +518,7 @@
1.150    shows "closedin U (S - T)"
1.151  proof -
1.152    have "S - T = S \<inter> (topspace U - T)"
1.153 -    using closedin_subset[of U S] oS cT
1.154 -    by (auto simp add: topspace_def)
1.155 +    using closedin_subset[of U S] oS cT by (auto simp add: topspace_def)
1.156    then show ?thesis
1.157      using oS cT by (auto simp add: openin_closedin_eq)
1.158  qed
1.159 @@ -537,7 +543,8 @@
1.160    }
1.161    moreover
1.162    {
1.163 -    fix K assume K: "K \<subseteq> Collect ?L"
1.164 +    fix K
1.165 +    assume K: "K \<subseteq> Collect ?L"
1.166      have th0: "Collect ?L = (\<lambda>S. S \<inter> V) ` Collect (openin U)"
1.167        apply (rule set_eqI)
1.168        apply (simp add: Ball_def image_iff)
1.169 @@ -663,7 +670,8 @@
1.170  lemma closedin_closed_Int: "closed S ==> closedin (subtopology euclidean U) (U \<inter> S)"
1.171    by (metis closedin_closed)
1.172
1.173 -lemma closed_closedin_trans: "closed S \<Longrightarrow> closed T \<Longrightarrow> T \<subseteq> S \<Longrightarrow> closedin (subtopology euclidean S) T"
1.174 +lemma closed_closedin_trans:
1.175 +  "closed S \<Longrightarrow> closed T \<Longrightarrow> T \<subseteq> S \<Longrightarrow> closedin (subtopology euclidean S) T"
1.176    apply (subgoal_tac "S \<inter> T = T" )
1.177    apply auto
1.178    apply (frule closedin_closed_Int[of T S])
1.179 @@ -680,7 +688,8 @@
1.180    (is "?lhs \<longleftrightarrow> ?rhs")
1.181  proof
1.182    assume ?lhs
1.183 -  then show ?rhs unfolding openin_open open_dist by blast
1.184 +  then show ?rhs
1.185 +    unfolding openin_open open_dist by blast
1.186  next
1.187    def T \<equiv> "{x. \<exists>a\<in>S. \<exists>d>0. (\<forall>y\<in>U. dist y a < d \<longrightarrow> y \<in> S) \<and> dist x a < d}"
1.188    have 1: "\<forall>x\<in>T. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> T"
1.189 @@ -692,7 +701,7 @@
1.190      apply (rule_tac x=d in exI, clarify)
1.191      apply (erule le_less_trans [OF dist_triangle])
1.192      done
1.193 -  assume ?rhs hence 2: "S = U \<inter> T"
1.194 +  assume ?rhs then have 2: "S = U \<inter> T"
1.195      unfolding T_def
1.196      apply auto
1.197      apply (drule (1) bspec, erule rev_bexI)
1.198 @@ -754,10 +763,10 @@
1.199  lemma ball_subset_cball[simp,intro]: "ball x e \<subseteq> cball x e"
1.200    by (simp add: subset_eq)
1.201
1.202 -lemma subset_ball[intro]: "d <= e ==> ball x d \<subseteq> ball x e"
1.203 +lemma subset_ball[intro]: "d \<le> e \<Longrightarrow> ball x d \<subseteq> ball x e"
1.204    by (simp add: subset_eq)
1.205
1.206 -lemma subset_cball[intro]: "d <= e ==> cball x d \<subseteq> cball x e"
1.207 +lemma subset_cball[intro]: "d \<le> e \<Longrightarrow> cball x d \<subseteq> cball x e"
1.208    by (simp add: subset_eq)
1.209
1.210  lemma ball_max_Un: "ball a (max r s) = ball a r \<union> ball a s"
1.211 @@ -796,7 +805,7 @@
1.212    unfolding open_dist subset_eq mem_ball Ball_def dist_commute ..
1.213
1.214  lemma openE[elim?]:
1.215 -  assumes "open S" "x\<in>S"
1.216 +  assumes "open S" "x\<in>S"
1.217    obtains e where "e>0" "ball x e \<subseteq> S"
1.218    using assms unfolding open_contains_ball by auto
1.219
1.220 @@ -876,7 +885,7 @@
1.221
1.222  lemma open_UNION_box:
1.223    fixes M :: "'a\<Colon>euclidean_space set"
1.224 -  assumes "open M"
1.225 +  assumes "open M"
1.226    defines "a' \<equiv> \<lambda>f :: 'a \<Rightarrow> real \<times> real. (\<Sum>(i::'a)\<in>Basis. fst (f i) *\<^sub>R i)"
1.227    defines "b' \<equiv> \<lambda>f :: 'a \<Rightarrow> real \<times> real. (\<Sum>(i::'a)\<in>Basis. snd (f i) *\<^sub>R i)"
1.228    defines "I \<equiv> {f\<in>Basis \<rightarrow>\<^sub>E \<rat> \<times> \<rat>. box (a' f) (b' f) \<subseteq> M}"
1.229 @@ -886,8 +895,11 @@
1.230      fix x assume "x \<in> M"
1.231      obtain e where e: "e > 0" "ball x e \<subseteq> M"
1.232        using openE[OF `open M` `x \<in> M`] by auto
1.233 -    moreover then obtain a b where ab: "x \<in> box a b"
1.234 -      "\<forall>i \<in> Basis. a \<bullet> i \<in> \<rat>" "\<forall>i\<in>Basis. b \<bullet> i \<in> \<rat>" "box a b \<subseteq> ball x e"
1.235 +    moreover obtain a b where ab:
1.236 +      "x \<in> box a b"
1.237 +      "\<forall>i \<in> Basis. a \<bullet> i \<in> \<rat>"
1.238 +      "\<forall>i\<in>Basis. b \<bullet> i \<in> \<rat>"
1.239 +      "box a b \<subseteq> ball x e"
1.240        using rational_boxes[OF e(1)] by metis
1.241      ultimately have "x \<in> (\<Union>f\<in>I. box (a' f) (b' f))"
1.242         by (intro UN_I[of "\<lambda>i\<in>Basis. (a \<bullet> i, b \<bullet> i)"])
1.243 @@ -908,7 +920,10 @@
1.244        e1 \<inter> e2 = {} \<and>
1.245        e1 \<noteq> {} \<and>
1.246        e2 \<noteq> {})"
1.247 -  unfolding connected_def openin_open by (safe, blast+)
1.248 +  unfolding connected_def openin_open
1.249 +  apply safe
1.250 +  apply blast+
1.251 +  done
1.252
1.253  lemma exists_diff:
1.254    fixes P :: "'a set \<Rightarrow> bool"
1.255 @@ -938,7 +953,7 @@
1.256      apply (subst exists_diff)
1.257      apply blast
1.258      done
1.259 -  hence th0: "connected S \<longleftrightarrow>
1.260 +  then have th0: "connected S \<longleftrightarrow>
1.261      \<not> (\<exists>e2 e1. closed e2 \<and> open e1 \<and> S \<subseteq> e1 \<union> (- e2) \<and> e1 \<inter> (- e2) \<inter> S = {} \<and> e1 \<inter> S \<noteq> {} \<and> (- e2) \<inter> S \<noteq> {})"
1.262      (is " _ \<longleftrightarrow> \<not> (\<exists>e2 e1. ?P e2 e1)")
1.263      apply (simp add: closed_def)
1.264 @@ -951,7 +966,7 @@
1.265      fix e2
1.266      {
1.267        fix e1
1.268 -      have "?P e2 e1 \<longleftrightarrow> (\<exists>t.  closed e2 \<and> t = S\<inter>e2 \<and> open e1 \<and> t = S\<inter>e1 \<and> t\<noteq>{} \<and> t\<noteq>S)"
1.269 +      have "?P e2 e1 \<longleftrightarrow> (\<exists>t. closed e2 \<and> t = S\<inter>e2 \<and> open e1 \<and> t = S\<inter>e1 \<and> t\<noteq>{} \<and> t \<noteq> S)"
1.270          by auto
1.271      }
1.272      then have "(\<exists>e1. ?P e2 e1) \<longleftrightarrow> (\<exists>t. ?Q e2 t)"
1.273 @@ -969,7 +984,7 @@
1.274
1.275  subsection{* Limit points *}
1.276
1.277 -definition (in topological_space) islimpt:: "'a \<Rightarrow> 'a set \<Rightarrow> bool" (infixr "islimpt" 60)
1.278 +definition (in topological_space) islimpt:: "'a \<Rightarrow> 'a set \<Rightarrow> bool"  (infixr "islimpt" 60)
1.279    where "x islimpt S \<longleftrightarrow> (\<forall>T. x\<in>T \<longrightarrow> open T \<longrightarrow> (\<exists>y\<in>S. y\<in>T \<and> y\<noteq>x))"
1.280
1.281  lemma islimptI:
1.282 @@ -1068,12 +1083,12 @@
1.283      fix x
1.284      assume C: "\<forall>e>0. \<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e"
1.285      from e have e2: "e/2 > 0" by arith
1.286 -    from C[rule_format, OF e2] obtain y where y: "y \<in> S" "y\<noteq>x" "dist y x < e/2"
1.287 +    from C[rule_format, OF e2] obtain y where y: "y \<in> S" "y \<noteq> x" "dist y x < e/2"
1.288        by blast
1.289      let ?m = "min (e/2) (dist x y) "
1.290      from e2 y(2) have mp: "?m > 0"
1.291        by (simp add: dist_nz[THEN sym])
1.292 -    from C[rule_format, OF mp] obtain z where z: "z \<in> S" "z\<noteq>x" "dist z x < ?m"
1.293 +    from C[rule_format, OF mp] obtain z where z: "z \<in> S" "z \<noteq> x" "dist z x < ?m"
1.294        by blast
1.295      have th: "dist z y < e" using z y
1.296        by (intro dist_triangle_lt [where z=x], simp)
1.297 @@ -1170,10 +1185,12 @@
1.298        assume "x \<notin> interior S"
1.299        with `x \<in> R` `open R` obtain y where "y \<in> R - S"
1.300          unfolding interior_def by fast
1.301 -      from `open R` `closed S` have "open (R - S)" by (rule open_Diff)
1.302 -      from `R \<subseteq> S \<union> T` have "R - S \<subseteq> T" by fast
1.303 -      from `y \<in> R - S` `open (R - S)` `R - S \<subseteq> T` `interior T = {}`
1.304 -      show "False" unfolding interior_def by fast
1.305 +      from `open R` `closed S` have "open (R - S)"
1.306 +        by (rule open_Diff)
1.307 +      from `R \<subseteq> S \<union> T` have "R - S \<subseteq> T"
1.308 +        by fast
1.309 +      from `y \<in> R - S` `open (R - S)` `R - S \<subseteq> T` `interior T = {}` show False
1.310 +        unfolding interior_def by fast
1.311      qed
1.312    qed
1.313  qed
1.314 @@ -1187,7 +1204,7 @@
1.315    fix T
1.316    assume "T \<subseteq> A \<times> B" and "open T"
1.317    then show "T \<subseteq> interior A \<times> interior B"
1.318 -  proof (safe)
1.319 +  proof safe
1.320      fix x y
1.321      assume "(x, y) \<in> T"
1.322      then obtain C D where "open C" "open D" "C \<times> D \<subseteq> T" "x \<in> C" "y \<in> D"
1.323 @@ -1271,7 +1288,7 @@
1.324    fix x
1.325    assume as: "open S" "x \<in> S \<inter> closure T"
1.326    {
1.327 -    assume *:"x islimpt T"
1.328 +    assume *: "x islimpt T"
1.329      have "x islimpt (S \<inter> T)"
1.330      proof (rule islimptI)
1.331        fix A
1.332 @@ -1302,7 +1319,9 @@
1.333      by (intro Sigma_mono closure_subset)
1.334    show "closed (closure A \<times> closure B)"
1.335      by (intro closed_Times closed_closure)
1.336 -  fix T assume "A \<times> B \<subseteq> T" and "closed T" thus "closure A \<times> closure B \<subseteq> T"
1.337 +  fix T
1.338 +  assume "A \<times> B \<subseteq> T" and "closed T"
1.339 +  then show "closure A \<times> closure B \<subseteq> T"
1.340      apply (simp add: closed_def open_prod_def, clarify)
1.341      apply (rule ccontr)
1.342      apply (drule_tac x="(a, b)" in bspec, simp, clarify, rename_tac C D)
1.343 @@ -1432,7 +1451,7 @@
1.344    "eventually P net \<Longrightarrow> (\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> eventually Q net"
1.345    using eventually_mono [of P Q] by fast
1.346
1.347 -lemma not_eventually: "(\<forall>x. \<not> P x ) \<Longrightarrow> ~(trivial_limit net) ==> ~(eventually (\<lambda>x. P x) net)"
1.348 +lemma not_eventually: "(\<forall>x. \<not> P x ) \<Longrightarrow> \<not> trivial_limit net \<Longrightarrow> \<not> eventually (\<lambda>x. P x) net"
1.349    by (simp add: eventually_False)
1.350
1.351
1.352 @@ -1481,7 +1500,7 @@
1.353    done
1.354
1.355  lemma Lim_Un_univ:
1.356 -  "(f ---> l) (at x within S) \<Longrightarrow> (f ---> l) (at x within T) \<Longrightarrow>
1.357 +  "(f ---> l) (at x within S) \<Longrightarrow> (f ---> l) (at x within T) \<Longrightarrow>
1.358      S \<union> T = UNIV \<Longrightarrow> (f ---> l) (at x)"
1.359    by (metis Lim_Un)
1.360
1.361 @@ -1537,7 +1556,8 @@
1.362    assume e: "{x<..} \<inter> I \<noteq> {}"
1.363    show ?thesis
1.364    proof (rule order_tendstoI)
1.365 -    fix a assume a: "a < Inf (f ` ({x<..} \<inter> I))"
1.366 +    fix a
1.367 +    assume a: "a < Inf (f ` ({x<..} \<inter> I))"
1.368      {
1.369        fix y
1.370        assume "y \<in> {x<..} \<inter> I"
1.371 @@ -1620,8 +1640,8 @@
1.372    fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
1.373    assumes "eventually (\<lambda>x. norm (f x) \<le> g x) net" "(g ---> 0) net"
1.374    shows "(f ---> 0) net"
1.375 +  using assms(2)
1.376  proof (rule metric_tendsto_imp_tendsto)
1.377 -  show "(g ---> 0) net" by fact
1.378    show "eventually (\<lambda>x. dist (f x) 0 \<le> dist (g x) 0) net"
1.379      using assms(1) by (rule eventually_elim1) (simp add: dist_norm)
1.380  qed
1.381 @@ -1717,7 +1737,9 @@
1.382  text{* Limit under bilinear function *}
1.383
1.384  lemma Lim_bilinear:
1.385 -  assumes "(f ---> l) net" and "(g ---> m) net" and "bounded_bilinear h"
1.386 +  assumes "(f ---> l) net"
1.387 +    and "(g ---> m) net"
1.388 +    and "bounded_bilinear h"
1.389    shows "((\<lambda>x. h (f x) (g x)) ---> (h l m)) net"
1.390    using `bounded_bilinear h` `(f ---> l) net` `(g ---> m) net`
1.391    by (rule bounded_bilinear.tendsto)
1.392 @@ -1733,7 +1755,7 @@
1.393  lemma Lim_at_zero:
1.394    fixes a :: "'a::real_normed_vector"
1.395    fixes l :: "'b::topological_space"
1.396 -  shows "(f ---> l) (at a) \<longleftrightarrow> ((\<lambda>x. f(a + x)) ---> l) (at 0)" (is "?lhs = ?rhs")
1.397 +  shows "(f ---> l) (at a) \<longleftrightarrow> ((\<lambda>x. f(a + x)) ---> l) (at 0)"
1.398    using LIM_offset_zero LIM_offset_zero_cancel ..
1.399
1.400  text{* It's also sometimes useful to extract the limit point from the filter. *}
1.401 @@ -1741,8 +1763,7 @@
1.402  abbreviation netlimit :: "'a::t2_space filter \<Rightarrow> 'a"
1.403    where "netlimit F \<equiv> Lim F (\<lambda>x. x)"
1.404
1.405 -lemma netlimit_within:
1.406 -  "\<not> trivial_limit (at a within S) \<Longrightarrow> netlimit (at a within S) = a"
1.407 +lemma netlimit_within: "\<not> trivial_limit (at a within S) \<Longrightarrow> netlimit (at a within S) = a"
1.408    by (rule tendsto_Lim) (auto intro: tendsto_intros)
1.409
1.410  lemma netlimit_at:
1.411 @@ -1776,8 +1797,9 @@
1.412    done
1.413
1.414  lemma Lim_transform_within:
1.415 -  assumes "0 < d" and "\<forall>x'\<in>S. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
1.416 -  and "(f ---> l) (at x within S)"
1.417 +  assumes "0 < d"
1.418 +    and "\<forall>x'\<in>S. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
1.419 +    and "(f ---> l) (at x within S)"
1.420    shows "(g ---> l) (at x within S)"
1.421  proof (rule Lim_transform_eventually)
1.422    show "eventually (\<lambda>x. f x = g x) (at x within S)"
1.423 @@ -1786,22 +1808,24 @@
1.424  qed
1.425
1.426  lemma Lim_transform_at:
1.427 -  assumes "0 < d" and "\<forall>x'. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
1.428 -  and "(f ---> l) (at x)"
1.429 +  assumes "0 < d"
1.430 +    and "\<forall>x'. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
1.431 +    and "(f ---> l) (at x)"
1.432    shows "(g ---> l) (at x)"
1.433 +  using _ assms(3)
1.434  proof (rule Lim_transform_eventually)
1.435    show "eventually (\<lambda>x. f x = g x) (at x)"
1.436      unfolding eventually_at2
1.437      using assms(1,2) by auto
1.438 -  show "(f ---> l) (at x)" by fact
1.439  qed
1.440
1.441  text{* Common case assuming being away from some crucial point like 0. *}
1.442
1.443  lemma Lim_transform_away_within:
1.444    fixes a b :: "'a::t1_space"
1.445 -  assumes "a \<noteq> b" and "\<forall>x\<in>S. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x"
1.446 -  and "(f ---> l) (at a within S)"
1.447 +  assumes "a \<noteq> b"
1.448 +    and "\<forall>x\<in>S. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x"
1.449 +    and "(f ---> l) (at a within S)"
1.450    shows "(g ---> l) (at a within S)"
1.451  proof (rule Lim_transform_eventually)
1.452    show "(f ---> l) (at a within S)" by fact
1.453 @@ -1821,8 +1845,9 @@
1.454  text{* Alternatively, within an open set. *}
1.455
1.456  lemma Lim_transform_within_open:
1.457 -  assumes "open S" and "a \<in> S" and "\<forall>x\<in>S. x \<noteq> a \<longrightarrow> f x = g x"
1.458 -  and "(f ---> l) (at a)"
1.459 +  assumes "open S" and "a \<in> S"
1.460 +    and "\<forall>x\<in>S. x \<noteq> a \<longrightarrow> f x = g x"
1.461 +    and "(f ---> l) (at a)"
1.462    shows "(g ---> l) (at a)"
1.463  proof (rule Lim_transform_eventually)
1.464    show "eventually (\<lambda>x. f x = g x) (at a)"
1.465 @@ -1836,15 +1861,17 @@
1.466  (* FIXME: Only one congruence rule for tendsto can be used at a time! *)
1.467
1.468  lemma Lim_cong_within(*[cong add]*):
1.469 -  assumes "a = b" "x = y" "S = T"
1.470 -  assumes "\<And>x. x \<noteq> b \<Longrightarrow> x \<in> T \<Longrightarrow> f x = g x"
1.471 +  assumes "a = b"
1.472 +    and "x = y"
1.473 +    and "S = T"
1.474 +    and "\<And>x. x \<noteq> b \<Longrightarrow> x \<in> T \<Longrightarrow> f x = g x"
1.475    shows "(f ---> x) (at a within S) \<longleftrightarrow> (g ---> y) (at b within T)"
1.476    unfolding tendsto_def eventually_at_topological
1.477    using assms by simp
1.478
1.479  lemma Lim_cong_at(*[cong add]*):
1.480    assumes "a = b" "x = y"
1.481 -  assumes "\<And>x. x \<noteq> a \<Longrightarrow> f x = g x"
1.482 +    and "\<And>x. x \<noteq> a \<Longrightarrow> f x = g x"
1.483    shows "((\<lambda>x. f x) ---> x) (at a) \<longleftrightarrow> ((g ---> y) (at a))"
1.484    unfolding tendsto_def eventually_at_topological
1.485    using assms by simp
1.486 @@ -1855,19 +1882,22 @@
1.487    fixes l :: "'a::first_countable_topology"
1.488    shows "l \<in> closure S \<longleftrightarrow> (\<exists>x. (\<forall>n. x n \<in> S) \<and> (x ---> l) sequentially)" (is "?lhs = ?rhs")
1.489  proof
1.490 -  assume "?lhs" moreover
1.491 -  { assume "l \<in> S"
1.492 -    hence "?rhs" using tendsto_const[of l sequentially] by auto
1.493 +  assume "?lhs"
1.494 +  moreover
1.495 +  {
1.496 +    assume "l \<in> S"
1.497 +    then have "?rhs" using tendsto_const[of l sequentially] by auto
1.498    }
1.499    moreover
1.500 -  { assume "l islimpt S"
1.501 -    hence "?rhs" unfolding islimpt_sequential by auto
1.502 +  {
1.503 +    assume "l islimpt S"
1.504 +    then have "?rhs" unfolding islimpt_sequential by auto
1.505    }
1.506    ultimately show "?rhs"
1.507      unfolding closure_def by auto
1.508  next
1.509    assume "?rhs"
1.510 -  thus "?lhs" unfolding closure_def islimpt_sequential by auto
1.511 +  then show "?lhs" unfolding closure_def islimpt_sequential by auto
1.512  qed
1.513
1.514  lemma closed_sequential_limits:
1.515 @@ -1898,7 +1928,8 @@
1.516    have *: "\<forall>x\<in>S. Inf S \<le> x"
1.517      using cInf_lower_EX[of _ S] assms by metis
1.518    {
1.519 -    fix e :: real assume "0 < e"
1.520 +    fix e :: real
1.521 +    assume "e > 0"
1.522      then have "Inf S < Inf S + e" by simp
1.523      with assms obtain x where "x \<in> S" "x < Inf S + e"
1.524        by (subst (asm) cInf_less_iff[of _ B]) auto
1.525 @@ -1920,9 +1951,11 @@
1.526    "(\<not> trivial_limit (at x within S)) = (\<forall>e>0. S \<inter> ball x e - {x} \<noteq> {})"
1.527    (is "?lhs = ?rhs")
1.528  proof -
1.529 -  { assume "?lhs"
1.530 -    { fix e :: real
1.531 -      assume "e>0"
1.532 +  {
1.533 +    assume "?lhs"
1.534 +    {
1.535 +      fix e :: real
1.536 +      assume "e > 0"
1.537        then obtain y where "y:(S-{x}) & dist y x < e"
1.538          using `?lhs` not_trivial_limit_within[of x S] closure_approachable[of x "S - {x}"]
1.539          by auto
1.540 @@ -1933,16 +1966,21 @@
1.541      then have "?rhs" by auto
1.542    }
1.543    moreover
1.544 -  { assume "?rhs"
1.545 -    { fix e :: real
1.546 -      assume "e>0"
1.547 -      then obtain y where "y : (S Int ball x e - {x})" using `?rhs` by blast
1.548 +  {
1.549 +    assume "?rhs"
1.550 +    {
1.551 +      fix e :: real
1.552 +      assume "e > 0"
1.553 +      then obtain y where "y : (S Int ball x e - {x})"
1.554 +        using `?rhs` by blast
1.555        then have "y:(S-{x}) & dist y x < e"
1.556          unfolding ball_def by (simp add: dist_commute)
1.557 -      then have "EX y:(S-{x}). dist y x < e" by auto
1.558 +      then have "EX y:(S-{x}). dist y x < e"
1.559 +        by auto
1.560      }
1.561      then have "?lhs"
1.562 -      using not_trivial_limit_within[of x S] closure_approachable[of x "S - {x}"] by auto
1.563 +      using not_trivial_limit_within[of x S] closure_approachable[of x "S - {x}"]
1.564 +      by auto
1.565    }
1.566    ultimately show ?thesis by auto
1.567  qed
1.568 @@ -1975,34 +2013,47 @@
1.569  lemma infdist_triangle: "infdist x A \<le> infdist y A + dist x y"
1.570  proof cases
1.571    assume "A = {}"
1.572 -  thus ?thesis by (simp add: infdist_def)
1.573 +  then show ?thesis by (simp add: infdist_def)
1.574  next
1.575    assume "A \<noteq> {}"
1.576    then obtain a where "a \<in> A" by auto
1.577    have "infdist x A \<le> Inf {dist x y + dist y a |a. a \<in> A}"
1.578    proof (rule cInf_greatest)
1.579 -    from `A \<noteq> {}` show "{dist x y + dist y a |a. a \<in> A} \<noteq> {}" by simp
1.580 -    fix d assume "d \<in> {dist x y + dist y a |a. a \<in> A}"
1.581 -    then obtain a where d: "d = dist x y + dist y a" "a \<in> A" by auto
1.582 +    from `A \<noteq> {}` show "{dist x y + dist y a |a. a \<in> A} \<noteq> {}"
1.583 +      by simp
1.584 +    fix d
1.585 +    assume "d \<in> {dist x y + dist y a |a. a \<in> A}"
1.586 +    then obtain a where d: "d = dist x y + dist y a" "a \<in> A"
1.587 +      by auto
1.588      show "infdist x A \<le> d"
1.589        unfolding infdist_notempty[OF `A \<noteq> {}`]
1.590      proof (rule cInf_lower2)
1.591 -      show "dist x a \<in> {dist x a |a. a \<in> A}" using `a \<in> A` by auto
1.592 -      show "dist x a \<le> d" unfolding d by (rule dist_triangle)
1.593 -      fix d assume "d \<in> {dist x a |a. a \<in> A}"
1.594 -      then obtain a where "a \<in> A" "d = dist x a" by auto
1.595 -      thus "infdist x A \<le> d" by (rule infdist_le)
1.596 +      show "dist x a \<in> {dist x a |a. a \<in> A}"
1.597 +        using `a \<in> A` by auto
1.598 +      show "dist x a \<le> d"
1.599 +        unfolding d by (rule dist_triangle)
1.600 +      fix d
1.601 +      assume "d \<in> {dist x a |a. a \<in> A}"
1.602 +      then obtain a where "a \<in> A" "d = dist x a"
1.603 +        by auto
1.604 +      then show "infdist x A \<le> d"
1.605 +        by (rule infdist_le)
1.606      qed
1.607    qed
1.608    also have "\<dots> = dist x y + infdist y A"
1.609    proof (rule cInf_eq, safe)
1.610 -    fix a assume "a \<in> A"
1.611 -    thus "dist x y + infdist y A \<le> dist x y + dist y a" by (auto intro: infdist_le)
1.612 +    fix a
1.613 +    assume "a \<in> A"
1.614 +    then show "dist x y + infdist y A \<le> dist x y + dist y a"
1.615 +      by (auto intro: infdist_le)
1.616    next
1.617 -    fix i assume inf: "\<And>d. d \<in> {dist x y + dist y a |a. a \<in> A} \<Longrightarrow> i \<le> d"
1.618 -    hence "i - dist x y \<le> infdist y A" unfolding infdist_notempty[OF `A \<noteq> {}`] using `a \<in> A`
1.619 +    fix i
1.620 +    assume inf: "\<And>d. d \<in> {dist x y + dist y a |a. a \<in> A} \<Longrightarrow> i \<le> d"
1.621 +    then have "i - dist x y \<le> infdist y A"
1.622 +      unfolding infdist_notempty[OF `A \<noteq> {}`] using `a \<in> A`
1.623        by (intro cInf_greatest) (auto simp: field_simps)
1.624 -    thus "i \<le> dist x y + infdist y A" by simp
1.625 +    then show "i \<le> dist x y + infdist y A"
1.626 +      by simp
1.627    qed
1.628    finally show ?thesis by simp
1.629  qed
1.630 @@ -2015,27 +2066,32 @@
1.631    show "infdist x A = 0"
1.632    proof (rule ccontr)
1.633      assume "infdist x A \<noteq> 0"
1.634 -    with infdist_nonneg[of x A] have "infdist x A > 0" by auto
1.635 -    hence "ball x (infdist x A) \<inter> closure A = {}"
1.636 +    with infdist_nonneg[of x A] have "infdist x A > 0"
1.637 +      by auto
1.638 +    then have "ball x (infdist x A) \<inter> closure A = {}"
1.639        apply auto
1.640        apply (metis `0 < infdist x A` `x \<in> closure A` closure_approachable dist_commute
1.641          eucl_less_not_refl euclidean_trans(2) infdist_le)
1.642        done
1.643 -    hence "x \<notin> closure A"
1.644 +    then have "x \<notin> closure A"
1.645        by (metis `0 < infdist x A` centre_in_ball disjoint_iff_not_equal)
1.646 -    thus False using `x \<in> closure A` by simp
1.647 +    then show False using `x \<in> closure A` by simp
1.648    qed
1.649  next
1.650    assume x: "infdist x A = 0"
1.651 -  then obtain a where "a \<in> A" by atomize_elim (metis all_not_in_conv assms)
1.652 -  show "x \<in> closure A" unfolding closure_approachable
1.653 -  proof (safe, rule ccontr)
1.654 -    fix e::real assume "0 < e"
1.655 +  then obtain a where "a \<in> A"
1.656 +    by atomize_elim (metis all_not_in_conv assms)
1.657 +  show "x \<in> closure A"
1.658 +    unfolding closure_approachable
1.659 +    apply safe
1.660 +  proof (rule ccontr)
1.661 +    fix e :: real
1.662 +    assume "e > 0"
1.663      assume "\<not> (\<exists>y\<in>A. dist y x < e)"
1.664 -    hence "infdist x A \<ge> e" using `a \<in> A`
1.665 +    then have "infdist x A \<ge> e" using `a \<in> A`
1.666        unfolding infdist_def
1.667        by (force simp: dist_commute intro: cInf_greatest)
1.668 -    with x `0 < e` show False by auto
1.669 +    with x `e > 0` show False by auto
1.670    qed
1.671  qed
1.672
1.673 @@ -2052,7 +2108,8 @@
1.674    assumes f: "(f ---> l) F"
1.675    shows "((\<lambda>x. infdist (f x) A) ---> infdist l A) F"
1.676  proof (rule tendstoI)
1.677 -  fix e ::real assume "0 < e"
1.678 +  fix e ::real
1.679 +  assume "e > 0"
1.680    from tendstoD[OF f this]
1.681    show "eventually (\<lambda>x. dist (infdist (f x) A) (infdist l A) < e) F"
1.682    proof (eventually_elim)
1.683 @@ -2111,13 +2168,13 @@
1.684    {
1.685      fix x and e::real
1.686      assume "x\<in>S" "e>0" "ball x e \<subseteq> S"
1.687 -    hence "\<exists>d>0. cball x d \<subseteq> S" unfolding subset_eq by (rule_tac x="e/2" in exI, auto)
1.688 +    then have "\<exists>d>0. cball x d \<subseteq> S" unfolding subset_eq by (rule_tac x="e/2" in exI, auto)
1.689    }
1.690    moreover
1.691    {
1.692      fix x and e::real
1.693      assume "x\<in>S" "e>0" "cball x e \<subseteq> S"
1.694 -    hence "\<exists>d>0. ball x d \<subseteq> S"
1.695 +    then have "\<exists>d>0. ball x d \<subseteq> S"
1.696        unfolding subset_eq
1.697        apply(rule_tac x="e/2" in exI)
1.698        apply auto
1.699 @@ -2142,11 +2199,14 @@
1.700    shows "y islimpt ball x e \<longleftrightarrow> 0 < e \<and> y \<in> cball x e" (is "?lhs = ?rhs")
1.701  proof
1.702    assume "?lhs"
1.703 -  { assume "e \<le> 0"
1.704 -    hence *:"ball x e = {}" using ball_eq_empty[of x e] by auto
1.705 -    have False using `?lhs` unfolding * using islimpt_EMPTY[of y] by auto
1.706 +  {
1.707 +    assume "e \<le> 0"
1.708 +    then have *:"ball x e = {}"
1.709 +      using ball_eq_empty[of x e] by auto
1.710 +    have False using `?lhs`
1.711 +      unfolding * using islimpt_EMPTY[of y] by auto
1.712    }
1.713 -  hence "e > 0" by (metis not_less)
1.714 +  then have "e > 0" by (metis not_less)
1.715    moreover
1.716    have "y \<in> cball x e"
1.717      using closed_cball[of x e] islimpt_subset[of y "ball x e" "cball x e"]
1.718 @@ -2154,44 +2214,62 @@
1.719      unfolding closed_limpt by auto
1.720    ultimately show "?rhs" by auto
1.721  next
1.722 -  assume "?rhs" hence "e>0"  by auto
1.723 -  { fix d::real assume "d>0"
1.724 +  assume "?rhs"
1.725 +  then have "e>0" by auto
1.726 +  {
1.727 +    fix d :: real
1.728 +    assume "d > 0"
1.729      have "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
1.730 -    proof(cases "d \<le> dist x y")
1.731 -      case True thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
1.732 -      proof(cases "x=y")
1.733 -        case True hence False using `d \<le> dist x y` `d>0` by auto
1.734 -        thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d" by auto
1.735 +    proof (cases "d \<le> dist x y")
1.736 +      case True
1.737 +      then show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
1.738 +      proof (cases "x = y")
1.739 +        case True
1.740 +        then have False
1.741 +          using `d \<le> dist x y` `d>0` by auto
1.742 +        then show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
1.743 +          by auto
1.744        next
1.745          case False
1.746 -
1.747 -        have "dist x (y - (d / (2 * dist y x)) *\<^sub>R (y - x))
1.748 -              = norm (x - y + (d / (2 * norm (y - x))) *\<^sub>R (y - x))"
1.749 -          unfolding mem_cball mem_ball dist_norm diff_diff_eq2 diff_add_eq[THEN sym] by auto
1.750 +        have "dist x (y - (d / (2 * dist y x)) *\<^sub>R (y - x)) =
1.751 +          norm (x - y + (d / (2 * norm (y - x))) *\<^sub>R (y - x))"
1.752 +          unfolding mem_cball mem_ball dist_norm diff_diff_eq2 diff_add_eq[THEN sym]
1.753 +          by auto
1.754          also have "\<dots> = \<bar>- 1 + d / (2 * norm (x - y))\<bar> * norm (x - y)"
1.755            using scaleR_left_distrib[of "- 1" "d / (2 * norm (y - x))", THEN sym, of "y - x"]
1.756            unfolding scaleR_minus_left scaleR_one
1.757            by (auto simp add: norm_minus_commute)
1.758          also have "\<dots> = \<bar>- norm (x - y) + d / 2\<bar>"
1.759            unfolding abs_mult_pos[of "norm (x - y)", OF norm_ge_zero[of "x - y"]]
1.760 -          unfolding distrib_right using `x\<noteq>y`[unfolded dist_nz, unfolded dist_norm] by auto
1.761 -        also have "\<dots> \<le> e - d/2" using `d \<le> dist x y` and `d>0` and `?rhs` by(auto simp add: dist_norm)
1.762 -        finally have "y - (d / (2 * dist y x)) *\<^sub>R (y - x) \<in> ball x e" using `d>0` by auto
1.763 -
1.764 +          unfolding distrib_right using `x\<noteq>y`[unfolded dist_nz, unfolded dist_norm]
1.765 +          by auto
1.766 +        also have "\<dots> \<le> e - d/2" using `d \<le> dist x y` and `d>0` and `?rhs`
1.767 +          by (auto simp add: dist_norm)
1.768 +        finally have "y - (d / (2 * dist y x)) *\<^sub>R (y - x) \<in> ball x e" using `d>0`
1.769 +          by auto
1.770          moreover
1.771 -
1.772          have "(d / (2*dist y x)) *\<^sub>R (y - x) \<noteq> 0"
1.773 -          using `x\<noteq>y`[unfolded dist_nz] `d>0` unfolding scaleR_eq_0_iff by (auto simp add: dist_commute)
1.774 +          using `x\<noteq>y`[unfolded dist_nz] `d>0` unfolding scaleR_eq_0_iff
1.775 +          by (auto simp add: dist_commute)
1.776          moreover
1.777 -        have "dist (y - (d / (2 * dist y x)) *\<^sub>R (y - x)) y < d" unfolding dist_norm apply simp unfolding norm_minus_cancel
1.778 -          using `d>0` `x\<noteq>y`[unfolded dist_nz] dist_commute[of x y]
1.779 -          unfolding dist_norm by auto
1.780 -        ultimately show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d" by (rule_tac  x="y - (d / (2*dist y x)) *\<^sub>R (y - x)" in bexI) auto
1.781 +        have "dist (y - (d / (2 * dist y x)) *\<^sub>R (y - x)) y < d"
1.782 +          unfolding dist_norm
1.783 +          apply simp
1.784 +          unfolding norm_minus_cancel
1.785 +          using `d > 0` `x\<noteq>y`[unfolded dist_nz] dist_commute[of x y]
1.786 +          unfolding dist_norm
1.787 +          apply auto
1.788 +          done
1.789 +        ultimately show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
1.790 +          apply (rule_tac x = "y - (d / (2*dist y x)) *\<^sub>R (y - x)" in bexI)
1.791 +          apply auto
1.792 +          done
1.793        qed
1.794      next
1.795 -      case False hence "d > dist x y" by auto
1.796 -      show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
1.797 -      proof(cases "x=y")
1.798 +      case False
1.799 +      then have "d > dist x y" by auto
1.800 +      show "\<exists>x' \<in> ball x e. x' \<noteq> y \<and> dist x' y < d"
1.801 +      proof (cases "x = y")
1.802          case True
1.803          obtain z where **: "z \<noteq> y" "dist z y < min e d"
1.804            using perfect_choose_dist[of "min e d" y]
1.805 @@ -2199,20 +2277,30 @@
1.806          show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
1.807            unfolding `x = y`
1.808            using `z \<noteq> y` **
1.809 -          by (rule_tac x=z in bexI, auto simp add: dist_commute)
1.810 +          apply (rule_tac x=z in bexI)
1.811 +          apply (auto simp add: dist_commute)
1.812 +          done
1.813        next
1.814 -        case False thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
1.815 -          using `d>0` `d > dist x y` `?rhs` by(rule_tac x=x in bexI, auto)
1.816 +        case False
1.817 +        then show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
1.818 +          using `d>0` `d > dist x y` `?rhs`
1.819 +          apply (rule_tac x=x in bexI)
1.820 +          apply auto
1.821 +          done
1.822        qed
1.823 -    qed  }
1.824 -  thus "?lhs" unfolding mem_cball islimpt_approachable mem_ball by auto
1.825 +    qed
1.826 +  }
1.827 +  then show "?lhs"
1.828 +    unfolding mem_cball islimpt_approachable mem_ball by auto
1.829  qed
1.830
1.831  lemma closure_ball_lemma:
1.832    fixes x y :: "'a::real_normed_vector"
1.833 -  assumes "x \<noteq> y" shows "y islimpt ball x (dist x y)"
1.834 +  assumes "x \<noteq> y"
1.835 +  shows "y islimpt ball x (dist x y)"
1.836  proof (rule islimptI)
1.837 -  fix T assume "y \<in> T" "open T"
1.838 +  fix T
1.839 +  assume "y \<in> T" "open T"
1.840    then obtain r where "0 < r" "\<forall>z. dist z y < r \<longrightarrow> z \<in> T"
1.841      unfolding open_dist by fast
1.842    (* choose point between x and y, within distance r of y. *)
1.843 @@ -2223,7 +2311,8 @@
1.844    have "dist z y < r"
1.845      unfolding z_def k_def using `0 < r`
1.846      by (simp add: dist_norm min_def)
1.847 -  hence "z \<in> T" using `\<forall>z. dist z y < r \<longrightarrow> z \<in> T` by simp
1.848 +  then have "z \<in> T"
1.849 +    using `\<forall>z. dist z y < r \<longrightarrow> z \<in> T` by simp
1.850    have "dist x z < dist x y"
1.851      unfolding z_def2 dist_norm
1.852      apply (simp add: norm_minus_commute)
1.853 @@ -2233,7 +2322,8 @@
1.854      apply (simp add: k_def divide_pos_pos zero_less_dist_iff `0 < r` `x \<noteq> y`)
1.855      apply (simp add: zero_less_dist_iff `x \<noteq> y`)
1.856      done
1.857 -  hence "z \<in> ball x (dist x y)" by simp
1.858 +  then have "z \<in> ball x (dist x y)"
1.859 +    by simp
1.860    have "z \<noteq> y"
1.861      unfolding z_def k_def using `x \<noteq> y` `0 < r`
1.862      by (simp add: min_def)
1.863 @@ -2265,51 +2355,72 @@
1.864    shows "interior (cball x e) = ball x e"
1.865  proof (cases "e\<ge>0")
1.866    case False note cs = this
1.867 -  from cs have "ball x e = {}" using ball_empty[of e x] by auto moreover
1.868 -  { fix y assume "y \<in> cball x e"
1.869 -    hence False unfolding mem_cball using dist_nz[of x y] cs by auto  }
1.870 -  hence "cball x e = {}" by auto
1.871 -  hence "interior (cball x e) = {}" using interior_empty by auto
1.872 +  from cs have "ball x e = {}"
1.873 +    using ball_empty[of e x] by auto
1.874 +  moreover
1.875 +  {
1.876 +    fix y
1.877 +    assume "y \<in> cball x e"
1.878 +    then have False
1.879 +      unfolding mem_cball using dist_nz[of x y] cs by auto
1.880 +  }
1.881 +  then have "cball x e = {}" by auto
1.882 +  then have "interior (cball x e) = {}"
1.883 +    using interior_empty by auto
1.884    ultimately show ?thesis by blast
1.885  next
1.886    case True note cs = this
1.887 -  have "ball x e \<subseteq> cball x e" using ball_subset_cball by auto moreover
1.888 -  { fix S y assume as: "S \<subseteq> cball x e" "open S" "y\<in>S"
1.889 -    then obtain d where "d>0" and d:"\<forall>x'. dist x' y < d \<longrightarrow> x' \<in> S" unfolding open_dist by blast
1.890 -
1.891 +  have "ball x e \<subseteq> cball x e"
1.892 +    using ball_subset_cball by auto
1.893 +  moreover
1.894 +  {
1.895 +    fix S y
1.896 +    assume as: "S \<subseteq> cball x e" "open S" "y\<in>S"
1.897 +    then obtain d where "d>0" and d: "\<forall>x'. dist x' y < d \<longrightarrow> x' \<in> S"
1.898 +      unfolding open_dist by blast
1.899      then obtain xa where xa_y: "xa \<noteq> y" and xa: "dist xa y < d"
1.900        using perfect_choose_dist [of d] by auto
1.901 -    have "xa\<in>S" using d[THEN spec[where x=xa]] using xa by(auto simp add: dist_commute)
1.902 -    hence xa_cball:"xa \<in> cball x e" using as(1) by auto
1.903 -
1.904 -    hence "y \<in> ball x e" proof(cases "x = y")
1.905 +    have "xa \<in> S"
1.906 +      using d[THEN spec[where x = xa]]
1.907 +      using xa by (auto simp add: dist_commute)
1.908 +    then have xa_cball: "xa \<in> cball x e"
1.909 +      using as(1) by auto
1.910 +    then have "y \<in> ball x e"
1.911 +    proof (cases "x = y")
1.912        case True
1.913 -      hence "e>0" using xa_y[unfolded dist_nz] xa_cball[unfolded mem_cball]
1.914 +      then have "e > 0"
1.915 +        using xa_y[unfolded dist_nz] xa_cball[unfolded mem_cball]
1.916          by (auto simp add: dist_commute)
1.917 -      thus "y \<in> ball x e" using `x = y ` by simp
1.918 +      then show "y \<in> ball x e"
1.919 +        using `x = y ` by simp
1.920      next
1.921        case False
1.922 -      have "dist (y + (d / 2 / dist y x) *\<^sub>R (y - x)) y < d" unfolding dist_norm
1.923 +      have "dist (y + (d / 2 / dist y x) *\<^sub>R (y - x)) y < d"
1.924 +        unfolding dist_norm
1.925          using `d>0` norm_ge_zero[of "y - x"] `x \<noteq> y` by auto
1.926 -      hence *:"y + (d / 2 / dist y x) *\<^sub>R (y - x) \<in> cball x e"
1.927 +      then have *: "y + (d / 2 / dist y x) *\<^sub>R (y - x) \<in> cball x e"
1.928          using d as(1)[unfolded subset_eq] by blast
1.929        have "y - x \<noteq> 0" using `x \<noteq> y` by auto
1.930 -      hence **:"d / (2 * norm (y - x)) > 0"
1.931 +      then have **:"d / (2 * norm (y - x)) > 0"
1.932          unfolding zero_less_norm_iff[THEN sym]
1.933          using `d>0` divide_pos_pos[of d "2*norm (y - x)"] by auto
1.934 -
1.935 -      have "dist (y + (d / 2 / dist y x) *\<^sub>R (y - x)) x = norm (y + (d / (2 * norm (y - x))) *\<^sub>R y - (d / (2 * norm (y - x))) *\<^sub>R x - x)"
1.936 +      have "dist (y + (d / 2 / dist y x) *\<^sub>R (y - x)) x =
1.937 +        norm (y + (d / (2 * norm (y - x))) *\<^sub>R y - (d / (2 * norm (y - x))) *\<^sub>R x - x)"
1.938          by (auto simp add: dist_norm algebra_simps)
1.939        also have "\<dots> = norm ((1 + d / (2 * norm (y - x))) *\<^sub>R (y - x))"
1.940          by (auto simp add: algebra_simps)
1.941        also have "\<dots> = \<bar>1 + d / (2 * norm (y - x))\<bar> * norm (y - x)"
1.942          using ** by auto
1.943 -      also have "\<dots> = (dist y x) + d/2"using ** by (auto simp add: distrib_right dist_norm)
1.944 -      finally have "e \<ge> dist x y +d/2" using *[unfolded mem_cball] by (auto simp add: dist_commute)
1.945 -      thus "y \<in> ball x e" unfolding mem_ball using `d>0` by auto
1.946 +      also have "\<dots> = (dist y x) + d/2"
1.947 +        using ** by (auto simp add: distrib_right dist_norm)
1.948 +      finally have "e \<ge> dist x y +d/2"
1.949 +        using *[unfolded mem_cball] by (auto simp add: dist_commute)
1.950 +      then show "y \<in> ball x e"
1.951 +        unfolding mem_ball using `d>0` by auto
1.952      qed
1.953    }
1.954 -  hence "\<forall>S \<subseteq> cball x e. open S \<longrightarrow> S \<subseteq> ball x e" by auto
1.955 +  then have "\<forall>S \<subseteq> cball x e. open S \<longrightarrow> S \<subseteq> ball x e"
1.956 +    by auto
1.957    ultimately show ?thesis
1.958      using interior_unique[of "ball x e" "cball x e"] using open_ball[of x e] by auto
1.959  qed
1.960 @@ -2335,7 +2446,7 @@
1.961    apply (metis zero_le_dist dist_self order_less_le_trans)
1.962    done
1.963
1.964 -lemma cball_empty: "e < 0 ==> cball x e = {}"
1.965 +lemma cball_empty: "e < 0 \<Longrightarrow> cball x e = {}"
1.966    by (simp add: cball_eq_empty)
1.967
1.968  lemma cball_eq_sing:
1.969 @@ -2345,7 +2456,8 @@
1.970    assume e: "0 < e"
1.971    obtain a where "a \<noteq> x" "dist a x < e"
1.972      using perfect_choose_dist [OF e] by auto
1.973 -  hence "a \<noteq> x" "dist x a \<le> e" by (auto simp add: dist_commute)
1.974 +  then have "a \<noteq> x" "dist x a \<le> e"
1.975 +    by (auto simp add: dist_commute)
1.976    with e show ?thesis by (auto simp add: set_eq_iff)
1.977  qed auto
1.978
1.979 @@ -2377,9 +2489,14 @@
1.980    unfolding bounded_any_center [where a=0]
1.981    by (simp add: dist_norm)
1.982
1.983 -lemma bounded_realI: assumes "\<forall>x\<in>s. abs (x::real) \<le> B" shows "bounded s"
1.984 -  unfolding bounded_def dist_real_def apply(rule_tac x=0 in exI)
1.985 -  using assms by auto
1.986 +lemma bounded_realI:
1.987 +  assumes "\<forall>x\<in>s. abs (x::real) \<le> B"
1.988 +  shows "bounded s"
1.989 +  unfolding bounded_def dist_real_def
1.990 +  apply (rule_tac x=0 in exI)
1.991 +  using assms
1.992 +  apply auto
1.993 +  done
1.994
1.995  lemma bounded_empty [simp]: "bounded {}"
1.996    by (simp add: bounded_def)
1.997 @@ -2402,7 +2519,7 @@
1.998      then obtain f where f: "\<forall>n. f n \<in> S"  "(f ---> y) sequentially"
1.999        unfolding closure_sequential by auto
1.1000      have "\<forall>n. f n \<in> S \<longrightarrow> dist x (f n) \<le> a" using a by simp
1.1001 -    hence "eventually (\<lambda>n. dist x (f n) \<le> a) sequentially"
1.1002 +    then have "eventually (\<lambda>n. dist x (f n) \<le> a) sequentially"
1.1003        by (rule eventually_mono, simp add: f(1))
1.1004      have "dist x y \<le> a"
1.1005        apply (rule Lim_dist_ubound [of sequentially f])
1.1006 @@ -2411,7 +2528,8 @@
1.1007        apply fact
1.1008        done
1.1009    }
1.1010 -  thus ?thesis unfolding bounded_def by auto
1.1011 +  then show ?thesis
1.1012 +    unfolding bounded_def by auto
1.1013  qed
1.1014
1.1015  lemma bounded_cball[simp,intro]: "bounded (cball x e)"
1.1016 @@ -2445,8 +2563,8 @@
1.1017  lemma bounded_insert [simp]: "bounded (insert x S) \<longleftrightarrow> bounded S"
1.1018  proof -
1.1019    have "\<forall>y\<in>{x}. dist x y \<le> 0" by simp
1.1020 -  hence "bounded {x}" unfolding bounded_def by fast
1.1021 -  thus ?thesis by (metis insert_is_Un bounded_Un)
1.1022 +  then have "bounded {x}" unfolding bounded_def by fast
1.1023 +  then show ?thesis by (metis insert_is_Un bounded_Un)
1.1024  qed
1.1025
1.1026  lemma finite_imp_bounded [intro]: "finite S \<Longrightarrow> bounded S"
1.1027 @@ -2489,14 +2607,16 @@
1.1028    from assms(2) obtain B where B:"B>0" "\<forall>x. norm (f x) \<le> B * norm x"
1.1029      using bounded_linear.pos_bounded by (auto simp add: mult_ac)
1.1030    {
1.1031 -    fix x assume "x\<in>S"
1.1032 -    hence "norm x \<le> b" using b by auto
1.1033 -    hence "norm (f x) \<le> B * b" using B(2)
1.1034 +    fix x
1.1035 +    assume "x\<in>S"
1.1036 +    then have "norm x \<le> b" using b by auto
1.1037 +    then have "norm (f x) \<le> B * b" using B(2)
1.1038        apply (erule_tac x=x in allE)
1.1039        apply (metis B(1) B(2) order_trans mult_le_cancel_left_pos)
1.1040        done
1.1041    }
1.1042 -  thus ?thesis unfolding bounded_pos
1.1043 +  then show ?thesis
1.1044 +    unfolding bounded_pos
1.1045      apply (rule_tac x="b*B" in exI)
1.1046      using b B mult_pos_pos [of b B]
1.1047      apply (auto simp add: mult_commute)
1.1048 @@ -2514,16 +2634,16 @@
1.1049    fixes S :: "'a::real_normed_vector set"
1.1050    assumes "bounded S"
1.1051    shows "bounded ((\<lambda>x. a + x) ` S)"
1.1052 -proof-
1.1053 +proof -
1.1054    from assms obtain b where b:"b>0" "\<forall>x\<in>S. norm x \<le> b"
1.1055      unfolding bounded_pos by auto
1.1056    {
1.1057      fix x
1.1058      assume "x\<in>S"
1.1059 -    hence "norm (a + x) \<le> b + norm a"
1.1060 +    then have "norm (a + x) \<le> b + norm a"
1.1061        using norm_triangle_ineq[of a x] b by auto
1.1062    }
1.1063 -  thus ?thesis
1.1064 +  then show ?thesis
1.1065      unfolding bounded_pos
1.1066      using norm_ge_zero[of a] b(1) and add_strict_increasing[of b 0 "norm a"]
1.1067      by (auto intro!: exI[of _ "b + norm a"])
1.1068 @@ -2540,19 +2660,21 @@
1.1069  lemma bounded_has_Sup:
1.1070    fixes S :: "real set"
1.1071    assumes "bounded S" "S \<noteq> {}"
1.1072 -  shows "\<forall>x\<in>S. x <= Sup S" and "\<forall>b. (\<forall>x\<in>S. x <= b) \<longrightarrow> Sup S <= b"
1.1073 +  shows "\<forall>x\<in>S. x \<le> Sup S"
1.1074 +    and "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b"
1.1075  proof
1.1076 -  fix x assume "x\<in>S"
1.1077 -  thus "x \<le> Sup S"
1.1078 +  fix x
1.1079 +  assume "x\<in>S"
1.1080 +  then show "x \<le> Sup S"
1.1081      by (metis cSup_upper abs_le_D1 assms(1) bounded_real)
1.1082  next
1.1083 -  show "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b" using assms
1.1084 -    by (metis cSup_least)
1.1085 +  show "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b"
1.1086 +    using assms by (metis cSup_least)
1.1087  qed
1.1088
1.1089  lemma Sup_insert:
1.1090    fixes S :: "real set"
1.1091 -  shows "bounded S ==> Sup(insert x S) = (if S = {} then x else max x (Sup S))"
1.1092 +  shows "bounded S ==> Sup(insert x S) = (if S = {} then x else max x (Sup S))"
1.1093    apply (subst cSup_insert_If)
1.1094    apply (rule bounded_has_Sup(1)[of S, rule_format])
1.1095    apply (auto simp: sup_max)
1.1096 @@ -2569,22 +2691,23 @@
1.1097  lemma bounded_has_Inf:
1.1098    fixes S :: "real set"
1.1099    assumes "bounded S"  "S \<noteq> {}"
1.1100 -  shows "\<forall>x\<in>S. x >= Inf S" and "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> Inf S >= b"
1.1101 +  shows "\<forall>x\<in>S. x \<ge> Inf S"
1.1102 +    and "\<forall>b. (\<forall>x\<in>S. x \<ge> b) \<longrightarrow> Inf S \<ge> b"
1.1103  proof
1.1104    fix x
1.1105    assume "x\<in>S"
1.1106 -  from assms(1) obtain a where a:"\<forall>x\<in>S. \<bar>x\<bar> \<le> a"
1.1107 +  from assms(1) obtain a where a: "\<forall>x\<in>S. \<bar>x\<bar> \<le> a"
1.1108      unfolding bounded_real by auto
1.1109 -  thus "x \<ge> Inf S" using `x\<in>S`
1.1110 +  then show "x \<ge> Inf S" using `x\<in>S`
1.1111      by (metis cInf_lower_EX abs_le_D2 minus_le_iff)
1.1112  next
1.1113 -  show "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> Inf S \<ge> b" using assms
1.1114 -    by (metis cInf_greatest)
1.1115 +  show "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> Inf S \<ge> b"
1.1116 +    using assms by (metis cInf_greatest)
1.1117  qed
1.1118
1.1119  lemma Inf_insert:
1.1120    fixes S :: "real set"
1.1121 -  shows "bounded S ==> Inf(insert x S) = (if S = {} then x else min x (Inf S))"
1.1122 +  shows "bounded S ==> Inf(insert x S) = (if S = {} then x else min x (Inf S))"
1.1123    apply (subst cInf_insert_if)
1.1124    apply (rule bounded_has_Inf(1)[of S, rule_format])
1.1125    apply (auto simp: inf_min)
1.1126 @@ -2592,8 +2715,11 @@
1.1127
1.1128  lemma Inf_insert_finite:
1.1129    fixes S :: "real set"
1.1130 -  shows "finite S ==> Inf(insert x S) = (if S = {} then x else min x (Inf S))"
1.1131 -  by (rule Inf_insert, rule finite_imp_bounded, simp)
1.1132 +  shows "finite S \<Longrightarrow> Inf(insert x S) = (if S = {} then x else min x (Inf S))"
1.1133 +  apply (rule Inf_insert)
1.1134 +  apply (rule finite_imp_bounded)
1.1135 +  apply simp
1.1136 +  done
1.1137
1.1138  subsection {* Compactness *}
1.1139
1.1140 @@ -2606,22 +2732,23 @@
1.1141    assume "\<not> (\<exists>x \<in> s. x islimpt t)"
1.1142    then obtain f where f:"\<forall>x\<in>s. x \<in> f x \<and> open (f x) \<and> (\<forall>y\<in>t. y \<in> f x \<longrightarrow> y = x)"
1.1143      unfolding islimpt_def
1.1144 -    using bchoice[of s "\<lambda> x T. x \<in> T \<and> open T \<and> (\<forall>y\<in>t. y \<in> T \<longrightarrow> y = x)"] by auto
1.1145 -  obtain g where g:"g\<subseteq>{t. \<exists>x. x \<in> s \<and> t = f x}" "finite g" "s \<subseteq> \<Union>g"
1.1146 +    using bchoice[of s "\<lambda> x T. x \<in> T \<and> open T \<and> (\<forall>y\<in>t. y \<in> T \<longrightarrow> y = x)"]
1.1147 +    by auto
1.1148 +  obtain g where g: "g\<subseteq>{t. \<exists>x. x \<in> s \<and> t = f x}" "finite g" "s \<subseteq> \<Union>g"
1.1149      using assms(1)[unfolded compact_eq_heine_borel, THEN spec[where x="{t. \<exists>x. x\<in>s \<and> t = f x}"]]
1.1150      using f by auto
1.1151    from g(1,3) have g':"\<forall>x\<in>g. \<exists>xa \<in> s. x = f xa" by auto
1.1152    {
1.1153      fix x y
1.1154      assume "x\<in>t" "y\<in>t" "f x = f y"
1.1155 -    hence "x \<in> f x"  "y \<in> f x \<longrightarrow> y = x"
1.1156 +    then have "x \<in> f x"  "y \<in> f x \<longrightarrow> y = x"
1.1157        using f[THEN bspec[where x=x]] and `t\<subseteq>s` by auto
1.1158 -    hence "x = y"
1.1159 +    then have "x = y"
1.1160        using `f x = f y` and f[THEN bspec[where x=y]] and `y\<in>t` and `t\<subseteq>s` by auto
1.1161    }
1.1162 -  hence "inj_on f t"
1.1163 +  then have "inj_on f t"
1.1164      unfolding inj_on_def by simp
1.1165 -  hence "infinite (f ` t)"
1.1166 +  then have "infinite (f ` t)"
1.1167      using assms(2) using finite_imageD by auto
1.1168    moreover
1.1169    {
1.1170 @@ -2630,12 +2757,12 @@
1.1171      from g(3) assms(3) `x\<in>t` obtain h where "h\<in>g" and "x\<in>h" by auto
1.1172      then obtain y where "y\<in>s" "h = f y"
1.1173        using g'[THEN bspec[where x=h]] by auto
1.1174 -    hence "y = x"
1.1175 +    then have "y = x"
1.1176        using f[THEN bspec[where x=y]] and `x\<in>t` and `x\<in>h`[unfolded `h = f y`] by auto
1.1177 -    hence False
1.1178 +    then have False
1.1179        using `f x \<notin> g` `h\<in>g` unfolding `h = f y` by auto
1.1180    }
1.1181 -  hence "f ` t \<subseteq> g" by auto
1.1182 +  then have "f ` t \<subseteq> g" by auto
1.1183    ultimately show False
1.1184      using g(2) using finite_subset by auto
1.1185  qed
1.1186 @@ -2668,12 +2795,14 @@
1.1187    moreover
1.1188    have "(\<lambda>n. f (r n)) ----> l"
1.1189    proof (rule topological_tendstoI)
1.1190 -    fix S assume "open S" "l \<in> S"
1.1191 +    fix S
1.1192 +    assume "open S" "l \<in> S"
1.1193      with A(3) have "eventually (\<lambda>i. A i \<subseteq> S) sequentially" by auto
1.1194      moreover
1.1195      {
1.1196        fix i
1.1197 -      assume "Suc 0 \<le> i" then have "f (r i) \<in> A i"
1.1198 +      assume "Suc 0 \<le> i"
1.1199 +      then have "f (r i) \<in> A i"
1.1200          by (cases i) (simp_all add: r_def s)
1.1201      }
1.1202      then have "eventually (\<lambda>i. f (r i) \<in> A i) sequentially"
1.1203 @@ -2687,16 +2816,17 @@
1.1204
1.1205  lemma sequence_infinite_lemma:
1.1206    fixes f :: "nat \<Rightarrow> 'a::t1_space"
1.1207 -  assumes "\<forall>n. f n \<noteq> l" and "(f ---> l) sequentially"
1.1208 +  assumes "\<forall>n. f n \<noteq> l"
1.1209 +    and "(f ---> l) sequentially"
1.1210    shows "infinite (range f)"
1.1211  proof
1.1212    assume "finite (range f)"
1.1213 -  hence "closed (range f)" by (rule finite_imp_closed)
1.1214 -  hence "open (- range f)" by (rule open_Compl)
1.1215 +  then have "closed (range f)" by (rule finite_imp_closed)
1.1216 +  then have "open (- range f)" by (rule open_Compl)
1.1217    from assms(1) have "l \<in> - range f" by auto
1.1218    from assms(2) have "eventually (\<lambda>n. f n \<in> - range f) sequentially"
1.1219      using `open (- range f)` `l \<in> - range f` by (rule topological_tendstoD)
1.1220 -  thus False unfolding eventually_sequentially by auto
1.1221 +  then show False unfolding eventually_sequentially by auto
1.1222  qed
1.1223
1.1224  lemma closure_insert:
1.1225 @@ -2715,7 +2845,8 @@
1.1226    assume *: "x islimpt (insert a s)"
1.1227    show "x islimpt s"
1.1228    proof (rule islimptI)
1.1229 -    fix t assume t: "x \<in> t" "open t"
1.1230 +    fix t
1.1231 +    assume t: "x \<in> t" "open t"
1.1232      show "\<exists>y\<in>s. y \<in> t \<and> y \<noteq> x"
1.1233      proof (cases "x = a")
1.1234        case True
1.1235 @@ -2728,11 +2859,12 @@
1.1236          by (simp_all add: open_Diff)
1.1237        obtain y where "y \<in> insert a s" "y \<in> t - {a}" "y \<noteq> x"
1.1238          using * t' by (rule islimptE)
1.1239 -      thus ?thesis by auto
1.1240 +      then show ?thesis by auto
1.1241      qed
1.1242    qed
1.1243  next
1.1244 -  assume "x islimpt s" thus "x islimpt (insert a s)"
1.1245 +  assume "x islimpt s"
1.1246 +  then show "x islimpt (insert a s)"
1.1247      by (rule islimpt_subset) auto
1.1248  qed
1.1249
1.1250 @@ -2750,14 +2882,17 @@
1.1251    fixes l :: "'a :: t1_space"
1.1252    shows "l islimpt S \<longleftrightarrow> (\<forall>U. l\<in>U \<longrightarrow> open U \<longrightarrow> infinite (U \<inter> S))"
1.1253  proof (safe intro!: islimptI)
1.1254 -  fix U assume "l islimpt S" "l \<in> U" "open U" "finite (U \<inter> S)"
1.1255 +  fix U
1.1256 +  assume "l islimpt S" "l \<in> U" "open U" "finite (U \<inter> S)"
1.1257    then have "l islimpt S" "l \<in> (U - (U \<inter> S - {l}))" "open (U - (U \<inter> S - {l}))"
1.1258      by (auto intro: finite_imp_closed)
1.1259    then show False
1.1260      by (rule islimptE) auto
1.1261  next
1.1262 -  fix T assume *: "\<forall>U. l\<in>U \<longrightarrow> open U \<longrightarrow> infinite (U \<inter> S)" "l \<in> T" "open T"
1.1263 -  then have "infinite (T \<inter> S - {l})" by auto
1.1264 +  fix T
1.1265 +  assume *: "\<forall>U. l\<in>U \<longrightarrow> open U \<longrightarrow> infinite (U \<inter> S)" "l \<in> T" "open T"
1.1266 +  then have "infinite (T \<inter> S - {l})"
1.1267 +    by auto
1.1268    then have "\<exists>x. x \<in> (T \<inter> S - {l})"
1.1269      unfolding ex_in_conv by (intro notI) simp
1.1270    then show "\<exists>y\<in>S. y \<in> T \<and> y \<noteq> l"
1.1271 @@ -2773,7 +2908,8 @@
1.1272
1.1273  lemma sequence_unique_limpt:
1.1274    fixes f :: "nat \<Rightarrow> 'a::t2_space"
1.1275 -  assumes "(f ---> l) sequentially" and "l' islimpt (range f)"
1.1276 +  assumes "(f ---> l) sequentially"
1.1277 +    and "l' islimpt (range f)"
1.1278    shows "l' = l"
1.1279  proof (rule ccontr)
1.1280    assume "l' \<noteq> l"
1.1281 @@ -2784,15 +2920,22 @@
1.1282    then obtain N where "\<forall>n\<ge>N. f n \<in> t"
1.1283      unfolding eventually_sequentially by auto
1.1284
1.1285 -  have "UNIV = {..<N} \<union> {N..}" by auto
1.1286 -  hence "l' islimpt (f ` ({..<N} \<union> {N..}))" using assms(2) by simp
1.1287 -  hence "l' islimpt (f ` {..<N} \<union> f ` {N..})" by (simp add: image_Un)
1.1288 -  hence "l' islimpt (f ` {N..})" by (simp add: islimpt_union_finite)
1.1289 +  have "UNIV = {..<N} \<union> {N..}"
1.1290 +    by auto
1.1291 +  then have "l' islimpt (f ` ({..<N} \<union> {N..}))"
1.1292 +    using assms(2) by simp
1.1293 +  then have "l' islimpt (f ` {..<N} \<union> f ` {N..})"
1.1294 +    by (simp add: image_Un)
1.1295 +  then have "l' islimpt (f ` {N..})"
1.1296 +    by (simp add: islimpt_union_finite)
1.1297    then obtain y where "y \<in> f ` {N..}" "y \<in> s" "y \<noteq> l'"
1.1298      using `l' \<in> s` `open s` by (rule islimptE)
1.1299 -  then obtain n where "N \<le> n" "f n \<in> s" "f n \<noteq> l'" by auto
1.1300 -  with `\<forall>n\<ge>N. f n \<in> t` have "f n \<in> s \<inter> t" by simp
1.1301 -  with `s \<inter> t = {}` show False by simp
1.1302 +  then obtain n where "N \<le> n" "f n \<in> s" "f n \<noteq> l'"
1.1303 +    by auto
1.1304 +  with `\<forall>n\<ge>N. f n \<in> t` have "f n \<in> s \<inter> t"
1.1305 +    by simp
1.1306 +  with `s \<inter> t = {}` show False
1.1307 +    by simp
1.1308  qed
1.1309
1.1310  lemma bolzano_weierstrass_imp_closed:
1.1311 @@ -2803,21 +2946,22 @@
1.1312    {
1.1313      fix x l
1.1314      assume as: "\<forall>n::nat. x n \<in> s" "(x ---> l) sequentially"
1.1315 -    hence "l \<in> s"
1.1316 +    then have "l \<in> s"
1.1317      proof (cases "\<forall>n. x n \<noteq> l")
1.1318        case False
1.1319 -      thus "l\<in>s" using as(1) by auto
1.1320 +      then show "l\<in>s" using as(1) by auto
1.1321      next
1.1322        case True note cas = this
1.1323        with as(2) have "infinite (range x)"
1.1324          using sequence_infinite_lemma[of x l] by auto
1.1325        then obtain l' where "l'\<in>s" "l' islimpt (range x)"
1.1326          using assms[THEN spec[where x="range x"]] as(1) by auto
1.1327 -      thus "l\<in>s" using sequence_unique_limpt[of x l l']
1.1328 +      then show "l\<in>s" using sequence_unique_limpt[of x l l']
1.1329          using as cas by auto
1.1330      qed
1.1331    }
1.1332 -  thus ?thesis unfolding closed_sequential_limits by fast
1.1333 +  then show ?thesis
1.1334 +    unfolding closed_sequential_limits by fast
1.1335  qed
1.1336
1.1337  lemma compact_imp_bounded:
1.1338 @@ -2830,14 +2974,15 @@
1.1339      by (rule compactE_image)
1.1340    from `finite D` have "bounded (\<Union>x\<in>D. ball x 1)"
1.1341      by (simp add: bounded_UN)
1.1342 -  thus "bounded U" using `U \<subseteq> (\<Union>x\<in>D. ball x 1)`
1.1343 +  then show "bounded U" using `U \<subseteq> (\<Union>x\<in>D. ball x 1)`
1.1344      by (rule bounded_subset)
1.1345  qed
1.1346
1.1347  text{* In particular, some common special cases. *}
1.1348
1.1349  lemma compact_union [intro]:
1.1350 -  assumes "compact s" "compact t" shows " compact (s \<union> t)"
1.1351 +  assumes "compact s" "compact t"
1.1352 +  shows " compact (s \<union> t)"
1.1353  proof (rule compactI)
1.1354    fix f
1.1355    assume *: "Ball f open" "s \<union> t \<subseteq> \<Union>f"
1.1356 @@ -2858,14 +3003,16 @@
1.1357    unfolding SUP_def by (rule compact_Union) auto
1.1358
1.1359  lemma closed_inter_compact [intro]:
1.1360 -  assumes "closed s" and "compact t"
1.1361 +  assumes "closed s"
1.1362 +    and "compact t"
1.1363    shows "compact (s \<inter> t)"
1.1364    using compact_inter_closed [of t s] assms
1.1365    by (simp add: Int_commute)
1.1366
1.1367  lemma compact_inter [intro]:
1.1368    fixes s t :: "'a :: t2_space set"
1.1369 -  assumes "compact s" and "compact t"
1.1370 +  assumes "compact s"
1.1371 +    and "compact t"
1.1372    shows "compact (s \<inter> t)"
1.1373    using assms by (intro compact_inter_closed compact_imp_closed)
1.1374
1.1375 @@ -2873,11 +3020,12 @@
1.1376    unfolding compact_eq_heine_borel by auto
1.1377
1.1378  lemma compact_insert [simp]:
1.1379 -  assumes "compact s" shows "compact (insert x s)"
1.1380 +  assumes "compact s"
1.1381 +  shows "compact (insert x s)"
1.1382  proof -
1.1383    have "compact ({x} \<union> s)"
1.1384      using compact_sing assms by (rule compact_union)
1.1385 -  thus ?thesis by simp
1.1386 +  then show ?thesis by simp
1.1387  qed
1.1388
1.1389  lemma finite_imp_compact: "finite s \<Longrightarrow> compact s"
1.1390 @@ -2898,7 +3046,9 @@
1.1391      (\<forall>A. (\<forall>a\<in>A. closed a) \<longrightarrow> (\<forall>B \<subseteq> A. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {}) \<longrightarrow> U \<inter> \<Inter>A \<noteq> {})"
1.1392    (is "_ \<longleftrightarrow> ?R")
1.1393  proof (safe intro!: compact_eq_heine_borel[THEN iffD2])
1.1394 -  fix A assume "compact U" and A: "\<forall>a\<in>A. closed a" "U \<inter> \<Inter>A = {}"
1.1395 +  fix A
1.1396 +  assume "compact U"
1.1397 +    and A: "\<forall>a\<in>A. closed a" "U \<inter> \<Inter>A = {}"
1.1398      and fi: "\<forall>B \<subseteq> A. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {}"
1.1399    from A have "(\<forall>a\<in>uminus`A. open a) \<and> U \<subseteq> \<Union>(uminus`A)"
1.1400      by auto
1.1401 @@ -2907,8 +3057,10 @@
1.1402    with fi[THEN spec, of B] show False
1.1403      by (auto dest: finite_imageD intro: inj_setminus)
1.1404  next
1.1405 -  fix A assume ?R and cover: "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
1.1406 -  from cover have "U \<inter> \<Inter>(uminus`A) = {}" "\<forall>a\<in>uminus`A. closed a"
1.1407 +  fix A
1.1408 +  assume ?R
1.1409 +  assume "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
1.1410 +  then have "U \<inter> \<Inter>(uminus`A) = {}" "\<forall>a\<in>uminus`A. closed a"
1.1411      by auto
1.1412    with `?R` obtain B where "B \<subseteq> A" "finite (uminus`B)" "U \<inter> \<Inter>(uminus`B) = {}"
1.1413      by (metis subset_image_iff)
1.1414 @@ -2956,8 +3108,9 @@
1.1415    "x \<in> closure X \<longleftrightarrow> (\<forall>A. \<forall>S\<subseteq>A. open S \<longrightarrow> x \<in> S \<longrightarrow> X \<inter> A \<noteq> {})"
1.1416  proof safe
1.1417    assume x: "x \<in> closure X"
1.1418 -  fix S A assume "open S" "x \<in> S" "X \<inter> A = {}" "S \<subseteq> A"
1.1419 -  then have "x \<notin> closure (-S)"
1.1420 +  fix S A
1.1421 +  assume "open S" "x \<in> S" "X \<inter> A = {}" "S \<subseteq> A"
1.1422 +  then have "x \<notin> closure (-S)"
1.1423      by (auto simp: closure_complement subset_eq[symmetric] intro: interiorI)
1.1424    with x have "x \<in> closure X - closure (-S)"
1.1425      by auto
1.1426 @@ -2975,14 +3128,16 @@
1.1427  lemma compact_filter:
1.1428    "compact U \<longleftrightarrow> (\<forall>F. F \<noteq> bot \<longrightarrow> eventually (\<lambda>x. x \<in> U) F \<longrightarrow> (\<exists>x\<in>U. inf (nhds x) F \<noteq> bot))"
1.1429  proof (intro allI iffI impI compact_fip[THEN iffD2] notI)
1.1430 -  fix F assume "compact U" and F: "F \<noteq> bot" "eventually (\<lambda>x. x \<in> U) F"
1.1431 -  from F have "U \<noteq> {}"
1.1432 +  fix F
1.1433 +  assume "compact U"
1.1434 +  assume F: "F \<noteq> bot" "eventually (\<lambda>x. x \<in> U) F"
1.1435 +  then have "U \<noteq> {}"
1.1436      by (auto simp: eventually_False)
1.1437
1.1438    def Z \<equiv> "closure ` {A. eventually (\<lambda>x. x \<in> A) F}"
1.1439    then have "\<forall>z\<in>Z. closed z"
1.1440      by auto
1.1441 -  moreover
1.1442 +  moreover
1.1443    have ev_Z: "\<And>z. z \<in> Z \<Longrightarrow> eventually (\<lambda>x. x \<in> z) F"
1.1444      unfolding Z_def by (auto elim: eventually_elim1 intro: set_mp[OF closure_subset])
1.1445    have "(\<forall>B \<subseteq> Z. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {})"
1.1446 @@ -2997,7 +3152,8 @@
1.1447    qed
1.1448    ultimately have "U \<inter> \<Inter>Z \<noteq> {}"
1.1449      using `compact U` unfolding compact_fip by blast
1.1450 -  then obtain x where "x \<in> U" and x: "\<And>z. z \<in> Z \<Longrightarrow> x \<in> z" by auto
1.1451 +  then obtain x where "x \<in> U" and x: "\<And>z. z \<in> Z \<Longrightarrow> x \<in> z"
1.1452 +    by auto
1.1453
1.1454    have "\<And>P. eventually P (inf (nhds x) F) \<Longrightarrow> P \<noteq> bot"
1.1455      unfolding eventually_inf eventually_nhds
1.1456 @@ -3012,8 +3168,8 @@
1.1457    with `x \<in> U` show "\<exists>x\<in>U. inf (nhds x) F \<noteq> bot"
1.1458      by (metis eventually_bot)
1.1459  next
1.1460 -  fix A assume A: "\<forall>a\<in>A. closed a" "\<forall>B\<subseteq>A. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {}" "U \<inter> \<Inter>A = {}"
1.1461 -
1.1462 +  fix A
1.1463 +  assume A: "\<forall>a\<in>A. closed a" "\<forall>B\<subseteq>A. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {}" "U \<inter> \<Inter>A = {}"
1.1464    def P' \<equiv> "(\<lambda>a (x::'a). x \<in> a)"
1.1465    then have inj_P': "\<And>A. inj_on P' A"
1.1466      by (auto intro!: inj_onI simp: fun_eq_iff)
1.1467 @@ -3021,33 +3177,42 @@
1.1468    have "F \<noteq> bot"
1.1469      unfolding F_def
1.1470    proof (safe intro!: filter_from_subbase_not_bot)
1.1471 -    fix X assume "X \<subseteq> P' ` insert U A" "finite X" "Inf X = bot"
1.1472 +    fix X
1.1473 +    assume "X \<subseteq> P' ` insert U A" "finite X" "Inf X = bot"
1.1474      then obtain B where "B \<subseteq> insert U A" "finite B" and B: "Inf (P' ` B) = bot"
1.1475        unfolding subset_image_iff by (auto intro: inj_P' finite_imageD)
1.1476 -    with A(2)[THEN spec, of "B - {U}"] have "U \<inter> \<Inter>(B - {U}) \<noteq> {}" by auto
1.1477 -    with B show False by (auto simp: P'_def fun_eq_iff)
1.1478 +    with A(2)[THEN spec, of "B - {U}"] have "U \<inter> \<Inter>(B - {U}) \<noteq> {}"
1.1479 +      by auto
1.1480 +    with B show False
1.1481 +      by (auto simp: P'_def fun_eq_iff)
1.1482    qed
1.1483    moreover have "eventually (\<lambda>x. x \<in> U) F"
1.1484      unfolding F_def by (rule eventually_filter_from_subbaseI) (auto simp: P'_def)
1.1485 -  moreover assume "\<forall>F. F \<noteq> bot \<longrightarrow> eventually (\<lambda>x. x \<in> U) F \<longrightarrow> (\<exists>x\<in>U. inf (nhds x) F \<noteq> bot)"
1.1486 +  moreover
1.1487 +  assume "\<forall>F. F \<noteq> bot \<longrightarrow> eventually (\<lambda>x. x \<in> U) F \<longrightarrow> (\<exists>x\<in>U. inf (nhds x) F \<noteq> bot)"
1.1488    ultimately obtain x where "x \<in> U" and x: "inf (nhds x) F \<noteq> bot"
1.1489      by auto
1.1490
1.1491 -  { fix V assume "V \<in> A"
1.1492 +  {
1.1493 +    fix V
1.1494 +    assume "V \<in> A"
1.1495      then have V: "eventually (\<lambda>x. x \<in> V) F"
1.1496        by (auto simp add: F_def image_iff P'_def intro!: eventually_filter_from_subbaseI)
1.1497      have "x \<in> closure V"
1.1498        unfolding closure_iff_nhds_not_empty
1.1499      proof (intro impI allI)
1.1500 -      fix S A assume "open S" "x \<in> S" "S \<subseteq> A"
1.1501 -      then have "eventually (\<lambda>x. x \<in> A) (nhds x)" by (auto simp: eventually_nhds)
1.1502 +      fix S A
1.1503 +      assume "open S" "x \<in> S" "S \<subseteq> A"
1.1504 +      then have "eventually (\<lambda>x. x \<in> A) (nhds x)"
1.1505 +        by (auto simp: eventually_nhds)
1.1506        with V have "eventually (\<lambda>x. x \<in> V \<inter> A) (inf (nhds x) F)"
1.1507          by (auto simp: eventually_inf)
1.1508        with x show "V \<inter> A \<noteq> {}"
1.1509          by (auto simp del: Int_iff simp add: trivial_limit_def)
1.1510      qed
1.1511      then have "x \<in> V"
1.1512 -      using `V \<in> A` A(1) by simp }
1.1513 +      using `V \<in> A` A(1) by simp
1.1514 +  }
1.1515    with `x\<in>U` have "x \<in> U \<inter> \<Inter>A" by auto
1.1516    with `U \<inter> \<Inter>A = {}` show False by auto
1.1517  qed
1.1518 @@ -3070,12 +3235,14 @@
1.1519
1.1520  lemma countably_compact_imp_compact:
1.1521    assumes "countably_compact U"
1.1522 -  assumes ccover: "countable B" "\<forall>b\<in>B. open b"
1.1523 -  assumes basis: "\<And>T x. open T \<Longrightarrow> x \<in> T \<Longrightarrow> x \<in> U \<Longrightarrow> \<exists>b\<in>B. x \<in> b \<and> b \<inter> U \<subseteq> T"
1.1524 +    and ccover: "countable B" "\<forall>b\<in>B. open b"
1.1525 +    and basis: "\<And>T x. open T \<Longrightarrow> x \<in> T \<Longrightarrow> x \<in> U \<Longrightarrow> \<exists>b\<in>B. x \<in> b \<and> b \<inter> U \<subseteq> T"
1.1526    shows "compact U"
1.1527 -  using `countably_compact U` unfolding compact_eq_heine_borel countably_compact_def
1.1528 +  using `countably_compact U`
1.1529 +  unfolding compact_eq_heine_borel countably_compact_def
1.1530  proof safe
1.1531 -  fix A assume A: "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
1.1532 +  fix A
1.1533 +  assume A: "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
1.1534    assume *: "\<forall>A. countable A \<longrightarrow> (\<forall>a\<in>A. open a) \<longrightarrow> U \<subseteq> \<Union>A \<longrightarrow> (\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T)"
1.1535
1.1536    moreover def C \<equiv> "{b\<in>B. \<exists>a\<in>A. b \<inter> U \<subseteq> a}"
1.1537 @@ -3084,10 +3251,12 @@
1.1538    moreover
1.1539    have "\<Union>A \<inter> U \<subseteq> \<Union>C"
1.1540    proof safe
1.1541 -    fix x a assume "x \<in> U" "x \<in> a" "a \<in> A"
1.1542 -    with basis[of a x] A obtain b where "b \<in> B" "x \<in> b" "b \<inter> U \<subseteq> a" by blast
1.1543 -    with `a \<in> A` show "x \<in> \<Union>C" unfolding C_def
1.1544 -      by auto
1.1545 +    fix x a
1.1546 +    assume "x \<in> U" "x \<in> a" "a \<in> A"
1.1547 +    with basis[of a x] A obtain b where "b \<in> B" "x \<in> b" "b \<inter> U \<subseteq> a"
1.1548 +      by blast
1.1549 +    with `a \<in> A` show "x \<in> \<Union>C"
1.1550 +      unfolding C_def by auto
1.1551    qed
1.1552    then have "U \<subseteq> \<Union>C" using `U \<subseteq> \<Union>A` by auto
1.1553    ultimately obtain T where "T\<subseteq>C" "finite T" "U \<subseteq> \<Union>T"
1.1554 @@ -3102,22 +3271,22 @@
1.1555  lemma countably_compact_imp_compact_second_countable:
1.1556    "countably_compact U \<Longrightarrow> compact (U :: 'a :: second_countable_topology set)"
1.1557  proof (rule countably_compact_imp_compact)
1.1558 -  fix T and x :: 'a assume "open T" "x \<in> T"
1.1559 +  fix T and x :: 'a
1.1560 +  assume "open T" "x \<in> T"
1.1561    from topological_basisE[OF is_basis this] guess b .
1.1562 -  then show "\<exists>b\<in>SOME B. countable B \<and> topological_basis B. x \<in> b \<and> b \<inter> U \<subseteq> T" by auto
1.1563 +  then show "\<exists>b\<in>SOME B. countable B \<and> topological_basis B. x \<in> b \<and> b \<inter> U \<subseteq> T"
1.1564 +    by auto
1.1565  qed (insert countable_basis topological_basis_open[OF is_basis], auto)
1.1566
1.1567  lemma countably_compact_eq_compact:
1.1568    "countably_compact U \<longleftrightarrow> compact (U :: 'a :: second_countable_topology set)"
1.1569    using countably_compact_imp_compact_second_countable compact_imp_countably_compact by blast
1.1570 -
1.1571 +
1.1572  subsubsection{* Sequential compactness *}
1.1573
1.1574 -definition
1.1575 -  seq_compact :: "'a::topological_space set \<Rightarrow> bool" where
1.1576 -  "seq_compact S \<longleftrightarrow>
1.1577 -   (\<forall>f. (\<forall>n. f n \<in> S) \<longrightarrow>
1.1578 -       (\<exists>l\<in>S. \<exists>r. subseq r \<and> ((f o r) ---> l) sequentially))"
1.1579 +definition seq_compact :: "'a::topological_space set \<Rightarrow> bool"
1.1580 +  where "seq_compact S \<longleftrightarrow>
1.1581 +    (\<forall>f. (\<forall>n. f n \<in> S) \<longrightarrow> (\<exists>l\<in>S. \<exists>r. subseq r \<and> ((f o r) ---> l) sequentially))"
1.1582
1.1583  lemma seq_compact_imp_countably_compact:
1.1584    fixes U :: "'a :: first_countable_topology set"
1.1585 @@ -3138,13 +3307,17 @@
1.1586      show ?thesis
1.1587      proof (rule ccontr)
1.1588        assume "\<not> (\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T)"
1.1589 -      then have "\<forall>T. \<exists>x. T \<subseteq> A \<and> finite T \<longrightarrow> (x \<in> U - \<Union>T)" by auto
1.1590 -      then obtain X' where T: "\<And>T. T \<subseteq> A \<Longrightarrow> finite T \<Longrightarrow> X' T \<in> U - \<Union>T" by metis
1.1591 +      then have "\<forall>T. \<exists>x. T \<subseteq> A \<and> finite T \<longrightarrow> (x \<in> U - \<Union>T)"
1.1592 +        by auto
1.1593 +      then obtain X' where T: "\<And>T. T \<subseteq> A \<Longrightarrow> finite T \<Longrightarrow> X' T \<in> U - \<Union>T"
1.1594 +        by metis
1.1595        def X \<equiv> "\<lambda>n. X' (from_nat_into A ` {.. n})"
1.1596        have X: "\<And>n. X n \<in> U - (\<Union>i\<le>n. from_nat_into A i)"
1.1597          using `A \<noteq> {}` unfolding X_def SUP_def by (intro T) (auto intro: from_nat_into)
1.1598 -      then have "range X \<subseteq> U" by auto
1.1599 -      with subseq[of X] obtain r x where "x \<in> U" and r: "subseq r" "(X \<circ> r) ----> x" by auto
1.1600 +      then have "range X \<subseteq> U"
1.1601 +        by auto
1.1602 +      with subseq[of X] obtain r x where "x \<in> U" and r: "subseq r" "(X \<circ> r) ----> x"
1.1603 +        by auto
1.1604        from `x\<in>U` `U \<subseteq> \<Union>A` from_nat_into_surj[OF `countable A`]
1.1605        obtain n where "x \<in> from_nat_into A n" by auto
1.1606        with r(2) A(1) from_nat_into[OF `A \<noteq> {}`, of n]
1.1607 @@ -3164,7 +3337,8 @@
1.1608
1.1609  lemma compact_imp_seq_compact:
1.1610    fixes U :: "'a :: first_countable_topology set"
1.1611 -  assumes "compact U" shows "seq_compact U"
1.1612 +  assumes "compact U"
1.1613 +  shows "seq_compact U"
1.1614    unfolding seq_compact_def
1.1615  proof safe
1.1616    fix X :: "nat \<Rightarrow> 'a"
1.1617 @@ -3185,7 +3359,8 @@
1.1618      have "\<exists>a. i < a \<and> X a \<in> A (Suc n)"
1.1619      proof (rule ccontr)
1.1620        assume "\<not> (\<exists>a>i. X a \<in> A (Suc n))"
1.1621 -      then have "\<And>a. Suc i \<le> a \<Longrightarrow> X a \<notin> A (Suc n)" by auto
1.1622 +      then have "\<And>a. Suc i \<le> a \<Longrightarrow> X a \<notin> A (Suc n)"
1.1623 +        by auto
1.1624        then have "eventually (\<lambda>x. x \<notin> A (Suc n)) (filtermap X sequentially)"
1.1625          by (auto simp: eventually_filtermap eventually_sequentially)
1.1626        moreover have "eventually (\<lambda>x. x \<in> A (Suc n)) (nhds x)"
1.1627 @@ -3207,7 +3382,8 @@
1.1628    proof (rule topological_tendstoI)
1.1629      fix S
1.1630      assume "open S" "x \<in> S"
1.1631 -    with A(3) have "eventually (\<lambda>i. A i \<subseteq> S) sequentially" by auto
1.1632 +    with A(3) have "eventually (\<lambda>i. A i \<subseteq> S) sequentially"
1.1633 +      by auto
1.1634      moreover
1.1635      {
1.1636        fix i
1.1637 @@ -3238,9 +3414,9 @@
1.1638    assumes "countably_compact s" "countable t" "infinite t"  "t \<subseteq> s"
1.1639    shows "\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> t)"
1.1640  proof (rule ccontr)
1.1641 -  def C \<equiv> "(\<lambda>F. interior (F \<union> (- t))) ` {F. finite F \<and> F \<subseteq> t }"
1.1642 +  def C \<equiv> "(\<lambda>F. interior (F \<union> (- t))) ` {F. finite F \<and> F \<subseteq> t }"
1.1643    note `countably_compact s`
1.1644 -  moreover have "\<forall>t\<in>C. open t"
1.1645 +  moreover have "\<forall>t\<in>C. open t"
1.1646      by (auto simp: C_def)
1.1647    moreover
1.1648    assume "\<not> (\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> t))"
1.1649 @@ -3256,19 +3432,20 @@
1.1650    from `countable t` have "countable C"
1.1651      unfolding C_def by (auto intro: countable_Collect_finite_subset)
1.1652    ultimately guess D by (rule countably_compactE)
1.1653 -  then obtain E where E: "E \<subseteq> {F. finite F \<and> F \<subseteq> t }" "finite E" and
1.1654 -    s: "s \<subseteq> (\<Union>F\<in>E. interior (F \<union> (- t)))"
1.1655 +  then obtain E where E: "E \<subseteq> {F. finite F \<and> F \<subseteq> t }" "finite E"
1.1656 +    and s: "s \<subseteq> (\<Union>F\<in>E. interior (F \<union> (- t)))"
1.1657      by (metis (lifting) Union_image_eq finite_subset_image C_def)
1.1658    from s `t \<subseteq> s` have "t \<subseteq> \<Union>E"
1.1659      using interior_subset by blast
1.1660    moreover have "finite (\<Union>E)"
1.1661      using E by auto
1.1662 -  ultimately show False using `infinite t` by (auto simp: finite_subset)
1.1663 +  ultimately show False using `infinite t`
1.1664 +    by (auto simp: finite_subset)
1.1665  qed
1.1666
1.1667  lemma countable_acc_point_imp_seq_compact:
1.1668    fixes s :: "'a::first_countable_topology set"
1.1669 -  assumes "\<forall>t. infinite t \<and> countable t \<and> t \<subseteq> s --> (\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> t))"
1.1670 +  assumes "\<forall>t. infinite t \<and> countable t \<and> t \<subseteq> s \<longrightarrow> (\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> t))"
1.1671    shows "seq_compact s"
1.1672  proof -
1.1673    {
1.1674 @@ -3281,20 +3458,22 @@
1.1675          using pigeonhole_infinite[OF _ True] by auto
1.1676        then obtain r where "subseq r" and fr: "\<forall>n. f (r n) = f l"
1.1677          using infinite_enumerate by blast
1.1678 -      hence "subseq r \<and> (f \<circ> r) ----> f l"
1.1679 +      then have "subseq r \<and> (f \<circ> r) ----> f l"
1.1680          by (simp add: fr tendsto_const o_def)
1.1681        with f show "\<exists>l\<in>s. \<exists>r. subseq r \<and> (f \<circ> r) ----> l"
1.1682          by auto
1.1683      next
1.1684        case False
1.1685 -      with f assms have "\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> range f)" by auto
1.1686 +      with f assms have "\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> range f)"
1.1687 +        by auto
1.1688        then obtain l where "l \<in> s" "\<forall>U. l\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> range f)" ..
1.1689        from this(2) have "\<exists>r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
1.1690          using acc_point_range_imp_convergent_subsequence[of l f] by auto
1.1691        with `l \<in> s` show "\<exists>l\<in>s. \<exists>r. subseq r \<and> ((f \<circ> r) ---> l) sequentially" ..
1.1692      qed
1.1693    }
1.1694 -  thus ?thesis unfolding seq_compact_def by auto
1.1695 +  then show ?thesis
1.1696 +    unfolding seq_compact_def by auto
1.1697  qed
1.1698
1.1699  lemma seq_compact_eq_countably_compact:
1.1700 @@ -3327,11 +3506,11 @@
1.1701
1.1702  subsubsection{* Total boundedness *}
1.1703
1.1704 -lemma cauchy_def:
1.1705 -  "Cauchy s \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>m n. m \<ge> N \<and> n \<ge> N --> dist(s m)(s n) < e)"
1.1706 +lemma cauchy_def: "Cauchy s \<longleftrightarrow> (\<forall>e>0. \<exists>N. \<forall>m n. m \<ge> N \<and> n \<ge> N --> dist(s m)(s n) < e)"
1.1707    unfolding Cauchy_def by metis
1.1708
1.1709 -fun helper_1 :: "('a::metric_space set) \<Rightarrow> real \<Rightarrow> nat \<Rightarrow> 'a" where
1.1710 +fun helper_1 :: "('a::metric_space set) \<Rightarrow> real \<Rightarrow> nat \<Rightarrow> 'a"
1.1711 +where
1.1712    "helper_1 s e n = (SOME y::'a. y \<in> s \<and> (\<forall>m<n. \<not> (dist (helper_1 s e m) y < e)))"
1.1713  declare helper_1.simps[simp del]
1.1714
1.1715 @@ -3340,7 +3519,8 @@
1.1716    shows "\<forall>e>0. \<exists>k. finite k \<and> k \<subseteq> s \<and> s \<subseteq> (\<Union>((\<lambda>x. ball x e) ` k))"
1.1717  proof (rule, rule, rule ccontr)
1.1718    fix e::real
1.1719 -  assume "e>0" and assm:"\<not> (\<exists>k. finite k \<and> k \<subseteq> s \<and> s \<subseteq> \<Union>((\<lambda>x. ball x e) ` k))"
1.1720 +  assume "e > 0"
1.1721 +  assume assm: "\<not> (\<exists>k. finite k \<and> k \<subseteq> s \<and> s \<subseteq> \<Union>((\<lambda>x. ball x e) ` k))"
1.1722    def x \<equiv> "helper_1 s e"
1.1723    {
1.1724      fix n
1.1725 @@ -3365,11 +3545,11 @@
1.1726          using z
1.1727          apply auto
1.1728          done
1.1729 -      thus "x n \<in> s \<and> (\<forall>m<n. \<not> dist (x m) (x n) < e)"
1.1730 +      then show "x n \<in> s \<and> (\<forall>m<n. \<not> dist (x m) (x n) < e)"
1.1731          unfolding Q_def by auto
1.1732      qed
1.1733    }
1.1734 -  hence "\<forall>n::nat. x n \<in> s" and x:"\<forall>n. \<forall>m < n. \<not> (dist (x m) (x n) < e)"
1.1735 +  then have "\<forall>n::nat. x n \<in> s" and x:"\<forall>n. \<forall>m < n. \<not> (dist (x m) (x n) < e)"
1.1736      by blast+
1.1737    then obtain l r where "l\<in>s" and r:"subseq r" and "((x \<circ> r) ---> l) sequentially"
1.1738      using assms(1)[unfolded seq_compact_def, THEN spec[where x=x]] by auto
1.1739 @@ -3388,7 +3568,8 @@
1.1740
1.1741  lemma seq_compact_imp_heine_borel:
1.1742    fixes s :: "'a :: metric_space set"
1.1743 -  assumes "seq_compact s" shows "compact s"
1.1744 +  assumes "seq_compact s"
1.1745 +  shows "compact s"
1.1746  proof -
1.1747    from seq_compact_imp_totally_bounded[OF `seq_compact s`]
1.1748    guess f unfolding choice_iff' .. note f = this
1.1749 @@ -3403,20 +3584,29 @@
1.1750                 intro!: countable_image countable_SIGMA countable_UN)
1.1751      show "\<forall>b\<in>K. open b" by (auto simp: K_def)
1.1752    next
1.1753 -    fix T x assume T: "open T" "x \<in> T" and x: "x \<in> s"
1.1754 -    from openE[OF T] obtain e where "0 < e" "ball x e \<subseteq> T" by auto
1.1755 -    then have "0 < e / 2" "ball x (e / 2) \<subseteq> T" by auto
1.1756 -    from Rats_dense_in_real[OF `0 < e / 2`] obtain r where "r \<in> \<rat>" "0 < r" "r < e / 2" by auto
1.1757 +    fix T x
1.1758 +    assume T: "open T" "x \<in> T" and x: "x \<in> s"
1.1759 +    from openE[OF T] obtain e where "0 < e" "ball x e \<subseteq> T"
1.1760 +      by auto
1.1761 +    then have "0 < e / 2" "ball x (e / 2) \<subseteq> T"
1.1762 +      by auto
1.1763 +    from Rats_dense_in_real[OF `0 < e / 2`] obtain r where "r \<in> \<rat>" "0 < r" "r < e / 2"
1.1764 +      by auto
1.1765      from f[rule_format, of r] `0 < r` `x \<in> s` obtain k where "k \<in> f r" "x \<in> ball k r"
1.1766        unfolding Union_image_eq by auto
1.1767 -    from `r \<in> \<rat>` `0 < r` `k \<in> f r` have "ball k r \<in> K" by (auto simp: K_def)
1.1768 +    from `r \<in> \<rat>` `0 < r` `k \<in> f r` have "ball k r \<in> K"
1.1769 +      by (auto simp: K_def)
1.1770      then show "\<exists>b\<in>K. x \<in> b \<and> b \<inter> s \<subseteq> T"
1.1771      proof (rule bexI[rotated], safe)
1.1772 -      fix y assume "y \<in> ball k r"
1.1773 +      fix y
1.1774 +      assume "y \<in> ball k r"
1.1775        with `r < e / 2` `x \<in> ball k r` have "dist x y < e"
1.1776          by (intro dist_double[where x = k and d=e]) (auto simp: dist_commute)
1.1777 -      with `ball x e \<subseteq> T` show "y \<in> T" by auto
1.1778 -    qed (rule `x \<in> ball k r`)
1.1779 +      with `ball x e \<subseteq> T` show "y \<in> T"
1.1780 +        by auto
1.1781 +    next
1.1782 +      show "x \<in> ball k r" by fact
1.1783 +    qed
1.1784    qed
1.1785  qed
1.1786
1.1787 @@ -3433,18 +3623,20 @@
1.1788
1.1789  lemma compact_eq_bolzano_weierstrass:
1.1790    fixes s :: "'a::metric_space set"
1.1791 -  shows "compact s \<longleftrightarrow> (\<forall>t. infinite t \<and> t \<subseteq> s --> (\<exists>x \<in> s. x islimpt t))" (is "?lhs = ?rhs")
1.1792 +  shows "compact s \<longleftrightarrow> (\<forall>t. infinite t \<and> t \<subseteq> s --> (\<exists>x \<in> s. x islimpt t))"
1.1793 +  (is "?lhs = ?rhs")
1.1794  proof
1.1795    assume ?lhs
1.1796 -  thus ?rhs using heine_borel_imp_bolzano_weierstrass[of s] by auto
1.1797 +  then show ?rhs
1.1798 +    using heine_borel_imp_bolzano_weierstrass[of s] by auto
1.1799  next
1.1800    assume ?rhs
1.1801 -  thus ?lhs
1.1802 +  then show ?lhs
1.1803      unfolding compact_eq_seq_compact_metric by (rule bolzano_weierstrass_imp_seq_compact)
1.1804  qed
1.1805
1.1806  lemma bolzano_weierstrass_imp_bounded:
1.1807 -  "\<forall>t. infinite t \<and> t \<subseteq> s --> (\<exists>x \<in> s. x islimpt t) \<Longrightarrow> bounded s"
1.1808 +  "\<forall>t. infinite t \<and> t \<subseteq> s \<longrightarrow> (\<exists>x \<in> s. x islimpt t) \<Longrightarrow> bounded s"
1.1809    using compact_imp_bounded unfolding compact_eq_bolzano_weierstrass .
1.1810
1.1811  text {*
1.1812 @@ -3458,13 +3650,18 @@
1.1813
1.1814  lemma bounded_closed_imp_seq_compact:
1.1815    fixes s::"'a::heine_borel set"
1.1816 -  assumes "bounded s" and "closed s" shows "seq_compact s"
1.1817 +  assumes "bounded s"
1.1818 +    and "closed s"
1.1819 +  shows "seq_compact s"
1.1820  proof (unfold seq_compact_def, clarify)
1.1821 -  fix f :: "nat \<Rightarrow> 'a" assume f: "\<forall>n. f n \<in> s"
1.1822 -  with `bounded s` have "bounded (range f)" by (auto intro: bounded_subset)
1.1823 +  fix f :: "nat \<Rightarrow> 'a"
1.1824 +  assume f: "\<forall>n. f n \<in> s"
1.1825 +  with `bounded s` have "bounded (range f)"
1.1826 +    by (auto intro: bounded_subset)
1.1827    obtain l r where r: "subseq r" and l: "((f \<circ> r) ---> l) sequentially"
1.1828      using bounded_imp_convergent_subsequence [OF `bounded (range f)`] by auto
1.1829 -  from f have fr: "\<forall>n. (f \<circ> r) n \<in> s" by simp
1.1830 +  from f have fr: "\<forall>n. (f \<circ> r) n \<in> s"
1.1831 +    by simp
1.1832    have "l \<in> s" using `closed s` fr l
1.1833      unfolding closed_sequential_limits by blast
1.1834    show "\<exists>l\<in>s. \<exists>r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
1.1835 @@ -3476,12 +3673,12 @@
1.1836    shows "compact s \<longleftrightarrow> bounded s \<and> closed s"  (is "?lhs = ?rhs")
1.1837  proof
1.1838    assume ?lhs
1.1839 -  thus ?rhs
1.1840 +  then show ?rhs
1.1841      using compact_imp_closed compact_imp_bounded
1.1842      by blast
1.1843  next
1.1844    assume ?rhs
1.1845 -  thus ?lhs
1.1846 +  then show ?lhs
1.1847      using bounded_closed_imp_seq_compact[of s]
1.1848      unfolding compact_eq_seq_compact_metric
1.1849      by auto
1.1850 @@ -3514,41 +3711,48 @@
1.1851          (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) \<bullet> i) (l \<bullet> i) < e) sequentially)"
1.1852  proof safe
1.1853    fix d :: "'a set"
1.1854 -  assume d: "d \<subseteq> Basis"
1.1855 -  with finite_Basis have "finite d" by (blast intro: finite_subset)
1.1856 +  assume d: "d \<subseteq> Basis"
1.1857 +  with finite_Basis have "finite d"
1.1858 +    by (blast intro: finite_subset)
1.1859    from this d show "\<exists>l::'a. \<exists>r. subseq r \<and>
1.1860      (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) \<bullet> i) (l \<bullet> i) < e) sequentially)"
1.1861    proof (induct d)
1.1862      case empty
1.1863 -    thus ?case unfolding subseq_def by auto
1.1864 +    then show ?case
1.1865 +      unfolding subseq_def by auto
1.1866    next
1.1867      case (insert k d)
1.1868 -    have k[intro]:"k\<in>Basis" using insert by auto
1.1869 -    have s': "bounded ((\<lambda>x. x \<bullet> k) ` range f)" using `bounded (range f)`
1.1870 +    have k[intro]: "k \<in> Basis"
1.1871 +      using insert by auto
1.1872 +    have s': "bounded ((\<lambda>x. x \<bullet> k) ` range f)"
1.1873 +      using `bounded (range f)`
1.1874        by (auto intro!: bounded_linear_image bounded_linear_inner_left)
1.1875 -    obtain l1::"'a" and r1 where r1:"subseq r1" and
1.1876 -      lr1:"\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 n) \<bullet> i) (l1 \<bullet> i) < e) sequentially"
1.1877 +    obtain l1::"'a" and r1 where r1: "subseq r1"
1.1878 +      and lr1: "\<forall>e > 0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 n) \<bullet> i) (l1 \<bullet> i) < e) sequentially"
1.1879        using insert(3) using insert(4) by auto
1.1880 -    have f': "\<forall>n. f (r1 n) \<bullet> k \<in> (\<lambda>x. x \<bullet> k) ` range f" by simp
1.1881 +    have f': "\<forall>n. f (r1 n) \<bullet> k \<in> (\<lambda>x. x \<bullet> k) ` range f"
1.1882 +      by simp
1.1883      have "bounded (range (\<lambda>i. f (r1 i) \<bullet> k))"
1.1884        by (metis (lifting) bounded_subset f' image_subsetI s')
1.1885      then obtain l2 r2 where r2:"subseq r2" and lr2:"((\<lambda>i. f (r1 (r2 i)) \<bullet> k) ---> l2) sequentially"
1.1886 -      using bounded_imp_convergent_subsequence[of "\<lambda>i. f (r1 i) \<bullet> k"] by (auto simp: o_def)
1.1887 -    def r \<equiv> "r1 \<circ> r2" have r:"subseq r"
1.1888 +      using bounded_imp_convergent_subsequence[of "\<lambda>i. f (r1 i) \<bullet> k"]
1.1889 +      by (auto simp: o_def)
1.1890 +    def r \<equiv> "r1 \<circ> r2"
1.1891 +    have r:"subseq r"
1.1892        using r1 and r2 unfolding r_def o_def subseq_def by auto
1.1893      moreover
1.1894      def l \<equiv> "(\<Sum>i\<in>Basis. (if i = k then l2 else l1\<bullet>i) *\<^sub>R i)::'a"
1.1895      {
1.1896        fix e::real
1.1897 -      assume "e>0"
1.1898 -      from lr1 `e>0` have N1:"eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 n) \<bullet> i) (l1 \<bullet> i) < e) sequentially"
1.1899 +      assume "e > 0"
1.1900 +      from lr1 `e > 0` have N1: "eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 n) \<bullet> i) (l1 \<bullet> i) < e) sequentially"
1.1901          by blast
1.1902 -      from lr2 `e>0` have N2:"eventually (\<lambda>n. dist (f (r1 (r2 n)) \<bullet> k) l2 < e) sequentially"
1.1903 +      from lr2 `e > 0` have N2:"eventually (\<lambda>n. dist (f (r1 (r2 n)) \<bullet> k) l2 < e) sequentially"
1.1904          by (rule tendstoD)
1.1905        from r2 N1 have N1': "eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 (r2 n)) \<bullet> i) (l1 \<bullet> i) < e) sequentially"
1.1906          by (rule eventually_subseq)
1.1907        have "eventually (\<lambda>n. \<forall>i\<in>(insert k d). dist (f (r n) \<bullet> i) (l \<bullet> i) < e) sequentially"
1.1908 -        using N1' N2
1.1909 +        using N1' N2
1.1910          by eventually_elim (insert insert.prems, auto simp: l_def r_def o_def)
1.1911      }
1.1912      ultimately show ?case by auto
1.1913 @@ -3564,8 +3768,8 @@
1.1914      using compact_lemma [OF f] by blast
1.1915    {
1.1916      fix e::real
1.1917 -    assume "e>0"
1.1918 -    hence "0 < e / real_of_nat DIM('a)"
1.1919 +    assume "e > 0"
1.1920 +    then have "e / real_of_nat DIM('a) > 0"
1.1921        by (auto intro!: divide_pos_pos DIM_positive)
1.1922      with l have "eventually (\<lambda>n. \<forall>i\<in>Basis. dist (f (r n) \<bullet> i) (l \<bullet> i) < e / (real_of_nat DIM('a))) sequentially"
1.1923        by simp
1.1924 @@ -3576,18 +3780,20 @@
1.1925        have "dist (f (r n)) l \<le> (\<Sum>i\<in>Basis. dist (f (r n) \<bullet> i) (l \<bullet> i))"
1.1926          apply (subst euclidean_dist_l2)
1.1927          using zero_le_dist
1.1928 -        by (rule setL2_le_setsum)
1.1929 +        apply (rule setL2_le_setsum)
1.1930 +        done
1.1931        also have "\<dots> < (\<Sum>i\<in>(Basis::'a set). e / (real_of_nat DIM('a)))"
1.1932          apply (rule setsum_strict_mono)
1.1933          using n
1.1934 -        by auto
1.1935 -      finally have "dist (f (r n)) l < e"
1.1936 +        apply auto
1.1937 +        done
1.1938 +      finally have "dist (f (r n)) l < e"
1.1939          by auto
1.1940      }
1.1941      ultimately have "eventually (\<lambda>n. dist (f (r n)) l < e) sequentially"
1.1942        by (rule eventually_elim1)
1.1943    }
1.1944 -  hence *: "((f \<circ> r) ---> l) sequentially"
1.1945 +  then have *: "((f \<circ> r) ---> l) sequentially"
1.1946      unfolding o_def tendsto_iff by simp
1.1947    with r show "\<exists>l r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
1.1948      by auto
1.1949 @@ -3619,13 +3825,13 @@
1.1950  proof
1.1951    fix f :: "nat \<Rightarrow> 'a \<times> 'b"
1.1952    assume f: "bounded (range f)"
1.1953 -  from f have s1: "bounded (range (fst \<circ> f))" unfolding image_comp by (rule bounded_fst)
1.1954 +  from f have s1: "bounded (range (fst \<circ> f))"
1.1955 +    unfolding image_comp by (rule bounded_fst)
1.1956    obtain l1 r1 where r1: "subseq r1" and l1: "(\<lambda>n. fst (f (r1 n))) ----> l1"
1.1957      using bounded_imp_convergent_subsequence [OF s1] unfolding o_def by fast
1.1958    from f have s2: "bounded (range (snd \<circ> f \<circ> r1))"
1.1959      by (auto simp add: image_comp intro: bounded_snd bounded_subset)
1.1960 -  obtain l2 r2 where r2: "subseq r2"
1.1961 -    and l2: "((\<lambda>n. snd (f (r1 (r2 n)))) ---> l2) sequentially"
1.1962 +  obtain l2 r2 where r2: "subseq r2" and l2: "((\<lambda>n. snd (f (r1 (r2 n)))) ---> l2) sequentially"
1.1963      using bounded_imp_convergent_subsequence [OF s2]
1.1964      unfolding o_def by fast
1.1965    have l1': "((\<lambda>n. fst (f (r1 (r2 n)))) ---> l1) sequentially"
1.1966 @@ -3656,36 +3862,42 @@
1.1967      note lr' = seq_suble [OF lr(2)]
1.1968
1.1969      {
1.1970 -      fix e::real
1.1971 -      assume "e>0"
1.1972 +      fix e :: real
1.1973 +      assume "e > 0"
1.1974        from as(2) obtain N where N:"\<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (f m) (f n) < e/2"
1.1975          unfolding cauchy_def
1.1976 -        using `e>0` apply (erule_tac x="e/2" in allE)
1.1977 +        using `e > 0`
1.1978 +        apply (erule_tac x="e/2" in allE)
1.1979          apply auto
1.1980          done
1.1981        from lr(3)[unfolded LIMSEQ_def, THEN spec[where x="e/2"]]
1.1982 -      obtain M where M:"\<forall>n\<ge>M. dist ((f \<circ> r) n) l < e/2" using `e>0` by auto
1.1983 +      obtain M where M:"\<forall>n\<ge>M. dist ((f \<circ> r) n) l < e/2"
1.1984 +        using `e > 0` by auto
1.1985        {
1.1986 -        fix n::nat
1.1987 -        assume n:"n \<ge> max N M"
1.1988 -        have "dist ((f \<circ> r) n) l < e/2" using n M by auto
1.1989 -        moreover have "r n \<ge> N" using lr'[of n] n by auto
1.1990 -        hence "dist (f n) ((f \<circ> r) n) < e / 2" using N using n by auto
1.1991 +        fix n :: nat
1.1992 +        assume n: "n \<ge> max N M"
1.1993 +        have "dist ((f \<circ> r) n) l < e/2"
1.1994 +          using n M by auto
1.1995 +        moreover have "r n \<ge> N"
1.1996 +          using lr'[of n] n by auto
1.1997 +        then have "dist (f n) ((f \<circ> r) n) < e / 2"
1.1998 +          using N and n by auto
1.1999          ultimately have "dist (f n) l < e"
1.2000 -          using dist_triangle_half_r[of "f (r n)" "f n" e l] by (auto simp add: dist_commute)
1.2001 +          using dist_triangle_half_r[of "f (r n)" "f n" e l]
1.2002 +          by (auto simp add: dist_commute)
1.2003        }
1.2004 -      hence "\<exists>N. \<forall>n\<ge>N. dist (f n) l < e" by blast
1.2005 +      then have "\<exists>N. \<forall>n\<ge>N. dist (f n) l < e" by blast
1.2006      }
1.2007 -    hence "\<exists>l\<in>s. (f ---> l) sequentially" using `l\<in>s`
1.2008 +    then have "\<exists>l\<in>s. (f ---> l) sequentially" using `l\<in>s`
1.2009        unfolding LIMSEQ_def by auto
1.2010    }
1.2011 -  thus ?thesis unfolding complete_def by auto
1.2012 +  then show ?thesis unfolding complete_def by auto
1.2013  qed
1.2014
1.2015  lemma nat_approx_posE:
1.2016    fixes e::real
1.2017    assumes "0 < e"
1.2018 -  obtains n::nat where "1 / (Suc n) < e"
1.2019 +  obtains n :: nat where "1 / (Suc n) < e"
1.2020  proof atomize_elim
1.2021    have " 1 / real (Suc (nat (ceiling (1/e)))) < 1 / (ceiling (1/e))"
1.2022      by (rule divide_strict_left_mono) (auto intro!: mult_pos_pos simp: `0 < e`)
1.2023 @@ -3705,18 +3917,22 @@
1.2024
1.2025    show "compact s"
1.2026    proof cases
1.2027 -    assume "s = {}" thus "compact s" by (simp add: compact_def)
1.2028 +    assume "s = {}"
1.2029 +    then show "compact s" by (simp add: compact_def)
1.2030    next
1.2031      assume "s \<noteq> {}"
1.2032      show ?thesis
1.2033        unfolding compact_def
1.2034      proof safe
1.2035 -      fix f :: "nat \<Rightarrow> 'a" assume f: "\<forall>n. f n \<in> s"
1.2036 -
1.2037 +      fix f :: "nat \<Rightarrow> 'a"
1.2038 +      assume f: "\<forall>n. f n \<in> s"
1.2039 +
1.2040        def e \<equiv> "\<lambda>n. 1 / (2 * Suc n)"
1.2041        then have [simp]: "\<And>n. 0 < e n" by auto
1.2042        def B \<equiv> "\<lambda>n U. SOME b. infinite {n. f n \<in> b} \<and> (\<exists>x. b \<subseteq> ball x (e n) \<inter> U)"
1.2043 -      { fix n U assume "infinite {n. f n \<in> U}"
1.2044 +      {
1.2045 +        fix n U
1.2046 +        assume "infinite {n. f n \<in> U}"
1.2047          then have "\<exists>b\<in>k (e n). infinite {i\<in>{n. f n \<in> U}. f i \<in> ball b (e n)}"
1.2048            using k f by (intro pigeonhole_infinite_rel) (auto simp: subset_eq)
1.2049          then guess a ..
1.2050 @@ -3724,12 +3940,16 @@
1.2051            by (intro exI[of _ "ball a (e n) \<inter> U"] exI[of _ a]) (auto simp: ac_simps)
1.2052          from someI_ex[OF this]
1.2053          have "infinite {i. f i \<in> B n U}" "\<exists>x. B n U \<subseteq> ball x (e n) \<inter> U"
1.2054 -          unfolding B_def by auto }
1.2055 +          unfolding B_def by auto
1.2056 +      }
1.2057        note B = this
1.2058
1.2059        def F \<equiv> "nat_rec (B 0 UNIV) B"
1.2060 -      { fix n have "infinite {i. f i \<in> F n}"
1.2061 -          by (induct n) (auto simp: F_def B) }
1.2062 +      {
1.2063 +        fix n
1.2064 +        have "infinite {i. f i \<in> F n}"
1.2065 +          by (induct n) (auto simp: F_def B)
1.2066 +      }
1.2067        then have F: "\<And>n. \<exists>x. F (Suc n) \<subseteq> ball x (e n) \<inter> F n"
1.2068          using B by (simp add: F_def)
1.2069        then have F_dec: "\<And>m n. m \<le> n \<Longrightarrow> F n \<subseteq> F m"
1.2070 @@ -3751,13 +3971,17 @@
1.2071        moreover have "\<forall>i. (f \<circ> t) i \<in> s"
1.2072          using f by auto
1.2073        moreover
1.2074 -      { fix n have "(f \<circ> t) n \<in> F n"
1.2075 -          by (cases n) (simp_all add: t_def sel) }
1.2076 +      {
1.2077 +        fix n
1.2078 +        have "(f \<circ> t) n \<in> F n"
1.2079 +          by (cases n) (simp_all add: t_def sel)
1.2080 +      }
1.2081        note t = this
1.2082
1.2083        have "Cauchy (f \<circ> t)"
1.2084        proof (safe intro!: metric_CauchyI exI elim!: nat_approx_posE)
1.2085 -        fix r :: real and N n m assume "1 / Suc N < r" "Suc N \<le> n" "Suc N \<le> m"
1.2086 +        fix r :: real and N n m
1.2087 +        assume "1 / Suc N < r" "Suc N \<le> n" "Suc N \<le> m"
1.2088          then have "(f \<circ> t) n \<in> F (Suc N)" "(f \<circ> t) m \<in> F (Suc N)" "2 * e N < r"
1.2089            using F_dec t by (auto simp: e_def field_simps real_of_nat_Suc)
1.2090          with F[of N] obtain x where "dist x ((f \<circ> t) n) < e N" "dist x ((f \<circ> t) m) < e N"
1.2091 @@ -3774,39 +3998,44 @@
1.2092  qed (metis compact_imp_complete compact_imp_seq_compact seq_compact_imp_totally_bounded)
1.2093
1.2094  lemma cauchy: "Cauchy s \<longleftrightarrow> (\<forall>e>0.\<exists> N::nat. \<forall>n\<ge>N. dist(s n)(s N) < e)" (is "?lhs = ?rhs")
1.2095 -proof-
1.2096 -  { assume ?rhs
1.2097 -    { fix e::real
1.2098 +proof -
1.2099 +  {
1.2100 +    assume ?rhs
1.2101 +    {
1.2102 +      fix e::real
1.2103        assume "e>0"
1.2104        with `?rhs` obtain N where N:"\<forall>n\<ge>N. dist (s n) (s N) < e/2"
1.2105          by (erule_tac x="e/2" in allE) auto
1.2106 -      { fix n m
1.2107 +      {
1.2108 +        fix n m
1.2109          assume nm:"N \<le> m \<and> N \<le> n"
1.2110 -        hence "dist (s m) (s n) < e" using N
1.2111 +        then have "dist (s m) (s n) < e" using N
1.2112            using dist_triangle_half_l[of "s m" "s N" "e" "s n"]
1.2113            by blast
1.2114        }
1.2115 -      hence "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < e"
1.2116 +      then have "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < e"
1.2117          by blast
1.2118      }
1.2119 -    hence ?lhs
1.2120 +    then have ?lhs
1.2121        unfolding cauchy_def
1.2122        by blast
1.2123    }
1.2124 -  thus ?thesis
1.2125 +  then show ?thesis
1.2126      unfolding cauchy_def
1.2127      using dist_triangle_half_l
1.2128      by blast
1.2129  qed
1.2130
1.2131 -lemma cauchy_imp_bounded: assumes "Cauchy s" shows "bounded (range s)"
1.2132 -proof-
1.2133 -  from assms obtain N::nat where "\<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < 1"
1.2134 +lemma cauchy_imp_bounded:
1.2135 +  assumes "Cauchy s"
1.2136 +  shows "bounded (range s)"
1.2137 +proof -
1.2138 +  from assms obtain N :: nat where "\<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < 1"
1.2139      unfolding cauchy_def
1.2140      apply (erule_tac x= 1 in allE)
1.2141      apply auto
1.2142      done
1.2143 -  hence N:"\<forall>n. N \<le> n \<longrightarrow> dist (s N) (s n) < 1" by auto
1.2144 +  then have N:"\<forall>n. N \<le> n \<longrightarrow> dist (s N) (s n) < 1" by auto
1.2145    moreover
1.2146    have "bounded (s ` {0..N})"
1.2147      using finite_imp_bounded[of "s ` {1..N}"] by auto
1.2148 @@ -3825,11 +4054,11 @@
1.2149  instance heine_borel < complete_space
1.2150  proof
1.2151    fix f :: "nat \<Rightarrow> 'a" assume "Cauchy f"
1.2152 -  hence "bounded (range f)"
1.2153 +  then have "bounded (range f)"
1.2154      by (rule cauchy_imp_bounded)
1.2155 -  hence "compact (closure (range f))"
1.2156 +  then have "compact (closure (range f))"
1.2157      unfolding compact_eq_bounded_closed by auto
1.2158 -  hence "complete (closure (range f))"
1.2159 +  then have "complete (closure (range f))"
1.2160      by (rule compact_imp_complete)
1.2161    moreover have "\<forall>n. f n \<in> closure (range f)"
1.2162      using closure_subset [of "range f"] by auto
1.2163 @@ -3842,29 +4071,36 @@
1.2164  instance euclidean_space \<subseteq> banach ..
1.2165
1.2166  lemma complete_univ: "complete (UNIV :: 'a::complete_space set)"
1.2167 -proof(simp add: complete_def, rule, rule)
1.2168 -  fix f :: "nat \<Rightarrow> 'a" assume "Cauchy f"
1.2169 -  hence "convergent f" by (rule Cauchy_convergent)
1.2170 -  thus "\<exists>l. f ----> l" unfolding convergent_def .
1.2171 -qed
1.2172 -
1.2173 -lemma complete_imp_closed: assumes "complete s" shows "closed s"
1.2174 +proof (simp add: complete_def, rule, rule)
1.2175 +  fix f :: "nat \<Rightarrow> 'a"
1.2176 +  assume "Cauchy f"
1.2177 +  then have "convergent f" by (rule Cauchy_convergent)
1.2178 +  then show "\<exists>l. f ----> l" unfolding convergent_def .
1.2179 +qed
1.2180 +
1.2181 +lemma complete_imp_closed:
1.2182 +  assumes "complete s"
1.2183 +  shows "closed s"
1.2184  proof -
1.2185 -  { fix x assume "x islimpt s"
1.2186 +  {
1.2187 +    fix x
1.2188 +    assume "x islimpt s"
1.2189      then obtain f where f: "\<forall>n. f n \<in> s - {x}" "(f ---> x) sequentially"
1.2190        unfolding islimpt_sequential by auto
1.2191      then obtain l where l: "l\<in>s" "(f ---> l) sequentially"
1.2192        using `complete s`[unfolded complete_def] using LIMSEQ_imp_Cauchy[of f x] by auto
1.2193 -    hence "x \<in> s"  using tendsto_unique[of sequentially f l x] trivial_limit_sequentially f(2) by auto
1.2194 +    then have "x \<in> s"
1.2195 +      using tendsto_unique[of sequentially f l x] trivial_limit_sequentially f(2) by auto
1.2196    }
1.2197 -  thus "closed s" unfolding closed_limpt by auto
1.2198 +  then show "closed s" unfolding closed_limpt by auto
1.2199  qed
1.2200
1.2201  lemma complete_eq_closed:
1.2202    fixes s :: "'a::complete_space set"
1.2203    shows "complete s \<longleftrightarrow> closed s" (is "?lhs = ?rhs")
1.2204  proof
1.2205 -  assume ?lhs thus ?rhs by (rule complete_imp_closed)
1.2206 +  assume ?lhs
1.2207 +  then show ?rhs by (rule complete_imp_closed)
1.2208  next
1.2209    assume ?rhs
1.2210    {
1.2211 @@ -3872,11 +4108,11 @@
1.2212      assume as:"\<forall>n::nat. f n \<in> s" "Cauchy f"
1.2213      then obtain l where "(f ---> l) sequentially"
1.2214        using complete_univ[unfolded complete_def, THEN spec[where x=f]] by auto
1.2215 -    hence "\<exists>l\<in>s. (f ---> l) sequentially"
1.2216 +    then have "\<exists>l\<in>s. (f ---> l) sequentially"
1.2217        using `?rhs`[unfolded closed_sequential_limits, THEN spec[where x=f], THEN spec[where x=l]]
1.2218        using as(1) by auto
1.2219    }
1.2220 -  thus ?lhs unfolding complete_def by auto
1.2221 +  then show ?lhs unfolding complete_def by auto
1.2222  qed
1.2223
1.2224  lemma convergent_eq_cauchy:
1.2225 @@ -3933,56 +4169,94 @@
1.2226      apply blast
1.2227      done
1.2228
1.2229 -  { fix n::nat
1.2230 -    { fix e::real assume "e>0"
1.2231 +  {
1.2232 +    fix n :: nat
1.2233 +    {
1.2234 +      fix e :: real
1.2235 +      assume "e>0"
1.2236        with lr(3) obtain N where N:"\<forall>m\<ge>N. dist ((x \<circ> r) m) l < e"
1.2237          unfolding LIMSEQ_def by auto
1.2238 -      hence "dist ((x \<circ> r) (max N n)) l < e" by auto
1.2239 +      then have "dist ((x \<circ> r) (max N n)) l < e" by auto
1.2240        moreover
1.2241 -      have "r (max N n) \<ge> n" using lr(2) using seq_suble[of r "max N n"] by auto
1.2242 -      hence "(x \<circ> r) (max N n) \<in> s n"
1.2243 -        using x apply (erule_tac x=n in allE)
1.2244 -        using x apply (erule_tac x="r (max N n)" in allE)
1.2245 -        using assms(3) apply (erule_tac x=n in allE)
1.2246 +      have "r (max N n) \<ge> n" using lr(2) using seq_suble[of r "max N n"]
1.2247 +        by auto
1.2248 +      then have "(x \<circ> r) (max N n) \<in> s n"
1.2249 +        using x
1.2250 +        apply (erule_tac x=n in allE)
1.2251 +        using x
1.2252 +        apply (erule_tac x="r (max N n)" in allE)
1.2253 +        using assms(3)
1.2254 +        apply (erule_tac x=n in allE)
1.2255          apply (erule_tac x="r (max N n)" in allE)
1.2256          apply auto
1.2257          done
1.2258 -      ultimately have "\<exists>y\<in>s n. dist y l < e" by auto
1.2259 +      ultimately have "\<exists>y\<in>s n. dist y l < e"
1.2260 +        by auto
1.2261      }
1.2262 -    hence "l \<in> s n" using closed_approachable[of "s n" l] assms(1) by blast
1.2263 +    then have "l \<in> s n"
1.2264 +      using closed_approachable[of "s n" l] assms(1) by blast
1.2265    }
1.2266 -  thus ?thesis by auto
1.2267 +  then show ?thesis by auto
1.2268  qed
1.2269
1.2270  text {* Decreasing case does not even need compactness, just completeness. *}
1.2271
1.2272  lemma decreasing_closed_nest:
1.2273 -  assumes "\<forall>n. closed(s n)"
1.2274 -          "\<forall>n. (s n \<noteq> {})"
1.2275 -          "\<forall>m n. m \<le> n --> s n \<subseteq> s m"
1.2276 -          "\<forall>e>0. \<exists>n. \<forall>x \<in> (s n). \<forall> y \<in> (s n). dist x y < e"
1.2277 +  assumes
1.2278 +    "\<forall>n. closed(s n)"
1.2279 +    "\<forall>n. (s n \<noteq> {})"
1.2280 +    "\<forall>m n. m \<le> n --> s n \<subseteq> s m"
1.2281 +    "\<forall>e>0. \<exists>n. \<forall>x \<in> (s n). \<forall> y \<in> (s n). dist x y < e"
1.2282    shows "\<exists>a::'a::complete_space. \<forall>n::nat. a \<in> s n"
1.2283  proof-
1.2284 -  have "\<forall>n. \<exists> x. x\<in>s n" using assms(2) by auto
1.2285 -  hence "\<exists>t. \<forall>n. t n \<in> s n" using choice[of "\<lambda> n x. x \<in> s n"] by auto
1.2286 +  have "\<forall>n. \<exists> x. x\<in>s n"
1.2287 +    using assms(2) by auto
1.2288 +  then have "\<exists>t. \<forall>n. t n \<in> s n"
1.2289 +    using choice[of "\<lambda> n x. x \<in> s n"] by auto
1.2290    then obtain t where t: "\<forall>n. t n \<in> s n" by auto
1.2291 -  { fix e::real assume "e>0"
1.2292 -    then obtain N where N:"\<forall>x\<in>s N. \<forall>y\<in>s N. dist x y < e" using assms(4) by auto
1.2293 -    { fix m n ::nat assume "N \<le> m \<and> N \<le> n"
1.2294 -      hence "t m \<in> s N" "t n \<in> s N" using assms(3) t unfolding  subset_eq t by blast+
1.2295 -      hence "dist (t m) (t n) < e" using N by auto
1.2296 +  {
1.2297 +    fix e :: real
1.2298 +    assume "e > 0"
1.2299 +    then obtain N where N:"\<forall>x\<in>s N. \<forall>y\<in>s N. dist x y < e"
1.2300 +      using assms(4) by auto
1.2301 +    {
1.2302 +      fix m n :: nat
1.2303 +      assume "N \<le> m \<and> N \<le> n"
1.2304 +      then have "t m \<in> s N" "t n \<in> s N"
1.2305 +        using assms(3) t unfolding  subset_eq t by blast+
1.2306 +      then have "dist (t m) (t n) < e"
1.2307 +        using N by auto
1.2308      }
1.2309 -    hence "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (t m) (t n) < e" by auto
1.2310 +    then have "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (t m) (t n) < e"
1.2311 +      by auto
1.2312    }
1.2313 -  hence  "Cauchy t" unfolding cauchy_def by auto
1.2314 -  then obtain l where l:"(t ---> l) sequentially" using complete_univ unfolding complete_def by auto
1.2315 -  { fix n::nat
1.2316 -    { fix e::real assume "e>0"
1.2317 -      then obtain N::nat where N:"\<forall>n\<ge>N. dist (t n) l < e" using l[unfolded LIMSEQ_def] by auto
1.2318 -      have "t (max n N) \<in> s n" using assms(3) unfolding subset_eq apply(erule_tac x=n in allE) apply (erule_tac x="max n N" in allE) using t by auto
1.2319 -      hence "\<exists>y\<in>s n. dist y l < e" apply(rule_tac x="t (max n N)" in bexI) using N by auto
1.2320 +  then have "Cauchy t"
1.2321 +    unfolding cauchy_def by auto
1.2322 +  then obtain l where l:"(t ---> l) sequentially"
1.2323 +    using complete_univ unfolding complete_def by auto
1.2324 +  {
1.2325 +    fix n :: nat
1.2326 +    {
1.2327 +      fix e :: real
1.2328 +      assume "e > 0"
1.2329 +      then obtain N :: nat where N: "\<forall>n\<ge>N. dist (t n) l < e"
1.2330 +        using l[unfolded LIMSEQ_def] by auto
1.2331 +      have "t (max n N) \<in> s n"
1.2332 +        using assms(3)
1.2333 +        unfolding subset_eq
1.2334 +        apply (erule_tac x=n in allE)
1.2335 +        apply (erule_tac x="max n N" in allE)
1.2336 +        using t
1.2337 +        apply auto
1.2338 +        done
1.2339 +      then have "\<exists>y\<in>s n. dist y l < e"
1.2340 +        apply (rule_tac x="t (max n N)" in bexI)
1.2341 +        using N
1.2342 +        apply auto
1.2343 +        done
1.2344      }
1.2345 -    hence "l \<in> s n" using closed_approachable[of "s n" l] assms(1) by auto
1.2346 +    then have "l \<in> s n"
1.2347 +      using closed_approachable[of "s n" l] assms(1) by auto
1.2348    }
1.2349    then show ?thesis by auto
1.2350  qed
1.2351 @@ -3991,56 +4265,94 @@
1.2352
1.2353  lemma decreasing_closed_nest_sing:
1.2354    fixes s :: "nat \<Rightarrow> 'a::complete_space set"
1.2355 -  assumes "\<forall>n. closed(s n)"
1.2356 -          "\<forall>n. s n \<noteq> {}"
1.2357 -          "\<forall>m n. m \<le> n --> s n \<subseteq> s m"
1.2358 -          "\<forall>e>0. \<exists>n. \<forall>x \<in> (s n). \<forall> y\<in>(s n). dist x y < e"
1.2359 +  assumes
1.2360 +    "\<forall>n. closed(s n)"
1.2361 +    "\<forall>n. s n \<noteq> {}"
1.2362 +    "\<forall>m n. m \<le> n --> s n \<subseteq> s m"
1.2363 +    "\<forall>e>0. \<exists>n. \<forall>x \<in> (s n). \<forall> y\<in>(s n). dist x y < e"
1.2364    shows "\<exists>a. \<Inter>(range s) = {a}"
1.2365 -proof-
1.2366 -  obtain a where a:"\<forall>n. a \<in> s n" using decreasing_closed_nest[of s] using assms by auto
1.2367 -  { fix b assume b:"b \<in> \<Inter>(range s)"
1.2368 -    { fix e::real assume "e>0"
1.2369 -      hence "dist a b < e" using assms(4 )using b using a by blast
1.2370 +proof -
1.2371 +  obtain a where a: "\<forall>n. a \<in> s n"
1.2372 +    using decreasing_closed_nest[of s] using assms by auto
1.2373 +  {
1.2374 +    fix b
1.2375 +    assume b: "b \<in> \<Inter>(range s)"
1.2376 +    {
1.2377 +      fix e :: real
1.2378 +      assume "e > 0"
1.2379 +      then have "dist a b < e"
1.2380 +        using assms(4) and b and a by blast
1.2381      }
1.2382 -    hence "dist a b = 0" by (metis dist_eq_0_iff dist_nz less_le)
1.2383 +    then have "dist a b = 0"
1.2384 +      by (metis dist_eq_0_iff dist_nz less_le)
1.2385    }
1.2386 -  with a have "\<Inter>(range s) = {a}" unfolding image_def by auto
1.2387 -  thus ?thesis ..
1.2388 +  with a have "\<Inter>(range s) = {a}"
1.2389 +    unfolding image_def by auto
1.2390 +  then show ?thesis ..
1.2391  qed
1.2392
1.2393  text{* Cauchy-type criteria for uniform convergence. *}
1.2394
1.2395 -lemma uniformly_convergent_eq_cauchy: fixes s::"nat \<Rightarrow> 'b \<Rightarrow> 'a::complete_space" shows
1.2396 - "(\<exists>l. \<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x --> dist(s n x)(l x) < e) \<longleftrightarrow>
1.2397 -  (\<forall>e>0. \<exists>N. \<forall>m n x. N \<le> m \<and> N \<le> n \<and> P x  --> dist (s m x) (s n x) < e)" (is "?lhs = ?rhs")
1.2398 -proof(rule)
1.2399 +lemma uniformly_convergent_eq_cauchy:
1.2400 +  fixes s::"nat \<Rightarrow> 'b \<Rightarrow> 'a::complete_space"
1.2401 +  shows
1.2402 +    "(\<exists>l. \<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x --> dist(s n x)(l x) < e) \<longleftrightarrow>
1.2403 +      (\<forall>e>0. \<exists>N. \<forall>m n x. N \<le> m \<and> N \<le> n \<and> P x  --> dist (s m x) (s n x) < e)"
1.2404 +  (is "?lhs = ?rhs")
1.2405 +proof
1.2406    assume ?lhs
1.2407 -  then obtain l where l:"\<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist (s n x) (l x) < e" by auto
1.2408 -  { fix e::real assume "e>0"
1.2409 -    then obtain N::nat where N:"\<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist (s n x) (l x) < e / 2" using l[THEN spec[where x="e/2"]] by auto
1.2410 -    { fix n m::nat and x::"'b" assume "N \<le> m \<and> N \<le> n \<and> P x"
1.2411 -      hence "dist (s m x) (s n x) < e"
1.2412 +  then obtain l where l:"\<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist (s n x) (l x) < e"
1.2413 +    by auto
1.2414 +  {
1.2415 +    fix e :: real
1.2416 +    assume "e > 0"
1.2417 +    then obtain N :: nat where N: "\<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist (s n x) (l x) < e / 2"
1.2418 +      using l[THEN spec[where x="e/2"]] by auto
1.2419 +    {
1.2420 +      fix n m :: nat and x :: "'b"
1.2421 +      assume "N \<le> m \<and> N \<le> n \<and> P x"
1.2422 +      then have "dist (s m x) (s n x) < e"
1.2423          using N[THEN spec[where x=m], THEN spec[where x=x]]
1.2424          using N[THEN spec[where x=n], THEN spec[where x=x]]
1.2425 -        using dist_triangle_half_l[of "s m x" "l x" e "s n x"] by auto  }
1.2426 -    hence "\<exists>N. \<forall>m n x. N \<le> m \<and> N \<le> n \<and> P x  --> dist (s m x) (s n x) < e"  by auto  }
1.2427 -  thus ?rhs by auto
1.2428 +        using dist_triangle_half_l[of "s m x" "l x" e "s n x"] by auto
1.2429 +    }
1.2430 +    then have "\<exists>N. \<forall>m n x. N \<le> m \<and> N \<le> n \<and> P x  --> dist (s m x) (s n x) < e"  by auto
1.2431 +  }
1.2432 +  then show ?rhs by auto
1.2433  next
1.2434    assume ?rhs
1.2435 -  hence "\<forall>x. P x \<longrightarrow> Cauchy (\<lambda>n. s n x)" unfolding cauchy_def apply auto by (erule_tac x=e in allE)auto
1.2436 -  then obtain l where l:"\<forall>x. P x \<longrightarrow> ((\<lambda>n. s n x) ---> l x) sequentially" unfolding convergent_eq_cauchy[THEN sym]
1.2437 -    using choice[of "\<lambda>x l. P x \<longrightarrow> ((\<lambda>n. s n x) ---> l) sequentially"] by auto
1.2438 -  { fix e::real assume "e>0"
1.2439 +  then have "\<forall>x. P x \<longrightarrow> Cauchy (\<lambda>n. s n x)"
1.2440 +    unfolding cauchy_def
1.2441 +    apply auto
1.2442 +    apply (erule_tac x=e in allE)
1.2443 +    apply auto
1.2444 +    done
1.2445 +  then obtain l where l: "\<forall>x. P x \<longrightarrow> ((\<lambda>n. s n x) ---> l x) sequentially"
1.2446 +    unfolding convergent_eq_cauchy[THEN sym]
1.2447 +    using choice[of "\<lambda>x l. P x \<longrightarrow> ((\<lambda>n. s n x) ---> l) sequentially"]
1.2448 +    by auto
1.2449 +  {
1.2450 +    fix e :: real
1.2451 +    assume "e > 0"
1.2452      then obtain N where N:"\<forall>m n x. N \<le> m \<and> N \<le> n \<and> P x \<longrightarrow> dist (s m x) (s n x) < e/2"
1.2453        using `?rhs`[THEN spec[where x="e/2"]] by auto
1.2454 -    { fix x assume "P x"
1.2455 +    {
1.2456 +      fix x
1.2457 +      assume "P x"
1.2458        then obtain M where M:"\<forall>n\<ge>M. dist (s n x) (l x) < e/2"
1.2459 -        using l[THEN spec[where x=x], unfolded LIMSEQ_def] using `e>0` by(auto elim!: allE[where x="e/2"])
1.2460 -      fix n::nat assume "n\<ge>N"
1.2461 -      hence "dist(s n x)(l x) < e"  using `P x`and N[THEN spec[where x=n], THEN spec[where x="N+M"], THEN spec[where x=x]]
1.2462 -        using M[THEN spec[where x="N+M"]] and dist_triangle_half_l[of "s n x" "s (N+M) x" e "l x"] by (auto simp add: dist_commute)  }
1.2463 -    hence "\<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist(s n x)(l x) < e" by auto }
1.2464 -  thus ?lhs by auto
1.2465 +        using l[THEN spec[where x=x], unfolded LIMSEQ_def] and `e > 0`
1.2466 +        by (auto elim!: allE[where x="e/2"])
1.2467 +      fix n :: nat
1.2468 +      assume "n \<ge> N"
1.2469 +      then have "dist(s n x)(l x) < e"
1.2470 +        using `P x`and N[THEN spec[where x=n], THEN spec[where x="N+M"], THEN spec[where x=x]]
1.2471 +        using M[THEN spec[where x="N+M"]] and dist_triangle_half_l[of "s n x" "s (N+M) x" e "l x"]
1.2472 +        by (auto simp add: dist_commute)
1.2473 +    }
1.2474 +    then have "\<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist(s n x)(l x) < e"
1.2475 +      by auto
1.2476 +  }
1.2477 +  then show ?lhs by auto
1.2478  qed
1.2479
1.2480  lemma uniformly_cauchy_imp_uniformly_convergent:
1.2481 @@ -4048,13 +4360,17 @@
1.2482    assumes "\<forall>e>0.\<exists>N. \<forall>m (n::nat) x. N \<le> m \<and> N \<le> n \<and> P x --> dist(s m x)(s n x) < e"
1.2483            "\<forall>x. P x --> (\<forall>e>0. \<exists>N. \<forall>n. N \<le> n --> dist(s n x)(l x) < e)"
1.2484    shows "\<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x --> dist(s n x)(l x) < e"
1.2485 -proof-
1.2486 +proof -
1.2487    obtain l' where l:"\<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist (s n x) (l' x) < e"
1.2488      using assms(1) unfolding uniformly_convergent_eq_cauchy[THEN sym] by auto
1.2489    moreover
1.2490 -  { fix x assume "P x"
1.2491 -    hence "l x = l' x" using tendsto_unique[OF trivial_limit_sequentially, of "\<lambda>n. s n x" "l x" "l' x"]
1.2492 -      using l and assms(2) unfolding LIMSEQ_def by blast  }
1.2493 +  {
1.2494 +    fix x
1.2495 +    assume "P x"
1.2496 +    then have "l x = l' x"
1.2497 +      using tendsto_unique[OF trivial_limit_sequentially, of "\<lambda>n. s n x" "l x" "l' x"]
1.2498 +      using l and assms(2) unfolding LIMSEQ_def by blast
1.2499 +  }
1.2500    ultimately show ?thesis by auto
1.2501  qed
1.2502
1.2503 @@ -4066,42 +4382,86 @@
1.2504  lemma continuous_within_eps_delta:
1.2505    "continuous (at x within s) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0. \<forall>x'\<in> s.  dist x' x < d --> dist (f x') (f x) < e)"
1.2506    unfolding continuous_within and Lim_within
1.2507 -  apply auto unfolding dist_nz[THEN sym] apply(auto del: allE elim!:allE) apply(rule_tac x=d in exI) by auto
1.2508 -
1.2509 -lemma continuous_at_eps_delta: "continuous (at x) f \<longleftrightarrow>  (\<forall>e>0. \<exists>d>0.
1.2510 -                           \<forall>x'. dist x' x < d --> dist(f x')(f x) < e)"
1.2511 +  apply auto
1.2512 +  unfolding dist_nz[THEN sym]
1.2513 +  apply (auto del: allE elim!:allE)
1.2514 +  apply(rule_tac x=d in exI)
1.2515 +  apply auto
1.2516 +  done
1.2517 +
1.2518 +lemma continuous_at_eps_delta:
1.2519 +  "continuous (at x) f \<longleftrightarrow> (\<forall>e > 0. \<exists>d > 0. \<forall>x'. dist x' x < d \<longrightarrow> dist (f x') (f x) < e)"
1.2520    using continuous_within_eps_delta [of x UNIV f] by simp
1.2521
1.2522  text{* Versions in terms of open balls. *}
1.2523
1.2524  lemma continuous_within_ball:
1.2525 - "continuous (at x within s) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0.
1.2526 -                            f ` (ball x d \<inter> s) \<subseteq> ball (f x) e)" (is "?lhs = ?rhs")
1.2527 +  "continuous (at x within s) f \<longleftrightarrow>
1.2528 +    (\<forall>e > 0. \<exists>d > 0. f ` (ball x d \<inter> s) \<subseteq> ball (f x) e)"
1.2529 +  (is "?lhs = ?rhs")
1.2530  proof
1.2531    assume ?lhs
1.2532 -  { fix e::real assume "e>0"
1.2533 +  {
1.2534 +    fix e :: real
1.2535 +    assume "e > 0"
1.2536      then obtain d where d: "d>0" "\<forall>xa\<in>s. 0 < dist xa x \<and> dist xa x < d \<longrightarrow> dist (f xa) (f x) < e"
1.2537        using `?lhs`[unfolded continuous_within Lim_within] by auto
1.2538 -    { fix y assume "y\<in>f ` (ball x d \<inter> s)"
1.2539 -      hence "y \<in> ball (f x) e" using d(2) unfolding dist_nz[THEN sym]
1.2540 -        apply (auto simp add: dist_commute) apply(erule_tac x=xa in ballE) apply auto using `e>0` by auto
1.2541 +    {
1.2542 +      fix y
1.2543 +      assume "y \<in> f ` (ball x d \<inter> s)"
1.2544 +      then have "y \<in> ball (f x) e"
1.2545 +        using d(2)
1.2546 +        unfolding dist_nz[THEN sym]
1.2547 +        apply (auto simp add: dist_commute)
1.2548 +        apply (erule_tac x=xa in ballE)
1.2549 +        apply auto
1.2550 +        using `e > 0`
1.2551 +        apply auto
1.2552 +        done
1.2553      }
1.2554 -    hence "\<exists>d>0. f ` (ball x d \<inter> s) \<subseteq> ball (f x) e" using `d>0` unfolding subset_eq ball_def by (auto simp add: dist_commute)  }
1.2555 -  thus ?rhs by auto
1.2556 +    then have "\<exists>d>0. f ` (ball x d \<inter> s) \<subseteq> ball (f x) e"
1.2557 +      using `d > 0`
1.2558 +      unfolding subset_eq ball_def by (auto simp add: dist_commute)
1.2559 +  }
1.2560 +  then show ?rhs by auto
1.2561  next
1.2562 -  assume ?rhs thus ?lhs unfolding continuous_within Lim_within ball_def subset_eq
1.2563 -    apply (auto simp add: dist_commute) apply(erule_tac x=e in allE) by auto
1.2564 +  assume ?rhs
1.2565 +  then show ?lhs
1.2566 +    unfolding continuous_within Lim_within ball_def subset_eq
1.2567 +    apply (auto simp add: dist_commute)
1.2568 +    apply (erule_tac x=e in allE)
1.2569 +    apply auto
1.2570 +    done
1.2571  qed
1.2572
1.2573  lemma continuous_at_ball:
1.2574    "continuous (at x) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0. f ` (ball x d) \<subseteq> ball (f x) e)" (is "?lhs = ?rhs")
1.2575  proof
1.2576 -  assume ?lhs thus ?rhs unfolding continuous_at Lim_at subset_eq Ball_def Bex_def image_iff mem_ball
1.2577 -    apply auto apply(erule_tac x=e in allE) apply auto apply(rule_tac x=d in exI) apply auto apply(erule_tac x=xa in allE) apply (auto simp add: dist_commute dist_nz)
1.2578 -    unfolding dist_nz[THEN sym] by auto
1.2579 +  assume ?lhs
1.2580 +  then show ?rhs
1.2581 +    unfolding continuous_at Lim_at subset_eq Ball_def Bex_def image_iff mem_ball
1.2582 +    apply auto
1.2583 +    apply (erule_tac x=e in allE)
1.2584 +    apply auto
1.2585 +    apply (rule_tac x=d in exI)
1.2586 +    apply auto
1.2587 +    apply (erule_tac x=xa in allE)
1.2588 +    apply (auto simp add: dist_commute dist_nz)
1.2589 +    unfolding dist_nz[THEN sym]
1.2590 +    apply auto
1.2591 +    done
1.2592  next
1.2593 -  assume ?rhs thus ?lhs unfolding continuous_at Lim_at subset_eq Ball_def Bex_def image_iff mem_ball
1.2594 -    apply auto apply(erule_tac x=e in allE) apply auto apply(rule_tac x=d in exI) apply auto apply(erule_tac x="f xa" in allE) by (auto simp add: dist_commute dist_nz)
1.2595 +  assume ?rhs
1.2596 +  then show ?lhs
1.2597 +    unfolding continuous_at Lim_at subset_eq Ball_def Bex_def image_iff mem_ball
1.2598 +    apply auto
1.2599 +    apply (erule_tac x=e in allE)
1.2600 +    apply auto
1.2601 +    apply (rule_tac x=d in exI)
1.2602 +    apply auto
1.2603 +    apply (erule_tac x="f xa" in allE)
1.2604 +    apply (auto simp add: dist_commute dist_nz)
1.2605 +    done
1.2606  qed
1.2607
1.2608  text{* Define setwise continuity in terms of limits within the set. *}
1.2609 @@ -4109,27 +4469,25 @@
1.2610  lemma continuous_on_iff:
1.2611    "continuous_on s f \<longleftrightarrow>
1.2612      (\<forall>x\<in>s. \<forall>e>0. \<exists>d>0. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f x') (f x) < e)"
1.2613 -unfolding continuous_on_def Lim_within
1.2614 -apply (intro ball_cong [OF refl] all_cong ex_cong)
1.2615 -apply (rename_tac y, case_tac "y = x", simp)
1.2616 -apply (simp add: dist_nz)
1.2617 -done
1.2618 -
1.2619 -definition
1.2620 -  uniformly_continuous_on ::
1.2621 -    "'a set \<Rightarrow> ('a::metric_space \<Rightarrow> 'b::metric_space) \<Rightarrow> bool"
1.2622 -where
1.2623 -  "uniformly_continuous_on s f \<longleftrightarrow>
1.2624 +  unfolding continuous_on_def Lim_within
1.2625 +  apply (intro ball_cong [OF refl] all_cong ex_cong)
1.2626 +  apply (rename_tac y, case_tac "y = x")
1.2627 +  apply simp
1.2628 +  apply (simp add: dist_nz)
1.2629 +  done
1.2630 +
1.2631 +definition uniformly_continuous_on :: "'a set \<Rightarrow> ('a::metric_space \<Rightarrow> 'b::metric_space) \<Rightarrow> bool"
1.2632 +  where "uniformly_continuous_on s f \<longleftrightarrow>
1.2633      (\<forall>e>0. \<exists>d>0. \<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f x') (f x) < e)"
1.2634
1.2635  text{* Some simple consequential lemmas. *}
1.2636
1.2637  lemma uniformly_continuous_imp_continuous:
1.2638 - " uniformly_continuous_on s f ==> continuous_on s f"
1.2639 +  "uniformly_continuous_on s f \<Longrightarrow> continuous_on s f"
1.2640    unfolding uniformly_continuous_on_def continuous_on_iff by blast
1.2641
1.2642  lemma continuous_at_imp_continuous_within:
1.2643 - "continuous (at x) f ==> continuous (at x within s) f"
1.2644 +  "continuous (at x) f \<Longrightarrow> continuous (at x within s) f"
1.2645    unfolding continuous_within continuous_at using Lim_at_within by auto
1.2646
1.2647  lemma Lim_trivial_limit: "trivial_limit net \<Longrightarrow> (f ---> l) net"
1.2648 @@ -4138,14 +4496,15 @@
1.2649  lemmas continuous_on = continuous_on_def -- "legacy theorem name"
1.2650
1.2651  lemma continuous_within_subset:
1.2652 - "continuous (at x within s) f \<Longrightarrow> t \<subseteq> s
1.2653 -             ==> continuous (at x within t) f"
1.2654 +  "continuous (at x within s) f \<Longrightarrow> t \<subseteq> s \<Longrightarrow> continuous (at x within t) f"
1.2655    unfolding continuous_within by(metis tendsto_within_subset)
1.2656
1.2657  lemma continuous_on_interior:
1.2658 -  shows "continuous_on s f \<Longrightarrow> x \<in> interior s \<Longrightarrow> continuous (at x) f"
1.2659 -  by (erule interiorE, drule (1) continuous_on_subset,
1.2660 -    simp add: continuous_on_eq_continuous_at)
1.2661 +  "continuous_on s f \<Longrightarrow> x \<in> interior s \<Longrightarrow> continuous (at x) f"
1.2662 +  apply (erule interiorE)
1.2663 +  apply (drule (1) continuous_on_subset)
1.2664 +  apply (simp add: continuous_on_eq_continuous_at)
1.2665 +  done
1.2666
1.2667  lemma continuous_on_eq:
1.2668    "(\<forall>x \<in> s. f x = g x) \<Longrightarrow> continuous_on s f \<Longrightarrow> continuous_on s g"
1.2669 @@ -4157,25 +4516,32 @@
1.2670  lemma continuous_within_sequentially:
1.2671    fixes f :: "'a::metric_space \<Rightarrow> 'b::topological_space"
1.2672    shows "continuous (at a within s) f \<longleftrightarrow>
1.2673 -                (\<forall>x. (\<forall>n::nat. x n \<in> s) \<and> (x ---> a) sequentially
1.2674 -                     --> ((f o x) ---> f a) sequentially)" (is "?lhs = ?rhs")
1.2675 +    (\<forall>x. (\<forall>n::nat. x n \<in> s) \<and> (x ---> a) sequentially
1.2676 +         \<longrightarrow> ((f o x) ---> f a) sequentially)"
1.2677 +  (is "?lhs = ?rhs")
1.2678  proof
1.2679    assume ?lhs
1.2680 -  { fix x::"nat \<Rightarrow> 'a" assume x:"\<forall>n. x n \<in> s" "\<forall>e>0. eventually (\<lambda>n. dist (x n) a < e) sequentially"
1.2681 -    fix T::"'b set" assume "open T" and "f a \<in> T"
1.2682 +  {
1.2683 +    fix x :: "nat \<Rightarrow> 'a"
1.2684 +    assume x: "\<forall>n. x n \<in> s" "\<forall>e>0. eventually (\<lambda>n. dist (x n) a < e) sequentially"
1.2685 +    fix T :: "'b set"
1.2686 +    assume "open T" and "f a \<in> T"
1.2687      with `?lhs` obtain d where "d>0" and d:"\<forall>x\<in>s. 0 < dist x a \<and> dist x a < d \<longrightarrow> f x \<in> T"
1.2688        unfolding continuous_within tendsto_def eventually_at by (auto simp: dist_nz)
1.2689      have "eventually (\<lambda>n. dist (x n) a < d) sequentially"
1.2690        using x(2) `d>0` by simp
1.2691 -    hence "eventually (\<lambda>n. (f \<circ> x) n \<in> T) sequentially"
1.2692 +    then have "eventually (\<lambda>n. (f \<circ> x) n \<in> T) sequentially"
1.2693      proof eventually_elim
1.2694 -      case (elim n) thus ?case
1.2695 +      case (elim n)
1.2696 +      then show ?case
1.2697          using d x(1) `f a \<in> T` unfolding dist_nz[THEN sym] by auto
1.2698      qed
1.2699    }
1.2700 -  thus ?rhs unfolding tendsto_iff unfolding tendsto_def by simp
1.2701 +  then show ?rhs
1.2702 +    unfolding tendsto_iff tendsto_def by simp
1.2703  next
1.2704 -  assume ?rhs thus ?lhs
1.2705 +  assume ?rhs
1.2706 +  then show ?lhs
1.2707      unfolding continuous_within tendsto_def [where l="f a"]
1.2708      by (simp add: sequentially_imp_eventually_within)
1.2709  qed
1.2710 @@ -4192,9 +4558,17 @@
1.2711      (\<forall>x. \<forall>a \<in> s. (\<forall>n. x(n) \<in> s) \<and> (x ---> a) sequentially
1.2712                      --> ((f o x) ---> f(a)) sequentially)" (is "?lhs = ?rhs")
1.2713  proof
1.2714 -  assume ?rhs thus ?lhs using continuous_within_sequentially[of _ s f] unfolding continuous_on_eq_continuous_within by auto
1.2715 +  assume ?rhs
1.2716 +  then show ?lhs
1.2717 +    using continuous_within_sequentially[of _ s f]
1.2718 +    unfolding continuous_on_eq_continuous_within
1.2719 +    by auto
1.2720  next
1.2721 -  assume ?lhs thus ?rhs unfolding continuous_on_eq_continuous_within using continuous_within_sequentially[of _ s f] by auto
1.2722 +  assume ?lhs
1.2723 +  then show ?rhs
1.2724 +    unfolding continuous_on_eq_continuous_within
1.2725 +    using continuous_within_sequentially[of _ s f]
1.2726 +    by auto
1.2727  qed
1.2728
1.2729  lemma uniformly_continuous_on_sequentially:
1.2730 @@ -4203,67 +4577,108 @@
1.2731                      \<longrightarrow> ((\<lambda>n. dist (f(x n)) (f(y n))) ---> 0) sequentially)" (is "?lhs = ?rhs")
1.2732  proof
1.2733    assume ?lhs
1.2734 -  { fix x y assume x:"\<forall>n. x n \<in> s" and y:"\<forall>n. y n \<in> s" and xy:"((\<lambda>n. dist (x n) (y n)) ---> 0) sequentially"
1.2735 -    { fix e::real assume "e>0"
1.2736 -      then obtain d where "d>0" and d:"\<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f x') (f x) < e"
1.2737 +  {
1.2738 +    fix x y
1.2739 +    assume x: "\<forall>n. x n \<in> s"
1.2740 +      and y: "\<forall>n. y n \<in> s"
1.2741 +      and xy: "((\<lambda>n. dist (x n) (y n)) ---> 0) sequentially"
1.2742 +    {
1.2743 +      fix e :: real
1.2744 +      assume "e > 0"
1.2745 +      then obtain d where "d > 0" and d: "\<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f x') (f x) < e"
1.2746          using `?lhs`[unfolded uniformly_continuous_on_def, THEN spec[where x=e]] by auto
1.2747 -      obtain N where N:"\<forall>n\<ge>N. dist (x n) (y n) < d" using xy[unfolded LIMSEQ_def dist_norm] and `d>0` by auto
1.2748 -      { fix n assume "n\<ge>N"
1.2749 -        hence "dist (f (x n)) (f (y n)) < e"
1.2750 -          using N[THEN spec[where x=n]] using d[THEN bspec[where x="x n"], THEN bspec[where x="y n"]] using x and y
1.2751 -          unfolding dist_commute by simp  }
1.2752 -      hence "\<exists>N. \<forall>n\<ge>N. dist (f (x n)) (f (y n)) < e"  by auto  }
1.2753 -    hence "((\<lambda>n. dist (f(x n)) (f(y n))) ---> 0) sequentially" unfolding LIMSEQ_def and dist_real_def by auto  }
1.2754 -  thus ?rhs by auto
1.2755 +      obtain N where N: "\<forall>n\<ge>N. dist (x n) (y n) < d"
1.2756 +        using xy[unfolded LIMSEQ_def dist_norm] and `d>0` by auto
1.2757 +      {
1.2758 +        fix n
1.2759 +        assume "n\<ge>N"
1.2760 +        then have "dist (f (x n)) (f (y n)) < e"
1.2761 +          using N[THEN spec[where x=n]]
1.2762 +          using d[THEN bspec[where x="x n"], THEN bspec[where x="y n"]]
1.2763 +          using x and y
1.2764 +          unfolding dist_commute
1.2765 +          by simp
1.2766 +      }
1.2767 +      then have "\<exists>N. \<forall>n\<ge>N. dist (f (x n)) (f (y n)) < e"
1.2768 +        by auto
1.2769 +    }
1.2770 +    then have "((\<lambda>n. dist (f(x n)) (f(y n))) ---> 0) sequentially"
1.2771 +      unfolding LIMSEQ_def and dist_real_def by auto
1.2772 +  }
1.2773 +  then show ?rhs by auto
1.2774  next
1.2775    assume ?rhs
1.2776 -  { assume "\<not> ?lhs"
1.2777 -    then obtain e where "e>0" "\<forall>d>0. \<exists>x\<in>s. \<exists>x'\<in>s. dist x' x < d \<and> \<not> dist (f x') (f x) < e" unfolding uniformly_continuous_on_def by auto
1.2778 -    then obtain fa where fa:"\<forall>x.  0 < x \<longrightarrow> fst (fa x) \<in> s \<and> snd (fa x) \<in> s \<and> dist (fst (fa x)) (snd (fa x)) < x \<and> \<not> dist (f (fst (fa x))) (f (snd (fa x))) < e"
1.2779 -      using choice[of "\<lambda>d x. d>0 \<longrightarrow> fst x \<in> s \<and> snd x \<in> s \<and> dist (snd x) (fst x) < d \<and> \<not> dist (f (snd x)) (f (fst x)) < e"] unfolding Bex_def
1.2780 +  {
1.2781 +    assume "\<not> ?lhs"
1.2782 +    then obtain e where "e > 0" "\<forall>d>0. \<exists>x\<in>s. \<exists>x'\<in>s. dist x' x < d \<and> \<not> dist (f x') (f x) < e"
1.2783 +      unfolding uniformly_continuous_on_def by auto
1.2784 +    then obtain fa where fa:
1.2785 +      "\<forall>x. 0 < x \<longrightarrow> fst (fa x) \<in> s \<and> snd (fa x) \<in> s \<and> dist (fst (fa x)) (snd (fa x)) < x \<and> \<not> dist (f (fst (fa x))) (f (snd (fa x))) < e"
1.2786 +      using choice[of "\<lambda>d x. d>0 \<longrightarrow> fst x \<in> s \<and> snd x \<in> s \<and> dist (snd x) (fst x) < d \<and> \<not> dist (f (snd x)) (f (fst x)) < e"]
1.2787 +      unfolding Bex_def
1.2788        by (auto simp add: dist_commute)
1.2789      def x \<equiv> "\<lambda>n::nat. fst (fa (inverse (real n + 1)))"
1.2790      def y \<equiv> "\<lambda>n::nat. snd (fa (inverse (real n + 1)))"
1.2791 -    have xyn:"\<forall>n. x n \<in> s \<and> y n \<in> s" and xy0:"\<forall>n. dist (x n) (y n) < inverse (real n + 1)" and fxy:"\<forall>n. \<not> dist (f (x n)) (f (y n)) < e"
1.2792 -      unfolding x_def and y_def using fa by auto
1.2793 -    { fix e::real assume "e>0"
1.2794 -      then obtain N::nat where "N \<noteq> 0" and N:"0 < inverse (real N) \<and> inverse (real N) < e" unfolding real_arch_inv[of e]   by auto
1.2795 -      { fix n::nat assume "n\<ge>N"
1.2796 -        hence "inverse (real n + 1) < inverse (real N)" using real_of_nat_ge_zero and `N\<noteq>0` by auto
1.2797 +    have xyn: "\<forall>n. x n \<in> s \<and> y n \<in> s"
1.2798 +      and xy0: "\<forall>n. dist (x n) (y n) < inverse (real n + 1)"
1.2799 +      and fxy:"\<forall>n. \<not> dist (f (x n)) (f (y n)) < e"
1.2800 +      unfolding x_def and y_def using fa
1.2801 +      by auto
1.2802 +    {
1.2803 +      fix e :: real
1.2804 +      assume "e > 0"
1.2805 +      then obtain N :: nat where "N \<noteq> 0" and N: "0 < inverse (real N) \<and> inverse (real N) < e"
1.2806 +        unfolding real_arch_inv[of e] by auto
1.2807 +      {
1.2808 +        fix n :: nat
1.2809 +        assume "n \<ge> N"
1.2810 +        then have "inverse (real n + 1) < inverse (real N)"
1.2811 +          using real_of_nat_ge_zero and `N\<noteq>0` by auto
1.2812          also have "\<dots> < e" using N by auto
1.2813          finally have "inverse (real n + 1) < e" by auto
1.2814 -        hence "dist (x n) (y n) < e" using xy0[THEN spec[where x=n]] by auto  }
1.2815 -      hence "\<exists>N. \<forall>n\<ge>N. dist (x n) (y n) < e" by auto  }
1.2816 -    hence "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. dist (f (x n)) (f (y n)) < e" using `?rhs`[THEN spec[where x=x], THEN spec[where x=y]] and xyn unfolding LIMSEQ_def dist_real_def by auto
1.2817 -    hence False using fxy and `e>0` by auto  }
1.2818 -  thus ?lhs unfolding uniformly_continuous_on_def by blast
1.2819 +        then have "dist (x n) (y n) < e"
1.2820 +          using xy0[THEN spec[where x=n]] by auto
1.2821 +      }
1.2822 +      then have "\<exists>N. \<forall>n\<ge>N. dist (x n) (y n) < e" by auto
1.2823 +    }
1.2824 +    then have "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. dist (f (x n)) (f (y n)) < e"
1.2825 +      using `?rhs`[THEN spec[where x=x], THEN spec[where x=y]] and xyn
1.2826 +      unfolding LIMSEQ_def dist_real_def by auto
1.2827 +    then have False using fxy and `e>0` by auto
1.2828 +  }
1.2829 +  then show ?lhs
1.2830 +    unfolding uniformly_continuous_on_def by blast
1.2831  qed
1.2832
1.2833  text{* The usual transformation theorems. *}
1.2834
1.2835  lemma continuous_transform_within:
1.2836    fixes f g :: "'a::metric_space \<Rightarrow> 'b::topological_space"
1.2837 -  assumes "0 < d" "x \<in> s" "\<forall>x' \<in> s. dist x' x < d --> f x' = g x'"
1.2838 -          "continuous (at x within s) f"
1.2839 +  assumes "0 < d"
1.2840 +    and "x \<in> s"
1.2841 +    and "\<forall>x' \<in> s. dist x' x < d --> f x' = g x'"
1.2842 +    and "continuous (at x within s) f"
1.2843    shows "continuous (at x within s) g"
1.2844 -unfolding continuous_within
1.2845 +  unfolding continuous_within
1.2846  proof (rule Lim_transform_within)
1.2847    show "0 < d" by fact
1.2848    show "\<forall>x'\<in>s. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
1.2849      using assms(3) by auto
1.2850    have "f x = g x"
1.2851      using assms(1,2,3) by auto
1.2852 -  thus "(f ---> g x) (at x within s)"
1.2853 +  then show "(f ---> g x) (at x within s)"
1.2854      using assms(4) unfolding continuous_within by simp
1.2855  qed
1.2856
1.2857  lemma continuous_transform_at:
1.2858    fixes f g :: "'a::metric_space \<Rightarrow> 'b::topological_space"
1.2859 -  assumes "0 < d" "\<forall>x'. dist x' x < d --> f x' = g x'"
1.2860 -          "continuous (at x) f"
1.2861 +  assumes "0 < d"
1.2862 +    and "\<forall>x'. dist x' x < d --> f x' = g x'"
1.2863 +    and "continuous (at x) f"
1.2864    shows "continuous (at x) g"
1.2865    using continuous_transform_within [of d x UNIV f g] assms by simp
1.2866
1.2867 +
1.2868  subsubsection {* Structural rules for pointwise continuity *}
1.2869
1.2870  lemmas continuous_within_id = continuous_ident
1.2871 @@ -4276,11 +4691,12 @@
1.2872    using assms unfolding continuous_def by (rule tendsto_infdist)
1.2873
1.2874  lemma continuous_infnorm[continuous_intros]:
1.2875 -  shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. infnorm (f x))"
1.2876 +  "continuous F f \<Longrightarrow> continuous F (\<lambda>x. infnorm (f x))"
1.2877    unfolding continuous_def by (rule tendsto_infnorm)
1.2878
1.2879  lemma continuous_inner[continuous_intros]:
1.2880 -  assumes "continuous F f" and "continuous F g"
1.2881 +  assumes "continuous F f"
1.2882 +    and "continuous F g"
1.2883    shows "continuous F (\<lambda>x. inner (f x) (g x))"
1.2884    using assms unfolding continuous_def by (rule tendsto_inner)
1.2885
1.2886 @@ -4289,12 +4705,13 @@
1.2887  subsubsection {* Structural rules for setwise continuity *}
1.2888
1.2889  lemma continuous_on_infnorm[continuous_on_intros]:
1.2890 -  shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. infnorm (f x))"
1.2891 +  "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. infnorm (f x))"
1.2892    unfolding continuous_on by (fast intro: tendsto_infnorm)
1.2893
1.2894  lemma continuous_on_inner[continuous_on_intros]:
1.2895    fixes g :: "'a::topological_space \<Rightarrow> 'b::real_inner"
1.2896 -  assumes "continuous_on s f" and "continuous_on s g"
1.2897 +  assumes "continuous_on s f"
1.2898 +    and "continuous_on s g"
1.2899    shows "continuous_on s (\<lambda>x. inner (f x) (g x))"
1.2900    using bounded_bilinear_inner assms
1.2901    by (rule bounded_bilinear.continuous_on)
1.2902 @@ -4302,32 +4719,36 @@
1.2903  subsubsection {* Structural rules for uniform continuity *}
1.2904
1.2905  lemma uniformly_continuous_on_id[continuous_on_intros]:
1.2906 -  shows "uniformly_continuous_on s (\<lambda>x. x)"
1.2907 +  "uniformly_continuous_on s (\<lambda>x. x)"
1.2908    unfolding uniformly_continuous_on_def by auto
1.2909
1.2910  lemma uniformly_continuous_on_const[continuous_on_intros]:
1.2911 -  shows "uniformly_continuous_on s (\<lambda>x. c)"
1.2912 +  "uniformly_continuous_on s (\<lambda>x. c)"
1.2913    unfolding uniformly_continuous_on_def by simp
1.2914
1.2915  lemma uniformly_continuous_on_dist[continuous_on_intros]:
1.2916    fixes f g :: "'a::metric_space \<Rightarrow> 'b::metric_space"
1.2917    assumes "uniformly_continuous_on s f"
1.2918 -  assumes "uniformly_continuous_on s g"
1.2919 +    and "uniformly_continuous_on s g"
1.2920    shows "uniformly_continuous_on s (\<lambda>x. dist (f x) (g x))"
1.2921  proof -
1.2922 -  { fix a b c d :: 'b have "\<bar>dist a b - dist c d\<bar> \<le> dist a c + dist b d"
1.2923 +  {
1.2924 +    fix a b c d :: 'b
1.2925 +    have "\<bar>dist a b - dist c d\<bar> \<le> dist a c + dist b d"
1.2926        using dist_triangle2 [of a b c] dist_triangle2 [of b c d]
1.2927        using dist_triangle3 [of c d a] dist_triangle [of a d b]
1.2928        by arith
1.2929    } note le = this
1.2930 -  { fix x y
1.2931 +  {
1.2932 +    fix x y
1.2933      assume f: "(\<lambda>n. dist (f (x n)) (f (y n))) ----> 0"
1.2934      assume g: "(\<lambda>n. dist (g (x n)) (g (y n))) ----> 0"
1.2935      have "(\<lambda>n. \<bar>dist (f (x n)) (g (x n)) - dist (f (y n)) (g (y n))\<bar>) ----> 0"
1.2936        by (rule Lim_transform_bound [OF _ tendsto_add_zero [OF f g]],
1.2937          simp add: le)
1.2938    }
1.2939 -  thus ?thesis using assms unfolding uniformly_continuous_on_sequentially
1.2940 +  then show ?thesis
1.2941 +    using assms unfolding uniformly_continuous_on_sequentially
1.2942      unfolding dist_real_def by simp
1.2943  qed
1.2944
1.2945 @@ -4364,15 +4785,17 @@
1.2947    fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
1.2948    assumes "uniformly_continuous_on s f"
1.2949 -  assumes "uniformly_continuous_on s g"
1.2950 +    and "uniformly_continuous_on s g"
1.2951    shows "uniformly_continuous_on s (\<lambda>x. f x + g x)"
1.2952 -  using assms unfolding uniformly_continuous_on_sequentially
1.2953 +  using assms
1.2954 +  unfolding uniformly_continuous_on_sequentially
1.2956    by (auto intro: tendsto_add_zero)
1.2957
1.2958  lemma uniformly_continuous_on_diff[continuous_on_intros]:
1.2959    fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
1.2960 -  assumes "uniformly_continuous_on s f" and "uniformly_continuous_on s g"
1.2961 +  assumes "uniformly_continuous_on s f"
1.2962 +    and "uniformly_continuous_on s g"
1.2963    shows "uniformly_continuous_on s (\<lambda>x. f x - g x)"
1.2964    unfolding ab_diff_minus using assms
1.2965    by (intro uniformly_continuous_on_add uniformly_continuous_on_minus)
1.2966 @@ -4385,22 +4808,32 @@
1.2967    assumes "uniformly_continuous_on s f"  "uniformly_continuous_on (f ` s) g"
1.2968    shows "uniformly_continuous_on s (g o f)"
1.2969  proof-
1.2970 -  { fix e::real assume "e>0"
1.2971 -    then obtain d where "d>0" and d:"\<forall>x\<in>f ` s. \<forall>x'\<in>f ` s. dist x' x < d \<longrightarrow> dist (g x') (g x) < e" using assms(2) unfolding uniformly_continuous_on_def by auto
1.2972 -    obtain d' where "d'>0" "\<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d' \<longrightarrow> dist (f x') (f x) < d" using `d>0` using assms(1) unfolding uniformly_continuous_on_def by auto
1.2973 -    hence "\<exists>d>0. \<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist ((g \<circ> f) x') ((g \<circ> f) x) < e" using `d>0` using d by auto  }
1.2974 -  thus ?thesis using assms unfolding uniformly_continuous_on_def by auto
1.2975 +  {
1.2976 +    fix e :: real
1.2977 +    assume "e > 0"
1.2978 +    then obtain d where "d > 0"
1.2979 +      and d: "\<forall>x\<in>f ` s. \<forall>x'\<in>f ` s. dist x' x < d \<longrightarrow> dist (g x') (g x) < e"
1.2980 +      using assms(2) unfolding uniformly_continuous_on_def by auto
1.2981 +    obtain d' where "d'>0" "\<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d' \<longrightarrow> dist (f x') (f x) < d"
1.2982 +      using `d > 0` using assms(1) unfolding uniformly_continuous_on_def by auto
1.2983 +    then have "\<exists>d>0. \<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist ((g \<circ> f) x') ((g \<circ> f) x) < e"
1.2984 +      using `d>0` using d by auto
1.2985 +  }
1.2986 +  then show ?thesis
1.2987 +    using assms unfolding uniformly_continuous_on_def by auto
1.2988  qed
1.2989
1.2990  text{* Continuity in terms of open preimages. *}
1.2991
1.2992  lemma continuous_at_open:
1.2993 -  shows "continuous (at x) f \<longleftrightarrow> (\<forall>t. open t \<and> f x \<in> t --> (\<exists>s. open s \<and> x \<in> s \<and> (\<forall>x' \<in> s. (f x') \<in> t)))"
1.2994 -unfolding continuous_within_topological [of x UNIV f]
1.2995 -unfolding imp_conjL by (intro all_cong imp_cong ex_cong conj_cong refl) auto
1.2996 +  "continuous (at x) f \<longleftrightarrow> (\<forall>t. open t \<and> f x \<in> t --> (\<exists>s. open s \<and> x \<in> s \<and> (\<forall>x' \<in> s. (f x') \<in> t)))"
1.2997 +  unfolding continuous_within_topological [of x UNIV f]
1.2998 +  unfolding imp_conjL
1.2999 +  by (intro all_cong imp_cong ex_cong conj_cong refl) auto
1.3000
1.3001  lemma continuous_imp_tendsto:
1.3002 -  assumes "continuous (at x0) f" and "x ----> x0"
1.3003 +  assumes "continuous (at x0) f"
1.3004 +    and "x ----> x0"
1.3005    shows "(f \<circ> x) ----> (f x0)"
1.3006  proof (rule topological_tendstoI)
1.3007    fix S
1.3008 @@ -4415,15 +4848,17 @@
1.3009
1.3010  lemma continuous_on_open:
1.3011    "continuous_on s f \<longleftrightarrow>
1.3012 -        (\<forall>t. openin (subtopology euclidean (f ` s)) t
1.3013 -            --> openin (subtopology euclidean s) {x \<in> s. f x \<in> t})" (is "?lhs = ?rhs")
1.3014 +    (\<forall>t. openin (subtopology euclidean (f ` s)) t \<longrightarrow>
1.3015 +      openin (subtopology euclidean s) {x \<in> s. f x \<in> t})"
1.3016    unfolding continuous_on_open_invariant openin_open Int_def vimage_def Int_commute
1.3017    by (simp add: imp_ex imageI conj_commute eq_commute cong: conj_cong)
1.3018
1.3019  text {* Similarly in terms of closed sets. *}
1.3020
1.3021  lemma continuous_on_closed:
1.3022 -  shows "continuous_on s f \<longleftrightarrow>  (\<forall>t. closedin (subtopology euclidean (f ` s)) t  --> closedin (subtopology euclidean s) {x \<in> s. f x \<in> t})" (is "?lhs = ?rhs")
1.3023 +  "continuous_on s f \<longleftrightarrow>
1.3024 +    (\<forall>t. closedin (subtopology euclidean (f ` s)) t \<longrightarrow>
1.3025 +      closedin (subtopology euclidean s) {x \<in> s. f x \<in> t})"
1.3026    unfolding continuous_on_closed_invariant closedin_closed Int_def vimage_def Int_commute
1.3027    by (simp add: imp_ex imageI conj_commute eq_commute cong: conj_cong)
1.3028
1.3029 @@ -4432,22 +4867,28 @@
1.3030  lemma continuous_open_in_preimage:
1.3031    assumes "continuous_on s f"  "open t"
1.3032    shows "openin (subtopology euclidean s) {x \<in> s. f x \<in> t}"
1.3033 -proof-
1.3034 -  have *:"\<forall>x. x \<in> s \<and> f x \<in> t \<longleftrightarrow> x \<in> s \<and> f x \<in> (t \<inter> f ` s)" by auto
1.3035 +proof -
1.3036 +  have *: "\<forall>x. x \<in> s \<and> f x \<in> t \<longleftrightarrow> x \<in> s \<and> f x \<in> (t \<inter> f ` s)"
1.3037 +    by auto
1.3038    have "openin (subtopology euclidean (f ` s)) (t \<inter> f ` s)"
1.3039      using openin_open_Int[of t "f ` s", OF assms(2)] unfolding openin_open by auto
1.3040 -  thus ?thesis using assms(1)[unfolded continuous_on_open, THEN spec[where x="t \<inter> f ` s"]] using * by auto
1.3041 +  then show ?thesis
1.3042 +    using assms(1)[unfolded continuous_on_open, THEN spec[where x="t \<inter> f ` s"]]
1.3043 +    using * by auto
1.3044  qed
1.3045
1.3046  lemma continuous_closed_in_preimage:
1.3047    assumes "continuous_on s f"  "closed t"
1.3048    shows "closedin (subtopology euclidean s) {x \<in> s. f x \<in> t}"
1.3049 -proof-
1.3050 -  have *:"\<forall>x. x \<in> s \<and> f x \<in> t \<longleftrightarrow> x \<in> s \<and> f x \<in> (t \<inter> f ` s)" by auto
1.3051 +proof -
1.3052 +  have *: "\<forall>x. x \<in> s \<and> f x \<in> t \<longleftrightarrow> x \<in> s \<and> f x \<in> (t \<inter> f ` s)"
1.3053 +    by auto
1.3054    have "closedin (subtopology euclidean (f ` s)) (t \<inter> f ` s)"
1.3055 -    using closedin_closed_Int[of t "f ` s", OF assms(2)] unfolding Int_commute by auto
1.3056 -  thus ?thesis
1.3057 -    using assms(1)[unfolded continuous_on_closed, THEN spec[where x="t \<inter> f ` s"]] using * by auto
1.3058 +    using closedin_closed_Int[of t "f ` s", OF assms(2)] unfolding Int_commute
1.3059 +    by auto
1.3060 +  then show ?thesis
1.3061 +    using assms(1)[unfolded continuous_on_closed, THEN spec[where x="t \<inter> f ` s"]]
1.3062 +    using * by auto
1.3063  qed
1.3064
1.3065  lemma continuous_open_preimage:
1.3066 @@ -4456,32 +4897,32 @@
1.3067  proof-
1.3068    obtain T where T: "open T" "{x \<in> s. f x \<in> t} = s \<inter> T"
1.3069      using continuous_open_in_preimage[OF assms(1,3)] unfolding openin_open by auto
1.3070 -  thus ?thesis using open_Int[of s T, OF assms(2)] by auto
1.3071 +  then show ?thesis
1.3072 +    using open_Int[of s T, OF assms(2)] by auto
1.3073  qed
1.3074
1.3075  lemma continuous_closed_preimage:
1.3076    assumes "continuous_on s f" "closed s" "closed t"
1.3077    shows "closed {x \<in> s. f x \<in> t}"
1.3078  proof-
1.3079 -  obtain T where T: "closed T" "{x \<in> s. f x \<in> t} = s \<inter> T"
1.3080 -    using continuous_closed_in_preimage[OF assms(1,3)] unfolding closedin_closed by auto
1.3081 -  thus ?thesis using closed_Int[of s T, OF assms(2)] by auto
1.3082 +  obtain T where "closed T" "{x \<in> s. f x \<in> t} = s \<inter> T"
1.3083 +    using continuous_closed_in_preimage[OF assms(1,3)]
1.3084 +    unfolding closedin_closed by auto
1.3085 +  then show ?thesis using closed_Int[of s T, OF assms(2)] by auto
1.3086  qed
1.3087
1.3088  lemma continuous_open_preimage_univ:
1.3089 -  shows "\<forall>x. continuous (at x) f \<Longrightarrow> open s \<Longrightarrow> open {x. f x \<in> s}"
1.3090 +  "\<forall>x. continuous (at x) f \<Longrightarrow> open s \<Longrightarrow> open {x. f x \<in> s}"
1.3091    using continuous_open_preimage[of UNIV f s] open_UNIV continuous_at_imp_continuous_on by auto
1.3092
1.3093  lemma continuous_closed_preimage_univ:
1.3094 -  shows "(\<forall>x. continuous (at x) f) \<Longrightarrow> closed s ==> closed {x. f x \<in> s}"
1.3095 +  "(\<forall>x. continuous (at x) f) \<Longrightarrow> closed s ==> closed {x. f x \<in> s}"
1.3096    using continuous_closed_preimage[of UNIV f s] closed_UNIV continuous_at_imp_continuous_on by auto
1.3097
1.3098 -lemma continuous_open_vimage:
1.3099 -  shows "\<forall>x. continuous (at x) f \<Longrightarrow> open s \<Longrightarrow> open (f -` s)"
1.3100 +lemma continuous_open_vimage: "\<forall>x. continuous (at x) f \<Longrightarrow> open s \<Longrightarrow> open (f -` s)"
1.3101    unfolding vimage_def by (rule continuous_open_preimage_univ)
1.3102
1.3103 -lemma continuous_closed_vimage:
1.3104 -  shows "\<forall>x. continuous (at x) f \<Longrightarrow> closed s \<Longrightarrow> closed (f -` s)"
1.3105 +lemma continuous_closed_vimage: "\<forall>x. continuous (at x) f \<Longrightarrow> closed s \<Longrightarrow> closed (f -` s)"
1.3106    unfolding vimage_def by (rule continuous_closed_preimage_univ)
1.3107
1.3108  lemma interior_image_subset:
1.3109 @@ -4490,7 +4931,7 @@
1.3110  proof
1.3111    fix x assume "x \<in> interior (f ` s)"
1.3112    then obtain T where as: "open T" "x \<in> T" "T \<subseteq> f ` s" ..
1.3113 -  hence "x \<in> f ` s" by auto
1.3114 +  then have "x \<in> f ` s" by auto
1.3115    then obtain y where y: "y \<in> s" "x = f y" by auto
1.3116    have "open (vimage f T)"
1.3117      using assms(1) `open T` by (rule continuous_open_vimage)
1.3118 @@ -4517,71 +4958,89 @@
1.3119  lemma continuous_constant_on_closure:
1.3120    fixes f :: "_ \<Rightarrow> 'b::t1_space"
1.3121    assumes "continuous_on (closure s) f"
1.3122 -          "\<forall>x \<in> s. f x = a"
1.3123 +    and "\<forall>x \<in> s. f x = a"
1.3124    shows "\<forall>x \<in> (closure s). f x = a"
1.3125      using continuous_closed_preimage_constant[of "closure s" f a]
1.3126 -    assms closure_minimal[of s "{x \<in> closure s. f x = a}"] closure_subset unfolding subset_eq by auto
1.3127 +      assms closure_minimal[of s "{x \<in> closure s. f x = a}"] closure_subset
1.3128 +    unfolding subset_eq
1.3129 +    by auto
1.3130
1.3131  lemma image_closure_subset:
1.3132    assumes "continuous_on (closure s) f"  "closed t"  "(f ` s) \<subseteq> t"
1.3133    shows "f ` (closure s) \<subseteq> t"
1.3134 -proof-
1.3135 -  have "s \<subseteq> {x \<in> closure s. f x \<in> t}" using assms(3) closure_subset by auto
1.3136 +proof -
1.3137 +  have "s \<subseteq> {x \<in> closure s. f x \<in> t}"
1.3138 +    using assms(3) closure_subset by auto
1.3139    moreover have "closed {x \<in> closure s. f x \<in> t}"
1.3140      using continuous_closed_preimage[OF assms(1)] and assms(2) by auto
1.3141    ultimately have "closure s = {x \<in> closure s . f x \<in> t}"
1.3142      using closure_minimal[of s "{x \<in> closure s. f x \<in> t}"] by auto
1.3143 -  thus ?thesis by auto
1.3144 +  then show ?thesis by auto
1.3145  qed
1.3146
1.3147  lemma continuous_on_closure_norm_le:
1.3148    fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
1.3149 -  assumes "continuous_on (closure s) f"  "\<forall>y \<in> s. norm(f y) \<le> b"  "x \<in> (closure s)"
1.3150 +  assumes "continuous_on (closure s) f"
1.3151 +    and "\<forall>y \<in> s. norm(f y) \<le> b"
1.3152 +    and "x \<in> (closure s)"
1.3153    shows "norm(f x) \<le> b"
1.3154 -proof-
1.3155 -  have *:"f ` s \<subseteq> cball 0 b" using assms(2)[unfolded mem_cball_0[THEN sym]] by auto
1.3156 +proof -
1.3157 +  have *: "f ` s \<subseteq> cball 0 b"
1.3158 +    using assms(2)[unfolded mem_cball_0[THEN sym]] by auto
1.3159    show ?thesis
1.3160      using image_closure_subset[OF assms(1) closed_cball[of 0 b] *] assms(3)
1.3161 -    unfolding subset_eq apply(erule_tac x="f x" in ballE) by (auto simp add: dist_norm)
1.3162 +    unfolding subset_eq
1.3163 +    apply (erule_tac x="f x" in ballE)
1.3164 +    apply (auto simp add: dist_norm)
1.3165 +    done
1.3166  qed
1.3167
1.3168  text {* Making a continuous function avoid some value in a neighbourhood. *}
1.3169
1.3170  lemma continuous_within_avoid:
1.3171    fixes f :: "'a::metric_space \<Rightarrow> 'b::t1_space"
1.3172 -  assumes "continuous (at x within s) f" and "f x \<noteq> a"
1.3173 +  assumes "continuous (at x within s) f"
1.3174 +    and "f x \<noteq> a"
1.3175    shows "\<exists>e>0. \<forall>y \<in> s. dist x y < e --> f y \<noteq> a"
1.3176  proof-
1.3177    obtain U where "open U" and "f x \<in> U" and "a \<notin> U"
1.3178      using t1_space [OF `f x \<noteq> a`] by fast
1.3179    have "(f ---> f x) (at x within s)"
1.3180      using assms(1) by (simp add: continuous_within)
1.3181 -  hence "eventually (\<lambda>y. f y \<in> U) (at x within s)"
1.3182 +  then have "eventually (\<lambda>y. f y \<in> U) (at x within s)"
1.3183      using `open U` and `f x \<in> U`
1.3184      unfolding tendsto_def by fast
1.3185 -  hence "eventually (\<lambda>y. f y \<noteq> a) (at x within s)"
1.3186 +  then have "eventually (\<lambda>y. f y \<noteq> a) (at x within s)"
1.3187      using `a \<notin> U` by (fast elim: eventually_mono [rotated])
1.3188 -  thus ?thesis
1.3189 +  then show ?thesis
1.3190      using `f x \<noteq> a` by (auto simp: dist_commute zero_less_dist_iff eventually_at)
1.3191  qed
1.3192
1.3193  lemma continuous_at_avoid:
1.3194    fixes f :: "'a::metric_space \<Rightarrow> 'b::t1_space"
1.3195 -  assumes "continuous (at x) f" and "f x \<noteq> a"
1.3196 +  assumes "continuous (at x) f"
1.3197 +    and "f x \<noteq> a"
1.3198    shows "\<exists>e>0. \<forall>y. dist x y < e \<longrightarrow> f y \<noteq> a"
1.3199    using assms continuous_within_avoid[of x UNIV f a] by simp
1.3200
1.3201  lemma continuous_on_avoid:
1.3202    fixes f :: "'a::metric_space \<Rightarrow> 'b::t1_space"
1.3203 -  assumes "continuous_on s f"  "x \<in> s"  "f x \<noteq> a"
1.3204 +  assumes "continuous_on s f"
1.3205 +    and "x \<in> s"
1.3206 +    and "f x \<noteq> a"
1.3207    shows "\<exists>e>0. \<forall>y \<in> s. dist x y < e \<longrightarrow> f y \<noteq> a"
1.3208 -using assms(1)[unfolded continuous_on_eq_continuous_within, THEN bspec[where x=x], OF assms(2)]  continuous_within_avoid[of x s f a]  assms(3) by auto
1.3209 +  using assms(1)[unfolded continuous_on_eq_continuous_within, THEN bspec[where x=x],
1.3210 +    OF assms(2)] continuous_within_avoid[of x s f a]
1.3211 +  using assms(3)
1.3212 +  by auto
1.3213
1.3214  lemma continuous_on_open_avoid:
1.3215    fixes f :: "'a::metric_space \<Rightarrow> 'b::t1_space"
1.3216    assumes "continuous_on s f"  "open s"  "x \<in> s"  "f x \<noteq> a"
1.3217    shows "\<exists>e>0. \<forall>y. dist x y < e \<longrightarrow> f y \<noteq> a"
1.3218 -using assms(1)[unfolded continuous_on_eq_continuous_at[OF assms(2)], THEN bspec[where x=x], OF assms(3)]  continuous_at_avoid[of x f a]  assms(4) by auto
1.3219 +  using assms(1)[unfolded continuous_on_eq_continuous_at[OF assms(2)], THEN bspec[where x=x], OF assms(3)]
1.3220 +  using continuous_at_avoid[of x f a] assms(4)
1.3221 +  by auto
1.3222
1.3223  text {* Proving a function is constant by proving open-ness of level set. *}
1.3224
1.3225 @@ -4589,22 +5048,28 @@
1.3226    fixes f :: "_ \<Rightarrow> 'b::t1_space"
1.3227    shows "connected s \<Longrightarrow> continuous_on s f \<Longrightarrow>
1.3228          openin (subtopology euclidean s) {x \<in> s. f x = a}
1.3229 -        ==> (\<forall>x \<in> s. f x \<noteq> a) \<or> (\<forall>x \<in> s. f x = a)"
1.3230 -unfolding connected_clopen using continuous_closed_in_preimage_constant by auto
1.3231 +        \<Longrightarrow> (\<forall>x \<in> s. f x \<noteq> a) \<or> (\<forall>x \<in> s. f x = a)"
1.3232 +  unfolding connected_clopen
1.3233 +  using continuous_closed_in_preimage_constant by auto
1.3234
1.3235  lemma continuous_levelset_open_in:
1.3236    fixes f :: "_ \<Rightarrow> 'b::t1_space"
1.3237    shows "connected s \<Longrightarrow> continuous_on s f \<Longrightarrow>
1.3238          openin (subtopology euclidean s) {x \<in> s. f x = a} \<Longrightarrow>
1.3239          (\<exists>x \<in> s. f x = a)  ==> (\<forall>x \<in> s. f x = a)"
1.3240 -using continuous_levelset_open_in_cases[of s f ]
1.3241 -by meson
1.3242 +  using continuous_levelset_open_in_cases[of s f ]
1.3243 +  by meson
1.3244
1.3245  lemma continuous_levelset_open:
1.3246    fixes f :: "_ \<Rightarrow> 'b::t1_space"
1.3247 -  assumes "connected s"  "continuous_on s f"  "open {x \<in> s. f x = a}"  "\<exists>x \<in> s.  f x = a"
1.3248 +  assumes "connected s"
1.3249 +    and "continuous_on s f"
1.3250 +    and "open {x \<in> s. f x = a}"
1.3251 +    and "\<exists>x \<in> s.  f x = a"
1.3252    shows "\<forall>x \<in> s. f x = a"
1.3253 -using continuous_levelset_open_in[OF assms(1,2), of a, unfolded openin_open] using assms (3,4) by fast
1.3254 +  using continuous_levelset_open_in[OF assms(1,2), of a, unfolded openin_open]
1.3255 +  using assms (3,4)
1.3256 +  by fast
1.3257
1.3258  text {* Some arithmetical combinations (more to prove). *}
1.3259
1.3260 @@ -4612,18 +5077,38 @@
1.3261    fixes s :: "'a::real_normed_vector set"
1.3262    assumes "c \<noteq> 0"  "open s"
1.3263    shows "open((\<lambda>x. c *\<^sub>R x) ` s)"
1.3264 -proof-
1.3265 -  { fix x assume "x \<in> s"
1.3266 -    then obtain e where "e>0" and e:"\<forall>x'. dist x' x < e \<longrightarrow> x' \<in> s" using assms(2)[unfolded open_dist, THEN bspec[where x=x]] by auto
1.3267 -    have "e * abs c > 0" using assms(1)[unfolded zero_less_abs_iff[THEN sym]] using mult_pos_pos[OF `e>0`] by auto
1.3268 +proof -
1.3269 +  {
1.3270 +    fix x
1.3271 +    assume "x \<in> s"
1.3272 +    then obtain e where "e>0"
1.3273 +      and e:"\<forall>x'. dist x' x < e \<longrightarrow> x' \<in> s" using assms(2)[unfolded open_dist, THEN bspec[where x=x]]
1.3274 +      by auto
1.3275 +    have "e * abs c > 0"
1.3276 +      using assms(1)[unfolded zero_less_abs_iff[THEN sym]]
1.3277 +      using mult_pos_pos[OF `e>0`]
1.3278 +      by auto
1.3279      moreover
1.3280 -    { fix y assume "dist y (c *\<^sub>R x) < e * \<bar>c\<bar>"
1.3281 -      hence "norm ((1 / c) *\<^sub>R y - x) < e" unfolding dist_norm
1.3282 +    {
1.3283 +      fix y
1.3284 +      assume "dist y (c *\<^sub>R x) < e * \<bar>c\<bar>"
1.3285 +      then have "norm ((1 / c) *\<^sub>R y - x) < e"
1.3286 +        unfolding dist_norm
1.3287          using norm_scaleR[of c "(1 / c) *\<^sub>R y - x", unfolded scaleR_right_diff_distrib, unfolded scaleR_scaleR] assms(1)
1.3288            assms(1)[unfolded zero_less_abs_iff[THEN sym]] by (simp del:zero_less_abs_iff)
1.3289 -      hence "y \<in> op *\<^sub>R c ` s" using rev_image_eqI[of "(1 / c) *\<^sub>R y" s y "op *\<^sub>R c"]  e[THEN spec[where x="(1 / c) *\<^sub>R y"]]  assms(1) unfolding dist_norm scaleR_scaleR by auto  }
1.3290 -    ultimately have "\<exists>e>0. \<forall>x'. dist x' (c *\<^sub>R x) < e \<longrightarrow> x' \<in> op *\<^sub>R c ` s" apply(rule_tac x="e * abs c" in exI) by auto  }
1.3291 -  thus ?thesis unfolding open_dist by auto
1.3292 +      then have "y \<in> op *\<^sub>R c ` s"
1.3293 +        using rev_image_eqI[of "(1 / c) *\<^sub>R y" s y "op *\<^sub>R c"]
1.3294 +        using e[THEN spec[where x="(1 / c) *\<^sub>R y"]]
1.3295 +        using assms(1)
1.3296 +        unfolding dist_norm scaleR_scaleR
1.3297 +        by auto
1.3298 +    }
1.3299 +    ultimately have "\<exists>e>0. \<forall>x'. dist x' (c *\<^sub>R x) < e \<longrightarrow> x' \<in> op *\<^sub>R c ` s"
1.3300 +      apply (rule_tac x="e * abs c" in exI)
1.3301 +      apply auto
1.3302 +      done
1.3303 +  }
1.3304 +  then show ?thesis unfolding open_dist by auto
1.3305  qed
1.3306
1.3307  lemma minus_image_eq_vimage:
1.3308 @@ -4640,83 +5125,124 @@
1.3309  lemma open_translation:
1.3310    fixes s :: "'a::real_normed_vector set"
1.3311    assumes "open s"  shows "open((\<lambda>x. a + x) ` s)"
1.3312 -proof-
1.3313 -  { fix x have "continuous (at x) (\<lambda>x. x - a)"
1.3314 -      by (intro continuous_diff continuous_at_id continuous_const) }
1.3315 -  moreover have "{x. x - a \<in> s} = op + a ` s" by force
1.3316 -  ultimately show ?thesis using continuous_open_preimage_univ[of "\<lambda>x. x - a" s] using assms by auto
1.3317 +proof -
1.3318 +  {
1.3319 +    fix x
1.3320 +    have "continuous (at x) (\<lambda>x. x - a)"
1.3321 +      by (intro continuous_diff continuous_at_id continuous_const)
1.3322 +  }
1.3323 +  moreover have "{x. x - a \<in> s} = op + a ` s"
1.3324 +    by force
1.3325 +  ultimately show ?thesis using continuous_open_preimage_univ[of "\<lambda>x. x - a" s]
1.3326 +    using assms by auto
1.3327  qed
1.3328
1.3329  lemma open_affinity:
1.3330    fixes s :: "'a::real_normed_vector set"
1.3331    assumes "open s"  "c \<noteq> 0"
1.3332    shows "open ((\<lambda>x. a + c *\<^sub>R x) ` s)"
1.3333 -proof-
1.3334 -  have *:"(\<lambda>x. a + c *\<^sub>R x) = (\<lambda>x. a + x) \<circ> (\<lambda>x. c *\<^sub>R x)" unfolding o_def ..
1.3335 -  have "op + a ` op *\<^sub>R c ` s = (op + a \<circ> op *\<^sub>R c) ` s" by auto
1.3336 -  thus ?thesis using assms open_translation[of "op *\<^sub>R c ` s" a] unfolding * by auto
1.3337 +proof -
1.3338 +  have *: "(\<lambda>x. a + c *\<^sub>R x) = (\<lambda>x. a + x) \<circ> (\<lambda>x. c *\<^sub>R x)"
1.3339 +    unfolding o_def ..
1.3340 +  have "op + a ` op *\<^sub>R c ` s = (op + a \<circ> op *\<^sub>R c) ` s"
1.3341 +    by auto
1.3342 +  then show ?thesis
1.3343 +    using assms open_translation[of "op *\<^sub>R c ` s" a]
1.3344 +    unfolding *
1.3345 +    by auto
1.3346  qed
1.3347
1.3348  lemma interior_translation:
1.3349    fixes s :: "'a::real_normed_vector set"
1.3350    shows "interior ((\<lambda>x. a + x) ` s) = (\<lambda>x. a + x) ` (interior s)"
1.3351  proof (rule set_eqI, rule)
1.3352 -  fix x assume "x \<in> interior (op + a ` s)"
1.3353 -  then obtain e where "e>0" and e:"ball x e \<subseteq> op + a ` s" unfolding mem_interior by auto
1.3354 -  hence "ball (x - a) e \<subseteq> s" unfolding subset_eq Ball_def mem_ball dist_norm apply auto apply(erule_tac x="a + xa" in allE) unfolding ab_group_add_class.diff_diff_eq[THEN sym] by auto
1.3355 -  thus "x \<in> op + a ` interior s" unfolding image_iff apply(rule_tac x="x - a" in bexI) unfolding mem_interior using `e > 0` by auto
1.3356 +  fix x
1.3357 +  assume "x \<in> interior (op + a ` s)"
1.3358 +  then obtain e where "e > 0" and e: "ball x e \<subseteq> op + a ` s"
1.3359 +    unfolding mem_interior by auto
1.3360 +  then have "ball (x - a) e \<subseteq> s"
1.3361 +    unfolding subset_eq Ball_def mem_ball dist_norm
1.3362 +    apply auto
1.3363 +    apply (erule_tac x="a + xa" in allE)
1.3364 +    unfolding ab_group_add_class.diff_diff_eq[THEN sym]
1.3365 +    apply auto
1.3366 +    done
1.3367 +  then show "x \<in> op + a ` interior s"
1.3368 +    unfolding image_iff
1.3369 +    apply (rule_tac x="x - a" in bexI)
1.3370 +    unfolding mem_interior
1.3371 +    using `e > 0`
1.3372 +    apply auto
1.3373 +    done
1.3374  next
1.3375 -  fix x assume "x \<in> op + a ` interior s"
1.3376 -  then obtain y e where "e>0" and e:"ball y e \<subseteq> s" and y:"x = a + y" unfolding image_iff Bex_def mem_interior by auto
1.3377 -  { fix z have *:"a + y - z = y + a - z" by auto
1.3378 -    assume "z\<in>ball x e"
1.3379 -    hence "z - a \<in> s" using e[unfolded subset_eq, THEN bspec[where x="z - a"]] unfolding mem_ball dist_norm y group_add_class.diff_diff_eq2 * by auto
1.3380 -    hence "z \<in> op + a ` s" unfolding image_iff by(auto intro!: bexI[where x="z - a"])  }
1.3381 -  hence "ball x e \<subseteq> op + a ` s" unfolding subset_eq by auto
1.3382 -  thus "x \<in> interior (op + a ` s)" unfolding mem_interior using `e>0` by auto
1.3383 +  fix x
1.3384 +  assume "x \<in> op + a ` interior s"
1.3385 +  then obtain y e where "e > 0" and e: "ball y e \<subseteq> s" and y: "x = a + y"
1.3386 +    unfolding image_iff Bex_def mem_interior by auto
1.3387 +  {
1.3388 +    fix z
1.3389 +    have *: "a + y - z = y + a - z" by auto
1.3390 +    assume "z \<in> ball x e"
1.3391 +    then have "z - a \<in> s"
1.3392 +      using e[unfolded subset_eq, THEN bspec[where x="z - a"]]
1.3393 +      unfolding mem_ball dist_norm y group_add_class.diff_diff_eq2 *
1.3394 +      by auto
1.3395 +    then have "z \<in> op + a ` s"
1.3396 +      unfolding image_iff by (auto intro!: bexI[where x="z - a"])
1.3397 +  }
1.3398 +  then have "ball x e \<subseteq> op + a ` s"
1.3399 +    unfolding subset_eq by auto
1.3400 +  then show "x \<in> interior (op + a ` s)"
1.3401 +    unfolding mem_interior using `e > 0` by auto
1.3402  qed
1.3403
1.3404  text {* Topological properties of linear functions. *}
1.3405
1.3406  lemma linear_lim_0:
1.3407 -  assumes "bounded_linear f" shows "(f ---> 0) (at (0))"
1.3408 -proof-
1.3409 +  assumes "bounded_linear f"
1.3410 +  shows "(f ---> 0) (at (0))"
1.3411 +proof -
1.3412    interpret f: bounded_linear f by fact
1.3413    have "(f ---> f 0) (at 0)"
1.3414      using tendsto_ident_at by (rule f.tendsto)
1.3415 -  thus ?thesis unfolding f.zero .
1.3416 +  then show ?thesis unfolding f.zero .
1.3417  qed
1.3418
1.3419  lemma linear_continuous_at:
1.3420 -  assumes "bounded_linear f"  shows "continuous (at a) f"
1.3421 +  assumes "bounded_linear f"
1.3422 +  shows "continuous (at a) f"
1.3423    unfolding continuous_at using assms
1.3424    apply (rule bounded_linear.tendsto)
1.3425    apply (rule tendsto_ident_at)
1.3426    done
1.3427
1.3428  lemma linear_continuous_within:
1.3429 -  shows "bounded_linear f ==> continuous (at x within s) f"
1.3430 +  "bounded_linear f ==> continuous (at x within s) f"
1.3431    using continuous_at_imp_continuous_within[of x f s] using linear_continuous_at[of f] by auto
1.3432
1.3433  lemma linear_continuous_on:
1.3434 -  shows "bounded_linear f ==> continuous_on s f"
1.3435 +  "bounded_linear f ==> continuous_on s f"
1.3436    using continuous_at_imp_continuous_on[of s f] using linear_continuous_at[of f] by auto
1.3437
1.3438  text {* Also bilinear functions, in composition form. *}
1.3439
1.3440  lemma bilinear_continuous_at_compose:
1.3441 -  shows "continuous (at x) f \<Longrightarrow> continuous (at x) g \<Longrightarrow> bounded_bilinear h
1.3442 -        ==> continuous (at x) (\<lambda>x. h (f x) (g x))"
1.3443 -  unfolding continuous_at using Lim_bilinear[of f "f x" "(at x)" g "g x" h] by auto
1.3444 +  "continuous (at x) f \<Longrightarrow> continuous (at x) g \<Longrightarrow> bounded_bilinear h \<Longrightarrow>
1.3445 +    continuous (at x) (\<lambda>x. h (f x) (g x))"
1.3446 +  unfolding continuous_at
1.3447 +  using Lim_bilinear[of f "f x" "(at x)" g "g x" h]
1.3448 +  by auto
1.3449
1.3450  lemma bilinear_continuous_within_compose:
1.3451 -  shows "continuous (at x within s) f \<Longrightarrow> continuous (at x within s) g \<Longrightarrow> bounded_bilinear h
1.3452 -        ==> continuous (at x within s) (\<lambda>x. h (f x) (g x))"
1.3453 -  unfolding continuous_within using Lim_bilinear[of f "f x"] by auto
1.3454 +  "continuous (at x within s) f \<Longrightarrow> continuous (at x within s) g \<Longrightarrow> bounded_bilinear h \<Longrightarrow>
1.3455 +    continuous (at x within s) (\<lambda>x. h (f x) (g x))"
1.3456 +  unfolding continuous_within
1.3457 +  using Lim_bilinear[of f "f x"]
1.3458 +  by auto
1.3459
1.3460  lemma bilinear_continuous_on_compose:
1.3461 -  shows "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> bounded_bilinear h
1.3462 -             ==> continuous_on s (\<lambda>x. h (f x) (g x))"
1.3463 +  "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> bounded_bilinear h \<Longrightarrow>
1.3464 +    continuous_on s (\<lambda>x. h (f x) (g x))"
1.3465    unfolding continuous_on_def
1.3466    by (fast elim: bounded_bilinear.tendsto)
1.3467
1.3468 @@ -4729,13 +5255,13 @@
1.3469  proof safe
1.3470    fix C
1.3471    assume "compact S" and "\<forall>c\<in>C. openin (subtopology euclidean S) c" and "S \<subseteq> \<Union>C"
1.3472 -  hence "\<forall>c\<in>{T. open T \<and> S \<inter> T \<in> C}. open c" and "S \<subseteq> \<Union>{T. open T \<and> S \<inter> T \<in> C}"
1.3473 +  then have "\<forall>c\<in>{T. open T \<and> S \<inter> T \<in> C}. open c" and "S \<subseteq> \<Union>{T. open T \<and> S \<inter> T \<in> C}"
1.3474      unfolding openin_open by force+
1.3475    with `compact S` obtain D where "D \<subseteq> {T. open T \<and> S \<inter> T \<in> C}" and "finite D" and "S \<subseteq> \<Union>D"
1.3476      by (rule compactE)
1.3477 -  hence "image (\<lambda>T. S \<inter> T) D \<subseteq> C \<and> finite (image (\<lambda>T. S \<inter> T) D) \<and> S \<subseteq> \<Union>(image (\<lambda>T. S \<inter> T) D)"
1.3478 +  then have "image (\<lambda>T. S \<inter> T) D \<subseteq> C \<and> finite (image (\<lambda>T. S \<inter> T) D) \<and> S \<subseteq> \<Union>(image (\<lambda>T. S \<inter> T) D)"
1.3479      by auto
1.3480 -  thus "\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D" ..
1.3481 +  then show "\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D" ..
1.3482  next
1.3483    assume 1: "\<forall>C. (\<forall>c\<in>C. openin (subtopology euclidean S) c) \<and> S \<subseteq> \<Union>C \<longrightarrow>
1.3484          (\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D)"
1.3485 @@ -4744,7 +5270,7 @@
1.3486      fix C
1.3487      let ?C = "image (\<lambda>T. S \<inter> T) C"
1.3488      assume "\<forall>t\<in>C. open t" and "S \<subseteq> \<Union>C"
1.3489 -    hence "(\<forall>c\<in>?C. openin (subtopology euclidean S) c) \<and> S \<subseteq> \<Union>?C"
1.3490 +    then have "(\<forall>c\<in>?C. openin (subtopology euclidean S) c) \<and> S \<subseteq> \<Union>?C"
1.3491        unfolding openin_open by auto
1.3492      with 1 obtain D where "D \<subseteq> ?C" and "finite D" and "S \<subseteq> \<Union>D"
1.3493        by metis
1.3494 @@ -4762,37 +5288,43 @@
1.3495          apply (erule rev_bexI, fast)
1.3496          done
1.3497      qed
1.3498 -    thus "\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D" ..
1.3499 +    then show "\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D" ..
1.3500    qed
1.3501  qed
1.3502
1.3503  lemma connected_continuous_image:
1.3504    assumes "continuous_on s f"  "connected s"
1.3505    shows "connected(f ` s)"
1.3506 -proof-
1.3507 -  { fix T assume as: "T \<noteq> {}"  "T \<noteq> f ` s"  "openin (subtopology euclidean (f ` s)) T"  "closedin (subtopology euclidean (f ` s)) T"
1.3508 +proof -
1.3509 +  {
1.3510 +    fix T
1.3511 +    assume as: "T \<noteq> {}"  "T \<noteq> f ` s"  "openin (subtopology euclidean (f ` s)) T"  "closedin (subtopology euclidean (f ` s)) T"
1.3512      have "{x \<in> s. f x \<in> T} = {} \<or> {x \<in> s. f x \<in> T} = s"
1.3513        using assms(1)[unfolded continuous_on_open, THEN spec[where x=T]]
1.3514        using assms(1)[unfolded continuous_on_closed, THEN spec[where x=T]]
1.3515        using assms(2)[unfolded connected_clopen, THEN spec[where x="{x \<in> s. f x \<in> T}"]] as(3,4) by auto
1.3516 -    hence False using as(1,2)
1.3517 -      using as(4)[unfolded closedin_def topspace_euclidean_subtopology] by auto }
1.3518 -  thus ?thesis unfolding connected_clopen by auto
1.3519 +    then have False using as(1,2)
1.3520 +      using as(4)[unfolded closedin_def topspace_euclidean_subtopology] by auto
1.3521 +  }
1.3522 +  then show ?thesis
1.3523 +    unfolding connected_clopen by auto
1.3524  qed
1.3525
1.3526  text {* Continuity implies uniform continuity on a compact domain. *}
1.3527 -
1.3528 +
1.3529  lemma compact_uniformly_continuous:
1.3530    assumes f: "continuous_on s f" and s: "compact s"
1.3531    shows "uniformly_continuous_on s f"
1.3532    unfolding uniformly_continuous_on_def
1.3533  proof (cases, safe)
1.3534 -  fix e :: real assume "0 < e" "s \<noteq> {}"
1.3535 +  fix e :: real
1.3536 +  assume "0 < e" "s \<noteq> {}"
1.3537    def [simp]: R \<equiv> "{(y, d). y \<in> s \<and> 0 < d \<and> ball y d \<inter> s \<subseteq> {x \<in> s. f x \<in> ball (f y) (e/2) } }"
1.3538    let ?b = "(\<lambda>(y, d). ball y (d/2))"
1.3539    have "(\<forall>r\<in>R. open (?b r))" "s \<subseteq> (\<Union>r\<in>R. ?b r)"
1.3540    proof safe
1.3541 -    fix y assume "y \<in> s"
1.3542 +    fix y
1.3543 +    assume "y \<in> s"
1.3544      from continuous_open_in_preimage[OF f open_ball]
1.3545      obtain T where "open T" and T: "{x \<in> s. f x \<in> ball (f y) (e/2)} = T \<inter> s"
1.3546        unfolding openin_subtopology open_openin by metis
1.3547 @@ -4807,7 +5339,8 @@
1.3548      by (subst Min_gr_iff) auto
1.3549    show "\<exists>d>0. \<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f x') (f x) < e"
1.3550    proof (rule, safe)
1.3551 -    fix x x' assume in_s: "x' \<in> s" "x \<in> s"
1.3552 +    fix x x'
1.3553 +    assume in_s: "x' \<in> s" "x \<in> s"
1.3554      with D obtain y d where x: "x \<in> ball y (d/2)" "(y, d) \<in> D"
1.3555        by blast
1.3556      moreover assume "dist x x' < Min (snd`D) / 2"
1.3557 @@ -4823,11 +5356,13 @@
1.3558  lemma continuous_uniform_limit:
1.3559    fixes f :: "'a \<Rightarrow> 'b::metric_space \<Rightarrow> 'c::metric_space"
1.3560    assumes "\<not> trivial_limit F"
1.3561 -  assumes "eventually (\<lambda>n. continuous_on s (f n)) F"
1.3562 -  assumes "\<forall>e>0. eventually (\<lambda>n. \<forall>x\<in>s. dist (f n x) (g x) < e) F"
1.3563 +    and "eventually (\<lambda>n. continuous_on s (f n)) F"
1.3564 +    and "\<forall>e>0. eventually (\<lambda>n. \<forall>x\<in>s. dist (f n x) (g x) < e) F"
1.3565    shows "continuous_on s g"
1.3566 -proof-
1.3567 -  { fix x and e::real assume "x\<in>s" "e>0"
1.3568 +proof -
1.3569 +  {
1.3570 +    fix x and e :: real
1.3571 +    assume "x\<in>s" "e>0"
1.3572      have "eventually (\<lambda>n. \<forall>x\<in>s. dist (f n x) (g x) < e / 3) F"
1.3573        using `e>0` assms(3)[THEN spec[where x="e/3"]] by auto
1.3574      from eventually_happens [OF eventually_conj [OF this assms(2)]]
1.3575 @@ -4836,29 +5371,33 @@
1.3576      have "e / 3 > 0" using `e>0` by auto
1.3577      then obtain d where "d>0" and d:"\<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f n x') (f n x) < e / 3"
1.3578        using n(2)[unfolded continuous_on_iff, THEN bspec[where x=x], OF `x\<in>s`, THEN spec[where x="e/3"]] by blast
1.3579 -    { fix y assume "y \<in> s" and "dist y x < d"
1.3580 -      hence "dist (f n y) (f n x) < e / 3"
1.3581 +    {
1.3582 +      fix y
1.3583 +      assume "y \<in> s" and "dist y x < d"
1.3584 +      then have "dist (f n y) (f n x) < e / 3"
1.3585          by (rule d [rule_format])
1.3586 -      hence "dist (f n y) (g x) < 2 * e / 3"
1.3587 +      then have "dist (f n y) (g x) < 2 * e / 3"
1.3588          using dist_triangle [of "f n y" "g x" "f n x"]
1.3589          using n(1)[THEN bspec[where x=x], OF `x\<in>s`]
1.3590          by auto
1.3591 -      hence "dist (g y) (g x) < e"
1.3592 +      then have "dist (g y) (g x) < e"
1.3593          using n(1)[THEN bspec[where x=y], OF `y\<in>s`]
1.3594          using dist_triangle3 [of "g y" "g x" "f n y"]
1.3595 -        by auto }
1.3596 -    hence "\<exists>d>0. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (g x') (g x) < e"
1.3597 -      using `d>0` by auto }
1.3598 -  thus ?thesis unfolding continuous_on_iff by auto
1.3599 +        by auto
1.3600 +    }
1.3601 +    then have "\<exists>d>0. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (g x') (g x) < e"
1.3602 +      using `d>0` by auto
1.3603 +  }
1.3604 +  then show ?thesis
1.3605 +    unfolding continuous_on_iff by auto
1.3606  qed
1.3607
1.3608
1.3609  subsection {* Topological stuff lifted from and dropped to R *}
1.3610
1.3611  lemma open_real:
1.3612 -  fixes s :: "real set" shows
1.3613 - "open s \<longleftrightarrow>
1.3614 -        (\<forall>x \<in> s. \<exists>e>0. \<forall>x'. abs(x' - x) < e --> x' \<in> s)" (is "?lhs = ?rhs")
1.3615 +  fixes s :: "real set"
1.3616 +  shows "open s \<longleftrightarrow> (\<forall>x \<in> s. \<exists>e>0. \<forall>x'. abs(x' - x) < e --> x' \<in> s)"
1.3617    unfolding open_dist dist_norm by simp
1.3618
1.3619  lemma islimpt_approachable_real:
1.3620 @@ -4868,23 +5407,31 @@
1.3621
1.3622  lemma closed_real:
1.3623    fixes s :: "real set"
1.3624 -  shows "closed s \<longleftrightarrow>
1.3625 -        (\<forall>x. (\<forall>e>0.  \<exists>x' \<in> s. x' \<noteq> x \<and> abs(x' - x) < e)
1.3626 -            --> x \<in> s)"
1.3627 +  shows "closed s \<longleftrightarrow> (\<forall>x. (\<forall>e>0.  \<exists>x' \<in> s. x' \<noteq> x \<and> abs(x' - x) < e) \<longrightarrow> x \<in> s)"
1.3628    unfolding closed_limpt islimpt_approachable dist_norm by simp
1.3629
1.3630  lemma continuous_at_real_range:
1.3631    fixes f :: "'a::real_normed_vector \<Rightarrow> real"
1.3632 -  shows "continuous (at x) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0.
1.3633 -        \<forall>x'. norm(x' - x) < d --> abs(f x' - f x) < e)"
1.3634 -  unfolding continuous_at unfolding Lim_at
1.3635 -  unfolding dist_nz[THEN sym] unfolding dist_norm apply auto
1.3636 -  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
1.3637 -  apply(erule_tac x=e in allE) by auto
1.3638 +  shows "continuous (at x) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0. \<forall>x'. norm(x' - x) < d --> abs(f x' - f x) < e)"
1.3639 +  unfolding continuous_at
1.3640 +  unfolding Lim_at
1.3641 +  unfolding dist_nz[THEN sym]
1.3642 +  unfolding dist_norm
1.3643 +  apply auto
1.3644 +  apply (erule_tac x=e in allE)
1.3645 +  apply auto
1.3646 +  apply (rule_tac x=d in exI)
1.3647 +  apply auto
1.3648 +  apply (erule_tac x=x' in allE)
1.3649 +  apply auto
1.3650 +  apply (erule_tac x=e in allE)
1.3651 +  apply auto
1.3652 +  done
1.3653
1.3654  lemma continuous_on_real_range:
1.3655    fixes f :: "'a::real_normed_vector \<Rightarrow> real"
1.3656 -  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))"
1.3657 +  shows "continuous_on s f \<longleftrightarrow>
1.3658 +    (\<forall>x \<in> s. \<forall>e>0. \<exists>d>0. (\<forall>x' \<in> s. norm(x' - x) < d \<longrightarrow> abs(f x' - f x) < e))"
1.3659    unfolding continuous_on_iff dist_norm by simp
1.3660
1.3661  text {* Hence some handy theorems on distance, diameter etc. of/from a set. *}
1.3662 @@ -4893,11 +5440,13 @@
1.3663    assumes "compact s" "s \<noteq> {}"
1.3664    shows "\<exists>x\<in>s. \<forall>y\<in>s. dist a y \<le> dist a x"
1.3665  proof (rule continuous_attains_sup [OF assms])
1.3666 -  { fix x assume "x\<in>s"
1.3667 +  {
1.3668 +    fix x
1.3669 +    assume "x\<in>s"
1.3670      have "(dist a ---> dist a x) (at x within s)"
1.3671        by (intro tendsto_dist tendsto_const tendsto_ident_at)
1.3672    }
1.3673 -  thus "continuous_on s (dist a)"
1.3674 +  then show "continuous_on s (dist a)"
1.3675      unfolding continuous_on ..
1.3676  qed
1.3677
1.3678 @@ -4907,63 +5456,68 @@
1.3679    fixes a :: "'a::heine_borel"
1.3680    assumes "closed s"  "s \<noteq> {}"
1.3681    shows "\<exists>x\<in>s. \<forall>y\<in>s. dist a x \<le> dist a y"
1.3682 -proof-
1.3683 +proof -
1.3684    from assms(2) obtain b where "b \<in> s" by auto
1.3685    let ?B = "s \<inter> cball a (dist b a)"
1.3686 -  have "?B \<noteq> {}" using `b \<in> s` by (auto simp add: dist_commute)
1.3687 +  have "?B \<noteq> {}" using `b \<in> s`
1.3688 +    by (auto simp add: dist_commute)
1.3689    moreover have "continuous_on ?B (dist a)"
1.3690      by (auto intro!: continuous_at_imp_continuous_on continuous_dist continuous_at_id continuous_const)
1.3691    moreover have "compact ?B"
1.3692      by (intro closed_inter_compact `closed s` compact_cball)
1.3693    ultimately obtain x where "x \<in> ?B" "\<forall>y\<in>?B. dist a x \<le> dist a y"
1.3694      by (metis continuous_attains_inf)
1.3695 -  thus ?thesis by fastforce
1.3696 +  then show ?thesis by fastforce
1.3697  qed
1.3698
1.3699
1.3700  subsection {* Pasted sets *}
1.3701
1.3702  lemma bounded_Times:
1.3703 -  assumes "bounded s" "bounded t" shows "bounded (s \<times> t)"
1.3704 -proof-
1.3705 +  assumes "bounded s" "bounded t"
1.3706 +  shows "bounded (s \<times> t)"
1.3707 +proof -
1.3708    obtain x y a b where "\<forall>z\<in>s. dist x z \<le> a" "\<forall>z\<in>t. dist y z \<le> b"
1.3709      using assms [unfolded bounded_def] by auto
1.3710    then have "\<forall>z\<in>s \<times> t. dist (x, y) z \<le> sqrt (a\<^sup>2 + b\<^sup>2)"
1.3711      by (auto simp add: dist_Pair_Pair real_sqrt_le_mono add_mono power_mono)
1.3712 -  thus ?thesis unfolding bounded_any_center [where a="(x, y)"] by auto
1.3713 +  then show ?thesis unfolding bounded_any_center [where a="(x, y)"] by auto
1.3714  qed
1.3715
1.3716  lemma mem_Times_iff: "x \<in> A \<times> B \<longleftrightarrow> fst x \<in> A \<and> snd x \<in> B"
1.3717 -by (induct x) simp
1.3718 +  by (induct x) simp
1.3719
1.3720  lemma seq_compact_Times: "seq_compact s \<Longrightarrow> seq_compact t \<Longrightarrow> seq_compact (s \<times> t)"
1.3721 -unfolding seq_compact_def
1.3722 -apply clarify
1.3723 -apply (drule_tac x="fst \<circ> f" in spec)
1.3724 -apply (drule mp, simp add: mem_Times_iff)
1.3725 -apply (clarify, rename_tac l1 r1)
1.3726 -apply (drule_tac x="snd \<circ> f \<circ> r1" in spec)
1.3727 -apply (drule mp, simp add: mem_Times_iff)
1.3728 -apply (clarify, rename_tac l2 r2)
1.3729 -apply (rule_tac x="(l1, l2)" in rev_bexI, simp)
1.3730 -apply (rule_tac x="r1 \<circ> r2" in exI)
1.3731 -apply (rule conjI, simp add: subseq_def)
1.3732 -apply (drule_tac f=r2 in LIMSEQ_subseq_LIMSEQ, assumption)
1.3733 -apply (drule (1) tendsto_Pair) back
1.3734 -apply (simp add: o_def)
1.3735 -done
1.3736 -
1.3737 -lemma compact_Times:
1.3738 +  unfolding seq_compact_def
1.3739 +  apply clarify
1.3740 +  apply (drule_tac x="fst \<circ> f" in spec)
1.3741 +  apply (drule mp, simp add: mem_Times_iff)
1.3742 +  apply (clarify, rename_tac l1 r1)
1.3743 +  apply (drule_tac x="snd \<circ> f \<circ> r1" in spec)
1.3744 +  apply (drule mp, simp add: mem_Times_iff)
1.3745 +  apply (clarify, rename_tac l2 r2)
1.3746 +  apply (rule_tac x="(l1, l2)" in rev_bexI, simp)
1.3747 +  apply (rule_tac x="r1 \<circ> r2" in exI)
1.3748 +  apply (rule conjI, simp add: subseq_def)
1.3749 +  apply (drule_tac f=r2 in LIMSEQ_subseq_LIMSEQ, assumption)
1.3750 +  apply (drule (1) tendsto_Pair) back
1.3751 +  apply (simp add: o_def)
1.3752 +  done
1.3753 +
1.3754 +lemma compact_Times:
1.3755    assumes "compact s" "compact t"
1.3756    shows "compact (s \<times> t)"
1.3757  proof (rule compactI)
1.3758 -  fix C assume C: "\<forall>t\<in>C. open t" "s \<times> t \<subseteq> \<Union>C"
1.3759 +  fix C
1.3760 +  assume C: "\<forall>t\<in>C. open t" "s \<times> t \<subseteq> \<Union>C"
1.3761    have "\<forall>x\<in>s. \<exists>a. open a \<and> x \<in> a \<and> (\<exists>d\<subseteq>C. finite d \<and> a \<times> t \<subseteq> \<Union>d)"
1.3762    proof
1.3763 -    fix x assume "x \<in> s"
1.3764 +    fix x
1.3765 +    assume "x \<in> s"
1.3766      have "\<forall>y\<in>t. \<exists>a b c. c \<in> C \<and> open a \<and> open b \<and> x \<in> a \<and> y \<in> b \<and> a \<times> b \<subseteq> c" (is "\<forall>y\<in>t. ?P y")
1.3767 -    proof
1.3768 -      fix y assume "y \<in> t"
1.3769 +    proof
1.3770 +      fix y
1.3771 +      assume "y \<in> t"
1.3772        with `x \<in> s` C obtain c where "c \<in> C" "(x, y) \<in> c" "open c" by auto
1.3773        then show "?P y" by (auto elim!: open_prod_elim)
1.3774      qed
1.3775 @@ -4981,12 +5535,18 @@
1.3776    then obtain a d where a: "\<forall>x\<in>s. open (a x)" "s \<subseteq> (\<Union>x\<in>s. a x)"
1.3777      and d: "\<And>x. x \<in> s \<Longrightarrow> d x \<subseteq> C \<and> finite (d x) \<and> a x \<times> t \<subseteq> \<Union>d x"
1.3778      unfolding subset_eq UN_iff by metis
1.3779 -  moreover from compactE_image[OF `compact s` a] obtain e where e: "e \<subseteq> s" "finite e"
1.3780 -    and s: "s \<subseteq> (\<Union>x\<in>e. a x)" by auto
1.3781 +  moreover
1.3782 +  from compactE_image[OF `compact s` a]
1.3783 +  obtain e where e: "e \<subseteq> s" "finite e" and s: "s \<subseteq> (\<Union>x\<in>e. a x)"
1.3784 +    by auto
1.3785    moreover
1.3786 -  { from s have "s \<times> t \<subseteq> (\<Union>x\<in>e. a x \<times> t)" by auto
1.3787 -    also have "\<dots> \<subseteq> (\<Union>x\<in>e. \<Union>d x)" using d `e \<subseteq> s` by (intro UN_mono) auto
1.3788 -    finally have "s \<times> t \<subseteq> (\<Union>x\<in>e. \<Union>d x)" . }
1.3789 +  {
1.3790 +    from s have "s \<times> t \<subseteq> (\<Union>x\<in>e. a x \<times> t)"
1.3791 +      by auto
1.3792 +    also have "\<dots> \<subseteq> (\<Union>x\<in>e. \<Union>d x)"
1.3793 +      using d `e \<subseteq> s` by (intro UN_mono) auto
1.3794 +    finally have "s \<times> t \<subseteq> (\<Union>x\<in>e. \<Union>d x)" .
1.3795 +  }
1.3796    ultimately show "\<exists>C'\<subseteq>C. finite C' \<and> s \<times> t \<subseteq> \<Union>C'"
1.3797      by (intro exI[of _ "(\<Union>x\<in>e. d x)"]) (auto simp add: subset_eq)
1.3798  qed
1.3799 @@ -4995,28 +5555,38 @@
1.3800
1.3801  lemma compact_scaling:
1.3802    fixes s :: "'a::real_normed_vector set"
1.3803 -  assumes "compact s"  shows "compact ((\<lambda>x. c *\<^sub>R x) ` s)"
1.3804 -proof-
1.3805 +  assumes "compact s"
1.3806 +  shows "compact ((\<lambda>x. c *\<^sub>R x) ` s)"
1.3807 +proof -
1.3808    let ?f = "\<lambda>x. scaleR c x"
1.3809 -  have *:"bounded_linear ?f" by (rule bounded_linear_scaleR_right)
1.3810 -  show ?thesis using compact_continuous_image[of s ?f] continuous_at_imp_continuous_on[of s ?f]
1.3811 -    using linear_continuous_at[OF *] assms by auto
1.3812 +  have *: "bounded_linear ?f" by (rule bounded_linear_scaleR_right)
1.3813 +  show ?thesis
1.3814 +    using compact_continuous_image[of s ?f] continuous_at_imp_continuous_on[of s ?f]
1.3815 +    using linear_continuous_at[OF *] assms
1.3816 +    by auto
1.3817  qed
1.3818
1.3819  lemma compact_negations:
1.3820    fixes s :: "'a::real_normed_vector set"
1.3821 -  assumes "compact s"  shows "compact ((\<lambda>x. -x) ` s)"
1.3822 +  assumes "compact s"
1.3823 +  shows "compact ((\<lambda>x. -x) ` s)"
1.3824    using compact_scaling [OF assms, of "- 1"] by auto
1.3825
1.3826  lemma compact_sums:
1.3827    fixes s t :: "'a::real_normed_vector set"
1.3828 -  assumes "compact s"  "compact t"  shows "compact {x + y | x y. x \<in> s \<and> y \<in> t}"
1.3829 -proof-
1.3830 -  have *:"{x + y | x y. x \<in> s \<and> y \<in> t} = (\<lambda>z. fst z + snd z) ` (s \<times> t)"
1.3831 -    apply auto unfolding image_iff apply(rule_tac x="(xa, y)" in bexI) by auto
1.3832 +  assumes "compact s" and "compact t"
1.3833 +  shows "compact {x + y | x y. x \<in> s \<and> y \<in> t}"
1.3834 +proof -
1.3835 +  have *: "{x + y | x y. x \<in> s \<and> y \<in> t} = (\<lambda>z. fst z + snd z) ` (s \<times> t)"
1.3836 +    apply auto
1.3837 +    unfolding image_iff
1.3838 +    apply (rule_tac x="(xa, y)" in bexI)
1.3839 +    apply auto
1.3840 +    done
1.3841    have "continuous_on (s \<times> t) (\<lambda>z. fst z + snd z)"
1.3842      unfolding continuous_on by (rule ballI) (intro tendsto_intros)
1.3843 -  thus ?thesis unfolding * using compact_continuous_image compact_Times [OF assms] by auto
1.3844 +  then show ?thesis
1.3845 +    unfolding * using compact_continuous_image compact_Times [OF assms] by auto
1.3846  qed
1.3847
1.3848  lemma compact_differences:
1.3849 @@ -5024,24 +5594,36 @@
1.3850    assumes "compact s" "compact t"  shows "compact {x - y | x y. x \<in> s \<and> y \<in> t}"
1.3851  proof-
1.3852    have "{x - y | x y. x\<in>s \<and> y \<in> t} =  {x + y | x y. x \<in> s \<and> y \<in> (uminus ` t)}"
1.3853 -    apply auto apply(rule_tac x= xa in exI) apply auto apply(rule_tac x=xa in exI) by auto
1.3854 -  thus ?thesis using compact_sums[OF assms(1) compact_negations[OF assms(2)]] by auto
1.3855 +    apply auto
1.3856 +    apply (rule_tac x= xa in exI)
1.3857 +    apply auto
1.3858 +    apply (rule_tac x=xa in exI)
1.3859 +    apply auto
1.3860 +    done
1.3861 +  then show ?thesis
1.3862 +    using compact_sums[OF assms(1) compact_negations[OF assms(2)]] by auto
1.3863  qed
1.3864
1.3865  lemma compact_translation:
1.3866    fixes s :: "'a::real_normed_vector set"
1.3867 -  assumes "compact s"  shows "compact ((\<lambda>x. a + x) ` s)"
1.3868 -proof-
1.3869 -  have "{x + y |x y. x \<in> s \<and> y \<in> {a}} = (\<lambda>x. a + x) ` s" by auto
1.3870 -  thus ?thesis using compact_sums[OF assms compact_sing[of a]] by auto
1.3871 +  assumes "compact s"
1.3872 +  shows "compact ((\<lambda>x. a + x) ` s)"
1.3873 +proof -
1.3874 +  have "{x + y |x y. x \<in> s \<and> y \<in> {a}} = (\<lambda>x. a + x) ` s"
1.3875 +    by auto
1.3876 +  then show ?thesis
1.3877 +    using compact_sums[OF assms compact_sing[of a]] by auto
1.3878  qed
1.3879
1.3880  lemma compact_affinity:
1.3881    fixes s :: "'a::real_normed_vector set"
1.3882 -  assumes "compact s"  shows "compact ((\<lambda>x. a + c *\<^sub>R x) ` s)"
1.3883 -proof-
1.3884 -  have "op + a ` op *\<^sub>R c ` s = (\<lambda>x. a + c *\<^sub>R x) ` s" by auto
1.3885 -  thus ?thesis using compact_translation[OF compact_scaling[OF assms], of a c] by auto
1.3886 +  assumes "compact s"
1.3887 +  shows "compact ((\<lambda>x. a + c *\<^sub>R x) ` s)"
1.3888 +proof -
1.3889 +  have "op + a ` op *\<^sub>R c ` s = (\<lambda>x. a + c *\<^sub>R x) ` s"
1.3890 +    by auto
1.3891 +  then show ?thesis
1.3892 +    using compact_translation[OF compact_scaling[OF assms], of a c] by auto
1.3893  qed
1.3894
1.3895  text {* Hence we get the following. *}
1.3896 @@ -5050,9 +5632,11 @@
1.3897    fixes s :: "'a::metric_space set"
1.3898    assumes "compact s"  "s \<noteq> {}"
1.3899    shows "\<exists>x\<in>s. \<exists>y\<in>s. \<forall>u\<in>s. \<forall>v\<in>s. dist u v \<le> dist x y"
1.3900 -proof-
1.3901 -  have "compact (s \<times> s)" using `compact s` by (intro compact_Times)
1.3902 -  moreover have "s \<times> s \<noteq> {}" using `s \<noteq> {}` by auto
1.3903 +proof -
1.3904 +  have "compact (s \<times> s)"
1.3905 +    using `compact s` by (intro compact_Times)
1.3906 +  moreover have "s \<times> s \<noteq> {}"
1.3907 +    using `s \<noteq> {}` by auto
1.3908    moreover have "continuous_on (s \<times> s) (\<lambda>x. dist (fst x) (snd x))"
1.3909      by (intro continuous_at_imp_continuous_on ballI continuous_intros)
1.3910    ultimately show ?thesis
1.3911 @@ -5073,7 +5657,8 @@
1.3912      unfolding bounded_def by auto
1.3913    have "dist x y \<le> Sup ?D"
1.3914    proof (rule cSup_upper, safe)
1.3915 -    fix a b assume "a \<in> s" "b \<in> s"
1.3916 +    fix a b
1.3917 +    assume "a \<in> s" "b \<in> s"
1.3918      with z[of a] z[of b] dist_triangle[of a b z]
1.3919      show "dist a b \<le> 2 * d"
1.3920        by (simp add: dist_commute)
1.3921 @@ -5084,7 +5669,8 @@
1.3922
1.3923  lemma diameter_lower_bounded:
1.3924    fixes s :: "'a :: metric_space set"
1.3925 -  assumes s: "bounded s" and d: "0 < d" "d < diameter s"
1.3926 +  assumes s: "bounded s"
1.3927 +    and d: "0 < d" "d < diameter s"
1.3928    shows "\<exists>x\<in>s. \<exists>y\<in>s. d < dist x y"
1.3929  proof (rule ccontr)
1.3930    let ?D = "{dist x y |x y. x \<in> s \<and> y \<in> s}"
1.3931 @@ -5110,12 +5696,17 @@
1.3932    assumes "compact s"  "s \<noteq> {}"
1.3933    shows "\<exists>x\<in>s. \<exists>y\<in>s. dist x y = diameter s"
1.3934  proof -
1.3935 -  have b:"bounded s" using assms(1) by (rule compact_imp_bounded)
1.3936 -  then obtain x y where xys:"x\<in>s" "y\<in>s" and xy:"\<forall>u\<in>s. \<forall>v\<in>s. dist u v \<le> dist x y"
1.3937 +  have b: "bounded s" using assms(1)
1.3938 +    by (rule compact_imp_bounded)
1.3939 +  then obtain x y where xys: "x\<in>s" "y\<in>s" and xy: "\<forall>u\<in>s. \<forall>v\<in>s. dist u v \<le> dist x y"
1.3940      using compact_sup_maxdistance[OF assms] by auto
1.3941 -  hence "diameter s \<le> dist x y"
1.3942 -    unfolding diameter_def by clarsimp (rule cSup_least, fast+)
1.3943 -  thus ?thesis
1.3944 +  then have "diameter s \<le> dist x y"
1.3945 +    unfolding diameter_def
1.3946 +    apply clarsimp
1.3947 +    apply (rule cSup_least)
1.3948 +    apply fast+
1.3949 +    done
1.3950 +  then show ?thesis
1.3951      by (metis b diameter_bounded_bound order_antisym xys)
1.3952  qed
1.3953
1.3954 @@ -5123,109 +5714,175 @@
1.3955
1.3956  lemma closed_scaling:
1.3957    fixes s :: "'a::real_normed_vector set"
1.3958 -  assumes "closed s" shows "closed ((\<lambda>x. c *\<^sub>R x) ` s)"
1.3959 -proof(cases "s={}")
1.3960 -  case True thus ?thesis by auto
1.3961 +  assumes "closed s"
1.3962 +  shows "closed ((\<lambda>x. c *\<^sub>R x) ` s)"
1.3963 +proof (cases "s = {}")
1.3964 +  case True
1.3965 +  then show ?thesis by auto
1.3966  next
1.3967    case False
1.3968    show ?thesis
1.3969 -  proof(cases "c=0")
1.3970 -    have *:"(\<lambda>x. 0) ` s = {0}" using `s\<noteq>{}` by auto
1.3971 -    case True thus ?thesis apply auto unfolding * by auto
1.3972 +  proof (cases "c = 0")
1.3973 +    have *: "(\<lambda>x. 0) ` s = {0}" using `s\<noteq>{}` by auto
1.3974 +    case True
1.3975 +    then show ?thesis
1.3976 +      apply auto
1.3977 +      unfolding *
1.3978 +      apply auto
1.3979 +      done
1.3980    next
1.3981      case False
1.3982 -    { fix x l assume as:"\<forall>n::nat. x n \<in> scaleR c ` s"  "(x ---> l) sequentially"
1.3983 -      { fix n::nat have "scaleR (1 / c) (x n) \<in> s"
1.3984 +    {
1.3985 +      fix x l
1.3986 +      assume as: "\<forall>n::nat. x n \<in> scaleR c ` s"  "(x ---> l) sequentially"
1.3987 +      {
1.3988 +        fix n :: nat
1.3989 +        have "scaleR (1 / c) (x n) \<in> s"
1.3990            using as(1)[THEN spec[where x=n]]
1.3991 -          using `c\<noteq>0` by auto
1.3992 +          using `c\<noteq>0`
1.3993 +          by auto
1.3994        }
1.3995        moreover
1.3996 -      { fix e::real assume "e>0"
1.3997 -        hence "0 < e *\<bar>c\<bar>"  using `c\<noteq>0` mult_pos_pos[of e "abs c"] by auto
1.3998 +      {
1.3999 +        fix e :: real
1.4000 +        assume "e > 0"
1.4001 +        then have "0 < e *\<bar>c\<bar>"
1.4002 +          using `c\<noteq>0` mult_pos_pos[of e "abs c"] by auto
1.4003          then obtain N where "\<forall>n\<ge>N. dist (x n) l < e * \<bar>c\<bar>"
1.4004            using as(2)[unfolded LIMSEQ_def, THEN spec[where x="e * abs c"]] by auto
1.4005 -        hence "\<exists>N. \<forall>n\<ge>N. dist (scaleR (1 / c) (x n)) (scaleR (1 / c) l) < e"
1.4006 -          unfolding dist_norm unfolding scaleR_right_diff_distrib[THEN sym]
1.4007 -          using mult_imp_div_pos_less[of "abs c" _ e] `c\<noteq>0` by auto  }
1.4008 -      hence "((\<lambda>n. scaleR (1 / c) (x n)) ---> scaleR (1 / c) l) sequentially" unfolding LIMSEQ_def by auto
1.4009 +        then have "\<exists>N. \<forall>n\<ge>N. dist (scaleR (1 / c) (x n)) (scaleR (1 / c) l) < e"
1.4010 +          unfolding dist_norm
1.4011 +          unfolding scaleR_right_diff_distrib[THEN sym]
1.4012 +          using mult_imp_div_pos_less[of "abs c" _ e] `c\<noteq>0` by auto
1.4013 +      }
1.4014 +      then have "((\<lambda>n. scaleR (1 / c) (x n)) ---> scaleR (1 / c) l) sequentially"
1.4015 +        unfolding LIMSEQ_def by auto
1.4016        ultimately have "l \<in> scaleR c ` s"
1.4017 -        using assms[unfolded closed_sequential_limits, THEN spec[where x="\<lambda>n. scaleR (1/c) (x n)"], THEN spec[where x="scaleR (1/c) l"]]
1.4018 -        unfolding image_iff using `c\<noteq>0` apply(rule_tac x="scaleR (1 / c) l" in bexI) by auto  }
1.4019 -    thus ?thesis unfolding closed_sequential_limits by fast
1.4020 +        using assms[unfolded closed_sequential_limits,
1.4021 +          THEN spec[where x="\<lambda>n. scaleR (1/c) (x n)"],
1.4022 +          THEN spec[where x="scaleR (1/c) l"]]
1.4023 +        unfolding image_iff using `c\<noteq>0`
1.4024 +          apply (rule_tac x="scaleR (1 / c) l" in bexI)
1.4025 +          apply auto
1.4026 +          done
1.4027 +    }
1.4028 +    then show ?thesis
1.4029 +      unfolding closed_sequential_limits by fast
1.4030    qed
1.4031  qed
1.4032
1.4033  lemma closed_negations:
1.4034    fixes s :: "'a::real_normed_vector set"
1.4035 -  assumes "closed s"  shows "closed ((\<lambda>x. -x) ` s)"
1.4036 +  assumes "closed s"
1.4037 +  shows "closed ((\<lambda>x. -x) ` s)"
1.4038    using closed_scaling[OF assms, of "- 1"] by simp
1.4039
1.4040  lemma compact_closed_sums:
1.4041    fixes s :: "'a::real_normed_vector set"
1.4042 -  assumes "compact s"  "closed t"  shows "closed {x + y | x y. x \<in> s \<and> y \<in> t}"
1.4043 -proof-
1.4044 +  assumes "compact s" and "closed t"
1.4045 +  shows "closed {x + y | x y. x \<in> s \<and> y \<in> t}"
1.4046 +proof -
1.4047    let ?S = "{x + y |x y. x \<in> s \<and> y \<in> t}"
1.4048 -  { fix x l assume as:"\<forall>n. x n \<in> ?S"  "(x ---> l) sequentially"
1.4049 -    from as(1) obtain f where f:"\<forall>n. x n = fst (f n) + snd (f n)"  "\<forall>n. fst (f n) \<in> s"  "\<forall>n. snd (f n) \<in> t"
1.4050 +  {
1.4051 +    fix x l
1.4052 +    assume as: "\<forall>n. x n \<in> ?S"  "(x ---> l) sequentially"
1.4053 +    from as(1) obtain f where f: "\<forall>n. x n = fst (f n) + snd (f n)"  "\<forall>n. fst (f n) \<in> s"  "\<forall>n. snd (f n) \<in> t"
1.4054        using choice[of "\<lambda>n y. x n = (fst y) + (snd y) \<and> fst y \<in> s \<and> snd y \<in> t"] by auto
1.4055 -    obtain l' r where "l'\<in>s" and r:"subseq r" and lr:"(((\<lambda>n. fst (f n)) \<circ> r) ---> l') sequentially"
1.4056 +    obtain l' r where "l'\<in>s" and r: "subseq r" and lr: "(((\<lambda>n. fst (f n)) \<circ> r) ---> l') sequentially"
1.4057        using assms(1)[unfolded compact_def, THEN spec[where x="\<lambda> n. fst (f n)"]] using f(2) by auto
1.4058      have "((\<lambda>n. snd (f (r n))) ---> l - l') sequentially"
1.4059 -      using tendsto_diff[OF LIMSEQ_subseq_LIMSEQ[OF as(2) r] lr] and f(1) unfolding o_def by auto
1.4060 -    hence "l - l' \<in> t"
1.4061 +      using tendsto_diff[OF LIMSEQ_subseq_LIMSEQ[OF as(2) r] lr] and f(1)
1.4062 +      unfolding o_def
1.4063 +      by auto
1.4064 +    then have "l - l' \<in> t"
1.4065        using assms(2)[unfolded closed_sequential_limits, THEN spec[where x="\<lambda> n. snd (f (r n))"], THEN spec[where x="l - l'"]]
1.4066 -      using f(3) by auto
1.4067 -    hence "l \<in> ?S" using `l' \<in> s` apply auto apply(rule_tac x=l' in exI) apply(rule_tac x="l - l'" in exI) by auto
1.4068 +      using f(3)
1.4069 +      by auto
1.4070 +    then have "l \<in> ?S"
1.4071 +      using `l' \<in> s`
1.4072 +      apply auto
1.4073 +      apply (rule_tac x=l' in exI)
1.4074 +      apply (rule_tac x="l - l'" in exI)
1.4075 +      apply auto
1.4076 +      done
1.4077    }
1.4078 -  thus ?thesis unfolding closed_sequential_limits by fast
1.4079 +  then show ?thesis
1.4080 +    unfolding closed_sequential_limits by fast
1.4081  qed
1.4082
1.4083  lemma closed_compact_sums:
1.4084    fixes s t :: "'a::real_normed_vector set"
1.4085    assumes "closed s"  "compact t"
1.4086    shows "closed {x + y | x y. x \<in> s \<and> y \<in> t}"
1.4087 -proof-
1.4088 -  have "{x + y |x y. x \<in> t \<and> y \<in> s} = {x + y |x y. x \<in> s \<and> y \<in> t}" apply auto
1.4089 -    apply(rule_tac x=y in exI) apply auto apply(rule_tac x=y in exI) by auto
1.4090 -  thus ?thesis using compact_closed_sums[OF assms(2,1)] by simp
1.4091 +proof -
1.4092 +  have "{x + y |x y. x \<in> t \<and> y \<in> s} = {x + y |x y. x \<in> s \<and> y \<in> t}"
1.4093 +    apply auto
1.4094 +    apply (rule_tac x=y in exI)
1.4095 +    apply auto
1.4096 +    apply (rule_tac x=y in exI)
1.4097 +    apply auto
1.4098 +    done
1.4099 +  then show ?thesis
1.4100 +    using compact_closed_sums[OF assms(2,1)] by simp
1.4101  qed
1.4102
1.4103  lemma compact_closed_differences:
1.4104    fixes s t :: "'a::real_normed_vector set"
1.4105 -  assumes "compact s"  "closed t"
1.4106 +  assumes "compact s" and "closed t"
1.4107    shows "closed {x - y | x y. x \<in> s \<and> y \<in> t}"
1.4108 -proof-
1.4109 +proof -
1.4110    have "{x + y |x y. x \<in> s \<and> y \<in> uminus ` t} =  {x - y |x y. x \<in> s \<and> y \<in> t}"
1.4111 -    apply auto apply(rule_tac x=xa in exI) apply auto apply(rule_tac x=xa in exI) by auto
1.4112 -  thus ?thesis using compact_closed_sums[OF assms(1) closed_negations[OF assms(2)]] by auto
1.4113 +    apply auto
1.4114 +    apply (rule_tac x=xa in exI)
1.4115 +    apply auto
1.4116 +    apply (rule_tac x=xa in exI)
1.4117 +    apply auto
1.4118 +    done
1.4119 +  then show ?thesis
1.4120 +    using compact_closed_sums[OF assms(1) closed_negations[OF assms(2)]] by auto
1.4121  qed
1.4122
1.4123  lemma closed_compact_differences:
1.4124    fixes s t :: "'a::real_normed_vector set"
1.4125    assumes "closed s" "compact t"
1.4126    shows "closed {x - y | x y. x \<in> s \<and> y \<in> t}"
1.4127 -proof-
1.4128 +proof -
1.4129    have "{x + y |x y. x \<in> s \<and> y \<in> uminus ` t} = {x - y |x y. x \<in> s \<and> y \<in> t}"
1.4130 -    apply auto apply(rule_tac x=xa in exI) apply auto apply(rule_tac x=xa in exI) by auto
1.4131 - thus ?thesis using closed_compact_sums[OF assms(1) compact_negations[OF assms(2)]] by simp
1.4132 +    apply auto
1.4133 +    apply (rule_tac x=xa in exI)
1.4134 +    apply auto
1.4135 +    apply (rule_tac x=xa in exI)
1.4136 +    apply auto
1.4137 +    done
1.4138 + then show ?thesis
1.4139 +  using closed_compact_sums[OF assms(1) compact_negations[OF assms(2)]] by simp
1.4140  qed
1.4141
1.4142  lemma closed_translation:
1.4143    fixes a :: "'a::real_normed_vector"
1.4144 -  assumes "closed s"  shows "closed ((\<lambda>x. a + x) ` s)"
1.4145 -proof-
1.4146 +  assumes "closed s"
1.4147 +  shows "closed ((\<lambda>x. a + x) ` s)"
1.4148 +proof -
1.4149    have "{a + y |y. y \<in> s} = (op + a ` s)" by auto
1.4150 -  thus ?thesis using compact_closed_sums[OF compact_sing[of a] assms] by auto
1.4151 +  then show ?thesis
1.4152 +    using compact_closed_sums[OF compact_sing[of a] assms] by auto
1.4153  qed
1.4154
1.4155  lemma translation_Compl:
1.4156    fixes a :: "'a::ab_group_add"
1.4157    shows "(\<lambda>x. a + x) ` (- t) = - ((\<lambda>x. a + x) ` t)"
1.4158 -  apply (auto simp add: image_iff) apply(rule_tac x="x - a" in bexI) by auto
1.4159 +  apply (auto simp add: image_iff)
1.4160 +  apply (rule_tac x="x - a" in bexI)
1.4161 +  apply auto
1.4162 +  done
1.4163
1.4164  lemma translation_UNIV:
1.4165 -  fixes a :: "'a::ab_group_add" shows "range (\<lambda>x. a + x) = UNIV"
1.4166 -  apply (auto simp add: image_iff) apply(rule_tac x="x - a" in exI) by auto
1.4167 +  fixes a :: "'a::ab_group_add"
1.4168 +  shows "range (\<lambda>x. a + x) = UNIV"
1.4169 +  apply (auto simp add: image_iff)
1.4170 +  apply (rule_tac x="x - a" in exI)
1.4171 +  apply auto
1.4172 +  done
1.4173
1.4174  lemma translation_diff:
1.4175    fixes a :: "'a::ab_group_add"
1.4176 @@ -5235,37 +5892,48 @@
1.4177  lemma closure_translation:
1.4178    fixes a :: "'a::real_normed_vector"
1.4179    shows "closure ((\<lambda>x. a + x) ` s) = (\<lambda>x. a + x) ` (closure s)"
1.4180 -proof-
1.4181 -  have *:"op + a ` (- s) = - op + a ` s"
1.4182 -    apply auto unfolding image_iff apply(rule_tac x="x - a" in bexI) by auto
1.4183 -  show ?thesis unfolding closure_interior translation_Compl
1.4184 -    using interior_translation[of a "- s"] unfolding * by auto
1.4185 +proof -
1.4186 +  have *: "op + a ` (- s) = - op + a ` s"
1.4187 +    apply auto
1.4188 +    unfolding image_iff
1.4189 +    apply (rule_tac x="x - a" in bexI)
1.4190 +    apply auto
1.4191 +    done
1.4192 +  show ?thesis
1.4193 +    unfolding closure_interior translation_Compl
1.4194 +    using interior_translation[of a "- s"]
1.4195 +    unfolding *
1.4196 +    by auto
1.4197  qed
1.4198
1.4199  lemma frontier_translation:
1.4200    fixes a :: "'a::real_normed_vector"
1.4201    shows "frontier((\<lambda>x. a + x) ` s) = (\<lambda>x. a + x) ` (frontier s)"
1.4202 -  unfolding frontier_def translation_diff interior_translation closure_translation by auto
1.4203 +  unfolding frontier_def translation_diff interior_translation closure_translation
1.4204 +  by auto
1.4205
1.4206
1.4207  subsection {* Separation between points and sets *}
1.4208
1.4209  lemma separate_point_closed:
1.4210    fixes s :: "'a::heine_borel set"
1.4211 -  shows "closed s \<Longrightarrow> a \<notin> s  ==> (\<exists>d>0. \<forall>x\<in>s. d \<le> dist a x)"
1.4212 -proof(cases "s = {}")
1.4213 +  assumes "closed s" and "a \<notin> s"
1.4214 +  shows "\<exists>d>0. \<forall>x\<in>s. d \<le> dist a x"
1.4215 +proof (cases "s = {}")
1.4216    case True
1.4217 -  thus ?thesis by(auto intro!: exI[where x=1])
1.4218 +  then show ?thesis by(auto intro!: exI[where x=1])
1.4219  next
1.4220    case False
1.4221 -  assume "closed s" "a \<notin> s"
1.4222 -  then obtain x where "x\<in>s" "\<forall>y\<in>s. dist a x \<le> dist a y" using `s \<noteq> {}` distance_attains_inf [of s a] by blast
1.4223 -  with `x\<in>s` show ?thesis using dist_pos_lt[of a x] and`a \<notin> s` by blast
1.4224 +  from assms obtain x where "x\<in>s" "\<forall>y\<in>s. dist a x \<le> dist a y"
1.4225 +    using `s \<noteq> {}` distance_attains_inf [of s a] by blast
1.4226 +  with `x\<in>s` show ?thesis using dist_pos_lt[of a x] and`a \<notin> s`
1.4227 +    by blast
1.4228  qed
1.4229
1.4230  lemma separate_compact_closed:
1.4231    fixes s t :: "'a::heine_borel set"
1.4232 -  assumes "compact s" and t: "closed t" "s \<inter> t = {}"
1.4233 +  assumes "compact s"
1.4234 +    and t: "closed t" "s \<inter> t = {}"
1.4235    shows "\<exists>d>0. \<forall>x\<in>s. \<forall>y\<in>t. d \<le> dist x y"
1.4236  proof cases
1.4237    assume "s \<noteq> {} \<and> t \<noteq> {}"
1.4238 @@ -5279,70 +5947,104 @@
1.4239      using t `t \<noteq> {}` in_closed_iff_infdist_zero by (auto simp: less_le infdist_nonneg)
1.4240    moreover have "\<forall>x'\<in>s. \<forall>y\<in>t. ?inf x \<le> dist x' y"
1.4241      using x by (auto intro: order_trans infdist_le)
1.4242 -  ultimately show ?thesis
1.4243 -    by auto
1.4244 +  ultimately show ?thesis by auto
1.4245  qed (auto intro!: exI[of _ 1])
1.4246
1.4247  lemma separate_closed_compact:
1.4248    fixes s t :: "'a::heine_borel set"
1.4249 -  assumes "closed s" and "compact t" and "s \<inter> t = {}"
1.4250 +  assumes "closed s"
1.4251 +    and "compact t"
1.4252 +    and "s \<inter> t = {}"
1.4253    shows "\<exists>d>0. \<forall>x\<in>s. \<forall>y\<in>t. d \<le> dist x y"
1.4254 -proof-
1.4255 -  have *:"t \<inter> s = {}" using assms(3) by auto
1.4256 -  show ?thesis using separate_compact_closed[OF assms(2,1) *]
1.4257 -    apply auto apply(rule_tac x=d in exI) apply auto apply (erule_tac x=y in ballE)
1.4258 -    by (auto simp add: dist_commute)
1.4259 +proof -
1.4260 +  have *: "t \<inter> s = {}"
1.4261 +    using assms(3) by auto
1.4262 +  show ?thesis
1.4263 +    using separate_compact_closed[OF assms(2,1) *]
1.4264 +    apply auto
1.4265 +    apply (rule_tac x=d in exI)
1.4266 +    apply auto
1.4267 +    apply (erule_tac x=y in ballE)
1.4268 +    apply (auto simp add: dist_commute)
1.4269 +    done
1.4270  qed
1.4271
1.4272
1.4273  subsection {* Intervals *}
1.4274 -
1.4275 -lemma interval: fixes a :: "'a::ordered_euclidean_space" shows
1.4276 -  "{a <..< b} = {x::'a. \<forall>i\<in>Basis. a\<bullet>i < x\<bullet>i \<and> x\<bullet>i < b\<bullet>i}" and
1.4277 -  "{a .. b} = {x::'a. \<forall>i\<in>Basis. a\<bullet>i \<le> x\<bullet>i \<and> x\<bullet>i \<le> b\<bullet>i}"
1.4278 -  by(auto simp add:set_eq_iff eucl_le[where 'a='a] eucl_less[where 'a='a])
1.4279 -
1.4280 -lemma mem_interval: fixes a :: "'a::ordered_euclidean_space" shows
1.4281 -  "x \<in> {a<..<b} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < x\<bullet>i \<and> x\<bullet>i < b\<bullet>i)"
1.4282 -  "x \<in> {a .. b} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> x\<bullet>i \<and> x\<bullet>i \<le> b\<bullet>i)"
1.4283 -  using interval[of a b] by(auto simp add: set_eq_iff eucl_le[where 'a='a] eucl_less[where 'a='a])
1.4284 -
1.4285 -lemma interval_eq_empty: fixes a :: "'a::ordered_euclidean_space" shows
1.4286 - "({a <..< b} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i \<le> a\<bullet>i))" (is ?th1) and
1.4287 - "({a  ..  b} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i < a\<bullet>i))" (is ?th2)
1.4288 -proof-
1.4289 -  { fix i x assume i:"i\<in>Basis" and as:"b\<bullet>i \<le> a\<bullet>i" and x:"x\<in>{a <..< b}"
1.4290 -    hence "a \<bullet> i < x \<bullet> i \<and> x \<bullet> i < b \<bullet> i" unfolding mem_interval by auto
1.4291 -    hence "a\<bullet>i < b\<bullet>i" by auto
1.4292 -    hence False using as by auto  }
1.4293 +
1.4294 +lemma interval:
1.4295 +  fixes a :: "'a::ordered_euclidean_space"
1.4296 +  shows "{a <..< b} = {x::'a. \<forall>i\<in>Basis. a\<bullet>i < x\<bullet>i \<and> x\<bullet>i < b\<bullet>i}"
1.4297 +    and "{a .. b} = {x::'a. \<forall>i\<in>Basis. a\<bullet>i \<le> x\<bullet>i \<and> x\<bullet>i \<le> b\<bullet>i}"
1.4298 +  by (auto simp add:set_eq_iff eucl_le[where 'a='a] eucl_less[where 'a='a])
1.4299 +
1.4300 +lemma mem_interval:
1.4301 +  fixes a :: "'a::ordered_euclidean_space"
1.4302 +  shows "x \<in> {a<..<b} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < x\<bullet>i \<and> x\<bullet>i < b\<bullet>i)"
1.4303 +    and "x \<in> {a .. b} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> x\<bullet>i \<and> x\<bullet>i \<le> b\<bullet>i)"
1.4304 +  using interval[of a b]
1.4305 +  by (auto simp add: set_eq_iff eucl_le[where 'a='a] eucl_less[where 'a='a])
1.4306 +
1.4307 +lemma interval_eq_empty:
1.4308 +  fixes a :: "'a::ordered_euclidean_space"
1.4309 +  shows "({a <..< b} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i \<le> a\<bullet>i))" (is ?th1)
1.4310 +    and "({a  ..  b} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i < a\<bullet>i))" (is ?th2)
1.4311 +proof -
1.4312 +  {
1.4313 +    fix i x
1.4314 +    assume i: "i\<in>Basis" and as:"b\<bullet>i \<le> a\<bullet>i" and x:"x\<in>{a <..< b}"
1.4315 +    then have "a \<bullet> i < x \<bullet> i \<and> x \<bullet> i < b \<bullet> i"
1.4316 +      unfolding mem_interval by auto
1.4317 +    then have "a\<bullet>i < b\<bullet>i" by auto
1.4318 +    then have False using as by auto
1.4319 +  }
1.4320    moreover
1.4321 -  { assume as:"\<forall>i\<in>Basis. \<not> (b\<bullet>i \<le> a\<bullet>i)"
1.4322 +  {
1.4323 +    assume as: "\<forall>i\<in>Basis. \<not> (b\<bullet>i \<le> a\<bullet>i)"
1.4324      let ?x = "(1/2) *\<^sub>R (a + b)"
1.4325 -    { fix i :: 'a assume i:"i\<in>Basis"
1.4326 -      have "a\<bullet>i < b\<bullet>i" using as[THEN bspec[where x=i]] i by auto
1.4327 -      hence "a\<bullet>i < ((1/2) *\<^sub>R (a+b)) \<bullet> i" "((1/2) *\<^sub>R (a+b)) \<bullet> i < b\<bullet>i"
1.4328 -        by (auto simp: inner_add_left) }
1.4329 -    hence "{a <..< b} \<noteq> {}" using mem_interval(1)[of "?x" a b] by auto  }
1.4330 +    {
1.4331 +      fix i :: 'a
1.4332 +      assume i: "i \<in> Basis"
1.4333 +      have "a\<bullet>i < b\<bullet>i"
1.4334 +        using as[THEN bspec[where x=i]] i by auto
1.4335 +      then have "a\<bullet>i < ((1/2) *\<^sub>R (a+b)) \<bullet> i" "((1/2) *\<^sub>R (a+b)) \<bullet> i < b\<bullet>i"
1.4336 +        by (auto simp: inner_add_left)
1.4337 +    }
1.4338 +    then have "{a <..< b} \<noteq> {}"
1.4339 +      using mem_interval(1)[of "?x" a b] by auto
1.4340 +  }
1.4341    ultimately show ?th1 by blast
1.4342
1.4343 -  { fix i x assume i:"i\<in>Basis" and as:"b\<bullet>i < a\<bullet>i" and x:"x\<in>{a .. b}"
1.4344 -    hence "a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i" unfolding mem_interval by auto
1.4345 -    hence "a\<bullet>i \<le> b\<bullet>i" by auto
1.4346 -    hence False using as by auto  }
1.4347 +  {
1.4348 +    fix i x
1.4349 +    assume i: "i \<in> Basis" and as:"b\<bullet>i < a\<bullet>i" and x:"x\<in>{a .. b}"
1.4350 +    then have "a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i"
1.4351 +      unfolding mem_interval by auto
1.4352 +    then have "a\<bullet>i \<le> b\<bullet>i" by auto
1.4353 +    then have False using as by auto
1.4354 +  }
1.4355    moreover
1.4356 -  { assume as:"\<forall>i\<in>Basis. \<not> (b\<bullet>i < a\<bullet>i)"
1.4357 +  {
1.4358 +    assume as:"\<forall>i\<in>Basis. \<not> (b\<bullet>i < a\<bullet>i)"
1.4359      let ?x = "(1/2) *\<^sub>R (a + b)"
1.4360 -    { fix i :: 'a assume i:"i\<in>Basis"
1.4361 -      have "a\<bullet>i \<le> b\<bullet>i" using as[THEN bspec[where x=i]] i by auto
1.4362 -      hence "a\<bullet>i \<le> ((1/2) *\<^sub>R (a+b)) \<bullet> i" "((1/2) *\<^sub>R (a+b)) \<bullet> i \<le> b\<bullet>i"
1.4363 -        by (auto simp: inner_add_left) }
1.4364 -    hence "{a .. b} \<noteq> {}" using mem_interval(2)[of "?x" a b] by auto  }
1.4365 +    {
1.4366 +      fix i :: 'a
1.4367 +      assume i:"i \<in> Basis"
1.4368 +      have "a\<bullet>i \<le> b\<bullet>i"
1.4369 +        using as[THEN bspec[where x=i]] i by auto
1.4370 +      then have "a\<bullet>i \<le> ((1/2) *\<^sub>R (a+b)) \<bullet> i" "((1/2) *\<^sub>R (a+b)) \<bullet> i \<le> b\<bullet>i"
1.4371 +        by (auto simp: inner_add_left)
1.4372 +    }
1.4373 +    then have "{a .. b} \<noteq> {}"
1.4374 +      using mem_interval(2)[of "?x" a b] by auto
1.4375 +  }
1.4376    ultimately show ?th2 by blast
1.4377  qed
1.4378
1.4379 -lemma interval_ne_empty: fixes a :: "'a::ordered_euclidean_space" shows
1.4380 -  "{a  ..  b} \<noteq> {} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i)" and
1.4381 -  "{a <..< b} \<noteq> {} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i)"
1.4382 +lemma interval_ne_empty:
1.4383 +  fixes a :: "'a::ordered_euclidean_space"
1.4384 +  shows "{a  ..  b} \<noteq> {} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i)"
1.4385 +  and "{a <..< b} \<noteq> {} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i)"
1.4386    unfolding interval_eq_empty[of a b] by fastforce+
1.4387
1.4388  lemma interval_sing:
1.4389 @@ -5351,11 +6053,12 @@
1.4390    unfolding set_eq_iff mem_interval eq_iff [symmetric]
1.4391    by (auto intro: euclidean_eqI simp: ex_in_conv)
1.4392
1.4393 -lemma subset_interval_imp: fixes a :: "'a::ordered_euclidean_space" shows
1.4394 - "(\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i) \<Longrightarrow> {c .. d} \<subseteq> {a .. b}" and
1.4395 - "(\<forall>i\<in>Basis. a\<bullet>i < c\<bullet>i \<and> d\<bullet>i < b\<bullet>i) \<Longrightarrow> {c .. d} \<subseteq> {a<..<b}" and
1.4396 - "(\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i) \<Longrightarrow> {c<..<d} \<subseteq> {a .. b}" and
1.4397 - "(\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i) \<Longrightarrow> {c<..<d} \<subseteq> {a<..<b}"
1.4398 +lemma subset_interval_imp:
1.4399 +  fixes a :: "'a::ordered_euclidean_space"
1.4400 +  shows "(\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i) \<Longrightarrow> {c .. d} \<subseteq> {a .. b}"
1.4401 +    and "(\<forall>i\<in>Basis. a\<bullet>i < c\<bullet>i \<and> d\<bullet>i < b\<bullet>i) \<Longrightarrow> {c .. d} \<subseteq> {a<..<b}"
1.4402 +    and "(\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i) \<Longrightarrow> {c<..<d} \<subseteq> {a .. b}"
1.4403 +    and "(\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i) \<Longrightarrow> {c<..<d} \<subseteq> {a<..<b}"
1.4404    unfolding subset_eq[unfolded Ball_def] unfolding mem_interval
1.4405    by (best intro: order_trans less_le_trans le_less_trans less_imp_le)+
1.4406
1.4407 @@ -5365,80 +6068,125 @@
1.4408    unfolding subset_eq [unfolded Ball_def] mem_interval
1.4409    by (fast intro: less_imp_le)
1.4410
1.4411 -lemma subset_interval: fixes a :: "'a::ordered_euclidean_space" shows
1.4412 - "{c .. d} \<subseteq> {a .. b} \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i \<le> d\<bullet>i) --> (\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i)" (is ?th1) and
1.4413 - "{c .. d} \<subseteq> {a<..<b} \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i \<le> d\<bullet>i) --> (\<forall>i\<in>Basis. a\<bullet>i < c\<bullet>i \<and> d\<bullet>i < b\<bullet>i)" (is ?th2) and
1.4414 - "{c<..<d} \<subseteq> {a .. b} \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i) --> (\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i)" (is ?th3) and
1.4415 - "{c<..<d} \<subseteq> {a<..<b} \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i) --> (\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i)" (is ?th4)
1.4416 -proof-
1.4417 -  show ?th1 unfolding subset_eq and Ball_def and mem_interval by (auto intro: order_trans)
1.4418 -  show ?th2 unfolding subset_eq and Ball_def and mem_interval by (auto intro: le_less_trans less_le_trans order_trans less_imp_le)
1.4419 -  { assume as: "{c<..<d} \<subseteq> {a .. b}" "\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i"
1.4420 -    hence "{c<..<d} \<noteq> {}" unfolding interval_eq_empty by auto
1.4421 -    fix i :: 'a assume i:"i\<in>Basis"
1.4422 +lemma subset_interval:
1.4423 +  fixes a :: "'a::ordered_euclidean_space"
1.4424 +  shows "{c .. d} \<subseteq> {a .. b} \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i \<le> d\<bullet>i) --> (\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i)" (is ?th1)
1.4425 +    and "{c .. d} \<subseteq> {a<..<b} \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i \<le> d\<bullet>i) --> (\<forall>i\<in>Basis. a\<bullet>i < c\<bullet>i \<and> d\<bullet>i < b\<bullet>i)" (is ?th2)
1.4426 +    and "{c<..<d} \<subseteq> {a .. b} \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i) --> (\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i)" (is ?th3)
1.4427 +    and "{c<..<d} \<subseteq> {a<..<b} \<longleftrightarrow> (\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i) --> (\<forall>i\<in>Basis. a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i)" (is ?th4)
1.4428 +proof -
1.4429 +  show ?th1
1.4430 +    unfolding subset_eq and Ball_def and mem_interval
1.4431 +    by (auto intro: order_trans)
1.4432 +  show ?th2
1.4433 +    unfolding subset_eq and Ball_def and mem_interval
1.4434 +    by (auto intro: le_less_trans less_le_trans order_trans less_imp_le)
1.4435 +  {
1.4436 +    assume as: "{c<..<d} \<subseteq> {a .. b}" "\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i"
1.4437 +    then have "{c<..<d} \<noteq> {}"
1.4438 +      unfolding interval_eq_empty by auto
1.4439 +    fix i :: 'a
1.4440 +    assume i: "i \<in> Basis"
1.4441      (** TODO combine the following two parts as done in the HOL_light version. **)
1.4442 -    { let ?x = "(\<Sum>j\<in>Basis. (if j=i then ((min (a\<bullet>j) (d\<bullet>j))+c\<bullet>j)/2 else (c\<bullet>j+d\<bullet>j)/2) *\<^sub>R j)::'a"
1.4443 +    {
1.4444 +      let ?x = "(\<Sum>j\<in>Basis. (if j=i then ((min (a\<bullet>j) (d\<bullet>j))+c\<bullet>j)/2 else (c\<bullet>j+d\<bullet>j)/2) *\<^sub>R j)::'a"
1.4445        assume as2: "a\<bullet>i > c\<bullet>i"
1.4446 -      { fix j :: 'a assume j:"j\<in>Basis"
1.4447 -        hence "c \<bullet> j < ?x \<bullet> j \<and> ?x \<bullet> j < d \<bullet> j"
1.4448 -          apply(cases "j=i") using as(2)[THEN bspec[where x=j]] i
1.4449 -          by (auto simp add: as2)  }
1.4450 -      hence "?x\<in>{c<..<d}" using i unfolding mem_interval by auto
1.4451 +      {
1.4452 +        fix j :: 'a
1.4453 +        assume j: "j \<in> Basis"
1.4454 +        then have "c \<bullet> j < ?x \<bullet> j \<and> ?x \<bullet> j < d \<bullet> j"
1.4455 +          apply (cases "j = i")
1.4456 +          using as(2)[THEN bspec[where x=j]] i
1.4457 +          apply (auto simp add: as2)
1.4458 +          done
1.4459 +      }
1.4460 +      then have "?x\<in>{c<..<d}"
1.4461 +        using i unfolding mem_interval by auto
1.4462 +      moreover
1.4463 +      have "?x \<notin> {a .. b}"
1.4464 +        unfolding mem_interval
1.4465 +        apply auto
1.4466 +        apply (rule_tac x=i in bexI)
1.4467 +        using as(2)[THEN bspec[where x=i]] and as2 i
1.4468 +        apply auto
1.4469 +        done
1.4470 +      ultimately have False using as by auto
1.4471 +    }
1.4472 +    then have "a\<bullet>i \<le> c\<bullet>i" by (rule ccontr) auto
1.4473 +    moreover
1.4474 +    {
1.4475 +      let ?x = "(\<Sum>j\<in>Basis. (if j=i then ((max (b\<bullet>j) (c\<bullet>j))+d\<bullet>j)/2 else (c\<bullet>j+d\<bullet>j)/2) *\<^sub>R j)::'a"
1.4476 +      assume as2: "b\<bullet>i < d\<bullet>i"
1.4477 +      {
1.4478 +        fix j :: 'a
1.4479 +        assume "j\<in>Basis"
1.4480 +        then have "d \<bullet> j > ?x \<bullet> j \<and> ?x \<bullet> j > c \<bullet> j"
1.4481 +          apply (cases "j = i")
1.4482 +          using as(2)[THEN bspec[where x=j]]
1.4483 +          apply (auto simp add: as2)
1.4484 +          done
1.4485 +      }
1.4486 +      then have "?x\<in>{c<..<d}"
1.4487 +        unfolding mem_interval by auto
1.4488        moreover
1.4489        have "?x\<notin>{a .. b}"
1.4490 -        unfolding mem_interval apply auto apply(rule_tac x=i in bexI)
1.4491 -        using as(2)[THEN bspec[where x=i]] and as2 i
1.4492 -        by auto
1.4493 -      ultimately have False using as by auto  }
1.4494 -    hence "a\<bullet>i \<le> c\<bullet>i" by(rule ccontr)auto
1.4495 -    moreover
1.4496 -    { let ?x = "(\<Sum>j\<in>Basis. (if j=i then ((max (b\<bullet>j) (c\<bullet>j))+d\<bullet>j)/2 else (c\<bullet>j+d\<bullet>j)/2) *\<^sub>R j)::'a"
1.4497 -      assume as2: "b\<bullet>i < d\<bullet>i"
1.4498 -      { fix j :: 'a assume "j\<in>Basis"
1.4499 -        hence "d \<bullet> j > ?x \<bullet> j \<and> ?x \<bullet> j > c \<bullet> j"
1.4500 -          apply(cases "j=i") using as(2)[THEN bspec[where x=j]]
1.4501 -          by (auto simp add: as2) }
1.4502 -      hence "?x\<in>{c<..<d}" unfolding mem_interval by auto
1.4503 -      moreover
1.4504 -      have "?x\<notin>{a .. b}"
1.4505 -        unfolding mem_interval apply auto apply(rule_tac x=i in bexI)
1.4506 +        unfolding mem_interval
1.4507 +        apply auto
1.4508 +        apply (rule_tac x=i in bexI)
1.4509          using as(2)[THEN bspec[where x=i]] and as2 using i
1.4510 -        by auto
1.4511 -      ultimately have False using as by auto  }
1.4512 -    hence "b\<bullet>i \<ge> d\<bullet>i" by(rule ccontr)auto
1.4513 +        apply auto
1.4514 +        done
1.4515 +      ultimately have False using as by auto
1.4516 +    }
1.4517 +    then have "b\<bullet>i \<ge> d\<bullet>i" by (rule ccontr) auto
1.4518      ultimately
1.4519      have "a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i" by auto
1.4520    } note part1 = this
1.4521    show ?th3
1.4522 -    unfolding subset_eq and Ball_def and mem_interval
1.4523 -    apply(rule,rule,rule,rule)
1.4524 -    apply(rule part1)
1.4525 +    unfolding subset_eq and Ball_def and mem_interval
1.4526 +    apply (rule, rule, rule, rule)
1.4527 +    apply (rule part1)
1.4528      unfolding subset_eq and Ball_def and mem_interval
1.4529      prefer 4
1.4530 -    apply auto
1.4531 -    by(erule_tac x=xa in allE,erule_tac x=xa in allE,fastforce)+
1.4532 -  { assume as:"{c<..<d} \<subseteq> {a<..<b}" "\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i"
1.4533 -    fix i :: 'a assume i:"i\<in>Basis"
1.4534 -    from as(1) have "{c<..<d} \<subseteq> {a..b}" using interval_open_subset_closed[of a b] by auto
1.4535 -    hence "a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i" using part1 and as(2) using i by auto  } note * = this
1.4536 -  show ?th4 unfolding subset_eq and Ball_def and mem_interval
1.4537 -    apply(rule,rule,rule,rule) apply(rule *) unfolding subset_eq and Ball_def and mem_interval prefer 4
1.4538 -    apply auto by(erule_tac x=xa in allE, simp)+
1.4539 -qed
1.4540 -
1.4541 -lemma inter_interval: fixes a :: "'a::ordered_euclidean_space" shows
1.4542 - "{a .. b} \<inter> {c .. d} =  {(\<Sum>i\<in>Basis. max (a\<bullet>i) (c\<bullet>i) *\<^sub>R i) .. (\<Sum>i\<in>Basis. min (b\<bullet>i) (d\<bullet>i) *\<^sub>R i)}"
1.4543 -  unfolding set_eq_iff and Int_iff and mem_interval by auto
1.4544 -
1.4545 -lemma disjoint_interval: fixes a::"'a::ordered_euclidean_space" shows
1.4546 -  "{a .. b} \<inter> {c .. d} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. (b\<bullet>i < a\<bullet>i \<or> d\<bullet>i < c\<bullet>i \<or> b\<bullet>i < c\<bullet>i \<or> d\<bullet>i < a\<bullet>i))" (is ?th1) and
1.4547 -  "{a .. b} \<inter> {c<..<d} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. (b\<bullet>i < a\<bullet>i \<or> d\<bullet>i \<le> c\<bullet>i \<or> b\<bullet>i \<le> c\<bullet>i \<or> d\<bullet>i \<le> a\<bullet>i))" (is ?th2) and
1.4548 -  "{a<..<b} \<inter> {c .. d} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. (b\<bullet>i \<le> a\<bullet>i \<or> d\<bullet>i < c\<bullet>i \<or> b\<bullet>i \<le> c\<bullet>i \<or> d\<bullet>i \<le> a\<bullet>i))" (is ?th3) and
1.4549 -  "{a<..<b} \<inter> {c<..<d} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. (b\<bullet>i \<le> a\<bullet>i \<or> d\<bullet>i \<le> c\<bullet>i \<or> b\<bullet>i \<le> c\<bullet>i \<or> d\<bullet>i \<le> a\<bullet>i))" (is ?th4)
1.4550 -proof-
1.4551 +    apply auto
1.4552 +    apply (erule_tac x=xa in allE, erule_tac x=xa in allE, fastforce)+
1.4553 +    done
1.4554 +  {
1.4555 +    assume as: "{c<..<d} \<subseteq> {a<..<b}" "\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i"
1.4556 +    fix i :: 'a
1.4557 +    assume i:"i\<in>Basis"
1.4558 +    from as(1) have "{c<..<d} \<subseteq> {a..b}"
1.4559 +      using interval_open_subset_closed[of a b] by auto
1.4560 +    then have "a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i"
1.4561 +      using part1 and as(2) using i by auto
1.4562 +  } note * = this
1.4563 +  show ?th4
1.4564 +    unfolding subset_eq and Ball_def and mem_interval
1.4565 +    apply (rule, rule, rule, rule)
1.4566 +    apply (rule *)
1.4567 +    unfolding subset_eq and Ball_def and mem_interval
1.4568 +    prefer 4
1.4569 +    apply auto
1.4570 +    apply (erule_tac x=xa in allE, simp)+
1.4571 +    done
1.4572 +qed
1.4573 +
1.4574 +lemma inter_interval:
1.4575 +  fixes a :: "'a::ordered_euclidean_space"
1.4576 +  shows "{a .. b} \<inter> {c .. d} =  {(\<Sum>i\<in>Basis. max (a\<bullet>i) (c\<bullet>i) *\<^sub>R i) .. (\<Sum>i\<in>Basis. min (b\<bullet>i) (d\<bullet>i) *\<^sub>R i)}"
1.4577 +  unfolding set_eq_iff and Int_iff and mem_interval
1.4578 +  by auto
1.4579 +
1.4580 +lemma disjoint_interval:
1.4581 +  fixes a::"'a::ordered_euclidean_space"
1.4582 +  shows "{a .. b} \<inter> {c .. d} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. (b\<bullet>i < a\<bullet>i \<or> d\<bullet>i < c\<bullet>i \<or> b\<bullet>i < c\<bullet>i \<or> d\<bullet>i < a\<bullet>i))" (is ?th1)
1.4583 +    and "{a .. b} \<inter> {c<..<d} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. (b\<bullet>i < a\<bullet>i \<or> d\<bullet>i \<le> c\<bullet>i \<or> b\<bullet>i \<le> c\<bullet>i \<or> d\<bullet>i \<le> a\<bullet>i))" (is ?th2)
1.4584 +    and "{a<..<b} \<inter> {c .. d} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. (b\<bullet>i \<le> a\<bullet>i \<or> d\<bullet>i < c\<bullet>i \<or> b\<bullet>i \<le> c\<bullet>i \<or> d\<bullet>i \<le> a\<bullet>i))" (is ?th3)
1.4585 +    and "{a<..<b} \<inter> {c<..<d} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. (b\<bullet>i \<le> a\<bullet>i \<or> d\<bullet>i \<le> c\<bullet>i \<or> b\<bullet>i \<le> c\<bullet>i \<or> d\<bullet>i \<le> a\<bullet>i))" (is ?th4)
1.4586 +proof -
1.4587    let ?z = "(\<Sum>i\<in>Basis. (((max (a\<bullet>i) (c\<bullet>i)) + (min (b\<bullet>i) (d\<bullet>i))) / 2) *\<^sub>R i)::'a"
1.4588    have **: "\<And>P Q. (\<And>i :: 'a. i \<in> Basis \<Longrightarrow> Q ?z i \<Longrightarrow> P i) \<Longrightarrow>
1.4589 -      (\<And>i x :: 'a. i \<in> Basis \<Longrightarrow> P i \<Longrightarrow> Q x i) \<Longrightarrow> (\<forall>x. \<exists>i\<in>Basis. Q x i) \<longleftrightarrow> (\<exists>i\<in>Basis. P i)"
1.4590 +      (\<And>i x :: 'a. i \<in> Basis \<Longrightarrow> P i \<Longrightarrow> Q x i) \<Longrightarrow> (\<forall>x. \<exists>i\<in>Basis. Q x i) \<longleftrightarrow> (\<exists>i\<in>Basis. P i)"
1.4591      by blast
1.4592    note * = set_eq_iff Int_iff empty_iff mem_interval ball_conj_distrib[symmetric] eq_False ball_simps(10)
1.4593    show ?th1 unfolding * by (intro **) auto
1.4594 @@ -5450,8 +6198,9 @@
1.4595  (* Moved interval_open_subset_closed a bit upwards *)
1.4596
1.4597  lemma open_interval[intro]:
1.4598 -  fixes a b :: "'a::ordered_euclidean_space" shows "open {a<..<b}"
1.4599 -proof-
1.4600 +  fixes a b :: "'a::ordered_euclidean_space"
1.4601 +  shows "open {a<..<b}"
1.4602 +proof -
1.4603    have "open (\<Inter>i\<in>Basis. (\<lambda>x. x\<bullet>i) -` {a\<bullet>i<..<b\<bullet>i})"
1.4604      by (intro open_INT finite_lessThan ballI continuous_open_vimage allI
1.4605        linear_continuous_at open_real_greaterThanLessThan finite_Basis bounded_linear_inner_left)
1.4606 @@ -5461,8 +6210,9 @@
1.4607  qed
1.4608
1.4609  lemma closed_interval[intro]:
1.4610 -  fixes a b :: "'a::ordered_euclidean_space" shows "closed {a .. b}"
1.4611 -proof-
1.4612 +  fixes a b :: "'a::ordered_euclidean_space"
1.4613 +  shows "closed {a .. b}"
1.4614 +proof -
1.4615    have "closed (\<Inter>i\<in>Basis. (\<lambda>x. x\<bullet>i) -` {a\<bullet>i .. b\<bullet>i})"
1.4616      by (intro closed_INT ballI continuous_closed_vimage allI
1.4617        linear_continuous_at closed_real_atLeastAtMost finite_Basis bounded_linear_inner_left)
1.4618 @@ -5477,127 +6227,237 @@
1.4619  proof(rule subset_antisym)
1.4620    show "?R \<subseteq> ?L" using interval_open_subset_closed open_interval
1.4621      by (rule interior_maximal)
1.4622 -next
1.4623 -  { fix x assume "x \<in> interior {a..b}"
1.4624 -    then obtain s where s:"open s" "x \<in> s" "s \<subseteq> {a..b}" ..
1.4625 -    then obtain e where "e>0" and e:"\<forall>x'. dist x' x < e \<longrightarrow> x' \<in> {a..b}" unfolding open_dist and subset_eq by auto
1.4626 -    { fix i :: 'a assume i:"i\<in>Basis"
1.4627 +  {
1.4628 +    fix x
1.4629 +    assume "x \<in> interior {a..b}"
1.4630 +    then obtain s where s: "open s" "x \<in> s" "s \<subseteq> {a..b}" ..
1.4631 +    then obtain e where "e>0" and e:"\<forall>x'. dist x' x < e \<longrightarrow> x' \<in> {a..b}"
1.4632 +      unfolding open_dist and subset_eq by auto
1.4633 +    {
1.4634 +      fix i :: 'a
1.4635 +      assume i: "i \<in> Basis"
1.4636        have "dist (x - (e / 2) *\<^sub>R i) x < e"
1.4637 -           "dist (x + (e / 2) *\<^sub>R i) x < e"
1.4638 -        unfolding dist_norm apply auto
1.4639 -        unfolding norm_minus_cancel using norm_Basis[OF i] `e>0` by auto
1.4640 -      hence "a \<bullet> i \<le> (x - (e / 2) *\<^sub>R i) \<bullet> i"
1.4641 -                     "(x + (e / 2) *\<^sub>R i) \<bullet> i \<le> b \<bullet> i"
1.4642 +        and "dist (x + (e / 2) *\<^sub>R i) x < e"
1.4643 +        unfolding dist_norm
1.4644 +        apply auto
1.4645 +        unfolding norm_minus_cancel
1.4646 +        using norm_Basis[OF i] `e>0`
1.4647 +        apply auto
1.4648 +        done
1.4649 +      then have "a \<bullet> i \<le> (x - (e / 2) *\<^sub>R i) \<bullet> i" and "(x + (e / 2) *\<^sub>R i) \<bullet> i \<le> b \<bullet> i"
1.4650          using e[THEN spec[where x="x - (e/2) *\<^sub>R i"]]
1.4651 -        and   e[THEN spec[where x="x + (e/2) *\<^sub>R i"]]
1.4652 -        unfolding mem_interval using i by blast+
1.4653 -      hence "a \<bullet> i < x \<bullet> i" and "x \<bullet> i < b \<bullet> i"
1.4654 -        using `e>0` i by (auto simp: inner_diff_left inner_Basis inner_add_left) }
1.4655 -    hence "x \<in> {a<..<b}" unfolding mem_interval by auto  }
1.4656 -  thus "?L \<subseteq> ?R" ..
1.4657 -qed
1.4658 -
1.4659 -lemma bounded_closed_interval: fixes a :: "'a::ordered_euclidean_space" shows "bounded {a .. b}"
1.4660 -proof-
1.4661 +          and e[THEN spec[where x="x + (e/2) *\<^sub>R i"]]
1.4662 +        unfolding mem_interval
1.4663 +        using i
1.4664 +        by blast+
1.4665 +      then have "a \<bullet> i < x \<bullet> i" and "x \<bullet> i < b \<bullet> i"
1.4666 +        using `e>0` i
1.4667 +        by (auto simp: inner_diff_left inner_Basis inner_add_left)
1.4668 +    }
1.4669 +    then have "x \<in> {a<..<b}"
1.4670 +      unfolding mem_interval by auto
1.4671 +  }
1.4672 +  then show "?L \<subseteq> ?R" ..
1.4673 +qed
1.4674 +
1.4675 +lemma bounded_closed_interval:
1.4676 +  fixes a :: "'a::ordered_euclidean_space"
1.4677 +  shows "bounded {a .. b}"
1.4678 +proof -
1.4679    let ?b = "\<Sum>i\<in>Basis. \<bar>a\<bullet>i\<bar> + \<bar>b\<bullet>i\<bar>"
1.4680 -  { fix x::"'a" assume x:"\<forall>i\<in>Basis. a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i"
1.4681 -    { fix i :: 'a assume "i\<in>Basis"
1.4682 -      hence "\<bar>x\<bullet>i\<bar> \<le> \<bar>a\<bullet>i\<bar> + \<bar>b\<bullet>i\<bar>" using x[THEN bspec[where x=i]] by auto  }
1.4683 -    hence "(\<Sum>i\<in>Basis. \<bar>x \<bullet> i\<bar>) \<le> ?b" apply-apply(rule setsum_mono) by auto
1.4684 -    hence "norm x \<le> ?b" using norm_le_l1[of x] by auto  }
1.4685 -  thus ?thesis unfolding interval and bounded_iff by auto
1.4686 -qed
1.4687 -
1.4688 -lemma bounded_interval: fixes a :: "'a::ordered_euclidean_space" shows
1.4689 - "bounded {a .. b} \<and> bounded {a<..<b}"
1.4690 +  {
1.4691 +    fix x :: "'a"
1.4692 +    assume x: "\<forall>i\<in>Basis. a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i"
1.4693 +    {
1.4694 +      fix i :: 'a
1.4695 +      assume "i \<in> Basis"
1.4696 +      then have "\<bar>x\<bullet>i\<bar> \<le> \<bar>a\<bullet>i\<bar> + \<bar>b\<bullet>i\<bar>"
1.4697 +        using x[THEN bspec[where x=i]] by auto
1.4698 +    }
1.4699 +    then have "(\<Sum>i\<in>Basis. \<bar>x \<bullet> i\<bar>) \<le> ?b"
1.4700 +      apply -
1.4701 +      apply (rule setsum_mono)
1.4702 +      apply auto
1.4703 +      done
1.4704 +    then have "norm x \<le> ?b"
1.4705 +      using norm_le_l1[of x] by auto
1.4706 +  }
1.4707 +  then show ?thesis
1.4708 +    unfolding interval and bounded_iff by auto
1.4709 +qed
1.4710 +
1.4711 +lemma bounded_interval:
1.4712 +  fixes a :: "'a::ordered_euclidean_space"
1.4713 +  shows "bounded {a .. b} \<and> bounded {a<..<b}"
1.4714    using bounded_closed_interval[of a b]
1.4715    using interval_open_subset_closed[of a b]
1.4716    using bounded_subset[of "{a..b}" "{a<..<b}"]
1.4717    by simp
1.4718
1.4719 -lemma not_interval_univ: fixes a :: "'a::ordered_euclidean_space" shows
1.4720 - "({a .. b} \<noteq> UNIV) \<and> ({a<..<b} \<noteq> UNIV)"
1.4721 +lemma not_interval_univ:
1.4722 +  fixes a :: "'a::ordered_euclidean_space"
1.4723 +  shows "({a .. b} \<noteq> UNIV) \<and> ({a<..<b} \<noteq> UNIV)"
1.4724    using bounded_interval[of a b] by auto
1.4725
1.4726 -lemma compact_interval: fixes a :: "'a::ordered_euclidean_space" shows "compact {a .. b}"
1.4727 +lemma compact_interval:
1.4728 +  fixes a :: "'a::ordered_euclidean_space"
1.4729 +  shows "compact {a .. b}"
1.4730    using bounded_closed_imp_seq_compact[of "{a..b}"] using bounded_interval[of a b]
1.4731    by (auto simp: compact_eq_seq_compact_metric)
1.4732
1.4733 -lemma open_interval_midpoint: fixes a :: "'a::ordered_euclidean_space"
1.4734 -  assumes "{a<..<b} \<noteq> {}" shows "((1/2) *\<^sub>R (a + b)) \<in> {a<..<b}"
1.4735 -proof-
1.4736 -  { fix i :: 'a assume "i\<in>Basis"
1.4737 -    hence "a \<bullet> i < ((1 / 2) *\<^sub>R (a + b)) \<bullet> i \<and> ((1 / 2) *\<^sub>R (a + b)) \<bullet> i < b \<bullet> i"
1.4738 -      using assms[unfolded interval_ne_empty, THEN bspec[where x=i]] by (auto simp: inner_add_left)  }
1.4739 -  thus ?thesis unfolding mem_interval by auto
1.4740 -qed
1.4741 -
1.4742 -lemma open_closed_interval_convex: fixes x :: "'a::ordered_euclidean_space"
1.4743 -  assumes x:"x \<in> {a<..<b}" and y:"y \<in> {a .. b}" and e:"0 < e" "e \<le> 1"
1.4744 +lemma open_interval_midpoint:
1.4745 +  fixes a :: "'a::ordered_euclidean_space"
1.4746 +  assumes "{a<..<b} \<noteq> {}"
1.4747 +  shows "((1/2) *\<^sub>R (a + b)) \<in> {a<..<b}"
1.4748 +proof -
1.4749 +  {
1.4750 +    fix i :: 'a
1.4751 +    assume "i \<in> Basis"
1.4752 +    then have "a \<bullet> i < ((1 / 2) *\<^sub>R (a + b)) \<bullet> i \<and> ((1 / 2) *\<^sub>R (a + b)) \<bullet> i < b \<bullet> i"
1.4753 +      using assms[unfolded interval_ne_empty, THEN bspec[where x=i]] by (auto simp: inner_add_left)
1.4754 +  }
1.4755 +  then show ?thesis unfolding mem_interval by auto
1.4756 +qed
1.4757 +
1.4758 +lemma open_closed_interval_convex:
1.4759 +  fixes x :: "'a::ordered_euclidean_space"
1.4760 +  assumes x: "x \<in> {a<..<b}"
1.4761 +    and y: "y \<in> {a .. b}"
1.4762 +    and e: "0 < e" "e \<le> 1"
1.4763    shows "(e *\<^sub>R x + (1 - e) *\<^sub>R y) \<in> {a<..<b}"
1.4764 -proof-
1.4765 -  { fix i :: 'a assume i:"i\<in>Basis"
1.4766 -    have "a \<bullet> i = e * (a \<bullet> i) + (1 - e) * (a \<bullet> i)" unfolding left_diff_distrib by simp
1.4767 -    also have "\<dots> < e * (x \<bullet> i) + (1 - e) * (y \<bullet> i)" apply(rule add_less_le_mono)
1.4768 -      using e unfolding mult_less_cancel_left and mult_le_cancel_left apply simp_all
1.4769 -      using x unfolding mem_interval using i apply simp
1.4770 -      using y unfolding mem_interval using i apply simp
1.4771 +proof -
1.4772 +  {
1.4773 +    fix i :: 'a
1.4774 +    assume i: "i \<in> Basis"
1.4775 +    have "a \<bullet> i = e * (a \<bullet> i) + (1 - e) * (a \<bullet> i)"
1.4776 +      unfolding left_diff_distrib by simp
1.4777 +    also have "\<dots> < e * (x \<bullet> i) + (1 - e) * (y \<bullet> i)"
1.4778 +      apply (rule add_less_le_mono)
1.4779 +      using e unfolding mult_less_cancel_left and mult_le_cancel_left
1.4780 +      apply simp_all
1.4781 +      using x unfolding mem_interval using i
1.4782 +      apply simp
1.4783 +      using y unfolding mem_interval using i
1.4784 +      apply simp
1.4785        done
1.4786 -    finally have "a \<bullet> i < (e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i" unfolding inner_simps by auto
1.4787 -    moreover {
1.4788 -    have "b \<bullet> i = e * (b\<bullet>i) + (1 - e) * (b\<bullet>i)" unfolding left_diff_distrib by simp
1.4789 -    also have "\<dots> > e * (x \<bullet> i) + (1 - e) * (y \<bullet> i)" apply(rule add_less_le_mono)
1.4790 -      using e unfolding mult_less_cancel_left and mult_le_cancel_left apply simp_all
1.4791 -      using x unfolding mem_interval using i apply simp
1.4792 -      using y unfolding mem_interval using i apply simp
1.4793 -      done
1.4794 -    finally have "(e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i < b \<bullet> i" unfolding inner_simps by auto
1.4795 -    } ultimately have "a \<bullet> i < (e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i \<and> (e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i < b \<bullet> i" by auto }
1.4796 -  thus ?thesis unfolding mem_interval by auto
1.4797 -qed
1.4798 -
1.4799 -lemma closure_open_interval: fixes a :: "'a::ordered_euclidean_space"
1.4800 +    finally have "a \<bullet> i < (e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i"
1.4801 +      unfolding inner_simps by auto
1.4802 +    moreover
1.4803 +    {
1.4804 +      have "b \<bullet> i = e * (b\<bullet>i) + (1 - e) * (b\<bullet>i)"
1.4805 +        unfolding left_diff_distrib by simp
1.4806 +      also have "\<dots> > e * (x \<bullet> i) + (1 - e) * (y \<bullet> i)"
1.4807 +        apply (rule add_less_le_mono)
1.4808 +        using e unfolding mult_less_cancel_left and mult_le_cancel_left
1.4809 +        apply simp_all
1.4810 +        using x
1.4811 +        unfolding mem_interval
1.4812 +        using i
1.4813 +        apply simp
1.4814 +        using y
1.4815 +        unfolding mem_interval
1.4816 +        using i
1.4817 +        apply simp
1.4818 +        done
1.4819 +      finally have "(e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i < b \<bullet> i"
1.4820 +        unfolding inner_simps by auto
1.4821 +    }
1.4822 +    ultimately have "a \<bullet> i < (e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i \<and> (e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i < b \<bullet> i"
1.4823 +      by auto
1.4824 +  }
1.4825 +  then show ?thesis
1.4826 +    unfolding mem_interval by auto
1.4827 +qed
1.4828 +
1.4829 +lemma closure_open_interval:
1.4830 +  fixes a :: "'a::ordered_euclidean_space"
1.4831    assumes "{a<..<b} \<noteq> {}"
1.4832    shows "closure {a<..<b} = {a .. b}"
1.4833 -proof-
1.4834 -  have ab:"a < b" using assms[unfolded interval_ne_empty] apply(subst eucl_less) by auto
1.4835 +proof -
1.4836 +  have ab: "a < b"
1.4837 +    using assms[unfolded interval_ne_empty]
1.4838 +    apply (subst eucl_less)
1.4839 +    apply auto
1.4840 +    done
1.4841    let ?c = "(1 / 2) *\<^sub>R (a + b)"
1.4842 -  { fix x assume as:"x \<in> {a .. b}"
1.4843 -    def f == "\<lambda>n::nat. x + (inverse (real n + 1)) *\<^sub>R (?c - x)"
1.4844 -    { fix n assume fn:"f n < b \<longrightarrow> a < f n \<longrightarrow> f n = x" and xc:"x \<noteq> ?c"
1.4845 -      have *:"0 < inverse (real n + 1)" "inverse (real n + 1) \<le> 1" unfolding inverse_le_1_iff by auto
1.4846 +  {
1.4847 +    fix x
1.4848 +    assume as:"x \<in> {a .. b}"
1.4849 +    def f \<equiv> "\<lambda>n::nat. x + (inverse (real n + 1)) *\<^sub>R (?c - x)"
1.4850 +    {
1.4851 +      fix n
1.4852 +      assume fn: "f n < b \<longrightarrow> a < f n \<longrightarrow> f n = x" and xc: "x \<noteq> ?c"
1.4853 +      have *: "0 < inverse (real n + 1)" "inverse (real n + 1) \<le> 1"
1.4854 +        unfolding inverse_le_1_iff by auto
1.4855        have "(inverse (real n + 1)) *\<^sub>R ((1 / 2) *\<^sub>R (a + b)) + (1 - inverse (real n + 1)) *\<^sub>R x =
1.4856          x + (inverse (real n + 1)) *\<^sub>R (((1 / 2) *\<^sub>R (a + b)) - x)"
1.4857          by (auto simp add: algebra_simps)
1.4858 -      hence "f n < b" and "a < f n" using open_closed_interval_convex[OF open_interval_midpoint[OF assms] as *] unfolding f_def by auto
1.4859 -      hence False using fn unfolding f_def using xc by auto  }
1.4860 +      then have "f n < b" and "a < f n"
1.4861 +        using open_closed_interval_convex[OF open_interval_midpoint[OF assms] as *]
1.4862 +        unfolding f_def by auto
1.4863 +      then have False
1.4864 +        using fn unfolding f_def using xc by auto
1.4865 +    }
1.4866      moreover
1.4867 -    { assume "\<not> (f ---> x) sequentially"
1.4868 -      { fix e::real assume "e>0"
1.4869 -        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
1.4870 -        then obtain N::nat where "inverse (real (N + 1)) < e" by auto
1.4871 -        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)
1.4872 -        hence "\<exists>N::nat. \<forall>n\<ge>N. inverse (real n + 1) < e" by auto  }
1.4873 -      hence "((\<lambda>n. inverse (real n + 1)) ---> 0) sequentially"
1.4874 +    {
1.4875 +      assume "\<not> (f ---> x) sequentially"
1.4876 +      {
1.4877 +        fix e :: real
1.4878 +        assume "e > 0"
1.4879 +        then have "\<exists>N::nat. inverse (real (N + 1)) < e"
1.4880 +          using real_arch_inv[of e]
1.4881 +          apply (auto simp add: Suc_pred')
1.4882 +          apply (rule_tac x="n - 1" in exI)
1.4883 +          apply auto
1.4884 +          done
1.4885 +        then obtain N :: nat where "inverse (real (N + 1)) < e"
1.4886 +          by auto
1.4887 +        then have "\<forall>n\<ge>N. inverse (real n + 1) < e"
1.4888 +          apply auto
1.4889 +          apply (metis Suc_le_mono le_SucE less_imp_inverse_less nat_le_real_less order_less_trans
1.4890 +            real_of_nat_Suc real_of_nat_Suc_gt_zero)
1.4891 +          done
1.4892 +        then have "\<exists>N::nat. \<forall>n\<ge>N. inverse (real n + 1) < e" by auto
1.4893 +      }
1.4894 +      then have "((\<lambda>n. inverse (real n + 1)) ---> 0) sequentially"
1.4895          unfolding LIMSEQ_def by(auto simp add: dist_norm)
1.4896 -      hence "(f ---> x) sequentially" unfolding f_def
1.4897 +      then have "(f ---> x) sequentially"
1.4898 +        unfolding f_def
1.4899          using tendsto_add[OF tendsto_const, of "\<lambda>n::nat. (inverse (real n + 1)) *\<^sub>R ((1 / 2) *\<^sub>R (a + b) - x)" 0 sequentially x]
1.4900 -        using tendsto_scaleR [OF _ tendsto_const, of "\<lambda>n::nat. inverse (real n + 1)" 0 sequentially "((1 / 2) *\<^sub>R (a + b) - x)"] by auto  }
1.4901 +        using tendsto_scaleR [OF _ tendsto_const, of "\<lambda>n::nat. inverse (real n + 1)" 0 sequentially "((1 / 2) *\<^sub>R (a + b) - x)"]
1.4902 +        by auto
1.4903 +    }
1.4904      ultimately have "x \<in> closure {a<..<b}"
1.4905 -      using as and open_interval_midpoint[OF assms] unfolding closure_def unfolding islimpt_sequential by(cases "x=?c")auto  }
1.4906 -  thus ?thesis using closure_minimal[OF interval_open_subset_closed closed_interval, of a b] by blast
1.4907 -qed
1.4908 -
1.4909 -lemma bounded_subset_open_interval_symmetric: fixes s::"('a::ordered_euclidean_space) set"
1.4910 -  assumes "bounded s"  shows "\<exists>a. s \<subseteq> {-a<..<a}"
1.4911 -proof-
1.4912 -  obtain b where "b>0" and b:"\<forall>x\<in>s. norm x \<le> b" using assms[unfolded bounded_pos] by auto
1.4913 +      using as and open_interval_midpoint[OF assms]
1.4914 +      unfolding closure_def
1.4915 +      unfolding islimpt_sequential
1.4916 +      by (cases "x=?c") auto
1.4917 +  }
1.4918 +  then show ?thesis
1.4919 +    using closure_minimal[OF interval_open_subset_closed closed_interval, of a b] by blast
1.4920 +qed
1.4921 +
1.4922 +lemma bounded_subset_open_interval_symmetric:
1.4923 +  fixes s::"('a::ordered_euclidean_space) set"
1.4924 +  assumes "bounded s"
1.4925 +  shows "\<exists>a. s \<subseteq> {-a<..<a}"
1.4926 +proof -
1.4927 +  obtain b where "b>0" and b: "\<forall>x\<in>s. norm x \<le> b"
1.4928 +    using assms[unfolded bounded_pos] by auto
1.4929    def a \<equiv> "(\<Sum>i\<in>Basis. (b + 1) *\<^sub>R i)::'a"
1.4930 -  { fix x assume "x\<in>s"
1.4931 -    fix i :: 'a assume i:"i\<in>Basis"
1.4932 -    hence "(-a)\<bullet>i < x\<bullet>i" and "x\<bullet>i < a\<bullet>i" using b[THEN bspec[where x=x], OF `x\<in>s`]
1.4933 -      and Basis_le_norm[OF i, of x] unfolding inner_simps and a_def by auto }
1.4934 -  thus ?thesis by(auto intro: exI[where x=a] simp add: eucl_less[where 'a='a])
1.4935 +  {
1.4936 +    fix x
1.4937 +    assume "x \<in> s"
1.4938 +    fix i :: 'a
1.4939 +    assume i: "i \<in> Basis"
1.4940 +    then have "(-a)\<bullet>i < x\<bullet>i" and "x\<bullet>i < a\<bullet>i"
1.4941 +      using b[THEN bspec[where x=x], OF `x\<in>s`]
1.4942 +      using Basis_le_norm[OF i, of x]
1.4943 +      unfolding inner_simps and a_def
1.4944 +      by auto
1.4945 +  }
1.4946 +  then show ?thesis
1.4947 +    by (auto intro: exI[where x=a] simp add: eucl_less[where 'a='a])
1.4948  qed
1.4949
1.4950  lemma bounded_subset_open_interval:
1.4951 @@ -5608,14 +6468,16 @@
1.4952  lemma bounded_subset_closed_interval_symmetric:
1.4953    fixes s :: "('a::ordered_euclidean_space) set"
1.4954    assumes "bounded s" shows "\<exists>a. s \<subseteq> {-a .. a}"
1.4955 -proof-
1.4956 -  obtain a where "s \<subseteq> {- a<..<a}" using bounded_subset_open_interval_symmetric[OF assms] by auto
1.4957 -  thus ?thesis using interval_open_subset_closed[of "-a" a] by auto
1.4958 +proof -
1.4959 +  obtain a where "s \<subseteq> {- a<..<a}"
1.4960 +    using bounded_subset_open_interval_symmetric[OF assms] by auto
1.4961 +  then show ?thesis
1.4962 +    using interval_open_subset_closed[of "-a" a] by auto
1.4963  qed
1.4964
1.4965  lemma bounded_subset_closed_interval:
1.4966    fixes s :: "('a::ordered_euclidean_space) set"
1.4967 -  shows "bounded s ==> (\<exists>a b. s \<subseteq> {a .. b})"
1.4968 +  shows "bounded s \<Longrightarrow> (\<exists>a b. s \<subseteq> {a .. b})"
1.4969    using bounded_subset_closed_interval_symmetric[of s] by auto
1.4970
1.4971  lemma frontier_closed_interval:
1.4972 @@ -5626,44 +6488,74 @@
1.4973  lemma frontier_open_interval:
1.4974    fixes a b :: "'a::ordered_euclidean_space"
1.4975    shows "frontier {a<..<b} = (if {a<..<b} = {} then {} else {a .. b} - {a<..<b})"
1.4976 -proof(cases "{a<..<b} = {}")
1.4977 -  case True thus ?thesis using frontier_empty by auto
1.4978 +proof (cases "{a<..<b} = {}")
1.4979 +  case True
1.4980 +  then show ?thesis
1.4981 +    using frontier_empty by auto
1.4982  next
1.4983 -  case False thus ?thesis unfolding frontier_def and closure_open_interval[OF False] and interior_open[OF open_interval] by auto
1.4984 -qed
1.4985 -
1.4986 -lemma inter_interval_mixed_eq_empty: fixes a :: "'a::ordered_euclidean_space"
1.4987 -  assumes "{c<..<d} \<noteq> {}"  shows "{a<..<b} \<inter> {c .. d} = {} \<longleftrightarrow> {a<..<b} \<inter> {c<..<d} = {}"
1.4988 -  unfolding closure_open_interval[OF assms, THEN sym] unfolding open_inter_closure_eq_empty[OF open_interval] ..
1.4989 +  case False
1.4990 +  then show ?thesis
1.4991 +    unfolding frontier_def and closure_open_interval[OF False] and interior_open[OF open_interval]
1.4992 +    by auto
1.4993 +qed
1.4994 +
1.4995 +lemma inter_interval_mixed_eq_empty:
1.4996 +  fixes a :: "'a::ordered_euclidean_space"
1.4997 +  assumes "{c<..<d} \<noteq> {}"
1.4998 +  shows "{a<..<b} \<inter> {c .. d} = {} \<longleftrightarrow> {a<..<b} \<inter> {c<..<d} = {}"
1.4999 +  unfolding closure_open_interval[OF assms, THEN sym]
1.5000 +  unfolding open_inter_closure_eq_empty[OF open_interval] ..
1.5001
1.5002
1.5003  (* Some stuff for half-infinite intervals too; FIXME: notation?  *)
1.5004
1.5005 -lemma closed_interval_left: fixes b::"'a::euclidean_space"
1.5006 +lemma closed_interval_left:
1.5007 +  fixes b :: "'a::euclidean_space"
1.5008    shows "closed {x::'a. \<forall>i\<in>Basis. x\<bullet>i \<le> b\<bullet>i}"
1.5009 -proof-
1.5010 -  { fix i :: 'a assume i:"i\<in>Basis"
1.5011 -    fix x::"'a" assume x:"\<forall>e>0. \<exists>x'\<in>{x. \<forall>i\<in>Basis. x \<bullet> i \<le> b \<bullet> i}. x' \<noteq> x \<and> dist x' x < e"
1.5012 -    { assume "x\<bullet>i > b\<bullet>i"
1.5013 +proof -
1.5014 +  {
1.5015 +    fix i :: 'a
1.5016 +    assume i: "i \<in> Basis"
1.5017 +    fix x :: "'a"
1.5018 +    assume x: "\<forall>e>0. \<exists>x'\<in>{x. \<forall>i\<in>Basis. x \<bullet> i \<le> b \<bullet> i}. x' \<noteq> x \<and> dist x' x < e"
1.5019 +    {
1.5020 +      assume "x\<bullet>i > b\<bullet>i"
1.5021        then obtain y where "y \<bullet> i \<le> b \<bullet> i"  "y \<noteq> x"  "dist y x < x\<bullet>i - b\<bullet>i"
1.5022          using x[THEN spec[where x="x\<bullet>i - b\<bullet>i"]] using i by auto
1.5023 -      hence False using Basis_le_norm[OF i, of "y - x"] unfolding dist_norm inner_simps using i
1.5024 -        by auto }
1.5025 -    hence "x\<bullet>i \<le> b\<bullet>i" by(rule ccontr)auto  }
1.5026 -  thus ?thesis unfolding closed_limpt unfolding islimpt_approachable by blast
1.5027 -qed
1.5028 -
1.5029 -lemma closed_interval_right: fixes a::"'a::euclidean_space"
1.5030 +      then have False
1.5031 +        using Basis_le_norm[OF i, of "y - x"]
1.5032 +        unfolding dist_norm inner_simps
1.5033 +        using i
1.5034 +        by auto
1.5035 +    }
1.5036 +    then have "x\<bullet>i \<le> b\<bullet>i" by (rule ccontr)auto
1.5037 +  }
1.5038 +  then show ?thesis
1.5039 +    unfolding closed_limpt unfolding islimpt_approachable by blast
1.5040 +qed
1.5041 +
1.5042 +lemma closed_interval_right:
1.5043 +  fixes a :: "'a::euclidean_space"
1.5044    shows "closed {x::'a. \<forall>i\<in>Basis. a\<bullet>i \<le> x\<bullet>i}"
1.5045 -proof-
1.5046 -  { fix i :: 'a assume i:"i\<in>Basis"
1.5047 -    fix x::"'a" assume x:"\<forall>e>0. \<exists>x'\<in>{x. \<forall>i\<in>Basis. a \<bullet> i \<le> x \<bullet> i}. x' \<noteq> x \<and> dist x' x < e"
1.5048 -    { assume "a\<bullet>i > x\<bullet>i"
1.5049 +proof -
1.5050 +  {
1.5051 +    fix i :: 'a
1.5052 +    assume i: "i \<in> Basis"
1.5053 +    fix x :: "'a"
1.5054 +    assume x: "\<forall>e>0. \<exists>x'\<in>{x. \<forall>i\<in>Basis. a \<bullet> i \<le> x \<bullet> i}. x' \<noteq> x \<and> dist x' x < e"
1.5055 +    {
1.5056 +      assume "a\<bullet>i > x\<bullet>i"
1.5057        then obtain y where "a \<bullet> i \<le> y \<bullet> i"  "y \<noteq> x"  "dist y x < a\<bullet>i - x\<bullet>i"
1.5058          using x[THEN spec[where x="a\<bullet>i - x\<bullet>i"]] i by auto
1.5059 -      hence False using Basis_le_norm[OF i, of "y - x"] unfolding dist_norm inner_simps by auto }
1.5060 -    hence "a\<bullet>i \<le> x\<bullet>i" by(rule ccontr)auto  }
1.5061 -  thus ?thesis unfolding closed_limpt unfolding islimpt_approachable by blast
1.5062 +      then have False
1.5063 +        using Basis_le_norm[OF i, of "y - x"]
1.5064 +        unfolding dist_norm inner_simps
1.5065 +        by auto
1.5066 +    }
1.5067 +    then have "a\<bullet>i \<le> x\<bullet>i" by (rule ccontr) auto
1.5068 +  }
1.5069 +  then show ?thesis
1.5070 +    unfolding closed_limpt unfolding islimpt_approachable by blast
1.5071  qed
1.5072
1.5073  lemma open_box: "open (box a b)"
1.5074 @@ -5678,15 +6570,18 @@
1.5075  instance euclidean_space \<subseteq> second_countable_topology
1.5076  proof
1.5077    def a \<equiv> "\<lambda>f :: 'a \<Rightarrow> (real \<times> real). \<Sum>i\<in>Basis. fst (f i) *\<^sub>R i"
1.5078 -  then have a: "\<And>f. (\<Sum>i\<in>Basis. fst (f i) *\<^sub>R i) = a f" by simp
1.5079 +  then have a: "\<And>f. (\<Sum>i\<in>Basis. fst (f i) *\<^sub>R i) = a f"
1.5080 +    by simp
1.5081    def b \<equiv> "\<lambda>f :: 'a \<Rightarrow> (real \<times> real). \<Sum>i\<in>Basis. snd (f i) *\<^sub>R i"
1.5082 -  then have b: "\<And>f. (\<Sum>i\<in>Basis. snd (f i) *\<^sub>R i) = b f" by simp
1.5083 +  then have b: "\<And>f. (\<Sum>i\<in>Basis. snd (f i) *\<^sub>R i) = b f"
1.5084 +    by simp
1.5085    def B \<equiv> "(\<lambda>f. box (a f) (b f)) ` (Basis \<rightarrow>\<^sub>E (\<rat> \<times> \<rat>))"
1.5086
1.5087    have "Ball B open" by (simp add: B_def open_box)
1.5088    moreover have "(\<forall>A. open A \<longrightarrow> (\<exists>B'\<subseteq>B. \<Union>B' = A))"
1.5089    proof safe
1.5090 -    fix A::"'a set" assume "open A"
1.5091 +    fix A::"'a set"
1.5092 +    assume "open A"
1.5093      show "\<exists>B'\<subseteq>B. \<Union>B' = A"
1.5094        apply (rule exI[of _ "{b\<in>B. b \<subseteq> A}"])
1.5095        apply (subst (3) open_UNION_box[OF `open A`])
1.5096 @@ -5694,9 +6589,11 @@
1.5097        done
1.5098    qed
1.5099    ultimately
1.5100 -  have "topological_basis B" unfolding topological_basis_def by blast
1.5101 +  have "topological_basis B"
1.5102 +    unfolding topological_basis_def by blast
1.5103    moreover
1.5104 -  have "countable B" unfolding B_def
1.5105 +  have "countable B"
1.5106 +    unfolding B_def
1.5107      by (intro countable_image countable_PiE finite_Basis countable_SIGMA countable_rat)
1.5108    ultimately show "\<exists>B::'a set set. countable B \<and> open = generate_topology B"
1.5109      by (blast intro: topological_basis_imp_subbasis)
1.5110 @@ -5728,25 +6625,29 @@
1.5111  subsection {* Closure of halfspaces and hyperplanes *}
1.5112
1.5113  lemma isCont_open_vimage:
1.5114 -  assumes "\<And>x. isCont f x" and "open s" shows "open (f -` s)"
1.5115 +  assumes "\<And>x. isCont f x"
1.5116 +    and "open s"
1.5117 +  shows "open (f -` s)"
1.5118  proof -
1.5119    from assms(1) have "continuous_on UNIV f"
1.5120      unfolding isCont_def continuous_on_def by simp
1.5121 -  hence "open {x \<in> UNIV. f x \<in> s}"
1.5122 +  then have "open {x \<in> UNIV. f x \<in> s}"
1.5123      using open_UNIV `open s` by (rule continuous_open_preimage)
1.5124 -  thus "open (f -` s)"
1.5125 +  then show "open (f -` s)"
1.5126      by (simp add: vimage_def)
1.5127  qed
1.5128
1.5129  lemma isCont_closed_vimage:
1.5130 -  assumes "\<And>x. isCont f x" and "closed s" shows "closed (f -` s)"
1.5131 +  assumes "\<And>x. isCont f x"
1.5132 +    and "closed s"
1.5133 +  shows "closed (f -` s)"
1.5134    using assms unfolding closed_def vimage_Compl [symmetric]
1.5135    by (rule isCont_open_vimage)
1.5136
1.5137  lemma open_Collect_less:
1.5138    fixes f g :: "'a::t2_space \<Rightarrow> real"
1.5139    assumes f: "\<And>x. isCont f x"
1.5140 -  assumes g: "\<And>x. isCont g x"
1.5141 +    and g: "\<And>x. isCont g x"
1.5142    shows "open {x. f x < g x}"
1.5143  proof -
1.5144    have "open ((\<lambda>x. g x - f x) -` {0<..})"
1.5145 @@ -5760,7 +6661,7 @@
1.5146  lemma closed_Collect_le:
1.5147    fixes f g :: "'a::t2_space \<Rightarrow> real"
1.5148    assumes f: "\<And>x. isCont f x"
1.5149 -  assumes g: "\<And>x. isCont g x"
1.5150 +    and g: "\<And>x. isCont g x"
1.5151    shows "closed {x. f x \<le> g x}"
1.5152  proof -
1.5153    have "closed ((\<lambda>x. g x - f x) -` {0..})"
1.5154 @@ -5774,12 +6675,12 @@
1.5155  lemma closed_Collect_eq:
1.5156    fixes f g :: "'a::t2_space \<Rightarrow> 'b::t2_space"
1.5157    assumes f: "\<And>x. isCont f x"
1.5158 -  assumes g: "\<And>x. isCont g x"
1.5159 +    and g: "\<And>x. isCont g x"
1.5160    shows "closed {x. f x = g x}"
1.5161  proof -
1.5162    have "open {(x::'b, y::'b). x \<noteq> y}"
1.5163      unfolding open_prod_def by (auto dest!: hausdorff)
1.5164 -  hence "closed {(x::'b, y::'b). x = y}"
1.5165 +  then have "closed {(x::'b, y::'b). x = y}"
1.5166      unfolding closed_def split_def Collect_neg_eq .
1.5167    with isCont_Pair [OF f g]
1.5168    have "closed ((\<lambda>x. (f x, g x)) -` {(x, y). x = y})"
1.5169 @@ -5800,12 +6701,10 @@
1.5170  lemma closed_hyperplane: "closed {x. inner a x = b}"
1.5171    by (simp add: closed_Collect_eq)
1.5172
1.5173 -lemma closed_halfspace_component_le:
1.5174 -  shows "closed {x::'a::euclidean_space. x\<bullet>i \<le> a}"
1.5175 +lemma closed_halfspace_component_le: "closed {x::'a::euclidean_space. x\<bullet>i \<le> a}"
1.5176    by (simp add: closed_Collect_le)
1.5177
1.5178 -lemma closed_halfspace_component_ge:
1.5179 -  shows "closed {x::'a::euclidean_space. x\<bullet>i \<ge> a}"
1.5180 +lemma closed_halfspace_component_ge: "closed {x::'a::euclidean_space. x\<bullet>i \<ge> a}"
1.5181    by (simp add: closed_Collect_le)
1.5182
1.5183  text {* Openness of halfspaces. *}
1.5184 @@ -5816,12 +6715,10 @@
1.5185  lemma open_halfspace_gt: "open {x. inner a x > b}"
1.5186    by (simp add: open_Collect_less)
1.5187
1.5188 -lemma open_halfspace_component_lt:
1.5189 -  shows "open {x::'a::euclidean_space. x\<bullet>i < a}"
1.5190 +lemma open_halfspace_component_lt: "open {x::'a::euclidean_space. x\<bullet>i < a}"
1.5191    by (simp add: open_Collect_less)
1.5192
1.5193 -lemma open_halfspace_component_gt:
1.5194 -  shows "open {x::'a::euclidean_space. x\<bullet>i > a}"
1.5195 +lemma open_halfspace_component_gt: "open {x::'a::euclidean_space. x\<bullet>i > a}"
1.5196    by (simp add: open_Collect_less)
1.5197
1.5198  text{* Instantiation for intervals on @{text ordered_euclidean_space} *}
1.5199 @@ -5829,22 +6726,22 @@
1.5200  lemma eucl_lessThan_eq_halfspaces:
1.5201    fixes a :: "'a\<Colon>ordered_euclidean_space"
1.5202    shows "{..<a} = (\<Inter>i\<in>Basis. {x. x \<bullet> i < a \<bullet> i})"
1.5203 - by (auto simp: eucl_less[where 'a='a])
1.5204 +  by (auto simp: eucl_less[where 'a='a])
1.5205
1.5206  lemma eucl_greaterThan_eq_halfspaces:
1.5207    fixes a :: "'a\<Colon>ordered_euclidean_space"
1.5208    shows "{a<..} = (\<Inter>i\<in>Basis. {x. a \<bullet> i < x \<bullet> i})"
1.5209 - by (auto simp: eucl_less[where 'a='a])
1.5210 +  by (auto simp: eucl_less[where 'a='a])
1.5211
1.5212  lemma eucl_atMost_eq_halfspaces:
1.5213    fixes a :: "'a\<Colon>ordered_euclidean_space"
1.5214    shows "{.. a} = (\<Inter>i\<in>Basis. {x. x \<bullet> i \<le> a \<bullet> i})"
1.5215 - by (auto simp: eucl_le[where 'a='a])
1.5216 +  by (auto simp: eucl_le[where 'a='a])
1.5217
1.5218  lemma eucl_atLeast_eq_halfspaces:
1.5219    fixes a :: "'a\<Colon>ordered_euclidean_space"
1.5220    shows "{a ..} = (\<Inter>i\<in>Basis. {x. a \<bullet> i \<le> x \<bullet> i})"
1.5221 - by (auto simp: eucl_le[where 'a='a])
1.5222 +  by (auto simp: eucl_le[where 'a='a])
1.5223
1.5224  lemma open_eucl_lessThan[simp, intro]:
1.5225    fixes a :: "'a\<Colon>ordered_euclidean_space"
1.5226 @@ -5870,26 +6767,37 @@
1.5227
1.5228  text {* This gives a simple derivation of limit component bounds. *}
1.5229
1.5230 -lemma Lim_component_le: fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
1.5231 -  assumes "(f ---> l) net" "\<not> (trivial_limit net)"  "eventually (\<lambda>x. f(x)\<bullet>i \<le> b) net"
1.5232 +lemma Lim_component_le:
1.5233 +  fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
1.5234 +  assumes "(f ---> l) net"
1.5235 +    and "\<not> (trivial_limit net)"
1.5236 +    and "eventually (\<lambda>x. f(x)\<bullet>i \<le> b) net"
1.5237    shows "l\<bullet>i \<le> b"
1.5238    by (rule tendsto_le[OF assms(2) tendsto_const tendsto_inner[OF assms(1) tendsto_const] assms(3)])
1.5239
1.5240 -lemma Lim_component_ge: fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
1.5241 -  assumes "(f ---> l) net"  "\<not> (trivial_limit net)"  "eventually (\<lambda>x. b \<le> (f x)\<bullet>i) net"
1.5242 +lemma Lim_component_ge:
1.5243 +  fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
1.5244 +  assumes "(f ---> l) net"
1.5245 +    and "\<not> (trivial_limit net)"
1.5246 +    and "eventually (\<lambda>x. b \<le> (f x)\<bullet>i) net"
1.5247    shows "b \<le> l\<bullet>i"
1.5248    by (rule tendsto_le[OF assms(2) tendsto_inner[OF assms(1) tendsto_const] tendsto_const assms(3)])
1.5249
1.5250 -lemma Lim_component_eq: fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
1.5251 -  assumes net:"(f ---> l) net" "~(trivial_limit net)" and ev:"eventually (\<lambda>x. f(x)\<bullet>i = b) net"
1.5252 +lemma Lim_component_eq:
1.5253 +  fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
1.5254 +  assumes net: "(f ---> l) net" "~(trivial_limit net)"
1.5255 +    and ev:"eventually (\<lambda>x. f(x)\<bullet>i = b) net"
1.5256    shows "l\<bullet>i = b"
1.5257    using ev[unfolded order_eq_iff eventually_conj_iff]
1.5258 -  using Lim_component_ge[OF net, of b i] and Lim_component_le[OF net, of i b] by auto
1.5259 -
1.5260 -text{* Limits relative to a union.                                               *}
1.5261 +  using Lim_component_ge[OF net, of b i]
1.5262 +  using Lim_component_le[OF net, of i b]
1.5263 +  by auto
1.5264 +
1.5265 +text {* Limits relative to a union. *}
1.5266
1.5267  lemma eventually_within_Un:
1.5268 -  "eventually P (at x within (s \<union> t)) \<longleftrightarrow> eventually P (at x within s) \<and> eventually P (at x within t)"
1.5269 +  "eventually P (at x within (s \<union> t)) \<longleftrightarrow>
1.5270 +    eventually P (at x within s) \<and> eventually P (at x within t)"
1.5271    unfolding eventually_at_filter
1.5272    by (auto elim!: eventually_rev_mp)
1.5273
1.5274 @@ -5900,25 +6808,27 @@
1.5275    by (auto simp add: eventually_within_Un)
1.5276
1.5277  lemma Lim_topological:
1.5278 - "(f ---> l) net \<longleftrightarrow>
1.5279 -        trivial_limit net \<or>
1.5280 -        (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) net)"
1.5281 +  "(f ---> l) net \<longleftrightarrow>
1.5282 +    trivial_limit net \<or> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) net)"
1.5283    unfolding tendsto_def trivial_limit_eq by auto
1.5284
1.5285 -text{* Some more convenient intermediate-value theorem formulations.             *}
1.5286 +text{* Some more convenient intermediate-value theorem formulations. *}
1.5287
1.5288  lemma connected_ivt_hyperplane:
1.5289    assumes "connected s" "x \<in> s" "y \<in> s" "inner a x \<le> b" "b \<le> inner a y"
1.5290    shows "\<exists>z \<in> s. inner a z = b"
1.5291 -proof(rule ccontr)
1.5292 +proof (rule ccontr)
1.5293    assume as:"\<not> (\<exists>z\<in>s. inner a z = b)"
1.5294    let ?A = "{x. inner a x < b}"
1.5295    let ?B = "{x. inner a x > b}"
1.5296 -  have "open ?A" "open ?B" using open_halfspace_lt and open_halfspace_gt by auto
1.5297 +  have "open ?A" "open ?B"
1.5298 +    using open_halfspace_lt and open_halfspace_gt by auto
1.5299    moreover have "?A \<inter> ?B = {}" by auto
1.5300    moreover have "s \<subseteq> ?A \<union> ?B" using as by auto
1.5301    ultimately show False
1.5302 -    using assms(1)[unfolded connected_def not_ex, THEN spec[where x="?A"], THEN spec[where x="?B"]] and assms(2-5)
1.5303 +    using assms(1)[unfolded connected_def not_ex,
1.5304 +      THEN spec[where x="?A"], THEN spec[where x="?B"]]
1.5305 +    using assms(2-5)
1.5306      by auto
1.5307  qed
1.5308
1.5309 @@ -5939,38 +6849,38 @@
1.5310
1.5311  definition
1.5312    homeomorphic :: "'a::topological_space set \<Rightarrow> 'b::topological_space set \<Rightarrow> bool"
1.5313 -    (infixr "homeomorphic" 60) where
1.5314 -  "s homeomorphic t \<equiv> (\<exists>f g. homeomorphism s t f g)"
1.5315 +    (infixr "homeomorphic" 60)
1.5316 +  where "s homeomorphic t \<equiv> (\<exists>f g. homeomorphism s t f g)"
1.5317
1.5318  lemma homeomorphic_refl: "s homeomorphic s"
1.5319    unfolding homeomorphic_def
1.5320    unfolding homeomorphism_def
1.5321    using continuous_on_id
1.5322 -  apply(rule_tac x = "(\<lambda>x. x)" in exI)
1.5323 -  apply(rule_tac x = "(\<lambda>x. x)" in exI)
1.5324 +  apply (rule_tac x = "(\<lambda>x. x)" in exI)
1.5325 +  apply (rule_tac x = "(\<lambda>x. x)" in exI)
1.5326    apply blast
1.5327    done
1.5328
1.5329  lemma homeomorphic_sym: "s homeomorphic t \<longleftrightarrow> t homeomorphic s"
1.5330    unfolding homeomorphic_def
1.5331    unfolding homeomorphism_def
1.5332 -  by blast
1.5333 +  by blast
1.5334
1.5335  lemma homeomorphic_trans:
1.5336 -  assumes "s homeomorphic t" "t homeomorphic u"
1.5337 +  assumes "s homeomorphic t"
1.5338 +    and "t homeomorphic u"
1.5339    shows "s homeomorphic u"
1.5340 -proof-
1.5341 -  obtain f1 g1 where fg1:"\<forall>x\<in>s. g1 (f1 x) = x"  "f1 ` s = t"
1.5342 -      "continuous_on s f1" "\<forall>y\<in>t. f1 (g1 y) = y" "g1 ` t = s" "continuous_on t g1"
1.5343 +proof -
1.5344 +  obtain f1 g1 where fg1: "\<forall>x\<in>s. g1 (f1 x) = x"  "f1 ` s = t"
1.5345 +    "continuous_on s f1" "\<forall>y\<in>t. f1 (g1 y) = y" "g1 ` t = s" "continuous_on t g1"
1.5346      using assms(1) unfolding homeomorphic_def homeomorphism_def by auto
1.5347 -  obtain f2 g2 where fg2:"\<forall>x\<in>t. g2 (f2 x) = x"  "f2 ` t = u" "continuous_on t f2"
1.5348 -      "\<forall>y\<in>u. f2 (g2 y) = y" "g2 ` u = t" "continuous_on u g2"
1.5349 +  obtain f2 g2 where fg2: "\<forall>x\<in>t. g2 (f2 x) = x"  "f2 ` t = u" "continuous_on t f2"
1.5350 +    "\<forall>y\<in>u. f2 (g2 y) = y" "g2 ` u = t" "continuous_on u g2"
1.5351      using assms(2) unfolding homeomorphic_def homeomorphism_def by auto
1.5352 -
1.5353    {
1.5354      fix x
1.5355      assume "x\<in>s"
1.5356 -    hence "(g1 \<circ> g2) ((f2 \<circ> f1) x) = x"
1.5357 +    then have "(g1 \<circ> g2) ((f2 \<circ> f1) x) = x"
1.5358        using fg1(1)[THEN bspec[where x=x]] and fg2(1)[THEN bspec[where x="f1 x"]] and fg1(2)
1.5359        by auto
1.5360    }
1.5361 @@ -5978,10 +6888,11 @@
1.5362      using fg1(2) fg2(2) by auto
1.5363    moreover have "continuous_on s (f2 \<circ> f1)"
1.5364      using continuous_on_compose[OF fg1(3)] and fg2(3) unfolding fg1(2) by auto
1.5365 -  moreover {
1.5366 +  moreover
1.5367 +  {
1.5368      fix y
1.5369      assume "y\<in>u"
1.5370 -    hence "(f2 \<circ> f1) ((g1 \<circ> g2) y) = y"
1.5371 +    then have "(f2 \<circ> f1) ((g1 \<circ> g2) y) = y"
1.5372        using fg2(4)[THEN bspec[where x=y]] and fg1(4)[THEN bspec[where x="g2 y"]] and fg2(5)
1.5373        by auto
1.5374    }
1.5375 @@ -6030,17 +6941,19 @@
1.5376    fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
1.5377    assumes "compact s" "continuous_on s f"  "f ` s = t"  "inj_on f s"
1.5378    shows "\<exists>g. homeomorphism s t f g"
1.5379 -proof-
1.5380 +proof -
1.5381    def g \<equiv> "\<lambda>x. SOME y. y\<in>s \<and> f y = x"
1.5382    have g: "\<forall>x\<in>s. g (f x) = x"
1.5383      using assms(3) assms(4)[unfolded inj_on_def] unfolding g_def by auto
1.5384    {
1.5385 -    fix y assume "y\<in>t"
1.5386 -    then obtain x where x:"f x = y" "x\<in>s" using assms(3) by auto
1.5387 -    hence "g (f x) = x" using g by auto
1.5388 -    hence "f (g y) = y" unfolding x(1)[THEN sym] by auto
1.5389 +    fix y
1.5390 +    assume "y \<in> t"
1.5391 +    then obtain x where x:"f x = y" "x\<in>s"
1.5392 +      using assms(3) by auto
1.5393 +    then have "g (f x) = x" using g by auto
1.5394 +    then have "f (g y) = y" unfolding x(1)[THEN sym] by auto
1.5395    }
1.5396 -  hence g':"\<forall>x\<in>t. f (g x) = x" by auto
1.5397 +  then have g':"\<forall>x\<in>t. f (g x) = x" by auto
1.5398    moreover
1.5399    {
1.5400      fix x
1.5401 @@ -6055,7 +6968,7 @@
1.5402        then obtain y where y:"y\<in>t" "g y = x" by auto
1.5403        then obtain x' where x':"x'\<in>s" "f x' = y"
1.5404          using assms(3) by auto
1.5405 -      hence "x \<in> s"
1.5406 +      then have "x \<in> s"
1.5407          unfolding g_def
1.5408          using someI2[of "\<lambda>b. b\<in>s \<and> f b = y" x' "\<lambda>x. x\<in>s"]
1.5409          unfolding y(2)[THEN sym] and g_def
1.5410 @@ -6063,7 +6976,7 @@
1.5411      }
1.5412      ultimately have "x\<in>s \<longleftrightarrow> x \<in> g ` t" ..
1.5413    }
1.5414 -  hence "g ` t = s" by auto
1.5415 +  then have "g ` t = s" by auto
1.5416    ultimately show ?thesis
1.5417      unfolding homeomorphism_def homeomorphic_def
1.5418      apply (rule_tac x=g in exI)
1.5419 @@ -6074,21 +6987,21 @@
1.5420
1.5421  lemma homeomorphic_compact:
1.5422    fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
1.5423 -  shows "compact s \<Longrightarrow> continuous_on s f \<Longrightarrow> (f ` s = t) \<Longrightarrow> inj_on f s
1.5424 -          \<Longrightarrow> s homeomorphic t"
1.5425 +  shows "compact s \<Longrightarrow> continuous_on s f \<Longrightarrow> (f ` s = t) \<Longrightarrow> inj_on f s \<Longrightarrow> s homeomorphic t"
1.5426    unfolding homeomorphic_def by (metis homeomorphism_compact)
1.5427
1.5428 -text{* Preservation of topological properties.                                   *}
1.5429 +text{* Preservation of topological properties. *}
1.5430
1.5431  lemma homeomorphic_compactness: "s homeomorphic t \<Longrightarrow> (compact s \<longleftrightarrow> compact t)"
1.5432    unfolding homeomorphic_def homeomorphism_def
1.5433    by (metis compact_continuous_image)
1.5434
1.5435 -text{* Results on translation, scaling etc.                                      *}
1.5436 +text{* Results on translation, scaling etc. *}
1.5437
1.5438  lemma homeomorphic_scaling:
1.5439    fixes s :: "'a::real_normed_vector set"
1.5440 -  assumes "c \<noteq> 0"  shows "s homeomorphic ((\<lambda>x. c *\<^sub>R x) ` s)"
1.5441 +  assumes "c \<noteq> 0"
1.5442 +  shows "s homeomorphic ((\<lambda>x. c *\<^sub>R x) ` s)"
1.5443    unfolding homeomorphic_minimal
1.5444    apply (rule_tac x="\<lambda>x. c *\<^sub>R x" in exI)
1.5445    apply (rule_tac x="\<lambda>x. (1 / c) *\<^sub>R x" in exI)
1.5446 @@ -6110,7 +7023,7 @@
1.5447    fixes s :: "'a::real_normed_vector set"
1.5448    assumes "c \<noteq> 0"
1.5449    shows "s homeomorphic ((\<lambda>x. a + c *\<^sub>R x) ` s)"
1.5450 -proof-
1.5451 +proof -
1.5452    have *: "op + a ` op *\<^sub>R c ` s = (\<lambda>x. a + c *\<^sub>R x) ` s" by auto
1.5453    show ?thesis
1.5454      using homeomorphic_trans
1.5455 @@ -6124,8 +7037,8 @@
1.5456    fixes a b ::"'a::real_normed_vector"
1.5457    assumes "0 < d"  "0 < e"
1.5458    shows "(ball a d) homeomorphic  (ball b e)" (is ?th)
1.5459 -        "(cball a d) homeomorphic (cball b e)" (is ?cth)
1.5460 -proof-
1.5461 +    and "(cball a d) homeomorphic (cball b e)" (is ?cth)
1.5462 +proof -
1.5463    show ?th unfolding homeomorphic_minimal
1.5464      apply(rule_tac x="\<lambda>x. b + (e/d) *\<^sub>R (x - a)" in exI)
1.5465      apply(rule_tac x="\<lambda>x. a + (d/e) *\<^sub>R (x - b)" in exI)
1.5466 @@ -6133,7 +7046,6 @@
1.5467      apply (auto intro!: continuous_on_intros
1.5468        simp: dist_commute dist_norm pos_divide_less_eq mult_strict_left_mono)
1.5469      done
1.5470 -next
1.5471    show ?cth unfolding homeomorphic_minimal
1.5472      apply(rule_tac x="\<lambda>x. b + (e/d) *\<^sub>R (x - a)" in exI)
1.5473      apply(rule_tac x="\<lambda>x. a + (d/e) *\<^sub>R (x - b)" in exI)
1.5474 @@ -6173,9 +7085,9 @@
1.5475          using `N \<le> n` N unfolding f.diff[THEN sym] by auto
1.5476        finally have "norm (x n - x N) < d" using `e>0` by simp
1.5477      }
1.5478 -    hence "\<exists>N. \<forall>n\<ge>N. norm (x n - x N) < d" by auto
1.5479 +    then have "\<exists>N. \<forall>n\<ge>N. norm (x n - x N) < d" by auto
1.5480    }
1.5481 -  thus ?thesis unfolding cauchy and dist_norm by auto
1.5482 +  then show ?thesis unfolding cauchy and dist_norm by auto
1.5483  qed
1.5484
1.5485  lemma complete_isometric_image:
1.5486 @@ -6190,18 +7102,18 @@
1.5487    {
1.5488      fix g
1.5489      assume as:"\<forall>n::nat. g n \<in> f ` s" and cfg:"Cauchy g"
1.5490 -    then obtain x where "\<forall>n. x n \<in> s \<and> g n = f (x n)"
1.5491 +    then obtain x where "\<forall>n. x n \<in> s \<and> g n = f (x n)"
1.5492        using choice[of "\<lambda> n xa. xa \<in> s \<and> g n = f xa"] by auto
1.5493 -    hence x:"\<forall>n. x n \<in> s"  "\<forall>n. g n = f (x n)" by auto
1.5494 -    hence "f \<circ> x = g" unfolding fun_eq_iff by auto
1.5495 +    then have x:"\<forall>n. x n \<in> s"  "\<forall>n. g n = f (x n)" by auto
1.5496 +    then have "f \<circ> x = g" unfolding fun_eq_iff by auto
1.5497      then obtain l where "l\<in>s" and l:"(x ---> l) sequentially"
1.5498        using cs[unfolded complete_def, THEN spec[where x="x"]]
1.5499        using cauchy_isometric[OF `0<e` s f normf] and cfg and x(1) by auto
1.5500 -    hence "\<exists>l\<in>f ` s. (g ---> l) sequentially"
1.5501 +    then have "\<exists>l\<in>f ` s. (g ---> l) sequentially"
1.5502        using linear_continuous_at[OF f, unfolded continuous_at_sequentially, THEN spec[where x=x], of l]
1.5503        unfolding `f \<circ> x = g` by auto
1.5504    }
1.5505 -  thus ?thesis unfolding complete_def by auto
1.5506 +  then show ?thesis unfolding complete_def by auto
1.5507  qed
1.5508
1.5509  lemma injective_imp_isometric:
1.5510 @@ -6214,10 +7126,10 @@
1.5511    {
1.5512      fix x
1.5513      assume "x \<in> s"
1.5514 -    hence "x = 0" using True by auto
1.5515 -    hence "norm x \<le> norm (f x)" by auto
1.5516 +    then have "x = 0" using True by auto
1.5517 +    then have "norm x \<le> norm (f x)" by auto
1.5518    }
1.5519 -  thus ?thesis by (auto intro!: exI[where x=1])
1.5520 +  then show ?thesis by (auto intro!: exI[where x=1])
1.5521  next
1.5522    interpret f: bounded_linear f by fact
1.5523    case False
1.5524 @@ -6229,7 +7141,7 @@
1.5525
1.5526    have "?S'' = frontier(cball 0 (norm a))"
1.5527      unfolding frontier_cball and dist_norm by auto
1.5528 -  hence "compact ?S''"
1.5529 +  then have "compact ?S''"
1.5530      using compact_frontier[OF compact_cball, of 0 "norm a"] by auto
1.5531    moreover have "?S' = s \<inter> ?S''" by auto
1.5532    ultimately have "compact ?S'"
1.5533 @@ -6237,12 +7149,13 @@
1.5534    moreover have *:"f ` ?S' = ?S" by auto
1.5535    ultimately have "compact ?S"
1.5536      using compact_continuous_image[OF linear_continuous_on[OF f(1)], of ?S'] by auto
1.5537 -  hence "closed ?S" using compact_imp_closed by auto
1.5538 +  then have "closed ?S" using compact_imp_closed by auto
1.5539    moreover have "?S \<noteq> {}" using a by auto
1.5540    ultimately obtain b' where "b'\<in>?S" "\<forall>y\<in>?S. norm b' \<le> norm y"
1.5541      using distance_attains_inf[of ?S 0] unfolding dist_0_norm by auto
1.5542 -  then obtain b where "b\<in>s" and ba:"norm b = norm a"
1.5543 -      and b:"\<forall>x\<in>{x \<in> s. norm x = norm a}. norm (f b) \<le> norm (f x)"
1.5544 +  then obtain b where "b\<in>s"
1.5545 +    and ba: "norm b = norm a"
1.5546 +    and b: "\<forall>x\<in>{x \<in> s. norm x = norm a}. norm (f b) \<le> norm (f x)"
1.5547      unfolding *[THEN sym] unfolding image_iff by auto
1.5548
1.5549    let ?e = "norm (f b) / norm b"
1.5550 @@ -6258,21 +7171,21 @@
1.5551    {
1.5552      fix x
1.5553      assume "x\<in>s"
1.5554 -    hence "norm (f b) / norm b * norm x \<le> norm (f x)"
1.5555 +    then have "norm (f b) / norm b * norm x \<le> norm (f x)"
1.5556      proof (cases "x=0")
1.5557        case True
1.5558 -      thus "norm (f b) / norm b * norm x \<le> norm (f x)" by auto
1.5559 +      then show "norm (f b) / norm b * norm x \<le> norm (f x)" by auto
1.5560      next
1.5561        case False
1.5562 -      hence *:"0 < norm a / norm x"
1.5563 +      then have *: "0 < norm a / norm x"
1.5564          using `a\<noteq>0`
1.5565          unfolding zero_less_norm_iff[THEN sym]
1.5566          by (simp only: divide_pos_pos)
1.5567        have "\<forall>c. \<forall>x\<in>s. c *\<^sub>R x \<in> s"
1.5568          using s[unfolded subspace_def] by auto
1.5569 -      hence "(norm a / norm x) *\<^sub>R x \<in> {x \<in> s. norm x = norm a}"
1.5570 +      then have "(norm a / norm x) *\<^sub>R x \<in> {x \<in> s. norm x = norm a}"
1.5571          using `x\<in>s` and `x\<noteq>0` by auto
1.5572 -      thus "norm (f b) / norm b * norm x \<le> norm (f x)"
1.5573 +      then show "norm (f b) / norm b * norm x \<le> norm (f x)"
1.5574          using b[THEN bspec[where x="(norm a / norm x) *\<^sub>R x"]]
1.5575          unfolding f.scaleR and ba using `x\<noteq>0` `a\<noteq>0`
1.5576          by (auto simp add: mult_commute pos_le_divide_eq pos_divide_le_eq)
1.5577 @@ -6283,10 +7196,10 @@
1.5578
1.5579  lemma closed_injective_image_subspace:
1.5580    fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
1.5581 -  assumes "subspace s" "bounded_linear f" "\<forall>x\<in>s. f x = 0 --> x = 0" "closed s"
1.5582 +  assumes "subspace s" "bounded_linear f" "\<forall>x\<in>s. f x = 0 \<longrightarrow> x = 0" "closed s"
1.5583    shows "closed(f ` s)"
1.5584 -proof-
1.5585 -  obtain e where "e>0" and e:"\<forall>x\<in>s. e * norm x \<le> norm (f x)"
1.5586 +proof -
1.5587 +  obtain e where "e > 0" and e: "\<forall>x\<in>s. e * norm x \<le> norm (f x)"
1.5588      using injective_imp_isometric[OF assms(4,1,2,3)] by auto
1.5589    show ?thesis
1.5590      using complete_isometric_image[OF `e>0` assms(1,2) e] and assms(4)
1.5591 @@ -6320,55 +7233,58 @@
1.5592    moreover
1.5593    {
1.5594      fix x::"'a" assume "x \<in> ?A"
1.5595 -    hence "finite d" "x \<in> ?A" using assms by(auto intro: finite_subset[OF _ finite_Basis])
1.5596 +    then have "finite d" "x \<in> ?A"
1.5597 +      using assms by (auto intro: finite_subset[OF _ finite_Basis])
1.5598      from this d have "x \<in> span d"
1.5599      proof (induct d arbitrary: x)
1.5600        case empty
1.5601 -      hence "x=0"
1.5602 +      then have "x = 0"
1.5603          apply (rule_tac euclidean_eqI)
1.5604          apply auto
1.5605          done
1.5606 -      thus ?case
1.5607 +      then show ?case
1.5608          using subspace_0[OF subspace_span[of "{}"]] by auto
1.5609      next
1.5610        case (insert k F)
1.5611 -      hence *:"\<forall>i\<in>Basis. i \<notin> insert k F \<longrightarrow> x \<bullet> i = 0" by auto
1.5612 -      have **:"F \<subseteq> insert k F" by auto
1.5613 +      then have *: "\<forall>i\<in>Basis. i \<notin> insert k F \<longrightarrow> x \<bullet> i = 0" by auto
1.5614 +      have **: "F \<subseteq> insert k F" by auto
1.5615        def y \<equiv> "x - (x\<bullet>k) *\<^sub>R k"
1.5616 -      have y:"x = y + (x\<bullet>k) *\<^sub>R k" unfolding y_def by auto
1.5617 +      have y: "x = y + (x\<bullet>k) *\<^sub>R k" unfolding y_def by auto
1.5618        { fix i assume i': "i \<notin> F" "i \<in> Basis"
1.5619 -        hence "y \<bullet> i = 0" unfolding y_def
1.5620 +        then have "y \<bullet> i = 0" unfolding y_def
1.5621            using *[THEN bspec[where x=i]] insert by (auto simp: inner_simps inner_Basis) }
1.5622 -      hence "y \<in> span F" using insert by auto
1.5623 -      hence "y \<in> span (insert k F)"
1.5624 +      then have "y \<in> span F" using insert by auto
1.5625 +      then have "y \<in> span (insert k F)"
1.5626          using span_mono[of F "insert k F"] using assms by auto
1.5627        moreover
1.5628        have "k \<in> span (insert k F)" by(rule span_superset, auto)
1.5629 -      hence "(x\<bullet>k) *\<^sub>R k \<in> span (insert k F)"
1.5630 +      then have "(x\<bullet>k) *\<^sub>R k \<in> span (insert k F)"
1.5631          using span_mul by auto
1.5632        ultimately
1.5633        have "y + (x\<bullet>k) *\<^sub>R k \<in> span (insert k F)"
1.5634          using span_add by auto
1.5635 -      thus ?case using y by auto
1.5636 +      then show ?case using y by auto
1.5637      qed
1.5638    }
1.5639 -  hence "?A \<subseteq> span d" by auto
1.5640 +  then have "?A \<subseteq> span d" by auto
1.5641    moreover
1.5642    {
1.5643      fix x
1.5644      assume "x \<in> d"
1.5645 -    hence "x \<in> ?D" using assms by auto
1.5646 +    then have "x \<in> ?D" using assms by auto
1.5647    }
1.5648 -  hence "independent d"
1.5649 +  then have "independent d"
1.5650      using independent_mono[OF independent_Basis, of d] and assms by auto
1.5651    moreover
1.5652    have "d \<subseteq> ?D" unfolding subset_eq using assms by auto
1.5653    ultimately show ?thesis using dim_unique[of d ?A] by auto
1.5654  qed
1.5655
1.5656 -text{* Hence closure and completeness of all subspaces.                          *}
1.5657 -
1.5658 -lemma ex_card: assumes "n \<le> card A" shows "\<exists>S\<subseteq>A. card S = n"
1.5659 +text{* Hence closure and completeness of all subspaces. *}
1.5660 +
1.5661 +lemma ex_card:
1.5662 +  assumes "n \<le> card A"
1.5663 +  shows "\<exists>S\<subseteq>A. card S = n"
1.5664  proof cases
1.5665    assume "finite A"
1.5666    from ex_bij_betw_nat_finite[OF this] guess f ..
1.5667 @@ -6425,7 +7341,7 @@
1.5668      using dim_subset[of "closure s" "span s"]
1.5669      unfolding dim_span
1.5670      by auto
1.5671 -  thus ?thesis using dim_subset[OF closure_subset, of s]
1.5672 +  then show ?thesis using dim_subset[OF closure_subset, of s]
1.5673      by auto
1.5674  qed
1.5675
1.5676 @@ -6462,34 +7378,54 @@
1.5677              (if {a .. b} = {} then {}
1.5678              else (if 0 \<le> m then {m *\<^sub>R a + c .. m *\<^sub>R b + c}
1.5679              else {m *\<^sub>R b + c .. m *\<^sub>R a + c}))"
1.5680 -proof(cases "m=0")
1.5681 -  { fix x assume "x \<le> c" "c \<le> x"
1.5682 -    hence "x=c" unfolding eucl_le[where 'a='a] apply-
1.5683 -      apply(subst euclidean_eq_iff) by (auto intro: order_antisym) }
1.5684 +proof (cases "m = 0")
1.5685 +  {
1.5686 +    fix x
1.5687 +    assume "x \<le> c" "c \<le> x"
1.5688 +    then have "x = c"
1.5689 +      unfolding eucl_le[where 'a='a]
1.5690 +      apply -
1.5691 +      apply (subst euclidean_eq_iff)
1.5692 +      apply (auto intro: order_antisym)
1.5693 +      done
1.5694 +  }
1.5695    moreover case True
1.5696    moreover have "c \<in> {m *\<^sub>R a + c..m *\<^sub>R b + c}" unfolding True by(auto simp add: eucl_le[where 'a='a])
1.5697    ultimately show ?thesis by auto
1.5698  next
1.5699    case False
1.5700 -  { fix y assume "a \<le> y" "y \<le> b" "m > 0"
1.5701 -    hence "m *\<^sub>R a + c \<le> m *\<^sub>R y + c"  "m *\<^sub>R y + c \<le> m *\<^sub>R b + c"
1.5702 +  {
1.5703 +    fix y
1.5704 +    assume "a \<le> y" "y \<le> b" "m > 0"
1.5705 +    then have "m *\<^sub>R a + c \<le> m *\<^sub>R y + c" and "m *\<^sub>R y + c \<le> m *\<^sub>R b + c"
1.5706        unfolding eucl_le[where 'a='a] by (auto simp: inner_simps)
1.5707 -  } moreover
1.5708 -  { fix y assume "a \<le> y" "y \<le> b" "m < 0"
1.5709 -    hence "m *\<^sub>R b + c \<le> m *\<^sub>R y + c"  "m *\<^sub>R y + c \<le> m *\<^sub>R a + c"
1.5710 -      unfolding eucl_le[where 'a='a] by(auto simp add: mult_left_mono_neg inner_simps)
1.5711 -  } moreover
1.5712 -  { fix y assume "m > 0"  "m *\<^sub>R a + c \<le> y"  "y \<le> m *\<^sub>R b + c"
1.5713 -    hence "y \<in> (\<lambda>x. m *\<^sub>R x + c) ` {a..b}"
1.5714 +  }
1.5715 +  moreover
1.5716 +  {
1.5717 +    fix y
1.5718 +    assume "a \<le> y" "y \<le> b" "m < 0"
1.5719 +    then have "m *\<^sub>R b + c \<le> m *\<^sub>R y + c" and "m *\<^sub>R y + c \<le> m *\<^sub>R a + c"
1.5720 +      unfolding eucl_le[where 'a='a] by (auto simp add: mult_left_mono_neg inner_simps)
1.5721 +  }
1.5722 +  moreover
1.5723 +  {
1.5724 +    fix y
1.5725 +    assume "m > 0" and "m *\<^sub>R a + c \<le> y" and "y \<le> m *\<^sub>R b + c"
1.5726 +    then have "y \<in> (\<lambda>x. m *\<^sub>R x + c) ` {a..b}"
1.5727        unfolding image_iff Bex_def mem_interval eucl_le[where 'a='a]
1.5728        apply (intro exI[where x="(1 / m) *\<^sub>R (y - c)"])
1.5729 -      by(auto simp add: pos_le_divide_eq pos_divide_le_eq mult_commute diff_le_iff inner_simps)
1.5730 -  } moreover
1.5731 -  { fix y assume "m *\<^sub>R b + c \<le> y" "y \<le> m *\<^sub>R a + c" "m < 0"
1.5732 -    hence "y \<in> (\<lambda>x. m *\<^sub>R x + c) ` {a..b}"
1.5733 +      apply (auto simp add: pos_le_divide_eq pos_divide_le_eq mult_commute diff_le_iff inner_simps)
1.5734 +      done
1.5735 +  }
1.5736 +  moreover
1.5737 +  {
1.5738 +    fix y
1.5739 +    assume "m *\<^sub>R b + c \<le> y" "y \<le> m *\<^sub>R a + c" "m < 0"
1.5740 +    then have "y \<in> (\<lambda>x. m *\<^sub>R x + c) ` {a..b}"
1.5741        unfolding image_iff Bex_def mem_interval eucl_le[where 'a='a]
1.5742        apply (intro exI[where x="(1 / m) *\<^sub>R (y - c)"])
1.5743 -      by(auto simp add: neg_le_divide_eq neg_divide_le_eq mult_commute diff_le_iff inner_simps)
1.5744 +      apply (auto simp add: neg_le_divide_eq neg_divide_le_eq mult_commute diff_le_iff inner_simps)
1.5745 +      done
1.5746    }
1.5747    ultimately show ?thesis using False by auto
1.5748  qed
1.5749 @@ -6502,40 +7438,44 @@
1.5750  subsection {* Banach fixed point theorem (not really topological...) *}
1.5751
1.5752  lemma banach_fix:
1.5753 -  assumes s:"complete s" "s \<noteq> {}" and c:"0 \<le> c" "c < 1" and f:"(f ` s) \<subseteq> s" and
1.5754 -          lipschitz:"\<forall>x\<in>s. \<forall>y\<in>s. dist (f x) (f y) \<le> c * dist x y"
1.5755 +  assumes s: "complete s" "s \<noteq> {}"
1.5756 +    and c: "0 \<le> c" "c < 1"
1.5757 +    and f: "(f ` s) \<subseteq> s"
1.5758 +    and lipschitz:"\<forall>x\<in>s. \<forall>y\<in>s. dist (f x) (f y) \<le> c * dist x y"
1.5759    shows "\<exists>! x\<in>s. (f x = x)"
1.5760 -proof-
1.5761 +proof -
1.5762    have "1 - c > 0" using c by auto
1.5763
1.5764    from s(2) obtain z0 where "z0 \<in> s" by auto
1.5765    def z \<equiv> "\<lambda>n. (f ^^ n) z0"
1.5766 -  { fix n::nat
1.5767 +  {
1.5768 +    fix n :: nat
1.5769      have "z n \<in> s" unfolding z_def
1.5770      proof (induct n)
1.5771        case 0
1.5772 -      thus ?case using `z0 \<in>s` by auto
1.5773 +      then show ?case using `z0 \<in> s` by auto
1.5774      next
1.5775        case Suc
1.5776 -      thus ?case using f by auto qed
1.5777 +      then show ?case using f by auto qed
1.5778    } note z_in_s = this
1.5779
1.5780    def d \<equiv> "dist (z 0) (z 1)"
1.5781
1.5782    have fzn:"\<And>n. f (z n) = z (Suc n)" unfolding z_def by auto
1.5783    {
1.5784 -    fix n::nat
1.5785 +    fix n :: nat
1.5786      have "dist (z n) (z (Suc n)) \<le> (c ^ n) * d"
1.5787      proof (induct n)
1.5788 -      case 0 thus ?case
1.5789 +      case 0
1.5790 +      then show ?case
1.5791          unfolding d_def by auto
1.5792      next
1.5793        case (Suc m)
1.5794 -      hence "c * dist (z m) (z (Suc m)) \<le> c ^ Suc m * d"
1.5795 +      then have "c * dist (z m) (z (Suc m)) \<le> c ^ Suc m * d"
1.5796          using `0 \<le> c`
1.5797          using mult_left_mono[of "dist (z m) (z (Suc m))" "c ^ m * d" c]
1.5798          by auto
1.5799 -      thus ?case
1.5800 +      then show ?case
1.5801          using lipschitz[THEN bspec[where x="z m"], OF z_in_s, THEN bspec[where x="z (Suc m)"], OF z_in_s]
1.5802          unfolding fzn and mult_le_cancel_left
1.5803          by auto
1.5804 @@ -6543,10 +7483,11 @@
1.5805    } note cf_z = this
1.5806
1.5807    {
1.5808 -    fix n m::nat
1.5809 +    fix n m :: nat
1.5810      have "(1 - c) * dist (z m) (z (m+n)) \<le> (c ^ m) * d * (1 - c ^ n)"
1.5811      proof (induct n)
1.5812 -      case 0 show ?case by auto
1.5813 +      case 0
1.5814 +      show ?case by auto
1.5815      next
1.5816        case (Suc k)
1.5817        have "(1 - c) * dist (z m) (z (m + Suc k)) \<le>
1.5818 @@ -6564,21 +7505,21 @@
1.5819      qed
1.5820    } note cf_z2 = this
1.5821    {
1.5822 -    fix e::real
1.5823 -    assume "e>0"
1.5824 -    hence "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (z m) (z n) < e"
1.5825 +    fix e :: real
1.5826 +    assume "e > 0"
1.5827 +    then have "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (z m) (z n) < e"
1.5828      proof (cases "d = 0")
1.5829        case True
1.5830        have *: "\<And>x. ((1 - c) * x \<le> 0) = (x \<le> 0)" using `1 - c > 0`
1.5831          by (metis mult_zero_left mult_commute real_mult_le_cancel_iff1)
1.5832        from True have "\<And>n. z n = z0" using cf_z2[of 0] and c unfolding z_def
1.5833          by (simp add: *)
1.5834 -      thus ?thesis using `e>0` by auto
1.5835 +      then show ?thesis using `e>0` by auto
1.5836      next
1.5837        case False
1.5838 -      hence "d>0" unfolding d_def using zero_le_dist[of "z 0" "z 1"]
1.5839 +      then have "d>0" unfolding d_def using zero_le_dist[of "z 0" "z 1"]
1.5840          by (metis False d_def less_le)
1.5841 -      hence "0 < e * (1 - c) / d"
1.5842 +      then have "0 < e * (1 - c) / d"
1.5843          using `e>0` and `1-c>0`
1.5844          using divide_pos_pos[of "e * (1 - c)" d] and mult_pos_pos[of e "1 - c"]
1.5845          by auto
1.5846 @@ -6591,7 +7532,7 @@
1.5847            using power_decreasing[OF `n\<ge>N`, of c] by auto
1.5848          have "1 - c ^ (m - n) > 0"
1.5849            using c and power_strict_mono[of c 1 "m - n"] using `m>n` by auto
1.5850 -        hence **:"d * (1 - c ^ (m - n)) / (1 - c) > 0"
1.5851 +        then have **: "d * (1 - c ^ (m - n)) / (1 - c) > 0"
1.5852            using mult_pos_pos[OF `d>0`, of "1 - c ^ (m - n)"]
1.5853            using divide_pos_pos[of "d * (1 - c ^ (m - n))" "1 - c"]
1.5854            using `0 < 1 - c`
1.5855 @@ -6606,27 +7547,30 @@
1.5856            unfolding mult_assoc by auto
1.5857          also have "\<dots> < (e * (1 - c) / d) * d * (1 - c ^ (m - n)) / (1 - c)"
1.5858            using mult_strict_right_mono[OF N **] unfolding mult_assoc by auto
1.5859 -        also have "\<dots> = e * (1 - c ^ (m - n))" using c and `d>0` and `1 - c > 0` by auto
1.5860 -        also have "\<dots> \<le> e" using c and `1 - c ^ (m - n) > 0` and `e>0` using mult_right_le_one_le[of e "1 - c ^ (m - n)"] by auto
1.5861 +        also have "\<dots> = e * (1 - c ^ (m - n))"
1.5862 +          using c and `d>0` and `1 - c > 0` by auto
1.5863 +        also have "\<dots> \<le> e" using c and `1 - c ^ (m - n) > 0` and `e>0`
1.5864 +          using mult_right_le_one_le[of e "1 - c ^ (m - n)"] by auto
1.5865          finally have  "dist (z m) (z n) < e" by auto
1.5866        } note * = this
1.5867        {
1.5868 -        fix m n::nat
1.5869 -        assume as:"N\<le>m" "N\<le>n"
1.5870 -        hence "dist (z n) (z m) < e"
1.5871 +        fix m n :: nat
1.5872 +        assume as: "N \<le> m" "N \<le> n"
1.5873 +        then have "dist (z n) (z m) < e"
1.5874          proof (cases "n = m")
1.5875            case True
1.5876 -          thus ?thesis using `e>0` by auto
1.5877 +          then show ?thesis using `e>0` by auto
1.5878          next
1.5879            case False
1.5880 -          thus ?thesis using as and *[of n m] *[of m n]
1.5881 +          then show ?thesis using as and *[of n m] *[of m n]
1.5882              unfolding nat_neq_iff by (auto simp add: dist_commute)
1.5883          qed
1.5884        }
1.5885 -      thus ?thesis by auto
1.5886 +      then show ?thesis by auto
1.5887      qed
1.5888    }
1.5889 -  hence "Cauchy z" unfolding cauchy_def by auto
1.5890 +  then have "Cauchy z"
1.5891 +    unfolding cauchy_def by auto
1.5892    then obtain x where "x\<in>s" and x:"(z ---> x) sequentially"
1.5893      using s(1)[unfolded compact_def complete_def, THEN spec[where x=z]] and z_in_s by auto
1.5894
1.5895 @@ -6634,13 +7578,14 @@
1.5896    have "e = 0"
1.5897    proof (rule ccontr)
1.5898      assume "e \<noteq> 0"
1.5899 -    hence "e>0" unfolding e_def using zero_le_dist[of "f x" x]
1.5900 +    then have "e > 0"
1.5901 +      unfolding e_def using zero_le_dist[of "f x" x]
1.5902        by (metis dist_eq_0_iff dist_nz e_def)
1.5903      then obtain N where N:"\<forall>n\<ge>N. dist (z n) x < e / 2"
1.5904        using x[unfolded LIMSEQ_def, THEN spec[where x="e/2"]] by auto
1.5905 -    hence N':"dist (z N) x < e / 2" by auto
1.5906 -
1.5907 -    have *:"c * dist (z N) x \<le> dist (z N) x"
1.5908 +    then have N':"dist (z N) x < e / 2" by auto
1.5909 +
1.5910 +    have *: "c * dist (z N) x \<le> dist (z N) x"
1.5911        unfolding mult_le_cancel_right2
1.5912        using zero_le_dist[of "z N" x] and c
1.5913        by (metis dist_eq_0_iff dist_nz order_less_asym less_le)
1.5914 @@ -6657,24 +7602,25 @@
1.5915        unfolding e_def
1.5916        by auto
1.5917    qed
1.5918 -  hence "f x = x" unfolding e_def by auto
1.5919 +  then have "f x = x" unfolding e_def by auto
1.5920    moreover
1.5921    {
1.5922      fix y
1.5923      assume "f y = y" "y\<in>s"
1.5924 -    hence "dist x y \<le> c * dist x y"
1.5925 +    then have "dist x y \<le> c * dist x y"
1.5926        using lipschitz[THEN bspec[where x=x], THEN bspec[where x=y]]
1.5927        using `x\<in>s` and `f x = x`
1.5928        by auto
1.5929 -    hence "dist x y = 0"
1.5930 +    then have "dist x y = 0"
1.5931        unfolding mult_le_cancel_right1
1.5932        using c and zero_le_dist[of x y]
1.5933        by auto
1.5934 -    hence "y = x" by auto
1.5935 +    then have "y = x" by auto
1.5936    }
1.5937    ultimately show ?thesis using `x\<in>s` by blast+
1.5938  qed
1.5939
1.5940 +
1.5941  subsection {* Edelstein fixed point theorem *}
1.5942
1.5943  lemma edelstein_fix:
```