merged
authorwenzelm
Thu, 29 Aug 2013 19:22:48 +0200
changeset 53283 be0491d86d19
parent 53270 c8628119d18e (current diff)
parent 53282 9d6e263fa921 (diff)
child 53284 d0153a0a9b2b
child 53291 f7fa953bd15b
merged
src/Pure/Thy/completion.scala
--- a/NEWS	Thu Aug 29 18:44:03 2013 +0200
+++ b/NEWS	Thu Aug 29 19:22:48 2013 +0200
@@ -90,10 +90,14 @@
 according to Isabelle/Scala plugin option "jedit_font_reset_size"
 (cf. keyboard shortcut C+0).
 
-* More reactive and less intrusive completion.  Plain words need to be
-at least 3 characters long to be completed (was 2 before).  Symbols
-are only completed in backslash forms, e.g. \forall or \<forall> that
-both produce the Isabelle symbol \<forall> in its Unicode rendering.
+* More reactive and less intrusive completion, managed by
+Isabelle/jEdit instead of SideKick.  Plain words need to be at least 3
+characters long to be completed (was 2 before).  Symbols are only
+completed in backslash forms, e.g. \forall or \<forall> that both
+produce the Isabelle symbol \<forall> in its Unicode rendering.
+
+* Improved support for Linux look-and-feel "GTK+", see also "Utilities
+/ Global Options / Appearance".
 
 
 *** Pure ***
--- a/src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy	Thu Aug 29 19:22:48 2013 +0200
@@ -30,7 +30,7 @@
 
 lemmas real_isGlb_unique = isGlb_unique[where 'a=real]
 
-lemma countable_PiE: 
+lemma countable_PiE:
   "finite I \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> countable (F i)) \<Longrightarrow> countable (PiE I F)"
   by (induct I arbitrary: F rule: finite_induct) (auto simp: PiE_insert_eq)
 
@@ -77,45 +77,48 @@
 proof safe
   fix O' and x::'a
   assume H: "topological_basis B" "open O'" "x \<in> O'"
-  hence "(\<exists>B'\<subseteq>B. \<Union>B' = O')" by (simp add: topological_basis_def)
+  then have "(\<exists>B'\<subseteq>B. \<Union>B' = O')" by (simp add: topological_basis_def)
   then obtain B' where "B' \<subseteq> B" "O' = \<Union>B'" by auto
-  thus "\<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'" using H by auto
+  then show "\<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'" using H by auto
 next
   assume H: ?rhs
-  show "topological_basis B" using assms unfolding topological_basis_def
+  show "topological_basis B"
+    using assms unfolding topological_basis_def
   proof safe
-    fix O'::"'a set" assume "open O'"
+    fix O'::"'a set"
+    assume "open O'"
     with H obtain f where "\<forall>x\<in>O'. f x \<in> B \<and> x \<in> f x \<and> f x \<subseteq> O'"
       by (force intro: bchoice simp: Bex_def)
-    thus "\<exists>B'\<subseteq>B. \<Union>B' = O'"
+    then show "\<exists>B'\<subseteq>B. \<Union>B' = O'"
       by (auto intro: exI[where x="{f x |x. x \<in> O'}"])
   qed
 qed
 
 lemma topological_basisI:
   assumes "\<And>B'. B' \<in> B \<Longrightarrow> open B'"
-  assumes "\<And>O' x. open O' \<Longrightarrow> x \<in> O' \<Longrightarrow> \<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'"
+    and "\<And>O' x. open O' \<Longrightarrow> x \<in> O' \<Longrightarrow> \<exists>B'\<in>B. x \<in> B' \<and> B' \<subseteq> O'"
   shows "topological_basis B"
   using assms by (subst topological_basis_iff) auto
 
 lemma topological_basisE:
   fixes O'
   assumes "topological_basis B"
-  assumes "open O'"
-  assumes "x \<in> O'"
+    and "open O'"
+    and "x \<in> O'"
   obtains B' where "B' \<in> B" "x \<in> B'" "B' \<subseteq> O'"
 proof atomize_elim
-  from assms have "\<And>B'. B'\<in>B \<Longrightarrow> open B'" by (simp add: topological_basis_def)
+  from assms have "\<And>B'. B'\<in>B \<Longrightarrow> open B'"
+    by (simp add: topological_basis_def)
   with topological_basis_iff assms
-  show  "\<exists>B'. B' \<in> B \<and> x \<in> B' \<and> B' \<subseteq> O'" using assms by (simp add: Bex_def)
+  show  "\<exists>B'. B' \<in> B \<and> x \<in> B' \<and> B' \<subseteq> O'"
+    using assms by (simp add: Bex_def)
 qed
 
 lemma topological_basis_open:
   assumes "topological_basis B"
-  assumes "X \<in> B"
+    and "X \<in> B"
   shows "open X"
-  using assms
-  by (simp add: topological_basis_def)
+  using assms by (simp add: topological_basis_def)
 
 lemma topological_basis_imp_subbasis:
   assumes B: "topological_basis B"
@@ -179,7 +182,7 @@
 locale countable_basis =
   fixes B::"'a::topological_space set set"
   assumes is_basis: "topological_basis B"
-  assumes countable_basis: "countable B"
+    and countable_basis: "countable B"
 begin
 
 lemma open_countable_basis_ex:
@@ -275,7 +278,8 @@
   fix x :: "'a \<times> 'b"
   from first_countable_basisE[of "fst x"] guess A :: "'a set set" . note A = this
   from first_countable_basisE[of "snd x"] guess B :: "'b set set" . note B = this
-  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))"
+  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))"
   proof (rule first_countableI[of "(\<lambda>(a, b). a \<times> b) ` (A \<times> B)"], safe)
     fix a b
     assume x: "a \<in> A" "b \<in> B"
@@ -293,7 +297,8 @@
 qed
 
 class second_countable_topology = topological_space +
-  assumes ex_countable_subbasis: "\<exists>B::'a::topological_space set set. countable B \<and> open = generate_topology B"
+  assumes ex_countable_subbasis:
+    "\<exists>B::'a::topological_space set set. countable B \<and> open = generate_topology B"
 begin
 
 lemma ex_countable_basis: "\<exists>B::'a set set. countable B \<and> topological_basis B"
@@ -337,7 +342,7 @@
         unfolding subset_image_iff by blast }
     then show "topological_basis ?B"
       unfolding topological_space_class.topological_basis_def
-      by (safe intro!: topological_space_class.open_Inter) 
+      by (safe intro!: topological_space_class.open_Inter)
          (simp_all add: B generate_topology.Basis subset_eq)
   qed
 qed
@@ -368,7 +373,8 @@
   then have B: "countable B" "topological_basis B"
     using countable_basis is_basis
     by (auto simp: countable_basis is_basis)
-  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))"
+  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))"
     by (intro first_countableI[of "{b\<in>B. x \<in> b}"])
        (fastforce simp: topological_space_class.topological_basis_def)+
 qed
@@ -418,11 +424,11 @@
 
 lemma openin_clauses:
   fixes U :: "'a topology"
-  shows "openin U {}"
-  "\<And>S T. openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S\<inter>T)"
-  "\<And>K. (\<forall>S \<in> K. openin U S) \<Longrightarrow> openin U (\<Union>K)"
-  using openin[of U] unfolding istopology_def mem_Collect_eq
-  by fast+
+  shows
+    "openin U {}"
+    "\<And>S T. openin U S \<Longrightarrow> openin U T \<Longrightarrow> openin U (S\<inter>T)"
+    "\<And>K. (\<forall>S \<in> K. openin U S) \<Longrightarrow> openin U (\<Union>K)"
+  using openin[of U] unfolding istopology_def mem_Collect_eq by fast+
 
 lemma openin_subset[intro]: "openin U S \<Longrightarrow> S \<subseteq> topspace U"
   unfolding topspace_def by blast
@@ -502,7 +508,8 @@
 proof -
   have "S - T = S \<inter> (topspace U - T)" using openin_subset[of U S]  oS cT
     by (auto simp add: topspace_def openin_subset)
-  then show ?thesis using oS cT by (auto simp add: closedin_def)
+  then show ?thesis using oS cT
+    by (auto simp add: closedin_def)
 qed
 
 lemma closedin_diff[intro]:
@@ -511,8 +518,7 @@
   shows "closedin U (S - T)"
 proof -
   have "S - T = S \<inter> (topspace U - T)"
-    using closedin_subset[of U S] oS cT
-    by (auto simp add: topspace_def)
+    using closedin_subset[of U S] oS cT by (auto simp add: topspace_def)
   then show ?thesis
     using oS cT by (auto simp add: openin_closedin_eq)
 qed
@@ -537,7 +543,8 @@
   }
   moreover
   {
-    fix K assume K: "K \<subseteq> Collect ?L"
+    fix K
+    assume K: "K \<subseteq> Collect ?L"
     have th0: "Collect ?L = (\<lambda>S. S \<inter> V) ` Collect (openin U)"
       apply (rule set_eqI)
       apply (simp add: Ball_def image_iff)
@@ -663,7 +670,8 @@
 lemma closedin_closed_Int: "closed S ==> closedin (subtopology euclidean U) (U \<inter> S)"
   by (metis closedin_closed)
 
-lemma closed_closedin_trans: "closed S \<Longrightarrow> closed T \<Longrightarrow> T \<subseteq> S \<Longrightarrow> closedin (subtopology euclidean S) T"
+lemma closed_closedin_trans:
+  "closed S \<Longrightarrow> closed T \<Longrightarrow> T \<subseteq> S \<Longrightarrow> closedin (subtopology euclidean S) T"
   apply (subgoal_tac "S \<inter> T = T" )
   apply auto
   apply (frule closedin_closed_Int[of T S])
@@ -680,7 +688,8 @@
   (is "?lhs \<longleftrightarrow> ?rhs")
 proof
   assume ?lhs
-  then show ?rhs unfolding openin_open open_dist by blast
+  then show ?rhs
+    unfolding openin_open open_dist by blast
 next
   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}"
   have 1: "\<forall>x\<in>T. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> T"
@@ -692,7 +701,7 @@
     apply (rule_tac x=d in exI, clarify)
     apply (erule le_less_trans [OF dist_triangle])
     done
-  assume ?rhs hence 2: "S = U \<inter> T"
+  assume ?rhs then have 2: "S = U \<inter> T"
     unfolding T_def
     apply auto
     apply (drule (1) bspec, erule rev_bexI)
@@ -754,10 +763,10 @@
 lemma ball_subset_cball[simp,intro]: "ball x e \<subseteq> cball x e"
   by (simp add: subset_eq)
 
-lemma subset_ball[intro]: "d <= e ==> ball x d \<subseteq> ball x e"
+lemma subset_ball[intro]: "d \<le> e \<Longrightarrow> ball x d \<subseteq> ball x e"
   by (simp add: subset_eq)
 
-lemma subset_cball[intro]: "d <= e ==> cball x d \<subseteq> cball x e"
+lemma subset_cball[intro]: "d \<le> e \<Longrightarrow> cball x d \<subseteq> cball x e"
   by (simp add: subset_eq)
 
 lemma ball_max_Un: "ball a (max r s) = ball a r \<union> ball a s"
@@ -796,7 +805,7 @@
   unfolding open_dist subset_eq mem_ball Ball_def dist_commute ..
 
 lemma openE[elim?]:
-  assumes "open S" "x\<in>S" 
+  assumes "open S" "x\<in>S"
   obtains e where "e>0" "ball x e \<subseteq> S"
   using assms unfolding open_contains_ball by auto
 
@@ -876,7 +885,7 @@
 
 lemma open_UNION_box:
   fixes M :: "'a\<Colon>euclidean_space set"
-  assumes "open M" 
+  assumes "open M"
   defines "a' \<equiv> \<lambda>f :: 'a \<Rightarrow> real \<times> real. (\<Sum>(i::'a)\<in>Basis. fst (f i) *\<^sub>R i)"
   defines "b' \<equiv> \<lambda>f :: 'a \<Rightarrow> real \<times> real. (\<Sum>(i::'a)\<in>Basis. snd (f i) *\<^sub>R i)"
   defines "I \<equiv> {f\<in>Basis \<rightarrow>\<^sub>E \<rat> \<times> \<rat>. box (a' f) (b' f) \<subseteq> M}"
@@ -886,8 +895,11 @@
     fix x assume "x \<in> M"
     obtain e where e: "e > 0" "ball x e \<subseteq> M"
       using openE[OF `open M` `x \<in> M`] by auto
-    moreover then obtain a b where ab: "x \<in> box a b"
-      "\<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"
+    moreover obtain a b where ab:
+      "x \<in> box a b"
+      "\<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"
       using rational_boxes[OF e(1)] by metis
     ultimately have "x \<in> (\<Union>f\<in>I. box (a' f) (b' f))"
        by (intro UN_I[of "\<lambda>i\<in>Basis. (a \<bullet> i, b \<bullet> i)"])
@@ -908,7 +920,10 @@
       e1 \<inter> e2 = {} \<and>
       e1 \<noteq> {} \<and>
       e2 \<noteq> {})"
-  unfolding connected_def openin_open by (safe, blast+)
+  unfolding connected_def openin_open
+  apply safe
+  apply blast+
+  done
 
 lemma exists_diff:
   fixes P :: "'a set \<Rightarrow> bool"
@@ -938,7 +953,7 @@
     apply (subst exists_diff)
     apply blast
     done
-  hence th0: "connected S \<longleftrightarrow>
+  then have th0: "connected S \<longleftrightarrow>
     \<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> {})"
     (is " _ \<longleftrightarrow> \<not> (\<exists>e2 e1. ?P e2 e1)")
     apply (simp add: closed_def)
@@ -951,7 +966,7 @@
     fix e2
     {
       fix e1
-      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)"
+      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)"
         by auto
     }
     then have "(\<exists>e1. ?P e2 e1) \<longleftrightarrow> (\<exists>t. ?Q e2 t)"
@@ -969,7 +984,7 @@
 
 subsection{* Limit points *}
 
-definition (in topological_space) islimpt:: "'a \<Rightarrow> 'a set \<Rightarrow> bool" (infixr "islimpt" 60)
+definition (in topological_space) islimpt:: "'a \<Rightarrow> 'a set \<Rightarrow> bool"  (infixr "islimpt" 60)
   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))"
 
 lemma islimptI:
@@ -1068,12 +1083,12 @@
     fix x
     assume C: "\<forall>e>0. \<exists>x'\<in>S. x' \<noteq> x \<and> dist x' x < e"
     from e have e2: "e/2 > 0" by arith
-    from C[rule_format, OF e2] obtain y where y: "y \<in> S" "y\<noteq>x" "dist y x < e/2"
+    from C[rule_format, OF e2] obtain y where y: "y \<in> S" "y \<noteq> x" "dist y x < e/2"
       by blast
     let ?m = "min (e/2) (dist x y) "
     from e2 y(2) have mp: "?m > 0"
       by (simp add: dist_nz[THEN sym])
-    from C[rule_format, OF mp] obtain z where z: "z \<in> S" "z\<noteq>x" "dist z x < ?m"
+    from C[rule_format, OF mp] obtain z where z: "z \<in> S" "z \<noteq> x" "dist z x < ?m"
       by blast
     have th: "dist z y < e" using z y
       by (intro dist_triangle_lt [where z=x], simp)
@@ -1170,10 +1185,12 @@
       assume "x \<notin> interior S"
       with `x \<in> R` `open R` obtain y where "y \<in> R - S"
         unfolding interior_def by fast
-      from `open R` `closed S` have "open (R - S)" by (rule open_Diff)
-      from `R \<subseteq> S \<union> T` have "R - S \<subseteq> T" by fast
-      from `y \<in> R - S` `open (R - S)` `R - S \<subseteq> T` `interior T = {}`
-      show "False" unfolding interior_def by fast
+      from `open R` `closed S` have "open (R - S)"
+        by (rule open_Diff)
+      from `R \<subseteq> S \<union> T` have "R - S \<subseteq> T"
+        by fast
+      from `y \<in> R - S` `open (R - S)` `R - S \<subseteq> T` `interior T = {}` show False
+        unfolding interior_def by fast
     qed
   qed
 qed
@@ -1187,7 +1204,7 @@
   fix T
   assume "T \<subseteq> A \<times> B" and "open T"
   then show "T \<subseteq> interior A \<times> interior B"
-  proof (safe)
+  proof safe
     fix x y
     assume "(x, y) \<in> T"
     then obtain C D where "open C" "open D" "C \<times> D \<subseteq> T" "x \<in> C" "y \<in> D"
@@ -1271,7 +1288,7 @@
   fix x
   assume as: "open S" "x \<in> S \<inter> closure T"
   {
-    assume *:"x islimpt T"
+    assume *: "x islimpt T"
     have "x islimpt (S \<inter> T)"
     proof (rule islimptI)
       fix A
@@ -1302,7 +1319,9 @@
     by (intro Sigma_mono closure_subset)
   show "closed (closure A \<times> closure B)"
     by (intro closed_Times closed_closure)
-  fix T assume "A \<times> B \<subseteq> T" and "closed T" thus "closure A \<times> closure B \<subseteq> T"
+  fix T
+  assume "A \<times> B \<subseteq> T" and "closed T"
+  then show "closure A \<times> closure B \<subseteq> T"
     apply (simp add: closed_def open_prod_def, clarify)
     apply (rule ccontr)
     apply (drule_tac x="(a, b)" in bspec, simp, clarify, rename_tac C D)
@@ -1432,7 +1451,7 @@
   "eventually P net \<Longrightarrow> (\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> eventually Q net"
   using eventually_mono [of P Q] by fast
 
-lemma not_eventually: "(\<forall>x. \<not> P x ) \<Longrightarrow> ~(trivial_limit net) ==> ~(eventually (\<lambda>x. P x) net)"
+lemma not_eventually: "(\<forall>x. \<not> P x ) \<Longrightarrow> \<not> trivial_limit net \<Longrightarrow> \<not> eventually (\<lambda>x. P x) net"
   by (simp add: eventually_False)
 
 
@@ -1481,7 +1500,7 @@
   done
 
 lemma Lim_Un_univ:
-  "(f ---> l) (at x within S) \<Longrightarrow> (f ---> l) (at x within T) \<Longrightarrow>  
+  "(f ---> l) (at x within S) \<Longrightarrow> (f ---> l) (at x within T) \<Longrightarrow>
     S \<union> T = UNIV \<Longrightarrow> (f ---> l) (at x)"
   by (metis Lim_Un)
 
@@ -1537,7 +1556,8 @@
   assume e: "{x<..} \<inter> I \<noteq> {}"
   show ?thesis
   proof (rule order_tendstoI)
-    fix a assume a: "a < Inf (f ` ({x<..} \<inter> I))"
+    fix a
+    assume a: "a < Inf (f ` ({x<..} \<inter> I))"
     {
       fix y
       assume "y \<in> {x<..} \<inter> I"
@@ -1620,8 +1640,8 @@
   fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
   assumes "eventually (\<lambda>x. norm (f x) \<le> g x) net" "(g ---> 0) net"
   shows "(f ---> 0) net"
+  using assms(2)
 proof (rule metric_tendsto_imp_tendsto)
-  show "(g ---> 0) net" by fact
   show "eventually (\<lambda>x. dist (f x) 0 \<le> dist (g x) 0) net"
     using assms(1) by (rule eventually_elim1) (simp add: dist_norm)
 qed
@@ -1717,7 +1737,9 @@
 text{* Limit under bilinear function *}
 
 lemma Lim_bilinear:
-  assumes "(f ---> l) net" and "(g ---> m) net" and "bounded_bilinear h"
+  assumes "(f ---> l) net"
+    and "(g ---> m) net"
+    and "bounded_bilinear h"
   shows "((\<lambda>x. h (f x) (g x)) ---> (h l m)) net"
   using `bounded_bilinear h` `(f ---> l) net` `(g ---> m) net`
   by (rule bounded_bilinear.tendsto)
@@ -1733,7 +1755,7 @@
 lemma Lim_at_zero:
   fixes a :: "'a::real_normed_vector"
   fixes l :: "'b::topological_space"
-  shows "(f ---> l) (at a) \<longleftrightarrow> ((\<lambda>x. f(a + x)) ---> l) (at 0)" (is "?lhs = ?rhs")
+  shows "(f ---> l) (at a) \<longleftrightarrow> ((\<lambda>x. f(a + x)) ---> l) (at 0)"
   using LIM_offset_zero LIM_offset_zero_cancel ..
 
 text{* It's also sometimes useful to extract the limit point from the filter. *}
@@ -1741,8 +1763,7 @@
 abbreviation netlimit :: "'a::t2_space filter \<Rightarrow> 'a"
   where "netlimit F \<equiv> Lim F (\<lambda>x. x)"
 
-lemma netlimit_within:
-  "\<not> trivial_limit (at a within S) \<Longrightarrow> netlimit (at a within S) = a"
+lemma netlimit_within: "\<not> trivial_limit (at a within S) \<Longrightarrow> netlimit (at a within S) = a"
   by (rule tendsto_Lim) (auto intro: tendsto_intros)
 
 lemma netlimit_at:
@@ -1776,8 +1797,9 @@
   done
 
 lemma Lim_transform_within:
-  assumes "0 < d" and "\<forall>x'\<in>S. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
-  and "(f ---> l) (at x within S)"
+  assumes "0 < d"
+    and "\<forall>x'\<in>S. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
+    and "(f ---> l) (at x within S)"
   shows "(g ---> l) (at x within S)"
 proof (rule Lim_transform_eventually)
   show "eventually (\<lambda>x. f x = g x) (at x within S)"
@@ -1786,22 +1808,24 @@
 qed
 
 lemma Lim_transform_at:
-  assumes "0 < d" and "\<forall>x'. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
-  and "(f ---> l) (at x)"
+  assumes "0 < d"
+    and "\<forall>x'. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
+    and "(f ---> l) (at x)"
   shows "(g ---> l) (at x)"
+  using _ assms(3)
 proof (rule Lim_transform_eventually)
   show "eventually (\<lambda>x. f x = g x) (at x)"
     unfolding eventually_at2
     using assms(1,2) by auto
-  show "(f ---> l) (at x)" by fact
 qed
 
 text{* Common case assuming being away from some crucial point like 0. *}
 
 lemma Lim_transform_away_within:
   fixes a b :: "'a::t1_space"
-  assumes "a \<noteq> b" and "\<forall>x\<in>S. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x"
-  and "(f ---> l) (at a within S)"
+  assumes "a \<noteq> b"
+    and "\<forall>x\<in>S. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x"
+    and "(f ---> l) (at a within S)"
   shows "(g ---> l) (at a within S)"
 proof (rule Lim_transform_eventually)
   show "(f ---> l) (at a within S)" by fact
@@ -1821,8 +1845,9 @@
 text{* Alternatively, within an open set. *}
 
 lemma Lim_transform_within_open:
-  assumes "open S" and "a \<in> S" and "\<forall>x\<in>S. x \<noteq> a \<longrightarrow> f x = g x"
-  and "(f ---> l) (at a)"
+  assumes "open S" and "a \<in> S"
+    and "\<forall>x\<in>S. x \<noteq> a \<longrightarrow> f x = g x"
+    and "(f ---> l) (at a)"
   shows "(g ---> l) (at a)"
 proof (rule Lim_transform_eventually)
   show "eventually (\<lambda>x. f x = g x) (at a)"
@@ -1836,15 +1861,17 @@
 (* FIXME: Only one congruence rule for tendsto can be used at a time! *)
 
 lemma Lim_cong_within(*[cong add]*):
-  assumes "a = b" "x = y" "S = T"
-  assumes "\<And>x. x \<noteq> b \<Longrightarrow> x \<in> T \<Longrightarrow> f x = g x"
+  assumes "a = b"
+    and "x = y"
+    and "S = T"
+    and "\<And>x. x \<noteq> b \<Longrightarrow> x \<in> T \<Longrightarrow> f x = g x"
   shows "(f ---> x) (at a within S) \<longleftrightarrow> (g ---> y) (at b within T)"
   unfolding tendsto_def eventually_at_topological
   using assms by simp
 
 lemma Lim_cong_at(*[cong add]*):
   assumes "a = b" "x = y"
-  assumes "\<And>x. x \<noteq> a \<Longrightarrow> f x = g x"
+    and "\<And>x. x \<noteq> a \<Longrightarrow> f x = g x"
   shows "((\<lambda>x. f x) ---> x) (at a) \<longleftrightarrow> ((g ---> y) (at a))"
   unfolding tendsto_def eventually_at_topological
   using assms by simp
@@ -1855,19 +1882,22 @@
   fixes l :: "'a::first_countable_topology"
   shows "l \<in> closure S \<longleftrightarrow> (\<exists>x. (\<forall>n. x n \<in> S) \<and> (x ---> l) sequentially)" (is "?lhs = ?rhs")
 proof
-  assume "?lhs" moreover
-  { assume "l \<in> S"
-    hence "?rhs" using tendsto_const[of l sequentially] by auto
+  assume "?lhs"
+  moreover
+  {
+    assume "l \<in> S"
+    then have "?rhs" using tendsto_const[of l sequentially] by auto
   }
   moreover
-  { assume "l islimpt S"
-    hence "?rhs" unfolding islimpt_sequential by auto
+  {
+    assume "l islimpt S"
+    then have "?rhs" unfolding islimpt_sequential by auto
   }
   ultimately show "?rhs"
     unfolding closure_def by auto
 next
   assume "?rhs"
-  thus "?lhs" unfolding closure_def islimpt_sequential by auto
+  then show "?lhs" unfolding closure_def islimpt_sequential by auto
 qed
 
 lemma closed_sequential_limits:
@@ -1898,7 +1928,8 @@
   have *: "\<forall>x\<in>S. Inf S \<le> x"
     using cInf_lower_EX[of _ S] assms by metis
   {
-    fix e :: real assume "0 < e"
+    fix e :: real
+    assume "e > 0"
     then have "Inf S < Inf S + e" by simp
     with assms obtain x where "x \<in> S" "x < Inf S + e"
       by (subst (asm) cInf_less_iff[of _ B]) auto
@@ -1920,9 +1951,11 @@
   "(\<not> trivial_limit (at x within S)) = (\<forall>e>0. S \<inter> ball x e - {x} \<noteq> {})"
   (is "?lhs = ?rhs")
 proof -
-  { assume "?lhs"
-    { fix e :: real
-      assume "e>0"
+  {
+    assume "?lhs"
+    {
+      fix e :: real
+      assume "e > 0"
       then obtain y where "y:(S-{x}) & dist y x < e"
         using `?lhs` not_trivial_limit_within[of x S] closure_approachable[of x "S - {x}"]
         by auto
@@ -1933,16 +1966,21 @@
     then have "?rhs" by auto
   }
   moreover
-  { assume "?rhs"
-    { fix e :: real
-      assume "e>0"
-      then obtain y where "y : (S Int ball x e - {x})" using `?rhs` by blast
+  {
+    assume "?rhs"
+    {
+      fix e :: real
+      assume "e > 0"
+      then obtain y where "y : (S Int ball x e - {x})"
+        using `?rhs` by blast
       then have "y:(S-{x}) & dist y x < e"
         unfolding ball_def by (simp add: dist_commute)
-      then have "EX y:(S-{x}). dist y x < e" by auto
+      then have "EX y:(S-{x}). dist y x < e"
+        by auto
     }
     then have "?lhs"
-      using not_trivial_limit_within[of x S] closure_approachable[of x "S - {x}"] by auto
+      using not_trivial_limit_within[of x S] closure_approachable[of x "S - {x}"]
+      by auto
   }
   ultimately show ?thesis by auto
 qed
@@ -1975,34 +2013,47 @@
 lemma infdist_triangle: "infdist x A \<le> infdist y A + dist x y"
 proof cases
   assume "A = {}"
-  thus ?thesis by (simp add: infdist_def)
+  then show ?thesis by (simp add: infdist_def)
 next
   assume "A \<noteq> {}"
   then obtain a where "a \<in> A" by auto
   have "infdist x A \<le> Inf {dist x y + dist y a |a. a \<in> A}"
   proof (rule cInf_greatest)
-    from `A \<noteq> {}` show "{dist x y + dist y a |a. a \<in> A} \<noteq> {}" by simp
-    fix d assume "d \<in> {dist x y + dist y a |a. a \<in> A}"
-    then obtain a where d: "d = dist x y + dist y a" "a \<in> A" by auto
+    from `A \<noteq> {}` show "{dist x y + dist y a |a. a \<in> A} \<noteq> {}"
+      by simp
+    fix d
+    assume "d \<in> {dist x y + dist y a |a. a \<in> A}"
+    then obtain a where d: "d = dist x y + dist y a" "a \<in> A"
+      by auto
     show "infdist x A \<le> d"
       unfolding infdist_notempty[OF `A \<noteq> {}`]
     proof (rule cInf_lower2)
-      show "dist x a \<in> {dist x a |a. a \<in> A}" using `a \<in> A` by auto
-      show "dist x a \<le> d" unfolding d by (rule dist_triangle)
-      fix d assume "d \<in> {dist x a |a. a \<in> A}"
-      then obtain a where "a \<in> A" "d = dist x a" by auto
-      thus "infdist x A \<le> d" by (rule infdist_le)
+      show "dist x a \<in> {dist x a |a. a \<in> A}"
+        using `a \<in> A` by auto
+      show "dist x a \<le> d"
+        unfolding d by (rule dist_triangle)
+      fix d
+      assume "d \<in> {dist x a |a. a \<in> A}"
+      then obtain a where "a \<in> A" "d = dist x a"
+        by auto
+      then show "infdist x A \<le> d"
+        by (rule infdist_le)
     qed
   qed
   also have "\<dots> = dist x y + infdist y A"
   proof (rule cInf_eq, safe)
-    fix a assume "a \<in> A"
-    thus "dist x y + infdist y A \<le> dist x y + dist y a" by (auto intro: infdist_le)
+    fix a
+    assume "a \<in> A"
+    then show "dist x y + infdist y A \<le> dist x y + dist y a"
+      by (auto intro: infdist_le)
   next
-    fix i assume inf: "\<And>d. d \<in> {dist x y + dist y a |a. a \<in> A} \<Longrightarrow> i \<le> d"
-    hence "i - dist x y \<le> infdist y A" unfolding infdist_notempty[OF `A \<noteq> {}`] using `a \<in> A`
+    fix i
+    assume inf: "\<And>d. d \<in> {dist x y + dist y a |a. a \<in> A} \<Longrightarrow> i \<le> d"
+    then have "i - dist x y \<le> infdist y A"
+      unfolding infdist_notempty[OF `A \<noteq> {}`] using `a \<in> A`
       by (intro cInf_greatest) (auto simp: field_simps)
-    thus "i \<le> dist x y + infdist y A" by simp
+    then show "i \<le> dist x y + infdist y A"
+      by simp
   qed
   finally show ?thesis by simp
 qed
@@ -2015,27 +2066,32 @@
   show "infdist x A = 0"
   proof (rule ccontr)
     assume "infdist x A \<noteq> 0"
-    with infdist_nonneg[of x A] have "infdist x A > 0" by auto
-    hence "ball x (infdist x A) \<inter> closure A = {}"
+    with infdist_nonneg[of x A] have "infdist x A > 0"
+      by auto
+    then have "ball x (infdist x A) \<inter> closure A = {}"
       apply auto
       apply (metis `0 < infdist x A` `x \<in> closure A` closure_approachable dist_commute
         eucl_less_not_refl euclidean_trans(2) infdist_le)
       done
-    hence "x \<notin> closure A"
+    then have "x \<notin> closure A"
       by (metis `0 < infdist x A` centre_in_ball disjoint_iff_not_equal)
-    thus False using `x \<in> closure A` by simp
+    then show False using `x \<in> closure A` by simp
   qed
 next
   assume x: "infdist x A = 0"
-  then obtain a where "a \<in> A" by atomize_elim (metis all_not_in_conv assms)
-  show "x \<in> closure A" unfolding closure_approachable
-  proof (safe, rule ccontr)
-    fix e::real assume "0 < e"
+  then obtain a where "a \<in> A"
+    by atomize_elim (metis all_not_in_conv assms)
+  show "x \<in> closure A"
+    unfolding closure_approachable
+    apply safe
+  proof (rule ccontr)
+    fix e :: real
+    assume "e > 0"
     assume "\<not> (\<exists>y\<in>A. dist y x < e)"
-    hence "infdist x A \<ge> e" using `a \<in> A`
+    then have "infdist x A \<ge> e" using `a \<in> A`
       unfolding infdist_def
       by (force simp: dist_commute intro: cInf_greatest)
-    with x `0 < e` show False by auto
+    with x `e > 0` show False by auto
   qed
 qed
 
@@ -2052,7 +2108,8 @@
   assumes f: "(f ---> l) F"
   shows "((\<lambda>x. infdist (f x) A) ---> infdist l A) F"
 proof (rule tendstoI)
-  fix e ::real assume "0 < e"
+  fix e ::real
+  assume "e > 0"
   from tendstoD[OF f this]
   show "eventually (\<lambda>x. dist (infdist (f x) A) (infdist l A) < e) F"
   proof (eventually_elim)
@@ -2111,13 +2168,13 @@
   {
     fix x and e::real
     assume "x\<in>S" "e>0" "ball x e \<subseteq> S"
-    hence "\<exists>d>0. cball x d \<subseteq> S" unfolding subset_eq by (rule_tac x="e/2" in exI, auto)
+    then have "\<exists>d>0. cball x d \<subseteq> S" unfolding subset_eq by (rule_tac x="e/2" in exI, auto)
   }
   moreover
   {
     fix x and e::real
     assume "x\<in>S" "e>0" "cball x e \<subseteq> S"
-    hence "\<exists>d>0. ball x d \<subseteq> S"
+    then have "\<exists>d>0. ball x d \<subseteq> S"
       unfolding subset_eq
       apply(rule_tac x="e/2" in exI)
       apply auto
@@ -2142,11 +2199,14 @@
   shows "y islimpt ball x e \<longleftrightarrow> 0 < e \<and> y \<in> cball x e" (is "?lhs = ?rhs")
 proof
   assume "?lhs"
-  { assume "e \<le> 0"
-    hence *:"ball x e = {}" using ball_eq_empty[of x e] by auto
-    have False using `?lhs` unfolding * using islimpt_EMPTY[of y] by auto
+  {
+    assume "e \<le> 0"
+    then have *:"ball x e = {}"
+      using ball_eq_empty[of x e] by auto
+    have False using `?lhs`
+      unfolding * using islimpt_EMPTY[of y] by auto
   }
-  hence "e > 0" by (metis not_less)
+  then have "e > 0" by (metis not_less)
   moreover
   have "y \<in> cball x e"
     using closed_cball[of x e] islimpt_subset[of y "ball x e" "cball x e"]
@@ -2154,44 +2214,62 @@
     unfolding closed_limpt by auto
   ultimately show "?rhs" by auto
 next
-  assume "?rhs" hence "e>0"  by auto
-  { fix d::real assume "d>0"
+  assume "?rhs"
+  then have "e>0" by auto
+  {
+    fix d :: real
+    assume "d > 0"
     have "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
-    proof(cases "d \<le> dist x y")
-      case True thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
-      proof(cases "x=y")
-        case True hence False using `d \<le> dist x y` `d>0` by auto
-        thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d" by auto
+    proof (cases "d \<le> dist x y")
+      case True
+      then show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
+      proof (cases "x = y")
+        case True
+        then have False
+          using `d \<le> dist x y` `d>0` by auto
+        then show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
+          by auto
       next
         case False
-
-        have "dist x (y - (d / (2 * dist y x)) *\<^sub>R (y - x))
-              = norm (x - y + (d / (2 * norm (y - x))) *\<^sub>R (y - x))"
-          unfolding mem_cball mem_ball dist_norm diff_diff_eq2 diff_add_eq[THEN sym] by auto
+        have "dist x (y - (d / (2 * dist y x)) *\<^sub>R (y - x)) =
+          norm (x - y + (d / (2 * norm (y - x))) *\<^sub>R (y - x))"
+          unfolding mem_cball mem_ball dist_norm diff_diff_eq2 diff_add_eq[THEN sym]
+          by auto
         also have "\<dots> = \<bar>- 1 + d / (2 * norm (x - y))\<bar> * norm (x - y)"
           using scaleR_left_distrib[of "- 1" "d / (2 * norm (y - x))", THEN sym, of "y - x"]
           unfolding scaleR_minus_left scaleR_one
           by (auto simp add: norm_minus_commute)
         also have "\<dots> = \<bar>- norm (x - y) + d / 2\<bar>"
           unfolding abs_mult_pos[of "norm (x - y)", OF norm_ge_zero[of "x - y"]]
-          unfolding distrib_right using `x\<noteq>y`[unfolded dist_nz, unfolded dist_norm] by auto
-        also have "\<dots> \<le> e - d/2" using `d \<le> dist x y` and `d>0` and `?rhs` by(auto simp add: dist_norm)
-        finally have "y - (d / (2 * dist y x)) *\<^sub>R (y - x) \<in> ball x e" using `d>0` by auto
-
+          unfolding distrib_right using `x\<noteq>y`[unfolded dist_nz, unfolded dist_norm]
+          by auto
+        also have "\<dots> \<le> e - d/2" using `d \<le> dist x y` and `d>0` and `?rhs`
+          by (auto simp add: dist_norm)
+        finally have "y - (d / (2 * dist y x)) *\<^sub>R (y - x) \<in> ball x e" using `d>0`
+          by auto
         moreover
-
         have "(d / (2*dist y x)) *\<^sub>R (y - x) \<noteq> 0"
-          using `x\<noteq>y`[unfolded dist_nz] `d>0` unfolding scaleR_eq_0_iff by (auto simp add: dist_commute)
+          using `x\<noteq>y`[unfolded dist_nz] `d>0` unfolding scaleR_eq_0_iff
+          by (auto simp add: dist_commute)
         moreover
-        have "dist (y - (d / (2 * dist y x)) *\<^sub>R (y - x)) y < d" unfolding dist_norm apply simp unfolding norm_minus_cancel
-          using `d>0` `x\<noteq>y`[unfolded dist_nz] dist_commute[of x y]
-          unfolding dist_norm by auto
-        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
+        have "dist (y - (d / (2 * dist y x)) *\<^sub>R (y - x)) y < d"
+          unfolding dist_norm
+          apply simp
+          unfolding norm_minus_cancel
+          using `d > 0` `x\<noteq>y`[unfolded dist_nz] dist_commute[of x y]
+          unfolding dist_norm
+          apply auto
+          done
+        ultimately show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
+          apply (rule_tac x = "y - (d / (2*dist y x)) *\<^sub>R (y - x)" in bexI)
+          apply auto
+          done
       qed
     next
-      case False hence "d > dist x y" by auto
-      show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
-      proof(cases "x=y")
+      case False
+      then have "d > dist x y" by auto
+      show "\<exists>x' \<in> ball x e. x' \<noteq> y \<and> dist x' y < d"
+      proof (cases "x = y")
         case True
         obtain z where **: "z \<noteq> y" "dist z y < min e d"
           using perfect_choose_dist[of "min e d" y]
@@ -2199,20 +2277,30 @@
         show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
           unfolding `x = y`
           using `z \<noteq> y` **
-          by (rule_tac x=z in bexI, auto simp add: dist_commute)
+          apply (rule_tac x=z in bexI)
+          apply (auto simp add: dist_commute)
+          done
       next
-        case False thus "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
-          using `d>0` `d > dist x y` `?rhs` by(rule_tac x=x in bexI, auto)
+        case False
+        then show "\<exists>x'\<in>ball x e. x' \<noteq> y \<and> dist x' y < d"
+          using `d>0` `d > dist x y` `?rhs`
+          apply (rule_tac x=x in bexI)
+          apply auto
+          done
       qed
-    qed  }
-  thus "?lhs" unfolding mem_cball islimpt_approachable mem_ball by auto
+    qed
+  }
+  then show "?lhs"
+    unfolding mem_cball islimpt_approachable mem_ball by auto
 qed
 
 lemma closure_ball_lemma:
   fixes x y :: "'a::real_normed_vector"
-  assumes "x \<noteq> y" shows "y islimpt ball x (dist x y)"
+  assumes "x \<noteq> y"
+  shows "y islimpt ball x (dist x y)"
 proof (rule islimptI)
-  fix T assume "y \<in> T" "open T"
+  fix T
+  assume "y \<in> T" "open T"
   then obtain r where "0 < r" "\<forall>z. dist z y < r \<longrightarrow> z \<in> T"
     unfolding open_dist by fast
   (* choose point between x and y, within distance r of y. *)
@@ -2223,7 +2311,8 @@
   have "dist z y < r"
     unfolding z_def k_def using `0 < r`
     by (simp add: dist_norm min_def)
-  hence "z \<in> T" using `\<forall>z. dist z y < r \<longrightarrow> z \<in> T` by simp
+  then have "z \<in> T"
+    using `\<forall>z. dist z y < r \<longrightarrow> z \<in> T` by simp
   have "dist x z < dist x y"
     unfolding z_def2 dist_norm
     apply (simp add: norm_minus_commute)
@@ -2233,7 +2322,8 @@
     apply (simp add: k_def divide_pos_pos zero_less_dist_iff `0 < r` `x \<noteq> y`)
     apply (simp add: zero_less_dist_iff `x \<noteq> y`)
     done
-  hence "z \<in> ball x (dist x y)" by simp
+  then have "z \<in> ball x (dist x y)"
+    by simp
   have "z \<noteq> y"
     unfolding z_def k_def using `x \<noteq> y` `0 < r`
     by (simp add: min_def)
@@ -2265,51 +2355,72 @@
   shows "interior (cball x e) = ball x e"
 proof (cases "e\<ge>0")
   case False note cs = this
-  from cs have "ball x e = {}" using ball_empty[of e x] by auto moreover
-  { fix y assume "y \<in> cball x e"
-    hence False unfolding mem_cball using dist_nz[of x y] cs by auto  }
-  hence "cball x e = {}" by auto
-  hence "interior (cball x e) = {}" using interior_empty by auto
+  from cs have "ball x e = {}"
+    using ball_empty[of e x] by auto
+  moreover
+  {
+    fix y
+    assume "y \<in> cball x e"
+    then have False
+      unfolding mem_cball using dist_nz[of x y] cs by auto
+  }
+  then have "cball x e = {}" by auto
+  then have "interior (cball x e) = {}"
+    using interior_empty by auto
   ultimately show ?thesis by blast
 next
   case True note cs = this
-  have "ball x e \<subseteq> cball x e" using ball_subset_cball by auto moreover
-  { fix S y assume as: "S \<subseteq> cball x e" "open S" "y\<in>S"
-    then obtain d where "d>0" and d:"\<forall>x'. dist x' y < d \<longrightarrow> x' \<in> S" unfolding open_dist by blast
-
+  have "ball x e \<subseteq> cball x e"
+    using ball_subset_cball by auto
+  moreover
+  {
+    fix S y
+    assume as: "S \<subseteq> cball x e" "open S" "y\<in>S"
+    then obtain d where "d>0" and d: "\<forall>x'. dist x' y < d \<longrightarrow> x' \<in> S"
+      unfolding open_dist by blast
     then obtain xa where xa_y: "xa \<noteq> y" and xa: "dist xa y < d"
       using perfect_choose_dist [of d] by auto
-    have "xa\<in>S" using d[THEN spec[where x=xa]] using xa by(auto simp add: dist_commute)
-    hence xa_cball:"xa \<in> cball x e" using as(1) by auto
-
-    hence "y \<in> ball x e" proof(cases "x = y")
+    have "xa \<in> S"
+      using d[THEN spec[where x = xa]]
+      using xa by (auto simp add: dist_commute)
+    then have xa_cball: "xa \<in> cball x e"
+      using as(1) by auto
+    then have "y \<in> ball x e"
+    proof (cases "x = y")
       case True
-      hence "e>0" using xa_y[unfolded dist_nz] xa_cball[unfolded mem_cball]
+      then have "e > 0"
+        using xa_y[unfolded dist_nz] xa_cball[unfolded mem_cball]
         by (auto simp add: dist_commute)
-      thus "y \<in> ball x e" using `x = y ` by simp
+      then show "y \<in> ball x e"
+        using `x = y ` by simp
     next
       case False
-      have "dist (y + (d / 2 / dist y x) *\<^sub>R (y - x)) y < d" unfolding dist_norm
+      have "dist (y + (d / 2 / dist y x) *\<^sub>R (y - x)) y < d"
+        unfolding dist_norm
         using `d>0` norm_ge_zero[of "y - x"] `x \<noteq> y` by auto
-      hence *:"y + (d / 2 / dist y x) *\<^sub>R (y - x) \<in> cball x e"
+      then have *: "y + (d / 2 / dist y x) *\<^sub>R (y - x) \<in> cball x e"
         using d as(1)[unfolded subset_eq] by blast
       have "y - x \<noteq> 0" using `x \<noteq> y` by auto
-      hence **:"d / (2 * norm (y - x)) > 0"
+      then have **:"d / (2 * norm (y - x)) > 0"
         unfolding zero_less_norm_iff[THEN sym]
         using `d>0` divide_pos_pos[of d "2*norm (y - x)"] by auto
-
-      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)"
+      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)"
         by (auto simp add: dist_norm algebra_simps)
       also have "\<dots> = norm ((1 + d / (2 * norm (y - x))) *\<^sub>R (y - x))"
         by (auto simp add: algebra_simps)
       also have "\<dots> = \<bar>1 + d / (2 * norm (y - x))\<bar> * norm (y - x)"
         using ** by auto
-      also have "\<dots> = (dist y x) + d/2"using ** by (auto simp add: distrib_right dist_norm)
-      finally have "e \<ge> dist x y +d/2" using *[unfolded mem_cball] by (auto simp add: dist_commute)
-      thus "y \<in> ball x e" unfolding mem_ball using `d>0` by auto
+      also have "\<dots> = (dist y x) + d/2"
+        using ** by (auto simp add: distrib_right dist_norm)
+      finally have "e \<ge> dist x y +d/2"
+        using *[unfolded mem_cball] by (auto simp add: dist_commute)
+      then show "y \<in> ball x e"
+        unfolding mem_ball using `d>0` by auto
     qed
   }
-  hence "\<forall>S \<subseteq> cball x e. open S \<longrightarrow> S \<subseteq> ball x e" by auto
+  then have "\<forall>S \<subseteq> cball x e. open S \<longrightarrow> S \<subseteq> ball x e"
+    by auto
   ultimately show ?thesis
     using interior_unique[of "ball x e" "cball x e"] using open_ball[of x e] by auto
 qed
@@ -2335,7 +2446,7 @@
   apply (metis zero_le_dist dist_self order_less_le_trans)
   done
 
-lemma cball_empty: "e < 0 ==> cball x e = {}"
+lemma cball_empty: "e < 0 \<Longrightarrow> cball x e = {}"
   by (simp add: cball_eq_empty)
 
 lemma cball_eq_sing:
@@ -2345,7 +2456,8 @@
   assume e: "0 < e"
   obtain a where "a \<noteq> x" "dist a x < e"
     using perfect_choose_dist [OF e] by auto
-  hence "a \<noteq> x" "dist x a \<le> e" by (auto simp add: dist_commute)
+  then have "a \<noteq> x" "dist x a \<le> e"
+    by (auto simp add: dist_commute)
   with e show ?thesis by (auto simp add: set_eq_iff)
 qed auto
 
@@ -2377,9 +2489,14 @@
   unfolding bounded_any_center [where a=0]
   by (simp add: dist_norm)
 
-lemma bounded_realI: assumes "\<forall>x\<in>s. abs (x::real) \<le> B" shows "bounded s"
-  unfolding bounded_def dist_real_def apply(rule_tac x=0 in exI)
-  using assms by auto
+lemma bounded_realI:
+  assumes "\<forall>x\<in>s. abs (x::real) \<le> B"
+  shows "bounded s"
+  unfolding bounded_def dist_real_def
+  apply (rule_tac x=0 in exI)
+  using assms
+  apply auto
+  done
 
 lemma bounded_empty [simp]: "bounded {}"
   by (simp add: bounded_def)
@@ -2402,7 +2519,7 @@
     then obtain f where f: "\<forall>n. f n \<in> S"  "(f ---> y) sequentially"
       unfolding closure_sequential by auto
     have "\<forall>n. f n \<in> S \<longrightarrow> dist x (f n) \<le> a" using a by simp
-    hence "eventually (\<lambda>n. dist x (f n) \<le> a) sequentially"
+    then have "eventually (\<lambda>n. dist x (f n) \<le> a) sequentially"
       by (rule eventually_mono, simp add: f(1))
     have "dist x y \<le> a"
       apply (rule Lim_dist_ubound [of sequentially f])
@@ -2411,7 +2528,8 @@
       apply fact
       done
   }
-  thus ?thesis unfolding bounded_def by auto
+  then show ?thesis
+    unfolding bounded_def by auto
 qed
 
 lemma bounded_cball[simp,intro]: "bounded (cball x e)"
@@ -2445,8 +2563,8 @@
 lemma bounded_insert [simp]: "bounded (insert x S) \<longleftrightarrow> bounded S"
 proof -
   have "\<forall>y\<in>{x}. dist x y \<le> 0" by simp
-  hence "bounded {x}" unfolding bounded_def by fast
-  thus ?thesis by (metis insert_is_Un bounded_Un)
+  then have "bounded {x}" unfolding bounded_def by fast
+  then show ?thesis by (metis insert_is_Un bounded_Un)
 qed
 
 lemma finite_imp_bounded [intro]: "finite S \<Longrightarrow> bounded S"
@@ -2489,14 +2607,16 @@
   from assms(2) obtain B where B:"B>0" "\<forall>x. norm (f x) \<le> B * norm x"
     using bounded_linear.pos_bounded by (auto simp add: mult_ac)
   {
-    fix x assume "x\<in>S"
-    hence "norm x \<le> b" using b by auto
-    hence "norm (f x) \<le> B * b" using B(2)
+    fix x
+    assume "x\<in>S"
+    then have "norm x \<le> b" using b by auto
+    then have "norm (f x) \<le> B * b" using B(2)
       apply (erule_tac x=x in allE)
       apply (metis B(1) B(2) order_trans mult_le_cancel_left_pos)
       done
   }
-  thus ?thesis unfolding bounded_pos
+  then show ?thesis
+    unfolding bounded_pos
     apply (rule_tac x="b*B" in exI)
     using b B mult_pos_pos [of b B]
     apply (auto simp add: mult_commute)
@@ -2514,16 +2634,16 @@
   fixes S :: "'a::real_normed_vector set"
   assumes "bounded S"
   shows "bounded ((\<lambda>x. a + x) ` S)"
-proof-
+proof -
   from assms obtain b where b:"b>0" "\<forall>x\<in>S. norm x \<le> b"
     unfolding bounded_pos by auto
   {
     fix x
     assume "x\<in>S"
-    hence "norm (a + x) \<le> b + norm a"
+    then have "norm (a + x) \<le> b + norm a"
       using norm_triangle_ineq[of a x] b by auto
   }
-  thus ?thesis
+  then show ?thesis
     unfolding bounded_pos
     using norm_ge_zero[of a] b(1) and add_strict_increasing[of b 0 "norm a"]
     by (auto intro!: exI[of _ "b + norm a"])
@@ -2540,19 +2660,21 @@
 lemma bounded_has_Sup:
   fixes S :: "real set"
   assumes "bounded S" "S \<noteq> {}"
-  shows "\<forall>x\<in>S. x <= Sup S" and "\<forall>b. (\<forall>x\<in>S. x <= b) \<longrightarrow> Sup S <= b"
+  shows "\<forall>x\<in>S. x \<le> Sup S"
+    and "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b"
 proof
-  fix x assume "x\<in>S"
-  thus "x \<le> Sup S"
+  fix x
+  assume "x\<in>S"
+  then show "x \<le> Sup S"
     by (metis cSup_upper abs_le_D1 assms(1) bounded_real)
 next
-  show "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b" using assms
-    by (metis cSup_least)
+  show "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b"
+    using assms by (metis cSup_least)
 qed
 
 lemma Sup_insert:
   fixes S :: "real set"
-  shows "bounded S ==> Sup(insert x S) = (if S = {} then x else max x (Sup S))" 
+  shows "bounded S ==> Sup(insert x S) = (if S = {} then x else max x (Sup S))"
   apply (subst cSup_insert_If)
   apply (rule bounded_has_Sup(1)[of S, rule_format])
   apply (auto simp: sup_max)
@@ -2569,22 +2691,23 @@
 lemma bounded_has_Inf:
   fixes S :: "real set"
   assumes "bounded S"  "S \<noteq> {}"
-  shows "\<forall>x\<in>S. x >= Inf S" and "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> Inf S >= b"
+  shows "\<forall>x\<in>S. x \<ge> Inf S"
+    and "\<forall>b. (\<forall>x\<in>S. x \<ge> b) \<longrightarrow> Inf S \<ge> b"
 proof
   fix x
   assume "x\<in>S"
-  from assms(1) obtain a where a:"\<forall>x\<in>S. \<bar>x\<bar> \<le> a"
+  from assms(1) obtain a where a: "\<forall>x\<in>S. \<bar>x\<bar> \<le> a"
     unfolding bounded_real by auto
-  thus "x \<ge> Inf S" using `x\<in>S`
+  then show "x \<ge> Inf S" using `x\<in>S`
     by (metis cInf_lower_EX abs_le_D2 minus_le_iff)
 next
-  show "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> Inf S \<ge> b" using assms
-    by (metis cInf_greatest)
+  show "\<forall>b. (\<forall>x\<in>S. x >= b) \<longrightarrow> Inf S \<ge> b"
+    using assms by (metis cInf_greatest)
 qed
 
 lemma Inf_insert:
   fixes S :: "real set"
-  shows "bounded S ==> Inf(insert x S) = (if S = {} then x else min x (Inf S))" 
+  shows "bounded S ==> Inf(insert x S) = (if S = {} then x else min x (Inf S))"
   apply (subst cInf_insert_if)
   apply (rule bounded_has_Inf(1)[of S, rule_format])
   apply (auto simp: inf_min)
@@ -2592,8 +2715,11 @@
 
 lemma Inf_insert_finite:
   fixes S :: "real set"
-  shows "finite S ==> Inf(insert x S) = (if S = {} then x else min x (Inf S))"
-  by (rule Inf_insert, rule finite_imp_bounded, simp)
+  shows "finite S \<Longrightarrow> Inf(insert x S) = (if S = {} then x else min x (Inf S))"
+  apply (rule Inf_insert)
+  apply (rule finite_imp_bounded)
+  apply simp
+  done
 
 subsection {* Compactness *}
 
@@ -2606,22 +2732,23 @@
   assume "\<not> (\<exists>x \<in> s. x islimpt t)"
   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)"
     unfolding islimpt_def
-    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
-  obtain g where g:"g\<subseteq>{t. \<exists>x. x \<in> s \<and> t = f x}" "finite g" "s \<subseteq> \<Union>g"
+    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
+  obtain g where g: "g\<subseteq>{t. \<exists>x. x \<in> s \<and> t = f x}" "finite g" "s \<subseteq> \<Union>g"
     using assms(1)[unfolded compact_eq_heine_borel, THEN spec[where x="{t. \<exists>x. x\<in>s \<and> t = f x}"]]
     using f by auto
   from g(1,3) have g':"\<forall>x\<in>g. \<exists>xa \<in> s. x = f xa" by auto
   {
     fix x y
     assume "x\<in>t" "y\<in>t" "f x = f y"
-    hence "x \<in> f x"  "y \<in> f x \<longrightarrow> y = x"
+    then have "x \<in> f x"  "y \<in> f x \<longrightarrow> y = x"
       using f[THEN bspec[where x=x]] and `t\<subseteq>s` by auto
-    hence "x = y"
+    then have "x = y"
       using `f x = f y` and f[THEN bspec[where x=y]] and `y\<in>t` and `t\<subseteq>s` by auto
   }
-  hence "inj_on f t"
+  then have "inj_on f t"
     unfolding inj_on_def by simp
-  hence "infinite (f ` t)"
+  then have "infinite (f ` t)"
     using assms(2) using finite_imageD by auto
   moreover
   {
@@ -2630,12 +2757,12 @@
     from g(3) assms(3) `x\<in>t` obtain h where "h\<in>g" and "x\<in>h" by auto
     then obtain y where "y\<in>s" "h = f y"
       using g'[THEN bspec[where x=h]] by auto
-    hence "y = x"
+    then have "y = x"
       using f[THEN bspec[where x=y]] and `x\<in>t` and `x\<in>h`[unfolded `h = f y`] by auto
-    hence False
+    then have False
       using `f x \<notin> g` `h\<in>g` unfolding `h = f y` by auto
   }
-  hence "f ` t \<subseteq> g" by auto
+  then have "f ` t \<subseteq> g" by auto
   ultimately show False
     using g(2) using finite_subset by auto
 qed
@@ -2668,12 +2795,14 @@
   moreover
   have "(\<lambda>n. f (r n)) ----> l"
   proof (rule topological_tendstoI)
-    fix S assume "open S" "l \<in> S"
+    fix S
+    assume "open S" "l \<in> S"
     with A(3) have "eventually (\<lambda>i. A i \<subseteq> S) sequentially" by auto
     moreover
     {
       fix i
-      assume "Suc 0 \<le> i" then have "f (r i) \<in> A i"
+      assume "Suc 0 \<le> i"
+      then have "f (r i) \<in> A i"
         by (cases i) (simp_all add: r_def s)
     }
     then have "eventually (\<lambda>i. f (r i) \<in> A i) sequentially"
@@ -2687,16 +2816,17 @@
 
 lemma sequence_infinite_lemma:
   fixes f :: "nat \<Rightarrow> 'a::t1_space"
-  assumes "\<forall>n. f n \<noteq> l" and "(f ---> l) sequentially"
+  assumes "\<forall>n. f n \<noteq> l"
+    and "(f ---> l) sequentially"
   shows "infinite (range f)"
 proof
   assume "finite (range f)"
-  hence "closed (range f)" by (rule finite_imp_closed)
-  hence "open (- range f)" by (rule open_Compl)
+  then have "closed (range f)" by (rule finite_imp_closed)
+  then have "open (- range f)" by (rule open_Compl)
   from assms(1) have "l \<in> - range f" by auto
   from assms(2) have "eventually (\<lambda>n. f n \<in> - range f) sequentially"
     using `open (- range f)` `l \<in> - range f` by (rule topological_tendstoD)
-  thus False unfolding eventually_sequentially by auto
+  then show False unfolding eventually_sequentially by auto
 qed
 
 lemma closure_insert:
@@ -2715,7 +2845,8 @@
   assume *: "x islimpt (insert a s)"
   show "x islimpt s"
   proof (rule islimptI)
-    fix t assume t: "x \<in> t" "open t"
+    fix t
+    assume t: "x \<in> t" "open t"
     show "\<exists>y\<in>s. y \<in> t \<and> y \<noteq> x"
     proof (cases "x = a")
       case True
@@ -2728,11 +2859,12 @@
         by (simp_all add: open_Diff)
       obtain y where "y \<in> insert a s" "y \<in> t - {a}" "y \<noteq> x"
         using * t' by (rule islimptE)
-      thus ?thesis by auto
+      then show ?thesis by auto
     qed
   qed
 next
-  assume "x islimpt s" thus "x islimpt (insert a s)"
+  assume "x islimpt s"
+  then show "x islimpt (insert a s)"
     by (rule islimpt_subset) auto
 qed
 
@@ -2750,14 +2882,17 @@
   fixes l :: "'a :: t1_space"
   shows "l islimpt S \<longleftrightarrow> (\<forall>U. l\<in>U \<longrightarrow> open U \<longrightarrow> infinite (U \<inter> S))"
 proof (safe intro!: islimptI)
-  fix U assume "l islimpt S" "l \<in> U" "open U" "finite (U \<inter> S)"
+  fix U
+  assume "l islimpt S" "l \<in> U" "open U" "finite (U \<inter> S)"
   then have "l islimpt S" "l \<in> (U - (U \<inter> S - {l}))" "open (U - (U \<inter> S - {l}))"
     by (auto intro: finite_imp_closed)
   then show False
     by (rule islimptE) auto
 next
-  fix T assume *: "\<forall>U. l\<in>U \<longrightarrow> open U \<longrightarrow> infinite (U \<inter> S)" "l \<in> T" "open T"
-  then have "infinite (T \<inter> S - {l})" by auto
+  fix T
+  assume *: "\<forall>U. l\<in>U \<longrightarrow> open U \<longrightarrow> infinite (U \<inter> S)" "l \<in> T" "open T"
+  then have "infinite (T \<inter> S - {l})"
+    by auto
   then have "\<exists>x. x \<in> (T \<inter> S - {l})"
     unfolding ex_in_conv by (intro notI) simp
   then show "\<exists>y\<in>S. y \<in> T \<and> y \<noteq> l"
@@ -2773,7 +2908,8 @@
 
 lemma sequence_unique_limpt:
   fixes f :: "nat \<Rightarrow> 'a::t2_space"
-  assumes "(f ---> l) sequentially" and "l' islimpt (range f)"
+  assumes "(f ---> l) sequentially"
+    and "l' islimpt (range f)"
   shows "l' = l"
 proof (rule ccontr)
   assume "l' \<noteq> l"
@@ -2784,15 +2920,22 @@
   then obtain N where "\<forall>n\<ge>N. f n \<in> t"
     unfolding eventually_sequentially by auto
 
-  have "UNIV = {..<N} \<union> {N..}" by auto
-  hence "l' islimpt (f ` ({..<N} \<union> {N..}))" using assms(2) by simp
-  hence "l' islimpt (f ` {..<N} \<union> f ` {N..})" by (simp add: image_Un)
-  hence "l' islimpt (f ` {N..})" by (simp add: islimpt_union_finite)
+  have "UNIV = {..<N} \<union> {N..}"
+    by auto
+  then have "l' islimpt (f ` ({..<N} \<union> {N..}))"
+    using assms(2) by simp
+  then have "l' islimpt (f ` {..<N} \<union> f ` {N..})"
+    by (simp add: image_Un)
+  then have "l' islimpt (f ` {N..})"
+    by (simp add: islimpt_union_finite)
   then obtain y where "y \<in> f ` {N..}" "y \<in> s" "y \<noteq> l'"
     using `l' \<in> s` `open s` by (rule islimptE)
-  then obtain n where "N \<le> n" "f n \<in> s" "f n \<noteq> l'" by auto
-  with `\<forall>n\<ge>N. f n \<in> t` have "f n \<in> s \<inter> t" by simp
-  with `s \<inter> t = {}` show False by simp
+  then obtain n where "N \<le> n" "f n \<in> s" "f n \<noteq> l'"
+    by auto
+  with `\<forall>n\<ge>N. f n \<in> t` have "f n \<in> s \<inter> t"
+    by simp
+  with `s \<inter> t = {}` show False
+    by simp
 qed
 
 lemma bolzano_weierstrass_imp_closed:
@@ -2803,21 +2946,22 @@
   {
     fix x l
     assume as: "\<forall>n::nat. x n \<in> s" "(x ---> l) sequentially"
-    hence "l \<in> s"
+    then have "l \<in> s"
     proof (cases "\<forall>n. x n \<noteq> l")
       case False
-      thus "l\<in>s" using as(1) by auto
+      then show "l\<in>s" using as(1) by auto
     next
       case True note cas = this
       with as(2) have "infinite (range x)"
         using sequence_infinite_lemma[of x l] by auto
       then obtain l' where "l'\<in>s" "l' islimpt (range x)"
         using assms[THEN spec[where x="range x"]] as(1) by auto
-      thus "l\<in>s" using sequence_unique_limpt[of x l l']
+      then show "l\<in>s" using sequence_unique_limpt[of x l l']
         using as cas by auto
     qed
   }
-  thus ?thesis unfolding closed_sequential_limits by fast
+  then show ?thesis
+    unfolding closed_sequential_limits by fast
 qed
 
 lemma compact_imp_bounded:
@@ -2830,14 +2974,15 @@
     by (rule compactE_image)
   from `finite D` have "bounded (\<Union>x\<in>D. ball x 1)"
     by (simp add: bounded_UN)
-  thus "bounded U" using `U \<subseteq> (\<Union>x\<in>D. ball x 1)` 
+  then show "bounded U" using `U \<subseteq> (\<Union>x\<in>D. ball x 1)`
     by (rule bounded_subset)
 qed
 
 text{* In particular, some common special cases. *}
 
 lemma compact_union [intro]:
-  assumes "compact s" "compact t" shows " compact (s \<union> t)"
+  assumes "compact s" "compact t"
+  shows " compact (s \<union> t)"
 proof (rule compactI)
   fix f
   assume *: "Ball f open" "s \<union> t \<subseteq> \<Union>f"
@@ -2858,14 +3003,16 @@
   unfolding SUP_def by (rule compact_Union) auto
 
 lemma closed_inter_compact [intro]:
-  assumes "closed s" and "compact t"
+  assumes "closed s"
+    and "compact t"
   shows "compact (s \<inter> t)"
   using compact_inter_closed [of t s] assms
   by (simp add: Int_commute)
 
 lemma compact_inter [intro]:
   fixes s t :: "'a :: t2_space set"
-  assumes "compact s" and "compact t"
+  assumes "compact s"
+    and "compact t"
   shows "compact (s \<inter> t)"
   using assms by (intro compact_inter_closed compact_imp_closed)
 
@@ -2873,11 +3020,12 @@
   unfolding compact_eq_heine_borel by auto
 
 lemma compact_insert [simp]:
-  assumes "compact s" shows "compact (insert x s)"
+  assumes "compact s"
+  shows "compact (insert x s)"
 proof -
   have "compact ({x} \<union> s)"
     using compact_sing assms by (rule compact_union)
-  thus ?thesis by simp
+  then show ?thesis by simp
 qed
 
 lemma finite_imp_compact: "finite s \<Longrightarrow> compact s"
@@ -2898,7 +3046,9 @@
     (\<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> {})"
   (is "_ \<longleftrightarrow> ?R")
 proof (safe intro!: compact_eq_heine_borel[THEN iffD2])
-  fix A assume "compact U" and A: "\<forall>a\<in>A. closed a" "U \<inter> \<Inter>A = {}"
+  fix A
+  assume "compact U"
+    and A: "\<forall>a\<in>A. closed a" "U \<inter> \<Inter>A = {}"
     and fi: "\<forall>B \<subseteq> A. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {}"
   from A have "(\<forall>a\<in>uminus`A. open a) \<and> U \<subseteq> \<Union>(uminus`A)"
     by auto
@@ -2907,8 +3057,10 @@
   with fi[THEN spec, of B] show False
     by (auto dest: finite_imageD intro: inj_setminus)
 next
-  fix A assume ?R and cover: "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
-  from cover have "U \<inter> \<Inter>(uminus`A) = {}" "\<forall>a\<in>uminus`A. closed a"
+  fix A
+  assume ?R
+  assume "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
+  then have "U \<inter> \<Inter>(uminus`A) = {}" "\<forall>a\<in>uminus`A. closed a"
     by auto
   with `?R` obtain B where "B \<subseteq> A" "finite (uminus`B)" "U \<inter> \<Inter>(uminus`B) = {}"
     by (metis subset_image_iff)
@@ -2956,8 +3108,9 @@
   "x \<in> closure X \<longleftrightarrow> (\<forall>A. \<forall>S\<subseteq>A. open S \<longrightarrow> x \<in> S \<longrightarrow> X \<inter> A \<noteq> {})"
 proof safe
   assume x: "x \<in> closure X"
-  fix S A assume "open S" "x \<in> S" "X \<inter> A = {}" "S \<subseteq> A"
-  then have "x \<notin> closure (-S)" 
+  fix S A
+  assume "open S" "x \<in> S" "X \<inter> A = {}" "S \<subseteq> A"
+  then have "x \<notin> closure (-S)"
     by (auto simp: closure_complement subset_eq[symmetric] intro: interiorI)
   with x have "x \<in> closure X - closure (-S)"
     by auto
@@ -2975,14 +3128,16 @@
 lemma compact_filter:
   "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))"
 proof (intro allI iffI impI compact_fip[THEN iffD2] notI)
-  fix F assume "compact U" and F: "F \<noteq> bot" "eventually (\<lambda>x. x \<in> U) F"
-  from F have "U \<noteq> {}"
+  fix F
+  assume "compact U"
+  assume F: "F \<noteq> bot" "eventually (\<lambda>x. x \<in> U) F"
+  then have "U \<noteq> {}"
     by (auto simp: eventually_False)
 
   def Z \<equiv> "closure ` {A. eventually (\<lambda>x. x \<in> A) F}"
   then have "\<forall>z\<in>Z. closed z"
     by auto
-  moreover 
+  moreover
   have ev_Z: "\<And>z. z \<in> Z \<Longrightarrow> eventually (\<lambda>x. x \<in> z) F"
     unfolding Z_def by (auto elim: eventually_elim1 intro: set_mp[OF closure_subset])
   have "(\<forall>B \<subseteq> Z. finite B \<longrightarrow> U \<inter> \<Inter>B \<noteq> {})"
@@ -2997,7 +3152,8 @@
   qed
   ultimately have "U \<inter> \<Inter>Z \<noteq> {}"
     using `compact U` unfolding compact_fip by blast
-  then obtain x where "x \<in> U" and x: "\<And>z. z \<in> Z \<Longrightarrow> x \<in> z" by auto
+  then obtain x where "x \<in> U" and x: "\<And>z. z \<in> Z \<Longrightarrow> x \<in> z"
+    by auto
 
   have "\<And>P. eventually P (inf (nhds x) F) \<Longrightarrow> P \<noteq> bot"
     unfolding eventually_inf eventually_nhds
@@ -3012,8 +3168,8 @@
   with `x \<in> U` show "\<exists>x\<in>U. inf (nhds x) F \<noteq> bot"
     by (metis eventually_bot)
 next
-  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 = {}"
-
+  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 = {}"
   def P' \<equiv> "(\<lambda>a (x::'a). x \<in> a)"
   then have inj_P': "\<And>A. inj_on P' A"
     by (auto intro!: inj_onI simp: fun_eq_iff)
@@ -3021,33 +3177,42 @@
   have "F \<noteq> bot"
     unfolding F_def
   proof (safe intro!: filter_from_subbase_not_bot)
-    fix X assume "X \<subseteq> P' ` insert U A" "finite X" "Inf X = bot"
+    fix X
+    assume "X \<subseteq> P' ` insert U A" "finite X" "Inf X = bot"
     then obtain B where "B \<subseteq> insert U A" "finite B" and B: "Inf (P' ` B) = bot"
       unfolding subset_image_iff by (auto intro: inj_P' finite_imageD)
-    with A(2)[THEN spec, of "B - {U}"] have "U \<inter> \<Inter>(B - {U}) \<noteq> {}" by auto
-    with B show False by (auto simp: P'_def fun_eq_iff)
+    with A(2)[THEN spec, of "B - {U}"] have "U \<inter> \<Inter>(B - {U}) \<noteq> {}"
+      by auto
+    with B show False
+      by (auto simp: P'_def fun_eq_iff)
   qed
   moreover have "eventually (\<lambda>x. x \<in> U) F"
     unfolding F_def by (rule eventually_filter_from_subbaseI) (auto simp: P'_def)
-  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)"
+  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)"
   ultimately obtain x where "x \<in> U" and x: "inf (nhds x) F \<noteq> bot"
     by auto
 
-  { fix V assume "V \<in> A"
+  {
+    fix V
+    assume "V \<in> A"
     then have V: "eventually (\<lambda>x. x \<in> V) F"
       by (auto simp add: F_def image_iff P'_def intro!: eventually_filter_from_subbaseI)
     have "x \<in> closure V"
       unfolding closure_iff_nhds_not_empty
     proof (intro impI allI)
-      fix S A assume "open S" "x \<in> S" "S \<subseteq> A"
-      then have "eventually (\<lambda>x. x \<in> A) (nhds x)" by (auto simp: eventually_nhds)
+      fix S A
+      assume "open S" "x \<in> S" "S \<subseteq> A"
+      then have "eventually (\<lambda>x. x \<in> A) (nhds x)"
+        by (auto simp: eventually_nhds)
       with V have "eventually (\<lambda>x. x \<in> V \<inter> A) (inf (nhds x) F)"
         by (auto simp: eventually_inf)
       with x show "V \<inter> A \<noteq> {}"
         by (auto simp del: Int_iff simp add: trivial_limit_def)
     qed
     then have "x \<in> V"
-      using `V \<in> A` A(1) by simp }
+      using `V \<in> A` A(1) by simp
+  }
   with `x\<in>U` have "x \<in> U \<inter> \<Inter>A" by auto
   with `U \<inter> \<Inter>A = {}` show False by auto
 qed
@@ -3070,12 +3235,14 @@
 
 lemma countably_compact_imp_compact:
   assumes "countably_compact U"
-  assumes ccover: "countable B" "\<forall>b\<in>B. open b"
-  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"
+    and ccover: "countable B" "\<forall>b\<in>B. open b"
+    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"
   shows "compact U"
-  using `countably_compact U` unfolding compact_eq_heine_borel countably_compact_def
+  using `countably_compact U`
+  unfolding compact_eq_heine_borel countably_compact_def
 proof safe
-  fix A assume A: "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
+  fix A
+  assume A: "\<forall>a\<in>A. open a" "U \<subseteq> \<Union>A"
   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)"
 
   moreover def C \<equiv> "{b\<in>B. \<exists>a\<in>A. b \<inter> U \<subseteq> a}"
@@ -3084,10 +3251,12 @@
   moreover
   have "\<Union>A \<inter> U \<subseteq> \<Union>C"
   proof safe
-    fix x a assume "x \<in> U" "x \<in> a" "a \<in> A"
-    with basis[of a x] A obtain b where "b \<in> B" "x \<in> b" "b \<inter> U \<subseteq> a" by blast
-    with `a \<in> A` show "x \<in> \<Union>C" unfolding C_def
-      by auto
+    fix x a
+    assume "x \<in> U" "x \<in> a" "a \<in> A"
+    with basis[of a x] A obtain b where "b \<in> B" "x \<in> b" "b \<inter> U \<subseteq> a"
+      by blast
+    with `a \<in> A` show "x \<in> \<Union>C"
+      unfolding C_def by auto
   qed
   then have "U \<subseteq> \<Union>C" using `U \<subseteq> \<Union>A` by auto
   ultimately obtain T where "T\<subseteq>C" "finite T" "U \<subseteq> \<Union>T"
@@ -3102,22 +3271,22 @@
 lemma countably_compact_imp_compact_second_countable:
   "countably_compact U \<Longrightarrow> compact (U :: 'a :: second_countable_topology set)"
 proof (rule countably_compact_imp_compact)
-  fix T and x :: 'a assume "open T" "x \<in> T"
+  fix T and x :: 'a
+  assume "open T" "x \<in> T"
   from topological_basisE[OF is_basis this] guess b .
-  then show "\<exists>b\<in>SOME B. countable B \<and> topological_basis B. x \<in> b \<and> b \<inter> U \<subseteq> T" by auto
+  then show "\<exists>b\<in>SOME B. countable B \<and> topological_basis B. x \<in> b \<and> b \<inter> U \<subseteq> T"
+    by auto
 qed (insert countable_basis topological_basis_open[OF is_basis], auto)
 
 lemma countably_compact_eq_compact:
   "countably_compact U \<longleftrightarrow> compact (U :: 'a :: second_countable_topology set)"
   using countably_compact_imp_compact_second_countable compact_imp_countably_compact by blast
-  
+
 subsubsection{* Sequential compactness *}
 
-definition
-  seq_compact :: "'a::topological_space set \<Rightarrow> bool" where
-  "seq_compact S \<longleftrightarrow>
-   (\<forall>f. (\<forall>n. f n \<in> S) \<longrightarrow>
-       (\<exists>l\<in>S. \<exists>r. subseq r \<and> ((f o r) ---> l) sequentially))"
+definition seq_compact :: "'a::topological_space set \<Rightarrow> bool"
+  where "seq_compact S \<longleftrightarrow>
+    (\<forall>f. (\<forall>n. f n \<in> S) \<longrightarrow> (\<exists>l\<in>S. \<exists>r. subseq r \<and> ((f o r) ---> l) sequentially))"
 
 lemma seq_compact_imp_countably_compact:
   fixes U :: "'a :: first_countable_topology set"
@@ -3138,13 +3307,17 @@
     show ?thesis
     proof (rule ccontr)
       assume "\<not> (\<exists>T\<subseteq>A. finite T \<and> U \<subseteq> \<Union>T)"
-      then have "\<forall>T. \<exists>x. T \<subseteq> A \<and> finite T \<longrightarrow> (x \<in> U - \<Union>T)" by auto
-      then obtain X' where T: "\<And>T. T \<subseteq> A \<Longrightarrow> finite T \<Longrightarrow> X' T \<in> U - \<Union>T" by metis
+      then have "\<forall>T. \<exists>x. T \<subseteq> A \<and> finite T \<longrightarrow> (x \<in> U - \<Union>T)"
+        by auto
+      then obtain X' where T: "\<And>T. T \<subseteq> A \<Longrightarrow> finite T \<Longrightarrow> X' T \<in> U - \<Union>T"
+        by metis
       def X \<equiv> "\<lambda>n. X' (from_nat_into A ` {.. n})"
       have X: "\<And>n. X n \<in> U - (\<Union>i\<le>n. from_nat_into A i)"
         using `A \<noteq> {}` unfolding X_def SUP_def by (intro T) (auto intro: from_nat_into)
-      then have "range X \<subseteq> U" by auto
-      with subseq[of X] obtain r x where "x \<in> U" and r: "subseq r" "(X \<circ> r) ----> x" by auto
+      then have "range X \<subseteq> U"
+        by auto
+      with subseq[of X] obtain r x where "x \<in> U" and r: "subseq r" "(X \<circ> r) ----> x"
+        by auto
       from `x\<in>U` `U \<subseteq> \<Union>A` from_nat_into_surj[OF `countable A`]
       obtain n where "x \<in> from_nat_into A n" by auto
       with r(2) A(1) from_nat_into[OF `A \<noteq> {}`, of n]
@@ -3164,7 +3337,8 @@
 
 lemma compact_imp_seq_compact:
   fixes U :: "'a :: first_countable_topology set"
-  assumes "compact U" shows "seq_compact U"
+  assumes "compact U"
+  shows "seq_compact U"
   unfolding seq_compact_def
 proof safe
   fix X :: "nat \<Rightarrow> 'a"
@@ -3185,7 +3359,8 @@
     have "\<exists>a. i < a \<and> X a \<in> A (Suc n)"
     proof (rule ccontr)
       assume "\<not> (\<exists>a>i. X a \<in> A (Suc n))"
-      then have "\<And>a. Suc i \<le> a \<Longrightarrow> X a \<notin> A (Suc n)" by auto
+      then have "\<And>a. Suc i \<le> a \<Longrightarrow> X a \<notin> A (Suc n)"
+        by auto
       then have "eventually (\<lambda>x. x \<notin> A (Suc n)) (filtermap X sequentially)"
         by (auto simp: eventually_filtermap eventually_sequentially)
       moreover have "eventually (\<lambda>x. x \<in> A (Suc n)) (nhds x)"
@@ -3207,7 +3382,8 @@
   proof (rule topological_tendstoI)
     fix S
     assume "open S" "x \<in> S"
-    with A(3) have "eventually (\<lambda>i. A i \<subseteq> S) sequentially" by auto
+    with A(3) have "eventually (\<lambda>i. A i \<subseteq> S) sequentially"
+      by auto
     moreover
     {
       fix i
@@ -3238,9 +3414,9 @@
   assumes "countably_compact s" "countable t" "infinite t"  "t \<subseteq> s"
   shows "\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> t)"
 proof (rule ccontr)
-  def C \<equiv> "(\<lambda>F. interior (F \<union> (- t))) ` {F. finite F \<and> F \<subseteq> t }"  
+  def C \<equiv> "(\<lambda>F. interior (F \<union> (- t))) ` {F. finite F \<and> F \<subseteq> t }"
   note `countably_compact s`
-  moreover have "\<forall>t\<in>C. open t" 
+  moreover have "\<forall>t\<in>C. open t"
     by (auto simp: C_def)
   moreover
   assume "\<not> (\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> t))"
@@ -3256,19 +3432,20 @@
   from `countable t` have "countable C"
     unfolding C_def by (auto intro: countable_Collect_finite_subset)
   ultimately guess D by (rule countably_compactE)
-  then obtain E where E: "E \<subseteq> {F. finite F \<and> F \<subseteq> t }" "finite E" and
-    s: "s \<subseteq> (\<Union>F\<in>E. interior (F \<union> (- t)))"
+  then obtain E where E: "E \<subseteq> {F. finite F \<and> F \<subseteq> t }" "finite E"
+    and s: "s \<subseteq> (\<Union>F\<in>E. interior (F \<union> (- t)))"
     by (metis (lifting) Union_image_eq finite_subset_image C_def)
   from s `t \<subseteq> s` have "t \<subseteq> \<Union>E"
     using interior_subset by blast
   moreover have "finite (\<Union>E)"
     using E by auto
-  ultimately show False using `infinite t` by (auto simp: finite_subset)
+  ultimately show False using `infinite t`
+    by (auto simp: finite_subset)
 qed
 
 lemma countable_acc_point_imp_seq_compact:
   fixes s :: "'a::first_countable_topology set"
-  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))"
+  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))"
   shows "seq_compact s"
 proof -
   {
@@ -3281,20 +3458,22 @@
         using pigeonhole_infinite[OF _ True] by auto
       then obtain r where "subseq r" and fr: "\<forall>n. f (r n) = f l"
         using infinite_enumerate by blast
-      hence "subseq r \<and> (f \<circ> r) ----> f l"
+      then have "subseq r \<and> (f \<circ> r) ----> f l"
         by (simp add: fr tendsto_const o_def)
       with f show "\<exists>l\<in>s. \<exists>r. subseq r \<and> (f \<circ> r) ----> l"
         by auto
     next
       case False
-      with f assms have "\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> range f)" by auto
+      with f assms have "\<exists>x\<in>s. \<forall>U. x\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> range f)"
+        by auto
       then obtain l where "l \<in> s" "\<forall>U. l\<in>U \<and> open U \<longrightarrow> infinite (U \<inter> range f)" ..
       from this(2) have "\<exists>r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
         using acc_point_range_imp_convergent_subsequence[of l f] by auto
       with `l \<in> s` show "\<exists>l\<in>s. \<exists>r. subseq r \<and> ((f \<circ> r) ---> l) sequentially" ..
     qed
   }
-  thus ?thesis unfolding seq_compact_def by auto
+  then show ?thesis
+    unfolding seq_compact_def by auto
 qed
 
 lemma seq_compact_eq_countably_compact:
@@ -3327,11 +3506,11 @@
 
 subsubsection{* Total boundedness *}
 
-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)"
+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)"
   unfolding Cauchy_def by metis
 
-fun helper_1 :: "('a::metric_space set) \<Rightarrow> real \<Rightarrow> nat \<Rightarrow> 'a" where
+fun helper_1 :: "('a::metric_space set) \<Rightarrow> real \<Rightarrow> nat \<Rightarrow> 'a"
+where
   "helper_1 s e n = (SOME y::'a. y \<in> s \<and> (\<forall>m<n. \<not> (dist (helper_1 s e m) y < e)))"
 declare helper_1.simps[simp del]
 
@@ -3340,7 +3519,8 @@
   shows "\<forall>e>0. \<exists>k. finite k \<and> k \<subseteq> s \<and> s \<subseteq> (\<Union>((\<lambda>x. ball x e) ` k))"
 proof (rule, rule, rule ccontr)
   fix e::real
-  assume "e>0" and assm:"\<not> (\<exists>k. finite k \<and> k \<subseteq> s \<and> s \<subseteq> \<Union>((\<lambda>x. ball x e) ` k))"
+  assume "e > 0"
+  assume assm: "\<not> (\<exists>k. finite k \<and> k \<subseteq> s \<and> s \<subseteq> \<Union>((\<lambda>x. ball x e) ` k))"
   def x \<equiv> "helper_1 s e"
   {
     fix n
@@ -3365,11 +3545,11 @@
         using z
         apply auto
         done
-      thus "x n \<in> s \<and> (\<forall>m<n. \<not> dist (x m) (x n) < e)"
+      then show "x n \<in> s \<and> (\<forall>m<n. \<not> dist (x m) (x n) < e)"
         unfolding Q_def by auto
     qed
   }
-  hence "\<forall>n::nat. x n \<in> s" and x:"\<forall>n. \<forall>m < n. \<not> (dist (x m) (x n) < e)"
+  then have "\<forall>n::nat. x n \<in> s" and x:"\<forall>n. \<forall>m < n. \<not> (dist (x m) (x n) < e)"
     by blast+
   then obtain l r where "l\<in>s" and r:"subseq r" and "((x \<circ> r) ---> l) sequentially"
     using assms(1)[unfolded seq_compact_def, THEN spec[where x=x]] by auto
@@ -3388,7 +3568,8 @@
 
 lemma seq_compact_imp_heine_borel:
   fixes s :: "'a :: metric_space set"
-  assumes "seq_compact s" shows "compact s"
+  assumes "seq_compact s"
+  shows "compact s"
 proof -
   from seq_compact_imp_totally_bounded[OF `seq_compact s`]
   guess f unfolding choice_iff' .. note f = this
@@ -3403,20 +3584,29 @@
                intro!: countable_image countable_SIGMA countable_UN)
     show "\<forall>b\<in>K. open b" by (auto simp: K_def)
   next
-    fix T x assume T: "open T" "x \<in> T" and x: "x \<in> s"
-    from openE[OF T] obtain e where "0 < e" "ball x e \<subseteq> T" by auto
-    then have "0 < e / 2" "ball x (e / 2) \<subseteq> T" by auto
-    from Rats_dense_in_real[OF `0 < e / 2`] obtain r where "r \<in> \<rat>" "0 < r" "r < e / 2" by auto
+    fix T x
+    assume T: "open T" "x \<in> T" and x: "x \<in> s"
+    from openE[OF T] obtain e where "0 < e" "ball x e \<subseteq> T"
+      by auto
+    then have "0 < e / 2" "ball x (e / 2) \<subseteq> T"
+      by auto
+    from Rats_dense_in_real[OF `0 < e / 2`] obtain r where "r \<in> \<rat>" "0 < r" "r < e / 2"
+      by auto
     from f[rule_format, of r] `0 < r` `x \<in> s` obtain k where "k \<in> f r" "x \<in> ball k r"
       unfolding Union_image_eq by auto
-    from `r \<in> \<rat>` `0 < r` `k \<in> f r` have "ball k r \<in> K" by (auto simp: K_def)
+    from `r \<in> \<rat>` `0 < r` `k \<in> f r` have "ball k r \<in> K"
+      by (auto simp: K_def)
     then show "\<exists>b\<in>K. x \<in> b \<and> b \<inter> s \<subseteq> T"
     proof (rule bexI[rotated], safe)
-      fix y assume "y \<in> ball k r"
+      fix y
+      assume "y \<in> ball k r"
       with `r < e / 2` `x \<in> ball k r` have "dist x y < e"
         by (intro dist_double[where x = k and d=e]) (auto simp: dist_commute)
-      with `ball x e \<subseteq> T` show "y \<in> T" by auto
-    qed (rule `x \<in> ball k r`)
+      with `ball x e \<subseteq> T` show "y \<in> T"
+        by auto
+    next
+      show "x \<in> ball k r" by fact
+    qed
   qed
 qed
 
@@ -3433,18 +3623,20 @@
 
 lemma compact_eq_bolzano_weierstrass:
   fixes s :: "'a::metric_space set"
-  shows "compact s \<longleftrightarrow> (\<forall>t. infinite t \<and> t \<subseteq> s --> (\<exists>x \<in> s. x islimpt t))" (is "?lhs = ?rhs")
+  shows "compact s \<longleftrightarrow> (\<forall>t. infinite t \<and> t \<subseteq> s --> (\<exists>x \<in> s. x islimpt t))"
+  (is "?lhs = ?rhs")
 proof
   assume ?lhs
-  thus ?rhs using heine_borel_imp_bolzano_weierstrass[of s] by auto
+  then show ?rhs
+    using heine_borel_imp_bolzano_weierstrass[of s] by auto
 next
   assume ?rhs
-  thus ?lhs
+  then show ?lhs
     unfolding compact_eq_seq_compact_metric by (rule bolzano_weierstrass_imp_seq_compact)
 qed
 
 lemma bolzano_weierstrass_imp_bounded:
-  "\<forall>t. infinite t \<and> t \<subseteq> s --> (\<exists>x \<in> s. x islimpt t) \<Longrightarrow> bounded s"
+  "\<forall>t. infinite t \<and> t \<subseteq> s \<longrightarrow> (\<exists>x \<in> s. x islimpt t) \<Longrightarrow> bounded s"
   using compact_imp_bounded unfolding compact_eq_bolzano_weierstrass .
 
 text {*
@@ -3458,13 +3650,18 @@
 
 lemma bounded_closed_imp_seq_compact:
   fixes s::"'a::heine_borel set"
-  assumes "bounded s" and "closed s" shows "seq_compact s"
+  assumes "bounded s"
+    and "closed s"
+  shows "seq_compact s"
 proof (unfold seq_compact_def, clarify)
-  fix f :: "nat \<Rightarrow> 'a" assume f: "\<forall>n. f n \<in> s"
-  with `bounded s` have "bounded (range f)" by (auto intro: bounded_subset)
+  fix f :: "nat \<Rightarrow> 'a"
+  assume f: "\<forall>n. f n \<in> s"
+  with `bounded s` have "bounded (range f)"
+    by (auto intro: bounded_subset)
   obtain l r where r: "subseq r" and l: "((f \<circ> r) ---> l) sequentially"
     using bounded_imp_convergent_subsequence [OF `bounded (range f)`] by auto
-  from f have fr: "\<forall>n. (f \<circ> r) n \<in> s" by simp
+  from f have fr: "\<forall>n. (f \<circ> r) n \<in> s"
+    by simp
   have "l \<in> s" using `closed s` fr l
     unfolding closed_sequential_limits by blast
   show "\<exists>l\<in>s. \<exists>r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
@@ -3476,12 +3673,12 @@
   shows "compact s \<longleftrightarrow> bounded s \<and> closed s"  (is "?lhs = ?rhs")
 proof
   assume ?lhs
-  thus ?rhs
+  then show ?rhs
     using compact_imp_closed compact_imp_bounded
     by blast
 next
   assume ?rhs
-  thus ?lhs
+  then show ?lhs
     using bounded_closed_imp_seq_compact[of s]
     unfolding compact_eq_seq_compact_metric
     by auto
@@ -3514,41 +3711,48 @@
         (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) \<bullet> i) (l \<bullet> i) < e) sequentially)"
 proof safe
   fix d :: "'a set"
-  assume d: "d \<subseteq> Basis" 
-  with finite_Basis have "finite d" by (blast intro: finite_subset)
+  assume d: "d \<subseteq> Basis"
+  with finite_Basis have "finite d"
+    by (blast intro: finite_subset)
   from this d show "\<exists>l::'a. \<exists>r. subseq r \<and>
     (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) \<bullet> i) (l \<bullet> i) < e) sequentially)"
   proof (induct d)
     case empty
-    thus ?case unfolding subseq_def by auto
+    then show ?case
+      unfolding subseq_def by auto
   next
     case (insert k d)
-    have k[intro]:"k\<in>Basis" using insert by auto
-    have s': "bounded ((\<lambda>x. x \<bullet> k) ` range f)" using `bounded (range f)`
+    have k[intro]: "k \<in> Basis"
+      using insert by auto
+    have s': "bounded ((\<lambda>x. x \<bullet> k) ` range f)"
+      using `bounded (range f)`
       by (auto intro!: bounded_linear_image bounded_linear_inner_left)
-    obtain l1::"'a" and r1 where r1:"subseq r1" and
-      lr1:"\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 n) \<bullet> i) (l1 \<bullet> i) < e) sequentially"
+    obtain l1::"'a" and r1 where r1: "subseq r1"
+      and lr1: "\<forall>e > 0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 n) \<bullet> i) (l1 \<bullet> i) < e) sequentially"
       using insert(3) using insert(4) by auto
-    have f': "\<forall>n. f (r1 n) \<bullet> k \<in> (\<lambda>x. x \<bullet> k) ` range f" by simp
+    have f': "\<forall>n. f (r1 n) \<bullet> k \<in> (\<lambda>x. x \<bullet> k) ` range f"
+      by simp
     have "bounded (range (\<lambda>i. f (r1 i) \<bullet> k))"
       by (metis (lifting) bounded_subset f' image_subsetI s')
     then obtain l2 r2 where r2:"subseq r2" and lr2:"((\<lambda>i. f (r1 (r2 i)) \<bullet> k) ---> l2) sequentially"
-      using bounded_imp_convergent_subsequence[of "\<lambda>i. f (r1 i) \<bullet> k"] by (auto simp: o_def)
-    def r \<equiv> "r1 \<circ> r2" have r:"subseq r"
+      using bounded_imp_convergent_subsequence[of "\<lambda>i. f (r1 i) \<bullet> k"]
+      by (auto simp: o_def)
+    def r \<equiv> "r1 \<circ> r2"
+    have r:"subseq r"
       using r1 and r2 unfolding r_def o_def subseq_def by auto
     moreover
     def l \<equiv> "(\<Sum>i\<in>Basis. (if i = k then l2 else l1\<bullet>i) *\<^sub>R i)::'a"
     {
       fix e::real
-      assume "e>0"
-      from lr1 `e>0` have N1:"eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 n) \<bullet> i) (l1 \<bullet> i) < e) sequentially"
+      assume "e > 0"
+      from lr1 `e > 0` have N1: "eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 n) \<bullet> i) (l1 \<bullet> i) < e) sequentially"
         by blast
-      from lr2 `e>0` have N2:"eventually (\<lambda>n. dist (f (r1 (r2 n)) \<bullet> k) l2 < e) sequentially"
+      from lr2 `e > 0` have N2:"eventually (\<lambda>n. dist (f (r1 (r2 n)) \<bullet> k) l2 < e) sequentially"
         by (rule tendstoD)
       from r2 N1 have N1': "eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r1 (r2 n)) \<bullet> i) (l1 \<bullet> i) < e) sequentially"
         by (rule eventually_subseq)
       have "eventually (\<lambda>n. \<forall>i\<in>(insert k d). dist (f (r n) \<bullet> i) (l \<bullet> i) < e) sequentially"
-        using N1' N2 
+        using N1' N2
         by eventually_elim (insert insert.prems, auto simp: l_def r_def o_def)
     }
     ultimately show ?case by auto
@@ -3564,8 +3768,8 @@
     using compact_lemma [OF f] by blast
   {
     fix e::real
-    assume "e>0"
-    hence "0 < e / real_of_nat DIM('a)"
+    assume "e > 0"
+    then have "e / real_of_nat DIM('a) > 0"
       by (auto intro!: divide_pos_pos DIM_positive)
     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"
       by simp
@@ -3576,18 +3780,20 @@
       have "dist (f (r n)) l \<le> (\<Sum>i\<in>Basis. dist (f (r n) \<bullet> i) (l \<bullet> i))"
         apply (subst euclidean_dist_l2)
         using zero_le_dist
-        by (rule setL2_le_setsum)
+        apply (rule setL2_le_setsum)
+        done
       also have "\<dots> < (\<Sum>i\<in>(Basis::'a set). e / (real_of_nat DIM('a)))"
         apply (rule setsum_strict_mono)
         using n
-        by auto
-      finally have "dist (f (r n)) l < e" 
+        apply auto
+        done
+      finally have "dist (f (r n)) l < e"
         by auto
     }
     ultimately have "eventually (\<lambda>n. dist (f (r n)) l < e) sequentially"
       by (rule eventually_elim1)
   }
-  hence *: "((f \<circ> r) ---> l) sequentially"
+  then have *: "((f \<circ> r) ---> l) sequentially"
     unfolding o_def tendsto_iff by simp
   with r show "\<exists>l r. subseq r \<and> ((f \<circ> r) ---> l) sequentially"
     by auto
@@ -3619,13 +3825,13 @@
 proof
   fix f :: "nat \<Rightarrow> 'a \<times> 'b"
   assume f: "bounded (range f)"
-  from f have s1: "bounded (range (fst \<circ> f))" unfolding image_comp by (rule bounded_fst)
+  from f have s1: "bounded (range (fst \<circ> f))"
+    unfolding image_comp by (rule bounded_fst)
   obtain l1 r1 where r1: "subseq r1" and l1: "(\<lambda>n. fst (f (r1 n))) ----> l1"
     using bounded_imp_convergent_subsequence [OF s1] unfolding o_def by fast
   from f have s2: "bounded (range (snd \<circ> f \<circ> r1))"
     by (auto simp add: image_comp intro: bounded_snd bounded_subset)
-  obtain l2 r2 where r2: "subseq r2"
-    and l2: "((\<lambda>n. snd (f (r1 (r2 n)))) ---> l2) sequentially"
+  obtain l2 r2 where r2: "subseq r2" and l2: "((\<lambda>n. snd (f (r1 (r2 n)))) ---> l2) sequentially"
     using bounded_imp_convergent_subsequence [OF s2]
     unfolding o_def by fast
   have l1': "((\<lambda>n. fst (f (r1 (r2 n)))) ---> l1) sequentially"
@@ -3656,36 +3862,42 @@
     note lr' = seq_suble [OF lr(2)]
 
     {
-      fix e::real
-      assume "e>0"
+      fix e :: real
+      assume "e > 0"
       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"
         unfolding cauchy_def
-        using `e>0` apply (erule_tac x="e/2" in allE)
+        using `e > 0`
+        apply (erule_tac x="e/2" in allE)
         apply auto
         done
       from lr(3)[unfolded LIMSEQ_def, THEN spec[where x="e/2"]]
-      obtain M where M:"\<forall>n\<ge>M. dist ((f \<circ> r) n) l < e/2" using `e>0` by auto
+      obtain M where M:"\<forall>n\<ge>M. dist ((f \<circ> r) n) l < e/2"
+        using `e > 0` by auto
       {
-        fix n::nat
-        assume n:"n \<ge> max N M"
-        have "dist ((f \<circ> r) n) l < e/2" using n M by auto
-        moreover have "r n \<ge> N" using lr'[of n] n by auto
-        hence "dist (f n) ((f \<circ> r) n) < e / 2" using N using n by auto
+        fix n :: nat
+        assume n: "n \<ge> max N M"
+        have "dist ((f \<circ> r) n) l < e/2"
+          using n M by auto
+        moreover have "r n \<ge> N"
+          using lr'[of n] n by auto
+        then have "dist (f n) ((f \<circ> r) n) < e / 2"
+          using N and n by auto
         ultimately have "dist (f n) l < e"
-          using dist_triangle_half_r[of "f (r n)" "f n" e l] by (auto simp add: dist_commute)
+          using dist_triangle_half_r[of "f (r n)" "f n" e l]
+          by (auto simp add: dist_commute)
       }
-      hence "\<exists>N. \<forall>n\<ge>N. dist (f n) l < e" by blast
+      then have "\<exists>N. \<forall>n\<ge>N. dist (f n) l < e" by blast
     }
-    hence "\<exists>l\<in>s. (f ---> l) sequentially" using `l\<in>s`
+    then have "\<exists>l\<in>s. (f ---> l) sequentially" using `l\<in>s`
       unfolding LIMSEQ_def by auto
   }
-  thus ?thesis unfolding complete_def by auto
+  then show ?thesis unfolding complete_def by auto
 qed
 
 lemma nat_approx_posE:
   fixes e::real
   assumes "0 < e"
-  obtains n::nat where "1 / (Suc n) < e"
+  obtains n :: nat where "1 / (Suc n) < e"
 proof atomize_elim
   have " 1 / real (Suc (nat (ceiling (1/e)))) < 1 / (ceiling (1/e))"
     by (rule divide_strict_left_mono) (auto intro!: mult_pos_pos simp: `0 < e`)
@@ -3705,18 +3917,22 @@
 
   show "compact s"
   proof cases
-    assume "s = {}" thus "compact s" by (simp add: compact_def)
+    assume "s = {}"
+    then show "compact s" by (simp add: compact_def)
   next
     assume "s \<noteq> {}"
     show ?thesis
       unfolding compact_def
     proof safe
-      fix f :: "nat \<Rightarrow> 'a" assume f: "\<forall>n. f n \<in> s"
-      
+      fix f :: "nat \<Rightarrow> 'a"
+      assume f: "\<forall>n. f n \<in> s"
+
       def e \<equiv> "\<lambda>n. 1 / (2 * Suc n)"
       then have [simp]: "\<And>n. 0 < e n" by auto
       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)"
-      { fix n U assume "infinite {n. f n \<in> U}"
+      {
+        fix n U
+        assume "infinite {n. f n \<in> U}"
         then have "\<exists>b\<in>k (e n). infinite {i\<in>{n. f n \<in> U}. f i \<in> ball b (e n)}"
           using k f by (intro pigeonhole_infinite_rel) (auto simp: subset_eq)
         then guess a ..
@@ -3724,12 +3940,16 @@
           by (intro exI[of _ "ball a (e n) \<inter> U"] exI[of _ a]) (auto simp: ac_simps)
         from someI_ex[OF this]
         have "infinite {i. f i \<in> B n U}" "\<exists>x. B n U \<subseteq> ball x (e n) \<inter> U"
-          unfolding B_def by auto }
+          unfolding B_def by auto
+      }
       note B = this
 
       def F \<equiv> "nat_rec (B 0 UNIV) B"
-      { fix n have "infinite {i. f i \<in> F n}"
-          by (induct n) (auto simp: F_def B) }
+      {
+        fix n
+        have "infinite {i. f i \<in> F n}"
+          by (induct n) (auto simp: F_def B)
+      }
       then have F: "\<And>n. \<exists>x. F (Suc n) \<subseteq> ball x (e n) \<inter> F n"
         using B by (simp add: F_def)
       then have F_dec: "\<And>m n. m \<le> n \<Longrightarrow> F n \<subseteq> F m"
@@ -3751,13 +3971,17 @@
       moreover have "\<forall>i. (f \<circ> t) i \<in> s"
         using f by auto
       moreover
-      { fix n have "(f \<circ> t) n \<in> F n"
-          by (cases n) (simp_all add: t_def sel) }
+      {
+        fix n
+        have "(f \<circ> t) n \<in> F n"
+          by (cases n) (simp_all add: t_def sel)
+      }
       note t = this
 
       have "Cauchy (f \<circ> t)"
       proof (safe intro!: metric_CauchyI exI elim!: nat_approx_posE)
-        fix r :: real and N n m assume "1 / Suc N < r" "Suc N \<le> n" "Suc N \<le> m"
+        fix r :: real and N n m
+        assume "1 / Suc N < r" "Suc N \<le> n" "Suc N \<le> m"
         then have "(f \<circ> t) n \<in> F (Suc N)" "(f \<circ> t) m \<in> F (Suc N)" "2 * e N < r"
           using F_dec t by (auto simp: e_def field_simps real_of_nat_Suc)
         with F[of N] obtain x where "dist x ((f \<circ> t) n) < e N" "dist x ((f \<circ> t) m) < e N"
@@ -3774,39 +3998,44 @@
 qed (metis compact_imp_complete compact_imp_seq_compact seq_compact_imp_totally_bounded)
 
 lemma cauchy: "Cauchy s \<longleftrightarrow> (\<forall>e>0.\<exists> N::nat. \<forall>n\<ge>N. dist(s n)(s N) < e)" (is "?lhs = ?rhs")
-proof-
-  { assume ?rhs
-    { fix e::real
+proof -
+  {
+    assume ?rhs
+    {
+      fix e::real
       assume "e>0"
       with `?rhs` obtain N where N:"\<forall>n\<ge>N. dist (s n) (s N) < e/2"
         by (erule_tac x="e/2" in allE) auto
-      { fix n m
+      {
+        fix n m
         assume nm:"N \<le> m \<and> N \<le> n"
-        hence "dist (s m) (s n) < e" using N
+        then have "dist (s m) (s n) < e" using N
           using dist_triangle_half_l[of "s m" "s N" "e" "s n"]
           by blast
       }
-      hence "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < e"
+      then have "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < e"
         by blast
     }
-    hence ?lhs
+    then have ?lhs
       unfolding cauchy_def
       by blast
   }
-  thus ?thesis
+  then show ?thesis
     unfolding cauchy_def
     using dist_triangle_half_l
     by blast
 qed
 
-lemma cauchy_imp_bounded: assumes "Cauchy s" shows "bounded (range s)"
-proof-
-  from assms obtain N::nat where "\<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < 1"
+lemma cauchy_imp_bounded:
+  assumes "Cauchy s"
+  shows "bounded (range s)"
+proof -
+  from assms obtain N :: nat where "\<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (s m) (s n) < 1"
     unfolding cauchy_def
     apply (erule_tac x= 1 in allE)
     apply auto
     done
-  hence N:"\<forall>n. N \<le> n \<longrightarrow> dist (s N) (s n) < 1" by auto
+  then have N:"\<forall>n. N \<le> n \<longrightarrow> dist (s N) (s n) < 1" by auto
   moreover
   have "bounded (s ` {0..N})"
     using finite_imp_bounded[of "s ` {1..N}"] by auto
@@ -3825,11 +4054,11 @@
 instance heine_borel < complete_space
 proof
   fix f :: "nat \<Rightarrow> 'a" assume "Cauchy f"
-  hence "bounded (range f)"
+  then have "bounded (range f)"
     by (rule cauchy_imp_bounded)
-  hence "compact (closure (range f))"
+  then have "compact (closure (range f))"
     unfolding compact_eq_bounded_closed by auto
-  hence "complete (closure (range f))"
+  then have "complete (closure (range f))"
     by (rule compact_imp_complete)
   moreover have "\<forall>n. f n \<in> closure (range f)"
     using closure_subset [of "range f"] by auto
@@ -3842,29 +4071,36 @@
 instance euclidean_space \<subseteq> banach ..
 
 lemma complete_univ: "complete (UNIV :: 'a::complete_space set)"
-proof(simp add: complete_def, rule, rule)
-  fix f :: "nat \<Rightarrow> 'a" assume "Cauchy f"
-  hence "convergent f" by (rule Cauchy_convergent)
-  thus "\<exists>l. f ----> l" unfolding convergent_def .  
-qed
-
-lemma complete_imp_closed: assumes "complete s" shows "closed s"
+proof (simp add: complete_def, rule, rule)
+  fix f :: "nat \<Rightarrow> 'a"
+  assume "Cauchy f"
+  then have "convergent f" by (rule Cauchy_convergent)
+  then show "\<exists>l. f ----> l" unfolding convergent_def .
+qed
+
+lemma complete_imp_closed:
+  assumes "complete s"
+  shows "closed s"
 proof -
-  { fix x assume "x islimpt s"
+  {
+    fix x
+    assume "x islimpt s"
     then obtain f where f: "\<forall>n. f n \<in> s - {x}" "(f ---> x) sequentially"
       unfolding islimpt_sequential by auto
     then obtain l where l: "l\<in>s" "(f ---> l) sequentially"
       using `complete s`[unfolded complete_def] using LIMSEQ_imp_Cauchy[of f x] by auto
-    hence "x \<in> s"  using tendsto_unique[of sequentially f l x] trivial_limit_sequentially f(2) by auto
+    then have "x \<in> s"
+      using tendsto_unique[of sequentially f l x] trivial_limit_sequentially f(2) by auto
   }
-  thus "closed s" unfolding closed_limpt by auto
+  then show "closed s" unfolding closed_limpt by auto
 qed
 
 lemma complete_eq_closed:
   fixes s :: "'a::complete_space set"
   shows "complete s \<longleftrightarrow> closed s" (is "?lhs = ?rhs")
 proof
-  assume ?lhs thus ?rhs by (rule complete_imp_closed)
+  assume ?lhs
+  then show ?rhs by (rule complete_imp_closed)
 next
   assume ?rhs
   {
@@ -3872,11 +4108,11 @@
     assume as:"\<forall>n::nat. f n \<in> s" "Cauchy f"
     then obtain l where "(f ---> l) sequentially"
       using complete_univ[unfolded complete_def, THEN spec[where x=f]] by auto
-    hence "\<exists>l\<in>s. (f ---> l) sequentially"
+    then have "\<exists>l\<in>s. (f ---> l) sequentially"
       using `?rhs`[unfolded closed_sequential_limits, THEN spec[where x=f], THEN spec[where x=l]]
       using as(1) by auto
   }
-  thus ?lhs unfolding complete_def by auto
+  then show ?lhs unfolding complete_def by auto
 qed
 
 lemma convergent_eq_cauchy:
@@ -3933,56 +4169,94 @@
     apply blast
     done
 
-  { fix n::nat
-    { fix e::real assume "e>0"
+  {
+    fix n :: nat
+    {
+      fix e :: real
+      assume "e>0"
       with lr(3) obtain N where N:"\<forall>m\<ge>N. dist ((x \<circ> r) m) l < e"
         unfolding LIMSEQ_def by auto
-      hence "dist ((x \<circ> r) (max N n)) l < e" by auto
+      then have "dist ((x \<circ> r) (max N n)) l < e" by auto
       moreover
-      have "r (max N n) \<ge> n" using lr(2) using seq_suble[of r "max N n"] by auto
-      hence "(x \<circ> r) (max N n) \<in> s n"
-        using x apply (erule_tac x=n in allE)
-        using x apply (erule_tac x="r (max N n)" in allE)
-        using assms(3) apply (erule_tac x=n in allE)
+      have "r (max N n) \<ge> n" using lr(2) using seq_suble[of r "max N n"]
+        by auto
+      then have "(x \<circ> r) (max N n) \<in> s n"
+        using x
+        apply (erule_tac x=n in allE)
+        using x
+        apply (erule_tac x="r (max N n)" in allE)
+        using assms(3)
+        apply (erule_tac x=n in allE)
         apply (erule_tac x="r (max N n)" in allE)
         apply auto
         done
-      ultimately have "\<exists>y\<in>s n. dist y l < e" by auto
+      ultimately have "\<exists>y\<in>s n. dist y l < e"
+        by auto
     }
-    hence "l \<in> s n" using closed_approachable[of "s n" l] assms(1) by blast
+    then have "l \<in> s n"
+      using closed_approachable[of "s n" l] assms(1) by blast
   }
-  thus ?thesis by auto
+  then show ?thesis by auto
 qed
 
 text {* Decreasing case does not even need compactness, just completeness. *}
 
 lemma decreasing_closed_nest:
-  assumes "\<forall>n. closed(s n)"
-          "\<forall>n. (s n \<noteq> {})"
-          "\<forall>m n. m \<le> n --> s n \<subseteq> s m"
-          "\<forall>e>0. \<exists>n. \<forall>x \<in> (s n). \<forall> y \<in> (s n). dist x y < e"
+  assumes
+    "\<forall>n. closed(s n)"
+    "\<forall>n. (s n \<noteq> {})"
+    "\<forall>m n. m \<le> n --> s n \<subseteq> s m"
+    "\<forall>e>0. \<exists>n. \<forall>x \<in> (s n). \<forall> y \<in> (s n). dist x y < e"
   shows "\<exists>a::'a::complete_space. \<forall>n::nat. a \<in> s n"
 proof-
-  have "\<forall>n. \<exists> x. x\<in>s n" using assms(2) by auto
-  hence "\<exists>t. \<forall>n. t n \<in> s n" using choice[of "\<lambda> n x. x \<in> s n"] by auto
+  have "\<forall>n. \<exists> x. x\<in>s n"
+    using assms(2) by auto
+  then have "\<exists>t. \<forall>n. t n \<in> s n"
+    using choice[of "\<lambda> n x. x \<in> s n"] by auto
   then obtain t where t: "\<forall>n. t n \<in> s n" by auto
-  { fix e::real assume "e>0"
-    then obtain N where N:"\<forall>x\<in>s N. \<forall>y\<in>s N. dist x y < e" using assms(4) by auto
-    { fix m n ::nat assume "N \<le> m \<and> N \<le> n"
-      hence "t m \<in> s N" "t n \<in> s N" using assms(3) t unfolding  subset_eq t by blast+
-      hence "dist (t m) (t n) < e" using N by auto
+  {
+    fix e :: real
+    assume "e > 0"
+    then obtain N where N:"\<forall>x\<in>s N. \<forall>y\<in>s N. dist x y < e"
+      using assms(4) by auto
+    {
+      fix m n :: nat
+      assume "N \<le> m \<and> N \<le> n"
+      then have "t m \<in> s N" "t n \<in> s N"
+        using assms(3) t unfolding  subset_eq t by blast+
+      then have "dist (t m) (t n) < e"
+        using N by auto
     }
-    hence "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (t m) (t n) < e" by auto
+    then have "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (t m) (t n) < e"
+      by auto
   }
-  hence  "Cauchy t" unfolding cauchy_def by auto
-  then obtain l where l:"(t ---> l) sequentially" using complete_univ unfolding complete_def by auto
-  { fix n::nat
-    { fix e::real assume "e>0"
-      then obtain N::nat where N:"\<forall>n\<ge>N. dist (t n) l < e" using l[unfolded LIMSEQ_def] by auto
-      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
-      hence "\<exists>y\<in>s n. dist y l < e" apply(rule_tac x="t (max n N)" in bexI) using N by auto
+  then have "Cauchy t"
+    unfolding cauchy_def by auto
+  then obtain l where l:"(t ---> l) sequentially"
+    using complete_univ unfolding complete_def by auto
+  {
+    fix n :: nat
+    {
+      fix e :: real
+      assume "e > 0"
+      then obtain N :: nat where N: "\<forall>n\<ge>N. dist (t n) l < e"
+        using l[unfolded LIMSEQ_def] by auto
+      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
+        apply auto
+        done
+      then have "\<exists>y\<in>s n. dist y l < e"
+        apply (rule_tac x="t (max n N)" in bexI)
+        using N
+        apply auto
+        done
     }
-    hence "l \<in> s n" using closed_approachable[of "s n" l] assms(1) by auto
+    then have "l \<in> s n"
+      using closed_approachable[of "s n" l] assms(1) by auto
   }
   then show ?thesis by auto
 qed
@@ -3991,56 +4265,94 @@
 
 lemma decreasing_closed_nest_sing:
   fixes s :: "nat \<Rightarrow> 'a::complete_space set"
-  assumes "\<forall>n. closed(s n)"
-          "\<forall>n. s n \<noteq> {}"
-          "\<forall>m n. m \<le> n --> s n \<subseteq> s m"
-          "\<forall>e>0. \<exists>n. \<forall>x \<in> (s n). \<forall> y\<in>(s n). dist x y < e"
+  assumes
+    "\<forall>n. closed(s n)"
+    "\<forall>n. s n \<noteq> {}"
+    "\<forall>m n. m \<le> n --> s n \<subseteq> s m"
+    "\<forall>e>0. \<exists>n. \<forall>x \<in> (s n). \<forall> y\<in>(s n). dist x y < e"
   shows "\<exists>a. \<Inter>(range s) = {a}"
-proof-
-  obtain a where a:"\<forall>n. a \<in> s n" using decreasing_closed_nest[of s] using assms by auto
-  { fix b assume b:"b \<in> \<Inter>(range s)"
-    { fix e::real assume "e>0"
-      hence "dist a b < e" using assms(4 )using b using a by blast
+proof -
+  obtain a where a: "\<forall>n. a \<in> s n"
+    using decreasing_closed_nest[of s] using assms by auto
+  {
+    fix b
+    assume b: "b \<in> \<Inter>(range s)"
+    {
+      fix e :: real
+      assume "e > 0"
+      then have "dist a b < e"
+        using assms(4) and b and a by blast
     }
-    hence "dist a b = 0" by (metis dist_eq_0_iff dist_nz less_le)
+    then have "dist a b = 0"
+      by (metis dist_eq_0_iff dist_nz less_le)
   }
-  with a have "\<Inter>(range s) = {a}" unfolding image_def by auto
-  thus ?thesis ..
+  with a have "\<Inter>(range s) = {a}"
+    unfolding image_def by auto
+  then show ?thesis ..
 qed
 
 text{* Cauchy-type criteria for uniform convergence. *}
 
-lemma uniformly_convergent_eq_cauchy: fixes s::"nat \<Rightarrow> 'b \<Rightarrow> 'a::complete_space" shows
- "(\<exists>l. \<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x --> dist(s n x)(l x) < e) \<longleftrightarrow>
-  (\<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")
-proof(rule)
+lemma uniformly_convergent_eq_cauchy:
+  fixes s::"nat \<Rightarrow> 'b \<Rightarrow> 'a::complete_space"
+  shows
+    "(\<exists>l. \<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x --> dist(s n x)(l x) < e) \<longleftrightarrow>
+      (\<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")
+proof
   assume ?lhs
-  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
-  { fix e::real assume "e>0"
-    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
-    { fix n m::nat and x::"'b" assume "N \<le> m \<and> N \<le> n \<and> P x"
-      hence "dist (s m x) (s n x) < e"
+  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
+  {
+    fix e :: real
+    assume "e > 0"
+    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
+    {
+      fix n m :: nat and x :: "'b"
+      assume "N \<le> m \<and> N \<le> n \<and> P x"
+      then have "dist (s m x) (s n x) < e"
         using N[THEN spec[where x=m], THEN spec[where x=x]]
         using N[THEN spec[where x=n], THEN spec[where x=x]]
-        using dist_triangle_half_l[of "s m x" "l x" e "s n x"] by auto  }
-    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  }
-  thus ?rhs by auto
+        using dist_triangle_half_l[of "s m x" "l x" e "s n x"] by auto
+    }
+    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
+  }
+  then show ?rhs by auto
 next
   assume ?rhs
-  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
-  then obtain l where l:"\<forall>x. P x \<longrightarrow> ((\<lambda>n. s n x) ---> l x) sequentially" unfolding convergent_eq_cauchy[THEN sym]
-    using choice[of "\<lambda>x l. P x \<longrightarrow> ((\<lambda>n. s n x) ---> l) sequentially"] by auto
-  { fix e::real assume "e>0"
+  then have "\<forall>x. P x \<longrightarrow> Cauchy (\<lambda>n. s n x)"
+    unfolding cauchy_def
+    apply auto
+    apply (erule_tac x=e in allE)
+    apply auto
+    done
+  then obtain l where l: "\<forall>x. P x \<longrightarrow> ((\<lambda>n. s n x) ---> l x) sequentially"
+    unfolding convergent_eq_cauchy[THEN sym]
+    using choice[of "\<lambda>x l. P x \<longrightarrow> ((\<lambda>n. s n x) ---> l) sequentially"]
+    by auto
+  {
+    fix e :: real
+    assume "e > 0"
     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"
       using `?rhs`[THEN spec[where x="e/2"]] by auto
-    { fix x assume "P x"
+    {
+      fix x
+      assume "P x"
       then obtain M where M:"\<forall>n\<ge>M. dist (s n x) (l x) < e/2"
-        using l[THEN spec[where x=x], unfolded LIMSEQ_def] using `e>0` by(auto elim!: allE[where x="e/2"])
-      fix n::nat assume "n\<ge>N"
-      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]]
-        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)  }
-    hence "\<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist(s n x)(l x) < e" by auto }
-  thus ?lhs by auto
+        using l[THEN spec[where x=x], unfolded LIMSEQ_def] and `e > 0`
+        by (auto elim!: allE[where x="e/2"])
+      fix n :: nat
+      assume "n \<ge> N"
+      then have "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]]
+        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)
+    }
+    then have "\<exists>N. \<forall>n x. N \<le> n \<and> P x \<longrightarrow> dist(s n x)(l x) < e"
+      by auto
+  }
+  then show ?lhs by auto
 qed
 
 lemma uniformly_cauchy_imp_uniformly_convergent:
@@ -4048,13 +4360,17 @@
   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"
           "\<forall>x. P x --> (\<forall>e>0. \<exists>N. \<forall>n. N \<le> n --> dist(s n x)(l x) < e)"
   shows "\<forall>e>0. \<exists>N. \<forall>n x. N \<le> n \<and> P x --> dist(s n x)(l x) < e"
-proof-
+proof -
   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"
     using assms(1) unfolding uniformly_convergent_eq_cauchy[THEN sym] by auto
   moreover
-  { fix x assume "P x"
-    hence "l x = l' x" using tendsto_unique[OF trivial_limit_sequentially, of "\<lambda>n. s n x" "l x" "l' x"]
-      using l and assms(2) unfolding LIMSEQ_def by blast  }
+  {
+    fix x
+    assume "P x"
+    then have "l x = l' x"
+      using tendsto_unique[OF trivial_limit_sequentially, of "\<lambda>n. s n x" "l x" "l' x"]
+      using l and assms(2) unfolding LIMSEQ_def by blast
+  }
   ultimately show ?thesis by auto
 qed
 
@@ -4066,42 +4382,86 @@
 lemma continuous_within_eps_delta:
   "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)"
   unfolding continuous_within and Lim_within
-  apply auto unfolding dist_nz[THEN sym] apply(auto del: allE elim!:allE) apply(rule_tac x=d in exI) by auto
-
-lemma continuous_at_eps_delta: "continuous (at x) f \<longleftrightarrow>  (\<forall>e>0. \<exists>d>0.
-                           \<forall>x'. dist x' x < d --> dist(f x')(f x) < e)"
+  apply auto
+  unfolding dist_nz[THEN sym]
+  apply (auto del: allE elim!:allE)
+  apply(rule_tac x=d in exI)
+  apply auto
+  done
+
+lemma continuous_at_eps_delta:
+  "continuous (at x) f \<longleftrightarrow> (\<forall>e > 0. \<exists>d > 0. \<forall>x'. dist x' x < d \<longrightarrow> dist (f x') (f x) < e)"
   using continuous_within_eps_delta [of x UNIV f] by simp
 
 text{* Versions in terms of open balls. *}
 
 lemma continuous_within_ball:
- "continuous (at x within s) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0.
-                            f ` (ball x d \<inter> s) \<subseteq> ball (f x) e)" (is "?lhs = ?rhs")
+  "continuous (at x within s) f \<longleftrightarrow>
+    (\<forall>e > 0. \<exists>d > 0. f ` (ball x d \<inter> s) \<subseteq> ball (f x) e)"
+  (is "?lhs = ?rhs")
 proof
   assume ?lhs
-  { fix e::real assume "e>0"
+  {
+    fix e :: real
+    assume "e > 0"
     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"
       using `?lhs`[unfolded continuous_within Lim_within] by auto
-    { fix y assume "y\<in>f ` (ball x d \<inter> s)"
-      hence "y \<in> ball (f x) e" using d(2) unfolding dist_nz[THEN sym]
-        apply (auto simp add: dist_commute) apply(erule_tac x=xa in ballE) apply auto using `e>0` by auto
+    {
+      fix y
+      assume "y \<in> f ` (ball x d \<inter> s)"
+      then have "y \<in> ball (f x) e"
+        using d(2)
+        unfolding dist_nz[THEN sym]
+        apply (auto simp add: dist_commute)
+        apply (erule_tac x=xa in ballE)
+        apply auto
+        using `e > 0`
+        apply auto
+        done
     }
-    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)  }
-  thus ?rhs by auto
+    then have "\<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)
+  }
+  then show ?rhs by auto
 next
-  assume ?rhs thus ?lhs unfolding continuous_within Lim_within ball_def subset_eq
-    apply (auto simp add: dist_commute) apply(erule_tac x=e in allE) by auto
+  assume ?rhs
+  then show ?lhs
+    unfolding continuous_within Lim_within ball_def subset_eq
+    apply (auto simp add: dist_commute)
+    apply (erule_tac x=e in allE)
+    apply auto
+    done
 qed
 
 lemma continuous_at_ball:
   "continuous (at x) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0. f ` (ball x d) \<subseteq> ball (f x) e)" (is "?lhs = ?rhs")
 proof
-  assume ?lhs thus ?rhs unfolding continuous_at Lim_at subset_eq Ball_def Bex_def image_iff mem_ball
-    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)
-    unfolding dist_nz[THEN sym] by auto
+  assume ?lhs
+  then show ?rhs
+    unfolding continuous_at Lim_at subset_eq Ball_def Bex_def image_iff mem_ball
+    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)
+    unfolding dist_nz[THEN sym]
+    apply auto
+    done
 next
-  assume ?rhs thus ?lhs unfolding continuous_at Lim_at subset_eq Ball_def Bex_def image_iff mem_ball
-    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)
+  assume ?rhs
+  then show ?lhs
+    unfolding continuous_at Lim_at subset_eq Ball_def Bex_def image_iff mem_ball
+    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)
+    apply (auto simp add: dist_commute dist_nz)
+    done
 qed
 
 text{* Define setwise continuity in terms of limits within the set. *}
@@ -4109,27 +4469,25 @@
 lemma continuous_on_iff:
   "continuous_on s f \<longleftrightarrow>
     (\<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)"
-unfolding continuous_on_def Lim_within
-apply (intro ball_cong [OF refl] all_cong ex_cong)
-apply (rename_tac y, case_tac "y = x", simp)
-apply (simp add: dist_nz)
-done
-
-definition
-  uniformly_continuous_on ::
-    "'a set \<Rightarrow> ('a::metric_space \<Rightarrow> 'b::metric_space) \<Rightarrow> bool"
-where
-  "uniformly_continuous_on s f \<longleftrightarrow>
+  unfolding continuous_on_def Lim_within
+  apply (intro ball_cong [OF refl] all_cong ex_cong)
+  apply (rename_tac y, case_tac "y = x")
+  apply simp
+  apply (simp add: dist_nz)
+  done
+
+definition uniformly_continuous_on :: "'a set \<Rightarrow> ('a::metric_space \<Rightarrow> 'b::metric_space) \<Rightarrow> bool"
+  where "uniformly_continuous_on s f \<longleftrightarrow>
     (\<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)"
 
 text{* Some simple consequential lemmas. *}
 
 lemma uniformly_continuous_imp_continuous:
- " uniformly_continuous_on s f ==> continuous_on s f"
+  "uniformly_continuous_on s f \<Longrightarrow> continuous_on s f"
   unfolding uniformly_continuous_on_def continuous_on_iff by blast
 
 lemma continuous_at_imp_continuous_within:
- "continuous (at x) f ==> continuous (at x within s) f"
+  "continuous (at x) f \<Longrightarrow> continuous (at x within s) f"
   unfolding continuous_within continuous_at using Lim_at_within by auto
 
 lemma Lim_trivial_limit: "trivial_limit net \<Longrightarrow> (f ---> l) net"
@@ -4138,14 +4496,15 @@
 lemmas continuous_on = continuous_on_def -- "legacy theorem name"
 
 lemma continuous_within_subset:
- "continuous (at x within s) f \<Longrightarrow> t \<subseteq> s
-             ==> continuous (at x within t) f"
+  "continuous (at x within s) f \<Longrightarrow> t \<subseteq> s \<Longrightarrow> continuous (at x within t) f"
   unfolding continuous_within by(metis tendsto_within_subset)
 
 lemma continuous_on_interior:
-  shows "continuous_on s f \<Longrightarrow> x \<in> interior s \<Longrightarrow> continuous (at x) f"
-  by (erule interiorE, drule (1) continuous_on_subset,
-    simp add: continuous_on_eq_continuous_at)
+  "continuous_on s f \<Longrightarrow> x \<in> interior s \<Longrightarrow> continuous (at x) f"
+  apply (erule interiorE)
+  apply (drule (1) continuous_on_subset)
+  apply (simp add: continuous_on_eq_continuous_at)
+  done
 
 lemma continuous_on_eq:
   "(\<forall>x \<in> s. f x = g x) \<Longrightarrow> continuous_on s f \<Longrightarrow> continuous_on s g"
@@ -4157,25 +4516,32 @@
 lemma continuous_within_sequentially:
   fixes f :: "'a::metric_space \<Rightarrow> 'b::topological_space"
   shows "continuous (at a within s) f \<longleftrightarrow>
-                (\<forall>x. (\<forall>n::nat. x n \<in> s) \<and> (x ---> a) sequentially
-                     --> ((f o x) ---> f a) sequentially)" (is "?lhs = ?rhs")
+    (\<forall>x. (\<forall>n::nat. x n \<in> s) \<and> (x ---> a) sequentially
+         \<longrightarrow> ((f o x) ---> f a) sequentially)"
+  (is "?lhs = ?rhs")
 proof
   assume ?lhs
-  { 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"
-    fix T::"'b set" assume "open T" and "f a \<in> T"
+  {
+    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"
+    fix T :: "'b set"
+    assume "open T" and "f a \<in> T"
     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"
       unfolding continuous_within tendsto_def eventually_at by (auto simp: dist_nz)
     have "eventually (\<lambda>n. dist (x n) a < d) sequentially"
       using x(2) `d>0` by simp
-    hence "eventually (\<lambda>n. (f \<circ> x) n \<in> T) sequentially"
+    then have "eventually (\<lambda>n. (f \<circ> x) n \<in> T) sequentially"
     proof eventually_elim
-      case (elim n) thus ?case
+      case (elim n)
+      then show ?case
         using d x(1) `f a \<in> T` unfolding dist_nz[THEN sym] by auto
     qed
   }
-  thus ?rhs unfolding tendsto_iff unfolding tendsto_def by simp
+  then show ?rhs
+    unfolding tendsto_iff tendsto_def by simp
 next
-  assume ?rhs thus ?lhs
+  assume ?rhs
+  then show ?lhs
     unfolding continuous_within tendsto_def [where l="f a"]
     by (simp add: sequentially_imp_eventually_within)
 qed
@@ -4192,9 +4558,17 @@
     (\<forall>x. \<forall>a \<in> s. (\<forall>n. x(n) \<in> s) \<and> (x ---> a) sequentially
                     --> ((f o x) ---> f(a)) sequentially)" (is "?lhs = ?rhs")
 proof
-  assume ?rhs thus ?lhs using continuous_within_sequentially[of _ s f] unfolding continuous_on_eq_continuous_within by auto
+  assume ?rhs
+  then show ?lhs
+    using continuous_within_sequentially[of _ s f]
+    unfolding continuous_on_eq_continuous_within
+    by auto
 next
-  assume ?lhs thus ?rhs unfolding continuous_on_eq_continuous_within using continuous_within_sequentially[of _ s f] by auto
+  assume ?lhs
+  then show ?rhs
+    unfolding continuous_on_eq_continuous_within
+    using continuous_within_sequentially[of _ s f]
+    by auto
 qed
 
 lemma uniformly_continuous_on_sequentially:
@@ -4203,67 +4577,108 @@
                     \<longrightarrow> ((\<lambda>n. dist (f(x n)) (f(y n))) ---> 0) sequentially)" (is "?lhs = ?rhs")
 proof
   assume ?lhs
-  { 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"
-    { fix e::real assume "e>0"
-      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"
+  {
+    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"
+    {
+      fix e :: real
+      assume "e > 0"
+      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"
         using `?lhs`[unfolded uniformly_continuous_on_def, THEN spec[where x=e]] by auto
-      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
-      { fix n assume "n\<ge>N"
-        hence "dist (f (x n)) (f (y n)) < e"
-          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
-          unfolding dist_commute by simp  }
-      hence "\<exists>N. \<forall>n\<ge>N. dist (f (x n)) (f (y n)) < e"  by auto  }
-    hence "((\<lambda>n. dist (f(x n)) (f(y n))) ---> 0) sequentially" unfolding LIMSEQ_def and dist_real_def by auto  }
-  thus ?rhs by auto
+      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
+      {
+        fix n
+        assume "n\<ge>N"
+        then have "dist (f (x n)) (f (y n)) < e"
+          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
+          unfolding dist_commute
+          by simp
+      }
+      then have "\<exists>N. \<forall>n\<ge>N. dist (f (x n)) (f (y n)) < e"
+        by auto
+    }
+    then have "((\<lambda>n. dist (f(x n)) (f(y n))) ---> 0) sequentially"
+      unfolding LIMSEQ_def and dist_real_def by auto
+  }
+  then show ?rhs by auto
 next
   assume ?rhs
-  { assume "\<not> ?lhs"
-    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
-    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"
-      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
+  {
+    assume "\<not> ?lhs"
+    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
+    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"
+      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
       by (auto simp add: dist_commute)
     def x \<equiv> "\<lambda>n::nat. fst (fa (inverse (real n + 1)))"
     def y \<equiv> "\<lambda>n::nat. snd (fa (inverse (real n + 1)))"
-    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"
-      unfolding x_def and y_def using fa by auto
-    { fix e::real assume "e>0"
-      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
-      { fix n::nat assume "n\<ge>N"
-        hence "inverse (real n + 1) < inverse (real N)" using real_of_nat_ge_zero and `N\<noteq>0` by auto
+    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"
+      unfolding x_def and y_def using fa
+      by auto
+    {
+      fix e :: real
+      assume "e > 0"
+      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
+      {
+        fix n :: nat
+        assume "n \<ge> N"
+        then have "inverse (real n + 1) < inverse (real N)"
+          using real_of_nat_ge_zero and `N\<noteq>0` by auto
         also have "\<dots> < e" using N by auto
         finally have "inverse (real n + 1) < e" by auto
-        hence "dist (x n) (y n) < e" using xy0[THEN spec[where x=n]] by auto  }
-      hence "\<exists>N. \<forall>n\<ge>N. dist (x n) (y n) < e" by auto  }
-    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
-    hence False using fxy and `e>0` by auto  }
-  thus ?lhs unfolding uniformly_continuous_on_def by blast
+        then have "dist (x n) (y n) < e"
+          using xy0[THEN spec[where x=n]] by auto
+      }
+      then have "\<exists>N. \<forall>n\<ge>N. dist (x n) (y n) < e" by auto
+    }
+    then have "\<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
+    then have False using fxy and `e>0` by auto
+  }
+  then show ?lhs
+    unfolding uniformly_continuous_on_def by blast
 qed
 
 text{* The usual transformation theorems. *}
 
 lemma continuous_transform_within:
   fixes f g :: "'a::metric_space \<Rightarrow> 'b::topological_space"
-  assumes "0 < d" "x \<in> s" "\<forall>x' \<in> s. dist x' x < d --> f x' = g x'"
-          "continuous (at x within s) f"
+  assumes "0 < d"
+    and "x \<in> s"
+    and "\<forall>x' \<in> s. dist x' x < d --> f x' = g x'"
+    and "continuous (at x within s) f"
   shows "continuous (at x within s) g"
-unfolding continuous_within
+  unfolding continuous_within
 proof (rule Lim_transform_within)
   show "0 < d" by fact
   show "\<forall>x'\<in>s. 0 < dist x' x \<and> dist x' x < d \<longrightarrow> f x' = g x'"
     using assms(3) by auto
   have "f x = g x"
     using assms(1,2,3) by auto
-  thus "(f ---> g x) (at x within s)"
+  then show "(f ---> g x) (at x within s)"
     using assms(4) unfolding continuous_within by simp
 qed
 
 lemma continuous_transform_at:
   fixes f g :: "'a::metric_space \<Rightarrow> 'b::topological_space"
-  assumes "0 < d" "\<forall>x'. dist x' x < d --> f x' = g x'"
-          "continuous (at x) f"
+  assumes "0 < d"
+    and "\<forall>x'. dist x' x < d --> f x' = g x'"
+    and "continuous (at x) f"
   shows "continuous (at x) g"
   using continuous_transform_within [of d x UNIV f g] assms by simp
 
+
 subsubsection {* Structural rules for pointwise continuity *}
 
 lemmas continuous_within_id = continuous_ident
@@ -4276,11 +4691,12 @@
   using assms unfolding continuous_def by (rule tendsto_infdist)
 
 lemma continuous_infnorm[continuous_intros]:
-  shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. infnorm (f x))"
+  "continuous F f \<Longrightarrow> continuous F (\<lambda>x. infnorm (f x))"
   unfolding continuous_def by (rule tendsto_infnorm)
 
 lemma continuous_inner[continuous_intros]:
-  assumes "continuous F f" and "continuous F g"
+  assumes "continuous F f"
+    and "continuous F g"
   shows "continuous F (\<lambda>x. inner (f x) (g x))"
   using assms unfolding continuous_def by (rule tendsto_inner)
 
@@ -4289,12 +4705,13 @@
 subsubsection {* Structural rules for setwise continuity *}
 
 lemma continuous_on_infnorm[continuous_on_intros]:
-  shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. infnorm (f x))"
+  "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. infnorm (f x))"
   unfolding continuous_on by (fast intro: tendsto_infnorm)
 
 lemma continuous_on_inner[continuous_on_intros]:
   fixes g :: "'a::topological_space \<Rightarrow> 'b::real_inner"
-  assumes "continuous_on s f" and "continuous_on s g"
+  assumes "continuous_on s f"
+    and "continuous_on s g"
   shows "continuous_on s (\<lambda>x. inner (f x) (g x))"
   using bounded_bilinear_inner assms
   by (rule bounded_bilinear.continuous_on)
@@ -4302,32 +4719,36 @@
 subsubsection {* Structural rules for uniform continuity *}
 
 lemma uniformly_continuous_on_id[continuous_on_intros]:
-  shows "uniformly_continuous_on s (\<lambda>x. x)"
+  "uniformly_continuous_on s (\<lambda>x. x)"
   unfolding uniformly_continuous_on_def by auto
 
 lemma uniformly_continuous_on_const[continuous_on_intros]:
-  shows "uniformly_continuous_on s (\<lambda>x. c)"
+  "uniformly_continuous_on s (\<lambda>x. c)"
   unfolding uniformly_continuous_on_def by simp
 
 lemma uniformly_continuous_on_dist[continuous_on_intros]:
   fixes f g :: "'a::metric_space \<Rightarrow> 'b::metric_space"
   assumes "uniformly_continuous_on s f"
-  assumes "uniformly_continuous_on s g"
+    and "uniformly_continuous_on s g"
   shows "uniformly_continuous_on s (\<lambda>x. dist (f x) (g x))"
 proof -
-  { fix a b c d :: 'b have "\<bar>dist a b - dist c d\<bar> \<le> dist a c + dist b d"
+  {
+    fix a b c d :: 'b
+    have "\<bar>dist a b - dist c d\<bar> \<le> dist a c + dist b d"
       using dist_triangle2 [of a b c] dist_triangle2 [of b c d]
       using dist_triangle3 [of c d a] dist_triangle [of a d b]
       by arith
   } note le = this
-  { fix x y
+  {
+    fix x y
     assume f: "(\<lambda>n. dist (f (x n)) (f (y n))) ----> 0"
     assume g: "(\<lambda>n. dist (g (x n)) (g (y n))) ----> 0"
     have "(\<lambda>n. \<bar>dist (f (x n)) (g (x n)) - dist (f (y n)) (g (y n))\<bar>) ----> 0"
       by (rule Lim_transform_bound [OF _ tendsto_add_zero [OF f g]],
         simp add: le)
   }
-  thus ?thesis using assms unfolding uniformly_continuous_on_sequentially
+  then show ?thesis
+    using assms unfolding uniformly_continuous_on_sequentially
     unfolding dist_real_def by simp
 qed
 
@@ -4364,15 +4785,17 @@
 lemma uniformly_continuous_on_add[continuous_on_intros]:
   fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   assumes "uniformly_continuous_on s f"
-  assumes "uniformly_continuous_on s g"
+    and "uniformly_continuous_on s g"
   shows "uniformly_continuous_on s (\<lambda>x. f x + g x)"
-  using assms unfolding uniformly_continuous_on_sequentially
+  using assms
+  unfolding uniformly_continuous_on_sequentially
   unfolding dist_norm tendsto_norm_zero_iff add_diff_add
   by (auto intro: tendsto_add_zero)
 
 lemma uniformly_continuous_on_diff[continuous_on_intros]:
   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
-  assumes "uniformly_continuous_on s f" and "uniformly_continuous_on s g"
+  assumes "uniformly_continuous_on s f"
+    and "uniformly_continuous_on s g"
   shows "uniformly_continuous_on s (\<lambda>x. f x - g x)"
   unfolding ab_diff_minus using assms
   by (intro uniformly_continuous_on_add uniformly_continuous_on_minus)
@@ -4385,22 +4808,32 @@
   assumes "uniformly_continuous_on s f"  "uniformly_continuous_on (f ` s) g"
   shows "uniformly_continuous_on s (g o f)"
 proof-
-  { fix e::real assume "e>0"
-    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
-    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
-    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  }
-  thus ?thesis using assms unfolding uniformly_continuous_on_def by auto
+  {
+    fix e :: real
+    assume "e > 0"
+    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
+    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
+    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"
+      using `d>0` using d by auto
+  }
+  then show ?thesis
+    using assms unfolding uniformly_continuous_on_def by auto
 qed
 
 text{* Continuity in terms of open preimages. *}
 
 lemma continuous_at_open:
-  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)))"
-unfolding continuous_within_topological [of x UNIV f]
-unfolding imp_conjL by (intro all_cong imp_cong ex_cong conj_cong refl) auto
+  "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)))"
+  unfolding continuous_within_topological [of x UNIV f]
+  unfolding imp_conjL
+  by (intro all_cong imp_cong ex_cong conj_cong refl) auto
 
 lemma continuous_imp_tendsto:
-  assumes "continuous (at x0) f" and "x ----> x0"
+  assumes "continuous (at x0) f"
+    and "x ----> x0"
   shows "(f \<circ> x) ----> (f x0)"
 proof (rule topological_tendstoI)
   fix S
@@ -4415,15 +4848,17 @@
 
 lemma continuous_on_open:
   "continuous_on s f \<longleftrightarrow>
-        (\<forall>t. openin (subtopology euclidean (f ` s)) t
-            --> openin (subtopology euclidean s) {x \<in> s. f x \<in> t})" (is "?lhs = ?rhs")
+    (\<forall>t. openin (subtopology euclidean (f ` s)) t \<longrightarrow>
+      openin (subtopology euclidean s) {x \<in> s. f x \<in> t})"
   unfolding continuous_on_open_invariant openin_open Int_def vimage_def Int_commute
   by (simp add: imp_ex imageI conj_commute eq_commute cong: conj_cong)
 
 text {* Similarly in terms of closed sets. *}
 
 lemma continuous_on_closed:
-  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")
+  "continuous_on s f \<longleftrightarrow>
+    (\<forall>t. closedin (subtopology euclidean (f ` s)) t \<longrightarrow>
+      closedin (subtopology euclidean s) {x \<in> s. f x \<in> t})"
   unfolding continuous_on_closed_invariant closedin_closed Int_def vimage_def Int_commute
   by (simp add: imp_ex imageI conj_commute eq_commute cong: conj_cong)
 
@@ -4432,22 +4867,28 @@
 lemma continuous_open_in_preimage:
   assumes "continuous_on s f"  "open t"
   shows "openin (subtopology euclidean s) {x \<in> s. f x \<in> t}"
-proof-
-  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
+proof -
+  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
   have "openin (subtopology euclidean (f ` s)) (t \<inter> f ` s)"
     using openin_open_Int[of t "f ` s", OF assms(2)] unfolding openin_open by auto
-  thus ?thesis using assms(1)[unfolded continuous_on_open, THEN spec[where x="t \<inter> f ` s"]] using * by auto
+  then show ?thesis
+    using assms(1)[unfolded continuous_on_open, THEN spec[where x="t \<inter> f ` s"]]
+    using * by auto
 qed
 
 lemma continuous_closed_in_preimage:
   assumes "continuous_on s f"  "closed t"
   shows "closedin (subtopology euclidean s) {x \<in> s. f x \<in> t}"
-proof-
-  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
+proof -
+  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
   have "closedin (subtopology euclidean (f ` s)) (t \<inter> f ` s)"
-    using closedin_closed_Int[of t "f ` s", OF assms(2)] unfolding Int_commute by auto
-  thus ?thesis
-    using assms(1)[unfolded continuous_on_closed, THEN spec[where x="t \<inter> f ` s"]] using * by auto
+    using closedin_closed_Int[of t "f ` s", OF assms(2)] unfolding Int_commute
+    by auto
+  then show ?thesis
+    using assms(1)[unfolded continuous_on_closed, THEN spec[where x="t \<inter> f ` s"]]
+    using * by auto
 qed
 
 lemma continuous_open_preimage:
@@ -4456,32 +4897,32 @@
 proof-
   obtain T where T: "open T" "{x \<in> s. f x \<in> t} = s \<inter> T"
     using continuous_open_in_preimage[OF assms(1,3)] unfolding openin_open by auto
-  thus ?thesis using open_Int[of s T, OF assms(2)] by auto
+  then show ?thesis
+    using open_Int[of s T, OF assms(2)] by auto
 qed
 
 lemma continuous_closed_preimage:
   assumes "continuous_on s f" "closed s" "closed t"
   shows "closed {x \<in> s. f x \<in> t}"
 proof-
-  obtain T where T: "closed T" "{x \<in> s. f x \<in> t} = s \<inter> T"
-    using continuous_closed_in_preimage[OF assms(1,3)] unfolding closedin_closed by auto
-  thus ?thesis using closed_Int[of s T, OF assms(2)] by auto
+  obtain T where "closed T" "{x \<in> s. f x \<in> t} = s \<inter> T"
+    using continuous_closed_in_preimage[OF assms(1,3)]
+    unfolding closedin_closed by auto
+  then show ?thesis using closed_Int[of s T, OF assms(2)] by auto
 qed
 
 lemma continuous_open_preimage_univ:
-  shows "\<forall>x. continuous (at x) f \<Longrightarrow> open s \<Longrightarrow> open {x. f x \<in> s}"
+  "\<forall>x. continuous (at x) f \<Longrightarrow> open s \<Longrightarrow> open {x. f x \<in> s}"
   using continuous_open_preimage[of UNIV f s] open_UNIV continuous_at_imp_continuous_on by auto
 
 lemma continuous_closed_preimage_univ:
-  shows "(\<forall>x. continuous (at x) f) \<Longrightarrow> closed s ==> closed {x. f x \<in> s}"
+  "(\<forall>x. continuous (at x) f) \<Longrightarrow> closed s ==> closed {x. f x \<in> s}"
   using continuous_closed_preimage[of UNIV f s] closed_UNIV continuous_at_imp_continuous_on by auto
 
-lemma continuous_open_vimage:
-  shows "\<forall>x. continuous (at x) f \<Longrightarrow> open s \<Longrightarrow> open (f -` s)"
+lemma continuous_open_vimage: "\<forall>x. continuous (at x) f \<Longrightarrow> open s \<Longrightarrow> open (f -` s)"
   unfolding vimage_def by (rule continuous_open_preimage_univ)
 
-lemma continuous_closed_vimage:
-  shows "\<forall>x. continuous (at x) f \<Longrightarrow> closed s \<Longrightarrow> closed (f -` s)"
+lemma continuous_closed_vimage: "\<forall>x. continuous (at x) f \<Longrightarrow> closed s \<Longrightarrow> closed (f -` s)"
   unfolding vimage_def by (rule continuous_closed_preimage_univ)
 
 lemma interior_image_subset:
@@ -4490,7 +4931,7 @@
 proof
   fix x assume "x \<in> interior (f ` s)"
   then obtain T where as: "open T" "x \<in> T" "T \<subseteq> f ` s" ..
-  hence "x \<in> f ` s" by auto
+  then have "x \<in> f ` s" by auto
   then obtain y where y: "y \<in> s" "x = f y" by auto
   have "open (vimage f T)"
     using assms(1) `open T` by (rule continuous_open_vimage)
@@ -4517,71 +4958,89 @@
 lemma continuous_constant_on_closure:
   fixes f :: "_ \<Rightarrow> 'b::t1_space"
   assumes "continuous_on (closure s) f"
-          "\<forall>x \<in> s. f x = a"
+    and "\<forall>x \<in> s. f x = a"
   shows "\<forall>x \<in> (closure s). f x = a"
     using continuous_closed_preimage_constant[of "closure s" f a]
-    assms closure_minimal[of s "{x \<in> closure s. f x = a}"] closure_subset unfolding subset_eq by auto
+      assms closure_minimal[of s "{x \<in> closure s. f x = a}"] closure_subset
+    unfolding subset_eq
+    by auto
 
 lemma image_closure_subset:
   assumes "continuous_on (closure s) f"  "closed t"  "(f ` s) \<subseteq> t"
   shows "f ` (closure s) \<subseteq> t"
-proof-
-  have "s \<subseteq> {x \<in> closure s. f x \<in> t}" using assms(3) closure_subset by auto
+proof -
+  have "s \<subseteq> {x \<in> closure s. f x \<in> t}"
+    using assms(3) closure_subset by auto
   moreover have "closed {x \<in> closure s. f x \<in> t}"
     using continuous_closed_preimage[OF assms(1)] and assms(2) by auto
   ultimately have "closure s = {x \<in> closure s . f x \<in> t}"
     using closure_minimal[of s "{x \<in> closure s. f x \<in> t}"] by auto
-  thus ?thesis by auto
+  then show ?thesis by auto
 qed
 
 lemma continuous_on_closure_norm_le:
   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
-  assumes "continuous_on (closure s) f"  "\<forall>y \<in> s. norm(f y) \<le> b"  "x \<in> (closure s)"
+  assumes "continuous_on (closure s) f"
+    and "\<forall>y \<in> s. norm(f y) \<le> b"
+    and "x \<in> (closure s)"
   shows "norm(f x) \<le> b"
-proof-
-  have *:"f ` s \<subseteq> cball 0 b" using assms(2)[unfolded mem_cball_0[THEN sym]] by auto
+proof -
+  have *: "f ` s \<subseteq> cball 0 b"
+    using assms(2)[unfolded mem_cball_0[THEN sym]] by auto
   show ?thesis
     using image_closure_subset[OF assms(1) closed_cball[of 0 b] *] assms(3)
-    unfolding subset_eq apply(erule_tac x="f x" in ballE) by (auto simp add: dist_norm)
+    unfolding subset_eq
+    apply (erule_tac x="f x" in ballE)
+    apply (auto simp add: dist_norm)
+    done
 qed
 
 text {* Making a continuous function avoid some value in a neighbourhood. *}
 
 lemma continuous_within_avoid:
   fixes f :: "'a::metric_space \<Rightarrow> 'b::t1_space"
-  assumes "continuous (at x within s) f" and "f x \<noteq> a"
+  assumes "continuous (at x within s) f"
+    and "f x \<noteq> a"
   shows "\<exists>e>0. \<forall>y \<in> s. dist x y < e --> f y \<noteq> a"
 proof-
   obtain U where "open U" and "f x \<in> U" and "a \<notin> U"
     using t1_space [OF `f x \<noteq> a`] by fast
   have "(f ---> f x) (at x within s)"
     using assms(1) by (simp add: continuous_within)
-  hence "eventually (\<lambda>y. f y \<in> U) (at x within s)"
+  then have "eventually (\<lambda>y. f y \<in> U) (at x within s)"
     using `open U` and `f x \<in> U`
     unfolding tendsto_def by fast
-  hence "eventually (\<lambda>y. f y \<noteq> a) (at x within s)"
+  then have "eventually (\<lambda>y. f y \<noteq> a) (at x within s)"
     using `a \<notin> U` by (fast elim: eventually_mono [rotated])
-  thus ?thesis
+  then show ?thesis
     using `f x \<noteq> a` by (auto simp: dist_commute zero_less_dist_iff eventually_at)
 qed
 
 lemma continuous_at_avoid:
   fixes f :: "'a::metric_space \<Rightarrow> 'b::t1_space"
-  assumes "continuous (at x) f" and "f x \<noteq> a"
+  assumes "continuous (at x) f"
+    and "f x \<noteq> a"
   shows "\<exists>e>0. \<forall>y. dist x y < e \<longrightarrow> f y \<noteq> a"
   using assms continuous_within_avoid[of x UNIV f a] by simp
 
 lemma continuous_on_avoid:
   fixes f :: "'a::metric_space \<Rightarrow> 'b::t1_space"
-  assumes "continuous_on s f"  "x \<in> s"  "f x \<noteq> a"
+  assumes "continuous_on s f"
+    and "x \<in> s"
+    and "f x \<noteq> a"
   shows "\<exists>e>0. \<forall>y \<in> s. dist x y < e \<longrightarrow> f y \<noteq> a"
-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
+  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]
+  using assms(3)
+  by auto
 
 lemma continuous_on_open_avoid:
   fixes f :: "'a::metric_space \<Rightarrow> 'b::t1_space"
   assumes "continuous_on s f"  "open s"  "x \<in> s"  "f x \<noteq> a"
   shows "\<exists>e>0. \<forall>y. dist x y < e \<longrightarrow> f y \<noteq> a"
-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
+  using assms(1)[unfolded continuous_on_eq_continuous_at[OF assms(2)], THEN bspec[where x=x], OF assms(3)]
+  using continuous_at_avoid[of x f a] assms(4)
+  by auto
 
 text {* Proving a function is constant by proving open-ness of level set. *}
 
@@ -4589,22 +5048,28 @@
   fixes f :: "_ \<Rightarrow> 'b::t1_space"
   shows "connected s \<Longrightarrow> continuous_on s f \<Longrightarrow>
         openin (subtopology euclidean s) {x \<in> s. f x = a}
-        ==> (\<forall>x \<in> s. f x \<noteq> a) \<or> (\<forall>x \<in> s. f x = a)"
-unfolding connected_clopen using continuous_closed_in_preimage_constant by auto
+        \<Longrightarrow> (\<forall>x \<in> s. f x \<noteq> a) \<or> (\<forall>x \<in> s. f x = a)"
+  unfolding connected_clopen
+  using continuous_closed_in_preimage_constant by auto
 
 lemma continuous_levelset_open_in:
   fixes f :: "_ \<Rightarrow> 'b::t1_space"
   shows "connected s \<Longrightarrow> continuous_on s f \<Longrightarrow>
         openin (subtopology euclidean s) {x \<in> s. f x = a} \<Longrightarrow>
         (\<exists>x \<in> s. f x = a)  ==> (\<forall>x \<in> s. f x = a)"
-using continuous_levelset_open_in_cases[of s f ]
-by meson
+  using continuous_levelset_open_in_cases[of s f ]
+  by meson
 
 lemma continuous_levelset_open:
   fixes f :: "_ \<Rightarrow> 'b::t1_space"
-  assumes "connected s"  "continuous_on s f"  "open {x \<in> s. f x = a}"  "\<exists>x \<in> s.  f x = a"
+  assumes "connected s"
+    and "continuous_on s f"
+    and "open {x \<in> s. f x = a}"
+    and "\<exists>x \<in> s.  f x = a"
   shows "\<forall>x \<in> s. f x = a"
-using continuous_levelset_open_in[OF assms(1,2), of a, unfolded openin_open] using assms (3,4) by fast
+  using continuous_levelset_open_in[OF assms(1,2), of a, unfolded openin_open]
+  using assms (3,4)
+  by fast
 
 text {* Some arithmetical combinations (more to prove). *}
 
@@ -4612,18 +5077,38 @@
   fixes s :: "'a::real_normed_vector set"
   assumes "c \<noteq> 0"  "open s"
   shows "open((\<lambda>x. c *\<^sub>R x) ` s)"
-proof-
-  { fix x assume "x \<in> s"
-    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
-    have "e * abs c > 0" using assms(1)[unfolded zero_less_abs_iff[THEN sym]] using mult_pos_pos[OF `e>0`] by auto
+proof -
+  {
+    fix x
+    assume "x \<in> s"
+    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
+    have "e * abs c > 0"
+      using assms(1)[unfolded zero_less_abs_iff[THEN sym]]
+      using mult_pos_pos[OF `e>0`]
+      by auto
     moreover
-    { fix y assume "dist y (c *\<^sub>R x) < e * \<bar>c\<bar>"
-      hence "norm ((1 / c) *\<^sub>R y - x) < e" unfolding dist_norm
+    {
+      fix y
+      assume "dist y (c *\<^sub>R x) < e * \<bar>c\<bar>"
+      then have "norm ((1 / c) *\<^sub>R y - x) < e"
+        unfolding dist_norm
         using norm_scaleR[of c "(1 / c) *\<^sub>R y - x", unfolded scaleR_right_diff_distrib, unfolded scaleR_scaleR] assms(1)
           assms(1)[unfolded zero_less_abs_iff[THEN sym]] by (simp del:zero_less_abs_iff)
-      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  }
-    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  }
-  thus ?thesis unfolding open_dist by auto
+      then have "y \<in> op *\<^sub>R c ` s"
+        using rev_image_eqI[of "(1 / c) *\<^sub>R y" s y "op *\<^sub>R c"]
+        using e[THEN spec[where x="(1 / c) *\<^sub>R y"]]
+        using assms(1)
+        unfolding dist_norm scaleR_scaleR
+        by auto
+    }
+    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)
+      apply auto
+      done
+  }
+  then show ?thesis unfolding open_dist by auto
 qed
 
 lemma minus_image_eq_vimage:
@@ -4640,83 +5125,124 @@
 lemma open_translation:
   fixes s :: "'a::real_normed_vector set"
   assumes "open s"  shows "open((\<lambda>x. a + x) ` s)"
-proof-
-  { fix x have "continuous (at x) (\<lambda>x. x - a)"
-      by (intro continuous_diff continuous_at_id continuous_const) }
-  moreover have "{x. x - a \<in> s} = op + a ` s" by force
-  ultimately show ?thesis using continuous_open_preimage_univ[of "\<lambda>x. x - a" s] using assms by auto
+proof -
+  {
+    fix x
+    have "continuous (at x) (\<lambda>x. x - a)"
+      by (intro continuous_diff continuous_at_id continuous_const)
+  }
+  moreover have "{x. x - a \<in> s} = op + a ` s"
+    by force
+  ultimately show ?thesis using continuous_open_preimage_univ[of "\<lambda>x. x - a" s]
+    using assms by auto
 qed
 
 lemma open_affinity:
   fixes s :: "'a::real_normed_vector set"
   assumes "open s"  "c \<noteq> 0"
   shows "open ((\<lambda>x. a + c *\<^sub>R x) ` s)"
-proof-
-  have *:"(\<lambda>x. a + c *\<^sub>R x) = (\<lambda>x. a + x) \<circ> (\<lambda>x. c *\<^sub>R x)" unfolding o_def ..
-  have "op + a ` op *\<^sub>R c ` s = (op + a \<circ> op *\<^sub>R c) ` s" by auto
-  thus ?thesis using assms open_translation[of "op *\<^sub>R c ` s" a] unfolding * by auto
+proof -
+  have *: "(\<lambda>x. a + c *\<^sub>R x) = (\<lambda>x. a + x) \<circ> (\<lambda>x. c *\<^sub>R x)"
+    unfolding o_def ..
+  have "op + a ` op *\<^sub>R c ` s = (op + a \<circ> op *\<^sub>R c) ` s"
+    by auto
+  then show ?thesis
+    using assms open_translation[of "op *\<^sub>R c ` s" a]
+    unfolding *
+    by auto
 qed
 
 lemma interior_translation:
   fixes s :: "'a::real_normed_vector set"
   shows "interior ((\<lambda>x. a + x) ` s) = (\<lambda>x. a + x) ` (interior s)"
 proof (rule set_eqI, rule)
-  fix x assume "x \<in> interior (op + a ` s)"
-  then obtain e where "e>0" and e:"ball x e \<subseteq> op + a ` s" unfolding mem_interior by auto
-  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
-  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
+  fix x
+  assume "x \<in> interior (op + a ` s)"
+  then obtain e where "e > 0" and e: "ball x e \<subseteq> op + a ` s"
+    unfolding mem_interior by auto
+  then have "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]
+    apply auto
+    done
+  then show "x \<in> op + a ` interior s"
+    unfolding image_iff
+    apply (rule_tac x="x - a" in bexI)
+    unfolding mem_interior
+    using `e > 0`
+    apply auto
+    done
 next
-  fix x assume "x \<in> op + a ` interior s"
-  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
-  { fix z have *:"a + y - z = y + a - z" by auto
-    assume "z\<in>ball x e"
-    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
-    hence "z \<in> op + a ` s" unfolding image_iff by(auto intro!: bexI[where x="z - a"])  }
-  hence "ball x e \<subseteq> op + a ` s" unfolding subset_eq by auto
-  thus "x \<in> interior (op + a ` s)" unfolding mem_interior using `e>0` by auto
+  fix x
+  assume "x \<in> op + a ` interior s"
+  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
+  {
+    fix z
+    have *: "a + y - z = y + a - z" by auto
+    assume "z \<in> ball x e"
+    then have "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
+    then have "z \<in> op + a ` s"
+      unfolding image_iff by (auto intro!: bexI[where x="z - a"])
+  }
+  then have "ball x e \<subseteq> op + a ` s"
+    unfolding subset_eq by auto
+  then show "x \<in> interior (op + a ` s)"
+    unfolding mem_interior using `e > 0` by auto
 qed
 
 text {* Topological properties of linear functions. *}
 
 lemma linear_lim_0:
-  assumes "bounded_linear f" shows "(f ---> 0) (at (0))"
-proof-
+  assumes "bounded_linear f"
+  shows "(f ---> 0) (at (0))"
+proof -
   interpret f: bounded_linear f by fact
   have "(f ---> f 0) (at 0)"
     using tendsto_ident_at by (rule f.tendsto)
-  thus ?thesis unfolding f.zero .
+  then show ?thesis unfolding f.zero .
 qed
 
 lemma linear_continuous_at:
-  assumes "bounded_linear f"  shows "continuous (at a) f"
+  assumes "bounded_linear f"
+  shows "continuous (at a) f"
   unfolding continuous_at using assms
   apply (rule bounded_linear.tendsto)
   apply (rule tendsto_ident_at)
   done
 
 lemma linear_continuous_within:
-  shows "bounded_linear f ==> continuous (at x within s) f"
+  "bounded_linear f ==> continuous (at x within s) f"
   using continuous_at_imp_continuous_within[of x f s] using linear_continuous_at[of f] by auto
 
 lemma linear_continuous_on:
-  shows "bounded_linear f ==> continuous_on s f"
+  "bounded_linear f ==> continuous_on s f"
   using continuous_at_imp_continuous_on[of s f] using linear_continuous_at[of f] by auto
 
 text {* Also bilinear functions, in composition form. *}
 
 lemma bilinear_continuous_at_compose:
-  shows "continuous (at x) f \<Longrightarrow> continuous (at x) g \<Longrightarrow> bounded_bilinear h
-        ==> continuous (at x) (\<lambda>x. h (f x) (g x))"
-  unfolding continuous_at using Lim_bilinear[of f "f x" "(at x)" g "g x" h] by auto
+  "continuous (at x) f \<Longrightarrow> continuous (at x) g \<Longrightarrow> bounded_bilinear h \<Longrightarrow>
+    continuous (at x) (\<lambda>x. h (f x) (g x))"
+  unfolding continuous_at
+  using Lim_bilinear[of f "f x" "(at x)" g "g x" h]
+  by auto
 
 lemma bilinear_continuous_within_compose:
-  shows "continuous (at x within s) f \<Longrightarrow> continuous (at x within s) g \<Longrightarrow> bounded_bilinear h
-        ==> continuous (at x within s) (\<lambda>x. h (f x) (g x))"
-  unfolding continuous_within using Lim_bilinear[of f "f x"] by auto
+  "continuous (at x within s) f \<Longrightarrow> continuous (at x within s) g \<Longrightarrow> bounded_bilinear h \<Longrightarrow>
+    continuous (at x within s) (\<lambda>x. h (f x) (g x))"
+  unfolding continuous_within
+  using Lim_bilinear[of f "f x"]
+  by auto
 
 lemma bilinear_continuous_on_compose:
-  shows "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> bounded_bilinear h
-             ==> continuous_on s (\<lambda>x. h (f x) (g x))"
+  "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> bounded_bilinear h \<Longrightarrow>
+    continuous_on s (\<lambda>x. h (f x) (g x))"
   unfolding continuous_on_def
   by (fast elim: bounded_bilinear.tendsto)
 
@@ -4729,13 +5255,13 @@
 proof safe
   fix C
   assume "compact S" and "\<forall>c\<in>C. openin (subtopology euclidean S) c" and "S \<subseteq> \<Union>C"
-  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}"
+  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}"
     unfolding openin_open by force+
   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"
     by (rule compactE)
-  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)"
+  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)"
     by auto
-  thus "\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D" ..
+  then show "\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D" ..
 next
   assume 1: "\<forall>C. (\<forall>c\<in>C. openin (subtopology euclidean S) c) \<and> S \<subseteq> \<Union>C \<longrightarrow>
         (\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D)"
@@ -4744,7 +5270,7 @@
     fix C
     let ?C = "image (\<lambda>T. S \<inter> T) C"
     assume "\<forall>t\<in>C. open t" and "S \<subseteq> \<Union>C"
-    hence "(\<forall>c\<in>?C. openin (subtopology euclidean S) c) \<and> S \<subseteq> \<Union>?C"
+    then have "(\<forall>c\<in>?C. openin (subtopology euclidean S) c) \<and> S \<subseteq> \<Union>?C"
       unfolding openin_open by auto
     with 1 obtain D where "D \<subseteq> ?C" and "finite D" and "S \<subseteq> \<Union>D"
       by metis
@@ -4762,37 +5288,43 @@
         apply (erule rev_bexI, fast)
         done
     qed
-    thus "\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D" ..
+    then show "\<exists>D\<subseteq>C. finite D \<and> S \<subseteq> \<Union>D" ..
   qed
 qed
 
 lemma connected_continuous_image:
   assumes "continuous_on s f"  "connected s"
   shows "connected(f ` s)"
-proof-
-  { fix T assume as: "T \<noteq> {}"  "T \<noteq> f ` s"  "openin (subtopology euclidean (f ` s)) T"  "closedin (subtopology euclidean (f ` s)) T"
+proof -
+  {
+    fix T
+    assume as: "T \<noteq> {}"  "T \<noteq> f ` s"  "openin (subtopology euclidean (f ` s)) T"  "closedin (subtopology euclidean (f ` s)) T"
     have "{x \<in> s. f x \<in> T} = {} \<or> {x \<in> s. f x \<in> T} = s"
       using assms(1)[unfolded continuous_on_open, THEN spec[where x=T]]
       using assms(1)[unfolded continuous_on_closed, THEN spec[where x=T]]
       using assms(2)[unfolded connected_clopen, THEN spec[where x="{x \<in> s. f x \<in> T}"]] as(3,4) by auto
-    hence False using as(1,2)
-      using as(4)[unfolded closedin_def topspace_euclidean_subtopology] by auto }
-  thus ?thesis unfolding connected_clopen by auto
+    then have False using as(1,2)
+      using as(4)[unfolded closedin_def topspace_euclidean_subtopology] by auto
+  }
+  then show ?thesis
+    unfolding connected_clopen by auto
 qed
 
 text {* Continuity implies uniform continuity on a compact domain. *}
-  
+
 lemma compact_uniformly_continuous:
   assumes f: "continuous_on s f" and s: "compact s"
   shows "uniformly_continuous_on s f"
   unfolding uniformly_continuous_on_def
 proof (cases, safe)
-  fix e :: real assume "0 < e" "s \<noteq> {}"
+  fix e :: real
+  assume "0 < e" "s \<noteq> {}"
   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) } }"
   let ?b = "(\<lambda>(y, d). ball y (d/2))"
   have "(\<forall>r\<in>R. open (?b r))" "s \<subseteq> (\<Union>r\<in>R. ?b r)"
   proof safe
-    fix y assume "y \<in> s"
+    fix y
+    assume "y \<in> s"
     from continuous_open_in_preimage[OF f open_ball]
     obtain T where "open T" and T: "{x \<in> s. f x \<in> ball (f y) (e/2)} = T \<inter> s"
       unfolding openin_subtopology open_openin by metis
@@ -4807,7 +5339,8 @@
     by (subst Min_gr_iff) auto
   show "\<exists>d>0. \<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f x') (f x) < e"
   proof (rule, safe)
-    fix x x' assume in_s: "x' \<in> s" "x \<in> s"
+    fix x x'
+    assume in_s: "x' \<in> s" "x \<in> s"
     with D obtain y d where x: "x \<in> ball y (d/2)" "(y, d) \<in> D"
       by blast
     moreover assume "dist x x' < Min (snd`D) / 2"
@@ -4823,11 +5356,13 @@
 lemma continuous_uniform_limit:
   fixes f :: "'a \<Rightarrow> 'b::metric_space \<Rightarrow> 'c::metric_space"
   assumes "\<not> trivial_limit F"
-  assumes "eventually (\<lambda>n. continuous_on s (f n)) F"
-  assumes "\<forall>e>0. eventually (\<lambda>n. \<forall>x\<in>s. dist (f n x) (g x) < e) F"
+    and "eventually (\<lambda>n. continuous_on s (f n)) F"
+    and "\<forall>e>0. eventually (\<lambda>n. \<forall>x\<in>s. dist (f n x) (g x) < e) F"
   shows "continuous_on s g"
-proof-
-  { fix x and e::real assume "x\<in>s" "e>0"
+proof -
+  {
+    fix x and e :: real
+    assume "x\<in>s" "e>0"
     have "eventually (\<lambda>n. \<forall>x\<in>s. dist (f n x) (g x) < e / 3) F"
       using `e>0` assms(3)[THEN spec[where x="e/3"]] by auto
     from eventually_happens [OF eventually_conj [OF this assms(2)]]
@@ -4836,29 +5371,33 @@
     have "e / 3 > 0" using `e>0` by auto
     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"
       using n(2)[unfolded continuous_on_iff, THEN bspec[where x=x], OF `x\<in>s`, THEN spec[where x="e/3"]] by blast
-    { fix y assume "y \<in> s" and "dist y x < d"
-      hence "dist (f n y) (f n x) < e / 3"
+    {
+      fix y
+      assume "y \<in> s" and "dist y x < d"
+      then have "dist (f n y) (f n x) < e / 3"
         by (rule d [rule_format])
-      hence "dist (f n y) (g x) < 2 * e / 3"
+      then have "dist (f n y) (g x) < 2 * e / 3"
         using dist_triangle [of "f n y" "g x" "f n x"]
         using n(1)[THEN bspec[where x=x], OF `x\<in>s`]
         by auto
-      hence "dist (g y) (g x) < e"
+      then have "dist (g y) (g x) < e"
         using n(1)[THEN bspec[where x=y], OF `y\<in>s`]
         using dist_triangle3 [of "g y" "g x" "f n y"]
-        by auto }
-    hence "\<exists>d>0. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (g x') (g x) < e"
-      using `d>0` by auto }
-  thus ?thesis unfolding continuous_on_iff by auto
+        by auto
+    }
+    then have "\<exists>d>0. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (g x') (g x) < e"
+      using `d>0` by auto
+  }
+  then show ?thesis
+    unfolding continuous_on_iff by auto
 qed
 
 
 subsection {* Topological stuff lifted from and dropped to R *}
 
 lemma open_real:
-  fixes s :: "real set" shows
- "open s \<longleftrightarrow>
-        (\<forall>x \<in> s. \<exists>e>0. \<forall>x'. abs(x' - x) < e --> x' \<in> s)" (is "?lhs = ?rhs")
+  fixes s :: "real set"
+  shows "open s \<longleftrightarrow> (\<forall>x \<in> s. \<exists>e>0. \<forall>x'. abs(x' - x) < e --> x' \<in> s)"
   unfolding open_dist dist_norm by simp
 
 lemma islimpt_approachable_real:
@@ -4868,23 +5407,31 @@
 
 lemma closed_real:
   fixes s :: "real set"
-  shows "closed s \<longleftrightarrow>
-        (\<forall>x. (\<forall>e>0.  \<exists>x' \<in> s. x' \<noteq> x \<and> abs(x' - x) < e)
-            --> x \<in> s)"
+  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)"
   unfolding closed_limpt islimpt_approachable dist_norm by simp
 
 lemma continuous_at_real_range:
   fixes f :: "'a::real_normed_vector \<Rightarrow> real"
-  shows "continuous (at x) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0.
-        \<forall>x'. norm(x' - x) < d --> abs(f x' - f x) < e)"
-  unfolding continuous_at unfolding Lim_at
-  unfolding dist_nz[THEN sym] unfolding dist_norm apply auto
-  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
-  apply(erule_tac x=e in allE) by auto
+  shows "continuous (at x) f \<longleftrightarrow> (\<forall>e>0. \<exists>d>0. \<forall>x'. norm(x' - x) < d --> abs(f x' - f x) < e)"
+  unfolding continuous_at
+  unfolding Lim_at
+  unfolding dist_nz[THEN sym]
+  unfolding dist_norm
+  apply auto
+  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
+  apply (erule_tac x=e in allE)
+  apply auto
+  done
 
 lemma continuous_on_real_range:
   fixes f :: "'a::real_normed_vector \<Rightarrow> real"
-  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))"
+  shows "continuous_on s f \<longleftrightarrow>
+    (\<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))"
   unfolding continuous_on_iff dist_norm by simp
 
 text {* Hence some handy theorems on distance, diameter etc. of/from a set. *}
@@ -4893,11 +5440,13 @@
   assumes "compact s" "s \<noteq> {}"
   shows "\<exists>x\<in>s. \<forall>y\<in>s. dist a y \<le> dist a x"
 proof (rule continuous_attains_sup [OF assms])
-  { fix x assume "x\<in>s"
+  {
+    fix x
+    assume "x\<in>s"
     have "(dist a ---> dist a x) (at x within s)"
       by (intro tendsto_dist tendsto_const tendsto_ident_at)
   }
-  thus "continuous_on s (dist a)"
+  then show "continuous_on s (dist a)"
     unfolding continuous_on ..
 qed
 
@@ -4907,63 +5456,68 @@
   fixes a :: "'a::heine_borel"
   assumes "closed s"  "s \<noteq> {}"
   shows "\<exists>x\<in>s. \<forall>y\<in>s. dist a x \<le> dist a y"
-proof-
+proof -
   from assms(2) obtain b where "b \<in> s" by auto
   let ?B = "s \<inter> cball a (dist b a)"
-  have "?B \<noteq> {}" using `b \<in> s` by (auto simp add: dist_commute)
+  have "?B \<noteq> {}" using `b \<in> s`
+    by (auto simp add: dist_commute)
   moreover have "continuous_on ?B (dist a)"
     by (auto intro!: continuous_at_imp_continuous_on continuous_dist continuous_at_id continuous_const)
   moreover have "compact ?B"
     by (intro closed_inter_compact `closed s` compact_cball)
   ultimately obtain x where "x \<in> ?B" "\<forall>y\<in>?B. dist a x \<le> dist a y"
     by (metis continuous_attains_inf)
-  thus ?thesis by fastforce
+  then show ?thesis by fastforce
 qed
 
 
 subsection {* Pasted sets *}
 
 lemma bounded_Times:
-  assumes "bounded s" "bounded t" shows "bounded (s \<times> t)"
-proof-
+  assumes "bounded s" "bounded t"
+  shows "bounded (s \<times> t)"
+proof -
   obtain x y a b where "\<forall>z\<in>s. dist x z \<le> a" "\<forall>z\<in>t. dist y z \<le> b"
     using assms [unfolded bounded_def] by auto
   then have "\<forall>z\<in>s \<times> t. dist (x, y) z \<le> sqrt (a\<^sup>2 + b\<^sup>2)"
     by (auto simp add: dist_Pair_Pair real_sqrt_le_mono add_mono power_mono)
-  thus ?thesis unfolding bounded_any_center [where a="(x, y)"] by auto
+  then show ?thesis unfolding bounded_any_center [where a="(x, y)"] by auto
 qed
 
 lemma mem_Times_iff: "x \<in> A \<times> B \<longleftrightarrow> fst x \<in> A \<and> snd x \<in> B"
-by (induct x) simp
+  by (induct x) simp
 
 lemma seq_compact_Times: "seq_compact s \<Longrightarrow> seq_compact t \<Longrightarrow> seq_compact (s \<times> t)"
-unfolding seq_compact_def
-apply clarify
-apply (drule_tac x="fst \<circ> f" in spec)
-apply (drule mp, simp add: mem_Times_iff)
-apply (clarify, rename_tac l1 r1)
-apply (drule_tac x="snd \<circ> f \<circ> r1" in spec)
-apply (drule mp, simp add: mem_Times_iff)
-apply (clarify, rename_tac l2 r2)
-apply (rule_tac x="(l1, l2)" in rev_bexI, simp)
-apply (rule_tac x="r1 \<circ> r2" in exI)
-apply (rule conjI, simp add: subseq_def)
-apply (drule_tac f=r2 in LIMSEQ_subseq_LIMSEQ, assumption)
-apply (drule (1) tendsto_Pair) back
-apply (simp add: o_def)
-done
-
-lemma compact_Times: 
+  unfolding seq_compact_def
+  apply clarify
+  apply (drule_tac x="fst \<circ> f" in spec)
+  apply (drule mp, simp add: mem_Times_iff)
+  apply (clarify, rename_tac l1 r1)
+  apply (drule_tac x="snd \<circ> f \<circ> r1" in spec)
+  apply (drule mp, simp add: mem_Times_iff)
+  apply (clarify, rename_tac l2 r2)
+  apply (rule_tac x="(l1, l2)" in rev_bexI, simp)
+  apply (rule_tac x="r1 \<circ> r2" in exI)
+  apply (rule conjI, simp add: subseq_def)
+  apply (drule_tac f=r2 in LIMSEQ_subseq_LIMSEQ, assumption)
+  apply (drule (1) tendsto_Pair) back
+  apply (simp add: o_def)
+  done
+
+lemma compact_Times:
   assumes "compact s" "compact t"
   shows "compact (s \<times> t)"
 proof (rule compactI)
-  fix C assume C: "\<forall>t\<in>C. open t" "s \<times> t \<subseteq> \<Union>C"
+  fix C
+  assume C: "\<forall>t\<in>C. open t" "s \<times> t \<subseteq> \<Union>C"
   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)"
   proof
-    fix x assume "x \<in> s"
+    fix x
+    assume "x \<in> s"
     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")
-    proof 
-      fix y assume "y \<in> t"
+    proof
+      fix y
+      assume "y \<in> t"
       with `x \<in> s` C obtain c where "c \<in> C" "(x, y) \<in> c" "open c" by auto
       then show "?P y" by (auto elim!: open_prod_elim)
     qed
@@ -4981,12 +5535,18 @@
   then obtain a d where a: "\<forall>x\<in>s. open (a x)" "s \<subseteq> (\<Union>x\<in>s. a x)"
     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"
     unfolding subset_eq UN_iff by metis
-  moreover from compactE_image[OF `compact s` a] obtain e where e: "e \<subseteq> s" "finite e"
-    and s: "s \<subseteq> (\<Union>x\<in>e. a x)" by auto
+  moreover
+  from compactE_image[OF `compact s` a]
+  obtain e where e: "e \<subseteq> s" "finite e" and s: "s \<subseteq> (\<Union>x\<in>e. a x)"
+    by auto
   moreover
-  { from s have "s \<times> t \<subseteq> (\<Union>x\<in>e. a x \<times> t)" by auto
-    also have "\<dots> \<subseteq> (\<Union>x\<in>e. \<Union>d x)" using d `e \<subseteq> s` by (intro UN_mono) auto
-    finally have "s \<times> t \<subseteq> (\<Union>x\<in>e. \<Union>d x)" . }
+  {
+    from s have "s \<times> t \<subseteq> (\<Union>x\<in>e. a x \<times> t)"
+      by auto
+    also have "\<dots> \<subseteq> (\<Union>x\<in>e. \<Union>d x)"
+      using d `e \<subseteq> s` by (intro UN_mono) auto
+    finally have "s \<times> t \<subseteq> (\<Union>x\<in>e. \<Union>d x)" .
+  }
   ultimately show "\<exists>C'\<subseteq>C. finite C' \<and> s \<times> t \<subseteq> \<Union>C'"
     by (intro exI[of _ "(\<Union>x\<in>e. d x)"]) (auto simp add: subset_eq)
 qed
@@ -4995,28 +5555,38 @@
 
 lemma compact_scaling:
   fixes s :: "'a::real_normed_vector set"
-  assumes "compact s"  shows "compact ((\<lambda>x. c *\<^sub>R x) ` s)"
-proof-
+  assumes "compact s"
+  shows "compact ((\<lambda>x. c *\<^sub>R x) ` s)"
+proof -
   let ?f = "\<lambda>x. scaleR c x"
-  have *:"bounded_linear ?f" by (rule bounded_linear_scaleR_right)
-  show ?thesis using compact_continuous_image[of s ?f] continuous_at_imp_continuous_on[of s ?f]
-    using linear_continuous_at[OF *] assms by auto
+  have *: "bounded_linear ?f" by (rule bounded_linear_scaleR_right)
+  show ?thesis
+    using compact_continuous_image[of s ?f] continuous_at_imp_continuous_on[of s ?f]
+    using linear_continuous_at[OF *] assms
+    by auto
 qed
 
 lemma compact_negations:
   fixes s :: "'a::real_normed_vector set"
-  assumes "compact s"  shows "compact ((\<lambda>x. -x) ` s)"
+  assumes "compact s"
+  shows "compact ((\<lambda>x. -x) ` s)"
   using compact_scaling [OF assms, of "- 1"] by auto
 
 lemma compact_sums:
   fixes s t :: "'a::real_normed_vector set"
-  assumes "compact s"  "compact t"  shows "compact {x + y | x y. x \<in> s \<and> y \<in> t}"
-proof-
-  have *:"{x + y | x y. x \<in> s \<and> y \<in> t} = (\<lambda>z. fst z + snd z) ` (s \<times> t)"
-    apply auto unfolding image_iff apply(rule_tac x="(xa, y)" in bexI) by auto
+  assumes "compact s" and "compact t"
+  shows "compact {x + y | x y. x \<in> s \<and> y \<in> t}"
+proof -
+  have *: "{x + y | x y. x \<in> s \<and> y \<in> t} = (\<lambda>z. fst z + snd z) ` (s \<times> t)"
+    apply auto
+    unfolding image_iff
+    apply (rule_tac x="(xa, y)" in bexI)
+    apply auto
+    done
   have "continuous_on (s \<times> t) (\<lambda>z. fst z + snd z)"
     unfolding continuous_on by (rule ballI) (intro tendsto_intros)
-  thus ?thesis unfolding * using compact_continuous_image compact_Times [OF assms] by auto
+  then show ?thesis
+    unfolding * using compact_continuous_image compact_Times [OF assms] by auto
 qed
 
 lemma compact_differences:
@@ -5024,24 +5594,36 @@
   assumes "compact s" "compact t"  shows "compact {x - y | x y. x \<in> s \<and> y \<in> t}"
 proof-
   have "{x - y | x y. x\<in>s \<and> y \<in> t} =  {x + y | x y. x \<in> s \<and> y \<in> (uminus ` t)}"
-    apply auto apply(rule_tac x= xa in exI) apply auto apply(rule_tac x=xa in exI) by auto
-  thus ?thesis using compact_sums[OF assms(1) compact_negations[OF assms(2)]] by auto
+    apply auto
+    apply (rule_tac x= xa in exI)
+    apply auto
+    apply (rule_tac x=xa in exI)
+    apply auto
+    done
+  then show ?thesis
+    using compact_sums[OF assms(1) compact_negations[OF assms(2)]] by auto
 qed
 
 lemma compact_translation:
   fixes s :: "'a::real_normed_vector set"
-  assumes "compact s"  shows "compact ((\<lambda>x. a + x) ` s)"
-proof-
-  have "{x + y |x y. x \<in> s \<and> y \<in> {a}} = (\<lambda>x. a + x) ` s" by auto
-  thus ?thesis using compact_sums[OF assms compact_sing[of a]] by auto
+  assumes "compact s"
+  shows "compact ((\<lambda>x. a + x) ` s)"
+proof -
+  have "{x + y |x y. x \<in> s \<and> y \<in> {a}} = (\<lambda>x. a + x) ` s"
+    by auto
+  then show ?thesis
+    using compact_sums[OF assms compact_sing[of a]] by auto
 qed
 
 lemma compact_affinity:
   fixes s :: "'a::real_normed_vector set"
-  assumes "compact s"  shows "compact ((\<lambda>x. a + c *\<^sub>R x) ` s)"
-proof-
-  have "op + a ` op *\<^sub>R c ` s = (\<lambda>x. a + c *\<^sub>R x) ` s" by auto
-  thus ?thesis using compact_translation[OF compact_scaling[OF assms], of a c] by auto
+  assumes "compact s"
+  shows "compact ((\<lambda>x. a + c *\<^sub>R x) ` s)"
+proof -
+  have "op + a ` op *\<^sub>R c ` s = (\<lambda>x. a + c *\<^sub>R x) ` s"
+    by auto
+  then show ?thesis
+    using compact_translation[OF compact_scaling[OF assms], of a c] by auto
 qed
 
 text {* Hence we get the following. *}
@@ -5050,9 +5632,11 @@
   fixes s :: "'a::metric_space set"
   assumes "compact s"  "s \<noteq> {}"
   shows "\<exists>x\<in>s. \<exists>y\<in>s. \<forall>u\<in>s. \<forall>v\<in>s. dist u v \<le> dist x y"
-proof-
-  have "compact (s \<times> s)" using `compact s` by (intro compact_Times)
-  moreover have "s \<times> s \<noteq> {}" using `s \<noteq> {}` by auto
+proof -
+  have "compact (s \<times> s)"
+    using `compact s` by (intro compact_Times)
+  moreover have "s \<times> s \<noteq> {}"
+    using `s \<noteq> {}` by auto
   moreover have "continuous_on (s \<times> s) (\<lambda>x. dist (fst x) (snd x))"
     by (intro continuous_at_imp_continuous_on ballI continuous_intros)
   ultimately show ?thesis
@@ -5073,7 +5657,8 @@
     unfolding bounded_def by auto
   have "dist x y \<le> Sup ?D"
   proof (rule cSup_upper, safe)
-    fix a b assume "a \<in> s" "b \<in> s"
+    fix a b
+    assume "a \<in> s" "b \<in> s"
     with z[of a] z[of b] dist_triangle[of a b z]
     show "dist a b \<le> 2 * d"
       by (simp add: dist_commute)
@@ -5084,7 +5669,8 @@
 
 lemma diameter_lower_bounded:
   fixes s :: "'a :: metric_space set"
-  assumes s: "bounded s" and d: "0 < d" "d < diameter s"
+  assumes s: "bounded s"
+    and d: "0 < d" "d < diameter s"
   shows "\<exists>x\<in>s. \<exists>y\<in>s. d < dist x y"
 proof (rule ccontr)
   let ?D = "{dist x y |x y. x \<in> s \<and> y \<in> s}"
@@ -5110,12 +5696,17 @@
   assumes "compact s"  "s \<noteq> {}"
   shows "\<exists>x\<in>s. \<exists>y\<in>s. dist x y = diameter s"
 proof -
-  have b:"bounded s" using assms(1) by (rule compact_imp_bounded)
-  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"
+  have b: "bounded s" using assms(1)
+    by (rule compact_imp_bounded)
+  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"
     using compact_sup_maxdistance[OF assms] by auto
-  hence "diameter s \<le> dist x y"
-    unfolding diameter_def by clarsimp (rule cSup_least, fast+)
-  thus ?thesis
+  then have "diameter s \<le> dist x y"
+    unfolding diameter_def
+    apply clarsimp
+    apply (rule cSup_least)
+    apply fast+
+    done
+  then show ?thesis
     by (metis b diameter_bounded_bound order_antisym xys)
 qed
 
@@ -5123,109 +5714,175 @@
 
 lemma closed_scaling:
   fixes s :: "'a::real_normed_vector set"
-  assumes "closed s" shows "closed ((\<lambda>x. c *\<^sub>R x) ` s)"
-proof(cases "s={}")
-  case True thus ?thesis by auto
+  assumes "closed s"
+  shows "closed ((\<lambda>x. c *\<^sub>R x) ` s)"
+proof (cases "s = {}")
+  case True
+  then show ?thesis by auto
 next
   case False
   show ?thesis
-  proof(cases "c=0")
-    have *:"(\<lambda>x. 0) ` s = {0}" using `s\<noteq>{}` by auto
-    case True thus ?thesis apply auto unfolding * by auto
+  proof (cases "c = 0")
+    have *: "(\<lambda>x. 0) ` s = {0}" using `s\<noteq>{}` by auto
+    case True
+    then show ?thesis
+      apply auto
+      unfolding *
+      apply auto
+      done
   next
     case False
-    { fix x l assume as:"\<forall>n::nat. x n \<in> scaleR c ` s"  "(x ---> l) sequentially"
-      { fix n::nat have "scaleR (1 / c) (x n) \<in> s"
+    {
+      fix x l
+      assume as: "\<forall>n::nat. x n \<in> scaleR c ` s"  "(x ---> l) sequentially"
+      {
+        fix n :: nat
+        have "scaleR (1 / c) (x n) \<in> s"
           using as(1)[THEN spec[where x=n]]
-          using `c\<noteq>0` by auto
+          using `c\<noteq>0`
+          by auto
       }
       moreover
-      { fix e::real assume "e>0"
-        hence "0 < e *\<bar>c\<bar>"  using `c\<noteq>0` mult_pos_pos[of e "abs c"] by auto
+      {
+        fix e :: real
+        assume "e > 0"
+        then have "0 < e *\<bar>c\<bar>"
+          using `c\<noteq>0` mult_pos_pos[of e "abs c"] by auto
         then obtain N where "\<forall>n\<ge>N. dist (x n) l < e * \<bar>c\<bar>"
           using as(2)[unfolded LIMSEQ_def, THEN spec[where x="e * abs c"]] by auto
-        hence "\<exists>N. \<forall>n\<ge>N. dist (scaleR (1 / c) (x n)) (scaleR (1 / c) l) < e"
-          unfolding dist_norm unfolding scaleR_right_diff_distrib[THEN sym]
-          using mult_imp_div_pos_less[of "abs c" _ e] `c\<noteq>0` by auto  }
-      hence "((\<lambda>n. scaleR (1 / c) (x n)) ---> scaleR (1 / c) l) sequentially" unfolding LIMSEQ_def by auto
+        then have "\<exists>N. \<forall>n\<ge>N. dist (scaleR (1 / c) (x n)) (scaleR (1 / c) l) < e"
+          unfolding dist_norm
+          unfolding scaleR_right_diff_distrib[THEN sym]
+          using mult_imp_div_pos_less[of "abs c" _ e] `c\<noteq>0` by auto
+      }
+      then have "((\<lambda>n. scaleR (1 / c) (x n)) ---> scaleR (1 / c) l) sequentially"
+        unfolding LIMSEQ_def by auto
       ultimately have "l \<in> scaleR c ` s"
-        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"]]
-        unfolding image_iff using `c\<noteq>0` apply(rule_tac x="scaleR (1 / c) l" in bexI) by auto  }
-    thus ?thesis unfolding closed_sequential_limits by fast
+        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"]]
+        unfolding image_iff using `c\<noteq>0`
+          apply (rule_tac x="scaleR (1 / c) l" in bexI)
+          apply auto
+          done
+    }
+    then show ?thesis
+      unfolding closed_sequential_limits by fast
   qed
 qed
 
 lemma closed_negations:
   fixes s :: "'a::real_normed_vector set"
-  assumes "closed s"  shows "closed ((\<lambda>x. -x) ` s)"
+  assumes "closed s"
+  shows "closed ((\<lambda>x. -x) ` s)"
   using closed_scaling[OF assms, of "- 1"] by simp
 
 lemma compact_closed_sums:
   fixes s :: "'a::real_normed_vector set"
-  assumes "compact s"  "closed t"  shows "closed {x + y | x y. x \<in> s \<and> y \<in> t}"
-proof-
+  assumes "compact s" and "closed t"
+  shows "closed {x + y | x y. x \<in> s \<and> y \<in> t}"
+proof -
   let ?S = "{x + y |x y. x \<in> s \<and> y \<in> t}"
-  { fix x l assume as:"\<forall>n. x n \<in> ?S"  "(x ---> l) sequentially"
-    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"
+  {
+    fix x l
+    assume as: "\<forall>n. x n \<in> ?S"  "(x ---> l) sequentially"
+    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"
       using choice[of "\<lambda>n y. x n = (fst y) + (snd y) \<and> fst y \<in> s \<and> snd y \<in> t"] by auto
-    obtain l' r where "l'\<in>s" and r:"subseq r" and lr:"(((\<lambda>n. fst (f n)) \<circ> r) ---> l') sequentially"
+    obtain l' r where "l'\<in>s" and r: "subseq r" and lr: "(((\<lambda>n. fst (f n)) \<circ> r) ---> l') sequentially"
       using assms(1)[unfolded compact_def, THEN spec[where x="\<lambda> n. fst (f n)"]] using f(2) by auto
     have "((\<lambda>n. snd (f (r n))) ---> l - l') sequentially"
-      using tendsto_diff[OF LIMSEQ_subseq_LIMSEQ[OF as(2) r] lr] and f(1) unfolding o_def by auto
-    hence "l - l' \<in> t"
+      using tendsto_diff[OF LIMSEQ_subseq_LIMSEQ[OF as(2) r] lr] and f(1)
+      unfolding o_def
+      by auto
+    then have "l - l' \<in> t"
       using assms(2)[unfolded closed_sequential_limits, THEN spec[where x="\<lambda> n. snd (f (r n))"], THEN spec[where x="l - l'"]]
-      using f(3) by auto
-    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
+      using f(3)
+      by auto
+    then have "l \<in> ?S"
+      using `l' \<in> s`
+      apply auto
+      apply (rule_tac x=l' in exI)
+      apply (rule_tac x="l - l'" in exI)
+      apply auto
+      done
   }
-  thus ?thesis unfolding closed_sequential_limits by fast
+  then show ?thesis
+    unfolding closed_sequential_limits by fast
 qed
 
 lemma closed_compact_sums:
   fixes s t :: "'a::real_normed_vector set"
   assumes "closed s"  "compact t"
   shows "closed {x + y | x y. x \<in> s \<and> y \<in> t}"
-proof-
-  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
-    apply(rule_tac x=y in exI) apply auto apply(rule_tac x=y in exI) by auto
-  thus ?thesis using compact_closed_sums[OF assms(2,1)] by simp
+proof -
+  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
+    apply (rule_tac x=y in exI)
+    apply auto
+    apply (rule_tac x=y in exI)
+    apply auto
+    done
+  then show ?thesis
+    using compact_closed_sums[OF assms(2,1)] by simp
 qed
 
 lemma compact_closed_differences:
   fixes s t :: "'a::real_normed_vector set"
-  assumes "compact s"  "closed t"
+  assumes "compact s" and "closed t"
   shows "closed {x - y | x y. x \<in> s \<and> y \<in> t}"
-proof-
+proof -
   have "{x + y |x y. x \<in> s \<and> y \<in> uminus ` t} =  {x - y |x y. x \<in> s \<and> y \<in> t}"
-    apply auto apply(rule_tac x=xa in exI) apply auto apply(rule_tac x=xa in exI) by auto
-  thus ?thesis using compact_closed_sums[OF assms(1) closed_negations[OF assms(2)]] by auto
+    apply auto
+    apply (rule_tac x=xa in exI)
+    apply auto
+    apply (rule_tac x=xa in exI)
+    apply auto
+    done
+  then show ?thesis
+    using compact_closed_sums[OF assms(1) closed_negations[OF assms(2)]] by auto
 qed
 
 lemma closed_compact_differences:
   fixes s t :: "'a::real_normed_vector set"
   assumes "closed s" "compact t"
   shows "closed {x - y | x y. x \<in> s \<and> y \<in> t}"
-proof-
+proof -
   have "{x + y |x y. x \<in> s \<and> y \<in> uminus ` t} = {x - y |x y. x \<in> s \<and> y \<in> t}"
-    apply auto apply(rule_tac x=xa in exI) apply auto apply(rule_tac x=xa in exI) by auto
- thus ?thesis using closed_compact_sums[OF assms(1) compact_negations[OF assms(2)]] by simp
+    apply auto
+    apply (rule_tac x=xa in exI)
+    apply auto
+    apply (rule_tac x=xa in exI)
+    apply auto
+    done
+ then show ?thesis
+  using closed_compact_sums[OF assms(1) compact_negations[OF assms(2)]] by simp
 qed
 
 lemma closed_translation:
   fixes a :: "'a::real_normed_vector"
-  assumes "closed s"  shows "closed ((\<lambda>x. a + x) ` s)"
-proof-
+  assumes "closed s"
+  shows "closed ((\<lambda>x. a + x) ` s)"
+proof -
   have "{a + y |y. y \<in> s} = (op + a ` s)" by auto
-  thus ?thesis using compact_closed_sums[OF compact_sing[of a] assms] by auto
+  then show ?thesis
+    using compact_closed_sums[OF compact_sing[of a] assms] by auto
 qed
 
 lemma translation_Compl:
   fixes a :: "'a::ab_group_add"
   shows "(\<lambda>x. a + x) ` (- t) = - ((\<lambda>x. a + x) ` t)"
-  apply (auto simp add: image_iff) apply(rule_tac x="x - a" in bexI) by auto
+  apply (auto simp add: image_iff)
+  apply (rule_tac x="x - a" in bexI)
+  apply auto
+  done
 
 lemma translation_UNIV:
-  fixes a :: "'a::ab_group_add" shows "range (\<lambda>x. a + x) = UNIV"
-  apply (auto simp add: image_iff) apply(rule_tac x="x - a" in exI) by auto
+  fixes a :: "'a::ab_group_add"
+  shows "range (\<lambda>x. a + x) = UNIV"
+  apply (auto simp add: image_iff)
+  apply (rule_tac x="x - a" in exI)
+  apply auto
+  done
 
 lemma translation_diff:
   fixes a :: "'a::ab_group_add"
@@ -5235,37 +5892,48 @@
 lemma closure_translation:
   fixes a :: "'a::real_normed_vector"
   shows "closure ((\<lambda>x. a + x) ` s) = (\<lambda>x. a + x) ` (closure s)"
-proof-
-  have *:"op + a ` (- s) = - op + a ` s"
-    apply auto unfolding image_iff apply(rule_tac x="x - a" in bexI) by auto
-  show ?thesis unfolding closure_interior translation_Compl
-    using interior_translation[of a "- s"] unfolding * by auto
+proof -
+  have *: "op + a ` (- s) = - op + a ` s"
+    apply auto
+    unfolding image_iff
+    apply (rule_tac x="x - a" in bexI)
+    apply auto
+    done
+  show ?thesis
+    unfolding closure_interior translation_Compl
+    using interior_translation[of a "- s"]
+    unfolding *
+    by auto
 qed
 
 lemma frontier_translation:
   fixes a :: "'a::real_normed_vector"
   shows "frontier((\<lambda>x. a + x) ` s) = (\<lambda>x. a + x) ` (frontier s)"
-  unfolding frontier_def translation_diff interior_translation closure_translation by auto
+  unfolding frontier_def translation_diff interior_translation closure_translation
+  by auto
 
 
 subsection {* Separation between points and sets *}
 
 lemma separate_point_closed:
   fixes s :: "'a::heine_borel set"
-  shows "closed s \<Longrightarrow> a \<notin> s  ==> (\<exists>d>0. \<forall>x\<in>s. d \<le> dist a x)"
-proof(cases "s = {}")
+  assumes "closed s" and "a \<notin> s"
+  shows "\<exists>d>0. \<forall>x\<in>s. d \<le> dist a x"
+proof (cases "s = {}")
   case True
-  thus ?thesis by(auto intro!: exI[where x=1])
+  then show ?thesis by(auto intro!: exI[where x=1])
 next
   case False
-  assume "closed s" "a \<notin> s"
-  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
-  with `x\<in>s` show ?thesis using dist_pos_lt[of a x] and`a \<notin> s` by blast
+  from assms 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
+  with `x\<in>s` show ?thesis using dist_pos_lt[of a x] and`a \<notin> s`
+    by blast
 qed
 
 lemma separate_compact_closed:
   fixes s t :: "'a::heine_borel set"
-  assumes "compact s" and t: "closed t" "s \<inter> t = {}"
+  assumes "compact s"
+    and t: "closed t" "s \<inter> t = {}"
   shows "\<exists>d>0. \<forall>x\<in>s. \<forall>y\<in>t. d \<le> dist x y"
 proof cases
   assume "s \<noteq> {} \<and> t \<noteq> {}"
@@ -5279,70 +5947,104 @@
     using t `t \<noteq> {}` in_closed_iff_infdist_zero by (auto simp: less_le infdist_nonneg)
   moreover have "\<forall>x'\<in>s. \<forall>y\<in>t. ?inf x \<le> dist x' y"
     using x by (auto intro: order_trans infdist_le)
-  ultimately show ?thesis
-    by auto
+  ultimately show ?thesis by auto
 qed (auto intro!: exI[of _ 1])
 
 lemma separate_closed_compact:
   fixes s t :: "'a::heine_borel set"
-  assumes "closed s" and "compact t" and "s \<inter> t = {}"
+  assumes "closed s"
+    and "compact t"
+    and "s \<inter> t = {}"
   shows "\<exists>d>0. \<forall>x\<in>s. \<forall>y\<in>t. d \<le> dist x y"
-proof-
-  have *:"t \<inter> s = {}" using assms(3) by auto
-  show ?thesis using separate_compact_closed[OF assms(2,1) *]
-    apply auto apply(rule_tac x=d in exI) apply auto apply (erule_tac x=y in ballE)
-    by (auto simp add: dist_commute)
+proof -
+  have *: "t \<inter> s = {}"
+    using assms(3) by auto
+  show ?thesis
+    using separate_compact_closed[OF assms(2,1) *]
+    apply auto
+    apply (rule_tac x=d in exI)
+    apply auto
+    apply (erule_tac x=y in ballE)
+    apply (auto simp add: dist_commute)
+    done
 qed
 
 
 subsection {* Intervals *}
-  
-lemma interval: fixes a :: "'a::ordered_euclidean_space" shows
-  "{a <..< b} = {x::'a. \<forall>i\<in>Basis. a\<bullet>i < x\<bullet>i \<and> x\<bullet>i < b\<bullet>i}" and
-  "{a .. b} = {x::'a. \<forall>i\<in>Basis. a\<bullet>i \<le> x\<bullet>i \<and> x\<bullet>i \<le> b\<bullet>i}"
-  by(auto simp add:set_eq_iff eucl_le[where 'a='a] eucl_less[where 'a='a])
-
-lemma mem_interval: fixes a :: "'a::ordered_euclidean_space" shows
-  "x \<in> {a<..<b} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < x\<bullet>i \<and> x\<bullet>i < b\<bullet>i)"
-  "x \<in> {a .. b} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> x\<bullet>i \<and> x\<bullet>i \<le> b\<bullet>i)"
-  using interval[of a b] by(auto simp add: set_eq_iff eucl_le[where 'a='a] eucl_less[where 'a='a])
-
-lemma interval_eq_empty: fixes a :: "'a::ordered_euclidean_space" shows
- "({a <..< b} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i \<le> a\<bullet>i))" (is ?th1) and
- "({a  ..  b} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i < a\<bullet>i))" (is ?th2)
-proof-
-  { fix i x assume i:"i\<in>Basis" and as:"b\<bullet>i \<le> a\<bullet>i" and x:"x\<in>{a <..< b}"
-    hence "a \<bullet> i < x \<bullet> i \<and> x \<bullet> i < b \<bullet> i" unfolding mem_interval by auto
-    hence "a\<bullet>i < b\<bullet>i" by auto
-    hence False using as by auto  }
+
+lemma interval:
+  fixes a :: "'a::ordered_euclidean_space"
+  shows "{a <..< b} = {x::'a. \<forall>i\<in>Basis. a\<bullet>i < x\<bullet>i \<and> x\<bullet>i < b\<bullet>i}"
+    and "{a .. b} = {x::'a. \<forall>i\<in>Basis. a\<bullet>i \<le> x\<bullet>i \<and> x\<bullet>i \<le> b\<bullet>i}"
+  by (auto simp add:set_eq_iff eucl_le[where 'a='a] eucl_less[where 'a='a])
+
+lemma mem_interval:
+  fixes a :: "'a::ordered_euclidean_space"
+  shows "x \<in> {a<..<b} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < x\<bullet>i \<and> x\<bullet>i < b\<bullet>i)"
+    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)"
+  using interval[of a b]
+  by (auto simp add: set_eq_iff eucl_le[where 'a='a] eucl_less[where 'a='a])
+
+lemma interval_eq_empty:
+  fixes a :: "'a::ordered_euclidean_space"
+  shows "({a <..< b} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i \<le> a\<bullet>i))" (is ?th1)
+    and "({a  ..  b} = {} \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i < a\<bullet>i))" (is ?th2)
+proof -
+  {
+    fix i x
+    assume i: "i\<in>Basis" and as:"b\<bullet>i \<le> a\<bullet>i" and x:"x\<in>{a <..< b}"
+    then have "a \<bullet> i < x \<bullet> i \<and> x \<bullet> i < b \<bullet> i"
+      unfolding mem_interval by auto
+    then have "a\<bullet>i < b\<bullet>i" by auto
+    then have False using as by auto
+  }
   moreover
-  { assume as:"\<forall>i\<in>Basis. \<not> (b\<bullet>i \<le> a\<bullet>i)"
+  {
+    assume as: "\<forall>i\<in>Basis. \<not> (b\<bullet>i \<le> a\<bullet>i)"
     let ?x = "(1/2) *\<^sub>R (a + b)"
-    { fix i :: 'a assume i:"i\<in>Basis" 
-      have "a\<bullet>i < b\<bullet>i" using as[THEN bspec[where x=i]] i by auto
-      hence "a\<bullet>i < ((1/2) *\<^sub>R (a+b)) \<bullet> i" "((1/2) *\<^sub>R (a+b)) \<bullet> i < b\<bullet>i"
-        by (auto simp: inner_add_left) }
-    hence "{a <..< b} \<noteq> {}" using mem_interval(1)[of "?x" a b] by auto  }
+    {
+      fix i :: 'a
+      assume i: "i \<in> Basis"
+      have "a\<bullet>i < b\<bullet>i"
+        using as[THEN bspec[where x=i]] i by auto
+      then have "a\<bullet>i < ((1/2) *\<^sub>R (a+b)) \<bullet> i" "((1/2) *\<^sub>R (a+b)) \<bullet> i < b\<bullet>i"
+        by (auto simp: inner_add_left)
+    }
+    then have "{a <..< b} \<noteq> {}"
+      using mem_interval(1)[of "?x" a b] by auto
+  }
   ultimately show ?th1 by blast
 
-  { fix i x assume i:"i\<in>Basis" and as:"b\<bullet>i < a\<bullet>i" and x:"x\<in>{a .. b}"
-    hence "a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i" unfolding mem_interval by auto
-    hence "a\<bullet>i \<le> b\<bullet>i" by auto
-    hence False using as by auto  }
+  {
+    fix i x
+    assume i: "i \<in> Basis" and as:"b\<bullet>i < a\<bullet>i" and x:"x\<in>{a .. b}"
+    then have "a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i"
+      unfolding mem_interval by auto
+    then have "a\<bullet>i \<le> b\<bullet>i" by auto
+    then have False using as by auto
+  }
   moreover
-  { assume as:"\<forall>i\<in>Basis. \<not> (b\<bullet>i < a\<bullet>i)"
+  {
+    assume as:"\<forall>i\<in>Basis. \<not> (b\<bullet>i < a\<bullet>i)"
     let ?x = "(1/2) *\<^sub>R (a + b)"
-    { fix i :: 'a assume i:"i\<in>Basis"
-      have "a\<bullet>i \<le> b\<bullet>i" using as[THEN bspec[where x=i]] i by auto
-      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"
-        by (auto simp: inner_add_left) }
-    hence "{a .. b} \<noteq> {}" using mem_interval(2)[of "?x" a b] by auto  }
+    {
+      fix i :: 'a
+      assume i:"i \<in> Basis"
+      have "a\<bullet>i \<le> b\<bullet>i"
+        using as[THEN bspec[where x=i]] i by auto
+      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"
+        by (auto simp: inner_add_left)
+    }
+    then have "{a .. b} \<noteq> {}"
+      using mem_interval(2)[of "?x" a b] by auto
+  }
   ultimately show ?th2 by blast
 qed
 
-lemma interval_ne_empty: fixes a :: "'a::ordered_euclidean_space" shows
-  "{a  ..  b} \<noteq> {} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i)" and
-  "{a <..< b} \<noteq> {} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i)"
+lemma interval_ne_empty:
+  fixes a :: "'a::ordered_euclidean_space"
+  shows "{a  ..  b} \<noteq> {} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i)"
+  and "{a <..< b} \<noteq> {} \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i)"
   unfolding interval_eq_empty[of a b] by fastforce+
 
 lemma interval_sing:
@@ -5351,11 +6053,12 @@
   unfolding set_eq_iff mem_interval eq_iff [symmetric]
   by (auto intro: euclidean_eqI simp: ex_in_conv)
 
-lemma subset_interval_imp: fixes a :: "'a::ordered_euclidean_space" 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}" and
- "(\<forall>i\<in>Basis. a\<bullet>i < c\<bullet>i \<and> d\<bullet>i < b\<bullet>i) \<Longrightarrow> {c .. d} \<subseteq> {a<..<b}" 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}" 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}"
+lemma subset_interval_imp:
+  fixes a :: "'a::ordered_euclidean_space"
+  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}"
+    and "(\<forall>i\<in>Basis. a\<bullet>i < c\<bullet>i \<and> d\<bullet>i < b\<bullet>i) \<Longrightarrow> {c .. d} \<subseteq> {a<..<b}"
+    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}"
+    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}"
   unfolding subset_eq[unfolded Ball_def] unfolding mem_interval
   by (best intro: order_trans less_le_trans le_less_trans less_imp_le)+
 
@@ -5365,80 +6068,125 @@
   unfolding subset_eq [unfolded Ball_def] mem_interval
   by (fast intro: less_imp_le)
 
-lemma subset_interval: fixes a :: "'a::ordered_euclidean_space" 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) 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) 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) 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)
-proof-
-  show ?th1 unfolding subset_eq and Ball_def and mem_interval by (auto intro: order_trans)
-  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)
-  { assume as: "{c<..<d} \<subseteq> {a .. b}" "\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i"
-    hence "{c<..<d} \<noteq> {}" unfolding interval_eq_empty by auto
-    fix i :: 'a assume i:"i\<in>Basis"
+lemma subset_interval:
+  fixes a :: "'a::ordered_euclidean_space"
+  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)
+    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)
+    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)
+    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)
+proof -
+  show ?th1
+    unfolding subset_eq and Ball_def and mem_interval
+    by (auto intro: order_trans)
+  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)
+  {
+    assume as: "{c<..<d} \<subseteq> {a .. b}" "\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i"
+    then have "{c<..<d} \<noteq> {}"
+      unfolding interval_eq_empty by auto
+    fix i :: 'a
+    assume i: "i \<in> Basis"
     (** TODO combine the following two parts as done in the HOL_light version. **)
-    { 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"
+    {
+      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"
       assume as2: "a\<bullet>i > c\<bullet>i"
-      { fix j :: 'a assume j:"j\<in>Basis"
-        hence "c \<bullet> j < ?x \<bullet> j \<and> ?x \<bullet> j < d \<bullet> j"
-          apply(cases "j=i") using as(2)[THEN bspec[where x=j]] i
-          by (auto simp add: as2)  }
-      hence "?x\<in>{c<..<d}" using i unfolding mem_interval by auto
+      {
+        fix j :: 'a
+        assume j: "j \<in> Basis"
+        then have "c \<bullet> j < ?x \<bullet> j \<and> ?x \<bullet> j < d \<bullet> j"
+          apply (cases "j = i")
+          using as(2)[THEN bspec[where x=j]] i
+          apply (auto simp add: as2)
+          done
+      }
+      then have "?x\<in>{c<..<d}"
+        using i unfolding mem_interval by auto
+      moreover
+      have "?x \<notin> {a .. b}"
+        unfolding mem_interval
+        apply auto
+        apply (rule_tac x=i in bexI)
+        using as(2)[THEN bspec[where x=i]] and as2 i
+        apply auto
+        done
+      ultimately have False using as by auto
+    }
+    then have "a\<bullet>i \<le> c\<bullet>i" by (rule ccontr) auto
+    moreover
+    {
+      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"
+      assume as2: "b\<bullet>i < d\<bullet>i"
+      {
+        fix j :: 'a
+        assume "j\<in>Basis"
+        then have "d \<bullet> j > ?x \<bullet> j \<and> ?x \<bullet> j > c \<bullet> j"
+          apply (cases "j = i")
+          using as(2)[THEN bspec[where x=j]]
+          apply (auto simp add: as2)
+          done
+      }
+      then have "?x\<in>{c<..<d}"
+        unfolding mem_interval by auto
       moreover
       have "?x\<notin>{a .. b}"
-        unfolding mem_interval apply auto apply(rule_tac x=i in bexI)
-        using as(2)[THEN bspec[where x=i]] and as2 i
-        by auto
-      ultimately have False using as by auto  }
-    hence "a\<bullet>i \<le> c\<bullet>i" by(rule ccontr)auto
-    moreover
-    { 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"
-      assume as2: "b\<bullet>i < d\<bullet>i"
-      { fix j :: 'a assume "j\<in>Basis"
-        hence "d \<bullet> j > ?x \<bullet> j \<and> ?x \<bullet> j > c \<bullet> j" 
-          apply(cases "j=i") using as(2)[THEN bspec[where x=j]]
-          by (auto simp add: as2) }
-      hence "?x\<in>{c<..<d}" unfolding mem_interval by auto
-      moreover
-      have "?x\<notin>{a .. b}"
-        unfolding mem_interval apply auto apply(rule_tac x=i in bexI)
+        unfolding mem_interval
+        apply auto
+        apply (rule_tac x=i in bexI)
         using as(2)[THEN bspec[where x=i]] and as2 using i
-        by auto
-      ultimately have False using as by auto  }
-    hence "b\<bullet>i \<ge> d\<bullet>i" by(rule ccontr)auto
+        apply auto
+        done
+      ultimately have False using as by auto
+    }
+    then have "b\<bullet>i \<ge> d\<bullet>i" by (rule ccontr) auto
     ultimately
     have "a\<bullet>i \<le> c\<bullet>i \<and> d\<bullet>i \<le> b\<bullet>i" by auto
   } note part1 = this
   show ?th3
-    unfolding subset_eq and Ball_def and mem_interval 
-    apply(rule,rule,rule,rule) 
-    apply(rule part1)
+    unfolding subset_eq and Ball_def and mem_interval
+    apply (rule, rule, rule, rule)
+    apply (rule part1)
     unfolding subset_eq and Ball_def and mem_interval
     prefer 4
-    apply auto 
-    by(erule_tac x=xa in allE,erule_tac x=xa in allE,fastforce)+ 
-  { assume as:"{c<..<d} \<subseteq> {a<..<b}" "\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i"
-    fix i :: 'a assume i:"i\<in>Basis"
-    from as(1) have "{c<..<d} \<subseteq> {a..b}" using interval_open_subset_closed[of a b] by auto
-    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
-  show ?th4 unfolding subset_eq and Ball_def and mem_interval 
-    apply(rule,rule,rule,rule) apply(rule *) unfolding subset_eq and Ball_def and mem_interval prefer 4
-    apply auto by(erule_tac x=xa in allE, simp)+ 
-qed
-
-lemma inter_interval: fixes a :: "'a::ordered_euclidean_space" 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)}"
-  unfolding set_eq_iff and Int_iff and mem_interval by auto
-
-lemma disjoint_interval: fixes a::"'a::ordered_euclidean_space" 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) 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) 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) 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)
-proof-
+    apply auto
+    apply (erule_tac x=xa in allE, erule_tac x=xa in allE, fastforce)+
+    done
+  {
+    assume as: "{c<..<d} \<subseteq> {a<..<b}" "\<forall>i\<in>Basis. c\<bullet>i < d\<bullet>i"
+    fix i :: 'a
+    assume i:"i\<in>Basis"
+    from as(1) have "{c<..<d} \<subseteq> {a..b}"
+      using interval_open_subset_closed[of a b] by auto
+    then have "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
+  show ?th4
+    unfolding subset_eq and Ball_def and mem_interval
+    apply (rule, rule, rule, rule)
+    apply (rule *)
+    unfolding subset_eq and Ball_def and mem_interval
+    prefer 4
+    apply auto
+    apply (erule_tac x=xa in allE, simp)+
+    done
+qed
+
+lemma inter_interval:
+  fixes a :: "'a::ordered_euclidean_space"
+  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)}"
+  unfolding set_eq_iff and Int_iff and mem_interval
+  by auto
+
+lemma disjoint_interval:
+  fixes a::"'a::ordered_euclidean_space"
+  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)
+    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)
+    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)
+    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)
+proof -
   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"
   have **: "\<And>P Q. (\<And>i :: 'a. i \<in> Basis \<Longrightarrow> Q ?z i \<Longrightarrow> P i) \<Longrightarrow>
-      (\<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)" 
+      (\<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)"
     by blast
   note * = set_eq_iff Int_iff empty_iff mem_interval ball_conj_distrib[symmetric] eq_False ball_simps(10)
   show ?th1 unfolding * by (intro **) auto
@@ -5450,8 +6198,9 @@
 (* Moved interval_open_subset_closed a bit upwards *)
 
 lemma open_interval[intro]:
-  fixes a b :: "'a::ordered_euclidean_space" shows "open {a<..<b}"
-proof-
+  fixes a b :: "'a::ordered_euclidean_space"
+  shows "open {a<..<b}"
+proof -
   have "open (\<Inter>i\<in>Basis. (\<lambda>x. x\<bullet>i) -` {a\<bullet>i<..<b\<bullet>i})"
     by (intro open_INT finite_lessThan ballI continuous_open_vimage allI
       linear_continuous_at open_real_greaterThanLessThan finite_Basis bounded_linear_inner_left)
@@ -5461,8 +6210,9 @@
 qed
 
 lemma closed_interval[intro]:
-  fixes a b :: "'a::ordered_euclidean_space" shows "closed {a .. b}"
-proof-
+  fixes a b :: "'a::ordered_euclidean_space"
+  shows "closed {a .. b}"
+proof -
   have "closed (\<Inter>i\<in>Basis. (\<lambda>x. x\<bullet>i) -` {a\<bullet>i .. b\<bullet>i})"
     by (intro closed_INT ballI continuous_closed_vimage allI
       linear_continuous_at closed_real_atLeastAtMost finite_Basis bounded_linear_inner_left)
@@ -5477,127 +6227,237 @@
 proof(rule subset_antisym)
   show "?R \<subseteq> ?L" using interval_open_subset_closed open_interval
     by (rule interior_maximal)
-next
-  { fix x assume "x \<in> interior {a..b}"
-    then obtain s where s:"open s" "x \<in> s" "s \<subseteq> {a..b}" ..
-    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
-    { fix i :: 'a assume i:"i\<in>Basis"
+  {
+    fix x
+    assume "x \<in> interior {a..b}"
+    then obtain s where s: "open s" "x \<in> s" "s \<subseteq> {a..b}" ..
+    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
+    {
+      fix i :: 'a
+      assume i: "i \<in> Basis"
       have "dist (x - (e / 2) *\<^sub>R i) x < e"
-           "dist (x + (e / 2) *\<^sub>R i) x < e"
-        unfolding dist_norm apply auto
-        unfolding norm_minus_cancel using norm_Basis[OF i] `e>0` by auto
-      hence "a \<bullet> i \<le> (x - (e / 2) *\<^sub>R i) \<bullet> i"
-                     "(x + (e / 2) *\<^sub>R i) \<bullet> i \<le> b \<bullet> i"
+        and "dist (x + (e / 2) *\<^sub>R i) x < e"
+        unfolding dist_norm
+        apply auto
+        unfolding norm_minus_cancel
+        using norm_Basis[OF i] `e>0`
+        apply auto
+        done
+      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"
         using e[THEN spec[where x="x - (e/2) *\<^sub>R i"]]
-        and   e[THEN spec[where x="x + (e/2) *\<^sub>R i"]]
-        unfolding mem_interval using i by blast+
-      hence "a \<bullet> i < x \<bullet> i" and "x \<bullet> i < b \<bullet> i"
-        using `e>0` i by (auto simp: inner_diff_left inner_Basis inner_add_left) }
-    hence "x \<in> {a<..<b}" unfolding mem_interval by auto  }
-  thus "?L \<subseteq> ?R" ..
-qed
-
-lemma bounded_closed_interval: fixes a :: "'a::ordered_euclidean_space" shows "bounded {a .. b}"
-proof-
+          and e[THEN spec[where x="x + (e/2) *\<^sub>R i"]]
+        unfolding mem_interval
+        using i
+        by blast+
+      then have "a \<bullet> i < x \<bullet> i" and "x \<bullet> i < b \<bullet> i"
+        using `e>0` i
+        by (auto simp: inner_diff_left inner_Basis inner_add_left)
+    }
+    then have "x \<in> {a<..<b}"
+      unfolding mem_interval by auto
+  }
+  then show "?L \<subseteq> ?R" ..
+qed
+
+lemma bounded_closed_interval:
+  fixes a :: "'a::ordered_euclidean_space"
+  shows "bounded {a .. b}"
+proof -
   let ?b = "\<Sum>i\<in>Basis. \<bar>a\<bullet>i\<bar> + \<bar>b\<bullet>i\<bar>"
-  { fix x::"'a" assume x:"\<forall>i\<in>Basis. a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i"
-    { fix i :: 'a assume "i\<in>Basis"
-      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  }
-    hence "(\<Sum>i\<in>Basis. \<bar>x \<bullet> i\<bar>) \<le> ?b" apply-apply(rule setsum_mono) by auto
-    hence "norm x \<le> ?b" using norm_le_l1[of x] by auto  }
-  thus ?thesis unfolding interval and bounded_iff by auto
-qed
-
-lemma bounded_interval: fixes a :: "'a::ordered_euclidean_space" shows
- "bounded {a .. b} \<and> bounded {a<..<b}"
+  {
+    fix x :: "'a"
+    assume x: "\<forall>i\<in>Basis. a \<bullet> i \<le> x \<bullet> i \<and> x \<bullet> i \<le> b \<bullet> i"
+    {
+      fix i :: 'a
+      assume "i \<in> Basis"
+      then have "\<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
+    }
+    then have "(\<Sum>i\<in>Basis. \<bar>x \<bullet> i\<bar>) \<le> ?b"
+      apply -
+      apply (rule setsum_mono)
+      apply auto
+      done
+    then have "norm x \<le> ?b"
+      using norm_le_l1[of x] by auto
+  }
+  then show ?thesis
+    unfolding interval and bounded_iff by auto
+qed
+
+lemma bounded_interval:
+  fixes a :: "'a::ordered_euclidean_space"
+  shows "bounded {a .. b} \<and> bounded {a<..<b}"
   using bounded_closed_interval[of a b]
   using interval_open_subset_closed[of a b]
   using bounded_subset[of "{a..b}" "{a<..<b}"]
   by simp
 
-lemma not_interval_univ: fixes a :: "'a::ordered_euclidean_space" shows
- "({a .. b} \<noteq> UNIV) \<and> ({a<..<b} \<noteq> UNIV)"
+lemma not_interval_univ:
+  fixes a :: "'a::ordered_euclidean_space"
+  shows "({a .. b} \<noteq> UNIV) \<and> ({a<..<b} \<noteq> UNIV)"
   using bounded_interval[of a b] by auto
 
-lemma compact_interval: fixes a :: "'a::ordered_euclidean_space" shows "compact {a .. b}"
+lemma compact_interval:
+  fixes a :: "'a::ordered_euclidean_space"
+  shows "compact {a .. b}"
   using bounded_closed_imp_seq_compact[of "{a..b}"] using bounded_interval[of a b]
   by (auto simp: compact_eq_seq_compact_metric)
 
-lemma open_interval_midpoint: fixes a :: "'a::ordered_euclidean_space"
-  assumes "{a<..<b} \<noteq> {}" shows "((1/2) *\<^sub>R (a + b)) \<in> {a<..<b}"
-proof-
-  { fix i :: 'a assume "i\<in>Basis"
-    hence "a \<bullet> i < ((1 / 2) *\<^sub>R (a + b)) \<bullet> i \<and> ((1 / 2) *\<^sub>R (a + b)) \<bullet> i < b \<bullet> i"
-      using assms[unfolded interval_ne_empty, THEN bspec[where x=i]] by (auto simp: inner_add_left)  }
-  thus ?thesis unfolding mem_interval by auto
-qed
-
-lemma open_closed_interval_convex: fixes x :: "'a::ordered_euclidean_space"
-  assumes x:"x \<in> {a<..<b}" and y:"y \<in> {a .. b}" and e:"0 < e" "e \<le> 1"
+lemma open_interval_midpoint:
+  fixes a :: "'a::ordered_euclidean_space"
+  assumes "{a<..<b} \<noteq> {}"
+  shows "((1/2) *\<^sub>R (a + b)) \<in> {a<..<b}"
+proof -
+  {
+    fix i :: 'a
+    assume "i \<in> Basis"
+    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"
+      using assms[unfolded interval_ne_empty, THEN bspec[where x=i]] by (auto simp: inner_add_left)
+  }
+  then show ?thesis unfolding mem_interval by auto
+qed
+
+lemma open_closed_interval_convex:
+  fixes x :: "'a::ordered_euclidean_space"
+  assumes x: "x \<in> {a<..<b}"
+    and y: "y \<in> {a .. b}"
+    and e: "0 < e" "e \<le> 1"
   shows "(e *\<^sub>R x + (1 - e) *\<^sub>R y) \<in> {a<..<b}"
-proof-
-  { fix i :: 'a assume i:"i\<in>Basis"
-    have "a \<bullet> i = e * (a \<bullet> i) + (1 - e) * (a \<bullet> i)" unfolding left_diff_distrib by simp
-    also have "\<dots> < e * (x \<bullet> i) + (1 - e) * (y \<bullet> i)" apply(rule add_less_le_mono)
-      using e unfolding mult_less_cancel_left and mult_le_cancel_left apply simp_all
-      using x unfolding mem_interval using i apply simp
-      using y unfolding mem_interval using i apply simp
+proof -
+  {
+    fix i :: 'a
+    assume i: "i \<in> Basis"
+    have "a \<bullet> i = e * (a \<bullet> i) + (1 - e) * (a \<bullet> i)"
+      unfolding left_diff_distrib by simp
+    also have "\<dots> < e * (x \<bullet> i) + (1 - e) * (y \<bullet> i)"
+      apply (rule add_less_le_mono)
+      using e unfolding mult_less_cancel_left and mult_le_cancel_left
+      apply simp_all
+      using x unfolding mem_interval using i
+      apply simp
+      using y unfolding mem_interval using i
+      apply simp
       done
-    finally have "a \<bullet> i < (e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i" unfolding inner_simps by auto
-    moreover {
-    have "b \<bullet> i = e * (b\<bullet>i) + (1 - e) * (b\<bullet>i)" unfolding left_diff_distrib by simp
-    also have "\<dots> > e * (x \<bullet> i) + (1 - e) * (y \<bullet> i)" apply(rule add_less_le_mono)
-      using e unfolding mult_less_cancel_left and mult_le_cancel_left apply simp_all
-      using x unfolding mem_interval using i apply simp
-      using y unfolding mem_interval using i apply simp
-      done
-    finally have "(e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i < b \<bullet> i" unfolding inner_simps by auto
-    } 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 }
-  thus ?thesis unfolding mem_interval by auto
-qed
-
-lemma closure_open_interval: fixes a :: "'a::ordered_euclidean_space"
+    finally have "a \<bullet> i < (e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i"
+      unfolding inner_simps by auto
+    moreover
+    {
+      have "b \<bullet> i = e * (b\<bullet>i) + (1 - e) * (b\<bullet>i)"
+        unfolding left_diff_distrib by simp
+      also have "\<dots> > e * (x \<bullet> i) + (1 - e) * (y \<bullet> i)"
+        apply (rule add_less_le_mono)
+        using e unfolding mult_less_cancel_left and mult_le_cancel_left
+        apply simp_all
+        using x
+        unfolding mem_interval
+        using i
+        apply simp
+        using y
+        unfolding mem_interval
+        using i
+        apply simp
+        done
+      finally have "(e *\<^sub>R x + (1 - e) *\<^sub>R y) \<bullet> i < b \<bullet> i"
+        unfolding inner_simps by auto
+    }
+    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
+  }
+  then show ?thesis
+    unfolding mem_interval by auto
+qed
+
+lemma closure_open_interval:
+  fixes a :: "'a::ordered_euclidean_space"
   assumes "{a<..<b} \<noteq> {}"
   shows "closure {a<..<b} = {a .. b}"
-proof-
-  have ab:"a < b" using assms[unfolded interval_ne_empty] apply(subst eucl_less) by auto
+proof -
+  have ab: "a < b"
+    using assms[unfolded interval_ne_empty]
+    apply (subst eucl_less)
+    apply auto
+    done
   let ?c = "(1 / 2) *\<^sub>R (a + b)"
-  { fix x assume as:"x \<in> {a .. b}"
-    def f == "\<lambda>n::nat. x + (inverse (real n + 1)) *\<^sub>R (?c - x)"
-    { fix n assume fn:"f n < b \<longrightarrow> a < f n \<longrightarrow> f n = x" and xc:"x \<noteq> ?c"
-      have *:"0 < inverse (real n + 1)" "inverse (real n + 1) \<le> 1" unfolding inverse_le_1_iff by auto
+  {
+    fix x
+    assume as:"x \<in> {a .. b}"
+    def f \<equiv> "\<lambda>n::nat. x + (inverse (real n + 1)) *\<^sub>R (?c - x)"
+    {
+      fix n
+      assume fn: "f n < b \<longrightarrow> a < f n \<longrightarrow> f n = x" and xc: "x \<noteq> ?c"
+      have *: "0 < inverse (real n + 1)" "inverse (real n + 1) \<le> 1"
+        unfolding inverse_le_1_iff by auto
       have "(inverse (real n + 1)) *\<^sub>R ((1 / 2) *\<^sub>R (a + b)) + (1 - inverse (real n + 1)) *\<^sub>R x =
         x + (inverse (real n + 1)) *\<^sub>R (((1 / 2) *\<^sub>R (a + b)) - x)"
         by (auto simp add: algebra_simps)
-      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
-      hence False using fn unfolding f_def using xc by auto  }
+      then have "f n < b" and "a < f n"
+        using open_closed_interval_convex[OF open_interval_midpoint[OF assms] as *]
+        unfolding f_def by auto
+      then have False
+        using fn unfolding f_def using xc by auto
+    }
     moreover
-    { assume "\<not> (f ---> x) sequentially"
-      { fix e::real assume "e>0"
-        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
-        then obtain N::nat where "inverse (real (N + 1)) < e" by auto
-        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)
-        hence "\<exists>N::nat. \<forall>n\<ge>N. inverse (real n + 1) < e" by auto  }
-      hence "((\<lambda>n. inverse (real n + 1)) ---> 0) sequentially"
+    {
+      assume "\<not> (f ---> x) sequentially"
+      {
+        fix e :: real
+        assume "e > 0"
+        then have "\<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)
+          apply auto
+          done
+        then obtain N :: nat where "inverse (real (N + 1)) < e"
+          by auto
+        then have "\<forall>n\<ge>N. inverse (real n + 1) < e"
+          apply auto
+          apply (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)
+          done
+        then have "\<exists>N::nat. \<forall>n\<ge>N. inverse (real n + 1) < e" by auto
+      }
+      then have "((\<lambda>n. inverse (real n + 1)) ---> 0) sequentially"
         unfolding LIMSEQ_def by(auto simp add: dist_norm)
-      hence "(f ---> x) sequentially" unfolding f_def
+      then have "(f ---> x) sequentially"
+        unfolding f_def
         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]
-        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  }
+        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
+    }
     ultimately have "x \<in> closure {a<..<b}"
-      using as and open_interval_midpoint[OF assms] unfolding closure_def unfolding islimpt_sequential by(cases "x=?c")auto  }
-  thus ?thesis using closure_minimal[OF interval_open_subset_closed closed_interval, of a b] by blast
-qed
-
-lemma bounded_subset_open_interval_symmetric: fixes s::"('a::ordered_euclidean_space) set"
-  assumes "bounded s"  shows "\<exists>a. s \<subseteq> {-a<..<a}"
-proof-
-  obtain b where "b>0" and b:"\<forall>x\<in>s. norm x \<le> b" using assms[unfolded bounded_pos] by auto
+      using as and open_interval_midpoint[OF assms]
+      unfolding closure_def
+      unfolding islimpt_sequential
+      by (cases "x=?c") auto
+  }
+  then show ?thesis
+    using closure_minimal[OF interval_open_subset_closed closed_interval, of a b] by blast
+qed
+
+lemma bounded_subset_open_interval_symmetric:
+  fixes s::"('a::ordered_euclidean_space) set"
+  assumes "bounded s"
+  shows "\<exists>a. s \<subseteq> {-a<..<a}"
+proof -
+  obtain b where "b>0" and b: "\<forall>x\<in>s. norm x \<le> b"
+    using assms[unfolded bounded_pos] by auto
   def a \<equiv> "(\<Sum>i\<in>Basis. (b + 1) *\<^sub>R i)::'a"
-  { fix x assume "x\<in>s"
-    fix i :: 'a assume i:"i\<in>Basis"
-    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`]
-      and Basis_le_norm[OF i, of x] unfolding inner_simps and a_def by auto }
-  thus ?thesis by(auto intro: exI[where x=a] simp add: eucl_less[where 'a='a])
+  {
+    fix x
+    assume "x \<in> s"
+    fix i :: 'a
+    assume i: "i \<in> Basis"
+    then have "(-a)\<bullet>i < x\<bullet>i" and "x\<bullet>i < a\<bullet>i"
+      using b[THEN bspec[where x=x], OF `x\<in>s`]
+      using Basis_le_norm[OF i, of x]
+      unfolding inner_simps and a_def
+      by auto
+  }
+  then show ?thesis
+    by (auto intro: exI[where x=a] simp add: eucl_less[where 'a='a])
 qed
 
 lemma bounded_subset_open_interval:
@@ -5608,14 +6468,16 @@
 lemma bounded_subset_closed_interval_symmetric:
   fixes s :: "('a::ordered_euclidean_space) set"
   assumes "bounded s" shows "\<exists>a. s \<subseteq> {-a .. a}"
-proof-
-  obtain a where "s \<subseteq> {- a<..<a}" using bounded_subset_open_interval_symmetric[OF assms] by auto
-  thus ?thesis using interval_open_subset_closed[of "-a" a] by auto
+proof -
+  obtain a where "s \<subseteq> {- a<..<a}"
+    using bounded_subset_open_interval_symmetric[OF assms] by auto
+  then show ?thesis
+    using interval_open_subset_closed[of "-a" a] by auto
 qed
 
 lemma bounded_subset_closed_interval:
   fixes s :: "('a::ordered_euclidean_space) set"
-  shows "bounded s ==> (\<exists>a b. s \<subseteq> {a .. b})"
+  shows "bounded s \<Longrightarrow> (\<exists>a b. s \<subseteq> {a .. b})"
   using bounded_subset_closed_interval_symmetric[of s] by auto
 
 lemma frontier_closed_interval:
@@ -5626,44 +6488,74 @@
 lemma frontier_open_interval:
   fixes a b :: "'a::ordered_euclidean_space"
   shows "frontier {a<..<b} = (if {a<..<b} = {} then {} else {a .. b} - {a<..<b})"
-proof(cases "{a<..<b} = {}")
-  case True thus ?thesis using frontier_empty by auto
+proof (cases "{a<..<b} = {}")
+  case True
+  then show ?thesis
+    using frontier_empty by auto
 next
-  case False thus ?thesis unfolding frontier_def and closure_open_interval[OF False] and interior_open[OF open_interval] by auto
-qed
-
-lemma inter_interval_mixed_eq_empty: fixes a :: "'a::ordered_euclidean_space"
-  assumes "{c<..<d} \<noteq> {}"  shows "{a<..<b} \<inter> {c .. d} = {} \<longleftrightarrow> {a<..<b} \<inter> {c<..<d} = {}"
-  unfolding closure_open_interval[OF assms, THEN sym] unfolding open_inter_closure_eq_empty[OF open_interval] ..
+  case False
+  then show ?thesis
+    unfolding frontier_def and closure_open_interval[OF False] and interior_open[OF open_interval]
+    by auto
+qed
+
+lemma inter_interval_mixed_eq_empty:
+  fixes a :: "'a::ordered_euclidean_space"
+  assumes "{c<..<d} \<noteq> {}"
+  shows "{a<..<b} \<inter> {c .. d} = {} \<longleftrightarrow> {a<..<b} \<inter> {c<..<d} = {}"
+  unfolding closure_open_interval[OF assms, THEN sym]
+  unfolding open_inter_closure_eq_empty[OF open_interval] ..
 
 
 (* Some stuff for half-infinite intervals too; FIXME: notation?  *)
 
-lemma closed_interval_left: fixes b::"'a::euclidean_space"
+lemma closed_interval_left:
+  fixes b :: "'a::euclidean_space"
   shows "closed {x::'a. \<forall>i\<in>Basis. x\<bullet>i \<le> b\<bullet>i}"
-proof-
-  { fix i :: 'a assume i:"i\<in>Basis"
-    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"
-    { assume "x\<bullet>i > b\<bullet>i"
+proof -
+  {
+    fix i :: 'a
+    assume i: "i \<in> Basis"
+    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"
+    {
+      assume "x\<bullet>i > b\<bullet>i"
       then obtain y where "y \<bullet> i \<le> b \<bullet> i"  "y \<noteq> x"  "dist y x < x\<bullet>i - b\<bullet>i"
         using x[THEN spec[where x="x\<bullet>i - b\<bullet>i"]] using i by auto
-      hence False using Basis_le_norm[OF i, of "y - x"] unfolding dist_norm inner_simps using i 
-        by auto }
-    hence "x\<bullet>i \<le> b\<bullet>i" by(rule ccontr)auto  }
-  thus ?thesis unfolding closed_limpt unfolding islimpt_approachable by blast
-qed
-
-lemma closed_interval_right: fixes a::"'a::euclidean_space"
+      then have False
+        using Basis_le_norm[OF i, of "y - x"]
+        unfolding dist_norm inner_simps
+        using i
+        by auto
+    }
+    then have "x\<bullet>i \<le> b\<bullet>i" by (rule ccontr)auto
+  }
+  then show ?thesis
+    unfolding closed_limpt unfolding islimpt_approachable by blast
+qed
+
+lemma closed_interval_right:
+  fixes a :: "'a::euclidean_space"
   shows "closed {x::'a. \<forall>i\<in>Basis. a\<bullet>i \<le> x\<bullet>i}"
-proof-
-  { fix i :: 'a assume i:"i\<in>Basis"
-    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"
-    { assume "a\<bullet>i > x\<bullet>i"
+proof -
+  {
+    fix i :: 'a
+    assume i: "i \<in> Basis"
+    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"
+    {
+      assume "a\<bullet>i > x\<bullet>i"
       then obtain y where "a \<bullet> i \<le> y \<bullet> i"  "y \<noteq> x"  "dist y x < a\<bullet>i - x\<bullet>i"
         using x[THEN spec[where x="a\<bullet>i - x\<bullet>i"]] i by auto
-      hence False using Basis_le_norm[OF i, of "y - x"] unfolding dist_norm inner_simps by auto }
-    hence "a\<bullet>i \<le> x\<bullet>i" by(rule ccontr)auto  }
-  thus ?thesis unfolding closed_limpt unfolding islimpt_approachable by blast
+      then have False
+        using Basis_le_norm[OF i, of "y - x"]
+        unfolding dist_norm inner_simps
+        by auto
+    }
+    then have "a\<bullet>i \<le> x\<bullet>i" by (rule ccontr) auto
+  }
+  then show ?thesis
+    unfolding closed_limpt unfolding islimpt_approachable by blast
 qed
 
 lemma open_box: "open (box a b)"
@@ -5678,15 +6570,18 @@
 instance euclidean_space \<subseteq> second_countable_topology
 proof
   def a \<equiv> "\<lambda>f :: 'a \<Rightarrow> (real \<times> real). \<Sum>i\<in>Basis. fst (f i) *\<^sub>R i"
-  then have a: "\<And>f. (\<Sum>i\<in>Basis. fst (f i) *\<^sub>R i) = a f" by simp
+  then have a: "\<And>f. (\<Sum>i\<in>Basis. fst (f i) *\<^sub>R i) = a f"
+    by simp
   def b \<equiv> "\<lambda>f :: 'a \<Rightarrow> (real \<times> real). \<Sum>i\<in>Basis. snd (f i) *\<^sub>R i"
-  then have b: "\<And>f. (\<Sum>i\<in>Basis. snd (f i) *\<^sub>R i) = b f" by simp
+  then have b: "\<And>f. (\<Sum>i\<in>Basis. snd (f i) *\<^sub>R i) = b f"
+    by simp
   def B \<equiv> "(\<lambda>f. box (a f) (b f)) ` (Basis \<rightarrow>\<^sub>E (\<rat> \<times> \<rat>))"
 
   have "Ball B open" by (simp add: B_def open_box)
   moreover have "(\<forall>A. open A \<longrightarrow> (\<exists>B'\<subseteq>B. \<Union>B' = A))"
   proof safe
-    fix A::"'a set" assume "open A"
+    fix A::"'a set"
+    assume "open A"
     show "\<exists>B'\<subseteq>B. \<Union>B' = A"
       apply (rule exI[of _ "{b\<in>B. b \<subseteq> A}"])
       apply (subst (3) open_UNION_box[OF `open A`])
@@ -5694,9 +6589,11 @@
       done
   qed
   ultimately
-  have "topological_basis B" unfolding topological_basis_def by blast
+  have "topological_basis B"
+    unfolding topological_basis_def by blast
   moreover
-  have "countable B" unfolding B_def 
+  have "countable B"
+    unfolding B_def
     by (intro countable_image countable_PiE finite_Basis countable_SIGMA countable_rat)
   ultimately show "\<exists>B::'a set set. countable B \<and> open = generate_topology B"
     by (blast intro: topological_basis_imp_subbasis)
@@ -5728,25 +6625,29 @@
 subsection {* Closure of halfspaces and hyperplanes *}
 
 lemma isCont_open_vimage:
-  assumes "\<And>x. isCont f x" and "open s" shows "open (f -` s)"
+  assumes "\<And>x. isCont f x"
+    and "open s"
+  shows "open (f -` s)"
 proof -
   from assms(1) have "continuous_on UNIV f"
     unfolding isCont_def continuous_on_def by simp
-  hence "open {x \<in> UNIV. f x \<in> s}"
+  then have "open {x \<in> UNIV. f x \<in> s}"
     using open_UNIV `open s` by (rule continuous_open_preimage)
-  thus "open (f -` s)"
+  then show "open (f -` s)"
     by (simp add: vimage_def)
 qed
 
 lemma isCont_closed_vimage:
-  assumes "\<And>x. isCont f x" and "closed s" shows "closed (f -` s)"
+  assumes "\<And>x. isCont f x"
+    and "closed s"
+  shows "closed (f -` s)"
   using assms unfolding closed_def vimage_Compl [symmetric]
   by (rule isCont_open_vimage)
 
 lemma open_Collect_less:
   fixes f g :: "'a::t2_space \<Rightarrow> real"
   assumes f: "\<And>x. isCont f x"
-  assumes g: "\<And>x. isCont g x"
+    and g: "\<And>x. isCont g x"
   shows "open {x. f x < g x}"
 proof -
   have "open ((\<lambda>x. g x - f x) -` {0<..})"
@@ -5760,7 +6661,7 @@
 lemma closed_Collect_le:
   fixes f g :: "'a::t2_space \<Rightarrow> real"
   assumes f: "\<And>x. isCont f x"
-  assumes g: "\<And>x. isCont g x"
+    and g: "\<And>x. isCont g x"
   shows "closed {x. f x \<le> g x}"
 proof -
   have "closed ((\<lambda>x. g x - f x) -` {0..})"
@@ -5774,12 +6675,12 @@
 lemma closed_Collect_eq:
   fixes f g :: "'a::t2_space \<Rightarrow> 'b::t2_space"
   assumes f: "\<And>x. isCont f x"
-  assumes g: "\<And>x. isCont g x"
+    and g: "\<And>x. isCont g x"
   shows "closed {x. f x = g x}"
 proof -
   have "open {(x::'b, y::'b). x \<noteq> y}"
     unfolding open_prod_def by (auto dest!: hausdorff)
-  hence "closed {(x::'b, y::'b). x = y}"
+  then have "closed {(x::'b, y::'b). x = y}"
     unfolding closed_def split_def Collect_neg_eq .
   with isCont_Pair [OF f g]
   have "closed ((\<lambda>x. (f x, g x)) -` {(x, y). x = y})"
@@ -5800,12 +6701,10 @@
 lemma closed_hyperplane: "closed {x. inner a x = b}"
   by (simp add: closed_Collect_eq)
 
-lemma closed_halfspace_component_le:
-  shows "closed {x::'a::euclidean_space. x\<bullet>i \<le> a}"
+lemma closed_halfspace_component_le: "closed {x::'a::euclidean_space. x\<bullet>i \<le> a}"
   by (simp add: closed_Collect_le)
 
-lemma closed_halfspace_component_ge:
-  shows "closed {x::'a::euclidean_space. x\<bullet>i \<ge> a}"
+lemma closed_halfspace_component_ge: "closed {x::'a::euclidean_space. x\<bullet>i \<ge> a}"
   by (simp add: closed_Collect_le)
 
 text {* Openness of halfspaces. *}
@@ -5816,12 +6715,10 @@
 lemma open_halfspace_gt: "open {x. inner a x > b}"
   by (simp add: open_Collect_less)
 
-lemma open_halfspace_component_lt:
-  shows "open {x::'a::euclidean_space. x\<bullet>i < a}"
+lemma open_halfspace_component_lt: "open {x::'a::euclidean_space. x\<bullet>i < a}"
   by (simp add: open_Collect_less)
 
-lemma open_halfspace_component_gt:
-  shows "open {x::'a::euclidean_space. x\<bullet>i > a}"
+lemma open_halfspace_component_gt: "open {x::'a::euclidean_space. x\<bullet>i > a}"
   by (simp add: open_Collect_less)
 
 text{* Instantiation for intervals on @{text ordered_euclidean_space} *}
@@ -5829,22 +6726,22 @@
 lemma eucl_lessThan_eq_halfspaces:
   fixes a :: "'a\<Colon>ordered_euclidean_space"
   shows "{..<a} = (\<Inter>i\<in>Basis. {x. x \<bullet> i < a \<bullet> i})"
- by (auto simp: eucl_less[where 'a='a])
+  by (auto simp: eucl_less[where 'a='a])
 
 lemma eucl_greaterThan_eq_halfspaces:
   fixes a :: "'a\<Colon>ordered_euclidean_space"
   shows "{a<..} = (\<Inter>i\<in>Basis. {x. a \<bullet> i < x \<bullet> i})"
- by (auto simp: eucl_less[where 'a='a])
+  by (auto simp: eucl_less[where 'a='a])
 
 lemma eucl_atMost_eq_halfspaces:
   fixes a :: "'a\<Colon>ordered_euclidean_space"
   shows "{.. a} = (\<Inter>i\<in>Basis. {x. x \<bullet> i \<le> a \<bullet> i})"
- by (auto simp: eucl_le[where 'a='a])
+  by (auto simp: eucl_le[where 'a='a])
 
 lemma eucl_atLeast_eq_halfspaces:
   fixes a :: "'a\<Colon>ordered_euclidean_space"
   shows "{a ..} = (\<Inter>i\<in>Basis. {x. a \<bullet> i \<le> x \<bullet> i})"
- by (auto simp: eucl_le[where 'a='a])
+  by (auto simp: eucl_le[where 'a='a])
 
 lemma open_eucl_lessThan[simp, intro]:
   fixes a :: "'a\<Colon>ordered_euclidean_space"
@@ -5870,26 +6767,37 @@
 
 text {* This gives a simple derivation of limit component bounds. *}
 
-lemma Lim_component_le: fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
-  assumes "(f ---> l) net" "\<not> (trivial_limit net)"  "eventually (\<lambda>x. f(x)\<bullet>i \<le> b) net"
+lemma Lim_component_le:
+  fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
+  assumes "(f ---> l) net"
+    and "\<not> (trivial_limit net)"
+    and "eventually (\<lambda>x. f(x)\<bullet>i \<le> b) net"
   shows "l\<bullet>i \<le> b"
   by (rule tendsto_le[OF assms(2) tendsto_const tendsto_inner[OF assms(1) tendsto_const] assms(3)])
 
-lemma Lim_component_ge: fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
-  assumes "(f ---> l) net"  "\<not> (trivial_limit net)"  "eventually (\<lambda>x. b \<le> (f x)\<bullet>i) net"
+lemma Lim_component_ge:
+  fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
+  assumes "(f ---> l) net"
+    and "\<not> (trivial_limit net)"
+    and "eventually (\<lambda>x. b \<le> (f x)\<bullet>i) net"
   shows "b \<le> l\<bullet>i"
   by (rule tendsto_le[OF assms(2) tendsto_inner[OF assms(1) tendsto_const] tendsto_const assms(3)])
 
-lemma Lim_component_eq: fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
-  assumes net:"(f ---> l) net" "~(trivial_limit net)" and ev:"eventually (\<lambda>x. f(x)\<bullet>i = b) net"
+lemma Lim_component_eq:
+  fixes f :: "'a \<Rightarrow> 'b::euclidean_space"
+  assumes net: "(f ---> l) net" "~(trivial_limit net)"
+    and ev:"eventually (\<lambda>x. f(x)\<bullet>i = b) net"
   shows "l\<bullet>i = b"
   using ev[unfolded order_eq_iff eventually_conj_iff]
-  using Lim_component_ge[OF net, of b i] and Lim_component_le[OF net, of i b] by auto
-
-text{* Limits relative to a union.                                               *}
+  using Lim_component_ge[OF net, of b i]
+  using Lim_component_le[OF net, of i b]
+  by auto
+
+text {* Limits relative to a union. *}
 
 lemma eventually_within_Un:
-  "eventually P (at x within (s \<union> t)) \<longleftrightarrow> eventually P (at x within s) \<and> eventually P (at x within t)"
+  "eventually P (at x within (s \<union> t)) \<longleftrightarrow>
+    eventually P (at x within s) \<and> eventually P (at x within t)"
   unfolding eventually_at_filter
   by (auto elim!: eventually_rev_mp)
 
@@ -5900,25 +6808,27 @@
   by (auto simp add: eventually_within_Un)
 
 lemma Lim_topological:
- "(f ---> l) net \<longleftrightarrow>
-        trivial_limit net \<or>
-        (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) net)"
+  "(f ---> l) net \<longleftrightarrow>
+    trivial_limit net \<or> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) net)"
   unfolding tendsto_def trivial_limit_eq by auto
 
-text{* Some more convenient intermediate-value theorem formulations.             *}
+text{* Some more convenient intermediate-value theorem formulations. *}
 
 lemma connected_ivt_hyperplane:
   assumes "connected s" "x \<in> s" "y \<in> s" "inner a x \<le> b" "b \<le> inner a y"
   shows "\<exists>z \<in> s. inner a z = b"
-proof(rule ccontr)
+proof (rule ccontr)
   assume as:"\<not> (\<exists>z\<in>s. inner a z = b)"
   let ?A = "{x. inner a x < b}"
   let ?B = "{x. inner a x > b}"
-  have "open ?A" "open ?B" using open_halfspace_lt and open_halfspace_gt by auto
+  have "open ?A" "open ?B"
+    using open_halfspace_lt and open_halfspace_gt by auto
   moreover have "?A \<inter> ?B = {}" by auto
   moreover have "s \<subseteq> ?A \<union> ?B" using as by auto
   ultimately show False
-    using assms(1)[unfolded connected_def not_ex, THEN spec[where x="?A"], THEN spec[where x="?B"]] and assms(2-5)
+    using assms(1)[unfolded connected_def not_ex,
+      THEN spec[where x="?A"], THEN spec[where x="?B"]]
+    using assms(2-5)
     by auto
 qed
 
@@ -5939,38 +6849,38 @@
 
 definition
   homeomorphic :: "'a::topological_space set \<Rightarrow> 'b::topological_space set \<Rightarrow> bool"
-    (infixr "homeomorphic" 60) where
-  "s homeomorphic t \<equiv> (\<exists>f g. homeomorphism s t f g)"
+    (infixr "homeomorphic" 60)
+  where "s homeomorphic t \<equiv> (\<exists>f g. homeomorphism s t f g)"
 
 lemma homeomorphic_refl: "s homeomorphic s"
   unfolding homeomorphic_def
   unfolding homeomorphism_def
   using continuous_on_id
-  apply(rule_tac x = "(\<lambda>x. x)" in exI)
-  apply(rule_tac x = "(\<lambda>x. x)" in exI)
+  apply (rule_tac x = "(\<lambda>x. x)" in exI)
+  apply (rule_tac x = "(\<lambda>x. x)" in exI)
   apply blast
   done
 
 lemma homeomorphic_sym: "s homeomorphic t \<longleftrightarrow> t homeomorphic s"
   unfolding homeomorphic_def
   unfolding homeomorphism_def
-  by blast 
+  by blast
 
 lemma homeomorphic_trans:
-  assumes "s homeomorphic t" "t homeomorphic u"
+  assumes "s homeomorphic t"
+    and "t homeomorphic u"
   shows "s homeomorphic u"
-proof-
-  obtain f1 g1 where fg1:"\<forall>x\<in>s. g1 (f1 x) = x"  "f1 ` s = t"
-      "continuous_on s f1" "\<forall>y\<in>t. f1 (g1 y) = y" "g1 ` t = s" "continuous_on t g1"
+proof -
+  obtain f1 g1 where fg1: "\<forall>x\<in>s. g1 (f1 x) = x"  "f1 ` s = t"
+    "continuous_on s f1" "\<forall>y\<in>t. f1 (g1 y) = y" "g1 ` t = s" "continuous_on t g1"
     using assms(1) unfolding homeomorphic_def homeomorphism_def by auto
-  obtain f2 g2 where fg2:"\<forall>x\<in>t. g2 (f2 x) = x"  "f2 ` t = u" "continuous_on t f2"
-      "\<forall>y\<in>u. f2 (g2 y) = y" "g2 ` u = t" "continuous_on u g2"
+  obtain f2 g2 where fg2: "\<forall>x\<in>t. g2 (f2 x) = x"  "f2 ` t = u" "continuous_on t f2"
+    "\<forall>y\<in>u. f2 (g2 y) = y" "g2 ` u = t" "continuous_on u g2"
     using assms(2) unfolding homeomorphic_def homeomorphism_def by auto
-
   {
     fix x
     assume "x\<in>s"
-    hence "(g1 \<circ> g2) ((f2 \<circ> f1) x) = x"
+    then have "(g1 \<circ> g2) ((f2 \<circ> f1) x) = x"
       using fg1(1)[THEN bspec[where x=x]] and fg2(1)[THEN bspec[where x="f1 x"]] and fg1(2)
       by auto
   }
@@ -5978,10 +6888,11 @@
     using fg1(2) fg2(2) by auto
   moreover have "continuous_on s (f2 \<circ> f1)"
     using continuous_on_compose[OF fg1(3)] and fg2(3) unfolding fg1(2) by auto
-  moreover {
+  moreover
+  {
     fix y
     assume "y\<in>u"
-    hence "(f2 \<circ> f1) ((g1 \<circ> g2) y) = y"
+    then have "(f2 \<circ> f1) ((g1 \<circ> g2) y) = y"
       using fg2(4)[THEN bspec[where x=y]] and fg1(4)[THEN bspec[where x="g2 y"]] and fg2(5)
       by auto
   }
@@ -6030,17 +6941,19 @@
   fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
   assumes "compact s" "continuous_on s f"  "f ` s = t"  "inj_on f s"
   shows "\<exists>g. homeomorphism s t f g"
-proof-
+proof -
   def g \<equiv> "\<lambda>x. SOME y. y\<in>s \<and> f y = x"
   have g: "\<forall>x\<in>s. g (f x) = x"
     using assms(3) assms(4)[unfolded inj_on_def] unfolding g_def by auto
   {
-    fix y assume "y\<in>t"
-    then obtain x where x:"f x = y" "x\<in>s" using assms(3) by auto
-    hence "g (f x) = x" using g by auto
-    hence "f (g y) = y" unfolding x(1)[THEN sym] by auto
+    fix y
+    assume "y \<in> t"
+    then obtain x where x:"f x = y" "x\<in>s"
+      using assms(3) by auto
+    then have "g (f x) = x" using g by auto
+    then have "f (g y) = y" unfolding x(1)[THEN sym] by auto
   }
-  hence g':"\<forall>x\<in>t. f (g x) = x" by auto
+  then have g':"\<forall>x\<in>t. f (g x) = x" by auto
   moreover
   {
     fix x
@@ -6055,7 +6968,7 @@
       then obtain y where y:"y\<in>t" "g y = x" by auto
       then obtain x' where x':"x'\<in>s" "f x' = y"
         using assms(3) by auto
-      hence "x \<in> s"
+      then have "x \<in> s"
         unfolding g_def
         using someI2[of "\<lambda>b. b\<in>s \<and> f b = y" x' "\<lambda>x. x\<in>s"]
         unfolding y(2)[THEN sym] and g_def
@@ -6063,7 +6976,7 @@
     }
     ultimately have "x\<in>s \<longleftrightarrow> x \<in> g ` t" ..
   }
-  hence "g ` t = s" by auto
+  then have "g ` t = s" by auto
   ultimately show ?thesis
     unfolding homeomorphism_def homeomorphic_def
     apply (rule_tac x=g in exI)
@@ -6074,21 +6987,21 @@
 
 lemma homeomorphic_compact:
   fixes f :: "'a::topological_space \<Rightarrow> 'b::t2_space"
-  shows "compact s \<Longrightarrow> continuous_on s f \<Longrightarrow> (f ` s = t) \<Longrightarrow> inj_on f s
-          \<Longrightarrow> s homeomorphic t"
+  shows "compact s \<Longrightarrow> continuous_on s f \<Longrightarrow> (f ` s = t) \<Longrightarrow> inj_on f s \<Longrightarrow> s homeomorphic t"
   unfolding homeomorphic_def by (metis homeomorphism_compact)
 
-text{* Preservation of topological properties.                                   *}
+text{* Preservation of topological properties. *}
 
 lemma homeomorphic_compactness: "s homeomorphic t \<Longrightarrow> (compact s \<longleftrightarrow> compact t)"
   unfolding homeomorphic_def homeomorphism_def
   by (metis compact_continuous_image)
 
-text{* Results on translation, scaling etc.                                      *}
+text{* Results on translation, scaling etc. *}
 
 lemma homeomorphic_scaling:
   fixes s :: "'a::real_normed_vector set"
-  assumes "c \<noteq> 0"  shows "s homeomorphic ((\<lambda>x. c *\<^sub>R x) ` s)"
+  assumes "c \<noteq> 0"
+  shows "s homeomorphic ((\<lambda>x. c *\<^sub>R x) ` s)"
   unfolding homeomorphic_minimal
   apply (rule_tac x="\<lambda>x. c *\<^sub>R x" in exI)
   apply (rule_tac x="\<lambda>x. (1 / c) *\<^sub>R x" in exI)
@@ -6110,7 +7023,7 @@
   fixes s :: "'a::real_normed_vector set"
   assumes "c \<noteq> 0"
   shows "s homeomorphic ((\<lambda>x. a + c *\<^sub>R x) ` s)"
-proof-
+proof -
   have *: "op + a ` op *\<^sub>R c ` s = (\<lambda>x. a + c *\<^sub>R x) ` s" by auto
   show ?thesis
     using homeomorphic_trans
@@ -6124,8 +7037,8 @@
   fixes a b ::"'a::real_normed_vector"
   assumes "0 < d"  "0 < e"
   shows "(ball a d) homeomorphic  (ball b e)" (is ?th)
-        "(cball a d) homeomorphic (cball b e)" (is ?cth)
-proof-
+    and "(cball a d) homeomorphic (cball b e)" (is ?cth)
+proof -
   show ?th unfolding homeomorphic_minimal
     apply(rule_tac x="\<lambda>x. b + (e/d) *\<^sub>R (x - a)" in exI)
     apply(rule_tac x="\<lambda>x. a + (d/e) *\<^sub>R (x - b)" in exI)
@@ -6133,7 +7046,6 @@
     apply (auto intro!: continuous_on_intros
       simp: dist_commute dist_norm pos_divide_less_eq mult_strict_left_mono)
     done
-next
   show ?cth unfolding homeomorphic_minimal
     apply(rule_tac x="\<lambda>x. b + (e/d) *\<^sub>R (x - a)" in exI)
     apply(rule_tac x="\<lambda>x. a + (d/e) *\<^sub>R (x - b)" in exI)
@@ -6173,9 +7085,9 @@
         using `N \<le> n` N unfolding f.diff[THEN sym] by auto
       finally have "norm (x n - x N) < d" using `e>0` by simp
     }
-    hence "\<exists>N. \<forall>n\<ge>N. norm (x n - x N) < d" by auto
+    then have "\<exists>N. \<forall>n\<ge>N. norm (x n - x N) < d" by auto
   }
-  thus ?thesis unfolding cauchy and dist_norm by auto
+  then show ?thesis unfolding cauchy and dist_norm by auto
 qed
 
 lemma complete_isometric_image:
@@ -6190,18 +7102,18 @@
   {
     fix g
     assume as:"\<forall>n::nat. g n \<in> f ` s" and cfg:"Cauchy g"
-    then obtain x where "\<forall>n. x n \<in> s \<and> g n = f (x n)" 
+    then obtain x where "\<forall>n. x n \<in> s \<and> g n = f (x n)"
       using choice[of "\<lambda> n xa. xa \<in> s \<and> g n = f xa"] by auto
-    hence x:"\<forall>n. x n \<in> s"  "\<forall>n. g n = f (x n)" by auto
-    hence "f \<circ> x = g" unfolding fun_eq_iff by auto
+    then have x:"\<forall>n. x n \<in> s"  "\<forall>n. g n = f (x n)" by auto
+    then have "f \<circ> x = g" unfolding fun_eq_iff by auto
     then obtain l where "l\<in>s" and l:"(x ---> l) sequentially"
       using cs[unfolded complete_def, THEN spec[where x="x"]]
       using cauchy_isometric[OF `0<e` s f normf] and cfg and x(1) by auto
-    hence "\<exists>l\<in>f ` s. (g ---> l) sequentially"
+    then have "\<exists>l\<in>f ` s. (g ---> l) sequentially"
       using linear_continuous_at[OF f, unfolded continuous_at_sequentially, THEN spec[where x=x], of l]
       unfolding `f \<circ> x = g` by auto
   }
-  thus ?thesis unfolding complete_def by auto
+  then show ?thesis unfolding complete_def by auto
 qed
 
 lemma injective_imp_isometric:
@@ -6214,10 +7126,10 @@
   {
     fix x
     assume "x \<in> s"
-    hence "x = 0" using True by auto
-    hence "norm x \<le> norm (f x)" by auto
+    then have "x = 0" using True by auto
+    then have "norm x \<le> norm (f x)" by auto
   }
-  thus ?thesis by (auto intro!: exI[where x=1])
+  then show ?thesis by (auto intro!: exI[where x=1])
 next
   interpret f: bounded_linear f by fact
   case False
@@ -6229,7 +7141,7 @@
 
   have "?S'' = frontier(cball 0 (norm a))"
     unfolding frontier_cball and dist_norm by auto
-  hence "compact ?S''"
+  then have "compact ?S''"
     using compact_frontier[OF compact_cball, of 0 "norm a"] by auto
   moreover have "?S' = s \<inter> ?S''" by auto
   ultimately have "compact ?S'"
@@ -6237,12 +7149,13 @@
   moreover have *:"f ` ?S' = ?S" by auto
   ultimately have "compact ?S"
     using compact_continuous_image[OF linear_continuous_on[OF f(1)], of ?S'] by auto
-  hence "closed ?S" using compact_imp_closed by auto
+  then have "closed ?S" using compact_imp_closed by auto
   moreover have "?S \<noteq> {}" using a by auto
   ultimately obtain b' where "b'\<in>?S" "\<forall>y\<in>?S. norm b' \<le> norm y"
     using distance_attains_inf[of ?S 0] unfolding dist_0_norm by auto
-  then obtain b where "b\<in>s" and ba:"norm b = norm a"
-      and b:"\<forall>x\<in>{x \<in> s. norm x = norm a}. norm (f b) \<le> norm (f x)"
+  then obtain b where "b\<in>s"
+    and ba: "norm b = norm a"
+    and b: "\<forall>x\<in>{x \<in> s. norm x = norm a}. norm (f b) \<le> norm (f x)"
     unfolding *[THEN sym] unfolding image_iff by auto
 
   let ?e = "norm (f b) / norm b"
@@ -6258,21 +7171,21 @@
   {
     fix x
     assume "x\<in>s"
-    hence "norm (f b) / norm b * norm x \<le> norm (f x)"
+    then have "norm (f b) / norm b * norm x \<le> norm (f x)"
     proof (cases "x=0")
       case True
-      thus "norm (f b) / norm b * norm x \<le> norm (f x)" by auto
+      then show "norm (f b) / norm b * norm x \<le> norm (f x)" by auto
     next
       case False
-      hence *:"0 < norm a / norm x"
+      then have *: "0 < norm a / norm x"
         using `a\<noteq>0`
         unfolding zero_less_norm_iff[THEN sym]
         by (simp only: divide_pos_pos)
       have "\<forall>c. \<forall>x\<in>s. c *\<^sub>R x \<in> s"
         using s[unfolded subspace_def] by auto
-      hence "(norm a / norm x) *\<^sub>R x \<in> {x \<in> s. norm x = norm a}"
+      then have "(norm a / norm x) *\<^sub>R x \<in> {x \<in> s. norm x = norm a}"
         using `x\<in>s` and `x\<noteq>0` by auto
-      thus "norm (f b) / norm b * norm x \<le> norm (f x)"
+      then show "norm (f b) / norm b * norm x \<le> norm (f x)"
         using b[THEN bspec[where x="(norm a / norm x) *\<^sub>R x"]]
         unfolding f.scaleR and ba using `x\<noteq>0` `a\<noteq>0`
         by (auto simp add: mult_commute pos_le_divide_eq pos_divide_le_eq)
@@ -6283,10 +7196,10 @@
 
 lemma closed_injective_image_subspace:
   fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
-  assumes "subspace s" "bounded_linear f" "\<forall>x\<in>s. f x = 0 --> x = 0" "closed s"
+  assumes "subspace s" "bounded_linear f" "\<forall>x\<in>s. f x = 0 \<longrightarrow> x = 0" "closed s"
   shows "closed(f ` s)"
-proof-
-  obtain e where "e>0" and e:"\<forall>x\<in>s. e * norm x \<le> norm (f x)"
+proof -
+  obtain e where "e > 0" and e: "\<forall>x\<in>s. e * norm x \<le> norm (f x)"
     using injective_imp_isometric[OF assms(4,1,2,3)] by auto
   show ?thesis
     using complete_isometric_image[OF `e>0` assms(1,2) e] and assms(4)
@@ -6320,55 +7233,58 @@
   moreover
   {
     fix x::"'a" assume "x \<in> ?A"
-    hence "finite d" "x \<in> ?A" using assms by(auto intro: finite_subset[OF _ finite_Basis])
+    then have "finite d" "x \<in> ?A"
+      using assms by (auto intro: finite_subset[OF _ finite_Basis])
     from this d have "x \<in> span d"
     proof (induct d arbitrary: x)
       case empty
-      hence "x=0"
+      then have "x = 0"
         apply (rule_tac euclidean_eqI)
         apply auto
         done
-      thus ?case
+      then show ?case
         using subspace_0[OF subspace_span[of "{}"]] by auto
     next
       case (insert k F)
-      hence *:"\<forall>i\<in>Basis. i \<notin> insert k F \<longrightarrow> x \<bullet> i = 0" by auto
-      have **:"F \<subseteq> insert k F" by auto
+      then have *: "\<forall>i\<in>Basis. i \<notin> insert k F \<longrightarrow> x \<bullet> i = 0" by auto
+      have **: "F \<subseteq> insert k F" by auto
       def y \<equiv> "x - (x\<bullet>k) *\<^sub>R k"
-      have y:"x = y + (x\<bullet>k) *\<^sub>R k" unfolding y_def by auto
+      have y: "x = y + (x\<bullet>k) *\<^sub>R k" unfolding y_def by auto
       { fix i assume i': "i \<notin> F" "i \<in> Basis"
-        hence "y \<bullet> i = 0" unfolding y_def 
+        then have "y \<bullet> i = 0" unfolding y_def
           using *[THEN bspec[where x=i]] insert by (auto simp: inner_simps inner_Basis) }
-      hence "y \<in> span F" using insert by auto
-      hence "y \<in> span (insert k F)"
+      then have "y \<in> span F" using insert by auto
+      then have "y \<in> span (insert k F)"
         using span_mono[of F "insert k F"] using assms by auto
       moreover
       have "k \<in> span (insert k F)" by(rule span_superset, auto)
-      hence "(x\<bullet>k) *\<^sub>R k \<in> span (insert k F)"
+      then have "(x\<bullet>k) *\<^sub>R k \<in> span (insert k F)"
         using span_mul by auto
       ultimately
       have "y + (x\<bullet>k) *\<^sub>R k \<in> span (insert k F)"
         using span_add by auto
-      thus ?case using y by auto
+      then show ?case using y by auto
     qed
   }
-  hence "?A \<subseteq> span d" by auto
+  then have "?A \<subseteq> span d" by auto
   moreover
   {
     fix x
     assume "x \<in> d"
-    hence "x \<in> ?D" using assms by auto
+    then have "x \<in> ?D" using assms by auto
   }
-  hence "independent d"
+  then have "independent d"
     using independent_mono[OF independent_Basis, of d] and assms by auto
   moreover
   have "d \<subseteq> ?D" unfolding subset_eq using assms by auto
   ultimately show ?thesis using dim_unique[of d ?A] by auto
 qed
 
-text{* Hence closure and completeness of all subspaces.                          *}
-
-lemma ex_card: assumes "n \<le> card A" shows "\<exists>S\<subseteq>A. card S = n"
+text{* Hence closure and completeness of all subspaces. *}
+
+lemma ex_card:
+  assumes "n \<le> card A"
+  shows "\<exists>S\<subseteq>A. card S = n"
 proof cases
   assume "finite A"
   from ex_bij_betw_nat_finite[OF this] guess f ..
@@ -6425,7 +7341,7 @@
     using dim_subset[of "closure s" "span s"]
     unfolding dim_span
     by auto
-  thus ?thesis using dim_subset[OF closure_subset, of s]
+  then show ?thesis using dim_subset[OF closure_subset, of s]
     by auto
 qed
 
@@ -6462,34 +7378,54 @@
             (if {a .. b} = {} then {}
             else (if 0 \<le> m then {m *\<^sub>R a + c .. m *\<^sub>R b + c}
             else {m *\<^sub>R b + c .. m *\<^sub>R a + c}))"
-proof(cases "m=0")  
-  { fix x assume "x \<le> c" "c \<le> x"
-    hence "x=c" unfolding eucl_le[where 'a='a] apply-
-      apply(subst euclidean_eq_iff) by (auto intro: order_antisym) }
+proof (cases "m = 0")
+  {
+    fix x
+    assume "x \<le> c" "c \<le> x"
+    then have "x = c"
+      unfolding eucl_le[where 'a='a]
+      apply -
+      apply (subst euclidean_eq_iff)
+      apply (auto intro: order_antisym)
+      done
+  }
   moreover case True
   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])
   ultimately show ?thesis by auto
 next
   case False
-  { fix y assume "a \<le> y" "y \<le> b" "m > 0"
-    hence "m *\<^sub>R a + c \<le> m *\<^sub>R y + c"  "m *\<^sub>R y + c \<le> m *\<^sub>R b + c"
+  {
+    fix y
+    assume "a \<le> y" "y \<le> b" "m > 0"
+    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"
       unfolding eucl_le[where 'a='a] by (auto simp: inner_simps)
-  } moreover
-  { fix y assume "a \<le> y" "y \<le> b" "m < 0"
-    hence "m *\<^sub>R b + c \<le> m *\<^sub>R y + c"  "m *\<^sub>R y + c \<le> m *\<^sub>R a + c"
-      unfolding eucl_le[where 'a='a] by(auto simp add: mult_left_mono_neg inner_simps)
-  } moreover
-  { fix y assume "m > 0"  "m *\<^sub>R a + c \<le> y"  "y \<le> m *\<^sub>R b + c"
-    hence "y \<in> (\<lambda>x. m *\<^sub>R x + c) ` {a..b}"
+  }
+  moreover
+  {
+    fix y
+    assume "a \<le> y" "y \<le> b" "m < 0"
+    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"
+      unfolding eucl_le[where 'a='a] by (auto simp add: mult_left_mono_neg inner_simps)
+  }
+  moreover
+  {
+    fix y
+    assume "m > 0" and "m *\<^sub>R a + c \<le> y" and "y \<le> m *\<^sub>R b + c"
+    then have "y \<in> (\<lambda>x. m *\<^sub>R x + c) ` {a..b}"
       unfolding image_iff Bex_def mem_interval eucl_le[where 'a='a]
       apply (intro exI[where x="(1 / m) *\<^sub>R (y - c)"])
-      by(auto simp add: pos_le_divide_eq pos_divide_le_eq mult_commute diff_le_iff inner_simps)
-  } moreover
-  { fix y assume "m *\<^sub>R b + c \<le> y" "y \<le> m *\<^sub>R a + c" "m < 0"
-    hence "y \<in> (\<lambda>x. m *\<^sub>R x + c) ` {a..b}"
+      apply (auto simp add: pos_le_divide_eq pos_divide_le_eq mult_commute diff_le_iff inner_simps)
+      done
+  }
+  moreover
+  {
+    fix y
+    assume "m *\<^sub>R b + c \<le> y" "y \<le> m *\<^sub>R a + c" "m < 0"
+    then have "y \<in> (\<lambda>x. m *\<^sub>R x + c) ` {a..b}"
       unfolding image_iff Bex_def mem_interval eucl_le[where 'a='a]
       apply (intro exI[where x="(1 / m) *\<^sub>R (y - c)"])
-      by(auto simp add: neg_le_divide_eq neg_divide_le_eq mult_commute diff_le_iff inner_simps)
+      apply (auto simp add: neg_le_divide_eq neg_divide_le_eq mult_commute diff_le_iff inner_simps)
+      done
   }
   ultimately show ?thesis using False by auto
 qed
@@ -6502,40 +7438,44 @@
 subsection {* Banach fixed point theorem (not really topological...) *}
 
 lemma banach_fix:
-  assumes s:"complete s" "s \<noteq> {}" and c:"0 \<le> c" "c < 1" and f:"(f ` s) \<subseteq> s" and
-          lipschitz:"\<forall>x\<in>s. \<forall>y\<in>s. dist (f x) (f y) \<le> c * dist x y"
+  assumes s: "complete s" "s \<noteq> {}"
+    and c: "0 \<le> c" "c < 1"
+    and f: "(f ` s) \<subseteq> s"
+    and lipschitz:"\<forall>x\<in>s. \<forall>y\<in>s. dist (f x) (f y) \<le> c * dist x y"
   shows "\<exists>! x\<in>s. (f x = x)"
-proof-
+proof -
   have "1 - c > 0" using c by auto
 
   from s(2) obtain z0 where "z0 \<in> s" by auto
   def z \<equiv> "\<lambda>n. (f ^^ n) z0"
-  { fix n::nat
+  {
+    fix n :: nat
     have "z n \<in> s" unfolding z_def
     proof (induct n)
       case 0
-      thus ?case using `z0 \<in>s` by auto
+      then show ?case using `z0 \<in> s` by auto
     next
       case Suc
-      thus ?case using f by auto qed
+      then show ?case using f by auto qed
   } note z_in_s = this
 
   def d \<equiv> "dist (z 0) (z 1)"
 
   have fzn:"\<And>n. f (z n) = z (Suc n)" unfolding z_def by auto
   {
-    fix n::nat
+    fix n :: nat
     have "dist (z n) (z (Suc n)) \<le> (c ^ n) * d"
     proof (induct n)
-      case 0 thus ?case
+      case 0
+      then show ?case
         unfolding d_def by auto
     next
       case (Suc m)
-      hence "c * dist (z m) (z (Suc m)) \<le> c ^ Suc m * d"
+      then have "c * dist (z m) (z (Suc m)) \<le> c ^ Suc m * d"
         using `0 \<le> c`
         using mult_left_mono[of "dist (z m) (z (Suc m))" "c ^ m * d" c]
         by auto
-      thus ?case
+      then show ?case
         using lipschitz[THEN bspec[where x="z m"], OF z_in_s, THEN bspec[where x="z (Suc m)"], OF z_in_s]
         unfolding fzn and mult_le_cancel_left
         by auto
@@ -6543,10 +7483,11 @@
   } note cf_z = this
 
   {
-    fix n m::nat
+    fix n m :: nat
     have "(1 - c) * dist (z m) (z (m+n)) \<le> (c ^ m) * d * (1 - c ^ n)"
     proof (induct n)
-      case 0 show ?case by auto
+      case 0
+      show ?case by auto
     next
       case (Suc k)
       have "(1 - c) * dist (z m) (z (m + Suc k)) \<le>
@@ -6564,21 +7505,21 @@
     qed
   } note cf_z2 = this
   {
-    fix e::real
-    assume "e>0"
-    hence "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (z m) (z n) < e"
+    fix e :: real
+    assume "e > 0"
+    then have "\<exists>N. \<forall>m n. N \<le> m \<and> N \<le> n \<longrightarrow> dist (z m) (z n) < e"
     proof (cases "d = 0")
       case True
       have *: "\<And>x. ((1 - c) * x \<le> 0) = (x \<le> 0)" using `1 - c > 0`
         by (metis mult_zero_left mult_commute real_mult_le_cancel_iff1)
       from True have "\<And>n. z n = z0" using cf_z2[of 0] and c unfolding z_def
         by (simp add: *)
-      thus ?thesis using `e>0` by auto
+      then show ?thesis using `e>0` by auto
     next
       case False
-      hence "d>0" unfolding d_def using zero_le_dist[of "z 0" "z 1"]
+      then have "d>0" unfolding d_def using zero_le_dist[of "z 0" "z 1"]
         by (metis False d_def less_le)
-      hence "0 < e * (1 - c) / d"
+      then have "0 < e * (1 - c) / d"
         using `e>0` and `1-c>0`
         using divide_pos_pos[of "e * (1 - c)" d] and mult_pos_pos[of e "1 - c"]
         by auto
@@ -6591,7 +7532,7 @@
           using power_decreasing[OF `n\<ge>N`, of c] by auto
         have "1 - c ^ (m - n) > 0"
           using c and power_strict_mono[of c 1 "m - n"] using `m>n` by auto
-        hence **:"d * (1 - c ^ (m - n)) / (1 - c) > 0"
+        then have **: "d * (1 - c ^ (m - n)) / (1 - c) > 0"
           using mult_pos_pos[OF `d>0`, of "1 - c ^ (m - n)"]
           using divide_pos_pos[of "d * (1 - c ^ (m - n))" "1 - c"]
           using `0 < 1 - c`
@@ -6606,27 +7547,30 @@
           unfolding mult_assoc by auto
         also have "\<dots> < (e * (1 - c) / d) * d * (1 - c ^ (m - n)) / (1 - c)"
           using mult_strict_right_mono[OF N **] unfolding mult_assoc by auto
-        also have "\<dots> = e * (1 - c ^ (m - n))" using c and `d>0` and `1 - c > 0` by auto
-        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
+        also have "\<dots> = e * (1 - c ^ (m - n))"
+          using c and `d>0` and `1 - c > 0` by auto
+        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
         finally have  "dist (z m) (z n) < e" by auto
       } note * = this
       {
-        fix m n::nat
-        assume as:"N\<le>m" "N\<le>n"
-        hence "dist (z n) (z m) < e"
+        fix m n :: nat
+        assume as: "N \<le> m" "N \<le> n"
+        then have "dist (z n) (z m) < e"
         proof (cases "n = m")
           case True
-          thus ?thesis using `e>0` by auto
+          then show ?thesis using `e>0` by auto
         next
           case False
-          thus ?thesis using as and *[of n m] *[of m n]
+          then show ?thesis using as and *[of n m] *[of m n]
             unfolding nat_neq_iff by (auto simp add: dist_commute)
         qed
       }
-      thus ?thesis by auto
+      then show ?thesis by auto
     qed
   }
-  hence "Cauchy z" unfolding cauchy_def by auto
+  then have "Cauchy z"
+    unfolding cauchy_def by auto
   then obtain x where "x\<in>s" and x:"(z ---> x) sequentially"
     using s(1)[unfolded compact_def complete_def, THEN spec[where x=z]] and z_in_s by auto
 
@@ -6634,13 +7578,14 @@
   have "e = 0"
   proof (rule ccontr)
     assume "e \<noteq> 0"
-    hence "e>0" unfolding e_def using zero_le_dist[of "f x" x]
+    then have "e > 0"
+      unfolding e_def using zero_le_dist[of "f x" x]
       by (metis dist_eq_0_iff dist_nz e_def)
     then obtain N where N:"\<forall>n\<ge>N. dist (z n) x < e / 2"
       using x[unfolded LIMSEQ_def, THEN spec[where x="e/2"]] by auto
-    hence N':"dist (z N) x < e / 2" by auto
-
-    have *:"c * dist (z N) x \<le> dist (z N) x"
+    then have N':"dist (z N) x < e / 2" by auto
+
+    have *: "c * dist (z N) x \<le> dist (z N) x"
       unfolding mult_le_cancel_right2
       using zero_le_dist[of "z N" x] and c
       by (metis dist_eq_0_iff dist_nz order_less_asym less_le)
@@ -6657,24 +7602,25 @@
       unfolding e_def
       by auto
   qed
-  hence "f x = x" unfolding e_def by auto
+  then have "f x = x" unfolding e_def by auto
   moreover
   {
     fix y
     assume "f y = y" "y\<in>s"
-    hence "dist x y \<le> c * dist x y"
+    then have "dist x y \<le> c * dist x y"
       using lipschitz[THEN bspec[where x=x], THEN bspec[where x=y]]
       using `x\<in>s` and `f x = x`
       by auto
-    hence "dist x y = 0"
+    then have "dist x y = 0"
       unfolding mult_le_cancel_right1
       using c and zero_le_dist[of x y]
       by auto
-    hence "y = x" by auto
+    then have "y = x" by auto
   }
   ultimately show ?thesis using `x\<in>s` by blast+
 qed
 
+
 subsection {* Edelstein fixed point theorem *}
 
 lemma edelstein_fix:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Pure/Isar/completion.scala	Thu Aug 29 19:22:48 2013 +0200
@@ -0,0 +1,114 @@
+/*  Title:      Pure/Isar/completion.scala
+    Author:     Makarius
+
+Completion of symbols and keywords.
+*/
+
+package isabelle
+
+import scala.util.parsing.combinator.RegexParsers
+
+
+object Completion
+{
+  /* items */
+
+  sealed case class Item(original: String, replacement: String, description: String)
+  { override def toString: String = description }
+
+
+  /* init */
+
+  val empty: Completion = new Completion()
+  def init(): Completion = empty.add_symbols()
+
+
+  /** word completion **/
+
+  private val word_regex = "[a-zA-Z0-9_']+".r
+  private def is_word(s: CharSequence): Boolean = word_regex.pattern.matcher(s).matches
+
+  private object Parse extends RegexParsers
+  {
+    override val whiteSpace = "".r
+
+    def reverse_symbol: Parser[String] = """>[A-Za-z0-9_']+\^?<\\""".r
+    def reverse_symb: Parser[String] = """[A-Za-z0-9_']{2,}\^?<\\""".r
+    def escape: Parser[String] = """[a-zA-Z0-9_']+\\""".r
+    def word: Parser[String] = """[a-zA-Z0-9_']{3,}""".r
+
+    def read(in: CharSequence): Option[String] =
+    {
+      val reverse_in = new Library.Reverse(in)
+      parse((reverse_symbol | reverse_symb | escape | word) ^^ (_.reverse), reverse_in) match {
+        case Success(result, _) => Some(result)
+        case _ => None
+      }
+    }
+  }
+}
+
+final class Completion private(
+  words_lex: Scan.Lexicon = Scan.Lexicon.empty,
+  words_map: Map[String, String] = Map.empty,
+  abbrevs_lex: Scan.Lexicon = Scan.Lexicon.empty,
+  abbrevs_map: Map[String, (String, String)] = Map.empty)
+{
+  /* adding stuff */
+
+  def + (keyword: String, replace: String): Completion =
+    new Completion(
+      words_lex + keyword,
+      words_map + (keyword -> replace),
+      abbrevs_lex,
+      abbrevs_map)
+
+  def + (keyword: String): Completion = this + (keyword, keyword)
+
+  private def add_symbols(): Completion =
+  {
+    val words =
+      (for ((x, _) <- Symbol.names) yield (x, x)).toList :::
+      (for ((x, y) <- Symbol.names) yield ("\\" + y, x)).toList :::
+      (for ((x, y) <- Symbol.abbrevs if Completion.is_word(y)) yield (y, x)).toList
+
+    val abbrs =
+      (for ((x, y) <- Symbol.abbrevs if !Completion.is_word(y))
+        yield (y.reverse.toString, (y, x))).toList
+
+    new Completion(
+      words_lex ++ words.map(_._1),
+      words_map ++ words,
+      abbrevs_lex ++ abbrs.map(_._1),
+      abbrevs_map ++ abbrs)
+  }
+
+
+  /* complete */
+
+  def complete(decode: Boolean, line: CharSequence): Option[(String, List[Completion.Item])] =
+  {
+    val raw_result =
+      abbrevs_lex.parse(abbrevs_lex.keyword, new Library.Reverse(line)) match {
+        case abbrevs_lex.Success(reverse_a, _) =>
+          val (word, c) = abbrevs_map(reverse_a)
+          Some(word, List(c))
+        case _ =>
+          Completion.Parse.read(line) match {
+            case Some(word) =>
+              words_lex.completions(word).map(words_map(_)) match {
+                case Nil => None
+                case cs => Some(word, cs.sorted)
+              }
+            case None => None
+          }
+      }
+    raw_result match {
+      case Some((word, cs)) =>
+        val ds = (if (decode) cs.map(Symbol.decode(_)).sorted else cs).filter(_ != word)
+        if (ds.isEmpty) None
+        else Some((word, ds.map(s => Completion.Item(word, s, s))))
+      case None => None
+    }
+  }
+}
--- a/src/Pure/Isar/outer_syntax.scala	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Pure/Isar/outer_syntax.scala	Thu Aug 29 19:22:48 2013 +0200
@@ -42,7 +42,8 @@
 final class Outer_Syntax private(
   keywords: Map[String, (String, List[String])] = Map.empty,
   lexicon: Scan.Lexicon = Scan.Lexicon.empty,
-  val completion: Completion = Completion.empty)
+  val completion: Completion = Completion.empty,
+  val has_tokens: Boolean = true)
 {
   override def toString: String =
     (for ((name, (kind, files)) <- keywords) yield {
@@ -59,14 +60,19 @@
     (for ((name, (Keyword.THY_LOAD, files)) <- keywords.iterator) yield (name, files)).toList
 
   def + (name: String, kind: (String, List[String]), replace: Option[String]): Outer_Syntax =
-    new Outer_Syntax(
-      keywords + (name -> kind),
-      lexicon + name,
+  {
+    val keywords1 = keywords + (name -> kind)
+    val lexicon1 = lexicon + name
+    val completion1 =
       if (Keyword.control(kind._1) || replace == Some("")) completion
-      else completion + (name, replace getOrElse name))
+      else completion + (name, replace getOrElse name)
+    new Outer_Syntax(keywords1, lexicon1, completion1, true)
+  }
 
-  def + (name: String, kind: (String, List[String])): Outer_Syntax = this + (name, kind, Some(name))
-  def + (name: String, kind: String): Outer_Syntax = this + (name, (kind, Nil), Some(name))
+  def + (name: String, kind: (String, List[String])): Outer_Syntax =
+    this + (name, kind, Some(name))
+  def + (name: String, kind: String): Outer_Syntax =
+    this + (name, (kind, Nil), Some(name))
   def + (name: String, replace: Option[String]): Outer_Syntax =
     this + (name, (Keyword.MINOR, Nil), replace)
   def + (name: String): Outer_Syntax = this + (name, None)
@@ -106,7 +112,13 @@
     heading_level(command.name)
 
 
-  /* tokenize */
+  /* token language */
+
+  def no_tokens: Outer_Syntax =
+  {
+    require(keywords.isEmpty && lexicon.isEmpty)
+    new Outer_Syntax(completion = completion, has_tokens = false)
+  }
 
   def scan(input: Reader[Char]): List[Token] =
   {
--- a/src/Pure/Thy/completion.scala	Thu Aug 29 18:44:03 2013 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-/*  Title:      Pure/Thy/completion.scala
-    Author:     Makarius
-
-Completion of symbols and keywords.
-*/
-
-package isabelle
-
-import scala.util.matching.Regex
-import scala.util.parsing.combinator.RegexParsers
-
-
-object Completion
-{
-  val empty: Completion = new Completion()
-  def init(): Completion = empty.add_symbols()
-
-
-  /** word completion **/
-
-  private val word_regex = "[a-zA-Z0-9_']+".r
-  private def is_word(s: CharSequence): Boolean = word_regex.pattern.matcher(s).matches
-
-  private object Parse extends RegexParsers
-  {
-    override val whiteSpace = "".r
-
-    def reverse_symbol: Parser[String] = """>[A-Za-z0-9_']+\^?<\\""".r
-    def reverse_symb: Parser[String] = """[A-Za-z0-9_']{2,}\^?<\\""".r
-    def escape: Parser[String] = """[a-zA-Z0-9_']+\\""".r
-    def word: Parser[String] = """[a-zA-Z0-9_']{3,}""".r
-
-    def read(in: CharSequence): Option[String] =
-    {
-      val reverse_in = new Library.Reverse(in)
-      parse((reverse_symbol | reverse_symb | escape | word) ^^ (_.reverse), reverse_in) match {
-        case Success(result, _) => Some(result)
-        case _ => None
-      }
-    }
-  }
-}
-
-final class Completion private(
-  words_lex: Scan.Lexicon = Scan.Lexicon.empty,
-  words_map: Map[String, String] = Map.empty,
-  abbrevs_lex: Scan.Lexicon = Scan.Lexicon.empty,
-  abbrevs_map: Map[String, (String, String)] = Map.empty)
-{
-  /* adding stuff */
-
-  def + (keyword: String, replace: String): Completion =
-    new Completion(
-      words_lex + keyword,
-      words_map + (keyword -> replace),
-      abbrevs_lex,
-      abbrevs_map)
-
-  def + (keyword: String): Completion = this + (keyword, keyword)
-
-  private def add_symbols(): Completion =
-  {
-    val words =
-      (for ((x, _) <- Symbol.names) yield (x, x)).toList :::
-      (for ((x, y) <- Symbol.names) yield ("\\" + y, x)).toList :::
-      (for ((x, y) <- Symbol.abbrevs if Completion.is_word(y)) yield (y, x)).toList
-
-    val abbrs =
-      (for ((x, y) <- Symbol.abbrevs if !Completion.is_word(y))
-        yield (y.reverse.toString, (y, x))).toList
-
-    new Completion(
-      words_lex ++ words.map(_._1),
-      words_map ++ words,
-      abbrevs_lex ++ abbrs.map(_._1),
-      abbrevs_map ++ abbrs)
-  }
-
-
-  /* complete */
-
-  def complete(line: CharSequence): Option[(String, List[String])] =
-  {
-    abbrevs_lex.parse(abbrevs_lex.keyword, new Library.Reverse(line)) match {
-      case abbrevs_lex.Success(reverse_a, _) =>
-        val (word, c) = abbrevs_map(reverse_a)
-        Some(word, List(c))
-      case _ =>
-        Completion.Parse.read(line) match {
-          case Some(word) =>
-            words_lex.completions(word).map(words_map(_)) match {
-              case Nil => None
-              case cs => Some(word, cs.sorted)
-            }
-          case None => None
-        }
-    }
-  }
-}
--- a/src/Pure/build-jars	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Pure/build-jars	Thu Aug 29 19:22:48 2013 +0200
@@ -29,6 +29,7 @@
   General/time.scala
   General/timing.scala
   General/xz_file.scala
+  Isar/completion.scala
   Isar/keyword.scala
   Isar/outer_syntax.scala
   Isar/parse.scala
@@ -64,7 +65,6 @@
   System/swing_thread.scala
   System/system_channel.scala
   System/utf8.scala
-  Thy/completion.scala
   Thy/html.scala
   Thy/present.scala
   Thy/thy_header.scala
--- a/src/Tools/jEdit/etc/options	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Tools/jEdit/etc/options	Thu Aug 29 19:22:48 2013 +0200
@@ -16,7 +16,7 @@
   -- "relative bounds of popup window wrt. logical screen size"
 
 public option jedit_tooltip_delay : real = 0.75
-  -- "open/close delay for document tooltips"
+  -- "open/close delay for document tooltips (seconds)"
 
 public option jedit_tooltip_margin : int = 60
   -- "margin for tooltip pretty-printing"
@@ -33,6 +33,12 @@
 public option jedit_timing_threshold : real = 0.1
   -- "default threshold for timing display"
 
+public option jedit_completion : bool = true
+  -- "enable completion popup"
+
+public option jedit_completion_delay : real = 0.0
+  -- "delay for completion popup (seconds)"
+
 
 section "Rendering of Document Content"
 
--- a/src/Tools/jEdit/src/completion_popup.scala	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Tools/jEdit/src/completion_popup.scala	Thu Aug 29 19:22:48 2013 +0200
@@ -22,41 +22,72 @@
 
 object Completion_Popup
 {
-  /* items */
+  /* setup for jEdit text area */
+
+  object Text_Area
+  {
+    private val key = new Object
 
-  private sealed case class Item(original: String, replacement: String, description: String)
-  { override def toString: String = description }
-
-
-  /* maintain single instance */
+    def apply(text_area: JEditTextArea): Option[Completion_Popup.Text_Area] =
+      text_area.getClientProperty(key) match {
+        case text_area_completion: Completion_Popup.Text_Area => Some(text_area_completion)
+        case _ => None
+      }
 
-  def dismissed(layered: JLayeredPane): Boolean =
-  {
-    Swing_Thread.require()
+    def exit(text_area: JEditTextArea)
+    {
+      Swing_Thread.require()
+      apply(text_area) match {
+        case None =>
+        case Some(text_area_completion) =>
+          text_area_completion.deactivate()
+          text_area.putClientProperty(key, null)
+      }
+    }
 
-    layered.getClientProperty(Completion_Popup) match {
-      case old_completion: Completion_Popup =>
-        old_completion.hide_popup()
-        true
-      case _ =>
-        false
+    def init(text_area: JEditTextArea): Completion_Popup.Text_Area =
+    {
+      exit(text_area)
+      val text_area_completion = new Text_Area(text_area)
+      text_area.putClientProperty(key, text_area_completion)
+      text_area_completion.activate()
+      text_area_completion
+    }
+
+    def dismissed(text_area: JEditTextArea): Boolean =
+    {
+      Swing_Thread.require()
+      apply(text_area) match {
+        case Some(text_area_completion) => text_area_completion.dismissed()
+        case None => false
+      }
     }
   }
 
-  private def register(layered: JLayeredPane, completion: Completion_Popup)
+  class Text_Area private(text_area: JEditTextArea)
   {
-    Swing_Thread.require()
+    /* popup state */
+
+    private var completion_popup: Option[Completion_Popup] = None
+
+    def dismissed(): Boolean =
+    {
+      Swing_Thread.require()
 
-    dismissed(layered)
-    layered.putClientProperty(Completion_Popup, completion)
-  }
+      completion_popup match {
+        case Some(completion) =>
+          completion.hide_popup()
+          completion_popup = None
+          true
+        case None =>
+          false
+      }
+    }
 
 
-  /* jEdit text area operations */
+    /* insert selected item */
 
-  object Text_Area
-  {
-    private def insert(text_area: JEditTextArea, item: Item)
+    private def insert(item: Completion.Item)
     {
       Swing_Thread.require()
 
@@ -75,67 +106,86 @@
       }
     }
 
-    def input(text_area: JEditTextArea, get_syntax: => Option[Outer_Syntax], evt: KeyEvent)
+
+    /* input of key events */
+
+    def input(evt: KeyEvent)
     {
       Swing_Thread.require()
 
-      val view = text_area.getView
-      val layered = view.getLayeredPane
-      val buffer = text_area.getBuffer
-      val painter = text_area.getPainter
+      if (PIDE.options.bool("jedit_completion")) {
+        if (!evt.isConsumed) {
+          dismissed()
+          input_delay.invoke()
+        }
+      }
+      else {
+        dismissed()
+        input_delay.revoke()
+      }
+    }
 
-      if (buffer.isEditable && !evt.isConsumed) {
-        dismissed(layered)
+    private val input_delay =
+      Swing_Thread.delay_last(PIDE.options.seconds("jedit_completion_delay"))
+      {
+        val view = text_area.getView
+        val layered = view.getLayeredPane
+        val buffer = text_area.getBuffer
+        val painter = text_area.getPainter
 
-        get_syntax match {
-          case Some(syntax) =>
-            val caret = text_area.getCaretPosition
-            val result =
-            {
+        if (buffer.isEditable) {
+          Isabelle.mode_syntax(JEdit_Lib.buffer_mode(buffer)) match {
+            case Some(syntax) =>
+              val caret = text_area.getCaretPosition
               val line = buffer.getLineOfOffset(caret)
               val start = buffer.getLineStartOffset(line)
               val text = buffer.getSegment(start, caret - start)
 
-              syntax.completion.complete(text) match {
-                case Some((word, cs)) =>
-                  val ds =
-                    (if (Isabelle_Encoding.is_active(buffer))
-                      cs.map(Symbol.decode(_)).sorted
-                     else cs).filter(_ != word)
-                  if (ds.isEmpty) None
-                  else Some((word, ds.map(s => Item(word, s, s))))
-                case None => None
-              }
-            }
-            result match {
-              case Some((original, items)) =>
-                val popup_font =
-                  painter.getFont.deriveFont(
-                    (painter.getFont.getSize2D * PIDE.options.real("jedit_popup_font_scale")).toFloat
-                      max 10.0f)
+              syntax.completion.complete(Isabelle_Encoding.is_active(buffer), text) match {
+                case Some((original, items)) =>
+                  val font =
+                    painter.getFont.deriveFont(Rendering.font_size("jedit_popup_font_scale"))
+
+                  val loc1 = text_area.offsetToXY(caret - original.length)
+                  if (loc1 != null) {
+                    val loc2 =
+                      SwingUtilities.convertPoint(painter,
+                        loc1.x, loc1.y + painter.getFontMetrics.getHeight, layered)
 
-                val loc1 = text_area.offsetToXY(caret - original.length)
-                if (loc1 != null) {
-                  val loc2 =
-                    SwingUtilities.convertPoint(painter,
-                      loc1.x, loc1.y + painter.getFontMetrics.getHeight, layered)
-                  val completion =
-                    new Completion_Popup(layered, loc2, popup_font, items) {
-                      override def complete(item: Item) { insert(text_area, item) }
-                      override def propagate(e: KeyEvent) {
-                        JEdit_Lib.propagate_key(view, e)
-                        input(text_area, get_syntax, e)
+                    val completion =
+                      new Completion_Popup(layered, loc2, font, items) {
+                        override def complete(item: Completion.Item) { insert(item) }
+                        override def propagate(evt: KeyEvent) {
+                          JEdit_Lib.propagate_key(view, evt)
+                          input(evt)
+                        }
+                        override def refocus() { text_area.requestFocus }
                       }
-                      override def refocus() { text_area.requestFocus }
-                    }
-                  register(layered, completion)
-                  completion.show_popup()
-                }
-              case None =>
-            }
-          case None =>
+                    completion_popup = Some(completion)
+                    completion.show_popup()
+                  }
+                case None =>
+              }
+            case None =>
+          }
         }
       }
+
+
+    /* activation */
+
+    private val outer_key_listener =
+      JEdit_Lib.key_listener(key_typed = input _)
+
+    private def activate()
+    {
+      text_area.addKeyListener(outer_key_listener)
+    }
+
+    private def deactivate()
+    {
+      dismissed()
+      text_area.removeKeyListener(outer_key_listener)
     }
   }
 }
@@ -144,8 +194,8 @@
 class Completion_Popup private(
   layered: JLayeredPane,
   location: Point,
-  popup_font: Font,
-  items: List[Completion_Popup.Item]) extends JPanel(new BorderLayout)
+  font: Font,
+  items: List[Completion.Item]) extends JPanel(new BorderLayout)
 {
   completion =>
 
@@ -155,7 +205,7 @@
 
   /* actions */
 
-  def complete(item: Completion_Popup.Item) { }
+  def complete(item: Completion.Item) { }
   def propagate(evt: KeyEvent) { }
   def refocus() { }
 
@@ -163,9 +213,7 @@
   /* list view */
 
   private val list_view = new ListView(items)
-  {
-    font = popup_font
-  }
+  list_view.font = font
   list_view.selection.intervalMode = ListView.IntervalMode.Single
   list_view.peer.setFocusTraversalKeysEnabled(false)
   list_view.peer.setVisibleRowCount(items.length min 8)
@@ -198,7 +246,7 @@
 
   /* event handling */
 
-  private val key_listener =
+  private val inner_key_listener =
     JEdit_Lib.key_listener(
       key_pressed = (e: KeyEvent) =>
         {
@@ -224,7 +272,7 @@
       key_typed = propagate _
     )
 
-  list_view.peer.addKeyListener(key_listener)
+  list_view.peer.addKeyListener(inner_key_listener)
 
   list_view.peer.addMouseListener(new MouseAdapter {
     override def mouseClicked(e: MouseEvent) {
--- a/src/Tools/jEdit/src/document_view.scala	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Tools/jEdit/src/document_view.scala	Thu Aug 29 19:22:48 2013 +0200
@@ -155,8 +155,7 @@
         {
           if (evt.getKeyCode == KeyEvent.VK_ESCAPE && PIDE.dismissed_popups(text_area.getView))
             evt.consume
-        },
-      key_typed = Completion_Popup.Text_Area.input(text_area, PIDE.get_recent_syntax, _)
+        }
     )
 
 
--- a/src/Tools/jEdit/src/isabelle.scala	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Tools/jEdit/src/isabelle.scala	Thu Aug 29 19:22:48 2013 +0200
@@ -1,7 +1,7 @@
 /*  Title:      Tools/jEdit/src/isabelle.scala
     Author:     Makarius
 
-Convenience operations for Isabelle/jEdit.
+Global configuration and convenience operations for Isabelle/jEdit.
 */
 
 package isabelle.jedit
@@ -16,6 +16,40 @@
 
 object Isabelle
 {
+  /* editor modes */
+
+  val modes =
+    List(
+      "isabelle",         // theory source
+      "isabelle-markup",  // SideKick markup tree
+      "isabelle-news",    // NEWS
+      "isabelle-options", // etc/options
+      "isabelle-output",  // pretty text area output
+      "isabelle-root")    // session ROOT
+
+  private lazy val news_syntax = Outer_Syntax.init().no_tokens
+
+  def mode_syntax(name: String): Option[Outer_Syntax] =
+    name match {
+      case "isabelle" | "isabelle-markup" =>
+        val syntax = PIDE.session.recent_syntax
+        if (syntax == Outer_Syntax.empty) None else Some(syntax)
+      case "isabelle-options" => Some(Options.options_syntax)
+      case "isabelle-root" => Some(Build.root_syntax)
+      case "isabelle-news" => Some(news_syntax)
+      case "isabelle-output" => None
+      case _ => None
+    }
+
+
+  /* token markers */
+
+  private val markers =
+    Map(modes.map(name => (name, new Token_Markup.Marker(name))): _*)
+
+  def token_marker(name: String): Option[Token_Markup.Marker] = markers.get(name)
+
+
   /* dockable windows */
 
   private def wm(view: View): DockableWindowManager = view.getDockableWindowManager
@@ -98,19 +132,14 @@
 
   /* font size */
 
-  def change_font_size(view: View, change: Int => Int)
-  {
-    val size = change(jEdit.getIntegerProperty("view.fontsize", 16)) max 5 min 250
-    jEdit.setIntegerProperty("view.fontsize", size)
-    jEdit.propertiesChanged()
-    jEdit.saveSettings()
-    view.getStatus.setMessageAndClear("Text font size: " + size)
-  }
+  def reset_font_size(view: View): Unit =
+    Rendering.font_size_change(view, _ => PIDE.options.int("jedit_reset_font_size"))
 
-  def reset_font_size(view: View): Unit =
-    change_font_size(view, _ => PIDE.options.int("jedit_reset_font_size"))
-  def increase_font_size(view: View): Unit = change_font_size(view, i => i + ((i / 10) max 1))
-  def decrease_font_size(view: View): Unit = change_font_size(view, i => i - ((i / 10) max 1))
+  def increase_font_size(view: View): Unit =
+    Rendering.font_size_change(view, i => i + ((i / 10) max 1))
+
+  def decrease_font_size(view: View): Unit =
+    Rendering.font_size_change(view, i => i - ((i / 10) max 1))
 
 
   /* structured insert */
--- a/src/Tools/jEdit/src/isabelle_sidekick.scala	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Tools/jEdit/src/isabelle_sidekick.scala	Thu Aug 29 19:22:48 2013 +0200
@@ -10,18 +10,12 @@
 
 import isabelle._
 
-import scala.collection.Set
-import scala.collection.immutable.TreeSet
-import scala.util.matching.Regex
-
-import java.awt.Component
 import javax.swing.tree.DefaultMutableTreeNode
 import javax.swing.text.Position
-import javax.swing.{Icon, DefaultListCellRenderer, ListCellRenderer, JList}
+import javax.swing.Icon
 
-import org.gjt.sp.jedit.{Buffer, EditPane, TextUtilities, View}
-import errorlist.DefaultErrorSource
-import sidekick.{SideKickParser, SideKickParsedData, SideKickCompletion, IAsset}
+import org.gjt.sp.jedit.Buffer
+import sidekick.{SideKickParser, SideKickParsedData, IAsset}
 
 
 object Isabelle_Sidekick
@@ -58,9 +52,11 @@
 }
 
 
-class Isabelle_Sidekick(name: String, get_syntax: => Option[Outer_Syntax])
-  extends SideKickParser(name)
+class Isabelle_Sidekick(name: String) extends SideKickParser(name)
 {
+  override def supportsCompletion = false
+
+
   /* parsing */
 
   @volatile protected var stopped = false
@@ -68,7 +64,7 @@
 
   def parser(buffer: Buffer, syntax: Outer_Syntax, data: SideKickParsedData): Boolean = false
 
-  def parse(buffer: Buffer, error_source: DefaultErrorSource): SideKickParsedData =
+  def parse(buffer: Buffer, error_source: errorlist.DefaultErrorSource): SideKickParsedData =
   {
     stopped = false
 
@@ -77,7 +73,7 @@
     val root = data.root
     data.getAsset(root).setEnd(Isabelle_Sidekick.int_to_pos(buffer.getLength))
 
-    val syntax = get_syntax
+    val syntax = Isabelle.mode_syntax(name)
     val ok =
       if (syntax.isDefined) {
         val ok = parser(buffer, syntax.get, data)
@@ -89,65 +85,13 @@
 
     data
   }
-
-
-  /* completion */
-
-  override def supportsCompletion = true
-  override def canCompleteAnywhere = true
-
-  override def complete(pane: EditPane, caret: Text.Offset): SideKickCompletion =
-  {
-    Swing_Thread.assert()
-
-    val buffer = pane.getBuffer
-    JEdit_Lib.buffer_lock(buffer) {
-      get_syntax match {
-        case None => null
-        case Some(syntax) =>
-          val line = buffer.getLineOfOffset(caret)
-          val start = buffer.getLineStartOffset(line)
-          val text = buffer.getSegment(start, caret - start)
-
-          syntax.completion.complete(text) match {
-            case None => null
-            case Some((word, cs)) =>
-              val ds =
-                (if (Isabelle_Encoding.is_active(buffer))
-                  cs.map(Symbol.decode(_)).sorted
-                 else cs).filter(_ != word)
-              if (ds.isEmpty) null
-              else
-                new SideKickCompletion(pane.getView, word, ds.toArray.asInstanceOf[Array[Object]]) {
-                  override def getRenderer() =
-                    new ListCellRenderer[Any] {
-                      val default_renderer =
-                        (new DefaultListCellRenderer).asInstanceOf[ListCellRenderer[Any]]
-
-                      override def getListCellRendererComponent(
-                          list: JList[_ <: Any], value: Any, index: Int,
-                          selected: Boolean, focus: Boolean): Component =
-                      {
-                        val renderer: Component =
-                          default_renderer.getListCellRendererComponent(
-                            list, value, index, selected, focus)
-                        renderer.setFont(pane.getTextArea.getPainter.getFont)
-                        renderer
-                      }
-                    }
-                }
-          }
-      }
-    }
-  }
 }
 
 
 class Isabelle_Sidekick_Structure(
     name: String,
-    get_syntax: => Option[Outer_Syntax],
     node_name: Buffer => Option[Document.Node.Name])
-  extends Isabelle_Sidekick(name, get_syntax)
+  extends Isabelle_Sidekick(name)
 {
   import Thy_Syntax.Structure
 
@@ -186,22 +130,19 @@
 }
 
 
-class Isabelle_Sidekick_Default extends Isabelle_Sidekick_Structure(
-  "isabelle", PIDE.get_recent_syntax, PIDE.thy_load.buffer_node_name)
-{
-  override def supportsCompletion = false
-}
+class Isabelle_Sidekick_Default extends
+  Isabelle_Sidekick_Structure("isabelle", PIDE.thy_load.buffer_node_name)
 
 
-class Isabelle_Sidekick_Options extends Isabelle_Sidekick_Structure(
-  "isabelle-options", Some(Options.options_syntax), PIDE.thy_load.buffer_node_dummy)
+class Isabelle_Sidekick_Options extends
+  Isabelle_Sidekick_Structure("isabelle-options", PIDE.thy_load.buffer_node_dummy)
 
 
-class Isabelle_Sidekick_Root extends Isabelle_Sidekick_Structure(
-  "isabelle-root", Some(Build.root_syntax), PIDE.thy_load.buffer_node_dummy)
+class Isabelle_Sidekick_Root extends
+  Isabelle_Sidekick_Structure("isabelle-root", PIDE.thy_load.buffer_node_dummy)
 
 
-class Isabelle_Sidekick_Raw extends Isabelle_Sidekick("isabelle-raw", PIDE.get_recent_syntax)
+class Isabelle_Sidekick_Markup extends Isabelle_Sidekick("isabelle-markup")
 {
   override def parser(buffer: Buffer, syntax: Outer_Syntax, data: SideKickParsedData): Boolean =
   {
@@ -234,10 +175,10 @@
 }
 
 
-class Isabelle_Sidekick_News extends Isabelle_Sidekick("isabelle-news", Some(Outer_Syntax.empty))
+class Isabelle_Sidekick_News extends Isabelle_Sidekick("isabelle-news")
 {
-  private val Heading1 = new Regex("""^New in (.*)\w*$""")
-  private val Heading2 = new Regex("""^\*\*\*\w*(.*)\w*\*\*\*\w*$""")
+  private val Heading1 = """^New in (.*)\w*$""".r
+  private val Heading2 = """^\*\*\*\w*(.*)\w*\*\*\*\w*$""".r
 
   private def make_node(s: String, start: Text.Offset, stop: Text.Offset): DefaultMutableTreeNode =
     new DefaultMutableTreeNode(new Isabelle_Sidekick.Asset(s, start, stop))
@@ -260,7 +201,5 @@
 
     true
   }
-
-  override def supportsCompletion = false
 }
 
--- a/src/Tools/jEdit/src/jedit_lib.scala	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Tools/jEdit/src/jedit_lib.scala	Thu Aug 29 19:22:48 2013 +0200
@@ -131,6 +131,16 @@
   def buffer_text(buffer: JEditBuffer): String =
     buffer_lock(buffer) { buffer.getText(0, buffer.getLength) }
 
+  def buffer_mode(buffer: JEditBuffer): String =
+  {
+    val mode = buffer.getMode
+    if (mode == null) ""
+    else {
+      val name = mode.getName
+      if (name == null) "" else name
+    }
+  }
+
   def buffer_name(buffer: Buffer): String = buffer.getSymlinkPath
 
 
--- a/src/Tools/jEdit/src/plugin.scala	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Tools/jEdit/src/plugin.scala	Thu Aug 29 19:22:48 2013 +0200
@@ -43,13 +43,6 @@
   def thy_load(): JEdit_Thy_Load =
     session.thy_load.asInstanceOf[JEdit_Thy_Load]
 
-  def get_recent_syntax(): Option[Outer_Syntax] =
-  {
-    val current_session = session
-    if (current_session.recent_syntax == Outer_Syntax.empty) None
-    else Some(current_session.recent_syntax)
-  }
-
   lazy val editor = new JEdit_Editor
 
 
@@ -57,15 +50,21 @@
 
   def dismissed_popups(view: View): Boolean =
   {
-    val b1 = Completion_Popup.dismissed(view.getLayeredPane)
-    val b2 = Pretty_Tooltip.dismissed_all()
-    b1 || b2
+    var dismissed = false
+
+    JEdit_Lib.jedit_text_areas(view).foreach(text_area =>
+      if (Completion_Popup.Text_Area.dismissed(text_area)) dismissed = true)
+
+    if (Pretty_Tooltip.dismissed_all()) dismissed = true
+
+    dismissed
   }
 
 
   /* document model and view */
 
   def document_model(buffer: Buffer): Option[Document_Model] = Document_Model(buffer)
+
   def document_view(text_area: JEditTextArea): Option[Document_View] = Document_View(text_area)
 
   def document_views(buffer: Buffer): List[Document_View] =
@@ -278,6 +277,12 @@
               PIDE.dismissed_popups(text_area.getView)
               PIDE.exit_view(buffer, text_area)
             }
+
+            if (msg.getWhat == EditPaneUpdate.CREATED)
+              Completion_Popup.Text_Area.init(text_area)
+
+            if (msg.getWhat == EditPaneUpdate.DESTROYED)
+              Completion_Popup.Text_Area.exit(text_area)
           }
 
         case msg: PropertiesChanged =>
@@ -307,6 +312,8 @@
       if (ModeProvider.instance.isInstanceOf[ModeProvider])
         ModeProvider.instance = new Token_Markup.Mode_Provider(ModeProvider.instance)
 
+      JEdit_Lib.jedit_text_areas.foreach(Completion_Popup.Text_Area.init _)
+
       val content = Isabelle_Logic.session_content(false)
       val thy_load = new JEdit_Thy_Load(content.loaded_theories, content.syntax)
 
@@ -327,6 +334,8 @@
 
   override def stop()
   {
+    JEdit_Lib.jedit_text_areas.foreach(Completion_Popup.Text_Area.exit _)
+
     if (PIDE.startup_failure.isEmpty)
       PIDE.options.value.save_prefs()
 
--- a/src/Tools/jEdit/src/pretty_text_area.scala	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Tools/jEdit/src/pretty_text_area.scala	Thu Aug 29 19:22:48 2013 +0200
@@ -196,7 +196,7 @@
   getPainter.setStructureHighlightEnabled(false)
   getPainter.setLineHighlightEnabled(false)
 
-  getBuffer.setTokenMarker(new Token_Markup.Marker(true, None))
+  getBuffer.setTokenMarker(Isabelle.token_marker("isabelle-output").get)
   getBuffer.setReadOnly(true)
   getBuffer.setStringProperty("noWordSep", "_'.?")
 
--- a/src/Tools/jEdit/src/rendering.scala	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Tools/jEdit/src/rendering.scala	Thu Aug 29 19:22:48 2013 +0200
@@ -14,7 +14,7 @@
 import javax.swing.Icon
 
 import org.gjt.sp.jedit.syntax.{Token => JEditToken}
-import org.gjt.sp.jedit.jEdit
+import org.gjt.sp.jedit.{jEdit, View}
 
 import scala.collection.immutable.SortedMap
 
@@ -45,8 +45,21 @@
 
   def font_family(): String = jEdit.getProperty("view.font")
 
+  private def view_font_size(): Int = jEdit.getIntegerProperty("view.fontsize", 16)
+  private val font_size0 = 5
+  private val font_size1 = 250
+
   def font_size(scale: String): Float =
-    (jEdit.getIntegerProperty("view.fontsize", 16) * PIDE.options.real(scale)).toFloat
+    (view_font_size() * PIDE.options.real(scale)).toFloat max font_size0 min font_size1
+
+  def font_size_change(view: View, change: Int => Int)
+  {
+    val size = change(view_font_size()) max font_size0 min font_size1
+    jEdit.setIntegerProperty("view.fontsize", size)
+    jEdit.propertiesChanged()
+    jEdit.saveSettings()
+    view.getStatus.setMessageAndClear("Text font size: " + size)
+  }
 
 
   /* popup window bounds */
--- a/src/Tools/jEdit/src/services.xml	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Tools/jEdit/src/services.xml	Thu Aug 29 19:22:48 2013 +0200
@@ -8,6 +8,9 @@
 	<SERVICE NAME="isabelle" CLASS="sidekick.SideKickParser">
 		new isabelle.jedit.Isabelle_Sidekick_Default();
 	</SERVICE>
+	<SERVICE NAME="isabelle-markup" CLASS="sidekick.SideKickParser">
+		new isabelle.jedit.Isabelle_Sidekick_Markup();
+	</SERVICE>
 	<SERVICE NAME="isabelle-news" CLASS="sidekick.SideKickParser">
 		new isabelle.jedit.Isabelle_Sidekick_News();
 	</SERVICE>
@@ -17,9 +20,6 @@
 	<SERVICE NAME="isabelle-root" CLASS="sidekick.SideKickParser">
 		new isabelle.jedit.Isabelle_Sidekick_Root();
 	</SERVICE>
-	<SERVICE NAME="isabelle-raw" CLASS="sidekick.SideKickParser">
-		new isabelle.jedit.Isabelle_Sidekick_Raw();
-	</SERVICE>
  	<SERVICE CLASS="console.Shell" NAME="Scala">
 		new isabelle.jedit.Scala_Console();
 	</SERVICE>
--- a/src/Tools/jEdit/src/token_markup.scala	Thu Aug 29 18:44:03 2013 +0200
+++ b/src/Tools/jEdit/src/token_markup.scala	Thu Aug 29 19:22:48 2013 +0200
@@ -206,7 +206,7 @@
       }
   }
 
-  class Marker(ext_styles: Boolean, get_syntax: => Option[Outer_Syntax]) extends TokenMarker
+  class Marker(mode: String) extends TokenMarker
   {
     override def markTokens(context: TokenMarker.LineContext,
         handler: TokenHandler, raw_line: Segment): TokenMarker.LineContext =
@@ -220,21 +220,18 @@
 
       val context1 =
       {
-        val syntax = get_syntax
         val (styled_tokens, context1) =
-          if (line_ctxt.isDefined && syntax.isDefined) {
-            val (tokens, ctxt1) = syntax.get.scan_context(line, line_ctxt.get)
-            val styled_tokens = tokens.map(tok => (Rendering.token_markup(syntax.get, tok), tok))
-            (styled_tokens, new Line_Context(Some(ctxt1)))
-          }
-          else {
-            val token = Token(Token.Kind.UNPARSED, line.subSequence(0, line.count).toString)
-            (List((JEditToken.NULL, token)), new Line_Context(None))
+          Isabelle.mode_syntax(mode) match {
+            case Some(syntax) if syntax.has_tokens && line_ctxt.isDefined =>
+              val (tokens, ctxt1) = syntax.scan_context(line, line_ctxt.get)
+              val styled_tokens = tokens.map(tok => (Rendering.token_markup(syntax, tok), tok))
+              (styled_tokens, new Line_Context(Some(ctxt1)))
+            case _ =>
+              val token = Token(Token.Kind.UNPARSED, line.subSequence(0, line.count).toString)
+              (List((JEditToken.NULL, token)), new Line_Context(None))
           }
 
-        val extended =
-          if (ext_styles) extended_styles(line)
-          else Map.empty[Text.Offset, Byte => Byte]
+        val extended = extended_styles(line)
 
         var offset = 0
         for ((style, token) <- styled_tokens) {
@@ -266,11 +263,6 @@
 
   /* mode provider */
 
-  private val markers = Map(
-    "isabelle" -> new Token_Markup.Marker(true, PIDE.get_recent_syntax()),
-    "isabelle-options" -> new Token_Markup.Marker(false, Some(Options.options_syntax)),
-    "isabelle-root" -> new Token_Markup.Marker(false, Some(Build.root_syntax)))
-
   class Mode_Provider(orig_provider: ModeProvider) extends ModeProvider
   {
     for (mode <- orig_provider.getModes) addMode(mode)
@@ -278,18 +270,18 @@
     override def loadMode(mode: Mode, xmh: XModeHandler)
     {
       super.loadMode(mode, xmh)
-      markers.get(mode.getName).map(mode.setTokenMarker(_))
+      Isabelle.token_marker(mode.getName).foreach(mode.setTokenMarker _)
     }
   }
 
   def refresh_buffer(buffer: JEditBuffer)
   {
-    buffer.setTokenMarker(jEdit.getMode("text").getTokenMarker)
-    // FIXME potential NPE ahead!?!
-    val mode = buffer.getMode
-    val name = mode.getName
-    val marker = markers.get(name)
-    marker.map(buffer.setTokenMarker(_))
+    Isabelle.token_marker(JEdit_Lib.buffer_mode(buffer)) match {
+      case None =>
+      case Some(marker) =>
+        buffer.setTokenMarker(jEdit.getMode("text").getTokenMarker)
+        buffer.setTokenMarker(marker)
+    }
   }
 }