/- Copyright (c) 2019 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, SΓ©bastien GouΓ«zel -/ import analysis.calculus.fderiv import data.polynomial.derivative import linear_algebra.affine_space.slope /-! # One-dimensional derivatives This file defines the derivative of a function `f : π•œ β†’ F` where `π•œ` is a normed field and `F` is a normed space over this field. The derivative of such a function `f` at a point `x` is given by an element `f' : F`. The theory is developed analogously to the [FrΓ©chet derivatives](./fderiv.html). We first introduce predicates defined in terms of the corresponding predicates for FrΓ©chet derivatives: - `has_deriv_at_filter f f' x L` states that the function `f` has the derivative `f'` at the point `x` as `x` goes along the filter `L`. - `has_deriv_within_at f f' s x` states that the function `f` has the derivative `f'` at the point `x` within the subset `s`. - `has_deriv_at f f' x` states that the function `f` has the derivative `f'` at the point `x`. - `has_strict_deriv_at f f' x` states that the function `f` has the derivative `f'` at the point `x` in the sense of strict differentiability, i.e., `f y - f z = (y - z) β€’ f' + o (y - z)` as `y, z β†’ x`. For the last two notions we also define a functional version: - `deriv_within f s x` is a derivative of `f` at `x` within `s`. If the derivative does not exist, then `deriv_within f s x` equals zero. - `deriv f x` is a derivative of `f` at `x`. If the derivative does not exist, then `deriv f x` equals zero. The theorems `fderiv_within_deriv_within` and `fderiv_deriv` show that the one-dimensional derivatives coincide with the general FrΓ©chet derivatives. We also show the existence and compute the derivatives of: - constants - the identity function - linear maps - addition - sum of finitely many functions - negation - subtraction - multiplication - inverse `x β†’ x⁻¹` - multiplication of two functions in `π•œ β†’ π•œ` - multiplication of a function in `π•œ β†’ π•œ` and of a function in `π•œ β†’ E` - composition of a function in `π•œ β†’ F` with a function in `π•œ β†’ π•œ` - composition of a function in `F β†’ E` with a function in `π•œ β†’ F` - inverse function (assuming that it exists; the inverse function theorem is in `inverse.lean`) - division - polynomials For most binary operations we also define `const_op` and `op_const` theorems for the cases when the first or second argument is a constant. This makes writing chains of `has_deriv_at`'s easier, and they more frequently lead to the desired result. We set up the simplifier so that it can compute the derivative of simple functions. For instance, ```lean example (x : ℝ) : deriv (Ξ» x, cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) := by { simp, ring } ``` ## Implementation notes Most of the theorems are direct restatements of the corresponding theorems for FrΓ©chet derivatives. The strategy to construct simp lemmas that give the simplifier the possibility to compute derivatives is the same as the one for differentiability statements, as explained in `fderiv.lean`. See the explanations there. -/ universes u v w noncomputable theory open_locale classical topological_space big_operators filter ennreal polynomial open filter asymptotics set open continuous_linear_map (smul_right smul_right_one_eq_iff) variables {π•œ : Type u} [nontrivially_normed_field π•œ] section variables {F : Type v} [normed_add_comm_group F] [normed_space π•œ F] variables {E : Type w} [normed_add_comm_group E] [normed_space π•œ E] /-- `f` has the derivative `f'` at the point `x` as `x` goes along the filter `L`. That is, `f x' = f x + (x' - x) β€’ f' + o(x' - x)` where `x'` converges along the filter `L`. -/ def has_deriv_at_filter (f : π•œ β†’ F) (f' : F) (x : π•œ) (L : filter π•œ) := has_fderiv_at_filter f (smul_right (1 : π•œ β†’L[π•œ] π•œ) f') x L /-- `f` has the derivative `f'` at the point `x` within the subset `s`. That is, `f x' = f x + (x' - x) β€’ f' + o(x' - x)` where `x'` converges to `x` inside `s`. -/ def has_deriv_within_at (f : π•œ β†’ F) (f' : F) (s : set π•œ) (x : π•œ) := has_deriv_at_filter f f' x (𝓝[s] x) /-- `f` has the derivative `f'` at the point `x`. That is, `f x' = f x + (x' - x) β€’ f' + o(x' - x)` where `x'` converges to `x`. -/ def has_deriv_at (f : π•œ β†’ F) (f' : F) (x : π•œ) := has_deriv_at_filter f f' x (𝓝 x) /-- `f` has the derivative `f'` at the point `x` in the sense of strict differentiability. That is, `f y - f z = (y - z) β€’ f' + o(y - z)` as `y, z β†’ x`. -/ def has_strict_deriv_at (f : π•œ β†’ F) (f' : F) (x : π•œ) := has_strict_fderiv_at f (smul_right (1 : π•œ β†’L[π•œ] π•œ) f') x /-- Derivative of `f` at the point `x` within the set `s`, if it exists. Zero otherwise. If the derivative exists (i.e., `βˆƒ f', has_deriv_within_at f f' s x`), then `f x' = f x + (x' - x) β€’ deriv_within f s x + o(x' - x)` where `x'` converges to `x` inside `s`. -/ def deriv_within (f : π•œ β†’ F) (s : set π•œ) (x : π•œ) := fderiv_within π•œ f s x 1 /-- Derivative of `f` at the point `x`, if it exists. Zero otherwise. If the derivative exists (i.e., `βˆƒ f', has_deriv_at f f' x`), then `f x' = f x + (x' - x) β€’ deriv f x + o(x' - x)` where `x'` converges to `x`. -/ def deriv (f : π•œ β†’ F) (x : π•œ) := fderiv π•œ f x 1 variables {f fβ‚€ f₁ g : π•œ β†’ F} variables {f' fβ‚€' f₁' g' : F} variables {x : π•œ} variables {s t : set π•œ} variables {L L₁ Lβ‚‚ : filter π•œ} /-- Expressing `has_fderiv_at_filter f f' x L` in terms of `has_deriv_at_filter` -/ lemma has_fderiv_at_filter_iff_has_deriv_at_filter {f' : π•œ β†’L[π•œ] F} : has_fderiv_at_filter f f' x L ↔ has_deriv_at_filter f (f' 1) x L := by simp [has_deriv_at_filter] lemma has_fderiv_at_filter.has_deriv_at_filter {f' : π•œ β†’L[π•œ] F} : has_fderiv_at_filter f f' x L β†’ has_deriv_at_filter f (f' 1) x L := has_fderiv_at_filter_iff_has_deriv_at_filter.mp /-- Expressing `has_fderiv_within_at f f' s x` in terms of `has_deriv_within_at` -/ lemma has_fderiv_within_at_iff_has_deriv_within_at {f' : π•œ β†’L[π•œ] F} : has_fderiv_within_at f f' s x ↔ has_deriv_within_at f (f' 1) s x := has_fderiv_at_filter_iff_has_deriv_at_filter /-- Expressing `has_deriv_within_at f f' s x` in terms of `has_fderiv_within_at` -/ lemma has_deriv_within_at_iff_has_fderiv_within_at {f' : F} : has_deriv_within_at f f' s x ↔ has_fderiv_within_at f (smul_right (1 : π•œ β†’L[π•œ] π•œ) f') s x := iff.rfl lemma has_fderiv_within_at.has_deriv_within_at {f' : π•œ β†’L[π•œ] F} : has_fderiv_within_at f f' s x β†’ has_deriv_within_at f (f' 1) s x := has_fderiv_within_at_iff_has_deriv_within_at.mp lemma has_deriv_within_at.has_fderiv_within_at {f' : F} : has_deriv_within_at f f' s x β†’ has_fderiv_within_at f (smul_right (1 : π•œ β†’L[π•œ] π•œ) f') s x := has_deriv_within_at_iff_has_fderiv_within_at.mp /-- Expressing `has_fderiv_at f f' x` in terms of `has_deriv_at` -/ lemma has_fderiv_at_iff_has_deriv_at {f' : π•œ β†’L[π•œ] F} : has_fderiv_at f f' x ↔ has_deriv_at f (f' 1) x := has_fderiv_at_filter_iff_has_deriv_at_filter lemma has_fderiv_at.has_deriv_at {f' : π•œ β†’L[π•œ] F} : has_fderiv_at f f' x β†’ has_deriv_at f (f' 1) x := has_fderiv_at_iff_has_deriv_at.mp lemma has_strict_fderiv_at_iff_has_strict_deriv_at {f' : π•œ β†’L[π•œ] F} : has_strict_fderiv_at f f' x ↔ has_strict_deriv_at f (f' 1) x := by simp [has_strict_deriv_at, has_strict_fderiv_at] protected lemma has_strict_fderiv_at.has_strict_deriv_at {f' : π•œ β†’L[π•œ] F} : has_strict_fderiv_at f f' x β†’ has_strict_deriv_at f (f' 1) x := has_strict_fderiv_at_iff_has_strict_deriv_at.mp lemma has_strict_deriv_at_iff_has_strict_fderiv_at : has_strict_deriv_at f f' x ↔ has_strict_fderiv_at f (smul_right (1 : π•œ β†’L[π•œ] π•œ) f') x := iff.rfl alias has_strict_deriv_at_iff_has_strict_fderiv_at ↔ has_strict_deriv_at.has_strict_fderiv_at _ /-- Expressing `has_deriv_at f f' x` in terms of `has_fderiv_at` -/ lemma has_deriv_at_iff_has_fderiv_at {f' : F} : has_deriv_at f f' x ↔ has_fderiv_at f (smul_right (1 : π•œ β†’L[π•œ] π•œ) f') x := iff.rfl alias has_deriv_at_iff_has_fderiv_at ↔ has_deriv_at.has_fderiv_at _ lemma deriv_within_zero_of_not_differentiable_within_at (h : Β¬ differentiable_within_at π•œ f s x) : deriv_within f s x = 0 := by { unfold deriv_within, rw fderiv_within_zero_of_not_differentiable_within_at, simp, assumption } lemma differentiable_within_at_of_deriv_within_ne_zero (h : deriv_within f s x β‰  0) : differentiable_within_at π•œ f s x := not_imp_comm.1 deriv_within_zero_of_not_differentiable_within_at h lemma deriv_zero_of_not_differentiable_at (h : Β¬ differentiable_at π•œ f x) : deriv f x = 0 := by { unfold deriv, rw fderiv_zero_of_not_differentiable_at, simp, assumption } lemma differentiable_at_of_deriv_ne_zero (h : deriv f x β‰  0) : differentiable_at π•œ f x := not_imp_comm.1 deriv_zero_of_not_differentiable_at h theorem unique_diff_within_at.eq_deriv (s : set π•œ) (H : unique_diff_within_at π•œ s x) (h : has_deriv_within_at f f' s x) (h₁ : has_deriv_within_at f f₁' s x) : f' = f₁' := smul_right_one_eq_iff.mp $ unique_diff_within_at.eq H h h₁ theorem has_deriv_at_filter_iff_is_o : has_deriv_at_filter f f' x L ↔ (Ξ» x' : π•œ, f x' - f x - (x' - x) β€’ f') =o[L] (Ξ» x', x' - x) := iff.rfl theorem has_deriv_at_filter_iff_tendsto : has_deriv_at_filter f f' x L ↔ tendsto (Ξ» x' : π•œ, βˆ₯x' - xβˆ₯⁻¹ * βˆ₯f x' - f x - (x' - x) β€’ f'βˆ₯) L (𝓝 0) := has_fderiv_at_filter_iff_tendsto theorem has_deriv_within_at_iff_is_o : has_deriv_within_at f f' s x ↔ (Ξ» x' : π•œ, f x' - f x - (x' - x) β€’ f') =o[𝓝[s] x] (Ξ» x', x' - x) := iff.rfl theorem has_deriv_within_at_iff_tendsto : has_deriv_within_at f f' s x ↔ tendsto (Ξ» x', βˆ₯x' - xβˆ₯⁻¹ * βˆ₯f x' - f x - (x' - x) β€’ f'βˆ₯) (𝓝[s] x) (𝓝 0) := has_fderiv_at_filter_iff_tendsto theorem has_deriv_at_iff_is_o : has_deriv_at f f' x ↔ (Ξ» x' : π•œ, f x' - f x - (x' - x) β€’ f') =o[𝓝 x] (Ξ» x', x' - x) := iff.rfl theorem has_deriv_at_iff_tendsto : has_deriv_at f f' x ↔ tendsto (Ξ» x', βˆ₯x' - xβˆ₯⁻¹ * βˆ₯f x' - f x - (x' - x) β€’ f'βˆ₯) (𝓝 x) (𝓝 0) := has_fderiv_at_filter_iff_tendsto theorem has_strict_deriv_at.has_deriv_at (h : has_strict_deriv_at f f' x) : has_deriv_at f f' x := h.has_fderiv_at /-- If the domain has dimension one, then FrΓ©chet derivative is equivalent to the classical definition with a limit. In this version we have to take the limit along the subset `-{x}`, because for `y=x` the slope equals zero due to the convention `0⁻¹=0`. -/ lemma has_deriv_at_filter_iff_tendsto_slope {x : π•œ} {L : filter π•œ} : has_deriv_at_filter f f' x L ↔ tendsto (slope f x) (L βŠ“ π“Ÿ {x}ᢜ) (𝓝 f') := begin conv_lhs { simp only [has_deriv_at_filter_iff_tendsto, (norm_inv _).symm, (norm_smul _ _).symm, tendsto_zero_iff_norm_tendsto_zero.symm] }, conv_rhs { rw [← nhds_translation_sub f', tendsto_comap_iff] }, refine (tendsto_inf_principal_nhds_iff_of_forall_eq $ by simp).symm.trans (tendsto_congr' _), refine (eventually_principal.2 $ Ξ» z hz, _).filter_mono inf_le_right, simp only [(∘)], rw [smul_sub, ← mul_smul, inv_mul_cancel (sub_ne_zero.2 hz), one_smul, slope_def_module] end lemma has_deriv_within_at_iff_tendsto_slope : has_deriv_within_at f f' s x ↔ tendsto (slope f x) (𝓝[s \ {x}] x) (𝓝 f') := begin simp only [has_deriv_within_at, nhds_within, diff_eq, inf_assoc.symm, inf_principal.symm], exact has_deriv_at_filter_iff_tendsto_slope end lemma has_deriv_within_at_iff_tendsto_slope' (hs : x βˆ‰ s) : has_deriv_within_at f f' s x ↔ tendsto (slope f x) (𝓝[s] x) (𝓝 f') := begin convert ← has_deriv_within_at_iff_tendsto_slope, exact diff_singleton_eq_self hs end lemma has_deriv_at_iff_tendsto_slope : has_deriv_at f f' x ↔ tendsto (slope f x) (𝓝[β‰ ] x) (𝓝 f') := has_deriv_at_filter_iff_tendsto_slope theorem has_deriv_within_at_congr_set {s t u : set π•œ} (hu : u ∈ 𝓝 x) (h : s ∩ u = t ∩ u) : has_deriv_within_at f f' s x ↔ has_deriv_within_at f f' t x := by simp_rw [has_deriv_within_at, nhds_within_eq_nhds_within' hu h] alias has_deriv_within_at_congr_set ↔ has_deriv_within_at.congr_set _ @[simp] lemma has_deriv_within_at_diff_singleton : has_deriv_within_at f f' (s \ {x}) x ↔ has_deriv_within_at f f' s x := by simp only [has_deriv_within_at_iff_tendsto_slope, sdiff_idem] @[simp] lemma has_deriv_within_at_Ioi_iff_Ici [partial_order π•œ] : has_deriv_within_at f f' (Ioi x) x ↔ has_deriv_within_at f f' (Ici x) x := by rw [← Ici_diff_left, has_deriv_within_at_diff_singleton] alias has_deriv_within_at_Ioi_iff_Ici ↔ has_deriv_within_at.Ici_of_Ioi has_deriv_within_at.Ioi_of_Ici @[simp] lemma has_deriv_within_at_Iio_iff_Iic [partial_order π•œ] : has_deriv_within_at f f' (Iio x) x ↔ has_deriv_within_at f f' (Iic x) x := by rw [← Iic_diff_right, has_deriv_within_at_diff_singleton] alias has_deriv_within_at_Iio_iff_Iic ↔ has_deriv_within_at.Iic_of_Iio has_deriv_within_at.Iio_of_Iic theorem has_deriv_within_at.Ioi_iff_Ioo [linear_order π•œ] [order_closed_topology π•œ] {x y : π•œ} (h : x < y) : has_deriv_within_at f f' (Ioo x y) x ↔ has_deriv_within_at f f' (Ioi x) x := has_deriv_within_at_congr_set (is_open_Iio.mem_nhds h) $ by { rw [Ioi_inter_Iio, inter_eq_left_iff_subset], exact Ioo_subset_Iio_self } alias has_deriv_within_at.Ioi_iff_Ioo ↔ has_deriv_within_at.Ioi_of_Ioo has_deriv_within_at.Ioo_of_Ioi theorem has_deriv_at_iff_is_o_nhds_zero : has_deriv_at f f' x ↔ (Ξ»h, f (x + h) - f x - h β€’ f') =o[𝓝 0] (Ξ»h, h) := has_fderiv_at_iff_is_o_nhds_zero theorem has_deriv_at_filter.mono (h : has_deriv_at_filter f f' x Lβ‚‚) (hst : L₁ ≀ Lβ‚‚) : has_deriv_at_filter f f' x L₁ := has_fderiv_at_filter.mono h hst theorem has_deriv_within_at.mono (h : has_deriv_within_at f f' t x) (hst : s βŠ† t) : has_deriv_within_at f f' s x := has_fderiv_within_at.mono h hst theorem has_deriv_at.has_deriv_at_filter (h : has_deriv_at f f' x) (hL : L ≀ 𝓝 x) : has_deriv_at_filter f f' x L := has_fderiv_at.has_fderiv_at_filter h hL theorem has_deriv_at.has_deriv_within_at (h : has_deriv_at f f' x) : has_deriv_within_at f f' s x := has_fderiv_at.has_fderiv_within_at h lemma has_deriv_within_at.differentiable_within_at (h : has_deriv_within_at f f' s x) : differentiable_within_at π•œ f s x := has_fderiv_within_at.differentiable_within_at h lemma has_deriv_at.differentiable_at (h : has_deriv_at f f' x) : differentiable_at π•œ f x := has_fderiv_at.differentiable_at h @[simp] lemma has_deriv_within_at_univ : has_deriv_within_at f f' univ x ↔ has_deriv_at f f' x := has_fderiv_within_at_univ theorem has_deriv_at.unique (hβ‚€ : has_deriv_at f fβ‚€' x) (h₁ : has_deriv_at f f₁' x) : fβ‚€' = f₁' := smul_right_one_eq_iff.mp $ hβ‚€.has_fderiv_at.unique h₁ lemma has_deriv_within_at_inter' (h : t ∈ 𝓝[s] x) : has_deriv_within_at f f' (s ∩ t) x ↔ has_deriv_within_at f f' s x := has_fderiv_within_at_inter' h lemma has_deriv_within_at_inter (h : t ∈ 𝓝 x) : has_deriv_within_at f f' (s ∩ t) x ↔ has_deriv_within_at f f' s x := has_fderiv_within_at_inter h lemma has_deriv_within_at.union (hs : has_deriv_within_at f f' s x) (ht : has_deriv_within_at f f' t x) : has_deriv_within_at f f' (s βˆͺ t) x := hs.has_fderiv_within_at.union ht.has_fderiv_within_at lemma has_deriv_within_at.nhds_within (h : has_deriv_within_at f f' s x) (ht : s ∈ 𝓝[t] x) : has_deriv_within_at f f' t x := (has_deriv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _)) lemma has_deriv_within_at.has_deriv_at (h : has_deriv_within_at f f' s x) (hs : s ∈ 𝓝 x) : has_deriv_at f f' x := has_fderiv_within_at.has_fderiv_at h hs lemma differentiable_within_at.has_deriv_within_at (h : differentiable_within_at π•œ f s x) : has_deriv_within_at f (deriv_within f s x) s x := h.has_fderiv_within_at.has_deriv_within_at lemma differentiable_at.has_deriv_at (h : differentiable_at π•œ f x) : has_deriv_at f (deriv f x) x := h.has_fderiv_at.has_deriv_at @[simp] lemma has_deriv_at_deriv_iff : has_deriv_at f (deriv f x) x ↔ differentiable_at π•œ f x := ⟨λ h, h.differentiable_at, Ξ» h, h.has_deriv_at⟩ @[simp] lemma has_deriv_within_at_deriv_within_iff : has_deriv_within_at f (deriv_within f s x) s x ↔ differentiable_within_at π•œ f s x := ⟨λ h, h.differentiable_within_at, Ξ» h, h.has_deriv_within_at⟩ lemma differentiable_on.has_deriv_at (h : differentiable_on π•œ f s) (hs : s ∈ 𝓝 x) : has_deriv_at f (deriv f x) x := (h.has_fderiv_at hs).has_deriv_at lemma has_deriv_at.deriv (h : has_deriv_at f f' x) : deriv f x = f' := h.differentiable_at.has_deriv_at.unique h lemma deriv_eq {f' : π•œ β†’ F} (h : βˆ€ x, has_deriv_at f (f' x) x) : deriv f = f' := funext $ Ξ» x, (h x).deriv lemma has_deriv_within_at.deriv_within (h : has_deriv_within_at f f' s x) (hxs : unique_diff_within_at π•œ s x) : deriv_within f s x = f' := hxs.eq_deriv _ h.differentiable_within_at.has_deriv_within_at h lemma fderiv_within_deriv_within : (fderiv_within π•œ f s x : π•œ β†’ F) 1 = deriv_within f s x := rfl lemma deriv_within_fderiv_within : smul_right (1 : π•œ β†’L[π•œ] π•œ) (deriv_within f s x) = fderiv_within π•œ f s x := by simp [deriv_within] lemma fderiv_deriv : (fderiv π•œ f x : π•œ β†’ F) 1 = deriv f x := rfl lemma deriv_fderiv : smul_right (1 : π•œ β†’L[π•œ] π•œ) (deriv f x) = fderiv π•œ f x := by simp [deriv] lemma differentiable_at.deriv_within (h : differentiable_at π•œ f x) (hxs : unique_diff_within_at π•œ s x) : deriv_within f s x = deriv f x := by { unfold deriv_within deriv, rw h.fderiv_within hxs } theorem has_deriv_within_at.deriv_eq_zero (hd : has_deriv_within_at f 0 s x) (H : unique_diff_within_at π•œ s x) : deriv f x = 0 := (em' (differentiable_at π•œ f x)).elim deriv_zero_of_not_differentiable_at $ Ξ» h, H.eq_deriv _ h.has_deriv_at.has_deriv_within_at hd lemma deriv_within_subset (st : s βŠ† t) (ht : unique_diff_within_at π•œ s x) (h : differentiable_within_at π•œ f t x) : deriv_within f s x = deriv_within f t x := ((differentiable_within_at.has_deriv_within_at h).mono st).deriv_within ht @[simp] lemma deriv_within_univ : deriv_within f univ = deriv f := by { ext, unfold deriv_within deriv, rw fderiv_within_univ } lemma deriv_within_inter (ht : t ∈ 𝓝 x) (hs : unique_diff_within_at π•œ s x) : deriv_within f (s ∩ t) x = deriv_within f s x := by { unfold deriv_within, rw fderiv_within_inter ht hs } lemma deriv_within_of_open (hs : is_open s) (hx : x ∈ s) : deriv_within f s x = deriv f x := by { unfold deriv_within, rw fderiv_within_of_open hs hx, refl } lemma deriv_mem_iff {f : π•œ β†’ F} {s : set F} {x : π•œ} : deriv f x ∈ s ↔ (differentiable_at π•œ f x ∧ deriv f x ∈ s) ∨ (Β¬differentiable_at π•œ f x ∧ (0 : F) ∈ s) := by by_cases hx : differentiable_at π•œ f x; simp [deriv_zero_of_not_differentiable_at, *] lemma deriv_within_mem_iff {f : π•œ β†’ F} {t : set π•œ} {s : set F} {x : π•œ} : deriv_within f t x ∈ s ↔ (differentiable_within_at π•œ f t x ∧ deriv_within f t x ∈ s) ∨ (Β¬differentiable_within_at π•œ f t x ∧ (0 : F) ∈ s) := by by_cases hx : differentiable_within_at π•œ f t x; simp [deriv_within_zero_of_not_differentiable_within_at, *] lemma differentiable_within_at_Ioi_iff_Ici [partial_order π•œ] : differentiable_within_at π•œ f (Ioi x) x ↔ differentiable_within_at π•œ f (Ici x) x := ⟨λ h, h.has_deriv_within_at.Ici_of_Ioi.differentiable_within_at, Ξ» h, h.has_deriv_within_at.Ioi_of_Ici.differentiable_within_at⟩ lemma deriv_within_Ioi_eq_Ici {E : Type*} [normed_add_comm_group E] [normed_space ℝ E] (f : ℝ β†’ E) (x : ℝ) : deriv_within f (Ioi x) x = deriv_within f (Ici x) x := begin by_cases H : differentiable_within_at ℝ f (Ioi x) x, { have A := H.has_deriv_within_at.Ici_of_Ioi, have B := (differentiable_within_at_Ioi_iff_Ici.1 H).has_deriv_within_at, simpa using (unique_diff_on_Ici x).eq le_rfl A B }, { rw [deriv_within_zero_of_not_differentiable_within_at H, deriv_within_zero_of_not_differentiable_within_at], rwa differentiable_within_at_Ioi_iff_Ici at H } end section congr /-! ### Congruence properties of derivatives -/ theorem filter.eventually_eq.has_deriv_at_filter_iff (hβ‚€ : fβ‚€ =αΆ [L] f₁) (hx : fβ‚€ x = f₁ x) (h₁ : fβ‚€' = f₁') : has_deriv_at_filter fβ‚€ fβ‚€' x L ↔ has_deriv_at_filter f₁ f₁' x L := hβ‚€.has_fderiv_at_filter_iff hx (by simp [h₁]) lemma has_deriv_at_filter.congr_of_eventually_eq (h : has_deriv_at_filter f f' x L) (hL : f₁ =αΆ [L] f) (hx : f₁ x = f x) : has_deriv_at_filter f₁ f' x L := by rwa hL.has_deriv_at_filter_iff hx rfl lemma has_deriv_within_at.congr_mono (h : has_deriv_within_at f f' s x) (ht : βˆ€x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t βŠ† s) : has_deriv_within_at f₁ f' t x := has_fderiv_within_at.congr_mono h ht hx h₁ lemma has_deriv_within_at.congr (h : has_deriv_within_at f f' s x) (hs : βˆ€x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : has_deriv_within_at f₁ f' s x := h.congr_mono hs hx (subset.refl _) lemma has_deriv_within_at.congr_of_mem (h : has_deriv_within_at f f' s x) (hs : βˆ€x ∈ s, f₁ x = f x) (hx : x ∈ s) : has_deriv_within_at f₁ f' s x := h.congr hs (hs _ hx) lemma has_deriv_within_at.congr_of_eventually_eq (h : has_deriv_within_at f f' s x) (h₁ : f₁ =αΆ [𝓝[s] x] f) (hx : f₁ x = f x) : has_deriv_within_at f₁ f' s x := has_deriv_at_filter.congr_of_eventually_eq h h₁ hx lemma has_deriv_within_at.congr_of_eventually_eq_of_mem (h : has_deriv_within_at f f' s x) (h₁ : f₁ =αΆ [𝓝[s] x] f) (hx : x ∈ s) : has_deriv_within_at f₁ f' s x := h.congr_of_eventually_eq h₁ (h₁.eq_of_nhds_within hx) lemma has_deriv_at.congr_of_eventually_eq (h : has_deriv_at f f' x) (h₁ : f₁ =αΆ [𝓝 x] f) : has_deriv_at f₁ f' x := has_deriv_at_filter.congr_of_eventually_eq h h₁ (mem_of_mem_nhds h₁ : _) lemma filter.eventually_eq.deriv_within_eq (hs : unique_diff_within_at π•œ s x) (hL : f₁ =αΆ [𝓝[s] x] f) (hx : f₁ x = f x) : deriv_within f₁ s x = deriv_within f s x := by { unfold deriv_within, rw hL.fderiv_within_eq hs hx } lemma deriv_within_congr (hs : unique_diff_within_at π•œ s x) (hL : βˆ€y∈s, f₁ y = f y) (hx : f₁ x = f x) : deriv_within f₁ s x = deriv_within f s x := by { unfold deriv_within, rw fderiv_within_congr hs hL hx } lemma filter.eventually_eq.deriv_eq (hL : f₁ =αΆ [𝓝 x] f) : deriv f₁ x = deriv f x := by { unfold deriv, rwa filter.eventually_eq.fderiv_eq } protected lemma filter.eventually_eq.deriv (h : f₁ =αΆ [𝓝 x] f) : deriv f₁ =αΆ [𝓝 x] deriv f := h.eventually_eq_nhds.mono $ Ξ» x h, h.deriv_eq end congr section id /-! ### Derivative of the identity -/ variables (s x L) theorem has_deriv_at_filter_id : has_deriv_at_filter id 1 x L := (has_fderiv_at_filter_id x L).has_deriv_at_filter theorem has_deriv_within_at_id : has_deriv_within_at id 1 s x := has_deriv_at_filter_id _ _ theorem has_deriv_at_id : has_deriv_at id 1 x := has_deriv_at_filter_id _ _ theorem has_deriv_at_id' : has_deriv_at (Ξ» (x : π•œ), x) 1 x := has_deriv_at_filter_id _ _ theorem has_strict_deriv_at_id : has_strict_deriv_at id 1 x := (has_strict_fderiv_at_id x).has_strict_deriv_at lemma deriv_id : deriv id x = 1 := has_deriv_at.deriv (has_deriv_at_id x) @[simp] lemma deriv_id' : deriv (@id π•œ) = Ξ» _, 1 := funext deriv_id @[simp] lemma deriv_id'' : deriv (Ξ» x : π•œ, x) = Ξ» _, 1 := deriv_id' lemma deriv_within_id (hxs : unique_diff_within_at π•œ s x) : deriv_within id s x = 1 := (has_deriv_within_at_id x s).deriv_within hxs end id section const /-! ### Derivative of constant functions -/ variables (c : F) (s x L) theorem has_deriv_at_filter_const : has_deriv_at_filter (Ξ» x, c) 0 x L := (has_fderiv_at_filter_const c x L).has_deriv_at_filter theorem has_strict_deriv_at_const : has_strict_deriv_at (Ξ» x, c) 0 x := (has_strict_fderiv_at_const c x).has_strict_deriv_at theorem has_deriv_within_at_const : has_deriv_within_at (Ξ» x, c) 0 s x := has_deriv_at_filter_const _ _ _ theorem has_deriv_at_const : has_deriv_at (Ξ» x, c) 0 x := has_deriv_at_filter_const _ _ _ lemma deriv_const : deriv (Ξ» x, c) x = 0 := has_deriv_at.deriv (has_deriv_at_const x c) @[simp] lemma deriv_const' : deriv (Ξ» x:π•œ, c) = Ξ» x, 0 := funext (Ξ» x, deriv_const x c) lemma deriv_within_const (hxs : unique_diff_within_at π•œ s x) : deriv_within (Ξ» x, c) s x = 0 := (has_deriv_within_at_const _ _ _).deriv_within hxs end const section continuous_linear_map /-! ### Derivative of continuous linear maps -/ variables (e : π•œ β†’L[π•œ] F) protected lemma continuous_linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L := e.has_fderiv_at_filter.has_deriv_at_filter protected lemma continuous_linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x := e.has_strict_fderiv_at.has_strict_deriv_at protected lemma continuous_linear_map.has_deriv_at : has_deriv_at e (e 1) x := e.has_deriv_at_filter protected lemma continuous_linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x := e.has_deriv_at_filter @[simp] protected lemma continuous_linear_map.deriv : deriv e x = e 1 := e.has_deriv_at.deriv protected lemma continuous_linear_map.deriv_within (hxs : unique_diff_within_at π•œ s x) : deriv_within e s x = e 1 := e.has_deriv_within_at.deriv_within hxs end continuous_linear_map section linear_map /-! ### Derivative of bundled linear maps -/ variables (e : π•œ β†’β‚—[π•œ] F) protected lemma linear_map.has_deriv_at_filter : has_deriv_at_filter e (e 1) x L := e.to_continuous_linear_map₁.has_deriv_at_filter protected lemma linear_map.has_strict_deriv_at : has_strict_deriv_at e (e 1) x := e.to_continuous_linear_map₁.has_strict_deriv_at protected lemma linear_map.has_deriv_at : has_deriv_at e (e 1) x := e.has_deriv_at_filter protected lemma linear_map.has_deriv_within_at : has_deriv_within_at e (e 1) s x := e.has_deriv_at_filter @[simp] protected lemma linear_map.deriv : deriv e x = e 1 := e.has_deriv_at.deriv protected lemma linear_map.deriv_within (hxs : unique_diff_within_at π•œ s x) : deriv_within e s x = e 1 := e.has_deriv_within_at.deriv_within hxs end linear_map section add /-! ### Derivative of the sum of two functions -/ theorem has_deriv_at_filter.add (hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) : has_deriv_at_filter (Ξ» y, f y + g y) (f' + g') x L := by simpa using (hf.add hg).has_deriv_at_filter theorem has_strict_deriv_at.add (hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) : has_strict_deriv_at (Ξ» y, f y + g y) (f' + g') x := by simpa using (hf.add hg).has_strict_deriv_at theorem has_deriv_within_at.add (hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) : has_deriv_within_at (Ξ» y, f y + g y) (f' + g') s x := hf.add hg theorem has_deriv_at.add (hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) : has_deriv_at (Ξ» x, f x + g x) (f' + g') x := hf.add hg lemma deriv_within_add (hxs : unique_diff_within_at π•œ s x) (hf : differentiable_within_at π•œ f s x) (hg : differentiable_within_at π•œ g s x) : deriv_within (Ξ»y, f y + g y) s x = deriv_within f s x + deriv_within g s x := (hf.has_deriv_within_at.add hg.has_deriv_within_at).deriv_within hxs @[simp] lemma deriv_add (hf : differentiable_at π•œ f x) (hg : differentiable_at π•œ g x) : deriv (Ξ»y, f y + g y) x = deriv f x + deriv g x := (hf.has_deriv_at.add hg.has_deriv_at).deriv theorem has_deriv_at_filter.add_const (hf : has_deriv_at_filter f f' x L) (c : F) : has_deriv_at_filter (Ξ» y, f y + c) f' x L := add_zero f' β–Έ hf.add (has_deriv_at_filter_const x L c) theorem has_deriv_within_at.add_const (hf : has_deriv_within_at f f' s x) (c : F) : has_deriv_within_at (Ξ» y, f y + c) f' s x := hf.add_const c theorem has_deriv_at.add_const (hf : has_deriv_at f f' x) (c : F) : has_deriv_at (Ξ» x, f x + c) f' x := hf.add_const c lemma deriv_within_add_const (hxs : unique_diff_within_at π•œ s x) (c : F) : deriv_within (Ξ»y, f y + c) s x = deriv_within f s x := by simp only [deriv_within, fderiv_within_add_const hxs] lemma deriv_add_const (c : F) : deriv (Ξ»y, f y + c) x = deriv f x := by simp only [deriv, fderiv_add_const] @[simp] lemma deriv_add_const' (c : F) : deriv (Ξ» y, f y + c) = deriv f := funext $ Ξ» x, deriv_add_const c theorem has_deriv_at_filter.const_add (c : F) (hf : has_deriv_at_filter f f' x L) : has_deriv_at_filter (Ξ» y, c + f y) f' x L := zero_add f' β–Έ (has_deriv_at_filter_const x L c).add hf theorem has_deriv_within_at.const_add (c : F) (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (Ξ» y, c + f y) f' s x := hf.const_add c theorem has_deriv_at.const_add (c : F) (hf : has_deriv_at f f' x) : has_deriv_at (Ξ» x, c + f x) f' x := hf.const_add c lemma deriv_within_const_add (hxs : unique_diff_within_at π•œ s x) (c : F) : deriv_within (Ξ»y, c + f y) s x = deriv_within f s x := by simp only [deriv_within, fderiv_within_const_add hxs] lemma deriv_const_add (c : F) : deriv (Ξ»y, c + f y) x = deriv f x := by simp only [deriv, fderiv_const_add] @[simp] lemma deriv_const_add' (c : F) : deriv (Ξ» y, c + f y) = deriv f := funext $ Ξ» x, deriv_const_add c end add section sum /-! ### Derivative of a finite sum of functions -/ open_locale big_operators variables {ΞΉ : Type*} {u : finset ΞΉ} {A : ΞΉ β†’ (π•œ β†’ F)} {A' : ΞΉ β†’ F} theorem has_deriv_at_filter.sum (h : βˆ€ i ∈ u, has_deriv_at_filter (A i) (A' i) x L) : has_deriv_at_filter (Ξ» y, βˆ‘ i in u, A i y) (βˆ‘ i in u, A' i) x L := by simpa [continuous_linear_map.sum_apply] using (has_fderiv_at_filter.sum h).has_deriv_at_filter theorem has_strict_deriv_at.sum (h : βˆ€ i ∈ u, has_strict_deriv_at (A i) (A' i) x) : has_strict_deriv_at (Ξ» y, βˆ‘ i in u, A i y) (βˆ‘ i in u, A' i) x := by simpa [continuous_linear_map.sum_apply] using (has_strict_fderiv_at.sum h).has_strict_deriv_at theorem has_deriv_within_at.sum (h : βˆ€ i ∈ u, has_deriv_within_at (A i) (A' i) s x) : has_deriv_within_at (Ξ» y, βˆ‘ i in u, A i y) (βˆ‘ i in u, A' i) s x := has_deriv_at_filter.sum h theorem has_deriv_at.sum (h : βˆ€ i ∈ u, has_deriv_at (A i) (A' i) x) : has_deriv_at (Ξ» y, βˆ‘ i in u, A i y) (βˆ‘ i in u, A' i) x := has_deriv_at_filter.sum h lemma deriv_within_sum (hxs : unique_diff_within_at π•œ s x) (h : βˆ€ i ∈ u, differentiable_within_at π•œ (A i) s x) : deriv_within (Ξ» y, βˆ‘ i in u, A i y) s x = βˆ‘ i in u, deriv_within (A i) s x := (has_deriv_within_at.sum (Ξ» i hi, (h i hi).has_deriv_within_at)).deriv_within hxs @[simp] lemma deriv_sum (h : βˆ€ i ∈ u, differentiable_at π•œ (A i) x) : deriv (Ξ» y, βˆ‘ i in u, A i y) x = βˆ‘ i in u, deriv (A i) x := (has_deriv_at.sum (Ξ» i hi, (h i hi).has_deriv_at)).deriv end sum section pi /-! ### Derivatives of functions `f : π•œ β†’ Ξ  i, E i` -/ variables {ΞΉ : Type*} [fintype ΞΉ] {E' : ΞΉ β†’ Type*} [Ξ  i, normed_add_comm_group (E' i)] [Ξ  i, normed_space π•œ (E' i)] {Ο† : π•œ β†’ Ξ  i, E' i} {Ο†' : Ξ  i, E' i} @[simp] lemma has_strict_deriv_at_pi : has_strict_deriv_at Ο† Ο†' x ↔ βˆ€ i, has_strict_deriv_at (Ξ» x, Ο† x i) (Ο†' i) x := has_strict_fderiv_at_pi' @[simp] lemma has_deriv_at_filter_pi : has_deriv_at_filter Ο† Ο†' x L ↔ βˆ€ i, has_deriv_at_filter (Ξ» x, Ο† x i) (Ο†' i) x L := has_fderiv_at_filter_pi' lemma has_deriv_at_pi : has_deriv_at Ο† Ο†' x ↔ βˆ€ i, has_deriv_at (Ξ» x, Ο† x i) (Ο†' i) x:= has_deriv_at_filter_pi lemma has_deriv_within_at_pi : has_deriv_within_at Ο† Ο†' s x ↔ βˆ€ i, has_deriv_within_at (Ξ» x, Ο† x i) (Ο†' i) s x:= has_deriv_at_filter_pi lemma deriv_within_pi (h : βˆ€ i, differentiable_within_at π•œ (Ξ» x, Ο† x i) s x) (hs : unique_diff_within_at π•œ s x) : deriv_within Ο† s x = Ξ» i, deriv_within (Ξ» x, Ο† x i) s x := (has_deriv_within_at_pi.2 (Ξ» i, (h i).has_deriv_within_at)).deriv_within hs lemma deriv_pi (h : βˆ€ i, differentiable_at π•œ (Ξ» x, Ο† x i) x) : deriv Ο† x = Ξ» i, deriv (Ξ» x, Ο† x i) x := (has_deriv_at_pi.2 (Ξ» i, (h i).has_deriv_at)).deriv end pi section smul /-! ### Derivative of the multiplication of a scalar function and a vector function -/ variables {π•œ' : Type*} [nontrivially_normed_field π•œ'] [normed_algebra π•œ π•œ'] [normed_space π•œ' F] [is_scalar_tower π•œ π•œ' F] {c : π•œ β†’ π•œ'} {c' : π•œ'} theorem has_deriv_within_at.smul (hc : has_deriv_within_at c c' s x) (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (Ξ» y, c y β€’ f y) (c x β€’ f' + c' β€’ f x) s x := by simpa using (has_fderiv_within_at.smul hc hf).has_deriv_within_at theorem has_deriv_at.smul (hc : has_deriv_at c c' x) (hf : has_deriv_at f f' x) : has_deriv_at (Ξ» y, c y β€’ f y) (c x β€’ f' + c' β€’ f x) x := begin rw [← has_deriv_within_at_univ] at *, exact hc.smul hf end theorem has_strict_deriv_at.smul (hc : has_strict_deriv_at c c' x) (hf : has_strict_deriv_at f f' x) : has_strict_deriv_at (Ξ» y, c y β€’ f y) (c x β€’ f' + c' β€’ f x) x := by simpa using (hc.smul hf).has_strict_deriv_at lemma deriv_within_smul (hxs : unique_diff_within_at π•œ s x) (hc : differentiable_within_at π•œ c s x) (hf : differentiable_within_at π•œ f s x) : deriv_within (Ξ» y, c y β€’ f y) s x = c x β€’ deriv_within f s x + (deriv_within c s x) β€’ f x := (hc.has_deriv_within_at.smul hf.has_deriv_within_at).deriv_within hxs lemma deriv_smul (hc : differentiable_at π•œ c x) (hf : differentiable_at π•œ f x) : deriv (Ξ» y, c y β€’ f y) x = c x β€’ deriv f x + (deriv c x) β€’ f x := (hc.has_deriv_at.smul hf.has_deriv_at).deriv theorem has_strict_deriv_at.smul_const (hc : has_strict_deriv_at c c' x) (f : F) : has_strict_deriv_at (Ξ» y, c y β€’ f) (c' β€’ f) x := begin have := hc.smul (has_strict_deriv_at_const x f), rwa [smul_zero, zero_add] at this, end theorem has_deriv_within_at.smul_const (hc : has_deriv_within_at c c' s x) (f : F) : has_deriv_within_at (Ξ» y, c y β€’ f) (c' β€’ f) s x := begin have := hc.smul (has_deriv_within_at_const x s f), rwa [smul_zero, zero_add] at this end theorem has_deriv_at.smul_const (hc : has_deriv_at c c' x) (f : F) : has_deriv_at (Ξ» y, c y β€’ f) (c' β€’ f) x := begin rw [← has_deriv_within_at_univ] at *, exact hc.smul_const f end lemma deriv_within_smul_const (hxs : unique_diff_within_at π•œ s x) (hc : differentiable_within_at π•œ c s x) (f : F) : deriv_within (Ξ» y, c y β€’ f) s x = (deriv_within c s x) β€’ f := (hc.has_deriv_within_at.smul_const f).deriv_within hxs lemma deriv_smul_const (hc : differentiable_at π•œ c x) (f : F) : deriv (Ξ» y, c y β€’ f) x = (deriv c x) β€’ f := (hc.has_deriv_at.smul_const f).deriv end smul section const_smul variables {R : Type*} [semiring R] [module R F] [smul_comm_class π•œ R F] [has_continuous_const_smul R F] theorem has_strict_deriv_at.const_smul (c : R) (hf : has_strict_deriv_at f f' x) : has_strict_deriv_at (Ξ» y, c β€’ f y) (c β€’ f') x := by simpa using (hf.const_smul c).has_strict_deriv_at theorem has_deriv_at_filter.const_smul (c : R) (hf : has_deriv_at_filter f f' x L) : has_deriv_at_filter (Ξ» y, c β€’ f y) (c β€’ f') x L := by simpa using (hf.const_smul c).has_deriv_at_filter theorem has_deriv_within_at.const_smul (c : R) (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (Ξ» y, c β€’ f y) (c β€’ f') s x := hf.const_smul c theorem has_deriv_at.const_smul (c : R) (hf : has_deriv_at f f' x) : has_deriv_at (Ξ» y, c β€’ f y) (c β€’ f') x := hf.const_smul c lemma deriv_within_const_smul (hxs : unique_diff_within_at π•œ s x) (c : R) (hf : differentiable_within_at π•œ f s x) : deriv_within (Ξ» y, c β€’ f y) s x = c β€’ deriv_within f s x := (hf.has_deriv_within_at.const_smul c).deriv_within hxs lemma deriv_const_smul (c : R) (hf : differentiable_at π•œ f x) : deriv (Ξ» y, c β€’ f y) x = c β€’ deriv f x := (hf.has_deriv_at.const_smul c).deriv end const_smul section neg /-! ### Derivative of the negative of a function -/ theorem has_deriv_at_filter.neg (h : has_deriv_at_filter f f' x L) : has_deriv_at_filter (Ξ» x, -f x) (-f') x L := by simpa using h.neg.has_deriv_at_filter theorem has_deriv_within_at.neg (h : has_deriv_within_at f f' s x) : has_deriv_within_at (Ξ» x, -f x) (-f') s x := h.neg theorem has_deriv_at.neg (h : has_deriv_at f f' x) : has_deriv_at (Ξ» x, -f x) (-f') x := h.neg theorem has_strict_deriv_at.neg (h : has_strict_deriv_at f f' x) : has_strict_deriv_at (Ξ» x, -f x) (-f') x := by simpa using h.neg.has_strict_deriv_at lemma deriv_within.neg (hxs : unique_diff_within_at π•œ s x) : deriv_within (Ξ»y, -f y) s x = - deriv_within f s x := by simp only [deriv_within, fderiv_within_neg hxs, continuous_linear_map.neg_apply] lemma deriv.neg : deriv (Ξ»y, -f y) x = - deriv f x := by simp only [deriv, fderiv_neg, continuous_linear_map.neg_apply] @[simp] lemma deriv.neg' : deriv (Ξ»y, -f y) = (Ξ» x, - deriv f x) := funext $ Ξ» x, deriv.neg end neg section neg2 /-! ### Derivative of the negation function (i.e `has_neg.neg`) -/ variables (s x L) theorem has_deriv_at_filter_neg : has_deriv_at_filter has_neg.neg (-1) x L := has_deriv_at_filter.neg $ has_deriv_at_filter_id _ _ theorem has_deriv_within_at_neg : has_deriv_within_at has_neg.neg (-1) s x := has_deriv_at_filter_neg _ _ theorem has_deriv_at_neg : has_deriv_at has_neg.neg (-1) x := has_deriv_at_filter_neg _ _ theorem has_deriv_at_neg' : has_deriv_at (Ξ» x, -x) (-1) x := has_deriv_at_filter_neg _ _ theorem has_strict_deriv_at_neg : has_strict_deriv_at has_neg.neg (-1) x := has_strict_deriv_at.neg $ has_strict_deriv_at_id _ lemma deriv_neg : deriv has_neg.neg x = -1 := has_deriv_at.deriv (has_deriv_at_neg x) @[simp] lemma deriv_neg' : deriv (has_neg.neg : π•œ β†’ π•œ) = Ξ» _, -1 := funext deriv_neg @[simp] lemma deriv_neg'' : deriv (Ξ» x : π•œ, -x) x = -1 := deriv_neg x lemma deriv_within_neg (hxs : unique_diff_within_at π•œ s x) : deriv_within has_neg.neg s x = -1 := (has_deriv_within_at_neg x s).deriv_within hxs lemma differentiable_neg : differentiable π•œ (has_neg.neg : π•œ β†’ π•œ) := differentiable.neg differentiable_id lemma differentiable_on_neg : differentiable_on π•œ (has_neg.neg : π•œ β†’ π•œ) s := differentiable_on.neg differentiable_on_id end neg2 section sub /-! ### Derivative of the difference of two functions -/ theorem has_deriv_at_filter.sub (hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) : has_deriv_at_filter (Ξ» x, f x - g x) (f' - g') x L := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem has_deriv_within_at.sub (hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) : has_deriv_within_at (Ξ» x, f x - g x) (f' - g') s x := hf.sub hg theorem has_deriv_at.sub (hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) : has_deriv_at (Ξ» x, f x - g x) (f' - g') x := hf.sub hg theorem has_strict_deriv_at.sub (hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x) : has_strict_deriv_at (Ξ» x, f x - g x) (f' - g') x := by simpa only [sub_eq_add_neg] using hf.add hg.neg lemma deriv_within_sub (hxs : unique_diff_within_at π•œ s x) (hf : differentiable_within_at π•œ f s x) (hg : differentiable_within_at π•œ g s x) : deriv_within (Ξ»y, f y - g y) s x = deriv_within f s x - deriv_within g s x := (hf.has_deriv_within_at.sub hg.has_deriv_within_at).deriv_within hxs @[simp] lemma deriv_sub (hf : differentiable_at π•œ f x) (hg : differentiable_at π•œ g x) : deriv (Ξ» y, f y - g y) x = deriv f x - deriv g x := (hf.has_deriv_at.sub hg.has_deriv_at).deriv theorem has_deriv_at_filter.is_O_sub (h : has_deriv_at_filter f f' x L) : (Ξ» x', f x' - f x) =O[L] (Ξ» x', x' - x) := has_fderiv_at_filter.is_O_sub h theorem has_deriv_at_filter.is_O_sub_rev (hf : has_deriv_at_filter f f' x L) (hf' : f' β‰  0) : (Ξ» x', x' - x) =O[L] (Ξ» x', f x' - f x) := suffices antilipschitz_with βˆ₯f'βˆ₯β‚Šβ»ΒΉ (smul_right (1 : π•œ β†’L[π•œ] π•œ) f'), from hf.is_O_sub_rev this, add_monoid_hom_class.antilipschitz_of_bound (smul_right (1 : π•œ β†’L[π•œ] π•œ) f') $ Ξ» x, by simp [norm_smul, ← div_eq_inv_mul, mul_div_cancel _ (mt norm_eq_zero.1 hf')] theorem has_deriv_at_filter.sub_const (hf : has_deriv_at_filter f f' x L) (c : F) : has_deriv_at_filter (Ξ» x, f x - c) f' x L := by simpa only [sub_eq_add_neg] using hf.add_const (-c) theorem has_deriv_within_at.sub_const (hf : has_deriv_within_at f f' s x) (c : F) : has_deriv_within_at (Ξ» x, f x - c) f' s x := hf.sub_const c theorem has_deriv_at.sub_const (hf : has_deriv_at f f' x) (c : F) : has_deriv_at (Ξ» x, f x - c) f' x := hf.sub_const c lemma deriv_within_sub_const (hxs : unique_diff_within_at π•œ s x) (c : F) : deriv_within (Ξ»y, f y - c) s x = deriv_within f s x := by simp only [deriv_within, fderiv_within_sub_const hxs] lemma deriv_sub_const (c : F) : deriv (Ξ» y, f y - c) x = deriv f x := by simp only [deriv, fderiv_sub_const] theorem has_deriv_at_filter.const_sub (c : F) (hf : has_deriv_at_filter f f' x L) : has_deriv_at_filter (Ξ» x, c - f x) (-f') x L := by simpa only [sub_eq_add_neg] using hf.neg.const_add c theorem has_deriv_within_at.const_sub (c : F) (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (Ξ» x, c - f x) (-f') s x := hf.const_sub c theorem has_strict_deriv_at.const_sub (c : F) (hf : has_strict_deriv_at f f' x) : has_strict_deriv_at (Ξ» x, c - f x) (-f') x := by simpa only [sub_eq_add_neg] using hf.neg.const_add c theorem has_deriv_at.const_sub (c : F) (hf : has_deriv_at f f' x) : has_deriv_at (Ξ» x, c - f x) (-f') x := hf.const_sub c lemma deriv_within_const_sub (hxs : unique_diff_within_at π•œ s x) (c : F) : deriv_within (Ξ»y, c - f y) s x = -deriv_within f s x := by simp [deriv_within, fderiv_within_const_sub hxs] lemma deriv_const_sub (c : F) : deriv (Ξ» y, c - f y) x = -deriv f x := by simp only [← deriv_within_univ, deriv_within_const_sub (unique_diff_within_at_univ : unique_diff_within_at π•œ _ _)] end sub section continuous /-! ### Continuity of a function admitting a derivative -/ theorem has_deriv_at_filter.tendsto_nhds (hL : L ≀ 𝓝 x) (h : has_deriv_at_filter f f' x L) : tendsto f L (𝓝 (f x)) := h.tendsto_nhds hL theorem has_deriv_within_at.continuous_within_at (h : has_deriv_within_at f f' s x) : continuous_within_at f s x := has_deriv_at_filter.tendsto_nhds inf_le_left h theorem has_deriv_at.continuous_at (h : has_deriv_at f f' x) : continuous_at f x := has_deriv_at_filter.tendsto_nhds le_rfl h protected theorem has_deriv_at.continuous_on {f f' : π•œ β†’ F} (hderiv : βˆ€ x ∈ s, has_deriv_at f (f' x) x) : continuous_on f s := Ξ» x hx, (hderiv x hx).continuous_at.continuous_within_at end continuous section cartesian_product /-! ### Derivative of the cartesian product of two functions -/ variables {G : Type w} [normed_add_comm_group G] [normed_space π•œ G] variables {fβ‚‚ : π•œ β†’ G} {fβ‚‚' : G} lemma has_deriv_at_filter.prod (hf₁ : has_deriv_at_filter f₁ f₁' x L) (hfβ‚‚ : has_deriv_at_filter fβ‚‚ fβ‚‚' x L) : has_deriv_at_filter (Ξ» x, (f₁ x, fβ‚‚ x)) (f₁', fβ‚‚') x L := hf₁.prod hfβ‚‚ lemma has_deriv_within_at.prod (hf₁ : has_deriv_within_at f₁ f₁' s x) (hfβ‚‚ : has_deriv_within_at fβ‚‚ fβ‚‚' s x) : has_deriv_within_at (Ξ» x, (f₁ x, fβ‚‚ x)) (f₁', fβ‚‚') s x := hf₁.prod hfβ‚‚ lemma has_deriv_at.prod (hf₁ : has_deriv_at f₁ f₁' x) (hfβ‚‚ : has_deriv_at fβ‚‚ fβ‚‚' x) : has_deriv_at (Ξ» x, (f₁ x, fβ‚‚ x)) (f₁', fβ‚‚') x := hf₁.prod hfβ‚‚ lemma has_strict_deriv_at.prod (hf₁ : has_strict_deriv_at f₁ f₁' x) (hfβ‚‚ : has_strict_deriv_at fβ‚‚ fβ‚‚' x) : has_strict_deriv_at (Ξ» x, (f₁ x, fβ‚‚ x)) (f₁', fβ‚‚') x := hf₁.prod hfβ‚‚ end cartesian_product section composition /-! ### Derivative of the composition of a vector function and a scalar function We use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp` in lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also because the `comp` version with the shorter name will show up much more often in applications). The formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to usual multiplication in `comp` lemmas. -/ /- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to get confused since there are too many possibilities for composition -/ variables {π•œ' : Type*} [nontrivially_normed_field π•œ'] [normed_algebra π•œ π•œ'] [normed_space π•œ' F] [is_scalar_tower π•œ π•œ' F] {s' t' : set π•œ'} {h : π•œ β†’ π•œ'} {h₁ : π•œ β†’ π•œ} {hβ‚‚ : π•œ' β†’ π•œ'} {h' hβ‚‚' : π•œ'} {h₁' : π•œ} {g₁ : π•œ' β†’ F} {g₁' : F} {L' : filter π•œ'} (x) theorem has_deriv_at_filter.scomp (hg : has_deriv_at_filter g₁ g₁' (h x) L') (hh : has_deriv_at_filter h h' x L) (hL : tendsto h L L'): has_deriv_at_filter (g₁ ∘ h) (h' β€’ g₁') x L := by simpa using ((hg.restrict_scalars π•œ).comp x hh hL).has_deriv_at_filter theorem has_deriv_within_at.scomp_has_deriv_at (hg : has_deriv_within_at g₁ g₁' s' (h x)) (hh : has_deriv_at h h' x) (hs : βˆ€ x, h x ∈ s') : has_deriv_at (g₁ ∘ h) (h' β€’ g₁') x := hg.scomp x hh $ tendsto_inf.2 ⟨hh.continuous_at, tendsto_principal.2 $ eventually_of_forall hs⟩ theorem has_deriv_within_at.scomp (hg : has_deriv_within_at g₁ g₁' t' (h x)) (hh : has_deriv_within_at h h' s x) (hst : maps_to h s t') : has_deriv_within_at (g₁ ∘ h) (h' β€’ g₁') s x := hg.scomp x hh $ hh.continuous_within_at.tendsto_nhds_within hst /-- The chain rule. -/ theorem has_deriv_at.scomp (hg : has_deriv_at g₁ g₁' (h x)) (hh : has_deriv_at h h' x) : has_deriv_at (g₁ ∘ h) (h' β€’ g₁') x := hg.scomp x hh hh.continuous_at theorem has_strict_deriv_at.scomp (hg : has_strict_deriv_at g₁ g₁' (h x)) (hh : has_strict_deriv_at h h' x) : has_strict_deriv_at (g₁ ∘ h) (h' β€’ g₁') x := by simpa using ((hg.restrict_scalars π•œ).comp x hh).has_strict_deriv_at theorem has_deriv_at.scomp_has_deriv_within_at (hg : has_deriv_at g₁ g₁' (h x)) (hh : has_deriv_within_at h h' s x) : has_deriv_within_at (g₁ ∘ h) (h' β€’ g₁') s x := has_deriv_within_at.scomp x hg.has_deriv_within_at hh (maps_to_univ _ _) lemma deriv_within.scomp (hg : differentiable_within_at π•œ' g₁ t' (h x)) (hh : differentiable_within_at π•œ h s x) (hs : maps_to h s t') (hxs : unique_diff_within_at π•œ s x) : deriv_within (g₁ ∘ h) s x = deriv_within h s x β€’ deriv_within g₁ t' (h x) := (has_deriv_within_at.scomp x hg.has_deriv_within_at hh.has_deriv_within_at hs).deriv_within hxs lemma deriv.scomp (hg : differentiable_at π•œ' g₁ (h x)) (hh : differentiable_at π•œ h x) : deriv (g₁ ∘ h) x = deriv h x β€’ deriv g₁ (h x) := (has_deriv_at.scomp x hg.has_deriv_at hh.has_deriv_at).deriv /-! ### Derivative of the composition of a scalar and vector functions -/ theorem has_deriv_at_filter.comp_has_fderiv_at_filter {f : E β†’ π•œ'} {f' : E β†’L[π•œ] π•œ'} (x) {L'' : filter E} (hhβ‚‚ : has_deriv_at_filter hβ‚‚ hβ‚‚' (f x) L') (hf : has_fderiv_at_filter f f' x L'') (hL : tendsto f L'' L') : has_fderiv_at_filter (hβ‚‚ ∘ f) (hβ‚‚' β€’ f') x L'' := by { convert (hhβ‚‚.restrict_scalars π•œ).comp x hf hL, ext x, simp [mul_comm] } theorem has_strict_deriv_at.comp_has_strict_fderiv_at {f : E β†’ π•œ'} {f' : E β†’L[π•œ] π•œ'} (x) (hh : has_strict_deriv_at hβ‚‚ hβ‚‚' (f x)) (hf : has_strict_fderiv_at f f' x) : has_strict_fderiv_at (hβ‚‚ ∘ f) (hβ‚‚' β€’ f') x := begin rw has_strict_deriv_at at hh, convert (hh.restrict_scalars π•œ).comp x hf, ext x, simp [mul_comm] end theorem has_deriv_at.comp_has_fderiv_at {f : E β†’ π•œ'} {f' : E β†’L[π•œ] π•œ'} (x) (hh : has_deriv_at hβ‚‚ hβ‚‚' (f x)) (hf : has_fderiv_at f f' x) : has_fderiv_at (hβ‚‚ ∘ f) (hβ‚‚' β€’ f') x := hh.comp_has_fderiv_at_filter x hf hf.continuous_at theorem has_deriv_at.comp_has_fderiv_within_at {f : E β†’ π•œ'} {f' : E β†’L[π•œ] π•œ'} {s} (x) (hh : has_deriv_at hβ‚‚ hβ‚‚' (f x)) (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (hβ‚‚ ∘ f) (hβ‚‚' β€’ f') s x := hh.comp_has_fderiv_at_filter x hf hf.continuous_within_at theorem has_deriv_within_at.comp_has_fderiv_within_at {f : E β†’ π•œ'} {f' : E β†’L[π•œ] π•œ'} {s t} (x) (hh : has_deriv_within_at hβ‚‚ hβ‚‚' t (f x)) (hf : has_fderiv_within_at f f' s x) (hst : maps_to f s t) : has_fderiv_within_at (hβ‚‚ ∘ f) (hβ‚‚' β€’ f') s x := hh.comp_has_fderiv_at_filter x hf $ hf.continuous_within_at.tendsto_nhds_within hst /-! ### Derivative of the composition of two scalar functions -/ theorem has_deriv_at_filter.comp (hhβ‚‚ : has_deriv_at_filter hβ‚‚ hβ‚‚' (h x) L') (hh : has_deriv_at_filter h h' x L) (hL : tendsto h L L') : has_deriv_at_filter (hβ‚‚ ∘ h) (hβ‚‚' * h') x L := by { rw mul_comm, exact hhβ‚‚.scomp x hh hL } theorem has_deriv_within_at.comp (hhβ‚‚ : has_deriv_within_at hβ‚‚ hβ‚‚' s' (h x)) (hh : has_deriv_within_at h h' s x) (hst : maps_to h s s') : has_deriv_within_at (hβ‚‚ ∘ h) (hβ‚‚' * h') s x := by { rw mul_comm, exact hhβ‚‚.scomp x hh hst, } /-- The chain rule. -/ theorem has_deriv_at.comp (hhβ‚‚ : has_deriv_at hβ‚‚ hβ‚‚' (h x)) (hh : has_deriv_at h h' x) : has_deriv_at (hβ‚‚ ∘ h) (hβ‚‚' * h') x := hhβ‚‚.comp x hh hh.continuous_at theorem has_strict_deriv_at.comp (hhβ‚‚ : has_strict_deriv_at hβ‚‚ hβ‚‚' (h x)) (hh : has_strict_deriv_at h h' x) : has_strict_deriv_at (hβ‚‚ ∘ h) (hβ‚‚' * h') x := by { rw mul_comm, exact hhβ‚‚.scomp x hh } theorem has_deriv_at.comp_has_deriv_within_at (hhβ‚‚ : has_deriv_at hβ‚‚ hβ‚‚' (h x)) (hh : has_deriv_within_at h h' s x) : has_deriv_within_at (hβ‚‚ ∘ h) (hβ‚‚' * h') s x := hhβ‚‚.has_deriv_within_at.comp x hh (maps_to_univ _ _) lemma deriv_within.comp (hhβ‚‚ : differentiable_within_at π•œ' hβ‚‚ s' (h x)) (hh : differentiable_within_at π•œ h s x) (hs : maps_to h s s') (hxs : unique_diff_within_at π•œ s x) : deriv_within (hβ‚‚ ∘ h) s x = deriv_within hβ‚‚ s' (h x) * deriv_within h s x := (hhβ‚‚.has_deriv_within_at.comp x hh.has_deriv_within_at hs).deriv_within hxs lemma deriv.comp (hhβ‚‚ : differentiable_at π•œ' hβ‚‚ (h x)) (hh : differentiable_at π•œ h x) : deriv (hβ‚‚ ∘ h) x = deriv hβ‚‚ (h x) * deriv h x := (hhβ‚‚.has_deriv_at.comp x hh.has_deriv_at).deriv protected lemma has_deriv_at_filter.iterate {f : π•œ β†’ π•œ} {f' : π•œ} (hf : has_deriv_at_filter f f' x L) (hL : tendsto f L L) (hx : f x = x) (n : β„•) : has_deriv_at_filter (f^[n]) (f'^n) x L := begin have := hf.iterate hL hx n, rwa [continuous_linear_map.smul_right_one_pow] at this end protected lemma has_deriv_at.iterate {f : π•œ β†’ π•œ} {f' : π•œ} (hf : has_deriv_at f f' x) (hx : f x = x) (n : β„•) : has_deriv_at (f^[n]) (f'^n) x := begin have := has_fderiv_at.iterate hf hx n, rwa [continuous_linear_map.smul_right_one_pow] at this end protected lemma has_deriv_within_at.iterate {f : π•œ β†’ π•œ} {f' : π•œ} (hf : has_deriv_within_at f f' s x) (hx : f x = x) (hs : maps_to f s s) (n : β„•) : has_deriv_within_at (f^[n]) (f'^n) s x := begin have := has_fderiv_within_at.iterate hf hx hs n, rwa [continuous_linear_map.smul_right_one_pow] at this end protected lemma has_strict_deriv_at.iterate {f : π•œ β†’ π•œ} {f' : π•œ} (hf : has_strict_deriv_at f f' x) (hx : f x = x) (n : β„•) : has_strict_deriv_at (f^[n]) (f'^n) x := begin have := hf.iterate hx n, rwa [continuous_linear_map.smul_right_one_pow] at this end end composition section composition_vector /-! ### Derivative of the composition of a function between vector spaces and a function on `π•œ` -/ open continuous_linear_map variables {l : F β†’ E} {l' : F β†’L[π•œ] E} variable (x) /-- The composition `l ∘ f` where `l : F β†’ E` and `f : π•œ β†’ F`, has a derivative within a set equal to the FrΓ©chet derivative of `l` applied to the derivative of `f`. -/ theorem has_fderiv_within_at.comp_has_deriv_within_at {t : set F} (hl : has_fderiv_within_at l l' t (f x)) (hf : has_deriv_within_at f f' s x) (hst : maps_to f s t) : has_deriv_within_at (l ∘ f) (l' f') s x := by simpa only [one_apply, one_smul, smul_right_apply, coe_comp', (∘)] using (hl.comp x hf.has_fderiv_within_at hst).has_deriv_within_at theorem has_fderiv_at.comp_has_deriv_within_at (hl : has_fderiv_at l l' (f x)) (hf : has_deriv_within_at f f' s x) : has_deriv_within_at (l ∘ f) (l' f') s x := hl.has_fderiv_within_at.comp_has_deriv_within_at x hf (maps_to_univ _ _) /-- The composition `l ∘ f` where `l : F β†’ E` and `f : π•œ β†’ F`, has a derivative equal to the FrΓ©chet derivative of `l` applied to the derivative of `f`. -/ theorem has_fderiv_at.comp_has_deriv_at (hl : has_fderiv_at l l' (f x)) (hf : has_deriv_at f f' x) : has_deriv_at (l ∘ f) (l' f') x := has_deriv_within_at_univ.mp $ hl.comp_has_deriv_within_at x hf.has_deriv_within_at theorem has_strict_fderiv_at.comp_has_strict_deriv_at (hl : has_strict_fderiv_at l l' (f x)) (hf : has_strict_deriv_at f f' x) : has_strict_deriv_at (l ∘ f) (l' f') x := by simpa only [one_apply, one_smul, smul_right_apply, coe_comp', (∘)] using (hl.comp x hf.has_strict_fderiv_at).has_strict_deriv_at lemma fderiv_within.comp_deriv_within {t : set F} (hl : differentiable_within_at π•œ l t (f x)) (hf : differentiable_within_at π•œ f s x) (hs : maps_to f s t) (hxs : unique_diff_within_at π•œ s x) : deriv_within (l ∘ f) s x = (fderiv_within π•œ l t (f x) : F β†’ E) (deriv_within f s x) := (hl.has_fderiv_within_at.comp_has_deriv_within_at x hf.has_deriv_within_at hs).deriv_within hxs lemma fderiv.comp_deriv (hl : differentiable_at π•œ l (f x)) (hf : differentiable_at π•œ f x) : deriv (l ∘ f) x = (fderiv π•œ l (f x) : F β†’ E) (deriv f x) := (hl.has_fderiv_at.comp_has_deriv_at x hf.has_deriv_at).deriv end composition_vector section mul /-! ### Derivative of the multiplication of two functions -/ variables {π•œ' 𝔸 : Type*} [normed_field π•œ'] [normed_ring 𝔸] [normed_algebra π•œ π•œ'] [normed_algebra π•œ 𝔸] {c d : π•œ β†’ 𝔸} {c' d' : 𝔸} {u v : π•œ β†’ π•œ'} theorem has_deriv_within_at.mul (hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) : has_deriv_within_at (Ξ» y, c y * d y) (c' * d x + c x * d') s x := begin have := (has_fderiv_within_at.mul' hc hd).has_deriv_within_at, rwa [continuous_linear_map.add_apply, continuous_linear_map.smul_apply, continuous_linear_map.smul_right_apply, continuous_linear_map.smul_right_apply, continuous_linear_map.smul_right_apply, continuous_linear_map.one_apply, one_smul, one_smul, add_comm] at this, end theorem has_deriv_at.mul (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) : has_deriv_at (Ξ» y, c y * d y) (c' * d x + c x * d') x := begin rw [← has_deriv_within_at_univ] at *, exact hc.mul hd end theorem has_strict_deriv_at.mul (hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x) : has_strict_deriv_at (Ξ» y, c y * d y) (c' * d x + c x * d') x := begin have := (has_strict_fderiv_at.mul' hc hd).has_strict_deriv_at, rwa [continuous_linear_map.add_apply, continuous_linear_map.smul_apply, continuous_linear_map.smul_right_apply, continuous_linear_map.smul_right_apply, continuous_linear_map.smul_right_apply, continuous_linear_map.one_apply, one_smul, one_smul, add_comm] at this, end lemma deriv_within_mul (hxs : unique_diff_within_at π•œ s x) (hc : differentiable_within_at π•œ c s x) (hd : differentiable_within_at π•œ d s x) : deriv_within (Ξ» y, c y * d y) s x = deriv_within c s x * d x + c x * deriv_within d s x := (hc.has_deriv_within_at.mul hd.has_deriv_within_at).deriv_within hxs @[simp] lemma deriv_mul (hc : differentiable_at π•œ c x) (hd : differentiable_at π•œ d x) : deriv (Ξ» y, c y * d y) x = deriv c x * d x + c x * deriv d x := (hc.has_deriv_at.mul hd.has_deriv_at).deriv theorem has_deriv_within_at.mul_const (hc : has_deriv_within_at c c' s x) (d : 𝔸) : has_deriv_within_at (Ξ» y, c y * d) (c' * d) s x := begin convert hc.mul (has_deriv_within_at_const x s d), rw [mul_zero, add_zero] end theorem has_deriv_at.mul_const (hc : has_deriv_at c c' x) (d : 𝔸) : has_deriv_at (Ξ» y, c y * d) (c' * d) x := begin rw [← has_deriv_within_at_univ] at *, exact hc.mul_const d end theorem has_deriv_at_mul_const (c : π•œ) : has_deriv_at (Ξ» x, x * c) c x := by simpa only [one_mul] using (has_deriv_at_id' x).mul_const c theorem has_strict_deriv_at.mul_const (hc : has_strict_deriv_at c c' x) (d : 𝔸) : has_strict_deriv_at (Ξ» y, c y * d) (c' * d) x := begin convert hc.mul (has_strict_deriv_at_const x d), rw [mul_zero, add_zero] end lemma deriv_within_mul_const (hxs : unique_diff_within_at π•œ s x) (hc : differentiable_within_at π•œ c s x) (d : 𝔸) : deriv_within (Ξ» y, c y * d) s x = deriv_within c s x * d := (hc.has_deriv_within_at.mul_const d).deriv_within hxs lemma deriv_mul_const (hc : differentiable_at π•œ c x) (d : 𝔸) : deriv (Ξ» y, c y * d) x = deriv c x * d := (hc.has_deriv_at.mul_const d).deriv lemma deriv_mul_const_field (v : π•œ') : deriv (Ξ» y, u y * v) x = deriv u x * v := begin by_cases hu : differentiable_at π•œ u x, { exact deriv_mul_const hu v }, { rw [deriv_zero_of_not_differentiable_at hu, zero_mul], rcases eq_or_ne v 0 with rfl|hd, { simp only [mul_zero, deriv_const] }, { refine deriv_zero_of_not_differentiable_at (mt (Ξ» H, _) hu), simpa only [mul_inv_cancel_rightβ‚€ hd] using H.mul_const v⁻¹ } } end @[simp] lemma deriv_mul_const_field' (v : π•œ') : deriv (Ξ» x, u x * v) = Ξ» x, deriv u x * v := funext $ Ξ» _, deriv_mul_const_field v theorem has_deriv_within_at.const_mul (c : 𝔸) (hd : has_deriv_within_at d d' s x) : has_deriv_within_at (Ξ» y, c * d y) (c * d') s x := begin convert (has_deriv_within_at_const x s c).mul hd, rw [zero_mul, zero_add] end theorem has_deriv_at.const_mul (c : 𝔸) (hd : has_deriv_at d d' x) : has_deriv_at (Ξ» y, c * d y) (c * d') x := begin rw [← has_deriv_within_at_univ] at *, exact hd.const_mul c end theorem has_strict_deriv_at.const_mul (c : 𝔸) (hd : has_strict_deriv_at d d' x) : has_strict_deriv_at (Ξ» y, c * d y) (c * d') x := begin convert (has_strict_deriv_at_const _ _).mul hd, rw [zero_mul, zero_add] end lemma deriv_within_const_mul (hxs : unique_diff_within_at π•œ s x) (c : 𝔸) (hd : differentiable_within_at π•œ d s x) : deriv_within (Ξ» y, c * d y) s x = c * deriv_within d s x := (hd.has_deriv_within_at.const_mul c).deriv_within hxs lemma deriv_const_mul (c : 𝔸) (hd : differentiable_at π•œ d x) : deriv (Ξ» y, c * d y) x = c * deriv d x := (hd.has_deriv_at.const_mul c).deriv lemma deriv_const_mul_field (u : π•œ') : deriv (Ξ» y, u * v y) x = u * deriv v x := by simp only [mul_comm u, deriv_mul_const_field] @[simp] lemma deriv_const_mul_field' (u : π•œ') : deriv (Ξ» x, u * v x) = Ξ» x, u * deriv v x := funext (Ξ» x, deriv_const_mul_field u) end mul section inverse /-! ### Derivative of `x ↦ x⁻¹` -/ theorem has_strict_deriv_at_inv (hx : x β‰  0) : has_strict_deriv_at has_inv.inv (-(x^2)⁻¹) x := begin suffices : (Ξ» p : π•œ Γ— π•œ, (p.1 - p.2) * ((x * x)⁻¹ - (p.1 * p.2)⁻¹)) =o[𝓝 (x, x)] (Ξ» p, (p.1 - p.2) * 1), { refine this.congr' _ (eventually_of_forall $ Ξ» _, mul_one _), refine eventually.mono (is_open.mem_nhds (is_open_ne.prod is_open_ne) ⟨hx, hx⟩) _, rintro ⟨y, z⟩ ⟨hy, hz⟩, simp only [mem_set_of_eq] at hy hz, -- hy : y β‰  0, hz : z β‰  0 field_simp [hx, hy, hz], ring, }, refine (is_O_refl (Ξ» p : π•œ Γ— π•œ, p.1 - p.2) _).mul_is_o ((is_o_one_iff _).2 _), rw [← sub_self (x * x)⁻¹], exact tendsto_const_nhds.sub ((continuous_mul.tendsto (x, x)).invβ‚€ $ mul_ne_zero hx hx) end theorem has_deriv_at_inv (x_ne_zero : x β‰  0) : has_deriv_at (Ξ»y, y⁻¹) (-(x^2)⁻¹) x := (has_strict_deriv_at_inv x_ne_zero).has_deriv_at theorem has_deriv_within_at_inv (x_ne_zero : x β‰  0) (s : set π•œ) : has_deriv_within_at (Ξ»x, x⁻¹) (-(x^2)⁻¹) s x := (has_deriv_at_inv x_ne_zero).has_deriv_within_at lemma differentiable_at_inv : differentiable_at π•œ (Ξ»x, x⁻¹) x ↔ x β‰  0:= ⟨λ H, normed_field.continuous_at_inv.1 H.continuous_at, Ξ» H, (has_deriv_at_inv H).differentiable_at⟩ lemma differentiable_within_at_inv (x_ne_zero : x β‰  0) : differentiable_within_at π•œ (Ξ»x, x⁻¹) s x := (differentiable_at_inv.2 x_ne_zero).differentiable_within_at lemma differentiable_on_inv : differentiable_on π•œ (Ξ»x:π•œ, x⁻¹) {x | x β‰  0} := Ξ»x hx, differentiable_within_at_inv hx lemma deriv_inv : deriv (Ξ»x, x⁻¹) x = -(x^2)⁻¹ := begin rcases eq_or_ne x 0 with rfl|hne, { simp [deriv_zero_of_not_differentiable_at (mt differentiable_at_inv.1 (not_not.2 rfl))] }, { exact (has_deriv_at_inv hne).deriv } end @[simp] lemma deriv_inv' : deriv (Ξ» x : π•œ, x⁻¹) = Ξ» x, -(x ^ 2)⁻¹ := funext (Ξ» x, deriv_inv) lemma deriv_within_inv (x_ne_zero : x β‰  0) (hxs : unique_diff_within_at π•œ s x) : deriv_within (Ξ»x, x⁻¹) s x = -(x^2)⁻¹ := begin rw differentiable_at.deriv_within (differentiable_at_inv.2 x_ne_zero) hxs, exact deriv_inv end lemma has_fderiv_at_inv (x_ne_zero : x β‰  0) : has_fderiv_at (Ξ»x, x⁻¹) (smul_right (1 : π•œ β†’L[π•œ] π•œ) (-(x^2)⁻¹) : π•œ β†’L[π•œ] π•œ) x := has_deriv_at_inv x_ne_zero lemma has_fderiv_within_at_inv (x_ne_zero : x β‰  0) : has_fderiv_within_at (Ξ»x, x⁻¹) (smul_right (1 : π•œ β†’L[π•œ] π•œ) (-(x^2)⁻¹) : π•œ β†’L[π•œ] π•œ) s x := (has_fderiv_at_inv x_ne_zero).has_fderiv_within_at lemma fderiv_inv : fderiv π•œ (Ξ»x, x⁻¹) x = smul_right (1 : π•œ β†’L[π•œ] π•œ) (-(x^2)⁻¹) := by rw [← deriv_fderiv, deriv_inv] lemma fderiv_within_inv (x_ne_zero : x β‰  0) (hxs : unique_diff_within_at π•œ s x) : fderiv_within π•œ (Ξ»x, x⁻¹) s x = smul_right (1 : π•œ β†’L[π•œ] π•œ) (-(x^2)⁻¹) := begin rw differentiable_at.fderiv_within (differentiable_at_inv.2 x_ne_zero) hxs, exact fderiv_inv end variables {c : π•œ β†’ π•œ} {c' : π•œ} lemma has_deriv_within_at.inv (hc : has_deriv_within_at c c' s x) (hx : c x β‰  0) : has_deriv_within_at (Ξ» y, (c y)⁻¹) (- c' / (c x)^2) s x := begin convert (has_deriv_at_inv hx).comp_has_deriv_within_at x hc, field_simp end lemma has_deriv_at.inv (hc : has_deriv_at c c' x) (hx : c x β‰  0) : has_deriv_at (Ξ» y, (c y)⁻¹) (- c' / (c x)^2) x := begin rw ← has_deriv_within_at_univ at *, exact hc.inv hx end lemma differentiable_within_at.inv (hc : differentiable_within_at π•œ c s x) (hx : c x β‰  0) : differentiable_within_at π•œ (Ξ»x, (c x)⁻¹) s x := (hc.has_deriv_within_at.inv hx).differentiable_within_at @[simp] lemma differentiable_at.inv (hc : differentiable_at π•œ c x) (hx : c x β‰  0) : differentiable_at π•œ (Ξ»x, (c x)⁻¹) x := (hc.has_deriv_at.inv hx).differentiable_at lemma differentiable_on.inv (hc : differentiable_on π•œ c s) (hx : βˆ€ x ∈ s, c x β‰  0) : differentiable_on π•œ (Ξ»x, (c x)⁻¹) s := Ξ»x h, (hc x h).inv (hx x h) @[simp] lemma differentiable.inv (hc : differentiable π•œ c) (hx : βˆ€ x, c x β‰  0) : differentiable π•œ (Ξ»x, (c x)⁻¹) := Ξ»x, (hc x).inv (hx x) lemma deriv_within_inv' (hc : differentiable_within_at π•œ c s x) (hx : c x β‰  0) (hxs : unique_diff_within_at π•œ s x) : deriv_within (Ξ»x, (c x)⁻¹) s x = - (deriv_within c s x) / (c x)^2 := (hc.has_deriv_within_at.inv hx).deriv_within hxs @[simp] lemma deriv_inv'' (hc : differentiable_at π•œ c x) (hx : c x β‰  0) : deriv (Ξ»x, (c x)⁻¹) x = - (deriv c x) / (c x)^2 := (hc.has_deriv_at.inv hx).deriv end inverse section division /-! ### Derivative of `x ↦ c x / d x` -/ variables {π•œ' : Type*} [nontrivially_normed_field π•œ'] [normed_algebra π•œ π•œ'] {c d : π•œ β†’ π•œ'} {c' d' : π•œ'} lemma has_deriv_within_at.div (hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) (hx : d x β‰  0) : has_deriv_within_at (Ξ» y, c y / d y) ((c' * d x - c x * d') / (d x)^2) s x := begin convert hc.mul ((has_deriv_at_inv hx).comp_has_deriv_within_at x hd), { simp only [div_eq_mul_inv] }, { field_simp, ring } end lemma has_strict_deriv_at.div (hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x) (hx : d x β‰  0) : has_strict_deriv_at (Ξ» y, c y / d y) ((c' * d x - c x * d') / (d x)^2) x := begin convert hc.mul ((has_strict_deriv_at_inv hx).comp x hd), { simp only [div_eq_mul_inv] }, { field_simp, ring } end lemma has_deriv_at.div (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) (hx : d x β‰  0) : has_deriv_at (Ξ» y, c y / d y) ((c' * d x - c x * d') / (d x)^2) x := begin rw ← has_deriv_within_at_univ at *, exact hc.div hd hx end lemma differentiable_within_at.div (hc : differentiable_within_at π•œ c s x) (hd : differentiable_within_at π•œ d s x) (hx : d x β‰  0) : differentiable_within_at π•œ (Ξ»x, c x / d x) s x := ((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).differentiable_within_at @[simp] lemma differentiable_at.div (hc : differentiable_at π•œ c x) (hd : differentiable_at π•œ d x) (hx : d x β‰  0) : differentiable_at π•œ (Ξ»x, c x / d x) x := ((hc.has_deriv_at).div (hd.has_deriv_at) hx).differentiable_at lemma differentiable_on.div (hc : differentiable_on π•œ c s) (hd : differentiable_on π•œ d s) (hx : βˆ€ x ∈ s, d x β‰  0) : differentiable_on π•œ (Ξ»x, c x / d x) s := Ξ»x h, (hc x h).div (hd x h) (hx x h) @[simp] lemma differentiable.div (hc : differentiable π•œ c) (hd : differentiable π•œ d) (hx : βˆ€ x, d x β‰  0) : differentiable π•œ (Ξ»x, c x / d x) := Ξ»x, (hc x).div (hd x) (hx x) lemma deriv_within_div (hc : differentiable_within_at π•œ c s x) (hd : differentiable_within_at π•œ d s x) (hx : d x β‰  0) (hxs : unique_diff_within_at π•œ s x) : deriv_within (Ξ»x, c x / d x) s x = ((deriv_within c s x) * d x - c x * (deriv_within d s x)) / (d x)^2 := ((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).deriv_within hxs @[simp] lemma deriv_div (hc : differentiable_at π•œ c x) (hd : differentiable_at π•œ d x) (hx : d x β‰  0) : deriv (Ξ»x, c x / d x) x = ((deriv c x) * d x - c x * (deriv d x)) / (d x)^2 := ((hc.has_deriv_at).div (hd.has_deriv_at) hx).deriv lemma has_deriv_at.div_const (hc : has_deriv_at c c' x) (d : π•œ') : has_deriv_at (Ξ» x, c x / d) (c' / d) x := by simpa only [div_eq_mul_inv] using hc.mul_const d⁻¹ lemma has_deriv_within_at.div_const (hc : has_deriv_within_at c c' s x) (d : π•œ') : has_deriv_within_at (Ξ» x, c x / d) (c' / d) s x := by simpa only [div_eq_mul_inv] using hc.mul_const d⁻¹ lemma has_strict_deriv_at.div_const (hc : has_strict_deriv_at c c' x) (d : π•œ') : has_strict_deriv_at (Ξ» x, c x / d) (c' / d) x := by simpa only [div_eq_mul_inv] using hc.mul_const d⁻¹ lemma differentiable_within_at.div_const (hc : differentiable_within_at π•œ c s x) {d : π•œ'} : differentiable_within_at π•œ (Ξ»x, c x / d) s x := (hc.has_deriv_within_at.div_const _).differentiable_within_at @[simp] lemma differentiable_at.div_const (hc : differentiable_at π•œ c x) {d : π•œ'} : differentiable_at π•œ (Ξ» x, c x / d) x := (hc.has_deriv_at.div_const _).differentiable_at lemma differentiable_on.div_const (hc : differentiable_on π•œ c s) {d : π•œ'} : differentiable_on π•œ (Ξ»x, c x / d) s := Ξ» x hx, (hc x hx).div_const @[simp] lemma differentiable.div_const (hc : differentiable π•œ c) {d : π•œ'} : differentiable π•œ (Ξ»x, c x / d) := Ξ» x, (hc x).div_const lemma deriv_within_div_const (hc : differentiable_within_at π•œ c s x) {d : π•œ'} (hxs : unique_diff_within_at π•œ s x) : deriv_within (Ξ»x, c x / d) s x = (deriv_within c s x) / d := by simp [div_eq_inv_mul, deriv_within_const_mul, hc, hxs] @[simp] lemma deriv_div_const (d : π•œ') : deriv (Ξ»x, c x / d) x = (deriv c x) / d := by simp only [div_eq_mul_inv, deriv_mul_const_field] end division section clm_comp_apply /-! ### Derivative of the pointwise composition/application of continuous linear maps -/ open continuous_linear_map variables {G : Type*} [normed_add_comm_group G] [normed_space π•œ G] {c : π•œ β†’ F β†’L[π•œ] G} {c' : F β†’L[π•œ] G} {d : π•œ β†’ E β†’L[π•œ] F} {d' : E β†’L[π•œ] F} {u : π•œ β†’ F} {u' : F} lemma has_strict_deriv_at.clm_comp (hc : has_strict_deriv_at c c' x) (hd : has_strict_deriv_at d d' x) : has_strict_deriv_at (Ξ» y, (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') x := begin have := (hc.has_strict_fderiv_at.clm_comp hd.has_strict_fderiv_at).has_strict_deriv_at, rwa [add_apply, comp_apply, comp_apply, smul_right_apply, smul_right_apply, one_apply, one_smul, one_smul, add_comm] at this, end lemma has_deriv_within_at.clm_comp (hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) : has_deriv_within_at (Ξ» y, (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') s x := begin have := (hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).has_deriv_within_at, rwa [add_apply, comp_apply, comp_apply, smul_right_apply, smul_right_apply, one_apply, one_smul, one_smul, add_comm] at this, end lemma has_deriv_at.clm_comp (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) : has_deriv_at (Ξ» y, (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') x := begin rw [← has_deriv_within_at_univ] at *, exact hc.clm_comp hd end lemma deriv_within_clm_comp (hc : differentiable_within_at π•œ c s x) (hd : differentiable_within_at π•œ d s x) (hxs : unique_diff_within_at π•œ s x): deriv_within (Ξ» y, (c y).comp (d y)) s x = ((deriv_within c s x).comp (d x) + (c x).comp (deriv_within d s x)) := (hc.has_deriv_within_at.clm_comp hd.has_deriv_within_at).deriv_within hxs lemma deriv_clm_comp (hc : differentiable_at π•œ c x) (hd : differentiable_at π•œ d x) : deriv (Ξ» y, (c y).comp (d y)) x = ((deriv c x).comp (d x) + (c x).comp (deriv d x)) := (hc.has_deriv_at.clm_comp hd.has_deriv_at).deriv lemma has_strict_deriv_at.clm_apply (hc : has_strict_deriv_at c c' x) (hu : has_strict_deriv_at u u' x) : has_strict_deriv_at (Ξ» y, (c y) (u y)) (c' (u x) + c x u') x := begin have := (hc.has_strict_fderiv_at.clm_apply hu.has_strict_fderiv_at).has_strict_deriv_at, rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul, one_smul, add_comm] at this, end lemma has_deriv_within_at.clm_apply (hc : has_deriv_within_at c c' s x) (hu : has_deriv_within_at u u' s x) : has_deriv_within_at (Ξ» y, (c y) (u y)) (c' (u x) + c x u') s x := begin have := (hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).has_deriv_within_at, rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul, one_smul, add_comm] at this, end lemma has_deriv_at.clm_apply (hc : has_deriv_at c c' x) (hu : has_deriv_at u u' x) : has_deriv_at (Ξ» y, (c y) (u y)) (c' (u x) + c x u') x := begin have := (hc.has_fderiv_at.clm_apply hu.has_fderiv_at).has_deriv_at, rwa [add_apply, comp_apply, flip_apply, smul_right_apply, smul_right_apply, one_apply, one_smul, one_smul, add_comm] at this, end lemma deriv_within_clm_apply (hxs : unique_diff_within_at π•œ s x) (hc : differentiable_within_at π•œ c s x) (hu : differentiable_within_at π•œ u s x) : deriv_within (Ξ» y, (c y) (u y)) s x = (deriv_within c s x (u x) + c x (deriv_within u s x)) := (hc.has_deriv_within_at.clm_apply hu.has_deriv_within_at).deriv_within hxs lemma deriv_clm_apply (hc : differentiable_at π•œ c x) (hu : differentiable_at π•œ u x) : deriv (Ξ» y, (c y) (u y)) x = (deriv c x (u x) + c x (deriv u x)) := (hc.has_deriv_at.clm_apply hu.has_deriv_at).deriv end clm_comp_apply theorem has_strict_deriv_at.has_strict_fderiv_at_equiv {f : π•œ β†’ π•œ} {f' x : π•œ} (hf : has_strict_deriv_at f f' x) (hf' : f' β‰  0) : has_strict_fderiv_at f (continuous_linear_equiv.units_equiv_aut π•œ (units.mk0 f' hf') : π•œ β†’L[π•œ] π•œ) x := hf theorem has_deriv_at.has_fderiv_at_equiv {f : π•œ β†’ π•œ} {f' x : π•œ} (hf : has_deriv_at f f' x) (hf' : f' β‰  0) : has_fderiv_at f (continuous_linear_equiv.units_equiv_aut π•œ (units.mk0 f' hf') : π•œ β†’L[π•œ] π•œ) x := hf /-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an invertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'⁻¹` at `a` in the strict sense. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem has_strict_deriv_at.of_local_left_inverse {f g : π•œ β†’ π•œ} {f' a : π•œ} (hg : continuous_at g a) (hf : has_strict_deriv_at f f' (g a)) (hf' : f' β‰  0) (hfg : βˆ€αΆ  y in 𝓝 a, f (g y) = y) : has_strict_deriv_at g f'⁻¹ a := (hf.has_strict_fderiv_at_equiv hf').of_local_left_inverse hg hfg /-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has a nonzero derivative `f'` at `f.symm a` in the strict sense, then `f.symm` has the derivative `f'⁻¹` at `a` in the strict sense. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ lemma local_homeomorph.has_strict_deriv_at_symm (f : local_homeomorph π•œ π•œ) {a f' : π•œ} (ha : a ∈ f.target) (hf' : f' β‰  0) (htff' : has_strict_deriv_at f f' (f.symm a)) : has_strict_deriv_at f.symm f'⁻¹ a := htff'.of_local_left_inverse (f.symm.continuous_at ha) hf' (f.eventually_right_inverse ha) /-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an invertible derivative `f'` at `g a`, then `g` has the derivative `f'⁻¹` at `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem has_deriv_at.of_local_left_inverse {f g : π•œ β†’ π•œ} {f' a : π•œ} (hg : continuous_at g a) (hf : has_deriv_at f f' (g a)) (hf' : f' β‰  0) (hfg : βˆ€αΆ  y in 𝓝 a, f (g y) = y) : has_deriv_at g f'⁻¹ a := (hf.has_fderiv_at_equiv hf').of_local_left_inverse hg hfg /-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an nonzero derivative `f'` at `f.symm a`, then `f.symm` has the derivative `f'⁻¹` at `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ lemma local_homeomorph.has_deriv_at_symm (f : local_homeomorph π•œ π•œ) {a f' : π•œ} (ha : a ∈ f.target) (hf' : f' β‰  0) (htff' : has_deriv_at f f' (f.symm a)) : has_deriv_at f.symm f'⁻¹ a := htff'.of_local_left_inverse (f.symm.continuous_at ha) hf' (f.eventually_right_inverse ha) lemma has_deriv_at.eventually_ne (h : has_deriv_at f f' x) (hf' : f' β‰  0) : βˆ€αΆ  z in 𝓝[β‰ ] x, f z β‰  f x := (has_deriv_at_iff_has_fderiv_at.1 h).eventually_ne ⟨βˆ₯f'βˆ₯⁻¹, Ξ» z, by field_simp [norm_smul, mt norm_eq_zero.1 hf']⟩ lemma has_deriv_at.tendsto_punctured_nhds (h : has_deriv_at f f' x) (hf' : f' β‰  0) : tendsto f (𝓝[β‰ ] x) (𝓝[β‰ ] (f x)) := tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ h.continuous_at.continuous_within_at (h.eventually_ne hf') theorem not_differentiable_within_at_of_local_left_inverse_has_deriv_within_at_zero {f g : π•œ β†’ π•œ} {a : π•œ} {s t : set π•œ} (ha : a ∈ s) (hsu : unique_diff_within_at π•œ s a) (hf : has_deriv_within_at f 0 t (g a)) (hst : maps_to g s t) (hfg : f ∘ g =αΆ [𝓝[s] a] id) : Β¬differentiable_within_at π•œ g s a := begin intro hg, have := (hf.comp a hg.has_deriv_within_at hst).congr_of_eventually_eq_of_mem hfg.symm ha, simpa using hsu.eq_deriv _ this (has_deriv_within_at_id _ _) end theorem not_differentiable_at_of_local_left_inverse_has_deriv_at_zero {f g : π•œ β†’ π•œ} {a : π•œ} (hf : has_deriv_at f 0 (g a)) (hfg : f ∘ g =αΆ [𝓝 a] id) : Β¬differentiable_at π•œ g a := begin intro hg, have := (hf.comp a hg.has_deriv_at).congr_of_eventually_eq hfg.symm, simpa using this.unique (has_deriv_at_id a) end end namespace polynomial /-! ### Derivative of a polynomial -/ variables {x : π•œ} {s : set π•œ} variable (p : π•œ[X]) /-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/ protected lemma has_strict_deriv_at (x : π•œ) : has_strict_deriv_at (Ξ»x, p.eval x) (p.derivative.eval x) x := begin apply p.induction_on, { simp [has_strict_deriv_at_const] }, { assume p q hp hq, convert hp.add hq; simp }, { assume n a h, convert h.mul (has_strict_deriv_at_id x), { ext y, simp [pow_add, mul_assoc] }, { simp [pow_add], ring } } end /-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/ protected lemma has_deriv_at (x : π•œ) : has_deriv_at (Ξ»x, p.eval x) (p.derivative.eval x) x := (p.has_strict_deriv_at x).has_deriv_at protected theorem has_deriv_within_at (x : π•œ) (s : set π•œ) : has_deriv_within_at (Ξ»x, p.eval x) (p.derivative.eval x) s x := (p.has_deriv_at x).has_deriv_within_at protected lemma differentiable_at : differentiable_at π•œ (Ξ»x, p.eval x) x := (p.has_deriv_at x).differentiable_at protected lemma differentiable_within_at : differentiable_within_at π•œ (Ξ»x, p.eval x) s x := p.differentiable_at.differentiable_within_at protected lemma differentiable : differentiable π•œ (Ξ»x, p.eval x) := Ξ»x, p.differentiable_at protected lemma differentiable_on : differentiable_on π•œ (Ξ»x, p.eval x) s := p.differentiable.differentiable_on @[simp] protected lemma deriv : deriv (Ξ»x, p.eval x) x = p.derivative.eval x := (p.has_deriv_at x).deriv protected lemma deriv_within (hxs : unique_diff_within_at π•œ s x) : deriv_within (Ξ»x, p.eval x) s x = p.derivative.eval x := begin rw differentiable_at.deriv_within p.differentiable_at hxs, exact p.deriv end protected lemma has_fderiv_at (x : π•œ) : has_fderiv_at (Ξ»x, p.eval x) (smul_right (1 : π•œ β†’L[π•œ] π•œ) (p.derivative.eval x)) x := p.has_deriv_at x protected lemma has_fderiv_within_at (x : π•œ) : has_fderiv_within_at (Ξ»x, p.eval x) (smul_right (1 : π•œ β†’L[π•œ] π•œ) (p.derivative.eval x)) s x := (p.has_fderiv_at x).has_fderiv_within_at @[simp] protected lemma fderiv : fderiv π•œ (Ξ»x, p.eval x) x = smul_right (1 : π•œ β†’L[π•œ] π•œ) (p.derivative.eval x) := (p.has_fderiv_at x).fderiv protected lemma fderiv_within (hxs : unique_diff_within_at π•œ s x) : fderiv_within π•œ (Ξ»x, p.eval x) s x = smul_right (1 : π•œ β†’L[π•œ] π•œ) (p.derivative.eval x) := (p.has_fderiv_within_at x).fderiv_within hxs end polynomial section pow /-! ### Derivative of `x ↦ x^n` for `n : β„•` -/ variables {x : π•œ} {s : set π•œ} {c : π•œ β†’ π•œ} {c' : π•œ} variable (n : β„•) lemma has_strict_deriv_at_pow (n : β„•) (x : π•œ) : has_strict_deriv_at (Ξ»x, x^n) ((n : π•œ) * x^(n-1)) x := begin convert (polynomial.C (1 : π•œ) * (polynomial.X)^n).has_strict_deriv_at x, { simp }, { rw [polynomial.derivative_C_mul_X_pow], simp } end lemma has_deriv_at_pow (n : β„•) (x : π•œ) : has_deriv_at (Ξ»x, x^n) ((n : π•œ) * x^(n-1)) x := (has_strict_deriv_at_pow n x).has_deriv_at theorem has_deriv_within_at_pow (n : β„•) (x : π•œ) (s : set π•œ) : has_deriv_within_at (Ξ»x, x^n) ((n : π•œ) * x^(n-1)) s x := (has_deriv_at_pow n x).has_deriv_within_at lemma differentiable_at_pow : differentiable_at π•œ (Ξ»x, x^n) x := (has_deriv_at_pow n x).differentiable_at lemma differentiable_within_at_pow : differentiable_within_at π•œ (Ξ»x, x^n) s x := (differentiable_at_pow n).differentiable_within_at lemma differentiable_pow : differentiable π•œ (Ξ»x:π•œ, x^n) := Ξ» x, differentiable_at_pow n lemma differentiable_on_pow : differentiable_on π•œ (Ξ»x, x^n) s := (differentiable_pow n).differentiable_on lemma deriv_pow : deriv (Ξ» x, x^n) x = (n : π•œ) * x^(n-1) := (has_deriv_at_pow n x).deriv @[simp] lemma deriv_pow' : deriv (Ξ» x, x^n) = Ξ» x, (n : π•œ) * x^(n-1) := funext $ Ξ» x, deriv_pow n lemma deriv_within_pow (hxs : unique_diff_within_at π•œ s x) : deriv_within (Ξ»x, x^n) s x = (n : π•œ) * x^(n-1) := (has_deriv_within_at_pow n x s).deriv_within hxs lemma has_deriv_within_at.pow (hc : has_deriv_within_at c c' s x) : has_deriv_within_at (Ξ» y, (c y)^n) ((n : π•œ) * (c x)^(n-1) * c') s x := (has_deriv_at_pow n (c x)).comp_has_deriv_within_at x hc lemma has_deriv_at.pow (hc : has_deriv_at c c' x) : has_deriv_at (Ξ» y, (c y)^n) ((n : π•œ) * (c x)^(n-1) * c') x := by { rw ← has_deriv_within_at_univ at *, exact hc.pow n } lemma deriv_within_pow' (hc : differentiable_within_at π•œ c s x) (hxs : unique_diff_within_at π•œ s x) : deriv_within (Ξ»x, (c x)^n) s x = (n : π•œ) * (c x)^(n-1) * (deriv_within c s x) := (hc.has_deriv_within_at.pow n).deriv_within hxs @[simp] lemma deriv_pow'' (hc : differentiable_at π•œ c x) : deriv (Ξ»x, (c x)^n) x = (n : π•œ) * (c x)^(n-1) * (deriv c x) := (hc.has_deriv_at.pow n).deriv end pow section zpow /-! ### Derivative of `x ↦ x^m` for `m : β„€` -/ variables {E : Type*} [normed_add_comm_group E] [normed_space π•œ E] {x : π•œ} {s : set π•œ} {m : β„€} lemma has_strict_deriv_at_zpow (m : β„€) (x : π•œ) (h : x β‰  0 ∨ 0 ≀ m) : has_strict_deriv_at (Ξ»x, x^m) ((m : π•œ) * x^(m-1)) x := begin have : βˆ€ m : β„€, 0 < m β†’ has_strict_deriv_at (Ξ»x, x^m) ((m:π•œ) * x^(m-1)) x, { assume m hm, lift m to β„• using (le_of_lt hm), simp only [zpow_coe_nat, int.cast_coe_nat], convert has_strict_deriv_at_pow _ _ using 2, rw [← int.coe_nat_one, ← int.coe_nat_sub, zpow_coe_nat], norm_cast at hm, exact nat.succ_le_of_lt hm }, rcases lt_trichotomy m 0 with hm|hm|hm, { have hx : x β‰  0, from h.resolve_right hm.not_le, have := (has_strict_deriv_at_inv _).scomp _ (this (-m) (neg_pos.2 hm)); [skip, exact zpow_ne_zero_of_ne_zero hx _], simp only [(∘), zpow_neg, one_div, inv_inv, smul_eq_mul] at this, convert this using 1, rw [sq, mul_inv, inv_inv, int.cast_neg, neg_mul, neg_mul_neg, ← zpow_addβ‚€ hx, mul_assoc, ← zpow_addβ‚€ hx], congr, abel }, { simp only [hm, zpow_zero, int.cast_zero, zero_mul, has_strict_deriv_at_const] }, { exact this m hm } end lemma has_deriv_at_zpow (m : β„€) (x : π•œ) (h : x β‰  0 ∨ 0 ≀ m) : has_deriv_at (Ξ»x, x^m) ((m : π•œ) * x^(m-1)) x := (has_strict_deriv_at_zpow m x h).has_deriv_at theorem has_deriv_within_at_zpow (m : β„€) (x : π•œ) (h : x β‰  0 ∨ 0 ≀ m) (s : set π•œ) : has_deriv_within_at (Ξ»x, x^m) ((m : π•œ) * x^(m-1)) s x := (has_deriv_at_zpow m x h).has_deriv_within_at lemma differentiable_at_zpow : differentiable_at π•œ (Ξ»x, x^m) x ↔ x β‰  0 ∨ 0 ≀ m := ⟨λ H, normed_field.continuous_at_zpow.1 H.continuous_at, Ξ» H, (has_deriv_at_zpow m x H).differentiable_at⟩ lemma differentiable_within_at_zpow (m : β„€) (x : π•œ) (h : x β‰  0 ∨ 0 ≀ m) : differentiable_within_at π•œ (Ξ»x, x^m) s x := (differentiable_at_zpow.mpr h).differentiable_within_at lemma differentiable_on_zpow (m : β„€) (s : set π•œ) (h : (0 : π•œ) βˆ‰ s ∨ 0 ≀ m) : differentiable_on π•œ (Ξ»x, x^m) s := Ξ» x hxs, differentiable_within_at_zpow m x $ h.imp_left $ ne_of_mem_of_not_mem hxs lemma deriv_zpow (m : β„€) (x : π•œ) : deriv (Ξ» x, x ^ m) x = m * x ^ (m - 1) := begin by_cases H : x β‰  0 ∨ 0 ≀ m, { exact (has_deriv_at_zpow m x H).deriv }, { rw deriv_zero_of_not_differentiable_at (mt differentiable_at_zpow.1 H), push_neg at H, rcases H with ⟨rfl, hm⟩, rw [zero_zpow _ ((sub_one_lt _).trans hm).ne, mul_zero] } end @[simp] lemma deriv_zpow' (m : β„€) : deriv (Ξ» x : π•œ, x ^ m) = Ξ» x, m * x ^ (m - 1) := funext $ deriv_zpow m lemma deriv_within_zpow (hxs : unique_diff_within_at π•œ s x) (h : x β‰  0 ∨ 0 ≀ m) : deriv_within (Ξ»x, x^m) s x = (m : π•œ) * x^(m-1) := (has_deriv_within_at_zpow m x h s).deriv_within hxs @[simp] lemma iter_deriv_zpow' (m : β„€) (k : β„•) : deriv^[k] (Ξ» x : π•œ, x ^ m) = Ξ» x, (∏ i in finset.range k, (m - i)) * x ^ (m - k) := begin induction k with k ihk, { simp only [one_mul, int.coe_nat_zero, id, sub_zero, finset.prod_range_zero, function.iterate_zero] }, { simp only [function.iterate_succ_apply', ihk, deriv_const_mul_field', deriv_zpow', finset.prod_range_succ, int.coe_nat_succ, ← sub_sub, int.cast_sub, int.cast_coe_nat, mul_assoc], } end lemma iter_deriv_zpow (m : β„€) (x : π•œ) (k : β„•) : deriv^[k] (Ξ» y, y ^ m) x = (∏ i in finset.range k, (m - i)) * x ^ (m - k) := congr_fun (iter_deriv_zpow' m k) x lemma iter_deriv_pow (n : β„•) (x : π•œ) (k : β„•) : deriv^[k] (Ξ»x:π•œ, x^n) x = (∏ i in finset.range k, (n - i)) * x^(n-k) := begin simp only [← zpow_coe_nat, iter_deriv_zpow, int.cast_coe_nat], cases le_or_lt k n with hkn hnk, { rw int.coe_nat_sub hkn }, { have : ∏ i in finset.range k, (n - i : π•œ) = 0, from finset.prod_eq_zero (finset.mem_range.2 hnk) (sub_self _), simp only [this, zero_mul] } end @[simp] lemma iter_deriv_pow' (n k : β„•) : deriv^[k] (Ξ» x : π•œ, x ^ n) = Ξ» x, (∏ i in finset.range k, (n - i)) * x ^ (n - k) := funext $ Ξ» x, iter_deriv_pow n x k lemma iter_deriv_inv (k : β„•) (x : π•œ) : deriv^[k] has_inv.inv x = (∏ i in finset.range k, (-1 - i)) * x ^ (-1 - k : β„€) := by simpa only [zpow_neg_one, int.cast_neg, int.cast_one] using iter_deriv_zpow (-1) x k @[simp] lemma iter_deriv_inv' (k : β„•) : deriv^[k] has_inv.inv = Ξ» x : π•œ, (∏ i in finset.range k, (-1 - i)) * x ^ (-1 - k : β„€) := funext (iter_deriv_inv k) variables {f : E β†’ π•œ} {t : set E} {a : E} lemma differentiable_within_at.zpow (hf : differentiable_within_at π•œ f t a) (h : f a β‰  0 ∨ 0 ≀ m) : differentiable_within_at π•œ (Ξ» x, f x ^ m) t a := (differentiable_at_zpow.2 h).comp_differentiable_within_at a hf lemma differentiable_at.zpow (hf : differentiable_at π•œ f a) (h : f a β‰  0 ∨ 0 ≀ m) : differentiable_at π•œ (Ξ» x, f x ^ m) a := (differentiable_at_zpow.2 h).comp a hf lemma differentiable_on.zpow (hf : differentiable_on π•œ f t) (h : (βˆ€ x ∈ t, f x β‰  0) ∨ 0 ≀ m) : differentiable_on π•œ (Ξ» x, f x ^ m) t := Ξ» x hx, (hf x hx).zpow $ h.imp_left (Ξ» h, h x hx) lemma differentiable.zpow (hf : differentiable π•œ f) (h : (βˆ€ x, f x β‰  0) ∨ 0 ≀ m) : differentiable π•œ (Ξ» x, f x ^ m) := Ξ» x, (hf x).zpow $ h.imp_left (Ξ» h, h x) end zpow /-! ### Support of derivatives -/ section support open function variables {F : Type*} [normed_add_comm_group F] [normed_space π•œ F] {f : π•œ β†’ F} lemma support_deriv_subset : support (deriv f) βŠ† tsupport f := begin intros x, rw [← not_imp_not], intro h2x, rw [not_mem_tsupport_iff_eventually_eq] at h2x, exact nmem_support.mpr (h2x.deriv_eq.trans (deriv_const x 0)) end lemma has_compact_support.deriv (hf : has_compact_support f) : has_compact_support (deriv f) := hf.mono' support_deriv_subset end support /-! ### Upper estimates on liminf and limsup -/ section real variables {f : ℝ β†’ ℝ} {f' : ℝ} {s : set ℝ} {x : ℝ} {r : ℝ} lemma has_deriv_within_at.limsup_slope_le (hf : has_deriv_within_at f f' s x) (hr : f' < r) : βˆ€αΆ  z in 𝓝[s \ {x}] x, slope f x z < r := has_deriv_within_at_iff_tendsto_slope.1 hf (is_open.mem_nhds is_open_Iio hr) lemma has_deriv_within_at.limsup_slope_le' (hf : has_deriv_within_at f f' s x) (hs : x βˆ‰ s) (hr : f' < r) : βˆ€αΆ  z in 𝓝[s] x, slope f x z < r := (has_deriv_within_at_iff_tendsto_slope' hs).1 hf (is_open.mem_nhds is_open_Iio hr) lemma has_deriv_within_at.liminf_right_slope_le (hf : has_deriv_within_at f f' (Ici x) x) (hr : f' < r) : βˆƒαΆ  z in 𝓝[>] x, slope f x z < r := (hf.Ioi_of_Ici.limsup_slope_le' (lt_irrefl x) hr).frequently end real section real_space open metric variables {E : Type u} [normed_add_comm_group E] [normed_space ℝ E] {f : ℝ β†’ E} {f' : E} {s : set ℝ} {x r : ℝ} /-- If `f` has derivative `f'` within `s` at `x`, then for any `r > βˆ₯f'βˆ₯` the ratio `βˆ₯f z - f xβˆ₯ / βˆ₯z - xβˆ₯` is less than `r` in some neighborhood of `x` within `s`. In other words, the limit superior of this ratio as `z` tends to `x` along `s` is less than or equal to `βˆ₯f'βˆ₯`. -/ lemma has_deriv_within_at.limsup_norm_slope_le (hf : has_deriv_within_at f f' s x) (hr : βˆ₯f'βˆ₯ < r) : βˆ€αΆ  z in 𝓝[s] x, βˆ₯z - xβˆ₯⁻¹ * βˆ₯f z - f xβˆ₯ < r := begin have hrβ‚€ : 0 < r, from lt_of_le_of_lt (norm_nonneg f') hr, have A : βˆ€αΆ  z in 𝓝[s \ {x}] x, βˆ₯(z - x)⁻¹ β€’ (f z - f x)βˆ₯ ∈ Iio r, from (has_deriv_within_at_iff_tendsto_slope.1 hf).norm (is_open.mem_nhds is_open_Iio hr), have B : βˆ€αΆ  z in 𝓝[{x}] x, βˆ₯(z - x)⁻¹ β€’ (f z - f x)βˆ₯ ∈ Iio r, from mem_of_superset self_mem_nhds_within (singleton_subset_iff.2 $ by simp [hrβ‚€]), have C := mem_sup.2 ⟨A, B⟩, rw [← nhds_within_union, diff_union_self, nhds_within_union, mem_sup] at C, filter_upwards [C.1], simp only [norm_smul, mem_Iio, norm_inv], exact Ξ» _, id end /-- If `f` has derivative `f'` within `s` at `x`, then for any `r > βˆ₯f'βˆ₯` the ratio `(βˆ₯f zβˆ₯ - βˆ₯f xβˆ₯) / βˆ₯z - xβˆ₯` is less than `r` in some neighborhood of `x` within `s`. In other words, the limit superior of this ratio as `z` tends to `x` along `s` is less than or equal to `βˆ₯f'βˆ₯`. This lemma is a weaker version of `has_deriv_within_at.limsup_norm_slope_le` where `βˆ₯f zβˆ₯ - βˆ₯f xβˆ₯` is replaced by `βˆ₯f z - f xβˆ₯`. -/ lemma has_deriv_within_at.limsup_slope_norm_le (hf : has_deriv_within_at f f' s x) (hr : βˆ₯f'βˆ₯ < r) : βˆ€αΆ  z in 𝓝[s] x, βˆ₯z - xβˆ₯⁻¹ * (βˆ₯f zβˆ₯ - βˆ₯f xβˆ₯) < r := begin apply (hf.limsup_norm_slope_le hr).mono, assume z hz, refine lt_of_le_of_lt (mul_le_mul_of_nonneg_left (norm_sub_norm_le _ _) _) hz, exact inv_nonneg.2 (norm_nonneg _) end /-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > βˆ₯f'βˆ₯` the ratio `βˆ₯f z - f xβˆ₯ / βˆ₯z - xβˆ₯` is frequently less than `r` as `z β†’ x+0`. In other words, the limit inferior of this ratio as `z` tends to `x+0` is less than or equal to `βˆ₯f'βˆ₯`. See also `has_deriv_within_at.limsup_norm_slope_le` for a stronger version using limit superior and any set `s`. -/ lemma has_deriv_within_at.liminf_right_norm_slope_le (hf : has_deriv_within_at f f' (Ici x) x) (hr : βˆ₯f'βˆ₯ < r) : βˆƒαΆ  z in 𝓝[>] x, βˆ₯z - xβˆ₯⁻¹ * βˆ₯f z - f xβˆ₯ < r := (hf.Ioi_of_Ici.limsup_norm_slope_le hr).frequently /-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > βˆ₯f'βˆ₯` the ratio `(βˆ₯f zβˆ₯ - βˆ₯f xβˆ₯) / (z - x)` is frequently less than `r` as `z β†’ x+0`. In other words, the limit inferior of this ratio as `z` tends to `x+0` is less than or equal to `βˆ₯f'βˆ₯`. See also * `has_deriv_within_at.limsup_norm_slope_le` for a stronger version using limit superior and any set `s`; * `has_deriv_within_at.liminf_right_norm_slope_le` for a stronger version using `βˆ₯f z - f xβˆ₯` instead of `βˆ₯f zβˆ₯ - βˆ₯f xβˆ₯`. -/ lemma has_deriv_within_at.liminf_right_slope_norm_le (hf : has_deriv_within_at f f' (Ici x) x) (hr : βˆ₯f'βˆ₯ < r) : βˆƒαΆ  z in 𝓝[>] x, (z - x)⁻¹ * (βˆ₯f zβˆ₯ - βˆ₯f xβˆ₯) < r := begin have := (hf.Ioi_of_Ici.limsup_slope_norm_le hr).frequently, refine this.mp (eventually.mono self_mem_nhds_within _), assume z hxz hz, rwa [real.norm_eq_abs, abs_of_pos (sub_pos_of_lt hxz)] at hz end end real_space