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