src/HOL/Analysis/Cauchy_Integral_Theorem.thy
author nipkow
Sat Dec 29 15:43:53 2018 +0100 (6 months ago)
changeset 69529 4ab9657b3257
parent 69517 dc20f278e8f3
child 69530 fc0da2166cda
permissions -rw-r--r--
capitalize proper names in lemma names
nipkow@69517
     1
section \<open>Complex Path Integrals and Cauchy's Integral Theorem\<close>
lp15@60809
     2
lp15@61711
     3
text\<open>By John Harrison et al.  Ported from HOL Light by L C Paulson (2015)\<close>
lp15@61711
     4
hoelzl@63594
     5
theory Cauchy_Integral_Theorem
hoelzl@63594
     6
imports Complex_Transcendental Weierstrass_Theorems Ordered_Euclidean_Space
lp15@60809
     7
begin
lp15@60809
     8
wl302@69423
     9
subsection%unimportant \<open>Homeomorphisms of arc images\<close>
lp15@62620
    10
lp15@62620
    11
lemma homeomorphism_arc:
lp15@62620
    12
  fixes g :: "real \<Rightarrow> 'a::t2_space"
lp15@62620
    13
  assumes "arc g"
lp15@62620
    14
  obtains h where "homeomorphism {0..1} (path_image g) g h"
lp15@68339
    15
using assms by (force simp: arc_def homeomorphism_compact path_def path_image_def)
lp15@62620
    16
lp15@62620
    17
lemma homeomorphic_arc_image_interval:
lp15@62620
    18
  fixes g :: "real \<Rightarrow> 'a::t2_space" and a::real
lp15@62620
    19
  assumes "arc g" "a < b"
lp15@62620
    20
  shows "(path_image g) homeomorphic {a..b}"
lp15@62620
    21
proof -
lp15@62620
    22
  have "(path_image g) homeomorphic {0..1::real}"
lp15@62620
    23
    by (meson assms(1) homeomorphic_def homeomorphic_sym homeomorphism_arc)
lp15@68339
    24
  also have "\<dots> homeomorphic {a..b}"
lp15@62620
    25
    using assms by (force intro: homeomorphic_closed_intervals_real)
lp15@62620
    26
  finally show ?thesis .
lp15@62620
    27
qed
lp15@62620
    28
lp15@62620
    29
lemma homeomorphic_arc_images:
lp15@62620
    30
  fixes g :: "real \<Rightarrow> 'a::t2_space" and h :: "real \<Rightarrow> 'b::t2_space"
lp15@62620
    31
  assumes "arc g" "arc h"
lp15@62620
    32
  shows "(path_image g) homeomorphic (path_image h)"
lp15@62620
    33
proof -
lp15@62620
    34
  have "(path_image g) homeomorphic {0..1::real}"
lp15@62620
    35
    by (meson assms homeomorphic_def homeomorphic_sym homeomorphism_arc)
lp15@68339
    36
  also have "\<dots> homeomorphic (path_image h)"
lp15@62620
    37
    by (meson assms homeomorphic_def homeomorphism_arc)
lp15@62620
    38
  finally show ?thesis .
lp15@62620
    39
qed
lp15@62620
    40
lp15@65037
    41
lemma path_connected_arc_complement:
lp15@65037
    42
  fixes \<gamma> :: "real \<Rightarrow> 'a::euclidean_space"
lp15@65037
    43
  assumes "arc \<gamma>" "2 \<le> DIM('a)"
lp15@65037
    44
  shows "path_connected(- path_image \<gamma>)"
lp15@65037
    45
proof -
lp15@65037
    46
  have "path_image \<gamma> homeomorphic {0..1::real}"
lp15@65037
    47
    by (simp add: assms homeomorphic_arc_image_interval)
lp15@65037
    48
  then
lp15@65037
    49
  show ?thesis
lp15@65037
    50
    apply (rule path_connected_complement_homeomorphic_convex_compact)
lp15@65037
    51
      apply (auto simp: assms)
lp15@65037
    52
    done
lp15@65037
    53
qed
lp15@65037
    54
lp15@65037
    55
lemma connected_arc_complement:
lp15@65037
    56
  fixes \<gamma> :: "real \<Rightarrow> 'a::euclidean_space"
lp15@65037
    57
  assumes "arc \<gamma>" "2 \<le> DIM('a)"
lp15@65037
    58
  shows "connected(- path_image \<gamma>)"
lp15@65037
    59
  by (simp add: assms path_connected_arc_complement path_connected_imp_connected)
lp15@65037
    60
lp15@65037
    61
lemma inside_arc_empty:
lp15@65037
    62
  fixes \<gamma> :: "real \<Rightarrow> 'a::euclidean_space"
lp15@65037
    63
  assumes "arc \<gamma>"
lp15@65037
    64
    shows "inside(path_image \<gamma>) = {}"
lp15@65037
    65
proof (cases "DIM('a) = 1")
lp15@65037
    66
  case True
lp15@65037
    67
  then show ?thesis
lp15@65037
    68
    using assms connected_arc_image connected_convex_1_gen inside_convex by blast
lp15@65037
    69
next
lp15@65037
    70
  case False
lp15@65037
    71
  show ?thesis
lp15@65037
    72
  proof (rule inside_bounded_complement_connected_empty)
lp15@65037
    73
    show "connected (- path_image \<gamma>)"
lp15@65037
    74
      apply (rule connected_arc_complement [OF assms])
lp15@65037
    75
      using False
lp15@65037
    76
      by (metis DIM_ge_Suc0 One_nat_def Suc_1 not_less_eq_eq order_class.order.antisym)
lp15@65037
    77
    show "bounded (path_image \<gamma>)"
lp15@65037
    78
      by (simp add: assms bounded_arc_image)
lp15@65037
    79
  qed
lp15@65037
    80
qed
lp15@65037
    81
lp15@65037
    82
lemma inside_simple_curve_imp_closed:
lp15@65037
    83
  fixes \<gamma> :: "real \<Rightarrow> 'a::euclidean_space"
lp15@65037
    84
    shows "\<lbrakk>simple_path \<gamma>; x \<in> inside(path_image \<gamma>)\<rbrakk> \<Longrightarrow> pathfinish \<gamma> = pathstart \<gamma>"
lp15@65037
    85
  using arc_simple_path  inside_arc_empty by blast
lp15@65037
    86
lp15@68493
    87
wl302@69423
    88
subsection%unimportant \<open>Piecewise differentiable functions\<close>
lp15@60809
    89
lp15@60809
    90
definition piecewise_differentiable_on
lp15@60809
    91
           (infixr "piecewise'_differentiable'_on" 50)
lp15@60809
    92
  where "f piecewise_differentiable_on i  \<equiv>
lp15@60809
    93
           continuous_on i f \<and>
lp15@68284
    94
           (\<exists>S. finite S \<and> (\<forall>x \<in> i - S. f differentiable (at x within i)))"
lp15@60809
    95
lp15@60809
    96
lemma piecewise_differentiable_on_imp_continuous_on:
lp15@68284
    97
    "f piecewise_differentiable_on S \<Longrightarrow> continuous_on S f"
lp15@60809
    98
by (simp add: piecewise_differentiable_on_def)
lp15@60809
    99
lp15@60809
   100
lemma piecewise_differentiable_on_subset:
lp15@68284
   101
    "f piecewise_differentiable_on S \<Longrightarrow> T \<le> S \<Longrightarrow> f piecewise_differentiable_on T"
lp15@60809
   102
  using continuous_on_subset
lp15@61190
   103
  unfolding piecewise_differentiable_on_def
lp15@61190
   104
  apply safe
lp15@68339
   105
  apply (blast elim: continuous_on_subset)
lp15@61190
   106
  by (meson Diff_iff differentiable_within_subset subsetCE)
lp15@60809
   107
lp15@60809
   108
lemma differentiable_on_imp_piecewise_differentiable:
lp15@60809
   109
  fixes a:: "'a::{linorder_topology,real_normed_vector}"
lp15@60809
   110
  shows "f differentiable_on {a..b} \<Longrightarrow> f piecewise_differentiable_on {a..b}"
lp15@60809
   111
  apply (simp add: piecewise_differentiable_on_def differentiable_imp_continuous_on)
lp15@61190
   112
  apply (rule_tac x="{a,b}" in exI, simp add: differentiable_on_def)
lp15@61190
   113
  done
lp15@60809
   114
lp15@60809
   115
lemma differentiable_imp_piecewise_differentiable:
lp15@68284
   116
    "(\<And>x. x \<in> S \<Longrightarrow> f differentiable (at x within S))
lp15@68284
   117
         \<Longrightarrow> f piecewise_differentiable_on S"
lp15@61190
   118
by (auto simp: piecewise_differentiable_on_def differentiable_imp_continuous_on differentiable_on_def
lp15@61190
   119
         intro: differentiable_within_subset)
lp15@60809
   120
lp15@68284
   121
lemma piecewise_differentiable_const [iff]: "(\<lambda>x. z) piecewise_differentiable_on S"
paulson@61204
   122
  by (simp add: differentiable_imp_piecewise_differentiable)
paulson@61204
   123
lp15@60809
   124
lemma piecewise_differentiable_compose:
lp15@68284
   125
    "\<lbrakk>f piecewise_differentiable_on S; g piecewise_differentiable_on (f ` S);
lp15@68284
   126
      \<And>x. finite (S \<inter> f-`{x})\<rbrakk>
lp15@68339
   127
      \<Longrightarrow> (g \<circ> f) piecewise_differentiable_on S"
lp15@60809
   128
  apply (simp add: piecewise_differentiable_on_def, safe)
lp15@60809
   129
  apply (blast intro: continuous_on_compose2)
lp15@60809
   130
  apply (rename_tac A B)
lp15@68284
   131
  apply (rule_tac x="A \<union> (\<Union>x\<in>B. S \<inter> f-`{x})" in exI)
lp15@65036
   132
  apply (blast intro!: differentiable_chain_within)
lp15@61190
   133
  done
lp15@60809
   134
lp15@60809
   135
lemma piecewise_differentiable_affine:
lp15@60809
   136
  fixes m::real
lp15@68284
   137
  assumes "f piecewise_differentiable_on ((\<lambda>x. m *\<^sub>R x + c) ` S)"
lp15@68339
   138
  shows "(f \<circ> (\<lambda>x. m *\<^sub>R x + c)) piecewise_differentiable_on S"
lp15@60809
   139
proof (cases "m = 0")
lp15@60809
   140
  case True
lp15@60809
   141
  then show ?thesis
lp15@60809
   142
    unfolding o_def
lp15@60809
   143
    by (force intro: differentiable_imp_piecewise_differentiable differentiable_const)
lp15@60809
   144
next
lp15@60809
   145
  case False
lp15@60809
   146
  show ?thesis
lp15@60809
   147
    apply (rule piecewise_differentiable_compose [OF differentiable_imp_piecewise_differentiable])
lp15@60809
   148
    apply (rule assms derivative_intros | simp add: False vimage_def real_vector_affinity_eq)+
lp15@60809
   149
    done
lp15@60809
   150
qed
lp15@60809
   151
lp15@60809
   152
lemma piecewise_differentiable_cases:
lp15@60809
   153
  fixes c::real
lp15@60809
   154
  assumes "f piecewise_differentiable_on {a..c}"
lp15@60809
   155
          "g piecewise_differentiable_on {c..b}"
lp15@60809
   156
           "a \<le> c" "c \<le> b" "f c = g c"
lp15@60809
   157
  shows "(\<lambda>x. if x \<le> c then f x else g x) piecewise_differentiable_on {a..b}"
lp15@60809
   158
proof -
lp15@68284
   159
  obtain S T where st: "finite S" "finite T"
lp15@68284
   160
               and fd: "\<And>x. x \<in> {a..c} - S \<Longrightarrow> f differentiable at x within {a..c}"
lp15@68284
   161
               and gd: "\<And>x. x \<in> {c..b} - T \<Longrightarrow> g differentiable at x within {c..b}"
lp15@60809
   162
    using assms
lp15@60809
   163
    by (auto simp: piecewise_differentiable_on_def)
lp15@68284
   164
  have finabc: "finite ({a,b,c} \<union> (S \<union> T))"
lp15@68284
   165
    by (metis \<open>finite S\<close> \<open>finite T\<close> finite_Un finite_insert finite.emptyI)
lp15@60809
   166
  have "continuous_on {a..c} f" "continuous_on {c..b} g"
lp15@60809
   167
    using assms piecewise_differentiable_on_def by auto
lp15@60809
   168
  then have "continuous_on {a..b} (\<lambda>x. if x \<le> c then f x else g x)"
lp15@60809
   169
    using continuous_on_cases [OF closed_real_atLeastAtMost [of a c],
lp15@60809
   170
                               OF closed_real_atLeastAtMost [of c b],
lp15@60809
   171
                               of f g "\<lambda>x. x\<le>c"]  assms
lp15@60809
   172
    by (force simp: ivl_disj_un_two_touch)
lp15@60809
   173
  moreover
lp15@60809
   174
  { fix x
lp15@68284
   175
    assume x: "x \<in> {a..b} - ({a,b,c} \<union> (S \<union> T))"
lp15@61190
   176
    have "(\<lambda>x. if x \<le> c then f x else g x) differentiable at x within {a..b}" (is "?diff_fg")
lp15@60809
   177
    proof (cases x c rule: le_cases)
lp15@60809
   178
      case le show ?diff_fg
lp15@68284
   179
      proof (rule differentiable_transform_within [where d = "dist x c"])
lp15@68284
   180
        have "f differentiable at x"
lp15@68284
   181
          using x le fd [of x] at_within_interior [of x "{a..c}"] by simp
lp15@68284
   182
        then show "f differentiable at x within {a..b}"
lp15@68284
   183
          by (simp add: differentiable_at_withinI)
lp15@63955
   184
      qed (use x le st dist_real_def in auto)
lp15@60809
   185
    next
lp15@60809
   186
      case ge show ?diff_fg
lp15@68284
   187
      proof (rule differentiable_transform_within [where d = "dist x c"])
lp15@68284
   188
        have "g differentiable at x"
lp15@68284
   189
          using x ge gd [of x] at_within_interior [of x "{c..b}"] by simp
lp15@68284
   190
        then show "g differentiable at x within {a..b}"
lp15@68284
   191
          by (simp add: differentiable_at_withinI)
lp15@63955
   192
      qed (use x ge st dist_real_def in auto)
lp15@60809
   193
    qed
lp15@60809
   194
  }
lp15@68284
   195
  then have "\<exists>S. finite S \<and>
lp15@68284
   196
                 (\<forall>x\<in>{a..b} - S. (\<lambda>x. if x \<le> c then f x else g x) differentiable at x within {a..b})"
lp15@61190
   197
    by (meson finabc)
lp15@60809
   198
  ultimately show ?thesis
lp15@60809
   199
    by (simp add: piecewise_differentiable_on_def)
lp15@60809
   200
qed
lp15@60809
   201
lp15@60809
   202
lemma piecewise_differentiable_neg:
lp15@68284
   203
    "f piecewise_differentiable_on S \<Longrightarrow> (\<lambda>x. -(f x)) piecewise_differentiable_on S"
lp15@60809
   204
  by (auto simp: piecewise_differentiable_on_def continuous_on_minus)
lp15@60809
   205
lp15@60809
   206
lemma piecewise_differentiable_add:
lp15@60809
   207
  assumes "f piecewise_differentiable_on i"
lp15@60809
   208
          "g piecewise_differentiable_on i"
lp15@60809
   209
    shows "(\<lambda>x. f x + g x) piecewise_differentiable_on i"
lp15@60809
   210
proof -
lp15@68284
   211
  obtain S T where st: "finite S" "finite T"
lp15@68284
   212
                       "\<forall>x\<in>i - S. f differentiable at x within i"
lp15@68284
   213
                       "\<forall>x\<in>i - T. g differentiable at x within i"
lp15@60809
   214
    using assms by (auto simp: piecewise_differentiable_on_def)
lp15@68284
   215
  then have "finite (S \<union> T) \<and> (\<forall>x\<in>i - (S \<union> T). (\<lambda>x. f x + g x) differentiable at x within i)"
lp15@60809
   216
    by auto
lp15@60809
   217
  moreover have "continuous_on i f" "continuous_on i g"
lp15@60809
   218
    using assms piecewise_differentiable_on_def by auto
lp15@60809
   219
  ultimately show ?thesis
lp15@60809
   220
    by (auto simp: piecewise_differentiable_on_def continuous_on_add)
lp15@60809
   221
qed
lp15@60809
   222
lp15@60809
   223
lemma piecewise_differentiable_diff:
lp15@68284
   224
    "\<lbrakk>f piecewise_differentiable_on S;  g piecewise_differentiable_on S\<rbrakk>
lp15@68284
   225
     \<Longrightarrow> (\<lambda>x. f x - g x) piecewise_differentiable_on S"
lp15@60809
   226
  unfolding diff_conv_add_uminus
lp15@60809
   227
  by (metis piecewise_differentiable_add piecewise_differentiable_neg)
lp15@60809
   228
lp15@61190
   229
lemma continuous_on_joinpaths_D1:
lp15@61190
   230
    "continuous_on {0..1} (g1 +++ g2) \<Longrightarrow> continuous_on {0..1} g1"
nipkow@69064
   231
  apply (rule continuous_on_eq [of _ "(g1 +++ g2) \<circ> ((*)(inverse 2))"])
lp15@61190
   232
  apply (rule continuous_intros | simp)+
lp15@61190
   233
  apply (auto elim!: continuous_on_subset simp: joinpaths_def)
lp15@61190
   234
  done
lp15@61190
   235
lp15@61190
   236
lemma continuous_on_joinpaths_D2:
lp15@61190
   237
    "\<lbrakk>continuous_on {0..1} (g1 +++ g2); pathfinish g1 = pathstart g2\<rbrakk> \<Longrightarrow> continuous_on {0..1} g2"
lp15@68339
   238
  apply (rule continuous_on_eq [of _ "(g1 +++ g2) \<circ> (\<lambda>x. inverse 2*x + 1/2)"])
lp15@61190
   239
  apply (rule continuous_intros | simp)+
lp15@61190
   240
  apply (auto elim!: continuous_on_subset simp add: joinpaths_def pathfinish_def pathstart_def Ball_def)
lp15@61190
   241
  done
lp15@61190
   242
lp15@61190
   243
lemma piecewise_differentiable_D1:
lp15@68284
   244
  assumes "(g1 +++ g2) piecewise_differentiable_on {0..1}"
lp15@68284
   245
  shows "g1 piecewise_differentiable_on {0..1}"
lp15@68284
   246
proof -
lp15@68284
   247
  obtain S where cont: "continuous_on {0..1} g1" and "finite S"
lp15@68284
   248
    and S: "\<And>x. x \<in> {0..1} - S \<Longrightarrow> g1 +++ g2 differentiable at x within {0..1}"
lp15@68284
   249
    using assms unfolding piecewise_differentiable_on_def
lp15@68284
   250
    by (blast dest!: continuous_on_joinpaths_D1)
lp15@68284
   251
  show ?thesis
lp15@68284
   252
    unfolding piecewise_differentiable_on_def
lp15@68284
   253
  proof (intro exI conjI ballI cont)
nipkow@69064
   254
    show "finite (insert 1 (((*)2) ` S))"
lp15@68284
   255
      by (simp add: \<open>finite S\<close>)
nipkow@69064
   256
    show "g1 differentiable at x within {0..1}" if "x \<in> {0..1} - insert 1 ((*) 2 ` S)" for x
lp15@68284
   257
    proof (rule_tac d="dist (x/2) (1/2)" in differentiable_transform_within)
lp15@68296
   258
      have "g1 +++ g2 differentiable at (x / 2) within {0..1/2}"
lp15@68284
   259
        by (rule differentiable_subset [OF S [of "x/2"]] | use that in force)+
nipkow@69064
   260
      then show "g1 +++ g2 \<circ> (*) (inverse 2) differentiable at x within {0..1}"
lp15@68284
   261
        by (auto intro: differentiable_chain_within)
lp15@68284
   262
    qed (use that in \<open>auto simp: joinpaths_def\<close>)
lp15@68284
   263
  qed
lp15@68284
   264
qed
lp15@61190
   265
lp15@61190
   266
lemma piecewise_differentiable_D2:
lp15@68284
   267
  assumes "(g1 +++ g2) piecewise_differentiable_on {0..1}" and eq: "pathfinish g1 = pathstart g2"
lp15@68284
   268
  shows "g2 piecewise_differentiable_on {0..1}"
lp15@68284
   269
proof -
lp15@68284
   270
  have [simp]: "g1 1 = g2 0"
lp15@68284
   271
    using eq by (simp add: pathfinish_def pathstart_def)
lp15@68284
   272
  obtain S where cont: "continuous_on {0..1} g2" and "finite S"
lp15@68284
   273
    and S: "\<And>x. x \<in> {0..1} - S \<Longrightarrow> g1 +++ g2 differentiable at x within {0..1}"
lp15@68284
   274
    using assms unfolding piecewise_differentiable_on_def
lp15@68284
   275
    by (blast dest!: continuous_on_joinpaths_D2)
lp15@68284
   276
  show ?thesis
lp15@68284
   277
    unfolding piecewise_differentiable_on_def
lp15@68284
   278
  proof (intro exI conjI ballI cont)
lp15@68284
   279
    show "finite (insert 0 ((\<lambda>x. 2*x-1)`S))"
lp15@68284
   280
      by (simp add: \<open>finite S\<close>)
lp15@68284
   281
    show "g2 differentiable at x within {0..1}" if "x \<in> {0..1} - insert 0 ((\<lambda>x. 2*x-1)`S)" for x
lp15@68284
   282
    proof (rule_tac d="dist ((x+1)/2) (1/2)" in differentiable_transform_within)
lp15@68284
   283
      have x2: "(x + 1) / 2 \<notin> S"
lp15@68284
   284
        using that
lp15@68284
   285
        apply (clarsimp simp: image_iff)
