Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
Try doing some basic maths questions in the Lean Theorem Prover. Functions, real numbers, equivalence relations and groups. Click on README.md and then on "Open in CoCalc with one click".
Project: Xena
Views: 18536License: APACHE
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import analysis.asymptotics analysis.calculus.tangent_cone /-! # The FrΓ©chet derivative Let `E` and `F` be normed spaces, `f : E β F`, and `f' : E βL[π] F` a continuous π-linear map, where `π` is a non-discrete normed field. Then `has_fderiv_within_at f f' s x` says that `f` has derivative `f'` at `x`, where the domain of interest is restricted to `s`. We also have `has_fderiv_at f f' x := has_fderiv_within_at f f' x univ` ## Main results In addition to the definition and basic properties of the derivative, this file contains the usual formulas (and existence assertions) for the derivative of * constants * the identity * bounded linear maps * bounded bilinear maps * sum of two functions * multiplication of a function by a scalar constant * negative of a function * subtraction of two functions * multiplication of a function by a scalar function * multiplication of two scalar functions * composition of functions (the chain rule) 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. One can also interpret the derivative of a function `f : π β E` as an element of `E` (by identifying a linear function from `π` to `E` with its value at `1`). Results on the FrΓ©chet derivative are translated to this more elementary point of view on the derivative in the file `deriv.lean`. The derivative of polynomials is handled there, as it is naturally one-dimensional. ## Implementation details The derivative is defined in terms of the `is_o` relation, but also characterized in terms of the `tendsto` relation. We also introduce predicates `differentiable_within_at π f s x` (where `π` is the base field, `f` the function to be differentiated, `x` the point at which the derivative is asserted to exist, and `s` the set along which the derivative is defined), as well as `differentiable_at π f x`, `differentiable_on π f s` and `differentiable π f` to express the existence of a derivative. To be able to compute with derivatives, we write `fderiv_within π f s x` and `fderiv π f x` for some choice of a derivative if it exists, and the zero function otherwise. This choice only behaves well along sets for which the derivative is unique, i.e., those for which the tangent directions span a dense subset of the whole space. The predicates `unique_diff_within_at s x` and `unique_diff_on s`, defined in `tangent_cone.lean` express this property. We prove that indeed they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever. ## Tags derivative, differentiable, FrΓ©chet, calculus -/ open filter asymptotics continuous_linear_map set open_locale topological_space classical noncomputable theory set_option class.instance_max_depth 90 section variables {π : Type*} [nondiscrete_normed_field π] variables {E : Type*} [normed_group E] [normed_space π E] variables {F : Type*} [normed_group F] [normed_space π F] variables {G : Type*} [normed_group G] [normed_space π G] /-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition is designed to be specialized for `L = π x` (in `has_fderiv_at`), giving rise to the usual notion of FrΓ©chet derivative, and for `L = nhds_within x s` (in `has_fderiv_within_at`), giving rise to the notion of FrΓ©chet derivative along the set `s`. -/ def has_fderiv_at_filter (f : E β F) (f' : E βL[π] F) (x : E) (L : filter E) := is_o (Ξ» x', f x' - f x - f' (x' - x)) (Ξ» x', x' - x) L /-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/ def has_fderiv_within_at (f : E β F) (f' : E βL[π] F) (s : set E) (x : E) := has_fderiv_at_filter f f' x (nhds_within x s) /-- A function `f` has the continuous linear map `f'` as derivative at `x` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/ def has_fderiv_at (f : E β F) (f' : E βL[π] F) (x : E) := has_fderiv_at_filter f f' x (π x) variables (π) /-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative there (possibly non-unique). -/ def differentiable_within_at (f : E β F) (s : set E) (x : E) := βf' : E βL[π] F, has_fderiv_within_at f f' s x /-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly non-unique). -/ def differentiable_at (f : E β F) (x : E) := βf' : E βL[π] F, has_fderiv_at f f' x /-- If `f` has a derivative at `x` within `s`, then `fderiv_within π f s x` is such a derivative. Otherwise, it is set to `0`. -/ def fderiv_within (f : E β F) (s : set E) (x : E) : E βL[π] F := if h : βf', has_fderiv_within_at f f' s x then classical.some h else 0 /-- If `f` has a derivative at `x`, then `fderiv π f x` is such a derivative. Otherwise, it is set to `0`. -/ def fderiv (f : E β F) (x : E) : E βL[π] F := if h : βf', has_fderiv_at f f' x then classical.some h else 0 /-- `differentiable_on π f s` means that `f` is differentiable within `s` at any point of `s`. -/ def differentiable_on (f : E β F) (s : set E) := βx β s, differentiable_within_at π f s x /-- `differentiable π f` means that `f` is differentiable at any point. -/ def differentiable (f : E β F) := βx, differentiable_at π f x variables {π} variables {f fβ fβ g : E β F} variables {f' fβ' fβ' g' : E βL[π] F} variables (e : E βL[π] F) variables {x : E} variables {s t : set E} variables {L Lβ Lβ : filter E} lemma fderiv_within_zero_of_not_differentiable_within_at (h : Β¬ differentiable_within_at π f s x) : fderiv_within π f s x = 0 := have Β¬ β f', has_fderiv_within_at f f' s x, from h, by simp [fderiv_within, this] lemma fderiv_zero_of_not_differentiable_at (h : Β¬ differentiable_at π f x) : fderiv π f x = 0 := have Β¬ β f', has_fderiv_at f f' x, from h, by simp [fderiv, this] section derivative_uniqueness /- In this section, we discuss the uniqueness of the derivative. We prove that the definitions `unique_diff_within_at` and `unique_diff_on` indeed imply the uniqueness of the derivative. -/ /-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f', i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses this fact, for functions having a derivative within a set. Its specific formulation is useful for tangent cone related discussions. -/ theorem has_fderiv_within_at.lim (h : has_fderiv_within_at f f' s x) {Ξ± : Type*} (l : filter Ξ±) {c : Ξ± β π} {d : Ξ± β E} {v : E} (dtop : βαΆ n in l, x + d n β s) (clim : tendsto (Ξ» n, β₯c nβ₯) l at_top) (cdlim : tendsto (Ξ» n, c n β’ d n) l (π v)) : tendsto (Ξ»n, c n β’ (f (x + d n) - f x)) l (π (f' v)) := begin have tendsto_arg : tendsto (Ξ» n, x + d n) l (nhds_within x s), { conv in (nhds_within x s) { rw β add_zero x }, rw [nhds_within, tendsto_inf], split, { apply tendsto_const_nhds.add (tangent_cone_at.lim_zero l clim cdlim) }, { rwa tendsto_principal } }, have : is_o (Ξ» y, f y - f x - f' (y - x)) (Ξ» y, y - x) (nhds_within x s) := h, have : is_o (Ξ» n, f (x + d n) - f x - f' ((x + d n) - x)) (Ξ» n, (x + d n) - x) l := this.comp_tendsto tendsto_arg, have : is_o (Ξ» n, f (x + d n) - f x - f' (d n)) d l := by simpa only [add_sub_cancel'], have : is_o (Ξ»n, c n β’ (f (x + d n) - f x - f' (d n))) (Ξ»n, c n β’ d n) l := (is_O_refl c l).smul_is_o this, have : is_o (Ξ»n, c n β’ (f (x + d n) - f x - f' (d n))) (Ξ»n, (1:β)) l := this.trans_is_O (is_O_one_of_tendsto β cdlim), have L1 : tendsto (Ξ»n, c n β’ (f (x + d n) - f x - f' (d n))) l (π 0) := (is_o_one_iff β).1 this, have L2 : tendsto (Ξ»n, f' (c n β’ d n)) l (π (f' v)) := tendsto.comp f'.cont.continuous_at cdlim, have L3 : tendsto (Ξ»n, (c n β’ (f (x + d n) - f x - f' (d n)) + f' (c n β’ d n))) l (π (0 + f' v)) := L1.add L2, have : (Ξ»n, (c n β’ (f (x + d n) - f x - f' (d n)) + f' (c n β’ d n))) = (Ξ»n, c n β’ (f (x + d n) - f x)), by { ext n, simp [smul_add] }, rwa [this, zero_add] at L3 end /-- `unique_diff_within_at` achieves its goal: it implies the uniqueness of the derivative. -/ theorem unique_diff_within_at.eq (H : unique_diff_within_at π s x) (h : has_fderiv_within_at f f' s x) (hβ : has_fderiv_within_at f fβ' s x) : f' = fβ' := begin have A : βy β tangent_cone_at π s x, f' y = fβ' y, { rintros y β¨c, d, dtop, clim, cdlimβ©, exact tendsto_nhds_unique (by simp) (h.lim at_top dtop clim cdlim) (hβ.lim at_top dtop clim cdlim) }, have B : βy β submodule.span π (tangent_cone_at π s x), f' y = fβ' y, { assume y hy, apply submodule.span_induction hy, { exact Ξ»y hy, A y hy }, { simp only [continuous_linear_map.map_zero] }, { simp {contextual := tt} }, { simp {contextual := tt} } }, have C : βy β closure ((submodule.span π (tangent_cone_at π s x)) : set E), f' y = fβ' y, { assume y hy, let K := {y | f' y = fβ' y}, have : (submodule.span π (tangent_cone_at π s x) : set E) β K := B, have : closure (submodule.span π (tangent_cone_at π s x) : set E) β closure K := closure_mono this, have : y β closure K := this hy, rwa closure_eq_of_is_closed (is_closed_eq f'.continuous fβ'.continuous) at this }, rw H.1 at C, ext y, exact C y (mem_univ _) end theorem unique_diff_on.eq (H : unique_diff_on π s) (hx : x β s) (h : has_fderiv_within_at f f' s x) (hβ : has_fderiv_within_at f fβ' s x) : f' = fβ' := unique_diff_within_at.eq (H x hx) h hβ end derivative_uniqueness section fderiv_properties /-! ### Basic properties of the derivative -/ theorem has_fderiv_at_filter_iff_tendsto : has_fderiv_at_filter f f' x L β tendsto (Ξ» x', β₯x' - xβ₯β»ΒΉ * β₯f x' - f x - f' (x' - x)β₯) L (π 0) := have h : β x', β₯x' - xβ₯ = 0 β β₯f x' - f x - f' (x' - x)β₯ = 0, from Ξ» x' hx', by { rw [sub_eq_zero.1 ((norm_eq_zero (x' - x)).1 hx')], simp }, begin unfold has_fderiv_at_filter, rw [βis_o_norm_left, βis_o_norm_right, is_o_iff_tendsto h], exact tendsto_congr (Ξ» _, div_eq_inv_mul), end theorem has_fderiv_within_at_iff_tendsto : has_fderiv_within_at f f' s x β tendsto (Ξ» x', β₯x' - xβ₯β»ΒΉ * β₯f x' - f x - f' (x' - x)β₯) (nhds_within x s) (π 0) := has_fderiv_at_filter_iff_tendsto theorem has_fderiv_at_iff_tendsto : has_fderiv_at f f' x β tendsto (Ξ» x', β₯x' - xβ₯β»ΒΉ * β₯f x' - f x - f' (x' - x)β₯) (π x) (π 0) := has_fderiv_at_filter_iff_tendsto theorem has_fderiv_at_iff_is_o_nhds_zero : has_fderiv_at f f' x β is_o (Ξ»h, f (x + h) - f x - f' h) (Ξ»h, h) (π 0) := begin split, { assume H, have : tendsto (Ξ» (z : E), z + x) (π 0) (π (0 + x)), from tendsto_id.add tendsto_const_nhds, rw [zero_add] at this, refine (H.comp_tendsto this).congr _ _; intro z; simp only [function.comp, add_sub_cancel', add_comm z] }, { assume H, have : tendsto (Ξ» (z : E), z - x) (π x) (π (x - x)), from tendsto_id.sub tendsto_const_nhds, rw [sub_self] at this, refine (H.comp_tendsto this).congr _ _; intro z; simp only [function.comp, add_sub_cancel'_right] } end theorem has_fderiv_at_filter.mono (h : has_fderiv_at_filter f f' x Lβ) (hst : Lβ β€ Lβ) : has_fderiv_at_filter f f' x Lβ := h.mono hst theorem has_fderiv_within_at.mono (h : has_fderiv_within_at f f' t x) (hst : s β t) : has_fderiv_within_at f f' s x := h.mono (nhds_within_mono _ hst) theorem has_fderiv_at.has_fderiv_at_filter (h : has_fderiv_at f f' x) (hL : L β€ π x) : has_fderiv_at_filter f f' x L := h.mono hL theorem has_fderiv_at.has_fderiv_within_at (h : has_fderiv_at f f' x) : has_fderiv_within_at f f' s x := h.has_fderiv_at_filter lattice.inf_le_left lemma has_fderiv_within_at.differentiable_within_at (h : has_fderiv_within_at f f' s x) : differentiable_within_at π f s x := β¨f', hβ© lemma has_fderiv_at.differentiable_at (h : has_fderiv_at f f' x) : differentiable_at π f x := β¨f', hβ© @[simp] lemma has_fderiv_within_at_univ : has_fderiv_within_at f f' univ x β has_fderiv_at f f' x := by { simp only [has_fderiv_within_at, nhds_within_univ], refl } /-- Directional derivative agrees with `has_fderiv`. -/ lemma has_fderiv_at.lim (hf : has_fderiv_at f f' x) (v : E) {Ξ± : Type*} {c : Ξ± β π} {l : filter Ξ±} (hc : tendsto (Ξ» n, β₯c nβ₯) l at_top) : tendsto (Ξ» n, (c n) β’ (f (x + (c n)β»ΒΉ β’ v) - f x)) l (π (f' v)) := begin refine (has_fderiv_within_at_univ.2 hf).lim _ (univ_mem_sets' (Ξ» _, trivial)) hc _, assume U hU, apply mem_sets_of_superset (ne_mem_of_tendsto_norm_at_top hc (0:π)) _, assume y hy, rw [mem_preimage], convert mem_of_nhds hU, rw [β mul_smul, mul_inv_cancel hy, one_smul] end theorem has_fderiv_at_unique (hβ : has_fderiv_at f fβ' x) (hβ : has_fderiv_at f fβ' x) : fβ' = fβ' := begin rw β has_fderiv_within_at_univ at hβ hβ, exact unique_diff_within_at_univ.eq hβ hβ end lemma has_fderiv_within_at_inter' (h : t β nhds_within x s) : has_fderiv_within_at f f' (s β© t) x β has_fderiv_within_at f f' s x := by simp [has_fderiv_within_at, nhds_within_restrict'' s h] lemma has_fderiv_within_at_inter (h : t β π x) : has_fderiv_within_at f f' (s β© t) x β has_fderiv_within_at f f' s x := by simp [has_fderiv_within_at, nhds_within_restrict' s h] lemma has_fderiv_within_at.union (hs : has_fderiv_within_at f f' s x) (ht : has_fderiv_within_at f f' t x) : has_fderiv_within_at f f' (s βͺ t) x := begin simp only [has_fderiv_within_at, nhds_within_union], exact hs.join ht, end lemma has_fderiv_within_at.nhds_within (h : has_fderiv_within_at f f' s x) (ht : s β nhds_within x t) : has_fderiv_within_at f f' t x := (has_fderiv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _)) lemma has_fderiv_within_at.has_fderiv_at (h : has_fderiv_within_at f f' s x) (hs : s β π x) : has_fderiv_at f f' x := by rwa [β univ_inter s, has_fderiv_within_at_inter hs, has_fderiv_within_at_univ] at h lemma differentiable_within_at.has_fderiv_within_at (h : differentiable_within_at π f s x) : has_fderiv_within_at f (fderiv_within π f s x) s x := begin dunfold fderiv_within, dunfold differentiable_within_at at h, rw dif_pos h, exact classical.some_spec h end lemma differentiable_at.has_fderiv_at (h : differentiable_at π f x) : has_fderiv_at f (fderiv π f x) x := begin dunfold fderiv, dunfold differentiable_at at h, rw dif_pos h, exact classical.some_spec h end lemma has_fderiv_at.fderiv (h : has_fderiv_at f f' x) : fderiv π f x = f' := by { ext, rw has_fderiv_at_unique h h.differentiable_at.has_fderiv_at } lemma has_fderiv_within_at.fderiv_within (h : has_fderiv_within_at f f' s x) (hxs : unique_diff_within_at π s x) : fderiv_within π f s x = f' := by { ext, rw hxs.eq h h.differentiable_within_at.has_fderiv_within_at } /-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ lemma has_fderiv_within_at_of_not_mem_closure (h : x β closure s) : has_fderiv_within_at f f' s x := begin simp [mem_closure_iff_nhds_within_ne_bot] at h, simp [has_fderiv_within_at, has_fderiv_at_filter, h, is_o, is_O_with], end lemma differentiable_within_at.mono (h : differentiable_within_at π f t x) (st : s β t) : differentiable_within_at π f s x := begin rcases h with β¨f', hf'β©, exact β¨f', hf'.mono stβ© end lemma differentiable_within_at_univ : differentiable_within_at π f univ x β differentiable_at π f x := by simp only [differentiable_within_at, has_fderiv_within_at_univ, differentiable_at] lemma differentiable_within_at_inter (ht : t β π x) : differentiable_within_at π f (s β© t) x β differentiable_within_at π f s x := by simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter, nhds_within_restrict' s ht] lemma differentiable_within_at_inter' (ht : t β nhds_within x s) : differentiable_within_at π f (s β© t) x β differentiable_within_at π f s x := by simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter, nhds_within_restrict'' s ht] lemma differentiable_at.differentiable_within_at (h : differentiable_at π f x) : differentiable_within_at π f s x := (differentiable_within_at_univ.2 h).mono (subset_univ _) lemma differentiable_within_at.differentiable_at (h : differentiable_within_at π f s x) (hs : s β π x) : differentiable_at π f x := h.imp (Ξ» f' hf', hf'.has_fderiv_at hs) lemma differentiable_at.fderiv_within (h : differentiable_at π f x) (hxs : unique_diff_within_at π s x) : fderiv_within π f s x = fderiv π f x := begin apply has_fderiv_within_at.fderiv_within _ hxs, exact h.has_fderiv_at.has_fderiv_within_at end lemma differentiable_on.mono (h : differentiable_on π f t) (st : s β t) : differentiable_on π f s := Ξ»x hx, (h x (st hx)).mono st lemma differentiable_on_univ : differentiable_on π f univ β differentiable π f := by { simp [differentiable_on, differentiable_within_at_univ], refl } lemma differentiable.differentiable_on (h : differentiable π f) : differentiable_on π f s := (differentiable_on_univ.2 h).mono (subset_univ _) lemma differentiable_on_of_locally_differentiable_on (h : βxβs, βu, is_open u β§ x β u β§ differentiable_on π f (s β© u)) : differentiable_on π f s := begin assume x xs, rcases h x xs with β¨t, t_open, xt, htβ©, exact (differentiable_within_at_inter (mem_nhds_sets t_open xt)).1 (ht x β¨xs, xtβ©) end lemma fderiv_within_subset (st : s β t) (ht : unique_diff_within_at π s x) (h : differentiable_within_at π f t x) : fderiv_within π f s x = fderiv_within π f t x := ((differentiable_within_at.has_fderiv_within_at h).mono st).fderiv_within ht @[simp] lemma fderiv_within_univ : fderiv_within π f univ = fderiv π f := begin ext x : 1, by_cases h : differentiable_at π f x, { apply has_fderiv_within_at.fderiv_within _ (is_open_univ.unique_diff_within_at (mem_univ _)), rw has_fderiv_within_at_univ, apply h.has_fderiv_at }, { have : Β¬ differentiable_within_at π f univ x, by contrapose! h; rwa β differentiable_within_at_univ, rw [fderiv_zero_of_not_differentiable_at h, fderiv_within_zero_of_not_differentiable_within_at this] } end lemma fderiv_within_inter (ht : t β π x) (hs : unique_diff_within_at π s x) : fderiv_within π f (s β© t) x = fderiv_within π f s x := begin by_cases h : differentiable_within_at π f (s β© t) x, { apply fderiv_within_subset (inter_subset_left _ _) _ ((differentiable_within_at_inter ht).1 h), apply hs.inter ht }, { have : Β¬ differentiable_within_at π f s x, by contrapose! h; rw differentiable_within_at_inter; assumption, rw [fderiv_within_zero_of_not_differentiable_within_at h, fderiv_within_zero_of_not_differentiable_within_at this] } end end fderiv_properties section congr /-! ### congr properties of the derivative -/ theorem has_fderiv_at_filter_congr_of_mem_sets (hx : fβ x = fβ x) (hβ : βαΆ x in L, fβ x = fβ x) (hβ : β x, fβ' x = fβ' x) : has_fderiv_at_filter fβ fβ' x L β has_fderiv_at_filter fβ fβ' x L := by { rw (ext hβ), exact is_o_congr (by filter_upwards [hβ] Ξ» x (h : _ = _), by simp [h, hx]) (univ_mem_sets' $ Ξ» _, rfl) } lemma has_fderiv_at_filter.congr_of_mem_sets (h : has_fderiv_at_filter f f' x L) (hL : βαΆ x in L, fβ x = f x) (hx : fβ x = f x) : has_fderiv_at_filter fβ f' x L := begin apply (has_fderiv_at_filter_congr_of_mem_sets hx hL _).2 h, exact Ξ»x, rfl end lemma has_fderiv_within_at.congr_mono (h : has_fderiv_within_at f f' s x) (ht : βx β t, fβ x = f x) (hx : fβ x = f x) (hβ : t β s) : has_fderiv_within_at fβ f' t x := has_fderiv_at_filter.congr_of_mem_sets (h.mono hβ) (filter.mem_inf_sets_of_right ht) hx lemma has_fderiv_within_at.congr (h : has_fderiv_within_at f f' s x) (hs : βx β s, fβ x = f x) (hx : fβ x = f x) : has_fderiv_within_at fβ f' s x := h.congr_mono hs hx (subset.refl _) lemma has_fderiv_within_at.congr_of_mem_nhds_within (h : has_fderiv_within_at f f' s x) (hβ : βαΆ y in nhds_within x s, fβ y = f y) (hx : fβ x = f x) : has_fderiv_within_at fβ f' s x := has_fderiv_at_filter.congr_of_mem_sets h hβ hx lemma has_fderiv_at.congr_of_mem_nhds (h : has_fderiv_at f f' x) (hβ : βαΆ y in π x, fβ y = f y) : has_fderiv_at fβ f' x := has_fderiv_at_filter.congr_of_mem_sets h hβ (mem_of_nhds hβ : _) lemma differentiable_within_at.congr_mono (h : differentiable_within_at π f s x) (ht : βx β t, fβ x = f x) (hx : fβ x = f x) (hβ : t β s) : differentiable_within_at π fβ t x := (has_fderiv_within_at.congr_mono h.has_fderiv_within_at ht hx hβ).differentiable_within_at lemma differentiable_within_at.congr (h : differentiable_within_at π f s x) (ht : βx β s, fβ x = f x) (hx : fβ x = f x) : differentiable_within_at π fβ s x := differentiable_within_at.congr_mono h ht hx (subset.refl _) lemma differentiable_within_at.congr_of_mem_nhds_within (h : differentiable_within_at π f s x) (hβ : βαΆ y in nhds_within x s, fβ y = f y) (hx : fβ x = f x) : differentiable_within_at π fβ s x := (h.has_fderiv_within_at.congr_of_mem_nhds_within hβ hx).differentiable_within_at lemma differentiable_on.congr_mono (h : differentiable_on π f s) (h' : βx β t, fβ x = f x) (hβ : t β s) : differentiable_on π fβ t := Ξ» x hx, (h x (hβ hx)).congr_mono h' (h' x hx) hβ lemma differentiable_on.congr (h : differentiable_on π f s) (h' : βx β s, fβ x = f x) : differentiable_on π fβ s := Ξ» x hx, (h x hx).congr h' (h' x hx) lemma differentiable_at.congr_of_mem_nhds (h : differentiable_at π f x) (hL : βαΆ y in π x, fβ y = f y) : differentiable_at π fβ x := has_fderiv_at.differentiable_at (has_fderiv_at_filter.congr_of_mem_sets h.has_fderiv_at hL (mem_of_nhds hL : _)) lemma differentiable_within_at.fderiv_within_congr_mono (h : differentiable_within_at π f s x) (hs : βx β t, fβ x = f x) (hx : fβ x = f x) (hxt : unique_diff_within_at π t x) (hβ : t β s) : fderiv_within π fβ t x = fderiv_within π f s x := (has_fderiv_within_at.congr_mono h.has_fderiv_within_at hs hx hβ).fderiv_within hxt lemma fderiv_within_congr_of_mem_nhds_within (hs : unique_diff_within_at π s x) (hL : βαΆ y in nhds_within x s, fβ y = f y) (hx : fβ x = f x) : fderiv_within π fβ s x = fderiv_within π f s x := begin by_cases h : differentiable_within_at π f s x β¨ differentiable_within_at π fβ s x, { cases h, { apply has_fderiv_within_at.fderiv_within _ hs, exact has_fderiv_at_filter.congr_of_mem_sets h.has_fderiv_within_at hL hx }, { symmetry, apply has_fderiv_within_at.fderiv_within _ hs, apply has_fderiv_at_filter.congr_of_mem_sets h.has_fderiv_within_at _ hx.symm, convert hL, ext y, exact eq_comm } }, { push_neg at h, have A : fderiv_within π f s x = 0, by { unfold differentiable_within_at at h, simp [fderiv_within, h] }, have Aβ : fderiv_within π fβ s x = 0, by { unfold differentiable_within_at at h, simp [fderiv_within, h] }, rw [A, Aβ] } end lemma fderiv_within_congr (hs : unique_diff_within_at π s x) (hL : βyβs, fβ y = f y) (hx : fβ x = f x) : fderiv_within π fβ s x = fderiv_within π f s x := begin apply fderiv_within_congr_of_mem_nhds_within hs _ hx, apply mem_sets_of_superset self_mem_nhds_within, exact hL end lemma fderiv_congr_of_mem_nhds (hL : βαΆ y in π x, fβ y = f y) : fderiv π fβ x = fderiv π f x := begin have A : fβ x = f x := (mem_of_nhds hL : _), rw [β fderiv_within_univ, β fderiv_within_univ], rw β nhds_within_univ at hL, exact fderiv_within_congr_of_mem_nhds_within unique_diff_within_at_univ hL A end end congr section id /-! ### Derivative of the identity -/ theorem has_fderiv_at_filter_id (x : E) (L : filter E) : has_fderiv_at_filter id (id : E βL[π] E) x L := (is_o_zero _ _).congr_left $ by simp theorem has_fderiv_within_at_id (x : E) (s : set E) : has_fderiv_within_at id (id : E βL[π] E) s x := has_fderiv_at_filter_id _ _ theorem has_fderiv_at_id (x : E) : has_fderiv_at id (id : E βL[π] E) x := has_fderiv_at_filter_id _ _ lemma differentiable_at_id : differentiable_at π id x := (has_fderiv_at_id x).differentiable_at lemma differentiable_within_at_id : differentiable_within_at π id s x := differentiable_at_id.differentiable_within_at lemma differentiable_id : differentiable π (id : E β E) := Ξ»x, differentiable_at_id lemma differentiable_on_id : differentiable_on π id s := differentiable_id.differentiable_on lemma fderiv_id : fderiv π id x = id := has_fderiv_at.fderiv (has_fderiv_at_id x) lemma fderiv_within_id (hxs : unique_diff_within_at π s x) : fderiv_within π id s x = id := begin rw differentiable_at.fderiv_within (differentiable_at_id) hxs, exact fderiv_id end end id section const /-! ### derivative of a constant function -/ theorem has_fderiv_at_filter_const (c : F) (x : E) (L : filter E) : has_fderiv_at_filter (Ξ» x, c) (0 : E βL[π] F) x L := (is_o_zero _ _).congr_left $ Ξ» _, by simp only [zero_apply, sub_self] theorem has_fderiv_within_at_const (c : F) (x : E) (s : set E) : has_fderiv_within_at (Ξ» x, c) (0 : E βL[π] F) s x := has_fderiv_at_filter_const _ _ _ theorem has_fderiv_at_const (c : F) (x : E) : has_fderiv_at (Ξ» x, c) (0 : E βL[π] F) x := has_fderiv_at_filter_const _ _ _ lemma differentiable_at_const (c : F) : differentiable_at π (Ξ»x, c) x := β¨0, has_fderiv_at_const c xβ© lemma differentiable_within_at_const (c : F) : differentiable_within_at π (Ξ»x, c) s x := differentiable_at.differentiable_within_at (differentiable_at_const _) lemma fderiv_const (c : F) : fderiv π (Ξ»y, c) x = 0 := has_fderiv_at.fderiv (has_fderiv_at_const c x) lemma fderiv_within_const (c : F) (hxs : unique_diff_within_at π s x) : fderiv_within π (Ξ»y, c) s x = 0 := begin rw differentiable_at.fderiv_within (differentiable_at_const _) hxs, exact fderiv_const _ end lemma differentiable_const (c : F) : differentiable π (Ξ»x : E, c) := Ξ»x, differentiable_at_const _ lemma differentiable_on_const (c : F) : differentiable_on π (Ξ»x, c) s := (differentiable_const _).differentiable_on end const section continuous_linear_map /-! ### Continuous linear maps There are currently two variants of these in mathlib, the bundled version (named `continuous_linear_map`, and denoted `E βL[π] F`), and the unbundled version (with a predicate `is_bounded_linear_map`). We give statements for both versions. -/ lemma is_bounded_linear_map.has_fderiv_at_filter (h : is_bounded_linear_map π f) : has_fderiv_at_filter f h.to_continuous_linear_map x L := begin have : (Ξ» (x' : E), f x' - f x - h.to_continuous_linear_map (x' - x)) = Ξ»x', 0, { ext, have : βa, h.to_continuous_linear_map a = f a := Ξ»a, rfl, simp, simp [this] }, rw [has_fderiv_at_filter, this], exact asymptotics.is_o_zero _ _ end lemma is_bounded_linear_map.has_fderiv_within_at (h : is_bounded_linear_map π f) : has_fderiv_within_at f h.to_continuous_linear_map s x := h.has_fderiv_at_filter lemma is_bounded_linear_map.has_fderiv_at (h : is_bounded_linear_map π f) : has_fderiv_at f h.to_continuous_linear_map x := h.has_fderiv_at_filter lemma is_bounded_linear_map.differentiable_at (h : is_bounded_linear_map π f) : differentiable_at π f x := h.has_fderiv_at.differentiable_at lemma is_bounded_linear_map.differentiable_within_at (h : is_bounded_linear_map π f) : differentiable_within_at π f s x := h.differentiable_at.differentiable_within_at lemma is_bounded_linear_map.fderiv (h : is_bounded_linear_map π f) : fderiv π f x = h.to_continuous_linear_map := has_fderiv_at.fderiv (h.has_fderiv_at) lemma is_bounded_linear_map.fderiv_within (h : is_bounded_linear_map π f) (hxs : unique_diff_within_at π s x) : fderiv_within π f s x = h.to_continuous_linear_map := begin rw differentiable_at.fderiv_within h.differentiable_at hxs, exact h.fderiv end lemma is_bounded_linear_map.differentiable (h : is_bounded_linear_map π f) : differentiable π f := Ξ»x, h.differentiable_at lemma is_bounded_linear_map.differentiable_on (h : is_bounded_linear_map π f) : differentiable_on π f s := h.differentiable.differentiable_on lemma continuous_linear_map.has_fderiv_at_filter : has_fderiv_at_filter e e x L := begin have : (Ξ» (x' : E), e x' - e x - e (x' - x)) = Ξ»x', 0, by { ext, simp }, rw [has_fderiv_at_filter, this], exact asymptotics.is_o_zero _ _ end protected lemma continuous_linear_map.has_fderiv_within_at : has_fderiv_within_at e e s x := e.has_fderiv_at_filter protected lemma continuous_linear_map.has_fderiv_at : has_fderiv_at e e x := e.has_fderiv_at_filter protected lemma continuous_linear_map.differentiable_at : differentiable_at π e x := e.has_fderiv_at.differentiable_at protected lemma continuous_linear_map.differentiable_within_at : differentiable_within_at π e s x := e.differentiable_at.differentiable_within_at protected lemma continuous_linear_map.fderiv : fderiv π e x = e := e.has_fderiv_at.fderiv protected lemma continuous_linear_map.fderiv_within (hxs : unique_diff_within_at π s x) : fderiv_within π e s x = e := begin rw differentiable_at.fderiv_within e.differentiable_at hxs, exact e.fderiv end protected lemma continuous_linear_map.differentiable : differentiable π e := Ξ»x, e.differentiable_at protected lemma continuous_linear_map.differentiable_on : differentiable_on π e s := e.differentiable.differentiable_on end continuous_linear_map section const_smul /-! ### Derivative of a function multiplied by a constant -/ theorem has_fderiv_at_filter.const_smul (h : has_fderiv_at_filter f f' x L) (c : π) : has_fderiv_at_filter (Ξ» x, c β’ f x) (c β’ f') x L := (is_o_const_smul_left h c).congr_left $ Ξ» x, by simp [smul_neg, smul_add] theorem has_fderiv_within_at.const_smul (h : has_fderiv_within_at f f' s x) (c : π) : has_fderiv_within_at (Ξ» x, c β’ f x) (c β’ f') s x := h.const_smul c theorem has_fderiv_at.const_smul (h : has_fderiv_at f f' x) (c : π) : has_fderiv_at (Ξ» x, c β’ f x) (c β’ f') x := h.const_smul c lemma differentiable_within_at.const_smul (h : differentiable_within_at π f s x) (c : π) : differentiable_within_at π (Ξ»y, c β’ f y) s x := (h.has_fderiv_within_at.const_smul c).differentiable_within_at lemma differentiable_at.const_smul (h : differentiable_at π f x) (c : π) : differentiable_at π (Ξ»y, c β’ f y) x := (h.has_fderiv_at.const_smul c).differentiable_at lemma differentiable_on.const_smul (h : differentiable_on π f s) (c : π) : differentiable_on π (Ξ»y, c β’ f y) s := Ξ»x hx, (h x hx).const_smul c lemma differentiable.const_smul (h : differentiable π f) (c : π) : differentiable π (Ξ»y, c β’ f y) := Ξ»x, (h x).const_smul c lemma fderiv_within_const_smul (hxs : unique_diff_within_at π s x) (h : differentiable_within_at π f s x) (c : π) : fderiv_within π (Ξ»y, c β’ f y) s x = c β’ fderiv_within π f s x := (h.has_fderiv_within_at.const_smul c).fderiv_within hxs lemma fderiv_const_smul (h : differentiable_at π f x) (c : π) : fderiv π (Ξ»y, c β’ f y) x = c β’ fderiv π f x := (h.has_fderiv_at.const_smul c).fderiv end const_smul section add /-! ### Derivative of the sum of two functions -/ theorem has_fderiv_at_filter.add (hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) : has_fderiv_at_filter (Ξ» y, f y + g y) (f' + g') x L := (hf.add hg).congr_left $ Ξ» _, by simp theorem has_fderiv_within_at.add (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) : has_fderiv_within_at (Ξ» y, f y + g y) (f' + g') s x := hf.add hg theorem has_fderiv_at.add (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) : has_fderiv_at (Ξ» x, f x + g x) (f' + g') x := hf.add hg lemma differentiable_within_at.add (hf : differentiable_within_at π f s x) (hg : differentiable_within_at π g s x) : differentiable_within_at π (Ξ» y, f y + g y) s x := (hf.has_fderiv_within_at.add hg.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.add (hf : differentiable_at π f x) (hg : differentiable_at π g x) : differentiable_at π (Ξ» y, f y + g y) x := (hf.has_fderiv_at.add hg.has_fderiv_at).differentiable_at lemma differentiable_on.add (hf : differentiable_on π f s) (hg : differentiable_on π g s) : differentiable_on π (Ξ»y, f y + g y) s := Ξ»x hx, (hf x hx).add (hg x hx) lemma differentiable.add (hf : differentiable π f) (hg : differentiable π g) : differentiable π (Ξ»y, f y + g y) := Ξ»x, (hf x).add (hg x) lemma fderiv_within_add (hxs : unique_diff_within_at π s x) (hf : differentiable_within_at π f s x) (hg : differentiable_within_at π g s x) : fderiv_within π (Ξ»y, f y + g y) s x = fderiv_within π f s x + fderiv_within π g s x := (hf.has_fderiv_within_at.add hg.has_fderiv_within_at).fderiv_within hxs lemma fderiv_add (hf : differentiable_at π f x) (hg : differentiable_at π g x) : fderiv π (Ξ»y, f y + g y) x = fderiv π f x + fderiv π g x := (hf.has_fderiv_at.add hg.has_fderiv_at).fderiv theorem has_fderiv_at_filter.add_const (hf : has_fderiv_at_filter f f' x L) (c : F) : has_fderiv_at_filter (Ξ» y, f y + c) f' x L := add_zero f' βΈ hf.add (has_fderiv_at_filter_const _ _ _) theorem has_fderiv_within_at.add_const (hf : has_fderiv_within_at f f' s x) (c : F) : has_fderiv_within_at (Ξ» y, f y + c) f' s x := hf.add_const c theorem has_fderiv_at.add_const (hf : has_fderiv_at f f' x) (c : F): has_fderiv_at (Ξ» x, f x + c) f' x := hf.add_const c lemma differentiable_within_at.add_const (hf : differentiable_within_at π f s x) (c : F) : differentiable_within_at π (Ξ» y, f y + c) s x := (hf.has_fderiv_within_at.add_const c).differentiable_within_at lemma differentiable_at.add_const (hf : differentiable_at π f x) (c : F) : differentiable_at π (Ξ» y, f y + c) x := (hf.has_fderiv_at.add_const c).differentiable_at lemma differentiable_on.add_const (hf : differentiable_on π f s) (c : F) : differentiable_on π (Ξ»y, f y + c) s := Ξ»x hx, (hf x hx).add_const c lemma differentiable.add_const (hf : differentiable π f) (c : F) : differentiable π (Ξ»y, f y + c) := Ξ»x, (hf x).add_const c lemma fderiv_within_add_const (hxs : unique_diff_within_at π s x) (hf : differentiable_within_at π f s x) (c : F) : fderiv_within π (Ξ»y, f y + c) s x = fderiv_within π f s x := (hf.has_fderiv_within_at.add_const c).fderiv_within hxs lemma fderiv_add_const (hf : differentiable_at π f x) (c : F) : fderiv π (Ξ»y, f y + c) x = fderiv π f x := (hf.has_fderiv_at.add_const c).fderiv theorem has_fderiv_at_filter.const_add (hf : has_fderiv_at_filter f f' x L) (c : F) : has_fderiv_at_filter (Ξ» y, c + f y) f' x L := zero_add f' βΈ (has_fderiv_at_filter_const _ _ _).add hf theorem has_fderiv_within_at.const_add (hf : has_fderiv_within_at f f' s x) (c : F) : has_fderiv_within_at (Ξ» y, c + f y) f' s x := hf.const_add c theorem has_fderiv_at.const_add (hf : has_fderiv_at f f' x) (c : F): has_fderiv_at (Ξ» x, c + f x) f' x := hf.const_add c lemma differentiable_within_at.const_add (hf : differentiable_within_at π f s x) (c : F) : differentiable_within_at π (Ξ» y, c + f y) s x := (hf.has_fderiv_within_at.const_add c).differentiable_within_at lemma differentiable_at.const_add (hf : differentiable_at π f x) (c : F) : differentiable_at π (Ξ» y, c + f y) x := (hf.has_fderiv_at.const_add c).differentiable_at lemma differentiable_on.const_add (hf : differentiable_on π f s) (c : F) : differentiable_on π (Ξ»y, c + f y) s := Ξ»x hx, (hf x hx).const_add c lemma differentiable.const_add (hf : differentiable π f) (c : F) : differentiable π (Ξ»y, c + f y) := Ξ»x, (hf x).const_add c lemma fderiv_within_const_add (hxs : unique_diff_within_at π s x) (hf : differentiable_within_at π f s x) (c : F) : fderiv_within π (Ξ»y, c + f y) s x = fderiv_within π f s x := (hf.has_fderiv_within_at.const_add c).fderiv_within hxs lemma fderiv_const_add (hf : differentiable_at π f x) (c : F) : fderiv π (Ξ»y, c + f y) x = fderiv π f x := (hf.has_fderiv_at.const_add c).fderiv end add section neg /-! ### Derivative of the negative of a function -/ theorem has_fderiv_at_filter.neg (h : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter (Ξ» x, -f x) (-f') x L := (h.const_smul (-1:π)).congr (by simp) (by simp) theorem has_fderiv_within_at.neg (h : has_fderiv_within_at f f' s x) : has_fderiv_within_at (Ξ» x, -f x) (-f') s x := h.neg theorem has_fderiv_at.neg (h : has_fderiv_at f f' x) : has_fderiv_at (Ξ» x, -f x) (-f') x := h.neg lemma differentiable_within_at.neg (h : differentiable_within_at π f s x) : differentiable_within_at π (Ξ»y, -f y) s x := h.has_fderiv_within_at.neg.differentiable_within_at lemma differentiable_at.neg (h : differentiable_at π f x) : differentiable_at π (Ξ»y, -f y) x := h.has_fderiv_at.neg.differentiable_at lemma differentiable_on.neg (h : differentiable_on π f s) : differentiable_on π (Ξ»y, -f y) s := Ξ»x hx, (h x hx).neg lemma differentiable.neg (h : differentiable π f) : differentiable π (Ξ»y, -f y) := Ξ»x, (h x).neg lemma fderiv_within_neg (hxs : unique_diff_within_at π s x) (h : differentiable_within_at π f s x) : fderiv_within π (Ξ»y, -f y) s x = - fderiv_within π f s x := h.has_fderiv_within_at.neg.fderiv_within hxs lemma fderiv_neg (h : differentiable_at π f x) : fderiv π (Ξ»y, -f y) x = - fderiv π f x := h.has_fderiv_at.neg.fderiv end neg section sub /-! ### Derivative of the difference of two functions -/ theorem has_fderiv_at_filter.sub (hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) : has_fderiv_at_filter (Ξ» x, f x - g x) (f' - g') x L := hf.add hg.neg theorem has_fderiv_within_at.sub (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) : has_fderiv_within_at (Ξ» x, f x - g x) (f' - g') s x := hf.sub hg theorem has_fderiv_at.sub (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) : has_fderiv_at (Ξ» x, f x - g x) (f' - g') x := hf.sub hg lemma differentiable_within_at.sub (hf : differentiable_within_at π f s x) (hg : differentiable_within_at π g s x) : differentiable_within_at π (Ξ» y, f y - g y) s x := (hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.sub (hf : differentiable_at π f x) (hg : differentiable_at π g x) : differentiable_at π (Ξ» y, f y - g y) x := (hf.has_fderiv_at.sub hg.has_fderiv_at).differentiable_at lemma differentiable_on.sub (hf : differentiable_on π f s) (hg : differentiable_on π g s) : differentiable_on π (Ξ»y, f y - g y) s := Ξ»x hx, (hf x hx).sub (hg x hx) lemma differentiable.sub (hf : differentiable π f) (hg : differentiable π g) : differentiable π (Ξ»y, f y - g y) := Ξ»x, (hf x).sub (hg x) lemma fderiv_within_sub (hxs : unique_diff_within_at π s x) (hf : differentiable_within_at π f s x) (hg : differentiable_within_at π g s x) : fderiv_within π (Ξ»y, f y - g y) s x = fderiv_within π f s x - fderiv_within π g s x := (hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).fderiv_within hxs lemma fderiv_sub (hf : differentiable_at π f x) (hg : differentiable_at π g x) : fderiv π (Ξ»y, f y - g y) x = fderiv π f x - fderiv π g x := (hf.has_fderiv_at.sub hg.has_fderiv_at).fderiv theorem has_fderiv_at_filter.is_O_sub (h : has_fderiv_at_filter f f' x L) : is_O (Ξ» x', f x' - f x) (Ξ» x', x' - x) L := h.is_O.congr_of_sub.2 (f'.is_O_sub _ _) theorem has_fderiv_at_filter.sub_const (hf : has_fderiv_at_filter f f' x L) (c : F) : has_fderiv_at_filter (Ξ» x, f x - c) f' x L := hf.add_const (-c) theorem has_fderiv_within_at.sub_const (hf : has_fderiv_within_at f f' s x) (c : F) : has_fderiv_within_at (Ξ» x, f x - c) f' s x := hf.sub_const c theorem has_fderiv_at.sub_const (hf : has_fderiv_at f f' x) (c : F) : has_fderiv_at (Ξ» x, f x - c) f' x := hf.sub_const c lemma differentiable_within_at.sub_const (hf : differentiable_within_at π f s x) (c : F) : differentiable_within_at π (Ξ» y, f y - c) s x := (hf.has_fderiv_within_at.sub_const c).differentiable_within_at lemma differentiable_at.sub_const (hf : differentiable_at π f x) (c : F) : differentiable_at π (Ξ» y, f y - c) x := (hf.has_fderiv_at.sub_const c).differentiable_at lemma differentiable_on.sub_const (hf : differentiable_on π f s) (c : F) : differentiable_on π (Ξ»y, f y - c) s := Ξ»x hx, (hf x hx).sub_const c lemma differentiable.sub_const (hf : differentiable π f) (c : F) : differentiable π (Ξ»y, f y - c) := Ξ»x, (hf x).sub_const c lemma fderiv_within_sub_const (hxs : unique_diff_within_at π s x) (hf : differentiable_within_at π f s x) (c : F) : fderiv_within π (Ξ»y, f y - c) s x = fderiv_within π f s x := (hf.has_fderiv_within_at.sub_const c).fderiv_within hxs lemma fderiv_sub_const (hf : differentiable_at π f x) (c : F) : fderiv π (Ξ»y, f y - c) x = fderiv π f x := (hf.has_fderiv_at.sub_const c).fderiv theorem has_fderiv_at_filter.const_sub (hf : has_fderiv_at_filter f f' x L) (c : F) : has_fderiv_at_filter (Ξ» x, c - f x) (-f') x L := hf.neg.const_add c theorem has_fderiv_within_at.const_sub (hf : has_fderiv_within_at f f' s x) (c : F) : has_fderiv_within_at (Ξ» x, c - f x) (-f') s x := hf.const_sub c theorem has_fderiv_at.const_sub (hf : has_fderiv_at f f' x) (c : F) : has_fderiv_at (Ξ» x, c - f x) (-f') x := hf.const_sub c lemma differentiable_within_at.const_sub (hf : differentiable_within_at π f s x) (c : F) : differentiable_within_at π (Ξ» y, c - f y) s x := (hf.has_fderiv_within_at.const_sub c).differentiable_within_at lemma differentiable_at.const_sub (hf : differentiable_at π f x) (c : F) : differentiable_at π (Ξ» y, c - f y) x := (hf.has_fderiv_at.const_sub c).differentiable_at lemma differentiable_on.const_sub (hf : differentiable_on π f s) (c : F) : differentiable_on π (Ξ»y, c - f y) s := Ξ»x hx, (hf x hx).const_sub c lemma differentiable.const_sub (hf : differentiable π f) (c : F) : differentiable π (Ξ»y, c - f y) := Ξ»x, (hf x).const_sub c lemma fderiv_within_const_sub (hxs : unique_diff_within_at π s x) (hf : differentiable_within_at π f s x) (c : F) : fderiv_within π (Ξ»y, c - f y) s x = -fderiv_within π f s x := (hf.has_fderiv_within_at.const_sub c).fderiv_within hxs lemma fderiv_const_sub (hf : differentiable_at π f x) (c : F) : fderiv π (Ξ»y, c - f y) x = -fderiv π f x := (hf.has_fderiv_at.const_sub c).fderiv end sub section continuous /-! ### Deducing continuity from differentiability -/ theorem has_fderiv_at_filter.tendsto_nhds (hL : L β€ π x) (h : has_fderiv_at_filter f f' x L) : tendsto f L (π (f x)) := begin have : tendsto (Ξ» x', f x' - f x) L (π 0), { refine h.is_O_sub.trans_tendsto (tendsto_le_left hL _), rw β sub_self x, exact tendsto_id.sub tendsto_const_nhds }, have := tendsto.add this tendsto_const_nhds, rw zero_add (f x) at this, exact this.congr (by simp) end theorem has_fderiv_within_at.continuous_within_at (h : has_fderiv_within_at f f' s x) : continuous_within_at f s x := has_fderiv_at_filter.tendsto_nhds lattice.inf_le_left h theorem has_fderiv_at.continuous_at (h : has_fderiv_at f f' x) : continuous_at f x := has_fderiv_at_filter.tendsto_nhds (le_refl _) h lemma differentiable_within_at.continuous_within_at (h : differentiable_within_at π f s x) : continuous_within_at f s x := let β¨f', hf'β© := h in hf'.continuous_within_at lemma differentiable_at.continuous_at (h : differentiable_at π f x) : continuous_at f x := let β¨f', hf'β© := h in hf'.continuous_at lemma differentiable_on.continuous_on (h : differentiable_on π f s) : continuous_on f s := Ξ»x hx, (h x hx).continuous_within_at lemma differentiable.continuous (h : differentiable π f) : continuous f := continuous_iff_continuous_at.2 $ Ξ»x, (h x).continuous_at end continuous section bilinear_map /-! ### Derivative of a bounded bilinear map -/ variables {b : E Γ F β G} {u : set (E Γ F) } open normed_field lemma is_bounded_bilinear_map.has_fderiv_at (h : is_bounded_bilinear_map π b) (p : E Γ F) : has_fderiv_at b (h.deriv p) p := begin have : (Ξ» (x : E Γ F), b x - b p - (h.deriv p) (x - p)) = (Ξ»x, b (x.1 - p.1, x.2 - p.2)), { ext x, delta is_bounded_bilinear_map.deriv, change b x - b p - (b (p.1, x.2-p.2) + b (x.1-p.1, p.2)) = b (x.1 - p.1, x.2 - p.2), have : b x = b (x.1, x.2), by { cases x, refl }, rw this, have : b p = b (p.1, p.2), by { cases p, refl }, rw this, simp only [h.map_sub_left, h.map_sub_right], abel }, rw [has_fderiv_at, has_fderiv_at_filter, this], rcases h.bound with β¨C, Cpos, hCβ©, have A : asymptotics.is_O (Ξ»x : E Γ F, b (x.1 - p.1, x.2 - p.2)) (Ξ»x, β₯x - pβ₯ * β₯x - pβ₯) (π p) := β¨C, filter.univ_mem_sets' (Ξ»x, begin simp only [mem_set_of_eq, norm_mul, norm_norm], calc β₯b (x.1 - p.1, x.2 - p.2)β₯ β€ C * β₯x.1 - p.1β₯ * β₯x.2 - p.2β₯ : hC _ _ ... β€ C * β₯x-pβ₯ * β₯x-pβ₯ : by apply_rules [mul_le_mul, le_max_left, le_max_right, norm_nonneg, le_of_lt Cpos, le_refl, mul_nonneg, norm_nonneg, norm_nonneg] ... = C * (β₯x-pβ₯ * β₯x-pβ₯) : mul_assoc _ _ _ end)β©, have B : asymptotics.is_o (Ξ» (x : E Γ F), β₯x - pβ₯ * β₯x - pβ₯) (Ξ»x, 1 * β₯x - pβ₯) (π p), { refine asymptotics.is_o.mul_is_O (asymptotics.is_o.norm_left _) (asymptotics.is_O_refl _ _), apply (asymptotics.is_o_one_iff β).2, rw [β sub_self p], exact tendsto_id.sub tendsto_const_nhds }, simp only [one_mul, asymptotics.is_o_norm_right] at B, exact A.trans_is_o B end lemma is_bounded_bilinear_map.has_fderiv_within_at (h : is_bounded_bilinear_map π b) (p : E Γ F) : has_fderiv_within_at b (h.deriv p) u p := (h.has_fderiv_at p).has_fderiv_within_at lemma is_bounded_bilinear_map.differentiable_at (h : is_bounded_bilinear_map π b) (p : E Γ F) : differentiable_at π b p := (h.has_fderiv_at p).differentiable_at lemma is_bounded_bilinear_map.differentiable_within_at (h : is_bounded_bilinear_map π b) (p : E Γ F) : differentiable_within_at π b u p := (h.differentiable_at p).differentiable_within_at lemma is_bounded_bilinear_map.fderiv (h : is_bounded_bilinear_map π b) (p : E Γ F) : fderiv π b p = h.deriv p := has_fderiv_at.fderiv (h.has_fderiv_at p) lemma is_bounded_bilinear_map.fderiv_within (h : is_bounded_bilinear_map π b) (p : E Γ F) (hxs : unique_diff_within_at π u p) : fderiv_within π b u p = h.deriv p := begin rw differentiable_at.fderiv_within (h.differentiable_at p) hxs, exact h.fderiv p end lemma is_bounded_bilinear_map.differentiable (h : is_bounded_bilinear_map π b) : differentiable π b := Ξ»x, h.differentiable_at x lemma is_bounded_bilinear_map.differentiable_on (h : is_bounded_bilinear_map π b) : differentiable_on π b u := h.differentiable.differentiable_on lemma is_bounded_bilinear_map.continuous (h : is_bounded_bilinear_map π b) : continuous b := h.differentiable.continuous lemma is_bounded_bilinear_map.continuous_left (h : is_bounded_bilinear_map π b) {f : F} : continuous (Ξ»e, b (e, f)) := h.continuous.comp (continuous_id.prod_mk continuous_const) lemma is_bounded_bilinear_map.continuous_right (h : is_bounded_bilinear_map π b) {e : E} : continuous (Ξ»f, b (e, f)) := h.continuous.comp (continuous_const.prod_mk continuous_id) end bilinear_map section cartesian_product /-! ### Derivative of the cartesian product of two functions -/ variables {fβ : E β G} {fβ' : E βL[π] G} lemma has_fderiv_at_filter.prod (hfβ : has_fderiv_at_filter fβ fβ' x L) (hfβ : has_fderiv_at_filter fβ fβ' x L) : has_fderiv_at_filter (Ξ»x, (fβ x, fβ x)) (continuous_linear_map.prod fβ' fβ') x L := begin have : (Ξ» (x' : E), (fβ x', fβ x') - (fβ x, fβ x) - (continuous_linear_map.prod fβ' fβ') (x' -x)) = (Ξ» (x' : E), (fβ x' - fβ x - fβ' (x' - x), fβ x' - fβ x - fβ' (x' - x))) := rfl, rw [has_fderiv_at_filter, this], rw [asymptotics.is_o_prod_left], exact β¨hfβ, hfββ© end lemma has_fderiv_within_at.prod (hfβ : has_fderiv_within_at fβ fβ' s x) (hfβ : has_fderiv_within_at fβ fβ' s x) : has_fderiv_within_at (Ξ»x, (fβ x, fβ x)) (continuous_linear_map.prod fβ' fβ') s x := hfβ.prod hfβ lemma has_fderiv_at.prod (hfβ : has_fderiv_at fβ fβ' x) (hfβ : has_fderiv_at fβ fβ' x) : has_fderiv_at (Ξ»x, (fβ x, fβ x)) (continuous_linear_map.prod fβ' fβ') x := hfβ.prod hfβ lemma differentiable_within_at.prod (hfβ : differentiable_within_at π fβ s x) (hfβ : differentiable_within_at π fβ s x) : differentiable_within_at π (Ξ»x:E, (fβ x, fβ x)) s x := (hfβ.has_fderiv_within_at.prod hfβ.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.prod (hfβ : differentiable_at π fβ x) (hfβ : differentiable_at π fβ x) : differentiable_at π (Ξ»x:E, (fβ x, fβ x)) x := (hfβ.has_fderiv_at.prod hfβ.has_fderiv_at).differentiable_at lemma differentiable_on.prod (hfβ : differentiable_on π fβ s) (hfβ : differentiable_on π fβ s) : differentiable_on π (Ξ»x:E, (fβ x, fβ x)) s := Ξ»x hx, differentiable_within_at.prod (hfβ x hx) (hfβ x hx) lemma differentiable.prod (hfβ : differentiable π fβ) (hfβ : differentiable π fβ) : differentiable π (Ξ»x:E, (fβ x, fβ x)) := Ξ» x, differentiable_at.prod (hfβ x) (hfβ x) lemma differentiable_at.fderiv_prod (hfβ : differentiable_at π fβ x) (hfβ : differentiable_at π fβ x) : fderiv π (Ξ»x:E, (fβ x, fβ x)) x = continuous_linear_map.prod (fderiv π fβ x) (fderiv π fβ x) := has_fderiv_at.fderiv (has_fderiv_at.prod hfβ.has_fderiv_at hfβ.has_fderiv_at) lemma differentiable_at.fderiv_within_prod (hfβ : differentiable_within_at π fβ s x) (hfβ : differentiable_within_at π fβ s x) (hxs : unique_diff_within_at π s x) : fderiv_within π (Ξ»x:E, (fβ x, fβ x)) s x = continuous_linear_map.prod (fderiv_within π fβ s x) (fderiv_within π fβ s x) := begin apply has_fderiv_within_at.fderiv_within _ hxs, exact has_fderiv_within_at.prod hfβ.has_fderiv_within_at hfβ.has_fderiv_within_at end end cartesian_product section composition /-! ### Derivative of the composition of two functions 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 -/ variable (x) theorem has_fderiv_at_filter.comp {g : F β G} {g' : F βL[π] G} (hg : has_fderiv_at_filter g g' (f x) (L.map f)) (hf : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter (g β f) (g'.comp f') x L := let eqβ := (g'.is_O_comp _ _).trans_is_o hf in let eqβ := (hg.comp_tendsto tendsto_map).trans_is_O hf.is_O_sub in by { refine eqβ.triangle (eqβ.congr_left (Ξ» x', _)), simp } /- A readable version of the previous theorem, a general form of the chain rule. -/ example {g : F β G} {g' : F βL[π] G} (hg : has_fderiv_at_filter g g' (f x) (L.map f)) (hf : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter (g β f) (g'.comp f') x L := begin unfold has_fderiv_at_filter at hg, have : is_o (Ξ» x', g (f x') - g (f x) - g' (f x' - f x)) (Ξ» x', f x' - f x) L, from hg.comp_tendsto (le_refl _), have eqβ : is_o (Ξ» x', g (f x') - g (f x) - g' (f x' - f x)) (Ξ» x', x' - x) L, from this.trans_is_O hf.is_O_sub, have eqβ : is_o (Ξ» x', f x' - f x - f' (x' - x)) (Ξ» x', x' - x) L, from hf, have : is_O (Ξ» x', g' (f x' - f x - f' (x' - x))) (Ξ» x', f x' - f x - f' (x' - x)) L, from g'.is_O_comp _ _, have : is_o (Ξ» x', g' (f x' - f x - f' (x' - x))) (Ξ» x', x' - x) L, from this.trans_is_o eqβ, have eqβ : is_o (Ξ» x', g' (f x' - f x) - (g' (f' (x' - x)))) (Ξ» x', x' - x) L, by { refine this.congr_left _, simp}, exact eqβ.triangle eqβ end theorem has_fderiv_within_at.comp {g : F β G} {g' : F βL[π] G} {t : set F} (hg : has_fderiv_within_at g g' t (f x)) (hf : has_fderiv_within_at f f' s x) (hst : s β f β»ΒΉ' t) : has_fderiv_within_at (g β f) (g'.comp f') s x := begin apply has_fderiv_at_filter.comp _ (has_fderiv_at_filter.mono hg _) hf, calc map f (nhds_within x s) β€ nhds_within (f x) (f '' s) : hf.continuous_within_at.tendsto_nhds_within_image ... β€ nhds_within (f x) t : nhds_within_mono _ (image_subset_iff.mpr hst) end /-- The chain rule. -/ theorem has_fderiv_at.comp {g : F β G} {g' : F βL[π] G} (hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_at f f' x) : has_fderiv_at (g β f) (g'.comp f') x := (hg.mono hf.continuous_at).comp x hf theorem has_fderiv_at.comp_has_fderiv_within_at {g : F β G} {g' : F βL[π] G} (hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (g β f) (g'.comp f') s x := begin rw β has_fderiv_within_at_univ at hg, exact has_fderiv_within_at.comp x hg hf subset_preimage_univ end lemma differentiable_within_at.comp {g : F β G} {t : set F} (hg : differentiable_within_at π g t (f x)) (hf : differentiable_within_at π f s x) (h : s β f β»ΒΉ' t) : differentiable_within_at π (g β f) s x := begin rcases hf with β¨f', hf'β©, rcases hg with β¨g', hg'β©, exact β¨continuous_linear_map.comp g' f', hg'.comp x hf' hβ© end lemma differentiable_at.comp {g : F β G} (hg : differentiable_at π g (f x)) (hf : differentiable_at π f x) : differentiable_at π (g β f) x := (hg.has_fderiv_at.comp x hf.has_fderiv_at).differentiable_at lemma fderiv_within.comp {g : F β G} {t : set F} (hg : differentiable_within_at π g t (f x)) (hf : differentiable_within_at π f s x) (h : s β f β»ΒΉ' t) (hxs : unique_diff_within_at π s x) : fderiv_within π (g β f) s x = continuous_linear_map.comp (fderiv_within π g t (f x)) (fderiv_within π f s x) := begin apply has_fderiv_within_at.fderiv_within _ hxs, exact has_fderiv_within_at.comp x (hg.has_fderiv_within_at) (hf.has_fderiv_within_at) h end lemma fderiv.comp {g : F β G} (hg : differentiable_at π g (f x)) (hf : differentiable_at π f x) : fderiv π (g β f) x = continuous_linear_map.comp (fderiv π g (f x)) (fderiv π f x) := begin apply has_fderiv_at.fderiv, exact has_fderiv_at.comp x hg.has_fderiv_at hf.has_fderiv_at end lemma differentiable_on.comp {g : F β G} {t : set F} (hg : differentiable_on π g t) (hf : differentiable_on π f s) (st : s β f β»ΒΉ' t) : differentiable_on π (g β f) s := Ξ»x hx, differentiable_within_at.comp x (hg (f x) (st hx)) (hf x hx) st lemma differentiable.comp {g : F β G} (hg : differentiable π g) (hf : differentiable π f) : differentiable π (g β f) := Ξ»x, differentiable_at.comp x (hg (f x)) (hf x) end composition section smul /-! ### Derivative of the product of a scalar-valued function and a vector-valued function -/ variables {c : E β π} {c' : E βL[π] π} theorem has_fderiv_within_at.smul (hc : has_fderiv_within_at c c' s x) (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (Ξ» y, c y β’ f y) (c x β’ f' + c'.smul_right (f x)) s x := begin have : is_bounded_bilinear_map π (Ξ» (p : π Γ F), p.1 β’ p.2) := is_bounded_bilinear_map_smul, exact has_fderiv_at.comp_has_fderiv_within_at x (this.has_fderiv_at (c x, f x)) (hc.prod hf) end theorem has_fderiv_at.smul (hc : has_fderiv_at c c' x) (hf : has_fderiv_at f f' x) : has_fderiv_at (Ξ» y, c y β’ f y) (c x β’ f' + c'.smul_right (f x)) x := begin have : is_bounded_bilinear_map π (Ξ» (p : π Γ F), p.1 β’ p.2) := is_bounded_bilinear_map_smul, exact has_fderiv_at.comp x (this.has_fderiv_at (c x, f x)) (hc.prod hf) end lemma differentiable_within_at.smul (hc : differentiable_within_at π c s x) (hf : differentiable_within_at π f s x) : differentiable_within_at π (Ξ» y, c y β’ f y) s x := (hc.has_fderiv_within_at.smul hf.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.smul (hc : differentiable_at π c x) (hf : differentiable_at π f x) : differentiable_at π (Ξ» y, c y β’ f y) x := (hc.has_fderiv_at.smul hf.has_fderiv_at).differentiable_at lemma differentiable_on.smul (hc : differentiable_on π c s) (hf : differentiable_on π f s) : differentiable_on π (Ξ» y, c y β’ f y) s := Ξ»x hx, (hc x hx).smul (hf x hx) lemma differentiable.smul (hc : differentiable π c) (hf : differentiable π f) : differentiable π (Ξ» y, c y β’ f y) := Ξ»x, (hc x).smul (hf x) lemma fderiv_within_smul (hxs : unique_diff_within_at π s x) (hc : differentiable_within_at π c s x) (hf : differentiable_within_at π f s x) : fderiv_within π (Ξ» y, c y β’ f y) s x = c x β’ fderiv_within π f s x + (fderiv_within π c s x).smul_right (f x) := (hc.has_fderiv_within_at.smul hf.has_fderiv_within_at).fderiv_within hxs lemma fderiv_smul (hc : differentiable_at π c x) (hf : differentiable_at π f x) : fderiv π (Ξ» y, c y β’ f y) x = c x β’ fderiv π f x + (fderiv π c x).smul_right (f x) := (hc.has_fderiv_at.smul hf.has_fderiv_at).fderiv theorem has_fderiv_within_at.smul_const (hc : has_fderiv_within_at c c' s x) (f : F) : has_fderiv_within_at (Ξ» y, c y β’ f) (c'.smul_right f) s x := begin convert hc.smul (has_fderiv_within_at_const f x s), -- Help Lean find an instance letI : distrib_mul_action π (E βL[π] F) := continuous_linear_map.module.to_distrib_mul_action, rw [smul_zero, zero_add] end theorem has_fderiv_at.smul_const (hc : has_fderiv_at c c' x) (f : F) : has_fderiv_at (Ξ» y, c y β’ f) (c'.smul_right f) x := begin rw [β has_fderiv_within_at_univ] at *, exact hc.smul_const f end lemma differentiable_within_at.smul_const (hc : differentiable_within_at π c s x) (f : F) : differentiable_within_at π (Ξ» y, c y β’ f) s x := (hc.has_fderiv_within_at.smul_const f).differentiable_within_at lemma differentiable_at.smul_const (hc : differentiable_at π c x) (f : F) : differentiable_at π (Ξ» y, c y β’ f) x := (hc.has_fderiv_at.smul_const f).differentiable_at lemma differentiable_on.smul_const (hc : differentiable_on π c s) (f : F) : differentiable_on π (Ξ» y, c y β’ f) s := Ξ»x hx, (hc x hx).smul_const f lemma differentiable.smul_const (hc : differentiable π c) (f : F) : differentiable π (Ξ» y, c y β’ f) := Ξ»x, (hc x).smul_const f lemma fderiv_within_smul_const (hxs : unique_diff_within_at π s x) (hc : differentiable_within_at π c s x) (f : F) : fderiv_within π (Ξ» y, c y β’ f) s x = (fderiv_within π c s x).smul_right f := (hc.has_fderiv_within_at.smul_const f).fderiv_within hxs lemma fderiv_smul_const (hc : differentiable_at π c x) (f : F) : fderiv π (Ξ» y, c y β’ f) x = (fderiv π c x).smul_right f := (hc.has_fderiv_at.smul_const f).fderiv end smul section mul /-! ### Derivative of the product of two scalar-valued functions -/ set_option class.instance_max_depth 120 variables {c d : E β π} {c' d' : E βL[π] π} theorem has_fderiv_within_at.mul (hc : has_fderiv_within_at c c' s x) (hd : has_fderiv_within_at d d' s x) : has_fderiv_within_at (Ξ» y, c y * d y) (c x β’ d' + d x β’ c') s x := begin have : is_bounded_bilinear_map π (Ξ» (p : π Γ π), p.1 * p.2) := is_bounded_bilinear_map_mul, convert has_fderiv_at.comp_has_fderiv_within_at x (this.has_fderiv_at (c x, d x)) (hc.prod hd), ext z, change c x * d' z + d x * c' z = c x * d' z + c' z * d x, ring end theorem has_fderiv_at.mul (hc : has_fderiv_at c c' x) (hd : has_fderiv_at d d' x) : has_fderiv_at (Ξ» y, c y * d y) (c x β’ d' + d x β’ c') x := begin have : is_bounded_bilinear_map π (Ξ» (p : π Γ π), p.1 * p.2) := is_bounded_bilinear_map_mul, convert has_fderiv_at.comp x (this.has_fderiv_at (c x, d x)) (hc.prod hd), ext z, change c x * d' z + d x * c' z = c x * d' z + c' z * d x, ring end lemma differentiable_within_at.mul (hc : differentiable_within_at π c s x) (hd : differentiable_within_at π d s x) : differentiable_within_at π (Ξ» y, c y * d y) s x := (hc.has_fderiv_within_at.mul hd.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.mul (hc : differentiable_at π c x) (hd : differentiable_at π d x) : differentiable_at π (Ξ» y, c y * d y) x := (hc.has_fderiv_at.mul hd.has_fderiv_at).differentiable_at lemma differentiable_on.mul (hc : differentiable_on π c s) (hd : differentiable_on π d s) : differentiable_on π (Ξ» y, c y * d y) s := Ξ»x hx, (hc x hx).mul (hd x hx) lemma differentiable.mul (hc : differentiable π c) (hd : differentiable π d) : differentiable π (Ξ» y, c y * d y) := Ξ»x, (hc x).mul (hd x) lemma fderiv_within_mul (hxs : unique_diff_within_at π s x) (hc : differentiable_within_at π c s x) (hd : differentiable_within_at π d s x) : fderiv_within π (Ξ» y, c y * d y) s x = c x β’ fderiv_within π d s x + d x β’ fderiv_within π c s x := (hc.has_fderiv_within_at.mul hd.has_fderiv_within_at).fderiv_within hxs lemma fderiv_mul (hc : differentiable_at π c x) (hd : differentiable_at π d x) : fderiv π (Ξ» y, c y * d y) x = c x β’ fderiv π d x + d x β’ fderiv π c x := (hc.has_fderiv_at.mul hd.has_fderiv_at).fderiv theorem has_fderiv_within_at.mul_const (hc : has_fderiv_within_at c c' s x) (d : π) : has_fderiv_within_at (Ξ» y, c y * d) (d β’ c') s x := begin have := hc.mul (has_fderiv_within_at_const d x s), letI : distrib_mul_action π (E βL[π] π) := continuous_linear_map.module.to_distrib_mul_action, rwa [smul_zero, zero_add] at this end theorem has_fderiv_at.mul_const (hc : has_fderiv_at c c' x) (d : π) : has_fderiv_at (Ξ» y, c y * d) (d β’ c') x := begin rw [β has_fderiv_within_at_univ] at *, exact hc.mul_const d end lemma differentiable_within_at.mul_const (hc : differentiable_within_at π c s x) (d : π) : differentiable_within_at π (Ξ» y, c y * d) s x := (hc.has_fderiv_within_at.mul_const d).differentiable_within_at lemma differentiable_at.mul_const (hc : differentiable_at π c x) (d : π) : differentiable_at π (Ξ» y, c y * d) x := (hc.has_fderiv_at.mul_const d).differentiable_at lemma differentiable_on.mul_const (hc : differentiable_on π c s) (d : π) : differentiable_on π (Ξ» y, c y * d) s := Ξ»x hx, (hc x hx).mul_const d lemma differentiable.mul_const (hc : differentiable π c) (d : π) : differentiable π (Ξ» y, c y * d) := Ξ»x, (hc x).mul_const d lemma fderiv_within_mul_const (hxs : unique_diff_within_at π s x) (hc : differentiable_within_at π c s x) (d : π) : fderiv_within π (Ξ» y, c y * d) s x = d β’ fderiv_within π c s x := (hc.has_fderiv_within_at.mul_const d).fderiv_within hxs lemma fderiv_mul_const (hc : differentiable_at π c x) (d : π) : fderiv π (Ξ» y, c y * d) x = d β’ fderiv π c x := (hc.has_fderiv_at.mul_const d).fderiv theorem has_fderiv_within_at.const_mul (hc : has_fderiv_within_at c c' s x) (d : π) : has_fderiv_within_at (Ξ» y, d * c y) (d β’ c') s x := begin simp only [mul_comm d], exact hc.mul_const d, end theorem has_fderiv_at.const_mul (hc : has_fderiv_at c c' x) (d : π) : has_fderiv_at (Ξ» y, d * c y) (d β’ c') x := begin simp only [mul_comm d], exact hc.mul_const d, end lemma differentiable_within_at.const_mul (hc : differentiable_within_at π c s x) (d : π) : differentiable_within_at π (Ξ» y, d * c y) s x := (hc.has_fderiv_within_at.const_mul d).differentiable_within_at lemma differentiable_at.const_mul (hc : differentiable_at π c x) (d : π) : differentiable_at π (Ξ» y, d * c y) x := (hc.has_fderiv_at.const_mul d).differentiable_at lemma differentiable_on.const_mul (hc : differentiable_on π c s) (d : π) : differentiable_on π (Ξ» y, d * c y) s := Ξ»x hx, (hc x hx).const_mul d lemma differentiable.const_mul (hc : differentiable π c) (d : π) : differentiable π (Ξ» y, d * c y) := Ξ»x, (hc x).const_mul d lemma fderiv_within_const_mul (hxs : unique_diff_within_at π s x) (hc : differentiable_within_at π c s x) (d : π) : fderiv_within π (Ξ» y, d * c y) s x = d β’ fderiv_within π c s x := (hc.has_fderiv_within_at.const_mul d).fderiv_within hxs lemma fderiv_const_mul (hc : differentiable_at π c x) (d : π) : fderiv π (Ξ» y, d * c y) x = d β’ fderiv π c x := (hc.has_fderiv_at.const_mul d).fderiv end mul end section /- In the special case of a normed space over the reals, we can use scalar multiplication in the `tendsto` characterization of the FrΓ©chet derivative. -/ variables {E : Type*} [normed_group E] [normed_space β E] variables {F : Type*} [normed_group F] [normed_space β F] variables {f : E β F} {f' : E βL[β] F} {x : E} theorem has_fderiv_at_filter_real_equiv {L : filter E} : tendsto (Ξ» x' : E, β₯x' - xβ₯β»ΒΉ * β₯f x' - f x - f' (x' - x)β₯) L (π 0) β tendsto (Ξ» x' : E, β₯x' - xβ₯β»ΒΉ β’ (f x' - f x - f' (x' - x))) L (π 0) := begin symmetry, rw [tendsto_iff_norm_tendsto_zero], refine tendsto_congr (Ξ» x', _), have : β₯x' + -xβ₯β»ΒΉ β₯ 0, from inv_nonneg.mpr (norm_nonneg _), simp [norm_smul, real.norm_eq_abs, abs_of_nonneg this] end lemma has_fderiv_at.lim_real (hf : has_fderiv_at f f' x) (v : E) : tendsto (Ξ» (c:β), c β’ (f (x + cβ»ΒΉ β’ v) - f x)) at_top (π (f' v)) := begin apply hf.lim v, rw tendsto_at_top_at_top, exact Ξ» b, β¨b, Ξ» a ha, le_trans ha (le_abs_self _)β© end end section tangent_cone variables {π : Type*} [nondiscrete_normed_field π] {E : Type*} [normed_group E] [normed_space π E] {F : Type*} [normed_group F] [normed_space π F] {f : E β F} {s : set E} {f' : E βL[π] F} /-- The image of a tangent cone under the differential of a map is included in the tangent cone to the image. -/ lemma has_fderiv_within_at.image_tangent_cone_subset {x : E} (h : has_fderiv_within_at f f' s x) : f' '' (tangent_cone_at π s x) β tangent_cone_at π (f '' s) (f x) := begin rw image_subset_iff, rintros v β¨c, d, dtop, clim, cdlimβ©, refine β¨c, (Ξ»n, f (x + d n) - f x), mem_sets_of_superset dtop _, clim, h.lim at_top dtop clim cdlimβ©, simp [-mem_image, mem_image_of_mem] {contextual := tt} end /-- If a set has the unique differentiability property at a point x, then the image of this set under a map with onto derivative has also the unique differentiability property at the image point. -/ lemma has_fderiv_within_at.unique_diff_within_at {x : E} (h : has_fderiv_within_at f f' s x) (hs : unique_diff_within_at π s x) (h' : closure (range f') = univ) : unique_diff_within_at π (f '' s) (f x) := begin have A : βv β tangent_cone_at π s x, f' v β tangent_cone_at π (f '' s) (f x), { assume v hv, have := h.image_tangent_cone_subset, rw image_subset_iff at this, exact this hv }, have B : βv β (submodule.span π (tangent_cone_at π s x) : set E), f' v β (submodule.span π (tangent_cone_at π (f '' s) (f x)) : set F), { assume v hv, apply submodule.span_induction hv, { exact Ξ» w hw, submodule.subset_span (A w hw) }, { simp }, { assume wβ wβ hwβ hwβ, rw continuous_linear_map.map_add, exact submodule.add_mem (submodule.span π (tangent_cone_at π (f '' s) (f x))) hwβ hwβ }, { assume a w hw, rw continuous_linear_map.map_smul, exact submodule.smul_mem (submodule.span π (tangent_cone_at π (f '' s) (f x))) _ hw } }, rw [unique_diff_within_at, β univ_subset_iff], split, show f x β closure (f '' s), from h.continuous_within_at.mem_closure_image hs.2, show univ β closure β(submodule.span π (tangent_cone_at π (f '' s) (f x))), from calc univ β closure (range f') : univ_subset_iff.2 h' ... = closure (f' '' univ) : by rw image_univ ... = closure (f' '' (closure (submodule.span π (tangent_cone_at π s x) : set E))) : by rw hs.1 ... β closure (closure (f' '' (submodule.span π (tangent_cone_at π s x) : set E))) : closure_mono (image_closure_subset_closure_image f'.cont) ... = closure (f' '' (submodule.span π (tangent_cone_at π s x) : set E)) : closure_closure ... β closure (submodule.span π (tangent_cone_at π (f '' s) (f x)) : set F) : closure_mono (image_subset_iff.mpr B) end lemma has_fderiv_within_at.unique_diff_within_at_of_continuous_linear_equiv {x : E} (e' : E βL[π] F) (h : has_fderiv_within_at f (e' : E βL[π] F) s x) (hs : unique_diff_within_at π s x) : unique_diff_within_at π (f '' s) (f x) := begin apply h.unique_diff_within_at hs, have : range (e' : E βL[π] F) = univ := e'.to_linear_equiv.to_equiv.range_eq_univ, rw [this, closure_univ] end end tangent_cone section restrict_scalars /-! ### Restricting from `β` to `β`, or generally from `π'` to `π` If a function is differentiable over `β`, then it is differentiable over `β`. In this paragraph, we give variants of this statement, in the general situation where `β` and `β` are replaced respectively by `π'` and `π` where `π'` is a normed algebra over `π`. -/ variables (π : Type*) [nondiscrete_normed_field π] {π' : Type*} [nondiscrete_normed_field π'] [normed_algebra π π'] {E : Type*} [normed_group E] [normed_space π' E] {F : Type*} [normed_group F] [normed_space π' F] {f : E β F} {f' : E βL[π'] F} {s : set E} {x : E} local attribute [instance] normed_space.restrict_scalars lemma has_fderiv_at.restrict_scalars (h : has_fderiv_at f f' x) : has_fderiv_at f (f'.restrict_scalars π) x := h lemma has_fderiv_within_at.restrict_scalars (h : has_fderiv_within_at f f' s x) : has_fderiv_within_at f (f'.restrict_scalars π) s x := h lemma differentiable_at.restrict_scalars (h : differentiable_at π' f x) : differentiable_at π f x := (h.has_fderiv_at.restrict_scalars π).differentiable_at lemma differentiable_within_at.restrict_scalars (h : differentiable_within_at π' f s x) : differentiable_within_at π f s x := (h.has_fderiv_within_at.restrict_scalars π).differentiable_within_at lemma differentiable_on.restrict_scalars (h : differentiable_on π' f s) : differentiable_on π f s := Ξ»x hx, (h x hx).restrict_scalars π lemma differentiable.restrict_scalars (h : differentiable π' f) : differentiable π f := Ξ»x, (h x).restrict_scalars π end restrict_scalars