the Cauchy integral theorem and related material
authorpaulson <lp15@cam.ac.uk>
Tue Jul 28 16:16:13 2015 +0100 (2015-07-28)
changeset 60809457abb82fb9e
parent 60808 fd26519b1a6a
child 60810 9ede42599eeb
child 60813 db6430b18964
the Cauchy integral theorem and related material
NEWS
src/HOL/Multivariate_Analysis/Cauchy_Integral_Thm.thy
src/HOL/Multivariate_Analysis/Complex_Transcendental.thy
src/HOL/Multivariate_Analysis/Convex_Euclidean_Space.thy
src/HOL/Multivariate_Analysis/Path_Connected.thy
src/HOL/Probability/Projective_Limit.thy
src/HOL/Probability/Regularity.thy
src/HOL/ROOT
src/HOL/Set_Interval.thy
     1.1 --- a/NEWS	Tue Jul 28 13:00:54 2015 +0200
     1.2 +++ b/NEWS	Tue Jul 28 16:16:13 2015 +0100
     1.3 @@ -240,6 +240,9 @@
     1.4      less_eq_multiset_def
     1.5      INCOMPATIBILITY
     1.6  
     1.7 +* Multivariate_Analysis/Cauchy_Integral_Thm: Complex path integrals and Cauchy's integral theorem,
     1.8 +    ported from HOL Light
     1.9 +
    1.10  * Theory Library/Old_Recdef: discontinued obsolete 'defer_recdef'
    1.11  command. Minor INCOMPATIBILITY, use 'function' instead.
    1.12  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/HOL/Multivariate_Analysis/Cauchy_Integral_Thm.thy	Tue Jul 28 16:16:13 2015 +0100
     2.3 @@ -0,0 +1,2781 @@
     2.4 +section \<open>Complex path integrals and Cauchy's integral theorem\<close>
     2.5 +
     2.6 +theory Cauchy_Integral_Thm
     2.7 +imports Complex_Transcendental Path_Connected
     2.8 +begin
     2.9 +
    2.10 +
    2.11 +definition piecewise_differentiable_on
    2.12 +           (infixr "piecewise'_differentiable'_on" 50)
    2.13 +  where "f piecewise_differentiable_on i  \<equiv>
    2.14 +           continuous_on i f \<and>
    2.15 +           (\<exists>s. finite s \<and> (\<forall>x \<in> i - s. f differentiable (at x)))"
    2.16 +
    2.17 +lemma piecewise_differentiable_on_imp_continuous_on:
    2.18 +    "f piecewise_differentiable_on s \<Longrightarrow> continuous_on s f"
    2.19 +by (simp add: piecewise_differentiable_on_def)
    2.20 +
    2.21 +lemma piecewise_differentiable_on_subset:
    2.22 +    "f piecewise_differentiable_on s \<Longrightarrow> t \<le> s \<Longrightarrow> f piecewise_differentiable_on t"
    2.23 +  using continuous_on_subset
    2.24 +  by (fastforce simp: piecewise_differentiable_on_def)
    2.25 +
    2.26 +lemma differentiable_on_imp_piecewise_differentiable:
    2.27 +  fixes a:: "'a::{linorder_topology,real_normed_vector}"
    2.28 +  shows "f differentiable_on {a..b} \<Longrightarrow> f piecewise_differentiable_on {a..b}"
    2.29 +  apply (simp add: piecewise_differentiable_on_def differentiable_imp_continuous_on)
    2.30 +  apply (rule_tac x="{a,b}" in exI, simp)
    2.31 +  by (metis DiffE atLeastAtMost_diff_ends differentiable_on_subset subsetI
    2.32 +        differentiable_on_eq_differentiable_at open_greaterThanLessThan)
    2.33 +
    2.34 +lemma differentiable_imp_piecewise_differentiable:
    2.35 +    "(\<And>x. x \<in> s \<Longrightarrow> f differentiable (at x))
    2.36 +         \<Longrightarrow> f piecewise_differentiable_on s"
    2.37 +by (auto simp: piecewise_differentiable_on_def differentiable_on_eq_differentiable_at
    2.38 +               differentiable_imp_continuous_within continuous_at_imp_continuous_on)
    2.39 +
    2.40 +lemma piecewise_differentiable_compose:
    2.41 +    "\<lbrakk>f piecewise_differentiable_on s; g piecewise_differentiable_on (f ` s);
    2.42 +      \<And>x. finite (s \<inter> f-`{x})\<rbrakk>
    2.43 +      \<Longrightarrow> (g o f) piecewise_differentiable_on s"
    2.44 +  apply (simp add: piecewise_differentiable_on_def, safe)
    2.45 +  apply (blast intro: continuous_on_compose2)
    2.46 +  apply (rename_tac A B)
    2.47 +  apply (rule_tac x="A \<union> (\<Union>x\<in>B. s \<inter> f-`{x})" in exI)
    2.48 +  using differentiable_chain_at by blast
    2.49 +
    2.50 +lemma piecewise_differentiable_affine:
    2.51 +  fixes m::real
    2.52 +  assumes "f piecewise_differentiable_on ((\<lambda>x. m *\<^sub>R x + c) ` s)"
    2.53 +  shows "(f o (\<lambda>x. m *\<^sub>R x + c)) piecewise_differentiable_on s"
    2.54 +proof (cases "m = 0")
    2.55 +  case True
    2.56 +  then show ?thesis
    2.57 +    unfolding o_def
    2.58 +    by (force intro: differentiable_imp_piecewise_differentiable differentiable_const)
    2.59 +next
    2.60 +  case False
    2.61 +  show ?thesis
    2.62 +    apply (rule piecewise_differentiable_compose [OF differentiable_imp_piecewise_differentiable])
    2.63 +    apply (rule assms derivative_intros | simp add: False vimage_def real_vector_affinity_eq)+
    2.64 +    done
    2.65 +qed
    2.66 +
    2.67 +lemma piecewise_differentiable_cases:
    2.68 +  fixes c::real
    2.69 +  assumes "f piecewise_differentiable_on {a..c}"
    2.70 +          "g piecewise_differentiable_on {c..b}"
    2.71 +           "a \<le> c" "c \<le> b" "f c = g c"
    2.72 +  shows "(\<lambda>x. if x \<le> c then f x else g x) piecewise_differentiable_on {a..b}"
    2.73 +proof -
    2.74 +  obtain s t where st: "finite s" "finite t"
    2.75 +                       "\<forall>x\<in>{a..c} - s. f differentiable at x"
    2.76 +                       "\<forall>x\<in>{c..b} - t. g differentiable at x"
    2.77 +    using assms
    2.78 +    by (auto simp: piecewise_differentiable_on_def)
    2.79 +  have "continuous_on {a..c} f" "continuous_on {c..b} g"
    2.80 +    using assms piecewise_differentiable_on_def by auto
    2.81 +  then have "continuous_on {a..b} (\<lambda>x. if x \<le> c then f x else g x)"
    2.82 +    using continuous_on_cases [OF closed_real_atLeastAtMost [of a c],
    2.83 +                               OF closed_real_atLeastAtMost [of c b],
    2.84 +                               of f g "\<lambda>x. x\<le>c"]  assms
    2.85 +    by (force simp: ivl_disj_un_two_touch)
    2.86 +  moreover
    2.87 +  { fix x
    2.88 +    assume x: "x \<in> {a..b} - insert c (s \<union> t)"
    2.89 +    have "(\<lambda>x. if x \<le> c then f x else g x) differentiable at x" (is "?diff_fg")
    2.90 +    proof (cases x c rule: le_cases)
    2.91 +      case le show ?diff_fg
    2.92 +        apply (rule differentiable_transform_at [of "dist x c" _ f])
    2.93 +        using dist_nz x dist_real_def le st x
    2.94 +        apply auto
    2.95 +        done
    2.96 +    next
    2.97 +      case ge show ?diff_fg
    2.98 +        apply (rule differentiable_transform_at [of "dist x c" _ g])
    2.99 +        using dist_nz x dist_real_def ge st x
   2.100 +        apply auto
   2.101 +        done
   2.102 +    qed
   2.103 +  }
   2.104 +  then have "\<exists>s. finite s \<and> (\<forall>x\<in>{a..b} - s. (\<lambda>x. if x \<le> c then f x else g x) differentiable at x)"
   2.105 +    using st
   2.106 +    by (metis (full_types) finite_Un finite_insert)
   2.107 +  ultimately show ?thesis
   2.108 +    by (simp add: piecewise_differentiable_on_def)
   2.109 +qed
   2.110 +
   2.111 +lemma piecewise_differentiable_neg:
   2.112 +    "f piecewise_differentiable_on s \<Longrightarrow> (\<lambda>x. -(f x)) piecewise_differentiable_on s"
   2.113 +  by (auto simp: piecewise_differentiable_on_def continuous_on_minus)
   2.114 +
   2.115 +lemma piecewise_differentiable_add:
   2.116 +  assumes "f piecewise_differentiable_on i"
   2.117 +          "g piecewise_differentiable_on i"
   2.118 +    shows "(\<lambda>x. f x + g x) piecewise_differentiable_on i"
   2.119 +proof -
   2.120 +  obtain s t where st: "finite s" "finite t"
   2.121 +                       "\<forall>x\<in>i - s. f differentiable at x"
   2.122 +                       "\<forall>x\<in>i - t. g differentiable at x"
   2.123 +    using assms by (auto simp: piecewise_differentiable_on_def)
   2.124 +  then have "finite (s \<union> t) \<and> (\<forall>x\<in>i - (s \<union> t). (\<lambda>x. f x + g x) differentiable at x)"
   2.125 +    by auto
   2.126 +  moreover have "continuous_on i f" "continuous_on i g"
   2.127 +    using assms piecewise_differentiable_on_def by auto
   2.128 +  ultimately show ?thesis
   2.129 +    by (auto simp: piecewise_differentiable_on_def continuous_on_add)
   2.130 +qed
   2.131 +
   2.132 +lemma piecewise_differentiable_diff:
   2.133 +    "\<lbrakk>f piecewise_differentiable_on s;  g piecewise_differentiable_on s\<rbrakk>
   2.134 +     \<Longrightarrow> (\<lambda>x. f x - g x) piecewise_differentiable_on s"
   2.135 +  unfolding diff_conv_add_uminus
   2.136 +  by (metis piecewise_differentiable_add piecewise_differentiable_neg)
   2.137 +
   2.138 +
   2.139 +subsection \<open>Valid paths, and their start and finish\<close>
   2.140 +
   2.141 +lemma Diff_Un_eq: "A - (B \<union> C) = A - B - C"
   2.142 +  by blast
   2.143 +
   2.144 +definition valid_path :: "(real \<Rightarrow> 'a :: real_normed_vector) \<Rightarrow> bool"
   2.145 +  where "valid_path f \<equiv> f piecewise_differentiable_on {0..1::real}"
   2.146 +
   2.147 +definition closed_path :: "(real \<Rightarrow> 'a :: real_normed_vector) \<Rightarrow> bool"
   2.148 +  where "closed_path g \<equiv> g 0 = g 1"
   2.149 +
   2.150 +lemma valid_path_compose:
   2.151 +  assumes "valid_path g" "f differentiable_on (path_image g)"
   2.152 +  shows "valid_path (f o g)"
   2.153 +proof -
   2.154 +  { fix s :: "real set"
   2.155 +    assume df: "f differentiable_on g ` {0..1}"
   2.156 +       and cg: "continuous_on {0..1} g"
   2.157 +       and s: "finite s"
   2.158 +       and dg: "\<And>x. x\<in>{0..1} - s \<Longrightarrow> g differentiable at x"
   2.159 +    have dfo: "f differentiable_on g ` {0<..<1}"
   2.160 +      by (auto intro: differentiable_on_subset [OF df])
   2.161 +    have *: "\<And>x. x \<in> {0<..<1} \<Longrightarrow> x \<notin> s \<Longrightarrow> (f o g) differentiable (at x within ({0<..<1} - s))"
   2.162 +      apply (rule differentiable_chain_within)
   2.163 +      apply (simp_all add: dg differentiable_at_withinI differentiable_chain_within)
   2.164 +      using df
   2.165 +      apply (force simp: differentiable_on_def elim: Deriv.differentiable_subset)
   2.166 +      done
   2.167 +    have oo: "open ({0<..<1} - s)"
   2.168 +      by (simp add: finite_imp_closed open_Diff s)
   2.169 +    have "\<exists>s. finite s \<and> (\<forall>x\<in>{0..1} - s. f \<circ> g differentiable at x)"
   2.170 +      apply (rule_tac x="{0,1} Un s" in exI)
   2.171 +      apply (simp add: Diff_Un_eq atLeastAtMost_diff_ends s del: Set.Un_insert_left, clarify)
   2.172 +      apply (rule differentiable_within_open [OF _ oo, THEN iffD1])
   2.173 +      apply (auto simp: *)
   2.174 +      done }
   2.175 +  with assms show ?thesis
   2.176 +    by (clarsimp simp: valid_path_def piecewise_differentiable_on_def continuous_on_compose
   2.177 +                       differentiable_imp_continuous_on path_image_def   simp del: o_apply)
   2.178 +qed
   2.179 +
   2.180 +
   2.181 +subsubsection\<open>In particular, all results for paths apply\<close>
   2.182 +
   2.183 +lemma valid_path_imp_path: "valid_path g \<Longrightarrow> path g"
   2.184 +by (simp add: path_def piecewise_differentiable_on_def valid_path_def)
   2.185 +
   2.186 +lemma connected_valid_path_image: "valid_path g \<Longrightarrow> connected(path_image g)"
   2.187 +  by (metis connected_path_image valid_path_imp_path)
   2.188 +
   2.189 +lemma compact_valid_path_image: "valid_path g \<Longrightarrow> compact(path_image g)"
   2.190 +  by (metis compact_path_image valid_path_imp_path)
   2.191 +
   2.192 +lemma bounded_valid_path_image: "valid_path g \<Longrightarrow> bounded(path_image g)"
   2.193 +  by (metis bounded_path_image valid_path_imp_path)
   2.194 +
   2.195 +lemma closed_valid_path_image: "valid_path g \<Longrightarrow> closed(path_image g)"
   2.196 +  by (metis closed_path_image valid_path_imp_path)
   2.197 +
   2.198 +
   2.199 +subsection\<open>Contour Integrals along a path\<close>
   2.200 +
   2.201 +text\<open>This definition is for complex numbers only, and does not generalise to line integrals in a vector field\<close>
   2.202 +
   2.203 +text\<open>= piecewise differentiable function on [0,1]\<close>
   2.204 +
   2.205 +definition has_path_integral :: "(complex \<Rightarrow> complex) \<Rightarrow> complex \<Rightarrow> (real \<Rightarrow> complex) \<Rightarrow> bool"
   2.206 +           (infixr "has'_path'_integral" 50)
   2.207 +  where "(f has_path_integral i) g \<equiv>
   2.208 +           ((\<lambda>x. f(g x) * vector_derivative g (at x within {0..1}))
   2.209 +            has_integral i) {0..1}"
   2.210 +
   2.211 +definition path_integrable_on
   2.212 +           (infixr "path'_integrable'_on" 50)
   2.213 +  where "f path_integrable_on g \<equiv> \<exists>i. (f has_path_integral i) g"
   2.214 +
   2.215 +definition path_integral
   2.216 +  where "path_integral g f \<equiv> @i. (f has_path_integral i) g"
   2.217 +
   2.218 +lemma path_integral_unique: "(f has_path_integral i)  g \<Longrightarrow> path_integral g f = i"
   2.219 +  by (auto simp: path_integral_def has_path_integral_def integral_def [symmetric])
   2.220 +
   2.221 +lemma has_path_integral_integral:
   2.222 +    "f path_integrable_on i \<Longrightarrow> (f has_path_integral (path_integral i f)) i"
   2.223 +  by (metis path_integral_unique path_integrable_on_def)
   2.224 +
   2.225 +lemma has_path_integral_unique:
   2.226 +    "(f has_path_integral i) g \<Longrightarrow> (f has_path_integral j) g \<Longrightarrow> i = j"
   2.227 +  using has_integral_unique
   2.228 +  by (auto simp: has_path_integral_def)
   2.229 +
   2.230 +lemma has_path_integral_integrable: "(f has_path_integral i) g \<Longrightarrow> f path_integrable_on g"
   2.231 +  using path_integrable_on_def by blast
   2.232 +
   2.233 +(* Show that we can forget about the localized derivative.*)
   2.234 +
   2.235 +lemma vector_derivative_within_interior:
   2.236 +     "\<lbrakk>x \<in> interior s; NO_MATCH UNIV s\<rbrakk>
   2.237 +      \<Longrightarrow> vector_derivative f (at x within s) = vector_derivative f (at x)"
   2.238 +  apply (simp add: vector_derivative_def has_vector_derivative_def has_derivative_def netlimit_within_interior)
   2.239 +  apply (subst lim_within_interior, auto)
   2.240 +  done
   2.241 +
   2.242 +lemma has_integral_localized_vector_derivative:
   2.243 +    "((\<lambda>x. f (g x) * vector_derivative g (at x within {a..b})) has_integral i) {a..b} \<longleftrightarrow>
   2.244 +     ((\<lambda>x. f (g x) * vector_derivative g (at x)) has_integral i) {a..b}"
   2.245 +proof -
   2.246 +  have "{a..b} - {a,b} = interior {a..b}"
   2.247 +    by (simp add: atLeastAtMost_diff_ends)
   2.248 +  show ?thesis
   2.249 +    apply (rule has_integral_spike_eq [of "{a,b}"])
   2.250 +    apply (auto simp: vector_derivative_within_interior)
   2.251 +    done
   2.252 +qed
   2.253 +
   2.254 +lemma integrable_on_localized_vector_derivative:
   2.255 +    "(\<lambda>x. f (g x) * vector_derivative g (at x within {a..b})) integrable_on {a..b} \<longleftrightarrow>
   2.256 +     (\<lambda>x. f (g x) * vector_derivative g (at x)) integrable_on {a..b}"
   2.257 +  by (simp add: integrable_on_def has_integral_localized_vector_derivative)
   2.258 +
   2.259 +lemma has_path_integral:
   2.260 +     "(f has_path_integral i) g \<longleftrightarrow>
   2.261 +      ((\<lambda>x. f (g x) * vector_derivative g (at x)) has_integral i) {0..1}"
   2.262 +  by (simp add: has_integral_localized_vector_derivative has_path_integral_def)
   2.263 +
   2.264 +lemma path_integrable_on:
   2.265 +     "f path_integrable_on g \<longleftrightarrow>
   2.266 +      (\<lambda>t. f(g t) * vector_derivative g (at t)) integrable_on {0..1}"
   2.267 +  by (simp add: has_path_integral integrable_on_def path_integrable_on_def)
   2.268 +
   2.269 +subsection\<open>Reversing a path\<close>
   2.270 +
   2.271 +lemma valid_path_imp_reverse:
   2.272 +  assumes "valid_path g"
   2.273 +    shows "valid_path(reversepath g)"
   2.274 +proof -
   2.275 +  obtain s where "finite s" "\<forall>x\<in>{0..1} - s. g differentiable at x"
   2.276 +    using assms by (auto simp: valid_path_def piecewise_differentiable_on_def)
   2.277 +  then have "finite (op - 1 ` s)" "(\<forall>x\<in>{0..1} - op - 1 ` s. reversepath g differentiable at x)"
   2.278 +    apply (auto simp: reversepath_def)
   2.279 +    apply (rule differentiable_chain_at [of "\<lambda>x::real. 1-x" _ g, unfolded o_def])
   2.280 +    using image_iff
   2.281 +    apply fastforce+
   2.282 +    done
   2.283 +  then show ?thesis using assms
   2.284 +    by (auto simp: valid_path_def piecewise_differentiable_on_def path_def [symmetric])
   2.285 +qed
   2.286 +
   2.287 +lemma valid_path_reversepath: "valid_path(reversepath g) \<longleftrightarrow> valid_path g"
   2.288 +  using valid_path_imp_reverse by force
   2.289 +
   2.290 +lemma has_path_integral_reversepath:
   2.291 +  assumes "valid_path g" "(f has_path_integral i) g"
   2.292 +    shows "(f has_path_integral (-i)) (reversepath g)"
   2.293 +proof -
   2.294 +  { fix s x
   2.295 +    assume xs: "\<forall>x\<in>{0..1} - s. g differentiable at x" "x \<notin> op - 1 ` s" "0 \<le> x" "x \<le> 1"
   2.296 +      have "vector_derivative (\<lambda>x. g (1 - x)) (at x within {0..1}) =
   2.297 +            - vector_derivative g (at (1 - x) within {0..1})"
   2.298 +      proof -
   2.299 +        obtain f' where f': "(g has_vector_derivative f') (at (1 - x))"
   2.300 +          using xs
   2.301 +          apply (drule_tac x="1-x" in bspec)
   2.302 +          apply (simp_all add: has_vector_derivative_def differentiable_def, force)
   2.303 +          apply (blast elim!: linear_imp_scaleR dest: has_derivative_linear)
   2.304 +          done
   2.305 +        have "(g o (\<lambda>x. 1 - x) has_vector_derivative -1 *\<^sub>R f') (at x)"
   2.306 +          apply (rule vector_diff_chain_within)
   2.307 +          apply (intro vector_diff_chain_within derivative_eq_intros | simp)+
   2.308 +          apply (rule has_vector_derivative_at_within [OF f'])
   2.309 +          done
   2.310 +        then have mf': "((\<lambda>x. g (1 - x)) has_vector_derivative -f') (at x)"
   2.311 +          by (simp add: o_def)
   2.312 +        show ?thesis
   2.313 +          using xs
   2.314 +          by (auto simp: vector_derivative_at_within_ivl [OF mf'] vector_derivative_at_within_ivl [OF f'])
   2.315 +      qed
   2.316 +  } note * = this
   2.317 +  have 01: "{0..1::real} = cbox 0 1"
   2.318 +    by simp
   2.319 +  show ?thesis using assms
   2.320 +    apply (auto simp: has_path_integral_def)
   2.321 +    apply (drule has_integral_affinity01 [where m= "-1" and c=1])
   2.322 +    apply (auto simp: reversepath_def valid_path_def piecewise_differentiable_on_def)
   2.323 +    apply (drule has_integral_neg)
   2.324 +    apply (rule_tac s = "(\<lambda>x. 1 - x) ` s" in has_integral_spike_finite)
   2.325 +    apply (auto simp: *)
   2.326 +    done
   2.327 +qed
   2.328 +
   2.329 +lemma path_integrable_reversepath:
   2.330 +    "valid_path g \<Longrightarrow> f path_integrable_on g \<Longrightarrow> f path_integrable_on (reversepath g)"
   2.331 +  using has_path_integral_reversepath path_integrable_on_def by blast
   2.332 +
   2.333 +lemma path_integrable_reversepath_eq:
   2.334 +    "valid_path g \<Longrightarrow> (f path_integrable_on (reversepath g) \<longleftrightarrow> f path_integrable_on g)"
   2.335 +  using path_integrable_reversepath valid_path_reversepath by fastforce
   2.336 +
   2.337 +lemma path_integral_reversepath:
   2.338 +    "\<lbrakk>valid_path g; f path_integrable_on g\<rbrakk> \<Longrightarrow> path_integral (reversepath g) f = -(path_integral g f)"
   2.339 +  using has_path_integral_reversepath path_integrable_on_def path_integral_unique by blast
   2.340 +
   2.341 +
   2.342 +subsection\<open>Joining two paths together\<close>
   2.343 +
   2.344 +lemma valid_path_join:
   2.345 +  assumes "valid_path g1" "valid_path g2" "pathfinish g1 = pathstart g2"
   2.346 +    shows "valid_path(g1 +++ g2)"
   2.347 +proof -
   2.348 +  have "g1 1 = g2 0"
   2.349 +    using assms by (auto simp: pathfinish_def pathstart_def)
   2.350 +  moreover have "(g1 o (\<lambda>x. 2*x)) piecewise_differentiable_on {0..1/2}"
   2.351 +    apply (rule piecewise_differentiable_compose)
   2.352 +    using assms
   2.353 +    apply (auto simp: valid_path_def piecewise_differentiable_on_def continuous_on_joinpaths)
   2.354 +    apply (rule continuous_intros | simp)+
   2.355 +    apply (force intro: finite_vimageI [where h = "op*2"] inj_onI)
   2.356 +    done
   2.357 +  moreover have "(g2 o (\<lambda>x. 2*x-1)) piecewise_differentiable_on {1/2..1}"
   2.358 +    apply (rule piecewise_differentiable_compose)
   2.359 +    using assms
   2.360 +    apply (auto simp: valid_path_def piecewise_differentiable_on_def continuous_on_joinpaths)
   2.361 +    apply (rule continuous_intros | simp add: image_affinity_atLeastAtMost_diff)+
   2.362 +    apply (force intro: finite_vimageI [where h = "(\<lambda>x. 2*x - 1)"] inj_onI)
   2.363 +    done
   2.364 +  ultimately show ?thesis
   2.365 +    apply (simp only: valid_path_def continuous_on_joinpaths joinpaths_def)
   2.366 +    apply (rule piecewise_differentiable_cases)
   2.367 +    apply (auto simp: o_def)
   2.368 +    done
   2.369 +qed
   2.370 +
   2.371 +lemma continuous_on_joinpaths_D1:
   2.372 +    "continuous_on {0..1} (g1 +++ g2) \<Longrightarrow> continuous_on {0..1} g1"
   2.373 +  apply (rule continuous_on_eq [of _ "(g1 +++ g2) o (op*(inverse 2))"])
   2.374 +  apply (simp add: joinpaths_def)
   2.375 +  apply (rule continuous_intros | simp)+
   2.376 +  apply (auto elim!: continuous_on_subset)
   2.377 +  done
   2.378 +
   2.379 +lemma continuous_on_joinpaths_D2:
   2.380 +    "\<lbrakk>continuous_on {0..1} (g1 +++ g2); pathfinish g1 = pathstart g2\<rbrakk> \<Longrightarrow> continuous_on {0..1} g2"
   2.381 +  apply (rule continuous_on_eq [of _ "(g1 +++ g2) o (\<lambda>x. inverse 2*x + 1/2)"])
   2.382 +  apply (simp add: joinpaths_def pathfinish_def pathstart_def Ball_def)
   2.383 +  apply (rule continuous_intros | simp)+
   2.384 +  apply (auto elim!: continuous_on_subset)
   2.385 +  done
   2.386 +
   2.387 +lemma piecewise_differentiable_D1:
   2.388 +    "(g1 +++ g2) piecewise_differentiable_on {0..1} \<Longrightarrow> g1 piecewise_differentiable_on {0..1}"
   2.389 +  apply (clarsimp simp add: piecewise_differentiable_on_def continuous_on_joinpaths_D1)
   2.390 +  apply (rule_tac x="insert 1 ((op*2)`s)" in exI)
   2.391 +  apply simp
   2.392 +  apply (intro ballI)
   2.393 +  apply (rule_tac d="dist (x/2) (1/2)" and f = "(g1 +++ g2) o (op*(inverse 2))" in differentiable_transform_at)
   2.394 +  apply (auto simp: dist_real_def joinpaths_def)
   2.395 +  apply (rule differentiable_chain_at derivative_intros | force)+
   2.396 +  done
   2.397 +
   2.398 +lemma piecewise_differentiable_D2:
   2.399 +    "\<lbrakk>(g1 +++ g2) piecewise_differentiable_on {0..1}; pathfinish g1 = pathstart g2\<rbrakk>
   2.400 +    \<Longrightarrow> g2 piecewise_differentiable_on {0..1}"
   2.401 +  apply (clarsimp simp add: piecewise_differentiable_on_def continuous_on_joinpaths_D2)
   2.402 +  apply (rule_tac x="insert 0 ((\<lambda>x. 2*x-1)`s)" in exI)
   2.403 +  apply simp
   2.404 +  apply (intro ballI)
   2.405 +  apply (rule_tac d="dist ((x+1)/2) (1/2)" and f = "(g1 +++ g2) o (\<lambda>x. (x+1)/2)" in differentiable_transform_at)
   2.406 +  apply (auto simp: dist_real_def joinpaths_def abs_if field_simps split: split_if_asm)
   2.407 +  apply (rule differentiable_chain_at derivative_intros | force simp: divide_simps)+
   2.408 +  done
   2.409 +
   2.410 +lemma valid_path_join_D1: "valid_path (g1 +++ g2) \<Longrightarrow> valid_path g1"
   2.411 +  by (simp add: valid_path_def piecewise_differentiable_D1)
   2.412 +
   2.413 +lemma valid_path_join_D2: "\<lbrakk>valid_path (g1 +++ g2); pathfinish g1 = pathstart g2\<rbrakk> \<Longrightarrow> valid_path g2"
   2.414 +  by (simp add: valid_path_def piecewise_differentiable_D2)
   2.415 +
   2.416 +lemma valid_path_join_eq [simp]:
   2.417 +    "pathfinish g1 = pathstart g2 \<Longrightarrow> (valid_path(g1 +++ g2) \<longleftrightarrow> valid_path g1 \<and> valid_path g2)"
   2.418 +  using valid_path_join_D1 valid_path_join_D2 valid_path_join by blast
   2.419 +
   2.420 +lemma has_path_integral_join:
   2.421 +  assumes "(f has_path_integral i1) g1" "(f has_path_integral i2) g2"
   2.422 +          "valid_path g1" "valid_path g2"
   2.423 +    shows "(f has_path_integral (i1 + i2)) (g1 +++ g2)"
   2.424 +proof -
   2.425 +  obtain s1 s2
   2.426 +    where s1: "finite s1" "\<forall>x\<in>{0..1} - s1. g1 differentiable at x"
   2.427 +      and s2: "finite s2" "\<forall>x\<in>{0..1} - s2. g2 differentiable at x"
   2.428 +    using assms
   2.429 +    by (auto simp: valid_path_def piecewise_differentiable_on_def)
   2.430 +  have 1: "((\<lambda>x. f (g1 x) * vector_derivative g1 (at x)) has_integral i1) {0..1}"
   2.431 +   and 2: "((\<lambda>x. f (g2 x) * vector_derivative g2 (at x)) has_integral i2) {0..1}"
   2.432 +    using assms
   2.433 +    by (auto simp: has_path_integral)
   2.434 +  have i1: "((\<lambda>x. (2*f (g1 (2*x))) * vector_derivative g1 (at (2*x))) has_integral i1) {0..1/2}"
   2.435 +   and i2: "((\<lambda>x. (2*f (g2 (2*x - 1))) * vector_derivative g2 (at (2*x - 1))) has_integral i2) {1/2..1}"
   2.436 +    using has_integral_affinity01 [OF 1, where m= 2 and c=0, THEN has_integral_cmul [where c=2]]
   2.437 +          has_integral_affinity01 [OF 2, where m= 2 and c="-1", THEN has_integral_cmul [where c=2]]
   2.438 +    by (simp_all only: image_affinity_atLeastAtMost_div_diff, simp_all add: scaleR_conv_of_real mult_ac)
   2.439 +  have g1: "\<lbrakk>0 \<le> z; z*2 < 1; z*2 \<notin> s1\<rbrakk> \<Longrightarrow>
   2.440 +            vector_derivative (\<lambda>x. if x*2 \<le> 1 then g1 (2*x) else g2 (2*x - 1)) (at z) =
   2.441 +            2 *\<^sub>R vector_derivative g1 (at (z*2))" for z
   2.442 +    apply (rule vector_derivative_at [OF has_vector_derivative_transform_at [of "\<bar>z - 1/2\<bar>" _ "(\<lambda>x. g1(2*x))"]])
   2.443 +    apply (simp_all add: dist_real_def abs_if split: split_if_asm)
   2.444 +    apply (rule vector_diff_chain_at [of "\<lambda>x. 2*x" 2 _ g1, simplified o_def])
   2.445 +    apply (simp add: has_vector_derivative_def has_derivative_def bounded_linear_mult_left)
   2.446 +    using s1
   2.447 +    apply (auto simp: algebra_simps vector_derivative_works)
   2.448 +    done
   2.449 +  have g2: "\<lbrakk>1 < z*2; z \<le> 1; z*2 - 1 \<notin> s2\<rbrakk> \<Longrightarrow>
   2.450 +            vector_derivative (\<lambda>x. if x*2 \<le> 1 then g1 (2*x) else g2 (2*x - 1)) (at z) =
   2.451 +            2 *\<^sub>R vector_derivative g2 (at (z*2 - 1))" for z
   2.452 +    apply (rule vector_derivative_at [OF has_vector_derivative_transform_at [of "\<bar>z - 1/2\<bar>" _ "(\<lambda>x. g2 (2*x - 1))"]])
   2.453 +    apply (simp_all add: dist_real_def abs_if split: split_if_asm)
   2.454 +    apply (rule vector_diff_chain_at [of "\<lambda>x. 2*x - 1" 2 _ g2, simplified o_def])
   2.455 +    apply (simp add: has_vector_derivative_def has_derivative_def bounded_linear_mult_left)
   2.456 +    using s2
   2.457 +    apply (auto simp: algebra_simps vector_derivative_works)
   2.458 +    done
   2.459 +  have "((\<lambda>x. f ((g1 +++ g2) x) * vector_derivative (g1 +++ g2) (at x)) has_integral i1) {0..1/2}"
   2.460 +    apply (rule has_integral_spike_finite [OF _ _ i1, of "insert (1/2) (op*2 -` s1)"])
   2.461 +    using s1
   2.462 +    apply (force intro: finite_vimageI [where h = "op*2"] inj_onI)
   2.463 +    apply (clarsimp simp add: joinpaths_def scaleR_conv_of_real mult_ac g1)
   2.464 +    done
   2.465 +  moreover have "((\<lambda>x. f ((g1 +++ g2) x) * vector_derivative (g1 +++ g2) (at x)) has_integral i2) {1/2..1}"
   2.466 +    apply (rule has_integral_spike_finite [OF _ _ i2, of "insert (1/2) ((\<lambda>x. 2*x-1) -` s2)"])
   2.467 +    using s2
   2.468 +    apply (force intro: finite_vimageI [where h = "\<lambda>x. 2*x-1"] inj_onI)
   2.469 +    apply (clarsimp simp add: joinpaths_def scaleR_conv_of_real mult_ac g2)
   2.470 +    done
   2.471 +  ultimately
   2.472 +  show ?thesis
   2.473 +    apply (simp add: has_path_integral)
   2.474 +    apply (rule has_integral_combine [where c = "1/2"], auto)
   2.475 +    done
   2.476 +qed
   2.477 +
   2.478 +lemma path_integrable_joinI:
   2.479 +  assumes "f path_integrable_on g1" "f path_integrable_on g2"
   2.480 +          "valid_path g1" "valid_path g2"
   2.481 +    shows "f path_integrable_on (g1 +++ g2)"
   2.482 +  using assms
   2.483 +  by (meson has_path_integral_join path_integrable_on_def)
   2.484 +
   2.485 +lemma path_integrable_joinD1:
   2.486 +  assumes "f path_integrable_on (g1 +++ g2)" "valid_path g1"
   2.487 +    shows "f path_integrable_on g1"
   2.488 +proof -
   2.489 +  obtain s1
   2.490 +    where s1: "finite s1" "\<forall>x\<in>{0..1} - s1. g1 differentiable at x"
   2.491 +    using assms by (auto simp: valid_path_def piecewise_differentiable_on_def)
   2.492 +  have "(\<lambda>x. f ((g1 +++ g2) (x/2)) * vector_derivative (g1 +++ g2) (at (x/2))) integrable_on {0..1}"
   2.493 +    using assms
   2.494 +    apply (auto simp: path_integrable_on)
   2.495 +    apply (drule integrable_on_subcbox [where a=0 and b="1/2"])
   2.496 +    apply (auto intro: integrable_affinity [of _ 0 "1/2::real" "1/2" 0, simplified])
   2.497 +    done
   2.498 +  then have *: "(\<lambda>x. (f ((g1 +++ g2) (x/2))/2) * vector_derivative (g1 +++ g2) (at (x/2))) integrable_on {0..1}"
   2.499 +    by (force dest: integrable_cmul [where c="1/2"] simp: scaleR_conv_of_real)
   2.500 +  have g1: "\<lbrakk>0 < z; z < 1; z \<notin> s1\<rbrakk> \<Longrightarrow>
   2.501 +            vector_derivative (\<lambda>x. if x*2 \<le> 1 then g1 (2*x) else g2 (2*x - 1)) (at (z/2)) =
   2.502 +            2 *\<^sub>R vector_derivative g1 (at z)"  for z
   2.503 +    apply (rule vector_derivative_at [OF has_vector_derivative_transform_at [of "\<bar>(z-1)/2\<bar>" _ "(\<lambda>x. g1(2*x))"]])
   2.504 +    apply (simp_all add: field_simps dist_real_def abs_if split: split_if_asm)
   2.505 +    apply (rule vector_diff_chain_at [of "\<lambda>x. x*2" 2 _ g1, simplified o_def])
   2.506 +    using s1
   2.507 +    apply (auto simp: vector_derivative_works has_vector_derivative_def has_derivative_def bounded_linear_mult_left)
   2.508 +    done
   2.509 +  show ?thesis
   2.510 +    using s1
   2.511 +    apply (auto simp: path_integrable_on)
   2.512 +    apply (rule integrable_spike_finite [of "{0,1} \<union> s1", OF _ _ *])
   2.513 +    apply (auto simp: joinpaths_def scaleR_conv_of_real g1)
   2.514 +    done
   2.515 +qed
   2.516 +
   2.517 +lemma path_integrable_joinD2: (*FIXME: could combine these proofs*)
   2.518 +  assumes "f path_integrable_on (g1 +++ g2)" "valid_path g2"
   2.519 +    shows "f path_integrable_on g2"
   2.520 +proof -
   2.521 +  obtain s2
   2.522 +    where s2: "finite s2" "\<forall>x\<in>{0..1} - s2. g2 differentiable at x"
   2.523 +    using assms by (auto simp: valid_path_def piecewise_differentiable_on_def)
   2.524 +  have "(\<lambda>x. f ((g1 +++ g2) (x/2 + 1/2)) * vector_derivative (g1 +++ g2) (at (x/2 + 1/2))) integrable_on {0..1}"
   2.525 +    using assms
   2.526 +    apply (auto simp: path_integrable_on)
   2.527 +    apply (drule integrable_on_subcbox [where a="1/2" and b=1], auto)
   2.528 +    apply (drule integrable_affinity [of _ "1/2::real" 1 "1/2" "1/2", simplified])
   2.529 +    apply (simp add: image_affinity_atLeastAtMost_diff)
   2.530 +    done
   2.531 +  then have *: "(\<lambda>x. (f ((g1 +++ g2) (x/2 + 1/2))/2) * vector_derivative (g1 +++ g2) (at (x/2 + 1/2)))
   2.532 +                integrable_on {0..1}"
   2.533 +    by (auto dest: integrable_cmul [where c="1/2"] simp: scaleR_conv_of_real)
   2.534 +  have g2: "\<lbrakk>0 < z; z < 1; z \<notin> s2\<rbrakk> \<Longrightarrow>
   2.535 +            vector_derivative (\<lambda>x. if x*2 \<le> 1 then g1 (2*x) else g2 (2*x - 1)) (at (z/2+1/2)) =
   2.536 +            2 *\<^sub>R vector_derivative g2 (at z)" for z
   2.537 +    apply (rule vector_derivative_at [OF has_vector_derivative_transform_at [of "\<bar>z/2\<bar>" _ "(\<lambda>x. g2(2*x-1))"]])
   2.538 +    apply (simp_all add: field_simps dist_real_def abs_if split: split_if_asm)
   2.539 +    apply (rule vector_diff_chain_at [of "\<lambda>x. x*2-1" 2 _ g2, simplified o_def])
   2.540 +    using s2
   2.541 +    apply (auto simp: has_vector_derivative_def has_derivative_def bounded_linear_mult_left
   2.542 +                      vector_derivative_works add_divide_distrib)
   2.543 +    done
   2.544 +  show ?thesis
   2.545 +    using s2
   2.546 +    apply (auto simp: path_integrable_on)
   2.547 +    apply (rule integrable_spike_finite [of "{0,1} \<union> s2", OF _ _ *])
   2.548 +    apply (auto simp: joinpaths_def scaleR_conv_of_real g2)
   2.549 +    done
   2.550 +qed
   2.551 +
   2.552 +lemma path_integrable_join [simp]:
   2.553 +  shows
   2.554 +    "\<lbrakk>valid_path g1; valid_path g2\<rbrakk>
   2.555 +     \<Longrightarrow> f path_integrable_on (g1 +++ g2) \<longleftrightarrow> f path_integrable_on g1 \<and> f path_integrable_on g2"
   2.556 +using path_integrable_joinD1 path_integrable_joinD2 path_integrable_joinI by blast
   2.557 +
   2.558 +lemma path_integral_join [simp]:
   2.559 +  shows
   2.560 +    "\<lbrakk>f path_integrable_on g1; f path_integrable_on g2; valid_path g1; valid_path g2\<rbrakk>
   2.561 +        \<Longrightarrow> path_integral (g1 +++ g2) f = path_integral g1 f + path_integral g2 f"
   2.562 +  by (simp add: has_path_integral_integral has_path_integral_join path_integral_unique)
   2.563 +
   2.564 +
   2.565 +subsection\<open>Shifting the starting point of a (closed) path\<close>
   2.566 +
   2.567 +lemma shiftpath_alt_def: "shiftpath a f = (\<lambda>x. if x \<le> 1-a then f (a + x) else f (a + x - 1))"
   2.568 +  by (auto simp: shiftpath_def)
   2.569 +
   2.570 +lemma valid_path_shiftpath [intro]:
   2.571 +  assumes "valid_path g" "pathfinish g = pathstart g" "a \<in> {0..1}"
   2.572 +    shows "valid_path(shiftpath a g)"
   2.573 +  using assms
   2.574 +  apply (auto simp: valid_path_def shiftpath_alt_def)
   2.575 +  apply (rule piecewise_differentiable_cases)
   2.576 +  apply (auto simp: algebra_simps)
   2.577 +  apply (rule piecewise_differentiable_affine [of g 1 a, simplified o_def scaleR_one])
   2.578 +  apply (auto simp: pathfinish_def pathstart_def elim: piecewise_differentiable_on_subset)
   2.579 +  apply (rule piecewise_differentiable_affine [of g 1 "a-1", simplified o_def scaleR_one algebra_simps])
   2.580 +  apply (auto simp: pathfinish_def pathstart_def elim: piecewise_differentiable_on_subset)
   2.581 +  done
   2.582 +
   2.583 +lemma has_path_integral_shiftpath:
   2.584 +  assumes f: "(f has_path_integral i) g" "valid_path g"
   2.585 +      and a: "a \<in> {0..1}"
   2.586 +    shows "(f has_path_integral i) (shiftpath a g)"
   2.587 +proof -
   2.588 +  obtain s
   2.589 +    where s: "finite s" and g: "\<forall>x\<in>{0..1} - s. g differentiable at x"
   2.590 +    using assms by (auto simp: valid_path_def piecewise_differentiable_on_def)
   2.591 +  have *: "((\<lambda>x. f (g x) * vector_derivative g (at x)) has_integral i) {0..1}"
   2.592 +    using assms by (auto simp: has_path_integral)
   2.593 +  then have i: "i = integral {a..1} (\<lambda>x. f (g x) * vector_derivative g (at x)) +
   2.594 +                    integral {0..a} (\<lambda>x. f (g x) * vector_derivative g (at x))"
   2.595 +    apply (rule has_integral_unique)
   2.596 +    apply (subst add.commute)
   2.597 +    apply (subst Integration.integral_combine)
   2.598 +    using assms * integral_unique by auto
   2.599 +  { fix x
   2.600 +    have "0 \<le> x \<Longrightarrow> x + a < 1 \<Longrightarrow> x \<notin> (\<lambda>x. x - a) ` s \<Longrightarrow>
   2.601 +         vector_derivative (shiftpath a g) (at x) = vector_derivative g (at (x + a))"
   2.602 +      unfolding shiftpath_def
   2.603 +      apply (rule vector_derivative_at [OF has_vector_derivative_transform_at [of "dist(1-a) x" _ "(\<lambda>x. g(a+x))"]])
   2.604 +        apply (auto simp: field_simps dist_real_def abs_if split: split_if_asm)
   2.605 +      apply (rule vector_diff_chain_at [of "\<lambda>x. x+a" 1 _ g, simplified o_def scaleR_one])
   2.606 +       apply (intro derivative_eq_intros | simp)+
   2.607 +      using g
   2.608 +       apply (drule_tac x="x+a" in bspec)
   2.609 +      using a apply (auto simp: has_vector_derivative_def vector_derivative_works image_def add.commute)
   2.610 +      done
   2.611 +  } note vd1 = this
   2.612 +  { fix x
   2.613 +    have "1 < x + a \<Longrightarrow> x \<le> 1 \<Longrightarrow> x \<notin> (\<lambda>x. x - a + 1) ` s \<Longrightarrow>
   2.614 +          vector_derivative (shiftpath a g) (at x) = vector_derivative g (at (x + a - 1))"
   2.615 +      unfolding shiftpath_def
   2.616 +      apply (rule vector_derivative_at [OF has_vector_derivative_transform_at [of "dist (1-a) x" _ "(\<lambda>x. g(a+x-1))"]])
   2.617 +        apply (auto simp: field_simps dist_real_def abs_if split: split_if_asm)
   2.618 +      apply (rule vector_diff_chain_at [of "\<lambda>x. x+a-1" 1 _ g, simplified o_def scaleR_one])
   2.619 +       apply (intro derivative_eq_intros | simp)+
   2.620 +      using g
   2.621 +      apply (drule_tac x="x+a-1" in bspec)
   2.622 +      using a apply (auto simp: has_vector_derivative_def vector_derivative_works image_def add.commute)
   2.623 +      done
   2.624 +  } note vd2 = this
   2.625 +  have va1: "(\<lambda>x. f (g x) * vector_derivative g (at x)) integrable_on ({a..1})"
   2.626 +    using * a   by (fastforce intro: integrable_subinterval_real)
   2.627 +  have v0a: "(\<lambda>x. f (g x) * vector_derivative g (at x)) integrable_on ({0..a})"
   2.628 +    apply (rule integrable_subinterval_real)
   2.629 +    using * a by auto
   2.630 +  have "((\<lambda>x. f (shiftpath a g x) * vector_derivative (shiftpath a g) (at x))
   2.631 +        has_integral  integral {a..1} (\<lambda>x. f (g x) * vector_derivative g (at x)))  {0..1 - a}"
   2.632 +    apply (rule has_integral_spike_finite
   2.633 +             [where s = "{1-a} \<union> (\<lambda>x. x-a) ` s" and f = "\<lambda>x. f(g(a+x)) * vector_derivative g (at(a+x))"])
   2.634 +      using s apply blast
   2.635 +     using a apply (auto simp: algebra_simps vd1)
   2.636 +     apply (force simp: shiftpath_def add.commute)
   2.637 +    using has_integral_affinity [where m=1 and c=a, simplified, OF integrable_integral [OF va1]]
   2.638 +    apply (simp add: image_affinity_atLeastAtMost_diff [where m=1 and c=a, simplified] add.commute)
   2.639 +    done
   2.640 +  moreover
   2.641 +  have "((\<lambda>x. f (shiftpath a g x) * vector_derivative (shiftpath a g) (at x))
   2.642 +        has_integral  integral {0..a} (\<lambda>x. f (g x) * vector_derivative g (at x)))  {1 - a..1}"
   2.643 +    apply (rule has_integral_spike_finite
   2.644 +             [where s = "{1-a} \<union> (\<lambda>x. x-a+1) ` s" and f = "\<lambda>x. f(g(a+x-1)) * vector_derivative g (at(a+x-1))"])
   2.645 +      using s apply blast
   2.646 +     using a apply (auto simp: algebra_simps vd2)
   2.647 +     apply (force simp: shiftpath_def add.commute)
   2.648 +    using has_integral_affinity [where m=1 and c="a-1", simplified, OF integrable_integral [OF v0a]]
   2.649 +    apply (simp add: image_affinity_atLeastAtMost [where m=1 and c="1-a", simplified])
   2.650 +    apply (simp add: algebra_simps)
   2.651 +    done
   2.652 +  ultimately show ?thesis
   2.653 +    using a
   2.654 +    by (auto simp: i has_path_integral intro: has_integral_combine [where c = "1-a"])
   2.655 +qed
   2.656 +
   2.657 +lemma has_path_integral_shiftpath_D:
   2.658 +  assumes "(f has_path_integral i) (shiftpath a g)"
   2.659 +          "valid_path g" "pathfinish g = pathstart g" "a \<in> {0..1}"
   2.660 +    shows "(f has_path_integral i) g"
   2.661 +proof -
   2.662 +  obtain s
   2.663 +    where s: "finite s" and g: "\<forall>x\<in>{0..1} - s. g differentiable at x"
   2.664 +    using assms by (auto simp: valid_path_def piecewise_differentiable_on_def)
   2.665 +  { fix x
   2.666 +    assume x: "0 < x" "x < 1" "x \<notin> s"
   2.667 +    then have gx: "g differentiable at x"
   2.668 +      using g by auto
   2.669 +    have "vector_derivative g (at x within {0..1}) =
   2.670 +          vector_derivative (shiftpath (1 - a) (shiftpath a g)) (at x within {0..1})"
   2.671 +      apply (rule vector_derivative_at_within_ivl
   2.672 +                  [OF has_vector_derivative_transform_within_open
   2.673 +                      [of "{0<..<1}-s" _ "(shiftpath (1 - a) (shiftpath a g))"]])
   2.674 +      using s g assms x
   2.675 +      apply (auto simp: finite_imp_closed open_Diff shiftpath_shiftpath
   2.676 +                        vector_derivative_within_interior vector_derivative_works [symmetric])
   2.677 +      apply (rule Derivative.differentiable_transform_at [of "min x (1-x)", OF _ _ gx])
   2.678 +      apply (auto simp: dist_real_def shiftpath_shiftpath abs_if)
   2.679 +      done
   2.680 +  } note vd = this
   2.681 +  have fi: "(f has_path_integral i) (shiftpath (1 - a) (shiftpath a g))"
   2.682 +    using assms  by (auto intro!: has_path_integral_shiftpath)
   2.683 +  show ?thesis
   2.684 +    apply (simp add: has_path_integral_def)
   2.685 +    apply (rule has_integral_spike_finite [of "{0,1} \<union> s", OF _ _  fi [unfolded has_path_integral_def]])
   2.686 +    using s assms vd
   2.687 +    apply (auto simp: Path_Connected.shiftpath_shiftpath)
   2.688 +    done
   2.689 +qed
   2.690 +
   2.691 +lemma has_path_integral_shiftpath_eq:
   2.692 +  assumes "valid_path g" "pathfinish g = pathstart g" "a \<in> {0..1}"
   2.693 +    shows "(f has_path_integral i) (shiftpath a g) \<longleftrightarrow> (f has_path_integral i) g"
   2.694 +  using assms has_path_integral_shiftpath has_path_integral_shiftpath_D by blast
   2.695 +
   2.696 +lemma path_integral_shiftpath:
   2.697 +  assumes "valid_path g" "pathfinish g = pathstart g" "a \<in> {0..1}"
   2.698 +    shows "path_integral (shiftpath a g) f = path_integral g f"
   2.699 +   using assms by (simp add: path_integral_def has_path_integral_shiftpath_eq)
   2.700 +
   2.701 +
   2.702 +subsection\<open>More about straight-line paths\<close>
   2.703 +
   2.704 +lemma has_vector_derivative_linepath_within:
   2.705 +    "(linepath a b has_vector_derivative (b - a)) (at x within s)"
   2.706 +apply (simp add: linepath_def has_vector_derivative_def algebra_simps)
   2.707 +apply (rule derivative_eq_intros | simp)+
   2.708 +done
   2.709 +
   2.710 +lemma valid_path_linepath [iff]: "valid_path (linepath a b)"
   2.711 +  apply (simp add: valid_path_def)
   2.712 +  apply (rule differentiable_on_imp_piecewise_differentiable)
   2.713 +  apply (simp add: differentiable_on_def differentiable_def)
   2.714 +  using has_vector_derivative_def has_vector_derivative_linepath_within by blast
   2.715 +
   2.716 +lemma vector_derivative_linepath_within:
   2.717 +    "x \<in> {0..1} \<Longrightarrow> vector_derivative (linepath a b) (at x within {0..1}) = b - a"
   2.718 +  apply (rule vector_derivative_within_closed_interval [of 0 "1::real", simplified])
   2.719 +  apply (auto simp: has_vector_derivative_linepath_within)
   2.720 +  done
   2.721 +
   2.722 +lemma vector_derivative_linepath_at: "vector_derivative (linepath a b) (at x) = b - a"
   2.723 +  by (simp add: has_vector_derivative_linepath_within vector_derivative_at)
   2.724 +
   2.725 +lemma has_path_integral_linepath:
   2.726 +  shows "(f has_path_integral i) (linepath a b) \<longleftrightarrow>
   2.727 +         ((\<lambda>x. f(linepath a b x) * (b - a)) has_integral i) {0..1}"
   2.728 +  by (simp add: has_path_integral vector_derivative_linepath_at)
   2.729 +
   2.730 +lemma linepath_in_path:
   2.731 +  shows "x \<in> {0..1} \<Longrightarrow> linepath a b x \<in> closed_segment a b"
   2.732 +  by (auto simp: segment linepath_def)
   2.733 +
   2.734 +lemma linepath_image_01: "linepath a b ` {0..1} = closed_segment a b"
   2.735 +  by (auto simp: segment linepath_def)
   2.736 +
   2.737 +lemma linepath_in_convex_hull:
   2.738 +    fixes x::real
   2.739 +    assumes a: "a \<in> convex hull s"
   2.740 +        and b: "b \<in> convex hull s"
   2.741 +        and x: "0\<le>x" "x\<le>1"
   2.742 +       shows "linepath a b x \<in> convex hull s"
   2.743 +  apply (rule closed_segment_subset_convex_hull [OF a b, THEN subsetD])
   2.744 +  using x
   2.745 +  apply (auto simp: linepath_image_01 [symmetric])
   2.746 +  done
   2.747 +
   2.748 +lemma Re_linepath: "Re(linepath (of_real a) (of_real b) x) = (1 - x)*a + x*b"
   2.749 +  by (simp add: linepath_def)
   2.750 +
   2.751 +lemma Im_linepath: "Im(linepath (of_real a) (of_real b) x) = 0"
   2.752 +  by (simp add: linepath_def)
   2.753 +
   2.754 +lemma linepath_of_real: "(linepath (of_real a) (of_real b) x) = of_real ((1 - x)*a + x*b)"
   2.755 +  by (simp add: scaleR_conv_of_real linepath_def)
   2.756 +
   2.757 +lemma of_real_linepath: "of_real (linepath a b x) = linepath (of_real a) (of_real b) x"
   2.758 +  by (metis linepath_of_real mult.right_neutral of_real_def real_scaleR_def)
   2.759 +
   2.760 +lemma has_path_integral_trivial [iff]: "(f has_path_integral 0) (linepath a a)"
   2.761 +  by (simp add: has_path_integral_linepath)
   2.762 +
   2.763 +lemma path_integral_trivial [simp]: "path_integral (linepath a a) f = 0"
   2.764 +  using has_path_integral_trivial path_integral_unique by blast
   2.765 +
   2.766 +
   2.767 +subsection\<open>Relation to subpath construction\<close>
   2.768 +
   2.769 +lemma valid_path_subpath:
   2.770 +  fixes g :: "real \<Rightarrow> 'a :: real_normed_vector"
   2.771 +  assumes "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}"
   2.772 +    shows "valid_path(subpath u v g)"
   2.773 +proof (cases "v=u")
   2.774 +  case True
   2.775 +  then show ?thesis
   2.776 +    by (simp add: valid_path_def subpath_def differentiable_on_def differentiable_on_imp_piecewise_differentiable)
   2.777 +next
   2.778 +  case False
   2.779 +  have "(g o (\<lambda>x. ((v-u) * x + u))) piecewise_differentiable_on {0..1}"
   2.780 +    apply (rule piecewise_differentiable_compose)
   2.781 +      apply (simp add: differentiable_on_def differentiable_on_imp_piecewise_differentiable)
   2.782 +     apply (simp add: image_affinity_atLeastAtMost)
   2.783 +    using assms False
   2.784 +    apply (auto simp: algebra_simps valid_path_def piecewise_differentiable_on_subset)
   2.785 +    apply (subst Int_commute)
   2.786 +    apply (auto simp: inj_on_def algebra_simps crossproduct_eq finite_vimage_IntI)
   2.787 +    done
   2.788 +  then show ?thesis
   2.789 +    by (auto simp: o_def valid_path_def subpath_def)
   2.790 +qed
   2.791 +
   2.792 +lemma has_path_integral_subpath_refl [iff]: "(f has_path_integral 0) (subpath u u g)"
   2.793 +  by (simp add: has_path_integral subpath_def)
   2.794 +
   2.795 +lemma path_integrable_subpath_refl [iff]: "f path_integrable_on (subpath u u g)"
   2.796 +  using has_path_integral_subpath_refl path_integrable_on_def by blast
   2.797 +
   2.798 +lemma path_integral_subpath_refl [simp]: "path_integral (subpath u u g) f = 0"
   2.799 +  by (simp add: has_path_integral_subpath_refl path_integral_unique)
   2.800 +
   2.801 +lemma has_path_integral_subpath:
   2.802 +  assumes f: "f path_integrable_on g" and g: "valid_path g"
   2.803 +      and uv: "u \<in> {0..1}" "v \<in> {0..1}" "u \<le> v"
   2.804 +    shows "(f has_path_integral  integral {u..v} (\<lambda>x. f(g x) * vector_derivative g (at x)))
   2.805 +           (subpath u v g)"
   2.806 +proof (cases "v=u")
   2.807 +  case True
   2.808 +  then show ?thesis
   2.809 +    using f   by (simp add: path_integrable_on_def subpath_def has_path_integral)
   2.810 +next
   2.811 +  case False
   2.812 +  obtain s where s: "\<And>x. x \<in> {0..1} - s \<Longrightarrow> g differentiable at x" and fs: "finite s"
   2.813 +    using g   by (auto simp: valid_path_def piecewise_differentiable_on_def) (blast intro: that)
   2.814 +  have *: "((\<lambda>x. f (g ((v - u) * x + u)) * vector_derivative g (at ((v - u) * x + u)))
   2.815 +            has_integral (1 / (v - u)) * integral {u..v} (\<lambda>t. f (g t) * vector_derivative g (at t)))
   2.816 +           {0..1}"
   2.817 +    using f uv
   2.818 +    apply (simp add: path_integrable_on subpath_def has_path_integral)
   2.819 +    apply (drule integrable_on_subcbox [where a=u and b=v, simplified])
   2.820 +    apply (simp_all add: has_integral_integral)
   2.821 +    apply (drule has_integral_affinity [where m="v-u" and c=u, simplified])
   2.822 +    apply (simp_all add: False image_affinity_atLeastAtMost_div_diff scaleR_conv_of_real)
   2.823 +    apply (simp add: divide_simps False)
   2.824 +    done
   2.825 +  { fix x
   2.826 +    have "x \<in> {0..1} \<Longrightarrow>
   2.827 +           x \<notin> (\<lambda>t. (v-u) *\<^sub>R t + u) -` s \<Longrightarrow>
   2.828 +           vector_derivative (\<lambda>x. g ((v-u) * x + u)) (at x) = (v-u) *\<^sub>R vector_derivative g (at ((v-u) * x + u))"
   2.829 +      apply (rule vector_derivative_at [OF vector_diff_chain_at [simplified o_def]])
   2.830 +      apply (intro derivative_eq_intros | simp)+
   2.831 +      apply (cut_tac s [of "(v - u) * x + u"])
   2.832 +      using uv mult_left_le [of x "v-u"]
   2.833 +      apply (auto simp:  vector_derivative_works)
   2.834 +      done
   2.835 +  } note vd = this
   2.836 +  show ?thesis
   2.837 +    apply (cut_tac has_integral_cmul [OF *, where c = "v-u"])
   2.838 +    using fs assms
   2.839 +    apply (simp add: False subpath_def has_path_integral)
   2.840 +    apply (rule_tac s = "(\<lambda>t. ((v-u) *\<^sub>R t + u)) -` s" in has_integral_spike_finite)
   2.841 +    apply (auto simp: inj_on_def False finite_vimageI vd scaleR_conv_of_real)
   2.842 +    done
   2.843 +qed
   2.844 +
   2.845 +lemma path_integrable_subpath:
   2.846 +  assumes "f path_integrable_on g" "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}"
   2.847 +    shows "f path_integrable_on (subpath u v g)"
   2.848 +  apply (cases u v rule: linorder_class.le_cases)
   2.849 +   apply (metis path_integrable_on_def has_path_integral_subpath [OF assms])
   2.850 +  apply (subst reversepath_subpath [symmetric])
   2.851 +  apply (rule path_integrable_reversepath)
   2.852 +   using assms apply (blast intro: valid_path_subpath)
   2.853 +  apply (simp add: path_integrable_on_def)
   2.854 +  using assms apply (blast intro: has_path_integral_subpath)
   2.855 +  done
   2.856 +
   2.857 +lemma has_integral_integrable_integral: "(f has_integral i) s \<longleftrightarrow> f integrable_on s \<and> integral s f = i"
   2.858 +  by blast
   2.859 +
   2.860 +lemma has_integral_path_integral_subpath:
   2.861 +  assumes "f path_integrable_on g" "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}" "u \<le> v"
   2.862 +    shows "(((\<lambda>x. f(g x) * vector_derivative g (at x)))
   2.863 +            has_integral  path_integral (subpath u v g) f) {u..v}"
   2.864 +  using assms
   2.865 +  apply (auto simp: has_integral_integrable_integral)
   2.866 +  apply (rule integrable_on_subcbox [where a=u and b=v and s = "{0..1}", simplified])
   2.867 +  apply (auto simp: path_integral_unique [OF has_path_integral_subpath] path_integrable_on)
   2.868 +  done
   2.869 +
   2.870 +lemma path_integral_subpath_integral:
   2.871 +  assumes "f path_integrable_on g" "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}" "u \<le> v"
   2.872 +    shows "path_integral (subpath u v g) f =
   2.873 +           integral {u..v} (\<lambda>x. f(g x) * vector_derivative g (at x))"
   2.874 +  using assms has_path_integral_subpath path_integral_unique by blast
   2.875 +
   2.876 +lemma path_integral_subpath_combine_less:
   2.877 +  assumes "f path_integrable_on g" "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}" "w \<in> {0..1}"
   2.878 +          "u<v" "v<w"
   2.879 +    shows "path_integral (subpath u v g) f + path_integral (subpath v w g) f =
   2.880 +           path_integral (subpath u w g) f"
   2.881 +  using assms apply (auto simp: path_integral_subpath_integral)
   2.882 +  apply (rule integral_combine, auto)
   2.883 +  apply (rule integrable_on_subcbox [where a=u and b=w and s = "{0..1}", simplified])
   2.884 +  apply (auto simp: path_integrable_on)
   2.885 +  done
   2.886 +
   2.887 +lemma path_integral_subpath_combine:
   2.888 +  assumes "f path_integrable_on g" "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}" "w \<in> {0..1}"
   2.889 +    shows "path_integral (subpath u v g) f + path_integral (subpath v w g) f =
   2.890 +           path_integral (subpath u w g) f"
   2.891 +proof (cases "u\<noteq>v \<and> v\<noteq>w \<and> u\<noteq>w")
   2.892 +  case True
   2.893 +    have *: "subpath v u g = reversepath(subpath u v g) \<and>
   2.894 +             subpath w u g = reversepath(subpath u w g) \<and>
   2.895 +             subpath w v g = reversepath(subpath v w g)"
   2.896 +      by (auto simp: reversepath_subpath)
   2.897 +    have "u < v \<and> v < w \<or>
   2.898 +          u < w \<and> w < v \<or>
   2.899 +          v < u \<and> u < w \<or>
   2.900 +          v < w \<and> w < u \<or>
   2.901 +          w < u \<and> u < v \<or>
   2.902 +          w < v \<and> v < u"
   2.903 +      using True assms by linarith
   2.904 +    with assms show ?thesis
   2.905 +      using path_integral_subpath_combine_less [of f g u v w]
   2.906 +            path_integral_subpath_combine_less [of f g u w v]
   2.907 +            path_integral_subpath_combine_less [of f g v u w]
   2.908 +            path_integral_subpath_combine_less [of f g v w u]
   2.909 +            path_integral_subpath_combine_less [of f g w u v]
   2.910 +            path_integral_subpath_combine_less [of f g w v u]
   2.911 +      apply simp
   2.912 +      apply (elim disjE)
   2.913 +      apply (auto simp: * path_integral_reversepath path_integrable_subpath
   2.914 +                   valid_path_reversepath valid_path_subpath algebra_simps)
   2.915 +      done
   2.916 +next
   2.917 +  case False
   2.918 +  then show ?thesis
   2.919 +    apply (auto simp: path_integral_subpath_refl)
   2.920 +    using assms
   2.921 +    by (metis eq_neg_iff_add_eq_0 path_integrable_subpath path_integral_reversepath reversepath_subpath valid_path_subpath)
   2.922 +qed
   2.923 +
   2.924 +lemma path_integral_integral:
   2.925 +  shows "path_integral g f = integral {0..1} (\<lambda>x. f (g x) * vector_derivative g (at x))"
   2.926 +  by (simp add: path_integral_def integral_def has_path_integral)
   2.927 +
   2.928 +
   2.929 +subsection\<open>Segments via convex hulls\<close>
   2.930 +
   2.931 +lemma segments_subset_convex_hull:
   2.932 +    "closed_segment a b \<subseteq> (convex hull {a,b,c})"
   2.933 +    "closed_segment a c \<subseteq> (convex hull {a,b,c})"
   2.934 +    "closed_segment b c \<subseteq> (convex hull {a,b,c})"
   2.935 +    "closed_segment b a \<subseteq> (convex hull {a,b,c})"
   2.936 +    "closed_segment c a \<subseteq> (convex hull {a,b,c})"
   2.937 +    "closed_segment c b \<subseteq> (convex hull {a,b,c})"
   2.938 +by (auto simp: segment_convex_hull linepath_of_real  elim!: rev_subsetD [OF _ hull_mono])
   2.939 +
   2.940 +lemma midpoints_in_convex_hull:
   2.941 +  assumes "x \<in> convex hull s" "y \<in> convex hull s"
   2.942 +    shows "midpoint x y \<in> convex hull s"
   2.943 +proof -
   2.944 +  have "(1 - inverse(2)) *\<^sub>R x + inverse(2) *\<^sub>R y \<in> convex hull s"
   2.945 +    apply (rule mem_convex)
   2.946 +    using assms
   2.947 +    apply (auto simp: convex_convex_hull)
   2.948 +    done
   2.949 +  then show ?thesis
   2.950 +    by (simp add: midpoint_def algebra_simps)
   2.951 +qed
   2.952 +
   2.953 +lemma convex_hull_subset:
   2.954 +    "s \<subseteq> convex hull t \<Longrightarrow> convex hull s \<subseteq> convex hull t"
   2.955 +  by (simp add: convex_convex_hull subset_hull)
   2.956 +
   2.957 +lemma not_in_interior_convex_hull_3:
   2.958 +  fixes a :: "complex"
   2.959 +  shows "a \<notin> interior(convex hull {a,b,c})"
   2.960 +        "b \<notin> interior(convex hull {a,b,c})"
   2.961 +        "c \<notin> interior(convex hull {a,b,c})"
   2.962 +  by (auto simp: card_insert_le_m1 not_in_interior_convex_hull)
   2.963 +
   2.964 +
   2.965 +text\<open>Cauchy's theorem where there's a primitive\<close>
   2.966 +
   2.967 +lemma path_integral_primitive_lemma:
   2.968 +  fixes f :: "complex \<Rightarrow> complex" and g :: "real \<Rightarrow> complex"
   2.969 +  assumes "a \<le> b"
   2.970 +      and "\<And>x. x \<in> s \<Longrightarrow> (f has_field_derivative f' x) (at x within s)"
   2.971 +      and "g piecewise_differentiable_on {a..b}"  "\<And>x. x \<in> {a..b} \<Longrightarrow> g x \<in> s"
   2.972 +    shows "((\<lambda>x. f'(g x) * vector_derivative g (at x within {a..b}))
   2.973 +             has_integral (f(g b) - f(g a))) {a..b}"
   2.974 +proof -
   2.975 +  obtain k where k: "finite k" "\<forall>x\<in>{a..b} - k. g differentiable at x" and cg: "continuous_on {a..b} g"
   2.976 +    using assms by (auto simp: piecewise_differentiable_on_def)
   2.977 +  have cfg: "continuous_on {a..b} (\<lambda>x. f (g x))"
   2.978 +    apply (rule continuous_on_compose [OF cg, unfolded o_def])
   2.979 +    using assms
   2.980 +    apply (metis complex_differentiable_def complex_differentiable_imp_continuous_at continuous_on_eq_continuous_within continuous_on_subset image_subset_iff)
   2.981 +    done
   2.982 +  { fix x::real
   2.983 +    assume a: "a < x" and b: "x < b" and xk: "x \<notin> k"
   2.984 +    then have "g differentiable at x within {a..b}"
   2.985 +      using k by (simp add: differentiable_at_withinI)
   2.986 +    then have "(g has_vector_derivative vector_derivative g (at x within {a..b})) (at x within {a..b})"
   2.987 +      by (simp add: vector_derivative_works has_field_derivative_def scaleR_conv_of_real)
   2.988 +    then have gdiff: "(g has_derivative (\<lambda>u. u * vector_derivative g (at x within {a..b}))) (at x within {a..b})"
   2.989 +      by (simp add: has_vector_derivative_def scaleR_conv_of_real)
   2.990 +    have "(f has_field_derivative (f' (g x))) (at (g x) within g ` {a..b})"
   2.991 +      using assms by (metis a atLeastAtMost_iff b DERIV_subset image_subset_iff less_eq_real_def)
   2.992 +    then have fdiff: "(f has_derivative op * (f' (g x))) (at (g x) within g ` {a..b})"
   2.993 +      by (simp add: has_field_derivative_def)
   2.994 +    have "((\<lambda>x. f (g x)) has_vector_derivative f' (g x) * vector_derivative g (at x within {a..b})) (at x within {a..b})"
   2.995 +      using diff_chain_within [OF gdiff fdiff]
   2.996 +      by (simp add: has_vector_derivative_def scaleR_conv_of_real o_def mult_ac)
   2.997 +  } note * = this
   2.998 +  show ?thesis
   2.999 +    apply (rule fundamental_theorem_of_calculus_interior_strong)
  2.1000 +    using k assms cfg *
  2.1001 +    apply (auto simp: at_within_closed_interval)
  2.1002 +    done
  2.1003 +qed
  2.1004 +
  2.1005 +lemma path_integral_primitive:
  2.1006 +  assumes "\<And>x. x \<in> s \<Longrightarrow> (f has_field_derivative f' x) (at x within s)"
  2.1007 +      and "valid_path g" "path_image g \<subseteq> s"
  2.1008 +    shows "(f' has_path_integral (f(pathfinish g) - f(pathstart g))) g"
  2.1009 +  using assms
  2.1010 +  apply (simp add: valid_path_def path_image_def pathfinish_def pathstart_def has_path_integral_def)
  2.1011 +  apply (auto intro!: path_integral_primitive_lemma [of 0 1 s])
  2.1012 +  done
  2.1013 +
  2.1014 +corollary Cauchy_theorem_primitive:
  2.1015 +  assumes "\<And>x. x \<in> s \<Longrightarrow> (f has_field_derivative f' x) (at x within s)"
  2.1016 +      and "valid_path g"  "path_image g \<subseteq> s" "pathfinish g = pathstart g"
  2.1017 +    shows "(f' has_path_integral 0) g"
  2.1018 +  using assms
  2.1019 +  by (metis diff_self path_integral_primitive)
  2.1020 +
  2.1021 +
  2.1022 +text\<open>Existence of path integral for continuous function\<close>
  2.1023 +lemma path_integrable_continuous_linepath:
  2.1024 +  assumes "continuous_on (closed_segment a b) f"
  2.1025 +  shows "f path_integrable_on (linepath a b)"
  2.1026 +proof -
  2.1027 +  have "continuous_on {0..1} ((\<lambda>x. f x * (b - a)) o linepath a b)"
  2.1028 +    apply (rule continuous_on_compose [OF continuous_on_linepath], simp add: linepath_image_01)
  2.1029 +    apply (rule continuous_intros | simp add: assms)+
  2.1030 +    done
  2.1031 +  then show ?thesis
  2.1032 +    apply (simp add: path_integrable_on_def has_path_integral_def integrable_on_def [symmetric])
  2.1033 +    apply (rule integrable_continuous [of 0 "1::real", simplified])
  2.1034 +    apply (rule continuous_on_eq [where f = "\<lambda>x. f(linepath a b x)*(b - a)"])
  2.1035 +    apply (auto simp: vector_derivative_linepath_within)
  2.1036 +    done
  2.1037 +qed
  2.1038 +
  2.1039 +lemma has_field_der_id: "((\<lambda>x. x\<^sup>2 / 2) has_field_derivative x) (at x)"
  2.1040 +  by (rule has_derivative_imp_has_field_derivative)
  2.1041 +     (rule derivative_intros | simp)+
  2.1042 +
  2.1043 +lemma path_integral_id [simp]: "path_integral (linepath a b) (\<lambda>y. y) = (b^2 - a^2)/2"
  2.1044 +  apply (rule path_integral_unique)
  2.1045 +  using path_integral_primitive [of UNIV "\<lambda>x. x^2/2" "\<lambda>x. x" "linepath a b"]
  2.1046 +  apply (auto simp: field_simps has_field_der_id)
  2.1047 +  done
  2.1048 +
  2.1049 +lemma path_integrable_on_const [iff]: "(\<lambda>x. c) path_integrable_on (linepath a b)"
  2.1050 +  by (simp add: continuous_on_const path_integrable_continuous_linepath)
  2.1051 +
  2.1052 +lemma path_integrable_on_id [iff]: "(\<lambda>x. x) path_integrable_on (linepath a b)"
  2.1053 +  by (simp add: continuous_on_id path_integrable_continuous_linepath)
  2.1054 +
  2.1055 +
  2.1056 +subsection\<open>Arithmetical combining theorems\<close>
  2.1057 +
  2.1058 +lemma has_path_integral_neg:
  2.1059 +    "(f has_path_integral i) g \<Longrightarrow> ((\<lambda>x. -(f x)) has_path_integral (-i)) g"
  2.1060 +  by (simp add: has_integral_neg has_path_integral_def)
  2.1061 +
  2.1062 +lemma has_path_integral_add:
  2.1063 +    "\<lbrakk>(f1 has_path_integral i1) g; (f2 has_path_integral i2) g\<rbrakk>
  2.1064 +     \<Longrightarrow> ((\<lambda>x. f1 x + f2 x) has_path_integral (i1 + i2)) g"
  2.1065 +  by (simp add: has_integral_add has_path_integral_def algebra_simps)
  2.1066 +
  2.1067 +lemma has_path_integral_diff:
  2.1068 +  shows "\<lbrakk>(f1 has_path_integral i1) g; (f2 has_path_integral i2) g\<rbrakk>
  2.1069 +         \<Longrightarrow> ((\<lambda>x. f1 x - f2 x) has_path_integral (i1 - i2)) g"
  2.1070 +  by (simp add: has_integral_sub has_path_integral_def algebra_simps)
  2.1071 +
  2.1072 +lemma has_path_integral_lmul:
  2.1073 +  shows "(f has_path_integral i) g
  2.1074 +         \<Longrightarrow> ((\<lambda>x. c * (f x)) has_path_integral (c*i)) g"
  2.1075 +apply (simp add: has_path_integral_def)
  2.1076 +apply (drule has_integral_mult_right)
  2.1077 +apply (simp add: algebra_simps)
  2.1078 +done
  2.1079 +
  2.1080 +lemma has_path_integral_rmul:
  2.1081 +  shows "(f has_path_integral i) g \<Longrightarrow> ((\<lambda>x. (f x) * c) has_path_integral (i*c)) g"
  2.1082 +apply (drule has_path_integral_lmul)
  2.1083 +apply (simp add: mult.commute)
  2.1084 +done
  2.1085 +
  2.1086 +lemma has_path_integral_div:
  2.1087 +  shows "(f has_path_integral i) g \<Longrightarrow> ((\<lambda>x. f x/c) has_path_integral (i/c)) g"
  2.1088 +  by (simp add: field_class.field_divide_inverse) (metis has_path_integral_rmul)
  2.1089 +
  2.1090 +lemma has_path_integral_eq:
  2.1091 +  shows
  2.1092 +    "\<lbrakk>(f has_path_integral y) p; \<And>x. x \<in> path_image p \<Longrightarrow> f x = g x\<rbrakk> \<Longrightarrow> (g has_path_integral y) p"
  2.1093 +apply (simp add: path_image_def has_path_integral_def)
  2.1094 +by (metis (no_types, lifting) image_eqI has_integral_eq)
  2.1095 +
  2.1096 +lemma has_path_integral_bound_linepath:
  2.1097 +  assumes "(f has_path_integral i) (linepath a b)"
  2.1098 +          "0 \<le> B" "\<And>x. x \<in> closed_segment a b \<Longrightarrow> norm(f x) \<le> B"
  2.1099 +    shows "norm i \<le> B * norm(b - a)"
  2.1100 +proof -
  2.1101 +  { fix x::real
  2.1102 +    assume x: "0 \<le> x" "x \<le> 1"
  2.1103 +  have "norm (f (linepath a b x)) *
  2.1104 +        norm (vector_derivative (linepath a b) (at x within {0..1})) \<le> B * norm (b - a)"
  2.1105 +    by (auto intro: mult_mono simp: assms linepath_in_path of_real_linepath vector_derivative_linepath_within x)
  2.1106 +  } note * = this
  2.1107 +  have "norm i \<le> (B * norm (b - a)) * content (cbox 0 (1::real))"
  2.1108 +    apply (rule has_integral_bound
  2.1109 +       [of _ "\<lambda>x. f (linepath a b x) * vector_derivative (linepath a b) (at x within {0..1})"])
  2.1110 +    using assms * unfolding has_path_integral_def
  2.1111 +    apply (auto simp: norm_mult)
  2.1112 +    done
  2.1113 +  then show ?thesis
  2.1114 +    by (auto simp: content_real)
  2.1115 +qed
  2.1116 +
  2.1117 +(*UNUSED
  2.1118 +lemma has_path_integral_bound_linepath_strong:
  2.1119 +  fixes a :: real and f :: "complex \<Rightarrow> real"
  2.1120 +  assumes "(f has_path_integral i) (linepath a b)"
  2.1121 +          "finite k"
  2.1122 +          "0 \<le> B" "\<And>x::real. x \<in> closed_segment a b - k \<Longrightarrow> norm(f x) \<le> B"
  2.1123 +    shows "norm i \<le> B*norm(b - a)"
  2.1124 +*)
  2.1125 +
  2.1126 +lemma has_path_integral_const_linepath: "((\<lambda>x. c) has_path_integral c*(b - a))(linepath a b)"
  2.1127 +  unfolding has_path_integral_linepath
  2.1128 +  by (metis content_real diff_0_right has_integral_const_real lambda_one of_real_1 scaleR_conv_of_real zero_le_one)
  2.1129 +
  2.1130 +lemma has_path_integral_0: "((\<lambda>x. 0) has_path_integral 0) g"
  2.1131 +  by (simp add: has_path_integral_def)
  2.1132 +
  2.1133 +lemma has_path_integral_is_0:
  2.1134 +    "(\<And>z. z \<in> path_image g \<Longrightarrow> f z = 0) \<Longrightarrow> (f has_path_integral 0) g"
  2.1135 +  by (rule has_path_integral_eq [OF has_path_integral_0]) auto
  2.1136 +
  2.1137 +lemma has_path_integral_setsum:
  2.1138 +    "\<lbrakk>finite s; \<And>a. a \<in> s \<Longrightarrow> (f a has_path_integral i a) p\<rbrakk>
  2.1139 +     \<Longrightarrow> ((\<lambda>x. setsum (\<lambda>a. f a x) s) has_path_integral setsum i s) p"
  2.1140 +  by (induction s rule: finite_induct) (auto simp: has_path_integral_0 has_path_integral_add)
  2.1141 +
  2.1142 +
  2.1143 +subsection \<open>Operations on path integrals\<close>
  2.1144 +
  2.1145 +lemma path_integral_const_linepath [simp]: "path_integral (linepath a b) (\<lambda>x. c) = c*(b - a)"
  2.1146 +  by (rule path_integral_unique [OF has_path_integral_const_linepath])
  2.1147 +
  2.1148 +lemma path_integral_neg:
  2.1149 +    "f path_integrable_on g \<Longrightarrow> path_integral g (\<lambda>x. -(f x)) = -(path_integral g f)"
  2.1150 +  by (simp add: path_integral_unique has_path_integral_integral has_path_integral_neg)
  2.1151 +
  2.1152 +lemma path_integral_add:
  2.1153 +    "f1 path_integrable_on g \<Longrightarrow> f2 path_integrable_on g \<Longrightarrow> path_integral g (\<lambda>x. f1 x + f2 x) =
  2.1154 +                path_integral g f1 + path_integral g f2"
  2.1155 +  by (simp add: path_integral_unique has_path_integral_integral has_path_integral_add)
  2.1156 +
  2.1157 +lemma path_integral_diff:
  2.1158 +    "f1 path_integrable_on g \<Longrightarrow> f2 path_integrable_on g \<Longrightarrow> path_integral g (\<lambda>x. f1 x - f2 x) =
  2.1159 +                path_integral g f1 - path_integral g f2"
  2.1160 +  by (simp add: path_integral_unique has_path_integral_integral has_path_integral_diff)
  2.1161 +
  2.1162 +lemma path_integral_lmul:
  2.1163 +  shows "f path_integrable_on g
  2.1164 +           \<Longrightarrow> path_integral g (\<lambda>x. c * f x) = c*path_integral g f"
  2.1165 +  by (simp add: path_integral_unique has_path_integral_integral has_path_integral_lmul)
  2.1166 +
  2.1167 +lemma path_integral_rmul:
  2.1168 +  shows "f path_integrable_on g
  2.1169 +        \<Longrightarrow> path_integral g (\<lambda>x. f x * c) = path_integral g f * c"
  2.1170 +  by (simp add: path_integral_unique has_path_integral_integral has_path_integral_rmul)
  2.1171 +
  2.1172 +lemma path_integral_div:
  2.1173 +  shows "f path_integrable_on g
  2.1174 +        \<Longrightarrow> path_integral g (\<lambda>x. f x / c) = path_integral g f / c"
  2.1175 +  by (simp add: path_integral_unique has_path_integral_integral has_path_integral_div)
  2.1176 +
  2.1177 +lemma path_integral_eq:
  2.1178 +    "(\<And>x. x \<in> path_image p \<Longrightarrow> f x = g x) \<Longrightarrow> path_integral p f = path_integral p g"
  2.1179 +  by (simp add: path_integral_def) (metis has_path_integral_eq)
  2.1180 +
  2.1181 +lemma path_integral_eq_0:
  2.1182 +    "(\<And>z. z \<in> path_image g \<Longrightarrow> f z = 0) \<Longrightarrow> path_integral g f = 0"
  2.1183 +  by (simp add: has_path_integral_is_0 path_integral_unique)
  2.1184 +
  2.1185 +lemma path_integral_bound_linepath:
  2.1186 +  shows
  2.1187 +    "\<lbrakk>f path_integrable_on (linepath a b);
  2.1188 +      0 \<le> B; \<And>x. x \<in> closed_segment a b \<Longrightarrow> norm(f x) \<le> B\<rbrakk>
  2.1189 +     \<Longrightarrow> norm(path_integral (linepath a b) f) \<le> B*norm(b - a)"
  2.1190 +  apply (rule has_path_integral_bound_linepath [of f])
  2.1191 +  apply (auto simp: has_path_integral_integral)
  2.1192 +  done
  2.1193 +
  2.1194 +lemma path_integral_0: "path_integral g (\<lambda>x. 0) = 0"
  2.1195 +  by (simp add: path_integral_unique has_path_integral_0)
  2.1196 +
  2.1197 +lemma path_integral_setsum:
  2.1198 +    "\<lbrakk>finite s; \<And>a. a \<in> s \<Longrightarrow> (f a) path_integrable_on p\<rbrakk>
  2.1199 +     \<Longrightarrow> path_integral p (\<lambda>x. setsum (\<lambda>a. f a x) s) = setsum (\<lambda>a. path_integral p (f a)) s"
  2.1200 +  by (auto simp: path_integral_unique has_path_integral_setsum has_path_integral_integral)
  2.1201 +
  2.1202 +lemma path_integrable_eq:
  2.1203 +    "\<lbrakk>f path_integrable_on p; \<And>x. x \<in> path_image p \<Longrightarrow> f x = g x\<rbrakk> \<Longrightarrow> g path_integrable_on p"
  2.1204 +  unfolding path_integrable_on_def
  2.1205 +  by (metis has_path_integral_eq)
  2.1206 +
  2.1207 +
  2.1208 +subsection \<open>Arithmetic theorems for path integrability\<close>
  2.1209 +
  2.1210 +lemma path_integrable_neg:
  2.1211 +    "f path_integrable_on g \<Longrightarrow> (\<lambda>x. -(f x)) path_integrable_on g"
  2.1212 +  using has_path_integral_neg path_integrable_on_def by blast
  2.1213 +
  2.1214 +lemma path_integrable_add:
  2.1215 +    "\<lbrakk>f1 path_integrable_on g; f2 path_integrable_on g\<rbrakk> \<Longrightarrow> (\<lambda>x. f1 x + f2 x) path_integrable_on g"
  2.1216 +  using has_path_integral_add path_integrable_on_def
  2.1217 +  by fastforce
  2.1218 +
  2.1219 +lemma path_integrable_diff:
  2.1220 +    "\<lbrakk>f1 path_integrable_on g; f2 path_integrable_on g\<rbrakk> \<Longrightarrow> (\<lambda>x. f1 x - f2 x) path_integrable_on g"
  2.1221 +  using has_path_integral_diff path_integrable_on_def
  2.1222 +  by fastforce
  2.1223 +
  2.1224 +lemma path_integrable_lmul:
  2.1225 +    "f path_integrable_on g \<Longrightarrow> (\<lambda>x. c * f x) path_integrable_on g"
  2.1226 +  using has_path_integral_lmul path_integrable_on_def
  2.1227 +  by fastforce
  2.1228 +
  2.1229 +lemma path_integrable_rmul:
  2.1230 +    "f path_integrable_on g \<Longrightarrow> (\<lambda>x. f x * c) path_integrable_on g"
  2.1231 +  using has_path_integral_rmul path_integrable_on_def
  2.1232 +  by fastforce
  2.1233 +
  2.1234 +lemma path_integrable_div:
  2.1235 +    "f path_integrable_on g \<Longrightarrow> (\<lambda>x. f x / c) path_integrable_on g"
  2.1236 +  using has_path_integral_div path_integrable_on_def
  2.1237 +  by fastforce
  2.1238 +
  2.1239 +lemma path_integrable_setsum:
  2.1240 +    "\<lbrakk>finite s; \<And>a. a \<in> s \<Longrightarrow> (f a) path_integrable_on p\<rbrakk>
  2.1241 +     \<Longrightarrow> (\<lambda>x. setsum (\<lambda>a. f a x) s) path_integrable_on p"
  2.1242 +   unfolding path_integrable_on_def
  2.1243 +   by (metis has_path_integral_setsum)
  2.1244 +
  2.1245 +
  2.1246 +subsection\<open>Reversing a path integral\<close>
  2.1247 +
  2.1248 +lemma has_path_integral_reverse_linepath:
  2.1249 +    "(f has_path_integral i) (linepath a b)
  2.1250 +     \<Longrightarrow> (f has_path_integral (-i)) (linepath b a)"
  2.1251 +  using has_path_integral_reversepath valid_path_linepath by fastforce
  2.1252 +
  2.1253 +lemma path_integral_reverse_linepath:
  2.1254 +    "continuous_on (closed_segment a b) f
  2.1255 +     \<Longrightarrow> path_integral (linepath a b) f = - (path_integral(linepath b a) f)"
  2.1256 +apply (rule path_integral_unique)
  2.1257 +apply (rule has_path_integral_reverse_linepath)
  2.1258 +by (simp add: closed_segment_commute path_integrable_continuous_linepath has_path_integral_integral)
  2.1259 +
  2.1260 +
  2.1261 +(* Splitting a path integral in a flat way.*)
  2.1262 +
  2.1263 +lemma has_path_integral_split:
  2.1264 +  assumes f: "(f has_path_integral i) (linepath a c)" "(f has_path_integral j) (linepath c b)"
  2.1265 +      and k: "0 \<le> k" "k \<le> 1"
  2.1266 +      and c: "c - a = k *\<^sub>R (b - a)"
  2.1267 +    shows "(f has_path_integral (i + j)) (linepath a b)"
  2.1268 +proof (cases "k = 0 \<or> k = 1")
  2.1269 +  case True
  2.1270 +  then show ?thesis
  2.1271 +    using assms
  2.1272 +    apply auto
  2.1273 +    apply (metis add.left_neutral has_path_integral_trivial has_path_integral_unique)
  2.1274 +    apply (metis add.right_neutral has_path_integral_trivial has_path_integral_unique)
  2.1275 +    done
  2.1276 +next
  2.1277 +  case False
  2.1278 +  then have k: "0 < k" "k < 1" "complex_of_real k \<noteq> 1"
  2.1279 +    using assms apply auto
  2.1280 +    using of_real_eq_iff by fastforce
  2.1281 +  have c': "c = k *\<^sub>R (b - a) + a"
  2.1282 +    by (metis diff_add_cancel c)
  2.1283 +  have bc: "(b - c) = (1 - k) *\<^sub>R (b - a)"
  2.1284 +    by (simp add: algebra_simps c')
  2.1285 +  { assume *: "((\<lambda>x. f ((1 - x) *\<^sub>R a + x *\<^sub>R c) * (c - a)) has_integral i) {0..1}"
  2.1286 +    have **: "\<And>x. ((k - x) / k) *\<^sub>R a + (x / k) *\<^sub>R c = (1 - x) *\<^sub>R a + x *\<^sub>R b"
  2.1287 +      using False
  2.1288 +      apply (simp add: c' algebra_simps)
  2.1289 +      apply (simp add: real_vector.scale_left_distrib [symmetric] divide_simps)
  2.1290 +      done
  2.1291 +    have "((\<lambda>x. f ((1 - x) *\<^sub>R a + x *\<^sub>R b) * (b - a)) has_integral i) {0..k}"
  2.1292 +      using * k
  2.1293 +      apply -
  2.1294 +      apply (drule has_integral_affinity [of _ _ 0 "1::real" "inverse k" "0", simplified])
  2.1295 +      apply (simp_all add: divide_simps mult.commute [of _ "k"] image_affinity_atLeastAtMost ** c)
  2.1296 +      apply (drule Integration.has_integral_cmul [where c = "inverse k"])
  2.1297 +      apply (simp add: Integration.has_integral_cmul)
  2.1298 +      done
  2.1299 +  } note fi = this
  2.1300 +  { assume *: "((\<lambda>x. f ((1 - x) *\<^sub>R c + x *\<^sub>R b) * (b - c)) has_integral j) {0..1}"
  2.1301 +    have **: "\<And>x. (((1 - x) / (1 - k)) *\<^sub>R c + ((x - k) / (1 - k)) *\<^sub>R b) = ((1 - x) *\<^sub>R a + x *\<^sub>R b)"
  2.1302 +      using k
  2.1303 +      apply (simp add: c' field_simps)
  2.1304 +      apply (simp add: scaleR_conv_of_real divide_simps)
  2.1305 +      apply (simp add: field_simps)
  2.1306 +      done
  2.1307 +    have "((\<lambda>x. f ((1 - x) *\<^sub>R a + x *\<^sub>R b) * (b - a)) has_integral j) {k..1}"
  2.1308 +      using * k
  2.1309 +      apply -
  2.1310 +      apply (drule has_integral_affinity [of _ _ 0 "1::real" "inverse(1 - k)" "-(k/(1 - k))", simplified])
  2.1311 +      apply (simp_all add: divide_simps mult.commute [of _ "1-k"] image_affinity_atLeastAtMost ** bc)
  2.1312 +      apply (drule Integration.has_integral_cmul [where k = "(1 - k) *\<^sub>R j" and c = "inverse (1 - k)"])
  2.1313 +      apply (simp add: Integration.has_integral_cmul)
  2.1314 +      done
  2.1315 +  } note fj = this
  2.1316 +  show ?thesis
  2.1317 +    using f k
  2.1318 +    apply (simp add: has_path_integral_linepath)
  2.1319 +    apply (simp add: linepath_def)
  2.1320 +    apply (rule has_integral_combine [OF _ _ fi fj], simp_all)
  2.1321 +    done
  2.1322 +qed
  2.1323 +
  2.1324 +lemma continuous_on_closed_segment_transform:
  2.1325 +  assumes f: "continuous_on (closed_segment a b) f"
  2.1326 +      and k: "0 \<le> k" "k \<le> 1"
  2.1327 +      and c: "c - a = k *\<^sub>R (b - a)"
  2.1328 +    shows "continuous_on (closed_segment a c) f"
  2.1329 +proof -
  2.1330 +  have c': "c = (1 - k) *\<^sub>R a + k *\<^sub>R b"
  2.1331 +    using c by (simp add: algebra_simps)
  2.1332 +  show "continuous_on (closed_segment a c) f"
  2.1333 +    apply (rule continuous_on_subset [OF f])
  2.1334 +    apply (simp add: segment_convex_hull)
  2.1335 +    apply (rule convex_hull_subset)
  2.1336 +    using assms
  2.1337 +    apply (auto simp: hull_inc c' Convex.mem_convex)
  2.1338 +    done
  2.1339 +qed
  2.1340 +
  2.1341 +lemma path_integral_split:
  2.1342 +  assumes f: "continuous_on (closed_segment a b) f"
  2.1343 +      and k: "0 \<le> k" "k \<le> 1"
  2.1344 +      and c: "c - a = k *\<^sub>R (b - a)"
  2.1345 +    shows "path_integral(linepath a b) f = path_integral(linepath a c) f + path_integral(linepath c b) f"
  2.1346 +proof -
  2.1347 +  have c': "c = (1 - k) *\<^sub>R a + k *\<^sub>R b"
  2.1348 +    using c by (simp add: algebra_simps)
  2.1349 +  have *: "continuous_on (closed_segment a c) f" "continuous_on (closed_segment c b) f"
  2.1350 +    apply (rule_tac [!] continuous_on_subset [OF f])
  2.1351 +    apply (simp_all add: segment_convex_hull)
  2.1352 +    apply (rule_tac [!] convex_hull_subset)
  2.1353 +    using assms
  2.1354 +    apply (auto simp: hull_inc c' Convex.mem_convex)
  2.1355 +    done
  2.1356 +  show ?thesis
  2.1357 +    apply (rule path_integral_unique)
  2.1358 +    apply (rule has_path_integral_split [OF has_path_integral_integral has_path_integral_integral k c])
  2.1359 +    apply (rule path_integrable_continuous_linepath *)+
  2.1360 +    done
  2.1361 +qed
  2.1362 +
  2.1363 +lemma path_integral_split_linepath:
  2.1364 +  assumes f: "continuous_on (closed_segment a b) f"
  2.1365 +      and c: "c \<in> closed_segment a b"
  2.1366 +    shows "path_integral(linepath a b) f = path_integral(linepath a c) f + path_integral(linepath c b) f"
  2.1367 +  using c
  2.1368 +  by (auto simp: closed_segment_def algebra_simps intro!: path_integral_split [OF f])
  2.1369 +
  2.1370 +(* The special case of midpoints used in the main quadrisection.*)
  2.1371 +
  2.1372 +lemma has_path_integral_midpoint:
  2.1373 +  assumes "(f has_path_integral i) (linepath a (midpoint a b))"
  2.1374 +          "(f has_path_integral j) (linepath (midpoint a b) b)"
  2.1375 +    shows "(f has_path_integral (i + j)) (linepath a b)"
  2.1376 +  apply (rule has_path_integral_split [where c = "midpoint a b" and k = "1/2"])
  2.1377 +  using assms
  2.1378 +  apply (auto simp: midpoint_def algebra_simps scaleR_conv_of_real)
  2.1379 +  done
  2.1380 +
  2.1381 +lemma path_integral_midpoint:
  2.1382 +   "continuous_on (closed_segment a b) f
  2.1383 +    \<Longrightarrow> path_integral (linepath a b) f =
  2.1384 +        path_integral (linepath a (midpoint a b)) f + path_integral (linepath (midpoint a b) b) f"
  2.1385 +  apply (rule path_integral_split [where c = "midpoint a b" and k = "1/2"])
  2.1386 +  using assms
  2.1387 +  apply (auto simp: midpoint_def algebra_simps scaleR_conv_of_real)
  2.1388 +  done
  2.1389 +
  2.1390 +
  2.1391 +text\<open>A couple of special case lemmas that are useful below\<close>
  2.1392 +
  2.1393 +lemma triangle_linear_has_chain_integral:
  2.1394 +    "((\<lambda>x. m*x + d) has_path_integral 0) (linepath a b +++ linepath b c +++ linepath c a)"
  2.1395 +  apply (rule Cauchy_theorem_primitive [of UNIV "\<lambda>x. m/2 * x^2 + d*x"])
  2.1396 +  apply (auto intro!: derivative_eq_intros)
  2.1397 +  done
  2.1398 +
  2.1399 +lemma has_chain_integral_chain_integral3:
  2.1400 +     "(f has_path_integral i) (linepath a b +++ linepath b c +++ linepath c d)
  2.1401 +      \<Longrightarrow> path_integral (linepath a b) f + path_integral (linepath b c) f + path_integral (linepath c d) f = i"
  2.1402 +  apply (subst path_integral_unique [symmetric], assumption)
  2.1403 +  apply (drule has_path_integral_integrable)
  2.1404 +  apply (simp add: valid_path_join)
  2.1405 +  done
  2.1406 +
  2.1407 +subsection\<open>Reversing the order in a double path integral\<close>
  2.1408 +
  2.1409 +text\<open>The condition is stronger than needed but it's often true in typical situations\<close>
  2.1410 +
  2.1411 +lemma fst_im_cbox [simp]: "cbox c d \<noteq> {} \<Longrightarrow> (fst ` cbox (a,c) (b,d)) = cbox a b"
  2.1412 +  by (auto simp: cbox_Pair_eq)
  2.1413 +
  2.1414 +lemma snd_im_cbox [simp]: "cbox a b \<noteq> {} \<Longrightarrow> (snd ` cbox (a,c) (b,d)) = cbox c d"
  2.1415 +  by (auto simp: cbox_Pair_eq)
  2.1416 +
  2.1417 +lemma path_integral_swap:
  2.1418 +  assumes fcon:  "continuous_on (path_image g \<times> path_image h) (\<lambda>(y1,y2). f y1 y2)"
  2.1419 +      and vp:    "valid_path g" "valid_path h"
  2.1420 +      and gvcon: "continuous_on {0..1} (\<lambda>t. vector_derivative g (at t))"
  2.1421 +      and hvcon: "continuous_on {0..1} (\<lambda>t. vector_derivative h (at t))"
  2.1422 +  shows "path_integral g (\<lambda>w. path_integral h (f w)) =
  2.1423 +         path_integral h (\<lambda>z. path_integral g (\<lambda>w. f w z))"
  2.1424 +proof -
  2.1425 +  have gcon: "continuous_on {0..1} g" and hcon: "continuous_on {0..1} h"
  2.1426 +    using assms by (auto simp: valid_path_def piecewise_differentiable_on_def)
  2.1427 +  have fgh1: "\<And>x. (\<lambda>t. f (g x) (h t)) = (\<lambda>(y1,y2). f y1 y2) o (\<lambda>t. (g x, h t))"
  2.1428 +    by (rule ext) simp
  2.1429 +  have fgh2: "\<And>x. (\<lambda>t. f (g t) (h x)) = (\<lambda>(y1,y2). f y1 y2) o (\<lambda>t. (g t, h x))"
  2.1430 +    by (rule ext) simp
  2.1431 +  have fcon_im1: "\<And>x. 0 \<le> x \<Longrightarrow> x \<le> 1 \<Longrightarrow> continuous_on ((\<lambda>t. (g x, h t)) ` {0..1}) (\<lambda>(x, y). f x y)"
  2.1432 +    by (rule continuous_on_subset [OF fcon]) (auto simp: path_image_def)
  2.1433 +  have fcon_im2: "\<And>x. 0 \<le> x \<Longrightarrow> x \<le> 1 \<Longrightarrow> continuous_on ((\<lambda>t. (g t, h x)) ` {0..1}) (\<lambda>(x, y). f x y)"
  2.1434 +    by (rule continuous_on_subset [OF fcon]) (auto simp: path_image_def)
  2.1435 +  have vdg: "\<And>y. y \<in> {0..1} \<Longrightarrow> (\<lambda>x. f (g x) (h y) * vector_derivative g (at x)) integrable_on {0..1}"
  2.1436 +    apply (rule integrable_continuous_real)
  2.1437 +    apply (rule continuous_on_mult [OF _ gvcon])
  2.1438 +    apply (subst fgh2)
  2.1439 +    apply (rule fcon_im2 gcon continuous_intros | simp)+
  2.1440 +    done
  2.1441 +  have "(\<lambda>z. vector_derivative g (at (fst z))) = (\<lambda>x. vector_derivative g (at x)) o fst"
  2.1442 +    by auto
  2.1443 +  then have gvcon': "continuous_on (cbox (0, 0) (1, 1::real)) (\<lambda>x. vector_derivative g (at (fst x)))"
  2.1444 +    apply (rule ssubst)
  2.1445 +    apply (rule continuous_intros | simp add: gvcon)+
  2.1446 +    done
  2.1447 +  have "(\<lambda>z. vector_derivative h (at (snd z))) = (\<lambda>x. vector_derivative h (at x)) o snd"
  2.1448 +    by auto
  2.1449 +  then have hvcon': "continuous_on (cbox (0, 0) (1::real, 1)) (\<lambda>x. vector_derivative h (at (snd x)))"
  2.1450 +    apply (rule ssubst)
  2.1451 +    apply (rule continuous_intros | simp add: hvcon)+
  2.1452 +    done
  2.1453 +  have "(\<lambda>x. f (g (fst x)) (h (snd x))) = (\<lambda>(y1,y2). f y1 y2) o (\<lambda>w. ((g o fst) w, (h o snd) w))"
  2.1454 +    by auto
  2.1455 +  then have fgh: "continuous_on (cbox (0, 0) (1, 1)) (\<lambda>x. f (g (fst x)) (h (snd x)))"
  2.1456 +    apply (rule ssubst)
  2.1457 +    apply (rule gcon hcon continuous_intros | simp)+
  2.1458 +    apply (auto simp: path_image_def intro: continuous_on_subset [OF fcon])
  2.1459 +    done
  2.1460 +  have "integral {0..1} (\<lambda>x. path_integral h (f (g x)) * vector_derivative g (at x)) =
  2.1461 +        integral {0..1} (\<lambda>x. path_integral h (\<lambda>y. f (g x) y * vector_derivative g (at x)))"
  2.1462 +    apply (rule integral_cong [OF path_integral_rmul [symmetric]])
  2.1463 +    apply (clarsimp simp: path_integrable_on)
  2.1464 +    apply (rule integrable_continuous_real)
  2.1465 +    apply (rule continuous_on_mult [OF _ hvcon])
  2.1466 +    apply (subst fgh1)
  2.1467 +    apply (rule fcon_im1 hcon continuous_intros | simp)+
  2.1468 +    done
  2.1469 +  also have "... = integral {0..1}
  2.1470 +                     (\<lambda>y. path_integral g (\<lambda>x. f x (h y) * vector_derivative h (at y)))"
  2.1471 +    apply (simp add: path_integral_integral)
  2.1472 +    apply (subst integral_swap_continuous [where 'a = real and 'b = real, of 0 0 1 1, simplified])
  2.1473 +    apply (rule fgh gvcon' hvcon' continuous_intros | simp add: split_def)+
  2.1474 +    apply (simp add: algebra_simps)
  2.1475 +    done
  2.1476 +  also have "... = path_integral h (\<lambda>z. path_integral g (\<lambda>w. f w z))"
  2.1477 +    apply (simp add: path_integral_integral)
  2.1478 +    apply (rule integral_cong)
  2.1479 +    apply (subst integral_mult_left [symmetric])
  2.1480 +    apply (blast intro: vdg)
  2.1481 +    apply (simp add: algebra_simps)
  2.1482 +    done
  2.1483 +  finally show ?thesis
  2.1484 +    by (simp add: path_integral_integral)
  2.1485 +qed
  2.1486 +
  2.1487 +
  2.1488 +subsection\<open>The key quadrisection step\<close>
  2.1489 +
  2.1490 +lemma norm_sum_half:
  2.1491 +  assumes "norm(a + b) >= e"
  2.1492 +    shows "norm a >= e/2 \<or> norm b >= e/2"
  2.1493 +proof -
  2.1494 +  have "e \<le> norm (- a - b)"
  2.1495 +    by (simp add: add.commute assms norm_minus_commute)
  2.1496 +  thus ?thesis
  2.1497 +    using norm_triangle_ineq4 order_trans by fastforce
  2.1498 +qed
  2.1499 +
  2.1500 +lemma norm_sum_lemma:
  2.1501 +  assumes "e \<le> norm (a + b + c + d)"
  2.1502 +    shows "e / 4 \<le> norm a \<or> e / 4 \<le> norm b \<or> e / 4 \<le> norm c \<or> e / 4 \<le> norm d"
  2.1503 +proof -
  2.1504 +  have "e \<le> norm ((a + b) + (c + d))" using assms
  2.1505 +    by (simp add: algebra_simps)
  2.1506 +  then show ?thesis
  2.1507 +    by (auto dest!: norm_sum_half)
  2.1508 +qed
  2.1509 +
  2.1510 +lemma Cauchy_theorem_quadrisection:
  2.1511 +  assumes f: "continuous_on (convex hull {a,b,c}) f"
  2.1512 +      and dist: "dist a b \<le> K" "dist b c \<le> K" "dist c a \<le> K"
  2.1513 +      and e: "e * K^2 \<le>
  2.1514 +              norm (path_integral(linepath a b) f + path_integral(linepath b c) f + path_integral(linepath c a) f)"
  2.1515 +  shows "\<exists>a' b' c'.
  2.1516 +           a' \<in> convex hull {a,b,c} \<and> b' \<in> convex hull {a,b,c} \<and> c' \<in> convex hull {a,b,c} \<and>
  2.1517 +           dist a' b' \<le> K/2  \<and>  dist b' c' \<le> K/2  \<and>  dist c' a' \<le> K/2  \<and>
  2.1518 +           e * (K/2)^2 \<le> norm(path_integral(linepath a' b') f + path_integral(linepath b' c') f + path_integral(linepath c' a') f)"
  2.1519 +proof -
  2.1520 +  note divide_le_eq_numeral1 [simp del]
  2.1521 +  def a' \<equiv> "midpoint b c"
  2.1522 +  def b' \<equiv> "midpoint c a"
  2.1523 +  def c' \<equiv> "midpoint a b"
  2.1524 +  have fabc: "continuous_on (closed_segment a b) f" "continuous_on (closed_segment b c) f" "continuous_on (closed_segment c a) f"
  2.1525 +    using f continuous_on_subset segments_subset_convex_hull by metis+
  2.1526 +  have fcont': "continuous_on (closed_segment c' b') f"
  2.1527 +               "continuous_on (closed_segment a' c') f"
  2.1528 +               "continuous_on (closed_segment b' a') f"
  2.1529 +    unfolding a'_def b'_def c'_def
  2.1530 +    apply (rule continuous_on_subset [OF f],
  2.1531 +           metis midpoints_in_convex_hull convex_hull_subset hull_subset insert_subset segment_convex_hull)+
  2.1532 +    done
  2.1533 +  let ?pathint = "\<lambda>x y. path_integral(linepath x y) f"
  2.1534 +  have *: "?pathint a b + ?pathint b c + ?pathint c a =
  2.1535 +          (?pathint a c' + ?pathint c' b' + ?pathint b' a) +
  2.1536 +          (?pathint a' c' + ?pathint c' b + ?pathint b a') +
  2.1537 +          (?pathint a' c + ?pathint c b' + ?pathint b' a') +
  2.1538 +          (?pathint a' b' + ?pathint b' c' + ?pathint c' a')"
  2.1539 +    apply (simp add: fcont' path_integral_reverse_linepath)
  2.1540 +    apply (simp add: a'_def b'_def c'_def path_integral_midpoint fabc)
  2.1541 +    done
  2.1542 +  have [simp]: "\<And>x y. cmod (x * 2 - y * 2) = cmod (x - y) * 2"
  2.1543 +    by (metis left_diff_distrib mult.commute norm_mult_numeral1)
  2.1544 +  have [simp]: "\<And>x y. cmod (x - y) = cmod (y - x)"
  2.1545 +    by (simp add: norm_minus_commute)
  2.1546 +  consider "e * K\<^sup>2 / 4 \<le> cmod (?pathint a c' + ?pathint c' b' + ?pathint b' a)" |
  2.1547 +           "e * K\<^sup>2 / 4 \<le> cmod (?pathint a' c' + ?pathint c' b + ?pathint b a')" |
  2.1548 +           "e * K\<^sup>2 / 4 \<le> cmod (?pathint a' c + ?pathint c b' + ?pathint b' a')" |
  2.1549 +           "e * K\<^sup>2 / 4 \<le> cmod (?pathint a' b' + ?pathint b' c' + ?pathint c' a')"
  2.1550 +    using assms
  2.1551 +    apply (simp only: *)
  2.1552 +    apply (blast intro: that dest!: norm_sum_lemma)
  2.1553 +    done
  2.1554 +  then show ?thesis
  2.1555 +  proof cases
  2.1556 +    case 1 then show ?thesis
  2.1557 +      apply (rule_tac x=a in exI)
  2.1558 +      apply (rule exI [where x=c'])
  2.1559 +      apply (rule exI [where x=b'])
  2.1560 +      using assms
  2.1561 +      apply (auto simp: a'_def c'_def b'_def midpoints_in_convex_hull hull_subset [THEN subsetD])
  2.1562 +      apply (auto simp: midpoint_def dist_norm scaleR_conv_of_real divide_simps)
  2.1563 +      done
  2.1564 +  next
  2.1565 +    case 2 then show ?thesis
  2.1566 +      apply (rule_tac x=a' in exI)
  2.1567 +      apply (rule exI [where x=c'])
  2.1568 +      apply (rule exI [where x=b])
  2.1569 +      using assms
  2.1570 +      apply (auto simp: a'_def c'_def b'_def midpoints_in_convex_hull hull_subset [THEN subsetD])
  2.1571 +      apply (auto simp: midpoint_def dist_norm scaleR_conv_of_real divide_simps)
  2.1572 +      done
  2.1573 +  next
  2.1574 +    case 3 then show ?thesis
  2.1575 +      apply (rule_tac x=a' in exI)
  2.1576 +      apply (rule exI [where x=c])
  2.1577 +      apply (rule exI [where x=b'])
  2.1578 +      using assms
  2.1579 +      apply (auto simp: a'_def c'_def b'_def midpoints_in_convex_hull hull_subset [THEN subsetD])
  2.1580 +      apply (auto simp: midpoint_def dist_norm scaleR_conv_of_real divide_simps)
  2.1581 +      done
  2.1582 +  next
  2.1583 +    case 4 then show ?thesis
  2.1584 +      apply (rule_tac x=a' in exI)
  2.1585 +      apply (rule exI [where x=b'])
  2.1586 +      apply (rule exI [where x=c'])
  2.1587 +      using assms
  2.1588 +      apply (auto simp: a'_def c'_def b'_def midpoints_in_convex_hull hull_subset [THEN subsetD])
  2.1589 +      apply (auto simp: midpoint_def dist_norm scaleR_conv_of_real divide_simps)
  2.1590 +      done
  2.1591 +  qed
  2.1592 +qed
  2.1593 +
  2.1594 +subsection\<open>Cauchy's theorem for triangles\<close>
  2.1595 +
  2.1596 +lemma triangle_points_closer:
  2.1597 +  fixes a::complex
  2.1598 +  shows "\<lbrakk>x \<in> convex hull {a,b,c};  y \<in> convex hull {a,b,c}\<rbrakk>
  2.1599 +         \<Longrightarrow> norm(x - y) \<le> norm(a - b) \<or>
  2.1600 +             norm(x - y) \<le> norm(b - c) \<or>
  2.1601 +             norm(x - y) \<le> norm(c - a)"
  2.1602 +  using simplex_extremal_le [of "{a,b,c}"]
  2.1603 +  by (auto simp: norm_minus_commute)
  2.1604 +
  2.1605 +lemma holomorphic_point_small_triangle:
  2.1606 +  assumes x: "x \<in> s"
  2.1607 +      and f: "continuous_on s f"
  2.1608 +      and cd: "f complex_differentiable (at x within s)"
  2.1609 +      and e: "0 < e"
  2.1610 +    shows "\<exists>k>0. \<forall>a b c. dist a b \<le> k \<and> dist b c \<le> k \<and> dist c a \<le> k \<and>
  2.1611 +              x \<in> convex hull {a,b,c} \<and> convex hull {a,b,c} \<subseteq> s
  2.1612 +              \<longrightarrow> norm(path_integral(linepath a b) f + path_integral(linepath b c) f +
  2.1613 +                       path_integral(linepath c a) f)
  2.1614 +                  \<le> e*(dist a b + dist b c + dist c a)^2"
  2.1615 +           (is "\<exists>k>0. \<forall>a b c. _ \<longrightarrow> ?normle a b c")
  2.1616 +proof -
  2.1617 +  have le_of_3: "\<And>a x y z. \<lbrakk>0 \<le> x*y; 0 \<le> x*z; 0 \<le> y*z; a \<le> (e*(x + y + z))*x + (e*(x + y + z))*y + (e*(x + y + z))*z\<rbrakk>
  2.1618 +                     \<Longrightarrow> a \<le> e*(x + y + z)^2"
  2.1619 +    by (simp add: algebra_simps power2_eq_square)
  2.1620 +  have disj_le: "\<lbrakk>x \<le> a \<or> x \<le> b \<or> x \<le> c; 0 \<le> a; 0 \<le> b; 0 \<le> c\<rbrakk> \<Longrightarrow> x \<le> a + b + c"
  2.1621 +             for x::real and a b c
  2.1622 +    by linarith
  2.1623 +  have fabc: "f path_integrable_on linepath a b" "f path_integrable_on linepath b c" "f path_integrable_on linepath c a"
  2.1624 +              if "convex hull {a, b, c} \<subseteq> s" for a b c
  2.1625 +    using segments_subset_convex_hull that
  2.1626 +    by (metis continuous_on_subset f path_integrable_continuous_linepath)+
  2.1627 +  note path_bound = has_path_integral_bound_linepath [simplified norm_minus_commute, OF has_path_integral_integral]
  2.1628 +  { fix f' a b c d
  2.1629 +    assume d: "0 < d"
  2.1630 +       and f': "\<And>y. \<lbrakk>cmod (y - x) \<le> d; y \<in> s\<rbrakk> \<Longrightarrow> cmod (f y - f x - f' * (y - x)) \<le> e * cmod (y - x)"
  2.1631 +       and le: "cmod (a - b) \<le> d" "cmod (b - c) \<le> d" "cmod (c - a) \<le> d"
  2.1632 +       and xc: "x \<in> convex hull {a, b, c}"
  2.1633 +       and s: "convex hull {a, b, c} \<subseteq> s"
  2.1634 +    have pa: "path_integral (linepath a b) f + path_integral (linepath b c) f + path_integral (linepath c a) f =
  2.1635 +              path_integral (linepath a b) (\<lambda>y. f y - f x - f'*(y - x)) +
  2.1636 +              path_integral (linepath b c) (\<lambda>y. f y - f x - f'*(y - x)) +
  2.1637 +              path_integral (linepath c a) (\<lambda>y. f y - f x - f'*(y - x))"
  2.1638 +      apply (simp add: path_integral_diff path_integral_lmul path_integrable_lmul path_integrable_diff fabc [OF s])
  2.1639 +      apply (simp add: field_simps)
  2.1640 +      done
  2.1641 +    { fix y
  2.1642 +      assume yc: "y \<in> convex hull {a,b,c}"
  2.1643 +      have "cmod (f y - f x - f' * (y - x)) \<le> e*norm(y - x)"
  2.1644 +        apply (rule f')
  2.1645 +        apply (metis triangle_points_closer [OF xc yc] le norm_minus_commute order_trans)
  2.1646 +        using s yc by blast
  2.1647 +      also have "... \<le> e * (cmod (a - b) + cmod (b - c) + cmod (c - a))"
  2.1648 +        by (simp add: yc e xc disj_le [OF triangle_points_closer])
  2.1649 +      finally have "cmod (f y - f x - f' * (y - x)) \<le> e * (cmod (a - b) + cmod (b - c) + cmod (c - a))" .
  2.1650 +    } note cm_le = this
  2.1651 +    have "?normle a b c"
  2.1652 +      apply (simp add: dist_norm pa)
  2.1653 +      apply (rule le_of_3)
  2.1654 +      using f' xc s e
  2.1655 +      apply simp_all
  2.1656 +      apply (intro norm_triangle_le add_mono path_bound)
  2.1657 +      apply (simp_all add: path_integral_diff path_integral_lmul path_integrable_lmul path_integrable_diff fabc)
  2.1658 +      apply (blast intro: cm_le elim: dest: segments_subset_convex_hull [THEN subsetD])+
  2.1659 +      done
  2.1660 +  } note * = this
  2.1661 +  show ?thesis
  2.1662 +    using cd e
  2.1663 +    apply (simp add: complex_differentiable_def has_field_derivative_def has_derivative_within_alt approachable_lt_le2 Ball_def)
  2.1664 +    apply (clarify dest!: spec mp)
  2.1665 +    using *
  2.1666 +    apply (simp add: dist_norm, blast)
  2.1667 +    done
  2.1668 +qed
  2.1669 +
  2.1670 +
  2.1671 +(* Hence the most basic theorem for a triangle.*)
  2.1672 +locale Chain =
  2.1673 +  fixes x0 At Follows
  2.1674 +  assumes At0: "At x0 0"
  2.1675 +      and AtSuc: "\<And>x n. At x n \<Longrightarrow> \<exists>x'. At x' (Suc n) \<and> Follows x' x"
  2.1676 +begin
  2.1677 +  primrec f where
  2.1678 +    "f 0 = x0"
  2.1679 +  | "f (Suc n) = (SOME x. At x (Suc n) \<and> Follows x (f n))"
  2.1680 +
  2.1681 +  lemma At: "At (f n) n"
  2.1682 +  proof (induct n)
  2.1683 +    case 0 show ?case
  2.1684 +      by (simp add: At0)
  2.1685 +  next
  2.1686 +    case (Suc n) show ?case
  2.1687 +      by (metis (no_types, lifting) AtSuc [OF Suc] f.simps(2) someI_ex)
  2.1688 +  qed
  2.1689 +
  2.1690 +  lemma Follows: "Follows (f(Suc n)) (f n)"
  2.1691 +    by (metis (no_types, lifting) AtSuc [OF At [of n]] f.simps(2) someI_ex)
  2.1692 +
  2.1693 +  declare f.simps(2) [simp del]
  2.1694 +end
  2.1695 +
  2.1696 +lemma Chain3:
  2.1697 +  assumes At0: "At x0 y0 z0 0"
  2.1698 +      and AtSuc: "\<And>x y z n. At x y z n \<Longrightarrow> \<exists>x' y' z'. At x' y' z' (Suc n) \<and> Follows x' y' z' x y z"
  2.1699 +  obtains f g h where
  2.1700 +    "f 0 = x0" "g 0 = y0" "h 0 = z0"
  2.1701 +                      "\<And>n. At (f n) (g n) (h n) n"
  2.1702 +                       "\<And>n. Follows (f(Suc n)) (g(Suc n)) (h(Suc n)) (f n) (g n) (h n)"
  2.1703 +proof -
  2.1704 +  interpret three: Chain "(x0,y0,z0)" "\<lambda>(x,y,z). At x y z" "\<lambda>(x',y',z'). \<lambda>(x,y,z). Follows x' y' z' x y z"
  2.1705 +    apply unfold_locales
  2.1706 +    using At0 AtSuc by auto
  2.1707 +  show ?thesis
  2.1708 +  apply (rule that [of "\<lambda>n. fst (three.f n)"  "\<lambda>n. fst (snd (three.f n))" "\<lambda>n. snd (snd (three.f n))"])
  2.1709 +  apply simp_all
  2.1710 +  using three.At three.Follows
  2.1711 +  apply (simp_all add: split_beta')
  2.1712 +  done
  2.1713 +qed
  2.1714 +
  2.1715 +lemma Cauchy_theorem_triangle:
  2.1716 +  assumes "f holomorphic_on (convex hull {a,b,c})"
  2.1717 +    shows "(f has_path_integral 0) (linepath a b +++ linepath b c +++ linepath c a)"
  2.1718 +proof -
  2.1719 +  have contf: "continuous_on (convex hull {a,b,c}) f"
  2.1720 +    by (metis assms holomorphic_on_imp_continuous_on)
  2.1721 +  let ?pathint = "\<lambda>x y. path_integral(linepath x y) f"
  2.1722 +  { fix y::complex
  2.1723 +    assume fy: "(f has_path_integral y) (linepath a b +++ linepath b c +++ linepath c a)"
  2.1724 +       and ynz: "y \<noteq> 0"
  2.1725 +    def K \<equiv> "1 + max (dist a b) (max (dist b c) (dist c a))"
  2.1726 +    def e \<equiv> "norm y / K^2"
  2.1727 +    have K1: "K \<ge> 1"  by (simp add: K_def max.coboundedI1)
  2.1728 +    then have K: "K > 0" by linarith
  2.1729 +    have [iff]: "dist a b \<le> K" "dist b c \<le> K" "dist c a \<le> K"
  2.1730 +      by (simp_all add: K_def)
  2.1731 +    have e: "e > 0"
  2.1732 +      unfolding e_def using ynz K1 by simp
  2.1733 +    def At \<equiv> "\<lambda>x y z n. convex hull {x,y,z} \<subseteq> convex hull {a,b,c} \<and>
  2.1734 +                         dist x y \<le> K/2^n \<and> dist y z \<le> K/2^n \<and> dist z x \<le> K/2^n \<and>
  2.1735 +                         norm(?pathint x y + ?pathint y z + ?pathint z x) \<ge> e*(K/2^n)^2"
  2.1736 +    have At0: "At a b c 0"
  2.1737 +      using fy
  2.1738 +      by (simp add: At_def e_def has_chain_integral_chain_integral3)
  2.1739 +    { fix x y z n
  2.1740 +      assume At: "At x y z n"
  2.1741 +      then have contf': "continuous_on (convex hull {x,y,z}) f"
  2.1742 +        using contf At_def continuous_on_subset by blast
  2.1743 +      have "\<exists>x' y' z'. At x' y' z' (Suc n) \<and> convex hull {x',y',z'} \<subseteq> convex hull {x,y,z}"
  2.1744 +        using At
  2.1745 +        apply (simp add: At_def)
  2.1746 +        using  Cauchy_theorem_quadrisection [OF contf', of "K/2^n" e]
  2.1747 +        apply clarsimp
  2.1748 +        apply (rule_tac x="a'" in exI)
  2.1749 +        apply (rule_tac x="b'" in exI)
  2.1750 +        apply (rule_tac x="c'" in exI)
  2.1751 +        apply (simp add: algebra_simps)
  2.1752 +        apply (meson convex_hull_subset empty_subsetI insert_subset subsetCE)
  2.1753 +        done
  2.1754 +    } note AtSuc = this
  2.1755 +    obtain fa fb fc
  2.1756 +      where f0 [simp]: "fa 0 = a" "fb 0 = b" "fc 0 = c"
  2.1757 +        and cosb: "\<And>n. convex hull {fa n, fb n, fc n} \<subseteq> convex hull {a,b,c}"
  2.1758 +        and dist: "\<And>n. dist (fa n) (fb n) \<le> K/2^n"
  2.1759 +                  "\<And>n. dist (fb n) (fc n) \<le> K/2^n"
  2.1760 +                  "\<And>n. dist (fc n) (fa n) \<le> K/2^n"
  2.1761 +        and no: "\<And>n. norm(?pathint (fa n) (fb n) +
  2.1762 +                           ?pathint (fb n) (fc n) +
  2.1763 +                           ?pathint (fc n) (fa n)) \<ge> e * (K/2^n)^2"
  2.1764 +        and conv_le: "\<And>n. convex hull {fa(Suc n), fb(Suc n), fc(Suc n)} \<subseteq> convex hull {fa n, fb n, fc n}"
  2.1765 +      apply (rule Chain3 [of At, OF At0 AtSuc])
  2.1766 +      apply (auto simp: At_def)
  2.1767 +      done
  2.1768 +    have "\<exists>x. \<forall>n. x \<in> convex hull {fa n, fb n, fc n}"
  2.1769 +      apply (rule bounded_closed_nest)
  2.1770 +      apply (simp_all add: compact_imp_closed finite_imp_compact_convex_hull finite_imp_bounded_convex_hull)
  2.1771 +      apply (rule allI)
  2.1772 +      apply (rule transitive_stepwise_le)
  2.1773 +      apply (auto simp: conv_le)
  2.1774 +      done
  2.1775 +    then obtain x where x: "\<And>n. x \<in> convex hull {fa n, fb n, fc n}" by auto
  2.1776 +    then have xin: "x \<in> convex hull {a,b,c}"
  2.1777 +      using assms f0 by blast
  2.1778 +    then have fx: "f complex_differentiable at x within (convex hull {a,b,c})"
  2.1779 +      using assms holomorphic_on_def by blast
  2.1780 +    { fix k n
  2.1781 +      assume k: "0 < k"
  2.1782 +         and le:
  2.1783 +            "\<And>x' y' z'.
  2.1784 +               \<lbrakk>dist x' y' \<le> k; dist y' z' \<le> k; dist z' x' \<le> k;
  2.1785 +                x \<in> convex hull {x',y',z'};
  2.1786 +                convex hull {x',y',z'} \<subseteq> convex hull {a,b,c}\<rbrakk>
  2.1787 +               \<Longrightarrow>
  2.1788 +               cmod (?pathint x' y' + ?pathint y' z' + ?pathint z' x') * 10
  2.1789 +                     \<le> e * (dist x' y' + dist y' z' + dist z' x')\<^sup>2"
  2.1790 +         and Kk: "K / k < 2 ^ n"
  2.1791 +      have "K / 2 ^ n < k" using Kk k
  2.1792 +        by (auto simp: field_simps)
  2.1793 +      then have DD: "dist (fa n) (fb n) \<le> k" "dist (fb n) (fc n) \<le> k" "dist (fc n) (fa n) \<le> k"
  2.1794 +        using dist [of n]  k
  2.1795 +        by linarith+
  2.1796 +      have dle: "(dist (fa n) (fb n) + dist (fb n) (fc n) + dist (fc n) (fa n))\<^sup>2
  2.1797 +               \<le> (3 * K / 2 ^ n)\<^sup>2"
  2.1798 +        using dist [of n] e K
  2.1799 +        by (simp add: abs_le_square_iff [symmetric])
  2.1800 +      have less10: "\<And>x y::real. 0 < x \<Longrightarrow> y \<le> 9*x \<Longrightarrow> y < x*10"
  2.1801 +        by linarith
  2.1802 +      have "e * (dist (fa n) (fb n) + dist (fb n) (fc n) + dist (fc n) (fa n))\<^sup>2 \<le> e * (3 * K / 2 ^ n)\<^sup>2"
  2.1803 +        using ynz dle e mult_le_cancel_left_pos by blast
  2.1804 +      also have "... <
  2.1805 +          cmod (?pathint (fa n) (fb n) + ?pathint (fb n) (fc n) + ?pathint (fc n) (fa n)) * 10"
  2.1806 +        using no [of n] e K
  2.1807 +        apply (simp add: e_def field_simps)
  2.1808 +        apply (simp only: zero_less_norm_iff [symmetric])
  2.1809 +        done
  2.1810 +      finally have False
  2.1811 +        using le [OF DD x cosb] by auto
  2.1812 +    } then
  2.1813 +    have ?thesis
  2.1814 +      using holomorphic_point_small_triangle [OF xin contf fx, of "e/10"] e
  2.1815 +      apply clarsimp
  2.1816 +      apply (rule_tac x1="K/k" in exE [OF real_arch_pow2], blast)
  2.1817 +      done
  2.1818 +  }
  2.1819 +  moreover have "f path_integrable_on (linepath a b +++ linepath b c +++ linepath c a)"
  2.1820 +    by simp (meson contf continuous_on_subset path_integrable_continuous_linepath segments_subset_convex_hull(1)
  2.1821 +                   segments_subset_convex_hull(3) segments_subset_convex_hull(5))
  2.1822 +  ultimately show ?thesis
  2.1823 +    using has_path_integral_integral by fastforce
  2.1824 +qed
  2.1825 +
  2.1826 +
  2.1827 +subsection\<open>Version needing function holomorphic in interior only\<close>
  2.1828 +
  2.1829 +lemma Cauchy_theorem_flat_lemma:
  2.1830 +  assumes f: "continuous_on (convex hull {a,b,c}) f"
  2.1831 +      and c: "c - a = k *\<^sub>R (b - a)"
  2.1832 +      and k: "0 \<le> k"
  2.1833 +    shows "path_integral (linepath a b) f + path_integral (linepath b c) f +
  2.1834 +          path_integral (linepath c a) f = 0"
  2.1835 +proof -
  2.1836 +  have fabc: "continuous_on (closed_segment a b) f" "continuous_on (closed_segment b c) f" "continuous_on (closed_segment c a) f"
  2.1837 +    using f continuous_on_subset segments_subset_convex_hull by metis+
  2.1838 +  show ?thesis
  2.1839 +  proof (cases "k \<le> 1")
  2.1840 +    case True show ?thesis
  2.1841 +      by (simp add: path_integral_split [OF fabc(1) k True c] path_integral_reverse_linepath fabc)
  2.1842 +  next
  2.1843 +    case False then show ?thesis
  2.1844 +      using fabc c
  2.1845 +      apply (subst path_integral_split [of a c f "1/k" b, symmetric])
  2.1846 +      apply (metis closed_segment_commute fabc(3))
  2.1847 +      apply (auto simp: k path_integral_reverse_linepath)
  2.1848 +      done
  2.1849 +  qed
  2.1850 +qed
  2.1851 +
  2.1852 +lemma Cauchy_theorem_flat:
  2.1853 +  assumes f: "continuous_on (convex hull {a,b,c}) f"
  2.1854 +      and c: "c - a = k *\<^sub>R (b - a)"
  2.1855 +    shows "path_integral (linepath a b) f +
  2.1856 +           path_integral (linepath b c) f +
  2.1857 +           path_integral (linepath c a) f = 0"
  2.1858 +proof (cases "0 \<le> k")
  2.1859 +  case True with assms show ?thesis
  2.1860 +    by (blast intro: Cauchy_theorem_flat_lemma)
  2.1861 +next
  2.1862 +  case False
  2.1863 +  have "continuous_on (closed_segment a b) f" "continuous_on (closed_segment b c) f" "continuous_on (closed_segment c a) f"
  2.1864 +    using f continuous_on_subset segments_subset_convex_hull by metis+
  2.1865 +  moreover have "path_integral (linepath b a) f + path_integral (linepath a c) f +
  2.1866 +        path_integral (linepath c b) f = 0"
  2.1867 +    apply (rule Cauchy_theorem_flat_lemma [of b a c f "1-k"])
  2.1868 +    using False c
  2.1869 +    apply (auto simp: f insert_commute scaleR_conv_of_real algebra_simps)
  2.1870 +    done
  2.1871 +  ultimately show ?thesis
  2.1872 +    apply (auto simp: path_integral_reverse_linepath)
  2.1873 +    using add_eq_0_iff by force
  2.1874 +qed
  2.1875 +
  2.1876 +
  2.1877 +lemma Cauchy_theorem_triangle_interior:
  2.1878 +  assumes contf: "continuous_on (convex hull {a,b,c}) f"
  2.1879 +      and holf:  "f holomorphic_on interior (convex hull {a,b,c})"
  2.1880 +     shows "(f has_path_integral 0) (linepath a b +++ linepath b c +++ linepath c a)"
  2.1881 +proof -
  2.1882 +  have fabc: "continuous_on (closed_segment a b) f" "continuous_on (closed_segment b c) f" "continuous_on (closed_segment c a) f"
  2.1883 +    using contf continuous_on_subset segments_subset_convex_hull by metis+
  2.1884 +  have "bounded (f ` (convex hull {a,b,c}))"
  2.1885 +    by (simp add: compact_continuous_image compact_convex_hull compact_imp_bounded contf)
  2.1886 +  then obtain B where "0 < B" and Bnf: "\<And>x. x \<in> convex hull {a,b,c} \<Longrightarrow> norm (f x) \<le> B"
  2.1887 +     by (auto simp: dest!: bounded_pos [THEN iffD1])
  2.1888 +  have "bounded (convex hull {a,b,c})"
  2.1889 +    by (simp add: bounded_convex_hull)
  2.1890 +  then obtain C where C: "0 < C" and Cno: "\<And>y. y \<in> convex hull {a,b,c} \<Longrightarrow> norm y < C"
  2.1891 +    using bounded_pos_less by blast
  2.1892 +  then have diff_2C: "norm(x - y) \<le> 2*C"
  2.1893 +           if x: "x \<in> convex hull {a, b, c}" and y: "y \<in> convex hull {a, b, c}" for x y
  2.1894 +  proof -
  2.1895 +    have "cmod x \<le> C"
  2.1896 +      using x by (meson Cno not_le not_less_iff_gr_or_eq)
  2.1897 +    hence "cmod (x - y) \<le> C + C"
  2.1898 +      using y by (meson Cno add_mono_thms_linordered_field(4) less_eq_real_def norm_triangle_ineq4 order_trans)
  2.1899 +    thus "cmod (x - y) \<le> 2 * C"
  2.1900 +      by (metis mult_2)
  2.1901 +  qed
  2.1902 +  have contf': "continuous_on (convex hull {b,a,c}) f"
  2.1903 +    using contf by (simp add: insert_commute)
  2.1904 +  { fix y::complex
  2.1905 +    assume fy: "(f has_path_integral y) (linepath a b +++ linepath b c +++ linepath c a)"
  2.1906 +       and ynz: "y \<noteq> 0"
  2.1907 +    have pi_eq_y: "path_integral (linepath a b) f + path_integral (linepath b c) f + path_integral (linepath c a) f = y"
  2.1908 +      by (rule has_chain_integral_chain_integral3 [OF fy])
  2.1909 +    have ?thesis
  2.1910 +    proof (cases "c=a \<or> a=b \<or> b=c")
  2.1911 +      case True then show ?thesis
  2.1912 +        using Cauchy_theorem_flat [OF contf, of 0]
  2.1913 +        using has_chain_integral_chain_integral3 [OF fy] ynz
  2.1914 +        by (force simp: fabc path_integral_reverse_linepath)
  2.1915 +    next
  2.1916 +      case False
  2.1917 +      then have car3: "card {a, b, c} = Suc (DIM(complex))"
  2.1918 +        by auto
  2.1919 +      { assume "interior(convex hull {a,b,c}) = {}"
  2.1920 +        then have "collinear{a,b,c}"
  2.1921 +          using interior_convex_hull_eq_empty [OF car3]
  2.1922 +          by (simp add: collinear_3_eq_affine_dependent)
  2.1923 +        then have "False"
  2.1924 +          using False
  2.1925 +          apply (clarsimp simp add: collinear_3 collinear_lemma)
  2.1926 +          apply (drule Cauchy_theorem_flat [OF contf'])
  2.1927 +          using pi_eq_y ynz
  2.1928 +          apply (simp add: fabc add_eq_0_iff path_integral_reverse_linepath)
  2.1929 +          done
  2.1930 +      }
  2.1931 +      then obtain d where d: "d \<in> interior (convex hull {a, b, c})"
  2.1932 +        by blast
  2.1933 +      { fix d1
  2.1934 +        assume d1_pos: "0 < d1"
  2.1935 +           and d1: "\<And>x x'. \<lbrakk>x\<in>convex hull {a, b, c}; x'\<in>convex hull {a, b, c}; cmod (x' - x) < d1\<rbrakk>
  2.1936 +                           \<Longrightarrow> cmod (f x' - f x) < cmod y / (24 * C)"
  2.1937 +        def e      \<equiv> "min 1 (min (d1/(4*C)) ((norm y / 24 / C) / B))"
  2.1938 +        def shrink \<equiv> "\<lambda>x. x - e *\<^sub>R (x - d)"
  2.1939 +        let ?pathint = "\<lambda>x y. path_integral(linepath x y) f"
  2.1940 +        have e: "0 < e" "e \<le> 1" "e \<le> d1 / (4 * C)" "e \<le> cmod y / 24 / C / B"
  2.1941 +          using d1_pos `C>0` `B>0` ynz by (simp_all add: e_def)
  2.1942 +        then have eCB: "24 * e * C * B \<le> cmod y"
  2.1943 +          using `C>0` `B>0`  by (simp add: field_simps)
  2.1944 +        have e_le_d1: "e * (4 * C) \<le> d1"
  2.1945 +          using e `C>0` by (simp add: field_simps)
  2.1946 +        have "shrink a \<in> interior(convex hull {a,b,c})"
  2.1947 +             "shrink b \<in> interior(convex hull {a,b,c})"
  2.1948 +             "shrink c \<in> interior(convex hull {a,b,c})"
  2.1949 +          using d e by (auto simp: hull_inc mem_interior_convex_shrink shrink_def)
  2.1950 +        then have fhp0: "(f has_path_integral 0)
  2.1951 +                (linepath (shrink a) (shrink b) +++ linepath (shrink b) (shrink c) +++ linepath (shrink c) (shrink a))"
  2.1952 +          by (simp add: Cauchy_theorem_triangle holomorphic_on_subset [OF holf] hull_minimal convex_interior)
  2.1953 +        then have f_0_shrink: "?pathint (shrink a) (shrink b) + ?pathint (shrink b) (shrink c) + ?pathint (shrink c) (shrink a) = 0"
  2.1954 +          by (simp add: has_chain_integral_chain_integral3)
  2.1955 +        have fpi_abc: "f path_integrable_on linepath (shrink a) (shrink b)"
  2.1956 +                      "f path_integrable_on linepath (shrink b) (shrink c)"
  2.1957 +                      "f path_integrable_on linepath (shrink c) (shrink a)"
  2.1958 +          using fhp0  by (auto simp: valid_path_join dest: has_path_integral_integrable)
  2.1959 +        have cmod_shr: "\<And>x y. cmod (shrink y - shrink x - (y - x)) = e * cmod (x - y)"
  2.1960 +          using e by (simp add: shrink_def real_vector.scale_right_diff_distrib [symmetric])
  2.1961 +        have sh_eq: "\<And>a b d::complex. (b - e *\<^sub>R (b - d)) - (a - e *\<^sub>R (a - d)) - (b - a) = e *\<^sub>R (a - b)"
  2.1962 +          by (simp add: algebra_simps)
  2.1963 +        have "cmod y / (24 * C) \<le> cmod y / cmod (b - a) / 12"
  2.1964 +          using False `C>0` diff_2C [of b a] ynz
  2.1965 +          by (auto simp: divide_simps hull_inc)
  2.1966 +        have less_C: "\<lbrakk>u \<in> convex hull {a, b, c}; 0 \<le> x; x \<le> 1\<rbrakk> \<Longrightarrow> x * cmod u < C" for x u
  2.1967 +          apply (cases "x=0", simp add: `0<C`)
  2.1968 +          using Cno [of u] mult_left_le_one_le [of "cmod u" x] le_less_trans norm_ge_zero by blast
  2.1969 +        { fix u v
  2.1970 +          assume uv: "u \<in> convex hull {a, b, c}" "v \<in> convex hull {a, b, c}" "u\<noteq>v"
  2.1971 +             and fpi_uv: "f path_integrable_on linepath (shrink u) (shrink v)"
  2.1972 +          have shr_uv: "shrink u \<in> interior(convex hull {a,b,c})"
  2.1973 +                       "shrink v \<in> interior(convex hull {a,b,c})"
  2.1974 +            using d e uv
  2.1975 +            by (auto simp: hull_inc mem_interior_convex_shrink shrink_def)
  2.1976 +          have cmod_fuv: "\<And>x. 0\<le>x \<Longrightarrow> x\<le>1 \<Longrightarrow> cmod (f (linepath (shrink u) (shrink v) x)) \<le> B"
  2.1977 +            using shr_uv by (blast intro: Bnf linepath_in_convex_hull interior_subset [THEN subsetD])
  2.1978 +          have By_uv: "B * (12 * (e * cmod (u - v))) \<le> cmod y"
  2.1979 +            apply (rule order_trans [OF _ eCB])
  2.1980 +            using e `B>0` diff_2C [of u v] uv
  2.1981 +            by (auto simp: field_simps)
  2.1982 +          { fix x::real   assume x: "0\<le>x" "x\<le>1"
  2.1983 +            have cmod_less_4C: "cmod ((1 - x) *\<^sub>R u - (1 - x) *\<^sub>R d) + cmod (x *\<^sub>R v - x *\<^sub>R d) < (C+C) + (C+C)"
  2.1984 +              apply (rule add_strict_mono; rule norm_triangle_half_l [of _ 0])
  2.1985 +              using uv x d interior_subset
  2.1986 +              apply (auto simp: hull_inc intro!: less_C)
  2.1987 +              done
  2.1988 +            have ll: "linepath (shrink u) (shrink v) x - linepath u v x = -e * ((1 - x) *\<^sub>R (u - d) + x *\<^sub>R (v - d))"
  2.1989 +              by (simp add: linepath_def shrink_def algebra_simps scaleR_conv_of_real)
  2.1990 +            have cmod_less_dt: "cmod (linepath (shrink u) (shrink v) x - linepath u v x) < d1"
  2.1991 +              using `e>0`
  2.1992 +              apply (simp add: ll norm_mult scaleR_diff_right)
  2.1993 +              apply (rule less_le_trans [OF _ e_le_d1])
  2.1994 +              using cmod_less_4C
  2.1995 +              apply (force intro: norm_triangle_lt)
  2.1996 +              done
  2.1997 +            have "cmod (f (linepath (shrink u) (shrink v) x) - f (linepath u v x)) < cmod y / (24 * C)"
  2.1998 +              using x uv shr_uv cmod_less_dt
  2.1999 +              by (auto simp: hull_inc intro: d1 interior_subset [THEN subsetD] linepath_in_convex_hull)
  2.2000 +            also have "... \<le> cmod y / cmod (v - u) / 12"
  2.2001 +              using False uv `C>0` diff_2C [of v u] ynz
  2.2002 +              by (auto simp: divide_simps hull_inc)
  2.2003 +            finally have "cmod (f (linepath (shrink u) (shrink v) x) - f (linepath u v x)) \<le> cmod y / cmod (v - u) / 12"
  2.2004 +              by simp
  2.2005 +            then have cmod_12_le: "cmod (v - u) * cmod (f (linepath (shrink u) (shrink v) x) - f (linepath u v x)) * 12 \<le> cmod y"
  2.2006 +              using uv False by (auto simp: field_simps)
  2.2007 +            have "cmod (f (linepath (shrink u) (shrink v) x)) * cmod (shrink v - shrink u - (v - u)) +
  2.2008 +                  cmod (v - u) * cmod (f (linepath (shrink u) (shrink v) x) - f (linepath u v x))
  2.2009 +                  \<le> cmod y / 6"
  2.2010 +              apply (rule order_trans [of _ "B*((norm y / 24 / C / B)*2*C) + (2*C)*(norm y /24 / C)"])
  2.2011 +              apply (rule add_mono [OF mult_mono])
  2.2012 +              using By_uv e `0 < B` `0 < C` x ynz
  2.2013 +              apply (simp_all add: cmod_fuv cmod_shr cmod_12_le hull_inc)
  2.2014 +              apply (simp add: field_simps)
  2.2015 +              done
  2.2016 +          } note cmod_diff_le = this
  2.2017 +          have f_uv: "continuous_on (closed_segment u v) f"
  2.2018 +            by (blast intro: uv continuous_on_subset [OF contf closed_segment_subset_convex_hull])
  2.2019 +          have **: "\<And>f' x' f x::complex. f'*x' - f*x = f'*(x' - x) + x*(f' - f)"
  2.2020 +            by (simp add: algebra_simps)
  2.2021 +          have "norm (?pathint (shrink u) (shrink v) - ?pathint u v) \<le> norm y / 6"
  2.2022 +            apply (rule order_trans)
  2.2023 +            apply (rule has_integral_bound
  2.2024 +                    [of "B*(norm y /24/C/B)*2*C + (2*C)*(norm y/24/C)"
  2.2025 +                        "\<lambda>x. f(linepath (shrink u) (shrink v) x) * (shrink v - shrink u) - f(linepath u v x)*(v - u)"
  2.2026 +                        _ 0 1 ])
  2.2027 +            using ynz `0 < B` `0 < C`
  2.2028 +            apply (simp_all del: le_divide_eq_numeral1)
  2.2029 +            apply (simp add: has_integral_sub has_path_integral_linepath [symmetric] has_path_integral_integral
  2.2030 +                             fpi_uv f_uv path_integrable_continuous_linepath, clarify)
  2.2031 +            apply (simp only: **)
  2.2032 +            apply (simp add: norm_triangle_le norm_mult cmod_diff_le del: le_divide_eq_numeral1)
  2.2033 +            done
  2.2034 +          } note * = this
  2.2035 +          have "norm (?pathint (shrink a) (shrink b) - ?pathint a b) \<le> norm y / 6"
  2.2036 +            using False fpi_abc by (rule_tac *) (auto simp: hull_inc)
  2.2037 +          moreover
  2.2038 +          have "norm (?pathint (shrink b) (shrink c) - ?pathint b c) \<le> norm y / 6"
  2.2039 +            using False fpi_abc by (rule_tac *) (auto simp: hull_inc)
  2.2040 +          moreover
  2.2041 +          have "norm (?pathint (shrink c) (shrink a) - ?pathint c a) \<le> norm y / 6"
  2.2042 +            using False fpi_abc by (rule_tac *) (auto simp: hull_inc)
  2.2043 +          ultimately
  2.2044 +          have "norm((?pathint (shrink a) (shrink b) - ?pathint a b) +
  2.2045 +                     (?pathint (shrink b) (shrink c) - ?pathint b c) + (?pathint (shrink c) (shrink a) - ?pathint c a))
  2.2046 +                \<le> norm y / 6 + norm y / 6 + norm y / 6"
  2.2047 +            by (metis norm_triangle_le add_mono)
  2.2048 +          also have "... = norm y / 2"
  2.2049 +            by simp
  2.2050 +          finally have "norm((?pathint (shrink a) (shrink b) + ?pathint (shrink b) (shrink c) + ?pathint (shrink c) (shrink a)) -
  2.2051 +                          (?pathint a b + ?pathint b c + ?pathint c a))
  2.2052 +                \<le> norm y / 2"
  2.2053 +            by (simp add: algebra_simps)
  2.2054 +          then
  2.2055 +          have "norm(?pathint a b + ?pathint b c + ?pathint c a) \<le> norm y / 2"
  2.2056 +            by (simp add: f_0_shrink) (metis (mono_tags) add.commute minus_add_distrib norm_minus_cancel uminus_add_conv_diff)
  2.2057 +          then have "False"
  2.2058 +            using pi_eq_y ynz by auto
  2.2059 +        }
  2.2060 +        moreover have "uniformly_continuous_on (convex hull {a,b,c}) f"
  2.2061 +          by (simp add: contf compact_convex_hull compact_uniformly_continuous)
  2.2062 +        ultimately have "False"
  2.2063 +          unfolding uniformly_continuous_on_def
  2.2064 +          by (force simp: ynz `0 < C` dist_norm)
  2.2065 +        then show ?thesis ..
  2.2066 +      qed
  2.2067 +  }
  2.2068 +  moreover have "f path_integrable_on (linepath a b +++ linepath b c +++ linepath c a)"
  2.2069 +    using fabc path_integrable_continuous_linepath by auto
  2.2070 +  ultimately show ?thesis
  2.2071 +    using has_path_integral_integral by fastforce
  2.2072 +qed
  2.2073 +
  2.2074 +
  2.2075 +
  2.2076 +subsection\<open>Version allowing finite number of exceptional points\<close>
  2.2077 +
  2.2078 +lemma Cauchy_theorem_triangle_cofinite:
  2.2079 +  assumes "continuous_on (convex hull {a,b,c}) f"
  2.2080 +      and "finite s"
  2.2081 +      and "(\<And>x. x \<in> interior(convex hull {a,b,c}) - s \<Longrightarrow> f complex_differentiable (at x))"
  2.2082 +     shows "(f has_path_integral 0) (linepath a b +++ linepath b c +++ linepath c a)"
  2.2083 +using assms
  2.2084 +proof (induction "card s" arbitrary: a b c s rule: less_induct)
  2.2085 +  case (less s a b c)
  2.2086 +  show ?case
  2.2087 +  proof (cases "s={}")
  2.2088 +    case True with less show ?thesis
  2.2089 +      by (simp add: holomorphic_on_def complex_differentiable_at_within
  2.2090 +                    Cauchy_theorem_triangle_interior)
  2.2091 +  next
  2.2092 +    case False
  2.2093 +    then obtain d s' where d: "s = insert d s'" "d \<notin> s'"
  2.2094 +      by (meson Set.set_insert all_not_in_conv)
  2.2095 +    then show ?thesis
  2.2096 +    proof (cases "d \<in> convex hull {a,b,c}")
  2.2097 +      case False
  2.2098 +      show "(f has_path_integral 0) (linepath a b +++ linepath b c +++ linepath c a)"
  2.2099 +        apply (rule less.hyps [of "s'"])
  2.2100 +        using False d `finite s` interior_subset
  2.2101 +        apply (auto intro!: less.prems)
  2.2102 +        done
  2.2103 +    next
  2.2104 +      case True
  2.2105 +      have *: "convex hull {a, b, d} \<subseteq> convex hull {a, b, c}"
  2.2106 +        by (meson True hull_subset insert_subset convex_hull_subset)
  2.2107 +      have abd: "(f has_path_integral 0) (linepath a b +++ linepath b d +++ linepath d a)"
  2.2108 +        apply (rule less.hyps [of "s'"])
  2.2109 +        using True d  `finite s` not_in_interior_convex_hull_3
  2.2110 +        apply (auto intro!: less.prems continuous_on_subset [OF  _ *])
  2.2111 +        apply (metis * insert_absorb insert_subset interior_mono)
  2.2112 +        done
  2.2113 +      have *: "convex hull {b, c, d} \<subseteq> convex hull {a, b, c}"
  2.2114 +        by (meson True hull_subset insert_subset convex_hull_subset)
  2.2115 +      have bcd: "(f has_path_integral 0) (linepath b c +++ linepath c d +++ linepath d b)"
  2.2116 +        apply (rule less.hyps [of "s'"])
  2.2117 +        using True d  `finite s` not_in_interior_convex_hull_3
  2.2118 +        apply (auto intro!: less.prems continuous_on_subset [OF _ *])
  2.2119 +        apply (metis * insert_absorb insert_subset interior_mono)
  2.2120 +        done
  2.2121 +      have *: "convex hull {c, a, d} \<subseteq> convex hull {a, b, c}"
  2.2122 +        by (meson True hull_subset insert_subset convex_hull_subset)
  2.2123 +      have cad: "(f has_path_integral 0) (linepath c a +++ linepath a d +++ linepath d c)"
  2.2124 +        apply (rule less.hyps [of "s'"])
  2.2125 +        using True d  `finite s` not_in_interior_convex_hull_3
  2.2126 +        apply (auto intro!: less.prems continuous_on_subset [OF _ *])
  2.2127 +        apply (metis * insert_absorb insert_subset interior_mono)
  2.2128 +        done
  2.2129 +      have "f path_integrable_on linepath a b"
  2.2130 +        using less.prems
  2.2131 +        by (metis continuous_on_subset insert_commute path_integrable_continuous_linepath segments_subset_convex_hull(3))
  2.2132 +      moreover have "f path_integrable_on linepath b c"
  2.2133 +        using less.prems
  2.2134 +        by (metis continuous_on_subset path_integrable_continuous_linepath segments_subset_convex_hull(3))
  2.2135 +      moreover have "f path_integrable_on linepath c a"
  2.2136 +        using less.prems
  2.2137 +        by (metis continuous_on_subset insert_commute path_integrable_continuous_linepath segments_subset_convex_hull(3))
  2.2138 +      ultimately have fpi: "f path_integrable_on (linepath a b +++ linepath b c +++ linepath c a)"
  2.2139 +        by auto
  2.2140 +      { fix y::complex
  2.2141 +        assume fy: "(f has_path_integral y) (linepath a b +++ linepath b c +++ linepath c a)"
  2.2142 +           and ynz: "y \<noteq> 0"
  2.2143 +        have cont_ad: "continuous_on (closed_segment a d) f"
  2.2144 +          by (meson "*" continuous_on_subset less.prems(1) segments_subset_convex_hull(3))
  2.2145 +        have cont_bd: "continuous_on (closed_segment b d) f"
  2.2146 +          by (meson True closed_segment_subset_convex_hull continuous_on_subset hull_subset insert_subset less.prems(1))
  2.2147 +        have cont_cd: "continuous_on (closed_segment c d) f"
  2.2148 +          by (meson "*" continuous_on_subset less.prems(1) segments_subset_convex_hull(2))
  2.2149 +        have "path_integral  (linepath a b) f = - (path_integral (linepath b d) f + (path_integral (linepath d a) f))"
  2.2150 +                "path_integral  (linepath b c) f = - (path_integral (linepath c d) f + (path_integral (linepath d b) f))"
  2.2151 +                "path_integral  (linepath c a) f = - (path_integral (linepath a d) f + path_integral (linepath d c) f)"
  2.2152 +            using has_chain_integral_chain_integral3 [OF abd]
  2.2153 +                  has_chain_integral_chain_integral3 [OF bcd]
  2.2154 +                  has_chain_integral_chain_integral3 [OF cad]
  2.2155 +            by (simp_all add: algebra_simps add_eq_0_iff)
  2.2156 +        then have ?thesis
  2.2157 +          using cont_ad cont_bd cont_cd fy has_chain_integral_chain_integral3 path_integral_reverse_linepath by fastforce
  2.2158 +      }
  2.2159 +      then show ?thesis
  2.2160 +        using fpi path_integrable_on_def by blast
  2.2161 +    qed
  2.2162 +  qed
  2.2163 +qed
  2.2164 +
  2.2165 +
  2.2166 +subsection\<open>Cauchy's theorem for an open starlike set\<close>
  2.2167 +
  2.2168 +lemma starlike_convex_subset:
  2.2169 +  assumes s: "a \<in> s" "closed_segment b c \<subseteq> s" and subs: "\<And>x. x \<in> s \<Longrightarrow> closed_segment a x \<subseteq> s"
  2.2170 +    shows "convex hull {a,b,c} \<subseteq> s"
  2.2171 +      using s
  2.2172 +      apply (clarsimp simp add: convex_hull_insert [of "{b,c}" a] segment_convex_hull)
  2.2173 +      apply (meson subs convexD convex_segment ends_in_segment(1) ends_in_segment(2) subsetCE)
  2.2174 +      done
  2.2175 +
  2.2176 +lemma triangle_path_integrals_starlike_primitive:
  2.2177 +  assumes contf: "continuous_on s f"
  2.2178 +      and s: "a \<in> s" "open s"
  2.2179 +      and x: "x \<in> s"
  2.2180 +      and subs: "\<And>y. y \<in> s \<Longrightarrow> closed_segment a y \<subseteq> s"
  2.2181 +      and zer: "\<And>b c. closed_segment b c \<subseteq> s
  2.2182 +                   \<Longrightarrow> path_integral (linepath a b) f + path_integral (linepath b c) f +
  2.2183 +                       path_integral (linepath c a) f = 0"
  2.2184 +    shows "((\<lambda>x. path_integral(linepath a x) f) has_field_derivative f x) (at x)"
  2.2185 +proof -
  2.2186 +  let ?pathint = "\<lambda>x y. path_integral(linepath x y) f"
  2.2187 +  { fix e y
  2.2188 +    assume e: "0 < e" and bxe: "ball x e \<subseteq> s" and close: "cmod (y - x) < e"
  2.2189 +    have y: "y \<in> s"
  2.2190 +      using bxe close  by (force simp: dist_norm norm_minus_commute)
  2.2191 +    have cont_ayf: "continuous_on (closed_segment a y) f"
  2.2192 +      using contf continuous_on_subset subs y by blast
  2.2193 +    have xys: "closed_segment x y \<subseteq> s"
  2.2194 +      apply (rule order_trans [OF _ bxe])
  2.2195 +      using close
  2.2196 +      by (auto simp: dist_norm ball_def norm_minus_commute dest: segment_bound)
  2.2197 +    have "?pathint a y - ?pathint a x = ?pathint x y"
  2.2198 +      using zer [OF xys]  path_integral_reverse_linepath [OF cont_ayf]  add_eq_0_iff by force
  2.2199 +  } note [simp] = this
  2.2200 +  { fix e::real
  2.2201 +    assume e: "0 < e"
  2.2202 +    have cont_atx: "continuous (at x) f"
  2.2203 +      using x s contf continuous_on_eq_continuous_at by blast
  2.2204 +    then obtain d1 where d1: "d1>0" and d1_less: "\<And>y. cmod (y - x) < d1 \<Longrightarrow> cmod (f y - f x) < e/2"
  2.2205 +      unfolding continuous_at Lim_at dist_norm  using e
  2.2206 +      by (drule_tac x="e/2" in spec) force
  2.2207 +    obtain d2 where d2: "d2>0" "ball x d2 \<subseteq> s" using  `open s` x
  2.2208 +      by (auto simp: open_contains_ball)
  2.2209 +    have dpos: "min d1 d2 > 0" using d1 d2 by simp
  2.2210 +    { fix y
  2.2211 +      assume yx: "y \<noteq> x" and close: "cmod (y - x) < min d1 d2"
  2.2212 +      have y: "y \<in> s"
  2.2213 +        using d2 close  by (force simp: dist_norm norm_minus_commute)
  2.2214 +      have fxy: "f path_integrable_on linepath x y"
  2.2215 +        apply (rule path_integrable_continuous_linepath)
  2.2216 +        apply (rule continuous_on_subset [OF contf])
  2.2217 +        using close d2
  2.2218 +        apply (auto simp: dist_norm norm_minus_commute dest!: segment_bound(1))
  2.2219 +        done
  2.2220 +      then obtain i where i: "(f has_path_integral i) (linepath x y)"
  2.2221 +        by (auto simp: path_integrable_on_def)
  2.2222 +      then have "((\<lambda>w. f w - f x) has_path_integral (i - f x * (y - x))) (linepath x y)"
  2.2223 +        by (rule has_path_integral_diff [OF _ has_path_integral_const_linepath])
  2.2224 +      then have "cmod (i - f x * (y - x)) \<le> e / 2 * cmod (y - x)"
  2.2225 +        apply (rule has_path_integral_bound_linepath [where B = "e/2"])
  2.2226 +        using e apply simp
  2.2227 +        apply (rule d1_less [THEN less_imp_le])
  2.2228 +        using close segment_bound
  2.2229 +        apply force
  2.2230 +        done
  2.2231 +      also have "... < e * cmod (y - x)"
  2.2232 +        by (simp add: e yx)
  2.2233 +      finally have "cmod (?pathint x y - f x * (y-x)) / cmod (y-x) < e"
  2.2234 +        using i yx  by (simp add: path_integral_unique divide_less_eq)
  2.2235 +    }
  2.2236 +    then have "\<exists>d>0. \<forall>y. y \<noteq> x \<and> cmod (y-x) < d \<longrightarrow> cmod (?pathint x y - f x * (y-x)) / cmod (y-x) < e"
  2.2237 +      using dpos by blast
  2.2238 +  }
  2.2239 +  then have *: "(\<lambda>y. (?pathint x y - f x * (y - x)) /\<^sub>R cmod (y - x)) -- x --> 0"
  2.2240 +    by (simp add: Lim_at dist_norm inverse_eq_divide)
  2.2241 +  show ?thesis
  2.2242 +    apply (simp add: has_field_derivative_def has_derivative_at bounded_linear_mult_right)
  2.2243 +    apply (rule Lim_transform [OF * Lim_eventually])
  2.2244 +    apply (simp add: inverse_eq_divide [symmetric] eventually_at)
  2.2245 +    using `open s` x
  2.2246 +    apply (force simp: dist_norm open_contains_ball)
  2.2247 +    done
  2.2248 +qed
  2.2249 +
  2.2250 +(** Existence of a primitive.*)
  2.2251 +
  2.2252 +lemma holomorphic_starlike_primitive:
  2.2253 +  assumes contf: "continuous_on s f"
  2.2254 +      and s: "starlike s" and os: "open s"
  2.2255 +      and k: "finite k"
  2.2256 +      and fcd: "\<And>x. x \<in> s - k \<Longrightarrow> f complex_differentiable at x"
  2.2257 +    shows "\<exists>g. \<forall>x \<in> s. (g has_field_derivative f x) (at x)"
  2.2258 +proof -
  2.2259 +  obtain a where a: "a\<in>s" and a_cs: "\<And>x. x\<in>s \<Longrightarrow> closed_segment a x \<subseteq> s"
  2.2260 +    using s by (auto simp: starlike_def)
  2.2261 +  { fix x b c
  2.2262 +    assume "x \<in> s" "closed_segment b c \<subseteq> s"
  2.2263 +    then have abcs: "convex hull {a, b, c} \<subseteq> s"
  2.2264 +      by (simp add: a a_cs starlike_convex_subset)
  2.2265 +    then have *: "continuous_on (convex hull {a, b, c}) f"
  2.2266 +      by (simp add: continuous_on_subset [OF contf])
  2.2267 +    have "(f has_path_integral 0) (linepath a b +++ linepath b c +++ linepath c a)"
  2.2268 +      apply (rule Cauchy_theorem_triangle_cofinite [OF _ k])
  2.2269 +      using abcs apply (simp add: continuous_on_subset [OF contf])
  2.2270 +      using * abcs interior_subset apply (auto intro: fcd)
  2.2271 +      done
  2.2272 +  } note 0 = this
  2.2273 +  show ?thesis
  2.2274 +    apply (intro exI ballI)
  2.2275 +    apply (rule triangle_path_integrals_starlike_primitive [OF contf a os], assumption)
  2.2276 +    apply (metis a_cs)
  2.2277 +    apply (metis has_chain_integral_chain_integral3 0)
  2.2278 +    done
  2.2279 +qed
  2.2280 +
  2.2281 +lemma Cauchy_theorem_starlike:
  2.2282 + "\<lbrakk>open s; starlike s; finite k; continuous_on s f;
  2.2283 +   \<And>x. x \<in> s - k \<Longrightarrow> f complex_differentiable at x;
  2.2284 +   valid_path g; path_image g \<subseteq> s; pathfinish g = pathstart g\<rbrakk>
  2.2285 +   \<Longrightarrow> (f has_path_integral 0)  g"
  2.2286 +  by (metis holomorphic_starlike_primitive Cauchy_theorem_primitive at_within_open)
  2.2287 +
  2.2288 +lemma Cauchy_theorem_starlike_simple:
  2.2289 +  "\<lbrakk>open s; starlike s; f holomorphic_on s; valid_path g; path_image g \<subseteq> s; pathfinish g = pathstart g\<rbrakk>
  2.2290 +   \<Longrightarrow> (f has_path_integral 0) g"
  2.2291 +apply (rule Cauchy_theorem_starlike [OF _ _ finite.emptyI])
  2.2292 +apply (simp_all add: holomorphic_on_imp_continuous_on)
  2.2293 +apply (metis at_within_open holomorphic_on_def)
  2.2294 +done
  2.2295 +
  2.2296 +
  2.2297 +subsection\<open>Cauchy's theorem for a convex set\<close>
  2.2298 +
  2.2299 +text\<open>For a convex set we can avoid assuming openness and boundary analyticity\<close>
  2.2300 +
  2.2301 +lemma triangle_path_integrals_convex_primitive:
  2.2302 +  assumes contf: "continuous_on s f"
  2.2303 +      and s: "a \<in> s" "convex s"
  2.2304 +      and x: "x \<in> s"
  2.2305 +      and zer: "\<And>b c. \<lbrakk>b \<in> s; c \<in> s\<rbrakk>
  2.2306 +                   \<Longrightarrow> path_integral (linepath a b) f + path_integral (linepath b c) f +
  2.2307 +                       path_integral (linepath c a) f = 0"
  2.2308 +    shows "((\<lambda>x. path_integral(linepath a x) f) has_field_derivative f x) (at x within s)"
  2.2309 +proof -
  2.2310 +  let ?pathint = "\<lambda>x y. path_integral(linepath x y) f"
  2.2311 +  { fix y
  2.2312 +    assume y: "y \<in> s"
  2.2313 +    have cont_ayf: "continuous_on (closed_segment a y) f"
  2.2314 +      using s y  by (meson contf continuous_on_subset convex_contains_segment)
  2.2315 +    have xys: "closed_segment x y \<subseteq> s"  (*?*)
  2.2316 +      using convex_contains_segment s x y by auto
  2.2317 +    have "?pathint a y - ?pathint a x = ?pathint x y"
  2.2318 +      using zer [OF x y]  path_integral_reverse_linepath [OF cont_ayf]  add_eq_0_iff by force
  2.2319 +  } note [simp] = this
  2.2320 +  { fix e::real
  2.2321 +    assume e: "0 < e"
  2.2322 +    have cont_atx: "continuous (at x within s) f"
  2.2323 +      using x s contf  by (simp add: continuous_on_eq_continuous_within)
  2.2324 +    then obtain d1 where d1: "d1>0" and d1_less: "\<And>y. \<lbrakk>y \<in> s; cmod (y - x) < d1\<rbrakk> \<Longrightarrow> cmod (f y - f x) < e/2"
  2.2325 +      unfolding continuous_within Lim_within dist_norm using e
  2.2326 +      by (drule_tac x="e/2" in spec) force
  2.2327 +    { fix y
  2.2328 +      assume yx: "y \<noteq> x" and close: "cmod (y - x) < d1" and y: "y \<in> s"
  2.2329 +      have fxy: "f path_integrable_on linepath x y"
  2.2330 +        using convex_contains_segment s x y
  2.2331 +        by (blast intro!: path_integrable_continuous_linepath continuous_on_subset [OF contf])
  2.2332 +      then obtain i where i: "(f has_path_integral i) (linepath x y)"
  2.2333 +        by (auto simp: path_integrable_on_def)
  2.2334 +      then have "((\<lambda>w. f w - f x) has_path_integral (i - f x * (y - x))) (linepath x y)"
  2.2335 +        by (rule has_path_integral_diff [OF _ has_path_integral_const_linepath])
  2.2336 +      then have "cmod (i - f x * (y - x)) \<le> e / 2 * cmod (y - x)"
  2.2337 +        apply (rule has_path_integral_bound_linepath [where B = "e/2"])
  2.2338 +        using e apply simp
  2.2339 +        apply (rule d1_less [THEN less_imp_le])
  2.2340 +        using convex_contains_segment s(2) x y apply blast
  2.2341 +        using close segment_bound(1) apply fastforce
  2.2342 +        done
  2.2343 +      also have "... < e * cmod (y - x)"
  2.2344 +        by (simp add: e yx)
  2.2345 +      finally have "cmod (?pathint x y - f x * (y-x)) / cmod (y-x) < e"
  2.2346 +        using i yx  by (simp add: path_integral_unique divide_less_eq)
  2.2347 +    }
  2.2348 +    then have "\<exists>d>0. \<forall>y\<in>s. y \<noteq> x \<and> cmod (y-x) < d \<longrightarrow> cmod (?pathint x y - f x * (y-x)) / cmod (y-x) < e"
  2.2349 +      using d1 by blast
  2.2350 +  }
  2.2351 +  then have *: "((\<lambda>y. (path_integral (linepath x y) f - f x * (y - x)) /\<^sub>R cmod (y - x)) ---> 0) (at x within s)"
  2.2352 +    by (simp add: Lim_within dist_norm inverse_eq_divide)
  2.2353 +  show ?thesis
  2.2354 +    apply (simp add: has_field_derivative_def has_derivative_within bounded_linear_mult_right)
  2.2355 +    apply (rule Lim_transform [OF * Lim_eventually])
  2.2356 +    using linordered_field_no_ub
  2.2357 +    apply (force simp: inverse_eq_divide [symmetric] eventually_at)
  2.2358 +    done
  2.2359 +qed
  2.2360 +
  2.2361 +lemma pathintegral_convex_primitive:
  2.2362 +  "\<lbrakk>convex s; continuous_on s f;
  2.2363 +    \<And>a b c. \<lbrakk>a \<in> s; b \<in> s; c \<in> s\<rbrakk> \<Longrightarrow> (f has_path_integral 0) (linepath a b +++ linepath b c +++ linepath c a)\<rbrakk>
  2.2364 +         \<Longrightarrow> \<exists>g. \<forall>x \<in> s. (g has_field_derivative f x) (at x within s)"
  2.2365 +  apply (cases "s={}")
  2.2366 +  apply (simp_all add: ex_in_conv [symmetric])
  2.2367 +  apply (blast intro: triangle_path_integrals_convex_primitive has_chain_integral_chain_integral3)
  2.2368 +  done
  2.2369 +
  2.2370 +lemma holomorphic_convex_primitive:
  2.2371 +  "\<lbrakk>convex s; finite k; continuous_on s f;
  2.2372 +    \<And>x. x \<in> interior s - k \<Longrightarrow> f complex_differentiable at x\<rbrakk>
  2.2373 +   \<Longrightarrow> \<exists>g. \<forall>x \<in> s. (g has_field_derivative f x) (at x within s)"
  2.2374 +apply (rule pathintegral_convex_primitive [OF _ _ Cauchy_theorem_triangle_cofinite])
  2.2375 +prefer 3
  2.2376 +apply (erule continuous_on_subset)
  2.2377 +apply (simp add: subset_hull continuous_on_subset, assumption+)
  2.2378 +by (metis Diff_iff convex_contains_segment insert_absorb insert_subset interior_mono segment_convex_hull subset_hull)
  2.2379 +
  2.2380 +lemma Cauchy_theorem_convex:
  2.2381 +    "\<lbrakk>continuous_on s f;convex s; finite k;
  2.2382 +      \<And>x. x \<in> interior s - k \<Longrightarrow> f complex_differentiable at x;
  2.2383 +     valid_path g; path_image g \<subseteq> s;
  2.2384 +     pathfinish g = pathstart g\<rbrakk> \<Longrightarrow> (f has_path_integral 0) g"
  2.2385 +  by (metis holomorphic_convex_primitive Cauchy_theorem_primitive)
  2.2386 +
  2.2387 +lemma Cauchy_theorem_convex_simple:
  2.2388 +    "\<lbrakk>f holomorphic_on s; convex s;
  2.2389 +     valid_path g; path_image g \<subseteq> s;
  2.2390 +     pathfinish g = pathstart g\<rbrakk> \<Longrightarrow> (f has_path_integral 0) g"
  2.2391 +  apply (rule Cauchy_theorem_convex)
  2.2392 +  apply (simp_all add: holomorphic_on_imp_continuous_on)
  2.2393 +  apply (rule finite.emptyI)
  2.2394 +  using at_within_interior holomorphic_on_def interior_subset by fastforce
  2.2395 +
  2.2396 +
  2.2397 +text\<open>In particular for a disc\<close>
  2.2398 +lemma Cauchy_theorem_disc:
  2.2399 +    "\<lbrakk>finite k; continuous_on (cball a e) f;
  2.2400 +      \<And>x. x \<in> ball a e - k \<Longrightarrow> f complex_differentiable at x;
  2.2401 +     valid_path g; path_image g \<subseteq> cball a e;
  2.2402 +     pathfinish g = pathstart g\<rbrakk> \<Longrightarrow> (f has_path_integral 0) g"
  2.2403 +  apply (rule Cauchy_theorem_convex)
  2.2404 +  apply (auto simp: convex_cball interior_cball)
  2.2405 +  done
  2.2406 +
  2.2407 +lemma Cauchy_theorem_disc_simple:
  2.2408 +    "\<lbrakk>f holomorphic_on (ball a e); valid_path g; path_image g \<subseteq> ball a e;
  2.2409 +     pathfinish g = pathstart g\<rbrakk> \<Longrightarrow> (f has_path_integral 0) g"
  2.2410 +by (simp add: Cauchy_theorem_convex_simple)
  2.2411 +
  2.2412 +
  2.2413 +subsection\<open>Generalize integrability to local primitives\<close>
  2.2414 +
  2.2415 +lemma path_integral_local_primitive_lemma:
  2.2416 +  fixes f :: "complex\<Rightarrow>complex"
  2.2417 +  shows
  2.2418 +    "\<lbrakk>g piecewise_differentiable_on {a..b};
  2.2419 +      \<And>x. x \<in> s \<Longrightarrow> (f has_field_derivative f' x) (at x within s);
  2.2420 +      \<And>x. x \<in> {a..b} \<Longrightarrow> g x \<in> s\<rbrakk>
  2.2421 +     \<Longrightarrow> (\<lambda>x. f' (g x) * vector_derivative g (at x within {a..b}))
  2.2422 +            integrable_on {a..b}"
  2.2423 +  apply (cases "cbox a b = {}", force)
  2.2424 +  apply (simp add: integrable_on_def)
  2.2425 +  apply (rule exI)
  2.2426 +  apply (rule path_integral_primitive_lemma, assumption+)
  2.2427 +  using atLeastAtMost_iff by blast
  2.2428 +
  2.2429 +lemma path_integral_local_primitive_any:
  2.2430 +  fixes f :: "complex \<Rightarrow> complex"
  2.2431 +  assumes gpd: "g piecewise_differentiable_on {a..b}"
  2.2432 +      and dh: "\<And>x. x \<in> s
  2.2433 +               \<Longrightarrow> \<exists>d h. 0 < d \<and>
  2.2434 +                         (\<forall>y. norm(y - x) < d \<longrightarrow> (h has_field_derivative f y) (at y within s))"
  2.2435 +      and gs: "\<And>x. x \<in> {a..b} \<Longrightarrow> g x \<in> s"
  2.2436 +  shows "(\<lambda>x. f(g x) * vector_derivative g (at x)) integrable_on {a..b}"
  2.2437 +proof -
  2.2438 +  { fix x
  2.2439 +    assume x: "a \<le> x" "x \<le> b"
  2.2440 +    obtain d h where d: "0 < d"
  2.2441 +               and h: "(\<And>y. norm(y - g x) < d \<Longrightarrow> (h has_field_derivative f y) (at y within s))"
  2.2442 +      using x gs dh by (metis atLeastAtMost_iff)
  2.2443 +    have "continuous_on {a..b} g" using gpd piecewise_differentiable_on_def by blast
  2.2444 +    then obtain e where e: "e>0" and lessd: "\<And>x'. x' \<in> {a..b} \<Longrightarrow> \<bar>x' - x\<bar> < e \<Longrightarrow> cmod (g x' - g x) < d"
  2.2445 +      using x d
  2.2446 +      apply (auto simp: dist_norm continuous_on_iff)
  2.2447 +      apply (drule_tac x=x in bspec)
  2.2448 +      using x apply simp
  2.2449 +      apply (drule_tac x=d in spec, auto)
  2.2450 +      done
  2.2451 +    have "\<exists>d>0. \<forall>u v. u \<le> x \<and> x \<le> v \<and> {u..v} \<subseteq> ball x d \<and> (u \<le> v \<longrightarrow> a \<le> u \<and> v \<le> b) \<longrightarrow>
  2.2452 +                          (\<lambda>x. f (g x) * vector_derivative g (at x)) integrable_on {u..v}"
  2.2453 +      apply (rule_tac x=e in exI)
  2.2454 +      using e
  2.2455 +      apply (simp add: integrable_on_localized_vector_derivative [symmetric], clarify)
  2.2456 +      apply (rule_tac f = h and s = "g ` {u..v}" in path_integral_local_primitive_lemma)
  2.2457 +        apply (meson atLeastatMost_subset_iff gpd piecewise_differentiable_on_subset)
  2.2458 +       apply (force simp: ball_def dist_norm intro: lessd gs DERIV_subset [OF h], force)
  2.2459 +      done
  2.2460 +  } then
  2.2461 +  show ?thesis
  2.2462 +    by (force simp: intro!: integrable_on_little_subintervals [of a b, simplified])
  2.2463 +qed
  2.2464 +
  2.2465 +lemma path_integral_local_primitive:
  2.2466 +  fixes f :: "complex \<Rightarrow> complex"
  2.2467 +  assumes g: "valid_path g" "path_image g \<subseteq> s"
  2.2468 +      and dh: "\<And>x. x \<in> s
  2.2469 +               \<Longrightarrow> \<exists>d h. 0 < d \<and>
  2.2470 +                         (\<forall>y. norm(y - x) < d \<longrightarrow> (h has_field_derivative f y) (at y within s))"
  2.2471 +  shows "f path_integrable_on g"
  2.2472 +  using g
  2.2473 +  apply (simp add: valid_path_def path_image_def path_integrable_on_def has_path_integral_def
  2.2474 +            has_integral_localized_vector_derivative integrable_on_def [symmetric])
  2.2475 +  apply (auto intro: path_integral_local_primitive_any [OF _ dh])
  2.2476 +  done
  2.2477 +
  2.2478 +
  2.2479 +text\<open>In particular if a function is holomorphic\<close>
  2.2480 +
  2.2481 +lemma path_integrable_holomorphic:
  2.2482 +  assumes contf: "continuous_on s f"
  2.2483 +      and os: "open s"
  2.2484 +      and k: "finite k"
  2.2485 +      and g: "valid_path g" "path_image g \<subseteq> s"
  2.2486 +      and fcd: "\<And>x. x \<in> s - k \<Longrightarrow> f complex_differentiable at x"
  2.2487 +    shows "f path_integrable_on g"
  2.2488 +proof -
  2.2489 +  { fix z
  2.2490 +    assume z: "z \<in> s"
  2.2491 +    obtain d where d: "d>0" "ball z d \<subseteq> s" using  `open s` z
  2.2492 +      by (auto simp: open_contains_ball)
  2.2493 +    then have contfb: "continuous_on (ball z d) f"
  2.2494 +      using contf continuous_on_subset by blast
  2.2495 +    obtain h where "\<forall>y\<in>ball z d. (h has_field_derivative f y) (at y within ball z d)"
  2.2496 +      using holomorphic_convex_primitive [OF convex_ball k contfb fcd] d
  2.2497 +            interior_subset by force
  2.2498 +    then have "\<forall>y\<in>ball z d. (h has_field_derivative f y) (at y within s)"
  2.2499 +      by (metis Topology_Euclidean_Space.open_ball at_within_open d(2) os subsetCE)
  2.2500 +    then have "\<exists>h. (\<forall>y. cmod (y - z) < d \<longrightarrow> (h has_field_derivative f y) (at y within s))"
  2.2501 +      by (force simp: dist_norm norm_minus_commute)
  2.2502 +    then have "\<exists>d h. 0 < d \<and> (\<forall>y. cmod (y - z) < d \<longrightarrow> (h has_field_derivative f y) (at y within s))"
  2.2503 +      using d by blast
  2.2504 +  }
  2.2505 +  then show ?thesis
  2.2506 +    by (rule path_integral_local_primitive [OF g])
  2.2507 +qed
  2.2508 +
  2.2509 +lemma path_integrable_holomorphic_simple:
  2.2510 +  assumes contf: "continuous_on s f"
  2.2511 +      and os: "open s"
  2.2512 +      and g: "valid_path g" "path_image g \<subseteq> s"
  2.2513 +      and fh: "f holomorphic_on s"
  2.2514 +    shows "f path_integrable_on g"
  2.2515 +  apply (rule path_integrable_holomorphic [OF contf os Finite_Set.finite.emptyI g])
  2.2516 +  using fh  by (simp add: complex_differentiable_def holomorphic_on_open os)
  2.2517 +
  2.2518 +lemma path_integrable_inversediff:
  2.2519 +    "\<lbrakk>valid_path g; z \<notin> path_image g\<rbrakk> \<Longrightarrow> (\<lambda>w. 1 / (w-z)) path_integrable_on g"
  2.2520 +apply (rule path_integrable_holomorphic_simple [of "UNIV-{z}"])
  2.2521 +    apply (rule continuous_intros | simp)+
  2.2522 + apply blast
  2.2523 +apply (simp add: holomorphic_on_open open_delete)
  2.2524 +apply (force intro: derivative_eq_intros)
  2.2525 +done
  2.2526 +
  2.2527 +text{*Key fact that path integral is the same for a "nearby" path. This is the
  2.2528 + main lemma for the homotopy form of Cauchy's theorem and is also useful
  2.2529 + if we want "without loss of generality" to assume some nice properties of a
  2.2530 + path (e.g. smoothness). It can also be used to define the integrals of
  2.2531 + analytic functions over arbitrary continuous paths. This is just done for
  2.2532 + winding numbers now.
  2.2533 +*}
  2.2534 +
  2.2535 +text{*This formulation covers two cases: @{term g} and @{term h} share their
  2.2536 +      start and end points; @{term g} and @{term h} both loop upon themselves. *}
  2.2537 +lemma path_integral_nearby:
  2.2538 +  assumes os: "open s"
  2.2539 +      and p: "path p" "path_image p \<subseteq> s"
  2.2540 +    shows
  2.2541 +       "\<exists>d. 0 < d \<and>
  2.2542 +            (\<forall>g h. valid_path g \<and> valid_path h \<and>
  2.2543 +                  (\<forall>t \<in> {0..1}. norm(g t - p t) < d \<and> norm(h t - p t) < d) \<and>
  2.2544 +                  (if Ends then pathstart h = pathstart g \<and> pathfinish h = pathfinish g
  2.2545 +                   else pathfinish g = pathstart g \<and> pathfinish h = pathstart h)
  2.2546 +                  \<longrightarrow> path_image g \<subseteq> s \<and> path_image h \<subseteq> s \<and>
  2.2547 +                      (\<forall>f. f holomorphic_on s \<longrightarrow> path_integral h f = path_integral g f))"
  2.2548 +proof -
  2.2549 +  have "\<forall>z. \<exists>e. z \<in> path_image p \<longrightarrow> 0 < e \<and> ball z e \<subseteq> s"
  2.2550 +    using open_contains_ball os p(2) by blast
  2.2551 +  then obtain ee where ee: "\<And>z. z \<in> path_image p \<Longrightarrow> 0 < ee z \<and> ball z (ee z) \<subseteq> s"
  2.2552 +    by metis
  2.2553 +  def cover \<equiv> "(\<lambda>z. ball z (ee z/3)) ` (path_image p)"
  2.2554 +  have "compact (path_image p)"
  2.2555 +    by (metis p(1) compact_path_image)
  2.2556 +  moreover have "path_image p \<subseteq> (\<Union>c\<in>path_image p. ball c (ee c / 3))"
  2.2557 +    using ee by auto
  2.2558 +  ultimately have "\<exists>D \<subseteq> cover. finite D \<and> path_image p \<subseteq> \<Union>D"
  2.2559 +    by (simp add: compact_eq_heine_borel cover_def)
  2.2560 +  then obtain D where D: "D \<subseteq> cover" "finite D" "path_image p \<subseteq> \<Union>D"
  2.2561 +    by blast
  2.2562 +  then obtain k where k: "k \<subseteq> {0..1}" "finite k" and D_eq: "D = ((\<lambda>z. ball z (ee z / 3)) \<circ> p) ` k"
  2.2563 +    apply (simp add: cover_def path_image_def image_comp)
  2.2564 +    apply (blast dest!: finite_subset_image [OF `finite D`])
  2.2565 +    done
  2.2566 +  then have kne: "k \<noteq> {}"
  2.2567 +    using D by auto
  2.2568 +  have pi: "\<And>i. i \<in> k \<Longrightarrow> p i \<in> path_image p"
  2.2569 +    using k  by (auto simp: path_image_def)
  2.2570 +  then have eepi: "\<And>i. i \<in> k \<Longrightarrow> 0 < ee((p i))"
  2.2571 +    by (metis ee)
  2.2572 +  def e \<equiv> "Min((ee o p) ` k)"
  2.2573 +  have fin_eep: "finite ((ee o p) ` k)"
  2.2574 +    using k  by blast
  2.2575 +  have enz: "0 < e"
  2.2576 +    using ee k  by (simp add: kne e_def Min_gr_iff [OF fin_eep] eepi)
  2.2577 +  have "uniformly_continuous_on {0..1} p"
  2.2578 +    using p  by (simp add: path_def compact_uniformly_continuous)
  2.2579 +  then obtain d::real where d: "d>0"
  2.2580 +          and de: "\<And>x x'. \<bar>x' - x\<bar> < d \<Longrightarrow> x\<in>{0..1} \<Longrightarrow> x'\<in>{0..1} \<Longrightarrow> cmod (p x' - p x) < e/3"
  2.2581 +    unfolding uniformly_continuous_on_def dist_norm real_norm_def
  2.2582 +    by (metis divide_pos_pos enz zero_less_numeral)
  2.2583 +  then obtain N::nat where N: "N>0" "inverse N < d"
  2.2584 +    using real_arch_inv [of d]   by auto
  2.2585 +  { fix g h
  2.2586 +    assume g: "valid_path g" and gp: "\<forall>t\<in>{0..1}. cmod (g t - p t) < e / 3"
  2.2587 +       and h: "valid_path h" and hp: "\<forall>t\<in>{0..1}. cmod (h t - p t) < e / 3"
  2.2588 +       and joins: "if Ends then pathstart h = pathstart g \<and> pathfinish h = pathfinish g
  2.2589 +                   else pathfinish g = pathstart g \<and> pathfinish h = pathstart h"
  2.2590 +    { fix t::real
  2.2591 +      assume t: "0 \<le> t" "t \<le> 1"
  2.2592 +      then obtain u where u: "u \<in> k" and ptu: "p t \<in> ball(p u) (ee(p u) / 3)"
  2.2593 +        using `path_image p \<subseteq> \<Union>D` D_eq by (force simp: path_image_def)
  2.2594 +      then have ele: "e \<le> ee (p u)" using fin_eep
  2.2595 +        by (simp add: e_def)
  2.2596 +      have "cmod (g t - p t) < e / 3" "cmod (h t - p t) < e / 3"
  2.2597 +        using gp hp t by auto
  2.2598 +      with ele have "cmod (g t - p t) < ee (p u) / 3"
  2.2599 +                    "cmod (h t - p t) < ee (p u) / 3"
  2.2600 +        by linarith+
  2.2601 +      then have "g t \<in> ball(p u) (ee(p u))"  "h t \<in> ball(p u) (ee(p u))"
  2.2602 +        using norm_diff_triangle_ineq [of "g t" "p t" "p t" "p u"]
  2.2603 +              norm_diff_triangle_ineq [of "h t" "p t" "p t" "p u"] ptu eepi u
  2.2604 +        by (force simp add: dist_norm ball_def norm_minus_commute)+
  2.2605 +      then have "g t \<in> s" "h t \<in> s" using ee u k
  2.2606 +        by (auto simp: path_image_def ball_def)
  2.2607 +    }
  2.2608 +    then have ghs: "path_image g \<subseteq> s" "path_image h \<subseteq> s"
  2.2609 +      by (auto simp: path_image_def)
  2.2610 +    moreover
  2.2611 +    { fix f
  2.2612 +      assume fhols: "f holomorphic_on s"
  2.2613 +      then have fpa: "f path_integrable_on g"  "f path_integrable_on h"
  2.2614 +        using g ghs h holomorphic_on_imp_continuous_on os path_integrable_holomorphic_simple
  2.2615 +        by blast+
  2.2616 +      have contf: "continuous_on s f"
  2.2617 +        by (simp add: fhols holomorphic_on_imp_continuous_on)
  2.2618 +      { fix z
  2.2619 +        assume z: "z \<in> path_image p"
  2.2620 +        have "f holomorphic_on ball z (ee z)"
  2.2621 +          using fhols ee z holomorphic_on_subset by blast
  2.2622 +        then have "\<exists>ff. (\<forall>w \<in> ball z (ee z). (ff has_field_derivative f w) (at w))"
  2.2623 +          using holomorphic_convex_primitive [of "ball z (ee z)" "{}" f, simplified]
  2.2624 +          by (metis open_ball at_within_open holomorphic_on_def holomorphic_on_imp_continuous_on mem_ball)
  2.2625 +      }
  2.2626 +      then obtain ff where ff:
  2.2627 +            "\<And>z w. \<lbrakk>z \<in> path_image p; w \<in> ball z (ee z)\<rbrakk> \<Longrightarrow> (ff z has_field_derivative f w) (at w)"
  2.2628 +        by metis
  2.2629 +      { fix n
  2.2630 +        assume n: "n \<le> N"
  2.2631 +        then have "path_integral(subpath 0 (n/N) h) f - path_integral(subpath 0 (n/N) g) f =
  2.2632 +                   path_integral(linepath (g(n/N)) (h(n/N))) f - path_integral(linepath (g 0) (h 0)) f"
  2.2633 +        proof (induct n)
  2.2634 +          case 0 show ?case by simp
  2.2635 +        next
  2.2636 +          case (Suc n)
  2.2637 +          obtain t where t: "t \<in> k" and "p (n/N) \<in> ball(p t) (ee(p t) / 3)"
  2.2638 +            using `path_image p \<subseteq> \<Union>D` [THEN subsetD, where c="p (n/N)"] D_eq N Suc.prems
  2.2639 +            by (force simp add: path_image_def)
  2.2640 +          then have ptu: "cmod (p t - p (n/N)) < ee (p t) / 3"
  2.2641 +            by (simp add: dist_norm)
  2.2642 +          have e3le: "e/3 \<le> ee (p t) / 3"  using fin_eep t
  2.2643 +            by (simp add: e_def)
  2.2644 +          { fix x
  2.2645 +            assume x: "n/N \<le> x" "x \<le> (1 + n)/N"
  2.2646 +            then have nN01: "0 \<le> n/N" "(1 + n)/N \<le> 1"
  2.2647 +              using Suc.prems by auto
  2.2648 +            then have x01: "0 \<le> x" "x \<le> 1"
  2.2649 +              using x by linarith+
  2.2650 +            have "cmod (p t - p x)  < ee (p t) / 3 + e/3"
  2.2651 +              apply (rule norm_diff_triangle_less [OF ptu de])
  2.2652 +              using x N x01 Suc.prems
  2.2653 +              apply (auto simp: field_simps)
  2.2654 +              done
  2.2655 +            then have ptx: "cmod (p t - p x) < 2*ee (p t)/3"
  2.2656 +              using e3le eepi [OF t] by simp
  2.2657 +            have "cmod (p t - g x) < 2*ee (p t)/3 + e/3 "
  2.2658 +              apply (rule norm_diff_triangle_less [OF ptx])
  2.2659 +              using gp x01 by (simp add: norm_minus_commute)
  2.2660 +            also have "... \<le> ee (p t)"
  2.2661 +              using e3le eepi [OF t] by simp
  2.2662 +            finally have gg: "cmod (p t - g x) < ee (p t)" .
  2.2663 +            have "cmod (p t - h x) < 2*ee (p t)/3 + e/3 "
  2.2664 +              apply (rule norm_diff_triangle_less [OF ptx])
  2.2665 +              using hp x01 by (simp add: norm_minus_commute)
  2.2666 +            also have "... \<le> ee (p t)"
  2.2667 +              using e3le eepi [OF t] by simp
  2.2668 +            finally have "cmod (p t - g x) < ee (p t)"
  2.2669 +                         "cmod (p t - h x) < ee (p t)"
  2.2670 +              using gg by auto
  2.2671 +          } note ptgh_ee = this
  2.2672 +          have pi_hgn: "path_image (linepath (h (n/N)) (g (n/N))) \<subseteq> ball (p t) (ee (p t))"
  2.2673 +            using ptgh_ee [of "n/N"] Suc.prems
  2.2674 +            by (auto simp: field_simps real_of_nat_def dist_norm dest: segment_furthest_le [where y="p t"])
  2.2675 +          then have gh_ns: "closed_segment (g (n/N)) (h (n/N)) \<subseteq> s"
  2.2676 +            using `N>0` Suc.prems
  2.2677 +            apply (simp add: real_of_nat_def path_image_join field_simps closed_segment_commute)
  2.2678 +            apply (erule order_trans)
  2.2679 +            apply (simp add: ee pi t)
  2.2680 +            done
  2.2681 +          have pi_ghn': "path_image (linepath (g ((1 + n) / N)) (h ((1 + n) / N)))
  2.2682 +                  \<subseteq> ball (p t) (ee (p t))"
  2.2683 +            using ptgh_ee [of "(1+n)/N"] Suc.prems
  2.2684 +            by (auto simp: field_simps real_of_nat_def dist_norm dest: segment_furthest_le [where y="p t"])
  2.2685 +          then have gh_n's: "closed_segment (g ((1 + n) / N)) (h ((1 + n) / N)) \<subseteq> s"
  2.2686 +            using `N>0` Suc.prems ee pi t
  2.2687 +            by (auto simp: Path_Connected.path_image_join field_simps)
  2.2688 +          have pi_subset_ball:
  2.2689 +                "path_image (subpath (n/N) ((1+n) / N) g +++ linepath (g ((1+n) / N)) (h ((1+n) / N)) +++
  2.2690 +                             subpath ((1+n) / N) (n/N) h +++ linepath (h (n/N)) (g (n/N)))
  2.2691 +                 \<subseteq> ball (p t) (ee (p t))"
  2.2692 +            apply (intro subset_path_image_join pi_hgn pi_ghn')
  2.2693 +            using `N>0` Suc.prems
  2.2694 +            apply (auto simp: dist_norm field_simps ptgh_ee)
  2.2695 +            done
  2.2696 +          have pi0: "(f has_path_integral 0)
  2.2697 +                       (subpath (n/ N) ((Suc n)/N) g +++ linepath(g ((Suc n) / N)) (h((Suc n) / N)) +++
  2.2698 +                        subpath ((Suc n) / N) (n/N) h +++ linepath(h (n/N)) (g (n/N)))"
  2.2699 +            apply (rule Cauchy_theorem_primitive [of "ball(p t) (ee(p t))" "ff (p t)" "f"])
  2.2700 +            apply (metis ff open_ball at_within_open pi t)
  2.2701 +            apply (intro valid_path_join)
  2.2702 +            using Suc.prems pi_subset_ball apply (simp_all add: valid_path_subpath g h)
  2.2703 +            done
  2.2704 +          have fpa1: "f path_integrable_on subpath (real n / real N) (real (Suc n) / real N) g"
  2.2705 +            using Suc.prems by (simp add: path_integrable_subpath g fpa)
  2.2706 +          have fpa2: "f path_integrable_on linepath (g (real (Suc n) / real N)) (h (real (Suc n) / real N))"
  2.2707 +            using gh_n's
  2.2708 +            by (auto intro!: path_integrable_continuous_linepath continuous_on_subset [OF contf])
  2.2709 +          have fpa3: "f path_integrable_on linepath (h (real n / real N)) (g (real n / real N))"
  2.2710 +            using gh_ns
  2.2711 +            by (auto simp: closed_segment_commute intro!: path_integrable_continuous_linepath continuous_on_subset [OF contf])
  2.2712 +          have eq0: "path_integral (subpath (n/N) ((Suc n) / real N) g) f +
  2.2713 +                     path_integral (linepath (g ((Suc n) / N)) (h ((Suc n) / N))) f +
  2.2714 +                     path_integral (subpath ((Suc n) / N) (n/N) h) f +
  2.2715 +                     path_integral (linepath (h (n/N)) (g (n/N))) f = 0"
  2.2716 +            using path_integral_unique [OF pi0] Suc.prems
  2.2717 +            by (simp add: g h fpa valid_path_subpath path_integrable_subpath
  2.2718 +                          fpa1 fpa2 fpa3 algebra_simps)
  2.2719 +          have *: "\<And>hn he hn' gn gd gn' hgn ghn gh0 ghn'.
  2.2720 +                    \<lbrakk>hn - gn = ghn - gh0;
  2.2721 +                     gd + ghn' + he + hgn = (0::complex);
  2.2722 +                     hn - he = hn'; gn + gd = gn'; hgn = -ghn\<rbrakk> \<Longrightarrow> hn' - gn' = ghn' - gh0"
  2.2723 +            by (auto simp: algebra_simps)
  2.2724 +          have "path_integral (subpath 0 (n/N) h) f - path_integral (subpath ((Suc n) / N) (n/N) h) f =
  2.2725 +                path_integral (subpath 0 (n/N) h) f + path_integral (subpath (n/N) ((Suc n) / N) h) f"
  2.2726 +            unfolding reversepath_subpath [symmetric, of "((Suc n) / N)"]
  2.2727 +            using Suc.prems by (simp add: h fpa path_integral_reversepath valid_path_subpath path_integrable_subpath)
  2.2728 +          also have "... = path_integral (subpath 0 ((Suc n) / N) h) f"
  2.2729 +            using Suc.prems by (simp add: path_integral_subpath_combine h fpa)
  2.2730 +          finally have pi0_eq:
  2.2731 +               "path_integral (subpath 0 (n/N) h) f - path_integral (subpath ((Suc n) / N) (n/N) h) f =
  2.2732 +                path_integral (subpath 0 ((Suc n) / N) h) f" .
  2.2733 +          show ?case
  2.2734 +            apply (rule * [OF Suc.hyps eq0 pi0_eq])
  2.2735 +            using Suc.prems
  2.2736 +            apply (simp_all add: g h fpa path_integral_subpath_combine
  2.2737 +                     path_integral_reversepath [symmetric] path_integrable_continuous_linepath
  2.2738 +                     continuous_on_subset [OF contf gh_ns])
  2.2739 +            done
  2.2740 +      qed
  2.2741 +      } note ind = this
  2.2742 +      have "path_integral h f = path_integral g f"
  2.2743 +        using ind [OF order_refl] N joins
  2.2744 +        by (simp add: pathstart_def pathfinish_def split: split_if_asm)
  2.2745 +    }
  2.2746 +    ultimately
  2.2747 +    have "path_image g \<subseteq> s \<and> path_image h \<subseteq> s \<and> (\<forall>f. f holomorphic_on s \<longrightarrow> path_integral h f = path_integral g f)"
  2.2748 +      by metis
  2.2749 +  } note * = this
  2.2750 +  show ?thesis
  2.2751 +    apply (rule_tac x="e/3" in exI)
  2.2752 +    apply (rule conjI)
  2.2753 +    using enz apply simp
  2.2754 +    apply (clarsimp simp only: ball_conj_distrib)
  2.2755 +    apply (rule *; assumption)
  2.2756 +    done
  2.2757 +qed
  2.2758 +
  2.2759 +
  2.2760 +lemma
  2.2761 +  assumes "open s" "path p" "path_image p \<subseteq> s"
  2.2762 +    shows path_integral_nearby_ends:
  2.2763 +      "\<exists>d. 0 < d \<and>
  2.2764 +              (\<forall>g h. valid_path g \<and> valid_path h \<and>
  2.2765 +                    (\<forall>t \<in> {0..1}. norm(g t - p t) < d \<and> norm(h t - p t) < d) \<and>
  2.2766 +                    pathstart h = pathstart g \<and> pathfinish h = pathfinish g
  2.2767 +                    \<longrightarrow> path_image g \<subseteq> s \<and>
  2.2768 +                        path_image h \<subseteq> s \<and>
  2.2769 +                        (\<forall>f. f holomorphic_on s
  2.2770 +                            \<longrightarrow> path_integral h f = path_integral g f))"
  2.2771 +    and path_integral_nearby_loop:
  2.2772 +      "\<exists>d. 0 < d \<and>
  2.2773 +              (\<forall>g h. valid_path g \<and> valid_path h \<and>
  2.2774 +                    (\<forall>t \<in> {0..1}. norm(g t - p t) < d \<and> norm(h t - p t) < d) \<and>
  2.2775 +                    pathfinish g = pathstart g \<and> pathfinish h = pathstart h
  2.2776 +                    \<longrightarrow> path_image g \<subseteq> s \<and>
  2.2777 +                        path_image h \<subseteq> s \<and>
  2.2778 +                        (\<forall>f. f holomorphic_on s
  2.2779 +                            \<longrightarrow> path_integral h f = path_integral g f))"
  2.2780 +  using path_integral_nearby [OF assms, where Ends=True]
  2.2781 +  using path_integral_nearby [OF assms, where Ends=False]
  2.2782 +  by simp_all
  2.2783 +
  2.2784 +end
     3.1 --- a/src/HOL/Multivariate_Analysis/Complex_Transcendental.thy	Tue Jul 28 13:00:54 2015 +0200
     3.2 +++ b/src/HOL/Multivariate_Analysis/Complex_Transcendental.thy	Tue Jul 28 16:16:13 2015 +0100
     3.3 @@ -1448,15 +1448,15 @@
     3.4    fixes n::nat and z::complex shows "z powr n = (if z = 0 then 0 else z^n)"
     3.5    by (simp add: exp_of_nat_mult powr_def)
     3.6  
     3.7 -lemma powr_add:
     3.8 +lemma powr_add_complex:
     3.9    fixes w::complex shows "w powr (z1 + z2) = w powr z1 * w powr z2"
    3.10    by (simp add: powr_def algebra_simps exp_add)
    3.11  
    3.12 -lemma powr_minus:
    3.13 +lemma powr_minus_complex:
    3.14    fixes w::complex shows  "w powr (-z) = inverse(w powr z)"
    3.15    by (simp add: powr_def exp_minus)
    3.16  
    3.17 -lemma powr_diff:
    3.18 +lemma powr_diff_complex:
    3.19    fixes w::complex shows  "w powr (z1 - z2) = w powr z1 / w powr z2"
    3.20    by (simp add: powr_def algebra_simps exp_diff)
    3.21  
     4.1 --- a/src/HOL/Multivariate_Analysis/Convex_Euclidean_Space.thy	Tue Jul 28 13:00:54 2015 +0200
     4.2 +++ b/src/HOL/Multivariate_Analysis/Convex_Euclidean_Space.thy	Tue Jul 28 16:16:13 2015 +0100
     4.3 @@ -3554,7 +3554,7 @@
     4.4        using mem_rel_interior[of "a+x" "((\<lambda>x. a + x) ` S)"] by auto
     4.5    }
     4.6    then show ?thesis by auto
     4.7 -qed                   
     4.8 +qed
     4.9  
    4.10  lemma rel_interior_translation:
    4.11    fixes a :: "'n::euclidean_space"
    4.12 @@ -6317,7 +6317,7 @@
    4.13  
    4.14  lemma closed_segment_subset_convex_hull:
    4.15      "\<lbrakk>x \<in> convex hull s; y \<in> convex hull s\<rbrakk> \<Longrightarrow> closed_segment x y \<subseteq> convex hull s"
    4.16 -  using convex_contains_segment by blast  
    4.17 +  using convex_contains_segment by blast
    4.18  
    4.19  lemma convex_imp_starlike:
    4.20    "convex s \<Longrightarrow> s \<noteq> {} \<Longrightarrow> starlike s"
    4.21 @@ -6396,6 +6396,10 @@
    4.22      by (auto simp: closed_segment_commute)
    4.23  qed
    4.24  
    4.25 +lemma closed_segment_real_eq:
    4.26 +  fixes u::real shows "closed_segment u v = (\<lambda>x. (v - u) * x + u) ` {0..1}"
    4.27 +  by (simp add: add.commute [of u] image_affinity_atLeastAtMost [where c=u] closed_segment_eq_real_ivl)
    4.28 +
    4.29  lemma between_mem_segment: "between (a,b) x \<longleftrightarrow> x \<in> closed_segment a b"
    4.30    unfolding between_def by auto
    4.31  
    4.32 @@ -8941,25 +8945,25 @@
    4.33  proof -
    4.34    have fin: "finite s" "finite t" using assms aff_independent_finite finite_subset by auto
    4.35      { fix u v x
    4.36 -      assume uv: "setsum u t = 1" "\<forall>x\<in>s. 0 \<le> v x" "setsum v s = 1" 
    4.37 +      assume uv: "setsum u t = 1" "\<forall>x\<in>s. 0 \<le> v x" "setsum v s = 1"
    4.38                   "(\<Sum>x\<in>s. v x *\<^sub>R x) = (\<Sum>v\<in>t. u v *\<^sub>R v)" "x \<in> t"
    4.39        then have s: "s = (s - t) \<union> t" --\<open>split into separate cases\<close>
    4.40          using assms by auto
    4.41        have [simp]: "(\<Sum>x\<in>t. v x *\<^sub>R x) + (\<Sum>x\<in>s - t. v x *\<^sub>R x) = (\<Sum>x\<in>t. u x *\<^sub>R x)"
    4.42                     "setsum v t + setsum v (s - t) = 1"
    4.43          using uv fin s
    4.44 -        by (auto simp: setsum.union_disjoint [symmetric] Un_commute)        
    4.45 -      have "(\<Sum>x\<in>s. if x \<in> t then v x - u x else v x) = 0" 
    4.46 +        by (auto simp: setsum.union_disjoint [symmetric] Un_commute)
    4.47 +      have "(\<Sum>x\<in>s. if x \<in> t then v x - u x else v x) = 0"
    4.48             "(\<Sum>x\<in>s. (if x \<in> t then v x - u x else v x) *\<^sub>R x) = 0"
    4.49          using uv fin
    4.50          by (subst s, subst setsum.union_disjoint, auto simp: algebra_simps setsum_subtractf)+
    4.51      } note [simp] = this
    4.52 -  have "convex hull t \<subseteq> affine hull t" 
    4.53 +  have "convex hull t \<subseteq> affine hull t"
    4.54      using convex_hull_subset_affine_hull by blast
    4.55    moreover have "convex hull t \<subseteq> convex hull s"
    4.56      using assms hull_mono by blast
    4.57    moreover have "affine hull t \<inter> convex hull s \<subseteq> convex hull t"
    4.58 -    using assms 
    4.59 +    using assms
    4.60      apply (simp add: convex_hull_finite affine_hull_finite fin affine_dependent_explicit)
    4.61      apply (drule_tac x=s in spec)
    4.62      apply (auto simp: fin)
    4.63 @@ -8972,7 +8976,7 @@
    4.64      by blast
    4.65  qed
    4.66  
    4.67 -lemma affine_independent_span_eq: 
    4.68 +lemma affine_independent_span_eq:
    4.69    fixes s :: "'a::euclidean_space set"
    4.70    assumes "~affine_dependent s" "card s = Suc (DIM ('a))"
    4.71      shows "affine hull s = UNIV"
    4.72 @@ -8983,7 +8987,7 @@
    4.73    case False
    4.74      then obtain a t where t: "a \<notin> t" "s = insert a t"
    4.75        by blast
    4.76 -    then have fin: "finite t" using assms 
    4.77 +    then have fin: "finite t" using assms
    4.78        by (metis finite_insert aff_independent_finite)
    4.79      show ?thesis
    4.80      using assms t fin
    4.81 @@ -8997,7 +9001,7 @@
    4.82        done
    4.83  qed
    4.84  
    4.85 -lemma affine_independent_span_gt: 
    4.86 +lemma affine_independent_span_gt:
    4.87    fixes s :: "'a::euclidean_space set"
    4.88    assumes ind: "~ affine_dependent s" and dim: "DIM ('a) < card s"
    4.89      shows "affine hull s = UNIV"
    4.90 @@ -9008,7 +9012,7 @@
    4.91    apply (metis add_2_eq_Suc' not_less_eq_eq affine_dependent_biggerset aff_independent_finite)
    4.92    done
    4.93  
    4.94 -lemma empty_interior_affine_hull: 
    4.95 +lemma empty_interior_affine_hull:
    4.96    fixes s :: "'a::euclidean_space set"
    4.97    assumes "finite s" and dim: "card s \<le> DIM ('a)"
    4.98      shows "interior(affine hull s) = {}"
    4.99 @@ -9020,33 +9024,33 @@
   4.100    apply (metis Suc_le_lessD not_less order_trans card_image_le finite_imageI dim_le_card)
   4.101    done
   4.102  
   4.103 -lemma empty_interior_convex_hull: 
   4.104 +lemma empty_interior_convex_hull:
   4.105    fixes s :: "'a::euclidean_space set"
   4.106    assumes "finite s" and dim: "card s \<le> DIM ('a)"
   4.107      shows "interior(convex hull s) = {}"
   4.108 -  by (metis Diff_empty Diff_eq_empty_iff convex_hull_subset_affine_hull 
   4.109 +  by (metis Diff_empty Diff_eq_empty_iff convex_hull_subset_affine_hull
   4.110              interior_mono empty_interior_affine_hull [OF assms])
   4.111  
   4.112  lemma explicit_subset_rel_interior_convex_hull:
   4.113    fixes s :: "'a::euclidean_space set"
   4.114 -  shows "finite s 
   4.115 +  shows "finite s
   4.116           \<Longrightarrow> {y. \<exists>u. (\<forall>x \<in> s. 0 < u x \<and> u x < 1) \<and> setsum u s = 1 \<and> setsum (\<lambda>x. u x *\<^sub>R x) s = y}
   4.117               \<subseteq> rel_interior (convex hull s)"
   4.118    by (force simp add:  rel_interior_convex_hull_union [where S="\<lambda>x. {x}" and I=s, simplified])
   4.119  
   4.120 -lemma explicit_subset_rel_interior_convex_hull_minimal: 
   4.121 +lemma explicit_subset_rel_interior_convex_hull_minimal:
   4.122    fixes s :: "'a::euclidean_space set"
   4.123 -  shows "finite s 
   4.124 +  shows "finite s
   4.125           \<Longrightarrow> {y. \<exists>u. (\<forall>x \<in> s. 0 < u x) \<and> setsum u s = 1 \<and> setsum (\<lambda>x. u x *\<^sub>R x) s = y}
   4.126               \<subseteq> rel_interior (convex hull s)"
   4.127    by (force simp add:  rel_interior_convex_hull_union [where S="\<lambda>x. {x}" and I=s, simplified])
   4.128  
   4.129 -lemma rel_interior_convex_hull_explicit: 
   4.130 +lemma rel_interior_convex_hull_explicit:
   4.131    fixes s :: "'a::euclidean_space set"
   4.132    assumes "~ affine_dependent s"
   4.133    shows "rel_interior(convex hull s) =
   4.134           {y. \<exists>u. (\<forall>x \<in> s. 0 < u x) \<and> setsum u s = 1 \<and> setsum (\<lambda>x. u x *\<^sub>R x) s = y}"
   4.135 -         (is "?lhs = ?rhs")  
   4.136 +         (is "?lhs = ?rhs")
   4.137  proof
   4.138    show "?rhs \<le> ?lhs"
   4.139      by (simp add: aff_independent_finite explicit_subset_rel_interior_convex_hull_minimal assms)
   4.140 @@ -9063,7 +9067,7 @@
   4.141        assume ab: "a \<in> s" "b \<in> s" "a \<noteq> b"
   4.142        then have s: "s = (s - {a,b}) \<union> {a,b}" --\<open>split into separate cases\<close>
   4.143          by auto
   4.144 -      have "(\<Sum>x\<in>s. if x = a then - d else if x = b then d else 0) = 0" 
   4.145 +      have "(\<Sum>x\<in>s. if x = a then - d else if x = b then d else 0) = 0"
   4.146             "(\<Sum>x\<in>s. (if x = a then - d else if x = b then d else 0) *\<^sub>R x) = d *\<^sub>R b - d *\<^sub>R a"
   4.147          using ab fs
   4.148          by (subst s, subst setsum.union_disjoint, auto)+
   4.149 @@ -9073,7 +9077,7 @@
   4.150        { fix u T a
   4.151          assume ua: "\<forall>x\<in>s. 0 \<le> u x" "setsum u s = 1" "\<not> 0 < u a" "a \<in> s"
   4.152             and yT: "y = (\<Sum>x\<in>s. u x *\<^sub>R x)" "y \<in> T" "open T"
   4.153 -           and sb: "T \<inter> affine hull s \<subseteq> {w. \<exists>u. (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<and> (\<Sum>x\<in>s. u x *\<^sub>R x) = w}" 
   4.154 +           and sb: "T \<inter> affine hull s \<subseteq> {w. \<exists>u. (\<forall>x\<in>s. 0 \<le> u x) \<and> setsum u s = 1 \<and> (\<Sum>x\<in>s. u x *\<^sub>R x) = w}"
   4.155          have ua0: "u a = 0"
   4.156            using ua by auto
   4.157          obtain b where b: "b\<in>s" "a \<noteq> b"
   4.158 @@ -9088,13 +9092,13 @@
   4.159            using ua b by (auto simp: hull_inc intro: mem_affine_3_minus2)
   4.160          then have "y - d *\<^sub>R (a - b) \<in> T \<inter> affine hull s"
   4.161            using d e yT by auto
   4.162 -        then obtain v where "\<forall>x\<in>s. 0 \<le> v x" 
   4.163 -                            "setsum v s = 1" 
   4.164 +        then obtain v where "\<forall>x\<in>s. 0 \<le> v x"
   4.165 +                            "setsum v s = 1"
   4.166                              "(\<Sum>x\<in>s. v x *\<^sub>R x) = (\<Sum>x\<in>s. u x *\<^sub>R x) - d *\<^sub>R (a - b)"
   4.167            using subsetD [OF sb] yT
   4.168            by auto
   4.169          then have False
   4.170 -          using assms 
   4.171 +          using assms
   4.172            apply (simp add: affine_dependent_explicit_finite fs)
   4.173            apply (drule_tac x="\<lambda>x. (v x - u x) - (if x = a then -d else if x = b then d else 0)" in spec)
   4.174            using ua b d
   4.175 @@ -9146,14 +9150,14 @@
   4.176        case False
   4.177        then show thesis
   4.178        by (blast intro: that)
   4.179 -    qed        
   4.180 +    qed
   4.181      have "u a + u b \<le> setsum u {a,b}"
   4.182        using a b by simp
   4.183      also have "... \<le> setsum u s"
   4.184        apply (rule Groups_Big.setsum_mono2)
   4.185        using a b u
   4.186        apply (auto simp: less_imp_le aff_independent_finite assms)
   4.187 -      done      
   4.188 +      done
   4.189      finally have "u a < 1"
   4.190        using \<open>b \<in> s\<close> u by fastforce
   4.191    } note [simp] = this
   4.192 @@ -9200,7 +9204,7 @@
   4.193    fixes s :: "'a::euclidean_space set"
   4.194    assumes "~ affine_dependent s"
   4.195    shows "frontier(convex hull s) =
   4.196 -         {y. \<exists>u. (\<forall>x \<in> s. 0 \<le> u x) \<and> (DIM ('a) < card s \<longrightarrow> (\<exists>x \<in> s. u x = 0)) \<and> 
   4.197 +         {y. \<exists>u. (\<forall>x \<in> s. 0 \<le> u x) \<and> (DIM ('a) < card s \<longrightarrow> (\<exists>x \<in> s. u x = 0)) \<and>
   4.198               setsum u s = 1 \<and> setsum (\<lambda>x. u x *\<^sub>R x) s = y}"
   4.199  proof -
   4.200    have fs: "finite s"
   4.201 @@ -9209,7 +9213,7 @@
   4.202    proof (cases "DIM ('a) < card s")
   4.203      case True
   4.204      with assms fs show ?thesis
   4.205 -      by (simp add: rel_frontier_def frontier_def rel_frontier_convex_hull_explicit [symmetric] 
   4.206 +      by (simp add: rel_frontier_def frontier_def rel_frontier_convex_hull_explicit [symmetric]
   4.207                      interior_convex_hull_explicit_minimal rel_interior_convex_hull_explicit)
   4.208    next
   4.209      case False
   4.210 @@ -9239,7 +9243,7 @@
   4.211      apply (rule_tac x=u in exI)
   4.212      apply (simp add: Groups_Big.setsum_diff1 fs)
   4.213      done }
   4.214 -  moreover 
   4.215 +  moreover
   4.216    { fix a u
   4.217      have "a \<in> s \<Longrightarrow> \<forall>x\<in>s - {a}. 0 \<le> u x \<Longrightarrow> setsum u (s - {a}) = 1 \<Longrightarrow>
   4.218              \<exists>v. (\<forall>x\<in>s. 0 \<le> v x) \<and>
   4.219 @@ -9257,17 +9261,17 @@
   4.220  lemma frontier_convex_hull_eq_rel_frontier:
   4.221    fixes s :: "'a::euclidean_space set"
   4.222    assumes "~ affine_dependent s"
   4.223 -  shows "frontier(convex hull s) = 
   4.224 +  shows "frontier(convex hull s) =
   4.225             (if card s \<le> DIM ('a) then convex hull s else rel_frontier(convex hull s))"
   4.226 -  using assms 
   4.227 -  unfolding rel_frontier_def frontier_def 
   4.228 -  by (simp add: affine_independent_span_gt rel_interior_interior  
   4.229 +  using assms
   4.230 +  unfolding rel_frontier_def frontier_def
   4.231 +  by (simp add: affine_independent_span_gt rel_interior_interior
   4.232                  finite_imp_compact empty_interior_convex_hull aff_independent_finite)
   4.233  
   4.234  lemma frontier_convex_hull_cases:
   4.235    fixes s :: "'a::euclidean_space set"
   4.236    assumes "~ affine_dependent s"
   4.237 -  shows "frontier(convex hull s) = 
   4.238 +  shows "frontier(convex hull s) =
   4.239             (if card s \<le> DIM ('a) then convex hull s else \<Union>{convex hull (s - {x}) |x. x \<in> s})"
   4.240  by (simp add: assms frontier_convex_hull_eq_rel_frontier rel_frontier_convex_hull_cases)
   4.241  
   4.242 @@ -9276,13 +9280,13 @@
   4.243    assumes "finite s" "card s \<le> Suc (DIM ('a))" "x \<in> s"
   4.244    shows   "x \<in> frontier(convex hull s)"
   4.245  proof (cases "affine_dependent s")
   4.246 -  case True 
   4.247 +  case True
   4.248    with assms show ?thesis
   4.249      apply (auto simp: affine_dependent_def frontier_def finite_imp_compact hull_inc)
   4.250      by (metis card.insert_remove convex_hull_subset_affine_hull empty_interior_affine_hull finite_Diff hull_redundant insert_Diff insert_Diff_single insert_not_empty interior_mono not_less_eq_eq subset_empty)
   4.251  next
   4.252 -  case False 
   4.253 -  { assume "card s = Suc (card Basis)" 
   4.254 +  case False
   4.255 +  { assume "card s = Suc (card Basis)"
   4.256      then have cs: "Suc 0 < card s"
   4.257        by (simp add: DIM_positive)
   4.258      with subset_singletonD have "\<exists>y \<in> s. y \<noteq> x"
   4.259 @@ -9444,7 +9448,7 @@
   4.260  lemma coplanar_linear_image_eq:
   4.261    fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
   4.262    assumes "linear f" "inj f" shows "coplanar(f ` s) = coplanar s"
   4.263 -proof 
   4.264 +proof
   4.265    assume "coplanar s"
   4.266    then show "coplanar (f ` s)"
   4.267      unfolding coplanar_def
   4.268 @@ -9463,7 +9467,7 @@
   4.269      using g by (simp add: Fun.image_comp)
   4.270    then show "coplanar s"
   4.271      unfolding coplanar_def
   4.272 -    using affine_hull_linear_image [of g "{u,v,w}" for u v w]  `linear g` linear_conv_bounded_linear 
   4.273 +    using affine_hull_linear_image [of g "{u,v,w}" for u v w]  `linear g` linear_conv_bounded_linear
   4.274      by fastforce
   4.275  qed
   4.276  (*The HOL Light proof is simply
     5.1 --- a/src/HOL/Multivariate_Analysis/Path_Connected.thy	Tue Jul 28 13:00:54 2015 +0200
     5.2 +++ b/src/HOL/Multivariate_Analysis/Path_Connected.thy	Tue Jul 28 16:16:13 2015 +0100
     5.3 @@ -9,27 +9,6 @@
     5.4  begin
     5.5  
     5.6  (*FIXME move up?*)
     5.7 -lemma image_add_atLeastAtMost [simp]:
     5.8 -  fixes d::"'a::linordered_idom" shows "(op + d ` {a..b}) = {a+d..b+d}"
     5.9 -  apply auto
    5.10 -  apply (rule_tac x="x-d" in rev_image_eqI, auto)
    5.11 -  done
    5.12 -
    5.13 -lemma image_diff_atLeastAtMost [simp]:
    5.14 -  fixes d::"'a::linordered_idom" shows "(op - d ` {a..b}) = {d-b..d-a}"
    5.15 -  apply auto
    5.16 -  apply (rule_tac x="d-x" in rev_image_eqI, auto)
    5.17 -  done
    5.18 -
    5.19 -lemma image_mult_atLeastAtMost [simp]:
    5.20 -  fixes d::"'a::linordered_field"
    5.21 -  assumes "d>0" shows "(op * d ` {a..b}) = {d*a..d*b}"
    5.22 -  using assms
    5.23 -  apply auto
    5.24 -  apply (rule_tac x="x/d" in rev_image_eqI)
    5.25 -  apply (auto simp: field_simps)
    5.26 -  done
    5.27 -
    5.28  lemma image_affinity_interval:
    5.29    fixes c :: "'a::ordered_real_vector"
    5.30    shows "((\<lambda>x. m *\<^sub>R x + c) ` {a..b}) = (if {a..b}={} then {}
    5.31 @@ -40,40 +19,10 @@
    5.32    apply (rule_tac x="inverse m *\<^sub>R (x-c)" in rev_image_eqI, auto simp: pos_le_divideR_eq le_diff_eq scaleR_left_mono_neg)
    5.33    apply (metis diff_le_eq inverse_inverse_eq order.not_eq_order_implies_strict pos_le_divideR_eq positive_imp_inverse_positive)
    5.34    apply (rule_tac x="inverse m *\<^sub>R (x-c)" in rev_image_eqI, auto simp: not_le neg_le_divideR_eq diff_le_eq)
    5.35 -  using le_diff_eq scaleR_le_cancel_left_neg 
    5.36 +  using le_diff_eq scaleR_le_cancel_left_neg
    5.37    apply fastforce
    5.38    done
    5.39  
    5.40 -lemma image_affinity_atLeastAtMost:
    5.41 -  fixes c :: "'a::linordered_field"
    5.42 -  shows "((\<lambda>x. m*x + c) ` {a..b}) = (if {a..b}={} then {}
    5.43 -            else if 0 \<le> m then {m*a + c .. m *b + c}
    5.44 -            else {m*b + c .. m*a + c})"
    5.45 -  apply (case_tac "m=0", auto)
    5.46 -  apply (rule_tac x="inverse m*(x-c)" in rev_image_eqI, auto simp: field_simps)
    5.47 -  apply (rule_tac x="inverse m*(x-c)" in rev_image_eqI, auto simp: field_simps)
    5.48 -  done
    5.49 -
    5.50 -lemma image_affinity_atLeastAtMost_diff:
    5.51 -  fixes c :: "'a::linordered_field"
    5.52 -  shows "((\<lambda>x. m*x - c) ` {a..b}) = (if {a..b}={} then {}
    5.53 -            else if 0 \<le> m then {m*a - c .. m*b - c}
    5.54 -            else {m*b - c .. m*a - c})"
    5.55 -  using image_affinity_atLeastAtMost [of m "-c" a b]
    5.56 -  by simp
    5.57 -
    5.58 -lemma image_affinity_atLeastAtMost_div_diff:
    5.59 -  fixes c :: "'a::linordered_field"
    5.60 -  shows "((\<lambda>x. x/m - c) ` {a..b}) = (if {a..b}={} then {}
    5.61 -            else if 0 \<le> m then {a/m - c .. b/m - c}
    5.62 -            else {b/m - c .. a/m - c})"
    5.63 -  using image_affinity_atLeastAtMost_diff [of "inverse m" c a b]
    5.64 -  by (simp add: field_class.field_divide_inverse algebra_simps)
    5.65 -
    5.66 -lemma closed_segment_real_eq:
    5.67 -  fixes u::real shows "closed_segment u v = (\<lambda>x. (v - u) * x + u) ` {0..1}"
    5.68 -  by (simp add: add.commute [of u] image_affinity_atLeastAtMost [where c=u] closed_segment_eq_real_ivl)
    5.69 -
    5.70  subsection \<open>Paths and Arcs\<close>
    5.71  
    5.72  definition path :: "(real \<Rightarrow> 'a::topological_space) \<Rightarrow> bool"
    5.73 @@ -174,7 +123,7 @@
    5.74  lemma joinpaths_linear_image: "linear f \<Longrightarrow> (f o g1) +++ (f o g2) = f o (g1 +++ g2)"
    5.75    by (rule ext) (simp add: joinpaths_def)
    5.76  
    5.77 -lemma simple_path_translation_eq: 
    5.78 +lemma simple_path_translation_eq:
    5.79    fixes g :: "real \<Rightarrow> 'a::euclidean_space"
    5.80    shows "simple_path((\<lambda>x. a + x) o g) = simple_path g"
    5.81    by (simp add: simple_path_def path_translation_eq)
    5.82 @@ -363,7 +312,7 @@
    5.83  lemma bounded_path_image: "path g \<Longrightarrow> bounded(path_image g)"
    5.84    by (simp add: compact_imp_bounded compact_path_image)
    5.85  
    5.86 -lemma closed_path_image: 
    5.87 +lemma closed_path_image:
    5.88    fixes g :: "real \<Rightarrow> 'a::t2_space"
    5.89    shows "path g \<Longrightarrow> closed(path_image g)"
    5.90    by (metis compact_path_image compact_imp_closed)
    5.91 @@ -528,8 +477,8 @@
    5.92  lemmas join_paths_simps = path_join path_image_join pathstart_join pathfinish_join
    5.93  
    5.94  lemma simple_path_join_loop:
    5.95 -  assumes "arc g1" "arc g2" 
    5.96 -          "pathfinish g1 = pathstart g2"  "pathfinish g2 = pathstart g1" 
    5.97 +  assumes "arc g1" "arc g2"
    5.98 +          "pathfinish g1 = pathstart g2"  "pathfinish g2 = pathstart g1"
    5.99            "path_image g1 \<inter> path_image g2 \<subseteq> {pathstart g1, pathstart g2}"
   5.100    shows "simple_path(g1 +++ g2)"
   5.101  proof -
   5.102 @@ -539,13 +488,13 @@
   5.103    have injg2: "inj_on g2 {0..1}"
   5.104      using assms
   5.105      by (simp add: arc_def)
   5.106 -  have g12: "g1 1 = g2 0" 
   5.107 -   and g21: "g2 1 = g1 0" 
   5.108 +  have g12: "g1 1 = g2 0"
   5.109 +   and g21: "g2 1 = g1 0"
   5.110     and sb:  "g1 ` {0..1} \<inter> g2 ` {0..1} \<subseteq> {g1 0, g2 0}"
   5.111      using assms
   5.112      by (simp_all add: arc_def pathfinish_def pathstart_def path_image_def)
   5.113    { fix x and y::real
   5.114 -    assume xyI: "x = 1 \<longrightarrow> y \<noteq> 0" 
   5.115 +    assume xyI: "x = 1 \<longrightarrow> y \<noteq> 0"
   5.116         and xy: "x \<le> 1" "0 \<le> y" " y * 2 \<le> 1" "\<not> x * 2 \<le> 1" "g2 (2 * x - 1) = g1 (2 * y)"
   5.117      have g1im: "g1 (2 * y) \<in> g1 ` {0..1} \<inter> g2 ` {0..1}"
   5.118        using xy
   5.119 @@ -553,7 +502,7 @@
   5.120        apply (rule_tac x="2 * x - 1" in image_eqI, auto)
   5.121        done
   5.122      have False
   5.123 -      using subsetD [OF sb g1im] xy 
   5.124 +      using subsetD [OF sb g1im] xy
   5.125        apply auto
   5.126        apply (drule inj_onD [OF injg1])
   5.127        using g21 [symmetric] xyI
   5.128 @@ -568,7 +517,7 @@
   5.129        apply (rule_tac x="2 * x" in image_eqI, auto)
   5.130        done
   5.131      have "x = 0 \<and> y = 1"
   5.132 -      using subsetD [OF sb g1im] xy 
   5.133 +      using subsetD [OF sb g1im] xy
   5.134        apply auto
   5.135        apply (force dest: inj_onD [OF injg1])
   5.136        using  g21 [symmetric]
   5.137 @@ -587,7 +536,7 @@
   5.138  qed
   5.139  
   5.140  lemma arc_join:
   5.141 -  assumes "arc g1" "arc g2" 
   5.142 +  assumes "arc g1" "arc g2"
   5.143            "pathfinish g1 = pathstart g2"
   5.144            "path_image g1 \<inter> path_image g2 \<subseteq> {pathstart g2}"
   5.145      shows "arc(g1 +++ g2)"
   5.146 @@ -603,14 +552,14 @@
   5.147      using assms
   5.148      by (simp_all add: arc_def pathfinish_def pathstart_def path_image_def)
   5.149    { fix x and y::real
   5.150 -    assume xy: "x \<le> 1" "0 \<le> y" " y * 2 \<le> 1" "\<not> x * 2 \<le> 1" "g2 (2 * x - 1) = g1 (2 * y)"       
   5.151 +    assume xy: "x \<le> 1" "0 \<le> y" " y * 2 \<le> 1" "\<not> x * 2 \<le> 1" "g2 (2 * x - 1) = g1 (2 * y)"
   5.152      have g1im: "g1 (2 * y) \<in> g1 ` {0..1} \<inter> g2 ` {0..1}"
   5.153        using xy
   5.154        apply simp
   5.155        apply (rule_tac x="2 * x - 1" in image_eqI, auto)
   5.156        done
   5.157      have False
   5.158 -      using subsetD [OF sb g1im] xy 
   5.159 +      using subsetD [OF sb g1im] xy
   5.160        by (auto dest: inj_onD [OF injg2])
   5.161     } note * = this
   5.162    show ?thesis
   5.163 @@ -631,11 +580,11 @@
   5.164  
   5.165  
   5.166  subsection\<open>Choosing a subpath of an existing path\<close>
   5.167 -    
   5.168 +
   5.169  definition subpath :: "real \<Rightarrow> real \<Rightarrow> (real \<Rightarrow> 'a) \<Rightarrow> real \<Rightarrow> 'a::real_normed_vector"
   5.170    where "subpath a b g \<equiv> \<lambda>x. g((b - a) * x + a)"
   5.171  
   5.172 -lemma path_image_subpath_gen [simp]: 
   5.173 +lemma path_image_subpath_gen [simp]:
   5.174    fixes g :: "real \<Rightarrow> 'a::real_normed_vector"
   5.175    shows "path_image(subpath u v g) = g ` (closed_segment u v)"
   5.176    apply (simp add: closed_segment_real_eq path_image_def subpath_def)
   5.177 @@ -684,8 +633,8 @@
   5.178  lemma subpath_linear_image: "linear f \<Longrightarrow> subpath u v (f o g) = f o subpath u v g"
   5.179    by (rule ext) (simp add: subpath_def)
   5.180  
   5.181 -lemma affine_ineq: 
   5.182 -  fixes x :: "'a::linordered_idom" 
   5.183 +lemma affine_ineq:
   5.184 +  fixes x :: "'a::linordered_idom"
   5.185    assumes "x \<le> 1" "v < u"
   5.186      shows "v + x * u \<le> u + x * v"
   5.187  proof -
   5.188 @@ -695,7 +644,7 @@
   5.189      by (simp add: algebra_simps)
   5.190  qed
   5.191  
   5.192 -lemma simple_path_subpath_eq: 
   5.193 +lemma simple_path_subpath_eq:
   5.194    "simple_path(subpath u v g) \<longleftrightarrow>
   5.195       path(subpath u v g) \<and> u\<noteq>v \<and>
   5.196       (\<forall>x y. x \<in> closed_segment u v \<and> y \<in> closed_segment u v \<and> g x = g y
   5.197 @@ -704,14 +653,14 @@
   5.198  proof (rule iffI)
   5.199    assume ?lhs
   5.200    then have p: "path (\<lambda>x. g ((v - u) * x + u))"
   5.201 -        and sim: "(\<And>x y. \<lbrakk>x\<in>{0..1}; y\<in>{0..1}; g ((v - u) * x + u) = g ((v - u) * y + u)\<rbrakk> 
   5.202 +        and sim: "(\<And>x y. \<lbrakk>x\<in>{0..1}; y\<in>{0..1}; g ((v - u) * x + u) = g ((v - u) * y + u)\<rbrakk>
   5.203                    \<Longrightarrow> x = y \<or> x = 0 \<and> y = 1 \<or> x = 1 \<and> y = 0)"
   5.204      by (auto simp: simple_path_def subpath_def)
   5.205    { fix x y
   5.206      assume "x \<in> closed_segment u v" "y \<in> closed_segment u v" "g x = g y"
   5.207      then have "x = y \<or> x = u \<and> y = v \<or> x = v \<and> y = u"
   5.208      using sim [of "(x-u)/(v-u)" "(y-u)/(v-u)"] p
   5.209 -    by (auto simp: closed_segment_real_eq image_affinity_atLeastAtMost divide_simps 
   5.210 +    by (auto simp: closed_segment_real_eq image_affinity_atLeastAtMost divide_simps
   5.211         split: split_if_asm)
   5.212    } moreover
   5.213    have "path(subpath u v g) \<and> u\<noteq>v"
   5.214 @@ -721,7 +670,7 @@
   5.215      by metis
   5.216  next
   5.217    assume ?rhs
   5.218 -  then 
   5.219 +  then
   5.220    have d1: "\<And>x y. \<lbrakk>g x = g y; u \<le> x; x \<le> v; u \<le> y; y \<le> v\<rbrakk> \<Longrightarrow> x = y \<or> x = u \<and> y = v \<or> x = v \<and> y = u"
   5.221     and d2: "\<And>x y. \<lbrakk>g x = g y; v \<le> x; x \<le> u; v \<le> y; y \<le> u\<rbrakk> \<Longrightarrow> x = y \<or> x = u \<and> y = v \<or> x = v \<and> y = u"
   5.222     and ne: "u < v \<or> v < u"
   5.223 @@ -734,31 +683,31 @@
   5.224      by (fastforce simp add: algebra_simps affine_ineq mult_left_mono crossproduct_eq dest: d1 d2)
   5.225  qed
   5.226  
   5.227 -lemma arc_subpath_eq: 
   5.228 +lemma arc_subpath_eq:
   5.229    "arc(subpath u v g) \<longleftrightarrow> path(subpath u v g) \<and> u\<noteq>v \<and> inj_on g (closed_segment u v)"
   5.230      (is "?lhs = ?rhs")
   5.231  proof (rule iffI)
   5.232    assume ?lhs
   5.233    then have p: "path (\<lambda>x. g ((v - u) * x + u))"
   5.234 -        and sim: "(\<And>x y. \<lbrakk>x\<in>{0..1}; y\<in>{0..1}; g ((v - u) * x + u) = g ((v - u) * y + u)\<rbrakk> 
   5.235 +        and sim: "(\<And>x y. \<lbrakk>x\<in>{0..1}; y\<in>{0..1}; g ((v - u) * x + u) = g ((v - u) * y + u)\<rbrakk>
   5.236                    \<Longrightarrow> x = y)"
   5.237      by (auto simp: arc_def inj_on_def subpath_def)
   5.238    { fix x y
   5.239      assume "x \<in> closed_segment u v" "y \<in> closed_segment u v" "g x = g y"
   5.240      then have "x = y"
   5.241      using sim [of "(x-u)/(v-u)" "(y-u)/(v-u)"] p
   5.242 -    by (force simp add: inj_on_def closed_segment_real_eq image_affinity_atLeastAtMost divide_simps 
   5.243 +    by (force simp add: inj_on_def closed_segment_real_eq image_affinity_atLeastAtMost divide_simps
   5.244         split: split_if_asm)
   5.245    } moreover
   5.246    have "path(subpath u v g) \<and> u\<noteq>v"
   5.247      using sim [of "1/3" "2/3"] p
   5.248      by (auto simp: subpath_def)
   5.249    ultimately show ?rhs
   5.250 -    unfolding inj_on_def   
   5.251 +    unfolding inj_on_def
   5.252      by metis
   5.253  next
   5.254    assume ?rhs
   5.255 -  then 
   5.256 +  then
   5.257    have d1: "\<And>x y. \<lbrakk>g x = g y; u \<le> x; x \<le> v; u \<le> y; y \<le> v\<rbrakk> \<Longrightarrow> x = y"
   5.258     and d2: "\<And>x y. \<lbrakk>g x = g y; v \<le> x; x \<le> u; v \<le> y; y \<le> u\<rbrakk> \<Longrightarrow> x = y"
   5.259     and ne: "u < v \<or> v < u"
   5.260 @@ -770,7 +719,7 @@
   5.261  qed
   5.262  
   5.263  
   5.264 -lemma simple_path_subpath: 
   5.265 +lemma simple_path_subpath:
   5.266    assumes "simple_path g" "u \<in> {0..1}" "v \<in> {0..1}" "u \<noteq> v"
   5.267    shows "simple_path(subpath u v g)"
   5.268    using assms
   5.269 @@ -786,13 +735,13 @@
   5.270      "\<lbrakk>arc g; u \<in> {0..1}; v \<in> {0..1}; u \<noteq> v\<rbrakk> \<Longrightarrow> arc(subpath u v g)"
   5.271    by (meson arc_def arc_imp_simple_path arc_simple_path_subpath inj_onD)
   5.272  
   5.273 -lemma arc_simple_path_subpath_interior: 
   5.274 +lemma arc_simple_path_subpath_interior:
   5.275      "\<lbrakk>simple_path g; u \<in> {0..1}; v \<in> {0..1}; u \<noteq> v; \<bar>u-v\<bar> < 1\<rbrakk> \<Longrightarrow> arc(subpath u v g)"
   5.276      apply (rule arc_simple_path_subpath)
   5.277      apply (force simp: simple_path_def)+
   5.278      done
   5.279  
   5.280 -lemma path_image_subpath_subset: 
   5.281 +lemma path_image_subpath_subset:
   5.282      "\<lbrakk>path g; u \<in> {0..1}; v \<in> {0..1}\<rbrakk> \<Longrightarrow> path_image(subpath u v g) \<subseteq> path_image g"
   5.283    apply (simp add: closed_segment_real_eq image_affinity_atLeastAtMost)
   5.284    apply (auto simp: path_image_def)
   5.285 @@ -949,7 +898,7 @@
   5.286        by simp
   5.287    }
   5.288    then show ?thesis
   5.289 -    unfolding arc_def inj_on_def 
   5.290 +    unfolding arc_def inj_on_def
   5.291      by (simp add:  path_linepath) (force simp: algebra_simps linepath_def)
   5.292  qed
   5.293  
   5.294 @@ -1066,7 +1015,7 @@
   5.295    unfolding path_connected_def path_component_def by auto
   5.296  
   5.297  lemma path_connected_component_set: "path_connected s \<longleftrightarrow> (\<forall>x\<in>s. {y. path_component s x y} = s)"
   5.298 -  unfolding path_connected_component path_component_subset 
   5.299 +  unfolding path_connected_component path_component_subset
   5.300    apply auto
   5.301    using path_component_mem(2) by blast
   5.302  
     6.1 --- a/src/HOL/Probability/Projective_Limit.thy	Tue Jul 28 13:00:54 2015 +0200
     6.2 +++ b/src/HOL/Probability/Projective_Limit.thy	Tue Jul 28 16:16:13 2015 +0100
     6.3 @@ -350,9 +350,8 @@
     6.4            by (simp add: setsum_left_distrib)
     6.5          also have "\<dots> < ereal (1 * real ?a)" unfolding less_ereal.simps
     6.6          proof (rule mult_strict_right_mono)
     6.7 -          have "(\<Sum>i\<in>{1..n}. 2 powr - real i) = (\<Sum>i\<in>{1..<Suc n}. (1/2) ^ i)"
     6.8 -            by (rule setsum.cong)
     6.9 -               (auto simp: powr_realpow[symmetric] powr_minus powr_divide inverse_eq_divide)
    6.10 +          have "(\<Sum>i = 1..n. 2 powr - real i) = (\<Sum>i = 1..<Suc n. (1/2) ^ i)"
    6.11 +            by (rule setsum.cong) (auto simp: powr_realpow powr_divide powr_minus_divide)  
    6.12            also have "{1..<Suc n} = {..<Suc n} - {0}" by auto
    6.13            also have "setsum (op ^ (1 / 2::real)) ({..<Suc n} - {0}) =
    6.14              setsum (op ^ (1 / 2)) ({..<Suc n}) - 1" by (auto simp: setsum_diff1)
     7.1 --- a/src/HOL/Probability/Regularity.thy	Tue Jul 28 13:00:54 2015 +0200
     7.2 +++ b/src/HOL/Probability/Regularity.thy	Tue Jul 28 16:16:13 2015 +0100
     7.3 @@ -192,7 +192,7 @@
     7.4      also have "\<dots> \<le> (\<Sum>n. ereal (e*2 powr - real (Suc n)))"
     7.5        using B_compl_le by (intro suminf_le_pos) (simp_all add: measure_nonneg emeasure_eq_measure)
     7.6      also have "\<dots> \<le> (\<Sum>n. ereal (e * (1 / 2) ^ Suc n))"
     7.7 -      by (simp add: powr_minus inverse_eq_divide powr_realpow field_simps power_divide)
     7.8 +      by (simp add: Transcendental.powr_minus powr_realpow field_simps)
     7.9      also have "\<dots> = (\<Sum>n. ereal e * ((1 / 2) ^ Suc n))"
    7.10        unfolding times_ereal.simps[symmetric] ereal_power[symmetric] one_ereal_def numeral_eq_ereal
    7.11        by simp
     8.1 --- a/src/HOL/ROOT	Tue Jul 28 13:00:54 2015 +0200
     8.2 +++ b/src/HOL/ROOT	Tue Jul 28 16:16:13 2015 +0100
     8.3 @@ -703,6 +703,7 @@
     8.4      PolyRoots
     8.5      Complex_Analysis_Basics
     8.6      Complex_Transcendental
     8.7 +    Cauchy_Integral_Thm
     8.8    document_files
     8.9      "root.tex"
    8.10  
     9.1 --- a/src/HOL/Set_Interval.thy	Tue Jul 28 13:00:54 2015 +0200
     9.2 +++ b/src/HOL/Set_Interval.thy	Tue Jul 28 16:16:13 2015 +0100
     9.3 @@ -809,7 +809,7 @@
     9.4  
     9.5  subsubsection \<open>Image\<close>
     9.6  
     9.7 -lemma image_add_atLeastAtMost:
     9.8 +lemma image_add_atLeastAtMost [simp]:
     9.9    fixes k ::"'a::linordered_semidom"
    9.10    shows "(\<lambda>n. n+k) ` {i..j} = {i+k..j+k}" (is "?A = ?B")
    9.11  proof
    9.12 @@ -833,6 +833,44 @@
    9.13    qed
    9.14  qed
    9.15  
    9.16 +lemma image_diff_atLeastAtMost [simp]:
    9.17 +  fixes d::"'a::linordered_idom" shows "(op - d ` {a..b}) = {d-b..d-a}"
    9.18 +  apply auto
    9.19 +  apply (rule_tac x="d-x" in rev_image_eqI, auto)
    9.20 +  done
    9.21 +
    9.22 +lemma image_mult_atLeastAtMost [simp]:
    9.23 +  fixes d::"'a::linordered_field"
    9.24 +  assumes "d>0" shows "(op * d ` {a..b}) = {d*a..d*b}"
    9.25 +  using assms
    9.26 +  by (auto simp: field_simps mult_le_cancel_right intro: rev_image_eqI [where x="x/d" for x])
    9.27 +
    9.28 +lemma image_affinity_atLeastAtMost:
    9.29 +  fixes c :: "'a::linordered_field"
    9.30 +  shows "((\<lambda>x. m*x + c) ` {a..b}) = (if {a..b}={} then {}
    9.31 +            else if 0 \<le> m then {m*a + c .. m *b + c}
    9.32 +            else {m*b + c .. m*a + c})"
    9.33 +  apply (case_tac "m=0", auto simp: mult_le_cancel_left)
    9.34 +  apply (rule_tac x="inverse m*(x-c)" in rev_image_eqI, auto simp: field_simps)
    9.35 +  apply (rule_tac x="inverse m*(x-c)" in rev_image_eqI, auto simp: field_simps)
    9.36 +  done
    9.37 +
    9.38 +lemma image_affinity_atLeastAtMost_diff:
    9.39 +  fixes c :: "'a::linordered_field"
    9.40 +  shows "((\<lambda>x. m*x - c) ` {a..b}) = (if {a..b}={} then {}
    9.41 +            else if 0 \<le> m then {m*a - c .. m*b - c}
    9.42 +            else {m*b - c .. m*a - c})"
    9.43 +  using image_affinity_atLeastAtMost [of m "-c" a b]
    9.44 +  by simp
    9.45 +
    9.46 +lemma image_affinity_atLeastAtMost_div_diff:
    9.47 +  fixes c :: "'a::linordered_field"
    9.48 +  shows "((\<lambda>x. x/m - c) ` {a..b}) = (if {a..b}={} then {}
    9.49 +            else if 0 \<le> m then {a/m - c .. b/m - c}
    9.50 +            else {b/m - c .. a/m - c})"
    9.51 +  using image_affinity_atLeastAtMost_diff [of "inverse m" c a b]
    9.52 +  by (simp add: field_class.field_divide_inverse algebra_simps)
    9.53 +
    9.54  lemma image_add_atLeastLessThan:
    9.55    "(%n::nat. n+k) ` {i..<j} = {i+k..<j+k}" (is "?A = ?B")
    9.56  proof