lp15@68527
   286
        by (metis add.commute add_diff_cancel_left' mult_2 field_sum_of_halves)
lp15@68284
   287
      have "g1 +++ g2 \<circ> (\<lambda>x. (x+1) / 2) differentiable at x within {0..1}"
lp15@68284
   288
        by (rule differentiable_chain_within differentiable_subset [OF S [of "(x+1)/2"]] | use x2 that in force)+
lp15@68284
   289
      then show "g1 +++ g2 \<circ> (\<lambda>x. (x+1) / 2) differentiable at x within {0..1}"
lp15@68284
   290
        by (auto intro: differentiable_chain_within)
lp15@68296
   291
      show "(g1 +++ g2 \<circ> (\<lambda>x. (x + 1) / 2)) x' = g2 x'" if "x' \<in> {0..1}" "dist x' x < dist ((x + 1) / 2) (1/2)" for x'
lp15@68284
   292
      proof -
lp15@68284
   293
        have [simp]: "(2*x'+2)/2 = x'+1"
lp15@68284
   294
          by (simp add: divide_simps)
lp15@68284
   295
        show ?thesis
lp15@68284
   296
          using that by (auto simp: joinpaths_def)
lp15@68284
   297
      qed
lp15@68284
   298
    qed (use that in \<open>auto simp: joinpaths_def\<close>)
lp15@68284
   299
  qed
lp15@68284
   300
qed
lp15@61190
   301
lp15@61190
   302
wl302@69423
   303
subsection\<open>The concept of continuously differentiable\<close>
lp15@61190
   304
lp15@62408
   305
text \<open>
lp15@62408
   306
John Harrison writes as follows:
lp15@62408
   307
wenzelm@62456
   308
``The usual assumption in complex analysis texts is that a path \<open>\<gamma>\<close> should be piecewise
lp15@62408
   309
continuously differentiable, which ensures that the path integral exists at least for any continuous
lp15@62408
   310
f, since all piecewise continuous functions are integrable. However, our notion of validity is
lp15@68341
   311
weaker, just piecewise differentiability\ldots{} [namely] continuity plus differentiability except on a
lp15@68341
   312
finite set\ldots{} [Our] underlying theory of integration is the Kurzweil-Henstock theory. In contrast to
lp15@62408
   313
the Riemann or Lebesgue theory (but in common with a simple notion based on antiderivatives), this
lp15@62408
   314
can integrate all derivatives.''
lp15@62408
   315
lp15@62534
   316
"Formalizing basic complex analysis." From Insight to Proof: Festschrift in Honour of Andrzej Trybulec.
lp15@62408
   317
Studies in Logic, Grammar and Rhetoric 10.23 (2007): 151-165.
lp15@62408
   318
lp15@62408
   319
And indeed he does not assume that his derivatives are continuous, but the penalty is unreasonably
lp15@62408
   320
difficult proofs concerning winding numbers. We need a self-contained and straightforward theorem
lp15@62408
   321
asserting that all derivatives can be integrated before we can adopt Harrison's choice.\<close>
lp15@62408
   322
wl302@69423
   323
definition%important C1_differentiable_on :: "(real \<Rightarrow> 'a::real_normed_vector) \<Rightarrow> real set \<Rightarrow> bool"
lp15@61190
   324
           (infix "C1'_differentiable'_on" 50)
lp15@61190
   325
  where
lp15@68296
   326
  "f C1_differentiable_on S \<longleftrightarrow>
lp15@68296
   327
   (\<exists>D. (\<forall>x \<in> S. (f has_vector_derivative (D x)) (at x)) \<and> continuous_on S D)"
lp15@61190
   328
lp15@61190
   329
lemma C1_differentiable_on_eq:
lp15@68296
   330
    "f C1_differentiable_on S \<longleftrightarrow>
lp15@68296
   331
     (\<forall>x \<in> S. f differentiable at x) \<and> continuous_on S (\<lambda>x. vector_derivative f (at x))"
lp15@68296
   332
     (is "?lhs = ?rhs")
lp15@68296
   333
proof
lp15@68296
   334
  assume ?lhs
lp15@68296
   335
  then show ?rhs
lp15@68296
   336
    unfolding C1_differentiable_on_def
lp15@68296
   337
    by (metis (no_types, lifting) continuous_on_eq  differentiableI_vector vector_derivative_at)
lp15@68296
   338
next
lp15@68296
   339
  assume ?rhs
lp15@68296
   340
  then show ?lhs
lp15@68296
   341
    using C1_differentiable_on_def vector_derivative_works by fastforce
lp15@68296
   342
qed
lp15@61190
   343
lp15@61190
   344
lemma C1_differentiable_on_subset:
lp15@68296
   345
  "f C1_differentiable_on T \<Longrightarrow> S \<subseteq> T \<Longrightarrow> f C1_differentiable_on S"
lp15@61190
   346
  unfolding C1_differentiable_on_def  continuous_on_eq_continuous_within
lp15@61190
   347
  by (blast intro:  continuous_within_subset)
lp15@61190
   348
lp15@61190
   349
lemma C1_differentiable_compose:
lp15@68296
   350
  assumes fg: "f C1_differentiable_on S" "g C1_differentiable_on (f ` S)" and fin: "\<And>x. finite (S \<inter> f-`{x})"
lp15@68339
   351
  shows "(g \<circ> f) C1_differentiable_on S"
lp15@68296
   352
proof -
lp15@68296
   353
  have "\<And>x. x \<in> S \<Longrightarrow> g \<circ> f differentiable at x"
lp15@68296
   354
    by (meson C1_differentiable_on_eq assms differentiable_chain_at imageI)
lp15@68296
   355
  moreover have "continuous_on S (\<lambda>x. vector_derivative (g \<circ> f) (at x))"
lp15@68296
   356
  proof (rule continuous_on_eq [of _ "\<lambda>x. vector_derivative f (at x) *\<^sub>R vector_derivative g (at (f x))"])
lp15@68296
   357
    show "continuous_on S (\<lambda>x. vector_derivative f (at x) *\<^sub>R vector_derivative g (at (f x)))"
lp15@68296
   358
      using fg
lp15@68296
   359
      apply (clarsimp simp add: C1_differentiable_on_eq)
lp15@68296
   360
      apply (rule Limits.continuous_on_scaleR, assumption)
lp15@68296
   361
      by (metis (mono_tags, lifting) continuous_at_imp_continuous_on continuous_on_compose continuous_on_cong differentiable_imp_continuous_within o_def)
lp15@68296
   362
    show "\<And>x. x \<in> S \<Longrightarrow> vector_derivative f (at x) *\<^sub>R vector_derivative g (at (f x)) = vector_derivative (g \<circ> f) (at x)"
lp15@68296
   363
      by (metis (mono_tags, hide_lams) C1_differentiable_on_eq fg imageI vector_derivative_chain_at)
lp15@68296
   364
  qed
lp15@68296
   365
  ultimately show ?thesis
lp15@68296
   366
    by (simp add: C1_differentiable_on_eq)
lp15@68296
   367
qed
lp15@68296
   368
lp15@68296
   369
lemma C1_diff_imp_diff: "f C1_differentiable_on S \<Longrightarrow> f differentiable_on S"
lp15@61190
   370
  by (simp add: C1_differentiable_on_eq differentiable_at_imp_differentiable_on)
lp15@61190
   371
lp15@68296
   372
lemma C1_differentiable_on_ident [simp, derivative_intros]: "(\<lambda>x. x) C1_differentiable_on S"
lp15@61190
   373
  by (auto simp: C1_differentiable_on_eq continuous_on_const)
lp15@61190
   374
lp15@68296
   375
lemma C1_differentiable_on_const [simp, derivative_intros]: "(\<lambda>z. a) C1_differentiable_on S"
lp15@61190
   376
  by (auto simp: C1_differentiable_on_eq continuous_on_const)
lp15@61190
   377
lp15@61190
   378
lemma C1_differentiable_on_add [simp, derivative_intros]:
lp15@68296
   379
  "f C1_differentiable_on S \<Longrightarrow> g C1_differentiable_on S \<Longrightarrow> (\<lambda>x. f x + g x) C1_differentiable_on S"
lp15@61190
   380
  unfolding C1_differentiable_on_eq  by (auto intro: continuous_intros)
lp15@61190
   381
lp15@61190
   382
lemma C1_differentiable_on_minus [simp, derivative_intros]:
lp15@68296
   383
  "f C1_differentiable_on S \<Longrightarrow> (\<lambda>x. - f x) C1_differentiable_on S"
lp15@61190
   384
  unfolding C1_differentiable_on_eq  by (auto intro: continuous_intros)
lp15@61190
   385
lp15@61190
   386
lemma C1_differentiable_on_diff [simp, derivative_intros]:
lp15@68296
   387
  "f C1_differentiable_on S \<Longrightarrow> g C1_differentiable_on S \<Longrightarrow> (\<lambda>x. f x - g x) C1_differentiable_on S"
lp15@61190
   388
  unfolding C1_differentiable_on_eq  by (auto intro: continuous_intros)
lp15@61190
   389
lp15@61190
   390
lemma C1_differentiable_on_mult [simp, derivative_intros]:
lp15@61190
   391
  fixes f g :: "real \<Rightarrow> 'a :: real_normed_algebra"
lp15@68296
   392
  shows "f C1_differentiable_on S \<Longrightarrow> g C1_differentiable_on S \<Longrightarrow> (\<lambda>x. f x * g x) C1_differentiable_on S"
lp15@61190
   393
  unfolding C1_differentiable_on_eq
lp15@61190
   394
  by (auto simp: continuous_on_add continuous_on_mult continuous_at_imp_continuous_on differentiable_imp_continuous_within)
lp15@61190
   395
lp15@61190
   396
lemma C1_differentiable_on_scaleR [simp, derivative_intros]:
lp15@68296
   397
  "f C1_differentiable_on S \<Longrightarrow> g C1_differentiable_on S \<Longrightarrow> (\<lambda>x. f x *\<^sub>R g x) C1_differentiable_on S"
lp15@61190
   398
  unfolding C1_differentiable_on_eq
lp15@61190
   399
  by (rule continuous_intros | simp add: continuous_at_imp_continuous_on differentiable_imp_continuous_within)+
lp15@61190
   400
lp15@61190
   401
wl302@69423
   402
definition%important piecewise_C1_differentiable_on
lp15@61190
   403
           (infixr "piecewise'_C1'_differentiable'_on" 50)
lp15@61190
   404
  where "f piecewise_C1_differentiable_on i  \<equiv>
lp15@61190
   405
           continuous_on i f \<and>
lp15@68296
   406
           (\<exists>S. finite S \<and> (f C1_differentiable_on (i - S)))"
lp15@61190
   407
lp15@61190
   408
lemma C1_differentiable_imp_piecewise:
lp15@68296
   409
    "f C1_differentiable_on S \<Longrightarrow> f piecewise_C1_differentiable_on S"
lp15@61190
   410
  by (auto simp: piecewise_C1_differentiable_on_def C1_differentiable_on_eq continuous_at_imp_continuous_on differentiable_imp_continuous_within)
lp15@61190
   411
lp15@61190
   412
lemma piecewise_C1_imp_differentiable:
lp15@61190
   413
    "f piecewise_C1_differentiable_on i \<Longrightarrow> f piecewise_differentiable_on i"
lp15@61190
   414
  by (auto simp: piecewise_C1_differentiable_on_def piecewise_differentiable_on_def
lp15@61190
   415
           C1_differentiable_on_def differentiable_def has_vector_derivative_def
lp15@67979
   416
           intro: has_derivative_at_withinI)
lp15@61190
   417
lp15@61190
   418
lemma piecewise_C1_differentiable_compose:
lp15@68296
   419
  assumes fg: "f piecewise_C1_differentiable_on S" "g piecewise_C1_differentiable_on (f ` S)" and fin: "\<And>x. finite (S \<inter> f-`{x})"
lp15@68339
   420
  shows "(g \<circ> f) piecewise_C1_differentiable_on S"
lp15@68296
   421
proof -
lp15@68296
   422
  have "continuous_on S (\<lambda>x. g (f x))"
lp15@68296
   423
    by (metis continuous_on_compose2 fg order_refl piecewise_C1_differentiable_on_def)
lp15@68296
   424
  moreover have "\<exists>T. finite T \<and> g \<circ> f C1_differentiable_on S - T"
lp15@68296
   425
  proof -
lp15@68296
   426
    obtain F where "finite F" and F: "f C1_differentiable_on S - F" and f: "f piecewise_C1_differentiable_on S"
lp15@68296
   427
      using fg by (auto simp: piecewise_C1_differentiable_on_def)
lp15@68296
   428
    obtain G where "finite G" and G: "g C1_differentiable_on f ` S - G" and g: "g piecewise_C1_differentiable_on f ` S"
lp15@68296
   429
      using fg by (auto simp: piecewise_C1_differentiable_on_def)
lp15@68296
   430
    show ?thesis
lp15@68296
   431
    proof (intro exI conjI)
lp15@68296
   432
      show "finite (F \<union> (\<Union>x\<in>G. S \<inter> f-`{x}))"
lp15@68296
   433
        using fin by (auto simp only: Int_Union \<open>finite F\<close> \<open>finite G\<close> finite_UN finite_imageI)
lp15@68296
   434
      show "g \<circ> f C1_differentiable_on S - (F \<union> (\<Union>x\<in>G. S \<inter> f -` {x}))"
lp15@68296
   435
        apply (rule C1_differentiable_compose)
lp15@68296
   436
          apply (blast intro: C1_differentiable_on_subset [OF F])
lp15@68296
   437
          apply (blast intro: C1_differentiable_on_subset [OF G])
lp15@68296
   438
        by (simp add:  C1_differentiable_on_subset G Diff_Int_distrib2 fin)
lp15@68296
   439
    qed
lp15@68296
   440
  qed
lp15@68296
   441
  ultimately show ?thesis
lp15@68296
   442
    by (simp add: piecewise_C1_differentiable_on_def)
lp15@68296
   443
qed
lp15@61190
   444
lp15@61190
   445
lemma piecewise_C1_differentiable_on_subset:
lp15@68296
   446
    "f piecewise_C1_differentiable_on S \<Longrightarrow> T \<le> S \<Longrightarrow> f piecewise_C1_differentiable_on T"
lp15@61190
   447
  by (auto simp: piecewise_C1_differentiable_on_def elim!: continuous_on_subset C1_differentiable_on_subset)
lp15@61190
   448
lp15@61190
   449
lemma C1_differentiable_imp_continuous_on:
lp15@68296
   450
  "f C1_differentiable_on S \<Longrightarrow> continuous_on S f"
lp15@61190
   451
  unfolding C1_differentiable_on_eq continuous_on_eq_continuous_within
lp15@61190
   452
  using differentiable_at_withinI differentiable_imp_continuous_within by blast
lp15@61190
   453
lp15@61190
   454
lemma C1_differentiable_on_empty [iff]: "f C1_differentiable_on {}"
lp15@61190
   455
  unfolding C1_differentiable_on_def
lp15@61190
   456
  by auto
lp15@61190
   457
lp15@61190
   458
lemma piecewise_C1_differentiable_affine:
lp15@61190
   459
  fixes m::real
lp15@68296
   460
  assumes "f piecewise_C1_differentiable_on ((\<lambda>x. m * x + c) ` S)"
lp15@68339
   461
  shows "(f \<circ> (\<lambda>x. m *\<^sub>R x + c)) piecewise_C1_differentiable_on S"
lp15@61190
   462
proof (cases "m = 0")
lp15@61190
   463
  case True
lp15@61190
   464
  then show ?thesis
lp15@61190
   465
    unfolding o_def by (auto simp: piecewise_C1_differentiable_on_def continuous_on_const)
lp15@61190
   466
next
lp15@61190
   467
  case False
lp15@68296
   468
  have *: "\<And>x. finite (S \<inter> {y. m * y + c = x})"
lp15@68493
   469
    using False not_finite_existsD by fastforce
lp15@61190
   470
  show ?thesis
lp15@61190
   471
    apply (rule piecewise_C1_differentiable_compose [OF C1_differentiable_imp_piecewise])
lp15@68296
   472
    apply (rule * assms derivative_intros | simp add: False vimage_def)+
lp15@61190
   473
    done
lp15@61190
   474
qed
lp15@61190
   475
lp15@61190
   476
lemma piecewise_C1_differentiable_cases:
lp15@61190
   477
  fixes c::real
lp15@61190
   478
  assumes "f piecewise_C1_differentiable_on {a..c}"
lp15@61190
   479
          "g piecewise_C1_differentiable_on {c..b}"
lp15@61190
   480
           "a \<le> c" "c \<le> b" "f c = g c"
lp15@61190
   481
  shows "(\<lambda>x. if x \<le> c then f x else g x) piecewise_C1_differentiable_on {a..b}"
lp15@61190
   482
proof -
lp15@68296
   483
  obtain S T where st: "f C1_differentiable_on ({a..c} - S)"
lp15@68296
   484
                       "g C1_differentiable_on ({c..b} - T)"
lp15@68296
   485
                       "finite S" "finite T"
lp15@61190
   486
    using assms
lp15@61190
   487
    by (force simp: piecewise_C1_differentiable_on_def)
lp15@68296
   488
  then have f_diff: "f differentiable_on {a..<c} - S"
lp15@68296
   489
        and g_diff: "g differentiable_on {c<..b} - T"
lp15@61190
   490
    by (simp_all add: C1_differentiable_on_eq differentiable_at_withinI differentiable_on_def)
lp15@61190
   491
  have "continuous_on {a..c} f" "continuous_on {c..b} g"
lp15@61190
   492
    using assms piecewise_C1_differentiable_on_def by auto
lp15@61190
   493
  then have cab: "continuous_on {a..b} (\<lambda>x. if x \<le> c then f x else g x)"
lp15@61190
   494
    using continuous_on_cases [OF closed_real_atLeastAtMost [of a c],
lp15@61190
   495
                               OF closed_real_atLeastAtMost [of c b],
lp15@61190
   496
                               of f g "\<lambda>x. x\<le>c"]  assms
lp15@61190
   497
    by (force simp: ivl_disj_un_two_touch)
lp15@61190
   498
  { fix x
lp15@68296
   499
    assume x: "x \<in> {a..b} - insert c (S \<union> T)"
lp15@61190
   500
    have "(\<lambda>x. if x \<le> c then f x else g x) differentiable at x" (is "?diff_fg")
lp15@61190
   501
    proof (cases x c rule: le_cases)
lp15@61190
   502
      case le show ?diff_fg
paulson@62087
   503
        apply (rule differentiable_transform_within [where f=f and d = "dist x c"])
lp15@61190
   504
        using x dist_real_def le st by (auto simp: C1_differentiable_on_eq)
lp15@61190
   505
    next
lp15@61190
   506
      case ge show ?diff_fg
paulson@62087
   507
        apply (rule differentiable_transform_within [where f=g and d = "dist x c"])
lp15@61190
   508
        using dist_nz x dist_real_def ge st x by (auto simp: C1_differentiable_on_eq)
lp15@61190
   509
    qed
lp15@61190
   510
  }
lp15@68296
   511
  then have "(\<forall>x \<in> {a..b} - insert c (S \<union> T). (\<lambda>x. if x \<le> c then f x else g x) differentiable at x)"
lp15@61190
   512
    by auto
lp15@61190
   513
  moreover
lp15@68296
   514
  { assume fcon: "continuous_on ({a<..<c} - S) (\<lambda>x. vector_derivative f (at x))"
lp15@68296
   515
       and gcon: "continuous_on ({c<..<b} - T) (\<lambda>x. vector_derivative g (at x))"
lp15@68296
   516
    have "open ({a<..<c} - S)"  "open ({c<..<b} - T)"
lp15@61190
   517
      using st by (simp_all add: open_Diff finite_imp_closed)
lp15@68296
   518
    moreover have "continuous_on ({a<..<c} - S) (\<lambda>x. vector_derivative (\<lambda>x. if x \<le> c then f x else g x) (at x))"
lp15@68296
   519
    proof -
lp15@68296
   520
      have "((\<lambda>x. if x \<le> c then f x else g x) has_vector_derivative vector_derivative f (at x))            (at x)"
lp15@68296
   521
        if "a < x" "x < c" "x \<notin> S" for x
lp15@68296
   522
      proof -
lp15@68296
   523
        have f: "f differentiable at x"
lp15@68296
   524
          by (meson C1_differentiable_on_eq Diff_iff atLeastAtMost_iff less_eq_real_def st(1) that)
lp15@68296
   525
        show ?thesis
lp15@68296
   526
          using that
lp15@68296
   527
          apply (rule_tac f=f and d="dist x c" in has_vector_derivative_transform_within)
lp15@68339
   528
             apply (auto simp: dist_norm vector_derivative_works [symmetric] f)
lp15@68296
   529
          done
lp15@68296
   530
      qed
lp15@68296
   531
      then show ?thesis
lp15@68296
   532
        by (metis (no_types, lifting) continuous_on_eq [OF fcon] DiffE greaterThanLessThan_iff vector_derivative_at)
lp15@68296
   533
    qed
lp15@68296
   534
    moreover have "continuous_on ({c<..<b} - T) (\<lambda>x. vector_derivative (\<lambda>x. if x \<le> c then f x else g x) (at x))"
lp15@68296
   535
    proof -
lp15@68296
   536
      have "((\<lambda>x. if x \<le> c then f x else g x) has_vector_derivative vector_derivative g (at x))            (at x)"
lp15@68296
   537
        if "c < x" "x < b" "x \<notin> T" for x
lp15@68296
   538
      proof -
lp15@68296
   539
        have g: "g differentiable at x"
lp15@68296
   540
          by (metis C1_differentiable_on_eq DiffD1 DiffI atLeastAtMost_diff_ends greaterThanLessThan_iff st(2) that)
lp15@68296
   541
        show ?thesis
lp15@68296
   542
          using that
lp15@68296
   543
          apply (rule_tac f=g and d="dist x c" in has_vector_derivative_transform_within)
lp15@68339
   544
             apply (auto simp: dist_norm vector_derivative_works [symmetric] g)
lp15@68296
   545
          done
lp15@68296
   546
      qed
lp15@68296
   547
      then show ?thesis
lp15@68296
   548
        by (metis (no_types, lifting) continuous_on_eq [OF gcon] DiffE greaterThanLessThan_iff vector_derivative_at)
lp15@68296
   549
    qed
lp15@68296
   550
    ultimately have "continuous_on ({a<..<b} - insert c (S \<union> T))
lp15@61190
   551
        (\<lambda>x. vector_derivative (\<lambda>x. if x \<le> c then f x else g x) (at x))"
lp15@68296
   552
      by (rule continuous_on_subset [OF continuous_on_open_Un], auto)
lp15@61190
   553
  } note * = this
lp15@68296
   554
  have "continuous_on ({a<..<b} - insert c (S \<union> T)) (\<lambda>x. vector_derivative (\<lambda>x. if x \<le> c then f x else g x) (at x))"
lp15@61190
   555
    using st
lp15@61190
   556
    by (auto simp: C1_differentiable_on_eq elim!: continuous_on_subset intro: *)
lp15@68296
   557
  ultimately have "\<exists>S. finite S \<and> ((\<lambda>x. if x \<le> c then f x else g x) C1_differentiable_on {a..b} - S)"
lp15@68296
   558
    apply (rule_tac x="{a,b,c} \<union> S \<union> T" in exI)
lp15@61190
   559
    using st  by (auto simp: C1_differentiable_on_eq elim!: continuous_on_subset)
lp15@61190
   560
  with cab show ?thesis
lp15@61190
   561
    by (simp add: piecewise_C1_differentiable_on_def)
lp15@61190
   562
qed
lp15@61190
   563
lp15@61190
   564
lemma piecewise_C1_differentiable_neg:
lp15@68296
   565
    "f piecewise_C1_differentiable_on S \<Longrightarrow> (\<lambda>x. -(f x)) piecewise_C1_differentiable_on S"
lp15@61190
   566
  unfolding piecewise_C1_differentiable_on_def
lp15@61190
   567
  by (auto intro!: continuous_on_minus C1_differentiable_on_minus)
lp15@61190
   568
lp15@61190
   569
lemma piecewise_C1_differentiable_add:
lp15@61190
   570
  assumes "f piecewise_C1_differentiable_on i"
lp15@61190
   571
          "g piecewise_C1_differentiable_on i"
lp15@61190
   572
    shows "(\<lambda>x. f x + g x) piecewise_C1_differentiable_on i"
lp15@61190
   573
proof -
lp15@68296
   574
  obtain S t where st: "finite S" "finite t"
lp15@68296
   575
                       "f C1_differentiable_on (i-S)"
lp15@61190
   576
                       "g C1_differentiable_on (i-t)"
lp15@61190
   577
    using assms by (auto simp: piecewise_C1_differentiable_on_def)
lp15@68296
   578
  then have "finite (S \<union> t) \<and> (\<lambda>x. f x + g x) C1_differentiable_on i - (S \<union> t)"
lp15@61190
   579
    by (auto intro: C1_differentiable_on_add elim!: C1_differentiable_on_subset)
lp15@61190
   580
  moreover have "continuous_on i f" "continuous_on i g"
lp15@61190
   581
    using assms piecewise_C1_differentiable_on_def by auto
lp15@61190
   582
  ultimately show ?thesis
lp15@61190
   583
    by (auto simp: piecewise_C1_differentiable_on_def continuous_on_add)
lp15@61190
   584
qed
lp15@61190
   585
paulson@61204
   586
lemma piecewise_C1_differentiable_diff:
lp15@68296
   587
    "\<lbrakk>f piecewise_C1_differentiable_on S;  g piecewise_C1_differentiable_on S\<rbrakk>
lp15@68296
   588
     \<Longrightarrow> (\<lambda>x. f x - g x) piecewise_C1_differentiable_on S"
lp15@61190
   589
  unfolding diff_conv_add_uminus
lp15@61190
   590
  by (metis piecewise_C1_differentiable_add piecewise_C1_differentiable_neg)
lp15@61190
   591
lp15@61190
   592
lemma piecewise_C1_differentiable_D1:
lp15@61190
   593
  fixes g1 :: "real \<Rightarrow> 'a::real_normed_field"
lp15@61190
   594
  assumes "(g1 +++ g2) piecewise_C1_differentiable_on {0..1}"
lp15@61190
   595
    shows "g1 piecewise_C1_differentiable_on {0..1}"
lp15@61190
   596
proof -
lp15@68296
   597
  obtain S where "finite S"
lp15@68296
   598
             and co12: "continuous_on ({0..1} - S) (\<lambda>x. vector_derivative (g1 +++ g2) (at x))"
lp15@68296
   599
             and g12D: "\<forall>x\<in>{0..1} - S. g1 +++ g2 differentiable at x"
lp15@61190
   600
    using assms  by (auto simp: piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
nipkow@69064
   601
  have g1D: "g1 differentiable at x" if "x \<in> {0..1} - insert 1 ((*) 2 ` S)" for x
lp15@68296
   602
  proof (rule differentiable_transform_within)
nipkow@69064
   603
    show "g1 +++ g2 \<circ> (*) (inverse 2) differentiable at x"
lp15@68493
   604
      using that g12D
lp15@68296
   605
      apply (simp only: joinpaths_def)
lp15@68296
   606
      by (rule differentiable_chain_at derivative_intros | force)+
lp15@68296
   607
    show "\<And>x'. \<lbrakk>dist x' x < dist (x/2) (1/2)\<rbrakk>
nipkow@69064
   608
          \<Longrightarrow> (g1 +++ g2 \<circ> (*) (inverse 2)) x' = g1 x'"
lp15@68339
   609
      using that by (auto simp: dist_real_def joinpaths_def)
lp15@68296
   610
  qed (use that in \<open>auto simp: dist_real_def\<close>)
nipkow@69064
   611
  have [simp]: "vector_derivative (g1 \<circ> (*) 2) (at (x/2)) = 2 *\<^sub>R vector_derivative g1 (at x)"
nipkow@69064
   612
               if "x \<in> {0..1} - insert 1 ((*) 2 ` S)" for x
lp15@61190
   613
    apply (subst vector_derivative_chain_at)
lp15@61190
   614
    using that
lp15@61190
   615
    apply (rule derivative_eq_intros g1D | simp)+
lp15@61190
   616
    done
lp15@68296
   617
  have "continuous_on ({0..1/2} - insert (1/2) S) (\<lambda>x. vector_derivative (g1 +++ g2) (at x))"
lp15@61190
   618
    using co12 by (rule continuous_on_subset) force
nipkow@69064
   619
  then have coDhalf: "continuous_on ({0..1/2} - insert (1/2) S) (\<lambda>x. vector_derivative (g1 \<circ> (*)2) (at x))"
lp15@68296
   620
  proof (rule continuous_on_eq [OF _ vector_derivative_at])
nipkow@69064
   621
    show "(g1 +++ g2 has_vector_derivative vector_derivative (g1 \<circ> (*) 2) (at x)) (at x)"
lp15@68296
   622
      if "x \<in> {0..1/2} - insert (1/2) S" for x
lp15@68296
   623
    proof (rule has_vector_derivative_transform_within)
nipkow@69064
   624
      show "(g1 \<circ> (*) 2 has_vector_derivative vector_derivative (g1 \<circ> (*) 2) (at x)) (at x)"
lp15@68296
   625
        using that
lp15@68296
   626
        by (force intro: g1D differentiable_chain_at simp: vector_derivative_works [symmetric])
nipkow@69064
   627
      show "\<And>x'. \<lbrakk>dist x' x < dist x (1/2)\<rbrakk> \<Longrightarrow> (g1 \<circ> (*) 2) x' = (g1 +++ g2) x'"
lp15@68296
   628
        using that by (auto simp: dist_norm joinpaths_def)
lp15@68296
   629
    qed (use that in \<open>auto simp: dist_norm\<close>)
lp15@68296
   630
  qed
nipkow@69064
   631
  have "continuous_on ({0..1} - insert 1 ((*) 2 ` S))
nipkow@69064
   632
                      ((\<lambda>x. 1/2 * vector_derivative (g1 \<circ> (*)2) (at x)) \<circ> (*)(1/2))"
lp15@61190
   633
    apply (rule continuous_intros)+
lp15@61190
   634
    using coDhalf
lp15@61190
   635
    apply (simp add: scaleR_conv_of_real image_set_diff image_image)
lp15@61190
   636
    done
nipkow@69064
   637
  then have con_g1: "continuous_on ({0..1} - insert 1 ((*) 2 ` S)) (\<lambda>x. vector_derivative g1 (at x))"
lp15@61190
   638
    by (rule continuous_on_eq) (simp add: scaleR_conv_of_real)
lp15@61190
   639
  have "continuous_on {0..1} g1"
lp15@61190
   640
    using continuous_on_joinpaths_D1 assms piecewise_C1_differentiable_on_def by blast
lp15@68296
   641
  with \<open>finite S\<close> show ?thesis
lp15@61190
   642
    apply (clarsimp simp add: piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
nipkow@69064
   643
    apply (rule_tac x="insert 1 (((*)2)`S)" in exI)
lp15@61190
   644
    apply (simp add: g1D con_g1)
lp15@61190
   645
  done
lp15@61190
   646
qed
lp15@61190
   647
lp15@61190
   648
lemma piecewise_C1_differentiable_D2:
lp15@61190
   649
  fixes g2 :: "real \<Rightarrow> 'a::real_normed_field"
lp15@61190
   650
  assumes "(g1 +++ g2) piecewise_C1_differentiable_on {0..1}" "pathfinish g1 = pathstart g2"
lp15@61190
   651
    shows "g2 piecewise_C1_differentiable_on {0..1}"
lp15@61190
   652
proof -
lp15@68296
   653
  obtain S where "finite S"
lp15@68296
   654
             and co12: "continuous_on ({0..1} - S) (\<lambda>x. vector_derivative (g1 +++ g2) (at x))"
lp15@68296
   655
             and g12D: "\<forall>x\<in>{0..1} - S. g1 +++ g2 differentiable at x"
lp15@61190
   656
    using assms  by (auto simp: piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
lp15@68296
   657
  have g2D: "g2 differentiable at x" if "x \<in> {0..1} - insert 0 ((\<lambda>x. 2*x-1) ` S)" for x
lp15@68296
   658
  proof (rule differentiable_transform_within)
lp15@68296
   659
    show "g1 +++ g2 \<circ> (\<lambda>x. (x + 1) / 2) differentiable at x"
lp15@68296
   660
      using g12D that
lp15@68296
   661
      apply (simp only: joinpaths_def)
lp15@68296
   662
      apply (drule_tac x= "(x+1) / 2" in bspec, force simp: divide_simps)
lp15@68296
   663
      apply (rule differentiable_chain_at derivative_intros | force)+
lp15@68296
   664
      done
lp15@68296
   665
    show "\<And>x'. dist x' x < dist ((x + 1) / 2) (1/2) \<Longrightarrow> (g1 +++ g2 \<circ> (\<lambda>x. (x + 1) / 2)) x' = g2 x'"
lp15@68296
   666
      using that by (auto simp: dist_real_def joinpaths_def field_simps)
lp15@68296
   667
    qed (use that in \<open>auto simp: dist_norm\<close>)
lp15@61190
   668
  have [simp]: "vector_derivative (g2 \<circ> (\<lambda>x. 2*x-1)) (at ((x+1)/2)) = 2 *\<^sub>R vector_derivative g2 (at x)"
lp15@68296
   669
               if "x \<in> {0..1} - insert 0 ((\<lambda>x. 2*x-1) ` S)" for x
lp15@61190
   670
    using that  by (auto simp: vector_derivative_chain_at divide_simps g2D)
lp15@68296
   671
  have "continuous_on ({1/2..1} - insert (1/2) S) (\<lambda>x. vector_derivative (g1 +++ g2) (at x))"
lp15@61190
   672
    using co12 by (rule continuous_on_subset) force
lp15@68339
   673
  then have coDhalf: "continuous_on ({1/2..1} - insert (1/2) S) (\<lambda>x. vector_derivative (g2 \<circ> (\<lambda>x. 2*x-1)) (at x))"
lp15@68296
   674
  proof (rule continuous_on_eq [OF _ vector_derivative_at])
lp15@68296
   675
    show "(g1 +++ g2 has_vector_derivative vector_derivative (g2 \<circ> (\<lambda>x. 2 * x - 1)) (at x))
lp15@68296
   676
          (at x)"
lp15@68296
   677
      if "x \<in> {1 / 2..1} - insert (1 / 2) S" for x
lp15@68339
   678
    proof (rule_tac f="g2 \<circ> (\<lambda>x. 2*x-1)" and d="dist (3/4) ((x+1)/2)" in has_vector_derivative_transform_within)
lp15@68296
   679
      show "(g2 \<circ> (\<lambda>x. 2 * x - 1) has_vector_derivative vector_derivative (g2 \<circ> (\<lambda>x. 2 * x - 1)) (at x))
lp15@68296
   680
            (at x)"
lp15@68296
   681
        using that by (force intro: g2D differentiable_chain_at simp: vector_derivative_works [symmetric])
lp15@68296
   682
      show "\<And>x'. \<lbrakk>dist x' x < dist (3 / 4) ((x + 1) / 2)\<rbrakk> \<Longrightarrow> (g2 \<circ> (\<lambda>x. 2 * x - 1)) x' = (g1 +++ g2) x'"
lp15@68296
   683
        using that by (auto simp: dist_norm joinpaths_def add_divide_distrib)
lp15@68296
   684
    qed (use that in \<open>auto simp: dist_norm\<close>)
lp15@68296
   685
  qed
lp15@68296
   686
  have [simp]: "((\<lambda>x. (x+1) / 2) ` ({0..1} - insert 0 ((\<lambda>x. 2 * x - 1) ` S))) = ({1/2..1} - insert (1/2) S)"
lp15@61190
   687
    apply (simp add: image_set_diff inj_on_def image_image)
lp15@61190
   688
    apply (auto simp: image_affinity_atLeastAtMost_div add_divide_distrib)
lp15@61190
   689
    done
lp15@68296
   690
  have "continuous_on ({0..1} - insert 0 ((\<lambda>x. 2*x-1) ` S))
lp15@68339
   691
                      ((\<lambda>x. 1/2 * vector_derivative (g2 \<circ> (\<lambda>x. 2*x-1)) (at x)) \<circ> (\<lambda>x. (x+1)/2))"
lp15@61190
   692
    by (rule continuous_intros | simp add:  coDhalf)+
lp15@68296
   693
  then have con_g2: "continuous_on ({0..1} - insert 0 ((\<lambda>x. 2*x-1) ` S)) (\<lambda>x. vector_derivative g2 (at x))"
lp15@61190
   694
    by (rule continuous_on_eq) (simp add: scaleR_conv_of_real)
lp15@61190
   695
  have "continuous_on {0..1} g2"
lp15@61190
   696
    using continuous_on_joinpaths_D2 assms piecewise_C1_differentiable_on_def by blast
lp15@68296
   697
  with \<open>finite S\<close> show ?thesis
lp15@61190
   698
    apply (clarsimp simp add: piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
lp15@68296
   699
    apply (rule_tac x="insert 0 ((\<lambda>x. 2 * x - 1) ` S)" in exI)
lp15@61190
   700
    apply (simp add: g2D con_g2)
lp15@61190
   701
  done
lp15@61190
   702
qed
lp15@60809
   703
lp15@60809
   704
subsection \<open>Valid paths, and their start and finish\<close>
lp15@60809
   705
wl302@69423
   706
definition%important valid_path :: "(real \<Rightarrow> 'a :: real_normed_vector) \<Rightarrow> bool"
lp15@61190
   707
  where "valid_path f \<equiv> f piecewise_C1_differentiable_on {0..1::real}"
lp15@60809
   708
lp15@60809
   709
definition closed_path :: "(real \<Rightarrow> 'a :: real_normed_vector) \<Rightarrow> bool"
lp15@60809
   710
  where "closed_path g \<equiv> g 0 = g 1"
lp15@60809
   711
wl302@69423
   712
text\<open>In particular, all results for paths apply\<close>
lp15@60809
   713
lp15@60809
   714
lemma valid_path_imp_path: "valid_path g \<Longrightarrow> path g"
wl302@69423
   715
  by (simp add: path_def piecewise_C1_differentiable_on_def valid_path_def)
lp15@60809
   716
lp15@60809
   717
lemma connected_valid_path_image: "valid_path g \<Longrightarrow> connected(path_image g)"
lp15@60809
   718
  by (metis connected_path_image valid_path_imp_path)
lp15@60809
   719
lp15@60809
   720
lemma compact_valid_path_image: "valid_path g \<Longrightarrow> compact(path_image g)"
lp15@60809
   721
  by (metis compact_path_image valid_path_imp_path)
lp15@60809
   722
lp15@60809
   723
lemma bounded_valid_path_image: "valid_path g \<Longrightarrow> bounded(path_image g)"
lp15@60809
   724
  by (metis bounded_path_image valid_path_imp_path)
lp15@60809
   725
lp15@60809
   726
lemma closed_valid_path_image: "valid_path g \<Longrightarrow> closed(path_image g)"
lp15@60809
   727
  by (metis closed_path_image valid_path_imp_path)
lp15@60809
   728
wl302@69423
   729
lemma valid_path_compose:
lp15@62623
   730
  assumes "valid_path g"
lp15@64394
   731
      and der: "\<And>x. x \<in> path_image g \<Longrightarrow> f field_differentiable (at x)"
lp15@62540
   732
      and con: "continuous_on (path_image g) (deriv f)"
lp15@68339
   733
    shows "valid_path (f \<circ> g)"
lp15@62408
   734
proof -
lp15@68296
   735
  obtain S where "finite S" and g_diff: "g C1_differentiable_on {0..1} - S"
wenzelm@62837
   736
    using \<open>valid_path g\<close> unfolding valid_path_def piecewise_C1_differentiable_on_def by auto
lp15@68296
   737
  have "f \<circ> g differentiable at t" when "t\<in>{0..1} - S" for t
lp15@62408
   738
    proof (rule differentiable_chain_at)
wenzelm@62837
   739
      show "g differentiable at t" using \<open>valid_path g\<close>
lp15@68296
   740
        by (meson C1_differentiable_on_eq \<open>g C1_differentiable_on {0..1} - S\<close> that)
lp15@62408
   741
    next
lp15@62408
   742
      have "g t\<in>path_image g" using that DiffD1 image_eqI path_image_def by metis
lp15@68493
   743
      then show "f differentiable at (g t)"
lp15@64394
   744
        using der[THEN field_differentiable_imp_differentiable] by auto
lp15@62408
   745
    qed
lp15@68296
   746
  moreover have "continuous_on ({0..1} - S) (\<lambda>x. vector_derivative (f \<circ> g) (at x))"
lp15@62540
   747
    proof (rule continuous_on_eq [where f = "\<lambda>x. vector_derivative g (at x) * deriv f (g x)"],
lp15@62540
   748
        rule continuous_intros)
lp15@68296
   749
      show "continuous_on ({0..1} - S) (\<lambda>x. vector_derivative g (at x))"
lp15@62540
   750
        using g_diff C1_differentiable_on_eq by auto
lp15@62540
   751
    next
lp15@62623
   752
      have "continuous_on {0..1} (\<lambda>x. deriv f (g x))"
lp15@62623
   753
        using continuous_on_compose[OF _ con[unfolded path_image_def],unfolded comp_def]
wenzelm@62837
   754
          \<open>valid_path g\<close> piecewise_C1_differentiable_on_def valid_path_def
lp15@62540
   755
        by blast
lp15@68296
   756
      then show "continuous_on ({0..1} - S) (\<lambda>x. deriv f (g x))"
lp15@62540
   757
        using continuous_on_subset by blast
lp15@62408
   758
    next
lp15@62540
   759
      show "vector_derivative g (at t) * deriv f (g t) = vector_derivative (f \<circ> g) (at t)"
lp15@68296
   760
          when "t \<in> {0..1} - S" for t
lp15@62540
   761
        proof (rule vector_derivative_chain_at_general[symmetric])
lp15@62540
   762
          show "g differentiable at t" by (meson C1_differentiable_on_eq g_diff that)
lp15@62540
   763
        next
lp15@62540
   764
          have "g t\<in>path_image g" using that DiffD1 image_eqI path_image_def by metis
lp15@64394
   765
          then show "f field_differentiable at (g t)" using der by auto
lp15@62540
   766
        qed
lp15@62408
   767
    qed
lp15@68339
   768
  ultimately have "f \<circ> g C1_differentiable_on {0..1} - S"
lp15@62408
   769
    using C1_differentiable_on_eq by blast
lp15@68493
   770
  moreover have "path (f \<circ> g)"
lp15@64394
   771
    apply (rule path_continuous_image[OF valid_path_imp_path[OF \<open>valid_path g\<close>]])
lp15@64394
   772
    using der
lp15@64394
   773
    by (simp add: continuous_at_imp_continuous_on field_differentiable_imp_continuous_at)
lp15@62408
   774
  ultimately show ?thesis unfolding valid_path_def piecewise_C1_differentiable_on_def path_def
lp15@68296
   775
    using \<open>finite S\<close> by auto
lp15@62408
   776
qed
lp15@68532
   777
  
lp15@68532
   778
lemma valid_path_uminus_comp[simp]:
lp15@68532
   779
  fixes g::"real \<Rightarrow> 'a ::real_normed_field"
lp15@68532
   780
  shows "valid_path (uminus \<circ> g) \<longleftrightarrow> valid_path g"
lp15@68532
   781
proof 
lp15@68532
   782
  show "valid_path g \<Longrightarrow> valid_path (uminus \<circ> g)" for g::"real \<Rightarrow> 'a"
lp15@68532
   783
    by (auto intro!: valid_path_compose derivative_intros simp add: deriv_linear[of "-1",simplified])  
lp15@68532
   784
  then show "valid_path g" when "valid_path (uminus \<circ> g)"
lp15@68532
   785
    by (metis fun.map_comp group_add_class.minus_comp_minus id_comp that)
lp15@68532
   786
qed
lp15@68532
   787
lp15@68532
   788
lemma valid_path_offset[simp]:
lp15@68532
   789
  shows "valid_path (\<lambda>t. g t - z) \<longleftrightarrow> valid_path g"  
lp15@68532
   790
proof 
lp15@68532
   791
  show *: "valid_path (g::real\<Rightarrow>'a) \<Longrightarrow> valid_path (\<lambda>t. g t - z)" for g z
lp15@68532
   792
    unfolding valid_path_def
lp15@68532
   793
    by (fastforce intro:derivative_intros C1_differentiable_imp_piecewise piecewise_C1_differentiable_diff)
lp15@68532
   794
  show "valid_path (\<lambda>t. g t - z) \<Longrightarrow> valid_path g"
lp15@68532
   795
    using *[of "\<lambda>t. g t - z" "-z",simplified] .
lp15@68532
   796
qed
lp15@68532
   797
  
lp15@60809
   798
lp15@60809
   799
subsection\<open>Contour Integrals along a path\<close>
lp15@60809
   800
lp15@60809
   801
text\<open>This definition is for complex numbers only, and does not generalise to line integrals in a vector field\<close>
lp15@60809
   802
lp15@61190
   803
text\<open>piecewise differentiable function on [0,1]\<close>
lp15@60809
   804
wl302@69423
   805
definition%important has_contour_integral :: "(complex \<Rightarrow> complex) \<Rightarrow> complex \<Rightarrow> (real \<Rightarrow> complex) \<Rightarrow> bool"
lp15@61738
   806
           (infixr "has'_contour'_integral" 50)
lp15@61738
   807
  where "(f has_contour_integral i) g \<equiv>
lp15@60809
   808
           ((\<lambda>x. f(g x) * vector_derivative g (at x within {0..1}))
lp15@60809
   809
            has_integral i) {0..1}"
lp15@60809
   810
wl302@69423
   811
definition%important contour_integrable_on
lp15@61738
   812
           (infixr "contour'_integrable'_on" 50)
lp15@61738
   813
  where "f contour_integrable_on g \<equiv> \<exists>i. (f has_contour_integral i) g"
lp15@61738
   814
wl302@69423
   815
definition%important contour_integral
wenzelm@67613
   816
  where "contour_integral g f \<equiv> SOME i. (f has_contour_integral i) g \<or> \<not> f contour_integrable_on g \<and> i=0"
wenzelm@67613
   817
wenzelm@67613
   818
lemma not_integrable_contour_integral: "\<not> f contour_integrable_on g \<Longrightarrow> contour_integral g f = 0"
lp15@62534
   819
  unfolding contour_integrable_on_def contour_integral_def by blast
lp15@62463
   820
lp15@62463
   821
lemma contour_integral_unique: "(f has_contour_integral i) g \<Longrightarrow> contour_integral g f = i"
lp15@62463
   822
  apply (simp add: contour_integral_def has_contour_integral_def contour_integrable_on_def)
lp15@62463
   823
  using has_integral_unique by blast
lp15@61738
   824
wl302@69423
   825
lemma has_contour_integral_eqpath:
lp15@62397
   826
     "\<lbrakk>(f has_contour_integral y) p; f contour_integrable_on \<gamma>;
paulson@62131
   827
       contour_integral p f = contour_integral \<gamma> f\<rbrakk>
paulson@62131
   828
      \<Longrightarrow> (f has_contour_integral y) \<gamma>"
paulson@62131
   829
using contour_integrable_on_def contour_integral_unique by auto
paulson@62131
   830
lp15@61738
   831
lemma has_contour_integral_integral:
lp15@61738
   832
    "f contour_integrable_on i \<Longrightarrow> (f has_contour_integral (contour_integral i f)) i"
lp15@61738
   833
  by (metis contour_integral_unique contour_integrable_on_def)
lp15@61738
   834
lp15@61738
   835
lemma has_contour_integral_unique:
lp15@61738
   836
    "(f has_contour_integral i) g \<Longrightarrow> (f has_contour_integral j) g \<Longrightarrow> i = j"
lp15@60809
   837
  using has_integral_unique
lp15@61738
   838
  by (auto simp: has_contour_integral_def)
lp15@61738
   839
lp15@61738
   840
lemma has_contour_integral_integrable: "(f has_contour_integral i) g \<Longrightarrow> f contour_integrable_on g"
lp15@61738
   841
  using contour_integrable_on_def by blast
lp15@60809
   842
wl302@69423
   843
text\<open>Show that we can forget about the localized derivative.\<close>
lp15@60809
   844
lp15@60809
   845
lemma has_integral_localized_vector_derivative:
lp15@60809
   846
    "((\<lambda>x. f (g x) * vector_derivative g (at x within {a..b})) has_integral i) {a..b} \<longleftrightarrow>
lp15@60809
   847
     ((\<lambda>x. f (g x) * vector_derivative g (at x)) has_integral i) {a..b}"
lp15@60809
   848
proof -
lp15@68296
   849
  have *: "{a..b} - {a,b} = interior {a..b}"
lp15@60809
   850
    by (simp add: atLeastAtMost_diff_ends)
lp15@60809
   851
  show ?thesis
lp15@60809
   852
    apply (rule has_integral_spike_eq [of "{a,b}"])
lp15@68296
   853
    apply (auto simp: at_within_interior [of _ "{a..b}"])
lp15@60809
   854
    done
lp15@60809
   855
qed
lp15@60809
   856
lp15@60809
   857
lemma integrable_on_localized_vector_derivative:
lp15@60809
   858
    "(\<lambda>x. f (g x) * vector_derivative g (at x within {a..b})) integrable_on {a..b} \<longleftrightarrow>
lp15@60809
   859
     (\<lambda>x. f (g x) * vector_derivative g (at x)) integrable_on {a..b}"
lp15@60809
   860
  by (simp add: integrable_on_def has_integral_localized_vector_derivative)
lp15@60809
   861
lp15@61738
   862
lemma has_contour_integral:
lp15@61738
   863
     "(f has_contour_integral i) g \<longleftrightarrow>
lp15@60809
   864
      ((\<lambda>x. f (g x) * vector_derivative g (at x)) has_integral i) {0..1}"
lp15@61738
   865
  by (simp add: has_integral_localized_vector_derivative has_contour_integral_def)
lp15@61738
   866
lp15@61738
   867
lemma contour_integrable_on:
lp15@61738
   868
     "f contour_integrable_on g \<longleftrightarrow>
lp15@60809
   869
      (\<lambda>t. f(g t) * vector_derivative g (at t)) integrable_on {0..1}"
lp15@61738
   870
  by (simp add: has_contour_integral integrable_on_def contour_integrable_on_def)
lp15@60809
   871
wl302@69423
   872
subsection%unimportant \<open>Reversing a path\<close>
lp15@60809
   873
lp15@60809
   874
lemma valid_path_imp_reverse:
lp15@60809
   875
  assumes "valid_path g"
lp15@60809
   876
    shows "valid_path(reversepath g)"
lp15@60809
   877
proof -
lp15@68296
   878
  obtain S where "finite S" and S: "g C1_differentiable_on ({0..1} - S)"
lp15@61190
   879
    using assms by (auto simp: valid_path_def piecewise_C1_differentiable_on_def)
lp15@68296
   880
  then have "finite ((-) 1 ` S)"
lp15@68296
   881
    by auto
lp15@68296
   882
  moreover have "(reversepath g C1_differentiable_on ({0..1} - (-) 1 ` S))"
lp15@68296
   883
    unfolding reversepath_def
lp15@61190
   884
    apply (rule C1_differentiable_compose [of "\<lambda>x::real. 1-x" _ g, unfolded o_def])
lp15@68296
   885
    using S
lp15@68296
   886
    by (force simp: finite_vimageI inj_on_def C1_differentiable_on_eq continuous_on_const elim!: continuous_on_subset)+
lp15@68296
   887
  ultimately show ?thesis using assms
lp15@61190
   888
    by (auto simp: valid_path_def piecewise_C1_differentiable_on_def path_def [symmetric])
lp15@60809
   889
qed
lp15@60809
   890
lp15@62540
   891
lemma valid_path_reversepath [simp]: "valid_path(reversepath g) \<longleftrightarrow> valid_path g"
lp15@60809
   892
  using valid_path_imp_reverse by force
lp15@60809
   893
lp15@61738
   894
lemma has_contour_integral_reversepath:
lp15@68296
   895
  assumes "valid_path g" and f: "(f has_contour_integral i) g"
lp15@61738
   896
    shows "(f has_contour_integral (-i)) (reversepath g)"
lp15@60809
   897
proof -
lp15@68296
   898
  { fix S x
lp15@68296
   899
    assume xs: "g C1_differentiable_on ({0..1} - S)" "x \<notin> (-) 1 ` S" "0 \<le> x" "x \<le> 1"
lp15@68296
   900
    have "vector_derivative (\<lambda>x. g (1 - x)) (at x within {0..1}) =
lp15@60809
   901
            - vector_derivative g (at (1 - x) within {0..1})"
lp15@68296
   902
    proof -
lp15@68296
   903
      obtain f' where f': "(g has_vector_derivative f') (at (1 - x))"
lp15@68296
   904
        using xs
lp15@68296
   905
        by (force simp: has_vector_derivative_def C1_differentiable_on_def)
lp15@68339
   906
      have "(g \<circ> (\<lambda>x. 1 - x) has_vector_derivative -1 *\<^sub>R f') (at x)"
lp15@68296
   907
        by (intro vector_diff_chain_within has_vector_derivative_at_within [OF f'] derivative_eq_intros | simp)+
lp15@68296
   908
      then have mf': "((\<lambda>x. g (1 - x)) has_vector_derivative -f') (at x)"
lp15@68296
   909
        by (simp add: o_def)
lp15@68296
   910
      show ?thesis
lp15@68296
   911
        using xs
lp15@68296
   912
        by (auto simp: vector_derivative_at_within_ivl [OF mf'] vector_derivative_at_within_ivl [OF f'])
lp15@68296
   913
    qed
lp15@60809
   914
  } note * = this
lp15@68296
   915
  obtain S where S: "continuous_on {0..1} g" "finite S" "g C1_differentiable_on {0..1} - S"
lp15@68296
   916
    using assms by (auto simp: valid_path_def piecewise_C1_differentiable_on_def)
lp15@68296
   917
  have "((\<lambda>x. - (f (g (1 - x)) * vector_derivative g (at (1 - x) within {0..1}))) has_integral -i)
lp15@68296
   918
       {0..1}"
lp15@68296
   919
    using has_integral_affinity01 [where m= "-1" and c=1, OF f [unfolded has_contour_integral_def]]
lp15@68296
   920
    by (simp add: has_integral_neg)
lp15@68493
   921
  then show ?thesis
lp15@68296
   922
    using S
lp15@68296
   923
    apply (clarsimp simp: reversepath_def has_contour_integral_def)
lp15@68296
   924
    apply (rule_tac S = "(\<lambda>x. 1 - x) ` S" in has_integral_spike_finite)
lp15@68296
   925
      apply (auto simp: *)
lp15@60809
   926
    done
lp15@60809
   927
qed
lp15@60809
   928
lp15@61738
   929
lemma contour_integrable_reversepath:
lp15@61738
   930
    "valid_path g \<Longrightarrow> f contour_integrable_on g \<Longrightarrow> f contour_integrable_on (reversepath g)"
lp15@61738
   931
  using has_contour_integral_reversepath contour_integrable_on_def by blast
lp15@61738
   932
lp15@61738
   933
lemma contour_integrable_reversepath_eq:
lp15@61738
   934
    "valid_path g \<Longrightarrow> (f contour_integrable_on (reversepath g) \<longleftrightarrow> f contour_integrable_on g)"
lp15@61738
   935
  using contour_integrable_reversepath valid_path_reversepath by fastforce
lp15@61738
   936
lp15@61738
   937
lemma contour_integral_reversepath:
lp15@62463
   938
  assumes "valid_path g"
lp15@62463
   939
    shows "contour_integral (reversepath g) f = - (contour_integral g f)"
lp15@62463
   940
proof (cases "f contour_integrable_on g")
lp15@62463
   941
  case True then show ?thesis
lp15@62463
   942
    by (simp add: assms contour_integral_unique has_contour_integral_integral has_contour_integral_reversepath)
lp15@62463
   943
next
nipkow@69508
   944
  case False then have "\<not> f contour_integrable_on (reversepath g)"
lp15@62463
   945
    by (simp add: assms contour_integrable_reversepath_eq)
lp15@62463
   946
  with False show ?thesis by (simp add: not_integrable_contour_integral)
lp15@62463
   947
qed
lp15@60809
   948
lp15@60809
   949
wl302@69423
   950
subsection%unimportant \<open>Joining two paths together\<close>
lp15@60809
   951
lp15@60809
   952
lemma valid_path_join:
lp15@60809
   953
  assumes "valid_path g1" "valid_path g2" "pathfinish g1 = pathstart g2"
lp15@60809
   954
    shows "valid_path(g1 +++ g2)"
lp15@60809
   955
proof -
lp15@60809
   956
  have "g1 1 = g2 0"
lp15@60809
   957
    using assms by (auto simp: pathfinish_def pathstart_def)
lp15@68339
   958
  moreover have "(g1 \<circ> (\<lambda>x. 2*x)) piecewise_C1_differentiable_on {0..1/2}"
lp15@61190
   959
    apply (rule piecewise_C1_differentiable_compose)
lp15@60809
   960
    using assms
lp15@61190
   961
    apply (auto simp: valid_path_def piecewise_C1_differentiable_on_def continuous_on_joinpaths)
nipkow@69064
   962
    apply (force intro: finite_vimageI [where h = "(*)2"] inj_onI)
lp15@60809
   963
    done
lp15@68339
   964
  moreover have "(g2 \<circ> (\<lambda>x. 2*x-1)) piecewise_C1_differentiable_on {1/2..1}"
lp15@61190
   965
    apply (rule piecewise_C1_differentiable_compose)
lp15@61190
   966
    using assms unfolding valid_path_def piecewise_C1_differentiable_on_def
lp15@61190
   967
    by (auto intro!: continuous_intros finite_vimageI [where h = "(\<lambda>x. 2*x - 1)"] inj_onI
lp15@61190
   968
             simp: image_affinity_atLeastAtMost_diff continuous_on_joinpaths)
lp15@60809
   969
  ultimately show ?thesis
lp15@60809
   970
    apply (simp only: valid_path_def continuous_on_joinpaths joinpaths_def)
lp15@61190
   971
    apply (rule piecewise_C1_differentiable_cases)
lp15@60809
   972
    apply (auto simp: o_def)
lp15@60809
   973
    done
lp15@60809
   974
qed
lp15@60809
   975
lp15@61190
   976
lemma valid_path_join_D1:
lp15@61190
   977
  fixes g1 :: "real \<Rightarrow> 'a::real_normed_field"
lp15@61190
   978
  shows "valid_path (g1 +++ g2) \<Longrightarrow> valid_path g1"
lp15@61190
   979
  unfolding valid_path_def
lp15@61190
   980
  by (rule piecewise_C1_differentiable_D1)
lp15@60809
   981
lp15@61190
   982
lemma valid_path_join_D2:
lp15@61190
   983
  fixes g2 :: "real \<Rightarrow> 'a::real_normed_field"
lp15@61190
   984
  shows "\<lbrakk>valid_path (g1 +++ g2); pathfinish g1 = pathstart g2\<rbrakk> \<Longrightarrow> valid_path g2"
lp15@61190
   985
  unfolding valid_path_def
lp15@61190
   986
  by (rule piecewise_C1_differentiable_D2)
lp15@60809
   987
lp15@60809
   988
lemma valid_path_join_eq [simp]:
lp15@61190
   989
  fixes g2 :: "real \<Rightarrow> 'a::real_normed_field"
lp15@61190
   990
  shows "pathfinish g1 = pathstart g2 \<Longrightarrow> (valid_path(g1 +++ g2) \<longleftrightarrow> valid_path g1 \<and> valid_path g2)"
lp15@60809
   991
  using valid_path_join_D1 valid_path_join_D2 valid_path_join by blast
lp15@60809
   992
lp15@61738
   993
lemma has_contour_integral_join:
lp15@61738
   994
  assumes "(f has_contour_integral i1) g1" "(f has_contour_integral i2) g2"
lp15@60809
   995
          "valid_path g1" "valid_path g2"
lp15@61738
   996
    shows "(f has_contour_integral (i1 + i2)) (g1 +++ g2)"
lp15@60809
   997
proof -
lp15@60809
   998
  obtain s1 s2
lp15@60809
   999
    where s1: "finite s1" "\<forall>x\<in>{0..1} - s1. g1 differentiable at x"
lp15@60809
  1000
      and s2: "finite s2" "\<forall>x\<in>{0..1} - s2. g2 differentiable at x"
lp15@60809
  1001
    using assms
lp15@61190
  1002
    by (auto simp: valid_path_def piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
lp15@60809
  1003
  have 1: "((\<lambda>x. f (g1 x) * vector_derivative g1 (at x)) has_integral i1) {0..1}"
lp15@60809
  1004
   and 2: "((\<lambda>x. f (g2 x) * vector_derivative g2 (at x)) has_integral i2) {0..1}"
lp15@60809
  1005
    using assms
lp15@61738
  1006
    by (auto simp: has_contour_integral)
lp15@60809
  1007
  have i1: "((\<lambda>x. (2*f (g1 (2*x))) * vector_derivative g1 (at (2*x))) has_integral i1) {0..1/2}"
lp15@60809
  1008
   and i2: "((\<lambda>x. (2*f (g2 (2*x - 1))) * vector_derivative g2 (at (2*x - 1))) has_integral i2) {1/2..1}"
lp15@60809
  1009
    using has_integral_affinity01 [OF 1, where m= 2 and c=0, THEN has_integral_cmul [where c=2]]
lp15@60809
  1010
          has_integral_affinity01 [OF 2, where m= 2 and c="-1", THEN has_integral_cmul [where c=2]]
lp15@60809
  1011
    by (simp_all only: image_affinity_atLeastAtMost_div_diff, simp_all add: scaleR_conv_of_real mult_ac)
lp15@60809
  1012
  have g1: "\<lbrakk>0 \<le> z; z*2 < 1; z*2 \<notin> s1\<rbrakk> \<Longrightarrow>
lp15@60809
  1013
            vector_derivative (\<lambda>x. if x*2 \<le> 1 then g1 (2*x) else g2 (2*x - 1)) (at z) =
lp15@60809
  1014
            2 *\<^sub>R vector_derivative g1 (at (z*2))" for z
paulson@62087
  1015
    apply (rule vector_derivative_at [OF has_vector_derivative_transform_within [where f = "(\<lambda>x. g1(2*x))" and d = "\<bar>z - 1/2\<bar>"]])
nipkow@62390
  1016
    apply (simp_all add: dist_real_def abs_if split: if_split_asm)
lp15@60809
  1017
    apply (rule vector_diff_chain_at [of "\<lambda>x. 2*x" 2 _ g1, simplified o_def])
lp15@60809
  1018
    apply (simp add: has_vector_derivative_def has_derivative_def bounded_linear_mult_left)
lp15@60809
  1019
    using s1
lp15@60809
  1020
    apply (auto simp: algebra_simps vector_derivative_works)
lp15@60809
  1021
    done
lp15@60809
  1022
  have g2: "\<lbrakk>1 < z*2; z \<le> 1; z*2 - 1 \<notin> s2\<rbrakk> \<Longrightarrow>
lp15@60809
  1023
            vector_derivative (\<lambda>x. if x*2 \<le> 1 then g1 (2*x) else g2 (2*x - 1)) (at z) =
lp15@60809
  1024
            2 *\<^sub>R vector_derivative g2 (at (z*2 - 1))" for z
paulson@62087
  1025
    apply (rule vector_derivative_at [OF has_vector_derivative_transform_within [where f = "(\<lambda>x. g2 (2*x - 1))" and d = "\<bar>z - 1/2\<bar>"]])
nipkow@62390
  1026
    apply (simp_all add: dist_real_def abs_if split: if_split_asm)
lp15@60809
  1027
    apply (rule vector_diff_chain_at [of "\<lambda>x. 2*x - 1" 2 _ g2, simplified o_def])
lp15@60809
  1028
    apply (simp add: has_vector_derivative_def has_derivative_def bounded_linear_mult_left)
lp15@60809
  1029
    using s2
lp15@60809
  1030
    apply (auto simp: algebra_simps vector_derivative_works)
lp15@60809
  1031
    done
lp15@60809
  1032
  have "((\<lambda>x. f ((g1 +++ g2) x) * vector_derivative (g1 +++ g2) (at x)) has_integral i1) {0..1/2}"
nipkow@69064
  1033
    apply (rule has_integral_spike_finite [OF _ _ i1, of "insert (1/2) ((*)2 -` s1)"])
lp15@60809
  1034
    using s1
nipkow@69064
  1035
    apply (force intro: finite_vimageI [where h = "(*)2"] inj_onI)
lp15@60809
  1036
    apply (clarsimp simp add: joinpaths_def scaleR_conv_of_real mult_ac g1)
lp15@60809
  1037
    done
lp15@60809
  1038
  moreover have "((\<lambda>x. f ((g1 +++ g2) x) * vector_derivative (g1 +++ g2) (at x)) has_integral i2) {1/2..1}"
lp15@60809
  1039
    apply (rule has_integral_spike_finite [OF _ _ i2, of "insert (1/2) ((\<lambda>x. 2*x-1) -` s2)"])
lp15@60809
  1040
    using s2
lp15@60809
  1041
    apply (force intro: finite_vimageI [where h = "\<lambda>x. 2*x-1"] inj_onI)
lp15@60809
  1042
    apply (clarsimp simp add: joinpaths_def scaleR_conv_of_real mult_ac g2)
lp15@60809
  1043
    done
lp15@60809
  1044
  ultimately
lp15@60809
  1045
  show ?thesis
lp15@61738
  1046
    apply (simp add: has_contour_integral)
lp15@60809
  1047
    apply (rule has_integral_combine [where c = "1/2"], auto)
lp15@60809
  1048
    done
lp15@60809
  1049
qed
lp15@60809
  1050
lp15@61738
  1051
lemma contour_integrable_joinI:
lp15@61738
  1052
  assumes "f contour_integrable_on g1" "f contour_integrable_on g2"
lp15@60809
  1053
          "valid_path g1" "valid_path g2"
lp15@61738
  1054
    shows "f contour_integrable_on (g1 +++ g2)"
lp15@60809
  1055
  using assms
lp15@61738
  1056
  by (meson has_contour_integral_join contour_integrable_on_def)
lp15@61738
  1057
lp15@61738
  1058
lemma contour_integrable_joinD1:
lp15@61738
  1059
  assumes "f contour_integrable_on (g1 +++ g2)" "valid_path g1"
lp15@61738
  1060
    shows "f contour_integrable_on g1"
lp15@60809
  1061
proof -
lp15@60809
  1062
  obtain s1
lp15@60809
  1063
    where s1: "finite s1" "\<forall>x\<in>{0..1} - s1. g1 differentiable at x"
lp15@61190
  1064
    using assms by (auto simp: valid_path_def piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
lp15@60809
  1065
  have "(\<lambda>x. f ((g1 +++ g2) (x/2)) * vector_derivative (g1 +++ g2) (at (x/2))) integrable_on {0..1}"
lp15@60809
  1066
    using assms
lp15@61738
  1067
    apply (auto simp: contour_integrable_on)
lp15@60809
  1068
    apply (drule integrable_on_subcbox [where a=0 and b="1/2"])
lp15@60809
  1069
    apply (auto intro: integrable_affinity [of _ 0 "1/2::real" "1/2" 0, simplified])
lp15@60809
  1070
    done
lp15@60809
  1071
  then have *: "(\<lambda>x. (f ((g1 +++ g2) (x/2))/2) * vector_derivative (g1 +++ g2) (at (x/2))) integrable_on {0..1}"
lp15@61190
  1072
    by (auto dest: integrable_cmul [where c="1/2"] simp: scaleR_conv_of_real)
lp15@60809
  1073
  have g1: "\<lbrakk>0 < z; z < 1; z \<notin> s1\<rbrakk> \<Longrightarrow>
lp15@60809
  1074
            vector_derivative (\<lambda>x. if x*2 \<le> 1 then g1 (2*x) else g2 (2*x - 1)) (at (z/2)) =
lp15@60809
  1075
            2 *\<^sub>R vector_derivative g1 (at z)"  for z
paulson@62087
  1076
    apply (rule vector_derivative_at [OF has_vector_derivative_transform_within [where f = "(\<lambda>x. g1(2*x))" and d = "\<bar>(z-1)/2\<bar>"]])
nipkow@62390
  1077
    apply (simp_all add: field_simps dist_real_def abs_if split: if_split_asm)
lp15@60809
  1078
    apply (rule vector_diff_chain_at [of "\<lambda>x. x*2" 2 _ g1, simplified o_def])
lp15@60809
  1079
    using s1
lp15@60809
  1080
    apply (auto simp: vector_derivative_works has_vector_derivative_def has_derivative_def bounded_linear_mult_left)
lp15@60809
  1081
    done
lp15@60809
  1082
  show ?thesis
lp15@60809
  1083
    using s1
lp15@61738
  1084
    apply (auto simp: contour_integrable_on)
lp15@60809
  1085
    apply (rule integrable_spike_finite [of "{0,1} \<union> s1", OF _ _ *])
lp15@60809
  1086
    apply (auto simp: joinpaths_def scaleR_conv_of_real g1)
lp15@60809
  1087
    done
lp15@60809
  1088
qed
lp15@60809
  1089
lp15@61738
  1090
lemma contour_integrable_joinD2:
lp15@61738
  1091
  assumes "f contour_integrable_on (g1 +++ g2)" "valid_path g2"
lp15@61738
  1092
    shows "f contour_integrable_on g2"
lp15@60809
  1093
proof -
lp15@60809
  1094
  obtain s2
lp15@60809
  1095
    where s2: "finite s2" "\<forall>x\<in>{0..1} - s2. g2 differentiable at x"
lp15@61190
  1096
    using assms by (auto simp: valid_path_def piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
lp15@60809
  1097
  have "(\<lambda>x. f ((g1 +++ g2) (x/2 + 1/2)) * vector_derivative (g1 +++ g2) (at (x/2 + 1/2))) integrable_on {0..1}"
lp15@60809
  1098
    using assms
lp15@61738
  1099
    apply (auto simp: contour_integrable_on)
lp15@60809
  1100
    apply (drule integrable_on_subcbox [where a="1/2" and b=1], auto)
lp15@60809
  1101
    apply (drule integrable_affinity [of _ "1/2::real" 1 "1/2" "1/2", simplified])
lp15@60809
  1102
    apply (simp add: image_affinity_atLeastAtMost_diff)
lp15@60809
  1103
    done
lp15@60809
  1104
  then have *: "(\<lambda>x. (f ((g1 +++ g2) (x/2 + 1/2))/2) * vector_derivative (g1 +++ g2) (at (x/2 + 1/2)))
lp15@60809
  1105
                integrable_on {0..1}"
lp15@60809
  1106
    by (auto dest: integrable_cmul [where c="1/2"] simp: scaleR_conv_of_real)
lp15@60809
  1107
  have g2: "\<lbrakk>0 < z; z < 1; z \<notin> s2\<rbrakk> \<Longrightarrow>
lp15@60809
  1108
            vector_derivative (\<lambda>x. if x*2 \<le> 1 then g1 (2*x) else g2 (2*x - 1)) (at (z/2+1/2)) =
lp15@60809
  1109
            2 *\<^sub>R vector_derivative g2 (at z)" for z
paulson@62087
  1110
    apply (rule vector_derivative_at [OF has_vector_derivative_transform_within [where f = "(\<lambda>x. g2(2*x-1))" and d = "\<bar>z/2\<bar>"]])
nipkow@62390
  1111
    apply (simp_all add: field_simps dist_real_def abs_if split: if_split_asm)
lp15@60809
  1112
    apply (rule vector_diff_chain_at [of "\<lambda>x. x*2-1" 2 _ g2, simplified o_def])
lp15@60809
  1113
    using s2
lp15@60809
  1114
    apply (auto simp: has_vector_derivative_def has_derivative_def bounded_linear_mult_left
lp15@60809
  1115
                      vector_derivative_works add_divide_distrib)
lp15@60809
  1116
    done
lp15@60809
  1117
  show ?thesis
lp15@60809
  1118
    using s2
lp15@61738
  1119
    apply (auto simp: contour_integrable_on)
lp15@60809
  1120
    apply (rule integrable_spike_finite [of "{0,1} \<union> s2", OF _ _ *])
lp15@60809
  1121
    apply (auto simp: joinpaths_def scaleR_conv_of_real g2)
lp15@60809
  1122
    done
lp15@60809
  1123
qed
lp15@60809
  1124
lp15@61738
  1125
lemma contour_integrable_join [simp]:
lp15@60809
  1126
  shows
lp15@60809
  1127
    "\<lbrakk>valid_path g1; valid_path g2\<rbrakk>
lp15@61738
  1128
     \<Longrightarrow> f contour_integrable_on (g1 +++ g2) \<longleftrightarrow> f contour_integrable_on g1 \<and> f contour_integrable_on g2"
lp15@61738
  1129
using contour_integrable_joinD1 contour_integrable_joinD2 contour_integrable_joinI by blast
lp15@61738
  1130
lp15@61738
  1131
lemma contour_integral_join [simp]:
lp15@60809
  1132
  shows
lp15@61738
  1133
    "\<lbrakk>f contour_integrable_on g1; f contour_integrable_on g2; valid_path g1; valid_path g2\<rbrakk>
lp15@61738
  1134
        \<Longrightarrow> contour_integral (g1 +++ g2) f = contour_integral g1 f + contour_integral g2 f"
lp15@61738
  1135
  by (simp add: has_contour_integral_integral has_contour_integral_join contour_integral_unique)
lp15@60809
  1136
lp15@60809
  1137
wl302@69423
  1138
subsection%unimportant \<open>Shifting the starting point of a (closed) path\<close>
lp15@60809
  1139
lp15@60809
  1140
lemma shiftpath_alt_def: "shiftpath a f = (\<lambda>x. if x \<le> 1-a then f (a + x) else f (a + x - 1))"
lp15@60809
  1141
  by (auto simp: shiftpath_def)
lp15@60809
  1142
lp15@60809
  1143
lemma valid_path_shiftpath [intro]:
lp15@60809
  1144
  assumes "valid_path g" "pathfinish g = pathstart g" "a \<in> {0..1}"
lp15@60809
  1145
    shows "valid_path(shiftpath a g)"
lp15@60809
  1146
  using assms
lp15@60809
  1147
  apply (auto simp: valid_path_def shiftpath_alt_def)
lp15@61190
  1148
  apply (rule piecewise_C1_differentiable_cases)
lp15@60809
  1149
  apply (auto simp: algebra_simps)
lp15@61190
  1150
  apply (rule piecewise_C1_differentiable_affine [of g 1 a, simplified o_def scaleR_one])
lp15@61190
  1151
  apply (auto simp: pathfinish_def pathstart_def elim: piecewise_C1_differentiable_on_subset)
lp15@61190
  1152
  apply (rule piecewise_C1_differentiable_affine [of g 1 "a-1", simplified o_def scaleR_one algebra_simps])
lp15@61190
  1153
  apply (auto simp: pathfinish_def pathstart_def elim: piecewise_C1_differentiable_on_subset)
lp15@60809
  1154
  done
lp15@60809
  1155
lp15@61738
  1156
lemma has_contour_integral_shiftpath:
lp15@61738
  1157
  assumes f: "(f has_contour_integral i) g" "valid_path g"
lp15@60809
  1158
      and a: "a \<in> {0..1}"
lp15@61738
  1159
    shows "(f has_contour_integral i) (shiftpath a g)"
lp15@60809
  1160
proof -
lp15@60809
  1161
  obtain s
lp15@60809
  1162
    where s: "finite s" and g: "\<forall>x\<in>{0..1} - s. g differentiable at x"
lp15@61190
  1163
    using assms by (auto simp: valid_path_def piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
lp15@60809
  1164
  have *: "((\<lambda>x. f (g x) * vector_derivative g (at x)) has_integral i) {0..1}"
lp15@61738
  1165
    using assms by (auto simp: has_contour_integral)
lp15@60809
  1166
  then have i: "i = integral {a..1} (\<lambda>x. f (g x) * vector_derivative g (at x)) +
lp15@60809
  1167
                    integral {0..a} (\<lambda>x. f (g x) * vector_derivative g (at x))"
lp15@60809
  1168
    apply (rule has_integral_unique)
lp15@60809
  1169
    apply (subst add.commute)
hoelzl@63594
  1170
    apply (subst integral_combine)
lp15@60809
  1171
    using assms * integral_unique by auto
lp15@60809
  1172
  { fix x
lp15@60809
  1173
    have "0 \<le> x \<Longrightarrow> x + a < 1 \<Longrightarrow> x \<notin> (\<lambda>x. x - a) ` s \<Longrightarrow>
lp15@60809
  1174
         vector_derivative (shiftpath a g) (at x) = vector_derivative g (at (x + a))"
lp15@60809
  1175
      unfolding shiftpath_def
paulson@62087
  1176
      apply (rule vector_derivative_at [OF has_vector_derivative_transform_within [where f = "(\<lambda>x. g(a+x))" and d = "dist(1-a) x"]])
nipkow@62390
  1177
        apply (auto simp: field_simps dist_real_def abs_if split: if_split_asm)
lp15@60809
  1178
      apply (rule vector_diff_chain_at [of "\<lambda>x. x+a" 1 _ g, simplified o_def scaleR_one])
lp15@60809
  1179
       apply (intro derivative_eq_intros | simp)+
lp15@60809
  1180
      using g
lp15@60809
  1181
       apply (drule_tac x="x+a" in bspec)
lp15@60809
  1182
      using a apply (auto simp: has_vector_derivative_def vector_derivative_works image_def add.commute)
lp15@60809
  1183
      done
lp15@60809
  1184
  } note vd1 = this
lp15@60809
  1185
  { fix x
lp15@60809
  1186
    have "1 < x + a \<Longrightarrow> x \<le> 1 \<Longrightarrow> x \<notin> (\<lambda>x. x - a + 1) ` s \<Longrightarrow>
lp15@60809
  1187
          vector_derivative (shiftpath a g) (at x) = vector_derivative g (at (x + a - 1))"
lp15@60809
  1188
      unfolding shiftpath_def
paulson@62087
  1189
      apply (rule vector_derivative_at [OF has_vector_derivative_transform_within [where f = "(\<lambda>x. g(a+x-1))" and d = "dist (1-a) x"]])
nipkow@62390
  1190
        apply (auto simp: field_simps dist_real_def abs_if split: if_split_asm)
lp15@60809
  1191
      apply (rule vector_diff_chain_at [of "\<lambda>x. x+a-1" 1 _ g, simplified o_def scaleR_one])
lp15@60809
  1192
       apply (intro derivative_eq_intros | simp)+
lp15@60809
  1193
      using g
lp15@60809
  1194
      apply (drule_tac x="x+a-1" in bspec)
lp15@60809
  1195
      using a apply (auto simp: has_vector_derivative_def vector_derivative_works image_def add.commute)
lp15@60809
  1196
      done
lp15@60809
  1197
  } note vd2 = this
lp15@60809
  1198
  have va1: "(\<lambda>x. f (g x) * vector_derivative g (at x)) integrable_on ({a..1})"
lp15@60809
  1199
    using * a   by (fastforce intro: integrable_subinterval_real)
lp15@60809
  1200
  have v0a: "(\<lambda>x. f (g x) * vector_derivative g (at x)) integrable_on ({0..a})"
lp15@60809
  1201
    apply (rule integrable_subinterval_real)
lp15@60809
  1202
    using * a by auto
lp15@60809
  1203
  have "((\<lambda>x. f (shiftpath a g x) * vector_derivative (shiftpath a g) (at x))
lp15@60809
  1204
        has_integral  integral {a..1} (\<lambda>x. f (g x) * vector_derivative g (at x)))  {0..1 - a}"
lp15@60809
  1205
    apply (rule has_integral_spike_finite
lp15@65587
  1206
             [where S = "{1-a} \<union> (\<lambda>x. x-a) ` s" and f = "\<lambda>x. f(g(a+x)) * vector_derivative g (at(a+x))"])
lp15@60809
  1207
      using s apply blast
lp15@60809
  1208
     using a apply (auto simp: algebra_simps vd1)
lp15@60809
  1209
     apply (force simp: shiftpath_def add.commute)
lp15@60809
  1210
    using has_integral_affinity [where m=1 and c=a, simplified, OF integrable_integral [OF va1]]
lp15@60809
  1211
    apply (simp add: image_affinity_atLeastAtMost_diff [where m=1 and c=a, simplified] add.commute)
lp15@60809
  1212
    done
lp15@60809
  1213
  moreover
lp15@60809
  1214
  have "((\<lambda>x. f (shiftpath a g x) * vector_derivative (shiftpath a g) (at x))
lp15@60809
  1215
        has_integral  integral {0..a} (\<lambda>x. f (g x) * vector_derivative g (at x)))  {1 - a..1}"
lp15@60809
  1216
    apply (rule has_integral_spike_finite
lp15@65587
  1217
             [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))"])
lp15@60809
  1218
      using s apply blast
lp15@60809
  1219
     using a apply (auto simp: algebra_simps vd2)
lp15@60809
  1220
     apply (force simp: shiftpath_def add.commute)
lp15@60809
  1221
    using has_integral_affinity [where m=1 and c="a-1", simplified, OF integrable_integral [OF v0a]]
lp15@60809
  1222
    apply (simp add: image_affinity_atLeastAtMost [where m=1 and c="1-a", simplified])
lp15@60809
  1223
    apply (simp add: algebra_simps)
lp15@60809
  1224
    done
lp15@60809
  1225
  ultimately show ?thesis
lp15@60809
  1226
    using a
lp15@61738
  1227
    by (auto simp: i has_contour_integral intro: has_integral_combine [where c = "1-a"])
lp15@60809
  1228
qed
lp15@60809
  1229
lp15@61738
  1230
lemma has_contour_integral_shiftpath_D:
lp15@61738
  1231
  assumes "(f has_contour_integral i) (shiftpath a g)"
lp15@60809
  1232
          "valid_path g" "pathfinish g = pathstart g" "a \<in> {0..1}"
lp15@61738
  1233
    shows "(f has_contour_integral i) g"
lp15@60809
  1234
proof -
lp15@60809
  1235
  obtain s
lp15@60809
  1236
    where s: "finite s" and g: "\<forall>x\<in>{0..1} - s. g differentiable at x"
lp15@61190
  1237
    using assms by (auto simp: valid_path_def piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
lp15@60809
  1238
  { fix x
lp15@60809
  1239
    assume x: "0 < x" "x < 1" "x \<notin> s"
lp15@60809
  1240
    then have gx: "g differentiable at x"
lp15@60809
  1241
      using g by auto
lp15@60809
  1242
    have "vector_derivative g (at x within {0..1}) =
lp15@60809
  1243
          vector_derivative (shiftpath (1 - a) (shiftpath a g)) (at x within {0..1})"
lp15@60809
  1244
      apply (rule vector_derivative_at_within_ivl
lp15@60809
  1245
                  [OF has_vector_derivative_transform_within_open
lp15@68239
  1246
                      [where f = "(shiftpath (1 - a) (shiftpath a g))" and S = "{0<..<1}-s"]])
lp15@60809
  1247
      using s g assms x
lp15@60809
  1248
      apply (auto simp: finite_imp_closed open_Diff shiftpath_shiftpath
lp15@68296
  1249
                        at_within_interior [of _ "{0..1}"] vector_derivative_works [symmetric])
paulson@62087
  1250
      apply (rule differentiable_transform_within [OF gx, of "min x (1-x)"])
nipkow@62390
  1251
      apply (auto simp: dist_real_def shiftpath_shiftpath abs_if split: if_split_asm)
lp15@60809
  1252
      done
lp15@60809
  1253
  } note vd = this
lp15@61738
  1254
  have fi: "(f has_contour_integral i) (shiftpath (1 - a) (shiftpath a g))"
lp15@61738
  1255
    using assms  by (auto intro!: has_contour_integral_shiftpath)
lp15@60809
  1256
  show ?thesis
lp15@61738
  1257
    apply (simp add: has_contour_integral_def)
lp15@61738
  1258
    apply (rule has_integral_spike_finite [of "{0,1} \<union> s", OF _ _  fi [unfolded has_contour_integral_def]])
lp15@60809
  1259
    using s assms vd
lp15@60809
  1260
    apply (auto simp: Path_Connected.shiftpath_shiftpath)
lp15@60809
  1261
    done
lp15@60809
  1262
qed
lp15@60809
  1263
lp15@61738
  1264
lemma has_contour_integral_shiftpath_eq:
lp15@60809
  1265
  assumes "valid_path g" "pathfinish g = pathstart g" "a \<in> {0..1}"
lp15@61738
  1266
    shows "(f has_contour_integral i) (shiftpath a g) \<longleftrightarrow> (f has_contour_integral i) g"
lp15@61738
  1267
  using assms has_contour_integral_shiftpath has_contour_integral_shiftpath_D by blast
lp15@61738
  1268
lp15@62463
  1269
lemma contour_integrable_on_shiftpath_eq:
lp15@62463
  1270
  assumes "valid_path g" "pathfinish g = pathstart g" "a \<in> {0..1}"
lp15@62463
  1271
    shows "f contour_integrable_on (shiftpath a g) \<longleftrightarrow> f contour_integrable_on g"
lp15@62463
  1272
using assms contour_integrable_on_def has_contour_integral_shiftpath_eq by auto
lp15@62463
  1273
lp15@61738
  1274
lemma contour_integral_shiftpath:
lp15@60809
  1275
  assumes "valid_path g" "pathfinish g = pathstart g" "a \<in> {0..1}"
lp15@61738
  1276
    shows "contour_integral (shiftpath a g) f = contour_integral g f"
lp15@62534
  1277
   using assms
lp15@62463
  1278
   by (simp add: contour_integral_def contour_integrable_on_def has_contour_integral_shiftpath_eq)
lp15@60809
  1279
lp15@60809
  1280
wl302@69423
  1281
subsection%unimportant \<open>More about straight-line paths\<close>
lp15@60809
  1282
lp15@60809
  1283
lemma has_vector_derivative_linepath_within:
lp15@60809
  1284
    "(linepath a b has_vector_derivative (b - a)) (at x within s)"
lp15@60809
  1285
apply (simp add: linepath_def has_vector_derivative_def algebra_simps)
lp15@60809
  1286
apply (rule derivative_eq_intros | simp)+
lp15@60809
  1287
done
lp15@60809
  1288
lp15@60809
  1289
lemma vector_derivative_linepath_within:
lp15@60809
  1290
    "x \<in> {0..1} \<Longrightarrow> vector_derivative (linepath a b) (at x within {0..1}) = b - a"
immler@67685
  1291
  apply (rule vector_derivative_within_cbox [of 0 "1::real", simplified])
lp15@60809
  1292
  apply (auto simp: has_vector_derivative_linepath_within)
lp15@60809
  1293
  done
lp15@60809
  1294
lp15@61190
  1295
lemma vector_derivative_linepath_at [simp]: "vector_derivative (linepath a b) (at x) = b - a"
lp15@60809
  1296
  by (simp add: has_vector_derivative_linepath_within vector_derivative_at)
lp15@60809
  1297
lp15@61190
  1298
lemma valid_path_linepath [iff]: "valid_path (linepath a b)"
lp15@61190
  1299
  apply (simp add: valid_path_def piecewise_C1_differentiable_on_def C1_differentiable_on_eq continuous_on_linepath)
lp15@61190
  1300
  apply (rule_tac x="{}" in exI)
lp15@61190
  1301
  apply (simp add: differentiable_on_def differentiable_def)
lp15@61190
  1302
  using has_vector_derivative_def has_vector_derivative_linepath_within
lp15@61190
  1303
  apply (fastforce simp add: continuous_on_eq_continuous_within)
lp15@61190
  1304
  done
lp15@61190
  1305
lp15@61738
  1306
lemma has_contour_integral_linepath:
lp15@61738
  1307
  shows "(f has_contour_integral i) (linepath a b) \<longleftrightarrow>
lp15@60809
  1308
         ((\<lambda>x. f(linepath a b x) * (b - a)) has_integral i) {0..1}"
lp15@61738
  1309
  by (simp add: has_contour_integral vector_derivative_linepath_at)
lp15@60809
  1310
lp15@60809
  1311
lemma linepath_in_path:
lp15@60809
  1312
  shows "x \<in> {0..1} \<Longrightarrow> linepath a b x \<in> closed_segment a b"
lp15@60809
  1313
  by (auto simp: segment linepath_def)
lp15@60809
  1314
lp15@60809
  1315
lemma linepath_image_01: "linepath a b ` {0..1} = closed_segment a b"
lp15@60809
  1316
  by (auto simp: segment linepath_def)
lp15@60809
  1317
lp15@60809
  1318
lemma linepath_in_convex_hull:
lp15@60809
  1319
    fixes x::real
lp15@60809
  1320
    assumes a: "a \<in> convex hull s"
lp15@60809
  1321
        and b: "b \<in> convex hull s"
lp15@60809
  1322
        and x: "0\<le>x" "x\<le>1"
lp15@60809
  1323
       shows "linepath a b x \<in> convex hull s"
lp15@60809
  1324
  apply (rule closed_segment_subset_convex_hull [OF a b, THEN subsetD])
lp15@60809
  1325
  using x
lp15@60809
  1326
  apply (auto simp: linepath_image_01 [symmetric])
lp15@60809
  1327
  done
lp15@60809
  1328
lp15@60809
  1329
lemma Re_linepath: "Re(linepath (of_real a) (of_real b) x) = (1 - x)*a + x*b"
lp15@60809
  1330
  by (simp add: linepath_def)
lp15@60809
  1331
lp15@60809
  1332
lemma Im_linepath: "Im(linepath (of_real a) (of_real b) x) = 0"
lp15@60809
  1333
  by (simp add: linepath_def)
lp15@60809
  1334
lp15@61738
  1335
lemma has_contour_integral_trivial [iff]: "(f has_contour_integral 0) (linepath a a)"
lp15@61738
  1336
  by (simp add: has_contour_integral_linepath)
lp15@61738
  1337
lp15@68296
  1338
lemma has_contour_integral_trivial_iff [simp]: "(f has_contour_integral i) (linepath a a) \<longleftrightarrow> i=0"
lp15@68296
  1339
  using has_contour_integral_unique by blast
lp15@68296
  1340
lp15@61738
  1341
lemma contour_integral_trivial [simp]: "contour_integral (linepath a a) f = 0"
lp15@61738
  1342
  using has_contour_integral_trivial contour_integral_unique by blast
lp15@60809
  1343
eberlm@68721
  1344
lemma differentiable_linepath [intro]: "linepath a b differentiable at x within A"
eberlm@68721
  1345
  by (auto simp: linepath_def)
eberlm@68721
  1346
eberlm@68721
  1347
lemma bounded_linear_linepath:
eberlm@68721
  1348
  assumes "bounded_linear f"
eberlm@68721
  1349
  shows   "f (linepath a b x) = linepath (f a) (f b) x"
eberlm@68721
  1350
proof -
eberlm@68721
  1351
  interpret f: bounded_linear f by fact
eberlm@68721
  1352
  show ?thesis by (simp add: linepath_def f.add f.scale)
eberlm@68721
  1353
qed
eberlm@68721
  1354
eberlm@68721
  1355
lemma bounded_linear_linepath':
eberlm@68721
  1356
  assumes "bounded_linear f"
eberlm@68721
  1357
  shows   "f \<circ> linepath a b = linepath (f a) (f b)"
eberlm@68721
  1358
  using bounded_linear_linepath[OF assms] by (simp add: fun_eq_iff)
eberlm@68721
  1359
eberlm@68721
  1360
lemma cnj_linepath: "cnj (linepath a b x) = linepath (cnj a) (cnj b) x"
eberlm@68721
  1361
  by (simp add: linepath_def)
eberlm@68721
  1362
eberlm@68721
  1363
lemma cnj_linepath': "cnj \<circ> linepath a b = linepath (cnj a) (cnj b)"
eberlm@68721
  1364
  by (simp add: linepath_def fun_eq_iff)
eberlm@68721
  1365
lp15@60809
  1366
subsection\<open>Relation to subpath construction\<close>
lp15@60809
  1367
lp15@60809
  1368
lemma valid_path_subpath:
lp15@60809
  1369
  fixes g :: "real \<Rightarrow> 'a :: real_normed_vector"
lp15@60809
  1370
  assumes "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}"
lp15@60809
  1371
    shows "valid_path(subpath u v g)"
lp15@60809
  1372
proof (cases "v=u")
lp15@60809
  1373
  case True
lp15@60809
  1374
  then show ?thesis
lp15@61190
  1375
    unfolding valid_path_def subpath_def
lp15@61190
  1376
    by (force intro: C1_differentiable_on_const C1_differentiable_imp_piecewise)
lp15@60809
  1377
next
lp15@60809
  1378
  case False
lp15@68339
  1379
  have "(g \<circ> (\<lambda>x. ((v-u) * x + u))) piecewise_C1_differentiable_on {0..1}"
lp15@61190
  1380
    apply (rule piecewise_C1_differentiable_compose)
lp15@61190
  1381
    apply (simp add: C1_differentiable_imp_piecewise)
lp15@60809
  1382
     apply (simp add: image_affinity_atLeastAtMost)
lp15@60809
  1383
    using assms False
lp15@61190
  1384
    apply (auto simp: algebra_simps valid_path_def piecewise_C1_differentiable_on_subset)
lp15@60809
  1385
    apply (subst Int_commute)
lp15@60809
  1386
    apply (auto simp: inj_on_def algebra_simps crossproduct_eq finite_vimage_IntI)
lp15@60809
  1387
    done
lp15@60809
  1388
  then show ?thesis
lp15@60809
  1389
    by (auto simp: o_def valid_path_def subpath_def)
lp15@60809
  1390
qed
lp15@60809
  1391
lp15@61738
  1392
lemma has_contour_integral_subpath_refl [iff]: "(f has_contour_integral 0) (subpath u u g)"
lp15@61738
  1393
  by (simp add: has_contour_integral subpath_def)
lp15@61738
  1394
lp15@61738
  1395
lemma contour_integrable_subpath_refl [iff]: "f contour_integrable_on (subpath u u g)"
lp15@61738
  1396
  using has_contour_integral_subpath_refl contour_integrable_on_def by blast
lp15@61738
  1397
lp15@61738
  1398
lemma contour_integral_subpath_refl [simp]: "contour_integral (subpath u u g) f = 0"
lp15@61738
  1399
  by (simp add: has_contour_integral_subpath_refl contour_integral_unique)
lp15@61738
  1400
lp15@61738
  1401
lemma has_contour_integral_subpath:
lp15@61738
  1402
  assumes f: "f contour_integrable_on g" and g: "valid_path g"
lp15@60809
  1403
      and uv: "u \<in> {0..1}" "v \<in> {0..1}" "u \<le> v"
lp15@61738
  1404
    shows "(f has_contour_integral  integral {u..v} (\<lambda>x. f(g x) * vector_derivative g (at x)))
lp15@60809
  1405
           (subpath u v g)"
lp15@60809
  1406
proof (cases "v=u")
lp15@60809
  1407
  case True
lp15@60809
  1408
  then show ?thesis
lp15@61738
  1409
    using f   by (simp add: contour_integrable_on_def subpath_def has_contour_integral)
lp15@60809
  1410
next
lp15@60809
  1411
  case False
lp15@60809
  1412
  obtain s where s: "\<And>x. x \<in> {0..1} - s \<Longrightarrow> g differentiable at x" and fs: "finite s"
lp15@61190
  1413
    using g unfolding piecewise_C1_differentiable_on_def C1_differentiable_on_eq valid_path_def by blast
lp15@60809
  1414
  have *: "((\<lambda>x. f (g ((v - u) * x + u)) * vector_derivative g (at ((v - u) * x + u)))
lp15@60809
  1415
            has_integral (1 / (v - u)) * integral {u..v} (\<lambda>t. f (g t) * vector_derivative g (at t)))
lp15@60809
  1416
           {0..1}"
lp15@60809
  1417
    using f uv
lp15@61738
  1418
    apply (simp add: contour_integrable_on subpath_def has_contour_integral)
lp15@60809
  1419
    apply (drule integrable_on_subcbox [where a=u and b=v, simplified])
lp15@60809
  1420
    apply (simp_all add: has_integral_integral)
lp15@60809
  1421
    apply (drule has_integral_affinity [where m="v-u" and c=u, simplified])
lp15@60809
  1422
    apply (simp_all add: False image_affinity_atLeastAtMost_div_diff scaleR_conv_of_real)
lp15@60809
  1423
    apply (simp add: divide_simps False)
lp15@60809
  1424
    done
lp15@60809
  1425
  { fix x
lp15@60809
  1426
    have "x \<in> {0..1} \<Longrightarrow>
lp15@60809
  1427
           x \<notin> (\<lambda>t. (v-u) *\<^sub>R t + u) -` s \<Longrightarrow>
lp15@60809
  1428
           vector_derivative (\<lambda>x. g ((v-u) * x + u)) (at x) = (v-u) *\<^sub>R vector_derivative g (at ((v-u) * x + u))"
lp15@60809
  1429
      apply (rule vector_derivative_at [OF vector_diff_chain_at [simplified o_def]])
lp15@60809
  1430
      apply (intro derivative_eq_intros | simp)+
lp15@60809
  1431
      apply (cut_tac s [of "(v - u) * x + u"])
lp15@60809
  1432
      using uv mult_left_le [of x "v-u"]
lp15@60809
  1433
      apply (auto simp:  vector_derivative_works)
lp15@60809
  1434
      done
lp15@60809
  1435
  } note vd = this
lp15@60809
  1436
  show ?thesis
lp15@60809
  1437
    apply (cut_tac has_integral_cmul [OF *, where c = "v-u"])
lp15@60809
  1438
    using fs assms
lp15@61738
  1439
    apply (simp add: False subpath_def has_contour_integral)
lp15@65587
  1440
    apply (rule_tac S = "(\<lambda>t. ((v-u) *\<^sub>R t + u)) -` s" in has_integral_spike_finite)
lp15@60809
  1441
    apply (auto simp: inj_on_def False finite_vimageI vd scaleR_conv_of_real)
lp15@60809
  1442
    done
lp15@60809
  1443
qed
lp15@60809
  1444
lp15@61738
  1445
lemma contour_integrable_subpath:
lp15@61738
  1446
  assumes "f contour_integrable_on g" "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}"
lp15@61738
  1447
    shows "f contour_integrable_on (subpath u v g)"
lp15@60809
  1448
  apply (cases u v rule: linorder_class.le_cases)
lp15@61738
  1449
   apply (metis contour_integrable_on_def has_contour_integral_subpath [OF assms])
lp15@60809
  1450
  apply (subst reversepath_subpath [symmetric])
lp15@61738
  1451
  apply (rule contour_integrable_reversepath)
lp15@60809
  1452
   using assms apply (blast intro: valid_path_subpath)
lp15@61738
  1453
  apply (simp add: contour_integrable_on_def)
lp15@61738
  1454
  using assms apply (blast intro: has_contour_integral_subpath)
lp15@60809
  1455
  done
lp15@60809
  1456
lp15@61738
  1457
lemma has_integral_contour_integral_subpath:
lp15@61738
  1458
  assumes "f contour_integrable_on g" "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}" "u \<le> v"
lp15@60809
  1459
    shows "(((\<lambda>x. f(g x) * vector_derivative g (at x)))
lp15@61738
  1460
            has_integral  contour_integral (subpath u v g) f) {u..v}"
lp15@60809
  1461
  using assms
lp15@60809
  1462
  apply (auto simp: has_integral_integrable_integral)
lp15@66507
  1463
  apply (rule integrable_on_subcbox [where a=u and b=v and S = "{0..1}", simplified])
lp15@61738
  1464
  apply (auto simp: contour_integral_unique [OF has_contour_integral_subpath] contour_integrable_on)
lp15@60809
  1465
  done
lp15@60809
  1466
lp15@61738
  1467
lemma contour_integral_subcontour_integral:
lp15@61738
  1468
  assumes "f contour_integrable_on g" "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}" "u \<le> v"
lp15@61738
  1469
    shows "contour_integral (subpath u v g) f =
lp15@60809
  1470
           integral {u..v} (\<lambda>x. f(g x) * vector_derivative g (at x))"
lp15@61738
  1471
  using assms has_contour_integral_subpath contour_integral_unique by blast
lp15@61738
  1472
lp15@61738
  1473
lemma contour_integral_subpath_combine_less:
lp15@61738
  1474
  assumes "f contour_integrable_on g" "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}" "w \<in> {0..1}"
lp15@60809
  1475
          "u<v" "v<w"
lp15@61738
  1476
    shows "contour_integral (subpath u v g) f + contour_integral (subpath v w g) f =
lp15@61738
  1477
           contour_integral (subpath u w g) f"
lp15@61738
  1478
  using assms apply (auto simp: contour_integral_subcontour_integral)
lp15@60809
  1479
  apply (rule integral_combine, auto)
lp15@66507
  1480
  apply (rule integrable_on_subcbox [where a=u and b=w and S = "{0..1}", simplified])
lp15@61738
  1481
  apply (auto simp: contour_integrable_on)
lp15@60809
  1482
  done
lp15@60809
  1483
lp15@61738
  1484
lemma contour_integral_subpath_combine:
lp15@61738
  1485
  assumes "f contour_integrable_on g" "valid_path g" "u \<in> {0..1}" "v \<in> {0..1}" "w \<in> {0..1}"
lp15@61738
  1486
    shows "contour_integral (subpath u v g) f + contour_integral (subpath v w g) f =
lp15@61738
  1487
           contour_integral (subpath u w g) f"
lp15@60809
  1488
proof (cases "u\<noteq>v \<and> v\<noteq>w \<and> u\<noteq>w")
lp15@60809
  1489
  case True
lp15@60809
  1490
    have *: "subpath v u g = reversepath(subpath u v g) \<and>
lp15@60809
  1491
             subpath w u g = reversepath(subpath u w g) \<and>
lp15@60809
  1492
             subpath w v g = reversepath(subpath v w g)"
lp15@60809
  1493
      by (auto simp: reversepath_subpath)
lp15@60809
  1494
    have "u < v \<and> v < w \<or>
lp15@60809
  1495
          u < w \<and> w < v \<or>
lp15@60809
  1496
          v < u \<and> u < w \<or>
lp15@60809
  1497
          v < w \<and> w < u \<or>
lp15@60809
  1498
          w < u \<and> u < v \<or>
lp15@60809
  1499
          w < v \<and> v < u"
lp15@60809
  1500
      using True assms by linarith
lp15@60809
  1501
    with assms show ?thesis
lp15@61738
  1502
      using contour_integral_subpath_combine_less [of f g u v w]
lp15@61738
  1503
            contour_integral_subpath_combine_less [of f g u w v]
lp15@61738
  1504
            contour_integral_subpath_combine_less [of f g v u w]
lp15@61738
  1505
            contour_integral_subpath_combine_less [of f g v w u]
lp15@61738
  1506
            contour_integral_subpath_combine_less [of f g w u v]
lp15@61738
  1507
            contour_integral_subpath_combine_less [of f g w v u]
lp15@60809
  1508
      apply simp
lp15@60809
  1509
      apply (elim disjE)
lp15@61738
  1510
      apply (auto simp: * contour_integral_reversepath contour_integrable_subpath
lp15@60809
  1511
                   valid_path_reversepath valid_path_subpath algebra_simps)
lp15@60809
  1512
      done
lp15@60809
  1513
next
lp15@60809
  1514
  case False
lp15@60809
  1515
  then show ?thesis
lp15@61738
  1516
    apply (auto simp: contour_integral_subpath_refl)
lp15@60809
  1517
    using assms
lp15@61738
  1518
    by (metis eq_neg_iff_add_eq_0 contour_integrable_subpath contour_integral_reversepath reversepath_subpath valid_path_subpath)
lp15@60809
  1519
qed
lp15@60809
  1520
lp15@61738
  1521
lemma contour_integral_integral:
lp15@62463
  1522
     "contour_integral g f = integral {0..1} (\<lambda>x. f (g x) * vector_derivative g (at x))"
lp15@62463
  1523
  by (simp add: contour_integral_def integral_def has_contour_integral contour_integrable_on)
lp15@60809
  1524
eberlm@68721
  1525
lemma contour_integral_cong:
eberlm@68721
  1526
  assumes "g = g'" "\<And>x. x \<in> path_image g \<Longrightarrow> f x = f' x"
eberlm@68721
  1527
  shows   "contour_integral g f = contour_integral g' f'"
eberlm@68721
  1528
  unfolding contour_integral_integral using assms
eberlm@68721
  1529
  by (intro integral_cong) (auto simp: path_image_def)
eberlm@68721
  1530
eberlm@68721
  1531
eberlm@68721
  1532
text \<open>Contour integral along a segment on the real axis\<close>
eberlm@68721
  1533
eberlm@68721
  1534
lemma has_contour_integral_linepath_Reals_iff:
eberlm@68721
  1535
  fixes a b :: complex and f :: "complex \<Rightarrow> complex"
eberlm@68721
  1536
  assumes "a \<in> Reals" "b \<in> Reals" "Re a < Re b"
eberlm@68721
  1537
  shows   "(f has_contour_integral I) (linepath a b) \<longleftrightarrow>
eberlm@68721
  1538
             ((\<lambda>x. f (of_real x)) has_integral I) {Re a..Re b}"
eberlm@68721
  1539
proof -
eberlm@68721
  1540
  from assms have [simp]: "of_real (Re a) = a" "of_real (Re b) = b"
eberlm@68721
  1541
    by (simp_all add: complex_eq_iff)
eberlm@68721
  1542
  from assms have "a \<noteq> b" by auto
eberlm@68721
  1543
  have "((\<lambda>x. f (of_real x)) has_integral I) (cbox (Re a) (Re b)) \<longleftrightarrow>
eberlm@68721
  1544
          ((\<lambda>x. f (a + b * of_real x - a * of_real x)) has_integral I /\<^sub>R (Re b - Re a)) {0..1}"
eberlm@68721
  1545
    by (subst has_integral_affinity_iff [of "Re b - Re a" _ "Re a", symmetric])
eberlm@68721
  1546
       (insert assms, simp_all add: field_simps scaleR_conv_of_real)
eberlm@68721
  1547
  also have "(\<lambda>x. f (a + b * of_real x - a * of_real x)) =
eberlm@68721
  1548
               (\<lambda>x. (f (a + b * of_real x - a * of_real x) * (b - a)) /\<^sub>R (Re b - Re a))"
eberlm@68721
  1549
    using \<open>a \<noteq> b\<close> by (auto simp: field_simps fun_eq_iff scaleR_conv_of_real)
eberlm@68721
  1550
  also have "(\<dots> has_integral I /\<^sub>R (Re b - Re a)) {0..1} \<longleftrightarrow> 
eberlm@68721
  1551
               ((\<lambda>x. f (linepath a b x) * (b - a)) has_integral I) {0..1}" using assms
eberlm@68721
  1552
    by (subst has_integral_cmul_iff) (auto simp: linepath_def scaleR_conv_of_real algebra_simps)
eberlm@68721
  1553
  also have "\<dots> \<longleftrightarrow> (f has_contour_integral I) (linepath a b)" unfolding has_contour_integral_def
eberlm@68721
  1554
    by (intro has_integral_cong) (simp add: vector_derivative_linepath_within)
eberlm@68721
  1555
  finally show ?thesis by simp
eberlm@68721
  1556
qed
eberlm@68721
  1557
eberlm@68721
  1558
lemma contour_integrable_linepath_Reals_iff:
eberlm@68721
  1559
  fixes a b :: complex and f :: "complex \<Rightarrow> complex"
eberlm@68721
  1560
  assumes "a \<in> Reals" "b \<in> Reals" "Re a < Re b"
eberlm@68721
  1561
  shows   "(f contour_integrable_on linepath a b) \<longleftrightarrow>
eberlm@68721
  1562
             (\<lambda>x. f (of_real x)) integrable_on {Re a..Re b}"
eberlm@68721
  1563
  using has_contour_integral_linepath_Reals_iff[OF assms, of f]
eberlm@68721
  1564
  by (auto simp: contour_integrable_on_def integrable_on_def)
eberlm@68721
  1565
eberlm@68721
  1566
lemma contour_integral_linepath_Reals_eq:
eberlm@68721
  1567
  fixes a b :: complex and f :: "complex \<Rightarrow> complex"
eberlm@68721
  1568
  assumes "a \<in> Reals" "b \<in> Reals" "Re a < Re b"
eberlm@68721
  1569
  shows   "contour_integral (linepath a b) f = integral {Re a..Re b} (\<lambda>x. f (of_real x))"
eberlm@68721
  1570
proof (cases "f contour_integrable_on linepath a b")
eberlm@68721
  1571
  case True
eberlm@68721
  1572
  thus ?thesis using has_contour_integral_linepath_Reals_iff[OF assms, of f]
eberlm@68721
  1573
    using has_contour_integral_integral has_contour_integral_unique by blast
eberlm@68721
  1574
next
eberlm@68721
  1575
  case False
eberlm@68721
  1576
  thus ?thesis using contour_integrable_linepath_Reals_iff[OF assms, of f]
eberlm@68721
  1577
    by (simp add: not_integrable_contour_integral not_integrable_integral)
eberlm@68721
  1578
qed
eberlm@68721
  1579
eberlm@68721
  1580
lp15@60809
  1581
lp15@60809
  1582
text\<open>Cauchy's theorem where there's a primitive\<close>
lp15@60809
  1583
lp15@61738
  1584
lemma contour_integral_primitive_lemma:
lp15@60809
  1585
  fixes f :: "complex \<Rightarrow> complex" and g :: "real \<Rightarrow> complex"
lp15@60809
  1586
  assumes "a \<le> b"
lp15@60809
  1587
      and "\<And>x. x \<in> s \<Longrightarrow> (f has_field_derivative f' x) (at x within s)"
lp15@60809
  1588
      and "g piecewise_differentiable_on {a..b}"  "\<And>x. x \<in> {a..b} \<Longrightarrow> g x \<in> s"
lp15@60809
  1589
    shows "((\<lambda>x. f'(g x) * vector_derivative g (at x within {a..b}))
lp15@60809
  1590
             has_integral (f(g b) - f(g a))) {a..b}"
lp15@60809
  1591
proof -
lp15@61190
  1592
  obtain k where k: "finite k" "\<forall>x\<in>{a..b} - k. g differentiable (at x within {a..b})" and cg: "continuous_on {a..b} g"
lp15@60809
  1593
    using assms by (auto simp: piecewise_differentiable_on_def)
lp15@60809
  1594
  have cfg: "continuous_on {a..b} (\<lambda>x. f (g x))"
lp15@60809
  1595
    apply (rule continuous_on_compose [OF cg, unfolded o_def])
lp15@60809
  1596
    using assms
lp15@62534
  1597
    apply (metis field_differentiable_def field_differentiable_imp_continuous_at continuous_on_eq_continuous_within continuous_on_subset image_subset_iff)
lp15@60809
  1598
    done
lp15@60809
  1599
  { fix x::real
lp15@60809
  1600
    assume a: "a < x" and b: "x < b" and xk: "x \<notin> k"
lp15@60809
  1601
    then have "g differentiable at x within {a..b}"
lp15@60809
  1602
      using k by (simp add: differentiable_at_withinI)
lp15@60809
  1603
    then have "(g has_vector_derivative vector_derivative g (at x within {a..b})) (at x within {a..b})"
lp15@60809
  1604
      by (simp add: vector_derivative_works has_field_derivative_def scaleR_conv_of_real)
lp15@60809
  1605
    then have gdiff: "(g has_derivative (\<lambda>u. u * vector_derivative g (at x within {a..b}))) (at x within {a..b})"
lp15@60809
  1606
      by (simp add: has_vector_derivative_def scaleR_conv_of_real)
lp15@60809
  1607
    have "(f has_field_derivative (f' (g x))) (at (g x) within g ` {a..b})"
lp15@60809
  1608
      using assms by (metis a atLeastAtMost_iff b DERIV_subset image_subset_iff less_eq_real_def)
nipkow@69064
  1609
    then have fdiff: "(f has_derivative (*) (f' (g x))) (at (g x) within g ` {a..b})"
lp15@60809
  1610
      by (simp add: has_field_derivative_def)
lp15@60809
  1611
    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})"
lp15@60809
  1612
      using diff_chain_within [OF gdiff fdiff]
lp15@60809
  1613
      by (simp add: has_vector_derivative_def scaleR_conv_of_real o_def mult_ac)
lp15@60809
  1614
  } note * = this
lp15@60809
  1615
  show ?thesis
lp15@60809
  1616
    apply (rule fundamental_theorem_of_calculus_interior_strong)
lp15@60809
  1617
    using k assms cfg *
lp15@66793
  1618
    apply (auto simp: at_within_Icc_at)
lp15@60809
  1619
    done
lp15@60809
  1620
qed
lp15@60809
  1621
lp15@61738
  1622
lemma contour_integral_primitive:
lp15@60809
  1623
  assumes "\<And>x. x \<in> s \<Longrightarrow> (f has_field_derivative f' x) (at x within s)"
lp15@60809
  1624
      and "valid_path g" "path_image g \<subseteq> s"
lp15@61738
  1625
    shows "(f' has_contour_integral (f(pathfinish g) - f(pathstart g))) g"
lp15@60809
  1626
  using assms
lp15@61738
  1627
  apply (simp add: valid_path_def path_image_def pathfinish_def pathstart_def has_contour_integral_def)
lp15@61738
  1628
  apply (auto intro!: piecewise_C1_imp_differentiable contour_integral_primitive_lemma [of 0 1 s])
lp15@60809
  1629
  done
lp15@60809
  1630
lp15@60809
  1631
corollary Cauchy_theorem_primitive:
lp15@60809
  1632
  assumes "\<And>x. x \<in> s \<Longrightarrow> (f has_field_derivative f' x) (at x within s)"
lp15@60809
  1633
      and "valid_path g"  "path_image g \<subseteq> s" "pathfinish g = pathstart g"
lp15@61738
  1634
    shows "(f' has_contour_integral 0) g"
lp15@60809
  1635
  using assms
lp15@61738
  1636
  by (metis diff_self contour_integral_primitive)
lp15@60809
  1637
lp15@60809
  1638
text\<open>Existence of path integral for continuous function\<close>
lp15@61738
  1639
lemma contour_integrable_continuous_linepath:
lp15@60809
  1640
  assumes "continuous_on (closed_segment a b) f"
lp15@61738
  1641
  shows "f contour_integrable_on (linepath a b)"
lp15@60809
  1642
proof -
lp15@68339
  1643
  have "continuous_on {0..1} ((\<lambda>x. f x * (b - a)) \<circ> linepath a b)"
lp15@60809
  1644
    apply (rule continuous_on_compose [OF continuous_on_linepath], simp add: linepath_image_01)
lp15@60809
  1645
    apply (rule continuous_intros | simp add: assms)+
lp15@60809
  1646
    done
lp15@60809
  1647
  then show ?thesis
lp15@61738
  1648
    apply (simp add: contour_integrable_on_def has_contour_integral_def integrable_on_def [symmetric])
lp15@60809
  1649
    apply (rule integrable_continuous [of 0 "1::real", simplified])
lp15@60809
  1650
    apply (rule continuous_on_eq [where f = "\<lambda>x. f(linepath a b x)*(b - a)"])
lp15@60809
  1651
    apply (auto simp: vector_derivative_linepath_within)
lp15@60809
  1652
    done
lp15@60809
  1653
qed
lp15@60809
  1654
lp15@60809
  1655
lemma has_field_der_id: "((\<lambda>x. x\<^sup>2 / 2) has_field_derivative x) (at x)"
lp15@60809
  1656
  by (rule has_derivative_imp_has_field_derivative)
lp15@60809
  1657
     (rule derivative_intros | simp)+
lp15@60809
  1658
lp15@61738
  1659
lemma contour_integral_id [simp]: "contour_integral (linepath a b) (\<lambda>y. y) = (b^2 - a^2)/2"
lp15@61738
  1660
  apply (rule contour_integral_unique)
lp15@61738
  1661
  using contour_integral_primitive [of UNIV "\<lambda>x. x^2/2" "\<lambda>x. x" "linepath a b"]
lp15@60809
  1662
  apply (auto simp: field_simps has_field_der_id)
lp15@60809
  1663
  done
lp15@60809
  1664
lp15@61738
  1665
lemma contour_integrable_on_const [iff]: "(\<lambda>x. c) contour_integrable_on (linepath a b)"
lp15@61738
  1666
  by (simp add: continuous_on_const contour_integrable_continuous_linepath)
lp15@61738
  1667
lp15@61738
  1668
lemma contour_integrable_on_id [iff]: "(\<lambda>x. x) contour_integrable_on (linepath a b)"
lp15@61738
  1669
  by (simp add: continuous_on_id contour_integrable_continuous_linepath)
lp15@60809
  1670
wl302@69423
  1671
subsection%unimportant \<open>Arithmetical combining theorems\<close>
lp15@60809
  1672
lp15@61738
  1673
lemma has_contour_integral_neg:
lp15@61738
  1674
    "(f has_contour_integral i) g \<Longrightarrow> ((\<lambda>x. -(f x)) has_contour_integral (-i)) g"
lp15@61738
  1675
  by (simp add: has_integral_neg has_contour_integral_def)
lp15@61738
  1676
lp15@61738
  1677
lemma has_contour_integral_add:
lp15@61738
  1678
    "\<lbrakk>(f1 has_contour_integral i1) g; (f2 has_contour_integral i2) g\<rbrakk>
lp15@61738
  1679
     \<Longrightarrow> ((\<lambda>x. f1 x + f2 x) has_contour_integral (i1 + i2)) g"
lp15@61738
  1680
  by (simp add: has_integral_add has_contour_integral_def algebra_simps)
lp15@61738
  1681
lp15@61738
  1682
lemma has_contour_integral_diff:
lp15@61738
  1683
  "\<lbrakk>(f1 has_contour_integral i1) g; (f2 has_contour_integral i2) g\<rbrakk>
lp15@61738
  1684
         \<Longrightarrow> ((\<lambda>x. f1 x - f2 x) has_contour_integral (i1 - i2)) g"
lp15@66112
  1685
  by (simp add: has_integral_diff has_contour_integral_def algebra_simps)
lp15@61738
  1686
lp15@61738
  1687
lemma has_contour_integral_lmul:
lp15@61738
  1688
  "(f has_contour_integral i) g \<Longrightarrow> ((\<lambda>x. c * (f x)) has_contour_integral (c*i)) g"
lp15@61738
  1689
apply (simp add: has_contour_integral_def)
lp15@60809
  1690
apply (drule has_integral_mult_right)
lp15@60809
  1691
apply (simp add: algebra_simps)
lp15@60809
  1692
done
lp15@60809
  1693
lp15@61738
  1694
lemma has_contour_integral_rmul:
lp15@61738
  1695
  "(f has_contour_integral i) g \<Longrightarrow> ((\<lambda>x. (f x) * c) has_contour_integral (i*c)) g"
lp15@61738
  1696
apply (drule has_contour_integral_lmul)
lp15@60809
  1697
apply (simp add: mult.commute)
lp15@60809
  1698
done
lp15@60809
  1699
lp15@61738
  1700
lemma has_contour_integral_div:
lp15@61738
  1701
  "(f has_contour_integral i) g \<Longrightarrow> ((\<lambda>x. f x/c) has_contour_integral (i/c)) g"
lp15@61738
  1702
  by (simp add: field_class.field_divide_inverse) (metis has_contour_integral_rmul)
lp15@61738
  1703
lp15@61738
  1704
lemma has_contour_integral_eq:
lp15@61738
  1705
    "\<lbrakk>(f has_contour_integral y) p; \<And>x. x \<in> path_image p \<Longrightarrow> f x = g x\<rbrakk> \<Longrightarrow> (g has_contour_integral y) p"
lp15@61738
  1706
apply (simp add: path_image_def has_contour_integral_def)
lp15@60809
  1707
by (metis (no_types, lifting) image_eqI has_integral_eq)
lp15@60809
  1708
lp15@61738
  1709
lemma has_contour_integral_bound_linepath:
lp15@61738
  1710
  assumes "(f has_contour_integral i) (linepath a b)"
lp15@60809
  1711
          "0 \<le> B" "\<And>x. x \<in> closed_segment a b \<Longrightarrow> norm(f x) \<le> B"
lp15@60809
  1712
    shows "norm i \<le> B * norm(b - a)"
lp15@60809
  1713
proof -
lp15@60809
  1714
  { fix x::real
lp15@60809
  1715
    assume x: "0 \<le> x" "x \<le> 1"
lp15@60809
  1716
  have "norm (f (linepath a b x)) *
lp15@60809
  1717
        norm (vector_derivative (linepath a b) (at x within {0..1})) \<le> B * norm (b - a)"
lp15@60809
  1718
    by (auto intro: mult_mono simp: assms linepath_in_path of_real_linepath vector_derivative_linepath_within x)
lp15@60809
  1719
  } note * = this
lp15@60809
  1720
  have "norm i \<le> (B * norm (b - a)) * content (cbox 0 (1::real))"
lp15@60809
  1721
    apply (rule has_integral_bound
lp15@60809
  1722
       [of _ "\<lambda>x. f (linepath a b x) * vector_derivative (linepath a b) (at x within {0..1})"])
lp15@61738
  1723
    using assms * unfolding has_contour_integral_def
lp15@60809
  1724
    apply (auto simp: norm_mult)
lp15@60809
  1725
    done
lp15@60809
  1726
  then show ?thesis
lp15@60809
  1727
    by (auto simp: content_real)
lp15@60809
  1728
qed
lp15@60809
  1729
lp15@60809
  1730
(*UNUSED
lp15@61738
  1731
lemma has_contour_integral_bound_linepath_strong:
lp15@60809
  1732
  fixes a :: real and f :: "complex \<Rightarrow> real"
lp15@61738
  1733
  assumes "(f has_contour_integral i) (linepath a b)"
lp15@60809
  1734
          "finite k"
lp15@60809
  1735
          "0 \<le> B" "\<And>x::real. x \<in> closed_segment a b - k \<Longrightarrow> norm(f x) \<le> B"
lp15@60809
  1736
    shows "norm i \<le> B*norm(b - a)"
lp15@60809
  1737
*)
lp15@60809
  1738
lp15@61738
  1739
lemma has_contour_integral_const_linepath: "((\<lambda>x. c) has_contour_integral c*(b - a))(linepath a b)"
lp15@61738
  1740
  unfolding has_contour_integral_linepath
lp15@60809
  1741
  by (metis content_real diff_0_right has_integral_const_real lambda_one of_real_1 scaleR_conv_of_real zero_le_one)
lp15@60809
  1742
lp15@61738
  1743
lemma has_contour_integral_0: "((\<lambda>x. 0) has_contour_integral 0) g"
lp15@61738
  1744
  by (simp add: has_contour_integral_def)
lp15@61738
  1745
lp15@61738
  1746
lemma has_contour_integral_is_0:
lp15@61738
  1747
    "(\<And>z. z \<in> path_image g \<Longrightarrow> f z = 0) \<Longrightarrow> (f has_contour_integral 0) g"
lp15@61738
  1748
  by (rule has_contour_integral_eq [OF has_contour_integral_0]) auto
lp15@61738
  1749
nipkow@64267
  1750
lemma has_contour_integral_sum:
lp15@61738
  1751
    "\<lbrakk>finite s; \<And>a. a \<in> s \<Longrightarrow> (f a has_contour_integral i a) p\<rbrakk>
nipkow@64267
  1752
     \<Longrightarrow> ((\<lambda>x. sum (\<lambda>a. f a x) s) has_contour_integral sum i s) p"
lp15@61738
  1753
  by (induction s rule: finite_induct) (auto simp: has_contour_integral_0 has_contour_integral_add)
lp15@60809
  1754
wl302@69423
  1755
subsection%unimportant \<open>Operations on path integrals\<close>
lp15@60809
  1756
lp15@61738
  1757
lemma contour_integral_const_linepath [simp]: "contour_integral (linepath a b) (\<lambda>x. c) = c*(b - a)"
lp15@61738
  1758
  by (rule contour_integral_unique [OF has_contour_integral_const_linepath])
lp15@61738
  1759
lp15@61738
  1760
lemma contour_integral_neg:
lp15@61738
  1761
    "f contour_integrable_on g \<Longrightarrow> contour_integral g (\<lambda>x. -(f x)) = -(contour_integral g f)"
lp15@61738
  1762
  by (simp add: contour_integral_unique has_contour_integral_integral has_contour_integral_neg)
lp15@61738
  1763
lp15@61738
  1764
lemma contour_integral_add:
lp15@61738
  1765
    "f1 contour_integrable_on g \<Longrightarrow> f2 contour_integrable_on g \<Longrightarrow> contour_integral g (\<lambda>x. f1 x + f2 x) =
lp15@61738
  1766
                contour_integral g f1 + contour_integral g f2"
lp15@61738
  1767
  by (simp add: contour_integral_unique has_contour_integral_integral has_contour_integral_add)
lp15@61738
  1768
lp15@61738
  1769
lemma contour_integral_diff:
lp15@61738
  1770
    "f1 contour_integrable_on g \<Longrightarrow> f2 contour_integrable_on g \<Longrightarrow> contour_integral g (\<lambda>x. f1 x - f2 x) =
lp15@61738
  1771
                contour_integral g f1 - contour_integral g f2"
lp15@61738
  1772
  by (simp add: contour_integral_unique has_contour_integral_integral has_contour_integral_diff)
lp15@61738
  1773
lp15@61738
  1774
lemma contour_integral_lmul:
lp15@61738
  1775
  shows "f contour_integrable_on g
lp15@61738
  1776
           \<Longrightarrow> contour_integral g (\<lambda>x. c * f x) = c*contour_integral g f"
lp15@61738
  1777
  by (simp add: contour_integral_unique has_contour_integral_integral has_contour_integral_lmul)
lp15@61738
  1778
lp15@61738
  1779
lemma contour_integral_rmul:
lp15@61738
  1780
  shows "f contour_integrable_on g
lp15@61738
  1781
        \<Longrightarrow> contour_integral g (\<lambda>x. f x * c) = contour_integral g f * c"
lp15@61738
  1782
  by (simp add: contour_integral_unique has_contour_integral_integral has_contour_integral_rmul)
lp15@61738
  1783
lp15@61738
  1784
lemma contour_integral_div:
lp15@61738
  1785
  shows "f contour_integrable_on g
lp15@61738
  1786
        \<Longrightarrow> contour_integral g (\<lambda>x. f x / c) = contour_integral g f / c"
lp15@61738
  1787
  by (simp add: contour_integral_unique has_contour_integral_integral has_contour_integral_div)
lp15@61738
  1788
lp15@61738
  1789
lemma contour_integral_eq:
lp15@61738
  1790
    "(\<And>x. x \<in> path_image p \<Longrightarrow> f x = g x) \<Longrightarrow> contour_integral p f = contour_integral p g"
lp15@62463
  1791
  apply (simp add: contour_integral_def)
lp15@62463
  1792
  using has_contour_integral_eq
lp15@62463
  1793
  by (metis contour_integral_unique has_contour_integral_integrable has_contour_integral_integral)
lp15@61738
  1794
lp15@61738
  1795
lemma contour_integral_eq_0:
lp15@61738
  1796
    "(\<And>z. z \<in> path_image g \<Longrightarrow> f z = 0) \<Longrightarrow> contour_integral g f = 0"
lp15@61738
  1797
  by (simp add: has_contour_integral_is_0 contour_integral_unique)
lp15@61738
  1798
lp15@61738
  1799
lemma contour_integral_bound_linepath:
lp15@60809
  1800
  shows
lp15@61738
  1801
    "\<lbrakk>f contour_integrable_on (linepath a b);
lp15@60809
  1802
      0 \<le> B; \<And>x. x \<in> closed_segment a b \<Longrightarrow> norm(f x) \<le> B\<rbrakk>
lp15@61738
  1803
     \<Longrightarrow> norm(contour_integral (linepath a b) f) \<le> B*norm(b - a)"
lp15@61738
  1804
  apply (rule has_contour_integral_bound_linepath [of f])
lp15@61738
  1805
  apply (auto simp: has_contour_integral_integral)
lp15@60809
  1806
  done
lp15@60809
  1807
lp15@61806
  1808
lemma contour_integral_0 [simp]: "contour_integral g (\<lambda>x. 0) = 0"
lp15@61738
  1809
  by (simp add: contour_integral_unique has_contour_integral_0)
lp15@61738
  1810
nipkow@64267
  1811
lemma contour_integral_sum:
lp15@61738
  1812
    "\<lbrakk>finite s; \<And>a. a \<in> s \<Longrightarrow> (f a) contour_integrable_on p\<rbrakk>
nipkow@64267
  1813
     \<Longrightarrow> contour_integral p (\<lambda>x. sum (\<lambda>a. f a x) s) = sum (\<lambda>a. contour_integral p (f a)) s"
nipkow@64267
  1814
  by (auto simp: contour_integral_unique has_contour_integral_sum has_contour_integral_integral)
lp15@61738
  1815
lp15@61738
  1816
lemma contour_integrable_eq:
lp15@61738
  1817
    "\<lbrakk>f contour_integrable_on p; \<And>x. x \<in> path_image p \<Longrightarrow> f x = g x\<rbrakk> \<Longrightarrow> g contour_integrable_on p"
lp15@61738
  1818
  unfolding contour_integrable_on_def
lp15@61738
  1819
  by (metis has_contour_integral_eq)
lp15@60809
  1820
lp15@60809
  1821
wl302@69423
  1822
subsection%unimportant \<open>Arithmetic theorems for path integrability\<close>
lp15@60809
  1823
lp15@61738
  1824
lemma contour_integrable_neg:
lp15@61738
  1825
    "f contour_integrable_on g \<Longrightarrow> (\<lambda>x. -(f x)) contour_integrable_on g"
lp15@61738
  1826
  using has_contour_integral_neg contour_integrable_on_def by blast
lp15@61738
  1827
lp15@61738
  1828
lemma contour_integrable_add:
lp15@61738
  1829
    "\<lbrakk>f1 contour_integrable_on g; f2 contour_integrable_on g\<rbrakk> \<Longrightarrow> (\<lambda>x. f1 x + f2 x) contour_integrable_on g"
lp15@61738
  1830
  using has_contour_integral_add contour_integrable_on_def
lp15@60809
  1831
  by fastforce
lp15@60809
  1832
lp15@61738
  1833
lemma contour_integrable_diff:
lp15@61738
  1834
    "\<lbrakk>f1 contour_integrable_on g; f2 contour_integrable_on g\<rbrakk> \<Longrightarrow> (\<lambda>x. f1 x - f2 x) contour_integrable_on g"
lp15@61738
  1835
  using has_contour_integral_diff contour_integrable_on_def
lp15@60809
  1836
  by fastforce
lp15@60809
  1837
lp15@61738
  1838
lemma contour_integrable_lmul:
lp15@61738
  1839
    "f contour_integrable_on g \<Longrightarrow> (\<lambda>x. c * f x) contour_integrable_on g"
lp15@61738
  1840
  using has_contour_integral_lmul contour_integrable_on_def
lp15@60809
  1841
  by fastforce
lp15@60809
  1842
lp15@61738
  1843
lemma contour_integrable_rmul:
lp15@61738
  1844
    "f contour_integrable_on g \<Longrightarrow> (\<lambda>x. f x * c) contour_integrable_on g"
lp15@61738
  1845
  using has_contour_integral_rmul contour_integrable_on_def
lp15@60809
  1846
  by fastforce
lp15@60809
  1847
lp15@61738
  1848
lemma contour_integrable_div:
lp15@61738
  1849
    "f contour_integrable_on g \<Longrightarrow> (\<lambda>x. f x / c) contour_integrable_on g"
lp15@61738
  1850
  using has_contour_integral_div contour_integrable_on_def
lp15@60809
  1851
  by fastforce
lp15@60809
  1852
nipkow@64267
  1853
lemma contour_integrable_sum:
lp15@61738
  1854
    "\<lbrakk>finite s; \<And>a. a \<in> s \<Longrightarrow> (f a) contour_integrable_on p\<rbrakk>
nipkow@64267
  1855
     \<Longrightarrow> (\<lambda>x. sum (\<lambda>a. f a x) s) contour_integrable_on p"
lp15@61738
  1856
   unfolding contour_integrable_on_def
nipkow@64267
  1857
   by (metis has_contour_integral_sum)
lp15@60809
  1858
lp15@60809
  1859
wl302@69423
  1860
subsection%unimportant \<open>Reversing a path integral\<close>
lp15@60809
  1861
lp15@61738
  1862
lemma has_contour_integral_reverse_linepath:
lp15@61738
  1863
    "(f has_contour_integral i) (linepath a b)
lp15@61738
  1864
     \<Longrightarrow> (f has_contour_integral (-i)) (linepath b a)"
lp15@61738
  1865
  using has_contour_integral_reversepath valid_path_linepath by fastforce
lp15@61738
  1866
lp15@61738
  1867
lemma contour_integral_reverse_linepath:
lp15@60809
  1868
    "continuous_on (closed_segment a b) f
lp15@61738
  1869
     \<Longrightarrow> contour_integral (linepath a b) f = - (contour_integral(linepath b a) f)"
lp15@61738
  1870
apply (rule contour_integral_unique)
lp15@61738
  1871
apply (rule has_contour_integral_reverse_linepath)
lp15@61738
  1872
by (simp add: closed_segment_commute contour_integrable_continuous_linepath has_contour_integral_integral)
lp15@60809
  1873
lp15@60809
  1874
lp15@60809
  1875
(* Splitting a path integral in a flat way.*)
lp15@60809
  1876
lp15@61738
  1877
lemma has_contour_integral_split:
lp15@61738
  1878
  assumes f: "(f has_contour_integral i) (linepath a c)" "(f has_contour_integral j) (linepath c b)"
lp15@60809
  1879
      and k: "0 \<le> k" "k \<le> 1"
lp15@60809
  1880
      and c: "c - a = k *\<^sub>R (b - a)"
lp15@61738
  1881
    shows "(f has_contour_integral (i + j)) (linepath a b)"
lp15@60809
  1882
proof (cases "k = 0 \<or> k = 1")
lp15@60809
  1883
  case True
lp15@60809
  1884
  then show ?thesis
lp15@68296
  1885
    using assms by auto
lp15@60809
  1886
next
lp15@60809
  1887
  case False
lp15@60809
  1888
  then have k: "0 < k" "k < 1" "complex_of_real k \<noteq> 1"
lp15@65578
  1889
    using assms by auto
lp15@60809
  1890
  have c': "c = k *\<^sub>R (b - a) + a"
lp15@60809
  1891
    by (metis diff_add_cancel c)
lp15@60809
  1892
  have bc: "(b - c) = (1 - k) *\<^sub>R (b - a)"
lp15@60809
  1893
    by (simp add: algebra_simps c')
lp15@60809
  1894
  { assume *: "((\<lambda>x. f ((1 - x) *\<^sub>R a + x *\<^sub>R c) * (c - a)) has_integral i) {0..1}"
lp15@60809
  1895
    have **: "\<And>x. ((k - x) / k) *\<^sub>R a + (x / k) *\<^sub>R c = (1 - x) *\<^sub>R a + x *\<^sub>R b"
lp15@68302
  1896
      using False apply (simp add: c' algebra_simps)
lp15@60809
  1897
      apply (simp add: real_vector.scale_left_distrib [symmetric] divide_simps)
lp15@60809
  1898
      done
lp15@60809
  1899
    have "((\<lambda>x. f ((1 - x) *\<^sub>R a + x *\<^sub>R b) * (b - a)) has_integral i) {0..k}"
lp15@68296
  1900
      using k has_integral_affinity01 [OF *, of "inverse k" "0"]
lp15@68296
  1901
      apply (simp add: divide_simps mult.commute [of _ "k"] image_affinity_atLeastAtMost ** c)
lp15@68296
  1902
      apply (auto dest: has_integral_cmul [where c = "inverse k"])
lp15@60809
  1903
      done
lp15@60809
  1904
  } note fi = this
lp15@60809
  1905
  { assume *: "((\<lambda>x. f ((1 - x) *\<^sub>R c + x *\<^sub>R b) * (b - c)) has_integral j) {0..1}"
lp15@60809
  1906
    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)"
lp15@60809
  1907
      using k
lp15@60809
  1908
      apply (simp add: c' field_simps)
lp15@60809
  1909
      apply (simp add: scaleR_conv_of_real divide_simps)
lp15@60809
  1910
      apply (simp add: field_simps)
lp15@60809
  1911
      done
lp15@60809
  1912
    have "((\<lambda>x. f ((1 - x) *\<^sub>R a + x *\<^sub>R b) * (b - a)) has_integral j) {k..1}"
lp15@68296
  1913
      using k has_integral_affinity01 [OF *, of "inverse(1 - k)" "-(k/(1 - k))"]
lp15@68296
  1914
      apply (simp add: divide_simps mult.commute [of _ "1-k"] image_affinity_atLeastAtMost ** bc)
lp15@68296
  1915
      apply (auto dest: has_integral_cmul [where k = "(1 - k) *\<^sub>R j" and c = "inverse (1 - k)"])
lp15@60809
  1916
      done
lp15@60809
  1917
  } note fj = this
lp15@60809
  1918
  show ?thesis
lp15@60809
  1919
    using f k
lp15@61738
  1920
    apply (simp add: has_contour_integral_linepath)
lp15@60809
  1921
    apply (simp add: linepath_def)
lp15@60809
  1922
    apply (rule has_integral_combine [OF _ _ fi fj], simp_all)
lp15@60809
  1923
    done
lp15@60809
  1924
qed
lp15@60809
  1925
lp15@60809
  1926
lemma continuous_on_closed_segment_transform:
lp15@60809
  1927
  assumes f: "continuous_on (closed_segment a b) f"
lp15@60809
  1928
      and k: "0 \<le> k" "k \<le> 1"
lp15@60809
  1929
      and c: "c - a = k *\<^sub>R (b - a)"
lp15@60809
  1930
    shows "continuous_on (closed_segment a c) f"
lp15@60809
  1931
proof -
lp15@60809
  1932
  have c': "c = (1 - k) *\<^sub>R a + k *\<^sub>R b"
lp15@60809
  1933
    using c by (simp add: algebra_simps)
lp15@68302
  1934
  have "closed_segment a c \<subseteq> closed_segment a b"
lp15@68302
  1935
    by (metis c' ends_in_segment(1) in_segment(1) k subset_closed_segment)
lp15@68302
  1936
  then show "continuous_on (closed_segment a c) f"
lp15@68302
  1937
    by (rule continuous_on_subset [OF f])
lp15@60809
  1938
qed
lp15@60809
  1939
lp15@61738
  1940
lemma contour_integral_split:
lp15@60809
  1941
  assumes f: "continuous_on (closed_segment a b) f"
lp15@60809
  1942
      and k: "0 \<le> k" "k \<le> 1"
lp15@60809
  1943
      and c: "c - a = k *\<^sub>R (b - a)"
lp15@61738
  1944
    shows "contour_integral(linepath a b) f = contour_integral(linepath a c) f + contour_integral(linepath c b) f"
lp15@60809
  1945
proof -
lp15@60809
  1946
  have c': "c = (1 - k) *\<^sub>R a + k *\<^sub>R b"
lp15@60809
  1947
    using c by (simp add: algebra_simps)
lp15@68302
  1948
  have "closed_segment a c \<subseteq> closed_segment a b"
lp15@68302
  1949
    by (metis c' ends_in_segment(1) in_segment(1) k subset_closed_segment)
lp15@68302
  1950
  moreover have "closed_segment c b \<subseteq> closed_segment a b"
lp15@68302
  1951
    by (metis c' ends_in_segment(2) in_segment(1) k subset_closed_segment)
lp15@68302
  1952
  ultimately
lp15@60809
  1953
  have *: "continuous_on (closed_segment a c) f" "continuous_on (closed_segment c b) f"
lp15@68302
  1954
    by (auto intro: continuous_on_subset [OF f])
lp15@60809
  1955
  show ?thesis
lp15@68302
  1956
    by (rule contour_integral_unique) (meson "*" c contour_integrable_continuous_linepath has_contour_integral_integral has_contour_integral_split k)
lp15@60809
  1957
qed
lp15@60809
  1958
lp15@61738
  1959
lemma contour_integral_split_linepath:
lp15@60809
  1960
  assumes f: "continuous_on (closed_segment a b) f"
lp15@60809
  1961
      and c: "c \<in> closed_segment a b"
lp15@61738
  1962
    shows "contour_integral(linepath a b) f = contour_integral(linepath a c) f + contour_integral(linepath c b) f"
lp15@68302
  1963
  using c by (auto simp: closed_segment_def algebra_simps intro!: contour_integral_split [OF f])
lp15@60809
  1964
lp15@68296
  1965
text\<open>The special case of midpoints used in the main quadrisection\<close>
lp15@60809
  1966
lp15@61738
  1967
lemma has_contour_integral_midpoint:
lp15@61738
  1968
  assumes "(f has_contour_integral i) (linepath a (midpoint a b))"
lp15@61738
  1969
          "(f has_contour_integral j) (linepath (midpoint a b) b)"
lp15@61738
  1970
    shows "(f has_contour_integral (i + j)) (linepath a b)"
lp15@61738
  1971
  apply (rule has_contour_integral_split [where c = "midpoint a b" and k = "1/2"])
lp15@60809
  1972
  using assms
lp15@60809
  1973
  apply (auto simp: midpoint_def algebra_simps scaleR_conv_of_real)
lp15@60809
  1974
  done
lp15@60809
  1975
lp15@61738
  1976
lemma contour_integral_midpoint:
lp15@60809
  1977
   "continuous_on (closed_segment a b) f
lp15@61738
  1978
    \<Longrightarrow> contour_integral (linepath a b) f =
lp15@61738
  1979
        contour_integral (linepath a (midpoint a b)) f + contour_integral (linepath (midpoint a b) b) f"
lp15@61738
  1980
  apply (rule contour_integral_split [where c = "midpoint a b" and k = "1/2"])
lp15@60809
  1981
  apply (auto simp: midpoint_def algebra_simps scaleR_conv_of_real)
lp15@60809
  1982
  done
lp15@60809
  1983
lp15@60809
  1984
lp15@60809
  1985
text\<open>A couple of special case lemmas that are useful below\<close>
lp15@60809
  1986
lp15@60809
  1987
lemma triangle_linear_has_chain_integral:
lp15@61738
  1988
    "((\<lambda>x. m*x + d) has_contour_integral 0) (linepath a b +++ linepath b c +++ linepath c a)"
lp15@60809
  1989
  apply (rule Cauchy_theorem_primitive [of UNIV "\<lambda>x. m/2 * x^2 + d*x"])
lp15@60809
  1990
  apply (auto intro!: derivative_eq_intros)
lp15@60809
  1991
  done
lp15@60809
  1992
lp15@60809
  1993
lemma has_chain_integral_chain_integral3:
lp15@61738
  1994
     "(f has_contour_integral i) (linepath a b +++ linepath b c +++ linepath c d)
lp15@61738
  1995
      \<Longrightarrow> contour_integral (linepath a b) f + contour_integral (linepath b c) f + contour_integral (linepath c d) f = i"
lp15@61738
  1996
  apply (subst contour_integral_unique [symmetric], assumption)
lp15@61738
  1997
  apply (drule has_contour_integral_integrable)
lp15@60809
  1998
  apply (simp add: valid_path_join)
lp15@60809
  1999
  done
lp15@60809
  2000
lp15@62397
  2001
lemma has_chain_integral_chain_integral4:
lp15@62397
  2002
     "(f has_contour_integral i) (linepath a b +++ linepath b c +++ linepath c d +++ linepath d e)
lp15@62397
  2003
      \<Longrightarrow> contour_integral (linepath a b) f + contour_integral (linepath b c) f + contour_integral (linepath c d) f + contour_integral (linepath d e) f = i"
lp15@62397
  2004
  apply (subst contour_integral_unique [symmetric], assumption)
lp15@62397
  2005
  apply (drule has_contour_integral_integrable)
lp15@62397
  2006
  apply (simp add: valid_path_join)
lp15@62397
  2007
  done
lp15@62397
  2008
lp15@60809
  2009
subsection\<open>Reversing the order in a double path integral\<close>
lp15@60809
  2010
lp15@60809
  2011
text\<open>The condition is stronger than needed but it's often true in typical situations\<close>
lp15@60809
  2012
lp15@60809
  2013
lemma fst_im_cbox [simp]: "cbox c d \<noteq> {} \<Longrightarrow> (fst ` cbox (a,c) (b,d)) = cbox a b"
lp15@60809
  2014
  by (auto simp: cbox_Pair_eq)
lp15@60809
  2015
lp15@60809
  2016
lemma snd_im_cbox [simp]: "cbox a b \<noteq> {} \<Longrightarrow> (snd ` cbox (a,c) (b,d)) = cbox c d"
lp15@60809
  2017
  by (auto simp: cbox_Pair_eq)
lp15@60809
  2018
wl302@69423
  2019
proposition contour_integral_swap:
lp15@60809
  2020
  assumes fcon:  "continuous_on (path_image g \<times> path_image h) (\<lambda>(y1,y2). f y1 y2)"
lp15@60809
  2021
      and vp:    "valid_path g" "valid_path h"
lp15@60809
  2022
      and gvcon: "continuous_on {0..1} (\<lambda>t. vector_derivative g (at t))"
lp15@60809
  2023
      and hvcon: "continuous_on {0..1} (\<lambda>t. vector_derivative h (at t))"
lp15@61738
  2024
  shows "contour_integral g (\<lambda>w. contour_integral h (f w)) =
lp15@61738
  2025
         contour_integral h (\<lambda>z. contour_integral g (\<lambda>w. f w z))"
lp15@60809
  2026
proof -
lp15@60809
  2027
  have gcon: "continuous_on {0..1} g" and hcon: "continuous_on {0..1} h"
lp15@61190
  2028
    using assms by (auto simp: valid_path_def piecewise_C1_differentiable_on_def)
lp15@68339
  2029
  have fgh1: "\<And>x. (\<lambda>t. f (g x) (h t)) = (\<lambda>(y1,y2). f y1 y2) \<circ> (\<lambda>t. (g x, h t))"
lp15@60809
  2030
    by (rule ext) simp
lp15@68339
  2031
  have fgh2: "\<And>x. (\<lambda>t. f (g t) (h x)) = (\<lambda>(y1,y2). f y1 y2) \<circ> (\<lambda>t. (g t, h x))"
lp15@60809
  2032
    by (rule ext) simp
lp15@60809
  2033
  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)"
lp15@60809
  2034
    by (rule continuous_on_subset [OF fcon]) (auto simp: path_image_def)
lp15@60809
  2035
  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)"
lp15@60809
  2036
    by (rule continuous_on_subset [OF fcon]) (auto simp: path_image_def)
lp15@68302
  2037
  have "\<And>y. y \<in> {0..1} \<Longrightarrow> continuous_on {0..1} (\<lambda>x. f (g x) (h y))"
lp15@68302
  2038
    by (subst fgh2) (rule fcon_im2 gcon continuous_intros | simp)+
lp15@68302
  2039
  then 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}"
lp15@68302
  2040
    using continuous_on_mult gvcon integrable_continuous_real by blast
lp15@68339
  2041
  have "(\<lambda>z. vector_derivative g (at (fst z))) = (\<lambda>x. vector_derivative g (at x)) \<circ> fst"
lp15@60809
  2042
    by auto
lp15@60809
  2043
  then have gvcon': "continuous_on (cbox (0, 0) (1, 1::real)) (\<lambda>x. vector_derivative g (at (fst x)))"
lp15@60809
  2044
    apply (rule ssubst)
lp15@60809
  2045
    apply (rule continuous_intros | simp add: gvcon)+
lp15@60809
  2046
    done
lp15@68339
  2047
  have "(\<lambda>z. vector_derivative h (at (snd z))) = (\<lambda>x. vector_derivative h (at x)) \<circ> snd"
lp15@60809
  2048
    by auto
lp15@60809
  2049
  then have hvcon': "continuous_on (cbox (0, 0) (1::real, 1)) (\<lambda>x. vector_derivative h (at (snd x)))"
lp15@60809
  2050
    apply (rule ssubst)
lp15@60809
  2051
    apply (rule continuous_intros | simp add: hvcon)+
lp15@60809
  2052
    done
lp15@68339
  2053
  have "(\<lambda>x. f (g (fst x)) (h (snd x))) = (\<lambda>(y1,y2). f y1 y2) \<circ> (\<lambda>w. ((g \<circ> fst) w, (h \<circ> snd) w))"
lp15@60809
  2054
    by auto
lp15@60809
  2055
  then have fgh: "continuous_on (cbox (0, 0) (1, 1)) (\<lambda>x. f (g (fst x)) (h (snd x)))"
lp15@60809
  2056
    apply (rule ssubst)
lp15@60809
  2057
    apply (rule gcon hcon continuous_intros | simp)+
lp15@60809
  2058
    apply (auto simp: path_image_def intro: continuous_on_subset [OF fcon])
lp15@60809
  2059
    done
lp15@61738
  2060
  have "integral {0..1} (\<lambda>x. contour_integral h (f (g x)) * vector_derivative g (at x)) =
lp15@61738
  2061
        integral {0..1} (\<lambda>x. contour_integral h (\<lambda>y. f (g x) y * vector_derivative g (at x)))"
lp15@68302
  2062
  proof (rule integral_cong [OF contour_integral_rmul [symmetric]])
lp15@68302
  2063
    show "\<And>x. x \<in> {0..1} \<Longrightarrow> f (g x) contour_integrable_on h"
lp15@68302
  2064
      unfolding contour_integrable_on
lp15@60809
  2065
    apply (rule integrable_continuous_real)
lp15@60809
  2066
    apply (rule continuous_on_mult [OF _ hvcon])
lp15@60809
  2067
    apply (subst fgh1)
lp15@60809
  2068
    apply (rule fcon_im1 hcon continuous_intros | simp)+
lp15@68302
  2069
      done
lp15@68302
  2070
  qed
lp15@68339
  2071
  also have "\<dots> = integral {0..1}
lp15@61738
  2072
                     (\<lambda>y. contour_integral g (\<lambda>x. f x (h y) * vector_derivative h (at y)))"
lp15@68302
  2073
    unfolding contour_integral_integral
lp15@60809
  2074
    apply (subst integral_swap_continuous [where 'a = real and 'b = real, of 0 0 1 1, simplified])
lp15@62463
  2075
     apply (rule fgh gvcon' hvcon' continuous_intros | simp add: split_def)+
lp15@62463
  2076
    unfolding integral_mult_left [symmetric]
lp15@62463
  2077
    apply (simp only: mult_ac)
lp15@60809
  2078
    done
lp15@68339
  2079
  also have "\<dots> = contour_integral h (\<lambda>z. contour_integral g (\<lambda>w. f w z))"
lp15@68302
  2080
    unfolding contour_integral_integral
lp15@60809
  2081
    apply (rule integral_cong)
lp15@62463
  2082
    unfolding integral_mult_left [symmetric]
lp15@60809
  2083
    apply (simp add: algebra_simps)
lp15@60809
  2084
    done
lp15@60809
  2085
  finally show ?thesis
lp15@61738
  2086
    by (simp add: contour_integral_integral)
lp15@60809
  2087
qed
lp15@60809
  2088
lp15@60809
  2089
wl302@69423
  2090
subsection%unimportant \<open>The key quadrisection step\<close>
lp15@60809
  2091
lp15@60809
  2092
lemma norm_sum_half:
lp15@68302
  2093
  assumes "norm(a + b) \<ge> e"
lp15@68302
  2094
    shows "norm a \<ge> e/2 \<or> norm b \<ge> e/2"
lp15@60809
  2095
proof -
lp15@60809
  2096
  have "e \<le> norm (- a - b)"
lp15@60809
  2097
    by (simp add: add.commute assms norm_minus_commute)
lp15@60809
  2098
  thus ?thesis
lp15@60809
  2099
    using norm_triangle_ineq4 order_trans by fastforce
lp15@60809
  2100
qed
lp15@60809
  2101
lp15@60809
  2102
lemma norm_sum_lemma:
lp15@60809
  2103
  assumes "e \<le> norm (a + b + c + d)"
lp15@60809
  2104
    shows "e / 4 \<le> norm a \<or> e / 4 \<le> norm b \<or> e / 4 \<le> norm c \<or> e / 4 \<le> norm d"
lp15@60809
  2105
proof -
lp15@60809
  2106
  have "e \<le> norm ((a + b) + (c + d))" using assms
lp15@60809
  2107
    by (simp add: algebra_simps)
lp15@60809
  2108
  then show ?thesis
lp15@60809
  2109
    by (auto dest!: norm_sum_half)
lp15@60809
  2110
qed
lp15@60809
  2111
lp15@60809
  2112
lemma Cauchy_theorem_quadrisection:
lp15@60809
  2113
  assumes f: "continuous_on (convex hull {a,b,c}) f"
lp15@60809
  2114
      and dist: "dist a b \<le> K" "dist b c \<le> K" "dist c a \<le> K"
lp15@60809
  2115
      and e: "e * K^2 \<le>
lp15@61738
  2116
              norm (contour_integral(linepath a b) f + contour_integral(linepath b c) f + contour_integral(linepath c a) f)"
lp15@60809
  2117
  shows "\<exists>a' b' c'.
lp15@60809
  2118
           a' \<in> convex hull {a,b,c} \<and> b' \<in> convex hull {a,b,c} \<and> c' \<in> convex hull {a,b,c} \<and>
lp15@60809
  2119
           dist a' b' \<le> K/2  \<and>  dist b' c' \<le> K/2  \<and>  dist c' a' \<le> K/2  \<and>
lp15@61738
  2120
           e * (K/2)^2 \<le> norm(contour_integral(linepath a' b') f + contour_integral(linepath b' c') f + contour_integral(linepath c' a') f)"
lp15@68302
  2121
         (is "\<exists>x y z. ?\<Phi> x y z")
lp15@60809
  2122
proof -
lp15@60809
  2123
  note divide_le_eq_numeral1 [simp del]
wenzelm@63040
  2124
  define a' where "a' = midpoint b c"
wenzelm@63040
  2125
  define b' where "b' = midpoint c a"
wenzelm@63040
  2126
  define c' where "c' = midpoint a b"
lp15@60809
  2127
  have fabc: "continuous_on (closed_segment a b) f" "continuous_on (closed_segment b c) f" "continuous_on (closed_segment c a) f"
lp15@60809
  2128
    using f continuous_on_subset segments_subset_convex_hull by metis+
lp15@60809
  2129
  have fcont': "continuous_on (closed_segment c' b') f"
lp15@60809
  2130
               "continuous_on (closed_segment a' c') f"
lp15@60809
  2131
               "continuous_on (closed_segment b' a') f"
lp15@60809
  2132
    unfolding a'_def b'_def c'_def
lp15@68302
  2133
    by (rule continuous_on_subset [OF f],
lp15@60809
  2134
           metis midpoints_in_convex_hull convex_hull_subset hull_subset insert_subset segment_convex_hull)+
lp15@61738
  2135
  let ?pathint = "\<lambda>x y. contour_integral(linepath x y) f"
lp15@60809
  2136
  have *: "?pathint a b + ?pathint b c + ?pathint c a =
lp15@60809
  2137
          (?pathint a c' + ?pathint c' b' + ?pathint b' a) +
lp15@60809
  2138
          (?pathint a' c' + ?pathint c' b + ?pathint b a') +
lp15@60809
  2139
          (?pathint a' c + ?pathint c b' + ?pathint b' a') +
lp15@60809
  2140
          (?pathint a' b' + ?pathint b' c' + ?pathint c' a')"
lp15@68302
  2141
    by (simp add: fcont' contour_integral_reverse_linepath) (simp add: a'_def b'_def c'_def contour_integral_midpoint fabc)
lp15@60809
  2142
  have [simp]: "\<And>x y. cmod (x * 2 - y * 2) = cmod (x - y) * 2"
lp15@60809
  2143
    by (metis left_diff_distrib mult.commute norm_mult_numeral1)
lp15@60809
  2144
  have [simp]: "\<And>x y. cmod (x - y) = cmod (y - x)"
lp15@60809
  2145
    by (simp add: norm_minus_commute)
lp15@60809
  2146
  consider "e * K\<^sup>2 / 4 \<le> cmod (?pathint a c' + ?pathint c' b' + ?pathint b' a)" |
lp15@60809
  2147
           "e * K\<^sup>2 / 4 \<le> cmod (?pathint a' c' + ?pathint c' b + ?pathint b a')" |
lp15@60809
  2148
           "e * K\<^sup>2 / 4 \<le> cmod (?pathint a' c + ?pathint c b' + ?pathint b' a')" |
lp15@60809
  2149
           "e * K\<^sup>2 / 4 \<le> cmod (?pathint a' b' + ?pathint b' c' + ?pathint c' a')"
lp15@68302
  2150
    using assms unfolding * by (blast intro: that dest!: norm_sum_lemma)
lp15@60809
  2151
  then show ?thesis
lp15@60809
  2152
  proof cases
lp15@68302
  2153
    case 1 then have "?\<Phi> a c' b'"
lp15@60809
  2154
      using assms
lp15@68302
  2155
      apply (clarsimp simp: c'_def b'_def midpoints_in_convex_hull hull_subset [THEN subsetD])
lp15@68302
  2156
      apply (auto simp: midpoint_def dist_norm scaleR_conv_of_real divide_simps)
lp15@68302
  2157
      done
lp15@68302
  2158
    then show ?thesis by blast
lp15@68302
  2159
  next
lp15@68302
  2160
    case 2 then  have "?\<Phi> a' c' b"
lp15@68302
  2161
      using assms
lp15@68302
  2162
      apply (clarsimp simp: a'_def c'_def midpoints_in_convex_hull hull_subset [THEN subsetD])
lp15@60809
  2163
      apply (auto simp: midpoint_def dist_norm scaleR_conv_of_real divide_simps)
lp15@60809
  2164
      done
lp15@68302
  2165
    then show ?thesis by blast
lp15@60809
  2166
  next
lp15@68302
  2167
    case 3 then have "?\<Phi> a' c b'"
lp15@60809
  2168
      using assms
lp15@68302
  2169
      apply (clarsimp simp: a'_def b'_def midpoints_in_convex_hull hull_subset [THEN subsetD])
lp15@60809
  2170
      apply (auto simp: midpoint_def dist_norm scaleR_conv_of_real divide_simps)
lp15@60809
  2171
      done
lp15@68302
  2172
    then show ?thesis by blast
lp15@60809
  2173
  next
lp15@68302
  2174
    case 4 then have "?\<Phi> a' b' c'"
lp15@60809
  2175
      using assms
lp15@68302
  2176
      apply (clarsimp simp: a'_def c'_def b'_def midpoints_in_convex_hull hull_subset [THEN subsetD])
lp15@60809
  2177
      apply (auto simp: midpoint_def dist_norm scaleR_conv_of_real divide_simps)
lp15@60809
  2178
      done
lp15@68302
  2179
    then show ?thesis by blast
lp15@60809
  2180
  qed
lp15@60809
  2181
qed
lp15@60809
  2182
wl302@69423
  2183
subsection%unimportant \<open>Cauchy's theorem for triangles\<close>
lp15@60809
  2184
lp15@60809
  2185
lemma triangle_points_closer:
lp15@60809
  2186
  fixes a::complex
lp15@60809
  2187
  shows "\<lbrakk>x \<in> convex hull {a,b,c};  y \<in> convex hull {a,b,c}\<rbrakk>
lp15@60809
  2188
         \<Longrightarrow> norm(x - y) \<le> norm(a - b) \<or>
lp15@60809
  2189
             norm(x - y) \<le> norm(b - c) \<or>
lp15@60809
  2190
             norm(x - y) \<le> norm(c - a)"
lp15@60809
  2191
  using simplex_extremal_le [of "{a,b,c}"]
lp15@60809
  2192
  by (auto simp: norm_minus_commute)
lp15@60809
  2193
lp15@60809
  2194
lemma holomorphic_point_small_triangle:
lp15@68302
  2195
  assumes x: "x \<in> S"
lp15@68302
  2196
      and f: "continuous_on S f"
lp15@68302
  2197
      and cd: "f field_differentiable (at x within S)"
lp15@60809
  2198
      and e: "0 < e"
lp15@60809
  2199
    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>
lp15@68302
  2200
              x \<in> convex hull {a,b,c} \<and> convex hull {a,b,c} \<subseteq> S
lp15@61738
  2201
              \<longrightarrow> norm(contour_integral(linepath a b) f + contour_integral(linepath b c) f +
lp15@61738
  2202
                       contour_integral(linepath c a) f)
lp15@60809
  2203
                  \<le> e*(dist a b + dist b c + dist c a)^2"
lp15@60809
  2204
           (is "\<exists>k>0. \<forall>a b c. _ \<longrightarrow> ?normle a b c")
lp15@60809
  2205
proof -
lp15@60809
  2206
  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>
lp15@60809
  2207
                     \<Longrightarrow> a \<le> e*(x + y + z)^2"
lp15@60809
  2208
    by (simp add: algebra_simps power2_eq_square)
lp15@60809
  2209
  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"
lp15@60809
  2210
             for x::real and a b c
lp15@60809
  2211
    by linarith
lp15@61738
  2212
  have fabc: "f contour_integrable_on linepath a b" "f contour_integrable_on linepath b c" "f contour_integrable_on linepath c a"
lp15@68302
  2213
              if "convex hull {a, b, c} \<subseteq> S" for a b c
lp15@60809
  2214
    using segments_subset_convex_hull that
lp15@61738
  2215
    by (metis continuous_on_subset f contour_integrable_continuous_linepath)+
lp15@61738
  2216
  note path_bound = has_contour_integral_bound_linepath [simplified norm_minus_commute, OF has_contour_integral_integral]
lp15@60809
  2217
  { fix f' a b c d
lp15@60809
  2218
    assume d: "0 < d"
lp15@68302
  2219
       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)"
lp15@60809
  2220
       and le: "cmod (a - b) \<le> d" "cmod (b - c) \<le> d" "cmod (c - a) \<le> d"
lp15@60809
  2221
       and xc: "x \<in> convex hull {a, b, c}"
lp15@68302
  2222
       and S: "convex hull {a, b, c} \<subseteq> S"
lp15@61738
  2223
    have pa: "contour_integral (linepath a b) f + contour_integral (linepath b c) f + contour_integral (linepath c a) f =
lp15@61738
  2224
              contour_integral (linepath a b) (\<lambda>y. f y - f x - f'*(y - x)) +
lp15@61738
  2225
              contour_integral (linepath b c) (\<lambda>y. f y - f x - f'*(y - x)) +
lp15@61738
  2226
              contour_integral (linepath c a) (\<lambda>y. f y - f x - f'*(y - x))"
lp15@68302
  2227
      apply (simp add: contour_integral_diff contour_integral_lmul contour_integrable_lmul contour_integrable_diff fabc [OF S])
lp15@60809
  2228
      apply (simp add: field_simps)
lp15@60809
  2229
      done
lp15@60809
  2230
    { fix y
lp15@60809
  2231
      assume yc: "y \<in> convex hull {a,b,c}"
lp15@60809
  2232
      have "cmod (f y - f x - f' * (y - x)) \<le> e*norm(y - x)"
lp15@68302
  2233
      proof (rule f')
lp15@68302
  2234
        show "cmod (y - x) \<le> d"
lp15@68302
  2235
          by (metis triangle_points_closer [OF xc yc] le norm_minus_commute order_trans)
lp15@68302
  2236
      qed (use S yc in blast)
lp15@68339
  2237
      also have "\<dots> \<le> e * (cmod (a - b) + cmod (b - c) + cmod (c - a))"
lp15@60809
  2238
        by (simp add: yc e xc disj_le [OF triangle_points_closer])
lp15@60809
  2239
      finally have "cmod (f y - f x - f' * (y - x)) \<le> e * (cmod (a - b) + cmod (b - c) + cmod (c - a))" .
lp15@60809
  2240
    } note cm_le = this
lp15@60809
  2241
    have "?normle a b c"
lp15@68302
  2242
      unfolding dist_norm pa
lp15@60809
  2243
      apply (rule le_of_3)
lp15@68302
  2244
      using f' xc S e
lp15@60809
  2245
      apply simp_all
lp15@60809
  2246
      apply (intro norm_triangle_le add_mono path_bound)
lp15@61738
  2247
      apply (simp_all add: contour_integral_diff contour_integral_lmul contour_integrable_lmul contour_integrable_diff fabc)
lp15@60809
  2248
      apply (blast intro: cm_le elim: dest: segments_subset_convex_hull [THEN subsetD])+
lp15@60809
  2249
      done
lp15@60809
  2250
  } note * = this
lp15@60809
  2251
  show ?thesis
lp15@68493
  2252
    using cd e