src/HOL/Multivariate_Analysis/Complex_Analysis_Basics.thy
author wenzelm
Wed Dec 30 11:21:54 2015 +0100 (2015-12-30)
changeset 61973 0c7e865fa7cb
parent 61969 e01015e49041
child 61975 b4b11391c676
permissions -rw-r--r--
more symbols;
     1 (*  Author: John Harrison, Marco Maggesi, Graziano Gentili, Gianni Ciolli, Valentina Bruno
     2     Ported from "hol_light/Multivariate/canal.ml" by L C Paulson (2014)
     3 *)
     4 
     5 section \<open>Complex Analysis Basics\<close>
     6 
     7 theory Complex_Analysis_Basics
     8 imports Cartesian_Euclidean_Space
     9 begin
    10 
    11 
    12 lemma cmod_fact [simp]: "cmod (fact n) = fact n"
    13   by (metis norm_of_nat of_nat_fact)
    14 
    15 subsection\<open>General lemmas\<close>
    16 
    17 lemma has_derivative_mult_right:
    18   fixes c:: "'a :: real_normed_algebra"
    19   shows "((op * c) has_derivative (op * c)) F"
    20 by (rule has_derivative_mult_right [OF has_derivative_id])
    21 
    22 lemma has_derivative_of_real[derivative_intros, simp]:
    23   "(f has_derivative f') F \<Longrightarrow> ((\<lambda>x. of_real (f x)) has_derivative (\<lambda>x. of_real (f' x))) F"
    24   using bounded_linear.has_derivative[OF bounded_linear_of_real] .
    25 
    26 lemma has_vector_derivative_real_complex:
    27   "DERIV f (of_real a) :> f' \<Longrightarrow> ((\<lambda>x. f (of_real x)) has_vector_derivative f') (at a within s)"
    28   using has_derivative_compose[of of_real of_real a _ f "op * f'"]
    29   by (simp add: scaleR_conv_of_real ac_simps has_vector_derivative_def has_field_derivative_def)
    30 
    31 lemma fact_cancel:
    32   fixes c :: "'a::real_field"
    33   shows "of_nat (Suc n) * c / (fact (Suc n)) = c / (fact n)"
    34   by (simp add: of_nat_mult del: of_nat_Suc times_nat.simps)
    35 
    36 lemma bilinear_times:
    37   fixes c::"'a::real_algebra" shows "bilinear (\<lambda>x y::'a. x*y)"
    38   by (auto simp: bilinear_def distrib_left distrib_right intro!: linearI)
    39 
    40 lemma linear_cnj: "linear cnj"
    41   using bounded_linear.linear[OF bounded_linear_cnj] .
    42 
    43 lemma tendsto_Re_upper:
    44   assumes "~ (trivial_limit F)"
    45           "(f \<longlongrightarrow> l) F"
    46           "eventually (\<lambda>x. Re(f x) \<le> b) F"
    47     shows  "Re(l) \<le> b"
    48   by (metis assms tendsto_le [OF _ tendsto_const]  tendsto_Re)
    49 
    50 lemma tendsto_Re_lower:
    51   assumes "~ (trivial_limit F)"
    52           "(f \<longlongrightarrow> l) F"
    53           "eventually (\<lambda>x. b \<le> Re(f x)) F"
    54     shows  "b \<le> Re(l)"
    55   by (metis assms tendsto_le [OF _ _ tendsto_const]  tendsto_Re)
    56 
    57 lemma tendsto_Im_upper:
    58   assumes "~ (trivial_limit F)"
    59           "(f \<longlongrightarrow> l) F"
    60           "eventually (\<lambda>x. Im(f x) \<le> b) F"
    61     shows  "Im(l) \<le> b"
    62   by (metis assms tendsto_le [OF _ tendsto_const]  tendsto_Im)
    63 
    64 lemma tendsto_Im_lower:
    65   assumes "~ (trivial_limit F)"
    66           "(f \<longlongrightarrow> l) F"
    67           "eventually (\<lambda>x. b \<le> Im(f x)) F"
    68     shows  "b \<le> Im(l)"
    69   by (metis assms tendsto_le [OF _ _ tendsto_const]  tendsto_Im)
    70 
    71 lemma lambda_zero: "(\<lambda>h::'a::mult_zero. 0) = op * 0"
    72   by auto
    73 
    74 lemma lambda_one: "(\<lambda>x::'a::monoid_mult. x) = op * 1"
    75   by auto
    76 
    77 lemma continuous_mult_left:
    78   fixes c::"'a::real_normed_algebra"
    79   shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. c * f x)"
    80 by (rule continuous_mult [OF continuous_const])
    81 
    82 lemma continuous_mult_right:
    83   fixes c::"'a::real_normed_algebra"
    84   shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. f x * c)"
    85 by (rule continuous_mult [OF _ continuous_const])
    86 
    87 lemma continuous_on_mult_left:
    88   fixes c::"'a::real_normed_algebra"
    89   shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. c * f x)"
    90 by (rule continuous_on_mult [OF continuous_on_const])
    91 
    92 lemma continuous_on_mult_right:
    93   fixes c::"'a::real_normed_algebra"
    94   shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. f x * c)"
    95 by (rule continuous_on_mult [OF _ continuous_on_const])
    96 
    97 lemma uniformly_continuous_on_cmul_right [continuous_intros]:
    98   fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_algebra"
    99   shows "uniformly_continuous_on s f \<Longrightarrow> uniformly_continuous_on s (\<lambda>x. f x * c)"
   100   using bounded_linear.uniformly_continuous_on[OF bounded_linear_mult_left] .
   101 
   102 lemma uniformly_continuous_on_cmul_left[continuous_intros]:
   103   fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_algebra"
   104   assumes "uniformly_continuous_on s f"
   105     shows "uniformly_continuous_on s (\<lambda>x. c * f x)"
   106 by (metis assms bounded_linear.uniformly_continuous_on bounded_linear_mult_right)
   107 
   108 lemma continuous_within_norm_id [continuous_intros]: "continuous (at x within S) norm"
   109   by (rule continuous_norm [OF continuous_ident])
   110 
   111 lemma continuous_on_norm_id [continuous_intros]: "continuous_on S norm"
   112   by (intro continuous_on_id continuous_on_norm)
   113 
   114 subsection\<open>DERIV stuff\<close>
   115 
   116 lemma DERIV_zero_connected_constant:
   117   fixes f :: "'a::{real_normed_field,euclidean_space} \<Rightarrow> 'a"
   118   assumes "connected s"
   119       and "open s"
   120       and "finite k"
   121       and "continuous_on s f"
   122       and "\<forall>x\<in>(s - k). DERIV f x :> 0"
   123     obtains c where "\<And>x. x \<in> s \<Longrightarrow> f(x) = c"
   124 using has_derivative_zero_connected_constant [OF assms(1-4)] assms
   125 by (metis DERIV_const has_derivative_const Diff_iff at_within_open frechet_derivative_at has_field_derivative_def)
   126 
   127 lemma DERIV_zero_constant:
   128   fixes f :: "'a::{real_normed_field, real_inner} \<Rightarrow> 'a"
   129   shows    "\<lbrakk>convex s;
   130              \<And>x. x\<in>s \<Longrightarrow> (f has_field_derivative 0) (at x within s)\<rbrakk>
   131              \<Longrightarrow> \<exists>c. \<forall>x \<in> s. f(x) = c"
   132   by (auto simp: has_field_derivative_def lambda_zero intro: has_derivative_zero_constant)
   133 
   134 lemma DERIV_zero_unique:
   135   fixes f :: "'a::{real_normed_field, real_inner} \<Rightarrow> 'a"
   136   assumes "convex s"
   137       and d0: "\<And>x. x\<in>s \<Longrightarrow> (f has_field_derivative 0) (at x within s)"
   138       and "a \<in> s"
   139       and "x \<in> s"
   140     shows "f x = f a"
   141   by (rule has_derivative_zero_unique [OF assms(1) _ assms(4,3)])
   142      (metis d0 has_field_derivative_imp_has_derivative lambda_zero)
   143 
   144 lemma DERIV_zero_connected_unique:
   145   fixes f :: "'a::{real_normed_field, real_inner} \<Rightarrow> 'a"
   146   assumes "connected s"
   147       and "open s"
   148       and d0: "\<And>x. x\<in>s \<Longrightarrow> DERIV f x :> 0"
   149       and "a \<in> s"
   150       and "x \<in> s"
   151     shows "f x = f a"
   152     by (rule has_derivative_zero_unique_connected [OF assms(2,1) _ assms(5,4)])
   153        (metis has_field_derivative_def lambda_zero d0)
   154 
   155 lemma DERIV_transform_within:
   156   assumes "(f has_field_derivative f') (at a within s)"
   157       and "0 < d" "a \<in> s"
   158       and "\<And>x. x\<in>s \<Longrightarrow> dist x a < d \<Longrightarrow> f x = g x"
   159     shows "(g has_field_derivative f') (at a within s)"
   160   using assms unfolding has_field_derivative_def
   161   by (blast intro: has_derivative_transform_within)
   162 
   163 lemma DERIV_transform_within_open:
   164   assumes "DERIV f a :> f'"
   165       and "open s" "a \<in> s"
   166       and "\<And>x. x\<in>s \<Longrightarrow> f x = g x"
   167     shows "DERIV g a :> f'"
   168   using assms unfolding has_field_derivative_def
   169 by (metis has_derivative_transform_within_open)
   170 
   171 lemma DERIV_transform_at:
   172   assumes "DERIV f a :> f'"
   173       and "0 < d"
   174       and "\<And>x. dist x a < d \<Longrightarrow> f x = g x"
   175     shows "DERIV g a :> f'"
   176   by (blast intro: assms DERIV_transform_within)
   177 
   178 (*generalising DERIV_isconst_all, which requires type real (using the ordering)*)
   179 lemma DERIV_zero_UNIV_unique:
   180   fixes f :: "'a::{real_normed_field, real_inner} \<Rightarrow> 'a"
   181   shows "(\<And>x. DERIV f x :> 0) \<Longrightarrow> f x = f a"
   182 by (metis DERIV_zero_unique UNIV_I assms convex_UNIV)
   183 
   184 subsection \<open>Some limit theorems about real part of real series etc.\<close>
   185 
   186 (*MOVE? But not to Finite_Cartesian_Product*)
   187 lemma sums_vec_nth :
   188   assumes "f sums a"
   189   shows "(\<lambda>x. f x $ i) sums a $ i"
   190 using assms unfolding sums_def
   191 by (auto dest: tendsto_vec_nth [where i=i])
   192 
   193 lemma summable_vec_nth :
   194   assumes "summable f"
   195   shows "summable (\<lambda>x. f x $ i)"
   196 using assms unfolding summable_def
   197 by (blast intro: sums_vec_nth)
   198 
   199 subsection \<open>Complex number lemmas\<close>
   200 
   201 lemma
   202   shows open_halfspace_Re_lt: "open {z. Re(z) < b}"
   203     and open_halfspace_Re_gt: "open {z. Re(z) > b}"
   204     and closed_halfspace_Re_ge: "closed {z. Re(z) \<ge> b}"
   205     and closed_halfspace_Re_le: "closed {z. Re(z) \<le> b}"
   206     and closed_halfspace_Re_eq: "closed {z. Re(z) = b}"
   207     and open_halfspace_Im_lt: "open {z. Im(z) < b}"
   208     and open_halfspace_Im_gt: "open {z. Im(z) > b}"
   209     and closed_halfspace_Im_ge: "closed {z. Im(z) \<ge> b}"
   210     and closed_halfspace_Im_le: "closed {z. Im(z) \<le> b}"
   211     and closed_halfspace_Im_eq: "closed {z. Im(z) = b}"
   212   by (intro open_Collect_less closed_Collect_le closed_Collect_eq isCont_Re
   213             isCont_Im continuous_ident continuous_const)+
   214 
   215 lemma closed_complex_Reals: "closed (\<real> :: complex set)"
   216 proof -
   217   have "(\<real> :: complex set) = {z. Im z = 0}"
   218     by (auto simp: complex_is_Real_iff)
   219   then show ?thesis
   220     by (metis closed_halfspace_Im_eq)
   221 qed
   222 
   223 lemma closed_Real_halfspace_Re_le: "closed (\<real> \<inter> {w. Re w \<le> x})"
   224   by (simp add: closed_Int closed_complex_Reals closed_halfspace_Re_le)
   225 
   226 lemma closed_Real_halfspace_Re_ge: "closed (\<real> \<inter> {w. x \<le> Re(w)})"
   227   using closed_halfspace_Re_ge
   228   by (simp add: closed_Int closed_complex_Reals)
   229 
   230 lemma closed_real_abs_le: "closed {w \<in> \<real>. \<bar>Re w\<bar> \<le> r}"
   231 proof -
   232   have "{w \<in> \<real>. \<bar>Re w\<bar> \<le> r} = (\<real> \<inter> {w. Re w \<le> r}) \<inter> (\<real> \<inter> {w. Re w \<ge> -r})"
   233     by auto
   234   then show "closed {w \<in> \<real>. \<bar>Re w\<bar> \<le> r}"
   235     by (simp add: closed_Int closed_Real_halfspace_Re_ge closed_Real_halfspace_Re_le)
   236 qed
   237 
   238 lemma real_lim:
   239   fixes l::complex
   240   assumes "(f \<longlongrightarrow> l) F" and "~(trivial_limit F)" and "eventually P F" and "\<And>a. P a \<Longrightarrow> f a \<in> \<real>"
   241   shows  "l \<in> \<real>"
   242 proof (rule Lim_in_closed_set[OF closed_complex_Reals _ assms(2,1)])
   243   show "eventually (\<lambda>x. f x \<in> \<real>) F"
   244     using assms(3, 4) by (auto intro: eventually_mono)
   245 qed
   246 
   247 lemma real_lim_sequentially:
   248   fixes l::complex
   249   shows "(f \<longlongrightarrow> l) sequentially \<Longrightarrow> (\<exists>N. \<forall>n\<ge>N. f n \<in> \<real>) \<Longrightarrow> l \<in> \<real>"
   250 by (rule real_lim [where F=sequentially]) (auto simp: eventually_sequentially)
   251 
   252 lemma real_series:
   253   fixes l::complex
   254   shows "f sums l \<Longrightarrow> (\<And>n. f n \<in> \<real>) \<Longrightarrow> l \<in> \<real>"
   255 unfolding sums_def
   256 by (metis real_lim_sequentially setsum_in_Reals)
   257 
   258 lemma Lim_null_comparison_Re:
   259   assumes "eventually (\<lambda>x. norm(f x) \<le> Re(g x)) F" "(g \<longlongrightarrow> 0) F" shows "(f \<longlongrightarrow> 0) F"
   260   by (rule Lim_null_comparison[OF assms(1)] tendsto_eq_intros assms(2))+ simp
   261 
   262 subsection\<open>Holomorphic functions\<close>
   263 
   264 text{*Could be generalized to real normed fields, but in practice that would only include the reals*}
   265 definition complex_differentiable :: "[complex \<Rightarrow> complex, complex filter] \<Rightarrow> bool"
   266            (infixr "(complex'_differentiable)" 50)
   267   where "f complex_differentiable F \<equiv> \<exists>f'. (f has_field_derivative f') F"
   268 
   269 lemma complex_differentiable_imp_continuous_at:
   270     "f complex_differentiable (at x within s) \<Longrightarrow> continuous (at x within s) f"
   271   by (metis DERIV_continuous complex_differentiable_def)
   272 
   273 lemma complex_differentiable_within_subset:
   274     "\<lbrakk>f complex_differentiable (at x within s); t \<subseteq> s\<rbrakk>
   275      \<Longrightarrow> f complex_differentiable (at x within t)"
   276   by (metis DERIV_subset complex_differentiable_def)
   277 
   278 lemma complex_differentiable_at_within:
   279     "\<lbrakk>f complex_differentiable (at x)\<rbrakk>
   280      \<Longrightarrow> f complex_differentiable (at x within s)"
   281   unfolding complex_differentiable_def
   282   by (metis DERIV_subset top_greatest)
   283 
   284 lemma complex_differentiable_linear [derivative_intros]: "(op * c) complex_differentiable F"
   285 proof -
   286   show ?thesis
   287     unfolding complex_differentiable_def has_field_derivative_def mult_commute_abs
   288     by (force intro: has_derivative_mult_right)
   289 qed
   290 
   291 lemma complex_differentiable_const [derivative_intros]: "(\<lambda>z. c) complex_differentiable F"
   292   unfolding complex_differentiable_def has_field_derivative_def
   293   by (rule exI [where x=0])
   294      (metis has_derivative_const lambda_zero)
   295 
   296 lemma complex_differentiable_ident [derivative_intros]: "(\<lambda>z. z) complex_differentiable F"
   297   unfolding complex_differentiable_def has_field_derivative_def
   298   by (rule exI [where x=1])
   299      (simp add: lambda_one [symmetric])
   300 
   301 lemma complex_differentiable_id [derivative_intros]: "id complex_differentiable F"
   302   unfolding id_def by (rule complex_differentiable_ident)
   303 
   304 lemma complex_differentiable_minus [derivative_intros]:
   305   "f complex_differentiable F \<Longrightarrow> (\<lambda>z. - (f z)) complex_differentiable F"
   306   using assms unfolding complex_differentiable_def
   307   by (metis field_differentiable_minus)
   308 
   309 lemma complex_differentiable_add [derivative_intros]:
   310   assumes "f complex_differentiable F" "g complex_differentiable F"
   311     shows "(\<lambda>z. f z + g z) complex_differentiable F"
   312   using assms unfolding complex_differentiable_def
   313   by (metis field_differentiable_add)
   314 
   315 lemma complex_differentiable_setsum [derivative_intros]:
   316   "(\<And>i. i \<in> I \<Longrightarrow> (f i) complex_differentiable F) \<Longrightarrow> (\<lambda>z. \<Sum>i\<in>I. f i z) complex_differentiable F"
   317   by (induct I rule: infinite_finite_induct)
   318      (auto intro: complex_differentiable_add complex_differentiable_const)
   319 
   320 lemma complex_differentiable_diff [derivative_intros]:
   321   assumes "f complex_differentiable F" "g complex_differentiable F"
   322     shows "(\<lambda>z. f z - g z) complex_differentiable F"
   323   using assms unfolding complex_differentiable_def
   324   by (metis field_differentiable_diff)
   325 
   326 lemma complex_differentiable_inverse [derivative_intros]:
   327   assumes "f complex_differentiable (at a within s)" "f a \<noteq> 0"
   328   shows "(\<lambda>z. inverse (f z)) complex_differentiable (at a within s)"
   329   using assms unfolding complex_differentiable_def
   330   by (metis DERIV_inverse_fun)
   331 
   332 lemma complex_differentiable_mult [derivative_intros]:
   333   assumes "f complex_differentiable (at a within s)"
   334           "g complex_differentiable (at a within s)"
   335     shows "(\<lambda>z. f z * g z) complex_differentiable (at a within s)"
   336   using assms unfolding complex_differentiable_def
   337   by (metis DERIV_mult [of f _ a s g])
   338 
   339 lemma complex_differentiable_divide [derivative_intros]:
   340   assumes "f complex_differentiable (at a within s)"
   341           "g complex_differentiable (at a within s)"
   342           "g a \<noteq> 0"
   343     shows "(\<lambda>z. f z / g z) complex_differentiable (at a within s)"
   344   using assms unfolding complex_differentiable_def
   345   by (metis DERIV_divide [of f _ a s g])
   346 
   347 lemma complex_differentiable_power [derivative_intros]:
   348   assumes "f complex_differentiable (at a within s)"
   349     shows "(\<lambda>z. f z ^ n) complex_differentiable (at a within s)"
   350   using assms unfolding complex_differentiable_def
   351   by (metis DERIV_power)
   352 
   353 lemma complex_differentiable_transform_within:
   354   "0 < d \<Longrightarrow>
   355         x \<in> s \<Longrightarrow>
   356         (\<And>x'. x' \<in> s \<Longrightarrow> dist x' x < d \<Longrightarrow> f x' = g x') \<Longrightarrow>
   357         f complex_differentiable (at x within s)
   358         \<Longrightarrow> g complex_differentiable (at x within s)"
   359   unfolding complex_differentiable_def has_field_derivative_def
   360   by (blast intro: has_derivative_transform_within)
   361 
   362 lemma complex_differentiable_compose_within:
   363   assumes "f complex_differentiable (at a within s)"
   364           "g complex_differentiable (at (f a) within f`s)"
   365     shows "(g o f) complex_differentiable (at a within s)"
   366   using assms unfolding complex_differentiable_def
   367   by (metis DERIV_image_chain)
   368 
   369 lemma complex_differentiable_compose:
   370   "f complex_differentiable at z \<Longrightarrow> g complex_differentiable at (f z)
   371           \<Longrightarrow> (g o f) complex_differentiable at z"
   372 by (metis complex_differentiable_at_within complex_differentiable_compose_within)
   373 
   374 lemma complex_differentiable_within_open:
   375      "\<lbrakk>a \<in> s; open s\<rbrakk> \<Longrightarrow> f complex_differentiable at a within s \<longleftrightarrow>
   376                           f complex_differentiable at a"
   377   unfolding complex_differentiable_def
   378   by (metis at_within_open)
   379 
   380 subsection\<open>Caratheodory characterization.\<close>
   381 
   382 lemma complex_differentiable_caratheodory_at:
   383   "f complex_differentiable (at z) \<longleftrightarrow>
   384          (\<exists>g. (\<forall>w. f(w) - f(z) = g(w) * (w - z)) \<and> continuous (at z) g)"
   385   using CARAT_DERIV [of f]
   386   by (simp add: complex_differentiable_def has_field_derivative_def)
   387 
   388 lemma complex_differentiable_caratheodory_within:
   389   "f complex_differentiable (at z within s) \<longleftrightarrow>
   390          (\<exists>g. (\<forall>w. f(w) - f(z) = g(w) * (w - z)) \<and> continuous (at z within s) g)"
   391   using DERIV_caratheodory_within [of f]
   392   by (simp add: complex_differentiable_def has_field_derivative_def)
   393 
   394 subsection\<open>Holomorphic\<close>
   395 
   396 definition holomorphic_on :: "[complex \<Rightarrow> complex, complex set] \<Rightarrow> bool"
   397            (infixl "(holomorphic'_on)" 50)
   398   where "f holomorphic_on s \<equiv> \<forall>x\<in>s. f complex_differentiable (at x within s)"
   399 
   400 named_theorems holomorphic_intros "structural introduction rules for holomorphic_on"
   401 
   402 lemma holomorphic_on_empty [holomorphic_intros]: "f holomorphic_on {}"
   403   by (simp add: holomorphic_on_def)
   404 
   405 lemma holomorphic_on_open:
   406     "open s \<Longrightarrow> f holomorphic_on s \<longleftrightarrow> (\<forall>x \<in> s. \<exists>f'. DERIV f x :> f')"
   407   by (auto simp: holomorphic_on_def complex_differentiable_def has_field_derivative_def at_within_open [of _ s])
   408 
   409 lemma holomorphic_on_imp_continuous_on:
   410     "f holomorphic_on s \<Longrightarrow> continuous_on s f"
   411   by (metis complex_differentiable_imp_continuous_at continuous_on_eq_continuous_within holomorphic_on_def)
   412 
   413 lemma holomorphic_on_subset:
   414     "f holomorphic_on s \<Longrightarrow> t \<subseteq> s \<Longrightarrow> f holomorphic_on t"
   415   unfolding holomorphic_on_def
   416   by (metis complex_differentiable_within_subset subsetD)
   417 
   418 lemma holomorphic_transform: "\<lbrakk>f holomorphic_on s; \<And>x. x \<in> s \<Longrightarrow> f x = g x\<rbrakk> \<Longrightarrow> g holomorphic_on s"
   419   by (metis complex_differentiable_transform_within linordered_field_no_ub holomorphic_on_def)
   420 
   421 lemma holomorphic_cong: "s = t ==> (\<And>x. x \<in> s \<Longrightarrow> f x = g x) \<Longrightarrow> f holomorphic_on s \<longleftrightarrow> g holomorphic_on t"
   422   by (metis holomorphic_transform)
   423 
   424 lemma holomorphic_on_linear [holomorphic_intros]: "(op * c) holomorphic_on s"
   425   unfolding holomorphic_on_def by (metis complex_differentiable_linear)
   426 
   427 lemma holomorphic_on_const [holomorphic_intros]: "(\<lambda>z. c) holomorphic_on s"
   428   unfolding holomorphic_on_def by (metis complex_differentiable_const)
   429 
   430 lemma holomorphic_on_ident [holomorphic_intros]: "(\<lambda>x. x) holomorphic_on s"
   431   unfolding holomorphic_on_def by (metis complex_differentiable_ident)
   432 
   433 lemma holomorphic_on_id [holomorphic_intros]: "id holomorphic_on s"
   434   unfolding id_def by (rule holomorphic_on_ident)
   435 
   436 lemma holomorphic_on_compose:
   437   "f holomorphic_on s \<Longrightarrow> g holomorphic_on (f ` s) \<Longrightarrow> (g o f) holomorphic_on s"
   438   using complex_differentiable_compose_within[of f _ s g]
   439   by (auto simp: holomorphic_on_def)
   440 
   441 lemma holomorphic_on_compose_gen:
   442   "f holomorphic_on s \<Longrightarrow> g holomorphic_on t \<Longrightarrow> f ` s \<subseteq> t \<Longrightarrow> (g o f) holomorphic_on s"
   443   by (metis holomorphic_on_compose holomorphic_on_subset)
   444 
   445 lemma holomorphic_on_minus [holomorphic_intros]: "f holomorphic_on s \<Longrightarrow> (\<lambda>z. -(f z)) holomorphic_on s"
   446   by (metis complex_differentiable_minus holomorphic_on_def)
   447 
   448 lemma holomorphic_on_add [holomorphic_intros]:
   449   "\<lbrakk>f holomorphic_on s; g holomorphic_on s\<rbrakk> \<Longrightarrow> (\<lambda>z. f z + g z) holomorphic_on s"
   450   unfolding holomorphic_on_def by (metis complex_differentiable_add)
   451 
   452 lemma holomorphic_on_diff [holomorphic_intros]:
   453   "\<lbrakk>f holomorphic_on s; g holomorphic_on s\<rbrakk> \<Longrightarrow> (\<lambda>z. f z - g z) holomorphic_on s"
   454   unfolding holomorphic_on_def by (metis complex_differentiable_diff)
   455 
   456 lemma holomorphic_on_mult [holomorphic_intros]:
   457   "\<lbrakk>f holomorphic_on s; g holomorphic_on s\<rbrakk> \<Longrightarrow> (\<lambda>z. f z * g z) holomorphic_on s"
   458   unfolding holomorphic_on_def by (metis complex_differentiable_mult)
   459 
   460 lemma holomorphic_on_inverse [holomorphic_intros]:
   461   "\<lbrakk>f holomorphic_on s; \<And>z. z \<in> s \<Longrightarrow> f z \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>z. inverse (f z)) holomorphic_on s"
   462   unfolding holomorphic_on_def by (metis complex_differentiable_inverse)
   463 
   464 lemma holomorphic_on_divide [holomorphic_intros]:
   465   "\<lbrakk>f holomorphic_on s; g holomorphic_on s; \<And>z. z \<in> s \<Longrightarrow> g z \<noteq> 0\<rbrakk> \<Longrightarrow> (\<lambda>z. f z / g z) holomorphic_on s"
   466   unfolding holomorphic_on_def by (metis complex_differentiable_divide)
   467 
   468 lemma holomorphic_on_power [holomorphic_intros]:
   469   "f holomorphic_on s \<Longrightarrow> (\<lambda>z. (f z)^n) holomorphic_on s"
   470   unfolding holomorphic_on_def by (metis complex_differentiable_power)
   471 
   472 lemma holomorphic_on_setsum [holomorphic_intros]:
   473   "(\<And>i. i \<in> I \<Longrightarrow> (f i) holomorphic_on s) \<Longrightarrow> (\<lambda>x. setsum (\<lambda>i. f i x) I) holomorphic_on s"
   474   unfolding holomorphic_on_def by (metis complex_differentiable_setsum)
   475 
   476 lemma DERIV_deriv_iff_complex_differentiable:
   477   "DERIV f x :> deriv f x \<longleftrightarrow> f complex_differentiable at x"
   478   unfolding complex_differentiable_def by (metis DERIV_imp_deriv)
   479 
   480 lemma complex_derivative_chain:
   481   "f complex_differentiable at x \<Longrightarrow> g complex_differentiable at (f x)
   482     \<Longrightarrow> deriv (g o f) x = deriv g (f x) * deriv f x"
   483   by (metis DERIV_deriv_iff_complex_differentiable DERIV_chain DERIV_imp_deriv)
   484 
   485 lemma deriv_linear: "deriv (\<lambda>w. c * w) = (\<lambda>z. c)"
   486   by (metis DERIV_imp_deriv DERIV_cmult_Id)
   487 
   488 lemma deriv_ident: "deriv (\<lambda>w. w) = (\<lambda>z. 1)"
   489   by (metis DERIV_imp_deriv DERIV_ident)
   490 
   491 lemma deriv_const: "deriv (\<lambda>w. c) = (\<lambda>z. 0)"
   492   by (metis DERIV_imp_deriv DERIV_const)
   493 
   494 lemma complex_derivative_add:
   495   "\<lbrakk>f complex_differentiable at z; g complex_differentiable at z\<rbrakk>
   496    \<Longrightarrow> deriv (\<lambda>w. f w + g w) z = deriv f z + deriv g z"
   497   unfolding DERIV_deriv_iff_complex_differentiable[symmetric]
   498   by (auto intro!: DERIV_imp_deriv derivative_intros)
   499 
   500 lemma complex_derivative_diff:
   501   "\<lbrakk>f complex_differentiable at z; g complex_differentiable at z\<rbrakk>
   502    \<Longrightarrow> deriv (\<lambda>w. f w - g w) z = deriv f z - deriv g z"
   503   unfolding DERIV_deriv_iff_complex_differentiable[symmetric]
   504   by (auto intro!: DERIV_imp_deriv derivative_intros)
   505 
   506 lemma complex_derivative_mult:
   507   "\<lbrakk>f complex_differentiable at z; g complex_differentiable at z\<rbrakk>
   508    \<Longrightarrow> deriv (\<lambda>w. f w * g w) z = f z * deriv g z + deriv f z * g z"
   509   unfolding DERIV_deriv_iff_complex_differentiable[symmetric]
   510   by (auto intro!: DERIV_imp_deriv derivative_eq_intros)
   511 
   512 lemma complex_derivative_cmult:
   513   "f complex_differentiable at z \<Longrightarrow> deriv (\<lambda>w. c * f w) z = c * deriv f z"
   514   unfolding DERIV_deriv_iff_complex_differentiable[symmetric]
   515   by (auto intro!: DERIV_imp_deriv derivative_eq_intros)
   516 
   517 lemma complex_derivative_cmult_right:
   518   "f complex_differentiable at z \<Longrightarrow> deriv (\<lambda>w. f w * c) z = deriv f z * c"
   519   unfolding DERIV_deriv_iff_complex_differentiable[symmetric]
   520   by (auto intro!: DERIV_imp_deriv derivative_eq_intros)
   521 
   522 lemma complex_derivative_transform_within_open:
   523   "\<lbrakk>f holomorphic_on s; g holomorphic_on s; open s; z \<in> s; \<And>w. w \<in> s \<Longrightarrow> f w = g w\<rbrakk>
   524    \<Longrightarrow> deriv f z = deriv g z"
   525   unfolding holomorphic_on_def
   526   by (rule DERIV_imp_deriv)
   527      (metis DERIV_deriv_iff_complex_differentiable DERIV_transform_within_open at_within_open)
   528 
   529 lemma complex_derivative_compose_linear:
   530   "f complex_differentiable at (c * z) \<Longrightarrow> deriv (\<lambda>w. f (c * w)) z = c * deriv f (c * z)"
   531 apply (rule DERIV_imp_deriv)
   532 apply (simp add: DERIV_deriv_iff_complex_differentiable [symmetric])
   533 apply (drule DERIV_chain' [of "times c" c z UNIV f "deriv f (c * z)", OF DERIV_cmult_Id])
   534 apply (simp add: algebra_simps)
   535 done
   536 
   537 subsection\<open>Analyticity on a set\<close>
   538 
   539 definition analytic_on (infixl "(analytic'_on)" 50)
   540   where
   541    "f analytic_on s \<equiv> \<forall>x \<in> s. \<exists>e. 0 < e \<and> f holomorphic_on (ball x e)"
   542 
   543 lemma analytic_imp_holomorphic: "f analytic_on s \<Longrightarrow> f holomorphic_on s"
   544   by (simp add: at_within_open [OF _ open_ball] analytic_on_def holomorphic_on_def)
   545      (metis centre_in_ball complex_differentiable_at_within)
   546 
   547 lemma analytic_on_open: "open s \<Longrightarrow> f analytic_on s \<longleftrightarrow> f holomorphic_on s"
   548 apply (auto simp: analytic_imp_holomorphic)
   549 apply (auto simp: analytic_on_def holomorphic_on_def)
   550 by (metis holomorphic_on_def holomorphic_on_subset open_contains_ball)
   551 
   552 lemma analytic_on_imp_differentiable_at:
   553   "f analytic_on s \<Longrightarrow> x \<in> s \<Longrightarrow> f complex_differentiable (at x)"
   554  apply (auto simp: analytic_on_def holomorphic_on_def)
   555 by (metis Topology_Euclidean_Space.open_ball centre_in_ball complex_differentiable_within_open)
   556 
   557 lemma analytic_on_subset: "f analytic_on s \<Longrightarrow> t \<subseteq> s \<Longrightarrow> f analytic_on t"
   558   by (auto simp: analytic_on_def)
   559 
   560 lemma analytic_on_Un: "f analytic_on (s \<union> t) \<longleftrightarrow> f analytic_on s \<and> f analytic_on t"
   561   by (auto simp: analytic_on_def)
   562 
   563 lemma analytic_on_Union: "f analytic_on (\<Union>s) \<longleftrightarrow> (\<forall>t \<in> s. f analytic_on t)"
   564   by (auto simp: analytic_on_def)
   565 
   566 lemma analytic_on_UN: "f analytic_on (\<Union>i\<in>I. s i) \<longleftrightarrow> (\<forall>i\<in>I. f analytic_on (s i))"
   567   by (auto simp: analytic_on_def)
   568 
   569 lemma analytic_on_holomorphic:
   570   "f analytic_on s \<longleftrightarrow> (\<exists>t. open t \<and> s \<subseteq> t \<and> f holomorphic_on t)"
   571   (is "?lhs = ?rhs")
   572 proof -
   573   have "?lhs \<longleftrightarrow> (\<exists>t. open t \<and> s \<subseteq> t \<and> f analytic_on t)"
   574   proof safe
   575     assume "f analytic_on s"
   576     then show "\<exists>t. open t \<and> s \<subseteq> t \<and> f analytic_on t"
   577       apply (simp add: analytic_on_def)
   578       apply (rule exI [where x="\<Union>{u. open u \<and> f analytic_on u}"], auto)
   579       apply (metis Topology_Euclidean_Space.open_ball analytic_on_open centre_in_ball)
   580       by (metis analytic_on_def)
   581   next
   582     fix t
   583     assume "open t" "s \<subseteq> t" "f analytic_on t"
   584     then show "f analytic_on s"
   585         by (metis analytic_on_subset)
   586   qed
   587   also have "... \<longleftrightarrow> ?rhs"
   588     by (auto simp: analytic_on_open)
   589   finally show ?thesis .
   590 qed
   591 
   592 lemma analytic_on_linear: "(op * c) analytic_on s"
   593   by (auto simp add: analytic_on_holomorphic holomorphic_on_linear)
   594 
   595 lemma analytic_on_const: "(\<lambda>z. c) analytic_on s"
   596   by (metis analytic_on_def holomorphic_on_const zero_less_one)
   597 
   598 lemma analytic_on_ident: "(\<lambda>x. x) analytic_on s"
   599   by (simp add: analytic_on_def holomorphic_on_ident gt_ex)
   600 
   601 lemma analytic_on_id: "id analytic_on s"
   602   unfolding id_def by (rule analytic_on_ident)
   603 
   604 lemma analytic_on_compose:
   605   assumes f: "f analytic_on s"
   606       and g: "g analytic_on (f ` s)"
   607     shows "(g o f) analytic_on s"
   608 unfolding analytic_on_def
   609 proof (intro ballI)
   610   fix x
   611   assume x: "x \<in> s"
   612   then obtain e where e: "0 < e" and fh: "f holomorphic_on ball x e" using f
   613     by (metis analytic_on_def)
   614   obtain e' where e': "0 < e'" and gh: "g holomorphic_on ball (f x) e'" using g
   615     by (metis analytic_on_def g image_eqI x)
   616   have "isCont f x"
   617     by (metis analytic_on_imp_differentiable_at complex_differentiable_imp_continuous_at f x)
   618   with e' obtain d where d: "0 < d" and fd: "f ` ball x d \<subseteq> ball (f x) e'"
   619      by (auto simp: continuous_at_ball)
   620   have "g \<circ> f holomorphic_on ball x (min d e)"
   621     apply (rule holomorphic_on_compose)
   622     apply (metis fh holomorphic_on_subset min.bounded_iff order_refl subset_ball)
   623     by (metis fd gh holomorphic_on_subset image_mono min.cobounded1 subset_ball)
   624   then show "\<exists>e>0. g \<circ> f holomorphic_on ball x e"
   625     by (metis d e min_less_iff_conj)
   626 qed
   627 
   628 lemma analytic_on_compose_gen:
   629   "f analytic_on s \<Longrightarrow> g analytic_on t \<Longrightarrow> (\<And>z. z \<in> s \<Longrightarrow> f z \<in> t)
   630              \<Longrightarrow> g o f analytic_on s"
   631 by (metis analytic_on_compose analytic_on_subset image_subset_iff)
   632 
   633 lemma analytic_on_neg:
   634   "f analytic_on s \<Longrightarrow> (\<lambda>z. -(f z)) analytic_on s"
   635 by (metis analytic_on_holomorphic holomorphic_on_minus)
   636 
   637 lemma analytic_on_add:
   638   assumes f: "f analytic_on s"
   639       and g: "g analytic_on s"
   640     shows "(\<lambda>z. f z + g z) analytic_on s"
   641 unfolding analytic_on_def
   642 proof (intro ballI)
   643   fix z
   644   assume z: "z \<in> s"
   645   then obtain e where e: "0 < e" and fh: "f holomorphic_on ball z e" using f
   646     by (metis analytic_on_def)
   647   obtain e' where e': "0 < e'" and gh: "g holomorphic_on ball z e'" using g
   648     by (metis analytic_on_def g z)
   649   have "(\<lambda>z. f z + g z) holomorphic_on ball z (min e e')"
   650     apply (rule holomorphic_on_add)
   651     apply (metis fh holomorphic_on_subset min.bounded_iff order_refl subset_ball)
   652     by (metis gh holomorphic_on_subset min.bounded_iff order_refl subset_ball)
   653   then show "\<exists>e>0. (\<lambda>z. f z + g z) holomorphic_on ball z e"
   654     by (metis e e' min_less_iff_conj)
   655 qed
   656 
   657 lemma analytic_on_diff:
   658   assumes f: "f analytic_on s"
   659       and g: "g analytic_on s"
   660     shows "(\<lambda>z. f z - g z) analytic_on s"
   661 unfolding analytic_on_def
   662 proof (intro ballI)
   663   fix z
   664   assume z: "z \<in> s"
   665   then obtain e where e: "0 < e" and fh: "f holomorphic_on ball z e" using f
   666     by (metis analytic_on_def)
   667   obtain e' where e': "0 < e'" and gh: "g holomorphic_on ball z e'" using g
   668     by (metis analytic_on_def g z)
   669   have "(\<lambda>z. f z - g z) holomorphic_on ball z (min e e')"
   670     apply (rule holomorphic_on_diff)
   671     apply (metis fh holomorphic_on_subset min.bounded_iff order_refl subset_ball)
   672     by (metis gh holomorphic_on_subset min.bounded_iff order_refl subset_ball)
   673   then show "\<exists>e>0. (\<lambda>z. f z - g z) holomorphic_on ball z e"
   674     by (metis e e' min_less_iff_conj)
   675 qed
   676 
   677 lemma analytic_on_mult:
   678   assumes f: "f analytic_on s"
   679       and g: "g analytic_on s"
   680     shows "(\<lambda>z. f z * g z) analytic_on s"
   681 unfolding analytic_on_def
   682 proof (intro ballI)
   683   fix z
   684   assume z: "z \<in> s"
   685   then obtain e where e: "0 < e" and fh: "f holomorphic_on ball z e" using f
   686     by (metis analytic_on_def)
   687   obtain e' where e': "0 < e'" and gh: "g holomorphic_on ball z e'" using g
   688     by (metis analytic_on_def g z)
   689   have "(\<lambda>z. f z * g z) holomorphic_on ball z (min e e')"
   690     apply (rule holomorphic_on_mult)
   691     apply (metis fh holomorphic_on_subset min.bounded_iff order_refl subset_ball)
   692     by (metis gh holomorphic_on_subset min.bounded_iff order_refl subset_ball)
   693   then show "\<exists>e>0. (\<lambda>z. f z * g z) holomorphic_on ball z e"
   694     by (metis e e' min_less_iff_conj)
   695 qed
   696 
   697 lemma analytic_on_inverse:
   698   assumes f: "f analytic_on s"
   699       and nz: "(\<And>z. z \<in> s \<Longrightarrow> f z \<noteq> 0)"
   700     shows "(\<lambda>z. inverse (f z)) analytic_on s"
   701 unfolding analytic_on_def
   702 proof (intro ballI)
   703   fix z
   704   assume z: "z \<in> s"
   705   then obtain e where e: "0 < e" and fh: "f holomorphic_on ball z e" using f
   706     by (metis analytic_on_def)
   707   have "continuous_on (ball z e) f"
   708     by (metis fh holomorphic_on_imp_continuous_on)
   709   then obtain e' where e': "0 < e'" and nz': "\<And>y. dist z y < e' \<Longrightarrow> f y \<noteq> 0"
   710     by (metis Topology_Euclidean_Space.open_ball centre_in_ball continuous_on_open_avoid e z nz)
   711   have "(\<lambda>z. inverse (f z)) holomorphic_on ball z (min e e')"
   712     apply (rule holomorphic_on_inverse)
   713     apply (metis fh holomorphic_on_subset min.cobounded2 min.commute subset_ball)
   714     by (metis nz' mem_ball min_less_iff_conj)
   715   then show "\<exists>e>0. (\<lambda>z. inverse (f z)) holomorphic_on ball z e"
   716     by (metis e e' min_less_iff_conj)
   717 qed
   718 
   719 
   720 lemma analytic_on_divide:
   721   assumes f: "f analytic_on s"
   722       and g: "g analytic_on s"
   723       and nz: "(\<And>z. z \<in> s \<Longrightarrow> g z \<noteq> 0)"
   724     shows "(\<lambda>z. f z / g z) analytic_on s"
   725 unfolding divide_inverse
   726 by (metis analytic_on_inverse analytic_on_mult f g nz)
   727 
   728 lemma analytic_on_power:
   729   "f analytic_on s \<Longrightarrow> (\<lambda>z. (f z) ^ n) analytic_on s"
   730 by (induct n) (auto simp: analytic_on_const analytic_on_mult)
   731 
   732 lemma analytic_on_setsum:
   733   "(\<And>i. i \<in> I \<Longrightarrow> (f i) analytic_on s) \<Longrightarrow> (\<lambda>x. setsum (\<lambda>i. f i x) I) analytic_on s"
   734   by (induct I rule: infinite_finite_induct) (auto simp: analytic_on_const analytic_on_add)
   735 
   736 subsection\<open>analyticity at a point.\<close>
   737 
   738 lemma analytic_at_ball:
   739   "f analytic_on {z} \<longleftrightarrow> (\<exists>e. 0<e \<and> f holomorphic_on ball z e)"
   740 by (metis analytic_on_def singleton_iff)
   741 
   742 lemma analytic_at:
   743     "f analytic_on {z} \<longleftrightarrow> (\<exists>s. open s \<and> z \<in> s \<and> f holomorphic_on s)"
   744 by (metis analytic_on_holomorphic empty_subsetI insert_subset)
   745 
   746 lemma analytic_on_analytic_at:
   747     "f analytic_on s \<longleftrightarrow> (\<forall>z \<in> s. f analytic_on {z})"
   748 by (metis analytic_at_ball analytic_on_def)
   749 
   750 lemma analytic_at_two:
   751   "f analytic_on {z} \<and> g analytic_on {z} \<longleftrightarrow>
   752    (\<exists>s. open s \<and> z \<in> s \<and> f holomorphic_on s \<and> g holomorphic_on s)"
   753   (is "?lhs = ?rhs")
   754 proof
   755   assume ?lhs
   756   then obtain s t
   757     where st: "open s" "z \<in> s" "f holomorphic_on s"
   758               "open t" "z \<in> t" "g holomorphic_on t"
   759     by (auto simp: analytic_at)
   760   show ?rhs
   761     apply (rule_tac x="s \<inter> t" in exI)
   762     using st
   763     apply (auto simp: Diff_subset holomorphic_on_subset)
   764     done
   765 next
   766   assume ?rhs
   767   then show ?lhs
   768     by (force simp add: analytic_at)
   769 qed
   770 
   771 subsection\<open>Combining theorems for derivative with ``analytic at'' hypotheses\<close>
   772 
   773 lemma
   774   assumes "f analytic_on {z}" "g analytic_on {z}"
   775   shows complex_derivative_add_at: "deriv (\<lambda>w. f w + g w) z = deriv f z + deriv g z"
   776     and complex_derivative_diff_at: "deriv (\<lambda>w. f w - g w) z = deriv f z - deriv g z"
   777     and complex_derivative_mult_at: "deriv (\<lambda>w. f w * g w) z =
   778            f z * deriv g z + deriv f z * g z"
   779 proof -
   780   obtain s where s: "open s" "z \<in> s" "f holomorphic_on s" "g holomorphic_on s"
   781     using assms by (metis analytic_at_two)
   782   show "deriv (\<lambda>w. f w + g w) z = deriv f z + deriv g z"
   783     apply (rule DERIV_imp_deriv [OF DERIV_add])
   784     using s
   785     apply (auto simp: holomorphic_on_open complex_differentiable_def DERIV_deriv_iff_complex_differentiable)
   786     done
   787   show "deriv (\<lambda>w. f w - g w) z = deriv f z - deriv g z"
   788     apply (rule DERIV_imp_deriv [OF DERIV_diff])
   789     using s
   790     apply (auto simp: holomorphic_on_open complex_differentiable_def DERIV_deriv_iff_complex_differentiable)
   791     done
   792   show "deriv (\<lambda>w. f w * g w) z = f z * deriv g z + deriv f z * g z"
   793     apply (rule DERIV_imp_deriv [OF DERIV_mult'])
   794     using s
   795     apply (auto simp: holomorphic_on_open complex_differentiable_def DERIV_deriv_iff_complex_differentiable)
   796     done
   797 qed
   798 
   799 lemma complex_derivative_cmult_at:
   800   "f analytic_on {z} \<Longrightarrow>  deriv (\<lambda>w. c * f w) z = c * deriv f z"
   801 by (auto simp: complex_derivative_mult_at deriv_const analytic_on_const)
   802 
   803 lemma complex_derivative_cmult_right_at:
   804   "f analytic_on {z} \<Longrightarrow>  deriv (\<lambda>w. f w * c) z = deriv f z * c"
   805 by (auto simp: complex_derivative_mult_at deriv_const analytic_on_const)
   806 
   807 subsection\<open>Complex differentiation of sequences and series\<close>
   808 
   809 (* TODO: Could probably be simplified using Uniform_Limit *)
   810 lemma has_complex_derivative_sequence:
   811   fixes s :: "complex set"
   812   assumes cvs: "convex s"
   813       and df:  "\<And>n x. x \<in> s \<Longrightarrow> (f n has_field_derivative f' n x) (at x within s)"
   814       and conv: "\<And>e. 0 < e \<Longrightarrow> \<exists>N. \<forall>n x. n \<ge> N \<longrightarrow> x \<in> s \<longrightarrow> norm (f' n x - g' x) \<le> e"
   815       and "\<exists>x l. x \<in> s \<and> ((\<lambda>n. f n x) \<longlongrightarrow> l) sequentially"
   816     shows "\<exists>g. \<forall>x \<in> s. ((\<lambda>n. f n x) \<longlongrightarrow> g x) sequentially \<and>
   817                        (g has_field_derivative (g' x)) (at x within s)"
   818 proof -
   819   from assms obtain x l where x: "x \<in> s" and tf: "((\<lambda>n. f n x) \<longlongrightarrow> l) sequentially"
   820     by blast
   821   { fix e::real assume e: "e > 0"
   822     then obtain N where N: "\<forall>n\<ge>N. \<forall>x. x \<in> s \<longrightarrow> cmod (f' n x - g' x) \<le> e"
   823       by (metis conv)
   824     have "\<exists>N. \<forall>n\<ge>N. \<forall>x\<in>s. \<forall>h. cmod (f' n x * h - g' x * h) \<le> e * cmod h"
   825     proof (rule exI [of _ N], clarify)
   826       fix n y h
   827       assume "N \<le> n" "y \<in> s"
   828       then have "cmod (f' n y - g' y) \<le> e"
   829         by (metis N)
   830       then have "cmod h * cmod (f' n y - g' y) \<le> cmod h * e"
   831         by (auto simp: antisym_conv2 mult_le_cancel_left norm_triangle_ineq2)
   832       then show "cmod (f' n y * h - g' y * h) \<le> e * cmod h"
   833         by (simp add: norm_mult [symmetric] field_simps)
   834     qed
   835   } note ** = this
   836   show ?thesis
   837   unfolding has_field_derivative_def
   838   proof (rule has_derivative_sequence [OF cvs _ _ x])
   839     show "\<forall>n. \<forall>x\<in>s. (f n has_derivative (op * (f' n x))) (at x within s)"
   840       by (metis has_field_derivative_def df)
   841   next show "(\<lambda>n. f n x) \<longlonglongrightarrow> l"
   842     by (rule tf)
   843   next show "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. \<forall>x\<in>s. \<forall>h. cmod (f' n x * h - g' x * h) \<le> e * cmod h"
   844     by (blast intro: **)
   845   qed
   846 qed
   847 
   848 
   849 lemma has_complex_derivative_series:
   850   fixes s :: "complex set"
   851   assumes cvs: "convex s"
   852       and df:  "\<And>n x. x \<in> s \<Longrightarrow> (f n has_field_derivative f' n x) (at x within s)"
   853       and conv: "\<And>e. 0 < e \<Longrightarrow> \<exists>N. \<forall>n x. n \<ge> N \<longrightarrow> x \<in> s
   854                 \<longrightarrow> cmod ((\<Sum>i<n. f' i x) - g' x) \<le> e"
   855       and "\<exists>x l. x \<in> s \<and> ((\<lambda>n. f n x) sums l)"
   856     shows "\<exists>g. \<forall>x \<in> s. ((\<lambda>n. f n x) sums g x) \<and> ((g has_field_derivative g' x) (at x within s))"
   857 proof -
   858   from assms obtain x l where x: "x \<in> s" and sf: "((\<lambda>n. f n x) sums l)"
   859     by blast
   860   { fix e::real assume e: "e > 0"
   861     then obtain N where N: "\<forall>n x. n \<ge> N \<longrightarrow> x \<in> s
   862             \<longrightarrow> cmod ((\<Sum>i<n. f' i x) - g' x) \<le> e"
   863       by (metis conv)
   864     have "\<exists>N. \<forall>n\<ge>N. \<forall>x\<in>s. \<forall>h. cmod ((\<Sum>i<n. h * f' i x) - g' x * h) \<le> e * cmod h"
   865     proof (rule exI [of _ N], clarify)
   866       fix n y h
   867       assume "N \<le> n" "y \<in> s"
   868       then have "cmod ((\<Sum>i<n. f' i y) - g' y) \<le> e"
   869         by (metis N)
   870       then have "cmod h * cmod ((\<Sum>i<n. f' i y) - g' y) \<le> cmod h * e"
   871         by (auto simp: antisym_conv2 mult_le_cancel_left norm_triangle_ineq2)
   872       then show "cmod ((\<Sum>i<n. h * f' i y) - g' y * h) \<le> e * cmod h"
   873         by (simp add: norm_mult [symmetric] field_simps setsum_right_distrib)
   874     qed
   875   } note ** = this
   876   show ?thesis
   877   unfolding has_field_derivative_def
   878   proof (rule has_derivative_series [OF cvs _ _ x])
   879     fix n x
   880     assume "x \<in> s"
   881     then show "((f n) has_derivative (\<lambda>z. z * f' n x)) (at x within s)"
   882       by (metis df has_field_derivative_def mult_commute_abs)
   883   next show " ((\<lambda>n. f n x) sums l)"
   884     by (rule sf)
   885   next show "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. \<forall>x\<in>s. \<forall>h. cmod ((\<Sum>i<n. h * f' i x) - g' x * h) \<le> e * cmod h"
   886     by (blast intro: **)
   887   qed
   888 qed
   889 
   890 
   891 lemma complex_differentiable_series:
   892   fixes f :: "nat \<Rightarrow> complex \<Rightarrow> complex"
   893   assumes "convex s" "open s"
   894   assumes "\<And>n x. x \<in> s \<Longrightarrow> (f n has_field_derivative f' n x) (at x)"
   895   assumes "uniformly_convergent_on s (\<lambda>n x. \<Sum>i<n. f' i x)"
   896   assumes "x0 \<in> s" "summable (\<lambda>n. f n x0)" and x: "x \<in> s"
   897   shows   "summable (\<lambda>n. f n x)" and "(\<lambda>x. \<Sum>n. f n x) complex_differentiable (at x)"
   898 proof -
   899   from assms(4) obtain g' where A: "uniform_limit s (\<lambda>n x. \<Sum>i<n. f' i x) g' sequentially"
   900     unfolding uniformly_convergent_on_def by blast
   901   from x and \<open>open s\<close> have s: "at x within s = at x" by (rule at_within_open)
   902   have "\<exists>g. \<forall>x\<in>s. (\<lambda>n. f n x) sums g x \<and> (g has_field_derivative g' x) (at x within s)"
   903     by (intro has_field_derivative_series[of s f f' g' x0] assms A has_field_derivative_at_within)
   904   then obtain g where g: "\<And>x. x \<in> s \<Longrightarrow> (\<lambda>n. f n x) sums g x"
   905     "\<And>x. x \<in> s \<Longrightarrow> (g has_field_derivative g' x) (at x within s)" by blast
   906   from g[OF x] show "summable (\<lambda>n. f n x)" by (auto simp: summable_def)
   907   from g(2)[OF x] have g': "(g has_derivative op * (g' x)) (at x)"
   908     by (simp add: has_field_derivative_def s)
   909   have "((\<lambda>x. \<Sum>n. f n x) has_derivative op * (g' x)) (at x)"
   910     by (rule has_derivative_transform_within_open[OF \<open>open s\<close> x _ g'])
   911        (insert g, auto simp: sums_iff)
   912   thus "(\<lambda>x. \<Sum>n. f n x) complex_differentiable (at x)" unfolding differentiable_def
   913     by (auto simp: summable_def complex_differentiable_def has_field_derivative_def)
   914 qed
   915 
   916 lemma complex_differentiable_series':
   917   fixes f :: "nat \<Rightarrow> complex \<Rightarrow> complex"
   918   assumes "convex s" "open s"
   919   assumes "\<And>n x. x \<in> s \<Longrightarrow> (f n has_field_derivative f' n x) (at x)"
   920   assumes "uniformly_convergent_on s (\<lambda>n x. \<Sum>i<n. f' i x)"
   921   assumes "x0 \<in> s" "summable (\<lambda>n. f n x0)"
   922   shows   "(\<lambda>x. \<Sum>n. f n x) complex_differentiable (at x0)"
   923   using complex_differentiable_series[OF assms, of x0] \<open>x0 \<in> s\<close> by blast+
   924 
   925 subsection\<open>Bound theorem\<close>
   926 
   927 lemma complex_differentiable_bound:
   928   fixes s :: "complex set"
   929   assumes cvs: "convex s"
   930       and df:  "\<And>z. z \<in> s \<Longrightarrow> (f has_field_derivative f' z) (at z within s)"
   931       and dn:  "\<And>z. z \<in> s \<Longrightarrow> norm (f' z) \<le> B"
   932       and "x \<in> s"  "y \<in> s"
   933     shows "norm(f x - f y) \<le> B * norm(x - y)"
   934   apply (rule differentiable_bound [OF cvs])
   935   apply (rule ballI, erule df [unfolded has_field_derivative_def])
   936   apply (rule ballI, rule onorm_le, simp add: norm_mult mult_right_mono dn)
   937   apply fact
   938   apply fact
   939   done
   940 
   941 subsection\<open>Inverse function theorem for complex derivatives.\<close>
   942 
   943 lemma has_complex_derivative_inverse_basic:
   944   fixes f :: "complex \<Rightarrow> complex"
   945   shows "DERIV f (g y) :> f' \<Longrightarrow>
   946         f' \<noteq> 0 \<Longrightarrow>
   947         continuous (at y) g \<Longrightarrow>
   948         open t \<Longrightarrow>
   949         y \<in> t \<Longrightarrow>
   950         (\<And>z. z \<in> t \<Longrightarrow> f (g z) = z)
   951         \<Longrightarrow> DERIV g y :> inverse (f')"
   952   unfolding has_field_derivative_def
   953   apply (rule has_derivative_inverse_basic)
   954   apply (auto simp:  bounded_linear_mult_right)
   955   done
   956 
   957 (*Used only once, in Multivariate/cauchy.ml. *)
   958 lemma has_complex_derivative_inverse_strong:
   959   fixes f :: "complex \<Rightarrow> complex"
   960   shows "DERIV f x :> f' \<Longrightarrow>
   961          f' \<noteq> 0 \<Longrightarrow>
   962          open s \<Longrightarrow>
   963          x \<in> s \<Longrightarrow>
   964          continuous_on s f \<Longrightarrow>
   965          (\<And>z. z \<in> s \<Longrightarrow> g (f z) = z)
   966          \<Longrightarrow> DERIV g (f x) :> inverse (f')"
   967   unfolding has_field_derivative_def
   968   apply (rule has_derivative_inverse_strong [of s x f g ])
   969   using assms
   970   by auto
   971 
   972 lemma has_complex_derivative_inverse_strong_x:
   973   fixes f :: "complex \<Rightarrow> complex"
   974   shows  "DERIV f (g y) :> f' \<Longrightarrow>
   975           f' \<noteq> 0 \<Longrightarrow>
   976           open s \<Longrightarrow>
   977           continuous_on s f \<Longrightarrow>
   978           g y \<in> s \<Longrightarrow> f(g y) = y \<Longrightarrow>
   979           (\<And>z. z \<in> s \<Longrightarrow> g (f z) = z)
   980           \<Longrightarrow> DERIV g y :> inverse (f')"
   981   unfolding has_field_derivative_def
   982   apply (rule has_derivative_inverse_strong_x [of s g y f])
   983   using assms
   984   by auto
   985 
   986 subsection \<open>Taylor on Complex Numbers\<close>
   987 
   988 lemma setsum_Suc_reindex:
   989   fixes f :: "nat \<Rightarrow> 'a::ab_group_add"
   990     shows  "setsum f {0..n} = f 0 - f (Suc n) + setsum (\<lambda>i. f (Suc i)) {0..n}"
   991 by (induct n) auto
   992 
   993 lemma complex_taylor:
   994   assumes s: "convex s"
   995       and f: "\<And>i x. x \<in> s \<Longrightarrow> i \<le> n \<Longrightarrow> (f i has_field_derivative f (Suc i) x) (at x within s)"
   996       and B: "\<And>x. x \<in> s \<Longrightarrow> cmod (f (Suc n) x) \<le> B"
   997       and w: "w \<in> s"
   998       and z: "z \<in> s"
   999     shows "cmod(f 0 z - (\<Sum>i\<le>n. f i w * (z-w) ^ i / (fact i)))
  1000           \<le> B * cmod(z - w)^(Suc n) / fact n"
  1001 proof -
  1002   have wzs: "closed_segment w z \<subseteq> s" using assms
  1003     by (metis convex_contains_segment)
  1004   { fix u
  1005     assume "u \<in> closed_segment w z"
  1006     then have "u \<in> s"
  1007       by (metis wzs subsetD)
  1008     have "(\<Sum>i\<le>n. f i u * (- of_nat i * (z-u)^(i - 1)) / (fact i) +
  1009                       f (Suc i) u * (z-u)^i / (fact i)) =
  1010               f (Suc n) u * (z-u) ^ n / (fact n)"
  1011     proof (induction n)
  1012       case 0 show ?case by simp
  1013     next
  1014       case (Suc n)
  1015       have "(\<Sum>i\<le>Suc n. f i u * (- of_nat i * (z-u) ^ (i - 1)) / (fact i) +
  1016                              f (Suc i) u * (z-u) ^ i / (fact i)) =
  1017            f (Suc n) u * (z-u) ^ n / (fact n) +
  1018            f (Suc (Suc n)) u * ((z-u) * (z-u) ^ n) / (fact (Suc n)) -
  1019            f (Suc n) u * ((1 + of_nat n) * (z-u) ^ n) / (fact (Suc n))"
  1020         using Suc by simp
  1021       also have "... = f (Suc (Suc n)) u * (z-u) ^ Suc n / (fact (Suc n))"
  1022       proof -
  1023         have "(fact(Suc n)) *
  1024              (f(Suc n) u *(z-u) ^ n / (fact n) +
  1025                f(Suc(Suc n)) u *((z-u) *(z-u) ^ n) / (fact(Suc n)) -
  1026                f(Suc n) u *((1 + of_nat n) *(z-u) ^ n) / (fact(Suc n))) =
  1027             ((fact(Suc n)) *(f(Suc n) u *(z-u) ^ n)) / (fact n) +
  1028             ((fact(Suc n)) *(f(Suc(Suc n)) u *((z-u) *(z-u) ^ n)) / (fact(Suc n))) -
  1029             ((fact(Suc n)) *(f(Suc n) u *(of_nat(Suc n) *(z-u) ^ n))) / (fact(Suc n))"
  1030           by (simp add: algebra_simps del: fact.simps)
  1031         also have "... = ((fact (Suc n)) * (f (Suc n) u * (z-u) ^ n)) / (fact n) +
  1032                          (f (Suc (Suc n)) u * ((z-u) * (z-u) ^ n)) -
  1033                          (f (Suc n) u * ((1 + of_nat n) * (z-u) ^ n))"
  1034           by (simp del: fact.simps)
  1035         also have "... = (of_nat (Suc n) * (f (Suc n) u * (z-u) ^ n)) +
  1036                          (f (Suc (Suc n)) u * ((z-u) * (z-u) ^ n)) -
  1037                          (f (Suc n) u * ((1 + of_nat n) * (z-u) ^ n))"
  1038           by (simp only: fact.simps of_nat_mult ac_simps) simp
  1039         also have "... = f (Suc (Suc n)) u * ((z-u) * (z-u) ^ n)"
  1040           by (simp add: algebra_simps)
  1041         finally show ?thesis
  1042         by (simp add: mult_left_cancel [where c = "(fact (Suc n))", THEN iffD1] del: fact.simps)
  1043       qed
  1044       finally show ?case .
  1045     qed
  1046     then have "((\<lambda>v. (\<Sum>i\<le>n. f i v * (z - v)^i / (fact i)))
  1047                 has_field_derivative f (Suc n) u * (z-u) ^ n / (fact n))
  1048                (at u within s)"
  1049       apply (intro derivative_eq_intros)
  1050       apply (blast intro: assms \<open>u \<in> s\<close>)
  1051       apply (rule refl)+
  1052       apply (auto simp: field_simps)
  1053       done
  1054   } note sum_deriv = this
  1055   { fix u
  1056     assume u: "u \<in> closed_segment w z"
  1057     then have us: "u \<in> s"
  1058       by (metis wzs subsetD)
  1059     have "cmod (f (Suc n) u) * cmod (z - u) ^ n \<le> cmod (f (Suc n) u) * cmod (u - z) ^ n"
  1060       by (metis norm_minus_commute order_refl)
  1061     also have "... \<le> cmod (f (Suc n) u) * cmod (z - w) ^ n"
  1062       by (metis mult_left_mono norm_ge_zero power_mono segment_bound [OF u])
  1063     also have "... \<le> B * cmod (z - w) ^ n"
  1064       by (metis norm_ge_zero zero_le_power mult_right_mono  B [OF us])
  1065     finally have "cmod (f (Suc n) u) * cmod (z - u) ^ n \<le> B * cmod (z - w) ^ n" .
  1066   } note cmod_bound = this
  1067   have "(\<Sum>i\<le>n. f i z * (z - z) ^ i / (fact i)) = (\<Sum>i\<le>n. (f i z / (fact i)) * 0 ^ i)"
  1068     by simp
  1069   also have "\<dots> = f 0 z / (fact 0)"
  1070     by (subst setsum_zero_power) simp
  1071   finally have "cmod (f 0 z - (\<Sum>i\<le>n. f i w * (z - w) ^ i / (fact i)))
  1072                 \<le> cmod ((\<Sum>i\<le>n. f i w * (z - w) ^ i / (fact i)) -
  1073                         (\<Sum>i\<le>n. f i z * (z - z) ^ i / (fact i)))"
  1074     by (simp add: norm_minus_commute)
  1075   also have "... \<le> B * cmod (z - w) ^ n / (fact n) * cmod (w - z)"
  1076     apply (rule complex_differentiable_bound
  1077       [where f' = "\<lambda>w. f (Suc n) w * (z - w)^n / (fact n)"
  1078          and s = "closed_segment w z", OF convex_closed_segment])
  1079     apply (auto simp: ends_in_segment DERIV_subset [OF sum_deriv wzs]
  1080                   norm_divide norm_mult norm_power divide_le_cancel cmod_bound)
  1081     done
  1082   also have "...  \<le> B * cmod (z - w) ^ Suc n / (fact n)"
  1083     by (simp add: algebra_simps norm_minus_commute)
  1084   finally show ?thesis .
  1085 qed
  1086 
  1087 text\<open>Something more like the traditional MVT for real components.\<close>
  1088 
  1089 lemma complex_mvt_line:
  1090   assumes "\<And>u. u \<in> closed_segment w z \<Longrightarrow> (f has_field_derivative f'(u)) (at u)"
  1091     shows "\<exists>u. u \<in> closed_segment w z \<and> Re(f z) - Re(f w) = Re(f'(u) * (z - w))"
  1092 proof -
  1093   have twz: "\<And>t. (1 - t) *\<^sub>R w + t *\<^sub>R z = w + t *\<^sub>R (z - w)"
  1094     by (simp add: real_vector.scale_left_diff_distrib real_vector.scale_right_diff_distrib)
  1095   note assms[unfolded has_field_derivative_def, derivative_intros]
  1096   show ?thesis
  1097     apply (cut_tac mvt_simple
  1098                      [of 0 1 "Re o f o (\<lambda>t. (1 - t) *\<^sub>R w +  t *\<^sub>R z)"
  1099                       "\<lambda>u. Re o (\<lambda>h. f'((1 - u) *\<^sub>R w + u *\<^sub>R z) * h) o (\<lambda>t. t *\<^sub>R (z - w))"])
  1100     apply auto
  1101     apply (rule_tac x="(1 - x) *\<^sub>R w + x *\<^sub>R z" in exI)
  1102     apply (auto simp: closed_segment_def twz) []
  1103     apply (intro derivative_eq_intros has_derivative_at_within, simp_all)
  1104     apply (simp add: fun_eq_iff real_vector.scale_right_diff_distrib)
  1105     apply (force simp: twz closed_segment_def)
  1106     done
  1107 qed
  1108 
  1109 lemma complex_taylor_mvt:
  1110   assumes "\<And>i x. \<lbrakk>x \<in> closed_segment w z; i \<le> n\<rbrakk> \<Longrightarrow> ((f i) has_field_derivative f (Suc i) x) (at x)"
  1111     shows "\<exists>u. u \<in> closed_segment w z \<and>
  1112             Re (f 0 z) =
  1113             Re ((\<Sum>i = 0..n. f i w * (z - w) ^ i / (fact i)) +
  1114                 (f (Suc n) u * (z-u)^n / (fact n)) * (z - w))"
  1115 proof -
  1116   { fix u
  1117     assume u: "u \<in> closed_segment w z"
  1118     have "(\<Sum>i = 0..n.
  1119                (f (Suc i) u * (z-u) ^ i - of_nat i * (f i u * (z-u) ^ (i - Suc 0))) /
  1120                (fact i)) =
  1121           f (Suc 0) u -
  1122              (f (Suc (Suc n)) u * ((z-u) ^ Suc n) - (of_nat (Suc n)) * (z-u) ^ n * f (Suc n) u) /
  1123              (fact (Suc n)) +
  1124              (\<Sum>i = 0..n.
  1125                  (f (Suc (Suc i)) u * ((z-u) ^ Suc i) - of_nat (Suc i) * (f (Suc i) u * (z-u) ^ i)) /
  1126                  (fact (Suc i)))"
  1127        by (subst setsum_Suc_reindex) simp
  1128     also have "... = f (Suc 0) u -
  1129              (f (Suc (Suc n)) u * ((z-u) ^ Suc n) - (of_nat (Suc n)) * (z-u) ^ n * f (Suc n) u) /
  1130              (fact (Suc n)) +
  1131              (\<Sum>i = 0..n.
  1132                  f (Suc (Suc i)) u * ((z-u) ^ Suc i) / (fact (Suc i))  -
  1133                  f (Suc i) u * (z-u) ^ i / (fact i))"
  1134       by (simp only: diff_divide_distrib fact_cancel ac_simps)
  1135     also have "... = f (Suc 0) u -
  1136              (f (Suc (Suc n)) u * (z-u) ^ Suc n - of_nat (Suc n) * (z-u) ^ n * f (Suc n) u) /
  1137              (fact (Suc n)) +
  1138              f (Suc (Suc n)) u * (z-u) ^ Suc n / (fact (Suc n)) - f (Suc 0) u"
  1139       by (subst setsum_Suc_diff) auto
  1140     also have "... = f (Suc n) u * (z-u) ^ n / (fact n)"
  1141       by (simp only: algebra_simps diff_divide_distrib fact_cancel)
  1142     finally have "(\<Sum>i = 0..n. (f (Suc i) u * (z - u) ^ i
  1143                              - of_nat i * (f i u * (z-u) ^ (i - Suc 0))) / (fact i)) =
  1144                   f (Suc n) u * (z - u) ^ n / (fact n)" .
  1145     then have "((\<lambda>u. \<Sum>i = 0..n. f i u * (z - u) ^ i / (fact i)) has_field_derivative
  1146                 f (Suc n) u * (z - u) ^ n / (fact n))  (at u)"
  1147       apply (intro derivative_eq_intros)+
  1148       apply (force intro: u assms)
  1149       apply (rule refl)+
  1150       apply (auto simp: ac_simps)
  1151       done
  1152   }
  1153   then show ?thesis
  1154     apply (cut_tac complex_mvt_line [of w z "\<lambda>u. \<Sum>i = 0..n. f i u * (z-u) ^ i / (fact i)"
  1155                "\<lambda>u. (f (Suc n) u * (z-u)^n / (fact n))"])
  1156     apply (auto simp add: intro: open_closed_segment)
  1157     done
  1158 qed
  1159 
  1160 
  1161 subsection \<open>Polynomal function extremal theorem, from HOL Light\<close>
  1162 
  1163 lemma polyfun_extremal_lemma: (*COMPLEX_POLYFUN_EXTREMAL_LEMMA in HOL Light*)
  1164     fixes c :: "nat \<Rightarrow> 'a::real_normed_div_algebra"
  1165   assumes "0 < e"
  1166     shows "\<exists>M. \<forall>z. M \<le> norm(z) \<longrightarrow> norm (\<Sum>i\<le>n. c(i) * z^i) \<le> e * norm(z) ^ (Suc n)"
  1167 proof (induct n)
  1168   case 0 with assms
  1169   show ?case
  1170     apply (rule_tac x="norm (c 0) / e" in exI)
  1171     apply (auto simp: field_simps)
  1172     done
  1173 next
  1174   case (Suc n)
  1175   obtain M where M: "\<And>z. M \<le> norm z \<Longrightarrow> norm (\<Sum>i\<le>n. c i * z^i) \<le> e * norm z ^ Suc n"
  1176     using Suc assms by blast
  1177   show ?case
  1178   proof (rule exI [where x= "max M (1 + norm(c(Suc n)) / e)"], clarsimp simp del: power_Suc)
  1179     fix z::'a
  1180     assume z1: "M \<le> norm z" and "1 + norm (c (Suc n)) / e \<le> norm z"
  1181     then have z2: "e + norm (c (Suc n)) \<le> e * norm z"
  1182       using assms by (simp add: field_simps)
  1183     have "norm (\<Sum>i\<le>n. c i * z^i) \<le> e * norm z ^ Suc n"
  1184       using M [OF z1] by simp
  1185     then have "norm (\<Sum>i\<le>n. c i * z^i) + norm (c (Suc n) * z ^ Suc n) \<le> e * norm z ^ Suc n + norm (c (Suc n) * z ^ Suc n)"
  1186       by simp
  1187     then have "norm ((\<Sum>i\<le>n. c i * z^i) + c (Suc n) * z ^ Suc n) \<le> e * norm z ^ Suc n + norm (c (Suc n) * z ^ Suc n)"
  1188       by (blast intro: norm_triangle_le elim: )
  1189     also have "... \<le> (e + norm (c (Suc n))) * norm z ^ Suc n"
  1190       by (simp add: norm_power norm_mult algebra_simps)
  1191     also have "... \<le> (e * norm z) * norm z ^ Suc n"
  1192       by (metis z2 mult.commute mult_left_mono norm_ge_zero norm_power)
  1193     finally show "norm ((\<Sum>i\<le>n. c i * z^i) + c (Suc n) * z ^ Suc n) \<le> e * norm z ^ Suc (Suc n)"
  1194       by simp
  1195   qed
  1196 qed
  1197 
  1198 lemma polyfun_extremal: (*COMPLEX_POLYFUN_EXTREMAL in HOL Light*)
  1199     fixes c :: "nat \<Rightarrow> 'a::real_normed_div_algebra"
  1200   assumes k: "c k \<noteq> 0" "1\<le>k" and kn: "k\<le>n"
  1201     shows "eventually (\<lambda>z. norm (\<Sum>i\<le>n. c(i) * z^i) \<ge> B) at_infinity"
  1202 using kn
  1203 proof (induction n)
  1204   case 0
  1205   then show ?case
  1206     using k  by simp
  1207 next
  1208   case (Suc m)
  1209   let ?even = ?case
  1210   show ?even
  1211   proof (cases "c (Suc m) = 0")
  1212     case True
  1213     then show ?even using Suc k
  1214       by auto (metis antisym_conv less_eq_Suc_le not_le)
  1215   next
  1216     case False
  1217     then obtain M where M:
  1218           "\<And>z. M \<le> norm z \<Longrightarrow> norm (\<Sum>i\<le>m. c i * z^i) \<le> norm (c (Suc m)) / 2 * norm z ^ Suc m"
  1219       using polyfun_extremal_lemma [of "norm(c (Suc m)) / 2" c m] Suc
  1220       by auto
  1221     have "\<exists>b. \<forall>z. b \<le> norm z \<longrightarrow> B \<le> norm (\<Sum>i\<le>Suc m. c i * z^i)"
  1222     proof (rule exI [where x="max M (max 1 (\<bar>B\<bar> / (norm(c (Suc m)) / 2)))"], clarsimp simp del: power_Suc)
  1223       fix z::'a
  1224       assume z1: "M \<le> norm z" "1 \<le> norm z"
  1225          and "\<bar>B\<bar> * 2 / norm (c (Suc m)) \<le> norm z"
  1226       then have z2: "\<bar>B\<bar> \<le> norm (c (Suc m)) * norm z / 2"
  1227         using False by (simp add: field_simps)
  1228       have nz: "norm z \<le> norm z ^ Suc m"
  1229         by (metis \<open>1 \<le> norm z\<close> One_nat_def less_eq_Suc_le power_increasing power_one_right zero_less_Suc)
  1230       have *: "\<And>y x. norm (c (Suc m)) * norm z / 2 \<le> norm y - norm x \<Longrightarrow> B \<le> norm (x + y)"
  1231         by (metis abs_le_iff add.commute norm_diff_ineq order_trans z2)
  1232       have "norm z * norm (c (Suc m)) + 2 * norm (\<Sum>i\<le>m. c i * z^i)
  1233             \<le> norm (c (Suc m)) * norm z + norm (c (Suc m)) * norm z ^ Suc m"
  1234         using M [of z] Suc z1  by auto
  1235       also have "... \<le> 2 * (norm (c (Suc m)) * norm z ^ Suc m)"
  1236         using nz by (simp add: mult_mono del: power_Suc)
  1237       finally show "B \<le> norm ((\<Sum>i\<le>m. c i * z^i) + c (Suc m) * z ^ Suc m)"
  1238         using Suc.IH
  1239         apply (auto simp: eventually_at_infinity)
  1240         apply (rule *)
  1241         apply (simp add: field_simps norm_mult norm_power)
  1242         done
  1243     qed
  1244     then show ?even
  1245       by (simp add: eventually_at_infinity)
  1246   qed
  1247 qed
  1248 
  1249 end