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