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