src/HOL/Analysis/Derivative.thy
changeset 76832 ab08604729a2
parent 75078 ec86cb2418e1
child 77140 9a60c1759543
equal deleted inserted replaced
76823:8a17349143df 76832:ab08604729a2
    45 lemma has_derivative_componentwise_within:
    45 lemma has_derivative_componentwise_within:
    46    "(f has_derivative f') (at a within S) \<longleftrightarrow>
    46    "(f has_derivative f') (at a within S) \<longleftrightarrow>
    47     (\<forall>i \<in> Basis. ((\<lambda>x. f x \<bullet> i) has_derivative (\<lambda>x. f' x \<bullet> i)) (at a within S))"
    47     (\<forall>i \<in> Basis. ((\<lambda>x. f x \<bullet> i) has_derivative (\<lambda>x. f' x \<bullet> i)) (at a within S))"
    48   apply (simp add: has_derivative_within)
    48   apply (simp add: has_derivative_within)
    49   apply (subst tendsto_componentwise_iff)
    49   apply (subst tendsto_componentwise_iff)
    50   apply (simp add: bounded_linear_componentwise_iff [symmetric] ball_conj_distrib)
    50   apply (simp add: ball_conj_distrib  inner_diff_left inner_left_distrib flip: bounded_linear_componentwise_iff)
    51   apply (simp add: algebra_simps)
       
    52   done
    51   done
    53 
    52 
    54 lemma has_derivative_at_withinI:
    53 lemma has_derivative_at_withinI:
    55   "(f has_derivative f') (at x) \<Longrightarrow> (f has_derivative f') (at x within s)"
    54   "(f has_derivative f') (at x) \<Longrightarrow> (f has_derivative f') (at x within s)"
    56   unfolding has_derivative_within' has_derivative_at'
    55   unfolding has_derivative_within' has_derivative_at'
  1179         open t \<Longrightarrow>
  1178         open t \<Longrightarrow>
  1180         y \<in> t \<Longrightarrow>
  1179         y \<in> t \<Longrightarrow>
  1181         (\<And>z. z \<in> t \<Longrightarrow> f (g z) = z)
  1180         (\<And>z. z \<in> t \<Longrightarrow> f (g z) = z)
  1182         \<Longrightarrow> DERIV g y :> inverse (f')"
  1181         \<Longrightarrow> DERIV g y :> inverse (f')"
  1183   unfolding has_field_derivative_def
  1182   unfolding has_field_derivative_def
  1184   apply (rule has_derivative_inverse_basic)
  1183   by (rule has_derivative_inverse_basic) (auto simp: bounded_linear_mult_right)
  1185   apply (auto simp:  bounded_linear_mult_right)
       
  1186   done
       
  1187 
  1184 
  1188 text \<open>Simply rewrite that based on the domain point x.\<close>
  1185 text \<open>Simply rewrite that based on the domain point x.\<close>
  1189 
  1186 
  1190 lemma has_derivative_inverse_basic_x:
  1187 lemma has_derivative_inverse_basic_x:
  1191   fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
  1188   fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
  1203 text \<open>This is the version in Dieudonne', assuming continuity of f and g.\<close>
  1200 text \<open>This is the version in Dieudonne', assuming continuity of f and g.\<close>
  1204 
  1201 
  1205 lemma has_derivative_inverse_dieudonne:
  1202 lemma has_derivative_inverse_dieudonne:
  1206   fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
  1203   fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
  1207   assumes "open S"
  1204   assumes "open S"
  1208     and "open (f ` S)"
  1205     and fS: "open (f ` S)"
  1209     and "continuous_on S f"
  1206     and A: "continuous_on S f" "continuous_on (f ` S) g" 
  1210     and "continuous_on (f ` S) g"
  1207            "\<And>x. x \<in> S \<Longrightarrow> g (f x) = x" "x \<in> S"
  1211     and "\<And>x. x \<in> S \<Longrightarrow> g (f x) = x"
  1208     and B: "(f has_derivative f') (at x)" "bounded_linear g'" "g' \<circ> f' = id"
  1212     and "x \<in> S"
       
  1213     and "(f has_derivative f') (at x)"
       
  1214     and "bounded_linear g'"
       
  1215     and "g' \<circ> f' = id"
       
  1216   shows "(g has_derivative g') (at (f x))"
  1209   shows "(g has_derivative g') (at (f x))"
  1217   apply (rule has_derivative_inverse_basic_x[OF assms(7-9) _ _ assms(2)])
  1210   using A fS continuous_on_eq_continuous_at
  1218   using assms(3-6)
  1211   by (intro has_derivative_inverse_basic_x[OF B _ _ fS]) force+
  1219   unfolding continuous_on_eq_continuous_at[OF assms(1)] continuous_on_eq_continuous_at[OF assms(2)]
       
  1220   apply auto
       
  1221   done
       
  1222 
  1212 
  1223 text \<open>Here's the simplest way of not assuming much about g.\<close>
  1213 text \<open>Here's the simplest way of not assuming much about g.\<close>
  1224 
  1214 
  1225 proposition has_derivative_inverse:
  1215 proposition has_derivative_inverse:
  1226   fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
  1216   fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::real_normed_vector"
  1227   assumes "compact S"
  1217   assumes "compact S"
  1228     and "x \<in> S"
  1218     and "x \<in> S"
  1229     and fx: "f x \<in> interior (f ` S)"
  1219     and fx: "f x \<in> interior (f ` S)"
  1230     and "continuous_on S f"
  1220     and "continuous_on S f"
  1231     and gf: "\<And>y. y \<in> S \<Longrightarrow> g (f y) = y"
  1221     and gf: "\<And>y. y \<in> S \<Longrightarrow> g (f y) = y"
  1232     and "(f has_derivative f') (at x)"
  1222     and B: "(f has_derivative f') (at x)" "bounded_linear g'" "g' \<circ> f' = id"
  1233     and "bounded_linear g'"
       
  1234     and "g' \<circ> f' = id"
       
  1235   shows "(g has_derivative g') (at (f x))"
  1223   shows "(g has_derivative g') (at (f x))"
  1236 proof -
  1224 proof -
  1237   have *: "\<And>y. y \<in> interior (f ` S) \<Longrightarrow> f (g y) = y"
  1225   have *: "\<And>y. y \<in> interior (f ` S) \<Longrightarrow> f (g y) = y"
  1238     by (metis gf image_iff interior_subset subsetCE)
  1226     by (metis gf image_iff interior_subset subsetCE)
  1239   show ?thesis
  1227   show ?thesis
  1240     apply (rule has_derivative_inverse_basic_x[OF assms(6-8), where T = "interior (f ` S)"])
  1228     using assms * continuous_on_interior continuous_on_inv fx 
  1241     apply (rule continuous_on_interior[OF _ fx])
  1229     by (intro has_derivative_inverse_basic_x[OF B, where T = "interior (f`S)"]) blast+
  1242     apply (rule continuous_on_inv)
       
  1243     apply (simp_all add: assms *)
       
  1244     done
       
  1245 qed
  1230 qed
  1246 
  1231 
  1247 
  1232 
  1248 text \<open>Invertible derivative continuous at a point implies local
  1233 text \<open>Invertible derivative continuous at a point implies local
  1249 injectivity. It's only for this we need continuity of the derivative,
  1234 injectivity. It's only for this we need continuity of the derivative,
  1314         then have "onorm (\<lambda>v. v - g' (f' u v)) \<le> onorm g' * onorm (\<lambda>w. f' a w - f' u w)"
  1299         then have "onorm (\<lambda>v. v - g' (f' u v)) \<le> onorm g' * onorm (\<lambda>w. f' a w - f' u w)"
  1315           by (simp add: "*" bounded_linear_axioms onorm_compose)
  1300           by (simp add: "*" bounded_linear_axioms onorm_compose)
  1316         also have "\<dots> \<le> onorm g' * k"
  1301         also have "\<dots> \<le> onorm g' * k"
  1317           apply (rule mult_left_mono)
  1302           apply (rule mult_left_mono)
  1318           using d1(2)[of u]
  1303           using d1(2)[of u]
  1319           using onorm_neg[where f="\<lambda>x. f' u x - f' a x"] d u onorm_pos_le[OF bling] apply (auto simp: algebra_simps)
  1304           using onorm_neg[where f="\<lambda>x. f' u x - f' a x"] d u onorm_pos_le[OF bling] 
       
  1305            apply (auto simp: algebra_simps)
  1320           done
  1306           done
  1321         also have "\<dots> \<le> 1 / 2"
  1307         also have "\<dots> \<le> 1 / 2"
  1322           unfolding k_def by auto
  1308           unfolding k_def by auto
  1323         finally show "onorm (\<lambda>v. v - g' (f' u v)) \<le> 1 / 2" .
  1309         finally show "onorm (\<lambda>v. v - g' (f' u v)) \<le> 1 / 2" .
  1324       qed
  1310       qed
  1496     show "bounded_linear (g' x)"
  1482     show "bounded_linear (g' x)"
  1497     proof
  1483     proof
  1498       fix x' y z :: 'a
  1484       fix x' y z :: 'a
  1499       fix c :: real
  1485       fix c :: real
  1500       note lin = assms(2)[rule_format,OF \<open>x\<in>S\<close>,THEN has_derivative_bounded_linear]
  1486       note lin = assms(2)[rule_format,OF \<open>x\<in>S\<close>,THEN has_derivative_bounded_linear]
  1501       show "g' x (c *\<^sub>R x') = c *\<^sub>R g' x x'"
  1487       have "(\<lambda>n. f' n x (c *\<^sub>R x')) \<longlonglongrightarrow> c *\<^sub>R g' x x'"
  1502         apply (rule tendsto_unique[OF trivial_limit_sequentially tog'])
       
  1503         unfolding lin[THEN bounded_linear.linear, THEN linear_cmul]
  1488         unfolding lin[THEN bounded_linear.linear, THEN linear_cmul]
  1504         apply (intro tendsto_intros tog')
  1489         by (intro tendsto_intros tog')
  1505         done
  1490       then show "g' x (c *\<^sub>R x') = c *\<^sub>R g' x x'"
  1506       show "g' x (y + z) = g' x y + g' x z"
  1491         using LIMSEQ_unique tog' by blast
  1507         apply (rule tendsto_unique[OF trivial_limit_sequentially tog'])
  1492       have "(\<lambda>n. f' n x (y + z)) \<longlonglongrightarrow> g' x y + g' x z"
  1508         unfolding lin[THEN bounded_linear.linear, THEN linear_add]
  1493         unfolding lin[THEN bounded_linear.linear, THEN linear_add]
  1509         apply (rule tendsto_add)
  1494         by (simp add: tendsto_add tog')
  1510         apply (rule tog')+
  1495       then show "g' x (y + z) = g' x y + g' x z"
  1511         done
  1496         using LIMSEQ_unique tog' by blast
  1512       obtain N where N: "\<forall>h. norm (f' N x h - g' x h) \<le> 1 * norm h"
  1497       obtain N where N: "\<forall>h. norm (f' N x h - g' x h) \<le> 1 * norm h"
  1513         using nle \<open>x \<in> S\<close> unfolding eventually_sequentially by (fast intro: zero_less_one)
  1498         using nle \<open>x \<in> S\<close> unfolding eventually_sequentially by (fast intro: zero_less_one)
  1514       have "bounded_linear (f' N x)"
  1499       have "bounded_linear (f' N x)"
  1515         using derf \<open>x \<in> S\<close> by fast
  1500         using derf \<open>x \<in> S\<close> by fast
  1516       from bounded_linear.bounded [OF this]
  1501       from bounded_linear.bounded [OF this]
  1619         unfolding eventually_sequentially
  1604         unfolding eventually_sequentially
  1620     proof (intro exI allI ballI impI)
  1605     proof (intro exI allI ballI impI)
  1621       fix n x h
  1606       fix n x h
  1622       assume n: "N \<le> n" and x: "x \<in> S"
  1607       assume n: "N \<le> n" and x: "x \<in> S"
  1623       have *: "inverse (real (Suc n)) \<le> e"
  1608       have *: "inverse (real (Suc n)) \<le> e"
  1624         apply (rule order_trans[OF _ N[THEN less_imp_le]])
  1609         using n N
  1625         using n apply (auto simp add: field_simps)
  1610         by (smt (verit, best) le_imp_inverse_le of_nat_0_less_iff of_nat_Suc of_nat_le_iff zero_less_Suc)
  1626         done
       
  1627       show "norm (f' n x h - g' x h) \<le> e * norm h"
  1611       show "norm (f' n x h - g' x h) \<le> e * norm h"
  1628         by (meson "*" mult_right_mono norm_ge_zero order.trans x f')
  1612         by (meson "*" mult_right_mono norm_ge_zero order.trans x f')
  1629     qed
  1613     qed
  1630   qed (use f' in auto)
  1614   qed (use f' in auto)
  1631 qed
  1615 qed
  1820   by (metis has_field_derivative_def has_real_derivative)
  1804   by (metis has_field_derivative_def has_real_derivative)
  1821 
  1805 
  1822 lemma has_vector_derivative_cong_ev:
  1806 lemma has_vector_derivative_cong_ev:
  1823   assumes *: "eventually (\<lambda>x. x \<in> S \<longrightarrow> f x = g x) (nhds x)" "f x = g x"
  1807   assumes *: "eventually (\<lambda>x. x \<in> S \<longrightarrow> f x = g x) (nhds x)" "f x = g x"
  1824   shows "(f has_vector_derivative f') (at x within S) = (g has_vector_derivative f') (at x within S)"
  1808   shows "(f has_vector_derivative f') (at x within S) = (g has_vector_derivative f') (at x within S)"
       
  1809 proof (cases "at x within S = bot")
       
  1810   case True
       
  1811   then show ?thesis   
       
  1812     by (simp add: has_derivative_def has_vector_derivative_def)
       
  1813 next
       
  1814   case False
       
  1815   then show ?thesis
  1825   unfolding has_vector_derivative_def has_derivative_def
  1816   unfolding has_vector_derivative_def has_derivative_def
  1826   using *
  1817   using *
  1827   apply (cases "at x within S \<noteq> bot")
       
  1828   apply (intro refl conj_cong filterlim_cong)
  1818   apply (intro refl conj_cong filterlim_cong)
  1829   apply (auto simp: Lim_ident_at eventually_at_filter elim: eventually_mono)
  1819   apply (auto simp: Lim_ident_at eventually_at_filter elim: eventually_mono)
  1830   done
  1820   done
       
  1821 qed
  1831 
  1822 
  1832 lemma vector_derivative_cong_eq:
  1823 lemma vector_derivative_cong_eq:
  1833   assumes "eventually (\<lambda>x. x \<in> A \<longrightarrow> f x = g x) (nhds x)" "x = y" "A = B" "x \<in> A"
  1824   assumes "eventually (\<lambda>x. x \<in> A \<longrightarrow> f x = g x) (nhds x)" "x = y" "A = B" "x \<in> A"
  1834   shows   "vector_derivative f (at x within A) = vector_derivative g (at y within B)"
  1825   shows   "vector_derivative f (at x within A) = vector_derivative g (at y within B)"
  1835 proof -
  1826 proof -
  1898   by (simp add: vector_derivative_at has_vector_derivative_mult vector_derivative_works [symmetric])
  1889   by (simp add: vector_derivative_at has_vector_derivative_mult vector_derivative_works [symmetric])
  1899 
  1890 
  1900 lemma vector_derivative_scaleR_at [simp]:
  1891 lemma vector_derivative_scaleR_at [simp]:
  1901     "\<lbrakk>f differentiable at a; g differentiable at a\<rbrakk>
  1892     "\<lbrakk>f differentiable at a; g differentiable at a\<rbrakk>
  1902    \<Longrightarrow> vector_derivative (\<lambda>x. f x *\<^sub>R g x) (at a) = f a *\<^sub>R vector_derivative g (at a) + vector_derivative f (at a) *\<^sub>R g a"
  1893    \<Longrightarrow> vector_derivative (\<lambda>x. f x *\<^sub>R g x) (at a) = f a *\<^sub>R vector_derivative g (at a) + vector_derivative f (at a) *\<^sub>R g a"
  1903 apply (rule vector_derivative_at)
  1894   apply (intro vector_derivative_at has_vector_derivative_scaleR)
  1904 apply (rule has_vector_derivative_scaleR)
  1895    apply (auto simp: vector_derivative_works has_vector_derivative_def has_field_derivative_def mult_commute_abs)
  1905 apply (auto simp: vector_derivative_works has_vector_derivative_def has_field_derivative_def mult_commute_abs)
  1896   done
  1906 done
       
  1907 
  1897 
  1908 lemma vector_derivative_within_cbox:
  1898 lemma vector_derivative_within_cbox:
  1909   assumes ab: "a < b" "x \<in> cbox a b"
  1899   assumes ab: "a < b" "x \<in> cbox a b"
  1910   assumes f: "(f has_vector_derivative f') (at x within cbox a b)"
  1900   assumes f: "(f has_vector_derivative f') (at x within cbox a b)"
  1911   shows "vector_derivative f (at x within cbox a b) = f'"
  1901   shows "vector_derivative f (at x within cbox a b) = f'"
  1912   by (intro vector_derivative_unique_within_closed_interval[OF ab _ f]
  1902   by (metis assms box_real(2) f islimpt_Icc trivial_limit_within vector_derivative_within)
  1913             vector_derivative_works[THEN iffD1] differentiableI_vector)
       
  1914      fact
       
  1915 
  1903 
  1916 lemma vector_derivative_within_closed_interval:
  1904 lemma vector_derivative_within_closed_interval:
  1917   fixes f::"real \<Rightarrow> 'a::euclidean_space"
  1905   fixes f::"real \<Rightarrow> 'a::euclidean_space"
  1918   assumes "a < b" and "x \<in> {a..b}"
  1906   assumes "a < b" and "x \<in> {a..b}"
  1919   assumes "(f has_vector_derivative f') (at x within {a..b})"
  1907   assumes "(f has_vector_derivative f') (at x within {a..b})"
  2326 by (simp add: field_differentiable_def DERIV_deriv_iff_has_field_derivative)
  2314 by (simp add: field_differentiable_def DERIV_deriv_iff_has_field_derivative)
  2327 
  2315 
  2328 lemma vector_derivative_chain_at_general:
  2316 lemma vector_derivative_chain_at_general:
  2329   assumes "f differentiable at x" "g field_differentiable at (f x)"
  2317   assumes "f differentiable at x" "g field_differentiable at (f x)"
  2330   shows "vector_derivative (g \<circ> f) (at x) = vector_derivative f (at x) * deriv g (f x)"
  2318   shows "vector_derivative (g \<circ> f) (at x) = vector_derivative f (at x) * deriv g (f x)"
  2331   apply (rule vector_derivative_at [OF field_vector_diff_chain_at])
  2319   using assms field_differentiable_derivI field_vector_diff_chain_at 
  2332   using assms vector_derivative_works by (auto simp: field_differentiable_derivI)
  2320       vector_derivative_at vector_derivative_works by blast
  2333 
  2321 
  2334 lemma deriv_chain:
  2322 lemma deriv_chain:
  2335   "f field_differentiable at x \<Longrightarrow> g field_differentiable at (f x)
  2323   "f field_differentiable at x \<Longrightarrow> g field_differentiable at (f x)
  2336     \<Longrightarrow> deriv (g o f) x = deriv g (f x) * deriv f x"
  2324     \<Longrightarrow> deriv (g o f) x = deriv g (f x) * deriv f x"
  2337   by (metis DERIV_deriv_iff_field_differentiable DERIV_chain DERIV_imp_deriv)
  2325   by (metis DERIV_deriv_iff_field_differentiable DERIV_chain DERIV_imp_deriv)
  2407    \<Longrightarrow> deriv (\<lambda>w. sum (\<lambda>i. f i w) S) z = sum (\<lambda>i. deriv (f i) z) S"
  2395    \<Longrightarrow> deriv (\<lambda>w. sum (\<lambda>i. f i w) S) z = sum (\<lambda>i. deriv (f i) z) S"
  2408   unfolding DERIV_deriv_iff_field_differentiable[symmetric]
  2396   unfolding DERIV_deriv_iff_field_differentiable[symmetric]
  2409   by (auto intro!: DERIV_imp_deriv derivative_intros)
  2397   by (auto intro!: DERIV_imp_deriv derivative_intros)
  2410 
  2398 
  2411 lemma deriv_compose_linear:
  2399 lemma deriv_compose_linear:
  2412   "f field_differentiable at (c * z) \<Longrightarrow> deriv (\<lambda>w. f (c * w)) z = c * deriv f (c * z)"
  2400   assumes "f field_differentiable at (c * z)"
  2413 apply (rule DERIV_imp_deriv)
  2401   shows "deriv (\<lambda>w. f (c * w)) z = c * deriv f (c * z)"
  2414   unfolding DERIV_deriv_iff_field_differentiable [symmetric]
  2402 proof -
  2415   by (metis (full_types) DERIV_chain2 DERIV_cmult_Id mult.commute)
  2403   have "deriv (\<lambda>a. f (c * a)) z = deriv f (c * z) * c"
       
  2404     using assms by (simp add: DERIV_chain2 DERIV_deriv_iff_field_differentiable DERIV_imp_deriv)
       
  2405   then show ?thesis
       
  2406     by simp
       
  2407 qed
  2416 
  2408 
  2417 
  2409 
  2418 lemma nonzero_deriv_nonconstant:
  2410 lemma nonzero_deriv_nonconstant:
  2419   assumes df: "DERIV f \<xi> :> df" and S: "open S" "\<xi> \<in> S" and "df \<noteq> 0"
  2411   assumes df: "DERIV f \<xi> :> df" and S: "open S" "\<xi> \<in> S" and "df \<noteq> 0"
  2420     shows "\<not> f constant_on S"
  2412     shows "\<not> f constant_on S"
  2622   ultimately
  2614   ultimately
  2623   have "\<forall>\<^sub>F (x', y') in at (x, y) within X \<times> Y.
  2615   have "\<forall>\<^sub>F (x', y') in at (x, y) within X \<times> Y.
  2624             norm ((f x' y' - f x y - (fx (x' - x) + fy x y (y' - y))) /\<^sub>R
  2616             norm ((f x' y' - f x y - (fx (x' - x) + fy x y (y' - y))) /\<^sub>R
  2625               norm ((x', y') - (x, y)))
  2617               norm ((x', y') - (x, y)))
  2626             < e'"
  2618             < e'"
  2627     apply eventually_elim
  2619   proof (eventually_elim, safe)
  2628   proof safe
       
  2629     fix x' y'
  2620     fix x' y'
  2630     have "norm (f x' y' - f x y - (fx (x' - x) + fy x y (y' - y))) \<le>
  2621     have "norm (f x' y' - f x y - (fx (x' - x) + fy x y (y' - y))) \<le>
  2631         norm (f x' y' - f x' y - fy x' y (y' - y)) +
  2622         norm (f x' y' - f x' y - fy x' y (y' - y)) +
  2632         norm (fy x y (y' - y) - fy x' y (y' - y)) +
  2623         norm (fy x y (y' - y) - fy x' y (y' - y)) +
  2633         norm (f x' y - f x y - fx (x' - x))"
  2624         norm (f x' y - f x y - fx (x' - x))"
  2725   assumes connect: "x \<in> closure S \<Longrightarrow> x \<in> closure T \<Longrightarrow> f x = g x"
  2716   assumes connect: "x \<in> closure S \<Longrightarrow> x \<in> closure T \<Longrightarrow> f x = g x"
  2726   assumes connect': "x \<in> closure S \<Longrightarrow> x \<in> closure T \<Longrightarrow> f' x = g' x"
  2717   assumes connect': "x \<in> closure S \<Longrightarrow> x \<in> closure T \<Longrightarrow> f' x = g' x"
  2727   shows "((\<lambda>x. if x \<in> S then f x else g x) has_vector_derivative
  2718   shows "((\<lambda>x. if x \<in> S then f x else g x) has_vector_derivative
  2728     (if x \<in> S then f' x else g' x)) (at x within u)"
  2719     (if x \<in> S then f' x else g' x)) (at x within u)"
  2729   unfolding has_vector_derivative_def assms
  2720   unfolding has_vector_derivative_def assms
  2730   using x_in
  2721   using x_in f' g'
  2731   apply (intro has_derivative_If_within_closures[where ?f' = "\<lambda>x a. a *\<^sub>R f' x" and ?g' = "\<lambda>x a. a *\<^sub>R g' x",
  2722   by (intro has_derivative_If_within_closures[where ?f' = "\<lambda>x a. a *\<^sub>R f' x" and ?g' = "\<lambda>x a. a *\<^sub>R g' x",
  2732         THEN has_derivative_eq_rhs])
  2723         THEN has_derivative_eq_rhs]; force simp: assms has_vector_derivative_def)
  2733   subgoal by (rule f'[unfolded has_vector_derivative_def]; assumption)
  2724 
  2734   subgoal by (rule g'[unfolded has_vector_derivative_def]; assumption)
       
  2735   by (auto simp: assms)
       
  2736 
  2725 
  2737 subsection\<^marker>\<open>tag important\<close>\<open>The Inverse Function Theorem\<close>
  2726 subsection\<^marker>\<open>tag important\<close>\<open>The Inverse Function Theorem\<close>
  2738 
  2727 
  2739 lemma linear_injective_contraction:
  2728 lemma linear_injective_contraction:
  2740   assumes "linear f" "c < 1" and le: "\<And>x. norm (f x - x) \<le> c * norm x"
  2729   assumes "linear f" "c < 1" and le: "\<And>x. norm (f x - x) \<le> c * norm x"
  3098 by (simp add: piecewise_differentiable_on_def)
  3087 by (simp add: piecewise_differentiable_on_def)
  3099 
  3088 
  3100 lemma piecewise_differentiable_on_subset:
  3089 lemma piecewise_differentiable_on_subset:
  3101     "f piecewise_differentiable_on S \<Longrightarrow> T \<le> S \<Longrightarrow> f piecewise_differentiable_on T"
  3090     "f piecewise_differentiable_on S \<Longrightarrow> T \<le> S \<Longrightarrow> f piecewise_differentiable_on T"
  3102   using continuous_on_subset
  3091   using continuous_on_subset
  3103   unfolding piecewise_differentiable_on_def
  3092   by (smt (verit) Diff_iff differentiable_within_subset in_mono piecewise_differentiable_on_def)
  3104   apply safe
       
  3105   apply (blast elim: continuous_on_subset)
       
  3106   by (meson Diff_iff differentiable_within_subset subsetCE)
       
  3107 
  3093 
  3108 lemma differentiable_on_imp_piecewise_differentiable:
  3094 lemma differentiable_on_imp_piecewise_differentiable:
  3109   fixes a:: "'a::{linorder_topology,real_normed_vector}"
  3095   fixes a:: "'a::{linorder_topology,real_normed_vector}"
  3110   shows "f differentiable_on {a..b} \<Longrightarrow> f piecewise_differentiable_on {a..b}"
  3096   shows "f differentiable_on {a..b} \<Longrightarrow> f piecewise_differentiable_on {a..b}"
  3111   apply (simp add: piecewise_differentiable_on_def differentiable_imp_continuous_on)
  3097   using differentiable_imp_continuous_on differentiable_onD piecewise_differentiable_on_def by fastforce
  3112   apply (rule_tac x="{a,b}" in exI, simp add: differentiable_on_def)
       
  3113   done
       
  3114 
  3098 
  3115 lemma differentiable_imp_piecewise_differentiable:
  3099 lemma differentiable_imp_piecewise_differentiable:
  3116     "(\<And>x. x \<in> S \<Longrightarrow> f differentiable (at x within S))
  3100     "(\<And>x. x \<in> S \<Longrightarrow> f differentiable (at x within S))
  3117          \<Longrightarrow> f piecewise_differentiable_on S"
  3101          \<Longrightarrow> f piecewise_differentiable_on S"
  3118 by (auto simp: piecewise_differentiable_on_def differentiable_imp_continuous_on differentiable_on_def
  3102 by (auto simp: piecewise_differentiable_on_def differentiable_imp_continuous_on differentiable_on_def