merged
authorwenzelm
Fri, 24 Jan 2025 10:22:17 +0100
changeset 81963 e3a8379a9884
parent 81902 7d711d3f37bf (diff)
parent 81962 e506e636c724 (current diff)
child 81964 8efec8da78f9
merged
NEWS
--- a/Admin/components/components.sha1	Thu Jan 23 22:29:38 2025 +0100
+++ b/Admin/components/components.sha1	Fri Jan 24 10:22:17 2025 +0100
@@ -187,6 +187,7 @@
 cd92c141883f0f6a18adceb885316c8b6119e648 isabelle_setup-20240327.tar.gz
 f23037b322b968c61350f9ec9995a4f397e6c71c javamail-1.4.7.tar.gz
 18e6b60ceb98e327fbf14e52f4613dd5b0483d2f javamail-20240109.tar.gz
+dc826bc0d715cd4190d1bb2e7122321eea5355de javamail-20250122.tar.gz
 0b2206f914336dec4923dd0479d8cee4b904f544 jdk-11+28.tar.gz
 e12574d838ed55ef2845acf1152329572ab0cc56 jdk-11.0.10+9.tar.gz
 3e05213cad47dbef52804fe329395db9b4e57f39 jdk-11.0.2+9.tar.gz
--- a/Admin/components/main	Thu Jan 23 22:29:38 2025 +0100
+++ b/Admin/components/main	Fri Jan 24 10:22:17 2025 +0100
@@ -13,7 +13,7 @@
 idea-icons-20210508
 isabelle_fonts-20241227
 isabelle_setup-20240327
-javamail-20240109
+javamail-20250122
 jdk-21.0.5
 jedit-20241115
 jfreechart-1.5.3
--- a/NEWS	Thu Jan 23 22:29:38 2025 +0100
+++ b/NEWS	Fri Jan 24 10:22:17 2025 +0100
@@ -365,7 +365,7 @@
 
     isabelle find_facts_index HOL
     isabelle find_facts_server
-    open http://localhost:8080/app#search?q=Hilbert
+    open http://localhost:8080/find_facts#search?q=Hilbert
 
 Persistent data is stored in $ISABELLE_HOME_USER/find_facts/.
 
--- a/src/HOL/Bit_Operations.thy	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/HOL/Bit_Operations.thy	Fri Jan 24 10:22:17 2025 +0100
@@ -132,6 +132,17 @@
   using div_mult_mod_eq [of \<open>1 + a\<close> \<open>2 ^ n\<close>] div_mult_mod_eq [of a \<open>2 ^ n\<close>] that
   by simp (metis (full_types) add.left_commute add_left_imp_eq)
 
+lemma half_numeral_Bit1_eq [simp]:
+  \<open>numeral (num.Bit1 m) div 2 = numeral (num.Bit0 m) div 2\<close>
+  using even_half_succ_eq [of \<open>2 * numeral m\<close>]
+  by simp
+
+lemma double_half_numeral_Bit_0_eq [simp]:
+  \<open>2 * (numeral (num.Bit0 m) div 2) = numeral (num.Bit0 m)\<close>
+  \<open>(numeral (num.Bit0 m) div 2) * 2 = numeral (num.Bit0 m)\<close>
+  using mod_mult_div_eq [of \<open>numeral (Num.Bit0 m)\<close> 2]
+  by (simp_all add: mod2_eq_if ac_simps)
+
 named_theorems bit_simps \<open>Simplification rules for \<^const>\<open>bit\<close>\<close>
 
 definition possible_bit :: \<open>'a itself \<Rightarrow> nat \<Rightarrow> bool\<close>
@@ -1195,7 +1206,7 @@
     by (cases n) (auto simp: bit_0 bit_double_iff even_bit_succ_iff)
 qed
 
-lemma set_bit_0 [simp]:
+lemma set_bit_0:
   \<open>set_bit 0 a = 1 + 2 * (a div 2)\<close>
   by (auto simp: bit_eq_iff bit_simps even_bit_succ_iff simp flip: bit_Suc)
 
@@ -1204,7 +1215,7 @@
   by (auto simp: bit_eq_iff bit_sum_mult_2_cases bit_simps bit_0 simp flip: bit_Suc
     elim: possible_bit_less_imp)
 
-lemma unset_bit_0 [simp]:
+lemma unset_bit_0:
   \<open>unset_bit 0 a = 2 * (a div 2)\<close>
   by (auto simp: bit_eq_iff bit_simps simp flip: bit_Suc)
 
@@ -1212,7 +1223,7 @@
   \<open>unset_bit (Suc n) a = a mod 2 + 2 * unset_bit n (a div 2)\<close>
   by (auto simp: bit_eq_iff bit_sum_mult_2_cases bit_simps bit_0 simp flip: bit_Suc)
 
-lemma flip_bit_0 [simp]:
+lemma flip_bit_0:
   \<open>flip_bit 0 a = of_bool (even a) + 2 * (a div 2)\<close>
   by (auto simp: bit_eq_iff bit_simps even_bit_succ_iff bit_0 simp flip: bit_Suc)
 
@@ -1557,7 +1568,7 @@
 
 lemma drop_bit_Suc_bit1 [simp]:
   \<open>drop_bit (Suc n) (numeral (Num.Bit1 k)) = drop_bit n (numeral k)\<close>
-  by (simp add: drop_bit_Suc numeral_Bit1_div_2)
+  by (simp add: drop_bit_Suc numeral_Bit0_div_2)
 
 lemma drop_bit_numeral_bit0 [simp]:
   \<open>drop_bit (numeral l) (numeral (Num.Bit0 k)) = drop_bit (pred_numeral l) (numeral k)\<close>
@@ -1565,7 +1576,7 @@
 
 lemma drop_bit_numeral_bit1 [simp]:
   \<open>drop_bit (numeral l) (numeral (Num.Bit1 k)) = drop_bit (pred_numeral l) (numeral k)\<close>
-  by (simp add: drop_bit_rec numeral_Bit1_div_2)
+  by (simp add: drop_bit_rec numeral_Bit0_div_2)
 
 lemma take_bit_Suc_1 [simp]:
   \<open>take_bit (Suc n) 1 = 1\<close>
@@ -1577,7 +1588,7 @@
 
 lemma take_bit_Suc_bit1:
   \<open>take_bit (Suc n) (numeral (Num.Bit1 k)) = take_bit n (numeral k) * 2 + 1\<close>
-  by (simp add: take_bit_Suc numeral_Bit1_div_2 mod_2_eq_odd)
+  by (simp add: take_bit_Suc numeral_Bit0_div_2 mod_2_eq_odd)
 
 lemma take_bit_numeral_1 [simp]:
   \<open>take_bit (numeral l) 1 = 1\<close>
@@ -1589,7 +1600,7 @@
 
 lemma take_bit_numeral_bit1:
   \<open>take_bit (numeral l) (numeral (Num.Bit1 k)) = take_bit (pred_numeral l) (numeral k) * 2 + 1\<close>
-  by (simp add: take_bit_rec numeral_Bit1_div_2 mod_2_eq_odd)
+  by (simp add: take_bit_rec numeral_Bit0_div_2 mod_2_eq_odd)
 
 lemma bit_of_nat_iff_bit [bit_simps]:
   \<open>bit (of_nat m) n \<longleftrightarrow> bit m n\<close>
@@ -2600,7 +2611,7 @@
 lemma [code]:
   \<open>unset_bit 0 m = 2 * (m div 2)\<close>
   \<open>unset_bit (Suc n) m = m mod 2 + 2 * unset_bit n (m div 2)\<close> for m n :: nat
-  by (simp_all add: unset_bit_Suc)
+  by (simp_all add: unset_bit_0 unset_bit_Suc)
 
 lemma push_bit_of_Suc_0 [simp]:
   \<open>push_bit n (Suc 0) = 2 ^ n\<close>
@@ -2778,7 +2789,7 @@
 
 lemma bit_numeral_Bit1_Suc_iff [simp]:
   \<open>bit (numeral (Num.Bit1 m)) (Suc n) \<longleftrightarrow> bit (numeral m) n\<close>
-  by (simp add: bit_Suc numeral_Bit1_div_2)
+  by (simp add: bit_Suc numeral_Bit0_div_2)
 
 lemma bit_numeral_rec:
   \<open>bit (numeral (Num.Bit0 w)) n \<longleftrightarrow> (case n of 0 \<Rightarrow> False | Suc m \<Rightarrow> bit (numeral w) m)\<close>
@@ -3278,6 +3289,86 @@
 
 end
 
+context semiring_bit_operations
+begin
+
+lemma push_bit_eq_pow:
+  \<open>push_bit (numeral n) 1 = numeral (Num.pow (Num.Bit0 Num.One) n)\<close>
+  by simp
+
+lemma set_bit_of_0 [simp]:
+  \<open>set_bit n 0 = 2 ^ n\<close>
+  by (simp add: set_bit_eq_or)
+
+lemma unset_bit_of_0 [simp]:
+  \<open>unset_bit n 0 = 0\<close>
+  by (simp add: unset_bit_eq_or_xor)
+
+lemma flip_bit_of_0 [simp]:
+  \<open>flip_bit n 0 = 2 ^ n\<close>
+  by (simp add: flip_bit_eq_xor)
+
+lemma set_bit_0_numeral_eq [simp]:
+  \<open>set_bit 0 (numeral Num.One) = 1\<close>
+  \<open>set_bit 0 (numeral (Num.Bit0 m)) = numeral (Num.Bit1 m)\<close>
+  \<open>set_bit 0 (numeral (Num.Bit1 m)) = numeral (Num.Bit1 m)\<close>
+  by (simp_all add: set_bit_0)
+
+lemma set_bit_numeral_eq_or [simp]:
+  \<open>set_bit (numeral n) (numeral m) = numeral m OR push_bit (numeral n) 1\<close>
+  by (fact set_bit_eq_or)
+
+lemma unset_bit_0_numeral_eq_and_not' [simp]:
+  \<open>unset_bit 0 (numeral Num.One) = 0\<close>
+  \<open>unset_bit 0 (numeral (Num.Bit0 m)) = numeral (Num.Bit0 m)\<close>
+  \<open>unset_bit 0 (numeral (Num.Bit1 m)) = numeral (Num.Bit0 m)\<close>
+  by (simp_all add: unset_bit_0)
+
+lemma unset_bit_numeral_eq_or [simp]:
+  \<open>unset_bit (numeral n) (numeral m) =
+    (case and_not_num m (Num.pow (Num.Bit0 Num.One) n)
+     of None \<Rightarrow> 0
+      | Some q \<Rightarrow> numeral q)\<close> (is \<open>?lhs = _\<close>)
+proof -
+  have \<open>?lhs = of_nat (unset_bit (numeral n) (numeral m))\<close>
+    by (simp add: of_nat_unset_bit_eq)
+  also have \<open>unset_bit (numeral n) (numeral m) = nat (unset_bit (numeral n) (numeral m))\<close>
+    by (simp flip: int_int_eq add: Bit_Operations.of_nat_unset_bit_eq)
+  finally have *: \<open>?lhs = of_nat (nat (unset_bit (numeral n) (numeral m)))\<close> .
+  show ?thesis
+    by (simp only: * unset_bit_eq_and_not Bit_Operations.push_bit_eq_pow int_numeral_and_not_num)
+      (auto split: option.splits)
+qed
+
+lemma flip_bit_0_numeral_eq_or [simp]:
+  \<open>flip_bit 0 (numeral Num.One) = 0\<close>
+  \<open>flip_bit 0 (numeral (Num.Bit0 m)) = numeral (Num.Bit1 m)\<close>
+  \<open>flip_bit 0 (numeral (Num.Bit1 m)) = numeral (Num.Bit0 m)\<close>
+  by (simp_all add: flip_bit_0)
+
+lemma flip_bit_numeral_eq_xor [simp]:
+  \<open>flip_bit (numeral n) (numeral m) = numeral m XOR push_bit (numeral n) 1\<close>
+  by (fact flip_bit_eq_xor)
+
+end
+
+context ring_bit_operations
+begin
+
+lemma set_bit_minus_numeral_eq_or [simp]:
+  \<open>set_bit (numeral n) (- numeral m) = - numeral m OR push_bit (numeral n) 1\<close>
+  by (fact set_bit_eq_or)
+
+lemma unset_bit_minus_numeral_eq_and_not [simp]:
+  \<open>unset_bit (numeral n) (- numeral m) = - numeral m AND NOT (push_bit (numeral n) 1)\<close>
+  by (fact unset_bit_eq_and_not)
+
+lemma flip_bit_minus_numeral_eq_xor [simp]:
+  \<open>flip_bit (numeral n) (- numeral m) = - numeral m XOR push_bit (numeral n) 1\<close>
+  by (fact flip_bit_eq_xor)
+
+end
+
 lemma xor_int_code [code]:
   fixes i j :: int shows
   \<open>0 XOR j = j\<close>
--- a/src/HOL/Complex_Analysis/Cauchy_Integral_Formula.thy	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/HOL/Complex_Analysis/Cauchy_Integral_Formula.thy	Fri Jan 24 10:22:17 2025 +0100
@@ -10,13 +10,13 @@
         and fcd: "(\<And>x. x \<in> interior S - k \<Longrightarrow> f field_differentiable at x)"
         and z: "z \<in> interior S - k" and vpg: "valid_path \<gamma>"
         and pasz: "path_image \<gamma> \<subseteq> S - {z}" and loop: "pathfinish \<gamma> = pathstart \<gamma>"
-      shows "((\<lambda>w. f w / (w - z)) has_contour_integral (2*pi * \<i> * winding_number \<gamma> z * f z)) \<gamma>"
+      shows "((\<lambda>w. f w / (w-z)) has_contour_integral (2*pi * \<i> * winding_number \<gamma> z * f z)) \<gamma>"
 proof -
-  let ?fz = "\<lambda>w. (f w - f z)/(w - z)"
+  let ?fz = "\<lambda>w. (f w - f z)/(w-z)"
   obtain f' where f': "(f has_field_derivative f') (at z)"
     using fcd [OF z] by (auto simp: field_differentiable_def)
   have pas: "path_image \<gamma> \<subseteq> S" and znotin: "z \<notin> path_image \<gamma>" using pasz by blast+
-  have c: "continuous (at x within S) (\<lambda>w. if w = z then f' else (f w - f z) / (w - z))" if "x \<in> S" for x
+  have c: "continuous (at x within S) (\<lambda>w. if w = z then f' else (f w - f z) / (w-z))" if "x \<in> S" for x
   proof (cases "x = z")
     case True then show ?thesis
       using LIM_equal [of "z" ?fz "\<lambda>w. if w = z then f' else ?fz w"] has_field_derivativeD [OF f'] 
@@ -26,7 +26,7 @@
     then have dxz: "dist x z > 0" by auto
     have cf: "continuous (at x within S) f"
       using conf continuous_on_eq_continuous_within that by blast
-    have "continuous (at x within S) (\<lambda>w. (f w - f z) / (w - z))"
+    have "continuous (at x within S) (\<lambda>w. (f w - f z) / (w-z))"
       by (rule cf continuous_intros | simp add: False)+
     then show ?thesis
       using continuous_transform_within [OF _ dxz that] by (force simp: dist_commute)
@@ -41,17 +41,17 @@
         using that by (intro derivative_intros fcd; simp)
     qed (use that in \<open>auto simp add: dist_pos_lt dist_commute\<close>)
   qed (use c in \<open>force simp: continuous_on_eq_continuous_within\<close>)
+  note ** = has_contour_integral_add [OF has_contour_integral_lmul [OF has_contour_integral_winding_number [OF vpg znotin], of "f z"] *]
   show ?thesis
     apply (rule has_contour_integral_eq)
-    using znotin has_contour_integral_add [OF has_contour_integral_lmul [OF has_contour_integral_winding_number [OF vpg znotin], of "f z"] *]
-    apply (auto simp: ac_simps divide_simps)
+    using znotin ** apply (auto simp: ac_simps divide_simps)
     done
 qed
 
 theorem Cauchy_integral_formula_convex_simple:
   assumes "convex S" and holf: "f holomorphic_on S" and "z \<in> interior S" "valid_path \<gamma>" "path_image \<gamma> \<subseteq> S - {z}"
       "pathfinish \<gamma> = pathstart \<gamma>"
-    shows "((\<lambda>w. f w / (w - z)) has_contour_integral (2*pi * \<i> * winding_number \<gamma> z * f z)) \<gamma>"
+    shows "((\<lambda>w. f w / (w-z)) has_contour_integral (2*pi * \<i> * winding_number \<gamma> z * f z)) \<gamma>"
 proof -
   have "\<And>x. x \<in> interior S \<Longrightarrow> f field_differentiable at x"
     using holf at_within_interior holomorphic_onD interior_subset by fastforce
@@ -63,13 +63,13 @@
 text\<open> Hence the Cauchy formula for points inside a circle.\<close>
 
 theorem Cauchy_integral_circlepath:
-  assumes contf: "continuous_on (cball z r) f" and holf: "f holomorphic_on (ball z r)" and wz: "norm(w - z) < r"
-  shows "((\<lambda>u. f u/(u - w)) has_contour_integral (2 * of_real pi * \<i> * f w))
+  assumes contf: "continuous_on (cball z r) f" and holf: "f holomorphic_on (ball z r)" and wz: "norm(w-z) < r"
+  shows "((\<lambda>u. f u/(u-w)) has_contour_integral (2 * of_real pi * \<i> * f w))
          (circlepath z r)"
 proof -
   have "r > 0"
     using assms le_less_trans norm_ge_zero by blast
-  have "((\<lambda>u. f u / (u - w)) has_contour_integral (2 * pi) * \<i> * winding_number (circlepath z r) w * f w)
+  have "((\<lambda>u. f u / (u-w)) has_contour_integral (2 * pi) * \<i> * winding_number (circlepath z r) w * f w)
         (circlepath z r)"
   proof (rule Cauchy_integral_formula_weak [where S = "cball z r" and k = "{}"])
     show "\<And>x. x \<in> interior (cball z r) - {} \<Longrightarrow>
@@ -85,32 +85,33 @@
 qed
 
 corollary\<^marker>\<open>tag unimportant\<close> Cauchy_integral_circlepath_simple:
-  assumes "f holomorphic_on cball z r" "norm(w - z) < r"
-  shows "((\<lambda>u. f u/(u - w)) has_contour_integral (2 * of_real pi * \<i> * f w))
+  assumes "f holomorphic_on cball z r" "norm(w-z) < r"
+  shows "((\<lambda>u. f u/(u-w)) has_contour_integral (2 * of_real pi * \<i> * f w))
          (circlepath z r)"
 using assms by (force simp: holomorphic_on_imp_continuous_on holomorphic_on_subset Cauchy_integral_circlepath)
 
 subsection\<^marker>\<open>tag unimportant\<close> \<open>General stepping result for derivative formulas\<close>
 
 lemma Cauchy_next_derivative:
+  fixes f' :: "complex \<Rightarrow> complex"
+  defines "h \<equiv> \<lambda>k w u. f' u / (u-w)^k"
   assumes "continuous_on (path_image \<gamma>) f'"
       and leB: "\<And>t. t \<in> {0..1} \<Longrightarrow> norm (vector_derivative \<gamma> (at t)) \<le> B"
-      and int: "\<And>w. w \<in> S - path_image \<gamma> \<Longrightarrow> ((\<lambda>u. f' u / (u - w)^k) has_contour_integral f w) \<gamma>"
+      and int: "\<And>w. w \<in> S - path_image \<gamma> \<Longrightarrow> (h k w has_contour_integral f w) \<gamma>"
       and k: "k \<noteq> 0"
       and "open S"
       and \<gamma>: "valid_path \<gamma>"
       and w: "w \<in> S - path_image \<gamma>"
-    shows "(\<lambda>u. f' u / (u - w)^(Suc k)) contour_integrable_on \<gamma>"
-      and "(f has_field_derivative (k * contour_integral \<gamma> (\<lambda>u. f' u/(u - w)^(Suc k))))
-           (at w)"  (is "?thes2")
+    shows "h (Suc k) w contour_integrable_on \<gamma>"
+      and "(f has_field_derivative (k * contour_integral \<gamma> (h (Suc k) w))) (at w)"  (is "?thes2")
 proof -
   have "open (S - path_image \<gamma>)" using \<open>open S\<close> closed_valid_path_image \<gamma> by blast
   then obtain d where "d>0" and d: "ball w d \<subseteq> S - path_image \<gamma>" using w
     using open_contains_ball by blast
   have [simp]: "\<And>n. cmod (1 + of_nat n) = 1 + of_nat n"
     by (metis norm_of_nat of_nat_Suc)
-  have cint: "(\<lambda>z. (f' z / (z - x) ^ k - f' z / (z - w) ^ k) / (x * k - w * k)) contour_integrable_on \<gamma>"
-    if "x \<noteq> w" "cmod (x - w) < d" for x
+  have cint: "(\<lambda>z. (h k x z - h k w z) / (x * k - w * k)) contour_integrable_on \<gamma>"
+    if "x \<noteq> w" "cmod (x-w) < d" for x::complex
   proof -
     have "x \<in> S - path_image \<gamma>"
       by (metis d dist_commute dist_norm mem_ball subsetD that(2))
@@ -118,31 +119,29 @@
       using contour_integrable_diff contour_integrable_div contour_integrable_on_def int w
       by meson
   qed
-  have 1: "\<forall>\<^sub>F n in at w. (\<lambda>x. f' x * (inverse (x - n) ^ k - inverse (x - w) ^ k) / (n - w) / of_nat k)
+  then have 1: "\<forall>\<^sub>F x in at w. (\<lambda>z. (h k x z - h k w z) / (x-w) / of_nat k)
                          contour_integrable_on \<gamma>"
-    unfolding eventually_at
-    apply (rule_tac x=d in exI)
-    apply (simp add: \<open>d > 0\<close> dist_norm field_simps cint)
-    done
+    unfolding eventually_at 
+    by (force intro: exI [where x=d] simp add: \<open>d > 0\<close> dist_norm field_simps)
   have bim_g: "bounded (image f' (path_image \<gamma>))"
     by (simp add: compact_imp_bounded compact_continuous_image compact_valid_path_image assms)
   then obtain C where "C > 0" and C: "\<And>x. \<lbrakk>0 \<le> x; x \<le> 1\<rbrakk> \<Longrightarrow> cmod (f' (\<gamma> x)) \<le> C"
     by (force simp: bounded_pos path_image_def)
   have twom: "\<forall>\<^sub>F n in at w.
                \<forall>x\<in>path_image \<gamma>.
-                cmod ((inverse (x - n) ^ k - inverse (x - w) ^ k) / (n - w) / k - inverse (x - w) ^ Suc k) < e"
+                cmod ((inverse (x-n) ^ k - inverse (x-w) ^ k) / (n-w) / k - inverse (x-w) ^ Suc k) < e"
          if "0 < e" for e
   proof -
-    have *: "cmod ((inverse (x - u) ^ k - inverse (x - w) ^ k) / ((u - w) * k) - inverse (x - w) ^ Suc k)   < e"
-            if x: "x \<in> path_image \<gamma>" and "u \<noteq> w" and uwd: "cmod (u - w) < d/2"
-                and uw_less: "cmod (u - w) < e * (d/2) ^ (k+2) / (1 + real k)"
+    have *: "cmod ((inverse (x-u) ^ k - inverse (x-w) ^ k) / ((u-w) * k) - inverse (x-w) ^ Suc k) < e"
+            if x: "x \<in> path_image \<gamma>" and "u \<noteq> w" and uwd: "cmod (u-w) < d/2"
+                and uw_less: "cmod (u-w) < e * (d/2) ^ (k+2) / (1 + real k)"
             for u x
     proof -
       define ff where [abs_def]:
         "ff n w =
-          (if n = 0 then inverse(x - w)^k
-           else if n = 1 then k / (x - w)^(Suc k)
-           else (k * of_real(Suc k)) / (x - w)^(k + 2))" for n :: nat and w
+          (if n = 0 then inverse(x-w)^k
+           else if n = 1 then k / (x-w)^(Suc k)
+           else (k * of_real(Suc k)) / (x-w)^(k + 2))" for n :: nat and w
       have km1: "\<And>z::complex. z \<noteq> 0 \<Longrightarrow> z ^ (k - Suc 0) = z ^ k / z"
         by (simp add: field_simps) (metis Suc_pred \<open>k \<noteq> 0\<close> neq0_conv power_Suc)
       have ff1: "(ff i has_field_derivative ff (Suc i) z) (at z within ball w (d/2))"
@@ -157,7 +156,7 @@
         then have neqq: "\<And>v. v \<noteq> 0 \<Longrightarrow> x * (x * v) + z * (z * v) \<noteq> x * (z * (2 * v))"
           by (simp add: algebra_simps)
         show ?thesis using \<open>i \<le> 1\<close>
-          apply (simp add: ff_def dist_norm Nat.le_Suc_eq km1, safe)
+          apply (simp add: ff_def dist_norm Nat.le_Suc_eq, safe)
           apply (rule derivative_eq_intros | simp add: km1 | simp add: field_simps neq neqq)+
           done
       qed
@@ -173,12 +172,12 @@
       proof -
         have lessd: "\<And>z. cmod (\<gamma> z - v) < d/2 \<Longrightarrow> cmod (w - \<gamma> z) < d"
           by (metis that norm_minus_commute norm_triangle_half_r dist_norm mem_ball)
-        have "d/2 \<le> cmod (x - v)" using d x that
-          using lessd d x
-          by (auto simp add: dist_norm path_image_def ball_def not_less [symmetric] del: divide_const_simps)
-        then have "d \<le> cmod (x - v) * 2"
+        have "d/2 \<le> cmod (x-v)" using d x that
+          using lessd d x unfolding path_image_def
+          by (smt (verit, best) dist_norm imageE insert_Diff mem_ball subset_Diff_insert)
+        then have "d \<le> cmod (x-v) * 2"
           by (simp add: field_split_simps)
-        then have dpow_le: "d ^ (k+2) \<le> (cmod (x - v) * 2) ^ (k+2)"
+        then have dpow_le: "d ^ (k+2) \<le> (cmod (x-v) * 2) ^ (k+2)"
           using \<open>0 < d\<close> order_less_imp_le power_mono by blast
         have "x \<noteq> v" using that
           using \<open>x \<in> path_image \<gamma>\<close> ball_divide_subset_numeral d by fastforce
@@ -189,29 +188,27 @@
       qed
       have ub: "u \<in> ball w (d/2)"
         using uwd by (simp add: dist_commute dist_norm)
-      have "cmod (inverse (x - u) ^ k - (inverse (x - w) ^ k + of_nat k * (u - w) / ((x - w) * (x - w) ^ k)))
-                  \<le> (real k * 4 + real k * real k * 4) * (cmod (u - w) * cmod (u - w)) / (d * (d * (d/2) ^ k))"
+      have "cmod (inverse (x-u) ^ k - (inverse (x-w) ^ k + of_nat k * (u-w) / ((x-w) * (x-w) ^ k)))
+                  \<le> (real k * 4 + real k * real k * 4) * (cmod (u-w) * cmod (u-w)) / (d * (d * (d/2) ^ k))"
         using complex_Taylor [OF _ ff1 ff2 _ ub, of w, simplified]
         by (simp add: ff_def \<open>0 < d\<close>)
-      then have "cmod (inverse (x - u) ^ k - (inverse (x - w) ^ k + of_nat k * (u - w) / ((x - w) * (x - w) ^ k)))
-                  \<le> (cmod (u - w) * real k) * (1 + real k) * cmod (u - w) / (d/2) ^ (k+2)"
+      then have "cmod (inverse (x-u) ^ k - (inverse (x-w) ^ k + of_nat k * (u-w) / ((x-w) * (x-w) ^ k)))
+                  \<le> (cmod (u-w) * real k) * (1 + real k) * cmod (u-w) / (d/2) ^ (k+2)"
         by (simp add: field_simps)
-      then have "cmod (inverse (x - u) ^ k - (inverse (x - w) ^ k + of_nat k * (u - w) / ((x - w) * (x - w) ^ k)))
-                 / (cmod (u - w) * real k)
-                  \<le> (1 + real k) * cmod (u - w) / (d/2) ^ (k+2)"
+      then have "cmod (inverse (x-u) ^ k - (inverse (x-w) ^ k + of_nat k * (u-w) / ((x-w) * (x-w) ^ k)))
+                 / (cmod (u-w) * real k)
+                  \<le> (1 + real k) * cmod (u-w) / (d/2) ^ (k+2)"
         using \<open>k \<noteq> 0\<close> \<open>u \<noteq> w\<close> by (simp add: mult_ac zero_less_mult_iff pos_divide_le_eq)
       also have "\<dots> < e"
         using uw_less \<open>0 < d\<close> by (simp add: mult_ac divide_simps)
       finally have e: "cmod (inverse (x-u)^k - (inverse (x-w)^k + of_nat k * (u-w) / ((x-w) * (x-w)^k)))
-                        / cmod ((u - w) * real k)   <   e"
+                        / cmod ((u-w) * real k)   <   e"
         by (simp add: norm_mult)
       have "x \<noteq> u"
         using uwd \<open>0 < d\<close> x d by (force simp: dist_norm ball_def norm_minus_commute)
       show ?thesis
-        apply (rule le_less_trans [OF _ e])
-        using \<open>k \<noteq> 0\<close> \<open>x \<noteq> u\<close> \<open>u \<noteq> w\<close>
-        apply (simp add: field_simps norm_divide [symmetric])
-        done
+        using \<open>k \<noteq> 0\<close> \<open>x \<noteq> u\<close> \<open>u \<noteq> w\<close> le_less_trans [OF _ e]
+        by (simp add: field_simps flip: norm_divide)
     qed
     show ?thesis
       unfolding eventually_at
@@ -219,76 +216,71 @@
       apply (force simp: \<open>d > 0\<close> dist_norm that simp del: power_Suc intro: *)
       done
   qed
-  have 2: "uniform_limit (path_image \<gamma>) (\<lambda>n x. f' x * (inverse (x - n) ^ k - inverse (x - w) ^ k) / (n - w) / of_nat k) (\<lambda>x. f' x / (x - w) ^ Suc k) (at w)"
+  have 2: "uniform_limit (path_image \<gamma>) (\<lambda>x z. (h k x z - h k w z) / (x-w) / k) (h (Suc k) w) (at w)"
     unfolding uniform_limit_iff dist_norm
   proof clarify
     fix e::real
     assume "0 < e"
-    have *: "cmod (f' (\<gamma> x) * (inverse (\<gamma> x - u) ^ k - inverse (\<gamma> x - w) ^ k) / ((u - w) * k) -
-                        f' (\<gamma> x) / ((\<gamma> x - w) * (\<gamma> x - w) ^ k)) < e"
-              if ec: "cmod ((inverse (\<gamma> x - u) ^ k - inverse (\<gamma> x - w) ^ k) / ((u - w) * k) -
-                      inverse (\<gamma> x - w) * inverse (\<gamma> x - w) ^ k) < e / C"
-                 and x: "0 \<le> x" "x \<le> 1"
-              for u x
-    proof (cases "(f' (\<gamma> x)) = 0")
-      case True then show ?thesis by (simp add: \<open>0 < e\<close>)
+    have *: "cmod ((h k x (\<gamma> u) - h k w (\<gamma> u)) / ((x-w) * k) - h (Suc k) w (\<gamma> u)) < e"
+          if ec: "cmod ((inverse (\<gamma> u - x) ^ k - inverse (\<gamma> u - w) ^ k) / ((x-w) * k) -
+                  inverse (\<gamma> u - w) * inverse (\<gamma> u - w) ^ k) < e / C"
+                 and x: "0 \<le> u" "u \<le> 1"
+               for x u
+    proof (cases "(f' (\<gamma> u)) = 0")
+      case True then show ?thesis by (simp add: \<open>0 < e\<close> h_def)
     next
       case False
-      have "cmod (f' (\<gamma> x) * (inverse (\<gamma> x - u) ^ k - inverse (\<gamma> x - w) ^ k) / ((u - w) * k) -
-                        f' (\<gamma> x) / ((\<gamma> x - w) * (\<gamma> x - w) ^ k)) =
-            cmod (f' (\<gamma> x) * ((inverse (\<gamma> x - u) ^ k - inverse (\<gamma> x - w) ^ k) / ((u - w) * k) -
-                             inverse (\<gamma> x - w) * inverse (\<gamma> x - w) ^ k))"
-        by (simp add: field_simps)
-      also have "\<dots> = cmod (f' (\<gamma> x)) *
-                       cmod ((inverse (\<gamma> x - u) ^ k - inverse (\<gamma> x - w) ^ k) / ((u - w) * k) -
-                             inverse (\<gamma> x - w) * inverse (\<gamma> x - w) ^ k)"
+      have "cmod ((h k x (\<gamma> u) - h k w (\<gamma> u)) / ((x-w) * k) - h (Suc k) w (\<gamma> u)) =
+            cmod (f' (\<gamma> u) * ((inverse (\<gamma> u - x) ^ k - inverse (\<gamma> u - w) ^ k) / ((x-w) * k) -
+                             inverse (\<gamma> u - w) * inverse (\<gamma> u - w) ^ k))"
+        by (simp add: h_def field_simps)
+      also have "\<dots> = cmod (f' (\<gamma> u)) *
+                       cmod ((inverse (\<gamma> u - x) ^ k - inverse (\<gamma> u - w) ^ k) / ((x-w) * k) -
+                             inverse (\<gamma> u - w) * inverse (\<gamma> u - w) ^ k)"
         by (simp add: norm_mult)
-      also have "\<dots> < cmod (f' (\<gamma> x)) * (e/C)"
+      also have "\<dots> < cmod (f' (\<gamma> u)) * (e/C)"
         using False mult_strict_left_mono [OF ec] by force
       also have "\<dots> \<le> e" using C
         by (metis False \<open>0 < e\<close> frac_le less_eq_real_def mult.commute pos_le_divide_eq x zero_less_norm_iff)
       finally show ?thesis .
     qed
-    show "\<forall>\<^sub>F n in at w.
+    show "\<forall>\<^sub>F u in at w.
               \<forall>x\<in>path_image \<gamma>.
-               cmod (f' x * (inverse (x - n) ^ k - inverse (x - w) ^ k) / (n - w) / of_nat k - f' x / (x - w) ^ Suc k) < e"
-      using twom [OF divide_pos_pos [OF \<open>0 < e\<close> \<open>C > 0\<close>]]   unfolding path_image_def
-      by (force intro: * elim: eventually_mono)
+               cmod ((h k u x - h k w x) / (u-w) / of_nat k - h (Suc k) w x) < e"
+      using twom [OF divide_pos_pos [OF \<open>0 < e\<close> \<open>C > 0\<close>]] *
+      unfolding path_image_def h_def
+      by (force elim: eventually_mono)
   qed
-  show "(\<lambda>u. f' u / (u - w) ^ (Suc k)) contour_integrable_on \<gamma>"
+  show "h (Suc k) w contour_integrable_on \<gamma>"
+    using contour_integral_uniform_limit [OF 1 2 leB \<gamma>] by (simp add: h_def)
+  have *: "(\<lambda>u. contour_integral \<gamma> (\<lambda>x. (h k u x - h k w x) / (u-w) / k))
+           \<midarrow>w\<rightarrow> contour_integral \<gamma> (h (Suc k) w)"
     by (rule contour_integral_uniform_limit [OF 1 2 leB \<gamma>]) auto
-  have *: "(\<lambda>n. contour_integral \<gamma> (\<lambda>x. f' x * (inverse (x - n) ^ k - inverse (x - w) ^ k) / (n - w) / k))
-           \<midarrow>w\<rightarrow> contour_integral \<gamma> (\<lambda>u. f' u / (u - w) ^ (Suc k))"
-    by (rule contour_integral_uniform_limit [OF 1 2 leB \<gamma>]) auto
-  have **: "contour_integral \<gamma> (\<lambda>x. f' x * (inverse (x - u) ^ k - inverse (x - w) ^ k) / ((u - w) * k)) =
-              (f u - f w) / (u - w) / k"
+  have **: "contour_integral \<gamma> (\<lambda>x. (h k u x - h k w x) / ((u-w) * k)) =
+              (f u - f w) / (u-w) / k"
     if "dist u w < d" for u
   proof -
-    have u: "u \<in> S - path_image \<gamma>"
+    have "u \<in> S - path_image \<gamma>"
       by (metis subsetD d dist_commute mem_ball that)
-    have \<section>: "((\<lambda>x. f' x * inverse (x - u) ^ k) has_contour_integral f u) \<gamma>"
-            "((\<lambda>x. f' x * inverse (x - w) ^ k) has_contour_integral f w) \<gamma>"
-      using u w by (simp_all add: field_simps int)
-    show ?thesis
-      apply (rule contour_integral_unique)
-      apply (simp add: diff_divide_distrib algebra_simps \<section> has_contour_integral_diff has_contour_integral_div)
-      done
+    then have "(h k u has_contour_integral f u) \<gamma>" "(h k w has_contour_integral f w) \<gamma>"
+      using w by (simp_all add: field_simps int)
+    then show ?thesis
+      using contour_integral_unique has_contour_integral_diff
+        has_contour_integral_div by force
   qed
   show ?thes2
-    apply (simp add: has_field_derivative_iff del: power_Suc)
-    apply (rule Lim_transform_within [OF tendsto_mult_left [OF *] \<open>0 < d\<close> ])
-    apply (simp add: \<open>k \<noteq> 0\<close> **)
-    done
+    unfolding has_field_derivative_iff
+    by (simp add: \<open>k \<noteq> 0\<close> ** Lim_transform_within [OF tendsto_mult_left [OF *] \<open>0 < d\<close>])
 qed
 
 lemma Cauchy_next_derivative_circlepath:
   assumes contf: "continuous_on (path_image (circlepath z r)) f"
-      and int: "\<And>w. w \<in> ball z r \<Longrightarrow> ((\<lambda>u. f u / (u - w)^k) has_contour_integral g w) (circlepath z r)"
+      and int: "\<And>w. w \<in> ball z r \<Longrightarrow> ((\<lambda>u. f u / (u-w)^k) has_contour_integral g w) (circlepath z r)"
       and k: "k \<noteq> 0"
       and w: "w \<in> ball z r"
-    shows "(\<lambda>u. f u / (u - w)^(Suc k)) contour_integrable_on (circlepath z r)"
+    shows "(\<lambda>u. f u / (u-w)^(Suc k)) contour_integrable_on (circlepath z r)"
            (is "?thes1")
-      and "(g has_field_derivative (k * contour_integral (circlepath z r) (\<lambda>u. f u/(u - w)^(Suc k)))) (at w)"
+      and "(g has_field_derivative (k * contour_integral (circlepath z r) (\<lambda>u. f u/(u-w)^(Suc k)))) (at w)"
            (is "?thes2")
 proof -
   have "r > 0" using w
@@ -307,9 +299,9 @@
   assumes contf: "continuous_on (cball z r) f"
       and holf: "f holomorphic_on ball z r"
       and w: "w \<in> ball z r"
-    shows "(\<lambda>u. f u/(u - w)^2) contour_integrable_on (circlepath z r)"
+    shows "(\<lambda>u. f u/(u-w)^2) contour_integrable_on (circlepath z r)"
            (is "?thes1")
-      and "(f has_field_derivative (1 / (2 * of_real pi * \<i>) * contour_integral(circlepath z r) (\<lambda>u. f u / (u - w)^2))) (at w)"
+      and "(f has_field_derivative (1 / (2 * of_real pi * \<i>) * contour_integral(circlepath z r) (\<lambda>u. f u / (u-w)^2))) (at w)"
            (is "?thes2")
 proof -
   have [simp]: "r \<ge> 0" using w
@@ -317,17 +309,17 @@
   have f: "continuous_on (path_image (circlepath z r)) f"
     by (rule continuous_on_subset [OF contf]) (force simp: cball_def sphere_def)
   have int: "\<And>w. dist z w < r \<Longrightarrow>
-                 ((\<lambda>u. f u / (u - w)) has_contour_integral (\<lambda>x. 2 * of_real pi * \<i> * f x) w) (circlepath z r)"
+                 ((\<lambda>u. f u / (u-w)) has_contour_integral (\<lambda>x. 2 * of_real pi * \<i> * f x) w) (circlepath z r)"
     by (rule Cauchy_integral_circlepath [OF contf holf]) (simp add: dist_norm norm_minus_commute)
   show ?thes1
     unfolding power2_eq_square
     using int Cauchy_next_derivative_circlepath [OF f _ _ w, where k=1]
     by fastforce
-  have "((\<lambda>x. 2 * of_real pi * \<i> * f x) has_field_derivative contour_integral (circlepath z r) (\<lambda>u. f u / (u - w)^2)) (at w)"
+  have "((\<lambda>x. 2 * of_real pi * \<i> * f x) has_field_derivative contour_integral (circlepath z r) (\<lambda>u. f u / (u-w)^2)) (at w)"
     unfolding power2_eq_square
     using int Cauchy_next_derivative_circlepath [OF f _ _ w, where k=1 and g = "\<lambda>x. 2 * of_real pi * \<i> * f x"]
     by fastforce
-  then have fder: "(f has_field_derivative contour_integral (circlepath z r) (\<lambda>u. f u / (u - w)^2) / (2 * of_real pi * \<i>)) (at w)"
+  then have fder: "(f has_field_derivative contour_integral (circlepath z r) (\<lambda>u. f u / (u-w)^2) / (2 * of_real pi * \<i>)) (at w)"
     by (rule DERIV_cdivide [where f = "\<lambda>x. 2 * of_real pi * \<i> * f x" and c = "2 * of_real pi * \<i>", simplified])
   show ?thes2
     by simp (rule fder)
@@ -356,22 +348,22 @@
     have holf_ball: "f holomorphic_on ball z r" using holf_cball
       using ball_subset_cball holomorphic_on_subset by blast
     { fix w  assume w: "w \<in> ball z r"
-      have intf: "(\<lambda>u. f u / (u - w)\<^sup>2) contour_integrable_on circlepath z r"
+      have intf: "(\<lambda>u. f u / (u-w)\<^sup>2) contour_integrable_on circlepath z r"
         by (blast intro: w Cauchy_derivative_integral_circlepath [OF contf_cball holf_ball])
-      have fder': "(f has_field_derivative 1 / (2 * of_real pi * \<i>) * contour_integral (circlepath z r) (\<lambda>u. f u / (u - w)\<^sup>2))
+      have fder': "(f has_field_derivative 1 / (2 * of_real pi * \<i>) * contour_integral (circlepath z r) (\<lambda>u. f u / (u-w)\<^sup>2))
                   (at w)"
         by (blast intro: w Cauchy_derivative_integral_circlepath [OF contf_cball holf_ball])
-      have f'_eq: "f' w = contour_integral (circlepath z r) (\<lambda>u. f u / (u - w)\<^sup>2) / (2 * of_real pi * \<i>)"
+      have f'_eq: "f' w = contour_integral (circlepath z r) (\<lambda>u. f u / (u-w)\<^sup>2) / (2 * of_real pi * \<i>)"
         using fder' ball_subset_cball r w by (force intro: DERIV_unique [OF fder])
-      have "((\<lambda>u. f u / (u - w)\<^sup>2 / (2 * of_real pi * \<i>)) has_contour_integral
-                contour_integral (circlepath z r) (\<lambda>u. f u / (u - w)\<^sup>2) / (2 * of_real pi * \<i>))
+      have "((\<lambda>u. f u / (u-w)\<^sup>2 / (2 * of_real pi * \<i>)) has_contour_integral
+                contour_integral (circlepath z r) (\<lambda>u. f u / (u-w)\<^sup>2) / (2 * of_real pi * \<i>))
                 (circlepath z r)"
         by (rule has_contour_integral_div [OF has_contour_integral_integral [OF intf]])
-      then have "((\<lambda>u. f u / (2 * of_real pi * \<i> * (u - w)\<^sup>2)) has_contour_integral
-                contour_integral (circlepath z r) (\<lambda>u. f u / (u - w)\<^sup>2) / (2 * of_real pi * \<i>))
+      then have "((\<lambda>u. f u / (2 * of_real pi * \<i> * (u-w)\<^sup>2)) has_contour_integral
+                contour_integral (circlepath z r) (\<lambda>u. f u / (u-w)\<^sup>2) / (2 * of_real pi * \<i>))
                 (circlepath z r)"
         by (simp add: algebra_simps)
-      then have "((\<lambda>u. f u / (2 * of_real pi * \<i> * (u - w)\<^sup>2)) has_contour_integral f' w) (circlepath z r)"
+      then have "((\<lambda>u. f u / (2 * of_real pi * \<i> * (u-w)\<^sup>2)) has_contour_integral f' w) (circlepath z r)"
         by (simp add: f'_eq)
     } note * = this
     show ?thesis
@@ -421,7 +413,7 @@
 qed simp_all
 
 lemma valid_path_compose_holomorphic:
-  assumes "valid_path g" and holo:"f holomorphic_on S" and "open S" "path_image g \<subseteq> S"
+  assumes "valid_path g" "f holomorphic_on S" and "open S" "path_image g \<subseteq> S"
   shows "valid_path (f \<circ> g)"
   by (meson assms holomorphic_deriv holomorphic_on_imp_continuous_on holomorphic_on_imp_differentiable_at
       holomorphic_on_subset subsetD valid_path_compose)
@@ -589,14 +581,14 @@
   unfolding diff_conv_add_uminus higher_deriv_add
   using assms higher_deriv_add higher_deriv_uminus holomorphic_on_minus by presburger
 
-lemma Suc_choose: "Suc n choose k = (n choose k) + (if k = 0 then 0 else (n choose (k - 1)))"
+lemma Suc_choose: "Suc n choose k = (n choose k) + (if k = 0 then 0 else (n choose (k-1)))"
   by (cases k) simp_all
 
 lemma higher_deriv_mult:
   fixes z::complex
   assumes "f holomorphic_on S" "g holomorphic_on S" "open S" and z: "z \<in> S"
     shows "(deriv ^^ n) (\<lambda>w. f w * g w) z =
-           (\<Sum>i = 0..n. of_nat (n choose i) * (deriv ^^ i) f z * (deriv ^^ (n - i)) g z)"
+           (\<Sum>i = 0..n. of_nat (n choose i) * (deriv ^^ i) f z * (deriv ^^ (n-i)) g z)"
 using z
 proof (induction n arbitrary: z)
   case 0 then show ?case by simp
@@ -606,7 +598,7 @@
           "\<And>n. ((deriv ^^ n) g has_field_derivative deriv ((deriv ^^ n) g) z) (at z)"
     using Suc.prems assms has_field_derivative_higher_deriv by auto
   have sumeq: "(\<Sum>i = 0..n.
-               of_nat (n choose i) * (deriv ((deriv ^^ i) f) z * (deriv ^^ (n - i)) g z + deriv ((deriv ^^ (n - i)) g) z * (deriv ^^ i) f z)) =
+               of_nat (n choose i) * (deriv ((deriv ^^ i) f) z * (deriv ^^ (n-i)) g z + deriv ((deriv ^^ (n-i)) g) z * (deriv ^^ i) f z)) =
             g z * deriv ((deriv ^^ n) f) z + (\<Sum>i = 0..n. (deriv ^^ i) f z * (of_nat (Suc n choose i) * (deriv ^^ (Suc n - i)) g z))"
     apply (simp add: Suc_choose algebra_simps sum.distrib)
     apply (subst (4) sum_Suc_reindex)
@@ -616,7 +608,7 @@
          (\<Sum>i = 0..Suc n. (Suc n choose i) * (deriv ^^ i) f z * (deriv ^^ (Suc n - i)) g z))
         (at z)"
     apply (rule has_field_derivative_transform_within_open
-        [of "\<lambda>w. (\<Sum>i = 0..n. of_nat (n choose i) * (deriv ^^ i) f w * (deriv ^^ (n - i)) g w)" _ _ S])
+        [of "\<lambda>w. (\<Sum>i = 0..n. of_nat (n choose i) * (deriv ^^ i) f w * (deriv ^^ (n-i)) g w)" _ _ S])
        apply (simp add: algebra_simps)
        apply (rule derivative_eq_intros | simp)+
            apply (auto intro: DERIV_mult * \<open>open S\<close> Suc.prems Suc.IH [symmetric])
@@ -665,13 +657,8 @@
     have "(deriv ^^ n) f analytic_on T"
       by (simp add: analytic_on_open f holomorphic_higher_deriv T)
     then have "(\<lambda>w. (deriv ^^ n) f (u * w+c)) analytic_on S"
-    proof -
-      have "(deriv ^^ n) f \<circ> (\<lambda>w. u * w+c) holomorphic_on S"
         using holomorphic_on_compose[OF _ holo2] \<open>(\<lambda>w. u * w+c) holomorphic_on S\<close>
-        by simp
-      then show ?thesis
         by (simp add: S analytic_on_open o_def)
-    qed
     then show ?thesis
       by (intro deriv_cmult analytic_on_imp_differentiable_at [OF _ Suc.prems])
   qed
@@ -710,7 +697,7 @@
 lemma higher_deriv_mult_at:
   assumes "f analytic_on {z}" "g analytic_on {z}"
     shows "(deriv ^^ n) (\<lambda>w. f w * g w) z =
-           (\<Sum>i = 0..n. of_nat (n choose i) * (deriv ^^ i) f z * (deriv ^^ (n - i)) g z)"
+           (\<Sum>i = 0..n. of_nat (n choose i) * (deriv ^^ i) f z * (deriv ^^ (n-i)) g z)"
   using analytic_at_two assms higher_deriv_mult by blast
 
 
@@ -718,7 +705,7 @@
 
 proposition no_isolated_singularity:
   fixes z::complex
-  assumes f: "continuous_on S f" and holf: "f holomorphic_on (S - K)" and S: "open S" and K: "finite K"
+  assumes f: "continuous_on S f" and holf: "f holomorphic_on (S-K)" and S: "open S" and K: "finite K"
     shows "f holomorphic_on S"
 proof -
   { fix z
@@ -758,17 +745,14 @@
 lemma no_isolated_singularity':
   fixes z::complex
   assumes f: "\<And>z. z \<in> K \<Longrightarrow> (f \<longlongrightarrow> f z) (at z within S)"
-      and holf: "f holomorphic_on (S - K)" and S: "open S" and K: "finite K"
+      and holf: "f holomorphic_on (S-K)" and S: "open S" and K: "finite K"
     shows "f holomorphic_on S"
 proof (rule no_isolated_singularity[OF _ assms(2-)])
-  show "continuous_on S f" unfolding continuous_on_def
-  proof
-    fix z assume z: "z \<in> S"
-    have "continuous_on (S - K) f"
-      using holf holomorphic_on_imp_continuous_on by auto
-    then show "(f \<longlongrightarrow> f z) (at z within S)"
-      by (metis Diff_iff K S at_within_interior continuous_on_def f finite_imp_closed interior_eq open_Diff z)
-  qed
+  have "continuous_on (S-K) f"
+    using holf holomorphic_on_imp_continuous_on by auto
+  then show "continuous_on S f"
+    by (metis Diff_iff K S at_within_open continuous_on_eq_continuous_at
+        continuous_within f finite_imp_closed open_Diff) 
 qed
 
 proposition Cauchy_integral_formula_convex:
@@ -776,14 +760,13 @@
     and fcd: "(\<And>x. x \<in> interior S - K \<Longrightarrow> f field_differentiable at x)"
     and z: "z \<in> interior S" and vpg: "valid_path \<gamma>"
     and pasz: "path_image \<gamma> \<subseteq> S - {z}" and loop: "pathfinish \<gamma> = pathstart \<gamma>"
-  shows "((\<lambda>w. f w / (w - z)) has_contour_integral (2*pi * \<i> * winding_number \<gamma> z * f z)) \<gamma>"
+  shows "((\<lambda>w. f w / (w-z)) has_contour_integral (2*pi * \<i> * winding_number \<gamma> z * f z)) \<gamma>"
 proof -
   have *: "\<And>x. x \<in> interior S \<Longrightarrow> f field_differentiable at x"
     unfolding holomorphic_on_open [symmetric] field_differentiable_def
     using no_isolated_singularity [where S = "interior S"]
-    by (meson K contf continuous_at_imp_continuous_on continuous_on_interior fcd
-          field_differentiable_at_within field_differentiable_def holomorphic_onI
-          holomorphic_on_imp_differentiable_at open_interior)
+    by (meson K contf continuous_on_subset fcd field_differentiable_def open_interior
+        has_field_derivative_at_within holomorphic_derivI holomorphic_onI interior_subset)
   show ?thesis
     by (rule Cauchy_integral_formula_weak [OF S finite.emptyI contf]) (use * assms in auto)
 qed
@@ -794,7 +777,7 @@
   assumes contf: "continuous_on (cball z r) f"
       and holf: "f holomorphic_on ball z r"
       and w: "w \<in> ball z r"
-    shows "((\<lambda>u. f u / (u - w) ^ (Suc k)) has_contour_integral ((2 * pi * \<i>) / (fact k) * (deriv ^^ k) f w))
+    shows "((\<lambda>u. f u / (u-w) ^ (Suc k)) has_contour_integral ((2 * pi * \<i>) / (fact k) * (deriv ^^ k) f w))
            (circlepath z r)"
 using w
 proof (induction k arbitrary: w)
@@ -806,17 +789,17 @@
     using ball_eq_empty by fastforce
   have f: "continuous_on (path_image (circlepath z r)) f"
     by (rule continuous_on_subset [OF contf]) (force simp: cball_def sphere_def less_imp_le)
-  obtain X where X: "((\<lambda>u. f u / (u - w) ^ Suc (Suc k)) has_contour_integral X) (circlepath z r)"
+  obtain X where X: "((\<lambda>u. f u / (u-w) ^ Suc (Suc k)) has_contour_integral X) (circlepath z r)"
     using Cauchy_next_derivative_circlepath(1) [OF f Suc.IH _ Suc.prems]
     by (auto simp: contour_integrable_on_def)
-  then have con: "contour_integral (circlepath z r) ((\<lambda>u. f u / (u - w) ^ Suc (Suc k))) = X"
+  then have con: "contour_integral (circlepath z r) ((\<lambda>u. f u / (u-w) ^ Suc (Suc k))) = X"
     by (rule contour_integral_unique)
   have "\<And>n. ((deriv ^^ n) f has_field_derivative deriv ((deriv ^^ n) f) w) (at w)"
     using Suc.prems assms has_field_derivative_higher_deriv by auto
   then have dnf_diff: "\<And>n. (deriv ^^ n) f field_differentiable (at w)"
     by (force simp: field_differentiable_def)
   have "deriv (\<lambda>w. complex_of_real (2 * pi) * \<i> / (fact k) * (deriv ^^ k) f w) w =
-          of_nat (Suc k) * contour_integral (circlepath z r) (\<lambda>u. f u / (u - w) ^ Suc (Suc k))"
+          of_nat (Suc k) * contour_integral (circlepath z r) (\<lambda>u. f u / (u-w) ^ Suc (Suc k))"
     by (force intro!: DERIV_imp_deriv Cauchy_next_derivative_circlepath [OF f Suc.IH _ Suc.prems])
   also have "\<dots> = of_nat (Suc k) * X"
     by (simp only: con)
@@ -833,12 +816,12 @@
   assumes contf: "continuous_on (cball z r) f"
       and holf: "f holomorphic_on ball z r"
       and w: "w \<in> ball z r"
-    shows "(\<lambda>u. f u / (u - w)^(Suc k)) contour_integrable_on (circlepath z r)"
+    shows "(\<lambda>u. f u / (u-w)^(Suc k)) contour_integrable_on (circlepath z r)"
            (is "?thes1")
-      and "(deriv ^^ k) f w = (fact k) / (2 * pi * \<i>) * contour_integral(circlepath z r) (\<lambda>u. f u/(u - w)^(Suc k))"
+      and "(deriv ^^ k) f w = (fact k) / (2 * pi * \<i>) * contour_integral(circlepath z r) (\<lambda>u. f u/(u-w)^(Suc k))"
            (is "?thes2")
 proof -
-  have *: "((\<lambda>u. f u / (u - w) ^ Suc k) has_contour_integral (2 * pi) * \<i> / (fact k) * (deriv ^^ k) f w)
+  have *: "((\<lambda>u. f u / (u-w) ^ Suc k) has_contour_integral (2 * pi) * \<i> / (fact k) * (deriv ^^ k) f w)
            (circlepath z r)"
     using Cauchy_has_contour_integral_higher_derivative_circlepath [OF assms]
     by simp
@@ -850,12 +833,12 @@
 
 corollary Cauchy_contour_integral_circlepath:
   assumes "continuous_on (cball z r) f" "f holomorphic_on ball z r" "w \<in> ball z r"
-  shows "contour_integral(circlepath z r) (\<lambda>u. f u/(u - w)^(Suc k)) = (2 * pi * \<i>) * (deriv ^^ k) f w / (fact k)"
+  shows "contour_integral(circlepath z r) (\<lambda>u. f u/(u-w)^(Suc k)) = (2 * pi * \<i>) * (deriv ^^ k) f w / (fact k)"
   by (simp add: Cauchy_higher_derivative_integral_circlepath [OF assms])
 
 lemma Cauchy_contour_integral_circlepath_2:
   assumes "continuous_on (cball z r) f" "f holomorphic_on ball z r" "w \<in> ball z r"
-    shows "contour_integral(circlepath z r) (\<lambda>u. f u/(u - w)^2) = (2 * pi * \<i>) * deriv f w"
+    shows "contour_integral(circlepath z r) (\<lambda>u. f u/(u-w)^2) = (2 * pi * \<i>) * deriv f w"
   using Cauchy_contour_integral_circlepath [OF assms, of 1]
   by (simp add: power2_eq_square)
 
@@ -865,7 +848,7 @@
 theorem holomorphic_power_series:
   assumes holf: "f holomorphic_on ball z r"
       and w: "w \<in> ball z r"
-    shows "((\<lambda>n. (deriv ^^ n) f z / (fact n) * (w - z)^n) sums f w)"
+    shows "((\<lambda>n. (deriv ^^ n) f z / (fact n) * (w-z)^n) sums f w)"
 proof -
   \<comment> \<open>Replacing \<^term>\<open>r\<close> and the original (weak) premises with stronger ones\<close>
   obtain r where "r > 0" and holfc: "f holomorphic_on cball z r" and w: "w \<in> ball z r"
@@ -875,7 +858,7 @@
     then show "f holomorphic_on cball z ((r + dist w z) / 2)"
       by (rule holomorphic_on_subset [OF holf])
     have "r > 0"
-      using w by clarsimp (metis dist_norm le_less_trans norm_ge_zero)
+      by (metis w dist_norm mem_ball norm_ge_zero not_less_iff_gr_or_eq order_less_le_trans)
     then show "0 < (r + dist w z) / 2"
       by simp (use zero_le_dist [of w z] in linarith)
   qed (use w in \<open>auto simp: dist_commute\<close>)
@@ -883,87 +866,87 @@
     using ball_subset_cball holomorphic_on_subset by blast
   have contf: "continuous_on (cball z r) f"
     by (simp add: holfc holomorphic_on_imp_continuous_on)
-  have cint: "\<And>k. (\<lambda>u. f u / (u - z) ^ Suc k) contour_integrable_on circlepath z r"
+  have cint: "\<And>k. (\<lambda>u. f u / (u-z) ^ Suc k) contour_integrable_on circlepath z r"
     by (rule Cauchy_higher_derivative_integral_circlepath [OF contf holf]) (simp add: \<open>0 < r\<close>)
   obtain B where "0 < B" and B: "\<And>u. u \<in> cball z r \<Longrightarrow> norm(f u) \<le> B"
     by (metis (no_types) bounded_pos compact_cball compact_continuous_image compact_imp_bounded contf image_eqI)
-  obtain k where k: "0 < k" "k \<le> r" and wz_eq: "norm(w - z) = r - k"
-             and kle: "\<And>u. norm(u - z) = r \<Longrightarrow> k \<le> norm(u - w)"
+  obtain k where k: "0 < k" "k \<le> r" and wz_eq: "norm(w-z) = r - k"
+             and kle: "\<And>u. norm(u-z) = r \<Longrightarrow> k \<le> norm(u-w)"
   proof
-    show "\<And>u. cmod (u - z) = r \<Longrightarrow> r - dist z w \<le> cmod (u - w)"
+    show "\<And>u. cmod (u-z) = r \<Longrightarrow> r - dist z w \<le> cmod (u-w)"
       by (metis add_diff_eq diff_add_cancel dist_norm norm_diff_ineq)
   qed (use w in \<open>auto simp: dist_norm norm_minus_commute\<close>)
-  have ul: "uniform_limit (sphere z r) (\<lambda>n x. (\<Sum>k<n. (w - z) ^ k * (f x / (x - z) ^ Suc k))) (\<lambda>x. f x / (x - w)) sequentially"
+  have ul: "uniform_limit (sphere z r) (\<lambda>n x. (\<Sum>k<n. (w-z) ^ k * (f x / (x-z) ^ Suc k))) (\<lambda>x. f x / (x-w)) sequentially"
     unfolding uniform_limit_iff dist_norm
   proof clarify
     fix e::real
     assume "0 < e"
-    have rr: "0 \<le> (r - k) / r" "(r - k) / r < 1" using  k by auto
-    obtain n where n: "((r - k) / r) ^ n < e / B * k"
-      using real_arch_pow_inv [of "e/B*k" "(r - k)/r"] \<open>0 < e\<close> \<open>0 < B\<close> k by force
-    have "norm ((\<Sum>k<N. (w - z) ^ k * f u / (u - z) ^ Suc k) - f u / (u - w)) < e"
+    have rr: "0 \<le> (r-k) / r" "(r-k) / r < 1" using  k by auto
+    obtain n where n: "((r-k) / r) ^ n < e / B * k"
+      using real_arch_pow_inv [of "e/B*k" "(r-k)/r"] \<open>0 < e\<close> \<open>0 < B\<close> k by force
+    have "norm ((\<Sum>k<N. (w-z) ^ k * f u / (u-z) ^ Suc k) - f u / (u-w)) < e"
          if "n \<le> N" and r: "r = dist z u"  for N u
     proof -
-      have N: "((r - k) / r) ^ N < e / B * k"
+      have N: "((r-k) / r) ^ N < e / B * k"
         using le_less_trans [OF power_decreasing n]
         using \<open>n \<le> N\<close> k by auto
       have u [simp]: "(u \<noteq> z) \<and> (u \<noteq> w)"
         using \<open>0 < r\<close> r w by auto
-      have wzu_not1: "(w - z) / (u - z) \<noteq> 1"
+      have wzu_not1: "(w-z) / (u-z) \<noteq> 1"
         by (metis (no_types) dist_norm divide_eq_1_iff less_irrefl mem_ball norm_minus_commute r w)
-      have "norm ((\<Sum>k<N. (w - z) ^ k * f u / (u - z) ^ Suc k) * (u - w) - f u)
-            = norm ((\<Sum>k<N. (((w - z) / (u - z)) ^ k)) * f u * (u - w) / (u - z) - f u)"
+      have "norm ((\<Sum>k<N. (w-z) ^ k * f u / (u-z) ^ Suc k) * (u-w) - f u)
+            = norm ((\<Sum>k<N. (((w-z) / (u-z)) ^ k)) * f u * (u-w) / (u-z) - f u)"
         unfolding sum_distrib_right sum_divide_distrib power_divide by (simp add: algebra_simps)
-      also have "\<dots> = norm ((((w - z) / (u - z)) ^ N - 1) * (u - w) / (((w - z) / (u - z) - 1) * (u - z)) - 1) * norm (f u)"
+      also have "\<dots> = norm ((((w-z) / (u-z)) ^ N - 1) * (u-w) / (((w-z) / (u-z) - 1) * (u-z)) - 1) * norm (f u)"
         using \<open>0 < B\<close>
-        apply (auto simp: geometric_sum [OF wzu_not1])
-        apply (simp add: field_simps norm_mult [symmetric])
+        apply (simp add: geometric_sum [OF wzu_not1] flip: norm_mult)
+        apply (simp add: field_simps)
         done
-      also have "\<dots> = norm ((u-z) ^ N * (w - u) - ((w - z) ^ N - (u-z) ^ N) * (u-w)) / (r ^ N * norm (u-w)) * norm (f u)"
+      also have "\<dots> = norm ((u-z) ^ N * (w-u) - ((w-z) ^ N - (u-z) ^ N) * (u-w)) / (r ^ N * norm (u-w)) * norm (f u)"
         using \<open>0 < r\<close> r by (simp add: divide_simps norm_mult norm_divide norm_power dist_norm norm_minus_commute)
-      also have "\<dots> = norm ((w - z) ^ N * (w - u)) / (r ^ N * norm (u - w)) * norm (f u)"
+      also have "\<dots> = norm ((w-z) ^ N * (w-u)) / (r ^ N * norm (u-w)) * norm (f u)"
         by (simp add: algebra_simps)
-      also have "\<dots> = norm (w - z) ^ N * norm (f u) / r ^ N"
+      also have "\<dots> = norm (w-z) ^ N * norm (f u) / r ^ N"
         by (simp add: norm_mult norm_power norm_minus_commute)
-      also have "\<dots> \<le> (((r - k)/r)^N) * B"
+      also have "\<dots> \<le> (((r-k)/r)^N) * B"
         using \<open>0 < r\<close> w k
         by (simp add: B divide_simps mult_mono r wz_eq)
       also have "\<dots> < e * k"
         using \<open>0 < B\<close> N by (simp add: divide_simps)
-      also have "\<dots> \<le> e * norm (u - w)"
+      also have "\<dots> \<le> e * norm (u-w)"
         using r kle \<open>0 < e\<close> by (simp add: dist_commute dist_norm)
       finally show ?thesis
         by (simp add: field_split_simps norm_divide del: power_Suc)
     qed
     with \<open>0 < r\<close> show "\<forall>\<^sub>F n in sequentially. \<forall>x\<in>sphere z r.
-                norm ((\<Sum>k<n. (w - z) ^ k * (f x / (x - z) ^ Suc k)) - f x / (x - w)) < e"
+                norm ((\<Sum>k<n. (w-z) ^ k * (f x / (x-z) ^ Suc k)) - f x / (x-w)) < e"
       by (auto simp: mult_ac less_imp_le eventually_sequentially Ball_def)
   qed
   have \<section>: "\<And>x k. k\<in> {..<x} \<Longrightarrow>
-           (\<lambda>u. (w - z) ^ k * (f u / (u - z) ^ Suc k)) contour_integrable_on circlepath z r"
-    using contour_integrable_lmul [OF cint, of "(w - z) ^ a" for a] by (simp add: field_simps)
-  have eq: "\<forall>\<^sub>F x in sequentially.
-             contour_integral (circlepath z r) (\<lambda>u. \<Sum>k<x. (w - z) ^ k * (f u / (u - z) ^ Suc k)) =
-             (\<Sum>k<x. contour_integral (circlepath z r) (\<lambda>u. f u / (u - z) ^ Suc k) * (w - z) ^ k)"
-    apply (rule eventuallyI)
-    apply (subst contour_integral_sum, simp)
-    apply (simp_all only: \<section> contour_integral_lmul cint algebra_simps)
+           (\<lambda>u. (w-z) ^ k * (f u / (u-z) ^ Suc k)) contour_integrable_on circlepath z r"
+    using contour_integrable_lmul [OF cint, of "(w-z) ^ a" for a] by (simp add: field_simps)
+  have eq: "\<And>n.
+             (\<Sum>k<n. contour_integral (circlepath z r) (\<lambda>u. f u / (u-z) ^ Suc k) * (w-z) ^ k) =
+             contour_integral (circlepath z r) (\<lambda>u. \<Sum>k<n. (w-z) ^ k * (f u / (u-z) ^ Suc k))"
+    apply (subst contour_integral_sum)
+    apply (simp_all only: \<section> finite_lessThan contour_integral_lmul cint algebra_simps)
     done
-  have "\<And>u k. k \<in> {..<u} \<Longrightarrow> (\<lambda>x. f x / (x - z) ^ Suc k) contour_integrable_on circlepath z r"
+  have "\<And>u k. k \<in> {..<u} \<Longrightarrow> (\<lambda>x. f x / (x-z) ^ Suc k) contour_integrable_on circlepath z r"
     using \<open>0 < r\<close> by (force intro!: Cauchy_higher_derivative_integral_circlepath [OF contf holf])
-  then have "\<And>u. (\<lambda>y. \<Sum>k<u. (w - z) ^ k * (f y / (y - z) ^ Suc k)) contour_integrable_on circlepath z r"
+  then have "\<And>u. (\<lambda>y. \<Sum>k<u. (w-z) ^ k * (f y / (y-z) ^ Suc k)) contour_integrable_on circlepath z r"
     by (intro contour_integrable_sum contour_integrable_lmul, simp)
-  then have "(\<lambda>k. contour_integral (circlepath z r) (\<lambda>u. f u/(u - z)^(Suc k)) * (w - z)^k)
-        sums contour_integral (circlepath z r) (\<lambda>u. f u/(u - w))"
-    unfolding sums_def using \<open>0 < r\<close> 
-    by (intro Lim_transform_eventually [OF _ eq] contour_integral_uniform_limit_circlepath [OF eventuallyI ul]) auto
-  then have "(\<lambda>k. contour_integral (circlepath z r) (\<lambda>u. f u/(u - z)^(Suc k)) * (w - z)^k)
+  then have "(\<lambda>k. contour_integral (circlepath z r) (\<lambda>u. f u/(u-z)^(Suc k)) * (w-z)^k)
+        sums contour_integral (circlepath z r) (\<lambda>u. f u/(u-w))"
+    unfolding sums_def eq 
+    using \<open>0 < r\<close> contour_integral_uniform_limit_circlepath [OF eventuallyI ul]    
+    by fastforce
+  then have "(\<lambda>k. contour_integral (circlepath z r) (\<lambda>u. f u/(u-z)^(Suc k)) * (w-z)^k)
              sums (2 * of_real pi * \<i> * f w)"
     using w by (auto simp: dist_commute dist_norm contour_integral_unique [OF Cauchy_integral_circlepath_simple [OF holfc]])
-  then have "(\<lambda>k. contour_integral (circlepath z r) (\<lambda>u. f u / (u - z) ^ Suc k) * (w - z)^k / (\<i> * (of_real pi * 2)))
+  then have "(\<lambda>k. contour_integral (circlepath z r) (\<lambda>u. f u / (u-z) ^ Suc k) * (w-z)^k / (\<i> * (of_real pi * 2)))
             sums ((2 * of_real pi * \<i> * f w) / (\<i> * (complex_of_real pi * 2)))"
     by (rule sums_divide)
-  then have "(\<lambda>n. (w - z) ^ n * contour_integral (circlepath z r) (\<lambda>u. f u / (u - z) ^ Suc n) / (\<i> * (of_real pi * 2)))
+  then have "(\<lambda>n. (w-z) ^ n * contour_integral (circlepath z r) (\<lambda>u. f u / (u-z) ^ Suc n) / (\<i> * (of_real pi * 2)))
             sums f w"
     by (simp add: field_simps)
   then show ?thesis
@@ -985,10 +968,10 @@
   define R where "R = 1 + \<bar>B\<bar> + norm z"
   have "R > 0"
     unfolding R_def by (smt (verit) norm_ge_zero)
-  have *: "((\<lambda>u. f u / (u - z)) has_contour_integral 2 * complex_of_real pi * \<i> * f z) (circlepath z R)"
+  have *: "((\<lambda>u. f u / (u-z)) has_contour_integral 2 * complex_of_real pi * \<i> * f z) (circlepath z R)"
     using continuous_on_subset holf  holomorphic_on_subset \<open>0 < R\<close>
     by (force intro: holomorphic_on_imp_continuous_on Cauchy_integral_circlepath)
-  have "cmod (x - z) = R \<Longrightarrow> cmod (f x) * 2 < cmod (f z)" for x
+  have "cmod (x-z) = R \<Longrightarrow> cmod (f x) * 2 < cmod (f z)" for x
     unfolding R_def by (rule B) (use norm_triangle_ineq4 [of x z] in auto)
   with \<open>R > 0\<close> fz show False
     using has_contour_integral_bound_circlepath [OF *, of "norm(f z)/2/R"]
@@ -1064,34 +1047,34 @@
     using \<open>0 < r\<close> by auto
   then have 1: "continuous_on (path_image (circlepath z r)) (\<lambda>x. 1 / (2 * complex_of_real pi * \<i>) * g x)"
     by (intro continuous_intros continuous_on_subset [OF contg])
-  have 2: "((\<lambda>u. 1 / (2 * of_real pi * \<i>) * g u / (u - w) ^ 1) has_contour_integral g w) (circlepath z r)"
+  have 2: "((\<lambda>u. 1 / (2 * of_real pi * \<i>) * g u / (u-w) ^ 1) has_contour_integral g w) (circlepath z r)"
        if w: "w \<in> ball z r" for w
   proof -
-    define d where "d = (r - norm(w - z))"
+    define d where "d = (r - norm(w-z))"
     have "0 < d"  "d \<le> r" using w by (auto simp: norm_minus_commute d_def dist_norm)
-    have dle: "\<And>u. cmod (z - u) = r \<Longrightarrow> d \<le> cmod (u - w)"
+    have dle: "\<And>u. cmod (z-u) = r \<Longrightarrow> d \<le> cmod (u-w)"
       unfolding d_def by (metis add_diff_eq diff_add_cancel norm_diff_ineq norm_minus_commute)
-    have ev_int: "\<forall>\<^sub>F n in F. (\<lambda>u. f n u / (u - w)) contour_integrable_on circlepath z r"
+    have ev_int: "\<forall>\<^sub>F n in F. (\<lambda>u. f n u / (u-w)) contour_integrable_on circlepath z r"
       using w
       by (auto intro: eventually_mono [OF cont] Cauchy_higher_derivative_integral_circlepath [where k=0, simplified])
     have "\<And>e. \<lbrakk>0 < r; 0 < d; 0 < e\<rbrakk>
          \<Longrightarrow> \<forall>\<^sub>F n in F.
                 \<forall>x\<in>sphere z r.
                    x \<noteq> w \<longrightarrow>
-                   cmod (f n x - g x) < e * cmod (x - w)"
+                   cmod (f n x - g x) < e * cmod (x-w)"
       apply (rule_tac e1="e * d" in eventually_mono [OF uniform_limitD [OF ulim]])
        apply (force simp: dist_norm intro: dle mult_left_mono less_le_trans)+
       done
-    then have ul_less: "uniform_limit (sphere z r) (\<lambda>n x. f n x / (x - w)) (\<lambda>x. g x / (x - w)) F"
+    then have ul_less: "uniform_limit (sphere z r) (\<lambda>n x. f n x / (x-w)) (\<lambda>x. g x / (x-w)) F"
       using greater \<open>0 < d\<close>
       by (auto simp add: uniform_limit_iff dist_norm norm_divide diff_divide_distrib [symmetric] divide_simps)
-    have g_cint: "(\<lambda>u. g u/(u - w)) contour_integrable_on circlepath z r"
+    have g_cint: "(\<lambda>u. g u/(u-w)) contour_integrable_on circlepath z r"
       by (rule contour_integral_uniform_limit_circlepath [OF ev_int ul_less F \<open>0 < r\<close>])
-    have cif_tends_cig: "((\<lambda>n. contour_integral(circlepath z r) (\<lambda>u. f n u / (u - w))) \<longlongrightarrow> contour_integral(circlepath z r) (\<lambda>u. g u/(u - w))) F"
+    have cif_tends_cig: "((\<lambda>n. contour_integral(circlepath z r) (\<lambda>u. f n u / (u-w))) \<longlongrightarrow> contour_integral(circlepath z r) (\<lambda>u. g u/(u-w))) F"
       by (rule contour_integral_uniform_limit_circlepath [OF ev_int ul_less F \<open>0 < r\<close>])
-    have f_tends_cig: "((\<lambda>n. 2 * of_real pi * \<i> * f n w) \<longlongrightarrow> contour_integral (circlepath z r) (\<lambda>u. g u / (u - w))) F"
+    have f_tends_cig: "((\<lambda>n. 2 * of_real pi * \<i> * f n w) \<longlongrightarrow> contour_integral (circlepath z r) (\<lambda>u. g u / (u-w))) F"
     proof (rule Lim_transform_eventually)
-      show "\<forall>\<^sub>F x in F. contour_integral (circlepath z r) (\<lambda>u. f x u / (u - w))
+      show "\<forall>\<^sub>F x in F. contour_integral (circlepath z r) (\<lambda>u. f x u / (u-w))
                      = 2 * of_real pi * \<i> * f x w"
         using w\<open>0 < d\<close> d_def
         by (auto intro: eventually_mono [OF cont contour_integral_unique [OF Cauchy_integral_circlepath]])
@@ -1100,10 +1083,10 @@
       by (rule eventually_mono [OF uniform_limitD [OF ulim]]) (use w in auto)
     then have "((\<lambda>n. 2 * of_real pi * \<i> * f n w) \<longlongrightarrow> 2 * of_real pi * \<i> * g w) F"
       by (rule tendsto_mult_left [OF tendstoI])
-    then have "((\<lambda>u. g u / (u - w)) has_contour_integral 2 * of_real pi * \<i> * g w) (circlepath z r)"
+    then have "((\<lambda>u. g u / (u-w)) has_contour_integral 2 * of_real pi * \<i> * g w) (circlepath z r)"
       using has_contour_integral_integral [OF g_cint] tendsto_unique [OF F f_tends_cig] w
       by fastforce
-    then have "((\<lambda>u. g u / (2 * of_real pi * \<i> * (u - w))) has_contour_integral g w) (circlepath z r)"
+    then have "((\<lambda>u. g u / (2 * of_real pi * \<i> * (u-w))) has_contour_integral g w) (circlepath z r)"
       using has_contour_integral_div [where c = "2 * of_real pi * \<i>"]
       by (force simp: field_simps)
     then show ?thesis
@@ -1138,54 +1121,47 @@
     by (simp add: DERIV_imp_deriv)
   have tends_f'n_g': "((\<lambda>n. f' n w) \<longlongrightarrow> g' w) F" if w: "w \<in> ball z r" for w
   proof -
-    have eq_f': "?conint (\<lambda>x. f n x / (x - w)\<^sup>2) - ?conint (\<lambda>x. g x / (x - w)\<^sup>2) = (f' n w - g' w) * (2 * of_real pi * \<i>)"
+    have eq_f': "?conint (\<lambda>x. f n x / (x-w)\<^sup>2) - ?conint (\<lambda>x. g x / (x-w)\<^sup>2) = (f' n w - g' w) * (2 * of_real pi * \<i>)"
              if cont_fn: "continuous_on (cball z r) (f n)"
              and fnd: "\<And>w. w \<in> ball z r \<Longrightarrow> (f n has_field_derivative f' n w) (at w)" for n
     proof -
       have hol_fn: "f n holomorphic_on ball z r"
         using fnd by (force simp: holomorphic_on_open)
-      have "(f n has_field_derivative 1 / (2 * of_real pi * \<i>) * ?conint (\<lambda>u. f n u / (u - w)\<^sup>2)) (at w)"
+      have "(f n has_field_derivative 1 / (2 * of_real pi * \<i>) * ?conint (\<lambda>u. f n u / (u-w)\<^sup>2)) (at w)"
         by (rule Cauchy_derivative_integral_circlepath [OF cont_fn hol_fn w])
-      then have f': "f' n w = 1 / (2 * of_real pi * \<i>) * ?conint (\<lambda>u. f n u / (u - w)\<^sup>2)"
+      then have f': "f' n w = 1 / (2 * of_real pi * \<i>) * ?conint (\<lambda>u. f n u / (u-w)\<^sup>2)"
         using DERIV_unique [OF fnd] w by blast
       show ?thesis
         by (simp add: f' Cauchy_contour_integral_circlepath_2 [OF g w] derg [OF w] field_split_simps)
     qed
-    define d where "d = (r - norm(w - z))^2"
+    define d where "d = (r - norm(w-z))^2"
     have "d > 0"
       using w by (simp add: dist_commute dist_norm d_def)
-    have dle: "d \<le> cmod ((y - w)\<^sup>2)" if "r = cmod (z - y)" for y
-    proof -
-      have "cmod (w - z) \<le> cmod (z - y)"
-        by (metis dist_commute dist_norm mem_ball order_less_imp_le that w)
-      moreover have "cmod (z - y) - cmod (w - z) \<le> cmod (y - w)"
-        by (metis diff_add_cancel diff_diff_eq2 norm_minus_commute norm_triangle_ineq2)
-      ultimately show ?thesis
-        using that by (simp add: d_def norm_power power_mono)
-    qed
-    have 1: "\<forall>\<^sub>F n in F. (\<lambda>x. f n x / (x - w)\<^sup>2) contour_integrable_on circlepath z r"
+    have dle: "d \<le> cmod ((y-w)\<^sup>2)" if "r = cmod (z-y)" for y
+      by (smt (verit, best) d_def diff_add_cancel diff_diff_eq2 dist_norm mem_ball
+          norm_minus_commute norm_power norm_triangle_ineq2 power_mono that w)
+    have 1: "\<forall>\<^sub>F n in F. (\<lambda>x. f n x / (x-w)\<^sup>2) contour_integrable_on circlepath z r"
       by (force simp: holomorphic_on_open intro: w Cauchy_derivative_integral_circlepath eventually_mono [OF cont])
-    have 2: "uniform_limit (sphere z r) (\<lambda>n x. f n x / (x - w)\<^sup>2) (\<lambda>x. g x / (x - w)\<^sup>2) F"
+    have 2: "uniform_limit (sphere z r) (\<lambda>n x. f n x / (x-w)\<^sup>2) (\<lambda>x. g x / (x-w)\<^sup>2) F"
       unfolding uniform_limit_iff
     proof clarify
       fix e::real
       assume "e > 0"
       with \<open>r > 0\<close> 
-      have "\<forall>\<^sub>F n in F. \<forall>x. x \<noteq> w \<longrightarrow> cmod (z - x) = r \<longrightarrow> cmod (f n x - g x) < e * cmod ((x - w)\<^sup>2)"
+      have "\<forall>\<^sub>F n in F. \<forall>x. x \<noteq> w \<longrightarrow> cmod (z-x) = r \<longrightarrow> cmod (f n x - g x) < e * cmod ((x-w)\<^sup>2)"
         by (force simp: \<open>0 < d\<close> dist_norm dle intro: less_le_trans eventually_mono [OF uniform_limitD [OF ulim], of "e*d"])
       with \<open>r > 0\<close> \<open>e > 0\<close> 
-      show "\<forall>\<^sub>F n in F. \<forall>x\<in>sphere z r. dist (f n x / (x - w)\<^sup>2) (g x / (x - w)\<^sup>2) < e"
+      show "\<forall>\<^sub>F n in F. \<forall>x\<in>sphere z r. dist (f n x / (x-w)\<^sup>2) (g x / (x-w)\<^sup>2) < e"
         by (simp add: norm_divide field_split_simps sphere_def dist_norm)
     qed
-    have "((\<lambda>n. contour_integral (circlepath z r) (\<lambda>x. f n x / (x - w)\<^sup>2))
-             \<longlongrightarrow> contour_integral (circlepath z r) ((\<lambda>x. g x / (x - w)\<^sup>2))) F"
+    have "((\<lambda>n. contour_integral (circlepath z r) (\<lambda>x. f n x / (x-w)\<^sup>2))
+             \<longlongrightarrow> contour_integral (circlepath z r) ((\<lambda>x. g x / (x-w)\<^sup>2))) F"
       by (rule contour_integral_uniform_limit_circlepath [OF 1 2 F \<open>0 < r\<close>])
-    then have tendsto_0: "((\<lambda>n. 1 / (2 * of_real pi * \<i>) * (?conint (\<lambda>x. f n x / (x - w)\<^sup>2) - ?conint (\<lambda>x. g x / (x - w)\<^sup>2))) \<longlongrightarrow> 0) F"
+    then have tendsto_0: "((\<lambda>n. 1 / (2 * of_real pi * \<i>) * (?conint (\<lambda>x. f n x / (x-w)\<^sup>2) - ?conint (\<lambda>x. g x / (x-w)\<^sup>2))) \<longlongrightarrow> 0) F"
       using Lim_null by (force intro!: tendsto_mult_right_zero)
     have "((\<lambda>n. f' n w - g' w) \<longlongrightarrow> 0) F"
-      apply (rule Lim_transform_eventually [OF tendsto_0])
-      apply (force simp: divide_simps intro: eq_f' eventually_mono [OF cont])
-      done
+      by (force simp: divide_simps 
+          intro: eq_f' eventually_mono [OF cont] Lim_transform_eventually [OF tendsto_0])
     then show ?thesis using Lim_null by blast
   qed
   obtain g' where "\<And>w. w \<in> ball z r \<Longrightarrow> (g has_field_derivative (g' w)) (at w) \<and> ((\<lambda>n. f' n w) \<longlongrightarrow> g' w) F"
@@ -1343,13 +1319,13 @@
   fixes a :: "nat \<Rightarrow> complex" and r::real
   assumes "summable (\<lambda>n. a n * r^n)"
     shows "\<exists>g g'. \<forall>z. cmod z < r \<longrightarrow>
-             ((\<lambda>n. a n * z^n) sums g z) \<and> ((\<lambda>n. of_nat n * a n * z^(n - 1)) sums g' z) \<and> (g has_field_derivative g' z) (at z)"
+             ((\<lambda>n. a n * z^n) sums g z) \<and> ((\<lambda>n. of_nat n * a n * z^(n-1)) sums g' z) \<and> (g has_field_derivative g' z) (at z)"
 proof (cases "0 < r")
   case True
-    have der: "\<And>n z. ((\<lambda>x. a n * x ^ n) has_field_derivative of_nat n * a n * z ^ (n - 1)) (at z)"
+    have der: "\<And>n z. ((\<lambda>x. a n * x ^ n) has_field_derivative of_nat n * a n * z ^ (n-1)) (at z)"
       by (rule derivative_eq_intros | simp)+
     have y_le: "cmod y \<le> cmod (of_real r + of_real (cmod z)) / 2" 
-      if "cmod (z - y) * 2 < r - cmod z" for z y
+      if "cmod (z-y) * 2 < r - cmod z" for z y
       by (smt (verit, best) field_sum_of_halves norm_minus_commute norm_of_real norm_triangle_ineq2 of_real_add that)
     have "summable (\<lambda>n. a n * complex_of_real r ^ n)"
       using assms \<open>r > 0\<close> by simp
@@ -1359,7 +1335,7 @@
     ultimately have sum: "\<And>z. cmod z < r \<Longrightarrow> summable (\<lambda>n. of_real (cmod (a n)) * ((of_real r + complex_of_real (cmod z)) / 2) ^ n)"
       by (rule power_series_conv_imp_absconv_weak)
     have "\<exists>g g'. \<forall>z \<in> ball 0 r. (\<lambda>n.  (a n) * z ^ n) sums g z \<and>
-               (\<lambda>n. of_nat n * (a n) * z ^ (n - 1)) sums g' z \<and> (g has_field_derivative g' z) (at z)"
+               (\<lambda>n. of_nat n * (a n) * z ^ (n-1)) sums g' z \<and> (g has_field_derivative g' z) (at z)"
       apply (rule series_and_derivative_comparison_complex [OF open_ball der])
       apply (rule_tac x="(r - norm z)/2" in exI)
       apply (rule_tac x="\<lambda>n. of_real(norm(a n)*((r + norm z)/2)^n)" in exI)
@@ -1377,46 +1353,46 @@
   fixes a :: "nat \<Rightarrow> complex" and r::real
   assumes "summable (\<lambda>n. a n * r^n)"
     obtains g g' where "\<forall>z \<in> ball w r.
-             ((\<lambda>n. a n * (z - w) ^ n) sums g z) \<and> ((\<lambda>n. of_nat n * a n * (z - w) ^ (n - 1)) sums g' z) \<and>
+             ((\<lambda>n. a n * (z-w) ^ n) sums g z) \<and> ((\<lambda>n. of_nat n * a n * (z-w) ^ (n-1)) sums g' z) \<and>
               (g has_field_derivative g' z) (at z)"
   using power_series_and_derivative_0 [OF assms]
   apply clarify
-  apply (rule_tac g="(\<lambda>z. g(z - w))" in that)
+  apply (rule_tac g="(\<lambda>z. g(z-w))" in that)
   using DERIV_shift [where z="-w"]
   apply (auto simp: norm_minus_commute Ball_def dist_norm)
   done
 
 proposition\<^marker>\<open>tag unimportant\<close> power_series_holomorphic:
-  assumes "\<And>w. w \<in> ball z r \<Longrightarrow> ((\<lambda>n. a n*(w - z)^n) sums f w)"
+  assumes "\<And>w. w \<in> ball z r \<Longrightarrow> ((\<lambda>n. a n*(w-z)^n) sums f w)"
     shows "f holomorphic_on ball z r"
 proof -
   have "\<exists>f'. (f has_field_derivative f') (at w)" if w: "dist z w < r" for w
   proof -
-    have wz: "cmod (w - z) < r" using w
+    have wz: "cmod (w-z) < r" using w
       by (auto simp: field_split_simps dist_norm norm_minus_commute)
     then have "0 \<le> r"
       by (meson less_eq_real_def norm_ge_zero order_trans)
     have inb: "z + complex_of_real ((dist z w + r) / 2) \<in> ball z r"
       using w by (simp add: dist_norm \<open>0\<le>r\<close> flip: of_real_add)
-    have sum: "summable (\<lambda>n. a n * of_real (((cmod (z - w) + r) / 2) ^ n))"
+    have sum: "summable (\<lambda>n. a n * of_real (((cmod (z-w) + r) / 2) ^ n))"
       using assms [OF inb] by (force simp: summable_def dist_norm)
-    obtain g g' where gg': "\<And>u. u \<in> ball z ((cmod (z - w) + r) / 2) \<Longrightarrow>
-                               (\<lambda>n. a n * (u - z) ^ n) sums g u \<and>
-                               (\<lambda>n. of_nat n * a n * (u - z) ^ (n - 1)) sums g' u \<and> (g has_field_derivative g' u) (at u)"
+    obtain g g' where gg': "\<And>u. u \<in> ball z ((cmod (z-w) + r) / 2) \<Longrightarrow>
+                               (\<lambda>n. a n * (u-z) ^ n) sums g u \<and>
+                               (\<lambda>n. of_nat n * a n * (u-z) ^ (n-1)) sums g' u \<and> (g has_field_derivative g' u) (at u)"
       by (rule power_series_and_derivative [OF sum, of z]) fastforce
-    have [simp]: "g u = f u" if "cmod (u - w) < (r - cmod (z - w)) / 2" for u
+    have [simp]: "g u = f u" if "cmod (u-w) < (r - cmod (z-w)) / 2" for u
     proof -
-      have less: "cmod (z - u) * 2 < cmod (z - w) + r"
+      have less: "cmod (z-u) * 2 < cmod (z-w) + r"
         using that dist_triangle2 [of z u w]
         by (simp add: dist_norm [symmetric] algebra_simps)
-      have "(\<lambda>n. a n * (u - z) ^ n) sums g u" "(\<lambda>n. a n * (u - z) ^ n) sums f u"
+      have "(\<lambda>n. a n * (u-z) ^ n) sums g u" "(\<lambda>n. a n * (u-z) ^ n) sums f u"
         using gg' [of u] less w by (auto simp: assms dist_norm)
       then show ?thesis
         by (metis sums_unique2)
     qed
     have "(f has_field_derivative g' w) (at w)"
-      by (rule has_field_derivative_transform_within [where d="(r - norm(z - w))/2"])
-      (use w gg' [of w] in \<open>(force simp: dist_norm)+\<close>)
+    proof (rule has_field_derivative_transform_within [where d="(r - norm(z-w))/2"])
+    qed (use w gg' [of w] in \<open>(force simp: dist_norm)+\<close>)
     then show ?thesis ..
   qed
   then show ?thesis by (simp add: holomorphic_on_open)
@@ -1424,17 +1400,17 @@
 
 corollary holomorphic_iff_power_series:
      "f holomorphic_on ball z r \<longleftrightarrow>
-      (\<forall>w \<in> ball z r. (\<lambda>n. (deriv ^^ n) f z / (fact n) * (w - z)^n) sums f w)"
+      (\<forall>w \<in> ball z r. (\<lambda>n. (deriv ^^ n) f z / (fact n) * (w-z)^n) sums f w)"
   using power_series_holomorphic [where a = "\<lambda>n. (deriv ^^ n) f z / (fact n)"] holomorphic_power_series
   by blast
 
 lemma power_series_analytic:
-     "(\<And>w. w \<in> ball z r \<Longrightarrow> (\<lambda>n. a n*(w - z)^n) sums f w) \<Longrightarrow> f analytic_on ball z r"
+     "(\<And>w. w \<in> ball z r \<Longrightarrow> (\<lambda>n. a n*(w-z)^n) sums f w) \<Longrightarrow> f analytic_on ball z r"
   by (force simp: analytic_on_open intro!: power_series_holomorphic)
 
 lemma analytic_iff_power_series:
      "f analytic_on ball z r \<longleftrightarrow>
-      (\<forall>w \<in> ball z r. (\<lambda>n. (deriv ^^ n) f z / (fact n) * (w - z)^n) sums f w)"
+      (\<forall>w \<in> ball z r. (\<lambda>n. (deriv ^^ n) f z / (fact n) * (w-z)^n) sums f w)"
   by (simp add: analytic_on_open holomorphic_iff_power_series)
 
 subsection\<^marker>\<open>tag unimportant\<close> \<open>Equality between holomorphic functions, on open ball then connected set\<close>
@@ -1444,7 +1420,7 @@
      w \<in> ball z r;
      \<And>n. (deriv ^^ n) f z = (deriv ^^ n) g z\<rbrakk>
      \<Longrightarrow> f w = g w"
-  by (auto simp: holomorphic_iff_power_series sums_unique2 [of "\<lambda>n. (deriv ^^ n) f z / (fact n) * (w - z)^n"])
+  by (auto simp: holomorphic_iff_power_series sums_unique2 [of "\<lambda>n. (deriv ^^ n) f z / (fact n) * (w-z)^n"])
 
 lemma holomorphic_fun_eq_0_on_ball:
    "\<lbrakk>f holomorphic_on ball z r;  w \<in> ball z r;
@@ -1518,13 +1494,13 @@
 lemma pole_lemma:
   assumes holf: "f holomorphic_on S" and a: "a \<in> interior S"
     shows "(\<lambda>z. if z = a then deriv f a
-                 else (f z - f a) / (z - a)) holomorphic_on S" (is "?F holomorphic_on S")
+                else (f z - f a) / (z-a)) holomorphic_on S" (is "?F holomorphic_on S")
 proof -
   have *: "?F field_differentiable (at u within S)" if "u \<in> S" "u \<noteq> a" for u
   proof -
     have fcd: "f field_differentiable at u within S"
       using holf holomorphic_on_def by (simp add: \<open>u \<in> S\<close>)
-    have cd: "(\<lambda>z. (f z - f a) / (z - a)) field_differentiable at u within S"
+    have cd: "(\<lambda>z. (f z - f a) / (z-a)) field_differentiable at u within S"
       by (rule fcd derivative_intros | simp add: that)+
     have "0 < dist a u" using that dist_nz by blast
     then show ?thesis
@@ -1538,7 +1514,7 @@
     have 2: "?F holomorphic_on ball a e - {a}"
       using mem_ball that
       by (auto simp add: holomorphic_on_def simp flip: field_differentiable_def intro: * field_differentiable_within_subset)
-    have "isCont (\<lambda>z. if z = a then deriv f a else (f z - f a) / (z - a)) x"
+    have "isCont (\<lambda>z. if z = a then deriv f a else (f z - f a) / (z-a)) x"
             if "dist a x < e" for x
     proof (cases "x=a")
       case True
@@ -1555,50 +1531,47 @@
     have "?F holomorphic_on ball a e"
       by (auto intro: no_isolated_singularity [OF 1 2])
     with that show ?thesis
-      by (simp add: holomorphic_on_open field_differentiable_def [symmetric]
-                    field_differentiable_at_within)
+      by (simp add: holomorphic_on_imp_differentiable_at)
   qed
   ultimately show ?thesis
-    by (metis (no_types, lifting) holomorphic_onI a field_differentiable_at_within interior_subset openE open_interior subset_iff)
+    by (metis (lifting) a at_within_interior holomorphic_onI mem_interior)
 qed
 
 lemma pole_theorem:
   assumes holg: "g holomorphic_on S" and a: "a \<in> interior S"
-      and eq: "\<And>z. z \<in> S - {a} \<Longrightarrow> g z = (z - a) * f z"
+      and eq: "\<And>z. z \<in> S - {a} \<Longrightarrow> g z = (z-a) * f z"
     shows "(\<lambda>z. if z = a then deriv g a
-                 else f z - g a/(z - a)) holomorphic_on S"
+                 else f z - g a/(z-a)) holomorphic_on S"
   using pole_lemma [OF holg a]
   by (rule holomorphic_transform) (simp add: eq field_split_simps)
 
 lemma pole_lemma_open:
   assumes "f holomorphic_on S" "open S"
-    shows "(\<lambda>z. if z = a then deriv f a else (f z - f a)/(z - a)) holomorphic_on S"
+    shows "(\<lambda>z. if z = a then deriv f a else (f z - f a)/(z-a)) holomorphic_on S"
 proof (cases "a \<in> S")
   case True with assms interior_eq pole_lemma
     show ?thesis by fastforce
 next
   case False 
-  then have "(\<lambda>z. (f z - f a) / (z - a)) field_differentiable at x within S"
+  then have "(\<lambda>z. (f z - f a) / (z-a)) field_differentiable at x within S"
     if "x \<in> S" for x
-    using assms that 
-    apply (simp add: holomorphic_on_def)
-    apply (rule derivative_intros | force)+
-    done
+    using assms that unfolding holomorphic_on_def
+    by (intro derivative_intros) auto
   with False show ?thesis
     using holomorphic_on_def holomorphic_transform by presburger
 qed
 
 lemma pole_theorem_open:
   assumes holg: "g holomorphic_on S" and S: "open S"
-      and eq: "\<And>z. z \<in> S - {a} \<Longrightarrow> g z = (z - a) * f z"
+      and eq: "\<And>z. z \<in> S - {a} \<Longrightarrow> g z = (z-a) * f z"
     shows "(\<lambda>z. if z = a then deriv g a
-                 else f z - g a/(z - a)) holomorphic_on S"
+                 else f z - g a/(z-a)) holomorphic_on S"
   using pole_lemma_open [OF holg S]
   by (rule holomorphic_transform) (auto simp: eq divide_simps)
 
 lemma pole_theorem_0:
   assumes holg: "g holomorphic_on S" and a: "a \<in> interior S"
-      and eq: "\<And>z. z \<in> S - {a} \<Longrightarrow> g z = (z - a) * f z"
+      and eq: "\<And>z. z \<in> S - {a} \<Longrightarrow> g z = (z-a) * f z"
       and [simp]: "f a = deriv g a" "g a = 0"
     shows "f holomorphic_on S"
   using pole_theorem [OF holg a eq]
@@ -1606,7 +1579,7 @@
 
 lemma pole_theorem_open_0:
   assumes holg: "g holomorphic_on S" and S: "open S"
-      and eq: "\<And>z. z \<in> S - {a} \<Longrightarrow> g z = (z - a) * f z"
+      and eq: "\<And>z. z \<in> S - {a} \<Longrightarrow> g z = (z-a) * f z"
       and [simp]: "f a = deriv g a" "g a = 0"
     shows "f holomorphic_on S"
   using pole_theorem_open [OF holg S eq]
@@ -1615,15 +1588,15 @@
 lemma pole_theorem_analytic:
   assumes g: "g analytic_on S"
       and eq: "\<And>z. z \<in> S
-             \<Longrightarrow> \<exists>d. 0 < d \<and> (\<forall>w \<in> ball z d - {a}. g w = (w - a) * f w)"
-    shows "(\<lambda>z. if z = a then deriv g a else f z - g a/(z - a)) analytic_on S" (is "?F analytic_on S")
+             \<Longrightarrow> \<exists>d. 0 < d \<and> (\<forall>w \<in> ball z d - {a}. g w = (w-a) * f w)"
+    shows "(\<lambda>z. if z = a then deriv g a else f z - g a/(z-a)) analytic_on S" (is "?F analytic_on S")
   unfolding analytic_on_def
 proof
   fix x
   assume "x \<in> S"
   with g obtain e where "0 < e" and e: "g holomorphic_on ball x e"
     by (auto simp add: analytic_on_def)
-  obtain d where "0 < d" and d: "\<And>w. w \<in> ball x d - {a} \<Longrightarrow> g w = (w - a) * f w"
+  obtain d where "0 < d" and d: "\<And>w. w \<in> ball x d - {a} \<Longrightarrow> g w = (w-a) * f w"
     using \<open>x \<in> S\<close> eq by blast
   have "?F holomorphic_on ball x (min d e)"
     using d e \<open>x \<in> S\<close> by (fastforce simp: holomorphic_on_subset subset_ball intro!: pole_theorem_open)
@@ -1633,11 +1606,11 @@
 
 lemma pole_theorem_analytic_0:
   assumes g: "g analytic_on S"
-      and eq: "\<And>z. z \<in> S \<Longrightarrow> \<exists>d. 0 < d \<and> (\<forall>w \<in> ball z d - {a}. g w = (w - a) * f w)"
+      and eq: "\<And>z. z \<in> S \<Longrightarrow> \<exists>d. 0 < d \<and> (\<forall>w \<in> ball z d - {a}. g w = (w-a) * f w)"
       and [simp]: "f a = deriv g a" "g a = 0"
     shows "f analytic_on S"
 proof -
-  have [simp]: "(\<lambda>z. if z = a then deriv g a else f z - g a / (z - a)) = f"
+  have [simp]: "(\<lambda>z. if z = a then deriv g a else f z - g a / (z-a)) = f"
     by auto
   show ?thesis
     using pole_theorem_analytic [OF g eq] by simp
@@ -1645,26 +1618,25 @@
 
 lemma pole_theorem_analytic_open_superset:
   assumes g: "g analytic_on S" and "S \<subseteq> T" "open T"
-      and eq: "\<And>z. z \<in> T - {a} \<Longrightarrow> g z = (z - a) * f z"
-    shows "(\<lambda>z. if z = a then deriv g a
-                 else f z - g a/(z - a)) analytic_on S"
+      and eq: "\<And>z. z \<in> T - {a} \<Longrightarrow> g z = (z-a) * f z"
+    shows "(\<lambda>z. if z = a then deriv g a else f z - g a/(z-a)) analytic_on S"
 proof (rule pole_theorem_analytic [OF g])
   fix z
   assume "z \<in> S"
   then obtain e where "0 < e" and e: "ball z e \<subseteq> T"
     using assms openE by blast
-  then show "\<exists>d>0. \<forall>w\<in>ball z d - {a}. g w = (w - a) * f w"
+  then show "\<exists>d>0. \<forall>w\<in>ball z d - {a}. g w = (w-a) * f w"
     using eq by auto
 qed
 
 lemma pole_theorem_analytic_open_superset_0:
-  assumes g: "g analytic_on S" "S \<subseteq> T" "open T" "\<And>z. z \<in> T - {a} \<Longrightarrow> g z = (z - a) * f z"
+  assumes g: "g analytic_on S" "S \<subseteq> T" "open T" "\<And>z. z \<in> T - {a} \<Longrightarrow> g z = (z-a) * f z"
       and [simp]: "f a = deriv g a" "g a = 0"
     shows "f analytic_on S"
 proof -
-  have [simp]: "(\<lambda>z. if z = a then deriv g a else f z - g a / (z - a)) = f"
+  have [simp]: "(\<lambda>z. if z = a then deriv g a else f z - g a / (z-a)) = f"
     by auto
-  have "(\<lambda>z. if z = a then deriv g a else f z - g a/(z - a)) analytic_on S"
+  have "(\<lambda>z. if z = a then deriv g a else f z - g a/(z-a)) analytic_on S"
     by (rule pole_theorem_analytic_open_superset [OF g])
   then show ?thesis by simp
 qed
@@ -1680,9 +1652,9 @@
       and abu: "closed_segment a b \<subseteq> U"
     shows "continuous_on U (\<lambda>w. contour_integral (linepath a b) (F w))"
 proof -
-  have *: "\<exists>d>0. \<forall>x'\<in>U. dist x' w < d \<longrightarrow>
-                         dist (contour_integral (linepath a b) (F x'))
-                              (contour_integral (linepath a b) (F w)) \<le> \<epsilon>"
+  have "\<exists>d>0. \<forall>x'\<in>U. dist x' w < d \<longrightarrow>
+                     dist (contour_integral (linepath a b) (F x'))
+                          (contour_integral (linepath a b) (F w)) \<le> \<epsilon>"
           if "w \<in> U" "0 < \<epsilon>" "a \<noteq> b" for w \<epsilon>
   proof -
     obtain \<delta> where "\<delta>>0" and \<delta>: "cball w \<delta> \<subseteq> U" using open_contains_cball \<open>open U\<close> \<open>w \<in> U\<close> by force
@@ -1692,12 +1664,12 @@
           cond_uu continuous_on_subset)
     then obtain \<eta> where "\<eta>>0"
         and \<eta>: "\<And>x x'. \<lbrakk>x\<in>?TZ; x'\<in>?TZ; dist x' x < \<eta>\<rbrakk> \<Longrightarrow>
-                         dist ((\<lambda>(x,y). F x y) x') ((\<lambda>(x,y). F x y) x) < \<epsilon>/norm(b - a)"
+                         dist ((\<lambda>(x,y). F x y) x') ((\<lambda>(x,y). F x y) x) < \<epsilon>/norm(b-a)"
       using \<open>0 < \<epsilon>\<close> \<open>a \<noteq> b\<close>
-      by (auto elim: uniformly_continuous_onE [where e = "\<epsilon>/norm(b - a)"])
+      by (auto elim: uniformly_continuous_onE [where e = "\<epsilon>/norm(b-a)"])
     have \<eta>: "\<lbrakk>norm (w - x1) \<le> \<delta>;   x2 \<in> closed_segment a b;
               norm (w - x1') \<le> \<delta>;  x2' \<in> closed_segment a b; norm ((x1', x2') - (x1, x2)) < \<eta>\<rbrakk>
-              \<Longrightarrow> norm (F x1' x2' - F x1 x2) \<le> \<epsilon> / cmod (b - a)"
+              \<Longrightarrow> norm (F x1' x2' - F x1 x2) \<le> \<epsilon> / cmod (b-a)"
              for x1 x2 x1' x2'
       using \<eta> [of "(x1,x2)" "(x1',x2')"] by (force simp: dist_norm)
     have le_ee: "cmod (contour_integral (linepath a b) (\<lambda>x. F x' x - F w x)) \<le> \<epsilon>"
@@ -1705,23 +1677,20 @@
     proof -
       have "(\<lambda>x. F x' x - F w x) contour_integrable_on linepath a b"
         by (simp add: \<open>w \<in> U\<close> cont_dw contour_integrable_diff that)
-      then have "cmod (contour_integral (linepath a b) (\<lambda>x. F x' x - F w x)) \<le> \<epsilon>/norm(b - a) * norm(b - a)"
+      then have "cmod (contour_integral (linepath a b) (\<lambda>x. F x' x - F w x)) \<le> \<epsilon>/norm(b-a) * norm(b-a)"
         using has_contour_integral_bound_linepath [OF has_contour_integral_integral _ \<eta>]
         using \<open>0 < \<epsilon>\<close> \<open>0 < \<delta>\<close> that by (force simp: norm_minus_commute)
       also have "\<dots> = \<epsilon>" using \<open>a \<noteq> b\<close> by simp
       finally show ?thesis .
     qed
     show ?thesis
-      apply (rule_tac x="min \<delta> \<eta>" in exI)
-      using \<open>0 < \<delta>\<close> \<open>0 < \<eta>\<close>
-      by (auto simp: dist_norm contour_integral_diff [OF cont_dw cont_dw, symmetric] \<open>w \<in> U\<close> intro: le_ee)
+      using \<open>0 < \<delta>\<close> \<open>0 < \<eta>\<close> \<open>w \<in> U\<close>
+      apply (intro exI[where x="min \<delta> \<eta>"])
+      by (auto simp: dist_norm contour_integral_diff [OF cont_dw cont_dw, symmetric]  intro: le_ee)
   qed
-  show ?thesis
-  proof (cases "a=b")
-    case False
-    show ?thesis
-      by (rule continuous_onI) (use False in \<open>auto intro: *\<close>)
-  qed auto
+  then show ?thesis
+    by (metis (no_types, lifting) continuous_onI continuous_on_iff
+        contour_integral_trivial dist_self)
 qed
 
 text\<open>This version has \<^term>\<open>polynomial_function \<gamma>\<close> as an additional assumption.\<close>
@@ -1730,7 +1699,7 @@
         and z: "z \<in> U" and \<gamma>: "polynomial_function \<gamma>"
         and pasz: "path_image \<gamma> \<subseteq> U - {z}" and loop: "pathfinish \<gamma> = pathstart \<gamma>"
         and zero: "\<And>w. w \<notin> U \<Longrightarrow> winding_number \<gamma> w = 0"
-      shows "((\<lambda>w. f w / (w - z)) has_contour_integral (2*pi * \<i> * winding_number \<gamma> z * f z)) \<gamma>"
+      shows "((\<lambda>w. f w / (w-z)) has_contour_integral (2*pi * \<i> * winding_number \<gamma> z * f z)) \<gamma>"
 proof -
   obtain \<gamma>' where pf\<gamma>': "polynomial_function \<gamma>'" and \<gamma>': "\<And>x. (\<gamma> has_vector_derivative (\<gamma>' x)) (at x)"
     using has_vector_derivative_polynomial_function [OF \<gamma>] by blast
@@ -1738,7 +1707,7 @@
     by (simp add: path_image_def compact_imp_bounded compact_continuous_image continuous_on_polymonial_function)
   then obtain B where "B>0" and B: "\<And>x. x \<in> path_image \<gamma>' \<Longrightarrow> norm x \<le> B"
     using bounded_pos by force
-  define d where [abs_def]: "d z w = (if w = z then deriv f z else (f w - f z)/(w - z))" for z w
+  define d where [abs_def]: "d z w = (if w = z then deriv f z else (f w - f z)/(w-z))" for z w
   define v where "v = {w. w \<notin> path_image \<gamma> \<and> winding_number \<gamma> w = 0}"
   have "path \<gamma>" "valid_path \<gamma>" using \<gamma>
     by (auto simp: path_polynomial_function valid_path_polynomial_function)
@@ -1750,18 +1719,18 @@
     by (metis holf holomorphic_on_imp_continuous_on)
   have hol_d: "(d y) holomorphic_on U" if "y \<in> U" for y
   proof -
-    have *: "(\<lambda>c. if c = y then deriv f y else (f c - f y) / (c - y)) holomorphic_on U"
+    have *: "(\<lambda>c. if c = y then deriv f y else (f c - f y) / (c-y)) holomorphic_on U"
       by (simp add: holf pole_lemma_open \<open>open U\<close>)
-    then have "isCont (\<lambda>x. if x = y then deriv f y else (f x - f y) / (x - y)) y"
+    then have "isCont (\<lambda>x. if x = y then deriv f y else (f x - f y) / (x-y)) y"
       using at_within_open field_differentiable_imp_continuous_at holomorphic_on_def that \<open>open U\<close> by fastforce
     then have "continuous_on U (d y)"
       using "*" d_def holomorphic_on_imp_continuous_on by auto
     moreover have "d y holomorphic_on U - {y}"
     proof -
-      have "(\<lambda>w. if w = y then deriv f y else (f w - f y) / (w - y)) field_differentiable at w"
+      have "(\<lambda>w. if w = y then deriv f y else (f w - f y) / (w-y)) field_differentiable at w"
         if "w \<in> U - {y}" for w
       proof (rule field_differentiable_transform_within)
-        show "(\<lambda>w. (f w - f y) / (w - y)) field_differentiable at w"
+        show "(\<lambda>w. (f w - f y) / (w-y)) field_differentiable at w"
           using that \<open>open U\<close> holf 
           by (auto intro!: holomorphic_on_imp_differentiable_at derivative_intros)
         show "dist w y > 0"
@@ -1773,43 +1742,44 @@
     ultimately show ?thesis
       by (rule no_isolated_singularity) (auto simp: \<open>open U\<close>)
   qed
-  have cint_fxy: "(\<lambda>x. (f x - f y) / (x - y)) contour_integrable_on \<gamma>" if "y \<notin> path_image \<gamma>" for y
+  have cint_fxy: "(\<lambda>x. (f x - f y) / (x-y)) contour_integrable_on \<gamma>" if "y \<notin> path_image \<gamma>" for y
   proof (rule contour_integrable_holomorphic_simple [where S = "U-{y}"])
-    show "(\<lambda>x. (f x - f y) / (x - y)) holomorphic_on U - {y}"
+    show "(\<lambda>x. (f x - f y) / (x-y)) holomorphic_on U - {y}"
       by (force intro: holomorphic_intros holomorphic_on_subset [OF holf])
     show "path_image \<gamma> \<subseteq> U - {y}"
       using pasz that by blast
   qed (auto simp: \<open>open U\<close> open_delete \<open>valid_path \<gamma>\<close>)
   define h where
-    "h z = (if z \<in> U then contour_integral \<gamma> (d z) else contour_integral \<gamma> (\<lambda>w. f w/(w - z)))" for z
+    "h z = (if z \<in> U then contour_integral \<gamma> (d z) else contour_integral \<gamma> (\<lambda>w. f w/(w-z)))" for z
   have U: "((d z) has_contour_integral h z) \<gamma>" if "z \<in> U" for z
   proof -
     have "d z holomorphic_on U"
       by (simp add: hol_d that)
     with that show ?thesis
-      by (metis Diff_subset \<open>valid_path \<gamma>\<close> \<open>open U\<close> contour_integrable_holomorphic_simple h_def has_contour_integral_integral pasz subset_trans)
+      by (metis Diff_subset \<open>valid_path \<gamma>\<close> \<open>open U\<close> contour_integrable_holomorphic_simple h_def 
+          has_contour_integral_integral pasz subset_trans)
   qed
-  have V: "((\<lambda>w. f w / (w - z)) has_contour_integral h z) \<gamma>" if z: "z \<in> v" for z
+  have V: "((\<lambda>w. f w / (w-z)) has_contour_integral h z) \<gamma>" if z: "z \<in> v" for z
   proof -
     have 0: "0 = (f z) * 2 * of_real (2 * pi) * \<i> * winding_number \<gamma> z"
       using v_def z by auto
-    then have "((\<lambda>x. 1 / (x - z)) has_contour_integral 0) \<gamma>"
+    then have "((\<lambda>x. 1 / (x-z)) has_contour_integral 0) \<gamma>"
      using z v_def  has_contour_integral_winding_number [OF \<open>valid_path \<gamma>\<close>] by fastforce
-    then have "((\<lambda>x. f z * (1 / (x - z))) has_contour_integral 0) \<gamma>"
+    then have "((\<lambda>x. f z * (1 / (x-z))) has_contour_integral 0) \<gamma>"
       using has_contour_integral_lmul by fastforce
-    then have "((\<lambda>x. f z / (x - z)) has_contour_integral 0) \<gamma>"
+    then have "((\<lambda>x. f z / (x-z)) has_contour_integral 0) \<gamma>"
       by (simp add: field_split_simps)
-    moreover have "((\<lambda>x. (f x - f z) / (x - z)) has_contour_integral contour_integral \<gamma> (d z)) \<gamma>"
+    moreover have "((\<lambda>x. (f x - f z) / (x-z)) has_contour_integral contour_integral \<gamma> (d z)) \<gamma>"
       by (metis (no_types, lifting) z cint_fxy contour_integral_eq d_def has_contour_integral_integral mem_Collect_eq v_def)
-    ultimately have *: "((\<lambda>x. f z / (x - z) + (f x - f z) / (x - z)) has_contour_integral (0 + contour_integral \<gamma> (d z))) \<gamma>"
+    ultimately have *: "((\<lambda>x. f z / (x-z) + (f x - f z) / (x-z)) has_contour_integral (0 + contour_integral \<gamma> (d z))) \<gamma>"
       by (rule has_contour_integral_add)
-    have "((\<lambda>w. f w / (w - z)) has_contour_integral contour_integral \<gamma> (d z)) \<gamma>"
+    have "((\<lambda>w. f w / (w-z)) has_contour_integral contour_integral \<gamma> (d z)) \<gamma>"
       if "z \<in> U"
       using * by (auto simp: divide_simps has_contour_integral_eq)
-    moreover have "((\<lambda>w. f w / (w - z)) has_contour_integral contour_integral \<gamma> (\<lambda>w. f w / (w - z))) \<gamma>"
+    moreover have "((\<lambda>w. f w / (w-z)) has_contour_integral contour_integral \<gamma> (\<lambda>w. f w / (w-z))) \<gamma>"
       if "z \<notin> U"
     proof (rule has_contour_integral_integral [OF contour_integrable_holomorphic_simple [where S=U]])
-      show "(\<lambda>w. f w / (w - z)) holomorphic_on U"
+      show "(\<lambda>w. f w / (w-z)) holomorphic_on U"
         by (rule holomorphic_intros assms | use that in force)+
     qed (use \<open>open U\<close> pasz \<open>valid_path \<gamma>\<close> in auto)
     ultimately show ?thesis
@@ -1825,7 +1795,8 @@
     show "0 < d0 / 2" using \<open>0 < d0\<close> by auto
   qed (use \<open>0 < d0\<close> d0 in \<open>force simp: dist_norm\<close>)
   define T where "T \<equiv> {y + k |y k. y \<in> path_image \<gamma> \<and> k \<in> cball 0 (dd / 2)}"
-  have "\<And>x x'. \<lbrakk>x \<in> path_image \<gamma>; dist x x' * 2 < dd\<rbrakk> \<Longrightarrow> \<exists>y k. x' = y + k \<and> y \<in> path_image \<gamma> \<and> dist 0 k * 2 \<le> dd"
+  have "\<And>x x'. \<lbrakk>x \<in> path_image \<gamma>; dist x x' * 2 < dd\<rbrakk> 
+              \<Longrightarrow> \<exists>y k. x' = y + k \<and> y \<in> path_image \<gamma> \<and> dist 0 k * 2 \<le> dd"
     by (metis add.commute diff_add_cancel dist_0_norm dist_commute dist_norm less_eq_real_def)
   then have subt: "path_image \<gamma> \<subseteq> interior T"
     using \<open>0 < dd\<close> 
@@ -1860,31 +1831,31 @@
       show "path_image \<gamma> \<subseteq> cball 0 C"
         by (meson C interior_subset mem_cball_0 subset_eq subt)
     qed (use ybig loop \<open>path \<gamma>\<close> in auto)
-    have [simp]: "h y = contour_integral \<gamma> (\<lambda>w. f w/(w - y))"
+    have [simp]: "h y = contour_integral \<gamma> (\<lambda>w. f w/(w-y))"
       by (rule contour_integral_unique [symmetric]) (simp add: v_def ynot V)
-    have holint: "(\<lambda>w. f w / (w - y)) holomorphic_on interior T"
+    have holint: "(\<lambda>w. f w / (w-y)) holomorphic_on interior T"
     proof (intro holomorphic_intros)
       show "f holomorphic_on interior T"
         using holf holomorphic_on_subset interior_subset T by blast
     qed (use \<open>y \<notin> T\<close> interior_subset in auto)
-    have leD: "cmod (f z / (z - y)) \<le> D * (e / L / D)" if z: "z \<in> interior T" for z
+    have leD: "cmod (f z / (z-y)) \<le> D * (e / L / D)" if z: "z \<in> interior T" for z
     proof -
       have "D * L / e + cmod z \<le> cmod y"
         using le C [of z] z using interior_subset by force
-      then have DL2: "D * L / e \<le> cmod (z - y)"
+      then have DL2: "D * L / e \<le> cmod (z-y)"
         using norm_triangle_ineq2 [of y z] by (simp add: norm_minus_commute)
-      have "cmod (f z / (z - y)) = cmod (f z) * inverse (cmod (z - y))"
+      have "cmod (f z / (z-y)) = cmod (f z) * inverse (cmod (z-y))"
         by (simp add: norm_mult norm_inverse Fields.field_class.field_divide_inverse)
       also have "\<dots> \<le> D * (e / L / D)"
       proof (rule mult_mono)
         show "cmod (f z) \<le> D"
           using D interior_subset z by blast 
-        show "inverse (cmod (z - y)) \<le> e / L / D" "D \<ge> 0"
+        show "inverse (cmod (z-y)) \<le> e / L / D" "D \<ge> 0"
           using \<open>L>0\<close> \<open>e>0\<close> \<open>D>0\<close> DL2 by (auto simp: norm_divide field_split_simps)
       qed auto
       finally show ?thesis .
     qed
-    have "dist (h y) 0 = cmod (contour_integral \<gamma> (\<lambda>w. f w / (w - y)))"
+    have "dist (h y) 0 = cmod (contour_integral \<gamma> (\<lambda>w. f w / (w-y)))"
       by (simp add: dist_norm)
     also have "\<dots> \<le> L * (D * (e / L / D))"
       by (rule L [OF holint leD])
@@ -1896,7 +1867,7 @@
     by (meson Lim_at_infinityI)
   moreover have "h holomorphic_on UNIV"
   proof -
-    have con_ff: "continuous (at (x,z)) (\<lambda>(x,y). (f y - f x) / (y - x))"
+    have con_ff: "continuous (at (x,z)) (\<lambda>(x,y). (f y - f x) / (y-x))"
                  if "x \<in> U" "z \<in> U" "x \<noteq> z" for x z
       using that conf
       apply (simp add: split_def continuous_on_eq_continuous_at \<open>open U\<close>)
@@ -1915,7 +1886,7 @@
     have con_derf: "continuous (at z) (deriv f)" if "z \<in> U" for z
       by (meson analytic_at analytic_at_imp_isCont assms(1) holf holomorphic_deriv that)
     have tendsto_f': "((\<lambda>(x,y). if y = x then deriv f (x)
-                                else (f (y) - f (x)) / (y - x)) \<longlongrightarrow> deriv f x)
+                                else (f (y) - f (x)) / (y-x)) \<longlongrightarrow> deriv f x)
                       (at (x, x) within U \<times> U)" if "x \<in> U" for x
     proof (rule Lim_withinI)
       fix e::real assume "0 < e"
@@ -1928,7 +1899,7 @@
                     if "z' \<noteq> x'" and less_k1: "norm (x'-x, z'-x) < k1" and less_k2: "norm (x'-x, z'-x) < k2"
                  for x' z'
       proof -
-        have cs_less: "w \<in> closed_segment x' z' \<Longrightarrow> cmod (w - x) \<le> norm (x'-x, z'-x)" for w
+        have cs_less: "w \<in> closed_segment x' z' \<Longrightarrow> cmod (w-x) \<le> norm (x'-x, z'-x)" for w
           using segment_furthest_le [of w x' z' x]
           by (metis (no_types) dist_commute dist_norm norm_fst_le norm_snd_le order_trans)
         have derf_le: "w \<in> closed_segment x' z' \<Longrightarrow> z' \<noteq> x' \<Longrightarrow> cmod (deriv f w - deriv f x) \<le> e" for w
@@ -1952,7 +1923,7 @@
       qed
       show "\<exists>d>0. \<forall>xa\<in>U \<times> U.
                   0 < dist xa (x, x) \<and> dist xa (x, x) < d \<longrightarrow>
-                  dist (case xa of (x, y) \<Rightarrow> if y = x then deriv f x else (f y - f x) / (y - x)) (deriv f x) \<le> e"
+                  dist (case xa of (x, y) \<Rightarrow> if y = x then deriv f x else (f y - f x) / (y-x)) (deriv f x) \<le> e"
         apply (rule_tac x="min k1 k2" in exI)
         using \<open>k1>0\<close> \<open>k2>0\<close> \<open>e>0\<close>
         by (force simp: dist_norm neq intro: dual_order.strict_trans2 k1 less_imp_le norm_fst_le)
@@ -1961,32 +1932,32 @@
       by (meson holf holomorphic_on_imp_continuous_on holomorphic_on_subset interior_subset subt T)
     have le_B: "\<And>T. T \<in> {0..1} \<Longrightarrow> cmod (vector_derivative \<gamma> (at T)) \<le> B"
       using \<gamma>' B by (simp add: path_image_def vector_derivative_at rev_image_eqI)
-    have f_has_cint: "\<And>w. w \<in> v - path_image \<gamma> \<Longrightarrow> ((\<lambda>u. f u / (u - w) ^ 1) has_contour_integral h w) \<gamma>"
+    have f_has_cint: "\<And>w. w \<in> v - path_image \<gamma> \<Longrightarrow> ((\<lambda>u. f u / (u-w) ^ 1) has_contour_integral h w) \<gamma>"
       by (simp add: V)
-    have cond_uu: "continuous_on (U \<times> U) (\<lambda>(x,y). d x y)"
-      apply (simp add: continuous_on_eq_continuous_within d_def continuous_within tendsto_f')
-      apply (simp add: tendsto_within_open_NO_MATCH open_Times \<open>open U\<close>, clarify)
-      apply (rule Lim_transform_within_open [OF _ open_uu_Id, where f = "(\<lambda>(x,y). (f y - f x) / (y - x))"])
-      using con_ff
-      apply (auto simp: continuous_within)
-      done
+    have "\<And>x y. \<lbrakk>x \<in> U; y \<in> U; y \<noteq> x\<rbrakk> \<Longrightarrow> (\<lambda>(x, y). d x y) \<midarrow>(x, y)\<rightarrow> (f y - f x) / (y - x)"
+      unfolding d_def
+      apply (rule Lim_transform_within_open [OF _ open_uu_Id, where f = "(\<lambda>(x,y). (f y - f x) / (y-x))"])
+      using con_ff by (auto simp: continuous_within)
+    then have cond_uu: "continuous_on (U \<times> U) (\<lambda>(x,y). d x y)"
+      unfolding continuous_on_eq_continuous_within continuous_within d_def
+      by (fastforce simp add: tendsto_f' intro: Lim_at_imp_Lim_at_within)
     have hol_dw: "(\<lambda>z. d z w) holomorphic_on U" if "w \<in> U" for w
     proof -
       have "continuous_on U ((\<lambda>(x,y). d x y) \<circ> (\<lambda>z. (w,z)))"
         by (rule continuous_on_compose continuous_intros continuous_on_subset [OF cond_uu] | force intro: that)+
-      then have *: "continuous_on U (\<lambda>z. if w = z then deriv f z else (f w - f z) / (w - z))"
+      then have *: "continuous_on U (\<lambda>z. if w = z then deriv f z else (f w - f z) / (w-z))"
         by (rule rev_iffD1 [OF _ continuous_on_cong [OF refl]]) (simp add: d_def field_simps)
-      have **: "(\<lambda>z. if w = z then deriv f z else (f w - f z) / (w - z)) field_differentiable at x"
+      have **: "(\<lambda>z. if w = z then deriv f z else (f w - f z) / (w-z)) field_differentiable at x"
         if "x \<in> U" "x \<noteq> w" for x
-      proof (rule_tac f = "\<lambda>x. (f w - f x)/(w - x)" and d = "dist x w" in field_differentiable_transform_within)
-        show "(\<lambda>x. (f w - f x) / (w - x)) field_differentiable at x"
+      proof (rule_tac f = "\<lambda>x. (f w - f x)/(w-x)" and d = "dist x w" in field_differentiable_transform_within)
+        show "(\<lambda>x. (f w - f x) / (w-x)) field_differentiable at x"
           using that \<open>open U\<close>
           by (intro derivative_intros holomorphic_on_imp_differentiable_at [OF holf]; force)
       qed (use that \<open>open U\<close> in \<open>auto simp: dist_commute\<close>)
       show ?thesis
         unfolding d_def
       proof (rule no_isolated_singularity [OF * _ \<open>open U\<close>])
-        show "(\<lambda>z. if w = z then deriv f z else (f w - f z) / (w - z)) holomorphic_on U - {w}"
+        show "(\<lambda>z. if w = z then deriv f z else (f w - f z) / (w-z)) holomorphic_on U - {w}"
           by (auto simp: field_differentiable_def [symmetric] holomorphic_on_open open_Diff \<open>open U\<close> **)
       qed auto
     qed
@@ -2048,7 +2019,7 @@
             and kk: "\<And>x x'. \<lbrakk>x \<in> ?ddpa; x' \<in> ?ddpa; dist x' x < kk\<rbrakk> \<Longrightarrow>
                              dist ((\<lambda>(x,y). d x y) x') ((\<lambda>(x,y). d x y) x) < ee"
             by (rule uniformly_continuous_onE [where e = ee]) (use \<open>0 < ee\<close> in auto)
-          have kk: "\<lbrakk>norm (w - x) \<le> dd; z \<in> path_image \<gamma>; norm ((w, z) - (x, z)) < kk\<rbrakk> \<Longrightarrow> norm (d w z - d x z) < ee"
+          have kk: "\<lbrakk>norm (w-x) \<le> dd; z \<in> path_image \<gamma>; norm ((w, z) - (x, z)) < kk\<rbrakk> \<Longrightarrow> norm (d w z - d x z) < ee"
             for  w z
             using \<open>dd>0\<close> kk [of "(x,z)" "(w,z)"] by (force simp: norm_minus_commute dist_norm)
           obtain no where "\<forall>n\<ge>no. dist (a n) x < min dd kk"
@@ -2090,16 +2061,13 @@
             show "\<And>w. w \<in> U \<Longrightarrow> (\<lambda>z. d z w) holomorphic_on convex hull {a, b, c}"
               using e abc_subset by (auto intro: holomorphic_on_subset [OF hol_dw])
           qed
-          have "contour_integral \<gamma>
-                   (\<lambda>x. contour_integral (linepath a b) (\<lambda>z. d z x) +
-                        (contour_integral (linepath b c) (\<lambda>z. d z x) +
-                         contour_integral (linepath c a) (\<lambda>z. d z x)))  =  0"
-            apply (rule contour_integral_eq_0)
-            using abc pasz U
-            apply (subst contour_integral_join [symmetric], auto intro: eq0 *)+
-            done
+          have "\<And>z. z \<in> path_image \<gamma> \<Longrightarrow>
+                         contour_integral (linepath a b) (\<lambda>x. d x z) +
+                         (contour_integral (linepath b c) (\<lambda>x. d x z) +
+                          contour_integral (linepath c a) (\<lambda>x. d x z)) = 0"
+            using abc pasz U "*" eq0 by auto
           then show ?thesis
-            by (simp add: cint_h abc contour_integrable_add contour_integral_add [symmetric] add_ac)
+            by (simp add: contour_integral_eq_0 cint_h abc contour_integrable_add contour_integral_add [symmetric] add_ac)
         qed
         show ?thesis
           using e \<open>e > 0\<close> 
@@ -2110,14 +2078,14 @@
   qed
   ultimately have [simp]: "h z = 0" for z
     by (meson Liouville_weak)
-  have "((\<lambda>w. 1 / (w - z)) has_contour_integral complex_of_real (2 * pi) * \<i> * winding_number \<gamma> z) \<gamma>"
+  have "((\<lambda>w. 1 / (w-z)) has_contour_integral complex_of_real (2 * pi) * \<i> * winding_number \<gamma> z) \<gamma>"
     by (rule has_contour_integral_winding_number [OF \<open>valid_path \<gamma>\<close> znot])
-  then have "((\<lambda>w. f z * (1 / (w - z))) has_contour_integral complex_of_real (2 * pi) * \<i> * winding_number \<gamma> z * f z) \<gamma>"
+  then have "((\<lambda>w. f z * (1 / (w-z))) has_contour_integral complex_of_real (2 * pi) * \<i> * winding_number \<gamma> z * f z) \<gamma>"
     by (metis mult.commute has_contour_integral_lmul)
-  then have 1: "((\<lambda>w. f z / (w - z)) has_contour_integral complex_of_real (2 * pi) * \<i> * winding_number \<gamma> z * f z) \<gamma>"
+  then have 1: "((\<lambda>w. f z / (w-z)) has_contour_integral complex_of_real (2 * pi) * \<i> * winding_number \<gamma> z * f z) \<gamma>"
     by (simp add: field_split_simps)
-  moreover have 2: "((\<lambda>w. (f w - f z) / (w - z)) has_contour_integral 0) \<gamma>"
-    using U [OF z] pasz d_def by (force elim: has_contour_integral_eq [where g = "\<lambda>w. (f w - f z)/(w - z)"])
+  moreover have 2: "((\<lambda>w. (f w - f z) / (w-z)) has_contour_integral 0) \<gamma>"
+    using U [OF z] pasz d_def by (force elim: has_contour_integral_eq [where g = "\<lambda>w. (f w - f z)/(w-z)"])
   show ?thesis
     using has_contour_integral_add [OF 1 2]  by (simp add: diff_divide_distrib)
 qed
@@ -2127,12 +2095,12 @@
         and z: "z \<in> S" and vpg: "valid_path \<gamma>"
         and pasz: "path_image \<gamma> \<subseteq> S - {z}" and loop: "pathfinish \<gamma> = pathstart \<gamma>"
         and zero: "\<And>w. w \<notin> S \<Longrightarrow> winding_number \<gamma> w = 0"
-      shows "((\<lambda>w. f w / (w - z)) has_contour_integral (2*pi * \<i> * winding_number \<gamma> z * f z)) \<gamma>"
+      shows "((\<lambda>w. f w / (w-z)) has_contour_integral (2*pi * \<i> * winding_number \<gamma> z * f z)) \<gamma>"
 proof -
   have "path \<gamma>" using vpg by (blast intro: valid_path_imp_path)
-  have hols: "(\<lambda>w. f w / (w - z)) holomorphic_on S - {z}" "(\<lambda>w. 1 / (w - z)) holomorphic_on S - {z}"
+  have hols: "(\<lambda>w. f w / (w-z)) holomorphic_on S - {z}" "(\<lambda>w. 1 / (w-z)) holomorphic_on S - {z}"
     by (rule holomorphic_intros holomorphic_on_subset [OF holf] | force)+
-  then have cint_fw: "(\<lambda>w. f w / (w - z)) contour_integrable_on \<gamma>"
+  then have cint_fw: "(\<lambda>w. f w / (w-z)) contour_integrable_on \<gamma>"
     by (meson contour_integrable_holomorphic_simple holomorphic_on_imp_continuous_on open_delete S vpg pasz)
   obtain d where "d>0"
       and d: "\<And>g h. \<lbrakk>valid_path g; valid_path h; \<forall>t\<in>{0..1}. cmod (g t - \<gamma> t) < d \<and> cmod (h t - \<gamma> t) < d;
@@ -2152,7 +2120,7 @@
     by (simp add: subset_Diff_insert vpg valid_path_polynomial_function winding_number_valid_path cint_eq hols)
   have "winding_number p w = winding_number \<gamma> w" if "w \<notin> S" for w
   proof -
-    have hol: "(\<lambda>v. 1 / (v - w)) holomorphic_on S - {z}"
+    have hol: "(\<lambda>v. 1 / (v-w)) holomorphic_on S - {z}"
       using that by (force intro: holomorphic_intros holomorphic_on_subset [OF holf])
    have "w \<notin> path_image p" "w \<notin> path_image \<gamma>" using paps pasz that by auto
    then show ?thesis
@@ -2172,14 +2140,11 @@
         and zero: "\<And>w. w \<notin> S \<Longrightarrow> winding_number \<gamma> w = 0"
       shows "(f has_contour_integral 0) \<gamma>"
 proof -
-  obtain z where "z \<in> S" and znot: "z \<notin> path_image \<gamma>"
-  proof -
-    have "path_image \<gamma> \<noteq> S"
-      by (metis compact_valid_path_image vpg compact_open path_image_nonempty S)
-    with pas show ?thesis by (blast intro: that)
-  qed
-  then have pasz: "path_image \<gamma> \<subseteq> S - {z}" using pas by blast
-  have hol: "(\<lambda>w. (w - z) * f w) holomorphic_on S"
+  have "path_image \<gamma> \<noteq> S"
+    by (metis compact_valid_path_image vpg compact_open path_image_nonempty S)
+  then obtain z where "z \<in> S" and znot: "z \<notin> path_image \<gamma>" and pasz: "path_image \<gamma> \<subseteq> S - {z}"
+    using pas by blast
+  have hol: "(\<lambda>w. (w-z) * f w) holomorphic_on S"
     by (rule holomorphic_intros holf)+
   show ?thesis
     using Cauchy_integral_formula_global [OF S hol \<open>z \<in> S\<close> vpg pasz loop zero]
@@ -2252,11 +2217,11 @@
         and contf: "continuous_on (cball z r) f"
         and fin : "\<And>w. w \<in> ball z r \<Longrightarrow> f w \<in> ball y B0"
         and "0 < r" and "0 < n"
-      shows "norm ((deriv ^^ n) f z) \<le> (fact n) * B0 / r^n"
+      shows "cmod ((deriv ^^ n) f z) \<le> (fact n) * B0 / r^n"
 proof -
-  have "0 < B0" using \<open>0 < r\<close> fin [of z]
-    by (metis ball_eq_empty ex_in_conv fin not_less)
-  have le_B0: "cmod (f w - y) \<le> B0" if "cmod (w - z) \<le> r" for w
+  have "0 < B0" 
+    using \<open>0 < r\<close> fin [of z] by (metis ball_eq_empty ex_in_conv fin not_less)
+  have le_B0: "cmod (f w - y) \<le> B0" if "cmod (w-z) \<le> r" for w
   proof (rule continuous_on_closure_norm_le [of "ball z r" "\<lambda>w. f w - y"], use \<open>0 < r\<close> in simp_all)
     show "continuous_on (cball z r) (\<lambda>w. f w - y)"
       by (intro continuous_intros contf)
@@ -2266,7 +2231,7 @@
   have "(deriv ^^ n) f z = (deriv ^^ n) (\<lambda>w. f w) z - (deriv ^^ n) (\<lambda>w. y) z"
     using \<open>0 < n\<close> by simp
   also have "... = (deriv ^^ n) (\<lambda>w. f w - y) z"
-    by (rule higher_deriv_diff [OF holf, symmetric]) (auto simp: \<open>0 < r\<close>)
+    using \<open>0 < r\<close> higher_deriv_diff holf by auto
   finally have "(deriv ^^ n) f z = (deriv ^^ n) (\<lambda>w. f w - y) z" .
   have contf': "continuous_on (cball z r) (\<lambda>u. f u - y)"
     by (rule contf continuous_intros)+
@@ -2281,7 +2246,7 @@
     by (auto simp: higher_deriv_diff [OF holf holomorphic_on_const])
   have "norm ((2 * of_real pi * \<i>)/(fact n) * (deriv ^^ n) (\<lambda>w. f w - y) z)
         \<le> (B0/r^(Suc n)) * (2 * pi * r)"
-    apply (rule has_contour_integral_bound_circlepath [of "(\<lambda>u. (f u - y)/(u - z)^(Suc n))" _ z])
+    apply (rule has_contour_integral_bound_circlepath [of "(\<lambda>u. (f u - y)/(u-z)^(Suc n))" _ z])
     using Cauchy_has_contour_integral_higher_derivative_circlepath [OF contf' holf']
     using \<open>0 < B0\<close> \<open>0 < r\<close>
     apply (auto simp: norm_divide norm_mult norm_power divide_simps le_B0)
@@ -2373,15 +2338,15 @@
         using holf holomorphic_on_subset by force
       show "continuous_on (cball 0 (cmod w)) f"
         using holf holomorphic_on_imp_continuous_on holomorphic_on_subset by blast
-      show "\<And>x. cmod (0 - x) = cmod w \<Longrightarrow> cmod (f x) \<le> B * cmod w ^ n"
+      show "\<And>x. cmod (0-x) = cmod w \<Longrightarrow> cmod (f x) \<le> B * cmod w ^ n"
         by (metis nof wgeA dist_0_norm dist_norm)
     qed (use \<open>w \<noteq> 0\<close> in auto)
     also have "... = fact k * B / cmod w ^ (k-n)"
       using \<open>k>n\<close> by (simp add: divide_simps flip: power_add)
-    finally have "fact k * B / cmod w < fact k * B / cmod w ^ (k - n)" .
-    then have "1 / cmod w < 1 / cmod w ^ (k - n)"
+    finally have "fact k * B / cmod w < fact k * B / cmod w ^ (k-n)" .
+    then have "1 / cmod w < 1 / cmod w ^ (k-n)"
       by (metis kB divide_inverse inverse_eq_divide mult_less_cancel_left_pos)
-    then have "cmod w ^ (k - n) < cmod w"
+    then have "cmod w ^ (k-n) < cmod w"
       by (smt (verit, best) \<open>w \<noteq> 0\<close> frac_le zero_less_norm_iff)
     with self_le_power [OF wge1] show ?thesis
       by (meson diff_is_0_eq not_gr0 not_le that)
@@ -2449,11 +2414,13 @@
     by (simp add: g_def)
   ultimately have gnz: "\<And>x. \<lbrakk>norm (x-\<xi>) \<le> s; norm (x-\<xi>) \<le> r/2\<rbrakk> \<Longrightarrow> (g x) \<noteq> 0"
     by fastforce
-  have "f x \<noteq> 0" if "x \<noteq> \<xi>" "norm (x-\<xi>) \<le> s" "norm (x-\<xi>) \<le> r/2" for x
-    using bsums [of x] that gnz [of x] r sums_iff unfolding g_def by fastforce
-  then show ?thesis
-    apply (rule_tac s="min s (r/2)" in that)
-    using \<open>0 < r\<close> \<open>0 < s\<close> by (auto simp: dist_commute dist_norm)
+  show ?thesis
+  proof
+    have *: "f x \<noteq> 0" if "x \<noteq> \<xi>" "norm (x-\<xi>) \<le> s" "norm (x-\<xi>) \<le> r/2" for x
+      using bsums [of x] that gnz [of x] r sums_iff unfolding g_def by fastforce
+    show "\<And>z. z \<in> cball \<xi> (min s (r / 2)) - {\<xi>} \<Longrightarrow> f z \<noteq> 0"
+      by (simp add: "*" dist_norm norm_minus_commute)
+  qed (use \<open>0 < r\<close> \<open>0 < s\<close> in auto)
 qed
 
 subsection \<open>Complex functions and power series\<close>
@@ -2473,9 +2440,9 @@
 lemma
   fixes r :: ereal
   assumes "f holomorphic_on eball z0 r"
-  shows   conv_radius_fps_expansion: "fps_conv_radius (fps_expansion f z0) \<ge> r"
-    and   eval_fps_expansion: "\<And>z. z \<in> eball z0 r \<Longrightarrow> eval_fps (fps_expansion f z0) (z - z0) = f z"
-    and   eval_fps_expansion': "\<And>z. norm z < r \<Longrightarrow> eval_fps (fps_expansion f z0) z = f (z0 + z)"
+  shows conv_radius_fps_expansion: "fps_conv_radius (fps_expansion f z0) \<ge> r"
+    and eval_fps_expansion:  "\<And>z. z \<in> eball z0 r \<Longrightarrow> eval_fps (fps_expansion f z0) (z - z0) = f z"
+    and eval_fps_expansion': "\<And>z. norm z < r \<Longrightarrow> eval_fps (fps_expansion f z0) z = f (z0 + z)"
 proof -
   have "(\<lambda>n. fps_nth (fps_expansion f z0) n * (z - z0) ^ n) sums f z"
     if "z \<in> ball z0 r'" "ereal r' < r" for z r'
@@ -2560,7 +2527,7 @@
     hence *: "eball 0 R = {}" 
       by (intro eball_empty) (auto simp: R_def min_def split: if_splits)
     show ?thesis
-    proof safe
+    proof 
       from False have "min r (fps_conv_radius f) \<le> 0"
         by (simp add: min_def)
       also have "0 \<le> fps_conv_radius (inverse f)"
@@ -2569,10 +2536,11 @@
     qed (unfold * [unfolded R_def], auto)
   qed
 
-  from * show "fps_conv_radius (inverse f) \<ge> min r (fps_conv_radius f)" by blast
-  from * show "eval_fps (inverse f) z = inverse (eval_fps f z)" 
+  show "fps_conv_radius (inverse f) \<ge> min r (fps_conv_radius f)"
+    using * by blast
+  show "eval_fps (inverse f) z = inverse (eval_fps f z)" 
     if "ereal (norm z) < fps_conv_radius f" "ereal (norm z) < r" for z
-    using that by auto
+    using that * by auto
 qed
 
 lemma
@@ -2696,7 +2664,8 @@
     using \<open>r > 0\<close> by (intro eventually_nhds_in_open) auto
   hence "eventually (\<lambda>z. eval_fps (fps_expansion f 0) z = f z) (nhds 0)"
     by eventually_elim (subst eval_fps_expansion'[OF holo], auto)
-  ultimately show ?thesis using \<open>r > 0\<close> by (auto simp: has_fps_expansion_def)
+  ultimately show ?thesis 
+    using \<open>r > 0\<close> by (auto simp: has_fps_expansion_def)
 qed
 
 lemma fps_conv_radius_tan:
--- a/src/HOL/Complex_Analysis/Complex_Singularities.thy	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/HOL/Complex_Analysis/Complex_Singularities.thy	Fri Jan 24 10:22:17 2025 +0100
@@ -4,9 +4,9 @@
 
 subsection \<open>Non-essential singular points\<close>
 
-definition\<^marker>\<open>tag important\<close> is_pole ::
-  "('a::topological_space \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a \<Rightarrow> bool" where
-  "is_pole f a =  (LIM x (at a). f x :> at_infinity)"
+definition\<^marker>\<open>tag important\<close>
+  is_pole :: "('a::topological_space \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a \<Rightarrow> bool" 
+  where "is_pole f a =  (LIM x (at a). f x :> at_infinity)"
 
 lemma is_pole_cong:
   assumes "eventually (\<lambda>x. f x = g x) (at a)" "a=b"
@@ -24,10 +24,10 @@
   by (metis add_diff_cancel_right' filterlim_shift_iff is_pole_def)
 
 lemma is_pole_tendsto:
-  fixes f::"('a::topological_space \<Rightarrow> 'b::real_normed_div_algebra)"
+  fixes f:: "('a::topological_space \<Rightarrow> 'b::real_normed_div_algebra)"
   shows "is_pole f x \<Longrightarrow> ((inverse o f) \<longlongrightarrow> 0) (at x)"
   unfolding is_pole_def
-  by (auto simp add:filterlim_inverse_at_iff[symmetric] comp_def filterlim_at)
+  by (auto simp add: filterlim_inverse_at_iff[symmetric] comp_def filterlim_at)
 
 lemma is_pole_shift_0:
   fixes f :: "('a::real_normed_vector \<Rightarrow> 'b::real_normed_vector)"
@@ -46,9 +46,9 @@
 
 lemma is_pole_inverse_holomorphic:
   assumes "open s"
-    and f_holo:"f holomorphic_on (s-{z})"
-    and pole:"is_pole f z"
-    and non_z:"\<forall>x\<in>s-{z}. f x\<noteq>0"
+    and f_holo: "f holomorphic_on (s-{z})"
+    and pole: "is_pole f z"
+    and non_z: "\<forall>x\<in>s-{z}. f x\<noteq>0"
   shows "(\<lambda>x. if x=z then 0 else inverse (f x)) holomorphic_on s"
 proof -
   define g where "g \<equiv> \<lambda>x. if x=z then 0 else inverse (f x)"
@@ -56,14 +56,14 @@
     by (simp add: g_def cong: LIM_cong)
   moreover have "continuous_on (s-{z}) f" using f_holo holomorphic_on_imp_continuous_on by auto
   hence "continuous_on (s-{z}) (inverse o f)" unfolding comp_def
-    by (auto elim!:continuous_on_inverse simp add:non_z)
+    by (auto elim!:continuous_on_inverse simp add: non_z)
   hence "continuous_on (s-{z}) g" unfolding g_def
     using continuous_on_eq by fastforce
   ultimately have "continuous_on s g" using open_delete[OF \<open>open s\<close>] \<open>open s\<close>
-    by (auto simp add:continuous_on_eq_continuous_at)
+    by (auto simp add: continuous_on_eq_continuous_at)
   moreover have "(inverse o f) holomorphic_on (s-{z})"
     unfolding comp_def using f_holo
-    by (auto elim!:holomorphic_on_inverse simp add:non_z)
+    by (auto elim!:holomorphic_on_inverse simp add: non_z)
   hence "g holomorphic_on (s-{z})"
     using g_def holomorphic_transform by force
   ultimately show ?thesis unfolding g_def using \<open>open s\<close>
@@ -125,15 +125,15 @@
 
 lemma is_pole_basic:
   assumes "f holomorphic_on A" "open A" "z \<in> A" "f z \<noteq> 0" "n > 0"
-  shows   "is_pole (\<lambda>w. f w / (w - z) ^ n) z"
+  shows   "is_pole (\<lambda>w. f w / (w-z) ^ n) z"
 proof (rule is_pole_divide)
   have "continuous_on A f" by (rule holomorphic_on_imp_continuous_on) fact
   with assms show "isCont f z" by (auto simp: continuous_on_eq_continuous_at)
-  have "filterlim (\<lambda>w. (w - z) ^ n) (nhds 0) (at z)"
+  have "filterlim (\<lambda>w. (w-z) ^ n) (nhds 0) (at z)"
     using assms by (auto intro!: tendsto_eq_intros)
-  thus "filterlim (\<lambda>w. (w - z) ^ n) (at 0) (at z)"
+  thus "filterlim (\<lambda>w. (w-z) ^ n) (at 0) (at z)"
     by (intro filterlim_atI tendsto_eq_intros)
-       (insert assms, auto simp: eventually_at_filter)
+       (use assms in \<open>auto simp: eventually_at_filter\<close>)
 qed fact+
 
 lemma is_pole_basic':
@@ -161,7 +161,7 @@
   then have "filterlim (\<lambda>x. f x + c) at_infinity (at z)" 
     unfolding is_pole_def .
   moreover have "((\<lambda>_. -c) \<longlongrightarrow> -c) (at z)" by auto
-  ultimately have " LIM x (at z). f x :> at_infinity"
+  ultimately have "LIM x (at z). f x :> at_infinity"
     using tendsto_add_filterlim_at_infinity'[of "(\<lambda>x. f x + c)"
         "at z" "(\<lambda>_. - c)" "-c"] 
     by auto
@@ -237,11 +237,11 @@
     unfolding islimpt_sequential by blast
   then have "(f \<circ> g) \<longlonglongrightarrow> c"
     by (simp add: tendsto_eventually)
-  moreover have *: "filterlim g (at z) sequentially"
+  moreover have "filterlim g (at z) sequentially"
     using g by (auto simp: filterlim_at)
-  have "filterlim (f \<circ> g) at_infinity sequentially"
-    unfolding o_def by (rule filterlim_compose [OF _ *])
-                       (use \<open>is_pole f z\<close> in \<open>simp add: is_pole_def\<close>)
+  then have "filterlim (f \<circ> g) at_infinity sequentially"
+    unfolding o_def
+    using \<open>is_pole f z\<close> filterlim_compose is_pole_def by blast
   ultimately show False
     using not_tendsto_and_filterlim_at_infinity trivial_limit_sequentially by blast
 qed
@@ -250,10 +250,10 @@
               \<^term>\<open>\<exists>x. ((f::complex\<Rightarrow>complex) \<longlongrightarrow> x) (at z) \<or> is_pole f z\<close>
 can be interpreted as the complex function \<^term>\<open>f\<close> has a non-essential singularity at \<^term>\<open>z\<close>
 (i.e. the singularity is either removable or a pole).\<close>
-definition not_essential::"[complex \<Rightarrow> complex, complex] \<Rightarrow> bool" where
+definition not_essential:: "[complex \<Rightarrow> complex, complex] \<Rightarrow> bool" where
   "not_essential f z = (\<exists>x. f\<midarrow>z\<rightarrow>x \<or> is_pole f z)"
 
-definition isolated_singularity_at::"[complex \<Rightarrow> complex, complex] \<Rightarrow> bool" where
+definition isolated_singularity_at:: "[complex \<Rightarrow> complex, complex] \<Rightarrow> bool" where
   "isolated_singularity_at f z = (\<exists>r>0. f analytic_on ball z r-{z})"
 
 lemma not_essential_cong:
@@ -322,7 +322,7 @@
       have "f \<midarrow>x\<rightarrow> c"
         by fact
       also have "?this \<longleftrightarrow> (?g \<longlongrightarrow> ?g y) (at y)"
-        by (intro filterlim_cong) (auto simp: eventually_at_filter)
+        by (simp add: LIM_equal)
       finally show ?thesis
         by (meson Lim_at_imp_Lim_at_within)
     qed
@@ -332,7 +332,7 @@
       using assms(1) holomorphic_transform by fastforce
   }
   ultimately show ?thesis
-    by (rule no_isolated_singularity) (use assms in auto)
+    using assms by (simp add: no_isolated_singularity)
 qed
 
 lemma removable_singularity':
@@ -354,18 +354,18 @@
 named_theorems singularity_intros "introduction rules for singularities"
 
 lemma holomorphic_factor_unique:
-  fixes f::"complex \<Rightarrow> complex" and z::complex and r::real and m n::int
+  fixes f:: "complex \<Rightarrow> complex" and z::complex and r::real and m n::int
   assumes "r>0" "g z\<noteq>0" "h z\<noteq>0"
-    and asm:"\<forall>w\<in>ball z r-{z}. f w = g w * (w-z) powi n \<and> g w\<noteq>0 \<and> f w =  h w * (w - z) powi m \<and> h w\<noteq>0"
-    and g_holo:"g holomorphic_on ball z r" and h_holo:"h holomorphic_on ball z r"
+    and asm: "\<forall>w\<in>ball z r-{z}. f w = g w * (w-z) powi n \<and> g w\<noteq>0 \<and> f w =  h w * (w-z) powi m \<and> h w\<noteq>0"
+    and g_holo: "g holomorphic_on ball z r" and h_holo: "h holomorphic_on ball z r"
   shows "n=m"
 proof -
-  have [simp]:"at z within ball z r \<noteq> bot" using \<open>r>0\<close>
-      by (auto simp add:at_within_ball_bot_iff)
+  have [simp]: "at z within ball z r \<noteq> bot" using \<open>r>0\<close>
+      by (auto simp add: at_within_ball_bot_iff)
   have False when "n>m"
   proof -
     have "(h \<longlongrightarrow> 0) (at z within ball z r)"
-    proof (rule Lim_transform_within[OF _ \<open>r>0\<close>, where f="\<lambda>w. (w - z) powi (n - m) * g w"])
+    proof (rule Lim_transform_within[OF _ \<open>r>0\<close>, where f="\<lambda>w. (w-z) powi (n - m) * g w"])
       have "\<forall>w\<in>ball z r-{z}. h w = (w-z)powi(n-m) * g w"
         using \<open>n>m\<close> asm \<open>r>0\<close> by (simp add: field_simps power_int_diff) force
       then show "\<lbrakk>x' \<in> ball z r; 0 < dist x' z;dist x' z < r\<rbrakk>
@@ -386,16 +386,16 @@
     qed
     moreover have "(h \<longlongrightarrow> h z) (at z within ball z r)"
       using holomorphic_on_imp_continuous_on[OF h_holo]
-      by (auto simp add:continuous_on_def \<open>r>0\<close>)
+      by (auto simp add: continuous_on_def \<open>r>0\<close>)
     ultimately have "h z=0" by (auto intro!: tendsto_unique)
     thus False using \<open>h z\<noteq>0\<close> by auto
   qed
   moreover have False when "m>n"
   proof -
     have "(g \<longlongrightarrow> 0) (at z within ball z r)"
-    proof (rule Lim_transform_within[OF _ \<open>r>0\<close>, where f="\<lambda>w. (w - z) powi (m - n) * h w"])
+    proof (rule Lim_transform_within[OF _ \<open>r>0\<close>, where f="\<lambda>w. (w-z) powi (m - n) * h w"])
       have "\<forall>w\<in>ball z r -{z}. g w = (w-z) powi (m-n) * h w" using \<open>m>n\<close> asm
-        by (simp add:field_simps power_int_diff) force
+        by (simp add: field_simps power_int_diff) force
       then show "\<lbrakk>x' \<in> ball z r; 0 < dist x' z;dist x' z < r\<rbrakk>
             \<Longrightarrow> (x' - z) powi (m - n) * h x' = g x'" for x' by auto
     next
@@ -414,7 +414,7 @@
     qed
     moreover have "(g \<longlongrightarrow> g z) (at z within ball z r)"
       using holomorphic_on_imp_continuous_on[OF g_holo]
-      by (auto simp add:continuous_on_def \<open>r>0\<close>)
+      by (auto simp add: continuous_on_def \<open>r>0\<close>)
     ultimately have "g z=0" by (auto intro!: tendsto_unique)
     thus False using \<open>g z\<noteq>0\<close> by auto
   qed
@@ -422,19 +422,19 @@
 qed
 
 lemma holomorphic_factor_puncture:
-  assumes f_iso:"isolated_singularity_at f z"
+  assumes f_iso: "isolated_singularity_at f z"
       and "not_essential f z" \<comment> \<open>\<^term>\<open>f\<close> has either a removable singularity or a pole at \<^term>\<open>z\<close>\<close>
-      and non_zero:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0" \<comment> \<open>\<^term>\<open>f\<close> will not be constantly zero in a neighbour of \<^term>\<open>z\<close>\<close>
+      and non_zero: "\<exists>\<^sub>Fw in (at z). f w\<noteq>0" \<comment> \<open>\<^term>\<open>f\<close> will not be constantly zero in a neighbour of \<^term>\<open>z\<close>\<close>
   shows "\<exists>!n::int. \<exists>g r. 0 < r \<and> g holomorphic_on cball z r \<and> g z\<noteq>0
           \<and> (\<forall>w\<in>cball z r-{z}. f w = g w * (w-z) powi n \<and> g w\<noteq>0)"
 proof -
   define P where "P = (\<lambda>f n g r. 0 < r \<and> g holomorphic_on cball z r \<and> g z\<noteq>0
           \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w-z) powi n  \<and> g w\<noteq>0))"
-  have imp_unique:"\<exists>!n::int. \<exists>g r. P f n g r" when "\<exists>n g r. P f n g r"
+  have imp_unique: "\<exists>!n::int. \<exists>g r. P f n g r" when "\<exists>n g r. P f n g r"
   proof (rule ex_ex1I[OF that])
     fix n1 n2 :: int
-    assume g1_asm:"\<exists>g1 r1. P f n1 g1 r1" and g2_asm:"\<exists>g2 r2. P f n2 g2 r2"
-    define fac where "fac \<equiv> \<lambda>n g r. \<forall>w\<in>cball z r-{z}. f w = g w * (w - z) powi n \<and> g w \<noteq> 0"
+    assume g1_asm: "\<exists>g1 r1. P f n1 g1 r1" and g2_asm: "\<exists>g2 r2. P f n2 g2 r2"
+    define fac where "fac \<equiv> \<lambda>n g r. \<forall>w\<in>cball z r-{z}. f w = g w * (w-z) powi n \<and> g w \<noteq> 0"
     obtain g1 r1 where "0 < r1" and g1_holo: "g1 holomorphic_on cball z r1" and "g1 z\<noteq>0"
         and "fac n1 g1 r1" using g1_asm unfolding P_def fac_def by auto
     obtain g2 r2 where "0 < r2" and g2_holo: "g2 holomorphic_on cball z r2" and "g2 z\<noteq>0"
@@ -442,16 +442,16 @@
     define r where "r \<equiv> min r1 r2"
     have "r>0" using \<open>r1>0\<close> \<open>r2>0\<close> unfolding r_def by auto
     moreover have "\<forall>w\<in>ball z r-{z}. f w = g1 w * (w-z) powi n1 \<and> g1 w\<noteq>0
-        \<and> f w = g2 w * (w - z) powi n2  \<and> g2 w\<noteq>0"
+        \<and> f w = g2 w * (w-z) powi n2  \<and> g2 w\<noteq>0"
       using \<open>fac n1 g1 r1\<close> \<open>fac n2 g2 r2\<close>   unfolding fac_def r_def
       by fastforce
     ultimately show "n1=n2" 
       using g1_holo g2_holo \<open>g1 z\<noteq>0\<close> \<open>g2 z\<noteq>0\<close>
       apply (elim holomorphic_factor_unique)
-      by (auto simp add:r_def)
+      by (auto simp add: r_def)
   qed
 
-  have P_exist:"\<exists> n g r. P h n g r" when
+  have P_exist: "\<exists> n g r. P h n g r" when
       "\<exists>z'. (h \<longlongrightarrow> z') (at z)" "isolated_singularity_at h z"  "\<exists>\<^sub>Fw in (at z). h w\<noteq>0"
     for h
   proof -
@@ -474,16 +474,16 @@
         by (metis \<open>0 < r\<close> centre_in_ball dist_commute mem_ball that)
       moreover note \<open>h' holomorphic_on ball z r\<close>
       ultimately obtain g r1 n where "0 < n" "0 < r1" "ball z r1 \<subseteq> ball z r" and
-          g:"g holomorphic_on ball z r1"
-          "\<And>w. w \<in> ball z r1 \<Longrightarrow> h' w = (w - z) ^ n * g w"
+          g: "g holomorphic_on ball z r1"
+          "\<And>w. w \<in> ball z r1 \<Longrightarrow> h' w = (w-z) ^ n * g w"
           "\<And>w. w \<in> ball z r1 \<Longrightarrow> g w \<noteq> 0"
         using holomorphic_factor_zero_nonconstant[of _ "ball z r" z thesis,simplified,
                 OF \<open>h' holomorphic_on ball z r\<close> \<open>r>0\<close> \<open>h' z=0\<close> \<open>\<not> h' constant_on ball z r\<close>]
-        by (auto simp add:dist_commute)
+        by (auto simp add: dist_commute)
       define rr where "rr=r1/2"
       have "P h' n g rr"
         unfolding P_def rr_def
-        using \<open>n>0\<close> \<open>r1>0\<close> g by (auto simp add:powr_nat)
+        using \<open>n>0\<close> \<open>r1>0\<close> g by (auto simp add: powr_nat)
       then have "P h n g rr"
         unfolding h'_def P_def by auto
       then show ?thesis unfolding P_def by blast
@@ -495,7 +495,7 @@
       proof -
         have "isCont h' z" "h' z\<noteq>0"
           by (auto simp add: Lim_cong_within \<open>h \<midarrow>z\<rightarrow> z'\<close> \<open>z'\<noteq>0\<close> continuous_at h'_def)
-        then obtain r2 where r2:"r2>0" "\<forall>x\<in>ball z r2. h' x\<noteq>0"
+        then obtain r2 where r2: "r2>0" "\<forall>x\<in>ball z r2. h' x\<noteq>0"
           using continuous_at_avoid[of z h' 0 ] unfolding ball_def by auto
         define r1 where "r1=min r2 r / 2"
         have "0 < r1" "cball z r1 \<subseteq> ball z r"
@@ -516,14 +516,14 @@
     using P_exist[OF that(1) f_iso non_zero] unfolding P_def .
   moreover have ?thesis when "is_pole f z"
   proof (rule imp_unique[unfolded P_def])
-    obtain e where [simp]:"e>0" and e_holo:"f holomorphic_on ball z e - {z}" and e_nz: "\<forall>x\<in>ball z e-{z}. f x\<noteq>0"
+    obtain e where [simp]: "e>0" and e_holo: "f holomorphic_on ball z e - {z}" and e_nz: "\<forall>x\<in>ball z e-{z}. f x\<noteq>0"
     proof -
       have "\<forall>\<^sub>F z in at z. f z \<noteq> 0"
         using \<open>is_pole f z\<close> filterlim_at_infinity_imp_eventually_ne unfolding is_pole_def
         by auto
-      then obtain e1 where e1:"e1>0" "\<forall>x\<in>ball z e1-{z}. f x\<noteq>0"
-        using that eventually_at[of "\<lambda>x. f x\<noteq>0" z UNIV,simplified] by (auto simp add:dist_commute)
-      obtain e2 where e2:"e2>0" "f holomorphic_on ball z e2 - {z}"
+      then obtain e1 where e1: "e1>0" "\<forall>x\<in>ball z e1-{z}. f x\<noteq>0"
+        using that eventually_at[of "\<lambda>x. f x\<noteq>0" z UNIV,simplified] by (auto simp add: dist_commute)
+      obtain e2 where e2: "e2>0" "f holomorphic_on ball z e2 - {z}"
         using f_iso analytic_imp_holomorphic unfolding isolated_singularity_at_def by auto
       show ?thesis
         using e1 e2 by (force intro: that[of "min e1 e2"])
@@ -545,22 +545,23 @@
     qed
     then obtain n g r
       where "0 < r" and
-            g_holo:"g holomorphic_on cball z r" and "g z\<noteq>0" and
-            g_fac:"(\<forall>w\<in>cball z r-{z}. h w = g w * (w - z) powi n  \<and> g w \<noteq> 0)"
+            g_holo: "g holomorphic_on cball z r" and "g z\<noteq>0" and
+            g_fac: "(\<forall>w\<in>cball z r-{z}. h w = g w * (w-z) powi n  \<and> g w \<noteq> 0)"
       unfolding P_def by auto
     have "P f (-n) (inverse o g) r"
     proof -
-      have "f w = inverse (g w) * (w - z) powi (- n)" when "w\<in>cball z r - {z}" for w
+      have "f w = inverse (g w) * (w-z) powi (- n)" when "w\<in>cball z r - {z}" for w
         by (metis g_fac h_def inverse_inverse_eq inverse_mult_distrib power_int_minus that)
       then show ?thesis
         unfolding P_def comp_def
-        using \<open>r>0\<close> g_holo g_fac \<open>g z\<noteq>0\<close> by (auto intro:holomorphic_intros)
+        using \<open>r>0\<close> g_holo g_fac \<open>g z\<noteq>0\<close> by (auto intro: holomorphic_intros)
     qed
     then show "\<exists>x g r. 0 < r \<and> g holomorphic_on cball z r \<and> g z \<noteq> 0
-                  \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powi x  \<and> g w \<noteq> 0)"
+                  \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w-z) powi x  \<and> g w \<noteq> 0)"
       unfolding P_def by blast
   qed
-  ultimately show ?thesis using \<open>not_essential f z\<close> unfolding not_essential_def  by presburger
+  ultimately show ?thesis 
+    using \<open>not_essential f z\<close> unfolding not_essential_def by presburger
 qed
 
 lemma not_essential_transform:
@@ -631,9 +632,9 @@
 proof -
   obtain r1 where "r1>0" "f analytic_on ball z r1 - {z}"
     using assms(1) unfolding isolated_singularity_at_def by auto
-  then have r1:"f holomorphic_on ball z r1 - {z}"
+  then have r1: "f holomorphic_on ball z r1 - {z}"
     using analytic_on_open[of "ball z r1-{z}" f] by blast
-  obtain r2 where "r2>0" and r2:"\<forall>w. w \<noteq> z \<and> dist w z < r2 \<longrightarrow> f w \<noteq> 0"
+  obtain r2 where "r2>0" and r2: "\<forall>w. w \<noteq> z \<and> dist w z < r2 \<longrightarrow> f w \<noteq> 0"
     using assms(2) unfolding eventually_at by auto
   define r3 where "r3=min r1 r2"
   have "(\<lambda>w. (f w) powi n) holomorphic_on ball z r3 - {z}"
@@ -644,20 +645,21 @@
 qed
 
 lemma non_zero_neighbour:
-  assumes f_iso:"isolated_singularity_at f z"
-      and f_ness:"not_essential f z"
-      and f_nconst:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
+  assumes f_iso: "isolated_singularity_at f z"
+      and f_ness: "not_essential f z"
+      and f_nconst: "\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
     shows "\<forall>\<^sub>F w in (at z). f w\<noteq>0"
 proof -
-  obtain fn fp fr where [simp]:"fp z \<noteq> 0" and "fr > 0"
-          and fr: "fp holomorphic_on cball z fr"
-                  "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w - z) powi fn \<and> fp w \<noteq> 0"
-    using holomorphic_factor_puncture[OF f_iso f_ness f_nconst,THEN ex1_implies_ex] by auto
+  obtain fn fp fr
+    where [simp]: "fp z \<noteq> 0" and "fr > 0"
+      and fr: "fp holomorphic_on cball z fr"
+              "\<And>w. w \<in> cball z fr - {z} \<Longrightarrow> f w = fp w * (w-z) powi fn \<and> fp w \<noteq> 0"
+    using holomorphic_factor_puncture[OF f_iso f_ness f_nconst] by auto
   have "f w \<noteq> 0" when " w \<noteq> z" "dist w z < fr" for w
   proof -
-    have "f w = fp w * (w - z) powi fn" "fp w \<noteq> 0"
-      using fr(2)[rule_format, of w] using that by (auto simp add:dist_commute)
-    moreover have "(w - z) powi fn \<noteq>0"
+    have "f w = fp w * (w-z) powi fn" "fp w \<noteq> 0"
+      using fr that by (auto simp add: dist_commute)
+    moreover have "(w-z) powi fn \<noteq>0"
       unfolding powr_eq_0_iff using \<open>w\<noteq>z\<close> by auto
     ultimately show ?thesis by auto
   qed
@@ -682,18 +684,18 @@
     by (smt (verit) open_ball centre_in_ball eventually_at_topological insertE insert_Diff subsetD)
 next
   case False
-  obtain r1 where r1:"r1>0" "\<forall>y. dist z y < r1 \<longrightarrow> f y \<noteq> 0"
-    using continuous_at_avoid[of z f, OF _ False] assms(2,4) continuous_on_eq_continuous_at
+  obtain r1 where r1: "r1>0" "\<forall>y. dist z y < r1 \<longrightarrow> f y \<noteq> 0"
+    using continuous_at_avoid[of z f, OF _ False] assms continuous_on_eq_continuous_at
       holo holomorphic_on_imp_continuous_on by blast
-  obtain r2 where r2:"r2>0" "ball z r2 \<subseteq> S"
+  obtain r2 where r2: "r2>0" "ball z r2 \<subseteq> S"
     using assms openE by blast
   show ?thesis unfolding eventually_at
-    by (metis (no_types) dist_commute dual_order.strict_trans linorder_less_linear mem_ball r1 r2 subsetD)
+    by (metis (no_types) dist_commute order.strict_trans linorder_less_linear mem_ball r1 r2 subsetD)
 qed
 
 lemma not_essential_times[singularity_intros]:
-  assumes f_ness:"not_essential f z" and g_ness:"not_essential g z"
-  assumes f_iso:"isolated_singularity_at f z" and g_iso:"isolated_singularity_at g z"
+  assumes f_ness: "not_essential f z" and g_ness: "not_essential g z"
+  assumes f_iso: "isolated_singularity_at f z" and g_iso: "isolated_singularity_at g z"
   shows "not_essential (\<lambda>w. f w * g w) z"
 proof -
   define fg where "fg = (\<lambda>w. f w * g w)"
@@ -704,41 +706,40 @@
     from tendsto_cong[OF this] have "fg \<midarrow>z\<rightarrow>0" by auto
     then show ?thesis unfolding not_essential_def fg_def by auto
   qed
-  moreover have ?thesis when f_nconst:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0" and g_nconst:"\<exists>\<^sub>Fw in (at z). g w\<noteq>0"
+  moreover have ?thesis when f_nconst: "\<exists>\<^sub>Fw in (at z). f w\<noteq>0" and g_nconst: "\<exists>\<^sub>Fw in (at z). g w\<noteq>0"
   proof -
-    obtain fn fp fr where [simp]:"fp z \<noteq> 0" and "fr > 0"
+    obtain fn fp fr where [simp]: "fp z \<noteq> 0" and "fr > 0"
           and fr: "fp holomorphic_on cball z fr"
-                  "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w - z) powi fn \<and> fp w \<noteq> 0"
-      using holomorphic_factor_puncture[OF f_iso f_ness f_nconst,THEN ex1_implies_ex] by auto
-    obtain gn gp gr where [simp]:"gp z \<noteq> 0" and "gr > 0"
+                  "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w-z) powi fn \<and> fp w \<noteq> 0"
+      using holomorphic_factor_puncture[OF f_iso f_ness f_nconst] by auto
+    obtain gn gp gr where [simp]: "gp z \<noteq> 0" and "gr > 0"
           and gr: "gp holomorphic_on cball z gr"
-                  "\<forall>w\<in>cball z gr - {z}. g w = gp w * (w - z) powi gn \<and> gp w \<noteq> 0"
-      using holomorphic_factor_puncture[OF g_iso g_ness g_nconst,THEN ex1_implies_ex] by auto
+                  "\<forall>w\<in>cball z gr - {z}. g w = gp w * (w-z) powi gn \<and> gp w \<noteq> 0"
+      using holomorphic_factor_puncture[OF g_iso g_ness g_nconst] by auto
 
     define r1 where "r1=(min fr gr)"
     have "r1>0" unfolding r1_def using  \<open>fr>0\<close> \<open>gr>0\<close> by auto
-    have fg_times:"fg w = (fp w * gp w) * (w - z) powi (fn+gn)" and fgp_nz:"fp w*gp w\<noteq>0"
+    have fg_times: "fg w = (fp w * gp w) * (w-z) powi (fn+gn)" and fgp_nz: "fp w*gp w\<noteq>0"
       when "w\<in>ball z r1 - {z}" for w
     proof -
-      have "f w = fp w * (w - z) powi fn" "fp w\<noteq>0"
-        using fr(2)[rule_format,of w] that unfolding r1_def by auto
-      moreover have "g w = gp w * (w - z) powi gn" "gp w \<noteq> 0"
-        using gr(2)[rule_format, of w] that unfolding r1_def by auto
-      ultimately show "fg w = (fp w * gp w) * (w - z) powi (fn+gn)" "fp w*gp w\<noteq>0"
-        using that unfolding fg_def by (auto simp add:power_int_add)
+      have "f w = fp w * (w-z) powi fn" "fp w\<noteq>0"
+        using fr that unfolding r1_def by auto
+      moreover have "g w = gp w * (w-z) powi gn" "gp w \<noteq> 0"
+        using gr that unfolding r1_def by auto
+      ultimately show "fg w = (fp w * gp w) * (w-z) powi (fn+gn)" "fp w*gp w\<noteq>0"
+        using that by (auto simp add: fg_def power_int_add)
     qed
 
-    have [intro]: "fp \<midarrow>z\<rightarrow>fp z" "gp \<midarrow>z\<rightarrow>gp z"
+    obtain [intro]: "fp \<midarrow>z\<rightarrow>fp z" "gp \<midarrow>z\<rightarrow>gp z"
         using fr(1) \<open>fr>0\<close> gr(1) \<open>gr>0\<close>
-        by (meson open_ball ball_subset_cball centre_in_ball
-            continuous_on_eq_continuous_at continuous_within holomorphic_on_imp_continuous_on
-            holomorphic_on_subset)+
+        by (metis centre_in_ball continuous_at continuous_on_interior
+            holomorphic_on_imp_continuous_on interior_cball)
     have ?thesis when "fn+gn>0"
     proof -
-      have "(\<lambda>w. (fp w * gp w) * (w - z) ^ (nat (fn+gn))) \<midarrow>z\<rightarrow>0"
+      have "(\<lambda>w. (fp w * gp w) * (w-z) ^ (nat (fn+gn))) \<midarrow>z\<rightarrow>0"
         using that by (auto intro!:tendsto_eq_intros)
       then have "fg \<midarrow>z\<rightarrow> 0"
-         apply (elim Lim_transform_within[OF _ \<open>r1>0\<close>])
+        using Lim_transform_within[OF _ \<open>r1>0\<close>]
         by (smt (verit, best) Diff_iff dist_commute fg_times mem_ball power_int_def singletonD that zero_less_dist_iff)
       then show ?thesis unfolding not_essential_def fg_def by auto
     qed
@@ -749,7 +750,7 @@
       then have "fg \<midarrow>z\<rightarrow> fp z*gp z"
         apply (elim Lim_transform_within[OF _ \<open>r1>0\<close>])
         apply (subst fg_times)
-        by (auto simp add:dist_commute that)
+        by (auto simp add: dist_commute that)
       then show ?thesis unfolding not_essential_def fg_def by auto
     qed
     moreover have ?thesis when "fn+gn<0"
@@ -773,28 +774,26 @@
 qed
 
 lemma not_essential_inverse[singularity_intros]:
-  assumes f_ness:"not_essential f z"
-  assumes f_iso:"isolated_singularity_at f z"
+  assumes f_ness: "not_essential f z"
+  assumes f_iso: "isolated_singularity_at f z"
   shows "not_essential (\<lambda>w. inverse (f w)) z"
 proof -
   define vf where "vf = (\<lambda>w. inverse (f w))"
   have ?thesis when "\<not>(\<exists>\<^sub>Fw in (at z). f w\<noteq>0)"
   proof -
     have "\<forall>\<^sub>Fw in (at z). f w=0"
-      using that[unfolded frequently_def, simplified] by (auto elim: eventually_rev_mp)
+      using not_eventually that by fastforce
     then have "vf \<midarrow>z\<rightarrow>0" 
       unfolding vf_def by (simp add: tendsto_eventually)
-    then show ?thesis unfolding not_essential_def vf_def by auto
+    then show ?thesis 
+      unfolding not_essential_def vf_def by auto
   qed
   moreover have ?thesis when "is_pole f z"
+    by (metis (mono_tags, lifting) filterlim_at filterlim_inverse_at_iff is_pole_def
+        not_essential_def that)
+  moreover have ?thesis when "\<exists>x. f\<midarrow>z\<rightarrow>x " and f_nconst: "\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
   proof -
-    have "vf \<midarrow>z\<rightarrow>0"
-      using that filterlim_at filterlim_inverse_at_iff unfolding is_pole_def vf_def by blast
-    then show ?thesis unfolding not_essential_def vf_def by auto
-  qed
-  moreover have ?thesis when "\<exists>x. f\<midarrow>z\<rightarrow>x " and f_nconst:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
-  proof -
-    from that obtain fz where fz:"f\<midarrow>z\<rightarrow>fz" by auto
+    from that obtain fz where fz: "f\<midarrow>z\<rightarrow>fz" by auto
     have ?thesis when "fz=0"
 
     proof -
@@ -814,8 +813,8 @@
 qed
 
 lemma isolated_singularity_at_inverse[singularity_intros]:
-  assumes f_iso:"isolated_singularity_at f z"
-      and f_ness:"not_essential f z"
+  assumes f_iso: "isolated_singularity_at f z"
+      and f_ness: "not_essential f z"
   shows "isolated_singularity_at (\<lambda>w. inverse (f w)) z"
 proof -
   define vf where "vf = (\<lambda>w. inverse (f w))"
@@ -825,21 +824,22 @@
       using that[unfolded frequently_def, simplified] by (auto elim: eventually_rev_mp)
     then have "\<forall>\<^sub>Fw in (at z). vf w=0"
       unfolding vf_def by auto
-    then obtain d1 where "d1>0" and d1:"\<forall>x. x \<noteq> z \<and> dist x z < d1 \<longrightarrow> vf x = 0"
+    then obtain d1 where "d1>0" and d1: "\<forall>x. x \<noteq> z \<and> dist x z < d1 \<longrightarrow> vf x = 0"
       unfolding eventually_at by auto
     then have "vf holomorphic_on ball z d1-{z}"
-      apply (rule_tac holomorphic_transform[of "\<lambda>_. 0"])
-      by (auto simp add:dist_commute)
+      using holomorphic_transform[of "\<lambda>_. 0"]
+      by (metis Diff_iff dist_commute holomorphic_on_const insert_iff mem_ball)
     then have "vf analytic_on ball z d1 - {z}"
       by (simp add: analytic_on_open open_delete)
-    then show ?thesis using \<open>d1>0\<close> unfolding isolated_singularity_at_def vf_def by auto
+    then show ?thesis 
+      using \<open>d1>0\<close> unfolding isolated_singularity_at_def vf_def by auto
   qed
-  moreover have ?thesis when f_nconst:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
+  moreover have ?thesis when f_nconst: "\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
   proof -
     have "\<forall>\<^sub>F w in at z. f w \<noteq> 0" using non_zero_neighbour[OF f_iso f_ness f_nconst] .
-    then obtain d1 where d1:"d1>0" "\<forall>x. x \<noteq> z \<and> dist x z < d1 \<longrightarrow> f x \<noteq> 0"
+    then obtain d1 where d1: "d1>0" "\<forall>x. x \<noteq> z \<and> dist x z < d1 \<longrightarrow> f x \<noteq> 0"
       unfolding eventually_at by auto
-    obtain d2 where "d2>0" and d2:"f analytic_on ball z d2 - {z}"
+    obtain d2 where "d2>0" and d2: "f analytic_on ball z d2 - {z}"
       using f_iso unfolding isolated_singularity_at_def by auto
     define d3 where "d3=min d1 d2"
     have "d3>0" unfolding d3_def using \<open>d1>0\<close> \<open>d2>0\<close> by auto
@@ -849,31 +849,33 @@
     then have "vf analytic_on ball z d3 - {z}"
       unfolding vf_def
       by (intro analytic_on_inverse; simp add: d1(2) d3_def dist_commute)
-    ultimately show ?thesis unfolding isolated_singularity_at_def vf_def by auto
+    ultimately show ?thesis 
+      unfolding isolated_singularity_at_def vf_def by auto
   qed
   ultimately show ?thesis by auto
 qed
 
 lemma not_essential_divide[singularity_intros]:
-  assumes f_ness:"not_essential f z" and g_ness:"not_essential g z"
-  assumes f_iso:"isolated_singularity_at f z" and g_iso:"isolated_singularity_at g z"
+  assumes f_ness: "not_essential f z" and g_ness: "not_essential g z"
+  assumes f_iso: "isolated_singularity_at f z" and g_iso: "isolated_singularity_at g z"
   shows "not_essential (\<lambda>w. f w / g w) z"
 proof -
   have "not_essential (\<lambda>w. f w * inverse (g w)) z"
-    by (simp add: f_iso f_ness g_iso g_ness isolated_singularity_at_inverse not_essential_inverse not_essential_times)
-  then show ?thesis by (simp add:field_simps)
+    by (simp add: f_iso f_ness g_iso g_ness isolated_singularity_at_inverse
+        not_essential_inverse not_essential_times)
+  then show ?thesis by (simp add: field_simps)
 qed
 
 lemma
-  assumes f_iso:"isolated_singularity_at f z"
-      and g_iso:"isolated_singularity_at g z"
+  assumes f_iso: "isolated_singularity_at f z"
+      and g_iso: "isolated_singularity_at g z"
     shows isolated_singularity_at_times[singularity_intros]:
               "isolated_singularity_at (\<lambda>w. f w * g w) z"
       and isolated_singularity_at_add[singularity_intros]:
               "isolated_singularity_at (\<lambda>w. f w + g w) z"
 proof -
   obtain d1 d2 where "d1>0" "d2>0"
-      and d1:"f analytic_on ball z d1 - {z}" and d2:"g analytic_on ball z d2 - {z}"
+      and d1: "f analytic_on ball z d1 - {z}" and d2: "g analytic_on ball z d2 - {z}"
     using f_iso g_iso unfolding isolated_singularity_at_def by auto
   define d3 where "d3=min d1 d2"
   have "d3>0" unfolding d3_def using \<open>d1>0\<close> \<open>d2>0\<close> by auto
@@ -893,7 +895,7 @@
 qed
 
 lemma isolated_singularity_at_uminus[singularity_intros]:
-  assumes f_iso:"isolated_singularity_at f z"
+  assumes f_iso: "isolated_singularity_at f z"
   shows "isolated_singularity_at (\<lambda>w. - f w) z"
   using assms unfolding isolated_singularity_at_def using analytic_on_neg by blast
 
@@ -1044,7 +1046,7 @@
 
 lemma not_essential_uminus [singularity_intros]:
   assumes f_ness: "not_essential f z"
-  assumes f_iso:"isolated_singularity_at f z"
+  assumes f_iso: "isolated_singularity_at f z"
   shows "not_essential (\<lambda>w. -f w) z"
 proof -
   have "not_essential (\<lambda>w. -1 * f w) z"
@@ -1065,17 +1067,17 @@
                    \<and> h w \<noteq>0)))"
 
 definition\<^marker>\<open>tag important\<close> zor_poly
-    ::"[complex \<Rightarrow> complex, complex] \<Rightarrow> complex \<Rightarrow> complex" where
+    :: "[complex \<Rightarrow> complex, complex] \<Rightarrow> complex \<Rightarrow> complex" where
   "zor_poly f z = (SOME h. \<exists>r. r > 0 \<and> h holomorphic_on cball z r \<and> h z \<noteq> 0
-                   \<and> (\<forall>w\<in>cball z r - {z}. f w =  h w * (w - z) powi (zorder f z)
+                   \<and> (\<forall>w\<in>cball z r - {z}. f w =  h w * (w-z) powi (zorder f z)
                    \<and> h w \<noteq>0))"
 
 lemma zorder_exist:
-  fixes f::"complex \<Rightarrow> complex" and z::complex
+  fixes f:: "complex \<Rightarrow> complex" and z::complex
   defines "n \<equiv> zorder f z" and "g \<equiv> zor_poly f z"
-  assumes f_iso:"isolated_singularity_at f z"
-      and f_ness:"not_essential f z"
-      and f_nconst:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
+  assumes f_iso: "isolated_singularity_at f z"
+      and f_ness: "not_essential f z"
+      and f_nconst: "\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
   shows "g z\<noteq>0 \<and> (\<exists>r. r>0 \<and> g holomorphic_on cball z r
     \<and> (\<forall>w\<in>cball z r - {z}. f w  = g w * (w-z) powi n  \<and> g w \<noteq>0))"
 proof -
@@ -1084,13 +1086,13 @@
   have "\<exists>!k. \<exists>g r. P k g r"
     using holomorphic_factor_puncture[OF assms(3-)] unfolding P_def by auto
   then have "\<exists>g r. P n g r"
-    unfolding n_def P_def zorder_def
-    by (drule_tac theI',argo)
+    unfolding n_def P_def zorder_def by (rule theI')
   then have "\<exists>r. P n g r"
-    unfolding P_def zor_poly_def g_def n_def
-    by (drule_tac someI_ex,argo)
-  then obtain r1 where "P n g r1" by auto
-  then show ?thesis unfolding P_def by auto
+    unfolding P_def zor_poly_def g_def n_def by (rule someI_ex)
+  then obtain r1 where "P n g r1" 
+    by auto
+  then show ?thesis 
+    unfolding P_def by auto
 qed
 
 lemma zorder_shift:
@@ -1109,7 +1111,7 @@
     apply (rule_tac x="h o (\<lambda>u. u-z)" in exI)
     apply (rule_tac x="r" in exI)
     apply (intro conjI holomorphic_on_compose holomorphic_intros)
-       apply (simp_all add: flip: cball_translation_subtract)
+       apply (simp_all flip: cball_translation_subtract)
     by (metis diff_add_cancel eq_iff_diff_eq_0 norm_minus_commute)
   done
 
@@ -1117,10 +1119,10 @@
   by (rule zorder_shift)
 
 lemma
-  fixes f::"complex \<Rightarrow> complex" and z::complex
-  assumes f_iso:"isolated_singularity_at f z"
-      and f_ness:"not_essential f z"
-      and f_nconst:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
+  fixes f:: "complex \<Rightarrow> complex" and z::complex
+  assumes f_iso: "isolated_singularity_at f z"
+      and f_ness: "not_essential f z"
+      and f_nconst: "\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
     shows zorder_inverse: "zorder (\<lambda>w. inverse (f w)) z = - zorder f z"
       and zor_poly_inverse: "\<forall>\<^sub>Fw in (at z). zor_poly (\<lambda>w. inverse (f w)) z w
                                                 = inverse (zor_poly f z w)"
@@ -1131,33 +1133,32 @@
   define fp vfp where
     "fp = zor_poly f z" and "vfp = zor_poly vf z"
 
-  obtain fr where [simp]:"fp z \<noteq> 0" and "fr > 0"
+  obtain fr where [simp]: "fp z \<noteq> 0" and "fr > 0"
           and fr: "fp holomorphic_on cball z fr"
-                  "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w - z) powi fn \<and> fp w \<noteq> 0"
+                  "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w-z) powi fn \<and> fp w \<noteq> 0"
     using zorder_exist[OF f_iso f_ness f_nconst,folded fn_def fp_def]
     by auto
-  have fr_inverse: "vf w = (inverse (fp w)) * (w - z) powi (-fn)"
+  have fr_inverse: "vf w = (inverse (fp w)) * (w-z) powi (-fn)"
         and fr_nz: "inverse (fp w) \<noteq> 0"
     when "w\<in>ball z fr - {z}" for w
   proof -
-    have "f w = fp w * (w - z) powi fn" "fp w \<noteq> 0"
+    have "f w = fp w * (w-z) powi fn" "fp w \<noteq> 0"
       using fr(2) that by auto
-    then show "vf w = (inverse (fp w)) * (w - z) powi (-fn)" "inverse (fp w)\<noteq>0"
+    then show "vf w = (inverse (fp w)) * (w-z) powi (-fn)" "inverse (fp w)\<noteq>0"
       by (simp_all add: power_int_minus vf_def)
   qed
-  obtain vfr where [simp]:"vfp z \<noteq> 0" and "vfr>0" and vfr:"vfp holomorphic_on cball z vfr"
-      "(\<forall>w\<in>cball z vfr - {z}. vf w = vfp w * (w - z) powi vfn \<and> vfp w \<noteq> 0)"
+  obtain vfr where [simp]: "vfp z \<noteq> 0" and "vfr>0" and vfr: "vfp holomorphic_on cball z vfr"
+      "(\<forall>w\<in>cball z vfr - {z}. vf w = vfp w * (w-z) powi vfn \<and> vfp w \<noteq> 0)"
   proof -
     have "isolated_singularity_at vf z"
       using isolated_singularity_at_inverse[OF f_iso f_ness] unfolding vf_def .
     moreover have "not_essential vf z"
       using not_essential_inverse[OF f_ness f_iso] unfolding vf_def .
     moreover have "\<exists>\<^sub>F w in at z. vf w \<noteq> 0"
-      using f_nconst unfolding vf_def by (auto elim:frequently_elim1)
+      using f_nconst unfolding vf_def by (auto elim: frequently_elim1)
     ultimately show ?thesis using zorder_exist[of vf z, folded vfn_def vfp_def] that by auto
   qed
 
-
   define r1 where "r1 = min fr vfr"
   have "r1>0" using \<open>fr>0\<close> \<open>vfr>0\<close> unfolding r1_def by simp
   show "vfn = - fn"
@@ -1165,8 +1166,8 @@
     have \<section>: "\<And>w. \<lbrakk>fp w = 0; dist z w < fr\<rbrakk> \<Longrightarrow> False"
       using fr_nz by force
     then show "\<forall>w\<in>ball z r1 - {z}.
-               vf w = vfp w * (w - z) powi vfn \<and>
-               vfp w \<noteq> 0 \<and> vf w = inverse (fp w) * (w - z) powi (- fn) \<and>
+               vf w = vfp w * (w-z) powi vfn \<and>
+               vfp w \<noteq> 0 \<and> vf w = inverse (fp w) * (w-z) powi (- fn) \<and>
                inverse (fp w) \<noteq> 0"
       using fr_inverse r1_def vfr(2)
       by (smt (verit) Diff_iff inverse_nonzero_iff_nonzero mem_ball mem_cball)
@@ -1177,13 +1178,14 @@
   qed (use \<open>r1>0\<close> in auto)
   have "vfp w = inverse (fp w)" when "w\<in>ball z r1-{z}" for w
   proof -
-    have "w \<in> ball z fr - {z}" "w \<in> cball z vfr - {z}"  "w\<noteq>z" using that unfolding r1_def by auto
-    from fr_inverse[OF this(1)] fr_nz[OF this(1)] vfr(2)[rule_format,OF this(2)] \<open>vfn = - fn\<close> \<open>w\<noteq>z\<close>
-    show ?thesis by auto
+    have "w \<in> ball z fr - {z}" "w \<in> cball z vfr - {z}"  "w\<noteq>z"
+      using that unfolding r1_def by auto
+    then show ?thesis
+      by (metis \<open>vfn = - fn\<close> power_int_not_zero right_minus_eq  fr_inverse vfr(2)
+          vector_space_over_itself.scale_right_imp_eq) 
   qed
   then show "\<forall>\<^sub>Fw in (at z). vfp w = inverse (fp w)"
-    unfolding eventually_at using \<open>r1>0\<close>
-    by (metis DiffI dist_commute mem_ball singletonD)
+    unfolding eventually_at by (metis DiffI dist_commute mem_ball singletonD \<open>r1>0\<close>)
 qed
 
 lemma zor_poly_shift:
@@ -1193,9 +1195,9 @@
   shows "\<forall>\<^sub>F w in nhds z. zor_poly f z w = zor_poly (\<lambda>u. f (z + u)) 0 (w-z)"
 proof -
   obtain r1 where "r1>0" "zor_poly f z z \<noteq> 0" and
-      holo1:"zor_poly f z holomorphic_on cball z r1" and
-      rball1:"\<forall>w\<in>cball z r1 - {z}.
-           f w = zor_poly f z w * (w - z) powi (zorder f z) \<and>
+      holo1: "zor_poly f z holomorphic_on cball z r1" and
+      rball1: "\<forall>w\<in>cball z r1 - {z}.
+           f w = zor_poly f z w * (w-z) powi (zorder f z) \<and>
            zor_poly f z w \<noteq> 0"
     using zorder_exist[OF iso1 ness1 nzero1] by blast
 
@@ -1203,54 +1205,50 @@
   have "isolated_singularity_at ff 0"
     unfolding ff_def
     using iso1 isolated_singularity_at_shift_iff[of f 0 z]
-    by (simp add:algebra_simps)
+    by (simp add: algebra_simps)
   moreover have "not_essential ff 0"
     unfolding ff_def
     using ness1 not_essential_shift_iff[of f 0 z]
-    by (simp add:algebra_simps)
+    by (simp add: algebra_simps)
   moreover have "\<exists>\<^sub>F w in at 0. ff w \<noteq> 0"
     unfolding ff_def using nzero1
     by (smt (verit, ccfv_SIG) add.commute eventually_at_to_0
         eventually_mono not_frequently)
-  ultimately obtain r2 where "r2>0" "zor_poly ff 0 0 \<noteq> 0" and
-      holo2:"zor_poly ff 0 holomorphic_on cball 0 r2" and
-      rball2:"\<forall>w\<in>cball 0 r2 - {0}.
-           ff w = zor_poly ff 0 w * w powi (zorder ff 0) \<and>
-           zor_poly ff 0 w \<noteq> 0"
+  ultimately 
+  obtain r2 where "r2>0" "zor_poly ff 0 0 \<noteq> 0"
+          and holo2: "zor_poly ff 0 holomorphic_on cball 0 r2" 
+          and rball2: "\<forall>w\<in>cball 0 r2 - {0}.
+               ff w = zor_poly ff 0 w * w powi (zorder ff 0) \<and> zor_poly ff 0 w \<noteq> 0"
     using zorder_exist[of ff 0] by auto
 
   define r where "r=min r1 r2"
   have "r>0" using \<open>r1>0\<close> \<open>r2>0\<close> unfolding r_def by auto
 
-  have "zor_poly f z w = zor_poly ff 0 (w - z)"
+  have "zor_poly f z w = zor_poly ff 0 (w-z)"
     if "w\<in>ball z r - {z}" for w
   proof -
     define n where "n \<equiv> zorder f z"
 
-    have "f w = zor_poly f z w * (w - z) powi n"
+    have "f w = zor_poly f z w * (w-z) powi n"
       using n_def r_def rball1 that by auto
-    moreover have "f w = zor_poly ff 0 (w - z) * (w - z) powi n"
+    moreover have "f w = zor_poly ff 0 (w-z) * (w-z) powi n"
     proof -
       have "w-z\<in>cball 0 r2 - {0}"
-        using r_def that by (auto simp:dist_complex_def)
-      from rball2[rule_format, OF this]
-      have "ff (w - z) = zor_poly ff 0 (w - z) * (w - z)
-                            powi (zorder ff 0)"
-        by simp
+        using r_def that by (auto simp: dist_complex_def)
+      then have "ff (w-z) = zor_poly ff 0 (w-z) * (w-z) powi (zorder ff 0)"
+        using rball2 by blast
       moreover have "of_int (zorder ff 0) = n"
         unfolding n_def ff_def by (simp add:zorder_shift' add.commute)
       ultimately show ?thesis unfolding ff_def by auto
     qed
-    ultimately have "zor_poly f z w * (w - z) powi n
-                = zor_poly ff 0 (w - z) * (w - z) powi n"
+    ultimately have "zor_poly f z w * (w-z) powi n = zor_poly ff 0 (w-z) * (w-z) powi n"
       by auto
-    moreover have "(w - z) powi n \<noteq>0"
+    moreover have "(w-z) powi n \<noteq>0"
       using that by auto
     ultimately show ?thesis
       using mult_cancel_right by blast
   qed
-  then have "\<forall>\<^sub>F w in at z. zor_poly f z w
-                  = zor_poly ff 0 (w - z)"
+  then have "\<forall>\<^sub>F w in at z. zor_poly f z w = zor_poly ff 0 (w-z)"
     unfolding eventually_at
     by (metis DiffI \<open>0 < r\<close> dist_commute mem_ball singletonD)
   moreover have "isCont (zor_poly f z) z"
@@ -1258,20 +1256,21 @@
     by (simp add: \<open>0 < r1\<close> continuous_on_interior)
   moreover 
   have "isCont (zor_poly ff 0) 0"
-    using \<open>0 < r2\<close> centre_in_ball continuous_on_interior holo2 holomorphic_on_imp_continuous_on interior_cball by blast  
-  then have "isCont (\<lambda>w. zor_poly ff 0 (w - z)) z"
+    using \<open>0 < r2\<close> continuous_on_interior holo2 holomorphic_on_imp_continuous_on
+    by fastforce
+  then have "isCont (\<lambda>w. zor_poly ff 0 (w-z)) z"
       unfolding isCont_iff by simp
-  ultimately show "\<forall>\<^sub>F w in nhds z. zor_poly f z w = zor_poly ff 0 (w - z)"
+  ultimately show "\<forall>\<^sub>F w in nhds z. zor_poly f z w = zor_poly ff 0 (w-z)"
     by (elim at_within_isCont_imp_nhds;auto)
 qed
 
 lemma
-  fixes f g::"complex \<Rightarrow> complex" and z::complex
-  assumes f_iso:"isolated_singularity_at f z" and g_iso:"isolated_singularity_at g z"
-      and f_ness:"not_essential f z" and g_ness:"not_essential g z"
+  fixes f g:: "complex \<Rightarrow> complex" and z::complex
+  assumes f_iso: "isolated_singularity_at f z" and g_iso: "isolated_singularity_at g z"
+      and f_ness: "not_essential f z" and g_ness: "not_essential g z"
       and fg_nconst: "\<exists>\<^sub>Fw in (at z). f w * g w\<noteq> 0"
-  shows zorder_times:"zorder (\<lambda>w. f w * g w) z = zorder f z + zorder g z" and
-        zor_poly_times:"\<forall>\<^sub>Fw in (at z). zor_poly (\<lambda>w. f w * g w) z w
+  shows zorder_times: "zorder (\<lambda>w. f w * g w) z = zorder f z + zorder g z" and
+        zor_poly_times: "\<forall>\<^sub>Fw in (at z). zor_poly (\<lambda>w. f w * g w) z w
                                                   = zor_poly f z w *zor_poly g z w"
 proof -
   define fg where "fg = (\<lambda>w. f w * g w)"
@@ -1279,32 +1278,32 @@
     "fn = zorder f z" and "gn = zorder g z" and "fgn = zorder fg z"
   define fp gp fgp where
     "fp = zor_poly f z" and "gp = zor_poly g z" and "fgp = zor_poly fg z"
-  have f_nconst:"\<exists>\<^sub>Fw in (at z). f w \<noteq> 0" and g_nconst:"\<exists>\<^sub>Fw in (at z).g w\<noteq> 0"
+  have f_nconst: "\<exists>\<^sub>Fw in (at z). f w \<noteq> 0" and g_nconst: "\<exists>\<^sub>Fw in (at z).g w\<noteq> 0"
     using fg_nconst by (auto elim!:frequently_elim1)
-  obtain fr where [simp]:"fp z \<noteq> 0" and "fr > 0"
+  obtain fr where [simp]: "fp z \<noteq> 0" and "fr > 0"
           and fr: "fp holomorphic_on cball z fr"
-                  "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w - z) powi fn \<and> fp w \<noteq> 0"
+                  "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w-z) powi fn \<and> fp w \<noteq> 0"
     using zorder_exist[OF f_iso f_ness f_nconst,folded fp_def fn_def] by auto
-  obtain gr where [simp]:"gp z \<noteq> 0" and "gr > 0"
+  obtain gr where [simp]: "gp z \<noteq> 0" and "gr > 0"
           and gr: "gp holomorphic_on cball z gr"
-                  "\<forall>w\<in>cball z gr - {z}. g w = gp w * (w - z) powi gn \<and> gp w \<noteq> 0"
+                  "\<forall>w\<in>cball z gr - {z}. g w = gp w * (w-z) powi gn \<and> gp w \<noteq> 0"
     using zorder_exist[OF g_iso g_ness g_nconst,folded gn_def gp_def] by auto
   define r1 where "r1=min fr gr"
   have "r1>0" unfolding r1_def using \<open>fr>0\<close> \<open>gr>0\<close> by auto
-  have fg_times:"fg w = (fp w * gp w) * (w - z) powi (fn+gn)" and fgp_nz:"fp w*gp w\<noteq>0"
+  have fg_times: "fg w = (fp w * gp w) * (w-z) powi (fn+gn)" and fgp_nz: "fp w*gp w\<noteq>0"
     when "w\<in>ball z r1 - {z}" for w
   proof -
-    have "f w = fp w * (w - z) powi fn" "fp w \<noteq> 0"
-      using fr(2)[rule_format,of w] that unfolding r1_def by auto
-    moreover have "g w = gp w * (w - z) powi gn" "gp w \<noteq> 0"
+    have "f w = fp w * (w-z) powi fn" "fp w \<noteq> 0"
+      using fr(2) r1_def that by auto
+    moreover have "g w = gp w * (w-z) powi gn" "gp w \<noteq> 0"
       using gr(2) that unfolding r1_def by auto
-    ultimately show "fg w = (fp w * gp w) * (w - z) powi (fn+gn)" "fp w*gp w\<noteq>0"
-      using that unfolding fg_def by (auto simp add:power_int_add)
+    ultimately show "fg w = (fp w * gp w) * (w-z) powi (fn+gn)" "fp w*gp w\<noteq>0"
+      using that unfolding fg_def by (auto simp add: power_int_add)
   qed
 
-  obtain fgr where [simp]:"fgp z \<noteq> 0" and "fgr > 0"
+  obtain fgr where [simp]: "fgp z \<noteq> 0" and "fgr > 0"
           and fgr: "fgp holomorphic_on cball z fgr"
-                  "\<forall>w\<in>cball z fgr - {z}. fg w = fgp w * (w - z) powi fgn \<and> fgp w \<noteq> 0"
+                   "\<forall>w\<in>cball z fgr - {z}. fg w = fgp w * (w-z) powi fgn \<and> fgp w \<noteq> 0"
   proof -
     have "isolated_singularity_at fg z"
       unfolding fg_def using isolated_singularity_at_times[OF f_iso g_iso] .
@@ -1318,42 +1317,40 @@
   define r2 where "r2 = min fgr r1"
   have "r2>0" using \<open>r1>0\<close> \<open>fgr>0\<close> unfolding r2_def by simp
   show "fgn = fn + gn "
-    apply (rule holomorphic_factor_unique[of r2 fgp z "\<lambda>w. fp w * gp w" fg])
-    subgoal using \<open>r2>0\<close> by simp
-    subgoal by simp
-    subgoal by simp
-    subgoal
-    proof (rule ballI)
-      fix w assume "w \<in> ball z r2 - {z}"
-      then have "w \<in> ball z r1 - {z}" "w \<in> cball z fgr - {z}"  unfolding r2_def by auto
-      then show "fg w = fgp w * (w - z) powi fgn \<and> fgp w \<noteq> 0
-              \<and> fg w = fp w * gp w * (w - z) powi (fn + gn) \<and> fp w * gp w \<noteq> 0"
-        using fg_times fgp_nz fgr(2) by blast
-    qed
-    subgoal using fgr(1) unfolding r2_def r1_def by (auto intro!:holomorphic_intros)
-    subgoal using fr(1) gr(1) unfolding r2_def r1_def by (auto intro!:holomorphic_intros)
-    done
+  proof (rule holomorphic_factor_unique)
+    show "\<forall>w \<in> ball z r2 - {z}. fg w = fgp w * (w - z) powi fgn \<and> fgp w \<noteq> 0 \<and> fg w = fp w * gp w * (w - z) powi (fn + gn) \<and> fp w * gp w \<noteq> 0"
+      using fg_times fgp_nz fgr(2) r2_def by fastforce
+  next
+    show "fgp holomorphic_on ball z r2"
+      using fgr(1) r2_def by auto
+  next
+    show "(\<lambda>w. fp w * gp w) holomorphic_on ball z r2"
+      by (metis ball_subset_cball fr(1) gr(1) holomorphic_on_mult holomorphic_on_subset
+          min.cobounded1 min.cobounded2 r1_def r2_def subset_ball)
+  qed (auto simp add: \<open>0 < r2\<close>)
 
-  have "fgp w = fp w *gp w" when "w\<in>ball z r2-{z}" for w
+  have "fgp w = fp w *gp w" when w: "w \<in> ball z r2-{z}" for w
   proof -
-    have "w \<in> ball z r1 - {z}" "w \<in> cball z fgr - {z}" "w\<noteq>z" using that  unfolding r2_def by auto
-    from fg_times[OF this(1)] fgp_nz[OF this(1)] fgr(2)[rule_format,OF this(2)] \<open>fgn = fn + gn\<close> \<open>w\<noteq>z\<close>
-    show ?thesis by auto
+    have "w \<in> ball z r1 - {z}" "w \<in> cball z fgr - {z}" "w\<noteq>z" 
+      using w unfolding r2_def by auto
+    then show ?thesis
+      by (metis \<open>fgn = fn + gn\<close> eq_iff_diff_eq_0 fg_times fgr(2) power_int_eq_0_iff
+          mult_right_cancel)
   qed
   then show "\<forall>\<^sub>Fw in (at z). fgp w = fp w * gp w"
-    using \<open>r2>0\<close> unfolding eventually_at by (auto simp add:dist_commute)
+    using \<open>r2>0\<close> unfolding eventually_at by (auto simp add: dist_commute)
 qed
 
 lemma
-  fixes f g::"complex \<Rightarrow> complex" and z::complex
-  assumes f_iso:"isolated_singularity_at f z" and g_iso:"isolated_singularity_at g z"
-      and f_ness:"not_essential f z" and g_ness:"not_essential g z"
+  fixes f g:: "complex \<Rightarrow> complex" and z::complex
+  assumes f_iso: "isolated_singularity_at f z" and g_iso: "isolated_singularity_at g z"
+      and f_ness: "not_essential f z" and g_ness: "not_essential g z"
       and fg_nconst: "\<exists>\<^sub>Fw in (at z). f w * g w\<noteq> 0"
-  shows zorder_divide:"zorder (\<lambda>w. f w / g w) z = zorder f z - zorder g z" and
-        zor_poly_divide:"\<forall>\<^sub>Fw in (at z). zor_poly (\<lambda>w. f w / g w) z w
-                                                  = zor_poly f z w  / zor_poly g z w"
+  shows zorder_divide: "zorder (\<lambda>w. f w / g w) z = zorder f z - zorder g z" and
+        zor_poly_divide: "\<forall>\<^sub>Fw in (at z). zor_poly (\<lambda>w. f w / g w) z w
+                                       = zor_poly f z w  / zor_poly g z w"
 proof -
-  have f_nconst:"\<exists>\<^sub>Fw in (at z). f w \<noteq> 0" and g_nconst:"\<exists>\<^sub>Fw in (at z).g w\<noteq> 0"
+  have f_nconst: "\<exists>\<^sub>Fw in (at z). f w \<noteq> 0" and g_nconst: "\<exists>\<^sub>Fw in (at z).g w\<noteq> 0"
     using fg_nconst by (auto elim!:frequently_elim1)
   define vg where "vg=(\<lambda>w. inverse (g w))"
   have 1: "isolated_singularity_at vg z"
@@ -1362,59 +1359,53 @@
     by (simp add: g_iso g_ness not_essential_inverse vg_def)
   moreover have 3: "\<exists>\<^sub>F w in at z. f w * vg w \<noteq> 0"
     using fg_nconst vg_def by auto
-  ultimately  have "zorder (\<lambda>w. f w * vg w) z = zorder f z + zorder vg z"
+  ultimately have "zorder (\<lambda>w. f w * vg w) z = zorder f z + zorder vg z"
     using zorder_times[OF f_iso _ f_ness] by blast
   then show "zorder (\<lambda>w. f w / g w) z = zorder f z - zorder g z"
     using zorder_inverse[OF g_iso g_ness g_nconst,folded vg_def] unfolding vg_def
-    by (auto simp add:field_simps)
-
+    by (auto simp add: field_simps)
   have "\<forall>\<^sub>F w in at z. zor_poly (\<lambda>w. f w * vg w) z w = zor_poly f z w * zor_poly vg z w"
     using zor_poly_times[OF f_iso _ f_ness,of vg] 1 2 3 by blast
   then show "\<forall>\<^sub>Fw in (at z). zor_poly (\<lambda>w. f w / g w) z w = zor_poly f z w  / zor_poly g z w"
     using zor_poly_inverse[OF g_iso g_ness g_nconst,folded vg_def] unfolding vg_def
-    by eventually_elim (auto simp add:field_simps)
+    by eventually_elim (auto simp add: field_simps)
 qed
 
 lemma zorder_exist_zero:
-  fixes f::"complex \<Rightarrow> complex" and z::complex
-  defines "n\<equiv>zorder f z" and "g\<equiv>zor_poly f z"
-  assumes  holo: "f holomorphic_on s" and
-          "open s" "connected s" "z\<in>s"
-      and non_const: "\<exists>w\<in>s. f w \<noteq> 0"
-  shows "(if f z=0 then n > 0 else n=0) \<and> (\<exists>r. r>0 \<and> cball z r \<subseteq> s \<and> g holomorphic_on cball z r
+  fixes f:: "complex \<Rightarrow> complex" and z::complex
+  defines "n \<equiv> zorder f z" and "g \<equiv> zor_poly f z"
+  assumes  holo: "f holomorphic_on S" and "open S" "connected S" "z\<in>S"
+      and non_const: "\<exists>w\<in>S. f w \<noteq> 0"
+  shows "(if f z=0 then n > 0 else n=0) \<and> (\<exists>r. r>0 \<and> cball z r \<subseteq> S \<and> g holomorphic_on cball z r
     \<and> (\<forall>w\<in>cball z r. f w  = g w * (w-z) ^ nat n  \<and> g w \<noteq>0))"
 proof -
-  obtain r where "g z \<noteq> 0" and r: "r>0" "cball z r \<subseteq> s" "g holomorphic_on cball z r"
-            "(\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powi n \<and> g w \<noteq> 0)"
+  obtain r where "g z \<noteq> 0" and r: "r>0" "cball z r \<subseteq> S" "g holomorphic_on cball z r"
+            "(\<forall>w\<in>cball z r - {z}. f w = g w * (w-z) powi n \<and> g w \<noteq> 0)"
   proof -
     have "g z \<noteq> 0 \<and> (\<exists>r>0. g holomorphic_on cball z r
-            \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powi n \<and> g w \<noteq> 0))"
+            \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w-z) powi n \<and> g w \<noteq> 0))"
     proof (rule zorder_exist[of f z,folded g_def n_def])
-      show "isolated_singularity_at f z" unfolding isolated_singularity_at_def
-        using holo assms(4,6)
-        by (meson Diff_subset open_ball analytic_on_holomorphic holomorphic_on_subset openE)
+      show "isolated_singularity_at f z"
+        using \<open>open S\<close> \<open>z\<in>S\<close> holo holomorphic_on_imp_analytic_at isolated_singularity_at_analytic 
+        by force 
       show "not_essential f z" unfolding not_essential_def
-        using assms(4,6) at_within_open continuous_on holo holomorphic_on_imp_continuous_on
+        using \<open>open S\<close> \<open>z\<in>S\<close> at_within_open continuous_on holo holomorphic_on_imp_continuous_on
         by fastforce
-      have "\<forall>\<^sub>F w in at z. f w \<noteq> 0 \<and> w\<in>s"
-      proof -
-        obtain w where "w\<in>s" "f w\<noteq>0" using non_const by auto
-        then show ?thesis
-          by (rule non_zero_neighbour_alt[OF holo \<open>open s\<close> \<open>connected s\<close> \<open>z\<in>s\<close>])
-      qed
+      have "\<forall>\<^sub>F w in at z. f w \<noteq> 0 \<and> w\<in>S"
+        using assms(4,5,6) holo non_const non_zero_neighbour_alt by blast
       then show "\<exists>\<^sub>F w in at z. f w \<noteq> 0"
         by (auto elim: eventually_frequentlyE)
     qed
-    then obtain r1 where "g z \<noteq> 0" "r1>0" and r1:"g holomorphic_on cball z r1"
-            "(\<forall>w\<in>cball z r1 - {z}. f w = g w * (w - z) powi n \<and> g w \<noteq> 0)"
+    then obtain r1 where "g z \<noteq> 0" "r1>0" and r1: "g holomorphic_on cball z r1"
+            "(\<forall>w\<in>cball z r1 - {z}. f w = g w * (w-z) powi n \<and> g w \<noteq> 0)"
       by auto
-    obtain r2 where r2: "r2>0" "cball z r2 \<subseteq> s"
+    obtain r2 where r2: "r2>0" "cball z r2 \<subseteq> S"
       using assms(4,6) open_contains_cball_eq by blast
     define r3 where "r3 \<equiv> min r1 r2"
-    have "r3>0" "cball z r3 \<subseteq> s" using \<open>r1>0\<close> r2 unfolding r3_def by auto
+    have "r3>0" "cball z r3 \<subseteq> S" using \<open>r1>0\<close> r2 unfolding r3_def by auto
     moreover have "g holomorphic_on cball z r3"
       using r1(1) unfolding r3_def by auto
-    moreover have "(\<forall>w\<in>cball z r3 - {z}. f w = g w * (w - z) powi n \<and> g w \<noteq> 0)"
+    moreover have "(\<forall>w\<in>cball z r3 - {z}. f w = g w * (w-z) powi n \<and> g w \<noteq> 0)"
       using r1(2) unfolding r3_def by auto
     ultimately show ?thesis using that[of r3] \<open>g z\<noteq>0\<close> by auto
   qed
@@ -1425,24 +1416,24 @@
     using r
     by (meson Elementary_Metric_Spaces.open_ball analytic_at analytic_at_imp_isCont 
         ball_subset_cball centre_in_ball holomorphic_on_subset isContD)
-  have if_0:"if f z=0 then n > 0 else n=0"
+  have if_0: "if f z=0 then n > 0 else n=0"
   proof -
-    have "(\<lambda>w. g w * (w - z) powi n) \<midarrow>z\<rightarrow> f z"
+    have "(\<lambda>w. g w * (w-z) powi n) \<midarrow>z\<rightarrow> f z"
       using fz_lim Lim_transform_within_open[where s="ball z r"] r by fastforce
-    then have "(\<lambda>w. (g w * (w - z) powi n) / g w) \<midarrow>z\<rightarrow> f z/g z"
+    then have "(\<lambda>w. (g w * (w-z) powi n) / g w) \<midarrow>z\<rightarrow> f z/g z"
       using gz_lim \<open>g z \<noteq> 0\<close> tendsto_divide by blast
-    then have powi_tendsto:"(\<lambda>w. (w - z) powi n) \<midarrow>z\<rightarrow> f z/g z"
+    then have powi_tendsto: "(\<lambda>w. (w-z) powi n) \<midarrow>z\<rightarrow> f z/g z"
       using Lim_transform_within_open[where s="ball z r"] r by fastforce
 
     have ?thesis when "n\<ge>0" "f z=0"
     proof -
-      have "(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> f z/g z"
+      have "(\<lambda>w. (w-z) ^ nat n) \<midarrow>z\<rightarrow> f z/g z"
         using Lim_transform_within[OF powi_tendsto, where d=r]
         by (meson power_int_def r(1) that(1))
-      then have *:"(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> 0" using \<open>f z=0\<close> by simp
+      then have *: "(\<lambda>w. (w-z) ^ nat n) \<midarrow>z\<rightarrow> 0" using \<open>f z=0\<close> by simp
       moreover have False when "n=0"
       proof -
-        have "(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> 1"
+        have "(\<lambda>w. (w-z) ^ nat n) \<midarrow>z\<rightarrow> 1"
           using \<open>n=0\<close> by auto
         then show False using * using LIM_unique zero_neq_one by blast
       qed
@@ -1452,28 +1443,30 @@
     proof -
       have False when "n>0"
       proof -
-        have "(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> f z/g z"
+        have "(\<lambda>w. (w-z) ^ nat n) \<midarrow>z\<rightarrow> f z/g z"
           using Lim_transform_within[OF powi_tendsto, where d=r]
           by (meson \<open>0 \<le> n\<close> power_int_def r(1))
-        moreover have "(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> 0"
+        moreover have "(\<lambda>w. (w-z) ^ nat n) \<midarrow>z\<rightarrow> 0"
           using \<open>n>0\<close> by (auto intro!:tendsto_eq_intros)
-        ultimately show False using \<open>f z\<noteq>0\<close> \<open>g z\<noteq>0\<close> using LIM_unique divide_eq_0_iff by blast
+        ultimately show False 
+          using \<open>f z\<noteq>0\<close> \<open>g z\<noteq>0\<close> LIM_unique divide_eq_0_iff by blast
       qed
       then show ?thesis using that by force
     qed
     moreover have False when "n<0"
     proof -
-      have "(\<lambda>w. inverse ((w - z) ^ nat (- n))) \<midarrow>z\<rightarrow> f z/g z"
+      have "(\<lambda>w. inverse ((w-z) ^ nat (- n))) \<midarrow>z\<rightarrow> f z/g z"
         by (smt (verit) LIM_cong power_int_def power_inverse powi_tendsto that)
       moreover
-      have "(\<lambda>w.((w - z) ^ nat (- n))) \<midarrow>z\<rightarrow> 0"
+      have "(\<lambda>w.((w-z) ^ nat (- n))) \<midarrow>z\<rightarrow> 0"
         using that by (auto intro!:tendsto_eq_intros)
       ultimately
       have "(\<lambda>x. inverse ((x - z) ^ nat (- n)) * (x - z) ^ nat (- n)) \<midarrow>z\<rightarrow> 0" 
         using tendsto_mult by fastforce
       then have "(\<lambda>x. 1::complex) \<midarrow>z\<rightarrow> 0"
         using Lim_transform_within_open by fastforce
-      then show False using LIM_const_eq by fastforce
+      then show False 
+        using LIM_const_eq by fastforce
     qed
     ultimately show ?thesis by fastforce
   qed
@@ -1499,7 +1492,7 @@
     then show ?thesis using \<open>g z\<noteq>0\<close> True by auto
   next
     case False
-    then have "f w = g w * (w - z) powi n \<and> g w \<noteq> 0"
+    then have "f w = g w * (w-z) powi n" "g w \<noteq> 0"
       using r(4) that by auto
     then show ?thesis
       by (smt (verit, best) False if_0 int_nat_eq power_int_of_nat)
@@ -1508,17 +1501,17 @@
 qed
 
 lemma zorder_exist_pole:
-  fixes f::"complex \<Rightarrow> complex" and z::complex
+  fixes f:: "complex \<Rightarrow> complex" and z::complex
   defines "n\<equiv>zorder f z" and "g\<equiv>zor_poly f z"
   assumes  holo: "f holomorphic_on S-{z}" and "open S" "z\<in>S" and "is_pole f z"
   shows "n < 0 \<and> g z\<noteq>0 \<and> (\<exists>r. r>0 \<and> cball z r \<subseteq> S \<and> g holomorphic_on cball z r
     \<and> (\<forall>w\<in>cball z r - {z}. f w  = g w / (w-z) ^ nat (- n) \<and> g w \<noteq>0))"
 proof -
   obtain r where "g z \<noteq> 0" and r: "r>0" "cball z r \<subseteq> S" "g holomorphic_on cball z r"
-            "(\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powi n \<and> g w \<noteq> 0)"
+            "(\<forall>w\<in>cball z r - {z}. f w = g w * (w-z) powi n \<and> g w \<noteq> 0)"
   proof -
     have "g z \<noteq> 0 \<and> (\<exists>r>0. g holomorphic_on cball z r
-            \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powi n \<and> g w \<noteq> 0))"
+            \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w-z) powi n \<and> g w \<noteq> 0))"
     proof (rule zorder_exist[of f z,folded g_def n_def])
       show "isolated_singularity_at f z" unfolding isolated_singularity_at_def
         using holo assms(4,5)
@@ -1529,8 +1522,8 @@
       from non_zero_neighbour_pole[OF \<open>is_pole f z\<close>] show "\<exists>\<^sub>F w in at z. f w \<noteq> 0"
         by (auto elim: eventually_frequentlyE)
     qed
-    then obtain r1 where "g z \<noteq> 0" "r1>0" and r1:"g holomorphic_on cball z r1"
-            "(\<forall>w\<in>cball z r1 - {z}. f w = g w * (w - z) powi n \<and> g w \<noteq> 0)"
+    then obtain r1 where "g z \<noteq> 0" "r1>0" and r1: "g holomorphic_on cball z r1"
+            "(\<forall>w\<in>cball z r1 - {z}. f w = g w * (w-z) powi n \<and> g w \<noteq> 0)"
       by auto
     obtain r2 where r2: "r2>0" "cball z r2 \<subseteq> S"
       using assms(4,5) open_contains_cball_eq by metis
@@ -1538,22 +1531,24 @@
     have "r3>0" "cball z r3 \<subseteq> S" using \<open>r1>0\<close> r2 unfolding r3_def by auto
     moreover have "g holomorphic_on cball z r3"
       using r1(1) unfolding r3_def by auto
-    moreover have "(\<forall>w\<in>cball z r3 - {z}. f w = g w * (w - z) powi n \<and> g w \<noteq> 0)"
+    moreover have "(\<forall>w\<in>cball z r3 - {z}. f w = g w * (w-z) powi n \<and> g w \<noteq> 0)"
       using r1(2) unfolding r3_def by auto
-    ultimately show ?thesis using that[of r3] \<open>g z\<noteq>0\<close> by auto
+    ultimately show ?thesis 
+      using that[of r3] \<open>g z\<noteq>0\<close> by auto
   qed
 
   have "n<0"
   proof (rule ccontr)
     assume " \<not> n < 0"
     define c where "c=(if n=0 then g z else 0)"
-    have [simp]:"g \<midarrow>z\<rightarrow> g z"
-      by (metis open_ball at_within_open ball_subset_cball centre_in_ball
-            continuous_on holomorphic_on_imp_continuous_on holomorphic_on_subset r(1) r(3) )
-    have "\<forall>\<^sub>F x in at z. f x = g x * (x - z) ^ nat n"
-      unfolding eventually_at_topological
-      apply (rule_tac exI[where x="ball z r"])
-      by (simp add: \<open>\<not> n < 0\<close> linorder_not_le power_int_def r(1) r(4))
+    have [simp]: "g \<midarrow>z\<rightarrow> g z"
+      using r
+      by (metis centre_in_ball continuous_on_interior holomorphic_on_imp_continuous_on
+          interior_cball isContD)
+    have "\<forall>x \<in> ball z r. x \<noteq> z \<longrightarrow> f x = g x * (x - z) ^ nat n"
+      by (simp add: \<open>\<not> n < 0\<close> linorder_not_le power_int_def r)
+    then have "\<forall>\<^sub>F x in at z. f x = g x * (x - z) ^ nat n"
+      using centre_in_ball eventually_at_topological r(1) by blast
     moreover have "(\<lambda>x. g x * (x - z) ^ nat n) \<midarrow>z\<rightarrow> c"
     proof (cases "n=0")
       case True
@@ -1572,12 +1567,13 @@
   moreover have "\<forall>w\<in>cball z r - {z}. f w  = g w / (w-z) ^ nat (- n) \<and> g w \<noteq>0"
     using r(4) \<open>n<0\<close>
     by (smt (verit) inverse_eq_divide mult.right_neutral power_int_def power_inverse times_divide_eq_right)
-  ultimately show ?thesis using r(1-3) \<open>g z\<noteq>0\<close> by auto
+  ultimately show ?thesis 
+    using r \<open>g z\<noteq>0\<close> by auto
 qed
 
 lemma zorder_eqI:
   assumes "open S" "z \<in> S" "g holomorphic_on S" "g z \<noteq> 0"
-  assumes fg_eq:"\<And>w. \<lbrakk>w \<in> S;w\<noteq>z\<rbrakk> \<Longrightarrow> f w = g w * (w - z) powi n"
+  assumes fg_eq: "\<And>w. \<lbrakk>w \<in> S;w\<noteq>z\<rbrakk> \<Longrightarrow> f w = g w * (w-z) powi n"
   shows   "zorder f z = n"
 proof -
   have "continuous_on S g" by (rule holomorphic_on_imp_continuous_on) fact
@@ -1588,7 +1584,7 @@
   ultimately obtain r where r: "r > 0" "cball z r \<subseteq>  S \<inter> (g -` (-{0}))"
     unfolding open_contains_cball by blast
 
-  let ?gg= "(\<lambda>w. g w * (w - z) powi n)"
+  let ?gg= "(\<lambda>w. g w * (w-z) powi n)"
   define P where "P = (\<lambda>n g r. 0 < r \<and> g holomorphic_on cball z r \<and> g z\<noteq>0
           \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w-z) powi n \<and> g w\<noteq>0))"
   have "P n g r"
@@ -1611,13 +1607,13 @@
             isCont_def not_essential_def)
       show " \<forall>\<^sub>F w in at z. w - z \<noteq> 0" by (simp add: eventually_at_filter)
       then show "LIM w at z. w - z :> at 0"
-        unfolding filterlim_at by (auto intro:tendsto_eq_intros)
+        unfolding filterlim_at by (auto intro: tendsto_eq_intros)
       show "isolated_singularity_at g z"
         by (meson Diff_subset open_ball analytic_on_holomorphic
             assms holomorphic_on_subset isolated_singularity_at_def openE)
     qed
     moreover
-    have "\<forall>\<^sub>F w in at z. g w * (w - z) powi n = f w"
+    have "\<forall>\<^sub>F w in at z. g w * (w-z) powi n = f w"
       unfolding eventually_at_topological using assms fg_eq by force
     ultimately show "not_essential f z"
       using not_essential_transform by blast
@@ -1626,12 +1622,12 @@
       fix d::real assume "0 < d"
       define z' where "z' \<equiv> z+min d r / 2"
       have "z' \<noteq> z" " dist z' z < d "
-        unfolding z'_def using \<open>d>0\<close> \<open>r>0\<close> by (auto simp add:dist_norm)
+        unfolding z'_def using \<open>d>0\<close> \<open>r>0\<close> by (auto simp add: dist_norm)
       moreover have "f z' \<noteq> 0"
       proof (subst fg_eq[OF _ \<open>z'\<noteq>z\<close>])
         have "z' \<in> cball z r"
-          unfolding z'_def using \<open>r>0\<close> \<open>d>0\<close> by (auto simp add:dist_norm)
-        then show " z' \<in> S" using r(2) by blast
+          unfolding z'_def using \<open>r>0\<close> \<open>d>0\<close> by (auto simp add: dist_norm)
+        then show "z' \<in> S" using r(2) by blast
         show "g z' * (z' - z) powi n \<noteq> 0"
           using P_def \<open>P n g r\<close> \<open>z' \<in> cball z r\<close> \<open>z' \<noteq> z\<close> by auto
       qed
@@ -1645,47 +1641,47 @@
 
 lemma simple_zeroI:
   assumes "open S" "z \<in> S" "g holomorphic_on S" "g z \<noteq> 0"
-  assumes "\<And>w. w \<in> S \<Longrightarrow> f w = g w * (w - z)"
+  assumes "\<And>w. w \<in> S \<Longrightarrow> f w = g w * (w-z)"
   shows   "zorder f z = 1"
   using assms zorder_eqI by force
 
 lemma higher_deriv_power:
-  shows   "(deriv ^^ j) (\<lambda>w. (w - z) ^ n) w =
-             pochhammer (of_nat (Suc n - j)) j * (w - z) ^ (n - j)"
+  shows   "(deriv ^^ j) (\<lambda>w. (w-z) ^ n) w =
+             pochhammer (of_nat (Suc n - j)) j * (w-z) ^ (n - j)"
 proof (induction j arbitrary: w)
   case 0
   thus ?case by auto
 next
   case (Suc j w)
-  have "(deriv ^^ Suc j) (\<lambda>w. (w - z) ^ n) w = deriv ((deriv ^^ j) (\<lambda>w. (w - z) ^ n)) w"
+  have "(deriv ^^ Suc j) (\<lambda>w. (w-z) ^ n) w = deriv ((deriv ^^ j) (\<lambda>w. (w-z) ^ n)) w"
     by simp
-  also have "(deriv ^^ j) (\<lambda>w. (w - z) ^ n) =
-               (\<lambda>w. pochhammer (of_nat (Suc n - j)) j * (w - z) ^ (n - j))"
+  also have "(deriv ^^ j) (\<lambda>w. (w-z) ^ n) =
+               (\<lambda>w. pochhammer (of_nat (Suc n - j)) j * (w-z) ^ (n - j))"
     using Suc by (intro Suc.IH ext)
   also {
     have "(\<dots> has_field_derivative of_nat (n - j) *
-               pochhammer (of_nat (Suc n - j)) j * (w - z) ^ (n - Suc j)) (at w)"
+               pochhammer (of_nat (Suc n - j)) j * (w-z) ^ (n - Suc j)) (at w)"
       using Suc.prems by (auto intro!: derivative_eq_intros)
     also have "of_nat (n - j) * pochhammer (of_nat (Suc n - j)) j =
                  pochhammer (of_nat (Suc n - Suc j)) (Suc j)"
       by (cases "Suc j \<le> n", subst pochhammer_rec)
-         (insert Suc.prems, simp_all add: algebra_simps Suc_diff_le pochhammer_0_left)
-    finally have "deriv (\<lambda>w. pochhammer (of_nat (Suc n - j)) j * (w - z) ^ (n - j)) w =
-                    \<dots> * (w - z) ^ (n - Suc j)"
+         (use Suc.prems in \<open>simp_all add: algebra_simps Suc_diff_le pochhammer_0_left\<close>)
+    finally have "deriv (\<lambda>w. pochhammer (of_nat (Suc n - j)) j * (w-z) ^ (n - j)) w =
+                    \<dots> * (w-z) ^ (n - Suc j)"
       by (rule DERIV_imp_deriv)
   }
   finally show ?case .
 qed
 
 lemma zorder_zero_eqI:
-  assumes  f_holo:"f holomorphic_on S" and "open S" "z \<in> S"
+  assumes  f_holo: "f holomorphic_on S" and "open S" "z \<in> S"
   assumes zero: "\<And>i. i < nat n \<Longrightarrow> (deriv ^^ i) f z = 0"
   assumes nz: "(deriv ^^ nat n) f z \<noteq> 0" and "n\<ge>0"
   shows   "zorder f z = n"
 proof -
-  obtain r where [simp]:"r>0" and "ball z r \<subseteq> S"
+  obtain r where [simp]: "r>0" and "ball z r \<subseteq> S"
     using \<open>open S\<close> \<open>z\<in>S\<close> openE by blast
-  have nz':"\<exists>w\<in>ball z r. f w \<noteq> 0"
+  have nz': "\<exists>w\<in>ball z r. f w \<noteq> 0"
   proof (rule ccontr)
     assume "\<not> (\<exists>w\<in>ball z r. f w \<noteq> 0)"
     then have "eventually (\<lambda>u. f u = 0) (nhds z)"
@@ -1701,7 +1697,7 @@
   obtain e where e_if: "if f z = 0 then 0 < zn else zn = 0" and
             [simp]: "e>0" and "cball z e \<subseteq> ball z r" and
             g_holo: "g holomorphic_on cball z e" and
-            e_fac: "(\<forall>w\<in>cball z e. f w = g w * (w - z) ^ nat zn \<and> g w \<noteq> 0)"
+            e_fac: "(\<forall>w\<in>cball z e. f w = g w * (w-z) ^ nat zn \<and> g w \<noteq> 0)"
   proof -
     have "f holomorphic_on ball z r"
       using f_holo \<open>ball z r \<subseteq> S\<close> by auto
@@ -1712,23 +1708,23 @@
     by (metis centre_in_cball less_le_not_le order_refl)
 
   define A where "A \<equiv> (\<lambda>i. of_nat (i choose (nat zn)) * fact (nat zn) * (deriv ^^ (i - nat zn)) g z)"
-  have deriv_A:"(deriv ^^ i) f z = (if zn \<le> int i then A i else 0)" for i
+  have deriv_A: "(deriv ^^ i) f z = (if zn \<le> int i then A i else 0)" for i
   proof -
     have "eventually (\<lambda>w. w \<in> ball z e) (nhds z)"
       using \<open>cball z e \<subseteq> ball z r\<close> \<open>e>0\<close> by (intro eventually_nhds_in_open) auto
-    hence "eventually (\<lambda>w. f w = (w - z) ^ (nat zn) * g w) (nhds z)"
+    hence "eventually (\<lambda>w. f w = (w-z) ^ (nat zn) * g w) (nhds z)"
       using e_fac eventually_mono by fastforce
-    hence "(deriv ^^ i) f z = (deriv ^^ i) (\<lambda>w. (w - z) ^ nat zn * g w) z"
+    hence "(deriv ^^ i) f z = (deriv ^^ i) (\<lambda>w. (w-z) ^ nat zn * g w) z"
       by (intro higher_deriv_cong_ev) auto
     also have "\<dots> = (\<Sum>j=0..i. of_nat (i choose j) *
-                       (deriv ^^ j) (\<lambda>w. (w - z) ^ nat zn) z * (deriv ^^ (i - j)) g z)"
+                       (deriv ^^ j) (\<lambda>w. (w-z) ^ nat zn) z * (deriv ^^ (i - j)) g z)"
       using g_holo \<open>e>0\<close>
       by (intro higher_deriv_mult[of _ "ball z e"]) (auto intro!: holomorphic_intros)
     also have "\<dots> = (\<Sum>j=0..i. if j = nat zn then
                     of_nat (i choose nat zn) * fact (nat zn) * (deriv ^^ (i - nat zn)) g z else 0)"
     proof (intro sum.cong refl, goal_cases)
       case (1 j)
-      have "(deriv ^^ j) (\<lambda>w. (w - z) ^ nat zn) z =
+      have "(deriv ^^ j) (\<lambda>w. (w-z) ^ nat zn) z =
               pochhammer (of_nat (Suc (nat zn) - j)) j * 0 ^ (nat zn - j)"
         by (subst higher_deriv_power) auto
       also have "\<dots> = (if j = nat zn then fact j else 0)"
@@ -1745,18 +1741,15 @@
   qed
 
   have False when "n<zn"
-  proof -
-    have "(deriv ^^ nat n) f z = 0"
-      using deriv_A[of "nat n"] that \<open>n\<ge>0\<close> by auto
-    with nz show False by auto
-  qed
+    using deriv_A[of "nat n"] that \<open>n\<ge>0\<close> by (simp add: nz) 
   moreover have "n\<le>zn"
   proof -
-    have "g z \<noteq> 0" using e_fac[rule_format,of z] \<open>e>0\<close> by simp
+    have "g z \<noteq> 0"
+      by (simp add: \<open>g z \<noteq> 0\<close>)
     then have "(deriv ^^ nat zn) f z \<noteq> 0"
-      using deriv_A[of "nat zn"] by(auto simp add:A_def)
+      using deriv_A[of "nat zn"] by(auto simp add: A_def)
     then have "nat zn \<ge> nat n" using zero[of "nat zn"] by linarith
-    moreover have "zn\<ge>0" using e_if by (auto split:if_splits)
+    moreover have "zn\<ge>0" using e_if by (auto split: if_splits)
     ultimately show ?thesis using nat_le_eq_zle by blast
   qed
   ultimately show ?thesis unfolding zn_def by fastforce
@@ -1764,7 +1757,7 @@
 
 lemma
   assumes "eventually (\<lambda>z. f z = g z) (at z)" "z = z'"
-  shows zorder_cong:"zorder f z = zorder g z'" and zor_poly_cong:"zor_poly f z = zor_poly g z'"
+  shows zorder_cong: "zorder f z = zorder g z'" and zor_poly_cong: "zor_poly f z = zor_poly g z'"
 proof -
   define P where "P = (\<lambda>ff n h r. 0 < r \<and> h holomorphic_on cball z r \<and> h z\<noteq>0
                     \<and> (\<forall>w\<in>cball z r - {z}. ff w = h w * (w-z) powi n \<and> h w\<noteq>0))"
@@ -1772,19 +1765,19 @@
   proof -
     have *: "\<exists>r. P g n h r" if "\<exists>r. P f n h r" and "eventually (\<lambda>x. f x = g x) (at z)" for f g
     proof -
-      from that(1) obtain r1 where r1_P:"P f n h r1" by auto
-      from that(2) obtain r2 where "r2>0" and r2_dist:"\<forall>x. x \<noteq> z \<and> dist x z \<le> r2 \<longrightarrow> f x = g x"
+      from that(1) obtain r1 where r1_P: "P f n h r1" by auto
+      from that(2) obtain r2 where "r2>0" and r2_dist: "\<forall>x. x \<noteq> z \<and> dist x z \<le> r2 \<longrightarrow> f x = g x"
         unfolding eventually_at_le by auto
       define r where "r=min r1 r2"
       have "r>0" "h z\<noteq>0" using r1_P \<open>r2>0\<close> unfolding r_def P_def by auto
       moreover have "h holomorphic_on cball z r"
         using r1_P unfolding P_def r_def by auto
-      moreover have "g w = h w * (w - z) powi n \<and> h w \<noteq> 0" when "w\<in>cball z r - {z}" for w
+      moreover have "g w = h w * (w-z) powi n \<and> h w \<noteq> 0" when "w\<in>cball z r - {z}" for w
       proof -
-        have "f w = h w * (w - z) powi n \<and> h w \<noteq> 0"
+        have "f w = h w * (w-z) powi n \<and> h w \<noteq> 0"
           using r1_P that unfolding P_def r_def by auto
-        moreover have "f w=g w" using r2_dist[rule_format,of w] that unfolding r_def
-          by (simp add: dist_commute)
+        moreover have "f w=g w"
+          using r2_dist that by (simp add: dist_commute r_def)
         ultimately show ?thesis by simp
       qed
       ultimately show ?thesis unfolding P_def by auto
@@ -1792,7 +1785,7 @@
     from assms have eq': "eventually (\<lambda>z. g z = f z) (at z)"
       by (simp add: eq_commute)
     show ?thesis
-      by (rule iffI[OF *[OF _ assms(1)] *[OF _ eq']])
+      using "*" assms(1) eq' by blast
   qed
   then show "zorder f z = zorder g z'" "zor_poly f z = zor_poly g z'"
       using \<open>z=z'\<close> unfolding P_def zorder_def zor_poly_def by auto
@@ -1810,8 +1803,9 @@
 proof -
   define P where
     "P = (\<lambda>f n h r. 0 < r \<and> h holomorphic_on cball z r \<and>
-              h z \<noteq> 0 \<and> (\<forall>w\<in>cball z r - {z}. f w = h w * (w - z) powi n \<and> h w \<noteq> 0))"
-  have *: "P (\<lambda>x. c * f x) n (\<lambda>x. c * h x) r" if "P f n h r" "c \<noteq> 0" for f n h r c
+                    h z \<noteq> 0 \<and> (\<forall>w\<in>cball z r - {z}. f w = h w * (w-z) powi n \<and> h w \<noteq> 0))"
+  have *: "P (\<lambda>x. c * f x) n (\<lambda>x. c * h x) r" 
+    if "P f n h r" "c \<noteq> 0" for f n h r c
     using that unfolding P_def by (auto intro!: holomorphic_intros)
   have "(\<exists>h r. P (\<lambda>x. c * f x) n h r) \<longleftrightarrow> (\<exists>h r. P f n h r)" for n
     using *[of f n _ _ c] *[of "\<lambda>x. c * f x" n _ _ "inverse c"] \<open>c \<noteq> 0\<close>
@@ -1827,17 +1821,17 @@
 
 lemma zorder_nonzero_div_power:
   assumes sz: "open S" "z \<in> S" "f holomorphic_on S" "f z \<noteq> 0" and "n > 0"
-  shows  "zorder (\<lambda>w. f w / (w - z) ^ n) z = - n"
+  shows  "zorder (\<lambda>w. f w / (w-z) ^ n) z = - n"
   by (intro zorder_eqI [OF sz]) (simp add: inverse_eq_divide power_int_minus)
 
 lemma zor_poly_eq:
   assumes "isolated_singularity_at f z" "not_essential f z" "\<exists>\<^sub>F w in at z. f w \<noteq> 0"
-  shows "eventually (\<lambda>w. zor_poly f z w = f w * (w - z) powi - zorder f z) (at z)"
+  shows "eventually (\<lambda>w. zor_poly f z w = f w * (w-z) powi - zorder f z) (at z)"
 proof -
-  obtain r where r:"r>0"
-       "(\<forall>w\<in>cball z r - {z}. f w = zor_poly f z w * (w - z) powi (zorder f z))"
+  obtain r where r: "r>0"
+       "(\<forall>w\<in>cball z r - {z}. f w = zor_poly f z w * (w-z) powi (zorder f z))"
     using zorder_exist[OF assms] by blast
-  then have *: "\<forall>w\<in>ball z r - {z}. zor_poly f z w = f w * (w - z) powi - zorder f z"
+  then have *: "\<forall>w\<in>ball z r - {z}. zor_poly f z w = f w * (w-z) powi - zorder f z"
     by (auto simp: field_simps power_int_minus)
   have "eventually (\<lambda>w. w \<in> ball z r - {z}) (at z)"
     using r eventually_at_ball'[of r z UNIV] by auto
@@ -1846,12 +1840,12 @@
 
 lemma zor_poly_zero_eq:
   assumes "f holomorphic_on S" "open S" "connected S" "z \<in> S" "\<exists>w\<in>S. f w \<noteq> 0"
-  shows "eventually (\<lambda>w. zor_poly f z w = f w / (w - z) ^ nat (zorder f z)) (at z)"
+  shows "eventually (\<lambda>w. zor_poly f z w = f w / (w-z) ^ nat (zorder f z)) (at z)"
 proof -
-  obtain r where r:"r>0"
-       "(\<forall>w\<in>cball z r - {z}. f w = zor_poly f z w * (w - z) ^ nat (zorder f z))"
+  obtain r where r: "r>0"
+       "(\<forall>w\<in>cball z r - {z}. f w = zor_poly f z w * (w-z) ^ nat (zorder f z))"
     using zorder_exist_zero[OF assms] by auto
-  then have *: "\<forall>w\<in>ball z r - {z}. zor_poly f z w = f w / (w - z) ^ nat (zorder f z)"
+  then have *: "\<forall>w\<in>ball z r - {z}. zor_poly f z w = f w / (w-z) ^ nat (zorder f z)"
     by (auto simp: field_simps powr_minus)
   have "eventually (\<lambda>w. w \<in> ball z r - {z}) (at z)"
     using r eventually_at_ball'[of r z UNIV] by auto
@@ -1859,15 +1853,15 @@
 qed
 
 lemma zor_poly_pole_eq:
-  assumes f_iso:"isolated_singularity_at f z" "is_pole f z"
-  shows "eventually (\<lambda>w. zor_poly f z w = f w * (w - z) ^ nat (- zorder f z)) (at z)"
+  assumes f_iso: "isolated_singularity_at f z" "is_pole f z"
+  shows "eventually (\<lambda>w. zor_poly f z w = f w * (w-z) ^ nat (- zorder f z)) (at z)"
 proof -
-  obtain e where [simp]:"e>0" and f_holo:"f holomorphic_on ball z e - {z}"
+  obtain e where [simp]: "e>0" and f_holo: "f holomorphic_on ball z e - {z}"
     using f_iso analytic_imp_holomorphic unfolding isolated_singularity_at_def by blast
-  obtain r where r:"r>0"
-       "(\<forall>w\<in>cball z r - {z}. f w = zor_poly f z w / (w - z) ^ nat (- zorder f z))"
+  obtain r where r: "r>0"
+       "(\<forall>w\<in>cball z r - {z}. f w = zor_poly f z w / (w-z) ^ nat (- zorder f z))"
     using zorder_exist_pole[OF f_holo,simplified,OF \<open>is_pole f z\<close>] by auto
-  then have *: "\<forall>w\<in>ball z r - {z}. zor_poly f z w = f w * (w - z) ^ nat (- zorder f z)"
+  then have *: "\<forall>w\<in>ball z r - {z}. zor_poly f z w = f w * (w-z) ^ nat (- zorder f z)"
     by (auto simp: field_simps)
   have "eventually (\<lambda>w. w \<in> ball z r - {z}) (at z)"
     using r eventually_at_ball'[of r z UNIV] by auto
@@ -1892,7 +1886,7 @@
     by eventually_elim (insert r, auto simp: field_simps power_int_minus)
   moreover have "continuous_on (ball z0 r) (zor_poly f z0)"
     using r by (intro holomorphic_on_imp_continuous_on) auto
-  with r(1,2) have "isCont (zor_poly f z0) z0"
+  with r have "isCont (zor_poly f z0) z0"
     by (auto simp: continuous_on_eq_continuous_at)
   hence "(zor_poly f z0 \<longlongrightarrow> zor_poly f z0 z0) (at z0)"
     unfolding isCont_def .
@@ -1935,7 +1929,7 @@
 lemma zor_poly_pole_eqI:
   fixes f :: "complex \<Rightarrow> complex" and z0 :: complex
   defines "n \<equiv> zorder f z0"
-  assumes f_iso:"isolated_singularity_at f z0" and "is_pole f z0"
+  assumes f_iso: "isolated_singularity_at f z0" and "is_pole f z0"
   assumes lim: "((\<lambda>x. f (g x) * (g x - z0) ^ nat (-n)) \<longlongrightarrow> c) F"
   assumes g: "filterlim g (at z0) F" and "F \<noteq> bot"
   shows   "zor_poly f z0 z0 = c"
@@ -1943,9 +1937,12 @@
   obtain r where r: "r > 0"  "zor_poly f z0 holomorphic_on cball z0 r"
   proof -
     have "\<exists>\<^sub>F w in at z0. f w \<noteq> 0"
-      using non_zero_neighbour_pole[OF \<open>is_pole f z0\<close>] by (auto elim:eventually_frequentlyE)
-    moreover have "not_essential f z0" unfolding not_essential_def using \<open>is_pole f z0\<close> by simp
-    ultimately show ?thesis using that zorder_exist[OF f_iso,folded n_def] by auto
+      using non_zero_neighbour_pole[OF \<open>is_pole f z0\<close>] 
+      by (auto elim: eventually_frequentlyE)
+    moreover have "not_essential f z0" 
+      unfolding not_essential_def using \<open>is_pole f z0\<close> by simp
+    ultimately show ?thesis 
+      using that zorder_exist[OF f_iso,folded n_def] by auto
   qed
   from r(1) have "eventually (\<lambda>w. w \<in> ball z0 r \<and> w \<noteq> z0) (at z0)"
     using eventually_at_ball'[of r z0 UNIV] by auto
@@ -1979,15 +1976,15 @@
   ultimately have "isolated_singularity_at f x"
     by (auto simp: isolated_singularity_at_def analytic_on_open
              intro!: exI[of _ r] holomorphic_on_subset[OF holo])
-  hence ev: "\<forall>\<^sub>F w in at x. zor_poly f x w = f w * (w - x) ^ nat (- zorder f x)"
+  hence ev: "\<forall>\<^sub>F w in at x. zor_poly f x w = f w * (w-x) ^ nat (- zorder f x)"
     using \<open>is_pole f x\<close> zor_poly_pole_eq by blast
 
   define P where "P = zor_poly f x"
   define n where "n = nat (-zorder f x)"
 
   obtain r where r: "r > 0" "cball x r \<subseteq> A" "P holomorphic_on cball x r" "zorder f x < 0" "P x \<noteq> 0"
-    "\<forall>w\<in>cball x r - {x}. f w = P w / (w - x) ^ n \<and> P w \<noteq> 0"
-    unfolding P_def n_def using zorder_exist_pole[OF holo assms(2,3,1)] by blast
+    "\<forall>w\<in>cball x r - {x}. f w = P w / (w-x) ^ n \<and> P w \<noteq> 0"
+    using P_def assms holo n_def zorder_exist_pole by blast
   have n: "n > 0"
     using r(4) by (auto simp: n_def)
 
@@ -1995,7 +1992,7 @@
     if "w \<in> ball x r" for w
     using that by (intro holomorphic_derivI[OF holomorphic_on_subset[OF r(3), of "ball x r"]]) auto
 
-  define D where "D = (\<lambda>w. (deriv P w * (w - x) - of_nat n * P w) / (w - x) ^ (n + 1))"
+  define D where "D = (\<lambda>w. (deriv P w * (w-x) - of_nat n * P w) / (w-x) ^ (n + 1))"
   define n' where "n' = n - 1"
   have n': "n = Suc n'"
     using n by (simp add: n'_def)
@@ -2010,12 +2007,10 @@
     have ev': "eventually (\<lambda>w. w \<in> ball x r - {x}) (nhds w)"
       using w by (intro eventually_nhds_in_open) auto
 
-    have "((\<lambda>w. P w / (w - x) ^ n) has_field_derivative D w) (at w)"
-      apply (rule derivative_eq_intros refl | use w in force)+
-      using w
-      apply (simp add: divide_simps D_def)
-      apply (simp add: n' algebra_simps)
-      done
+    have \<section>: "(deriv P w * (w-x) ^ n - P w * (n * (w-x) ^ (n-1))) / ((w-x) ^ n * (w-x) ^ n) = D w"
+      using w n' by (simp add: divide_simps D_def) (simp add: algebra_simps)
+    have "((\<lambda>w. P w / (w-x) ^ n) has_field_derivative D w) (at w)"
+      by (rule derivative_eq_intros refl | use w \<section> in force)+
     also have "?this \<longleftrightarrow> (f has_field_derivative D w) (at w)"
       using r by (intro has_field_derivative_cong_ev refl eventually_mono[OF ev']) auto
     finally have "(f has_field_derivative D w) (at w)" .
@@ -2036,7 +2031,7 @@
   proof (rule zorder_eqI)
     show "open (ball x r)" "x \<in> ball x r"
       using \<open>r > 0\<close> by auto
-    show "f' w = (deriv P w * (w - x) - of_nat n * P w) * (w - x) powi (- int (Suc n))"
+    show "f' w = (deriv P w * (w-x) - of_nat n * P w) * (w-x) powi (- int (Suc n))"
       if "w \<in> ball x r" "w \<noteq> x" for w
       using that D_eq[of w] n by (auto simp: D_def power_int_diff power_int_minus powr_nat' divide_simps)
   qed (use r n in \<open>auto intro!: holomorphic_intros\<close>)
@@ -2081,7 +2076,8 @@
   qed
 
   have "g holomorphic_on A"
-    unfolding g_def using assms assms(1) holo by (intro removable_singularity) auto
+    unfolding g_def using assms assms(1) holo 
+    by (intro removable_singularity) auto
   hence "deriv g holomorphic_on A"
     by (intro holomorphic_deriv assms)
   hence "continuous_on A (deriv g)"
@@ -2124,15 +2120,12 @@
   thus ?thesis
   proof cases
     case 1
-    hence "is_pole f' x"
-      using is_pole_deriv' assms by blast
-    thus ?thesis by (auto simp: not_essential_def)
+    thus ?thesis
+      using assms is_pole_deriv' by blast
   next
     case (2 c)
-    from 2 have "\<exists>c. f' \<midarrow>x\<rightarrow> c"
-      by (rule removable_singularity_deriv'[OF _ assms(2-4)])
     thus ?thesis
-      by (auto simp: not_essential_def)
+      by (meson assms removable_singularity_deriv' tendsto_imp_not_essential)
   qed
 qed
 
@@ -2178,7 +2171,7 @@
   next
     case 2
     have "filterlim (\<lambda>x. f (g x)) at_infinity sequentially"
-      by (rule filterlim_compose[OF _ g(1)]) (use 2 in \<open>auto simp: is_pole_def\<close>)
+      using "2" filterlim_compose g(1) is_pole_def by blast
     with fg have False
       by (meson not_tendsto_and_filterlim_at_infinity sequentially_bot)
     thus ?thesis ..
@@ -2241,13 +2234,14 @@
   hence **: "f \<midarrow>x\<rightarrow> c"
     by (simp add: tendsto_eventually)
   show False
-    using not_tendsto_and_filterlim_at_infinity[OF _ ** assms(1)[unfolded is_pole_def]] by simp
+    using ** \<open>is_pole f x\<close> at_neq_bot is_pole_def 
+          not_tendsto_and_filterlim_at_infinity by blast
 qed
 
 
 lemma neg_zorder_imp_is_pole:
-  assumes iso:"isolated_singularity_at f z" and f_ness:"not_essential f z"
-      and "zorder f z < 0" and fre_nz:"\<exists>\<^sub>F w in at z. f w \<noteq> 0 "
+  assumes iso: "isolated_singularity_at f z" and f_ness: "not_essential f z"
+      and "zorder f z < 0" and fre_nz: "\<exists>\<^sub>F w in at z. f w \<noteq> 0 "
     shows "is_pole f z"
 proof -
   define P where "P = zor_poly f z"
@@ -2255,24 +2249,23 @@
   have "n<0" unfolding n_def by (simp add: assms(3))
   define nn where "nn = nat (-n)"
 
-  obtain r where "P z \<noteq> 0" "r>0" and r_holo:"P holomorphic_on cball z r" and
-       w_Pn:"(\<forall>w\<in>cball z r - {z}. f w = P w * (w - z) powi n \<and> P w \<noteq> 0)"
+  obtain r where r: "P z \<noteq> 0" "r>0" and r_holo: "P holomorphic_on cball z r" and
+       w_Pn: "(\<forall>w\<in>cball z r - {z}. f w = P w * (w-z) powi n \<and> P w \<noteq> 0)"
     using zorder_exist[OF iso f_ness fre_nz,folded P_def n_def] by auto
 
-  have "is_pole (\<lambda>w. P w * (w - z) powi n) z"
+  have "is_pole (\<lambda>w. P w * (w-z) powi n) z"
     unfolding is_pole_def
   proof (rule tendsto_mult_filterlim_at_infinity)
     show "P \<midarrow>z\<rightarrow> P z"
-      by (meson open_ball \<open>0 < r\<close> ball_subset_cball centre_in_ball
-          continuous_on_eq_continuous_at continuous_on_subset
-          holomorphic_on_imp_continuous_on isContD r_holo)
+      by (metis \<open>r>0\<close> r_holo centre_in_ball continuous_on_interior 
+                holomorphic_on_imp_continuous_on interior_cball isContD)
     show "P z\<noteq>0" by (simp add: \<open>P z \<noteq> 0\<close>)
 
     have "LIM x at z. inverse ((x - z) ^ nat (-n)) :> at_infinity"
       apply (subst filterlim_inverse_at_iff[symmetric])
       using \<open>n<0\<close>
       by (auto intro!:tendsto_eq_intros filterlim_atI
-              simp add:eventually_at_filter)
+              simp add: eventually_at_filter)
     then show "LIM x at z. (x - z) powi n :> at_infinity"
     proof (elim filterlim_mono_eventually)
       have "inverse ((x - z) ^ nat (-n)) = (x - z) powi n"
@@ -2283,18 +2276,18 @@
         by (simp add: eventually_at_filter)
     qed auto
   qed
-  moreover have "\<forall>\<^sub>F w in at z. f w =  P w * (w - z) powi n"
+  moreover have "\<forall>\<^sub>F w in at z. f w =  P w * (w-z) powi n"
     unfolding eventually_at_le
     using w_Pn \<open>r>0\<close> by (force simp add: dist_commute)
   ultimately show ?thesis using is_pole_cong by fast
 qed
 
 lemma is_pole_divide_zorder:
-  fixes f g::"complex \<Rightarrow> complex" and z::complex
-  assumes f_iso:"isolated_singularity_at f z" and g_iso:"isolated_singularity_at g z"
-      and f_ness:"not_essential f z" and g_ness:"not_essential g z"
+  fixes f g:: "complex \<Rightarrow> complex" and z::complex
+  assumes f_iso: "isolated_singularity_at f z" and g_iso: "isolated_singularity_at g z"
+      and f_ness: "not_essential f z" and g_ness: "not_essential g z"
       and fg_nconst: "\<exists>\<^sub>Fw in (at z). f w * g w\<noteq> 0"
-      and z_less:"zorder f z < zorder g z"
+      and z_less: "zorder f z < zorder g z"
     shows "is_pole (\<lambda>z. f z / g z) z"
 proof -
   define fn gn fg where "fn=zorder f z" and "gn=zorder g z"
@@ -2302,15 +2295,15 @@
 
   have "isolated_singularity_at fg z"
     unfolding fg_def using f_iso g_iso g_ness
-    by (auto intro:singularity_intros)
+    by (auto intro: singularity_intros)
   moreover have "not_essential fg z"
     unfolding fg_def using f_iso g_iso g_ness f_ness
-    by (auto intro:singularity_intros)
+    by (auto intro: singularity_intros)
   moreover have "zorder fg z < 0"
   proof -
     have "zorder fg z = fn - gn"
-      using zorder_divide[OF f_iso g_iso f_ness g_ness
-            fg_nconst,folded fn_def gn_def fg_def] .
+      using zorder_divide[OF f_iso g_iso f_ness g_ness fg_nconst]
+      by (simp add: fg_def fn_def gn_def) 
     then show ?thesis
       using z_less by (simp add: fn_def gn_def)
   qed
@@ -2321,7 +2314,7 @@
 qed
 
 lemma isolated_pole_imp_nzero_times:
-  assumes f_iso:"isolated_singularity_at f z"
+  assumes f_iso: "isolated_singularity_at f z"
     and "is_pole f z"
   shows "\<exists>\<^sub>Fw in (at z). deriv f w * f w \<noteq> 0"
 proof (rule ccontr)
@@ -2350,30 +2343,30 @@
   by (meson analytic_deriv assms isolated_singularity_at_def)
 
 lemma zorder_deriv_minus_1:
-  fixes f g::"complex \<Rightarrow> complex" and z::complex
-  assumes f_iso:"isolated_singularity_at f z"
-      and f_ness:"not_essential f z"
-      and f_nconst:"\<exists>\<^sub>F w in at z. f w \<noteq> 0"
-      and f_ord:"zorder f z \<noteq>0"
+  fixes f g:: "complex \<Rightarrow> complex" and z::complex
+  assumes f_iso: "isolated_singularity_at f z"
+      and f_ness: "not_essential f z"
+      and f_nconst: "\<exists>\<^sub>F w in at z. f w \<noteq> 0"
+      and f_ord: "zorder f z \<noteq>0"
     shows "zorder (deriv f) z = zorder f z - 1"
 proof -
   define P where "P = zor_poly f z"
   define n where "n = zorder f z"
   have "n\<noteq>0" unfolding n_def using f_ord by auto
 
-  obtain r where "P z \<noteq> 0" "r>0" and P_holo:"P holomorphic_on cball z r"
+  obtain r where "P z \<noteq> 0" "r>0" and P_holo: "P holomorphic_on cball z r"
           and "(\<forall>w\<in>cball z r - {z}. f w
-                            = P w * (w - z) powi n \<and> P w \<noteq> 0)"
+                            = P w * (w-z) powi n \<and> P w \<noteq> 0)"
     using zorder_exist[OF f_iso f_ness f_nconst,folded P_def n_def] by auto
   from this(4)
-  have f_eq:"(\<forall>w\<in>cball z r - {z}. f w
-                            = P w * (w - z) powi n \<and> P w \<noteq> 0)"
+  have f_eq: "(\<forall>w\<in>cball z r - {z}. f w
+                            = P w * (w-z) powi n \<and> P w \<noteq> 0)"
     using complex_powr_of_int f_ord n_def by presburger
 
-  define D where "D = (\<lambda>w. (deriv P w * (w - z) + of_int n * P w)
-                          * (w - z) powi (n - 1))"
+  define D where "D = (\<lambda>w. (deriv P w * (w-z) + of_int n * P w)
+                          * (w-z) powi (n - 1))"
 
-  have deriv_f_eq:"deriv f w = D w" if "w \<in> ball z r - {z}" for w
+  have deriv_f_eq: "deriv f w = D w" if "w \<in> ball z r - {z}" for w
   proof -
     have ev': "eventually (\<lambda>w. w \<in> ball z r - {z}) (nhds w)"
       using that by (intro eventually_nhds_in_open) auto
@@ -2384,11 +2377,10 @@
     moreover have "(P has_field_derivative deriv P w) (at w)"
       by (meson DiffD1 Elementary_Metric_Spaces.open_ball P_holo
           ball_subset_cball holomorphic_derivI holomorphic_on_subset that)
-    ultimately have "((\<lambda>w. P w * (w - z) powi n) has_field_derivative D w) (at w)"
+    ultimately have "((\<lambda>w. P w * (w-z) powi n) has_field_derivative D w) (at w)"
       unfolding D_def using that
       apply (auto intro!: derivative_eq_intros)
-      apply (fold wz_def)
-      by (auto simp:algebra_simps simp flip:power_int_add_1')
+      by (auto simp: algebra_simps simp flip:power_int_add_1' wz_def)
     also have "?this \<longleftrightarrow> (f has_field_derivative D w) (at w)"
       using f_eq
       by (intro has_field_derivative_cong_ev refl eventually_mono[OF ev']) auto
@@ -2402,14 +2394,13 @@
   proof (rule zorder_eqI)
     show "open (ball z r)" "z \<in> ball z r"
       using \<open>r > 0\<close> by auto
-    define g where "g=(\<lambda>w. (deriv P w * (w - z) + of_int n * P w))"
+    define g where "g=(\<lambda>w. (deriv P w * (w-z) + of_int n * P w))"
     show "g holomorphic_on ball z r"
       unfolding g_def using P_holo
       by (auto intro!:holomorphic_intros)
     show "g z \<noteq> 0"
       unfolding g_def using \<open>P z \<noteq> 0\<close> \<open>n\<noteq>0\<close> by auto
-    show "deriv f w =
-         (deriv P w * (w - z) + of_int n * P w) * (w - z) powi (n - 1)"
+    show "deriv f w = (deriv P w * (w-z) + of_int n * P w) * (w-z) powi (n - 1)"
       if "w \<in> ball z r" "w \<noteq> z" for w
       using D_def deriv_f_eq that by blast
   qed
@@ -2417,20 +2408,19 @@
 
 
 lemma deriv_divide_is_pole: \<comment>\<open>Generalises @{thm zorder_deriv}\<close>
-  fixes f g::"complex \<Rightarrow> complex" and z::complex
-  assumes f_iso:"isolated_singularity_at f z"
-      and f_ness:"not_essential f z" 
+  fixes f g:: "complex \<Rightarrow> complex" and z::complex
+  assumes f_iso: "isolated_singularity_at f z"
+      and f_ness: "not_essential f z" 
       and fg_nconst: "\<exists>\<^sub>Fw in (at z). deriv f w *  f w \<noteq> 0"
-      and f_ord:"zorder f z \<noteq>0"
+      and f_ord: "zorder f z \<noteq>0"
     shows "is_pole (\<lambda>z. deriv f z / f z) z"
 proof (rule neg_zorder_imp_is_pole)
   define ff where "ff=(\<lambda>w. deriv f w / f w)"
   show "isolated_singularity_at ff z" 
     using f_iso f_ness unfolding ff_def
-    by (auto intro:singularity_intros)
+    by (auto intro: singularity_intros)
   show "not_essential ff z" 
-    unfolding ff_def using f_ness f_iso
-    by (auto intro:singularity_intros)
+    unfolding ff_def using f_ness f_iso by (auto intro: singularity_intros)
 
   have "zorder ff z =  zorder (deriv f) z - zorder f z"
     unfolding ff_def using f_iso f_ness fg_nconst
@@ -2444,8 +2434,8 @@
 qed
 
 lemma is_pole_deriv_divide_is_pole:
-  fixes f g::"complex \<Rightarrow> complex" and z::complex
-  assumes f_iso:"isolated_singularity_at f z"
+  fixes f g:: "complex \<Rightarrow> complex" and z::complex
+  assumes f_iso: "isolated_singularity_at f z"
       and "is_pole f z" 
     shows "is_pole (\<lambda>z. deriv f z / f z) z"
 proof (rule deriv_divide_is_pole[OF f_iso])
--- a/src/HOL/Complex_Analysis/Contour_Integration.thy	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/HOL/Complex_Analysis/Contour_Integration.thy	Fri Jan 24 10:22:17 2025 +0100
@@ -105,7 +105,6 @@
     from that have "x \<in> interior {0..1}" by auto
     with S[of x] that show ?thesis by (auto simp: at_within_interior[of _ "{0..1}"])
   qed
-
   have "(f has_contour_integral I) (-g) \<longleftrightarrow>
           ((\<lambda>x. f (- g x) * vector_derivative (-g) (at x)) has_integral I) {0..1}"
     by (simp add: has_contour_integral)
@@ -577,13 +576,8 @@
           "u<v" "v<w"
     shows "contour_integral (subpath u v g) f + contour_integral (subpath v w g) f =
            contour_integral (subpath u w g) f"
-proof -
-  have "(\<lambda>x. f (g x) * vector_derivative g (at x)) integrable_on {u..w}"
-    using integrable_on_subcbox [where a=u and b=w and S = "{0..1}"] assms
-    by (auto simp: contour_integrable_on)
-  with assms show ?thesis
-    by (auto simp: contour_integral_subcontour_integral Henstock_Kurzweil_Integration.integral_combine)
-qed
+  by (smt (verit) Henstock_Kurzweil_Integration.integral_combine assms
+      has_integral_contour_integral_subpath has_integral_iff)
 
 lemma contour_integral_subpath_combine:
   assumes "f contour_integrable_on g" "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}" "w \<in> {0..1}"
@@ -614,7 +608,8 @@
 next
   case False
   with assms show ?thesis
-    by (metis add.right_neutral contour_integral_reversepath contour_integral_subpath_refl diff_0 eq_diff_eq add_0 reversepath_subpath valid_path_subpath)
+    by (metis add.right_neutral contour_integral_reversepath contour_integral_subpath_refl
+        diff_0 eq_diff_eq add_0 reversepath_subpath valid_path_subpath)
 qed
 
 lemma contour_integral_integral:
@@ -652,9 +647,8 @@
   shows   "(f has_contour_integral I) (linepath a b) \<longleftrightarrow>
            ((\<lambda>x. f (of_real x)) has_integral I) {Re a..Re b}"
 proof -
-  from assms have [simp]: "of_real (Re a) = a" "of_real (Re b) = b"
-    by (simp_all add: complex_eq_iff)
-  from assms have "a \<noteq> b" by auto
+  have [simp]: "of_real (Re a) = a" "of_real (Re b) = b" and "a \<noteq> b"
+    using assms by (simp_all add: complex_eq_iff)
   have "((\<lambda>x. f (of_real x)) has_integral I) (cbox (Re a) (Re b)) \<longleftrightarrow>
           ((\<lambda>x. f (a + b * of_real x - a * of_real x)) has_integral I /\<^sub>R (Re b - Re a)) {0..1}"
     by (subst has_integral_affinity_iff [of "Re b - Re a" _ "Re a", symmetric])
@@ -665,8 +659,9 @@
   also have "(\<dots> has_integral I /\<^sub>R (Re b - Re a)) {0..1} \<longleftrightarrow>
                ((\<lambda>x. f (linepath a b x) * (b - a)) has_integral I) {0..1}" using assms
     by (subst has_integral_cmul_iff) (auto simp: linepath_def scaleR_conv_of_real algebra_simps)
-  also have "\<dots> \<longleftrightarrow> (f has_contour_integral I) (linepath a b)" unfolding has_contour_integral_def
-    by (intro has_integral_cong) (simp add: vector_derivative_linepath_within)
+  also have "\<dots> \<longleftrightarrow> (f has_contour_integral I) (linepath a b)" 
+    unfolding has_contour_integral_def
+    using has_contour_integral_def has_contour_integral_linepath by presburger
   finally show ?thesis by simp
 qed
 
@@ -684,12 +679,14 @@
   shows   "contour_integral (linepath a b) f = integral {Re a..Re b} (\<lambda>x. f (of_real x))"
 proof (cases "f contour_integrable_on linepath a b")
   case True
-  thus ?thesis using has_contour_integral_linepath_Reals_iff[OF assms, of f]
-    using has_contour_integral_integral has_contour_integral_unique by blast
+  thus ?thesis
+    by (metis assms has_contour_integral_integral
+        has_contour_integral_linepath_Reals_iff integral_unique)
 next
   case False
-  thus ?thesis using contour_integrable_linepath_Reals_iff[OF assms, of f]
-    by (simp add: not_integrable_contour_integral not_integrable_integral)
+  thus ?thesis
+    by (simp add: assms contour_integrable_linepath_Reals_iff
+        not_integrable_contour_integral not_integrable_integral)
 qed
 
 subsection \<open>Cauchy's theorem where there's a primitive\<close>
@@ -705,8 +702,7 @@
   obtain K where "finite K" and K: "\<forall>x\<in>{a..b} - K. g differentiable (at x within {a..b})" and cg: "continuous_on {a..b} g"
     using assms by (auto simp: piecewise_differentiable_on_def)
   have "continuous_on (g ` {a..b}) f"
-    using assms
-    by (metis field_differentiable_def field_differentiable_imp_continuous_at continuous_on_eq_continuous_within continuous_on_subset image_subset_iff)
+    using assms by (metis DERIV_continuous_on continuous_on_subset image_subsetI)
   then have cfg: "continuous_on {a..b} (\<lambda>x. f (g x))"
     by (rule continuous_on_compose [OF cg, unfolded o_def])
   { fix x::real
@@ -753,10 +749,9 @@
     by (rule continuous_intros | simp add: assms)+
   then have "continuous_on {0..1} (\<lambda>x. f (linepath a b x) * (b - a))"
     by (metis (no_types, lifting) continuous_on_compose continuous_on_cong continuous_on_linepath linepath_image_01 o_apply)
-  then have "(\<lambda>x. f (linepath a b x) *
-         vector_derivative (linepath a b)
-          (at x within {0..1})) integrable_on
-    {0..1}"
+  then have "(\<lambda>x. f (linepath a b x)
+             * vector_derivative (linepath a b) (at x within {0..1})) 
+             integrable_on {0..1}"
     by (metis (no_types, lifting) continuous_on_cong integrable_continuous_real vector_derivative_linepath_within)
   then show ?thesis
     by (simp add: contour_integrable_on_def has_contour_integral_def integrable_on_def [symmetric])
@@ -984,7 +979,7 @@
     using assms by auto
 next
   case False
-  then have k: "0 < k" "k < 1" "complex_of_real k \<noteq> 1"
+  then have k: "0 < k" "k < 1"
     using assms by auto
   have c': "c = k *\<^sub>R (b - a) + a"
     by (metis diff_add_cancel c)
@@ -1002,8 +997,8 @@
   } note fi = this
   { assume *: "((\<lambda>x. f ((1 - x) *\<^sub>R c + x *\<^sub>R b) * (b - c)) has_integral j) {0..1}"
     have **: "\<And>x. (((1 - x) / (1 - k)) *\<^sub>R c + ((x - k) / (1 - k)) *\<^sub>R b) = ((1 - x) *\<^sub>R a + x *\<^sub>R b)"
-      using k unfolding c' scaleR_conv_of_real
-      apply (simp add: divide_simps)
+      using k 
+      apply (simp add: c' scaleR_conv_of_real divide_simps)
       apply (simp add: distrib_right distrib_left right_diff_distrib left_diff_distrib)
       done
     have "((\<lambda>x. f ((1 - x) *\<^sub>R a + x *\<^sub>R b) * (b - a)) has_integral j) {k..1}"
@@ -1044,10 +1039,14 @@
   moreover have "closed_segment c b \<subseteq> closed_segment a b"
     by (metis c' ends_in_segment(2) in_segment(1) k subset_closed_segment)
   ultimately
-  have *: "continuous_on (closed_segment a c) f" "continuous_on (closed_segment c b) f"
+  have "continuous_on (closed_segment a c) f" "continuous_on (closed_segment c b) f"
     by (auto intro: continuous_on_subset [OF f])
-  show ?thesis
-    by (rule contour_integral_unique) (meson "*" c contour_integrable_continuous_linepath has_contour_integral_integral has_contour_integral_split k)
+  then have "(f has_contour_integral 
+                contour_integral (linepath a c) f + contour_integral (linepath c b) f) (linepath a b)"
+    by (meson c contour_integrable_continuous_linepath
+        has_contour_integral_integral has_contour_integral_split k)
+  then show ?thesis
+    by (metis contour_integral_unique)
 qed
 
 lemma contour_integral_split_linepath:
@@ -1113,10 +1112,7 @@
     apply (subst integral_swap_continuous [where 'a = real and 'b = real, of 0 0 1 1, simplified])
     subgoal
       by (rule fgh gvcon' hvcon' continuous_intros | simp add: split_def)+
-    subgoal
-      unfolding integral_mult_left [symmetric]
-      by (simp only: mult_ac)
-    done
+    by (simp add: mult.commute mult.left_commute)
   also have "\<dots> = contour_integral h (\<lambda>z. contour_integral g (\<lambda>w. f w z))"
     unfolding contour_integral_integral integral_mult_left [symmetric]
     by (simp add: algebra_simps)
@@ -1252,14 +1248,8 @@
 
 lemma path_image_part_circlepath':
   "path_image (part_circlepath z r s t) = (\<lambda>x. z + r * cis x) ` closed_segment s t"
-proof -
-  have "path_image (part_circlepath z r s t) =
-          (\<lambda>x. z + r * exp(\<i> * of_real x)) ` linepath s t ` {0..1}"
-    by (simp add: image_image path_image_def part_circlepath_def)
-  also have "linepath s t ` {0..1} = closed_segment s t"
-    by (rule linepath_image_01)
-  finally show ?thesis by (simp add: cis_conv_exp)
-qed
+  by (metis (no_types, lifting) ext cis_conv_exp image_image linepath_image_01
+      part_circlepath_def path_image_def)
 
 lemma path_image_part_circlepath_subset:
     "\<lbrakk>s \<le> t; 0 \<le> r\<rbrakk> \<Longrightarrow> path_image(part_circlepath z r s t) \<subseteq> sphere z r"
@@ -1443,10 +1433,11 @@
   case False
   have *: "finite {x. cmod ((2 * real_of_int x * pi) * \<i>) \<le> b + cmod (Ln w)}"
   proof (simp add: norm_mult finite_int_iff_bounded_le)
-    show "\<exists>k. abs ` {x. 2 * \<bar>of_int x\<bar> * pi \<le> b + cmod (Ln w)} \<subseteq> {..k}"
-    apply (rule_tac x="\<lfloor>(b + cmod (Ln w)) / (2*pi)\<rfloor>" in exI)
-    apply (auto simp: field_split_simps le_floor_iff)
-      done
+    have "abs ` {x. 2 * \<bar>real_of_int x\<bar> * pi \<le> b + cmod (Ln w)}
+    \<subseteq> {..\<lfloor>(b + cmod (Ln w)) / (2 * pi)\<rfloor>}"
+      by (auto simp: field_split_simps le_floor_iff)
+    then show "\<exists>k. abs ` {x. 2 * \<bar>of_int x\<bar> * pi \<le> b + cmod (Ln w)} \<subseteq> {..k}"
+      by blast
   qed
   have [simp]: "\<And>P f. {z. P z \<and> (\<exists>n. z = f n)} = f ` {n. P (f n)}"
     by blast
@@ -1482,12 +1473,12 @@
   next
     case 2
     have [simp]: "\<bar>r\<bar> = r" using \<open>r > 0\<close> by linarith
-    have [simp]: "cmod (complex_of_real t - complex_of_real s) = t-s"
+    have [simp]: "cmod (of_real t - of_real s) = t-s"
       by (metis "2" abs_of_pos diff_gt_0_iff_gt norm_of_real of_real_diff)
     have "finite (part_circlepath z r s t -` {y} \<inter> {0..1})" if "y \<in> k" for y
     proof -
       let ?w = "(y - z)/of_real r / exp(\<i> * of_real s)"
-      have fin: "finite (of_real -` {z. cmod z \<le> 1 \<and> exp (\<i> * complex_of_real (t - s) * z) = ?w})"
+      have fin: "finite (of_real -` {z. cmod z \<le> 1 \<and> exp (\<i> * of_real (t - s) * z) = ?w})"
         using \<open>s < t\<close>
         by (intro finite_vimageI [OF finite_bounded_log2]) (auto simp: inj_of_real)
       show ?thesis
@@ -1583,7 +1574,7 @@
   assumes "r \<noteq> 0" "s \<noteq> t" "\<bar>s - t\<bar> < 2*pi"
     shows "arc (part_circlepath z r s t)"
 proof -
-  have *: "x = y" if eq: "\<i> * (linepath s t x) = \<i> * (linepath s t y) + 2 * of_int n * complex_of_real pi * \<i>"
+  have *: "x = y" if eq: "\<i> * (linepath s t x) = \<i> * (linepath s t y) + 2 * of_int n * of_real pi * \<i>"
     and x: "x \<in> {0..1}" and y: "y \<in> {0..1}" for x y n
   proof (rule ccontr)
     assume "x \<noteq> y"
@@ -1735,9 +1726,9 @@
 
 lemma contour_integral_circlepath:
   assumes "r > 0"
-  shows "contour_integral (circlepath z r) (\<lambda>w. 1 / (w - z)) = 2 * complex_of_real pi * \<i>"
+  shows "contour_integral (circlepath z r) (\<lambda>w. 1 / (w - z)) = 2 * of_real pi * \<i>"
 proof (rule contour_integral_unique)
-  show "((\<lambda>w. 1 / (w - z)) has_contour_integral 2 * complex_of_real pi * \<i>) (circlepath z r)"
+  show "((\<lambda>w. 1 / (w - z)) has_contour_integral 2 * of_real pi * \<i>) (circlepath z r)"
     unfolding has_contour_integral_def using assms has_integral_const_real [of _ 0 1]
     apply (subst has_integral_cong)
      apply (simp add: vector_derivative_circlepath01)
--- a/src/HOL/Complex_Analysis/Riemann_Mapping.thy	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/HOL/Complex_Analysis/Riemann_Mapping.thy	Fri Jan 24 10:22:17 2025 +0100
@@ -63,8 +63,10 @@
   qed
   show ?thesis
     unfolding Moebius_function_def
-    apply (intro holomorphic_intros)
-    by (metis "*" mult.commute complex_cnj_cnj complex_cnj_mult complex_cnj_one complex_mod_cnj mem_ball_0 right_minus_eq)
+  proof (intro holomorphic_intros)
+    show "\<And>z. z \<in> ball 0 1 \<Longrightarrow> 1 - cnj w * z \<noteq> 0"
+      by (metis * complex_cnj_cnj complex_cnj_mult complex_mod_cnj mem_ball_0 mult.commute mult_1 right_minus_eq)
+  qed
 qed
 
 lemma Moebius_function_compose:
@@ -80,7 +82,7 @@
     have "w2 * cnj w2 = 1"
       using that meq by (auto simp: algebra_simps)
     then show "z = 0"
-      by (metis (no_types) \<open>cmod w2 < 1\<close> complex_mod_cnj less_irrefl mult.right_neutral norm_mult_less norm_one)
+      using \<open>cmod w2 < 1\<close> complex_mod_sqrt_Re_mult_cnj by force
   qed
   moreover have "z - w2 - w1 * (1 - cnj w2 * z) = z * (1 - cnj w2 * z - cnj w1 * (z - w2))"
     using meq by (fastforce simp: algebra_simps)
@@ -151,10 +153,9 @@
           by force
         have *: "((\<lambda>w. f (r * w)) has_field_derivative deriv f (r * z) * r) (at z)"
           if "z \<in> ball 0 1" for z::complex
-        proof (rule DERIV_chain' [where g=f])
-          show "(f has_field_derivative deriv f (of_real r * z)) (at (of_real r * z))"
-            by (metis holomorphic_derivI [OF holF \<open>open S\<close>] \<open>f \<in> F\<close> image_subset_iff r01 that)
-        qed simp
+          using DERIV_chain' [where g=f] \<open>open S\<close>
+          by (meson DERIV_cmult_Id \<open>f \<in> F\<close> holF holomorphic_derivI image_subset_iff
+              r01 that)
         have df0: "((\<lambda>w. f (r * w)) has_field_derivative deriv f 0 * r) (at 0)"
           using * [of 0] by simp
         have deq: "deriv (\<lambda>x. f (complex_of_real r * x)) 0 = deriv f 0 * complex_of_real r"
@@ -316,12 +317,7 @@
         qed
       qed
       have norm\<psi>1: "norm(\<psi> (h (f z))) < 1" if "z \<in> S" for z
-      proof -
-        have "norm (\<psi> (h (f z)) ^ 2) < 1"
-          by (metis (no_types) that DIM_complex \<psi>2 h01 image_subset_iff mem_ball_0 nf1)
-        then show ?thesis
-          by (metis le_less_trans mult_less_cancel_left2 norm_ge_zero norm_power not_le power2_eq_square)
-      qed
+        by (metis \<psi>2 h01 image_subset_iff mem_ball_0 nf1 norm_power power_less1_D that)
       then have \<psi>01: "\<psi> (h (f 0)) \<in> ball 0 1"
         by (simp add: \<open>0 \<in> S\<close>)
       obtain p q where p0: "p (\<psi> (h (f 0))) = 0"
@@ -535,7 +531,7 @@
             using gxy by (auto simp: path_image_join)
         qed (use gxy holf in auto)
         then have fintxy: "f contour_integrable_on linepath x y"
-          by (metis (no_types, lifting) contour_integrable_joinD1 contour_integrable_joinD2 gxy(2) has_contour_integral_integrable pathfinish_linepath pathstart_reversepath valid_path_imp_reverse valid_path_join valid_path_linepath vp(2))
+          using gxy(2) has_contour_integral_integrable vp by fastforce
         have fintgx: "f contour_integrable_on (?g x)" "f contour_integrable_on (?g y)"
           using openS contour_integrable_holomorphic_simple gxy holf vp by blast+
         show ?thesis
@@ -671,8 +667,8 @@
       unfolding norm_divide
       using \<open>r > 0\<close> g_not_r [OF \<open>z \<in> S\<close>] g_not_r [OF \<open>a \<in> S\<close>]
       by (simp_all add: field_split_simps dist_commute dist_norm)
-  then show "?f ` S \<subseteq> ball 0 1"
-    by auto
+    then show "?f ` S \<subseteq> ball 0 1"
+      by auto
     show "inj_on ?f S"
       using \<open>r > 0\<close> eqg apply (clarsimp simp: inj_on_def)
       by (metis diff_add_cancel)
@@ -697,7 +693,7 @@
     proof (intro exI conjI)
       show "g \<circ> k holomorphic_on h ` S"
         by (smt (verit) holg holk holomorphic_on_compose holomorphic_on_subset imageE image_subset_iff kh)
-      show "\<forall>z\<in>h ` S. f z = ((g \<circ> k) z)\<^sup>2"
+      show "\<forall>z \<in> h ` S. f z = ((g \<circ> k) z)\<^sup>2"
         using eqg kh by auto
     qed
   qed
@@ -714,22 +710,13 @@
 qed
 
 lemma homeomorphic_to_disc:
-  assumes S: "S \<noteq> {}"
-    and prev: "S = UNIV \<or>
+  assumes "S = UNIV \<or>
                (\<exists>f g. f holomorphic_on S \<and> g holomorphic_on ball 0 1 \<and>
-                     (\<forall>z \<in> S. f z \<in> ball 0 1 \<and> g(f z) = z) \<and>
-                     (\<forall>z \<in> ball 0 1. g z \<in> S \<and> f(g z) = z))" (is "_ \<or> ?P")
+                      (\<forall>z \<in> S. f z \<in> ball 0 1 \<and> g(f z) = z) \<and>
+                      (\<forall>z \<in> ball 0 1. g z \<in> S \<and> f(g z) = z))" (is "_ \<or> ?P")
   shows "S homeomorphic ball (0::complex) 1"
-  using prev
-proof
-  assume "S = UNIV" then show ?thesis
-    using homeomorphic_ball01_UNIV homeomorphic_sym by blast
-next
-  assume ?P
-  then show ?thesis
-    unfolding homeomorphic_minimal
-    using holomorphic_on_imp_continuous_on by blast
-qed
+  by (smt (verit, ccfv_SIG) holomorphic_on_imp_continuous_on homeomorphic_ball01_UNIV
+      homeomorphic_minimal assms)
 
 lemma homeomorphic_to_disc_imp_simply_connected:
   assumes "S = {} \<or> S homeomorphic ball (0::complex) 1"
@@ -900,15 +887,11 @@
           using n \<open>cmod x < 1\<close> by (auto simp: field_split_simps algebra_simps D_def)
         moreover have " f ` D n \<inter> closure (f ` A n) = {}"
         proof -
-          have op_fDn: "open(f ` (D n))"
-          proof (rule invariance_of_domain)
-            show "continuous_on (D n) f"
-              by (rule continuous_on_subset [OF contf D01])
-            show "open (D n)"
-              by (simp add: D_def)
-            show "inj_on f (D n)"
-              unfolding inj_on_def using D01 by (metis gf mem_ball_0 subsetCE)
-          qed
+          have"inj_on f (D n)"
+            unfolding inj_on_def using D01 by (metis gf mem_ball_0 subsetCE)
+          then have op_fDn: "open(f ` (D n))"
+            by (metis invariance_of_domain D_def Elementary_Metric_Spaces.open_ball 
+                continuous_on_subset [OF contf D01])
           have injf: "inj_on f (ball 0 1)"
             by (metis mem_ball_0 inj_on_def gf)
           have "D n \<union> A n \<subseteq> ball 0 1"
@@ -992,9 +975,9 @@
               by (metis closedin_diff closedin_self closedin_closed_trans [OF _ clo_INTX] K)
           qed (use \<open>compact L\<close> \<open>C \<subseteq> L\<close> in auto)
         qed
-        obtain U V where "open U" and "compact (closure U)" and "open V" "K \<subseteq> U"
-                     and V: "\<Inter>(range X) - K \<subseteq> V" and "U \<inter> V = {}"
-          using separation_normal_compact [OF \<open>compact K\<close> clo] by blast
+        obtain U V where "open U" "open V" and "compact (closure U)"
+                     and V: "\<Inter>(range X) - K \<subseteq> V" and U: "K \<subseteq> U" "U \<inter> V = {}"
+          by (metis Diff_disjoint separation_normal_compact [OF \<open>compact K\<close> clo])
         then have "U \<inter> (\<Inter> (range X) - K) = {}"
           by blast
         have "(closure U - U) \<inter> (\<Inter>n. X n \<inter> closure U) \<noteq> {}"
@@ -1049,12 +1032,8 @@
         moreover have "(\<Inter>n. X n \<inter> closure U) = (\<Inter>n. X n) \<inter> closure U"
           by blast
         moreover have "x \<in> U" if "\<And>n. x \<in> X n" "x \<in> closure U" for x
-        proof -
-          have "x \<notin> V"
-            using \<open>U \<inter> V = {}\<close> \<open>open V\<close> closure_iff_nhds_not_empty that(2) by blast
-          then show ?thesis
-            by (metis (no_types) Diff_iff INT_I V \<open>K \<subseteq> U\<close> subsetD that(1))
-        qed
+          by (metis Diff_iff INT_I U V \<open>open V\<close> closure_iff_nhds_not_empty
+              order.refl subsetD that)
         ultimately show False
           by (auto simp: open_Int_closure_eq_empty [OF \<open>open V\<close>, of U])
       qed
@@ -1101,7 +1080,7 @@
           moreover have "closed C"
             using C_ccsw clo_ccs by blast
           ultimately show False
-            by (metis C False \<open>S \<noteq> UNIV\<close> C_ccsw bot_eq_sup_iff connected_component_eq_UNIV frontier_Int_closed
+            by (metis C \<open>S \<noteq> {}\<close> \<open>S \<noteq> UNIV\<close> C_ccsw bot_eq_sup_iff connected_component_eq_UNIV frontier_Int_closed
                 frontier_closed frontier_complement frontier_eq_empty frontier_of_components_subset in_components_maximal inf.orderE)
         qed
         then show "connected_component_set (- S) w \<inter> frontier S \<noteq> {}"
@@ -1114,14 +1093,18 @@
             by (auto simp: closed_Compl closed_connected_component frontier_def openS)
           show "frontier (connected_component_set (- S) z) \<subseteq> frontier (- S)"
             using frontier_of_connected_component_subset by fastforce
-          have "\<not> bounded (-S)"
+          have "connected (closure S - S)"
+            by (metis confr frontier_def interior_open openS)
+          moreover have "\<not> bounded (-S)"
             by (simp add: True cobounded_imp_unbounded)
+          moreover have "bounded (connected_component_set (- S) w)"
+            using C_ccsw \<open>bounded C\<close> by auto
+          ultimately have "z \<notin> S"
+            using \<open>w \<notin> S\<close> openS
+            by (metis ComplI Compl_eq_Diff_UNIV connected_UNIV closed_closure closure_subset
+                  connected_component_eq_self connected_diff_open_from_closed subset_UNIV)
           then have "connected_component_set (- S) z \<noteq> {}"
-            unfolding connected_component_eq_empty
-            using confr openS \<open>bounded C\<close> \<open>w \<notin> S\<close>
-            apply (simp add: frontier_def interior_open C_ccsw)
-            by (metis ComplI Compl_eq_Diff_UNIV connected_UNIV closed_closure closure_subset connected_component_eq_self
-                      connected_diff_open_from_closed subset_UNIV)
+            by (metis ComplI connected_component_eq_empty)
           then show "frontier (connected_component_set (- S) z) \<noteq> {}"
             by (metis False \<open>S \<noteq> UNIV\<close> connected_component_eq_UNIV frontier_complement frontier_eq_empty)
         qed
@@ -1285,8 +1268,8 @@
       obtain \<delta> where "0 < \<delta>" "\<And>w. \<lbrakk>w \<in> S; dist w z < \<delta>\<rbrakk> \<Longrightarrow> dist (g w) (g z) < cmod (g z)"
         using contg [unfolded continuous_on_iff] by (metis \<open>g z \<noteq> 0\<close> \<open>z \<in> S\<close> zero_less_norm_iff)
       then have \<delta>: "\<And>w. \<lbrakk>w \<in> S; w \<in> ball z \<delta>\<rbrakk> \<Longrightarrow> g w + g z \<noteq> 0"
-        apply (clarsimp simp: dist_norm)
-        by (metis add_diff_cancel_left' dist_0_norm dist_complex_def less_le_not_le norm_increases_online norm_minus_commute)
+        by (metis add.commute add_cancel_right_left dist_commute dist_complex_def mem_ball
+            norm_increases_online norm_not_less_zero norm_zero order_less_asym)
       have *: "(\<lambda>x. (f x - f z) / (x - z) / (g x + g z)) \<midarrow>z\<rightarrow> deriv f z / (g z + g z)"
       proof (intro tendsto_intros)
         show "(\<lambda>x. (f x - f z) / (x - z)) \<midarrow>z\<rightarrow> deriv f z"
@@ -1303,10 +1286,9 @@
           using \<open>z \<in> S\<close> \<open>0 < \<delta>\<close> by simp
         show "\<And>x. \<lbrakk>x \<in> ball z \<delta> \<inter> S; x \<noteq> z\<rbrakk>
                   \<Longrightarrow> (f x - f z) / (x - z) / (g x + g z) = (g x - g z) / (x - z)"
-          using \<delta>
-          apply (simp add: geq \<open>z \<in> S\<close> divide_simps)
-          apply (auto simp: algebra_simps power2_eq_square)
-          done
+          using \<delta> \<open>z \<in> S\<close>
+          apply (simp add: geq field_split_simps power2_eq_square)
+          by (metis distrib_left mult_cancel_right)
       qed
       then show "\<exists>f'. (g has_field_derivative f') (at z)" ..
     qed
@@ -1401,7 +1383,7 @@
       assume g: "g holomorphic_on ball 0 1" "\<forall>z\<in>ball 0 1. g z \<in> S \<and> f (g z) = z"
         and "\<forall>z\<in>S. cmod (f z) < 1 \<and> g (f z) = z"
       then have "S = g ` (ball 0 1)"
-        by (force simp:)
+        by force
       then have "open S"
         by (metis open_ball g inj_on_def open_mapping_thm3)
     }
@@ -1480,9 +1462,10 @@
         proof -
           have "closed_segment t u \<subseteq> {0..1}"
             using closed_segment_eq_real_ivl t that by auto
+          then have "\<And>r. \<lbrakk>r \<in> closed_segment t u\<rbrakk> \<Longrightarrow> dist (p t) (p r) < cmod (p t - \<zeta>)"
+            by (smt (verit, best) d dist_commute dist_in_closed_segment subsetD \<open>dist u t < d\<close>)
           then have piB: "path_image(subpath t u p) \<subseteq> ?B"
-            apply (clarsimp simp add: path_image_subpath_gen)
-            by (metis subsetD le_less_trans \<open>dist u t < d\<close> d dist_commute dist_in_closed_segment)
+            by (auto simp: path_image_subpath_gen)
           have *: "path (g \<circ> subpath t u p)"
           proof (rule path_continuous_image)
             show "path (subpath t u p)"
@@ -1561,9 +1544,7 @@
     qed
     show "continuous_on UNIV (\<lambda>w. \<zeta> + exp w)"
       by (rule continuous_intros)+
-    show "(\<lambda>w. \<zeta> + exp w) \<in> UNIV \<rightarrow> -{\<zeta>}"
-      by auto
-  qed
+  qed auto
   then have "homotopic_with_canon (\<lambda>r. pathfinish r = pathstart r) {0..1} (-{\<zeta>}) p (\<lambda>x. \<zeta> + 1)"
     by (rule homotopic_with_eq) (auto simp: o_def peq pathfinish_def pathstart_def)
   then have "homotopic_loops (-{\<zeta>}) p (\<lambda>t. \<zeta> + 1)"
--- a/src/HOL/Library/Ramsey.thy	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/HOL/Library/Ramsey.thy	Fri Jan 24 10:22:17 2025 +0100
@@ -27,7 +27,7 @@
 lemma nsets_Pi_contra: "A' \<subseteq> A \<Longrightarrow> Pi ([A]\<^bsup>n\<^esup>) B \<subseteq> Pi ([A']\<^bsup>n\<^esup>) B"
   by (auto simp: nsets_def)
 
-lemma nsets_2_eq: "nsets A 2 = (\<Union>x\<in>A. \<Union>y\<in>A - {x}. {{x, y}})"
+lemma nsets_2_eq: "[A]\<^bsup>2\<^esup> = (\<Union>x\<in>A. \<Union>y\<in>A - {x}. {{x, y}})"
   by (auto simp: nsets_def card_2_iff)
 
 lemma nsets2_E:
@@ -41,7 +41,7 @@
 lemma doubleton_in_nsets_2 [simp]: "{x,y} \<in> [A]\<^bsup>2\<^esup> \<longleftrightarrow> x \<in> A \<and> y \<in> A \<and> x \<noteq> y"
   by (auto simp: nsets_2_eq Set.doubleton_eq_iff)
 
-lemma nsets_3_eq: "nsets A 3 = (\<Union>x\<in>A. \<Union>y\<in>A - {x}. \<Union>z\<in>A - {x,y}. {{x,y,z}})"
+lemma nsets_3_eq: "[A]\<^bsup>3\<^esup> = (\<Union>x\<in>A. \<Union>y\<in>A - {x}. \<Union>z\<in>A - {x,y}. {{x,y,z}})"
   by (simp add: eval_nat_numeral nsets_def card_Suc_eq) blast
 
 lemma nsets_4_eq: "[A]\<^bsup>4\<^esup> = (\<Union>u\<in>A. \<Union>x\<in>A - {u}. \<Union>y\<in>A - {u,x}. \<Union>z\<in>A - {u,x,y}. {{u,x,y,z}})"
@@ -49,9 +49,10 @@
 proof
   show "[A]\<^bsup>4\<^esup> \<subseteq> ?rhs"
     by (clarsimp simp add: nsets_def eval_nat_numeral card_Suc_eq) blast
-  show "?rhs \<subseteq> [A]\<^bsup>4\<^esup>"
-    apply (clarsimp simp add: nsets_def eval_nat_numeral card_Suc_eq)
-    by (metis insert_iff singletonD)
+  have "\<And>X. X \<in> ?rhs \<Longrightarrow> card X = 4"
+    by (force simp: card_2_iff)
+  then show "?rhs \<subseteq> [A]\<^bsup>4\<^esup>"
+    by (auto simp: nsets_def)
 qed
 
 lemma nsets_disjoint_2:
@@ -60,76 +61,75 @@
 
 lemma ordered_nsets_2_eq:
   fixes A :: "'a::linorder set"
-  shows "nsets A 2 = {{x,y} | x y. x \<in> A \<and> y \<in> A \<and> x<y}"
+  shows "[A]\<^bsup>2\<^esup> = {{x,y} | x y. x \<in> A \<and> y \<in> A \<and> x<y}"
      (is "_ = ?rhs")
 proof
-  show "nsets A 2 \<subseteq> ?rhs"
-    unfolding numeral_nat
-    apply (clarsimp simp add: nsets_def card_Suc_eq Set.doubleton_eq_iff not_less)
-    by (metis antisym)
-  show "?rhs \<subseteq> nsets A 2"
+  show "[A]\<^bsup>2\<^esup> \<subseteq> ?rhs"
+    by (auto simp: nsets_def card_2_iff doubleton_eq_iff neq_iff)
+  show "?rhs \<subseteq> [A]\<^bsup>2\<^esup>"
     unfolding numeral_nat by (auto simp: nsets_def card_Suc_eq)
 qed
 
 lemma ordered_nsets_3_eq:
   fixes A :: "'a::linorder set"
-  shows "nsets A 3 = {{x,y,z} | x y z. x \<in> A \<and> y \<in> A \<and> z \<in> A \<and> x<y \<and> y<z}"
+  shows "[A]\<^bsup>3\<^esup> = {{x,y,z} | x y z. x \<in> A \<and> y \<in> A \<and> z \<in> A \<and> x<y \<and> y<z}"
      (is "_ = ?rhs")
 proof
-  show "nsets A 3 \<subseteq> ?rhs"
-    apply (clarsimp simp add: nsets_def card_Suc_eq eval_nat_numeral)
-    by (metis insert_commute linorder_cases)
-  show "?rhs \<subseteq> nsets A 3"
-    apply (clarsimp simp add: nsets_def card_Suc_eq eval_nat_numeral)
-  by (metis empty_iff insert_iff not_less_iff_gr_or_eq)
+  show "[A]\<^bsup>3\<^esup> \<subseteq> ?rhs"
+    unfolding nsets_def card_3_iff
+    by (smt (verit, del_insts) Collect_mono_iff insert_commute insert_subset
+        linorder_less_linear)
+  have "\<And>X. X \<in> ?rhs \<Longrightarrow> card X = 3"
+    by (force simp: card_3_iff)
+  then show "?rhs \<subseteq> [A]\<^bsup>3\<^esup>"
+    by (auto simp: nsets_def)
 qed
 
 lemma ordered_nsets_4_eq:
   fixes A :: "'a::linorder set"
-  shows "[A]\<^bsup>4\<^esup> = {U. \<exists>u x y z. U = {u,x,y,z} \<and> u \<in> A \<and> x \<in> A \<and> y \<in> A \<and> z \<in> A \<and> u < x \<and> x < y \<and> y < z}"
-    (is "_ = Collect ?RHS")
+  defines "rhs \<equiv> \<lambda>U. \<exists>u x y z. U = {u,x,y,z} \<and> u \<in> A \<and> x \<in> A \<and> y \<in> A \<and> z \<in> A \<and> u < x \<and> x < y \<and> y < z"
+  shows "[A]\<^bsup>4\<^esup> = Collect rhs"
 proof -
-  have "?RHS U" if "U \<in> [A]\<^bsup>4\<^esup>" for U
+  have "rhs U" if "U \<in> [A]\<^bsup>4\<^esup>" for U
   proof -
     from that obtain l where "strict_sorted l" "List.set l = U" "length l = 4" "U \<subseteq> A"
       by (simp add: nsets_def) (metis finite_set_strict_sorted)
     then show ?thesis
-      unfolding numeral_nat length_Suc_conv by auto blast
+      unfolding numeral_nat length_Suc_conv rhs_def by auto blast
   qed
   moreover
-  have "Collect ?RHS \<subseteq> [A]\<^bsup>4\<^esup>"
-    apply (clarsimp simp add: nsets_def eval_nat_numeral)
-    apply (subst card_insert_disjoint, auto)+
-    done
+  have "\<And>X. X \<in> Collect rhs \<Longrightarrow> card X = 4 \<and> finite X \<and> X \<subseteq> A"
+    by (auto simp: rhs_def card_insert_if)
   ultimately show ?thesis
-    by auto
+    unfolding nsets_def by blast
 qed
 
 lemma ordered_nsets_5_eq:
   fixes A :: "'a::linorder set"
-  shows "[A]\<^bsup>5\<^esup> = {U. \<exists>u v x y z. U = {u,v,x,y,z} \<and> u \<in> A \<and> v \<in> A \<and> x \<in> A \<and> y \<in> A \<and> z \<in> A \<and> u < v \<and> v < x \<and> x < y \<and> y < z}"
-    (is "_ = Collect ?RHS")
+  defines "rhs \<equiv> \<lambda>U. \<exists>u v x y z. U = {u,v,x,y,z} \<and> u \<in> A \<and> v \<in> A \<and> x \<in> A \<and> y \<in> A \<and> z \<in> A \<and> u < v \<and> v < x \<and> x < y \<and> y < z"
+  shows "[A]\<^bsup>5\<^esup> = Collect rhs"
 proof -
-  have "?RHS U" if "U \<in> [A]\<^bsup>5\<^esup>" for U
+  have "rhs U" if "U \<in> [A]\<^bsup>5\<^esup>" for U
   proof -
     from that obtain l where "strict_sorted l" "List.set l = U" "length l = 5" "U \<subseteq> A"
-      apply (simp add: nsets_def)
-      by (metis finite_set_strict_sorted)
+      by (simp add: nsets_def) (metis finite_set_strict_sorted)
     then show ?thesis
-      unfolding numeral_nat length_Suc_conv by auto blast
+      unfolding numeral_nat length_Suc_conv rhs_def by auto blast
   qed
   moreover
-  have "Collect ?RHS \<subseteq> [A]\<^bsup>5\<^esup>"
-    apply (clarsimp simp add: nsets_def eval_nat_numeral)
-    apply (subst card_insert_disjoint, auto)+
-    done
+  have "\<And>X. X \<in> Collect rhs \<Longrightarrow> card X = 5 \<and> finite X \<and> X \<subseteq> A"
+    by (auto simp: rhs_def card_insert_if)
   ultimately show ?thesis
-    by auto
+    unfolding nsets_def by blast
 qed
 
 lemma binomial_eq_nsets: "n choose k = card (nsets {0..<n} k)"
-  apply (simp add: binomial_def nsets_def)
-  by (meson subset_eq_atLeast0_lessThan_finite)
+proof -
+  have "{K. K \<subseteq> {0..<n} \<and> card K = k} = {N. N \<subseteq> {0..<n} \<and> finite N \<and> card N = k}"
+    using infinite_super by blast
+  then show ?thesis
+    by (simp add: binomial_def nsets_def)
+qed
 
 lemma nsets_eq_empty_iff: "nsets A r = {} \<longleftrightarrow> finite A \<and> card A < r"
   unfolding nsets_def
@@ -157,9 +157,10 @@
   by (auto simp: nsets_def card_gt_0_iff subset_singleton_iff)
 
 lemma nsets_self [simp]: "nsets {..<m} m = {{..<m}}"
-  unfolding nsets_def
-  apply auto
-  by (metis add.left_neutral lessThan_atLeast0 lessThan_iff subset_card_intvl_is_intvl)
+proof
+  show "[{..<m}]\<^bsup>m\<^esup> \<subseteq> {{..<m}}"
+    by (force simp add: card_subset_eq nsets_def)
+qed (simp add: nsets_def)
 
 lemma nsets_zero [simp]: "nsets A 0 = {{}}"
   by (auto simp: nsets_def)
@@ -170,17 +171,16 @@
 lemma inj_on_nsets:
   assumes "inj_on f A"
   shows "inj_on (\<lambda>X. f ` X) ([A]\<^bsup>n\<^esup>)"
-  using assms unfolding nsets_def
-  by (metis (no_types, lifting) inj_on_inverseI inv_into_image_cancel mem_Collect_eq)
+  using assms by (simp add: nsets_def inj_on_def inj_on_image_eq_iff)
 
 lemma bij_betw_nsets:
   assumes "bij_betw f A B"
   shows "bij_betw (\<lambda>X. f ` X) ([A]\<^bsup>n\<^esup>) ([B]\<^bsup>n\<^esup>)"
 proof -
-  have "(`) f ` [A]\<^bsup>n\<^esup> = [f ` A]\<^bsup>n\<^esup>"
-    using assms
-    apply (auto simp: nsets_def bij_betw_def image_iff card_image inj_on_subset)
+  have "\<And>X. \<lbrakk>X \<subseteq> f ` A; finite X\<rbrakk> \<Longrightarrow> \<exists>Y\<subseteq>A. finite Y \<and> card Y = card X \<and> X = f ` Y"
     by (metis card_image inj_on_finite order_refl subset_image_inj)
+  then have "(`) f ` [A]\<^bsup>n\<^esup> = [f ` A]\<^bsup>n\<^esup>"
+    using assms by (auto simp: nsets_def bij_betw_def image_iff card_image inj_on_subset)
   with assms show ?thesis
     by (auto simp: bij_betw_def inj_on_nsets)
 qed
@@ -188,9 +188,14 @@
 lemma nset_image_obtains:
   assumes "X \<in> [f`A]\<^bsup>k\<^esup>" "inj_on f A"
   obtains Y where "Y \<in> [A]\<^bsup>k\<^esup>" "X = f ` Y"
-  using assms
-  apply (clarsimp simp add: nsets_def subset_image_iff)
-  by (metis card_image finite_imageD inj_on_subset)
+proof
+  show "X = f ` (A \<inter> f -` X)"
+    using assms by (auto simp: nsets_def)
+  then show "A Int (f -` X) \<in> [A]\<^bsup>k\<^esup>"
+    using assms
+    unfolding nsets_def mem_Collect_eq
+    by (metis card_image finite_image_iff inf_le1 subset_inj_on)
+qed
 
 lemma nsets_image_funcset:
   assumes "g \<in> S \<rightarrow> T" and "inj_on g S"
@@ -331,8 +336,12 @@
 qed
 
 lemma partn_lst_eq_partn: "partn_lst {..<n} [m,m] 2 = partn {..<n} m 2 {..<2::nat}"
-  apply (simp add: partn_lst_def partn_def numeral_2_eq_2)
-  by (metis less_2_cases numeral_2_eq_2 lessThan_iff nth_Cons_0 nth_Cons_Suc)
+proof -
+  have "\<And>i. i < 2 \<Longrightarrow> [m, m] ! i = m"
+    using less_2_cases_iff by force
+  then show ?thesis
+    by (auto simp: partn_lst_def partn_def numeral_2_eq_2 cong: conj_cong)
+qed
 
 lemma partn_lstE:
   assumes "partn_lst \<beta> \<alpha> \<gamma>" "f \<in> nsets \<beta> \<gamma>  \<rightarrow>  {..<l}" "length \<alpha> = l"
@@ -603,8 +612,7 @@
           using V by simp
         then have "u ` V \<in> nsets {..<p} (q2 - Suc 0)"
           using u_nsets [of _ "q2 - Suc 0"] nsets_mono [OF Vsub] Usub u
-          unfolding bij_betw_def nsets_def
-          by (fastforce elim!: subsetD)
+          unfolding bij_betw_def nsets_def by blast
         then have inq1: "?W \<in> nsets {..p} q2"
           unfolding nsets_def using \<open>q2 > 0\<close> card_insert_if by fastforce
         have invu_nsets: "inv_into {..<p2} u ` X \<in> nsets V r"
@@ -653,9 +661,9 @@
         then have "u ` V \<in> nsets {..p} q1"
           using V u_nsets by auto
         moreover have "f ` nsets (u ` V) (Suc r) \<subseteq> {j}"
-          using hj
+          using hj unfolding h_def image_subset_iff nsets_def
           apply (clarsimp simp add: h_def image_subset_iff nsets_def)
-          by (metis Zero_not_Suc card_eq_0_iff card_image subset_image_inj)
+          by (metis card_image finite_imageD subset_image_inj)
         ultimately show ?thesis
           using jzero not_less_eq by fastforce
       qed
@@ -792,7 +800,7 @@
               using Suc Suc.hyps(2) j by linarith
             have "nsets (u ` V) r \<subseteq> (\<lambda>x. (u ` x)) ` nsets V r"
               apply (clarsimp simp add: nsets_def image_iff)
-              by (metis card_eq_0_iff card_image image_is_empty subset_image_inj)
+              by (metis card_image finite_imageD subset_image_inj)
             then have "f ` nsets (u ` V) r \<subseteq> h ` nsets V r"
               by (auto simp: h_def)
             then show "f ` nsets (u ` V) r \<subseteq> {j}"
@@ -866,9 +874,8 @@
       show "card (v ` U) = m \<and> clique (v ` U) E \<or> card (v ` U) = n \<and> indep (v ` U) E"
         using i unfolding numeral_2_eq_2
           using gi U u
-          apply (simp add: image_subset_iff nsets_2_eq clique_def indep_def less_Suc_eq)
-          apply (auto simp: f_def nsets_def card_image inj_on_subset split: if_split_asm)
-          done
+          unfolding image_subset_iff nsets_2_eq clique_def indep_def less_Suc_eq
+          by (auto simp: f_def nsets_def card_image inj_on_subset split: if_splits)
     qed
   qed
   then show ?thesis
--- a/src/HOL/List.thy	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/HOL/List.thy	Fri Jan 24 10:22:17 2025 +0100
@@ -263,6 +263,15 @@
 replicate_0: "replicate 0 x = []" |
 replicate_Suc: "replicate (Suc n) x = x # replicate n x"
 
+overloading pow_list == "compow :: nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
+begin
+
+primrec pow_list :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list" where
+"pow_list 0 xs = []" |
+"pow_list (Suc n) xs = xs @ pow_list n xs"
+
+end
+
 text \<open>
   Function \<open>size\<close> is overloaded for all datatypes. Users may
   refer to the list version as \<open>length\<close>.\<close>
@@ -1168,7 +1177,7 @@
 by(blast dest:map_injective)
 
 lemma inj_mapI: "inj f \<Longrightarrow> inj (map f)"
-by (iprover dest: map_injective injD intro: inj_onI)
+by (rule list.inj_map)
 
 lemma inj_mapD: "inj (map f) \<Longrightarrow> inj f"
   by (metis (no_types, opaque_lifting) injI list.inject list.simps(9) the_inv_f_f)
@@ -1180,7 +1189,7 @@
   by (blast intro:inj_onI dest:inj_onD map_inj_on)
 
 lemma map_idI: "(\<And>x. x \<in> set xs \<Longrightarrow> f x = x) \<Longrightarrow> map f xs = xs"
-by (induct xs, auto)
+by (rule list.map_ident_strong)
 
 lemma map_fun_upd [simp]: "y \<notin> set xs \<Longrightarrow> map (f(y:=v)) xs = map f xs"
 by (induct xs) auto
@@ -1218,6 +1227,9 @@
 lemma rev_rev_ident [simp]: "rev (rev xs) = xs"
 by (induct xs) auto
 
+lemma rev_involution[simp]: "rev \<circ> rev = id"
+by auto
+
 lemma rev_swap: "(rev xs = ys) = (xs = rev ys)"
 by auto
 
@@ -1284,6 +1296,21 @@
   qed
 qed simp
 
+lemma rev_induct2:
+  "\<lbrakk> P [] [];
+  \<And>x xs. P (xs @ [x]) [];
+  \<And>y ys. P [] (ys @ [y]);
+  \<And>x xs y ys. P xs ys  \<Longrightarrow> P (xs @ [x]) (ys @ [y]) \<rbrakk>
+ \<Longrightarrow> P xs ys"
+proof (induct xs arbitrary: ys rule: rev_induct)
+  case Nil
+  then show ?case using rev_induct[of "P []"] by presburger
+next
+  case (snoc x xs)
+  hence "P xs ys'" for ys' by simp
+  then show ?case by (simp add: rev_induct snoc.prems(2,4))
+qed
+
 lemma length_Suc_conv_rev: "(length xs = Suc n) = (\<exists>y ys. xs = ys @ [y] \<and> length ys = n)"
 by (induct xs rule: rev_induct) auto
 
@@ -4404,6 +4431,10 @@
   "\<lbrakk> inj_on f (set xs); x \<in> set xs \<rbrakk> \<Longrightarrow> count_list (map f xs) (f x) = count_list xs x"
 by (induction xs) (simp, fastforce)
 
+lemma count_list_map_conv:
+assumes "inj f" shows "count_list (map f xs) (f x) = count_list xs x"
+by (induction xs) (simp_all add: inj_eq[OF assms])
+
 lemma count_list_rev[simp]: "count_list (rev xs) x = count_list xs x"
 by (induction xs) auto
 
@@ -4714,6 +4745,9 @@
   "concat (replicate i []) = []"
   by (induct i) (auto simp add: map_replicate_const)
 
+lemma concat_replicate_single[simp]: "concat (replicate m [a]) = replicate m a"
+by(induction m) auto
+
 lemma replicate_empty[simp]: "(replicate n x = []) \<longleftrightarrow> n=0"
 by (induct n) auto
 
@@ -4812,6 +4846,134 @@
 by (subst foldr_fold [symmetric]) simp_all
 
 
+subsubsection \<open>\<^term>\<open>xs ^^ n\<close>\<close>
+
+context
+begin
+
+interpretation monoid_mult "[]" "append"
+  rewrites "power u n = u ^^ n"
+proof-
+  show "class.monoid_mult [] (@)"
+    by (unfold_locales, simp_all)
+  show "power.power [] (@) u n = u ^^ n"
+    by(induction n) (auto simp add: power.power.simps)
+qed
+
+\<comment> \<open>inherited power properties\<close>
+
+lemmas pow_list_zero = power.power_0 and
+  pow_list_one = power_Suc0_right and
+  pow_list_1 = power_one_right and
+  pow_list_Nil = power_one and
+  pow_list_2 = power2_eq_square and
+  pow_list_Suc = power_Suc and
+  pow_list_Suc2 = power_Suc2 and
+  pow_list_comm = power_commutes and
+  pow_list_add = power_add and
+  pow_list_eq_if = power_eq_if and
+  pow_list_mult = power_mult and
+  pow_list_commuting_commutes = power_commuting_commutes
+
+end
+
+lemma pow_list_alt: "xs^^n = concat (replicate n xs)"
+by (induct n) auto
+
+lemma pow_list_single: "[a] ^^ m = replicate m a"
+by(simp add: pow_list_alt)
+
+lemma length_pow_list_single [simp]: "length([a] ^^ n) = n"
+by (simp add: pow_list_single)
+
+lemma nth_pow_list_single: "i < m \<Longrightarrow> ([a] ^^ m) ! i = a"
+by (simp add: pow_list_single)
+
+lemma pow_list_not_NilD: "xs ^^ m \<noteq> [] \<Longrightarrow> 0 < m"
+by (cases m) auto
+
+lemma length_pow_list:  "length(xs ^^ k) = k * length xs"
+by (induction k) simp+
+
+lemma pow_list_set: "set (w ^^ Suc k) = set w"
+by (induction k)(simp_all)
+
+lemma pow_list_slide: "xs @ (ys @ xs) ^^ n  @ ys = (xs @ ys)^^(Suc n)"
+by (induction n) simp+
+
+lemma hd_pow_list: "0 < n \<Longrightarrow> hd(xs ^^ n) = hd xs"
+by(auto simp: pow_list_alt hd_append gr0_conv_Suc)
+
+lemma rev_pow_list: "rev (xs ^^ m) = (rev xs) ^^ m"
+by (induction m)(auto simp: pow_list_comm)
+
+lemma eq_pow_list_iff_eq_exp[simp]: assumes "xs \<noteq> []" shows "xs ^^ k = xs ^^ m \<longleftrightarrow> k = m"
+proof
+  assume "k = m" thus "xs ^^ k = xs ^^ m" by simp
+next
+  assume "xs ^^ k = xs ^^ m"
+  thus "k = m" using \<open>xs \<noteq> []\<close>[folded length_0_conv]
+    by (metis length_pow_list mult_cancel2)
+qed
+
+lemma pow_list_Nil_iff_0: "xs \<noteq> [] \<Longrightarrow> xs ^^ m = [] \<longleftrightarrow> m = 0"
+by (simp add: pow_list_eq_if)
+
+lemma pow_list_Nil_iff_Nil: "0 < m \<Longrightarrow> xs ^^ m = [] \<longleftrightarrow>  xs = []"
+by (cases xs) (auto simp add: pow_list_Nil pow_list_Nil_iff_0)
+
+lemma pow_eq_eq:
+  assumes "xs ^^ k = ys ^^ k" and "0 < k"
+  shows "(xs::'a list) = ys"
+proof-
+  have "length xs = length ys"
+    using assms(1) length_pow_list by (metis nat_mult_eq_cancel1[OF \<open>0 < k\<close>])
+  thus ?thesis by (metis Suc_pred append_eq_append_conv assms(1,2) pow_list.simps(2))
+qed
+
+lemma map_pow_list[simp]: "map f (xs ^^ k) = (map f xs) ^^ k"
+by (induction k) simp_all
+
+lemma concat_pow_list: "concat (xs ^^ k) = (concat xs) ^^ k"
+by (induction k) simp_all
+
+lemma concat_pow_list_single[simp]: "concat ([a] ^^ k) = a ^^ k"
+by (simp add: pow_list_alt)
+
+lemma pow_list_single_Nil_iff: "[a] ^^ n = [] \<longleftrightarrow> n = 0"
+by (simp add: pow_list_single)
+
+lemma hd_pow_list_single: "k \<noteq> 0 \<Longrightarrow> hd ([a] ^^ k) = a"
+by (cases k) simp+
+
+lemma index_pow_mod: "i < length(xs ^^ k) \<Longrightarrow> (xs ^^ k)!i = xs!(i mod length xs)"
+proof(induction k)
+  have aux:  "length(xs ^^ Suc l) = length(xs ^^ l) + length xs" for l
+    by simp
+  have aux1: "length (xs ^^ l) \<le> i \<Longrightarrow> i < length(xs ^^ l) + length xs \<Longrightarrow>  i mod length xs = i -  length(xs^^l)" for l
+    unfolding length_pow_list[of l xs]
+     using less_diff_conv2[of "l * length xs" i "length xs", unfolded add.commute[of "length xs"  "l * length xs"]]
+       le_add_diff_inverse[of "l*length xs" i]
+    by (simp add: mod_nat_eqI)
+  case (Suc k)
+  show ?case
+    unfolding aux sym[OF pow_list_Suc2[symmetric]] nth_append le_mod_geq
+    using aux1[ OF _ Suc.prems[unfolded aux]]
+      Suc.IH pow_list_Suc2[symmetric] Suc.prems[unfolded aux] leI[of i "length(xs ^^ k)"] by presburger
+qed auto
+
+lemma unique_letter_word: assumes "\<And>c. c \<in> set w \<Longrightarrow> c = a" shows "w = [a] ^^ length w"
+  using assms proof (induction w)
+  case (Cons b w)
+  have "[a] ^^ length w = w" using Cons.IH[OF Cons.prems[OF list.set_intros(2)]]..
+  then show "b # w = [a] ^^ length(b # w)"
+    unfolding Cons.prems[OF list.set_intros(1)] by auto
+qed simp
+
+lemma count_list_pow_list: "count_list (w ^^ k) a = k * (count_list w a)"
+by (induction k) simp+
+
+
 subsubsection \<open>\<^const>\<open>enumerate\<close>\<close>
 
 lemma enumerate_simps [simp, code]:
@@ -6612,8 +6774,7 @@
 lemma Cons_in_lists_iff[simp]: "x#xs \<in> lists A \<longleftrightarrow> x \<in> A \<and> xs \<in> lists A"
 by auto
 
-lemma append_in_listsp_conv [iff]:
-     "(listsp A (xs @ ys)) = (listsp A xs \<and> listsp A ys)"
+lemma append_in_listsp_conv [iff]: "(listsp A (xs @ ys)) = (listsp A xs \<and> listsp A ys)"
 by (induct xs) auto
 
 lemmas append_in_lists_conv [iff] = append_in_listsp_conv [to_set]
@@ -6634,6 +6795,9 @@
 
 lemmas in_listsI [intro!] = in_listspI [to_set]
 
+lemma mono_lists: "mono lists"
+unfolding mono_def by auto
+
 lemma lists_eq_set: "lists A = {xs. set xs \<le> A}"
 by auto
 
@@ -6650,6 +6814,41 @@
   then show ?thesis by auto
 qed
 
+lemma inj_on_map_lists: assumes "inj_on f A"
+  shows "inj_on (map f) (lists A)"
+proof
+  fix xs ys
+  assume "xs \<in> lists A" and "ys \<in> lists A" and "map f xs = map f ys"
+  have "x = y" if "x \<in> set xs" and "y \<in> set ys" and  "f x =  f y"  for x y
+    using in_listsD[OF \<open>xs \<in> lists A\<close>, rule_format, OF \<open>x \<in> set xs\<close>]
+          in_listsD[OF \<open>ys \<in> lists A\<close>, rule_format, OF \<open>y \<in> set ys\<close>]
+         \<open>inj_on f A\<close>[unfolded inj_on_def, rule_format, OF _ _ \<open>f x =  f y\<close>] by blast
+  from list.inj_map_strong[OF this  \<open>map f xs = map f ys\<close>]
+  show "xs = ys".
+qed
+
+lemma bij_lists: "bij_betw f X Y \<Longrightarrow> bij_betw (map f) (lists X) (lists Y)"
+unfolding bij_betw_def using inj_on_map_lists lists_image by metis
+
+lemma replicate_in_lists: "a \<in> A \<Longrightarrow> replicate k a \<in> lists A"
+by (induction k) auto
+
+lemma sing_pow_lists: "a \<in> A \<Longrightarrow> [a] ^^ n \<in> lists A"
+by (induction n) auto
+
+lemma one_generated_list_power: "u \<in> lists {x} \<Longrightarrow> \<exists>k. concat u = x ^^ k"
+proof(induction u rule: lists.induct)
+  case Nil
+  then show ?case by (metis concat.simps(1) pow_list.simps(1))
+next
+  case Cons
+  then show ?case by (metis concat.simps(2) pow_list_Suc singletonD)
+qed
+
+lemma pow_list_in_lists: "0 < k \<Longrightarrow> u ^^ k \<in> lists B \<Longrightarrow> u \<in> lists B"
+by (metis Suc_pred in_lists_conv_set pow_list_set)
+
+
 subsubsection \<open>Inductive definition for membership\<close>
 
 inductive ListMem :: "'a \<Rightarrow> 'a list \<Rightarrow> bool"
--- a/src/HOL/ROOT	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/HOL/ROOT	Fri Jan 24 10:22:17 2025 +0100
@@ -694,6 +694,7 @@
     BigO
     BinEx
     Birthday_Paradox
+    Bit_Operation_Calculations
     Bubblesort
     CTL
     Cartouche_Examples
--- a/src/HOL/Transcendental.thy	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/HOL/Transcendental.thy	Fri Jan 24 10:22:17 2025 +0100
@@ -1985,6 +1985,9 @@
   finally show ?thesis .
 qed
 
+lemma exp_gt_self: "x < exp (x::real)"
+  using exp_gt_zero ln_less_self by fastforce
+
 lemma ln_one_plus_pos_lower_bound:
   fixes x :: real
   assumes a: "0 \<le> x" and b: "x \<le> 1"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/HOL/ex/Bit_Operation_Calculations.thy	Fri Jan 24 10:22:17 2025 +0100
@@ -0,0 +1,145 @@
+(* Author: Florian Haftmann, TU Muenchen *)
+
+section \<open>Tests for simplifying bit operations on ground terms\<close>
+
+theory Bit_Operation_Calculations
+  imports
+    "HOL.Bit_Operations"
+    "HOL-Library.Word"
+begin
+
+unbundle bit_operations_syntax
+
+subsection \<open>Generic unsigned computations\<close>
+
+locale unsigned_computations =
+  fixes type :: \<open>'a::semiring_bit_operations itself\<close>
+begin
+
+definition computations where
+  \<open>computations = (
+    [bit (473514 :: 'a) 5],
+    [473514 AND 767063 :: 'a],
+    [473514 OR 767063 :: 'a],
+    [473514 XOR 767063 :: 'a],
+    mask 11 :: 'a,
+    [set_bit 15 473514 :: 'a],
+    [unset_bit 13 473514 :: 'a],
+    [flip_bit 15 473514 :: 'a],
+    [push_bit 12 473514 :: 'a],
+    [drop_bit 12 65344 :: 'a],
+    [take_bit 12 473514 :: 'a]
+  )\<close>
+
+definition results where
+  \<open>results = (
+    [True],
+    [208898 :: 'a::semiring_bit_operations],
+    [1031679 :: 'a],
+    [822781 :: 'a],
+    2047 :: 'a,
+    [506282 :: 'a],
+    [465322 :: 'a],
+    [506282 :: 'a],
+    [1939513344 :: 'a],
+    [15 :: 'a],
+    [2474 :: 'a]
+  )\<close>
+
+lemmas evaluation_simps = computations_def results_def mask_numeral
+   \<comment> \<open>Expressions like \<term>\<open>mask 42\<close> are deliberately not simplified by default\<close>
+
+end
+
+global_interpretation unsigned_computations_nat: unsigned_computations \<open>TYPE(nat)\<close>
+  defines unsigned_computations_nat = unsigned_computations_nat.computations
+    and unsigned_results_nat = unsigned_computations_nat.results .
+
+lemma \<open>unsigned_computations_nat.computations = unsigned_computations_nat.results\<close>
+  by (simp add: unsigned_computations_nat.evaluation_simps)
+
+global_interpretation unsigned_computations_int: unsigned_computations \<open>TYPE(int)\<close>
+  defines unsigned_computations_int = unsigned_computations_int.computations
+    and unsigned_results_int = unsigned_computations_int.results .
+
+lemma \<open>unsigned_computations_int.computations = unsigned_computations_int.results\<close>
+  by (simp add: unsigned_computations_int.evaluation_simps)
+
+global_interpretation unsigned_computations_word16: unsigned_computations \<open>TYPE(16 word)\<close>
+  defines unsigned_computations_word16 = unsigned_computations_word16.computations
+    and unsigned_results_word16 = unsigned_computations_word16.results .
+
+lemma \<open>unsigned_computations_word16 = unsigned_results_word16\<close>
+  by (simp add: unsigned_computations_word16.evaluation_simps)
+
+
+subsection \<open>Generic unsigned computations\<close>
+
+locale signed_computations =
+  fixes type :: \<open>'a::ring_bit_operations itself\<close>
+begin
+
+definition computations where
+  \<open>computations = (
+    [bit (- 805167 :: 'a) 7],
+    [- 805167 AND 767063, 473514 AND - 314527, - 805167 AND - 314527 :: 'a],
+    [- 805167 OR 767063, 473514 OR - 314527, - 805167 OR - 314527 :: 'a],
+    [- 805167 XOR 767063, 473514 XOR - 314527, - 805167 XOR - 314527 :: 'a],
+    [NOT 473513, NOT (- 805167) :: 'a],
+    [set_bit 11 (- 805167) :: 'a],
+    [unset_bit 12 (- 805167) :: 'a],
+    [flip_bit 12 (- 805167) :: 'a],
+    [push_bit 12 (- 805167) :: 'a],
+    [take_bit 12 (- 805167) :: 'a],
+    [signed_take_bit 12 473514, signed_take_bit 12 (- 805167) :: 'a]
+  )\<close>
+
+definition results where
+  \<open>results = (
+    [True],
+    [242769, 209184, - 839103 :: 'a],
+    [- 280873, - 50197, - 280591 :: 'a],
+    [- 523642, - 259381, 558512 :: 'a],
+    [- 473514, 805166 :: 'a],
+    [- 803119 :: 'a],
+    [- 809263 :: 'a],
+    [- 809263 :: 'a],
+    [- 3297964032 :: 'a],
+    [1745 :: 'a],
+    [- 1622, - 2351 :: 'a]
+  )\<close>
+
+lemmas evaluation_simps = computations_def results_def
+
+end
+
+global_interpretation signed_computations_int: signed_computations \<open>TYPE(int)\<close>
+  defines signed_computations_int = signed_computations_int.computations
+    and signed_results_int = signed_computations_int.results .
+
+lemma \<open>signed_computations_int.computations = signed_computations_int.results\<close>
+  by (simp add: signed_computations_int.evaluation_simps)
+
+global_interpretation signed_computations_word16: signed_computations \<open>TYPE(16 word)\<close>
+  defines signed_computations_word16 = signed_computations_word16.computations
+    and signed_results_word16 = signed_computations_word16.results .
+
+lemma \<open>signed_computations_word16 = signed_results_word16\<close>
+  by (simp add: signed_computations_word16.evaluation_simps)
+
+
+subsection \<open>Special cases on particular type instances\<close>
+
+lemma
+  \<open>drop_bit 12 (- 17405 :: int) = - 5\<close>
+  by simp
+
+lemma
+  \<open>signed_drop_bit 12 (- 17405 :: 16 word) = - 5\<close>
+  by simp
+
+lemma
+  \<open>drop_bit 12 (- 17405 :: 16 word) = 11\<close>
+  by simp
+
+end
--- a/src/Pure/Admin/component_javamail.scala	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/Pure/Admin/component_javamail.scala	Fri Jan 24 10:22:17 2025 +0100
@@ -33,10 +33,10 @@
 
   val jars =
     List(
-      Jar("jakarta.mail", "jakarta.mail-api", "2.1.2"),
-      Jar("jakarta.activation", "jakarta.activation-api", "2.1.2"),
-      Jar("org.eclipse.angus", "angus-mail", "2.0.2"),
-      Jar("org.eclipse.angus", "angus-activation", "2.0.1"))
+      Jar("jakarta.mail", "jakarta.mail-api", "2.1.3"),
+      Jar("jakarta.activation", "jakarta.activation-api", "2.1.3"),
+      Jar("org.eclipse.angus", "angus-mail", "2.0.3"),
+      Jar("org.eclipse.angus", "angus-activation", "2.0.2"))
 
 
   /* build javamail */
--- a/src/Pure/Build/build_ci.scala	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/Pure/Build/build_ci.scala	Fri Jan 24 10:22:17 2025 +0100
@@ -70,16 +70,14 @@
   case object On_Commit extends Trigger
 
   object Timed {
-    def nightly(start_time: Time = Time.zero): Timed =
-      Timed { (before, now) =>
-        val start0 = before.midnight + start_time
-        val start1 = now.midnight + start_time
-        (before.time < start0.time && start0.time <= now.time) ||
-          (before.time < start1.time && start1.time <= now.time)
-      }
+    def nightly(start: Time = Time.hms(0, 17, 0)): Timed = Timed(Date.Daily(start))
+    def weekly(day: Date.Day = Date.Day.sun, start: Time = Time.hms(0, 17, 0)): Timed =
+      Timed(Date.Weekly(day, Date.Daily(start)))
   }
 
-  case class Timed(in_interval: (Date, Date) => Boolean) extends Trigger
+  case class Timed(cycle: Date.Cycle) extends Trigger {
+    def next(previous: Date, now: Date): Boolean = cycle.next(previous).time < cycle.next(now).time
+  }
 
 
   /* build hooks */
--- a/src/Pure/Build/build_manager.scala	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/Pure/Build/build_manager.scala	Fri Jan 24 10:22:17 2025 +0100
@@ -1135,7 +1135,7 @@
     private def add_tasks(previous: Date, next: Date): Unit = synchronized_database("add_tasks") {
       for (ci_job <- ci_jobs)
         ci_job.trigger match {
-          case Build_CI.Timed(in_interval) if in_interval(previous, next) =>
+          case timer: Build_CI.Timed if timer.next(previous, next) =>
             val task = CI_Build.task(ci_job)
             echo("Triggered task " + task.kind)
             _state = _state.add_pending(task)
@@ -1411,7 +1411,7 @@
         def render_diff(data: Report.Data, components: List[Component]): XML.Body =
           par(List(page_link(Page.BUILD, "back to build", Markup.Name(build.name)))) ::
           (for (component <- components if !component.is_local) yield {
-            val infos = 
+            val infos =
               data.component_logs.toMap.get(component.name).toList.flatMap(colored) :::
               data.component_diffs.toMap.get(component.name).toList.flatMap(colored)
 
@@ -1508,7 +1508,7 @@
           Web_App.More_HTML.icon("data:image/x-icon;base64," + logo.encode_base64.text),
           HTML.style_file("https://hawkz.github.io/gdcss/gd.css"),
           HTML.style("""
-:root { 
+:root {
   --color-secondary: var(--color-tertiary);
   --color-secondary-hover: var(--color-tertiary-hover);
 }
@@ -1894,7 +1894,7 @@
     progress.interrupt_handler {
       using(store.open_ssh()) { ssh =>
         val user = ssh.execute("whoami").check.out
-        
+
         val build_config = User_Build(user, afp_rev, prefs, requirements, all_sessions,
           base_sessions, exclude_session_groups, exclude_sessions, session_groups, sessions,
           build_heap, clean_build, export_files, fresh_build, presentation, verbose)
--- a/src/Pure/General/date.scala	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/Pure/General/date.scala	Fri Jan 24 10:22:17 2025 +0100
@@ -10,7 +10,7 @@
 import java.util.Locale
 import java.time.{Instant, ZonedDateTime, LocalTime, ZoneId}
 import java.time.format.{DateTimeFormatter, DateTimeParseException}
-import java.time.temporal.TemporalAccessor
+import java.time.temporal.{ChronoUnit, TemporalAccessor}
 
 import scala.annotation.tailrec
 
@@ -99,9 +99,67 @@
 
   def apply(t: Time, timezone: ZoneId = Date.timezone()): Date =
     instant(t.instant, timezone)
+
+
+  /* varying-length calendar cycles */
+
+  enum Day { case mon, tue, wed, thu, fri, sat, sun }
+  enum Month { case jan, feb, mar, apr, may, jun, jul, aug, sep, okt, nov, dec }
+
+  sealed trait Cycle {
+    def zero(date: Date): Date
+    def next(date: Date): Date
+  }
+
+  case class Daily(at: Time = Time.zero) extends Cycle {
+    require(at >= Time.zero && at < Time.hms(24, 0, 0))
+
+    def zero(date: Date): Date = date.midnight
+    def next(date: Date): Date = {
+      val start = zero(date) + at
+      if (date.time < start.time) start else start.shift(1)
+    }
+
+    override def toString: String = "Daily(" + Format.time(Date(at, timezone_utc)) + ")"
+  }
+
+  case class Weekly(on: Day = Day.mon, step: Daily = Daily()) extends Cycle {
+    def zero(date: Date): Date = date.shift(1 - date.rep.getDayOfWeek.getValue).midnight
+    def next(date: Date): Date = {
+      val next = step.next(zero(date).shift(on.ordinal) - Time.ms(1))
+      if (date.time < next.time) next else Date(next.rep.plus(1, ChronoUnit.WEEKS))
+    }
+  }
+
+  case class Monthly(nth: Int = 1, step: Daily = Daily()) extends Cycle {
+    require(nth > 0 && nth <= 31)
+
+    def zero(date: Date): Date = date.shift(1 - date.rep.getDayOfMonth).midnight
+    def next(date: Date): Date = {
+      @tailrec def find_next(zero: Date): Date = {
+        val next = step.next(zero.shift(nth - 1) - Time.ms(1))
+        if (next.rep.getDayOfMonth == nth && date.time < next.time) next
+        else find_next(Date(zero.rep.plus(1, ChronoUnit.MONTHS)))
+      }
+      find_next(zero(date))
+    }
+  }
+
+  case class Yearly(in: Month = Month.jan, step: Monthly = Monthly()) extends Cycle {
+    def zero(date: Date): Date = date.shift(1 - date.rep.getDayOfYear).midnight
+    def next(date: Date): Date = {
+      @tailrec def find_next(zero: Date): Date = {
+        val next = step.next(Date(zero.rep.plus(in.ordinal, ChronoUnit.MONTHS)) - Time.ms(1))
+        if (next.rep.getMonthValue - 1 == in.ordinal && date.time < next.time) next
+        else find_next(Date(zero.rep.plus(1, ChronoUnit.YEARS)))
+      }
+      find_next(zero(date))
+    }
+  }
 }
 
 sealed case class Date(rep: ZonedDateTime) {
+  def shift(days: Int): Date = Date(rep.plus(days, ChronoUnit.DAYS))
   def midnight: Date =
     new Date(ZonedDateTime.of(rep.toLocalDate, LocalTime.MIDNIGHT, rep.getZone))
 
--- a/src/Tools/Code/code_target.ML	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/Tools/Code/code_target.ML	Fri Jan 24 10:22:17 2025 +0100
@@ -384,16 +384,27 @@
     val serializer = (#serializer o #language) target;
   in { serializer = serializer, data = data, modify = modify } end;
 
-fun project_program_for_syms ctxt syms_hidden syms1 program1 =
+fun report_unimplemented ctxt program requested unimplemented =
   let
-    val syms2 = subtract (op =) syms_hidden syms1;
+    val deps = flat (map_product (fn req => fn unimpl =>
+      Code_Symbol.Graph.irreducible_paths program (req, Constant unimpl)) requested unimplemented)
+    val pretty_dep = space_implode " -> " o map (Code_Symbol.quote ctxt)
+  in
+    error ("No code equations for "
+      ^ commas (map (Proof_Context.markup_const ctxt) unimplemented)
+      ^ ",\nrequested by dependencies\n"
+      ^ space_implode "\n" (map pretty_dep deps))
+  end;
+
+fun project_program_for_syms ctxt syms_hidden requested1 program1 =
+  let
+    val requested2 = subtract (op =) syms_hidden requested1;
     val program2 = Code_Symbol.Graph.restrict (not o member (op =) syms_hidden) program1;
     val unimplemented = Code_Thingol.unimplemented program2;
     val _ =
       if null unimplemented then ()
-      else error ("No code equations for " ^
-        commas (map (Proof_Context.markup_const ctxt) unimplemented));
-    val syms3 = Code_Symbol.Graph.all_succs program2 syms2;
+      else report_unimplemented ctxt program2 requested2 unimplemented;
+    val syms3 = Code_Symbol.Graph.all_succs program2 requested2;
     val program3 = Code_Symbol.Graph.restrict (member (op =) syms3) program2;
   in program3 end;
 
--- a/src/Tools/Find_Facts/etc/settings	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/Tools/Find_Facts/etc/settings	Fri Jan 24 10:22:17 2025 +0100
@@ -1,9 +1,7 @@
 # -*- shell-script -*- :mode=shellscript:
 
 FIND_FACTS_HOME="$COMPONENT"
-FIND_FACTS_WEB="$ISABELLE_HOME_USER/find_facts/web"
-
-SOLR_DATA="$ISABELLE_HOME_USER/find_facts/solr"
-SOLR_COMPONENTS=""
+FIND_FACTS_HOME_USER="$ISABELLE_HOME_USER/find_facts"
+FIND_FACTS_INDEXES=""
 
 ISABELLE_TOOLS="$ISABELLE_TOOLS:$FIND_FACTS_HOME/Tools"
--- a/src/Tools/Find_Facts/src/find_facts.scala	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/Tools/Find_Facts/src/find_facts.scala	Fri Jan 24 10:22:17 2025 +0100
@@ -112,6 +112,8 @@
 
   /** Solr data model **/
 
+  val solr_data_dir: Path = Path.explode("$FIND_FACTS_HOME_USER/solr")
+
   object private_data extends Solr.Data("find_facts") {
     /* types */
 
@@ -577,29 +579,52 @@
       } yield block)
   }
 
+  def find_facts_index_command(
+    sessions: List[String],
+    ssh: SSH.System = SSH.Local,
+    isabelle_home: Path = Path.current,
+    options: List[Options.Spec] = Nil,
+    dirs: List[Path] = Nil,
+    clean: Boolean = false,
+    no_build: Boolean = false,
+    verbose: Boolean = false,
+  ): String = {
+    ssh.bash_path(Isabelle_Tool.exe(isabelle_home)) + " find_facts_index" +
+      dirs.map(dir => " -d " + ssh.bash_path(dir)).mkString +
+      if_proper(clean, " -c") +
+      if_proper(no_build, " -n") +
+      if_proper(verbose, " -v") +
+      Options.Spec.bash_strings(options, bg = true) +
+      sessions.map(session => " " + session).mkString
+  }
+
   def find_facts_index(
     options: Options,
     sessions: List[String],
+    afp_root: Option[Path] = None,
     dirs: List[Path] = Nil,
     clean: Boolean = false,
     progress: Progress = new Progress
   ): Unit = {
     val store = Store(options)
+    val solr = Solr.init(solr_data_dir)
     val database = options.string("find_facts_database_name")
     val session = Session(options, Resources.bootstrap)
 
     val selection = Sessions.Selection(sessions = sessions)
-    val session_structure = Sessions.load_structure(options, dirs = dirs).selection(selection)
+    val session_structure =
+      Sessions.load_structure(options, dirs = AFP.main_dirs(afp_root) ::: dirs).selection(selection)
     val deps = Sessions.Deps.load(session_structure)
     val browser_info_context = Browser_Info.context(session_structure)
 
     if (sessions.isEmpty) progress.echo("Nothing to index")
     else {
+      val start_date = Date.now()
       val stats =
-        using(Solr.init_database(database, Find_Facts.private_data, clean = clean)) { db =>
+        using(solr.init_database(database, Find_Facts.private_data, clean = clean)) { db =>
           using(Export.open_database_context(store)) { database_context =>
             val document_info = Document_Info.read(database_context, deps, sessions)
-            
+
             def index_session(session_name: String): Unit = {
               using(database_context.open_session0(session_name)) { session_context =>
                 val info = session_structure(session_name)
@@ -611,7 +636,7 @@
                   Build.read_theory(theory_context) match {
                     case None => progress.echo_warning("No snapshot for theory " + name.theory)
                     case Some(snapshot) =>
-                      progress.echo("Theory " + name.theory + " ...")
+                      progress.echo("Indexing theory " + quote(name.theory), verbose = true)
                       val blocks =
                         make_thy_blocks(options, session, browser_info_context, document_info,
                           theory_context, snapshot, info.chapter)
@@ -628,8 +653,9 @@
           Find_Facts.query_stats(db, query)
         }
 
-      progress.echo("Indexed " + stats.results + " blocks with " +
-        stats.consts + " consts, " + stats.typs + " typs, " + stats.thms + " thms")
+      val timing = Date.now() - start_date
+      progress.echo("Indexed " + stats.results + " blocks with " + stats.consts + " consts, " +
+        stats.typs + " typs, " + stats.thms + " thms in " + timing.message)
     }
   }
 
@@ -638,6 +664,7 @@
 
   def main_tool1(args: Array[String]): Unit = {
     Command_Line.tool {
+      var afp_root: Option[Path] = None
       var clean = false
       val dirs_buffer = new mutable.ListBuffer[Path]
       var no_build = false
@@ -648,6 +675,7 @@
   Usage: isabelle find_facts_index [OPTIONS] [SESSIONS ...]
 
     Options are:
+      -A ROOT      include AFP with given root directory (":" for """ + AFP.BASE.implode + """)
       -c           clean previous index
       -d DIR       include session directory
       -n           no build -- take existing session build databases
@@ -656,6 +684,7 @@
 
     Build and index sessions for Find_Facts.
   """,
+        "A:" -> (arg => afp_root = Some(if (arg == ":") AFP.BASE else Path.explode(arg))),
         "c" -> (_ => clean = true),
         "d:" -> (arg => dirs_buffer += Path.explode(arg)),
         "n" -> (_ => no_build = true),
@@ -673,7 +702,7 @@
       if (!no_build) {
         def build(test: Boolean = false): Build.Results =
           Build.build(options, selection = Sessions.Selection(sessions = sessions), dirs = dirs,
-            no_build = test, progress = if (test) new Progress else progress)
+            afp_root = afp_root, no_build = test, progress = if (test) new Progress else progress)
 
         progress.interrupt_handler {
           if (!build(test = true).ok) {
@@ -690,56 +719,66 @@
 
       /* index */
 
-      find_facts_index(options, sessions, dirs = dirs, clean = clean, progress = progress)
+      find_facts_index(options, sessions, dirs = dirs, afp_root = afp_root, clean = clean,
+        progress = progress)
     }
   }
 
 
-
   /** index components **/
 
-  def find_facts_index_component(
-    options: Options,
+  def resolve_indexes(solr: Solr.System): Unit =
+    for {
+      path <- Path.split(Isabelle_System.getenv("FIND_FACTS_INDEXES"))
+      database = Library.perhaps_unprefix("find_facts-", path.file_name)
+      database_dir = solr.database_dir(database)
+      if !database_dir.is_dir
+    } Isabelle_System.copy_dir(path, database_dir, direct = true)
+
+  def find_facts_index_build(
+    database: String,
     target_dir: Path = Path.current,
     progress: Progress = new Progress
   ): Unit = {
-    val database = options.string("find_facts_database_name")
+    val solr = Solr.init(solr_data_dir)
 
-    val component = "find_facts_index-" + database
+    val component = "find_facts-" + database
     val component_dir =
       Components.Directory(target_dir + Path.basic(component)).create(progress = progress)
 
-    Isabelle_System.copy_dir(Solr.database_dir(database), component_dir.path)
-    component_dir.write_settings("SOLR_COMPONENTS=\"$SOLR_COMPONENTS:$COMPONENT/" + database + "\"")
+    Isabelle_System.copy_dir(solr.database_dir(database), component_dir.path)
+    component_dir.write_settings(
+      "FIND_FACTS_INDEXES=\"$FIND_FACTS_INDEXES:$COMPONENT/" + database + "\"")
   }
 
 
   /* Isabelle tool wrapper */
 
-  val isabelle_tool2 = Isabelle_Tool("find_facts_index_component",
+  val isabelle_tool2 = Isabelle_Tool("find_facts_index_build",
     "build Isabelle component from Find_Facts index", Scala_Project.here,
     { args =>
-      var options = Options.init()
       var target_dir = Path.current
 
       val getopts = Getopts("""
-  Usage: isabelle find_facts_index_component
+  Usage: isabelle find_facts_index_build DATABASE
 
     Options are:
-      -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
       -D DIR       target directory (default ".")
 
-    Build Isabelle component from finalized Find_Facts index with given name.
+    Build Isabelle component from finalized Find_Facts index with given database name.
   """,
-        "o:" -> (arg => options = options + arg),
         "D:" -> (arg => target_dir = Path.explode(arg)))
 
       val more_args = getopts(args)
-      if (more_args.nonEmpty) getopts.usage()
+      val database =
+        more_args match {
+          case database :: Nil => database
+          case _ => getopts.usage()
+        }
 
       val progress = new Console_Progress()
 
-      find_facts_index_component(options, target_dir = target_dir, progress = progress)
+      find_facts_index_build(database, target_dir = target_dir, progress = progress)
     })
 
 
@@ -846,19 +885,18 @@
 
   /* find facts */
 
-  val template_web_dir: Path = Path.explode("$FIND_FACTS_HOME/web")
-  val default_web_dir: Path = Path.explode("$FIND_FACTS_WEB")
+  val web_sources: Path = Path.explode("$FIND_FACTS_HOME/web")
+  val web_dir: Path = Path.explode("$FIND_FACTS_HOME_USER/web")
 
   val default_port = 8080
 
-  def find_facts(
+  def find_facts_server(
     options: Options,
     port: Int = default_port,
     devel: Boolean = false,
-    web_dir: Path = default_web_dir,
     progress: Progress = new Progress
   ): Unit = {
-    Isabelle_System.copy_dir(template_web_dir, web_dir, direct = true)
+    Isabelle_System.copy_dir(web_sources, web_dir, direct = true)
 
     val database = options.string("find_facts_database_name")
     val encode = new Encode(options)
@@ -878,7 +916,10 @@
 
     val frontend = project.build_html(progress = progress)
 
-    using(Solr.open_database(database)) { db =>
+    val solr = Solr.init(solr_data_dir)
+    resolve_indexes(solr)
+
+    using(solr.open_database(database)) { db =>
       val stats = Find_Facts.query_stats(db, Query(Nil))
       progress.echo("Started Find_Facts with " + stats.results + " blocks, " +
         stats.consts + " consts, " + stats.typs + " typs, " + stats.thms + " thms")
@@ -890,7 +931,7 @@
             def apply(request: HTTP.Request): Option[HTTP.Response] =
               Some(HTTP.Response(Bytes(isabelle_style), "text/css"))
           },
-          new HTTP.Service("app") {
+          new HTTP.Service("find_facts") {
             def apply(request: HTTP.Request): Option[HTTP.Response] =
               Some(HTTP.Response.html(
                 if (devel) project.build_html(progress = progress) else frontend))
@@ -917,7 +958,7 @@
           }))
 
       server.start()
-      progress.echo("Server started " + server.toString + "/app")
+      progress.echo("Server started " + server.toString + "/find_facts")
 
       @tailrec
       def loop(): Unit = {
@@ -938,7 +979,6 @@
       var options = Options.init()
       var port = default_port
       var verbose = false
-      var web_dir = default_web_dir
 
       val getopts = Getopts("""
 Usage: isabelle find_facts_server [OPTIONS]
@@ -948,22 +988,20 @@
     -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
     -p PORT      explicit web server port (default: """ + default_port + """)
     -v           verbose server
-    -w DIR       web directory (default: """ + default_web_dir + """)
 
   Run server for Find_Facts.
 """,
         "d" -> (_ => devel = true),
         "o:" -> (arg => options = options + arg),
         "p:" -> (arg => port = Value.Int.parse(arg)),
-        "v" -> (_ => verbose = true),
-        "w:" -> (arg => web_dir = Path.explode(arg)))
+        "v" -> (_ => verbose = true))
 
       val more_args = getopts(args)
       if (more_args.nonEmpty) getopts.usage()
 
       val progress = new Console_Progress(verbose = verbose)
 
-      find_facts(options, port = port, devel = devel, web_dir = web_dir, progress = progress)
+      find_facts_server(options, port = port, devel = devel, progress = progress)
     }
   }
 }
--- a/src/Tools/Find_Facts/src/solr.scala	Thu Jan 23 22:29:38 2025 +0100
+++ b/src/Tools/Find_Facts/src/solr.scala	Fri Jan 24 10:22:17 2025 +0100
@@ -23,20 +23,12 @@
 
 
 object Solr {
-  def init(solr_data: Path): Path = {
+  def init(solr_data: Path): System = {
     File.write(Isabelle_System.make_directory(solr_data) + Path.basic("solr.xml"), "<solr/>")
-
-    // non-portable: only for Linux or macOS
-    for (path <- Path.split(Isabelle_System.getenv("SOLR_COMPONENTS"))) {
-      Isabelle_System.symlink(path.absolute, solr_data, force = true)
-    }
-
     java.util.logging.LogManager.getLogManager.reset()
-    solr_data
+    new System(solr_data)
   }
 
-  lazy val solr_data: Path = init(Path.explode("$SOLR_DATA"))
-
 
   /** query language */
 
@@ -347,32 +339,36 @@
 
   /* database */
 
-  def database_dir(database: String): Path = solr_data + Path.basic(database)
+  class System private[Solr](val solr_data: Path) {
+    def database_dir(database: String): Path = solr_data + Path.basic(database)
 
-  def init_database(database: String, data: Data, clean: Boolean = false): Database = {
-    val db_dir = database_dir(database)
+    def init_database(database: String, data: Data, clean: Boolean = false): Database = {
+      val db_dir = database_dir(database)
 
-    if (clean) Isabelle_System.rm_tree(db_dir)
+      if (clean) Isabelle_System.rm_tree(db_dir)
 
-    val conf_dir = db_dir + Path.basic("conf")
-    if (!conf_dir.is_dir) {
-      Isabelle_System.make_directory(conf_dir)
-      File.write(conf_dir + Path.basic("schema.xml"), XML.string_of_body(data.schema))
-      File.write(conf_dir + Path.basic("solrconfig.xml"), XML.string_of_body(data.solr_config))
-      data.more_config.foreach((path, content) => File.write(conf_dir + path, content))
+      val conf_dir = db_dir + Path.basic("conf")
+      if (!conf_dir.is_dir) {
+        Isabelle_System.make_directory(conf_dir)
+        File.write(conf_dir + Path.basic("schema.xml"), XML.string_of_body(data.schema))
+        File.write(conf_dir + Path.basic("solrconfig.xml"), XML.string_of_body(data.solr_config))
+        data.more_config.foreach((path, content) => File.write(conf_dir + path, content))
+      }
+
+      open_database(database)
     }
 
-    open_database(database)
-  }
-
-  def open_database(database: String): Database = {
-    val server = new EmbeddedSolrServer(solr_data.java_path, database)
-
-    val cores = server.getCoreContainer.getAllCoreNames.asScala
-    if (cores.contains(database)) server.getCoreContainer.reload(database)
-    else server.getCoreContainer.create(database, Map.empty.asJava)
-
-    new Database(server)
+    def open_database(database: String): Database =
+      if (!database_dir(database).is_dir) error("Missing Solr database: " + quote(database))
+      else {
+        val server = new EmbeddedSolrServer(solr_data.java_path, database)
+  
+        val cores = server.getCoreContainer.getAllCoreNames.asScala
+        if (cores.contains(database)) server.getCoreContainer.reload(database)
+        else server.getCoreContainer.create(database, Map.empty.asJava)
+  
+        new Database(server)
+      }
   }
 
   class Database private[Solr](solr: EmbeddedSolrServer) extends AutoCloseable {