tidying and reorganisation around Cauchy Integral Theorem
authorpaulson <lp15@cam.ac.uk>
Sat May 26 22:11:55 2018 +0100 (12 months ago)
changeset 6829669d680e94961
parent 68286 b9160ca067ae
child 68297 e033ccc418ad
tidying and reorganisation around Cauchy Integral Theorem
src/HOL/Analysis/Brouwer_Fixpoint.thy
src/HOL/Analysis/Cauchy_Integral_Theorem.thy
src/HOL/Analysis/Complex_Analysis_Basics.thy
src/HOL/Analysis/Path_Connected.thy
src/HOL/Limits.thy
src/HOL/Topological_Spaces.thy
     1.1 --- a/src/HOL/Analysis/Brouwer_Fixpoint.thy	Sat May 26 10:11:11 2018 +0100
     1.2 +++ b/src/HOL/Analysis/Brouwer_Fixpoint.thy	Sat May 26 22:11:55 2018 +0100
     1.3 @@ -2036,7 +2036,8 @@
     1.4  by (simp add: continuous_on_id retraction)
     1.5  
     1.6  lemma retract_of_refl [iff]: "S retract_of S"
     1.7 -  using continuous_on_id retract_of_def retraction_def by fastforce
     1.8 +  unfolding retract_of_def retraction_def
     1.9 +  using continuous_on_id by blast
    1.10  
    1.11  lemma retract_of_imp_subset:
    1.12     "S retract_of T \<Longrightarrow> S \<subseteq> T"
    1.13 @@ -2047,8 +2048,7 @@
    1.14  by (auto simp: retract_of_def retraction_def)
    1.15  
    1.16  lemma retract_of_singleton [iff]: "({x} retract_of S) \<longleftrightarrow> x \<in> S"
    1.17 -  using continuous_on_const
    1.18 -  by (auto simp: retract_of_def retraction_def)
    1.19 +  unfolding retract_of_def retraction_def by force
    1.20  
    1.21  lemma retraction_comp:
    1.22     "\<lbrakk>retraction S T f; retraction T U g\<rbrakk>
     2.1 --- a/src/HOL/Analysis/Cauchy_Integral_Theorem.thy	Sat May 26 10:11:11 2018 +0100
     2.2 +++ b/src/HOL/Analysis/Cauchy_Integral_Theorem.thy	Sat May 26 22:11:55 2018 +0100
     2.3 @@ -255,7 +255,7 @@
     2.4        by (simp add: \<open>finite S\<close>)
     2.5      show "g1 differentiable at x within {0..1}" if "x \<in> {0..1} - insert 1 (( * ) 2 ` S)" for x
     2.6      proof (rule_tac d="dist (x/2) (1/2)" in differentiable_transform_within)
     2.7 -      have "g1 +++ g2 differentiable at (x / 2) within {0..1 / 2}"
     2.8 +      have "g1 +++ g2 differentiable at (x / 2) within {0..1/2}"
     2.9          by (rule differentiable_subset [OF S [of "x/2"]] | use that in force)+
    2.10        then show "g1 +++ g2 \<circ> ( * ) (inverse 2) differentiable at x within {0..1}"
    2.11          by (auto intro: differentiable_chain_within)
    2.12 @@ -288,7 +288,7 @@
    2.13          by (rule differentiable_chain_within differentiable_subset [OF S [of "(x+1)/2"]] | use x2 that in force)+
    2.14        then show "g1 +++ g2 \<circ> (\<lambda>x. (x+1) / 2) differentiable at x within {0..1}"
    2.15          by (auto intro: differentiable_chain_within)
    2.16 -      show "(g1 +++ g2 \<circ> (\<lambda>x. (x + 1) / 2)) x' = g2 x'" if "x' \<in> {0..1}" "dist x' x < dist ((x + 1) / 2) (1 / 2)" for x'
    2.17 +      show "(g1 +++ g2 \<circ> (\<lambda>x. (x + 1) / 2)) x' = g2 x'" if "x' \<in> {0..1}" "dist x' x < dist ((x + 1) / 2) (1/2)" for x'
    2.18        proof -
    2.19          have [simp]: "(2*x'+2)/2 = x'+1"
    2.20            by (simp add: divide_simps)
    2.21 @@ -323,65 +323,78 @@
    2.22  definition C1_differentiable_on :: "(real \<Rightarrow> 'a::real_normed_vector) \<Rightarrow> real set \<Rightarrow> bool"
    2.23             (infix "C1'_differentiable'_on" 50)
    2.24    where
    2.25 -  "f C1_differentiable_on s \<longleftrightarrow>
    2.26 -   (\<exists>D. (\<forall>x \<in> s. (f has_vector_derivative (D x)) (at x)) \<and> continuous_on s D)"
    2.27 +  "f C1_differentiable_on S \<longleftrightarrow>
    2.28 +   (\<exists>D. (\<forall>x \<in> S. (f has_vector_derivative (D x)) (at x)) \<and> continuous_on S D)"
    2.29  
    2.30  lemma C1_differentiable_on_eq:
    2.31 -    "f C1_differentiable_on s \<longleftrightarrow>
    2.32 -     (\<forall>x \<in> s. f differentiable at x) \<and> continuous_on s (\<lambda>x. vector_derivative f (at x))"
    2.33 -  unfolding C1_differentiable_on_def
    2.34 -  apply safe
    2.35 -  using differentiable_def has_vector_derivative_def apply blast
    2.36 -  apply (erule continuous_on_eq)
    2.37 -  using vector_derivative_at apply fastforce
    2.38 -  using vector_derivative_works apply fastforce
    2.39 -  done
    2.40 +    "f C1_differentiable_on S \<longleftrightarrow>
    2.41 +     (\<forall>x \<in> S. f differentiable at x) \<and> continuous_on S (\<lambda>x. vector_derivative f (at x))"
    2.42 +     (is "?lhs = ?rhs")
    2.43 +proof
    2.44 +  assume ?lhs
    2.45 +  then show ?rhs
    2.46 +    unfolding C1_differentiable_on_def
    2.47 +    by (metis (no_types, lifting) continuous_on_eq  differentiableI_vector vector_derivative_at)
    2.48 +next
    2.49 +  assume ?rhs
    2.50 +  then show ?lhs
    2.51 +    using C1_differentiable_on_def vector_derivative_works by fastforce
    2.52 +qed
    2.53  
    2.54  lemma C1_differentiable_on_subset:
    2.55 -  "f C1_differentiable_on t \<Longrightarrow> s \<subseteq> t \<Longrightarrow> f C1_differentiable_on s"
    2.56 +  "f C1_differentiable_on T \<Longrightarrow> S \<subseteq> T \<Longrightarrow> f C1_differentiable_on S"
    2.57    unfolding C1_differentiable_on_def  continuous_on_eq_continuous_within
    2.58    by (blast intro:  continuous_within_subset)
    2.59  
    2.60  lemma C1_differentiable_compose:
    2.61 -    "\<lbrakk>f C1_differentiable_on s; g C1_differentiable_on (f ` s);
    2.62 -      \<And>x. finite (s \<inter> f-`{x})\<rbrakk>
    2.63 -      \<Longrightarrow> (g o f) C1_differentiable_on s"
    2.64 -  apply (simp add: C1_differentiable_on_eq, safe)
    2.65 -   using differentiable_chain_at apply blast
    2.66 -  apply (rule continuous_on_eq [of _ "\<lambda>x. vector_derivative f (at x) *\<^sub>R vector_derivative g (at (f x))"])
    2.67 -   apply (rule Limits.continuous_on_scaleR, assumption)
    2.68 -   apply (metis (mono_tags, lifting) continuous_on_eq continuous_at_imp_continuous_on continuous_on_compose differentiable_imp_continuous_within o_def)
    2.69 -  by (simp add: vector_derivative_chain_at)
    2.70 -
    2.71 -lemma C1_diff_imp_diff: "f C1_differentiable_on s \<Longrightarrow> f differentiable_on s"
    2.72 +  assumes fg: "f C1_differentiable_on S" "g C1_differentiable_on (f ` S)" and fin: "\<And>x. finite (S \<inter> f-`{x})"
    2.73 +  shows "(g o f) C1_differentiable_on S"
    2.74 +proof -
    2.75 +  have "\<And>x. x \<in> S \<Longrightarrow> g \<circ> f differentiable at x"
    2.76 +    by (meson C1_differentiable_on_eq assms differentiable_chain_at imageI)
    2.77 +  moreover have "continuous_on S (\<lambda>x. vector_derivative (g \<circ> f) (at x))"
    2.78 +  proof (rule continuous_on_eq [of _ "\<lambda>x. vector_derivative f (at x) *\<^sub>R vector_derivative g (at (f x))"])
    2.79 +    show "continuous_on S (\<lambda>x. vector_derivative f (at x) *\<^sub>R vector_derivative g (at (f x)))"
    2.80 +      using fg
    2.81 +      apply (clarsimp simp add: C1_differentiable_on_eq)
    2.82 +      apply (rule Limits.continuous_on_scaleR, assumption)
    2.83 +      by (metis (mono_tags, lifting) continuous_at_imp_continuous_on continuous_on_compose continuous_on_cong differentiable_imp_continuous_within o_def)
    2.84 +    show "\<And>x. x \<in> S \<Longrightarrow> vector_derivative f (at x) *\<^sub>R vector_derivative g (at (f x)) = vector_derivative (g \<circ> f) (at x)"
    2.85 +      by (metis (mono_tags, hide_lams) C1_differentiable_on_eq fg imageI vector_derivative_chain_at)
    2.86 +  qed
    2.87 +  ultimately show ?thesis
    2.88 +    by (simp add: C1_differentiable_on_eq)
    2.89 +qed
    2.90 +
    2.91 +lemma C1_diff_imp_diff: "f C1_differentiable_on S \<Longrightarrow> f differentiable_on S"
    2.92    by (simp add: C1_differentiable_on_eq differentiable_at_imp_differentiable_on)
    2.93  
    2.94 -lemma C1_differentiable_on_ident [simp, derivative_intros]: "(\<lambda>x. x) C1_differentiable_on s"
    2.95 +lemma C1_differentiable_on_ident [simp, derivative_intros]: "(\<lambda>x. x) C1_differentiable_on S"
    2.96    by (auto simp: C1_differentiable_on_eq continuous_on_const)
    2.97  
    2.98 -lemma C1_differentiable_on_const [simp, derivative_intros]: "(\<lambda>z. a) C1_differentiable_on s"
    2.99 +lemma C1_differentiable_on_const [simp, derivative_intros]: "(\<lambda>z. a) C1_differentiable_on S"
   2.100    by (auto simp: C1_differentiable_on_eq continuous_on_const)
   2.101  
   2.102  lemma C1_differentiable_on_add [simp, derivative_intros]:
   2.103 -  "f C1_differentiable_on s \<Longrightarrow> g C1_differentiable_on s \<Longrightarrow> (\<lambda>x. f x + g x) C1_differentiable_on s"
   2.104 +  "f C1_differentiable_on S \<Longrightarrow> g C1_differentiable_on S \<Longrightarrow> (\<lambda>x. f x + g x) C1_differentiable_on S"
   2.105    unfolding C1_differentiable_on_eq  by (auto intro: continuous_intros)
   2.106  
   2.107  lemma C1_differentiable_on_minus [simp, derivative_intros]:
   2.108 -  "f C1_differentiable_on s \<Longrightarrow> (\<lambda>x. - f x) C1_differentiable_on s"
   2.109 +  "f C1_differentiable_on S \<Longrightarrow> (\<lambda>x. - f x) C1_differentiable_on S"
   2.110    unfolding C1_differentiable_on_eq  by (auto intro: continuous_intros)
   2.111  
   2.112  lemma C1_differentiable_on_diff [simp, derivative_intros]:
   2.113 -  "f C1_differentiable_on s \<Longrightarrow> g C1_differentiable_on s \<Longrightarrow> (\<lambda>x. f x - g x) C1_differentiable_on s"
   2.114 +  "f C1_differentiable_on S \<Longrightarrow> g C1_differentiable_on S \<Longrightarrow> (\<lambda>x. f x - g x) C1_differentiable_on S"
   2.115    unfolding C1_differentiable_on_eq  by (auto intro: continuous_intros)
   2.116  
   2.117  lemma C1_differentiable_on_mult [simp, derivative_intros]:
   2.118    fixes f g :: "real \<Rightarrow> 'a :: real_normed_algebra"
   2.119 -  shows "f C1_differentiable_on s \<Longrightarrow> g C1_differentiable_on s \<Longrightarrow> (\<lambda>x. f x * g x) C1_differentiable_on s"
   2.120 +  shows "f C1_differentiable_on S \<Longrightarrow> g C1_differentiable_on S \<Longrightarrow> (\<lambda>x. f x * g x) C1_differentiable_on S"
   2.121    unfolding C1_differentiable_on_eq
   2.122    by (auto simp: continuous_on_add continuous_on_mult continuous_at_imp_continuous_on differentiable_imp_continuous_within)
   2.123  
   2.124  lemma C1_differentiable_on_scaleR [simp, derivative_intros]:
   2.125 -  "f C1_differentiable_on s \<Longrightarrow> g C1_differentiable_on s \<Longrightarrow> (\<lambda>x. f x *\<^sub>R g x) C1_differentiable_on s"
   2.126 +  "f C1_differentiable_on S \<Longrightarrow> g C1_differentiable_on S \<Longrightarrow> (\<lambda>x. f x *\<^sub>R g x) C1_differentiable_on S"
   2.127    unfolding C1_differentiable_on_eq
   2.128    by (rule continuous_intros | simp add: continuous_at_imp_continuous_on differentiable_imp_continuous_within)+
   2.129  
   2.130 @@ -390,10 +403,10 @@
   2.131             (infixr "piecewise'_C1'_differentiable'_on" 50)
   2.132    where "f piecewise_C1_differentiable_on i  \<equiv>
   2.133             continuous_on i f \<and>
   2.134 -           (\<exists>s. finite s \<and> (f C1_differentiable_on (i - s)))"
   2.135 +           (\<exists>S. finite S \<and> (f C1_differentiable_on (i - S)))"
   2.136  
   2.137  lemma C1_differentiable_imp_piecewise:
   2.138 -    "f C1_differentiable_on s \<Longrightarrow> f piecewise_C1_differentiable_on s"
   2.139 +    "f C1_differentiable_on S \<Longrightarrow> f piecewise_C1_differentiable_on S"
   2.140    by (auto simp: piecewise_C1_differentiable_on_def C1_differentiable_on_eq continuous_at_imp_continuous_on differentiable_imp_continuous_within)
   2.141  
   2.142  lemma piecewise_C1_imp_differentiable:
   2.143 @@ -403,25 +416,38 @@
   2.144             intro: has_derivative_at_withinI)
   2.145  
   2.146  lemma piecewise_C1_differentiable_compose:
   2.147 -    "\<lbrakk>f piecewise_C1_differentiable_on s; g piecewise_C1_differentiable_on (f ` s);
   2.148 -      \<And>x. finite (s \<inter> f-`{x})\<rbrakk>
   2.149 -      \<Longrightarrow> (g o f) piecewise_C1_differentiable_on s"
   2.150 -  apply (simp add: piecewise_C1_differentiable_on_def, safe)
   2.151 -  apply (blast intro: continuous_on_compose2)
   2.152 -  apply (rename_tac A B)
   2.153 -  apply (rule_tac x="A \<union> (\<Union>x\<in>B. s \<inter> f-`{x})" in exI)
   2.154 -  apply (rule conjI, blast)
   2.155 -  apply (rule C1_differentiable_compose)
   2.156 -  apply (blast intro: C1_differentiable_on_subset)
   2.157 -  apply (blast intro: C1_differentiable_on_subset)
   2.158 -  by (simp add: Diff_Int_distrib2)
   2.159 +  assumes fg: "f piecewise_C1_differentiable_on S" "g piecewise_C1_differentiable_on (f ` S)" and fin: "\<And>x. finite (S \<inter> f-`{x})"
   2.160 +  shows "(g o f) piecewise_C1_differentiable_on S"
   2.161 +proof -
   2.162 +  have "continuous_on S (\<lambda>x. g (f x))"
   2.163 +    by (metis continuous_on_compose2 fg order_refl piecewise_C1_differentiable_on_def)
   2.164 +  moreover have "\<exists>T. finite T \<and> g \<circ> f C1_differentiable_on S - T"
   2.165 +  proof -
   2.166 +    obtain F where "finite F" and F: "f C1_differentiable_on S - F" and f: "f piecewise_C1_differentiable_on S"
   2.167 +      using fg by (auto simp: piecewise_C1_differentiable_on_def)
   2.168 +    obtain G where "finite G" and G: "g C1_differentiable_on f ` S - G" and g: "g piecewise_C1_differentiable_on f ` S"
   2.169 +      using fg by (auto simp: piecewise_C1_differentiable_on_def)
   2.170 +    show ?thesis
   2.171 +    proof (intro exI conjI)
   2.172 +      show "finite (F \<union> (\<Union>x\<in>G. S \<inter> f-`{x}))"
   2.173 +        using fin by (auto simp only: Int_Union \<open>finite F\<close> \<open>finite G\<close> finite_UN finite_imageI)
   2.174 +      show "g \<circ> f C1_differentiable_on S - (F \<union> (\<Union>x\<in>G. S \<inter> f -` {x}))"
   2.175 +        apply (rule C1_differentiable_compose)
   2.176 +          apply (blast intro: C1_differentiable_on_subset [OF F])
   2.177 +          apply (blast intro: C1_differentiable_on_subset [OF G])
   2.178 +        by (simp add:  C1_differentiable_on_subset G Diff_Int_distrib2 fin)
   2.179 +    qed
   2.180 +  qed
   2.181 +  ultimately show ?thesis
   2.182 +    by (simp add: piecewise_C1_differentiable_on_def)
   2.183 +qed
   2.184  
   2.185  lemma piecewise_C1_differentiable_on_subset:
   2.186 -    "f piecewise_C1_differentiable_on s \<Longrightarrow> t \<le> s \<Longrightarrow> f piecewise_C1_differentiable_on t"
   2.187 +    "f piecewise_C1_differentiable_on S \<Longrightarrow> T \<le> S \<Longrightarrow> f piecewise_C1_differentiable_on T"
   2.188    by (auto simp: piecewise_C1_differentiable_on_def elim!: continuous_on_subset C1_differentiable_on_subset)
   2.189  
   2.190  lemma C1_differentiable_imp_continuous_on:
   2.191 -  "f C1_differentiable_on s \<Longrightarrow> continuous_on s f"
   2.192 +  "f C1_differentiable_on S \<Longrightarrow> continuous_on S f"
   2.193    unfolding C1_differentiable_on_eq continuous_on_eq_continuous_within
   2.194    using differentiable_at_withinI differentiable_imp_continuous_within by blast
   2.195  
   2.196 @@ -431,19 +457,19 @@
   2.197  
   2.198  lemma piecewise_C1_differentiable_affine:
   2.199    fixes m::real
   2.200 -  assumes "f piecewise_C1_differentiable_on ((\<lambda>x. m * x + c) ` s)"
   2.201 -  shows "(f o (\<lambda>x. m *\<^sub>R x + c)) piecewise_C1_differentiable_on s"
   2.202 +  assumes "f piecewise_C1_differentiable_on ((\<lambda>x. m * x + c) ` S)"
   2.203 +  shows "(f o (\<lambda>x. m *\<^sub>R x + c)) piecewise_C1_differentiable_on S"
   2.204  proof (cases "m = 0")
   2.205    case True
   2.206    then show ?thesis
   2.207      unfolding o_def by (auto simp: piecewise_C1_differentiable_on_def continuous_on_const)
   2.208  next
   2.209    case False
   2.210 +  have *: "\<And>x. finite (S \<inter> {y. m * y + c = x})"
   2.211 +    using False not_finite_existsD by fastforce 
   2.212    show ?thesis
   2.213      apply (rule piecewise_C1_differentiable_compose [OF C1_differentiable_imp_piecewise])
   2.214 -    apply (rule assms derivative_intros | simp add: False vimage_def)+
   2.215 -    using real_vector_affinity_eq [OF False, where c=c, unfolded scaleR_conv_of_real]
   2.216 -    apply simp
   2.217 +    apply (rule * assms derivative_intros | simp add: False vimage_def)+
   2.218      done
   2.219  qed
   2.220  
   2.221 @@ -454,13 +480,13 @@
   2.222             "a \<le> c" "c \<le> b" "f c = g c"
   2.223    shows "(\<lambda>x. if x \<le> c then f x else g x) piecewise_C1_differentiable_on {a..b}"
   2.224  proof -
   2.225 -  obtain s t where st: "f C1_differentiable_on ({a..c} - s)"
   2.226 -                       "g C1_differentiable_on ({c..b} - t)"
   2.227 -                       "finite s" "finite t"
   2.228 +  obtain S T where st: "f C1_differentiable_on ({a..c} - S)"
   2.229 +                       "g C1_differentiable_on ({c..b} - T)"
   2.230 +                       "finite S" "finite T"
   2.231      using assms
   2.232      by (force simp: piecewise_C1_differentiable_on_def)
   2.233 -  then have f_diff: "f differentiable_on {a..<c} - s"
   2.234 -        and g_diff: "g differentiable_on {c<..b} - t"
   2.235 +  then have f_diff: "f differentiable_on {a..<c} - S"
   2.236 +        and g_diff: "g differentiable_on {c<..b} - T"
   2.237      by (simp_all add: C1_differentiable_on_eq differentiable_at_withinI differentiable_on_def)
   2.238    have "continuous_on {a..c} f" "continuous_on {c..b} g"
   2.239      using assms piecewise_C1_differentiable_on_def by auto
   2.240 @@ -470,7 +496,7 @@
   2.241                                 of f g "\<lambda>x. x\<le>c"]  assms
   2.242      by (force simp: ivl_disj_un_two_touch)
   2.243    { fix x
   2.244 -    assume x: "x \<in> {a..b} - insert c (s \<union> t)"
   2.245 +    assume x: "x \<in> {a..b} - insert c (S \<union> T)"
   2.246      have "(\<lambda>x. if x \<le> c then f x else g x) differentiable at x" (is "?diff_fg")
   2.247      proof (cases x c rule: le_cases)
   2.248        case le show ?diff_fg
   2.249 @@ -482,48 +508,61 @@
   2.250          using dist_nz x dist_real_def ge st x by (auto simp: C1_differentiable_on_eq)
   2.251      qed
   2.252    }
   2.253 -  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)"
   2.254 +  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)"
   2.255      by auto
   2.256    moreover
   2.257 -  { assume fcon: "continuous_on ({a<..<c} - s) (\<lambda>x. vector_derivative f (at x))"
   2.258 -       and gcon: "continuous_on ({c<..<b} - t) (\<lambda>x. vector_derivative g (at x))"
   2.259 -    have "open ({a<..<c} - s)"  "open ({c<..<b} - t)"
   2.260 +  { assume fcon: "continuous_on ({a<..<c} - S) (\<lambda>x. vector_derivative f (at x))"
   2.261 +       and gcon: "continuous_on ({c<..<b} - T) (\<lambda>x. vector_derivative g (at x))"
   2.262 +    have "open ({a<..<c} - S)"  "open ({c<..<b} - T)"
   2.263        using st by (simp_all add: open_Diff finite_imp_closed)
   2.264 -    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))"
   2.265 -      apply (rule continuous_on_eq [OF fcon])
   2.266 -      apply (simp add:)
   2.267 -      apply (rule vector_derivative_at [symmetric])
   2.268 -      apply (rule_tac f=f and d="dist x c" in has_vector_derivative_transform_within)
   2.269 -      apply (simp_all add: dist_norm vector_derivative_works [symmetric])
   2.270 -      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))
   2.271 -      apply auto
   2.272 -      done
   2.273 -    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))"
   2.274 -      apply (rule continuous_on_eq [OF gcon])
   2.275 -      apply (simp add:)
   2.276 -      apply (rule vector_derivative_at [symmetric])
   2.277 -      apply (rule_tac f=g and d="dist x c" in has_vector_derivative_transform_within)
   2.278 -      apply (simp_all add: dist_norm vector_derivative_works [symmetric])
   2.279 -      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))
   2.280 -      apply auto
   2.281 -      done
   2.282 -    ultimately have "continuous_on ({a<..<b} - insert c (s \<union> t))
   2.283 +    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))"
   2.284 +    proof -
   2.285 +      have "((\<lambda>x. if x \<le> c then f x else g x) has_vector_derivative vector_derivative f (at x))            (at x)"
   2.286 +        if "a < x" "x < c" "x \<notin> S" for x
   2.287 +      proof -
   2.288 +        have f: "f differentiable at x"
   2.289 +          by (meson C1_differentiable_on_eq Diff_iff atLeastAtMost_iff less_eq_real_def st(1) that)
   2.290 +        show ?thesis
   2.291 +          using that
   2.292 +          apply (rule_tac f=f and d="dist x c" in has_vector_derivative_transform_within)
   2.293 +             apply (auto simp add: dist_norm vector_derivative_works [symmetric] f)
   2.294 +          done
   2.295 +      qed
   2.296 +      then show ?thesis
   2.297 +        by (metis (no_types, lifting) continuous_on_eq [OF fcon] DiffE greaterThanLessThan_iff vector_derivative_at)
   2.298 +    qed
   2.299 +    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))"
   2.300 +    proof -
   2.301 +      have "((\<lambda>x. if x \<le> c then f x else g x) has_vector_derivative vector_derivative g (at x))            (at x)"
   2.302 +        if "c < x" "x < b" "x \<notin> T" for x
   2.303 +      proof -
   2.304 +        have g: "g differentiable at x"
   2.305 +          by (metis C1_differentiable_on_eq DiffD1 DiffI atLeastAtMost_diff_ends greaterThanLessThan_iff st(2) that)
   2.306 +        show ?thesis
   2.307 +          using that
   2.308 +          apply (rule_tac f=g and d="dist x c" in has_vector_derivative_transform_within)
   2.309 +             apply (auto simp add: dist_norm vector_derivative_works [symmetric] g)
   2.310 +          done
   2.311 +      qed
   2.312 +      then show ?thesis
   2.313 +        by (metis (no_types, lifting) continuous_on_eq [OF gcon] DiffE greaterThanLessThan_iff vector_derivative_at)
   2.314 +    qed
   2.315 +    ultimately have "continuous_on ({a<..<b} - insert c (S \<union> T))
   2.316          (\<lambda>x. vector_derivative (\<lambda>x. if x \<le> c then f x else g x) (at x))"
   2.317 -      apply (rule continuous_on_subset [OF continuous_on_open_Un], auto)
   2.318 -      done
   2.319 +      by (rule continuous_on_subset [OF continuous_on_open_Un], auto)
   2.320    } note * = this
   2.321 -  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))"
   2.322 +  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))"
   2.323      using st
   2.324      by (auto simp: C1_differentiable_on_eq elim!: continuous_on_subset intro: *)
   2.325 -  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)"
   2.326 -    apply (rule_tac x="{a,b,c} \<union> s \<union> t" in exI)
   2.327 +  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)"
   2.328 +    apply (rule_tac x="{a,b,c} \<union> S \<union> T" in exI)
   2.329      using st  by (auto simp: C1_differentiable_on_eq elim!: continuous_on_subset)
   2.330    with cab show ?thesis
   2.331      by (simp add: piecewise_C1_differentiable_on_def)
   2.332  qed
   2.333  
   2.334  lemma piecewise_C1_differentiable_neg:
   2.335 -    "f piecewise_C1_differentiable_on s \<Longrightarrow> (\<lambda>x. -(f x)) piecewise_C1_differentiable_on s"
   2.336 +    "f piecewise_C1_differentiable_on S \<Longrightarrow> (\<lambda>x. -(f x)) piecewise_C1_differentiable_on S"
   2.337    unfolding piecewise_C1_differentiable_on_def
   2.338    by (auto intro!: continuous_on_minus C1_differentiable_on_minus)
   2.339  
   2.340 @@ -532,11 +571,11 @@
   2.341            "g piecewise_C1_differentiable_on i"
   2.342      shows "(\<lambda>x. f x + g x) piecewise_C1_differentiable_on i"
   2.343  proof -
   2.344 -  obtain s t where st: "finite s" "finite t"
   2.345 -                       "f C1_differentiable_on (i-s)"
   2.346 +  obtain S t where st: "finite S" "finite t"
   2.347 +                       "f C1_differentiable_on (i-S)"
   2.348                         "g C1_differentiable_on (i-t)"
   2.349      using assms by (auto simp: piecewise_C1_differentiable_on_def)
   2.350 -  then have "finite (s \<union> t) \<and> (\<lambda>x. f x + g x) C1_differentiable_on i - (s \<union> t)"
   2.351 +  then have "finite (S \<union> t) \<and> (\<lambda>x. f x + g x) C1_differentiable_on i - (S \<union> t)"
   2.352      by (auto intro: C1_differentiable_on_add elim!: C1_differentiable_on_subset)
   2.353    moreover have "continuous_on i f" "continuous_on i g"
   2.354      using assms piecewise_C1_differentiable_on_def by auto
   2.355 @@ -545,8 +584,8 @@
   2.356  qed
   2.357  
   2.358  lemma piecewise_C1_differentiable_diff:
   2.359 -    "\<lbrakk>f piecewise_C1_differentiable_on s;  g piecewise_C1_differentiable_on s\<rbrakk>
   2.360 -     \<Longrightarrow> (\<lambda>x. f x - g x) piecewise_C1_differentiable_on s"
   2.361 +    "\<lbrakk>f piecewise_C1_differentiable_on S;  g piecewise_C1_differentiable_on S\<rbrakk>
   2.362 +     \<Longrightarrow> (\<lambda>x. f x - g x) piecewise_C1_differentiable_on S"
   2.363    unfolding diff_conv_add_uminus
   2.364    by (metis piecewise_C1_differentiable_add piecewise_C1_differentiable_neg)
   2.365  
   2.366 @@ -555,44 +594,53 @@
   2.367    assumes "(g1 +++ g2) piecewise_C1_differentiable_on {0..1}"
   2.368      shows "g1 piecewise_C1_differentiable_on {0..1}"
   2.369  proof -
   2.370 -  obtain s where "finite s"
   2.371 -             and co12: "continuous_on ({0..1} - s) (\<lambda>x. vector_derivative (g1 +++ g2) (at x))"
   2.372 -             and g12D: "\<forall>x\<in>{0..1} - s. g1 +++ g2 differentiable at x"
   2.373 +  obtain S where "finite S"
   2.374 +             and co12: "continuous_on ({0..1} - S) (\<lambda>x. vector_derivative (g1 +++ g2) (at x))"
   2.375 +             and g12D: "\<forall>x\<in>{0..1} - S. g1 +++ g2 differentiable at x"
   2.376      using assms  by (auto simp: piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
   2.377 -  then have g1D: "g1 differentiable at x" if "x \<in> {0..1} - insert 1 (( * ) 2 ` s)" for x
   2.378 -    apply (rule_tac d="dist (x/2) (1/2)" and f = "(g1 +++ g2) o (( * )(inverse 2))" in differentiable_transform_within)
   2.379 -    using that
   2.380 -    apply (simp_all add: dist_real_def joinpaths_def)
   2.381 -    apply (rule differentiable_chain_at derivative_intros | force)+
   2.382 -    done
   2.383 +  have g1D: "g1 differentiable at x" if "x \<in> {0..1} - insert 1 (( * ) 2 ` S)" for x
   2.384 +  proof (rule differentiable_transform_within)
   2.385 +    show "g1 +++ g2 \<circ> ( * ) (inverse 2) differentiable at x"
   2.386 +      using that g12D 
   2.387 +      apply (simp only: joinpaths_def)
   2.388 +      by (rule differentiable_chain_at derivative_intros | force)+
   2.389 +    show "\<And>x'. \<lbrakk>dist x' x < dist (x/2) (1/2)\<rbrakk>
   2.390 +          \<Longrightarrow> (g1 +++ g2 \<circ> ( * ) (inverse 2)) x' = g1 x'"
   2.391 +      using that by (auto simp add: dist_real_def joinpaths_def)
   2.392 +  qed (use that in \<open>auto simp: dist_real_def\<close>)
   2.393    have [simp]: "vector_derivative (g1 \<circ> ( * ) 2) (at (x/2)) = 2 *\<^sub>R vector_derivative g1 (at x)"
   2.394 -               if "x \<in> {0..1} - insert 1 (( * ) 2 ` s)" for x
   2.395 +               if "x \<in> {0..1} - insert 1 (( * ) 2 ` S)" for x
   2.396      apply (subst vector_derivative_chain_at)
   2.397      using that
   2.398      apply (rule derivative_eq_intros g1D | simp)+
   2.399      done
   2.400 -  have "continuous_on ({0..1/2} - insert (1/2) s) (\<lambda>x. vector_derivative (g1 +++ g2) (at x))"
   2.401 +  have "continuous_on ({0..1/2} - insert (1/2) S) (\<lambda>x. vector_derivative (g1 +++ g2) (at x))"
   2.402      using co12 by (rule continuous_on_subset) force
   2.403 -  then have coDhalf: "continuous_on ({0..1/2} - insert (1/2) s) (\<lambda>x. vector_derivative (g1 o ( * )2) (at x))"
   2.404 -    apply (rule continuous_on_eq [OF _ vector_derivative_at])
   2.405 -    apply (rule_tac f="g1 o ( * )2" and d="dist x (1/2)" in has_vector_derivative_transform_within)
   2.406 -    apply (simp_all add: dist_norm joinpaths_def vector_derivative_works [symmetric])
   2.407 -    apply (force intro: g1D differentiable_chain_at)
   2.408 -    apply auto
   2.409 -    done
   2.410 -  have "continuous_on ({0..1} - insert 1 (( * ) 2 ` s))
   2.411 +  then have coDhalf: "continuous_on ({0..1/2} - insert (1/2) S) (\<lambda>x. vector_derivative (g1 o ( * )2) (at x))"
   2.412 +  proof (rule continuous_on_eq [OF _ vector_derivative_at])
   2.413 +    show "(g1 +++ g2 has_vector_derivative vector_derivative (g1 \<circ> ( * ) 2) (at x)) (at x)"
   2.414 +      if "x \<in> {0..1/2} - insert (1/2) S" for x
   2.415 +    proof (rule has_vector_derivative_transform_within)
   2.416 +      show "(g1 \<circ> ( * ) 2 has_vector_derivative vector_derivative (g1 \<circ> ( * ) 2) (at x)) (at x)"
   2.417 +        using that
   2.418 +        by (force intro: g1D differentiable_chain_at simp: vector_derivative_works [symmetric])
   2.419 +      show "\<And>x'. \<lbrakk>dist x' x < dist x (1/2)\<rbrakk> \<Longrightarrow> (g1 \<circ> ( * ) 2) x' = (g1 +++ g2) x'"
   2.420 +        using that by (auto simp: dist_norm joinpaths_def)
   2.421 +    qed (use that in \<open>auto simp: dist_norm\<close>)
   2.422 +  qed
   2.423 +  have "continuous_on ({0..1} - insert 1 (( * ) 2 ` S))
   2.424                        ((\<lambda>x. 1/2 * vector_derivative (g1 o ( * )2) (at x)) o ( * )(1/2))"
   2.425      apply (rule continuous_intros)+
   2.426      using coDhalf
   2.427      apply (simp add: scaleR_conv_of_real image_set_diff image_image)
   2.428      done
   2.429 -  then have con_g1: "continuous_on ({0..1} - insert 1 (( * ) 2 ` s)) (\<lambda>x. vector_derivative g1 (at x))"
   2.430 +  then have con_g1: "continuous_on ({0..1} - insert 1 (( * ) 2 ` S)) (\<lambda>x. vector_derivative g1 (at x))"
   2.431      by (rule continuous_on_eq) (simp add: scaleR_conv_of_real)
   2.432    have "continuous_on {0..1} g1"
   2.433      using continuous_on_joinpaths_D1 assms piecewise_C1_differentiable_on_def by blast
   2.434 -  with \<open>finite s\<close> show ?thesis
   2.435 +  with \<open>finite S\<close> show ?thesis
   2.436      apply (clarsimp simp add: piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
   2.437 -    apply (rule_tac x="insert 1 ((( * )2)`s)" in exI)
   2.438 +    apply (rule_tac x="insert 1 ((( * )2)`S)" in exI)
   2.439      apply (simp add: g1D con_g1)
   2.440    done
   2.441  qed
   2.442 @@ -602,44 +650,53 @@
   2.443    assumes "(g1 +++ g2) piecewise_C1_differentiable_on {0..1}" "pathfinish g1 = pathstart g2"
   2.444      shows "g2 piecewise_C1_differentiable_on {0..1}"
   2.445  proof -
   2.446 -  obtain s where "finite s"
   2.447 -             and co12: "continuous_on ({0..1} - s) (\<lambda>x. vector_derivative (g1 +++ g2) (at x))"
   2.448 -             and g12D: "\<forall>x\<in>{0..1} - s. g1 +++ g2 differentiable at x"
   2.449 +  obtain S where "finite S"
   2.450 +             and co12: "continuous_on ({0..1} - S) (\<lambda>x. vector_derivative (g1 +++ g2) (at x))"
   2.451 +             and g12D: "\<forall>x\<in>{0..1} - S. g1 +++ g2 differentiable at x"
   2.452      using assms  by (auto simp: piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
   2.453 -  then have g2D: "g2 differentiable at x" if "x \<in> {0..1} - insert 0 ((\<lambda>x. 2*x-1) ` s)" for x
   2.454 -    apply (rule_tac d="dist ((x+1)/2) (1/2)" and f = "(g1 +++ g2) o (\<lambda>x. (x+1)/2)" in differentiable_transform_within)
   2.455 -    using that
   2.456 -    apply (simp_all add: dist_real_def joinpaths_def)
   2.457 -    apply (auto simp: dist_real_def joinpaths_def field_simps)
   2.458 -    apply (rule differentiable_chain_at derivative_intros | force)+
   2.459 -    apply (drule_tac x= "(x+1) / 2" in bspec, force simp: divide_simps)
   2.460 -    apply assumption
   2.461 -    done
   2.462 +  have g2D: "g2 differentiable at x" if "x \<in> {0..1} - insert 0 ((\<lambda>x. 2*x-1) ` S)" for x
   2.463 +  proof (rule differentiable_transform_within)
   2.464 +    show "g1 +++ g2 \<circ> (\<lambda>x. (x + 1) / 2) differentiable at x"
   2.465 +      using g12D that
   2.466 +      apply (simp only: joinpaths_def)
   2.467 +      apply (drule_tac x= "(x+1) / 2" in bspec, force simp: divide_simps)
   2.468 +      apply (rule differentiable_chain_at derivative_intros | force)+
   2.469 +      done
   2.470 +    show "\<And>x'. dist x' x < dist ((x + 1) / 2) (1/2) \<Longrightarrow> (g1 +++ g2 \<circ> (\<lambda>x. (x + 1) / 2)) x' = g2 x'"
   2.471 +      using that by (auto simp: dist_real_def joinpaths_def field_simps)
   2.472 +    qed (use that in \<open>auto simp: dist_norm\<close>)
   2.473    have [simp]: "vector_derivative (g2 \<circ> (\<lambda>x. 2*x-1)) (at ((x+1)/2)) = 2 *\<^sub>R vector_derivative g2 (at x)"
   2.474 -               if "x \<in> {0..1} - insert 0 ((\<lambda>x. 2*x-1) ` s)" for x
   2.475 +               if "x \<in> {0..1} - insert 0 ((\<lambda>x. 2*x-1) ` S)" for x
   2.476      using that  by (auto simp: vector_derivative_chain_at divide_simps g2D)
   2.477 -  have "continuous_on ({1/2..1} - insert (1/2) s) (\<lambda>x. vector_derivative (g1 +++ g2) (at x))"
   2.478 +  have "continuous_on ({1/2..1} - insert (1/2) S) (\<lambda>x. vector_derivative (g1 +++ g2) (at x))"
   2.479      using co12 by (rule continuous_on_subset) force
   2.480 -  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))"
   2.481 -    apply (rule continuous_on_eq [OF _ vector_derivative_at])
   2.482 -    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)
   2.483 -    apply (auto simp: dist_real_def field_simps joinpaths_def vector_derivative_works [symmetric]
   2.484 -                intro!: g2D differentiable_chain_at)
   2.485 -    done
   2.486 -  have [simp]: "((\<lambda>x. (x+1) / 2) ` ({0..1} - insert 0 ((\<lambda>x. 2 * x - 1) ` s))) = ({1/2..1} - insert (1/2) s)"
   2.487 +  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))"
   2.488 +  proof (rule continuous_on_eq [OF _ vector_derivative_at])
   2.489 +    show "(g1 +++ g2 has_vector_derivative vector_derivative (g2 \<circ> (\<lambda>x. 2 * x - 1)) (at x))
   2.490 +          (at x)"
   2.491 +      if "x \<in> {1 / 2..1} - insert (1 / 2) S" for x
   2.492 +    proof (rule_tac f="g2 o (\<lambda>x. 2*x-1)" and d="dist (3/4) ((x+1)/2)" in has_vector_derivative_transform_within)
   2.493 +      show "(g2 \<circ> (\<lambda>x. 2 * x - 1) has_vector_derivative vector_derivative (g2 \<circ> (\<lambda>x. 2 * x - 1)) (at x))
   2.494 +            (at x)"
   2.495 +        using that by (force intro: g2D differentiable_chain_at simp: vector_derivative_works [symmetric])
   2.496 +      show "\<And>x'. \<lbrakk>dist x' x < dist (3 / 4) ((x + 1) / 2)\<rbrakk> \<Longrightarrow> (g2 \<circ> (\<lambda>x. 2 * x - 1)) x' = (g1 +++ g2) x'"
   2.497 +        using that by (auto simp: dist_norm joinpaths_def add_divide_distrib)
   2.498 +    qed (use that in \<open>auto simp: dist_norm\<close>)
   2.499 +  qed
   2.500 +  have [simp]: "((\<lambda>x. (x+1) / 2) ` ({0..1} - insert 0 ((\<lambda>x. 2 * x - 1) ` S))) = ({1/2..1} - insert (1/2) S)"
   2.501      apply (simp add: image_set_diff inj_on_def image_image)
   2.502      apply (auto simp: image_affinity_atLeastAtMost_div add_divide_distrib)
   2.503      done
   2.504 -  have "continuous_on ({0..1} - insert 0 ((\<lambda>x. 2*x-1) ` s))
   2.505 +  have "continuous_on ({0..1} - insert 0 ((\<lambda>x. 2*x-1) ` S))
   2.506                        ((\<lambda>x. 1/2 * vector_derivative (g2 \<circ> (\<lambda>x. 2*x-1)) (at x)) o (\<lambda>x. (x+1)/2))"
   2.507      by (rule continuous_intros | simp add:  coDhalf)+
   2.508 -  then have con_g2: "continuous_on ({0..1} - insert 0 ((\<lambda>x. 2*x-1) ` s)) (\<lambda>x. vector_derivative g2 (at x))"
   2.509 +  then have con_g2: "continuous_on ({0..1} - insert 0 ((\<lambda>x. 2*x-1) ` S)) (\<lambda>x. vector_derivative g2 (at x))"
   2.510      by (rule continuous_on_eq) (simp add: scaleR_conv_of_real)
   2.511    have "continuous_on {0..1} g2"
   2.512      using continuous_on_joinpaths_D2 assms piecewise_C1_differentiable_on_def by blast
   2.513 -  with \<open>finite s\<close> show ?thesis
   2.514 +  with \<open>finite S\<close> show ?thesis
   2.515      apply (clarsimp simp add: piecewise_C1_differentiable_on_def C1_differentiable_on_eq)
   2.516 -    apply (rule_tac x="insert 0 ((\<lambda>x. 2 * x - 1) ` s)" in exI)
   2.517 +    apply (rule_tac x="insert 0 ((\<lambda>x. 2 * x - 1) ` S)" in exI)
   2.518      apply (simp add: g2D con_g2)
   2.519    done
   2.520  qed
   2.521 @@ -675,32 +732,32 @@
   2.522        and con: "continuous_on (path_image g) (deriv f)"
   2.523      shows "valid_path (f o g)"
   2.524  proof -
   2.525 -  obtain s where "finite s" and g_diff: "g C1_differentiable_on {0..1} - s"
   2.526 +  obtain S where "finite S" and g_diff: "g C1_differentiable_on {0..1} - S"
   2.527      using \<open>valid_path g\<close> unfolding valid_path_def piecewise_C1_differentiable_on_def by auto
   2.528 -  have "f \<circ> g differentiable at t" when "t\<in>{0..1} - s" for t
   2.529 +  have "f \<circ> g differentiable at t" when "t\<in>{0..1} - S" for t
   2.530      proof (rule differentiable_chain_at)
   2.531        show "g differentiable at t" using \<open>valid_path g\<close>
   2.532 -        by (meson C1_differentiable_on_eq \<open>g C1_differentiable_on {0..1} - s\<close> that)
   2.533 +        by (meson C1_differentiable_on_eq \<open>g C1_differentiable_on {0..1} - S\<close> that)
   2.534      next
   2.535        have "g t\<in>path_image g" using that DiffD1 image_eqI path_image_def by metis
   2.536        then show "f differentiable at (g t)" 
   2.537          using der[THEN field_differentiable_imp_differentiable] by auto
   2.538      qed
   2.539 -  moreover have "continuous_on ({0..1} - s) (\<lambda>x. vector_derivative (f \<circ> g) (at x))"
   2.540 +  moreover have "continuous_on ({0..1} - S) (\<lambda>x. vector_derivative (f \<circ> g) (at x))"
   2.541      proof (rule continuous_on_eq [where f = "\<lambda>x. vector_derivative g (at x) * deriv f (g x)"],
   2.542          rule continuous_intros)
   2.543 -      show "continuous_on ({0..1} - s) (\<lambda>x. vector_derivative g (at x))"
   2.544 +      show "continuous_on ({0..1} - S) (\<lambda>x. vector_derivative g (at x))"
   2.545          using g_diff C1_differentiable_on_eq by auto
   2.546      next
   2.547        have "continuous_on {0..1} (\<lambda>x. deriv f (g x))"
   2.548          using continuous_on_compose[OF _ con[unfolded path_image_def],unfolded comp_def]
   2.549            \<open>valid_path g\<close> piecewise_C1_differentiable_on_def valid_path_def
   2.550          by blast
   2.551 -      then show "continuous_on ({0..1} - s) (\<lambda>x. deriv f (g x))"
   2.552 +      then show "continuous_on ({0..1} - S) (\<lambda>x. deriv f (g x))"
   2.553          using continuous_on_subset by blast
   2.554      next
   2.555        show "vector_derivative g (at t) * deriv f (g t) = vector_derivative (f \<circ> g) (at t)"
   2.556 -          when "t \<in> {0..1} - s" for t
   2.557 +          when "t \<in> {0..1} - S" for t
   2.558          proof (rule vector_derivative_chain_at_general[symmetric])
   2.559            show "g differentiable at t" by (meson C1_differentiable_on_eq g_diff that)
   2.560          next
   2.561 @@ -708,14 +765,14 @@
   2.562            then show "f field_differentiable at (g t)" using der by auto
   2.563          qed
   2.564      qed
   2.565 -  ultimately have "f o g C1_differentiable_on {0..1} - s"
   2.566 +  ultimately have "f o g C1_differentiable_on {0..1} - S"
   2.567      using C1_differentiable_on_eq by blast
   2.568    moreover have "path (f \<circ> g)" 
   2.569      apply (rule path_continuous_image[OF valid_path_imp_path[OF \<open>valid_path g\<close>]])
   2.570      using der
   2.571      by (simp add: continuous_at_imp_continuous_on field_differentiable_imp_continuous_at)
   2.572    ultimately show ?thesis unfolding valid_path_def piecewise_C1_differentiable_on_def path_def
   2.573 -    using \<open>finite s\<close> by auto
   2.574 +    using \<open>finite S\<close> by auto
   2.575  qed
   2.576  
   2.577  
   2.578 @@ -763,24 +820,17 @@
   2.579  lemma has_contour_integral_integrable: "(f has_contour_integral i) g \<Longrightarrow> f contour_integrable_on g"
   2.580    using contour_integrable_on_def by blast
   2.581  
   2.582 -(* Show that we can forget about the localized derivative.*)
   2.583 -
   2.584 -lemma vector_derivative_within_interior:
   2.585 -     "\<lbrakk>x \<in> interior s; NO_MATCH UNIV s\<rbrakk>
   2.586 -      \<Longrightarrow> vector_derivative f (at x within s) = vector_derivative f (at x)"
   2.587 -  apply (simp add: vector_derivative_def has_vector_derivative_def has_derivative_def netlimit_within_interior)
   2.588 -  apply (subst lim_within_interior, auto)
   2.589 -  done
   2.590 +subsubsection\<open>Show that we can forget about the localized derivative.\<close>
   2.591  
   2.592  lemma has_integral_localized_vector_derivative:
   2.593      "((\<lambda>x. f (g x) * vector_derivative g (at x within {a..b})) has_integral i) {a..b} \<longleftrightarrow>
   2.594       ((\<lambda>x. f (g x) * vector_derivative g (at x)) has_integral i) {a..b}"
   2.595  proof -
   2.596 -  have "{a..b} - {a,b} = interior {a..b}"
   2.597 +  have *: "{a..b} - {a,b} = interior {a..b}"
   2.598      by (simp add: atLeastAtMost_diff_ends)
   2.599    show ?thesis
   2.600      apply (rule has_integral_spike_eq [of "{a,b}"])
   2.601 -    apply (auto simp: vector_derivative_within_interior)
   2.602 +    apply (auto simp: at_within_interior [of _ "{a..b}"])
   2.603      done
   2.604  qed
   2.605  
   2.606 @@ -805,17 +855,16 @@
   2.607    assumes "valid_path g"
   2.608      shows "valid_path(reversepath g)"
   2.609  proof -
   2.610 -  obtain s where "finite s" "g C1_differentiable_on ({0..1} - s)"
   2.611 +  obtain S where "finite S" and S: "g C1_differentiable_on ({0..1} - S)"
   2.612      using assms by (auto simp: valid_path_def piecewise_C1_differentiable_on_def)
   2.613 -  then have "finite ((-) 1 ` s)" "(reversepath g C1_differentiable_on ({0..1} - (-) 1 ` s))"
   2.614 -    apply (auto simp: reversepath_def)
   2.615 +  then have "finite ((-) 1 ` S)"
   2.616 +    by auto
   2.617 +  moreover have "(reversepath g C1_differentiable_on ({0..1} - (-) 1 ` S))"
   2.618 +    unfolding reversepath_def
   2.619      apply (rule C1_differentiable_compose [of "\<lambda>x::real. 1-x" _ g, unfolded o_def])
   2.620 -    apply (auto simp: C1_differentiable_on_eq)
   2.621 -    apply (rule continuous_intros, force)
   2.622 -    apply (force elim!: continuous_on_subset)
   2.623 -    apply (simp add: finite_vimageI inj_on_def)
   2.624 -    done
   2.625 -  then show ?thesis using assms
   2.626 +    using S
   2.627 +    by (force simp: finite_vimageI inj_on_def C1_differentiable_on_eq continuous_on_const elim!: continuous_on_subset)+
   2.628 +  ultimately show ?thesis using assms
   2.629      by (auto simp: valid_path_def piecewise_C1_differentiable_on_def path_def [symmetric])
   2.630  qed
   2.631  
   2.632 @@ -823,38 +872,37 @@
   2.633    using valid_path_imp_reverse by force
   2.634  
   2.635  lemma has_contour_integral_reversepath:
   2.636 -  assumes "valid_path g" "(f has_contour_integral i) g"
   2.637 +  assumes "valid_path g" and f: "(f has_contour_integral i) g"
   2.638      shows "(f has_contour_integral (-i)) (reversepath g)"
   2.639  proof -
   2.640 -  { fix s x
   2.641 -    assume xs: "g C1_differentiable_on ({0..1} - s)" "x \<notin> (-) 1 ` s" "0 \<le> x" "x \<le> 1"
   2.642 -      have "vector_derivative (\<lambda>x. g (1 - x)) (at x within {0..1}) =
   2.643 +  { fix S x
   2.644 +    assume xs: "g C1_differentiable_on ({0..1} - S)" "x \<notin> (-) 1 ` S" "0 \<le> x" "x \<le> 1"
   2.645 +    have "vector_derivative (\<lambda>x. g (1 - x)) (at x within {0..1}) =
   2.646              - vector_derivative g (at (1 - x) within {0..1})"
   2.647 -      proof -
   2.648 -        obtain f' where f': "(g has_vector_derivative f') (at (1 - x))"
   2.649 -          using xs
   2.650 -          by (force simp: has_vector_derivative_def C1_differentiable_on_def)
   2.651 -        have "(g o (\<lambda>x. 1 - x) has_vector_derivative -1 *\<^sub>R f') (at x)"
   2.652 -          apply (rule vector_diff_chain_within)
   2.653 -          apply (intro vector_diff_chain_within derivative_eq_intros | simp)+
   2.654 -          apply (rule has_vector_derivative_at_within [OF f'])
   2.655 -          done
   2.656 -        then have mf': "((\<lambda>x. g (1 - x)) has_vector_derivative -f') (at x)"
   2.657 -          by (simp add: o_def)
   2.658 -        show ?thesis
   2.659 -          using xs
   2.660 -          by (auto simp: vector_derivative_at_within_ivl [OF mf'] vector_derivative_at_within_ivl [OF f'])
   2.661 -      qed
   2.662 +    proof -
   2.663 +      obtain f' where f': "(g has_vector_derivative f') (at (1 - x))"
   2.664 +        using xs
   2.665 +        by (force simp: has_vector_derivative_def C1_differentiable_on_def)
   2.666 +      have "(g o (\<lambda>x. 1 - x) has_vector_derivative -1 *\<^sub>R f') (at x)"
   2.667 +        by (intro vector_diff_chain_within has_vector_derivative_at_within [OF f'] derivative_eq_intros | simp)+
   2.668 +      then have mf': "((\<lambda>x. g (1 - x)) has_vector_derivative -f') (at x)"
   2.669 +        by (simp add: o_def)
   2.670 +      show ?thesis
   2.671 +        using xs
   2.672 +        by (auto simp: vector_derivative_at_within_ivl [OF mf'] vector_derivative_at_within_ivl [OF f'])
   2.673 +    qed
   2.674    } note * = this
   2.675 -  have 01: "{0..1::real} = cbox 0 1"
   2.676 -    by simp
   2.677 -  show ?thesis using assms
   2.678 -    apply (auto simp: has_contour_integral_def)
   2.679 -    apply (drule has_integral_affinity01 [where m= "-1" and c=1])
   2.680 -    apply (auto simp: reversepath_def valid_path_def piecewise_C1_differentiable_on_def)
   2.681 -    apply (drule has_integral_neg)
   2.682 -    apply (rule_tac S = "(\<lambda>x. 1 - x) ` s" in has_integral_spike_finite)
   2.683 -    apply (auto simp: *)
   2.684 +  obtain S where S: "continuous_on {0..1} g" "finite S" "g C1_differentiable_on {0..1} - S"
   2.685 +    using assms by (auto simp: valid_path_def piecewise_C1_differentiable_on_def)
   2.686 +  have "((\<lambda>x. - (f (g (1 - x)) * vector_derivative g (at (1 - x) within {0..1}))) has_integral -i)
   2.687 +       {0..1}"
   2.688 +    using has_integral_affinity01 [where m= "-1" and c=1, OF f [unfolded has_contour_integral_def]]
   2.689 +    by (simp add: has_integral_neg)
   2.690 +  then show ?thesis 
   2.691 +    using S
   2.692 +    apply (clarsimp simp: reversepath_def has_contour_integral_def)
   2.693 +    apply (rule_tac S = "(\<lambda>x. 1 - x) ` S" in has_integral_spike_finite)
   2.694 +      apply (auto simp: *)
   2.695      done
   2.696  qed
   2.697  
   2.698 @@ -891,7 +939,6 @@
   2.699      apply (rule piecewise_C1_differentiable_compose)
   2.700      using assms
   2.701      apply (auto simp: valid_path_def piecewise_C1_differentiable_on_def continuous_on_joinpaths)
   2.702 -    apply (rule continuous_intros | simp)+
   2.703      apply (force intro: finite_vimageI [where h = "( * )2"] inj_onI)
   2.704      done
   2.705    moreover have "(g2 o (\<lambda>x. 2*x-1)) piecewise_C1_differentiable_on {1/2..1}"
   2.706 @@ -1179,7 +1226,7 @@
   2.707                        [where f = "(shiftpath (1 - a) (shiftpath a g))" and S = "{0<..<1}-s"]])
   2.708        using s g assms x
   2.709        apply (auto simp: finite_imp_closed open_Diff shiftpath_shiftpath
   2.710 -                        vector_derivative_within_interior vector_derivative_works [symmetric])
   2.711 +                        at_within_interior [of _ "{0..1}"] vector_derivative_works [symmetric])
   2.712        apply (rule differentiable_transform_within [OF gx, of "min x (1-x)"])
   2.713        apply (auto simp: dist_real_def shiftpath_shiftpath abs_if split: if_split_asm)
   2.714        done
   2.715 @@ -1268,6 +1315,9 @@
   2.716  lemma has_contour_integral_trivial [iff]: "(f has_contour_integral 0) (linepath a a)"
   2.717    by (simp add: has_contour_integral_linepath)
   2.718  
   2.719 +lemma has_contour_integral_trivial_iff [simp]: "(f has_contour_integral i) (linepath a a) \<longleftrightarrow> i=0"
   2.720 +  using has_contour_integral_unique by blast
   2.721 +
   2.722  lemma contour_integral_trivial [simp]: "contour_integral (linepath a a) f = 0"
   2.723    using has_contour_integral_trivial contour_integral_unique by blast
   2.724  
   2.725 @@ -1738,11 +1788,7 @@
   2.726  proof (cases "k = 0 \<or> k = 1")
   2.727    case True
   2.728    then show ?thesis
   2.729 -    using assms
   2.730 -    apply auto
   2.731 -    apply (metis add.left_neutral has_contour_integral_trivial has_contour_integral_unique)
   2.732 -    apply (metis add.right_neutral has_contour_integral_trivial has_contour_integral_unique)
   2.733 -    done
   2.734 +    using assms by auto
   2.735  next
   2.736    case False
   2.737    then have k: "0 < k" "k < 1" "complex_of_real k \<noteq> 1"
   2.738 @@ -1758,12 +1804,9 @@
   2.739        apply (simp add: real_vector.scale_left_distrib [symmetric] divide_simps)
   2.740        done
   2.741      have "((\<lambda>x. f ((1 - x) *\<^sub>R a + x *\<^sub>R b) * (b - a)) has_integral i) {0..k}"
   2.742 -      using * k
   2.743 -      apply -
   2.744 -      apply (drule has_integral_affinity [of _ _ 0 "1::real" "inverse k" "0", simplified])
   2.745 -      apply (simp_all add: divide_simps mult.commute [of _ "k"] image_affinity_atLeastAtMost ** c)
   2.746 -      apply (drule has_integral_cmul [where c = "inverse k"])
   2.747 -      apply (simp add: has_integral_cmul)
   2.748 +      using k has_integral_affinity01 [OF *, of "inverse k" "0"]
   2.749 +      apply (simp add: divide_simps mult.commute [of _ "k"] image_affinity_atLeastAtMost ** c)
   2.750 +      apply (auto dest: has_integral_cmul [where c = "inverse k"])
   2.751        done
   2.752    } note fi = this
   2.753    { assume *: "((\<lambda>x. f ((1 - x) *\<^sub>R c + x *\<^sub>R b) * (b - c)) has_integral j) {0..1}"
   2.754 @@ -1774,12 +1817,9 @@
   2.755        apply (simp add: field_simps)
   2.756        done
   2.757      have "((\<lambda>x. f ((1 - x) *\<^sub>R a + x *\<^sub>R b) * (b - a)) has_integral j) {k..1}"
   2.758 -      using * k
   2.759 -      apply -
   2.760 -      apply (drule has_integral_affinity [of _ _ 0 "1::real" "inverse(1 - k)" "-(k/(1 - k))", simplified])
   2.761 -      apply (simp_all add: divide_simps mult.commute [of _ "1-k"] image_affinity_atLeastAtMost ** bc)
   2.762 -      apply (drule has_integral_cmul [where k = "(1 - k) *\<^sub>R j" and c = "inverse (1 - k)"])
   2.763 -      apply (simp add: has_integral_cmul)
   2.764 +      using k has_integral_affinity01 [OF *, of "inverse(1 - k)" "-(k/(1 - k))"]
   2.765 +      apply (simp add: divide_simps mult.commute [of _ "1-k"] image_affinity_atLeastAtMost ** bc)
   2.766 +      apply (auto dest: has_integral_cmul [where k = "(1 - k) *\<^sub>R j" and c = "inverse (1 - k)"])
   2.767        done
   2.768    } note fj = this
   2.769    show ?thesis
   2.770 @@ -1836,7 +1876,7 @@
   2.771    using c
   2.772    by (auto simp: closed_segment_def algebra_simps intro!: contour_integral_split [OF f])
   2.773  
   2.774 -(* The special case of midpoints used in the main quadrisection.*)
   2.775 +text\<open>The special case of midpoints used in the main quadrisection\<close>
   2.776  
   2.777  lemma has_contour_integral_midpoint:
   2.778    assumes "(f has_contour_integral i) (linepath a (midpoint a b))"
   2.779 @@ -5119,7 +5159,7 @@
   2.780  
   2.781  lemma circlepath_minus: "circlepath z (-r) x = circlepath z r (x + 1/2)"
   2.782  proof -
   2.783 -  have "z + of_real r * exp (2 * pi * \<i> * (x + 1 / 2)) =
   2.784 +  have "z + of_real r * exp (2 * pi * \<i> * (x + 1/2)) =
   2.785          z + of_real r * exp (2 * pi * \<i> * x + pi * \<i>)"
   2.786      by (simp add: divide_simps) (simp add: algebra_simps)
   2.787    also have "... = z - r * exp (2 * pi * \<i> * x)"
     3.1 --- a/src/HOL/Analysis/Complex_Analysis_Basics.thy	Sat May 26 10:11:11 2018 +0100
     3.2 +++ b/src/HOL/Analysis/Complex_Analysis_Basics.thy	Sat May 26 22:11:55 2018 +0100
     3.3 @@ -47,26 +47,6 @@
     3.4  lemma lambda_one: "(\<lambda>x::'a::monoid_mult. x) = ( * ) 1"
     3.5    by auto
     3.6  
     3.7 -lemma continuous_mult_left:
     3.8 -  fixes c::"'a::real_normed_algebra"
     3.9 -  shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. c * f x)"
    3.10 -by (rule continuous_mult [OF continuous_const])
    3.11 -
    3.12 -lemma continuous_mult_right:
    3.13 -  fixes c::"'a::real_normed_algebra"
    3.14 -  shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. f x * c)"
    3.15 -by (rule continuous_mult [OF _ continuous_const])
    3.16 -
    3.17 -lemma continuous_on_mult_left:
    3.18 -  fixes c::"'a::real_normed_algebra"
    3.19 -  shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. c * f x)"
    3.20 -by (rule continuous_on_mult [OF continuous_on_const])
    3.21 -
    3.22 -lemma continuous_on_mult_right:
    3.23 -  fixes c::"'a::real_normed_algebra"
    3.24 -  shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. f x * c)"
    3.25 -by (rule continuous_on_mult [OF _ continuous_on_const])
    3.26 -
    3.27  lemma uniformly_continuous_on_cmul_right [continuous_intros]:
    3.28    fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_algebra"
    3.29    shows "uniformly_continuous_on s f \<Longrightarrow> uniformly_continuous_on s (\<lambda>x. f x * c)"
     4.1 --- a/src/HOL/Analysis/Path_Connected.thy	Sat May 26 10:11:11 2018 +0100
     4.2 +++ b/src/HOL/Analysis/Path_Connected.thy	Sat May 26 22:11:55 2018 +0100
     4.3 @@ -8371,15 +8371,12 @@
     4.4                 (\<forall>x \<in> sphere a r. g x = f x))"
     4.5           (is "?lhs = ?rhs")
     4.6  proof%unimportant (cases r "0::real" rule: linorder_cases)
     4.7 -  case less
     4.8 -  then show ?thesis by simp
     4.9 -next
    4.10    case equal
    4.11 -  with continuous_on_const show ?thesis
    4.12 +  then show ?thesis
    4.13      apply (auto simp: homotopic_with)
    4.14      apply (rule_tac x="\<lambda>x. h (0, a)" in exI)
    4.15 -    apply (fastforce simp add:)
    4.16 -    done
    4.17 +     apply (fastforce simp add:)
    4.18 +    using continuous_on_const by blast
    4.19  next
    4.20    case greater
    4.21    let ?P = "continuous_on {x. norm(x - a) = r} f \<and> f ` {x. norm(x - a) = r} \<subseteq> S"
    4.22 @@ -8494,6 +8491,6 @@
    4.23    qed
    4.24    ultimately
    4.25    show ?thesis by meson
    4.26 -qed
    4.27 +qed simp
    4.28  
    4.29  end
     5.1 --- a/src/HOL/Limits.thy	Sat May 26 10:11:11 2018 +0100
     5.2 +++ b/src/HOL/Limits.thy	Sat May 26 22:11:55 2018 +0100
     5.3 @@ -842,6 +842,32 @@
     5.4  lemmas tendsto_mult_right_zero =
     5.5    bounded_bilinear.tendsto_right_zero [OF bounded_bilinear_mult]
     5.6  
     5.7 +
     5.8 +lemma continuous_mult_left:
     5.9 +  fixes c::"'a::real_normed_algebra"
    5.10 +  shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. c * f x)"
    5.11 +by (rule continuous_mult [OF continuous_const])
    5.12 +
    5.13 +lemma continuous_mult_right:
    5.14 +  fixes c::"'a::real_normed_algebra"
    5.15 +  shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. f x * c)"
    5.16 +by (rule continuous_mult [OF _ continuous_const])
    5.17 +
    5.18 +lemma continuous_on_mult_left:
    5.19 +  fixes c::"'a::real_normed_algebra"
    5.20 +  shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. c * f x)"
    5.21 +by (rule continuous_on_mult [OF continuous_on_const])
    5.22 +
    5.23 +lemma continuous_on_mult_right:
    5.24 +  fixes c::"'a::real_normed_algebra"
    5.25 +  shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. f x * c)"
    5.26 +by (rule continuous_on_mult [OF _ continuous_on_const])
    5.27 +
    5.28 +lemma continuous_on_mult_const [simp]:
    5.29 +  fixes c::"'a::real_normed_algebra"
    5.30 +  shows "continuous_on s (( * ) c)"
    5.31 +  by (intro continuous_on_mult_left continuous_on_id)
    5.32 +
    5.33  lemma tendsto_divide_zero:
    5.34    fixes c :: "'a::real_normed_field"
    5.35    shows "(f \<longlongrightarrow> 0) F \<Longrightarrow> ((\<lambda>x. f x / c) \<longlongrightarrow> 0) F"
     6.1 --- a/src/HOL/Topological_Spaces.thy	Sat May 26 10:11:11 2018 +0100
     6.2 +++ b/src/HOL/Topological_Spaces.thy	Sat May 26 22:11:55 2018 +0100
     6.3 @@ -1924,13 +1924,13 @@
     6.4      continuous_on (s \<union> t) (\<lambda>x. if P x then f x else g x)"
     6.5    by (rule continuous_on_If) auto
     6.6  
     6.7 -lemma continuous_on_id[continuous_intros]: "continuous_on s (\<lambda>x. x)"
     6.8 +lemma continuous_on_id[continuous_intros,simp]: "continuous_on s (\<lambda>x. x)"
     6.9    unfolding continuous_on_def by fast
    6.10  
    6.11 -lemma continuous_on_id'[continuous_intros]: "continuous_on s id"
    6.12 +lemma continuous_on_id'[continuous_intros,simp]: "continuous_on s id"
    6.13    unfolding continuous_on_def id_def by fast
    6.14  
    6.15 -lemma continuous_on_const[continuous_intros]: "continuous_on s (\<lambda>x. c)"
    6.16 +lemma continuous_on_const[continuous_intros,simp]: "continuous_on s (\<lambda>x. c)"
    6.17    unfolding continuous_on_def by auto
    6.18  
    6.19  lemma continuous_on_subset: "continuous_on s f \<Longrightarrow> t \<subseteq> s \<Longrightarrow> continuous_on t f"