src/HOL/Analysis/Conformal_Mappings.thy
changeset 71001 3e374c65f96b
parent 70817 dd675800469d
child 71002 9d0712c74834
equal deleted inserted replaced
71000:98308c6582ed 71001:3e374c65f96b
   224 subsection \<open>Analytic continuation\<close>
   224 subsection \<open>Analytic continuation\<close>
   225 
   225 
   226 proposition isolated_zeros:
   226 proposition isolated_zeros:
   227   assumes holf: "f holomorphic_on S"
   227   assumes holf: "f holomorphic_on S"
   228       and "open S" "connected S" "\<xi> \<in> S" "f \<xi> = 0" "\<beta> \<in> S" "f \<beta> \<noteq> 0"
   228       and "open S" "connected S" "\<xi> \<in> S" "f \<xi> = 0" "\<beta> \<in> S" "f \<beta> \<noteq> 0"
   229     obtains r where "0 < r" and "ball \<xi> r \<subseteq> S" and 
   229     obtains r where "0 < r" and "ball \<xi> r \<subseteq> S" and
   230         "\<And>z. z \<in> ball \<xi> r - {\<xi>} \<Longrightarrow> f z \<noteq> 0"
   230         "\<And>z. z \<in> ball \<xi> r - {\<xi>} \<Longrightarrow> f z \<noteq> 0"
   231 proof -
   231 proof -
   232   obtain r where "0 < r" and r: "ball \<xi> r \<subseteq> S"
   232   obtain r where "0 < r" and r: "ball \<xi> r \<subseteq> S"
   233     using \<open>open S\<close> \<open>\<xi> \<in> S\<close> open_contains_ball_eq by blast
   233     using \<open>open S\<close> \<open>\<xi> \<in> S\<close> open_contains_ball_eq by blast
   234   have powf: "((\<lambda>n. (deriv ^^ n) f \<xi> / (fact n) * (z - \<xi>)^n) sums f z)" if "z \<in> ball \<xi> r" for z
   234   have powf: "((\<lambda>n. (deriv ^^ n) f \<xi> / (fact n) * (z - \<xi>)^n) sums f z)" if "z \<in> ball \<xi> r" for z
   278     apply (rule isolated_zeros [OF holf \<open>open S\<close> \<open>connected S\<close> \<open>\<xi> \<in> S\<close> \<open>f \<xi> = 0\<close> \<open>w \<in> S\<close>], assumption)
   278     apply (rule isolated_zeros [OF holf \<open>open S\<close> \<open>connected S\<close> \<open>\<xi> \<in> S\<close> \<open>f \<xi> = 0\<close> \<open>w \<in> S\<close>], assumption)
   279     by (metis open_ball \<open>\<xi> islimpt T\<close> centre_in_ball fT0 insertE insert_Diff islimptE)
   279     by (metis open_ball \<open>\<xi> islimpt T\<close> centre_in_ball fT0 insertE insert_Diff islimptE)
   280 qed
   280 qed
   281 
   281 
   282 corollary analytic_continuation_open:
   282 corollary analytic_continuation_open:
   283   assumes "open s" and "open s'" and "s \<noteq> {}" and "connected s'" 
   283   assumes "open s" and "open s'" and "s \<noteq> {}" and "connected s'"
   284       and "s \<subseteq> s'"
   284       and "s \<subseteq> s'"
   285   assumes "f holomorphic_on s'" and "g holomorphic_on s'" 
   285   assumes "f holomorphic_on s'" and "g holomorphic_on s'"
   286       and "\<And>z. z \<in> s \<Longrightarrow> f z = g z"
   286       and "\<And>z. z \<in> s \<Longrightarrow> f z = g z"
   287   assumes "z \<in> s'"
   287   assumes "z \<in> s'"
   288   shows   "f z = g z"
   288   shows   "f z = g z"
   289 proof -
   289 proof -
   290   from \<open>s \<noteq> {}\<close> obtain \<xi> where "\<xi> \<in> s" by auto
   290   from \<open>s \<noteq> {}\<close> obtain \<xi> where "\<xi> \<in> s" by auto
   291   with \<open>open s\<close> have \<xi>: "\<xi> islimpt s" 
   291   with \<open>open s\<close> have \<xi>: "\<xi> islimpt s"
   292     by (intro interior_limit_point) (auto simp: interior_open)
   292     by (intro interior_limit_point) (auto simp: interior_open)
   293   have "f z - g z = 0"
   293   have "f z - g z = 0"
   294     by (rule analytic_continuation[of "\<lambda>z. f z - g z" s' s \<xi>])
   294     by (rule analytic_continuation[of "\<lambda>z. f z - g z" s' s \<xi>])
   295        (insert assms \<open>\<xi> \<in> s\<close> \<xi>, auto intro: holomorphic_intros)
   295        (insert assms \<open>\<xi> \<in> s\<close> \<xi>, auto intro: holomorphic_intros)
   296   thus ?thesis by simp
   296   thus ?thesis by simp
   448       obtain w where w: "w \<in> X" using \<open>X \<noteq> {}\<close> by blast
   448       obtain w where w: "w \<in> X" using \<open>X \<noteq> {}\<close> by blast
   449       have wis: "w islimpt X"
   449       have wis: "w islimpt X"
   450         using w \<open>open X\<close> interior_eq by auto
   450         using w \<open>open X\<close> interior_eq by auto
   451       have hol: "(\<lambda>z. f z - x) holomorphic_on S"
   451       have hol: "(\<lambda>z. f z - x) holomorphic_on S"
   452         by (simp add: holf holomorphic_on_diff)
   452         by (simp add: holf holomorphic_on_diff)
   453       with fne [unfolded constant_on_def] 
   453       with fne [unfolded constant_on_def]
   454            analytic_continuation[OF hol S \<open>connected S\<close> \<open>X \<subseteq> S\<close> _ wis] not \<open>X \<subseteq> S\<close> w
   454            analytic_continuation[OF hol S \<open>connected S\<close> \<open>X \<subseteq> S\<close> _ wis] not \<open>X \<subseteq> S\<close> w
   455       show False by auto
   455       show False by auto
   456     qed
   456     qed
   457     ultimately show ?thesis
   457     ultimately show ?thesis
   458       by (rule *)
   458       by (rule *)
  1268   qed
  1268   qed
  1269 qed
  1269 qed
  1270 
  1270 
  1271 text\<open>Hence a nice clean inverse function theorem\<close>
  1271 text\<open>Hence a nice clean inverse function theorem\<close>
  1272 
  1272 
       
  1273 lemma has_field_derivative_inverse_strong:
       
  1274   fixes f :: "'a::{euclidean_space,real_normed_field} ⇒ 'a"
       
  1275   shows "DERIV f x :> f' ⟹
       
  1276          f' ≠ 0 ⟹
       
  1277          open S ⟹
       
  1278          x ∈ S ⟹
       
  1279          continuous_on S f ⟹
       
  1280          (⋀z. z ∈ S ⟹ g (f z) = z)
       
  1281          ⟹ DERIV g (f x) :> inverse (f')"
       
  1282   unfolding has_field_derivative_def
       
  1283   apply (rule has_derivative_inverse_strong [of S x f g ])
       
  1284   by auto
       
  1285 
       
  1286 lemma has_field_derivative_inverse_strong_x:
       
  1287   fixes f :: "'a::{euclidean_space,real_normed_field} ⇒ 'a"
       
  1288   shows  "DERIV f (g y) :> f' ⟹
       
  1289           f' ≠ 0 ⟹
       
  1290           open S ⟹
       
  1291           continuous_on S f ⟹
       
  1292           g y ∈ S ⟹ f(g y) = y ⟹
       
  1293           (⋀z. z ∈ S ⟹ g (f z) = z)
       
  1294           ⟹ DERIV g y :> inverse (f')"
       
  1295   unfolding has_field_derivative_def
       
  1296   apply (rule has_derivative_inverse_strong_x [of S g y f])
       
  1297   by auto
       
  1298 
  1273 proposition holomorphic_has_inverse:
  1299 proposition holomorphic_has_inverse:
  1274   assumes holf: "f holomorphic_on S"
  1300   assumes holf: "f holomorphic_on S"
  1275       and "open S" and injf: "inj_on f S"
  1301       and "open S" and injf: "inj_on f S"
  1276   obtains g where "g holomorphic_on (f ` S)"
  1302   obtains g where "g holomorphic_on (f ` S)"
  1277                   "\<And>z. z \<in> S \<Longrightarrow> deriv f z * deriv g (f z) = 1"
  1303                   "\<And>z. z \<in> S \<Longrightarrow> deriv f z * deriv g (f z) = 1"
  1377 proposition Schwarz_Lemma:
  1403 proposition Schwarz_Lemma:
  1378   assumes holf: "f holomorphic_on (ball 0 1)" and [simp]: "f 0 = 0"
  1404   assumes holf: "f holomorphic_on (ball 0 1)" and [simp]: "f 0 = 0"
  1379       and no: "\<And>z. norm z < 1 \<Longrightarrow> norm (f z) < 1"
  1405       and no: "\<And>z. norm z < 1 \<Longrightarrow> norm (f z) < 1"
  1380       and \<xi>: "norm \<xi> < 1"
  1406       and \<xi>: "norm \<xi> < 1"
  1381     shows "norm (f \<xi>) \<le> norm \<xi>" and "norm(deriv f 0) \<le> 1"
  1407     shows "norm (f \<xi>) \<le> norm \<xi>" and "norm(deriv f 0) \<le> 1"
  1382       and "((\<exists>z. norm z < 1 \<and> z \<noteq> 0 \<and> norm(f z) = norm z) 
  1408       and "((\<exists>z. norm z < 1 \<and> z \<noteq> 0 \<and> norm(f z) = norm z)
  1383             \<or> norm(deriv f 0) = 1)
  1409             \<or> norm(deriv f 0) = 1)
  1384            \<Longrightarrow> \<exists>\<alpha>. (\<forall>z. norm z < 1 \<longrightarrow> f z = \<alpha> * z) \<and> norm \<alpha> = 1" 
  1410            \<Longrightarrow> \<exists>\<alpha>. (\<forall>z. norm z < 1 \<longrightarrow> f z = \<alpha> * z) \<and> norm \<alpha> = 1"
  1385       (is "?P \<Longrightarrow> ?Q")
  1411       (is "?P \<Longrightarrow> ?Q")
  1386 proof -
  1412 proof -
  1387   obtain h where holh: "h holomorphic_on (ball 0 1)"
  1413   obtain h where holh: "h holomorphic_on (ball 0 1)"
  1388              and fz_eq: "\<And>z. norm z < 1 \<Longrightarrow> f z = z * (h z)" and df0: "deriv f 0 = h 0"
  1414              and fz_eq: "\<And>z. norm z < 1 \<Longrightarrow> f z = z * (h z)" and df0: "deriv f 0 = h 0"
  1389     by (rule Schwarz3 [OF holf]) auto
  1415     by (rule Schwarz3 [OF holf]) auto
  1454 qed
  1480 qed
  1455 
  1481 
  1456 corollary Schwarz_Lemma':
  1482 corollary Schwarz_Lemma':
  1457   assumes holf: "f holomorphic_on (ball 0 1)" and [simp]: "f 0 = 0"
  1483   assumes holf: "f holomorphic_on (ball 0 1)" and [simp]: "f 0 = 0"
  1458       and no: "\<And>z. norm z < 1 \<Longrightarrow> norm (f z) < 1"
  1484       and no: "\<And>z. norm z < 1 \<Longrightarrow> norm (f z) < 1"
  1459     shows "((\<forall>\<xi>. norm \<xi> < 1 \<longrightarrow> norm (f \<xi>) \<le> norm \<xi>) 
  1485     shows "((\<forall>\<xi>. norm \<xi> < 1 \<longrightarrow> norm (f \<xi>) \<le> norm \<xi>)
  1460             \<and> norm(deriv f 0) \<le> 1) 
  1486             \<and> norm(deriv f 0) \<le> 1)
  1461             \<and> (((\<exists>z. norm z < 1 \<and> z \<noteq> 0 \<and> norm(f z) = norm z) 
  1487             \<and> (((\<exists>z. norm z < 1 \<and> z \<noteq> 0 \<and> norm(f z) = norm z)
  1462               \<or> norm(deriv f 0) = 1)
  1488               \<or> norm(deriv f 0) = 1)
  1463               \<longrightarrow> (\<exists>\<alpha>. (\<forall>z. norm z < 1 \<longrightarrow> f z = \<alpha> * z) \<and> norm \<alpha> = 1))"
  1489               \<longrightarrow> (\<exists>\<alpha>. (\<forall>z. norm z < 1 \<longrightarrow> f z = \<alpha> * z) \<and> norm \<alpha> = 1))"
  1464   using Schwarz_Lemma [OF assms]
  1490   using Schwarz_Lemma [OF assms]
  1465   by (metis (no_types) norm_eq_zero zero_less_one)
  1491   by (metis (no_types) norm_eq_zero zero_less_one)
  1466 
  1492 
  2181   let ?P = "\<lambda>f c e. (\<forall>\<epsilon>>0. \<epsilon> < e \<longrightarrow>
  2207   let ?P = "\<lambda>f c e. (\<forall>\<epsilon>>0. \<epsilon> < e \<longrightarrow>
  2182    (f has_contour_integral of_real (2 * pi) * \<i> * c) (circlepath z \<epsilon>))"
  2208    (f has_contour_integral of_real (2 * pi) * \<i> * c) (circlepath z \<epsilon>))"
  2183   have "residue f z = residue g z" unfolding residue_def
  2209   have "residue f z = residue g z" unfolding residue_def
  2184   proof (rule Eps_cong)
  2210   proof (rule Eps_cong)
  2185     fix c :: complex
  2211     fix c :: complex
  2186     have "\<exists>e>0. ?P g c e" 
  2212     have "\<exists>e>0. ?P g c e"
  2187       if "\<exists>e>0. ?P f c e" and "eventually (\<lambda>z. f z = g z) (at z)" for f g 
  2213       if "\<exists>e>0. ?P f c e" and "eventually (\<lambda>z. f z = g z) (at z)" for f g
  2188     proof -
  2214     proof -
  2189       from that(1) obtain e where e: "e > 0" "?P f c e"
  2215       from that(1) obtain e where e: "e > 0" "?P f c e"
  2190         by blast
  2216         by blast
  2191       from that(2) obtain e' where e': "e' > 0" "\<And>z'. z' \<noteq> z \<Longrightarrow> dist z' z < e' \<Longrightarrow> f z' = g z'"
  2217       from that(2) obtain e' where e': "e' > 0" "\<And>z'. z' \<noteq> z \<Longrightarrow> dist z' z < e' \<Longrightarrow> f z' = g z'"
  2192         unfolding eventually_at by blast
  2218         unfolding eventually_at by blast
  2193       have "?P g c (min e e')"
  2219       have "?P g c (min e e')"
  2194       proof (intro allI exI impI, goal_cases)
  2220       proof (intro allI exI impI, goal_cases)
  2195         case (1 \<epsilon>)
  2221         case (1 \<epsilon>)
  2196         hence "(f has_contour_integral of_real (2 * pi) * \<i> * c) (circlepath z \<epsilon>)" 
  2222         hence "(f has_contour_integral of_real (2 * pi) * \<i> * c) (circlepath z \<epsilon>)"
  2197           using e(2) by auto
  2223           using e(2) by auto
  2198         thus ?case
  2224         thus ?case
  2199         proof (rule has_contour_integral_eq)
  2225         proof (rule has_contour_integral_eq)
  2200           fix z' assume "z' \<in> path_image (circlepath z \<epsilon>)"
  2226           fix z' assume "z' \<in> path_image (circlepath z \<epsilon>)"
  2201           hence "dist z' z < e'" and "z' \<noteq> z"
  2227           hence "dist z' z < e'" and "z' \<noteq> z"
  2466     using has_contour_integral_unique by blast
  2492     using has_contour_integral_unique by blast
  2467   thus ?thesis unfolding c_def f'_def  by auto
  2493   thus ?thesis unfolding c_def f'_def  by auto
  2468 qed
  2494 qed
  2469 
  2495 
  2470 lemma residue_simple':
  2496 lemma residue_simple':
  2471   assumes s: "open s" "z \<in> s" and holo: "f holomorphic_on (s - {z})" 
  2497   assumes s: "open s" "z \<in> s" and holo: "f holomorphic_on (s - {z})"
  2472       and lim: "((\<lambda>w. f w * (w - z)) \<longlongrightarrow> c) (at z)"
  2498       and lim: "((\<lambda>w. f w * (w - z)) \<longlongrightarrow> c) (at z)"
  2473   shows   "residue f z = c"
  2499   shows   "residue f z = c"
  2474 proof -
  2500 proof -
  2475   define g where "g = (\<lambda>w. if w = z then c else f w * (w - z))"
  2501   define g where "g = (\<lambda>w. if w = z then c else f w * (w - z))"
  2476   from holo have "(\<lambda>w. f w * (w - z)) holomorphic_on (s - {z})" (is "?P")
  2502   from holo have "(\<lambda>w. f w * (w - z)) holomorphic_on (s - {z})" (is "?P")
  2508     using r assms by (intro base_residue[of A]) (auto intro!: holomorphic_intros)
  2534     using r assms by (intro base_residue[of A]) (auto intro!: holomorphic_intros)
  2509   moreover have "(?f has_contour_integral 2 * pi * \<i> / fact n * (deriv ^^ n) f z0) (circlepath z0 r)"
  2535   moreover have "(?f has_contour_integral 2 * pi * \<i> / fact n * (deriv ^^ n) f z0) (circlepath z0 r)"
  2510     using assms r
  2536     using assms r
  2511     by (intro Cauchy_has_contour_integral_higher_derivative_circlepath)
  2537     by (intro Cauchy_has_contour_integral_higher_derivative_circlepath)
  2512        (auto intro!: holomorphic_on_subset[OF assms(3)] holomorphic_on_imp_continuous_on)
  2538        (auto intro!: holomorphic_on_subset[OF assms(3)] holomorphic_on_imp_continuous_on)
  2513   ultimately have "2 * pi * \<i> * residue ?f z0 = 2 * pi * \<i> / fact n * (deriv ^^ n) f z0"  
  2539   ultimately have "2 * pi * \<i> * residue ?f z0 = 2 * pi * \<i> / fact n * (deriv ^^ n) f z0"
  2514     by (rule has_contour_integral_unique)
  2540     by (rule has_contour_integral_unique)
  2515   thus ?thesis by (simp add: field_simps)
  2541   thus ?thesis by (simp add: field_simps)
  2516 qed
  2542 qed
  2517 
  2543 
  2518 lemma residue_holomorphic_over_power':
  2544 lemma residue_holomorphic_over_power':
  2965   finally show ?thesis unfolding c_def .
  2991   finally show ?thesis unfolding c_def .
  2966 qed
  2992 qed
  2967 
  2993 
  2968 subsection \<open>Non-essential singular points\<close>
  2994 subsection \<open>Non-essential singular points\<close>
  2969 
  2995 
  2970 definition\<^marker>\<open>tag important\<close> is_pole :: 
  2996 definition\<^marker>\<open>tag important\<close> is_pole ::
  2971   "('a::topological_space \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a \<Rightarrow> bool" where
  2997   "('a::topological_space \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a \<Rightarrow> bool" where
  2972   "is_pole f a =  (LIM x (at a). f x :> at_infinity)"
  2998   "is_pole f a =  (LIM x (at a). f x :> at_infinity)"
  2973 
  2999 
  2974 lemma is_pole_cong:
  3000 lemma is_pole_cong:
  2975   assumes "eventually (\<lambda>x. f x = g x) (at a)" "a=b"
  3001   assumes "eventually (\<lambda>x. f x = g x) (at a)" "a=b"
  3063 lemma is_pole_basic':
  3089 lemma is_pole_basic':
  3064   assumes "f holomorphic_on A" "open A" "0 \<in> A" "f 0 \<noteq> 0" "n > 0"
  3090   assumes "f holomorphic_on A" "open A" "0 \<in> A" "f 0 \<noteq> 0" "n > 0"
  3065   shows   "is_pole (\<lambda>w. f w / w ^ n) 0"
  3091   shows   "is_pole (\<lambda>w. f w / w ^ n) 0"
  3066   using is_pole_basic[of f A 0] assms by simp
  3092   using is_pole_basic[of f A 0] assms by simp
  3067 
  3093 
  3068 text \<open>The proposition 
  3094 text \<open>The proposition
  3069               \<^term>\<open>\<exists>x. ((f::complex\<Rightarrow>complex) \<longlongrightarrow> x) (at z) \<or> is_pole f z\<close> 
  3095               \<^term>\<open>\<exists>x. ((f::complex\<Rightarrow>complex) \<longlongrightarrow> x) (at z) \<or> is_pole f z\<close>
  3070 can be interpreted as the complex function \<^term>\<open>f\<close> has a non-essential singularity at \<^term>\<open>z\<close> 
  3096 can be interpreted as the complex function \<^term>\<open>f\<close> has a non-essential singularity at \<^term>\<open>z\<close>
  3071 (i.e. the singularity is either removable or a pole).\<close> 
  3097 (i.e. the singularity is either removable or a pole).\<close>
  3072 definition not_essential::"[complex \<Rightarrow> complex, complex] \<Rightarrow> bool" where
  3098 definition not_essential::"[complex \<Rightarrow> complex, complex] \<Rightarrow> bool" where
  3073   "not_essential f z = (\<exists>x. f\<midarrow>z\<rightarrow>x \<or> is_pole f z)"
  3099   "not_essential f z = (\<exists>x. f\<midarrow>z\<rightarrow>x \<or> is_pole f z)"
  3074 
  3100 
  3075 definition isolated_singularity_at::"[complex \<Rightarrow> complex, complex] \<Rightarrow> bool" where
  3101 definition isolated_singularity_at::"[complex \<Rightarrow> complex, complex] \<Rightarrow> bool" where
  3076   "isolated_singularity_at f z = (\<exists>r>0. f analytic_on ball z r-{z})"
  3102   "isolated_singularity_at f z = (\<exists>r>0. f analytic_on ball z r-{z})"
  3100       define F where "F \<equiv> at z within ball z r"
  3126       define F where "F \<equiv> at z within ball z r"
  3101       define f' where "f' \<equiv> \<lambda>x. (x - z) powr (n-m)"
  3127       define f' where "f' \<equiv> \<lambda>x. (x - z) powr (n-m)"
  3102       have "f' z=0" using \<open>n>m\<close> unfolding f'_def by auto
  3128       have "f' z=0" using \<open>n>m\<close> unfolding f'_def by auto
  3103       moreover have "continuous F f'" unfolding f'_def F_def continuous_def
  3129       moreover have "continuous F f'" unfolding f'_def F_def continuous_def
  3104         apply (subst Lim_ident_at)
  3130         apply (subst Lim_ident_at)
  3105         using \<open>n>m\<close> by (auto intro!:tendsto_powr_complex_0 tendsto_eq_intros)  
  3131         using \<open>n>m\<close> by (auto intro!:tendsto_powr_complex_0 tendsto_eq_intros)
  3106       ultimately have "(f' \<longlongrightarrow> 0) F" unfolding F_def
  3132       ultimately have "(f' \<longlongrightarrow> 0) F" unfolding F_def
  3107         by (simp add: continuous_within)
  3133         by (simp add: continuous_within)
  3108       moreover have "(g \<longlongrightarrow> g z) F"
  3134       moreover have "(g \<longlongrightarrow> g z) F"
  3109         using holomorphic_on_imp_continuous_on[OF g_holo,unfolded continuous_on_def] \<open>r>0\<close>
  3135         using holomorphic_on_imp_continuous_on[OF g_holo,unfolded continuous_on_def] \<open>r>0\<close>
  3110         unfolding F_def by auto
  3136         unfolding F_def by auto
  3147   qed
  3173   qed
  3148   ultimately show "n=m" by fastforce
  3174   ultimately show "n=m" by fastforce
  3149 qed
  3175 qed
  3150 
  3176 
  3151 lemma holomorphic_factor_puncture:
  3177 lemma holomorphic_factor_puncture:
  3152   assumes f_iso:"isolated_singularity_at f z"   
  3178   assumes f_iso:"isolated_singularity_at f z"
  3153       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>
  3179       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>
  3154       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>
  3180       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>
  3155   shows "\<exists>!n::int. \<exists>g r. 0 < r \<and> g holomorphic_on cball z r \<and> g z\<noteq>0
  3181   shows "\<exists>!n::int. \<exists>g r. 0 < r \<and> g holomorphic_on cball z r \<and> g z\<noteq>0
  3156           \<and> (\<forall>w\<in>cball z r-{z}. f w = g w * (w-z) powr n \<and> g w\<noteq>0)"
  3182           \<and> (\<forall>w\<in>cball z r-{z}. f w = g w * (w-z) powr n \<and> g w\<noteq>0)"
  3157 proof -
  3183 proof -
  3158   define P where "P = (\<lambda>f n g r. 0 < r \<and> g holomorphic_on cball z r \<and> g z\<noteq>0
  3184   define P where "P = (\<lambda>f n g r. 0 < r \<and> g holomorphic_on cball z r \<and> g z\<noteq>0
  3159           \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w-z) powr (of_int n)  \<and> g w\<noteq>0))"
  3185           \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w-z) powr (of_int n)  \<and> g w\<noteq>0))"
  3160   have imp_unique:"\<exists>!n::int. \<exists>g r. P f n g r" when "\<exists>n g r. P f n g r" 
  3186   have imp_unique:"\<exists>!n::int. \<exists>g r. P f n g r" when "\<exists>n g r. P f n g r"
  3161   proof (rule ex_ex1I[OF that])
  3187   proof (rule ex_ex1I[OF that])
  3162     fix n1 n2 :: int
  3188     fix n1 n2 :: int
  3163     assume g1_asm:"\<exists>g1 r1. P f n1 g1 r1" and g2_asm:"\<exists>g2 r2. P f n2 g2 r2"
  3189     assume g1_asm:"\<exists>g1 r1. P f n1 g1 r1" and g2_asm:"\<exists>g2 r2. P f n2 g2 r2"
  3164     define fac where "fac \<equiv> \<lambda>n g r. \<forall>w\<in>cball z r-{z}. f w = g w * (w - z) powr (of_int n) \<and> g w \<noteq> 0"
  3190     define fac where "fac \<equiv> \<lambda>n g r. \<forall>w\<in>cball z r-{z}. f w = g w * (w - z) powr (of_int n) \<and> g w \<noteq> 0"
  3165     obtain g1 r1 where "0 < r1" and g1_holo: "g1 holomorphic_on cball z r1" and "g1 z\<noteq>0"
  3191     obtain g1 r1 where "0 < r1" and g1_holo: "g1 holomorphic_on cball z r1" and "g1 z\<noteq>0"
  3166         and "fac n1 g1 r1" using g1_asm unfolding P_def fac_def by auto
  3192         and "fac n1 g1 r1" using g1_asm unfolding P_def fac_def by auto
  3167     obtain g2 r2 where "0 < r2" and g2_holo: "g2 holomorphic_on cball z r2" and "g2 z\<noteq>0"
  3193     obtain g2 r2 where "0 < r2" and g2_holo: "g2 holomorphic_on cball z r2" and "g2 z\<noteq>0"
  3168         and "fac n2 g2 r2" using g2_asm unfolding P_def fac_def by auto
  3194         and "fac n2 g2 r2" using g2_asm unfolding P_def fac_def by auto
  3169     define r where "r \<equiv> min r1 r2"
  3195     define r where "r \<equiv> min r1 r2"
  3170     have "r>0" using \<open>r1>0\<close> \<open>r2>0\<close> unfolding r_def by auto
  3196     have "r>0" using \<open>r1>0\<close> \<open>r2>0\<close> unfolding r_def by auto
  3171     moreover have "\<forall>w\<in>ball z r-{z}. f w = g1 w * (w-z) powr n1 \<and> g1 w\<noteq>0 
  3197     moreover have "\<forall>w\<in>ball z r-{z}. f w = g1 w * (w-z) powr n1 \<and> g1 w\<noteq>0
  3172         \<and> f w = g2 w * (w - z) powr n2  \<and> g2 w\<noteq>0"
  3198         \<and> f w = g2 w * (w - z) powr n2  \<and> g2 w\<noteq>0"
  3173       using \<open>fac n1 g1 r1\<close> \<open>fac n2 g2 r2\<close>   unfolding fac_def r_def
  3199       using \<open>fac n1 g1 r1\<close> \<open>fac n2 g2 r2\<close>   unfolding fac_def r_def
  3174       by fastforce
  3200       by fastforce
  3175     ultimately show "n1=n2" using g1_holo g2_holo \<open>g1 z\<noteq>0\<close> \<open>g2 z\<noteq>0\<close>
  3201     ultimately show "n1=n2" using g1_holo g2_holo \<open>g1 z\<noteq>0\<close> \<open>g2 z\<noteq>0\<close>
  3176       apply (elim holomorphic_factor_unique)
  3202       apply (elim holomorphic_factor_unique)
  3177       by (auto simp add:r_def) 
  3203       by (auto simp add:r_def)
  3178   qed
  3204   qed
  3179 
  3205 
  3180   have P_exist:"\<exists> n g r. P h n g r" when 
  3206   have P_exist:"\<exists> n g r. P h n g r" when
  3181       "\<exists>z'. (h \<longlongrightarrow> z') (at z)" "isolated_singularity_at h z"  "\<exists>\<^sub>Fw in (at z). h w\<noteq>0" 
  3207       "\<exists>z'. (h \<longlongrightarrow> z') (at z)" "isolated_singularity_at h z"  "\<exists>\<^sub>Fw in (at z). h w\<noteq>0"
  3182     for h
  3208     for h
  3183   proof -
  3209   proof -
  3184     from that(2) obtain r where "r>0" "h analytic_on ball z r - {z}"
  3210     from that(2) obtain r where "r>0" "h analytic_on ball z r - {z}"
  3185       unfolding isolated_singularity_at_def by auto
  3211       unfolding isolated_singularity_at_def by auto
  3186     obtain z' where "(h \<longlongrightarrow> z') (at z)" using \<open>\<exists>z'. (h \<longlongrightarrow> z') (at z)\<close> by auto
  3212     obtain z' where "(h \<longlongrightarrow> z') (at z)" using \<open>\<exists>z'. (h \<longlongrightarrow> z') (at z)\<close> by auto
  3187     define h' where "h'=(\<lambda>x. if x=z then z' else h x)"
  3213     define h' where "h'=(\<lambda>x. if x=z then z' else h x)"
  3188     have "h' holomorphic_on ball z r"
  3214     have "h' holomorphic_on ball z r"
  3189       apply (rule no_isolated_singularity'[of "{z}"]) 
  3215       apply (rule no_isolated_singularity'[of "{z}"])
  3190       subgoal by (metis LIM_equal Lim_at_imp_Lim_at_within \<open>h \<midarrow>z\<rightarrow> z'\<close> empty_iff h'_def insert_iff)
  3216       subgoal by (metis LIM_equal Lim_at_imp_Lim_at_within \<open>h \<midarrow>z\<rightarrow> z'\<close> empty_iff h'_def insert_iff)
  3191       subgoal using \<open>h analytic_on ball z r - {z}\<close> analytic_imp_holomorphic h'_def holomorphic_transform 
  3217       subgoal using \<open>h analytic_on ball z r - {z}\<close> analytic_imp_holomorphic h'_def holomorphic_transform
  3192         by fastforce
  3218         by fastforce
  3193       by auto
  3219       by auto
  3194     have ?thesis when "z'=0"
  3220     have ?thesis when "z'=0"
  3195     proof - 
  3221     proof -
  3196       have "h' z=0" using that unfolding h'_def by auto
  3222       have "h' z=0" using that unfolding h'_def by auto
  3197       moreover have "\<not> h' constant_on ball z r" 
  3223       moreover have "\<not> h' constant_on ball z r"
  3198         using \<open>\<exists>\<^sub>Fw in (at z). h w\<noteq>0\<close> unfolding constant_on_def frequently_def eventually_at h'_def
  3224         using \<open>\<exists>\<^sub>Fw in (at z). h w\<noteq>0\<close> unfolding constant_on_def frequently_def eventually_at h'_def
  3199         apply simp
  3225         apply simp
  3200         by (metis \<open>0 < r\<close> centre_in_ball dist_commute mem_ball that)
  3226         by (metis \<open>0 < r\<close> centre_in_ball dist_commute mem_ball that)
  3201       moreover note \<open>h' holomorphic_on ball z r\<close>
  3227       moreover note \<open>h' holomorphic_on ball z r\<close>
  3202       ultimately obtain g r1 n where "0 < n" "0 < r1" "ball z r1 \<subseteq> ball z r" and
  3228       ultimately obtain g r1 n where "0 < n" "0 < r1" "ball z r1 \<subseteq> ball z r" and
  3203           g:"g holomorphic_on ball z r1"
  3229           g:"g holomorphic_on ball z r1"
  3204           "\<And>w. w \<in> ball z r1 \<Longrightarrow> h' w = (w - z) ^ n * g w"
  3230           "\<And>w. w \<in> ball z r1 \<Longrightarrow> h' w = (w - z) ^ n * g w"
  3205           "\<And>w. w \<in> ball z r1 \<Longrightarrow> g w \<noteq> 0" 
  3231           "\<And>w. w \<in> ball z r1 \<Longrightarrow> g w \<noteq> 0"
  3206         using holomorphic_factor_zero_nonconstant[of _ "ball z r" z thesis,simplified,
  3232         using holomorphic_factor_zero_nonconstant[of _ "ball z r" z thesis,simplified,
  3207                 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>] 
  3233                 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>]
  3208         by (auto simp add:dist_commute)
  3234         by (auto simp add:dist_commute)
  3209       define rr where "rr=r1/2"
  3235       define rr where "rr=r1/2"
  3210       have "P h' n g rr"
  3236       have "P h' n g rr"
  3211         unfolding P_def rr_def
  3237         unfolding P_def rr_def
  3212         using \<open>n>0\<close> \<open>r1>0\<close> g by (auto simp add:powr_nat)
  3238         using \<open>n>0\<close> \<open>r1>0\<close> g by (auto simp add:powr_nat)
  3222         have "isCont h' z" "h' z\<noteq>0"
  3248         have "isCont h' z" "h' z\<noteq>0"
  3223           by (auto simp add: Lim_cong_within \<open>h \<midarrow>z\<rightarrow> z'\<close> \<open>z'\<noteq>0\<close> continuous_at h'_def)
  3249           by (auto simp add: Lim_cong_within \<open>h \<midarrow>z\<rightarrow> z'\<close> \<open>z'\<noteq>0\<close> continuous_at h'_def)
  3224         then obtain r2 where r2:"r2>0" "\<forall>x\<in>ball z r2. h' x\<noteq>0"
  3250         then obtain r2 where r2:"r2>0" "\<forall>x\<in>ball z r2. h' x\<noteq>0"
  3225           using continuous_at_avoid[of z h' 0 ] unfolding ball_def by auto
  3251           using continuous_at_avoid[of z h' 0 ] unfolding ball_def by auto
  3226         define r1 where "r1=min r2 r / 2"
  3252         define r1 where "r1=min r2 r / 2"
  3227         have "0 < r1" "cball z r1 \<subseteq> ball z r" 
  3253         have "0 < r1" "cball z r1 \<subseteq> ball z r"
  3228           using \<open>r2>0\<close> \<open>r>0\<close> unfolding r1_def by auto
  3254           using \<open>r2>0\<close> \<open>r>0\<close> unfolding r1_def by auto
  3229         moreover have "\<forall>x\<in>cball z r1. h' x \<noteq> 0" 
  3255         moreover have "\<forall>x\<in>cball z r1. h' x \<noteq> 0"
  3230           using r2 unfolding r1_def by simp
  3256           using r2 unfolding r1_def by simp
  3231         ultimately show ?thesis using that by auto
  3257         ultimately show ?thesis using that by auto
  3232       qed
  3258       qed
  3233       then have "P h' 0 h' r1" using \<open>h' holomorphic_on ball z r\<close> unfolding P_def by auto
  3259       then have "P h' 0 h' r1" using \<open>h' holomorphic_on ball z r\<close> unfolding P_def by auto
  3234       then have "P h 0 h' r1" unfolding P_def h'_def by auto
  3260       then have "P h 0 h' r1" unfolding P_def h'_def by auto
  3254       define e where "e=min e1 e2"
  3280       define e where "e=min e1 e2"
  3255       show ?thesis
  3281       show ?thesis
  3256         apply (rule that[of e])
  3282         apply (rule that[of e])
  3257         using  e1 e2 unfolding e_def by auto
  3283         using  e1 e2 unfolding e_def by auto
  3258     qed
  3284     qed
  3259     
  3285 
  3260     define h where "h \<equiv> \<lambda>x. inverse (f x)"
  3286     define h where "h \<equiv> \<lambda>x. inverse (f x)"
  3261 
  3287 
  3262     have "\<exists>n g r. P h n g r"
  3288     have "\<exists>n g r. P h n g r"
  3263     proof -
  3289     proof -
  3264       have "h \<midarrow>z\<rightarrow> 0" 
  3290       have "h \<midarrow>z\<rightarrow> 0"
  3265         using Lim_transform_within_open assms(2) h_def is_pole_tendsto that by fastforce
  3291         using Lim_transform_within_open assms(2) h_def is_pole_tendsto that by fastforce
  3266       moreover have "\<exists>\<^sub>Fw in (at z). h w\<noteq>0"
  3292       moreover have "\<exists>\<^sub>Fw in (at z). h w\<noteq>0"
  3267         using non_zero 
  3293         using non_zero
  3268         apply (elim frequently_rev_mp)
  3294         apply (elim frequently_rev_mp)
  3269         unfolding h_def eventually_at by (auto intro:exI[where x=1])
  3295         unfolding h_def eventually_at by (auto intro:exI[where x=1])
  3270       moreover have "isolated_singularity_at h z"
  3296       moreover have "isolated_singularity_at h z"
  3271         unfolding isolated_singularity_at_def h_def
  3297         unfolding isolated_singularity_at_def h_def
  3272         apply (rule exI[where x=e])
  3298         apply (rule exI[where x=e])
  3273         using e_holo e_nz \<open>e>0\<close> by (metis open_ball analytic_on_open 
  3299         using e_holo e_nz \<open>e>0\<close> by (metis open_ball analytic_on_open
  3274             holomorphic_on_inverse open_delete)
  3300             holomorphic_on_inverse open_delete)
  3275       ultimately show ?thesis
  3301       ultimately show ?thesis
  3276         using P_exist[of h] by auto
  3302         using P_exist[of h] by auto
  3277     qed
  3303     qed
  3278     then obtain n g r
  3304     then obtain n g r
  3281             g_fac:"(\<forall>w\<in>cball z r-{z}. h w = g w * (w - z) powr of_int n  \<and> g w \<noteq> 0)"
  3307             g_fac:"(\<forall>w\<in>cball z r-{z}. h w = g w * (w - z) powr of_int n  \<and> g w \<noteq> 0)"
  3282       unfolding P_def by auto
  3308       unfolding P_def by auto
  3283     have "P f (-n) (inverse o g) r"
  3309     have "P f (-n) (inverse o g) r"
  3284     proof -
  3310     proof -
  3285       have "f w = inverse (g w) * (w - z) powr of_int (- n)" when "w\<in>cball z r - {z}" for w
  3311       have "f w = inverse (g w) * (w - z) powr of_int (- n)" when "w\<in>cball z r - {z}" for w
  3286         using g_fac[rule_format,of w] that unfolding h_def 
  3312         using g_fac[rule_format,of w] that unfolding h_def
  3287         apply (auto simp add:powr_minus )
  3313         apply (auto simp add:powr_minus )
  3288         by (metis inverse_inverse_eq inverse_mult_distrib)
  3314         by (metis inverse_inverse_eq inverse_mult_distrib)
  3289       then show ?thesis 
  3315       then show ?thesis
  3290         unfolding P_def comp_def
  3316         unfolding P_def comp_def
  3291         using \<open>r>0\<close> g_holo g_fac \<open>g z\<noteq>0\<close> by (auto intro:holomorphic_intros)
  3317         using \<open>r>0\<close> g_holo g_fac \<open>g z\<noteq>0\<close> by (auto intro:holomorphic_intros)
  3292     qed
  3318     qed
  3293     then show "\<exists>x g r. 0 < r \<and> g holomorphic_on cball z r \<and> g z \<noteq> 0 
  3319     then show "\<exists>x g r. 0 < r \<and> g holomorphic_on cball z r \<and> g z \<noteq> 0
  3294                   \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powr of_int x  \<and> g w \<noteq> 0)"
  3320                   \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powr of_int x  \<and> g w \<noteq> 0)"
  3295       unfolding P_def by blast
  3321       unfolding P_def by blast
  3296   qed
  3322   qed
  3297   ultimately show ?thesis using \<open>not_essential f z\<close> unfolding not_essential_def  by presburger
  3323   ultimately show ?thesis using \<open>not_essential f z\<close> unfolding not_essential_def  by presburger
  3298 qed
  3324 qed
  3299 
  3325 
  3300 lemma not_essential_transform:
  3326 lemma not_essential_transform:
  3301   assumes "not_essential g z"
  3327   assumes "not_essential g z"
  3302   assumes "\<forall>\<^sub>F w in (at z). g w = f w"
  3328   assumes "\<forall>\<^sub>F w in (at z). g w = f w"
  3303   shows "not_essential f z" 
  3329   shows "not_essential f z"
  3304   using assms unfolding not_essential_def
  3330   using assms unfolding not_essential_def
  3305   by (simp add: filterlim_cong is_pole_cong)
  3331   by (simp add: filterlim_cong is_pole_cong)
  3306 
  3332 
  3307 lemma isolated_singularity_at_transform:
  3333 lemma isolated_singularity_at_transform:
  3308   assumes "isolated_singularity_at g z"
  3334   assumes "isolated_singularity_at g z"
  3309   assumes "\<forall>\<^sub>F w in (at z). g w = f w"
  3335   assumes "\<forall>\<^sub>F w in (at z). g w = f w"
  3310   shows "isolated_singularity_at f z" 
  3336   shows "isolated_singularity_at f z"
  3311 proof -
  3337 proof -
  3312   obtain r1 where "r1>0" and r1:"g analytic_on ball z r1 - {z}"
  3338   obtain r1 where "r1>0" and r1:"g analytic_on ball z r1 - {z}"
  3313     using assms(1) unfolding isolated_singularity_at_def by auto
  3339     using assms(1) unfolding isolated_singularity_at_def by auto
  3314   obtain r2 where "r2>0" and r2:" \<forall>x. x \<noteq> z \<and> dist x z < r2 \<longrightarrow> g x = f x"
  3340   obtain r2 where "r2>0" and r2:" \<forall>x. x \<noteq> z \<and> dist x z < r2 \<longrightarrow> g x = f x"
  3315     using assms(2) unfolding eventually_at by auto
  3341     using assms(2) unfolding eventually_at by auto
  3318   moreover have "f analytic_on ball z r3 - {z}"
  3344   moreover have "f analytic_on ball z r3 - {z}"
  3319   proof -
  3345   proof -
  3320     have "g holomorphic_on ball z r3 - {z}"
  3346     have "g holomorphic_on ball z r3 - {z}"
  3321       using r1 unfolding r3_def by (subst (asm) analytic_on_open,auto)
  3347       using r1 unfolding r3_def by (subst (asm) analytic_on_open,auto)
  3322     then have "f holomorphic_on ball z r3 - {z}"
  3348     then have "f holomorphic_on ball z r3 - {z}"
  3323       using r2 unfolding r3_def 
  3349       using r2 unfolding r3_def
  3324       by (auto simp add:dist_commute elim!:holomorphic_transform)
  3350       by (auto simp add:dist_commute elim!:holomorphic_transform)
  3325     then show ?thesis by (subst analytic_on_open,auto)  
  3351     then show ?thesis by (subst analytic_on_open,auto)
  3326   qed
  3352   qed
  3327   ultimately show ?thesis unfolding isolated_singularity_at_def by auto
  3353   ultimately show ?thesis unfolding isolated_singularity_at_def by auto
  3328 qed
  3354 qed
  3329 
  3355 
  3330 lemma not_essential_powr[singularity_intros]:
  3356 lemma not_essential_powr[singularity_intros]:
  3332   shows "not_essential (\<lambda>w. (f w) powr (of_int n)) z"
  3358   shows "not_essential (\<lambda>w. (f w) powr (of_int n)) z"
  3333 proof -
  3359 proof -
  3334   define fp where "fp=(\<lambda>w. (f w) powr (of_int n))"
  3360   define fp where "fp=(\<lambda>w. (f w) powr (of_int n))"
  3335   have ?thesis when "n>0"
  3361   have ?thesis when "n>0"
  3336   proof -
  3362   proof -
  3337     have "(\<lambda>w.  (f w) ^ (nat n)) \<midarrow>z\<rightarrow> x ^ nat n" 
  3363     have "(\<lambda>w.  (f w) ^ (nat n)) \<midarrow>z\<rightarrow> x ^ nat n"
  3338       using that assms unfolding filterlim_at by (auto intro!:tendsto_eq_intros)
  3364       using that assms unfolding filterlim_at by (auto intro!:tendsto_eq_intros)
  3339     then have "fp \<midarrow>z\<rightarrow> x ^ nat n" unfolding fp_def      
  3365     then have "fp \<midarrow>z\<rightarrow> x ^ nat n" unfolding fp_def
  3340       apply (elim Lim_transform_within[where d=1],simp)
  3366       apply (elim Lim_transform_within[where d=1],simp)
  3341       by (metis less_le powr_0 powr_of_int that zero_less_nat_eq zero_power)
  3367       by (metis less_le powr_0 powr_of_int that zero_less_nat_eq zero_power)
  3342     then show ?thesis unfolding not_essential_def fp_def by auto
  3368     then show ?thesis unfolding not_essential_def fp_def by auto
  3343   qed
  3369   qed
  3344   moreover have ?thesis when "n=0"
  3370   moreover have ?thesis when "n=0"
  3345   proof -
  3371   proof -
  3346     have "fp \<midarrow>z\<rightarrow> 1 " 
  3372     have "fp \<midarrow>z\<rightarrow> 1 "
  3347       apply (subst tendsto_cong[where g="\<lambda>_.1"])
  3373       apply (subst tendsto_cong[where g="\<lambda>_.1"])
  3348       using that filterlim_at_within_not_equal[OF assms,of 0] unfolding fp_def by auto
  3374       using that filterlim_at_within_not_equal[OF assms,of 0] unfolding fp_def by auto
  3349     then show ?thesis unfolding fp_def not_essential_def by auto
  3375     then show ?thesis unfolding fp_def not_essential_def by auto
  3350   qed
  3376   qed
  3351   moreover have ?thesis when "n<0"
  3377   moreover have ?thesis when "n<0"
  3353     case True
  3379     case True
  3354     have "LIM w (at z). inverse ((f w) ^ (nat (-n))) :> at_infinity"
  3380     have "LIM w (at z). inverse ((f w) ^ (nat (-n))) :> at_infinity"
  3355       apply (subst filterlim_inverse_at_iff[symmetric],simp)
  3381       apply (subst filterlim_inverse_at_iff[symmetric],simp)
  3356       apply (rule filterlim_atI)
  3382       apply (rule filterlim_atI)
  3357       subgoal using assms True that unfolding filterlim_at by (auto intro!:tendsto_eq_intros)
  3383       subgoal using assms True that unfolding filterlim_at by (auto intro!:tendsto_eq_intros)
  3358       subgoal using filterlim_at_within_not_equal[OF assms,of 0] 
  3384       subgoal using filterlim_at_within_not_equal[OF assms,of 0]
  3359         by (eventually_elim,insert that,auto)
  3385         by (eventually_elim,insert that,auto)
  3360       done
  3386       done
  3361     then have "LIM w (at z). fp w :> at_infinity"
  3387     then have "LIM w (at z). fp w :> at_infinity"
  3362     proof (elim filterlim_mono_eventually)
  3388     proof (elim filterlim_mono_eventually)
  3363       show "\<forall>\<^sub>F x in at z. inverse (f x ^ nat (- n)) = fp x"
  3389       show "\<forall>\<^sub>F x in at z. inverse (f x ^ nat (- n)) = fp x"
  3371     let ?xx= "inverse (x ^ (nat (-n)))"
  3397     let ?xx= "inverse (x ^ (nat (-n)))"
  3372     have "(\<lambda>w. inverse ((f w) ^ (nat (-n)))) \<midarrow>z\<rightarrow>?xx"
  3398     have "(\<lambda>w. inverse ((f w) ^ (nat (-n)))) \<midarrow>z\<rightarrow>?xx"
  3373       using assms False unfolding filterlim_at by (auto intro!:tendsto_eq_intros)
  3399       using assms False unfolding filterlim_at by (auto intro!:tendsto_eq_intros)
  3374     then have "fp \<midarrow>z\<rightarrow>?xx"
  3400     then have "fp \<midarrow>z\<rightarrow>?xx"
  3375       apply (elim Lim_transform_within[where d=1],simp)
  3401       apply (elim Lim_transform_within[where d=1],simp)
  3376       unfolding fp_def by (metis inverse_zero nat_mono_iff nat_zero_as_int neg_0_less_iff_less 
  3402       unfolding fp_def by (metis inverse_zero nat_mono_iff nat_zero_as_int neg_0_less_iff_less
  3377           not_le power_eq_0_iff powr_0 powr_of_int that)
  3403           not_le power_eq_0_iff powr_0 powr_of_int that)
  3378     then show ?thesis unfolding fp_def not_essential_def by auto
  3404     then show ?thesis unfolding fp_def not_essential_def by auto
  3379   qed
  3405   qed
  3380   ultimately show ?thesis by linarith
  3406   ultimately show ?thesis by linarith
  3381 qed
  3407 qed
  3401     apply (subst (asm) analytic_on_open[symmetric])
  3427     apply (subst (asm) analytic_on_open[symmetric])
  3402     by auto
  3428     by auto
  3403 qed
  3429 qed
  3404 
  3430 
  3405 lemma non_zero_neighbour:
  3431 lemma non_zero_neighbour:
  3406   assumes f_iso:"isolated_singularity_at f z"   
  3432   assumes f_iso:"isolated_singularity_at f z"
  3407       and f_ness:"not_essential f z" 
  3433       and f_ness:"not_essential f z"
  3408       and f_nconst:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
  3434       and f_nconst:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
  3409     shows "\<forall>\<^sub>F w in (at z). f w\<noteq>0"
  3435     shows "\<forall>\<^sub>F w in (at z). f w\<noteq>0"
  3410 proof -
  3436 proof -
  3411   obtain fn fp fr where [simp]:"fp z \<noteq> 0" and "fr > 0"
  3437   obtain fn fp fr where [simp]:"fp z \<noteq> 0" and "fr > 0"
  3412           and fr: "fp holomorphic_on cball z fr" 
  3438           and fr: "fp holomorphic_on cball z fr"
  3413                   "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w - z) powr of_int fn \<and> fp w \<noteq> 0"
  3439                   "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w - z) powr of_int fn \<and> fp w \<noteq> 0"
  3414     using holomorphic_factor_puncture[OF f_iso f_ness f_nconst,THEN ex1_implies_ex] by auto
  3440     using holomorphic_factor_puncture[OF f_iso f_ness f_nconst,THEN ex1_implies_ex] by auto
  3415   have "f w \<noteq> 0" when " w \<noteq> z" "dist w z < fr" for w
  3441   have "f w \<noteq> 0" when " w \<noteq> z" "dist w z < fr" for w
  3416   proof -
  3442   proof -
  3417     have "f w = fp w * (w - z) powr of_int fn" "fp w \<noteq> 0"
  3443     have "f w = fp w * (w - z) powr of_int fn" "fp w \<noteq> 0"
  3424 qed
  3450 qed
  3425 
  3451 
  3426 lemma non_zero_neighbour_pole:
  3452 lemma non_zero_neighbour_pole:
  3427   assumes "is_pole f z"
  3453   assumes "is_pole f z"
  3428   shows "\<forall>\<^sub>F w in (at z). f w\<noteq>0"
  3454   shows "\<forall>\<^sub>F w in (at z). f w\<noteq>0"
  3429   using assms filterlim_at_infinity_imp_eventually_ne[of f "at z" 0]  
  3455   using assms filterlim_at_infinity_imp_eventually_ne[of f "at z" 0]
  3430   unfolding is_pole_def by auto
  3456   unfolding is_pole_def by auto
  3431 
  3457 
  3432 lemma non_zero_neighbour_alt:
  3458 lemma non_zero_neighbour_alt:
  3433   assumes holo: "f holomorphic_on S"
  3459   assumes holo: "f holomorphic_on S"
  3434       and "open S" "connected S" "z \<in> S"  "\<beta> \<in> S" "f \<beta> \<noteq> 0"
  3460       and "open S" "connected S" "z \<in> S"  "\<beta> \<in> S" "f \<beta> \<noteq> 0"
  3435     shows "\<forall>\<^sub>F w in (at z). f w\<noteq>0 \<and> w\<in>S"
  3461     shows "\<forall>\<^sub>F w in (at z). f w\<noteq>0 \<and> w\<in>S"
  3436 proof (cases "f z = 0")
  3462 proof (cases "f z = 0")
  3437   case True
  3463   case True
  3438   from isolated_zeros[OF holo \<open>open S\<close> \<open>connected S\<close> \<open>z \<in> S\<close> True \<open>\<beta> \<in> S\<close> \<open>f \<beta> \<noteq> 0\<close>] 
  3464   from isolated_zeros[OF holo \<open>open S\<close> \<open>connected S\<close> \<open>z \<in> S\<close> True \<open>\<beta> \<in> S\<close> \<open>f \<beta> \<noteq> 0\<close>]
  3439   obtain r where "0 < r" "ball z r \<subseteq> S" "\<forall>w \<in> ball z r - {z}.f w \<noteq> 0" by metis 
  3465   obtain r where "0 < r" "ball z r \<subseteq> S" "\<forall>w \<in> ball z r - {z}.f w \<noteq> 0" by metis
  3440   then show ?thesis unfolding eventually_at 
  3466   then show ?thesis unfolding eventually_at
  3441     apply (rule_tac x=r in exI)
  3467     apply (rule_tac x=r in exI)
  3442     by (auto simp add:dist_commute)
  3468     by (auto simp add:dist_commute)
  3443 next
  3469 next
  3444   case False
  3470   case False
  3445   obtain r1 where r1:"r1>0" "\<forall>y. dist z y < r1 \<longrightarrow> f y \<noteq> 0"
  3471   obtain r1 where r1:"r1>0" "\<forall>y. dist z y < r1 \<longrightarrow> f y \<noteq> 0"
  3446     using continuous_at_avoid[of z f, OF _ False] assms(2,4) continuous_on_eq_continuous_at 
  3472     using continuous_at_avoid[of z f, OF _ False] assms(2,4) continuous_on_eq_continuous_at
  3447       holo holomorphic_on_imp_continuous_on by blast
  3473       holo holomorphic_on_imp_continuous_on by blast
  3448   obtain r2 where r2:"r2>0" "ball z r2 \<subseteq> S" 
  3474   obtain r2 where r2:"r2>0" "ball z r2 \<subseteq> S"
  3449     using assms(2) assms(4) openE by blast
  3475     using assms(2) assms(4) openE by blast
  3450   show ?thesis unfolding eventually_at 
  3476   show ?thesis unfolding eventually_at
  3451     apply (rule_tac x="min r1 r2" in exI)
  3477     apply (rule_tac x="min r1 r2" in exI)
  3452     using r1 r2 by (auto simp add:dist_commute)
  3478     using r1 r2 by (auto simp add:dist_commute)
  3453 qed
  3479 qed
  3454 
  3480 
  3455 lemma not_essential_times[singularity_intros]:
  3481 lemma not_essential_times[singularity_intros]:
  3458   shows "not_essential (\<lambda>w. f w * g w) z"
  3484   shows "not_essential (\<lambda>w. f w * g w) z"
  3459 proof -
  3485 proof -
  3460   define fg where "fg = (\<lambda>w. f w * g w)"
  3486   define fg where "fg = (\<lambda>w. f w * g w)"
  3461   have ?thesis when "\<not> ((\<exists>\<^sub>Fw in (at z). f w\<noteq>0) \<and> (\<exists>\<^sub>Fw in (at z). g w\<noteq>0))"
  3487   have ?thesis when "\<not> ((\<exists>\<^sub>Fw in (at z). f w\<noteq>0) \<and> (\<exists>\<^sub>Fw in (at z). g w\<noteq>0))"
  3462   proof -
  3488   proof -
  3463     have "\<forall>\<^sub>Fw in (at z). fg w=0" 
  3489     have "\<forall>\<^sub>Fw in (at z). fg w=0"
  3464       using that[unfolded frequently_def, simplified] unfolding fg_def
  3490       using that[unfolded frequently_def, simplified] unfolding fg_def
  3465       by (auto elim: eventually_rev_mp)
  3491       by (auto elim: eventually_rev_mp)
  3466     from tendsto_cong[OF this] have "fg \<midarrow>z\<rightarrow>0" by auto
  3492     from tendsto_cong[OF this] have "fg \<midarrow>z\<rightarrow>0" by auto
  3467     then show ?thesis unfolding not_essential_def fg_def by auto
  3493     then show ?thesis unfolding not_essential_def fg_def by auto
  3468   qed
  3494   qed
  3469   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"
  3495   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"
  3470   proof -
  3496   proof -
  3471     obtain fn fp fr where [simp]:"fp z \<noteq> 0" and "fr > 0"
  3497     obtain fn fp fr where [simp]:"fp z \<noteq> 0" and "fr > 0"
  3472           and fr: "fp holomorphic_on cball z fr" 
  3498           and fr: "fp holomorphic_on cball z fr"
  3473                   "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w - z) powr of_int fn \<and> fp w \<noteq> 0"
  3499                   "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w - z) powr of_int fn \<and> fp w \<noteq> 0"
  3474       using holomorphic_factor_puncture[OF f_iso f_ness f_nconst,THEN ex1_implies_ex] by auto
  3500       using holomorphic_factor_puncture[OF f_iso f_ness f_nconst,THEN ex1_implies_ex] by auto
  3475     obtain gn gp gr where [simp]:"gp z \<noteq> 0" and "gr > 0"
  3501     obtain gn gp gr where [simp]:"gp z \<noteq> 0" and "gr > 0"
  3476           and gr: "gp holomorphic_on cball z gr" 
  3502           and gr: "gp holomorphic_on cball z gr"
  3477                   "\<forall>w\<in>cball z gr - {z}. g w = gp w * (w - z) powr of_int gn \<and> gp w \<noteq> 0"
  3503                   "\<forall>w\<in>cball z gr - {z}. g w = gp w * (w - z) powr of_int gn \<and> gp w \<noteq> 0"
  3478       using holomorphic_factor_puncture[OF g_iso g_ness g_nconst,THEN ex1_implies_ex] by auto
  3504       using holomorphic_factor_puncture[OF g_iso g_ness g_nconst,THEN ex1_implies_ex] by auto
  3479   
  3505 
  3480     define r1 where "r1=(min fr gr)"
  3506     define r1 where "r1=(min fr gr)"
  3481     have "r1>0" unfolding r1_def using  \<open>fr>0\<close> \<open>gr>0\<close> by auto
  3507     have "r1>0" unfolding r1_def using  \<open>fr>0\<close> \<open>gr>0\<close> by auto
  3482     have fg_times:"fg w = (fp w * gp w) * (w - z) powr (of_int (fn+gn))" and fgp_nz:"fp w*gp w\<noteq>0"
  3508     have fg_times:"fg w = (fp w * gp w) * (w - z) powr (of_int (fn+gn))" and fgp_nz:"fp w*gp w\<noteq>0"
  3483       when "w\<in>ball z r1 - {z}" for w
  3509       when "w\<in>ball z r1 - {z}" for w
  3484     proof -
  3510     proof -
  3490         unfolding fg_def by (auto simp add:powr_add)
  3516         unfolding fg_def by (auto simp add:powr_add)
  3491     qed
  3517     qed
  3492 
  3518 
  3493     have [intro]: "fp \<midarrow>z\<rightarrow>fp z" "gp \<midarrow>z\<rightarrow>gp z"
  3519     have [intro]: "fp \<midarrow>z\<rightarrow>fp z" "gp \<midarrow>z\<rightarrow>gp z"
  3494         using fr(1) \<open>fr>0\<close> gr(1) \<open>gr>0\<close>
  3520         using fr(1) \<open>fr>0\<close> gr(1) \<open>gr>0\<close>
  3495         by (meson open_ball ball_subset_cball centre_in_ball 
  3521         by (meson open_ball ball_subset_cball centre_in_ball
  3496             continuous_on_eq_continuous_at continuous_within holomorphic_on_imp_continuous_on 
  3522             continuous_on_eq_continuous_at continuous_within holomorphic_on_imp_continuous_on
  3497             holomorphic_on_subset)+
  3523             holomorphic_on_subset)+
  3498     have ?thesis when "fn+gn>0" 
  3524     have ?thesis when "fn+gn>0"
  3499     proof -
  3525     proof -
  3500       have "(\<lambda>w. (fp w * gp w) * (w - z) ^ (nat (fn+gn))) \<midarrow>z\<rightarrow>0" 
  3526       have "(\<lambda>w. (fp w * gp w) * (w - z) ^ (nat (fn+gn))) \<midarrow>z\<rightarrow>0"
  3501         using that by (auto intro!:tendsto_eq_intros)
  3527         using that by (auto intro!:tendsto_eq_intros)
  3502       then have "fg \<midarrow>z\<rightarrow> 0"
  3528       then have "fg \<midarrow>z\<rightarrow> 0"
  3503         apply (elim Lim_transform_within[OF _ \<open>r1>0\<close>])
  3529         apply (elim Lim_transform_within[OF _ \<open>r1>0\<close>])
  3504         by (metis (no_types, hide_lams) Diff_iff cball_trivial dist_commute dist_self 
  3530         by (metis (no_types, hide_lams) Diff_iff cball_trivial dist_commute dist_self
  3505               eq_iff_diff_eq_0 fg_times less_le linorder_not_le mem_ball mem_cball powr_of_int 
  3531               eq_iff_diff_eq_0 fg_times less_le linorder_not_le mem_ball mem_cball powr_of_int
  3506               that)
  3532               that)
  3507       then show ?thesis unfolding not_essential_def fg_def by auto
  3533       then show ?thesis unfolding not_essential_def fg_def by auto
  3508     qed
  3534     qed
  3509     moreover have ?thesis when "fn+gn=0" 
  3535     moreover have ?thesis when "fn+gn=0"
  3510     proof -
  3536     proof -
  3511       have "(\<lambda>w. fp w * gp w) \<midarrow>z\<rightarrow>fp z*gp z" 
  3537       have "(\<lambda>w. fp w * gp w) \<midarrow>z\<rightarrow>fp z*gp z"
  3512         using that by (auto intro!:tendsto_eq_intros)
  3538         using that by (auto intro!:tendsto_eq_intros)
  3513       then have "fg \<midarrow>z\<rightarrow> fp z*gp z"
  3539       then have "fg \<midarrow>z\<rightarrow> fp z*gp z"
  3514         apply (elim Lim_transform_within[OF _ \<open>r1>0\<close>])
  3540         apply (elim Lim_transform_within[OF _ \<open>r1>0\<close>])
  3515         apply (subst fg_times)
  3541         apply (subst fg_times)
  3516         by (auto simp add:dist_commute that)
  3542         by (auto simp add:dist_commute that)
  3517       then show ?thesis unfolding not_essential_def fg_def by auto
  3543       then show ?thesis unfolding not_essential_def fg_def by auto
  3518     qed
  3544     qed
  3519     moreover have ?thesis when "fn+gn<0" 
  3545     moreover have ?thesis when "fn+gn<0"
  3520     proof -
  3546     proof -
  3521       have "LIM w (at z). fp w * gp w / (w-z)^nat (-(fn+gn)) :> at_infinity"
  3547       have "LIM w (at z). fp w * gp w / (w-z)^nat (-(fn+gn)) :> at_infinity"
  3522         apply (rule filterlim_divide_at_infinity)
  3548         apply (rule filterlim_divide_at_infinity)
  3523         apply (insert that, auto intro!:tendsto_eq_intros filterlim_atI)
  3549         apply (insert that, auto intro!:tendsto_eq_intros filterlim_atI)
  3524         using eventually_at_topological by blast
  3550         using eventually_at_topological by blast
  3540   shows "not_essential (\<lambda>w. inverse (f w)) z"
  3566   shows "not_essential (\<lambda>w. inverse (f w)) z"
  3541 proof -
  3567 proof -
  3542   define vf where "vf = (\<lambda>w. inverse (f w))"
  3568   define vf where "vf = (\<lambda>w. inverse (f w))"
  3543   have ?thesis when "\<not>(\<exists>\<^sub>Fw in (at z). f w\<noteq>0)"
  3569   have ?thesis when "\<not>(\<exists>\<^sub>Fw in (at z). f w\<noteq>0)"
  3544   proof -
  3570   proof -
  3545     have "\<forall>\<^sub>Fw in (at z). f w=0" 
  3571     have "\<forall>\<^sub>Fw in (at z). f w=0"
  3546       using that[unfolded frequently_def, simplified] by (auto elim: eventually_rev_mp)
  3572       using that[unfolded frequently_def, simplified] by (auto elim: eventually_rev_mp)
  3547     then have "\<forall>\<^sub>Fw in (at z). vf w=0"
  3573     then have "\<forall>\<^sub>Fw in (at z). vf w=0"
  3548       unfolding vf_def by auto
  3574       unfolding vf_def by auto
  3549     from tendsto_cong[OF this] have "vf \<midarrow>z\<rightarrow>0" unfolding vf_def by auto
  3575     from tendsto_cong[OF this] have "vf \<midarrow>z\<rightarrow>0" unfolding vf_def by auto
  3550     then show ?thesis unfolding not_essential_def vf_def by auto
  3576     then show ?thesis unfolding not_essential_def vf_def by auto
  3586   shows "isolated_singularity_at (\<lambda>w. inverse (f w)) z"
  3612   shows "isolated_singularity_at (\<lambda>w. inverse (f w)) z"
  3587 proof -
  3613 proof -
  3588   define vf where "vf = (\<lambda>w. inverse (f w))"
  3614   define vf where "vf = (\<lambda>w. inverse (f w))"
  3589   have ?thesis when "\<not>(\<exists>\<^sub>Fw in (at z). f w\<noteq>0)"
  3615   have ?thesis when "\<not>(\<exists>\<^sub>Fw in (at z). f w\<noteq>0)"
  3590   proof -
  3616   proof -
  3591     have "\<forall>\<^sub>Fw in (at z). f w=0" 
  3617     have "\<forall>\<^sub>Fw in (at z). f w=0"
  3592       using that[unfolded frequently_def, simplified] by (auto elim: eventually_rev_mp)
  3618       using that[unfolded frequently_def, simplified] by (auto elim: eventually_rev_mp)
  3593     then have "\<forall>\<^sub>Fw in (at z). vf w=0"
  3619     then have "\<forall>\<^sub>Fw in (at z). vf w=0"
  3594       unfolding vf_def by auto
  3620       unfolding vf_def by auto
  3595     then obtain d1 where "d1>0" and d1:"\<forall>x. x \<noteq> z \<and> dist x z < d1 \<longrightarrow> vf x = 0"
  3621     then obtain d1 where "d1>0" and d1:"\<forall>x. x \<noteq> z \<and> dist x z < d1 \<longrightarrow> vf x = 0"
  3596       unfolding eventually_at by auto
  3622       unfolding eventually_at by auto
  3630     apply (rule not_essential_times[where g="\<lambda>w. inverse (g w)"])
  3656     apply (rule not_essential_times[where g="\<lambda>w. inverse (g w)"])
  3631     using assms by (auto intro: isolated_singularity_at_inverse not_essential_inverse)
  3657     using assms by (auto intro: isolated_singularity_at_inverse not_essential_inverse)
  3632   then show ?thesis by (simp add:field_simps)
  3658   then show ?thesis by (simp add:field_simps)
  3633 qed
  3659 qed
  3634 
  3660 
  3635 lemma 
  3661 lemma
  3636   assumes f_iso:"isolated_singularity_at f z"
  3662   assumes f_iso:"isolated_singularity_at f z"
  3637       and g_iso:"isolated_singularity_at g z"
  3663       and g_iso:"isolated_singularity_at g z"
  3638     shows isolated_singularity_at_times[singularity_intros]:
  3664     shows isolated_singularity_at_times[singularity_intros]:
  3639               "isolated_singularity_at (\<lambda>w. f w * g w) z" and
  3665               "isolated_singularity_at (\<lambda>w. f w * g w) z" and
  3640           isolated_singularity_at_add[singularity_intros]:
  3666           isolated_singularity_at_add[singularity_intros]:
  3641               "isolated_singularity_at (\<lambda>w. f w + g w) z"
  3667               "isolated_singularity_at (\<lambda>w. f w + g w) z"
  3642 proof -
  3668 proof -
  3643   obtain d1 d2 where "d1>0" "d2>0" 
  3669   obtain d1 d2 where "d1>0" "d2>0"
  3644       and d1:"f analytic_on ball z d1 - {z}" and d2:"g analytic_on ball z d2 - {z}"
  3670       and d1:"f analytic_on ball z d1 - {z}" and d2:"g analytic_on ball z d2 - {z}"
  3645     using f_iso g_iso unfolding isolated_singularity_at_def by auto
  3671     using f_iso g_iso unfolding isolated_singularity_at_def by auto
  3646   define d3 where "d3=min d1 d2"
  3672   define d3 where "d3=min d1 d2"
  3647   have "d3>0" unfolding d3_def using \<open>d1>0\<close> \<open>d2>0\<close> by auto
  3673   have "d3>0" unfolding d3_def using \<open>d1>0\<close> \<open>d2>0\<close> by auto
  3648   
  3674 
  3649   have "(\<lambda>w. f w * g w) analytic_on ball z d3 - {z}"
  3675   have "(\<lambda>w. f w * g w) analytic_on ball z d3 - {z}"
  3650     apply (rule analytic_on_mult)
  3676     apply (rule analytic_on_mult)
  3651     using d1 d2 unfolding d3_def by (auto elim:analytic_on_subset)
  3677     using d1 d2 unfolding d3_def by (auto elim:analytic_on_subset)
  3652   then show "isolated_singularity_at (\<lambda>w. f w * g w) z" 
  3678   then show "isolated_singularity_at (\<lambda>w. f w * g w) z"
  3653     using \<open>d3>0\<close> unfolding isolated_singularity_at_def by auto
  3679     using \<open>d3>0\<close> unfolding isolated_singularity_at_def by auto
  3654   have "(\<lambda>w. f w + g w) analytic_on ball z d3 - {z}"
  3680   have "(\<lambda>w. f w + g w) analytic_on ball z d3 - {z}"
  3655     apply (rule analytic_on_add)
  3681     apply (rule analytic_on_add)
  3656     using d1 d2 unfolding d3_def by (auto elim:analytic_on_subset)
  3682     using d1 d2 unfolding d3_def by (auto elim:analytic_on_subset)
  3657   then show "isolated_singularity_at (\<lambda>w. f w + g w) z" 
  3683   then show "isolated_singularity_at (\<lambda>w. f w + g w) z"
  3658     using \<open>d3>0\<close> unfolding isolated_singularity_at_def by auto
  3684     using \<open>d3>0\<close> unfolding isolated_singularity_at_def by auto
  3659 qed
  3685 qed
  3660 
  3686 
  3661 lemma isolated_singularity_at_uminus[singularity_intros]:
  3687 lemma isolated_singularity_at_uminus[singularity_intros]:
  3662   assumes f_iso:"isolated_singularity_at f z"
  3688   assumes f_iso:"isolated_singularity_at f z"
  3687   unfolding isolated_singularity_at_def by (simp add: gt_ex)
  3713   unfolding isolated_singularity_at_def by (simp add: gt_ex)
  3688 
  3714 
  3689 lemma isolated_singularity_at_holomorphic:
  3715 lemma isolated_singularity_at_holomorphic:
  3690   assumes "f holomorphic_on s-{z}" "open s" "z\<in>s"
  3716   assumes "f holomorphic_on s-{z}" "open s" "z\<in>s"
  3691   shows "isolated_singularity_at f z"
  3717   shows "isolated_singularity_at f z"
  3692   using assms unfolding isolated_singularity_at_def 
  3718   using assms unfolding isolated_singularity_at_def
  3693   by (metis analytic_on_holomorphic centre_in_ball insert_Diff openE open_delete subset_insert_iff)
  3719   by (metis analytic_on_holomorphic centre_in_ball insert_Diff openE open_delete subset_insert_iff)
  3694 
  3720 
  3695 subsubsection \<open>The order of non-essential singularities (i.e. removable singularities or poles)\<close>
  3721 subsubsection \<open>The order of non-essential singularities (i.e. removable singularities or poles)\<close>
  3696 
  3722 
  3697 
  3723 
  3707                    \<and> h w \<noteq>0))"
  3733                    \<and> h w \<noteq>0))"
  3708 
  3734 
  3709 lemma zorder_exist:
  3735 lemma zorder_exist:
  3710   fixes f::"complex \<Rightarrow> complex" and z::complex
  3736   fixes f::"complex \<Rightarrow> complex" and z::complex
  3711   defines "n\<equiv>zorder f z" and "g\<equiv>zor_poly f z"
  3737   defines "n\<equiv>zorder f z" and "g\<equiv>zor_poly f z"
  3712   assumes f_iso:"isolated_singularity_at f z" 
  3738   assumes f_iso:"isolated_singularity_at f z"
  3713       and f_ness:"not_essential f z" 
  3739       and f_ness:"not_essential f z"
  3714       and f_nconst:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
  3740       and f_nconst:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
  3715   shows "g z\<noteq>0 \<and> (\<exists>r. r>0 \<and> g holomorphic_on cball z r
  3741   shows "g z\<noteq>0 \<and> (\<exists>r. r>0 \<and> g holomorphic_on cball z r
  3716     \<and> (\<forall>w\<in>cball z r - {z}. f w  = g w * (w-z) powr n  \<and> g w \<noteq>0))"
  3742     \<and> (\<forall>w\<in>cball z r - {z}. f w  = g w * (w-z) powr n  \<and> g w \<noteq>0))"
  3717 proof -
  3743 proof -
  3718   define P where "P = (\<lambda>n g r. 0 < r \<and> g holomorphic_on cball z r \<and> g z\<noteq>0
  3744   define P where "P = (\<lambda>n g r. 0 < r \<and> g holomorphic_on cball z r \<and> g z\<noteq>0
  3719           \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w-z) powr (of_int n) \<and> g w\<noteq>0))"
  3745           \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w-z) powr (of_int n) \<and> g w\<noteq>0))"
  3720   have "\<exists>!n. \<exists>g r. P n g r" 
  3746   have "\<exists>!n. \<exists>g r. P n g r"
  3721     using holomorphic_factor_puncture[OF assms(3-)] unfolding P_def by auto
  3747     using holomorphic_factor_puncture[OF assms(3-)] unfolding P_def by auto
  3722   then have "\<exists>g r. P n g r"
  3748   then have "\<exists>g r. P n g r"
  3723     unfolding n_def P_def zorder_def
  3749     unfolding n_def P_def zorder_def
  3724     by (drule_tac theI',argo)
  3750     by (drule_tac theI',argo)
  3725   then have "\<exists>r. P n g r"
  3751   then have "\<exists>r. P n g r"
  3727     by (drule_tac someI_ex,argo)
  3753     by (drule_tac someI_ex,argo)
  3728   then obtain r1 where "P n g r1" by auto
  3754   then obtain r1 where "P n g r1" by auto
  3729   then show ?thesis unfolding P_def by auto
  3755   then show ?thesis unfolding P_def by auto
  3730 qed
  3756 qed
  3731 
  3757 
  3732 lemma 
  3758 lemma
  3733   fixes f::"complex \<Rightarrow> complex" and z::complex
  3759   fixes f::"complex \<Rightarrow> complex" and z::complex
  3734   assumes f_iso:"isolated_singularity_at f z" 
  3760   assumes f_iso:"isolated_singularity_at f z"
  3735       and f_ness:"not_essential f z"  
  3761       and f_ness:"not_essential f z"
  3736       and f_nconst:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
  3762       and f_nconst:"\<exists>\<^sub>Fw in (at z). f w\<noteq>0"
  3737     shows zorder_inverse: "zorder (\<lambda>w. inverse (f w)) z = - zorder f z"
  3763     shows zorder_inverse: "zorder (\<lambda>w. inverse (f w)) z = - zorder f z"
  3738       and zor_poly_inverse: "\<forall>\<^sub>Fw in (at z). zor_poly (\<lambda>w. inverse (f w)) z w 
  3764       and zor_poly_inverse: "\<forall>\<^sub>Fw in (at z). zor_poly (\<lambda>w. inverse (f w)) z w
  3739                                                 = inverse (zor_poly f z w)"
  3765                                                 = inverse (zor_poly f z w)"
  3740 proof -
  3766 proof -
  3741   define vf where "vf = (\<lambda>w. inverse (f w))"
  3767   define vf where "vf = (\<lambda>w. inverse (f w))"
  3742   define fn vfn where 
  3768   define fn vfn where
  3743     "fn = zorder f z"  and "vfn = zorder vf z"
  3769     "fn = zorder f z"  and "vfn = zorder vf z"
  3744   define fp vfp where 
  3770   define fp vfp where
  3745     "fp = zor_poly f z" and "vfp = zor_poly vf z"
  3771     "fp = zor_poly f z" and "vfp = zor_poly vf z"
  3746 
  3772 
  3747   obtain fr where [simp]:"fp z \<noteq> 0" and "fr > 0"
  3773   obtain fr where [simp]:"fp z \<noteq> 0" and "fr > 0"
  3748           and fr: "fp holomorphic_on cball z fr" 
  3774           and fr: "fp holomorphic_on cball z fr"
  3749                   "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w - z) powr of_int fn \<and> fp w \<noteq> 0"
  3775                   "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w - z) powr of_int fn \<and> fp w \<noteq> 0"
  3750     using zorder_exist[OF f_iso f_ness f_nconst,folded fn_def fp_def]
  3776     using zorder_exist[OF f_iso f_ness f_nconst,folded fn_def fp_def]
  3751     by auto
  3777     by auto
  3752   have fr_inverse: "vf w = (inverse (fp w)) * (w - z) powr (of_int (-fn))" 
  3778   have fr_inverse: "vf w = (inverse (fp w)) * (w - z) powr (of_int (-fn))"
  3753         and fr_nz: "inverse (fp w)\<noteq>0"
  3779         and fr_nz: "inverse (fp w)\<noteq>0"
  3754     when "w\<in>ball z fr - {z}" for w
  3780     when "w\<in>ball z fr - {z}" for w
  3755   proof -
  3781   proof -
  3756     have "f w = fp w * (w - z) powr of_int fn" "fp w\<noteq>0"
  3782     have "f w = fp w * (w - z) powr of_int fn" "fp w\<noteq>0"
  3757       using fr(2)[rule_format,of w] that by auto
  3783       using fr(2)[rule_format,of w] that by auto
  3758     then show "vf w = (inverse (fp w)) * (w - z) powr (of_int (-fn))" "inverse (fp w)\<noteq>0"
  3784     then show "vf w = (inverse (fp w)) * (w - z) powr (of_int (-fn))" "inverse (fp w)\<noteq>0"
  3759       unfolding vf_def by (auto simp add:powr_minus)
  3785       unfolding vf_def by (auto simp add:powr_minus)
  3760   qed
  3786   qed
  3761   obtain vfr where [simp]:"vfp z \<noteq> 0" and "vfr>0" and vfr:"vfp holomorphic_on cball z vfr" 
  3787   obtain vfr where [simp]:"vfp z \<noteq> 0" and "vfr>0" and vfr:"vfp holomorphic_on cball z vfr"
  3762       "(\<forall>w\<in>cball z vfr - {z}. vf w = vfp w * (w - z) powr of_int vfn \<and> vfp w \<noteq> 0)"
  3788       "(\<forall>w\<in>cball z vfr - {z}. vf w = vfp w * (w - z) powr of_int vfn \<and> vfp w \<noteq> 0)"
  3763   proof -
  3789   proof -
  3764     have "isolated_singularity_at vf z" 
  3790     have "isolated_singularity_at vf z"
  3765       using isolated_singularity_at_inverse[OF f_iso f_ness] unfolding vf_def . 
  3791       using isolated_singularity_at_inverse[OF f_iso f_ness] unfolding vf_def .
  3766     moreover have "not_essential vf z" 
  3792     moreover have "not_essential vf z"
  3767       using not_essential_inverse[OF f_ness f_iso] unfolding vf_def .
  3793       using not_essential_inverse[OF f_ness f_iso] unfolding vf_def .
  3768     moreover have "\<exists>\<^sub>F w in at z. vf w \<noteq> 0" 
  3794     moreover have "\<exists>\<^sub>F w in at z. vf w \<noteq> 0"
  3769       using f_nconst unfolding vf_def by (auto elim:frequently_elim1)
  3795       using f_nconst unfolding vf_def by (auto elim:frequently_elim1)
  3770     ultimately show ?thesis using zorder_exist[of vf z, folded vfn_def vfp_def] that by auto
  3796     ultimately show ?thesis using zorder_exist[of vf z, folded vfn_def vfp_def] that by auto
  3771   qed
  3797   qed
  3772 
  3798 
  3773 
  3799 
  3780     subgoal by simp
  3806     subgoal by simp
  3781     subgoal
  3807     subgoal
  3782     proof (rule ballI)
  3808     proof (rule ballI)
  3783       fix w assume "w \<in> ball z r1 - {z}"
  3809       fix w assume "w \<in> ball z r1 - {z}"
  3784       then have "w \<in> ball z fr - {z}" "w \<in> cball z vfr - {z}"  unfolding r1_def by auto
  3810       then have "w \<in> ball z fr - {z}" "w \<in> cball z vfr - {z}"  unfolding r1_def by auto
  3785       from fr_inverse[OF this(1)] fr_nz[OF this(1)] vfr(2)[rule_format,OF this(2)] 
  3811       from fr_inverse[OF this(1)] fr_nz[OF this(1)] vfr(2)[rule_format,OF this(2)]
  3786       show "vf w = vfp w * (w - z) powr of_int vfn \<and> vfp w \<noteq> 0 
  3812       show "vf w = vfp w * (w - z) powr of_int vfn \<and> vfp w \<noteq> 0
  3787               \<and> vf w = inverse (fp w) * (w - z) powr of_int (- fn) \<and> inverse (fp w) \<noteq> 0" by auto
  3813               \<and> vf w = inverse (fp w) * (w - z) powr of_int (- fn) \<and> inverse (fp w) \<noteq> 0" by auto
  3788     qed
  3814     qed
  3789     subgoal using vfr(1) unfolding r1_def by (auto intro!:holomorphic_intros) 
  3815     subgoal using vfr(1) unfolding r1_def by (auto intro!:holomorphic_intros)
  3790     subgoal using fr unfolding r1_def by (auto intro!:holomorphic_intros)
  3816     subgoal using fr unfolding r1_def by (auto intro!:holomorphic_intros)
  3791     done
  3817     done
  3792 
  3818 
  3793   have "vfp w = inverse (fp w)" when "w\<in>ball z r1-{z}" for w
  3819   have "vfp w = inverse (fp w)" when "w\<in>ball z r1-{z}" for w
  3794   proof -
  3820   proof -
  3800     unfolding eventually_at using \<open>r1>0\<close>
  3826     unfolding eventually_at using \<open>r1>0\<close>
  3801     apply (rule_tac x=r1 in exI)
  3827     apply (rule_tac x=r1 in exI)
  3802     by (auto simp add:dist_commute)
  3828     by (auto simp add:dist_commute)
  3803 qed
  3829 qed
  3804 
  3830 
  3805 lemma 
  3831 lemma
  3806   fixes f g::"complex \<Rightarrow> complex" and z::complex
  3832   fixes f g::"complex \<Rightarrow> complex" and z::complex
  3807   assumes f_iso:"isolated_singularity_at f z" and g_iso:"isolated_singularity_at g z"  
  3833   assumes f_iso:"isolated_singularity_at f z" and g_iso:"isolated_singularity_at g z"
  3808       and f_ness:"not_essential f z" and g_ness:"not_essential g z" 
  3834       and f_ness:"not_essential f z" and g_ness:"not_essential g z"
  3809       and fg_nconst: "\<exists>\<^sub>Fw in (at z). f w * g w\<noteq> 0"
  3835       and fg_nconst: "\<exists>\<^sub>Fw in (at z). f w * g w\<noteq> 0"
  3810   shows zorder_times:"zorder (\<lambda>w. f w * g w) z = zorder f z + zorder g z" and
  3836   shows zorder_times:"zorder (\<lambda>w. f w * g w) z = zorder f z + zorder g z" and
  3811         zor_poly_times:"\<forall>\<^sub>Fw in (at z). zor_poly (\<lambda>w. f w * g w) z w 
  3837         zor_poly_times:"\<forall>\<^sub>Fw in (at z). zor_poly (\<lambda>w. f w * g w) z w
  3812                                                   = zor_poly f z w *zor_poly g z w"
  3838                                                   = zor_poly f z w *zor_poly g z w"
  3813 proof -
  3839 proof -
  3814   define fg where "fg = (\<lambda>w. f w * g w)"
  3840   define fg where "fg = (\<lambda>w. f w * g w)"
  3815   define fn gn fgn where 
  3841   define fn gn fgn where
  3816     "fn = zorder f z" and "gn = zorder g z" and "fgn = zorder fg z"
  3842     "fn = zorder f z" and "gn = zorder g z" and "fgn = zorder fg z"
  3817   define fp gp fgp where 
  3843   define fp gp fgp where
  3818     "fp = zor_poly f z" and "gp = zor_poly g z" and "fgp = zor_poly fg z"
  3844     "fp = zor_poly f z" and "gp = zor_poly g z" and "fgp = zor_poly fg z"
  3819   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"
  3845   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"
  3820     using fg_nconst by (auto elim!:frequently_elim1)
  3846     using fg_nconst by (auto elim!:frequently_elim1)
  3821   obtain fr where [simp]:"fp z \<noteq> 0" and "fr > 0" 
  3847   obtain fr where [simp]:"fp z \<noteq> 0" and "fr > 0"
  3822           and fr: "fp holomorphic_on cball z fr" 
  3848           and fr: "fp holomorphic_on cball z fr"
  3823                   "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w - z) powr of_int fn \<and> fp w \<noteq> 0"
  3849                   "\<forall>w\<in>cball z fr - {z}. f w = fp w * (w - z) powr of_int fn \<and> fp w \<noteq> 0"
  3824     using zorder_exist[OF f_iso f_ness f_nconst,folded fp_def fn_def] by auto
  3850     using zorder_exist[OF f_iso f_ness f_nconst,folded fp_def fn_def] by auto
  3825   obtain gr where [simp]:"gp z \<noteq> 0" and "gr > 0"  
  3851   obtain gr where [simp]:"gp z \<noteq> 0" and "gr > 0"
  3826           and gr: "gp holomorphic_on cball z gr" 
  3852           and gr: "gp holomorphic_on cball z gr"
  3827                   "\<forall>w\<in>cball z gr - {z}. g w = gp w * (w - z) powr of_int gn \<and> gp w \<noteq> 0"
  3853                   "\<forall>w\<in>cball z gr - {z}. g w = gp w * (w - z) powr of_int gn \<and> gp w \<noteq> 0"
  3828     using zorder_exist[OF g_iso g_ness g_nconst,folded gn_def gp_def] by auto
  3854     using zorder_exist[OF g_iso g_ness g_nconst,folded gn_def gp_def] by auto
  3829   define r1 where "r1=min fr gr"
  3855   define r1 where "r1=min fr gr"
  3830   have "r1>0" unfolding r1_def using \<open>fr>0\<close> \<open>gr>0\<close> by auto
  3856   have "r1>0" unfolding r1_def using \<open>fr>0\<close> \<open>gr>0\<close> by auto
  3831   have fg_times:"fg w = (fp w * gp w) * (w - z) powr (of_int (fn+gn))" and fgp_nz:"fp w*gp w\<noteq>0"
  3857   have fg_times:"fg w = (fp w * gp w) * (w - z) powr (of_int (fn+gn))" and fgp_nz:"fp w*gp w\<noteq>0"
  3838     ultimately show "fg w = (fp w * gp w) * (w - z) powr (of_int (fn+gn))" "fp w*gp w\<noteq>0"
  3864     ultimately show "fg w = (fp w * gp w) * (w - z) powr (of_int (fn+gn))" "fp w*gp w\<noteq>0"
  3839       unfolding fg_def by (auto simp add:powr_add)
  3865       unfolding fg_def by (auto simp add:powr_add)
  3840   qed
  3866   qed
  3841 
  3867 
  3842   obtain fgr where [simp]:"fgp z \<noteq> 0" and "fgr > 0"
  3868   obtain fgr where [simp]:"fgp z \<noteq> 0" and "fgr > 0"
  3843           and fgr: "fgp holomorphic_on cball z fgr" 
  3869           and fgr: "fgp holomorphic_on cball z fgr"
  3844                   "\<forall>w\<in>cball z fgr - {z}. fg w = fgp w * (w - z) powr of_int fgn \<and> fgp w \<noteq> 0"
  3870                   "\<forall>w\<in>cball z fgr - {z}. fg w = fgp w * (w - z) powr of_int fgn \<and> fgp w \<noteq> 0"
  3845   proof -
  3871   proof -
  3846     have "fgp z \<noteq> 0 \<and> (\<exists>r>0. fgp holomorphic_on cball z r 
  3872     have "fgp z \<noteq> 0 \<and> (\<exists>r>0. fgp holomorphic_on cball z r
  3847             \<and> (\<forall>w\<in>cball z r - {z}. fg w = fgp w * (w - z) powr of_int fgn \<and> fgp w \<noteq> 0))"
  3873             \<and> (\<forall>w\<in>cball z r - {z}. fg w = fgp w * (w - z) powr of_int fgn \<and> fgp w \<noteq> 0))"
  3848       apply (rule zorder_exist[of fg z, folded fgn_def fgp_def])
  3874       apply (rule zorder_exist[of fg z, folded fgn_def fgp_def])
  3849       subgoal unfolding fg_def using isolated_singularity_at_times[OF f_iso g_iso] .
  3875       subgoal unfolding fg_def using isolated_singularity_at_times[OF f_iso g_iso] .
  3850       subgoal unfolding fg_def using not_essential_times[OF f_ness g_ness f_iso g_iso] .
  3876       subgoal unfolding fg_def using not_essential_times[OF f_ness g_ness f_iso g_iso] .
  3851       subgoal unfolding fg_def using fg_nconst .
  3877       subgoal unfolding fg_def using fg_nconst .
  3861     subgoal by simp
  3887     subgoal by simp
  3862     subgoal
  3888     subgoal
  3863     proof (rule ballI)
  3889     proof (rule ballI)
  3864       fix w assume "w \<in> ball z r2 - {z}"
  3890       fix w assume "w \<in> ball z r2 - {z}"
  3865       then have "w \<in> ball z r1 - {z}" "w \<in> cball z fgr - {z}"  unfolding r2_def by auto
  3891       then have "w \<in> ball z r1 - {z}" "w \<in> cball z fgr - {z}"  unfolding r2_def by auto
  3866       from fg_times[OF this(1)] fgp_nz[OF this(1)] fgr(2)[rule_format,OF this(2)] 
  3892       from fg_times[OF this(1)] fgp_nz[OF this(1)] fgr(2)[rule_format,OF this(2)]
  3867       show "fg w = fgp w * (w - z) powr of_int fgn \<and> fgp w \<noteq> 0 
  3893       show "fg w = fgp w * (w - z) powr of_int fgn \<and> fgp w \<noteq> 0
  3868               \<and> fg w = fp w * gp w * (w - z) powr of_int (fn + gn) \<and> fp w * gp w \<noteq> 0" by auto
  3894               \<and> fg w = fp w * gp w * (w - z) powr of_int (fn + gn) \<and> fp w * gp w \<noteq> 0" by auto
  3869     qed
  3895     qed
  3870     subgoal using fgr(1) unfolding r2_def r1_def by (auto intro!:holomorphic_intros) 
  3896     subgoal using fgr(1) unfolding r2_def r1_def by (auto intro!:holomorphic_intros)
  3871     subgoal using fr(1) gr(1) unfolding r2_def r1_def by (auto intro!:holomorphic_intros)
  3897     subgoal using fr(1) gr(1) unfolding r2_def r1_def by (auto intro!:holomorphic_intros)
  3872     done
  3898     done
  3873 
  3899 
  3874   have "fgp w = fp w *gp w" when "w\<in>ball z r2-{z}" for w
  3900   have "fgp w = fp w *gp w" when "w\<in>ball z r2-{z}" for w
  3875   proof -
  3901   proof -
  3876     have "w \<in> ball z r1 - {z}" "w \<in> cball z fgr - {z}" "w\<noteq>z" using that  unfolding r2_def by auto
  3902     have "w \<in> ball z r1 - {z}" "w \<in> cball z fgr - {z}" "w\<noteq>z" using that  unfolding r2_def by auto
  3877     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>
  3903     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>
  3878     show ?thesis by auto
  3904     show ?thesis by auto
  3879   qed
  3905   qed
  3880   then show "\<forall>\<^sub>Fw in (at z). fgp w = fp w * gp w" 
  3906   then show "\<forall>\<^sub>Fw in (at z). fgp w = fp w * gp w"
  3881     using \<open>r2>0\<close> unfolding eventually_at by (auto simp add:dist_commute)
  3907     using \<open>r2>0\<close> unfolding eventually_at by (auto simp add:dist_commute)
  3882 qed
  3908 qed
  3883 
  3909 
  3884 lemma 
  3910 lemma
  3885   fixes f g::"complex \<Rightarrow> complex" and z::complex
  3911   fixes f g::"complex \<Rightarrow> complex" and z::complex
  3886   assumes f_iso:"isolated_singularity_at f z" and g_iso:"isolated_singularity_at g z"  
  3912   assumes f_iso:"isolated_singularity_at f z" and g_iso:"isolated_singularity_at g z"
  3887       and f_ness:"not_essential f z" and g_ness:"not_essential g z" 
  3913       and f_ness:"not_essential f z" and g_ness:"not_essential g z"
  3888       and fg_nconst: "\<exists>\<^sub>Fw in (at z). f w * g w\<noteq> 0"
  3914       and fg_nconst: "\<exists>\<^sub>Fw in (at z). f w * g w\<noteq> 0"
  3889   shows zorder_divide:"zorder (\<lambda>w. f w / g w) z = zorder f z - zorder g z" and
  3915   shows zorder_divide:"zorder (\<lambda>w. f w / g w) z = zorder f z - zorder g z" and
  3890         zor_poly_divide:"\<forall>\<^sub>Fw in (at z). zor_poly (\<lambda>w. f w / g w) z w 
  3916         zor_poly_divide:"\<forall>\<^sub>Fw in (at z). zor_poly (\<lambda>w. f w / g w) z w
  3891                                                   = zor_poly f z w  / zor_poly g z w"
  3917                                                   = zor_poly f z w  / zor_poly g z w"
  3892 proof -
  3918 proof -
  3893   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"
  3919   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"
  3894     using fg_nconst by (auto elim!:frequently_elim1)
  3920     using fg_nconst by (auto elim!:frequently_elim1)
  3895   define vg where "vg=(\<lambda>w. inverse (g w))"
  3921   define vg where "vg=(\<lambda>w. inverse (g w))"
  3898     subgoal unfolding vg_def using isolated_singularity_at_inverse[OF g_iso g_ness] .
  3924     subgoal unfolding vg_def using isolated_singularity_at_inverse[OF g_iso g_ness] .
  3899     subgoal unfolding vg_def using not_essential_inverse[OF g_ness g_iso] .
  3925     subgoal unfolding vg_def using not_essential_inverse[OF g_ness g_iso] .
  3900     subgoal unfolding vg_def using fg_nconst by (auto elim!:frequently_elim1)
  3926     subgoal unfolding vg_def using fg_nconst by (auto elim!:frequently_elim1)
  3901     done
  3927     done
  3902   then show "zorder (\<lambda>w. f w / g w) z = zorder f z - zorder g z"
  3928   then show "zorder (\<lambda>w. f w / g w) z = zorder f z - zorder g z"
  3903     using zorder_inverse[OF g_iso g_ness g_nconst,folded vg_def] unfolding vg_def 
  3929     using zorder_inverse[OF g_iso g_ness g_nconst,folded vg_def] unfolding vg_def
  3904     by (auto simp add:field_simps)
  3930     by (auto simp add:field_simps)
  3905 
  3931 
  3906   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"
  3932   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"
  3907     apply (rule zor_poly_times[OF f_iso _ f_ness,of vg])
  3933     apply (rule zor_poly_times[OF f_iso _ f_ness,of vg])
  3908     subgoal unfolding vg_def using isolated_singularity_at_inverse[OF g_iso g_ness] .
  3934     subgoal unfolding vg_def using isolated_singularity_at_inverse[OF g_iso g_ness] .
  3916 qed
  3942 qed
  3917 
  3943 
  3918 lemma zorder_exist_zero:
  3944 lemma zorder_exist_zero:
  3919   fixes f::"complex \<Rightarrow> complex" and z::complex
  3945   fixes f::"complex \<Rightarrow> complex" and z::complex
  3920   defines "n\<equiv>zorder f z" and "g\<equiv>zor_poly f z"
  3946   defines "n\<equiv>zorder f z" and "g\<equiv>zor_poly f z"
  3921   assumes  holo: "f holomorphic_on s" and 
  3947   assumes  holo: "f holomorphic_on s" and
  3922           "open s" "connected s" "z\<in>s"
  3948           "open s" "connected s" "z\<in>s"
  3923       and non_const: "\<exists>w\<in>s. f w \<noteq> 0"
  3949       and non_const: "\<exists>w\<in>s. f w \<noteq> 0"
  3924   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
  3950   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
  3925     \<and> (\<forall>w\<in>cball z r. f w  = g w * (w-z) ^ nat n  \<and> g w \<noteq>0))"
  3951     \<and> (\<forall>w\<in>cball z r. f w  = g w * (w-z) ^ nat n  \<and> g w \<noteq>0))"
  3926 proof -
  3952 proof -
  3927   obtain r where "g z \<noteq> 0" and r: "r>0" "cball z r \<subseteq> s" "g holomorphic_on cball z r" 
  3953   obtain r where "g z \<noteq> 0" and r: "r>0" "cball z r \<subseteq> s" "g holomorphic_on cball z r"
  3928             "(\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0)"
  3954             "(\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0)"
  3929   proof -
  3955   proof -
  3930     have "g z \<noteq> 0 \<and> (\<exists>r>0. g holomorphic_on cball z r 
  3956     have "g z \<noteq> 0 \<and> (\<exists>r>0. g holomorphic_on cball z r
  3931             \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0))"
  3957             \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0))"
  3932     proof (rule zorder_exist[of f z,folded g_def n_def])
  3958     proof (rule zorder_exist[of f z,folded g_def n_def])
  3933       show "isolated_singularity_at f z" unfolding isolated_singularity_at_def
  3959       show "isolated_singularity_at f z" unfolding isolated_singularity_at_def
  3934         using holo assms(4,6)
  3960         using holo assms(4,6)
  3935         by (meson Diff_subset open_ball analytic_on_holomorphic holomorphic_on_subset openE)
  3961         by (meson Diff_subset open_ball analytic_on_holomorphic holomorphic_on_subset openE)
  3936       show "not_essential f z" unfolding not_essential_def 
  3962       show "not_essential f z" unfolding not_essential_def
  3937         using assms(4,6) at_within_open continuous_on holo holomorphic_on_imp_continuous_on 
  3963         using assms(4,6) at_within_open continuous_on holo holomorphic_on_imp_continuous_on
  3938         by fastforce
  3964         by fastforce
  3939       have "\<forall>\<^sub>F w in at z. f w \<noteq> 0 \<and> w\<in>s"
  3965       have "\<forall>\<^sub>F w in at z. f w \<noteq> 0 \<and> w\<in>s"
  3940       proof -
  3966       proof -
  3941         obtain w where "w\<in>s" "f w\<noteq>0" using non_const by auto
  3967         obtain w where "w\<in>s" "f w\<noteq>0" using non_const by auto
  3942         then show ?thesis 
  3968         then show ?thesis
  3943           by (rule non_zero_neighbour_alt[OF holo \<open>open s\<close> \<open>connected s\<close> \<open>z\<in>s\<close>])
  3969           by (rule non_zero_neighbour_alt[OF holo \<open>open s\<close> \<open>connected s\<close> \<open>z\<in>s\<close>])
  3944       qed
  3970       qed
  3945       then show "\<exists>\<^sub>F w in at z. f w \<noteq> 0"
  3971       then show "\<exists>\<^sub>F w in at z. f w \<noteq> 0"
  3946         apply (elim eventually_frequentlyE)
  3972         apply (elim eventually_frequentlyE)
  3947         by auto
  3973         by auto
  3948     qed
  3974     qed
  3949     then obtain r1 where "g z \<noteq> 0" "r1>0" and r1:"g holomorphic_on cball z r1"
  3975     then obtain r1 where "g z \<noteq> 0" "r1>0" and r1:"g holomorphic_on cball z r1"
  3950             "(\<forall>w\<in>cball z r1 - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0)"
  3976             "(\<forall>w\<in>cball z r1 - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0)"
  3951       by auto
  3977       by auto
  3952     obtain r2 where r2: "r2>0" "cball z r2 \<subseteq> s" 
  3978     obtain r2 where r2: "r2>0" "cball z r2 \<subseteq> s"
  3953       using assms(4,6) open_contains_cball_eq by blast
  3979       using assms(4,6) open_contains_cball_eq by blast
  3954     define r3 where "r3=min r1 r2"
  3980     define r3 where "r3=min r1 r2"
  3955     have "r3>0" "cball z r3 \<subseteq> s" using \<open>r1>0\<close> r2 unfolding r3_def by auto
  3981     have "r3>0" "cball z r3 \<subseteq> s" using \<open>r1>0\<close> r2 unfolding r3_def by auto
  3956     moreover have "g holomorphic_on cball z r3" 
  3982     moreover have "g holomorphic_on cball z r3"
  3957       using r1(1) unfolding r3_def by auto
  3983       using r1(1) unfolding r3_def by auto
  3958     moreover have "(\<forall>w\<in>cball z r3 - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0)" 
  3984     moreover have "(\<forall>w\<in>cball z r3 - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0)"
  3959       using r1(2) unfolding r3_def by auto
  3985       using r1(2) unfolding r3_def by auto
  3960     ultimately show ?thesis using that[of r3] \<open>g z\<noteq>0\<close> by auto 
  3986     ultimately show ?thesis using that[of r3] \<open>g z\<noteq>0\<close> by auto
  3961   qed
  3987   qed
  3962 
  3988 
  3963   have if_0:"if f z=0 then n > 0 else n=0" 
  3989   have if_0:"if f z=0 then n > 0 else n=0"
  3964   proof -
  3990   proof -
  3965     have "f\<midarrow> z \<rightarrow> f z"
  3991     have "f\<midarrow> z \<rightarrow> f z"
  3966       by (metis assms(4,6,7) at_within_open continuous_on holo holomorphic_on_imp_continuous_on)
  3992       by (metis assms(4,6,7) at_within_open continuous_on holo holomorphic_on_imp_continuous_on)
  3967     then have "(\<lambda>w. g w * (w - z) powr of_int n) \<midarrow>z\<rightarrow> f z"
  3993     then have "(\<lambda>w. g w * (w - z) powr of_int n) \<midarrow>z\<rightarrow> f z"
  3968       apply (elim Lim_transform_within_open[where s="ball z r"])
  3994       apply (elim Lim_transform_within_open[where s="ball z r"])
  3969       using r by auto
  3995       using r by auto
  3970     moreover have "g \<midarrow>z\<rightarrow>g z"
  3996     moreover have "g \<midarrow>z\<rightarrow>g z"
  3971       by (metis (mono_tags, lifting) open_ball at_within_open_subset 
  3997       by (metis (mono_tags, lifting) open_ball at_within_open_subset
  3972           ball_subset_cball centre_in_ball continuous_on holomorphic_on_imp_continuous_on r(1,3) subsetCE)
  3998           ball_subset_cball centre_in_ball continuous_on holomorphic_on_imp_continuous_on r(1,3) subsetCE)
  3973     ultimately have "(\<lambda>w. (g w * (w - z) powr of_int n) / g w) \<midarrow>z\<rightarrow> f z/g z"
  3999     ultimately have "(\<lambda>w. (g w * (w - z) powr of_int n) / g w) \<midarrow>z\<rightarrow> f z/g z"
  3974       apply (rule_tac tendsto_divide)
  4000       apply (rule_tac tendsto_divide)
  3975       using \<open>g z\<noteq>0\<close> by auto
  4001       using \<open>g z\<noteq>0\<close> by auto
  3976     then have powr_tendsto:"(\<lambda>w. (w - z) powr of_int n) \<midarrow>z\<rightarrow> f z/g z"
  4002     then have powr_tendsto:"(\<lambda>w. (w - z) powr of_int n) \<midarrow>z\<rightarrow> f z/g z"
  3977       apply (elim Lim_transform_within_open[where s="ball z r"])
  4003       apply (elim Lim_transform_within_open[where s="ball z r"])
  3978       using r by auto
  4004       using r by auto
  3979 
  4005 
  3980     have ?thesis when "n\<ge>0" "f z=0" 
  4006     have ?thesis when "n\<ge>0" "f z=0"
  3981     proof -
  4007     proof -
  3982       have "(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> f z/g z"
  4008       have "(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> f z/g z"
  3983         using powr_tendsto 
  4009         using powr_tendsto
  3984         apply (elim Lim_transform_within[where d=r])
  4010         apply (elim Lim_transform_within[where d=r])
  3985         by (auto simp add: powr_of_int \<open>n\<ge>0\<close> \<open>r>0\<close>)
  4011         by (auto simp add: powr_of_int \<open>n\<ge>0\<close> \<open>r>0\<close>)
  3986       then have *:"(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> 0" using \<open>f z=0\<close> by simp
  4012       then have *:"(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> 0" using \<open>f z=0\<close> by simp
  3987       moreover have False when "n=0"
  4013       moreover have False when "n=0"
  3988       proof -
  4014       proof -
  3990           using \<open>n=0\<close> by auto
  4016           using \<open>n=0\<close> by auto
  3991         then show False using * using LIM_unique zero_neq_one by blast
  4017         then show False using * using LIM_unique zero_neq_one by blast
  3992       qed
  4018       qed
  3993       ultimately show ?thesis using that by fastforce
  4019       ultimately show ?thesis using that by fastforce
  3994     qed
  4020     qed
  3995     moreover have ?thesis when "n\<ge>0" "f z\<noteq>0" 
  4021     moreover have ?thesis when "n\<ge>0" "f z\<noteq>0"
  3996     proof -
  4022     proof -
  3997       have False when "n>0"
  4023       have False when "n>0"
  3998       proof -
  4024       proof -
  3999         have "(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> f z/g z"
  4025         have "(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> f z/g z"
  4000           using powr_tendsto 
  4026           using powr_tendsto
  4001           apply (elim Lim_transform_within[where d=r])
  4027           apply (elim Lim_transform_within[where d=r])
  4002           by (auto simp add: powr_of_int \<open>n\<ge>0\<close> \<open>r>0\<close>)
  4028           by (auto simp add: powr_of_int \<open>n\<ge>0\<close> \<open>r>0\<close>)
  4003         moreover have "(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> 0"
  4029         moreover have "(\<lambda>w. (w - z) ^ nat n) \<midarrow>z\<rightarrow> 0"
  4004           using \<open>n>0\<close> by (auto intro!:tendsto_eq_intros)
  4030           using \<open>n>0\<close> by (auto intro!:tendsto_eq_intros)
  4005         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
  4031         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
  4012            "(\<lambda>w.((w - z) ^ nat (- n))) \<midarrow>z\<rightarrow> 0"
  4038            "(\<lambda>w.((w - z) ^ nat (- n))) \<midarrow>z\<rightarrow> 0"
  4013         subgoal  using powr_tendsto powr_of_int that
  4039         subgoal  using powr_tendsto powr_of_int that
  4014           by (elim Lim_transform_within_open[where s=UNIV],auto)
  4040           by (elim Lim_transform_within_open[where s=UNIV],auto)
  4015         subgoal using that by (auto intro!:tendsto_eq_intros)
  4041         subgoal using that by (auto intro!:tendsto_eq_intros)
  4016         done
  4042         done
  4017       from tendsto_mult[OF this,simplified] 
  4043       from tendsto_mult[OF this,simplified]
  4018       have "(\<lambda>x. inverse ((x - z) ^ nat (- n)) * (x - z) ^ nat (- n)) \<midarrow>z\<rightarrow> 0" .
  4044       have "(\<lambda>x. inverse ((x - z) ^ nat (- n)) * (x - z) ^ nat (- n)) \<midarrow>z\<rightarrow> 0" .
  4019       then have "(\<lambda>x. 1::complex) \<midarrow>z\<rightarrow> 0" 
  4045       then have "(\<lambda>x. 1::complex) \<midarrow>z\<rightarrow> 0"
  4020         by (elim Lim_transform_within_open[where s=UNIV],auto)
  4046         by (elim Lim_transform_within_open[where s=UNIV],auto)
  4021       then show False using LIM_const_eq by fastforce
  4047       then show False using LIM_const_eq by fastforce
  4022     qed
  4048     qed
  4023     ultimately show ?thesis by fastforce
  4049     ultimately show ?thesis by fastforce
  4024   qed
  4050   qed
  4025   moreover have "f w  = g w * (w-z) ^ nat n  \<and> g w \<noteq>0" when "w\<in>cball z r" for w
  4051   moreover have "f w  = g w * (w-z) ^ nat n  \<and> g w \<noteq>0" when "w\<in>cball z r" for w
  4026   proof (cases "w=z")
  4052   proof (cases "w=z")
  4027     case True
  4053     case True
  4028     then have "f \<midarrow>z\<rightarrow>f w" 
  4054     then have "f \<midarrow>z\<rightarrow>f w"
  4029       using assms(4,6) at_within_open continuous_on holo holomorphic_on_imp_continuous_on by fastforce
  4055       using assms(4,6) at_within_open continuous_on holo holomorphic_on_imp_continuous_on by fastforce
  4030     then have "(\<lambda>w. g w * (w-z) ^ nat n) \<midarrow>z\<rightarrow>f w"
  4056     then have "(\<lambda>w. g w * (w-z) ^ nat n) \<midarrow>z\<rightarrow>f w"
  4031     proof (elim Lim_transform_within[OF _ \<open>r>0\<close>])
  4057     proof (elim Lim_transform_within[OF _ \<open>r>0\<close>])
  4032       fix x assume "0 < dist x z" "dist x z < r"
  4058       fix x assume "0 < dist x z" "dist x z < r"
  4033       then have "x \<in> cball z r - {z}" "x\<noteq>z"
  4059       then have "x \<in> cball z r - {z}" "x\<noteq>z"
  4039         using if_0 \<open>x\<noteq>z\<close> by (auto split:if_splits)
  4065         using if_0 \<open>x\<noteq>z\<close> by (auto split:if_splits)
  4040       finally show "f x = g x * (x - z) ^ nat n" .
  4066       finally show "f x = g x * (x - z) ^ nat n" .
  4041     qed
  4067     qed
  4042     moreover have "(\<lambda>w. g w * (w-z) ^ nat n) \<midarrow>z\<rightarrow> g w * (w-z) ^ nat n"
  4068     moreover have "(\<lambda>w. g w * (w-z) ^ nat n) \<midarrow>z\<rightarrow> g w * (w-z) ^ nat n"
  4043       using True apply (auto intro!:tendsto_eq_intros)
  4069       using True apply (auto intro!:tendsto_eq_intros)
  4044       by (metis open_ball at_within_open_subset ball_subset_cball centre_in_ball 
  4070       by (metis open_ball at_within_open_subset ball_subset_cball centre_in_ball
  4045           continuous_on holomorphic_on_imp_continuous_on r(1) r(3) that)
  4071           continuous_on holomorphic_on_imp_continuous_on r(1) r(3) that)
  4046     ultimately have "f w = g w * (w-z) ^ nat n" using LIM_unique by blast
  4072     ultimately have "f w = g w * (w-z) ^ nat n" using LIM_unique by blast
  4047     then show ?thesis using \<open>g z\<noteq>0\<close> True by auto
  4073     then show ?thesis using \<open>g z\<noteq>0\<close> True by auto
  4048   next
  4074   next
  4049     case False
  4075     case False
  4055 qed
  4081 qed
  4056 
  4082 
  4057 lemma zorder_exist_pole:
  4083 lemma zorder_exist_pole:
  4058   fixes f::"complex \<Rightarrow> complex" and z::complex
  4084   fixes f::"complex \<Rightarrow> complex" and z::complex
  4059   defines "n\<equiv>zorder f z" and "g\<equiv>zor_poly f z"
  4085   defines "n\<equiv>zorder f z" and "g\<equiv>zor_poly f z"
  4060   assumes  holo: "f holomorphic_on s-{z}" and 
  4086   assumes  holo: "f holomorphic_on s-{z}" and
  4061           "open s" "z\<in>s"
  4087           "open s" "z\<in>s"
  4062       and "is_pole f z"
  4088       and "is_pole f z"
  4063   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
  4089   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
  4064     \<and> (\<forall>w\<in>cball z r - {z}. f w  = g w / (w-z) ^ nat (- n) \<and> g w \<noteq>0))"
  4090     \<and> (\<forall>w\<in>cball z r - {z}. f w  = g w / (w-z) ^ nat (- n) \<and> g w \<noteq>0))"
  4065 proof -
  4091 proof -
  4066   obtain r where "g z \<noteq> 0" and r: "r>0" "cball z r \<subseteq> s" "g holomorphic_on cball z r" 
  4092   obtain r where "g z \<noteq> 0" and r: "r>0" "cball z r \<subseteq> s" "g holomorphic_on cball z r"
  4067             "(\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0)"
  4093             "(\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0)"
  4068   proof -
  4094   proof -
  4069     have "g z \<noteq> 0 \<and> (\<exists>r>0. g holomorphic_on cball z r 
  4095     have "g z \<noteq> 0 \<and> (\<exists>r>0. g holomorphic_on cball z r
  4070             \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0))"
  4096             \<and> (\<forall>w\<in>cball z r - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0))"
  4071     proof (rule zorder_exist[of f z,folded g_def n_def])
  4097     proof (rule zorder_exist[of f z,folded g_def n_def])
  4072       show "isolated_singularity_at f z" unfolding isolated_singularity_at_def
  4098       show "isolated_singularity_at f z" unfolding isolated_singularity_at_def
  4073         using holo assms(4,5)
  4099         using holo assms(4,5)
  4074         by (metis analytic_on_holomorphic centre_in_ball insert_Diff openE open_delete subset_insert_iff)
  4100         by (metis analytic_on_holomorphic centre_in_ball insert_Diff openE open_delete subset_insert_iff)
  4075       show "not_essential f z" unfolding not_essential_def 
  4101       show "not_essential f z" unfolding not_essential_def
  4076         using assms(4,6) at_within_open continuous_on holo holomorphic_on_imp_continuous_on 
  4102         using assms(4,6) at_within_open continuous_on holo holomorphic_on_imp_continuous_on
  4077         by fastforce
  4103         by fastforce
  4078       from non_zero_neighbour_pole[OF \<open>is_pole f z\<close>] show "\<exists>\<^sub>F w in at z. f w \<noteq> 0"
  4104       from non_zero_neighbour_pole[OF \<open>is_pole f z\<close>] show "\<exists>\<^sub>F w in at z. f w \<noteq> 0"
  4079         apply (elim eventually_frequentlyE)
  4105         apply (elim eventually_frequentlyE)
  4080         by auto
  4106         by auto
  4081     qed
  4107     qed
  4082     then obtain r1 where "g z \<noteq> 0" "r1>0" and r1:"g holomorphic_on cball z r1"
  4108     then obtain r1 where "g z \<noteq> 0" "r1>0" and r1:"g holomorphic_on cball z r1"
  4083             "(\<forall>w\<in>cball z r1 - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0)"
  4109             "(\<forall>w\<in>cball z r1 - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0)"
  4084       by auto
  4110       by auto
  4085     obtain r2 where r2: "r2>0" "cball z r2 \<subseteq> s" 
  4111     obtain r2 where r2: "r2>0" "cball z r2 \<subseteq> s"
  4086       using assms(4,5) open_contains_cball_eq by metis
  4112       using assms(4,5) open_contains_cball_eq by metis
  4087     define r3 where "r3=min r1 r2"
  4113     define r3 where "r3=min r1 r2"
  4088     have "r3>0" "cball z r3 \<subseteq> s" using \<open>r1>0\<close> r2 unfolding r3_def by auto
  4114     have "r3>0" "cball z r3 \<subseteq> s" using \<open>r1>0\<close> r2 unfolding r3_def by auto
  4089     moreover have "g holomorphic_on cball z r3" 
  4115     moreover have "g holomorphic_on cball z r3"
  4090       using r1(1) unfolding r3_def by auto
  4116       using r1(1) unfolding r3_def by auto
  4091     moreover have "(\<forall>w\<in>cball z r3 - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0)" 
  4117     moreover have "(\<forall>w\<in>cball z r3 - {z}. f w = g w * (w - z) powr of_int n \<and> g w \<noteq> 0)"
  4092       using r1(2) unfolding r3_def by auto
  4118       using r1(2) unfolding r3_def by auto
  4093     ultimately show ?thesis using that[of r3] \<open>g z\<noteq>0\<close> by auto 
  4119     ultimately show ?thesis using that[of r3] \<open>g z\<noteq>0\<close> by auto
  4094   qed
  4120   qed
  4095 
  4121 
  4096   have "n<0"
  4122   have "n<0"
  4097   proof (rule ccontr)
  4123   proof (rule ccontr)
  4098     assume " \<not> n < 0"
  4124     assume " \<not> n < 0"
  4099     define c where "c=(if n=0 then g z else 0)"
  4125     define c where "c=(if n=0 then g z else 0)"
  4100     have [simp]:"g \<midarrow>z\<rightarrow> g z" 
  4126     have [simp]:"g \<midarrow>z\<rightarrow> g z"
  4101       by (metis open_ball at_within_open ball_subset_cball centre_in_ball 
  4127       by (metis open_ball at_within_open ball_subset_cball centre_in_ball
  4102             continuous_on holomorphic_on_imp_continuous_on holomorphic_on_subset r(1) r(3) )
  4128             continuous_on holomorphic_on_imp_continuous_on holomorphic_on_subset r(1) r(3) )
  4103     have "\<forall>\<^sub>F x in at z. f x = g x * (x - z) ^ nat n"
  4129     have "\<forall>\<^sub>F x in at z. f x = g x * (x - z) ^ nat n"
  4104       unfolding eventually_at_topological
  4130       unfolding eventually_at_topological
  4105       apply (rule_tac exI[where x="ball z r"])
  4131       apply (rule_tac exI[where x="ball z r"])
  4106       using r powr_of_int \<open>\<not> n < 0\<close> by auto
  4132       using r powr_of_int \<open>\<not> n < 0\<close> by auto
  4110       then show ?thesis unfolding c_def by simp
  4136       then show ?thesis unfolding c_def by simp
  4111     next
  4137     next
  4112       case False
  4138       case False
  4113       then have "(\<lambda>x. (x - z) ^ nat n) \<midarrow>z\<rightarrow> 0" using \<open>\<not> n < 0\<close>
  4139       then have "(\<lambda>x. (x - z) ^ nat n) \<midarrow>z\<rightarrow> 0" using \<open>\<not> n < 0\<close>
  4114         by (auto intro!:tendsto_eq_intros)
  4140         by (auto intro!:tendsto_eq_intros)
  4115       from tendsto_mult[OF _ this,of g "g z",simplified] 
  4141       from tendsto_mult[OF _ this,of g "g z",simplified]
  4116       show ?thesis unfolding c_def using False by simp
  4142       show ?thesis unfolding c_def using False by simp
  4117     qed
  4143     qed
  4118     ultimately have "f \<midarrow>z\<rightarrow>c" using tendsto_cong by fast
  4144     ultimately have "f \<midarrow>z\<rightarrow>c" using tendsto_cong by fast
  4119     then show False using \<open>is_pole f z\<close> at_neq_bot not_tendsto_and_filterlim_at_infinity 
  4145     then show False using \<open>is_pole f z\<close> at_neq_bot not_tendsto_and_filterlim_at_infinity
  4120       unfolding is_pole_def by blast
  4146       unfolding is_pole_def by blast
  4121   qed
  4147   qed
  4122   moreover have "\<forall>w\<in>cball z r - {z}. f w  = g w / (w-z) ^ nat (- n) \<and> g w \<noteq>0"
  4148   moreover have "\<forall>w\<in>cball z r - {z}. f w  = g w / (w-z) ^ nat (- n) \<and> g w \<noteq>0"
  4123     using r(4) \<open>n<0\<close> powr_of_int 
  4149     using r(4) \<open>n<0\<close> powr_of_int
  4124     by (metis Diff_iff divide_inverse eq_iff_diff_eq_0 insert_iff linorder_not_le)
  4150     by (metis Diff_iff divide_inverse eq_iff_diff_eq_0 insert_iff linorder_not_le)
  4125   ultimately show ?thesis using r(1-3) \<open>g z\<noteq>0\<close> by auto
  4151   ultimately show ?thesis using r(1-3) \<open>g z\<noteq>0\<close> by auto
  4126 qed
  4152 qed
  4127 
  4153 
  4128 lemma zorder_eqI:
  4154 lemma zorder_eqI:
  4155     then show "isolated_singularity_at f z" unfolding isolated_singularity_at_def
  4181     then show "isolated_singularity_at f z" unfolding isolated_singularity_at_def
  4156       using analytic_on_open open_delete r(1) by blast
  4182       using analytic_on_open open_delete r(1) by blast
  4157   next
  4183   next
  4158     have "not_essential ?gg z"
  4184     have "not_essential ?gg z"
  4159     proof (intro singularity_intros)
  4185     proof (intro singularity_intros)
  4160       show "not_essential g z" 
  4186       show "not_essential g z"
  4161         by (meson \<open>continuous_on s g\<close> assms(1) assms(2) continuous_on_eq_continuous_at 
  4187         by (meson \<open>continuous_on s g\<close> assms(1) assms(2) continuous_on_eq_continuous_at
  4162             isCont_def not_essential_def)
  4188             isCont_def not_essential_def)
  4163       show " \<forall>\<^sub>F w in at z. w - z \<noteq> 0" by (simp add: eventually_at_filter)
  4189       show " \<forall>\<^sub>F w in at z. w - z \<noteq> 0" by (simp add: eventually_at_filter)
  4164       then show "LIM w at z. w - z :> at 0" 
  4190       then show "LIM w at z. w - z :> at 0"
  4165         unfolding filterlim_at by (auto intro:tendsto_eq_intros)
  4191         unfolding filterlim_at by (auto intro:tendsto_eq_intros)
  4166       show "isolated_singularity_at g z" 
  4192       show "isolated_singularity_at g z"
  4167         by (meson Diff_subset open_ball analytic_on_holomorphic 
  4193         by (meson Diff_subset open_ball analytic_on_holomorphic
  4168             assms(1,2,3) holomorphic_on_subset isolated_singularity_at_def openE)
  4194             assms(1,2,3) holomorphic_on_subset isolated_singularity_at_def openE)
  4169     qed
  4195     qed
  4170     then show "not_essential f z"
  4196     then show "not_essential f z"
  4171       apply (elim not_essential_transform)
  4197       apply (elim not_essential_transform)
  4172       unfolding eventually_at using assms(1,2) assms(5)[symmetric] 
  4198       unfolding eventually_at using assms(1,2) assms(5)[symmetric]
  4173       by (metis dist_commute mem_ball openE subsetCE)
  4199       by (metis dist_commute mem_ball openE subsetCE)
  4174     show "\<exists>\<^sub>F w in at z. f w \<noteq> 0" unfolding frequently_at 
  4200     show "\<exists>\<^sub>F w in at z. f w \<noteq> 0" unfolding frequently_at
  4175     proof (rule,rule)
  4201     proof (rule,rule)
  4176       fix d::real assume "0 < d"
  4202       fix d::real assume "0 < d"
  4177       define z' where "z'=z+min d r / 2"
  4203       define z' where "z'=z+min d r / 2"
  4178       have "z' \<noteq> z" " dist z' z < d "
  4204       have "z' \<noteq> z" " dist z' z < d "
  4179         unfolding z'_def using \<open>d>0\<close> \<open>r>0\<close> 
  4205         unfolding z'_def using \<open>d>0\<close> \<open>r>0\<close>
  4180         by (auto simp add:dist_norm)
  4206         by (auto simp add:dist_norm)
  4181       moreover have "f z' \<noteq> 0"  
  4207       moreover have "f z' \<noteq> 0"
  4182       proof (subst fg_eq[OF _ \<open>z'\<noteq>z\<close>])
  4208       proof (subst fg_eq[OF _ \<open>z'\<noteq>z\<close>])
  4183         have "z' \<in> cball z r" unfolding z'_def using \<open>r>0\<close> \<open>d>0\<close> by (auto simp add:dist_norm)
  4209         have "z' \<in> cball z r" unfolding z'_def using \<open>r>0\<close> \<open>d>0\<close> by (auto simp add:dist_norm)
  4184         then show " z' \<in> s" using r(2) by blast
  4210         then show " z' \<in> s" using r(2) by blast
  4185         show "g z' * (z' - z) powr of_int n \<noteq> 0" 
  4211         show "g z' * (z' - z) powr of_int n \<noteq> 0"
  4186           using P_def \<open>P n g r\<close> \<open>z' \<in> cball z r\<close> calculation(1) by auto
  4212           using P_def \<open>P n g r\<close> \<open>z' \<in> cball z r\<close> calculation(1) by auto
  4187       qed
  4213       qed
  4188       ultimately show "\<exists>x\<in>UNIV. x \<noteq> z \<and> dist x z < d \<and> f x \<noteq> 0" by auto
  4214       ultimately show "\<exists>x\<in>UNIV. x \<noteq> z \<and> dist x z < d \<and> f x \<noteq> 0" by auto
  4189     qed
  4215     qed
  4190   qed
  4216   qed
  4204   obtain e where [simp]:"e>0" and f_holo:"f holomorphic_on ball z e - {z}"
  4230   obtain e where [simp]:"e>0" and f_holo:"f holomorphic_on ball z e - {z}"
  4205     using f_iso analytic_imp_holomorphic unfolding isolated_singularity_at_def by blast
  4231     using f_iso analytic_imp_holomorphic unfolding isolated_singularity_at_def by blast
  4206   obtain r where "0 < n" "0 < r" and r_cball:"cball z r \<subseteq> ball z e" and h_holo: "h holomorphic_on cball z r"
  4232   obtain r where "0 < n" "0 < r" and r_cball:"cball z r \<subseteq> ball z e" and h_holo: "h holomorphic_on cball z r"
  4207       and h_divide:"(\<forall>w\<in>cball z r. (w\<noteq>z \<longrightarrow> f w = h w / (w - z) ^ n) \<and> h w \<noteq> 0)"
  4233       and h_divide:"(\<forall>w\<in>cball z r. (w\<noteq>z \<longrightarrow> f w = h w / (w - z) ^ n) \<and> h w \<noteq> 0)"
  4208   proof -
  4234   proof -
  4209     obtain r where r:"zorder f z < 0" "h z \<noteq> 0" "r>0" "cball z r \<subseteq> ball z e" "h holomorphic_on cball z r" 
  4235     obtain r where r:"zorder f z < 0" "h z \<noteq> 0" "r>0" "cball z r \<subseteq> ball z e" "h holomorphic_on cball z r"
  4210         "(\<forall>w\<in>cball z r - {z}. f w = h w / (w - z) ^ n \<and> h w \<noteq> 0)"
  4236         "(\<forall>w\<in>cball z r - {z}. f w = h w / (w - z) ^ n \<and> h w \<noteq> 0)"
  4211       using zorder_exist_pole[OF f_holo,simplified,OF \<open>is_pole f z\<close>,folded n_def h_def] by auto
  4237       using zorder_exist_pole[OF f_holo,simplified,OF \<open>is_pole f z\<close>,folded n_def h_def] by auto
  4212     have "n>0" using \<open>zorder f z < 0\<close> unfolding n_def by simp
  4238     have "n>0" using \<open>zorder f z < 0\<close> unfolding n_def by simp
  4213     moreover have "(\<forall>w\<in>cball z r. (w\<noteq>z \<longrightarrow> f w = h w / (w - z) ^ n) \<and> h w \<noteq> 0)"
  4239     moreover have "(\<forall>w\<in>cball z r. (w\<noteq>z \<longrightarrow> f w = h w / (w - z) ^ n) \<and> h w \<noteq> 0)"
  4214       using \<open>h z\<noteq>0\<close> r(6) by blast
  4240       using \<open>h z\<noteq>0\<close> r(6) by blast
  4233       fix x assume "x \<in> path_image (circlepath z r)"
  4259       fix x assume "x \<in> path_image (circlepath z r)"
  4234       hence "x\<in>cball z r - {z}" using \<open>r>0\<close> by auto
  4260       hence "x\<in>cball z r - {z}" using \<open>r>0\<close> by auto
  4235       then show "h' x = f x" using h_divide unfolding h'_def by auto
  4261       then show "h' x = f x" using h_divide unfolding h'_def by auto
  4236     qed
  4262     qed
  4237   moreover have "(f has_contour_integral c * residue f z) (circlepath z r)"
  4263   moreover have "(f has_contour_integral c * residue f z) (circlepath z r)"
  4238     using base_residue[of \<open>ball z e\<close> z,simplified,OF \<open>r>0\<close> f_holo r_cball,folded c_def] 
  4264     using base_residue[of \<open>ball z e\<close> z,simplified,OF \<open>r>0\<close> f_holo r_cball,folded c_def]
  4239     unfolding c_def by simp
  4265     unfolding c_def by simp
  4240   ultimately have "c * der_f =  c * residue f z" using has_contour_integral_unique by blast
  4266   ultimately have "c * der_f =  c * residue f z" using has_contour_integral_unique by blast
  4241   hence "der_f = residue f z" unfolding c_def by auto
  4267   hence "der_f = residue f z" unfolding c_def by auto
  4242   thus ?thesis unfolding der_f_def by auto
  4268   thus ?thesis unfolding der_f_def by auto
  4243 qed
  4269 qed
  4247   assumes "\<And>w. w \<in> s \<Longrightarrow> f w = g w * (w - z)"
  4273   assumes "\<And>w. w \<in> s \<Longrightarrow> f w = g w * (w - z)"
  4248   shows   "zorder f z = 1"
  4274   shows   "zorder f z = 1"
  4249   using assms(1-4) by (rule zorder_eqI) (use assms(5) in auto)
  4275   using assms(1-4) by (rule zorder_eqI) (use assms(5) in auto)
  4250 
  4276 
  4251 lemma higher_deriv_power:
  4277 lemma higher_deriv_power:
  4252   shows   "(deriv ^^ j) (\<lambda>w. (w - z) ^ n) w = 
  4278   shows   "(deriv ^^ j) (\<lambda>w. (w - z) ^ n) w =
  4253              pochhammer (of_nat (Suc n - j)) j * (w - z) ^ (n - j)"
  4279              pochhammer (of_nat (Suc n - j)) j * (w - z) ^ (n - j)"
  4254 proof (induction j arbitrary: w)
  4280 proof (induction j arbitrary: w)
  4255   case 0
  4281   case 0
  4256   thus ?case by auto
  4282   thus ?case by auto
  4257 next
  4283 next
  4258   case (Suc j w)
  4284   case (Suc j w)
  4259   have "(deriv ^^ Suc j) (\<lambda>w. (w - z) ^ n) w = deriv ((deriv ^^ j) (\<lambda>w. (w - z) ^ n)) w"
  4285   have "(deriv ^^ Suc j) (\<lambda>w. (w - z) ^ n) w = deriv ((deriv ^^ j) (\<lambda>w. (w - z) ^ n)) w"
  4260     by simp
  4286     by simp
  4261   also have "(deriv ^^ j) (\<lambda>w. (w - z) ^ n) = 
  4287   also have "(deriv ^^ j) (\<lambda>w. (w - z) ^ n) =
  4262                (\<lambda>w. pochhammer (of_nat (Suc n - j)) j * (w - z) ^ (n - j))"
  4288                (\<lambda>w. pochhammer (of_nat (Suc n - j)) j * (w - z) ^ (n - j))"
  4263     using Suc by (intro Suc.IH ext)
  4289     using Suc by (intro Suc.IH ext)
  4264   also {
  4290   also {
  4265     have "(\<dots> has_field_derivative of_nat (n - j) *
  4291     have "(\<dots> has_field_derivative of_nat (n - j) *
  4266                pochhammer (of_nat (Suc n - j)) j * (w - z) ^ (n - Suc j)) (at w)"
  4292                pochhammer (of_nat (Suc n - j)) j * (w - z) ^ (n - Suc j)) (at w)"
  4267       using Suc.prems by (auto intro!: derivative_eq_intros)
  4293       using Suc.prems by (auto intro!: derivative_eq_intros)
  4268     also have "of_nat (n - j) * pochhammer (of_nat (Suc n - j)) j = 
  4294     also have "of_nat (n - j) * pochhammer (of_nat (Suc n - j)) j =
  4269                  pochhammer (of_nat (Suc n - Suc j)) (Suc j)"
  4295                  pochhammer (of_nat (Suc n - Suc j)) (Suc j)"
  4270       by (cases "Suc j \<le> n", subst pochhammer_rec) 
  4296       by (cases "Suc j \<le> n", subst pochhammer_rec)
  4271          (insert Suc.prems, simp_all add: algebra_simps Suc_diff_le pochhammer_0_left)
  4297          (insert Suc.prems, simp_all add: algebra_simps Suc_diff_le pochhammer_0_left)
  4272     finally have "deriv (\<lambda>w. pochhammer (of_nat (Suc n - j)) j * (w - z) ^ (n - j)) w =
  4298     finally have "deriv (\<lambda>w. pochhammer (of_nat (Suc n - j)) j * (w - z) ^ (n - j)) w =
  4273                     \<dots> * (w - z) ^ (n - Suc j)"
  4299                     \<dots> * (w - z) ^ (n - Suc j)"
  4274       by (rule DERIV_imp_deriv)
  4300       by (rule DERIV_imp_deriv)
  4275   }
  4301   }
  4286     using \<open>open s\<close> \<open>z\<in>s\<close> openE by blast
  4312     using \<open>open s\<close> \<open>z\<in>s\<close> openE by blast
  4287   have nz':"\<exists>w\<in>ball z r. f w \<noteq> 0"
  4313   have nz':"\<exists>w\<in>ball z r. f w \<noteq> 0"
  4288   proof (rule ccontr)
  4314   proof (rule ccontr)
  4289     assume "\<not> (\<exists>w\<in>ball z r. f w \<noteq> 0)"
  4315     assume "\<not> (\<exists>w\<in>ball z r. f w \<noteq> 0)"
  4290     then have "eventually (\<lambda>u. f u = 0) (nhds z)"
  4316     then have "eventually (\<lambda>u. f u = 0) (nhds z)"
  4291       using \<open>r>0\<close> unfolding eventually_nhds 
  4317       using \<open>r>0\<close> unfolding eventually_nhds
  4292       apply (rule_tac x="ball z r" in exI)
  4318       apply (rule_tac x="ball z r" in exI)
  4293       by auto
  4319       by auto
  4294     then have "(deriv ^^ nat n) f z = (deriv ^^ nat n) (\<lambda>_. 0) z"
  4320     then have "(deriv ^^ nat n) f z = (deriv ^^ nat n) (\<lambda>_. 0) z"
  4295       by (intro higher_deriv_cong_ev) auto
  4321       by (intro higher_deriv_cong_ev) auto
  4296     also have "(deriv ^^ nat n) (\<lambda>_. 0) z = 0"
  4322     also have "(deriv ^^ nat n) (\<lambda>_. 0) z = 0"
  4308       using f_holo \<open>ball z r \<subseteq> s\<close> by auto
  4334       using f_holo \<open>ball z r \<subseteq> s\<close> by auto
  4309     from that zorder_exist_zero[of f "ball z r" z,simplified,OF this nz',folded zn_def g_def]
  4335     from that zorder_exist_zero[of f "ball z r" z,simplified,OF this nz',folded zn_def g_def]
  4310     show ?thesis by blast
  4336     show ?thesis by blast
  4311   qed
  4337   qed
  4312   from this(1,2,5) have "zn\<ge>0" "g z\<noteq>0"
  4338   from this(1,2,5) have "zn\<ge>0" "g z\<noteq>0"
  4313     subgoal by (auto split:if_splits) 
  4339     subgoal by (auto split:if_splits)
  4314     subgoal using \<open>0 < e\<close> ball_subset_cball centre_in_ball e_fac by blast
  4340     subgoal using \<open>0 < e\<close> ball_subset_cball centre_in_ball e_fac by blast
  4315     done
  4341     done
  4316 
  4342 
  4317   define A where "A = (\<lambda>i. of_nat (i choose (nat zn)) * fact (nat zn) * (deriv ^^ (i - nat zn)) g z)"
  4343   define A where "A = (\<lambda>i. of_nat (i choose (nat zn)) * fact (nat zn) * (deriv ^^ (i - nat zn)) g z)"
  4318   have deriv_A:"(deriv ^^ i) f z = (if zn \<le> int i then A i else 0)" for i
  4344   have deriv_A:"(deriv ^^ i) f z = (if zn \<le> int i then A i else 0)" for i
  4319   proof -
  4345   proof -
  4320     have "eventually (\<lambda>w. w \<in> ball z e) (nhds z)"
  4346     have "eventually (\<lambda>w. w \<in> ball z e) (nhds z)"
  4321       using \<open>cball z e \<subseteq> ball z r\<close> \<open>e>0\<close> by (intro eventually_nhds_in_open) auto
  4347       using \<open>cball z e \<subseteq> ball z r\<close> \<open>e>0\<close> by (intro eventually_nhds_in_open) auto
  4322     hence "eventually (\<lambda>w. f w = (w - z) ^ (nat zn) * g w) (nhds z)"
  4348     hence "eventually (\<lambda>w. f w = (w - z) ^ (nat zn) * g w) (nhds z)"
  4323       apply eventually_elim 
  4349       apply eventually_elim
  4324       by (use e_fac in auto)
  4350       by (use e_fac in auto)
  4325     hence "(deriv ^^ i) f z = (deriv ^^ i) (\<lambda>w. (w - z) ^ nat zn * g w) z"
  4351     hence "(deriv ^^ i) f z = (deriv ^^ i) (\<lambda>w. (w - z) ^ nat zn * g w) z"
  4326       by (intro higher_deriv_cong_ev) auto
  4352       by (intro higher_deriv_cong_ev) auto
  4327     also have "\<dots> = (\<Sum>j=0..i. of_nat (i choose j) *
  4353     also have "\<dots> = (\<Sum>j=0..i. of_nat (i choose j) *
  4328                        (deriv ^^ j) (\<lambda>w. (w - z) ^ nat zn) z * (deriv ^^ (i - j)) g z)"
  4354                        (deriv ^^ j) (\<lambda>w. (w - z) ^ nat zn) z * (deriv ^^ (i - j)) g z)"
  4329       using g_holo \<open>e>0\<close> 
  4355       using g_holo \<open>e>0\<close>
  4330       by (intro higher_deriv_mult[of _ "ball z e"]) (auto intro!: holomorphic_intros)
  4356       by (intro higher_deriv_mult[of _ "ball z e"]) (auto intro!: holomorphic_intros)
  4331     also have "\<dots> = (\<Sum>j=0..i. if j = nat zn then 
  4357     also have "\<dots> = (\<Sum>j=0..i. if j = nat zn then
  4332                     of_nat (i choose nat zn) * fact (nat zn) * (deriv ^^ (i - nat zn)) g z else 0)"
  4358                     of_nat (i choose nat zn) * fact (nat zn) * (deriv ^^ (i - nat zn)) g z else 0)"
  4333     proof (intro sum.cong refl, goal_cases)
  4359     proof (intro sum.cong refl, goal_cases)
  4334       case (1 j)
  4360       case (1 j)
  4335       have "(deriv ^^ j) (\<lambda>w. (w - z) ^ nat zn) z = 
  4361       have "(deriv ^^ j) (\<lambda>w. (w - z) ^ nat zn) z =
  4336               pochhammer (of_nat (Suc (nat zn) - j)) j * 0 ^ (nat zn - j)"
  4362               pochhammer (of_nat (Suc (nat zn) - j)) j * 0 ^ (nat zn - j)"
  4337         by (subst higher_deriv_power) auto
  4363         by (subst higher_deriv_power) auto
  4338       also have "\<dots> = (if j = nat zn then fact j else 0)"
  4364       also have "\<dots> = (if j = nat zn then fact j else 0)"
  4339         by (auto simp: not_less pochhammer_0_left pochhammer_fact)
  4365         by (auto simp: not_less pochhammer_0_left pochhammer_fact)
  4340       also have "of_nat (i choose j) * \<dots> * (deriv ^^ (i - j)) g z = 
  4366       also have "of_nat (i choose j) * \<dots> * (deriv ^^ (i - j)) g z =
  4341                    (if j = nat zn then of_nat (i choose (nat zn)) * fact (nat zn) 
  4367                    (if j = nat zn then of_nat (i choose (nat zn)) * fact (nat zn)
  4342                         * (deriv ^^ (i - nat zn)) g z else 0)"
  4368                         * (deriv ^^ (i - nat zn)) g z else 0)"
  4343         by simp
  4369         by simp
  4344       finally show ?case .
  4370       finally show ?case .
  4345     qed
  4371     qed
  4346     also have "\<dots> = (if i \<ge> zn then A i else 0)"
  4372     also have "\<dots> = (if i \<ge> zn then A i else 0)"
  4349   qed
  4375   qed
  4350 
  4376 
  4351   have False when "n<zn"
  4377   have False when "n<zn"
  4352   proof -
  4378   proof -
  4353     have "(deriv ^^ nat n) f z = 0"
  4379     have "(deriv ^^ nat n) f z = 0"
  4354       using deriv_A[of "nat n"] that \<open>n\<ge>0\<close> by auto 
  4380       using deriv_A[of "nat n"] that \<open>n\<ge>0\<close> by auto
  4355     with nz show False by auto
  4381     with nz show False by auto
  4356   qed
  4382   qed
  4357   moreover have "n\<le>zn"
  4383   moreover have "n\<le>zn"
  4358   proof -
  4384   proof -
  4359     have "g z \<noteq> 0" using e_fac[rule_format,of z] \<open>e>0\<close> by simp 
  4385     have "g z \<noteq> 0" using e_fac[rule_format,of z] \<open>e>0\<close> by simp
  4360     then have "(deriv ^^ nat zn) f z \<noteq> 0"
  4386     then have "(deriv ^^ nat zn) f z \<noteq> 0"
  4361       using deriv_A[of "nat zn"] by(auto simp add:A_def)
  4387       using deriv_A[of "nat zn"] by(auto simp add:A_def)
  4362     then have "nat zn \<ge> nat n" using zero[of "nat zn"] by linarith
  4388     then have "nat zn \<ge> nat n" using zero[of "nat zn"] by linarith
  4363     moreover have "zn\<ge>0" using e_if by (auto split:if_splits)
  4389     moreover have "zn\<ge>0" using e_if by (auto split:if_splits)
  4364     ultimately show ?thesis using nat_le_eq_zle by blast
  4390     ultimately show ?thesis using nat_le_eq_zle by blast
  4365   qed
  4391   qed
  4366   ultimately show ?thesis unfolding zn_def by fastforce
  4392   ultimately show ?thesis unfolding zn_def by fastforce
  4367 qed
  4393 qed
  4368 
  4394 
  4369 lemma 
  4395 lemma
  4370   assumes "eventually (\<lambda>z. f z = g z) (at z)" "z = z'"
  4396   assumes "eventually (\<lambda>z. f z = g z) (at z)" "z = z'"
  4371   shows zorder_cong:"zorder f z = zorder g z'" and zor_poly_cong:"zor_poly f z = zor_poly g z'"
  4397   shows zorder_cong:"zorder f z = zorder g z'" and zor_poly_cong:"zor_poly f z = zor_poly g z'"
  4372 proof -
  4398 proof -
  4373   define P where "P = (\<lambda>ff n h r. 0 < r \<and> h holomorphic_on cball z r \<and> h z\<noteq>0
  4399   define P where "P = (\<lambda>ff n h r. 0 < r \<and> h holomorphic_on cball z r \<and> h z\<noteq>0
  4374                     \<and> (\<forall>w\<in>cball z r - {z}. ff w = h w * (w-z) powr (of_int n) \<and> h w\<noteq>0))"
  4400                     \<and> (\<forall>w\<in>cball z r - {z}. ff w = h w * (w-z) powr (of_int n) \<and> h w\<noteq>0))"
  4375   have "(\<exists>r. P f n h r) = (\<exists>r. P g n h r)" for n h 
  4401   have "(\<exists>r. P f n h r) = (\<exists>r. P g n h r)" for n h
  4376   proof -
  4402   proof -
  4377     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 
  4403     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
  4378     proof -
  4404     proof -
  4379       from that(1) obtain r1 where r1_P:"P f n h r1" by auto
  4405       from that(1) obtain r1 where r1_P:"P f n h r1" by auto
  4380       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"
  4406       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"
  4381         unfolding eventually_at_le by auto
  4407         unfolding eventually_at_le by auto
  4382       define r where "r=min r1 r2"
  4408       define r where "r=min r1 r2"
  4385         using r1_P unfolding P_def r_def by auto
  4411         using r1_P unfolding P_def r_def by auto
  4386       moreover have "g w = h w * (w - z) powr of_int n \<and> h w \<noteq> 0" when "w\<in>cball z r - {z}" for w
  4412       moreover have "g w = h w * (w - z) powr of_int n \<and> h w \<noteq> 0" when "w\<in>cball z r - {z}" for w
  4387       proof -
  4413       proof -
  4388         have "f w = h w * (w - z) powr of_int n \<and> h w \<noteq> 0"
  4414         have "f w = h w * (w - z) powr of_int n \<and> h w \<noteq> 0"
  4389           using r1_P that unfolding P_def r_def by auto
  4415           using r1_P that unfolding P_def r_def by auto
  4390         moreover have "f w=g w" using r2_dist[rule_format,of w] that unfolding r_def 
  4416         moreover have "f w=g w" using r2_dist[rule_format,of w] that unfolding r_def
  4391           by (simp add: dist_commute) 
  4417           by (simp add: dist_commute)
  4392         ultimately show ?thesis by simp
  4418         ultimately show ?thesis by simp
  4393       qed
  4419       qed
  4394       ultimately show ?thesis unfolding P_def by auto
  4420       ultimately show ?thesis unfolding P_def by auto
  4395     qed
  4421     qed
  4396     from assms have eq': "eventually (\<lambda>z. g z = f z) (at z)"
  4422     from assms have eq': "eventually (\<lambda>z. g z = f z) (at z)"
  4397       by (simp add: eq_commute)
  4423       by (simp add: eq_commute)
  4398     show ?thesis
  4424     show ?thesis
  4399       by (rule iffI[OF *[OF _ assms(1)] *[OF _ eq']])
  4425       by (rule iffI[OF *[OF _ assms(1)] *[OF _ eq']])
  4400   qed
  4426   qed
  4401   then show "zorder f z = zorder g z'" "zor_poly f z = zor_poly g z'"  
  4427   then show "zorder f z = zorder g z'" "zor_poly f z = zor_poly g z'"
  4402       using \<open>z=z'\<close> unfolding P_def zorder_def zor_poly_def by auto
  4428       using \<open>z=z'\<close> unfolding P_def zorder_def zor_poly_def by auto
  4403 qed
  4429 qed
  4404 
  4430 
  4405 lemma zorder_nonzero_div_power:
  4431 lemma zorder_nonzero_div_power:
  4406   assumes "open s" "z \<in> s" "f holomorphic_on s" "f z \<noteq> 0" "n > 0"
  4432   assumes "open s" "z \<in> s" "f holomorphic_on s" "f z \<noteq> 0" "n > 0"
  4411 
  4437 
  4412 lemma zor_poly_eq:
  4438 lemma zor_poly_eq:
  4413   assumes "isolated_singularity_at f z" "not_essential f z" "\<exists>\<^sub>F w in at z. f w \<noteq> 0"
  4439   assumes "isolated_singularity_at f z" "not_essential f z" "\<exists>\<^sub>F w in at z. f w \<noteq> 0"
  4414   shows "eventually (\<lambda>w. zor_poly f z w = f w * (w - z) powr - zorder f z) (at z)"
  4440   shows "eventually (\<lambda>w. zor_poly f z w = f w * (w - z) powr - zorder f z) (at z)"
  4415 proof -
  4441 proof -
  4416   obtain r where r:"r>0" 
  4442   obtain r where r:"r>0"
  4417        "(\<forall>w\<in>cball z r - {z}. f w = zor_poly f z w * (w - z) powr of_int (zorder f z))"
  4443        "(\<forall>w\<in>cball z r - {z}. f w = zor_poly f z w * (w - z) powr of_int (zorder f z))"
  4418     using zorder_exist[OF assms] by blast
  4444     using zorder_exist[OF assms] by blast
  4419   then have *: "\<forall>w\<in>ball z r - {z}. zor_poly f z w = f w * (w - z) powr - zorder f z" 
  4445   then have *: "\<forall>w\<in>ball z r - {z}. zor_poly f z w = f w * (w - z) powr - zorder f z"
  4420     by (auto simp: field_simps powr_minus)
  4446     by (auto simp: field_simps powr_minus)
  4421   have "eventually (\<lambda>w. w \<in> ball z r - {z}) (at z)"
  4447   have "eventually (\<lambda>w. w \<in> ball z r - {z}) (at z)"
  4422     using r eventually_at_ball'[of r z UNIV] by auto
  4448     using r eventually_at_ball'[of r z UNIV] by auto
  4423   thus ?thesis by eventually_elim (insert *, auto)
  4449   thus ?thesis by eventually_elim (insert *, auto)
  4424 qed
  4450 qed
  4425 
  4451 
  4426 lemma zor_poly_zero_eq:
  4452 lemma zor_poly_zero_eq:
  4427   assumes "f holomorphic_on s" "open s" "connected s" "z \<in> s" "\<exists>w\<in>s. f w \<noteq> 0"
  4453   assumes "f holomorphic_on s" "open s" "connected s" "z \<in> s" "\<exists>w\<in>s. f w \<noteq> 0"
  4428   shows "eventually (\<lambda>w. zor_poly f z w = f w / (w - z) ^ nat (zorder f z)) (at z)"
  4454   shows "eventually (\<lambda>w. zor_poly f z w = f w / (w - z) ^ nat (zorder f z)) (at z)"
  4429 proof -
  4455 proof -
  4430   obtain r where r:"r>0" 
  4456   obtain r where r:"r>0"
  4431        "(\<forall>w\<in>cball z r - {z}. f w = zor_poly f z w * (w - z) ^ nat (zorder f z))"
  4457        "(\<forall>w\<in>cball z r - {z}. f w = zor_poly f z w * (w - z) ^ nat (zorder f z))"
  4432     using zorder_exist_zero[OF assms] by auto
  4458     using zorder_exist_zero[OF assms] by auto
  4433   then have *: "\<forall>w\<in>ball z r - {z}. zor_poly f z w = f w / (w - z) ^ nat (zorder f z)" 
  4459   then have *: "\<forall>w\<in>ball z r - {z}. zor_poly f z w = f w / (w - z) ^ nat (zorder f z)"
  4434     by (auto simp: field_simps powr_minus)
  4460     by (auto simp: field_simps powr_minus)
  4435   have "eventually (\<lambda>w. w \<in> ball z r - {z}) (at z)"
  4461   have "eventually (\<lambda>w. w \<in> ball z r - {z}) (at z)"
  4436     using r eventually_at_ball'[of r z UNIV] by auto
  4462     using r eventually_at_ball'[of r z UNIV] by auto
  4437   thus ?thesis by eventually_elim (insert *, auto)
  4463   thus ?thesis by eventually_elim (insert *, auto)
  4438 qed
  4464 qed
  4441   assumes f_iso:"isolated_singularity_at f z" "is_pole f z"
  4467   assumes f_iso:"isolated_singularity_at f z" "is_pole f z"
  4442   shows "eventually (\<lambda>w. zor_poly f z w = f w * (w - z) ^ nat (- zorder f z)) (at z)"
  4468   shows "eventually (\<lambda>w. zor_poly f z w = f w * (w - z) ^ nat (- zorder f z)) (at z)"
  4443 proof -
  4469 proof -
  4444   obtain e where [simp]:"e>0" and f_holo:"f holomorphic_on ball z e - {z}"
  4470   obtain e where [simp]:"e>0" and f_holo:"f holomorphic_on ball z e - {z}"
  4445     using f_iso analytic_imp_holomorphic unfolding isolated_singularity_at_def by blast
  4471     using f_iso analytic_imp_holomorphic unfolding isolated_singularity_at_def by blast
  4446   obtain r where r:"r>0" 
  4472   obtain r where r:"r>0"
  4447        "(\<forall>w\<in>cball z r - {z}. f w = zor_poly f z w / (w - z) ^ nat (- zorder f z))"
  4473        "(\<forall>w\<in>cball z r - {z}. f w = zor_poly f z w / (w - z) ^ nat (- zorder f z))"
  4448     using zorder_exist_pole[OF f_holo,simplified,OF \<open>is_pole f z\<close>] by auto
  4474     using zorder_exist_pole[OF f_holo,simplified,OF \<open>is_pole f z\<close>] by auto
  4449   then have *: "\<forall>w\<in>ball z r - {z}. zor_poly f z w = f w * (w - z) ^ nat (- zorder f z)" 
  4475   then have *: "\<forall>w\<in>ball z r - {z}. zor_poly f z w = f w * (w - z) ^ nat (- zorder f z)"
  4450     by (auto simp: field_simps)
  4476     by (auto simp: field_simps)
  4451   have "eventually (\<lambda>w. w \<in> ball z r - {z}) (at z)"
  4477   have "eventually (\<lambda>w. w \<in> ball z r - {z}) (at z)"
  4452     using r eventually_at_ball'[of r z UNIV] by auto
  4478     using r eventually_at_ball'[of r z UNIV] by auto
  4453   thus ?thesis by eventually_elim (insert *, auto)
  4479   thus ?thesis by eventually_elim (insert *, auto)
  4454 qed
  4480 qed
  4518   assumes lim: "((\<lambda>x. f (g x) * (g x - z0) ^ nat (-n)) \<longlongrightarrow> c) F"
  4544   assumes lim: "((\<lambda>x. f (g x) * (g x - z0) ^ nat (-n)) \<longlongrightarrow> c) F"
  4519   assumes g: "filterlim g (at z0) F" and "F \<noteq> bot"
  4545   assumes g: "filterlim g (at z0) F" and "F \<noteq> bot"
  4520   shows   "zor_poly f z0 z0 = c"
  4546   shows   "zor_poly f z0 z0 = c"
  4521 proof -
  4547 proof -
  4522   obtain r where r: "r > 0"  "zor_poly f z0 holomorphic_on cball z0 r"
  4548   obtain r where r: "r > 0"  "zor_poly f z0 holomorphic_on cball z0 r"
  4523   proof -   
  4549   proof -
  4524     have "\<exists>\<^sub>F w in at z0. f w \<noteq> 0" 
  4550     have "\<exists>\<^sub>F w in at z0. f w \<noteq> 0"
  4525       using non_zero_neighbour_pole[OF \<open>is_pole f z0\<close>] by (auto elim:eventually_frequentlyE)
  4551       using non_zero_neighbour_pole[OF \<open>is_pole f z0\<close>] by (auto elim:eventually_frequentlyE)
  4526     moreover have "not_essential f z0" unfolding not_essential_def using \<open>is_pole f z0\<close> by simp
  4552     moreover have "not_essential f z0" unfolding not_essential_def using \<open>is_pole f z0\<close> by simp
  4527     ultimately show ?thesis using that zorder_exist[OF f_iso,folded n_def] by auto
  4553     ultimately show ?thesis using that zorder_exist[OF f_iso,folded n_def] by auto
  4528   qed
  4554   qed
  4529   from r(1) have "eventually (\<lambda>w. w \<in> ball z0 r \<and> w \<noteq> z0) (at z0)"
  4555   from r(1) have "eventually (\<lambda>w. w \<in> ball z0 r \<and> w \<noteq> z0) (at z0)"
  4542     by (rule filterlim_compose[OF _ g])
  4568     by (rule filterlim_compose[OF _ g])
  4543   from tendsto_unique[OF \<open>F \<noteq> bot\<close> this lim] show ?thesis .
  4569   from tendsto_unique[OF \<open>F \<noteq> bot\<close> this lim] show ?thesis .
  4544 qed
  4570 qed
  4545 
  4571 
  4546 lemma residue_simple_pole:
  4572 lemma residue_simple_pole:
  4547   assumes "isolated_singularity_at f z0" 
  4573   assumes "isolated_singularity_at f z0"
  4548   assumes "is_pole f z0" "zorder f z0 = - 1"
  4574   assumes "is_pole f z0" "zorder f z0 = - 1"
  4549   shows   "residue f z0 = zor_poly f z0 z0"
  4575   shows   "residue f z0 = zor_poly f z0 z0"
  4550   using assms by (subst residue_pole_order) simp_all
  4576   using assms by (subst residue_pole_order) simp_all
  4551 
  4577 
  4552 lemma residue_simple_pole_limit:
  4578 lemma residue_simple_pole_limit:
  4553   assumes "isolated_singularity_at f z0" 
  4579   assumes "isolated_singularity_at f z0"
  4554   assumes "is_pole f z0" "zorder f z0 = - 1"
  4580   assumes "is_pole f z0" "zorder f z0 = - 1"
  4555   assumes "((\<lambda>x. f (g x) * (g x - z0)) \<longlongrightarrow> c) F"
  4581   assumes "((\<lambda>x. f (g x) * (g x - z0)) \<longlongrightarrow> c) F"
  4556   assumes "filterlim g (at z0) F" "F \<noteq> bot"
  4582   assumes "filterlim g (at z0) F" "F \<noteq> bot"
  4557   shows   "residue f z0 = c"
  4583   shows   "residue f z0 = c"
  4558 proof -
  4584 proof -
  4563     using assms by auto
  4589     using assms by auto
  4564   finally show ?thesis .
  4590   finally show ?thesis .
  4565 qed
  4591 qed
  4566 
  4592 
  4567 lemma lhopital_complex_simple:
  4593 lemma lhopital_complex_simple:
  4568   assumes "(f has_field_derivative f') (at z)" 
  4594   assumes "(f has_field_derivative f') (at z)"
  4569   assumes "(g has_field_derivative g') (at z)"
  4595   assumes "(g has_field_derivative g') (at z)"
  4570   assumes "f z = 0" "g z = 0" "g' \<noteq> 0" "f' / g' = c"
  4596   assumes "f z = 0" "g z = 0" "g' \<noteq> 0" "f' / g' = c"
  4571   shows   "((\<lambda>w. f w / g w) \<longlongrightarrow> c) (at z)"
  4597   shows   "((\<lambda>w. f w / g w) \<longlongrightarrow> c) (at z)"
  4572 proof -
  4598 proof -
  4573   have "eventually (\<lambda>w. w \<noteq> z) (at z)"
  4599   have "eventually (\<lambda>w. w \<noteq> z) (at z)"
  4580     by (blast intro: Lim_transform_eventually)
  4606     by (blast intro: Lim_transform_eventually)
  4581   with assms show ?thesis by simp
  4607   with assms show ?thesis by simp
  4582 qed
  4608 qed
  4583 
  4609 
  4584 lemma
  4610 lemma
  4585   assumes f_holo:"f holomorphic_on s" and g_holo:"g holomorphic_on s" 
  4611   assumes f_holo:"f holomorphic_on s" and g_holo:"g holomorphic_on s"
  4586           and "open s" "connected s" "z \<in> s" 
  4612           and "open s" "connected s" "z \<in> s"
  4587   assumes g_deriv:"(g has_field_derivative g') (at z)"
  4613   assumes g_deriv:"(g has_field_derivative g') (at z)"
  4588   assumes "f z \<noteq> 0" "g z = 0" "g' \<noteq> 0"
  4614   assumes "f z \<noteq> 0" "g z = 0" "g' \<noteq> 0"
  4589   shows   porder_simple_pole_deriv: "zorder (\<lambda>w. f w / g w) z = - 1"
  4615   shows   porder_simple_pole_deriv: "zorder (\<lambda>w. f w / g w) z = - 1"
  4590     and   residue_simple_pole_deriv: "residue (\<lambda>w. f w / g w) z = f z / g'"
  4616     and   residue_simple_pole_deriv: "residue (\<lambda>w. f w / g w) z = f z / g'"
  4591 proof -
  4617 proof -
  4593     using isolated_singularity_at_holomorphic[OF _ \<open>open s\<close> \<open>z\<in>s\<close>] f_holo g_holo
  4619     using isolated_singularity_at_holomorphic[OF _ \<open>open s\<close> \<open>z\<in>s\<close>] f_holo g_holo
  4594     by (meson Diff_subset holomorphic_on_subset)+
  4620     by (meson Diff_subset holomorphic_on_subset)+
  4595   have [simp]:"not_essential f z" "not_essential g z"
  4621   have [simp]:"not_essential f z" "not_essential g z"
  4596     unfolding not_essential_def using f_holo g_holo assms(3,5)
  4622     unfolding not_essential_def using f_holo g_holo assms(3,5)
  4597     by (meson continuous_on_eq_continuous_at continuous_within holomorphic_on_imp_continuous_on)+
  4623     by (meson continuous_on_eq_continuous_at continuous_within holomorphic_on_imp_continuous_on)+
  4598   have g_nconst:"\<exists>\<^sub>F w in at z. g w \<noteq>0 " 
  4624   have g_nconst:"\<exists>\<^sub>F w in at z. g w \<noteq>0 "
  4599   proof (rule ccontr)
  4625   proof (rule ccontr)
  4600     assume "\<not> (\<exists>\<^sub>F w in at z. g w \<noteq> 0)"
  4626     assume "\<not> (\<exists>\<^sub>F w in at z. g w \<noteq> 0)"
  4601     then have "\<forall>\<^sub>F w in nhds z. g w = 0"
  4627     then have "\<forall>\<^sub>F w in nhds z. g w = 0"
  4602       unfolding eventually_at eventually_nhds frequently_at using \<open>g z = 0\<close> 
  4628       unfolding eventually_at eventually_nhds frequently_at using \<open>g z = 0\<close>
  4603       by (metis open_ball UNIV_I centre_in_ball dist_commute mem_ball)
  4629       by (metis open_ball UNIV_I centre_in_ball dist_commute mem_ball)
  4604     then have "deriv g z = deriv (\<lambda>_. 0) z"
  4630     then have "deriv g z = deriv (\<lambda>_. 0) z"
  4605       by (intro deriv_cong_ev) auto
  4631       by (intro deriv_cong_ev) auto
  4606     then have "deriv g z = 0" by auto
  4632     then have "deriv g z = 0" by auto
  4607     then have "g' = 0" using g_deriv DERIV_imp_deriv by blast
  4633     then have "g' = 0" using g_deriv DERIV_imp_deriv by blast
  4608     then show False using \<open>g'\<noteq>0\<close> by auto
  4634     then show False using \<open>g'\<noteq>0\<close> by auto
  4609   qed
  4635   qed
  4610   
  4636 
  4611   have "zorder (\<lambda>w. f w / g w) z = zorder f z - zorder g z"
  4637   have "zorder (\<lambda>w. f w / g w) z = zorder f z - zorder g z"
  4612   proof -
  4638   proof -
  4613     have "\<forall>\<^sub>F w in at z. f w \<noteq>0 \<and> w\<in>s" 
  4639     have "\<forall>\<^sub>F w in at z. f w \<noteq>0 \<and> w\<in>s"
  4614       apply (rule non_zero_neighbour_alt)
  4640       apply (rule non_zero_neighbour_alt)
  4615       using assms by auto
  4641       using assms by auto
  4616     with g_nconst have "\<exists>\<^sub>F w in at z. f w * g w \<noteq> 0" 
  4642     with g_nconst have "\<exists>\<^sub>F w in at z. f w * g w \<noteq> 0"
  4617       by (elim frequently_rev_mp eventually_rev_mp,auto)
  4643       by (elim frequently_rev_mp eventually_rev_mp,auto)
  4618     then show ?thesis using zorder_divide[of f z g] by auto
  4644     then show ?thesis using zorder_divide[of f z g] by auto
  4619   qed
  4645   qed
  4620   moreover have "zorder f z=0"
  4646   moreover have "zorder f z=0"
  4621     apply (rule zorder_zero_eqI[OF f_holo \<open>open s\<close> \<open>z\<in>s\<close>])
  4647     apply (rule zorder_zero_eqI[OF f_holo \<open>open s\<close> \<open>z\<in>s\<close>])
  4625     subgoal using assms(8) by auto
  4651     subgoal using assms(8) by auto
  4626     subgoal using DERIV_imp_deriv assms(9) g_deriv by auto
  4652     subgoal using DERIV_imp_deriv assms(9) g_deriv by auto
  4627     subgoal by simp
  4653     subgoal by simp
  4628     done
  4654     done
  4629   ultimately show "zorder (\<lambda>w. f w / g w) z = - 1" by auto
  4655   ultimately show "zorder (\<lambda>w. f w / g w) z = - 1" by auto
  4630   
  4656 
  4631   show "residue (\<lambda>w. f w / g w) z = f z / g'"
  4657   show "residue (\<lambda>w. f w / g w) z = f z / g'"
  4632   proof (rule residue_simple_pole_limit[where g=id and F="at z",simplified])
  4658   proof (rule residue_simple_pole_limit[where g=id and F="at z",simplified])
  4633     show "zorder (\<lambda>w. f w / g w) z = - 1" by fact
  4659     show "zorder (\<lambda>w. f w / g w) z = - 1" by fact
  4634     show "isolated_singularity_at (\<lambda>w. f w / g w) z" 
  4660     show "isolated_singularity_at (\<lambda>w. f w / g w) z"
  4635       by (auto intro: singularity_intros)
  4661       by (auto intro: singularity_intros)
  4636     show "is_pole (\<lambda>w. f w / g w) z" 
  4662     show "is_pole (\<lambda>w. f w / g w) z"
  4637     proof (rule is_pole_divide)
  4663     proof (rule is_pole_divide)
  4638       have "\<forall>\<^sub>F x in at z. g x \<noteq> 0" 
  4664       have "\<forall>\<^sub>F x in at z. g x \<noteq> 0"
  4639         apply (rule non_zero_neighbour)
  4665         apply (rule non_zero_neighbour)
  4640         using g_nconst by auto
  4666         using g_nconst by auto
  4641       moreover have "g \<midarrow>z\<rightarrow> 0" 
  4667       moreover have "g \<midarrow>z\<rightarrow> 0"
  4642         using DERIV_isCont assms(8) continuous_at g_deriv by force
  4668         using DERIV_isCont assms(8) continuous_at g_deriv by force
  4643       ultimately show "filterlim g (at 0) (at z)" unfolding filterlim_at by simp
  4669       ultimately show "filterlim g (at 0) (at z)" unfolding filterlim_at by simp
  4644       show "isCont f z" 
  4670       show "isCont f z"
  4645         using assms(3,5) continuous_on_eq_continuous_at f_holo holomorphic_on_imp_continuous_on 
  4671         using assms(3,5) continuous_on_eq_continuous_at f_holo holomorphic_on_imp_continuous_on
  4646         by auto
  4672         by auto
  4647       show "f z \<noteq> 0" by fact
  4673       show "f z \<noteq> 0" by fact
  4648     qed
  4674     qed
  4649     show "filterlim id (at z) (at z)" by (simp add: filterlim_iff)
  4675     show "filterlim id (at z) (at z)" by (simp add: filterlim_iff)
  4650     have "((\<lambda>w. (f w * (w - z)) / g w) \<longlongrightarrow> f z / g') (at z)"
  4676     have "((\<lambda>w. (f w * (w - z)) / g w) \<longlongrightarrow> f z / g') (at z)"
  4700         have "isolated_singularity_at f p"
  4726         have "isolated_singularity_at f p"
  4701         proof -
  4727         proof -
  4702           have "f holomorphic_on ball p e1 - {p}"
  4728           have "f holomorphic_on ball p e1 - {p}"
  4703             apply (intro holomorphic_on_subset[OF f_holo])
  4729             apply (intro holomorphic_on_subset[OF f_holo])
  4704             using e1_avoid \<open>p\<in>pz\<close> unfolding avoid_def pz_def by force
  4730             using e1_avoid \<open>p\<in>pz\<close> unfolding avoid_def pz_def by force
  4705           then show ?thesis unfolding isolated_singularity_at_def 
  4731           then show ?thesis unfolding isolated_singularity_at_def
  4706             using \<open>e1>0\<close> analytic_on_open open_delete by blast
  4732             using \<open>e1>0\<close> analytic_on_open open_delete by blast
  4707         qed
  4733         qed
  4708         moreover have "not_essential f p"  
  4734         moreover have "not_essential f p"
  4709         proof (cases "is_pole f p")
  4735         proof (cases "is_pole f p")
  4710           case True
  4736           case True
  4711           then show ?thesis unfolding not_essential_def by auto
  4737           then show ?thesis unfolding not_essential_def by auto
  4712         next
  4738         next
  4713           case False
  4739           case False
  4714           then have "p\<in>s-poles" using \<open>p\<in>s\<close> poles unfolding pz_def by auto
  4740           then have "p\<in>s-poles" using \<open>p\<in>s\<close> poles unfolding pz_def by auto
  4715           moreover have "open (s-poles)"
  4741           moreover have "open (s-poles)"
  4716             using \<open>open s\<close> 
  4742             using \<open>open s\<close>
  4717             apply (elim open_Diff)
  4743             apply (elim open_Diff)
  4718             apply (rule finite_imp_closed)
  4744             apply (rule finite_imp_closed)
  4719             using finite unfolding pz_def by simp
  4745             using finite unfolding pz_def by simp
  4720           ultimately have "isCont f p"
  4746           ultimately have "isCont f p"
  4721             using holomorphic_on_imp_continuous_on[OF f_holo] continuous_on_eq_continuous_at
  4747             using holomorphic_on_imp_continuous_on[OF f_holo] continuous_on_eq_continuous_at
  4722             by auto
  4748             by auto
  4723           then show ?thesis unfolding isCont_def not_essential_def by auto
  4749           then show ?thesis unfolding isCont_def not_essential_def by auto
  4724         qed  
  4750         qed
  4725         moreover have "\<exists>\<^sub>F w in at p. f w \<noteq> 0 "
  4751         moreover have "\<exists>\<^sub>F w in at p. f w \<noteq> 0 "
  4726         proof (rule ccontr)
  4752         proof (rule ccontr)
  4727           assume "\<not> (\<exists>\<^sub>F w in at p. f w \<noteq> 0)"
  4753           assume "\<not> (\<exists>\<^sub>F w in at p. f w \<noteq> 0)"
  4728           then have "\<forall>\<^sub>F w in at p. f w= 0" unfolding frequently_def by auto
  4754           then have "\<forall>\<^sub>F w in at p. f w= 0" unfolding frequently_def by auto
  4729           then obtain rr where "rr>0" "\<forall>w\<in>ball p rr - {p}. f w =0"
  4755           then obtain rr where "rr>0" "\<forall>w\<in>ball p rr - {p}. f w =0"
  4733           ultimately have "infinite {w\<in>ball p rr-{p}. f w=0}" using infinite_super by blast
  4759           ultimately have "infinite {w\<in>ball p rr-{p}. f w=0}" using infinite_super by blast
  4734           then have "infinite pz"
  4760           then have "infinite pz"
  4735             unfolding pz_def infinite_super by auto
  4761             unfolding pz_def infinite_super by auto
  4736           then show False using \<open>finite pz\<close> by auto
  4762           then show False using \<open>finite pz\<close> by auto
  4737         qed
  4763         qed
  4738         ultimately obtain r where "pp p \<noteq> 0" and r:"r>0" "pp holomorphic_on cball p r" 
  4764         ultimately obtain r where "pp p \<noteq> 0" and r:"r>0" "pp holomorphic_on cball p r"
  4739                   "(\<forall>w\<in>cball p r - {p}. f w = pp w * (w - p) powr of_int po \<and> pp w \<noteq> 0)"
  4765                   "(\<forall>w\<in>cball p r - {p}. f w = pp w * (w - p) powr of_int po \<and> pp w \<noteq> 0)"
  4740           using zorder_exist[of f p,folded po_def pp_def] by auto
  4766           using zorder_exist[of f p,folded po_def pp_def] by auto
  4741         define r1 where "r1=min r e1 / 2"
  4767         define r1 where "r1=min r e1 / 2"
  4742         have "r1<e1" unfolding r1_def using \<open>e1>0\<close> \<open>r>0\<close> by auto
  4768         have "r1<e1" unfolding r1_def using \<open>e1>0\<close> \<open>r>0\<close> by auto
  4743         moreover have "r1>0" "pp holomorphic_on cball p r1" 
  4769         moreover have "r1>0" "pp holomorphic_on cball p r1"
  4744                   "(\<forall>w\<in>cball p r1 - {p}. f w = pp w * (w - p) powr of_int po \<and> pp w \<noteq> 0)"
  4770                   "(\<forall>w\<in>cball p r1 - {p}. f w = pp w * (w - p) powr of_int po \<and> pp w \<noteq> 0)"
  4745           unfolding r1_def using \<open>e1>0\<close> r by auto
  4771           unfolding r1_def using \<open>e1>0\<close> r by auto
  4746         ultimately show ?thesis using that \<open>pp p\<noteq>0\<close> by auto
  4772         ultimately show ?thesis using that \<open>pp p\<noteq>0\<close> by auto
  4747       qed
  4773       qed
  4748       
  4774 
  4749       define e2 where "e2 \<equiv> r/2"
  4775       define e2 where "e2 \<equiv> r/2"
  4750       have "e2>0" using \<open>r>0\<close> unfolding e2_def by auto
  4776       have "e2>0" using \<open>r>0\<close> unfolding e2_def by auto
  4751       define anal where "anal \<equiv> \<lambda>w. deriv pp w * h w / pp w"
  4777       define anal where "anal \<equiv> \<lambda>w. deriv pp w * h w / pp w"
  4752       define prin where "prin \<equiv> \<lambda>w. po * h w / (w - p)"
  4778       define prin where "prin \<equiv> \<lambda>w. po * h w / (w - p)"
  4753       have "((\<lambda>w.  prin w + anal w) has_contour_integral c * po * h p) (circlepath p e2)"
  4779       have "((\<lambda>w.  prin w + anal w) has_contour_integral c * po * h p) (circlepath p e2)"
  4778         moreover have der_f':"deriv f' w = po * pp w * (w-p) powr (po - 1) + deriv pp w * (w-p) powr po"
  4804         moreover have der_f':"deriv f' w = po * pp w * (w-p) powr (po - 1) + deriv pp w * (w-p) powr po"
  4779         proof (rule DERIV_imp_deriv)
  4805         proof (rule DERIV_imp_deriv)
  4780           have "(pp has_field_derivative (deriv pp w)) (at w)"
  4806           have "(pp has_field_derivative (deriv pp w)) (at w)"
  4781             using DERIV_deriv_iff_has_field_derivative pp_holo \<open>w\<noteq>p\<close>
  4807             using DERIV_deriv_iff_has_field_derivative pp_holo \<open>w\<noteq>p\<close>
  4782             by (meson open_ball \<open>w \<in> ball p r\<close> ball_subset_cball holomorphic_derivI holomorphic_on_subset)
  4808             by (meson open_ball \<open>w \<in> ball p r\<close> ball_subset_cball holomorphic_derivI holomorphic_on_subset)
  4783           then show " (f' has_field_derivative of_int po * pp w * (w - p) powr of_int (po - 1) 
  4809           then show " (f' has_field_derivative of_int po * pp w * (w - p) powr of_int (po - 1)
  4784                   + deriv pp w * (w - p) powr of_int po) (at w)"
  4810                   + deriv pp w * (w - p) powr of_int po) (at w)"
  4785             unfolding f'_def using \<open>w\<noteq>p\<close>
  4811             unfolding f'_def using \<open>w\<noteq>p\<close>
  4786             by (auto intro!: derivative_eq_intros DERIV_cong[OF has_field_derivative_powr_of_int])
  4812             by (auto intro!: derivative_eq_intros DERIV_cong[OF has_field_derivative_powr_of_int])
  4787         qed
  4813         qed
  4788         ultimately show "prin w + anal w = ff' w"
  4814         ultimately show "prin w + anal w = ff' w"
  4803             by (auto intro!: holomorphic_intros)
  4829             by (auto intro!: holomorphic_intros)
  4804         next
  4830         next
  4805           have "ball p e1 - {p} \<subseteq> s - poles"
  4831           have "ball p e1 - {p} \<subseteq> s - poles"
  4806             using ball_subset_cball e1_avoid[unfolded avoid_def] unfolding pz_def
  4832             using ball_subset_cball e1_avoid[unfolded avoid_def] unfolding pz_def
  4807             by auto
  4833             by auto
  4808           then have "ball p r - {p} \<subseteq> s - poles" 
  4834           then have "ball p r - {p} \<subseteq> s - poles"
  4809             apply (elim dual_order.trans)
  4835             apply (elim dual_order.trans)
  4810             using \<open>r<e1\<close> by auto
  4836             using \<open>r<e1\<close> by auto
  4811           then show "f holomorphic_on ball p r - {p}" using f_holo
  4837           then show "f holomorphic_on ball p r - {p}" using f_holo
  4812             by auto
  4838             by auto
  4813         next
  4839         next
  4977       moreover have "t\<in>s"
  5003       moreover have "t\<in>s"
  4978         using contra_subsetD path_image_def path_fg t_def that by fastforce
  5004         using contra_subsetD path_image_def path_fg t_def that by fastforce
  4979       ultimately have "(h has_field_derivative der t) (at t)"
  5005       ultimately have "(h has_field_derivative der t) (at t)"
  4980         unfolding h_def der_def using g_holo f_holo \<open>open s\<close>
  5006         unfolding h_def der_def using g_holo f_holo \<open>open s\<close>
  4981         by (auto intro!: holomorphic_derivI derivative_eq_intros)
  5007         by (auto intro!: holomorphic_derivI derivative_eq_intros)
  4982       then show "h field_differentiable at (\<gamma> x)" 
  5008       then show "h field_differentiable at (\<gamma> x)"
  4983         unfolding t_def field_differentiable_def by blast
  5009         unfolding t_def field_differentiable_def by blast
  4984     qed
  5010     qed
  4985     then have " ((/) 1 has_contour_integral 0) (h \<circ> \<gamma>)
  5011     then have " ((/) 1 has_contour_integral 0) (h \<circ> \<gamma>)
  4986                   = ((\<lambda>x. deriv h x / h x) has_contour_integral 0) \<gamma>"
  5012                   = ((\<lambda>x. deriv h x / h x) has_contour_integral 0) \<gamma>"
  4987       unfolding has_contour_integral
  5013       unfolding has_contour_integral