src/HOL/Analysis/Conformal_Mappings.thy
 author wenzelm Sun Sep 18 20:33:48 2016 +0200 (2016-09-18) changeset 63915 bab633745c7f parent 63627 6ddb43c6b711 child 63918 6bf55e6e0b75 permissions -rw-r--r--
tuned proofs;
```     1 section \<open>Conformal Mappings. Consequences of Cauchy's integral theorem.\<close>
```
```     2
```
```     3 text\<open>By John Harrison et al.  Ported from HOL Light by L C Paulson (2016)\<close>
```
```     4
```
```     5 text\<open>Also Cauchy's residue theorem by Wenda Li (2016)\<close>
```
```     6
```
```     7 theory Conformal_Mappings
```
```     8 imports "~~/src/HOL/Analysis/Cauchy_Integral_Theorem"
```
```     9
```
```    10 begin
```
```    11
```
```    12 subsection\<open>Cauchy's inequality and more versions of Liouville\<close>
```
```    13
```
```    14 lemma Cauchy_higher_deriv_bound:
```
```    15     assumes holf: "f holomorphic_on (ball z r)"
```
```    16         and contf: "continuous_on (cball z r) f"
```
```    17         and "0 < r" and "0 < n"
```
```    18         and fin : "\<And>w. w \<in> ball z r \<Longrightarrow> f w \<in> ball y B0"
```
```    19       shows "norm ((deriv ^^ n) f z) \<le> (fact n) * B0 / r^n"
```
```    20 proof -
```
```    21   have "0 < B0" using \<open>0 < r\<close> fin [of z]
```
```    22     by (metis ball_eq_empty ex_in_conv fin not_less)
```
```    23   have le_B0: "\<And>w. cmod (w - z) \<le> r \<Longrightarrow> cmod (f w - y) \<le> B0"
```
```    24     apply (rule continuous_on_closure_norm_le [of "ball z r" "\<lambda>w. f w - y"])
```
```    25     apply (auto simp: \<open>0 < r\<close>  dist_norm norm_minus_commute)
```
```    26     apply (rule continuous_intros contf)+
```
```    27     using fin apply (simp add: dist_commute dist_norm less_eq_real_def)
```
```    28     done
```
```    29   have "(deriv ^^ n) f z = (deriv ^^ n) (\<lambda>w. f w) z - (deriv ^^ n) (\<lambda>w. y) z"
```
```    30     using \<open>0 < n\<close> by simp
```
```    31   also have "... = (deriv ^^ n) (\<lambda>w. f w - y) z"
```
```    32     by (rule higher_deriv_diff [OF holf, symmetric]) (auto simp: \<open>0 < r\<close>)
```
```    33   finally have "(deriv ^^ n) f z = (deriv ^^ n) (\<lambda>w. f w - y) z" .
```
```    34   have contf': "continuous_on (cball z r) (\<lambda>u. f u - y)"
```
```    35     by (rule contf continuous_intros)+
```
```    36   have holf': "(\<lambda>u. (f u - y)) holomorphic_on (ball z r)"
```
```    37     by (simp add: holf holomorphic_on_diff)
```
```    38   define a where "a = (2 * pi)/(fact n)"
```
```    39   have "0 < a"  by (simp add: a_def)
```
```    40   have "B0/r^(Suc n)*2 * pi * r = a*((fact n)*B0/r^n)"
```
```    41     using \<open>0 < r\<close> by (simp add: a_def divide_simps)
```
```    42   have der_dif: "(deriv ^^ n) (\<lambda>w. f w - y) z = (deriv ^^ n) f z"
```
```    43     using \<open>0 < r\<close> \<open>0 < n\<close>
```
```    44     by (auto simp: higher_deriv_diff [OF holf holomorphic_on_const])
```
```    45   have "norm ((2 * of_real pi * \<i>)/(fact n) * (deriv ^^ n) (\<lambda>w. f w - y) z)
```
```    46         \<le> (B0/r^(Suc n)) * (2 * pi * r)"
```
```    47     apply (rule has_contour_integral_bound_circlepath [of "(\<lambda>u. (f u - y)/(u - z)^(Suc n))" _ z])
```
```    48     using Cauchy_has_contour_integral_higher_derivative_circlepath [OF contf' holf']
```
```    49     using \<open>0 < B0\<close> \<open>0 < r\<close>
```
```    50     apply (auto simp: norm_divide norm_mult norm_power divide_simps le_B0)
```
```    51     done
```
```    52   then show ?thesis
```
```    53     using \<open>0 < r\<close>
```
```    54     by (auto simp: norm_divide norm_mult norm_power field_simps der_dif le_B0)
```
```    55 qed
```
```    56
```
```    57 proposition Cauchy_inequality:
```
```    58     assumes holf: "f holomorphic_on (ball \<xi> r)"
```
```    59         and contf: "continuous_on (cball \<xi> r) f"
```
```    60         and "0 < r"
```
```    61         and nof: "\<And>x. norm(\<xi>-x) = r \<Longrightarrow> norm(f x) \<le> B"
```
```    62       shows "norm ((deriv ^^ n) f \<xi>) \<le> (fact n) * B / r^n"
```
```    63 proof -
```
```    64   obtain x where "norm (\<xi>-x) = r"
```
```    65     by (metis abs_of_nonneg add_diff_cancel_left' \<open>0 < r\<close> diff_add_cancel
```
```    66                  dual_order.strict_implies_order norm_of_real)
```
```    67   then have "0 \<le> B"
```
```    68     by (metis nof norm_not_less_zero not_le order_trans)
```
```    69   have  "((\<lambda>u. f u / (u - \<xi>) ^ Suc n) has_contour_integral (2 * pi) * \<i> / fact n * (deriv ^^ n) f \<xi>)
```
```    70          (circlepath \<xi> r)"
```
```    71     apply (rule Cauchy_has_contour_integral_higher_derivative_circlepath [OF contf holf])
```
```    72     using \<open>0 < r\<close> by simp
```
```    73   then have "norm ((2 * pi * \<i>)/(fact n) * (deriv ^^ n) f \<xi>) \<le> (B / r^(Suc n)) * (2 * pi * r)"
```
```    74     apply (rule has_contour_integral_bound_circlepath)
```
```    75     using \<open>0 \<le> B\<close> \<open>0 < r\<close>
```
```    76     apply (simp_all add: norm_divide norm_power nof frac_le norm_minus_commute del: power_Suc)
```
```    77     done
```
```    78   then show ?thesis using \<open>0 < r\<close>
```
```    79     by (simp add: norm_divide norm_mult field_simps)
```
```    80 qed
```
```    81
```
```    82 proposition Liouville_polynomial:
```
```    83     assumes holf: "f holomorphic_on UNIV"
```
```    84         and nof: "\<And>z. A \<le> norm z \<Longrightarrow> norm(f z) \<le> B * norm z ^ n"
```
```    85       shows "f \<xi> = (\<Sum>k\<le>n. (deriv^^k) f 0 / fact k * \<xi> ^ k)"
```
```    86 proof (cases rule: le_less_linear [THEN disjE])
```
```    87   assume "B \<le> 0"
```
```    88   then have "\<And>z. A \<le> norm z \<Longrightarrow> norm(f z) = 0"
```
```    89     by (metis nof less_le_trans zero_less_mult_iff neqE norm_not_less_zero norm_power not_le)
```
```    90   then have f0: "(f \<longlongrightarrow> 0) at_infinity"
```
```    91     using Lim_at_infinity by force
```
```    92   then have [simp]: "f = (\<lambda>w. 0)"
```
```    93     using Liouville_weak [OF holf, of 0]
```
```    94     by (simp add: eventually_at_infinity f0) meson
```
```    95   show ?thesis by simp
```
```    96 next
```
```    97   assume "0 < B"
```
```    98   have "((\<lambda>k. (deriv ^^ k) f 0 / (fact k) * (\<xi> - 0)^k) sums f \<xi>)"
```
```    99     apply (rule holomorphic_power_series [where r = "norm \<xi> + 1"])
```
```   100     using holf holomorphic_on_subset apply auto
```
```   101     done
```
```   102   then have sumsf: "((\<lambda>k. (deriv ^^ k) f 0 / (fact k) * \<xi>^k) sums f \<xi>)" by simp
```
```   103   have "(deriv ^^ k) f 0 / fact k * \<xi> ^ k = 0" if "k>n" for k
```
```   104   proof (cases "(deriv ^^ k) f 0 = 0")
```
```   105     case True then show ?thesis by simp
```
```   106   next
```
```   107     case False
```
```   108     define w where "w = complex_of_real (fact k * B / cmod ((deriv ^^ k) f 0) + (\<bar>A\<bar> + 1))"
```
```   109     have "1 \<le> abs (fact k * B / cmod ((deriv ^^ k) f 0) + (\<bar>A\<bar> + 1))"
```
```   110       using \<open>0 < B\<close> by simp
```
```   111     then have wge1: "1 \<le> norm w"
```
```   112       by (metis norm_of_real w_def)
```
```   113     then have "w \<noteq> 0" by auto
```
```   114     have kB: "0 < fact k * B"
```
```   115       using \<open>0 < B\<close> by simp
```
```   116     then have "0 \<le> fact k * B / cmod ((deriv ^^ k) f 0)"
```
```   117       by simp
```
```   118     then have wgeA: "A \<le> cmod w"
```
```   119       by (simp only: w_def norm_of_real)
```
```   120     have "fact k * B / cmod ((deriv ^^ k) f 0) < abs (fact k * B / cmod ((deriv ^^ k) f 0) + (\<bar>A\<bar> + 1))"
```
```   121       using \<open>0 < B\<close> by simp
```
```   122     then have wge: "fact k * B / cmod ((deriv ^^ k) f 0) < norm w"
```
```   123       by (metis norm_of_real w_def)
```
```   124     then have "fact k * B / norm w < cmod ((deriv ^^ k) f 0)"
```
```   125       using False by (simp add: divide_simps mult.commute split: if_split_asm)
```
```   126     also have "... \<le> fact k * (B * norm w ^ n) / norm w ^ k"
```
```   127       apply (rule Cauchy_inequality)
```
```   128          using holf holomorphic_on_subset apply force
```
```   129         using holf holomorphic_on_imp_continuous_on holomorphic_on_subset apply blast
```
```   130        using \<open>w \<noteq> 0\<close> apply (simp add:)
```
```   131        by (metis nof wgeA dist_0_norm dist_norm)
```
```   132     also have "... = fact k * (B * 1 / cmod w ^ (k-n))"
```
```   133       apply (simp only: mult_cancel_left times_divide_eq_right [symmetric])
```
```   134       using \<open>k>n\<close> \<open>w \<noteq> 0\<close> \<open>0 < B\<close> apply (simp add: divide_simps semiring_normalization_rules)
```
```   135       done
```
```   136     also have "... = fact k * B / cmod w ^ (k-n)"
```
```   137       by simp
```
```   138     finally have "fact k * B / cmod w < fact k * B / cmod w ^ (k - n)" .
```
```   139     then have "1 / cmod w < 1 / cmod w ^ (k - n)"
```
```   140       by (metis kB divide_inverse inverse_eq_divide mult_less_cancel_left_pos)
```
```   141     then have "cmod w ^ (k - n) < cmod w"
```
```   142       by (metis frac_le le_less_trans norm_ge_zero norm_one not_less order_refl wge1 zero_less_one)
```
```   143     with self_le_power [OF wge1] have False
```
```   144       by (meson diff_is_0_eq not_gr0 not_le that)
```
```   145     then show ?thesis by blast
```
```   146   qed
```
```   147   then have "(deriv ^^ (k + Suc n)) f 0 / fact (k + Suc n) * \<xi> ^ (k + Suc n) = 0" for k
```
```   148     using not_less_eq by blast
```
```   149   then have "(\<lambda>i. (deriv ^^ (i + Suc n)) f 0 / fact (i + Suc n) * \<xi> ^ (i + Suc n)) sums 0"
```
```   150     by (rule sums_0)
```
```   151   with sums_split_initial_segment [OF sumsf, where n = "Suc n"]
```
```   152   show ?thesis
```
```   153     using atLeast0AtMost lessThan_Suc_atMost sums_unique2 by fastforce
```
```   154 qed
```
```   155
```
```   156 text\<open>Every bounded entire function is a constant function.\<close>
```
```   157 theorem Liouville_theorem:
```
```   158     assumes holf: "f holomorphic_on UNIV"
```
```   159         and bf: "bounded (range f)"
```
```   160     obtains c where "\<And>z. f z = c"
```
```   161 proof -
```
```   162   obtain B where "\<And>z. cmod (f z) \<le> B"
```
```   163     by (meson bf bounded_pos rangeI)
```
```   164   then show ?thesis
```
```   165     using Liouville_polynomial [OF holf, of 0 B 0, simplified] that by blast
```
```   166 qed
```
```   167
```
```   168
```
```   169
```
```   170 text\<open>A holomorphic function f has only isolated zeros unless f is 0.\<close>
```
```   171
```
```   172 proposition powser_0_nonzero:
```
```   173   fixes a :: "nat \<Rightarrow> 'a::{real_normed_field,banach}"
```
```   174   assumes r: "0 < r"
```
```   175       and sm: "\<And>x. norm (x - \<xi>) < r \<Longrightarrow> (\<lambda>n. a n * (x - \<xi>) ^ n) sums (f x)"
```
```   176       and [simp]: "f \<xi> = 0"
```
```   177       and m0: "a m \<noteq> 0" and "m>0"
```
```   178   obtains s where "0 < s" and "\<And>z. z \<in> cball \<xi> s - {\<xi>} \<Longrightarrow> f z \<noteq> 0"
```
```   179 proof -
```
```   180   have "r \<le> conv_radius a"
```
```   181     using sm sums_summable by (auto simp: le_conv_radius_iff [where \<xi>=\<xi>])
```
```   182   obtain m where am: "a m \<noteq> 0" and az [simp]: "(\<And>n. n<m \<Longrightarrow> a n = 0)"
```
```   183     apply (rule_tac m = "LEAST n. a n \<noteq> 0" in that)
```
```   184     using m0
```
```   185     apply (rule LeastI2)
```
```   186     apply (fastforce intro:  dest!: not_less_Least)+
```
```   187     done
```
```   188   define b where "b i = a (i+m) / a m" for i
```
```   189   define g where "g x = suminf (\<lambda>i. b i * (x - \<xi>) ^ i)" for x
```
```   190   have [simp]: "b 0 = 1"
```
```   191     by (simp add: am b_def)
```
```   192   { fix x::'a
```
```   193     assume "norm (x - \<xi>) < r"
```
```   194     then have "(\<lambda>n. (a m * (x - \<xi>)^m) * (b n * (x - \<xi>)^n)) sums (f x)"
```
```   195       using am az sm sums_zero_iff_shift [of m "(\<lambda>n. a n * (x - \<xi>) ^ n)" "f x"]
```
```   196       by (simp add: b_def monoid_mult_class.power_add algebra_simps)
```
```   197     then have "x \<noteq> \<xi> \<Longrightarrow> (\<lambda>n. b n * (x - \<xi>)^n) sums (f x / (a m * (x - \<xi>)^m))"
```
```   198       using am by (simp add: sums_mult_D)
```
```   199   } note bsums = this
```
```   200   then have  "norm (x - \<xi>) < r \<Longrightarrow> summable (\<lambda>n. b n * (x - \<xi>)^n)" for x
```
```   201     using sums_summable by (cases "x=\<xi>") auto
```
```   202   then have "r \<le> conv_radius b"
```
```   203     by (simp add: le_conv_radius_iff [where \<xi>=\<xi>])
```
```   204   then have "r/2 < conv_radius b"
```
```   205     using not_le order_trans r by fastforce
```
```   206   then have "continuous_on (cball \<xi> (r/2)) g"
```
```   207     using powser_continuous_suminf [of "r/2" b \<xi>] by (simp add: g_def)
```
```   208   then obtain s where "s>0"  "\<And>x. \<lbrakk>norm (x - \<xi>) \<le> s; norm (x - \<xi>) \<le> r/2\<rbrakk> \<Longrightarrow> dist (g x) (g \<xi>) < 1/2"
```
```   209     apply (rule continuous_onE [where x=\<xi> and e = "1/2"])
```
```   210     using r apply (auto simp: norm_minus_commute dist_norm)
```
```   211     done
```
```   212   moreover have "g \<xi> = 1"
```
```   213     by (simp add: g_def)
```
```   214   ultimately have gnz: "\<And>x. \<lbrakk>norm (x - \<xi>) \<le> s; norm (x - \<xi>) \<le> r/2\<rbrakk> \<Longrightarrow> (g x) \<noteq> 0"
```
```   215     by fastforce
```
```   216   have "f x \<noteq> 0" if "x \<noteq> \<xi>" "norm (x - \<xi>) \<le> s" "norm (x - \<xi>) \<le> r/2" for x
```
```   217     using bsums [of x] that gnz [of x]
```
```   218     apply (auto simp: g_def)
```
```   219     using r sums_iff by fastforce
```
```   220   then show ?thesis
```
```   221     apply (rule_tac s="min s (r/2)" in that)
```
```   222     using \<open>0 < r\<close> \<open>0 < s\<close> by (auto simp: dist_commute dist_norm)
```
```   223 qed
```
```   224
```
```   225 proposition isolated_zeros:
```
```   226   assumes holf: "f holomorphic_on S"
```
```   227       and "open S" "connected S" "\<xi> \<in> S" "f \<xi> = 0" "\<beta> \<in> S" "f \<beta> \<noteq> 0"
```
```   228   obtains r where "0 < r" "ball \<xi> r \<subseteq> S" "\<And>z. z \<in> ball \<xi> r - {\<xi>} \<Longrightarrow> f z \<noteq> 0"
```
```   229 proof -
```
```   230   obtain r where "0 < r" and r: "ball \<xi> r \<subseteq> S"
```
```   231     using \<open>open S\<close> \<open>\<xi> \<in> S\<close> open_contains_ball_eq by blast
```
```   232   have powf: "((\<lambda>n. (deriv ^^ n) f \<xi> / (fact n) * (z - \<xi>)^n) sums f z)" if "z \<in> ball \<xi> r" for z
```
```   233     apply (rule holomorphic_power_series [OF _ that])
```
```   234     apply (rule holomorphic_on_subset [OF holf r])
```
```   235     done
```
```   236   obtain m where m: "(deriv ^^ m) f \<xi> / (fact m) \<noteq> 0"
```
```   237     using holomorphic_fun_eq_0_on_connected [OF holf \<open>open S\<close> \<open>connected S\<close> _ \<open>\<xi> \<in> S\<close> \<open>\<beta> \<in> S\<close>] \<open>f \<beta> \<noteq> 0\<close>
```
```   238     by auto
```
```   239   then have "m \<noteq> 0" using assms(5) funpow_0 by fastforce
```
```   240   obtain s where "0 < s" and s: "\<And>z. z \<in> cball \<xi> s - {\<xi>} \<Longrightarrow> f z \<noteq> 0"
```
```   241     apply (rule powser_0_nonzero [OF \<open>0 < r\<close> powf \<open>f \<xi> = 0\<close> m])
```
```   242     using \<open>m \<noteq> 0\<close> by (auto simp: dist_commute dist_norm)
```
```   243   have "0 < min r s"  by (simp add: \<open>0 < r\<close> \<open>0 < s\<close>)
```
```   244   then show ?thesis
```
```   245     apply (rule that)
```
```   246     using r s by auto
```
```   247 qed
```
```   248
```
```   249
```
```   250 proposition analytic_continuation:
```
```   251   assumes holf: "f holomorphic_on S"
```
```   252       and S: "open S" "connected S"
```
```   253       and "U \<subseteq> S" "\<xi> \<in> S"
```
```   254       and "\<xi> islimpt U"
```
```   255       and fU0 [simp]: "\<And>z. z \<in> U \<Longrightarrow> f z = 0"
```
```   256       and "w \<in> S"
```
```   257     shows "f w = 0"
```
```   258 proof -
```
```   259   obtain e where "0 < e" and e: "cball \<xi> e \<subseteq> S"
```
```   260     using \<open>open S\<close> \<open>\<xi> \<in> S\<close> open_contains_cball_eq by blast
```
```   261   define T where "T = cball \<xi> e \<inter> U"
```
```   262   have contf: "continuous_on (closure T) f"
```
```   263     by (metis T_def closed_cball closure_minimal e holf holomorphic_on_imp_continuous_on
```
```   264               holomorphic_on_subset inf.cobounded1)
```
```   265   have fT0 [simp]: "\<And>x. x \<in> T \<Longrightarrow> f x = 0"
```
```   266     by (simp add: T_def)
```
```   267   have "\<And>r. \<lbrakk>\<forall>e>0. \<exists>x'\<in>U. x' \<noteq> \<xi> \<and> dist x' \<xi> < e; 0 < r\<rbrakk> \<Longrightarrow> \<exists>x'\<in>cball \<xi> e \<inter> U. x' \<noteq> \<xi> \<and> dist x' \<xi> < r"
```
```   268     by (metis \<open>0 < e\<close> IntI dist_commute less_eq_real_def mem_cball min_less_iff_conj)
```
```   269   then have "\<xi> islimpt T" using \<open>\<xi> islimpt U\<close>
```
```   270     by (auto simp: T_def islimpt_approachable)
```
```   271   then have "\<xi> \<in> closure T"
```
```   272     by (simp add: closure_def)
```
```   273   then have "f \<xi> = 0"
```
```   274     by (auto simp: continuous_constant_on_closure [OF contf])
```
```   275   show ?thesis
```
```   276     apply (rule ccontr)
```
```   277     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     by (metis open_ball \<open>\<xi> islimpt T\<close> centre_in_ball fT0 insertE insert_Diff islimptE)
```
```   279 qed
```
```   280
```
```   281
```
```   282 subsection\<open>Open mapping theorem\<close>
```
```   283
```
```   284 lemma holomorphic_contract_to_zero:
```
```   285   assumes contf: "continuous_on (cball \<xi> r) f"
```
```   286       and holf: "f holomorphic_on ball \<xi> r"
```
```   287       and "0 < r"
```
```   288       and norm_less: "\<And>z. norm(\<xi> - z) = r \<Longrightarrow> norm(f \<xi>) < norm(f z)"
```
```   289   obtains z where "z \<in> ball \<xi> r" "f z = 0"
```
```   290 proof -
```
```   291   { assume fnz: "\<And>w. w \<in> ball \<xi> r \<Longrightarrow> f w \<noteq> 0"
```
```   292     then have "0 < norm (f \<xi>)"
```
```   293       by (simp add: \<open>0 < r\<close>)
```
```   294     have fnz': "\<And>w. w \<in> cball \<xi> r \<Longrightarrow> f w \<noteq> 0"
```
```   295       by (metis norm_less dist_norm fnz less_eq_real_def mem_ball mem_cball norm_not_less_zero norm_zero)
```
```   296     have "frontier(cball \<xi> r) \<noteq> {}"
```
```   297       using \<open>0 < r\<close> by simp
```
```   298     define g where [abs_def]: "g z = inverse (f z)" for z
```
```   299     have contg: "continuous_on (cball \<xi> r) g"
```
```   300       unfolding g_def using contf continuous_on_inverse fnz' by blast
```
```   301     have holg: "g holomorphic_on ball \<xi> r"
```
```   302       unfolding g_def using fnz holf holomorphic_on_inverse by blast
```
```   303     have "frontier (cball \<xi> r) \<subseteq> cball \<xi> r"
```
```   304       by (simp add: subset_iff)
```
```   305     then have contf': "continuous_on (frontier (cball \<xi> r)) f"
```
```   306           and contg': "continuous_on (frontier (cball \<xi> r)) g"
```
```   307       by (blast intro: contf contg continuous_on_subset)+
```
```   308     have froc: "frontier(cball \<xi> r) \<noteq> {}"
```
```   309       using \<open>0 < r\<close> by simp
```
```   310     moreover have "continuous_on (frontier (cball \<xi> r)) (norm o f)"
```
```   311       using contf' continuous_on_compose continuous_on_norm_id by blast
```
```   312     ultimately obtain w where w: "w \<in> frontier(cball \<xi> r)"
```
```   313                           and now: "\<And>x. x \<in> frontier(cball \<xi> r) \<Longrightarrow> norm (f w) \<le> norm (f x)"
```
```   314       apply (rule bexE [OF continuous_attains_inf [OF compact_frontier [OF compact_cball]]])
```
```   315       apply (simp add:)
```
```   316       done
```
```   317     then have fw: "0 < norm (f w)"
```
```   318       by (simp add: fnz')
```
```   319     have "continuous_on (frontier (cball \<xi> r)) (norm o g)"
```
```   320       using contg' continuous_on_compose continuous_on_norm_id by blast
```
```   321     then obtain v where v: "v \<in> frontier(cball \<xi> r)"
```
```   322                and nov: "\<And>x. x \<in> frontier(cball \<xi> r) \<Longrightarrow> norm (g v) \<ge> norm (g x)"
```
```   323       apply (rule bexE [OF continuous_attains_sup [OF compact_frontier [OF compact_cball] froc]])
```
```   324       apply (simp add:)
```
```   325       done
```
```   326     then have fv: "0 < norm (f v)"
```
```   327       by (simp add: fnz')
```
```   328     have "norm ((deriv ^^ 0) g \<xi>) \<le> fact 0 * norm (g v) / r ^ 0"
```
```   329       by (rule Cauchy_inequality [OF holg contg \<open>0 < r\<close>]) (simp add: dist_norm nov)
```
```   330     then have "cmod (g \<xi>) \<le> norm (g v)"
```
```   331       by simp
```
```   332     with w have wr: "norm (\<xi> - w) = r" and nfw: "norm (f w) \<le> norm (f \<xi>)"
```
```   333       apply (simp_all add: dist_norm)
```
```   334       by (metis \<open>0 < cmod (f \<xi>)\<close> g_def less_imp_inverse_less norm_inverse not_le now order_trans v)
```
```   335     with fw have False
```
```   336       using norm_less by force
```
```   337   }
```
```   338   with that show ?thesis by blast
```
```   339 qed
```
```   340
```
```   341
```
```   342 theorem open_mapping_thm:
```
```   343   assumes holf: "f holomorphic_on S"
```
```   344       and S: "open S" "connected S"
```
```   345       and "open U" "U \<subseteq> S"
```
```   346       and fne: "~ f constant_on S"
```
```   347     shows "open (f ` U)"
```
```   348 proof -
```
```   349   have *: "open (f ` U)"
```
```   350           if "U \<noteq> {}" and U: "open U" "connected U" and "f holomorphic_on U" and fneU: "\<And>x. \<exists>y \<in> U. f y \<noteq> x"
```
```   351           for U
```
```   352   proof (clarsimp simp: open_contains_ball)
```
```   353     fix \<xi> assume \<xi>: "\<xi> \<in> U"
```
```   354     show "\<exists>e>0. ball (f \<xi>) e \<subseteq> f ` U"
```
```   355     proof -
```
```   356       have hol: "(\<lambda>z. f z - f \<xi>) holomorphic_on U"
```
```   357         by (rule holomorphic_intros that)+
```
```   358       obtain s where "0 < s" and sbU: "ball \<xi> s \<subseteq> U"
```
```   359                  and sne: "\<And>z. z \<in> ball \<xi> s - {\<xi>} \<Longrightarrow> (\<lambda>z. f z - f \<xi>) z \<noteq> 0"
```
```   360         using isolated_zeros [OF hol U \<xi>]  by (metis fneU right_minus_eq)
```
```   361       obtain r where "0 < r" and r: "cball \<xi> r \<subseteq> ball \<xi> s"
```
```   362         apply (rule_tac r="s/2" in that)
```
```   363         using \<open>0 < s\<close> by auto
```
```   364       have "cball \<xi> r \<subseteq> U"
```
```   365         using sbU r by blast
```
```   366       then have frsbU: "frontier (cball \<xi> r) \<subseteq> U"
```
```   367         using Diff_subset frontier_def order_trans by fastforce
```
```   368       then have cof: "compact (frontier(cball \<xi> r))"
```
```   369         by blast
```
```   370       have frne: "frontier (cball \<xi> r) \<noteq> {}"
```
```   371         using \<open>0 < r\<close> by auto
```
```   372       have contfr: "continuous_on (frontier (cball \<xi> r)) (\<lambda>z. norm (f z - f \<xi>))"
```
```   373         apply (rule continuous_on_compose2 [OF Complex_Analysis_Basics.continuous_on_norm_id])
```
```   374         using hol frsbU holomorphic_on_imp_continuous_on holomorphic_on_subset by blast+
```
```   375       obtain w where "norm (\<xi> - w) = r"
```
```   376                  and w: "(\<And>z. norm (\<xi> - z) = r \<Longrightarrow> norm (f w - f \<xi>) \<le> norm(f z - f \<xi>))"
```
```   377         apply (rule bexE [OF continuous_attains_inf [OF cof frne contfr]])
```
```   378         apply (simp add: dist_norm)
```
```   379         done
```
```   380       moreover define \<epsilon> where "\<epsilon> \<equiv> norm (f w - f \<xi>) / 3"
```
```   381       ultimately have "0 < \<epsilon>"
```
```   382         using \<open>0 < r\<close> dist_complex_def r sne by auto
```
```   383       have "ball (f \<xi>) \<epsilon> \<subseteq> f ` U"
```
```   384       proof
```
```   385         fix \<gamma>
```
```   386         assume \<gamma>: "\<gamma> \<in> ball (f \<xi>) \<epsilon>"
```
```   387         have *: "cmod (\<gamma> - f \<xi>) < cmod (\<gamma> - f z)" if "cmod (\<xi> - z) = r" for z
```
```   388         proof -
```
```   389           have lt: "cmod (f w - f \<xi>) / 3 < cmod (\<gamma> - f z)"
```
```   390             using w [OF that] \<gamma>
```
```   391             using dist_triangle2 [of "f \<xi>" "\<gamma>"  "f z"] dist_triangle2 [of "f \<xi>" "f z" \<gamma>]
```
```   392             by (simp add: \<epsilon>_def dist_norm norm_minus_commute)
```
```   393           show ?thesis
```
```   394             by (metis \<epsilon>_def dist_commute dist_norm less_trans lt mem_ball \<gamma>)
```
```   395        qed
```
```   396        have "continuous_on (cball \<xi> r) (\<lambda>z. \<gamma> - f z)"
```
```   397           apply (rule continuous_intros)+
```
```   398           using \<open>cball \<xi> r \<subseteq> U\<close> \<open>f holomorphic_on U\<close>
```
```   399           apply (blast intro: continuous_on_subset holomorphic_on_imp_continuous_on)
```
```   400           done
```
```   401         moreover have "(\<lambda>z. \<gamma> - f z) holomorphic_on ball \<xi> r"
```
```   402           apply (rule holomorphic_intros)+
```
```   403           apply (metis \<open>cball \<xi> r \<subseteq> U\<close> \<open>f holomorphic_on U\<close> holomorphic_on_subset interior_cball interior_subset)
```
```   404           done
```
```   405         ultimately obtain z where "z \<in> ball \<xi> r" "\<gamma> - f z = 0"
```
```   406           apply (rule holomorphic_contract_to_zero)
```
```   407           apply (blast intro!: \<open>0 < r\<close> *)+
```
```   408           done
```
```   409         then show "\<gamma> \<in> f ` U"
```
```   410           using \<open>cball \<xi> r \<subseteq> U\<close> by fastforce
```
```   411       qed
```
```   412       then show ?thesis using  \<open>0 < \<epsilon>\<close> by blast
```
```   413     qed
```
```   414   qed
```
```   415   have "open (f ` X)" if "X \<in> components U" for X
```
```   416   proof -
```
```   417     have holfU: "f holomorphic_on U"
```
```   418       using \<open>U \<subseteq> S\<close> holf holomorphic_on_subset by blast
```
```   419     have "X \<noteq> {}"
```
```   420       using that by (simp add: in_components_nonempty)
```
```   421     moreover have "open X"
```
```   422       using that \<open>open U\<close> open_components by auto
```
```   423     moreover have "connected X"
```
```   424       using that in_components_maximal by blast
```
```   425     moreover have "f holomorphic_on X"
```
```   426       by (meson that holfU holomorphic_on_subset in_components_maximal)
```
```   427     moreover have "\<exists>y\<in>X. f y \<noteq> x" for x
```
```   428     proof (rule ccontr)
```
```   429       assume not: "\<not> (\<exists>y\<in>X. f y \<noteq> x)"
```
```   430       have "X \<subseteq> S"
```
```   431         using \<open>U \<subseteq> S\<close> in_components_subset that by blast
```
```   432       obtain w where w: "w \<in> X" using \<open>X \<noteq> {}\<close> by blast
```
```   433       have wis: "w islimpt X"
```
```   434         using w \<open>open X\<close> interior_eq by auto
```
```   435       have hol: "(\<lambda>z. f z - x) holomorphic_on S"
```
```   436         by (simp add: holf holomorphic_on_diff)
```
```   437       with fne [unfolded constant_on_def] analytic_continuation [OF hol S \<open>X \<subseteq> S\<close> _ wis]
```
```   438            not \<open>X \<subseteq> S\<close> w
```
```   439       show False by auto
```
```   440     qed
```
```   441     ultimately show ?thesis
```
```   442       by (rule *)
```
```   443   qed
```
```   444   then have "open (f ` \<Union>components U)"
```
```   445     by (metis (no_types, lifting) imageE image_Union open_Union)
```
```   446   then show ?thesis
```
```   447     by force
```
```   448 qed
```
```   449
```
```   450
```
```   451 text\<open>No need for @{term S} to be connected. But the nonconstant condition is stronger.\<close>
```
```   452 corollary open_mapping_thm2:
```
```   453   assumes holf: "f holomorphic_on S"
```
```   454       and S: "open S"
```
```   455       and "open U" "U \<subseteq> S"
```
```   456       and fnc: "\<And>X. \<lbrakk>open X; X \<subseteq> S; X \<noteq> {}\<rbrakk> \<Longrightarrow> ~ f constant_on X"
```
```   457     shows "open (f ` U)"
```
```   458 proof -
```
```   459   have "S = \<Union>(components S)" by simp
```
```   460   with \<open>U \<subseteq> S\<close> have "U = (\<Union>C \<in> components S. C \<inter> U)" by auto
```
```   461   then have "f ` U = (\<Union>C \<in> components S. f ` (C \<inter> U))"
```
```   462     using image_UN by fastforce
```
```   463   moreover
```
```   464   { fix C assume "C \<in> components S"
```
```   465     with S \<open>C \<in> components S\<close> open_components in_components_connected
```
```   466     have C: "open C" "connected C" by auto
```
```   467     have "C \<subseteq> S"
```
```   468       by (metis \<open>C \<in> components S\<close> in_components_maximal)
```
```   469     have nf: "\<not> f constant_on C"
```
```   470       apply (rule fnc)
```
```   471       using C \<open>C \<subseteq> S\<close> \<open>C \<in> components S\<close> in_components_nonempty by auto
```
```   472     have "f holomorphic_on C"
```
```   473       by (metis holf holomorphic_on_subset \<open>C \<subseteq> S\<close>)
```
```   474     then have "open (f ` (C \<inter> U))"
```
```   475       apply (rule open_mapping_thm [OF _ C _ _ nf])
```
```   476       apply (simp add: C \<open>open U\<close> open_Int, blast)
```
```   477       done
```
```   478   } ultimately show ?thesis
```
```   479     by force
```
```   480 qed
```
```   481
```
```   482 corollary open_mapping_thm3:
```
```   483   assumes holf: "f holomorphic_on S"
```
```   484       and "open S" and injf: "inj_on f S"
```
```   485     shows  "open (f ` S)"
```
```   486 apply (rule open_mapping_thm2 [OF holf])
```
```   487 using assms
```
```   488 apply (simp_all add:)
```
```   489 using injective_not_constant subset_inj_on by blast
```
```   490
```
```   491
```
```   492
```
```   493 subsection\<open>Maximum Modulus Principle\<close>
```
```   494
```
```   495 text\<open>If @{term f} is holomorphic, then its norm (modulus) cannot exhibit a true local maximum that is
```
```   496    properly within the domain of @{term f}.\<close>
```
```   497
```
```   498 proposition maximum_modulus_principle:
```
```   499   assumes holf: "f holomorphic_on S"
```
```   500       and S: "open S" "connected S"
```
```   501       and "open U" "U \<subseteq> S" "\<xi> \<in> U"
```
```   502       and no: "\<And>z. z \<in> U \<Longrightarrow> norm(f z) \<le> norm(f \<xi>)"
```
```   503     shows "f constant_on S"
```
```   504 proof (rule ccontr)
```
```   505   assume "\<not> f constant_on S"
```
```   506   then have "open (f ` U)"
```
```   507     using open_mapping_thm assms by blast
```
```   508   moreover have "~ open (f ` U)"
```
```   509   proof -
```
```   510     have "\<exists>t. cmod (f \<xi> - t) < e \<and> t \<notin> f ` U" if "0 < e" for e
```
```   511       apply (rule_tac x="if 0 < Re(f \<xi>) then f \<xi> + (e/2) else f \<xi> - (e/2)" in exI)
```
```   512       using that
```
```   513       apply (simp add: dist_norm)
```
```   514       apply (fastforce simp: cmod_Re_le_iff dest!: no dest: sym)
```
```   515       done
```
```   516     then show ?thesis
```
```   517       unfolding open_contains_ball by (metis \<open>\<xi> \<in> U\<close> contra_subsetD dist_norm imageI mem_ball)
```
```   518   qed
```
```   519   ultimately show False
```
```   520     by blast
```
```   521 qed
```
```   522
```
```   523
```
```   524 proposition maximum_modulus_frontier:
```
```   525   assumes holf: "f holomorphic_on (interior S)"
```
```   526       and contf: "continuous_on (closure S) f"
```
```   527       and bos: "bounded S"
```
```   528       and leB: "\<And>z. z \<in> frontier S \<Longrightarrow> norm(f z) \<le> B"
```
```   529       and "\<xi> \<in> S"
```
```   530     shows "norm(f \<xi>) \<le> B"
```
```   531 proof -
```
```   532   have "compact (closure S)" using bos
```
```   533     by (simp add: bounded_closure compact_eq_bounded_closed)
```
```   534   moreover have "continuous_on (closure S) (cmod \<circ> f)"
```
```   535     using contf continuous_on_compose continuous_on_norm_id by blast
```
```   536   ultimately obtain z where zin: "z \<in> closure S" and z: "\<And>y. y \<in> closure S \<Longrightarrow> (cmod \<circ> f) y \<le> (cmod \<circ> f) z"
```
```   537     using continuous_attains_sup [of "closure S" "norm o f"] \<open>\<xi> \<in> S\<close> by auto
```
```   538   then consider "z \<in> frontier S" | "z \<in> interior S" using frontier_def by auto
```
```   539   then have "norm(f z) \<le> B"
```
```   540   proof cases
```
```   541     case 1 then show ?thesis using leB by blast
```
```   542   next
```
```   543     case 2
```
```   544     have zin: "z \<in> connected_component_set (interior S) z"
```
```   545       by (simp add: 2)
```
```   546     have "f constant_on (connected_component_set (interior S) z)"
```
```   547       apply (rule maximum_modulus_principle [OF _ _ _ _ _ zin])
```
```   548       apply (metis connected_component_subset holf holomorphic_on_subset)
```
```   549       apply (simp_all add: open_connected_component)
```
```   550       by (metis closure_subset comp_eq_dest_lhs  interior_subset subsetCE z connected_component_in)
```
```   551     then obtain c where c: "\<And>w. w \<in> connected_component_set (interior S) z \<Longrightarrow> f w = c"
```
```   552       by (auto simp: constant_on_def)
```
```   553     have "f ` closure(connected_component_set (interior S) z) \<subseteq> {c}"
```
```   554       apply (rule image_closure_subset)
```
```   555       apply (meson closure_mono connected_component_subset contf continuous_on_subset interior_subset)
```
```   556       using c
```
```   557       apply auto
```
```   558       done
```
```   559     then have cc: "\<And>w. w \<in> closure(connected_component_set (interior S) z) \<Longrightarrow> f w = c" by blast
```
```   560     have "frontier(connected_component_set (interior S) z) \<noteq> {}"
```
```   561       apply (simp add: frontier_eq_empty)
```
```   562       by (metis "2" bos bounded_interior connected_component_eq_UNIV connected_component_refl not_bounded_UNIV)
```
```   563     then obtain w where w: "w \<in> frontier(connected_component_set (interior S) z)"
```
```   564        by auto
```
```   565     then have "norm (f z) = norm (f w)"  by (simp add: "2" c cc frontier_def)
```
```   566     also have "... \<le> B"
```
```   567       apply (rule leB)
```
```   568       using w
```
```   569 using frontier_interior_subset frontier_of_connected_component_subset by blast
```
```   570     finally show ?thesis .
```
```   571   qed
```
```   572   then show ?thesis
```
```   573     using z \<open>\<xi> \<in> S\<close> closure_subset by fastforce
```
```   574 qed
```
```   575
```
```   576 corollary maximum_real_frontier:
```
```   577   assumes holf: "f holomorphic_on (interior S)"
```
```   578       and contf: "continuous_on (closure S) f"
```
```   579       and bos: "bounded S"
```
```   580       and leB: "\<And>z. z \<in> frontier S \<Longrightarrow> Re(f z) \<le> B"
```
```   581       and "\<xi> \<in> S"
```
```   582     shows "Re(f \<xi>) \<le> B"
```
```   583 using maximum_modulus_frontier [of "exp o f" S "exp B"]
```
```   584       Transcendental.continuous_on_exp holomorphic_on_compose holomorphic_on_exp assms
```
```   585 by auto
```
```   586
```
```   587
```
```   588 subsection\<open>Factoring out a zero according to its order\<close>
```
```   589
```
```   590 lemma holomorphic_factor_order_of_zero:
```
```   591   assumes holf: "f holomorphic_on S"
```
```   592       and os: "open S"
```
```   593       and "\<xi> \<in> S" "0 < n"
```
```   594       and dnz: "(deriv ^^ n) f \<xi> \<noteq> 0"
```
```   595       and dfz: "\<And>i. \<lbrakk>0 < i; i < n\<rbrakk> \<Longrightarrow> (deriv ^^ i) f \<xi> = 0"
```
```   596    obtains g r where "0 < r"
```
```   597                 "g holomorphic_on ball \<xi> r"
```
```   598                 "\<And>w. w \<in> ball \<xi> r \<Longrightarrow> f w - f \<xi> = (w - \<xi>)^n * g w"
```
```   599                 "\<And>w. w \<in> ball \<xi> r \<Longrightarrow> g w \<noteq> 0"
```
```   600 proof -
```
```   601   obtain r where "r>0" and r: "ball \<xi> r \<subseteq> S" using assms by (blast elim!: openE)
```
```   602   then have holfb: "f holomorphic_on ball \<xi> r"
```
```   603     using holf holomorphic_on_subset by blast
```
```   604   define g where "g w = suminf (\<lambda>i. (deriv ^^ (i + n)) f \<xi> / (fact(i + n)) * (w - \<xi>)^i)" for w
```
```   605   have sumsg: "(\<lambda>i. (deriv ^^ (i + n)) f \<xi> / (fact(i + n)) * (w - \<xi>)^i) sums g w"
```
```   606    and feq: "f w - f \<xi> = (w - \<xi>)^n * g w"
```
```   607        if w: "w \<in> ball \<xi> r" for w
```
```   608   proof -
```
```   609     define powf where "powf = (\<lambda>i. (deriv ^^ i) f \<xi>/(fact i) * (w - \<xi>)^i)"
```
```   610     have sing: "{..<n} - {i. powf i = 0} = (if f \<xi> = 0 then {} else {0})"
```
```   611       unfolding powf_def using \<open>0 < n\<close> dfz by (auto simp: dfz; metis funpow_0 not_gr0)
```
```   612     have "powf sums f w"
```
```   613       unfolding powf_def by (rule holomorphic_power_series [OF holfb w])
```
```   614     moreover have "(\<Sum>i<n. powf i) = f \<xi>"
```
```   615       apply (subst Groups_Big.comm_monoid_add_class.setsum.setdiff_irrelevant [symmetric])
```
```   616       apply (simp add:)
```
```   617       apply (simp only: dfz sing)
```
```   618       apply (simp add: powf_def)
```
```   619       done
```
```   620     ultimately have fsums: "(\<lambda>i. powf (i+n)) sums (f w - f \<xi>)"
```
```   621       using w sums_iff_shift' by metis
```
```   622     then have *: "summable (\<lambda>i. (w - \<xi>) ^ n * ((deriv ^^ (i + n)) f \<xi> * (w - \<xi>) ^ i / fact (i + n)))"
```
```   623       unfolding powf_def using sums_summable
```
```   624       by (auto simp: power_add mult_ac)
```
```   625     have "summable (\<lambda>i. (deriv ^^ (i + n)) f \<xi> * (w - \<xi>) ^ i / fact (i + n))"
```
```   626     proof (cases "w=\<xi>")
```
```   627       case False then show ?thesis
```
```   628         using summable_mult [OF *, of "1 / (w - \<xi>) ^ n"] by (simp add:)
```
```   629     next
```
```   630       case True then show ?thesis
```
```   631         by (auto simp: Power.semiring_1_class.power_0_left intro!: summable_finite [of "{0}"]
```
```   632                  split: if_split_asm)
```
```   633     qed
```
```   634     then show sumsg: "(\<lambda>i. (deriv ^^ (i + n)) f \<xi> / (fact(i + n)) * (w - \<xi>)^i) sums g w"
```
```   635       by (simp add: summable_sums_iff g_def)
```
```   636     show "f w - f \<xi> = (w - \<xi>)^n * g w"
```
```   637       apply (rule sums_unique2)
```
```   638       apply (rule fsums [unfolded powf_def])
```
```   639       using sums_mult [OF sumsg, of "(w - \<xi>) ^ n"]
```
```   640       by (auto simp: power_add mult_ac)
```
```   641   qed
```
```   642   then have holg: "g holomorphic_on ball \<xi> r"
```
```   643     by (meson sumsg power_series_holomorphic)
```
```   644   then have contg: "continuous_on (ball \<xi> r) g"
```
```   645     by (blast intro: holomorphic_on_imp_continuous_on)
```
```   646   have "g \<xi> \<noteq> 0"
```
```   647     using dnz unfolding g_def
```
```   648     by (subst suminf_finite [of "{0}"]) auto
```
```   649   obtain d where "0 < d" and d: "\<And>w. w \<in> ball \<xi> d \<Longrightarrow> g w \<noteq> 0"
```
```   650     apply (rule exE [OF continuous_on_avoid [OF contg _ \<open>g \<xi> \<noteq> 0\<close>]])
```
```   651     using \<open>0 < r\<close>
```
```   652     apply force
```
```   653     by (metis \<open>0 < r\<close> less_trans mem_ball not_less_iff_gr_or_eq)
```
```   654   show ?thesis
```
```   655     apply (rule that [where g=g and r ="min r d"])
```
```   656     using \<open>0 < r\<close> \<open>0 < d\<close> holg
```
```   657     apply (auto simp: feq holomorphic_on_subset subset_ball d)
```
```   658     done
```
```   659 qed
```
```   660
```
```   661
```
```   662 lemma holomorphic_factor_order_of_zero_strong:
```
```   663   assumes holf: "f holomorphic_on S" "open S"  "\<xi> \<in> S" "0 < n"
```
```   664       and "(deriv ^^ n) f \<xi> \<noteq> 0"
```
```   665       and "\<And>i. \<lbrakk>0 < i; i < n\<rbrakk> \<Longrightarrow> (deriv ^^ i) f \<xi> = 0"
```
```   666    obtains g r where "0 < r"
```
```   667                 "g holomorphic_on ball \<xi> r"
```
```   668                 "\<And>w. w \<in> ball \<xi> r \<Longrightarrow> f w - f \<xi> = ((w - \<xi>) * g w) ^ n"
```
```   669                 "\<And>w. w \<in> ball \<xi> r \<Longrightarrow> g w \<noteq> 0"
```
```   670 proof -
```
```   671   obtain g r where "0 < r"
```
```   672                and holg: "g holomorphic_on ball \<xi> r"
```
```   673                and feq: "\<And>w. w \<in> ball \<xi> r \<Longrightarrow> f w - f \<xi> = (w - \<xi>)^n * g w"
```
```   674                and gne: "\<And>w. w \<in> ball \<xi> r \<Longrightarrow> g w \<noteq> 0"
```
```   675     by (auto intro: holomorphic_factor_order_of_zero [OF assms])
```
```   676   have con: "continuous_on (ball \<xi> r) (\<lambda>z. deriv g z / g z)"
```
```   677     by (rule continuous_intros) (auto simp: gne holg holomorphic_deriv holomorphic_on_imp_continuous_on)
```
```   678   have cd: "\<And>x. dist \<xi> x < r \<Longrightarrow> (\<lambda>z. deriv g z / g z) field_differentiable at x"
```
```   679     apply (rule derivative_intros)+
```
```   680     using holg mem_ball apply (blast intro: holomorphic_deriv holomorphic_on_imp_differentiable_at)
```
```   681     apply (metis Topology_Euclidean_Space.open_ball at_within_open holg holomorphic_on_def mem_ball)
```
```   682     using gne mem_ball by blast
```
```   683   obtain h where h: "\<And>x. x \<in> ball \<xi> r \<Longrightarrow> (h has_field_derivative deriv g x / g x) (at x)"
```
```   684     apply (rule exE [OF holomorphic_convex_primitive [of "ball \<xi> r" "{}" "\<lambda>z. deriv g z / g z"]])
```
```   685     apply (auto simp: con cd)
```
```   686     apply (metis open_ball at_within_open mem_ball)
```
```   687     done
```
```   688   then have "continuous_on (ball \<xi> r) h"
```
```   689     by (metis open_ball holomorphic_on_imp_continuous_on holomorphic_on_open)
```
```   690   then have con: "continuous_on (ball \<xi> r) (\<lambda>x. exp (h x) / g x)"
```
```   691     by (auto intro!: continuous_intros simp add: holg holomorphic_on_imp_continuous_on gne)
```
```   692   have 0: "dist \<xi> x < r \<Longrightarrow> ((\<lambda>x. exp (h x) / g x) has_field_derivative 0) (at x)" for x
```
```   693     apply (rule h derivative_eq_intros | simp)+
```
```   694     apply (rule DERIV_deriv_iff_field_differentiable [THEN iffD2])
```
```   695     using holg apply (auto simp: holomorphic_on_imp_differentiable_at gne h)
```
```   696     done
```
```   697   obtain c where c: "\<And>x. x \<in> ball \<xi> r \<Longrightarrow> exp (h x) / g x = c"
```
```   698     by (rule DERIV_zero_connected_constant [of "ball \<xi> r" "{}" "\<lambda>x. exp(h x) / g x"]) (auto simp: con 0)
```
```   699   have hol: "(\<lambda>z. exp ((Ln (inverse c) + h z) / of_nat n)) holomorphic_on ball \<xi> r"
```
```   700     apply (rule holomorphic_on_compose [unfolded o_def, where g = exp])
```
```   701     apply (rule holomorphic_intros)+
```
```   702     using h holomorphic_on_open apply blast
```
```   703     apply (rule holomorphic_intros)+
```
```   704     using \<open>0 < n\<close> apply (simp add:)
```
```   705     apply (rule holomorphic_intros)+
```
```   706     done
```
```   707   show ?thesis
```
```   708     apply (rule that [where g="\<lambda>z. exp((Ln(inverse c) + h z)/n)" and r =r])
```
```   709     using \<open>0 < r\<close> \<open>0 < n\<close>
```
```   710     apply (auto simp: feq power_mult_distrib exp_divide_power_eq c [symmetric])
```
```   711     apply (rule hol)
```
```   712     apply (simp add: Transcendental.exp_add gne)
```
```   713     done
```
```   714 qed
```
```   715
```
```   716
```
```   717 lemma
```
```   718   fixes k :: "'a::wellorder"
```
```   719   assumes a_def: "a == LEAST x. P x" and P: "P k"
```
```   720   shows def_LeastI: "P a" and def_Least_le: "a \<le> k"
```
```   721 unfolding a_def
```
```   722 by (rule LeastI Least_le; rule P)+
```
```   723
```
```   724 lemma holomorphic_factor_zero_nonconstant:
```
```   725   assumes holf: "f holomorphic_on S" and S: "open S" "connected S"
```
```   726       and "\<xi> \<in> S" "f \<xi> = 0"
```
```   727       and nonconst: "\<And>c. \<exists>z \<in> S. f z \<noteq> c"
```
```   728    obtains g r n
```
```   729       where "0 < n"  "0 < r"  "ball \<xi> r \<subseteq> S"
```
```   730             "g holomorphic_on ball \<xi> r"
```
```   731             "\<And>w. w \<in> ball \<xi> r \<Longrightarrow> f w = (w - \<xi>)^n * g w"
```
```   732             "\<And>w. w \<in> ball \<xi> r \<Longrightarrow> g w \<noteq> 0"
```
```   733 proof (cases "\<forall>n>0. (deriv ^^ n) f \<xi> = 0")
```
```   734   case True then show ?thesis
```
```   735     using holomorphic_fun_eq_const_on_connected [OF holf S _ \<open>\<xi> \<in> S\<close>] nonconst by auto
```
```   736 next
```
```   737   case False
```
```   738   then obtain n0 where "n0 > 0" and n0: "(deriv ^^ n0) f \<xi> \<noteq> 0" by blast
```
```   739   obtain r0 where "r0 > 0" "ball \<xi> r0 \<subseteq> S" using S openE \<open>\<xi> \<in> S\<close> by auto
```
```   740   define n where "n \<equiv> LEAST n. (deriv ^^ n) f \<xi> \<noteq> 0"
```
```   741   have n_ne: "(deriv ^^ n) f \<xi> \<noteq> 0"
```
```   742     by (rule def_LeastI [OF n_def]) (rule n0)
```
```   743   then have "0 < n" using \<open>f \<xi> = 0\<close>
```
```   744     using funpow_0 by fastforce
```
```   745   have n_min: "\<And>k. k < n \<Longrightarrow> (deriv ^^ k) f \<xi> = 0"
```
```   746     using def_Least_le [OF n_def] not_le by blast
```
```   747   then obtain g r1
```
```   748     where  "0 < r1" "g holomorphic_on ball \<xi> r1"
```
```   749            "\<And>w. w \<in> ball \<xi> r1 \<Longrightarrow> f w = (w - \<xi>) ^ n * g w"
```
```   750            "\<And>w. w \<in> ball \<xi> r1 \<Longrightarrow> g w \<noteq> 0"
```
```   751     by (auto intro: holomorphic_factor_order_of_zero [OF holf \<open>open S\<close> \<open>\<xi> \<in> S\<close> \<open>n > 0\<close> n_ne] simp: \<open>f \<xi> = 0\<close>)
```
```   752   then show ?thesis
```
```   753     apply (rule_tac g=g and r="min r0 r1" and n=n in that)
```
```   754     using \<open>0 < n\<close> \<open>0 < r0\<close> \<open>0 < r1\<close> \<open>ball \<xi> r0 \<subseteq> S\<close>
```
```   755     apply (auto simp: subset_ball intro: holomorphic_on_subset)
```
```   756     done
```
```   757 qed
```
```   758
```
```   759
```
```   760 lemma holomorphic_lower_bound_difference:
```
```   761   assumes holf: "f holomorphic_on S" and S: "open S" "connected S"
```
```   762       and "\<xi> \<in> S" and "\<phi> \<in> S"
```
```   763       and fne: "f \<phi> \<noteq> f \<xi>"
```
```   764    obtains k n r
```
```   765       where "0 < k"  "0 < r"
```
```   766             "ball \<xi> r \<subseteq> S"
```
```   767             "\<And>w. w \<in> ball \<xi> r \<Longrightarrow> k * norm(w - \<xi>)^n \<le> norm(f w - f \<xi>)"
```
```   768 proof -
```
```   769   define n where "n = (LEAST n. 0 < n \<and> (deriv ^^ n) f \<xi> \<noteq> 0)"
```
```   770   obtain n0 where "0 < n0" and n0: "(deriv ^^ n0) f \<xi> \<noteq> 0"
```
```   771     using fne holomorphic_fun_eq_const_on_connected [OF holf S] \<open>\<xi> \<in> S\<close> \<open>\<phi> \<in> S\<close> by blast
```
```   772   then have "0 < n" and n_ne: "(deriv ^^ n) f \<xi> \<noteq> 0"
```
```   773     unfolding n_def by (metis (mono_tags, lifting) LeastI)+
```
```   774   have n_min: "\<And>k. \<lbrakk>0 < k; k < n\<rbrakk> \<Longrightarrow> (deriv ^^ k) f \<xi> = 0"
```
```   775     unfolding n_def by (blast dest: not_less_Least)
```
```   776   then obtain g r
```
```   777     where "0 < r" and holg: "g holomorphic_on ball \<xi> r"
```
```   778       and fne: "\<And>w. w \<in> ball \<xi> r \<Longrightarrow> f w - f \<xi> = (w - \<xi>) ^ n * g w"
```
```   779       and gnz: "\<And>w. w \<in> ball \<xi> r \<Longrightarrow> g w \<noteq> 0"
```
```   780       by (auto intro: holomorphic_factor_order_of_zero  [OF holf \<open>open S\<close> \<open>\<xi> \<in> S\<close> \<open>n > 0\<close> n_ne])
```
```   781   obtain e where "e>0" and e: "ball \<xi> e \<subseteq> S" using assms by (blast elim!: openE)
```
```   782   then have holfb: "f holomorphic_on ball \<xi> e"
```
```   783     using holf holomorphic_on_subset by blast
```
```   784   define d where "d = (min e r) / 2"
```
```   785   have "0 < d" using \<open>0 < r\<close> \<open>0 < e\<close> by (simp add: d_def)
```
```   786   have "d < r"
```
```   787     using \<open>0 < r\<close> by (auto simp: d_def)
```
```   788   then have cbb: "cball \<xi> d \<subseteq> ball \<xi> r"
```
```   789     by (auto simp: cball_subset_ball_iff)
```
```   790   then have "g holomorphic_on cball \<xi> d"
```
```   791     by (rule holomorphic_on_subset [OF holg])
```
```   792   then have "closed (g ` cball \<xi> d)"
```
```   793     by (simp add: compact_imp_closed compact_continuous_image holomorphic_on_imp_continuous_on)
```
```   794   moreover have "g ` cball \<xi> d \<noteq> {}"
```
```   795     using \<open>0 < d\<close> by auto
```
```   796   ultimately obtain x where x: "x \<in> g ` cball \<xi> d" and "\<And>y. y \<in> g ` cball \<xi> d \<Longrightarrow> dist 0 x \<le> dist 0 y"
```
```   797     by (rule distance_attains_inf) blast
```
```   798   then have leg: "\<And>w. w \<in> cball \<xi> d \<Longrightarrow> norm x \<le> norm (g w)"
```
```   799     by auto
```
```   800   have "ball \<xi> d \<subseteq> cball \<xi> d" by auto
```
```   801   also have "... \<subseteq> ball \<xi> e" using \<open>0 < d\<close> d_def by auto
```
```   802   also have "... \<subseteq> S" by (rule e)
```
```   803   finally have dS: "ball \<xi> d \<subseteq> S" .
```
```   804   moreover have "x \<noteq> 0" using gnz x \<open>d < r\<close> by auto
```
```   805   ultimately show ?thesis
```
```   806     apply (rule_tac k="norm x" and n=n and r=d in that)
```
```   807     using \<open>d < r\<close> leg
```
```   808     apply (auto simp: \<open>0 < d\<close> fne norm_mult norm_power algebra_simps mult_right_mono)
```
```   809     done
```
```   810 qed
```
```   811
```
```   812 lemma
```
```   813   assumes holf: "f holomorphic_on (S - {\<xi>})" and \<xi>: "\<xi> \<in> interior S"
```
```   814     shows holomorphic_on_extend_lim:
```
```   815           "(\<exists>g. g holomorphic_on S \<and> (\<forall>z \<in> S - {\<xi>}. g z = f z)) \<longleftrightarrow>
```
```   816            ((\<lambda>z. (z - \<xi>) * f z) \<longlongrightarrow> 0) (at \<xi>)"
```
```   817           (is "?P = ?Q")
```
```   818      and holomorphic_on_extend_bounded:
```
```   819           "(\<exists>g. g holomorphic_on S \<and> (\<forall>z \<in> S - {\<xi>}. g z = f z)) \<longleftrightarrow>
```
```   820            (\<exists>B. eventually (\<lambda>z. norm(f z) \<le> B) (at \<xi>))"
```
```   821           (is "?P = ?R")
```
```   822 proof -
```
```   823   obtain \<delta> where "0 < \<delta>" and \<delta>: "ball \<xi> \<delta> \<subseteq> S"
```
```   824     using \<xi> mem_interior by blast
```
```   825   have "?R" if holg: "g holomorphic_on S" and gf: "\<And>z. z \<in> S - {\<xi>} \<Longrightarrow> g z = f z" for g
```
```   826   proof -
```
```   827     have *: "\<forall>\<^sub>F z in at \<xi>. dist (g z) (g \<xi>) < 1 \<longrightarrow> cmod (f z) \<le> cmod (g \<xi>) + 1"
```
```   828       apply (simp add: eventually_at)
```
```   829       apply (rule_tac x="\<delta>" in exI)
```
```   830       using \<delta> \<open>0 < \<delta>\<close>
```
```   831       apply (clarsimp simp:)
```
```   832       apply (drule_tac c=x in subsetD)
```
```   833       apply (simp add: dist_commute)
```
```   834       by (metis DiffI add.commute diff_le_eq dist_norm gf le_less_trans less_eq_real_def norm_triangle_ineq2 singletonD)
```
```   835     have "continuous_on (interior S) g"
```
```   836       by (meson continuous_on_subset holg holomorphic_on_imp_continuous_on interior_subset)
```
```   837     then have "\<And>x. x \<in> interior S \<Longrightarrow> (g \<longlongrightarrow> g x) (at x)"
```
```   838       using continuous_on_interior continuous_within holg holomorphic_on_imp_continuous_on by blast
```
```   839     then have "(g \<longlongrightarrow> g \<xi>) (at \<xi>)"
```
```   840       by (simp add: \<xi>)
```
```   841     then show ?thesis
```
```   842       apply (rule_tac x="norm(g \<xi>) + 1" in exI)
```
```   843       apply (rule eventually_mp [OF * tendstoD [where e=1]], auto)
```
```   844       done
```
```   845   qed
```
```   846   moreover have "?Q" if "\<forall>\<^sub>F z in at \<xi>. cmod (f z) \<le> B" for B
```
```   847     by (rule lim_null_mult_right_bounded [OF _ that]) (simp add: LIM_zero)
```
```   848   moreover have "?P" if "(\<lambda>z. (z - \<xi>) * f z) \<midarrow>\<xi>\<rightarrow> 0"
```
```   849   proof -
```
```   850     define h where [abs_def]: "h z = (z - \<xi>)^2 * f z" for z
```
```   851     have h0: "(h has_field_derivative 0) (at \<xi>)"
```
```   852       apply (simp add: h_def Derivative.DERIV_within_iff)
```
```   853       apply (rule Lim_transform_within [OF that, of 1])
```
```   854       apply (auto simp: divide_simps power2_eq_square)
```
```   855       done
```
```   856     have holh: "h holomorphic_on S"
```
```   857     proof (simp add: holomorphic_on_def, clarify)
```
```   858       fix z assume "z \<in> S"
```
```   859       show "h field_differentiable at z within S"
```
```   860       proof (cases "z = \<xi>")
```
```   861         case True then show ?thesis
```
```   862           using field_differentiable_at_within field_differentiable_def h0 by blast
```
```   863       next
```
```   864         case False
```
```   865         then have "f field_differentiable at z within S"
```
```   866           using holomorphic_onD [OF holf, of z] \<open>z \<in> S\<close>
```
```   867           unfolding field_differentiable_def DERIV_within_iff
```
```   868           by (force intro: exI [where x="dist \<xi> z"] elim: Lim_transform_within_set [unfolded eventually_at])
```
```   869         then show ?thesis
```
```   870           by (simp add: h_def power2_eq_square derivative_intros)
```
```   871       qed
```
```   872     qed
```
```   873     define g where [abs_def]: "g z = (if z = \<xi> then deriv h \<xi> else (h z - h \<xi>) / (z - \<xi>))" for z
```
```   874     have holg: "g holomorphic_on S"
```
```   875       unfolding g_def by (rule pole_lemma [OF holh \<xi>])
```
```   876     show ?thesis
```
```   877       apply (rule_tac x="\<lambda>z. if z = \<xi> then deriv g \<xi> else (g z - g \<xi>)/(z - \<xi>)" in exI)
```
```   878       apply (rule conjI)
```
```   879       apply (rule pole_lemma [OF holg \<xi>])
```
```   880       apply (auto simp: g_def power2_eq_square divide_simps)
```
```   881       using h0 apply (simp add: h0 DERIV_imp_deriv h_def power2_eq_square)
```
```   882       done
```
```   883   qed
```
```   884   ultimately show "?P = ?Q" and "?P = ?R"
```
```   885     by meson+
```
```   886 qed
```
```   887
```
```   888
```
```   889 proposition pole_at_infinity:
```
```   890   assumes holf: "f holomorphic_on UNIV" and lim: "((inverse o f) \<longlongrightarrow> l) at_infinity"
```
```   891   obtains a n where "\<And>z. f z = (\<Sum>i\<le>n. a i * z^i)"
```
```   892 proof (cases "l = 0")
```
```   893   case False
```
```   894   with tendsto_inverse [OF lim] show ?thesis
```
```   895     apply (rule_tac a="(\<lambda>n. inverse l)" and n=0 in that)
```
```   896     apply (simp add: Liouville_weak [OF holf, of "inverse l"])
```
```   897     done
```
```   898 next
```
```   899   case True
```
```   900   then have [simp]: "l = 0" .
```
```   901   show ?thesis
```
```   902   proof (cases "\<exists>r. 0 < r \<and> (\<forall>z \<in> ball 0 r - {0}. f(inverse z) \<noteq> 0)")
```
```   903     case True
```
```   904       then obtain r where "0 < r" and r: "\<And>z. z \<in> ball 0 r - {0} \<Longrightarrow> f(inverse z) \<noteq> 0"
```
```   905              by auto
```
```   906       have 1: "inverse \<circ> f \<circ> inverse holomorphic_on ball 0 r - {0}"
```
```   907         by (rule holomorphic_on_compose holomorphic_intros holomorphic_on_subset [OF holf] | force simp: r)+
```
```   908       have 2: "0 \<in> interior (ball 0 r)"
```
```   909         using \<open>0 < r\<close> by simp
```
```   910       have "\<exists>B. 0<B \<and> eventually (\<lambda>z. cmod ((inverse \<circ> f \<circ> inverse) z) \<le> B) (at 0)"
```
```   911         apply (rule exI [where x=1])
```
```   912         apply (simp add:)
```
```   913         using tendstoD [OF lim [unfolded lim_at_infinity_0] zero_less_one]
```
```   914         apply (rule eventually_mono)
```
```   915         apply (simp add: dist_norm)
```
```   916         done
```
```   917       with holomorphic_on_extend_bounded [OF 1 2]
```
```   918       obtain g where holg: "g holomorphic_on ball 0 r"
```
```   919                  and geq: "\<And>z. z \<in> ball 0 r - {0} \<Longrightarrow> g z = (inverse \<circ> f \<circ> inverse) z"
```
```   920         by meson
```
```   921       have ifi0: "(inverse \<circ> f \<circ> inverse) \<midarrow>0\<rightarrow> 0"
```
```   922         using \<open>l = 0\<close> lim lim_at_infinity_0 by blast
```
```   923       have g2g0: "g \<midarrow>0\<rightarrow> g 0"
```
```   924         using \<open>0 < r\<close> centre_in_ball continuous_at continuous_on_eq_continuous_at holg
```
```   925         by (blast intro: holomorphic_on_imp_continuous_on)
```
```   926       have g2g1: "g \<midarrow>0\<rightarrow> 0"
```
```   927         apply (rule Lim_transform_within_open [OF ifi0 open_ball [of 0 r]])
```
```   928         using \<open>0 < r\<close> by (auto simp: geq)
```
```   929       have [simp]: "g 0 = 0"
```
```   930         by (rule tendsto_unique [OF _ g2g0 g2g1]) simp
```
```   931       have "ball 0 r - {0::complex} \<noteq> {}"
```
```   932         using \<open>0 < r\<close>
```
```   933         apply (clarsimp simp: ball_def dist_norm)
```
```   934         apply (drule_tac c="of_real r/2" in subsetD, auto)
```
```   935         done
```
```   936       then obtain w::complex where "w \<noteq> 0" and w: "norm w < r" by force
```
```   937       then have "g w \<noteq> 0" by (simp add: geq r)
```
```   938       obtain B n e where "0 < B" "0 < e" "e \<le> r"
```
```   939                      and leg: "\<And>w. norm w < e \<Longrightarrow> B * cmod w ^ n \<le> cmod (g w)"
```
```   940         apply (rule holomorphic_lower_bound_difference [OF holg open_ball connected_ball, of 0 w])
```
```   941         using \<open>0 < r\<close> w \<open>g w \<noteq> 0\<close> by (auto simp: ball_subset_ball_iff)
```
```   942       have "cmod (f z) \<le> cmod z ^ n / B" if "2/e \<le> cmod z" for z
```
```   943       proof -
```
```   944         have ize: "inverse z \<in> ball 0 e - {0}" using that \<open>0 < e\<close>
```
```   945           by (auto simp: norm_divide divide_simps algebra_simps)
```
```   946         then have [simp]: "z \<noteq> 0" and izr: "inverse z \<in> ball 0 r - {0}" using  \<open>e \<le> r\<close>
```
```   947           by auto
```
```   948         then have [simp]: "f z \<noteq> 0"
```
```   949           using r [of "inverse z"] by simp
```
```   950         have [simp]: "f z = inverse (g (inverse z))"
```
```   951           using izr geq [of "inverse z"] by simp
```
```   952         show ?thesis using ize leg [of "inverse z"]  \<open>0 < B\<close>  \<open>0 < e\<close>
```
```   953           by (simp add: divide_simps norm_divide algebra_simps)
```
```   954       qed
```
```   955       then show ?thesis
```
```   956         apply (rule_tac a = "\<lambda>k. (deriv ^^ k) f 0 / (fact k)" and n=n in that)
```
```   957         apply (rule_tac A = "2/e" and B = "1/B" in Liouville_polynomial [OF holf])
```
```   958         apply (simp add:)
```
```   959         done
```
```   960   next
```
```   961     case False
```
```   962     then have fi0: "\<And>r. r > 0 \<Longrightarrow> \<exists>z\<in>ball 0 r - {0}. f (inverse z) = 0"
```
```   963       by simp
```
```   964     have fz0: "f z = 0" if "0 < r" and lt1: "\<And>x. x \<noteq> 0 \<Longrightarrow> cmod x < r \<Longrightarrow> inverse (cmod (f (inverse x))) < 1"
```
```   965               for z r
```
```   966     proof -
```
```   967       have f0: "(f \<longlongrightarrow> 0) at_infinity"
```
```   968       proof -
```
```   969         have DIM_complex[intro]: "2 \<le> DIM(complex)"  \<comment>\<open>should not be necessary!\<close>
```
```   970           by simp
```
```   971         have "continuous_on (inverse ` (ball 0 r - {0})) f"
```
```   972           using continuous_on_subset holf holomorphic_on_imp_continuous_on by blast
```
```   973         then have "connected ((f \<circ> inverse) ` (ball 0 r - {0}))"
```
```   974           apply (intro connected_continuous_image continuous_intros)
```
```   975           apply (force intro: connected_punctured_ball)+
```
```   976           done
```
```   977         then have "\<lbrakk>w \<noteq> 0; cmod w < r\<rbrakk> \<Longrightarrow> f (inverse w) = 0" for w
```
```   978           apply (rule disjE [OF connected_closedD [where A = "{0}" and B = "- ball 0 1"]], auto)
```
```   979           apply (metis (mono_tags, hide_lams) not_less_iff_gr_or_eq one_less_inverse lt1 zero_less_norm_iff)
```
```   980           using False \<open>0 < r\<close> apply fastforce
```
```   981           by (metis (no_types, hide_lams) Compl_iff IntI comp_apply empty_iff image_eqI insert_Diff_single insert_iff mem_ball_0 not_less_iff_gr_or_eq one_less_inverse that(2) zero_less_norm_iff)
```
```   982         then show ?thesis
```
```   983           apply (simp add: lim_at_infinity_0)
```
```   984           apply (rule Lim_eventually)
```
```   985           apply (simp add: eventually_at)
```
```   986           apply (rule_tac x=r in exI)
```
```   987           apply (simp add: \<open>0 < r\<close> dist_norm)
```
```   988           done
```
```   989       qed
```
```   990       obtain w where "w \<in> ball 0 r - {0}" and "f (inverse w) = 0"
```
```   991         using False \<open>0 < r\<close> by blast
```
```   992       then show ?thesis
```
```   993         by (auto simp: f0 Liouville_weak [OF holf, of 0])
```
```   994     qed
```
```   995     show ?thesis
```
```   996       apply (rule that [of "\<lambda>n. 0" 0])
```
```   997       using lim [unfolded lim_at_infinity_0]
```
```   998       apply (simp add: Lim_at dist_norm norm_inverse)
```
```   999       apply (drule_tac x=1 in spec)
```
```  1000       using fz0 apply auto
```
```  1001       done
```
```  1002     qed
```
```  1003 qed
```
```  1004
```
```  1005
```
```  1006 subsection\<open>Entire proper functions are precisely the non-trivial polynomials\<close>
```
```  1007
```
```  1008 proposition proper_map_polyfun:
```
```  1009     fixes c :: "nat \<Rightarrow> 'a::{real_normed_div_algebra,heine_borel}"
```
```  1010   assumes "closed S" and "compact K" and c: "c i \<noteq> 0" "1 \<le> i" "i \<le> n"
```
```  1011     shows "compact (S \<inter> {z. (\<Sum>i\<le>n. c i * z^i) \<in> K})"
```
```  1012 proof -
```
```  1013   obtain B where "B > 0" and B: "\<And>x. x \<in> K \<Longrightarrow> norm x \<le> B"
```
```  1014     by (metis compact_imp_bounded \<open>compact K\<close> bounded_pos)
```
```  1015   have *: "norm x \<le> b"
```
```  1016             if "\<And>x. b \<le> norm x \<Longrightarrow> B + 1 \<le> norm (\<Sum>i\<le>n. c i * x ^ i)"
```
```  1017                "(\<Sum>i\<le>n. c i * x ^ i) \<in> K"  for b x
```
```  1018   proof -
```
```  1019     have "norm (\<Sum>i\<le>n. c i * x ^ i) \<le> B"
```
```  1020       using B that by blast
```
```  1021     moreover have "\<not> B + 1 \<le> B"
```
```  1022       by simp
```
```  1023     ultimately show "norm x \<le> b"
```
```  1024       using that by (metis (no_types) less_eq_real_def not_less order_trans)
```
```  1025   qed
```
```  1026   have "bounded {z. (\<Sum>i\<le>n. c i * z ^ i) \<in> K}"
```
```  1027     using polyfun_extremal [where c=c and B="B+1", OF c]
```
```  1028     by (auto simp: bounded_pos eventually_at_infinity_pos *)
```
```  1029   moreover have "closed {z. (\<Sum>i\<le>n. c i * z ^ i) \<in> K}"
```
```  1030     apply (rule allI continuous_closed_preimage_univ continuous_intros)+
```
```  1031     using \<open>compact K\<close> compact_eq_bounded_closed by blast
```
```  1032   ultimately show ?thesis
```
```  1033     using closed_Int_compact [OF \<open>closed S\<close>] compact_eq_bounded_closed by blast
```
```  1034 qed
```
```  1035
```
```  1036 corollary proper_map_polyfun_univ:
```
```  1037     fixes c :: "nat \<Rightarrow> 'a::{real_normed_div_algebra,heine_borel}"
```
```  1038   assumes "compact K" "c i \<noteq> 0" "1 \<le> i" "i \<le> n"
```
```  1039     shows "compact ({z. (\<Sum>i\<le>n. c i * z^i) \<in> K})"
```
```  1040 using proper_map_polyfun [of UNIV K c i n] assms by simp
```
```  1041
```
```  1042
```
```  1043 proposition proper_map_polyfun_eq:
```
```  1044   assumes "f holomorphic_on UNIV"
```
```  1045     shows "(\<forall>k. compact k \<longrightarrow> compact {z. f z \<in> k}) \<longleftrightarrow>
```
```  1046            (\<exists>c n. 0 < n \<and> (c n \<noteq> 0) \<and> f = (\<lambda>z. \<Sum>i\<le>n. c i * z^i))"
```
```  1047           (is "?lhs = ?rhs")
```
```  1048 proof
```
```  1049   assume compf [rule_format]: ?lhs
```
```  1050   have 2: "\<exists>k. 0 < k \<and> a k \<noteq> 0 \<and> f = (\<lambda>z. \<Sum>i \<le> k. a i * z ^ i)"
```
```  1051         if "\<And>z. f z = (\<Sum>i\<le>n. a i * z ^ i)" for a n
```
```  1052   proof (cases "\<forall>i\<le>n. 0<i \<longrightarrow> a i = 0")
```
```  1053     case True
```
```  1054     then have [simp]: "\<And>z. f z = a 0"
```
```  1055       by (simp add: that setsum_atMost_shift)
```
```  1056     have False using compf [of "{a 0}"] by simp
```
```  1057     then show ?thesis ..
```
```  1058   next
```
```  1059     case False
```
```  1060     then obtain k where k: "0 < k" "k\<le>n" "a k \<noteq> 0" by force
```
```  1061     define m where "m = (GREATEST k. k\<le>n \<and> a k \<noteq> 0)"
```
```  1062     have m: "m\<le>n \<and> a m \<noteq> 0"
```
```  1063       unfolding m_def
```
```  1064       apply (rule GreatestI [where b = "Suc n"])
```
```  1065       using k apply auto
```
```  1066       done
```
```  1067     have [simp]: "a i = 0" if "m < i" "i \<le> n" for i
```
```  1068       using Greatest_le [where b = "Suc n" and P = "\<lambda>k. k\<le>n \<and> a k \<noteq> 0"]
```
```  1069       using m_def not_le that by auto
```
```  1070     have "k \<le> m"
```
```  1071       unfolding m_def
```
```  1072       apply (rule Greatest_le [where b = "Suc n"])
```
```  1073       using k apply auto
```
```  1074       done
```
```  1075     with k m show ?thesis
```
```  1076       by (rule_tac x=m in exI) (auto simp: that comm_monoid_add_class.setsum.mono_neutral_right)
```
```  1077   qed
```
```  1078   have "((inverse \<circ> f) \<longlongrightarrow> 0) at_infinity"
```
```  1079   proof (rule Lim_at_infinityI)
```
```  1080     fix e::real assume "0 < e"
```
```  1081     with compf [of "cball 0 (inverse e)"]
```
```  1082     show "\<exists>B. \<forall>x. B \<le> cmod x \<longrightarrow> dist ((inverse \<circ> f) x) 0 \<le> e"
```
```  1083       apply (simp add:)
```
```  1084       apply (clarsimp simp add: compact_eq_bounded_closed bounded_pos norm_inverse)
```
```  1085       apply (rule_tac x="b+1" in exI)
```
```  1086       apply (metis inverse_inverse_eq less_add_same_cancel2 less_imp_inverse_less add.commute not_le not_less_iff_gr_or_eq order_trans zero_less_one)
```
```  1087       done
```
```  1088   qed
```
```  1089   then show ?rhs
```
```  1090     apply (rule pole_at_infinity [OF assms])
```
```  1091     using 2 apply blast
```
```  1092     done
```
```  1093 next
```
```  1094   assume ?rhs
```
```  1095   then obtain c n where "0 < n" "c n \<noteq> 0" "f = (\<lambda>z. \<Sum>i\<le>n. c i * z ^ i)" by blast
```
```  1096   then have "compact {z. f z \<in> k}" if "compact k" for k
```
```  1097     by (auto intro: proper_map_polyfun_univ [OF that])
```
```  1098   then show ?lhs by blast
```
```  1099 qed
```
```  1100
```
```  1101
```
```  1102 subsection\<open>Relating invertibility and nonvanishing of derivative\<close>
```
```  1103
```
```  1104 proposition has_complex_derivative_locally_injective:
```
```  1105   assumes holf: "f holomorphic_on S"
```
```  1106       and S: "\<xi> \<in> S" "open S"
```
```  1107       and dnz: "deriv f \<xi> \<noteq> 0"
```
```  1108   obtains r where "r > 0" "ball \<xi> r \<subseteq> S" "inj_on f (ball \<xi> r)"
```
```  1109 proof -
```
```  1110   have *: "\<exists>d>0. \<forall>x. dist \<xi> x < d \<longrightarrow> onorm (\<lambda>v. deriv f x * v - deriv f \<xi> * v) < e" if "e > 0" for e
```
```  1111   proof -
```
```  1112     have contdf: "continuous_on S (deriv f)"
```
```  1113       by (simp add: holf holomorphic_deriv holomorphic_on_imp_continuous_on \<open>open S\<close>)
```
```  1114     obtain \<delta> where "\<delta>>0" and \<delta>: "\<And>x. \<lbrakk>x \<in> S; dist x \<xi> \<le> \<delta>\<rbrakk> \<Longrightarrow> cmod (deriv f x - deriv f \<xi>) \<le> e/2"
```
```  1115       using continuous_onE [OF contdf \<open>\<xi> \<in> S\<close>, of "e/2"] \<open>0 < e\<close>
```
```  1116       by (metis dist_complex_def half_gt_zero less_imp_le)
```
```  1117     obtain \<epsilon> where "\<epsilon>>0" "ball \<xi> \<epsilon> \<subseteq> S"
```
```  1118       by (metis openE [OF \<open>open S\<close> \<open>\<xi> \<in> S\<close>])
```
```  1119     with \<open>\<delta>>0\<close> have "\<exists>\<delta>>0. \<forall>x. dist \<xi> x < \<delta> \<longrightarrow> onorm (\<lambda>v. deriv f x * v - deriv f \<xi> * v) \<le> e/2"
```
```  1120       apply (rule_tac x="min \<delta> \<epsilon>" in exI)
```
```  1121       apply (intro conjI allI impI Operator_Norm.onorm_le)
```
```  1122       apply (simp add:)
```
```  1123       apply (simp only: Rings.ring_class.left_diff_distrib [symmetric] norm_mult)
```
```  1124       apply (rule mult_right_mono [OF \<delta>])
```
```  1125       apply (auto simp: dist_commute Rings.ordered_semiring_class.mult_right_mono \<delta>)
```
```  1126       done
```
```  1127     with \<open>e>0\<close> show ?thesis by force
```
```  1128   qed
```
```  1129   have "inj (op * (deriv f \<xi>))"
```
```  1130     using dnz by simp
```
```  1131   then obtain g' where g': "linear g'" "g' \<circ> op * (deriv f \<xi>) = id"
```
```  1132     using linear_injective_left_inverse [of "op * (deriv f \<xi>)"]
```
```  1133     by (auto simp: linear_times)
```
```  1134   show ?thesis
```
```  1135     apply (rule has_derivative_locally_injective [OF S, where f=f and f' = "\<lambda>z h. deriv f z * h" and g' = g'])
```
```  1136     using g' *
```
```  1137     apply (simp_all add: linear_conv_bounded_linear that)
```
```  1138     using DERIV_deriv_iff_field_differentiable has_field_derivative_imp_has_derivative holf
```
```  1139         holomorphic_on_imp_differentiable_at \<open>open S\<close> apply blast
```
```  1140     done
```
```  1141 qed
```
```  1142
```
```  1143
```
```  1144 proposition has_complex_derivative_locally_invertible:
```
```  1145   assumes holf: "f holomorphic_on S"
```
```  1146       and S: "\<xi> \<in> S" "open S"
```
```  1147       and dnz: "deriv f \<xi> \<noteq> 0"
```
```  1148   obtains r where "r > 0" "ball \<xi> r \<subseteq> S" "open (f `  (ball \<xi> r))" "inj_on f (ball \<xi> r)"
```
```  1149 proof -
```
```  1150   obtain r where "r > 0" "ball \<xi> r \<subseteq> S" "inj_on f (ball \<xi> r)"
```
```  1151     by (blast intro: that has_complex_derivative_locally_injective [OF assms])
```
```  1152   then have \<xi>: "\<xi> \<in> ball \<xi> r" by simp
```
```  1153   then have nc: "~ f constant_on ball \<xi> r"
```
```  1154     using \<open>inj_on f (ball \<xi> r)\<close> injective_not_constant by fastforce
```
```  1155   have holf': "f holomorphic_on ball \<xi> r"
```
```  1156     using \<open>ball \<xi> r \<subseteq> S\<close> holf holomorphic_on_subset by blast
```
```  1157   have "open (f ` ball \<xi> r)"
```
```  1158     apply (rule open_mapping_thm [OF holf'])
```
```  1159     using nc apply auto
```
```  1160     done
```
```  1161   then show ?thesis
```
```  1162     using \<open>0 < r\<close> \<open>ball \<xi> r \<subseteq> S\<close> \<open>inj_on f (ball \<xi> r)\<close> that  by blast
```
```  1163 qed
```
```  1164
```
```  1165
```
```  1166 proposition holomorphic_injective_imp_regular:
```
```  1167   assumes holf: "f holomorphic_on S"
```
```  1168       and "open S" and injf: "inj_on f S"
```
```  1169       and "\<xi> \<in> S"
```
```  1170     shows "deriv f \<xi> \<noteq> 0"
```
```  1171 proof -
```
```  1172   obtain r where "r>0" and r: "ball \<xi> r \<subseteq> S" using assms by (blast elim!: openE)
```
```  1173   have holf': "f holomorphic_on ball \<xi> r"
```
```  1174     using \<open>ball \<xi> r \<subseteq> S\<close> holf holomorphic_on_subset by blast
```
```  1175   show ?thesis
```
```  1176   proof (cases "\<forall>n>0. (deriv ^^ n) f \<xi> = 0")
```
```  1177     case True
```
```  1178     have fcon: "f w = f \<xi>" if "w \<in> ball \<xi> r" for w
```
```  1179       apply (rule holomorphic_fun_eq_const_on_connected [OF holf'])
```
```  1180       using True \<open>0 < r\<close> that by auto
```
```  1181     have False
```
```  1182       using fcon [of "\<xi> + r/2"] \<open>0 < r\<close> r injf unfolding inj_on_def
```
```  1183       by (metis \<open>\<xi> \<in> S\<close> contra_subsetD dist_commute fcon mem_ball perfect_choose_dist)
```
```  1184     then show ?thesis ..
```
```  1185   next
```
```  1186     case False
```
```  1187     then obtain n0 where n0: "n0 > 0 \<and> (deriv ^^ n0) f \<xi> \<noteq> 0" by blast
```
```  1188     define n where [abs_def]: "n = (LEAST n. n > 0 \<and> (deriv ^^ n) f \<xi> \<noteq> 0)"
```
```  1189     have n_ne: "n > 0" "(deriv ^^ n) f \<xi> \<noteq> 0"
```
```  1190       using def_LeastI [OF n_def n0] by auto
```
```  1191     have n_min: "\<And>k. 0 < k \<Longrightarrow> k < n \<Longrightarrow> (deriv ^^ k) f \<xi> = 0"
```
```  1192       using def_Least_le [OF n_def] not_le by auto
```
```  1193     obtain g \<delta> where "0 < \<delta>"
```
```  1194              and holg: "g holomorphic_on ball \<xi> \<delta>"
```
```  1195              and fd: "\<And>w. w \<in> ball \<xi> \<delta> \<Longrightarrow> f w - f \<xi> = ((w - \<xi>) * g w) ^ n"
```
```  1196              and gnz: "\<And>w. w \<in> ball \<xi> \<delta> \<Longrightarrow> g w \<noteq> 0"
```
```  1197       apply (rule holomorphic_factor_order_of_zero_strong [OF holf \<open>open S\<close> \<open>\<xi> \<in> S\<close> n_ne])
```
```  1198       apply (blast intro: n_min)+
```
```  1199       done
```
```  1200     show ?thesis
```
```  1201     proof (cases "n=1")
```
```  1202       case True
```
```  1203       with n_ne show ?thesis by auto
```
```  1204     next
```
```  1205       case False
```
```  1206       have holgw: "(\<lambda>w. (w - \<xi>) * g w) holomorphic_on ball \<xi> (min r \<delta>)"
```
```  1207         apply (rule holomorphic_intros)+
```
```  1208         using holg by (simp add: holomorphic_on_subset subset_ball)
```
```  1209       have gd: "\<And>w. dist \<xi> w < \<delta> \<Longrightarrow> (g has_field_derivative deriv g w) (at w)"
```
```  1210         using holg
```
```  1211         by (simp add: DERIV_deriv_iff_field_differentiable holomorphic_on_def at_within_open_NO_MATCH)
```
```  1212       have *: "\<And>w. w \<in> ball \<xi> (min r \<delta>)
```
```  1213             \<Longrightarrow> ((\<lambda>w. (w - \<xi>) * g w) has_field_derivative ((w - \<xi>) * deriv g w + g w))
```
```  1214                 (at w)"
```
```  1215         by (rule gd derivative_eq_intros | simp)+
```
```  1216       have [simp]: "deriv (\<lambda>w. (w - \<xi>) * g w) \<xi> \<noteq> 0"
```
```  1217         using * [of \<xi>] \<open>0 < \<delta>\<close> \<open>0 < r\<close> by (simp add: DERIV_imp_deriv gnz)
```
```  1218       obtain T where "\<xi> \<in> T" "open T" and Tsb: "T \<subseteq> ball \<xi> (min r \<delta>)" and oimT: "open ((\<lambda>w. (w - \<xi>) * g w) ` T)"
```
```  1219         apply (rule has_complex_derivative_locally_invertible [OF holgw, of \<xi>])
```
```  1220         using \<open>0 < r\<close> \<open>0 < \<delta>\<close>
```
```  1221         apply (simp_all add:)
```
```  1222         by (meson Topology_Euclidean_Space.open_ball centre_in_ball)
```
```  1223       define U where "U = (\<lambda>w. (w - \<xi>) * g w) ` T"
```
```  1224       have "open U" by (metis oimT U_def)
```
```  1225       have "0 \<in> U"
```
```  1226         apply (auto simp: U_def)
```
```  1227         apply (rule image_eqI [where x = \<xi>])
```
```  1228         apply (auto simp: \<open>\<xi> \<in> T\<close>)
```
```  1229         done
```
```  1230       then obtain \<epsilon> where "\<epsilon>>0" and \<epsilon>: "cball 0 \<epsilon> \<subseteq> U"
```
```  1231         using \<open>open U\<close> open_contains_cball by blast
```
```  1232       then have "\<epsilon> * exp(2 * of_real pi * \<i> * (0/n)) \<in> cball 0 \<epsilon>"
```
```  1233                 "\<epsilon> * exp(2 * of_real pi * \<i> * (1/n)) \<in> cball 0 \<epsilon>"
```
```  1234         by (auto simp: norm_mult)
```
```  1235       with \<epsilon> have "\<epsilon> * exp(2 * of_real pi * \<i> * (0/n)) \<in> U"
```
```  1236                   "\<epsilon> * exp(2 * of_real pi * \<i> * (1/n)) \<in> U" by blast+
```
```  1237       then obtain y0 y1 where "y0 \<in> T" and y0: "(y0 - \<xi>) * g y0 = \<epsilon> * exp(2 * of_real pi * \<i> * (0/n))"
```
```  1238                           and "y1 \<in> T" and y1: "(y1 - \<xi>) * g y1 = \<epsilon> * exp(2 * of_real pi * \<i> * (1/n))"
```
```  1239         by (auto simp: U_def)
```
```  1240       then have "y0 \<in> ball \<xi> \<delta>" "y1 \<in> ball \<xi> \<delta>" using Tsb by auto
```
```  1241       moreover have "y0 \<noteq> y1"
```
```  1242         using y0 y1 \<open>\<epsilon> > 0\<close> complex_root_unity_eq_1 [of n 1] \<open>n > 0\<close> False by auto
```
```  1243       moreover have "T \<subseteq> S"
```
```  1244         by (meson Tsb min.cobounded1 order_trans r subset_ball)
```
```  1245       ultimately have False
```
```  1246         using inj_onD [OF injf, of y0 y1] \<open>y0 \<in> T\<close> \<open>y1 \<in> T\<close>
```
```  1247         using fd [of y0] fd [of y1] complex_root_unity [of n 1]
```
```  1248         apply (simp add: y0 y1 power_mult_distrib)
```
```  1249         apply (force simp: algebra_simps)
```
```  1250         done
```
```  1251       then show ?thesis ..
```
```  1252     qed
```
```  1253   qed
```
```  1254 qed
```
```  1255
```
```  1256
```
```  1257 text\<open>Hence a nice clean inverse function theorem\<close>
```
```  1258
```
```  1259 proposition holomorphic_has_inverse:
```
```  1260   assumes holf: "f holomorphic_on S"
```
```  1261       and "open S" and injf: "inj_on f S"
```
```  1262   obtains g where "g holomorphic_on (f ` S)"
```
```  1263                   "\<And>z. z \<in> S \<Longrightarrow> deriv f z * deriv g (f z) = 1"
```
```  1264                   "\<And>z. z \<in> S \<Longrightarrow> g(f z) = z"
```
```  1265 proof -
```
```  1266   have ofs: "open (f ` S)"
```
```  1267     by (rule open_mapping_thm3 [OF assms])
```
```  1268   have contf: "continuous_on S f"
```
```  1269     by (simp add: holf holomorphic_on_imp_continuous_on)
```
```  1270   have *: "(the_inv_into S f has_field_derivative inverse (deriv f z)) (at (f z))" if "z \<in> S" for z
```
```  1271   proof -
```
```  1272     have 1: "(f has_field_derivative deriv f z) (at z)"
```
```  1273       using DERIV_deriv_iff_field_differentiable \<open>z \<in> S\<close> \<open>open S\<close> holf holomorphic_on_imp_differentiable_at
```
```  1274       by blast
```
```  1275     have 2: "deriv f z \<noteq> 0"
```
```  1276       using \<open>z \<in> S\<close> \<open>open S\<close> holf holomorphic_injective_imp_regular injf by blast
```
```  1277     show ?thesis
```
```  1278       apply (rule has_complex_derivative_inverse_strong [OF 1 2 \<open>open S\<close> \<open>z \<in> S\<close>])
```
```  1279        apply (simp add: holf holomorphic_on_imp_continuous_on)
```
```  1280       by (simp add: injf the_inv_into_f_f)
```
```  1281   qed
```
```  1282   show ?thesis
```
```  1283     proof
```
```  1284       show "the_inv_into S f holomorphic_on f ` S"
```
```  1285         by (simp add: holomorphic_on_open ofs) (blast intro: *)
```
```  1286     next
```
```  1287       fix z assume "z \<in> S"
```
```  1288       have "deriv f z \<noteq> 0"
```
```  1289         using \<open>z \<in> S\<close> \<open>open S\<close> holf holomorphic_injective_imp_regular injf by blast
```
```  1290       then show "deriv f z * deriv (the_inv_into S f) (f z) = 1"
```
```  1291         using * [OF \<open>z \<in> S\<close>]  by (simp add: DERIV_imp_deriv)
```
```  1292     next
```
```  1293       fix z assume "z \<in> S"
```
```  1294       show "the_inv_into S f (f z) = z"
```
```  1295         by (simp add: \<open>z \<in> S\<close> injf the_inv_into_f_f)
```
```  1296   qed
```
```  1297 qed
```
```  1298
```
```  1299
```
```  1300 subsection\<open>The Schwarz Lemma\<close>
```
```  1301
```
```  1302 lemma Schwarz1:
```
```  1303   assumes holf: "f holomorphic_on S"
```
```  1304       and contf: "continuous_on (closure S) f"
```
```  1305       and S: "open S" "connected S"
```
```  1306       and boS: "bounded S"
```
```  1307       and "S \<noteq> {}"
```
```  1308   obtains w where "w \<in> frontier S"
```
```  1309                   "\<And>z. z \<in> closure S \<Longrightarrow> norm (f z) \<le> norm (f w)"
```
```  1310 proof -
```
```  1311   have connf: "continuous_on (closure S) (norm o f)"
```
```  1312     using contf continuous_on_compose continuous_on_norm_id by blast
```
```  1313   have coc: "compact (closure S)"
```
```  1314     by (simp add: \<open>bounded S\<close> bounded_closure compact_eq_bounded_closed)
```
```  1315   then obtain x where x: "x \<in> closure S" and xmax: "\<And>z. z \<in> closure S \<Longrightarrow> norm(f z) \<le> norm(f x)"
```
```  1316     apply (rule bexE [OF continuous_attains_sup [OF _ _ connf]])
```
```  1317     using \<open>S \<noteq> {}\<close> apply auto
```
```  1318     done
```
```  1319   then show ?thesis
```
```  1320   proof (cases "x \<in> frontier S")
```
```  1321     case True
```
```  1322     then show ?thesis using that xmax by blast
```
```  1323   next
```
```  1324     case False
```
```  1325     then have "x \<in> S"
```
```  1326       using \<open>open S\<close> frontier_def interior_eq x by auto
```
```  1327     then have "f constant_on S"
```
```  1328       apply (rule maximum_modulus_principle [OF holf S \<open>open S\<close> order_refl])
```
```  1329       using closure_subset apply (blast intro: xmax)
```
```  1330       done
```
```  1331     then have "f constant_on (closure S)"
```
```  1332       by (rule constant_on_closureI [OF _ contf])
```
```  1333     then obtain c where c: "\<And>x. x \<in> closure S \<Longrightarrow> f x = c"
```
```  1334       by (meson constant_on_def)
```
```  1335     obtain w where "w \<in> frontier S"
```
```  1336       by (metis coc all_not_in_conv assms(6) closure_UNIV frontier_eq_empty not_compact_UNIV)
```
```  1337     then show ?thesis
```
```  1338       by (simp add: c frontier_def that)
```
```  1339   qed
```
```  1340 qed
```
```  1341
```
```  1342 lemma Schwarz2:
```
```  1343  "\<lbrakk>f holomorphic_on ball 0 r;
```
```  1344     0 < s; ball w s \<subseteq> ball 0 r;
```
```  1345     \<And>z. norm (w-z) < s \<Longrightarrow> norm(f z) \<le> norm(f w)\<rbrakk>
```
```  1346     \<Longrightarrow> f constant_on ball 0 r"
```
```  1347 by (rule maximum_modulus_principle [where U = "ball w s" and \<xi> = w]) (simp_all add: dist_norm)
```
```  1348
```
```  1349 lemma Schwarz3:
```
```  1350   assumes holf: "f holomorphic_on (ball 0 r)" and [simp]: "f 0 = 0"
```
```  1351   obtains h where "h holomorphic_on (ball 0 r)" and "\<And>z. norm z < r \<Longrightarrow> f z = z * (h z)" and "deriv f 0 = h 0"
```
```  1352 proof -
```
```  1353   define h where "h z = (if z = 0 then deriv f 0 else f z / z)" for z
```
```  1354   have d0: "deriv f 0 = h 0"
```
```  1355     by (simp add: h_def)
```
```  1356   moreover have "h holomorphic_on (ball 0 r)"
```
```  1357     by (rule pole_theorem_open_0 [OF holf, of 0]) (auto simp: h_def)
```
```  1358   moreover have "norm z < r \<Longrightarrow> f z = z * h z" for z
```
```  1359     by (simp add: h_def)
```
```  1360   ultimately show ?thesis
```
```  1361     using that by blast
```
```  1362 qed
```
```  1363
```
```  1364
```
```  1365 proposition Schwarz_Lemma:
```
```  1366   assumes holf: "f holomorphic_on (ball 0 1)" and [simp]: "f 0 = 0"
```
```  1367       and no: "\<And>z. norm z < 1 \<Longrightarrow> norm (f z) < 1"
```
```  1368       and \<xi>: "norm \<xi> < 1"
```
```  1369     shows "norm (f \<xi>) \<le> norm \<xi>" and "norm(deriv f 0) \<le> 1"
```
```  1370       and "((\<exists>z. norm z < 1 \<and> z \<noteq> 0 \<and> norm(f z) = norm z) \<or> norm(deriv f 0) = 1)
```
```  1371            \<Longrightarrow> \<exists>\<alpha>. (\<forall>z. norm z < 1 \<longrightarrow> f z = \<alpha> * z) \<and> norm \<alpha> = 1" (is "?P \<Longrightarrow> ?Q")
```
```  1372 proof -
```
```  1373   obtain h where holh: "h holomorphic_on (ball 0 1)"
```
```  1374              and fz_eq: "\<And>z. norm z < 1 \<Longrightarrow> f z = z * (h z)" and df0: "deriv f 0 = h 0"
```
```  1375     by (rule Schwarz3 [OF holf]) auto
```
```  1376   have noh_le: "norm (h z) \<le> 1" if z: "norm z < 1" for z
```
```  1377   proof -
```
```  1378     have "norm (h z) < a" if a: "1 < a" for a
```
```  1379     proof -
```
```  1380       have "max (inverse a) (norm z) < 1"
```
```  1381         using z a by (simp_all add: inverse_less_1_iff)
```
```  1382       then obtain r where r: "max (inverse a) (norm z) < r" and "r < 1"
```
```  1383         using Rats_dense_in_real by blast
```
```  1384       then have nzr: "norm z < r" and ira: "inverse r < a"
```
```  1385         using z a less_imp_inverse_less by force+
```
```  1386       then have "0 < r"
```
```  1387         by (meson norm_not_less_zero not_le order.strict_trans2)
```
```  1388       have holh': "h holomorphic_on ball 0 r"
```
```  1389         by (meson holh \<open>r < 1\<close> holomorphic_on_subset less_eq_real_def subset_ball)
```
```  1390       have conth': "continuous_on (cball 0 r) h"
```
```  1391         by (meson \<open>r < 1\<close> dual_order.trans holh holomorphic_on_imp_continuous_on holomorphic_on_subset mem_ball_0 mem_cball_0 not_less subsetI)
```
```  1392       obtain w where w: "norm w = r" and lenw: "\<And>z. norm z < r \<Longrightarrow> norm(h z) \<le> norm(h w)"
```
```  1393         apply (rule Schwarz1 [OF holh']) using conth' \<open>0 < r\<close> by auto
```
```  1394       have "h w = f w / w" using fz_eq \<open>r < 1\<close> nzr w by auto
```
```  1395       then have "cmod (h z) < inverse r"
```
```  1396         by (metis \<open>0 < r\<close> \<open>r < 1\<close> divide_strict_right_mono inverse_eq_divide
```
```  1397                   le_less_trans lenw no norm_divide nzr w)
```
```  1398       then show ?thesis using ira by linarith
```
```  1399     qed
```
```  1400     then show "norm (h z) \<le> 1"
```
```  1401       using not_le by blast
```
```  1402   qed
```
```  1403   show "cmod (f \<xi>) \<le> cmod \<xi>"
```
```  1404   proof (cases "\<xi> = 0")
```
```  1405     case True then show ?thesis by auto
```
```  1406   next
```
```  1407     case False
```
```  1408     then show ?thesis
```
```  1409       by (simp add: noh_le fz_eq \<xi> mult_left_le norm_mult)
```
```  1410   qed
```
```  1411   show no_df0: "norm(deriv f 0) \<le> 1"
```
```  1412     by (simp add: \<open>\<And>z. cmod z < 1 \<Longrightarrow> cmod (h z) \<le> 1\<close> df0)
```
```  1413   show "?Q" if "?P"
```
```  1414     using that
```
```  1415   proof
```
```  1416     assume "\<exists>z. cmod z < 1 \<and> z \<noteq> 0 \<and> cmod (f z) = cmod z"
```
```  1417     then obtain \<gamma> where \<gamma>: "cmod \<gamma> < 1" "\<gamma> \<noteq> 0" "cmod (f \<gamma>) = cmod \<gamma>" by blast
```
```  1418     then have [simp]: "norm (h \<gamma>) = 1"
```
```  1419       by (simp add: fz_eq norm_mult)
```
```  1420     have "ball \<gamma> (1 - cmod \<gamma>) \<subseteq> ball 0 1"
```
```  1421       by (simp add: ball_subset_ball_iff)
```
```  1422     moreover have "\<And>z. cmod (\<gamma> - z) < 1 - cmod \<gamma> \<Longrightarrow> cmod (h z) \<le> cmod (h \<gamma>)"
```
```  1423       apply (simp add: algebra_simps)
```
```  1424       by (metis add_diff_cancel_left' diff_diff_eq2 le_less_trans noh_le norm_triangle_ineq4)
```
```  1425     ultimately obtain c where c: "\<And>z. norm z < 1 \<Longrightarrow> h z = c"
```
```  1426       using Schwarz2 [OF holh, of "1 - norm \<gamma>" \<gamma>, unfolded constant_on_def] \<gamma> by auto
```
```  1427     then have "norm c = 1"
```
```  1428       using \<gamma> by force
```
```  1429     with c show ?thesis
```
```  1430       using fz_eq by auto
```
```  1431   next
```
```  1432     assume [simp]: "cmod (deriv f 0) = 1"
```
```  1433     then obtain c where c: "\<And>z. norm z < 1 \<Longrightarrow> h z = c"
```
```  1434       using Schwarz2 [OF holh zero_less_one, of 0, unfolded constant_on_def] df0 noh_le
```
```  1435       by auto
```
```  1436     moreover have "norm c = 1"  using df0 c by auto
```
```  1437     ultimately show ?thesis
```
```  1438       using fz_eq by auto
```
```  1439   qed
```
```  1440 qed
```
```  1441
```
```  1442 subsection\<open>The Schwarz reflection principle\<close>
```
```  1443
```
```  1444 lemma hol_pal_lem0:
```
```  1445   assumes "d \<bullet> a \<le> k" "k \<le> d \<bullet> b"
```
```  1446   obtains c where
```
```  1447      "c \<in> closed_segment a b" "d \<bullet> c = k"
```
```  1448      "\<And>z. z \<in> closed_segment a c \<Longrightarrow> d \<bullet> z \<le> k"
```
```  1449      "\<And>z. z \<in> closed_segment c b \<Longrightarrow> k \<le> d \<bullet> z"
```
```  1450 proof -
```
```  1451   obtain c where cin: "c \<in> closed_segment a b" and keq: "k = d \<bullet> c"
```
```  1452     using connected_ivt_hyperplane [of "closed_segment a b" a b d k]
```
```  1453     by (auto simp: assms)
```
```  1454   have "closed_segment a c \<subseteq> {z. d \<bullet> z \<le> k}"  "closed_segment c b \<subseteq> {z. k \<le> d \<bullet> z}"
```
```  1455     unfolding segment_convex_hull using assms keq
```
```  1456     by (auto simp: convex_halfspace_le convex_halfspace_ge hull_minimal)
```
```  1457   then show ?thesis using cin that by fastforce
```
```  1458 qed
```
```  1459
```
```  1460 lemma hol_pal_lem1:
```
```  1461   assumes "convex S" "open S"
```
```  1462       and abc: "a \<in> S" "b \<in> S" "c \<in> S"
```
```  1463           "d \<noteq> 0" and lek: "d \<bullet> a \<le> k" "d \<bullet> b \<le> k" "d \<bullet> c \<le> k"
```
```  1464       and holf1: "f holomorphic_on {z. z \<in> S \<and> d \<bullet> z < k}"
```
```  1465       and contf: "continuous_on S f"
```
```  1466     shows "contour_integral (linepath a b) f +
```
```  1467            contour_integral (linepath b c) f +
```
```  1468            contour_integral (linepath c a) f = 0"
```
```  1469 proof -
```
```  1470   have "interior (convex hull {a, b, c}) \<subseteq> interior(S \<inter> {x. d \<bullet> x \<le> k})"
```
```  1471     apply (rule interior_mono)
```
```  1472     apply (rule hull_minimal)
```
```  1473      apply (simp add: abc lek)
```
```  1474     apply (rule convex_Int [OF \<open>convex S\<close> convex_halfspace_le])
```
```  1475     done
```
```  1476   also have "... \<subseteq> {z \<in> S. d \<bullet> z < k}"
```
```  1477     by (force simp: interior_open [OF \<open>open S\<close>] \<open>d \<noteq> 0\<close>)
```
```  1478   finally have *: "interior (convex hull {a, b, c}) \<subseteq> {z \<in> S. d \<bullet> z < k}" .
```
```  1479   have "continuous_on (convex hull {a,b,c}) f"
```
```  1480     using \<open>convex S\<close> contf abc continuous_on_subset subset_hull
```
```  1481     by fastforce
```
```  1482   moreover have "f holomorphic_on interior (convex hull {a,b,c})"
```
```  1483     by (rule holomorphic_on_subset [OF holf1 *])
```
```  1484   ultimately show ?thesis
```
```  1485     using Cauchy_theorem_triangle_interior has_chain_integral_chain_integral3
```
```  1486       by blast
```
```  1487 qed
```
```  1488
```
```  1489 lemma hol_pal_lem2:
```
```  1490   assumes S: "convex S" "open S"
```
```  1491       and abc: "a \<in> S" "b \<in> S" "c \<in> S"
```
```  1492       and "d \<noteq> 0" and lek: "d \<bullet> a \<le> k" "d \<bullet> b \<le> k"
```
```  1493       and holf1: "f holomorphic_on {z. z \<in> S \<and> d \<bullet> z < k}"
```
```  1494       and holf2: "f holomorphic_on {z. z \<in> S \<and> k < d \<bullet> z}"
```
```  1495       and contf: "continuous_on S f"
```
```  1496     shows "contour_integral (linepath a b) f +
```
```  1497            contour_integral (linepath b c) f +
```
```  1498            contour_integral (linepath c a) f = 0"
```
```  1499 proof (cases "d \<bullet> c \<le> k")
```
```  1500   case True show ?thesis
```
```  1501     by (rule hol_pal_lem1 [OF S abc \<open>d \<noteq> 0\<close> lek True holf1 contf])
```
```  1502 next
```
```  1503   case False
```
```  1504   then have "d \<bullet> c > k" by force
```
```  1505   obtain a' where a': "a' \<in> closed_segment b c" and "d \<bullet> a' = k"
```
```  1506      and ba': "\<And>z. z \<in> closed_segment b a' \<Longrightarrow> d \<bullet> z \<le> k"
```
```  1507      and a'c: "\<And>z. z \<in> closed_segment a' c \<Longrightarrow> k \<le> d \<bullet> z"
```
```  1508     apply (rule hol_pal_lem0 [of d b k c, OF \<open>d \<bullet> b \<le> k\<close>])
```
```  1509     using False by auto
```
```  1510   obtain b' where b': "b' \<in> closed_segment a c" and "d \<bullet> b' = k"
```
```  1511      and ab': "\<And>z. z \<in> closed_segment a b' \<Longrightarrow> d \<bullet> z \<le> k"
```
```  1512      and b'c: "\<And>z. z \<in> closed_segment b' c \<Longrightarrow> k \<le> d \<bullet> z"
```
```  1513     apply (rule hol_pal_lem0 [of d a k c, OF \<open>d \<bullet> a \<le> k\<close>])
```
```  1514     using False by auto
```
```  1515   have a'b': "a' \<in> S \<and> b' \<in> S"
```
```  1516     using a' abc b' convex_contains_segment \<open>convex S\<close> by auto
```
```  1517   have "continuous_on (closed_segment c a) f"
```
```  1518     by (meson abc contf continuous_on_subset convex_contains_segment \<open>convex S\<close>)
```
```  1519   then have 1: "contour_integral (linepath c a) f =
```
```  1520                 contour_integral (linepath c b') f + contour_integral (linepath b' a) f"
```
```  1521     apply (rule contour_integral_split_linepath)
```
```  1522     using b' by (simp add: closed_segment_commute)
```
```  1523   have "continuous_on (closed_segment b c) f"
```
```  1524     by (meson abc contf continuous_on_subset convex_contains_segment \<open>convex S\<close>)
```
```  1525   then have 2: "contour_integral (linepath b c) f =
```
```  1526                 contour_integral (linepath b a') f + contour_integral (linepath a' c) f"
```
```  1527     by (rule contour_integral_split_linepath [OF _ a'])
```
```  1528   have 3: "contour_integral (reversepath (linepath b' a')) f =
```
```  1529                 - contour_integral (linepath b' a') f"
```
```  1530     by (rule contour_integral_reversepath [OF valid_path_linepath])
```
```  1531   have fcd_le: "f field_differentiable at x"
```
```  1532                if "x \<in> interior S \<and> x \<in> interior {x. d \<bullet> x \<le> k}" for x
```
```  1533   proof -
```
```  1534     have "f holomorphic_on S \<inter> {c. d \<bullet> c < k}"
```
```  1535       by (metis (no_types) Collect_conj_eq Collect_mem_eq holf1)
```
```  1536     then have "\<exists>C D. x \<in> interior C \<inter> interior D \<and> f holomorphic_on interior C \<inter> interior D"
```
```  1537       using that
```
```  1538       by (metis Collect_mem_eq Int_Collect \<open>d \<noteq> 0\<close> interior_halfspace_le interior_open \<open>open S\<close>)
```
```  1539     then show "f field_differentiable at x"
```
```  1540       by (metis at_within_interior holomorphic_on_def interior_Int interior_interior)
```
```  1541   qed
```
```  1542   have ab_le: "\<And>x. x \<in> closed_segment a b \<Longrightarrow> d \<bullet> x \<le> k"
```
```  1543   proof -
```
```  1544     fix x :: complex
```
```  1545     assume "x \<in> closed_segment a b"
```
```  1546     then have "\<And>C. x \<in> C \<or> b \<notin> C \<or> a \<notin> C \<or> \<not> convex C"
```
```  1547       by (meson contra_subsetD convex_contains_segment)
```
```  1548     then show "d \<bullet> x \<le> k"
```
```  1549       by (metis lek convex_halfspace_le mem_Collect_eq)
```
```  1550   qed
```
```  1551   have "continuous_on (S \<inter> {x. d \<bullet> x \<le> k}) f" using contf
```
```  1552     by (simp add: continuous_on_subset)
```
```  1553   then have "(f has_contour_integral 0)
```
```  1554          (linepath a b +++ linepath b a' +++ linepath a' b' +++ linepath b' a)"
```
```  1555     apply (rule Cauchy_theorem_convex [where k = "{}"])
```
```  1556     apply (simp_all add: path_image_join convex_Int convex_halfspace_le \<open>convex S\<close> fcd_le ab_le
```
```  1557                 closed_segment_subset abc a'b' ba')
```
```  1558     by (metis \<open>d \<bullet> a' = k\<close> \<open>d \<bullet> b' = k\<close> convex_contains_segment convex_halfspace_le lek(1) mem_Collect_eq order_refl)
```
```  1559   then have 4: "contour_integral (linepath a b) f +
```
```  1560                 contour_integral (linepath b a') f +
```
```  1561                 contour_integral (linepath a' b') f +
```
```  1562                 contour_integral (linepath b' a) f = 0"
```
```  1563     by (rule has_chain_integral_chain_integral4)
```
```  1564   have fcd_ge: "f field_differentiable at x"
```
```  1565                if "x \<in> interior S \<and> x \<in> interior {x. k \<le> d \<bullet> x}" for x
```
```  1566   proof -
```
```  1567     have f2: "f holomorphic_on S \<inter> {c. k < d \<bullet> c}"
```
```  1568       by (metis (full_types) Collect_conj_eq Collect_mem_eq holf2)
```
```  1569     have f3: "interior S = S"
```
```  1570       by (simp add: interior_open \<open>open S\<close>)
```
```  1571     then have "x \<in> S \<inter> interior {c. k \<le> d \<bullet> c}"
```
```  1572       using that by simp
```
```  1573     then show "f field_differentiable at x"
```
```  1574       using f3 f2 unfolding holomorphic_on_def
```
```  1575       by (metis (no_types) \<open>d \<noteq> 0\<close> at_within_interior interior_Int interior_halfspace_ge interior_interior)
```
```  1576   qed
```
```  1577   have "continuous_on (S \<inter> {x. k \<le> d \<bullet> x}) f" using contf
```
```  1578     by (simp add: continuous_on_subset)
```
```  1579   then have "(f has_contour_integral 0) (linepath a' c +++ linepath c b' +++ linepath b' a')"
```
```  1580     apply (rule Cauchy_theorem_convex [where k = "{}"])
```
```  1581     apply (simp_all add: path_image_join convex_Int convex_halfspace_ge \<open>convex S\<close>
```
```  1582                       fcd_ge closed_segment_subset abc a'b' a'c)
```
```  1583     by (metis \<open>d \<bullet> a' = k\<close> b'c closed_segment_commute convex_contains_segment
```
```  1584               convex_halfspace_ge ends_in_segment(2) mem_Collect_eq order_refl)
```
```  1585   then have 5: "contour_integral (linepath a' c) f + contour_integral (linepath c b') f + contour_integral (linepath b' a') f = 0"
```
```  1586     by (rule has_chain_integral_chain_integral3)
```
```  1587   show ?thesis
```
```  1588     using 1 2 3 4 5 by (metis add.assoc eq_neg_iff_add_eq_0 reversepath_linepath)
```
```  1589 qed
```
```  1590
```
```  1591 lemma hol_pal_lem3:
```
```  1592   assumes S: "convex S" "open S"
```
```  1593       and abc: "a \<in> S" "b \<in> S" "c \<in> S"
```
```  1594       and "d \<noteq> 0" and lek: "d \<bullet> a \<le> k"
```
```  1595       and holf1: "f holomorphic_on {z. z \<in> S \<and> d \<bullet> z < k}"
```
```  1596       and holf2: "f holomorphic_on {z. z \<in> S \<and> k < d \<bullet> z}"
```
```  1597       and contf: "continuous_on S f"
```
```  1598     shows "contour_integral (linepath a b) f +
```
```  1599            contour_integral (linepath b c) f +
```
```  1600            contour_integral (linepath c a) f = 0"
```
```  1601 proof (cases "d \<bullet> b \<le> k")
```
```  1602   case True show ?thesis
```
```  1603     by (rule hol_pal_lem2 [OF S abc \<open>d \<noteq> 0\<close> lek True holf1 holf2 contf])
```
```  1604 next
```
```  1605   case False
```
```  1606   show ?thesis
```
```  1607   proof (cases "d \<bullet> c \<le> k")
```
```  1608     case True
```
```  1609     have "contour_integral (linepath c a) f +
```
```  1610           contour_integral (linepath a b) f +
```
```  1611           contour_integral (linepath b c) f = 0"
```
```  1612       by (rule hol_pal_lem2 [OF S \<open>c \<in> S\<close> \<open>a \<in> S\<close> \<open>b \<in> S\<close> \<open>d \<noteq> 0\<close> \<open>d \<bullet> c \<le> k\<close> lek holf1 holf2 contf])
```
```  1613     then show ?thesis
```
```  1614       by (simp add: algebra_simps)
```
```  1615   next
```
```  1616     case False
```
```  1617     have "contour_integral (linepath b c) f +
```
```  1618           contour_integral (linepath c a) f +
```
```  1619           contour_integral (linepath a b) f = 0"
```
```  1620       apply (rule hol_pal_lem2 [OF S \<open>b \<in> S\<close> \<open>c \<in> S\<close> \<open>a \<in> S\<close>, of "-d" "-k"])
```
```  1621       using \<open>d \<noteq> 0\<close> \<open>\<not> d \<bullet> b \<le> k\<close> False by (simp_all add: holf1 holf2 contf)
```
```  1622     then show ?thesis
```
```  1623       by (simp add: algebra_simps)
```
```  1624   qed
```
```  1625 qed
```
```  1626
```
```  1627 lemma hol_pal_lem4:
```
```  1628   assumes S: "convex S" "open S"
```
```  1629       and abc: "a \<in> S" "b \<in> S" "c \<in> S" and "d \<noteq> 0"
```
```  1630       and holf1: "f holomorphic_on {z. z \<in> S \<and> d \<bullet> z < k}"
```
```  1631       and holf2: "f holomorphic_on {z. z \<in> S \<and> k < d \<bullet> z}"
```
```  1632       and contf: "continuous_on S f"
```
```  1633     shows "contour_integral (linepath a b) f +
```
```  1634            contour_integral (linepath b c) f +
```
```  1635            contour_integral (linepath c a) f = 0"
```
```  1636 proof (cases "d \<bullet> a \<le> k")
```
```  1637   case True show ?thesis
```
```  1638     by (rule hol_pal_lem3 [OF S abc \<open>d \<noteq> 0\<close> True holf1 holf2 contf])
```
```  1639 next
```
```  1640   case False
```
```  1641   show ?thesis
```
```  1642     apply (rule hol_pal_lem3 [OF S abc, of "-d" "-k"])
```
```  1643     using \<open>d \<noteq> 0\<close> False by (simp_all add: holf1 holf2 contf)
```
```  1644 qed
```
```  1645
```
```  1646 proposition holomorphic_on_paste_across_line:
```
```  1647   assumes S: "open S" and "d \<noteq> 0"
```
```  1648       and holf1: "f holomorphic_on (S \<inter> {z. d \<bullet> z < k})"
```
```  1649       and holf2: "f holomorphic_on (S \<inter> {z. k < d \<bullet> z})"
```
```  1650       and contf: "continuous_on S f"
```
```  1651     shows "f holomorphic_on S"
```
```  1652 proof -
```
```  1653   have *: "\<exists>t. open t \<and> p \<in> t \<and> continuous_on t f \<and>
```
```  1654                (\<forall>a b c. convex hull {a, b, c} \<subseteq> t \<longrightarrow>
```
```  1655                          contour_integral (linepath a b) f +
```
```  1656                          contour_integral (linepath b c) f +
```
```  1657                          contour_integral (linepath c a) f = 0)"
```
```  1658           if "p \<in> S" for p
```
```  1659   proof -
```
```  1660     obtain e where "e>0" and e: "ball p e \<subseteq> S"
```
```  1661       using \<open>p \<in> S\<close> openE S by blast
```
```  1662     then have "continuous_on (ball p e) f"
```
```  1663       using contf continuous_on_subset by blast
```
```  1664     moreover have "f holomorphic_on {z. dist p z < e \<and> d \<bullet> z < k}"
```
```  1665       apply (rule holomorphic_on_subset [OF holf1])
```
```  1666       using e by auto
```
```  1667     moreover have "f holomorphic_on {z. dist p z < e \<and> k < d \<bullet> z}"
```
```  1668       apply (rule holomorphic_on_subset [OF holf2])
```
```  1669       using e by auto
```
```  1670     ultimately show ?thesis
```
```  1671       apply (rule_tac x="ball p e" in exI)
```
```  1672       using \<open>e > 0\<close> e \<open>d \<noteq> 0\<close>
```
```  1673       apply (simp add:, clarify)
```
```  1674       apply (rule hol_pal_lem4 [of "ball p e" _ _ _ d _ k])
```
```  1675       apply (auto simp: subset_hull)
```
```  1676       done
```
```  1677   qed
```
```  1678   show ?thesis
```
```  1679     by (blast intro: * Morera_local_triangle analytic_imp_holomorphic)
```
```  1680 qed
```
```  1681
```
```  1682 proposition Schwarz_reflection:
```
```  1683   assumes "open S" and cnjs: "cnj ` S \<subseteq> S"
```
```  1684       and  holf: "f holomorphic_on (S \<inter> {z. 0 < Im z})"
```
```  1685       and contf: "continuous_on (S \<inter> {z. 0 \<le> Im z}) f"
```
```  1686       and f: "\<And>z. \<lbrakk>z \<in> S; z \<in> \<real>\<rbrakk> \<Longrightarrow> (f z) \<in> \<real>"
```
```  1687     shows "(\<lambda>z. if 0 \<le> Im z then f z else cnj(f(cnj z))) holomorphic_on S"
```
```  1688 proof -
```
```  1689   have 1: "(\<lambda>z. if 0 \<le> Im z then f z else cnj (f (cnj z))) holomorphic_on (S \<inter> {z. 0 < Im z})"
```
```  1690     by (force intro: iffD1 [OF holomorphic_cong [OF refl] holf])
```
```  1691   have cont_cfc: "continuous_on (S \<inter> {z. Im z \<le> 0}) (cnj o f o cnj)"
```
```  1692     apply (intro continuous_intros continuous_on_compose continuous_on_subset [OF contf])
```
```  1693     using cnjs apply auto
```
```  1694     done
```
```  1695   have "cnj \<circ> f \<circ> cnj field_differentiable at x within S \<inter> {z. Im z < 0}"
```
```  1696         if "x \<in> S" "Im x < 0" "f field_differentiable at (cnj x) within S \<inter> {z. 0 < Im z}" for x
```
```  1697     using that
```
```  1698     apply (simp add: field_differentiable_def Derivative.DERIV_within_iff Lim_within dist_norm, clarify)
```
```  1699     apply (rule_tac x="cnj f'" in exI)
```
```  1700     apply (elim all_forward ex_forward conj_forward imp_forward asm_rl, clarify)
```
```  1701     apply (drule_tac x="cnj xa" in bspec)
```
```  1702     using cnjs apply force
```
```  1703     apply (metis complex_cnj_cnj complex_cnj_diff complex_cnj_divide complex_mod_cnj)
```
```  1704     done
```
```  1705   then have hol_cfc: "(cnj o f o cnj) holomorphic_on (S \<inter> {z. Im z < 0})"
```
```  1706     using holf cnjs
```
```  1707     by (force simp: holomorphic_on_def)
```
```  1708   have 2: "(\<lambda>z. if 0 \<le> Im z then f z else cnj (f (cnj z))) holomorphic_on (S \<inter> {z. Im z < 0})"
```
```  1709     apply (rule iffD1 [OF holomorphic_cong [OF refl]])
```
```  1710     using hol_cfc by auto
```
```  1711   have [simp]: "(S \<inter> {z. 0 \<le> Im z}) \<union> (S \<inter> {z. Im z \<le> 0}) = S"
```
```  1712     by force
```
```  1713   have "continuous_on ((S \<inter> {z. 0 \<le> Im z}) \<union> (S \<inter> {z. Im z \<le> 0}))
```
```  1714                        (\<lambda>z. if 0 \<le> Im z then f z else cnj (f (cnj z)))"
```
```  1715     apply (rule continuous_on_cases_local)
```
```  1716     using cont_cfc contf
```
```  1717     apply (simp_all add: closedin_closed_Int closed_halfspace_Im_le closed_halfspace_Im_ge)
```
```  1718     using f Reals_cnj_iff complex_is_Real_iff apply auto
```
```  1719     done
```
```  1720   then have 3: "continuous_on S (\<lambda>z. if 0 \<le> Im z then f z else cnj (f (cnj z)))"
```
```  1721     by force
```
```  1722   show ?thesis
```
```  1723     apply (rule holomorphic_on_paste_across_line [OF \<open>open S\<close>, of "- \<i>" _ 0])
```
```  1724     using 1 2 3
```
```  1725     apply auto
```
```  1726     done
```
```  1727 qed
```
```  1728
```
```  1729 subsection\<open>Bloch's theorem\<close>
```
```  1730
```
```  1731 lemma Bloch_lemma_0:
```
```  1732   assumes holf: "f holomorphic_on cball 0 r" and "0 < r"
```
```  1733       and [simp]: "f 0 = 0"
```
```  1734       and le: "\<And>z. norm z < r \<Longrightarrow> norm(deriv f z) \<le> 2 * norm(deriv f 0)"
```
```  1735     shows "ball 0 ((3 - 2 * sqrt 2) * r * norm(deriv f 0)) \<subseteq> f ` ball 0 r"
```
```  1736 proof -
```
```  1737   have "sqrt 2 < 3/2"
```
```  1738     by (rule real_less_lsqrt) (auto simp: power2_eq_square)
```
```  1739   then have sq3: "0 < 3 - 2 * sqrt 2" by simp
```
```  1740   show ?thesis
```
```  1741   proof (cases "deriv f 0 = 0")
```
```  1742     case True then show ?thesis by simp
```
```  1743   next
```
```  1744     case False
```
```  1745     define C where "C = 2 * norm(deriv f 0)"
```
```  1746     have "0 < C" using False by (simp add: C_def)
```
```  1747     have holf': "f holomorphic_on ball 0 r" using holf
```
```  1748       using ball_subset_cball holomorphic_on_subset by blast
```
```  1749     then have holdf': "deriv f holomorphic_on ball 0 r"
```
```  1750       by (rule holomorphic_deriv [OF _ open_ball])
```
```  1751     have "Le1": "norm(deriv f z - deriv f 0) \<le> norm z / (r - norm z) * C"
```
```  1752                 if "norm z < r" for z
```
```  1753     proof -
```
```  1754       have T1: "norm(deriv f z - deriv f 0) \<le> norm z / (R - norm z) * C"
```
```  1755               if R: "norm z < R" "R < r" for R
```
```  1756       proof -
```
```  1757         have "0 < R" using R
```
```  1758           by (metis less_trans norm_zero zero_less_norm_iff)
```
```  1759         have df_le: "\<And>x. norm x < r \<Longrightarrow> norm (deriv f x) \<le> C"
```
```  1760           using le by (simp add: C_def)
```
```  1761         have hol_df: "deriv f holomorphic_on cball 0 R"
```
```  1762           apply (rule holomorphic_on_subset) using R holdf' by auto
```
```  1763         have *: "((\<lambda>w. deriv f w / (w - z)) has_contour_integral 2 * pi * \<i> * deriv f z) (circlepath 0 R)"
```
```  1764                  if "norm z < R" for z
```
```  1765           using \<open>0 < R\<close> that Cauchy_integral_formula_convex_simple [OF convex_cball hol_df, of _ "circlepath 0 R"]
```
```  1766           by (force simp: winding_number_circlepath)
```
```  1767         have **: "((\<lambda>x. deriv f x / (x - z) - deriv f x / x) has_contour_integral
```
```  1768                    of_real (2 * pi) * \<i> * (deriv f z - deriv f 0))
```
```  1769                   (circlepath 0 R)"
```
```  1770            using has_contour_integral_diff [OF * [of z] * [of 0]] \<open>0 < R\<close> that
```
```  1771            by (simp add: algebra_simps)
```
```  1772         have [simp]: "\<And>x. norm x = R \<Longrightarrow> x \<noteq> z"  using that(1) by blast
```
```  1773         have "norm (deriv f x / (x - z) - deriv f x / x)
```
```  1774                      \<le> C * norm z / (R * (R - norm z))"
```
```  1775                   if "norm x = R" for x
```
```  1776         proof -
```
```  1777           have [simp]: "norm (deriv f x * x - deriv f x * (x - z)) =
```
```  1778                         norm (deriv f x) * norm z"
```
```  1779             by (simp add: norm_mult right_diff_distrib')
```
```  1780           show ?thesis
```
```  1781             using  \<open>0 < R\<close> \<open>0 < C\<close> R that
```
```  1782             apply (simp add: norm_mult norm_divide divide_simps)
```
```  1783             using df_le norm_triangle_ineq2 \<open>0 < C\<close> apply (auto intro!: mult_mono)
```
```  1784             done
```
```  1785         qed
```
```  1786         then show ?thesis
```
```  1787           using has_contour_integral_bound_circlepath
```
```  1788                   [OF **, of "C * norm z/(R*(R - norm z))"]
```
```  1789                 \<open>0 < R\<close> \<open>0 < C\<close> R
```
```  1790           apply (simp add: norm_mult norm_divide)
```
```  1791           apply (simp add: divide_simps mult.commute)
```
```  1792           done
```
```  1793       qed
```
```  1794       obtain r' where r': "norm z < r'" "r' < r"
```
```  1795         using Rats_dense_in_real [of "norm z" r] \<open>norm z < r\<close> by blast
```
```  1796       then have [simp]: "closure {r'<..<r} = {r'..r}" by simp
```
```  1797       show ?thesis
```
```  1798         apply (rule continuous_ge_on_closure
```
```  1799                  [where f = "\<lambda>r. norm z / (r - norm z) * C" and s = "{r'<..<r}",
```
```  1800                   OF _ _ T1])
```
```  1801         apply (intro continuous_intros)
```
```  1802         using that r'
```
```  1803         apply (auto simp: not_le)
```
```  1804         done
```
```  1805     qed
```
```  1806     have "*": "(norm z - norm z^2/(r - norm z)) * norm(deriv f 0) \<le> norm(f z)"
```
```  1807               if r: "norm z < r" for z
```
```  1808     proof -
```
```  1809       have 1: "\<And>x. x \<in> ball 0 r \<Longrightarrow>
```
```  1810               ((\<lambda>z. f z - deriv f 0 * z) has_field_derivative deriv f x - deriv f 0)
```
```  1811                (at x within ball 0 r)"
```
```  1812         by (rule derivative_eq_intros holomorphic_derivI holf' | simp)+
```
```  1813       have 2: "closed_segment 0 z \<subseteq> ball 0 r"
```
```  1814         by (metis \<open>0 < r\<close> convex_ball convex_contains_segment dist_self mem_ball mem_ball_0 that)
```
```  1815       have 3: "(\<lambda>t. (norm z)\<^sup>2 * t / (r - norm z) * C) integrable_on {0..1}"
```
```  1816         apply (rule integrable_on_cmult_right [where 'b=real, simplified])
```
```  1817         apply (rule integrable_on_cdivide [where 'b=real, simplified])
```
```  1818         apply (rule integrable_on_cmult_left [where 'b=real, simplified])
```
```  1819         apply (rule ident_integrable_on)
```
```  1820         done
```
```  1821       have 4: "norm (deriv f (x *\<^sub>R z) - deriv f 0) * norm z \<le> norm z * norm z * x * C / (r - norm z)"
```
```  1822               if x: "0 \<le> x" "x \<le> 1" for x
```
```  1823       proof -
```
```  1824         have [simp]: "x * norm z < r"
```
```  1825           using r x by (meson le_less_trans mult_le_cancel_right2 norm_not_less_zero)
```
```  1826         have "norm (deriv f (x *\<^sub>R z) - deriv f 0) \<le> norm (x *\<^sub>R z) / (r - norm (x *\<^sub>R z)) * C"
```
```  1827           apply (rule Le1) using r x \<open>0 < r\<close> by simp
```
```  1828         also have "... \<le> norm (x *\<^sub>R z) / (r - norm z) * C"
```
```  1829           using r x \<open>0 < r\<close>
```
```  1830           apply (simp add: divide_simps)
```
```  1831           by (simp add: \<open>0 < C\<close> mult.assoc mult_left_le_one_le ordered_comm_semiring_class.comm_mult_left_mono)
```
```  1832         finally have "norm (deriv f (x *\<^sub>R z) - deriv f 0) * norm z \<le> norm (x *\<^sub>R z)  / (r - norm z) * C * norm z"
```
```  1833           by (rule mult_right_mono) simp
```
```  1834         with x show ?thesis by (simp add: algebra_simps)
```
```  1835       qed
```
```  1836       have le_norm: "abc \<le> norm d - e \<Longrightarrow> norm(f - d) \<le> e \<Longrightarrow> abc \<le> norm f" for abc d e and f::complex
```
```  1837         by (metis add_diff_cancel_left' add_diff_eq diff_left_mono norm_diff_ineq order_trans)
```
```  1838       have "norm (integral {0..1} (\<lambda>x. (deriv f (x *\<^sub>R z) - deriv f 0) * z))
```
```  1839             \<le> integral {0..1} (\<lambda>t. (norm z)\<^sup>2 * t / (r - norm z) * C)"
```
```  1840         apply (rule integral_norm_bound_integral)
```
```  1841         using contour_integral_primitive [OF 1, of "linepath 0 z"] 2
```
```  1842         apply (simp add: has_contour_integral_linepath has_integral_integrable_integral)
```
```  1843         apply (rule 3)
```
```  1844         apply (simp add: norm_mult power2_eq_square 4)
```
```  1845         done
```
```  1846       then have int_le: "norm (f z - deriv f 0 * z) \<le> (norm z)\<^sup>2 * norm(deriv f 0) / ((r - norm z))"
```
```  1847         using contour_integral_primitive [OF 1, of "linepath 0 z"] 2
```
```  1848         apply (simp add: has_contour_integral_linepath has_integral_integrable_integral C_def)
```
```  1849         done
```
```  1850       show ?thesis
```
```  1851         apply (rule le_norm [OF _ int_le])
```
```  1852         using \<open>norm z < r\<close>
```
```  1853         apply (simp add: power2_eq_square divide_simps C_def norm_mult)
```
```  1854         proof -
```
```  1855           have "norm z * (norm (deriv f 0) * (r - norm z - norm z)) \<le> norm z * (norm (deriv f 0) * (r - norm z) - norm (deriv f 0) * norm z)"
```
```  1856             by (simp add: linordered_field_class.sign_simps(38))
```
```  1857           then show "(norm z * (r - norm z) - norm z * norm z) * norm (deriv f 0) \<le> norm (deriv f 0) * norm z * (r - norm z) - norm z * norm z * norm (deriv f 0)"
```
```  1858             by (simp add: linordered_field_class.sign_simps(38) mult.commute mult.left_commute)
```
```  1859         qed
```
```  1860     qed
```
```  1861     have sq201 [simp]: "0 < (1 - sqrt 2 / 2)" "(1 - sqrt 2 / 2)  < 1"
```
```  1862       by (auto simp:  sqrt2_less_2)
```
```  1863     have 1: "continuous_on (closure (ball 0 ((1 - sqrt 2 / 2) * r))) f"
```
```  1864       apply (rule continuous_on_subset [OF holomorphic_on_imp_continuous_on [OF holf]])
```
```  1865       apply (subst closure_ball)
```
```  1866       using \<open>0 < r\<close> mult_pos_pos sq201
```
```  1867       apply (auto simp: cball_subset_cball_iff)
```
```  1868       done
```
```  1869     have 2: "open (f ` interior (ball 0 ((1 - sqrt 2 / 2) * r)))"
```
```  1870       apply (rule open_mapping_thm [OF holf' open_ball connected_ball], force)
```
```  1871       using \<open>0 < r\<close> mult_pos_pos sq201 apply (simp add: ball_subset_ball_iff)
```
```  1872       using False \<open>0 < r\<close> centre_in_ball holf' holomorphic_nonconstant by blast
```
```  1873     have "ball 0 ((3 - 2 * sqrt 2) * r * norm (deriv f 0)) =
```
```  1874           ball (f 0) ((3 - 2 * sqrt 2) * r * norm (deriv f 0))"
```
```  1875       by simp
```
```  1876     also have "...  \<subseteq> f ` ball 0 ((1 - sqrt 2 / 2) * r)"
```
```  1877     proof -
```
```  1878       have 3: "(3 - 2 * sqrt 2) * r * norm (deriv f 0) \<le> norm (f z)"
```
```  1879            if "norm z = (1 - sqrt 2 / 2) * r" for z
```
```  1880         apply (rule order_trans [OF _ *])
```
```  1881         using  \<open>0 < r\<close>
```
```  1882         apply (simp_all add: field_simps  power2_eq_square that)
```
```  1883         apply (simp add: mult.assoc [symmetric])
```
```  1884         done
```
```  1885       show ?thesis
```
```  1886         apply (rule ball_subset_open_map_image [OF 1 2 _ bounded_ball])
```
```  1887         using \<open>0 < r\<close> sq201 3 apply simp_all
```
```  1888         using C_def \<open>0 < C\<close> sq3 apply force
```
```  1889         done
```
```  1890      qed
```
```  1891     also have "...  \<subseteq> f ` ball 0 r"
```
```  1892       apply (rule image_subsetI [OF imageI], simp)
```
```  1893       apply (erule less_le_trans)
```
```  1894       using \<open>0 < r\<close> apply (auto simp: field_simps)
```
```  1895       done
```
```  1896     finally show ?thesis .
```
```  1897   qed
```
```  1898 qed
```
```  1899
```
```  1900 lemma Bloch_lemma:
```
```  1901   assumes holf: "f holomorphic_on cball a r" and "0 < r"
```
```  1902       and le: "\<And>z. z \<in> ball a r \<Longrightarrow> norm(deriv f z) \<le> 2 * norm(deriv f a)"
```
```  1903     shows "ball (f a) ((3 - 2 * sqrt 2) * r * norm(deriv f a)) \<subseteq> f ` ball a r"
```
```  1904 proof -
```
```  1905   have fz: "(\<lambda>z. f (a + z)) = f o (\<lambda>z. (a + z))"
```
```  1906     by (simp add: o_def)
```
```  1907   have hol0: "(\<lambda>z. f (a + z)) holomorphic_on cball 0 r"
```
```  1908     unfolding fz by (intro holomorphic_intros holf holomorphic_on_compose | simp)+
```
```  1909   then have [simp]: "\<And>x. norm x < r \<Longrightarrow> (\<lambda>z. f (a + z)) field_differentiable at x"
```
```  1910     by (metis Topology_Euclidean_Space.open_ball at_within_open ball_subset_cball diff_0 dist_norm holomorphic_on_def holomorphic_on_subset mem_ball norm_minus_cancel)
```
```  1911   have [simp]: "\<And>z. norm z < r \<Longrightarrow> f field_differentiable at (a + z)"
```
```  1912     by (metis holf open_ball add_diff_cancel_left' dist_complex_def holomorphic_on_imp_differentiable_at holomorphic_on_subset interior_cball interior_subset mem_ball norm_minus_commute)
```
```  1913   then have [simp]: "f field_differentiable at a"
```
```  1914     by (metis add.comm_neutral \<open>0 < r\<close> norm_eq_zero)
```
```  1915   have hol1: "(\<lambda>z. f (a + z) - f a) holomorphic_on cball 0 r"
```
```  1916     by (intro holomorphic_intros hol0)
```
```  1917   then have "ball 0 ((3 - 2 * sqrt 2) * r * norm (deriv (\<lambda>z. f (a + z) - f a) 0))
```
```  1918              \<subseteq> (\<lambda>z. f (a + z) - f a) ` ball 0 r"
```
```  1919     apply (rule Bloch_lemma_0)
```
```  1920     apply (simp_all add: \<open>0 < r\<close>)
```
```  1921     apply (simp add: fz complex_derivative_chain)
```
```  1922     apply (simp add: dist_norm le)
```
```  1923     done
```
```  1924   then show ?thesis
```
```  1925     apply clarify
```
```  1926     apply (drule_tac c="x - f a" in subsetD)
```
```  1927      apply (force simp: fz \<open>0 < r\<close> dist_norm complex_derivative_chain field_differentiable_compose)+
```
```  1928     done
```
```  1929 qed
```
```  1930
```
```  1931 proposition Bloch_unit:
```
```  1932   assumes holf: "f holomorphic_on ball a 1" and [simp]: "deriv f a = 1"
```
```  1933   obtains b r where "1/12 < r" "ball b r \<subseteq> f ` (ball a 1)"
```
```  1934 proof -
```
```  1935   define r :: real where "r = 249/256"
```
```  1936   have "0 < r" "r < 1" by (auto simp: r_def)
```
```  1937   define g where "g z = deriv f z * of_real(r - norm(z - a))" for z
```
```  1938   have "deriv f holomorphic_on ball a 1"
```
```  1939     by (rule holomorphic_deriv [OF holf open_ball])
```
```  1940   then have "continuous_on (ball a 1) (deriv f)"
```
```  1941     using holomorphic_on_imp_continuous_on by blast
```
```  1942   then have "continuous_on (cball a r) (deriv f)"
```
```  1943     by (rule continuous_on_subset) (simp add: cball_subset_ball_iff \<open>r < 1\<close>)
```
```  1944   then have "continuous_on (cball a r) g"
```
```  1945     by (simp add: g_def continuous_intros)
```
```  1946   then have 1: "compact (g ` cball a r)"
```
```  1947     by (rule compact_continuous_image [OF _ compact_cball])
```
```  1948   have 2: "g ` cball a r \<noteq> {}"
```
```  1949     using \<open>r > 0\<close> by auto
```
```  1950   obtain p where pr: "p \<in> cball a r"
```
```  1951              and pge: "\<And>y. y \<in> cball a r \<Longrightarrow> norm (g y) \<le> norm (g p)"
```
```  1952     using distance_attains_sup [OF 1 2, of 0] by force
```
```  1953   define t where "t = (r - norm(p - a)) / 2"
```
```  1954   have "norm (p - a) \<noteq> r"
```
```  1955     using pge [of a] \<open>r > 0\<close> by (auto simp: g_def norm_mult)
```
```  1956   then have "norm (p - a) < r" using pr
```
```  1957     by (simp add: norm_minus_commute dist_norm)
```
```  1958   then have "0 < t"
```
```  1959     by (simp add: t_def)
```
```  1960   have cpt: "cball p t \<subseteq> ball a r"
```
```  1961     using \<open>0 < t\<close> by (simp add: cball_subset_ball_iff dist_norm t_def field_simps)
```
```  1962   have gen_le_dfp: "norm (deriv f y) * (r - norm (y - a)) / (r - norm (p - a)) \<le> norm (deriv f p)"
```
```  1963             if "y \<in> cball a r" for y
```
```  1964   proof -
```
```  1965     have [simp]: "norm (y - a) \<le> r"
```
```  1966       using that by (simp add: dist_norm norm_minus_commute)
```
```  1967     have "norm (g y) \<le> norm (g p)"
```
```  1968       using pge [OF that] by simp
```
```  1969     then have "norm (deriv f y) * abs (r - norm (y - a)) \<le> norm (deriv f p) * abs (r - norm (p - a))"
```
```  1970       by (simp only: dist_norm g_def norm_mult norm_of_real)
```
```  1971     with that \<open>norm (p - a) < r\<close> show ?thesis
```
```  1972       by (simp add: dist_norm divide_simps)
```
```  1973   qed
```
```  1974   have le_norm_dfp: "r / (r - norm (p - a)) \<le> norm (deriv f p)"
```
```  1975     using gen_le_dfp [of a] \<open>r > 0\<close> by auto
```
```  1976   have 1: "f holomorphic_on cball p t"
```
```  1977     apply (rule holomorphic_on_subset [OF holf])
```
```  1978     using cpt \<open>r < 1\<close> order_subst1 subset_ball by auto
```
```  1979   have 2: "norm (deriv f z) \<le> 2 * norm (deriv f p)" if "z \<in> ball p t" for z
```
```  1980   proof -
```
```  1981     have z: "z \<in> cball a r"
```
```  1982       by (meson ball_subset_cball subsetD cpt that)
```
```  1983     then have "norm(z - a) < r"
```
```  1984       by (metis ball_subset_cball contra_subsetD cpt dist_norm mem_ball norm_minus_commute that)
```
```  1985     have "norm (deriv f z) * (r - norm (z - a)) / (r - norm (p - a)) \<le> norm (deriv f p)"
```
```  1986       using gen_le_dfp [OF z] by simp
```
```  1987     with \<open>norm (z - a) < r\<close> \<open>norm (p - a) < r\<close>
```
```  1988     have "norm (deriv f z) \<le> (r - norm (p - a)) / (r - norm (z - a)) * norm (deriv f p)"
```
```  1989        by (simp add: field_simps)
```
```  1990     also have "... \<le> 2 * norm (deriv f p)"
```
```  1991       apply (rule mult_right_mono)
```
```  1992       using that \<open>norm (p - a) < r\<close> \<open>norm(z - a) < r\<close>
```
```  1993       apply (simp_all add: field_simps t_def dist_norm [symmetric])
```
```  1994       using dist_triangle3 [of z a p] by linarith
```
```  1995     finally show ?thesis .
```
```  1996   qed
```
```  1997   have sqrt2: "sqrt 2 < 2113/1494"
```
```  1998     by (rule real_less_lsqrt) (auto simp: power2_eq_square)
```
```  1999   then have sq3: "0 < 3 - 2 * sqrt 2" by simp
```
```  2000   have "1 / 12 / ((3 - 2 * sqrt 2) / 2) < r"
```
```  2001     using sq3 sqrt2 by (auto simp: field_simps r_def)
```
```  2002   also have "... \<le> cmod (deriv f p) * (r - cmod (p - a))"
```
```  2003     using \<open>norm (p - a) < r\<close> le_norm_dfp   by (simp add: pos_divide_le_eq)
```
```  2004   finally have "1 / 12 < cmod (deriv f p) * (r - cmod (p - a)) * ((3 - 2 * sqrt 2) / 2)"
```
```  2005     using pos_divide_less_eq half_gt_zero_iff sq3 by blast
```
```  2006   then have **: "1 / 12 < (3 - 2 * sqrt 2) * t * norm (deriv f p)"
```
```  2007     using sq3 by (simp add: mult.commute t_def)
```
```  2008   have "ball (f p) ((3 - 2 * sqrt 2) * t * norm (deriv f p)) \<subseteq> f ` ball p t"
```
```  2009     by (rule Bloch_lemma [OF 1 \<open>0 < t\<close> 2])
```
```  2010   also have "... \<subseteq> f ` ball a 1"
```
```  2011     apply (rule image_mono)
```
```  2012     apply (rule order_trans [OF ball_subset_cball])
```
```  2013     apply (rule order_trans [OF cpt])
```
```  2014     using \<open>0 < t\<close> \<open>r < 1\<close> apply (simp add: ball_subset_ball_iff dist_norm)
```
```  2015     done
```
```  2016   finally have "ball (f p) ((3 - 2 * sqrt 2) * t * norm (deriv f p)) \<subseteq> f ` ball a 1" .
```
```  2017   with ** show ?thesis
```
```  2018     by (rule that)
```
```  2019 qed
```
```  2020
```
```  2021
```
```  2022 theorem Bloch:
```
```  2023   assumes holf: "f holomorphic_on ball a r" and "0 < r"
```
```  2024       and r': "r' \<le> r * norm (deriv f a) / 12"
```
```  2025   obtains b where "ball b r' \<subseteq> f ` (ball a r)"
```
```  2026 proof (cases "deriv f a = 0")
```
```  2027   case True with r' show ?thesis
```
```  2028     using ball_eq_empty that by fastforce
```
```  2029 next
```
```  2030   case False
```
```  2031   define C where "C = deriv f a"
```
```  2032   have "0 < norm C" using False by (simp add: C_def)
```
```  2033   have dfa: "f field_differentiable at a"
```
```  2034     apply (rule holomorphic_on_imp_differentiable_at [OF holf])
```
```  2035     using \<open>0 < r\<close> by auto
```
```  2036   have fo: "(\<lambda>z. f (a + of_real r * z)) = f o (\<lambda>z. (a + of_real r * z))"
```
```  2037     by (simp add: o_def)
```
```  2038   have holf': "f holomorphic_on (\<lambda>z. a + complex_of_real r * z) ` ball 0 1"
```
```  2039     apply (rule holomorphic_on_subset [OF holf])
```
```  2040     using \<open>0 < r\<close> apply (force simp: dist_norm norm_mult)
```
```  2041     done
```
```  2042   have 1: "(\<lambda>z. f (a + r * z) / (C * r)) holomorphic_on ball 0 1"
```
```  2043     apply (rule holomorphic_intros holomorphic_on_compose holf' | simp add: fo)+
```
```  2044     using \<open>0 < r\<close> by (simp add: C_def False)
```
```  2045   have "((\<lambda>z. f (a + of_real r * z) / (C * of_real r)) has_field_derivative
```
```  2046         (deriv f (a + of_real r * z) / C)) (at z)"
```
```  2047        if "norm z < 1" for z
```
```  2048   proof -
```
```  2049     have *: "((\<lambda>x. f (a + of_real r * x)) has_field_derivative
```
```  2050            (deriv f (a + of_real r * z) * of_real r)) (at z)"
```
```  2051       apply (simp add: fo)
```
```  2052       apply (rule DERIV_chain [OF field_differentiable_derivI])
```
```  2053       apply (rule holomorphic_on_imp_differentiable_at [OF holf], simp)
```
```  2054       using \<open>0 < r\<close> apply (simp add: dist_norm norm_mult that)
```
```  2055       apply (rule derivative_eq_intros | simp)+
```
```  2056       done
```
```  2057     show ?thesis
```
```  2058       apply (rule derivative_eq_intros * | simp)+
```
```  2059       using \<open>0 < r\<close> by (auto simp: C_def False)
```
```  2060   qed
```
```  2061   have 2: "deriv (\<lambda>z. f (a + of_real r * z) / (C * of_real r)) 0 = 1"
```
```  2062     apply (subst deriv_cdivide_right)
```
```  2063     apply (simp add: field_differentiable_def fo)
```
```  2064     apply (rule exI)
```
```  2065     apply (rule DERIV_chain [OF field_differentiable_derivI])
```
```  2066     apply (simp add: dfa)
```
```  2067     apply (rule derivative_eq_intros | simp add: C_def False fo)+
```
```  2068     using \<open>0 < r\<close>
```
```  2069     apply (simp add: C_def False fo)
```
```  2070     apply (simp add: derivative_intros dfa complex_derivative_chain)
```
```  2071     done
```
```  2072   have sb1: "op * (C * r) ` (\<lambda>z. f (a + of_real r * z) / (C * r)) ` ball 0 1
```
```  2073              \<subseteq> f ` ball a r"
```
```  2074     using \<open>0 < r\<close> by (auto simp: dist_norm norm_mult C_def False)
```
```  2075   have sb2: "ball (C * r * b) r' \<subseteq> op * (C * r) ` ball b t"
```
```  2076              if "1 / 12 < t" for b t
```
```  2077   proof -
```
```  2078     have *: "r * cmod (deriv f a) / 12 \<le> r * (t * cmod (deriv f a))"
```
```  2079       using that \<open>0 < r\<close> less_eq_real_def mult.commute mult.right_neutral mult_left_mono norm_ge_zero times_divide_eq_right
```
```  2080       by auto
```
```  2081     show ?thesis
```
```  2082       apply clarify
```
```  2083       apply (rule_tac x="x / (C * r)" in image_eqI)
```
```  2084       using \<open>0 < r\<close>
```
```  2085       apply (simp_all add: dist_norm norm_mult norm_divide C_def False field_simps)
```
```  2086       apply (erule less_le_trans)
```
```  2087       apply (rule order_trans [OF r' *])
```
```  2088       done
```
```  2089   qed
```
```  2090   show ?thesis
```
```  2091     apply (rule Bloch_unit [OF 1 2])
```
```  2092     apply (rename_tac t)
```
```  2093     apply (rule_tac b="(C * of_real r) * b" in that)
```
```  2094     apply (drule image_mono [where f = "\<lambda>z. (C * of_real r) * z"])
```
```  2095     using sb1 sb2
```
```  2096     apply force
```
```  2097     done
```
```  2098 qed
```
```  2099
```
```  2100 corollary Bloch_general:
```
```  2101   assumes holf: "f holomorphic_on s" and "a \<in> s"
```
```  2102       and tle: "\<And>z. z \<in> frontier s \<Longrightarrow> t \<le> dist a z"
```
```  2103       and rle: "r \<le> t * norm(deriv f a) / 12"
```
```  2104   obtains b where "ball b r \<subseteq> f ` s"
```
```  2105 proof -
```
```  2106   consider "r \<le> 0" | "0 < t * norm(deriv f a) / 12" using rle by force
```
```  2107   then show ?thesis
```
```  2108   proof cases
```
```  2109     case 1 then show ?thesis
```
```  2110       by (simp add: Topology_Euclidean_Space.ball_empty that)
```
```  2111   next
```
```  2112     case 2
```
```  2113     show ?thesis
```
```  2114     proof (cases "deriv f a = 0")
```
```  2115       case True then show ?thesis
```
```  2116         using rle by (simp add: Topology_Euclidean_Space.ball_empty that)
```
```  2117     next
```
```  2118       case False
```
```  2119       then have "t > 0"
```
```  2120         using 2 by (force simp: zero_less_mult_iff)
```
```  2121       have "~ ball a t \<subseteq> s \<Longrightarrow> ball a t \<inter> frontier s \<noteq> {}"
```
```  2122         apply (rule connected_Int_frontier [of "ball a t" s], simp_all)
```
```  2123         using \<open>0 < t\<close> \<open>a \<in> s\<close> centre_in_ball apply blast
```
```  2124         done
```
```  2125       with tle have *: "ball a t \<subseteq> s" by fastforce
```
```  2126       then have 1: "f holomorphic_on ball a t"
```
```  2127         using holf using holomorphic_on_subset by blast
```
```  2128       show ?thesis
```
```  2129         apply (rule Bloch [OF 1 \<open>t > 0\<close> rle])
```
```  2130         apply (rule_tac b=b in that)
```
```  2131         using * apply force
```
```  2132         done
```
```  2133     qed
```
```  2134   qed
```
```  2135 qed
```
```  2136
```
```  2137 subsection \<open>Foundations of Cauchy's residue theorem\<close>
```
```  2138
```
```  2139 text\<open>Wenda Li and LC Paulson (2016). A Formal Proof of Cauchy's Residue Theorem.
```
```  2140     Interactive Theorem Proving\<close>
```
```  2141
```
```  2142 definition residue :: "(complex \<Rightarrow> complex) \<Rightarrow> complex \<Rightarrow> complex" where
```
```  2143   "residue f z = (SOME int. \<exists>e>0. \<forall>\<epsilon>>0. \<epsilon><e
```
```  2144     \<longrightarrow> (f has_contour_integral 2*pi* \<i> *int) (circlepath z \<epsilon>))"
```
```  2145
```
```  2146 lemma contour_integral_circlepath_eq:
```
```  2147   assumes "open s" and f_holo:"f holomorphic_on (s-{z})" and "0<e1" "e1\<le>e2"
```
```  2148     and e2_cball:"cball z e2 \<subseteq> s"
```
```  2149   shows
```
```  2150     "f contour_integrable_on circlepath z e1"
```
```  2151     "f contour_integrable_on circlepath z e2"
```
```  2152     "contour_integral (circlepath z e2) f = contour_integral (circlepath z e1) f"
```
```  2153 proof -
```
```  2154   define l where "l \<equiv> linepath (z+e2) (z+e1)"
```
```  2155   have [simp]:"valid_path l" "pathstart l=z+e2" "pathfinish l=z+e1" unfolding l_def by auto
```
```  2156   have "e2>0" using \<open>e1>0\<close> \<open>e1\<le>e2\<close> by auto
```
```  2157   have zl_img:"z\<notin>path_image l"
```
```  2158     proof
```
```  2159       assume "z \<in> path_image l"
```
```  2160       then have "e2 \<le> cmod (e2 - e1)"
```
```  2161         using segment_furthest_le[of z "z+e2" "z+e1" "z+e2",simplified] \<open>e1>0\<close> \<open>e2>0\<close> unfolding l_def
```
```  2162         by (auto simp add:closed_segment_commute)
```
```  2163       thus False using \<open>e2>0\<close> \<open>e1>0\<close> \<open>e1\<le>e2\<close>
```
```  2164         apply (subst (asm) norm_of_real)
```
```  2165         by auto
```
```  2166     qed
```
```  2167   define g where "g \<equiv> circlepath z e2 +++ l +++ reversepath (circlepath z e1) +++ reversepath l"
```
```  2168   show [simp]: "f contour_integrable_on circlepath z e2" "f contour_integrable_on (circlepath z e1)"
```
```  2169     proof -
```
```  2170       show "f contour_integrable_on circlepath z e2"
```
```  2171         apply (intro contour_integrable_continuous_circlepath[OF
```
```  2172                 continuous_on_subset[OF holomorphic_on_imp_continuous_on[OF f_holo]]])
```
```  2173         using \<open>e2>0\<close> e2_cball by auto
```
```  2174       show "f contour_integrable_on (circlepath z e1)"
```
```  2175         apply (intro contour_integrable_continuous_circlepath[OF
```
```  2176                       continuous_on_subset[OF holomorphic_on_imp_continuous_on[OF f_holo]]])
```
```  2177         using \<open>e1>0\<close> \<open>e1\<le>e2\<close> e2_cball by auto
```
```  2178     qed
```
```  2179   have [simp]:"f contour_integrable_on l"
```
```  2180     proof -
```
```  2181       have "closed_segment (z + e2) (z + e1) \<subseteq> cball z e2" using \<open>e2>0\<close> \<open>e1>0\<close> \<open>e1\<le>e2\<close>
```
```  2182         by (intro closed_segment_subset,auto simp add:dist_norm)
```
```  2183       hence "closed_segment (z + e2) (z + e1) \<subseteq> s - {z}" using zl_img e2_cball unfolding l_def
```
```  2184         by auto
```
```  2185       then show "f contour_integrable_on l" unfolding l_def
```
```  2186         apply (intro contour_integrable_continuous_linepath[OF
```
```  2187                       continuous_on_subset[OF holomorphic_on_imp_continuous_on[OF f_holo]]])
```
```  2188         by auto
```
```  2189     qed
```
```  2190   let ?ig="\<lambda>g. contour_integral g f"
```
```  2191   have "(f has_contour_integral 0) g"
```
```  2192     proof (rule Cauchy_theorem_global[OF _ f_holo])
```
```  2193       show "open (s - {z})" using \<open>open s\<close> by auto
```
```  2194       show "valid_path g" unfolding g_def l_def by auto
```
```  2195       show "pathfinish g = pathstart g" unfolding g_def l_def by auto
```
```  2196     next
```
```  2197       have path_img:"path_image g \<subseteq> cball z e2"
```
```  2198         proof -
```
```  2199           have "closed_segment (z + e2) (z + e1) \<subseteq> cball z e2" using \<open>e2>0\<close> \<open>e1>0\<close> \<open>e1\<le>e2\<close>
```
```  2200             by (intro closed_segment_subset,auto simp add:dist_norm)
```
```  2201           moreover have "sphere z \<bar>e1\<bar> \<subseteq> cball z e2" using \<open>e2>0\<close> \<open>e1\<le>e2\<close> \<open>e1>0\<close> by auto
```
```  2202           ultimately show ?thesis unfolding g_def l_def using \<open>e2>0\<close>
```
```  2203             by (simp add: path_image_join closed_segment_commute)
```
```  2204         qed
```
```  2205       show "path_image g \<subseteq> s - {z}"
```
```  2206         proof -
```
```  2207           have "z\<notin>path_image g" using zl_img
```
```  2208             unfolding g_def l_def by (auto simp add: path_image_join closed_segment_commute)
```
```  2209           moreover note \<open>cball z e2 \<subseteq> s\<close> and path_img
```
```  2210           ultimately show ?thesis by auto
```
```  2211         qed
```
```  2212       show "winding_number g w = 0" when"w \<notin> s - {z}" for w
```
```  2213         proof -
```
```  2214           have "winding_number g w = 0" when "w\<notin>s" using that e2_cball
```
```  2215             apply (intro winding_number_zero_outside[OF _ _ _ _ path_img])
```
```  2216             by (auto simp add:g_def l_def)
```
```  2217           moreover have "winding_number g z=0"
```
```  2218             proof -
```
```  2219               let ?Wz="\<lambda>g. winding_number g z"
```
```  2220               have "?Wz g = ?Wz (circlepath z e2) + ?Wz l + ?Wz (reversepath (circlepath z e1))
```
```  2221                   + ?Wz (reversepath l)"
```
```  2222                 using \<open>e2>0\<close> \<open>e1>0\<close> zl_img unfolding g_def l_def
```
```  2223                 by (subst winding_number_join,auto simp add:path_image_join closed_segment_commute)+
```
```  2224               also have "... = ?Wz (circlepath z e2) + ?Wz (reversepath (circlepath z e1))"
```
```  2225                 using zl_img
```
```  2226                 apply (subst (2) winding_number_reversepath)
```
```  2227                 by (auto simp add:l_def closed_segment_commute)
```
```  2228               also have "... = 0"
```
```  2229                 proof -
```
```  2230                   have "?Wz (circlepath z e2) = 1" using \<open>e2>0\<close>
```
```  2231                     by (auto intro: winding_number_circlepath_centre)
```
```  2232                   moreover have "?Wz (reversepath (circlepath z e1)) = -1" using \<open>e1>0\<close>
```
```  2233                     apply (subst winding_number_reversepath)
```
```  2234                     by (auto intro: winding_number_circlepath_centre)
```
```  2235                   ultimately show ?thesis by auto
```
```  2236                 qed
```
```  2237               finally show ?thesis .
```
```  2238             qed
```
```  2239           ultimately show ?thesis using that by auto
```
```  2240         qed
```
```  2241     qed
```
```  2242   then have "0 = ?ig g" using contour_integral_unique by simp
```
```  2243   also have "... = ?ig (circlepath z e2) + ?ig l + ?ig (reversepath (circlepath z e1))
```
```  2244       + ?ig (reversepath l)"
```
```  2245     unfolding g_def
```
```  2246     by (auto simp add:contour_integrable_reversepath_eq)
```
```  2247   also have "... = ?ig (circlepath z e2)  - ?ig (circlepath z e1)"
```
```  2248     by (auto simp add:contour_integral_reversepath)
```
```  2249   finally show "contour_integral (circlepath z e2) f = contour_integral (circlepath z e1) f"
```
```  2250     by simp
```
```  2251 qed
```
```  2252
```
```  2253 lemma base_residue:
```
```  2254   assumes "open s" "z\<in>s" "r>0" and f_holo:"f holomorphic_on (s - {z})"
```
```  2255     and r_cball:"cball z r \<subseteq> s"
```
```  2256   shows "(f has_contour_integral 2 * pi * \<i> * (residue f z)) (circlepath z r)"
```
```  2257 proof -
```
```  2258   obtain e where "e>0" and e_cball:"cball z e \<subseteq> s"
```
```  2259     using open_contains_cball[of s] \<open>open s\<close> \<open>z\<in>s\<close> by auto
```
```  2260   define c where "c \<equiv> 2 * pi * \<i>"
```
```  2261   define i where "i \<equiv> contour_integral (circlepath z e) f / c"
```
```  2262   have "(f has_contour_integral c*i) (circlepath z \<epsilon>)" when "\<epsilon>>0" "\<epsilon><e" for \<epsilon>
```
```  2263     proof -
```
```  2264       have "contour_integral (circlepath z e) f = contour_integral (circlepath z \<epsilon>) f"
```
```  2265           "f contour_integrable_on circlepath z \<epsilon>"
```
```  2266           "f contour_integrable_on circlepath z e"
```
```  2267         using \<open>\<epsilon><e\<close>
```
```  2268         by (intro contour_integral_circlepath_eq[OF \<open>open s\<close> f_holo \<open>\<epsilon>>0\<close> _ e_cball],auto)+
```
```  2269       then show ?thesis unfolding i_def c_def
```
```  2270         by (auto intro:has_contour_integral_integral)
```
```  2271     qed
```
```  2272   then have "\<exists>e>0. \<forall>\<epsilon>>0. \<epsilon><e \<longrightarrow> (f has_contour_integral c * (residue f z)) (circlepath z \<epsilon>)"
```
```  2273     unfolding residue_def c_def
```
```  2274     apply (rule_tac someI[of _ i],intro  exI[where x=e])
```
```  2275     by (auto simp add:\<open>e>0\<close> c_def)
```
```  2276   then obtain e' where "e'>0"
```
```  2277       and e'_def:"\<forall>\<epsilon>>0. \<epsilon><e' \<longrightarrow> (f has_contour_integral c * (residue f z)) (circlepath z \<epsilon>)"
```
```  2278     by auto
```
```  2279   let ?int="\<lambda>e. contour_integral (circlepath z e) f"
```
```  2280   def \<epsilon>\<equiv>"Min {r,e'} / 2"
```
```  2281   have "\<epsilon>>0" "\<epsilon>\<le>r" "\<epsilon><e'" using \<open>r>0\<close> \<open>e'>0\<close> unfolding \<epsilon>_def by auto
```
```  2282   have "(f has_contour_integral c * (residue f z)) (circlepath z \<epsilon>)"
```
```  2283     using e'_def[rule_format,OF \<open>\<epsilon>>0\<close> \<open>\<epsilon><e'\<close>] .
```
```  2284   then show ?thesis unfolding c_def
```
```  2285     using contour_integral_circlepath_eq[OF \<open>open s\<close> f_holo \<open>\<epsilon>>0\<close> \<open>\<epsilon>\<le>r\<close> r_cball]
```
```  2286     by (auto elim: has_contour_integral_eqpath[of _ _ "circlepath z \<epsilon>" "circlepath z r"])
```
```  2287 qed
```
```  2288
```
```  2289
```
```  2290 lemma residue_holo:
```
```  2291   assumes "open s" "z \<in> s" and f_holo: "f holomorphic_on s"
```
```  2292   shows "residue f z = 0"
```
```  2293 proof -
```
```  2294   define c where "c \<equiv> 2 * pi * \<i>"
```
```  2295   obtain e where "e>0" and e_cball:"cball z e \<subseteq> s" using \<open>open s\<close> \<open>z\<in>s\<close>
```
```  2296     using open_contains_cball_eq by blast
```
```  2297   have "(f has_contour_integral c*residue f z) (circlepath z e)"
```
```  2298     using f_holo
```
```  2299     by (auto intro: base_residue[OF \<open>open s\<close> \<open>z\<in>s\<close> \<open>e>0\<close> _ e_cball,folded c_def])
```
```  2300   moreover have "(f has_contour_integral 0) (circlepath z e)"
```
```  2301     using f_holo e_cball \<open>e>0\<close>
```
```  2302     by (auto intro: Cauchy_theorem_convex_simple[of _ "cball z e"])
```
```  2303   ultimately have "c*residue f z =0"
```
```  2304     using has_contour_integral_unique by blast
```
```  2305   thus ?thesis unfolding c_def  by auto
```
```  2306 qed
```
```  2307
```
```  2308
```
```  2309 lemma residue_const:"residue (\<lambda>_. c) z = 0"
```
```  2310   by (intro residue_holo[of "UNIV::complex set"],auto intro:holomorphic_intros)
```
```  2311
```
```  2312
```
```  2313 lemma residue_add:
```
```  2314   assumes "open s" "z \<in> s" and f_holo: "f holomorphic_on s - {z}"
```
```  2315       and g_holo:"g holomorphic_on s - {z}"
```
```  2316   shows "residue (\<lambda>z. f z + g z) z= residue f z + residue g z"
```
```  2317 proof -
```
```  2318   define c where "c \<equiv> 2 * pi * \<i>"
```
```  2319   define fg where "fg \<equiv> (\<lambda>z. f z+g z)"
```
```  2320   obtain e where "e>0" and e_cball:"cball z e \<subseteq> s" using \<open>open s\<close> \<open>z\<in>s\<close>
```
```  2321     using open_contains_cball_eq by blast
```
```  2322   have "(fg has_contour_integral c * residue fg z) (circlepath z e)"
```
```  2323     unfolding fg_def using f_holo g_holo
```
```  2324     apply (intro base_residue[OF \<open>open s\<close> \<open>z\<in>s\<close> \<open>e>0\<close> _ e_cball,folded c_def])
```
```  2325     by (auto intro:holomorphic_intros)
```
```  2326   moreover have "(fg has_contour_integral c*residue f z + c* residue g z) (circlepath z e)"
```
```  2327     unfolding fg_def using f_holo g_holo
```
```  2328     by (auto intro: has_contour_integral_add base_residue[OF \<open>open s\<close> \<open>z\<in>s\<close> \<open>e>0\<close> _ e_cball,folded c_def])
```
```  2329   ultimately have "c*(residue f z + residue g z) = c * residue fg z"
```
```  2330     using has_contour_integral_unique by (auto simp add:distrib_left)
```
```  2331   thus ?thesis unfolding fg_def
```
```  2332     by (auto simp add:c_def)
```
```  2333 qed
```
```  2334
```
```  2335
```
```  2336 lemma residue_lmul:
```
```  2337   assumes "open s" "z \<in> s" and f_holo: "f holomorphic_on s - {z}"
```
```  2338   shows "residue (\<lambda>z. c * (f z)) z= c * residue f z"
```
```  2339 proof (cases "c=0")
```
```  2340   case True
```
```  2341   thus ?thesis using residue_const by auto
```
```  2342 next
```
```  2343   case False
```
```  2344   def c'\<equiv>"2 * pi * \<i>"
```
```  2345   def f'\<equiv>"(\<lambda>z. c * (f z))"
```
```  2346   obtain e where "e>0" and e_cball:"cball z e \<subseteq> s" using \<open>open s\<close> \<open>z\<in>s\<close>
```
```  2347     using open_contains_cball_eq by blast
```
```  2348   have "(f' has_contour_integral c' * residue f' z) (circlepath z e)"
```
```  2349     unfolding f'_def using f_holo
```
```  2350     apply (intro base_residue[OF \<open>open s\<close> \<open>z\<in>s\<close> \<open>e>0\<close> _ e_cball,folded c'_def])
```
```  2351     by (auto intro:holomorphic_intros)
```
```  2352   moreover have "(f' has_contour_integral c * (c' * residue f z)) (circlepath z e)"
```
```  2353     unfolding f'_def using f_holo
```
```  2354     by (auto intro: has_contour_integral_lmul
```
```  2355       base_residue[OF \<open>open s\<close> \<open>z\<in>s\<close> \<open>e>0\<close> _ e_cball,folded c'_def])
```
```  2356   ultimately have "c' * residue f' z  = c * (c' * residue f z)"
```
```  2357     using has_contour_integral_unique by auto
```
```  2358   thus ?thesis unfolding f'_def c'_def using False
```
```  2359     by (auto simp add:field_simps)
```
```  2360 qed
```
```  2361
```
```  2362 lemma residue_rmul:
```
```  2363   assumes "open s" "z \<in> s" and f_holo: "f holomorphic_on s - {z}"
```
```  2364   shows "residue (\<lambda>z. (f z) * c) z= residue f z * c"
```
```  2365 using residue_lmul[OF assms,of c] by (auto simp add:algebra_simps)
```
```  2366
```
```  2367 lemma residue_div:
```
```  2368   assumes "open s" "z \<in> s" and f_holo: "f holomorphic_on s - {z}"
```
```  2369   shows "residue (\<lambda>z. (f z) / c) z= residue f z / c "
```
```  2370 using residue_lmul[OF assms,of "1/c"] by (auto simp add:algebra_simps)
```
```  2371
```
```  2372 lemma residue_neg:
```
```  2373   assumes "open s" "z \<in> s" and f_holo: "f holomorphic_on s - {z}"
```
```  2374   shows "residue (\<lambda>z. - (f z)) z= - residue f z"
```
```  2375 using residue_lmul[OF assms,of "-1"] by auto
```
```  2376
```
```  2377 lemma residue_diff:
```
```  2378   assumes "open s" "z \<in> s" and f_holo: "f holomorphic_on s - {z}"
```
```  2379       and g_holo:"g holomorphic_on s - {z}"
```
```  2380   shows "residue (\<lambda>z. f z - g z) z= residue f z - residue g z"
```
```  2381 using residue_add[OF assms(1,2,3),of "\<lambda>z. - g z"] residue_neg[OF assms(1,2,4)]
```
```  2382 by (auto intro:holomorphic_intros g_holo)
```
```  2383
```
```  2384 lemma residue_simple:
```
```  2385   assumes "open s" "z\<in>s" and f_holo:"f holomorphic_on s"
```
```  2386   shows "residue (\<lambda>w. f w / (w - z)) z = f z"
```
```  2387 proof -
```
```  2388   define c where "c \<equiv> 2 * pi * \<i>"
```
```  2389   def f'\<equiv>"\<lambda>w. f w / (w - z)"
```
```  2390   obtain e where "e>0" and e_cball:"cball z e \<subseteq> s" using \<open>open s\<close> \<open>z\<in>s\<close>
```
```  2391     using open_contains_cball_eq by blast
```
```  2392   have "(f' has_contour_integral c * f z) (circlepath z e)"
```
```  2393     unfolding f'_def c_def using \<open>e>0\<close> f_holo e_cball
```
```  2394     by (auto intro!: Cauchy_integral_circlepath_simple holomorphic_intros)
```
```  2395   moreover have "(f' has_contour_integral c * residue f' z) (circlepath z e)"
```
```  2396     unfolding f'_def using f_holo
```
```  2397     apply (intro base_residue[OF \<open>open s\<close> \<open>z\<in>s\<close> \<open>e>0\<close> _ e_cball,folded c_def])
```
```  2398     by (auto intro!:holomorphic_intros)
```
```  2399   ultimately have "c * f z = c * residue f' z"
```
```  2400     using has_contour_integral_unique by blast
```
```  2401   thus ?thesis unfolding c_def f'_def  by auto
```
```  2402 qed
```
```  2403
```
```  2404
```
```  2405
```
```  2406 subsubsection \<open>Cauchy's residue theorem\<close>
```
```  2407
```
```  2408 lemma get_integrable_path:
```
```  2409   assumes "open s" "connected (s-pts)" "finite pts" "f holomorphic_on (s-pts) " "a\<in>s-pts" "b\<in>s-pts"
```
```  2410   obtains g where "valid_path g" "pathstart g = a" "pathfinish g = b"
```
```  2411     "path_image g \<subseteq> s-pts" "f contour_integrable_on g" using assms
```
```  2412 proof (induct arbitrary:s thesis a rule:finite_induct[OF \<open>finite pts\<close>])
```
```  2413   case 1
```
```  2414   obtain g where "valid_path g" "path_image g \<subseteq> s" "pathstart g = a" "pathfinish g = b"
```
```  2415     using connected_open_polynomial_connected[OF \<open>open s\<close>,of a b ] \<open>connected (s - {})\<close>
```
```  2416       valid_path_polynomial_function "1.prems"(6) "1.prems"(7) by auto
```
```  2417   moreover have "f contour_integrable_on g"
```
```  2418     using contour_integrable_holomorphic_simple[OF _ \<open>open s\<close> \<open>valid_path g\<close> \<open>path_image g \<subseteq> s\<close>,of f]
```
```  2419       \<open>f holomorphic_on s - {}\<close>
```
```  2420     by auto
```
```  2421   ultimately show ?case using "1"(1)[of g] by auto
```
```  2422 next
```
```  2423   case idt:(2 p pts)
```
```  2424   obtain e where "e>0" and e:"\<forall>w\<in>ball a e. w \<in> s \<and> (w \<noteq> a \<longrightarrow> w \<notin> insert p pts)"
```
```  2425     using finite_ball_avoid[OF \<open>open s\<close> \<open>finite (insert p pts)\<close>, of a]
```
```  2426       \<open>a \<in> s - insert p pts\<close>
```
```  2427     by auto
```
```  2428   define a' where "a' \<equiv> a+e/2"
```
```  2429   have "a'\<in>s-{p} -pts"  using e[rule_format,of "a+e/2"] \<open>e>0\<close>
```
```  2430     by (auto simp add:dist_complex_def a'_def)
```
```  2431   then obtain g' where g'[simp]:"valid_path g'" "pathstart g' = a'" "pathfinish g' = b"
```
```  2432     "path_image g' \<subseteq> s - {p} - pts" "f contour_integrable_on g'"
```
```  2433     using idt.hyps(3)[of a' "s-{p}"] idt.prems idt.hyps(1)
```
```  2434     by (metis Diff_insert2 open_delete)
```
```  2435   define g where "g \<equiv> linepath a a' +++ g'"
```
```  2436   have "valid_path g" unfolding g_def by (auto intro: valid_path_join)
```
```  2437   moreover have "pathstart g = a" and  "pathfinish g = b" unfolding g_def by auto
```
```  2438   moreover have "path_image g \<subseteq> s - insert p pts" unfolding g_def
```
```  2439     proof (rule subset_path_image_join)
```
```  2440       have "closed_segment a a' \<subseteq> ball a e" using \<open>e>0\<close>
```
```  2441         by (auto dest!:segment_bound1 simp:a'_def dist_complex_def norm_minus_commute)
```
```  2442       then show "path_image (linepath a a') \<subseteq> s - insert p pts" using e idt(9)
```
```  2443         by auto
```
```  2444     next
```
```  2445       show "path_image g' \<subseteq> s - insert p pts" using g'(4) by blast
```
```  2446     qed
```
```  2447   moreover have "f contour_integrable_on g"
```
```  2448     proof -
```
```  2449       have "closed_segment a a' \<subseteq> ball a e" using \<open>e>0\<close>
```
```  2450         by (auto dest!:segment_bound1 simp:a'_def dist_complex_def norm_minus_commute)
```
```  2451       then have "continuous_on (closed_segment a a') f"
```
```  2452         using e idt.prems(6) holomorphic_on_imp_continuous_on[OF idt.prems(5)]
```
```  2453         apply (elim continuous_on_subset)
```
```  2454         by auto
```
```  2455       then have "f contour_integrable_on linepath a a'"
```
```  2456         using contour_integrable_continuous_linepath by auto
```
```  2457       then show ?thesis unfolding g_def
```
```  2458         apply (rule contour_integrable_joinI)
```
```  2459         by (auto simp add: \<open>e>0\<close>)
```
```  2460     qed
```
```  2461   ultimately show ?case using idt.prems(1)[of g] by auto
```
```  2462 qed
```
```  2463
```
```  2464 lemma Cauchy_theorem_aux:
```
```  2465   assumes "open s" "connected (s-pts)" "finite pts" "pts \<subseteq> s" "f holomorphic_on s-pts"
```
```  2466           "valid_path g" "pathfinish g = pathstart g" "path_image g \<subseteq> s-pts"
```
```  2467           "\<forall>z. (z \<notin> s) \<longrightarrow> winding_number g z  = 0"
```
```  2468           "\<forall>p\<in>s. h p>0 \<and> (\<forall>w\<in>cball p (h p). w\<in>s \<and> (w\<noteq>p \<longrightarrow> w \<notin> pts))"
```
```  2469   shows "contour_integral g f = (\<Sum>p\<in>pts. winding_number g p * contour_integral (circlepath p (h p)) f)"
```
```  2470     using assms
```
```  2471 proof (induct arbitrary:s g rule:finite_induct[OF \<open>finite pts\<close>])
```
```  2472   case 1
```
```  2473   then show ?case by (simp add: Cauchy_theorem_global contour_integral_unique)
```
```  2474 next
```
```  2475   case (2 p pts)
```
```  2476   note fin[simp] = \<open>finite (insert p pts)\<close>
```
```  2477     and connected = \<open>connected (s - insert p pts)\<close>
```
```  2478     and valid[simp] = \<open>valid_path g\<close>
```
```  2479     and g_loop[simp] = \<open>pathfinish g = pathstart g\<close>
```
```  2480     and holo[simp]= \<open>f holomorphic_on s - insert p pts\<close>
```
```  2481     and path_img = \<open>path_image g \<subseteq> s - insert p pts\<close>
```
```  2482     and winding = \<open>\<forall>z. z \<notin> s \<longrightarrow> winding_number g z = 0\<close>
```
```  2483     and h = \<open>\<forall>pa\<in>s. 0 < h pa \<and> (\<forall>w\<in>cball pa (h pa). w \<in> s \<and> (w \<noteq> pa \<longrightarrow> w \<notin> insert p pts))\<close>
```
```  2484   have "h p>0" and "p\<in>s"
```
```  2485     and h_p: "\<forall>w\<in>cball p (h p). w \<in> s \<and> (w \<noteq> p \<longrightarrow> w \<notin> insert p pts)"
```
```  2486     using h \<open>insert p pts \<subseteq> s\<close> by auto
```
```  2487   obtain pg where pg[simp]: "valid_path pg" "pathstart pg = pathstart g" "pathfinish pg=p+h p"
```
```  2488       "path_image pg \<subseteq> s-insert p pts" "f contour_integrable_on pg"
```
```  2489     proof -
```
```  2490       have "p + h p\<in>cball p (h p)" using h[rule_format,of p]
```
```  2491         by (simp add: \<open>p \<in> s\<close> dist_norm)
```
```  2492       then have "p + h p \<in> s - insert p pts" using h[rule_format,of p] \<open>insert p pts \<subseteq> s\<close>
```
```  2493         by fastforce
```
```  2494       moreover have "pathstart g \<in> s - insert p pts " using path_img by auto
```
```  2495       ultimately show ?thesis
```
```  2496         using get_integrable_path[OF \<open>open s\<close> connected fin holo,of "pathstart g" "p+h p"] that
```
```  2497         by blast
```
```  2498     qed
```
```  2499   obtain n::int where "n=winding_number g p"
```
```  2500     using integer_winding_number[OF _ g_loop,of p] valid path_img
```
```  2501     by (metis DiffD2 Ints_cases insertI1 subset_eq valid_path_imp_path)
```
```  2502   define p_circ where "p_circ \<equiv> circlepath p (h p)"
```
```  2503   define p_circ_pt where "p_circ_pt \<equiv> linepath (p+h p) (p+h p)"
```
```  2504   define n_circ where "n_circ \<equiv> \<lambda>n. (op +++ p_circ ^^ n) p_circ_pt"
```
```  2505   define cp where "cp \<equiv> if n\<ge>0 then reversepath (n_circ (nat n)) else n_circ (nat (- n))"
```
```  2506   have n_circ:"valid_path (n_circ k)"
```
```  2507       "winding_number (n_circ k) p = k"
```
```  2508       "pathstart (n_circ k) = p + h p" "pathfinish (n_circ k) = p + h p"
```
```  2509       "path_image (n_circ k) =  (if k=0 then {p + h p} else sphere p (h p))"
```
```  2510       "p \<notin> path_image (n_circ k)"
```
```  2511       "\<And>p'. p'\<notin>s - pts \<Longrightarrow> winding_number (n_circ k) p'=0 \<and> p'\<notin>path_image (n_circ k)"
```
```  2512       "f contour_integrable_on (n_circ k)"
```
```  2513       "contour_integral (n_circ k) f = k *  contour_integral p_circ f"
```
```  2514       for k
```
```  2515     proof (induct k)
```
```  2516       case 0
```
```  2517       show "valid_path (n_circ 0)"
```
```  2518         and "path_image (n_circ 0) =  (if 0=0 then {p + h p} else sphere p (h p))"
```
```  2519         and "winding_number (n_circ 0) p = of_nat 0"
```
```  2520         and "pathstart (n_circ 0) = p + h p"
```
```  2521         and "pathfinish (n_circ 0) = p + h p"
```
```  2522         and "p \<notin> path_image (n_circ 0)"
```
```  2523         unfolding n_circ_def p_circ_pt_def using \<open>h p > 0\<close>
```
```  2524         by (auto simp add: dist_norm)
```
```  2525       show "winding_number (n_circ 0) p'=0 \<and> p'\<notin>path_image (n_circ 0)" when "p'\<notin>s- pts" for p'
```
```  2526         unfolding n_circ_def p_circ_pt_def
```
```  2527         apply (auto intro!:winding_number_trivial)
```
```  2528         by (metis Diff_iff pathfinish_in_path_image pg(3) pg(4) subsetCE subset_insertI that)+
```
```  2529       show "f contour_integrable_on (n_circ 0)"
```
```  2530         unfolding n_circ_def p_circ_pt_def
```
```  2531         by (auto intro!:contour_integrable_continuous_linepath simp add:continuous_on_sing)
```
```  2532       show "contour_integral (n_circ 0) f = of_nat 0  *  contour_integral p_circ f"
```
```  2533         unfolding n_circ_def p_circ_pt_def by auto
```
```  2534     next
```
```  2535       case (Suc k)
```
```  2536       have n_Suc:"n_circ (Suc k) = p_circ +++ n_circ k" unfolding n_circ_def by auto
```
```  2537       have pcirc:"p \<notin> path_image p_circ" "valid_path p_circ" "pathfinish p_circ = pathstart (n_circ k)"
```
```  2538         using Suc(3) unfolding p_circ_def using \<open>h p > 0\<close> by (auto simp add: p_circ_def)
```
```  2539       have pcirc_image:"path_image p_circ \<subseteq> s - insert p pts"
```
```  2540         proof -
```
```  2541           have "path_image p_circ \<subseteq> cball p (h p)" using \<open>0 < h p\<close> p_circ_def by auto
```
```  2542           then show ?thesis using h_p pcirc(1) by auto
```
```  2543         qed
```
```  2544       have pcirc_integrable:"f contour_integrable_on p_circ"
```
```  2545         by (auto simp add:p_circ_def intro!: pcirc_image[unfolded p_circ_def]
```
```  2546           contour_integrable_continuous_circlepath holomorphic_on_imp_continuous_on
```
```  2547           holomorphic_on_subset[OF holo])
```
```  2548       show "valid_path (n_circ (Suc k))"
```
```  2549         using valid_path_join[OF pcirc(2) Suc(1) pcirc(3)] unfolding n_circ_def by auto
```
```  2550       show "path_image (n_circ (Suc k))
```
```  2551           = (if Suc k = 0 then {p + complex_of_real (h p)} else sphere p (h p))"
```
```  2552         proof -
```
```  2553           have "path_image p_circ = sphere p (h p)"
```
```  2554             unfolding p_circ_def using \<open>0 < h p\<close> by auto
```
```  2555           then show ?thesis unfolding n_Suc  using Suc.hyps(5)  \<open>h p>0\<close>
```
```  2556             by (auto simp add:  path_image_join[OF pcirc(3)]  dist_norm)
```
```  2557         qed
```
```  2558       then show "p \<notin> path_image (n_circ (Suc k))" using \<open>h p>0\<close> by auto
```
```  2559       show "winding_number (n_circ (Suc k)) p = of_nat (Suc k)"
```
```  2560         proof -
```
```  2561           have "winding_number p_circ p = 1"
```
```  2562             by (simp add: \<open>h p > 0\<close> p_circ_def winding_number_circlepath_centre)
```
```  2563           moreover have "p \<notin> path_image (n_circ k)" using Suc(5) \<open>h p>0\<close> by auto
```
```  2564           then have "winding_number (p_circ +++ n_circ k) p
```
```  2565               = winding_number p_circ p + winding_number (n_circ k) p"
```
```  2566             using  valid_path_imp_path Suc.hyps(1) Suc.hyps(2) pcirc
```
```  2567             apply (intro winding_number_join)
```
```  2568             by auto
```
```  2569           ultimately show ?thesis using Suc(2) unfolding n_circ_def
```
```  2570             by auto
```
```  2571         qed
```
```  2572       show "pathstart (n_circ (Suc k)) = p + h p"
```
```  2573         by (simp add: n_circ_def p_circ_def)
```
```  2574       show "pathfinish (n_circ (Suc k)) = p + h p"
```
```  2575         using Suc(4) unfolding n_circ_def by auto
```
```  2576       show "winding_number (n_circ (Suc k)) p'=0 \<and>  p'\<notin>path_image (n_circ (Suc k))" when "p'\<notin>s-pts" for p'
```
```  2577         proof -
```
```  2578           have " p' \<notin> path_image p_circ" using \<open>p \<in> s\<close> h p_circ_def that using pcirc_image by blast
```
```  2579           moreover have "p' \<notin> path_image (n_circ k)"
```
```  2580             using Suc.hyps(7) that by blast
```
```  2581           moreover have "winding_number p_circ p' = 0"
```
```  2582             proof -
```
```  2583               have "path_image p_circ \<subseteq> cball p (h p)"
```
```  2584                 using h unfolding p_circ_def using \<open>p \<in> s\<close> by fastforce
```
```  2585               moreover have "p'\<notin>cball p (h p)" using \<open>p \<in> s\<close> h that "2.hyps"(2) by fastforce
```
```  2586               ultimately show ?thesis unfolding p_circ_def
```
```  2587                 apply (intro winding_number_zero_outside)
```
```  2588                 by auto
```
```  2589             qed
```
```  2590           ultimately show ?thesis
```
```  2591             unfolding n_Suc
```
```  2592             apply (subst winding_number_join)
```
```  2593             by (auto simp: valid_path_imp_path pcirc Suc that not_in_path_image_join Suc.hyps(7)[OF that])
```
```  2594         qed
```
```  2595       show "f contour_integrable_on (n_circ (Suc k))"
```
```  2596         unfolding n_Suc
```
```  2597         by (rule contour_integrable_joinI[OF pcirc_integrable Suc(8) pcirc(2) Suc(1)])
```
```  2598       show "contour_integral (n_circ (Suc k)) f = (Suc k) *  contour_integral p_circ f"
```
```  2599         unfolding n_Suc
```
```  2600         by (auto simp add:contour_integral_join[OF pcirc_integrable Suc(8) pcirc(2) Suc(1)]
```
```  2601           Suc(9) algebra_simps)
```
```  2602     qed
```
```  2603   have cp[simp]:"pathstart cp = p + h p"  "pathfinish cp = p + h p"
```
```  2604          "valid_path cp" "path_image cp \<subseteq> s - insert p pts"
```
```  2605          "winding_number cp p = - n"
```
```  2606          "\<And>p'. p'\<notin>s - pts \<Longrightarrow> winding_number cp p'=0 \<and> p' \<notin> path_image cp"
```
```  2607          "f contour_integrable_on cp"
```
```  2608          "contour_integral cp f = - n * contour_integral p_circ f"
```
```  2609     proof -
```
```  2610       show "pathstart cp = p + h p" and "pathfinish cp = p + h p" and "valid_path cp"
```
```  2611         using n_circ unfolding cp_def by auto
```
```  2612     next
```
```  2613       have "sphere p (h p) \<subseteq>  s - insert p pts"
```
```  2614         using h[rule_format,of p] \<open>insert p pts \<subseteq> s\<close> by force
```
```  2615       moreover  have "p + complex_of_real (h p) \<in> s - insert p pts"
```
```  2616         using pg(3) pg(4) by (metis pathfinish_in_path_image subsetCE)
```
```  2617       ultimately show "path_image cp \<subseteq>  s - insert p pts" unfolding cp_def
```
```  2618         using n_circ(5)  by auto
```
```  2619     next
```
```  2620       show "winding_number cp p = - n"
```
```  2621         unfolding cp_def using winding_number_reversepath n_circ \<open>h p>0\<close>
```
```  2622         by (auto simp: valid_path_imp_path)
```
```  2623     next
```
```  2624       show "winding_number cp p'=0 \<and> p' \<notin> path_image cp" when "p'\<notin>s - pts" for p'
```
```  2625         unfolding cp_def
```
```  2626         apply (auto)
```
```  2627         apply (subst winding_number_reversepath)
```
```  2628         by (auto simp add: valid_path_imp_path n_circ(7)[OF that] n_circ(1))
```
```  2629     next
```
```  2630       show "f contour_integrable_on cp" unfolding cp_def
```
```  2631         using contour_integrable_reversepath_eq n_circ(1,8) by auto
```
```  2632     next
```
```  2633       show "contour_integral cp f = - n * contour_integral p_circ f"
```
```  2634         unfolding cp_def using contour_integral_reversepath[OF n_circ(1)] n_circ(9)
```
```  2635         by auto
```
```  2636     qed
```
```  2637   def g'\<equiv>"g +++ pg +++ cp +++ (reversepath pg)"
```
```  2638   have "contour_integral g' f = (\<Sum>p\<in>pts. winding_number g' p * contour_integral (circlepath p (h p)) f)"
```
```  2639     proof (rule "2.hyps"(3)[of "s-{p}" "g'",OF _ _ \<open>finite pts\<close> ])
```
```  2640       show "connected (s - {p} - pts)" using connected by (metis Diff_insert2)
```
```  2641       show "open (s - {p})" using \<open>open s\<close> by auto
```
```  2642       show " pts \<subseteq> s - {p}" using \<open>insert p pts \<subseteq> s\<close> \<open> p \<notin> pts\<close>  by blast
```
```  2643       show "f holomorphic_on s - {p} - pts" using holo \<open>p \<notin> pts\<close> by (metis Diff_insert2)
```
```  2644       show "valid_path g'"
```
```  2645         unfolding g'_def cp_def using n_circ valid pg g_loop
```
```  2646         by (auto intro!:valid_path_join )
```
```  2647       show "pathfinish g' = pathstart g'"
```
```  2648         unfolding g'_def cp_def using pg(2) by simp
```
```  2649       show "path_image g' \<subseteq> s - {p} - pts"
```
```  2650         proof -
```
```  2651           def s'\<equiv>"s - {p} - pts"
```
```  2652           have s':"s' = s-insert p pts " unfolding s'_def by auto
```
```  2653           then show ?thesis using path_img pg(4) cp(4)
```
```  2654             unfolding g'_def
```
```  2655             apply (fold s'_def s')
```
```  2656             apply (intro subset_path_image_join)
```
```  2657             by auto
```
```  2658         qed
```
```  2659       note path_join_imp[simp]
```
```  2660       show "\<forall>z. z \<notin> s - {p} \<longrightarrow> winding_number g' z = 0"
```
```  2661         proof clarify
```
```  2662           fix z assume z:"z\<notin>s - {p}"
```
```  2663           have "winding_number (g +++ pg +++ cp +++ reversepath pg) z = winding_number g z
```
```  2664               + winding_number (pg +++ cp +++ (reversepath pg)) z"
```
```  2665             proof (rule winding_number_join)
```
```  2666               show "path g" using \<open>valid_path g\<close> by (simp add: valid_path_imp_path)
```
```  2667               show "z \<notin> path_image g" using z path_img by auto
```
```  2668               show "path (pg +++ cp +++ reversepath pg)" using pg(3) cp
```
```  2669                 by (simp add: valid_path_imp_path)
```
```  2670             next
```
```  2671               have "path_image (pg +++ cp +++ reversepath pg) \<subseteq> s - insert p pts"
```
```  2672                 using pg(4) cp(4) by (auto simp:subset_path_image_join)
```
```  2673               then show "z \<notin> path_image (pg +++ cp +++ reversepath pg)" using z by auto
```
```  2674             next
```
```  2675               show "pathfinish g = pathstart (pg +++ cp +++ reversepath pg)" using g_loop by auto
```
```  2676             qed
```
```  2677           also have "... = winding_number g z + (winding_number pg z
```
```  2678               + winding_number (cp +++ (reversepath pg)) z)"
```
```  2679             proof (subst add_left_cancel,rule winding_number_join)
```
```  2680               show "path pg" and "path (cp +++ reversepath pg)"
```
```  2681                and "pathfinish pg = pathstart (cp +++ reversepath pg)"
```
```  2682                 by (auto simp add: valid_path_imp_path)
```
```  2683               show "z \<notin> path_image pg" using pg(4) z by blast
```
```  2684               show "z \<notin> path_image (cp +++ reversepath pg)" using z
```
```  2685                 by (metis Diff_iff \<open>z \<notin> path_image pg\<close> contra_subsetD cp(4) insertI1
```
```  2686                   not_in_path_image_join path_image_reversepath singletonD)
```
```  2687             qed
```
```  2688           also have "... = winding_number g z + (winding_number pg z
```
```  2689               + (winding_number cp z + winding_number (reversepath pg) z))"
```
```  2690             apply (auto intro!:winding_number_join simp: valid_path_imp_path)
```
```  2691             apply (metis Diff_iff contra_subsetD cp(4) insertI1 singletonD z)
```
```  2692             by (metis Diff_insert2 Diff_subset contra_subsetD pg(4) z)
```
```  2693           also have "... = winding_number g z + winding_number cp z"
```
```  2694             apply (subst winding_number_reversepath)
```
```  2695             apply (auto simp: valid_path_imp_path)
```
```  2696             by (metis Diff_iff contra_subsetD insertI1 pg(4) singletonD z)
```
```  2697           finally have "winding_number g' z = winding_number g z + winding_number cp z"
```
```  2698             unfolding g'_def .
```
```  2699           moreover have "winding_number g z + winding_number cp z = 0"
```
```  2700             using winding z \<open>n=winding_number g p\<close> by auto
```
```  2701           ultimately show "winding_number g' z = 0" unfolding g'_def by auto
```
```  2702         qed
```
```  2703       show "\<forall>pa\<in>s - {p}. 0 < h pa \<and> (\<forall>w\<in>cball pa (h pa). w \<in> s - {p} \<and> (w \<noteq> pa \<longrightarrow> w \<notin> pts))"
```
```  2704         using h by fastforce
```
```  2705     qed
```
```  2706   moreover have "contour_integral g' f = contour_integral g f
```
```  2707       - winding_number g p * contour_integral p_circ f"
```
```  2708     proof -
```
```  2709       have "contour_integral g' f =  contour_integral g f
```
```  2710         + contour_integral (pg +++ cp +++ reversepath pg) f"
```
```  2711         unfolding g'_def
```
```  2712         apply (subst contour_integral_join)
```
```  2713         by (auto simp add:open_Diff[OF \<open>open s\<close>,OF finite_imp_closed[OF fin]]
```
```  2714           intro!: contour_integrable_holomorphic_simple[OF holo _ _ path_img]
```
```  2715           contour_integrable_reversepath)
```
```  2716       also have "... = contour_integral g f + contour_integral pg f
```
```  2717           + contour_integral (cp +++ reversepath pg) f"
```
```  2718         apply (subst contour_integral_join)
```
```  2719         by (auto simp add:contour_integrable_reversepath)
```
```  2720       also have "... = contour_integral g f + contour_integral pg f
```
```  2721           + contour_integral cp f + contour_integral (reversepath pg) f"
```
```  2722         apply (subst contour_integral_join)
```
```  2723         by (auto simp add:contour_integrable_reversepath)
```
```  2724       also have "... = contour_integral g f + contour_integral cp f"
```
```  2725         using contour_integral_reversepath
```
```  2726         by (auto simp add:contour_integrable_reversepath)
```
```  2727       also have "... = contour_integral g f - winding_number g p * contour_integral p_circ f"
```
```  2728         using \<open>n=winding_number g p\<close> by auto
```
```  2729       finally show ?thesis .
```
```  2730     qed
```
```  2731   moreover have "winding_number g' p' = winding_number g p'" when "p'\<in>pts" for p'
```
```  2732     proof -
```
```  2733       have [simp]: "p' \<notin> path_image g" "p' \<notin> path_image pg" "p'\<notin>path_image cp"
```
```  2734         using "2.prems"(8) that
```
```  2735         apply blast
```
```  2736         apply (metis Diff_iff Diff_insert2 contra_subsetD pg(4) that)
```
```  2737         by (meson DiffD2 cp(4) set_rev_mp subset_insertI that)
```
```  2738       have "winding_number g' p' = winding_number g p'
```
```  2739           + winding_number (pg +++ cp +++ reversepath pg) p'" unfolding g'_def
```
```  2740         apply (subst winding_number_join)
```
```  2741         apply (simp_all add: valid_path_imp_path)
```
```  2742         apply (intro not_in_path_image_join)
```
```  2743         by auto
```
```  2744       also have "... = winding_number g p' + winding_number pg p'
```
```  2745           + winding_number (cp +++ reversepath pg) p'"
```
```  2746         apply (subst winding_number_join)
```
```  2747         apply (simp_all add: valid_path_imp_path)
```
```  2748         apply (intro not_in_path_image_join)
```
```  2749         by auto
```
```  2750       also have "... = winding_number g p' + winding_number pg p'+ winding_number cp p'
```
```  2751           + winding_number (reversepath pg) p'"
```
```  2752         apply (subst winding_number_join)
```
```  2753         by (simp_all add: valid_path_imp_path)
```
```  2754       also have "... = winding_number g p' + winding_number cp p'"
```
```  2755         apply (subst winding_number_reversepath)
```
```  2756         by (simp_all add: valid_path_imp_path)
```
```  2757       also have "... = winding_number g p'" using that by auto
```
```  2758       finally show ?thesis .
```
```  2759     qed
```
```  2760   ultimately show ?case unfolding p_circ_def
```
```  2761     apply (subst (asm) setsum.cong[OF refl,
```
```  2762         of pts _ "\<lambda>p. winding_number g p * contour_integral (circlepath p (h p)) f"])
```
```  2763     by (auto simp add:setsum.insert[OF \<open>finite pts\<close> \<open>p\<notin>pts\<close>] algebra_simps)
```
```  2764 qed
```
```  2765
```
```  2766 lemma Cauchy_theorem_singularities:
```
```  2767   assumes "open s" "connected s" "finite pts" and
```
```  2768           holo:"f holomorphic_on s-pts" and
```
```  2769           "valid_path g" and
```
```  2770           loop:"pathfinish g = pathstart g" and
```
```  2771           "path_image g \<subseteq> s-pts" and
```
```  2772           homo:"\<forall>z. (z \<notin> s) \<longrightarrow> winding_number g z  = 0" and
```
```  2773           avoid:"\<forall>p\<in>s. h p>0 \<and> (\<forall>w\<in>cball p (h p). w\<in>s \<and> (w\<noteq>p \<longrightarrow> w \<notin> pts))"
```
```  2774   shows "contour_integral g f = (\<Sum>p\<in>pts. winding_number g p * contour_integral (circlepath p (h p)) f)"
```
```  2775     (is "?L=?R")
```
```  2776 proof -
```
```  2777   define circ where "circ \<equiv> \<lambda>p. winding_number g p * contour_integral (circlepath p (h p)) f"
```
```  2778   define pts1 where "pts1 \<equiv> pts \<inter> s"
```
```  2779   define pts2 where "pts2 \<equiv> pts - pts1"
```
```  2780   have "pts=pts1 \<union> pts2" "pts1 \<inter> pts2 = {}" "pts2 \<inter> s={}" "pts1\<subseteq>s"
```
```  2781     unfolding pts1_def pts2_def by auto
```
```  2782   have "contour_integral g f =  (\<Sum>p\<in>pts1. circ p)" unfolding circ_def
```
```  2783     proof (rule Cauchy_theorem_aux[OF \<open>open s\<close> _ _ \<open>pts1\<subseteq>s\<close> _ \<open>valid_path g\<close> loop _ homo])
```
```  2784       have "finite pts1" unfolding pts1_def using \<open>finite pts\<close> by auto
```
```  2785       then show "connected (s - pts1)"
```
```  2786         using \<open>open s\<close> \<open>connected s\<close> connected_open_delete_finite[of s] by auto
```
```  2787     next
```
```  2788       show "finite pts1" using \<open>pts = pts1 \<union> pts2\<close> assms(3) by auto
```
```  2789       show "f holomorphic_on s - pts1" by (metis Diff_Int2 Int_absorb holo pts1_def)
```
```  2790       show "path_image g \<subseteq> s - pts1" using assms(7) pts1_def by auto
```
```  2791       show "\<forall>p\<in>s. 0 < h p \<and> (\<forall>w\<in>cball p (h p). w \<in> s \<and> (w \<noteq> p \<longrightarrow> w \<notin> pts1))"
```
```  2792         by (simp add: avoid pts1_def)
```
```  2793     qed
```
```  2794   moreover have "setsum circ pts2=0"
```
```  2795     proof -
```
```  2796       have "winding_number g p=0" when "p\<in>pts2" for p
```
```  2797         using  \<open>pts2 \<inter> s={}\<close> that homo[rule_format,of p] by auto
```
```  2798       thus ?thesis unfolding circ_def
```
```  2799         apply (intro setsum.neutral)
```
```  2800         by auto
```
```  2801     qed
```
```  2802   moreover have "?R=setsum circ pts1 + setsum circ pts2"
```
```  2803     unfolding circ_def
```
```  2804     using setsum.union_disjoint[OF _ _ \<open>pts1 \<inter> pts2 = {}\<close>] \<open>finite pts\<close> \<open>pts=pts1 \<union> pts2\<close>
```
```  2805     by blast
```
```  2806   ultimately show ?thesis
```
```  2807     apply (fold circ_def)
```
```  2808     by auto
```
```  2809 qed
```
```  2810
```
```  2811 lemma Residue_theorem:
```
```  2812   fixes s pts::"complex set" and f::"complex \<Rightarrow> complex"
```
```  2813     and g::"real \<Rightarrow> complex"
```
```  2814   assumes "open s" "connected s" "finite pts" and
```
```  2815           holo:"f holomorphic_on s-pts" and
```
```  2816           "valid_path g" and
```
```  2817           loop:"pathfinish g = pathstart g" and
```
```  2818           "path_image g \<subseteq> s-pts" and
```
```  2819           homo:"\<forall>z. (z \<notin> s) \<longrightarrow> winding_number g z  = 0"
```
```  2820   shows "contour_integral g f = 2 * pi * \<i> *(\<Sum>p\<in>pts. winding_number g p * residue f p)"
```
```  2821 proof -
```
```  2822   define c where "c \<equiv>  2 * pi * \<i>"
```
```  2823   obtain h where avoid:"\<forall>p\<in>s. h p>0 \<and> (\<forall>w\<in>cball p (h p). w\<in>s \<and> (w\<noteq>p \<longrightarrow> w \<notin> pts))"
```
```  2824     using finite_cball_avoid[OF \<open>open s\<close> \<open>finite pts\<close>] by metis
```
```  2825   have "contour_integral g f
```
```  2826       = (\<Sum>p\<in>pts. winding_number g p * contour_integral (circlepath p (h p)) f)"
```
```  2827     using Cauchy_theorem_singularities[OF assms avoid] .
```
```  2828   also have "... = (\<Sum>p\<in>pts.  c * winding_number g p * residue f p)"
```
```  2829     proof (intro setsum.cong)
```
```  2830       show "pts = pts" by simp
```
```  2831     next
```
```  2832       fix x assume "x \<in> pts"
```
```  2833       show "winding_number g x * contour_integral (circlepath x (h x)) f
```
```  2834           = c * winding_number g x * residue f x"
```
```  2835         proof (cases "x\<in>s")
```
```  2836           case False
```
```  2837           then have "winding_number g x=0" using homo by auto
```
```  2838           thus ?thesis by auto
```
```  2839         next
```
```  2840           case True
```
```  2841           have "contour_integral (circlepath x (h x)) f = c* residue f x"
```
```  2842             using \<open>x\<in>pts\<close> \<open>finite pts\<close> avoid[rule_format,OF True]
```
```  2843             apply (intro base_residue[of "s-(pts-{x})",THEN contour_integral_unique,folded c_def])
```
```  2844             by (auto intro:holomorphic_on_subset[OF holo] open_Diff[OF \<open>open s\<close> finite_imp_closed])
```
```  2845           then show ?thesis by auto
```
```  2846         qed
```
```  2847     qed
```
```  2848   also have "... = c * (\<Sum>p\<in>pts. winding_number g p * residue f p)"
```
```  2849     by (simp add: setsum_right_distrib algebra_simps)
```
```  2850   finally show ?thesis unfolding c_def .
```
```  2851 qed
```
```  2852
```
```  2853 subsection \<open>The argument principle\<close>
```
```  2854
```
```  2855 definition is_pole :: "('a::topological_space \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a \<Rightarrow> bool" where
```
```  2856   "is_pole f a =  (LIM x (at a). f x :> at_infinity)"
```
```  2857
```
```  2858 lemma is_pole_tendsto:
```
```  2859   fixes f::"('a::topological_space \<Rightarrow> 'b::real_normed_div_algebra)"
```
```  2860   shows "is_pole f x \<Longrightarrow> ((inverse o f) \<longlongrightarrow> 0) (at x)"
```
```  2861 unfolding is_pole_def
```
```  2862 by (auto simp add:filterlim_inverse_at_iff[symmetric] comp_def filterlim_at)
```
```  2863
```
```  2864 lemma is_pole_inverse_holomorphic:
```
```  2865   assumes "open s"
```
```  2866     and f_holo:"f holomorphic_on (s-{z})"
```
```  2867     and pole:"is_pole f z"
```
```  2868     and non_z:"\<forall>x\<in>s-{z}. f x\<noteq>0"
```
```  2869   shows "(\<lambda>x. if x=z then 0 else inverse (f x)) holomorphic_on s"
```
```  2870 proof -
```
```  2871   define g where "g \<equiv> \<lambda>x. if x=z then 0 else inverse (f x)"
```
```  2872   have "isCont g z" unfolding isCont_def  using is_pole_tendsto[OF pole]
```
```  2873     apply (subst Lim_cong_at[where b=z and y=0 and g="inverse \<circ> f"])
```
```  2874     by (simp_all add:g_def)
```
```  2875   moreover have "continuous_on (s-{z}) f" using f_holo holomorphic_on_imp_continuous_on by auto
```
```  2876   hence "continuous_on (s-{z}) (inverse o f)" unfolding comp_def
```
```  2877     by (auto elim!:continuous_on_inverse simp add:non_z)
```
```  2878   hence "continuous_on (s-{z}) g" unfolding g_def
```
```  2879     apply (subst continuous_on_cong[where t="s-{z}" and g="inverse o f"])
```
```  2880     by auto
```
```  2881   ultimately have "continuous_on s g" using open_delete[OF \<open>open s\<close>] \<open>open s\<close>
```
```  2882     by (auto simp add:continuous_on_eq_continuous_at)
```
```  2883   moreover have "(inverse o f) holomorphic_on (s-{z})"
```
```  2884     unfolding comp_def using f_holo
```
```  2885     by (auto elim!:holomorphic_on_inverse simp add:non_z)
```
```  2886   hence "g holomorphic_on (s-{z})"
```
```  2887     apply (subst holomorphic_cong[where t="s-{z}" and g="inverse o f"])
```
```  2888     by (auto simp add:g_def)
```
```  2889   ultimately show ?thesis unfolding g_def using \<open>open s\<close>
```
```  2890     by (auto elim!: no_isolated_singularity)
```
```  2891 qed
```
```  2892
```
```  2893
```
```  2894 (*order of the zero of f at z*)
```
```  2895 definition zorder::"(complex \<Rightarrow> complex) \<Rightarrow> complex \<Rightarrow> nat" where
```
```  2896   "zorder f z = (THE n. n>0 \<and> (\<exists>h r. r>0 \<and> h holomorphic_on cball z r
```
```  2897                     \<and> (\<forall>w\<in>cball z r. f w =  h w * (w-z)^n \<and> h w \<noteq>0)))"
```
```  2898
```
```  2899 definition zer_poly::"[complex \<Rightarrow> complex,complex]\<Rightarrow>complex \<Rightarrow> complex" where
```
```  2900   "zer_poly f z = (SOME h. \<exists>r . r>0 \<and> h holomorphic_on cball z r
```
```  2901                     \<and> (\<forall>w\<in>cball z r. f w =  h w * (w-z)^(zorder f z) \<and> h w \<noteq>0))"
```
```  2902
```
```  2903 (*order of the pole of f at z*)
```
```  2904 definition porder::"(complex \<Rightarrow> complex) \<Rightarrow> complex \<Rightarrow> nat" where
```
```  2905   "porder f z = (let f'=(\<lambda>x. if x=z then 0 else inverse (f x)) in zorder f' z)"
```
```  2906
```
```  2907 definition pol_poly::"[complex \<Rightarrow> complex,complex]\<Rightarrow>complex \<Rightarrow> complex" where
```
```  2908   "pol_poly f z = (let f'=(\<lambda> x. if x=z then 0 else inverse (f x))
```
```  2909       in inverse o zer_poly f' z)"
```
```  2910
```
```  2911
```
```  2912 lemma holomorphic_factor_zero_unique:
```
```  2913   fixes f::"complex \<Rightarrow> complex" and z::complex and r::real
```
```  2914   assumes "r>0"
```
```  2915     and asm:"\<forall>w\<in>ball z r. f w = (w-z)^n * g w \<and> g w\<noteq>0 \<and> f w = (w - z)^m * h w \<and> h w\<noteq>0"
```
```  2916     and g_holo:"g holomorphic_on ball z r" and h_holo:"h holomorphic_on ball z r"
```
```  2917   shows "n=m"
```
```  2918 proof -
```
```  2919   have "n>m \<Longrightarrow> False"
```
```  2920     proof -
```
```  2921       assume "n>m"
```
```  2922       have "(h \<longlongrightarrow> 0) (at z within ball z r)"
```
```  2923         proof (rule Lim_transform_within[OF _ \<open>r>0\<close>, where f="\<lambda>w. (w - z) ^ (n - m) * g w"])
```
```  2924           have "\<forall>w\<in>ball z r. w\<noteq>z \<longrightarrow> h w = (w-z)^(n-m) * g w" using \<open>n>m\<close> asm
```
```  2925             by (auto simp add:field_simps power_diff)
```
```  2926           then show "\<lbrakk>x' \<in> ball z r; 0 < dist x' z;dist x' z < r\<rbrakk>
```
```  2927             \<Longrightarrow> (x' - z) ^ (n - m) * g x' = h x'" for x' by auto
```
```  2928         next
```
```  2929           define F where "F \<equiv> at z within ball z r"
```
```  2930           define f' where "f' \<equiv> \<lambda>x. (x - z) ^ (n-m)"
```
```  2931           have "f' z=0" using \<open>n>m\<close> unfolding f'_def by auto
```
```  2932           moreover have "continuous F f'" unfolding f'_def F_def
```
```  2933             by (intro continuous_intros)
```
```  2934           ultimately have "(f' \<longlongrightarrow> 0) F" unfolding F_def
```
```  2935             by (simp add: continuous_within)
```
```  2936           moreover have "(g \<longlongrightarrow> g z) F"
```
```  2937             using holomorphic_on_imp_continuous_on[OF g_holo,unfolded continuous_on_def] \<open>r>0\<close>
```
```  2938             unfolding F_def by auto
```
```  2939           ultimately show " ((\<lambda>w. f' w * g w) \<longlongrightarrow> 0) F" using tendsto_mult by fastforce
```
```  2940         qed
```
```  2941       moreover have "(h \<longlongrightarrow> h z) (at z within ball z r)"
```
```  2942         using holomorphic_on_imp_continuous_on[OF h_holo]
```
```  2943         by (auto simp add:continuous_on_def \<open>r>0\<close>)
```
```  2944       moreover have "at z within ball z r \<noteq> bot" using \<open>r>0\<close>
```
```  2945         by (auto simp add:trivial_limit_within islimpt_ball)
```
```  2946       ultimately have "h z=0" by (auto intro: tendsto_unique)
```
```  2947       thus False using asm \<open>r>0\<close> by auto
```
```  2948     qed
```
```  2949   moreover have "m>n \<Longrightarrow> False"
```
```  2950     proof -
```
```  2951       assume "m>n"
```
```  2952       have "(g \<longlongrightarrow> 0) (at z within ball z r)"
```
```  2953         proof (rule Lim_transform_within[OF _ \<open>r>0\<close>, where f="\<lambda>w. (w - z) ^ (m - n) * h w"])
```
```  2954           have "\<forall>w\<in>ball z r. w\<noteq>z \<longrightarrow> g w = (w-z)^(m-n) * h w" using \<open>m>n\<close> asm
```
```  2955             by (auto simp add:field_simps power_diff)
```
```  2956           then show "\<lbrakk>x' \<in> ball z r; 0 < dist x' z;dist x' z < r\<rbrakk>
```
```  2957             \<Longrightarrow> (x' - z) ^ (m - n) * h x' = g x'" for x' by auto
```
```  2958         next
```
```  2959           define F where "F \<equiv> at z within ball z r"
```
```  2960           define f' where "f' \<equiv>\<lambda>x. (x - z) ^ (m-n)"
```
```  2961           have "f' z=0" using \<open>m>n\<close> unfolding f'_def by auto
```
```  2962           moreover have "continuous F f'" unfolding f'_def F_def
```
```  2963             by (intro continuous_intros)
```
```  2964           ultimately have "(f' \<longlongrightarrow> 0) F" unfolding F_def
```
```  2965             by (simp add: continuous_within)
```
```  2966           moreover have "(h \<longlongrightarrow> h z) F"
```
```  2967             using holomorphic_on_imp_continuous_on[OF h_holo,unfolded continuous_on_def] \<open>r>0\<close>
```
```  2968             unfolding F_def by auto
```
```  2969           ultimately show " ((\<lambda>w. f' w * h w) \<longlongrightarrow> 0) F" using tendsto_mult by fastforce
```
```  2970         qed
```
```  2971       moreover have "(g \<longlongrightarrow> g z) (at z within ball z r)"
```
```  2972         using holomorphic_on_imp_continuous_on[OF g_holo]
```
```  2973         by (auto simp add:continuous_on_def \<open>r>0\<close>)
```
```  2974       moreover have "at z within ball z r \<noteq> bot" using \<open>r>0\<close>
```
```  2975         by (auto simp add:trivial_limit_within islimpt_ball)
```
```  2976       ultimately have "g z=0" by (auto intro: tendsto_unique)
```
```  2977       thus False using asm \<open>r>0\<close> by auto
```
```  2978     qed
```
```  2979   ultimately show "n=m" by fastforce
```
```  2980 qed
```
```  2981
```
```  2982
```
```  2983 lemma holomorphic_factor_zero_Ex1:
```
```  2984   assumes "open s" "connected s" "z \<in> s" and
```
```  2985         holo:"f holomorphic_on s"
```
```  2986         and "f z = 0" and "\<exists>w\<in>s. f w \<noteq> 0"
```
```  2987   shows "\<exists>!n. \<exists>g r. 0 < n \<and> 0 < r \<and>
```
```  2988                 g holomorphic_on cball z r
```
```  2989                 \<and> (\<forall>w\<in>cball z r. f w = (w-z)^n * g w \<and> g w\<noteq>0)"
```
```  2990 proof (rule ex_ex1I)
```
```  2991   obtain g r n where "0 < n" "0 < r" "ball z r \<subseteq> s" and
```
```  2992           g:"g holomorphic_on ball z r"
```
```  2993           "\<And>w. w \<in> ball z r \<Longrightarrow> f w = (w - z) ^ n * g w"
```
```  2994           "\<And>w. w \<in> ball z r \<Longrightarrow> g w \<noteq> 0"
```
```  2995     using holomorphic_factor_zero_nonconstant[OF holo \<open>open s\<close> \<open>connected s\<close> \<open>z\<in>s\<close> \<open>f z=0\<close>]
```
```  2996     by (metis assms(3) assms(5) assms(6))
```
```  2997   def r'\<equiv>"r/2"
```
```  2998   have "cball z r' \<subseteq> ball z r" unfolding r'_def by (simp add: \<open>0 < r\<close> cball_subset_ball_iff)
```
```  2999   hence "cball z r' \<subseteq> s" "g holomorphic_on cball z r'"
```
```  3000       "(\<forall>w\<in>cball z r'. f w = (w - z) ^ n * g w \<and> g w \<noteq> 0)"
```
```  3001     using g \<open>ball z r \<subseteq> s\<close> by auto
```
```  3002   moreover have "r'>0" unfolding r'_def using \<open>0<r\<close> by auto
```
```  3003   ultimately show "\<exists>n g r. 0 < n \<and> 0 < r  \<and> g holomorphic_on cball z r
```
```  3004           \<and> (\<forall>w\<in>cball z r. f w = (w - z) ^ n * g w \<and> g w \<noteq> 0)"
```
```  3005     apply (intro exI[of _ n] exI[of _ g] exI[of _ r'])
```
```  3006     by (simp add:\<open>0 < n\<close>)
```
```  3007 next
```
```  3008   fix m n
```
```  3009   define fac where "fac \<equiv> \<lambda>n g r. \<forall>w\<in>cball z r. f w = (w - z) ^ n * g w \<and> g w \<noteq> 0"
```
```  3010   assume n_asm:"\<exists>g r1. 0 < n \<and> 0 < r1 \<and> g holomorphic_on cball z r1 \<and> fac n g r1"
```
```  3011      and m_asm:"\<exists>h r2. 0 < m \<and> 0 < r2  \<and> h holomorphic_on cball z r2 \<and> fac m h r2"
```
```  3012   obtain g r1 where "0 < n" "0 < r1" and g_holo: "g holomorphic_on cball z r1"
```
```  3013     and "fac n g r1" using n_asm by auto
```
```  3014   obtain h r2 where "0 < m" "0 < r2" and h_holo: "h holomorphic_on cball z r2"
```
```  3015     and "fac m h r2" using m_asm by auto
```
```  3016   define r where "r \<equiv> min r1 r2"
```
```  3017   have "r>0" using \<open>r1>0\<close> \<open>r2>0\<close> unfolding r_def by auto
```
```  3018   moreover have "\<forall>w\<in>ball z r. f w = (w-z)^n * g w \<and> g w\<noteq>0 \<and> f w = (w - z)^m * h w \<and> h w\<noteq>0"
```
```  3019     using \<open>fac m h r2\<close> \<open>fac n g r1\<close>   unfolding fac_def r_def
```
```  3020     by fastforce
```
```  3021   ultimately show "m=n" using g_holo h_holo
```
```  3022     apply (elim holomorphic_factor_zero_unique[of r z f n g m h,symmetric,rotated])
```
```  3023     by (auto simp add:r_def)
```
```  3024 qed
```
```  3025
```
```  3026 lemma zorder_exist:
```
```  3027   fixes f::"complex \<Rightarrow> complex" and z::complex
```
```  3028   defines "n\<equiv>zorder f z" and "h\<equiv>zer_poly f z"
```
```  3029   assumes  "open s" "connected s" "z\<in>s"
```
```  3030     and holo: "f holomorphic_on s"
```
```  3031     and  "f z=0" "\<exists>w\<in>s. f w\<noteq>0"
```
```  3032   shows "\<exists>r. n>0 \<and> r>0 \<and> cball z r \<subseteq> s \<and> h holomorphic_on cball z r
```
```  3033     \<and> (\<forall>w\<in>cball z r. f w  = h w * (w-z)^n \<and> h w \<noteq>0) "
```
```  3034 proof -
```
```  3035   define P where "P \<equiv> \<lambda>h r n. r>0 \<and> h holomorphic_on cball z r
```
```  3036     \<and> (\<forall>w\<in>cball z r. ( f w  = h w * (w-z)^n) \<and> h w \<noteq>0)"
```
```  3037   have "(\<exists>!n. n>0 \<and> (\<exists> h r. P h r n))"
```
```  3038     proof -
```
```  3039       have "\<exists>!n. \<exists>h r. n>0 \<and> P h r n"
```
```  3040         using holomorphic_factor_zero_Ex1[OF \<open>open s\<close> \<open>connected s\<close> \<open>z\<in>s\<close> holo \<open>f z=0\<close>
```
```  3041           \<open>\<exists>w\<in>s. f w\<noteq>0\<close>] unfolding P_def
```
```  3042         apply (subst mult.commute)
```
```  3043         by auto
```
```  3044       thus ?thesis by auto
```
```  3045     qed
```
```  3046   moreover have n:"n=(THE n. n>0 \<and> (\<exists>h r. P h r n))"
```
```  3047     unfolding n_def zorder_def P_def by simp
```
```  3048   ultimately have "n>0 \<and> (\<exists>h r. P h r n)"
```
```  3049     apply (drule_tac theI')
```
```  3050     by simp
```
```  3051   then have "n>0" and "\<exists>h r. P h r n" by auto
```
```  3052   moreover have "h=(SOME h. \<exists>r. P h r n)"
```
```  3053     unfolding h_def P_def zer_poly_def[of f z,folded n_def P_def] by simp
```
```  3054   ultimately have "\<exists>r. P h r n"
```
```  3055     apply (drule_tac someI_ex)
```
```  3056     by simp
```
```  3057   then obtain r1 where "P h r1 n" by auto
```
```  3058   obtain r2 where "r2>0" "cball z r2 \<subseteq> s"
```
```  3059     using assms(3) assms(5) open_contains_cball_eq by blast
```
```  3060   define r3 where "r3 \<equiv> min r1 r2"
```
```  3061   have "P h r3 n" using \<open>P h r1 n\<close> \<open>r2>0\<close> unfolding P_def r3_def
```
```  3062     by auto
```
```  3063   moreover have "cball z r3 \<subseteq> s" using \<open>cball z r2 \<subseteq> s\<close> unfolding r3_def by auto
```
```  3064   ultimately show ?thesis using \<open>n>0\<close> unfolding P_def by auto
```
```  3065 qed
```
```  3066
```
```  3067 lemma porder_exist:
```
```  3068   fixes f::"complex \<Rightarrow> complex" and z::complex
```
```  3069   defines "n \<equiv> porder f z" and "h \<equiv> pol_poly f z"
```
```  3070   assumes "open s" "z \<in> s"
```
```  3071     and holo:"f holomorphic_on s-{z}"
```
```  3072     and "is_pole f z"
```
```  3073   shows "\<exists>r. n>0 \<and> r>0 \<and> cball z r \<subseteq> s \<and> h holomorphic_on cball z r
```
```  3074     \<and> (\<forall>w\<in>cball z r. (w\<noteq>z \<longrightarrow> f w  = h w / (w-z)^n) \<and> h w \<noteq>0)"
```
```  3075 proof -
```
```  3076   obtain e where "e>0" and e_ball:"ball z e \<subseteq> s"and e_def: "\<forall>x\<in>ball z e-{z}. f x\<noteq>0"
```
```  3077     proof -
```
```  3078       have "\<forall>\<^sub>F z in at z. f z \<noteq> 0"
```
```  3079         using \<open>is_pole f z\<close> filterlim_at_infinity_imp_eventually_ne unfolding is_pole_def
```
```  3080         by auto
```
```  3081       then obtain e1 where "e1>0" and e1_def: "\<forall>x. x \<noteq> z \<and> dist x z < e1 \<longrightarrow> f x \<noteq> 0"
```
```  3082         using eventually_at[of "\<lambda>x. f x\<noteq>0" z,simplified] by auto
```
```  3083       obtain e2 where "e2>0" and "ball z e2 \<subseteq>s" using \<open>open s\<close> \<open>z\<in>s\<close> openE by auto
```
```  3084       define e where "e \<equiv> min e1 e2"
```
```  3085       have "e>0" using \<open>e1>0\<close> \<open>e2>0\<close> unfolding e_def by auto
```
```  3086       moreover have "ball z e \<subseteq> s" unfolding e_def using \<open>ball z e2 \<subseteq> s\<close> by auto
```
```  3087       moreover have "\<forall>x\<in>ball z e-{z}. f x\<noteq>0" using e1_def \<open>e1>0\<close> \<open>e2>0\<close> unfolding e_def
```
```  3088         by (simp add: DiffD1 DiffD2 dist_commute singletonI)
```
```  3089       ultimately show ?thesis using that by auto
```
```  3090     qed
```
```  3091   define g where "g \<equiv> \<lambda>x. if x=z then 0 else inverse (f x)"
```
```  3092   define zo where "zo \<equiv> zorder g z"
```
```  3093   define zp where "zp \<equiv> zer_poly g z"
```
```  3094   have "\<exists>w\<in>ball z e. g w \<noteq> 0"
```
```  3095     proof -
```
```  3096       obtain w where w:"w\<in>ball z e-{z}" using \<open>0 < e\<close>
```
```  3097         by (metis open_ball all_not_in_conv centre_in_ball insert_Diff_single
```
```  3098           insert_absorb not_open_singleton)
```
```  3099       hence "w\<noteq>z" "f w\<noteq>0" using e_def[rule_format,of w] mem_ball
```
```  3100         by (auto simp add:dist_commute)
```
```  3101       then show ?thesis unfolding g_def using w by auto
```
```  3102     qed
```
```  3103   moreover have "g holomorphic_on ball z e"
```
```  3104     apply (intro is_pole_inverse_holomorphic[of "ball z e",OF _ _ \<open>is_pole f z\<close> e_def,folded g_def])
```
```  3105     using holo e_ball by auto
```
```  3106   moreover have "g z=0" unfolding g_def by auto
```
```  3107   ultimately obtain r where "0 < zo" "0 < r" "cball z r \<subseteq> ball z e"
```
```  3108       and zp_holo: "zp holomorphic_on cball z r" and
```
```  3109       zp_fac: "\<forall>w\<in>cball z r. g w = zp w * (w - z) ^ zo \<and> zp w \<noteq> 0"
```
```  3110     using zorder_exist[of "ball z e" z g,simplified,folded zo_def zp_def] \<open>e>0\<close>
```
```  3111     by auto
```
```  3112   have n:"n=zo" and h:"h=inverse o zp"
```
```  3113     unfolding n_def zo_def porder_def h_def zp_def pol_poly_def g_def by simp_all
```
```  3114   have "h holomorphic_on cball z r"
```
```  3115     using zp_holo zp_fac holomorphic_on_inverse  unfolding h comp_def by blast
```
```  3116   moreover have "\<forall>w\<in>cball z r. (w\<noteq>z \<longrightarrow> f w  = h w / (w-z)^n) \<and> h w \<noteq>0"
```
```  3117     using zp_fac unfolding h n comp_def g_def
```
```  3118     by (metis divide_inverse_commute field_class.field_inverse_zero inverse_inverse_eq
```
```  3119       inverse_mult_distrib mult.commute)
```
```  3120   moreover have "0 < n" unfolding n using \<open>zo>0\<close> by simp
```
```  3121   ultimately show ?thesis using \<open>0 < r\<close> \<open>cball z r \<subseteq> ball z e\<close> e_ball by auto
```
```  3122 qed
```
```  3123
```
```  3124 lemma residue_porder:
```
```  3125   fixes f::"complex \<Rightarrow> complex" and z::complex
```
```  3126   defines "n \<equiv> porder f z" and "h \<equiv> pol_poly f z"
```
```  3127   assumes "open s" "z \<in> s"
```
```  3128     and holo:"f holomorphic_on s - {z}"
```
```  3129     and pole:"is_pole f z"
```
```  3130   shows "residue f z = ((deriv ^^ (n - 1)) h z / fact (n-1))"
```
```  3131 proof -
```
```  3132   define g where "g \<equiv> \<lambda>x. if x=z then 0 else inverse (f x)"
```
```  3133   obtain r where "0 < n" "0 < r" and r_cball:"cball z r \<subseteq> s" and h_holo: "h holomorphic_on cball z r"
```
```  3134       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)"
```
```  3135     using porder_exist[OF \<open>open s\<close> \<open>z \<in> s\<close> holo pole, folded n_def h_def] by blast
```
```  3136   have r_nonzero:"\<And>w. w \<in> ball z r - {z} \<Longrightarrow> f w \<noteq> 0"
```
```  3137     using h_divide by simp
```
```  3138   define c where "c \<equiv> 2 * pi * \<i>"
```
```  3139   define der_f where "der_f \<equiv> ((deriv ^^ (n - 1)) h z / fact (n-1))"
```
```  3140   def h'\<equiv>"\<lambda>u. h u / (u - z) ^ n"
```
```  3141   have "(h' has_contour_integral c / fact (n - 1) * (deriv ^^ (n - 1)) h z) (circlepath z r)"
```
```  3142     unfolding h'_def
```
```  3143     proof (rule Cauchy_has_contour_integral_higher_derivative_circlepath[of z r h z "n-1",
```
```  3144         folded c_def Suc_pred'[OF \<open>n>0\<close>]])
```
```  3145       show "continuous_on (cball z r) h" using holomorphic_on_imp_continuous_on h_holo by simp
```
```  3146       show "h holomorphic_on ball z r" using h_holo by auto
```
```  3147       show " z \<in> ball z r" using \<open>r>0\<close> by auto
```
```  3148     qed
```
```  3149   then have "(h' has_contour_integral c * der_f) (circlepath z r)" unfolding der_f_def by auto
```
```  3150   then have "(f has_contour_integral c * der_f) (circlepath z r)"
```
```  3151     proof (elim has_contour_integral_eq)
```
```  3152       fix x assume "x \<in> path_image (circlepath z r)"
```
```  3153       hence "x\<in>cball z r - {z}" using \<open>r>0\<close> by auto
```
```  3154       then show "h' x = f x" using h_divide unfolding h'_def by auto
```
```  3155     qed
```
```  3156   moreover have "(f has_contour_integral c * residue f z) (circlepath z r)"
```
```  3157     using base_residue[OF \<open>open s\<close> \<open>z\<in>s\<close> \<open>r>0\<close> holo r_cball,folded c_def] .
```
```  3158   ultimately have "c * der_f =  c * residue f z" using has_contour_integral_unique by blast
```
```  3159   hence "der_f = residue f z" unfolding c_def by auto
```
```  3160   thus ?thesis unfolding der_f_def by auto
```
```  3161 qed
```
```  3162
```
```  3163 theorem argument_principle:
```
```  3164   fixes f::"complex \<Rightarrow> complex" and poles s:: "complex set"
```
```  3165   defines "zeros\<equiv>{p. f p=0} - poles"
```
```  3166   assumes "open s" and
```
```  3167           "connected s" and
```
```  3168           f_holo:"f holomorphic_on s-poles" and
```
```  3169           h_holo:"h holomorphic_on s" and
```
```  3170           "valid_path g" and
```
```  3171           loop:"pathfinish g = pathstart g" and
```
```  3172           path_img:"path_image g \<subseteq> s - (zeros \<union> poles)" and
```
```  3173           homo:"\<forall>z. (z \<notin> s) \<longrightarrow> winding_number g z = 0" and
```
```  3174           finite:"finite (zeros \<union> poles)" and
```
```  3175           poles:"\<forall>p\<in>poles. is_pole f p"
```
```  3176   shows "contour_integral g (\<lambda>x. deriv f x * h x / f x) = 2 * pi * \<i> *
```
```  3177           ((\<Sum>p\<in>zeros. winding_number g p * h p * zorder f p)
```
```  3178            - (\<Sum>p\<in>poles. winding_number g p * h p * porder f p))"
```
```  3179     (is "?L=?R")
```
```  3180 proof -
```
```  3181   define c where "c \<equiv> 2 * complex_of_real pi * \<i> "
```
```  3182   define ff where "ff \<equiv> (\<lambda>x. deriv f x * h x / f x)"
```
```  3183   define cont_pole where "cont_pole \<equiv> \<lambda>ff p e. (ff has_contour_integral - c  * porder f p * h p) (circlepath p e)"
```
```  3184   define cont_zero where "cont_zero \<equiv> \<lambda>ff p e. (ff has_contour_integral c * zorder f p * h p ) (circlepath p e)"
```
```  3185   define avoid where "avoid \<equiv> \<lambda>p e. \<forall>w\<in>cball p e. w \<in> s \<and> (w \<noteq> p \<longrightarrow> w \<notin> zeros \<union> poles)"
```
```  3186   have "\<exists>e>0. avoid p e \<and> (p\<in>poles \<longrightarrow> cont_pole ff p e) \<and> (p\<in>zeros \<longrightarrow> cont_zero ff p e)"
```
```  3187       when "p\<in>s" for p
```
```  3188     proof -
```
```  3189       obtain e1 where "e1>0" and e1_avoid:"avoid p e1"
```
```  3190         using finite_cball_avoid[OF \<open>open s\<close> finite] \<open>p\<in>s\<close> unfolding avoid_def by auto
```
```  3191       have "\<exists>e2>0. cball p e2 \<subseteq> ball p e1 \<and> cont_pole ff p e2"
```
```  3192         when "p\<in>poles"
```
```  3193         proof -
```
```  3194           define po where "po \<equiv> porder f p"
```
```  3195           define pp where "pp \<equiv> pol_poly f p"
```
```  3196           def f'\<equiv>"\<lambda>w. pp w / (w - p) ^ po"
```
```  3197           def ff'\<equiv>"(\<lambda>x. deriv f' x * h x / f' x)"
```
```  3198           have "f holomorphic_on ball p e1 - {p}"
```
```  3199             apply (intro holomorphic_on_subset[OF f_holo])
```
```  3200             using e1_avoid \<open>p\<in>poles\<close> unfolding avoid_def by auto
```
```  3201           then obtain r where
```
```  3202               "0 < po" "r>0"
```
```  3203               "cball p r \<subseteq> ball p e1" and
```
```  3204               pp_holo:"pp holomorphic_on cball p r" and
```
```  3205               pp_po:"(\<forall>w\<in>cball p r. (w\<noteq>p \<longrightarrow> f w = pp w / (w - p) ^ po) \<and> pp w \<noteq> 0)"
```
```  3206             using porder_exist[of "ball p e1" p f,simplified,OF \<open>e1>0\<close>] poles \<open>p\<in>poles\<close>
```
```  3207             unfolding po_def pp_def
```
```  3208             by auto
```
```  3209           define e2 where "e2 \<equiv> r/2"
```
```  3210           have "e2>0" using \<open>r>0\<close> unfolding e2_def by auto
```
```  3211           define anal where "anal \<equiv> \<lambda>w. deriv pp w * h w / pp w"
```
```  3212           define prin where "prin \<equiv> \<lambda>w. - of_nat po * h w / (w - p)"
```
```  3213           have "((\<lambda>w.  prin w + anal w) has_contour_integral - c * po * h p) (circlepath p e2)"
```
```  3214             proof (rule  has_contour_integral_add[of _ _ _ _ 0,simplified])
```
```  3215               have "ball p r \<subseteq> s"
```
```  3216                 using \<open>cball p r \<subseteq> ball p e1\<close> avoid_def ball_subset_cball e1_avoid by blast
```
```  3217               then have "cball p e2 \<subseteq> s"
```
```  3218                 using \<open>r>0\<close> unfolding e2_def by auto
```
```  3219               then have "(\<lambda>w. - of_nat po * h w) holomorphic_on cball p e2"
```
```  3220                 using h_holo
```
```  3221                 by (auto intro!: holomorphic_intros)
```
```  3222               then show "(prin has_contour_integral - c * of_nat po * h p ) (circlepath p e2)"
```
```  3223                 using Cauchy_integral_circlepath_simple[folded c_def, of "\<lambda>w. - of_nat po * h w"]
```
```  3224                   \<open>e2>0\<close>
```
```  3225                 unfolding prin_def
```
```  3226                 by (auto simp add: mult.assoc)
```
```  3227               have "anal holomorphic_on ball p r" unfolding anal_def
```
```  3228                 using pp_holo h_holo pp_po \<open>ball p r \<subseteq> s\<close>
```
```  3229                 by (auto intro!: holomorphic_intros)
```
```  3230               then show "(anal has_contour_integral 0) (circlepath p e2)"
```
```  3231                 using e2_def \<open>r>0\<close>
```
```  3232                 by (auto elim!: Cauchy_theorem_disc_simple)
```
```  3233             qed
```
```  3234           then have "cont_pole ff' p e2" unfolding cont_pole_def po_def
```
```  3235             proof (elim has_contour_integral_eq)
```
```  3236               fix w assume "w \<in> path_image (circlepath p e2)"
```
```  3237               then have "w\<in>ball p r" and "w\<noteq>p" unfolding e2_def using \<open>r>0\<close> by auto
```
```  3238               define wp where "wp \<equiv> w-p"
```
```  3239               have "wp\<noteq>0" and "pp w \<noteq>0"
```
```  3240                 unfolding wp_def using \<open>w\<noteq>p\<close> \<open>w\<in>ball p r\<close> pp_po by auto
```
```  3241               moreover have der_f':"deriv f' w = - po * pp w / (w-p)^(po+1) + deriv pp w / (w-p)^po"
```
```  3242                 proof (rule DERIV_imp_deriv)
```
```  3243                   define der where "der \<equiv> - po * pp w / (w-p)^(po+1) + deriv pp w / (w-p)^po"
```
```  3244                   have po:"po = Suc (po - Suc 0) " using \<open>po>0\<close> by auto
```
```  3245                   have "(pp has_field_derivative (deriv pp w)) (at w)"
```
```  3246                     using DERIV_deriv_iff_has_field_derivative pp_holo \<open>w\<noteq>p\<close>
```
```  3247                       by (meson open_ball \<open>w \<in> ball p r\<close> ball_subset_cball holomorphic_derivI holomorphic_on_subset)
```
```  3248                   then show "(f' has_field_derivative  der) (at w)"
```
```  3249                     using \<open>w\<noteq>p\<close> \<open>po>0\<close> unfolding der_def f'_def
```
```  3250                     apply (auto intro!: derivative_eq_intros simp add:field_simps)
```
```  3251                     apply (subst (4) po)
```
```  3252                     apply (subst power_Suc)
```
```  3253                     by (auto simp add:field_simps)
```
```  3254                 qed
```
```  3255               ultimately show "prin w + anal w = ff' w"
```
```  3256                 unfolding ff'_def prin_def anal_def
```
```  3257                 apply simp
```
```  3258                 apply (unfold f'_def)
```
```  3259                 apply (fold wp_def)
```
```  3260                 by (auto simp add:field_simps)
```
```  3261             qed
```
```  3262           then have "cont_pole ff p e2" unfolding cont_pole_def
```
```  3263             proof (elim has_contour_integral_eq)
```
```  3264               fix w assume "w \<in> path_image (circlepath p e2)"
```
```  3265               then have "w\<in>ball p r" and "w\<noteq>p" unfolding e2_def using \<open>r>0\<close> by auto
```
```  3266               have "deriv f' w =  deriv f w"
```
```  3267                 proof (rule complex_derivative_transform_within_open[where s="ball p r - {p}"])
```
```  3268                   show "f' holomorphic_on ball p r - {p}" unfolding f'_def using pp_holo
```
```  3269                     by (auto intro!: holomorphic_intros)
```
```  3270                 next
```
```  3271                   have "ball p e1 - {p} \<subseteq> s - poles"
```
```  3272                     using avoid_def ball_subset_cball e1_avoid
```
```  3273                     by auto
```
```  3274                   then have "ball p r - {p} \<subseteq> s - poles" using \<open>cball p r \<subseteq> ball p e1\<close>
```
```  3275                     using ball_subset_cball by blast
```
```  3276                   then show "f holomorphic_on ball p r - {p}" using f_holo
```
```  3277                     by auto
```
```  3278                 next
```
```  3279                   show "open (ball p r - {p})" by auto
```
```  3280                 next
```
```  3281                   show "w \<in> ball p r - {p}" using \<open>w\<in>ball p r\<close> \<open>w\<noteq>p\<close> by auto
```
```  3282                 next
```
```  3283                   fix x assume "x \<in> ball p r - {p}"
```
```  3284                   then show "f' x = f x"
```
```  3285                     using pp_po unfolding f'_def by auto
```
```  3286                 qed
```
```  3287               moreover have " f' w  =  f w "
```
```  3288                 using \<open>w \<in> ball p r\<close> ball_subset_cball subset_iff pp_po \<open>w\<noteq>p\<close>
```
```  3289                 unfolding f'_def by auto
```
```  3290               ultimately show "ff' w = ff w"
```
```  3291                 unfolding ff'_def ff_def by simp
```
```  3292             qed
```
```  3293           moreover have "cball p e2 \<subseteq> ball p e1"
```
```  3294             using \<open>0 < r\<close> \<open>cball p r \<subseteq> ball p e1\<close> e2_def by auto
```
```  3295           ultimately show ?thesis using \<open>e2>0\<close> by auto
```
```  3296         qed
```
```  3297       then obtain e2 where e2:"p\<in>poles \<longrightarrow> e2>0 \<and> cball p e2 \<subseteq> ball p e1 \<and> cont_pole ff p e2"
```
```  3298         by auto
```
```  3299       have "\<exists>e3>0. cball p e3 \<subseteq> ball p e1 \<and> cont_zero ff p e3"
```
```  3300         when "p\<in>zeros"
```
```  3301         proof -
```
```  3302           define zo where "zo \<equiv> zorder f p"
```
```  3303           define zp where "zp \<equiv> zer_poly f p"
```
```  3304           def f'\<equiv>"\<lambda>w. zp w * (w - p) ^ zo"
```
```  3305           def ff'\<equiv>"(\<lambda>x. deriv f' x * h x / f' x)"
```
```  3306           have "f holomorphic_on ball p e1"
```
```  3307             proof -
```
```  3308               have "ball p e1 \<subseteq> s - poles"
```
```  3309                 using avoid_def ball_subset_cball e1_avoid that zeros_def by fastforce
```
```  3310               thus ?thesis using f_holo by auto
```
```  3311             qed
```
```  3312           moreover have "f p = 0" using \<open>p\<in>zeros\<close>
```
```  3313             using DiffD1 mem_Collect_eq zeros_def by blast
```
```  3314           moreover have "\<exists>w\<in>ball p e1. f w \<noteq> 0"
```
```  3315             proof -
```
```  3316               def p'\<equiv>"p+e1/2"
```
```  3317               have "p'\<in>ball p e1" and "p'\<noteq>p" using \<open>e1>0\<close> unfolding p'_def by (auto simp add:dist_norm)
```
```  3318               then show "\<exists>w\<in>ball p e1. f w \<noteq> 0" using e1_avoid unfolding avoid_def
```
```  3319                 apply (rule_tac x=p' in bexI)
```
```  3320                 by (auto simp add:zeros_def)
```
```  3321             qed
```
```  3322           ultimately obtain r where
```
```  3323               "0 < zo" "r>0"
```
```  3324               "cball p r \<subseteq> ball p e1" and
```
```  3325               pp_holo:"zp holomorphic_on cball p r" and
```
```  3326               pp_po:"(\<forall>w\<in>cball p r. f w = zp w * (w - p) ^ zo \<and> zp w \<noteq> 0)"
```
```  3327             using zorder_exist[of "ball p e1" p f,simplified,OF \<open>e1>0\<close>] unfolding zo_def zp_def
```
```  3328             by auto
```
```  3329           define e2 where "e2 \<equiv> r/2"
```
```  3330           have "e2>0" using \<open>r>0\<close> unfolding e2_def by auto
```
```  3331           define anal where "anal \<equiv> \<lambda>w. deriv zp w * h w / zp w"
```
```  3332           define prin where "prin \<equiv> \<lambda>w. of_nat zo * h w / (w - p)"
```
```  3333           have "((\<lambda>w.  prin w + anal w) has_contour_integral c * zo * h p) (circlepath p e2)"
```
```  3334             proof (rule  has_contour_integral_add[of _ _ _ _ 0,simplified])
```
```  3335               have "ball p r \<subseteq> s"
```
```  3336                 using \<open>cball p r \<subseteq> ball p e1\<close> avoid_def ball_subset_cball e1_avoid by blast
```
```  3337               then have "cball p e2 \<subseteq> s"
```
```  3338                 using \<open>r>0\<close> unfolding e2_def by auto
```
```  3339               then have "(\<lambda>w. of_nat zo * h w) holomorphic_on cball p e2"
```
```  3340                 using h_holo
```
```  3341                 by (auto intro!: holomorphic_intros)
```
```  3342               then show "(prin has_contour_integral c * of_nat zo * h p ) (circlepath p e2)"
```
```  3343                 using Cauchy_integral_circlepath_simple[folded c_def, of "\<lambda>w. of_nat zo * h w"]
```
```  3344                   \<open>e2>0\<close>
```
```  3345                 unfolding prin_def
```
```  3346                 by (auto simp add: mult.assoc)
```
```  3347               have "anal holomorphic_on ball p r" unfolding anal_def
```
```  3348                 using pp_holo h_holo pp_po \<open>ball p r \<subseteq> s\<close>
```
```  3349                 by (auto intro!: holomorphic_intros)
```
```  3350               then show "(anal has_contour_integral 0) (circlepath p e2)"
```
```  3351                 using e2_def \<open>r>0\<close>
```
```  3352                 by (auto elim!: Cauchy_theorem_disc_simple)
```
```  3353             qed
```
```  3354           then have "cont_zero ff' p e2" unfolding cont_zero_def zo_def
```
```  3355             proof (elim has_contour_integral_eq)
```
```  3356               fix w assume "w \<in> path_image (circlepath p e2)"
```
```  3357               then have "w\<in>ball p r" and "w\<noteq>p" unfolding e2_def using \<open>r>0\<close> by auto
```
```  3358               define wp where "wp \<equiv> w-p"
```
```  3359               have "wp\<noteq>0" and "zp w \<noteq>0"
```
```  3360                 unfolding wp_def using \<open>w\<noteq>p\<close> \<open>w\<in>ball p r\<close> pp_po by auto
```
```  3361               moreover have der_f':"deriv f' w = zo * zp w * (w-p)^(zo-1) + deriv zp w * (w-p)^zo"
```
```  3362                 proof (rule DERIV_imp_deriv)
```
```  3363                   define der where "der \<equiv> zo * zp w * (w-p)^(zo-1) + deriv zp w * (w-p)^zo"
```
```  3364                   have po:"zo = Suc (zo - Suc 0) " using \<open>zo>0\<close> by auto
```
```  3365                   have "(zp has_field_derivative (deriv zp w)) (at w)"
```
```  3366                     using DERIV_deriv_iff_has_field_derivative pp_holo
```
```  3367                     by (meson Topology_Euclidean_Space.open_ball \<open>w \<in> ball p r\<close> ball_subset_cball holomorphic_derivI holomorphic_on_subset)
```
```  3368                   then show "(f' has_field_derivative  der) (at w)"
```
```  3369                     using \<open>w\<noteq>p\<close> \<open>zo>0\<close> unfolding der_def f'_def
```
```  3370                     by (auto intro!: derivative_eq_intros simp add:field_simps)
```
```  3371                 qed
```
```  3372               ultimately show "prin w + anal w = ff' w"
```
```  3373                 unfolding ff'_def prin_def anal_def
```
```  3374                 apply simp
```
```  3375                 apply (unfold f'_def)
```
```  3376                 apply (fold wp_def)
```
```  3377                 apply (auto simp add:field_simps)
```
```  3378                 by (metis Suc_diff_Suc minus_nat.diff_0 power_Suc)
```
```  3379             qed
```
```  3380           then have "cont_zero ff p e2" unfolding cont_zero_def
```
```  3381             proof (elim has_contour_integral_eq)
```
```  3382               fix w assume "w \<in> path_image (circlepath p e2)"
```
```  3383               then have "w\<in>ball p r" and "w\<noteq>p" unfolding e2_def using \<open>r>0\<close> by auto
```
```  3384               have "deriv f' w =  deriv f w"
```
```  3385                 proof (rule complex_derivative_transform_within_open[where s="ball p r - {p}"])
```
```  3386                   show "f' holomorphic_on ball p r - {p}" unfolding f'_def using pp_holo
```
```  3387                     by (auto intro!: holomorphic_intros)
```
```  3388                 next
```
```  3389                   have "ball p e1 - {p} \<subseteq> s - poles"
```
```  3390                     using avoid_def ball_subset_cball e1_avoid by auto
```
```  3391                   then have "ball p r - {p} \<subseteq> s - poles" using \<open>cball p r \<subseteq> ball p e1\<close>
```
```  3392                     using ball_subset_cball by blast
```
```  3393                   then show "f holomorphic_on ball p r - {p}" using f_holo
```
```  3394                     by auto
```
```  3395                 next
```
```  3396                   show "open (ball p r - {p})" by auto
```
```  3397                 next
```
```  3398                   show "w \<in> ball p r - {p}" using \<open>w\<in>ball p r\<close> \<open>w\<noteq>p\<close> by auto
```
```  3399                 next
```
```  3400                   fix x assume "x \<in> ball p r - {p}"
```
```  3401                   then show "f' x = f x"
```
```  3402                     using pp_po unfolding f'_def by auto
```
```  3403                 qed
```
```  3404               moreover have " f' w  =  f w "
```
```  3405                 using \<open>w \<in> ball p r\<close> ball_subset_cball subset_iff pp_po unfolding f'_def by auto
```
```  3406               ultimately show "ff' w = ff w"
```
```  3407                 unfolding ff'_def ff_def by simp
```
```  3408             qed
```
```  3409           moreover have "cball p e2 \<subseteq> ball p e1"
```
```  3410             using \<open>0 < r\<close> \<open>cball p r \<subseteq> ball p e1\<close> e2_def by auto
```
```  3411           ultimately show ?thesis using \<open>e2>0\<close> by auto
```
```  3412         qed
```
```  3413       then obtain e3 where e3:"p\<in>zeros \<longrightarrow> e3>0 \<and> cball p e3 \<subseteq> ball p e1 \<and> cont_zero ff p e3"
```
```  3414         by auto
```
```  3415       define e4 where "e4 \<equiv> if p\<in>poles then e2 else if p\<in>zeros then e3 else e1"
```
```  3416       have "e4>0" using e2 e3 \<open>e1>0\<close> unfolding e4_def by auto
```
```  3417       moreover have "avoid p e4" using e2 e3 \<open>e1>0\<close> e1_avoid unfolding e4_def avoid_def by auto
```
```  3418       moreover have "p\<in>poles \<longrightarrow> cont_pole ff p e4" and "p\<in>zeros \<longrightarrow> cont_zero ff p e4"
```
```  3419         by (auto simp add: e2 e3 e4_def zeros_def)
```
```  3420       ultimately show ?thesis by auto
```
```  3421     qed
```
```  3422   then obtain get_e where get_e:"\<forall>p\<in>s. get_e p>0 \<and> avoid p (get_e p)
```
```  3423       \<and> (p\<in>poles \<longrightarrow> cont_pole ff p (get_e p)) \<and> (p\<in>zeros \<longrightarrow> cont_zero ff p (get_e p))"
```
```  3424     by metis
```
```  3425   define cont where "cont \<equiv> \<lambda>p. contour_integral (circlepath p (get_e p)) ff"
```
```  3426   define w where "w \<equiv> \<lambda>p. winding_number g p"
```
```  3427   have "contour_integral g ff = (\<Sum>p\<in>zeros \<union> poles. w p * cont p)"
```
```  3428     unfolding cont_def w_def
```
```  3429     proof (rule Cauchy_theorem_singularities[OF \<open>open s\<close> \<open>connected s\<close> finite _ \<open>valid_path g\<close> loop
```
```  3430         path_img homo])
```
```  3431       have "open (s - (zeros \<union> poles))" using open_Diff[OF _ finite_imp_closed[OF finite]] \<open>open s\<close> by auto
```
```  3432       then show "ff holomorphic_on s - (zeros \<union> poles)" unfolding ff_def using f_holo h_holo
```
```  3433         by (auto intro!: holomorphic_intros simp add:zeros_def)
```
```  3434     next
```
```  3435       show "\<forall>p\<in>s. 0 < get_e p \<and> (\<forall>w\<in>cball p (get_e p). w \<in> s \<and> (w \<noteq> p \<longrightarrow> w \<notin> zeros \<union> poles))"
```
```  3436         using get_e using avoid_def by blast
```
```  3437     qed
```
```  3438   also have "... = (\<Sum>p\<in>zeros. w p * cont p) + (\<Sum>p\<in>poles. w p * cont p)"
```
```  3439     using finite
```
```  3440     apply (subst setsum.union_disjoint)
```
```  3441     by (auto simp add:zeros_def)
```
```  3442   also have "... = c * ((\<Sum>p\<in>zeros. w p *  h p * zorder f p) - (\<Sum>p\<in>poles. w p *  h p * porder f p))"
```
```  3443     proof -
```
```  3444       have "(\<Sum>p\<in>zeros. w p * cont p) = (\<Sum>p\<in>zeros. c * w p *  h p * zorder f p)"
```
```  3445         proof (rule setsum.cong[of zeros zeros,simplified])
```
```  3446           fix p assume "p \<in> zeros"
```
```  3447           show "w p * cont p = c * w p * h p * (zorder f p)"
```
```  3448             proof (cases "p\<in>s")
```
```  3449               assume "p \<in> s"
```
```  3450               have "cont p = c * h p * (zorder f p)" unfolding cont_def
```
```  3451                 apply (rule contour_integral_unique)
```
```  3452                 using get_e \<open>p\<in>s\<close> \<open>p\<in>zeros\<close> unfolding cont_zero_def
```
```  3453                 by (metis mult.assoc mult.commute)
```
```  3454               thus ?thesis by auto
```
```  3455             next
```
```  3456               assume "p\<notin>s"
```
```  3457               then have "w p=0" using homo unfolding w_def by auto
```
```  3458               then show ?thesis by auto
```
```  3459             qed
```
```  3460         qed
```
```  3461       then have "(\<Sum>p\<in>zeros. w p * cont p) = c * (\<Sum>p\<in>zeros.  w p *  h p * zorder f p)"
```
```  3462         apply (subst setsum_right_distrib)
```
```  3463         by (simp add:algebra_simps)
```
```  3464       moreover have "(\<Sum>p\<in>poles. w p * cont p) = (\<Sum>p\<in>poles.  - c * w p *  h p * porder f p)"
```
```  3465         proof (rule setsum.cong[of poles poles,simplified])
```
```  3466           fix p assume "p \<in> poles"
```
```  3467           show "w p * cont p = - c * w p * h p * (porder f p)"
```
```  3468             proof (cases "p\<in>s")
```
```  3469               assume "p \<in> s"
```
```  3470               have "cont p = - c * h p * (porder f p)" unfolding cont_def
```
```  3471                 apply (rule contour_integral_unique)
```
```  3472                 using get_e \<open>p\<in>s\<close> \<open>p\<in>poles\<close> unfolding cont_pole_def
```
```  3473                 by (metis mult.assoc mult.commute)
```
```  3474               thus ?thesis by auto
```
```  3475             next
```
```  3476               assume "p\<notin>s"
```
```  3477               then have "w p=0" using homo unfolding w_def by auto
```
```  3478               then show ?thesis by auto
```
```  3479             qed
```
```  3480         qed
```
```  3481       then have "(\<Sum>p\<in>poles. w p * cont p) = - c * (\<Sum>p\<in>poles. w p *  h p * porder f p)"
```
```  3482         apply (subst setsum_right_distrib)
```
```  3483         by (simp add:algebra_simps)
```
```  3484       ultimately show ?thesis by (simp add: right_diff_distrib)
```
```  3485     qed
```
```  3486   finally show ?thesis unfolding w_def ff_def c_def by auto
```
```  3487 qed
```
```  3488
```
```  3489 subsection \<open>Rouche's theorem \<close>
```
```  3490
```
```  3491 theorem Rouche_theorem:
```
```  3492   fixes f g::"complex \<Rightarrow> complex" and s:: "complex set"
```
```  3493   defines "fg\<equiv>(\<lambda>p. f p+ g p)"
```
```  3494   defines "zeros_fg\<equiv>{p. fg p =0}" and "zeros_f\<equiv>{p. f p=0}"
```
```  3495   assumes
```
```  3496     "open s" and "connected s" and
```
```  3497     "finite zeros_fg" and
```
```  3498     "finite zeros_f" and
```
```  3499     f_holo:"f holomorphic_on s" and
```
```  3500     g_holo:"g holomorphic_on s" and
```
```  3501     "valid_path \<gamma>" and
```
```  3502     loop:"pathfinish \<gamma> = pathstart \<gamma>" and
```
```  3503     path_img:"path_image \<gamma> \<subseteq> s " and
```
```  3504     path_less:"\<forall>z\<in>path_image \<gamma>. cmod(f z) > cmod(g z)" and
```
```  3505     homo:"\<forall>z. (z \<notin> s) \<longrightarrow> winding_number \<gamma> z = 0"
```
```  3506   shows "(\<Sum>p\<in>zeros_fg. winding_number \<gamma> p * zorder fg p)
```
```  3507           = (\<Sum>p\<in>zeros_f. winding_number \<gamma> p * zorder f p)"
```
```  3508 proof -
```
```  3509   have path_fg:"path_image \<gamma> \<subseteq> s - zeros_fg"
```
```  3510     proof -
```
```  3511       have False when "z\<in>path_image \<gamma>" and "f z + g z=0" for z
```
```  3512         proof -
```
```  3513           have "cmod (f z) > cmod (g z)" using \<open>z\<in>path_image \<gamma>\<close> path_less by auto
```
```  3514           moreover have "f z = - g z"  using \<open>f z + g z =0\<close> by (simp add: eq_neg_iff_add_eq_0)
```
```  3515           then have "cmod (f z) = cmod (g z)" by auto
```
```  3516           ultimately show False by auto
```
```  3517         qed
```
```  3518       then show ?thesis unfolding zeros_fg_def fg_def using path_img by auto
```
```  3519     qed
```
```  3520   have path_f:"path_image \<gamma> \<subseteq> s - zeros_f"
```
```  3521     proof -
```
```  3522       have False when "z\<in>path_image \<gamma>" and "f z =0" for z
```
```  3523         proof -
```
```  3524           have "cmod (g z) < cmod (f z) " using \<open>z\<in>path_image \<gamma>\<close> path_less by auto
```
```  3525           then have "cmod (g z) < 0" using \<open>f z=0\<close> by auto
```
```  3526           then show False by auto
```
```  3527         qed
```
```  3528       then show ?thesis unfolding zeros_f_def using path_img by auto
```
```  3529     qed
```
```  3530   define w where "w \<equiv> \<lambda>p. winding_number \<gamma> p"
```
```  3531   define c where "c \<equiv> 2 * complex_of_real pi * \<i>"
```
```  3532   define h where "h \<equiv> \<lambda>p. g p / f p + 1"
```
```  3533   obtain spikes
```
```  3534     where "finite spikes" and spikes: "\<forall>x\<in>{0..1} - spikes. \<gamma> differentiable at x"
```
```  3535     using \<open>valid_path \<gamma>\<close>
```
```  3536     by (auto simp: valid_path_def piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
```
```  3537   have h_contour:"((\<lambda>x. deriv h x / h x) has_contour_integral 0) \<gamma>"
```
```  3538     proof -
```
```  3539       have outside_img:"0 \<in> outside (path_image (h o \<gamma>))"
```
```  3540         proof -
```
```  3541           have "h p \<in> ball 1 1" when "p\<in>path_image \<gamma>" for p
```
```  3542             proof -
```
```  3543               have "cmod (g p/f p) <1" using path_less[rule_format,OF that]
```
```  3544                 apply (cases "cmod (f p) = 0")
```
```  3545                 by (auto simp add: norm_divide)
```
```  3546               then show ?thesis unfolding h_def by (auto simp add:dist_complex_def)
```
```  3547             qed
```
```  3548           then have "path_image (h o \<gamma>) \<subseteq> ball 1 1"
```
```  3549             by (simp add: image_subset_iff path_image_compose)
```
```  3550           moreover have " (0::complex) \<notin> ball 1 1" by (simp add: dist_norm)
```
```  3551           ultimately show "?thesis"
```
```  3552             using  convex_in_outside[of "ball 1 1" 0] outside_mono by blast
```
```  3553         qed
```
```  3554       have valid_h:"valid_path (h \<circ> \<gamma>)"
```
```  3555         proof (rule valid_path_compose_holomorphic[OF \<open>valid_path \<gamma>\<close> _ _ path_f])
```
```  3556           show "h holomorphic_on s - zeros_f"
```
```  3557             unfolding h_def using f_holo g_holo
```
```  3558             by (auto intro!: holomorphic_intros simp add:zeros_f_def)
```
```  3559         next
```
```  3560           show "open (s - zeros_f)" using \<open>finite zeros_f\<close> \<open>open s\<close> finite_imp_closed
```
```  3561             by auto
```
```  3562         qed
```
```  3563       have "((\<lambda>z. 1/z) has_contour_integral 0) (h \<circ> \<gamma>)"
```
```  3564         proof -
```
```  3565           have "0 \<notin> path_image (h \<circ> \<gamma>)" using outside_img by (simp add: outside_def)
```
```  3566           then have "((\<lambda>z. 1/z) has_contour_integral c * winding_number (h \<circ> \<gamma>) 0) (h \<circ> \<gamma>)"
```
```  3567             using has_contour_integral_winding_number[of "h o \<gamma>" 0,simplified] valid_h
```
```  3568             unfolding c_def by auto
```
```  3569           moreover have "winding_number (h o \<gamma>) 0 = 0"
```
```  3570             proof -
```
```  3571               have "0 \<in> outside (path_image (h \<circ> \<gamma>))" using outside_img .
```
```  3572               moreover have "path (h o \<gamma>)"
```
```  3573                 using valid_h  by (simp add: valid_path_imp_path)
```
```  3574               moreover have "pathfinish (h o \<gamma>) = pathstart (h o \<gamma>)"
```
```  3575                 by (simp add: loop pathfinish_compose pathstart_compose)
```
```  3576               ultimately show ?thesis using winding_number_zero_in_outside by auto
```
```  3577             qed
```
```  3578           ultimately show ?thesis by auto
```
```  3579         qed
```
```  3580       moreover have "vector_derivative (h \<circ> \<gamma>) (at x) = vector_derivative \<gamma> (at x) * deriv h (\<gamma> x)"
```
```  3581           when "x\<in>{0..1} - spikes" for x
```
```  3582         proof (rule vector_derivative_chain_at_general)
```
```  3583           show "\<gamma> differentiable at x" using that \<open>valid_path \<gamma>\<close> spikes by auto
```
```  3584         next
```
```  3585           define der where "der \<equiv> \<lambda>p. (deriv g p * f p - g p * deriv f p)/(f p * f p)"
```
```  3586           define t where "t \<equiv> \<gamma> x"
```
```  3587           have "f t\<noteq>0" unfolding zeros_f_def t_def
```
```  3588             by (metis DiffD1 image_eqI norm_not_less_zero norm_zero path_defs(4) path_less that)
```
```  3589           moreover have "t\<in>s"
```
```  3590             using contra_subsetD path_image_def path_fg t_def that by fastforce
```
```  3591           ultimately have "(h has_field_derivative der t) (at t)"
```
```  3592             unfolding h_def der_def using g_holo f_holo \<open>open s\<close>
```
```  3593             by (auto intro!: holomorphic_derivI derivative_eq_intros )
```
```  3594           then show "\<exists>g'. (h has_field_derivative g') (at (\<gamma> x))" unfolding t_def by auto
```
```  3595         qed
```
```  3596       then have " (op / 1 has_contour_integral 0) (h \<circ> \<gamma>)
```
```  3597           = ((\<lambda>x. deriv h x / h x) has_contour_integral 0) \<gamma>"
```
```  3598         unfolding has_contour_integral
```
```  3599         apply (intro has_integral_spike_eq[OF negligible_finite, OF \<open>finite spikes\<close>])
```
```  3600         by auto
```
```  3601       ultimately show ?thesis by auto
```
```  3602     qed
```
```  3603   then have "contour_integral \<gamma> (\<lambda>x. deriv h x / h x) = 0"
```
```  3604     using  contour_integral_unique by simp
```
```  3605   moreover have "contour_integral \<gamma> (\<lambda>x. deriv fg x / fg x) = contour_integral \<gamma> (\<lambda>x. deriv f x / f x)
```
```  3606       + contour_integral \<gamma> (\<lambda>p. deriv h p / h p)"
```
```  3607     proof -
```
```  3608       have "(\<lambda>p. deriv f p / f p) contour_integrable_on \<gamma>"
```
```  3609         proof (rule contour_integrable_holomorphic_simple[OF _ _ \<open>valid_path \<gamma>\<close> path_f])
```
```  3610           show "open (s - zeros_f)" using finite_imp_closed[OF \<open>finite zeros_f\<close>] \<open>open s\<close>
```
```  3611             by auto
```
```  3612           then show "(\<lambda>p. deriv f p / f p) holomorphic_on s - zeros_f"
```
```  3613             using f_holo
```
```  3614             by (auto intro!: holomorphic_intros simp add:zeros_f_def)
```
```  3615         qed
```
```  3616       moreover have "(\<lambda>p. deriv h p / h p) contour_integrable_on \<gamma>"
```
```  3617         using h_contour
```
```  3618         by (simp add: has_contour_integral_integrable)
```
```  3619       ultimately have "contour_integral \<gamma> (\<lambda>x. deriv f x / f x + deriv h x / h x) =
```
```  3620           contour_integral \<gamma> (\<lambda>p. deriv f p / f p) + contour_integral \<gamma> (\<lambda>p. deriv h p / h p)"
```
```  3621         using contour_integral_add[of "(\<lambda>p. deriv f p / f p)" \<gamma> "(\<lambda>p. deriv h p / h p)" ]
```
```  3622         by auto
```
```  3623       moreover have "deriv fg p / fg p =  deriv f p / f p + deriv h p / h p"
```
```  3624           when "p\<in> path_image \<gamma>" for p
```
```  3625         proof -
```
```  3626           have "fg p\<noteq>0" and "f p\<noteq>0" using path_f path_fg that unfolding zeros_f_def zeros_fg_def
```
```  3627             by auto
```
```  3628           have "h p\<noteq>0"
```
```  3629             proof (rule ccontr)
```
```  3630               assume "\<not> h p \<noteq> 0"
```
```  3631               then have "g p / f p= -1" unfolding h_def by (simp add: add_eq_0_iff2)
```
```  3632               then have "cmod (g p/f p) = 1" by auto
```
```  3633               moreover have "cmod (g p/f p) <1" using path_less[rule_format,OF that]
```
```  3634                 apply (cases "cmod (f p) = 0")
```
```  3635                 by (auto simp add: norm_divide)
```
```  3636               ultimately show False by auto
```
```  3637             qed
```
```  3638           have der_fg:"deriv fg p =  deriv f p + deriv g p" unfolding fg_def
```
```  3639             using f_holo g_holo holomorphic_on_imp_differentiable_at[OF _  \<open>open s\<close>] path_img that
```
```  3640             by auto
```
```  3641           have der_h:"deriv h p = (deriv g p * f p - g p * deriv f p)/(f p * f p)"
```
```  3642             proof -
```
```  3643               define der where "der \<equiv> \<lambda>p. (deriv g p * f p - g p * deriv f p)/(f p * f p)"
```
```  3644               have "p\<in>s" using path_img that by auto
```
```  3645               then have "(h has_field_derivative der p) (at p)"
```
```  3646                 unfolding h_def der_def using g_holo f_holo \<open>open s\<close> \<open>f p\<noteq>0\<close>
```
```  3647                 by (auto intro!: derivative_eq_intros holomorphic_derivI)
```
```  3648               then show ?thesis unfolding der_def using DERIV_imp_deriv by auto
```
```  3649             qed
```
```  3650           show ?thesis
```
```  3651             apply (simp only:der_fg der_h)
```
```  3652             apply (auto simp add:field_simps \<open>h p\<noteq>0\<close> \<open>f p\<noteq>0\<close> \<open>fg p\<noteq>0\<close>)
```
```  3653             by (auto simp add:field_simps h_def \<open>f p\<noteq>0\<close> fg_def)
```
```  3654         qed
```
```  3655       then have "contour_integral \<gamma> (\<lambda>p. deriv fg p / fg p)
```
```  3656           = contour_integral \<gamma> (\<lambda>p. deriv f p / f p + deriv h p / h p)"
```
```  3657         by (elim contour_integral_eq)
```
```  3658       ultimately show ?thesis by auto
```
```  3659     qed
```
```  3660   moreover have "contour_integral \<gamma> (\<lambda>x. deriv fg x / fg x) = c * (\<Sum>p\<in>zeros_fg. w p * zorder fg p)"
```
```  3661     unfolding c_def zeros_fg_def w_def
```
```  3662     proof (rule argument_principle[OF \<open>open s\<close> \<open>connected s\<close> _ _ \<open>valid_path \<gamma>\<close> loop _ homo
```
```  3663         , of _ "{}" "\<lambda>_. 1",simplified])
```
```  3664       show "fg holomorphic_on s" unfolding fg_def using f_holo g_holo holomorphic_on_add by auto
```
```  3665       show "path_image \<gamma> \<subseteq> s - {p. fg p = 0}" using path_fg unfolding zeros_fg_def .
```
```  3666       show " finite {p. fg p = 0}" using \<open>finite zeros_fg\<close> unfolding zeros_fg_def .
```
```  3667     qed
```
```  3668   moreover have "contour_integral \<gamma> (\<lambda>x. deriv f x / f x) = c * (\<Sum>p\<in>zeros_f. w p * zorder f p)"
```
```  3669     unfolding c_def zeros_f_def w_def
```
```  3670     proof (rule argument_principle[OF \<open>open s\<close> \<open>connected s\<close> _ _ \<open>valid_path \<gamma>\<close> loop _ homo
```
```  3671         , of _ "{}" "\<lambda>_. 1",simplified])
```
```  3672       show "f holomorphic_on s" using f_holo g_holo holomorphic_on_add by auto
```
```  3673       show "path_image \<gamma> \<subseteq> s - {p. f p = 0}" using path_f unfolding zeros_f_def .
```
```  3674       show " finite {p. f p = 0}" using \<open>finite zeros_f\<close> unfolding zeros_f_def .
```
```  3675     qed
```
```  3676   ultimately have " c* (\<Sum>p\<in>zeros_fg. w p * (zorder fg p)) = c* (\<Sum>p\<in>zeros_f. w p * (zorder f p))"
```
```  3677     by auto
```
```  3678   then show ?thesis unfolding c_def using w_def by auto
```
```  3679 qed
```
```  3680
```
```  3681 end
```