path
stringlengths
11
71
content
stringlengths
75
124k
Analysis\Analytic\IsolatedZeros.lean
/- Copyright (c) 2022 Vincent Beffara. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Vincent Beffara -/ import Mathlib.Analysis.Analytic.Constructions import Mathlib.Analysis.Calculus.Dslope import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Analytic.Uniqueness /-! # Principle of isolated zeros This file proves the fact that the zeros of a non-constant analytic function of one variable are isolated. It also introduces a little bit of API in the `HasFPowerSeriesAt` namespace that is useful in this setup. ## Main results * `AnalyticAt.eventually_eq_zero_or_eventually_ne_zero` is the main statement that if a function is analytic at `z₀`, then either it is identically zero in a neighborhood of `z₀`, or it does not vanish in a punctured neighborhood of `z₀`. * `AnalyticOn.eqOn_of_preconnected_of_frequently_eq` is the identity theorem for analytic functions: if a function `f` is analytic on a connected set `U` and is zero on a set with an accumulation point in `U` then `f` is identically `0` on `U`. -/ open scoped Classical open Filter Function Nat FormalMultilinearSeries EMetric Set open scoped Topology variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {s : E} {p q : FormalMultilinearSeries 𝕜 𝕜 E} {f g : 𝕜 → E} {n : ℕ} {z z₀ : 𝕜} namespace HasSum variable {a : ℕ → E} theorem hasSum_at_zero (a : ℕ → E) : HasSum (fun n => (0 : 𝕜) ^ n • a n) (a 0) := by convert hasSum_single (α := E) 0 fun b h ↩ _ <;> simp [*] theorem exists_hasSum_smul_of_apply_eq_zero (hs : HasSum (fun m => z ^ m • a m) s) (ha : ∀ k < n, a k = 0) : ∃ t : E, z ^ n • t = s ∧ HasSum (fun m => z ^ m • a (m + n)) t := by obtain rfl | hn := n.eq_zero_or_pos · simpa by_cases h : z = 0 · have : s = 0 := hs.unique (by simpa [ha 0 hn, h] using hasSum_at_zero a) exact ⟹a n, by simp [h, hn.ne', this], by simpa [h] using hasSum_at_zero fun m => a (m + n)⟩ · refine ⟹(z ^ n)⁻¹ • s, by field_simp [smul_smul], ?_⟩ have h1 : ∑ i ∈ Finset.range n, z ^ i • a i = 0 := Finset.sum_eq_zero fun k hk => by simp [ha k (Finset.mem_range.mp hk)] have h2 : HasSum (fun m => z ^ (m + n) • a (m + n)) s := by simpa [h1] using (hasSum_nat_add_iff' n).mpr hs convert h2.const_smul (z⁻¹ ^ n) using 1 · field_simp [pow_add, smul_smul] · simp only [inv_pow] end HasSum namespace HasFPowerSeriesAt theorem has_fpower_series_dslope_fslope (hp : HasFPowerSeriesAt f p z₀) : HasFPowerSeriesAt (dslope f z₀) p.fslope z₀ := by have hpd : deriv f z₀ = p.coeff 1 := hp.deriv have hp0 : p.coeff 0 = f z₀ := hp.coeff_zero 1 simp only [hasFPowerSeriesAt_iff, apply_eq_pow_smul_coeff, coeff_fslope] at hp ⊢ refine hp.mono fun x hx => ?_ by_cases h : x = 0 · convert hasSum_single (α := E) 0 _ <;> intros <;> simp [*] · have hxx : ∀ n : ℕ, x⁻¹ * x ^ (n + 1) = x ^ n := fun n => by field_simp [h, _root_.pow_succ] suffices HasSum (fun n => x⁻¹ • x ^ (n + 1) • p.coeff (n + 1)) (x⁻¹ • (f (z₀ + x) - f z₀)) by simpa [dslope, slope, h, smul_smul, hxx] using this simpa [hp0] using ((hasSum_nat_add_iff' 1).mpr hx).const_smul x⁻¹ theorem has_fpower_series_iterate_dslope_fslope (n : ℕ) (hp : HasFPowerSeriesAt f p z₀) : HasFPowerSeriesAt ((swap dslope z₀)^[n] f) (fslope^[n] p) z₀ := by induction' n with n ih generalizing f p · exact hp · simpa using ih (has_fpower_series_dslope_fslope hp) theorem iterate_dslope_fslope_ne_zero (hp : HasFPowerSeriesAt f p z₀) (h : p ≠ 0) : (swap dslope z₀)^[p.order] f z₀ ≠ 0 := by rw [← coeff_zero (has_fpower_series_iterate_dslope_fslope p.order hp) 1] simpa [coeff_eq_zero] using apply_order_ne_zero h theorem eq_pow_order_mul_iterate_dslope (hp : HasFPowerSeriesAt f p z₀) : ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ p.order • (swap dslope z₀)^[p.order] f z := by have hq := hasFPowerSeriesAt_iff'.mp (has_fpower_series_iterate_dslope_fslope p.order hp) filter_upwards [hq, hasFPowerSeriesAt_iff'.mp hp] with x hx1 hx2 have : ∀ k < p.order, p.coeff k = 0 := fun k hk => by simpa [coeff_eq_zero] using apply_eq_zero_of_lt_order hk obtain ⟹s, hs1, hs2⟩ := HasSum.exists_hasSum_smul_of_apply_eq_zero hx2 this convert hs1.symm simp only [coeff_iterate_fslope] at hx1 exact hx1.unique hs2 theorem locally_ne_zero (hp : HasFPowerSeriesAt f p z₀) (h : p ≠ 0) : ∀ᶠ z in 𝓝[≠] z₀, f z ≠ 0 := by rw [eventually_nhdsWithin_iff] have h2 := (has_fpower_series_iterate_dslope_fslope p.order hp).continuousAt have h3 := h2.eventually_ne (iterate_dslope_fslope_ne_zero hp h) filter_upwards [eq_pow_order_mul_iterate_dslope hp, h3] with z e1 e2 e3 simpa [e1, e2, e3] using pow_ne_zero p.order (sub_ne_zero.mpr e3) theorem locally_zero_iff (hp : HasFPowerSeriesAt f p z₀) : (∀ᶠ z in 𝓝 z₀, f z = 0) ↔ p = 0 := ⟹fun hf => hp.eq_zero_of_eventually hf, fun h => eventually_eq_zero (by rwa [h] at hp)⟩ end HasFPowerSeriesAt namespace AnalyticAt /-- The *principle of isolated zeros* for an analytic function, local version: if a function is analytic at `z₀`, then either it is identically zero in a neighborhood of `z₀`, or it does not vanish in a punctured neighborhood of `z₀`. -/ theorem eventually_eq_zero_or_eventually_ne_zero (hf : AnalyticAt 𝕜 f z₀) : (∀ᶠ z in 𝓝 z₀, f z = 0) √ ∀ᶠ z in 𝓝[≠] z₀, f z ≠ 0 := by rcases hf with ⟹p, hp⟩ by_cases h : p = 0 · exact Or.inl (HasFPowerSeriesAt.eventually_eq_zero (by rwa [h] at hp)) · exact Or.inr (hp.locally_ne_zero h) theorem eventually_eq_or_eventually_ne (hf : AnalyticAt 𝕜 f z₀) (hg : AnalyticAt 𝕜 g z₀) : (∀ᶠ z in 𝓝 z₀, f z = g z) √ ∀ᶠ z in 𝓝[≠] z₀, f z ≠ g z := by simpa [sub_eq_zero] using (hf.sub hg).eventually_eq_zero_or_eventually_ne_zero theorem frequently_zero_iff_eventually_zero {f : 𝕜 → E} {w : 𝕜} (hf : AnalyticAt 𝕜 f w) : (∃ᶠ z in 𝓝[≠] w, f z = 0) ↔ ∀ᶠ z in 𝓝 w, f z = 0 := ⟹hf.eventually_eq_zero_or_eventually_ne_zero.resolve_right, fun h => (h.filter_mono nhdsWithin_le_nhds).frequently⟩ theorem frequently_eq_iff_eventually_eq (hf : AnalyticAt 𝕜 f z₀) (hg : AnalyticAt 𝕜 g z₀) : (∃ᶠ z in 𝓝[≠] z₀, f z = g z) ↔ ∀ᶠ z in 𝓝 z₀, f z = g z := by simpa [sub_eq_zero] using frequently_zero_iff_eventually_zero (hf.sub hg) /-- For a function `f` on `𝕜`, and `z₀ ∈ 𝕜`, there exists at most one `n` such that on a punctured neighbourhood of `z₀` we have `f z = (z - z₀) ^ n • g z`, with `g` analytic and nonvanishing at `z₀`. We formulate this with `n : â„€`, and deduce the case `n : ℕ` later, for applications to meromorphic functions. -/ lemma unique_eventuallyEq_zpow_smul_nonzero {m n : â„€} (hm : ∃ g, AnalyticAt 𝕜 g z₀ ∧ g z₀ ≠ 0 ∧ ∀ᶠ z in 𝓝[≠] z₀, f z = (z - z₀) ^ m • g z) (hn : ∃ g, AnalyticAt 𝕜 g z₀ ∧ g z₀ ≠ 0 ∧ ∀ᶠ z in 𝓝[≠] z₀, f z = (z - z₀) ^ n • g z) : m = n := by wlog h_le : n ≀ m generalizing m n · exact ((this hn hm) (not_le.mp h_le).le).symm let ⟹g, hg_an, _, hg_eq⟩ := hm let ⟹j, hj_an, hj_ne, hj_eq⟩ := hn contrapose! hj_ne have : ∃ᶠ z in 𝓝[≠] z₀, j z = (z - z₀) ^ (m - n) • g z := by apply Filter.Eventually.frequently rw [eventually_nhdsWithin_iff] at hg_eq hj_eq ⊢ filter_upwards [hg_eq, hj_eq] with z hfz hfz' hz rw [← add_sub_cancel_left n m, add_sub_assoc, zpow_add₀ <| sub_ne_zero.mpr hz, mul_smul, hfz' hz, smul_right_inj <| zpow_ne_zero _ <| sub_ne_zero.mpr hz] at hfz exact hfz hz rw [frequently_eq_iff_eventually_eq hj_an] at this · rw [EventuallyEq.eq_of_nhds this, sub_self, zero_zpow _ (sub_ne_zero.mpr hj_ne), zero_smul] conv => enter [2, z, 1]; rw [← Int.toNat_sub_of_le h_le, zpow_natCast] exact (((analyticAt_id _ _).sub analyticAt_const).pow _).smul hg_an /-- For a function `f` on `𝕜`, and `z₀ ∈ 𝕜`, there exists at most one `n` such that on a neighbourhood of `z₀` we have `f z = (z - z₀) ^ n • g z`, with `g` analytic and nonvanishing at `z₀`. -/ lemma unique_eventuallyEq_pow_smul_nonzero {m n : ℕ} (hm : ∃ g, AnalyticAt 𝕜 g z₀ ∧ g z₀ ≠ 0 ∧ ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ m • g z) (hn : ∃ g, AnalyticAt 𝕜 g z₀ ∧ g z₀ ≠ 0 ∧ ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ n • g z) : m = n := by simp_rw [← zpow_natCast] at hm hn exact Int.ofNat_inj.mp <| unique_eventuallyEq_zpow_smul_nonzero (let ⟹g, h₁, h₂, h₃⟩ := hm; ⟹g, h₁, h₂, h₃.filter_mono nhdsWithin_le_nhds⟩) (let ⟹g, h₁, h₂, h₃⟩ := hn; ⟹g, h₁, h₂, h₃.filter_mono nhdsWithin_le_nhds⟩) /-- If `f` is analytic at `z₀`, then exactly one of the following two possibilities occurs: either `f` vanishes identically near `z₀`, or locally around `z₀` it has the form `z ↩ (z - z₀) ^ n • g z` for some `n` and some `g` which is analytic and non-vanishing at `z₀`. -/ theorem exists_eventuallyEq_pow_smul_nonzero_iff (hf : AnalyticAt 𝕜 f z₀) : (∃ (n : ℕ), ∃ (g : 𝕜 → E), AnalyticAt 𝕜 g z₀ ∧ g z₀ ≠ 0 ∧ ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ n • g z) ↔ (¬∀ᶠ z in 𝓝 z₀, f z = 0) := by constructor · rintro ⟹n, g, hg_an, hg_ne, hg_eq⟩ contrapose! hg_ne apply EventuallyEq.eq_of_nhds rw [EventuallyEq, ← AnalyticAt.frequently_eq_iff_eventually_eq hg_an analyticAt_const] refine (eventually_nhdsWithin_iff.mpr ?_).frequently filter_upwards [hg_eq, hg_ne] with z hf_eq hf0 hz rwa [hf0, eq_comm, smul_eq_zero_iff_right] at hf_eq exact pow_ne_zero _ (sub_ne_zero.mpr hz) · intro hf_ne rcases hf with ⟹p, hp⟩ exact ⟹p.order, _, ⟹_, hp.has_fpower_series_iterate_dslope_fslope p.order⟩, hp.iterate_dslope_fslope_ne_zero (hf_ne.imp hp.locally_zero_iff.mpr), hp.eq_pow_order_mul_iterate_dslope⟩ /-- The order of vanishing of `f` at `z₀`, as an element of `ℕ∞`. This is defined to be `∞` if `f` is identically 0 on a neighbourhood of `z₀`, and otherwise the unique `n` such that `f z = (z - z₀) ^ n • g z` with `g` analytic and non-vanishing at `z₀`. See `AnalyticAt.order_eq_top_iff` and `AnalyticAt.order_eq_nat_iff` for these equivalences. -/ noncomputable def order (hf : AnalyticAt 𝕜 f z₀) : ENat := if h : ∀ᶠ z in 𝓝 z₀, f z = 0 then ⊀ else ↑(hf.exists_eventuallyEq_pow_smul_nonzero_iff.mpr h).choose lemma order_eq_top_iff (hf : AnalyticAt 𝕜 f z₀) : hf.order = ⊀ ↔ ∀ᶠ z in 𝓝 z₀, f z = 0 := by unfold order split_ifs with h · rwa [eq_self, true_iff] · simpa only [ne_eq, ENat.coe_ne_top, false_iff] using h lemma order_eq_nat_iff (hf : AnalyticAt 𝕜 f z₀) (n : ℕ) : hf.order = ↑n ↔ ∃ (g : 𝕜 → E), AnalyticAt 𝕜 g z₀ ∧ g z₀ ≠ 0 ∧ ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ n • g z := by unfold order split_ifs with h · simp only [ENat.top_ne_coe, false_iff] contrapose! h rw [← hf.exists_eventuallyEq_pow_smul_nonzero_iff] exact ⟹n, h⟩ · rw [← hf.exists_eventuallyEq_pow_smul_nonzero_iff] at h refine ⟹fun hn ↩ (WithTop.coe_inj.mp hn : h.choose = n) ▾ h.choose_spec, fun h' ↩ ?_⟩ rw [unique_eventuallyEq_pow_smul_nonzero h.choose_spec h'] end AnalyticAt namespace AnalyticOn variable {U : Set 𝕜} /-- The *principle of isolated zeros* for an analytic function, global version: if a function is analytic on a connected set `U` and vanishes in arbitrary neighborhoods of a point `z₀ ∈ U`, then it is identically zero in `U`. For higher-dimensional versions requiring that the function vanishes in a neighborhood of `z₀`, see `AnalyticOn.eqOn_zero_of_preconnected_of_eventuallyEq_zero`. -/ theorem eqOn_zero_of_preconnected_of_frequently_eq_zero (hf : AnalyticOn 𝕜 f U) (hU : IsPreconnected U) (h₀ : z₀ ∈ U) (hfw : ∃ᶠ z in 𝓝[≠] z₀, f z = 0) : EqOn f 0 U := hf.eqOn_zero_of_preconnected_of_eventuallyEq_zero hU h₀ ((hf z₀ h₀).frequently_zero_iff_eventually_zero.1 hfw) theorem eqOn_zero_of_preconnected_of_mem_closure (hf : AnalyticOn 𝕜 f U) (hU : IsPreconnected U) (h₀ : z₀ ∈ U) (hfz₀ : z₀ ∈ closure ({z | f z = 0} \ {z₀})) : EqOn f 0 U := hf.eqOn_zero_of_preconnected_of_frequently_eq_zero hU h₀ (mem_closure_ne_iff_frequently_within.mp hfz₀) /-- The *identity principle* for analytic functions, global version: if two functions are analytic on a connected set `U` and coincide at points which accumulate to a point `z₀ ∈ U`, then they coincide globally in `U`. For higher-dimensional versions requiring that the functions coincide in a neighborhood of `z₀`, see `AnalyticOn.eqOn_of_preconnected_of_eventuallyEq`. -/ theorem eqOn_of_preconnected_of_frequently_eq (hf : AnalyticOn 𝕜 f U) (hg : AnalyticOn 𝕜 g U) (hU : IsPreconnected U) (h₀ : z₀ ∈ U) (hfg : ∃ᶠ z in 𝓝[≠] z₀, f z = g z) : EqOn f g U := by have hfg' : ∃ᶠ z in 𝓝[≠] z₀, (f - g) z = 0 := hfg.mono fun z h => by rw [Pi.sub_apply, h, sub_self] simpa [sub_eq_zero] using fun z hz => (hf.sub hg).eqOn_zero_of_preconnected_of_frequently_eq_zero hU h₀ hfg' hz theorem eqOn_of_preconnected_of_mem_closure (hf : AnalyticOn 𝕜 f U) (hg : AnalyticOn 𝕜 g U) (hU : IsPreconnected U) (h₀ : z₀ ∈ U) (hfg : z₀ ∈ closure ({z | f z = g z} \ {z₀})) : EqOn f g U := hf.eqOn_of_preconnected_of_frequently_eq hg hU h₀ (mem_closure_ne_iff_frequently_within.mp hfg) /-- The *identity principle* for analytic functions, global version: if two functions on a normed field `𝕜` are analytic everywhere and coincide at points which accumulate to a point `z₀`, then they coincide globally. For higher-dimensional versions requiring that the functions coincide in a neighborhood of `z₀`, see `AnalyticOn.eq_of_eventuallyEq`. -/ theorem eq_of_frequently_eq [ConnectedSpace 𝕜] (hf : AnalyticOn 𝕜 f univ) (hg : AnalyticOn 𝕜 g univ) (hfg : ∃ᶠ z in 𝓝[≠] z₀, f z = g z) : f = g := funext fun x => eqOn_of_preconnected_of_frequently_eq hf hg isPreconnected_univ (mem_univ z₀) hfg (mem_univ x) end AnalyticOn
Analysis\Analytic\Linear.lean
/- Copyright (c) 2021 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Analytic.Basic /-! # Linear functions are analytic In this file we prove that a `ContinuousLinearMap` defines an analytic function with the formal power series `f x = f a + f (x - a)`. We also prove similar results for multilinear maps. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] open scoped Topology NNReal ENNReal open Set Filter Asymptotics noncomputable section namespace ContinuousLinearMap @[simp] theorem fpowerSeries_radius (f : E →L[𝕜] F) (x : E) : (f.fpowerSeries x).radius = ∞ := (f.fpowerSeries x).radius_eq_top_of_forall_image_add_eq_zero 2 fun _ => rfl protected theorem hasFPowerSeriesOnBall (f : E →L[𝕜] F) (x : E) : HasFPowerSeriesOnBall f (f.fpowerSeries x) x ∞ := { r_le := by simp r_pos := ENNReal.coe_lt_top hasSum := fun _ => (hasSum_nat_add_iff' 2).1 <| by simp [Finset.sum_range_succ, ← sub_sub, hasSum_zero, fpowerSeries] } protected theorem hasFPowerSeriesAt (f : E →L[𝕜] F) (x : E) : HasFPowerSeriesAt f (f.fpowerSeries x) x := ⟹∞, f.hasFPowerSeriesOnBall x⟩ protected theorem analyticAt (f : E →L[𝕜] F) (x : E) : AnalyticAt 𝕜 f x := (f.hasFPowerSeriesAt x).analyticAt /-- Reinterpret a bilinear map `f : E →L[𝕜] F →L[𝕜] G` as a multilinear map `(E × F) [×2]→L[𝕜] G`. This multilinear map is the second term in the formal multilinear series expansion of `uncurry f`. It is given by `f.uncurryBilinear ![(x, y), (x', y')] = f x y'`. -/ def uncurryBilinear (f : E →L[𝕜] F →L[𝕜] G) : E × F[×2]→L[𝕜] G := @ContinuousLinearMap.uncurryLeft 𝕜 1 (fun _ => E × F) G _ _ _ _ _ <| (↑(continuousMultilinearCurryFin1 𝕜 (E × F) G).symm : (E × F →L[𝕜] G) →L[𝕜] _).comp <| f.bilinearComp (fst _ _ _) (snd _ _ _) @[simp] theorem uncurryBilinear_apply (f : E →L[𝕜] F →L[𝕜] G) (m : Fin 2 → E × F) : f.uncurryBilinear m = f (m 0).1 (m 1).2 := rfl /-- Formal multilinear series expansion of a bilinear function `f : E →L[𝕜] F →L[𝕜] G`. -/ def fpowerSeriesBilinear (f : E →L[𝕜] F →L[𝕜] G) (x : E × F) : FormalMultilinearSeries 𝕜 (E × F) G | 0 => ContinuousMultilinearMap.curry0 𝕜 _ (f x.1 x.2) | 1 => (continuousMultilinearCurryFin1 𝕜 (E × F) G).symm (f.deriv₂ x) | 2 => f.uncurryBilinear | _ => 0 theorem fpowerSeriesBilinear_apply_zero (f : E →L[𝕜] F →L[𝕜] G) (x : E × F) : fpowerSeriesBilinear f x 0 = ContinuousMultilinearMap.curry0 𝕜 _ (f x.1 x.2) := rfl theorem fpowerSeriesBilinear_apply_one (f : E →L[𝕜] F →L[𝕜] G) (x : E × F) : fpowerSeriesBilinear f x 1 = (continuousMultilinearCurryFin1 𝕜 (E × F) G).symm (f.deriv₂ x) := rfl theorem fpowerSeriesBilinear_apply_two (f : E →L[𝕜] F →L[𝕜] G) (x : E × F) : fpowerSeriesBilinear f x 2 = f.uncurryBilinear := rfl theorem fpowerSeriesBilinear_apply_add_three (f : E →L[𝕜] F →L[𝕜] G) (x : E × F) (n) : fpowerSeriesBilinear f x (n + 3) = 0 := rfl attribute [eqns fpowerSeriesBilinear_apply_zero fpowerSeriesBilinear_apply_one fpowerSeriesBilinear_apply_two fpowerSeriesBilinear_apply_add_three] fpowerSeriesBilinear attribute [simp] fpowerSeriesBilinear @[simp] theorem fpowerSeriesBilinear_radius (f : E →L[𝕜] F →L[𝕜] G) (x : E × F) : (f.fpowerSeriesBilinear x).radius = ∞ := (f.fpowerSeriesBilinear x).radius_eq_top_of_forall_image_add_eq_zero 3 fun _ => rfl protected theorem hasFPowerSeriesOnBall_bilinear (f : E →L[𝕜] F →L[𝕜] G) (x : E × F) : HasFPowerSeriesOnBall (fun x : E × F => f x.1 x.2) (f.fpowerSeriesBilinear x) x ∞ := { r_le := by simp r_pos := ENNReal.coe_lt_top hasSum := fun _ => (hasSum_nat_add_iff' 3).1 <| by simp only [Finset.sum_range_succ, Finset.sum_range_one, Prod.fst_add, Prod.snd_add, f.map_add_add] simp [fpowerSeriesBilinear, hasSum_zero] } protected theorem hasFPowerSeriesAt_bilinear (f : E →L[𝕜] F →L[𝕜] G) (x : E × F) : HasFPowerSeriesAt (fun x : E × F => f x.1 x.2) (f.fpowerSeriesBilinear x) x := ⟹∞, f.hasFPowerSeriesOnBall_bilinear x⟩ protected theorem analyticAt_bilinear (f : E →L[𝕜] F →L[𝕜] G) (x : E × F) : AnalyticAt 𝕜 (fun x : E × F => f x.1 x.2) x := (f.hasFPowerSeriesAt_bilinear x).analyticAt end ContinuousLinearMap variable (𝕜) lemma analyticAt_id (z : E) : AnalyticAt 𝕜 (id : E → E) z := (ContinuousLinearMap.id 𝕜 E).analyticAt z /-- `id` is entire -/ theorem analyticOn_id {s : Set E} : AnalyticOn 𝕜 (fun x : E ↩ x) s := fun _ _ ↩ analyticAt_id _ _ /-- `fst` is analytic -/ theorem analyticAt_fst {p : E × F} : AnalyticAt 𝕜 (fun p : E × F ↩ p.fst) p := (ContinuousLinearMap.fst 𝕜 E F).analyticAt p /-- `snd` is analytic -/ theorem analyticAt_snd {p : E × F} : AnalyticAt 𝕜 (fun p : E × F ↩ p.snd) p := (ContinuousLinearMap.snd 𝕜 E F).analyticAt p /-- `fst` is entire -/ theorem analyticOn_fst {s : Set (E × F)} : AnalyticOn 𝕜 (fun p : E × F ↩ p.fst) s := fun _ _ ↩ analyticAt_fst _ /-- `snd` is entire -/ theorem analyticOn_snd {s : Set (E × F)} : AnalyticOn 𝕜 (fun p : E × F ↩ p.snd) s := fun _ _ ↩ analyticAt_snd _
Analysis\Analytic\Meromorphic.lean
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.Analytic.IsolatedZeros import Mathlib.Algebra.Order.AddGroupWithTop /-! # Meromorphic functions Main statements: * `MeromorphicAt`: definition of meromorphy at a point * `MeromorphicAt.iff_eventuallyEq_zpow_smul_analyticAt`: `f` is meromorphic at `z₀` iff we have `f z = (z - z₀) ^ n • g z` on a punctured nhd of `z₀`, for some `n : â„€` and `g` analytic at z₀. * `MeromorphicAt.order`: order of vanishing at `z₀`, as an element of `â„€ ∪ {∞}` -/ open Filter open scoped Topology variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] /-- Meromorphy of `f` at `x` (more precisely, on a punctured neighbourhood of `x`; the value at `x` itself is irrelevant). -/ def MeromorphicAt (f : 𝕜 → E) (x : 𝕜) := ∃ (n : ℕ), AnalyticAt 𝕜 (fun z ↩ (z - x) ^ n • f z) x lemma AnalyticAt.meromorphicAt {f : 𝕜 → E} {x : 𝕜} (hf : AnalyticAt 𝕜 f x) : MeromorphicAt f x := ⟹0, by simpa only [pow_zero, one_smul]⟩ namespace MeromorphicAt lemma id (x : 𝕜) : MeromorphicAt id x := (analyticAt_id 𝕜 x).meromorphicAt lemma const (e : E) (x : 𝕜) : MeromorphicAt (fun _ ↩ e) x := analyticAt_const.meromorphicAt lemma add {f g : 𝕜 → E} {x : 𝕜} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (f + g) x := by rcases hf with ⟹m, hf⟩ rcases hg with ⟹n, hg⟩ refine ⟹max m n, ?_⟩ have : (fun z ↩ (z - x) ^ max m n • (f + g) z) = fun z ↩ (z - x) ^ (max m n - m) • ((z - x) ^ m • f z) + (z - x) ^ (max m n - n) • ((z - x) ^ n • g z) := by simp_rw [← mul_smul, ← pow_add, Nat.sub_add_cancel (Nat.le_max_left _ _), Nat.sub_add_cancel (Nat.le_max_right _ _), Pi.add_apply, smul_add] rw [this] exact ((((analyticAt_id 𝕜 x).sub analyticAt_const).pow _).smul hf).add ((((analyticAt_id 𝕜 x).sub analyticAt_const).pow _).smul hg) lemma smul {f : 𝕜 → 𝕜} {g : 𝕜 → E} {x : 𝕜} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (f • g) x := by rcases hf with ⟹m, hf⟩ rcases hg with ⟹n, hg⟩ refine ⟹m + n, ?_⟩ convert hf.smul hg using 2 with z rw [smul_eq_mul, ← mul_smul, mul_assoc, mul_comm (f z), ← mul_assoc, pow_add, ← smul_eq_mul (a' := f z), smul_assoc, Pi.smul_apply'] lemma mul {f g : 𝕜 → 𝕜} {x : 𝕜} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (f * g) x := hf.smul hg lemma neg {f : 𝕜 → E} {x : 𝕜} (hf : MeromorphicAt f x) : MeromorphicAt (-f) x := by convert (MeromorphicAt.const (-1 : 𝕜) x).smul hf using 1 ext1 z simp only [Pi.neg_apply, Pi.smul_apply', neg_smul, one_smul] @[simp] lemma neg_iff {f : 𝕜 → E} {x : 𝕜} : MeromorphicAt (-f) x ↔ MeromorphicAt f x := ⟹fun h ↩ by simpa only [neg_neg] using h.neg, MeromorphicAt.neg⟩ lemma sub {f g : 𝕜 → E} {x : 𝕜} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (f - g) x := by convert hf.add hg.neg using 1 ext1 z simp_rw [Pi.sub_apply, Pi.add_apply, Pi.neg_apply, sub_eq_add_neg] /-- With our definitions, `MeromorphicAt f x` depends only on the values of `f` on a punctured neighbourhood of `x` (not on `f x`) -/ lemma congr {f g : 𝕜 → E} {x : 𝕜} (hf : MeromorphicAt f x) (hfg : f =á¶ [𝓝[≠] x] g) : MeromorphicAt g x := by rcases hf with ⟹m, hf⟩ refine ⟹m + 1, ?_⟩ have : AnalyticAt 𝕜 (fun z ↩ z - x) x := (analyticAt_id 𝕜 x).sub analyticAt_const refine (this.smul hf).congr ?_ rw [eventuallyEq_nhdsWithin_iff] at hfg filter_upwards [hfg] with z hz rcases eq_or_ne z x with rfl | hn · simp · rw [hz (Set.mem_compl_singleton_iff.mp hn), pow_succ', mul_smul] lemma inv {f : 𝕜 → 𝕜} {x : 𝕜} (hf : MeromorphicAt f x) : MeromorphicAt f⁻¹ x := by rcases hf with ⟹m, hf⟩ by_cases h_eq : (fun z ↩ (z - x) ^ m • f z) =á¶ [𝓝 x] 0 · -- silly case: f locally 0 near x refine (MeromorphicAt.const 0 x).congr ?_ rw [eventuallyEq_nhdsWithin_iff] filter_upwards [h_eq] with z hfz hz rw [Pi.inv_apply, (smul_eq_zero_iff_right <| pow_ne_zero _ (sub_ne_zero.mpr hz)).mp hfz, inv_zero] · -- interesting case: use local formula for `f` obtain ⟹n, g, hg_an, hg_ne, hg_eq⟩ := hf.exists_eventuallyEq_pow_smul_nonzero_iff.mpr h_eq have : AnalyticAt 𝕜 (fun z ↩ (z - x) ^ (m + 1)) x := ((analyticAt_id 𝕜 x).sub analyticAt_const).pow _ -- use `m + 1` rather than `m` to damp out any silly issues with the value at `z = x` refine ⟹n + 1, (this.smul <| hg_an.inv hg_ne).congr ?_⟩ filter_upwards [hg_eq, hg_an.continuousAt.eventually_ne hg_ne] with z hfg hg_ne' rcases eq_or_ne z x with rfl | hz_ne · simp only [sub_self, pow_succ, mul_zero, zero_smul] · simp_rw [smul_eq_mul] at hfg ⊢ have aux1 : f z ≠ 0 := by have : (z - x) ^ n * g z ≠ 0 := mul_ne_zero (pow_ne_zero _ (sub_ne_zero.mpr hz_ne)) hg_ne' rw [← hfg, mul_ne_zero_iff] at this exact this.2 field_simp [sub_ne_zero.mpr hz_ne] rw [pow_succ', mul_assoc, hfg] ring @[simp] lemma inv_iff {f : 𝕜 → 𝕜} {x : 𝕜} : MeromorphicAt f⁻¹ x ↔ MeromorphicAt f x := ⟹fun h ↩ by simpa only [inv_inv] using h.inv, MeromorphicAt.inv⟩ lemma div {f g : 𝕜 → 𝕜} {x : 𝕜} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (f / g) x := (div_eq_mul_inv f g).symm ▾ (hf.mul hg.inv) lemma pow {f : 𝕜 → 𝕜} {x : 𝕜} (hf : MeromorphicAt f x) (n : ℕ) : MeromorphicAt (f ^ n) x := by induction' n with m hm · simpa only [Nat.zero_eq, pow_zero] using MeromorphicAt.const 1 x · simpa only [pow_succ] using hm.mul hf lemma zpow {f : 𝕜 → 𝕜} {x : 𝕜} (hf : MeromorphicAt f x) (n : â„€) : MeromorphicAt (f ^ n) x := by induction' n with m m · simpa only [Int.ofNat_eq_coe, zpow_natCast] using hf.pow m · simpa only [zpow_negSucc, inv_iff] using hf.pow (m + 1) /-- The order of vanishing of a meromorphic function, as an element of `â„€ ∪ ∞` (to include the case of functions identically 0 near `x`). -/ noncomputable def order {f : 𝕜 → E} {x : 𝕜} (hf : MeromorphicAt f x) : WithTop â„€ := (hf.choose_spec.order.map (↑· : ℕ → â„€)) - hf.choose open WithTop.LinearOrderedAddCommGroup lemma order_eq_top_iff {f : 𝕜 → E} {x : 𝕜} (hf : MeromorphicAt f x) : hf.order = ⊀ ↔ ∀ᶠ z in 𝓝[≠] x, f z = 0 := by unfold order by_cases h : hf.choose_spec.order = ⊀ · rw [h, WithTop.map_top, ← WithTop.coe_natCast, top_sub, eq_self, true_iff, eventually_nhdsWithin_iff] rw [AnalyticAt.order_eq_top_iff] at h filter_upwards [h] with z hf hz rwa [smul_eq_zero_iff_right <| pow_ne_zero _ (sub_ne_zero.mpr hz)] at hf · obtain ⟹m, hm⟩ := WithTop.ne_top_iff_exists.mp h rw [← hm, WithTop.map_coe, sub_eq_top_iff, eq_false_intro WithTop.coe_ne_top, false_or] simp only [WithTop.natCast_ne_top, false_iff] contrapose! h rw [AnalyticAt.order_eq_top_iff] rw [← hf.choose_spec.frequently_eq_iff_eventually_eq analyticAt_const] apply Eventually.frequently filter_upwards [h] with z hfz rw [hfz, smul_zero] lemma order_eq_int_iff {f : 𝕜 → E} {x : 𝕜} (hf : MeromorphicAt f x) (n : â„€) : hf.order = n ↔ ∃ g : 𝕜 → E, AnalyticAt 𝕜 g x ∧ g x ≠ 0 ∧ ∀ᶠ z in 𝓝[≠] x, f z = (z - x) ^ n • g z := by unfold order by_cases h : hf.choose_spec.order = ⊀ · rw [h, WithTop.map_top, ← WithTop.coe_natCast, top_sub, eq_false_intro WithTop.top_ne_coe, false_iff] rw [AnalyticAt.order_eq_top_iff] at h refine fun ⟹g, hg_an, hg_ne, hg_eq⟩ ↩ hg_ne ?_ apply EventuallyEq.eq_of_nhds rw [EventuallyEq, ← AnalyticAt.frequently_eq_iff_eventually_eq hg_an analyticAt_const] apply Eventually.frequently rw [eventually_nhdsWithin_iff] at hg_eq ⊢ filter_upwards [h, hg_eq] with z hfz hfz_eq hz rwa [hfz_eq hz, ← mul_smul, smul_eq_zero_iff_right] at hfz exact mul_ne_zero (pow_ne_zero _ (sub_ne_zero.mpr hz)) (zpow_ne_zero _ (sub_ne_zero.mpr hz)) · obtain ⟹m, h⟩ := WithTop.ne_top_iff_exists.mp h rw [← h, WithTop.map_coe, ← WithTop.coe_natCast, ← coe_sub, WithTop.coe_inj] obtain ⟹g, hg_an, hg_ne, hg_eq⟩ := (AnalyticAt.order_eq_nat_iff _ _).mp h.symm replace hg_eq : ∀ᶠ (z : 𝕜) in 𝓝[≠] x, f z = (z - x) ^ (↑m - ↑hf.choose : â„€) • g z := by rw [eventually_nhdsWithin_iff] filter_upwards [hg_eq] with z hg_eq hz rwa [← smul_right_inj <| zpow_ne_zero _ (sub_ne_zero.mpr hz), ← mul_smul, ← zpow_add₀ (sub_ne_zero.mpr hz), ← add_sub_assoc, add_sub_cancel_left, zpow_natCast, zpow_natCast] exact ⟹fun h ↩ ⟹g, hg_an, hg_ne, h ▾ hg_eq⟩, AnalyticAt.unique_eventuallyEq_zpow_smul_nonzero ⟹g, hg_an, hg_ne, hg_eq⟩⟩ /-- Compatibility of notions of `order` for analytic and meromorphic functions. -/ lemma _root_.AnalyticAt.meromorphicAt_order {f : 𝕜 → E} {x : 𝕜} (hf : AnalyticAt 𝕜 f x) : hf.meromorphicAt.order = hf.order.map (↑) := by rcases eq_or_ne hf.order ⊀ with ho | ho · rw [ho, WithTop.map_top, order_eq_top_iff] exact (hf.order_eq_top_iff.mp ho).filter_mono nhdsWithin_le_nhds · obtain ⟹n, hn⟩ := WithTop.ne_top_iff_exists.mp ho simp_rw [← hn, WithTop.map_coe, order_eq_int_iff, zpow_natCast] rcases (hf.order_eq_nat_iff _).mp hn.symm with ⟹g, h1, h2, h3⟩ exact ⟹g, h1, h2, h3.filter_mono nhdsWithin_le_nhds⟩ lemma iff_eventuallyEq_zpow_smul_analyticAt {f : 𝕜 → E} {x : 𝕜} : MeromorphicAt f x ↔ ∃ (n : â„€) (g : 𝕜 → E), AnalyticAt 𝕜 g x ∧ ∀ᶠ z in 𝓝[≠] x, f z = (z - x) ^ n • g z := by refine ⟹fun ⟹n, hn⟩ ↩ ⟹-n, _, ⟹hn, eventually_nhdsWithin_iff.mpr ?_⟩⟩, ?_⟩ · filter_upwards with z hz rw [← mul_smul, ← zpow_natCast, ← zpow_add₀ (sub_ne_zero.mpr hz), add_left_neg, zpow_zero, one_smul] · refine fun ⟹n, g, hg_an, hg_eq⟩ ↩ MeromorphicAt.congr ?_ (EventuallyEq.symm hg_eq) exact (((MeromorphicAt.id x).sub (.const _ x)).zpow _).smul hg_an.meromorphicAt end MeromorphicAt /-- Meromorphy of a function on a set. -/ def MeromorphicOn (f : 𝕜 → E) (U : Set 𝕜) : Prop := ∀ x ∈ U, MeromorphicAt f x lemma AnalyticOn.meromorphicOn {f : 𝕜 → E} {U : Set 𝕜} (hf : AnalyticOn 𝕜 f U) : MeromorphicOn f U := fun x hx ↩ (hf x hx).meromorphicAt namespace MeromorphicOn variable {s t : 𝕜 → 𝕜} {f g : 𝕜 → E} {U : Set 𝕜} (hs : MeromorphicOn s U) (ht : MeromorphicOn t U) (hf : MeromorphicOn f U) (hg : MeromorphicOn g U) lemma id {U : Set 𝕜} : MeromorphicOn id U := fun x _ ↩ .id x lemma const (e : E) {U : Set 𝕜} : MeromorphicOn (fun _ ↩ e) U := fun x _ ↩ .const e x section arithmetic lemma mono_set {V : Set 𝕜} (hv : V ⊆ U) : MeromorphicOn f V := fun x hx ↩ hf x (hv hx) lemma add : MeromorphicOn (f + g) U := fun x hx ↩ (hf x hx).add (hg x hx) lemma sub : MeromorphicOn (f - g) U := fun x hx ↩ (hf x hx).sub (hg x hx) lemma neg : MeromorphicOn (-f) U := fun x hx ↩ (hf x hx).neg @[simp] lemma neg_iff : MeromorphicOn (-f) U ↔ MeromorphicOn f U := ⟹fun h ↩ by simpa only [neg_neg] using h.neg, neg⟩ lemma smul : MeromorphicOn (s • f) U := fun x hx ↩ (hs x hx).smul (hf x hx) lemma mul : MeromorphicOn (s * t) U := fun x hx ↩ (hs x hx).mul (ht x hx) lemma inv : MeromorphicOn s⁻¹ U := fun x hx ↩ (hs x hx).inv @[simp] lemma inv_iff : MeromorphicOn s⁻¹ U ↔ MeromorphicOn s U := ⟹fun h ↩ by simpa only [inv_inv] using h.inv, inv⟩ lemma div : MeromorphicOn (s / t) U := fun x hx ↩ (hs x hx).div (ht x hx) lemma pow (n : ℕ) : MeromorphicOn (s ^ n) U := fun x hx ↩ (hs x hx).pow _ lemma zpow (n : â„€) : MeromorphicOn (s ^ n) U := fun x hx ↩ (hs x hx).zpow _ end arithmetic lemma congr (h_eq : Set.EqOn f g U) (hu : IsOpen U) : MeromorphicOn g U := by refine fun x hx ↩ (hf x hx).congr (EventuallyEq.filter_mono ?_ nhdsWithin_le_nhds) exact eventually_of_mem (hu.mem_nhds hx) h_eq end MeromorphicOn
Analysis\Analytic\Polynomial.lean
/- Copyright (c) 2023 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.MvPolynomial.Basic import Mathlib.Analysis.Analytic.Constructions import Mathlib.Topology.Algebra.Module.FiniteDimension /-! # Polynomials are analytic This file combines the analysis and algebra libraries and shows that evaluation of a polynomial is an analytic function. -/ variable {𝕜 E A B : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [CommSemiring A] {z : E} {s : Set E} section Polynomial open Polynomial variable [NormedRing B] [NormedAlgebra 𝕜 B] [Algebra A B] {f : E → B} theorem AnalyticAt.aeval_polynomial (hf : AnalyticAt 𝕜 f z) (p : A[X]) : AnalyticAt 𝕜 (fun x ↩ aeval (f x) p) z := by refine p.induction_on (fun k ↩ ?_) (fun p q hp hq ↩ ?_) fun p i hp ↩ ?_ · simp_rw [aeval_C]; apply analyticAt_const · simp_rw [aeval_add]; exact hp.add hq · convert hp.mul hf simp_rw [pow_succ, aeval_mul, ← mul_assoc, aeval_X] theorem AnalyticOn.aeval_polynomial (hf : AnalyticOn 𝕜 f s) (p : A[X]) : AnalyticOn 𝕜 (fun x ↩ aeval (f x) p) s := fun x hx ↩ (hf x hx).aeval_polynomial p theorem AnalyticOn.eval_polynomial {A} [NormedCommRing A] [NormedAlgebra 𝕜 A] (p : A[X]) : AnalyticOn 𝕜 (eval · p) Set.univ := (analyticOn_id 𝕜).aeval_polynomial p end Polynomial section MvPolynomial open MvPolynomial variable [NormedCommRing B] [NormedAlgebra 𝕜 B] [Algebra A B] {σ : Type*} {f : E → σ → B} theorem AnalyticAt.aeval_mvPolynomial (hf : ∀ i, AnalyticAt 𝕜 (f · i) z) (p : MvPolynomial σ A) : AnalyticAt 𝕜 (fun x ↩ aeval (f x) p) z := by apply p.induction_on (fun k ↩ ?_) (fun p q hp hq ↩ ?_) fun p i hp ↩ ?_ -- `refine` doesn't work · simp_rw [aeval_C]; apply analyticAt_const · simp_rw [map_add]; exact hp.add hq · simp_rw [map_mul, aeval_X]; exact hp.mul (hf i) theorem AnalyticOn.aeval_mvPolynomial (hf : ∀ i, AnalyticOn 𝕜 (f · i) s) (p : MvPolynomial σ A) : AnalyticOn 𝕜 (fun x ↩ aeval (f x) p) s := fun x hx ↩ .aeval_mvPolynomial (hf · x hx) p theorem AnalyticOn.eval_continuousLinearMap (f : E →L[𝕜] σ → B) (p : MvPolynomial σ B) : AnalyticOn 𝕜 (fun x ↩ eval (f x) p) Set.univ := fun x _ ↩ .aeval_mvPolynomial (fun i ↩ ((ContinuousLinearMap.proj i).comp f).analyticAt x) p theorem AnalyticOn.eval_continuousLinearMap' (f : σ → E →L[𝕜] B) (p : MvPolynomial σ B) : AnalyticOn 𝕜 (fun x ↩ eval (f · x) p) Set.univ := fun x _ ↩ .aeval_mvPolynomial (fun i ↩ (f i).analyticAt x) p variable [CompleteSpace 𝕜] [T2Space E] [FiniteDimensional 𝕜 E] theorem AnalyticOn.eval_linearMap (f : E →ₗ[𝕜] σ → B) (p : MvPolynomial σ B) : AnalyticOn 𝕜 (fun x ↩ eval (f x) p) Set.univ := AnalyticOn.eval_continuousLinearMap { f with cont := f.continuous_of_finiteDimensional } p theorem AnalyticOn.eval_linearMap' (f : σ → E →ₗ[𝕜] B) (p : MvPolynomial σ B) : AnalyticOn 𝕜 (fun x ↩ eval (f · x) p) Set.univ := AnalyticOn.eval_linearMap (.pi f) p theorem AnalyticOn.eval_mvPolynomial [Fintype σ] (p : MvPolynomial σ 𝕜) : AnalyticOn 𝕜 (eval · p) Set.univ := AnalyticOn.eval_linearMap (.id (R := 𝕜) (M := σ → 𝕜)) p end MvPolynomial
Analysis\Analytic\RadiusLiminf.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Analytic.Basic import Mathlib.Analysis.SpecialFunctions.Pow.NNReal /-! # Representation of `FormalMultilinearSeries.radius` as a `liminf` In this file we prove that the radius of convergence of a `FormalMultilinearSeries` is equal to $\liminf_{n\to\infty} \frac{1}{\sqrt[n]{‖p n‖}}$. This lemma can't go to `Analysis.Analytic.Basic` because this would create a circular dependency once we redefine `exp` using `FormalMultilinearSeries`. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] open scoped Topology NNReal ENNReal open Filter Asymptotics namespace FormalMultilinearSeries variable (p : FormalMultilinearSeries 𝕜 E F) /-- The radius of a formal multilinear series is equal to $\liminf_{n\to\infty} \frac{1}{\sqrt[n]{‖p n‖}}$. The actual statement uses `ℝ≥0` and some coercions. -/ theorem radius_eq_liminf : p.radius = liminf (fun n => (1 / (‖p n‖₊ ^ (1 / (n : ℝ)) : ℝ≥0) : ℝ≥0∞)) atTop := by -- Porting note: added type ascription to make elaborated statement match Lean 3 version have : ∀ (r : ℝ≥0) {n : ℕ}, 0 < n → ((r : ℝ≥0∞) ≀ 1 / ↑(‖p n‖₊ ^ (1 / (n : ℝ))) ↔ ‖p n‖₊ * r ^ n ≀ 1) := by intro r n hn have : 0 < (n : ℝ) := Nat.cast_pos.2 hn conv_lhs => rw [one_div, ENNReal.le_inv_iff_mul_le, ← ENNReal.coe_mul, ENNReal.coe_le_one_iff, one_div, ← NNReal.rpow_one r, ← mul_inv_cancel this.ne', NNReal.rpow_mul, ← NNReal.mul_rpow, ← NNReal.one_rpow n⁻¹, NNReal.rpow_le_rpow_iff (inv_pos.2 this), mul_comm, NNReal.rpow_natCast] apply le_antisymm <;> refine ENNReal.le_of_forall_nnreal_lt fun r hr => ?_ · have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * r ^ n) 1).out 1 7).1 (p.isLittleO_of_lt_radius hr) obtain ⟹a, ha, H⟩ := this apply le_liminf_of_le · infer_param · rw [← eventually_map] refine H.mp ((eventually_gt_atTop 0).mono fun n hn₀ hn => (this _ hn₀).2 (NNReal.coe_le_coe.1 ?_)) push_cast exact (le_abs_self _).trans (hn.trans (pow_le_one _ ha.1.le ha.2.le)) · refine p.le_radius_of_isBigO (IsBigO.of_bound 1 ?_) refine (eventually_lt_of_lt_liminf hr).mp ((eventually_gt_atTop 0).mono fun n hn₀ hn => ?_) simpa using NNReal.coe_le_coe.2 ((this _ hn₀).1 hn.le) end FormalMultilinearSeries
Analysis\Analytic\Uniqueness.lean
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Analytic.Linear import Mathlib.Analysis.Analytic.Composition import Mathlib.Analysis.Normed.Module.Completion /-! # Uniqueness principle for analytic functions We show that two analytic functions which coincide around a point coincide on whole connected sets, in `AnalyticOn.eqOn_of_preconnected_of_eventuallyEq`. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] open Set open scoped Topology ENNReal namespace AnalyticOn /-- If an analytic function vanishes around a point, then it is uniformly zero along a connected set. Superseded by `eqOn_zero_of_preconnected_of_locally_zero` which does not assume completeness of the target space. -/ theorem eqOn_zero_of_preconnected_of_eventuallyEq_zero_aux [CompleteSpace F] {f : E → F} {U : Set E} (hf : AnalyticOn 𝕜 f U) (hU : IsPreconnected U) {z₀ : E} (h₀ : z₀ ∈ U) (hfz₀ : f =á¶ [𝓝 z₀] 0) : EqOn f 0 U := by /- Let `u` be the set of points around which `f` vanishes. It is clearly open. We have to show that its limit points in `U` still belong to it, from which the inclusion `U ⊆ u` will follow by connectedness. -/ let u := {x | f =á¶ [𝓝 x] 0} suffices main : closure u ∩ U ⊆ u by have Uu : U ⊆ u := hU.subset_of_closure_inter_subset isOpen_setOf_eventually_nhds ⟹z₀, h₀, hfz₀⟩ main intro z hz simpa using mem_of_mem_nhds (Uu hz) /- Take a limit point `x`, then a ball `B (x, r)` on which it has a power series expansion, and then `y ∈ B (x, r/2) ∩ u`. Then `f` has a power series expansion on `B (y, r/2)` as it is contained in `B (x, r)`. All the coefficients in this series expansion vanish, as `f` is zero on a neighborhood of `y`. Therefore, `f` is zero on `B (y, r/2)`. As this ball contains `x`, it follows that `f` vanishes on a neighborhood of `x`, proving the claim. -/ rintro x ⟹xu, xU⟩ rcases hf x xU with ⟹p, r, hp⟩ obtain ⟹y, yu, hxy⟩ : ∃ y ∈ u, edist x y < r / 2 := EMetric.mem_closure_iff.1 xu (r / 2) (ENNReal.half_pos hp.r_pos.ne') let q := p.changeOrigin (y - x) have has_series : HasFPowerSeriesOnBall f q y (r / 2) := by have A : (‖y - x‖₊ : ℝ≥0∞) < r / 2 := by rwa [edist_comm, edist_eq_coe_nnnorm_sub] at hxy have := hp.changeOrigin (A.trans_le ENNReal.half_le_self) simp only [add_sub_cancel] at this apply this.mono (ENNReal.half_pos hp.r_pos.ne') apply ENNReal.le_sub_of_add_le_left ENNReal.coe_ne_top apply (add_le_add A.le (le_refl (r / 2))).trans (le_of_eq _) exact ENNReal.add_halves _ have M : EMetric.ball y (r / 2) ∈ 𝓝 x := EMetric.isOpen_ball.mem_nhds hxy filter_upwards [M] with z hz have A : HasSum (fun n : ℕ => q n fun _ : Fin n => z - y) (f z) := has_series.hasSum_sub hz have B : HasSum (fun n : ℕ => q n fun _ : Fin n => z - y) 0 := by have : HasFPowerSeriesAt 0 q y := has_series.hasFPowerSeriesAt.congr yu convert hasSum_zero (α := F) using 2 ext n exact this.apply_eq_zero n _ exact HasSum.unique A B /-- The *identity principle* for analytic functions: If an analytic function vanishes in a whole neighborhood of a point `z₀`, then it is uniformly zero along a connected set. For a one-dimensional version assuming only that the function vanishes at some points arbitrarily close to `z₀`, see `eqOn_zero_of_preconnected_of_frequently_eq_zero`. -/ theorem eqOn_zero_of_preconnected_of_eventuallyEq_zero {f : E → F} {U : Set E} (hf : AnalyticOn 𝕜 f U) (hU : IsPreconnected U) {z₀ : E} (h₀ : z₀ ∈ U) (hfz₀ : f =á¶ [𝓝 z₀] 0) : EqOn f 0 U := by let F' := UniformSpace.Completion F set e : F →L[𝕜] F' := UniformSpace.Completion.toComplL have : AnalyticOn 𝕜 (e ∘ f) U := fun x hx => (e.analyticAt _).comp (hf x hx) have A : EqOn (e ∘ f) 0 U := by apply eqOn_zero_of_preconnected_of_eventuallyEq_zero_aux this hU h₀ filter_upwards [hfz₀] with x hx simp only [hx, Function.comp_apply, Pi.zero_apply, map_zero] intro z hz have : e (f z) = e 0 := by simpa only using A hz exact UniformSpace.Completion.coe_injective F this /-- The *identity principle* for analytic functions: If two analytic functions coincide in a whole neighborhood of a point `z₀`, then they coincide globally along a connected set. For a one-dimensional version assuming only that the functions coincide at some points arbitrarily close to `z₀`, see `eqOn_of_preconnected_of_frequently_eq`. -/ theorem eqOn_of_preconnected_of_eventuallyEq {f g : E → F} {U : Set E} (hf : AnalyticOn 𝕜 f U) (hg : AnalyticOn 𝕜 g U) (hU : IsPreconnected U) {z₀ : E} (h₀ : z₀ ∈ U) (hfg : f =á¶ [𝓝 z₀] g) : EqOn f g U := by have hfg' : f - g =á¶ [𝓝 z₀] 0 := hfg.mono fun z h => by simp [h] simpa [sub_eq_zero] using fun z hz => (hf.sub hg).eqOn_zero_of_preconnected_of_eventuallyEq_zero hU h₀ hfg' hz /-- The *identity principle* for analytic functions: If two analytic functions on a normed space coincide in a neighborhood of a point `z₀`, then they coincide everywhere. For a one-dimensional version assuming only that the functions coincide at some points arbitrarily close to `z₀`, see `eq_of_frequently_eq`. -/ theorem eq_of_eventuallyEq {f g : E → F} [PreconnectedSpace E] (hf : AnalyticOn 𝕜 f univ) (hg : AnalyticOn 𝕜 g univ) {z₀ : E} (hfg : f =á¶ [𝓝 z₀] g) : f = g := funext fun x => eqOn_of_preconnected_of_eventuallyEq hf hg isPreconnected_univ (mem_univ z₀) hfg (mem_univ x) end AnalyticOn
Analysis\Analytic\Within.lean
/- Copyright (c) 2024 Geoffrey Irving. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Geoffrey Irving -/ import Mathlib.Analysis.Analytic.Constructions import Mathlib.Analysis.Calculus.FDeriv.Analytic /-! # Properties of analyticity restricted to a set From `Mathlib.Analysis.Analytic.Basic`, we have the definitons 1. `AnalyticWithinAt 𝕜 f s x` means a power series at `x` converges to `f` on `𝓝[s] x`, and `f` is continuous within `s` at `x`. 2. `AnalyticWithinOn 𝕜 f s t` means `∀ x ∈ t, AnalyticWithinAt 𝕜 f s x`. This means there exists an extension of `f` which is analytic and agrees with `f` on `s ∪ {x}`, but `f` is allowed to be arbitrary elsewhere. Requiring `ContinuousWithinAt` is essential if `x ∉ s`: it is required for composition and smoothness to follow without extra hypotheses (we could alternately require convergence at `x` even if `x ∉ s`). Here we prove basic properties of these definitions. Where convenient we assume completeness of the ambient space, which allows us to related `AnalyticWithinAt` to analyticity of a local extension. -/ noncomputable section open Topology Filter ENNReal open Set Filter variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E F G H : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] [NormedAddCommGroup H] [NormedSpace 𝕜 H] /-! ### Basic properties -/ @[simp] lemma hasFPowerSeriesWithinOnBall_univ {f : E → F} {p : FormalMultilinearSeries 𝕜 E F} {x : E} {r : ℝ≥0∞} : HasFPowerSeriesWithinOnBall f p univ x r ↔ HasFPowerSeriesOnBall f p x r := by constructor · intro h exact ⟹h.r_le, h.r_pos, fun {y} m ↩ h.hasSum (mem_univ _) m⟩ · intro h refine ⟹h.r_le, h.r_pos, fun {y} _ m => h.hasSum m, ?_⟩ exact (h.continuousOn.continuousAt (EMetric.ball_mem_nhds x h.r_pos)).continuousWithinAt @[simp] lemma hasFPowerSeriesWithinAt_univ {f : E → F} {p : FormalMultilinearSeries 𝕜 E F} {x : E} : HasFPowerSeriesWithinAt f p univ x ↔ HasFPowerSeriesAt f p x := by simp only [HasFPowerSeriesWithinAt, hasFPowerSeriesWithinOnBall_univ, HasFPowerSeriesAt] @[simp] lemma analyticWithinAt_univ {f : E → F} {x : E} : AnalyticWithinAt 𝕜 f univ x ↔ AnalyticAt 𝕜 f x := by simp only [AnalyticWithinAt, hasFPowerSeriesWithinAt_univ, AnalyticAt] lemma analyticWithinOn_univ {f : E → F} : AnalyticWithinOn 𝕜 f univ ↔ AnalyticOn 𝕜 f univ := by simp only [AnalyticWithinOn, analyticWithinAt_univ, AnalyticOn] lemma HasFPowerSeriesWithinAt.continuousWithinAt {f : E → F} {p : FormalMultilinearSeries 𝕜 E F} {s : Set E} {x : E} (h : HasFPowerSeriesWithinAt f p s x) : ContinuousWithinAt f s x := by rcases h with ⟹r, h⟩ exact h.continuousWithinAt lemma AnalyticWithinAt.continuousWithinAt {f : E → F} {s : Set E} {x : E} (h : AnalyticWithinAt 𝕜 f s x) : ContinuousWithinAt f s x := by rcases h with ⟹p, h⟩ exact h.continuousWithinAt /-- `AnalyticWithinAt` is trivial if `{x} ∈ 𝓝[s] x` -/ lemma analyticWithinAt_of_singleton_mem {f : E → F} {s : Set E} {x : E} (h : {x} ∈ 𝓝[s] x) : AnalyticWithinAt 𝕜 f s x := by have fc : ContinuousWithinAt f s x := Filter.Tendsto.mono_left (tendsto_pure_nhds _ _) (Filter.le_pure_iff.mpr h) rcases mem_nhdsWithin.mp h with ⟹t, ot, xt, st⟩ rcases Metric.mem_nhds_iff.mp (ot.mem_nhds xt) with ⟹r, r0, rt⟩ exact ⟹constFormalMultilinearSeries 𝕜 E (f x), .ofReal r, { r_le := by simp only [FormalMultilinearSeries.constFormalMultilinearSeries_radius, le_top] r_pos := by positivity hasSum := by intro y ys yr simp only [subset_singleton_iff, mem_inter_iff, and_imp] at st specialize st (x + y) (rt (by simpa using yr)) ys simp only [st] apply (hasFPowerSeriesOnBall_const (e := 0)).hasSum simp only [Metric.emetric_ball_top, mem_univ] continuousWithinAt := fc }⟩ /-- Analyticity implies analyticity within any `s` -/ lemma AnalyticAt.analyticWithinAt {f : E → F} {s : Set E} {x : E} (h : AnalyticAt 𝕜 f x) : AnalyticWithinAt 𝕜 f s x := by rcases h with ⟹p, r, hp⟩ exact ⟹p, r, { r_le := hp.r_le r_pos := hp.r_pos hasSum := fun {y} _ yr ↩ hp.hasSum yr continuousWithinAt := (hp.continuousOn.continuousAt (EMetric.ball_mem_nhds x hp.r_pos)).continuousWithinAt }⟩ /-- Analyticity on `s` implies analyticity within `s` -/ lemma AnalyticOn.analyticWithinOn {f : E → F} {s : Set E} (h : AnalyticOn 𝕜 f s) : AnalyticWithinOn 𝕜 f s := fun x m ↩ (h x m).analyticWithinAt lemma AnalyticWithinOn.continuousOn {f : E → F} {s : Set E} (h : AnalyticWithinOn 𝕜 f s) : ContinuousOn f s := fun x m ↩ (h x m).continuousWithinAt /-- If `f` is `AnalyticWithinOn` near each point in a set, it is `AnalyticWithinOn` the set -/ lemma analyticWithinOn_of_locally_analyticWithinOn {f : E → F} {s : Set E} (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ AnalyticWithinOn 𝕜 f (s ∩ u)) : AnalyticWithinOn 𝕜 f s := by intro x m rcases h x m with ⟹u, ou, xu, fu⟩ rcases Metric.mem_nhds_iff.mp (ou.mem_nhds xu) with ⟹r, r0, ru⟩ rcases fu x ⟹m, xu⟩ with ⟹p, t, fp⟩ exact ⟹p, min (.ofReal r) t, { r_pos := lt_min (by positivity) fp.r_pos r_le := min_le_of_right_le fp.r_le hasSum := by intro y ys yr simp only [EMetric.mem_ball, lt_min_iff, edist_lt_ofReal, dist_zero_right] at yr apply fp.hasSum ⟹ys, ru ?_⟩ · simp only [EMetric.mem_ball, yr] · simp only [Metric.mem_ball, dist_self_add_left, yr] continuousWithinAt := by refine (fu.continuousOn x ⟹m, xu⟩).mono_left (le_of_eq ?_) exact nhdsWithin_eq_nhdsWithin xu ou (by simp only [inter_assoc, inter_self]) }⟩ /-- On open sets, `AnalyticOn` and `AnalyticWithinOn` coincide -/ @[simp] lemma IsOpen.analyticWithinOn_iff_analyticOn {f : E → F} {s : Set E} (hs : IsOpen s) : AnalyticWithinOn 𝕜 f s ↔ AnalyticOn 𝕜 f s := by refine ⟹?_, AnalyticOn.analyticWithinOn⟩ intro hf x m rcases Metric.mem_nhds_iff.mp (hs.mem_nhds m) with ⟹r, r0, rs⟩ rcases hf x m with ⟹p, t, fp⟩ exact ⟹p, min (.ofReal r) t, { r_pos := lt_min (by positivity) fp.r_pos r_le := min_le_of_right_le fp.r_le hasSum := by intro y ym simp only [EMetric.mem_ball, lt_min_iff, edist_lt_ofReal, dist_zero_right] at ym refine fp.hasSum (rs ?_) ym.2 simp only [Metric.mem_ball, dist_self_add_left, ym.1] }⟩ /-! ### Equivalence to analyticity of a local extension We show that `HasFPowerSeriesWithinOnBall`, `HasFPowerSeriesWithinAt`, and `AnalyticWithinAt` are equivalent to the existence of a local extension with full analyticity. We do not yet show a result for `AnalyticWithinOn`, as this requires a bit more work to show that local extensions can be stitched together. -/ /-- `f` has power series `p` at `x` iff some local extension of `f` has that series -/ lemma hasFPowerSeriesWithinOnBall_iff_exists_hasFPowerSeriesOnBall [CompleteSpace F] {f : E → F} {p : FormalMultilinearSeries 𝕜 E F} {s : Set E} {x : E} {r : ℝ≥0∞} : HasFPowerSeriesWithinOnBall f p s x r ↔ ContinuousWithinAt f s x ∧ ∃ g, EqOn f g (s ∩ EMetric.ball x r) ∧ HasFPowerSeriesOnBall g p x r := by constructor · intro h refine ⟹h.continuousWithinAt, fun y ↩ p.sum (y - x), ?_, ?_⟩ · intro y ⟹ys,yb⟩ simp only [EMetric.mem_ball, edist_eq_coe_nnnorm_sub] at yb have e0 := p.hasSum (x := y - x) ?_ have e1 := (h.hasSum (y := y - x) ?_ ?_) · simp only [add_sub_cancel] at e1 exact e1.unique e0 · simpa only [add_sub_cancel] · simpa only [EMetric.mem_ball, edist_eq_coe_nnnorm] · simp only [EMetric.mem_ball, edist_eq_coe_nnnorm] exact lt_of_lt_of_le yb h.r_le · refine ⟹h.r_le, h.r_pos, ?_⟩ intro y lt simp only [add_sub_cancel_left] apply p.hasSum simp only [EMetric.mem_ball] at lt ⊢ exact lt_of_lt_of_le lt h.r_le · intro ⟹mem, g, hfg, hg⟩ refine ⟹hg.r_le, hg.r_pos, ?_, mem⟩ intro y ys lt rw [hfg] · exact hg.hasSum lt · refine ⟹ys, ?_⟩ simpa only [EMetric.mem_ball, edist_eq_coe_nnnorm_sub, add_sub_cancel_left, sub_zero] using lt /-- `f` has power series `p` at `x` iff some local extension of `f` has that series -/ lemma hasFPowerSeriesWithinAt_iff_exists_hasFPowerSeriesAt [CompleteSpace F] {f : E → F} {p : FormalMultilinearSeries 𝕜 E F} {s : Set E} {x : E} : HasFPowerSeriesWithinAt f p s x ↔ ContinuousWithinAt f s x ∧ ∃ g, f =á¶ [𝓝[s] x] g ∧ HasFPowerSeriesAt g p x := by constructor · intro ⟹r, h⟩ rcases hasFPowerSeriesWithinOnBall_iff_exists_hasFPowerSeriesOnBall.mp h with ⟹fc, g, e, h⟩ refine ⟹fc, g, ?_, ⟹r, h⟩⟩ refine Filter.eventuallyEq_iff_exists_mem.mpr ⟹_, ?_, e⟩ exact inter_mem_nhdsWithin _ (EMetric.ball_mem_nhds _ h.r_pos) · intro ⟹mem, g, hfg, ⟹r, hg⟩⟩ simp only [eventuallyEq_nhdsWithin_iff, Metric.eventually_nhds_iff] at hfg rcases hfg with ⟹e, e0, hfg⟩ refine ⟹min r (.ofReal e), ?_⟩ refine hasFPowerSeriesWithinOnBall_iff_exists_hasFPowerSeriesOnBall.mpr ⟹mem, g, ?_, ?_⟩ · intro y ⟹ys, xy⟩ refine hfg ?_ ys simp only [EMetric.mem_ball, lt_min_iff, edist_lt_ofReal] at xy exact xy.2 · exact hg.mono (lt_min hg.r_pos (by positivity)) (min_le_left _ _) /-- `f` is analytic within `s` at `x` iff some local extension of `f` is analytic at `x` -/ lemma analyticWithinAt_iff_exists_analyticAt [CompleteSpace F] {f : E → F} {s : Set E} {x : E} : AnalyticWithinAt 𝕜 f s x ↔ ContinuousWithinAt f s x ∧ ∃ g, f =á¶ [𝓝[s] x] g ∧ AnalyticAt 𝕜 g x := by simp only [AnalyticWithinAt, AnalyticAt, hasFPowerSeriesWithinAt_iff_exists_hasFPowerSeriesAt] tauto /-- If `f` is analytic within `s` at `x`, some local extension of `f` is analytic at `x` -/ lemma AnalyticWithinAt.exists_analyticAt [CompleteSpace F] {f : E → F} {s : Set E} {x : E} (h : AnalyticWithinAt 𝕜 f s x) : ∃ g, f x = g x ∧ f =á¶ [𝓝[s] x] g ∧ AnalyticAt 𝕜 g x := by by_cases s0 : 𝓝[s] x = ⊥ · refine ⟹fun _ ↩ f x, rfl, ?_, analyticAt_const⟩ simp only [EventuallyEq, s0, eventually_bot] · rcases analyticWithinAt_iff_exists_analyticAt.mp h with ⟹_, g, fg, hg⟩ refine ⟹g, ?_, fg, hg⟩ exact tendsto_nhds_unique' ⟹s0⟩ h.continuousWithinAt (hg.continuousAt.continuousWithinAt.congr' fg.symm) /-! ### Congruence We require completeness to use equivalence to locally extensions, but this is nonessential. -/ lemma AnalyticWithinAt.congr_of_eventuallyEq [CompleteSpace F] {f g : E → F} {s : Set E} {x : E} (hf : AnalyticWithinAt 𝕜 f s x) (hs : f =á¶ [𝓝[s] x] g) (hx : f x = g x) : AnalyticWithinAt 𝕜 g s x := by rcases hf.exists_analyticAt with ⟹f', fx, ef, hf'⟩ rw [analyticWithinAt_iff_exists_analyticAt] have eg := hs.symm.trans ef refine ⟹?_, f', eg, hf'⟩ exact hf'.continuousAt.continuousWithinAt.congr_of_eventuallyEq eg (hx.symm.trans fx) lemma AnalyticWithinAt.congr [CompleteSpace F] {f g : E → F} {s : Set E} {x : E} (hf : AnalyticWithinAt 𝕜 f s x) (hs : EqOn f g s) (hx : f x = g x) : AnalyticWithinAt 𝕜 g s x := hf.congr_of_eventuallyEq hs.eventuallyEq_nhdsWithin hx lemma AnalyticWithinOn.congr [CompleteSpace F] {f g : E → F} {s : Set E} (hf : AnalyticWithinOn 𝕜 f s) (hs : EqOn f g s) : AnalyticWithinOn 𝕜 g s := fun x m ↩ (hf x m).congr hs (hs m) /-! ### Monotonicity w.r.t. the set we're analytic within -/ lemma HasFPowerSeriesWithinOnBall.mono {f : E → F} {p : FormalMultilinearSeries 𝕜 E F} {s t : Set E} {x : E} {r : ℝ≥0∞} (h : HasFPowerSeriesWithinOnBall f p t x r) (hs : s ⊆ t) : HasFPowerSeriesWithinOnBall f p s x r where r_le := h.r_le r_pos := h.r_pos hasSum {_} ys yb := h.hasSum (hs ys) yb continuousWithinAt := h.continuousWithinAt.mono hs lemma HasFPowerSeriesWithinAt.mono {f : E → F} {p : FormalMultilinearSeries 𝕜 E F} {s t : Set E} {x : E} (h : HasFPowerSeriesWithinAt f p t x) (hs : s ⊆ t) : HasFPowerSeriesWithinAt f p s x := by rcases h with ⟹r, hr⟩ exact ⟹r, hr.mono hs⟩ lemma AnalyticWithinAt.mono {f : E → F} {s t : Set E} {x : E} (h : AnalyticWithinAt 𝕜 f t x) (hs : s ⊆ t) : AnalyticWithinAt 𝕜 f s x := by rcases h with ⟹p, hp⟩ exact ⟹p, hp.mono hs⟩ lemma AnalyticWithinOn.mono {f : E → F} {s t : Set E} (h : AnalyticWithinOn 𝕜 f t) (hs : s ⊆ t) : AnalyticWithinOn 𝕜 f s := fun _ m ↩ (h _ (hs m)).mono hs /-! ### Analyticity within respects composition Currently we require `CompleteSpace`s to use equivalence to local extensions, but this is not essential. -/ lemma AnalyticWithinAt.comp [CompleteSpace F] [CompleteSpace G] {f : F → G} {g : E → F} {s : Set F} {t : Set E} {x : E} (hf : AnalyticWithinAt 𝕜 f s (g x)) (hg : AnalyticWithinAt 𝕜 g t x) (h : MapsTo g t s) : AnalyticWithinAt 𝕜 (f ∘ g) t x := by rcases hf.exists_analyticAt with ⟹f', _, ef, hf'⟩ rcases hg.exists_analyticAt with ⟹g', gx, eg, hg'⟩ refine analyticWithinAt_iff_exists_analyticAt.mpr ⟹?_, f' ∘ g', ?_, ?_⟩ · exact hf.continuousWithinAt.comp hg.continuousWithinAt h · have gt := hg.continuousWithinAt.tendsto_nhdsWithin h filter_upwards [eg, gt.eventually ef] intro y gy fgy simp only [Function.comp_apply, fgy, ← gy] · exact hf'.comp_of_eq hg' gx.symm lemma AnalyticWithinOn.comp [CompleteSpace F] [CompleteSpace G] {f : F → G} {g : E → F} {s : Set F} {t : Set E} (hf : AnalyticWithinOn 𝕜 f s) (hg : AnalyticWithinOn 𝕜 g t) (h : MapsTo g t s) : AnalyticWithinOn 𝕜 (f ∘ g) t := fun x m ↩ (hf _ (h m)).comp (hg x m) h /-! ### Analyticity within implies smoothness -/ lemma AnalyticWithinAt.contDiffWithinAt [CompleteSpace F] {f : E → F} {s : Set E} {x : E} (h : AnalyticWithinAt 𝕜 f s x) {n : ℕ∞} : ContDiffWithinAt 𝕜 n f s x := by rcases h.exists_analyticAt with ⟹g, fx, fg, hg⟩ exact hg.contDiffAt.contDiffWithinAt.congr_of_eventuallyEq fg fx lemma AnalyticWithinOn.contDiffOn [CompleteSpace F] {f : E → F} {s : Set E} (h : AnalyticWithinOn 𝕜 f s) {n : ℕ∞} : ContDiffOn 𝕜 n f s := fun x m ↩ (h x m).contDiffWithinAt /-! ### Analyticity within respects products -/ lemma HasFPowerSeriesWithinOnBall.prod {e : E} {f : E → F} {g : E → G} {s : Set E} {r t : ℝ≥0∞} {p : FormalMultilinearSeries 𝕜 E F} {q : FormalMultilinearSeries 𝕜 E G} (hf : HasFPowerSeriesWithinOnBall f p s e r) (hg : HasFPowerSeriesWithinOnBall g q s e t) : HasFPowerSeriesWithinOnBall (fun x ↩ (f x, g x)) (p.prod q) s e (min r t) where r_le := by rw [p.radius_prod_eq_min] exact min_le_min hf.r_le hg.r_le r_pos := lt_min hf.r_pos hg.r_pos hasSum := by intro y m hy simp_rw [FormalMultilinearSeries.prod, ContinuousMultilinearMap.prod_apply] refine (hf.hasSum m ?_).prod_mk (hg.hasSum m ?_) · exact EMetric.mem_ball.mpr (lt_of_lt_of_le hy (min_le_left _ _)) · exact EMetric.mem_ball.mpr (lt_of_lt_of_le hy (min_le_right _ _)) continuousWithinAt := hf.continuousWithinAt.prod hg.continuousWithinAt lemma HasFPowerSeriesWithinAt.prod {e : E} {f : E → F} {g : E → G} {s : Set E} {p : FormalMultilinearSeries 𝕜 E F} {q : FormalMultilinearSeries 𝕜 E G} (hf : HasFPowerSeriesWithinAt f p s e) (hg : HasFPowerSeriesWithinAt g q s e) : HasFPowerSeriesWithinAt (fun x ↩ (f x, g x)) (p.prod q) s e := by rcases hf with ⟹_, hf⟩ rcases hg with ⟹_, hg⟩ exact ⟹_, hf.prod hg⟩ lemma AnalyticWithinAt.prod {e : E} {f : E → F} {g : E → G} {s : Set E} (hf : AnalyticWithinAt 𝕜 f s e) (hg : AnalyticWithinAt 𝕜 g s e) : AnalyticWithinAt 𝕜 (fun x ↩ (f x, g x)) s e := by rcases hf with ⟹_, hf⟩ rcases hg with ⟹_, hg⟩ exact ⟹_, hf.prod hg⟩ lemma AnalyticWithinOn.prod {f : E → F} {g : E → G} {s : Set E} (hf : AnalyticWithinOn 𝕜 f s) (hg : AnalyticWithinOn 𝕜 g s) : AnalyticWithinOn 𝕜 (fun x ↩ (f x, g x)) s := fun x hx ↩ (hf x hx).prod (hg x hx)
Analysis\Asymptotics\AsymptoticEquivalent.lean
/- Copyright (c) 2020 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Analysis.Asymptotics.Asymptotics import Mathlib.Analysis.Asymptotics.Theta import Mathlib.Analysis.Normed.Order.Basic /-! # Asymptotic equivalence In this file, we define the relation `IsEquivalent l u v`, which means that `u-v` is little o of `v` along the filter `l`. Unlike `Is(Little|Big)O` relations, this one requires `u` and `v` to have the same codomain `β`. While the definition only requires `β` to be a `NormedAddCommGroup`, most interesting properties require it to be a `NormedField`. ## Notations We introduce the notation `u ~[l] v := IsEquivalent l u v`, which you can use by opening the `Asymptotics` locale. ## Main results If `β` is a `NormedAddCommGroup` : - `_ ~[l] _` is an equivalence relation - Equivalent statements for `u ~[l] const _ c` : - If `c ≠ 0`, this is true iff `Tendsto u l (𝓝 c)` (see `isEquivalent_const_iff_tendsto`) - For `c = 0`, this is true iff `u =á¶ [l] 0` (see `isEquivalent_zero_iff_eventually_zero`) If `β` is a `NormedField` : - Alternative characterization of the relation (see `isEquivalent_iff_exists_eq_mul`) : `u ~[l] v ↔ ∃ (φ : α → β) (hφ : Tendsto φ l (𝓝 1)), u =á¶ [l] φ * v` - Provided some non-vanishing hypothesis, this can be seen as `u ~[l] v ↔ Tendsto (u/v) l (𝓝 1)` (see `isEquivalent_iff_tendsto_one`) - For any constant `c`, `u ~[l] v` implies `Tendsto u l (𝓝 c) ↔ Tendsto v l (𝓝 c)` (see `IsEquivalent.tendsto_nhds_iff`) - `*` and `/` are compatible with `_ ~[l] _` (see `IsEquivalent.mul` and `IsEquivalent.div`) If `β` is a `NormedLinearOrderedField` : - If `u ~[l] v`, we have `Tendsto u l atTop ↔ Tendsto v l atTop` (see `IsEquivalent.tendsto_atTop_iff`) ## Implementation Notes Note that `IsEquivalent` takes the parameters `(l : Filter α) (u v : α → β)` in that order. This is to enable `calc` support, as `calc` requires that the last two explicit arguments are `u v`. -/ namespace Asymptotics open Filter Function open Topology section NormedAddCommGroup variable {α β : Type*} [NormedAddCommGroup β] /-- Two functions `u` and `v` are said to be asymptotically equivalent along a filter `l` when `u x - v x = o(v x)` as `x` converges along `l`. -/ def IsEquivalent (l : Filter α) (u v : α → β) := (u - v) =o[l] v @[inherit_doc] scoped notation:50 u " ~[" l:50 "] " v:50 => Asymptotics.IsEquivalent l u v variable {u v w : α → β} {l : Filter α} theorem IsEquivalent.isLittleO (h : u ~[l] v) : (u - v) =o[l] v := h nonrec theorem IsEquivalent.isBigO (h : u ~[l] v) : u =O[l] v := (IsBigO.congr_of_sub h.isBigO.symm).mp (isBigO_refl _ _) theorem IsEquivalent.isBigO_symm (h : u ~[l] v) : v =O[l] u := by convert h.isLittleO.right_isBigO_add simp theorem IsEquivalent.isTheta (h : u ~[l] v) : u =Θ[l] v := ⟹h.isBigO, h.isBigO_symm⟩ theorem IsEquivalent.isTheta_symm (h : u ~[l] v) : v =Θ[l] u := ⟹h.isBigO_symm, h.isBigO⟩ @[refl] theorem IsEquivalent.refl : u ~[l] u := by rw [IsEquivalent, sub_self] exact isLittleO_zero _ _ @[symm] theorem IsEquivalent.symm (h : u ~[l] v) : v ~[l] u := (h.isLittleO.trans_isBigO h.isBigO_symm).symm @[trans] theorem IsEquivalent.trans {l : Filter α} {u v w : α → β} (huv : u ~[l] v) (hvw : v ~[l] w) : u ~[l] w := (huv.isLittleO.trans_isBigO hvw.isBigO).triangle hvw.isLittleO theorem IsEquivalent.congr_left {u v w : α → β} {l : Filter α} (huv : u ~[l] v) (huw : u =á¶ [l] w) : w ~[l] v := huv.congr' (huw.sub (EventuallyEq.refl _ _)) (EventuallyEq.refl _ _) theorem IsEquivalent.congr_right {u v w : α → β} {l : Filter α} (huv : u ~[l] v) (hvw : v =á¶ [l] w) : u ~[l] w := (huv.symm.congr_left hvw).symm theorem isEquivalent_zero_iff_eventually_zero : u ~[l] 0 ↔ u =á¶ [l] 0 := by rw [IsEquivalent, sub_zero] exact isLittleO_zero_right_iff theorem isEquivalent_zero_iff_isBigO_zero : u ~[l] 0 ↔ u =O[l] (0 : α → β) := by refine ⟹IsEquivalent.isBigO, fun h ↩ ?_⟩ rw [isEquivalent_zero_iff_eventually_zero, eventuallyEq_iff_exists_mem] exact ⟹{ x : α | u x = 0 }, isBigO_zero_right_iff.mp h, fun x hx ↩ hx⟩ theorem isEquivalent_const_iff_tendsto {c : β} (h : c ≠ 0) : u ~[l] const _ c ↔ Tendsto u l (𝓝 c) := by simp (config := { unfoldPartialApp := true }) only [IsEquivalent, const, isLittleO_const_iff h] constructor <;> intro h · have := h.sub (tendsto_const_nhds (x := -c)) simp only [Pi.sub_apply, sub_neg_eq_add, sub_add_cancel, zero_add] at this exact this · have := h.sub (tendsto_const_nhds (x := c)) rwa [sub_self] at this theorem IsEquivalent.tendsto_const {c : β} (hu : u ~[l] const _ c) : Tendsto u l (𝓝 c) := by rcases em <| c = 0 with rfl | h · exact (tendsto_congr' <| isEquivalent_zero_iff_eventually_zero.mp hu).mpr tendsto_const_nhds · exact (isEquivalent_const_iff_tendsto h).mp hu theorem IsEquivalent.tendsto_nhds {c : β} (huv : u ~[l] v) (hu : Tendsto u l (𝓝 c)) : Tendsto v l (𝓝 c) := by by_cases h : c = 0 · subst c rw [← isLittleO_one_iff ℝ] at hu ⊢ simpa using (huv.symm.isLittleO.trans hu).add hu · rw [← isEquivalent_const_iff_tendsto h] at hu ⊢ exact huv.symm.trans hu theorem IsEquivalent.tendsto_nhds_iff {c : β} (huv : u ~[l] v) : Tendsto u l (𝓝 c) ↔ Tendsto v l (𝓝 c) := ⟹huv.tendsto_nhds, huv.symm.tendsto_nhds⟩ theorem IsEquivalent.add_isLittleO (huv : u ~[l] v) (hwv : w =o[l] v) : u + w ~[l] v := by simpa only [IsEquivalent, add_sub_right_comm] using huv.add hwv theorem IsEquivalent.sub_isLittleO (huv : u ~[l] v) (hwv : w =o[l] v) : u - w ~[l] v := by simpa only [sub_eq_add_neg] using huv.add_isLittleO hwv.neg_left theorem IsLittleO.add_isEquivalent (hu : u =o[l] w) (hv : v ~[l] w) : u + v ~[l] w := add_comm v u ▾ hv.add_isLittleO hu theorem IsLittleO.isEquivalent (huv : (u - v) =o[l] v) : u ~[l] v := huv theorem IsEquivalent.neg (huv : u ~[l] v) : (fun x ↩ -u x) ~[l] fun x ↩ -v x := by rw [IsEquivalent] convert huv.isLittleO.neg_left.neg_right simp [neg_add_eq_sub] end NormedAddCommGroup open Asymptotics section NormedField variable {α β : Type*} [NormedField β] {t u v w : α → β} {l : Filter α} theorem isEquivalent_iff_exists_eq_mul : u ~[l] v ↔ ∃ (φ : α → β) (_ : Tendsto φ l (𝓝 1)), u =á¶ [l] φ * v := by rw [IsEquivalent, isLittleO_iff_exists_eq_mul] constructor <;> rintro ⟚φ, hφ, h⟩ <;> [refine ⟚φ + 1, ?_, ?_⟩; refine ⟚φ - 1, ?_, ?_⟩] · conv in 𝓝 _ => rw [← zero_add (1 : β)] exact hφ.add tendsto_const_nhds · convert h.add (EventuallyEq.refl l v) <;> simp [add_mul] · conv in 𝓝 _ => rw [← sub_self (1 : β)] exact hφ.sub tendsto_const_nhds · convert h.sub (EventuallyEq.refl l v); simp [sub_mul] theorem IsEquivalent.exists_eq_mul (huv : u ~[l] v) : ∃ (φ : α → β) (_ : Tendsto φ l (𝓝 1)), u =á¶ [l] φ * v := isEquivalent_iff_exists_eq_mul.mp huv theorem isEquivalent_of_tendsto_one (hz : ∀ᶠ x in l, v x = 0 → u x = 0) (huv : Tendsto (u / v) l (𝓝 1)) : u ~[l] v := by rw [isEquivalent_iff_exists_eq_mul] exact ⟹u / v, huv, hz.mono fun x hz' ↩ (div_mul_cancel_of_imp hz').symm⟩ theorem isEquivalent_of_tendsto_one' (hz : ∀ x, v x = 0 → u x = 0) (huv : Tendsto (u / v) l (𝓝 1)) : u ~[l] v := isEquivalent_of_tendsto_one (eventually_of_forall hz) huv theorem isEquivalent_iff_tendsto_one (hz : ∀ᶠ x in l, v x ≠ 0) : u ~[l] v ↔ Tendsto (u / v) l (𝓝 1) := by constructor · intro hequiv have := hequiv.isLittleO.tendsto_div_nhds_zero simp only [Pi.sub_apply, sub_div] at this have key : Tendsto (fun x ↩ v x / v x) l (𝓝 1) := (tendsto_congr' <| hz.mono fun x hnz ↩ @div_self _ _ (v x) hnz).mpr tendsto_const_nhds convert this.add key · simp · norm_num · exact isEquivalent_of_tendsto_one (hz.mono fun x hnvz hz ↩ (hnvz hz).elim) end NormedField section SMul theorem IsEquivalent.smul {α E 𝕜 : Type*} [NormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] {a b : α → 𝕜} {u v : α → E} {l : Filter α} (hab : a ~[l] b) (huv : u ~[l] v) : (fun x ↩ a x • u x) ~[l] fun x ↩ b x • v x := by rcases hab.exists_eq_mul with ⟚φ, hφ, habφ⟩ have : ((fun x ↩ a x • u x) - (fun x ↩ b x • v x)) =á¶ [l] fun x ↩ b x • (φ x • u x - v x) := by -- Porting note: `convert` has become too strong, so we need to specify `using 1`. convert (habφ.comp₂ (· • ·) <| EventuallyEq.refl _ u).sub (EventuallyEq.refl _ fun x ↩ b x • v x) using 1 ext rw [Pi.mul_apply, mul_comm, mul_smul, ← smul_sub] refine (isLittleO_congr this.symm <| EventuallyEq.rfl).mp ((isBigO_refl b l).smul_isLittleO ?_) rcases huv.isBigO.exists_pos with ⟹C, hC, hCuv⟩ rw [IsEquivalent] at * rw [isLittleO_iff] at * rw [IsBigOWith] at hCuv simp only [Metric.tendsto_nhds, dist_eq_norm] at hφ intro c hc specialize hφ (c / 2 / C) (div_pos (div_pos hc zero_lt_two) hC) specialize huv (div_pos hc zero_lt_two) refine hφ.mp (huv.mp <| hCuv.mono fun x hCuvx huvx hφx ↩ ?_) have key := calc ‖φ x - 1‖ * ‖u x‖ ≀ c / 2 / C * ‖u x‖ := by gcongr _ ≀ c / 2 / C * (C * ‖v x‖) := by gcongr _ = c / 2 * ‖v x‖ := by field_simp [hC.ne.symm] ring calc ‖((fun x : α ↩ φ x • u x) - v) x‖ = ‖(φ x - 1) • u x + (u x - v x)‖ := by simp [sub_smul, sub_add] _ ≀ ‖(φ x - 1) • u x‖ + ‖u x - v x‖ := norm_add_le _ _ _ = ‖φ x - 1‖ * ‖u x‖ + ‖u x - v x‖ := by rw [norm_smul] _ ≀ c / 2 * ‖v x‖ + ‖u x - v x‖ := by gcongr _ ≀ c / 2 * ‖v x‖ + c / 2 * ‖v x‖ := by gcongr; exact huvx _ = c * ‖v x‖ := by ring end SMul section mul_inv variable {α β : Type*} [NormedField β] {t u v w : α → β} {l : Filter α} theorem IsEquivalent.mul (htu : t ~[l] u) (hvw : v ~[l] w) : t * v ~[l] u * w := htu.smul hvw theorem IsEquivalent.inv (huv : u ~[l] v) : (fun x ↩ (u x)⁻¹) ~[l] fun x ↩ (v x)⁻¹ := by rw [isEquivalent_iff_exists_eq_mul] at * rcases huv with ⟚φ, hφ, h⟩ rw [← inv_one] refine ⟹fun x ↩ (φ x)⁻¹, Tendsto.inv₀ hφ (by norm_num), ?_⟩ convert h.inv simp [mul_comm] theorem IsEquivalent.div (htu : t ~[l] u) (hvw : v ~[l] w) : (fun x ↩ t x / v x) ~[l] fun x ↩ u x / w x := by simpa only [div_eq_mul_inv] using htu.mul hvw.inv end mul_inv section NormedLinearOrderedField variable {α β : Type*} [NormedLinearOrderedField β] {u v : α → β} {l : Filter α} theorem IsEquivalent.tendsto_atTop [OrderTopology β] (huv : u ~[l] v) (hu : Tendsto u l atTop) : Tendsto v l atTop := let ⟚φ, hφ, h⟩ := huv.symm.exists_eq_mul Tendsto.congr' h.symm (mul_comm u φ ▾ hu.atTop_mul zero_lt_one hφ) theorem IsEquivalent.tendsto_atTop_iff [OrderTopology β] (huv : u ~[l] v) : Tendsto u l atTop ↔ Tendsto v l atTop := ⟹huv.tendsto_atTop, huv.symm.tendsto_atTop⟩ theorem IsEquivalent.tendsto_atBot [OrderTopology β] (huv : u ~[l] v) (hu : Tendsto u l atBot) : Tendsto v l atBot := by convert tendsto_neg_atTop_atBot.comp (huv.neg.tendsto_atTop <| tendsto_neg_atBot_atTop.comp hu) ext simp theorem IsEquivalent.tendsto_atBot_iff [OrderTopology β] (huv : u ~[l] v) : Tendsto u l atBot ↔ Tendsto v l atBot := ⟹huv.tendsto_atBot, huv.symm.tendsto_atBot⟩ end NormedLinearOrderedField end Asymptotics open Filter Asymptotics open Asymptotics variable {α β β₂ : Type*} [NormedAddCommGroup β] [Norm β₂] {l : Filter α} theorem Filter.EventuallyEq.isEquivalent {u v : α → β} (h : u =á¶ [l] v) : u ~[l] v := IsEquivalent.congr_right (isLittleO_refl_left _ _) h @[trans] theorem Filter.EventuallyEq.trans_isEquivalent {f g₁ g₂ : α → β} (h : f =á¶ [l] g₁) (h₂ : g₁ ~[l] g₂) : f ~[l] g₂ := h.isEquivalent.trans h₂ namespace Asymptotics instance transIsEquivalentIsEquivalent : @Trans (α → β) (α → β) (α → β) (IsEquivalent l) (IsEquivalent l) (IsEquivalent l) where trans := IsEquivalent.trans instance transEventuallyEqIsEquivalent : @Trans (α → β) (α → β) (α → β) (EventuallyEq l) (IsEquivalent l) (IsEquivalent l) where trans := EventuallyEq.trans_isEquivalent @[trans] theorem IsEquivalent.trans_eventuallyEq {f g₁ g₂ : α → β} (h : f ~[l] g₁) (h₂ : g₁ =á¶ [l] g₂) : f ~[l] g₂ := h.trans h₂.isEquivalent instance transIsEquivalentEventuallyEq : @Trans (α → β) (α → β) (α → β) (IsEquivalent l) (EventuallyEq l) (IsEquivalent l) where trans := IsEquivalent.trans_eventuallyEq @[trans] theorem IsEquivalent.trans_isBigO {f g₁ : α → β} {g₂ : α → β₂} (h : f ~[l] g₁) (h₂ : g₁ =O[l] g₂) : f =O[l] g₂ := IsBigO.trans h.isBigO h₂ instance transIsEquivalentIsBigO : @Trans (α → β) (α → β) (α → β₂) (IsEquivalent l) (IsBigO l) (IsBigO l) where trans := IsEquivalent.trans_isBigO @[trans] theorem IsBigO.trans_isEquivalent {f : α → β₂} {g₁ g₂ : α → β} (h : f =O[l] g₁) (h₂ : g₁ ~[l] g₂) : f =O[l] g₂ := IsBigO.trans h h₂.isBigO instance transIsBigOIsEquivalent : @Trans (α → β₂) (α → β) (α → β) (IsBigO l) (IsEquivalent l) (IsBigO l) where trans := IsBigO.trans_isEquivalent @[trans] theorem IsEquivalent.trans_isLittleO {f g₁ : α → β} {g₂ : α → β₂} (h : f ~[l] g₁) (h₂ : g₁ =o[l] g₂) : f =o[l] g₂ := IsBigO.trans_isLittleO h.isBigO h₂ instance transIsEquivalentIsLittleO : @Trans (α → β) (α → β) (α → β₂) (IsEquivalent l) (IsLittleO l) (IsLittleO l) where trans := IsEquivalent.trans_isLittleO @[trans] theorem IsLittleO.trans_isEquivalent {f : α → β₂} {g₁ g₂ : α → β} (h : f =o[l] g₁) (h₂ : g₁ ~[l] g₂) : f =o[l] g₂ := IsLittleO.trans_isBigO h h₂.isBigO instance transIsLittleOIsEquivalent : @Trans (α → β₂) (α → β) (α → β) (IsLittleO l) (IsEquivalent l) (IsLittleO l) where trans := IsLittleO.trans_isEquivalent @[trans] theorem IsEquivalent.trans_isTheta {f g₁ : α → β} {g₂ : α → β₂} (h : f ~[l] g₁) (h₂ : g₁ =Θ[l] g₂) : f =Θ[l] g₂ := IsTheta.trans h.isTheta h₂ instance transIsEquivalentIsTheta : @Trans (α → β) (α → β) (α → β₂) (IsEquivalent l) (IsTheta l) (IsTheta l) where trans := IsEquivalent.trans_isTheta @[trans] theorem IsTheta.trans_isEquivalent {f : α → β₂} {g₁ g₂ : α → β} (h : f =Θ[l] g₁) (h₂ : g₁ ~[l] g₂) : f =Θ[l] g₂ := IsTheta.trans h h₂.isTheta instance transIsThetaIsEquivalent : @Trans (α → β₂) (α → β) (α → β) (IsTheta l) (IsEquivalent l) (IsTheta l) where trans := IsTheta.trans_isEquivalent end Asymptotics
Analysis\Asymptotics\Asymptotics.lean
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Yury Kudryashov -/ import Mathlib.Analysis.Normed.Group.InfiniteSum import Mathlib.Analysis.Normed.MulAction import Mathlib.Topology.Algebra.Order.LiminfLimsup import Mathlib.Topology.PartialHomeomorph /-! # Asymptotics We introduce these relations: * `IsBigOWith c l f g` : "f is big O of g along l with constant c"; * `f =O[l] g` : "f is big O of g along l"; * `f =o[l] g` : "f is little o of g along l". Here `l` is any filter on the domain of `f` and `g`, which are assumed to be the same. The codomains of `f` and `g` do not need to be the same; all that is needed that there is a norm associated with these types, and it is the norm that is compared asymptotically. The relation `IsBigOWith c` is introduced to factor out common algebraic arguments in the proofs of similar properties of `IsBigO` and `IsLittleO`. Usually proofs outside of this file should use `IsBigO` instead. Often the ranges of `f` and `g` will be the real numbers, in which case the norm is the absolute value. In general, we have `f =O[l] g ↔ (fun x ↩ ‖f x‖) =O[l] (fun x ↩ ‖g x‖)`, and similarly for `IsLittleO`. But our setup allows us to use the notions e.g. with functions to the integers, rationals, complex numbers, or any normed vector space without mentioning the norm explicitly. If `f` and `g` are functions to a normed field like the reals or complex numbers and `g` is always nonzero, we have `f =o[l] g ↔ Tendsto (fun x ↩ f x / (g x)) l (𝓝 0)`. In fact, the right-to-left direction holds without the hypothesis on `g`, and in the other direction it suffices to assume that `f` is zero wherever `g` is. (This generalization is useful in defining the Fréchet derivative.) -/ open Filter Set open scoped Classical open Topology Filter NNReal namespace Asymptotics variable {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*} {E' : Type*} {F' : Type*} {G' : Type*} {E'' : Type*} {F'' : Type*} {G'' : Type*} {E''' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : Type*} variable [Norm E] [Norm F] [Norm G] variable [SeminormedAddCommGroup E'] [SeminormedAddCommGroup F'] [SeminormedAddCommGroup G'] [NormedAddCommGroup E''] [NormedAddCommGroup F''] [NormedAddCommGroup G''] [SeminormedRing R] [SeminormedAddGroup E'''] [SeminormedRing R'] variable [NormedDivisionRing 𝕜] [NormedDivisionRing 𝕜'] variable {c c' c₁ c₂ : ℝ} {f : α → E} {g : α → F} {k : α → G} variable {f' : α → E'} {g' : α → F'} {k' : α → G'} variable {f'' : α → E''} {g'' : α → F''} {k'' : α → G''} variable {l l' : Filter α} section Defs /-! ### Definitions -/ /-- This version of the Landau notation `IsBigOWith C l f g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by `C * ‖g‖`. In other words, `‖f‖ / ‖g‖` is eventually bounded by `C`, modulo division by zero issues that are avoided by this definition. Probably you want to use `IsBigO` instead of this relation. -/ irreducible_def IsBigOWith (c : ℝ) (l : Filter α) (f : α → E) (g : α → F) : Prop := ∀ᶠ x in l, ‖f x‖ ≀ c * ‖g x‖ /-- Definition of `IsBigOWith`. We record it in a lemma as `IsBigOWith` is irreducible. -/ theorem isBigOWith_iff : IsBigOWith c l f g ↔ ∀ᶠ x in l, ‖f x‖ ≀ c * ‖g x‖ := by rw [IsBigOWith_def] alias ⟹IsBigOWith.bound, IsBigOWith.of_bound⟩ := isBigOWith_iff /-- The Landau notation `f =O[l] g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by a constant multiple of `‖g‖`. In other words, `‖f‖ / ‖g‖` is eventually bounded, modulo division by zero issues that are avoided by this definition. -/ irreducible_def IsBigO (l : Filter α) (f : α → E) (g : α → F) : Prop := ∃ c : ℝ, IsBigOWith c l f g @[inherit_doc] notation:100 f " =O[" l "] " g:100 => IsBigO l f g /-- Definition of `IsBigO` in terms of `IsBigOWith`. We record it in a lemma as `IsBigO` is irreducible. -/ theorem isBigO_iff_isBigOWith : f =O[l] g ↔ ∃ c : ℝ, IsBigOWith c l f g := by rw [IsBigO_def] /-- Definition of `IsBigO` in terms of filters. -/ theorem isBigO_iff : f =O[l] g ↔ ∃ c : ℝ, ∀ᶠ x in l, ‖f x‖ ≀ c * ‖g x‖ := by simp only [IsBigO_def, IsBigOWith_def] /-- Definition of `IsBigO` in terms of filters, with a positive constant. -/ theorem isBigO_iff' {g : α → E'''} : f =O[l] g ↔ ∃ c > 0, ∀ᶠ x in l, ‖f x‖ ≀ c * ‖g x‖ := by refine ⟹fun h => ?mp, fun h => ?mpr⟩ case mp => rw [isBigO_iff] at h obtain ⟹c, hc⟩ := h refine ⟹max c 1, zero_lt_one.trans_le (le_max_right _ _), ?_⟩ filter_upwards [hc] with x hx apply hx.trans gcongr exact le_max_left _ _ case mpr => rw [isBigO_iff] obtain ⟹c, ⟹_, hc⟩⟩ := h exact ⟹c, hc⟩ /-- Definition of `IsBigO` in terms of filters, with the constant in the lower bound. -/ theorem isBigO_iff'' {g : α → E'''} : f =O[l] g ↔ ∃ c > 0, ∀ᶠ x in l, c * ‖f x‖ ≀ ‖g x‖ := by refine ⟹fun h => ?mp, fun h => ?mpr⟩ case mp => rw [isBigO_iff'] at h obtain ⟹c, ⟹hc_pos, hc⟩⟩ := h refine ⟹c⁻¹, ⟹by positivity, ?_⟩⟩ filter_upwards [hc] with x hx rwa [inv_mul_le_iff (by positivity)] case mpr => rw [isBigO_iff'] obtain ⟹c, ⟹hc_pos, hc⟩⟩ := h refine ⟹c⁻¹, ⟹by positivity, ?_⟩⟩ filter_upwards [hc] with x hx rwa [← inv_inv c, inv_mul_le_iff (by positivity)] at hx theorem IsBigO.of_bound (c : ℝ) (h : ∀ᶠ x in l, ‖f x‖ ≀ c * ‖g x‖) : f =O[l] g := isBigO_iff.2 ⟹c, h⟩ theorem IsBigO.of_bound' (h : ∀ᶠ x in l, ‖f x‖ ≀ ‖g x‖) : f =O[l] g := IsBigO.of_bound 1 <| by simp_rw [one_mul] exact h theorem IsBigO.bound : f =O[l] g → ∃ c : ℝ, ∀ᶠ x in l, ‖f x‖ ≀ c * ‖g x‖ := isBigO_iff.1 /-- The Landau notation `f =o[l] g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by an arbitrarily small constant multiple of `‖g‖`. In other words, `‖f‖ / ‖g‖` tends to `0` along `l`, modulo division by zero issues that are avoided by this definition. -/ irreducible_def IsLittleO (l : Filter α) (f : α → E) (g : α → F) : Prop := ∀ ⊃c : ℝ⩄, 0 < c → IsBigOWith c l f g @[inherit_doc] notation:100 f " =o[" l "] " g:100 => IsLittleO l f g /-- Definition of `IsLittleO` in terms of `IsBigOWith`. -/ theorem isLittleO_iff_forall_isBigOWith : f =o[l] g ↔ ∀ ⊃c : ℝ⩄, 0 < c → IsBigOWith c l f g := by rw [IsLittleO_def] alias ⟹IsLittleO.forall_isBigOWith, IsLittleO.of_isBigOWith⟩ := isLittleO_iff_forall_isBigOWith /-- Definition of `IsLittleO` in terms of filters. -/ theorem isLittleO_iff : f =o[l] g ↔ ∀ ⊃c : ℝ⩄, 0 < c → ∀ᶠ x in l, ‖f x‖ ≀ c * ‖g x‖ := by simp only [IsLittleO_def, IsBigOWith_def] alias ⟹IsLittleO.bound, IsLittleO.of_bound⟩ := isLittleO_iff theorem IsLittleO.def (h : f =o[l] g) (hc : 0 < c) : ∀ᶠ x in l, ‖f x‖ ≀ c * ‖g x‖ := isLittleO_iff.1 h hc theorem IsLittleO.def' (h : f =o[l] g) (hc : 0 < c) : IsBigOWith c l f g := isBigOWith_iff.2 <| isLittleO_iff.1 h hc theorem IsLittleO.eventuallyLE (h : f =o[l] g) : ∀ᶠ x in l, ‖f x‖ ≀ ‖g x‖ := by simpa using h.def zero_lt_one end Defs /-! ### Conversions -/ theorem IsBigOWith.isBigO (h : IsBigOWith c l f g) : f =O[l] g := by rw [IsBigO_def]; exact ⟹c, h⟩ theorem IsLittleO.isBigOWith (hgf : f =o[l] g) : IsBigOWith 1 l f g := hgf.def' zero_lt_one theorem IsLittleO.isBigO (hgf : f =o[l] g) : f =O[l] g := hgf.isBigOWith.isBigO theorem IsBigO.isBigOWith : f =O[l] g → ∃ c : ℝ, IsBigOWith c l f g := isBigO_iff_isBigOWith.1 theorem IsBigOWith.weaken (h : IsBigOWith c l f g') (hc : c ≀ c') : IsBigOWith c' l f g' := IsBigOWith.of_bound <| mem_of_superset h.bound fun x hx => calc ‖f x‖ ≀ c * ‖g' x‖ := hx _ ≀ _ := by gcongr theorem IsBigOWith.exists_pos (h : IsBigOWith c l f g') : ∃ c' > 0, IsBigOWith c' l f g' := ⟹max c 1, lt_of_lt_of_le zero_lt_one (le_max_right c 1), h.weaken <| le_max_left c 1⟩ theorem IsBigO.exists_pos (h : f =O[l] g') : ∃ c > 0, IsBigOWith c l f g' := let ⟹_c, hc⟩ := h.isBigOWith hc.exists_pos theorem IsBigOWith.exists_nonneg (h : IsBigOWith c l f g') : ∃ c' ≥ 0, IsBigOWith c' l f g' := let ⟹c, cpos, hc⟩ := h.exists_pos ⟹c, le_of_lt cpos, hc⟩ theorem IsBigO.exists_nonneg (h : f =O[l] g') : ∃ c ≥ 0, IsBigOWith c l f g' := let ⟹_c, hc⟩ := h.isBigOWith hc.exists_nonneg /-- `f = O(g)` if and only if `IsBigOWith c f g` for all sufficiently large `c`. -/ theorem isBigO_iff_eventually_isBigOWith : f =O[l] g' ↔ ∀ᶠ c in atTop, IsBigOWith c l f g' := isBigO_iff_isBigOWith.trans ⟹fun ⟹c, hc⟩ => mem_atTop_sets.2 ⟹c, fun _c' hc' => hc.weaken hc'⟩, fun h => h.exists⟩ /-- `f = O(g)` if and only if `∀ᶠ x in l, ‖f x‖ ≀ c * ‖g x‖` for all sufficiently large `c`. -/ theorem isBigO_iff_eventually : f =O[l] g' ↔ ∀ᶠ c in atTop, ∀ᶠ x in l, ‖f x‖ ≀ c * ‖g' x‖ := isBigO_iff_eventually_isBigOWith.trans <| by simp only [IsBigOWith_def] theorem IsBigO.exists_mem_basis {ι} {p : ι → Prop} {s : ι → Set α} (h : f =O[l] g') (hb : l.HasBasis p s) : ∃ c > 0, ∃ i : ι, p i ∧ ∀ x ∈ s i, ‖f x‖ ≀ c * ‖g' x‖ := flip Exists.imp h.exists_pos fun c h => by simpa only [isBigOWith_iff, hb.eventually_iff, exists_prop] using h theorem isBigOWith_inv (hc : 0 < c) : IsBigOWith c⁻¹ l f g ↔ ∀ᶠ x in l, c * ‖f x‖ ≀ ‖g x‖ := by simp only [IsBigOWith_def, ← div_eq_inv_mul, le_div_iff' hc] -- We prove this lemma with strange assumptions to get two lemmas below automatically theorem isLittleO_iff_nat_mul_le_aux (h₀ : (∀ x, 0 ≀ ‖f x‖) √ ∀ x, 0 ≀ ‖g x‖) : f =o[l] g ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f x‖ ≀ ‖g x‖ := by constructor · rintro H (_ | n) · refine (H.def one_pos).mono fun x h₀' => ?_ rw [Nat.cast_zero, zero_mul] refine h₀.elim (fun hf => (hf x).trans ?_) fun hg => hg x rwa [one_mul] at h₀' · have : (0 : ℝ) < n.succ := Nat.cast_pos.2 n.succ_pos exact (isBigOWith_inv this).1 (H.def' <| inv_pos.2 this) · refine fun H => isLittleO_iff.2 fun ε ε0 => ?_ rcases exists_nat_gt ε⁻¹ with ⟹n, hn⟩ have hn₀ : (0 : ℝ) < n := (inv_pos.2 ε0).trans hn refine ((isBigOWith_inv hn₀).2 (H n)).bound.mono fun x hfg => ?_ refine hfg.trans (mul_le_mul_of_nonneg_right (inv_le_of_inv_le ε0 hn.le) ?_) refine h₀.elim (fun hf => nonneg_of_mul_nonneg_right ((hf x).trans hfg) ?_) fun h => h x exact inv_pos.2 hn₀ theorem isLittleO_iff_nat_mul_le : f =o[l] g' ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f x‖ ≀ ‖g' x‖ := isLittleO_iff_nat_mul_le_aux (Or.inr fun _x => norm_nonneg _) theorem isLittleO_iff_nat_mul_le' : f' =o[l] g ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f' x‖ ≀ ‖g x‖ := isLittleO_iff_nat_mul_le_aux (Or.inl fun _x => norm_nonneg _) /-! ### Subsingleton -/ @[nontriviality] theorem isLittleO_of_subsingleton [Subsingleton E'] : f' =o[l] g' := IsLittleO.of_bound fun c hc => by simp [Subsingleton.elim (f' _) 0, mul_nonneg hc.le] @[nontriviality] theorem isBigO_of_subsingleton [Subsingleton E'] : f' =O[l] g' := isLittleO_of_subsingleton.isBigO section congr variable {f₁ f₂ : α → E} {g₁ g₂ : α → F} /-! ### Congruence -/ theorem isBigOWith_congr (hc : c₁ = c₂) (hf : f₁ =á¶ [l] f₂) (hg : g₁ =á¶ [l] g₂) : IsBigOWith c₁ l f₁ g₁ ↔ IsBigOWith c₂ l f₂ g₂ := by simp only [IsBigOWith_def] subst c₂ apply Filter.eventually_congr filter_upwards [hf, hg] with _ e₁ e₂ rw [e₁, e₂] theorem IsBigOWith.congr' (h : IsBigOWith c₁ l f₁ g₁) (hc : c₁ = c₂) (hf : f₁ =á¶ [l] f₂) (hg : g₁ =á¶ [l] g₂) : IsBigOWith c₂ l f₂ g₂ := (isBigOWith_congr hc hf hg).mp h theorem IsBigOWith.congr (h : IsBigOWith c₁ l f₁ g₁) (hc : c₁ = c₂) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : IsBigOWith c₂ l f₂ g₂ := h.congr' hc (univ_mem' hf) (univ_mem' hg) theorem IsBigOWith.congr_left (h : IsBigOWith c l f₁ g) (hf : ∀ x, f₁ x = f₂ x) : IsBigOWith c l f₂ g := h.congr rfl hf fun _ => rfl theorem IsBigOWith.congr_right (h : IsBigOWith c l f g₁) (hg : ∀ x, g₁ x = g₂ x) : IsBigOWith c l f g₂ := h.congr rfl (fun _ => rfl) hg theorem IsBigOWith.congr_const (h : IsBigOWith c₁ l f g) (hc : c₁ = c₂) : IsBigOWith c₂ l f g := h.congr hc (fun _ => rfl) fun _ => rfl theorem isBigO_congr (hf : f₁ =á¶ [l] f₂) (hg : g₁ =á¶ [l] g₂) : f₁ =O[l] g₁ ↔ f₂ =O[l] g₂ := by simp only [IsBigO_def] exact exists_congr fun c => isBigOWith_congr rfl hf hg theorem IsBigO.congr' (h : f₁ =O[l] g₁) (hf : f₁ =á¶ [l] f₂) (hg : g₁ =á¶ [l] g₂) : f₂ =O[l] g₂ := (isBigO_congr hf hg).mp h theorem IsBigO.congr (h : f₁ =O[l] g₁) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : f₂ =O[l] g₂ := h.congr' (univ_mem' hf) (univ_mem' hg) theorem IsBigO.congr_left (h : f₁ =O[l] g) (hf : ∀ x, f₁ x = f₂ x) : f₂ =O[l] g := h.congr hf fun _ => rfl theorem IsBigO.congr_right (h : f =O[l] g₁) (hg : ∀ x, g₁ x = g₂ x) : f =O[l] g₂ := h.congr (fun _ => rfl) hg theorem isLittleO_congr (hf : f₁ =á¶ [l] f₂) (hg : g₁ =á¶ [l] g₂) : f₁ =o[l] g₁ ↔ f₂ =o[l] g₂ := by simp only [IsLittleO_def] exact forall₂_congr fun c _hc => isBigOWith_congr (Eq.refl c) hf hg theorem IsLittleO.congr' (h : f₁ =o[l] g₁) (hf : f₁ =á¶ [l] f₂) (hg : g₁ =á¶ [l] g₂) : f₂ =o[l] g₂ := (isLittleO_congr hf hg).mp h theorem IsLittleO.congr (h : f₁ =o[l] g₁) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : f₂ =o[l] g₂ := h.congr' (univ_mem' hf) (univ_mem' hg) theorem IsLittleO.congr_left (h : f₁ =o[l] g) (hf : ∀ x, f₁ x = f₂ x) : f₂ =o[l] g := h.congr hf fun _ => rfl theorem IsLittleO.congr_right (h : f =o[l] g₁) (hg : ∀ x, g₁ x = g₂ x) : f =o[l] g₂ := h.congr (fun _ => rfl) hg @[trans] theorem _root_.Filter.EventuallyEq.trans_isBigO {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =á¶ [l] f₂) (h : f₂ =O[l] g) : f₁ =O[l] g := h.congr' hf.symm EventuallyEq.rfl instance transEventuallyEqIsBigO : @Trans (α → E) (α → E) (α → F) (· =á¶ [l] ·) (· =O[l] ·) (· =O[l] ·) where trans := Filter.EventuallyEq.trans_isBigO @[trans] theorem _root_.Filter.EventuallyEq.trans_isLittleO {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =á¶ [l] f₂) (h : f₂ =o[l] g) : f₁ =o[l] g := h.congr' hf.symm EventuallyEq.rfl instance transEventuallyEqIsLittleO : @Trans (α → E) (α → E) (α → F) (· =á¶ [l] ·) (· =o[l] ·) (· =o[l] ·) where trans := Filter.EventuallyEq.trans_isLittleO @[trans] theorem IsBigO.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =O[l] g₁) (hg : g₁ =á¶ [l] g₂) : f =O[l] g₂ := h.congr' EventuallyEq.rfl hg instance transIsBigOEventuallyEq : @Trans (α → E) (α → F) (α → F) (· =O[l] ·) (· =á¶ [l] ·) (· =O[l] ·) where trans := IsBigO.trans_eventuallyEq @[trans] theorem IsLittleO.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =o[l] g₁) (hg : g₁ =á¶ [l] g₂) : f =o[l] g₂ := h.congr' EventuallyEq.rfl hg instance transIsLittleOEventuallyEq : @Trans (α → E) (α → F) (α → F) (· =o[l] ·) (· =á¶ [l] ·) (· =o[l] ·) where trans := IsLittleO.trans_eventuallyEq end congr /-! ### Filter operations and transitivity -/ theorem IsBigOWith.comp_tendsto (hcfg : IsBigOWith c l f g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : IsBigOWith c l' (f ∘ k) (g ∘ k) := IsBigOWith.of_bound <| hk hcfg.bound theorem IsBigO.comp_tendsto (hfg : f =O[l] g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : (f ∘ k) =O[l'] (g ∘ k) := isBigO_iff_isBigOWith.2 <| hfg.isBigOWith.imp fun _c h => h.comp_tendsto hk theorem IsLittleO.comp_tendsto (hfg : f =o[l] g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : (f ∘ k) =o[l'] (g ∘ k) := IsLittleO.of_isBigOWith fun _c cpos => (hfg.forall_isBigOWith cpos).comp_tendsto hk @[simp] theorem isBigOWith_map {k : β → α} {l : Filter β} : IsBigOWith c (map k l) f g ↔ IsBigOWith c l (f ∘ k) (g ∘ k) := by simp only [IsBigOWith_def] exact eventually_map @[simp] theorem isBigO_map {k : β → α} {l : Filter β} : f =O[map k l] g ↔ (f ∘ k) =O[l] (g ∘ k) := by simp only [IsBigO_def, isBigOWith_map] @[simp] theorem isLittleO_map {k : β → α} {l : Filter β} : f =o[map k l] g ↔ (f ∘ k) =o[l] (g ∘ k) := by simp only [IsLittleO_def, isBigOWith_map] theorem IsBigOWith.mono (h : IsBigOWith c l' f g) (hl : l ≀ l') : IsBigOWith c l f g := IsBigOWith.of_bound <| hl h.bound theorem IsBigO.mono (h : f =O[l'] g) (hl : l ≀ l') : f =O[l] g := isBigO_iff_isBigOWith.2 <| h.isBigOWith.imp fun _c h => h.mono hl theorem IsLittleO.mono (h : f =o[l'] g) (hl : l ≀ l') : f =o[l] g := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).mono hl theorem IsBigOWith.trans (hfg : IsBigOWith c l f g) (hgk : IsBigOWith c' l g k) (hc : 0 ≀ c) : IsBigOWith (c * c') l f k := by simp only [IsBigOWith_def] at * filter_upwards [hfg, hgk] with x hx hx' calc ‖f x‖ ≀ c * ‖g x‖ := hx _ ≀ c * (c' * ‖k x‖) := by gcongr _ = c * c' * ‖k x‖ := (mul_assoc _ _ _).symm @[trans] theorem IsBigO.trans {f : α → E} {g : α → F'} {k : α → G} (hfg : f =O[l] g) (hgk : g =O[l] k) : f =O[l] k := let ⟹_c, cnonneg, hc⟩ := hfg.exists_nonneg let ⟹_c', hc'⟩ := hgk.isBigOWith (hc.trans hc' cnonneg).isBigO instance transIsBigOIsBigO : @Trans (α → E) (α → F') (α → G) (· =O[l] ·) (· =O[l] ·) (· =O[l] ·) where trans := IsBigO.trans theorem IsLittleO.trans_isBigOWith (hfg : f =o[l] g) (hgk : IsBigOWith c l g k) (hc : 0 < c) : f =o[l] k := by simp only [IsLittleO_def] at * intro c' c'pos have : 0 < c' / c := div_pos c'pos hc exact ((hfg this).trans hgk this.le).congr_const (div_mul_cancel₀ _ hc.ne') @[trans] theorem IsLittleO.trans_isBigO {f : α → E} {g : α → F} {k : α → G'} (hfg : f =o[l] g) (hgk : g =O[l] k) : f =o[l] k := let ⟹_c, cpos, hc⟩ := hgk.exists_pos hfg.trans_isBigOWith hc cpos instance transIsLittleOIsBigO : @Trans (α → E) (α → F) (α → G') (· =o[l] ·) (· =O[l] ·) (· =o[l] ·) where trans := IsLittleO.trans_isBigO theorem IsBigOWith.trans_isLittleO (hfg : IsBigOWith c l f g) (hgk : g =o[l] k) (hc : 0 < c) : f =o[l] k := by simp only [IsLittleO_def] at * intro c' c'pos have : 0 < c' / c := div_pos c'pos hc exact (hfg.trans (hgk this) hc.le).congr_const (mul_div_cancel₀ _ hc.ne') @[trans] theorem IsBigO.trans_isLittleO {f : α → E} {g : α → F'} {k : α → G} (hfg : f =O[l] g) (hgk : g =o[l] k) : f =o[l] k := let ⟹_c, cpos, hc⟩ := hfg.exists_pos hc.trans_isLittleO hgk cpos instance transIsBigOIsLittleO : @Trans (α → E) (α → F') (α → G) (· =O[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := IsBigO.trans_isLittleO @[trans] theorem IsLittleO.trans {f : α → E} {g : α → F} {k : α → G} (hfg : f =o[l] g) (hgk : g =o[l] k) : f =o[l] k := hfg.trans_isBigOWith hgk.isBigOWith one_pos instance transIsLittleOIsLittleO : @Trans (α → E) (α → F) (α → G) (· =o[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := IsLittleO.trans theorem _root_.Filter.Eventually.trans_isBigO {f : α → E} {g : α → F'} {k : α → G} (hfg : ∀ᶠ x in l, ‖f x‖ ≀ ‖g x‖) (hgk : g =O[l] k) : f =O[l] k := (IsBigO.of_bound' hfg).trans hgk theorem _root_.Filter.Eventually.isBigO {f : α → E} {g : α → ℝ} {l : Filter α} (hfg : ∀ᶠ x in l, ‖f x‖ ≀ g x) : f =O[l] g := IsBigO.of_bound' <| hfg.mono fun _x hx => hx.trans <| Real.le_norm_self _ section variable (l) theorem isBigOWith_of_le' (hfg : ∀ x, ‖f x‖ ≀ c * ‖g x‖) : IsBigOWith c l f g := IsBigOWith.of_bound <| univ_mem' hfg theorem isBigOWith_of_le (hfg : ∀ x, ‖f x‖ ≀ ‖g x‖) : IsBigOWith 1 l f g := isBigOWith_of_le' l fun x => by rw [one_mul] exact hfg x theorem isBigO_of_le' (hfg : ∀ x, ‖f x‖ ≀ c * ‖g x‖) : f =O[l] g := (isBigOWith_of_le' l hfg).isBigO theorem isBigO_of_le (hfg : ∀ x, ‖f x‖ ≀ ‖g x‖) : f =O[l] g := (isBigOWith_of_le l hfg).isBigO end theorem isBigOWith_refl (f : α → E) (l : Filter α) : IsBigOWith 1 l f f := isBigOWith_of_le l fun _ => le_rfl theorem isBigO_refl (f : α → E) (l : Filter α) : f =O[l] f := (isBigOWith_refl f l).isBigO theorem _root_.Filter.EventuallyEq.isBigO {f₁ f₂ : α → E} (hf : f₁ =á¶ [l] f₂) : f₁ =O[l] f₂ := hf.trans_isBigO (isBigO_refl _ _) theorem IsBigOWith.trans_le (hfg : IsBigOWith c l f g) (hgk : ∀ x, ‖g x‖ ≀ ‖k x‖) (hc : 0 ≀ c) : IsBigOWith c l f k := (hfg.trans (isBigOWith_of_le l hgk) hc).congr_const <| mul_one c theorem IsBigO.trans_le (hfg : f =O[l] g') (hgk : ∀ x, ‖g' x‖ ≀ ‖k x‖) : f =O[l] k := hfg.trans (isBigO_of_le l hgk) theorem IsLittleO.trans_le (hfg : f =o[l] g) (hgk : ∀ x, ‖g x‖ ≀ ‖k x‖) : f =o[l] k := hfg.trans_isBigOWith (isBigOWith_of_le _ hgk) zero_lt_one theorem isLittleO_irrefl' (h : ∃ᶠ x in l, ‖f' x‖ ≠ 0) : ¬f' =o[l] f' := by intro ho rcases ((ho.bound one_half_pos).and_frequently h).exists with ⟹x, hle, hne⟩ rw [one_div, ← div_eq_inv_mul] at hle exact (half_lt_self (lt_of_le_of_ne (norm_nonneg _) hne.symm)).not_le hle theorem isLittleO_irrefl (h : ∃ᶠ x in l, f'' x ≠ 0) : ¬f'' =o[l] f'' := isLittleO_irrefl' <| h.mono fun _x => norm_ne_zero_iff.mpr theorem IsBigO.not_isLittleO (h : f'' =O[l] g') (hf : ∃ᶠ x in l, f'' x ≠ 0) : ¬g' =o[l] f'' := fun h' => isLittleO_irrefl hf (h.trans_isLittleO h') theorem IsLittleO.not_isBigO (h : f'' =o[l] g') (hf : ∃ᶠ x in l, f'' x ≠ 0) : ¬g' =O[l] f'' := fun h' => isLittleO_irrefl hf (h.trans_isBigO h') section Bot variable (c f g) @[simp] theorem isBigOWith_bot : IsBigOWith c ⊥ f g := IsBigOWith.of_bound <| trivial @[simp] theorem isBigO_bot : f =O[⊥] g := (isBigOWith_bot 1 f g).isBigO @[simp] theorem isLittleO_bot : f =o[⊥] g := IsLittleO.of_isBigOWith fun c _ => isBigOWith_bot c f g end Bot @[simp] theorem isBigOWith_pure {x} : IsBigOWith c (pure x) f g ↔ ‖f x‖ ≀ c * ‖g x‖ := isBigOWith_iff theorem IsBigOWith.sup (h : IsBigOWith c l f g) (h' : IsBigOWith c l' f g) : IsBigOWith c (l ⊔ l') f g := IsBigOWith.of_bound <| mem_sup.2 ⟹h.bound, h'.bound⟩ theorem IsBigOWith.sup' (h : IsBigOWith c l f g') (h' : IsBigOWith c' l' f g') : IsBigOWith (max c c') (l ⊔ l') f g' := IsBigOWith.of_bound <| mem_sup.2 ⟹(h.weaken <| le_max_left c c').bound, (h'.weaken <| le_max_right c c').bound⟩ theorem IsBigO.sup (h : f =O[l] g') (h' : f =O[l'] g') : f =O[l ⊔ l'] g' := let ⟹_c, hc⟩ := h.isBigOWith let ⟹_c', hc'⟩ := h'.isBigOWith (hc.sup' hc').isBigO theorem IsLittleO.sup (h : f =o[l] g) (h' : f =o[l'] g) : f =o[l ⊔ l'] g := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).sup (h'.forall_isBigOWith cpos) @[simp] theorem isBigO_sup : f =O[l ⊔ l'] g' ↔ f =O[l] g' ∧ f =O[l'] g' := ⟹fun h => ⟹h.mono le_sup_left, h.mono le_sup_right⟩, fun h => h.1.sup h.2⟩ @[simp] theorem isLittleO_sup : f =o[l ⊔ l'] g ↔ f =o[l] g ∧ f =o[l'] g := ⟹fun h => ⟹h.mono le_sup_left, h.mono le_sup_right⟩, fun h => h.1.sup h.2⟩ theorem isBigOWith_insert [TopologicalSpace α] {x : α} {s : Set α} {C : ℝ} {g : α → E} {g' : α → F} (h : ‖g x‖ ≀ C * ‖g' x‖) : IsBigOWith C (𝓝[insert x s] x) g g' ↔ IsBigOWith C (𝓝[s] x) g g' := by simp_rw [IsBigOWith_def, nhdsWithin_insert, eventually_sup, eventually_pure, h, true_and_iff] protected theorem IsBigOWith.insert [TopologicalSpace α] {x : α} {s : Set α} {C : ℝ} {g : α → E} {g' : α → F} (h1 : IsBigOWith C (𝓝[s] x) g g') (h2 : ‖g x‖ ≀ C * ‖g' x‖) : IsBigOWith C (𝓝[insert x s] x) g g' := (isBigOWith_insert h2).mpr h1 theorem isLittleO_insert [TopologicalSpace α] {x : α} {s : Set α} {g : α → E'} {g' : α → F'} (h : g x = 0) : g =o[𝓝[insert x s] x] g' ↔ g =o[𝓝[s] x] g' := by simp_rw [IsLittleO_def] refine forall_congr' fun c => forall_congr' fun hc => ?_ rw [isBigOWith_insert] rw [h, norm_zero] exact mul_nonneg hc.le (norm_nonneg _) protected theorem IsLittleO.insert [TopologicalSpace α] {x : α} {s : Set α} {g : α → E'} {g' : α → F'} (h1 : g =o[𝓝[s] x] g') (h2 : g x = 0) : g =o[𝓝[insert x s] x] g' := (isLittleO_insert h2).mpr h1 /-! ### Simplification : norm, abs -/ section NormAbs variable {u v : α → ℝ} @[simp] theorem isBigOWith_norm_right : (IsBigOWith c l f fun x => ‖g' x‖) ↔ IsBigOWith c l f g' := by simp only [IsBigOWith_def, norm_norm] @[simp] theorem isBigOWith_abs_right : (IsBigOWith c l f fun x => |u x|) ↔ IsBigOWith c l f u := @isBigOWith_norm_right _ _ _ _ _ _ f u l alias ⟹IsBigOWith.of_norm_right, IsBigOWith.norm_right⟩ := isBigOWith_norm_right alias ⟹IsBigOWith.of_abs_right, IsBigOWith.abs_right⟩ := isBigOWith_abs_right @[simp] theorem isBigO_norm_right : (f =O[l] fun x => ‖g' x‖) ↔ f =O[l] g' := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_norm_right @[simp] theorem isBigO_abs_right : (f =O[l] fun x => |u x|) ↔ f =O[l] u := @isBigO_norm_right _ _ ℝ _ _ _ _ _ alias ⟹IsBigO.of_norm_right, IsBigO.norm_right⟩ := isBigO_norm_right alias ⟹IsBigO.of_abs_right, IsBigO.abs_right⟩ := isBigO_abs_right @[simp] theorem isLittleO_norm_right : (f =o[l] fun x => ‖g' x‖) ↔ f =o[l] g' := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_norm_right @[simp] theorem isLittleO_abs_right : (f =o[l] fun x => |u x|) ↔ f =o[l] u := @isLittleO_norm_right _ _ ℝ _ _ _ _ _ alias ⟹IsLittleO.of_norm_right, IsLittleO.norm_right⟩ := isLittleO_norm_right alias ⟹IsLittleO.of_abs_right, IsLittleO.abs_right⟩ := isLittleO_abs_right @[simp] theorem isBigOWith_norm_left : IsBigOWith c l (fun x => ‖f' x‖) g ↔ IsBigOWith c l f' g := by simp only [IsBigOWith_def, norm_norm] @[simp] theorem isBigOWith_abs_left : IsBigOWith c l (fun x => |u x|) g ↔ IsBigOWith c l u g := @isBigOWith_norm_left _ _ _ _ _ _ g u l alias ⟹IsBigOWith.of_norm_left, IsBigOWith.norm_left⟩ := isBigOWith_norm_left alias ⟹IsBigOWith.of_abs_left, IsBigOWith.abs_left⟩ := isBigOWith_abs_left @[simp] theorem isBigO_norm_left : (fun x => ‖f' x‖) =O[l] g ↔ f' =O[l] g := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_norm_left @[simp] theorem isBigO_abs_left : (fun x => |u x|) =O[l] g ↔ u =O[l] g := @isBigO_norm_left _ _ _ _ _ g u l alias ⟹IsBigO.of_norm_left, IsBigO.norm_left⟩ := isBigO_norm_left alias ⟹IsBigO.of_abs_left, IsBigO.abs_left⟩ := isBigO_abs_left @[simp] theorem isLittleO_norm_left : (fun x => ‖f' x‖) =o[l] g ↔ f' =o[l] g := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_norm_left @[simp] theorem isLittleO_abs_left : (fun x => |u x|) =o[l] g ↔ u =o[l] g := @isLittleO_norm_left _ _ _ _ _ g u l alias ⟹IsLittleO.of_norm_left, IsLittleO.norm_left⟩ := isLittleO_norm_left alias ⟹IsLittleO.of_abs_left, IsLittleO.abs_left⟩ := isLittleO_abs_left theorem isBigOWith_norm_norm : (IsBigOWith c l (fun x => ‖f' x‖) fun x => ‖g' x‖) ↔ IsBigOWith c l f' g' := isBigOWith_norm_left.trans isBigOWith_norm_right theorem isBigOWith_abs_abs : (IsBigOWith c l (fun x => |u x|) fun x => |v x|) ↔ IsBigOWith c l u v := isBigOWith_abs_left.trans isBigOWith_abs_right alias ⟹IsBigOWith.of_norm_norm, IsBigOWith.norm_norm⟩ := isBigOWith_norm_norm alias ⟹IsBigOWith.of_abs_abs, IsBigOWith.abs_abs⟩ := isBigOWith_abs_abs theorem isBigO_norm_norm : ((fun x => ‖f' x‖) =O[l] fun x => ‖g' x‖) ↔ f' =O[l] g' := isBigO_norm_left.trans isBigO_norm_right theorem isBigO_abs_abs : ((fun x => |u x|) =O[l] fun x => |v x|) ↔ u =O[l] v := isBigO_abs_left.trans isBigO_abs_right alias ⟹IsBigO.of_norm_norm, IsBigO.norm_norm⟩ := isBigO_norm_norm alias ⟹IsBigO.of_abs_abs, IsBigO.abs_abs⟩ := isBigO_abs_abs theorem isLittleO_norm_norm : ((fun x => ‖f' x‖) =o[l] fun x => ‖g' x‖) ↔ f' =o[l] g' := isLittleO_norm_left.trans isLittleO_norm_right theorem isLittleO_abs_abs : ((fun x => |u x|) =o[l] fun x => |v x|) ↔ u =o[l] v := isLittleO_abs_left.trans isLittleO_abs_right alias ⟹IsLittleO.of_norm_norm, IsLittleO.norm_norm⟩ := isLittleO_norm_norm alias ⟹IsLittleO.of_abs_abs, IsLittleO.abs_abs⟩ := isLittleO_abs_abs end NormAbs /-! ### Simplification: negate -/ @[simp] theorem isBigOWith_neg_right : (IsBigOWith c l f fun x => -g' x) ↔ IsBigOWith c l f g' := by simp only [IsBigOWith_def, norm_neg] alias ⟹IsBigOWith.of_neg_right, IsBigOWith.neg_right⟩ := isBigOWith_neg_right @[simp] theorem isBigO_neg_right : (f =O[l] fun x => -g' x) ↔ f =O[l] g' := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_neg_right alias ⟹IsBigO.of_neg_right, IsBigO.neg_right⟩ := isBigO_neg_right @[simp] theorem isLittleO_neg_right : (f =o[l] fun x => -g' x) ↔ f =o[l] g' := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_neg_right alias ⟹IsLittleO.of_neg_right, IsLittleO.neg_right⟩ := isLittleO_neg_right @[simp] theorem isBigOWith_neg_left : IsBigOWith c l (fun x => -f' x) g ↔ IsBigOWith c l f' g := by simp only [IsBigOWith_def, norm_neg] alias ⟹IsBigOWith.of_neg_left, IsBigOWith.neg_left⟩ := isBigOWith_neg_left @[simp] theorem isBigO_neg_left : (fun x => -f' x) =O[l] g ↔ f' =O[l] g := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_neg_left alias ⟹IsBigO.of_neg_left, IsBigO.neg_left⟩ := isBigO_neg_left @[simp] theorem isLittleO_neg_left : (fun x => -f' x) =o[l] g ↔ f' =o[l] g := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_neg_left alias ⟹IsLittleO.of_neg_left, IsLittleO.neg_left⟩ := isLittleO_neg_left /-! ### Product of functions (right) -/ theorem isBigOWith_fst_prod : IsBigOWith 1 l f' fun x => (f' x, g' x) := isBigOWith_of_le l fun _x => le_max_left _ _ theorem isBigOWith_snd_prod : IsBigOWith 1 l g' fun x => (f' x, g' x) := isBigOWith_of_le l fun _x => le_max_right _ _ theorem isBigO_fst_prod : f' =O[l] fun x => (f' x, g' x) := isBigOWith_fst_prod.isBigO theorem isBigO_snd_prod : g' =O[l] fun x => (f' x, g' x) := isBigOWith_snd_prod.isBigO theorem isBigO_fst_prod' {f' : α → E' × F'} : (fun x => (f' x).1) =O[l] f' := by simpa [IsBigO_def, IsBigOWith_def] using isBigO_fst_prod (E' := E') (F' := F') theorem isBigO_snd_prod' {f' : α → E' × F'} : (fun x => (f' x).2) =O[l] f' := by simpa [IsBigO_def, IsBigOWith_def] using isBigO_snd_prod (E' := E') (F' := F') section variable (f' k') theorem IsBigOWith.prod_rightl (h : IsBigOWith c l f g') (hc : 0 ≀ c) : IsBigOWith c l f fun x => (g' x, k' x) := (h.trans isBigOWith_fst_prod hc).congr_const (mul_one c) theorem IsBigO.prod_rightl (h : f =O[l] g') : f =O[l] fun x => (g' x, k' x) := let ⟹_c, cnonneg, hc⟩ := h.exists_nonneg (hc.prod_rightl k' cnonneg).isBigO theorem IsLittleO.prod_rightl (h : f =o[l] g') : f =o[l] fun x => (g' x, k' x) := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).prod_rightl k' cpos.le theorem IsBigOWith.prod_rightr (h : IsBigOWith c l f g') (hc : 0 ≀ c) : IsBigOWith c l f fun x => (f' x, g' x) := (h.trans isBigOWith_snd_prod hc).congr_const (mul_one c) theorem IsBigO.prod_rightr (h : f =O[l] g') : f =O[l] fun x => (f' x, g' x) := let ⟹_c, cnonneg, hc⟩ := h.exists_nonneg (hc.prod_rightr f' cnonneg).isBigO theorem IsLittleO.prod_rightr (h : f =o[l] g') : f =o[l] fun x => (f' x, g' x) := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).prod_rightr f' cpos.le end theorem IsBigOWith.prod_left_same (hf : IsBigOWith c l f' k') (hg : IsBigOWith c l g' k') : IsBigOWith c l (fun x => (f' x, g' x)) k' := by rw [isBigOWith_iff] at *; filter_upwards [hf, hg] with x using max_le theorem IsBigOWith.prod_left (hf : IsBigOWith c l f' k') (hg : IsBigOWith c' l g' k') : IsBigOWith (max c c') l (fun x => (f' x, g' x)) k' := (hf.weaken <| le_max_left c c').prod_left_same (hg.weaken <| le_max_right c c') theorem IsBigOWith.prod_left_fst (h : IsBigOWith c l (fun x => (f' x, g' x)) k') : IsBigOWith c l f' k' := (isBigOWith_fst_prod.trans h zero_le_one).congr_const <| one_mul c theorem IsBigOWith.prod_left_snd (h : IsBigOWith c l (fun x => (f' x, g' x)) k') : IsBigOWith c l g' k' := (isBigOWith_snd_prod.trans h zero_le_one).congr_const <| one_mul c theorem isBigOWith_prod_left : IsBigOWith c l (fun x => (f' x, g' x)) k' ↔ IsBigOWith c l f' k' ∧ IsBigOWith c l g' k' := ⟹fun h => ⟹h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left_same h.2⟩ theorem IsBigO.prod_left (hf : f' =O[l] k') (hg : g' =O[l] k') : (fun x => (f' x, g' x)) =O[l] k' := let ⟹_c, hf⟩ := hf.isBigOWith let ⟹_c', hg⟩ := hg.isBigOWith (hf.prod_left hg).isBigO theorem IsBigO.prod_left_fst : (fun x => (f' x, g' x)) =O[l] k' → f' =O[l] k' := IsBigO.trans isBigO_fst_prod theorem IsBigO.prod_left_snd : (fun x => (f' x, g' x)) =O[l] k' → g' =O[l] k' := IsBigO.trans isBigO_snd_prod @[simp] theorem isBigO_prod_left : (fun x => (f' x, g' x)) =O[l] k' ↔ f' =O[l] k' ∧ g' =O[l] k' := ⟹fun h => ⟹h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left h.2⟩ theorem IsLittleO.prod_left (hf : f' =o[l] k') (hg : g' =o[l] k') : (fun x => (f' x, g' x)) =o[l] k' := IsLittleO.of_isBigOWith fun _c hc => (hf.forall_isBigOWith hc).prod_left_same (hg.forall_isBigOWith hc) theorem IsLittleO.prod_left_fst : (fun x => (f' x, g' x)) =o[l] k' → f' =o[l] k' := IsBigO.trans_isLittleO isBigO_fst_prod theorem IsLittleO.prod_left_snd : (fun x => (f' x, g' x)) =o[l] k' → g' =o[l] k' := IsBigO.trans_isLittleO isBigO_snd_prod @[simp] theorem isLittleO_prod_left : (fun x => (f' x, g' x)) =o[l] k' ↔ f' =o[l] k' ∧ g' =o[l] k' := ⟹fun h => ⟹h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left h.2⟩ theorem IsBigOWith.eq_zero_imp (h : IsBigOWith c l f'' g'') : ∀ᶠ x in l, g'' x = 0 → f'' x = 0 := Eventually.mono h.bound fun x hx hg => norm_le_zero_iff.1 <| by simpa [hg] using hx theorem IsBigO.eq_zero_imp (h : f'' =O[l] g'') : ∀ᶠ x in l, g'' x = 0 → f'' x = 0 := let ⟹_C, hC⟩ := h.isBigOWith hC.eq_zero_imp /-! ### Addition and subtraction -/ section add_sub variable {f₁ f₂ : α → E'} {g₁ g₂ : α → F'} theorem IsBigOWith.add (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : IsBigOWith c₂ l f₂ g) : IsBigOWith (c₁ + c₂) l (fun x => f₁ x + f₂ x) g := by rw [IsBigOWith_def] at * filter_upwards [h₁, h₂] with x hx₁ hx₂ using calc ‖f₁ x + f₂ x‖ ≀ c₁ * ‖g x‖ + c₂ * ‖g x‖ := norm_add_le_of_le hx₁ hx₂ _ = (c₁ + c₂) * ‖g x‖ := (add_mul _ _ _).symm theorem IsBigO.add (h₁ : f₁ =O[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := let ⟹_c₁, hc₁⟩ := h₁.isBigOWith let ⟹_c₂, hc₂⟩ := h₂.isBigOWith (hc₁.add hc₂).isBigO theorem IsLittleO.add (h₁ : f₁ =o[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x + f₂ x) =o[l] g := IsLittleO.of_isBigOWith fun c cpos => ((h₁.forall_isBigOWith <| half_pos cpos).add (h₂.forall_isBigOWith <| half_pos cpos)).congr_const (add_halves c) theorem IsLittleO.add_add (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x + f₂ x) =o[l] fun x => ‖g₁ x‖ + ‖g₂ x‖ := by refine (h₁.trans_le fun x => ?_).add (h₂.trans_le ?_) <;> simp [abs_of_nonneg, add_nonneg] theorem IsBigO.add_isLittleO (h₁ : f₁ =O[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := h₁.add h₂.isBigO theorem IsLittleO.add_isBigO (h₁ : f₁ =o[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := h₁.isBigO.add h₂ theorem IsBigOWith.add_isLittleO (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : f₂ =o[l] g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x + f₂ x) g := (h₁.add (h₂.forall_isBigOWith (sub_pos.2 hc))).congr_const (add_sub_cancel _ _) theorem IsLittleO.add_isBigOWith (h₁ : f₁ =o[l] g) (h₂ : IsBigOWith c₁ l f₂ g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x + f₂ x) g := (h₂.add_isLittleO h₁ hc).congr_left fun _ => add_comm _ _ theorem IsBigOWith.sub (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : IsBigOWith c₂ l f₂ g) : IsBigOWith (c₁ + c₂) l (fun x => f₁ x - f₂ x) g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left theorem IsBigOWith.sub_isLittleO (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : f₂ =o[l] g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x - f₂ x) g := by simpa only [sub_eq_add_neg] using h₁.add_isLittleO h₂.neg_left hc theorem IsBigO.sub (h₁ : f₁ =O[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x - f₂ x) =O[l] g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left theorem IsLittleO.sub (h₁ : f₁ =o[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x - f₂ x) =o[l] g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left end add_sub /-! ### Lemmas about `IsBigO (f₁ - f₂) g l` / `IsLittleO (f₁ - f₂) g l` treated as a binary relation -/ section IsBigOOAsRel variable {f₁ f₂ f₃ : α → E'} theorem IsBigOWith.symm (h : IsBigOWith c l (fun x => f₁ x - f₂ x) g) : IsBigOWith c l (fun x => f₂ x - f₁ x) g := h.neg_left.congr_left fun _x => neg_sub _ _ theorem isBigOWith_comm : IsBigOWith c l (fun x => f₁ x - f₂ x) g ↔ IsBigOWith c l (fun x => f₂ x - f₁ x) g := ⟹IsBigOWith.symm, IsBigOWith.symm⟩ theorem IsBigO.symm (h : (fun x => f₁ x - f₂ x) =O[l] g) : (fun x => f₂ x - f₁ x) =O[l] g := h.neg_left.congr_left fun _x => neg_sub _ _ theorem isBigO_comm : (fun x => f₁ x - f₂ x) =O[l] g ↔ (fun x => f₂ x - f₁ x) =O[l] g := ⟹IsBigO.symm, IsBigO.symm⟩ theorem IsLittleO.symm (h : (fun x => f₁ x - f₂ x) =o[l] g) : (fun x => f₂ x - f₁ x) =o[l] g := by simpa only [neg_sub] using h.neg_left theorem isLittleO_comm : (fun x => f₁ x - f₂ x) =o[l] g ↔ (fun x => f₂ x - f₁ x) =o[l] g := ⟹IsLittleO.symm, IsLittleO.symm⟩ theorem IsBigOWith.triangle (h₁ : IsBigOWith c l (fun x => f₁ x - f₂ x) g) (h₂ : IsBigOWith c' l (fun x => f₂ x - f₃ x) g) : IsBigOWith (c + c') l (fun x => f₁ x - f₃ x) g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ theorem IsBigO.triangle (h₁ : (fun x => f₁ x - f₂ x) =O[l] g) (h₂ : (fun x => f₂ x - f₃ x) =O[l] g) : (fun x => f₁ x - f₃ x) =O[l] g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ theorem IsLittleO.triangle (h₁ : (fun x => f₁ x - f₂ x) =o[l] g) (h₂ : (fun x => f₂ x - f₃ x) =o[l] g) : (fun x => f₁ x - f₃ x) =o[l] g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ theorem IsBigO.congr_of_sub (h : (fun x => f₁ x - f₂ x) =O[l] g) : f₁ =O[l] g ↔ f₂ =O[l] g := ⟹fun h' => (h'.sub h).congr_left fun _x => sub_sub_cancel _ _, fun h' => (h.add h').congr_left fun _x => sub_add_cancel _ _⟩ theorem IsLittleO.congr_of_sub (h : (fun x => f₁ x - f₂ x) =o[l] g) : f₁ =o[l] g ↔ f₂ =o[l] g := ⟹fun h' => (h'.sub h).congr_left fun _x => sub_sub_cancel _ _, fun h' => (h.add h').congr_left fun _x => sub_add_cancel _ _⟩ end IsBigOOAsRel /-! ### Zero, one, and other constants -/ section ZeroConst variable (g g' l) theorem isLittleO_zero : (fun _x => (0 : E')) =o[l] g' := IsLittleO.of_bound fun c hc => univ_mem' fun x => by simpa using mul_nonneg hc.le (norm_nonneg <| g' x) theorem isBigOWith_zero (hc : 0 ≀ c) : IsBigOWith c l (fun _x => (0 : E')) g' := IsBigOWith.of_bound <| univ_mem' fun x => by simpa using mul_nonneg hc (norm_nonneg <| g' x) theorem isBigOWith_zero' : IsBigOWith 0 l (fun _x => (0 : E')) g := IsBigOWith.of_bound <| univ_mem' fun x => by simp theorem isBigO_zero : (fun _x => (0 : E')) =O[l] g := isBigO_iff_isBigOWith.2 ⟹0, isBigOWith_zero' _ _⟩ theorem isBigO_refl_left : (fun x => f' x - f' x) =O[l] g' := (isBigO_zero g' l).congr_left fun _x => (sub_self _).symm theorem isLittleO_refl_left : (fun x => f' x - f' x) =o[l] g' := (isLittleO_zero g' l).congr_left fun _x => (sub_self _).symm variable {g g' l} @[simp] theorem isBigOWith_zero_right_iff : (IsBigOWith c l f'' fun _x => (0 : F')) ↔ f'' =á¶ [l] 0 := by simp only [IsBigOWith_def, exists_prop, true_and_iff, norm_zero, mul_zero, norm_le_zero_iff, EventuallyEq, Pi.zero_apply] @[simp] theorem isBigO_zero_right_iff : (f'' =O[l] fun _x => (0 : F')) ↔ f'' =á¶ [l] 0 := ⟹fun h => let ⟹_c, hc⟩ := h.isBigOWith isBigOWith_zero_right_iff.1 hc, fun h => (isBigOWith_zero_right_iff.2 h : IsBigOWith 1 _ _ _).isBigO⟩ @[simp] theorem isLittleO_zero_right_iff : (f'' =o[l] fun _x => (0 : F')) ↔ f'' =á¶ [l] 0 := ⟹fun h => isBigO_zero_right_iff.1 h.isBigO, fun h => IsLittleO.of_isBigOWith fun _c _hc => isBigOWith_zero_right_iff.2 h⟩ theorem isBigOWith_const_const (c : E) {c' : F''} (hc' : c' ≠ 0) (l : Filter α) : IsBigOWith (‖c‖ / ‖c'‖) l (fun _x : α => c) fun _x => c' := by simp only [IsBigOWith_def] apply univ_mem' intro x rw [mem_setOf, div_mul_cancel₀ _ (norm_ne_zero_iff.mpr hc')] theorem isBigO_const_const (c : E) {c' : F''} (hc' : c' ≠ 0) (l : Filter α) : (fun _x : α => c) =O[l] fun _x => c' := (isBigOWith_const_const c hc' l).isBigO @[simp] theorem isBigO_const_const_iff {c : E''} {c' : F''} (l : Filter α) [l.NeBot] : ((fun _x : α => c) =O[l] fun _x => c') ↔ c' = 0 → c = 0 := by rcases eq_or_ne c' 0 with (rfl | hc') · simp [EventuallyEq] · simp [hc', isBigO_const_const _ hc'] @[simp] theorem isBigO_pure {x} : f'' =O[pure x] g'' ↔ g'' x = 0 → f'' x = 0 := calc f'' =O[pure x] g'' ↔ (fun _y : α => f'' x) =O[pure x] fun _ => g'' x := isBigO_congr rfl rfl _ ↔ g'' x = 0 → f'' x = 0 := isBigO_const_const_iff _ end ZeroConst @[simp] theorem isBigOWith_principal {s : Set α} : IsBigOWith c (𝓟 s) f g ↔ ∀ x ∈ s, ‖f x‖ ≀ c * ‖g x‖ := by rw [IsBigOWith_def, eventually_principal] theorem isBigO_principal {s : Set α} : f =O[𝓟 s] g ↔ ∃ c, ∀ x ∈ s, ‖f x‖ ≀ c * ‖g x‖ := by simp_rw [isBigO_iff, eventually_principal] @[simp] theorem isLittleO_principal {s : Set α} : f'' =o[𝓟 s] g' ↔ ∀ x ∈ s, f'' x = 0 := by refine ⟹fun h x hx ↩ norm_le_zero_iff.1 ?_, fun h ↩ ?_⟩ · simp only [isLittleO_iff, isBigOWith_principal] at h have : Tendsto (fun c : ℝ => c * ‖g' x‖) (𝓝[>] 0) (𝓝 0) := ((continuous_id.mul continuous_const).tendsto' _ _ (zero_mul _)).mono_left inf_le_left apply le_of_tendsto_of_tendsto tendsto_const_nhds this apply eventually_nhdsWithin_iff.2 (eventually_of_forall (fun c hc ↩ ?_)) exact eventually_principal.1 (h hc) x hx · apply (isLittleO_zero g' _).congr' ?_ EventuallyEq.rfl exact fun x hx ↩ (h x hx).symm @[simp] theorem isBigOWith_top : IsBigOWith c ⊀ f g ↔ ∀ x, ‖f x‖ ≀ c * ‖g x‖ := by rw [IsBigOWith_def, eventually_top] @[simp] theorem isBigO_top : f =O[⊀] g ↔ ∃ C, ∀ x, ‖f x‖ ≀ C * ‖g x‖ := by simp_rw [isBigO_iff, eventually_top] @[simp] theorem isLittleO_top : f'' =o[⊀] g' ↔ ∀ x, f'' x = 0 := by simp only [← principal_univ, isLittleO_principal, mem_univ, forall_true_left] section variable (F) variable [One F] [NormOneClass F] theorem isBigOWith_const_one (c : E) (l : Filter α) : IsBigOWith ‖c‖ l (fun _x : α => c) fun _x => (1 : F) := by simp [isBigOWith_iff] theorem isBigO_const_one (c : E) (l : Filter α) : (fun _x : α => c) =O[l] fun _x => (1 : F) := (isBigOWith_const_one F c l).isBigO theorem isLittleO_const_iff_isLittleO_one {c : F''} (hc : c ≠ 0) : (f =o[l] fun _x => c) ↔ f =o[l] fun _x => (1 : F) := ⟹fun h => h.trans_isBigOWith (isBigOWith_const_one _ _ _) (norm_pos_iff.2 hc), fun h => h.trans_isBigO <| isBigO_const_const _ hc _⟩ @[simp] theorem isLittleO_one_iff : f' =o[l] (fun _x => 1 : α → F) ↔ Tendsto f' l (𝓝 0) := by simp only [isLittleO_iff, norm_one, mul_one, Metric.nhds_basis_closedBall.tendsto_right_iff, Metric.mem_closedBall, dist_zero_right] @[simp] theorem isBigO_one_iff : f =O[l] (fun _x => 1 : α → F) ↔ IsBoundedUnder (· ≀ ·) l fun x => ‖f x‖ := by simp only [isBigO_iff, norm_one, mul_one, IsBoundedUnder, IsBounded, eventually_map] alias ⟹_, _root_.Filter.IsBoundedUnder.isBigO_one⟩ := isBigO_one_iff @[simp] theorem isLittleO_one_left_iff : (fun _x => 1 : α → F) =o[l] f ↔ Tendsto (fun x => ‖f x‖) l atTop := calc (fun _x => 1 : α → F) =o[l] f ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖(1 : F)‖ ≀ ‖f x‖ := isLittleO_iff_nat_mul_le_aux <| Or.inl fun _x => by simp only [norm_one, zero_le_one] _ ↔ ∀ n : ℕ, True → ∀ᶠ x in l, ‖f x‖ ∈ Ici (n : ℝ) := by simp only [norm_one, mul_one, true_imp_iff, mem_Ici] _ ↔ Tendsto (fun x => ‖f x‖) l atTop := atTop_hasCountableBasis_of_archimedean.1.tendsto_right_iff.symm theorem _root_.Filter.Tendsto.isBigO_one {c : E'} (h : Tendsto f' l (𝓝 c)) : f' =O[l] (fun _x => 1 : α → F) := h.norm.isBoundedUnder_le.isBigO_one F theorem IsBigO.trans_tendsto_nhds (hfg : f =O[l] g') {y : F'} (hg : Tendsto g' l (𝓝 y)) : f =O[l] (fun _x => 1 : α → F) := hfg.trans <| hg.isBigO_one F /-- The condition `f = O[𝓝[≠] a] 1` is equivalent to `f = O[𝓝 a] 1`. -/ lemma isBigO_one_nhds_ne_iff [TopologicalSpace α] {a : α} : f =O[𝓝[≠] a] (fun _ ↩ 1 : α → F) ↔ f =O[𝓝 a] (fun _ ↩ 1 : α → F) := by refine ⟹fun h ↩ ?_, fun h ↩ h.mono nhdsWithin_le_nhds⟩ simp only [isBigO_one_iff, IsBoundedUnder, IsBounded, eventually_map] at h ⊢ obtain ⟹c, hc⟩ := h use max c ‖f a‖ filter_upwards [eventually_nhdsWithin_iff.mp hc] with b hb rcases eq_or_ne b a with rfl | hb' · apply le_max_right · exact (hb hb').trans (le_max_left ..) end theorem isLittleO_const_iff {c : F''} (hc : c ≠ 0) : (f'' =o[l] fun _x => c) ↔ Tendsto f'' l (𝓝 0) := (isLittleO_const_iff_isLittleO_one ℝ hc).trans (isLittleO_one_iff _) theorem isLittleO_id_const {c : F''} (hc : c ≠ 0) : (fun x : E'' => x) =o[𝓝 0] fun _x => c := (isLittleO_const_iff hc).mpr (continuous_id.tendsto 0) theorem _root_.Filter.IsBoundedUnder.isBigO_const (h : IsBoundedUnder (· ≀ ·) l (norm ∘ f)) {c : F''} (hc : c ≠ 0) : f =O[l] fun _x => c := (h.isBigO_one ℝ).trans (isBigO_const_const _ hc _) theorem isBigO_const_of_tendsto {y : E''} (h : Tendsto f'' l (𝓝 y)) {c : F''} (hc : c ≠ 0) : f'' =O[l] fun _x => c := h.norm.isBoundedUnder_le.isBigO_const hc theorem IsBigO.isBoundedUnder_le {c : F} (h : f =O[l] fun _x => c) : IsBoundedUnder (· ≀ ·) l (norm ∘ f) := let ⟹c', hc'⟩ := h.bound ⟹c' * ‖c‖, eventually_map.2 hc'⟩ theorem isBigO_const_of_ne {c : F''} (hc : c ≠ 0) : (f =O[l] fun _x => c) ↔ IsBoundedUnder (· ≀ ·) l (norm ∘ f) := ⟹fun h => h.isBoundedUnder_le, fun h => h.isBigO_const hc⟩ theorem isBigO_const_iff {c : F''} : (f'' =O[l] fun _x => c) ↔ (c = 0 → f'' =á¶ [l] 0) ∧ IsBoundedUnder (· ≀ ·) l fun x => ‖f'' x‖ := by refine ⟹fun h => ⟹fun hc => isBigO_zero_right_iff.1 (by rwa [← hc]), h.isBoundedUnder_le⟩, ?_⟩ rintro ⟹hcf, hf⟩ rcases eq_or_ne c 0 with (hc | hc) exacts [(hcf hc).trans_isBigO (isBigO_zero _ _), hf.isBigO_const hc] theorem isBigO_iff_isBoundedUnder_le_div (h : ∀ᶠ x in l, g'' x ≠ 0) : f =O[l] g'' ↔ IsBoundedUnder (· ≀ ·) l fun x => ‖f x‖ / ‖g'' x‖ := by simp only [isBigO_iff, IsBoundedUnder, IsBounded, eventually_map] exact exists_congr fun c => eventually_congr <| h.mono fun x hx => (div_le_iff <| norm_pos_iff.2 hx).symm /-- `(fun x ↩ c) =O[l] f` if and only if `f` is bounded away from zero. -/ theorem isBigO_const_left_iff_pos_le_norm {c : E''} (hc : c ≠ 0) : (fun _x => c) =O[l] f' ↔ ∃ b, 0 < b ∧ ∀ᶠ x in l, b ≀ ‖f' x‖ := by constructor · intro h rcases h.exists_pos with ⟹C, hC₀, hC⟩ refine ⟹‖c‖ / C, div_pos (norm_pos_iff.2 hc) hC₀, ?_⟩ exact hC.bound.mono fun x => (div_le_iff' hC₀).2 · rintro ⟹b, hb₀, hb⟩ refine IsBigO.of_bound (‖c‖ / b) (hb.mono fun x hx => ?_) rw [div_mul_eq_mul_div, mul_div_assoc] exact le_mul_of_one_le_right (norm_nonneg _) ((one_le_div hb₀).2 hx) theorem IsBigO.trans_tendsto (hfg : f'' =O[l] g'') (hg : Tendsto g'' l (𝓝 0)) : Tendsto f'' l (𝓝 0) := (isLittleO_one_iff ℝ).1 <| hfg.trans_isLittleO <| (isLittleO_one_iff ℝ).2 hg theorem IsLittleO.trans_tendsto (hfg : f'' =o[l] g'') (hg : Tendsto g'' l (𝓝 0)) : Tendsto f'' l (𝓝 0) := hfg.isBigO.trans_tendsto hg /-! ### Multiplication by a constant -/ theorem isBigOWith_const_mul_self (c : R) (f : α → R) (l : Filter α) : IsBigOWith ‖c‖ l (fun x => c * f x) f := isBigOWith_of_le' _ fun _x => norm_mul_le _ _ theorem isBigO_const_mul_self (c : R) (f : α → R) (l : Filter α) : (fun x => c * f x) =O[l] f := (isBigOWith_const_mul_self c f l).isBigO theorem IsBigOWith.const_mul_left {f : α → R} (h : IsBigOWith c l f g) (c' : R) : IsBigOWith (‖c'‖ * c) l (fun x => c' * f x) g := (isBigOWith_const_mul_self c' f l).trans h (norm_nonneg c') theorem IsBigO.const_mul_left {f : α → R} (h : f =O[l] g) (c' : R) : (fun x => c' * f x) =O[l] g := let ⟹_c, hc⟩ := h.isBigOWith (hc.const_mul_left c').isBigO theorem isBigOWith_self_const_mul' (u : RË£) (f : α → R) (l : Filter α) : IsBigOWith ‖(↑u⁻¹ : R)‖ l f fun x => ↑u * f x := (isBigOWith_const_mul_self ↑u⁻¹ (fun x ↩ ↑u * f x) l).congr_left fun x ↩ u.inv_mul_cancel_left (f x) theorem isBigOWith_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : Filter α) : IsBigOWith ‖c‖⁻¹ l f fun x => c * f x := (isBigOWith_self_const_mul' (Units.mk0 c hc) f l).congr_const <| norm_inv c theorem isBigO_self_const_mul' {c : R} (hc : IsUnit c) (f : α → R) (l : Filter α) : f =O[l] fun x => c * f x := let ⟹u, hu⟩ := hc hu ▾ (isBigOWith_self_const_mul' u f l).isBigO theorem isBigO_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : Filter α) : f =O[l] fun x => c * f x := isBigO_self_const_mul' (IsUnit.mk0 c hc) f l theorem isBigO_const_mul_left_iff' {f : α → R} {c : R} (hc : IsUnit c) : (fun x => c * f x) =O[l] g ↔ f =O[l] g := ⟹(isBigO_self_const_mul' hc f l).trans, fun h => h.const_mul_left c⟩ theorem isBigO_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (fun x => c * f x) =O[l] g ↔ f =O[l] g := isBigO_const_mul_left_iff' <| IsUnit.mk0 c hc theorem IsLittleO.const_mul_left {f : α → R} (h : f =o[l] g) (c : R) : (fun x => c * f x) =o[l] g := (isBigO_const_mul_self c f l).trans_isLittleO h theorem isLittleO_const_mul_left_iff' {f : α → R} {c : R} (hc : IsUnit c) : (fun x => c * f x) =o[l] g ↔ f =o[l] g := ⟹(isBigO_self_const_mul' hc f l).trans_isLittleO, fun h => h.const_mul_left c⟩ theorem isLittleO_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (fun x => c * f x) =o[l] g ↔ f =o[l] g := isLittleO_const_mul_left_iff' <| IsUnit.mk0 c hc theorem IsBigOWith.of_const_mul_right {g : α → R} {c : R} (hc' : 0 ≀ c') (h : IsBigOWith c' l f fun x => c * g x) : IsBigOWith (c' * ‖c‖) l f g := h.trans (isBigOWith_const_mul_self c g l) hc' theorem IsBigO.of_const_mul_right {g : α → R} {c : R} (h : f =O[l] fun x => c * g x) : f =O[l] g := let ⟹_c, cnonneg, hc⟩ := h.exists_nonneg (hc.of_const_mul_right cnonneg).isBigO theorem IsBigOWith.const_mul_right' {g : α → R} {u : RË£} {c' : ℝ} (hc' : 0 ≀ c') (h : IsBigOWith c' l f g) : IsBigOWith (c' * ‖(↑u⁻¹ : R)‖) l f fun x => ↑u * g x := h.trans (isBigOWith_self_const_mul' _ _ _) hc' theorem IsBigOWith.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) {c' : ℝ} (hc' : 0 ≀ c') (h : IsBigOWith c' l f g) : IsBigOWith (c' * ‖c‖⁻¹) l f fun x => c * g x := h.trans (isBigOWith_self_const_mul c hc g l) hc' theorem IsBigO.const_mul_right' {g : α → R} {c : R} (hc : IsUnit c) (h : f =O[l] g) : f =O[l] fun x => c * g x := h.trans (isBigO_self_const_mul' hc g l) theorem IsBigO.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : f =O[l] g) : f =O[l] fun x => c * g x := h.const_mul_right' <| IsUnit.mk0 c hc theorem isBigO_const_mul_right_iff' {g : α → R} {c : R} (hc : IsUnit c) : (f =O[l] fun x => c * g x) ↔ f =O[l] g := ⟹fun h => h.of_const_mul_right, fun h => h.const_mul_right' hc⟩ theorem isBigO_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (f =O[l] fun x => c * g x) ↔ f =O[l] g := isBigO_const_mul_right_iff' <| IsUnit.mk0 c hc theorem IsLittleO.of_const_mul_right {g : α → R} {c : R} (h : f =o[l] fun x => c * g x) : f =o[l] g := h.trans_isBigO (isBigO_const_mul_self c g l) theorem IsLittleO.const_mul_right' {g : α → R} {c : R} (hc : IsUnit c) (h : f =o[l] g) : f =o[l] fun x => c * g x := h.trans_isBigO (isBigO_self_const_mul' hc g l) theorem IsLittleO.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : f =o[l] g) : f =o[l] fun x => c * g x := h.const_mul_right' <| IsUnit.mk0 c hc theorem isLittleO_const_mul_right_iff' {g : α → R} {c : R} (hc : IsUnit c) : (f =o[l] fun x => c * g x) ↔ f =o[l] g := ⟹fun h => h.of_const_mul_right, fun h => h.const_mul_right' hc⟩ theorem isLittleO_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (f =o[l] fun x => c * g x) ↔ f =o[l] g := isLittleO_const_mul_right_iff' <| IsUnit.mk0 c hc /-! ### Multiplication -/ theorem IsBigOWith.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} {c₁ c₂ : ℝ} (h₁ : IsBigOWith c₁ l f₁ g₁) (h₂ : IsBigOWith c₂ l f₂ g₂) : IsBigOWith (c₁ * c₂) l (fun x => f₁ x * f₂ x) fun x => g₁ x * g₂ x := by simp only [IsBigOWith_def] at * filter_upwards [h₁, h₂] with _ hx₁ hx₂ apply le_trans (norm_mul_le _ _) convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1 rw [norm_mul, mul_mul_mul_comm] theorem IsBigO.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =O[l] g₁) (h₂ : f₂ =O[l] g₂) : (fun x => f₁ x * f₂ x) =O[l] fun x => g₁ x * g₂ x := let ⟹_c, hc⟩ := h₁.isBigOWith let ⟹_c', hc'⟩ := h₂.isBigOWith (hc.mul hc').isBigO theorem IsBigO.mul_isLittleO {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =O[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := by simp only [IsLittleO_def] at * intro c cpos rcases h₁.exists_pos with ⟹c', c'pos, hc'⟩ exact (hc'.mul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel₀ _ (ne_of_gt c'pos)) theorem IsLittleO.mul_isBigO {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =O[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := by simp only [IsLittleO_def] at * intro c cpos rcases h₂.exists_pos with ⟹c', c'pos, hc'⟩ exact ((h₁ (div_pos cpos c'pos)).mul hc').congr_const (div_mul_cancel₀ _ (ne_of_gt c'pos)) theorem IsLittleO.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := h₁.mul_isBigO h₂.isBigO theorem IsBigOWith.pow' {f : α → R} {g : α → 𝕜} (h : IsBigOWith c l f g) : ∀ n : ℕ, IsBigOWith (Nat.casesOn n ‖(1 : R)‖ fun n => c ^ (n + 1)) l (fun x => f x ^ n) fun x => g x ^ n | 0 => by simpa using isBigOWith_const_const (1 : R) (one_ne_zero' 𝕜) l | 1 => by simpa | n + 2 => by simpa [pow_succ] using (IsBigOWith.pow' h (n + 1)).mul h theorem IsBigOWith.pow [NormOneClass R] {f : α → R} {g : α → 𝕜} (h : IsBigOWith c l f g) : ∀ n : ℕ, IsBigOWith (c ^ n) l (fun x => f x ^ n) fun x => g x ^ n | 0 => by simpa using h.pow' 0 | n + 1 => h.pow' (n + 1) theorem IsBigOWith.of_pow {n : ℕ} {f : α → 𝕜} {g : α → R} (h : IsBigOWith c l (f ^ n) (g ^ n)) (hn : n ≠ 0) (hc : c ≀ c' ^ n) (hc' : 0 ≀ c') : IsBigOWith c' l f g := IsBigOWith.of_bound <| (h.weaken hc).bound.mono fun x hx ↩ le_of_pow_le_pow_left hn (by positivity) <| calc ‖f x‖ ^ n = ‖f x ^ n‖ := (norm_pow _ _).symm _ ≀ c' ^ n * ‖g x ^ n‖ := hx _ ≀ c' ^ n * ‖g x‖ ^ n := by gcongr; exact norm_pow_le' _ hn.bot_lt _ = (c' * ‖g x‖) ^ n := (mul_pow _ _ _).symm theorem IsBigO.pow {f : α → R} {g : α → 𝕜} (h : f =O[l] g) (n : ℕ) : (fun x => f x ^ n) =O[l] fun x => g x ^ n := let ⟹_C, hC⟩ := h.isBigOWith isBigO_iff_isBigOWith.2 ⟹_, hC.pow' n⟩ theorem IsBigO.of_pow {f : α → 𝕜} {g : α → R} {n : ℕ} (hn : n ≠ 0) (h : (f ^ n) =O[l] (g ^ n)) : f =O[l] g := by rcases h.exists_pos with ⟹C, _hC₀, hC⟩ obtain ⟹c : ℝ, hc₀ : 0 ≀ c, hc : C ≀ c ^ n⟩ := ((eventually_ge_atTop _).and <| (tendsto_pow_atTop hn).eventually_ge_atTop C).exists exact (hC.of_pow hn hc hc₀).isBigO theorem IsLittleO.pow {f : α → R} {g : α → 𝕜} (h : f =o[l] g) {n : ℕ} (hn : 0 < n) : (fun x => f x ^ n) =o[l] fun x => g x ^ n := by obtain ⟹n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn.ne'; clear hn induction' n with n ihn · simpa only [Nat.zero_eq, ← Nat.one_eq_succ_zero, pow_one] · convert ihn.mul h <;> simp [pow_succ] theorem IsLittleO.of_pow {f : α → 𝕜} {g : α → R} {n : ℕ} (h : (f ^ n) =o[l] (g ^ n)) (hn : n ≠ 0) : f =o[l] g := IsLittleO.of_isBigOWith fun _c hc => (h.def' <| pow_pos hc _).of_pow hn le_rfl hc.le /-! ### Inverse -/ theorem IsBigOWith.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : IsBigOWith c l f g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : IsBigOWith c l (fun x => (g x)⁻¹) fun x => (f x)⁻¹ := by refine IsBigOWith.of_bound (h.bound.mp (h₀.mono fun x h₀ hle => ?_)) rcases eq_or_ne (f x) 0 with hx | hx · simp only [hx, h₀ hx, inv_zero, norm_zero, mul_zero, le_rfl] · have hc : 0 < c := pos_of_mul_pos_left ((norm_pos_iff.2 hx).trans_le hle) (norm_nonneg _) replace hle := inv_le_inv_of_le (norm_pos_iff.2 hx) hle simpa only [norm_inv, mul_inv, ← div_eq_inv_mul, div_le_iff hc] using hle theorem IsBigO.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : f =O[l] g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : (fun x => (g x)⁻¹) =O[l] fun x => (f x)⁻¹ := let ⟹_c, hc⟩ := h.isBigOWith (hc.inv_rev h₀).isBigO theorem IsLittleO.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : f =o[l] g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : (fun x => (g x)⁻¹) =o[l] fun x => (f x)⁻¹ := IsLittleO.of_isBigOWith fun _c hc => (h.def' hc).inv_rev h₀ /-! ### Scalar multiplication -/ section SMulConst variable [Module R E'] [BoundedSMul R E'] theorem IsBigOWith.const_smul_self (c' : R) : IsBigOWith (‖c'‖) l (fun x => c' • f' x) f' := isBigOWith_of_le' _ fun _ => norm_smul_le _ _ theorem IsBigO.const_smul_self (c' : R) : (fun x => c' • f' x) =O[l] f' := (IsBigOWith.const_smul_self _).isBigO theorem IsBigOWith.const_smul_left (h : IsBigOWith c l f' g) (c' : R) : IsBigOWith (‖c'‖ * c) l (fun x => c' • f' x) g := .trans (.const_smul_self _) h (norm_nonneg _) theorem IsBigO.const_smul_left (h : f' =O[l] g) (c : R) : (c • f') =O[l] g := let ⟹_b, hb⟩ := h.isBigOWith (hb.const_smul_left _).isBigO theorem IsLittleO.const_smul_left (h : f' =o[l] g) (c : R) : (c • f') =o[l] g := (IsBigO.const_smul_self _).trans_isLittleO h variable [Module 𝕜 E'] [BoundedSMul 𝕜 E'] theorem isBigO_const_smul_left {c : 𝕜} (hc : c ≠ 0) : (fun x => c • f' x) =O[l] g ↔ f' =O[l] g := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isBigO_norm_left] simp only [norm_smul] rw [isBigO_const_mul_left_iff cne0, isBigO_norm_left] theorem isLittleO_const_smul_left {c : 𝕜} (hc : c ≠ 0) : (fun x => c • f' x) =o[l] g ↔ f' =o[l] g := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isLittleO_norm_left] simp only [norm_smul] rw [isLittleO_const_mul_left_iff cne0, isLittleO_norm_left] theorem isBigO_const_smul_right {c : 𝕜} (hc : c ≠ 0) : (f =O[l] fun x => c • f' x) ↔ f =O[l] f' := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isBigO_norm_right] simp only [norm_smul] rw [isBigO_const_mul_right_iff cne0, isBigO_norm_right] theorem isLittleO_const_smul_right {c : 𝕜} (hc : c ≠ 0) : (f =o[l] fun x => c • f' x) ↔ f =o[l] f' := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isLittleO_norm_right] simp only [norm_smul] rw [isLittleO_const_mul_right_iff cne0, isLittleO_norm_right] end SMulConst section SMul variable [Module R E'] [BoundedSMul R E'] [Module 𝕜' F'] [BoundedSMul 𝕜' F'] variable {k₁ : α → R} {k₂ : α → 𝕜'} theorem IsBigOWith.smul (h₁ : IsBigOWith c l k₁ k₂) (h₂ : IsBigOWith c' l f' g') : IsBigOWith (c * c') l (fun x => k₁ x • f' x) fun x => k₂ x • g' x := by simp only [IsBigOWith_def] at * filter_upwards [h₁, h₂] with _ hx₁ hx₂ apply le_trans (norm_smul_le _ _) convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1 rw [norm_smul, mul_mul_mul_comm] theorem IsBigO.smul (h₁ : k₁ =O[l] k₂) (h₂ : f' =O[l] g') : (fun x => k₁ x • f' x) =O[l] fun x => k₂ x • g' x := by obtain ⟹c₁, h₁⟩ := h₁.isBigOWith obtain ⟹c₂, h₂⟩ := h₂.isBigOWith exact (h₁.smul h₂).isBigO theorem IsBigO.smul_isLittleO (h₁ : k₁ =O[l] k₂) (h₂ : f' =o[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := by simp only [IsLittleO_def] at * intro c cpos rcases h₁.exists_pos with ⟹c', c'pos, hc'⟩ exact (hc'.smul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel₀ _ (ne_of_gt c'pos)) theorem IsLittleO.smul_isBigO (h₁ : k₁ =o[l] k₂) (h₂ : f' =O[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := by simp only [IsLittleO_def] at * intro c cpos rcases h₂.exists_pos with ⟹c', c'pos, hc'⟩ exact ((h₁ (div_pos cpos c'pos)).smul hc').congr_const (div_mul_cancel₀ _ (ne_of_gt c'pos)) theorem IsLittleO.smul (h₁ : k₁ =o[l] k₂) (h₂ : f' =o[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := h₁.smul_isBigO h₂.isBigO end SMul /-! ### Sum -/ section Sum variable {ι : Type*} {A : ι → α → E'} {C : ι → ℝ} {s : Finset ι} theorem IsBigOWith.sum (h : ∀ i ∈ s, IsBigOWith (C i) l (A i) g) : IsBigOWith (∑ i ∈ s, C i) l (fun x => ∑ i ∈ s, A i x) g := by induction' s using Finset.induction_on with i s is IH · simp only [isBigOWith_zero', Finset.sum_empty, forall_true_iff] · simp only [is, Finset.sum_insert, not_false_iff] exact (h _ (Finset.mem_insert_self i s)).add (IH fun j hj => h _ (Finset.mem_insert_of_mem hj)) theorem IsBigO.sum (h : ∀ i ∈ s, A i =O[l] g) : (fun x => ∑ i ∈ s, A i x) =O[l] g := by simp only [IsBigO_def] at * choose! C hC using h exact ⟹_, IsBigOWith.sum hC⟩ theorem IsLittleO.sum (h : ∀ i ∈ s, A i =o[l] g') : (fun x => ∑ i ∈ s, A i x) =o[l] g' := by induction' s using Finset.induction_on with i s is IH · simp only [isLittleO_zero, Finset.sum_empty, forall_true_iff] · simp only [is, Finset.sum_insert, not_false_iff] exact (h _ (Finset.mem_insert_self i s)).add (IH fun j hj => h _ (Finset.mem_insert_of_mem hj)) end Sum /-! ### Relation between `f = o(g)` and `f / g → 0` -/ theorem IsLittleO.tendsto_div_nhds_zero {f g : α → 𝕜} (h : f =o[l] g) : Tendsto (fun x => f x / g x) l (𝓝 0) := (isLittleO_one_iff 𝕜).mp <| by calc (fun x => f x / g x) =o[l] fun x => g x / g x := by simpa only [div_eq_mul_inv] using h.mul_isBigO (isBigO_refl _ _) _ =O[l] fun _x => (1 : 𝕜) := isBigO_of_le _ fun x => by simp [div_self_le_one] theorem IsLittleO.tendsto_inv_smul_nhds_zero [Module 𝕜 E'] [BoundedSMul 𝕜 E'] {f : α → E'} {g : α → 𝕜} {l : Filter α} (h : f =o[l] g) : Tendsto (fun x => (g x)⁻¹ • f x) l (𝓝 0) := by simpa only [div_eq_inv_mul, ← norm_inv, ← norm_smul, ← tendsto_zero_iff_norm_tendsto_zero] using h.norm_norm.tendsto_div_nhds_zero theorem isLittleO_iff_tendsto' {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) : f =o[l] g ↔ Tendsto (fun x => f x / g x) l (𝓝 0) := ⟹IsLittleO.tendsto_div_nhds_zero, fun h => (((isLittleO_one_iff _).mpr h).mul_isBigO (isBigO_refl g l)).congr' (hgf.mono fun _x => div_mul_cancel_of_imp) (eventually_of_forall fun _x => one_mul _)⟩ theorem isLittleO_iff_tendsto {f g : α → 𝕜} (hgf : ∀ x, g x = 0 → f x = 0) : f =o[l] g ↔ Tendsto (fun x => f x / g x) l (𝓝 0) := isLittleO_iff_tendsto' (eventually_of_forall hgf) alias ⟹_, isLittleO_of_tendsto'⟩ := isLittleO_iff_tendsto' alias ⟹_, isLittleO_of_tendsto⟩ := isLittleO_iff_tendsto theorem isLittleO_const_left_of_ne {c : E''} (hc : c ≠ 0) : (fun _x => c) =o[l] g ↔ Tendsto (fun x => ‖g x‖) l atTop := by simp only [← isLittleO_one_left_iff ℝ] exact ⟹(isBigO_const_const (1 : ℝ) hc l).trans_isLittleO, (isBigO_const_one ℝ c l).trans_isLittleO⟩ @[simp] theorem isLittleO_const_left {c : E''} : (fun _x => c) =o[l] g'' ↔ c = 0 √ Tendsto (norm ∘ g'') l atTop := by rcases eq_or_ne c 0 with (rfl | hc) · simp only [isLittleO_zero, eq_self_iff_true, true_or_iff] · simp only [hc, false_or_iff, isLittleO_const_left_of_ne hc]; rfl @[simp 1001] -- Porting note: increase priority so that this triggers before `isLittleO_const_left` theorem isLittleO_const_const_iff [NeBot l] {d : E''} {c : F''} : ((fun _x => d) =o[l] fun _x => c) ↔ d = 0 := by have : ¬Tendsto (Function.const α ‖c‖) l atTop := not_tendsto_atTop_of_tendsto_nhds tendsto_const_nhds simp only [isLittleO_const_left, or_iff_left_iff_imp] exact fun h => (this h).elim @[simp] theorem isLittleO_pure {x} : f'' =o[pure x] g'' ↔ f'' x = 0 := calc f'' =o[pure x] g'' ↔ (fun _y : α => f'' x) =o[pure x] fun _ => g'' x := isLittleO_congr rfl rfl _ ↔ f'' x = 0 := isLittleO_const_const_iff theorem isLittleO_const_id_cobounded (c : F'') : (fun _ => c) =o[Bornology.cobounded E''] id := isLittleO_const_left.2 <| .inr tendsto_norm_cobounded_atTop theorem isLittleO_const_id_atTop (c : E'') : (fun _x : ℝ => c) =o[atTop] id := isLittleO_const_left.2 <| Or.inr tendsto_abs_atTop_atTop theorem isLittleO_const_id_atBot (c : E'') : (fun _x : ℝ => c) =o[atBot] id := isLittleO_const_left.2 <| Or.inr tendsto_abs_atBot_atTop /-! ### Eventually (u / v) * v = u If `u` and `v` are linked by an `IsBigOWith` relation, then we eventually have `(u / v) * v = u`, even if `v` vanishes. -/ section EventuallyMulDivCancel variable {u v : α → 𝕜} theorem IsBigOWith.eventually_mul_div_cancel (h : IsBigOWith c l u v) : u / v * v =á¶ [l] u := Eventually.mono h.bound fun y hy => div_mul_cancel_of_imp fun hv => by simpa [hv] using hy /-- If `u = O(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/ theorem IsBigO.eventually_mul_div_cancel (h : u =O[l] v) : u / v * v =á¶ [l] u := let ⟹_c, hc⟩ := h.isBigOWith hc.eventually_mul_div_cancel /-- If `u = o(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/ theorem IsLittleO.eventually_mul_div_cancel (h : u =o[l] v) : u / v * v =á¶ [l] u := (h.forall_isBigOWith zero_lt_one).eventually_mul_div_cancel end EventuallyMulDivCancel /-! ### Equivalent definitions of the form `∃ φ, u =á¶ [l] φ * v` in a `NormedField`. -/ section ExistsMulEq variable {u v : α → 𝕜} /-- If `‖φ‖` is eventually bounded by `c`, and `u =á¶ [l] φ * v`, then we have `IsBigOWith c u v l`. This does not require any assumptions on `c`, which is why we keep this version along with `IsBigOWith_iff_exists_eq_mul`. -/ theorem isBigOWith_of_eq_mul {u v : α → R} (φ : α → R) (hφ : ∀ᶠ x in l, ‖φ x‖ ≀ c) (h : u =á¶ [l] φ * v) : IsBigOWith c l u v := by simp only [IsBigOWith_def] refine h.symm.rw (fun x a => ‖a‖ ≀ c * ‖v x‖) (hφ.mono fun x hx => ?_) simp only [Pi.mul_apply] refine (norm_mul_le _ _).trans ?_ gcongr theorem isBigOWith_iff_exists_eq_mul (hc : 0 ≀ c) : IsBigOWith c l u v ↔ ∃ φ : α → 𝕜, (∀ᶠ x in l, ‖φ x‖ ≀ c) ∧ u =á¶ [l] φ * v := by constructor · intro h use fun x => u x / v x refine ⟹Eventually.mono h.bound fun y hy => ?_, h.eventually_mul_div_cancel.symm⟩ simpa using div_le_of_nonneg_of_le_mul (norm_nonneg _) hc hy · rintro ⟚φ, hφ, h⟩ exact isBigOWith_of_eq_mul φ hφ h theorem IsBigOWith.exists_eq_mul (h : IsBigOWith c l u v) (hc : 0 ≀ c) : ∃ φ : α → 𝕜, (∀ᶠ x in l, ‖φ x‖ ≀ c) ∧ u =á¶ [l] φ * v := (isBigOWith_iff_exists_eq_mul hc).mp h theorem isBigO_iff_exists_eq_mul : u =O[l] v ↔ ∃ φ : α → 𝕜, l.IsBoundedUnder (· ≀ ·) (norm ∘ φ) ∧ u =á¶ [l] φ * v := by constructor · rintro h rcases h.exists_nonneg with ⟹c, hnnc, hc⟩ rcases hc.exists_eq_mul hnnc with ⟚φ, hφ, huvφ⟩ exact ⟚φ, ⟹c, hφ⟩, huvφ⟩ · rintro ⟚φ, ⟹c, hφ⟩, huvφ⟩ exact isBigO_iff_isBigOWith.2 ⟹c, isBigOWith_of_eq_mul φ hφ huvφ⟩ alias ⟹IsBigO.exists_eq_mul, _⟩ := isBigO_iff_exists_eq_mul theorem isLittleO_iff_exists_eq_mul : u =o[l] v ↔ ∃ φ : α → 𝕜, Tendsto φ l (𝓝 0) ∧ u =á¶ [l] φ * v := by constructor · exact fun h => ⟹fun x => u x / v x, h.tendsto_div_nhds_zero, h.eventually_mul_div_cancel.symm⟩ · simp only [IsLittleO_def] rintro ⟚φ, hφ, huvφ⟩ c hpos rw [NormedAddCommGroup.tendsto_nhds_zero] at hφ exact isBigOWith_of_eq_mul _ ((hφ c hpos).mono fun x => le_of_lt) huvφ alias ⟹IsLittleO.exists_eq_mul, _⟩ := isLittleO_iff_exists_eq_mul end ExistsMulEq /-! ### Miscellaneous lemmas -/ theorem div_isBoundedUnder_of_isBigO {α : Type*} {l : Filter α} {f g : α → 𝕜} (h : f =O[l] g) : IsBoundedUnder (· ≀ ·) l fun x => ‖f x / g x‖ := by obtain ⟹c, h₀, hc⟩ := h.exists_nonneg refine ⟹c, eventually_map.2 (hc.bound.mono fun x hx => ?_)⟩ rw [norm_div] exact div_le_of_nonneg_of_le_mul (norm_nonneg _) h₀ hx theorem isBigO_iff_div_isBoundedUnder {α : Type*} {l : Filter α} {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) : f =O[l] g ↔ IsBoundedUnder (· ≀ ·) l fun x => ‖f x / g x‖ := by refine ⟹div_isBoundedUnder_of_isBigO, fun h => ?_⟩ obtain ⟹c, hc⟩ := h simp only [eventually_map, norm_div] at hc refine IsBigO.of_bound c (hc.mp <| hgf.mono fun x hx₁ hx₂ => ?_) by_cases hgx : g x = 0 · simp [hx₁ hgx, hgx] · exact (div_le_iff (norm_pos_iff.2 hgx)).mp hx₂ theorem isBigO_of_div_tendsto_nhds {α : Type*} {l : Filter α} {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) (c : 𝕜) (H : Filter.Tendsto (f / g) l (𝓝 c)) : f =O[l] g := (isBigO_iff_div_isBoundedUnder hgf).2 <| H.norm.isBoundedUnder_le theorem IsLittleO.tendsto_zero_of_tendsto {α E 𝕜 : Type*} [NormedAddCommGroup E] [NormedField 𝕜] {u : α → E} {v : α → 𝕜} {l : Filter α} {y : 𝕜} (huv : u =o[l] v) (hv : Tendsto v l (𝓝 y)) : Tendsto u l (𝓝 0) := by suffices h : u =o[l] fun _x => (1 : 𝕜) by rwa [isLittleO_one_iff] at h exact huv.trans_isBigO (hv.isBigO_one 𝕜) theorem isLittleO_pow_pow {m n : ℕ} (h : m < n) : (fun x : 𝕜 => x ^ n) =o[𝓝 0] fun x => x ^ m := by rcases lt_iff_exists_add.1 h with ⟹p, hp0 : 0 < p, rfl⟩ suffices (fun x : 𝕜 => x ^ m * x ^ p) =o[𝓝 0] fun x => x ^ m * 1 ^ p by simpa only [pow_add, one_pow, mul_one] exact IsBigO.mul_isLittleO (isBigO_refl _ _) (IsLittleO.pow ((isLittleO_one_iff _).2 tendsto_id) hp0) theorem isLittleO_norm_pow_norm_pow {m n : ℕ} (h : m < n) : (fun x : E' => ‖x‖ ^ n) =o[𝓝 0] fun x => ‖x‖ ^ m := (isLittleO_pow_pow h).comp_tendsto tendsto_norm_zero theorem isLittleO_pow_id {n : ℕ} (h : 1 < n) : (fun x : 𝕜 => x ^ n) =o[𝓝 0] fun x => x := by convert isLittleO_pow_pow h (𝕜 := 𝕜) simp only [pow_one] theorem isLittleO_norm_pow_id {n : ℕ} (h : 1 < n) : (fun x : E' => ‖x‖ ^ n) =o[𝓝 0] fun x => x := by have := @isLittleO_norm_pow_norm_pow E' _ _ _ h simp only [pow_one] at this exact isLittleO_norm_right.mp this theorem IsBigO.eq_zero_of_norm_pow_within {f : E'' → F''} {s : Set E''} {x₀ : E''} {n : ℕ} (h : f =O[𝓝[s] x₀] fun x => ‖x - x₀‖ ^ n) (hx₀ : x₀ ∈ s) (hn : n ≠ 0) : f x₀ = 0 := mem_of_mem_nhdsWithin hx₀ h.eq_zero_imp <| by simp_rw [sub_self, norm_zero, zero_pow hn] theorem IsBigO.eq_zero_of_norm_pow {f : E'' → F''} {x₀ : E''} {n : ℕ} (h : f =O[𝓝 x₀] fun x => ‖x - x₀‖ ^ n) (hn : n ≠ 0) : f x₀ = 0 := by rw [← nhdsWithin_univ] at h exact h.eq_zero_of_norm_pow_within (mem_univ _) hn theorem isLittleO_pow_sub_pow_sub (x₀ : E') {n m : ℕ} (h : n < m) : (fun x => ‖x - x₀‖ ^ m) =o[𝓝 x₀] fun x => ‖x - x₀‖ ^ n := haveI : Tendsto (fun x => ‖x - x₀‖) (𝓝 x₀) (𝓝 0) := by apply tendsto_norm_zero.comp rw [← sub_self x₀] exact tendsto_id.sub tendsto_const_nhds (isLittleO_pow_pow h).comp_tendsto this theorem isLittleO_pow_sub_sub (x₀ : E') {m : ℕ} (h : 1 < m) : (fun x => ‖x - x₀‖ ^ m) =o[𝓝 x₀] fun x => x - x₀ := by simpa only [isLittleO_norm_right, pow_one] using isLittleO_pow_sub_pow_sub x₀ h theorem IsBigOWith.right_le_sub_of_lt_one {f₁ f₂ : α → E'} (h : IsBigOWith c l f₁ f₂) (hc : c < 1) : IsBigOWith (1 / (1 - c)) l f₂ fun x => f₂ x - f₁ x := IsBigOWith.of_bound <| mem_of_superset h.bound fun x hx => by simp only [mem_setOf_eq] at hx ⊢ rw [mul_comm, one_div, ← div_eq_mul_inv, _root_.le_div_iff, mul_sub, mul_one, mul_comm] · exact le_trans (sub_le_sub_left hx _) (norm_sub_norm_le _ _) · exact sub_pos.2 hc theorem IsBigOWith.right_le_add_of_lt_one {f₁ f₂ : α → E'} (h : IsBigOWith c l f₁ f₂) (hc : c < 1) : IsBigOWith (1 / (1 - c)) l f₂ fun x => f₁ x + f₂ x := (h.neg_right.right_le_sub_of_lt_one hc).neg_right.of_neg_left.congr rfl (fun x ↩ rfl) fun x ↩ by rw [neg_sub, sub_neg_eq_add] @[deprecated (since := "2024-01-31")] alias IsBigOWith.right_le_sub_of_lt_1 := IsBigOWith.right_le_sub_of_lt_one @[deprecated (since := "2024-01-31")] alias IsBigOWith.right_le_add_of_lt_1 := IsBigOWith.right_le_add_of_lt_one theorem IsLittleO.right_isBigO_sub {f₁ f₂ : α → E'} (h : f₁ =o[l] f₂) : f₂ =O[l] fun x => f₂ x - f₁ x := ((h.def' one_half_pos).right_le_sub_of_lt_one one_half_lt_one).isBigO theorem IsLittleO.right_isBigO_add {f₁ f₂ : α → E'} (h : f₁ =o[l] f₂) : f₂ =O[l] fun x => f₁ x + f₂ x := ((h.def' one_half_pos).right_le_add_of_lt_one one_half_lt_one).isBigO theorem IsLittleO.right_isBigO_add' {f₁ f₂ : α → E'} (h : f₁ =o[l] f₂) : f₂ =O[l] (f₂ + f₁) := add_comm f₁ f₂ ▾ h.right_isBigO_add /-- If `f x = O(g x)` along `cofinite`, then there exists a positive constant `C` such that `‖f x‖ ≀ C * ‖g x‖` whenever `g x ≠ 0`. -/ theorem bound_of_isBigO_cofinite (h : f =O[cofinite] g'') : ∃ C > 0, ∀ ⊃x⩄, g'' x ≠ 0 → ‖f x‖ ≀ C * ‖g'' x‖ := by rcases h.exists_pos with ⟹C, C₀, hC⟩ rw [IsBigOWith_def, eventually_cofinite] at hC rcases (hC.toFinset.image fun x => ‖f x‖ / ‖g'' x‖).exists_le with ⟹C', hC'⟩ have : ∀ x, C * ‖g'' x‖ < ‖f x‖ → ‖f x‖ / ‖g'' x‖ ≀ C' := by simpa using hC' refine ⟹max C C', lt_max_iff.2 (Or.inl C₀), fun x h₀ => ?_⟩ rw [max_mul_of_nonneg _ _ (norm_nonneg _), le_max_iff, or_iff_not_imp_left, not_le] exact fun hx => (div_le_iff (norm_pos_iff.2 h₀)).1 (this _ hx) theorem isBigO_cofinite_iff (h : ∀ x, g'' x = 0 → f'' x = 0) : f'' =O[cofinite] g'' ↔ ∃ C, ∀ x, ‖f'' x‖ ≀ C * ‖g'' x‖ := ⟹fun h' => let ⟹C, _C₀, hC⟩ := bound_of_isBigO_cofinite h' ⟹C, fun x => if hx : g'' x = 0 then by simp [h _ hx, hx] else hC hx⟩, fun h => (isBigO_top.2 h).mono le_top⟩ theorem bound_of_isBigO_nat_atTop {f : ℕ → E} {g'' : ℕ → E''} (h : f =O[atTop] g'') : ∃ C > 0, ∀ ⊃x⩄, g'' x ≠ 0 → ‖f x‖ ≀ C * ‖g'' x‖ := bound_of_isBigO_cofinite <| by rwa [Nat.cofinite_eq_atTop] theorem isBigO_nat_atTop_iff {f : ℕ → E''} {g : ℕ → F''} (h : ∀ x, g x = 0 → f x = 0) : f =O[atTop] g ↔ ∃ C, ∀ x, ‖f x‖ ≀ C * ‖g x‖ := by rw [← Nat.cofinite_eq_atTop, isBigO_cofinite_iff h] theorem isBigO_one_nat_atTop_iff {f : ℕ → E''} : f =O[atTop] (fun _n => 1 : ℕ → ℝ) ↔ ∃ C, ∀ n, ‖f n‖ ≀ C := Iff.trans (isBigO_nat_atTop_iff fun n h => (one_ne_zero h).elim) <| by simp only [norm_one, mul_one] theorem isBigOWith_pi {ι : Type*} [Fintype ι] {E' : ι → Type*} [∀ i, NormedAddCommGroup (E' i)] {f : α → ∀ i, E' i} {C : ℝ} (hC : 0 ≀ C) : IsBigOWith C l f g' ↔ ∀ i, IsBigOWith C l (fun x => f x i) g' := by have : ∀ x, 0 ≀ C * ‖g' x‖ := fun x => mul_nonneg hC (norm_nonneg _) simp only [isBigOWith_iff, pi_norm_le_iff_of_nonneg (this _), eventually_all] @[simp] theorem isBigO_pi {ι : Type*} [Fintype ι] {E' : ι → Type*} [∀ i, NormedAddCommGroup (E' i)] {f : α → ∀ i, E' i} : f =O[l] g' ↔ ∀ i, (fun x => f x i) =O[l] g' := by simp only [isBigO_iff_eventually_isBigOWith, ← eventually_all] exact eventually_congr (eventually_atTop.2 ⟹0, fun c => isBigOWith_pi⟩) @[simp] theorem isLittleO_pi {ι : Type*} [Fintype ι] {E' : ι → Type*} [∀ i, NormedAddCommGroup (E' i)] {f : α → ∀ i, E' i} : f =o[l] g' ↔ ∀ i, (fun x => f x i) =o[l] g' := by simp (config := { contextual := true }) only [IsLittleO_def, isBigOWith_pi, le_of_lt] exact ⟹fun h i c hc => h hc i, fun h c hc i => h i hc⟩ theorem IsBigO.natCast_atTop {R : Type*} [StrictOrderedSemiring R] [Archimedean R] {f : R → E} {g : R → F} (h : f =O[atTop] g) : (fun (n : ℕ) => f n) =O[atTop] (fun n => g n) := IsBigO.comp_tendsto h tendsto_natCast_atTop_atTop @[deprecated (since := "2024-04-17")] alias IsBigO.nat_cast_atTop := IsBigO.natCast_atTop theorem IsLittleO.natCast_atTop {R : Type*} [StrictOrderedSemiring R] [Archimedean R] {f : R → E} {g : R → F} (h : f =o[atTop] g) : (fun (n : ℕ) => f n) =o[atTop] (fun n => g n) := IsLittleO.comp_tendsto h tendsto_natCast_atTop_atTop @[deprecated (since := "2024-04-17")] alias IsLittleO.nat_cast_atTop := IsLittleO.natCast_atTop theorem isBigO_atTop_iff_eventually_exists {α : Type*} [SemilatticeSup α] [Nonempty α] {f : α → E} {g : α → F} : f =O[atTop] g ↔ ∀ᶠ n₀ in atTop, ∃ c, ∀ n ≥ n₀, ‖f n‖ ≀ c * ‖g n‖ := by rw [isBigO_iff, exists_eventually_atTop] theorem isBigO_atTop_iff_eventually_exists_pos {α : Type*} [SemilatticeSup α] [Nonempty α] {f : α → G} {g : α → G'} : f =O[atTop] g ↔ ∀ᶠ n₀ in atTop, ∃ c > 0, ∀ n ≥ n₀, c * ‖f n‖ ≀ ‖g n‖ := by simp_rw [isBigO_iff'', ← exists_prop, Subtype.exists', exists_eventually_atTop] end Asymptotics open Asymptotics theorem summable_of_isBigO {ι E} [SeminormedAddCommGroup E] [CompleteSpace E] {f : ι → E} {g : ι → ℝ} (hg : Summable g) (h : f =O[cofinite] g) : Summable f := let ⟹C, hC⟩ := h.isBigOWith .of_norm_bounded_eventually (fun x => C * ‖g x‖) (hg.abs.mul_left _) hC.bound theorem summable_of_isBigO_nat {E} [SeminormedAddCommGroup E] [CompleteSpace E] {f : ℕ → E} {g : ℕ → ℝ} (hg : Summable g) (h : f =O[atTop] g) : Summable f := summable_of_isBigO hg <| Nat.cofinite_eq_atTop.symm ▾ h lemma Asymptotics.IsBigO.comp_summable_norm {ι E F : Type*} [SeminormedAddCommGroup E] [SeminormedAddCommGroup F] {f : E → F} {g : ι → E} (hf : f =O[𝓝 0] id) (hg : Summable (‖g ·‖)) : Summable (‖f <| g ·‖) := summable_of_isBigO hg <| hf.norm_norm.comp_tendsto <| tendsto_zero_iff_norm_tendsto_zero.2 hg.tendsto_cofinite_zero namespace PartialHomeomorph variable {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] variable {E : Type*} [Norm E] {F : Type*} [Norm F] /-- Transfer `IsBigOWith` over a `PartialHomeomorph`. -/ theorem isBigOWith_congr (e : PartialHomeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} {C : ℝ} : IsBigOWith C (𝓝 b) f g ↔ IsBigOWith C (𝓝 (e.symm b)) (f ∘ e) (g ∘ e) := ⟹fun h => h.comp_tendsto <| by have := e.continuousAt (e.map_target hb) rwa [ContinuousAt, e.rightInvOn hb] at this, fun h => (h.comp_tendsto (e.continuousAt_symm hb)).congr' rfl ((e.eventually_right_inverse hb).mono fun x hx => congr_arg f hx) ((e.eventually_right_inverse hb).mono fun x hx => congr_arg g hx)⟩ /-- Transfer `IsBigO` over a `PartialHomeomorph`. -/ theorem isBigO_congr (e : PartialHomeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} : f =O[𝓝 b] g ↔ (f ∘ e) =O[𝓝 (e.symm b)] (g ∘ e) := by simp only [IsBigO_def] exact exists_congr fun C => e.isBigOWith_congr hb /-- Transfer `IsLittleO` over a `PartialHomeomorph`. -/ theorem isLittleO_congr (e : PartialHomeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} : f =o[𝓝 b] g ↔ (f ∘ e) =o[𝓝 (e.symm b)] (g ∘ e) := by simp only [IsLittleO_def] exact forall₂_congr fun c _hc => e.isBigOWith_congr hb end PartialHomeomorph namespace Homeomorph variable {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] variable {E : Type*} [Norm E] {F : Type*} [Norm F] open Asymptotics /-- Transfer `IsBigOWith` over a `Homeomorph`. -/ theorem isBigOWith_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} {C : ℝ} : IsBigOWith C (𝓝 b) f g ↔ IsBigOWith C (𝓝 (e.symm b)) (f ∘ e) (g ∘ e) := e.toPartialHomeomorph.isBigOWith_congr trivial /-- Transfer `IsBigO` over a `Homeomorph`. -/ theorem isBigO_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} : f =O[𝓝 b] g ↔ (f ∘ e) =O[𝓝 (e.symm b)] (g ∘ e) := by simp only [IsBigO_def] exact exists_congr fun C => e.isBigOWith_congr /-- Transfer `IsLittleO` over a `Homeomorph`. -/ theorem isLittleO_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} : f =o[𝓝 b] g ↔ (f ∘ e) =o[𝓝 (e.symm b)] (g ∘ e) := by simp only [IsLittleO_def] exact forall₂_congr fun c _hc => e.isBigOWith_congr end Homeomorph
Analysis\Asymptotics\SpecificAsymptotics.lean
/- Copyright (c) 2021 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Analysis.Normed.Order.Basic import Mathlib.Analysis.Asymptotics.Asymptotics import Mathlib.Analysis.Normed.Module.Basic /-! # A collection of specific asymptotic results This file contains specific lemmas about asymptotics which don't have their place in the general theory developed in `Mathlib.Analysis.Asymptotics.Asymptotics`. -/ open Filter Asymptotics open Topology section NormedField /-- If `f : 𝕜 → E` is bounded in a punctured neighborhood of `a`, then `f(x) = o((x - a)⁻¹)` as `x → a`, `x ≠ a`. -/ theorem Filter.IsBoundedUnder.isLittleO_sub_self_inv {𝕜 E : Type*} [NormedField 𝕜] [Norm E] {a : 𝕜} {f : 𝕜 → E} (h : IsBoundedUnder (· ≀ ·) (𝓝[≠] a) (norm ∘ f)) : f =o[𝓝[≠] a] fun x => (x - a)⁻¹ := by refine (h.isBigO_const (one_ne_zero' ℝ)).trans_isLittleO (isLittleO_const_left.2 <| Or.inr ?_) simp only [(· ∘ ·), norm_inv] exact (tendsto_norm_sub_self_punctured_nhds a).inv_tendsto_zero end NormedField section LinearOrderedField variable {𝕜 : Type*} [LinearOrderedField 𝕜] theorem pow_div_pow_eventuallyEq_atTop {p q : ℕ} : (fun x : 𝕜 => x ^ p / x ^ q) =á¶ [atTop] fun x => x ^ ((p : â„€) - q) := by apply (eventually_gt_atTop (0 : 𝕜)).mono fun x hx => _ intro x hx simp [zpow_sub₀ hx.ne'] theorem pow_div_pow_eventuallyEq_atBot {p q : ℕ} : (fun x : 𝕜 => x ^ p / x ^ q) =á¶ [atBot] fun x => x ^ ((p : â„€) - q) := by apply (eventually_lt_atBot (0 : 𝕜)).mono fun x hx => _ intro x hx simp [zpow_sub₀ hx.ne] theorem tendsto_pow_div_pow_atTop_atTop {p q : ℕ} (hpq : q < p) : Tendsto (fun x : 𝕜 => x ^ p / x ^ q) atTop atTop := by rw [tendsto_congr' pow_div_pow_eventuallyEq_atTop] apply tendsto_zpow_atTop_atTop omega theorem tendsto_pow_div_pow_atTop_zero [TopologicalSpace 𝕜] [OrderTopology 𝕜] {p q : ℕ} (hpq : p < q) : Tendsto (fun x : 𝕜 => x ^ p / x ^ q) atTop (𝓝 0) := by rw [tendsto_congr' pow_div_pow_eventuallyEq_atTop] apply tendsto_zpow_atTop_zero omega end LinearOrderedField section NormedLinearOrderedField variable {𝕜 : Type*} [NormedLinearOrderedField 𝕜] theorem Asymptotics.isLittleO_pow_pow_atTop_of_lt [OrderTopology 𝕜] {p q : ℕ} (hpq : p < q) : (fun x : 𝕜 => x ^ p) =o[atTop] fun x => x ^ q := by refine (isLittleO_iff_tendsto' ?_).mpr (tendsto_pow_div_pow_atTop_zero hpq) exact (eventually_gt_atTop 0).mono fun x hx hxq => (pow_ne_zero q hx.ne' hxq).elim theorem Asymptotics.IsBigO.trans_tendsto_norm_atTop {α : Type*} {u v : α → 𝕜} {l : Filter α} (huv : u =O[l] v) (hu : Tendsto (fun x => ‖u x‖) l atTop) : Tendsto (fun x => ‖v x‖) l atTop := by rcases huv.exists_pos with ⟹c, hc, hcuv⟩ rw [IsBigOWith] at hcuv convert Tendsto.atTop_div_const hc (tendsto_atTop_mono' l hcuv hu) rw [mul_div_cancel_left₀ _ hc.ne.symm] end NormedLinearOrderedField section Real open Finset theorem Asymptotics.IsLittleO.sum_range {α : Type*} [NormedAddCommGroup α] {f : ℕ → α} {g : ℕ → ℝ} (h : f =o[atTop] g) (hg : 0 ≀ g) (h'g : Tendsto (fun n => ∑ i ∈ range n, g i) atTop atTop) : (fun n => ∑ i ∈ range n, f i) =o[atTop] fun n => ∑ i ∈ range n, g i := by have A : ∀ i, ‖g i‖ = g i := fun i => Real.norm_of_nonneg (hg i) have B : ∀ n, ‖∑ i ∈ range n, g i‖ = ∑ i ∈ range n, g i := fun n => by rwa [Real.norm_eq_abs, abs_sum_of_nonneg'] apply isLittleO_iff.2 fun ε εpos => _ intro ε εpos obtain ⟹N, hN⟩ : ∃ N : ℕ, ∀ b : ℕ, N ≀ b → ‖f b‖ ≀ ε / 2 * g b := by simpa only [A, eventually_atTop] using isLittleO_iff.mp h (half_pos εpos) have : (fun _ : ℕ => ∑ i ∈ range N, f i) =o[atTop] fun n : ℕ => ∑ i ∈ range n, g i := by apply isLittleO_const_left.2 exact Or.inr (h'g.congr fun n => (B n).symm) filter_upwards [isLittleO_iff.1 this (half_pos εpos), Ici_mem_atTop N] with n hn Nn calc ‖∑ i ∈ range n, f i‖ = ‖(∑ i ∈ range N, f i) + ∑ i ∈ Ico N n, f i‖ := by rw [sum_range_add_sum_Ico _ Nn] _ ≀ ‖∑ i ∈ range N, f i‖ + ‖∑ i ∈ Ico N n, f i‖ := norm_add_le _ _ _ ≀ ‖∑ i ∈ range N, f i‖ + ∑ i ∈ Ico N n, ε / 2 * g i := (add_le_add le_rfl (norm_sum_le_of_le _ fun i hi => hN _ (mem_Ico.1 hi).1)) _ ≀ ‖∑ i ∈ range N, f i‖ + ∑ i ∈ range n, ε / 2 * g i := by gcongr apply sum_le_sum_of_subset_of_nonneg · rw [range_eq_Ico] exact Ico_subset_Ico (zero_le _) le_rfl · intro i _ _ exact mul_nonneg (half_pos εpos).le (hg i) _ ≀ ε / 2 * ‖∑ i ∈ range n, g i‖ + ε / 2 * ∑ i ∈ range n, g i := by rw [← mul_sum]; gcongr _ = ε * ‖∑ i ∈ range n, g i‖ := by simp only [B] ring theorem Asymptotics.isLittleO_sum_range_of_tendsto_zero {α : Type*} [NormedAddCommGroup α] {f : ℕ → α} (h : Tendsto f atTop (𝓝 0)) : (fun n => ∑ i ∈ range n, f i) =o[atTop] fun n => (n : ℝ) := by have := ((isLittleO_one_iff ℝ).2 h).sum_range fun i => zero_le_one simp only [sum_const, card_range, Nat.smul_one_eq_cast] at this exact this tendsto_natCast_atTop_atTop /-- The Cesaro average of a converging sequence converges to the same limit. -/ theorem Filter.Tendsto.cesaro_smul {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {u : ℕ → E} {l : E} (h : Tendsto u atTop (𝓝 l)) : Tendsto (fun n : ℕ => (n⁻¹ : ℝ) • ∑ i ∈ range n, u i) atTop (𝓝 l) := by rw [← tendsto_sub_nhds_zero_iff, ← isLittleO_one_iff ℝ] have := Asymptotics.isLittleO_sum_range_of_tendsto_zero (tendsto_sub_nhds_zero_iff.2 h) apply ((isBigO_refl (fun n : ℕ => (n : ℝ)⁻¹) atTop).smul_isLittleO this).congr' _ _ · filter_upwards [Ici_mem_atTop 1] with n npos have nposℝ : (0 : ℝ) < n := Nat.cast_pos.2 npos simp only [smul_sub, sum_sub_distrib, sum_const, card_range, sub_right_inj] rw [← Nat.cast_smul_eq_nsmul ℝ, smul_smul, inv_mul_cancel nposℝ.ne', one_smul] · filter_upwards [Ici_mem_atTop 1] with n npos have nposℝ : (0 : ℝ) < n := Nat.cast_pos.2 npos rw [Algebra.id.smul_eq_mul, inv_mul_cancel nposℝ.ne'] /-- The Cesaro average of a converging sequence converges to the same limit. -/ theorem Filter.Tendsto.cesaro {u : ℕ → ℝ} {l : ℝ} (h : Tendsto u atTop (𝓝 l)) : Tendsto (fun n : ℕ => (n⁻¹ : ℝ) * ∑ i ∈ range n, u i) atTop (𝓝 l) := h.cesaro_smul end Real
Analysis\Asymptotics\SuperpolynomialDecay.lean
/- Copyright (c) 2021 Devon Tuma. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Devon Tuma -/ import Mathlib.Algebra.Polynomial.Eval import Mathlib.Analysis.Asymptotics.Asymptotics import Mathlib.Analysis.Normed.Order.Basic import Mathlib.Topology.Algebra.Order.LiminfLimsup /-! # Super-Polynomial Function Decay This file defines a predicate `Asymptotics.SuperpolynomialDecay f` for a function satisfying one of following equivalent definitions (The definition is in terms of the first condition): * `x ^ n * f` tends to `𝓝 0` for all (or sufficiently large) naturals `n` * `|x ^ n * f|` tends to `𝓝 0` for all naturals `n` (`superpolynomialDecay_iff_abs_tendsto_zero`) * `|x ^ n * f|` is bounded for all naturals `n` (`superpolynomialDecay_iff_abs_isBoundedUnder`) * `f` is `o(x ^ c)` for all integers `c` (`superpolynomialDecay_iff_isLittleO`) * `f` is `O(x ^ c)` for all integers `c` (`superpolynomialDecay_iff_isBigO`) These conditions are all equivalent to conditions in terms of polynomials, replacing `x ^ c` with `p(x)` or `p(x)⁻¹` as appropriate, since asymptotically `p(x)` behaves like `X ^ p.natDegree`. These further equivalences are not proven in mathlib but would be good future projects. The definition of superpolynomial decay for `f : α → β` is relative to a parameter `k : α → β`. Super-polynomial decay then means `f x` decays faster than `(k x) ^ c` for all integers `c`. Equivalently `f x` decays faster than `p.eval (k x)` for all polynomials `p : β[X]`. The definition is also relative to a filter `l : Filter α` where the decay rate is compared. When the map `k` is given by `n ↩ ↑n : ℕ → ℝ` this defines negligible functions: https://en.wikipedia.org/wiki/Negligible_function When the map `k` is given by `(r₁,...,rₙ) ↩ r₁*...*rₙ : ℝⁿ → ℝ` this is equivalent to the definition of rapidly decreasing functions given here: https://ncatlab.org/nlab/show/rapidly+decreasing+function # Main Theorems * `SuperpolynomialDecay.polynomial_mul` says that if `f(x)` is negligible, then so is `p(x) * f(x)` for any polynomial `p`. * `superpolynomialDecay_iff_zpow_tendsto_zero` gives an equivalence between definitions in terms of decaying faster than `k(x) ^ n` for all naturals `n` or `k(x) ^ c` for all integer `c`. -/ namespace Asymptotics open Topology Polynomial open Filter /-- `f` has superpolynomial decay in parameter `k` along filter `l` if `k ^ n * f` tends to zero at `l` for all naturals `n` -/ def SuperpolynomialDecay {α β : Type*} [TopologicalSpace β] [CommSemiring β] (l : Filter α) (k : α → β) (f : α → β) := ∀ n : ℕ, Tendsto (fun a : α => k a ^ n * f a) l (𝓝 0) variable {α β : Type*} {l : Filter α} {k : α → β} {f g g' : α → β} section CommSemiring variable [TopologicalSpace β] [CommSemiring β] theorem SuperpolynomialDecay.congr' (hf : SuperpolynomialDecay l k f) (hfg : f =á¶ [l] g) : SuperpolynomialDecay l k g := fun z => (hf z).congr' (EventuallyEq.mul (EventuallyEq.refl l _) hfg) theorem SuperpolynomialDecay.congr (hf : SuperpolynomialDecay l k f) (hfg : ∀ x, f x = g x) : SuperpolynomialDecay l k g := fun z => (hf z).congr fun x => (congr_arg fun a => k x ^ z * a) <| hfg x @[simp] theorem superpolynomialDecay_zero (l : Filter α) (k : α → β) : SuperpolynomialDecay l k 0 := fun z => by simpa only [Pi.zero_apply, mul_zero] using tendsto_const_nhds theorem SuperpolynomialDecay.add [ContinuousAdd β] (hf : SuperpolynomialDecay l k f) (hg : SuperpolynomialDecay l k g) : SuperpolynomialDecay l k (f + g) := fun z => by simpa only [mul_add, add_zero, Pi.add_apply] using (hf z).add (hg z) theorem SuperpolynomialDecay.mul [ContinuousMul β] (hf : SuperpolynomialDecay l k f) (hg : SuperpolynomialDecay l k g) : SuperpolynomialDecay l k (f * g) := fun z => by simpa only [mul_assoc, one_mul, mul_zero, pow_zero] using (hf z).mul (hg 0) theorem SuperpolynomialDecay.mul_const [ContinuousMul β] (hf : SuperpolynomialDecay l k f) (c : β) : SuperpolynomialDecay l k fun n => f n * c := fun z => by simpa only [← mul_assoc, zero_mul] using Tendsto.mul_const c (hf z) theorem SuperpolynomialDecay.const_mul [ContinuousMul β] (hf : SuperpolynomialDecay l k f) (c : β) : SuperpolynomialDecay l k fun n => c * f n := (hf.mul_const c).congr fun _ => mul_comm _ _ theorem SuperpolynomialDecay.param_mul (hf : SuperpolynomialDecay l k f) : SuperpolynomialDecay l k (k * f) := fun z => tendsto_nhds.2 fun s hs hs0 => l.sets_of_superset ((tendsto_nhds.1 (hf <| z + 1)) s hs hs0) fun x hx => by simpa only [Set.mem_preimage, Pi.mul_apply, ← mul_assoc, ← pow_succ] using hx theorem SuperpolynomialDecay.mul_param (hf : SuperpolynomialDecay l k f) : SuperpolynomialDecay l k (f * k) := hf.param_mul.congr fun _ => mul_comm _ _ theorem SuperpolynomialDecay.param_pow_mul (hf : SuperpolynomialDecay l k f) (n : ℕ) : SuperpolynomialDecay l k (k ^ n * f) := by induction' n with n hn · simpa only [Nat.zero_eq, one_mul, pow_zero] using hf · simpa only [pow_succ', mul_assoc] using hn.param_mul theorem SuperpolynomialDecay.mul_param_pow (hf : SuperpolynomialDecay l k f) (n : ℕ) : SuperpolynomialDecay l k (f * k ^ n) := (hf.param_pow_mul n).congr fun _ => mul_comm _ _ theorem SuperpolynomialDecay.polynomial_mul [ContinuousAdd β] [ContinuousMul β] (hf : SuperpolynomialDecay l k f) (p : β[X]) : SuperpolynomialDecay l k fun x => (p.eval <| k x) * f x := Polynomial.induction_on' p (fun p q hp hq => by simpa [add_mul] using hp.add hq) fun n c => by simpa [mul_assoc] using (hf.param_pow_mul n).const_mul c theorem SuperpolynomialDecay.mul_polynomial [ContinuousAdd β] [ContinuousMul β] (hf : SuperpolynomialDecay l k f) (p : β[X]) : SuperpolynomialDecay l k fun x => f x * (p.eval <| k x) := (hf.polynomial_mul p).congr fun _ => mul_comm _ _ end CommSemiring section OrderedCommSemiring variable [TopologicalSpace β] [OrderedCommSemiring β] [OrderTopology β] theorem SuperpolynomialDecay.trans_eventuallyLE (hk : 0 ≀ᶠ[l] k) (hg : SuperpolynomialDecay l k g) (hg' : SuperpolynomialDecay l k g') (hfg : g ≀ᶠ[l] f) (hfg' : f ≀ᶠ[l] g') : SuperpolynomialDecay l k f := fun z => tendsto_of_tendsto_of_tendsto_of_le_of_le' (hg z) (hg' z) (hfg.mp (hk.mono fun _ hx hx' => mul_le_mul_of_nonneg_left hx' (pow_nonneg hx z))) (hfg'.mp (hk.mono fun _ hx hx' => mul_le_mul_of_nonneg_left hx' (pow_nonneg hx z))) end OrderedCommSemiring section LinearOrderedCommRing variable [TopologicalSpace β] [LinearOrderedCommRing β] [OrderTopology β] variable (l k f) theorem superpolynomialDecay_iff_abs_tendsto_zero : SuperpolynomialDecay l k f ↔ ∀ n : ℕ, Tendsto (fun a : α => |k a ^ n * f a|) l (𝓝 0) := ⟹fun h z => (tendsto_zero_iff_abs_tendsto_zero _).1 (h z), fun h z => (tendsto_zero_iff_abs_tendsto_zero _).2 (h z)⟩ theorem superpolynomialDecay_iff_superpolynomialDecay_abs : SuperpolynomialDecay l k f ↔ SuperpolynomialDecay l (fun a => |k a|) fun a => |f a| := (superpolynomialDecay_iff_abs_tendsto_zero l k f).trans (by simp_rw [SuperpolynomialDecay, abs_mul, abs_pow]) variable {l k f} theorem SuperpolynomialDecay.trans_eventually_abs_le (hf : SuperpolynomialDecay l k f) (hfg : abs ∘ g ≀ᶠ[l] abs ∘ f) : SuperpolynomialDecay l k g := by rw [superpolynomialDecay_iff_abs_tendsto_zero] at hf ⊢ refine fun z => tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (hf z) (eventually_of_forall fun x => abs_nonneg _) (hfg.mono fun x hx => ?_) calc |k x ^ z * g x| = |k x ^ z| * |g x| := abs_mul (k x ^ z) (g x) _ ≀ |k x ^ z| * |f x| := by gcongr _ * ?_; exact hx _ = |k x ^ z * f x| := (abs_mul (k x ^ z) (f x)).symm theorem SuperpolynomialDecay.trans_abs_le (hf : SuperpolynomialDecay l k f) (hfg : ∀ x, |g x| ≀ |f x|) : SuperpolynomialDecay l k g := hf.trans_eventually_abs_le (eventually_of_forall hfg) end LinearOrderedCommRing section Field variable [TopologicalSpace β] [Field β] (l k f) theorem superpolynomialDecay_mul_const_iff [ContinuousMul β] {c : β} (hc0 : c ≠ 0) : (SuperpolynomialDecay l k fun n => f n * c) ↔ SuperpolynomialDecay l k f := ⟹fun h => (h.mul_const c⁻¹).congr fun x => by simp [mul_assoc, mul_inv_cancel hc0], fun h => h.mul_const c⟩ theorem superpolynomialDecay_const_mul_iff [ContinuousMul β] {c : β} (hc0 : c ≠ 0) : (SuperpolynomialDecay l k fun n => c * f n) ↔ SuperpolynomialDecay l k f := ⟹fun h => (h.const_mul c⁻¹).congr fun x => by simp [← mul_assoc, inv_mul_cancel hc0], fun h => h.const_mul c⟩ variable {l k f} end Field section LinearOrderedField variable [TopologicalSpace β] [LinearOrderedField β] [OrderTopology β] variable (f) theorem superpolynomialDecay_iff_abs_isBoundedUnder (hk : Tendsto k l atTop) : SuperpolynomialDecay l k f ↔ ∀ z : ℕ, IsBoundedUnder (· ≀ ·) l fun a : α => |k a ^ z * f a| := by refine ⟹fun h z => Tendsto.isBoundedUnder_le (Tendsto.abs (h z)), fun h => (superpolynomialDecay_iff_abs_tendsto_zero l k f).2 fun z => ?_⟩ obtain ⟹m, hm⟩ := h (z + 1) have h1 : Tendsto (fun _ : α => (0 : β)) l (𝓝 0) := tendsto_const_nhds have h2 : Tendsto (fun a : α => |(k a)⁻¹| * m) l (𝓝 0) := zero_mul m ▾ Tendsto.mul_const m ((tendsto_zero_iff_abs_tendsto_zero _).1 hk.inv_tendsto_atTop) refine tendsto_of_tendsto_of_tendsto_of_le_of_le' h1 h2 (eventually_of_forall fun x => abs_nonneg _) ((eventually_map.1 hm).mp ?_) refine (hk.eventually_ne_atTop 0).mono fun x hk0 hx => ?_ refine Eq.trans_le ?_ (mul_le_mul_of_nonneg_left hx <| abs_nonneg (k x)⁻¹) rw [← abs_mul, ← mul_assoc, pow_succ', ← mul_assoc, inv_mul_cancel hk0, one_mul] theorem superpolynomialDecay_iff_zpow_tendsto_zero (hk : Tendsto k l atTop) : SuperpolynomialDecay l k f ↔ ∀ z : â„€, Tendsto (fun a : α => k a ^ z * f a) l (𝓝 0) := by refine ⟹fun h z => ?_, fun h n => by simpa only [zpow_natCast] using h (n : â„€)⟩ by_cases hz : 0 ≀ z · unfold Tendsto lift z to ℕ using hz simpa using h z · have : Tendsto (fun a => k a ^ z) l (𝓝 0) := Tendsto.comp (tendsto_zpow_atTop_zero (not_le.1 hz)) hk have h : Tendsto f l (𝓝 0) := by simpa using h 0 exact zero_mul (0 : β) ▾ this.mul h variable {f} theorem SuperpolynomialDecay.param_zpow_mul (hk : Tendsto k l atTop) (hf : SuperpolynomialDecay l k f) (z : â„€) : SuperpolynomialDecay l k fun a => k a ^ z * f a := by rw [superpolynomialDecay_iff_zpow_tendsto_zero _ hk] at hf ⊢ refine fun z' => (hf <| z' + z).congr' ((hk.eventually_ne_atTop 0).mono fun x hx => ?_) simp [zpow_add₀ hx, mul_assoc, Pi.mul_apply] theorem SuperpolynomialDecay.mul_param_zpow (hk : Tendsto k l atTop) (hf : SuperpolynomialDecay l k f) (z : â„€) : SuperpolynomialDecay l k fun a => f a * k a ^ z := (hf.param_zpow_mul hk z).congr fun _ => mul_comm _ _ theorem SuperpolynomialDecay.inv_param_mul (hk : Tendsto k l atTop) (hf : SuperpolynomialDecay l k f) : SuperpolynomialDecay l k (k⁻¹ * f) := by simpa using hf.param_zpow_mul hk (-1) theorem SuperpolynomialDecay.param_inv_mul (hk : Tendsto k l atTop) (hf : SuperpolynomialDecay l k f) : SuperpolynomialDecay l k (f * k⁻¹) := (hf.inv_param_mul hk).congr fun _ => mul_comm _ _ variable (f) theorem superpolynomialDecay_param_mul_iff (hk : Tendsto k l atTop) : SuperpolynomialDecay l k (k * f) ↔ SuperpolynomialDecay l k f := ⟹fun h => (h.inv_param_mul hk).congr' ((hk.eventually_ne_atTop 0).mono fun x hx => by simp [← mul_assoc, inv_mul_cancel hx]), fun h => h.param_mul⟩ theorem superpolynomialDecay_mul_param_iff (hk : Tendsto k l atTop) : SuperpolynomialDecay l k (f * k) ↔ SuperpolynomialDecay l k f := by simpa [mul_comm k] using superpolynomialDecay_param_mul_iff f hk theorem superpolynomialDecay_param_pow_mul_iff (hk : Tendsto k l atTop) (n : ℕ) : SuperpolynomialDecay l k (k ^ n * f) ↔ SuperpolynomialDecay l k f := by induction' n with n hn · simp · simpa [pow_succ, ← mul_comm k, mul_assoc, superpolynomialDecay_param_mul_iff (k ^ n * f) hk] using hn theorem superpolynomialDecay_mul_param_pow_iff (hk : Tendsto k l atTop) (n : ℕ) : SuperpolynomialDecay l k (f * k ^ n) ↔ SuperpolynomialDecay l k f := by simpa [mul_comm f] using superpolynomialDecay_param_pow_mul_iff f hk n variable {f} end LinearOrderedField section NormedLinearOrderedField variable [NormedLinearOrderedField β] variable (l k f) theorem superpolynomialDecay_iff_norm_tendsto_zero : SuperpolynomialDecay l k f ↔ ∀ n : ℕ, Tendsto (fun a : α => ‖k a ^ n * f a‖) l (𝓝 0) := ⟹fun h z => tendsto_zero_iff_norm_tendsto_zero.1 (h z), fun h z => tendsto_zero_iff_norm_tendsto_zero.2 (h z)⟩ theorem superpolynomialDecay_iff_superpolynomialDecay_norm : SuperpolynomialDecay l k f ↔ SuperpolynomialDecay l (fun a => ‖k a‖) fun a => ‖f a‖ := (superpolynomialDecay_iff_norm_tendsto_zero l k f).trans (by simp [SuperpolynomialDecay]) variable {l k} variable [OrderTopology β] theorem superpolynomialDecay_iff_isBigO (hk : Tendsto k l atTop) : SuperpolynomialDecay l k f ↔ ∀ z : â„€, f =O[l] fun a : α => k a ^ z := by refine (superpolynomialDecay_iff_zpow_tendsto_zero f hk).trans ?_ have hk0 : ∀ᶠ x in l, k x ≠ 0 := hk.eventually_ne_atTop 0 refine ⟹fun h z => ?_, fun h z => ?_⟩ · refine isBigO_of_div_tendsto_nhds (hk0.mono fun x hx hxz ↩ absurd hxz (zpow_ne_zero _ hx)) 0 ?_ have : (fun a : α => k a ^ z)⁻¹ = fun a : α => k a ^ (-z) := funext fun x => by simp rw [div_eq_mul_inv, mul_comm f, this] exact h (-z) · suffices (fun a : α => k a ^ z * f a) =O[l] fun a : α => (k a)⁻¹ from IsBigO.trans_tendsto this hk.inv_tendsto_atTop refine ((isBigO_refl (fun a => k a ^ z) l).mul (h (-(z + 1)))).trans (IsBigO.of_bound 1 <| hk0.mono fun a ha0 => ?_) simp only [one_mul, neg_add z 1, zpow_add₀ ha0, ← mul_assoc, zpow_neg, mul_inv_cancel (zpow_ne_zero z ha0), zpow_one] rfl theorem superpolynomialDecay_iff_isLittleO (hk : Tendsto k l atTop) : SuperpolynomialDecay l k f ↔ ∀ z : â„€, f =o[l] fun a : α => k a ^ z := by refine ⟹fun h z => ?_, fun h => (superpolynomialDecay_iff_isBigO f hk).2 fun z => (h z).isBigO⟩ have hk0 : ∀ᶠ x in l, k x ≠ 0 := hk.eventually_ne_atTop 0 have : (fun _ : α => (1 : β)) =o[l] k := isLittleO_of_tendsto' (hk0.mono fun x hkx hkx' => absurd hkx' hkx) (by simpa using hk.inv_tendsto_atTop) have : f =o[l] fun x : α => k x * k x ^ (z - 1) := by simpa using this.mul_isBigO ((superpolynomialDecay_iff_isBigO f hk).1 h <| z - 1) refine this.trans_isBigO (IsBigO.of_bound 1 (hk0.mono fun x hkx => le_of_eq ?_)) rw [one_mul, zpow_sub_one₀ hkx, mul_comm (k x), mul_assoc, inv_mul_cancel hkx, mul_one] end NormedLinearOrderedField end Asymptotics
Analysis\Asymptotics\Theta.lean
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Asymptotics.Asymptotics import Mathlib.Analysis.Normed.Module.Basic /-! # Asymptotic equivalence up to a constant In this file we define `Asymptotics.IsTheta l f g` (notation: `f =Θ[l] g`) as `f =O[l] g ∧ g =O[l] f`, then prove basic properties of this equivalence relation. -/ open Filter open Topology namespace Asymptotics variable {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*} {E' : Type*} {F' : Type*} {G' : Type*} {E'' : Type*} {F'' : Type*} {G'' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : Type*} variable [Norm E] [Norm F] [Norm G] variable [SeminormedAddCommGroup E'] [SeminormedAddCommGroup F'] [SeminormedAddCommGroup G'] [NormedAddCommGroup E''] [NormedAddCommGroup F''] [NormedAddCommGroup G''] [SeminormedRing R] [SeminormedRing R'] variable [NormedField 𝕜] [NormedField 𝕜'] variable {c c' c₁ c₂ : ℝ} {f : α → E} {g : α → F} {k : α → G} variable {f' : α → E'} {g' : α → F'} {k' : α → G'} variable {f'' : α → E''} {g'' : α → F''} variable {l l' : Filter α} /-- We say that `f` is `Θ(g)` along a filter `l` (notation: `f =Θ[l] g`) if `f =O[l] g` and `g =O[l] f`. -/ def IsTheta (l : Filter α) (f : α → E) (g : α → F) : Prop := IsBigO l f g ∧ IsBigO l g f @[inherit_doc] notation:100 f " =Θ[" l "] " g:100 => IsTheta l f g theorem IsBigO.antisymm (h₁ : f =O[l] g) (h₂ : g =O[l] f) : f =Θ[l] g := ⟹h₁, h₂⟩ lemma IsTheta.isBigO (h : f =Θ[l] g) : f =O[l] g := h.1 lemma IsTheta.isBigO_symm (h : f =Θ[l] g) : g =O[l] f := h.2 @[refl] theorem isTheta_refl (f : α → E) (l : Filter α) : f =Θ[l] f := ⟹isBigO_refl _ _, isBigO_refl _ _⟩ theorem isTheta_rfl : f =Θ[l] f := isTheta_refl _ _ @[symm] nonrec theorem IsTheta.symm (h : f =Θ[l] g) : g =Θ[l] f := h.symm theorem isTheta_comm : f =Θ[l] g ↔ g =Θ[l] f := ⟹fun h ↩ h.symm, fun h ↩ h.symm⟩ @[trans] theorem IsTheta.trans {f : α → E} {g : α → F'} {k : α → G} (h₁ : f =Θ[l] g) (h₂ : g =Θ[l] k) : f =Θ[l] k := ⟹h₁.1.trans h₂.1, h₂.2.trans h₁.2⟩ -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → F') (γ := α → G) (IsTheta l) (IsTheta l) (IsTheta l) := ⟹IsTheta.trans⟩ @[trans] theorem IsBigO.trans_isTheta {f : α → E} {g : α → F'} {k : α → G} (h₁ : f =O[l] g) (h₂ : g =Θ[l] k) : f =O[l] k := h₁.trans h₂.1 -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → F') (γ := α → G) (IsBigO l) (IsTheta l) (IsBigO l) := ⟹IsBigO.trans_isTheta⟩ @[trans] theorem IsTheta.trans_isBigO {f : α → E} {g : α → F'} {k : α → G} (h₁ : f =Θ[l] g) (h₂ : g =O[l] k) : f =O[l] k := h₁.1.trans h₂ -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → F') (γ := α → G) (IsTheta l) (IsBigO l) (IsBigO l) := ⟹IsTheta.trans_isBigO⟩ @[trans] theorem IsLittleO.trans_isTheta {f : α → E} {g : α → F} {k : α → G'} (h₁ : f =o[l] g) (h₂ : g =Θ[l] k) : f =o[l] k := h₁.trans_isBigO h₂.1 -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → F') (γ := α → G') (IsLittleO l) (IsTheta l) (IsLittleO l) := ⟹IsLittleO.trans_isTheta⟩ @[trans] theorem IsTheta.trans_isLittleO {f : α → E} {g : α → F'} {k : α → G} (h₁ : f =Θ[l] g) (h₂ : g =o[l] k) : f =o[l] k := h₁.1.trans_isLittleO h₂ -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → F') (γ := α → G) (IsTheta l) (IsLittleO l) (IsLittleO l) := ⟹IsTheta.trans_isLittleO⟩ @[trans] theorem IsTheta.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =Θ[l] g₁) (hg : g₁ =á¶ [l] g₂) : f =Θ[l] g₂ := ⟹h.1.trans_eventuallyEq hg, hg.symm.trans_isBigO h.2⟩ -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → F) (γ := α → F) (IsTheta l) (EventuallyEq l) (IsTheta l) := ⟹IsTheta.trans_eventuallyEq⟩ @[trans] theorem _root_.Filter.EventuallyEq.trans_isTheta {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =á¶ [l] f₂) (h : f₂ =Θ[l] g) : f₁ =Θ[l] g := ⟹hf.trans_isBigO h.1, h.2.trans_eventuallyEq hf.symm⟩ -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → E) (γ := α → F) (EventuallyEq l) (IsTheta l) (IsTheta l) := ⟹EventuallyEq.trans_isTheta⟩ lemma _root_.Filter.EventuallyEq.isTheta {f g : α → E} (h : f =á¶ [l] g) : f =Θ[l] g := h.trans_isTheta isTheta_rfl @[simp] theorem isTheta_norm_left : (fun x ↩ ‖f' x‖) =Θ[l] g ↔ f' =Θ[l] g := by simp [IsTheta] @[simp] theorem isTheta_norm_right : (f =Θ[l] fun x ↩ ‖g' x‖) ↔ f =Θ[l] g' := by simp [IsTheta] alias ⟹IsTheta.of_norm_left, IsTheta.norm_left⟩ := isTheta_norm_left alias ⟹IsTheta.of_norm_right, IsTheta.norm_right⟩ := isTheta_norm_right theorem isTheta_of_norm_eventuallyEq (h : (fun x ↩ ‖f x‖) =á¶ [l] fun x ↩ ‖g x‖) : f =Θ[l] g := ⟹IsBigO.of_bound 1 <| by simpa only [one_mul] using h.le, IsBigO.of_bound 1 <| by simpa only [one_mul] using h.symm.le⟩ theorem isTheta_of_norm_eventuallyEq' {g : α → ℝ} (h : (fun x ↩ ‖f' x‖) =á¶ [l] g) : f' =Θ[l] g := isTheta_of_norm_eventuallyEq <| h.mono fun x hx ↩ by simp only [← hx, norm_norm] theorem IsTheta.isLittleO_congr_left (h : f' =Θ[l] g') : f' =o[l] k ↔ g' =o[l] k := ⟹h.symm.trans_isLittleO, h.trans_isLittleO⟩ theorem IsTheta.isLittleO_congr_right (h : g' =Θ[l] k') : f =o[l] g' ↔ f =o[l] k' := ⟹fun H ↩ H.trans_isTheta h, fun H ↩ H.trans_isTheta h.symm⟩ theorem IsTheta.isBigO_congr_left (h : f' =Θ[l] g') : f' =O[l] k ↔ g' =O[l] k := ⟹h.symm.trans_isBigO, h.trans_isBigO⟩ theorem IsTheta.isBigO_congr_right (h : g' =Θ[l] k') : f =O[l] g' ↔ f =O[l] k' := ⟹fun H ↩ H.trans_isTheta h, fun H ↩ H.trans_isTheta h.symm⟩ lemma IsTheta.isTheta_congr_left (h : f' =Θ[l] g') : f' =Θ[l] k ↔ g' =Θ[l] k := h.isBigO_congr_left.and h.isBigO_congr_right lemma IsTheta.isTheta_congr_right (h : f' =Θ[l] g') : k =Θ[l] f' ↔ k =Θ[l] g' := h.isBigO_congr_right.and h.isBigO_congr_left theorem IsTheta.mono (h : f =Θ[l] g) (hl : l' ≀ l) : f =Θ[l'] g := ⟹h.1.mono hl, h.2.mono hl⟩ theorem IsTheta.sup (h : f' =Θ[l] g') (h' : f' =Θ[l'] g') : f' =Θ[l ⊔ l'] g' := ⟹h.1.sup h'.1, h.2.sup h'.2⟩ @[simp] theorem isTheta_sup : f' =Θ[l ⊔ l'] g' ↔ f' =Θ[l] g' ∧ f' =Θ[l'] g' := ⟹fun h ↩ ⟹h.mono le_sup_left, h.mono le_sup_right⟩, fun h ↩ h.1.sup h.2⟩ theorem IsTheta.eq_zero_iff (h : f'' =Θ[l] g'') : ∀ᶠ x in l, f'' x = 0 ↔ g'' x = 0 := h.1.eq_zero_imp.mp <| h.2.eq_zero_imp.mono fun _ ↩ Iff.intro theorem IsTheta.tendsto_zero_iff (h : f'' =Θ[l] g'') : Tendsto f'' l (𝓝 0) ↔ Tendsto g'' l (𝓝 0) := by simp only [← isLittleO_one_iff ℝ, h.isLittleO_congr_left] theorem IsTheta.tendsto_norm_atTop_iff (h : f' =Θ[l] g') : Tendsto (norm ∘ f') l atTop ↔ Tendsto (norm ∘ g') l atTop := by simp only [Function.comp, ← isLittleO_const_left_of_ne (one_ne_zero' ℝ), h.isLittleO_congr_right] theorem IsTheta.isBoundedUnder_le_iff (h : f' =Θ[l] g') : IsBoundedUnder (· ≀ ·) l (norm ∘ f') ↔ IsBoundedUnder (· ≀ ·) l (norm ∘ g') := by simp only [← isBigO_const_of_ne (one_ne_zero' ℝ), h.isBigO_congr_left] theorem IsTheta.smul [NormedSpace 𝕜 E'] [NormedSpace 𝕜' F'] {f₁ : α → 𝕜} {f₂ : α → 𝕜'} {g₁ : α → E'} {g₂ : α → F'} (hf : f₁ =Θ[l] f₂) (hg : g₁ =Θ[l] g₂) : (fun x ↩ f₁ x • g₁ x) =Θ[l] fun x ↩ f₂ x • g₂ x := ⟹hf.1.smul hg.1, hf.2.smul hg.2⟩ theorem IsTheta.mul {f₁ f₂ : α → 𝕜} {g₁ g₂ : α → 𝕜'} (h₁ : f₁ =Θ[l] g₁) (h₂ : f₂ =Θ[l] g₂) : (fun x ↩ f₁ x * f₂ x) =Θ[l] fun x ↩ g₁ x * g₂ x := h₁.smul h₂ theorem IsTheta.inv {f : α → 𝕜} {g : α → 𝕜'} (h : f =Θ[l] g) : (fun x ↩ (f x)⁻¹) =Θ[l] fun x ↩ (g x)⁻¹ := ⟹h.2.inv_rev h.1.eq_zero_imp, h.1.inv_rev h.2.eq_zero_imp⟩ @[simp] theorem isTheta_inv {f : α → 𝕜} {g : α → 𝕜'} : ((fun x ↩ (f x)⁻¹) =Θ[l] fun x ↩ (g x)⁻¹) ↔ f =Θ[l] g := ⟹fun h ↩ by simpa only [inv_inv] using h.inv, IsTheta.inv⟩ theorem IsTheta.div {f₁ f₂ : α → 𝕜} {g₁ g₂ : α → 𝕜'} (h₁ : f₁ =Θ[l] g₁) (h₂ : f₂ =Θ[l] g₂) : (fun x ↩ f₁ x / f₂ x) =Θ[l] fun x ↩ g₁ x / g₂ x := by simpa only [div_eq_mul_inv] using h₁.mul h₂.inv theorem IsTheta.pow {f : α → 𝕜} {g : α → 𝕜'} (h : f =Θ[l] g) (n : ℕ) : (fun x ↩ f x ^ n) =Θ[l] fun x ↩ g x ^ n := ⟹h.1.pow n, h.2.pow n⟩ theorem IsTheta.zpow {f : α → 𝕜} {g : α → 𝕜'} (h : f =Θ[l] g) (n : â„€) : (fun x ↩ f x ^ n) =Θ[l] fun x ↩ g x ^ n := by cases n · simpa only [Int.ofNat_eq_coe, zpow_natCast] using h.pow _ · simpa only [zpow_negSucc] using (h.pow _).inv theorem isTheta_const_const {c₁ : E''} {c₂ : F''} (h₁ : c₁ ≠ 0) (h₂ : c₂ ≠ 0) : (fun _ : α ↩ c₁) =Θ[l] fun _ ↩ c₂ := ⟹isBigO_const_const _ h₂ _, isBigO_const_const _ h₁ _⟩ @[simp] theorem isTheta_const_const_iff [NeBot l] {c₁ : E''} {c₂ : F''} : ((fun _ : α ↩ c₁) =Θ[l] fun _ ↩ c₂) ↔ (c₁ = 0 ↔ c₂ = 0) := by simpa only [IsTheta, isBigO_const_const_iff, ← iff_def] using Iff.comm @[simp] theorem isTheta_zero_left : (fun _ ↩ (0 : E')) =Θ[l] g'' ↔ g'' =á¶ [l] 0 := by simp only [IsTheta, isBigO_zero, isBigO_zero_right_iff, true_and_iff] @[simp] theorem isTheta_zero_right : (f'' =Θ[l] fun _ ↩ (0 : F')) ↔ f'' =á¶ [l] 0 := isTheta_comm.trans isTheta_zero_left theorem isTheta_const_smul_left [NormedSpace 𝕜 E'] {c : 𝕜} (hc : c ≠ 0) : (fun x ↩ c • f' x) =Θ[l] g ↔ f' =Θ[l] g := and_congr (isBigO_const_smul_left hc) (isBigO_const_smul_right hc) alias ⟹IsTheta.of_const_smul_left, IsTheta.const_smul_left⟩ := isTheta_const_smul_left theorem isTheta_const_smul_right [NormedSpace 𝕜 F'] {c : 𝕜} (hc : c ≠ 0) : (f =Θ[l] fun x ↩ c • g' x) ↔ f =Θ[l] g' := and_congr (isBigO_const_smul_right hc) (isBigO_const_smul_left hc) alias ⟹IsTheta.of_const_smul_right, IsTheta.const_smul_right⟩ := isTheta_const_smul_right theorem isTheta_const_mul_left {c : 𝕜} {f : α → 𝕜} (hc : c ≠ 0) : (fun x ↩ c * f x) =Θ[l] g ↔ f =Θ[l] g := by simpa only [← smul_eq_mul] using isTheta_const_smul_left hc alias ⟹IsTheta.of_const_mul_left, IsTheta.const_mul_left⟩ := isTheta_const_mul_left theorem isTheta_const_mul_right {c : 𝕜} {g : α → 𝕜} (hc : c ≠ 0) : (f =Θ[l] fun x ↩ c * g x) ↔ f =Θ[l] g := by simpa only [← smul_eq_mul] using isTheta_const_smul_right hc alias ⟹IsTheta.of_const_mul_right, IsTheta.const_mul_right⟩ := isTheta_const_mul_right theorem IsLittleO.right_isTheta_add {f₁ f₂ : α → E'} (h : f₁ =o[l] f₂) : f₂ =Θ[l] (f₁ + f₂) := ⟹h.right_isBigO_add, h.add_isBigO (isBigO_refl _ _)⟩ theorem IsLittleO.right_isTheta_add' {f₁ f₂ : α → E'} (h : f₁ =o[l] f₂) : f₂ =Θ[l] (f₂ + f₁) := add_comm f₁ f₂ ▾ h.right_isTheta_add lemma IsTheta.add_isLittleO {f₁ f₂ : α → E'} {g : α → F} (hΘ : f₁ =Θ[l] g) (ho : f₂ =o[l] g) : (f₁ + f₂) =Θ[l] g := (ho.trans_isTheta hΘ.symm).right_isTheta_add'.symm.trans hΘ lemma IsLittleO.add_isTheta {f₁ f₂ : α → E'} {g : α → F} (ho : f₁ =o[l] g) (hΘ : f₂ =Θ[l] g) : (f₁ + f₂) =Θ[l] g := add_comm f₁ f₂ ▾ hΘ.add_isLittleO ho end Asymptotics
Analysis\BoxIntegral\Basic.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Partition.Filter import Mathlib.Analysis.BoxIntegral.Partition.Measure import Mathlib.Analysis.Oscillation import Mathlib.Topology.UniformSpace.Compact import Mathlib.Data.Bool.Basic /-! # Integrals of Riemann, Henstock-Kurzweil, and McShane In this file we define the integral of a function over a box in `ℝⁿ`. The same definition works for Riemann, Henstock-Kurzweil, and McShane integrals. As usual, we represent `ℝⁿ` as the type of functions `ι → ℝ` for some finite type `ι`. A rectangular box `(l, u]` in `ℝⁿ` is defined to be the set `{x : ι → ℝ | ∀ i, l i < x i ∧ x i ≀ u i}`, see `BoxIntegral.Box`. Let `vol` be a box-additive function on boxes in `ℝⁿ` with codomain `E →L[ℝ] F`. Given a function `f : ℝⁿ → E`, a box `I` and a tagged partition `π` of this box, the *integral sum* of `f` over `π` with respect to the volume `vol` is the sum of `vol J (f (π.tag J))` over all boxes of `π`. Here `π.tag J` is the point (tag) in `ℝⁿ` associated with the box `J`. The integral is defined as the limit of integral sums along a filter. Different filters correspond to different integration theories. In order to avoid code duplication, all our definitions and theorems take an argument `l : BoxIntegral.IntegrationParams`. This is a type that holds three boolean values, and encodes eight filters including those corresponding to Riemann, Henstock-Kurzweil, and McShane integrals. Following the design of infinite sums (see `hasSum` and `tsum`), we define a predicate `BoxIntegral.HasIntegral` and a function `BoxIntegral.integral` that returns a vector satisfying the predicate or zero if the function is not integrable. Then we prove some basic properties of box integrals (linearity, a formula for the integral of a constant). We also prove a version of the Henstock-Sacks inequality (see `BoxIntegral.Integrable.dist_integralSum_le_of_memBaseSet` and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq`), prove integrability of continuous functions, and provide a criterion for integrability w.r.t. a non-Riemann filter (e.g., Henstock-Kurzweil and McShane). ## Notation - `ℝⁿ`: local notation for `ι → ℝ` ## Tags integral -/ open scoped Topology NNReal Filter Uniformity BoxIntegral open Set Finset Function Filter Metric BoxIntegral.IntegrationParams noncomputable section namespace BoxIntegral universe u v w variable {ι : Type u} {E : Type v} {F : Type w} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {I J : Box ι} {π : TaggedPrepartition I} open TaggedPrepartition local notation "ℝⁿ" => ι → ℝ /-! ### Integral sum and its basic properties -/ /-- The integral sum of `f : ℝⁿ → E` over a tagged prepartition `π` w.r.t. box-additive volume `vol` with codomain `E →L[ℝ] F` is the sum of `vol J (f (π.tag J))` over all boxes of `π`. -/ def integralSum (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : F := ∑ J ∈ π.boxes, vol J (f (π.tag J)) theorem integralSum_biUnionTagged (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : Prepartition I) (πi : ∀ J, TaggedPrepartition J) : integralSum f vol (π.biUnionTagged πi) = ∑ J ∈ π.boxes, integralSum f vol (πi J) := by refine (π.sum_biUnion_boxes _ _).trans <| sum_congr rfl fun J hJ => sum_congr rfl fun J' hJ' => ?_ rw [π.tag_biUnionTagged hJ hJ'] theorem integralSum_biUnion_partition (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) (πi : ∀ J, Prepartition J) (hπi : ∀ J ∈ π, (πi J).IsPartition) : integralSum f vol (π.biUnionPrepartition πi) = integralSum f vol π := by refine (π.sum_biUnion_boxes _ _).trans (sum_congr rfl fun J hJ => ?_) calc (∑ J' ∈ (πi J).boxes, vol J' (f (π.tag <| π.toPrepartition.biUnionIndex πi J'))) = ∑ J' ∈ (πi J).boxes, vol J' (f (π.tag J)) := sum_congr rfl fun J' hJ' => by rw [Prepartition.biUnionIndex_of_mem _ hJ hJ'] _ = vol J (f (π.tag J)) := (vol.map ⟹⟹fun g : E →L[ℝ] F => g (f (π.tag J)), rfl⟩, fun _ _ => rfl⟩).sum_partition_boxes le_top (hπi J hJ) theorem integralSum_inf_partition (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) {π' : Prepartition I} (h : π'.IsPartition) : integralSum f vol (π.infPrepartition π') = integralSum f vol π := integralSum_biUnion_partition f vol π _ fun _J hJ => h.restrict (Prepartition.le_of_mem _ hJ) open Classical in theorem integralSum_fiberwise {α} (g : Box ι → α) (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : (∑ y ∈ π.boxes.image g, integralSum f vol (π.filter (g · = y))) = integralSum f vol π := π.sum_fiberwise g fun J => vol J (f <| π.tag J) theorem integralSum_sub_partitions (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) {π₁ π₂ : TaggedPrepartition I} (h₁ : π₁.IsPartition) (h₂ : π₂.IsPartition) : integralSum f vol π₁ - integralSum f vol π₂ = ∑ J ∈ (π₁.toPrepartition ⊓ π₂.toPrepartition).boxes, (vol J (f <| (π₁.infPrepartition π₂.toPrepartition).tag J) - vol J (f <| (π₂.infPrepartition π₁.toPrepartition).tag J)) := by rw [← integralSum_inf_partition f vol π₁ h₂, ← integralSum_inf_partition f vol π₂ h₁, integralSum, integralSum, Finset.sum_sub_distrib] simp only [infPrepartition_toPrepartition, inf_comm] @[simp] theorem integralSum_disjUnion (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) {π₁ π₂ : TaggedPrepartition I} (h : Disjoint π₁.iUnion π₂.iUnion) : integralSum f vol (π₁.disjUnion π₂ h) = integralSum f vol π₁ + integralSum f vol π₂ := by refine (Prepartition.sum_disj_union_boxes h _).trans (congr_arg₂ (· + ·) (sum_congr rfl fun J hJ => ?_) (sum_congr rfl fun J hJ => ?_)) · rw [disjUnion_tag_of_mem_left _ hJ] · rw [disjUnion_tag_of_mem_right _ hJ] @[simp] theorem integralSum_add (f g : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : integralSum (f + g) vol π = integralSum f vol π + integralSum g vol π := by simp only [integralSum, Pi.add_apply, (vol _).map_add, Finset.sum_add_distrib] @[simp] theorem integralSum_neg (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : integralSum (-f) vol π = -integralSum f vol π := by simp only [integralSum, Pi.neg_apply, (vol _).map_neg, Finset.sum_neg_distrib] @[simp] theorem integralSum_smul (c : ℝ) (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : integralSum (c • f) vol π = c • integralSum f vol π := by simp only [integralSum, Finset.smul_sum, Pi.smul_apply, ContinuousLinearMap.map_smul] variable [Fintype ι] /-! ### Basic integrability theory -/ /-- The predicate `HasIntegral I l f vol y` says that `y` is the integral of `f` over `I` along `l` w.r.t. volume `vol`. This means that integral sums of `f` tend to `𝓝 y` along `BoxIntegral.IntegrationParams.toFilteriUnion I ⊀`. -/ def HasIntegral (I : Box ι) (l : IntegrationParams) (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (y : F) : Prop := Tendsto (integralSum f vol) (l.toFilteriUnion I ⊀) (𝓝 y) /-- A function is integrable if there exists a vector that satisfies the `HasIntegral` predicate. -/ def Integrable (I : Box ι) (l : IntegrationParams) (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) := ∃ y, HasIntegral I l f vol y open Classical in /-- The integral of a function `f` over a box `I` along a filter `l` w.r.t. a volume `vol`. Returns zero on non-integrable functions. -/ def integral (I : Box ι) (l : IntegrationParams) (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) := if h : Integrable I l f vol then h.choose else 0 -- Porting note: using the above notation ℝⁿ here causes the theorem below to be silently ignored -- see https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Lean.204.20doesn't.20add.20lemma.20to.20the.20environment/near/363764522 -- and https://github.com/leanprover/lean4/issues/2257 variable {l : IntegrationParams} {f g : (ι → ℝ) → E} {vol : ι →ᵇᵃ E →L[ℝ] F} {y y' : F} /-- Reinterpret `BoxIntegral.HasIntegral` as `Filter.Tendsto`, e.g., dot-notation theorems that are shadowed in the `BoxIntegral.HasIntegral` namespace. -/ theorem HasIntegral.tendsto (h : HasIntegral I l f vol y) : Tendsto (integralSum f vol) (l.toFilteriUnion I ⊀) (𝓝 y) := h /-- The `ε`-`ÎŽ` definition of `BoxIntegral.HasIntegral`. -/ theorem hasIntegral_iff : HasIntegral I l f vol y ↔ ∀ ε > (0 : ℝ), ∃ r : ℝ≥0 → ℝⁿ → Ioi (0 : ℝ), (∀ c, l.RCond (r c)) ∧ ∀ c π, l.MemBaseSet I c (r c) π → IsPartition π → dist (integralSum f vol π) y ≀ ε := ((l.hasBasis_toFilteriUnion_top I).tendsto_iff nhds_basis_closedBall).trans <| by simp [@forall_swap ℝ≥0 (TaggedPrepartition I)] /-- Quite often it is more natural to prove an estimate of the form `a * ε`, not `ε` in the RHS of `BoxIntegral.hasIntegral_iff`, so we provide this auxiliary lemma. -/ theorem HasIntegral.of_mul (a : ℝ) (h : ∀ ε : ℝ, 0 < ε → ∃ r : ℝ≥0 → ℝⁿ → Ioi (0 : ℝ), (∀ c, l.RCond (r c)) ∧ ∀ c π, l.MemBaseSet I c (r c) π → IsPartition π → dist (integralSum f vol π) y ≀ a * ε) : HasIntegral I l f vol y := by refine hasIntegral_iff.2 fun ε hε => ?_ rcases exists_pos_mul_lt hε a with ⟚ε', hε', ha⟩ rcases h ε' hε' with ⟹r, hr, H⟩ exact ⟹r, hr, fun c π hπ hπp => (H c π hπ hπp).trans ha.le⟩ theorem integrable_iff_cauchy [CompleteSpace F] : Integrable I l f vol ↔ Cauchy ((l.toFilteriUnion I ⊀).map (integralSum f vol)) := cauchy_map_iff_exists_tendsto.symm /-- In a complete space, a function is integrable if and only if its integral sums form a Cauchy net. Here we restate this fact in terms of `∀ ε > 0, ∃ r, ...`. -/ theorem integrable_iff_cauchy_basis [CompleteSpace F] : Integrable I l f vol ↔ ∀ ε > (0 : ℝ), ∃ r : ℝ≥0 → ℝⁿ → Ioi (0 : ℝ), (∀ c, l.RCond (r c)) ∧ ∀ c₁ c₂ π₁ π₂, l.MemBaseSet I c₁ (r c₁) π₁ → π₁.IsPartition → l.MemBaseSet I c₂ (r c₂) π₂ → π₂.IsPartition → dist (integralSum f vol π₁) (integralSum f vol π₂) ≀ ε := by rw [integrable_iff_cauchy, cauchy_map_iff', (l.hasBasis_toFilteriUnion_top _).prod_self.tendsto_iff uniformity_basis_dist_le] refine forall₂_congr fun ε _ => exists_congr fun r => ?_ simp only [exists_prop, Prod.forall, Set.mem_iUnion, exists_imp, prod_mk_mem_set_prod_eq, and_imp, mem_inter_iff, mem_setOf_eq] exact and_congr Iff.rfl ⟹fun H c₁ c₂ π₁ π₂ h₁ hU₁ h₂ hU₂ => H π₁ π₂ c₁ h₁ hU₁ c₂ h₂ hU₂, fun H π₁ π₂ c₁ h₁ hU₁ c₂ h₂ hU₂ => H c₁ c₂ π₁ π₂ h₁ hU₁ h₂ hU₂⟩ theorem HasIntegral.mono {l₁ l₂ : IntegrationParams} (h : HasIntegral I l₁ f vol y) (hl : l₂ ≀ l₁) : HasIntegral I l₂ f vol y := h.mono_left <| IntegrationParams.toFilteriUnion_mono _ hl _ protected theorem Integrable.hasIntegral (h : Integrable I l f vol) : HasIntegral I l f vol (integral I l f vol) := by rw [integral, dif_pos h] exact Classical.choose_spec h theorem Integrable.mono {l'} (h : Integrable I l f vol) (hle : l' ≀ l) : Integrable I l' f vol := ⟹_, h.hasIntegral.mono hle⟩ theorem HasIntegral.unique (h : HasIntegral I l f vol y) (h' : HasIntegral I l f vol y') : y = y' := tendsto_nhds_unique h h' theorem HasIntegral.integrable (h : HasIntegral I l f vol y) : Integrable I l f vol := ⟹_, h⟩ theorem HasIntegral.integral_eq (h : HasIntegral I l f vol y) : integral I l f vol = y := h.integrable.hasIntegral.unique h nonrec theorem HasIntegral.add (h : HasIntegral I l f vol y) (h' : HasIntegral I l g vol y') : HasIntegral I l (f + g) vol (y + y') := by simpa only [HasIntegral, ← integralSum_add] using h.add h' theorem Integrable.add (hf : Integrable I l f vol) (hg : Integrable I l g vol) : Integrable I l (f + g) vol := (hf.hasIntegral.add hg.hasIntegral).integrable theorem integral_add (hf : Integrable I l f vol) (hg : Integrable I l g vol) : integral I l (f + g) vol = integral I l f vol + integral I l g vol := (hf.hasIntegral.add hg.hasIntegral).integral_eq nonrec theorem HasIntegral.neg (hf : HasIntegral I l f vol y) : HasIntegral I l (-f) vol (-y) := by simpa only [HasIntegral, ← integralSum_neg] using hf.neg theorem Integrable.neg (hf : Integrable I l f vol) : Integrable I l (-f) vol := hf.hasIntegral.neg.integrable theorem Integrable.of_neg (hf : Integrable I l (-f) vol) : Integrable I l f vol := neg_neg f ▾ hf.neg @[simp] theorem integrable_neg : Integrable I l (-f) vol ↔ Integrable I l f vol := ⟹fun h => h.of_neg, fun h => h.neg⟩ @[simp] theorem integral_neg : integral I l (-f) vol = -integral I l f vol := by classical exact if h : Integrable I l f vol then h.hasIntegral.neg.integral_eq else by rw [integral, integral, dif_neg h, dif_neg (mt Integrable.of_neg h), neg_zero] theorem HasIntegral.sub (h : HasIntegral I l f vol y) (h' : HasIntegral I l g vol y') : HasIntegral I l (f - g) vol (y - y') := by simpa only [sub_eq_add_neg] using h.add h'.neg theorem Integrable.sub (hf : Integrable I l f vol) (hg : Integrable I l g vol) : Integrable I l (f - g) vol := (hf.hasIntegral.sub hg.hasIntegral).integrable theorem integral_sub (hf : Integrable I l f vol) (hg : Integrable I l g vol) : integral I l (f - g) vol = integral I l f vol - integral I l g vol := (hf.hasIntegral.sub hg.hasIntegral).integral_eq theorem hasIntegral_const (c : E) : HasIntegral I l (fun _ => c) vol (vol I c) := tendsto_const_nhds.congr' <| (l.eventually_isPartition I).mono fun _π hπ => Eq.symm <| (vol.map ⟹⟹fun g : E →L[ℝ] F ↩ g c, rfl⟩, fun _ _ ↩ rfl⟩).sum_partition_boxes le_top hπ @[simp] theorem integral_const (c : E) : integral I l (fun _ => c) vol = vol I c := (hasIntegral_const c).integral_eq theorem integrable_const (c : E) : Integrable I l (fun _ => c) vol := ⟹_, hasIntegral_const c⟩ theorem hasIntegral_zero : HasIntegral I l (fun _ => (0 : E)) vol 0 := by simpa only [← (vol I).map_zero] using hasIntegral_const (0 : E) theorem integrable_zero : Integrable I l (fun _ => (0 : E)) vol := ⟹0, hasIntegral_zero⟩ theorem integral_zero : integral I l (fun _ => (0 : E)) vol = 0 := hasIntegral_zero.integral_eq theorem HasIntegral.sum {α : Type*} {s : Finset α} {f : α → ℝⁿ → E} {g : α → F} (h : ∀ i ∈ s, HasIntegral I l (f i) vol (g i)) : HasIntegral I l (fun x => ∑ i ∈ s, f i x) vol (∑ i ∈ s, g i) := by classical induction' s using Finset.induction_on with a s ha ihs; · simp [hasIntegral_zero] simp only [Finset.sum_insert ha]; rw [Finset.forall_mem_insert] at h exact h.1.add (ihs h.2) theorem HasIntegral.smul (hf : HasIntegral I l f vol y) (c : ℝ) : HasIntegral I l (c • f) vol (c • y) := by simpa only [HasIntegral, ← integralSum_smul] using (tendsto_const_nhds : Tendsto _ _ (𝓝 c)).smul hf theorem Integrable.smul (hf : Integrable I l f vol) (c : ℝ) : Integrable I l (c • f) vol := (hf.hasIntegral.smul c).integrable theorem Integrable.of_smul {c : ℝ} (hf : Integrable I l (c • f) vol) (hc : c ≠ 0) : Integrable I l f vol := by simpa [inv_smul_smul₀ hc] using hf.smul c⁻¹ @[simp] theorem integral_smul (c : ℝ) : integral I l (fun x => c • f x) vol = c • integral I l f vol := by rcases eq_or_ne c 0 with (rfl | hc); · simp only [zero_smul, integral_zero] by_cases hf : Integrable I l f vol · exact (hf.hasIntegral.smul c).integral_eq · have : ¬Integrable I l (fun x => c • f x) vol := mt (fun h => h.of_smul hc) hf rw [integral, integral, dif_neg hf, dif_neg this, smul_zero] open MeasureTheory /-- The integral of a nonnegative function w.r.t. a volume generated by a locally-finite measure is nonnegative. -/ theorem integral_nonneg {g : ℝⁿ → ℝ} (hg : ∀ x ∈ Box.Icc I, 0 ≀ g x) (ÎŒ : Measure ℝⁿ) [IsLocallyFiniteMeasure ÎŒ] : 0 ≀ integral I l g ÎŒ.toBoxAdditive.toSMul := by by_cases hgi : Integrable I l g ÎŒ.toBoxAdditive.toSMul · refine ge_of_tendsto' hgi.hasIntegral fun π => sum_nonneg fun J _ => ?_ exact mul_nonneg ENNReal.toReal_nonneg (hg _ <| π.tag_mem_Icc _) · rw [integral, dif_neg hgi] /-- If `‖f x‖ ≀ g x` on `[l, u]` and `g` is integrable, then the norm of the integral of `f` is less than or equal to the integral of `g`. -/ theorem norm_integral_le_of_norm_le {g : ℝⁿ → ℝ} (hle : ∀ x ∈ Box.Icc I, ‖f x‖ ≀ g x) (ÎŒ : Measure ℝⁿ) [IsLocallyFiniteMeasure ÎŒ] (hg : Integrable I l g ÎŒ.toBoxAdditive.toSMul) : ‖(integral I l f ÎŒ.toBoxAdditive.toSMul : E)‖ ≀ integral I l g ÎŒ.toBoxAdditive.toSMul := by by_cases hfi : Integrable.{u, v, v} I l f ÎŒ.toBoxAdditive.toSMul · refine le_of_tendsto_of_tendsto' hfi.hasIntegral.norm hg.hasIntegral fun π => ?_ refine norm_sum_le_of_le _ fun J _ => ?_ simp only [BoxAdditiveMap.toSMul_apply, norm_smul, smul_eq_mul, Real.norm_eq_abs, ÎŒ.toBoxAdditive_apply, abs_of_nonneg ENNReal.toReal_nonneg] exact mul_le_mul_of_nonneg_left (hle _ <| π.tag_mem_Icc _) ENNReal.toReal_nonneg · rw [integral, dif_neg hfi, norm_zero] exact integral_nonneg (fun x hx => (norm_nonneg _).trans (hle x hx)) ÎŒ theorem norm_integral_le_of_le_const {c : ℝ} (hc : ∀ x ∈ Box.Icc I, ‖f x‖ ≀ c) (ÎŒ : Measure ℝⁿ) [IsLocallyFiniteMeasure ÎŒ] : ‖(integral I l f ÎŒ.toBoxAdditive.toSMul : E)‖ ≀ (ÎŒ I).toReal * c := by simpa only [integral_const] using norm_integral_le_of_norm_le hc ÎŒ (integrable_const c) /-! # Henstock-Sacks inequality and integrability on subboxes Henstock-Sacks inequality for Henstock-Kurzweil integral says the following. Let `f` be a function integrable on a box `I`; let `r : ℝⁿ → (0, ∞)` be a function such that for any tagged partition of `I` subordinate to `r`, the integral sum over this partition is `ε`-close to the integral. Then for any tagged prepartition (i.e. a finite collections of pairwise disjoint subboxes of `I` with tagged points) `π`, the integral sum over `π` differs from the integral of `f` over the part of `I` covered by `π` by at most `ε`. The actual statement in the library is a bit more complicated to make it work for any `BoxIntegral.IntegrationParams`. We formalize several versions of this inequality in `BoxIntegral.Integrable.dist_integralSum_le_of_memBaseSet`, `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq`, and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet`. Instead of using predicate assumptions on `r`, we define `BoxIntegral.Integrable.convergenceR (h : integrable I l f vol) (ε : ℝ) (c : ℝ≥0) : ℝⁿ → (0, ∞)` to be a function `r` such that - if `l.bRiemann`, then `r` is a constant; - if `ε > 0`, then for any tagged partition `π` of `I` subordinate to `r` (more precisely, satisfying the predicate `l.mem_base_set I c r`), the integral sum of `f` over `π` differs from the integral of `f` over `I` by at most `ε`. The proof is mostly based on [Russel A. Gordon, *The integrals of Lebesgue, Denjoy, Perron, and Henstock*][Gordon55]. -/ namespace Integrable /-- If `ε > 0`, then `BoxIntegral.Integrable.convergenceR` is a function `r : ℝ≥0 → ℝⁿ → (0, ∞)` such that for every `c : ℝ≥0`, for every tagged partition `π` subordinate to `r` (and satisfying additional distortion estimates if `BoxIntegral.IntegrationParams.bDistortion l = true`), the corresponding integral sum is `ε`-close to the integral. If `BoxIntegral.IntegrationParams.bRiemann = true`, then `r c x` does not depend on `x`. If `ε ≀ 0`, then we use `r c x = 1`. -/ def convergenceR (h : Integrable I l f vol) (ε : ℝ) : ℝ≥0 → ℝⁿ → Ioi (0 : ℝ) := if hε : 0 < ε then (hasIntegral_iff.1 h.hasIntegral ε hε).choose else fun _ _ => ⟹1, Set.mem_Ioi.2 zero_lt_one⟩ variable {c c₁ c₂ : ℝ≥0} {ε ε₁ ε₂ : ℝ} {π₁ π₂ : TaggedPrepartition I} theorem convergenceR_cond (h : Integrable I l f vol) (ε : ℝ) (c : ℝ≥0) : l.RCond (h.convergenceR ε c) := by rw [convergenceR]; split_ifs with h₀ exacts [(hasIntegral_iff.1 h.hasIntegral ε h₀).choose_spec.1 _, fun _ x => rfl] theorem dist_integralSum_integral_le_of_memBaseSet (h : Integrable I l f vol) (h₀ : 0 < ε) (hπ : l.MemBaseSet I c (h.convergenceR ε c) π) (hπp : π.IsPartition) : dist (integralSum f vol π) (integral I l f vol) ≀ ε := by rw [convergenceR, dif_pos h₀] at hπ exact (hasIntegral_iff.1 h.hasIntegral ε h₀).choose_spec.2 c _ hπ hπp /-- **Henstock-Sacks inequality**. Let `r₁ r₂ : ℝⁿ → (0, ∞)` be a function such that for any tagged *partition* of `I` subordinate to `rₖ`, `k=1,2`, the integral sum of `f` over this partition differs from the integral of `f` by at most `εₖ`. Then for any two tagged *prepartition* `π₁ π₂` subordinate to `r₁` and `r₂` respectively and covering the same part of `I`, the integral sums of `f` over these prepartitions differ from each other by at most `ε₁ + ε₂`. The actual statement - uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`; - uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of “subordinate to `r`” to account for additional requirements like being a Henstock partition or having a bounded distortion. See also `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq` and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet`. -/ theorem dist_integralSum_le_of_memBaseSet (h : Integrable I l f vol) (hpos₁ : 0 < ε₁) (hpos₂ : 0 < ε₂) (h₁ : l.MemBaseSet I c₁ (h.convergenceR ε₁ c₁) π₁) (h₂ : l.MemBaseSet I c₂ (h.convergenceR ε₂ c₂) π₂) (HU : π₁.iUnion = π₂.iUnion) : dist (integralSum f vol π₁) (integralSum f vol π₂) ≀ ε₁ + ε₂ := by rcases h₁.exists_common_compl h₂ HU with ⟚π, hπU, hπc₁, hπc₂⟩ set r : ℝⁿ → Ioi (0 : ℝ) := fun x => min (h.convergenceR ε₁ c₁ x) (h.convergenceR ε₂ c₂ x) set πr := π.toSubordinate r have H₁ : dist (integralSum f vol (π₁.unionComplToSubordinate π hπU r)) (integral I l f vol) ≀ ε₁ := h.dist_integralSum_integral_le_of_memBaseSet hpos₁ (h₁.unionComplToSubordinate (fun _ _ => min_le_left _ _) hπU hπc₁) (isPartition_unionComplToSubordinate _ _ _ _) rw [HU] at hπU have H₂ : dist (integralSum f vol (π₂.unionComplToSubordinate π hπU r)) (integral I l f vol) ≀ ε₂ := h.dist_integralSum_integral_le_of_memBaseSet hpos₂ (h₂.unionComplToSubordinate (fun _ _ => min_le_right _ _) hπU hπc₂) (isPartition_unionComplToSubordinate _ _ _ _) simpa [unionComplToSubordinate] using (dist_triangle_right _ _ _).trans (add_le_add H₁ H₂) /-- If `f` is integrable on `I` along `l`, then for two sufficiently fine tagged prepartitions (in the sense of the filter `BoxIntegral.IntegrationParams.toFilter l I`) such that they cover the same part of `I`, the integral sums of `f` over `π₁` and `π₂` are very close to each other. -/ theorem tendsto_integralSum_toFilter_prod_self_inf_iUnion_eq_uniformity (h : Integrable I l f vol) : Tendsto (fun π : TaggedPrepartition I × TaggedPrepartition I => (integralSum f vol π.1, integralSum f vol π.2)) ((l.toFilter I ×ˢ l.toFilter I) ⊓ 𝓟 {π | π.1.iUnion = π.2.iUnion}) (𝓀 F) := by refine (((l.hasBasis_toFilter I).prod_self.inf_principal _).tendsto_iff uniformity_basis_dist_le).2 fun ε ε0 => ?_ replace ε0 := half_pos ε0 use h.convergenceR (ε / 2), h.convergenceR_cond (ε / 2); rintro ⟚π₁, π₂⟩ ⟹⟹h₁, h₂⟩, hU⟩ rw [← add_halves ε] exact h.dist_integralSum_le_of_memBaseSet ε0 ε0 h₁.choose_spec h₂.choose_spec hU /-- If `f` is integrable on a box `I` along `l`, then for any fixed subset `s` of `I` that can be represented as a finite union of boxes, the integral sums of `f` over tagged prepartitions that cover exactly `s` form a Cauchy “sequence” along `l`. -/ theorem cauchy_map_integralSum_toFilteriUnion (h : Integrable I l f vol) (π₀ : Prepartition I) : Cauchy ((l.toFilteriUnion I π₀).map (integralSum f vol)) := by refine ⟹inferInstance, ?_⟩ rw [prod_map_map_eq, ← toFilter_inf_iUnion_eq, ← prod_inf_prod, prod_principal_principal] exact h.tendsto_integralSum_toFilter_prod_self_inf_iUnion_eq_uniformity.mono_left (inf_le_inf_left _ <| principal_mono.2 fun π h => h.1.trans h.2.symm) variable [CompleteSpace F] theorem to_subbox_aux (h : Integrable I l f vol) (hJ : J ≀ I) : ∃ y : F, HasIntegral J l f vol y ∧ Tendsto (integralSum f vol) (l.toFilteriUnion I (Prepartition.single I J hJ)) (𝓝 y) := by refine (cauchy_map_iff_exists_tendsto.1 (h.cauchy_map_integralSum_toFilteriUnion (.single I J hJ))).imp fun y hy ↩ ⟹?_, hy⟩ convert hy.comp (l.tendsto_embedBox_toFilteriUnion_top hJ) -- faster than `exact` here /-- If `f` is integrable on a box `I`, then it is integrable on any subbox of `I`. -/ theorem to_subbox (h : Integrable I l f vol) (hJ : J ≀ I) : Integrable J l f vol := (h.to_subbox_aux hJ).imp fun _ => And.left /-- If `f` is integrable on a box `I`, then integral sums of `f` over tagged prepartitions that cover exactly a subbox `J ≀ I` tend to the integral of `f` over `J` along `l`. -/ theorem tendsto_integralSum_toFilteriUnion_single (h : Integrable I l f vol) (hJ : J ≀ I) : Tendsto (integralSum f vol) (l.toFilteriUnion I (Prepartition.single I J hJ)) (𝓝 <| integral J l f vol) := let ⟹_y, h₁, h₂⟩ := h.to_subbox_aux hJ h₁.integral_eq.symm ▾ h₂ /-- **Henstock-Sacks inequality**. Let `r : ℝⁿ → (0, ∞)` be a function such that for any tagged *partition* of `I` subordinate to `r`, the integral sum of `f` over this partition differs from the integral of `f` by at most `ε`. Then for any tagged *prepartition* `π` subordinate to `r`, the integral sum of `f` over this prepartition differs from the integral of `f` over the part of `I` covered by `π` by at most `ε`. The actual statement - uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`; - uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of “subordinate to `r`” to account for additional requirements like being a Henstock partition or having a bounded distortion; - takes an extra argument `π₀ : prepartition I` and an assumption `π.Union = π₀.Union` instead of using `π.to_prepartition`. -/ theorem dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq (h : Integrable I l f vol) (h0 : 0 < ε) (hπ : l.MemBaseSet I c (h.convergenceR ε c) π) {π₀ : Prepartition I} (hU : π.iUnion = π₀.iUnion) : dist (integralSum f vol π) (∑ J ∈ π₀.boxes, integral J l f vol) ≀ ε := by -- Let us prove that the distance is less than or equal to `ε + ÎŽ` for all positive `ÎŽ`. refine le_of_forall_pos_le_add fun ÎŽ ÎŽ0 => ?_ -- First we choose some constants. set ÎŽ' : ℝ := ÎŽ / (π₀.boxes.card + 1) have H0 : 0 < (π₀.boxes.card + 1 : ℝ) := Nat.cast_add_one_pos _ have ÎŽ'0 : 0 < ÎŽ' := div_pos ÎŽ0 H0 set C := max π₀.distortion π₀.compl.distortion /- Next we choose a tagged partition of each `J ∈ π₀` such that the integral sum of `f` over this partition is `ÎŽ'`-close to the integral of `f` over `J`. -/ have : ∀ J ∈ π₀, ∃ πi : TaggedPrepartition J, πi.IsPartition ∧ dist (integralSum f vol πi) (integral J l f vol) ≀ ÎŽ' ∧ l.MemBaseSet J C (h.convergenceR ÎŽ' C) πi := by intro J hJ have Hle : J ≀ I := π₀.le_of_mem hJ have HJi : Integrable J l f vol := h.to_subbox Hle set r := fun x => min (h.convergenceR ÎŽ' C x) (HJi.convergenceR ÎŽ' C x) have hJd : J.distortion ≀ C := le_trans (Finset.le_sup hJ) (le_max_left _ _) rcases l.exists_memBaseSet_isPartition J hJd r with ⟚πJ, hC, hp⟩ have hC₁ : l.MemBaseSet J C (HJi.convergenceR ÎŽ' C) πJ := by refine hC.mono J le_rfl le_rfl fun x _ => ?_; exact min_le_right _ _ have hC₂ : l.MemBaseSet J C (h.convergenceR ÎŽ' C) πJ := by refine hC.mono J le_rfl le_rfl fun x _ => ?_; exact min_le_left _ _ exact ⟚πJ, hp, HJi.dist_integralSum_integral_le_of_memBaseSet ÎŽ'0 hC₁ hp, hC₂⟩ /- Now we combine these tagged partitions into a tagged prepartition of `I` that covers the same part of `I` as `π₀` and apply `BoxIntegral.dist_integralSum_le_of_memBaseSet` to `π` and this prepartition. -/ choose! πi hπip hπiÎŽ' hπiC using this have : l.MemBaseSet I C (h.convergenceR ÎŽ' C) (π₀.biUnionTagged πi) := biUnionTagged_memBaseSet hπiC hπip fun _ => le_max_right _ _ have hU' : π.iUnion = (π₀.biUnionTagged πi).iUnion := hU.trans (Prepartition.iUnion_biUnion_partition _ hπip).symm have := h.dist_integralSum_le_of_memBaseSet h0 ÎŽ'0 hπ this hU' rw [integralSum_biUnionTagged] at this calc dist (integralSum f vol π) (∑ J ∈ π₀.boxes, integral J l f vol) ≀ dist (integralSum f vol π) (∑ J ∈ π₀.boxes, integralSum f vol (πi J)) + dist (∑ J ∈ π₀.boxes, integralSum f vol (πi J)) (∑ J ∈ π₀.boxes, integral J l f vol) := dist_triangle _ _ _ _ ≀ ε + ÎŽ' + ∑ _J ∈ π₀.boxes, ÎŽ' := add_le_add this (dist_sum_sum_le_of_le _ hπiÎŽ') _ = ε + ÎŽ := by field_simp [ÎŽ']; ring /-- **Henstock-Sacks inequality**. Let `r : ℝⁿ → (0, ∞)` be a function such that for any tagged *partition* of `I` subordinate to `r`, the integral sum of `f` over this partition differs from the integral of `f` by at most `ε`. Then for any tagged *prepartition* `π` subordinate to `r`, the integral sum of `f` over this prepartition differs from the integral of `f` over the part of `I` covered by `π` by at most `ε`. The actual statement - uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`; - uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of “subordinate to `r`” to account for additional requirements like being a Henstock partition or having a bounded distortion; -/ theorem dist_integralSum_sum_integral_le_of_memBaseSet (h : Integrable I l f vol) (h0 : 0 < ε) (hπ : l.MemBaseSet I c (h.convergenceR ε c) π) : dist (integralSum f vol π) (∑ J ∈ π.boxes, integral J l f vol) ≀ ε := h.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq h0 hπ rfl /-- Integral sum of `f` over a tagged prepartition `π` such that `π.Union = π₀.Union` tends to the sum of integrals of `f` over the boxes of `π₀`. -/ theorem tendsto_integralSum_sum_integral (h : Integrable I l f vol) (π₀ : Prepartition I) : Tendsto (integralSum f vol) (l.toFilteriUnion I π₀) (𝓝 <| ∑ J ∈ π₀.boxes, integral J l f vol) := by refine ((l.hasBasis_toFilteriUnion I π₀).tendsto_iff nhds_basis_closedBall).2 fun ε ε0 => ?_ refine ⟹h.convergenceR ε, h.convergenceR_cond ε, ?_⟩ simp only [mem_inter_iff, Set.mem_iUnion, mem_setOf_eq] rintro π ⟹c, hc, hU⟩ exact h.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq ε0 hc hU /-- If `f` is integrable on `I`, then `fun J ↩ integral J l f vol` is box-additive on subboxes of `I`: if `π₁`, `π₂` are two prepartitions of `I` covering the same part of `I`, the sum of integrals of `f` over the boxes of `π₁` is equal to the sum of integrals of `f` over the boxes of `π₂`. See also `BoxIntegral.Integrable.toBoxAdditive` for a bundled version. -/ theorem sum_integral_congr (h : Integrable I l f vol) {π₁ π₂ : Prepartition I} (hU : π₁.iUnion = π₂.iUnion) : ∑ J ∈ π₁.boxes, integral J l f vol = ∑ J ∈ π₂.boxes, integral J l f vol := by refine tendsto_nhds_unique (h.tendsto_integralSum_sum_integral π₁) ?_ rw [l.toFilteriUnion_congr _ hU] exact h.tendsto_integralSum_sum_integral π₂ /-- If `f` is integrable on `I`, then `fun J ↩ integral J l f vol` is box-additive on subboxes of `I`: if `π₁`, `π₂` are two prepartitions of `I` covering the same part of `I`, the sum of integrals of `f` over the boxes of `π₁` is equal to the sum of integrals of `f` over the boxes of `π₂`. See also `BoxIntegral.Integrable.sum_integral_congr` for an unbundled version. -/ @[simps] def toBoxAdditive (h : Integrable I l f vol) : ι →ᵇᵃ[I] F where toFun J := integral J l f vol sum_partition_boxes' J hJ π hπ := by replace hπ := hπ.iUnion_eq; rw [← Prepartition.iUnion_top] at hπ rw [(h.to_subbox (WithTop.coe_le_coe.1 hJ)).sum_integral_congr hπ, Prepartition.top_boxes, sum_singleton] end Integrable open MeasureTheory /-! ### Integrability conditions -/ open Prepartition EMetric ENNReal BoxAdditiveMap Finset Metric TaggedPrepartition variable (l) /-- A function that is bounded and a.e. continuous on a box `I` is integrable on `I`. -/ theorem integrable_of_bounded_and_ae_continuousWithinAt [CompleteSpace E] {I : Box ι} {f : ℝⁿ → E} (hb : ∃ C : ℝ, ∀ x ∈ Box.Icc I, ‖f x‖ ≀ C) (ÎŒ : Measure ℝⁿ) [IsLocallyFiniteMeasure ÎŒ] (hc : ∀ᵐ x ∂(ÎŒ.restrict (Box.Icc I)), ContinuousWithinAt f (Box.Icc I) x) : Integrable I l f ÎŒ.toBoxAdditive.toSMul := by /- We prove that f is integrable by proving that we can ensure that the integralSums over any two tagged prepartitions π₁ and π₂ can be made ε-close by making the partitions sufficiently fine. Start by defining some constants C, ε₁, ε₂ that will be useful later. -/ refine integrable_iff_cauchy_basis.2 fun ε ε0 ↩ ?_ rcases exists_pos_mul_lt ε0 (2 * ÎŒ.toBoxAdditive I) with ⟚ε₁, ε₁0, hε₁⟩ rcases hb with ⟹C, hC⟩ have C0 : 0 ≀ C := by obtain ⟹x, hx⟩ := BoxIntegral.Box.nonempty_coe I exact le_trans (norm_nonneg (f x)) <| hC x (I.coe_subset_Icc hx) rcases exists_pos_mul_lt ε0 (4 * C) with ⟚ε₂, ε₂0, hε₂⟩ have ε₂0' : ENNReal.ofReal ε₂ ≠ 0 := ne_of_gt <| ofReal_pos.2 ε₂0 -- The set of discontinuities of f is contained in an open set U with ÎŒ U < ε₂. let D := { x ∈ Box.Icc I | ¬ ContinuousWithinAt f (Box.Icc I) x } let ÎŒ' := ÎŒ.restrict (Box.Icc I) have ÎŒ'D : ÎŒ' D = 0 := by rcases eventually_iff_exists_mem.1 hc with ⟹V, ae, hV⟩ exact eq_of_le_of_not_lt (mem_ae_iff.1 ae ▾ (ÎŒ'.mono <| fun x h xV ↩ h.2 (hV x xV))) not_lt_zero obtain ⟹U, UD, Uopen, hU⟩ := Set.exists_isOpen_lt_add D (show ÎŒ' D ≠ ⊀ by simp [ÎŒ'D]) ε₂0' rw [ÎŒ'D, zero_add] at hU /- Box.Icc I \ U is compact and avoids discontinuities of f, so there exists r > 0 such that for every x ∈ Box.Icc I \ U, the oscillation (within Box.Icc I) of f on the ball of radius r centered at x is ≀ ε₁ -/ have comp : IsCompact (Box.Icc I \ U) := I.isCompact_Icc.of_isClosed_subset (I.isCompact_Icc.isClosed.sdiff Uopen) Set.diff_subset have : ∀ x ∈ (Box.Icc I \ U), oscillationWithin f (Box.Icc I) x < (ENNReal.ofReal ε₁) := by intro x hx suffices oscillationWithin f (Box.Icc I) x = 0 by rw [this]; exact ofReal_pos.2 ε₁0 simpa [OscillationWithin.eq_zero_iff_continuousWithinAt, D, hx.1] using hx.2 ∘ (fun a ↩ UD a) rcases comp.uniform_oscillationWithin this with ⟹r, r0, hr⟩ /- We prove the claim for partitions π₁ and π₂ subordinate to r/2, by writing the difference as an integralSum over π₁ ⊓ π₂ and considering separately the boxes of π₁ ⊓ π₂ which are/aren't fully contained within U. -/ refine ⟹fun _ _ ↩ ⟹r / 2, half_pos r0⟩, fun _ _ _ ↩ rfl, fun c₁ c₂ π₁ π₂ h₁ h₁p h₂ h₂p ↩ ?_⟩ simp only [dist_eq_norm, integralSum_sub_partitions _ _ h₁p h₂p, toSMul_apply, ← smul_sub] have ÎŒI : ÎŒ I < ⊀ := lt_of_le_of_lt (ÎŒ.mono I.coe_subset_Icc) I.isCompact_Icc.measure_lt_top let t₁ (J : Box ι) : ℝⁿ := (π₁.infPrepartition π₂.toPrepartition).tag J let t₂ (J : Box ι) : ℝⁿ := (π₂.infPrepartition π₁.toPrepartition).tag J let B := (π₁.toPrepartition ⊓ π₂.toPrepartition).boxes classical let B' := B.filter (fun J ↩ J.toSet ⊆ U) have hB' : B' ⊆ B := B.filter_subset (fun J ↩ J.toSet ⊆ U) have ÎŒJ_ne_top : ∀ J ∈ B, ÎŒ J ≠ ⊀ := fun J hJ ↩ lt_top_iff_ne_top.1 <| lt_of_le_of_lt (ÎŒ.mono (Prepartition.le_of_mem' _ J hJ)) ÎŒI have un : ∀ S ⊆ B, ⋃ J ∈ S, J.toSet ⊆ I.toSet := fun S hS ↩ iUnion_subset_iff.2 (fun J ↩ iUnion_subset_iff.2 fun hJ ↩ le_of_mem' _ J (hS hJ)) rw [← sum_sdiff hB', ← add_halves ε] apply le_trans (norm_add_le _ _) (add_le_add ?_ ?_) /- If a box J is not contained within U, then the oscillation of f on J is small, which bounds the contribution of J to the overall sum. -/ · have : ∀ J ∈ B \ B', ‖Ό.toBoxAdditive J • (f (t₁ J) - f (t₂ J))‖ ≀ ÎŒ.toBoxAdditive J * ε₁ := by intro J hJ rw [mem_sdiff, B.mem_filter, not_and] at hJ rw [norm_smul, ÎŒ.toBoxAdditive_apply, Real.norm_of_nonneg toReal_nonneg] refine mul_le_mul_of_nonneg_left ?_ toReal_nonneg obtain ⟹x, xJ, xnU⟩ : ∃ x ∈ J, x ∉ U := Set.not_subset.1 (hJ.2 hJ.1) have hx : x ∈ Box.Icc I \ U := ⟹Box.coe_subset_Icc ((le_of_mem' _ J hJ.1) xJ), xnU⟩ have ineq : edist (f (t₁ J)) (f (t₂ J)) ≀ EMetric.diam (f '' (ball x r ∩ (Box.Icc I))) := by apply edist_le_diam_of_mem <;> refine Set.mem_image_of_mem f ⟹?_, tag_mem_Icc _ J⟩ <;> refine closedBall_subset_ball (div_two_lt_of_pos r0) <| mem_closedBall_comm.1 ?_ · exact h₁.isSubordinate.infPrepartition π₂.toPrepartition J hJ.1 (Box.coe_subset_Icc xJ) · exact h₂.isSubordinate.infPrepartition π₁.toPrepartition J ((π₁.mem_infPrepartition_comm).1 hJ.1) (Box.coe_subset_Icc xJ) rw [← emetric_ball] at ineq simpa only [edist_le_ofReal (le_of_lt ε₁0), dist_eq_norm, hJ.1] using ineq.trans (hr x hx) refine (norm_sum_le _ _).trans <| (sum_le_sum this).trans ?_ rw [← sum_mul] trans ÎŒ.toBoxAdditive I * ε₁; swap · linarith simp_rw [mul_le_mul_right ε₁0, ÎŒ.toBoxAdditive_apply] refine le_trans ?_ <| toReal_mono (lt_top_iff_ne_top.1 ÎŒI) <| ÎŒ.mono <| un (B \ B') sdiff_subset rw [← toReal_sum (fun J hJ ↩ ÎŒJ_ne_top J (mem_sdiff.1 hJ).1), ← Finset.tsum_subtype] refine (toReal_mono <| ne_of_lt <| lt_of_le_of_lt (ÎŒ.mono <| un (B \ B') sdiff_subset) ÎŒI) ?_ refine le_of_eq (measure_biUnion (countable_toSet _) ?_ (fun J _ ↩ J.measurableSet_coe)).symm exact fun J hJ J' hJ' hJJ' ↩ pairwiseDisjoint _ (mem_sdiff.1 hJ).1 (mem_sdiff.1 hJ').1 hJJ' -- The contribution of the boxes contained within U is bounded because f is bounded and ÎŒ U < ε₂. · have : ∀ J ∈ B', ‖Ό.toBoxAdditive J • (f (t₁ J) - f (t₂ J))‖ ≀ ÎŒ.toBoxAdditive J * (2 * C) := by intro J _ rw [norm_smul, ÎŒ.toBoxAdditive_apply, Real.norm_of_nonneg toReal_nonneg, two_mul] refine mul_le_mul_of_nonneg_left (le_trans (norm_sub_le _ _) (add_le_add ?_ ?_)) (by simp) <;> exact hC _ (TaggedPrepartition.tag_mem_Icc _ J) apply (norm_sum_le_of_le B' this).trans simp_rw [← sum_mul, ÎŒ.toBoxAdditive_apply, ← toReal_sum (fun J hJ ↩ ÎŒJ_ne_top J (hB' hJ))] suffices (∑ J in B', ÎŒ J).toReal ≀ ε₂ by linarith [mul_le_mul_of_nonneg_right this <| (mul_nonneg_iff_of_pos_left two_pos).2 C0] rw [← toReal_ofReal (le_of_lt ε₂0)] refine toReal_mono ofReal_ne_top (le_trans ?_ (le_of_lt hU)) trans ÎŒ' (⋃ J ∈ B', J) · simp only [ÎŒ', ÎŒ.restrict_eq_self <| (un _ hB').trans I.coe_subset_Icc] exact le_of_eq <| Eq.symm <| measure_biUnion_finset (fun J hJ K hK hJK ↩ pairwiseDisjoint _ (hB' hJ) (hB' hK) hJK) fun J _ ↩ J.measurableSet_coe · apply ÎŒ'.mono simp_rw [iUnion_subset_iff] exact fun J hJ ↩ (mem_filter.1 hJ).2 /-- A function that is bounded on a box `I` and a.e. continuous is integrable on `I`. This is a version of `integrable_of_bounded_and_ae_continuousWithinAt` with a stronger continuity assumption so that the user does not need to specialize the continuity assumption to each box on which the theorem is to be applied. -/ theorem integrable_of_bounded_and_ae_continuous [CompleteSpace E] {I : Box ι} {f : ℝⁿ → E} (hb : ∃ C : ℝ, ∀ x ∈ Box.Icc I, ‖f x‖ ≀ C) (ÎŒ : Measure ℝⁿ) [IsLocallyFiniteMeasure ÎŒ] (hc : ∀ᵐ x ∂Ό, ContinuousAt f x) : Integrable I l f ÎŒ.toBoxAdditive.toSMul := integrable_of_bounded_and_ae_continuousWithinAt l hb ÎŒ <| Eventually.filter_mono (ae_mono ÎŒ.restrict_le_self) (hc.mono fun _ h ↩ h.continuousWithinAt) /-- A continuous function is box-integrable with respect to any locally finite measure. This is true for any volume with bounded variation. -/ theorem integrable_of_continuousOn [CompleteSpace E] {I : Box ι} {f : ℝⁿ → E} (hc : ContinuousOn f (Box.Icc I)) (ÎŒ : Measure ℝⁿ) [IsLocallyFiniteMeasure ÎŒ] : Integrable.{u, v, v} I l f ÎŒ.toBoxAdditive.toSMul := by apply integrable_of_bounded_and_ae_continuousWithinAt · obtain ⟹C, hC⟩ := (NormedSpace.isBounded_iff_subset_smul_closedBall ℝ).1 (I.isCompact_Icc.image_of_continuousOn hc).isBounded use ‖C‖, fun x hx ↩ by simpa only [smul_closedUnitBall, mem_closedBall_zero_iff] using hC (Set.mem_image_of_mem f hx) · refine eventually_of_mem ?_ (fun x hx ↩ hc.continuousWithinAt hx) rw [mem_ae_iff, ÎŒ.restrict_apply] <;> simp [MeasurableSet.compl_iff.2 I.measurableSet_Icc] variable {l} /-- This is an auxiliary lemma used to prove two statements at once. Use one of the next two lemmas instead. -/ theorem HasIntegral.of_bRiemann_eq_false_of_forall_isLittleO (hl : l.bRiemann = false) (B : ι →ᵇᵃ[I] ℝ) (hB0 : ∀ J, 0 ≀ B J) (g : ι →ᵇᵃ[I] F) (s : Set ℝⁿ) (hs : s.Countable) (hlH : s.Nonempty → l.bHenstock = true) (H₁ : ∀ (c : ℝ≥0), ∀ x ∈ Box.Icc I ∩ s, ∀ ε > (0 : ℝ), ∃ ÎŽ > 0, ∀ J ≀ I, Box.Icc J ⊆ Metric.closedBall x ÎŽ → x ∈ Box.Icc J → (l.bDistortion → J.distortion ≀ c) → dist (vol J (f x)) (g J) ≀ ε) (H₂ : ∀ (c : ℝ≥0), ∀ x ∈ Box.Icc I \ s, ∀ ε > (0 : ℝ), ∃ ÎŽ > 0, ∀ J ≀ I, Box.Icc J ⊆ Metric.closedBall x ÎŽ → (l.bHenstock → x ∈ Box.Icc J) → (l.bDistortion → J.distortion ≀ c) → dist (vol J (f x)) (g J) ≀ ε * B J) : HasIntegral I l f vol (g I) := by /- We choose `r x` differently for `x ∈ s` and `x ∉ s`. For `x ∈ s`, we choose `εs` such that `∑' x : s, εs x < ε / 2 / 2 ^ #ι`, then choose `r x` so that `dist (vol J (f x)) (g J) ≀ εs x` for `J` in the `r x`-neighborhood of `x`. This guarantees that the sum of these distances over boxes `J` such that `π.tag J ∈ s` is less than `ε / 2`. We need an additional multiplier `2 ^ #ι` because different boxes can have the same tag. For `x ∉ s`, we choose `r x` so that `dist (vol (J (f x))) (g J) ≀ (ε / 2 / B I) * B J` for a box `J` in the `ÎŽ`-neighborhood of `x`. -/ refine ((l.hasBasis_toFilteriUnion_top _).tendsto_iff Metric.nhds_basis_closedBall).2 ?_ intro ε ε0 simp only [← exists_prop, gt_iff_lt, Subtype.exists'] at H₁ H₂ choose! ή₁ Hή₁ using H₁ choose! ή₂ Hή₂ using H₂ have ε0' := half_pos ε0; have H0 : 0 < (2 : ℝ) ^ Fintype.card ι := pow_pos zero_lt_two _ rcases hs.exists_pos_forall_sum_le (div_pos ε0' H0) with ⟚εs, hεs0, hεs⟩ simp only [le_div_iff' H0, mul_sum] at hεs rcases exists_pos_mul_lt ε0' (B I) with ⟚ε', ε'0, hεI⟩ classical set ÎŽ : ℝ≥0 → ℝⁿ → Ioi (0 : ℝ) := fun c x => if x ∈ s then ή₁ c x (εs x) else (ή₂ c) x ε' refine ⟹ή, fun c => l.rCond_of_bRiemann_eq_false hl, ?_⟩ simp only [Set.mem_iUnion, mem_inter_iff, mem_setOf_eq] rintro π ⟹c, hπΎ, hπp⟩ -- Now we split the sum into two parts based on whether `π.tag J` belongs to `s` or not. rw [← g.sum_partition_boxes le_rfl hπp, Metric.mem_closedBall, integralSum, ← sum_filter_add_sum_filter_not π.boxes fun J => π.tag J ∈ s, ← sum_filter_add_sum_filter_not π.boxes fun J => π.tag J ∈ s, ← add_halves ε] refine dist_add_add_le_of_le ?_ ?_ · rcases s.eq_empty_or_nonempty with (rfl | hsne); · simp [ε0'.le] /- For the boxes such that `π.tag J ∈ s`, we use the fact that at most `2 ^ #ι` boxes have the same tag. -/ specialize hlH hsne have : ∀ J ∈ π.boxes.filter fun J => π.tag J ∈ s, dist (vol J (f <| π.tag J)) (g J) ≀ εs (π.tag J) := fun J hJ ↩ by rw [Finset.mem_filter] at hJ; cases' hJ with hJ hJs refine Hή₁ c _ ⟚π.tag_mem_Icc _, hJs⟩ _ (hεs0 _) _ (π.le_of_mem' _ hJ) ?_ (hπΎ.2 hlH J hJ) fun hD => (Finset.le_sup hJ).trans (hπΎ.3 hD) convert hπΎ.1 J hJ using 3; exact (if_pos hJs).symm refine (dist_sum_sum_le_of_le _ this).trans ?_ rw [sum_comp] refine (sum_le_sum ?_).trans (hεs _ ?_) · rintro b - rw [← Nat.cast_two, ← Nat.cast_pow, ← nsmul_eq_mul] refine nsmul_le_nsmul_left (hεs0 _).le ?_ refine (Finset.card_le_card ?_).trans ((hπΎ.isHenstock hlH).card_filter_tag_eq_le b) exact filter_subset_filter _ (filter_subset _ _) · rw [Finset.coe_image, Set.image_subset_iff] exact fun J hJ => (Finset.mem_filter.1 hJ).2 /- Now we deal with boxes such that `π.tag J ∉ s`. In this case the estimate is straightforward. -/ -- Porting note: avoided strange elaboration issues by rewriting using `calc` calc dist (∑ J ∈ π.boxes.filter (¬tag π · ∈ s), vol J (f (tag π J))) (∑ J ∈ π.boxes.filter (¬tag π · ∈ s), g J) ≀ ∑ J ∈ π.boxes.filter (¬tag π · ∈ s), ε' * B J := dist_sum_sum_le_of_le _ fun J hJ ↩ by rw [Finset.mem_filter] at hJ; cases' hJ with hJ hJs refine Hή₂ c _ ⟚π.tag_mem_Icc _, hJs⟩ _ ε'0 _ (π.le_of_mem' _ hJ) ?_ (fun hH => hπΎ.2 hH J hJ) fun hD => (Finset.le_sup hJ).trans (hπΎ.3 hD) convert hπΎ.1 J hJ using 3; exact (if_neg hJs).symm _ ≀ ∑ J ∈ π.boxes, ε' * B J := sum_le_sum_of_subset_of_nonneg (filter_subset _ _) fun _ _ _ ↩ mul_nonneg ε'0.le (hB0 _) _ = B I * ε' := by rw [← mul_sum, B.sum_partition_boxes le_rfl hπp, mul_comm] _ ≀ ε / 2 := hεI.le /-- A function `f` has Henstock (or `⊥`) integral over `I` is equal to the value of a box-additive function `g` on `I` provided that `vol J (f x)` is sufficiently close to `g J` for sufficiently small boxes `J ∋ x`. This lemma is useful to prove, e.g., to prove the Divergence theorem for integral along `⊥`. Let `l` be either `BoxIntegral.IntegrationParams.Henstock` or `⊥`. Let `g` a box-additive function on subboxes of `I`. Suppose that there exists a nonnegative box-additive function `B` and a countable set `s` with the following property. For every `c : ℝ≥0`, a point `x ∈ I.Icc`, and a positive `ε` there exists `ÎŽ > 0` such that for any box `J ≀ I` such that - `x ∈ J.Icc ⊆ Metric.closedBall x ÎŽ`; - if `l.bDistortion` (i.e., `l = ⊥`), then the distortion of `J` is less than or equal to `c`, the distance between the term `vol J (f x)` of an integral sum corresponding to `J` and `g J` is less than or equal to `ε` if `x ∈ s` and is less than or equal to `ε * B J` otherwise. Then `f` is integrable on `I` along `l` with integral `g I`. -/ theorem HasIntegral.of_le_Henstock_of_forall_isLittleO (hl : l ≀ Henstock) (B : ι →ᵇᵃ[I] ℝ) (hB0 : ∀ J, 0 ≀ B J) (g : ι →ᵇᵃ[I] F) (s : Set ℝⁿ) (hs : s.Countable) (H₁ : ∀ (c : ℝ≥0), ∀ x ∈ Box.Icc I ∩ s, ∀ ε > (0 : ℝ), ∃ ÎŽ > 0, ∀ J ≀ I, Box.Icc J ⊆ Metric.closedBall x ÎŽ → x ∈ Box.Icc J → (l.bDistortion → J.distortion ≀ c) → dist (vol J (f x)) (g J) ≀ ε) (H₂ : ∀ (c : ℝ≥0), ∀ x ∈ Box.Icc I \ s, ∀ ε > (0 : ℝ), ∃ ÎŽ > 0, ∀ J ≀ I, Box.Icc J ⊆ Metric.closedBall x ÎŽ → x ∈ Box.Icc J → (l.bDistortion → J.distortion ≀ c) → dist (vol J (f x)) (g J) ≀ ε * B J) : HasIntegral I l f vol (g I) := have A : l.bHenstock := Bool.eq_true_of_true_le hl.2.1 HasIntegral.of_bRiemann_eq_false_of_forall_isLittleO (Bool.eq_false_of_le_false hl.1) B hB0 _ s hs (fun _ => A) H₁ <| by simpa only [A, true_imp_iff] using H₂ /-- Suppose that there exists a nonnegative box-additive function `B` with the following property. For every `c : ℝ≥0`, a point `x ∈ I.Icc`, and a positive `ε` there exists `ÎŽ > 0` such that for any box `J ≀ I` such that - `J.Icc ⊆ Metric.closedBall x ÎŽ`; - if `l.bDistortion` (i.e., `l = ⊥`), then the distortion of `J` is less than or equal to `c`, the distance between the term `vol J (f x)` of an integral sum corresponding to `J` and `g J` is less than or equal to `ε * B J`. Then `f` is McShane integrable on `I` with integral `g I`. -/ theorem HasIntegral.mcShane_of_forall_isLittleO (B : ι →ᵇᵃ[I] ℝ) (hB0 : ∀ J, 0 ≀ B J) (g : ι →ᵇᵃ[I] F) (H : ∀ (c : ℝ≥0), ∀ x ∈ Box.Icc I, ∀ ε > (0 : ℝ), ∃ ÎŽ > 0, ∀ J ≀ I, Box.Icc J ⊆ Metric.closedBall x ÎŽ → dist (vol J (f x)) (g J) ≀ ε * B J) : HasIntegral I McShane f vol (g I) := (HasIntegral.of_bRiemann_eq_false_of_forall_isLittleO (l := McShane) rfl B hB0 g ∅ countable_empty (fun ⟹_x, hx⟩ => hx.elim) fun c x hx => hx.2.elim) <| by simpa only [McShane, Bool.coe_sort_false, false_imp_iff, true_imp_iff, diff_empty] using H end BoxIntegral
Analysis\BoxIntegral\DivergenceTheorem.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Basic import Mathlib.Analysis.BoxIntegral.Partition.Additive import Mathlib.Analysis.Calculus.FDeriv.Prod /-! # Divergence integral for Henstock-Kurzweil integral In this file we prove the Divergence Theorem for a Henstock-Kurzweil style integral. The theorem says the following. Let `f : ℝⁿ → Eⁿ` be a function differentiable on a closed rectangular box `I` with derivative `f' x : ℝⁿ →L[ℝ] Eⁿ` at `x ∈ I`. Then the divergence `fun x ↩ ∑ k, f' x eₖ k`, where `eₖ = Pi.single k 1` is the `k`-th basis vector, is integrable on `I`, and its integral is equal to the sum of integrals of `f` over the faces of `I` taken with appropriate signs. To make the proof work, we had to ban tagged partitions with “long and thin” boxes. More precisely, we use the following generalization of one-dimensional Henstock-Kurzweil integral to functions defined on a box in `ℝⁿ` (it corresponds to the value `BoxIntegral.IntegrationParams.GP = ⊥` of `BoxIntegral.IntegrationParams` in the definition of `BoxIntegral.HasIntegral`). We say that `f : ℝⁿ → E` has integral `y : E` over a box `I ⊆ ℝⁿ` if for an arbitrarily small positive `ε` and an arbitrarily large `c`, there exists a function `r : ℝⁿ → (0, ∞)` such that for any tagged partition `π` of `I` such that * `π` is a Henstock partition, i.e., each tag belongs to its box; * `π` is subordinate to `r`; * for every box of `π`, the maximum of the ratios of its sides is less than or equal to `c`, the integral sum of `f` over `π` is `ε`-close to `y`. In case of dimension one, the last condition trivially holds for any `c ≥ 1`, so this definition is equivalent to the standard definition of Henstock-Kurzweil integral. ## Tags Henstock-Kurzweil integral, integral, Stokes theorem, divergence theorem -/ open scoped NNReal ENNReal Topology BoxIntegral open ContinuousLinearMap (lsmul) open Filter Set Finset Metric open BoxIntegral.IntegrationParams (GP gp_le) noncomputable section universe u variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℝ E] {n : ℕ} namespace BoxIntegral variable [CompleteSpace E] (I : Box (Fin (n + 1))) {i : Fin (n + 1)} open MeasureTheory /-- Auxiliary lemma for the divergence theorem. -/ theorem norm_volume_sub_integral_face_upper_sub_lower_smul_le {f : (Fin (n + 1) → ℝ) → E} {f' : (Fin (n + 1) → ℝ) →L[ℝ] E} (hfc : ContinuousOn f (Box.Icc I)) {x : Fin (n + 1) → ℝ} (hxI : x ∈ (Box.Icc I)) {a : E} {ε : ℝ} (h0 : 0 < ε) (hε : ∀ y ∈ (Box.Icc I), ‖f y - a - f' (y - x)‖ ≀ ε * ‖y - x‖) {c : ℝ≥0} (hc : I.distortion ≀ c) : ‖(∏ j, (I.upper j - I.lower j)) • f' (Pi.single i 1) - (integral (I.face i) ⊥ (f ∘ i.insertNth (α := fun _ ↩ ℝ) (I.upper i)) BoxAdditiveMap.volume - integral (I.face i) ⊥ (f ∘ i.insertNth (α := fun _ ↩ ℝ) (I.lower i)) BoxAdditiveMap.volume)‖ ≀ 2 * ε * c * ∏ j, (I.upper j - I.lower j) := by -- Porting note: Lean fails to find `α` in the next line set e : ℝ → (Fin n → ℝ) → (Fin (n + 1) → ℝ) := i.insertNth (α := fun _ ↩ ℝ) /- **Plan of the proof**. The difference of the integrals of the affine function `fun y ↩ a + f' (y - x)` over the faces `x i = I.upper i` and `x i = I.lower i` is equal to the volume of `I` multiplied by `f' (Pi.single i 1)`, so it suffices to show that the integral of `f y - a - f' (y - x)` over each of these faces is less than or equal to `ε * c * vol I`. We integrate a function of the norm `≀ ε * diam I.Icc` over a box of volume `∏ j ≠ i, (I.upper j - I.lower j)`. Since `diam I.Icc ≀ c * (I.upper i - I.lower i)`, we get the required estimate. -/ have Hl : I.lower i ∈ Icc (I.lower i) (I.upper i) := Set.left_mem_Icc.2 (I.lower_le_upper i) have Hu : I.upper i ∈ Icc (I.lower i) (I.upper i) := Set.right_mem_Icc.2 (I.lower_le_upper i) have Hi : ∀ x ∈ Icc (I.lower i) (I.upper i), Integrable.{0, u, u} (I.face i) ⊥ (f ∘ e x) BoxAdditiveMap.volume := fun x hx => integrable_of_continuousOn _ (Box.continuousOn_face_Icc hfc hx) volume /- We start with an estimate: the difference of the values of `f` at the corresponding points of the faces `x i = I.lower i` and `x i = I.upper i` is `(2 * ε * diam I.Icc)`-close to the value of `f'` on `Pi.single i (I.upper i - I.lower i) = láµ¢ • eáµ¢`, where `láµ¢ = I.upper i - I.lower i` is the length of `i`-th edge of `I` and `eáµ¢ = Pi.single i 1` is the `i`-th unit vector. -/ have : ∀ y ∈ Box.Icc (I.face i), ‖f' (Pi.single i (I.upper i - I.lower i)) - (f (e (I.upper i) y) - f (e (I.lower i) y))‖ ≀ 2 * ε * diam (Box.Icc I) := fun y hy ↩ by set g := fun y => f y - a - f' (y - x) with hg change ∀ y ∈ (Box.Icc I), ‖g y‖ ≀ ε * ‖y - x‖ at hε clear_value g; obtain rfl : f = fun y => a + f' (y - x) + g y := by simp [hg] convert_to ‖g (e (I.lower i) y) - g (e (I.upper i) y)‖ ≀ _ · congr 1 have := Fin.insertNth_sub_same (α := fun _ ↩ ℝ) i (I.upper i) (I.lower i) y simp only [← this, f'.map_sub]; abel · have : ∀ z ∈ Icc (I.lower i) (I.upper i), e z y ∈ (Box.Icc I) := fun z hz => I.mapsTo_insertNth_face_Icc hz hy replace hε : ∀ y ∈ (Box.Icc I), ‖g y‖ ≀ ε * diam (Box.Icc I) := by intro y hy refine (hε y hy).trans (mul_le_mul_of_nonneg_left ?_ h0.le) rw [← dist_eq_norm] exact dist_le_diam_of_mem I.isCompact_Icc.isBounded hy hxI rw [two_mul, add_mul] exact norm_sub_le_of_le (hε _ (this _ Hl)) (hε _ (this _ Hu)) calc ‖(∏ j, (I.upper j - I.lower j)) • f' (Pi.single i 1) - (integral (I.face i) ⊥ (f ∘ e (I.upper i)) BoxAdditiveMap.volume - integral (I.face i) ⊥ (f ∘ e (I.lower i)) BoxAdditiveMap.volume)‖ = ‖integral.{0, u, u} (I.face i) ⊥ (fun x : Fin n → ℝ => f' (Pi.single i (I.upper i - I.lower i)) - (f (e (I.upper i) x) - f (e (I.lower i) x))) BoxAdditiveMap.volume‖ := by rw [← integral_sub (Hi _ Hu) (Hi _ Hl), ← Box.volume_face_mul i, mul_smul, ← Box.volume_apply, ← BoxAdditiveMap.toSMul_apply, ← integral_const, ← BoxAdditiveMap.volume, ← integral_sub (integrable_const _) ((Hi _ Hu).sub (Hi _ Hl))] simp only [(· ∘ ·), Pi.sub_def, ← f'.map_smul, ← Pi.single_smul', smul_eq_mul, mul_one] _ ≀ (volume (I.face i : Set (Fin n → ℝ))).toReal * (2 * ε * c * (I.upper i - I.lower i)) := by -- The hard part of the estimate was done above, here we just replace `diam I.Icc` -- with `c * (I.upper i - I.lower i)` refine norm_integral_le_of_le_const (fun y hy => (this y hy).trans ?_) volume rw [mul_assoc (2 * ε)] gcongr exact I.diam_Icc_le_of_distortion_le i hc _ = 2 * ε * c * ∏ j, (I.upper j - I.lower j) := by rw [← Measure.toBoxAdditive_apply, Box.volume_apply, ← I.volume_face_mul i] ac_rfl /-- If `f : ℝⁿ⁺¹ → E` is differentiable on a closed rectangular box `I` with derivative `f'`, then the partial derivative `fun x ↩ f' x (Pi.single i 1)` is Henstock-Kurzweil integrable with integral equal to the difference of integrals of `f` over the faces `x i = I.upper i` and `x i = I.lower i`. More precisely, we use a non-standard generalization of the Henstock-Kurzweil integral and we allow `f` to be non-differentiable (but still continuous) at a countable set of points. TODO: If `n > 0`, then the condition at `x ∈ s` can be replaced by a much weaker estimate but this requires either better integrability theorems, or usage of a filter depending on the countable set `s` (we need to ensure that none of the faces of a partition contain a point from `s`). -/ theorem hasIntegral_GP_pderiv (f : (Fin (n + 1) → ℝ) → E) (f' : (Fin (n + 1) → ℝ) → (Fin (n + 1) → ℝ) →L[ℝ] E) (s : Set (Fin (n + 1) → ℝ)) (hs : s.Countable) (Hs : ∀ x ∈ s, ContinuousWithinAt f (Box.Icc I) x) (Hd : ∀ x ∈ (Box.Icc I) \ s, HasFDerivWithinAt f (f' x) (Box.Icc I) x) (i : Fin (n + 1)) : HasIntegral.{0, u, u} I GP (fun x => f' x (Pi.single i 1)) BoxAdditiveMap.volume (integral.{0, u, u} (I.face i) GP (fun x => f (i.insertNth (I.upper i) x)) BoxAdditiveMap.volume - integral.{0, u, u} (I.face i) GP (fun x => f (i.insertNth (I.lower i) x)) BoxAdditiveMap.volume) := by /- Note that `f` is continuous on `I.Icc`, hence it is integrable on the faces of all boxes `J ≀ I`, thus the difference of integrals over `x i = J.upper i` and `x i = J.lower i` is a box-additive function of `J ≀ I`. -/ have Hc : ContinuousOn f (Box.Icc I) := fun x hx ↩ by by_cases hxs : x ∈ s exacts [Hs x hxs, (Hd x ⟹hx, hxs⟩).continuousWithinAt] set fI : ℝ → Box (Fin n) → E := fun y J => integral.{0, u, u} J GP (fun x => f (i.insertNth y x)) BoxAdditiveMap.volume set fb : Icc (I.lower i) (I.upper i) → Fin n →ᵇᵃ[↑(I.face i)] E := fun x => (integrable_of_continuousOn GP (Box.continuousOn_face_Icc Hc x.2) volume).toBoxAdditive set F : Fin (n + 1) →ᵇᵃ[I] E := BoxAdditiveMap.upperSubLower I i fI fb fun x _ J => rfl -- Thus our statement follows from some local estimates. change HasIntegral I GP (fun x => f' x (Pi.single i 1)) _ (F I) refine HasIntegral.of_le_Henstock_of_forall_isLittleO gp_le ?_ ?_ _ s hs ?_ ?_ ·-- We use the volume as an upper estimate. exact (volume : Measure (Fin (n + 1) → ℝ)).toBoxAdditive.restrict _ le_top · exact fun J => ENNReal.toReal_nonneg · intro c x hx ε ε0 /- Near `x ∈ s` we choose `ÎŽ` so that both vectors are small. `volume J • eáµ¢` is small because `volume J ≀ (2 * ÎŽ) ^ (n + 1)` is small, and the difference of the integrals is small because each of the integrals is close to `volume (J.face i) • f x`. TODO: there should be a shorter and more readable way to formalize this simple proof. -/ have : ∀ᶠ ÎŽ in 𝓝[>] (0 : ℝ), ÎŽ ∈ Ioc (0 : ℝ) (1 / 2) ∧ (∀ᵉ (y₁ ∈ closedBall x ÎŽ ∩ (Box.Icc I)) (y₂ ∈ closedBall x ÎŽ ∩ (Box.Icc I)), ‖f y₁ - f y₂‖ ≀ ε / 2) ∧ (2 * ÎŽ) ^ (n + 1) * ‖f' x (Pi.single i 1)‖ ≀ ε / 2 := by refine .and ?_ (.and ?_ ?_) · exact Ioc_mem_nhdsWithin_Ioi ⟹le_rfl, one_half_pos⟩ · rcases ((nhdsWithin_hasBasis nhds_basis_closedBall _).tendsto_iff nhds_basis_closedBall).1 (Hs x hx.2) _ (half_pos <| half_pos ε0) with ⟹ή₁, ή₁0, hΎ₁⟩ filter_upwards [Ioc_mem_nhdsWithin_Ioi ⟹le_rfl, ή₁0⟩] with ÎŽ hÎŽ y₁ hy₁ y₂ hy₂ have : closedBall x ÎŽ ∩ (Box.Icc I) ⊆ closedBall x ή₁ ∩ (Box.Icc I) := by gcongr; exact hÎŽ.2 rw [← dist_eq_norm] calc dist (f y₁) (f y₂) ≀ dist (f y₁) (f x) + dist (f y₂) (f x) := dist_triangle_right _ _ _ _ ≀ ε / 2 / 2 + ε / 2 / 2 := add_le_add (hή₁ _ <| this hy₁) (hή₁ _ <| this hy₂) _ = ε / 2 := add_halves _ · have : ContinuousWithinAt (fun ÎŽ : ℝ => (2 * ÎŽ) ^ (n + 1) * ‖f' x (Pi.single i 1)‖) (Ioi 0) 0 := ((continuousWithinAt_id.const_mul _).pow _).mul_const _ refine this.eventually (ge_mem_nhds ?_) simpa using half_pos ε0 rcases this.exists with ⟹ή, ⟹hÎŽ0, hÎŽ12⟩, hdfÎŽ, hΎ⟩ refine ⟹ή, hÎŽ0, fun J hJI hJÎŽ _ _ => add_halves ε ▾ ?_⟩ have Hl : J.lower i ∈ Icc (J.lower i) (J.upper i) := Set.left_mem_Icc.2 (J.lower_le_upper i) have Hu : J.upper i ∈ Icc (J.lower i) (J.upper i) := Set.right_mem_Icc.2 (J.lower_le_upper i) have Hi : ∀ x ∈ Icc (J.lower i) (J.upper i), Integrable.{0, u, u} (J.face i) GP (fun y => f (i.insertNth x y)) BoxAdditiveMap.volume := fun x hx => integrable_of_continuousOn _ (Box.continuousOn_face_Icc (Hc.mono <| Box.le_iff_Icc.1 hJI) hx) volume have hJÎŽ' : Box.Icc J ⊆ closedBall x ÎŽ ∩ (Box.Icc I) := subset_inter hJÎŽ (Box.le_iff_Icc.1 hJI) have Hmaps : ∀ z ∈ Icc (J.lower i) (J.upper i), MapsTo (i.insertNth z) (Box.Icc (J.face i)) (closedBall x ÎŽ ∩ (Box.Icc I)) := fun z hz => (J.mapsTo_insertNth_face_Icc hz).mono Subset.rfl hJÎŽ' simp only [dist_eq_norm]; dsimp [F] rw [← integral_sub (Hi _ Hu) (Hi _ Hl)] refine (norm_sub_le _ _).trans (add_le_add ?_ ?_) · simp_rw [BoxAdditiveMap.volume_apply, norm_smul, Real.norm_eq_abs, abs_prod] refine (mul_le_mul_of_nonneg_right ?_ <| norm_nonneg _).trans hÎŽ have : ∀ j, |J.upper j - J.lower j| ≀ 2 * ÎŽ := fun j ↩ calc dist (J.upper j) (J.lower j) ≀ dist J.upper J.lower := dist_le_pi_dist _ _ _ _ ≀ dist J.upper x + dist J.lower x := dist_triangle_right _ _ _ _ ≀ ÎŽ + ÎŽ := add_le_add (hJÎŽ J.upper_mem_Icc) (hJÎŽ J.lower_mem_Icc) _ = 2 * ÎŽ := (two_mul ÎŽ).symm calc ∏ j, |J.upper j - J.lower j| ≀ ∏ j : Fin (n + 1), 2 * ÎŽ := prod_le_prod (fun _ _ => abs_nonneg _) fun j _ => this j _ = (2 * ÎŽ) ^ (n + 1) := by simp · refine (norm_integral_le_of_le_const (fun y hy => hdfÎŽ _ (Hmaps _ Hu hy) _ (Hmaps _ Hl hy)) volume).trans ?_ refine (mul_le_mul_of_nonneg_right ?_ (half_pos ε0).le).trans_eq (one_mul _) rw [Box.coe_eq_pi, Real.volume_pi_Ioc_toReal (Box.lower_le_upper _)] refine prod_le_one (fun _ _ => sub_nonneg.2 <| Box.lower_le_upper _ _) fun j _ => ?_ calc J.upper (i.succAbove j) - J.lower (i.succAbove j) ≀ dist (J.upper (i.succAbove j)) (J.lower (i.succAbove j)) := le_abs_self _ _ ≀ dist J.upper J.lower := dist_le_pi_dist J.upper J.lower (i.succAbove j) _ ≀ dist J.upper x + dist J.lower x := dist_triangle_right _ _ _ _ ≀ ÎŽ + ÎŽ := add_le_add (hJÎŽ J.upper_mem_Icc) (hJÎŽ J.lower_mem_Icc) _ ≀ 1 / 2 + 1 / 2 := by gcongr _ = 1 := add_halves 1 · intro c x hx ε ε0 /- At a point `x ∉ s`, we unfold the definition of Fréchet differentiability, then use an estimate we proved earlier in this file. -/ rcases exists_pos_mul_lt ε0 (2 * c) with ⟚ε', ε'0, hlt⟩ rcases (nhdsWithin_hasBasis nhds_basis_closedBall _).mem_iff.1 ((Hd x hx).isLittleO.def ε'0) with ⟹ή, ÎŽ0, HΎ⟩ refine ⟹ή, ÎŽ0, fun J hle hJÎŽ hxJ hJc => ?_⟩ simp only [BoxAdditiveMap.volume_apply, Box.volume_apply, dist_eq_norm] refine (norm_volume_sub_integral_face_upper_sub_lower_smul_le _ (Hc.mono <| Box.le_iff_Icc.1 hle) hxJ ε'0 (fun y hy => HÎŽ ?_) (hJc rfl)).trans ?_ · exact ⟹hJÎŽ hy, Box.le_iff_Icc.1 hle hy⟩ · rw [mul_right_comm (2 : ℝ), ← Box.volume_apply] exact mul_le_mul_of_nonneg_right hlt.le ENNReal.toReal_nonneg /-- Divergence theorem for a Henstock-Kurzweil style integral. If `f : ℝⁿ⁺¹ → Eⁿ⁺¹` is differentiable on a closed rectangular box `I` with derivative `f'`, then the divergence `∑ i, f' x (Pi.single i 1) i` is Henstock-Kurzweil integrable with integral equal to the sum of integrals of `f` over the faces of `I` taken with appropriate signs. More precisely, we use a non-standard generalization of the Henstock-Kurzweil integral and we allow `f` to be non-differentiable (but still continuous) at a countable set of points. -/ theorem hasIntegral_GP_divergence_of_forall_hasDerivWithinAt (f : (Fin (n + 1) → ℝ) → Fin (n + 1) → E) (f' : (Fin (n + 1) → ℝ) → (Fin (n + 1) → ℝ) →L[ℝ] (Fin (n + 1) → E)) (s : Set (Fin (n + 1) → ℝ)) (hs : s.Countable) (Hs : ∀ x ∈ s, ContinuousWithinAt f (Box.Icc I) x) (Hd : ∀ x ∈ (Box.Icc I) \ s, HasFDerivWithinAt f (f' x) (Box.Icc I) x) : HasIntegral.{0, u, u} I GP (fun x => ∑ i, f' x (Pi.single i 1) i) BoxAdditiveMap.volume (∑ i, (integral.{0, u, u} (I.face i) GP (fun x => f (i.insertNth (I.upper i) x) i) BoxAdditiveMap.volume - integral.{0, u, u} (I.face i) GP (fun x => f (i.insertNth (I.lower i) x) i) BoxAdditiveMap.volume)) := by refine HasIntegral.sum fun i _ => ?_ simp only [hasFDerivWithinAt_pi', continuousWithinAt_pi] at Hd Hs exact hasIntegral_GP_pderiv I _ _ s hs (fun x hx => Hs x hx i) (fun x hx => Hd x hx i) i end BoxIntegral
Analysis\BoxIntegral\Integrability.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Basic import Mathlib.MeasureTheory.Integral.SetIntegral import Mathlib.Tactic.Generalize /-! # McShane integrability vs Bochner integrability In this file we prove that any Bochner integrable function is McShane integrable (hence, it is Henstock and `GP` integrable) with the same integral. The proof is based on [Russel A. Gordon, *The integrals of Lebesgue, Denjoy, Perron, and Henstock*][Gordon55]. We deduce that the same is true for the Riemann integral for continuous functions. ## Tags integral, McShane integral, Bochner integral -/ open scoped NNReal ENNReal Topology universe u v variable {ι : Type u} {E : Type v} [Fintype ι] [NormedAddCommGroup E] [NormedSpace ℝ E] open MeasureTheory Metric Set Finset Filter BoxIntegral namespace BoxIntegral /-- The indicator function of a measurable set is McShane integrable with respect to any locally-finite measure. -/ theorem hasIntegralIndicatorConst (l : IntegrationParams) (hl : l.bRiemann = false) {s : Set (ι → ℝ)} (hs : MeasurableSet s) (I : Box ι) (y : E) (ÎŒ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure ÎŒ] : HasIntegral.{u, v, v} I l (s.indicator fun _ => y) ÎŒ.toBoxAdditive.toSMul ((ÎŒ (s ∩ I)).toReal • y) := by refine HasIntegral.of_mul ‖y‖ fun ε ε0 => ?_ lift ε to ℝ≥0 using ε0.le; rw [NNReal.coe_pos] at ε0 /- First we choose a closed set `F ⊆ s ∩ I.Icc` and an open set `U ⊇ s` such that both `(s ∩ I.Icc) \ F` and `U \ s` have measure less than `ε`. -/ have A : ÎŒ (s ∩ Box.Icc I) ≠ ∞ := ((measure_mono Set.inter_subset_right).trans_lt (I.measure_Icc_lt_top ÎŒ)).ne have B : ÎŒ (s ∩ I) ≠ ∞ := ((measure_mono Set.inter_subset_right).trans_lt (I.measure_coe_lt_top ÎŒ)).ne obtain ⟹F, hFs, hFc, hÎŒF⟩ : ∃ F, F ⊆ s ∩ Box.Icc I ∧ IsClosed F ∧ ÎŒ ((s ∩ Box.Icc I) \ F) < ε := (hs.inter I.measurableSet_Icc).exists_isClosed_diff_lt A (ENNReal.coe_pos.2 ε0).ne' obtain ⟹U, hsU, hUo, hUt, hÎŒU⟩ : ∃ U, s ∩ Box.Icc I ⊆ U ∧ IsOpen U ∧ ÎŒ U < ∞ ∧ ÎŒ (U \ (s ∩ Box.Icc I)) < ε := (hs.inter I.measurableSet_Icc).exists_isOpen_diff_lt A (ENNReal.coe_pos.2 ε0).ne' /- Then we choose `r` so that `closed_ball x (r x) ⊆ U` whenever `x ∈ s ∩ I.Icc` and `closed_ball x (r x)` is disjoint with `F` otherwise. -/ have : ∀ x ∈ s ∩ Box.Icc I, ∃ r : Ioi (0 : ℝ), closedBall x r ⊆ U := fun x hx => by rcases nhds_basis_closedBall.mem_iff.1 (hUo.mem_nhds <| hsU hx) with ⟹r, hr₀, hr⟩ exact ⟹⟹r, hr₀⟩, hr⟩ choose! rs hrsU using this have : ∀ x ∈ Box.Icc I \ s, ∃ r : Ioi (0 : ℝ), closedBall x r ⊆ Fᶜ := fun x hx => by obtain ⟹r, hr₀, hr⟩ := nhds_basis_closedBall.mem_iff.1 (hFc.isOpen_compl.mem_nhds fun hx' => hx.2 (hFs hx').1) exact ⟹⟹r, hr₀⟩, hr⟩ choose! rs' hrs'F using this classical set r : (ι → ℝ) → Ioi (0 : ℝ) := s.piecewise rs rs' refine ⟹fun _ => r, fun c => l.rCond_of_bRiemann_eq_false hl, fun c π hπ hπp => ?_⟩; rw [mul_comm] /- Then the union of boxes `J ∈ π` such that `π.tag ∈ s` includes `F` and is included by `U`, hence its measure is `ε`-close to the measure of `s`. -/ dsimp [integralSum] simp only [mem_closedBall, dist_eq_norm, ← indicator_const_smul_apply, sum_indicator_eq_sum_filter, ← sum_smul, ← sub_smul, norm_smul, Real.norm_eq_abs, ← Prepartition.filter_boxes, ← Prepartition.measure_iUnion_toReal] gcongr set t := (π.filter (π.tag · ∈ s)).iUnion change abs ((ÎŒ t).toReal - (ÎŒ (s ∩ I)).toReal) ≀ ε have htU : t ⊆ U ∩ I := by simp only [t, TaggedPrepartition.iUnion_def, iUnion_subset_iff, TaggedPrepartition.mem_filter, and_imp] refine fun J hJ hJs x hx => ⟹hrsU _ ⟹hJs, π.tag_mem_Icc J⟩ ?_, π.le_of_mem' J hJ hx⟩ simpa only [r, s.piecewise_eq_of_mem _ _ hJs] using hπ.1 J hJ (Box.coe_subset_Icc hx) refine abs_sub_le_iff.2 ⟹?_, ?_⟩ · refine (ENNReal.le_toReal_sub B).trans (ENNReal.toReal_le_coe_of_le_coe ?_) refine (tsub_le_tsub (measure_mono htU) le_rfl).trans (le_measure_diff.trans ?_) refine (measure_mono fun x hx => ?_).trans hÎŒU.le exact ⟹hx.1.1, fun hx' => hx.2 ⟹hx'.1, hx.1.2⟩⟩ · have hÎŒt : ÎŒ t ≠ ∞ := ((measure_mono (htU.trans inter_subset_left)).trans_lt hUt).ne refine (ENNReal.le_toReal_sub hÎŒt).trans (ENNReal.toReal_le_coe_of_le_coe ?_) refine le_measure_diff.trans ((measure_mono ?_).trans hÎŒF.le) rintro x ⟹⟹hxs, hxI⟩, hxt⟩ refine ⟹⟹hxs, Box.coe_subset_Icc hxI⟩, fun hxF => hxt ?_⟩ simp only [t, TaggedPrepartition.iUnion_def, TaggedPrepartition.mem_filter, Set.mem_iUnion] rcases hπp x hxI with ⟹J, hJπ, hxJ⟩ refine ⟹J, ⟹hJπ, ?_⟩, hxJ⟩ contrapose hxF refine hrs'F _ ⟚π.tag_mem_Icc J, hxF⟩ ?_ simpa only [r, s.piecewise_eq_of_not_mem _ _ hxF] using hπ.1 J hJπ (Box.coe_subset_Icc hxJ) /-- If `f` is a.e. equal to zero on a rectangular box, then it has McShane integral zero on this box. -/ theorem HasIntegral.of_aeEq_zero {l : IntegrationParams} {I : Box ι} {f : (ι → ℝ) → E} {ÎŒ : Measure (ι → ℝ)} [IsLocallyFiniteMeasure ÎŒ] (hf : f =ᵐ[ÎŒ.restrict I] 0) (hl : l.bRiemann = false) : HasIntegral.{u, v, v} I l f ÎŒ.toBoxAdditive.toSMul 0 := by /- Each set `{x | n < ‖f x‖ ≀ n + 1}`, `n : ℕ`, has measure zero. We cover it by an open set of measure less than `ε / 2 ^ n / (n + 1)`. Then the norm of the integral sum is less than `ε`. -/ refine hasIntegral_iff.2 fun ε ε0 => ?_ lift ε to ℝ≥0 using ε0.lt.le; rw [gt_iff_lt, NNReal.coe_pos] at ε0 rcases NNReal.exists_pos_sum_of_countable ε0.ne' ℕ with ⟹ή, ÎŽ0, c, hÎŽc, hcε⟩ haveI := Fact.mk (I.measure_coe_lt_top ÎŒ) change ÎŒ.restrict I {x | f x ≠ 0} = 0 at hf set N : (ι → ℝ) → ℕ := fun x => ⌈‖f x‖⌉₊ have N0 : ∀ {x}, N x = 0 ↔ f x = 0 := by simp [N] have : ∀ n, ∃ U, N ⁻¹' {n} ⊆ U ∧ IsOpen U ∧ ÎŒ.restrict I U < ÎŽ n / n := fun n ↩ by refine (N ⁻¹' {n}).exists_isOpen_lt_of_lt _ ?_ cases' n with n · simpa [ENNReal.div_zero (ENNReal.coe_pos.2 (ÎŽ0 _)).ne'] using measure_lt_top (ÎŒ.restrict I) _ · refine (measure_mono_null ?_ hf).le.trans_lt ?_ · exact fun x hxN hxf => n.succ_ne_zero ((Eq.symm hxN).trans <| N0.2 hxf) · simp [(ÎŽ0 _).ne'] choose U hNU hUo hÎŒU using this have : ∀ x, ∃ r : Ioi (0 : ℝ), closedBall x r ⊆ U (N x) := fun x => by obtain ⟹r, hr₀, hr⟩ := nhds_basis_closedBall.mem_iff.1 ((hUo _).mem_nhds (hNU _ rfl)) exact ⟹⟹r, hr₀⟩, hr⟩ choose r hrU using this refine ⟹fun _ => r, fun c => l.rCond_of_bRiemann_eq_false hl, fun c π hπ _ => ?_⟩ rw [dist_eq_norm, sub_zero, ← integralSum_fiberwise fun J => N (π.tag J)] refine le_trans ?_ (NNReal.coe_lt_coe.2 hcε).le refine (norm_sum_le_of_le _ ?_).trans (sum_le_hasSum _ (fun n _ => (ÎŽ n).2) (NNReal.hasSum_coe.2 hÎŽc)) rintro n - dsimp [integralSum] have : ∀ J ∈ π.filter fun J => N (π.tag J) = n, ‖(ÎŒ ↑J).toReal • f (π.tag J)‖ ≀ (ÎŒ J).toReal * n := fun J hJ ↩ by rw [TaggedPrepartition.mem_filter] at hJ rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ENNReal.toReal_nonneg] gcongr exact hJ.2 ▾ Nat.le_ceil _ refine (norm_sum_le_of_le _ this).trans ?_; clear this rw [← sum_mul, ← Prepartition.measure_iUnion_toReal] let m := ÎŒ (π.filter fun J => N (π.tag J) = n).iUnion show m.toReal * ↑n ≀ ↑(ÎŽ n) have : m < ÎŽ n / n := by simp only [Measure.restrict_apply (hUo _).measurableSet] at hÎŒU refine (measure_mono ?_).trans_lt (hÎŒU _) simp only [Set.subset_def, TaggedPrepartition.mem_iUnion, TaggedPrepartition.mem_filter] rintro x ⟹J, ⟹hJ, rfl⟩, hx⟩ exact ⟹hrU _ (hπ.1 _ hJ (Box.coe_subset_Icc hx)), π.le_of_mem' J hJ hx⟩ clear_value m lift m to ℝ≥0 using ne_top_of_lt this rw [ENNReal.coe_toReal, ← NNReal.coe_natCast, ← NNReal.coe_mul, NNReal.coe_le_coe, ← ENNReal.coe_le_coe, ENNReal.coe_mul, ENNReal.coe_natCast, mul_comm] exact (mul_le_mul_left' this.le _).trans ENNReal.mul_div_le /-- If `f` has integral `y` on a box `I` with respect to a locally finite measure `ÎŒ` and `g` is a.e. equal to `f` on `I`, then `g` has the same integral on `I`. -/ theorem HasIntegral.congr_ae {l : IntegrationParams} {I : Box ι} {y : E} {f g : (ι → ℝ) → E} {ÎŒ : Measure (ι → ℝ)} [IsLocallyFiniteMeasure ÎŒ] (hf : HasIntegral.{u, v, v} I l f ÎŒ.toBoxAdditive.toSMul y) (hfg : f =ᵐ[ÎŒ.restrict I] g) (hl : l.bRiemann = false) : HasIntegral.{u, v, v} I l g ÎŒ.toBoxAdditive.toSMul y := by have : g - f =ᵐ[ÎŒ.restrict I] 0 := hfg.mono fun x hx => sub_eq_zero.2 hx.symm simpa using hf.add (HasIntegral.of_aeEq_zero this hl) end BoxIntegral namespace MeasureTheory namespace SimpleFunc /-- A simple function is McShane integrable w.r.t. any locally finite measure. -/ theorem hasBoxIntegral (f : SimpleFunc (ι → ℝ) E) (ÎŒ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure ÎŒ] (I : Box ι) (l : IntegrationParams) (hl : l.bRiemann = false) : HasIntegral.{u, v, v} I l f ÎŒ.toBoxAdditive.toSMul (f.integral (ÎŒ.restrict I)) := by induction' f using MeasureTheory.SimpleFunc.induction with y s hs f g _ hfi hgi · simpa only [Measure.restrict_apply hs, const_zero, integral_piecewise_zero, integral_const, Measure.restrict_apply, MeasurableSet.univ, Set.univ_inter] using BoxIntegral.hasIntegralIndicatorConst l hl hs I y ÎŒ · borelize E; haveI := Fact.mk (I.measure_coe_lt_top ÎŒ) rw [integral_add] exacts [hfi.add hgi, integrable_iff.2 fun _ _ => measure_lt_top _ _, integrable_iff.2 fun _ _ => measure_lt_top _ _] /-- For a simple function, its McShane (or Henstock, or `⊥`) box integral is equal to its integral in the sense of `MeasureTheory.SimpleFunc.integral`. -/ theorem box_integral_eq_integral (f : SimpleFunc (ι → ℝ) E) (ÎŒ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure ÎŒ] (I : Box ι) (l : IntegrationParams) (hl : l.bRiemann = false) : BoxIntegral.integral.{u, v, v} I l f ÎŒ.toBoxAdditive.toSMul = f.integral (ÎŒ.restrict I) := (f.hasBoxIntegral ÎŒ I l hl).integral_eq end SimpleFunc open TopologicalSpace /-- If `f : ℝⁿ → E` is Bochner integrable w.r.t. a locally finite measure `ÎŒ` on a rectangular box `I`, then it is McShane integrable on `I` with the same integral. -/ theorem IntegrableOn.hasBoxIntegral [CompleteSpace E] {f : (ι → ℝ) → E} {ÎŒ : Measure (ι → ℝ)} [IsLocallyFiniteMeasure ÎŒ] {I : Box ι} (hf : IntegrableOn f I ÎŒ) (l : IntegrationParams) (hl : l.bRiemann = false) : HasIntegral.{u, v, v} I l f ÎŒ.toBoxAdditive.toSMul (∫ x in I, f x ∂Ό) := by borelize E -- First we replace an `ae_strongly_measurable` function by a measurable one. rcases hf.aestronglyMeasurable with ⟹g, hg, hfg⟩ haveI : SeparableSpace (range g ∪ {0} : Set E) := hg.separableSpace_range_union_singleton rw [integral_congr_ae hfg]; have hgi : IntegrableOn g I ÎŒ := (integrable_congr hfg).1 hf refine BoxIntegral.HasIntegral.congr_ae ?_ hfg.symm hl clear! f /- Now consider the sequence of simple functions `SimpleFunc.approxOn g hg.measurable (range g ∪ {0}) 0 (by simp)` approximating `g`. Recall some properties of this sequence. -/ set f : ℕ → SimpleFunc (ι → ℝ) E := SimpleFunc.approxOn g hg.measurable (range g ∪ {0}) 0 (by simp) have hfi : ∀ n, IntegrableOn (f n) I ÎŒ := SimpleFunc.integrable_approxOn_range hg.measurable hgi have hfi' := fun n => ((f n).hasBoxIntegral ÎŒ I l hl).integrable have hfg_mono : ∀ (x) {m n}, m ≀ n → ‖f n x - g x‖ ≀ ‖f m x - g x‖ := by intro x m n hmn rw [← dist_eq_norm, ← dist_eq_norm, dist_nndist, dist_nndist, NNReal.coe_le_coe, ← ENNReal.coe_le_coe, ← edist_nndist, ← edist_nndist] exact SimpleFunc.edist_approxOn_mono hg.measurable _ x hmn /- Now consider `ε > 0`. We need to find `r` such that for any tagged partition subordinate to `r`, the integral sum is `(ÎŒ I + 1 + 1) * ε`-close to the Bochner integral. -/ refine HasIntegral.of_mul ((ÎŒ I).toReal + 1 + 1) fun ε ε0 => ?_ lift ε to ℝ≥0 using ε0.le; rw [NNReal.coe_pos] at ε0; have ε0' := ENNReal.coe_pos.2 ε0 -- Choose `N` such that the integral of `‖f N x - g x‖` is less than or equal to `ε`. obtain ⟹N₀, hN₀⟩ : ∃ N : ℕ, ∫ x in I, ‖f N x - g x‖ ∂Ό ≀ ε := by have : Tendsto (fun n => ∫⁻ x in I, ‖f n x - g x‖₊ ∂Ό) atTop (𝓝 0) := SimpleFunc.tendsto_approxOn_range_L1_nnnorm hg.measurable hgi refine (this.eventually (ge_mem_nhds ε0')).exists.imp fun N hN => ?_ exact integral_coe_le_of_lintegral_coe_le hN -- For each `x`, we choose `Nx x ≥ N₀` such that `dist (f Nx x) (g x) ≀ ε`. have : ∀ x, ∃ N₁, N₀ ≀ N₁ ∧ dist (f N₁ x) (g x) ≀ ε := fun x ↩ by have : Tendsto (f · x) atTop (𝓝 <| g x) := SimpleFunc.tendsto_approxOn hg.measurable _ (subset_closure (by simp)) exact ((eventually_ge_atTop N₀).and <| this <| closedBall_mem_nhds _ ε0).exists choose Nx hNx hNxε using this -- We also choose a convergent series with `∑' i : ℕ, ÎŽ i < ε`. rcases NNReal.exists_pos_sum_of_countable ε0.ne' ℕ with ⟹ή, ÎŽ0, c, hÎŽc, hcε⟩ /- Since each simple function `fáµ¢` is integrable, there exists `ráµ¢ : ℝⁿ → (0, ∞)` such that the integral sum of `f` over any tagged prepartition is `ÎŽáµ¢`-close to the sum of integrals of `fáµ¢` over the boxes of this prepartition. For each `x`, we choose `r (Nx x)` as the radius at `x`. -/ set r : ℝ≥0 → (ι → ℝ) → Ioi (0 : ℝ) := fun c x => (hfi' <| Nx x).convergenceR (ÎŽ <| Nx x) c x refine ⟹r, fun c => l.rCond_of_bRiemann_eq_false hl, fun c π hπ hπp => ?_⟩ /- Now we prove the estimate in 3 "jumps": first we replace `g x` in the formula for the integral sum by `f (Nx x)`; then we replace each `ÎŒ J • f (Nx (π.tag J)) (π.tag J)` by the Bochner integral of `f (Nx (π.tag J)) x` over `J`, then we jump to the Bochner integral of `g`. -/ refine (dist_triangle4 _ (∑ J ∈ π.boxes, (ÎŒ J).toReal • f (Nx <| π.tag J) (π.tag J)) (∑ J ∈ π.boxes, ∫ x in J, f (Nx <| π.tag J) x ∂Ό) _).trans ?_ rw [add_mul, add_mul, one_mul] refine add_le_add_three ?_ ?_ ?_ · /- Since each `f (Nx <| π.tag J)` is `ε`-close to `g (π.tag J)`, replacing the latter with the former in the formula for the integral sum changes the sum at most by `ÎŒ I * ε`. -/ rw [← hπp.iUnion_eq, π.measure_iUnion_toReal, sum_mul, integralSum] refine dist_sum_sum_le_of_le _ fun J _ => ?_; dsimp rw [dist_eq_norm, ← smul_sub, norm_smul, Real.norm_eq_abs, abs_of_nonneg ENNReal.toReal_nonneg] gcongr rw [← dist_eq_norm']; exact hNxε _ · /- We group the terms of both sums by the values of `Nx (π.tag J)`. For each `N`, the sum of Bochner integrals over the boxes is equal to the sum of box integrals, and the sum of box integrals is `ÎŽáµ¢`-close to the corresponding integral sum due to the Henstock-Sacks inequality. -/ rw [← π.sum_fiberwise fun J => Nx (π.tag J), ← π.sum_fiberwise fun J => Nx (π.tag J)] refine le_trans ?_ (NNReal.coe_lt_coe.2 hcε).le refine (dist_sum_sum_le_of_le _ fun n hn => ?_).trans (sum_le_hasSum _ (fun n _ => (ÎŽ n).2) (NNReal.hasSum_coe.2 hÎŽc)) have hNxn : ∀ J ∈ π.filter fun J => Nx (π.tag J) = n, Nx (π.tag J) = n := fun J hJ => (π.mem_filter.1 hJ).2 have hrn : ∀ J ∈ π.filter fun J => Nx (π.tag J) = n, r c (π.tag J) = (hfi' n).convergenceR (ÎŽ n) c (π.tag J) := fun J hJ ↩ by obtain rfl := hNxn J hJ rfl have : l.MemBaseSet I c ((hfi' n).convergenceR (ÎŽ n) c) (π.filter fun J => Nx (π.tag J) = n) := (hπ.filter _).mono' _ le_rfl le_rfl fun J hJ => (hrn J hJ).le convert (hfi' n).dist_integralSum_sum_integral_le_of_memBaseSet (ÎŽ0 _) this using 2 · refine sum_congr rfl fun J hJ => ?_ simp [hNxn J hJ] · refine sum_congr rfl fun J hJ => ?_ rw [← SimpleFunc.integral_eq_integral, SimpleFunc.box_integral_eq_integral _ _ _ _ hl, hNxn J hJ] exact (hfi _).mono_set (Prepartition.le_of_mem _ hJ) · /- For the last jump, we use the fact that the distance between `f (Nx x) x` and `g x` is less than or equal to the distance between `f N₀ x` and `g x` and the integral of `‖f N₀ x - g x‖` is less than or equal to `ε`. -/ refine le_trans ?_ hN₀ have hfi : ∀ (n), ∀ J ∈ π, IntegrableOn (f n) (↑J) ÎŒ := fun n J hJ => (hfi n).mono_set (π.le_of_mem' J hJ) have hgi : ∀ J ∈ π, IntegrableOn g (↑J) ÎŒ := fun J hJ => hgi.mono_set (π.le_of_mem' J hJ) have hfgi : ∀ (n), ∀ J ∈ π, IntegrableOn (fun x => ‖f n x - g x‖) J ÎŒ := fun n J hJ => ((hfi n J hJ).sub (hgi J hJ)).norm rw [← hπp.iUnion_eq, Prepartition.iUnion_def', integral_finset_biUnion π.boxes (fun J _ => J.measurableSet_coe) π.pairwiseDisjoint hgi, integral_finset_biUnion π.boxes (fun J _ => J.measurableSet_coe) π.pairwiseDisjoint (hfgi _)] refine dist_sum_sum_le_of_le _ fun J hJ => ?_ rw [dist_eq_norm, ← integral_sub (hfi _ J hJ) (hgi J hJ)] refine norm_integral_le_of_norm_le (hfgi _ J hJ) (eventually_of_forall fun x => ?_) exact hfg_mono x (hNx (π.tag J)) /-- If `f : ℝⁿ → E` is continuous on a rectangular box `I`, then it is Box integrable on `I` w.r.t. a locally finite measure `ÎŒ` with the same integral. -/ theorem ContinuousOn.hasBoxIntegral [CompleteSpace E] {f : (ι → ℝ) → E} (ÎŒ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure ÎŒ] {I : Box ι} (hc : ContinuousOn f (Box.Icc I)) (l : IntegrationParams) : HasIntegral.{u, v, v} I l f ÎŒ.toBoxAdditive.toSMul (∫ x in I, f x ∂Ό) := by obtain ⟹y, hy⟩ := BoxIntegral.integrable_of_continuousOn l hc ÎŒ convert hy have : IntegrableOn f I ÎŒ := IntegrableOn.mono_set (hc.integrableOn_compact I.isCompact_Icc) Box.coe_subset_Icc exact HasIntegral.unique (IntegrableOn.hasBoxIntegral this ⊥ rfl) (HasIntegral.mono hy bot_le) /-- If `f : ℝⁿ → E` is a.e. continuous and bounded on a rectangular box `I`, then it is Box integrable on `I` w.r.t. a locally finite measure `ÎŒ` with the same integral. -/ theorem AEContinuous.hasBoxIntegral [CompleteSpace E] {f : (ι → ℝ) → E} (ÎŒ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure ÎŒ] {I : Box ι} (hb : ∃ C : ℝ, ∀ x ∈ Box.Icc I, ‖f x‖ ≀ C) (hc : ∀ᵐ x ∂Ό, ContinuousAt f x) (l : IntegrationParams) : HasIntegral.{u, v, v} I l f ÎŒ.toBoxAdditive.toSMul (∫ x in I, f x ∂Ό) := by obtain ⟹y, hy⟩ := integrable_of_bounded_and_ae_continuous l hb ÎŒ hc convert hy refine HasIntegral.unique (IntegrableOn.hasBoxIntegral ?_ ⊥ rfl) (HasIntegral.mono hy bot_le) constructor · let v := {x : (ι → ℝ) | ContinuousAt f x} have : AEStronglyMeasurable f (ÎŒ.restrict v) := (ContinuousAt.continuousOn fun _ h ↩ h).aestronglyMeasurable (measurableSet_of_continuousAt f) refine this.mono_measure (Measure.le_iff.2 fun s hs ↩ ?_) repeat rw [ÎŒ.restrict_apply hs] apply le_of_le_of_eq <| ÎŒ.mono s.inter_subset_left refine measure_eq_measure_of_null_diff s.inter_subset_left ?_ |>.symm rw [diff_self_inter, Set.diff_eq] refine (le_antisymm (zero_le (ÎŒ (s ∩ vᶜ))) ?_).symm exact le_trans (ÎŒ.mono s.inter_subset_right) (nonpos_iff_eq_zero.2 hc) · have : IsFiniteMeasure (ÎŒ.restrict (Box.Icc I)) := { measure_univ_lt_top := by simp [I.isCompact_Icc.measure_lt_top (ÎŒ := ÎŒ)] } have : IsFiniteMeasure (ÎŒ.restrict I) := isFiniteMeasure_of_le (ÎŒ.restrict (Box.Icc I)) (ÎŒ.restrict_mono Box.coe_subset_Icc (le_refl ÎŒ)) obtain ⟹C, hC⟩ := hb refine hasFiniteIntegral_of_bounded (C := C) (Filter.eventually_iff_exists_mem.2 ?_) use I, self_mem_ae_restrict I.measurableSet_coe, fun y hy ↩ hC y (I.coe_subset_Icc hy) end MeasureTheory
Analysis\BoxIntegral\Box\Basic.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Order.Fin.Tuple import Mathlib.Order.Interval.Set.Monotone import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.MetricSpace.Bounded import Mathlib.Topology.Order.MonotoneConvergence import Mathlib.Topology.MetricSpace.Pseudo.Lemmas /-! # Rectangular boxes in `ℝⁿ` In this file we define rectangular boxes in `ℝⁿ`. As usual, we represent `ℝⁿ` as the type of functions `ι → ℝ` (usually `ι = Fin n` for some `n`). When we need to interpret a box `[l, u]` as a set, we use the product `{x | ∀ i, l i < x i ∧ x i ≀ u i}` of half-open intervals `(l i, u i]`. We exclude `l i` because this way boxes of a partition are disjoint as sets in `ℝⁿ`. Currently, the only use cases for these constructions are the definitions of Riemann-style integrals (Riemann, Henstock-Kurzweil, McShane). ## Main definitions We use the same structure `BoxIntegral.Box` both for ambient boxes and for elements of a partition. Each box is stored as two points `lower upper : ι → ℝ` and a proof of `∀ i, lower i < upper i`. We define instances `Membership (ι → ℝ) (Box ι)` and `CoeTC (Box ι) (Set <| ι → ℝ)` so that each box is interpreted as the set `{x | ∀ i, x i ∈ Set.Ioc (I.lower i) (I.upper i)}`. This way boxes of a partition are pairwise disjoint and their union is exactly the original box. We require boxes to be nonempty, because this way coercion to sets is injective. The empty box can be represented as `⊥ : WithBot (BoxIntegral.Box ι)`. We define the following operations on boxes: * coercion to `Set (ι → ℝ)` and `Membership (ι → ℝ) (BoxIntegral.Box ι)` as described above; * `PartialOrder` and `SemilatticeSup` instances such that `I ≀ J` is equivalent to `(I : Set (ι → ℝ)) ⊆ J`; * `Lattice` instances on `WithBot (BoxIntegral.Box ι)`; * `BoxIntegral.Box.Icc`: the closed box `Set.Icc I.lower I.upper`; defined as a bundled monotone map from `Box ι` to `Set (ι → ℝ)`; * `BoxIntegral.Box.face I i : Box (Fin n)`: a hyperface of `I : BoxIntegral.Box (Fin (n + 1))`; * `BoxIntegral.Box.distortion`: the maximal ratio of two lengths of edges of a box; defined as the supremum of `nndist I.lower I.upper / nndist (I.lower i) (I.upper i)`. We also provide a convenience constructor `BoxIntegral.Box.mk' (l u : ι → ℝ) : WithBot (Box ι)` that returns the box `⟹l, u, _⟩` if it is nonempty and `⊥` otherwise. ## Tags rectangular box -/ open Set Function Metric Filter noncomputable section open scoped Classical open NNReal Topology namespace BoxIntegral variable {ι : Type*} /-! ### Rectangular box: definition and partial order -/ /-- A nontrivial rectangular box in `ι → ℝ` with corners `lower` and `upper`. Represents the product of half-open intervals `(lower i, upper i]`. -/ structure Box (ι : Type*) where /-- coordinates of the lower and upper corners of the box -/ (lower upper : ι → ℝ) /-- Each lower coordinate is less than its upper coordinate: i.e., the box is non-empty -/ lower_lt_upper : ∀ i, lower i < upper i attribute [simp] Box.lower_lt_upper namespace Box variable (I J : Box ι) {x y : ι → ℝ} instance : Inhabited (Box ι) := ⟹⟹0, 1, fun _ ↩ zero_lt_one⟩⟩ theorem lower_le_upper : I.lower ≀ I.upper := fun i ↩ (I.lower_lt_upper i).le theorem lower_ne_upper (i) : I.lower i ≠ I.upper i := (I.lower_lt_upper i).ne instance : Membership (ι → ℝ) (Box ι) := ⟹fun x I ↩ ∀ i, x i ∈ Ioc (I.lower i) (I.upper i)⟩ -- Porting note: added /-- The set of points in this box: this is the product of half-open intervals `(lower i, upper i]`, where `lower` and `upper` are this box' corners. -/ @[coe] def toSet (I : Box ι) : Set (ι → ℝ) := { x | x ∈ I } instance : CoeTC (Box ι) (Set <| ι → ℝ) := ⟹toSet⟩ @[simp] theorem mem_mk {l u x : ι → ℝ} {H} : x ∈ mk l u H ↔ ∀ i, x i ∈ Ioc (l i) (u i) := Iff.rfl @[simp, norm_cast] theorem mem_coe : x ∈ (I : Set (ι → ℝ)) ↔ x ∈ I := Iff.rfl theorem mem_def : x ∈ I ↔ ∀ i, x i ∈ Ioc (I.lower i) (I.upper i) := Iff.rfl theorem mem_univ_Ioc {I : Box ι} : (x ∈ pi univ fun i ↩ Ioc (I.lower i) (I.upper i)) ↔ x ∈ I := mem_univ_pi theorem coe_eq_pi : (I : Set (ι → ℝ)) = pi univ fun i ↩ Ioc (I.lower i) (I.upper i) := Set.ext fun _ ↩ mem_univ_Ioc.symm @[simp] theorem upper_mem : I.upper ∈ I := fun i ↩ right_mem_Ioc.2 <| I.lower_lt_upper i theorem exists_mem : ∃ x, x ∈ I := ⟹_, I.upper_mem⟩ theorem nonempty_coe : Set.Nonempty (I : Set (ι → ℝ)) := I.exists_mem @[simp] theorem coe_ne_empty : (I : Set (ι → ℝ)) ≠ ∅ := I.nonempty_coe.ne_empty @[simp] theorem empty_ne_coe : ∅ ≠ (I : Set (ι → ℝ)) := I.coe_ne_empty.symm instance : LE (Box ι) := ⟹fun I J ↩ ∀ ⊃x⩄, x ∈ I → x ∈ J⟩ theorem le_def : I ≀ J ↔ ∀ x ∈ I, x ∈ J := Iff.rfl theorem le_TFAE : List.TFAE [I ≀ J, (I : Set (ι → ℝ)) ⊆ J, Icc I.lower I.upper ⊆ Icc J.lower J.upper, J.lower ≀ I.lower ∧ I.upper ≀ J.upper] := by tfae_have 1 ↔ 2 · exact Iff.rfl tfae_have 2 → 3 · intro h simpa [coe_eq_pi, closure_pi_set, lower_ne_upper] using closure_mono h tfae_have 3 ↔ 4 · exact Icc_subset_Icc_iff I.lower_le_upper tfae_have 4 → 2 · exact fun h x hx i ↩ Ioc_subset_Ioc (h.1 i) (h.2 i) (hx i) tfae_finish variable {I J} @[simp, norm_cast] theorem coe_subset_coe : (I : Set (ι → ℝ)) ⊆ J ↔ I ≀ J := Iff.rfl theorem le_iff_bounds : I ≀ J ↔ J.lower ≀ I.lower ∧ I.upper ≀ J.upper := (le_TFAE I J).out 0 3 theorem injective_coe : Injective ((↑) : Box ι → Set (ι → ℝ)) := by rintro ⟹l₁, u₁, h₁⟩ ⟹l₂, u₂, h₂⟩ h simp only [Subset.antisymm_iff, coe_subset_coe, le_iff_bounds] at h congr exacts [le_antisymm h.2.1 h.1.1, le_antisymm h.1.2 h.2.2] @[simp, norm_cast] theorem coe_inj : (I : Set (ι → ℝ)) = J ↔ I = J := injective_coe.eq_iff @[ext] theorem ext (H : ∀ x, x ∈ I ↔ x ∈ J) : I = J := injective_coe <| Set.ext H theorem ne_of_disjoint_coe (h : Disjoint (I : Set (ι → ℝ)) J) : I ≠ J := mt coe_inj.2 <| h.ne I.coe_ne_empty instance : PartialOrder (Box ι) := { PartialOrder.lift ((↑) : Box ι → Set (ι → ℝ)) injective_coe with le := (· ≀ ·) } /-- Closed box corresponding to `I : BoxIntegral.Box ι`. -/ protected def Icc : Box ι ↪o Set (ι → ℝ) := OrderEmbedding.ofMapLEIff (fun I : Box ι ↩ Icc I.lower I.upper) fun I J ↩ (le_TFAE I J).out 2 0 theorem Icc_def : Box.Icc I = Icc I.lower I.upper := rfl @[simp] theorem upper_mem_Icc (I : Box ι) : I.upper ∈ Box.Icc I := right_mem_Icc.2 I.lower_le_upper @[simp] theorem lower_mem_Icc (I : Box ι) : I.lower ∈ Box.Icc I := left_mem_Icc.2 I.lower_le_upper protected theorem isCompact_Icc (I : Box ι) : IsCompact (Box.Icc I) := isCompact_Icc theorem Icc_eq_pi : Box.Icc I = pi univ fun i ↩ Icc (I.lower i) (I.upper i) := (pi_univ_Icc _ _).symm theorem le_iff_Icc : I ≀ J ↔ Box.Icc I ⊆ Box.Icc J := (le_TFAE I J).out 0 2 theorem antitone_lower : Antitone fun I : Box ι ↩ I.lower := fun _ _ H ↩ (le_iff_bounds.1 H).1 theorem monotone_upper : Monotone fun I : Box ι ↩ I.upper := fun _ _ H ↩ (le_iff_bounds.1 H).2 theorem coe_subset_Icc : ↑I ⊆ Box.Icc I := fun _ hx ↩ ⟹fun i ↩ (hx i).1.le, fun i ↩ (hx i).2⟩ /-! ### Supremum of two boxes -/ /-- `I ⊔ J` is the least box that includes both `I` and `J`. Since `↑I ∪ ↑J` is usually not a box, `↑(I ⊔ J)` is larger than `↑I ∪ ↑J`. -/ instance : Sup (Box ι) := ⟹fun I J ↩ ⟹I.lower ⊓ J.lower, I.upper ⊔ J.upper, fun i ↩ (min_le_left _ _).trans_lt <| (I.lower_lt_upper i).trans_le (le_max_left _ _)⟩⟩ instance : SemilatticeSup (Box ι) := { (inferInstance : PartialOrder (Box ι)), (inferInstance : Sup (Box ι)) with le_sup_left := fun _ _ ↩ le_iff_bounds.2 ⟹inf_le_left, le_sup_left⟩ le_sup_right := fun _ _ ↩ le_iff_bounds.2 ⟹inf_le_right, le_sup_right⟩ sup_le := fun _ _ _ h₁ h₂ ↩ le_iff_bounds.2 ⟹le_inf (antitone_lower h₁) (antitone_lower h₂), sup_le (monotone_upper h₁) (monotone_upper h₂)⟩ } /-! ### `WithBot (Box ι)` In this section we define coercion from `WithBot (Box ι)` to `Set (ι → ℝ)` by sending `⊥` to `∅`. -/ -- Porting note: added /-- The set underlying this box: `⊥` is mapped to `∅`. -/ @[coe] def withBotToSet (o : WithBot (Box ι)) : Set (ι → ℝ) := o.elim ∅ (↑) instance withBotCoe : CoeTC (WithBot (Box ι)) (Set (ι → ℝ)) := ⟹withBotToSet⟩ @[simp, norm_cast] theorem coe_bot : ((⊥ : WithBot (Box ι)) : Set (ι → ℝ)) = ∅ := rfl @[simp, norm_cast] theorem coe_coe : ((I : WithBot (Box ι)) : Set (ι → ℝ)) = I := rfl theorem isSome_iff : ∀ {I : WithBot (Box ι)}, I.isSome ↔ (I : Set (ι → ℝ)).Nonempty | ⊥ => by erw [Option.isSome] simp | (I : Box ι) => by erw [Option.isSome] simp [I.nonempty_coe] theorem biUnion_coe_eq_coe (I : WithBot (Box ι)) : ⋃ (J : Box ι) (_ : ↑J = I), (J : Set (ι → ℝ)) = I := by induction I <;> simp [WithBot.coe_eq_coe] @[simp, norm_cast] theorem withBotCoe_subset_iff {I J : WithBot (Box ι)} : (I : Set (ι → ℝ)) ⊆ J ↔ I ≀ J := by induction I; · simp induction J; · simp [subset_empty_iff] simp [le_def] @[simp, norm_cast] theorem withBotCoe_inj {I J : WithBot (Box ι)} : (I : Set (ι → ℝ)) = J ↔ I = J := by simp only [Subset.antisymm_iff, ← le_antisymm_iff, withBotCoe_subset_iff] /-- Make a `WithBot (Box ι)` from a pair of corners `l u : ι → ℝ`. If `l i < u i` for all `i`, then the result is `⟹l, u, _⟩ : Box ι`, otherwise it is `⊥`. In any case, the result interpreted as a set in `ι → ℝ` is the set `{x : ι → ℝ | ∀ i, x i ∈ Ioc (l i) (u i)}`. -/ def mk' (l u : ι → ℝ) : WithBot (Box ι) := if h : ∀ i, l i < u i then ↑(⟹l, u, h⟩ : Box ι) else ⊥ @[simp] theorem mk'_eq_bot {l u : ι → ℝ} : mk' l u = ⊥ ↔ ∃ i, u i ≀ l i := by rw [mk'] split_ifs with h <;> simpa using h @[simp] theorem mk'_eq_coe {l u : ι → ℝ} : mk' l u = I ↔ l = I.lower ∧ u = I.upper := by cases' I with lI uI hI; rw [mk']; split_ifs with h · simp [WithBot.coe_eq_coe] · suffices l = lI → u ≠ uI by simpa rintro rfl rfl exact h hI @[simp] theorem coe_mk' (l u : ι → ℝ) : (mk' l u : Set (ι → ℝ)) = pi univ fun i ↩ Ioc (l i) (u i) := by rw [mk']; split_ifs with h · exact coe_eq_pi _ · rcases not_forall.mp h with ⟹i, hi⟩ rw [coe_bot, univ_pi_eq_empty] exact Ioc_eq_empty hi instance WithBot.inf : Inf (WithBot (Box ι)) := ⟹fun I ↩ WithBot.recBotCoe (fun _ ↩ ⊥) (fun I J ↩ WithBot.recBotCoe ⊥ (fun J ↩ mk' (I.lower ⊔ J.lower) (I.upper ⊓ J.upper)) J) I⟩ @[simp] theorem coe_inf (I J : WithBot (Box ι)) : (↑(I ⊓ J) : Set (ι → ℝ)) = (I : Set _) ∩ J := by induction I · change ∅ = _ simp induction J · change ∅ = _ simp change ((mk' _ _ : WithBot (Box ι)) : Set (ι → ℝ)) = _ simp only [coe_eq_pi, ← pi_inter_distrib, Ioc_inter_Ioc, Pi.sup_apply, Pi.inf_apply, coe_mk', coe_coe] instance : Lattice (WithBot (Box ι)) := { WithBot.semilatticeSup, Box.WithBot.inf with inf_le_left := fun I J ↩ by rw [← withBotCoe_subset_iff, coe_inf] exact inter_subset_left inf_le_right := fun I J ↩ by rw [← withBotCoe_subset_iff, coe_inf] exact inter_subset_right le_inf := fun I J₁ J₂ h₁ h₂ ↩ by simp only [← withBotCoe_subset_iff, coe_inf] at * exact subset_inter h₁ h₂ } @[simp, norm_cast] theorem disjoint_withBotCoe {I J : WithBot (Box ι)} : Disjoint (I : Set (ι → ℝ)) J ↔ Disjoint I J := by simp only [disjoint_iff_inf_le, ← withBotCoe_subset_iff, coe_inf] rfl theorem disjoint_coe : Disjoint (I : WithBot (Box ι)) J ↔ Disjoint (I : Set (ι → ℝ)) J := disjoint_withBotCoe.symm theorem not_disjoint_coe_iff_nonempty_inter : ¬Disjoint (I : WithBot (Box ι)) J ↔ (I ∩ J : Set (ι → ℝ)).Nonempty := by rw [disjoint_coe, Set.not_disjoint_iff_nonempty_inter] /-! ### Hyperface of a box in `ℝⁿ⁺¹ = Fin (n + 1) → ℝ` -/ /-- Face of a box in `ℝⁿ⁺¹ = Fin (n + 1) → ℝ`: the box in `ℝⁿ = Fin n → ℝ` with corners at `I.lower ∘ Fin.succAbove i` and `I.upper ∘ Fin.succAbove i`. -/ @[simps (config := { simpRhs := true })] def face {n} (I : Box (Fin (n + 1))) (i : Fin (n + 1)) : Box (Fin n) := ⟹I.lower ∘ Fin.succAbove i, I.upper ∘ Fin.succAbove i, fun _ ↩ I.lower_lt_upper _⟩ @[simp] theorem face_mk {n} (l u : Fin (n + 1) → ℝ) (h : ∀ i, l i < u i) (i : Fin (n + 1)) : face ⟹l, u, h⟩ i = ⟹l ∘ Fin.succAbove i, u ∘ Fin.succAbove i, fun _ ↩ h _⟩ := rfl @[mono] theorem face_mono {n} {I J : Box (Fin (n + 1))} (h : I ≀ J) (i : Fin (n + 1)) : face I i ≀ face J i := fun _ hx _ ↩ Ioc_subset_Ioc ((le_iff_bounds.1 h).1 _) ((le_iff_bounds.1 h).2 _) (hx _) theorem monotone_face {n} (i : Fin (n + 1)) : Monotone fun I ↩ face I i := fun _ _ h ↩ face_mono h i theorem mapsTo_insertNth_face_Icc {n} (I : Box (Fin (n + 1))) {i : Fin (n + 1)} {x : ℝ} (hx : x ∈ Icc (I.lower i) (I.upper i)) : MapsTo (i.insertNth x) (Box.Icc (I.face i)) (Box.Icc I) := fun _ hy ↩ Fin.insertNth_mem_Icc.2 ⟹hx, hy⟩ theorem mapsTo_insertNth_face {n} (I : Box (Fin (n + 1))) {i : Fin (n + 1)} {x : ℝ} (hx : x ∈ Ioc (I.lower i) (I.upper i)) : MapsTo (i.insertNth x) (I.face i : Set (_ → _)) (I : Set (_ → _)) := by intro y hy simp_rw [mem_coe, mem_def, i.forall_iff_succAbove, Fin.insertNth_apply_same, Fin.insertNth_apply_succAbove] exact ⟹hx, hy⟩ theorem continuousOn_face_Icc {X} [TopologicalSpace X] {n} {f : (Fin (n + 1) → ℝ) → X} {I : Box (Fin (n + 1))} (h : ContinuousOn f (Box.Icc I)) {i : Fin (n + 1)} {x : ℝ} (hx : x ∈ Icc (I.lower i) (I.upper i)) : ContinuousOn (f ∘ i.insertNth x) (Box.Icc (I.face i)) := h.comp (continuousOn_const.fin_insertNth i continuousOn_id) (I.mapsTo_insertNth_face_Icc hx) /-! ### Covering of the interior of a box by a monotone sequence of smaller boxes -/ /-- The interior of a box. -/ protected def Ioo : Box ι →o Set (ι → ℝ) where toFun I := pi univ fun i ↩ Ioo (I.lower i) (I.upper i) monotone' _ _ h := pi_mono fun i _ ↩ Ioo_subset_Ioo ((le_iff_bounds.1 h).1 i) ((le_iff_bounds.1 h).2 i) theorem Ioo_subset_coe (I : Box ι) : Box.Ioo I ⊆ I := fun _ hx i ↩ Ioo_subset_Ioc_self (hx i trivial) protected theorem Ioo_subset_Icc (I : Box ι) : Box.Ioo I ⊆ Box.Icc I := I.Ioo_subset_coe.trans coe_subset_Icc theorem iUnion_Ioo_of_tendsto [Finite ι] {I : Box ι} {J : ℕ → Box ι} (hJ : Monotone J) (hl : Tendsto (lower ∘ J) atTop (𝓝 I.lower)) (hu : Tendsto (upper ∘ J) atTop (𝓝 I.upper)) : ⋃ n, Box.Ioo (J n) = Box.Ioo I := have hl' : ∀ i, Antitone fun n ↩ (J n).lower i := fun i ↩ (monotone_eval i).comp_antitone (antitone_lower.comp_monotone hJ) have hu' : ∀ i, Monotone fun n ↩ (J n).upper i := fun i ↩ (monotone_eval i).comp (monotone_upper.comp hJ) calc ⋃ n, Box.Ioo (J n) = pi univ fun i ↩ ⋃ n, Ioo ((J n).lower i) ((J n).upper i) := iUnion_univ_pi_of_monotone fun i ↩ (hl' i).Ioo (hu' i) _ = Box.Ioo I := pi_congr rfl fun i _ ↩ iUnion_Ioo_of_mono_of_isGLB_of_isLUB (hl' i) (hu' i) (isGLB_of_tendsto_atTop (hl' i) (tendsto_pi_nhds.1 hl _)) (isLUB_of_tendsto_atTop (hu' i) (tendsto_pi_nhds.1 hu _)) theorem exists_seq_mono_tendsto (I : Box ι) : ∃ J : ℕ →o Box ι, (∀ n, Box.Icc (J n) ⊆ Box.Ioo I) ∧ Tendsto (lower ∘ J) atTop (𝓝 I.lower) ∧ Tendsto (upper ∘ J) atTop (𝓝 I.upper) := by choose a b ha_anti hb_mono ha_mem hb_mem hab ha_tendsto hb_tendsto using fun i ↩ exists_seq_strictAnti_strictMono_tendsto (I.lower_lt_upper i) exact ⟹⟹fun k ↩ ⟹flip a k, flip b k, fun i ↩ hab _ _ _⟩, fun k l hkl ↩ le_iff_bounds.2 ⟹fun i ↩ (ha_anti i).antitone hkl, fun i ↩ (hb_mono i).monotone hkl⟩⟩, fun n x hx i _ ↩ ⟹(ha_mem _ _).1.trans_le (hx.1 _), (hx.2 _).trans_lt (hb_mem _ _).2⟩, tendsto_pi_nhds.2 ha_tendsto, tendsto_pi_nhds.2 hb_tendsto⟩ section Distortion variable [Fintype ι] /-- The distortion of a box `I` is the maximum of the ratios of the lengths of its edges. It is defined as the maximum of the ratios `nndist I.lower I.upper / nndist (I.lower i) (I.upper i)`. -/ def distortion (I : Box ι) : ℝ≥0 := Finset.univ.sup fun i : ι ↩ nndist I.lower I.upper / nndist (I.lower i) (I.upper i) theorem distortion_eq_of_sub_eq_div {I J : Box ι} {r : ℝ} (h : ∀ i, I.upper i - I.lower i = (J.upper i - J.lower i) / r) : distortion I = distortion J := by simp only [distortion, nndist_pi_def, Real.nndist_eq', h, map_div₀] congr 1 with i have : 0 < r := by by_contra hr have := div_nonpos_of_nonneg_of_nonpos (sub_nonneg.2 <| J.lower_le_upper i) (not_lt.1 hr) rw [← h] at this exact this.not_lt (sub_pos.2 <| I.lower_lt_upper i) have hn0 := (map_ne_zero Real.nnabs).2 this.ne' simp_rw [NNReal.finset_sup_div, div_div_div_cancel_right _ hn0] theorem nndist_le_distortion_mul (I : Box ι) (i : ι) : nndist I.lower I.upper ≀ I.distortion * nndist (I.lower i) (I.upper i) := calc nndist I.lower I.upper = nndist I.lower I.upper / nndist (I.lower i) (I.upper i) * nndist (I.lower i) (I.upper i) := (div_mul_cancel₀ _ <| mt nndist_eq_zero.1 (I.lower_lt_upper i).ne).symm _ ≀ I.distortion * nndist (I.lower i) (I.upper i) := by apply mul_le_mul_right' apply Finset.le_sup (Finset.mem_univ i) theorem dist_le_distortion_mul (I : Box ι) (i : ι) : dist I.lower I.upper ≀ I.distortion * (I.upper i - I.lower i) := by have A : I.lower i - I.upper i < 0 := sub_neg.2 (I.lower_lt_upper i) simpa only [← NNReal.coe_le_coe, ← dist_nndist, NNReal.coe_mul, Real.dist_eq, abs_of_neg A, neg_sub] using I.nndist_le_distortion_mul i theorem diam_Icc_le_of_distortion_le (I : Box ι) (i : ι) {c : ℝ≥0} (h : I.distortion ≀ c) : diam (Box.Icc I) ≀ c * (I.upper i - I.lower i) := have : (0 : ℝ) ≀ c * (I.upper i - I.lower i) := mul_nonneg c.coe_nonneg (sub_nonneg.2 <| I.lower_le_upper _) diam_le_of_forall_dist_le this fun x hx y hy ↩ calc dist x y ≀ dist I.lower I.upper := Real.dist_le_of_mem_pi_Icc hx hy _ ≀ I.distortion * (I.upper i - I.lower i) := I.dist_le_distortion_mul i _ ≀ c * (I.upper i - I.lower i) := by gcongr; exact sub_nonneg.2 (I.lower_le_upper i) end Distortion end Box end BoxIntegral
Analysis\BoxIntegral\Box\SubboxInduction.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Box.Basic import Mathlib.Analysis.SpecificLimits.Basic /-! # Induction on subboxes In this file we prove the following induction principle for `BoxIntegral.Box`, see `BoxIntegral.Box.subbox_induction_on`. Let `p` be a predicate on `BoxIntegral.Box ι`, let `I` be a box. Suppose that the following two properties hold true. * Consider a smaller box `J ≀ I`. The hyperplanes passing through the center of `J` split it into `2 ^ n` boxes. If `p` holds true on each of these boxes, then it is true on `J`. * For each `z` in the closed box `I.Icc` there exists a neighborhood `U` of `z` within `I.Icc` such that for every box `J ≀ I` such that `z ∈ J.Icc ⊆ U`, if `J` is homothetic to `I` with a coefficient of the form `1 / 2 ^ m`, then `p` is true on `J`. Then `p I` is true. ## Tags rectangular box, induction -/ open Set Function Filter Topology noncomputable section namespace BoxIntegral namespace Box variable {ι : Type*} {I J : Box ι} open Classical in /-- For a box `I`, the hyperplanes passing through its center split `I` into `2 ^ card ι` boxes. `BoxIntegral.Box.splitCenterBox I s` is one of these boxes. See also `BoxIntegral.Partition.splitCenter` for the corresponding `BoxIntegral.Partition`. -/ def splitCenterBox (I : Box ι) (s : Set ι) : Box ι where lower := s.piecewise (fun i ↩ (I.lower i + I.upper i) / 2) I.lower upper := s.piecewise I.upper fun i ↩ (I.lower i + I.upper i) / 2 lower_lt_upper i := by dsimp only [Set.piecewise] split_ifs <;> simp only [left_lt_add_div_two, add_div_two_lt_right, I.lower_lt_upper] theorem mem_splitCenterBox {s : Set ι} {y : ι → ℝ} : y ∈ I.splitCenterBox s ↔ y ∈ I ∧ ∀ i, (I.lower i + I.upper i) / 2 < y i ↔ i ∈ s := by simp only [splitCenterBox, mem_def, ← forall_and] refine forall_congr' fun i ↩ ?_ dsimp only [Set.piecewise] split_ifs with hs <;> simp only [hs, iff_true_iff, iff_false_iff, not_lt] exacts [⟹fun H ↩ ⟹⟹(left_lt_add_div_two.2 (I.lower_lt_upper i)).trans H.1, H.2⟩, H.1⟩, fun H ↩ ⟹H.2, H.1.2⟩⟩, ⟹fun H ↩ ⟹⟹H.1, H.2.trans (add_div_two_lt_right.2 (I.lower_lt_upper i)).le⟩, H.2⟩, fun H ↩ ⟹H.1.1, H.2⟩⟩] theorem splitCenterBox_le (I : Box ι) (s : Set ι) : I.splitCenterBox s ≀ I := fun _ hx ↩ (mem_splitCenterBox.1 hx).1 theorem disjoint_splitCenterBox (I : Box ι) {s t : Set ι} (h : s ≠ t) : Disjoint (I.splitCenterBox s : Set (ι → ℝ)) (I.splitCenterBox t) := by rw [disjoint_iff_inf_le] rintro y ⟹hs, ht⟩; apply h ext i rw [mem_coe, mem_splitCenterBox] at hs ht rw [← hs.2, ← ht.2] theorem injective_splitCenterBox (I : Box ι) : Injective I.splitCenterBox := fun _ _ H ↩ by_contra fun Hne ↩ (I.disjoint_splitCenterBox Hne).ne (nonempty_coe _).ne_empty (H ▾ rfl) @[simp] theorem exists_mem_splitCenterBox {I : Box ι} {x : ι → ℝ} : (∃ s, x ∈ I.splitCenterBox s) ↔ x ∈ I := ⟹fun ⟹s, hs⟩ ↩ I.splitCenterBox_le s hs, fun hx ↩ ⟹{ i | (I.lower i + I.upper i) / 2 < x i }, mem_splitCenterBox.2 ⟹hx, fun _ ↩ Iff.rfl⟩⟩⟩ /-- `BoxIntegral.Box.splitCenterBox` bundled as a `Function.Embedding`. -/ @[simps] def splitCenterBoxEmb (I : Box ι) : Set ι ↪ Box ι := ⟹splitCenterBox I, injective_splitCenterBox I⟩ @[simp] theorem iUnion_coe_splitCenterBox (I : Box ι) : ⋃ s, (I.splitCenterBox s : Set (ι → ℝ)) = I := by ext x simp @[simp] theorem upper_sub_lower_splitCenterBox (I : Box ι) (s : Set ι) (i : ι) : (I.splitCenterBox s).upper i - (I.splitCenterBox s).lower i = (I.upper i - I.lower i) / 2 := by by_cases i ∈ s <;> field_simp [splitCenterBox] <;> field_simp [mul_two, two_mul] /-- Let `p` be a predicate on `Box ι`, let `I` be a box. Suppose that the following two properties hold true. * `H_ind` : Consider a smaller box `J ≀ I`. The hyperplanes passing through the center of `J` split it into `2 ^ n` boxes. If `p` holds true on each of these boxes, then it true on `J`. * `H_nhds` : For each `z` in the closed box `I.Icc` there exists a neighborhood `U` of `z` within `I.Icc` such that for every box `J ≀ I` such that `z ∈ J.Icc ⊆ U`, if `J` is homothetic to `I` with a coefficient of the form `1 / 2 ^ m`, then `p` is true on `J`. Then `p I` is true. See also `BoxIntegral.Box.subbox_induction_on` for a version using `BoxIntegral.Prepartition.splitCenter` instead of `BoxIntegral.Box.splitCenterBox`. The proof still works if we assume `H_ind` only for subboxes `J ≀ I` that are homothetic to `I` with a coefficient of the form `2⁻ᵐ` but we do not need this generalization yet. -/ @[elab_as_elim] theorem subbox_induction_on' {p : Box ι → Prop} (I : Box ι) (H_ind : ∀ J ≀ I, (∀ s, p (splitCenterBox J s)) → p J) (H_nhds : ∀ z ∈ Box.Icc I, ∃ U ∈ 𝓝[Box.Icc I] z, ∀ J ≀ I, ∀ (m : ℕ), z ∈ Box.Icc J → Box.Icc J ⊆ U → (∀ i, J.upper i - J.lower i = (I.upper i - I.lower i) / 2 ^ m) → p J) : p I := by by_contra hpI -- First we use `H_ind` to construct a decreasing sequence of boxes such that `∀ m, ¬p (J m)`. replace H_ind := fun J hJ ↩ not_imp_not.2 (H_ind J hJ) simp only [exists_imp, not_forall] at H_ind choose! s hs using H_ind set J : ℕ → Box ι := fun m ↩ (fun J ↩ splitCenterBox J (s J))^[m] I have J_succ : ∀ m, J (m + 1) = splitCenterBox (J m) (s <| J m) := fun m ↩ iterate_succ_apply' _ _ _ -- Now we prove some properties of `J` have hJmono : Antitone J := antitone_nat_of_succ_le fun n ↩ by simpa [J_succ] using splitCenterBox_le _ _ have hJle : ∀ m, J m ≀ I := fun m ↩ hJmono (zero_le m) have hJp : ∀ m, ¬p (J m) := fun m ↩ Nat.recOn m hpI fun m ↩ by simpa only [J_succ] using hs (J m) (hJle m) have hJsub : ∀ m i, (J m).upper i - (J m).lower i = (I.upper i - I.lower i) / 2 ^ m := by intro m i induction' m with m ihm · simp [J, Nat.zero_eq] simp only [pow_succ, J_succ, upper_sub_lower_splitCenterBox, ihm, div_div] have h0 : J 0 = I := rfl clear_value J clear hpI hs J_succ s -- Let `z` be the unique common point of all `(J m).Icc`. Then `H_nhds` proves `p (J m)` for -- sufficiently large `m`. This contradicts `hJp`. set z : ι → ℝ := ⹆ m, (J m).lower have hzJ : ∀ m, z ∈ Box.Icc (J m) := mem_iInter.1 (ciSup_mem_iInter_Icc_of_antitone_Icc ((@Box.Icc ι).monotone.comp_antitone hJmono) fun m ↩ (J m).lower_le_upper) have hJl_mem : ∀ m, (J m).lower ∈ Box.Icc I := fun m ↩ le_iff_Icc.1 (hJle m) (J m).lower_mem_Icc have hJu_mem : ∀ m, (J m).upper ∈ Box.Icc I := fun m ↩ le_iff_Icc.1 (hJle m) (J m).upper_mem_Icc have hJlz : Tendsto (fun m ↩ (J m).lower) atTop (𝓝 z) := tendsto_atTop_ciSup (antitone_lower.comp hJmono) ⟹I.upper, fun x ⟹m, hm⟩ ↩ hm ▾ (hJl_mem m).2⟩ have hJuz : Tendsto (fun m ↩ (J m).upper) atTop (𝓝 z) := by suffices Tendsto (fun m ↩ (J m).upper - (J m).lower) atTop (𝓝 0) by simpa using hJlz.add this refine tendsto_pi_nhds.2 fun i ↩ ?_ simpa [hJsub] using tendsto_const_nhds.div_atTop (tendsto_pow_atTop_atTop_of_one_lt _root_.one_lt_two) replace hJlz : Tendsto (fun m ↩ (J m).lower) atTop (𝓝[Icc I.lower I.upper] z) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ hJlz (eventually_of_forall hJl_mem) replace hJuz : Tendsto (fun m ↩ (J m).upper) atTop (𝓝[Icc I.lower I.upper] z) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ hJuz (eventually_of_forall hJu_mem) rcases H_nhds z (h0 ▾ hzJ 0) with ⟹U, hUz, hU⟩ rcases (tendsto_lift'.1 (hJlz.Icc hJuz) U hUz).exists with ⟹m, hUm⟩ exact hJp m (hU (J m) (hJle m) m (hzJ m) hUm (hJsub m)) end Box end BoxIntegral
Analysis\BoxIntegral\Partition\Additive.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Partition.Split import Mathlib.Analysis.NormedSpace.OperatorNorm.Mul /-! # Box additive functions We say that a function `f : Box ι → M` from boxes in `ℝⁿ` to a commutative additive monoid `M` is *box additive* on subboxes of `I₀ : WithTop (Box ι)` if for any box `J`, `↑J ≀ I₀`, and a partition `π` of `J`, `f J = ∑ J' ∈ π.boxes, f J'`. We use `I₀ : WithTop (Box ι)` instead of `I₀ : Box ι` to use the same definition for functions box additive on subboxes of a box and for functions box additive on all boxes. Examples of box-additive functions include the measure of a box and the integral of a fixed integrable function over a box. In this file we define box-additive functions and prove that a function such that `f J = f (J ∩ {x | x i < y}) + f (J ∩ {x | y ≀ x i})` is box-additive. ## Tags rectangular box, additive function -/ noncomputable section open scoped Classical open Function Set namespace BoxIntegral variable {ι M : Type*} {n : ℕ} /-- A function on `Box ι` is called box additive if for every box `J` and a partition `π` of `J` we have `f J = ∑ Ji ∈ π.boxes, f Ji`. A function is called box additive on subboxes of `I : Box ι` if the same property holds for `J ≀ I`. We formalize these two notions in the same definition using `I : WithBot (Box ι)`: the value `I = ⊀` corresponds to functions box additive on the whole space. -/ structure BoxAdditiveMap (ι M : Type*) [AddCommMonoid M] (I : WithTop (Box ι)) where /-- The function underlying this additive map. -/ toFun : Box ι → M sum_partition_boxes' : ∀ J : Box ι, ↑J ≀ I → ∀ π : Prepartition J, π.IsPartition → ∑ Ji ∈ π.boxes, toFun Ji = toFun J /-- A function on `Box ι` is called box additive if for every box `J` and a partition `π` of `J` we have `f J = ∑ Ji ∈ π.boxes, f Ji`. -/ scoped notation:25 ι " →ᵇᵃ " M => BoxIntegral.BoxAdditiveMap ι M ⊀ @[inherit_doc] scoped notation:25 ι " →ᵇᵃ[" I "] " M => BoxIntegral.BoxAdditiveMap ι M I namespace BoxAdditiveMap open Box Prepartition Finset variable {N : Type*} [AddCommMonoid M] [AddCommMonoid N] {I₀ : WithTop (Box ι)} {I J : Box ι} {i : ι} instance : FunLike (ι →ᵇᵃ[I₀] M) (Box ι) M where coe := toFun coe_injective' f g h := by cases f; cases g; congr initialize_simps_projections BoxIntegral.BoxAdditiveMap (toFun → apply) @[simp] theorem coe_mk (f h) : ⇑(mk f h : ι →ᵇᵃ[I₀] M) = f := rfl theorem coe_injective : Injective fun (f : ι →ᵇᵃ[I₀] M) x => f x := DFunLike.coe_injective -- Porting note (#10618): was @[simp], now can be proved by `simp` theorem coe_inj {f g : ι →ᵇᵃ[I₀] M} : (f : Box ι → M) = g ↔ f = g := DFunLike.coe_fn_eq theorem sum_partition_boxes (f : ι →ᵇᵃ[I₀] M) (hI : ↑I ≀ I₀) {π : Prepartition I} (h : π.IsPartition) : ∑ J ∈ π.boxes, f J = f I := f.sum_partition_boxes' I hI π h @[simps (config := .asFn)] instance : Zero (ι →ᵇᵃ[I₀] M) := ⟹⟹0, fun _ _ _ _ => sum_const_zero⟩⟩ instance : Inhabited (ι →ᵇᵃ[I₀] M) := ⟹0⟩ instance : Add (ι →ᵇᵃ[I₀] M) := ⟹fun f g => ⟹f + g, fun I hI π hπ => by simp only [Pi.add_apply, sum_add_distrib, sum_partition_boxes _ hI hπ]⟩⟩ instance {R} [Monoid R] [DistribMulAction R M] : SMul R (ι →ᵇᵃ[I₀] M) := ⟹fun r f => ⟹r • (f : Box ι → M), fun I hI π hπ => by simp only [Pi.smul_apply, ← smul_sum, sum_partition_boxes _ hI hπ]⟩⟩ instance : AddCommMonoid (ι →ᵇᵃ[I₀] M) := Function.Injective.addCommMonoid _ coe_injective rfl (fun _ _ => rfl) fun _ _ => rfl @[simp] theorem map_split_add (f : ι →ᵇᵃ[I₀] M) (hI : ↑I ≀ I₀) (i : ι) (x : ℝ) : (I.splitLower i x).elim' 0 f + (I.splitUpper i x).elim' 0 f = f I := by rw [← f.sum_partition_boxes hI (isPartitionSplit I i x), sum_split_boxes] /-- If `f` is box-additive on subboxes of `I₀`, then it is box-additive on subboxes of any `I ≀ I₀`. -/ @[simps] def restrict (f : ι →ᵇᵃ[I₀] M) (I : WithTop (Box ι)) (hI : I ≀ I₀) : ι →ᵇᵃ[I] M := ⟹f, fun J hJ => f.2 J (hJ.trans hI)⟩ /-- If `f : Box ι → M` is box additive on partitions of the form `split I i x`, then it is box additive. -/ def ofMapSplitAdd [Finite ι] (f : Box ι → M) (I₀ : WithTop (Box ι)) (hf : ∀ I : Box ι, ↑I ≀ I₀ → ∀ {i x}, x ∈ Ioo (I.lower i) (I.upper i) → (I.splitLower i x).elim' 0 f + (I.splitUpper i x).elim' 0 f = f I) : ι →ᵇᵃ[I₀] M := by refine ⟹f, ?_⟩ replace hf : ∀ I : Box ι, ↑I ≀ I₀ → ∀ s, (∑ J ∈ (splitMany I s).boxes, f J) = f I := by intro I hI s induction' s using Finset.induction_on with a s _ ihs · simp rw [splitMany_insert, inf_split, ← ihs, biUnion_boxes, sum_biUnion_boxes] refine Finset.sum_congr rfl fun J' hJ' => ?_ by_cases h : a.2 ∈ Ioo (J'.lower a.1) (J'.upper a.1) · rw [sum_split_boxes] exact hf _ ((WithTop.coe_le_coe.2 <| le_of_mem _ hJ').trans hI) h · rw [split_of_not_mem_Ioo h, top_boxes, Finset.sum_singleton] intro I hI π hπ have Hle : ∀ J ∈ π, ↑J ≀ I₀ := fun J hJ => (WithTop.coe_le_coe.2 <| π.le_of_mem hJ).trans hI rcases hπ.exists_splitMany_le with ⟹s, hs⟩ rw [← hf _ hI, ← inf_of_le_right hs, inf_splitMany, biUnion_boxes, sum_biUnion_boxes] exact Finset.sum_congr rfl fun J hJ => (hf _ (Hle _ hJ) _).symm /-- If `g : M → N` is an additive map and `f` is a box additive map, then `g ∘ f` is a box additive map. -/ @[simps (config := .asFn)] def map (f : ι →ᵇᵃ[I₀] M) (g : M →+ N) : ι →ᵇᵃ[I₀] N where toFun := g ∘ f sum_partition_boxes' I hI π hπ := by simp_rw [comp, ← map_sum, f.sum_partition_boxes hI hπ] /-- If `f` is a box additive function on subboxes of `I` and `π₁`, `π₂` are two prepartitions of `I` that cover the same part of `I`, then `∑ J ∈ π₁.boxes, f J = ∑ J ∈ π₂.boxes, f J`. -/ theorem sum_boxes_congr [Finite ι] (f : ι →ᵇᵃ[I₀] M) (hI : ↑I ≀ I₀) {π₁ π₂ : Prepartition I} (h : π₁.iUnion = π₂.iUnion) : ∑ J ∈ π₁.boxes, f J = ∑ J ∈ π₂.boxes, f J := by rcases exists_splitMany_inf_eq_filter_of_finite {π₁, π₂} ((finite_singleton _).insert _) with ⟹s, hs⟩ simp only [inf_splitMany] at hs rcases hs _ (Or.inl rfl), hs _ (Or.inr rfl) with ⟹h₁, h₂⟩; clear hs rw [h] at h₁ calc ∑ J ∈ π₁.boxes, f J = ∑ J ∈ π₁.boxes, ∑ J' ∈ (splitMany J s).boxes, f J' := Finset.sum_congr rfl fun J hJ => (f.sum_partition_boxes ?_ (isPartition_splitMany _ _)).symm _ = ∑ J ∈ (π₁.biUnion fun J => splitMany J s).boxes, f J := (sum_biUnion_boxes _ _ _).symm _ = ∑ J ∈ (π₂.biUnion fun J => splitMany J s).boxes, f J := by rw [h₁, h₂] _ = ∑ J ∈ π₂.boxes, ∑ J' ∈ (splitMany J s).boxes, f J' := sum_biUnion_boxes _ _ _ _ = ∑ J ∈ π₂.boxes, f J := Finset.sum_congr rfl fun J hJ => f.sum_partition_boxes ?_ (isPartition_splitMany _ _) exacts [(WithTop.coe_le_coe.2 <| π₁.le_of_mem hJ).trans hI, (WithTop.coe_le_coe.2 <| π₂.le_of_mem hJ).trans hI] section ToSMul variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- If `f` is a box-additive map, then so is the map sending `I` to the scalar multiplication by `f I` as a continuous linear map from `E` to itself. -/ def toSMul (f : ι →ᵇᵃ[I₀] ℝ) : ι →ᵇᵃ[I₀] E →L[ℝ] E := f.map (ContinuousLinearMap.lsmul ℝ ℝ).toLinearMap.toAddMonoidHom @[simp] theorem toSMul_apply (f : ι →ᵇᵃ[I₀] ℝ) (I : Box ι) (x : E) : f.toSMul I x = f I • x := rfl end ToSMul /-- Given a box `I₀` in `ℝⁿ⁺¹`, `f x : Box (Fin n) → G` is a family of functions indexed by a real `x` and for `x ∈ [I₀.lower i, I₀.upper i]`, `f x` is box-additive on subboxes of the `i`-th face of `I₀`, then `fun J ↩ f (J.upper i) (J.face i) - f (J.lower i) (J.face i)` is box-additive on subboxes of `I₀`. -/ @[simps!] def upperSubLower.{u} {G : Type u} [AddCommGroup G] (I₀ : Box (Fin (n + 1))) (i : Fin (n + 1)) (f : ℝ → Box (Fin n) → G) (fb : Icc (I₀.lower i) (I₀.upper i) → Fin n →ᵇᵃ[I₀.face i] G) (hf : ∀ (x) (hx : x ∈ Icc (I₀.lower i) (I₀.upper i)) (J), f x J = fb ⟹x, hx⟩ J) : Fin (n + 1) →ᵇᵃ[I₀] G := ofMapSplitAdd (fun J : Box (Fin (n + 1)) => f (J.upper i) (J.face i) - f (J.lower i) (J.face i)) I₀ (by intro J hJ j x rw [WithTop.coe_le_coe] at hJ refine i.succAboveCases (fun hx => ?_) (fun j hx => ?_) j · simp only [Box.splitLower_def hx, Box.splitUpper_def hx, update_same, ← WithBot.some_eq_coe, Option.elim', Box.face, (· ∘ ·), update_noteq (Fin.succAbove_ne _ _)] abel · have : (J.face i : WithTop (Box (Fin n))) ≀ I₀.face i := WithTop.coe_le_coe.2 (face_mono hJ i) rw [le_iff_Icc, @Box.Icc_eq_pi _ I₀] at hJ simp only rw [hf _ (hJ J.upper_mem_Icc _ trivial), hf _ (hJ J.lower_mem_Icc _ trivial), ← (fb _).map_split_add this j x, ← (fb _).map_split_add this j x] have hx' : x ∈ Ioo ((J.face i).lower j) ((J.face i).upper j) := hx simp only [Box.splitLower_def hx, Box.splitUpper_def hx, Box.splitLower_def hx', Box.splitUpper_def hx', ← WithBot.some_eq_coe, Option.elim', Box.face_mk, update_noteq (Fin.succAbove_ne _ _).symm, sub_add_sub_comm, update_comp_eq_of_injective _ (Fin.strictMono_succAbove i).injective j x, ← hf] simp only [Box.face]) end BoxAdditiveMap end BoxIntegral
Analysis\BoxIntegral\Partition\Basic.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.Option import Mathlib.Analysis.BoxIntegral.Box.Basic import Mathlib.Data.Set.Pairwise.Lattice /-! # Partitions of rectangular boxes in `ℝⁿ` In this file we define (pre)partitions of rectangular boxes in `ℝⁿ`. A partition of a box `I` in `ℝⁿ` (see `BoxIntegral.Prepartition` and `BoxIntegral.Prepartition.IsPartition`) is a finite set of pairwise disjoint boxes such that their union is exactly `I`. We use `boxes : Finset (Box ι)` to store the set of boxes. Many lemmas about box integrals deal with pairwise disjoint collections of subboxes, so we define a structure `BoxIntegral.Prepartition (I : BoxIntegral.Box ι)` that stores a collection of boxes such that * each box `J ∈ boxes` is a subbox of `I`; * the boxes are pairwise disjoint as sets in `ℝⁿ`. Then we define a predicate `BoxIntegral.Prepartition.IsPartition`; `π.IsPartition` means that the boxes of `π` actually cover the whole `I`. We also define some operations on prepartitions: * `BoxIntegral.Prepartition.biUnion`: split each box of a partition into smaller boxes; * `BoxIntegral.Prepartition.restrict`: restrict a partition to a smaller box. We also define a `SemilatticeInf` structure on `BoxIntegral.Prepartition I` for all `I : BoxIntegral.Box ι`. ## Tags rectangular box, partition -/ open Set Finset Function open scoped Classical open NNReal noncomputable section namespace BoxIntegral variable {ι : Type*} /-- A prepartition of `I : BoxIntegral.Box ι` is a finite set of pairwise disjoint subboxes of `I`. -/ structure Prepartition (I : Box ι) where /-- The underlying set of boxes -/ boxes : Finset (Box ι) /-- Each box is a sub-box of `I` -/ le_of_mem' : ∀ J ∈ boxes, J ≀ I /-- The boxes in a prepartition are pairwise disjoint. -/ pairwiseDisjoint : Set.Pairwise (↑boxes) (Disjoint on ((↑) : Box ι → Set (ι → ℝ))) namespace Prepartition variable {I J J₁ J₂ : Box ι} (π : Prepartition I) {π₁ π₂ : Prepartition I} {x : ι → ℝ} instance : Membership (Box ι) (Prepartition I) := ⟹fun J π => J ∈ π.boxes⟩ @[simp] theorem mem_boxes : J ∈ π.boxes ↔ J ∈ π := Iff.rfl @[simp] theorem mem_mk {s h₁ h₂} : J ∈ (mk s h₁ h₂ : Prepartition I) ↔ J ∈ s := Iff.rfl theorem disjoint_coe_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (h : J₁ ≠ J₂) : Disjoint (J₁ : Set (ι → ℝ)) J₂ := π.pairwiseDisjoint h₁ h₂ h theorem eq_of_mem_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hx₁ : x ∈ J₁) (hx₂ : x ∈ J₂) : J₁ = J₂ := by_contra fun H => (π.disjoint_coe_of_mem h₁ h₂ H).le_bot ⟹hx₁, hx₂⟩ theorem eq_of_le_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle₁ : J ≀ J₁) (hle₂ : J ≀ J₂) : J₁ = J₂ := π.eq_of_mem_of_mem h₁ h₂ (hle₁ J.upper_mem) (hle₂ J.upper_mem) theorem eq_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle : J₁ ≀ J₂) : J₁ = J₂ := π.eq_of_le_of_le h₁ h₂ le_rfl hle theorem le_of_mem (hJ : J ∈ π) : J ≀ I := π.le_of_mem' J hJ theorem lower_le_lower (hJ : J ∈ π) : I.lower ≀ J.lower := Box.antitone_lower (π.le_of_mem hJ) theorem upper_le_upper (hJ : J ∈ π) : J.upper ≀ I.upper := Box.monotone_upper (π.le_of_mem hJ) theorem injective_boxes : Function.Injective (boxes : Prepartition I → Finset (Box ι)) := by rintro ⟹s₁, h₁, h₁'⟩ ⟹s₂, h₂, h₂'⟩ (rfl : s₁ = s₂) rfl @[ext] theorem ext (h : ∀ J, J ∈ π₁ ↔ J ∈ π₂) : π₁ = π₂ := injective_boxes <| Finset.ext h /-- The singleton prepartition `{J}`, `J ≀ I`. -/ @[simps] def single (I J : Box ι) (h : J ≀ I) : Prepartition I := ⟹{J}, by simpa, by simp⟩ @[simp] theorem mem_single {J'} (h : J ≀ I) : J' ∈ single I J h ↔ J' = J := mem_singleton /-- We say that `π ≀ π'` if each box of `π` is a subbox of some box of `π'`. -/ instance : LE (Prepartition I) := ⟹fun π π' => ∀ ⊃I⩄, I ∈ π → ∃ I' ∈ π', I ≀ I'⟩ instance partialOrder : PartialOrder (Prepartition I) where le := (· ≀ ·) le_refl π I hI := ⟹I, hI, le_rfl⟩ le_trans π₁ π₂ π₃ h₁₂ h₂₃ I₁ hI₁ := let ⟹I₂, hI₂, hI₁₂⟩ := h₁₂ hI₁ let ⟹I₃, hI₃, hI₂₃⟩ := h₂₃ hI₂ ⟹I₃, hI₃, hI₁₂.trans hI₂₃⟩ le_antisymm := by suffices ∀ {π₁ π₂ : Prepartition I}, π₁ ≀ π₂ → π₂ ≀ π₁ → π₁.boxes ⊆ π₂.boxes from fun π₁ π₂ h₁ h₂ => injective_boxes (Subset.antisymm (this h₁ h₂) (this h₂ h₁)) intro π₁ π₂ h₁ h₂ J hJ rcases h₁ hJ with ⟹J', hJ', hle⟩; rcases h₂ hJ' with ⟹J'', hJ'', hle'⟩ obtain rfl : J = J'' := π₁.eq_of_le hJ hJ'' (hle.trans hle') obtain rfl : J' = J := le_antisymm ‹_› ‹_› assumption instance : OrderTop (Prepartition I) where top := single I I le_rfl le_top π J hJ := ⟹I, by simp, π.le_of_mem hJ⟩ instance : OrderBot (Prepartition I) where bot := ⟹∅, fun _ hJ => (Finset.not_mem_empty _ hJ).elim, fun _ hJ => (Set.not_mem_empty _ <| Finset.coe_empty ▾ hJ).elim⟩ bot_le _ _ hJ := (Finset.not_mem_empty _ hJ).elim instance : Inhabited (Prepartition I) := ⟚⊀⟩ theorem le_def : π₁ ≀ π₂ ↔ ∀ J ∈ π₁, ∃ J' ∈ π₂, J ≀ J' := Iff.rfl @[simp] theorem mem_top : J ∈ (⊀ : Prepartition I) ↔ J = I := mem_singleton @[simp] theorem top_boxes : (⊀ : Prepartition I).boxes = {I} := rfl @[simp] theorem not_mem_bot : J ∉ (⊥ : Prepartition I) := Finset.not_mem_empty _ @[simp] theorem bot_boxes : (⊥ : Prepartition I).boxes = ∅ := rfl /-- An auxiliary lemma used to prove that the same point can't belong to more than `2 ^ Fintype.card ι` closed boxes of a prepartition. -/ theorem injOn_setOf_mem_Icc_setOf_lower_eq (x : ι → ℝ) : InjOn (fun J : Box ι => { i | J.lower i = x i }) { J | J ∈ π ∧ x ∈ Box.Icc J } := by rintro J₁ ⟹h₁, hx₁⟩ J₂ ⟹h₂, hx₂⟩ (H : { i | J₁.lower i = x i } = { i | J₂.lower i = x i }) suffices ∀ i, (Ioc (J₁.lower i) (J₁.upper i) ∩ Ioc (J₂.lower i) (J₂.upper i)).Nonempty by choose y hy₁ hy₂ using this exact π.eq_of_mem_of_mem h₁ h₂ hy₁ hy₂ intro i simp only [Set.ext_iff, mem_setOf] at H rcases (hx₁.1 i).eq_or_lt with hi₁ | hi₁ · have hi₂ : J₂.lower i = x i := (H _).1 hi₁ have H₁ : x i < J₁.upper i := by simpa only [hi₁] using J₁.lower_lt_upper i have H₂ : x i < J₂.upper i := by simpa only [hi₂] using J₂.lower_lt_upper i rw [Ioc_inter_Ioc, hi₁, hi₂, sup_idem, Set.nonempty_Ioc] exact lt_min H₁ H₂ · have hi₂ : J₂.lower i < x i := (hx₂.1 i).lt_of_ne (mt (H _).2 hi₁.ne) exact ⟹x i, ⟹hi₁, hx₁.2 i⟩, ⟹hi₂, hx₂.2 i⟩⟩ /-- The set of boxes of a prepartition that contain `x` in their closures has cardinality at most `2 ^ Fintype.card ι`. -/ theorem card_filter_mem_Icc_le [Fintype ι] (x : ι → ℝ) : (π.boxes.filter fun J : Box ι => x ∈ Box.Icc J).card ≀ 2 ^ Fintype.card ι := by rw [← Fintype.card_set] refine Finset.card_le_card_of_injOn (fun J : Box ι => { i | J.lower i = x i }) (fun _ _ => Finset.mem_univ _) ?_ simpa using π.injOn_setOf_mem_Icc_setOf_lower_eq x /-- Given a prepartition `π : BoxIntegral.Prepartition I`, `π.iUnion` is the part of `I` covered by the boxes of `π`. -/ protected def iUnion : Set (ι → ℝ) := ⋃ J ∈ π, ↑J theorem iUnion_def : π.iUnion = ⋃ J ∈ π, ↑J := rfl theorem iUnion_def' : π.iUnion = ⋃ J ∈ π.boxes, ↑J := rfl -- Porting note: Previous proof was `:= Set.mem_iUnion₂` @[simp] theorem mem_iUnion : x ∈ π.iUnion ↔ ∃ J ∈ π, x ∈ J := by convert Set.mem_iUnion₂ rw [Box.mem_coe, exists_prop] @[simp] theorem iUnion_single (h : J ≀ I) : (single I J h).iUnion = J := by simp [iUnion_def] @[simp] theorem iUnion_top : (⊀ : Prepartition I).iUnion = I := by simp [Prepartition.iUnion] @[simp] theorem iUnion_eq_empty : π₁.iUnion = ∅ ↔ π₁ = ⊥ := by simp [← injective_boxes.eq_iff, Finset.ext_iff, Prepartition.iUnion, imp_false] @[simp] theorem iUnion_bot : (⊥ : Prepartition I).iUnion = ∅ := iUnion_eq_empty.2 rfl theorem subset_iUnion (h : J ∈ π) : ↑J ⊆ π.iUnion := subset_biUnion_of_mem h theorem iUnion_subset : π.iUnion ⊆ I := iUnion₂_subset π.le_of_mem' @[mono] theorem iUnion_mono (h : π₁ ≀ π₂) : π₁.iUnion ⊆ π₂.iUnion := fun _ hx => let ⟹_, hJ₁, hx⟩ := π₁.mem_iUnion.1 hx let ⟹J₂, hJ₂, hle⟩ := h hJ₁ π₂.mem_iUnion.2 ⟹J₂, hJ₂, hle hx⟩ theorem disjoint_boxes_of_disjoint_iUnion (h : Disjoint π₁.iUnion π₂.iUnion) : Disjoint π₁.boxes π₂.boxes := Finset.disjoint_left.2 fun J h₁ h₂ => Disjoint.le_bot (h.mono (π₁.subset_iUnion h₁) (π₂.subset_iUnion h₂)) ⟹J.upper_mem, J.upper_mem⟩ theorem le_iff_nonempty_imp_le_and_iUnion_subset : π₁ ≀ π₂ ↔ (∀ J ∈ π₁, ∀ J' ∈ π₂, (J ∩ J' : Set (ι → ℝ)).Nonempty → J ≀ J') ∧ π₁.iUnion ⊆ π₂.iUnion := by constructor · refine fun H => ⟹fun J hJ J' hJ' Hne => ?_, iUnion_mono H⟩ rcases H hJ with ⟹J'', hJ'', Hle⟩ rcases Hne with ⟹x, hx, hx'⟩ rwa [π₂.eq_of_mem_of_mem hJ' hJ'' hx' (Hle hx)] · rintro ⟹H, HU⟩ J hJ simp only [Set.subset_def, mem_iUnion] at HU rcases HU J.upper ⟹J, hJ, J.upper_mem⟩ with ⟹J₂, hJ₂, hx⟩ exact ⟹J₂, hJ₂, H _ hJ _ hJ₂ ⟹_, J.upper_mem, hx⟩⟩ theorem eq_of_boxes_subset_iUnion_superset (h₁ : π₁.boxes ⊆ π₂.boxes) (h₂ : π₂.iUnion ⊆ π₁.iUnion) : π₁ = π₂ := le_antisymm (fun J hJ => ⟹J, h₁ hJ, le_rfl⟩) <| le_iff_nonempty_imp_le_and_iUnion_subset.2 ⟹fun _ hJ₁ _ hJ₂ Hne => (π₂.eq_of_mem_of_mem hJ₁ (h₁ hJ₂) Hne.choose_spec.1 Hne.choose_spec.2).le, h₂⟩ /-- Given a prepartition `π` of a box `I` and a collection of prepartitions `πi J` of all boxes `J ∈ π`, returns the prepartition of `I` into the union of the boxes of all `πi J`. Though we only use the values of `πi` on the boxes of `π`, we require `πi` to be a globally defined function. -/ @[simps] def biUnion (πi : ∀ J : Box ι, Prepartition J) : Prepartition I where boxes := π.boxes.biUnion fun J => (πi J).boxes le_of_mem' J hJ := by simp only [Finset.mem_biUnion, exists_prop, mem_boxes] at hJ rcases hJ with ⟹J', hJ', hJ⟩ exact ((πi J').le_of_mem hJ).trans (π.le_of_mem hJ') pairwiseDisjoint := by simp only [Set.Pairwise, Finset.mem_coe, Finset.mem_biUnion] rintro J₁' ⟹J₁, hJ₁, hJ₁'⟩ J₂' ⟹J₂, hJ₂, hJ₂'⟩ Hne rw [Function.onFun, Set.disjoint_left] rintro x hx₁ hx₂; apply Hne obtain rfl : J₁ = J₂ := π.eq_of_mem_of_mem hJ₁ hJ₂ ((πi J₁).le_of_mem hJ₁' hx₁) ((πi J₂).le_of_mem hJ₂' hx₂) exact (πi J₁).eq_of_mem_of_mem hJ₁' hJ₂' hx₁ hx₂ variable {πi πi₁ πi₂ : ∀ J : Box ι, Prepartition J} @[simp] theorem mem_biUnion : J ∈ π.biUnion πi ↔ ∃ J' ∈ π, J ∈ πi J' := by simp [biUnion] theorem biUnion_le (πi : ∀ J, Prepartition J) : π.biUnion πi ≀ π := fun _ hJ => let ⟹J', hJ', hJ⟩ := π.mem_biUnion.1 hJ ⟹J', hJ', (πi J').le_of_mem hJ⟩ @[simp] theorem biUnion_top : (π.biUnion fun _ => ⊀) = π := by ext simp @[congr] theorem biUnion_congr (h : π₁ = π₂) (hi : ∀ J ∈ π₁, πi₁ J = πi₂ J) : π₁.biUnion πi₁ = π₂.biUnion πi₂ := by subst π₂ ext J simp only [mem_biUnion] constructor <;> exact fun ⟹J', h₁, h₂⟩ => ⟹J', h₁, hi J' h₁ ▾ h₂⟩ theorem biUnion_congr_of_le (h : π₁ = π₂) (hi : ∀ J ≀ I, πi₁ J = πi₂ J) : π₁.biUnion πi₁ = π₂.biUnion πi₂ := biUnion_congr h fun J hJ => hi J (π₁.le_of_mem hJ) @[simp] theorem iUnion_biUnion (πi : ∀ J : Box ι, Prepartition J) : (π.biUnion πi).iUnion = ⋃ J ∈ π, (πi J).iUnion := by simp [Prepartition.iUnion] @[simp] theorem sum_biUnion_boxes {M : Type*} [AddCommMonoid M] (π : Prepartition I) (πi : ∀ J, Prepartition J) (f : Box ι → M) : (∑ J ∈ π.boxes.biUnion fun J => (πi J).boxes, f J) = ∑ J ∈ π.boxes, ∑ J' ∈ (πi J).boxes, f J' := by refine Finset.sum_biUnion fun J₁ h₁ J₂ h₂ hne => Finset.disjoint_left.2 fun J' h₁' h₂' => ?_ exact hne (π.eq_of_le_of_le h₁ h₂ ((πi J₁).le_of_mem h₁') ((πi J₂).le_of_mem h₂')) /-- Given a box `J ∈ π.biUnion πi`, returns the box `J' ∈ π` such that `J ∈ πi J'`. For `J ∉ π.biUnion πi`, returns `I`. -/ def biUnionIndex (πi : ∀ (J : Box ι), Prepartition J) (J : Box ι) : Box ι := if hJ : J ∈ π.biUnion πi then (π.mem_biUnion.1 hJ).choose else I theorem biUnionIndex_mem (hJ : J ∈ π.biUnion πi) : π.biUnionIndex πi J ∈ π := by rw [biUnionIndex, dif_pos hJ] exact (π.mem_biUnion.1 hJ).choose_spec.1 theorem biUnionIndex_le (πi : ∀ J, Prepartition J) (J : Box ι) : π.biUnionIndex πi J ≀ I := by by_cases hJ : J ∈ π.biUnion πi · exact π.le_of_mem (π.biUnionIndex_mem hJ) · rw [biUnionIndex, dif_neg hJ] theorem mem_biUnionIndex (hJ : J ∈ π.biUnion πi) : J ∈ πi (π.biUnionIndex πi J) := by convert (π.mem_biUnion.1 hJ).choose_spec.2 <;> exact dif_pos hJ theorem le_biUnionIndex (hJ : J ∈ π.biUnion πi) : J ≀ π.biUnionIndex πi J := le_of_mem _ (π.mem_biUnionIndex hJ) /-- Uniqueness property of `BoxIntegral.Prepartition.biUnionIndex`. -/ theorem biUnionIndex_of_mem (hJ : J ∈ π) {J'} (hJ' : J' ∈ πi J) : π.biUnionIndex πi J' = J := have : J' ∈ π.biUnion πi := π.mem_biUnion.2 ⟹J, hJ, hJ'⟩ π.eq_of_le_of_le (π.biUnionIndex_mem this) hJ (π.le_biUnionIndex this) (le_of_mem _ hJ') theorem biUnion_assoc (πi : ∀ J, Prepartition J) (πi' : Box ι → ∀ J : Box ι, Prepartition J) : (π.biUnion fun J => (πi J).biUnion (πi' J)) = (π.biUnion πi).biUnion fun J => πi' (π.biUnionIndex πi J) J := by ext J simp only [mem_biUnion, exists_prop] constructor · rintro ⟹J₁, hJ₁, J₂, hJ₂, hJ⟩ refine ⟹J₂, ⟹J₁, hJ₁, hJ₂⟩, ?_⟩ rwa [π.biUnionIndex_of_mem hJ₁ hJ₂] · rintro ⟹J₁, ⟹J₂, hJ₂, hJ₁⟩, hJ⟩ refine ⟹J₂, hJ₂, J₁, hJ₁, ?_⟩ rwa [π.biUnionIndex_of_mem hJ₂ hJ₁] at hJ /-- Create a `BoxIntegral.Prepartition` from a collection of possibly empty boxes by filtering out the empty one if it exists. -/ def ofWithBot (boxes : Finset (WithBot (Box ι))) (le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≀ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) : Prepartition I where boxes := Finset.eraseNone boxes le_of_mem' J hJ := by rw [mem_eraseNone] at hJ simpa only [WithBot.some_eq_coe, WithBot.coe_le_coe] using le_of_mem _ hJ pairwiseDisjoint J₁ h₁ J₂ h₂ hne := by simp only [mem_coe, mem_eraseNone] at h₁ h₂ exact Box.disjoint_coe.1 (pairwise_disjoint h₁ h₂ (mt Option.some_inj.1 hne)) @[simp] theorem mem_ofWithBot {boxes : Finset (WithBot (Box ι))} {h₁ h₂} : J ∈ (ofWithBot boxes h₁ h₂ : Prepartition I) ↔ (J : WithBot (Box ι)) ∈ boxes := mem_eraseNone @[simp] theorem iUnion_ofWithBot (boxes : Finset (WithBot (Box ι))) (le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≀ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) : (ofWithBot boxes le_of_mem pairwise_disjoint).iUnion = ⋃ J ∈ boxes, ↑J := by suffices ⋃ (J : Box ι) (_ : ↑J ∈ boxes), ↑J = ⋃ J ∈ boxes, (J : Set (ι → ℝ)) by simpa [ofWithBot, Prepartition.iUnion] simp only [← Box.biUnion_coe_eq_coe, @iUnion_comm _ _ (Box ι), @iUnion_comm _ _ (@Eq _ _ _), iUnion_iUnion_eq_right] theorem ofWithBot_le {boxes : Finset (WithBot (Box ι))} {le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≀ I} {pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint} (H : ∀ J ∈ boxes, J ≠ ⊥ → ∃ J' ∈ π, J ≀ ↑J') : ofWithBot boxes le_of_mem pairwise_disjoint ≀ π := by have : ∀ J : Box ι, ↑J ∈ boxes → ∃ J' ∈ π, J ≀ J' := fun J hJ => by simpa only [WithBot.coe_le_coe] using H J hJ WithBot.coe_ne_bot simpa [ofWithBot, le_def] theorem le_ofWithBot {boxes : Finset (WithBot (Box ι))} {le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≀ I} {pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint} (H : ∀ J ∈ π, ∃ J' ∈ boxes, ↑J ≀ J') : π ≀ ofWithBot boxes le_of_mem pairwise_disjoint := by intro J hJ rcases H J hJ with ⟹J', J'mem, hle⟩ lift J' to Box ι using ne_bot_of_le_ne_bot WithBot.coe_ne_bot hle exact ⟹J', mem_ofWithBot.2 J'mem, WithBot.coe_le_coe.1 hle⟩ theorem ofWithBot_mono {boxes₁ : Finset (WithBot (Box ι))} {le_of_mem₁ : ∀ J ∈ boxes₁, (J : WithBot (Box ι)) ≀ I} {pairwise_disjoint₁ : Set.Pairwise (boxes₁ : Set (WithBot (Box ι))) Disjoint} {boxes₂ : Finset (WithBot (Box ι))} {le_of_mem₂ : ∀ J ∈ boxes₂, (J : WithBot (Box ι)) ≀ I} {pairwise_disjoint₂ : Set.Pairwise (boxes₂ : Set (WithBot (Box ι))) Disjoint} (H : ∀ J ∈ boxes₁, J ≠ ⊥ → ∃ J' ∈ boxes₂, J ≀ J') : ofWithBot boxes₁ le_of_mem₁ pairwise_disjoint₁ ≀ ofWithBot boxes₂ le_of_mem₂ pairwise_disjoint₂ := le_ofWithBot _ fun J hJ => H J (mem_ofWithBot.1 hJ) WithBot.coe_ne_bot theorem sum_ofWithBot {M : Type*} [AddCommMonoid M] (boxes : Finset (WithBot (Box ι))) (le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≀ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) (f : Box ι → M) : (∑ J ∈ (ofWithBot boxes le_of_mem pairwise_disjoint).boxes, f J) = ∑ J ∈ boxes, Option.elim' 0 f J := Finset.sum_eraseNone _ _ /-- Restrict a prepartition to a box. -/ def restrict (π : Prepartition I) (J : Box ι) : Prepartition J := ofWithBot (π.boxes.image fun J' : Box ι => J ⊓ J') (fun J' hJ' => by rcases Finset.mem_image.1 hJ' with ⟹J', -, rfl⟩ exact inf_le_left) (by simp only [Set.Pairwise, onFun, Finset.mem_coe, Finset.mem_image] rintro _ ⟹J₁, h₁, rfl⟩ _ ⟹J₂, h₂, rfl⟩ Hne have : J₁ ≠ J₂ := by rintro rfl exact Hne rfl exact ((Box.disjoint_coe.2 <| π.disjoint_coe_of_mem h₁ h₂ this).inf_left' _).inf_right' _) @[simp] theorem mem_restrict : J₁ ∈ π.restrict J ↔ ∃ J' ∈ π, (J₁ : WithBot (Box ι)) = ↑J ⊓ ↑J' := by simp [restrict, eq_comm] theorem mem_restrict' : J₁ ∈ π.restrict J ↔ ∃ J' ∈ π, (J₁ : Set (ι → ℝ)) = ↑J ∩ ↑J' := by simp only [mem_restrict, ← Box.withBotCoe_inj, Box.coe_inf, Box.coe_coe] @[mono] theorem restrict_mono {π₁ π₂ : Prepartition I} (Hle : π₁ ≀ π₂) : π₁.restrict J ≀ π₂.restrict J := by refine ofWithBot_mono fun J₁ hJ₁ hne => ?_ rw [Finset.mem_image] at hJ₁; rcases hJ₁ with ⟹J₁, hJ₁, rfl⟩ rcases Hle hJ₁ with ⟹J₂, hJ₂, hle⟩ exact ⟹_, Finset.mem_image_of_mem _ hJ₂, inf_le_inf_left _ <| WithBot.coe_le_coe.2 hle⟩ theorem monotone_restrict : Monotone fun π : Prepartition I => restrict π J := fun _ _ => restrict_mono /-- Restricting to a larger box does not change the set of boxes. We cannot claim equality of prepartitions because they have different types. -/ theorem restrict_boxes_of_le (π : Prepartition I) (h : I ≀ J) : (π.restrict J).boxes = π.boxes := by simp only [restrict, ofWithBot, eraseNone_eq_biUnion] refine Finset.image_biUnion.trans ?_ refine (Finset.biUnion_congr rfl ?_).trans Finset.biUnion_singleton_eq_self intro J' hJ' rw [inf_of_le_right, ← WithBot.some_eq_coe, Option.toFinset_some] exact WithBot.coe_le_coe.2 ((π.le_of_mem hJ').trans h) @[simp] theorem restrict_self : π.restrict I = π := injective_boxes <| restrict_boxes_of_le π le_rfl @[simp] theorem iUnion_restrict : (π.restrict J).iUnion = (J : Set (ι → ℝ)) ∩ (π.iUnion) := by simp [restrict, ← inter_iUnion, ← iUnion_def] @[simp] theorem restrict_biUnion (πi : ∀ J, Prepartition J) (hJ : J ∈ π) : (π.biUnion πi).restrict J = πi J := by refine (eq_of_boxes_subset_iUnion_superset (fun J₁ h₁ => ?_) ?_).symm · refine (mem_restrict _).2 ⟹J₁, π.mem_biUnion.2 ⟹J, hJ, h₁⟩, (inf_of_le_right ?_).symm⟩ exact WithBot.coe_le_coe.2 (le_of_mem _ h₁) · simp only [iUnion_restrict, iUnion_biUnion, Set.subset_def, Set.mem_inter_iff, Set.mem_iUnion] rintro x ⟹hxJ, J₁, h₁, hx⟩ obtain rfl : J = J₁ := π.eq_of_mem_of_mem hJ h₁ hxJ (iUnion_subset _ hx) exact hx theorem biUnion_le_iff {πi : ∀ J, Prepartition J} {π' : Prepartition I} : π.biUnion πi ≀ π' ↔ ∀ J ∈ π, πi J ≀ π'.restrict J := by constructor <;> intro H J hJ · rw [← π.restrict_biUnion πi hJ] exact restrict_mono H · rw [mem_biUnion] at hJ rcases hJ with ⟹J₁, h₁, hJ⟩ rcases H J₁ h₁ hJ with ⟹J₂, h₂, Hle⟩ rcases π'.mem_restrict.mp h₂ with ⟹J₃, h₃, H⟩ exact ⟹J₃, h₃, Hle.trans <| WithBot.coe_le_coe.1 <| H.trans_le inf_le_right⟩ theorem le_biUnion_iff {πi : ∀ J, Prepartition J} {π' : Prepartition I} : π' ≀ π.biUnion πi ↔ π' ≀ π ∧ ∀ J ∈ π, π'.restrict J ≀ πi J := by refine ⟹fun H => ⟹H.trans (π.biUnion_le πi), fun J hJ => ?_⟩, ?_⟩ · rw [← π.restrict_biUnion πi hJ] exact restrict_mono H · rintro ⟹H, Hi⟩ J' hJ' rcases H hJ' with ⟹J, hJ, hle⟩ have : J' ∈ π'.restrict J := π'.mem_restrict.2 ⟹J', hJ', (inf_of_le_right <| WithBot.coe_le_coe.2 hle).symm⟩ rcases Hi J hJ this with ⟹Ji, hJi, hlei⟩ exact ⟹Ji, π.mem_biUnion.2 ⟹J, hJ, hJi⟩, hlei⟩ instance inf : Inf (Prepartition I) := ⟹fun π₁ π₂ => π₁.biUnion fun J => π₂.restrict J⟩ theorem inf_def (π₁ π₂ : Prepartition I) : π₁ ⊓ π₂ = π₁.biUnion fun J => π₂.restrict J := rfl @[simp] theorem mem_inf {π₁ π₂ : Prepartition I} : J ∈ π₁ ⊓ π₂ ↔ ∃ J₁ ∈ π₁, ∃ J₂ ∈ π₂, (J : WithBot (Box ι)) = ↑J₁ ⊓ ↑J₂ := by simp only [inf_def, mem_biUnion, mem_restrict] @[simp] theorem iUnion_inf (π₁ π₂ : Prepartition I) : (π₁ ⊓ π₂).iUnion = π₁.iUnion ∩ π₂.iUnion := by simp only [inf_def, iUnion_biUnion, iUnion_restrict, ← iUnion_inter, ← iUnion_def] instance : SemilatticeInf (Prepartition I) := { Prepartition.inf, Prepartition.partialOrder with inf_le_left := fun π₁ _ => π₁.biUnion_le _ inf_le_right := fun _ _ => (biUnion_le_iff _).2 fun _ _ => le_rfl le_inf := fun _ π₁ _ h₁ h₂ => π₁.le_biUnion_iff.2 ⟹h₁, fun _ _ => restrict_mono h₂⟩ } /-- The prepartition with boxes `{J ∈ π | p J}`. -/ @[simps] def filter (π : Prepartition I) (p : Box ι → Prop) : Prepartition I where boxes := π.boxes.filter p le_of_mem' _ hJ := π.le_of_mem (mem_filter.1 hJ).1 pairwiseDisjoint _ h₁ _ h₂ := π.disjoint_coe_of_mem (mem_filter.1 h₁).1 (mem_filter.1 h₂).1 @[simp] theorem mem_filter {p : Box ι → Prop} : J ∈ π.filter p ↔ J ∈ π ∧ p J := Finset.mem_filter theorem filter_le (π : Prepartition I) (p : Box ι → Prop) : π.filter p ≀ π := fun J hJ => let ⟹hπ, _⟩ := π.mem_filter.1 hJ ⟹J, hπ, le_rfl⟩ theorem filter_of_true {p : Box ι → Prop} (hp : ∀ J ∈ π, p J) : π.filter p = π := by ext J simpa using hp J @[simp] theorem filter_true : (π.filter fun _ => True) = π := π.filter_of_true fun _ _ => trivial @[simp] theorem iUnion_filter_not (π : Prepartition I) (p : Box ι → Prop) : (π.filter fun J => ¬p J).iUnion = π.iUnion \ (π.filter p).iUnion := by simp only [Prepartition.iUnion] convert (@Set.biUnion_diff_biUnion_eq (ι → ℝ) (Box ι) π.boxes (π.filter p).boxes (↑) _).symm · simp (config := { contextual := true }) · rw [Set.PairwiseDisjoint] convert π.pairwiseDisjoint rw [Set.union_eq_left, filter_boxes, coe_filter] exact fun _ ⟹h, _⟩ => h theorem sum_fiberwise {α M} [AddCommMonoid M] (π : Prepartition I) (f : Box ι → α) (g : Box ι → M) : (∑ y ∈ π.boxes.image f, ∑ J ∈ (π.filter fun J => f J = y).boxes, g J) = ∑ J ∈ π.boxes, g J := by convert sum_fiberwise_of_maps_to (fun _ => Finset.mem_image_of_mem f) g /-- Union of two disjoint prepartitions. -/ @[simps] def disjUnion (π₁ π₂ : Prepartition I) (h : Disjoint π₁.iUnion π₂.iUnion) : Prepartition I where boxes := π₁.boxes ∪ π₂.boxes le_of_mem' J hJ := (Finset.mem_union.1 hJ).elim π₁.le_of_mem π₂.le_of_mem pairwiseDisjoint := suffices ∀ J₁ ∈ π₁, ∀ J₂ ∈ π₂, J₁ ≠ J₂ → Disjoint (J₁ : Set (ι → ℝ)) J₂ by simpa [pairwise_union_of_symmetric (symmetric_disjoint.comap _), pairwiseDisjoint] fun J₁ h₁ J₂ h₂ _ => h.mono (π₁.subset_iUnion h₁) (π₂.subset_iUnion h₂) @[simp] theorem mem_disjUnion (H : Disjoint π₁.iUnion π₂.iUnion) : J ∈ π₁.disjUnion π₂ H ↔ J ∈ π₁ √ J ∈ π₂ := Finset.mem_union @[simp] theorem iUnion_disjUnion (h : Disjoint π₁.iUnion π₂.iUnion) : (π₁.disjUnion π₂ h).iUnion = π₁.iUnion ∪ π₂.iUnion := by simp [disjUnion, Prepartition.iUnion, iUnion_or, iUnion_union_distrib] @[simp] theorem sum_disj_union_boxes {M : Type*} [AddCommMonoid M] (h : Disjoint π₁.iUnion π₂.iUnion) (f : Box ι → M) : ∑ J ∈ π₁.boxes ∪ π₂.boxes, f J = (∑ J ∈ π₁.boxes, f J) + ∑ J ∈ π₂.boxes, f J := sum_union <| disjoint_boxes_of_disjoint_iUnion h section Distortion variable [Fintype ι] /-- The distortion of a prepartition is the maximum of the distortions of the boxes of this prepartition. -/ def distortion : ℝ≥0 := π.boxes.sup Box.distortion theorem distortion_le_of_mem (h : J ∈ π) : J.distortion ≀ π.distortion := le_sup h theorem distortion_le_iff {c : ℝ≥0} : π.distortion ≀ c ↔ ∀ J ∈ π, Box.distortion J ≀ c := Finset.sup_le_iff theorem distortion_biUnion (π : Prepartition I) (πi : ∀ J, Prepartition J) : (π.biUnion πi).distortion = π.boxes.sup fun J => (πi J).distortion := sup_biUnion _ _ @[simp] theorem distortion_disjUnion (h : Disjoint π₁.iUnion π₂.iUnion) : (π₁.disjUnion π₂ h).distortion = max π₁.distortion π₂.distortion := sup_union theorem distortion_of_const {c} (h₁ : π.boxes.Nonempty) (h₂ : ∀ J ∈ π, Box.distortion J = c) : π.distortion = c := (sup_congr rfl h₂).trans (sup_const h₁ _) @[simp] theorem distortion_top (I : Box ι) : distortion (⊀ : Prepartition I) = I.distortion := sup_singleton @[simp] theorem distortion_bot (I : Box ι) : distortion (⊥ : Prepartition I) = 0 := sup_empty end Distortion /-- A prepartition `π` of `I` is a partition if the boxes of `π` cover the whole `I`. -/ def IsPartition (π : Prepartition I) := ∀ x ∈ I, ∃ J ∈ π, x ∈ J theorem isPartition_iff_iUnion_eq {π : Prepartition I} : π.IsPartition ↔ π.iUnion = I := by simp_rw [IsPartition, Set.Subset.antisymm_iff, π.iUnion_subset, true_and_iff, Set.subset_def, mem_iUnion, Box.mem_coe] @[simp] theorem isPartition_single_iff (h : J ≀ I) : IsPartition (single I J h) ↔ J = I := by simp [isPartition_iff_iUnion_eq] theorem isPartitionTop (I : Box ι) : IsPartition (⊀ : Prepartition I) := fun _ hx => ⟹I, mem_top.2 rfl, hx⟩ namespace IsPartition variable {π} theorem iUnion_eq (h : π.IsPartition) : π.iUnion = I := isPartition_iff_iUnion_eq.1 h theorem iUnion_subset (h : π.IsPartition) (π₁ : Prepartition I) : π₁.iUnion ⊆ π.iUnion := h.iUnion_eq.symm ▾ π₁.iUnion_subset protected theorem existsUnique (h : π.IsPartition) (hx : x ∈ I) : ∃! J ∈ π, x ∈ J := by rcases h x hx with ⟹J, h, hx⟩ exact ExistsUnique.intro J ⟹h, hx⟩ fun J' ⟹h', hx'⟩ => π.eq_of_mem_of_mem h' h hx' hx theorem nonempty_boxes (h : π.IsPartition) : π.boxes.Nonempty := let ⟹J, hJ, _⟩ := h _ I.upper_mem ⟹J, hJ⟩ theorem eq_of_boxes_subset (h₁ : π₁.IsPartition) (h₂ : π₁.boxes ⊆ π₂.boxes) : π₁ = π₂ := eq_of_boxes_subset_iUnion_superset h₂ <| h₁.iUnion_subset _ theorem le_iff (h : π₂.IsPartition) : π₁ ≀ π₂ ↔ ∀ J ∈ π₁, ∀ J' ∈ π₂, (J ∩ J' : Set (ι → ℝ)).Nonempty → J ≀ J' := le_iff_nonempty_imp_le_and_iUnion_subset.trans <| and_iff_left <| h.iUnion_subset _ protected theorem biUnion (h : IsPartition π) (hi : ∀ J ∈ π, IsPartition (πi J)) : IsPartition (π.biUnion πi) := fun x hx => let ⟹J, hJ, hxi⟩ := h x hx let ⟹Ji, hJi, hx⟩ := hi J hJ x hxi ⟹Ji, π.mem_biUnion.2 ⟹J, hJ, hJi⟩, hx⟩ protected theorem restrict (h : IsPartition π) (hJ : J ≀ I) : IsPartition (π.restrict J) := isPartition_iff_iUnion_eq.2 <| by simp [h.iUnion_eq, hJ] protected theorem inf (h₁ : IsPartition π₁) (h₂ : IsPartition π₂) : IsPartition (π₁ ⊓ π₂) := isPartition_iff_iUnion_eq.2 <| by simp [h₁.iUnion_eq, h₂.iUnion_eq] end IsPartition theorem iUnion_biUnion_partition (h : ∀ J ∈ π, (πi J).IsPartition) : (π.biUnion πi).iUnion = π.iUnion := (iUnion_biUnion _ _).trans <| iUnion_congr_of_surjective id surjective_id fun J => iUnion_congr_of_surjective id surjective_id fun hJ => (h J hJ).iUnion_eq theorem isPartitionDisjUnionOfEqDiff (h : π₂.iUnion = ↑I \ π₁.iUnion) : IsPartition (π₁.disjUnion π₂ <| h.symm ▾ disjoint_sdiff_self_right) := isPartition_iff_iUnion_eq.2 <| (iUnion_disjUnion _).trans <| by simp [h, π₁.iUnion_subset] end Prepartition end BoxIntegral
Analysis\BoxIntegral\Partition\Filter.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Partition.SubboxInduction import Mathlib.Analysis.BoxIntegral.Partition.Split /-! # Filters used in box-based integrals First we define a structure `BoxIntegral.IntegrationParams`. This structure will be used as an argument in the definition of `BoxIntegral.integral` in order to use the same definition for a few well-known definitions of integrals based on partitions of a rectangular box into subboxes (Riemann integral, Henstock-Kurzweil integral, and McShane integral). This structure holds three boolean values (see below), and encodes eight different sets of parameters; only four of these values are used somewhere in `mathlib4`. Three of them correspond to the integration theories listed above, and one is a generalization of the one-dimensional Henstock-Kurzweil integral such that the divergence theorem works without additional integrability assumptions. Finally, for each set of parameters `l : BoxIntegral.IntegrationParams` and a rectangular box `I : BoxIntegral.Box ι`, we define several `Filter`s that will be used either in the definition of the corresponding integral, or in the proofs of its properties. We equip `BoxIntegral.IntegrationParams` with a `BoundedOrder` structure such that larger `IntegrationParams` produce larger filters. ## Main definitions ### Integration parameters The structure `BoxIntegral.IntegrationParams` has 3 boolean fields with the following meaning: * `bRiemann`: the value `true` means that the filter corresponds to a Riemann-style integral, i.e. in the definition of integrability we require a constant upper estimate `r` on the size of boxes of a tagged partition; the value `false` means that the estimate may depend on the position of the tag. * `bHenstock`: the value `true` means that we require that each tag belongs to its own closed box; the value `false` means that we only require that tags belong to the ambient box. * `bDistortion`: the value `true` means that `r` can depend on the maximal ratio of sides of the same box of a partition. Presence of this case make quite a few proofs harder but we can prove the divergence theorem only for the filter `BoxIntegral.IntegrationParams.GP = ⊥ = {bRiemann := false, bHenstock := true, bDistortion := true}`. ### Well-known sets of parameters Out of eight possible values of `BoxIntegral.IntegrationParams`, the following four are used in the library. * `BoxIntegral.IntegrationParams.Riemann` (`bRiemann = true`, `bHenstock = true`, `bDistortion = false`): this value corresponds to the Riemann integral; in the corresponding filter, we require that the diameters of all boxes `J` of a tagged partition are bounded from above by a constant upper estimate that may not depend on the geometry of `J`, and each tag belongs to the corresponding closed box. * `BoxIntegral.IntegrationParams.Henstock` (`bRiemann = false`, `bHenstock = true`, `bDistortion = false`): this value corresponds to the most natural generalization of Henstock-Kurzweil integral to higher dimension; the only (but important!) difference between this theory and Riemann integral is that instead of a constant upper estimate on the size of all boxes of a partition, we require that the partition is *subordinate* to a possibly discontinuous function `r : (ι → ℝ) → {x : ℝ | 0 < x}`, i.e. each box `J` is included in a closed ball with center `π.tag J` and radius `r J`. * `BoxIntegral.IntegrationParams.McShane` (`bRiemann = false`, `bHenstock = false`, `bDistortion = false`): this value corresponds to the McShane integral; the only difference with the Henstock integral is that we allow tags to be outside of their boxes; the tags still have to be in the ambient closed box, and the partition still has to be subordinate to a function. * `BoxIntegral.IntegrationParams.GP = ⊥` (`bRiemann = false`, `bHenstock = true`, `bDistortion = true`): this is the least integration theory in our list, i.e., all functions integrable in any other theory is integrable in this one as well. This is a non-standard generalization of the Henstock-Kurzweil integral to higher dimension. In dimension one, it generates the same filter as `Henstock`. In higher dimension, this generalization defines an integration theory such that the divergence of any Fréchet differentiable function `f` is integrable, and its integral is equal to the sum of integrals of `f` over the faces of the box, taken with appropriate signs. A function `f` is `GP`-integrable if for any `ε > 0` and `c : ℝ≥0` there exists `r : (ι → ℝ) → {x : ℝ | 0 < x}` such that for any tagged partition `π` subordinate to `r`, if each tag belongs to the corresponding closed box and for each box `J ∈ π`, the maximal ratio of its sides is less than or equal to `c`, then the integral sum of `f` over `π` is `ε`-close to the integral. ### Filters and predicates on `TaggedPrepartition I` For each value of `IntegrationParams` and a rectangular box `I`, we define a few filters on `TaggedPrepartition I`. First, we define a predicate ``` structure BoxIntegral.IntegrationParams.MemBaseSet (l : BoxIntegral.IntegrationParams) (I : BoxIntegral.Box ι) (c : ℝ≥0) (r : (ι → ℝ) → Ioi (0 : ℝ)) (π : BoxIntegral.TaggedPrepartition I) : Prop where ``` This predicate says that * if `l.bHenstock`, then `π` is a Henstock prepartition, i.e. each tag belongs to the corresponding closed box; * `π` is subordinate to `r`; * if `l.bDistortion`, then the distortion of each box in `π` is less than or equal to `c`; * if `l.bDistortion`, then there exists a prepartition `π'` with distortion `≀ c` that covers exactly `I \ π.iUnion`. The last condition is always true for `c > 1`, see TODO section for more details. Then we define a predicate `BoxIntegral.IntegrationParams.RCond` on functions `r : (ι → ℝ) → {x : ℝ | 0 < x}`. If `l.bRiemann`, then this predicate requires `r` to be a constant function, otherwise it imposes no restrictions on `r`. We introduce this definition to prove a few dot-notation lemmas: e.g., `BoxIntegral.IntegrationParams.RCond.min` says that the pointwise minimum of two functions that satisfy this condition satisfies this condition as well. Then we define four filters on `BoxIntegral.TaggedPrepartition I`. * `BoxIntegral.IntegrationParams.toFilterDistortion`: an auxiliary filter that takes parameters `(l : BoxIntegral.IntegrationParams) (I : BoxIntegral.Box ι) (c : ℝ≥0)` and returns the filter generated by all sets `{π | MemBaseSet l I c r π}`, where `r` is a function satisfying the predicate `BoxIntegral.IntegrationParams.RCond l`; * `BoxIntegral.IntegrationParams.toFilter l I`: the supremum of `l.toFilterDistortion I c` over all `c : ℝ≥0`; * `BoxIntegral.IntegrationParams.toFilterDistortioniUnion l I c π₀`, where `π₀` is a prepartition of `I`: the infimum of `l.toFilterDistortion I c` and the principal filter generated by `{π | π.iUnion = π₀.iUnion}`; * `BoxIntegral.IntegrationParams.toFilteriUnion l I π₀`: the supremum of `l.toFilterDistortioniUnion l I c π₀` over all `c : ℝ≥0`. This is the filter (in the case `π₀ = ⊀` is the one-box partition of `I`) used in the definition of the integral of a function over a box. ## Implementation details * Later we define the integral of a function over a rectangular box as the limit (if it exists) of the integral sums along `BoxIntegral.IntegrationParams.toFilteriUnion l I ⊀`. While it is possible to define the integral with a general filter on `BoxIntegral.TaggedPrepartition I` as a parameter, many lemmas (e.g., Sacks-Henstock lemma and most results about integrability of functions) require the filter to have a predictable structure. So, instead of adding assumptions about the filter here and there, we define this auxiliary type that can encode all integration theories we need in practice. * While the definition of the integral only uses the filter `BoxIntegral.IntegrationParams.toFilteriUnion l I ⊀` and partitions of a box, some lemmas (e.g., the Henstock-Sacks lemmas) are best formulated in terms of the predicate `MemBaseSet` and other filters defined above. * We use `Bool` instead of `Prop` for the fields of `IntegrationParams` in order to have decidable equality and inequalities. ## TODO Currently, `BoxIntegral.IntegrationParams.MemBaseSet` explicitly requires that there exists a partition of the complement `I \ π.iUnion` with distortion `≀ c`. For `c > 1`, this condition is always true but the proof of this fact requires more API about `BoxIntegral.Prepartition.splitMany`. We should formalize this fact, then either require `c > 1` everywhere, or replace `≀ c` with `< c` so that we automatically get `c > 1` for a non-trivial prepartition (and consider the special case `π = ⊥` separately if needed). ## Tags integral, rectangular box, partition, filter -/ open Set Function Filter Metric Finset Bool open scoped Classical open Topology Filter NNReal noncomputable section namespace BoxIntegral variable {ι : Type*} [Fintype ι] {I J : Box ι} {c c₁ c₂ : ℝ≥0} open TaggedPrepartition /-- An `IntegrationParams` is a structure holding 3 boolean values used to define a filter to be used in the definition of a box-integrable function. * `bRiemann`: the value `true` means that the filter corresponds to a Riemann-style integral, i.e. in the definition of integrability we require a constant upper estimate `r` on the size of boxes of a tagged partition; the value `false` means that the estimate may depend on the position of the tag. * `bHenstock`: the value `true` means that we require that each tag belongs to its own closed box; the value `false` means that we only require that tags belong to the ambient box. * `bDistortion`: the value `true` means that `r` can depend on the maximal ratio of sides of the same box of a partition. Presence of this case makes quite a few proofs harder but we can prove the divergence theorem only for the filter `BoxIntegral.IntegrationParams.GP = ⊥ = {bRiemann := false, bHenstock := true, bDistortion := true}`. -/ @[ext] structure IntegrationParams : Type where (bRiemann bHenstock bDistortion : Bool) variable {l l₁ l₂ : IntegrationParams} namespace IntegrationParams /-- Auxiliary equivalence with a product type used to lift an order. -/ def equivProd : IntegrationParams ≃ Bool × Boolᵒᵈ × Boolᵒᵈ where toFun l := ⟹l.1, OrderDual.toDual l.2, OrderDual.toDual l.3⟩ invFun l := ⟹l.1, OrderDual.ofDual l.2.1, OrderDual.ofDual l.2.2⟩ left_inv _ := rfl right_inv _ := rfl instance : PartialOrder IntegrationParams := PartialOrder.lift equivProd equivProd.injective /-- Auxiliary `OrderIso` with a product type used to lift a `BoundedOrder` structure. -/ def isoProd : IntegrationParams ≃o Bool × Boolᵒᵈ × Boolᵒᵈ := ⟹equivProd, Iff.rfl⟩ instance : BoundedOrder IntegrationParams := isoProd.symm.toGaloisInsertion.liftBoundedOrder /-- The value `BoxIntegral.IntegrationParams.GP = ⊥` (`bRiemann = false`, `bHenstock = true`, `bDistortion = true`) corresponds to a generalization of the Henstock integral such that the Divergence theorem holds true without additional integrability assumptions, see the module docstring for details. -/ instance : Inhabited IntegrationParams := ⟚⊥⟩ instance : DecidableRel ((· ≀ ·) : IntegrationParams → IntegrationParams → Prop) := fun _ _ => And.decidable instance : DecidableEq IntegrationParams := fun _ _ => decidable_of_iff _ IntegrationParams.ext_iff.symm /-- The `BoxIntegral.IntegrationParams` corresponding to the Riemann integral. In the corresponding filter, we require that the diameters of all boxes `J` of a tagged partition are bounded from above by a constant upper estimate that may not depend on the geometry of `J`, and each tag belongs to the corresponding closed box. -/ def Riemann : IntegrationParams where bRiemann := true bHenstock := true bDistortion := false /-- The `BoxIntegral.IntegrationParams` corresponding to the Henstock-Kurzweil integral. In the corresponding filter, we require that the tagged partition is subordinate to a (possibly, discontinuous) positive function `r` and each tag belongs to the corresponding closed box. -/ def Henstock : IntegrationParams := ⟹false, true, false⟩ /-- The `BoxIntegral.IntegrationParams` corresponding to the McShane integral. In the corresponding filter, we require that the tagged partition is subordinate to a (possibly, discontinuous) positive function `r`; the tags may be outside of the corresponding closed box (but still inside the ambient closed box `I.Icc`). -/ def McShane : IntegrationParams := ⟹false, false, false⟩ /-- The `BoxIntegral.IntegrationParams` corresponding to the generalized Perron integral. In the corresponding filter, we require that the tagged partition is subordinate to a (possibly, discontinuous) positive function `r` and each tag belongs to the corresponding closed box. We also require an upper estimate on the distortion of all boxes of the partition. -/ def GP : IntegrationParams := ⊥ theorem henstock_le_riemann : Henstock ≀ Riemann := by trivial theorem henstock_le_mcShane : Henstock ≀ McShane := by trivial theorem gp_le : GP ≀ l := bot_le /-- The predicate corresponding to a base set of the filter defined by an `IntegrationParams`. It says that * if `l.bHenstock`, then `π` is a Henstock prepartition, i.e. each tag belongs to the corresponding closed box; * `π` is subordinate to `r`; * if `l.bDistortion`, then the distortion of each box in `π` is less than or equal to `c`; * if `l.bDistortion`, then there exists a prepartition `π'` with distortion `≀ c` that covers exactly `I \ π.iUnion`. The last condition is automatically verified for partitions, and is used in the proof of the Sacks-Henstock inequality to compare two prepartitions covering the same part of the box. It is also automatically satisfied for any `c > 1`, see TODO section of the module docstring for details. -/ structure MemBaseSet (l : IntegrationParams) (I : Box ι) (c : ℝ≥0) (r : (ι → ℝ) → Ioi (0 : ℝ)) (π : TaggedPrepartition I) : Prop where protected isSubordinate : π.IsSubordinate r protected isHenstock : l.bHenstock → π.IsHenstock protected distortion_le : l.bDistortion → π.distortion ≀ c protected exists_compl : l.bDistortion → ∃ π' : Prepartition I, π'.iUnion = ↑I \ π.iUnion ∧ π'.distortion ≀ c /-- A predicate saying that in case `l.bRiemann = true`, the function `r` is a constant. -/ def RCond {ι : Type*} (l : IntegrationParams) (r : (ι → ℝ) → Ioi (0 : ℝ)) : Prop := l.bRiemann → ∀ x, r x = r 0 /-- A set `s : Set (TaggedPrepartition I)` belongs to `l.toFilterDistortion I c` if there exists a function `r : ℝⁿ → (0, ∞)` (or a constant `r` if `l.bRiemann = true`) such that `s` contains each prepartition `π` such that `l.MemBaseSet I c r π`. -/ def toFilterDistortion (l : IntegrationParams) (I : Box ι) (c : ℝ≥0) : Filter (TaggedPrepartition I) := ⹅ (r : (ι → ℝ) → Ioi (0 : ℝ)) (_ : l.RCond r), 𝓟 { π | l.MemBaseSet I c r π } /-- A set `s : Set (TaggedPrepartition I)` belongs to `l.toFilter I` if for any `c : ℝ≥0` there exists a function `r : ℝⁿ → (0, ∞)` (or a constant `r` if `l.bRiemann = true`) such that `s` contains each prepartition `π` such that `l.MemBaseSet I c r π`. -/ def toFilter (l : IntegrationParams) (I : Box ι) : Filter (TaggedPrepartition I) := ⹆ c : ℝ≥0, l.toFilterDistortion I c /-- A set `s : Set (TaggedPrepartition I)` belongs to `l.toFilterDistortioniUnion I c π₀` if there exists a function `r : ℝⁿ → (0, ∞)` (or a constant `r` if `l.bRiemann = true`) such that `s` contains each prepartition `π` such that `l.MemBaseSet I c r π` and `π.iUnion = π₀.iUnion`. -/ def toFilterDistortioniUnion (l : IntegrationParams) (I : Box ι) (c : ℝ≥0) (π₀ : Prepartition I) := l.toFilterDistortion I c ⊓ 𝓟 { π | π.iUnion = π₀.iUnion } /-- A set `s : Set (TaggedPrepartition I)` belongs to `l.toFilteriUnion I π₀` if for any `c : ℝ≥0` there exists a function `r : ℝⁿ → (0, ∞)` (or a constant `r` if `l.bRiemann = true`) such that `s` contains each prepartition `π` such that `l.MemBaseSet I c r π` and `π.iUnion = π₀.iUnion`. -/ def toFilteriUnion (l : IntegrationParams) (I : Box ι) (π₀ : Prepartition I) := ⹆ c : ℝ≥0, l.toFilterDistortioniUnion I c π₀ theorem rCond_of_bRiemann_eq_false {ι} (l : IntegrationParams) (hl : l.bRiemann = false) {r : (ι → ℝ) → Ioi (0 : ℝ)} : l.RCond r := by simp [RCond, hl] theorem toFilter_inf_iUnion_eq (l : IntegrationParams) (I : Box ι) (π₀ : Prepartition I) : l.toFilter I ⊓ 𝓟 { π | π.iUnion = π₀.iUnion } = l.toFilteriUnion I π₀ := (iSup_inf_principal _ _).symm variable {r r₁ r₂ : (ι → ℝ) → Ioi (0 : ℝ)} {π π₁ π₂ : TaggedPrepartition I} variable (I) in theorem MemBaseSet.mono' (h : l₁ ≀ l₂) (hc : c₁ ≀ c₂) (hr : ∀ J ∈ π, r₁ (π.tag J) ≀ r₂ (π.tag J)) (hπ : l₁.MemBaseSet I c₁ r₁ π) : l₂.MemBaseSet I c₂ r₂ π := ⟹hπ.1.mono' hr, fun h₂ => hπ.2 (le_iff_imp.1 h.2.1 h₂), fun hD => (hπ.3 (le_iff_imp.1 h.2.2 hD)).trans hc, fun hD => (hπ.4 (le_iff_imp.1 h.2.2 hD)).imp fun _ hπ => ⟹hπ.1, hπ.2.trans hc⟩⟩ variable (I) in @[mono] theorem MemBaseSet.mono (h : l₁ ≀ l₂) (hc : c₁ ≀ c₂) (hr : ∀ x ∈ Box.Icc I, r₁ x ≀ r₂ x) (hπ : l₁.MemBaseSet I c₁ r₁ π) : l₂.MemBaseSet I c₂ r₂ π := hπ.mono' I h hc fun J _ => hr _ <| π.tag_mem_Icc J theorem MemBaseSet.exists_common_compl (h₁ : l.MemBaseSet I c₁ r₁ π₁) (h₂ : l.MemBaseSet I c₂ r₂ π₂) (hU : π₁.iUnion = π₂.iUnion) : ∃ π : Prepartition I, π.iUnion = ↑I \ π₁.iUnion ∧ (l.bDistortion → π.distortion ≀ c₁) ∧ (l.bDistortion → π.distortion ≀ c₂) := by wlog hc : c₁ ≀ c₂ with H · simpa [hU, _root_.and_comm] using @H _ _ I J c c₂ c₁ _ l₂ l₁ r r₂ r₁ π π₂ π₁ h₂ h₁ hU.symm (le_of_not_le hc) by_cases hD : (l.bDistortion : Prop) · rcases h₁.4 hD with ⟚π, hπU, hπc⟩ exact ⟚π, hπU, fun _ => hπc, fun _ => hπc.trans hc⟩ · exact ⟚π₁.toPrepartition.compl, π₁.toPrepartition.iUnion_compl, fun h => (hD h).elim, fun h => (hD h).elim⟩ protected theorem MemBaseSet.unionComplToSubordinate (hπ₁ : l.MemBaseSet I c r₁ π₁) (hle : ∀ x ∈ Box.Icc I, r₂ x ≀ r₁ x) {π₂ : Prepartition I} (hU : π₂.iUnion = ↑I \ π₁.iUnion) (hc : l.bDistortion → π₂.distortion ≀ c) : l.MemBaseSet I c r₁ (π₁.unionComplToSubordinate π₂ hU r₂) := ⟹hπ₁.1.disjUnion ((π₂.isSubordinate_toSubordinate r₂).mono hle) _, fun h => (hπ₁.2 h).disjUnion (π₂.isHenstock_toSubordinate _) _, fun h => (distortion_unionComplToSubordinate _ _ _ _).trans_le (max_le (hπ₁.3 h) (hc h)), fun _ => ⟚⊥, by simp⟩⟩ protected theorem MemBaseSet.filter (hπ : l.MemBaseSet I c r π) (p : Box ι → Prop) : l.MemBaseSet I c r (π.filter p) := by refine ⟹fun J hJ => hπ.1 J (π.mem_filter.1 hJ).1, fun hH J hJ => hπ.2 hH J (π.mem_filter.1 hJ).1, fun hD => (distortion_filter_le _ _).trans (hπ.3 hD), fun hD => ?_⟩ rcases hπ.4 hD with ⟚π₁, hπ₁U, hc⟩ set π₂ := π.filter fun J => ¬p J have : Disjoint π₁.iUnion π₂.iUnion := by simpa [π₂, hπ₁U] using disjoint_sdiff_self_left.mono_right sdiff_le refine ⟚π₁.disjUnion π₂.toPrepartition this, ?_, ?_⟩ · suffices ↑I \ π.iUnion ∪ π.iUnion \ (π.filter p).iUnion = ↑I \ (π.filter p).iUnion by simp [π₂, *] have h : (π.filter p).iUnion ⊆ π.iUnion := biUnion_subset_biUnion_left (Finset.filter_subset _ _) ext x fconstructor · rintro (⟹hxI, hxπ⟩ | ⟹hxπ, hxp⟩) exacts [⟹hxI, mt (@h x) hxπ⟩, ⟚π.iUnion_subset hxπ, hxp⟩] · rintro ⟹hxI, hxp⟩ by_cases hxπ : x ∈ π.iUnion exacts [Or.inr ⟹hxπ, hxp⟩, Or.inl ⟹hxI, hxπ⟩] · have : (π.filter fun J => ¬p J).distortion ≀ c := (distortion_filter_le _ _).trans (hπ.3 hD) simpa [hc] theorem biUnionTagged_memBaseSet {π : Prepartition I} {πi : ∀ J, TaggedPrepartition J} (h : ∀ J ∈ π, l.MemBaseSet J c r (πi J)) (hp : ∀ J ∈ π, (πi J).IsPartition) (hc : l.bDistortion → π.compl.distortion ≀ c) : l.MemBaseSet I c r (π.biUnionTagged πi) := by refine ⟹TaggedPrepartition.isSubordinate_biUnionTagged.2 fun J hJ => (h J hJ).1, fun hH => TaggedPrepartition.isHenstock_biUnionTagged.2 fun J hJ => (h J hJ).2 hH, fun hD => ?_, fun hD => ?_⟩ · rw [Prepartition.distortion_biUnionTagged, Finset.sup_le_iff] exact fun J hJ => (h J hJ).3 hD · refine ⟹_, ?_, hc hD⟩ rw [π.iUnion_compl, ← π.iUnion_biUnion_partition hp] rfl @[mono] theorem RCond.mono {ι : Type*} {r : (ι → ℝ) → Ioi (0 : ℝ)} (h : l₁ ≀ l₂) (hr : l₂.RCond r) : l₁.RCond r := fun hR => hr (le_iff_imp.1 h.1 hR) nonrec theorem RCond.min {ι : Type*} {r₁ r₂ : (ι → ℝ) → Ioi (0 : ℝ)} (h₁ : l.RCond r₁) (h₂ : l.RCond r₂) : l.RCond fun x => min (r₁ x) (r₂ x) := fun hR x => congr_arg₂ min (h₁ hR x) (h₂ hR x) @[mono] theorem toFilterDistortion_mono (I : Box ι) (h : l₁ ≀ l₂) (hc : c₁ ≀ c₂) : l₁.toFilterDistortion I c₁ ≀ l₂.toFilterDistortion I c₂ := iInf_mono fun _ => iInf_mono' fun hr => ⟹hr.mono h, principal_mono.2 fun _ => MemBaseSet.mono I h hc fun _ _ => le_rfl⟩ @[mono] theorem toFilter_mono (I : Box ι) {l₁ l₂ : IntegrationParams} (h : l₁ ≀ l₂) : l₁.toFilter I ≀ l₂.toFilter I := iSup_mono fun _ => toFilterDistortion_mono I h le_rfl @[mono] theorem toFilteriUnion_mono (I : Box ι) {l₁ l₂ : IntegrationParams} (h : l₁ ≀ l₂) (π₀ : Prepartition I) : l₁.toFilteriUnion I π₀ ≀ l₂.toFilteriUnion I π₀ := iSup_mono fun _ => inf_le_inf_right _ <| toFilterDistortion_mono _ h le_rfl theorem toFilteriUnion_congr (I : Box ι) (l : IntegrationParams) {π₁ π₂ : Prepartition I} (h : π₁.iUnion = π₂.iUnion) : l.toFilteriUnion I π₁ = l.toFilteriUnion I π₂ := by simp only [toFilteriUnion, toFilterDistortioniUnion, h] theorem hasBasis_toFilterDistortion (l : IntegrationParams) (I : Box ι) (c : ℝ≥0) : (l.toFilterDistortion I c).HasBasis l.RCond fun r => { π | l.MemBaseSet I c r π } := hasBasis_biInf_principal' (fun _ hr₁ _ hr₂ => ⟹_, hr₁.min hr₂, fun _ => MemBaseSet.mono _ le_rfl le_rfl fun _ _ => min_le_left _ _, fun _ => MemBaseSet.mono _ le_rfl le_rfl fun _ _ => min_le_right _ _⟩) ⟹fun _ => ⟹1, Set.mem_Ioi.2 zero_lt_one⟩, fun _ _ => rfl⟩ theorem hasBasis_toFilterDistortioniUnion (l : IntegrationParams) (I : Box ι) (c : ℝ≥0) (π₀ : Prepartition I) : (l.toFilterDistortioniUnion I c π₀).HasBasis l.RCond fun r => { π | l.MemBaseSet I c r π ∧ π.iUnion = π₀.iUnion } := (l.hasBasis_toFilterDistortion I c).inf_principal _ theorem hasBasis_toFilteriUnion (l : IntegrationParams) (I : Box ι) (π₀ : Prepartition I) : (l.toFilteriUnion I π₀).HasBasis (fun r : ℝ≥0 → (ι → ℝ) → Ioi (0 : ℝ) => ∀ c, l.RCond (r c)) fun r => { π | ∃ c, l.MemBaseSet I c (r c) π ∧ π.iUnion = π₀.iUnion } := by have := fun c => l.hasBasis_toFilterDistortioniUnion I c π₀ simpa only [setOf_and, setOf_exists] using hasBasis_iSup this theorem hasBasis_toFilteriUnion_top (l : IntegrationParams) (I : Box ι) : (l.toFilteriUnion I ⊀).HasBasis (fun r : ℝ≥0 → (ι → ℝ) → Ioi (0 : ℝ) => ∀ c, l.RCond (r c)) fun r => { π | ∃ c, l.MemBaseSet I c (r c) π ∧ π.IsPartition } := by simpa only [TaggedPrepartition.isPartition_iff_iUnion_eq, Prepartition.iUnion_top] using l.hasBasis_toFilteriUnion I ⊀ theorem hasBasis_toFilter (l : IntegrationParams) (I : Box ι) : (l.toFilter I).HasBasis (fun r : ℝ≥0 → (ι → ℝ) → Ioi (0 : ℝ) => ∀ c, l.RCond (r c)) fun r => { π | ∃ c, l.MemBaseSet I c (r c) π } := by simpa only [setOf_exists] using hasBasis_iSup (l.hasBasis_toFilterDistortion I) theorem tendsto_embedBox_toFilteriUnion_top (l : IntegrationParams) (h : I ≀ J) : Tendsto (TaggedPrepartition.embedBox I J h) (l.toFilteriUnion I ⊀) (l.toFilteriUnion J (Prepartition.single J I h)) := by simp only [toFilteriUnion, tendsto_iSup]; intro c set π₀ := Prepartition.single J I h refine le_iSup_of_le (max c π₀.compl.distortion) ?_ refine ((l.hasBasis_toFilterDistortioniUnion I c ⊀).tendsto_iff (l.hasBasis_toFilterDistortioniUnion J _ _)).2 fun r hr => ?_ refine ⟹r, hr, fun π hπ => ?_⟩ rw [mem_setOf_eq, Prepartition.iUnion_top] at hπ refine ⟹⟹hπ.1.1, hπ.1.2, fun hD => le_trans (hπ.1.3 hD) (le_max_left _ _), fun _ => ?_⟩, ?_⟩ · refine ⟹_, π₀.iUnion_compl.trans ?_, le_max_right _ _⟩ congr 1 exact (Prepartition.iUnion_single h).trans hπ.2.symm · exact hπ.2.trans (Prepartition.iUnion_single _).symm theorem exists_memBaseSet_le_iUnion_eq (l : IntegrationParams) (π₀ : Prepartition I) (hc₁ : π₀.distortion ≀ c) (hc₂ : π₀.compl.distortion ≀ c) (r : (ι → ℝ) → Ioi (0 : ℝ)) : ∃ π, l.MemBaseSet I c r π ∧ π.toPrepartition ≀ π₀ ∧ π.iUnion = π₀.iUnion := by rcases π₀.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r with ⟚π, hle, hH, hr, hd, hU⟩ refine ⟚π, ⟹hr, fun _ => hH, fun _ => hd.trans_le hc₁, fun _ => ⟚π₀.compl, ?_, hc₂⟩⟩, ⟹hle, hU⟩⟩ exact Prepartition.compl_congr hU ▾ π.toPrepartition.iUnion_compl theorem exists_memBaseSet_isPartition (l : IntegrationParams) (I : Box ι) (hc : I.distortion ≀ c) (r : (ι → ℝ) → Ioi (0 : ℝ)) : ∃ π, l.MemBaseSet I c r π ∧ π.IsPartition := by rw [← Prepartition.distortion_top] at hc have hc' : (⊀ : Prepartition I).compl.distortion ≀ c := by simp simpa [isPartition_iff_iUnion_eq] using l.exists_memBaseSet_le_iUnion_eq ⊀ hc hc' r theorem toFilterDistortioniUnion_neBot (l : IntegrationParams) (I : Box ι) (π₀ : Prepartition I) (hc₁ : π₀.distortion ≀ c) (hc₂ : π₀.compl.distortion ≀ c) : (l.toFilterDistortioniUnion I c π₀).NeBot := ((l.hasBasis_toFilterDistortion I _).inf_principal _).neBot_iff.2 fun {r} _ => (l.exists_memBaseSet_le_iUnion_eq π₀ hc₁ hc₂ r).imp fun _ hπ => ⟹hπ.1, hπ.2.2⟩ instance toFilterDistortioniUnion_neBot' (l : IntegrationParams) (I : Box ι) (π₀ : Prepartition I) : (l.toFilterDistortioniUnion I (max π₀.distortion π₀.compl.distortion) π₀).NeBot := l.toFilterDistortioniUnion_neBot I π₀ (le_max_left _ _) (le_max_right _ _) instance toFilterDistortion_neBot (l : IntegrationParams) (I : Box ι) : (l.toFilterDistortion I I.distortion).NeBot := by simpa using (l.toFilterDistortioniUnion_neBot' I ⊀).mono inf_le_left instance toFilter_neBot (l : IntegrationParams) (I : Box ι) : (l.toFilter I).NeBot := (l.toFilterDistortion_neBot I).mono <| le_iSup _ _ instance toFilteriUnion_neBot (l : IntegrationParams) (I : Box ι) (π₀ : Prepartition I) : (l.toFilteriUnion I π₀).NeBot := (l.toFilterDistortioniUnion_neBot' I π₀).mono <| le_iSup (fun c => l.toFilterDistortioniUnion I c π₀) _ theorem eventually_isPartition (l : IntegrationParams) (I : Box ι) : ∀ᶠ π in l.toFilteriUnion I ⊀, TaggedPrepartition.IsPartition π := eventually_iSup.2 fun _ => eventually_inf_principal.2 <| eventually_of_forall fun π h => π.isPartition_iff_iUnion_eq.2 (h.trans Prepartition.iUnion_top) end IntegrationParams end BoxIntegral
Analysis\BoxIntegral\Partition\Measure.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Partition.Additive import Mathlib.MeasureTheory.Measure.Lebesgue.Basic /-! # Box-additive functions defined by measures In this file we prove a few simple facts about rectangular boxes, partitions, and measures: - given a box `I : Box ι`, its coercion to `Set (ι → ℝ)` and `I.Icc` are measurable sets; - if `ÎŒ` is a locally finite measure, then `(I : Set (ι → ℝ))` and `I.Icc` have finite measure; - if `ÎŒ` is a locally finite measure, then `fun J ↩ (ÎŒ J).toReal` is a box additive function. For the last statement, we both prove it as a proposition and define a bundled `BoxIntegral.BoxAdditiveMap` function. ## Tags rectangular box, measure -/ open Set noncomputable section open scoped ENNReal BoxIntegral variable {ι : Type*} namespace BoxIntegral open MeasureTheory namespace Box variable (I : Box ι) theorem measure_Icc_lt_top (ÎŒ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure ÎŒ] : ÎŒ (Box.Icc I) < ∞ := show ÎŒ (Icc I.lower I.upper) < ∞ from I.isCompact_Icc.measure_lt_top theorem measure_coe_lt_top (ÎŒ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure ÎŒ] : ÎŒ I < ∞ := (measure_mono <| coe_subset_Icc).trans_lt (I.measure_Icc_lt_top ÎŒ) section Countable variable [Countable ι] theorem measurableSet_coe : MeasurableSet (I : Set (ι → ℝ)) := by rw [coe_eq_pi] exact MeasurableSet.univ_pi fun i => measurableSet_Ioc theorem measurableSet_Icc : MeasurableSet (Box.Icc I) := _root_.measurableSet_Icc theorem measurableSet_Ioo : MeasurableSet (Box.Ioo I) := MeasurableSet.univ_pi fun _ => _root_.measurableSet_Ioo end Countable variable [Fintype ι] theorem coe_ae_eq_Icc : (I : Set (ι → ℝ)) =ᵐ[volume] Box.Icc I := by rw [coe_eq_pi] exact Measure.univ_pi_Ioc_ae_eq_Icc theorem Ioo_ae_eq_Icc : Box.Ioo I =ᵐ[volume] Box.Icc I := Measure.univ_pi_Ioo_ae_eq_Icc end Box theorem Prepartition.measure_iUnion_toReal [Finite ι] {I : Box ι} (π : Prepartition I) (ÎŒ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure ÎŒ] : (ÎŒ π.iUnion).toReal = ∑ J ∈ π.boxes, (ÎŒ J).toReal := by erw [← ENNReal.toReal_sum, π.iUnion_def, measure_biUnion_finset π.pairwiseDisjoint] exacts [fun J _ => J.measurableSet_coe, fun J _ => (J.measure_coe_lt_top ÎŒ).ne] end BoxIntegral open BoxIntegral BoxIntegral.Box namespace MeasureTheory namespace Measure /-- If `ÎŒ` is a locally finite measure on `ℝⁿ`, then `fun J ↩ (ÎŒ J).toReal` is a box-additive function. -/ @[simps] def toBoxAdditive [Finite ι] (ÎŒ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure ÎŒ] : ι →ᵇᵃ[⊀] ℝ where toFun J := (ÎŒ J).toReal sum_partition_boxes' J _ π hπ := by rw [← π.measure_iUnion_toReal, hπ.iUnion_eq] end Measure end MeasureTheory namespace BoxIntegral open MeasureTheory namespace Box variable [Fintype ι] -- @[simp] -- Porting note: simp normal form is `volume_apply'` theorem volume_apply (I : Box ι) : (volume : Measure (ι → ℝ)).toBoxAdditive I = ∏ i, (I.upper i - I.lower i) := by rw [Measure.toBoxAdditive_apply, coe_eq_pi, Real.volume_pi_Ioc_toReal I.lower_le_upper] @[simp] theorem volume_apply' (I : Box ι) : ((volume : Measure (ι → ℝ)) I).toReal = ∏ i, (I.upper i - I.lower i) := by rw [coe_eq_pi, Real.volume_pi_Ioc_toReal I.lower_le_upper] theorem volume_face_mul {n} (i : Fin (n + 1)) (I : Box (Fin (n + 1))) : (∏ j, ((I.face i).upper j - (I.face i).lower j)) * (I.upper i - I.lower i) = ∏ j, (I.upper j - I.lower j) := by simp only [face_lower, face_upper, (· ∘ ·), Fin.prod_univ_succAbove _ i, mul_comm] end Box namespace BoxAdditiveMap variable [Fintype ι] /-- Box-additive map sending each box `I` to the continuous linear endomorphism `x ↩ (volume I).toReal • x`. -/ protected def volume {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] : ι →ᵇᵃ E →L[ℝ] E := (volume : Measure (ι → ℝ)).toBoxAdditive.toSMul theorem volume_apply {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (I : Box ι) (x : E) : BoxAdditiveMap.volume I x = (∏ j, (I.upper j - I.lower j)) • x := by rw [BoxAdditiveMap.volume, toSMul_apply] exact congr_arg₂ (· • ·) I.volume_apply rfl end BoxAdditiveMap end BoxIntegral
Analysis\BoxIntegral\Partition\Split.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Partition.Basic /-! # Split a box along one or more hyperplanes ## Main definitions A hyperplane `{x : ι → ℝ | x i = a}` splits a rectangular box `I : BoxIntegral.Box ι` into two smaller boxes. If `a ∉ Ioo (I.lower i, I.upper i)`, then one of these boxes is empty, so it is not a box in the sense of `BoxIntegral.Box`. We introduce the following definitions. * `BoxIntegral.Box.splitLower I i a` and `BoxIntegral.Box.splitUpper I i a` are these boxes (as `WithBot (BoxIntegral.Box ι)`); * `BoxIntegral.Prepartition.split I i a` is the partition of `I` made of these two boxes (or of one box `I` if one of these boxes is empty); * `BoxIntegral.Prepartition.splitMany I s`, where `s : Finset (ι × ℝ)` is a finite set of hyperplanes `{x : ι → ℝ | x i = a}` encoded as pairs `(i, a)`, is the partition of `I` made by cutting it along all the hyperplanes in `s`. ## Main results The main result `BoxIntegral.Prepartition.exists_iUnion_eq_diff` says that any prepartition `π` of `I` admits a prepartition `π'` of `I` that covers exactly `I \ π.iUnion`. One of these prepartitions is available as `BoxIntegral.Prepartition.compl`. ## Tags rectangular box, partition, hyperplane -/ noncomputable section open scoped Classical open Filter open Function Set Filter namespace BoxIntegral variable {ι M : Type*} {n : ℕ} namespace Box variable {I : Box ι} {i : ι} {x : ℝ} {y : ι → ℝ} /-- Given a box `I` and `x ∈ (I.lower i, I.upper i)`, the hyperplane `{y : ι → ℝ | y i = x}` splits `I` into two boxes. `BoxIntegral.Box.splitLower I i x` is the box `I ∩ {y | y i ≀ x}` (if it is nonempty). As usual, we represent a box that may be empty as `WithBot (BoxIntegral.Box ι)`. -/ def splitLower (I : Box ι) (i : ι) (x : ℝ) : WithBot (Box ι) := mk' I.lower (update I.upper i (min x (I.upper i))) @[simp] theorem coe_splitLower : (splitLower I i x : Set (ι → ℝ)) = ↑I ∩ { y | y i ≀ x } := by rw [splitLower, coe_mk'] ext y simp only [mem_univ_pi, mem_Ioc, mem_inter_iff, mem_coe, mem_setOf_eq, forall_and, ← Pi.le_def, le_update_iff, le_min_iff, and_assoc, and_forall_ne (p := fun j => y j ≀ upper I j) i, mem_def] rw [and_comm (a := y i ≀ x)] theorem splitLower_le : I.splitLower i x ≀ I := withBotCoe_subset_iff.1 <| by simp @[simp] theorem splitLower_eq_bot {i x} : I.splitLower i x = ⊥ ↔ x ≀ I.lower i := by rw [splitLower, mk'_eq_bot, exists_update_iff I.upper fun j y => y ≀ I.lower j] simp [(I.lower_lt_upper _).not_le] @[simp] theorem splitLower_eq_self : I.splitLower i x = I ↔ I.upper i ≀ x := by simp [splitLower, update_eq_iff] theorem splitLower_def [DecidableEq ι] {i x} (h : x ∈ Ioo (I.lower i) (I.upper i)) (h' : ∀ j, I.lower j < update I.upper i x j := (forall_update_iff I.upper fun j y => I.lower j < y).2 ⟹h.1, fun j _ => I.lower_lt_upper _⟩) : I.splitLower i x = (⟹I.lower, update I.upper i x, h'⟩ : Box ι) := by simp (config := { unfoldPartialApp := true }) only [splitLower, mk'_eq_coe, min_eq_left h.2.le, update, and_self] /-- Given a box `I` and `x ∈ (I.lower i, I.upper i)`, the hyperplane `{y : ι → ℝ | y i = x}` splits `I` into two boxes. `BoxIntegral.Box.splitUpper I i x` is the box `I ∩ {y | x < y i}` (if it is nonempty). As usual, we represent a box that may be empty as `WithBot (BoxIntegral.Box ι)`. -/ def splitUpper (I : Box ι) (i : ι) (x : ℝ) : WithBot (Box ι) := mk' (update I.lower i (max x (I.lower i))) I.upper @[simp] theorem coe_splitUpper : (splitUpper I i x : Set (ι → ℝ)) = ↑I ∩ { y | x < y i } := by rw [splitUpper, coe_mk'] ext y simp only [mem_univ_pi, mem_Ioc, mem_inter_iff, mem_coe, mem_setOf_eq, forall_and, forall_update_iff I.lower fun j z => z < y j, max_lt_iff, and_assoc (a := x < y i), and_forall_ne (p := fun j => lower I j < y j) i, mem_def] exact and_comm theorem splitUpper_le : I.splitUpper i x ≀ I := withBotCoe_subset_iff.1 <| by simp @[simp] theorem splitUpper_eq_bot {i x} : I.splitUpper i x = ⊥ ↔ I.upper i ≀ x := by rw [splitUpper, mk'_eq_bot, exists_update_iff I.lower fun j y => I.upper j ≀ y] simp [(I.lower_lt_upper _).not_le] @[simp] theorem splitUpper_eq_self : I.splitUpper i x = I ↔ x ≀ I.lower i := by simp [splitUpper, update_eq_iff] theorem splitUpper_def [DecidableEq ι] {i x} (h : x ∈ Ioo (I.lower i) (I.upper i)) (h' : ∀ j, update I.lower i x j < I.upper j := (forall_update_iff I.lower fun j y => y < I.upper j).2 ⟹h.2, fun j _ => I.lower_lt_upper _⟩) : I.splitUpper i x = (⟹update I.lower i x, I.upper, h'⟩ : Box ι) := by simp (config := { unfoldPartialApp := true }) only [splitUpper, mk'_eq_coe, max_eq_left h.1.le, update, and_self] theorem disjoint_splitLower_splitUpper (I : Box ι) (i : ι) (x : ℝ) : Disjoint (I.splitLower i x) (I.splitUpper i x) := by rw [← disjoint_withBotCoe, coe_splitLower, coe_splitUpper] refine (Disjoint.inf_left' _ ?_).inf_right' _ rw [Set.disjoint_left] exact fun y (hle : y i ≀ x) hlt => not_lt_of_le hle hlt theorem splitLower_ne_splitUpper (I : Box ι) (i : ι) (x : ℝ) : I.splitLower i x ≠ I.splitUpper i x := by cases' le_or_lt x (I.lower i) with h · rw [splitUpper_eq_self.2 h, splitLower_eq_bot.2 h] exact WithBot.bot_ne_coe · refine (disjoint_splitLower_splitUpper I i x).ne ?_ rwa [Ne, splitLower_eq_bot, not_le] end Box namespace Prepartition variable {I J : Box ι} {i : ι} {x : ℝ} /-- The partition of `I : Box ι` into the boxes `I ∩ {y | y ≀ x i}` and `I ∩ {y | x i < y}`. One of these boxes can be empty, then this partition is just the single-box partition `⊀`. -/ def split (I : Box ι) (i : ι) (x : ℝ) : Prepartition I := ofWithBot {I.splitLower i x, I.splitUpper i x} (by simp only [Finset.mem_insert, Finset.mem_singleton] rintro J (rfl | rfl) exacts [Box.splitLower_le, Box.splitUpper_le]) (by simp only [Finset.coe_insert, Finset.coe_singleton, true_and_iff, Set.mem_singleton_iff, pairwise_insert_of_symmetric symmetric_disjoint, pairwise_singleton] rintro J rfl - exact I.disjoint_splitLower_splitUpper i x) @[simp] theorem mem_split_iff : J ∈ split I i x ↔ ↑J = I.splitLower i x √ ↑J = I.splitUpper i x := by simp [split] theorem mem_split_iff' : J ∈ split I i x ↔ (J : Set (ι → ℝ)) = ↑I ∩ { y | y i ≀ x } √ (J : Set (ι → ℝ)) = ↑I ∩ { y | x < y i } := by simp [mem_split_iff, ← Box.withBotCoe_inj] @[simp] theorem iUnion_split (I : Box ι) (i : ι) (x : ℝ) : (split I i x).iUnion = I := by simp [split, ← inter_union_distrib_left, ← setOf_or, le_or_lt] theorem isPartitionSplit (I : Box ι) (i : ι) (x : ℝ) : IsPartition (split I i x) := isPartition_iff_iUnion_eq.2 <| iUnion_split I i x -- Porting note: In the type, changed `Option.elim` to `Option.elim'` theorem sum_split_boxes {M : Type*} [AddCommMonoid M] (I : Box ι) (i : ι) (x : ℝ) (f : Box ι → M) : (∑ J ∈ (split I i x).boxes, f J) = (I.splitLower i x).elim' 0 f + (I.splitUpper i x).elim' 0 f := by rw [split, sum_ofWithBot, Finset.sum_pair (I.splitLower_ne_splitUpper i x)] /-- If `x ∉ (I.lower i, I.upper i)`, then the hyperplane `{y | y i = x}` does not split `I`. -/ theorem split_of_not_mem_Ioo (h : x ∉ Ioo (I.lower i) (I.upper i)) : split I i x = ⊀ := by refine ((isPartitionTop I).eq_of_boxes_subset fun J hJ => ?_).symm rcases mem_top.1 hJ with rfl; clear hJ rw [mem_boxes, mem_split_iff] rw [mem_Ioo, not_and_or, not_lt, not_lt] at h cases h <;> [right; left] · rwa [eq_comm, Box.splitUpper_eq_self] · rwa [eq_comm, Box.splitLower_eq_self] theorem coe_eq_of_mem_split_of_mem_le {y : ι → ℝ} (h₁ : J ∈ split I i x) (h₂ : y ∈ J) (h₃ : y i ≀ x) : (J : Set (ι → ℝ)) = ↑I ∩ { y | y i ≀ x } := by refine (mem_split_iff'.1 h₁).resolve_right fun H => ?_ rw [← Box.mem_coe, H] at h₂ exact h₃.not_lt h₂.2 theorem coe_eq_of_mem_split_of_lt_mem {y : ι → ℝ} (h₁ : J ∈ split I i x) (h₂ : y ∈ J) (h₃ : x < y i) : (J : Set (ι → ℝ)) = ↑I ∩ { y | x < y i } := by refine (mem_split_iff'.1 h₁).resolve_left fun H => ?_ rw [← Box.mem_coe, H] at h₂ exact h₃.not_le h₂.2 @[simp] theorem restrict_split (h : I ≀ J) (i : ι) (x : ℝ) : (split J i x).restrict I = split I i x := by refine ((isPartitionSplit J i x).restrict h).eq_of_boxes_subset ?_ simp only [Finset.subset_iff, mem_boxes, mem_restrict', exists_prop, mem_split_iff'] have : ∀ s, (I ∩ s : Set (ι → ℝ)) ⊆ J := fun s => inter_subset_left.trans h rintro J₁ ⟹J₂, H₂ | H₂, H₁⟩ <;> [left; right] <;> simp [H₁, H₂, inter_left_comm (I : Set (ι → ℝ)), this] theorem inf_split (π : Prepartition I) (i : ι) (x : ℝ) : π ⊓ split I i x = π.biUnion fun J => split J i x := biUnion_congr_of_le rfl fun _ hJ => restrict_split hJ i x /-- Split a box along many hyperplanes `{y | y i = x}`; each hyperplane is given by the pair `(i x)`. -/ def splitMany (I : Box ι) (s : Finset (ι × ℝ)) : Prepartition I := s.inf fun p => split I p.1 p.2 @[simp] theorem splitMany_empty (I : Box ι) : splitMany I ∅ = ⊀ := Finset.inf_empty @[simp] theorem splitMany_insert (I : Box ι) (s : Finset (ι × ℝ)) (p : ι × ℝ) : splitMany I (insert p s) = splitMany I s ⊓ split I p.1 p.2 := by rw [splitMany, Finset.inf_insert, inf_comm, splitMany] theorem splitMany_le_split (I : Box ι) {s : Finset (ι × ℝ)} {p : ι × ℝ} (hp : p ∈ s) : splitMany I s ≀ split I p.1 p.2 := Finset.inf_le hp theorem isPartition_splitMany (I : Box ι) (s : Finset (ι × ℝ)) : IsPartition (splitMany I s) := Finset.induction_on s (by simp only [splitMany_empty, isPartitionTop]) fun a s _ hs => by simpa only [splitMany_insert, inf_split] using hs.biUnion fun J _ => isPartitionSplit _ _ _ @[simp] theorem iUnion_splitMany (I : Box ι) (s : Finset (ι × ℝ)) : (splitMany I s).iUnion = I := (isPartition_splitMany I s).iUnion_eq theorem inf_splitMany {I : Box ι} (π : Prepartition I) (s : Finset (ι × ℝ)) : π ⊓ splitMany I s = π.biUnion fun J => splitMany J s := by induction' s using Finset.induction_on with p s _ ihp · simp · simp_rw [splitMany_insert, ← inf_assoc, ihp, inf_split, biUnion_assoc] /-- Let `s : Finset (ι × ℝ)` be a set of hyperplanes `{x : ι → ℝ | x i = r}` in `ι → ℝ` encoded as pairs `(i, r)`. Suppose that this set contains all faces of a box `J`. The hyperplanes of `s` split a box `I` into subboxes. Let `Js` be one of them. If `J` and `Js` have nonempty intersection, then `Js` is a subbox of `J`. -/ theorem not_disjoint_imp_le_of_subset_of_mem_splitMany {I J Js : Box ι} {s : Finset (ι × ℝ)} (H : ∀ i, {(i, J.lower i), (i, J.upper i)} ⊆ s) (HJs : Js ∈ splitMany I s) (Hn : ¬Disjoint (J : WithBot (Box ι)) Js) : Js ≀ J := by simp only [Finset.insert_subset_iff, Finset.singleton_subset_iff] at H rcases Box.not_disjoint_coe_iff_nonempty_inter.mp Hn with ⟹x, hx, hxs⟩ refine fun y hy i => ⟹?_, ?_⟩ · rcases splitMany_le_split I (H i).1 HJs with ⟹Jl, Hmem : Jl ∈ split I i (J.lower i), Hle⟩ have := Hle hxs rw [← Box.coe_subset_coe, coe_eq_of_mem_split_of_lt_mem Hmem this (hx i).1] at Hle exact (Hle hy).2 · rcases splitMany_le_split I (H i).2 HJs with ⟹Jl, Hmem : Jl ∈ split I i (J.upper i), Hle⟩ have := Hle hxs rw [← Box.coe_subset_coe, coe_eq_of_mem_split_of_mem_le Hmem this (hx i).2] at Hle exact (Hle hy).2 section Finite variable [Finite ι] /-- Let `s` be a finite set of boxes in `ℝⁿ = ι → ℝ`. Then there exists a finite set `t₀` of hyperplanes (namely, the set of all hyperfaces of boxes in `s`) such that for any `t ⊇ t₀` and any box `I` in `ℝⁿ` the following holds. The hyperplanes from `t` split `I` into subboxes. Let `J'` be one of them, and let `J` be one of the boxes in `s`. If these boxes have a nonempty intersection, then `J' ≀ J`. -/ theorem eventually_not_disjoint_imp_le_of_mem_splitMany (s : Finset (Box ι)) : ∀ᶠ t : Finset (ι × ℝ) in atTop, ∀ (I : Box ι), ∀ J ∈ s, ∀ J' ∈ splitMany I t, ¬Disjoint (J : WithBot (Box ι)) J' → J' ≀ J := by cases nonempty_fintype ι refine eventually_atTop.2 ⟹s.biUnion fun J => Finset.univ.biUnion fun i => {(i, J.lower i), (i, J.upper i)}, fun t ht I J hJ J' hJ' => not_disjoint_imp_le_of_subset_of_mem_splitMany (fun i => ?_) hJ'⟩ exact fun p hp => ht (Finset.mem_biUnion.2 ⟹J, hJ, Finset.mem_biUnion.2 ⟹i, Finset.mem_univ _, hp⟩⟩) theorem eventually_splitMany_inf_eq_filter (π : Prepartition I) : ∀ᶠ t : Finset (ι × ℝ) in atTop, π ⊓ splitMany I t = (splitMany I t).filter fun J => ↑J ⊆ π.iUnion := by refine (eventually_not_disjoint_imp_le_of_mem_splitMany π.boxes).mono fun t ht => ?_ refine le_antisymm ((biUnion_le_iff _).2 fun J hJ => ?_) (le_inf (fun J hJ => ?_) (filter_le _ _)) · refine ofWithBot_mono ?_ simp only [Finset.mem_image, exists_prop, mem_boxes, mem_filter] rintro _ ⟹J₁, h₁, rfl⟩ hne refine ⟹_, ⟹J₁, ⟹h₁, Subset.trans ?_ (π.subset_iUnion hJ)⟩, rfl⟩, le_rfl⟩ exact ht I J hJ J₁ h₁ (mt disjoint_iff.1 hne) · rw [mem_filter] at hJ rcases Set.mem_iUnion₂.1 (hJ.2 J.upper_mem) with ⟹J', hJ', hmem⟩ refine ⟹J', hJ', ht I _ hJ' _ hJ.1 <| Box.not_disjoint_coe_iff_nonempty_inter.2 ?_⟩ exact ⟹J.upper, hmem, J.upper_mem⟩ theorem exists_splitMany_inf_eq_filter_of_finite (s : Set (Prepartition I)) (hs : s.Finite) : ∃ t : Finset (ι × ℝ), ∀ π ∈ s, π ⊓ splitMany I t = (splitMany I t).filter fun J => ↑J ⊆ π.iUnion := haveI := fun π (_ : π ∈ s) => eventually_splitMany_inf_eq_filter π (hs.eventually_all.2 this).exists /-- If `π` is a partition of `I`, then there exists a finite set `s` of hyperplanes such that `splitMany I s ≀ π`. -/ theorem IsPartition.exists_splitMany_le {I : Box ι} {π : Prepartition I} (h : IsPartition π) : ∃ s, splitMany I s ≀ π := by refine (eventually_splitMany_inf_eq_filter π).exists.imp fun s hs => ?_ rwa [h.iUnion_eq, filter_of_true, inf_eq_right] at hs exact fun J hJ => le_of_mem _ hJ /-- For every prepartition `π` of `I` there exists a prepartition that covers exactly `I \ π.iUnion`. -/ theorem exists_iUnion_eq_diff (π : Prepartition I) : ∃ π' : Prepartition I, π'.iUnion = ↑I \ π.iUnion := by rcases π.eventually_splitMany_inf_eq_filter.exists with ⟹s, hs⟩ use (splitMany I s).filter fun J => ¬(J : Set (ι → ℝ)) ⊆ π.iUnion simp [← hs] /-- If `π` is a prepartition of `I`, then `π.compl` is a prepartition of `I` such that `π.compl.iUnion = I \ π.iUnion`. -/ def compl (π : Prepartition I) : Prepartition I := π.exists_iUnion_eq_diff.choose @[simp] theorem iUnion_compl (π : Prepartition I) : π.compl.iUnion = ↑I \ π.iUnion := π.exists_iUnion_eq_diff.choose_spec /-- Since the definition of `BoxIntegral.Prepartition.compl` uses `Exists.choose`, the result depends only on `π.iUnion`. -/ theorem compl_congr {π₁ π₂ : Prepartition I} (h : π₁.iUnion = π₂.iUnion) : π₁.compl = π₂.compl := by dsimp only [compl] congr 1 rw [h] theorem IsPartition.compl_eq_bot {π : Prepartition I} (h : IsPartition π) : π.compl = ⊥ := by rw [← iUnion_eq_empty, iUnion_compl, h.iUnion_eq, diff_self] @[simp] theorem compl_top : (⊀ : Prepartition I).compl = ⊥ := (isPartitionTop I).compl_eq_bot end Finite end Prepartition end BoxIntegral
Analysis\BoxIntegral\Partition\SubboxInduction.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Box.SubboxInduction import Mathlib.Analysis.BoxIntegral.Partition.Tagged /-! # Induction on subboxes In this file we prove (see `BoxIntegral.Box.exists_taggedPartition_isHenstock_isSubordinate_homothetic`) that for every box `I` in `ℝⁿ` and a function `r : ℝⁿ → ℝ` positive on `I` there exists a tagged partition `π` of `I` such that * `π` is a Henstock partition; * `π` is subordinate to `r`; * each box in `π` is homothetic to `I` with coefficient of the form `1 / 2 ^ n`. Later we will use this lemma to prove that the Henstock filter is nontrivial, hence the Henstock integral is well-defined. ## Tags partition, tagged partition, Henstock integral -/ namespace BoxIntegral open Set Metric open scoped Classical open Topology noncomputable section variable {ι : Type*} [Fintype ι] {I J : Box ι} namespace Prepartition /-- Split a box in `ℝⁿ` into `2 ^ n` boxes by hyperplanes passing through its center. -/ def splitCenter (I : Box ι) : Prepartition I where boxes := Finset.univ.map (Box.splitCenterBoxEmb I) le_of_mem' := by simp [I.splitCenterBox_le] pairwiseDisjoint := by rw [Finset.coe_map, Finset.coe_univ, image_univ] rintro _ ⟹s, rfl⟩ _ ⟹t, rfl⟩ Hne exact I.disjoint_splitCenterBox (mt (congr_arg _) Hne) @[simp] theorem mem_splitCenter : J ∈ splitCenter I ↔ ∃ s, I.splitCenterBox s = J := by simp [splitCenter] theorem isPartition_splitCenter (I : Box ι) : IsPartition (splitCenter I) := fun x hx => by simp [hx] theorem upper_sub_lower_of_mem_splitCenter (h : J ∈ splitCenter I) (i : ι) : J.upper i - J.lower i = (I.upper i - I.lower i) / 2 := let ⟹s, hs⟩ := mem_splitCenter.1 h hs ▾ I.upper_sub_lower_splitCenterBox s i end Prepartition namespace Box open Prepartition TaggedPrepartition /-- Let `p` be a predicate on `Box ι`, let `I` be a box. Suppose that the following two properties hold true. * Consider a smaller box `J ≀ I`. The hyperplanes passing through the center of `J` split it into `2 ^ n` boxes. If `p` holds true on each of these boxes, then it true on `J`. * For each `z` in the closed box `I.Icc` there exists a neighborhood `U` of `z` within `I.Icc` such that for every box `J ≀ I` such that `z ∈ J.Icc ⊆ U`, if `J` is homothetic to `I` with a coefficient of the form `1 / 2 ^ m`, then `p` is true on `J`. Then `p I` is true. See also `BoxIntegral.Box.subbox_induction_on'` for a version using `BoxIntegral.Box.splitCenterBox` instead of `BoxIntegral.Prepartition.splitCenter`. -/ @[elab_as_elim] theorem subbox_induction_on {p : Box ι → Prop} (I : Box ι) (H_ind : ∀ J ≀ I, (∀ J' ∈ splitCenter J, p J') → p J) (H_nhds : ∀ z ∈ Box.Icc I, ∃ U ∈ 𝓝[Box.Icc I] z, ∀ J ≀ I, ∀ (m : ℕ), z ∈ Box.Icc J → Box.Icc J ⊆ U → (∀ i, J.upper i - J.lower i = (I.upper i - I.lower i) / 2 ^ m) → p J) : p I := by refine subbox_induction_on' I (fun J hle hs => H_ind J hle fun J' h' => ?_) H_nhds rcases mem_splitCenter.1 h' with ⟹s, rfl⟩ exact hs s /-- Given a box `I` in `ℝⁿ` and a function `r : ℝⁿ → (0, ∞)`, there exists a tagged partition `π` of `I` such that * `π` is a Henstock partition; * `π` is subordinate to `r`; * each box in `π` is homothetic to `I` with coefficient of the form `1 / 2 ^ m`. This lemma implies that the Henstock filter is nontrivial, hence the Henstock integral is well-defined. -/ theorem exists_taggedPartition_isHenstock_isSubordinate_homothetic (I : Box ι) (r : (ι → ℝ) → Ioi (0 : ℝ)) : ∃ π : TaggedPrepartition I, π.IsPartition ∧ π.IsHenstock ∧ π.IsSubordinate r ∧ (∀ J ∈ π, ∃ m : ℕ, ∀ i, (J : _).upper i - J.lower i = (I.upper i - I.lower i) / 2 ^ m) ∧ π.distortion = I.distortion := by refine subbox_induction_on I (fun J _ hJ => ?_) fun z _ => ?_ · choose! πi hP hHen hr Hn _ using hJ choose! n hn using Hn have hP : ((splitCenter J).biUnionTagged πi).IsPartition := (isPartition_splitCenter _).biUnionTagged hP have hsub : ∀ J' ∈ (splitCenter J).biUnionTagged πi, ∃ n : ℕ, ∀ i, (J' : _).upper i - J'.lower i = (J.upper i - J.lower i) / 2 ^ n := by intro J' hJ' rcases (splitCenter J).mem_biUnionTagged.1 hJ' with ⟹J₁, h₁, h₂⟩ refine ⟹n J₁ J' + 1, fun i => ?_⟩ simp only [hn J₁ h₁ J' h₂, upper_sub_lower_of_mem_splitCenter h₁, pow_succ', div_div] refine ⟹_, hP, isHenstock_biUnionTagged.2 hHen, isSubordinate_biUnionTagged.2 hr, hsub, ?_⟩ refine TaggedPrepartition.distortion_of_const _ hP.nonempty_boxes fun J' h' => ?_ rcases hsub J' h' with ⟹n, hn⟩ exact Box.distortion_eq_of_sub_eq_div hn · refine ⟹Box.Icc I ∩ closedBall z (r z), inter_mem_nhdsWithin _ (closedBall_mem_nhds _ (r z).coe_prop), ?_⟩ intro J _ n Hmem HIcc Hsub rw [Set.subset_inter_iff] at HIcc refine ⟹single _ _ le_rfl _ Hmem, isPartition_single _, isHenstock_single _, (isSubordinate_single _ _).2 HIcc.2, ?_, distortion_single _ _⟩ simp only [TaggedPrepartition.mem_single, forall_eq] refine ⟹0, fun i => ?_⟩ simp end Box namespace Prepartition open TaggedPrepartition Finset Function /-- Given a box `I` in `ℝⁿ`, a function `r : ℝⁿ → (0, ∞)`, and a prepartition `π` of `I`, there exists a tagged prepartition `π'` of `I` such that * each box of `π'` is included in some box of `π`; * `π'` is a Henstock partition; * `π'` is subordinate to `r`; * `π'` covers exactly the same part of `I` as `π`; * the distortion of `π'` is equal to the distortion of `π`. -/ theorem exists_tagged_le_isHenstock_isSubordinate_iUnion_eq {I : Box ι} (r : (ι → ℝ) → Ioi (0 : ℝ)) (π : Prepartition I) : ∃ π' : TaggedPrepartition I, π'.toPrepartition ≀ π ∧ π'.IsHenstock ∧ π'.IsSubordinate r ∧ π'.distortion = π.distortion ∧ π'.iUnion = π.iUnion := by have := fun J => Box.exists_taggedPartition_isHenstock_isSubordinate_homothetic J r choose! πi πip πiH πir _ πid using this refine ⟚π.biUnionTagged πi, biUnion_le _ _, isHenstock_biUnionTagged.2 fun J _ => πiH J, isSubordinate_biUnionTagged.2 fun J _ => πir J, ?_, π.iUnion_biUnion_partition fun J _ => πip J⟩ rw [distortion_biUnionTagged] exact sup_congr rfl fun J _ => πid J /-- Given a prepartition `π` of a box `I` and a function `r : ℝⁿ → (0, ∞)`, `π.toSubordinate r` is a tagged partition `π'` such that * each box of `π'` is included in some box of `π`; * `π'` is a Henstock partition; * `π'` is subordinate to `r`; * `π'` covers exactly the same part of `I` as `π`; * the distortion of `π'` is equal to the distortion of `π`. -/ def toSubordinate (π : Prepartition I) (r : (ι → ℝ) → Ioi (0 : ℝ)) : TaggedPrepartition I := (π.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r).choose theorem toSubordinate_toPrepartition_le (π : Prepartition I) (r : (ι → ℝ) → Ioi (0 : ℝ)) : (π.toSubordinate r).toPrepartition ≀ π := (π.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r).choose_spec.1 theorem isHenstock_toSubordinate (π : Prepartition I) (r : (ι → ℝ) → Ioi (0 : ℝ)) : (π.toSubordinate r).IsHenstock := (π.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r).choose_spec.2.1 theorem isSubordinate_toSubordinate (π : Prepartition I) (r : (ι → ℝ) → Ioi (0 : ℝ)) : (π.toSubordinate r).IsSubordinate r := (π.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r).choose_spec.2.2.1 @[simp] theorem distortion_toSubordinate (π : Prepartition I) (r : (ι → ℝ) → Ioi (0 : ℝ)) : (π.toSubordinate r).distortion = π.distortion := (π.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r).choose_spec.2.2.2.1 @[simp] theorem iUnion_toSubordinate (π : Prepartition I) (r : (ι → ℝ) → Ioi (0 : ℝ)) : (π.toSubordinate r).iUnion = π.iUnion := (π.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r).choose_spec.2.2.2.2 end Prepartition namespace TaggedPrepartition /-- Given a tagged prepartition `π₁`, a prepartition `π₂` that covers exactly `I \ π₁.iUnion`, and a function `r : ℝⁿ → (0, ∞)`, returns the union of `π₁` and `π₂.toSubordinate r`. This partition `π` has the following properties: * `π` is a partition, i.e. it covers the whole `I`; * `π₁.boxes ⊆ π.boxes`; * `π.tag J = π₁.tag J` whenever `J ∈ π₁`; * `π` is Henstock outside of `π₁`: `π.tag J ∈ J.Icc` whenever `J ∈ π`, `J ∉ π₁`; * `π` is subordinate to `r` outside of `π₁`; * the distortion of `π` is equal to the maximum of the distortions of `π₁` and `π₂`. -/ def unionComplToSubordinate (π₁ : TaggedPrepartition I) (π₂ : Prepartition I) (hU : π₂.iUnion = ↑I \ π₁.iUnion) (r : (ι → ℝ) → Ioi (0 : ℝ)) : TaggedPrepartition I := π₁.disjUnion (π₂.toSubordinate r) (((π₂.iUnion_toSubordinate r).trans hU).symm ▾ disjoint_sdiff_self_right) theorem isPartition_unionComplToSubordinate (π₁ : TaggedPrepartition I) (π₂ : Prepartition I) (hU : π₂.iUnion = ↑I \ π₁.iUnion) (r : (ι → ℝ) → Ioi (0 : ℝ)) : IsPartition (π₁.unionComplToSubordinate π₂ hU r) := Prepartition.isPartitionDisjUnionOfEqDiff ((π₂.iUnion_toSubordinate r).trans hU) @[simp] theorem unionComplToSubordinate_boxes (π₁ : TaggedPrepartition I) (π₂ : Prepartition I) (hU : π₂.iUnion = ↑I \ π₁.iUnion) (r : (ι → ℝ) → Ioi (0 : ℝ)) : (π₁.unionComplToSubordinate π₂ hU r).boxes = π₁.boxes ∪ (π₂.toSubordinate r).boxes := rfl @[simp] theorem iUnion_unionComplToSubordinate_boxes (π₁ : TaggedPrepartition I) (π₂ : Prepartition I) (hU : π₂.iUnion = ↑I \ π₁.iUnion) (r : (ι → ℝ) → Ioi (0 : ℝ)) : (π₁.unionComplToSubordinate π₂ hU r).iUnion = I := (isPartition_unionComplToSubordinate _ _ _ _).iUnion_eq @[simp] theorem distortion_unionComplToSubordinate (π₁ : TaggedPrepartition I) (π₂ : Prepartition I) (hU : π₂.iUnion = ↑I \ π₁.iUnion) (r : (ι → ℝ) → Ioi (0 : ℝ)) : (π₁.unionComplToSubordinate π₂ hU r).distortion = max π₁.distortion π₂.distortion := by simp [unionComplToSubordinate] end TaggedPrepartition end end BoxIntegral
Analysis\BoxIntegral\Partition\Tagged.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Partition.Basic /-! # Tagged partitions A tagged (pre)partition is a (pre)partition `π` enriched with a tagged point for each box of `π`. For simplicity we require that the function `BoxIntegral.TaggedPrepartition.tag` is defined on all boxes `J : Box ι` but use its values only on boxes of the partition. Given `π : BoxIntegral.TaggedPrepartition I`, we require that each `BoxIntegral.TaggedPrepartition π J` belongs to `BoxIntegral.Box.Icc I`. If for every `J ∈ π`, `π.tag J` belongs to `J.Icc`, then `π` is called a *Henstock* partition. We do not include this assumption into the definition of a tagged (pre)partition because McShane integral is defined as a limit along tagged partitions without this requirement. ## Tags rectangular box, box partition -/ noncomputable section open scoped Classical open ENNReal NNReal open Set Function namespace BoxIntegral variable {ι : Type*} /-- A tagged prepartition is a prepartition enriched with a tagged point for each box of the prepartition. For simplicity we require that `tag` is defined for all boxes in `ι → ℝ` but we will use only the values of `tag` on the boxes of the partition. -/ structure TaggedPrepartition (I : Box ι) extends Prepartition I where /-- Choice of tagged point of each box in this prepartition: we extend this to a total function, on all boxes in `ι → ℝ`. -/ tag : Box ι → ι → ℝ /-- Each tagged point belongs to `I` -/ tag_mem_Icc : ∀ J, tag J ∈ Box.Icc I namespace TaggedPrepartition variable {I J J₁ J₂ : Box ι} (π : TaggedPrepartition I) {x : ι → ℝ} instance : Membership (Box ι) (TaggedPrepartition I) := ⟹fun J π => J ∈ π.boxes⟩ @[simp] theorem mem_toPrepartition {π : TaggedPrepartition I} : J ∈ π.toPrepartition ↔ J ∈ π := Iff.rfl @[simp] theorem mem_mk (π : Prepartition I) (f h) : J ∈ mk π f h ↔ J ∈ π := Iff.rfl /-- Union of all boxes of a tagged prepartition. -/ def iUnion : Set (ι → ℝ) := π.toPrepartition.iUnion theorem iUnion_def : π.iUnion = ⋃ J ∈ π, ↑J := rfl @[simp] theorem iUnion_mk (π : Prepartition I) (f h) : (mk π f h).iUnion = π.iUnion := rfl @[simp] theorem iUnion_toPrepartition : π.toPrepartition.iUnion = π.iUnion := rfl -- Porting note: Previous proof was `:= Set.mem_iUnion₂` @[simp] theorem mem_iUnion : x ∈ π.iUnion ↔ ∃ J ∈ π, x ∈ J := by convert Set.mem_iUnion₂ rw [Box.mem_coe, mem_toPrepartition, exists_prop] theorem subset_iUnion (h : J ∈ π) : ↑J ⊆ π.iUnion := subset_biUnion_of_mem h theorem iUnion_subset : π.iUnion ⊆ I := iUnion₂_subset π.le_of_mem' /-- A tagged prepartition is a partition if it covers the whole box. -/ def IsPartition := π.toPrepartition.IsPartition theorem isPartition_iff_iUnion_eq : IsPartition π ↔ π.iUnion = I := Prepartition.isPartition_iff_iUnion_eq /-- The tagged partition made of boxes of `π` that satisfy predicate `p`. -/ @[simps! (config := .asFn)] def filter (p : Box ι → Prop) : TaggedPrepartition I := ⟚π.1.filter p, π.2, π.3⟩ @[simp] theorem mem_filter {p : Box ι → Prop} : J ∈ π.filter p ↔ J ∈ π ∧ p J := Finset.mem_filter @[simp] theorem iUnion_filter_not (π : TaggedPrepartition I) (p : Box ι → Prop) : (π.filter fun J => ¬p J).iUnion = π.iUnion \ (π.filter p).iUnion := π.toPrepartition.iUnion_filter_not p end TaggedPrepartition namespace Prepartition variable {I J : Box ι} /-- Given a partition `π` of `I : BoxIntegral.Box ι` and a collection of tagged partitions `πi J` of all boxes `J ∈ π`, returns the tagged partition of `I` into all the boxes of `πi J` with tags coming from `(πi J).tag`. -/ def biUnionTagged (π : Prepartition I) (πi : ∀ J : Box ι, TaggedPrepartition J) : TaggedPrepartition I where toPrepartition := π.biUnion fun J => (πi J).toPrepartition tag J := (πi (π.biUnionIndex (fun J => (πi J).toPrepartition) J)).tag J tag_mem_Icc _ := Box.le_iff_Icc.1 (π.biUnionIndex_le _ _) ((πi _).tag_mem_Icc _) @[simp] theorem mem_biUnionTagged (π : Prepartition I) {πi : ∀ J, TaggedPrepartition J} : J ∈ π.biUnionTagged πi ↔ ∃ J' ∈ π, J ∈ πi J' := π.mem_biUnion theorem tag_biUnionTagged (π : Prepartition I) {πi : ∀ J, TaggedPrepartition J} (hJ : J ∈ π) {J'} (hJ' : J' ∈ πi J) : (π.biUnionTagged πi).tag J' = (πi J).tag J' := by rw [← π.biUnionIndex_of_mem (πi := fun J => (πi J).toPrepartition) hJ hJ'] rfl @[simp] theorem iUnion_biUnionTagged (π : Prepartition I) (πi : ∀ J, TaggedPrepartition J) : (π.biUnionTagged πi).iUnion = ⋃ J ∈ π, (πi J).iUnion := iUnion_biUnion _ _ theorem forall_biUnionTagged (p : (ι → ℝ) → Box ι → Prop) (π : Prepartition I) (πi : ∀ J, TaggedPrepartition J) : (∀ J ∈ π.biUnionTagged πi, p ((π.biUnionTagged πi).tag J) J) ↔ ∀ J ∈ π, ∀ J' ∈ πi J, p ((πi J).tag J') J' := by simp only [mem_biUnionTagged] refine ⟹fun H J hJ J' hJ' => ?_, fun H J' ⟹J, hJ, hJ'⟩ => ?_⟩ · rw [← π.tag_biUnionTagged hJ hJ'] exact H J' ⟹J, hJ, hJ'⟩ · rw [π.tag_biUnionTagged hJ hJ'] exact H J hJ J' hJ' theorem IsPartition.biUnionTagged {π : Prepartition I} (h : IsPartition π) {πi : ∀ J, TaggedPrepartition J} (hi : ∀ J ∈ π, (πi J).IsPartition) : (π.biUnionTagged πi).IsPartition := h.biUnion hi end Prepartition namespace TaggedPrepartition variable {I J : Box ι} {π π₁ π₂ : TaggedPrepartition I} {x : ι → ℝ} /-- Given a tagged partition `π` of `I` and a (not tagged) partition `πi J hJ` of each `J ∈ π`, returns the tagged partition of `I` into all the boxes of all `πi J hJ`. The tag of a box `J` is defined to be the `π.tag` of the box of the partition `π` that includes `J`. Note that usually the result is not a Henstock partition. -/ @[simps (config := .asFn) tag] def biUnionPrepartition (π : TaggedPrepartition I) (πi : ∀ J : Box ι, Prepartition J) : TaggedPrepartition I where toPrepartition := π.toPrepartition.biUnion πi tag J := π.tag (π.toPrepartition.biUnionIndex πi J) tag_mem_Icc _ := π.tag_mem_Icc _ theorem IsPartition.biUnionPrepartition {π : TaggedPrepartition I} (h : IsPartition π) {πi : ∀ J, Prepartition J} (hi : ∀ J ∈ π, (πi J).IsPartition) : (π.biUnionPrepartition πi).IsPartition := h.biUnion hi /-- Given two partitions `π₁` and `π₁`, one of them tagged and the other is not, returns the tagged partition with `toPrepartition = π₁.toPrepartition ⊓ π₂` and tags coming from `π₁`. Note that usually the result is not a Henstock partition. -/ def infPrepartition (π : TaggedPrepartition I) (π' : Prepartition I) : TaggedPrepartition I := π.biUnionPrepartition fun J => π'.restrict J @[simp] theorem infPrepartition_toPrepartition (π : TaggedPrepartition I) (π' : Prepartition I) : (π.infPrepartition π').toPrepartition = π.toPrepartition ⊓ π' := rfl theorem mem_infPrepartition_comm : J ∈ π₁.infPrepartition π₂.toPrepartition ↔ J ∈ π₂.infPrepartition π₁.toPrepartition := by simp only [← mem_toPrepartition, infPrepartition_toPrepartition, inf_comm] theorem IsPartition.infPrepartition (h₁ : π₁.IsPartition) {π₂ : Prepartition I} (h₂ : π₂.IsPartition) : (π₁.infPrepartition π₂).IsPartition := h₁.inf h₂ open Metric /-- A tagged partition is said to be a Henstock partition if for each `J ∈ π`, the tag of `J` belongs to `J.Icc`. -/ def IsHenstock (π : TaggedPrepartition I) : Prop := ∀ J ∈ π, π.tag J ∈ Box.Icc J @[simp] theorem isHenstock_biUnionTagged {π : Prepartition I} {πi : ∀ J, TaggedPrepartition J} : IsHenstock (π.biUnionTagged πi) ↔ ∀ J ∈ π, (πi J).IsHenstock := π.forall_biUnionTagged (fun x J => x ∈ Box.Icc J) πi /-- In a Henstock prepartition, there are at most `2 ^ Fintype.card ι` boxes with a given tag. -/ theorem IsHenstock.card_filter_tag_eq_le [Fintype ι] (h : π.IsHenstock) (x : ι → ℝ) : (π.boxes.filter fun J => π.tag J = x).card ≀ 2 ^ Fintype.card ι := calc (π.boxes.filter fun J => π.tag J = x).card ≀ (π.boxes.filter fun J : Box ι => x ∈ Box.Icc J).card := by refine Finset.card_le_card fun J hJ => ?_ rw [Finset.mem_filter] at hJ ⊢; rcases hJ with ⟹hJ, rfl⟩ exact ⟹hJ, h J hJ⟩ _ ≀ 2 ^ Fintype.card ι := π.toPrepartition.card_filter_mem_Icc_le x /-- A tagged partition `π` is subordinate to `r : (ι → ℝ) → ℝ` if each box `J ∈ π` is included in the closed ball with center `π.tag J` and radius `r (π.tag J)`. -/ def IsSubordinate [Fintype ι] (π : TaggedPrepartition I) (r : (ι → ℝ) → Ioi (0 : ℝ)) : Prop := ∀ J ∈ π, Box.Icc J ⊆ closedBall (π.tag J) (r <| π.tag J) variable {r r₁ r₂ : (ι → ℝ) → Ioi (0 : ℝ)} @[simp] theorem isSubordinate_biUnionTagged [Fintype ι] {π : Prepartition I} {πi : ∀ J, TaggedPrepartition J} : IsSubordinate (π.biUnionTagged πi) r ↔ ∀ J ∈ π, (πi J).IsSubordinate r := π.forall_biUnionTagged (fun x J => Box.Icc J ⊆ closedBall x (r x)) πi theorem IsSubordinate.biUnionPrepartition [Fintype ι] (h : IsSubordinate π r) (πi : ∀ J, Prepartition J) : IsSubordinate (π.biUnionPrepartition πi) r := fun _ hJ => Subset.trans (Box.le_iff_Icc.1 <| π.toPrepartition.le_biUnionIndex hJ) <| h _ <| π.toPrepartition.biUnionIndex_mem hJ theorem IsSubordinate.infPrepartition [Fintype ι] (h : IsSubordinate π r) (π' : Prepartition I) : IsSubordinate (π.infPrepartition π') r := h.biUnionPrepartition _ theorem IsSubordinate.mono' [Fintype ι] {π : TaggedPrepartition I} (hr₁ : π.IsSubordinate r₁) (h : ∀ J ∈ π, r₁ (π.tag J) ≀ r₂ (π.tag J)) : π.IsSubordinate r₂ := fun _ hJ _ hx => closedBall_subset_closedBall (h _ hJ) (hr₁ _ hJ hx) theorem IsSubordinate.mono [Fintype ι] {π : TaggedPrepartition I} (hr₁ : π.IsSubordinate r₁) (h : ∀ x ∈ Box.Icc I, r₁ x ≀ r₂ x) : π.IsSubordinate r₂ := hr₁.mono' fun J _ => h _ <| π.tag_mem_Icc J theorem IsSubordinate.diam_le [Fintype ι] {π : TaggedPrepartition I} (h : π.IsSubordinate r) (hJ : J ∈ π.boxes) : diam (Box.Icc J) ≀ 2 * r (π.tag J) := calc diam (Box.Icc J) ≀ diam (closedBall (π.tag J) (r <| π.tag J)) := diam_mono (h J hJ) isBounded_closedBall _ ≀ 2 * r (π.tag J) := diam_closedBall (le_of_lt (r _).2) /-- Tagged prepartition with single box and prescribed tag. -/ @[simps! (config := .asFn)] def single (I J : Box ι) (hJ : J ≀ I) (x : ι → ℝ) (h : x ∈ Box.Icc I) : TaggedPrepartition I := ⟹Prepartition.single I J hJ, fun _ => x, fun _ => h⟩ @[simp] theorem mem_single {J'} (hJ : J ≀ I) (h : x ∈ Box.Icc I) : J' ∈ single I J hJ x h ↔ J' = J := Finset.mem_singleton instance (I : Box ι) : Inhabited (TaggedPrepartition I) := ⟹single I I le_rfl I.upper I.upper_mem_Icc⟩ theorem isPartition_single_iff (hJ : J ≀ I) (h : x ∈ Box.Icc I) : (single I J hJ x h).IsPartition ↔ J = I := Prepartition.isPartition_single_iff hJ theorem isPartition_single (h : x ∈ Box.Icc I) : (single I I le_rfl x h).IsPartition := Prepartition.isPartitionTop I theorem forall_mem_single (p : (ι → ℝ) → Box ι → Prop) (hJ : J ≀ I) (h : x ∈ Box.Icc I) : (∀ J' ∈ single I J hJ x h, p ((single I J hJ x h).tag J') J') ↔ p x J := by simp @[simp] theorem isHenstock_single_iff (hJ : J ≀ I) (h : x ∈ Box.Icc I) : IsHenstock (single I J hJ x h) ↔ x ∈ Box.Icc J := forall_mem_single (fun x J => x ∈ Box.Icc J) hJ h --@[simp] -- Porting note: Commented out, because `simp only [isHenstock_single_iff]` simplifies it theorem isHenstock_single (h : x ∈ Box.Icc I) : IsHenstock (single I I le_rfl x h) := (isHenstock_single_iff (le_refl I) h).2 h @[simp] theorem isSubordinate_single [Fintype ι] (hJ : J ≀ I) (h : x ∈ Box.Icc I) : IsSubordinate (single I J hJ x h) r ↔ Box.Icc J ⊆ closedBall x (r x) := forall_mem_single (fun x J => Box.Icc J ⊆ closedBall x (r x)) hJ h @[simp] theorem iUnion_single (hJ : J ≀ I) (h : x ∈ Box.Icc I) : (single I J hJ x h).iUnion = J := Prepartition.iUnion_single hJ /-- Union of two tagged prepartitions with disjoint unions of boxes. -/ def disjUnion (π₁ π₂ : TaggedPrepartition I) (h : Disjoint π₁.iUnion π₂.iUnion) : TaggedPrepartition I where toPrepartition := π₁.toPrepartition.disjUnion π₂.toPrepartition h tag := π₁.boxes.piecewise π₁.tag π₂.tag tag_mem_Icc J := by dsimp only [Finset.piecewise] split_ifs exacts [π₁.tag_mem_Icc J, π₂.tag_mem_Icc J] @[simp] theorem disjUnion_boxes (h : Disjoint π₁.iUnion π₂.iUnion) : (π₁.disjUnion π₂ h).boxes = π₁.boxes ∪ π₂.boxes := rfl @[simp] theorem mem_disjUnion (h : Disjoint π₁.iUnion π₂.iUnion) : J ∈ π₁.disjUnion π₂ h ↔ J ∈ π₁ √ J ∈ π₂ := Finset.mem_union @[simp] theorem iUnion_disjUnion (h : Disjoint π₁.iUnion π₂.iUnion) : (π₁.disjUnion π₂ h).iUnion = π₁.iUnion ∪ π₂.iUnion := Prepartition.iUnion_disjUnion h theorem disjUnion_tag_of_mem_left (h : Disjoint π₁.iUnion π₂.iUnion) (hJ : J ∈ π₁) : (π₁.disjUnion π₂ h).tag J = π₁.tag J := dif_pos hJ theorem disjUnion_tag_of_mem_right (h : Disjoint π₁.iUnion π₂.iUnion) (hJ : J ∈ π₂) : (π₁.disjUnion π₂ h).tag J = π₂.tag J := dif_neg fun h₁ => h.le_bot ⟚π₁.subset_iUnion h₁ J.upper_mem, π₂.subset_iUnion hJ J.upper_mem⟩ theorem IsSubordinate.disjUnion [Fintype ι] (h₁ : IsSubordinate π₁ r) (h₂ : IsSubordinate π₂ r) (h : Disjoint π₁.iUnion π₂.iUnion) : IsSubordinate (π₁.disjUnion π₂ h) r := by refine fun J hJ => (Finset.mem_union.1 hJ).elim (fun hJ => ?_) fun hJ => ?_ · rw [disjUnion_tag_of_mem_left _ hJ] exact h₁ _ hJ · rw [disjUnion_tag_of_mem_right _ hJ] exact h₂ _ hJ theorem IsHenstock.disjUnion (h₁ : IsHenstock π₁) (h₂ : IsHenstock π₂) (h : Disjoint π₁.iUnion π₂.iUnion) : IsHenstock (π₁.disjUnion π₂ h) := by refine fun J hJ => (Finset.mem_union.1 hJ).elim (fun hJ => ?_) fun hJ => ?_ · rw [disjUnion_tag_of_mem_left _ hJ] exact h₁ _ hJ · rw [disjUnion_tag_of_mem_right _ hJ] exact h₂ _ hJ /-- If `I ≀ J`, then every tagged prepartition of `I` is a tagged prepartition of `J`. -/ def embedBox (I J : Box ι) (h : I ≀ J) : TaggedPrepartition I ↪ TaggedPrepartition J where toFun π := { π with le_of_mem' := fun J' hJ' => (π.le_of_mem' J' hJ').trans h tag_mem_Icc := fun J => Box.le_iff_Icc.1 h (π.tag_mem_Icc J) } inj' := by rintro ⟹⟹b₁, h₁le, h₁d⟩, t₁, ht₁⟩ ⟹⟹b₂, h₂le, h₂d⟩, t₂, ht₂⟩ H simpa using H section Distortion variable [Fintype ι] (π) open Finset /-- The distortion of a tagged prepartition is the maximum of distortions of its boxes. -/ def distortion : ℝ≥0 := π.toPrepartition.distortion theorem distortion_le_of_mem (h : J ∈ π) : J.distortion ≀ π.distortion := le_sup h theorem distortion_le_iff {c : ℝ≥0} : π.distortion ≀ c ↔ ∀ J ∈ π, Box.distortion J ≀ c := Finset.sup_le_iff @[simp] theorem _root_.BoxIntegral.Prepartition.distortion_biUnionTagged (π : Prepartition I) (πi : ∀ J, TaggedPrepartition J) : (π.biUnionTagged πi).distortion = π.boxes.sup fun J => (πi J).distortion := sup_biUnion _ _ @[simp] theorem distortion_biUnionPrepartition (π : TaggedPrepartition I) (πi : ∀ J, Prepartition J) : (π.biUnionPrepartition πi).distortion = π.boxes.sup fun J => (πi J).distortion := sup_biUnion _ _ @[simp] theorem distortion_disjUnion (h : Disjoint π₁.iUnion π₂.iUnion) : (π₁.disjUnion π₂ h).distortion = max π₁.distortion π₂.distortion := sup_union theorem distortion_of_const {c} (h₁ : π.boxes.Nonempty) (h₂ : ∀ J ∈ π, Box.distortion J = c) : π.distortion = c := (sup_congr rfl h₂).trans (sup_const h₁ _) @[simp] theorem distortion_single (hJ : J ≀ I) (h : x ∈ Box.Icc I) : distortion (single I J hJ x h) = J.distortion := sup_singleton theorem distortion_filter_le (p : Box ι → Prop) : (π.filter p).distortion ≀ π.distortion := sup_mono (filter_subset _ _) end Distortion end TaggedPrepartition end BoxIntegral
Analysis\Calculus\Darboux.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.LocalExtr.Basic /-! # Darboux's theorem In this file we prove that the derivative of a differentiable function on an interval takes all intermediate values. The proof is based on the [Wikipedia](https://en.wikipedia.org/wiki/Darboux%27s_theorem_(analysis)) page about this theorem. -/ open Filter Set open scoped Topology Classical variable {a b : ℝ} {f f' : ℝ → ℝ} /-- **Darboux's theorem**: if `a ≀ b` and `f' a < m < f' b`, then `f' c = m` for some `c ∈ (a, b)`. -/ theorem exists_hasDerivWithinAt_eq_of_gt_of_lt (hab : a ≀ b) (hf : ∀ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) {m : ℝ} (hma : f' a < m) (hmb : m < f' b) : m ∈ f' '' Ioo a b := by rcases hab.eq_or_lt with (rfl | hab') · exact (lt_asymm hma hmb).elim set g : ℝ → ℝ := fun x => f x - m * x have hg : ∀ x ∈ Icc a b, HasDerivWithinAt g (f' x - m) (Icc a b) x := by intro x hx simpa using (hf x hx).sub ((hasDerivWithinAt_id x _).const_mul m) obtain ⟹c, cmem, hc⟩ : ∃ c ∈ Icc a b, IsMinOn g (Icc a b) c := isCompact_Icc.exists_isMinOn (nonempty_Icc.2 <| hab) fun x hx => (hg x hx).continuousWithinAt have cmem' : c ∈ Ioo a b := by rcases cmem.1.eq_or_lt with (rfl | hac) -- Show that `c` can't be equal to `a` · refine absurd (sub_nonneg.1 <| nonneg_of_mul_nonneg_right ?_ (sub_pos.2 hab')) (not_le_of_lt hma) have : b - a ∈ posTangentConeAt (Icc a b) a := sub_mem_posTangentConeAt_of_segment_subset (segment_eq_Icc hab ▾ Subset.rfl) simpa only [ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply] using hc.localize.hasFDerivWithinAt_nonneg (hg a (left_mem_Icc.2 hab)) this rcases cmem.2.eq_or_gt with (rfl | hcb) -- Show that `c` can't be equal to `b` · refine absurd (sub_nonpos.1 <| nonpos_of_mul_nonneg_right ?_ (sub_lt_zero.2 hab')) (not_le_of_lt hmb) have : a - b ∈ posTangentConeAt (Icc a b) b := sub_mem_posTangentConeAt_of_segment_subset (by rw [segment_symm, segment_eq_Icc hab]) simpa only [ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply] using hc.localize.hasFDerivWithinAt_nonneg (hg b (right_mem_Icc.2 hab)) this exact ⟹hac, hcb⟩ use c, cmem' rw [← sub_eq_zero] have : Icc a b ∈ 𝓝 c := by rwa [← mem_interior_iff_mem_nhds, interior_Icc] exact (hc.isLocalMin this).hasDerivAt_eq_zero ((hg c cmem).hasDerivAt this) /-- **Darboux's theorem**: if `a ≀ b` and `f' b < m < f' a`, then `f' c = m` for some `c ∈ (a, b)`. -/ theorem exists_hasDerivWithinAt_eq_of_lt_of_gt (hab : a ≀ b) (hf : ∀ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) {m : ℝ} (hma : m < f' a) (hmb : f' b < m) : m ∈ f' '' Ioo a b := let ⟹c, cmem, hc⟩ := exists_hasDerivWithinAt_eq_of_gt_of_lt hab (fun x hx => (hf x hx).neg) (neg_lt_neg hma) (neg_lt_neg hmb) ⟹c, cmem, neg_injective hc⟩ /-- **Darboux's theorem**: the image of a `Set.OrdConnected` set under `f'` is a `Set.OrdConnected` set, `HasDerivWithinAt` version. -/ theorem Set.OrdConnected.image_hasDerivWithinAt {s : Set ℝ} (hs : OrdConnected s) (hf : ∀ x ∈ s, HasDerivWithinAt f (f' x) s x) : OrdConnected (f' '' s) := by apply ordConnected_of_Ioo rintro _ ⟹a, ha, rfl⟩ _ ⟹b, hb, rfl⟩ - m ⟹hma, hmb⟩ rcases le_total a b with hab | hab · have : Icc a b ⊆ s := hs.out ha hb rcases exists_hasDerivWithinAt_eq_of_gt_of_lt hab (fun x hx => (hf x <| this hx).mono this) hma hmb with ⟹c, cmem, hc⟩ exact ⟹c, this <| Ioo_subset_Icc_self cmem, hc⟩ · have : Icc b a ⊆ s := hs.out hb ha rcases exists_hasDerivWithinAt_eq_of_lt_of_gt hab (fun x hx => (hf x <| this hx).mono this) hmb hma with ⟹c, cmem, hc⟩ exact ⟹c, this <| Ioo_subset_Icc_self cmem, hc⟩ /-- **Darboux's theorem**: the image of a `Set.OrdConnected` set under `f'` is a `Set.OrdConnected` set, `derivWithin` version. -/ theorem Set.OrdConnected.image_derivWithin {s : Set ℝ} (hs : OrdConnected s) (hf : DifferentiableOn ℝ f s) : OrdConnected (derivWithin f s '' s) := hs.image_hasDerivWithinAt fun x hx => (hf x hx).hasDerivWithinAt /-- **Darboux's theorem**: the image of a `Set.OrdConnected` set under `f'` is a `Set.OrdConnected` set, `deriv` version. -/ theorem Set.OrdConnected.image_deriv {s : Set ℝ} (hs : OrdConnected s) (hf : ∀ x ∈ s, DifferentiableAt ℝ f x) : OrdConnected (deriv f '' s) := hs.image_hasDerivWithinAt fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt /-- **Darboux's theorem**: the image of a convex set under `f'` is a convex set, `HasDerivWithinAt` version. -/ theorem Convex.image_hasDerivWithinAt {s : Set ℝ} (hs : Convex ℝ s) (hf : ∀ x ∈ s, HasDerivWithinAt f (f' x) s x) : Convex ℝ (f' '' s) := (hs.ordConnected.image_hasDerivWithinAt hf).convex /-- **Darboux's theorem**: the image of a convex set under `f'` is a convex set, `derivWithin` version. -/ theorem Convex.image_derivWithin {s : Set ℝ} (hs : Convex ℝ s) (hf : DifferentiableOn ℝ f s) : Convex ℝ (derivWithin f s '' s) := (hs.ordConnected.image_derivWithin hf).convex /-- **Darboux's theorem**: the image of a convex set under `f'` is a convex set, `deriv` version. -/ theorem Convex.image_deriv {s : Set ℝ} (hs : Convex ℝ s) (hf : ∀ x ∈ s, DifferentiableAt ℝ f x) : Convex ℝ (deriv f '' s) := (hs.ordConnected.image_deriv hf).convex /-- **Darboux's theorem**: if `a ≀ b` and `f' a ≀ m ≀ f' b`, then `f' c = m` for some `c ∈ [a, b]`. -/ theorem exists_hasDerivWithinAt_eq_of_ge_of_le (hab : a ≀ b) (hf : ∀ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) {m : ℝ} (hma : f' a ≀ m) (hmb : m ≀ f' b) : m ∈ f' '' Icc a b := (ordConnected_Icc.image_hasDerivWithinAt hf).out (mem_image_of_mem _ (left_mem_Icc.2 hab)) (mem_image_of_mem _ (right_mem_Icc.2 hab)) ⟹hma, hmb⟩ /-- **Darboux's theorem**: if `a ≀ b` and `f' b ≀ m ≀ f' a`, then `f' c = m` for some `c ∈ [a, b]`. -/ theorem exists_hasDerivWithinAt_eq_of_le_of_ge (hab : a ≀ b) (hf : ∀ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) {m : ℝ} (hma : f' a ≀ m) (hmb : m ≀ f' b) : m ∈ f' '' Icc a b := (ordConnected_Icc.image_hasDerivWithinAt hf).out (mem_image_of_mem _ (left_mem_Icc.2 hab)) (mem_image_of_mem _ (right_mem_Icc.2 hab)) ⟹hma, hmb⟩ /-- If the derivative of a function is never equal to `m`, then either it is always greater than `m`, or it is always less than `m`. -/ theorem hasDerivWithinAt_forall_lt_or_forall_gt_of_forall_ne {s : Set ℝ} (hs : Convex ℝ s) (hf : ∀ x ∈ s, HasDerivWithinAt f (f' x) s x) {m : ℝ} (hf' : ∀ x ∈ s, f' x ≠ m) : (∀ x ∈ s, f' x < m) √ ∀ x ∈ s, m < f' x := by contrapose! hf' rcases hf' with ⟹⟹b, hb, hmb⟩, ⟹a, ha, hma⟩⟩ exact (hs.ordConnected.image_hasDerivWithinAt hf).out (mem_image_of_mem f' ha) (mem_image_of_mem f' hb) ⟹hma, hmb⟩
Analysis\Calculus\DiffContOnCl.lean
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Inv import Mathlib.Analysis.NormedSpace.Real /-! # Functions differentiable on a domain and continuous on its closure Many theorems in complex analysis assume that a function is complex differentiable on a domain and is continuous on its closure. In this file we define a predicate `DiffContOnCl` that expresses this property and prove basic facts about this predicate. -/ open Set Filter Metric open scoped Topology variable (𝕜 : Type*) {E F G : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] {f g : E → F} {s t : Set E} {x : E} /-- A predicate saying that a function is differentiable on a set and is continuous on its closure. This is a common assumption in complex analysis. -/ structure DiffContOnCl (f : E → F) (s : Set E) : Prop where protected differentiableOn : DifferentiableOn 𝕜 f s protected continuousOn : ContinuousOn f (closure s) variable {𝕜} theorem DifferentiableOn.diffContOnCl (h : DifferentiableOn 𝕜 f (closure s)) : DiffContOnCl 𝕜 f s := ⟹h.mono subset_closure, h.continuousOn⟩ theorem Differentiable.diffContOnCl (h : Differentiable 𝕜 f) : DiffContOnCl 𝕜 f s := ⟹h.differentiableOn, h.continuous.continuousOn⟩ theorem IsClosed.diffContOnCl_iff (hs : IsClosed s) : DiffContOnCl 𝕜 f s ↔ DifferentiableOn 𝕜 f s := ⟹fun h => h.differentiableOn, fun h => ⟹h, hs.closure_eq.symm ▾ h.continuousOn⟩⟩ theorem diffContOnCl_univ : DiffContOnCl 𝕜 f univ ↔ Differentiable 𝕜 f := isClosed_univ.diffContOnCl_iff.trans differentiableOn_univ theorem diffContOnCl_const {c : F} : DiffContOnCl 𝕜 (fun _ : E => c) s := ⟹differentiableOn_const c, continuousOn_const⟩ namespace DiffContOnCl theorem comp {g : G → E} {t : Set G} (hf : DiffContOnCl 𝕜 f s) (hg : DiffContOnCl 𝕜 g t) (h : MapsTo g t s) : DiffContOnCl 𝕜 (f ∘ g) t := ⟹hf.1.comp hg.1 h, hf.2.comp hg.2 <| h.closure_of_continuousOn hg.2⟩ theorem continuousOn_ball [NormedSpace ℝ E] {x : E} {r : ℝ} (h : DiffContOnCl 𝕜 f (ball x r)) : ContinuousOn f (closedBall x r) := by rcases eq_or_ne r 0 with (rfl | hr) · rw [closedBall_zero] exact continuousOn_singleton f x · rw [← closure_ball x hr] exact h.continuousOn theorem mk_ball {x : E} {r : ℝ} (hd : DifferentiableOn 𝕜 f (ball x r)) (hc : ContinuousOn f (closedBall x r)) : DiffContOnCl 𝕜 f (ball x r) := ⟹hd, hc.mono <| closure_ball_subset_closedBall⟩ protected theorem differentiableAt (h : DiffContOnCl 𝕜 f s) (hs : IsOpen s) (hx : x ∈ s) : DifferentiableAt 𝕜 f x := h.differentiableOn.differentiableAt <| hs.mem_nhds hx theorem differentiableAt' (h : DiffContOnCl 𝕜 f s) (hx : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := h.differentiableOn.differentiableAt hx protected theorem mono (h : DiffContOnCl 𝕜 f s) (ht : t ⊆ s) : DiffContOnCl 𝕜 f t := ⟹h.differentiableOn.mono ht, h.continuousOn.mono (closure_mono ht)⟩ theorem add (hf : DiffContOnCl 𝕜 f s) (hg : DiffContOnCl 𝕜 g s) : DiffContOnCl 𝕜 (f + g) s := ⟹hf.1.add hg.1, hf.2.add hg.2⟩ theorem add_const (hf : DiffContOnCl 𝕜 f s) (c : F) : DiffContOnCl 𝕜 (fun x => f x + c) s := hf.add diffContOnCl_const theorem const_add (hf : DiffContOnCl 𝕜 f s) (c : F) : DiffContOnCl 𝕜 (fun x => c + f x) s := diffContOnCl_const.add hf theorem neg (hf : DiffContOnCl 𝕜 f s) : DiffContOnCl 𝕜 (-f) s := ⟹hf.1.neg, hf.2.neg⟩ theorem sub (hf : DiffContOnCl 𝕜 f s) (hg : DiffContOnCl 𝕜 g s) : DiffContOnCl 𝕜 (f - g) s := ⟹hf.1.sub hg.1, hf.2.sub hg.2⟩ theorem sub_const (hf : DiffContOnCl 𝕜 f s) (c : F) : DiffContOnCl 𝕜 (fun x => f x - c) s := hf.sub diffContOnCl_const theorem const_sub (hf : DiffContOnCl 𝕜 f s) (c : F) : DiffContOnCl 𝕜 (fun x => c - f x) s := diffContOnCl_const.sub hf theorem const_smul {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] (hf : DiffContOnCl 𝕜 f s) (c : R) : DiffContOnCl 𝕜 (c • f) s := ⟹hf.1.const_smul c, hf.2.const_smul c⟩ theorem smul {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] {c : E → 𝕜'} {f : E → F} {s : Set E} (hc : DiffContOnCl 𝕜 c s) (hf : DiffContOnCl 𝕜 f s) : DiffContOnCl 𝕜 (fun x => c x • f x) s := ⟹hc.1.smul hf.1, hc.2.smul hf.2⟩ theorem smul_const {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] {c : E → 𝕜'} {s : Set E} (hc : DiffContOnCl 𝕜 c s) (y : F) : DiffContOnCl 𝕜 (fun x => c x • y) s := hc.smul diffContOnCl_const theorem inv {f : E → 𝕜} (hf : DiffContOnCl 𝕜 f s) (h₀ : ∀ x ∈ closure s, f x ≠ 0) : DiffContOnCl 𝕜 f⁻¹ s := ⟹differentiableOn_inv.comp hf.1 fun _ hx => h₀ _ (subset_closure hx), hf.2.inv₀ h₀⟩ end DiffContOnCl theorem Differentiable.comp_diffContOnCl {g : G → E} {t : Set G} (hf : Differentiable 𝕜 f) (hg : DiffContOnCl 𝕜 g t) : DiffContOnCl 𝕜 (f ∘ g) t := hf.diffContOnCl.comp hg (mapsTo_image _ _) theorem DifferentiableOn.diffContOnCl_ball {U : Set E} {c : E} {R : ℝ} (hf : DifferentiableOn 𝕜 f U) (hc : closedBall c R ⊆ U) : DiffContOnCl 𝕜 f (ball c R) := DiffContOnCl.mk_ball (hf.mono (ball_subset_closedBall.trans hc)) (hf.continuousOn.mono hc)
Analysis\Calculus\Dslope.lean
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Inv /-! # Slope of a differentiable function Given a function `f : 𝕜 → E` from a nontrivially normed field to a normed space over this field, `dslope f a b` is defined as `slope f a b = (b - a)⁻¹ • (f b - f a)` for `a ≠ b` and as `deriv f a` for `a = b`. In this file we define `dslope` and prove some basic lemmas about its continuity and differentiability. -/ open scoped Topology Filter open Function Set Filter variable {𝕜 E : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] open Classical in /-- `dslope f a b` is defined as `slope f a b = (b - a)⁻¹ • (f b - f a)` for `a ≠ b` and `deriv f a` for `a = b`. -/ noncomputable def dslope (f : 𝕜 → E) (a : 𝕜) : 𝕜 → E := update (slope f a) a (deriv f a) @[simp] theorem dslope_same (f : 𝕜 → E) (a : 𝕜) : dslope f a a = deriv f a := by classical exact update_same _ _ _ variable {f : 𝕜 → E} {a b : 𝕜} {s : Set 𝕜} theorem dslope_of_ne (f : 𝕜 → E) (h : b ≠ a) : dslope f a b = slope f a b := by classical exact update_noteq h _ _ theorem ContinuousLinearMap.dslope_comp {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] (f : E →L[𝕜] F) (g : 𝕜 → E) (a b : 𝕜) (H : a = b → DifferentiableAt 𝕜 g a) : dslope (f ∘ g) a b = f (dslope g a b) := by rcases eq_or_ne b a with (rfl | hne) · simp only [dslope_same] exact (f.hasFDerivAt.comp_hasDerivAt b (H rfl).hasDerivAt).deriv · simpa only [dslope_of_ne _ hne] using f.toLinearMap.slope_comp g a b theorem eqOn_dslope_slope (f : 𝕜 → E) (a : 𝕜) : EqOn (dslope f a) (slope f a) {a}ᶜ := fun _ => dslope_of_ne f theorem dslope_eventuallyEq_slope_of_ne (f : 𝕜 → E) (h : b ≠ a) : dslope f a =á¶ [𝓝 b] slope f a := (eqOn_dslope_slope f a).eventuallyEq_of_mem (isOpen_ne.mem_nhds h) theorem dslope_eventuallyEq_slope_punctured_nhds (f : 𝕜 → E) : dslope f a =á¶ [𝓝[≠] a] slope f a := (eqOn_dslope_slope f a).eventuallyEq_of_mem self_mem_nhdsWithin @[simp] theorem sub_smul_dslope (f : 𝕜 → E) (a b : 𝕜) : (b - a) • dslope f a b = f b - f a := by rcases eq_or_ne b a with (rfl | hne) <;> simp [dslope_of_ne, *] theorem dslope_sub_smul_of_ne (f : 𝕜 → E) (h : b ≠ a) : dslope (fun x => (x - a) • f x) a b = f b := by rw [dslope_of_ne _ h, slope_sub_smul _ h.symm] theorem eqOn_dslope_sub_smul (f : 𝕜 → E) (a : 𝕜) : EqOn (dslope (fun x => (x - a) • f x) a) f {a}ᶜ := fun _ => dslope_sub_smul_of_ne f theorem dslope_sub_smul [DecidableEq 𝕜] (f : 𝕜 → E) (a : 𝕜) : dslope (fun x => (x - a) • f x) a = update f a (deriv (fun x => (x - a) • f x) a) := eq_update_iff.2 ⟹dslope_same _ _, eqOn_dslope_sub_smul f a⟩ @[simp] theorem continuousAt_dslope_same : ContinuousAt (dslope f a) a ↔ DifferentiableAt 𝕜 f a := by simp only [dslope, continuousAt_update_same, ← hasDerivAt_deriv_iff, hasDerivAt_iff_tendsto_slope] theorem ContinuousWithinAt.of_dslope (h : ContinuousWithinAt (dslope f a) s b) : ContinuousWithinAt f s b := by have : ContinuousWithinAt (fun x => (x - a) • dslope f a x + f a) s b := ((continuousWithinAt_id.sub continuousWithinAt_const).smul h).add continuousWithinAt_const simpa only [sub_smul_dslope, sub_add_cancel] using this theorem ContinuousAt.of_dslope (h : ContinuousAt (dslope f a) b) : ContinuousAt f b := (continuousWithinAt_univ _ _).1 h.continuousWithinAt.of_dslope theorem ContinuousOn.of_dslope (h : ContinuousOn (dslope f a) s) : ContinuousOn f s := fun x hx => (h x hx).of_dslope theorem continuousWithinAt_dslope_of_ne (h : b ≠ a) : ContinuousWithinAt (dslope f a) s b ↔ ContinuousWithinAt f s b := by refine ⟹ContinuousWithinAt.of_dslope, fun hc => ?_⟩ classical simp only [dslope, continuousWithinAt_update_of_ne h] exact ((continuousWithinAt_id.sub continuousWithinAt_const).inv₀ (sub_ne_zero.2 h)).smul (hc.sub continuousWithinAt_const) theorem continuousAt_dslope_of_ne (h : b ≠ a) : ContinuousAt (dslope f a) b ↔ ContinuousAt f b := by simp only [← continuousWithinAt_univ, continuousWithinAt_dslope_of_ne h] theorem continuousOn_dslope (h : s ∈ 𝓝 a) : ContinuousOn (dslope f a) s ↔ ContinuousOn f s ∧ DifferentiableAt 𝕜 f a := by refine ⟹fun hc => ⟹hc.of_dslope, continuousAt_dslope_same.1 <| hc.continuousAt h⟩, ?_⟩ rintro ⟹hc, hd⟩ x hx rcases eq_or_ne x a with (rfl | hne) exacts [(continuousAt_dslope_same.2 hd).continuousWithinAt, (continuousWithinAt_dslope_of_ne hne).2 (hc x hx)] theorem DifferentiableWithinAt.of_dslope (h : DifferentiableWithinAt 𝕜 (dslope f a) s b) : DifferentiableWithinAt 𝕜 f s b := by simpa only [id, sub_smul_dslope f a, sub_add_cancel] using ((differentiableWithinAt_id.sub_const a).smul h).add_const (f a) theorem DifferentiableAt.of_dslope (h : DifferentiableAt 𝕜 (dslope f a) b) : DifferentiableAt 𝕜 f b := differentiableWithinAt_univ.1 h.differentiableWithinAt.of_dslope theorem DifferentiableOn.of_dslope (h : DifferentiableOn 𝕜 (dslope f a) s) : DifferentiableOn 𝕜 f s := fun x hx => (h x hx).of_dslope theorem differentiableWithinAt_dslope_of_ne (h : b ≠ a) : DifferentiableWithinAt 𝕜 (dslope f a) s b ↔ DifferentiableWithinAt 𝕜 f s b := by refine ⟹DifferentiableWithinAt.of_dslope, fun hd => ?_⟩ refine (((differentiableWithinAt_id.sub_const a).inv (sub_ne_zero.2 h)).smul (hd.sub_const (f a))).congr_of_eventuallyEq ?_ (dslope_of_ne _ h) refine (eqOn_dslope_slope _ _).eventuallyEq_of_mem ?_ exact mem_nhdsWithin_of_mem_nhds (isOpen_ne.mem_nhds h) theorem differentiableOn_dslope_of_nmem (h : a ∉ s) : DifferentiableOn 𝕜 (dslope f a) s ↔ DifferentiableOn 𝕜 f s := forall_congr' fun _ => forall_congr' fun hx => differentiableWithinAt_dslope_of_ne <| ne_of_mem_of_not_mem hx h theorem differentiableAt_dslope_of_ne (h : b ≠ a) : DifferentiableAt 𝕜 (dslope f a) b ↔ DifferentiableAt 𝕜 f b := by simp only [← differentiableWithinAt_univ, differentiableWithinAt_dslope_of_ne h]
Analysis\Calculus\FormalMultilinearSeries.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.NormedSpace.Multilinear.Curry /-! # Formal multilinear series In this file we define `FormalMultilinearSeries 𝕜 E F` to be a family of `n`-multilinear maps for all `n`, designed to model the sequence of derivatives of a function. In other files we use this notion to define `C^n` functions (called `contDiff` in `mathlib`) and analytic functions. ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. ## Tags multilinear, formal series -/ noncomputable section open Set Fin Topology -- Porting note: added explicit universes to fix compile universe u u' v w x variable {𝕜 : Type u} {𝕜' : Type u'} {E : Type v} {F : Type w} {G : Type x} section variable [Ring 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F] [TopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] [AddCommGroup G] [Module 𝕜 G] [TopologicalSpace G] [TopologicalAddGroup G] [ContinuousConstSMul 𝕜 G] /-- A formal multilinear series over a field `𝕜`, from `E` to `F`, is given by a family of multilinear maps from `E^n` to `F` for all `n`. -/ @[nolint unusedArguments] def FormalMultilinearSeries (𝕜 : Type*) (E : Type*) (F : Type*) [Ring 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F] [TopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] := ∀ n : ℕ, E[×n]→L[𝕜] F -- Porting note: was `deriving` instance : AddCommGroup (FormalMultilinearSeries 𝕜 E F) := inferInstanceAs <| AddCommGroup <| ∀ n : ℕ, E[×n]→L[𝕜] F instance : Inhabited (FormalMultilinearSeries 𝕜 E F) := ⟹0⟩ section Module instance (𝕜') [Semiring 𝕜'] [Module 𝕜' F] [ContinuousConstSMul 𝕜' F] [SMulCommClass 𝕜 𝕜' F] : Module 𝕜' (FormalMultilinearSeries 𝕜 E F) := inferInstanceAs <| Module 𝕜' <| ∀ n : ℕ, E[×n]→L[𝕜] F end Module namespace FormalMultilinearSeries #adaptation_note /-- After https://github.com/leanprover/lean4/pull/4481 the `simpNF` linter incorrectly claims this lemma can't be applied by `simp`. -/ @[simp, nolint simpNF] theorem zero_apply (n : ℕ) : (0 : FormalMultilinearSeries 𝕜 E F) n = 0 := rfl @[simp] theorem neg_apply (f : FormalMultilinearSeries 𝕜 E F) (n : ℕ) : (-f) n = - f n := rfl @[ext] protected theorem ext {p q : FormalMultilinearSeries 𝕜 E F} (h : ∀ n, p n = q n) : p = q := funext h protected theorem ne_iff {p q : FormalMultilinearSeries 𝕜 E F} : p ≠ q ↔ ∃ n, p n ≠ q n := Function.ne_iff /-- Cartesian product of two formal multilinear series (with the same field `𝕜` and the same source space, but possibly different target spaces). -/ def prod (p : FormalMultilinearSeries 𝕜 E F) (q : FormalMultilinearSeries 𝕜 E G) : FormalMultilinearSeries 𝕜 E (F × G) | n => (p n).prod (q n) /-- Killing the zeroth coefficient in a formal multilinear series -/ def removeZero (p : FormalMultilinearSeries 𝕜 E F) : FormalMultilinearSeries 𝕜 E F | 0 => 0 | n + 1 => p (n + 1) @[simp] theorem removeZero_coeff_zero (p : FormalMultilinearSeries 𝕜 E F) : p.removeZero 0 = 0 := rfl @[simp] theorem removeZero_coeff_succ (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) : p.removeZero (n + 1) = p (n + 1) := rfl theorem removeZero_of_pos (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (h : 0 < n) : p.removeZero n = p n := by rw [← Nat.succ_pred_eq_of_pos h] rfl /-- Convenience congruence lemma stating in a dependent setting that, if the arguments to a formal multilinear series are equal, then the values are also equal. -/ theorem congr (p : FormalMultilinearSeries 𝕜 E F) {m n : ℕ} {v : Fin m → E} {w : Fin n → E} (h1 : m = n) (h2 : ∀ (i : ℕ) (him : i < m) (hin : i < n), v ⟹i, him⟩ = w ⟹i, hin⟩) : p m v = p n w := by subst n congr with ⟹i, hi⟩ exact h2 i hi hi /-- Composing each term `pₙ` in a formal multilinear series with `(u, ..., u)` where `u` is a fixed continuous linear map, gives a new formal multilinear series `p.compContinuousLinearMap u`. -/ def compContinuousLinearMap (p : FormalMultilinearSeries 𝕜 F G) (u : E →L[𝕜] F) : FormalMultilinearSeries 𝕜 E G := fun n => (p n).compContinuousLinearMap fun _ : Fin n => u @[simp] theorem compContinuousLinearMap_apply (p : FormalMultilinearSeries 𝕜 F G) (u : E →L[𝕜] F) (n : ℕ) (v : Fin n → E) : (p.compContinuousLinearMap u) n v = p n (u ∘ v) := rfl variable (𝕜) [Ring 𝕜'] [SMul 𝕜 𝕜'] variable [Module 𝕜' E] [ContinuousConstSMul 𝕜' E] [IsScalarTower 𝕜 𝕜' E] variable [Module 𝕜' F] [ContinuousConstSMul 𝕜' F] [IsScalarTower 𝕜 𝕜' F] /-- Reinterpret a formal `𝕜'`-multilinear series as a formal `𝕜`-multilinear series. -/ @[simp] protected def restrictScalars (p : FormalMultilinearSeries 𝕜' E F) : FormalMultilinearSeries 𝕜 E F := fun n => (p n).restrictScalars 𝕜 end FormalMultilinearSeries end namespace FormalMultilinearSeries variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable (p : FormalMultilinearSeries 𝕜 E F) /-- Forgetting the zeroth term in a formal multilinear series, and interpreting the following terms as multilinear maps into `E →L[𝕜] F`. If `p` is the Taylor series (`HasFTaylorSeriesUpTo`) of a function, then `p.shift` is the Taylor series of the derivative of the function. Note that the `p.sum` of a Taylor series `p` does not give the original function; for a formal multilinear series that sums to the derivative of `p.sum`, see `HasFPowerSeriesOnBall.fderiv`. -/ def shift : FormalMultilinearSeries 𝕜 E (E →L[𝕜] F) := fun n => (p n.succ).curryRight /-- Adding a zeroth term to a formal multilinear series taking values in `E →L[𝕜] F`. This corresponds to starting from a Taylor series (`HasFTaylorSeriesUpTo`) for the derivative of a function, and building a Taylor series for the function itself. -/ def unshift (q : FormalMultilinearSeries 𝕜 E (E →L[𝕜] F)) (z : F) : FormalMultilinearSeries 𝕜 E F | 0 => (continuousMultilinearCurryFin0 𝕜 E F).symm z | n + 1 => -- Porting note: added type hint here and explicit universes to fix compile (continuousMultilinearCurryRightEquiv' 𝕜 n E F : (E [×n]→L[𝕜] E →L[𝕜] F) → (E [×n.succ]→L[𝕜] F)) (q n) end FormalMultilinearSeries section variable [Ring 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F] [TopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] [AddCommGroup G] [Module 𝕜 G] [TopologicalSpace G] [TopologicalAddGroup G] [ContinuousConstSMul 𝕜 G] namespace ContinuousLinearMap /-- Composing each term `pₙ` in a formal multilinear series with a continuous linear map `f` on the left gives a new formal multilinear series `f.compFormalMultilinearSeries p` whose general term is `f ∘ pₙ`. -/ def compFormalMultilinearSeries (f : F →L[𝕜] G) (p : FormalMultilinearSeries 𝕜 E F) : FormalMultilinearSeries 𝕜 E G := fun n => f.compContinuousMultilinearMap (p n) @[simp] theorem compFormalMultilinearSeries_apply (f : F →L[𝕜] G) (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) : (f.compFormalMultilinearSeries p) n = f.compContinuousMultilinearMap (p n) := rfl theorem compFormalMultilinearSeries_apply' (f : F →L[𝕜] G) (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) (v : Fin n → E) : (f.compFormalMultilinearSeries p) n v = f (p n v) := rfl end ContinuousLinearMap namespace ContinuousMultilinearMap variable {ι : Type*} {E : ι → Type*} [∀ i, AddCommGroup (E i)] [∀ i, Module 𝕜 (E i)] [∀ i, TopologicalSpace (E i)] [∀ i, TopologicalAddGroup (E i)] [∀ i, ContinuousConstSMul 𝕜 (E i)] [Fintype ι] (f : ContinuousMultilinearMap 𝕜 E F) /-- Realize a ContinuousMultilinearMap on `∀ i : ι, E i` as the evaluation of a FormalMultilinearSeries by choosing an arbitrary identification `ι ≃ Fin (Fintype.card ι)`. -/ noncomputable def toFormalMultilinearSeries : FormalMultilinearSeries 𝕜 (∀ i, E i) F := fun n ↩ if h : Fintype.card ι = n then (f.compContinuousLinearMap .proj).domDomCongr (Fintype.equivFinOfCardEq h) else 0 end ContinuousMultilinearMap end namespace FormalMultilinearSeries section Order variable [Ring 𝕜] {n : ℕ} [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F] [TopologicalAddGroup F] [ContinuousConstSMul 𝕜 F] {p : FormalMultilinearSeries 𝕜 E F} /-- The index of the first non-zero coefficient in `p` (or `0` if all coefficients are zero). This is the order of the isolated zero of an analytic function `f` at a point if `p` is the Taylor series of `f` at that point. -/ noncomputable def order (p : FormalMultilinearSeries 𝕜 E F) : ℕ := sInf { n | p n ≠ 0 } @[simp] theorem order_zero : (0 : FormalMultilinearSeries 𝕜 E F).order = 0 := by simp [order] theorem ne_zero_of_order_ne_zero (hp : p.order ≠ 0) : p ≠ 0 := fun h => by simp [h] at hp theorem order_eq_find [DecidablePred fun n => p n ≠ 0] (hp : ∃ n, p n ≠ 0) : p.order = Nat.find hp := by convert Nat.sInf_def hp theorem order_eq_find' [DecidablePred fun n => p n ≠ 0] (hp : p ≠ 0) : p.order = Nat.find (FormalMultilinearSeries.ne_iff.mp hp) := order_eq_find _ theorem order_eq_zero_iff' : p.order = 0 ↔ p = 0 √ p 0 ≠ 0 := by simpa [order, Nat.sInf_eq_zero, FormalMultilinearSeries.ext_iff, eq_empty_iff_forall_not_mem] using or_comm theorem order_eq_zero_iff (hp : p ≠ 0) : p.order = 0 ↔ p 0 ≠ 0 := by simp [order_eq_zero_iff', hp] theorem apply_order_ne_zero (hp : p ≠ 0) : p p.order ≠ 0 := Nat.sInf_mem (FormalMultilinearSeries.ne_iff.1 hp) theorem apply_order_ne_zero' (hp : p.order ≠ 0) : p p.order ≠ 0 := apply_order_ne_zero (ne_zero_of_order_ne_zero hp) theorem apply_eq_zero_of_lt_order (hp : n < p.order) : p n = 0 := by_contra <| Nat.not_mem_of_lt_sInf hp end Order section Coef variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] {s : E} {p : FormalMultilinearSeries 𝕜 𝕜 E} {f : 𝕜 → E} {n : ℕ} {z z₀ : 𝕜} {y : Fin n → 𝕜} /-- The `n`th coefficient of `p` when seen as a power series. -/ def coeff (p : FormalMultilinearSeries 𝕜 𝕜 E) (n : ℕ) : E := p n 1 theorem mkPiRing_coeff_eq (p : FormalMultilinearSeries 𝕜 𝕜 E) (n : ℕ) : ContinuousMultilinearMap.mkPiRing 𝕜 (Fin n) (p.coeff n) = p n := (p n).mkPiRing_apply_one_eq_self @[simp] theorem apply_eq_prod_smul_coeff : p n y = (∏ i, y i) • p.coeff n := by convert (p n).toMultilinearMap.map_smul_univ y 1 simp only [Pi.one_apply, Algebra.id.smul_eq_mul, mul_one] theorem coeff_eq_zero : p.coeff n = 0 ↔ p n = 0 := by rw [← mkPiRing_coeff_eq p, ContinuousMultilinearMap.mkPiRing_eq_zero_iff] theorem apply_eq_pow_smul_coeff : (p n fun _ => z) = z ^ n • p.coeff n := by simp @[simp] theorem norm_apply_eq_norm_coef : ‖p n‖ = ‖coeff p n‖ := by rw [← mkPiRing_coeff_eq p, ContinuousMultilinearMap.norm_mkPiRing] end Coef section Fslope variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] {p : FormalMultilinearSeries 𝕜 𝕜 E} {n : ℕ} /-- The formal counterpart of `dslope`, corresponding to the expansion of `(f z - f 0) / z`. If `f` has `p` as a power series, then `dslope f` has `fslope p` as a power series. -/ noncomputable def fslope (p : FormalMultilinearSeries 𝕜 𝕜 E) : FormalMultilinearSeries 𝕜 𝕜 E := fun n => (p (n + 1)).curryLeft 1 @[simp] theorem coeff_fslope : p.fslope.coeff n = p.coeff (n + 1) := by simp only [fslope, coeff, ContinuousMultilinearMap.curryLeft_apply] congr 1 exact Fin.cons_self_tail 1 @[simp] theorem coeff_iterate_fslope (k n : ℕ) : (fslope^[k] p).coeff n = p.coeff (n + k) := by induction k generalizing p with | zero => rfl | succ k ih => simp [ih, add_assoc] end Fslope end FormalMultilinearSeries section Const /-- The formal multilinear series where all terms of positive degree are equal to zero, and the term of degree zero is `c`. It is the power series expansion of the constant function equal to `c` everywhere. -/ def constFormalMultilinearSeries (𝕜 : Type*) [NontriviallyNormedField 𝕜] (E : Type*) [NormedAddCommGroup E] [NormedSpace 𝕜 E] [ContinuousConstSMul 𝕜 E] [TopologicalAddGroup E] {F : Type*} [NormedAddCommGroup F] [TopologicalAddGroup F] [NormedSpace 𝕜 F] [ContinuousConstSMul 𝕜 F] (c : F) : FormalMultilinearSeries 𝕜 E F | 0 => ContinuousMultilinearMap.curry0 _ _ c | _ => 0 @[simp] theorem constFormalMultilinearSeries_apply [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] {c : F} {n : ℕ} (hn : n ≠ 0) : constFormalMultilinearSeries 𝕜 E c n = 0 := Nat.casesOn n (fun hn => (hn rfl).elim) (fun _ _ => rfl) hn @[simp] lemma constFormalMultilinearSeries_zero [NontriviallyNormedField 𝕜] [NormedAddCommGroup E ] [NormedAddCommGroup F] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] : constFormalMultilinearSeries 𝕜 E (0 : F) = 0 := by ext n x simp only [FormalMultilinearSeries.zero_apply, ContinuousMultilinearMap.zero_apply, constFormalMultilinearSeries] induction n · simp only [Nat.zero_eq, ContinuousMultilinearMap.curry0_apply] · simp only [constFormalMultilinearSeries.match_1.eq_2, ContinuousMultilinearMap.zero_apply] end Const section Linear variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] namespace ContinuousLinearMap /-- Formal power series of a continuous linear map `f : E →L[𝕜] F` at `x : E`: `f y = f x + f (y - x)`. -/ def fpowerSeries (f : E →L[𝕜] F) (x : E) : FormalMultilinearSeries 𝕜 E F | 0 => ContinuousMultilinearMap.curry0 𝕜 _ (f x) | 1 => (continuousMultilinearCurryFin1 𝕜 E F).symm f | _ => 0 theorem fpowerSeries_apply_zero (f : E →L[𝕜] F) (x : E) : f.fpowerSeries x 0 = ContinuousMultilinearMap.curry0 𝕜 _ (f x) := rfl theorem fpowerSeries_apply_one (f : E →L[𝕜] F) (x : E) : f.fpowerSeries x 1 = (continuousMultilinearCurryFin1 𝕜 E F).symm f := rfl theorem fpowerSeries_apply_add_two (f : E →L[𝕜] F) (x : E) (n : ℕ) : f.fpowerSeries x (n + 2) = 0 := rfl attribute [eqns fpowerSeries_apply_zero fpowerSeries_apply_one fpowerSeries_apply_add_two] fpowerSeries attribute [simp] fpowerSeries end ContinuousLinearMap end Linear
Analysis\Calculus\Implicit.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.InverseFunctionTheorem.FDeriv import Mathlib.Analysis.Calculus.FDeriv.Add import Mathlib.Analysis.Calculus.FDeriv.Prod import Mathlib.Analysis.Normed.Module.Complemented /-! # Implicit function theorem We prove three versions of the implicit function theorem. First we define a structure `ImplicitFunctionData` that holds arguments for the most general version of the implicit function theorem, see `ImplicitFunctionData.implicitFunction` and `ImplicitFunctionData.implicitFunction_hasStrictFDerivAt`. This version allows a user to choose a specific implicit function but provides only a little convenience over the inverse function theorem. Then we define `HasStrictFDerivAt.implicitFunctionDataOfComplemented`: implicit function defined by `f (g z y) = z`, where `f : E → F` is a function strictly differentiable at `a` such that its derivative `f'` is surjective and has a `complemented` kernel. Finally, if the codomain of `f` is a finite dimensional space, then we can automatically prove that the kernel of `f'` is complemented, hence the only assumptions are `HasStrictFDerivAt` and `f'.range = ⊀`. This version is named `HasStrictFDerivAt.implicitFunction`. ## TODO * Add a version for a function `f : E × F → G` such that $$\frac{\partial f}{\partial y}$$ is invertible. * Add a version for `f : 𝕜 × 𝕜 → 𝕜` proving `HasStrictDerivAt` and `deriv φ = ...`. * Prove that in a real vector space the implicit function has the same smoothness as the original one. * If the original function is differentiable in a neighborhood, then the implicit function is differentiable in a neighborhood as well. Current setup only proves differentiability at one point for the implicit function constructed in this file (as opposed to an unspecified implicit function). One of the ways to overcome this difficulty is to use uniqueness of the implicit function in the general version of the theorem. Another way is to prove that *any* implicit function satisfying some predicate is strictly differentiable. ## Tags implicit function, inverse function -/ noncomputable section open scoped Topology open Filter open ContinuousLinearMap (fst snd smulRight ker_prod) open ContinuousLinearEquiv (ofBijective) open LinearMap (ker range) /-! ### General version Consider two functions `f : E → F` and `g : E → G` and a point `a` such that * both functions are strictly differentiable at `a`; * the derivatives are surjective; * the kernels of the derivatives are complementary subspaces of `E`. Note that the map `x ↩ (f x, g x)` has a bijective derivative, hence it is a partial homeomorphism between `E` and `F × G`. We use this fact to define a function `φ : F → G → E` (see `ImplicitFunctionData.implicitFunction`) such that for `(y, z)` close enough to `(f a, g a)` we have `f (φ y z) = y` and `g (φ y z) = z`. We also prove a formula for $$\frac{\partial\varphi}{\partial z}.$$ Though this statement is almost symmetric with respect to `F`, `G`, we interpret it in the following way. Consider a family of surfaces `{x | f x = y}`, `y ∈ 𝓝 (f a)`. Each of these surfaces is parametrized by `φ y`. There are many ways to choose a (differentiable) function `φ` such that `f (φ y z) = y` but the extra condition `g (φ y z) = z` allows a user to select one of these functions. If we imagine that the level surfaces `f = const` form a local horizontal foliation, then the choice of `g` fixes a transverse foliation `g = const`, and `φ` is the inverse function of the projection of `{x | f x = y}` along this transverse foliation. This version of the theorem is used to prove the other versions and can be used if a user needs to have a complete control over the choice of the implicit function. -/ /-- Data for the general version of the implicit function theorem. It holds two functions `f : E → F` and `g : E → G` (named `leftFun` and `rightFun`) and a point `a` (named `pt`) such that * both functions are strictly differentiable at `a`; * the derivatives are surjective; * the kernels of the derivatives are complementary subspaces of `E`. -/ -- Porting note(#5171): linter not yet ported @[nolint has_nonempty_instance] structure ImplicitFunctionData (𝕜 : Type*) [NontriviallyNormedField 𝕜] (E : Type*) [NormedAddCommGroup E] [NormedSpace 𝕜 E] [CompleteSpace E] (F : Type*) [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F] (G : Type*) [NormedAddCommGroup G] [NormedSpace 𝕜 G] [CompleteSpace G] where leftFun : E → F leftDeriv : E →L[𝕜] F rightFun : E → G rightDeriv : E →L[𝕜] G pt : E left_has_deriv : HasStrictFDerivAt leftFun leftDeriv pt right_has_deriv : HasStrictFDerivAt rightFun rightDeriv pt left_range : range leftDeriv = ⊀ right_range : range rightDeriv = ⊀ isCompl_ker : IsCompl (ker leftDeriv) (ker rightDeriv) namespace ImplicitFunctionData variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [CompleteSpace E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F] {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] [CompleteSpace G] (φ : ImplicitFunctionData 𝕜 E F G) /-- The function given by `x ↩ (leftFun x, rightFun x)`. -/ def prodFun (x : E) : F × G := (φ.leftFun x, φ.rightFun x) @[simp] theorem prodFun_apply (x : E) : φ.prodFun x = (φ.leftFun x, φ.rightFun x) := rfl protected theorem hasStrictFDerivAt : HasStrictFDerivAt φ.prodFun (φ.leftDeriv.equivProdOfSurjectiveOfIsCompl φ.rightDeriv φ.left_range φ.right_range φ.isCompl_ker : E →L[𝕜] F × G) φ.pt := φ.left_has_deriv.prod φ.right_has_deriv /-- Implicit function theorem. If `f : E → F` and `g : E → G` are two maps strictly differentiable at `a`, their derivatives `f'`, `g'` are surjective, and the kernels of these derivatives are complementary subspaces of `E`, then `x ↩ (f x, g x)` defines a partial homeomorphism between `E` and `F × G`. In particular, `{x | f x = f a}` is locally homeomorphic to `G`. -/ def toPartialHomeomorph : PartialHomeomorph E (F × G) := φ.hasStrictFDerivAt.toPartialHomeomorph _ /-- Implicit function theorem. If `f : E → F` and `g : E → G` are two maps strictly differentiable at `a`, their derivatives `f'`, `g'` are surjective, and the kernels of these derivatives are complementary subspaces of `E`, then `implicitFunction` is the unique (germ of a) map `φ : F → G → E` such that `f (φ y z) = y` and `g (φ y z) = z`. -/ def implicitFunction : F → G → E := Function.curry <| φ.toPartialHomeomorph.symm @[simp] theorem toPartialHomeomorph_coe : ⇑φ.toPartialHomeomorph = φ.prodFun := rfl theorem toPartialHomeomorph_apply (x : E) : φ.toPartialHomeomorph x = (φ.leftFun x, φ.rightFun x) := rfl theorem pt_mem_toPartialHomeomorph_source : φ.pt ∈ φ.toPartialHomeomorph.source := φ.hasStrictFDerivAt.mem_toPartialHomeomorph_source theorem map_pt_mem_toPartialHomeomorph_target : (φ.leftFun φ.pt, φ.rightFun φ.pt) ∈ φ.toPartialHomeomorph.target := φ.toPartialHomeomorph.map_source <| φ.pt_mem_toPartialHomeomorph_source theorem prod_map_implicitFunction : ∀ᶠ p : F × G in 𝓝 (φ.prodFun φ.pt), φ.prodFun (φ.implicitFunction p.1 p.2) = p := φ.hasStrictFDerivAt.eventually_right_inverse.mono fun ⟹_, _⟩ h => h theorem left_map_implicitFunction : ∀ᶠ p : F × G in 𝓝 (φ.prodFun φ.pt), φ.leftFun (φ.implicitFunction p.1 p.2) = p.1 := φ.prod_map_implicitFunction.mono fun _ => congr_arg Prod.fst theorem right_map_implicitFunction : ∀ᶠ p : F × G in 𝓝 (φ.prodFun φ.pt), φ.rightFun (φ.implicitFunction p.1 p.2) = p.2 := φ.prod_map_implicitFunction.mono fun _ => congr_arg Prod.snd theorem implicitFunction_apply_image : ∀ᶠ x in 𝓝 φ.pt, φ.implicitFunction (φ.leftFun x) (φ.rightFun x) = x := φ.hasStrictFDerivAt.eventually_left_inverse theorem map_nhds_eq : map φ.leftFun (𝓝 φ.pt) = 𝓝 (φ.leftFun φ.pt) := show map (Prod.fst ∘ φ.prodFun) (𝓝 φ.pt) = 𝓝 (φ.prodFun φ.pt).1 by rw [← map_map, φ.hasStrictFDerivAt.map_nhds_eq_of_equiv, map_fst_nhds] theorem implicitFunction_hasStrictFDerivAt (g'inv : G →L[𝕜] E) (hg'inv : φ.rightDeriv.comp g'inv = ContinuousLinearMap.id 𝕜 G) (hg'invf : φ.leftDeriv.comp g'inv = 0) : HasStrictFDerivAt (φ.implicitFunction (φ.leftFun φ.pt)) g'inv (φ.rightFun φ.pt) := by have := φ.hasStrictFDerivAt.to_localInverse simp only [prodFun] at this convert this.comp (φ.rightFun φ.pt) ((hasStrictFDerivAt_const _ _).prod (hasStrictFDerivAt_id _)) -- Porting note: added parentheses to help `simp` simp only [ContinuousLinearMap.ext_iff, (ContinuousLinearMap.comp_apply)] at hg'inv hg'invf ⊢ -- porting note (#10745): was `simp [ContinuousLinearEquiv.eq_symm_apply]`; -- both `simp` and `rw` fail here, `erw` works intro x erw [ContinuousLinearEquiv.eq_symm_apply] simp [*] end ImplicitFunctionData namespace HasStrictFDerivAt section Complemented /-! ### Case of a complemented kernel In this section we prove the following version of the implicit function theorem. Consider a map `f : E → F` and a point `a : E` such that `f` is strictly differentiable at `a`, its derivative `f'` is surjective and the kernel of `f'` is a complemented subspace of `E` (i.e., it has a closed complementary subspace). Then there exists a function `φ : F → ker f' → E` such that for `(y, z)` close to `(f a, 0)` we have `f (φ y z) = y` and the derivative of `φ (f a)` at zero is the embedding `ker f' → E`. Note that a map with these properties is not unique. E.g., different choices of a subspace complementary to `ker f'` lead to different maps `φ`. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [CompleteSpace E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F] {f : E → F} {f' : E →L[𝕜] F} {a : E} section Defs variable (f f') /-- Data used to apply the generic implicit function theorem to the case of a strictly differentiable map such that its derivative is surjective and has a complemented kernel. -/ @[simp] def implicitFunctionDataOfComplemented (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) : ImplicitFunctionData 𝕜 E F (ker f') where leftFun := f leftDeriv := f' rightFun x := Classical.choose hker (x - a) rightDeriv := Classical.choose hker pt := a left_has_deriv := hf right_has_deriv := (Classical.choose hker).hasStrictFDerivAt.comp a ((hasStrictFDerivAt_id a).sub_const a) left_range := hf' right_range := LinearMap.range_eq_of_proj (Classical.choose_spec hker) isCompl_ker := LinearMap.isCompl_of_proj (Classical.choose_spec hker) /-- A partial homeomorphism between `E` and `F × f'.ker` sending level surfaces of `f` to vertical subspaces. -/ def implicitToPartialHomeomorphOfComplemented (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) : PartialHomeomorph E (F × ker f') := (implicitFunctionDataOfComplemented f f' hf hf' hker).toPartialHomeomorph /-- Implicit function `g` defined by `f (g z y) = z`. -/ def implicitFunctionOfComplemented (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) : F → ker f' → E := (implicitFunctionDataOfComplemented f f' hf hf' hker).implicitFunction end Defs @[simp] theorem implicitToPartialHomeomorphOfComplemented_fst (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) (x : E) : (hf.implicitToPartialHomeomorphOfComplemented f f' hf' hker x).fst = f x := rfl theorem implicitToPartialHomeomorphOfComplemented_apply (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) (y : E) : hf.implicitToPartialHomeomorphOfComplemented f f' hf' hker y = (f y, Classical.choose hker (y - a)) := rfl @[simp] theorem implicitToPartialHomeomorphOfComplemented_apply_ker (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) (y : ker f') : hf.implicitToPartialHomeomorphOfComplemented f f' hf' hker (y + a) = (f (y + a), y) := by simp only [implicitToPartialHomeomorphOfComplemented_apply, add_sub_cancel_right, Classical.choose_spec hker] @[simp] theorem implicitToPartialHomeomorphOfComplemented_self (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) : hf.implicitToPartialHomeomorphOfComplemented f f' hf' hker a = (f a, 0) := by simp [hf.implicitToPartialHomeomorphOfComplemented_apply] theorem mem_implicitToPartialHomeomorphOfComplemented_source (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) : a ∈ (hf.implicitToPartialHomeomorphOfComplemented f f' hf' hker).source := ImplicitFunctionData.pt_mem_toPartialHomeomorph_source _ theorem mem_implicitToPartialHomeomorphOfComplemented_target (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) : (f a, (0 : ker f')) ∈ (hf.implicitToPartialHomeomorphOfComplemented f f' hf' hker).target := by simpa only [implicitToPartialHomeomorphOfComplemented_self] using (hf.implicitToPartialHomeomorphOfComplemented f f' hf' hker).map_source <| hf.mem_implicitToPartialHomeomorphOfComplemented_source hf' hker /-- `HasStrictFDerivAt.implicitFunctionOfComplemented` sends `(z, y)` to a point in `f ⁻¹' z`. -/ theorem map_implicitFunctionOfComplemented_eq (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) : ∀ᶠ p : F × ker f' in 𝓝 (f a, 0), f (hf.implicitFunctionOfComplemented f f' hf' hker p.1 p.2) = p.1 := ((hf.implicitToPartialHomeomorphOfComplemented f f' hf' hker).eventually_right_inverse <| hf.mem_implicitToPartialHomeomorphOfComplemented_target hf' hker).mono fun ⟹_, _⟩ h => congr_arg Prod.fst h /-- Any point in some neighborhood of `a` can be represented as `HasStrictFDerivAt.implicitFunctionOfComplemented` of some point. -/ theorem eq_implicitFunctionOfComplemented (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) : ∀ᶠ x in 𝓝 a, hf.implicitFunctionOfComplemented f f' hf' hker (f x) (hf.implicitToPartialHomeomorphOfComplemented f f' hf' hker x).snd = x := (implicitFunctionDataOfComplemented f f' hf hf' hker).implicitFunction_apply_image @[simp] theorem implicitFunctionOfComplemented_apply_image (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) : hf.implicitFunctionOfComplemented f f' hf' hker (f a) 0 = a := by simpa only [implicitToPartialHomeomorphOfComplemented_self] using (hf.implicitToPartialHomeomorphOfComplemented f f' hf' hker).left_inv (hf.mem_implicitToPartialHomeomorphOfComplemented_source hf' hker) theorem to_implicitFunctionOfComplemented (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (hker : (ker f').ClosedComplemented) : HasStrictFDerivAt (hf.implicitFunctionOfComplemented f f' hf' hker (f a)) (ker f').subtypeL 0 := by convert (implicitFunctionDataOfComplemented f f' hf hf' hker).implicitFunction_hasStrictFDerivAt (ker f').subtypeL _ _ swap · ext -- Porting note: added parentheses to help `simp` simp only [Classical.choose_spec hker, implicitFunctionDataOfComplemented, ContinuousLinearMap.comp_apply, Submodule.coe_subtypeL', Submodule.coeSubtype, ContinuousLinearMap.id_apply] swap · ext -- Porting note: added parentheses to help `simp` simp only [(ContinuousLinearMap.comp_apply), Submodule.coe_subtypeL', Submodule.coeSubtype, LinearMap.map_coe_ker, (ContinuousLinearMap.zero_apply)] simp only [implicitFunctionDataOfComplemented, map_sub, sub_self] end Complemented /-! ### Finite dimensional case In this section we prove the following version of the implicit function theorem. Consider a map `f : E → F` from a Banach normed space to a finite dimensional space. Take a point `a : E` such that `f` is strictly differentiable at `a` and its derivative `f'` is surjective. Then there exists a function `φ : F → ker f' → E` such that for `(y, z)` close to `(f a, 0)` we have `f (φ y z) = y` and the derivative of `φ (f a)` at zero is the embedding `ker f' → E`. This version deduces that `ker f'` is a complemented subspace from the fact that `F` is a finite dimensional space, then applies the previous version. Note that a map with these properties is not unique. E.g., different choices of a subspace complementary to `ker f'` lead to different maps `φ`. -/ section FiniteDimensional variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] [CompleteSpace 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [CompleteSpace E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [FiniteDimensional 𝕜 F] (f : E → F) (f' : E →L[𝕜] F) {a : E} /-- Given a map `f : E → F` to a finite dimensional space with a surjective derivative `f'`, returns a partial homeomorphism between `E` and `F × ker f'`. -/ def implicitToPartialHomeomorph (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) : PartialHomeomorph E (F × ker f') := haveI := FiniteDimensional.complete 𝕜 F hf.implicitToPartialHomeomorphOfComplemented f f' hf' f'.ker_closedComplemented_of_finiteDimensional_range /-- Implicit function `g` defined by `f (g z y) = z`. -/ def implicitFunction (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) : F → ker f' → E := Function.curry <| (hf.implicitToPartialHomeomorph f f' hf').symm variable {f f'} @[simp] theorem implicitToPartialHomeomorph_fst (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (x : E) : (hf.implicitToPartialHomeomorph f f' hf' x).fst = f x := rfl @[simp] theorem implicitToPartialHomeomorph_apply_ker (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) (y : ker f') : hf.implicitToPartialHomeomorph f f' hf' (y + a) = (f (y + a), y) := -- Porting note: had to add `haveI` (here and below) haveI := FiniteDimensional.complete 𝕜 F implicitToPartialHomeomorphOfComplemented_apply_ker .. @[simp] theorem implicitToPartialHomeomorph_self (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) : hf.implicitToPartialHomeomorph f f' hf' a = (f a, 0) := haveI := FiniteDimensional.complete 𝕜 F implicitToPartialHomeomorphOfComplemented_self .. theorem mem_implicitToPartialHomeomorph_source (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) : a ∈ (hf.implicitToPartialHomeomorph f f' hf').source := haveI := FiniteDimensional.complete 𝕜 F ImplicitFunctionData.pt_mem_toPartialHomeomorph_source _ theorem mem_implicitToPartialHomeomorph_target (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) : (f a, (0 : ker f')) ∈ (hf.implicitToPartialHomeomorph f f' hf').target := haveI := FiniteDimensional.complete 𝕜 F mem_implicitToPartialHomeomorphOfComplemented_target .. theorem tendsto_implicitFunction (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) {α : Type*} {l : Filter α} {g₁ : α → F} {g₂ : α → ker f'} (h₁ : Tendsto g₁ l (𝓝 <| f a)) (h₂ : Tendsto g₂ l (𝓝 0)) : Tendsto (fun t => hf.implicitFunction f f' hf' (g₁ t) (g₂ t)) l (𝓝 a) := by refine ((hf.implicitToPartialHomeomorph f f' hf').tendsto_symm (hf.mem_implicitToPartialHomeomorph_source hf')).comp ?_ rw [implicitToPartialHomeomorph_self] exact h₁.prod_mk_nhds h₂ alias _root_.Filter.Tendsto.implicitFunction := tendsto_implicitFunction /-- `HasStrictFDerivAt.implicitFunction` sends `(z, y)` to a point in `f ⁻¹' z`. -/ theorem map_implicitFunction_eq (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) : ∀ᶠ p : F × ker f' in 𝓝 (f a, 0), f (hf.implicitFunction f f' hf' p.1 p.2) = p.1 := haveI := FiniteDimensional.complete 𝕜 F map_implicitFunctionOfComplemented_eq .. @[simp] theorem implicitFunction_apply_image (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) : hf.implicitFunction f f' hf' (f a) 0 = a := by haveI := FiniteDimensional.complete 𝕜 F apply implicitFunctionOfComplemented_apply_image /-- Any point in some neighborhood of `a` can be represented as `HasStrictFDerivAt.implicitFunction` of some point. -/ theorem eq_implicitFunction (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) : ∀ᶠ x in 𝓝 a, hf.implicitFunction f f' hf' (f x) (hf.implicitToPartialHomeomorph f f' hf' x).snd = x := haveI := FiniteDimensional.complete 𝕜 F eq_implicitFunctionOfComplemented .. theorem to_implicitFunction (hf : HasStrictFDerivAt f f' a) (hf' : range f' = ⊀) : HasStrictFDerivAt (hf.implicitFunction f f' hf' (f a)) (ker f').subtypeL 0 := haveI := FiniteDimensional.complete 𝕜 F to_implicitFunctionOfComplemented .. end FiniteDimensional end HasStrictFDerivAt
Analysis\Calculus\LagrangeMultipliers.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.FDeriv.Prod import Mathlib.Analysis.Calculus.InverseFunctionTheorem.FDeriv import Mathlib.LinearAlgebra.Dual /-! # Lagrange multipliers In this file we formalize the [Lagrange multipliers](https://en.wikipedia.org/wiki/Lagrange_multiplier) method of solving conditional extremum problems: if a function `φ` has a local extremum at `x₀` on the set `f ⁻¹' {f x₀}`, `f x = (f₀ x, ..., fₙ₋₁ x)`, then the differentials of `fₖ` and `φ` are linearly dependent. First we formulate a geometric version of this theorem which does not rely on the target space being `ℝⁿ`, then restate it in terms of coordinates. ## TODO Formalize Karush-Kuhn-Tucker theorem ## Tags lagrange multiplier, local extremum -/ open Filter Set open scoped Topology Filter variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {f : E → F} {φ : E → ℝ} {x₀ : E} {f' : E →L[ℝ] F} {φ' : E →L[ℝ] ℝ} /-- Lagrange multipliers theorem: if `φ : E → ℝ` has a local extremum on the set `{x | f x = f x₀}` at `x₀`, both `f : E → F` and `φ` are strictly differentiable at `x₀`, and the codomain of `f` is a complete space, then the linear map `x ↩ (f' x, φ' x)` is not surjective. -/ theorem IsLocalExtrOn.range_ne_top_of_hasStrictFDerivAt (hextr : IsLocalExtrOn φ {x | f x = f x₀} x₀) (hf' : HasStrictFDerivAt f f' x₀) (hφ' : HasStrictFDerivAt φ φ' x₀) : LinearMap.range (f'.prod φ') ≠ ⊀ := by intro htop set fφ := fun x => (f x, φ x) have A : map φ (𝓝[f ⁻¹' {f x₀}] x₀) = 𝓝 (φ x₀) := by change map (Prod.snd ∘ fφ) (𝓝[fφ ⁻¹' {p | p.1 = f x₀}] x₀) = 𝓝 (φ x₀) rw [← map_map, nhdsWithin, map_inf_principal_preimage, (hf'.prod hφ').map_nhds_eq_of_surj htop] exact map_snd_nhdsWithin _ exact hextr.not_nhds_le_map A.ge /-- Lagrange multipliers theorem: if `φ : E → ℝ` has a local extremum on the set `{x | f x = f x₀}` at `x₀`, both `f : E → F` and `φ` are strictly differentiable at `x₀`, and the codomain of `f` is a complete space, then there exist `Λ : dual ℝ F` and `Λ₀ : ℝ` such that `(Λ, Λ₀) ≠ 0` and `Λ (f' x) + Λ₀ • φ' x = 0` for all `x`. -/ theorem IsLocalExtrOn.exists_linear_map_of_hasStrictFDerivAt (hextr : IsLocalExtrOn φ {x | f x = f x₀} x₀) (hf' : HasStrictFDerivAt f f' x₀) (hφ' : HasStrictFDerivAt φ φ' x₀) : ∃ (Λ : Module.Dual ℝ F) (Λ₀ : ℝ), (Λ, Λ₀) ≠ 0 ∧ ∀ x, Λ (f' x) + Λ₀ • φ' x = 0 := by rcases Submodule.exists_le_ker_of_lt_top _ (lt_top_iff_ne_top.2 <| hextr.range_ne_top_of_hasStrictFDerivAt hf' hφ') with ⟹Λ', h0, hΛ'⟩ set e : ((F →ₗ[ℝ] ℝ) × ℝ) ≃ₗ[ℝ] F × ℝ →ₗ[ℝ] ℝ := ((LinearEquiv.refl ℝ (F →ₗ[ℝ] ℝ)).prod (LinearMap.ringLmapEquivSelf ℝ ℝ ℝ).symm).trans (LinearMap.coprodEquiv ℝ) rcases e.surjective Λ' with ⟹⟹Λ, Λ₀⟩, rfl⟩ refine ⟹Λ, Λ₀, e.map_ne_zero_iff.1 h0, fun x => ?_⟩ convert LinearMap.congr_fun (LinearMap.range_le_ker_iff.1 hΛ') x using 1 -- squeezed `simp [mul_comm]` to speed up elaboration simp only [e, smul_eq_mul, LinearEquiv.trans_apply, LinearEquiv.prod_apply, LinearEquiv.refl_apply, LinearMap.ringLmapEquivSelf_symm_apply, LinearMap.coprodEquiv_apply, ContinuousLinearMap.coe_prod, LinearMap.coprod_comp_prod, LinearMap.add_apply, LinearMap.coe_comp, ContinuousLinearMap.coe_coe, Function.comp_apply, LinearMap.coe_smulRight, LinearMap.one_apply, mul_comm] /-- Lagrange multipliers theorem: if `φ : E → ℝ` has a local extremum on the set `{x | f x = f x₀}` at `x₀`, and both `f : E → ℝ` and `φ` are strictly differentiable at `x₀`, then there exist `a b : ℝ` such that `(a, b) ≠ 0` and `a • f' + b • φ' = 0`. -/ theorem IsLocalExtrOn.exists_multipliers_of_hasStrictFDerivAt_1d {f : E → ℝ} {f' : E →L[ℝ] ℝ} (hextr : IsLocalExtrOn φ {x | f x = f x₀} x₀) (hf' : HasStrictFDerivAt f f' x₀) (hφ' : HasStrictFDerivAt φ φ' x₀) : ∃ a b : ℝ, (a, b) ≠ 0 ∧ a • f' + b • φ' = 0 := by obtain ⟹Λ, Λ₀, hΛ, hfΛ⟩ := hextr.exists_linear_map_of_hasStrictFDerivAt hf' hφ' refine ⟹Λ 1, Λ₀, ?_, ?_⟩ · contrapose! hΛ simp only [Prod.mk_eq_zero] at hΛ ⊢ refine ⟹LinearMap.ext fun x => ?_, hΛ.2⟩ simpa [hΛ.1] using Λ.map_smul x 1 · ext x have H₁ : Λ (f' x) = f' x * Λ 1 := by simpa only [mul_one, Algebra.id.smul_eq_mul] using Λ.map_smul (f' x) 1 have H₂ : f' x * Λ 1 + Λ₀ * φ' x = 0 := by simpa only [Algebra.id.smul_eq_mul, H₁] using hfΛ x simpa [mul_comm] using H₂ /-- Lagrange multipliers theorem, 1d version. Let `f : ι → E → ℝ` be a finite family of functions. Suppose that `φ : E → ℝ` has a local extremum on the set `{x | ∀ i, f i x = f i x₀}` at `x₀`. Suppose that all functions `f i` as well as `φ` are strictly differentiable at `x₀`. Then the derivatives `f' i : E → L[ℝ] ℝ` and `φ' : E →L[ℝ] ℝ` are linearly dependent: there exist `Λ : ι → ℝ` and `Λ₀ : ℝ`, `(Λ, Λ₀) ≠ 0`, such that `∑ i, Λ i • f' i + Λ₀ • φ' = 0`. See also `IsLocalExtrOn.linear_dependent_of_hasStrictFDerivAt` for a version that states `¬LinearIndependent ℝ _` instead of existence of `Λ` and `Λ₀`. -/ theorem IsLocalExtrOn.exists_multipliers_of_hasStrictFDerivAt {ι : Type*} [Fintype ι] {f : ι → E → ℝ} {f' : ι → E →L[ℝ] ℝ} (hextr : IsLocalExtrOn φ {x | ∀ i, f i x = f i x₀} x₀) (hf' : ∀ i, HasStrictFDerivAt (f i) (f' i) x₀) (hφ' : HasStrictFDerivAt φ φ' x₀) : ∃ (Λ : ι → ℝ) (Λ₀ : ℝ), (Λ, Λ₀) ≠ 0 ∧ (∑ i, Λ i • f' i) + Λ₀ • φ' = 0 := by letI := Classical.decEq ι replace hextr : IsLocalExtrOn φ {x | (fun i => f i x) = fun i => f i x₀} x₀ := by simpa only [Function.funext_iff] using hextr rcases hextr.exists_linear_map_of_hasStrictFDerivAt (hasStrictFDerivAt_pi.2 fun i => hf' i) hφ' with ⟹Λ, Λ₀, h0, hsum⟩ rcases (LinearEquiv.piRing ℝ ℝ ι ℝ).symm.surjective Λ with ⟹Λ, rfl⟩ refine ⟹Λ, Λ₀, ?_, ?_⟩ · simpa only [Ne, Prod.ext_iff, LinearEquiv.map_eq_zero_iff, Prod.fst_zero] using h0 · ext x; simpa [mul_comm] using hsum x /-- Lagrange multipliers theorem. Let `f : ι → E → ℝ` be a finite family of functions. Suppose that `φ : E → ℝ` has a local extremum on the set `{x | ∀ i, f i x = f i x₀}` at `x₀`. Suppose that all functions `f i` as well as `φ` are strictly differentiable at `x₀`. Then the derivatives `f' i : E → L[ℝ] ℝ` and `φ' : E →L[ℝ] ℝ` are linearly dependent. See also `IsLocalExtrOn.exists_multipliers_of_hasStrictFDerivAt` for a version that that states existence of Lagrange multipliers `Λ` and `Λ₀` instead of using `¬LinearIndependent ℝ _` -/ theorem IsLocalExtrOn.linear_dependent_of_hasStrictFDerivAt {ι : Type*} [Finite ι] {f : ι → E → ℝ} {f' : ι → E →L[ℝ] ℝ} (hextr : IsLocalExtrOn φ {x | ∀ i, f i x = f i x₀} x₀) (hf' : ∀ i, HasStrictFDerivAt (f i) (f' i) x₀) (hφ' : HasStrictFDerivAt φ φ' x₀) : ¬LinearIndependent ℝ (Option.elim' φ' f' : Option ι → E →L[ℝ] ℝ) := by cases nonempty_fintype ι rw [Fintype.linearIndependent_iff]; push_neg rcases hextr.exists_multipliers_of_hasStrictFDerivAt hf' hφ' with ⟹Λ, Λ₀, hΛ, hΛf⟩ refine ⟹Option.elim' Λ₀ Λ, ?_, ?_⟩ · simpa [add_comm] using hΛf · simpa only [Function.funext_iff, not_and_or, or_comm, Option.exists, Prod.mk_eq_zero, Ne, not_forall] using hΛ
Analysis\Calculus\LHopital.lean
/- Copyright (c) 2020 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Analysis.Calculus.Deriv.Inv /-! # L'HÃŽpital's rule for 0/0 indeterminate forms In this file, we prove several forms of "L'HÃŽpital's rule" for computing 0/0 indeterminate forms. The proof of `HasDerivAt.lhopital_zero_right_on_Ioo` is based on the one given in the corresponding [Wikibooks](https://en.wikibooks.org/wiki/Calculus/L%27H%C3%B4pital%27s_Rule) chapter, and all other statements are derived from this one by composing by carefully chosen functions. Note that the filter `f'/g'` tends to isn't required to be one of `𝓝 a`, `atTop` or `atBot`. In fact, we give a slightly stronger statement by allowing it to be any filter on `ℝ`. Each statement is available in a `HasDerivAt` form and a `deriv` form, which is denoted by each statement being in either the `HasDerivAt` or the `deriv` namespace. ## Tags L'HÃŽpital's rule, L'Hopital's rule -/ open Filter Set open scoped Filter Topology Pointwise variable {a b : ℝ} {l : Filter ℝ} {f f' g g' : ℝ → ℝ} /-! ## Interval-based versions We start by proving statements where all conditions (derivability, `g' ≠ 0`) have to be satisfied on an explicitly-provided interval. -/ namespace HasDerivAt theorem lhopital_zero_right_on_Ioo (hab : a < b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by have sub : ∀ x ∈ Ioo a b, Ioo a x ⊆ Ioo a b := fun x hx => Ioo_subset_Ioo (le_refl a) (le_of_lt hx.2) have hg : ∀ x ∈ Ioo a b, g x ≠ 0 := by intro x hx h have : Tendsto g (𝓝[<] x) (𝓝 0) := by rw [← h, ← nhdsWithin_Ioo_eq_nhdsWithin_Iio hx.1] exact ((hgg' x hx).continuousAt.continuousWithinAt.mono <| sub x hx).tendsto obtain ⟹y, hyx, hy⟩ : ∃ c ∈ Ioo a x, g' c = 0 := exists_hasDerivAt_eq_zero' hx.1 hga this fun y hy => hgg' y <| sub x hx hy exact hg' y (sub x hx hyx) hy have : ∀ x ∈ Ioo a b, ∃ c ∈ Ioo a x, f x * g' c = g x * f' c := by intro x hx rw [← sub_zero (f x), ← sub_zero (g x)] exact exists_ratio_hasDerivAt_eq_ratio_slope' g g' hx.1 f f' (fun y hy => hgg' y <| sub x hx hy) (fun y hy => hff' y <| sub x hx hy) hga hfa (tendsto_nhdsWithin_of_tendsto_nhds (hgg' x hx).continuousAt.tendsto) (tendsto_nhdsWithin_of_tendsto_nhds (hff' x hx).continuousAt.tendsto) choose! c hc using this have : ∀ x ∈ Ioo a b, ((fun x' => f' x' / g' x') ∘ c) x = f x / g x := by intro x hx rcases hc x hx with ⟹h₁, h₂⟩ field_simp [hg x hx, hg' (c x) ((sub x hx) h₁)] simp only [h₂] rw [mul_comm] have cmp : ∀ x ∈ Ioo a b, a < c x ∧ c x < x := fun x hx => (hc x hx).1 rw [← nhdsWithin_Ioo_eq_nhdsWithin_Ioi hab] apply tendsto_nhdsWithin_congr this apply hdiv.comp refine tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ (tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (tendsto_nhdsWithin_of_tendsto_nhds tendsto_id) ?_ ?_) ?_ all_goals apply eventually_nhdsWithin_of_forall intro x hx have := cmp x hx try simp linarith [this] theorem lhopital_zero_right_on_Ico (hab : a < b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ico a b)) (hcg : ContinuousOn g (Ico a b)) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfa : f a = 0) (hga : g a = 0) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by refine lhopital_zero_right_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv · rw [← hfa, ← nhdsWithin_Ioo_eq_nhdsWithin_Ioi hab] exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto · rw [← hga, ← nhdsWithin_Ioo_eq_nhdsWithin_Ioi hab] exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto theorem lhopital_zero_left_on_Ioo (hab : a < b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfb : Tendsto f (𝓝[<] b) (𝓝 0)) (hgb : Tendsto g (𝓝[<] b) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by -- Here, we essentially compose by `Neg.neg`. The following is mostly technical details. have hdnf : ∀ x ∈ -Ioo a b, HasDerivAt (f ∘ Neg.neg) (f' (-x) * -1) x := fun x hx => comp x (hff' (-x) hx) (hasDerivAt_neg x) have hdng : ∀ x ∈ -Ioo a b, HasDerivAt (g ∘ Neg.neg) (g' (-x) * -1) x := fun x hx => comp x (hgg' (-x) hx) (hasDerivAt_neg x) rw [preimage_neg_Ioo] at hdnf rw [preimage_neg_Ioo] at hdng have := lhopital_zero_right_on_Ioo (neg_lt_neg hab) hdnf hdng (by intro x hx h apply hg' _ (by rw [← preimage_neg_Ioo] at hx; exact hx) rwa [mul_comm, ← neg_eq_neg_one_mul, neg_eq_zero] at h) (hfb.comp tendsto_neg_nhdsWithin_Ioi_neg) (hgb.comp tendsto_neg_nhdsWithin_Ioi_neg) (by simp only [neg_div_neg_eq, mul_one, mul_neg] exact (tendsto_congr fun x => rfl).mp (hdiv.comp tendsto_neg_nhdsWithin_Ioi_neg)) have := this.comp tendsto_neg_nhdsWithin_Iio unfold Function.comp at this simpa only [neg_neg] theorem lhopital_zero_left_on_Ioc (hab : a < b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ioc a b)) (hcg : ContinuousOn g (Ioc a b)) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfb : f b = 0) (hgb : g b = 0) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by refine lhopital_zero_left_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv · rw [← hfb, ← nhdsWithin_Ioo_eq_nhdsWithin_Iio hab] exact ((hcf b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto · rw [← hgb, ← nhdsWithin_Ioo_eq_nhdsWithin_Iio hab] exact ((hcg b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto theorem lhopital_zero_atTop_on_Ioi (hff' : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Ioi a, g' x ≠ 0) (hftop : Tendsto f atTop (𝓝 0)) (hgtop : Tendsto g atTop (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by obtain ⟹a', haa', ha'⟩ : ∃ a', a < a' ∧ 0 < a' := ⟹1 + max a 0, ⟹lt_of_le_of_lt (le_max_left a 0) (lt_one_add _), lt_of_le_of_lt (le_max_right a 0) (lt_one_add _)⟩⟩ have fact1 : ∀ x : ℝ, x ∈ Ioo 0 a'⁻¹ → x ≠ 0 := fun _ hx => (ne_of_lt hx.1).symm have fact2 : ∀ x ∈ Ioo 0 a'⁻¹, a < x⁻¹ := fun _ hx => lt_trans haa' ((lt_inv ha' hx.1).mpr hx.2) have hdnf : ∀ x ∈ Ioo 0 a'⁻¹, HasDerivAt (f ∘ Inv.inv) (f' x⁻¹ * -(x ^ 2)⁻¹) x := fun x hx => comp x (hff' x⁻¹ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx) have hdng : ∀ x ∈ Ioo 0 a'⁻¹, HasDerivAt (g ∘ Inv.inv) (g' x⁻¹ * -(x ^ 2)⁻¹) x := fun x hx => comp x (hgg' x⁻¹ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx) have := lhopital_zero_right_on_Ioo (inv_pos.mpr ha') hdnf hdng (by intro x hx refine mul_ne_zero ?_ (neg_ne_zero.mpr <| inv_ne_zero <| pow_ne_zero _ <| fact1 x hx) exact hg' _ (fact2 x hx)) (hftop.comp tendsto_inv_zero_atTop) (hgtop.comp tendsto_inv_zero_atTop) (by refine (tendsto_congr' ?_).mp (hdiv.comp tendsto_inv_zero_atTop) rw [eventuallyEq_iff_exists_mem] use Ioi 0, self_mem_nhdsWithin intro x hx unfold Function.comp simp only erw [mul_div_mul_right] exact neg_ne_zero.mpr (inv_ne_zero <| pow_ne_zero _ <| ne_of_gt hx)) have := this.comp tendsto_inv_atTop_zero' unfold Function.comp at this simpa only [inv_inv] theorem lhopital_zero_atBot_on_Iio (hff' : ∀ x ∈ Iio a, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Iio a, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Iio a, g' x ≠ 0) (hfbot : Tendsto f atBot (𝓝 0)) (hgbot : Tendsto g atBot (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) atBot l) : Tendsto (fun x => f x / g x) atBot l := by -- Here, we essentially compose by `Neg.neg`. The following is mostly technical details. have hdnf : ∀ x ∈ -Iio a, HasDerivAt (f ∘ Neg.neg) (f' (-x) * -1) x := fun x hx => comp x (hff' (-x) hx) (hasDerivAt_neg x) have hdng : ∀ x ∈ -Iio a, HasDerivAt (g ∘ Neg.neg) (g' (-x) * -1) x := fun x hx => comp x (hgg' (-x) hx) (hasDerivAt_neg x) rw [preimage_neg_Iio] at hdnf rw [preimage_neg_Iio] at hdng have := lhopital_zero_atTop_on_Ioi hdnf hdng (by intro x hx h apply hg' _ (by rw [← preimage_neg_Iio] at hx; exact hx) rwa [mul_comm, ← neg_eq_neg_one_mul, neg_eq_zero] at h) (hfbot.comp tendsto_neg_atTop_atBot) (hgbot.comp tendsto_neg_atTop_atBot) (by simp only [mul_one, mul_neg, neg_div_neg_eq] exact (tendsto_congr fun x => rfl).mp (hdiv.comp tendsto_neg_atTop_atBot)) have := this.comp tendsto_neg_atBot_atTop unfold Function.comp at this simpa only [neg_neg] end HasDerivAt namespace deriv theorem lhopital_zero_right_on_Ioo (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b)) (hg' : ∀ x ∈ Ioo a b, deriv g x ≠ 0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by have hdf : ∀ x ∈ Ioo a b, DifferentiableAt ℝ f x := fun x hx => (hdf x hx).differentiableAt (Ioo_mem_nhds hx.1 hx.2) have hdg : ∀ x ∈ Ioo a b, DifferentiableAt ℝ g x := fun x hx => by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h) exact HasDerivAt.lhopital_zero_right_on_Ioo hab (fun x hx => (hdf x hx).hasDerivAt) (fun x hx => (hdg x hx).hasDerivAt) hg' hfa hga hdiv theorem lhopital_zero_right_on_Ico (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b)) (hcf : ContinuousOn f (Ico a b)) (hcg : ContinuousOn g (Ico a b)) (hg' : ∀ x ∈ Ioo a b, (deriv g) x ≠ 0) (hfa : f a = 0) (hga : g a = 0) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by refine lhopital_zero_right_on_Ioo hab hdf hg' ?_ ?_ hdiv · rw [← hfa, ← nhdsWithin_Ioo_eq_nhdsWithin_Ioi hab] exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto · rw [← hga, ← nhdsWithin_Ioo_eq_nhdsWithin_Ioi hab] exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto theorem lhopital_zero_left_on_Ioo (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b)) (hg' : ∀ x ∈ Ioo a b, (deriv g) x ≠ 0) (hfb : Tendsto f (𝓝[<] b) (𝓝 0)) (hgb : Tendsto g (𝓝[<] b) (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by have hdf : ∀ x ∈ Ioo a b, DifferentiableAt ℝ f x := fun x hx => (hdf x hx).differentiableAt (Ioo_mem_nhds hx.1 hx.2) have hdg : ∀ x ∈ Ioo a b, DifferentiableAt ℝ g x := fun x hx => by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h) exact HasDerivAt.lhopital_zero_left_on_Ioo hab (fun x hx => (hdf x hx).hasDerivAt) (fun x hx => (hdg x hx).hasDerivAt) hg' hfb hgb hdiv theorem lhopital_zero_atTop_on_Ioi (hdf : DifferentiableOn ℝ f (Ioi a)) (hg' : ∀ x ∈ Ioi a, (deriv g) x ≠ 0) (hftop : Tendsto f atTop (𝓝 0)) (hgtop : Tendsto g atTop (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by have hdf : ∀ x ∈ Ioi a, DifferentiableAt ℝ f x := fun x hx => (hdf x hx).differentiableAt (Ioi_mem_nhds hx) have hdg : ∀ x ∈ Ioi a, DifferentiableAt ℝ g x := fun x hx => by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h) exact HasDerivAt.lhopital_zero_atTop_on_Ioi (fun x hx => (hdf x hx).hasDerivAt) (fun x hx => (hdg x hx).hasDerivAt) hg' hftop hgtop hdiv theorem lhopital_zero_atBot_on_Iio (hdf : DifferentiableOn ℝ f (Iio a)) (hg' : ∀ x ∈ Iio a, (deriv g) x ≠ 0) (hfbot : Tendsto f atBot (𝓝 0)) (hgbot : Tendsto g atBot (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atBot l) : Tendsto (fun x => f x / g x) atBot l := by have hdf : ∀ x ∈ Iio a, DifferentiableAt ℝ f x := fun x hx => (hdf x hx).differentiableAt (Iio_mem_nhds hx) have hdg : ∀ x ∈ Iio a, DifferentiableAt ℝ g x := fun x hx => by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h) exact HasDerivAt.lhopital_zero_atBot_on_Iio (fun x hx => (hdf x hx).hasDerivAt) (fun x hx => (hdg x hx).hasDerivAt) hg' hfbot hgbot hdiv end deriv /-! ## Generic versions The following statements no longer any explicit interval, as they only require conditions holding eventually. -/ namespace HasDerivAt /-- L'HÃŽpital's rule for approaching a real from the right, `HasDerivAt` version -/ theorem lhopital_zero_nhds_right (hff' : ∀ᶠ x in 𝓝[>] a, HasDerivAt f (f' x) x) (hgg' : ∀ᶠ x in 𝓝[>] a, HasDerivAt g (g' x) x) (hg' : ∀ᶠ x in 𝓝[>] a, g' x ≠ 0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by rw [eventually_iff_exists_mem] at * rcases hff' with ⟹s₁, hs₁, hff'⟩ rcases hgg' with ⟹s₂, hs₂, hgg'⟩ rcases hg' with ⟹s₃, hs₃, hg'⟩ let s := s₁ ∩ s₂ ∩ s₃ have hs : s ∈ 𝓝[>] a := inter_mem (inter_mem hs₁ hs₂) hs₃ rw [mem_nhdsWithin_Ioi_iff_exists_Ioo_subset] at hs rcases hs with ⟹u, hau, hu⟩ refine lhopital_zero_right_on_Ioo hau ?_ ?_ ?_ hfa hga hdiv <;> intro x hx <;> apply_assumption <;> first | exact (hu hx).1.1 | exact (hu hx).1.2 | exact (hu hx).2 /-- L'HÃŽpital's rule for approaching a real from the left, `HasDerivAt` version -/ theorem lhopital_zero_nhds_left (hff' : ∀ᶠ x in 𝓝[<] a, HasDerivAt f (f' x) x) (hgg' : ∀ᶠ x in 𝓝[<] a, HasDerivAt g (g' x) x) (hg' : ∀ᶠ x in 𝓝[<] a, g' x ≠ 0) (hfa : Tendsto f (𝓝[<] a) (𝓝 0)) (hga : Tendsto g (𝓝[<] a) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] a) l) : Tendsto (fun x => f x / g x) (𝓝[<] a) l := by rw [eventually_iff_exists_mem] at * rcases hff' with ⟹s₁, hs₁, hff'⟩ rcases hgg' with ⟹s₂, hs₂, hgg'⟩ rcases hg' with ⟹s₃, hs₃, hg'⟩ let s := s₁ ∩ s₂ ∩ s₃ have hs : s ∈ 𝓝[<] a := inter_mem (inter_mem hs₁ hs₂) hs₃ rw [mem_nhdsWithin_Iio_iff_exists_Ioo_subset] at hs rcases hs with ⟹l, hal, hl⟩ refine lhopital_zero_left_on_Ioo hal ?_ ?_ ?_ hfa hga hdiv <;> intro x hx <;> apply_assumption <;> first | exact (hl hx).1.1| exact (hl hx).1.2| exact (hl hx).2 /-- L'HÃŽpital's rule for approaching a real, `HasDerivAt` version. This does not require anything about the situation at `a` -/ theorem lhopital_zero_nhds' (hff' : ∀ᶠ x in 𝓝[≠] a, HasDerivAt f (f' x) x) (hgg' : ∀ᶠ x in 𝓝[≠] a, HasDerivAt g (g' x) x) (hg' : ∀ᶠ x in 𝓝[≠] a, g' x ≠ 0) (hfa : Tendsto f (𝓝[≠] a) (𝓝 0)) (hga : Tendsto g (𝓝[≠] a) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[≠] a) l) : Tendsto (fun x => f x / g x) (𝓝[≠] a) l := by simp only [← Iio_union_Ioi, nhdsWithin_union, tendsto_sup, eventually_sup] at * exact ⟹lhopital_zero_nhds_left hff'.1 hgg'.1 hg'.1 hfa.1 hga.1 hdiv.1, lhopital_zero_nhds_right hff'.2 hgg'.2 hg'.2 hfa.2 hga.2 hdiv.2⟩ /-- **L'HÃŽpital's rule** for approaching a real, `HasDerivAt` version -/ theorem lhopital_zero_nhds (hff' : ∀ᶠ x in 𝓝 a, HasDerivAt f (f' x) x) (hgg' : ∀ᶠ x in 𝓝 a, HasDerivAt g (g' x) x) (hg' : ∀ᶠ x in 𝓝 a, g' x ≠ 0) (hfa : Tendsto f (𝓝 a) (𝓝 0)) (hga : Tendsto g (𝓝 a) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝 a) l) : Tendsto (fun x => f x / g x) (𝓝[≠] a) l := by apply @lhopital_zero_nhds' _ _ _ f' _ g' <;> (first | apply eventually_nhdsWithin_of_eventually_nhds | apply tendsto_nhdsWithin_of_tendsto_nhds) <;> assumption /-- L'HÃŽpital's rule for approaching +∞, `HasDerivAt` version -/ theorem lhopital_zero_atTop (hff' : ∀ᶠ x in atTop, HasDerivAt f (f' x) x) (hgg' : ∀ᶠ x in atTop, HasDerivAt g (g' x) x) (hg' : ∀ᶠ x in atTop, g' x ≠ 0) (hftop : Tendsto f atTop (𝓝 0)) (hgtop : Tendsto g atTop (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by rw [eventually_iff_exists_mem] at * rcases hff' with ⟹s₁, hs₁, hff'⟩ rcases hgg' with ⟹s₂, hs₂, hgg'⟩ rcases hg' with ⟹s₃, hs₃, hg'⟩ let s := s₁ ∩ s₂ ∩ s₃ have hs : s ∈ atTop := inter_mem (inter_mem hs₁ hs₂) hs₃ rw [mem_atTop_sets] at hs rcases hs with ⟹l, hl⟩ have hl' : Ioi l ⊆ s := fun x hx => hl x (le_of_lt hx) refine lhopital_zero_atTop_on_Ioi ?_ ?_ (fun x hx => hg' x <| (hl' hx).2) hftop hgtop hdiv <;> intro x hx <;> apply_assumption <;> first | exact (hl' hx).1.1| exact (hl' hx).1.2 /-- L'HÃŽpital's rule for approaching -∞, `HasDerivAt` version -/ theorem lhopital_zero_atBot (hff' : ∀ᶠ x in atBot, HasDerivAt f (f' x) x) (hgg' : ∀ᶠ x in atBot, HasDerivAt g (g' x) x) (hg' : ∀ᶠ x in atBot, g' x ≠ 0) (hfbot : Tendsto f atBot (𝓝 0)) (hgbot : Tendsto g atBot (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) atBot l) : Tendsto (fun x => f x / g x) atBot l := by rw [eventually_iff_exists_mem] at * rcases hff' with ⟹s₁, hs₁, hff'⟩ rcases hgg' with ⟹s₂, hs₂, hgg'⟩ rcases hg' with ⟹s₃, hs₃, hg'⟩ let s := s₁ ∩ s₂ ∩ s₃ have hs : s ∈ atBot := inter_mem (inter_mem hs₁ hs₂) hs₃ rw [mem_atBot_sets] at hs rcases hs with ⟹l, hl⟩ have hl' : Iio l ⊆ s := fun x hx => hl x (le_of_lt hx) refine lhopital_zero_atBot_on_Iio ?_ ?_ (fun x hx => hg' x <| (hl' hx).2) hfbot hgbot hdiv <;> intro x hx <;> apply_assumption <;> first | exact (hl' hx).1.1| exact (hl' hx).1.2 end HasDerivAt namespace deriv /-- **L'HÃŽpital's rule** for approaching a real from the right, `deriv` version -/ theorem lhopital_zero_nhds_right (hdf : ∀ᶠ x in 𝓝[>] a, DifferentiableAt ℝ f x) (hg' : ∀ᶠ x in 𝓝[>] a, deriv g x ≠ 0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by have hdg : ∀ᶠ x in 𝓝[>] a, DifferentiableAt ℝ g x := hg'.mp (eventually_of_forall fun _ hg' => by_contradiction fun h => hg' (deriv_zero_of_not_differentiableAt h)) have hdf' : ∀ᶠ x in 𝓝[>] a, HasDerivAt f (deriv f x) x := hdf.mp (eventually_of_forall fun _ => DifferentiableAt.hasDerivAt) have hdg' : ∀ᶠ x in 𝓝[>] a, HasDerivAt g (deriv g x) x := hdg.mp (eventually_of_forall fun _ => DifferentiableAt.hasDerivAt) exact HasDerivAt.lhopital_zero_nhds_right hdf' hdg' hg' hfa hga hdiv /-- **L'HÃŽpital's rule** for approaching a real from the left, `deriv` version -/ theorem lhopital_zero_nhds_left (hdf : ∀ᶠ x in 𝓝[<] a, DifferentiableAt ℝ f x) (hg' : ∀ᶠ x in 𝓝[<] a, deriv g x ≠ 0) (hfa : Tendsto f (𝓝[<] a) (𝓝 0)) (hga : Tendsto g (𝓝[<] a) (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[<] a) l) : Tendsto (fun x => f x / g x) (𝓝[<] a) l := by have hdg : ∀ᶠ x in 𝓝[<] a, DifferentiableAt ℝ g x := hg'.mp (eventually_of_forall fun _ hg' => by_contradiction fun h => hg' (deriv_zero_of_not_differentiableAt h)) have hdf' : ∀ᶠ x in 𝓝[<] a, HasDerivAt f (deriv f x) x := hdf.mp (eventually_of_forall fun _ => DifferentiableAt.hasDerivAt) have hdg' : ∀ᶠ x in 𝓝[<] a, HasDerivAt g (deriv g x) x := hdg.mp (eventually_of_forall fun _ => DifferentiableAt.hasDerivAt) exact HasDerivAt.lhopital_zero_nhds_left hdf' hdg' hg' hfa hga hdiv /-- **L'HÃŽpital's rule** for approaching a real, `deriv` version. This does not require anything about the situation at `a` -/ theorem lhopital_zero_nhds' (hdf : ∀ᶠ x in 𝓝[≠] a, DifferentiableAt ℝ f x) (hg' : ∀ᶠ x in 𝓝[≠] a, deriv g x ≠ 0) (hfa : Tendsto f (𝓝[≠] a) (𝓝 0)) (hga : Tendsto g (𝓝[≠] a) (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[≠] a) l) : Tendsto (fun x => f x / g x) (𝓝[≠] a) l := by simp only [← Iio_union_Ioi, nhdsWithin_union, tendsto_sup, eventually_sup] at * exact ⟹lhopital_zero_nhds_left hdf.1 hg'.1 hfa.1 hga.1 hdiv.1, lhopital_zero_nhds_right hdf.2 hg'.2 hfa.2 hga.2 hdiv.2⟩ /-- **L'HÃŽpital's rule** for approaching a real, `deriv` version -/ theorem lhopital_zero_nhds (hdf : ∀ᶠ x in 𝓝 a, DifferentiableAt ℝ f x) (hg' : ∀ᶠ x in 𝓝 a, deriv g x ≠ 0) (hfa : Tendsto f (𝓝 a) (𝓝 0)) (hga : Tendsto g (𝓝 a) (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝 a) l) : Tendsto (fun x => f x / g x) (𝓝[≠] a) l := by apply lhopital_zero_nhds' <;> (first | apply eventually_nhdsWithin_of_eventually_nhds | apply tendsto_nhdsWithin_of_tendsto_nhds) <;> assumption /-- **L'HÃŽpital's rule** for approaching +∞, `deriv` version -/ theorem lhopital_zero_atTop (hdf : ∀ᶠ x : ℝ in atTop, DifferentiableAt ℝ f x) (hg' : ∀ᶠ x : ℝ in atTop, deriv g x ≠ 0) (hftop : Tendsto f atTop (𝓝 0)) (hgtop : Tendsto g atTop (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by have hdg : ∀ᶠ x in atTop, DifferentiableAt ℝ g x := hg'.mp (eventually_of_forall fun _ hg' => by_contradiction fun h => hg' (deriv_zero_of_not_differentiableAt h)) have hdf' : ∀ᶠ x in atTop, HasDerivAt f (deriv f x) x := hdf.mp (eventually_of_forall fun _ => DifferentiableAt.hasDerivAt) have hdg' : ∀ᶠ x in atTop, HasDerivAt g (deriv g x) x := hdg.mp (eventually_of_forall fun _ => DifferentiableAt.hasDerivAt) exact HasDerivAt.lhopital_zero_atTop hdf' hdg' hg' hftop hgtop hdiv /-- **L'HÃŽpital's rule** for approaching -∞, `deriv` version -/ theorem lhopital_zero_atBot (hdf : ∀ᶠ x : ℝ in atBot, DifferentiableAt ℝ f x) (hg' : ∀ᶠ x : ℝ in atBot, deriv g x ≠ 0) (hfbot : Tendsto f atBot (𝓝 0)) (hgbot : Tendsto g atBot (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atBot l) : Tendsto (fun x => f x / g x) atBot l := by have hdg : ∀ᶠ x in atBot, DifferentiableAt ℝ g x := hg'.mp (eventually_of_forall fun _ hg' => by_contradiction fun h => hg' (deriv_zero_of_not_differentiableAt h)) have hdf' : ∀ᶠ x in atBot, HasDerivAt f (deriv f x) x := hdf.mp (eventually_of_forall fun _ => DifferentiableAt.hasDerivAt) have hdg' : ∀ᶠ x in atBot, HasDerivAt g (deriv g x) x := hdg.mp (eventually_of_forall fun _ => DifferentiableAt.hasDerivAt) exact HasDerivAt.lhopital_zero_atBot hdf' hdg' hg' hfbot hgbot hdiv end deriv
Analysis\Calculus\LogDeriv.lean
/- Copyright (c) 2024 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Analysis.Calculus.Deriv.ZPow /-! # Logarithmic Derivatives We define the logarithmic derivative of a function f as `deriv f / f`. We then prove some basic facts about this, including how it changes under multiplication and composition. -/ noncomputable section open Filter Function open scoped Topology BigOperators Classical variable {𝕜 𝕜': Type*} [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] /-- The logarithmic derivative of a function defined as `deriv f /f`. Note that it will be zero at `x` if `f` is not DifferentiableAt `x`. -/ def logDeriv (f : 𝕜 → 𝕜') := deriv f / f theorem logDeriv_apply (f : 𝕜 → 𝕜') (x : 𝕜) : logDeriv f x = deriv f x / f x := rfl lemma logDeriv_eq_zero_of_not_differentiableAt (f : 𝕜 → 𝕜') (x : 𝕜) (h : ¬DifferentiableAt 𝕜 f x) : logDeriv f x = 0 := by simp only [logDeriv_apply, deriv_zero_of_not_differentiableAt h, zero_div] @[simp] theorem logDeriv_id (x : 𝕜) : logDeriv id x = 1 / x := by simp [logDeriv_apply] @[simp] theorem logDeriv_id' (x : 𝕜) : logDeriv (·) x = 1 / x := logDeriv_id x @[simp] theorem logDeriv_const (a : 𝕜') : logDeriv (fun _ : 𝕜 ↩ a) = 0 := by ext simp [logDeriv_apply] theorem logDeriv_mul {f g : 𝕜 → 𝕜'} (x : 𝕜) (hf : f x ≠ 0) (hg : g x ≠ 0) (hdf : DifferentiableAt 𝕜 f x) (hdg : DifferentiableAt 𝕜 g x) : logDeriv (fun z => f z * g z) x = logDeriv f x + logDeriv g x := by simp only [logDeriv_apply, deriv_mul hdf hdg] field_simp [mul_comm] theorem logDeriv_mul_const {f : 𝕜 → 𝕜'} (x : 𝕜) (a : 𝕜') (ha : a ≠ 0): logDeriv (fun z => f z * a) x = logDeriv f x := by simp only [logDeriv_apply, deriv_mul_const_field, mul_div_mul_right _ _ ha] theorem logDeriv_const_mul {f : 𝕜 → 𝕜'} (x : 𝕜) (a : 𝕜') (ha : a ≠ 0): logDeriv (fun z => a * f z) x = logDeriv f x := by simp only [logDeriv_apply, deriv_const_mul_field, mul_div_mul_left _ _ ha] /-- The logarithmic derivative of a finite product is the sum of the logarithmic derivatives. -/ theorem logDeriv_prod {ι : Type*} (s : Finset ι) (f : ι → 𝕜 → 𝕜') (x : 𝕜) (hf : ∀ i ∈ s, f i x ≠ 0) (hd : ∀ i ∈ s, DifferentiableAt 𝕜 (f i) x) : logDeriv (∏ i ∈ s, f i ·) x = ∑ i ∈ s, logDeriv (f i) x := by induction s using Finset.cons_induction with | empty => simp | cons a s ha ih => rw [Finset.forall_mem_cons] at hf hd simp_rw [Finset.prod_cons, Finset.sum_cons] rw [logDeriv_mul, ih hf.2 hd.2] · exact hf.1 · simpa [Finset.prod_eq_zero_iff] using hf.2 · exact hd.1 · exact .finset_prod hd.2 lemma logDeriv_fun_zpow {f : 𝕜 → 𝕜'} {x : 𝕜} (hdf : DifferentiableAt 𝕜 f x) (n : â„€) : logDeriv (f · ^ n) x = n * logDeriv f x := by rcases eq_or_ne n 0 with rfl | hn; · simp rcases eq_or_ne (f x) 0 with hf | hf · simp [logDeriv_apply, zero_zpow, *] · rw [logDeriv_apply, ← comp_def (·^n), deriv.comp _ (differentiableAt_zpow.2 <| .inl hf) hdf, deriv_zpow, logDeriv_apply] field_simp [zpow_ne_zero, zpow_sub_one₀ hf] ring lemma logDeriv_fun_pow {f : 𝕜 → 𝕜'} {x : 𝕜} (hdf : DifferentiableAt 𝕜 f x) (n : ℕ) : logDeriv (f · ^ n) x = n * logDeriv f x := mod_cast logDeriv_fun_zpow hdf n @[simp] lemma logDeriv_zpow (x : 𝕜) (n : â„€) : logDeriv (· ^ n) x = n / x := by rw [logDeriv_fun_zpow (by fun_prop), logDeriv_id', mul_one_div] @[simp] lemma logDeriv_pow (x : 𝕜) (n : ℕ) : logDeriv (· ^ n) x = n / x := mod_cast logDeriv_zpow x n @[simp] lemma logDeriv_inv (x : 𝕜) : logDeriv (·⁻¹) x = -1 / x := by simpa using logDeriv_zpow x (-1) theorem logDeriv_comp {f : 𝕜' → 𝕜'} {g : 𝕜 → 𝕜'} {x : 𝕜} (hf : DifferentiableAt 𝕜' f (g x)) (hg : DifferentiableAt 𝕜 g x) : logDeriv (f ∘ g) x = logDeriv f (g x) * deriv g x := by simp only [logDeriv, Pi.div_apply, deriv.comp _ hf hg, comp_apply] ring
Analysis\Calculus\MeanValue.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Normed import Mathlib.Analysis.RCLike.Basic /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `RCLike`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `‖f x‖ ≀ B x` from upper estimates on `f'` or `‖f'‖`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `‖f x‖ = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `‖f x - f a‖ ≀ C * ‖x - a‖`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `∀ x, C (</≀/>/≥) (f' x)`, then `C * (y - x) (</≀/>/≥) (f y - f x)` whenever `x < y`. * `monotoneOn_of_deriv_nonneg`, `antitoneOn_of_deriv_nonpos`, `strictMono_of_deriv_pos`, `strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) {B B' : ℝ → ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⊃x⩄, x ∈ Icc a b → f x ≀ B x := by change Icc a b ⊆ { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [s, inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟹hxB : f x ≀ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB · -- If `f x < B x`, then all we need is continuity of both sides refine nonempty_of_mem (inter_mem ?_ (Ioc_mem_nhdsWithin_Ioi ⟹le_rfl, hy⟩)) have : ∀ᶠ x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : ∀ᶠ x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt · rcases exists_between (bound x xab hxB) with ⟹r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : ∀ᶠ z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟹z, hfz, hzB, hz⟩ : ∃ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y := (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟹le_rfl, hy⟩))).exists refine ⟹z, ?_, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) {B B' : ℝ → ℝ} (ha : f a ≀ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⊃x⩄, x ∈ Icc a b → f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ → ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : ∀ x ∈ Ico a b, ∀ r, B' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) : ∀ ⊃x⩄, x ∈ Icc a b → f x ≀ B x := by have Hr : ∀ x ∈ Icc a b, ∀ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound · rwa [sub_self, mul_zero, add_zero] · exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) · intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) · intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⊃x⩄, x ∈ Icc a b → f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : f a ≀ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⊃x⩄, x ∈ Icc a b → f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, f' x ≀ B' x) : ∀ ⊃x⩄, x ∈ Icc a b → f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) /-! ### Vector-valued functions `f : ℝ → E` -/ section variable {f : ℝ → E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(‖f z‖ - ‖f x‖) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `‖f x‖ = B x`. Then `‖f x‖ ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ → E} {f' : ℝ → ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (‖f z‖ - ‖f x‖) / (z - x) ≀ f' x` (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → f' x < B' x) : ∀ ⊃x⩄, x ∈ Icc a b → ‖f x‖ ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `‖f x‖ = B x`. Then `‖f x‖ ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → ‖f' x‖ < B' x) : ∀ ⊃x⩄, x ∈ Icc a b → ‖f x‖ ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `‖f x‖ = B x`. Then `‖f x‖ ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≀ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → ‖f' x‖ < B' x) : ∀ ⊃x⩄, x ∈ Icc a b → ‖f x‖ ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `‖f' x‖ ≀ B x` everywhere on `[a, b)`. Then `‖f x‖ ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≀ B' x) : ∀ ⊃x⩄, x ∈ Icc a b → ‖f x‖ ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `‖f' x‖ ≀ B x` everywhere on `[a, b)`. Then `‖f x‖ ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≀ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≀ B' x) : ∀ ⊃x⩄, x ∈ Icc a b → ‖f x‖ ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `‖f x - f a‖ ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ → E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≀ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : ∀ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : ∀ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only [g, B]; rw [sub_self, norm_zero, sub_self, mul_zero] /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `‖f x - f a‖ ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ → E} {C : ℝ} (hf : ∀ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≀ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≀ C * (x - a) := by refine norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => ?_) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `‖f x - f a‖ ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : ∀ x ∈ Ico a b, ‖derivWithin f (Icc a b) x‖ ≀ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≀ C * (x - a) := by refine norm_image_sub_le_of_norm_deriv_le_segment' ?_ bound exact fun x hx => (hf x hx).hasDerivWithinAt /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `‖f 1 - f 0‖ ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ → E} {C : ℝ} (hf : ∀ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : ∀ x ∈ Ico (0 : ℝ) 1, ‖f' x‖ ≀ C) : ‖f 1 - f 0‖ ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `‖f 1 - f 0‖ ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : ∀ x ∈ Ico (0 : ℝ) 1, ‖derivWithin f (Icc (0 : ℝ) 1) x‖ ≀ C) : ‖f 1 - f 0‖ ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : ∀ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : ∀ x ∈ Icc a b, f x = f a := by have : ∀ x ∈ Icc a b, ‖f x - f a‖ ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : ∀ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : ∀ x ∈ Icc a b, f x = f a := by have H : ∀ x ∈ Ico a b, ‖derivWithin f (Icc a b) x‖ ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx variable {f' g : ℝ → E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : ∀ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : ∀ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊢ exact hi ▾ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : ∀ y ∈ Icc a b, f y = g y := by have A : ∀ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : ∀ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm ▾ B y hy) fdiff.continuousOn gdiff.continuousOn hi end /-! ### Vector-valued functions `f : E → G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[RCLike 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section variable {𝕜 G : Type*} [RCLike 𝕜] [NormedSpace 𝕜 E] [NormedAddCommGroup G] [NormedSpace 𝕜 G] namespace Convex variable {f g : E → G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E → E →L[𝕜] G} {φ : E →L[𝕜] G} /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x‖ ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≀ C * ‖y - x‖ := by letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ 𝕜 G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ → E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : ∀ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : ∀ t ∈ Ico (0 : ℝ) 1, ‖f' (g t) (y - x)‖ ≀ C * ‖y - x‖ := fun t ht => le_of_opNorm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa [g] using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝ≥0} (hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x‖₊ ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E → G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝ≥0` larger than `‖f' x‖₊`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E → G} (hder : ∀ᶠ y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝ≥0) (hK : ‖f' x‖₊ < K) : ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟚ε, ε0, hε⟩ : ∃ ε > 0, ball x ε ∩ s ⊆ { y | HasFDerivWithinAt f (f' y) s y ∧ ‖f' y‖₊ < K } := mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hε refine ⟹s ∩ ball x ε, inter_mem_nhdsWithin _ (ball_mem_nhds _ ε0), ?_⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hε hy).1.mono inter_subset_left) fun y hy => (hε hy).2.le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E → G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝ≥0` larger than `‖f' x‖₊`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E → G} (hder : ∀ᶠ y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : ∃ K, ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn 𝕜 f s) (bound : ∀ x ∈ s, ‖fderivWithin 𝕜 f s x‖ ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≀ C * ‖y - x‖ := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝ≥0} (hf : DifferentiableOn 𝕜 f s) (bound : ∀ x ∈ s, ‖fderivWithin 𝕜 f s x‖₊ ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x) (bound : ∀ x ∈ s, ‖fderiv 𝕜 f x‖ ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≀ C * ‖y - x‖ := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝ≥0} (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x) (bound : ∀ x ∈ s, ‖fderiv 𝕜 f x‖₊ ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {f : E → G} {C : ℝ≥0} (hf : Differentiable 𝕜 f) (bound : ∀ x, ‖fderiv 𝕜 f x‖₊ ≀ C) : LipschitzWith C f := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ 𝕜 E rw [← lipschitzOnWith_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↩ hf x) (fun x _ ↩ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x - φ‖ ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x - φ (y - x)‖ ≀ C * ‖y - x‖ := by /- We subtract `φ` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - φ y have hg : ∀ x ∈ s, HasFDerivWithinAt g (f' x - φ) s x := fun x xs => (hf x xs).sub φ.hasFDerivWithinAt calc ‖f y - f x - φ (y - x)‖ = ‖f y - f x - (φ y - φ x)‖ := by simp _ = ‖f y - φ y - (f x - φ x)‖ := by congr 1; abel _ = ‖g y - g x‖ := by simp _ ≀ C * ‖y - x‖ := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn 𝕜 f s) (bound : ∀ x ∈ s, ‖fderivWithin 𝕜 f s x - φ‖ ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x - φ (y - x)‖ ≀ C * ‖y - x‖ := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x) (bound : ∀ x ∈ s, ‖fderiv 𝕜 f x - φ‖ ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x - φ (y - x)‖ ≀ C * ‖y - x‖ := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys /-- If a function has zero Fréchet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn 𝕜 f s) (hf' : ∀ x ∈ s, fderivWithin 𝕜 f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : ∀ x ∈ s, ‖fderivWithin 𝕜 f s x‖ ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {f : E → G} (hf : Differentiable 𝕜 f) (hf' : ∀ x, fderiv 𝕜 f x = 0) (x y : E) : f x = f y := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ 𝕜 E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial /-- If two functions have equal Fréchet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) (hs' : UniqueDiffOn 𝕜 s) (hf' : ∀ x ∈ s, fderivWithin 𝕜 f s x = fderivWithin 𝕜 g s x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => ?_) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' _ hz] theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {f g : E → G} (hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g) (hf' : ∀ x, fderiv 𝕜 f x = fderiv 𝕜 g x) (x : E) (hfgx : f x = g x) : f = g := by let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ 𝕜 E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx end Convex namespace Convex variable {f f' : 𝕜 → G} {s : Set 𝕜} {x y : 𝕜} /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasDerivWithin_le {C : ℝ} (hf : ∀ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x‖ ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≀ C * ‖y - x‖ := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs xs ys /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasDerivWithin_le {C : ℝ≥0} (hs : Convex ℝ s) (hf : ∀ x ∈ s, HasDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x‖₊ ≀ C) : LipschitzOnWith C f s := Convex.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) (fun x hx => le_trans (by simp) (bound x hx)) hs /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `derivWithin` -/ theorem norm_image_sub_le_of_norm_derivWithin_le {C : ℝ} (hf : DifferentiableOn 𝕜 f s) (bound : ∀ x ∈ s, ‖derivWithin f s x‖ ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≀ C * ‖y - x‖ := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `derivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_derivWithin_le {C : ℝ≥0} (hs : Convex ℝ s) (hf : DifferentiableOn 𝕜 f s) (bound : ∀ x ∈ s, ‖derivWithin f s x‖₊ ≀ C) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivWithinAt) bound /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/ theorem norm_image_sub_le_of_norm_deriv_le {C : ℝ} (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x) (bound : ∀ x ∈ s, ‖deriv f x‖ ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≀ C * ‖y - x‖ := hs.norm_image_sub_le_of_norm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `deriv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_deriv_le {C : ℝ≥0} (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x) (bound : ∀ x ∈ s, ‖deriv f x‖₊ ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x hx => (hf x hx).hasDerivAt.hasDerivWithinAt) bound /-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_deriv_le {C : ℝ≥0} (hf : Differentiable 𝕜 f) (bound : ∀ x, ‖deriv f x‖₊ ≀ C) : LipschitzWith C f := lipschitzOnWith_univ.1 <| convex_univ.lipschitzOnWith_of_nnnorm_deriv_le (fun x _ => hf x) fun x _ => bound x /-- If `f : 𝕜 → G`, `𝕜 = R` or `𝕜 = ℂ`, is differentiable everywhere and its derivative equal zero, then it is a constant function. -/ theorem _root_.is_const_of_deriv_eq_zero (hf : Differentiable 𝕜 f) (hf' : ∀ x, deriv f x = 0) (x y : 𝕜) : f x = f y := is_const_of_fderiv_eq_zero hf (fun z => by ext; simp [← deriv_fderiv, hf']) _ _ end Convex end /-! ### Functions `[a, b] → ℝ`. -/ section Interval -- Declare all variables here to make sure they come in a correct order variable (f f' : ℝ → ℝ) {a b : ℝ} (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hfd : DifferentiableOn ℝ f (Ioo a b)) (g g' : ℝ → ℝ) (hgc : ContinuousOn g (Icc a b)) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hgd : DifferentiableOn ℝ g (Ioo a b)) /-- Cauchy's **Mean Value Theorem**, `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope : ∃ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c := by let h x := (g b - g a) * f x - (f b - f a) * g x have hI : h a = h b := by simp only [h]; ring let h' x := (g b - g a) * f' x - (f b - f a) * g' x have hhh' : ∀ x ∈ Ioo a b, HasDerivAt h (h' x) x := fun x hx => ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)) have hhc : ContinuousOn h (Icc a b) := (continuousOn_const.mul hfc).sub (continuousOn_const.mul hgc) rcases exists_hasDerivAt_eq_zero hab hhc hI hhh' with ⟹c, cmem, hc⟩ exact ⟹c, cmem, sub_eq_zero.1 hc⟩ /-- Cauchy's **Mean Value Theorem**, extended `HasDerivAt` version. -/ theorem exists_ratio_hasDerivAt_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : ∃ c ∈ Ioo a b, (lgb - lga) * f' c = (lfb - lfa) * g' c := by let h x := (lgb - lga) * f x - (lfb - lfa) * g x have hha : Tendsto h (𝓝[>] a) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[>] a) (𝓝 <| (lgb - lga) * lfa - (lfb - lfa) * lga) := (tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga) convert this using 2 ring have hhb : Tendsto h (𝓝[<] b) (𝓝 <| lgb * lfa - lfb * lga) := by have : Tendsto h (𝓝[<] b) (𝓝 <| (lgb - lga) * lfb - (lfb - lfa) * lgb) := (tendsto_const_nhds.mul hfb).sub (tendsto_const_nhds.mul hgb) convert this using 2 ring let h' x := (lgb - lga) * f' x - (lfb - lfa) * g' x have hhh' : ∀ x ∈ Ioo a b, HasDerivAt h (h' x) x := by intro x hx exact ((hff' x hx).const_mul _).sub ((hgg' x hx).const_mul _) rcases exists_hasDerivAt_eq_zero' hab hha hhb hhh' with ⟹c, cmem, hc⟩ exact ⟹c, cmem, sub_eq_zero.1 hc⟩ /-- Lagrange's Mean Value Theorem, `HasDerivAt` version -/ theorem exists_hasDerivAt_eq_slope : ∃ c ∈ Ioo a b, f' c = (f b - f a) / (b - a) := by obtain ⟹c, cmem, hc⟩ : ∃ c ∈ Ioo a b, (b - a) * f' c = (f b - f a) * 1 := exists_ratio_hasDerivAt_eq_ratio_slope f f' hab hfc hff' id 1 continuousOn_id fun x _ => hasDerivAt_id x use c, cmem rwa [mul_one, mul_comm, ← eq_div_iff (sub_ne_zero.2 hab.ne')] at hc /-- Cauchy's Mean Value Theorem, `deriv` version. -/ theorem exists_ratio_deriv_eq_ratio_slope : ∃ c ∈ Ioo a b, (g b - g a) * deriv f c = (f b - f a) * deriv g c := exists_ratio_hasDerivAt_eq_ratio_slope f (deriv f) hab hfc (fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt) g (deriv g) hgc fun x hx => ((hgd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt /-- Cauchy's Mean Value Theorem, extended `deriv` version. -/ theorem exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : ℝ} (hdf : DifferentiableOn ℝ f <| Ioo a b) (hdg : DifferentiableOn ℝ g <| Ioo a b) (hfa : Tendsto f (𝓝[>] a) (𝓝 lfa)) (hga : Tendsto g (𝓝[>] a) (𝓝 lga)) (hfb : Tendsto f (𝓝[<] b) (𝓝 lfb)) (hgb : Tendsto g (𝓝[<] b) (𝓝 lgb)) : ∃ c ∈ Ioo a b, (lgb - lga) * deriv f c = (lfb - lfa) * deriv g c := exists_ratio_hasDerivAt_eq_ratio_slope' _ _ hab _ _ (fun x hx => ((hdf x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) (fun x hx => ((hdg x hx).differentiableAt <| Ioo_mem_nhds hx.1 hx.2).hasDerivAt) hfa hga hfb hgb /-- Lagrange's **Mean Value Theorem**, `deriv` version. -/ theorem exists_deriv_eq_slope : ∃ c ∈ Ioo a b, deriv f c = (f b - f a) / (b - a) := exists_hasDerivAt_eq_slope f (deriv f) hab hfc fun x hx => ((hfd x hx).differentiableAt <| IsOpen.mem_nhds isOpen_Ioo hx).hasDerivAt /-- Lagrange's **Mean Value Theorem**, `deriv` version. -/ theorem exists_deriv_eq_slope' : ∃ c ∈ Ioo a b, deriv f c = slope f a b := by rw [slope_def_field] exact exists_deriv_eq_slope f hab hfc hfd /-- A real function whose derivative tends to infinity from the right at a point is not differentiable on the right at that point -/ theorem not_differentiableWithinAt_of_deriv_tendsto_atTop_Ioi (f : ℝ → ℝ) {a : ℝ} (hf : Tendsto (deriv f) (𝓝[>] a) atTop) : ¬ DifferentiableWithinAt ℝ f (Ioi a) a := by replace hf : Tendsto (derivWithin f (Ioi a)) (𝓝[>] a) atTop := by refine hf.congr' ?_ filter_upwards [eventually_mem_nhdsWithin] with x hx have : Ioi a ∈ 𝓝 x := by simp [← mem_interior_iff_mem_nhds, hx] exact (derivWithin_of_mem_nhds this).symm by_cases hcont_at_a : ContinuousWithinAt f (Ici a) a case neg => intro hcontra have := hcontra.continuousWithinAt rw [← ContinuousWithinAt.diff_iff this] at hcont_at_a simp at hcont_at_a case pos => intro hdiff replace hdiff := hdiff.hasDerivWithinAt rw [hasDerivWithinAt_iff_tendsto_slope, Set.diff_singleton_eq_self not_mem_Ioi_self] at hdiff have h₀ : ∀ᶠ b in 𝓝[>] a, ∀ x ∈ Ioc a b, max (derivWithin f (Ioi a) a + 1) 0 < derivWithin f (Ioi a) x := by rw [(nhdsWithin_Ioi_basis a).eventually_iff] rw [(nhdsWithin_Ioi_basis a).tendsto_left_iff] at hf obtain ⟹b, hab, hb⟩ := hf (Ioi (max (derivWithin f (Ioi a) a + 1) 0)) (Ioi_mem_atTop _) refine ⟹b, hab, fun x hx z hz => ?_⟩ simp only [MapsTo, mem_Ioo, mem_Ioi, and_imp] at hb exact hb hz.1 <| hz.2.trans_lt hx.2 have h₁ : ∀ᶠ b in 𝓝[>] a, slope f a b < derivWithin f (Ioi a) a + 1 := by rw [(nhds_basis_Ioo _).tendsto_right_iff] at hdiff specialize hdiff ⟹derivWithin f (Ioi a) a - 1, derivWithin f (Ioi a) a + 1⟩ <| by simp filter_upwards [hdiff] with z hz using hz.2 have hcontra : ∀ᶠ _ in 𝓝[>] a, False := by filter_upwards [h₀, h₁, eventually_mem_nhdsWithin] with b hb hslope (hab : a < b) have hdiff' : DifferentiableOn ℝ f (Ioc a b) := fun z hz => by refine DifferentiableWithinAt.mono (t := Ioi a) ?_ Ioc_subset_Ioi_self have : derivWithin f (Ioi a) z ≠ 0 := ne_of_gt <| by simp_all only [mem_Ioo, and_imp, mem_Ioc, max_lt_iff] exact differentiableWithinAt_of_derivWithin_ne_zero this have hcont_Ioc : ∀ z ∈ Ioc a b, ContinuousWithinAt f (Icc a b) z := by intro z hz'' refine (hdiff'.continuousOn z hz'').mono_of_mem ?_ have hfinal : 𝓝[Ioc a b] z = 𝓝[Icc a b] z := by refine nhdsWithin_eq_nhdsWithin' (s := Ioi a) (Ioi_mem_nhds hz''.1) ?_ simp only [Ioc_inter_Ioi, le_refl, sup_of_le_left] ext y exact ⟹fun h => ⟹mem_Icc_of_Ioc h, mem_of_mem_inter_left h⟩, fun ⟹H1, H2⟩ => ⟹H2, H1.2⟩⟩ rw [← hfinal] exact self_mem_nhdsWithin have hcont : ContinuousOn f (Icc a b) := by intro z hz by_cases hz' : z = a · rw [hz'] exact hcont_at_a.mono Icc_subset_Ici_self · exact hcont_Ioc z ⟹lt_of_le_of_ne hz.1 (Ne.symm hz'), hz.2⟩ obtain ⟹x, hx₁, hx₂⟩ := exists_deriv_eq_slope' f hab hcont (hdiff'.mono (Ioo_subset_Ioc_self)) specialize hb x ⟹hx₁.1, le_of_lt hx₁.2⟩ replace hx₂ : derivWithin f (Ioi a) x = slope f a b := by have : Ioi a ∈ 𝓝 x := by simp [← mem_interior_iff_mem_nhds, hx₁.1] rwa [derivWithin_of_mem_nhds this] rw [hx₂, max_lt_iff] at hb linarith simp [Filter.eventually_false_iff_eq_bot, ← not_mem_closure_iff_nhdsWithin_eq_bot] at hcontra /-- A real function whose derivative tends to minus infinity from the right at a point is not differentiable on the right at that point -/ theorem not_differentiableWithinAt_of_deriv_tendsto_atBot_Ioi (f : ℝ → ℝ) {a : ℝ} (hf : Tendsto (deriv f) (𝓝[>] a) atBot) : ¬ DifferentiableWithinAt ℝ f (Ioi a) a := by intro h have hf' : Tendsto (deriv (-f)) (𝓝[>] a) atTop := by rw [Pi.neg_def, deriv.neg'] exact tendsto_neg_atBot_atTop.comp hf exact not_differentiableWithinAt_of_deriv_tendsto_atTop_Ioi (-f) hf' h.neg /-- A real function whose derivative tends to minus infinity from the left at a point is not differentiable on the left at that point -/ theorem not_differentiableWithinAt_of_deriv_tendsto_atBot_Iio (f : ℝ → ℝ) {a : ℝ} (hf : Tendsto (deriv f) (𝓝[<] a) atBot) : ¬ DifferentiableWithinAt ℝ f (Iio a) a := by let f' := f ∘ Neg.neg have hderiv : deriv f' =á¶ [𝓝[>] (-a)] -(deriv f ∘ Neg.neg) := by rw [atBot_basis.tendsto_right_iff] at hf specialize hf (-1) trivial rw [(nhdsWithin_Iio_basis a).eventually_iff] at hf rw [EventuallyEq, (nhdsWithin_Ioi_basis (-a)).eventually_iff] obtain ⟹b, hb₁, hb₂⟩ := hf refine ⟹-b, by linarith, fun x hx => ?_⟩ simp only [Pi.neg_apply, Function.comp_apply] suffices deriv f' x = deriv f (-x) * deriv (Neg.neg : ℝ → ℝ) x by simpa using this refine deriv.comp x (differentiableAt_of_deriv_ne_zero ?_) (by fun_prop) rw [mem_Ioo] at hx have h₁ : -x ∈ Ioo b a := ⟹by linarith, by linarith⟩ have h₂ : deriv f (-x) ≀ -1 := hb₂ h₁ exact ne_of_lt (by linarith) have hmain : ¬ DifferentiableWithinAt ℝ f' (Ioi (-a)) (-a) := by refine not_differentiableWithinAt_of_deriv_tendsto_atTop_Ioi f' <| Tendsto.congr' hderiv.symm ?_ refine Tendsto.comp (g := -deriv f) ?_ tendsto_neg_nhdsWithin_Ioi_neg exact Tendsto.comp (g := Neg.neg) tendsto_neg_atBot_atTop hf intro h have : DifferentiableWithinAt ℝ f' (Ioi (-a)) (-a) := by refine DifferentiableWithinAt.comp (g := f) (f := Neg.neg) (t := Iio a) (-a) ?_ ?_ ?_ · simp [h] · fun_prop · intro x simp [neg_lt] exact hmain this /-- A real function whose derivative tends to infinity from the left at a point is not differentiable on the left at that point -/ theorem not_differentiableWithinAt_of_deriv_tendsto_atTop_Iio (f : ℝ → ℝ) {a : ℝ} (hf : Tendsto (deriv f) (𝓝[<] a) atTop) : ¬ DifferentiableWithinAt ℝ f (Iio a) a := by intro h have hf' : Tendsto (deriv (-f)) (𝓝[<] a) atBot := by rw [Pi.neg_def, deriv.neg'] exact tendsto_neg_atTop_atBot.comp hf exact not_differentiableWithinAt_of_deriv_tendsto_atBot_Iio (-f) hf' h.neg end Interval /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D` of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then `f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y ∈ D`, `x < y`. -/ theorem Convex.mul_sub_lt_image_sub_of_lt_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) {C} (hf'_gt : ∀ x ∈ interior D, C < deriv f x) : ∀ᵉ (x ∈ D) (y ∈ D), x < y → C * (y - x) < f y - f x := by intro x hx y hy hxy have hxyD : Icc x y ⊆ D := hD.ordConnected.out hx hy have hxyD' : Ioo x y ⊆ interior D := subset_sUnion_of_mem ⟹isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩ obtain ⟹a, a_mem, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD') have : C < (f y - f x) / (y - x) := ha ▾ hf'_gt _ (hxyD' a_mem) exact (lt_div_iff (sub_pos.2 hxy)).1 this /-- Let `f : ℝ → ℝ` be a differentiable function. If `C < f'`, then `f` grows faster than `C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/ theorem mul_sub_lt_image_sub_of_lt_deriv {f : ℝ → ℝ} (hf : Differentiable ℝ f) {C} (hf'_gt : ∀ x, C < deriv f x) ⊃x y⩄ (hxy : x < y) : C * (y - x) < f y - f x := convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuousOn hf.differentiableOn (fun x _ => hf'_gt x) x trivial y trivial hxy /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D` of the real line. If `f` is differentiable on the interior of `D` and `C ≀ f'`, then `f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) ≀ f y - f x` whenever `x, y ∈ D`, `x ≀ y`. -/ theorem Convex.mul_sub_le_image_sub_of_le_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) {C} (hf'_ge : ∀ x ∈ interior D, C ≀ deriv f x) : ∀ᵉ (x ∈ D) (y ∈ D), x ≀ y → C * (y - x) ≀ f y - f x := by intro x hx y hy hxy cases' eq_or_lt_of_le hxy with hxy' hxy' · rw [hxy', sub_self, sub_self, mul_zero] have hxyD : Icc x y ⊆ D := hD.ordConnected.out hx hy have hxyD' : Ioo x y ⊆ interior D := subset_sUnion_of_mem ⟹isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩ obtain ⟹a, a_mem, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD') have : C ≀ (f y - f x) / (y - x) := ha ▾ hf'_ge _ (hxyD' a_mem) exact (le_div_iff (sub_pos.2 hxy')).1 this /-- Let `f : ℝ → ℝ` be a differentiable function. If `C ≀ f'`, then `f` grows at least as fast as `C * x`, i.e., `C * (y - x) ≀ f y - f x` whenever `x ≀ y`. -/ theorem mul_sub_le_image_sub_of_le_deriv {f : ℝ → ℝ} (hf : Differentiable ℝ f) {C} (hf'_ge : ∀ x, C ≀ deriv f x) ⊃x y⩄ (hxy : x ≀ y) : C * (y - x) ≀ f y - f x := convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuousOn hf.differentiableOn (fun x _ => hf'_ge x) x trivial y trivial hxy /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D` of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then `f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y ∈ D`, `x < y`. -/ theorem Convex.image_sub_lt_mul_sub_of_deriv_lt {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) {C} (lt_hf' : ∀ x ∈ interior D, deriv f x < C) (x : ℝ) (hx : x ∈ D) (y : ℝ) (hy : y ∈ D) (hxy : x < y) : f y - f x < C * (y - x) := have hf'_gt : ∀ x ∈ interior D, -C < deriv (fun y => -f y) x := fun x hx => by rw [deriv.neg, neg_lt_neg_iff] exact lt_hf' x hx by linarith [hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy] /-- Let `f : ℝ → ℝ` be a differentiable function. If `f' < C`, then `f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/ theorem image_sub_lt_mul_sub_of_deriv_lt {f : ℝ → ℝ} (hf : Differentiable ℝ f) {C} (lt_hf' : ∀ x, deriv f x < C) ⊃x y⩄ (hxy : x < y) : f y - f x < C * (y - x) := convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuousOn hf.differentiableOn (fun x _ => lt_hf' x) x trivial y trivial hxy /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D` of the real line. If `f` is differentiable on the interior of `D` and `f' ≀ C`, then `f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x ≀ C * (y - x)` whenever `x, y ∈ D`, `x ≀ y`. -/ theorem Convex.image_sub_le_mul_sub_of_deriv_le {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) {C} (le_hf' : ∀ x ∈ interior D, deriv f x ≀ C) (x : ℝ) (hx : x ∈ D) (y : ℝ) (hy : y ∈ D) (hxy : x ≀ y) : f y - f x ≀ C * (y - x) := have hf'_ge : ∀ x ∈ interior D, -C ≀ deriv (fun y => -f y) x := fun x hx => by rw [deriv.neg, neg_le_neg_iff] exact le_hf' x hx by linarith [hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy] /-- Let `f : ℝ → ℝ` be a differentiable function. If `f' ≀ C`, then `f` grows at most as fast as `C * x`, i.e., `f y - f x ≀ C * (y - x)` whenever `x ≀ y`. -/ theorem image_sub_le_mul_sub_of_deriv_le {f : ℝ → ℝ} (hf : Differentiable ℝ f) {C} (le_hf' : ∀ x, deriv f x ≀ C) ⊃x y⩄ (hxy : x ≀ y) : f y - f x ≀ C * (y - x) := convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuousOn hf.differentiableOn (fun x _ => le_hf' x) x trivial y trivial hxy /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D` of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then `f` is a strictly monotone function on `D`. Note that we don't require differentiability explicitly as it already implied by the derivative being strictly positive. -/ theorem strictMonoOn_of_deriv_pos {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, 0 < deriv f x) : StrictMonoOn f D := by intro x hx y hy have : DifferentiableOn ℝ f (interior D) := fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne').differentiableWithinAt simpa only [zero_mul, sub_pos] using hD.mul_sub_lt_image_sub_of_lt_deriv hf this hf' x hx y hy /-- Let `f : ℝ → ℝ` be a differentiable function. If `f'` is positive, then `f` is a strictly monotone function. Note that we don't require differentiability explicitly as it already implied by the derivative being strictly positive. -/ theorem strictMono_of_deriv_pos {f : ℝ → ℝ} (hf' : ∀ x, 0 < deriv f x) : StrictMono f := strictMonoOn_univ.1 <| strictMonoOn_of_deriv_pos convex_univ (fun z _ => (differentiableAt_of_deriv_ne_zero (hf' z).ne').differentiableWithinAt.continuousWithinAt) fun x _ => hf' x /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D` of the real line. If `f` is differentiable on the interior of `D` and `f'` is strictly positive, then `f` is a strictly monotone function on `D`. -/ lemma strictMonoOn_of_hasDerivWithinAt_pos {D : Set ℝ} (hD : Convex ℝ D) {f f' : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x) (hf'₀ : ∀ x ∈ interior D, 0 < f' x) : StrictMonoOn f D := strictMonoOn_of_deriv_pos hD hf fun x hx ↩ by rw [deriv_eqOn isOpen_interior hf' hx]; exact hf'₀ _ hx @[deprecated (since := "2024-03-02")] alias StrictMonoOn_of_hasDerivWithinAt_pos := strictMonoOn_of_hasDerivWithinAt_pos /-- Let `f : ℝ → ℝ` be a differentiable function. If `f'` is strictly positive, then `f` is a strictly monotone function. -/ lemma strictMono_of_hasDerivAt_pos {f f' : ℝ → ℝ} (hf : ∀ x, HasDerivAt f (f' x) x) (hf' : ∀ x, 0 < f' x) : StrictMono f := strictMono_of_deriv_pos fun x ↩ by rw [(hf _).deriv]; exact hf' _ /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D` of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then `f` is a monotone function on `D`. -/ theorem monotoneOn_of_deriv_nonneg {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (hf'_nonneg : ∀ x ∈ interior D, 0 ≀ deriv f x) : MonotoneOn f D := fun x hx y hy hxy => by simpa only [zero_mul, sub_nonneg] using hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy /-- Let `f : ℝ → ℝ` be a differentiable function. If `f'` is nonnegative, then `f` is a monotone function. -/ theorem monotone_of_deriv_nonneg {f : ℝ → ℝ} (hf : Differentiable ℝ f) (hf' : ∀ x, 0 ≀ deriv f x) : Monotone f := monotoneOn_univ.1 <| monotoneOn_of_deriv_nonneg convex_univ hf.continuous.continuousOn hf.differentiableOn fun x _ => hf' x /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D` of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then `f` is a monotone function on `D`. -/ lemma monotoneOn_of_hasDerivWithinAt_nonneg {D : Set ℝ} (hD : Convex ℝ D) {f f' : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x) (hf'₀ : ∀ x ∈ interior D, 0 ≀ f' x) : MonotoneOn f D := monotoneOn_of_deriv_nonneg hD hf (fun x hx ↩ (hf' _ hx).differentiableWithinAt) fun x hx ↩ by rw [deriv_eqOn isOpen_interior hf' hx]; exact hf'₀ _ hx /-- Let `f : ℝ → ℝ` be a differentiable function. If `f'` is nonnegative, then `f` is a monotone function. -/ lemma monotone_of_hasDerivAt_nonneg {f f' : ℝ → ℝ} (hf : ∀ x, HasDerivAt f (f' x) x) (hf' : 0 ≀ f') : Monotone f := monotone_of_deriv_nonneg (fun x ↩ (hf _).differentiableAt) fun x ↩ by rw [(hf _).deriv]; exact hf' _ /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D` of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then `f` is a strictly antitone function on `D`. -/ theorem strictAntiOn_of_deriv_neg {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, deriv f x < 0) : StrictAntiOn f D := fun x hx y => by simpa only [zero_mul, sub_lt_zero] using hD.image_sub_lt_mul_sub_of_deriv_lt hf (fun z hz => (differentiableAt_of_deriv_ne_zero (hf' z hz).ne).differentiableWithinAt) hf' x hx y /-- Let `f : ℝ → ℝ` be a differentiable function. If `f'` is negative, then `f` is a strictly antitone function. Note that we don't require differentiability explicitly as it already implied by the derivative being strictly negative. -/ theorem strictAnti_of_deriv_neg {f : ℝ → ℝ} (hf' : ∀ x, deriv f x < 0) : StrictAnti f := strictAntiOn_univ.1 <| strictAntiOn_of_deriv_neg convex_univ (fun z _ => (differentiableAt_of_deriv_ne_zero (hf' z).ne).differentiableWithinAt.continuousWithinAt) fun x _ => hf' x /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D` of the real line. If `f` is differentiable on the interior of `D` and `f'` is strictly positive, then `f` is a strictly monotone function on `D`. -/ lemma strictAntiOn_of_hasDerivWithinAt_neg {D : Set ℝ} (hD : Convex ℝ D) {f f' : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x) (hf'₀ : ∀ x ∈ interior D, f' x < 0) : StrictAntiOn f D := strictAntiOn_of_deriv_neg hD hf fun x hx ↩ by rw [deriv_eqOn isOpen_interior hf' hx]; exact hf'₀ _ hx @[deprecated (since := "2024-03-02")] alias StrictAntiOn_of_hasDerivWithinAt_pos := strictAntiOn_of_hasDerivWithinAt_neg /-- Let `f : ℝ → ℝ` be a differentiable function. If `f'` is strictly positive, then `f` is a strictly monotone function. -/ lemma strictAnti_of_hasDerivAt_neg {f f' : ℝ → ℝ} (hf : ∀ x, HasDerivAt f (f' x) x) (hf' : ∀ x, f' x < 0) : StrictAnti f := strictAnti_of_deriv_neg fun x ↩ by rw [(hf _).deriv]; exact hf' _ @[deprecated (since := "2024-03-02")] alias strictAnti_of_hasDerivAt_pos := strictAnti_of_hasDerivAt_neg /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D` of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then `f` is an antitone function on `D`. -/ theorem antitoneOn_of_deriv_nonpos {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (hf'_nonpos : ∀ x ∈ interior D, deriv f x ≀ 0) : AntitoneOn f D := fun x hx y hy hxy => by simpa only [zero_mul, sub_nonpos] using hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy /-- Let `f : ℝ → ℝ` be a differentiable function. If `f'` is nonpositive, then `f` is an antitone function. -/ theorem antitone_of_deriv_nonpos {f : ℝ → ℝ} (hf : Differentiable ℝ f) (hf' : ∀ x, deriv f x ≀ 0) : Antitone f := antitoneOn_univ.1 <| antitoneOn_of_deriv_nonpos convex_univ hf.continuous.continuousOn hf.differentiableOn fun x _ => hf' x /-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D` of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then `f` is an antitone function on `D`. -/ lemma antitoneOn_of_hasDerivWithinAt_nonpos {D : Set ℝ} (hD : Convex ℝ D) {f f' : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x) (hf'₀ : ∀ x ∈ interior D, f' x ≀ 0) : AntitoneOn f D := antitoneOn_of_deriv_nonpos hD hf (fun x hx ↩ (hf' _ hx).differentiableWithinAt) fun x hx ↩ by rw [deriv_eqOn isOpen_interior hf' hx]; exact hf'₀ _ hx /-- Let `f : ℝ → ℝ` be a differentiable function. If `f'` is nonpositive, then `f` is an antitone function. -/ lemma antitone_of_hasDerivAt_nonpos {f f' : ℝ → ℝ} (hf : ∀ x, HasDerivAt f (f' x) x) (hf' : f' ≀ 0) : Antitone f := antitone_of_deriv_nonpos (fun x ↩ (hf _).differentiableAt) fun x ↩ by rw [(hf _).deriv]; exact hf' _ /-! ### Functions `f : E → ℝ` -/ /-- Lagrange's **Mean Value Theorem**, applied to convex domains. -/ theorem domain_mvt {f : E → ℝ} {s : Set E} {x y : E} {f' : E → E →L[ℝ] ℝ} (hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ∃ z ∈ segment ℝ x y, f y - f x = f' z (y - x) := by -- Use `g = AffineMap.lineMap x y` to parametrize the segment set g : ℝ → E := fun t => AffineMap.lineMap x y t set I := Icc (0 : ℝ) 1 have hsub : Ioo (0 : ℝ) 1 ⊆ I := Ioo_subset_Icc_self have hmaps : MapsTo g I s := hs.mapsTo_lineMap xs ys -- The one-variable function `f ∘ g` has derivative `f' (g t) (y - x)` at each `t ∈ I` have hfg : ∀ t ∈ I, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) I t := fun t ht => (hf _ (hmaps ht)).comp_hasDerivWithinAt t AffineMap.hasDerivWithinAt_lineMap hmaps -- apply 1-variable mean value theorem to pullback have hMVT : ∃ t ∈ Ioo (0 : ℝ) 1, f' (g t) (y - x) = (f (g 1) - f (g 0)) / (1 - 0) := by refine exists_hasDerivAt_eq_slope (f ∘ g) _ (by norm_num) ?_ ?_ · exact fun t Ht => (hfg t Ht).continuousWithinAt · exact fun t Ht => (hfg t <| hsub Ht).hasDerivAt (Icc_mem_nhds Ht.1 Ht.2) -- reinterpret on domain rcases hMVT with ⟹t, Ht, hMVT'⟩ rw [segment_eq_image_lineMap, exists_mem_image] refine ⟹t, hsub Ht, ?_⟩ simpa [g] using hMVT'.symm section RCLike /-! ### Vector-valued functions `f : E → F`. Strict differentiability. A `C^1` function is strictly differentiable, when the field is `ℝ` or `ℂ`. This follows from the mean value inequality on balls, which is a particular case of the above results after restricting the scalars to `ℝ`. Note that it does not make sense to talk of a convex set over `ℂ`, but balls make sense and are enough. Many formulations of the mean value inequality could be generalized to balls over `ℝ` or `ℂ`. For now, we only include the ones that we need. -/ variable {𝕜 : Type*} [RCLike 𝕜] {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {H : Type*} [NormedAddCommGroup H] [NormedSpace 𝕜 H] {f : G → H} {f' : G → G →L[𝕜] H} {x : G} /-- Over the reals or the complexes, a continuously differentiable function is strictly differentiable. -/ theorem hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt (hder : ∀ᶠ y in 𝓝 x, HasFDerivAt f (f' y) y) (hcont : ContinuousAt f' x) : HasStrictFDerivAt f (f' x) x := by -- turn little-o definition of strict_fderiv into an epsilon-delta statement refine isLittleO_iff.mpr fun c hc => Metric.eventually_nhds_iff_ball.mpr ?_ -- the correct ε is the modulus of continuity of f' rcases Metric.mem_nhds_iff.mp (inter_mem hder (hcont <| ball_mem_nhds _ hc)) with ⟚ε, ε0, hε⟩ refine ⟚ε, ε0, ?_⟩ -- simplify formulas involving the product E × E rintro ⟹a, b⟩ h rw [← ball_prod_same, prod_mk_mem_set_prod_eq] at h -- exploit the choice of ε as the modulus of continuity of f' have hf' : ∀ x' ∈ ball x ε, ‖f' x' - f' x‖ ≀ c := fun x' H' => by rw [← dist_eq_norm] exact le_of_lt (hε H').2 -- apply mean value theorem letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ 𝕜 G refine (convex_ball _ _).norm_image_sub_le_of_norm_hasFDerivWithin_le' ?_ hf' h.2 h.1 exact fun y hy => (hε hy).1.hasFDerivWithinAt /-- Over the reals or the complexes, a continuously differentiable function is strictly differentiable. -/ theorem hasStrictDerivAt_of_hasDerivAt_of_continuousAt {f f' : 𝕜 → G} {x : 𝕜} (hder : ∀ᶠ y in 𝓝 x, HasDerivAt f (f' y) y) (hcont : ContinuousAt f' x) : HasStrictDerivAt f (f' x) x := hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt (hder.mono fun _ hy => hy.hasFDerivAt) <| (smulRightL 𝕜 𝕜 G 1).continuous.continuousAt.comp hcont end RCLike
Analysis\Calculus\Monotone.lean
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.MeasureTheory.Covering.OneDim import Mathlib.Order.Monotone.Extension /-! # Differentiability of monotone functions We show that a monotone function `f : ℝ → ℝ` is differentiable almost everywhere, in `Monotone.ae_differentiableAt`. (We also give a version for a function monotone on a set, in `MonotoneOn.ae_differentiableWithinAt`.) If the function `f` is continuous, this follows directly from general differentiation of measure theorems. Let `ÎŒ` be the Stieltjes measure associated to `f`. Then, almost everywhere, `ÎŒ [x, y] / Leb [x, y]` (resp. `ÎŒ [y, x] / Leb [y, x]`) converges to the Radon-Nikodym derivative of `ÎŒ` with respect to Lebesgue when `y` tends to `x` in `(x, +∞)` (resp. `(-∞, x)`), by `VitaliFamily.ae_tendsto_rnDeriv`. As `ÎŒ [x, y] = f y - f x` and `Leb [x, y] = y - x`, this gives differentiability right away. When `f` is only monotone, the same argument works up to small adjustments, as the associated Stieltjes measure satisfies `ÎŒ [x, y] = f (y^+) - f (x^-)` (the right and left limits of `f` at `y` and `x` respectively). One argues that `f (x^-) = f x` almost everywhere (in fact away from a countable set), and moreover `f ((y - (y-x)^2)^+) ≀ f y ≀ f (y^+)`. This is enough to deduce the limit of `(f y - f x) / (y - x)` by a lower and upper approximation argument from the known behavior of `ÎŒ [x, y]`. -/ open Set Filter Function Metric MeasureTheory MeasureTheory.Measure IsUnifLocDoublingMeasure open scoped Topology /-- If `(f y - f x) / (y - x)` converges to a limit as `y` tends to `x`, then the same goes if `y` is shifted a little bit, i.e., `f (y + (y-x)^2) - f x) / (y - x)` converges to the same limit. This lemma contains a slightly more general version of this statement (where one considers convergence along some subfilter, typically `𝓝[<] x` or `𝓝[>] x`) tailored to the application to almost everywhere differentiability of monotone functions. -/ theorem tendsto_apply_add_mul_sq_div_sub {f : ℝ → ℝ} {x a c d : ℝ} {l : Filter ℝ} (hl : l ≀ 𝓝[≠] x) (hf : Tendsto (fun y => (f y - d) / (y - x)) l (𝓝 a)) (h' : Tendsto (fun y => y + c * (y - x) ^ 2) l l) : Tendsto (fun y => (f (y + c * (y - x) ^ 2) - d) / (y - x)) l (𝓝 a) := by have L : Tendsto (fun y => (y + c * (y - x) ^ 2 - x) / (y - x)) l (𝓝 1) := by have : Tendsto (fun y => 1 + c * (y - x)) l (𝓝 (1 + c * (x - x))) := by apply Tendsto.mono_left _ (hl.trans nhdsWithin_le_nhds) exact ((tendsto_id.sub_const x).const_mul c).const_add 1 simp only [_root_.sub_self, add_zero, mul_zero] at this apply Tendsto.congr' (Eventually.filter_mono hl _) this filter_upwards [self_mem_nhdsWithin] with y hy field_simp [sub_ne_zero.2 hy] ring have Z := (hf.comp h').mul L rw [mul_one] at Z apply Tendsto.congr' _ Z have : ∀ᶠ y in l, y + c * (y - x) ^ 2 ≠ x := by apply Tendsto.mono_right h' hl self_mem_nhdsWithin filter_upwards [this] with y hy field_simp [sub_ne_zero.2 hy] /-- A Stieltjes function is almost everywhere differentiable, with derivative equal to the Radon-Nikodym derivative of the associated Stieltjes measure with respect to Lebesgue. -/ theorem StieltjesFunction.ae_hasDerivAt (f : StieltjesFunction) : ∀ᵐ x, HasDerivAt f (rnDeriv f.measure volume x).toReal x := by /- Denote by `ÎŒ` the Stieltjes measure associated to `f`. The general theorem `VitaliFamily.ae_tendsto_rnDeriv` ensures that `ÎŒ [x, y] / (y - x)` tends to the Radon-Nikodym derivative as `y` tends to `x` from the right. As `ÎŒ [x,y] = f y - f (x^-)` and `f (x^-) = f x` almost everywhere, this gives differentiability on the right. On the left, `ÎŒ [y, x] / (x - y)` again tends to the Radon-Nikodym derivative. As `ÎŒ [y, x] = f x - f (y^-)`, this is not exactly the right result, so one uses a sandwiching argument to deduce the convergence for `(f x - f y) / (x - y)`. -/ filter_upwards [VitaliFamily.ae_tendsto_rnDeriv (vitaliFamily (volume : Measure ℝ) 1) f.measure, rnDeriv_lt_top f.measure volume, f.countable_leftLim_ne.ae_not_mem volume] with x hx h'x h''x -- Limit on the right, following from differentiation of measures have L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[>] x) (𝓝 (rnDeriv f.measure volume x).toReal) := by apply Tendsto.congr' _ ((ENNReal.tendsto_toReal h'x.ne).comp (hx.comp (Real.tendsto_Icc_vitaliFamily_right x))) filter_upwards [self_mem_nhdsWithin] rintro y (hxy : x < y) simp only [comp_apply, StieltjesFunction.measure_Icc, Real.volume_Icc, Classical.not_not.1 h''x] rw [← ENNReal.ofReal_div_of_pos (sub_pos.2 hxy), ENNReal.toReal_ofReal] exact div_nonneg (sub_nonneg.2 (f.mono hxy.le)) (sub_pos.2 hxy).le -- Limit on the left, following from differentiation of measures. Its form is not exactly the one -- we need, due to the appearance of a left limit. have L2 : Tendsto (fun y => (leftLim f y - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv f.measure volume x).toReal) := by apply Tendsto.congr' _ ((ENNReal.tendsto_toReal h'x.ne).comp (hx.comp (Real.tendsto_Icc_vitaliFamily_left x))) filter_upwards [self_mem_nhdsWithin] rintro y (hxy : y < x) simp only [comp_apply, StieltjesFunction.measure_Icc, Real.volume_Icc] rw [← ENNReal.ofReal_div_of_pos (sub_pos.2 hxy), ENNReal.toReal_ofReal, ← neg_neg (y - x), div_neg, neg_div', neg_sub, neg_sub] exact div_nonneg (sub_nonneg.2 (f.mono.leftLim_le hxy.le)) (sub_pos.2 hxy).le -- Shifting a little bit the limit on the left, by `(y - x)^2`. have L3 : Tendsto (fun y => (leftLim f (y + 1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv f.measure volume x).toReal) := by apply tendsto_apply_add_mul_sq_div_sub (nhds_left'_le_nhds_ne x) L2 apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · apply Tendsto.mono_left _ nhdsWithin_le_nhds have : Tendsto (fun y : ℝ => y + ↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + ↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul ↑1) simpa using this · have : Ioo (x - 1) x ∈ 𝓝[<] x := by apply Ioo_mem_nhdsWithin_Iio; exact ⟹by linarith, le_refl _⟩ filter_upwards [this] rintro y ⟹hy : x - 1 < y, h'y : y < x⟩ rw [mem_Iio] norm_num; nlinarith -- Deduce the correct limit on the left, by sandwiching. have L4 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv f.measure volume x).toReal) := by apply tendsto_of_tendsto_of_tendsto_of_le_of_le' L3 L2 · filter_upwards [self_mem_nhdsWithin] rintro y (hy : y < x) refine div_le_div_of_nonpos_of_le (by linarith) ((sub_le_sub_iff_right _).2 ?_) apply f.mono.le_leftLim have : ↑0 < (x - y) ^ 2 := sq_pos_of_pos (sub_pos.2 hy) norm_num; linarith · filter_upwards [self_mem_nhdsWithin] rintro y (hy : y < x) refine div_le_div_of_nonpos_of_le (by linarith) ?_ simpa only [sub_le_sub_iff_right] using f.mono.leftLim_le (le_refl y) -- prove the result by splitting into left and right limits. rw [hasDerivAt_iff_tendsto_slope, slope_fun_def_field, ← nhds_left'_sup_nhds_right', tendsto_sup] exact ⟹L4, L1⟩ /-- A monotone function is almost everywhere differentiable, with derivative equal to the Radon-Nikodym derivative of the associated Stieltjes measure with respect to Lebesgue. -/ theorem Monotone.ae_hasDerivAt {f : ℝ → ℝ} (hf : Monotone f) : ∀ᵐ x, HasDerivAt f (rnDeriv hf.stieltjesFunction.measure volume x).toReal x := by /- We already know that the Stieltjes function associated to `f` (i.e., `g : x ↩ f (x^+)`) is differentiable almost everywhere. We reduce to this statement by sandwiching values of `f` with values of `g`, by shifting with `(y - x)^2` (which has no influence on the relevant scale `y - x`.)-/ filter_upwards [hf.stieltjesFunction.ae_hasDerivAt, hf.countable_not_continuousAt.ae_not_mem volume] with x hx h'x have A : hf.stieltjesFunction x = f x := by rw [Classical.not_not, hf.continuousAt_iff_leftLim_eq_rightLim] at h'x apply le_antisymm _ (hf.le_rightLim (le_refl _)) rw [← h'x] exact hf.leftLim_le (le_refl _) rw [hasDerivAt_iff_tendsto_slope, (nhds_left'_sup_nhds_right' x).symm, tendsto_sup, slope_fun_def_field, A] at hx -- prove differentiability on the right, by sandwiching with values of `g` have L1 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[>] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by -- limit of a helper function, with a small shift compared to `g` have : Tendsto (fun y => (hf.stieltjesFunction (y + -1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[>] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by apply tendsto_apply_add_mul_sq_div_sub (nhds_right'_le_nhds_ne x) hx.2 apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · apply Tendsto.mono_left _ nhdsWithin_le_nhds have : Tendsto (fun y : ℝ => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + -↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul (-1)) simpa using this · have : Ioo x (x + 1) ∈ 𝓝[>] x := by apply Ioo_mem_nhdsWithin_Ioi; exact ⟹le_refl _, by linarith⟩ filter_upwards [this] rintro y ⟹hy : x < y, h'y : y < x + 1⟩ rw [mem_Ioi] norm_num; nlinarith -- apply the sandwiching argument, with the helper function and `g` apply tendsto_of_tendsto_of_tendsto_of_le_of_le' this hx.2 · filter_upwards [self_mem_nhdsWithin] with y hy rw [mem_Ioi, ← sub_pos] at hy gcongr exact hf.rightLim_le (by nlinarith) · filter_upwards [self_mem_nhdsWithin] with y hy rw [mem_Ioi, ← sub_pos] at hy gcongr exact hf.le_rightLim le_rfl -- prove differentiability on the left, by sandwiching with values of `g` have L2 : Tendsto (fun y => (f y - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by -- limit of a helper function, with a small shift compared to `g` have : Tendsto (fun y => (hf.stieltjesFunction (y + -1 * (y - x) ^ 2) - f x) / (y - x)) (𝓝[<] x) (𝓝 (rnDeriv hf.stieltjesFunction.measure volume x).toReal) := by apply tendsto_apply_add_mul_sq_div_sub (nhds_left'_le_nhds_ne x) hx.1 apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · apply Tendsto.mono_left _ nhdsWithin_le_nhds have : Tendsto (fun y : ℝ => y + -↑1 * (y - x) ^ 2) (𝓝 x) (𝓝 (x + -↑1 * (x - x) ^ 2)) := tendsto_id.add (((tendsto_id.sub_const x).pow 2).const_mul (-1)) simpa using this · have : Ioo (x - 1) x ∈ 𝓝[<] x := by apply Ioo_mem_nhdsWithin_Iio; exact ⟹by linarith, le_refl _⟩ filter_upwards [this] rintro y hy rw [mem_Ioo] at hy rw [mem_Iio] norm_num; nlinarith -- apply the sandwiching argument, with `g` and the helper function apply tendsto_of_tendsto_of_tendsto_of_le_of_le' hx.1 this · filter_upwards [self_mem_nhdsWithin] rintro y hy rw [mem_Iio, ← sub_neg] at hy apply div_le_div_of_nonpos_of_le hy.le exact (sub_le_sub_iff_right _).2 (hf.le_rightLim (le_refl _)) · filter_upwards [self_mem_nhdsWithin] rintro y hy rw [mem_Iio, ← sub_neg] at hy have : 0 < (y - x) ^ 2 := sq_pos_of_neg hy apply div_le_div_of_nonpos_of_le hy.le exact (sub_le_sub_iff_right _).2 (hf.rightLim_le (by norm_num; linarith)) -- conclude global differentiability rw [hasDerivAt_iff_tendsto_slope, slope_fun_def_field, (nhds_left'_sup_nhds_right' x).symm, tendsto_sup] exact ⟹L2, L1⟩ /-- A monotone real function is differentiable Lebesgue-almost everywhere. -/ theorem Monotone.ae_differentiableAt {f : ℝ → ℝ} (hf : Monotone f) : ∀ᵐ x, DifferentiableAt ℝ f x := by filter_upwards [hf.ae_hasDerivAt] with x hx using hx.differentiableAt /-- A real function which is monotone on a set is differentiable Lebesgue-almost everywhere on this set. This version does not assume that `s` is measurable. For a formulation with `volume.restrict s` assuming that `s` is measurable, see `MonotoneOn.ae_differentiableWithinAt`. -/ theorem MonotoneOn.ae_differentiableWithinAt_of_mem {f : ℝ → ℝ} {s : Set ℝ} (hf : MonotoneOn f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x := by /- We use a global monotone extension of `f`, and argue that this extension is differentiable almost everywhere. Such an extension need not exist (think of `1/x` on `(0, +∞)`), but it exists if one restricts first the function to a compact interval `[a, b]`. -/ apply ae_of_mem_of_ae_of_mem_inter_Ioo intro a b as bs _ obtain ⟹g, hg, gf⟩ : ∃ g : ℝ → ℝ, Monotone g ∧ EqOn f g (s ∩ Icc a b) := (hf.mono inter_subset_left).exists_monotone_extension (hf.map_bddBelow inter_subset_left ⟹a, fun x hx => hx.2.1, as⟩) (hf.map_bddAbove inter_subset_left ⟹b, fun x hx => hx.2.2, bs⟩) filter_upwards [hg.ae_differentiableAt] with x hx intro h'x apply hx.differentiableWithinAt.congr_of_eventuallyEq _ (gf ⟹h'x.1, h'x.2.1.le, h'x.2.2.le⟩) have : Ioo a b ∈ 𝓝[s] x := nhdsWithin_le_nhds (Ioo_mem_nhds h'x.2.1 h'x.2.2) filter_upwards [self_mem_nhdsWithin, this] with y hy h'y exact gf ⟹hy, h'y.1.le, h'y.2.le⟩ /-- A real function which is monotone on a set is differentiable Lebesgue-almost everywhere on this set. This version assumes that `s` is measurable and uses `volume.restrict s`. For a formulation without measurability assumption, see `MonotoneOn.ae_differentiableWithinAt_of_mem`. -/ theorem MonotoneOn.ae_differentiableWithinAt {f : ℝ → ℝ} {s : Set ℝ} (hf : MonotoneOn f s) (hs : MeasurableSet s) : ∀ᵐ x ∂volume.restrict s, DifferentiableWithinAt ℝ f s x := by rw [ae_restrict_iff' hs] exact hf.ae_differentiableWithinAt_of_mem
Analysis\Calculus\ParametricIntegral.lean
/- Copyright (c) 2021 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Analysis.Calculus.MeanValue import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.MeasureTheory.Integral.SetIntegral import Mathlib.Analysis.NormedSpace.HahnBanach.SeparatingDual /-! # Derivatives of integrals depending on parameters A parametric integral is a function with shape `f = fun x : H ↩ ∫ a : α, F x a ∂Ό` for some `F : H → α → E`, where `H` and `E` are normed spaces and `α` is a measured space with measure `ÎŒ`. We already know from `continuous_of_dominated` in `Mathlib/MeasureTheory/Integral/Bochner.lean` how to guarantee that `f` is continuous using the dominated convergence theorem. In this file, we want to express the derivative of `f` as the integral of the derivative of `F` with respect to `x`. ## Main results As explained above, all results express the derivative of a parametric integral as the integral of a derivative. The variations come from the assumptions and from the different ways of expressing derivative, especially Fréchet derivatives vs elementary derivative of function of one real variable. * `hasFDerivAt_integral_of_dominated_loc_of_lip`: this version assumes that - `F x` is ae-measurable for x near `x₀`, - `F x₀` is integrable, - `fun x ↩ F x a` has derivative `F' a : H →L[ℝ] E` at `x₀` which is ae-measurable, - `fun x ↩ F x a` is locally Lipschitz near `x₀` for almost every `a`, with a Lipschitz bound which is integrable with respect to `a`. A subtle point is that the "near x₀" in the last condition has to be uniform in `a`. This is controlled by a positive number `ε`. * `hasFDerivAt_integral_of_dominated_of_fderiv_le`: this version assumes `fun x ↩ F x a` has derivative `F' x a` for `x` near `x₀` and `F' x` is bounded by an integrable function independent from `x` near `x₀`. `hasDerivAt_integral_of_dominated_loc_of_lip` and `hasDerivAt_integral_of_dominated_loc_of_deriv_le` are versions of the above two results that assume `H = ℝ` or `H = ℂ` and use the high-school derivative `deriv` instead of Fréchet derivative `fderiv`. We also provide versions of these theorems for set integrals. ## Tags integral, derivative -/ noncomputable section open TopologicalSpace MeasureTheory Filter Metric open scoped Topology Filter variable {α : Type*} [MeasurableSpace α] {ÎŒ : Measure α} {𝕜 : Type*} [RCLike 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedSpace 𝕜 E] {H : Type*} [NormedAddCommGroup H] [NormedSpace 𝕜 H] variable {F : H → α → E} {x₀ : H} {bound : α → ℝ} {ε : ℝ} /-- Differentiation under integral of `x ↩ ∫ F x a` at a given point `x₀`, assuming `F x₀` is integrable, `‖F x a - F x₀ a‖ ≀ bound a * ‖x - x₀‖` for `x` in a ball around `x₀` for ae `a` with integrable Lipschitz bound `bound` (with a ball radius independent of `a`), and `F x` is ae-measurable for `x` in the same ball. See `hasFDerivAt_integral_of_dominated_loc_of_lip` for a slightly less general but usually more useful version. -/ theorem hasFDerivAt_integral_of_dominated_loc_of_lip' {F' : α → H →L[𝕜] E} (ε_pos : 0 < ε) (hF_meas : ∀ x ∈ ball x₀ ε, AEStronglyMeasurable (F x) ÎŒ) (hF_int : Integrable (F x₀) ÎŒ) (hF'_meas : AEStronglyMeasurable F' ÎŒ) (h_lipsch : ∀ᵐ a ∂Ό, ∀ x ∈ ball x₀ ε, ‖F x a - F x₀ a‖ ≀ bound a * ‖x - x₀‖) (bound_integrable : Integrable (bound : α → ℝ) ÎŒ) (h_diff : ∀ᵐ a ∂Ό, HasFDerivAt (F · a) (F' a) x₀) : Integrable F' ÎŒ ∧ HasFDerivAt (fun x ↩ ∫ a, F x a ∂Ό) (∫ a, F' a ∂Ό) x₀ := by have x₀_in : x₀ ∈ ball x₀ ε := mem_ball_self ε_pos have nneg : ∀ x, 0 ≀ ‖x - x₀‖⁻¹ := fun x ↩ inv_nonneg.mpr (norm_nonneg _) set b : α → ℝ := fun a ↩ |bound a| have b_int : Integrable b ÎŒ := bound_integrable.norm have b_nonneg : ∀ a, 0 ≀ b a := fun a ↩ abs_nonneg _ replace h_lipsch : ∀ᵐ a ∂Ό, ∀ x ∈ ball x₀ ε, ‖F x a - F x₀ a‖ ≀ b a * ‖x - x₀‖ := h_lipsch.mono fun a ha x hx ↩ (ha x hx).trans <| mul_le_mul_of_nonneg_right (le_abs_self _) (norm_nonneg _) have hF_int' : ∀ x ∈ ball x₀ ε, Integrable (F x) ÎŒ := fun x x_in ↩ by have : ∀ᵐ a ∂Ό, ‖F x₀ a - F x a‖ ≀ ε * b a := by simp only [norm_sub_rev (F x₀ _)] refine h_lipsch.mono fun a ha ↩ (ha x x_in).trans ?_ rw [mul_comm ε] rw [mem_ball, dist_eq_norm] at x_in exact mul_le_mul_of_nonneg_left x_in.le (b_nonneg _) exact integrable_of_norm_sub_le (hF_meas x x_in) hF_int (bound_integrable.norm.const_mul ε) this have hF'_int : Integrable F' ÎŒ := have : ∀ᵐ a ∂Ό, ‖F' a‖ ≀ b a := by apply (h_diff.and h_lipsch).mono rintro a ⟹ha_diff, ha_lip⟩ exact ha_diff.le_of_lip' (b_nonneg a) (mem_of_superset (ball_mem_nhds _ ε_pos) <| ha_lip) b_int.mono' hF'_meas this refine ⟹hF'_int, ?_⟩ /- Discard the trivial case where `E` is not complete, as all integrals vanish. -/ by_cases hE : CompleteSpace E; swap · rcases subsingleton_or_nontrivial H with hH|hH · have : Subsingleton (H →L[𝕜] E) := inferInstance convert hasFDerivAt_of_subsingleton _ x₀ · have : ¬(CompleteSpace (H →L[𝕜] E)) := by simpa [SeparatingDual.completeSpace_continuousLinearMap_iff] using hE simp only [integral, hE, ↓reduceDIte, this] exact hasFDerivAt_const 0 x₀ have h_ball : ball x₀ ε ∈ 𝓝 x₀ := ball_mem_nhds x₀ ε_pos have : ∀ᶠ x in 𝓝 x₀, ‖x - x₀‖⁻¹ * ‖((∫ a, F x a ∂Ό) - ∫ a, F x₀ a ∂Ό) - (∫ a, F' a ∂Ό) (x - x₀)‖ = ‖∫ a, ‖x - x₀‖⁻¹ • (F x a - F x₀ a - F' a (x - x₀)) ∂Ό‖ := by apply mem_of_superset (ball_mem_nhds _ ε_pos) intro x x_in; simp only rw [Set.mem_setOf_eq, ← norm_smul_of_nonneg (nneg _), integral_smul, integral_sub, integral_sub, ← ContinuousLinearMap.integral_apply hF'_int] exacts [hF_int' x x_in, hF_int, (hF_int' x x_in).sub hF_int, hF'_int.apply_continuousLinearMap _] rw [hasFDerivAt_iff_tendsto, tendsto_congr' this, ← tendsto_zero_iff_norm_tendsto_zero, ← show (∫ a : α, ‖x₀ - x₀‖⁻¹ • (F x₀ a - F x₀ a - (F' a) (x₀ - x₀)) ∂Ό) = 0 by simp] apply tendsto_integral_filter_of_dominated_convergence · filter_upwards [h_ball] with _ x_in apply AEStronglyMeasurable.const_smul exact ((hF_meas _ x_in).sub (hF_meas _ x₀_in)).sub (hF'_meas.apply_continuousLinearMap _) · refine mem_of_superset h_ball fun x hx ↩ ?_ apply (h_diff.and h_lipsch).mono on_goal 1 => rintro a ⟹-, ha_bound⟩ show ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - F' a (x - x₀))‖ ≀ b a + ‖F' a‖ replace ha_bound : ‖F x a - F x₀ a‖ ≀ b a * ‖x - x₀‖ := ha_bound x hx calc ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - F' a (x - x₀))‖ = ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a) - ‖x - x₀‖⁻¹ • F' a (x - x₀)‖ := by rw [smul_sub] _ ≀ ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a)‖ + ‖‖x - x₀‖⁻¹ • F' a (x - x₀)‖ := norm_sub_le _ _ _ = ‖x - x₀‖⁻¹ * ‖F x a - F x₀ a‖ + ‖x - x₀‖⁻¹ * ‖F' a (x - x₀)‖ := by rw [norm_smul_of_nonneg, norm_smul_of_nonneg] <;> exact nneg _ _ ≀ ‖x - x₀‖⁻¹ * (b a * ‖x - x₀‖) + ‖x - x₀‖⁻¹ * (‖F' a‖ * ‖x - x₀‖) := by gcongr; exact (F' a).le_opNorm _ _ ≀ b a + ‖F' a‖ := ?_ simp only [← div_eq_inv_mul] apply_rules [add_le_add, div_le_of_nonneg_of_le_mul] <;> first | rfl | positivity · exact b_int.add hF'_int.norm · apply h_diff.mono intro a ha suffices Tendsto (fun x ↩ ‖x - x₀‖⁻¹ • (F x a - F x₀ a - F' a (x - x₀))) (𝓝 x₀) (𝓝 0) by simpa rw [tendsto_zero_iff_norm_tendsto_zero] have : (fun x ↩ ‖x - x₀‖⁻¹ * ‖F x a - F x₀ a - F' a (x - x₀)‖) = fun x ↩ ‖‖x - x₀‖⁻¹ • (F x a - F x₀ a - F' a (x - x₀))‖ := by ext x rw [norm_smul_of_nonneg (nneg _)] rwa [hasFDerivAt_iff_tendsto, this] at ha /-- Differentiation under integral of `x ↩ ∫ F x a` at a given point `x₀`, assuming `F x₀` is integrable, `x ↩ F x a` is locally Lipschitz on a ball around `x₀` for ae `a` (with a ball radius independent of `a`) with integrable Lipschitz bound, and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/ theorem hasFDerivAt_integral_of_dominated_loc_of_lip {F' : α → H →L[𝕜] E} (ε_pos : 0 < ε) (hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) ÎŒ) (hF_int : Integrable (F x₀) ÎŒ) (hF'_meas : AEStronglyMeasurable F' ÎŒ) (h_lip : ∀ᵐ a ∂Ό, LipschitzOnWith (Real.nnabs <| bound a) (F · a) (ball x₀ ε)) (bound_integrable : Integrable (bound : α → ℝ) ÎŒ) (h_diff : ∀ᵐ a ∂Ό, HasFDerivAt (F · a) (F' a) x₀) : Integrable F' ÎŒ ∧ HasFDerivAt (fun x ↩ ∫ a, F x a ∂Ό) (∫ a, F' a ∂Ό) x₀ := by obtain ⟹ή, ÎŽ_pos, hΎ⟩ : ∃ ÎŽ > 0, ∀ x ∈ ball x₀ ÎŽ, AEStronglyMeasurable (F x) ÎŒ ∧ x ∈ ball x₀ ε := eventually_nhds_iff_ball.mp (hF_meas.and (ball_mem_nhds x₀ ε_pos)) choose hÎŽ_meas hΎε using hÎŽ replace h_lip : ∀ᵐ a : α ∂Ό, ∀ x ∈ ball x₀ ÎŽ, ‖F x a - F x₀ a‖ ≀ |bound a| * ‖x - x₀‖ := h_lip.mono fun a lip x hx ↩ lip.norm_sub_le (hΎε x hx) (mem_ball_self ε_pos) replace bound_integrable := bound_integrable.norm apply hasFDerivAt_integral_of_dominated_loc_of_lip' ÎŽ_pos <;> assumption /-- Differentiation under integral of `x ↩ ∫ x in a..b, F x t` at a given point `x₀ ∈ (a,b)`, assuming `F x₀` is integrable on `(a,b)`, that `x ↩ F x t` is Lipschitz on a ball around `x₀` for almost every `t` (with a ball radius independent of `t`) with integrable Lipschitz bound, and `F x` is a.e.-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/ theorem hasFDerivAt_integral_of_dominated_loc_of_lip_interval [NormedSpace ℝ H] {ÎŒ : Measure ℝ} {F : H → ℝ → E} {F' : ℝ → H →L[ℝ] E} {a b : ℝ} {bound : ℝ → ℝ} (ε_pos : 0 < ε) (hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) <| ÎŒ.restrict (Ι a b)) (hF_int : IntervalIntegrable (F x₀) ÎŒ a b) (hF'_meas : AEStronglyMeasurable F' <| ÎŒ.restrict (Ι a b)) (h_lip : ∀ᵐ t ∂Ό.restrict (Ι a b), LipschitzOnWith (Real.nnabs <| bound t) (F · t) (ball x₀ ε)) (bound_integrable : IntervalIntegrable bound ÎŒ a b) (h_diff : ∀ᵐ t ∂Ό.restrict (Ι a b), HasFDerivAt (F · t) (F' t) x₀) : IntervalIntegrable F' ÎŒ a b ∧ HasFDerivAt (fun x ↩ ∫ t in a..b, F x t ∂Ό) (∫ t in a..b, F' t ∂Ό) x₀ := by simp_rw [AEStronglyMeasurable.aestronglyMeasurable_uIoc_iff, eventually_and] at hF_meas hF'_meas rw [ae_restrict_uIoc_iff] at h_lip h_diff have H₁ := hasFDerivAt_integral_of_dominated_loc_of_lip ε_pos hF_meas.1 hF_int.1 hF'_meas.1 h_lip.1 bound_integrable.1 h_diff.1 have H₂ := hasFDerivAt_integral_of_dominated_loc_of_lip ε_pos hF_meas.2 hF_int.2 hF'_meas.2 h_lip.2 bound_integrable.2 h_diff.2 exact ⟹⟹H₁.1, H₂.1⟩, H₁.2.sub H₂.2⟩ /-- Differentiation under integral of `x ↩ ∫ F x a` at a given point `x₀`, assuming `F x₀` is integrable, `x ↩ F x a` is differentiable on a ball around `x₀` for ae `a` with derivative norm uniformly bounded by an integrable function (the ball radius is independent of `a`), and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/ theorem hasFDerivAt_integral_of_dominated_of_fderiv_le {F' : H → α → H →L[𝕜] E} (ε_pos : 0 < ε) (hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) ÎŒ) (hF_int : Integrable (F x₀) ÎŒ) (hF'_meas : AEStronglyMeasurable (F' x₀) ÎŒ) (h_bound : ∀ᵐ a ∂Ό, ∀ x ∈ ball x₀ ε, ‖F' x a‖ ≀ bound a) (bound_integrable : Integrable (bound : α → ℝ) ÎŒ) (h_diff : ∀ᵐ a ∂Ό, ∀ x ∈ ball x₀ ε, HasFDerivAt (F · a) (F' x a) x) : HasFDerivAt (fun x ↩ ∫ a, F x a ∂Ό) (∫ a, F' x₀ a ∂Ό) x₀ := by letI : NormedSpace ℝ H := NormedSpace.restrictScalars ℝ 𝕜 H have x₀_in : x₀ ∈ ball x₀ ε := mem_ball_self ε_pos have diff_x₀ : ∀ᵐ a ∂Ό, HasFDerivAt (F · a) (F' x₀ a) x₀ := h_diff.mono fun a ha ↩ ha x₀ x₀_in have : ∀ᵐ a ∂Ό, LipschitzOnWith (Real.nnabs (bound a)) (F · a) (ball x₀ ε) := by apply (h_diff.and h_bound).mono rintro a ⟹ha_deriv, ha_bound⟩ refine (convex_ball _ _).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x x_in ↩ (ha_deriv x x_in).hasFDerivWithinAt) fun x x_in ↩ ?_ rw [← NNReal.coe_le_coe, coe_nnnorm, Real.coe_nnabs] exact (ha_bound x x_in).trans (le_abs_self _) exact (hasFDerivAt_integral_of_dominated_loc_of_lip ε_pos hF_meas hF_int hF'_meas this bound_integrable diff_x₀).2 /-- Differentiation under integral of `x ↩ ∫ x in a..b, F x a` at a given point `x₀`, assuming `F x₀` is integrable on `(a,b)`, `x ↩ F x a` is differentiable on a ball around `x₀` for ae `a` with derivative norm uniformly bounded by an integrable function (the ball radius is independent of `a`), and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/ theorem hasFDerivAt_integral_of_dominated_of_fderiv_le'' [NormedSpace ℝ H] {ÎŒ : Measure ℝ} {F : H → ℝ → E} {F' : H → ℝ → H →L[ℝ] E} {a b : ℝ} {bound : ℝ → ℝ} (ε_pos : 0 < ε) (hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) <| ÎŒ.restrict (Ι a b)) (hF_int : IntervalIntegrable (F x₀) ÎŒ a b) (hF'_meas : AEStronglyMeasurable (F' x₀) <| ÎŒ.restrict (Ι a b)) (h_bound : ∀ᵐ t ∂Ό.restrict (Ι a b), ∀ x ∈ ball x₀ ε, ‖F' x t‖ ≀ bound t) (bound_integrable : IntervalIntegrable bound ÎŒ a b) (h_diff : ∀ᵐ t ∂Ό.restrict (Ι a b), ∀ x ∈ ball x₀ ε, HasFDerivAt (F · t) (F' x t) x) : HasFDerivAt (fun x ↩ ∫ t in a..b, F x t ∂Ό) (∫ t in a..b, F' x₀ t ∂Ό) x₀ := by rw [ae_restrict_uIoc_iff] at h_diff h_bound simp_rw [AEStronglyMeasurable.aestronglyMeasurable_uIoc_iff, eventually_and] at hF_meas hF'_meas exact (hasFDerivAt_integral_of_dominated_of_fderiv_le ε_pos hF_meas.1 hF_int.1 hF'_meas.1 h_bound.1 bound_integrable.1 h_diff.1).sub (hasFDerivAt_integral_of_dominated_of_fderiv_le ε_pos hF_meas.2 hF_int.2 hF'_meas.2 h_bound.2 bound_integrable.2 h_diff.2) section variable {F : 𝕜 → α → E} {x₀ : 𝕜} /-- Derivative under integral of `x ↩ ∫ F x a` at a given point `x₀ : 𝕜`, `𝕜 = ℝ` or `𝕜 = ℂ`, assuming `F x₀` is integrable, `x ↩ F x a` is locally Lipschitz on a ball around `x₀` for ae `a` (with ball radius independent of `a`) with integrable Lipschitz bound, and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/ theorem hasDerivAt_integral_of_dominated_loc_of_lip {F' : α → E} (ε_pos : 0 < ε) (hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) ÎŒ) (hF_int : Integrable (F x₀) ÎŒ) (hF'_meas : AEStronglyMeasurable F' ÎŒ) (h_lipsch : ∀ᵐ a ∂Ό, LipschitzOnWith (Real.nnabs <| bound a) (F · a) (ball x₀ ε)) (bound_integrable : Integrable (bound : α → ℝ) ÎŒ) (h_diff : ∀ᵐ a ∂Ό, HasDerivAt (F · a) (F' a) x₀) : Integrable F' ÎŒ ∧ HasDerivAt (fun x ↩ ∫ a, F x a ∂Ό) (∫ a, F' a ∂Ό) x₀ := by set L : E →L[𝕜] 𝕜 →L[𝕜] E := ContinuousLinearMap.smulRightL 𝕜 𝕜 E 1 replace h_diff : ∀ᵐ a ∂Ό, HasFDerivAt (F · a) (L (F' a)) x₀ := h_diff.mono fun x hx ↩ hx.hasFDerivAt have hm : AEStronglyMeasurable (L ∘ F') ÎŒ := L.continuous.comp_aestronglyMeasurable hF'_meas cases' hasFDerivAt_integral_of_dominated_loc_of_lip ε_pos hF_meas hF_int hm h_lipsch bound_integrable h_diff with hF'_int key replace hF'_int : Integrable F' ÎŒ := by rw [← integrable_norm_iff hm] at hF'_int simpa only [L, (· ∘ ·), integrable_norm_iff, hF'_meas, one_mul, norm_one, ContinuousLinearMap.comp_apply, ContinuousLinearMap.coe_restrict_scalarsL', ContinuousLinearMap.norm_restrictScalars, ContinuousLinearMap.norm_smulRightL_apply] using hF'_int refine ⟹hF'_int, ?_⟩ by_cases hE : CompleteSpace E; swap · simpa [integral, hE] using hasDerivAt_const x₀ 0 simp_rw [hasDerivAt_iff_hasFDerivAt] at h_diff ⊢ simpa only [(· ∘ ·), ContinuousLinearMap.integral_comp_comm _ hF'_int] using key /-- Derivative under integral of `x ↩ ∫ F x a` at a given point `x₀ : ℝ`, assuming `F x₀` is integrable, `x ↩ F x a` is differentiable on an interval around `x₀` for ae `a` (with interval radius independent of `a`) with derivative uniformly bounded by an integrable function, and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/ theorem hasDerivAt_integral_of_dominated_loc_of_deriv_le (ε_pos : 0 < ε) (hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) ÎŒ) (hF_int : Integrable (F x₀) ÎŒ) {F' : 𝕜 → α → E} (hF'_meas : AEStronglyMeasurable (F' x₀) ÎŒ) (h_bound : ∀ᵐ a ∂Ό, ∀ x ∈ ball x₀ ε, ‖F' x a‖ ≀ bound a) (bound_integrable : Integrable bound ÎŒ) (h_diff : ∀ᵐ a ∂Ό, ∀ x ∈ ball x₀ ε, HasDerivAt (F · a) (F' x a) x) : Integrable (F' x₀) ÎŒ ∧ HasDerivAt (fun n ↩ ∫ a, F n a ∂Ό) (∫ a, F' x₀ a ∂Ό) x₀ := by have x₀_in : x₀ ∈ ball x₀ ε := mem_ball_self ε_pos have diff_x₀ : ∀ᵐ a ∂Ό, HasDerivAt (F · a) (F' x₀ a) x₀ := h_diff.mono fun a ha ↩ ha x₀ x₀_in have : ∀ᵐ a ∂Ό, LipschitzOnWith (Real.nnabs (bound a)) (fun x : 𝕜 ↩ F x a) (ball x₀ ε) := by apply (h_diff.and h_bound).mono rintro a ⟹ha_deriv, ha_bound⟩ refine (convex_ball _ _).lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun x x_in ↩ (ha_deriv x x_in).hasDerivWithinAt) fun x x_in ↩ ?_ rw [← NNReal.coe_le_coe, coe_nnnorm, Real.coe_nnabs] exact (ha_bound x x_in).trans (le_abs_self _) exact hasDerivAt_integral_of_dominated_loc_of_lip ε_pos hF_meas hF_int hF'_meas this bound_integrable diff_x₀ end
Analysis\Calculus\ParametricIntervalIntegral.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.ParametricIntegral import Mathlib.MeasureTheory.Integral.IntervalIntegral /-! # Derivatives of interval integrals depending on parameters In this file we restate theorems about derivatives of integrals depending on parameters for interval integrals. -/ open TopologicalSpace MeasureTheory Filter Metric open scoped Topology Filter Interval variable {𝕜 : Type*} [RCLike 𝕜] {ÎŒ : Measure ℝ} {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedSpace 𝕜 E] [CompleteSpace E] {H : Type*} [NormedAddCommGroup H] [NormedSpace 𝕜 H] {a b ε : ℝ} {bound : ℝ → ℝ} namespace intervalIntegral /-- Differentiation under integral of `x ↩ ∫ t in a..b, F x t` at a given point `x₀`, assuming `F x₀` is integrable, `x ↩ F x a` is locally Lipschitz on a ball around `x₀` for ae `a` (with a ball radius independent of `a`) with integrable Lipschitz bound, and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/ nonrec theorem hasFDerivAt_integral_of_dominated_loc_of_lip {F : H → ℝ → E} {F' : ℝ → H →L[𝕜] E} {x₀ : H} (ε_pos : 0 < ε) (hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) (ÎŒ.restrict (Ι a b))) (hF_int : IntervalIntegrable (F x₀) ÎŒ a b) (hF'_meas : AEStronglyMeasurable F' (ÎŒ.restrict (Ι a b))) (h_lip : ∀ᵐ t ∂Ό, t ∈ Ι a b → LipschitzOnWith (Real.nnabs <| bound t) (fun x => F x t) (ball x₀ ε)) (bound_integrable : IntervalIntegrable bound ÎŒ a b) (h_diff : ∀ᵐ t ∂Ό, t ∈ Ι a b → HasFDerivAt (fun x => F x t) (F' t) x₀) : IntervalIntegrable F' ÎŒ a b ∧ HasFDerivAt (fun x => ∫ t in a..b, F x t ∂Ό) (∫ t in a..b, F' t ∂Ό) x₀ := by rw [← ae_restrict_iff' measurableSet_uIoc] at h_lip h_diff simp only [intervalIntegrable_iff] at hF_int bound_integrable ⊢ simp only [intervalIntegral_eq_integral_uIoc] have := hasFDerivAt_integral_of_dominated_loc_of_lip ε_pos hF_meas hF_int hF'_meas h_lip bound_integrable h_diff exact ⟹this.1, this.2.const_smul _⟩ /-- Differentiation under integral of `x ↩ ∫ F x a` at a given point `x₀`, assuming `F x₀` is integrable, `x ↩ F x a` is differentiable on a ball around `x₀` for ae `a` with derivative norm uniformly bounded by an integrable function (the ball radius is independent of `a`), and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/ nonrec theorem hasFDerivAt_integral_of_dominated_of_fderiv_le {F : H → ℝ → E} {F' : H → ℝ → H →L[𝕜] E} {x₀ : H} (ε_pos : 0 < ε) (hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) (ÎŒ.restrict (Ι a b))) (hF_int : IntervalIntegrable (F x₀) ÎŒ a b) (hF'_meas : AEStronglyMeasurable (F' x₀) (ÎŒ.restrict (Ι a b))) (h_bound : ∀ᵐ t ∂Ό, t ∈ Ι a b → ∀ x ∈ ball x₀ ε, ‖F' x t‖ ≀ bound t) (bound_integrable : IntervalIntegrable bound ÎŒ a b) (h_diff : ∀ᵐ t ∂Ό, t ∈ Ι a b → ∀ x ∈ ball x₀ ε, HasFDerivAt (fun x => F x t) (F' x t) x) : HasFDerivAt (fun x => ∫ t in a..b, F x t ∂Ό) (∫ t in a..b, F' x₀ t ∂Ό) x₀ := by rw [← ae_restrict_iff' measurableSet_uIoc] at h_bound h_diff simp only [intervalIntegrable_iff] at hF_int bound_integrable simp only [intervalIntegral_eq_integral_uIoc] exact (hasFDerivAt_integral_of_dominated_of_fderiv_le ε_pos hF_meas hF_int hF'_meas h_bound bound_integrable h_diff).const_smul _ /-- Derivative under integral of `x ↩ ∫ F x a` at a given point `x₀ : 𝕜`, `𝕜 = ℝ` or `𝕜 = ℂ`, assuming `F x₀` is integrable, `x ↩ F x a` is locally Lipschitz on a ball around `x₀` for ae `a` (with ball radius independent of `a`) with integrable Lipschitz bound, and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/ nonrec theorem hasDerivAt_integral_of_dominated_loc_of_lip {F : 𝕜 → ℝ → E} {F' : ℝ → E} {x₀ : 𝕜} (ε_pos : 0 < ε) (hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) (ÎŒ.restrict (Ι a b))) (hF_int : IntervalIntegrable (F x₀) ÎŒ a b) (hF'_meas : AEStronglyMeasurable F' (ÎŒ.restrict (Ι a b))) (h_lipsch : ∀ᵐ t ∂Ό, t ∈ Ι a b → LipschitzOnWith (Real.nnabs <| bound t) (fun x => F x t) (ball x₀ ε)) (bound_integrable : IntervalIntegrable (bound : ℝ → ℝ) ÎŒ a b) (h_diff : ∀ᵐ t ∂Ό, t ∈ Ι a b → HasDerivAt (fun x => F x t) (F' t) x₀) : IntervalIntegrable F' ÎŒ a b ∧ HasDerivAt (fun x => ∫ t in a..b, F x t ∂Ό) (∫ t in a..b, F' t ∂Ό) x₀ := by rw [← ae_restrict_iff' measurableSet_uIoc] at h_lipsch h_diff simp only [intervalIntegrable_iff] at hF_int bound_integrable ⊢ simp only [intervalIntegral_eq_integral_uIoc] have := hasDerivAt_integral_of_dominated_loc_of_lip ε_pos hF_meas hF_int hF'_meas h_lipsch bound_integrable h_diff exact ⟹this.1, this.2.const_smul _⟩ /-- Derivative under integral of `x ↩ ∫ F x a` at a given point `x₀ : 𝕜`, `𝕜 = ℝ` or `𝕜 = ℂ`, assuming `F x₀` is integrable, `x ↩ F x a` is differentiable on an interval around `x₀` for ae `a` (with interval radius independent of `a`) with derivative uniformly bounded by an integrable function, and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/ nonrec theorem hasDerivAt_integral_of_dominated_loc_of_deriv_le {F : 𝕜 → ℝ → E} {F' : 𝕜 → ℝ → E} {x₀ : 𝕜} (ε_pos : 0 < ε) (hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) (ÎŒ.restrict (Ι a b))) (hF_int : IntervalIntegrable (F x₀) ÎŒ a b) (hF'_meas : AEStronglyMeasurable (F' x₀) (ÎŒ.restrict (Ι a b))) (h_bound : ∀ᵐ t ∂Ό, t ∈ Ι a b → ∀ x ∈ ball x₀ ε, ‖F' x t‖ ≀ bound t) (bound_integrable : IntervalIntegrable bound ÎŒ a b) (h_diff : ∀ᵐ t ∂Ό, t ∈ Ι a b → ∀ x ∈ ball x₀ ε, HasDerivAt (fun x => F x t) (F' x t) x) : IntervalIntegrable (F' x₀) ÎŒ a b ∧ HasDerivAt (fun x => ∫ t in a..b, F x t ∂Ό) (∫ t in a..b, F' x₀ t ∂Ό) x₀ := by rw [← ae_restrict_iff' measurableSet_uIoc] at h_bound h_diff simp only [intervalIntegrable_iff] at hF_int bound_integrable ⊢ simp only [intervalIntegral_eq_integral_uIoc] have := hasDerivAt_integral_of_dominated_loc_of_deriv_le ε_pos hF_meas hF_int hF'_meas h_bound bound_integrable h_diff exact ⟹this.1, this.2.const_smul _⟩ end intervalIntegral
Analysis\Calculus\Rademacher.lean
/- Copyright (c) 2023 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.LineDeriv.Measurable import Mathlib.Analysis.Normed.Module.FiniteDimension import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.Analysis.BoundedVariation import Mathlib.MeasureTheory.Group.Integral import Mathlib.Analysis.Distribution.AEEqOfIntegralContDiff import Mathlib.MeasureTheory.Measure.Haar.Disintegration /-! # Rademacher's theorem: a Lipschitz function is differentiable almost everywhere This file proves Rademacher's theorem: a Lipschitz function between finite-dimensional real vector spaces is differentiable almost everywhere with respect to the Lebesgue measure. This is the content of `LipschitzWith.ae_differentiableAt`. Versions for functions which are Lipschitz on sets are also given (see `LipschitzOnWith.ae_differentiableWithinAt`). ## Implementation There are many proofs of Rademacher's theorem. We follow the one by Morrey, which is not the most elementary but maybe the most elegant once necessary prerequisites are set up. * Step 0: without loss of generality, one may assume that `f` is real-valued. * Step 1: Since a one-dimensional Lipschitz function has bounded variation, it is differentiable almost everywhere. With a Fubini argument, it follows that given any vector `v` then `f` is ae differentiable in the direction of `v`. See `LipschitzWith.ae_lineDifferentiableAt`. * Step 2: the line derivative `LineDeriv ℝ f x v` is ae linear in `v`. Morrey proves this by a duality argument, integrating against a smooth compactly supported function `g`, passing the derivative to `g` by integration by parts, and using the linearity of the derivative of `g`. See `LipschitzWith.ae_lineDeriv_sum_eq`. * Step 3: consider a countable dense set `s` of directions. Almost everywhere, the function `f` is line-differentiable in all these directions and the line derivative is linear. Approximating any direction by a direction in `s` and using the fact that `f` is Lipschitz to control the error, it follows that `f` is Fréchet-differentiable at these points. See `LipschitzWith.hasFderivAt_of_hasLineDerivAt_of_closure`. ## References * [Pertti Mattila, Geometry of sets and measures in Euclidean spaces, Theorem 7.3][Federer1996] -/ open Filter MeasureTheory Measure FiniteDimensional Metric Set Asymptotics open scoped NNReal ENNReal Topology variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] {C D : ℝ≥0} {f g : E → ℝ} {s : Set E} {ÎŒ : Measure E} [IsAddHaarMeasure ÎŒ] namespace LipschitzWith /-! ### Step 1: A Lipschitz function is ae differentiable in any given direction This follows from the one-dimensional result that a Lipschitz function on `ℝ` has bounded variation, and is therefore ae differentiable, together with a Fubini argument. -/ theorem ae_lineDifferentiableAt (hf : LipschitzWith C f) (v : E) : ∀ᵐ p ∂Ό, LineDifferentiableAt ℝ f p v := by let L : ℝ →L[ℝ] E := ContinuousLinearMap.smulRight (1 : ℝ →L[ℝ] ℝ) v suffices A : ∀ p, ∀ᵐ (t : ℝ) ∂volume, LineDifferentiableAt ℝ f (p + t • v) v from ae_mem_of_ae_add_linearMap_mem L.toLinearMap volume ÎŒ (measurableSet_lineDifferentiableAt hf.continuous) A intro p have : ∀ᵐ (s : ℝ), DifferentiableAt ℝ (fun t ↩ f (p + t • v)) s := (hf.comp ((LipschitzWith.const p).add L.lipschitz)).ae_differentiableAt_real filter_upwards [this] with s hs have h's : DifferentiableAt ℝ (fun t ↩ f (p + t • v)) (s + 0) := by simpa using hs have : DifferentiableAt ℝ (fun t ↩ s + t) 0 := differentiableAt_id.const_add _ simp only [LineDifferentiableAt] convert h's.comp 0 this with _ t simp only [LineDifferentiableAt, add_assoc, Function.comp_apply, add_smul] theorem memℒp_lineDeriv (hf : LipschitzWith C f) (v : E) : Memℒp (fun x ↩ lineDeriv ℝ f x v) ∞ ÎŒ := memℒp_top_of_bound (aestronglyMeasurable_lineDeriv hf.continuous ÎŒ) (C * ‖v‖) (eventually_of_forall (fun _x ↩ norm_lineDeriv_le_of_lipschitz ℝ hf)) theorem locallyIntegrable_lineDeriv (hf : LipschitzWith C f) (v : E) : LocallyIntegrable (fun x ↩ lineDeriv ℝ f x v) ÎŒ := (hf.memℒp_lineDeriv v).locallyIntegrable le_top /-! ### Step 2: the ae line derivative is linear Surprisingly, this is the hardest step. We prove it using an elegant but slightly sophisticated argument by Morrey, with a distributional flavor: we integrate against a smooth function, and push the derivative to the smooth function by integration by parts. As the derivative of a smooth function is linear, this gives the result. -/ theorem integral_inv_smul_sub_mul_tendsto_integral_lineDeriv_mul (hf : LipschitzWith C f) (hg : Integrable g ÎŒ) (v : E) : Tendsto (fun (t : ℝ) ↩ ∫ x, (t⁻¹ • (f (x + t • v) - f x)) * g x ∂Ό) (𝓝[>] 0) (𝓝 (∫ x, lineDeriv ℝ f x v * g x ∂Ό)) := by apply tendsto_integral_filter_of_dominated_convergence (fun x ↩ (C * ‖v‖) * ‖g x‖) · filter_upwards with t apply AEStronglyMeasurable.mul ?_ hg.aestronglyMeasurable apply aestronglyMeasurable_const.smul apply AEStronglyMeasurable.sub _ hf.continuous.measurable.aestronglyMeasurable apply AEMeasurable.aestronglyMeasurable exact hf.continuous.measurable.comp_aemeasurable' (aemeasurable_id'.add_const _) · filter_upwards [self_mem_nhdsWithin] with t (ht : 0 < t) filter_upwards with x calc ‖t⁻¹ • (f (x + t • v) - f x) * g x‖ = (t⁻¹ * ‖f (x + t • v) - f x‖) * ‖g x‖ := by simp [norm_mul, ht.le] _ ≀ (t⁻¹ * (C * ‖(x + t • v) - x‖)) * ‖g x‖ := by gcongr; exact LipschitzWith.norm_sub_le hf (x + t • v) x _ = (C * ‖v‖) *‖g x‖ := by field_simp [norm_smul, abs_of_nonneg ht.le]; ring · exact hg.norm.const_mul _ · filter_upwards [hf.ae_lineDifferentiableAt v] with x hx exact hx.hasLineDerivAt.tendsto_slope_zero_right.mul tendsto_const_nhds theorem integral_inv_smul_sub_mul_tendsto_integral_lineDeriv_mul' (hf : LipschitzWith C f) (h'f : HasCompactSupport f) (hg : Continuous g) (v : E) : Tendsto (fun (t : ℝ) ↩ ∫ x, (t⁻¹ • (f (x + t • v) - f x)) * g x ∂Ό) (𝓝[>] 0) (𝓝 (∫ x, lineDeriv ℝ f x v * g x ∂Ό)) := by let K := cthickening (‖v‖) (tsupport f) have K_compact : IsCompact K := IsCompact.cthickening h'f apply tendsto_integral_filter_of_dominated_convergence (K.indicator (fun x ↩ (C * ‖v‖) * ‖g x‖)) · filter_upwards with t apply AEStronglyMeasurable.mul ?_ hg.aestronglyMeasurable apply aestronglyMeasurable_const.smul apply AEStronglyMeasurable.sub _ hf.continuous.measurable.aestronglyMeasurable apply AEMeasurable.aestronglyMeasurable exact hf.continuous.measurable.comp_aemeasurable' (aemeasurable_id'.add_const _) · filter_upwards [Ioc_mem_nhdsWithin_Ioi' zero_lt_one] with t ht have t_pos : 0 < t := ht.1 filter_upwards with x by_cases hx : x ∈ K · calc ‖t⁻¹ • (f (x + t • v) - f x) * g x‖ = (t⁻¹ * ‖f (x + t • v) - f x‖) * ‖g x‖ := by simp [norm_mul, t_pos.le] _ ≀ (t⁻¹ * (C * ‖(x + t • v) - x‖)) * ‖g x‖ := by gcongr; exact LipschitzWith.norm_sub_le hf (x + t • v) x _ = (C * ‖v‖) *‖g x‖ := by field_simp [norm_smul, abs_of_nonneg t_pos.le]; ring _ = K.indicator (fun x ↩ (C * ‖v‖) * ‖g x‖) x := by rw [indicator_of_mem hx] · have A : f x = 0 := by rw [← Function.nmem_support] contrapose! hx exact self_subset_cthickening _ (subset_tsupport _ hx) have B : f (x + t • v) = 0 := by rw [← Function.nmem_support] contrapose! hx apply mem_cthickening_of_dist_le _ _ (‖v‖) (tsupport f) (subset_tsupport _ hx) simp only [dist_eq_norm, sub_add_cancel_left, norm_neg, norm_smul, Real.norm_eq_abs, abs_of_nonneg t_pos.le, norm_pos_iff] exact mul_le_of_le_one_left (norm_nonneg v) ht.2 simp only [B, A, _root_.sub_self, smul_eq_mul, mul_zero, zero_mul, norm_zero] exact indicator_nonneg (fun y _hy ↩ by positivity) _ · rw [integrable_indicator_iff K_compact.measurableSet] apply ContinuousOn.integrableOn_compact K_compact exact (Continuous.mul continuous_const hg.norm).continuousOn · filter_upwards [hf.ae_lineDifferentiableAt v] with x hx exact hx.hasLineDerivAt.tendsto_slope_zero_right.mul tendsto_const_nhds /-- Integration by parts formula for the line derivative of Lipschitz functions, assuming one of them is compactly supported. -/ theorem integral_lineDeriv_mul_eq (hf : LipschitzWith C f) (hg : LipschitzWith D g) (h'g : HasCompactSupport g) (v : E) : ∫ x, lineDeriv ℝ f x v * g x ∂Ό = ∫ x, lineDeriv ℝ g x (-v) * f x ∂Ό := by /- Write down the line derivative as the limit of `(f (x + t v) - f x) / t` and `(g (x - t v) - g x) / t`, and therefore the integrals as limits of the corresponding integrals thanks to the dominated convergence theorem. At fixed positive `t`, the integrals coincide (with the change of variables `y = x + t v`), so the limits also coincide. -/ have A : Tendsto (fun (t : ℝ) ↩ ∫ x, (t⁻¹ • (f (x + t • v) - f x)) * g x ∂Ό) (𝓝[>] 0) (𝓝 (∫ x, lineDeriv ℝ f x v * g x ∂Ό)) := integral_inv_smul_sub_mul_tendsto_integral_lineDeriv_mul hf (hg.continuous.integrable_of_hasCompactSupport h'g) v have B : Tendsto (fun (t : ℝ) ↩ ∫ x, (t⁻¹ • (g (x + t • (-v)) - g x)) * f x ∂Ό) (𝓝[>] 0) (𝓝 (∫ x, lineDeriv ℝ g x (-v) * f x ∂Ό)) := integral_inv_smul_sub_mul_tendsto_integral_lineDeriv_mul' hg h'g hf.continuous (-v) suffices S1 : ∀ (t : ℝ), ∫ x, (t⁻¹ • (f (x + t • v) - f x)) * g x ∂Ό = ∫ x, (t⁻¹ • (g (x + t • (-v)) - g x)) * f x ∂Ό by simp only [S1] at A; exact tendsto_nhds_unique A B intro t suffices S2 : ∫ x, (f (x + t • v) - f x) * g x ∂Ό = ∫ x, f x * (g (x + t • (-v)) - g x) ∂Ό by simp only [smul_eq_mul, mul_assoc, integral_mul_left, S2, mul_neg, mul_comm (f _)] have S3 : ∫ x, f (x + t • v) * g x ∂Ό = ∫ x, f x * g (x + t • (-v)) ∂Ό := by rw [← integral_add_right_eq_self _ (t • (-v))]; simp simp_rw [_root_.sub_mul, _root_.mul_sub] rw [integral_sub, integral_sub, S3] · apply Continuous.integrable_of_hasCompactSupport · exact hf.continuous.mul (hg.continuous.comp (continuous_add_right _)) · exact (h'g.comp_homeomorph (Homeomorph.addRight (t • (-v)))).mul_left · exact (hf.continuous.mul hg.continuous).integrable_of_hasCompactSupport h'g.mul_left · apply Continuous.integrable_of_hasCompactSupport · exact (hf.continuous.comp (continuous_add_right _)).mul hg.continuous · exact h'g.mul_left · exact (hf.continuous.mul hg.continuous).integrable_of_hasCompactSupport h'g.mul_left /-- The line derivative of a Lipschitz function is almost everywhere linear with respect to fixed coefficients. -/ theorem ae_lineDeriv_sum_eq (hf : LipschitzWith C f) {ι : Type*} (s : Finset ι) (a : ι → ℝ) (v : ι → E) : ∀ᵐ x ∂Ό, lineDeriv ℝ f x (∑ i ∈ s, a i • v i) = ∑ i ∈ s, a i • lineDeriv ℝ f x (v i) := by /- Clever argument by Morrey: integrate against a smooth compactly supported function `g`, switch the derivative to `g` by integration by parts, and use the linearity of the derivative of `g` to conclude that the initial integrals coincide. -/ apply ae_eq_of_integral_contDiff_smul_eq (hf.locallyIntegrable_lineDeriv _) (locallyIntegrable_finset_sum _ (fun i hi ↩ (hf.locallyIntegrable_lineDeriv (v i)).smul (a i))) (fun g g_smooth g_comp ↩ ?_) simp_rw [Finset.smul_sum] have A : ∀ i ∈ s, Integrable (fun x ↩ g x • (a i • fun x ↩ lineDeriv ℝ f x (v i)) x) ÎŒ := fun i hi ↩ (g_smooth.continuous.integrable_of_hasCompactSupport g_comp).smul_of_top_left ((hf.memℒp_lineDeriv (v i)).const_smul (a i)) rw [integral_finset_sum _ A] suffices S1 : ∫ x, lineDeriv ℝ f x (∑ i ∈ s, a i • v i) * g x ∂Ό = ∑ i ∈ s, a i * ∫ x, lineDeriv ℝ f x (v i) * g x ∂Ό by dsimp only [smul_eq_mul, Pi.smul_apply] simp_rw [← mul_assoc, mul_comm _ (a _), mul_assoc, integral_mul_left, mul_comm (g _), S1] suffices S2 : ∫ x, (∑ i ∈ s, a i * fderiv ℝ g x (v i)) * f x ∂Ό = ∑ i ∈ s, a i * ∫ x, fderiv ℝ g x (v i) * f x ∂Ό by obtain ⟹D, g_lip⟩ : ∃ D, LipschitzWith D g := ContDiff.lipschitzWith_of_hasCompactSupport g_comp g_smooth le_top simp_rw [integral_lineDeriv_mul_eq hf g_lip g_comp] simp_rw [(g_smooth.differentiable le_top).differentiableAt.lineDeriv_eq_fderiv] simp only [map_neg, _root_.map_sum, _root_.map_smul, smul_eq_mul, neg_mul] simp only [integral_neg, mul_neg, Finset.sum_neg_distrib, neg_inj] exact S2 suffices B : ∀ i ∈ s, Integrable (fun x ↩ a i * (fderiv ℝ g x (v i) * f x)) ÎŒ by simp_rw [Finset.sum_mul, mul_assoc, integral_finset_sum s B, integral_mul_left] intro i _hi let L : (E →L[ℝ] ℝ) → ℝ := fun f ↩ f (v i) change Integrable (fun x ↩ a i * ((L ∘ (fderiv ℝ g)) x * f x)) ÎŒ refine (Continuous.integrable_of_hasCompactSupport ?_ ?_).const_mul _ · exact ((g_smooth.continuous_fderiv le_top).clm_apply continuous_const).mul hf.continuous · exact ((g_comp.fderiv ℝ).comp_left rfl).mul_right /-! ### Step 3: construct the derivative using the line derivatives along a basis -/ theorem ae_exists_fderiv_of_countable (hf : LipschitzWith C f) {s : Set E} (hs : s.Countable) : ∀ᵐ x ∂Ό, ∃ (L : E →L[ℝ] ℝ), ∀ v ∈ s, HasLineDerivAt ℝ f (L v) x v := by have B := Basis.ofVectorSpace ℝ E have I1 : ∀ᵐ (x : E) ∂Ό, ∀ v ∈ s, lineDeriv ℝ f x (∑ i, (B.repr v i) • B i) = ∑ i, B.repr v i • lineDeriv ℝ f x (B i) := (ae_ball_iff hs).2 (fun v _ ↩ hf.ae_lineDeriv_sum_eq _ _ _) have I2 : ∀ᵐ (x : E) ∂Ό, ∀ v ∈ s, LineDifferentiableAt ℝ f x v := (ae_ball_iff hs).2 (fun v _ ↩ hf.ae_lineDifferentiableAt v) filter_upwards [I1, I2] with x hx h'x let L : E →L[ℝ] ℝ := LinearMap.toContinuousLinearMap (B.constr ℝ (fun i ↩ lineDeriv ℝ f x (B i))) refine ⟹L, fun v hv ↩ ?_⟩ have J : L v = lineDeriv ℝ f x v := by convert (hx v hv).symm <;> simp [L, B.sum_repr v] simpa [J] using (h'x v hv).hasLineDerivAt /-- If a Lipschitz functions has line derivatives in a dense set of directions, all of them given by a single continuous linear map `L`, then it admits `L` as Fréchet derivative. -/ theorem hasFderivAt_of_hasLineDerivAt_of_closure {f : E → F} (hf : LipschitzWith C f) {s : Set E} (hs : sphere 0 1 ⊆ closure s) {L : E →L[ℝ] F} {x : E} (hL : ∀ v ∈ s, HasLineDerivAt ℝ f (L v) x v) : HasFDerivAt f L x := by rw [hasFDerivAt_iff_isLittleO_nhds_zero, isLittleO_iff] intro ε εpos obtain ⟹ή, ÎŽpos, hΎ⟩ : ∃ ÎŽ, 0 < ÎŽ ∧ (C + ‖L‖ + 1) * ÎŽ = ε := ⟚ε / (C + ‖L‖ + 1), by positivity, mul_div_cancel₀ ε (by positivity)⟩ obtain ⟹q, hqs, q_fin, hq⟩ : ∃ q, q ⊆ s ∧ q.Finite ∧ sphere 0 1 ⊆ ⋃ y ∈ q, ball y ÎŽ := by have : sphere 0 1 ⊆ ⋃ y ∈ s, ball y ÎŽ := by apply hs.trans (fun z hz ↩ ?_) obtain ⟹y, ys, hy⟩ : ∃ y ∈ s, dist z y < ÎŽ := Metric.mem_closure_iff.1 hz ÎŽ ÎŽpos exact mem_biUnion ys hy exact (isCompact_sphere 0 1).elim_finite_subcover_image (fun y _hy ↩ isOpen_ball) this have I : ∀ᶠ t in 𝓝 (0 : ℝ), ∀ v ∈ q, ‖f (x + t • v) - f x - t • L v‖ ≀ ÎŽ * ‖t‖ := by apply (Finite.eventually_all q_fin).2 (fun v hv ↩ ?_) apply Asymptotics.IsLittleO.def ?_ ÎŽpos exact hasLineDerivAt_iff_isLittleO_nhds_zero.1 (hL v (hqs hv)) obtain ⟹r, r_pos, hr⟩ : ∃ (r : ℝ), 0 < r ∧ ∀ (t : ℝ), ‖t‖ < r → ∀ v ∈ q, ‖f (x + t • v) - f x - t • L v‖ ≀ ÎŽ * ‖t‖ := by rcases Metric.mem_nhds_iff.1 I with ⟹r, r_pos, hr⟩ exact ⟹r, r_pos, fun t ht v hv ↩ hr (mem_ball_zero_iff.2 ht) v hv⟩ apply Metric.mem_nhds_iff.2 ⟹r, r_pos, fun v hv ↩ ?_⟩ rcases eq_or_ne v 0 with rfl|v_ne · simp obtain ⟹w, ρ, w_mem, hvw, hρ⟩ : ∃ w ρ, w ∈ sphere 0 1 ∧ v = ρ • w ∧ ρ = ‖v‖ := by refine ⟹‖v‖⁻¹ • v, ‖v‖, by simp [norm_smul, inv_mul_cancel (norm_ne_zero_iff.2 v_ne)], ?_, rfl⟩ simp [smul_smul, mul_inv_cancel (norm_ne_zero_iff.2 v_ne)] have norm_rho : ‖ρ‖ = ρ := by rw [hρ, norm_norm] have rho_pos : 0 ≀ ρ := by simp [hρ] obtain ⟹y, yq, hy⟩ : ∃ y ∈ q, ‖w - y‖ < ÎŽ := by simpa [← dist_eq_norm] using hq w_mem have : ‖y - w‖ < ÎŽ := by rwa [norm_sub_rev] calc ‖f (x + v) - f x - L v‖ = ‖f (x + ρ • w) - f x - ρ • L w‖ := by simp [hvw] _ = ‖(f (x + ρ • w) - f (x + ρ • y)) + (ρ • L y - ρ • L w) + (f (x + ρ • y) - f x - ρ • L y)‖ := by congr; abel _ ≀ ‖f (x + ρ • w) - f (x + ρ • y)‖ + ‖ρ • L y - ρ • L w‖ + ‖f (x + ρ • y) - f x - ρ • L y‖ := norm_add₃_le _ _ _ _ ≀ C * ‖(x + ρ • w) - (x + ρ • y)‖ + ρ * (‖L‖ * ‖y - w‖) + ÎŽ * ρ := by gcongr · exact hf.norm_sub_le _ _ · rw [← smul_sub, norm_smul, norm_rho] gcongr exact L.lipschitz.norm_sub_le _ _ · conv_rhs => rw [← norm_rho] apply hr _ _ _ yq simpa [norm_rho, hρ] using hv _ ≀ C * (ρ * ÎŽ) + ρ * (‖L‖ * ÎŽ) + ÎŽ * ρ := by simp only [add_sub_add_left_eq_sub, ← smul_sub, norm_smul, norm_rho]; gcongr _ = ((C + ‖L‖ + 1) * ÎŽ) * ρ := by ring _ = ε * ‖v‖ := by rw [hÎŽ, hρ] /-- A real-valued function on a finite-dimensional space which is Lipschitz is differentiable almost everywere. Superseded by `LipschitzWith.ae_differentiableAt` which works for functions taking value in any finite-dimensional space. -/ theorem ae_differentiableAt_of_real (hf : LipschitzWith C f) : ∀ᵐ x ∂Ό, DifferentiableAt ℝ f x := by obtain ⟹s, s_count, s_dense⟩ : ∃ (s : Set E), s.Countable ∧ Dense s := TopologicalSpace.exists_countable_dense E have hs : sphere 0 1 ⊆ closure s := by rw [s_dense.closure_eq]; exact subset_univ _ filter_upwards [hf.ae_exists_fderiv_of_countable s_count] rintro x ⟹L, hL⟩ exact (hf.hasFderivAt_of_hasLineDerivAt_of_closure hs hL).differentiableAt end LipschitzWith variable [FiniteDimensional ℝ F] namespace LipschitzOnWith /-- A real-valued function on a finite-dimensional space which is Lipschitz on a set is differentiable almost everywere in this set. Superseded by `LipschitzOnWith.ae_differentiableWithinAt_of_mem` which works for functions taking value in any finite-dimensional space. -/ theorem ae_differentiableWithinAt_of_mem_of_real (hf : LipschitzOnWith C f s) : ∀ᵐ x ∂Ό, x ∈ s → DifferentiableWithinAt ℝ f s x := by obtain ⟹g, g_lip, hg⟩ : ∃ (g : E → ℝ), LipschitzWith C g ∧ EqOn f g s := hf.extend_real filter_upwards [g_lip.ae_differentiableAt_of_real] with x hx xs exact hx.differentiableWithinAt.congr hg (hg xs) /-- A function on a finite-dimensional space which is Lipschitz on a set and taking values in a product space is differentiable almost everywere in this set. Superseded by `LipschitzOnWith.ae_differentiableWithinAt_of_mem` which works for functions taking value in any finite-dimensional space. -/ theorem ae_differentiableWithinAt_of_mem_pi {ι : Type*} [Fintype ι] {f : E → ι → ℝ} {s : Set E} (hf : LipschitzOnWith C f s) : ∀ᵐ x ∂Ό, x ∈ s → DifferentiableWithinAt ℝ f s x := by have A : ∀ i : ι, LipschitzWith 1 (fun x : ι → ℝ ↩ x i) := fun i => LipschitzWith.eval i have : ∀ i : ι, ∀ᵐ x ∂Ό, x ∈ s → DifferentiableWithinAt ℝ (fun x : E ↩ f x i) s x := fun i ↩ by apply ae_differentiableWithinAt_of_mem_of_real exact LipschitzWith.comp_lipschitzOnWith (A i) hf filter_upwards [ae_all_iff.2 this] with x hx xs exact differentiableWithinAt_pi.2 (fun i ↩ hx i xs) /-- *Rademacher's theorem*: a function between finite-dimensional real vector spaces which is Lipschitz on a set is differentiable almost everywere in this set. -/ theorem ae_differentiableWithinAt_of_mem {f : E → F} (hf : LipschitzOnWith C f s) : ∀ᵐ x ∂Ό, x ∈ s → DifferentiableWithinAt ℝ f s x := by have A := (Basis.ofVectorSpace ℝ F).equivFun.toContinuousLinearEquiv suffices H : ∀ᵐ x ∂Ό, x ∈ s → DifferentiableWithinAt ℝ (A ∘ f) s x by filter_upwards [H] with x hx xs have : f = (A.symm ∘ A) ∘ f := by simp only [ContinuousLinearEquiv.symm_comp_self, Function.id_comp] rw [this] exact A.symm.differentiableAt.comp_differentiableWithinAt x (hx xs) apply ae_differentiableWithinAt_of_mem_pi exact A.lipschitz.comp_lipschitzOnWith hf /-- *Rademacher's theorem*: a function between finite-dimensional real vector spaces which is Lipschitz on a set is differentiable almost everywere in this set. -/ theorem ae_differentiableWithinAt {f : E → F} (hf : LipschitzOnWith C f s) (hs : MeasurableSet s) : ∀ᵐ x ∂(ÎŒ.restrict s), DifferentiableWithinAt ℝ f s x := by rw [ae_restrict_iff' hs] exact hf.ae_differentiableWithinAt_of_mem end LipschitzOnWith /-- *Rademacher's theorem*: a Lipschitz function between finite-dimensional real vector spaces is differentiable almost everywhere. -/ theorem LipschitzWith.ae_differentiableAt {f : E → F} (h : LipschitzWith C f) : ∀ᵐ x ∂Ό, DifferentiableAt ℝ f x := by rw [← lipschitzOnWith_univ] at h simpa [differentiableWithinAt_univ] using h.ae_differentiableWithinAt_of_mem
Analysis\Calculus\SmoothSeries.lean
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Calculus.UniformLimitsDeriv import Mathlib.Topology.Algebra.InfiniteSum.Module import Mathlib.Analysis.NormedSpace.FunctionSeries /-! # Smoothness of series We show that series of functions are differentiable, or smooth, when each individual function in the series is and additionally suitable uniform summable bounds are satisfied. More specifically, * `differentiable_tsum` ensures that a series of differentiable functions is differentiable. * `contDiff_tsum` ensures that a series of smooth functions is smooth. We also give versions of these statements which are localized to a set. -/ open Set Metric TopologicalSpace Function Asymptotics Filter open scoped Topology NNReal variable {α β 𝕜 E F : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [CompleteSpace F] {u : α → ℝ} /-! ### Differentiability -/ variable [NormedSpace 𝕜 F] variable {f : α → E → F} {f' : α → E → E →L[𝕜] F} {g : α → 𝕜 → F} {g' : α → 𝕜 → F} {v : ℕ → α → ℝ} {s : Set E} {t : Set 𝕜} {x₀ x : E} {y₀ y : 𝕜} {N : ℕ∞} /-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series converges everywhere on the set. -/ theorem summable_of_summable_hasFDerivAt_of_isPreconnected (hu : Summable u) (hs : IsOpen s) (h's : IsPreconnected s) (hf : ∀ n x, x ∈ s → HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, x ∈ s → ‖f' n x‖ ≀ u n) (hx₀ : x₀ ∈ s) (hf0 : Summable (f · x₀)) (hx : x ∈ s) : Summable fun n => f n x := by haveI := Classical.decEq α rw [summable_iff_cauchySeq_finset] at hf0 ⊢ have A : UniformCauchySeqOn (fun t : Finset α => fun x => ∑ i ∈ t, f' i x) atTop s := (tendstoUniformlyOn_tsum hu hf').uniformCauchySeqOn -- Porting note: Lean 4 failed to find `f` by unification refine cauchy_map_of_uniformCauchySeqOn_fderiv (f := fun t x ↩ ∑ i ∈ t, f i x) hs h's A (fun t y hy => ?_) hx₀ hx hf0 exact HasFDerivAt.sum fun i _ => hf i y hy /-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series converges everywhere on the set. -/ theorem summable_of_summable_hasDerivAt_of_isPreconnected (hu : Summable u) (ht : IsOpen t) (h't : IsPreconnected t) (hg : ∀ n y, y ∈ t → HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, y ∈ t → ‖g' n y‖ ≀ u n) (hy₀ : y₀ ∈ t) (hg0 : Summable (g · y₀)) (hy : y ∈ t) : Summable fun n => g n y := by simp_rw [hasDerivAt_iff_hasFDerivAt] at hg refine summable_of_summable_hasFDerivAt_of_isPreconnected hu ht h't hg ?_ hy₀ hg0 hy simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul] /-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable on the set and its derivative is the sum of the derivatives. -/ theorem hasFDerivAt_tsum_of_isPreconnected (hu : Summable u) (hs : IsOpen s) (h's : IsPreconnected s) (hf : ∀ n x, x ∈ s → HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, x ∈ s → ‖f' n x‖ ≀ u n) (hx₀ : x₀ ∈ s) (hf0 : Summable fun n => f n x₀) (hx : x ∈ s) : HasFDerivAt (fun y => ∑' n, f n y) (∑' n, f' n x) x := by classical have A : ∀ x : E, x ∈ s → Tendsto (fun t : Finset α => ∑ n ∈ t, f n x) atTop (𝓝 (∑' n, f n x)) := by intro y hy apply Summable.hasSum exact summable_of_summable_hasFDerivAt_of_isPreconnected hu hs h's hf hf' hx₀ hf0 hy refine hasFDerivAt_of_tendstoUniformlyOn hs (tendstoUniformlyOn_tsum hu hf') (fun t y hy => ?_) A _ hx exact HasFDerivAt.sum fun n _ => hf n y hy /-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable on the set and its derivative is the sum of the derivatives. -/ theorem hasDerivAt_tsum_of_isPreconnected (hu : Summable u) (ht : IsOpen t) (h't : IsPreconnected t) (hg : ∀ n y, y ∈ t → HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, y ∈ t → ‖g' n y‖ ≀ u n) (hy₀ : y₀ ∈ t) (hg0 : Summable fun n => g n y₀) (hy : y ∈ t) : HasDerivAt (fun z => ∑' n, g n z) (∑' n, g' n y) y := by simp_rw [hasDerivAt_iff_hasFDerivAt] at hg ⊢ convert hasFDerivAt_tsum_of_isPreconnected hu ht h't hg ?_ hy₀ hg0 hy · exact (ContinuousLinearMap.smulRightL 𝕜 𝕜 F 1).map_tsum <| .of_norm_bounded u hu fun n ↩ hg' n y hy · simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul] /-- Consider a series of functions `∑' n, f n x`. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series converges everywhere. -/ theorem summable_of_summable_hasFDerivAt (hu : Summable u) (hf : ∀ n x, HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, ‖f' n x‖ ≀ u n) (hf0 : Summable fun n => f n x₀) (x : E) : Summable fun n => f n x := by let _ : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _ exact summable_of_summable_hasFDerivAt_of_isPreconnected hu isOpen_univ isPreconnected_univ (fun n x _ => hf n x) (fun n x _ => hf' n x) (mem_univ _) hf0 (mem_univ _) /-- Consider a series of functions `∑' n, f n x`. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series converges everywhere. -/ theorem summable_of_summable_hasDerivAt (hu : Summable u) (hg : ∀ n y, HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, ‖g' n y‖ ≀ u n) (hg0 : Summable fun n => g n y₀) (y : 𝕜) : Summable fun n => g n y := by exact summable_of_summable_hasDerivAt_of_isPreconnected hu isOpen_univ isPreconnected_univ (fun n x _ => hg n x) (fun n x _ => hg' n x) (mem_univ _) hg0 (mem_univ _) /-- Consider a series of functions `∑' n, f n x`. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable and its derivative is the sum of the derivatives. -/ theorem hasFDerivAt_tsum (hu : Summable u) (hf : ∀ n x, HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, ‖f' n x‖ ≀ u n) (hf0 : Summable fun n => f n x₀) (x : E) : HasFDerivAt (fun y => ∑' n, f n y) (∑' n, f' n x) x := by let A : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _ exact hasFDerivAt_tsum_of_isPreconnected hu isOpen_univ isPreconnected_univ (fun n x _ => hf n x) (fun n x _ => hf' n x) (mem_univ _) hf0 (mem_univ _) /-- Consider a series of functions `∑' n, f n x`. If the series converges at a point, and all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable and its derivative is the sum of the derivatives. -/ theorem hasDerivAt_tsum (hu : Summable u) (hg : ∀ n y, HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, ‖g' n y‖ ≀ u n) (hg0 : Summable fun n => g n y₀) (y : 𝕜) : HasDerivAt (fun z => ∑' n, g n z) (∑' n, g' n y) y := by exact hasDerivAt_tsum_of_isPreconnected hu isOpen_univ isPreconnected_univ (fun n y _ => hg n y) (fun n y _ => hg' n y) (mem_univ _) hg0 (mem_univ _) /-- Consider a series of functions `∑' n, f n x`. If all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable. Note that our assumptions do not ensure the pointwise convergence, but if there is no pointwise convergence then the series is zero everywhere so the result still holds. -/ theorem differentiable_tsum (hu : Summable u) (hf : ∀ n x, HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, ‖f' n x‖ ≀ u n) : Differentiable 𝕜 fun y => ∑' n, f n y := by by_cases h : ∃ x₀, Summable fun n => f n x₀ · rcases h with ⟹x₀, hf0⟩ intro x exact (hasFDerivAt_tsum hu hf hf' hf0 x).differentiableAt · push_neg at h have : (fun x => ∑' n, f n x) = 0 := by ext1 x; exact tsum_eq_zero_of_not_summable (h x) rw [this] exact differentiable_const 0 /-- Consider a series of functions `∑' n, f n x`. If all functions in the series are differentiable with a summable bound on the derivatives, then the series is differentiable. Note that our assumptions do not ensure the pointwise convergence, but if there is no pointwise convergence then the series is zero everywhere so the result still holds. -/ theorem differentiable_tsum' (hu : Summable u) (hg : ∀ n y, HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, ‖g' n y‖ ≀ u n) : Differentiable 𝕜 fun z => ∑' n, g n z := by simp_rw [hasDerivAt_iff_hasFDerivAt] at hg refine differentiable_tsum hu hg ?_ simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul] theorem fderiv_tsum_apply (hu : Summable u) (hf : ∀ n, Differentiable 𝕜 (f n)) (hf' : ∀ n x, ‖fderiv 𝕜 (f n) x‖ ≀ u n) (hf0 : Summable fun n => f n x₀) (x : E) : fderiv 𝕜 (fun y => ∑' n, f n y) x = ∑' n, fderiv 𝕜 (f n) x := (hasFDerivAt_tsum hu (fun n x => (hf n x).hasFDerivAt) hf' hf0 _).fderiv theorem deriv_tsum_apply (hu : Summable u) (hg : ∀ n, Differentiable 𝕜 (g n)) (hg' : ∀ n y, ‖deriv (g n) y‖ ≀ u n) (hg0 : Summable fun n => g n y₀) (y : 𝕜) : deriv (fun z => ∑' n, g n z) y = ∑' n, deriv (g n) y := (hasDerivAt_tsum hu (fun n y => (hg n y).hasDerivAt) hg' hg0 _).deriv theorem fderiv_tsum (hu : Summable u) (hf : ∀ n, Differentiable 𝕜 (f n)) (hf' : ∀ n x, ‖fderiv 𝕜 (f n) x‖ ≀ u n) (hf0 : Summable fun n => f n x₀) : (fderiv 𝕜 fun y => ∑' n, f n y) = fun x => ∑' n, fderiv 𝕜 (f n) x := by ext1 x exact fderiv_tsum_apply hu hf hf' hf0 x theorem deriv_tsum (hu : Summable u) (hg : ∀ n, Differentiable 𝕜 (g n)) (hg' : ∀ n y, ‖deriv (g n) y‖ ≀ u n) (hg0 : Summable fun n => g n y₀) : (deriv fun y => ∑' n, g n y) = fun y => ∑' n, deriv (g n) y := by ext1 x exact deriv_tsum_apply hu hg hg' hg0 x /-! ### Higher smoothness -/ /-- Consider a series of smooth functions, with summable uniform bounds on the successive derivatives. Then the iterated derivative of the sum is the sum of the iterated derivative. -/ theorem iteratedFDeriv_tsum (hf : ∀ i, ContDiff 𝕜 N (f i)) (hv : ∀ k : ℕ, (k : ℕ∞) ≀ N → Summable (v k)) (h'f : ∀ (k : ℕ) (i : α) (x : E), (k : ℕ∞) ≀ N → ‖iteratedFDeriv 𝕜 k (f i) x‖ ≀ v k i) {k : ℕ} (hk : (k : ℕ∞) ≀ N) : (iteratedFDeriv 𝕜 k fun y => ∑' n, f n y) = fun x => ∑' n, iteratedFDeriv 𝕜 k (f n) x := by induction' k with k IH · ext1 x simp_rw [iteratedFDeriv_zero_eq_comp] exact (continuousMultilinearCurryFin0 𝕜 E F).symm.toContinuousLinearEquiv.map_tsum · have h'k : (k : ℕ∞) < N := lt_of_lt_of_le (WithTop.coe_lt_coe.2 (Nat.lt_succ_self _)) hk have A : Summable fun n => iteratedFDeriv 𝕜 k (f n) 0 := .of_norm_bounded (v k) (hv k h'k.le) fun n => h'f k n 0 h'k.le simp_rw [iteratedFDeriv_succ_eq_comp_left, IH h'k.le] rw [fderiv_tsum (hv _ hk) (fun n => (hf n).differentiable_iteratedFDeriv h'k) _ A] · ext1 x exact (continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (k + 1) => E) F).toContinuousLinearEquiv.map_tsum · intro n x simpa only [iteratedFDeriv_succ_eq_comp_left, LinearIsometryEquiv.norm_map, comp_apply] using h'f k.succ n x hk /-- Consider a series of smooth functions, with summable uniform bounds on the successive derivatives. Then the iterated derivative of the sum is the sum of the iterated derivative. -/ theorem iteratedFDeriv_tsum_apply (hf : ∀ i, ContDiff 𝕜 N (f i)) (hv : ∀ k : ℕ, (k : ℕ∞) ≀ N → Summable (v k)) (h'f : ∀ (k : ℕ) (i : α) (x : E), (k : ℕ∞) ≀ N → ‖iteratedFDeriv 𝕜 k (f i) x‖ ≀ v k i) {k : ℕ} (hk : (k : ℕ∞) ≀ N) (x : E) : iteratedFDeriv 𝕜 k (fun y => ∑' n, f n y) x = ∑' n, iteratedFDeriv 𝕜 k (f n) x := by rw [iteratedFDeriv_tsum hf hv h'f hk] /-- Consider a series of functions `∑' i, f i x`. Assume that each individual function `f i` is of class `C^N`, and moreover there is a uniform summable upper bound on the `k`-th derivative for each `k ≀ N`. Then the series is also `C^N`. -/ theorem contDiff_tsum (hf : ∀ i, ContDiff 𝕜 N (f i)) (hv : ∀ k : ℕ, (k : ℕ∞) ≀ N → Summable (v k)) (h'f : ∀ (k : ℕ) (i : α) (x : E), (k : ℕ∞) ≀ N → ‖iteratedFDeriv 𝕜 k (f i) x‖ ≀ v k i) : ContDiff 𝕜 N fun x => ∑' i, f i x := by rw [contDiff_iff_continuous_differentiable] constructor · intro m hm rw [iteratedFDeriv_tsum hf hv h'f hm] refine continuous_tsum ?_ (hv m hm) ?_ · intro i exact ContDiff.continuous_iteratedFDeriv hm (hf i) · intro n x exact h'f _ _ _ hm · intro m hm have h'm : ((m + 1 : ℕ) : ℕ∞) ≀ N := by simpa only [ENat.coe_add, ENat.coe_one] using ENat.add_one_le_of_lt hm rw [iteratedFDeriv_tsum hf hv h'f hm.le] have A : ∀ n x, HasFDerivAt (iteratedFDeriv 𝕜 m (f n)) (fderiv 𝕜 (iteratedFDeriv 𝕜 m (f n)) x) x := fun n x => (ContDiff.differentiable_iteratedFDeriv hm (hf n)).differentiableAt.hasFDerivAt refine differentiable_tsum (hv _ h'm) A fun n x => ?_ rw [fderiv_iteratedFDeriv, comp_apply, LinearIsometryEquiv.norm_map] exact h'f _ _ _ h'm /-- Consider a series of functions `∑' i, f i x`. Assume that each individual function `f i` is of class `C^N`, and moreover there is a uniform summable upper bound on the `k`-th derivative for each `k ≀ N` (except maybe for finitely many `i`s). Then the series is also `C^N`. -/ theorem contDiff_tsum_of_eventually (hf : ∀ i, ContDiff 𝕜 N (f i)) (hv : ∀ k : ℕ, (k : ℕ∞) ≀ N → Summable (v k)) (h'f : ∀ k : ℕ, (k : ℕ∞) ≀ N → ∀ᶠ i in (Filter.cofinite : Filter α), ∀ x : E, ‖iteratedFDeriv 𝕜 k (f i) x‖ ≀ v k i) : ContDiff 𝕜 N fun x => ∑' i, f i x := by classical refine contDiff_iff_forall_nat_le.2 fun m hm => ?_ let t : Set α := { i : α | ¬∀ k : ℕ, k ∈ Finset.range (m + 1) → ∀ x, ‖iteratedFDeriv 𝕜 k (f i) x‖ ≀ v k i } have ht : Set.Finite t := haveI A : ∀ᶠ i in (Filter.cofinite : Filter α), ∀ k : ℕ, k ∈ Finset.range (m + 1) → ∀ x : E, ‖iteratedFDeriv 𝕜 k (f i) x‖ ≀ v k i := by rw [eventually_all_finset] intro i hi apply h'f simp only [Finset.mem_range_succ_iff] at hi exact (WithTop.coe_le_coe.2 hi).trans hm eventually_cofinite.2 A let T : Finset α := ht.toFinset have : (fun x => ∑' i, f i x) = (fun x => ∑ i ∈ T, f i x) + fun x => ∑' i : { i // i ∉ T }, f i x := by ext1 x refine (sum_add_tsum_subtype_compl ?_ T).symm refine .of_norm_bounded_eventually _ (hv 0 (zero_le _)) ?_ filter_upwards [h'f 0 (zero_le _)] with i hi simpa only [norm_iteratedFDeriv_zero] using hi x rw [this] apply (ContDiff.sum fun i _ => (hf i).of_le hm).add have h'u : ∀ k : ℕ, (k : ℕ∞) ≀ m → Summable (v k ∘ ((↑) : { i // i ∉ T } → α)) := fun k hk => (hv k (hk.trans hm)).subtype _ refine contDiff_tsum (fun i => (hf i).of_le hm) h'u ?_ rintro k ⟹i, hi⟩ x hk simp only [t, T, Finite.mem_toFinset, mem_setOf_eq, Finset.mem_range, not_forall, not_le, exists_prop, not_exists, not_and, not_lt] at hi exact hi k (Nat.lt_succ_iff.2 (WithTop.coe_le_coe.1 hk)) x
Analysis\Calculus\TangentCone.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Convex.Topology import Mathlib.Analysis.Normed.Module.Basic import Mathlib.Analysis.SpecificLimits.Basic /-! # Tangent cone In this file, we define two predicates `UniqueDiffWithinAt 𝕜 s x` and `UniqueDiffOn 𝕜 s` ensuring that, if a function has two derivatives, then they have to coincide. As a direct definition of this fact (quantifying on all target types and all functions) would depend on universes, we use a more intrinsic definition: if all the possible tangent directions to the set `s` at the point `x` span a dense subset of the whole subset, it is easy to check that the derivative has to be unique. Therefore, we introduce the set of all tangent directions, named `tangentConeAt`, and express `UniqueDiffWithinAt` and `UniqueDiffOn` in terms of it. One should however think of this definition as an implementation detail: the only reason to introduce the predicates `UniqueDiffWithinAt` and `UniqueDiffOn` is to ensure the uniqueness of the derivative. This is why their names reflect their uses, and not how they are defined. ## Implementation details Note that this file is imported by `Fderiv.Basic`. Hence, derivatives are not defined yet. The property of uniqueness of the derivative is therefore proved in `Fderiv.Basic`, but based on the properties of the tangent cone we prove here. -/ variable (𝕜 : Type*) [NontriviallyNormedField 𝕜] open Filter Set open Topology section TangentCone variable {E : Type*} [AddCommMonoid E] [Module 𝕜 E] [TopologicalSpace E] /-- The set of all tangent directions to the set `s` at the point `x`. -/ def tangentConeAt (s : Set E) (x : E) : Set E := { y : E | ∃ (c : ℕ → 𝕜) (d : ℕ → E), (∀ᶠ n in atTop, x + d n ∈ s) ∧ Tendsto (fun n => ‖c n‖) atTop atTop ∧ Tendsto (fun n => c n • d n) atTop (𝓝 y) } /-- A property ensuring that the tangent cone to `s` at `x` spans a dense subset of the whole space. The main role of this property is to ensure that the differential within `s` at `x` is unique, hence this name. The uniqueness it asserts is proved in `UniqueDiffWithinAt.eq` in `Fderiv.Basic`. To avoid pathologies in dimension 0, we also require that `x` belongs to the closure of `s` (which is automatic when `E` is not `0`-dimensional). -/ @[mk_iff] structure UniqueDiffWithinAt (s : Set E) (x : E) : Prop where dense_tangentCone : Dense (Submodule.span 𝕜 (tangentConeAt 𝕜 s x) : Set E) mem_closure : x ∈ closure s /-- A property ensuring that the tangent cone to `s` at any of its points spans a dense subset of the whole space. The main role of this property is to ensure that the differential along `s` is unique, hence this name. The uniqueness it asserts is proved in `UniqueDiffOn.eq` in `Fderiv.Basic`. -/ def UniqueDiffOn (s : Set E) : Prop := ∀ x ∈ s, UniqueDiffWithinAt 𝕜 s x end TangentCone variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G] variable {𝕜} {x y : E} {s t : Set E} section TangentCone -- This section is devoted to the properties of the tangent cone. open NormedField theorem mem_tangentConeAt_of_pow_smul {r : 𝕜} (hr₀ : r ≠ 0) (hr : ‖r‖ < 1) (hs : ∀ᶠ n : ℕ in atTop, x + r ^ n • y ∈ s) : y ∈ tangentConeAt 𝕜 s x := by refine ⟹fun n ↩ (r ^ n)⁻¹, fun n ↩ r ^ n • y, hs, ?_, ?_⟩ · simp only [norm_inv, norm_pow, ← inv_pow] exact tendsto_pow_atTop_atTop_of_one_lt <| one_lt_inv (norm_pos_iff.2 hr₀) hr · simp only [inv_smul_smul₀ (pow_ne_zero _ hr₀), tendsto_const_nhds] theorem tangentCone_univ : tangentConeAt 𝕜 univ x = univ := let ⟹_r, hr₀, hr⟩ := exists_norm_lt_one 𝕜 eq_univ_of_forall fun _ ↩ mem_tangentConeAt_of_pow_smul (norm_pos_iff.1 hr₀) hr <| eventually_of_forall fun _ ↩ mem_univ _ theorem tangentCone_mono (h : s ⊆ t) : tangentConeAt 𝕜 s x ⊆ tangentConeAt 𝕜 t x := by rintro y ⟹c, d, ds, ctop, clim⟩ exact ⟹c, d, mem_of_superset ds fun n hn => h hn, ctop, clim⟩ /-- Auxiliary lemma ensuring that, under the assumptions defining the tangent cone, the sequence `d` tends to 0 at infinity. -/ theorem tangentConeAt.lim_zero {α : Type*} (l : Filter α) {c : α → 𝕜} {d : α → E} (hc : Tendsto (fun n => ‖c n‖) l atTop) (hd : Tendsto (fun n => c n • d n) l (𝓝 y)) : Tendsto d l (𝓝 0) := by have A : Tendsto (fun n => ‖c n‖⁻¹) l (𝓝 0) := tendsto_inv_atTop_zero.comp hc have B : Tendsto (fun n => ‖c n • d n‖) l (𝓝 ‖y‖) := (continuous_norm.tendsto _).comp hd have C : Tendsto (fun n => ‖c n‖⁻¹ * ‖c n • d n‖) l (𝓝 (0 * ‖y‖)) := A.mul B rw [zero_mul] at C have : ∀ᶠ n in l, ‖c n‖⁻¹ * ‖c n • d n‖ = ‖d n‖ := by refine (eventually_ne_of_tendsto_norm_atTop hc 0).mono fun n hn => ?_ rw [norm_smul, ← mul_assoc, inv_mul_cancel, one_mul] rwa [Ne, norm_eq_zero] have D : Tendsto (fun n => ‖d n‖) l (𝓝 0) := Tendsto.congr' this C rw [tendsto_zero_iff_norm_tendsto_zero] exact D theorem tangentCone_mono_nhds (h : 𝓝[s] x ≀ 𝓝[t] x) : tangentConeAt 𝕜 s x ⊆ tangentConeAt 𝕜 t x := by rintro y ⟹c, d, ds, ctop, clim⟩ refine ⟹c, d, ?_, ctop, clim⟩ suffices Tendsto (fun n => x + d n) atTop (𝓝[t] x) from tendsto_principal.1 (tendsto_inf.1 this).2 refine (tendsto_inf.2 ⟹?_, tendsto_principal.2 ds⟩).mono_right h simpa only [add_zero] using tendsto_const_nhds.add (tangentConeAt.lim_zero atTop ctop clim) /-- Tangent cone of `s` at `x` depends only on `𝓝[s] x`. -/ theorem tangentCone_congr (h : 𝓝[s] x = 𝓝[t] x) : tangentConeAt 𝕜 s x = tangentConeAt 𝕜 t x := Subset.antisymm (tangentCone_mono_nhds <| le_of_eq h) (tangentCone_mono_nhds <| le_of_eq h.symm) /-- Intersecting with a neighborhood of the point does not change the tangent cone. -/ theorem tangentCone_inter_nhds (ht : t ∈ 𝓝 x) : tangentConeAt 𝕜 (s ∩ t) x = tangentConeAt 𝕜 s x := tangentCone_congr (nhdsWithin_restrict' _ ht).symm /-- The tangent cone of a product contains the tangent cone of its left factor. -/ theorem subset_tangentCone_prod_left {t : Set F} {y : F} (ht : y ∈ closure t) : LinearMap.inl 𝕜 E F '' tangentConeAt 𝕜 s x ⊆ tangentConeAt 𝕜 (s ×ˢ t) (x, y) := by rintro _ ⟹v, ⟹c, d, hd, hc, hy⟩, rfl⟩ have : ∀ n, ∃ d', y + d' ∈ t ∧ ‖c n • d'‖ < ((1 : ℝ) / 2) ^ n := by intro n rcases mem_closure_iff_nhds.1 ht _ (eventually_nhds_norm_smul_sub_lt (c n) y (pow_pos one_half_pos n)) with ⟹z, hz, hzt⟩ exact ⟹z - y, by simpa using hzt, by simpa using hz⟩ choose d' hd' using this refine ⟹c, fun n => (d n, d' n), ?_, hc, ?_⟩ · show ∀ᶠ n in atTop, (x, y) + (d n, d' n) ∈ s ×ˢ t filter_upwards [hd] with n hn simp [hn, (hd' n).1] · apply Tendsto.prod_mk_nhds hy _ refine squeeze_zero_norm (fun n => (hd' n).2.le) ?_ exact tendsto_pow_atTop_nhds_zero_of_lt_one one_half_pos.le one_half_lt_one /-- The tangent cone of a product contains the tangent cone of its right factor. -/ theorem subset_tangentCone_prod_right {t : Set F} {y : F} (hs : x ∈ closure s) : LinearMap.inr 𝕜 E F '' tangentConeAt 𝕜 t y ⊆ tangentConeAt 𝕜 (s ×ˢ t) (x, y) := by rintro _ ⟹w, ⟹c, d, hd, hc, hy⟩, rfl⟩ have : ∀ n, ∃ d', x + d' ∈ s ∧ ‖c n • d'‖ < ((1 : ℝ) / 2) ^ n := by intro n rcases mem_closure_iff_nhds.1 hs _ (eventually_nhds_norm_smul_sub_lt (c n) x (pow_pos one_half_pos n)) with ⟹z, hz, hzs⟩ exact ⟹z - x, by simpa using hzs, by simpa using hz⟩ choose d' hd' using this refine ⟹c, fun n => (d' n, d n), ?_, hc, ?_⟩ · show ∀ᶠ n in atTop, (x, y) + (d' n, d n) ∈ s ×ˢ t filter_upwards [hd] with n hn simp [hn, (hd' n).1] · apply Tendsto.prod_mk_nhds _ hy refine squeeze_zero_norm (fun n => (hd' n).2.le) ?_ exact tendsto_pow_atTop_nhds_zero_of_lt_one one_half_pos.le one_half_lt_one /-- The tangent cone of a product contains the tangent cone of each factor. -/ theorem mapsTo_tangentCone_pi {ι : Type*} [DecidableEq ι] {E : ι → Type*} [∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] {s : ∀ i, Set (E i)} {x : ∀ i, E i} {i : ι} (hi : ∀ j ≠ i, x j ∈ closure (s j)) : MapsTo (LinearMap.single i : E i →ₗ[𝕜] ∀ j, E j) (tangentConeAt 𝕜 (s i) (x i)) (tangentConeAt 𝕜 (Set.pi univ s) x) := by rintro w ⟹c, d, hd, hc, hy⟩ have : ∀ n, ∀ j ≠ i, ∃ d', x j + d' ∈ s j ∧ ‖c n • d'‖ < (1 / 2 : ℝ) ^ n := fun n j hj ↩ by rcases mem_closure_iff_nhds.1 (hi j hj) _ (eventually_nhds_norm_smul_sub_lt (c n) (x j) (pow_pos one_half_pos n)) with ⟹z, hz, hzs⟩ exact ⟹z - x j, by simpa using hzs, by simpa using hz⟩ choose! d' hd's hcd' using this refine ⟹c, fun n => Function.update (d' n) i (d n), hd.mono fun n hn j _ => ?_, hc, tendsto_pi_nhds.2 fun j => ?_⟩ · rcases em (j = i) with (rfl | hj) <;> simp [*] · rcases em (j = i) with (rfl | hj) · simp [hy] · suffices Tendsto (fun n => c n • d' n j) atTop (𝓝 0) by simpa [hj] refine squeeze_zero_norm (fun n => (hcd' n j hj).le) ?_ exact tendsto_pow_atTop_nhds_zero_of_lt_one one_half_pos.le one_half_lt_one /-- If a subset of a real vector space contains an open segment, then the direction of this segment belongs to the tangent cone at its endpoints. -/ theorem mem_tangentCone_of_openSegment_subset {s : Set G} {x y : G} (h : openSegment ℝ x y ⊆ s) : y - x ∈ tangentConeAt ℝ s x := by refine mem_tangentConeAt_of_pow_smul one_half_pos.ne' (by norm_num) ?_ refine (eventually_ne_atTop 0).mono fun n hn ↩ (h ?_) rw [openSegment_eq_image] refine ⟹(1 / 2) ^ n, ⟹?_, ?_⟩, ?_⟩ · exact pow_pos one_half_pos _ · exact pow_lt_one one_half_pos.le one_half_lt_one hn · simp only [sub_smul, one_smul, smul_sub]; abel /-- If a subset of a real vector space contains a segment, then the direction of this segment belongs to the tangent cone at its endpoints. -/ theorem mem_tangentCone_of_segment_subset {s : Set G} {x y : G} (h : segment ℝ x y ⊆ s) : y - x ∈ tangentConeAt ℝ s x := mem_tangentCone_of_openSegment_subset ((openSegment_subset_segment ℝ x y).trans h) end TangentCone section UniqueDiff /-! ### Properties of `UniqueDiffWithinAt` and `UniqueDiffOn` This section is devoted to properties of the predicates `UniqueDiffWithinAt` and `UniqueDiffOn`. -/ theorem UniqueDiffOn.uniqueDiffWithinAt {s : Set E} {x} (hs : UniqueDiffOn 𝕜 s) (h : x ∈ s) : UniqueDiffWithinAt 𝕜 s x := hs x h theorem uniqueDiffWithinAt_univ : UniqueDiffWithinAt 𝕜 univ x := by rw [uniqueDiffWithinAt_iff, tangentCone_univ] simp theorem uniqueDiffOn_univ : UniqueDiffOn 𝕜 (univ : Set E) := fun _ _ => uniqueDiffWithinAt_univ theorem uniqueDiffOn_empty : UniqueDiffOn 𝕜 (∅ : Set E) := fun _ hx => hx.elim theorem UniqueDiffWithinAt.congr_pt (h : UniqueDiffWithinAt 𝕜 s x) (hy : x = y) : UniqueDiffWithinAt 𝕜 s y := hy ▾ h theorem UniqueDiffWithinAt.mono_nhds (h : UniqueDiffWithinAt 𝕜 s x) (st : 𝓝[s] x ≀ 𝓝[t] x) : UniqueDiffWithinAt 𝕜 t x := by simp only [uniqueDiffWithinAt_iff] at * rw [mem_closure_iff_nhdsWithin_neBot] at h ⊢ exact ⟹h.1.mono <| Submodule.span_mono <| tangentCone_mono_nhds st, h.2.mono st⟩ theorem UniqueDiffWithinAt.mono (h : UniqueDiffWithinAt 𝕜 s x) (st : s ⊆ t) : UniqueDiffWithinAt 𝕜 t x := h.mono_nhds <| nhdsWithin_mono _ st theorem uniqueDiffWithinAt_congr (st : 𝓝[s] x = 𝓝[t] x) : UniqueDiffWithinAt 𝕜 s x ↔ UniqueDiffWithinAt 𝕜 t x := ⟹fun h => h.mono_nhds <| le_of_eq st, fun h => h.mono_nhds <| le_of_eq st.symm⟩ theorem uniqueDiffWithinAt_inter (ht : t ∈ 𝓝 x) : UniqueDiffWithinAt 𝕜 (s ∩ t) x ↔ UniqueDiffWithinAt 𝕜 s x := uniqueDiffWithinAt_congr <| (nhdsWithin_restrict' _ ht).symm theorem UniqueDiffWithinAt.inter (hs : UniqueDiffWithinAt 𝕜 s x) (ht : t ∈ 𝓝 x) : UniqueDiffWithinAt 𝕜 (s ∩ t) x := (uniqueDiffWithinAt_inter ht).2 hs theorem uniqueDiffWithinAt_inter' (ht : t ∈ 𝓝[s] x) : UniqueDiffWithinAt 𝕜 (s ∩ t) x ↔ UniqueDiffWithinAt 𝕜 s x := uniqueDiffWithinAt_congr <| (nhdsWithin_restrict'' _ ht).symm theorem UniqueDiffWithinAt.inter' (hs : UniqueDiffWithinAt 𝕜 s x) (ht : t ∈ 𝓝[s] x) : UniqueDiffWithinAt 𝕜 (s ∩ t) x := (uniqueDiffWithinAt_inter' ht).2 hs theorem uniqueDiffWithinAt_of_mem_nhds (h : s ∈ 𝓝 x) : UniqueDiffWithinAt 𝕜 s x := by simpa only [univ_inter] using uniqueDiffWithinAt_univ.inter h theorem IsOpen.uniqueDiffWithinAt (hs : IsOpen s) (xs : x ∈ s) : UniqueDiffWithinAt 𝕜 s x := uniqueDiffWithinAt_of_mem_nhds (IsOpen.mem_nhds hs xs) theorem UniqueDiffOn.inter (hs : UniqueDiffOn 𝕜 s) (ht : IsOpen t) : UniqueDiffOn 𝕜 (s ∩ t) := fun x hx => (hs x hx.1).inter (IsOpen.mem_nhds ht hx.2) theorem IsOpen.uniqueDiffOn (hs : IsOpen s) : UniqueDiffOn 𝕜 s := fun _ hx => IsOpen.uniqueDiffWithinAt hs hx /-- The product of two sets of unique differentiability at points `x` and `y` has unique differentiability at `(x, y)`. -/ theorem UniqueDiffWithinAt.prod {t : Set F} {y : F} (hs : UniqueDiffWithinAt 𝕜 s x) (ht : UniqueDiffWithinAt 𝕜 t y) : UniqueDiffWithinAt 𝕜 (s ×ˢ t) (x, y) := by rw [uniqueDiffWithinAt_iff] at hs ht ⊢ rw [closure_prod_eq] refine ⟹?_, hs.2, ht.2⟩ have : _ ≀ Submodule.span 𝕜 (tangentConeAt 𝕜 (s ×ˢ t) (x, y)) := Submodule.span_mono (union_subset (subset_tangentCone_prod_left ht.2) (subset_tangentCone_prod_right hs.2)) rw [LinearMap.span_inl_union_inr, SetLike.le_def] at this exact (hs.1.prod ht.1).mono this theorem UniqueDiffWithinAt.univ_pi (ι : Type*) [Finite ι] (E : ι → Type*) [∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] (s : ∀ i, Set (E i)) (x : ∀ i, E i) (h : ∀ i, UniqueDiffWithinAt 𝕜 (s i) (x i)) : UniqueDiffWithinAt 𝕜 (Set.pi univ s) x := by classical simp only [uniqueDiffWithinAt_iff, closure_pi_set] at h ⊢ refine ⟹(dense_pi univ fun i _ => (h i).1).mono ?_, fun i _ => (h i).2⟩ norm_cast simp only [← Submodule.iSup_map_single, iSup_le_iff, LinearMap.map_span, Submodule.span_le, ← mapsTo'] exact fun i => (mapsTo_tangentCone_pi fun j _ => (h j).2).mono Subset.rfl Submodule.subset_span theorem UniqueDiffWithinAt.pi (ι : Type*) [Finite ι] (E : ι → Type*) [∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] (s : ∀ i, Set (E i)) (x : ∀ i, E i) (I : Set ι) (h : ∀ i ∈ I, UniqueDiffWithinAt 𝕜 (s i) (x i)) : UniqueDiffWithinAt 𝕜 (Set.pi I s) x := by classical rw [← Set.univ_pi_piecewise_univ] refine UniqueDiffWithinAt.univ_pi ι E _ _ fun i => ?_ by_cases hi : i ∈ I <;> simp [*, uniqueDiffWithinAt_univ] /-- The product of two sets of unique differentiability is a set of unique differentiability. -/ theorem UniqueDiffOn.prod {t : Set F} (hs : UniqueDiffOn 𝕜 s) (ht : UniqueDiffOn 𝕜 t) : UniqueDiffOn 𝕜 (s ×ˢ t) := fun ⟹x, y⟩ h => UniqueDiffWithinAt.prod (hs x h.1) (ht y h.2) /-- The finite product of a family of sets of unique differentiability is a set of unique differentiability. -/ theorem UniqueDiffOn.pi (ι : Type*) [Finite ι] (E : ι → Type*) [∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] (s : ∀ i, Set (E i)) (I : Set ι) (h : ∀ i ∈ I, UniqueDiffOn 𝕜 (s i)) : UniqueDiffOn 𝕜 (Set.pi I s) := fun x hx => UniqueDiffWithinAt.pi _ _ _ _ _ fun i hi => h i hi (x i) (hx i hi) /-- The finite product of a family of sets of unique differentiability is a set of unique differentiability. -/ theorem UniqueDiffOn.univ_pi (ι : Type*) [Finite ι] (E : ι → Type*) [∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] (s : ∀ i, Set (E i)) (h : ∀ i, UniqueDiffOn 𝕜 (s i)) : UniqueDiffOn 𝕜 (Set.pi univ s) := UniqueDiffOn.pi _ _ _ _ fun i _ => h i /-- In a real vector space, a convex set with nonempty interior is a set of unique differentiability at every point of its closure. -/ theorem uniqueDiffWithinAt_convex {s : Set G} (conv : Convex ℝ s) (hs : (interior s).Nonempty) {x : G} (hx : x ∈ closure s) : UniqueDiffWithinAt ℝ s x := by rcases hs with ⟹y, hy⟩ suffices y - x ∈ interior (tangentConeAt ℝ s x) by refine ⟹Dense.of_closure ?_, hx⟩ simp [(Submodule.span ℝ (tangentConeAt ℝ s x)).eq_top_of_nonempty_interior' ⟹y - x, interior_mono Submodule.subset_span this⟩] rw [mem_interior_iff_mem_nhds] replace hy : interior s ∈ 𝓝 y := IsOpen.mem_nhds isOpen_interior hy apply mem_of_superset ((isOpenMap_sub_right x).image_mem_nhds hy) rintro _ ⟹z, zs, rfl⟩ refine mem_tangentCone_of_openSegment_subset (Subset.trans ?_ interior_subset) exact conv.openSegment_closure_interior_subset_interior hx zs /-- In a real vector space, a convex set with nonempty interior is a set of unique differentiability. -/ theorem uniqueDiffOn_convex {s : Set G} (conv : Convex ℝ s) (hs : (interior s).Nonempty) : UniqueDiffOn ℝ s := fun _ xs => uniqueDiffWithinAt_convex conv hs (subset_closure xs) theorem uniqueDiffOn_Ici (a : ℝ) : UniqueDiffOn ℝ (Ici a) := uniqueDiffOn_convex (convex_Ici a) <| by simp only [interior_Ici, nonempty_Ioi] theorem uniqueDiffOn_Iic (a : ℝ) : UniqueDiffOn ℝ (Iic a) := uniqueDiffOn_convex (convex_Iic a) <| by simp only [interior_Iic, nonempty_Iio] theorem uniqueDiffOn_Ioi (a : ℝ) : UniqueDiffOn ℝ (Ioi a) := isOpen_Ioi.uniqueDiffOn theorem uniqueDiffOn_Iio (a : ℝ) : UniqueDiffOn ℝ (Iio a) := isOpen_Iio.uniqueDiffOn theorem uniqueDiffOn_Icc {a b : ℝ} (hab : a < b) : UniqueDiffOn ℝ (Icc a b) := uniqueDiffOn_convex (convex_Icc a b) <| by simp only [interior_Icc, nonempty_Ioo, hab] theorem uniqueDiffOn_Ico (a b : ℝ) : UniqueDiffOn ℝ (Ico a b) := if hab : a < b then uniqueDiffOn_convex (convex_Ico a b) <| by simp only [interior_Ico, nonempty_Ioo, hab] else by simp only [Ico_eq_empty hab, uniqueDiffOn_empty] theorem uniqueDiffOn_Ioc (a b : ℝ) : UniqueDiffOn ℝ (Ioc a b) := if hab : a < b then uniqueDiffOn_convex (convex_Ioc a b) <| by simp only [interior_Ioc, nonempty_Ioo, hab] else by simp only [Ioc_eq_empty hab, uniqueDiffOn_empty] theorem uniqueDiffOn_Ioo (a b : ℝ) : UniqueDiffOn ℝ (Ioo a b) := isOpen_Ioo.uniqueDiffOn /-- The real interval `[0, 1]` is a set of unique differentiability. -/ theorem uniqueDiffOn_Icc_zero_one : UniqueDiffOn ℝ (Icc (0 : ℝ) 1) := uniqueDiffOn_Icc zero_lt_one theorem uniqueDiffWithinAt_Ioo {a b t : ℝ} (ht : t ∈ Set.Ioo a b) : UniqueDiffWithinAt ℝ (Set.Ioo a b) t := IsOpen.uniqueDiffWithinAt isOpen_Ioo ht theorem uniqueDiffWithinAt_Ioi (a : ℝ) : UniqueDiffWithinAt ℝ (Ioi a) a := uniqueDiffWithinAt_convex (convex_Ioi a) (by simp) (by simp) theorem uniqueDiffWithinAt_Iio (a : ℝ) : UniqueDiffWithinAt ℝ (Iio a) a := uniqueDiffWithinAt_convex (convex_Iio a) (by simp) (by simp) end UniqueDiff
Analysis\Calculus\Taylor.lean
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import Mathlib.Algebra.Polynomial.Module.Basic import Mathlib.Analysis.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.IteratedDeriv.Defs import Mathlib.Analysis.Calculus.MeanValue /-! # Taylor's theorem This file defines the Taylor polynomial of a real function `f : ℝ → E`, where `E` is a normed vector space over `ℝ` and proves Taylor's theorem, which states that if `f` is sufficiently smooth, then `f` can be approximated by the Taylor polynomial up to an explicit error term. ## Main definitions * `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin` * `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin` ## Main statements * `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term * `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder * `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder * `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a polynomial bound on the remainder ## TODO * the Peano form of the remainder * the integral form of the remainder * Generalization to higher dimensions ## Tags Taylor polynomial, Taylor's theorem -/ open scoped Interval Topology Nat open Set variable {𝕜 E F : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] /-- The `k`th coefficient of the Taylor polynomial. -/ noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E := (k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀ /-- The Taylor polynomial with derivatives inside of a set `s`. The Taylor polynomial is given by $$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$ where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/ noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E := (Finset.range (n + 1)).sum fun k => PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀)) /-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E`-/ noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E := PolynomialModule.eval x (taylorWithin f n s x₀) theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ + PolynomialModule.comp (Polynomial.X - Polynomial.C x₀) (PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by dsimp only [taylorWithin] rw [Finset.sum_range_succ] @[simp] theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x + (((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval] congr simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C, PolynomialModule.eval_single, mul_inv_rev] dsimp only [taylorCoeffWithin] rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, mul_inv_rev] /-- The Taylor polynomial of order zero evaluates to `f x`. -/ @[simp] theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f 0 s x₀ x = f x₀ := by dsimp only [taylorWithinEval] dsimp only [taylorWithin] dsimp only [taylorCoeffWithin] simp /-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/ @[simp] theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : taylorWithinEval f n s x₀ x₀ = f x₀ := by induction' n with k hk · exact taylor_within_zero_eval _ _ _ _ simp [hk] theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : taylorWithinEval f n s x₀ x = ∑ k ∈ Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by induction' n with k hk · simp rw [taylorWithinEval_succ, Finset.sum_range_succ, hk] simp [Nat.factorial] /-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial `taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/ theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ} (hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) : ContinuousOn (fun t => taylorWithinEval f n s t x) s := by simp_rw [taylor_within_apply] refine continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => ?_ refine (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul ?_ rw [contDiffOn_iff_continuousOn_differentiableOn_deriv hs] at hf cases' hf with hf_left specialize hf_left i simp only [Finset.mem_range] at hi refine hf_left ?_ simp only [WithTop.coe_le_coe, Nat.cast_le, Nat.lt_succ_iff.mp hi] /-- Helper lemma for calculating the derivative of the monomial that appears in Taylor expansions. -/ theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) : HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by simp_rw [sub_eq_neg_add] rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc] convert HasDerivAt.pow (n + 1) ((hasDerivAt_id t).neg.add_const x) simp only [Nat.cast_add, Nat.cast_one] theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ} (ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y) (hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) : HasDerivWithinAt (fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z) ((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y - ((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by replace hf : HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by convert (hf.mono_of_mem hs).hasDerivWithinAt using 1 rw [iteratedDerivWithin_succ (ht.mono_nhds (nhdsWithin_le_iff.mpr hs))] exact (derivWithin_of_mem hs ht hf).symm have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1)) (-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by -- Commuting the factors: have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by field_simp; ring rw [this] exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _ convert this.smul hf using 1 field_simp rw [neg_div, neg_smul, sub_eq_add_neg] /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for arbitrary sets -/ theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ} (hs'_unique : UniqueDiffWithinAt ℝ s' y) (hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y) (hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s) (hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) : HasDerivWithinAt (fun t => taylorWithinEval f n s t x) (((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by induction' n with k hk · simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero, mul_one, zero_add, one_smul] simp only [iteratedDerivWithin_zero] at hf' rw [iteratedDerivWithin_one (hs_unique _ (h hy))] exact hf'.hasDerivWithinAt.mono h simp_rw [Nat.add_succ, taylorWithinEval_succ] simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' := (hf.differentiableOn_iteratedDerivWithin coe_lt_succ hs_unique).mono h specialize hk hf.of_succ ((hdiff y hy).mono_of_mem hs') convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique (nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1 exact (add_sub_cancel _ _).symm /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for open intervals -/ theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) : HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t := have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds (hasDerivWithinAt_taylorWithinEval (uniqueDiffWithinAt_Ioo ht) (uniqueDiffOn_Icc hx) h_nhds' ht Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem h_nhds').hasDerivAt h_nhds /-- Calculate the derivative of the Taylor polynomial with respect to `x₀`. Version for closed intervals -/ theorem hasDerivWithinAt_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) : HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t := hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx t ht) (uniqueDiffOn_Icc hx) self_mem_nhdsWithin ht rfl.subset hf (hf' t ht) /-! ### Taylor's theorem with mean value type remainder estimate -/ /-- **Taylor's theorem** with the general mean value form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on `Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$. -/ theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) (gcont : ContinuousOn g (Icc x₀ x)) (gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1) (g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = ((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by -- We apply the mean value theorem rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x) (fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx (continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf) (fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟹y, hy, h⟩ use y, hy -- The rest is simplifications and trivial calculations simp only [taylorWithinEval_self] at h rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel_right₀ _ (g'_ne y hy)] at h rw [← h] field_simp [g'_ne y hy] ring /-- **Taylor's theorem** with the Lagrange form of the remainder. We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by fun_prop have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by intro y hy refine pow_ne_zero _ ?_ rw [mem_Ioo] at hy rw [sub_ne_zero] exact hy.2.ne' have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy => mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy) -- We apply the general theorem with g(t) = (x - t)^(n+1) rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with ⟹y, hy, h⟩ use y, hy simp only [sub_self, zero_pow, Ne, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h rw [h, neg_div, ← div_neg, neg_mul, neg_neg] field_simp [xy_ne y hy, Nat.factorial]; ring /-- **Taylor's theorem** with the Cauchy form of the remainder. We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and `n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$ where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated derivative. -/ theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x) (hf : ContDiffOn ℝ n f (Icc x₀ x)) (hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) : ∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x = iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by have gcont : ContinuousOn id (Icc x₀ x) := by fun_prop have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 := fun _ _ => hasDerivAt_id _ -- We apply the general theorem with g = id rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟹y, hy, h⟩ use y, hy rw [h] field_simp [n.factorial_ne_zero] ring /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. The difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/ theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b) (hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ C) : ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) / n ! := by rcases eq_or_lt_of_le hab with (rfl | h) · rw [Icc_self, mem_singleton_iff] at hx simp [hx] -- The nth iterated derivative is differentiable have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) := hf.differentiableOn_iteratedDerivWithin (WithTop.coe_lt_coe.mpr n.lt_succ_self) (uniqueDiffOn_Icc h) -- We can uniformly bound the derivative of the Taylor polynomial have h' : ∀ y ∈ Ico a x, ‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≀ (n ! : ℝ)⁻¹ * |x - a| ^ n * C := by rintro y ⟹hay, hyx⟩ rw [norm_smul, Real.norm_eq_abs] gcongr · rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast] gcongr exact sub_nonneg.2 hyx.le -- Estimate the iterated derivative by `C` · exact hC y ⟹hay, hyx.le.trans hx.2⟩ -- Apply the mean value theorem for vector valued functions: have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x) (((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by intro t ht have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2 exact (hasDerivWithinAt_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1) simp only [taylorWithinEval_self] at this refine this.trans_eq ?_ -- The rest is a trivial calculation rw [abs_of_nonneg (sub_nonneg.mpr hx.1)] ring /-- **Taylor's theorem** with a polynomial bound on the remainder We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`. There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/ theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≀ b) (hf : ContDiffOn ℝ (n + 1) f (Icc a b)) : ∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≀ C * (x - a) ^ (n + 1) := by rcases eq_or_lt_of_le hab with (rfl | h) · refine ⟹0, fun x hx => ?_⟩ have : x = a := by simpa [← le_antisymm_iff] using hx simp [← this] -- We estimate by the supremum of the norm of the iterated derivative let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ use SupSet.sSup (g '' Icc a b) / (n !) intro x hx rw [div_mul_eq_mul_div₀] refine taylor_mean_remainder_bound hab hf hx fun y => ?_ exact (hf.continuousOn_iteratedDerivWithin rfl.le <| uniqueDiffOn_Icc h).norm.le_sSup_image_Icc
Analysis\Calculus\UniformLimitsDeriv.lean
/- Copyright (c) 2022 Kevin H. Wilson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin H. Wilson -/ import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Analysis.NormedSpace.RCLike import Mathlib.Order.Filter.Curry /-! # Swapping limits and derivatives via uniform convergence The purpose of this file is to prove that the derivative of the pointwise limit of a sequence of functions is the pointwise limit of the functions' derivatives when the derivatives converge _uniformly_. The formal statement appears as `hasFDerivAt_of_tendstoLocallyUniformlyOn`. ## Main statements * `uniformCauchySeqOnFilter_of_fderiv`: If 1. `f : ℕ → E → G` is a sequence of functions which have derivatives `f' : ℕ → E → (E →L[𝕜] G)` on a neighborhood of `x`, 2. the functions `f` converge at `x`, and 3. the derivatives `f'` form a Cauchy sequence uniformly on a neighborhood of `x`, then the `f` form a Cauchy sequence _uniformly_ on a neighborhood of `x` * `hasFDerivAt_of_tendstoUniformlyOnFilter` : Suppose (1), (2), and (3) above are true. Let `g` (resp. `g'`) be the limiting function of the `f` (resp. `g'`). Then `f'` is the derivative of `g` on a neighborhood of `x` * `hasFDerivAt_of_tendstoUniformlyOn`: An often-easier-to-use version of the above theorem when *all* the derivatives exist and functions converge on a common open set and the derivatives converge uniformly there. Each of the above statements also has variations that support `deriv` instead of `fderiv`. ## Implementation notes Our technique for proving the main result is the famous "`ε / 3` proof." In words, you can find it explained, for instance, at [this StackExchange post](https://math.stackexchange.com/questions/214218/uniform-convergence-of-derivatives-tao-14-2-7). The subtlety is that we want to prove that the difference quotients of the `g` converge to the `g'`. That is, we want to prove something like: ``` ∀ ε > 0, ∃ ÎŽ > 0, ∀ y ∈ B_ÎŽ(x), |y - x|⁻¹ * |(g y - g x) - g' x (y - x)| < ε. ``` To do so, we will need to introduce a pair of quantifiers ```lean ∀ ε > 0, ∃ N, ∀ n ≥ N, ∃ ÎŽ > 0, ∀ y ∈ B_ÎŽ(x), |y - x|⁻¹ * |(g y - g x) - g' x (y - x)| < ε. ``` So how do we write this in terms of filters? Well, the initial definition of the derivative is ```lean tendsto (|y - x|⁻¹ * |(g y - g x) - g' x (y - x)|) (𝓝 x) (𝓝 0) ``` There are two ways we might introduce `n`. We could do: ```lean ∀ᶠ (n : ℕ) in atTop, Tendsto (|y - x|⁻¹ * |(g y - g x) - g' x (y - x)|) (𝓝 x) (𝓝 0) ``` but this is equivalent to the quantifier order `∃ N, ∀ n ≥ N, ∀ ε > 0, ∃ ÎŽ > 0, ∀ y ∈ B_ÎŽ(x)`, which _implies_ our desired `∀ ∃ ∀ ∃ ∀` but is _not_ equivalent to it. On the other hand, we might try ```lean Tendsto (|y - x|⁻¹ * |(g y - g x) - g' x (y - x)|) (atTop ×ˢ 𝓝 x) (𝓝 0) ``` but this is equivalent to the quantifier order `∀ ε > 0, ∃ N, ∃ ÎŽ > 0, ∀ n ≥ N, ∀ y ∈ B_ÎŽ(x)`, which again _implies_ our desired `∀ ∃ ∀ ∃ ∀` but is not equivalent to it. So to get the quantifier order we want, we need to introduce a new filter construction, which we call a "curried filter" ```lean Tendsto (|y - x|⁻¹ * |(g y - g x) - g' x (y - x)|) (atTop.curry (𝓝 x)) (𝓝 0) ``` Then the above implications are `Filter.Tendsto.curry` and `Filter.Tendsto.mono_left Filter.curry_le_prod`. We will use both of these deductions as part of our proof. We note that if you loosen the assumptions of the main theorem then the proof becomes quite a bit easier. In particular, if you assume there is a common neighborhood `s` where all of the three assumptions of `hasFDerivAt_of_tendstoUniformlyOnFilter` hold and that the `f'` are continuous, then you can avoid the mean value theorem and much of the work around curried filters. ## Tags uniform convergence, limits of derivatives -/ open Filter open scoped uniformity Filter Topology section LimitsOfDerivatives variable {ι : Type*} {l : Filter ι} {E : Type*} [NormedAddCommGroup E] {𝕜 : Type*} [RCLike 𝕜] [NormedSpace 𝕜 E] {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {f : ι → E → G} {g : E → G} {f' : ι → E → E →L[𝕜] G} {g' : E → E →L[𝕜] G} {x : E} /-- If a sequence of functions real or complex functions are eventually differentiable on a neighborhood of `x`, they are Cauchy _at_ `x`, and their derivatives are a uniform Cauchy sequence in a neighborhood of `x`, then the functions form a uniform Cauchy sequence in a neighborhood of `x`. -/ theorem uniformCauchySeqOnFilter_of_fderiv (hf' : UniformCauchySeqOnFilter f' l (𝓝 x)) (hf : ∀ᶠ n : ι × E in l ×ˢ 𝓝 x, HasFDerivAt (f n.1) (f' n.1 n.2) n.2) (hfg : Cauchy (map (fun n => f n x) l)) : UniformCauchySeqOnFilter f l (𝓝 x) := by letI : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _ rw [SeminormedAddGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_zero] at hf' ⊢ suffices TendstoUniformlyOnFilter (fun (n : ι × ι) (z : E) => f n.1 z - f n.2 z - (f n.1 x - f n.2 x)) 0 (l ×ˢ l) (𝓝 x) ∧ TendstoUniformlyOnFilter (fun (n : ι × ι) (_ : E) => f n.1 x - f n.2 x) 0 (l ×ˢ l) (𝓝 x) by have := this.1.add this.2 rw [add_zero] at this exact this.congr (by simp) constructor · -- This inequality follows from the mean value theorem. To apply it, we will need to shrink our -- neighborhood to small enough ball rw [Metric.tendstoUniformlyOnFilter_iff] at hf' ⊢ intro ε hε have := (tendsto_swap4_prod.eventually (hf.prod_mk hf)).diag_of_prod_right obtain ⟹a, b, c, d, e⟩ := eventually_prod_iff.1 ((hf' ε hε).and this) obtain ⟹R, hR, hR'⟩ := Metric.nhds_basis_ball.eventually_iff.mp d let r := min 1 R have hr : 0 < r := by simp [r, hR] have hr' : ∀ ⊃y : E⩄, y ∈ Metric.ball x r → c y := fun y hy => hR' (lt_of_lt_of_le (Metric.mem_ball.mp hy) (min_le_right _ _)) have hxy : ∀ y : E, y ∈ Metric.ball x r → ‖y - x‖ < 1 := by intro y hy rw [Metric.mem_ball, dist_eq_norm] at hy exact lt_of_lt_of_le hy (min_le_left _ _) have hxyε : ∀ y : E, y ∈ Metric.ball x r → ε * ‖y - x‖ < ε := by intro y hy exact (mul_lt_iff_lt_one_right hε.lt).mpr (hxy y hy) -- With a small ball in hand, apply the mean value theorem refine eventually_prod_iff.mpr ⟹_, b, fun e : E => Metric.ball x r e, eventually_mem_set.mpr (Metric.nhds_basis_ball.mem_of_mem hr), fun {n} hn {y} hy => ?_⟩ simp only [Pi.zero_apply, dist_zero_left] at e ⊢ refine lt_of_le_of_lt ?_ (hxyε y hy) exact Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun y hy => ((e hn (hr' hy)).2.1.sub (e hn (hr' hy)).2.2).hasFDerivWithinAt) (fun y hy => (e hn (hr' hy)).1.le) (convex_ball x r) (Metric.mem_ball_self hr) hy · -- This is just `hfg` run through `eventually_prod_iff` refine Metric.tendstoUniformlyOnFilter_iff.mpr fun ε hε => ?_ obtain ⟹t, ht, ht'⟩ := (Metric.cauchy_iff.mp hfg).2 ε hε exact eventually_prod_iff.mpr ⟹fun n : ι × ι => f n.1 x ∈ t ∧ f n.2 x ∈ t, eventually_prod_iff.mpr ⟹_, ht, _, ht, fun {n} hn {n'} hn' => ⟹hn, hn'⟩⟩, fun _ => True, by simp, fun {n} hn {y} _ => by simpa [norm_sub_rev, dist_eq_norm] using ht' _ hn.1 _ hn.2⟩ /-- A variant of the second fundamental theorem of calculus (FTC-2): If a sequence of functions between real or complex normed spaces are differentiable on a ball centered at `x`, they form a Cauchy sequence _at_ `x`, and their derivatives are Cauchy uniformly on the ball, then the functions form a uniform Cauchy sequence on the ball. NOTE: The fact that we work on a ball is typically all that is necessary to work with power series and Dirichlet series (our primary use case). However, this can be generalized by replacing the ball with any connected, bounded, open set and replacing uniform convergence with local uniform convergence. See `cauchy_map_of_uniformCauchySeqOn_fderiv`. -/ theorem uniformCauchySeqOn_ball_of_fderiv {r : ℝ} (hf' : UniformCauchySeqOn f' l (Metric.ball x r)) (hf : ∀ n : ι, ∀ y : E, y ∈ Metric.ball x r → HasFDerivAt (f n) (f' n y) y) (hfg : Cauchy (map (fun n => f n x) l)) : UniformCauchySeqOn f l (Metric.ball x r) := by letI : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _ have : NeBot l := (cauchy_map_iff.1 hfg).1 rcases le_or_lt r 0 with (hr | hr) · simp only [Metric.ball_eq_empty.2 hr, UniformCauchySeqOn, Set.mem_empty_iff_false, IsEmpty.forall_iff, eventually_const, imp_true_iff] rw [SeminormedAddGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_zero] at hf' ⊢ suffices TendstoUniformlyOn (fun (n : ι × ι) (z : E) => f n.1 z - f n.2 z - (f n.1 x - f n.2 x)) 0 (l ×ˢ l) (Metric.ball x r) ∧ TendstoUniformlyOn (fun (n : ι × ι) (_ : E) => f n.1 x - f n.2 x) 0 (l ×ˢ l) (Metric.ball x r) by have := this.1.add this.2 rw [add_zero] at this refine this.congr ?_ filter_upwards with n z _ using (by simp) constructor · -- This inequality follows from the mean value theorem rw [Metric.tendstoUniformlyOn_iff] at hf' ⊢ intro ε hε obtain ⟹q, hqpos, hq⟩ : ∃ q : ℝ, 0 < q ∧ q * r < ε := by simp_rw [mul_comm] exact exists_pos_mul_lt hε.lt r apply (hf' q hqpos.gt).mono intro n hn y hy simp_rw [dist_eq_norm, Pi.zero_apply, zero_sub, norm_neg] at hn ⊢ have mvt := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun z hz => ((hf n.1 z hz).sub (hf n.2 z hz)).hasFDerivWithinAt) (fun z hz => (hn z hz).le) (convex_ball x r) (Metric.mem_ball_self hr) hy refine lt_of_le_of_lt mvt ?_ have : q * ‖y - x‖ < q * r := mul_lt_mul' rfl.le (by simpa only [dist_eq_norm] using Metric.mem_ball.mp hy) (norm_nonneg _) hqpos exact this.trans hq · -- This is just `hfg` run through `eventually_prod_iff` refine Metric.tendstoUniformlyOn_iff.mpr fun ε hε => ?_ obtain ⟹t, ht, ht'⟩ := (Metric.cauchy_iff.mp hfg).2 ε hε rw [eventually_prod_iff] refine ⟹fun n => f n x ∈ t, ht, fun n => f n x ∈ t, ht, ?_⟩ intro n hn n' hn' z _ rw [dist_eq_norm, Pi.zero_apply, zero_sub, norm_neg, ← dist_eq_norm] exact ht' _ hn _ hn' /-- If a sequence of functions between real or complex normed spaces are differentiable on a preconnected open set, they form a Cauchy sequence _at_ `x`, and their derivatives are Cauchy uniformly on the set, then the functions form a Cauchy sequence at any point in the set. -/ theorem cauchy_map_of_uniformCauchySeqOn_fderiv {s : Set E} (hs : IsOpen s) (h's : IsPreconnected s) (hf' : UniformCauchySeqOn f' l s) (hf : ∀ n : ι, ∀ y : E, y ∈ s → HasFDerivAt (f n) (f' n y) y) {x₀ x : E} (hx₀ : x₀ ∈ s) (hx : x ∈ s) (hfg : Cauchy (map (fun n => f n x₀) l)) : Cauchy (map (fun n => f n x) l) := by have : NeBot l := (cauchy_map_iff.1 hfg).1 let t := { y | y ∈ s ∧ Cauchy (map (fun n => f n y) l) } suffices H : s ⊆ t from (H hx).2 have A : ∀ x ε, x ∈ t → Metric.ball x ε ⊆ s → Metric.ball x ε ⊆ t := fun x ε xt hx y hy => ⟹hx hy, (uniformCauchySeqOn_ball_of_fderiv (hf'.mono hx) (fun n y hy => hf n y (hx hy)) xt.2).cauchy_map hy⟩ have open_t : IsOpen t := by rw [Metric.isOpen_iff] intro x hx rcases Metric.isOpen_iff.1 hs x hx.1 with ⟚ε, εpos, hε⟩ exact ⟚ε, εpos, A x ε hx hε⟩ have st_nonempty : (s ∩ t).Nonempty := ⟹x₀, hx₀, ⟹hx₀, hfg⟩⟩ suffices H : closure t ∩ s ⊆ t from h's.subset_of_closure_inter_subset open_t st_nonempty H rintro x ⟹xt, xs⟩ obtain ⟚ε, εpos, hε⟩ : ∃ (ε : ℝ), ε > 0 ∧ Metric.ball x ε ⊆ s := Metric.isOpen_iff.1 hs x xs obtain ⟹y, yt, hxy⟩ : ∃ (y : E), y ∈ t ∧ dist x y < ε / 2 := Metric.mem_closure_iff.1 xt _ (half_pos εpos) have B : Metric.ball y (ε / 2) ⊆ Metric.ball x ε := by apply Metric.ball_subset_ball'; rw [dist_comm]; linarith exact A y (ε / 2) yt (B.trans hε) (Metric.mem_ball.2 hxy) /-- If `f_n → g` pointwise and the derivatives `(f_n)' → h` _uniformly_ converge, then in fact for a fixed `y`, the difference quotients `‖z - y‖⁻¹ • (f_n z - f_n y)` converge _uniformly_ to `‖z - y‖⁻¹ • (g z - g y)` -/ theorem difference_quotients_converge_uniformly (hf' : TendstoUniformlyOnFilter f' g' l (𝓝 x)) (hf : ∀ᶠ n : ι × E in l ×ˢ 𝓝 x, HasFDerivAt (f n.1) (f' n.1 n.2) n.2) (hfg : ∀ᶠ y : E in 𝓝 x, Tendsto (fun n => f n y) l (𝓝 (g y))) : TendstoUniformlyOnFilter (fun n : ι => fun y : E => (‖y - x‖⁻¹ : 𝕜) • (f n y - f n x)) (fun y : E => (‖y - x‖⁻¹ : 𝕜) • (g y - g x)) l (𝓝 x) := by let A : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _ rcases eq_or_ne l ⊥ with (hl | hl) · simp only [hl, TendstoUniformlyOnFilter, bot_prod, eventually_bot, imp_true_iff] haveI : NeBot l := ⟹hl⟩ refine UniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto ?_ ((hfg.and (eventually_const.mpr hfg.self_of_nhds)).mono fun y hy => (hy.1.sub hy.2).const_smul _) rw [SeminormedAddGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_zero] rw [Metric.tendstoUniformlyOnFilter_iff] have hfg' := hf'.uniformCauchySeqOnFilter rw [SeminormedAddGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_zero] at hfg' rw [Metric.tendstoUniformlyOnFilter_iff] at hfg' intro ε hε obtain ⟹q, hqpos, hqε⟩ := exists_pos_rat_lt hε specialize hfg' (q : ℝ) (by simp [hqpos]) have := (tendsto_swap4_prod.eventually (hf.prod_mk hf)).diag_of_prod_right obtain ⟹a, b, c, d, e⟩ := eventually_prod_iff.1 (hfg'.and this) obtain ⟹r, hr, hr'⟩ := Metric.nhds_basis_ball.eventually_iff.mp d rw [eventually_prod_iff] refine ⟹_, b, fun e : E => Metric.ball x r e, eventually_mem_set.mpr (Metric.nhds_basis_ball.mem_of_mem hr), fun {n} hn {y} hy => ?_⟩ simp only [Pi.zero_apply, dist_zero_left] rw [← smul_sub, norm_smul, norm_inv, RCLike.norm_coe_norm] refine lt_of_le_of_lt ?_ hqε by_cases hyz' : x = y; · simp [hyz', hqpos.le] have hyz : 0 < ‖y - x‖ := by rw [norm_pos_iff]; intro hy'; exact hyz' (eq_of_sub_eq_zero hy').symm rw [inv_mul_le_iff hyz, mul_comm, sub_sub_sub_comm] simp only [Pi.zero_apply, dist_zero_left] at e refine Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun y hy => ((e hn (hr' hy)).2.1.sub (e hn (hr' hy)).2.2).hasFDerivWithinAt) (fun y hy => (e hn (hr' hy)).1.le) (convex_ball x r) (Metric.mem_ball_self hr) hy /-- `(d/dx) lim_{n → ∞} f n x = lim_{n → ∞} f' n x` when the `f' n` converge _uniformly_ to their limit at `x`. In words the assumptions mean the following: * `hf'`: The `f'` converge "uniformly at" `x` to `g'`. This does not mean that the `f' n` even converge away from `x`! * `hf`: For all `(y, n)` with `y` sufficiently close to `x` and `n` sufficiently large, `f' n` is the derivative of `f n` * `hfg`: The `f n` converge pointwise to `g` on a neighborhood of `x` -/ theorem hasFDerivAt_of_tendstoUniformlyOnFilter [NeBot l] (hf' : TendstoUniformlyOnFilter f' g' l (𝓝 x)) (hf : ∀ᶠ n : ι × E in l ×ˢ 𝓝 x, HasFDerivAt (f n.1) (f' n.1 n.2) n.2) (hfg : ∀ᶠ y in 𝓝 x, Tendsto (fun n => f n y) l (𝓝 (g y))) : HasFDerivAt g (g' x) x := by -- The proof strategy follows several steps: -- 1. The quantifiers in the definition of the derivative are -- `∀ ε > 0, ∃Ύ > 0, ∀y ∈ B_ÎŽ(x)`. We will introduce a quantifier in the middle: -- `∀ ε > 0, ∃N, ∀n ≥ N, ∃Ύ > 0, ∀y ∈ B_ÎŽ(x)` which will allow us to introduce the `f(') n` -- 2. The order of the quantifiers `hfg` are opposite to what we need. We will be able to swap -- the quantifiers using the uniform convergence assumption rw [hasFDerivAt_iff_tendsto] -- Introduce extra quantifier via curried filters suffices Tendsto (fun y : ι × E => ‖y.2 - x‖⁻¹ * ‖g y.2 - g x - (g' x) (y.2 - x)‖) (l.curry (𝓝 x)) (𝓝 0) by rw [Metric.tendsto_nhds] at this ⊢ intro ε hε specialize this ε hε rw [eventually_curry_iff] at this simp only at this exact (eventually_const.mp this).mono (by simp only [imp_self, forall_const]) -- With the new quantifier in hand, we can perform the famous `ε/3` proof. Specifically, -- we will break up the limit (the difference functions minus the derivative go to 0) into 3: -- * The difference functions of the `f n` converge *uniformly* to the difference functions -- of the `g n` -- * The `f' n` are the derivatives of the `f n` -- * The `f' n` converge to `g'` at `x` conv => congr ext rw [← abs_norm, ← abs_inv, ← @RCLike.norm_ofReal 𝕜 _ _, RCLike.ofReal_inv, ← norm_smul] rw [← tendsto_zero_iff_norm_tendsto_zero] have : (fun a : ι × E => (‖a.2 - x‖⁻¹ : 𝕜) • (g a.2 - g x - (g' x) (a.2 - x))) = ((fun a : ι × E => (‖a.2 - x‖⁻¹ : 𝕜) • (g a.2 - g x - (f a.1 a.2 - f a.1 x))) + fun a : ι × E => (‖a.2 - x‖⁻¹ : 𝕜) • (f a.1 a.2 - f a.1 x - ((f' a.1 x) a.2 - (f' a.1 x) x))) + fun a : ι × E => (‖a.2 - x‖⁻¹ : 𝕜) • (f' a.1 x - g' x) (a.2 - x) := by ext; simp only [Pi.add_apply]; rw [← smul_add, ← smul_add]; congr simp only [map_sub, sub_add_sub_cancel, ContinuousLinearMap.coe_sub', Pi.sub_apply] -- Porting note: added abel simp_rw [this] have : 𝓝 (0 : G) = 𝓝 (0 + 0 + 0) := by simp only [add_zero] rw [this] refine Tendsto.add (Tendsto.add ?_ ?_) ?_ · have := difference_quotients_converge_uniformly hf' hf hfg rw [Metric.tendstoUniformlyOnFilter_iff] at this rw [Metric.tendsto_nhds] intro ε hε apply ((this ε hε).filter_mono curry_le_prod).mono intro n hn rw [dist_eq_norm] at hn ⊢ rw [← smul_sub] at hn rwa [sub_zero] · -- (Almost) the definition of the derivatives rw [Metric.tendsto_nhds] intro ε hε rw [eventually_curry_iff] refine hf.curry.mono fun n hn => ?_ have := hn.self_of_nhds rw [hasFDerivAt_iff_tendsto, Metric.tendsto_nhds] at this refine (this ε hε).mono fun y hy => ?_ rw [dist_eq_norm] at hy ⊢ simp only [sub_zero, map_sub, norm_mul, norm_inv, norm_norm] at hy ⊢ rw [norm_smul, norm_inv, RCLike.norm_coe_norm] exact hy · -- hfg' after specializing to `x` and applying the definition of the operator norm refine Tendsto.mono_left ?_ curry_le_prod have h1 : Tendsto (fun n : ι × E => g' n.2 - f' n.1 n.2) (l ×ˢ 𝓝 x) (𝓝 0) := by rw [Metric.tendstoUniformlyOnFilter_iff] at hf' exact Metric.tendsto_nhds.mpr fun ε hε => by simpa using hf' ε hε have h2 : Tendsto (fun n : ι => g' x - f' n x) l (𝓝 0) := by rw [Metric.tendsto_nhds] at h1 ⊢ exact fun ε hε => (h1 ε hε).curry.mono fun n hn => hn.self_of_nhds refine squeeze_zero_norm ?_ (tendsto_zero_iff_norm_tendsto_zero.mp (tendsto_fst.comp (h2.prod_map tendsto_id))) intro n simp_rw [norm_smul, norm_inv, RCLike.norm_coe_norm] by_cases hx : x = n.2; · simp [hx] have hnx : 0 < ‖n.2 - x‖ := by rw [norm_pos_iff]; intro hx'; exact hx (eq_of_sub_eq_zero hx').symm rw [inv_mul_le_iff hnx, mul_comm] simp only [Function.comp_apply, Prod.map_apply'] rw [norm_sub_rev] exact (f' n.1 x - g' x).le_opNorm (n.2 - x) theorem hasFDerivAt_of_tendstoLocallyUniformlyOn [NeBot l] {s : Set E} (hs : IsOpen s) (hf' : TendstoLocallyUniformlyOn f' g' l s) (hf : ∀ n, ∀ x ∈ s, HasFDerivAt (f n) (f' n x) x) (hfg : ∀ x ∈ s, Tendsto (fun n => f n x) l (𝓝 (g x))) (hx : x ∈ s) : HasFDerivAt g (g' x) x := by have h1 : s ∈ 𝓝 x := hs.mem_nhds hx have h3 : Set.univ ×ˢ s ∈ l ×ˢ 𝓝 x := by simp only [h1, prod_mem_prod_iff, univ_mem, and_self_iff] have h4 : ∀ᶠ n : ι × E in l ×ˢ 𝓝 x, HasFDerivAt (f n.1) (f' n.1 n.2) n.2 := eventually_of_mem h3 fun ⟹n, z⟩ ⟹_, hz⟩ => hf n z hz refine hasFDerivAt_of_tendstoUniformlyOnFilter ?_ h4 (eventually_of_mem h1 hfg) simpa [IsOpen.nhdsWithin_eq hs hx] using tendstoLocallyUniformlyOn_iff_filter.mp hf' x hx /-- A slight variant of `hasFDerivAt_of_tendstoLocallyUniformlyOn` with the assumption stated in terms of `DifferentiableOn` rather than `HasFDerivAt`. This makes a few proofs nicer in complex analysis where holomorphicity is assumed but the derivative is not known a priori. -/ theorem hasFDerivAt_of_tendsto_locally_uniformly_on' [NeBot l] {s : Set E} (hs : IsOpen s) (hf' : TendstoLocallyUniformlyOn (fderiv 𝕜 ∘ f) g' l s) (hf : ∀ n, DifferentiableOn 𝕜 (f n) s) (hfg : ∀ x ∈ s, Tendsto (fun n => f n x) l (𝓝 (g x))) (hx : x ∈ s) : HasFDerivAt g (g' x) x := by refine hasFDerivAt_of_tendstoLocallyUniformlyOn hs hf' (fun n z hz => ?_) hfg hx exact ((hf n z hz).differentiableAt (hs.mem_nhds hz)).hasFDerivAt /-- `(d/dx) lim_{n → ∞} f n x = lim_{n → ∞} f' n x` when the `f' n` converge _uniformly_ to their limit on an open set containing `x`. -/ theorem hasFDerivAt_of_tendstoUniformlyOn [NeBot l] {s : Set E} (hs : IsOpen s) (hf' : TendstoUniformlyOn f' g' l s) (hf : ∀ n : ι, ∀ x : E, x ∈ s → HasFDerivAt (f n) (f' n x) x) (hfg : ∀ x : E, x ∈ s → Tendsto (fun n => f n x) l (𝓝 (g x))) : ∀ x : E, x ∈ s → HasFDerivAt g (g' x) x := fun _ => hasFDerivAt_of_tendstoLocallyUniformlyOn hs hf'.tendstoLocallyUniformlyOn hf hfg /-- `(d/dx) lim_{n → ∞} f n x = lim_{n → ∞} f' n x` when the `f' n` converge _uniformly_ to their limit. -/ theorem hasFDerivAt_of_tendstoUniformly [NeBot l] (hf' : TendstoUniformly f' g' l) (hf : ∀ n : ι, ∀ x : E, HasFDerivAt (f n) (f' n x) x) (hfg : ∀ x : E, Tendsto (fun n => f n x) l (𝓝 (g x))) : ∀ x : E, HasFDerivAt g (g' x) x := by intro x have hf : ∀ n : ι, ∀ x : E, x ∈ Set.univ → HasFDerivAt (f n) (f' n x) x := by simp [hf] have hfg : ∀ x : E, x ∈ Set.univ → Tendsto (fun n => f n x) l (𝓝 (g x)) := by simp [hfg] have hf' : TendstoUniformlyOn f' g' l Set.univ := by rwa [tendstoUniformlyOn_univ] exact hasFDerivAt_of_tendstoUniformlyOn isOpen_univ hf' hf hfg x (Set.mem_univ x) end LimitsOfDerivatives section deriv /-! ### `deriv` versions of above theorems In this section, we provide `deriv` equivalents of the `fderiv` lemmas in the previous section. -/ variable {ι : Type*} {l : Filter ι} {𝕜 : Type*} [RCLike 𝕜] {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {f : ι → 𝕜 → G} {g : 𝕜 → G} {f' : ι → 𝕜 → G} {g' : 𝕜 → G} {x : 𝕜} /-- If our derivatives converge uniformly, then the Fréchet derivatives converge uniformly -/ theorem UniformCauchySeqOnFilter.one_smulRight {l' : Filter 𝕜} (hf' : UniformCauchySeqOnFilter f' l l') : UniformCauchySeqOnFilter (fun n => fun z => (1 : 𝕜 →L[𝕜] 𝕜).smulRight (f' n z)) l l' := by -- The tricky part of this proof is that operator norms are written in terms of `≀` whereas -- metrics are written in terms of `<`. So we need to shrink `ε` utilizing the archimedean -- property of `ℝ` rw [SeminormedAddGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_zero, Metric.tendstoUniformlyOnFilter_iff] at hf' ⊢ intro ε hε obtain ⟹q, hq, hq'⟩ := exists_between hε.lt apply (hf' q hq).mono intro n hn refine lt_of_le_of_lt ?_ hq' simp only [dist_eq_norm, Pi.zero_apply, zero_sub, norm_neg] at hn ⊢ refine ContinuousLinearMap.opNorm_le_bound _ hq.le ?_ intro z simp only [ContinuousLinearMap.coe_sub', Pi.sub_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply] rw [← smul_sub, norm_smul, mul_comm] gcongr theorem uniformCauchySeqOnFilter_of_deriv (hf' : UniformCauchySeqOnFilter f' l (𝓝 x)) (hf : ∀ᶠ n : ι × 𝕜 in l ×ˢ 𝓝 x, HasDerivAt (f n.1) (f' n.1 n.2) n.2) (hfg : Cauchy (map (fun n => f n x) l)) : UniformCauchySeqOnFilter f l (𝓝 x) := by simp_rw [hasDerivAt_iff_hasFDerivAt] at hf exact uniformCauchySeqOnFilter_of_fderiv hf'.one_smulRight hf hfg theorem uniformCauchySeqOn_ball_of_deriv {r : ℝ} (hf' : UniformCauchySeqOn f' l (Metric.ball x r)) (hf : ∀ n : ι, ∀ y : 𝕜, y ∈ Metric.ball x r → HasDerivAt (f n) (f' n y) y) (hfg : Cauchy (map (fun n => f n x) l)) : UniformCauchySeqOn f l (Metric.ball x r) := by simp_rw [hasDerivAt_iff_hasFDerivAt] at hf rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf' have hf' : UniformCauchySeqOn (fun n => fun z => (1 : 𝕜 →L[𝕜] 𝕜).smulRight (f' n z)) l (Metric.ball x r) := by rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] exact hf'.one_smulRight exact uniformCauchySeqOn_ball_of_fderiv hf' hf hfg theorem hasDerivAt_of_tendstoUniformlyOnFilter [NeBot l] (hf' : TendstoUniformlyOnFilter f' g' l (𝓝 x)) (hf : ∀ᶠ n : ι × 𝕜 in l ×ˢ 𝓝 x, HasDerivAt (f n.1) (f' n.1 n.2) n.2) (hfg : ∀ᶠ y in 𝓝 x, Tendsto (fun n => f n y) l (𝓝 (g y))) : HasDerivAt g (g' x) x := by -- The first part of the proof rewrites `hf` and the goal to be functions so that Lean -- can recognize them when we apply `hasFDerivAt_of_tendstoUniformlyOnFilter` let F' n z := (1 : 𝕜 →L[𝕜] 𝕜).smulRight (f' n z) let G' z := (1 : 𝕜 →L[𝕜] 𝕜).smulRight (g' z) simp_rw [hasDerivAt_iff_hasFDerivAt] at hf ⊢ -- Now we need to rewrite hf' in terms of `ContinuousLinearMap`s. The tricky part is that -- operator norms are written in terms of `≀` whereas metrics are written in terms of `<`. So we -- need to shrink `ε` utilizing the archimedean property of `ℝ` have hf' : TendstoUniformlyOnFilter F' G' l (𝓝 x) := by rw [Metric.tendstoUniformlyOnFilter_iff] at hf' ⊢ intro ε hε obtain ⟹q, hq, hq'⟩ := exists_between hε.lt apply (hf' q hq).mono intro n hn refine lt_of_le_of_lt ?_ hq' simp only [dist_eq_norm] at hn ⊢ refine ContinuousLinearMap.opNorm_le_bound _ hq.le ?_ intro z simp only [F', G', ContinuousLinearMap.coe_sub', Pi.sub_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply] rw [← smul_sub, norm_smul, mul_comm] gcongr exact hasFDerivAt_of_tendstoUniformlyOnFilter hf' hf hfg theorem hasDerivAt_of_tendstoLocallyUniformlyOn [NeBot l] {s : Set 𝕜} (hs : IsOpen s) (hf' : TendstoLocallyUniformlyOn f' g' l s) (hf : ∀ᶠ n in l, ∀ x ∈ s, HasDerivAt (f n) (f' n x) x) (hfg : ∀ x ∈ s, Tendsto (fun n => f n x) l (𝓝 (g x))) (hx : x ∈ s) : HasDerivAt g (g' x) x := by have h1 : s ∈ 𝓝 x := hs.mem_nhds hx have h2 : ∀ᶠ n : ι × 𝕜 in l ×ˢ 𝓝 x, HasDerivAt (f n.1) (f' n.1 n.2) n.2 := eventually_prod_iff.2 ⟹_, hf, fun x => x ∈ s, h1, fun {n} => id⟩ refine hasDerivAt_of_tendstoUniformlyOnFilter ?_ h2 (eventually_of_mem h1 hfg) simpa [IsOpen.nhdsWithin_eq hs hx] using tendstoLocallyUniformlyOn_iff_filter.mp hf' x hx /-- A slight variant of `hasDerivAt_of_tendstoLocallyUniformlyOn` with the assumption stated in terms of `DifferentiableOn` rather than `HasDerivAt`. This makes a few proofs nicer in complex analysis where holomorphicity is assumed but the derivative is not known a priori. -/ theorem hasDerivAt_of_tendsto_locally_uniformly_on' [NeBot l] {s : Set 𝕜} (hs : IsOpen s) (hf' : TendstoLocallyUniformlyOn (deriv ∘ f) g' l s) (hf : ∀ᶠ n in l, DifferentiableOn 𝕜 (f n) s) (hfg : ∀ x ∈ s, Tendsto (fun n => f n x) l (𝓝 (g x))) (hx : x ∈ s) : HasDerivAt g (g' x) x := by refine hasDerivAt_of_tendstoLocallyUniformlyOn hs hf' ?_ hfg hx filter_upwards [hf] with n h z hz using ((h z hz).differentiableAt (hs.mem_nhds hz)).hasDerivAt theorem hasDerivAt_of_tendstoUniformlyOn [NeBot l] {s : Set 𝕜} (hs : IsOpen s) (hf' : TendstoUniformlyOn f' g' l s) (hf : ∀ᶠ n in l, ∀ x : 𝕜, x ∈ s → HasDerivAt (f n) (f' n x) x) (hfg : ∀ x : 𝕜, x ∈ s → Tendsto (fun n => f n x) l (𝓝 (g x))) : ∀ x : 𝕜, x ∈ s → HasDerivAt g (g' x) x := fun _ => hasDerivAt_of_tendstoLocallyUniformlyOn hs hf'.tendstoLocallyUniformlyOn hf hfg theorem hasDerivAt_of_tendstoUniformly [NeBot l] (hf' : TendstoUniformly f' g' l) (hf : ∀ᶠ n in l, ∀ x : 𝕜, HasDerivAt (f n) (f' n x) x) (hfg : ∀ x : 𝕜, Tendsto (fun n => f n x) l (𝓝 (g x))) : ∀ x : 𝕜, HasDerivAt g (g' x) x := by intro x have hf : ∀ᶠ n in l, ∀ x : 𝕜, x ∈ Set.univ → HasDerivAt (f n) (f' n x) x := by filter_upwards [hf] with n h x _ using h x have hfg : ∀ x : 𝕜, x ∈ Set.univ → Tendsto (fun n => f n x) l (𝓝 (g x)) := by simp [hfg] have hf' : TendstoUniformlyOn f' g' l Set.univ := by rwa [tendstoUniformlyOn_univ] exact hasDerivAt_of_tendstoUniformlyOn isOpen_univ hf' hf hfg x (Set.mem_univ x) end deriv
Analysis\Calculus\AddTorsor\AffineMap.lean
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Analysis.NormedSpace.ContinuousAffineMap import Mathlib.Analysis.Calculus.ContDiff.Basic /-! # Smooth affine maps This file contains results about smoothness of affine maps. ## Main definitions: * `ContinuousAffineMap.contDiff`: a continuous affine map is smooth -/ namespace ContinuousAffineMap variable {𝕜 V W : Type*} [NontriviallyNormedField 𝕜] variable [NormedAddCommGroup V] [NormedSpace 𝕜 V] variable [NormedAddCommGroup W] [NormedSpace 𝕜 W] /-- A continuous affine map between normed vector spaces is smooth. -/ theorem contDiff {n : ℕ∞} (f : V →Ꭼ[𝕜] W) : ContDiff 𝕜 n f := by rw [f.decomp] apply f.contLinear.contDiff.add exact contDiff_const end ContinuousAffineMap
Analysis\Calculus\AddTorsor\Coord.lean
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Analysis.Calculus.AddTorsor.AffineMap import Mathlib.Analysis.NormedSpace.AddTorsorBases /-! # Barycentric coordinates are smooth -/ variable {ι 𝕜 E P : Type*} [NontriviallyNormedField 𝕜] [CompleteSpace 𝕜] variable [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable [MetricSpace P] [NormedAddTorsor E P] variable [FiniteDimensional 𝕜 E] theorem smooth_barycentric_coord (b : AffineBasis ι 𝕜 E) (i : ι) : ContDiff 𝕜 ⊀ (b.coord i) := (⟹b.coord i, continuous_barycentric_coord b i⟩ : E →Ꭼ[𝕜] 𝕜).contDiff
Analysis\Calculus\BumpFunction\Basic.lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Normed.Module.FiniteDimension /-! # Infinitely smooth "bump" functions A smooth bump function is an infinitely smooth function `f : E → ℝ` supported on a ball that is equal to `1` on a ball of smaller radius. These functions have many uses in real analysis. E.g., - they can be used to construct a smooth partition of unity which is a very useful tool; - they can be used to approximate a continuous function by infinitely smooth functions. There are two classes of spaces where bump functions are guaranteed to exist: inner product spaces and finite dimensional spaces. In this file we define a typeclass `HasContDiffBump` saying that a normed space has a family of smooth bump functions with certain properties. We also define a structure `ContDiffBump` that holds the center and radii of the balls from above. An element `f : ContDiffBump c` can be coerced to a function which is an infinitely smooth function such that - `f` is equal to `1` in `Metric.closedBall c f.rIn`; - `support f = Metric.ball c f.rOut`; - `0 ≀ f x ≀ 1` for all `x`. ## Main Definitions - `ContDiffBump (c : E)`: a structure holding data needed to construct an infinitely smooth bump function. - `ContDiffBumpBase (E : Type*)`: a family of infinitely smooth bump functions that can be used to construct coercion of a `ContDiffBump (c : E)` to a function. - `HasContDiffBump (E : Type*)`: a typeclass saying that `E` has a `ContDiffBumpBase`. Two instances of this typeclass (for inner product spaces and for finite dimensional spaces) are provided elsewhere. ## Keywords smooth function, smooth bump function -/ noncomputable section open Function Set Filter open scoped Topology Filter variable {E X : Type*} /-- `f : ContDiffBump c`, where `c` is a point in a normed vector space, is a bundled smooth function such that - `f` is equal to `1` in `Metric.closedBall c f.rIn`; - `support f = Metric.ball c f.rOut`; - `0 ≀ f x ≀ 1` for all `x`. The structure `ContDiffBump` contains the data required to construct the function: real numbers `rIn`, `rOut`, and proofs of `0 < rIn < rOut`. The function itself is available through `CoeFun` when the space is nice enough, i.e., satisfies the `HasContDiffBump` typeclass. -/ structure ContDiffBump (c : E) where /-- real numbers `0 < rIn < rOut` -/ (rIn rOut : ℝ) rIn_pos : 0 < rIn rIn_lt_rOut : rIn < rOut /-- The base function from which one will construct a family of bump functions. One could add more properties if they are useful and satisfied in the examples of inner product spaces and finite dimensional vector spaces, notably derivative norm control in terms of `R - 1`. TODO: do we ever need `f x = 1 ↔ ‖x‖ ≀ 1`? -/ -- Porting note(#5171): linter not yet ported; was @[nolint has_nonempty_instance] structure ContDiffBumpBase (E : Type*) [NormedAddCommGroup E] [NormedSpace ℝ E] where /-- The function underlying this family of bump functions -/ toFun : ℝ → E → ℝ mem_Icc : ∀ (R : ℝ) (x : E), toFun R x ∈ Icc (0 : ℝ) 1 symmetric : ∀ (R : ℝ) (x : E), toFun R (-x) = toFun R x smooth : ContDiffOn ℝ ⊀ (uncurry toFun) (Ioi (1 : ℝ) ×ˢ (univ : Set E)) eq_one : ∀ R : ℝ, 1 < R → ∀ x : E, ‖x‖ ≀ 1 → toFun R x = 1 support : ∀ R : ℝ, 1 < R → Function.support (toFun R) = Metric.ball (0 : E) R /-- A class registering that a real vector space admits bump functions. This will be instantiated first for inner product spaces, and then for finite-dimensional normed spaces. We use a specific class instead of `Nonempty (ContDiffBumpBase E)` for performance reasons. -/ class HasContDiffBump (E : Type*) [NormedAddCommGroup E] [NormedSpace ℝ E] : Prop where out : Nonempty (ContDiffBumpBase E) /-- In a space with `C^∞` bump functions, register some function that will be used as a basis to construct bump functions of arbitrary size around any point. -/ def someContDiffBumpBase (E : Type*) [NormedAddCommGroup E] [NormedSpace ℝ E] [hb : HasContDiffBump E] : ContDiffBumpBase E := Nonempty.some hb.out namespace ContDiffBump theorem rOut_pos {c : E} (f : ContDiffBump c) : 0 < f.rOut := f.rIn_pos.trans f.rIn_lt_rOut theorem one_lt_rOut_div_rIn {c : E} (f : ContDiffBump c) : 1 < f.rOut / f.rIn := by rw [one_lt_div f.rIn_pos] exact f.rIn_lt_rOut instance (c : E) : Inhabited (ContDiffBump c) := ⟹⟹1, 2, zero_lt_one, one_lt_two⟩⟩ variable [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup X] [NormedSpace ℝ X] [HasContDiffBump E] {c : E} (f : ContDiffBump c) {x : E} {n : ℕ∞} /-- The function defined by `f : ContDiffBump c`. Use automatic coercion to function instead. -/ @[coe] def toFun {c : E} (f : ContDiffBump c) : E → ℝ := (someContDiffBumpBase E).toFun (f.rOut / f.rIn) ∘ fun x ↩ (f.rIn⁻¹ • (x - c)) instance : CoeFun (ContDiffBump c) fun _ => E → ℝ := ⟹toFun⟩ protected theorem apply (x : E) : f x = (someContDiffBumpBase E).toFun (f.rOut / f.rIn) (f.rIn⁻¹ • (x - c)) := rfl protected theorem sub (x : E) : f (c - x) = f (c + x) := by simp [f.apply, ContDiffBumpBase.symmetric] protected theorem neg (f : ContDiffBump (0 : E)) (x : E) : f (-x) = f x := by simp_rw [← zero_sub, f.sub, zero_add] open Metric theorem one_of_mem_closedBall (hx : x ∈ closedBall c f.rIn) : f x = 1 := by apply ContDiffBumpBase.eq_one _ _ f.one_lt_rOut_div_rIn simpa only [norm_smul, Real.norm_eq_abs, abs_inv, abs_of_nonneg f.rIn_pos.le, ← div_eq_inv_mul, div_le_one f.rIn_pos] using mem_closedBall_iff_norm.1 hx theorem nonneg : 0 ≀ f x := (ContDiffBumpBase.mem_Icc (someContDiffBumpBase E) _ _).1 /-- A version of `ContDiffBump.nonneg` with `x` explicit -/ theorem nonneg' (x : E) : 0 ≀ f x := f.nonneg theorem le_one : f x ≀ 1 := (ContDiffBumpBase.mem_Icc (someContDiffBumpBase E) _ _).2 theorem support_eq : Function.support f = Metric.ball c f.rOut := by simp only [toFun, support_comp_eq_preimage, ContDiffBumpBase.support _ _ f.one_lt_rOut_div_rIn] ext x simp only [mem_ball_iff_norm, sub_zero, norm_smul, mem_preimage, Real.norm_eq_abs, abs_inv, abs_of_pos f.rIn_pos, ← div_eq_inv_mul, div_lt_div_right f.rIn_pos] theorem tsupport_eq : tsupport f = closedBall c f.rOut := by simp_rw [tsupport, f.support_eq, closure_ball _ f.rOut_pos.ne'] theorem pos_of_mem_ball (hx : x ∈ ball c f.rOut) : 0 < f x := f.nonneg.lt_of_ne' <| by rwa [← support_eq, mem_support] at hx theorem zero_of_le_dist (hx : f.rOut ≀ dist x c) : f x = 0 := by rwa [← nmem_support, support_eq, mem_ball, not_lt] protected theorem hasCompactSupport [FiniteDimensional ℝ E] : HasCompactSupport f := by simp_rw [HasCompactSupport, f.tsupport_eq, isCompact_closedBall] theorem eventuallyEq_one_of_mem_ball (h : x ∈ ball c f.rIn) : f =á¶ [𝓝 x] 1 := mem_of_superset (closedBall_mem_nhds_of_mem h) fun _ ↩ f.one_of_mem_closedBall theorem eventuallyEq_one : f =á¶ [𝓝 c] 1 := f.eventuallyEq_one_of_mem_ball (mem_ball_self f.rIn_pos) /-- `ContDiffBump` is `𝒞ⁿ` in all its arguments. -/ protected theorem _root_.ContDiffWithinAt.contDiffBump {c g : X → E} {s : Set X} {f : ∀ x, ContDiffBump (c x)} {x : X} (hc : ContDiffWithinAt ℝ n c s x) (hr : ContDiffWithinAt ℝ n (fun x => (f x).rIn) s x) (hR : ContDiffWithinAt ℝ n (fun x => (f x).rOut) s x) (hg : ContDiffWithinAt ℝ n g s x) : ContDiffWithinAt ℝ n (fun x => f x (g x)) s x := by change ContDiffWithinAt ℝ n (uncurry (someContDiffBumpBase E).toFun ∘ fun x : X => ((f x).rOut / (f x).rIn, (f x).rIn⁻¹ • (g x - c x))) s x refine (((someContDiffBumpBase E).smooth.contDiffAt ?_).of_le le_top).comp_contDiffWithinAt x ?_ · exact prod_mem_nhds (Ioi_mem_nhds (f x).one_lt_rOut_div_rIn) univ_mem · exact (hR.div hr (f x).rIn_pos.ne').prod ((hr.inv (f x).rIn_pos.ne').smul (hg.sub hc)) /-- `ContDiffBump` is `𝒞ⁿ` in all its arguments. -/ protected nonrec theorem _root_.ContDiffAt.contDiffBump {c g : X → E} {f : ∀ x, ContDiffBump (c x)} {x : X} (hc : ContDiffAt ℝ n c x) (hr : ContDiffAt ℝ n (fun x => (f x).rIn) x) (hR : ContDiffAt ℝ n (fun x => (f x).rOut) x) (hg : ContDiffAt ℝ n g x) : ContDiffAt ℝ n (fun x => f x (g x)) x := hc.contDiffBump hr hR hg theorem _root_.ContDiff.contDiffBump {c g : X → E} {f : ∀ x, ContDiffBump (c x)} (hc : ContDiff ℝ n c) (hr : ContDiff ℝ n fun x => (f x).rIn) (hR : ContDiff ℝ n fun x => (f x).rOut) (hg : ContDiff ℝ n g) : ContDiff ℝ n fun x => f x (g x) := by rw [contDiff_iff_contDiffAt] at * exact fun x => (hc x).contDiffBump (hr x) (hR x) (hg x) protected theorem contDiff : ContDiff ℝ n f := contDiff_const.contDiffBump contDiff_const contDiff_const contDiff_id protected theorem contDiffAt : ContDiffAt ℝ n f x := f.contDiff.contDiffAt protected theorem contDiffWithinAt {s : Set E} : ContDiffWithinAt ℝ n f s x := f.contDiffAt.contDiffWithinAt protected theorem continuous : Continuous f := contDiff_zero.mp f.contDiff end ContDiffBump
Analysis\Calculus\BumpFunction\Convolution.lean
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Analysis.Convolution import Mathlib.Analysis.Calculus.BumpFunction.Normed import Mathlib.MeasureTheory.Integral.Average import Mathlib.MeasureTheory.Covering.Differentiation import Mathlib.MeasureTheory.Covering.BesicovitchVectorSpace import Mathlib.MeasureTheory.Measure.Haar.Unique /-! # Convolution with a bump function In this file we prove lemmas about convolutions `(φ.normed ÎŒ ⋆[lsmul ℝ ℝ, ÎŒ] g) x₀`, where `φ : ContDiffBump 0` is a smooth bump function. We prove that this convolution is equal to `g x₀` if `g` is a constant on `Metric.ball x₀ φ.rOut`. We also provide estimates in the case if `g x` is close to `g x₀` on this ball. ## Main results - `ContDiffBump.convolution_tendsto_right_of_continuous`: Let `g` be a continuous function; let `φ i` be a family of `ContDiffBump 0` functions with. If `(φ i).rOut` tends to zero along a filter `l`, then `((φ i).normed ÎŒ ⋆[lsmul ℝ ℝ, ÎŒ] g) x₀` tends to `g x₀` along the same filter. - `ContDiffBump.convolution_tendsto_right`: generalization of the above lemma. - `ContDiffBump.ae_convolution_tendsto_right_of_locallyIntegrable`: let `g` be a locally integrable function. Then the convolution of `g` with a family of bump functions with support tending to `0` converges almost everywhere to `g`. ## Keywords convolution, smooth function, bump function -/ universe uG uE' open ContinuousLinearMap Metric MeasureTheory Filter Function Measure Set open scoped Convolution Topology namespace ContDiffBump variable {G : Type uG} {E' : Type uE'} [NormedAddCommGroup E'] {g : G → E'} [MeasurableSpace G] {ÎŒ : MeasureTheory.Measure G} [NormedSpace ℝ E'] [NormedAddCommGroup G] [NormedSpace ℝ G] [HasContDiffBump G] [CompleteSpace E'] {φ : ContDiffBump (0 : G)} {x₀ : G} /-- If `φ` is a bump function, compute `(φ ⋆ g) x₀` if `g` is constant on `Metric.ball x₀ φ.rOut`. -/ theorem convolution_eq_right {x₀ : G} (hg : ∀ x ∈ ball x₀ φ.rOut, g x = g x₀) : (φ ⋆[lsmul ℝ ℝ, ÎŒ] g : G → E') x₀ = integral ÎŒ φ • g x₀ := by simp_rw [convolution_eq_right' _ φ.support_eq.subset hg, lsmul_apply, integral_smul_const] variable [BorelSpace G] variable [IsLocallyFiniteMeasure ÎŒ] [ÎŒ.IsOpenPosMeasure] variable [FiniteDimensional ℝ G] /-- If `φ` is a normed bump function, compute `φ ⋆ g` if `g` is constant on `Metric.ball x₀ φ.rOut`. -/ theorem normed_convolution_eq_right {x₀ : G} (hg : ∀ x ∈ ball x₀ φ.rOut, g x = g x₀) : (φ.normed ÎŒ ⋆[lsmul ℝ ℝ, ÎŒ] g : G → E') x₀ = g x₀ := by rw [convolution_eq_right' _ φ.support_normed_eq.subset hg] exact integral_normed_smul φ ÎŒ (g x₀) variable [ÎŒ.IsAddLeftInvariant] /-- If `φ` is a normed bump function, approximate `(φ ⋆ g) x₀` if `g` is near `g x₀` on a ball with radius `φ.rOut` around `x₀`. -/ theorem dist_normed_convolution_le {x₀ : G} {ε : ℝ} (hmg : AEStronglyMeasurable g ÎŒ) (hg : ∀ x ∈ ball x₀ φ.rOut, dist (g x) (g x₀) ≀ ε) : dist ((φ.normed ÎŒ ⋆[lsmul ℝ ℝ, ÎŒ] g : G → E') x₀) (g x₀) ≀ ε := dist_convolution_le (by simp_rw [← dist_self (g x₀), hg x₀ (mem_ball_self φ.rOut_pos)]) φ.support_normed_eq.subset φ.nonneg_normed φ.integral_normed hmg hg /-- `(φ i ⋆ g i) (k i)` tends to `z₀` as `i` tends to some filter `l` if * `φ` is a sequence of normed bump functions such that `(φ i).rOut` tends to `0` as `i` tends to `l`; * `g i` is `ÎŒ`-a.e. strongly measurable as `i` tends to `l`; * `g i x` tends to `z₀` as `(i, x)` tends to `l ×ˢ 𝓝 x₀`; * `k i` tends to `x₀`. -/ nonrec theorem convolution_tendsto_right {ι} {φ : ι → ContDiffBump (0 : G)} {g : ι → G → E'} {k : ι → G} {x₀ : G} {z₀ : E'} {l : Filter ι} (hφ : Tendsto (fun i => (φ i).rOut) l (𝓝 0)) (hig : ∀ᶠ i in l, AEStronglyMeasurable (g i) ÎŒ) (hcg : Tendsto (uncurry g) (l ×ˢ 𝓝 x₀) (𝓝 z₀)) (hk : Tendsto k l (𝓝 x₀)) : Tendsto (fun i => ((φ i).normed ÎŒ ⋆[lsmul ℝ ℝ, ÎŒ] g i) (k i)) l (𝓝 z₀) := convolution_tendsto_right (eventually_of_forall fun i => (φ i).nonneg_normed) (eventually_of_forall fun i => (φ i).integral_normed) (tendsto_support_normed_smallSets hφ) hig hcg hk /-- Special case of `ContDiffBump.convolution_tendsto_right` where `g` is continuous, and the limit is taken only in the first function. -/ theorem convolution_tendsto_right_of_continuous {ι} {φ : ι → ContDiffBump (0 : G)} {l : Filter ι} (hφ : Tendsto (fun i => (φ i).rOut) l (𝓝 0)) (hg : Continuous g) (x₀ : G) : Tendsto (fun i => ((φ i).normed ÎŒ ⋆[lsmul ℝ ℝ, ÎŒ] g) x₀) l (𝓝 (g x₀)) := convolution_tendsto_right hφ (eventually_of_forall fun _ => hg.aestronglyMeasurable) ((hg.tendsto x₀).comp tendsto_snd) tendsto_const_nhds /-- If a function `g` is locally integrable, then the convolution `φ i * g` converges almost everywhere to `g` if `φ i` is a sequence of bump functions with support tending to `0`, provided that the ratio between the inner and outer radii of `φ i` remains bounded. -/ theorem ae_convolution_tendsto_right_of_locallyIntegrable {ι} {φ : ι → ContDiffBump (0 : G)} {l : Filter ι} {K : ℝ} (hφ : Tendsto (fun i ↩ (φ i).rOut) l (𝓝 0)) (h'φ : ∀ᶠ i in l, (φ i).rOut ≀ K * (φ i).rIn) (hg : LocallyIntegrable g ÎŒ) : ∀ᵐ x₀ ∂Ό, Tendsto (fun i ↩ ((φ i).normed ÎŒ ⋆[lsmul ℝ ℝ, ÎŒ] g) x₀) l (𝓝 (g x₀)) := by have : IsAddHaarMeasure ÎŒ := ⟚⟩ -- By Lebesgue differentiation theorem, the average of `g` on a small ball converges -- almost everywhere to the value of `g` as the radius shrinks to zero. -- We will see that this set of points satisfies the desired conclusion. filter_upwards [(Besicovitch.vitaliFamily ÎŒ).ae_tendsto_average_norm_sub hg] with x₀ h₀ simp only [convolution_eq_swap, lsmul_apply] have hφ' : Tendsto (fun i ↩ (φ i).rOut) l (𝓝[>] 0) := tendsto_nhdsWithin_iff.2 ⟹hφ, eventually_of_forall (fun i ↩ (φ i).rOut_pos)⟩ have := (h₀.comp (Besicovitch.tendsto_filterAt ÎŒ x₀)).comp hφ' simp only [Function.comp] at this apply tendsto_integral_smul_of_tendsto_average_norm_sub (K ^ (FiniteDimensional.finrank ℝ G)) this · filter_upwards with i using hg.integrableOn_isCompact (isCompact_closedBall _ _) · apply tendsto_const_nhds.congr (fun i ↩ ?_) rw [← integral_neg_eq_self] simp only [sub_neg_eq_add, integral_add_left_eq_self, integral_normed] · filter_upwards with i change support ((ContDiffBump.normed (φ i) ÎŒ) ∘ (fun y ↩ x₀ - y)) ⊆ closedBall x₀ (φ i).rOut simp only [support_comp_eq_preimage, support_normed_eq] intro x hx simp only [mem_preimage, mem_ball, dist_zero_right] at hx simpa [dist_eq_norm_sub'] using hx.le · filter_upwards [h'φ] with i hi x rw [abs_of_nonneg (nonneg_normed _ _), addHaar_closedBall_center] exact (φ i).normed_le_div_measure_closedBall_rOut _ _ hi _ end ContDiffBump
Analysis\Calculus\BumpFunction\FiniteDimension.lean
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.SmoothSeries import Mathlib.Analysis.Calculus.BumpFunction.InnerProduct import Mathlib.Analysis.Convolution import Mathlib.Analysis.InnerProductSpace.EuclideanDist import Mathlib.Data.Set.Pointwise.Support import Mathlib.MeasureTheory.Measure.Haar.NormedSpace import Mathlib.MeasureTheory.Measure.Haar.Unique /-! # Bump functions in finite-dimensional vector spaces Let `E` be a finite-dimensional real normed vector space. We show that any open set `s` in `E` is exactly the support of a smooth function taking values in `[0, 1]`, in `IsOpen.exists_smooth_support_eq`. Then we use this construction to construct bump functions with nice behavior, by convolving the indicator function of `closedBall 0 1` with a function as above with `s = ball 0 D`. -/ noncomputable section open Set Metric TopologicalSpace Function Asymptotics MeasureTheory FiniteDimensional ContinuousLinearMap Filter MeasureTheory.Measure Bornology open scoped Pointwise Topology NNReal Convolution variable {E : Type*} [NormedAddCommGroup E] section variable [NormedSpace ℝ E] [FiniteDimensional ℝ E] /-- If a set `s` is a neighborhood of `x`, then there exists a smooth function `f` taking values in `[0, 1]`, supported in `s` and with `f x = 1`. -/ theorem exists_smooth_tsupport_subset {s : Set E} {x : E} (hs : s ∈ 𝓝 x) : ∃ f : E → ℝ, tsupport f ⊆ s ∧ HasCompactSupport f ∧ ContDiff ℝ ⊀ f ∧ range f ⊆ Icc 0 1 ∧ f x = 1 := by obtain ⟹d : ℝ, d_pos : 0 < d, hd : Euclidean.closedBall x d ⊆ s⟩ := Euclidean.nhds_basis_closedBall.mem_iff.1 hs let c : ContDiffBump (toEuclidean x) := { rIn := d / 2 rOut := d rIn_pos := half_pos d_pos rIn_lt_rOut := half_lt_self d_pos } let f : E → ℝ := c ∘ toEuclidean have f_supp : f.support ⊆ Euclidean.ball x d := by intro y hy have : toEuclidean y ∈ Function.support c := by simpa only [Function.mem_support, Function.comp_apply, Ne] using hy rwa [c.support_eq] at this have f_tsupp : tsupport f ⊆ Euclidean.closedBall x d := by rw [tsupport, ← Euclidean.closure_ball _ d_pos.ne'] exact closure_mono f_supp refine ⟹f, f_tsupp.trans hd, ?_, ?_, ?_, ?_⟩ · refine isCompact_of_isClosed_isBounded isClosed_closure ?_ have : IsBounded (Euclidean.closedBall x d) := Euclidean.isCompact_closedBall.isBounded refine this.subset (Euclidean.isClosed_closedBall.closure_subset_iff.2 ?_) exact f_supp.trans Euclidean.ball_subset_closedBall · apply c.contDiff.comp exact ContinuousLinearEquiv.contDiff _ · rintro t ⟹y, rfl⟩ exact ⟹c.nonneg, c.le_one⟩ · apply c.one_of_mem_closedBall apply mem_closedBall_self exact (half_pos d_pos).le /-- Given an open set `s` in a finite-dimensional real normed vector space, there exists a smooth function with values in `[0, 1]` whose support is exactly `s`. -/ theorem IsOpen.exists_smooth_support_eq {s : Set E} (hs : IsOpen s) : ∃ f : E → ℝ, f.support = s ∧ ContDiff ℝ ⊀ f ∧ Set.range f ⊆ Set.Icc 0 1 := by /- For any given point `x` in `s`, one can construct a smooth function with support in `s` and nonzero at `x`. By second-countability, it follows that we may cover `s` with the supports of countably many such functions, say `g i`. Then `∑ i, r i • g i` will be the desired function if `r i` is a sequence of positive numbers tending quickly enough to zero. Indeed, this ensures that, for any `k ≀ i`, the `k`-th derivative of `r i • g i` is bounded by a prescribed (summable) sequence `u i`. From this, the summability of the series and of its successive derivatives follows. -/ rcases eq_empty_or_nonempty s with (rfl | h's) · exact ⟹fun _ => 0, Function.support_zero, contDiff_const, by simp only [range_const, singleton_subset_iff, left_mem_Icc, zero_le_one]⟩ let ι := { f : E → ℝ // f.support ⊆ s ∧ HasCompactSupport f ∧ ContDiff ℝ ⊀ f ∧ range f ⊆ Icc 0 1 } obtain ⟹T, T_count, hT⟩ : ∃ T : Set ι, T.Countable ∧ ⋃ f ∈ T, support (f : E → ℝ) = s := by have : ⋃ f : ι, (f : E → ℝ).support = s := by refine Subset.antisymm (iUnion_subset fun f => f.2.1) ?_ intro x hx rcases exists_smooth_tsupport_subset (hs.mem_nhds hx) with ⟹f, hf⟩ let g : ι := ⟹f, (subset_tsupport f).trans hf.1, hf.2.1, hf.2.2.1, hf.2.2.2.1⟩ have : x ∈ support (g : E → ℝ) := by simp only [hf.2.2.2.2, Subtype.coe_mk, mem_support, Ne, one_ne_zero, not_false_iff] exact mem_iUnion_of_mem _ this simp_rw [← this] apply isOpen_iUnion_countable rintro ⟹f, hf⟩ exact hf.2.2.1.continuous.isOpen_support obtain ⟹g0, hg⟩ : ∃ g0 : ℕ → ι, T = range g0 := by apply Countable.exists_eq_range T_count rcases eq_empty_or_nonempty T with (rfl | hT) · simp only [ι, iUnion_false, iUnion_empty] at hT simp only [← hT, mem_empty_iff_false, iUnion_of_empty, iUnion_empty, Set.not_nonempty_empty] at h's · exact hT let g : ℕ → E → ℝ := fun n => (g0 n).1 have g_s : ∀ n, support (g n) ⊆ s := fun n => (g0 n).2.1 have s_g : ∀ x ∈ s, ∃ n, x ∈ support (g n) := fun x hx ↩ by rw [← hT] at hx obtain ⟹i, iT, hi⟩ : ∃ i ∈ T, x ∈ support (i : E → ℝ) := by simpa only [mem_iUnion, exists_prop] using hx rw [hg, mem_range] at iT rcases iT with ⟹n, hn⟩ rw [← hn] at hi exact ⟹n, hi⟩ have g_smooth : ∀ n, ContDiff ℝ ⊀ (g n) := fun n => (g0 n).2.2.2.1 have g_comp_supp : ∀ n, HasCompactSupport (g n) := fun n => (g0 n).2.2.1 have g_nonneg : ∀ n x, 0 ≀ g n x := fun n x => ((g0 n).2.2.2.2 (mem_range_self x)).1 obtain ⟹ή, ÎŽpos, c, ÎŽc, c_lt⟩ : ∃ ÎŽ : ℕ → ℝ≥0, (∀ i : ℕ, 0 < ÎŽ i) ∧ ∃ c : NNReal, HasSum ÎŽ c ∧ c < 1 := NNReal.exists_pos_sum_of_countable one_ne_zero ℕ have : ∀ n : ℕ, ∃ r : ℝ, 0 < r ∧ ∀ i ≀ n, ∀ x, ‖iteratedFDeriv ℝ i (r • g n) x‖ ≀ ÎŽ n := by intro n have : ∀ i, ∃ R, ∀ x, ‖iteratedFDeriv ℝ i (fun x => g n x) x‖ ≀ R := by intro i have : BddAbove (range fun x => ‖iteratedFDeriv ℝ i (fun x : E => g n x) x‖) := by apply ((g_smooth n).continuous_iteratedFDeriv le_top).norm.bddAbove_range_of_hasCompactSupport apply HasCompactSupport.comp_left _ norm_zero apply (g_comp_supp n).iteratedFDeriv rcases this with ⟹R, hR⟩ exact ⟹R, fun x => hR (mem_range_self _)⟩ choose R hR using this let M := max (((Finset.range (n + 1)).image R).max' (by simp)) 1 have ÎŽnpos : 0 < ÎŽ n := ÎŽpos n have IR : ∀ i ≀ n, R i ≀ M := by intro i hi refine le_trans ?_ (le_max_left _ _) apply Finset.le_max' apply Finset.mem_image_of_mem -- Porting note: was -- simp only [Finset.mem_range] -- linarith simpa only [Finset.mem_range, Nat.lt_add_one_iff] refine ⟹M⁻¹ * ÎŽ n, by positivity, fun i hi x => ?_⟩ calc ‖iteratedFDeriv ℝ i ((M⁻¹ * ÎŽ n) • g n) x‖ = ‖(M⁻¹ * ÎŽ n) • iteratedFDeriv ℝ i (g n) x‖ := by rw [iteratedFDeriv_const_smul_apply]; exact (g_smooth n).of_le le_top _ = M⁻¹ * ÎŽ n * ‖iteratedFDeriv ℝ i (g n) x‖ := by rw [norm_smul _ (iteratedFDeriv ℝ i (g n) x), Real.norm_of_nonneg]; positivity _ ≀ M⁻¹ * ÎŽ n * M := (mul_le_mul_of_nonneg_left ((hR i x).trans (IR i hi)) (by positivity)) _ = ÎŽ n := by field_simp choose r rpos hr using this have S : ∀ x, Summable fun n => (r n • g n) x := fun x ↩ by refine .of_nnnorm_bounded _ ÎŽc.summable fun n => ?_ rw [← NNReal.coe_le_coe, coe_nnnorm] simpa only [norm_iteratedFDeriv_zero] using hr n 0 (zero_le n) x refine ⟹fun x => ∑' n, (r n • g n) x, ?_, ?_, ?_⟩ · apply Subset.antisymm · intro x hx simp only [Pi.smul_apply, Algebra.id.smul_eq_mul, mem_support, Ne] at hx contrapose! hx have : ∀ n, g n x = 0 := by intro n contrapose! hx exact g_s n hx simp only [this, mul_zero, tsum_zero] · intro x hx obtain ⟹n, hn⟩ : ∃ n, x ∈ support (g n) := s_g x hx have I : 0 < r n * g n x := mul_pos (rpos n) (lt_of_le_of_ne (g_nonneg n x) (Ne.symm hn)) exact ne_of_gt (tsum_pos (S x) (fun i => mul_nonneg (rpos i).le (g_nonneg i x)) n I) · refine contDiff_tsum_of_eventually (fun n => (g_smooth n).const_smul (r n)) (fun k _ => (NNReal.hasSum_coe.2 ÎŽc).summable) ?_ intro i _ simp only [Nat.cofinite_eq_atTop, Pi.smul_apply, Algebra.id.smul_eq_mul, Filter.eventually_atTop] exact ⟹i, fun n hn x => hr _ _ hn _⟩ · rintro - ⟹y, rfl⟩ refine ⟹tsum_nonneg fun n => mul_nonneg (rpos n).le (g_nonneg n y), le_trans ?_ c_lt.le⟩ have A : HasSum (fun n => (ÎŽ n : ℝ)) c := NNReal.hasSum_coe.2 ÎŽc simp only [Pi.smul_apply, smul_eq_mul, NNReal.val_eq_coe, ← A.tsum_eq] apply tsum_le_tsum _ (S y) A.summable intro n apply (le_abs_self _).trans simpa only [norm_iteratedFDeriv_zero] using hr n 0 (zero_le n) y end section namespace ExistsContDiffBumpBase /-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces. It is the characteristic function of the closed unit ball. -/ def φ : E → ℝ := (closedBall (0 : E) 1).indicator fun _ => (1 : ℝ) variable [NormedSpace ℝ E] [FiniteDimensional ℝ E] section HelperDefinitions variable (E) theorem u_exists : ∃ u : E → ℝ, ContDiff ℝ ⊀ u ∧ (∀ x, u x ∈ Icc (0 : ℝ) 1) ∧ support u = ball 0 1 ∧ ∀ x, u (-x) = u x := by have A : IsOpen (ball (0 : E) 1) := isOpen_ball obtain ⟹f, f_support, f_smooth, f_range⟩ : ∃ f : E → ℝ, f.support = ball (0 : E) 1 ∧ ContDiff ℝ ⊀ f ∧ Set.range f ⊆ Set.Icc 0 1 := A.exists_smooth_support_eq have B : ∀ x, f x ∈ Icc (0 : ℝ) 1 := fun x => f_range (mem_range_self x) refine ⟹fun x => (f x + f (-x)) / 2, ?_, ?_, ?_, ?_⟩ · exact (f_smooth.add (f_smooth.comp contDiff_neg)).div_const _ · intro x simp only [mem_Icc] constructor · linarith [(B x).1, (B (-x)).1] · linarith [(B x).2, (B (-x)).2] · refine support_eq_iff.2 ⟹fun x hx => ?_, fun x hx => ?_⟩ · apply ne_of_gt have : 0 < f x := by apply lt_of_le_of_ne (B x).1 (Ne.symm _) rwa [← f_support] at hx linarith [(B (-x)).1] · have I1 : x ∉ support f := by rwa [f_support] have I2 : -x ∉ support f := by rw [f_support] simpa using hx simp only [mem_support, Classical.not_not] at I1 I2 simp only [I1, I2, add_zero, zero_div] · intro x; simp only [add_comm, neg_neg] variable {E} /-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces, which is smooth, symmetric, and with support equal to the unit ball. -/ def u (x : E) : ℝ := Classical.choose (u_exists E) x variable (E) theorem u_smooth : ContDiff ℝ ⊀ (u : E → ℝ) := (Classical.choose_spec (u_exists E)).1 theorem u_continuous : Continuous (u : E → ℝ) := (u_smooth E).continuous theorem u_support : support (u : E → ℝ) = ball 0 1 := (Classical.choose_spec (u_exists E)).2.2.1 theorem u_compact_support : HasCompactSupport (u : E → ℝ) := by rw [hasCompactSupport_def, u_support, closure_ball (0 : E) one_ne_zero] exact isCompact_closedBall _ _ variable {E} theorem u_nonneg (x : E) : 0 ≀ u x := ((Classical.choose_spec (u_exists E)).2.1 x).1 theorem u_le_one (x : E) : u x ≀ 1 := ((Classical.choose_spec (u_exists E)).2.1 x).2 theorem u_neg (x : E) : u (-x) = u x := (Classical.choose_spec (u_exists E)).2.2.2 x variable [MeasurableSpace E] [BorelSpace E] local notation "ÎŒ" => MeasureTheory.Measure.addHaar variable (E) theorem u_int_pos : 0 < ∫ x : E, u x ∂Ό := by refine (integral_pos_iff_support_of_nonneg u_nonneg ?_).mpr ?_ · exact (u_continuous E).integrable_of_hasCompactSupport (u_compact_support E) · rw [u_support]; exact measure_ball_pos _ _ zero_lt_one variable {E} /-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces, which is smooth, symmetric, with support equal to the ball of radius `D` and integral `1`. -/ def w (D : ℝ) (x : E) : ℝ := ((∫ x : E, u x ∂Ό) * |D| ^ finrank ℝ E)⁻¹ • u (D⁻¹ • x) theorem w_def (D : ℝ) : (w D : E → ℝ) = fun x => ((∫ x : E, u x ∂Ό) * |D| ^ finrank ℝ E)⁻¹ • u (D⁻¹ • x) := by ext1 x; rfl theorem w_nonneg (D : ℝ) (x : E) : 0 ≀ w D x := by apply mul_nonneg _ (u_nonneg _) apply inv_nonneg.2 apply mul_nonneg (u_int_pos E).le norm_cast apply pow_nonneg (abs_nonneg D) theorem w_mul_φ_nonneg (D : ℝ) (x y : E) : 0 ≀ w D y * φ (x - y) := mul_nonneg (w_nonneg D y) (indicator_nonneg (by simp only [zero_le_one, imp_true_iff]) _) variable (E) theorem w_integral {D : ℝ} (Dpos : 0 < D) : ∫ x : E, w D x ∂Ό = 1 := by simp_rw [w, integral_smul] rw [integral_comp_inv_smul_of_nonneg ÎŒ (u : E → ℝ) Dpos.le, abs_of_nonneg Dpos.le, mul_comm] field_simp [(u_int_pos E).ne'] theorem w_support {D : ℝ} (Dpos : 0 < D) : support (w D : E → ℝ) = ball 0 D := by have B : D • ball (0 : E) 1 = ball 0 D := by rw [smul_unitBall Dpos.ne', Real.norm_of_nonneg Dpos.le] have C : D ^ finrank ℝ E ≠ 0 := by norm_cast exact pow_ne_zero _ Dpos.ne' simp only [w_def, Algebra.id.smul_eq_mul, support_mul, support_inv, univ_inter, support_comp_inv_smul₀ Dpos.ne', u_support, B, support_const (u_int_pos E).ne', support_const C, abs_of_nonneg Dpos.le] theorem w_compact_support {D : ℝ} (Dpos : 0 < D) : HasCompactSupport (w D : E → ℝ) := by rw [hasCompactSupport_def, w_support E Dpos, closure_ball (0 : E) Dpos.ne'] exact isCompact_closedBall _ _ variable {E} /-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces. It is the convolution between a smooth function of integral `1` supported in the ball of radius `D`, with the indicator function of the closed unit ball. Therefore, it is smooth, equal to `1` on the ball of radius `1 - D`, with support equal to the ball of radius `1 + D`. -/ def y (D : ℝ) : E → ℝ := w D ⋆[lsmul ℝ ℝ, ÎŒ] φ theorem y_neg (D : ℝ) (x : E) : y D (-x) = y D x := by apply convolution_neg_of_neg_eq · filter_upwards with x simp only [w_def, Real.rpow_natCast, mul_inv_rev, smul_neg, u_neg, smul_eq_mul, forall_const] · filter_upwards with x simp only [φ, indicator, mem_closedBall, dist_zero_right, norm_neg, forall_const] theorem y_eq_one_of_mem_closedBall {D : ℝ} {x : E} (Dpos : 0 < D) (hx : x ∈ closedBall (0 : E) (1 - D)) : y D x = 1 := by change (w D ⋆[lsmul ℝ ℝ, ÎŒ] φ) x = 1 have B : ∀ y : E, y ∈ ball x D → φ y = 1 := by have C : ball x D ⊆ ball 0 1 := by apply ball_subset_ball' simp only [mem_closedBall] at hx linarith only [hx] intro y hy simp only [φ, indicator, mem_closedBall, ite_eq_left_iff, not_le, zero_ne_one] intro h'y linarith only [mem_ball.1 (C hy), h'y] have Bx : φ x = 1 := B _ (mem_ball_self Dpos) have B' : ∀ y, y ∈ ball x D → φ y = φ x := by rw [Bx]; exact B rw [convolution_eq_right' _ (le_of_eq (w_support E Dpos)) B'] simp only [lsmul_apply, Algebra.id.smul_eq_mul, integral_mul_right, w_integral E Dpos, Bx, one_mul] theorem y_eq_zero_of_not_mem_ball {D : ℝ} {x : E} (Dpos : 0 < D) (hx : x ∉ ball (0 : E) (1 + D)) : y D x = 0 := by change (w D ⋆[lsmul ℝ ℝ, ÎŒ] φ) x = 0 have B : ∀ y, y ∈ ball x D → φ y = 0 := by intro y hy simp only [φ, indicator, mem_closedBall_zero_iff, ite_eq_right_iff, one_ne_zero] intro h'y have C : ball y D ⊆ ball 0 (1 + D) := by apply ball_subset_ball' rw [← dist_zero_right] at h'y linarith only [h'y] exact hx (C (mem_ball_comm.1 hy)) have Bx : φ x = 0 := B _ (mem_ball_self Dpos) have B' : ∀ y, y ∈ ball x D → φ y = φ x := by rw [Bx]; exact B rw [convolution_eq_right' _ (le_of_eq (w_support E Dpos)) B'] simp only [lsmul_apply, Algebra.id.smul_eq_mul, Bx, mul_zero, integral_const] theorem y_nonneg (D : ℝ) (x : E) : 0 ≀ y D x := integral_nonneg (w_mul_φ_nonneg D x) theorem y_le_one {D : ℝ} (x : E) (Dpos : 0 < D) : y D x ≀ 1 := by have A : (w D ⋆[lsmul ℝ ℝ, ÎŒ] φ) x ≀ (w D ⋆[lsmul ℝ ℝ, ÎŒ] 1) x := by apply convolution_mono_right_of_nonneg _ (w_nonneg D) (indicator_le_self' fun x _ => zero_le_one) fun _ => zero_le_one refine (HasCompactSupport.convolutionExistsLeft _ (w_compact_support E Dpos) ?_ (locallyIntegrable_const (1 : ℝ)) x).integrable exact continuous_const.mul ((u_continuous E).comp (continuous_id.const_smul _)) have B : (w D ⋆[lsmul ℝ ℝ, ÎŒ] fun _ => (1 : ℝ)) x = 1 := by simp only [convolution, ContinuousLinearMap.map_smul, mul_inv_rev, coe_smul', mul_one, lsmul_apply, Algebra.id.smul_eq_mul, integral_mul_left, w_integral E Dpos, Pi.smul_apply] exact A.trans (le_of_eq B) theorem y_pos_of_mem_ball {D : ℝ} {x : E} (Dpos : 0 < D) (D_lt_one : D < 1) (hx : x ∈ ball (0 : E) (1 + D)) : 0 < y D x := by simp only [mem_ball_zero_iff] at hx refine (integral_pos_iff_support_of_nonneg (w_mul_φ_nonneg D x) ?_).2 ?_ · have F_comp : HasCompactSupport (w D) := w_compact_support E Dpos have B : LocallyIntegrable (φ : E → ℝ) ÎŒ := (locallyIntegrable_const _).indicator measurableSet_closedBall have C : Continuous (w D : E → ℝ) := continuous_const.mul ((u_continuous E).comp (continuous_id.const_smul _)) exact (HasCompactSupport.convolutionExistsLeft (lsmul ℝ ℝ : ℝ →L[ℝ] ℝ →L[ℝ] ℝ) F_comp C B x).integrable · set z := (D / (1 + D)) • x with hz have B : 0 < 1 + D := by linarith have C : ball z (D * (1 + D - ‖x‖) / (1 + D)) ⊆ support fun y : E => w D y * φ (x - y) := by intro y hy simp only [support_mul, w_support E Dpos] simp only [φ, mem_inter_iff, mem_support, Ne, indicator_apply_eq_zero, mem_closedBall_zero_iff, one_ne_zero, not_forall, not_false_iff, exists_prop, and_true_iff] constructor · apply ball_subset_ball' _ hy simp only [hz, norm_smul, abs_of_nonneg Dpos.le, abs_of_nonneg B.le, dist_zero_right, Real.norm_eq_abs, abs_div] simp only [div_le_iff B, field_simps] ring_nf rfl · have ID : ‖D / (1 + D) - 1‖ = 1 / (1 + D) := by rw [Real.norm_of_nonpos] · simp only [B.ne', Ne, not_false_iff, mul_one, neg_sub, add_tsub_cancel_right, field_simps] · simp only [B.ne', Ne, not_false_iff, mul_one, field_simps] apply div_nonpos_of_nonpos_of_nonneg _ B.le linarith only rw [← mem_closedBall_iff_norm'] apply closedBall_subset_closedBall' _ (ball_subset_closedBall hy) rw [← one_smul ℝ x, dist_eq_norm, hz, ← sub_smul, one_smul, norm_smul, ID] simp only [B.ne', div_le_iff B, field_simps] nlinarith only [hx, D_lt_one] apply lt_of_lt_of_le _ (measure_mono C) apply measure_ball_pos exact div_pos (mul_pos Dpos (by linarith only [hx])) B variable (E) theorem y_smooth : ContDiffOn ℝ ⊀ (uncurry y) (Ioo (0 : ℝ) 1 ×ˢ (univ : Set E)) := by have hs : IsOpen (Ioo (0 : ℝ) (1 : ℝ)) := isOpen_Ioo have hk : IsCompact (closedBall (0 : E) 1) := ProperSpace.isCompact_closedBall _ _ refine contDiffOn_convolution_left_with_param (lsmul ℝ ℝ) hs hk ?_ ?_ ?_ · rintro p x hp hx simp only [w, mul_inv_rev, Algebra.id.smul_eq_mul, mul_eq_zero, inv_eq_zero] right contrapose! hx have : p⁻¹ • x ∈ support u := mem_support.2 hx simp only [u_support, norm_smul, mem_ball_zero_iff, Real.norm_eq_abs, abs_inv, abs_of_nonneg hp.1.le, ← div_eq_inv_mul, div_lt_one hp.1] at this rw [mem_closedBall_zero_iff] exact this.le.trans hp.2.le · exact (locallyIntegrable_const _).indicator measurableSet_closedBall · apply ContDiffOn.mul · norm_cast refine (contDiffOn_const.mul ?_).inv fun x hx => ne_of_gt (mul_pos (u_int_pos E) (pow_pos (abs_pos_of_pos hx.1.1) (finrank ℝ E))) apply ContDiffOn.pow simp_rw [← Real.norm_eq_abs] apply ContDiffOn.norm ℝ · exact contDiffOn_fst · intro x hx; exact ne_of_gt hx.1.1 · apply (u_smooth E).comp_contDiffOn exact ContDiffOn.smul (contDiffOn_fst.inv fun x hx => ne_of_gt hx.1.1) contDiffOn_snd theorem y_support {D : ℝ} (Dpos : 0 < D) (D_lt_one : D < 1) : support (y D : E → ℝ) = ball (0 : E) (1 + D) := support_eq_iff.2 ⟹fun _ hx => (y_pos_of_mem_ball Dpos D_lt_one hx).ne', fun _ hx => y_eq_zero_of_not_mem_ball Dpos hx⟩ variable {E} end HelperDefinitions instance (priority := 100) {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] : HasContDiffBump E := by refine ⟹⟹?_⟩⟩ borelize E have IR : ∀ R : ℝ, 1 < R → 0 < (R - 1) / (R + 1) := by intro R hR; apply div_pos <;> linarith exact { toFun := fun R x => if 1 < R then y ((R - 1) / (R + 1)) (((R + 1) / 2)⁻¹ • x) else 0 mem_Icc := fun R x => by simp only [mem_Icc] split_ifs with h · refine ⟹y_nonneg _ _, y_le_one _ (IR R h)⟩ · simp only [le_refl, zero_le_one, and_self] symmetric := fun R x => by simp only split_ifs · simp only [y_neg, smul_neg] · rfl smooth := by suffices ContDiffOn ℝ ⊀ (uncurry y ∘ fun p : ℝ × E => ((p.1 - 1) / (p.1 + 1), ((p.1 + 1) / 2)⁻¹ • p.2)) (Ioi 1 ×ˢ univ) by apply this.congr rintro ⟹R, x⟩ ⟹hR : 1 < R, _⟩ simp only [hR, uncurry_apply_pair, if_true, Function.comp_apply] apply (y_smooth E).comp · apply ContDiffOn.prod · refine (contDiffOn_fst.sub contDiffOn_const).div (contDiffOn_fst.add contDiffOn_const) ?_ rintro ⟹R, x⟩ ⟹hR : 1 < R, _⟩ apply ne_of_gt dsimp only linarith · apply ContDiffOn.smul _ contDiffOn_snd refine ((contDiffOn_fst.add contDiffOn_const).div_const _).inv ?_ rintro ⟹R, x⟩ ⟹hR : 1 < R, _⟩ apply ne_of_gt dsimp only linarith · rintro ⟹R, x⟩ ⟹hR : 1 < R, _⟩ have A : 0 < (R - 1) / (R + 1) := by apply div_pos <;> linarith have B : (R - 1) / (R + 1) < 1 := by apply (div_lt_one _).2 <;> linarith simp only [mem_preimage, prod_mk_mem_set_prod_eq, mem_Ioo, mem_univ, and_true_iff, A, B] eq_one := fun R hR x hx => by have A : 0 < R + 1 := by linarith simp only [hR, if_true] apply y_eq_one_of_mem_closedBall (IR R hR) simp only [norm_smul, inv_div, mem_closedBall_zero_iff, Real.norm_eq_abs, abs_div, abs_two, abs_of_nonneg A.le] calc 2 / (R + 1) * ‖x‖ ≀ 2 / (R + 1) := mul_le_of_le_one_right (by positivity) hx _ = 1 - (R - 1) / (R + 1) := by field_simp; ring support := fun R hR => by have A : 0 < (R + 1) / 2 := by linarith have C : (R - 1) / (R + 1) < 1 := by apply (div_lt_one _).2 <;> linarith simp only [hR, if_true, support_comp_inv_smul₀ A.ne', y_support _ (IR R hR) C, _root_.smul_ball A.ne', Real.norm_of_nonneg A.le, smul_zero] refine congr (congr_arg ball (Eq.refl 0)) ?_ field_simp; ring } end ExistsContDiffBumpBase end
Analysis\Calculus\BumpFunction\InnerProduct.lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.BumpFunction.Basic import Mathlib.Analysis.InnerProductSpace.Calculus import Mathlib.Analysis.SpecialFunctions.SmoothTransition /-! # Smooth bump functions in inner product spaces In this file we prove that a real inner product space has smooth bump functions, see `hasContDiffBump_of_innerProductSpace`. ## Keywords smooth function, bump function, inner product space -/ open Function Real open scoped Topology variable (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] -- Porting note: this definition was hidden inside the next instance. /-- A base bump function in an inner product space. This construction works in any space with a norm smooth away from zero but we do not have a typeclass for this. -/ noncomputable def ContDiffBumpBase.ofInnerProductSpace : ContDiffBumpBase E where toFun R x := smoothTransition ((R - ‖x‖) / (R - 1)) mem_Icc _ _ := ⟹smoothTransition.nonneg _, smoothTransition.le_one _⟩ symmetric _ _ := by simp only [norm_neg] smooth := by rintro ⟹R, x⟩ ⟹hR : 1 < R, -⟩ apply ContDiffAt.contDiffWithinAt rw [← sub_pos] at hR rcases eq_or_ne x 0 with rfl | hx · have A : ContinuousAt (fun p : ℝ × E ↩ (p.1 - ‖p.2‖) / (p.1 - 1)) (R, 0) := (continuousAt_fst.sub continuousAt_snd.norm).div (continuousAt_fst.sub continuousAt_const) hR.ne' have B : ∀ᶠ p in 𝓝 (R, (0 : E)), 1 ≀ (p.1 - ‖p.2‖) / (p.1 - 1) := A.eventually <| le_mem_nhds <| (one_lt_div hR).2 <| sub_lt_sub_left (by simp) _ refine (contDiffAt_const (c := 1)).congr_of_eventuallyEq <| B.mono fun _ ↩ smoothTransition.one_of_one_le · refine smoothTransition.contDiffAt.comp _ (ContDiffAt.div ?_ ?_ hR.ne') · exact contDiffAt_fst.sub (contDiffAt_snd.norm ℝ hx) · exact contDiffAt_fst.sub contDiffAt_const eq_one R hR x hx := smoothTransition.one_of_one_le <| (one_le_div <| sub_pos.2 hR).2 <| sub_le_sub_left hx _ support R hR := by ext x rw [mem_support, Ne, smoothTransition.zero_iff_nonpos, not_le, mem_ball_zero_iff] simp [div_pos_iff, sq_lt_sq, abs_of_pos (one_pos.trans hR), hR, hR.not_lt] /-- Any inner product space has smooth bump functions. -/ instance (priority := 100) hasContDiffBump_of_innerProductSpace : HasContDiffBump E := ⟹⟹.ofInnerProductSpace E⟩⟩
Analysis\Calculus\BumpFunction\Normed.lean
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Analysis.Calculus.BumpFunction.Basic import Mathlib.MeasureTheory.Integral.SetIntegral import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar /-! # Normed bump function In this file we define `ContDiffBump.normed f ÎŒ` to be the bump function `f` normalized so that `∫ x, f.normed ÎŒ x ∂Ό = 1` and prove some properties of this function. -/ noncomputable section open Function Filter Set Metric MeasureTheory FiniteDimensional Measure open scoped Topology namespace ContDiffBump variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [HasContDiffBump E] [MeasurableSpace E] {c : E} (f : ContDiffBump c) {x : E} {n : ℕ∞} {ÎŒ : Measure E} /-- A bump function normed so that `∫ x, f.normed ÎŒ x ∂Ό = 1`. -/ protected def normed (ÎŒ : Measure E) : E → ℝ := fun x => f x / ∫ x, f x ∂Ό theorem normed_def {ÎŒ : Measure E} (x : E) : f.normed ÎŒ x = f x / ∫ x, f x ∂Ό := rfl theorem nonneg_normed (x : E) : 0 ≀ f.normed ÎŒ x := div_nonneg f.nonneg <| integral_nonneg f.nonneg' theorem contDiff_normed {n : ℕ∞} : ContDiff ℝ n (f.normed ÎŒ) := f.contDiff.div_const _ theorem continuous_normed : Continuous (f.normed ÎŒ) := f.continuous.div_const _ theorem normed_sub (x : E) : f.normed ÎŒ (c - x) = f.normed ÎŒ (c + x) := by simp_rw [f.normed_def, f.sub] theorem normed_neg (f : ContDiffBump (0 : E)) (x : E) : f.normed ÎŒ (-x) = f.normed ÎŒ x := by simp_rw [f.normed_def, f.neg] variable [BorelSpace E] [FiniteDimensional ℝ E] [IsLocallyFiniteMeasure ÎŒ] protected theorem integrable : Integrable f ÎŒ := f.continuous.integrable_of_hasCompactSupport f.hasCompactSupport protected theorem integrable_normed : Integrable (f.normed ÎŒ) ÎŒ := f.integrable.div_const _ variable [ÎŒ.IsOpenPosMeasure] theorem integral_pos : 0 < ∫ x, f x ∂Ό := by refine (integral_pos_iff_support_of_nonneg f.nonneg' f.integrable).mpr ?_ rw [f.support_eq] exact measure_ball_pos ÎŒ c f.rOut_pos theorem integral_normed : ∫ x, f.normed ÎŒ x ∂Ό = 1 := by simp_rw [ContDiffBump.normed, div_eq_mul_inv, mul_comm (f _), ← smul_eq_mul, integral_smul] exact inv_mul_cancel f.integral_pos.ne' theorem support_normed_eq : Function.support (f.normed ÎŒ) = Metric.ball c f.rOut := by unfold ContDiffBump.normed rw [support_div, f.support_eq, support_const f.integral_pos.ne', inter_univ] theorem tsupport_normed_eq : tsupport (f.normed ÎŒ) = Metric.closedBall c f.rOut := by rw [tsupport, f.support_normed_eq, closure_ball _ f.rOut_pos.ne'] theorem hasCompactSupport_normed : HasCompactSupport (f.normed ÎŒ) := by simp only [HasCompactSupport, f.tsupport_normed_eq (ÎŒ := ÎŒ), isCompact_closedBall] theorem tendsto_support_normed_smallSets {ι} {φ : ι → ContDiffBump c} {l : Filter ι} (hφ : Tendsto (fun i => (φ i).rOut) l (𝓝 0)) : Tendsto (fun i => Function.support fun x => (φ i).normed ÎŒ x) l (𝓝 c).smallSets := by simp_rw [NormedAddCommGroup.tendsto_nhds_zero, Real.norm_eq_abs, abs_eq_self.mpr (φ _).rOut_pos.le] at hφ rw [nhds_basis_ball.smallSets.tendsto_right_iff] refine fun ε hε ↩ (hφ ε hε).mono fun i hi ↩ ?_ rw [(φ i).support_normed_eq] exact ball_subset_ball hi.le variable (ÎŒ) theorem integral_normed_smul {X} [NormedAddCommGroup X] [NormedSpace ℝ X] [CompleteSpace X] (z : X) : ∫ x, f.normed ÎŒ x • z ∂Ό = z := by simp_rw [integral_smul_const, f.integral_normed (ÎŒ := ÎŒ), one_smul] theorem measure_closedBall_le_integral : (ÎŒ (closedBall c f.rIn)).toReal ≀ ∫ x, f x ∂Ό := by calc (ÎŒ (closedBall c f.rIn)).toReal = ∫ x in closedBall c f.rIn, 1 ∂Ό := by simp _ = ∫ x in closedBall c f.rIn, f x ∂Ό := setIntegral_congr measurableSet_closedBall (fun x hx ↩ (one_of_mem_closedBall f hx).symm) _ ≀ ∫ x, f x ∂Ό := setIntegral_le_integral f.integrable (eventually_of_forall (fun x ↩ f.nonneg)) theorem normed_le_div_measure_closedBall_rIn (x : E) : f.normed ÎŒ x ≀ 1 / (ÎŒ (closedBall c f.rIn)).toReal := by rw [normed_def] gcongr · exact ENNReal.toReal_pos (measure_closedBall_pos _ _ f.rIn_pos).ne' measure_closedBall_lt_top.ne · exact f.le_one · exact f.measure_closedBall_le_integral ÎŒ theorem integral_le_measure_closedBall : ∫ x, f x ∂Ό ≀ (ÎŒ (closedBall c f.rOut)).toReal := by calc ∫ x, f x ∂Ό = ∫ x in closedBall c f.rOut, f x ∂Ό := by apply (setIntegral_eq_integral_of_forall_compl_eq_zero (fun x hx ↩ ?_)).symm apply f.zero_of_le_dist (le_of_lt _) simpa using hx _ ≀ ∫ x in closedBall c f.rOut, 1 ∂Ό := by apply setIntegral_mono f.integrable.integrableOn _ (fun x ↩ f.le_one) simp [measure_closedBall_lt_top] _ = (ÎŒ (closedBall c f.rOut)).toReal := by simp theorem measure_closedBall_div_le_integral [IsAddHaarMeasure ÎŒ] (K : ℝ) (h : f.rOut ≀ K * f.rIn) : (ÎŒ (closedBall c f.rOut)).toReal / K ^ finrank ℝ E ≀ ∫ x, f x ∂Ό := by have K_pos : 0 < K := by simpa [f.rIn_pos, not_lt.2 f.rIn_pos.le] using mul_pos_iff.1 (f.rOut_pos.trans_le h) apply le_trans _ (f.measure_closedBall_le_integral ÎŒ) rw [div_le_iff (pow_pos K_pos _), addHaar_closedBall' _ _ f.rIn_pos.le, addHaar_closedBall' _ _ f.rOut_pos.le, ENNReal.toReal_mul, ENNReal.toReal_mul, ENNReal.toReal_ofReal (pow_nonneg f.rOut_pos.le _), ENNReal.toReal_ofReal (pow_nonneg f.rIn_pos.le _), mul_assoc, mul_comm _ (K ^ _), ← mul_assoc, ← mul_pow, mul_comm _ K] gcongr exact f.rOut_pos.le theorem normed_le_div_measure_closedBall_rOut [IsAddHaarMeasure ÎŒ] (K : ℝ) (h : f.rOut ≀ K * f.rIn) (x : E) : f.normed ÎŒ x ≀ K ^ finrank ℝ E / (ÎŒ (closedBall c f.rOut)).toReal := by have K_pos : 0 < K := by simpa [f.rIn_pos, not_lt.2 f.rIn_pos.le] using mul_pos_iff.1 (f.rOut_pos.trans_le h) have : f x / ∫ y, f y ∂Ό ≀ 1 / ∫ y, f y ∂Ό := by gcongr · exact f.integral_pos.le · exact f.le_one apply this.trans rw [div_le_div_iff f.integral_pos, one_mul, ← div_le_iff' (pow_pos K_pos _)] · exact f.measure_closedBall_div_le_integral ÎŒ K h · exact ENNReal.toReal_pos (measure_closedBall_pos _ _ f.rOut_pos).ne' measure_closedBall_lt_top.ne end ContDiffBump
Analysis\Calculus\Conformal\InnerProduct.lean
/- Copyright (c) 2021 Yourong Zang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yourong Zang -/ import Mathlib.Analysis.Calculus.Conformal.NormedSpace import Mathlib.Analysis.InnerProductSpace.ConformalLinearMap /-! # Conformal maps between inner product spaces A function between inner product spaces which has a derivative at `x` is conformal at `x` iff the derivative preserves inner products up to a scalar multiple. -/ noncomputable section variable {E F : Type*} variable [NormedAddCommGroup E] [NormedAddCommGroup F] variable [InnerProductSpace ℝ E] [InnerProductSpace ℝ F] open RealInnerProductSpace /-- A real differentiable map `f` is conformal at point `x` if and only if its differential `fderiv ℝ f x` at that point scales every inner product by a positive scalar. -/ theorem conformalAt_iff' {f : E → F} {x : E} : ConformalAt f x ↔ ∃ c : ℝ, 0 < c ∧ ∀ u v : E, ⟪fderiv ℝ f x u, fderiv ℝ f x v⟫ = c * ⟪u, v⟫ := by rw [conformalAt_iff_isConformalMap_fderiv, isConformalMap_iff] /-- A real differentiable map `f` is conformal at point `x` if and only if its differential `f'` at that point scales every inner product by a positive scalar. -/ theorem conformalAt_iff {f : E → F} {x : E} {f' : E →L[ℝ] F} (h : HasFDerivAt f f' x) : ConformalAt f x ↔ ∃ c : ℝ, 0 < c ∧ ∀ u v : E, ⟪f' u, f' v⟫ = c * ⟪u, v⟫ := by simp only [conformalAt_iff', h.fderiv] /-- The conformal factor of a conformal map at some point `x`. Some authors refer to this function as the characteristic function of the conformal map. -/ def conformalFactorAt {f : E → F} {x : E} (h : ConformalAt f x) : ℝ := Classical.choose (conformalAt_iff'.mp h) theorem conformalFactorAt_pos {f : E → F} {x : E} (h : ConformalAt f x) : 0 < conformalFactorAt h := (Classical.choose_spec <| conformalAt_iff'.mp h).1 theorem conformalFactorAt_inner_eq_mul_inner' {f : E → F} {x : E} (h : ConformalAt f x) (u v : E) : ⟪(fderiv ℝ f x) u, (fderiv ℝ f x) v⟫ = (conformalFactorAt h : ℝ) * ⟪u, v⟫ := (Classical.choose_spec <| conformalAt_iff'.mp h).2 u v theorem conformalFactorAt_inner_eq_mul_inner {f : E → F} {x : E} {f' : E →L[ℝ] F} (h : HasFDerivAt f f' x) (H : ConformalAt f x) (u v : E) : ⟪f' u, f' v⟫ = (conformalFactorAt H : ℝ) * ⟪u, v⟫ := H.differentiableAt.hasFDerivAt.unique h ▾ conformalFactorAt_inner_eq_mul_inner' H u v
Analysis\Calculus\Conformal\NormedSpace.lean
/- Copyright (c) 2021 Yourong Zang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yourong Zang -/ import Mathlib.Analysis.NormedSpace.ConformalLinearMap import Mathlib.Analysis.Calculus.FDeriv.Add /-! # Conformal Maps A continuous linear map between real normed spaces `X` and `Y` is `ConformalAt` some point `x` if it is real differentiable at that point and its differential is a conformal linear map. ## Main definitions * `ConformalAt`: the main definition of conformal maps * `Conformal`: maps that are conformal at every point ## Main results * The conformality of the composition of two conformal maps, the identity map and multiplications by nonzero constants * `conformalAt_iff_isConformalMap_fderiv`: an equivalent definition of the conformality of a map In `Analysis.Calculus.Conformal.InnerProduct`: * `conformalAt_iff`: an equivalent definition of the conformality of a map In `Geometry.Euclidean.Angle.Unoriented.Conformal`: * `ConformalAt.preserves_angle`: if a map is conformal at `x`, then its differential preserves all angles at `x` ## Tags conformal ## Warning The definition of conformality in this file does NOT require the maps to be orientation-preserving. Maps such as the complex conjugate are considered to be conformal. -/ noncomputable section variable {X Y Z : Type*} [NormedAddCommGroup X] [NormedAddCommGroup Y] [NormedAddCommGroup Z] [NormedSpace ℝ X] [NormedSpace ℝ Y] [NormedSpace ℝ Z] section LocConformality open LinearIsometry ContinuousLinearMap /-- A map `f` is said to be conformal if it has a conformal differential `f'`. -/ def ConformalAt (f : X → Y) (x : X) := ∃ f' : X →L[ℝ] Y, HasFDerivAt f f' x ∧ IsConformalMap f' theorem conformalAt_id (x : X) : ConformalAt _root_.id x := ⟹id ℝ X, hasFDerivAt_id _, isConformalMap_id⟩ theorem conformalAt_const_smul {c : ℝ} (h : c ≠ 0) (x : X) : ConformalAt (fun x' : X => c • x') x := ⟹c • ContinuousLinearMap.id ℝ X, (hasFDerivAt_id x).const_smul c, isConformalMap_const_smul h⟩ @[nontriviality] theorem Subsingleton.conformalAt [Subsingleton X] (f : X → Y) (x : X) : ConformalAt f x := ⟹0, hasFDerivAt_of_subsingleton _ _, isConformalMap_of_subsingleton _⟩ /-- A function is a conformal map if and only if its differential is a conformal linear map-/ theorem conformalAt_iff_isConformalMap_fderiv {f : X → Y} {x : X} : ConformalAt f x ↔ IsConformalMap (fderiv ℝ f x) := by constructor · rintro ⟹f', hf, hf'⟩ rwa [hf.fderiv] · intro H by_cases h : DifferentiableAt ℝ f x · exact ⟹fderiv ℝ f x, h.hasFDerivAt, H⟩ · nontriviality X exact absurd (fderiv_zero_of_not_differentiableAt h) H.ne_zero namespace ConformalAt theorem differentiableAt {f : X → Y} {x : X} (h : ConformalAt f x) : DifferentiableAt ℝ f x := let ⟹_, h₁, _⟩ := h h₁.differentiableAt theorem congr {f g : X → Y} {x : X} {u : Set X} (hx : x ∈ u) (hu : IsOpen u) (hf : ConformalAt f x) (h : ∀ x : X, x ∈ u → g x = f x) : ConformalAt g x := let ⟹f', hfderiv, hf'⟩ := hf ⟹f', hfderiv.congr_of_eventuallyEq ((hu.eventually_mem hx).mono h), hf'⟩ theorem comp {f : X → Y} {g : Y → Z} (x : X) (hg : ConformalAt g (f x)) (hf : ConformalAt f x) : ConformalAt (g ∘ f) x := by rcases hf with ⟹f', hf₁, cf⟩ rcases hg with ⟹g', hg₁, cg⟩ exact ⟹g'.comp f', hg₁.comp x hf₁, cg.comp cf⟩ theorem const_smul {f : X → Y} {x : X} {c : ℝ} (hc : c ≠ 0) (hf : ConformalAt f x) : ConformalAt (c • f) x := (conformalAt_const_smul hc <| f x).comp x hf end ConformalAt end LocConformality section GlobalConformality /-- A map `f` is conformal if it's conformal at every point. -/ def Conformal (f : X → Y) := ∀ x : X, ConformalAt f x theorem conformal_id : Conformal (id : X → X) := fun x => conformalAt_id x theorem conformal_const_smul {c : ℝ} (h : c ≠ 0) : Conformal fun x : X => c • x := fun x => conformalAt_const_smul h x namespace Conformal theorem conformalAt {f : X → Y} (h : Conformal f) (x : X) : ConformalAt f x := h x theorem differentiable {f : X → Y} (h : Conformal f) : Differentiable ℝ f := fun x => (h x).differentiableAt theorem comp {f : X → Y} {g : Y → Z} (hf : Conformal f) (hg : Conformal g) : Conformal (g ∘ f) := fun x => (hg <| f x).comp x (hf x) theorem const_smul {f : X → Y} (hf : Conformal f) {c : ℝ} (hc : c ≠ 0) : Conformal (c • f) := fun x => (hf x).const_smul hc end Conformal end GlobalConformality
Analysis\Calculus\ContDiff\Basic.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Analysis.Calculus.ContDiff.Defs import Mathlib.Analysis.Calculus.FDeriv.Add import Mathlib.Analysis.Calculus.FDeriv.Mul import Mathlib.Analysis.Calculus.Deriv.Inverse /-! # Higher differentiability of usual operations We prove that the usual operations (addition, multiplication, difference, composition, and so on) preserve `C^n` functions. We also expand the API around `C^n` functions. ## Main results * `ContDiff.comp` states that the composition of two `C^n` functions is `C^n`. Similar results are given for `C^n` functions on domains. ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `⊀ : ℕ∞` with `∞`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open scoped NNReal Nat local notation "∞" => (⊀ : ℕ∞) universe u v w uD uE uF uG attribute [local instance 1001] NormedAddCommGroup.toAddCommGroup NormedSpace.toModule' AddCommGroup.toAddCommMonoid open Set Fin Filter Function open scoped Topology variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {D : Type uD} [NormedAddCommGroup D] [NormedSpace 𝕜 D] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type*} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {b : E × F → G} {m n : ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Constants -/ @[simp] theorem iteratedFDerivWithin_zero_fun (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} : iteratedFDerivWithin 𝕜 i (fun _ : E ↩ (0 : F)) s x = 0 := by induction i generalizing x with | zero => ext; simp | succ i IH => ext m rw [iteratedFDerivWithin_succ_apply_left, fderivWithin_congr (fun _ ↩ IH) (IH hx)] rw [fderivWithin_const_apply _ (hs x hx)] rfl @[simp] theorem iteratedFDeriv_zero_fun {n : ℕ} : (iteratedFDeriv 𝕜 n fun _ : E ↩ (0 : F)) = 0 := funext fun x ↩ by simpa [← iteratedFDerivWithin_univ] using iteratedFDerivWithin_zero_fun uniqueDiffOn_univ (mem_univ x) theorem contDiff_zero_fun : ContDiff 𝕜 n fun _ : E => (0 : F) := contDiff_of_differentiable_iteratedFDeriv fun m _ => by rw [iteratedFDeriv_zero_fun] exact differentiable_const (0 : E[×m]→L[𝕜] F) /-- Constants are `C^∞`. -/ theorem contDiff_const {c : F} : ContDiff 𝕜 n fun _ : E => c := by suffices h : ContDiff 𝕜 ∞ fun _ : E => c from h.of_le le_top rw [contDiff_top_iff_fderiv] refine ⟹differentiable_const c, ?_⟩ rw [fderiv_const] exact contDiff_zero_fun theorem contDiffOn_const {c : F} {s : Set E} : ContDiffOn 𝕜 n (fun _ : E => c) s := contDiff_const.contDiffOn theorem contDiffAt_const {c : F} : ContDiffAt 𝕜 n (fun _ : E => c) x := contDiff_const.contDiffAt theorem contDiffWithinAt_const {c : F} : ContDiffWithinAt 𝕜 n (fun _ : E => c) s x := contDiffAt_const.contDiffWithinAt @[nontriviality] theorem contDiff_of_subsingleton [Subsingleton F] : ContDiff 𝕜 n f := by rw [Subsingleton.elim f fun _ => 0]; exact contDiff_const @[nontriviality] theorem contDiffAt_of_subsingleton [Subsingleton F] : ContDiffAt 𝕜 n f x := by rw [Subsingleton.elim f fun _ => 0]; exact contDiffAt_const @[nontriviality] theorem contDiffWithinAt_of_subsingleton [Subsingleton F] : ContDiffWithinAt 𝕜 n f s x := by rw [Subsingleton.elim f fun _ => 0]; exact contDiffWithinAt_const @[nontriviality] theorem contDiffOn_of_subsingleton [Subsingleton F] : ContDiffOn 𝕜 n f s := by rw [Subsingleton.elim f fun _ => 0]; exact contDiffOn_const theorem iteratedFDerivWithin_succ_const (n : ℕ) (c : F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 (n + 1) (fun _ : E ↩ c) s x = 0 := by ext m rw [iteratedFDerivWithin_succ_apply_right hs hx] rw [iteratedFDerivWithin_congr (fun y hy ↩ fderivWithin_const_apply c (hs y hy)) hx] rw [iteratedFDerivWithin_zero_fun hs hx] simp [ContinuousMultilinearMap.zero_apply (R := 𝕜)] theorem iteratedFDeriv_succ_const (n : ℕ) (c : F) : (iteratedFDeriv 𝕜 (n + 1) fun _ : E ↩ c) = 0 := funext fun x ↩ by simpa [← iteratedFDerivWithin_univ] using iteratedFDerivWithin_succ_const n c uniqueDiffOn_univ (mem_univ x) theorem iteratedFDerivWithin_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 n (fun _ : E ↩ c) s x = 0 := by cases n with | zero => contradiction | succ n => exact iteratedFDerivWithin_succ_const n c hs hx theorem iteratedFDeriv_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) : (iteratedFDeriv 𝕜 n fun _ : E ↩ c) = 0 := funext fun x ↩ by simpa [← iteratedFDerivWithin_univ] using iteratedFDerivWithin_const_of_ne hn c uniqueDiffOn_univ (mem_univ x) /-! ### Smoothness of linear functions -/ /-- Unbundled bounded linear functions are `C^∞`. -/ theorem IsBoundedLinearMap.contDiff (hf : IsBoundedLinearMap 𝕜 f) : ContDiff 𝕜 n f := by suffices h : ContDiff 𝕜 ∞ f from h.of_le le_top rw [contDiff_top_iff_fderiv] refine ⟹hf.differentiable, ?_⟩ simp_rw [hf.fderiv] exact contDiff_const theorem ContinuousLinearMap.contDiff (f : E →L[𝕜] F) : ContDiff 𝕜 n f := f.isBoundedLinearMap.contDiff theorem ContinuousLinearEquiv.contDiff (f : E ≃L[𝕜] F) : ContDiff 𝕜 n f := (f : E →L[𝕜] F).contDiff theorem LinearIsometry.contDiff (f : E →ₗᵢ[𝕜] F) : ContDiff 𝕜 n f := f.toContinuousLinearMap.contDiff theorem LinearIsometryEquiv.contDiff (f : E ≃ₗᵢ[𝕜] F) : ContDiff 𝕜 n f := (f : E →L[𝕜] F).contDiff /-- The identity is `C^∞`. -/ theorem contDiff_id : ContDiff 𝕜 n (id : E → E) := IsBoundedLinearMap.id.contDiff theorem contDiffWithinAt_id {s x} : ContDiffWithinAt 𝕜 n (id : E → E) s x := contDiff_id.contDiffWithinAt theorem contDiffAt_id {x} : ContDiffAt 𝕜 n (id : E → E) x := contDiff_id.contDiffAt theorem contDiffOn_id {s} : ContDiffOn 𝕜 n (id : E → E) s := contDiff_id.contDiffOn /-- Bilinear functions are `C^∞`. -/ theorem IsBoundedBilinearMap.contDiff (hb : IsBoundedBilinearMap 𝕜 b) : ContDiff 𝕜 n b := by suffices h : ContDiff 𝕜 ∞ b from h.of_le le_top rw [contDiff_top_iff_fderiv] refine ⟹hb.differentiable, ?_⟩ simp only [hb.fderiv] exact hb.isBoundedLinearMap_deriv.contDiff /-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `g ∘ f` admits a Taylor series whose `k`-th term is given by `g ∘ (p k)`. -/ theorem HasFTaylorSeriesUpToOn.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : HasFTaylorSeriesUpToOn n f p s) : HasFTaylorSeriesUpToOn n (g ∘ f) (fun x k => g.compContinuousMultilinearMap (p x k)) s where zero_eq x hx := congr_arg g (hf.zero_eq x hx) fderivWithin m hm x hx := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜 (fun _ : Fin m => E) F G g).hasFDerivAt.comp_hasFDerivWithinAt x (hf.fderivWithin m hm x hx) cont m hm := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜 (fun _ : Fin m => E) F G g).continuous.comp_continuousOn (hf.cont m hm) /-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain at a point. -/ theorem ContDiffWithinAt.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := fun m hm ↩ by rcases hf m hm with ⟹u, hu, p, hp⟩ exact ⟹u, hu, _, hp.continuousLinearMap_comp g⟩ /-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain at a point. -/ theorem ContDiffAt.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (g ∘ f) x := ContDiffWithinAt.continuousLinearMap_comp g hf /-- Composition by continuous linear maps on the left preserves `C^n` functions on domains. -/ theorem ContDiffOn.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) s := fun x hx => (hf x hx).continuousLinearMap_comp g /-- Composition by continuous linear maps on the left preserves `C^n` functions. -/ theorem ContDiff.continuousLinearMap_comp {f : E → F} (g : F →L[𝕜] G) (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => g (f x) := contDiffOn_univ.1 <| ContDiffOn.continuousLinearMap_comp _ (contDiffOn_univ.2 hf) /-- The iterated derivative within a set of the composition with a linear map on the left is obtained by applying the linear map to the iterated derivative. -/ theorem ContinuousLinearMap.iteratedFDerivWithin_comp_left {f : E → F} (g : F →L[𝕜] G) (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : (i : ℕ∞) ≀ n) : iteratedFDerivWithin 𝕜 i (g ∘ f) s x = g.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := (((hf.ftaylorSeriesWithin hs).continuousLinearMap_comp g).eq_iteratedFDerivWithin_of_uniqueDiffOn hi hs hx).symm /-- The iterated derivative of the composition with a linear map on the left is obtained by applying the linear map to the iterated derivative. -/ theorem ContinuousLinearMap.iteratedFDeriv_comp_left {f : E → F} (g : F →L[𝕜] G) (hf : ContDiff 𝕜 n f) (x : E) {i : ℕ} (hi : (i : ℕ∞) ≀ n) : iteratedFDeriv 𝕜 i (g ∘ f) x = g.compContinuousMultilinearMap (iteratedFDeriv 𝕜 i f x) := by simp only [← iteratedFDerivWithin_univ] exact g.iteratedFDerivWithin_comp_left hf.contDiffOn uniqueDiffOn_univ (mem_univ x) hi /-- The iterated derivative within a set of the composition with a linear equiv on the left is obtained by applying the linear equiv to the iterated derivative. This is true without differentiability assumptions. -/ theorem ContinuousLinearEquiv.iteratedFDerivWithin_comp_left (g : F ≃L[𝕜] G) (f : E → F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (i : ℕ) : iteratedFDerivWithin 𝕜 i (g ∘ f) s x = (g : F →L[𝕜] G).compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := by induction' i with i IH generalizing x · ext1 m simp only [Nat.zero_eq, iteratedFDerivWithin_zero_apply, comp_apply, ContinuousLinearMap.compContinuousMultilinearMap_coe, coe_coe] · ext1 m rw [iteratedFDerivWithin_succ_apply_left] have Z : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (g ∘ f) s) s x = fderivWithin 𝕜 (g.compContinuousMultilinearMapL (fun _ : Fin i => E) ∘ iteratedFDerivWithin 𝕜 i f s) s x := fderivWithin_congr' (@IH) hx simp_rw [Z] rw [(g.compContinuousMultilinearMapL fun _ : Fin i => E).comp_fderivWithin (hs x hx)] simp only [ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, comp_apply, ContinuousLinearEquiv.compContinuousMultilinearMapL_apply, ContinuousLinearMap.compContinuousMultilinearMap_coe, EmbeddingLike.apply_eq_iff_eq] rw [iteratedFDerivWithin_succ_apply_left] /-- Composition with a linear isometry on the left preserves the norm of the iterated derivative within a set. -/ theorem LinearIsometry.norm_iteratedFDerivWithin_comp_left {f : E → F} (g : F →ₗᵢ[𝕜] G) (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : (i : ℕ∞) ≀ n) : ‖iteratedFDerivWithin 𝕜 i (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by have : iteratedFDerivWithin 𝕜 i (g ∘ f) s x = g.toContinuousLinearMap.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := g.toContinuousLinearMap.iteratedFDerivWithin_comp_left hf hs hx hi rw [this] apply LinearIsometry.norm_compContinuousMultilinearMap /-- Composition with a linear isometry on the left preserves the norm of the iterated derivative. -/ theorem LinearIsometry.norm_iteratedFDeriv_comp_left {f : E → F} (g : F →ₗᵢ[𝕜] G) (hf : ContDiff 𝕜 n f) (x : E) {i : ℕ} (hi : (i : ℕ∞) ≀ n) : ‖iteratedFDeriv 𝕜 i (g ∘ f) x‖ = ‖iteratedFDeriv 𝕜 i f x‖ := by simp only [← iteratedFDerivWithin_univ] exact g.norm_iteratedFDerivWithin_comp_left hf.contDiffOn uniqueDiffOn_univ (mem_univ x) hi /-- Composition with a linear isometry equiv on the left preserves the norm of the iterated derivative within a set. -/ theorem LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left (g : F ≃ₗᵢ[𝕜] G) (f : E → F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (i : ℕ) : ‖iteratedFDerivWithin 𝕜 i (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by have : iteratedFDerivWithin 𝕜 i (g ∘ f) s x = (g : F →L[𝕜] G).compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := g.toContinuousLinearEquiv.iteratedFDerivWithin_comp_left f hs hx i rw [this] apply LinearIsometry.norm_compContinuousMultilinearMap g.toLinearIsometry /-- Composition with a linear isometry equiv on the left preserves the norm of the iterated derivative. -/ theorem LinearIsometryEquiv.norm_iteratedFDeriv_comp_left (g : F ≃ₗᵢ[𝕜] G) (f : E → F) (x : E) (i : ℕ) : ‖iteratedFDeriv 𝕜 i (g ∘ f) x‖ = ‖iteratedFDeriv 𝕜 i f x‖ := by rw [← iteratedFDerivWithin_univ, ← iteratedFDerivWithin_univ] apply g.norm_iteratedFDerivWithin_comp_left f uniqueDiffOn_univ (mem_univ x) i /-- Composition by continuous linear equivs on the left respects higher differentiability at a point in a domain. -/ theorem ContinuousLinearEquiv.comp_contDiffWithinAt_iff (e : F ≃L[𝕜] G) : ContDiffWithinAt 𝕜 n (e ∘ f) s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟹fun H => by simpa only [(· ∘ ·), e.symm.coe_coe, e.symm_apply_apply] using H.continuousLinearMap_comp (e.symm : G →L[𝕜] F), fun H => H.continuousLinearMap_comp (e : F →L[𝕜] G)⟩ /-- Composition by continuous linear equivs on the left respects higher differentiability at a point. -/ theorem ContinuousLinearEquiv.comp_contDiffAt_iff (e : F ≃L[𝕜] G) : ContDiffAt 𝕜 n (e ∘ f) x ↔ ContDiffAt 𝕜 n f x := by simp only [← contDiffWithinAt_univ, e.comp_contDiffWithinAt_iff] /-- Composition by continuous linear equivs on the left respects higher differentiability on domains. -/ theorem ContinuousLinearEquiv.comp_contDiffOn_iff (e : F ≃L[𝕜] G) : ContDiffOn 𝕜 n (e ∘ f) s ↔ ContDiffOn 𝕜 n f s := by simp [ContDiffOn, e.comp_contDiffWithinAt_iff] /-- Composition by continuous linear equivs on the left respects higher differentiability. -/ theorem ContinuousLinearEquiv.comp_contDiff_iff (e : F ≃L[𝕜] G) : ContDiff 𝕜 n (e ∘ f) ↔ ContDiff 𝕜 n f := by simp only [← contDiffOn_univ, e.comp_contDiffOn_iff] /-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `f ∘ g` admits a Taylor series in `g ⁻¹' s`, whose `k`-th term is given by `p k (g v₁, ..., g vₖ)` . -/ theorem HasFTaylorSeriesUpToOn.compContinuousLinearMap (hf : HasFTaylorSeriesUpToOn n f p s) (g : G →L[𝕜] E) : HasFTaylorSeriesUpToOn n (f ∘ g) (fun x k => (p (g x) k).compContinuousLinearMap fun _ => g) (g ⁻¹' s) := by let A : ∀ m : ℕ, (E[×m]→L[𝕜] F) → G[×m]→L[𝕜] F := fun m h => h.compContinuousLinearMap fun _ => g have hA : ∀ m, IsBoundedLinearMap 𝕜 (A m) := fun m => isBoundedLinearMap_continuousMultilinearMap_comp_linear g constructor · intro x hx simp only [(hf.zero_eq (g x) hx).symm, Function.comp_apply] change (p (g x) 0 fun _ : Fin 0 => g 0) = p (g x) 0 0 rw [ContinuousLinearMap.map_zero] rfl · intro m hm x hx convert (hA m).hasFDerivAt.comp_hasFDerivWithinAt x ((hf.fderivWithin m hm (g x) hx).comp x g.hasFDerivWithinAt (Subset.refl _)) ext y v change p (g x) (Nat.succ m) (g ∘ cons y v) = p (g x) m.succ (cons (g y) (g ∘ v)) rw [comp_cons] · intro m hm exact (hA m).continuous.comp_continuousOn <| (hf.cont m hm).comp g.continuous.continuousOn <| Subset.refl _ /-- Composition by continuous linear maps on the right preserves `C^n` functions at a point on a domain. -/ theorem ContDiffWithinAt.comp_continuousLinearMap {x : G} (g : G →L[𝕜] E) (hf : ContDiffWithinAt 𝕜 n f s (g x)) : ContDiffWithinAt 𝕜 n (f ∘ g) (g ⁻¹' s) x := by intro m hm rcases hf m hm with ⟹u, hu, p, hp⟩ refine ⟹g ⁻¹' u, ?_, _, hp.compContinuousLinearMap g⟩ refine g.continuous.continuousWithinAt.tendsto_nhdsWithin ?_ hu exact (mapsTo_singleton.2 <| mem_singleton _).union_union (mapsTo_preimage _ _) /-- Composition by continuous linear maps on the right preserves `C^n` functions on domains. -/ theorem ContDiffOn.comp_continuousLinearMap (hf : ContDiffOn 𝕜 n f s) (g : G →L[𝕜] E) : ContDiffOn 𝕜 n (f ∘ g) (g ⁻¹' s) := fun x hx => (hf (g x) hx).comp_continuousLinearMap g /-- Composition by continuous linear maps on the right preserves `C^n` functions. -/ theorem ContDiff.comp_continuousLinearMap {f : E → F} {g : G →L[𝕜] E} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n (f ∘ g) := contDiffOn_univ.1 <| ContDiffOn.comp_continuousLinearMap (contDiffOn_univ.2 hf) _ /-- The iterated derivative within a set of the composition with a linear map on the right is obtained by composing the iterated derivative with the linear map. -/ theorem ContinuousLinearMap.iteratedFDerivWithin_comp_right {f : E → F} (g : G →L[𝕜] E) (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (h's : UniqueDiffOn 𝕜 (g ⁻¹' s)) {x : G} (hx : g x ∈ s) {i : ℕ} (hi : (i : ℕ∞) ≀ n) : iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x = (iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g := (((hf.ftaylorSeriesWithin hs).compContinuousLinearMap g).eq_iteratedFDerivWithin_of_uniqueDiffOn hi h's hx).symm /-- The iterated derivative within a set of the composition with a linear equiv on the right is obtained by composing the iterated derivative with the linear equiv. -/ theorem ContinuousLinearEquiv.iteratedFDerivWithin_comp_right (g : G ≃L[𝕜] E) (f : E → F) (hs : UniqueDiffOn 𝕜 s) {x : G} (hx : g x ∈ s) (i : ℕ) : iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x = (iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g := by induction' i with i IH generalizing x · ext1 simp only [Nat.zero_eq, iteratedFDerivWithin_zero_apply, comp_apply, ContinuousMultilinearMap.compContinuousLinearMap_apply] · ext1 m simp only [ContinuousMultilinearMap.compContinuousLinearMap_apply, ContinuousLinearEquiv.coe_coe, iteratedFDerivWithin_succ_apply_left] have : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s)) (g ⁻¹' s) x = fderivWithin 𝕜 (ContinuousMultilinearMap.compContinuousLinearMapEquivL _ (fun _x : Fin i => g) ∘ (iteratedFDerivWithin 𝕜 i f s ∘ g)) (g ⁻¹' s) x := fderivWithin_congr' (@IH) hx rw [this, ContinuousLinearEquiv.comp_fderivWithin _ (g.uniqueDiffOn_preimage_iff.2 hs x hx)] simp only [ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, comp_apply, ContinuousMultilinearMap.compContinuousLinearMapEquivL_apply, ContinuousMultilinearMap.compContinuousLinearMap_apply] rw [ContinuousLinearEquiv.comp_right_fderivWithin _ (g.uniqueDiffOn_preimage_iff.2 hs x hx), ContinuousLinearMap.coe_comp', coe_coe, comp_apply, tail_def, tail_def] /-- The iterated derivative of the composition with a linear map on the right is obtained by composing the iterated derivative with the linear map. -/ theorem ContinuousLinearMap.iteratedFDeriv_comp_right (g : G →L[𝕜] E) {f : E → F} (hf : ContDiff 𝕜 n f) (x : G) {i : ℕ} (hi : (i : ℕ∞) ≀ n) : iteratedFDeriv 𝕜 i (f ∘ g) x = (iteratedFDeriv 𝕜 i f (g x)).compContinuousLinearMap fun _ => g := by simp only [← iteratedFDerivWithin_univ] exact g.iteratedFDerivWithin_comp_right hf.contDiffOn uniqueDiffOn_univ uniqueDiffOn_univ (mem_univ _) hi /-- Composition with a linear isometry on the right preserves the norm of the iterated derivative within a set. -/ theorem LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right (g : G ≃ₗᵢ[𝕜] E) (f : E → F) (hs : UniqueDiffOn 𝕜 s) {x : G} (hx : g x ∈ s) (i : ℕ) : ‖iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x‖ = ‖iteratedFDerivWithin 𝕜 i f s (g x)‖ := by have : iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x = (iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g := g.toContinuousLinearEquiv.iteratedFDerivWithin_comp_right f hs hx i rw [this, ContinuousMultilinearMap.norm_compContinuous_linearIsometryEquiv] /-- Composition with a linear isometry on the right preserves the norm of the iterated derivative within a set. -/ theorem LinearIsometryEquiv.norm_iteratedFDeriv_comp_right (g : G ≃ₗᵢ[𝕜] E) (f : E → F) (x : G) (i : ℕ) : ‖iteratedFDeriv 𝕜 i (f ∘ g) x‖ = ‖iteratedFDeriv 𝕜 i f (g x)‖ := by simp only [← iteratedFDerivWithin_univ] apply g.norm_iteratedFDerivWithin_comp_right f uniqueDiffOn_univ (mem_univ (g x)) i /-- Composition by continuous linear equivs on the right respects higher differentiability at a point in a domain. -/ theorem ContinuousLinearEquiv.contDiffWithinAt_comp_iff (e : G ≃L[𝕜] E) : ContDiffWithinAt 𝕜 n (f ∘ e) (e ⁻¹' s) (e.symm x) ↔ ContDiffWithinAt 𝕜 n f s x := by constructor · intro H simpa [← preimage_comp, (· ∘ ·)] using H.comp_continuousLinearMap (e.symm : E →L[𝕜] G) · intro H rw [← e.apply_symm_apply x, ← e.coe_coe] at H exact H.comp_continuousLinearMap _ /-- Composition by continuous linear equivs on the right respects higher differentiability at a point. -/ theorem ContinuousLinearEquiv.contDiffAt_comp_iff (e : G ≃L[𝕜] E) : ContDiffAt 𝕜 n (f ∘ e) (e.symm x) ↔ ContDiffAt 𝕜 n f x := by rw [← contDiffWithinAt_univ, ← contDiffWithinAt_univ, ← preimage_univ] exact e.contDiffWithinAt_comp_iff /-- Composition by continuous linear equivs on the right respects higher differentiability on domains. -/ theorem ContinuousLinearEquiv.contDiffOn_comp_iff (e : G ≃L[𝕜] E) : ContDiffOn 𝕜 n (f ∘ e) (e ⁻¹' s) ↔ ContDiffOn 𝕜 n f s := ⟹fun H => by simpa [(· ∘ ·)] using H.comp_continuousLinearMap (e.symm : E →L[𝕜] G), fun H => H.comp_continuousLinearMap (e : G →L[𝕜] E)⟩ /-- Composition by continuous linear equivs on the right respects higher differentiability. -/ theorem ContinuousLinearEquiv.contDiff_comp_iff (e : G ≃L[𝕜] E) : ContDiff 𝕜 n (f ∘ e) ↔ ContDiff 𝕜 n f := by rw [← contDiffOn_univ, ← contDiffOn_univ, ← preimage_univ] exact e.contDiffOn_comp_iff /-- If two functions `f` and `g` admit Taylor series `p` and `q` in a set `s`, then the cartesian product of `f` and `g` admits the cartesian product of `p` and `q` as a Taylor series. -/ theorem HasFTaylorSeriesUpToOn.prod (hf : HasFTaylorSeriesUpToOn n f p s) {g : E → G} {q : E → FormalMultilinearSeries 𝕜 E G} (hg : HasFTaylorSeriesUpToOn n g q s) : HasFTaylorSeriesUpToOn n (fun y => (f y, g y)) (fun y k => (p y k).prod (q y k)) s := by set L := fun m => ContinuousMultilinearMap.prodL 𝕜 (fun _ : Fin m => E) F G constructor · intro x hx; rw [← hf.zero_eq x hx, ← hg.zero_eq x hx]; rfl · intro m hm x hx convert (L m).hasFDerivAt.comp_hasFDerivWithinAt x ((hf.fderivWithin m hm x hx).prod (hg.fderivWithin m hm x hx)) · intro m hm exact (L m).continuous.comp_continuousOn ((hf.cont m hm).prod (hg.cont m hm)) /-- The cartesian product of `C^n` functions at a point in a domain is `C^n`. -/ theorem ContDiffWithinAt.prod {s : Set E} {f : E → F} {g : E → G} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x : E => (f x, g x)) s x := by intro m hm rcases hf m hm with ⟹u, hu, p, hp⟩ rcases hg m hm with ⟹v, hv, q, hq⟩ exact ⟹u ∩ v, Filter.inter_mem hu hv, _, (hp.mono inter_subset_left).prod (hq.mono inter_subset_right)⟩ /-- The cartesian product of `C^n` functions on domains is `C^n`. -/ theorem ContDiffOn.prod {s : Set E} {f : E → F} {g : E → G} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x : E => (f x, g x)) s := fun x hx => (hf x hx).prod (hg x hx) /-- The cartesian product of `C^n` functions at a point is `C^n`. -/ theorem ContDiffAt.prod {f : E → F} {g : E → G} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x : E => (f x, g x)) x := contDiffWithinAt_univ.1 <| ContDiffWithinAt.prod (contDiffWithinAt_univ.2 hf) (contDiffWithinAt_univ.2 hg) /-- The cartesian product of `C^n` functions is `C^n`. -/ theorem ContDiff.prod {f : E → F} {g : E → G} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x : E => (f x, g x) := contDiffOn_univ.1 <| ContDiffOn.prod (contDiffOn_univ.2 hf) (contDiffOn_univ.2 hg) /-! ### Composition of `C^n` functions We show that the composition of `C^n` functions is `C^n`. One way to prove it would be to write the `n`-th derivative of the composition (this is Faà di Bruno's formula) and check its continuity, but this is very painful. Instead, we go for a simple inductive proof. Assume it is done for `n`. Then, to check it for `n+1`, one needs to check that the derivative of `g ∘ f` is `C^n`, i.e., that `Dg(f x) ⬝ Df(x)` is `C^n`. The term `Dg (f x)` is the composition of two `C^n` functions, so it is `C^n` by the inductive assumption. The term `Df(x)` is also `C^n`. Then, the matrix multiplication is the application of a bilinear map (which is `C^∞`, and therefore `C^n`) to `x ↩ (Dg(f x), Df x)`. As the composition of two `C^n` maps, it is again `C^n`, and we are done. There is a subtlety in this argument: we apply the inductive assumption to functions on other Banach spaces. In maths, one would say: prove by induction over `n` that, for all `C^n` maps between all pairs of Banach spaces, their composition is `C^n`. In Lean, this is fine as long as the spaces stay in the same universe. This is not the case in the above argument: if `E` lives in universe `u` and `F` lives in universe `v`, then linear maps from `E` to `F` (to which the derivative of `f` belongs) is in universe `max u v`. If one could quantify over finitely many universes, the above proof would work fine, but this is not the case. One could still write the proof considering spaces in any universe in `u, v, w, max u v, max v w, max u v w`, but it would be extremely tedious and lead to a lot of duplication. Instead, we formulate the above proof when all spaces live in the same universe (where everything is fine), and then we deduce the general result by lifting all our spaces to a common universe through `ULift`. This lifting is done through a continuous linear equiv. We have already proved that composing with such a linear equiv does not change the fact of being `C^n`, which concludes the proof. -/ /-- Auxiliary lemma proving that the composition of `C^n` functions on domains is `C^n` when all spaces live in the same universe. Use instead `ContDiffOn.comp` which removes the universe assumption (but is deduced from this one). -/ private theorem ContDiffOn.comp_same_univ {Eu : Type u} [NormedAddCommGroup Eu] [NormedSpace 𝕜 Eu] {Fu : Type u} [NormedAddCommGroup Fu] [NormedSpace 𝕜 Fu] {Gu : Type u} [NormedAddCommGroup Gu] [NormedSpace 𝕜 Gu] {s : Set Eu} {t : Set Fu} {g : Fu → Gu} {f : Eu → Fu} (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) : ContDiffOn 𝕜 n (g ∘ f) s := by induction' n using ENat.nat_induction with n IH Itop generalizing Eu Fu Gu · rw [contDiffOn_zero] at hf hg ⊢ exact ContinuousOn.comp hg hf st · rw [contDiffOn_succ_iff_hasFDerivWithinAt] at hg ⊢ intro x hx rcases (contDiffOn_succ_iff_hasFDerivWithinAt.1 hf) x hx with ⟹u, hu, f', hf', f'_diff⟩ rcases hg (f x) (st hx) with ⟹v, hv, g', hg', g'_diff⟩ rw [insert_eq_of_mem hx] at hu ⊢ have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu let w := s ∩ (u ∩ f ⁻¹' v) have wv : w ⊆ f ⁻¹' v := fun y hy => hy.2.2 have wu : w ⊆ u := fun y hy => hy.2.1 have ws : w ⊆ s := fun y hy => hy.1 refine ⟹w, ?_, fun y => (g' (f y)).comp (f' y), ?_, ?_⟩ · show w ∈ 𝓝[s] x apply Filter.inter_mem self_mem_nhdsWithin apply Filter.inter_mem hu apply ContinuousWithinAt.preimage_mem_nhdsWithin' · rw [← continuousWithinAt_inter' hu] exact (hf' x xu).differentiableWithinAt.continuousWithinAt.mono inter_subset_right · apply nhdsWithin_mono _ _ hv exact Subset.trans (image_subset_iff.mpr st) (subset_insert (f x) t) · show ∀ y ∈ w, HasFDerivWithinAt (g ∘ f) ((g' (f y)).comp (f' y)) w y rintro y ⟹-, yu, yv⟩ exact (hg' (f y) yv).comp y ((hf' y yu).mono wu) wv · show ContDiffOn 𝕜 n (fun y => (g' (f y)).comp (f' y)) w have A : ContDiffOn 𝕜 n (fun y => g' (f y)) w := IH g'_diff ((hf.of_le (WithTop.coe_le_coe.2 (Nat.le_succ n))).mono ws) wv have B : ContDiffOn 𝕜 n f' w := f'_diff.mono wu have C : ContDiffOn 𝕜 n (fun y => (g' (f y), f' y)) w := A.prod B have D : ContDiffOn 𝕜 n (fun p : (Fu →L[𝕜] Gu) × (Eu →L[𝕜] Fu) => p.1.comp p.2) univ := isBoundedBilinearMap_comp.contDiff.contDiffOn exact IH D C (subset_univ _) · rw [contDiffOn_top] at hf hg ⊢ exact fun n => Itop n (hg n) (hf n) st /-- The composition of `C^n` functions on domains is `C^n`. -/ theorem ContDiffOn.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (st : s ⊆ f ⁻¹' t) : ContDiffOn 𝕜 n (g ∘ f) s := by /- we lift all the spaces to a common universe, as we have already proved the result in this situation. -/ let Eu : Type max uE uF uG := ULift.{max uF uG} E let Fu : Type max uE uF uG := ULift.{max uE uG} F let Gu : Type max uE uF uG := ULift.{max uE uF} G -- declare the isomorphisms have isoE : Eu ≃L[𝕜] E := ContinuousLinearEquiv.ulift have isoF : Fu ≃L[𝕜] F := ContinuousLinearEquiv.ulift have isoG : Gu ≃L[𝕜] G := ContinuousLinearEquiv.ulift -- lift the functions to the new spaces, check smoothness there, and then go back. let fu : Eu → Fu := (isoF.symm ∘ f) ∘ isoE have fu_diff : ContDiffOn 𝕜 n fu (isoE ⁻¹' s) := by rwa [isoE.contDiffOn_comp_iff, isoF.symm.comp_contDiffOn_iff] let gu : Fu → Gu := (isoG.symm ∘ g) ∘ isoF have gu_diff : ContDiffOn 𝕜 n gu (isoF ⁻¹' t) := by rwa [isoF.contDiffOn_comp_iff, isoG.symm.comp_contDiffOn_iff] have main : ContDiffOn 𝕜 n (gu ∘ fu) (isoE ⁻¹' s) := by apply ContDiffOn.comp_same_univ gu_diff fu_diff intro y hy simp only [fu, ContinuousLinearEquiv.coe_apply, Function.comp_apply, mem_preimage] rw [isoF.apply_symm_apply (f (isoE y))] exact st hy have : gu ∘ fu = (isoG.symm ∘ g ∘ f) ∘ isoE := by ext y simp only [fu, gu, Function.comp_apply] rw [isoF.apply_symm_apply (f (isoE y))] rwa [this, isoE.contDiffOn_comp_iff, isoG.symm.comp_contDiffOn_iff] at main /-- The composition of `C^n` functions on domains is `C^n`. -/ theorem ContDiffOn.comp' {s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) (s ∩ f ⁻¹' t) := hg.comp (hf.mono inter_subset_left) inter_subset_right /-- The composition of a `C^n` function on a domain with a `C^n` function is `C^n`. -/ theorem ContDiff.comp_contDiffOn {s : Set E} {g : F → G} {f : E → F} (hg : ContDiff 𝕜 n g) (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) s := (contDiffOn_univ.2 hg).comp hf subset_preimage_univ /-- The composition of `C^n` functions is `C^n`. -/ theorem ContDiff.comp {g : F → G} {f : E → F} (hg : ContDiff 𝕜 n g) (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n (g ∘ f) := contDiffOn_univ.1 <| ContDiffOn.comp (contDiffOn_univ.2 hg) (contDiffOn_univ.2 hf) (subset_univ _) /-- The composition of `C^n` functions at points in domains is `C^n`. -/ theorem ContDiffWithinAt.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E) (hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) (st : s ⊆ f ⁻¹' t) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := by intro m hm rcases hg.contDiffOn hm with ⟹u, u_nhd, _, hu⟩ rcases hf.contDiffOn hm with ⟹v, v_nhd, vs, hv⟩ have xmem : x ∈ f ⁻¹' u ∩ v := ⟹(mem_of_mem_nhdsWithin (mem_insert (f x) _) u_nhd : _), mem_of_mem_nhdsWithin (mem_insert x s) v_nhd⟩ have : f ⁻¹' u ∈ 𝓝[insert x s] x := by apply hf.continuousWithinAt.insert_self.preimage_mem_nhdsWithin' apply nhdsWithin_mono _ _ u_nhd rw [image_insert_eq] exact insert_subset_insert (image_subset_iff.mpr st) have Z := (hu.comp (hv.mono inter_subset_right) inter_subset_left).contDiffWithinAt xmem m le_rfl have : 𝓝[f ⁻¹' u ∩ v] x = 𝓝[insert x s] x := by have A : f ⁻¹' u ∩ v = insert x s ∩ (f ⁻¹' u ∩ v) := by apply Subset.antisymm _ inter_subset_right rintro y ⟹hy1, hy2⟩ simpa only [mem_inter_iff, mem_preimage, hy2, and_true, true_and, vs hy2] using hy1 rw [A, ← nhdsWithin_restrict''] exact Filter.inter_mem this v_nhd rwa [insert_eq_of_mem xmem, this] at Z /-- The composition of `C^n` functions at points in domains is `C^n`, with a weaker condition on `s` and `t`. -/ theorem ContDiffWithinAt.comp_of_mem {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E) (hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) (hs : t ∈ 𝓝[f '' s] f x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := (hg.mono_of_mem hs).comp x hf (subset_preimage_image f s) /-- The composition of `C^n` functions at points in domains is `C^n`. -/ theorem ContDiffWithinAt.comp' {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E) (hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) (s ∩ f ⁻¹' t) x := hg.comp x (hf.mono inter_subset_left) inter_subset_right theorem ContDiffAt.comp_contDiffWithinAt {n} (x : E) (hg : ContDiffAt 𝕜 n g (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := hg.comp x hf (mapsTo_univ _ _) /-- The composition of `C^n` functions at points is `C^n`. -/ nonrec theorem ContDiffAt.comp (x : E) (hg : ContDiffAt 𝕜 n g (f x)) (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (g ∘ f) x := hg.comp x hf subset_preimage_univ theorem ContDiff.comp_contDiffWithinAt {g : F → G} {f : E → F} (h : ContDiff 𝕜 n g) (hf : ContDiffWithinAt 𝕜 n f t x) : ContDiffWithinAt 𝕜 n (g ∘ f) t x := haveI : ContDiffWithinAt 𝕜 n g univ (f x) := h.contDiffAt.contDiffWithinAt this.comp x hf (subset_univ _) theorem ContDiff.comp_contDiffAt {g : F → G} {f : E → F} (x : E) (hg : ContDiff 𝕜 n g) (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (g ∘ f) x := hg.comp_contDiffWithinAt hf /-! ### Smoothness of projections -/ /-- The first projection in a product is `C^∞`. -/ theorem contDiff_fst : ContDiff 𝕜 n (Prod.fst : E × F → E) := IsBoundedLinearMap.contDiff IsBoundedLinearMap.fst /-- Postcomposing `f` with `Prod.fst` is `C^n` -/ theorem ContDiff.fst {f : E → F × G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (f x).1 := contDiff_fst.comp hf /-- Precomposing `f` with `Prod.fst` is `C^n` -/ theorem ContDiff.fst' {f : E → G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x : E × F => f x.1 := hf.comp contDiff_fst /-- The first projection on a domain in a product is `C^∞`. -/ theorem contDiffOn_fst {s : Set (E × F)} : ContDiffOn 𝕜 n (Prod.fst : E × F → E) s := ContDiff.contDiffOn contDiff_fst theorem ContDiffOn.fst {f : E → F × G} {s : Set E} (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (fun x => (f x).1) s := contDiff_fst.comp_contDiffOn hf /-- The first projection at a point in a product is `C^∞`. -/ theorem contDiffAt_fst {p : E × F} : ContDiffAt 𝕜 n (Prod.fst : E × F → E) p := contDiff_fst.contDiffAt /-- Postcomposing `f` with `Prod.fst` is `C^n` at `(x, y)` -/ theorem ContDiffAt.fst {f : E → F × G} {x : E} (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (fun x => (f x).1) x := contDiffAt_fst.comp x hf /-- Precomposing `f` with `Prod.fst` is `C^n` at `(x, y)` -/ theorem ContDiffAt.fst' {f : E → G} {x : E} {y : F} (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (fun x : E × F => f x.1) (x, y) := ContDiffAt.comp (x, y) hf contDiffAt_fst /-- Precomposing `f` with `Prod.fst` is `C^n` at `x : E × F` -/ theorem ContDiffAt.fst'' {f : E → G} {x : E × F} (hf : ContDiffAt 𝕜 n f x.1) : ContDiffAt 𝕜 n (fun x : E × F => f x.1) x := hf.comp x contDiffAt_fst /-- The first projection within a domain at a point in a product is `C^∞`. -/ theorem contDiffWithinAt_fst {s : Set (E × F)} {p : E × F} : ContDiffWithinAt 𝕜 n (Prod.fst : E × F → E) s p := contDiff_fst.contDiffWithinAt /-- The second projection in a product is `C^∞`. -/ theorem contDiff_snd : ContDiff 𝕜 n (Prod.snd : E × F → F) := IsBoundedLinearMap.contDiff IsBoundedLinearMap.snd /-- Postcomposing `f` with `Prod.snd` is `C^n` -/ theorem ContDiff.snd {f : E → F × G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (f x).2 := contDiff_snd.comp hf /-- Precomposing `f` with `Prod.snd` is `C^n` -/ theorem ContDiff.snd' {f : F → G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x : E × F => f x.2 := hf.comp contDiff_snd /-- The second projection on a domain in a product is `C^∞`. -/ theorem contDiffOn_snd {s : Set (E × F)} : ContDiffOn 𝕜 n (Prod.snd : E × F → F) s := ContDiff.contDiffOn contDiff_snd theorem ContDiffOn.snd {f : E → F × G} {s : Set E} (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (fun x => (f x).2) s := contDiff_snd.comp_contDiffOn hf /-- The second projection at a point in a product is `C^∞`. -/ theorem contDiffAt_snd {p : E × F} : ContDiffAt 𝕜 n (Prod.snd : E × F → F) p := contDiff_snd.contDiffAt /-- Postcomposing `f` with `Prod.snd` is `C^n` at `x` -/ theorem ContDiffAt.snd {f : E → F × G} {x : E} (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (fun x => (f x).2) x := contDiffAt_snd.comp x hf /-- Precomposing `f` with `Prod.snd` is `C^n` at `(x, y)` -/ theorem ContDiffAt.snd' {f : F → G} {x : E} {y : F} (hf : ContDiffAt 𝕜 n f y) : ContDiffAt 𝕜 n (fun x : E × F => f x.2) (x, y) := ContDiffAt.comp (x, y) hf contDiffAt_snd /-- Precomposing `f` with `Prod.snd` is `C^n` at `x : E × F` -/ theorem ContDiffAt.snd'' {f : F → G} {x : E × F} (hf : ContDiffAt 𝕜 n f x.2) : ContDiffAt 𝕜 n (fun x : E × F => f x.2) x := hf.comp x contDiffAt_snd /-- The second projection within a domain at a point in a product is `C^∞`. -/ theorem contDiffWithinAt_snd {s : Set (E × F)} {p : E × F} : ContDiffWithinAt 𝕜 n (Prod.snd : E × F → F) s p := contDiff_snd.contDiffWithinAt section NAry variable {E₁ E₂ E₃ E₄ : Type*} variable [NormedAddCommGroup E₁] [NormedAddCommGroup E₂] [NormedAddCommGroup E₃] [NormedAddCommGroup E₄] [NormedSpace 𝕜 E₁] [NormedSpace 𝕜 E₂] [NormedSpace 𝕜 E₃] [NormedSpace 𝕜 E₄] theorem ContDiff.comp₂ {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} (hg : ContDiff 𝕜 n g) (hf₁ : ContDiff 𝕜 n f₁) (hf₂ : ContDiff 𝕜 n f₂) : ContDiff 𝕜 n fun x => g (f₁ x, f₂ x) := hg.comp <| hf₁.prod hf₂ theorem ContDiff.comp₃ {g : E₁ × E₂ × E₃ → G} {f₁ : F → E₁} {f₂ : F → E₂} {f₃ : F → E₃} (hg : ContDiff 𝕜 n g) (hf₁ : ContDiff 𝕜 n f₁) (hf₂ : ContDiff 𝕜 n f₂) (hf₃ : ContDiff 𝕜 n f₃) : ContDiff 𝕜 n fun x => g (f₁ x, f₂ x, f₃ x) := hg.comp₂ hf₁ <| hf₂.prod hf₃ theorem ContDiff.comp_contDiff_on₂ {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} {s : Set F} (hg : ContDiff 𝕜 n g) (hf₁ : ContDiffOn 𝕜 n f₁ s) (hf₂ : ContDiffOn 𝕜 n f₂ s) : ContDiffOn 𝕜 n (fun x => g (f₁ x, f₂ x)) s := hg.comp_contDiffOn <| hf₁.prod hf₂ theorem ContDiff.comp_contDiff_on₃ {g : E₁ × E₂ × E₃ → G} {f₁ : F → E₁} {f₂ : F → E₂} {f₃ : F → E₃} {s : Set F} (hg : ContDiff 𝕜 n g) (hf₁ : ContDiffOn 𝕜 n f₁ s) (hf₂ : ContDiffOn 𝕜 n f₂ s) (hf₃ : ContDiffOn 𝕜 n f₃ s) : ContDiffOn 𝕜 n (fun x => g (f₁ x, f₂ x, f₃ x)) s := hg.comp_contDiff_on₂ hf₁ <| hf₂.prod hf₃ end NAry section SpecificBilinearMaps theorem ContDiff.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} (hg : ContDiff 𝕜 n g) (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (g x).comp (f x) := isBoundedBilinearMap_comp.contDiff.comp₂ hg hf theorem ContDiffOn.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} {s : Set X} (hg : ContDiffOn 𝕜 n g s) (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (fun x => (g x).comp (f x)) s := isBoundedBilinearMap_comp.contDiff.comp_contDiff_on₂ hg hf theorem ContDiff.clm_apply {f : E → F →L[𝕜] G} {g : E → F} {n : ℕ∞} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => (f x) (g x) := isBoundedBilinearMap_apply.contDiff.comp₂ hf hg theorem ContDiffOn.clm_apply {f : E → F →L[𝕜] G} {g : E → F} {n : ℕ∞} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => (f x) (g x)) s := isBoundedBilinearMap_apply.contDiff.comp_contDiff_on₂ hf hg -- Porting note: In Lean 3 we had to give implicit arguments in proofs like the following, -- to speed up elaboration. In Lean 4 this isn't necessary anymore. theorem ContDiff.smulRight {f : E → F →L[𝕜] 𝕜} {g : E → G} {n : ℕ∞} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => (f x).smulRight (g x) := isBoundedBilinearMap_smulRight.contDiff.comp₂ hf hg end SpecificBilinearMaps section ClmApplyConst /-- Application of a `ContinuousLinearMap` to a constant commutes with `iteratedFDerivWithin`. -/ theorem iteratedFDerivWithin_clm_apply_const_apply {s : Set E} (hs : UniqueDiffOn 𝕜 s) {n : ℕ∞} {c : E → F →L[𝕜] G} (hc : ContDiffOn 𝕜 n c s) {i : ℕ} (hi : i ≀ n) {x : E} (hx : x ∈ s) {u : F} {m : Fin i → E} : (iteratedFDerivWithin 𝕜 i (fun y ↩ (c y) u) s x) m = (iteratedFDerivWithin 𝕜 i c s x) m u := by induction i generalizing x with | zero => simp | succ i ih => replace hi : i < n := lt_of_lt_of_le (by norm_cast; simp) hi have h_deriv_apply : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 i (fun y ↩ (c y) u) s) s := (hc.clm_apply contDiffOn_const).differentiableOn_iteratedFDerivWithin hi hs have h_deriv : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 i c s) s := hc.differentiableOn_iteratedFDerivWithin hi hs simp only [iteratedFDerivWithin_succ_apply_left] rw [← fderivWithin_continuousMultilinear_apply_const_apply (hs x hx) (h_deriv_apply x hx)] rw [fderivWithin_congr' (fun x hx ↩ ih hi.le hx) hx] rw [fderivWithin_clm_apply (hs x hx) (h_deriv.continuousMultilinear_apply_const _ x hx) (differentiableWithinAt_const u)] rw [fderivWithin_const_apply _ (hs x hx)] simp only [ContinuousLinearMap.flip_apply, ContinuousLinearMap.comp_zero, zero_add] rw [fderivWithin_continuousMultilinear_apply_const_apply (hs x hx) (h_deriv x hx)] /-- Application of a `ContinuousLinearMap` to a constant commutes with `iteratedFDeriv`. -/ theorem iteratedFDeriv_clm_apply_const_apply {n : ℕ∞} {c : E → F →L[𝕜] G} (hc : ContDiff 𝕜 n c) {i : ℕ} (hi : i ≀ n) {x : E} {u : F} {m : Fin i → E} : (iteratedFDeriv 𝕜 i (fun y ↩ (c y) u) x) m = (iteratedFDeriv 𝕜 i c x) m u := by simp only [← iteratedFDerivWithin_univ] exact iteratedFDerivWithin_clm_apply_const_apply uniqueDiffOn_univ hc.contDiffOn hi (mem_univ _) end ClmApplyConst /-- The natural equivalence `(E × F) × G ≃ E × (F × G)` is smooth. Warning: if you think you need this lemma, it is likely that you can simplify your proof by reformulating the lemma that you're applying next using the tips in Note [continuity lemma statement] -/ theorem contDiff_prodAssoc : ContDiff 𝕜 ⊀ <| Equiv.prodAssoc E F G := (LinearIsometryEquiv.prodAssoc 𝕜 E F G).contDiff /-- The natural equivalence `E × (F × G) ≃ (E × F) × G` is smooth. Warning: see remarks attached to `contDiff_prodAssoc` -/ theorem contDiff_prodAssoc_symm : ContDiff 𝕜 ⊀ <| (Equiv.prodAssoc E F G).symm := (LinearIsometryEquiv.prodAssoc 𝕜 E F G).symm.contDiff /-! ### Bundled derivatives are smooth -/ /-- One direction of `contDiffWithinAt_succ_iff_hasFDerivWithinAt`, but where all derivatives taken within the same set. Version for partial derivatives / functions with parameters. `f x` is a `C^n+1` family of functions and `g x` is a `C^n` family of points, then the derivative of `f x` at `g x` depends in a `C^n` way on `x`. We give a general version of this fact relative to sets which may not have unique derivatives, in the following form. If `f : E × F → G` is `C^n+1` at `(x₀, g(x₀))` in `(s ∪ {x₀}) × t ⊆ E × F` and `g : E → F` is `C^n` at `x₀` within some set `s ⊆ E`, then there is a function `f' : E → F →L[𝕜] G` that is `C^n` at `x₀` within `s` such that for all `x` sufficiently close to `x₀` within `s ∪ {x₀}` the function `y ↩ f x y` has derivative `f' x` at `g x` within `t ⊆ F`. For convenience, we return an explicit set of `x`'s where this holds that is a subset of `s ∪ {x₀}`. We need one additional condition, namely that `t` is a neighborhood of `g(x₀)` within `g '' s`. -/ theorem ContDiffWithinAt.hasFDerivWithinAt_nhds {f : E → F → G} {g : E → F} {t : Set F} {n : ℕ} {x₀ : E} (hf : ContDiffWithinAt 𝕜 (n + 1) (uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀)) (hg : ContDiffWithinAt 𝕜 n g s x₀) (hgt : t ∈ 𝓝[g '' s] g x₀) : ∃ v ∈ 𝓝[insert x₀ s] x₀, v ⊆ insert x₀ s ∧ ∃ f' : E → F →L[𝕜] G, (∀ x ∈ v, HasFDerivWithinAt (f x) (f' x) t (g x)) ∧ ContDiffWithinAt 𝕜 n (fun x => f' x) s x₀ := by have hst : insert x₀ s ×ˢ t ∈ 𝓝[(fun x => (x, g x)) '' s] (x₀, g x₀) := by refine nhdsWithin_mono _ ?_ (nhdsWithin_prod self_mem_nhdsWithin hgt) simp_rw [image_subset_iff, mk_preimage_prod, preimage_id', subset_inter_iff, subset_insert, true_and_iff, subset_preimage_image] obtain ⟹v, hv, hvs, f', hvf', hf'⟩ := contDiffWithinAt_succ_iff_hasFDerivWithinAt'.mp hf refine ⟹(fun z => (z, g z)) ⁻¹' v ∩ insert x₀ s, ?_, inter_subset_right, fun z => (f' (z, g z)).comp (ContinuousLinearMap.inr 𝕜 E F), ?_, ?_⟩ · refine inter_mem ?_ self_mem_nhdsWithin have := mem_of_mem_nhdsWithin (mem_insert _ _) hv refine mem_nhdsWithin_insert.mpr ⟹this, ?_⟩ refine (continuousWithinAt_id.prod hg.continuousWithinAt).preimage_mem_nhdsWithin' ?_ rw [← nhdsWithin_le_iff] at hst hv ⊢ exact (hst.trans <| nhdsWithin_mono _ <| subset_insert _ _).trans hv · intro z hz have := hvf' (z, g z) hz.1 refine this.comp _ (hasFDerivAt_prod_mk_right _ _).hasFDerivWithinAt ?_ exact mapsTo'.mpr (image_prod_mk_subset_prod_right hz.2) · exact (hf'.continuousLinearMap_comp <| (ContinuousLinearMap.compL 𝕜 F (E × F) G).flip (ContinuousLinearMap.inr 𝕜 E F)).comp_of_mem x₀ (contDiffWithinAt_id.prod hg) hst /-- The most general lemma stating that `x ↩ fderivWithin 𝕜 (f x) t (g x)` is `C^n` at a point within a set. To show that `x ↩ D_yf(x,y)g(x)` (taken within `t`) is `C^m` at `x₀` within `s`, we require that * `f` is `C^n` at `(x₀, g(x₀))` within `(s ∪ {x₀}) × t` for `n ≥ m+1`. * `g` is `C^m` at `x₀` within `s`; * Derivatives are unique at `g(x)` within `t` for `x` sufficiently close to `x₀` within `s ∪ {x₀}`; * `t` is a neighborhood of `g(x₀)` within `g '' s`; -/ theorem ContDiffWithinAt.fderivWithin'' {f : E → F → G} {g : E → F} {t : Set F} {n : ℕ∞} (hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀)) (hg : ContDiffWithinAt 𝕜 m g s x₀) (ht : ∀ᶠ x in 𝓝[insert x₀ s] x₀, UniqueDiffWithinAt 𝕜 t (g x)) (hmn : m + 1 ≀ n) (hgt : t ∈ 𝓝[g '' s] g x₀) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := by have : ∀ k : ℕ, (k : ℕ∞) ≀ m → ContDiffWithinAt 𝕜 k (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := fun k hkm ↩ by obtain ⟹v, hv, -, f', hvf', hf'⟩ := (hf.of_le <| (add_le_add_right hkm 1).trans hmn).hasFDerivWithinAt_nhds (hg.of_le hkm) hgt refine hf'.congr_of_eventuallyEq_insert ?_ filter_upwards [hv, ht] exact fun y hy h2y => (hvf' y hy).fderivWithin h2y induction' m with m · obtain rfl := eq_top_iff.mpr hmn rw [contDiffWithinAt_top] exact fun m => this m le_top exact this _ le_rfl /-- A special case of `ContDiffWithinAt.fderivWithin''` where we require that `s ⊆ g⁻¹(t)`. -/ theorem ContDiffWithinAt.fderivWithin' {f : E → F → G} {g : E → F} {t : Set F} {n : ℕ∞} (hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀)) (hg : ContDiffWithinAt 𝕜 m g s x₀) (ht : ∀ᶠ x in 𝓝[insert x₀ s] x₀, UniqueDiffWithinAt 𝕜 t (g x)) (hmn : m + 1 ≀ n) (hst : s ⊆ g ⁻¹' t) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := hf.fderivWithin'' hg ht hmn <| mem_of_superset self_mem_nhdsWithin <| image_subset_iff.mpr hst /-- A special case of `ContDiffWithinAt.fderivWithin'` where we require that `x₀ ∈ s` and there are unique derivatives everywhere within `t`. -/ protected theorem ContDiffWithinAt.fderivWithin {f : E → F → G} {g : E → F} {t : Set F} {n : ℕ∞} (hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (s ×ˢ t) (x₀, g x₀)) (hg : ContDiffWithinAt 𝕜 m g s x₀) (ht : UniqueDiffOn 𝕜 t) (hmn : m + 1 ≀ n) (hx₀ : x₀ ∈ s) (hst : s ⊆ g ⁻¹' t) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := by rw [← insert_eq_self.mpr hx₀] at hf refine hf.fderivWithin' hg ?_ hmn hst rw [insert_eq_self.mpr hx₀] exact eventually_of_mem self_mem_nhdsWithin fun x hx => ht _ (hst hx) /-- `x ↩ fderivWithin 𝕜 (f x) t (g x) (k x)` is smooth at a point within a set. -/ theorem ContDiffWithinAt.fderivWithin_apply {f : E → F → G} {g k : E → F} {t : Set F} {n : ℕ∞} (hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (s ×ˢ t) (x₀, g x₀)) (hg : ContDiffWithinAt 𝕜 m g s x₀) (hk : ContDiffWithinAt 𝕜 m k s x₀) (ht : UniqueDiffOn 𝕜 t) (hmn : m + 1 ≀ n) (hx₀ : x₀ ∈ s) (hst : s ⊆ g ⁻¹' t) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x) (k x)) s x₀ := (contDiff_fst.clm_apply contDiff_snd).contDiffAt.comp_contDiffWithinAt x₀ ((hf.fderivWithin hg ht hmn hx₀ hst).prod hk) /-- `fderivWithin 𝕜 f s` is smooth at `x₀` within `s`. -/ theorem ContDiffWithinAt.fderivWithin_right (hf : ContDiffWithinAt 𝕜 n f s x₀) (hs : UniqueDiffOn 𝕜 s) (hmn : (m + 1 : ℕ∞) ≀ n) (hx₀s : x₀ ∈ s) : ContDiffWithinAt 𝕜 m (fderivWithin 𝕜 f s) s x₀ := ContDiffWithinAt.fderivWithin (ContDiffWithinAt.comp (x₀, x₀) hf contDiffWithinAt_snd <| prod_subset_preimage_snd s s) contDiffWithinAt_id hs hmn hx₀s (by rw [preimage_id']) -- TODO: can we make a version of `ContDiffWithinAt.fderivWithin` for iterated derivatives? theorem ContDiffWithinAt.iteratedFderivWithin_right {i : ℕ} (hf : ContDiffWithinAt 𝕜 n f s x₀) (hs : UniqueDiffOn 𝕜 s) (hmn : (m + i : ℕ∞) ≀ n) (hx₀s : x₀ ∈ s) : ContDiffWithinAt 𝕜 m (iteratedFDerivWithin 𝕜 i f s) s x₀ := by induction' i with i hi generalizing m · rw [ENat.coe_zero, add_zero] at hmn exact (hf.of_le hmn).continuousLinearMap_comp ((continuousMultilinearCurryFin0 𝕜 E F).symm : _ →L[𝕜] E [×0]→L[𝕜] F) · rw [Nat.cast_succ, add_comm _ 1, ← add_assoc] at hmn exact ((hi hmn).fderivWithin_right hs le_rfl hx₀s).continuousLinearMap_comp (continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (i+1) ↩ E) F : _ →L[𝕜] E [×(i+1)]→L[𝕜] F) /-- `x ↩ fderiv 𝕜 (f x) (g x)` is smooth at `x₀`. -/ protected theorem ContDiffAt.fderiv {f : E → F → G} {g : E → F} {n : ℕ∞} (hf : ContDiffAt 𝕜 n (Function.uncurry f) (x₀, g x₀)) (hg : ContDiffAt 𝕜 m g x₀) (hmn : m + 1 ≀ n) : ContDiffAt 𝕜 m (fun x => fderiv 𝕜 (f x) (g x)) x₀ := by simp_rw [← fderivWithin_univ] refine (ContDiffWithinAt.fderivWithin hf.contDiffWithinAt hg.contDiffWithinAt uniqueDiffOn_univ hmn (mem_univ x₀) ?_).contDiffAt univ_mem rw [preimage_univ] /-- `fderiv 𝕜 f` is smooth at `x₀`. -/ theorem ContDiffAt.fderiv_right (hf : ContDiffAt 𝕜 n f x₀) (hmn : (m + 1 : ℕ∞) ≀ n) : ContDiffAt 𝕜 m (fderiv 𝕜 f) x₀ := ContDiffAt.fderiv (ContDiffAt.comp (x₀, x₀) hf contDiffAt_snd) contDiffAt_id hmn theorem ContDiffAt.iteratedFDeriv_right {i : ℕ} (hf : ContDiffAt 𝕜 n f x₀) (hmn : (m + i : ℕ∞) ≀ n) : ContDiffAt 𝕜 m (iteratedFDeriv 𝕜 i f) x₀ := by rw [← iteratedFDerivWithin_univ, ← contDiffWithinAt_univ] at * exact hf.iteratedFderivWithin_right uniqueDiffOn_univ hmn trivial /-- `x ↩ fderiv 𝕜 (f x) (g x)` is smooth. -/ protected theorem ContDiff.fderiv {f : E → F → G} {g : E → F} {n m : ℕ∞} (hf : ContDiff 𝕜 m <| Function.uncurry f) (hg : ContDiff 𝕜 n g) (hnm : n + 1 ≀ m) : ContDiff 𝕜 n fun x => fderiv 𝕜 (f x) (g x) := contDiff_iff_contDiffAt.mpr fun _ => hf.contDiffAt.fderiv hg.contDiffAt hnm /-- `fderiv 𝕜 f` is smooth. -/ theorem ContDiff.fderiv_right (hf : ContDiff 𝕜 n f) (hmn : (m + 1 : ℕ∞) ≀ n) : ContDiff 𝕜 m (fderiv 𝕜 f) := contDiff_iff_contDiffAt.mpr fun _x => hf.contDiffAt.fderiv_right hmn theorem ContDiff.iteratedFDeriv_right {i : ℕ} (hf : ContDiff 𝕜 n f) (hmn : (m + i : ℕ∞) ≀ n) : ContDiff 𝕜 m (iteratedFDeriv 𝕜 i f) := contDiff_iff_contDiffAt.mpr fun _x => hf.contDiffAt.iteratedFDeriv_right hmn /-- `x ↩ fderiv 𝕜 (f x) (g x)` is continuous. -/ theorem Continuous.fderiv {f : E → F → G} {g : E → F} {n : ℕ∞} (hf : ContDiff 𝕜 n <| Function.uncurry f) (hg : Continuous g) (hn : 1 ≀ n) : Continuous fun x => fderiv 𝕜 (f x) (g x) := (hf.fderiv (contDiff_zero.mpr hg) hn).continuous /-- `x ↩ fderiv 𝕜 (f x) (g x) (k x)` is smooth. -/ theorem ContDiff.fderiv_apply {f : E → F → G} {g k : E → F} {n m : ℕ∞} (hf : ContDiff 𝕜 m <| Function.uncurry f) (hg : ContDiff 𝕜 n g) (hk : ContDiff 𝕜 n k) (hnm : n + 1 ≀ m) : ContDiff 𝕜 n fun x => fderiv 𝕜 (f x) (g x) (k x) := (hf.fderiv hg hnm).clm_apply hk /-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/ theorem contDiffOn_fderivWithin_apply {m n : ℕ∞} {s : Set E} {f : E → F} (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≀ n) : ContDiffOn 𝕜 m (fun p : E × E => (fderivWithin 𝕜 f s p.1 : E →L[𝕜] F) p.2) (s ×ˢ univ) := ((hf.fderivWithin hs hmn).comp contDiffOn_fst (prod_subset_preimage_fst _ _)).clm_apply contDiffOn_snd /-- If a function is at least `C^1`, its bundled derivative (mapping `(x, v)` to `Df(x) v`) is continuous. -/ theorem ContDiffOn.continuousOn_fderivWithin_apply (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hn : 1 ≀ n) : ContinuousOn (fun p : E × E => (fderivWithin 𝕜 f s p.1 : E → F) p.2) (s ×ˢ univ) := (contDiffOn_fderivWithin_apply hf hs <| by rwa [zero_add]).continuousOn /-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/ theorem ContDiff.contDiff_fderiv_apply {f : E → F} (hf : ContDiff 𝕜 n f) (hmn : m + 1 ≀ n) : ContDiff 𝕜 m fun p : E × E => (fderiv 𝕜 f p.1 : E →L[𝕜] F) p.2 := by rw [← contDiffOn_univ] at hf ⊢ rw [← fderivWithin_univ, ← univ_prod_univ] exact contDiffOn_fderivWithin_apply hf uniqueDiffOn_univ hmn /-! ### Smoothness of functions `f : E → Π i, F' i` -/ section Pi variable {ι ι' : Type*} [Fintype ι] [Fintype ι'] {F' : ι → Type*} [∀ i, NormedAddCommGroup (F' i)] [∀ i, NormedSpace 𝕜 (F' i)] {φ : ∀ i, E → F' i} {p' : ∀ i, E → FormalMultilinearSeries 𝕜 E (F' i)} {Ί : E → ∀ i, F' i} {P' : E → FormalMultilinearSeries 𝕜 E (∀ i, F' i)} theorem hasFTaylorSeriesUpToOn_pi : HasFTaylorSeriesUpToOn n (fun x i => φ i x) (fun x m => ContinuousMultilinearMap.pi fun i => p' i x m) s ↔ ∀ i, HasFTaylorSeriesUpToOn n (φ i) (p' i) s := by set pr := @ContinuousLinearMap.proj 𝕜 _ ι F' _ _ _ letI : ∀ (m : ℕ) (i : ι), NormedSpace 𝕜 (E[×m]→L[𝕜] F' i) := fun m i => inferInstance set L : ∀ m : ℕ, (∀ i, E[×m]→L[𝕜] F' i) ≃ₗᵢ[𝕜] E[×m]→L[𝕜] ∀ i, F' i := fun m => ContinuousMultilinearMap.piₗᵢ _ _ refine ⟹fun h i => ?_, fun h => ⟹fun x hx => ?_, ?_, ?_⟩⟩ · convert h.continuousLinearMap_comp (pr i) · ext1 i exact (h i).zero_eq x hx · intro m hm x hx have := hasFDerivWithinAt_pi.2 fun i => (h i).fderivWithin m hm x hx convert (L m).hasFDerivAt.comp_hasFDerivWithinAt x this · intro m hm have := continuousOn_pi.2 fun i => (h i).cont m hm convert (L m).continuous.comp_continuousOn this @[simp] theorem hasFTaylorSeriesUpToOn_pi' : HasFTaylorSeriesUpToOn n Ί P' s ↔ ∀ i, HasFTaylorSeriesUpToOn n (fun x => Ί x i) (fun x m => (@ContinuousLinearMap.proj 𝕜 _ ι F' _ _ _ i).compContinuousMultilinearMap (P' x m)) s := by convert hasFTaylorSeriesUpToOn_pi (𝕜 := 𝕜) (φ := fun i x ↩ Ί x i); ext; rfl theorem contDiffWithinAt_pi : ContDiffWithinAt 𝕜 n Ί s x ↔ ∀ i, ContDiffWithinAt 𝕜 n (fun x => Ί x i) s x := by set pr := @ContinuousLinearMap.proj 𝕜 _ ι F' _ _ _ refine ⟹fun h i => h.continuousLinearMap_comp (pr i), fun h m hm => ?_⟩ choose u hux p hp using fun i => h i m hm exact ⟹⋂ i, u i, Filter.iInter_mem.2 hux, _, hasFTaylorSeriesUpToOn_pi.2 fun i => (hp i).mono <| iInter_subset _ _⟩ theorem contDiffOn_pi : ContDiffOn 𝕜 n Ί s ↔ ∀ i, ContDiffOn 𝕜 n (fun x => Ί x i) s := ⟹fun h _ x hx => contDiffWithinAt_pi.1 (h x hx) _, fun h x hx => contDiffWithinAt_pi.2 fun i => h i x hx⟩ theorem contDiffAt_pi : ContDiffAt 𝕜 n Ί x ↔ ∀ i, ContDiffAt 𝕜 n (fun x => Ί x i) x := contDiffWithinAt_pi theorem contDiff_pi : ContDiff 𝕜 n Ί ↔ ∀ i, ContDiff 𝕜 n fun x => Ί x i := by simp only [← contDiffOn_univ, contDiffOn_pi] theorem contDiff_update [DecidableEq ι] (k : ℕ∞) (x : ∀ i, F' i) (i : ι) : ContDiff 𝕜 k (update x i) := by rw [contDiff_pi] intro j dsimp [Function.update] split_ifs with h · subst h exact contDiff_id · exact contDiff_const variable (F') in theorem contDiff_single [DecidableEq ι] (k : ℕ∞) (i : ι) : ContDiff 𝕜 k (Pi.single i : F' i → ∀ i, F' i) := contDiff_update k 0 i variable (𝕜 E) theorem contDiff_apply (i : ι) : ContDiff 𝕜 n fun f : ι → E => f i := contDiff_pi.mp contDiff_id i theorem contDiff_apply_apply (i : ι) (j : ι') : ContDiff 𝕜 n fun f : ι → ι' → E => f i j := contDiff_pi.mp (contDiff_apply 𝕜 (ι' → E) i) j end Pi /-! ### Sum of two functions -/ section Add theorem HasFTaylorSeriesUpToOn.add {q g} (hf : HasFTaylorSeriesUpToOn n f p s) (hg : HasFTaylorSeriesUpToOn n g q s) : HasFTaylorSeriesUpToOn n (f + g) (p + q) s := by convert HasFTaylorSeriesUpToOn.continuousLinearMap_comp (ContinuousLinearMap.fst 𝕜 F F + .snd 𝕜 F F) (hf.prod hg) -- The sum is smooth. theorem contDiff_add : ContDiff 𝕜 n fun p : F × F => p.1 + p.2 := (IsBoundedLinearMap.fst.add IsBoundedLinearMap.snd).contDiff /-- The sum of two `C^n` functions within a set at a point is `C^n` within this set at this point. -/ theorem ContDiffWithinAt.add {s : Set E} {f g : E → F} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x => f x + g x) s x := contDiff_add.contDiffWithinAt.comp x (hf.prod hg) subset_preimage_univ /-- The sum of two `C^n` functions at a point is `C^n` at this point. -/ theorem ContDiffAt.add {f g : E → F} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => f x + g x) x := by rw [← contDiffWithinAt_univ] at *; exact hf.add hg /-- The sum of two `C^n`functions is `C^n`. -/ theorem ContDiff.add {f g : E → F} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => f x + g x := contDiff_add.comp (hf.prod hg) /-- The sum of two `C^n` functions on a domain is `C^n`. -/ theorem ContDiffOn.add {s : Set E} {f g : E → F} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => f x + g x) s := fun x hx => (hf x hx).add (hg x hx) variable {i : ℕ} /-- The iterated derivative of the sum of two functions is the sum of the iterated derivatives. See also `iteratedFDerivWithin_add_apply'`, which uses the spelling `(fun x ↩ f x + g x)` instead of `f + g`. -/ theorem iteratedFDerivWithin_add_apply {f g : E → F} (hf : ContDiffOn 𝕜 i f s) (hg : ContDiffOn 𝕜 i g s) (hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 i (f + g) s x = iteratedFDerivWithin 𝕜 i f s x + iteratedFDerivWithin 𝕜 i g s x := Eq.symm <| ((hf.ftaylorSeriesWithin hu).add (hg.ftaylorSeriesWithin hu)).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl hu hx /-- The iterated derivative of the sum of two functions is the sum of the iterated derivatives. This is the same as `iteratedFDerivWithin_add_apply`, but using the spelling `(fun x ↩ f x + g x)` instead of `f + g`, which can be handy for some rewrites. TODO: use one form consistently. -/ theorem iteratedFDerivWithin_add_apply' {f g : E → F} (hf : ContDiffOn 𝕜 i f s) (hg : ContDiffOn 𝕜 i g s) (hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 i (fun x => f x + g x) s x = iteratedFDerivWithin 𝕜 i f s x + iteratedFDerivWithin 𝕜 i g s x := iteratedFDerivWithin_add_apply hf hg hu hx theorem iteratedFDeriv_add_apply {i : ℕ} {f g : E → F} (hf : ContDiff 𝕜 i f) (hg : ContDiff 𝕜 i g) : iteratedFDeriv 𝕜 i (f + g) x = iteratedFDeriv 𝕜 i f x + iteratedFDeriv 𝕜 i g x := by simp_rw [← contDiffOn_univ, ← iteratedFDerivWithin_univ] at hf hg ⊢ exact iteratedFDerivWithin_add_apply hf hg uniqueDiffOn_univ (Set.mem_univ _) theorem iteratedFDeriv_add_apply' {i : ℕ} {f g : E → F} (hf : ContDiff 𝕜 i f) (hg : ContDiff 𝕜 i g) : iteratedFDeriv 𝕜 i (fun x => f x + g x) x = iteratedFDeriv 𝕜 i f x + iteratedFDeriv 𝕜 i g x := iteratedFDeriv_add_apply hf hg end Add /-! ### Negative -/ section Neg -- The negative is smooth. theorem contDiff_neg : ContDiff 𝕜 n fun p : F => -p := IsBoundedLinearMap.id.neg.contDiff /-- The negative of a `C^n` function within a domain at a point is `C^n` within this domain at this point. -/ theorem ContDiffWithinAt.neg {s : Set E} {f : E → F} (hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (fun x => -f x) s x := contDiff_neg.contDiffWithinAt.comp x hf subset_preimage_univ /-- The negative of a `C^n` function at a point is `C^n` at this point. -/ theorem ContDiffAt.neg {f : E → F} (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (fun x => -f x) x := by rw [← contDiffWithinAt_univ] at *; exact hf.neg /-- The negative of a `C^n`function is `C^n`. -/ theorem ContDiff.neg {f : E → F} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => -f x := contDiff_neg.comp hf /-- The negative of a `C^n` function on a domain is `C^n`. -/ theorem ContDiffOn.neg {s : Set E} {f : E → F} (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (fun x => -f x) s := fun x hx => (hf x hx).neg variable {i : ℕ} -- Porting note (#11215): TODO: define `Neg` instance on `ContinuousLinearEquiv`, -- prove it from `ContinuousLinearEquiv.iteratedFDerivWithin_comp_left` theorem iteratedFDerivWithin_neg_apply {f : E → F} (hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 i (-f) s x = -iteratedFDerivWithin 𝕜 i f s x := by induction' i with i hi generalizing x · ext; simp · ext h calc iteratedFDerivWithin 𝕜 (i + 1) (-f) s x h = fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (-f) s) s x (h 0) (Fin.tail h) := rfl _ = fderivWithin 𝕜 (-iteratedFDerivWithin 𝕜 i f s) s x (h 0) (Fin.tail h) := by rw [fderivWithin_congr' (@hi) hx]; rfl _ = -(fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i f s) s) x (h 0) (Fin.tail h) := by rw [Pi.neg_def, fderivWithin_neg (hu x hx)]; rfl _ = -(iteratedFDerivWithin 𝕜 (i + 1) f s) x h := rfl theorem iteratedFDeriv_neg_apply {i : ℕ} {f : E → F} : iteratedFDeriv 𝕜 i (-f) x = -iteratedFDeriv 𝕜 i f x := by simp_rw [← iteratedFDerivWithin_univ] exact iteratedFDerivWithin_neg_apply uniqueDiffOn_univ (Set.mem_univ _) end Neg /-! ### Subtraction -/ /-- The difference of two `C^n` functions within a set at a point is `C^n` within this set at this point. -/ theorem ContDiffWithinAt.sub {s : Set E} {f g : E → F} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x => f x - g x) s x := by simpa only [sub_eq_add_neg] using hf.add hg.neg /-- The difference of two `C^n` functions at a point is `C^n` at this point. -/ theorem ContDiffAt.sub {f g : E → F} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => f x - g x) x := by simpa only [sub_eq_add_neg] using hf.add hg.neg /-- The difference of two `C^n` functions on a domain is `C^n`. -/ theorem ContDiffOn.sub {s : Set E} {f g : E → F} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => f x - g x) s := by simpa only [sub_eq_add_neg] using hf.add hg.neg /-- The difference of two `C^n` functions is `C^n`. -/ theorem ContDiff.sub {f g : E → F} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => f x - g x := by simpa only [sub_eq_add_neg] using hf.add hg.neg /-! ### Sum of finitely many functions -/ theorem ContDiffWithinAt.sum {ι : Type*} {f : ι → E → F} {s : Finset ι} {t : Set E} {x : E} (h : ∀ i ∈ s, ContDiffWithinAt 𝕜 n (fun x => f i x) t x) : ContDiffWithinAt 𝕜 n (fun x => ∑ i ∈ s, f i x) t x := by classical induction' s using Finset.induction_on with i s is IH · simp [contDiffWithinAt_const] · simp only [is, Finset.sum_insert, not_false_iff] exact (h _ (Finset.mem_insert_self i s)).add (IH fun j hj => h _ (Finset.mem_insert_of_mem hj)) theorem ContDiffAt.sum {ι : Type*} {f : ι → E → F} {s : Finset ι} {x : E} (h : ∀ i ∈ s, ContDiffAt 𝕜 n (fun x => f i x) x) : ContDiffAt 𝕜 n (fun x => ∑ i ∈ s, f i x) x := by rw [← contDiffWithinAt_univ] at *; exact ContDiffWithinAt.sum h theorem ContDiffOn.sum {ι : Type*} {f : ι → E → F} {s : Finset ι} {t : Set E} (h : ∀ i ∈ s, ContDiffOn 𝕜 n (fun x => f i x) t) : ContDiffOn 𝕜 n (fun x => ∑ i ∈ s, f i x) t := fun x hx => ContDiffWithinAt.sum fun i hi => h i hi x hx theorem ContDiff.sum {ι : Type*} {f : ι → E → F} {s : Finset ι} (h : ∀ i ∈ s, ContDiff 𝕜 n fun x => f i x) : ContDiff 𝕜 n fun x => ∑ i ∈ s, f i x := by simp only [← contDiffOn_univ] at *; exact ContDiffOn.sum h theorem iteratedFDerivWithin_sum_apply {ι : Type*} {f : ι → E → F} {u : Finset ι} {i : ℕ} {x : E} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h : ∀ j ∈ u, ContDiffOn 𝕜 i (f j) s) : iteratedFDerivWithin 𝕜 i (∑ j ∈ u, f j ·) s x = ∑ j ∈ u, iteratedFDerivWithin 𝕜 i (f j) s x := by induction u using Finset.cons_induction with | empty => ext; simp [hs, hx] | cons a u ha IH => simp only [Finset.mem_cons, forall_eq_or_imp] at h simp only [Finset.sum_cons] rw [iteratedFDerivWithin_add_apply' h.1 (ContDiffOn.sum h.2) hs hx, IH h.2] theorem iteratedFDeriv_sum {ι : Type*} {f : ι → E → F} {u : Finset ι} {i : ℕ} (h : ∀ j ∈ u, ContDiff 𝕜 i (f j)) : iteratedFDeriv 𝕜 i (∑ j ∈ u, f j ·) = ∑ j ∈ u, iteratedFDeriv 𝕜 i (f j) := funext fun x ↩ by simpa [iteratedFDerivWithin_univ] using iteratedFDerivWithin_sum_apply uniqueDiffOn_univ (mem_univ x) fun j hj ↩ (h j hj).contDiffOn /-! ### Product of two functions -/ section MulProd variable {𝔞 𝔞' ι 𝕜' : Type*} [NormedRing 𝔞] [NormedAlgebra 𝕜 𝔞] [NormedCommRing 𝔞'] [NormedAlgebra 𝕜 𝔞'] [NormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] -- The product is smooth. theorem contDiff_mul : ContDiff 𝕜 n fun p : 𝔞 × 𝔞 => p.1 * p.2 := (ContinuousLinearMap.mul 𝕜 𝔞).isBoundedBilinearMap.contDiff /-- The product of two `C^n` functions within a set at a point is `C^n` within this set at this point. -/ theorem ContDiffWithinAt.mul {s : Set E} {f g : E → 𝔞} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x => f x * g x) s x := contDiff_mul.comp_contDiffWithinAt (hf.prod hg) /-- The product of two `C^n` functions at a point is `C^n` at this point. -/ nonrec theorem ContDiffAt.mul {f g : E → 𝔞} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => f x * g x) x := hf.mul hg /-- The product of two `C^n` functions on a domain is `C^n`. -/ theorem ContDiffOn.mul {f g : E → 𝔞} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => f x * g x) s := fun x hx => (hf x hx).mul (hg x hx) /-- The product of two `C^n`functions is `C^n`. -/ theorem ContDiff.mul {f g : E → 𝔞} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => f x * g x := contDiff_mul.comp (hf.prod hg) theorem contDiffWithinAt_prod' {t : Finset ι} {f : ι → E → 𝔞'} (h : ∀ i ∈ t, ContDiffWithinAt 𝕜 n (f i) s x) : ContDiffWithinAt 𝕜 n (∏ i ∈ t, f i) s x := Finset.prod_induction f (fun f => ContDiffWithinAt 𝕜 n f s x) (fun _ _ => ContDiffWithinAt.mul) (contDiffWithinAt_const (c := 1)) h theorem contDiffWithinAt_prod {t : Finset ι} {f : ι → E → 𝔞'} (h : ∀ i ∈ t, ContDiffWithinAt 𝕜 n (f i) s x) : ContDiffWithinAt 𝕜 n (fun y => ∏ i ∈ t, f i y) s x := by simpa only [← Finset.prod_apply] using contDiffWithinAt_prod' h theorem contDiffAt_prod' {t : Finset ι} {f : ι → E → 𝔞'} (h : ∀ i ∈ t, ContDiffAt 𝕜 n (f i) x) : ContDiffAt 𝕜 n (∏ i ∈ t, f i) x := contDiffWithinAt_prod' h theorem contDiffAt_prod {t : Finset ι} {f : ι → E → 𝔞'} (h : ∀ i ∈ t, ContDiffAt 𝕜 n (f i) x) : ContDiffAt 𝕜 n (fun y => ∏ i ∈ t, f i y) x := contDiffWithinAt_prod h theorem contDiffOn_prod' {t : Finset ι} {f : ι → E → 𝔞'} (h : ∀ i ∈ t, ContDiffOn 𝕜 n (f i) s) : ContDiffOn 𝕜 n (∏ i ∈ t, f i) s := fun x hx => contDiffWithinAt_prod' fun i hi => h i hi x hx theorem contDiffOn_prod {t : Finset ι} {f : ι → E → 𝔞'} (h : ∀ i ∈ t, ContDiffOn 𝕜 n (f i) s) : ContDiffOn 𝕜 n (fun y => ∏ i ∈ t, f i y) s := fun x hx => contDiffWithinAt_prod fun i hi => h i hi x hx theorem contDiff_prod' {t : Finset ι} {f : ι → E → 𝔞'} (h : ∀ i ∈ t, ContDiff 𝕜 n (f i)) : ContDiff 𝕜 n (∏ i ∈ t, f i) := contDiff_iff_contDiffAt.mpr fun _ => contDiffAt_prod' fun i hi => (h i hi).contDiffAt theorem contDiff_prod {t : Finset ι} {f : ι → E → 𝔞'} (h : ∀ i ∈ t, ContDiff 𝕜 n (f i)) : ContDiff 𝕜 n fun y => ∏ i ∈ t, f i y := contDiff_iff_contDiffAt.mpr fun _ => contDiffAt_prod fun i hi => (h i hi).contDiffAt theorem ContDiff.pow {f : E → 𝔞} (hf : ContDiff 𝕜 n f) : ∀ m : ℕ, ContDiff 𝕜 n fun x => f x ^ m | 0 => by simpa using contDiff_const | m + 1 => by simpa [pow_succ] using (hf.pow m).mul hf theorem ContDiffWithinAt.pow {f : E → 𝔞} (hf : ContDiffWithinAt 𝕜 n f s x) (m : ℕ) : ContDiffWithinAt 𝕜 n (fun y => f y ^ m) s x := (contDiff_id.pow m).comp_contDiffWithinAt hf nonrec theorem ContDiffAt.pow {f : E → 𝔞} (hf : ContDiffAt 𝕜 n f x) (m : ℕ) : ContDiffAt 𝕜 n (fun y => f y ^ m) x := hf.pow m theorem ContDiffOn.pow {f : E → 𝔞} (hf : ContDiffOn 𝕜 n f s) (m : ℕ) : ContDiffOn 𝕜 n (fun y => f y ^ m) s := fun y hy => (hf y hy).pow m theorem ContDiffWithinAt.div_const {f : E → 𝕜'} {n} (hf : ContDiffWithinAt 𝕜 n f s x) (c : 𝕜') : ContDiffWithinAt 𝕜 n (fun x => f x / c) s x := by simpa only [div_eq_mul_inv] using hf.mul contDiffWithinAt_const nonrec theorem ContDiffAt.div_const {f : E → 𝕜'} {n} (hf : ContDiffAt 𝕜 n f x) (c : 𝕜') : ContDiffAt 𝕜 n (fun x => f x / c) x := hf.div_const c theorem ContDiffOn.div_const {f : E → 𝕜'} {n} (hf : ContDiffOn 𝕜 n f s) (c : 𝕜') : ContDiffOn 𝕜 n (fun x => f x / c) s := fun x hx => (hf x hx).div_const c theorem ContDiff.div_const {f : E → 𝕜'} {n} (hf : ContDiff 𝕜 n f) (c : 𝕜') : ContDiff 𝕜 n fun x => f x / c := by simpa only [div_eq_mul_inv] using hf.mul contDiff_const end MulProd /-! ### Scalar multiplication -/ section SMul -- The scalar multiplication is smooth. theorem contDiff_smul : ContDiff 𝕜 n fun p : 𝕜 × F => p.1 • p.2 := isBoundedBilinearMap_smul.contDiff /-- The scalar multiplication of two `C^n` functions within a set at a point is `C^n` within this set at this point. -/ theorem ContDiffWithinAt.smul {s : Set E} {f : E → 𝕜} {g : E → F} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) : ContDiffWithinAt 𝕜 n (fun x => f x • g x) s x := contDiff_smul.contDiffWithinAt.comp x (hf.prod hg) subset_preimage_univ /-- The scalar multiplication of two `C^n` functions at a point is `C^n` at this point. -/ theorem ContDiffAt.smul {f : E → 𝕜} {g : E → F} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => f x • g x) x := by rw [← contDiffWithinAt_univ] at *; exact hf.smul hg /-- The scalar multiplication of two `C^n` functions is `C^n`. -/ theorem ContDiff.smul {f : E → 𝕜} {g : E → F} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => f x • g x := contDiff_smul.comp (hf.prod hg) /-- The scalar multiplication of two `C^n` functions on a domain is `C^n`. -/ theorem ContDiffOn.smul {s : Set E} {f : E → 𝕜} {g : E → F} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => f x • g x) s := fun x hx => (hf x hx).smul (hg x hx) end SMul /-! ### Constant scalar multiplication Porting note (#11215): TODO: generalize results in this section. 1. It should be possible to assume `[Monoid R] [DistribMulAction R F] [SMulCommClass 𝕜 R F]`. 2. If `c` is a unit (or `R` is a group), then one can drop `ContDiff*` assumptions in some lemmas. -/ section ConstSMul variable {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] variable [ContinuousConstSMul R F] -- The scalar multiplication with a constant is smooth. theorem contDiff_const_smul (c : R) : ContDiff 𝕜 n fun p : F => c • p := (c • ContinuousLinearMap.id 𝕜 F).contDiff /-- The scalar multiplication of a constant and a `C^n` function within a set at a point is `C^n` within this set at this point. -/ theorem ContDiffWithinAt.const_smul {s : Set E} {f : E → F} {x : E} (c : R) (hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (fun y => c • f y) s x := (contDiff_const_smul c).contDiffAt.comp_contDiffWithinAt x hf /-- The scalar multiplication of a constant and a `C^n` function at a point is `C^n` at this point. -/ theorem ContDiffAt.const_smul {f : E → F} {x : E} (c : R) (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (fun y => c • f y) x := by rw [← contDiffWithinAt_univ] at *; exact hf.const_smul c /-- The scalar multiplication of a constant and a `C^n` function is `C^n`. -/ theorem ContDiff.const_smul {f : E → F} (c : R) (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun y => c • f y := (contDiff_const_smul c).comp hf /-- The scalar multiplication of a constant and a `C^n` on a domain is `C^n`. -/ theorem ContDiffOn.const_smul {s : Set E} {f : E → F} (c : R) (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (fun y => c • f y) s := fun x hx => (hf x hx).const_smul c variable {i : ℕ} {a : R} theorem iteratedFDerivWithin_const_smul_apply (hf : ContDiffOn 𝕜 i f s) (hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 i (a • f) s x = a • iteratedFDerivWithin 𝕜 i f s x := (a • (1 : F →L[𝕜] F)).iteratedFDerivWithin_comp_left hf hu hx le_rfl theorem iteratedFDeriv_const_smul_apply {x : E} (hf : ContDiff 𝕜 i f) : iteratedFDeriv 𝕜 i (a • f) x = a • iteratedFDeriv 𝕜 i f x := by simp_rw [← contDiffOn_univ, ← iteratedFDerivWithin_univ] at * exact iteratedFDerivWithin_const_smul_apply hf uniqueDiffOn_univ (Set.mem_univ _) theorem iteratedFDeriv_const_smul_apply' {x : E} (hf : ContDiff 𝕜 i f) : iteratedFDeriv 𝕜 i (fun x ↩ a • f x) x = a • iteratedFDeriv 𝕜 i f x := iteratedFDeriv_const_smul_apply hf end ConstSMul /-! ### Cartesian product of two functions -/ section prodMap variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] variable {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ theorem ContDiffWithinAt.prod_map' {s : Set E} {t : Set E'} {f : E → F} {g : E' → F'} {p : E × E'} (hf : ContDiffWithinAt 𝕜 n f s p.1) (hg : ContDiffWithinAt 𝕜 n g t p.2) : ContDiffWithinAt 𝕜 n (Prod.map f g) (s ×ˢ t) p := (hf.comp p contDiffWithinAt_fst (prod_subset_preimage_fst _ _)).prod (hg.comp p contDiffWithinAt_snd (prod_subset_preimage_snd _ _)) theorem ContDiffWithinAt.prod_map {s : Set E} {t : Set E'} {f : E → F} {g : E' → F'} {x : E} {y : E'} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g t y) : ContDiffWithinAt 𝕜 n (Prod.map f g) (s ×ˢ t) (x, y) := ContDiffWithinAt.prod_map' hf hg /-- The product map of two `C^n` functions on a set is `C^n` on the product set. -/ theorem ContDiffOn.prod_map {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {s : Set E} {t : Set E'} {f : E → F} {g : E' → F'} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g t) : ContDiffOn 𝕜 n (Prod.map f g) (s ×ˢ t) := (hf.comp contDiffOn_fst (prod_subset_preimage_fst _ _)).prod (hg.comp contDiffOn_snd (prod_subset_preimage_snd _ _)) /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ theorem ContDiffAt.prod_map {f : E → F} {g : E' → F'} {x : E} {y : E'} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g y) : ContDiffAt 𝕜 n (Prod.map f g) (x, y) := by rw [ContDiffAt] at * convert hf.prod_map hg simp only [univ_prod_univ] /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ theorem ContDiffAt.prod_map' {f : E → F} {g : E' → F'} {p : E × E'} (hf : ContDiffAt 𝕜 n f p.1) (hg : ContDiffAt 𝕜 n g p.2) : ContDiffAt 𝕜 n (Prod.map f g) p := by rcases p with ⟚⟩ exact ContDiffAt.prod_map hf hg /-- The product map of two `C^n` functions is `C^n`. -/ theorem ContDiff.prod_map {f : E → F} {g : E' → F'} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n (Prod.map f g) := by rw [contDiff_iff_contDiffAt] at * exact fun ⟹x, y⟩ => (hf x).prod_map (hg y) theorem contDiff_prod_mk_left (f₀ : F) : ContDiff 𝕜 n fun e : E => (e, f₀) := contDiff_id.prod contDiff_const theorem contDiff_prod_mk_right (e₀ : E) : ContDiff 𝕜 n fun f : F => (e₀, f) := contDiff_const.prod contDiff_id end prodMap /-! ### Inversion in a complete normed algebra -/ section AlgebraInverse variable (𝕜) {R : Type*} [NormedRing R] -- Porting note: this couldn't be on the same line as the binder type update of `𝕜` variable [NormedAlgebra 𝕜 R] open NormedRing ContinuousLinearMap Ring /-- In a complete normed algebra, the operation of inversion is `C^n`, for all `n`, at each invertible element. The proof is by induction, bootstrapping using an identity expressing the derivative of inversion as a bilinear map of inversion itself. -/ theorem contDiffAt_ring_inverse [CompleteSpace R] (x : RË£) : ContDiffAt 𝕜 n Ring.inverse (x : R) := by induction' n using ENat.nat_induction with n IH Itop · intro m hm refine ⟹{ y : R | IsUnit y }, ?_, ?_⟩ · simpa [nhdsWithin_univ] using x.nhds · use ftaylorSeriesWithin 𝕜 inverse univ rw [le_antisymm hm bot_le, hasFTaylorSeriesUpToOn_zero_iff] constructor · rintro _ ⟹x', rfl⟩ exact (inverse_continuousAt x').continuousWithinAt · simp [ftaylorSeriesWithin] · rw [contDiffAt_succ_iff_hasFDerivAt] refine ⟹fun x : R => -mulLeftRight 𝕜 R (inverse x) (inverse x), ?_, ?_⟩ · refine ⟹{ y : R | IsUnit y }, x.nhds, ?_⟩ rintro _ ⟹y, rfl⟩ simp_rw [inverse_unit] exact hasFDerivAt_ring_inverse y · convert (mulLeftRight_isBoundedBilinear 𝕜 R).contDiff.neg.comp_contDiffAt (x : R) (IH.prod IH) · exact contDiffAt_top.mpr Itop variable {𝕜' : Type*} [NormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [CompleteSpace 𝕜'] theorem contDiffAt_inv {x : 𝕜'} (hx : x ≠ 0) {n} : ContDiffAt 𝕜 n Inv.inv x := by simpa only [Ring.inverse_eq_inv'] using contDiffAt_ring_inverse 𝕜 (Units.mk0 x hx) theorem contDiffOn_inv {n} : ContDiffOn 𝕜 n (Inv.inv : 𝕜' → 𝕜') {0}ᶜ := fun _ hx => (contDiffAt_inv 𝕜 hx).contDiffWithinAt variable {𝕜} -- TODO: the next few lemmas don't need `𝕜` or `𝕜'` to be complete -- A good way to show this is to generalize `contDiffAt_ring_inverse` to the setting -- of a function `f` such that `∀ᶠ x in 𝓝 a, x * f x = 1`. theorem ContDiffWithinAt.inv {f : E → 𝕜'} {n} (hf : ContDiffWithinAt 𝕜 n f s x) (hx : f x ≠ 0) : ContDiffWithinAt 𝕜 n (fun x => (f x)⁻¹) s x := (contDiffAt_inv 𝕜 hx).comp_contDiffWithinAt x hf theorem ContDiffOn.inv {f : E → 𝕜'} {n} (hf : ContDiffOn 𝕜 n f s) (h : ∀ x ∈ s, f x ≠ 0) : ContDiffOn 𝕜 n (fun x => (f x)⁻¹) s := fun x hx => (hf.contDiffWithinAt hx).inv (h x hx) nonrec theorem ContDiffAt.inv {f : E → 𝕜'} {n} (hf : ContDiffAt 𝕜 n f x) (hx : f x ≠ 0) : ContDiffAt 𝕜 n (fun x => (f x)⁻¹) x := hf.inv hx theorem ContDiff.inv {f : E → 𝕜'} {n} (hf : ContDiff 𝕜 n f) (h : ∀ x, f x ≠ 0) : ContDiff 𝕜 n fun x => (f x)⁻¹ := by rw [contDiff_iff_contDiffAt]; exact fun x => hf.contDiffAt.inv (h x) -- TODO: generalize to `f g : E → 𝕜'` theorem ContDiffWithinAt.div [CompleteSpace 𝕜] {f g : E → 𝕜} {n} (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) (hx : g x ≠ 0) : ContDiffWithinAt 𝕜 n (fun x => f x / g x) s x := by simpa only [div_eq_mul_inv] using hf.mul (hg.inv hx) theorem ContDiffOn.div [CompleteSpace 𝕜] {f g : E → 𝕜} {n} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) (h₀ : ∀ x ∈ s, g x ≠ 0) : ContDiffOn 𝕜 n (f / g) s := fun x hx => (hf x hx).div (hg x hx) (h₀ x hx) nonrec theorem ContDiffAt.div [CompleteSpace 𝕜] {f g : E → 𝕜} {n} (hf : ContDiffAt 𝕜 n f x) (hg : ContDiffAt 𝕜 n g x) (hx : g x ≠ 0) : ContDiffAt 𝕜 n (fun x => f x / g x) x := hf.div hg hx theorem ContDiff.div [CompleteSpace 𝕜] {f g : E → 𝕜} {n} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) (h0 : ∀ x, g x ≠ 0) : ContDiff 𝕜 n fun x => f x / g x := by simp only [contDiff_iff_contDiffAt] at * exact fun x => (hf x).div (hg x) (h0 x) end AlgebraInverse /-! ### Inversion of continuous linear maps between Banach spaces -/ section MapInverse open ContinuousLinearMap /-- At a continuous linear equivalence `e : E ≃L[𝕜] F` between Banach spaces, the operation of inversion is `C^n`, for all `n`. -/ theorem contDiffAt_map_inverse [CompleteSpace E] (e : E ≃L[𝕜] F) : ContDiffAt 𝕜 n inverse (e : E →L[𝕜] F) := by nontriviality E -- first, we use the lemma `to_ring_inverse` to rewrite in terms of `Ring.inverse` in the ring -- `E →L[𝕜] E` let O₁ : (E →L[𝕜] E) → F →L[𝕜] E := fun f => f.comp (e.symm : F →L[𝕜] E) let O₂ : (E →L[𝕜] F) → E →L[𝕜] E := fun f => (e.symm : F →L[𝕜] E).comp f have : ContinuousLinearMap.inverse = O₁ ∘ Ring.inverse ∘ O₂ := funext (to_ring_inverse e) rw [this] -- `O₁` and `O₂` are `ContDiff`, -- so we reduce to proving that `Ring.inverse` is `ContDiff` have h₁ : ContDiff 𝕜 n O₁ := contDiff_id.clm_comp contDiff_const have h₂ : ContDiff 𝕜 n O₂ := contDiff_const.clm_comp contDiff_id refine h₁.contDiffAt.comp _ (ContDiffAt.comp _ ?_ h₂.contDiffAt) convert contDiffAt_ring_inverse 𝕜 (1 : (E →L[𝕜] E)Ë£) simp [O₂, one_def] end MapInverse section FunctionInverse open ContinuousLinearMap /-- If `f` is a local homeomorphism and the point `a` is in its target, and if `f` is `n` times continuously differentiable at `f.symm a`, and if the derivative at `f.symm a` is a continuous linear equivalence, then `f.symm` is `n` times continuously differentiable at the point `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem PartialHomeomorph.contDiffAt_symm [CompleteSpace E] (f : PartialHomeomorph E F) {f₀' : E ≃L[𝕜] F} {a : F} (ha : a ∈ f.target) (hf₀' : HasFDerivAt f (f₀' : E →L[𝕜] F) (f.symm a)) (hf : ContDiffAt 𝕜 n f (f.symm a)) : ContDiffAt 𝕜 n f.symm a := by -- We prove this by induction on `n` induction' n using ENat.nat_induction with n IH Itop · rw [contDiffAt_zero] exact ⟹f.target, IsOpen.mem_nhds f.open_target ha, f.continuousOn_invFun⟩ · obtain ⟹f', ⟹u, hu, hff'⟩, hf'⟩ := contDiffAt_succ_iff_hasFDerivAt.mp hf rw [contDiffAt_succ_iff_hasFDerivAt] -- For showing `n.succ` times continuous differentiability (the main inductive step), it -- suffices to produce the derivative and show that it is `n` times continuously differentiable have eq_f₀' : f' (f.symm a) = f₀' := (hff' (f.symm a) (mem_of_mem_nhds hu)).unique hf₀' -- This follows by a bootstrapping formula expressing the derivative as a function of `f` itself refine ⟹inverse ∘ f' ∘ f.symm, ?_, ?_⟩ · -- We first check that the derivative of `f` is that formula have h_nhds : { y : E | ∃ e : E ≃L[𝕜] F, ↑e = f' y } ∈ 𝓝 (f.symm a) := by have hf₀' := f₀'.nhds rw [← eq_f₀'] at hf₀' exact hf'.continuousAt.preimage_mem_nhds hf₀' obtain ⟹t, htu, ht, htf⟩ := mem_nhds_iff.mp (Filter.inter_mem hu h_nhds) use f.target ∩ f.symm ⁻¹' t refine ⟹IsOpen.mem_nhds ?_ ?_, ?_⟩ · exact f.isOpen_inter_preimage_symm ht · exact mem_inter ha (mem_preimage.mpr htf) intro x hx obtain ⟹hxu, e, he⟩ := htu hx.2 have h_deriv : HasFDerivAt f (e : E →L[𝕜] F) (f.symm x) := by rw [he] exact hff' (f.symm x) hxu convert f.hasFDerivAt_symm hx.1 h_deriv simp [← he] · -- Then we check that the formula, being a composition of `ContDiff` pieces, is -- itself `ContDiff` have h_deriv₁ : ContDiffAt 𝕜 n inverse (f' (f.symm a)) := by rw [eq_f₀'] exact contDiffAt_map_inverse _ have h_deriv₂ : ContDiffAt 𝕜 n f.symm a := by refine IH (hf.of_le ?_) norm_cast exact Nat.le_succ n exact (h_deriv₁.comp _ hf').comp _ h_deriv₂ · refine contDiffAt_top.mpr ?_ intro n exact Itop n (contDiffAt_top.mp hf n) /-- If `f` is an `n` times continuously differentiable homeomorphism, and if the derivative of `f` at each point is a continuous linear equivalence, then `f.symm` is `n` times continuously differentiable. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem Homeomorph.contDiff_symm [CompleteSpace E] (f : E ≃ₜ F) {f₀' : E → E ≃L[𝕜] F} (hf₀' : ∀ a, HasFDerivAt f (f₀' a : E →L[𝕜] F) a) (hf : ContDiff 𝕜 n (f : E → F)) : ContDiff 𝕜 n (f.symm : F → E) := contDiff_iff_contDiffAt.2 fun x => f.toPartialHomeomorph.contDiffAt_symm (mem_univ x) (hf₀' _) hf.contDiffAt /-- Let `f` be a local homeomorphism of a nontrivially normed field, let `a` be a point in its target. if `f` is `n` times continuously differentiable at `f.symm a`, and if the derivative at `f.symm a` is nonzero, then `f.symm` is `n` times continuously differentiable at the point `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem PartialHomeomorph.contDiffAt_symm_deriv [CompleteSpace 𝕜] (f : PartialHomeomorph 𝕜 𝕜) {f₀' a : 𝕜} (h₀ : f₀' ≠ 0) (ha : a ∈ f.target) (hf₀' : HasDerivAt f f₀' (f.symm a)) (hf : ContDiffAt 𝕜 n f (f.symm a)) : ContDiffAt 𝕜 n f.symm a := f.contDiffAt_symm ha (hf₀'.hasFDerivAt_equiv h₀) hf /-- Let `f` be an `n` times continuously differentiable homeomorphism of a nontrivially normed field. Suppose that the derivative of `f` is never equal to zero. Then `f.symm` is `n` times continuously differentiable. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem Homeomorph.contDiff_symm_deriv [CompleteSpace 𝕜] (f : 𝕜 ≃ₜ 𝕜) {f' : 𝕜 → 𝕜} (h₀ : ∀ x, f' x ≠ 0) (hf' : ∀ x, HasDerivAt f (f' x) x) (hf : ContDiff 𝕜 n (f : 𝕜 → 𝕜)) : ContDiff 𝕜 n (f.symm : 𝕜 → 𝕜) := contDiff_iff_contDiffAt.2 fun x => f.toPartialHomeomorph.contDiffAt_symm_deriv (h₀ _) (mem_univ x) (hf' _) hf.contDiffAt namespace PartialHomeomorph variable (𝕜) /-- Restrict a partial homeomorphism to the subsets of the source and target that consist of points `x ∈ f.source`, `y = f x ∈ f.target` such that `f` is `C^n` at `x` and `f.symm` is `C^n` at `y`. Note that `n` is a natural number, not `∞`, because the set of points of `C^∞`-smoothness of `f` is not guaranteed to be open. -/ @[simps! apply symm_apply source target] def restrContDiff (f : PartialHomeomorph E F) (n : ℕ) : PartialHomeomorph E F := haveI H : f.IsImage {x | ContDiffAt 𝕜 n f x ∧ ContDiffAt 𝕜 n f.symm (f x)} {y | ContDiffAt 𝕜 n f.symm y ∧ ContDiffAt 𝕜 n f (f.symm y)} := fun x hx ↩ by simp [hx, and_comm] H.restr <| isOpen_iff_mem_nhds.2 fun x ⟹hxs, hxf, hxf'⟩ ↩ inter_mem (f.open_source.mem_nhds hxs) <| hxf.eventually.and <| f.continuousAt hxs hxf'.eventually lemma contDiffOn_restrContDiff_source (f : PartialHomeomorph E F) (n : ℕ) : ContDiffOn 𝕜 n f (f.restrContDiff 𝕜 n).source := fun _x hx ↩ hx.2.1.contDiffWithinAt lemma contDiffOn_restrContDiff_target (f : PartialHomeomorph E F) (n : ℕ) : ContDiffOn 𝕜 n f.symm (f.restrContDiff 𝕜 n).target := fun _x hx ↩ hx.2.1.contDiffWithinAt end PartialHomeomorph end FunctionInverse section deriv /-! ### One dimension All results up to now have been expressed in terms of the general Fréchet derivative `fderiv`. For maps defined on the field, the one-dimensional derivative `deriv` is often easier to use. In this paragraph, we reformulate some higher smoothness results in terms of `deriv`. -/ variable {f₂ : 𝕜 → F} {s₂ : Set 𝕜} open ContinuousLinearMap (smulRight) /-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (formulated with `derivWithin`) is `C^n`. -/ theorem contDiffOn_succ_iff_derivWithin {n : ℕ} (hs : UniqueDiffOn 𝕜 s₂) : ContDiffOn 𝕜 (n + 1 : ℕ) f₂ s₂ ↔ DifferentiableOn 𝕜 f₂ s₂ ∧ ContDiffOn 𝕜 n (derivWithin f₂ s₂) s₂ := by rw [contDiffOn_succ_iff_fderivWithin hs, and_congr_right_iff] intro _ constructor · intro h have : derivWithin f₂ s₂ = (fun u : 𝕜 →L[𝕜] F => u 1) ∘ fderivWithin 𝕜 f₂ s₂ := by ext x; rfl simp_rw [this] apply ContDiff.comp_contDiffOn _ h exact (isBoundedBilinearMap_apply.isBoundedLinearMap_left _).contDiff · intro h have : fderivWithin 𝕜 f₂ s₂ = smulRight (1 : 𝕜 →L[𝕜] 𝕜) ∘ derivWithin f₂ s₂ := by ext x; simp [derivWithin] simp only [this] apply ContDiff.comp_contDiffOn _ h have : IsBoundedBilinearMap 𝕜 fun _ : (𝕜 →L[𝕜] 𝕜) × F => _ := isBoundedBilinearMap_smulRight exact (this.isBoundedLinearMap_right _).contDiff /-- A function is `C^(n + 1)` on an open domain if and only if it is differentiable there, and its derivative (formulated with `deriv`) is `C^n`. -/ theorem contDiffOn_succ_iff_deriv_of_isOpen {n : ℕ} (hs : IsOpen s₂) : ContDiffOn 𝕜 (n + 1 : ℕ) f₂ s₂ ↔ DifferentiableOn 𝕜 f₂ s₂ ∧ ContDiffOn 𝕜 n (deriv f₂) s₂ := by rw [contDiffOn_succ_iff_derivWithin hs.uniqueDiffOn] exact Iff.rfl.and (contDiffOn_congr fun _ => derivWithin_of_isOpen hs) /-- A function is `C^∞` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (formulated with `derivWithin`) is `C^∞`. -/ theorem contDiffOn_top_iff_derivWithin (hs : UniqueDiffOn 𝕜 s₂) : ContDiffOn 𝕜 ∞ f₂ s₂ ↔ DifferentiableOn 𝕜 f₂ s₂ ∧ ContDiffOn 𝕜 ∞ (derivWithin f₂ s₂) s₂ := by constructor · intro h refine ⟹h.differentiableOn le_top, ?_⟩ refine contDiffOn_top.2 fun n => ((contDiffOn_succ_iff_derivWithin hs).1 ?_).2 exact h.of_le le_top · intro h refine contDiffOn_top.2 fun n => ?_ have A : (n : ℕ∞) ≀ ∞ := le_top apply ((contDiffOn_succ_iff_derivWithin hs).2 ⟹h.1, h.2.of_le A⟩).of_le exact WithTop.coe_le_coe.2 (Nat.le_succ n) /-- A function is `C^∞` on an open domain if and only if it is differentiable there, and its derivative (formulated with `deriv`) is `C^∞`. -/ theorem contDiffOn_top_iff_deriv_of_isOpen (hs : IsOpen s₂) : ContDiffOn 𝕜 ∞ f₂ s₂ ↔ DifferentiableOn 𝕜 f₂ s₂ ∧ ContDiffOn 𝕜 ∞ (deriv f₂) s₂ := by rw [contDiffOn_top_iff_derivWithin hs.uniqueDiffOn] exact Iff.rfl.and <| contDiffOn_congr fun _ => derivWithin_of_isOpen hs protected theorem ContDiffOn.derivWithin (hf : ContDiffOn 𝕜 n f₂ s₂) (hs : UniqueDiffOn 𝕜 s₂) (hmn : m + 1 ≀ n) : ContDiffOn 𝕜 m (derivWithin f₂ s₂) s₂ := by cases m · change ∞ + 1 ≀ n at hmn have : n = ∞ := by simpa using hmn rw [this] at hf exact ((contDiffOn_top_iff_derivWithin hs).1 hf).2 · change (Nat.succ _ : ℕ∞) ≀ n at hmn exact ((contDiffOn_succ_iff_derivWithin hs).1 (hf.of_le hmn)).2 theorem ContDiffOn.deriv_of_isOpen (hf : ContDiffOn 𝕜 n f₂ s₂) (hs : IsOpen s₂) (hmn : m + 1 ≀ n) : ContDiffOn 𝕜 m (deriv f₂) s₂ := (hf.derivWithin hs.uniqueDiffOn hmn).congr fun _ hx => (derivWithin_of_isOpen hs hx).symm theorem ContDiffOn.continuousOn_derivWithin (h : ContDiffOn 𝕜 n f₂ s₂) (hs : UniqueDiffOn 𝕜 s₂) (hn : 1 ≀ n) : ContinuousOn (derivWithin f₂ s₂) s₂ := ((contDiffOn_succ_iff_derivWithin hs).1 (h.of_le hn)).2.continuousOn theorem ContDiffOn.continuousOn_deriv_of_isOpen (h : ContDiffOn 𝕜 n f₂ s₂) (hs : IsOpen s₂) (hn : 1 ≀ n) : ContinuousOn (deriv f₂) s₂ := ((contDiffOn_succ_iff_deriv_of_isOpen hs).1 (h.of_le hn)).2.continuousOn /-- A function is `C^(n + 1)` if and only if it is differentiable, and its derivative (formulated in terms of `deriv`) is `C^n`. -/ theorem contDiff_succ_iff_deriv {n : ℕ} : ContDiff 𝕜 (n + 1 : ℕ) f₂ ↔ Differentiable 𝕜 f₂ ∧ ContDiff 𝕜 n (deriv f₂) := by simp only [← contDiffOn_univ, contDiffOn_succ_iff_deriv_of_isOpen, isOpen_univ, differentiableOn_univ] theorem contDiff_one_iff_deriv : ContDiff 𝕜 1 f₂ ↔ Differentiable 𝕜 f₂ ∧ Continuous (deriv f₂) := contDiff_succ_iff_deriv.trans <| Iff.rfl.and contDiff_zero /-- A function is `C^∞` if and only if it is differentiable, and its derivative (formulated in terms of `deriv`) is `C^∞`. -/ theorem contDiff_top_iff_deriv : ContDiff 𝕜 ∞ f₂ ↔ Differentiable 𝕜 f₂ ∧ ContDiff 𝕜 ∞ (deriv f₂) := by simp only [← contDiffOn_univ, ← differentiableOn_univ, ← derivWithin_univ] rw [contDiffOn_top_iff_derivWithin uniqueDiffOn_univ] theorem ContDiff.continuous_deriv (h : ContDiff 𝕜 n f₂) (hn : 1 ≀ n) : Continuous (deriv f₂) := (contDiff_succ_iff_deriv.mp (h.of_le hn)).2.continuous theorem ContDiff.iterate_deriv : ∀ (n : ℕ) {f₂ : 𝕜 → F}, ContDiff 𝕜 ∞ f₂ → ContDiff 𝕜 ∞ (deriv^[n] f₂) | 0, _, hf => hf | n + 1, _, hf => ContDiff.iterate_deriv n (contDiff_top_iff_deriv.mp hf).2 theorem ContDiff.iterate_deriv' (n : ℕ) : ∀ (k : ℕ) {f₂ : 𝕜 → F}, ContDiff 𝕜 (n + k : ℕ) f₂ → ContDiff 𝕜 n (deriv^[k] f₂) | 0, _, hf => hf | k + 1, _, hf => ContDiff.iterate_deriv' _ k (contDiff_succ_iff_deriv.mp hf).2 end deriv section RestrictScalars /-! ### Restricting from `ℂ` to `ℝ`, or generally from `𝕜'` to `𝕜` If a function is `n` times continuously differentiable over `ℂ`, then it is `n` times continuously 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 `𝕜`. -/ variable (𝕜) {𝕜' : Type*} [NontriviallyNormedField 𝕜'] -- Porting note: this couldn't be on the same line as the binder type update of `𝕜` variable [NormedAlgebra 𝕜 𝕜'] variable [NormedSpace 𝕜' E] [IsScalarTower 𝕜 𝕜' E] variable [NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] variable {p' : E → FormalMultilinearSeries 𝕜' E F} theorem HasFTaylorSeriesUpToOn.restrictScalars (h : HasFTaylorSeriesUpToOn n f p' s) : HasFTaylorSeriesUpToOn n f (fun x => (p' x).restrictScalars 𝕜) s where zero_eq x hx := h.zero_eq x hx fderivWithin m hm x hx := by simpa only using -- Porting note: added `by simpa only using` (ContinuousMultilinearMap.restrictScalarsLinear 𝕜).hasFDerivAt.comp_hasFDerivWithinAt x <| (h.fderivWithin m hm x hx).restrictScalars 𝕜 cont m hm := ContinuousMultilinearMap.continuous_restrictScalars.comp_continuousOn (h.cont m hm) theorem ContDiffWithinAt.restrict_scalars (h : ContDiffWithinAt 𝕜' n f s x) : ContDiffWithinAt 𝕜 n f s x := fun m hm ↩ by rcases h m hm with ⟹u, u_mem, p', hp'⟩ exact ⟹u, u_mem, _, hp'.restrictScalars _⟩ theorem ContDiffOn.restrict_scalars (h : ContDiffOn 𝕜' n f s) : ContDiffOn 𝕜 n f s := fun x hx => (h x hx).restrict_scalars _ theorem ContDiffAt.restrict_scalars (h : ContDiffAt 𝕜' n f x) : ContDiffAt 𝕜 n f x := contDiffWithinAt_univ.1 <| h.contDiffWithinAt.restrict_scalars _ theorem ContDiff.restrict_scalars (h : ContDiff 𝕜' n f) : ContDiff 𝕜 n f := contDiff_iff_contDiffAt.2 fun _ => h.contDiffAt.restrict_scalars _ end RestrictScalars
Analysis\Calculus\ContDiff\Bounds.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Data.Finset.Sym import Mathlib.Data.Nat.Choose.Cast import Mathlib.Data.Nat.Choose.Multinomial /-! # Bounds on higher derivatives `norm_iteratedFDeriv_comp_le` gives the bound `n! * C * D ^ n` for the `n`-th derivative of `g ∘ f` assuming that the derivatives of `g` are bounded by `C` and the `i`-th derivative of `f` is bounded by `D ^ i`. -/ noncomputable section open scoped NNReal Nat universe u uD uE uF uG open Set Fin Filter Function variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {D : Type uD} [NormedAddCommGroup D] [NormedSpace 𝕜 D] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {s s₁ t u : Set E} /-!## Quantitative bounds -/ /-- Bounding the norm of the iterated derivative of `B (f x) (g x)` within a set in terms of the iterated derivatives of `f` and `g` when `B` is bilinear. This lemma is an auxiliary version assuming all spaces live in the same universe, to enable an induction. Use instead `ContinuousLinearMap.norm_iteratedFDerivWithin_le_of_bilinear` that removes this assumption. -/ theorem ContinuousLinearMap.norm_iteratedFDerivWithin_le_of_bilinear_aux {Du Eu Fu Gu : Type u} [NormedAddCommGroup Du] [NormedSpace 𝕜 Du] [NormedAddCommGroup Eu] [NormedSpace 𝕜 Eu] [NormedAddCommGroup Fu] [NormedSpace 𝕜 Fu] [NormedAddCommGroup Gu] [NormedSpace 𝕜 Gu] (B : Eu →L[𝕜] Fu →L[𝕜] Gu) {f : Du → Eu} {g : Du → Fu} {n : ℕ} {s : Set Du} {x : Du} (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : ‖iteratedFDerivWithin 𝕜 n (fun y => B (f y) (g y)) s x‖ ≀ ‖B‖ * ∑ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * ‖iteratedFDerivWithin 𝕜 i f s x‖ * ‖iteratedFDerivWithin 𝕜 (n - i) g s x‖ := by /- We argue by induction on `n`. The bound is trivial for `n = 0`. For `n + 1`, we write the `(n+1)`-th derivative as the `n`-th derivative of the derivative `B f g' + B f' g`, and apply the inductive assumption to each of those two terms. For this induction to make sense, the spaces of linear maps that appear in the induction should be in the same universe as the original spaces, which explains why we assume in the lemma that all spaces live in the same universe. -/ induction' n with n IH generalizing Eu Fu Gu · simp only [Nat.zero_eq, norm_iteratedFDerivWithin_zero, zero_add, Finset.range_one, Finset.sum_singleton, Nat.choose_self, Nat.cast_one, one_mul, Nat.sub_zero, ← mul_assoc] apply B.le_opNorm₂ · have In : (n : ℕ∞) + 1 ≀ n.succ := by simp only [Nat.cast_succ, le_refl] -- Porting note: the next line is a hack allowing Lean to find the operator norm instance. let norm := @ContinuousLinearMap.hasOpNorm _ _ Eu ((Du →L[𝕜] Fu) →L[𝕜] Du →L[𝕜] Gu) _ _ _ _ _ _ (RingHom.id 𝕜) have I1 : ‖iteratedFDerivWithin 𝕜 n (fun y : Du => B.precompR Du (f y) (fderivWithin 𝕜 g s y)) s x‖ ≀ ‖B‖ * ∑ i ∈ Finset.range (n + 1), n.choose i * ‖iteratedFDerivWithin 𝕜 i f s x‖ * ‖iteratedFDerivWithin 𝕜 (n + 1 - i) g s x‖ := by calc ‖iteratedFDerivWithin 𝕜 n (fun y : Du => B.precompR Du (f y) (fderivWithin 𝕜 g s y)) s x‖ ≀ ‖B.precompR Du‖ * ∑ i ∈ Finset.range (n + 1), n.choose i * ‖iteratedFDerivWithin 𝕜 i f s x‖ * ‖iteratedFDerivWithin 𝕜 (n - i) (fderivWithin 𝕜 g s) s x‖ := IH _ (hf.of_le (Nat.cast_le.2 (Nat.le_succ n))) (hg.fderivWithin hs In) _ ≀ ‖B‖ * ∑ i ∈ Finset.range (n + 1), n.choose i * ‖iteratedFDerivWithin 𝕜 i f s x‖ * ‖iteratedFDerivWithin 𝕜 (n - i) (fderivWithin 𝕜 g s) s x‖ := mul_le_mul_of_nonneg_right (B.norm_precompR_le Du) (by positivity) _ = _ := by congr 1 apply Finset.sum_congr rfl fun i hi => ?_ rw [Nat.succ_sub (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)), ← norm_iteratedFDerivWithin_fderivWithin hs hx] -- Porting note: the next line is a hack allowing Lean to find the operator norm instance. let norm := @ContinuousLinearMap.hasOpNorm _ _ (Du →L[𝕜] Eu) (Fu →L[𝕜] Du →L[𝕜] Gu) _ _ _ _ _ _ (RingHom.id 𝕜) have I2 : ‖iteratedFDerivWithin 𝕜 n (fun y : Du => B.precompL Du (fderivWithin 𝕜 f s y) (g y)) s x‖ ≀ ‖B‖ * ∑ i ∈ Finset.range (n + 1), n.choose i * ‖iteratedFDerivWithin 𝕜 (i + 1) f s x‖ * ‖iteratedFDerivWithin 𝕜 (n - i) g s x‖ := calc ‖iteratedFDerivWithin 𝕜 n (fun y : Du => B.precompL Du (fderivWithin 𝕜 f s y) (g y)) s x‖ ≀ ‖B.precompL Du‖ * ∑ i ∈ Finset.range (n + 1), n.choose i * ‖iteratedFDerivWithin 𝕜 i (fderivWithin 𝕜 f s) s x‖ * ‖iteratedFDerivWithin 𝕜 (n - i) g s x‖ := IH _ (hf.fderivWithin hs In) (hg.of_le (Nat.cast_le.2 (Nat.le_succ n))) _ ≀ ‖B‖ * ∑ i ∈ Finset.range (n + 1), n.choose i * ‖iteratedFDerivWithin 𝕜 i (fderivWithin 𝕜 f s) s x‖ * ‖iteratedFDerivWithin 𝕜 (n - i) g s x‖ := mul_le_mul_of_nonneg_right (B.norm_precompL_le Du) (by positivity) _ = _ := by congr 1 apply Finset.sum_congr rfl fun i _ => ?_ rw [← norm_iteratedFDerivWithin_fderivWithin hs hx] have J : iteratedFDerivWithin 𝕜 n (fun y : Du => fderivWithin 𝕜 (fun y : Du => B (f y) (g y)) s y) s x = iteratedFDerivWithin 𝕜 n (fun y => B.precompR Du (f y) (fderivWithin 𝕜 g s y) + B.precompL Du (fderivWithin 𝕜 f s y) (g y)) s x := by apply iteratedFDerivWithin_congr (fun y hy => ?_) hx have L : (1 : ℕ∞) ≀ n.succ := by simpa only [ENat.coe_one, Nat.one_le_cast] using Nat.succ_pos n exact B.fderivWithin_of_bilinear (hf.differentiableOn L y hy) (hg.differentiableOn L y hy) (hs y hy) rw [← norm_iteratedFDerivWithin_fderivWithin hs hx, J] have A : ContDiffOn 𝕜 n (fun y => B.precompR Du (f y) (fderivWithin 𝕜 g s y)) s := (B.precompR Du).isBoundedBilinearMap.contDiff.comp_contDiff_on₂ (hf.of_le (Nat.cast_le.2 (Nat.le_succ n))) (hg.fderivWithin hs In) have A' : ContDiffOn 𝕜 n (fun y => B.precompL Du (fderivWithin 𝕜 f s y) (g y)) s := (B.precompL Du).isBoundedBilinearMap.contDiff.comp_contDiff_on₂ (hf.fderivWithin hs In) (hg.of_le (Nat.cast_le.2 (Nat.le_succ n))) rw [iteratedFDerivWithin_add_apply' A A' hs hx] apply (norm_add_le _ _).trans ((add_le_add I1 I2).trans (le_of_eq ?_)) simp_rw [← mul_add, mul_assoc] congr 1 exact (Finset.sum_choose_succ_mul (fun i j => ‖iteratedFDerivWithin 𝕜 i f s x‖ * ‖iteratedFDerivWithin 𝕜 j g s x‖) n).symm /-- Bounding the norm of the iterated derivative of `B (f x) (g x)` within a set in terms of the iterated derivatives of `f` and `g` when `B` is bilinear: `‖D^n (x ↩ B (f x) (g x))‖ ≀ ‖B‖ ∑_{k ≀ n} n.choose k ‖D^k f‖ ‖D^{n-k} g‖` -/ theorem ContinuousLinearMap.norm_iteratedFDerivWithin_le_of_bilinear (B : E →L[𝕜] F →L[𝕜] G) {f : D → E} {g : D → F} {N : ℕ∞} {s : Set D} {x : D} (hf : ContDiffOn 𝕜 N f s) (hg : ContDiffOn 𝕜 N g s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {n : ℕ} (hn : (n : ℕ∞) ≀ N) : ‖iteratedFDerivWithin 𝕜 n (fun y => B (f y) (g y)) s x‖ ≀ ‖B‖ * ∑ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * ‖iteratedFDerivWithin 𝕜 i f s x‖ * ‖iteratedFDerivWithin 𝕜 (n - i) g s x‖ := by /- We reduce the bound to the case where all spaces live in the same universe (in which we already have proved the result), by using linear isometries between the spaces and their `ULift` to a common universe. These linear isometries preserve the norm of the iterated derivative. -/ let Du : Type max uD uE uF uG := ULift.{max uE uF uG, uD} D let Eu : Type max uD uE uF uG := ULift.{max uD uF uG, uE} E let Fu : Type max uD uE uF uG := ULift.{max uD uE uG, uF} F let Gu : Type max uD uE uF uG := ULift.{max uD uE uF, uG} G have isoD : Du ≃ₗᵢ[𝕜] D := LinearIsometryEquiv.ulift 𝕜 D have isoE : Eu ≃ₗᵢ[𝕜] E := LinearIsometryEquiv.ulift 𝕜 E have isoF : Fu ≃ₗᵢ[𝕜] F := LinearIsometryEquiv.ulift 𝕜 F have isoG : Gu ≃ₗᵢ[𝕜] G := LinearIsometryEquiv.ulift 𝕜 G -- lift `f` and `g` to versions `fu` and `gu` on the lifted spaces. set fu : Du → Eu := isoE.symm ∘ f ∘ isoD with hfu set gu : Du → Fu := isoF.symm ∘ g ∘ isoD with hgu -- lift the bilinear map `B` to a bilinear map `Bu` on the lifted spaces. set Bu₀ : Eu →L[𝕜] Fu →L[𝕜] G := ((B.comp (isoE : Eu →L[𝕜] E)).flip.comp (isoF : Fu →L[𝕜] F)).flip with hBu₀ let Bu : Eu →L[𝕜] Fu →L[𝕜] Gu := ContinuousLinearMap.compL 𝕜 Eu (Fu →L[𝕜] G) (Fu →L[𝕜] Gu) (ContinuousLinearMap.compL 𝕜 Fu G Gu (isoG.symm : G →L[𝕜] Gu)) Bu₀ have hBu : Bu = ContinuousLinearMap.compL 𝕜 Eu (Fu →L[𝕜] G) (Fu →L[𝕜] Gu) (ContinuousLinearMap.compL 𝕜 Fu G Gu (isoG.symm : G →L[𝕜] Gu)) Bu₀ := rfl have Bu_eq : (fun y => Bu (fu y) (gu y)) = isoG.symm ∘ (fun y => B (f y) (g y)) ∘ isoD := by ext1 y simp [hBu, hBu₀, hfu, hgu] -- All norms are preserved by the lifting process. have Bu_le : ‖Bu‖ ≀ ‖B‖ := by refine ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg B) fun y => ?_ refine ContinuousLinearMap.opNorm_le_bound _ (by positivity) fun x => ?_ simp only [hBu, hBu₀, compL_apply, coe_comp', Function.comp_apply, ContinuousLinearEquiv.coe_coe, LinearIsometryEquiv.coe_coe, flip_apply, LinearIsometryEquiv.norm_map] calc ‖B (isoE y) (isoF x)‖ ≀ ‖B (isoE y)‖ * ‖isoF x‖ := ContinuousLinearMap.le_opNorm _ _ _ ≀ ‖B‖ * ‖isoE y‖ * ‖isoF x‖ := by gcongr; apply ContinuousLinearMap.le_opNorm _ = ‖B‖ * ‖y‖ * ‖x‖ := by simp only [LinearIsometryEquiv.norm_map] let su := isoD ⁻¹' s have hsu : UniqueDiffOn 𝕜 su := isoD.toContinuousLinearEquiv.uniqueDiffOn_preimage_iff.2 hs let xu := isoD.symm x have hxu : xu ∈ su := by simpa only [xu, su, Set.mem_preimage, LinearIsometryEquiv.apply_symm_apply] using hx have xu_x : isoD xu = x := by simp only [xu, LinearIsometryEquiv.apply_symm_apply] have hfu : ContDiffOn 𝕜 n fu su := isoE.symm.contDiff.comp_contDiffOn ((hf.of_le hn).comp_continuousLinearMap (isoD : Du →L[𝕜] D)) have hgu : ContDiffOn 𝕜 n gu su := isoF.symm.contDiff.comp_contDiffOn ((hg.of_le hn).comp_continuousLinearMap (isoD : Du →L[𝕜] D)) have Nfu : ∀ i, ‖iteratedFDerivWithin 𝕜 i fu su xu‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by intro i rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left _ _ hsu hxu] rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right _ _ hs, xu_x] rwa [← xu_x] at hx have Ngu : ∀ i, ‖iteratedFDerivWithin 𝕜 i gu su xu‖ = ‖iteratedFDerivWithin 𝕜 i g s x‖ := by intro i rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left _ _ hsu hxu] rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right _ _ hs, xu_x] rwa [← xu_x] at hx have NBu : ‖iteratedFDerivWithin 𝕜 n (fun y => Bu (fu y) (gu y)) su xu‖ = ‖iteratedFDerivWithin 𝕜 n (fun y => B (f y) (g y)) s x‖ := by rw [Bu_eq] rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left _ _ hsu hxu] rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right _ _ hs, xu_x] rwa [← xu_x] at hx -- state the bound for the lifted objects, and deduce the original bound from it. have : ‖iteratedFDerivWithin 𝕜 n (fun y => Bu (fu y) (gu y)) su xu‖ ≀ ‖Bu‖ * ∑ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * ‖iteratedFDerivWithin 𝕜 i fu su xu‖ * ‖iteratedFDerivWithin 𝕜 (n - i) gu su xu‖ := Bu.norm_iteratedFDerivWithin_le_of_bilinear_aux hfu hgu hsu hxu simp only [Nfu, Ngu, NBu] at this exact this.trans (mul_le_mul_of_nonneg_right Bu_le (by positivity)) /-- Bounding the norm of the iterated derivative of `B (f x) (g x)` in terms of the iterated derivatives of `f` and `g` when `B` is bilinear: `‖D^n (x ↩ B (f x) (g x))‖ ≀ ‖B‖ ∑_{k ≀ n} n.choose k ‖D^k f‖ ‖D^{n-k} g‖` -/ theorem ContinuousLinearMap.norm_iteratedFDeriv_le_of_bilinear (B : E →L[𝕜] F →L[𝕜] G) {f : D → E} {g : D → F} {N : ℕ∞} (hf : ContDiff 𝕜 N f) (hg : ContDiff 𝕜 N g) (x : D) {n : ℕ} (hn : (n : ℕ∞) ≀ N) : ‖iteratedFDeriv 𝕜 n (fun y => B (f y) (g y)) x‖ ≀ ‖B‖ * ∑ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * ‖iteratedFDeriv 𝕜 i f x‖ * ‖iteratedFDeriv 𝕜 (n - i) g x‖ := by simp_rw [← iteratedFDerivWithin_univ] exact B.norm_iteratedFDerivWithin_le_of_bilinear hf.contDiffOn hg.contDiffOn uniqueDiffOn_univ (mem_univ x) hn /-- Bounding the norm of the iterated derivative of `B (f x) (g x)` within a set in terms of the iterated derivatives of `f` and `g` when `B` is bilinear of norm at most `1`: `‖D^n (x ↩ B (f x) (g x))‖ ≀ ∑_{k ≀ n} n.choose k ‖D^k f‖ ‖D^{n-k} g‖` -/ theorem ContinuousLinearMap.norm_iteratedFDerivWithin_le_of_bilinear_of_le_one (B : E →L[𝕜] F →L[𝕜] G) {f : D → E} {g : D → F} {N : ℕ∞} {s : Set D} {x : D} (hf : ContDiffOn 𝕜 N f s) (hg : ContDiffOn 𝕜 N g s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {n : ℕ} (hn : (n : ℕ∞) ≀ N) (hB : ‖B‖ ≀ 1) : ‖iteratedFDerivWithin 𝕜 n (fun y => B (f y) (g y)) s x‖ ≀ ∑ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * ‖iteratedFDerivWithin 𝕜 i f s x‖ * ‖iteratedFDerivWithin 𝕜 (n - i) g s x‖ := by apply (B.norm_iteratedFDerivWithin_le_of_bilinear hf hg hs hx hn).trans exact mul_le_of_le_one_left (by positivity) hB /-- Bounding the norm of the iterated derivative of `B (f x) (g x)` in terms of the iterated derivatives of `f` and `g` when `B` is bilinear of norm at most `1`: `‖D^n (x ↩ B (f x) (g x))‖ ≀ ∑_{k ≀ n} n.choose k ‖D^k f‖ ‖D^{n-k} g‖` -/ theorem ContinuousLinearMap.norm_iteratedFDeriv_le_of_bilinear_of_le_one (B : E →L[𝕜] F →L[𝕜] G) {f : D → E} {g : D → F} {N : ℕ∞} (hf : ContDiff 𝕜 N f) (hg : ContDiff 𝕜 N g) (x : D) {n : ℕ} (hn : (n : ℕ∞) ≀ N) (hB : ‖B‖ ≀ 1) : ‖iteratedFDeriv 𝕜 n (fun y => B (f y) (g y)) x‖ ≀ ∑ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * ‖iteratedFDeriv 𝕜 i f x‖ * ‖iteratedFDeriv 𝕜 (n - i) g x‖ := by simp_rw [← iteratedFDerivWithin_univ] exact B.norm_iteratedFDerivWithin_le_of_bilinear_of_le_one hf.contDiffOn hg.contDiffOn uniqueDiffOn_univ (mem_univ x) hn hB section variable {𝕜' : Type*} [NormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] theorem norm_iteratedFDerivWithin_smul_le {f : E → 𝕜'} {g : E → F} {N : ℕ∞} (hf : ContDiffOn 𝕜 N f s) (hg : ContDiffOn 𝕜 N g s) (hs : UniqueDiffOn 𝕜 s) {x : E} (hx : x ∈ s) {n : ℕ} (hn : (n : ℕ∞) ≀ N) : ‖iteratedFDerivWithin 𝕜 n (fun y => f y • g y) s x‖ ≀ ∑ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * ‖iteratedFDerivWithin 𝕜 i f s x‖ * ‖iteratedFDerivWithin 𝕜 (n - i) g s x‖ := (ContinuousLinearMap.lsmul 𝕜 𝕜' : 𝕜' →L[𝕜] F →L[𝕜] F).norm_iteratedFDerivWithin_le_of_bilinear_of_le_one hf hg hs hx hn ContinuousLinearMap.opNorm_lsmul_le theorem norm_iteratedFDeriv_smul_le {f : E → 𝕜'} {g : E → F} {N : ℕ∞} (hf : ContDiff 𝕜 N f) (hg : ContDiff 𝕜 N g) (x : E) {n : ℕ} (hn : (n : ℕ∞) ≀ N) : ‖iteratedFDeriv 𝕜 n (fun y => f y • g y) x‖ ≀ ∑ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * ‖iteratedFDeriv 𝕜 i f x‖ * ‖iteratedFDeriv 𝕜 (n - i) g x‖ := (ContinuousLinearMap.lsmul 𝕜 𝕜' : 𝕜' →L[𝕜] F →L[𝕜] F).norm_iteratedFDeriv_le_of_bilinear_of_le_one hf hg x hn ContinuousLinearMap.opNorm_lsmul_le end section variable {ι : Type*} {A : Type*} [NormedRing A] [NormedAlgebra 𝕜 A] {A' : Type*} [NormedCommRing A'] [NormedAlgebra 𝕜 A'] theorem norm_iteratedFDerivWithin_mul_le {f : E → A} {g : E → A} {N : ℕ∞} (hf : ContDiffOn 𝕜 N f s) (hg : ContDiffOn 𝕜 N g s) (hs : UniqueDiffOn 𝕜 s) {x : E} (hx : x ∈ s) {n : ℕ} (hn : (n : ℕ∞) ≀ N) : ‖iteratedFDerivWithin 𝕜 n (fun y => f y * g y) s x‖ ≀ ∑ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * ‖iteratedFDerivWithin 𝕜 i f s x‖ * ‖iteratedFDerivWithin 𝕜 (n - i) g s x‖ := (ContinuousLinearMap.mul 𝕜 A : A →L[𝕜] A →L[𝕜] A).norm_iteratedFDerivWithin_le_of_bilinear_of_le_one hf hg hs hx hn (ContinuousLinearMap.opNorm_mul_le _ _) theorem norm_iteratedFDeriv_mul_le {f : E → A} {g : E → A} {N : ℕ∞} (hf : ContDiff 𝕜 N f) (hg : ContDiff 𝕜 N g) (x : E) {n : ℕ} (hn : (n : ℕ∞) ≀ N) : ‖iteratedFDeriv 𝕜 n (fun y => f y * g y) x‖ ≀ ∑ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * ‖iteratedFDeriv 𝕜 i f x‖ * ‖iteratedFDeriv 𝕜 (n - i) g x‖ := by simp_rw [← iteratedFDerivWithin_univ] exact norm_iteratedFDerivWithin_mul_le hf.contDiffOn hg.contDiffOn uniqueDiffOn_univ (mem_univ x) hn -- TODO: Add `norm_iteratedFDeriv[Within]_list_prod_le` for non-commutative `NormedRing A`. theorem norm_iteratedFDerivWithin_prod_le [DecidableEq ι] [NormOneClass A'] {u : Finset ι} {f : ι → E → A'} {N : ℕ∞} (hf : ∀ i ∈ u, ContDiffOn 𝕜 N (f i) s) (hs : UniqueDiffOn 𝕜 s) {x : E} (hx : x ∈ s) {n : ℕ} (hn : (n : ℕ∞) ≀ N) : ‖iteratedFDerivWithin 𝕜 n (∏ j ∈ u, f j ·) s x‖ ≀ ∑ p ∈ u.sym n, (p : Multiset ι).multinomial * ∏ j ∈ u, ‖iteratedFDerivWithin 𝕜 (Multiset.count j p) (f j) s x‖ := by induction u using Finset.induction generalizing n with | empty => cases n with | zero => simp [Sym.eq_nil_of_card_zero] | succ n => simp [iteratedFDerivWithin_succ_const _ _ hs hx] | @insert i u hi IH => conv => lhs; simp only [Finset.prod_insert hi] simp only [Finset.mem_insert, forall_eq_or_imp] at hf refine le_trans (norm_iteratedFDerivWithin_mul_le hf.1 (contDiffOn_prod hf.2) hs hx hn) ?_ rw [← Finset.sum_coe_sort (Finset.sym _ _)] rw [Finset.sum_equiv (Finset.symInsertEquiv hi) (t := Finset.univ) (g := (fun v ↩ v.multinomial * ∏ j ∈ insert i u, ‖iteratedFDerivWithin 𝕜 (v.count j) (f j) s x‖) ∘ Sym.toMultiset ∘ Subtype.val ∘ (Finset.symInsertEquiv hi).symm) (by simp) (by simp only [← comp_apply (g := Finset.symInsertEquiv hi), comp.assoc]; simp)] rw [← Finset.univ_sigma_univ, Finset.sum_sigma, Finset.sum_range] simp only [comp_apply, Finset.symInsertEquiv_symm_apply_coe] refine Finset.sum_le_sum ?_ intro m _ specialize IH hf.2 (n := n - m) (le_trans (WithTop.coe_le_coe.mpr (n.sub_le m)) hn) refine le_trans (mul_le_mul_of_nonneg_left IH (by simp [mul_nonneg])) ?_ rw [Finset.mul_sum, ← Finset.sum_coe_sort] refine Finset.sum_le_sum ?_ simp only [Finset.mem_univ, forall_true_left, Subtype.forall, Finset.mem_sym_iff] intro p hp refine le_of_eq ?_ rw [Finset.prod_insert hi] have hip : i ∉ p := mt (hp i) hi rw [Sym.count_coe_fill_self_of_not_mem hip, Sym.multinomial_coe_fill_of_not_mem hip] suffices ∏ j ∈ u, ‖iteratedFDerivWithin 𝕜 (Multiset.count j p) (f j) s x‖ = ∏ j ∈ u, ‖iteratedFDerivWithin 𝕜 (Multiset.count j (Sym.fill i m p)) (f j) s x‖ by rw [this, Nat.cast_mul] ring refine Finset.prod_congr rfl ?_ intro j hj have hji : j ≠ i := mt (· ▾ hj) hi rw [Sym.count_coe_fill_of_ne hji] theorem norm_iteratedFDeriv_prod_le [DecidableEq ι] [NormOneClass A'] {u : Finset ι} {f : ι → E → A'} {N : ℕ∞} (hf : ∀ i ∈ u, ContDiff 𝕜 N (f i)) {x : E} {n : ℕ} (hn : (n : ℕ∞) ≀ N) : ‖iteratedFDeriv 𝕜 n (∏ j ∈ u, f j ·) x‖ ≀ ∑ p ∈ u.sym n, (p : Multiset ι).multinomial * ∏ j ∈ u, ‖iteratedFDeriv 𝕜 ((p : Multiset ι).count j) (f j) x‖ := by simpa [iteratedFDerivWithin_univ] using norm_iteratedFDerivWithin_prod_le (fun i hi ↩ (hf i hi).contDiffOn) uniqueDiffOn_univ (mem_univ x) hn end /-- If the derivatives within a set of `g` at `f x` are bounded by `C`, and the `i`-th derivative within a set of `f` at `x` is bounded by `D^i` for all `1 ≀ i ≀ n`, then the `n`-th derivative of `g ∘ f` is bounded by `n! * C * D^n`. This lemma proves this estimate assuming additionally that two of the spaces live in the same universe, to make an induction possible. Use instead `norm_iteratedFDerivWithin_comp_le` that removes this assumption. -/ theorem norm_iteratedFDerivWithin_comp_le_aux {Fu Gu : Type u} [NormedAddCommGroup Fu] [NormedSpace 𝕜 Fu] [NormedAddCommGroup Gu] [NormedSpace 𝕜 Gu] {g : Fu → Gu} {f : E → Fu} {n : ℕ} {s : Set E} {t : Set Fu} {x : E} (hg : ContDiffOn 𝕜 n g t) (hf : ContDiffOn 𝕜 n f s) (ht : UniqueDiffOn 𝕜 t) (hs : UniqueDiffOn 𝕜 s) (hst : MapsTo f s t) (hx : x ∈ s) {C : ℝ} {D : ℝ} (hC : ∀ i, i ≀ n → ‖iteratedFDerivWithin 𝕜 i g t (f x)‖ ≀ C) (hD : ∀ i, 1 ≀ i → i ≀ n → ‖iteratedFDerivWithin 𝕜 i f s x‖ ≀ D ^ i) : ‖iteratedFDerivWithin 𝕜 n (g ∘ f) s x‖ ≀ n ! * C * D ^ n := by /- We argue by induction on `n`, using that `D^(n+1) (g ∘ f) = D^n (g ' ∘ f ⬝ f')`. The successive derivatives of `g' ∘ f` are controlled thanks to the inductive assumption, and those of `f'` are controlled by assumption. As composition of linear maps is a bilinear map, one may use `ContinuousLinearMap.norm_iteratedFDeriv_le_of_bilinear_of_le_one` to get from these a bound on `D^n (g ' ∘ f ⬝ f')`. -/ induction' n using Nat.case_strong_induction_on with n IH generalizing Gu · simpa [norm_iteratedFDerivWithin_zero, Nat.factorial_zero, algebraMap.coe_one, one_mul, pow_zero, mul_one, comp_apply] using hC 0 le_rfl have M : (n : ℕ∞) < n.succ := Nat.cast_lt.2 n.lt_succ_self have Cnonneg : 0 ≀ C := (norm_nonneg _).trans (hC 0 bot_le) have Dnonneg : 0 ≀ D := by have : 1 ≀ n + 1 := by simp only [le_add_iff_nonneg_left, zero_le'] simpa only [pow_one] using (norm_nonneg _).trans (hD 1 le_rfl this) -- use the inductive assumption to bound the derivatives of `g' ∘ f`. have I : ∀ i ∈ Finset.range (n + 1), ‖iteratedFDerivWithin 𝕜 i (fderivWithin 𝕜 g t ∘ f) s x‖ ≀ i ! * C * D ^ i := by intro i hi simp only [Finset.mem_range_succ_iff] at hi apply IH i hi · apply hg.fderivWithin ht simp only [Nat.cast_succ] exact add_le_add_right (Nat.cast_le.2 hi) _ · apply hf.of_le (Nat.cast_le.2 (hi.trans n.le_succ)) · intro j hj have : ‖iteratedFDerivWithin 𝕜 j (fderivWithin 𝕜 g t) t (f x)‖ = ‖iteratedFDerivWithin 𝕜 (j + 1) g t (f x)‖ := by rw [iteratedFDerivWithin_succ_eq_comp_right ht (hst hx), comp_apply, LinearIsometryEquiv.norm_map] rw [this] exact hC (j + 1) (add_le_add (hj.trans hi) le_rfl) · intro j hj h'j exact hD j hj (h'j.trans (hi.trans n.le_succ)) -- reformulate `hD` as a bound for the derivatives of `f'`. have J : ∀ i, ‖iteratedFDerivWithin 𝕜 (n - i) (fderivWithin 𝕜 f s) s x‖ ≀ D ^ (n - i + 1) := by intro i have : ‖iteratedFDerivWithin 𝕜 (n - i) (fderivWithin 𝕜 f s) s x‖ = ‖iteratedFDerivWithin 𝕜 (n - i + 1) f s x‖ := by rw [iteratedFDerivWithin_succ_eq_comp_right hs hx, comp_apply, LinearIsometryEquiv.norm_map] rw [this] apply hD · simp only [le_add_iff_nonneg_left, zero_le'] · apply Nat.succ_le_succ tsub_le_self -- Now put these together: first, notice that we have to bound `D^n (g' ∘ f ⬝ f')`. calc ‖iteratedFDerivWithin 𝕜 (n + 1) (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 n (fun y : E => fderivWithin 𝕜 (g ∘ f) s y) s x‖ := by rw [iteratedFDerivWithin_succ_eq_comp_right hs hx, comp_apply, LinearIsometryEquiv.norm_map] _ = ‖iteratedFDerivWithin 𝕜 n (fun y : E => ContinuousLinearMap.compL 𝕜 E Fu Gu (fderivWithin 𝕜 g t (f y)) (fderivWithin 𝕜 f s y)) s x‖ := by have L : (1 : ℕ∞) ≀ n.succ := by simpa only [ENat.coe_one, Nat.one_le_cast] using n.succ_pos congr 1 refine iteratedFDerivWithin_congr (fun y hy => ?_) hx _ apply fderivWithin.comp _ _ _ hst (hs y hy) · exact hg.differentiableOn L _ (hst hy) · exact hf.differentiableOn L _ hy -- bound it using the fact that the composition of linear maps is a bilinear operation, -- for which we have bounds for the`n`-th derivative. _ ≀ ∑ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * ‖iteratedFDerivWithin 𝕜 i (fderivWithin 𝕜 g t ∘ f) s x‖ * ‖iteratedFDerivWithin 𝕜 (n - i) (fderivWithin 𝕜 f s) s x‖ := by have A : ContDiffOn 𝕜 n (fderivWithin 𝕜 g t ∘ f) s := by apply ContDiffOn.comp _ (hf.of_le M.le) hst apply hg.fderivWithin ht simp only [Nat.cast_succ, le_refl] have B : ContDiffOn 𝕜 n (fderivWithin 𝕜 f s) s := by apply hf.fderivWithin hs simp only [Nat.cast_succ, le_refl] exact (ContinuousLinearMap.compL 𝕜 E Fu Gu).norm_iteratedFDerivWithin_le_of_bilinear_of_le_one A B hs hx le_rfl (ContinuousLinearMap.norm_compL_le 𝕜 E Fu Gu) -- bound each of the terms using the estimates on previous derivatives (that use the inductive -- assumption for `g' ∘ f`). _ ≀ ∑ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * (i ! * C * D ^ i) * D ^ (n - i + 1) := by gcongr with i hi · exact I i hi · exact J i -- We are left with trivial algebraic manipulations to see that this is smaller than -- the claimed bound. _ = ∑ i ∈ Finset.range (n + 1), -- Porting note: had to insert a few more explicit type ascriptions in this and similar -- expressions. (n ! : ℝ) * ((i ! : ℝ)⁻¹ * i !) * C * (D ^ i * D ^ (n - i + 1)) * ((n - i)! : ℝ)⁻¹ := by congr! 1 with i hi simp only [Nat.cast_choose ℝ (Finset.mem_range_succ_iff.1 hi), div_eq_inv_mul, mul_inv] ring _ = ∑ i ∈ Finset.range (n + 1), (n ! : ℝ) * 1 * C * D ^ (n + 1) * ((n - i)! : ℝ)⁻¹ := by congr! with i hi · apply inv_mul_cancel simpa only [Ne, Nat.cast_eq_zero] using i.factorial_ne_zero · rw [← pow_add] congr 1 rw [Nat.add_succ, Nat.succ_inj'] exact Nat.add_sub_of_le (Finset.mem_range_succ_iff.1 hi) _ ≀ ∑ i ∈ Finset.range (n + 1), (n ! : ℝ) * 1 * C * D ^ (n + 1) * 1 := by gcongr with i apply inv_le_one simpa only [Nat.one_le_cast] using (n - i).factorial_pos _ = (n + 1)! * C * D ^ (n + 1) := by simp only [mul_assoc, mul_one, Finset.sum_const, Finset.card_range, nsmul_eq_mul, Nat.factorial_succ, Nat.cast_mul] /-- If the derivatives within a set of `g` at `f x` are bounded by `C`, and the `i`-th derivative within a set of `f` at `x` is bounded by `D^i` for all `1 ≀ i ≀ n`, then the `n`-th derivative of `g ∘ f` is bounded by `n! * C * D^n`. -/ theorem norm_iteratedFDerivWithin_comp_le {g : F → G} {f : E → F} {n : ℕ} {s : Set E} {t : Set F} {x : E} {N : ℕ∞} (hg : ContDiffOn 𝕜 N g t) (hf : ContDiffOn 𝕜 N f s) (hn : (n : ℕ∞) ≀ N) (ht : UniqueDiffOn 𝕜 t) (hs : UniqueDiffOn 𝕜 s) (hst : MapsTo f s t) (hx : x ∈ s) {C : ℝ} {D : ℝ} (hC : ∀ i, i ≀ n → ‖iteratedFDerivWithin 𝕜 i g t (f x)‖ ≀ C) (hD : ∀ i, 1 ≀ i → i ≀ n → ‖iteratedFDerivWithin 𝕜 i f s x‖ ≀ D ^ i) : ‖iteratedFDerivWithin 𝕜 n (g ∘ f) s x‖ ≀ n ! * C * D ^ n := by /- We reduce the bound to the case where all spaces live in the same universe (in which we already have proved the result), by using linear isometries between the spaces and their `ULift` to a common universe. These linear isometries preserve the norm of the iterated derivative. -/ let Fu : Type max uF uG := ULift.{uG, uF} F let Gu : Type max uF uG := ULift.{uF, uG} G have isoF : Fu ≃ₗᵢ[𝕜] F := LinearIsometryEquiv.ulift 𝕜 F have isoG : Gu ≃ₗᵢ[𝕜] G := LinearIsometryEquiv.ulift 𝕜 G -- lift `f` and `g` to versions `fu` and `gu` on the lifted spaces. let fu : E → Fu := isoF.symm ∘ f let gu : Fu → Gu := isoG.symm ∘ g ∘ isoF let tu := isoF ⁻¹' t have htu : UniqueDiffOn 𝕜 tu := isoF.toContinuousLinearEquiv.uniqueDiffOn_preimage_iff.2 ht have hstu : MapsTo fu s tu := fun y hy ↩ by simpa only [fu, tu, mem_preimage, comp_apply, LinearIsometryEquiv.apply_symm_apply] using hst hy have Ffu : isoF (fu x) = f x := by simp only [fu, comp_apply, LinearIsometryEquiv.apply_symm_apply] -- All norms are preserved by the lifting process. have hfu : ContDiffOn 𝕜 n fu s := isoF.symm.contDiff.comp_contDiffOn (hf.of_le hn) have hgu : ContDiffOn 𝕜 n gu tu := isoG.symm.contDiff.comp_contDiffOn ((hg.of_le hn).comp_continuousLinearMap (isoF : Fu →L[𝕜] F)) have Nfu : ∀ i, ‖iteratedFDerivWithin 𝕜 i fu s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := fun i ↩ by rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left _ _ hs hx] simp_rw [← Nfu] at hD have Ngu : ∀ i, ‖iteratedFDerivWithin 𝕜 i gu tu (fu x)‖ = ‖iteratedFDerivWithin 𝕜 i g t (f x)‖ := fun i ↩ by rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left _ _ htu (hstu hx)] rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right _ _ ht, Ffu] rw [Ffu] exact hst hx simp_rw [← Ngu] at hC have Nfgu : ‖iteratedFDerivWithin 𝕜 n (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 n (gu ∘ fu) s x‖ := by have : gu ∘ fu = isoG.symm ∘ g ∘ f := by ext x simp only [fu, gu, comp_apply, LinearIsometryEquiv.map_eq_iff, LinearIsometryEquiv.apply_symm_apply] rw [this, LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left _ _ hs hx] -- deduce the required bound from the one for `gu ∘ fu`. rw [Nfgu] exact norm_iteratedFDerivWithin_comp_le_aux hgu hfu htu hs hstu hx hC hD /-- If the derivatives of `g` at `f x` are bounded by `C`, and the `i`-th derivative of `f` at `x` is bounded by `D^i` for all `1 ≀ i ≀ n`, then the `n`-th derivative of `g ∘ f` is bounded by `n! * C * D^n`. -/ theorem norm_iteratedFDeriv_comp_le {g : F → G} {f : E → F} {n : ℕ} {N : ℕ∞} (hg : ContDiff 𝕜 N g) (hf : ContDiff 𝕜 N f) (hn : (n : ℕ∞) ≀ N) (x : E) {C : ℝ} {D : ℝ} (hC : ∀ i, i ≀ n → ‖iteratedFDeriv 𝕜 i g (f x)‖ ≀ C) (hD : ∀ i, 1 ≀ i → i ≀ n → ‖iteratedFDeriv 𝕜 i f x‖ ≀ D ^ i) : ‖iteratedFDeriv 𝕜 n (g ∘ f) x‖ ≀ n ! * C * D ^ n := by simp_rw [← iteratedFDerivWithin_univ] at hC hD ⊢ exact norm_iteratedFDerivWithin_comp_le hg.contDiffOn hf.contDiffOn hn uniqueDiffOn_univ uniqueDiffOn_univ (mapsTo_univ _ _) (mem_univ x) hC hD section Apply theorem norm_iteratedFDerivWithin_clm_apply {f : E → F →L[𝕜] G} {g : E → F} {s : Set E} {x : E} {N : ℕ∞} {n : ℕ} (hf : ContDiffOn 𝕜 N f s) (hg : ContDiffOn 𝕜 N g s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (hn : ↑n ≀ N) : ‖iteratedFDerivWithin 𝕜 n (fun y => (f y) (g y)) s x‖ ≀ ∑ i ∈ Finset.range (n + 1), ↑(n.choose i) * ‖iteratedFDerivWithin 𝕜 i f s x‖ * ‖iteratedFDerivWithin 𝕜 (n - i) g s x‖ := by let B : (F →L[𝕜] G) →L[𝕜] F →L[𝕜] G := ContinuousLinearMap.flip (ContinuousLinearMap.apply 𝕜 G) have hB : ‖B‖ ≀ 1 := by simp only [B, ContinuousLinearMap.opNorm_flip, ContinuousLinearMap.apply] refine ContinuousLinearMap.opNorm_le_bound _ zero_le_one fun f => ?_ simp only [ContinuousLinearMap.coe_id', id, one_mul] rfl exact B.norm_iteratedFDerivWithin_le_of_bilinear_of_le_one hf hg hs hx hn hB theorem norm_iteratedFDeriv_clm_apply {f : E → F →L[𝕜] G} {g : E → F} {N : ℕ∞} {n : ℕ} (hf : ContDiff 𝕜 N f) (hg : ContDiff 𝕜 N g) (x : E) (hn : ↑n ≀ N) : ‖iteratedFDeriv 𝕜 n (fun y : E => (f y) (g y)) x‖ ≀ ∑ i ∈ Finset.range (n + 1), ↑(n.choose i) * ‖iteratedFDeriv 𝕜 i f x‖ * ‖iteratedFDeriv 𝕜 (n - i) g x‖ := by simp only [← iteratedFDerivWithin_univ] exact norm_iteratedFDerivWithin_clm_apply hf.contDiffOn hg.contDiffOn uniqueDiffOn_univ (Set.mem_univ x) hn theorem norm_iteratedFDerivWithin_clm_apply_const {f : E → F →L[𝕜] G} {c : F} {s : Set E} {x : E} {N : ℕ∞} {n : ℕ} (hf : ContDiffOn 𝕜 N f s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (hn : ↑n ≀ N) : ‖iteratedFDerivWithin 𝕜 n (fun y : E => (f y) c) s x‖ ≀ ‖c‖ * ‖iteratedFDerivWithin 𝕜 n f s x‖ := by let g : (F →L[𝕜] G) →L[𝕜] G := ContinuousLinearMap.apply 𝕜 G c have h := g.norm_compContinuousMultilinearMap_le (iteratedFDerivWithin 𝕜 n f s x) rw [← g.iteratedFDerivWithin_comp_left hf hs hx hn] at h refine h.trans (mul_le_mul_of_nonneg_right ?_ (norm_nonneg _)) refine g.opNorm_le_bound (norm_nonneg _) fun f => ?_ rw [ContinuousLinearMap.apply_apply, mul_comm] exact f.le_opNorm c theorem norm_iteratedFDeriv_clm_apply_const {f : E → F →L[𝕜] G} {c : F} {x : E} {N : ℕ∞} {n : ℕ} (hf : ContDiff 𝕜 N f) (hn : ↑n ≀ N) : ‖iteratedFDeriv 𝕜 n (fun y : E => (f y) c) x‖ ≀ ‖c‖ * ‖iteratedFDeriv 𝕜 n f x‖ := by simp only [← iteratedFDerivWithin_univ] exact norm_iteratedFDerivWithin_clm_apply_const hf.contDiffOn uniqueDiffOn_univ (Set.mem_univ x) hn end Apply
Analysis\Calculus\ContDiff\Defs.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.FDeriv.Equiv import Mathlib.Analysis.Calculus.FormalMultilinearSeries /-! # Higher differentiability A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous. By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or, equivalently, if it is `C^1` and its derivative is `C^{n-1}`. Finally, it is `C^∞` if it is `C^n` for all n. We formalize these notions by defining iteratively the `n+1`-th derivative of a function as the derivative of the `n`-th derivative. It is called `iteratedFDeriv 𝕜 n f x` where `𝕜` is the field, `n` is the number of iterations, `f` is the function and `x` is the point, and it is given as an `n`-multilinear map. We also define a version `iteratedFDerivWithin` relative to a domain, as well as predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and `ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set and on the whole space respectively. To avoid the issue of choice when choosing a derivative in sets where the derivative is not necessarily unique, `ContDiffOn` is not defined directly in terms of the regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the existence of a nice sequence of derivatives, expressed with a predicate `HasFTaylorSeriesUpToOn`. We prove basic properties of these notions. ## Main definitions and results Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`. * `HasFTaylorSeriesUpTo n f p`: expresses that the formal multilinear series `p` is a sequence of iterated derivatives of `f`, up to the `n`-th term (where `n` is a natural number or `∞`). * `HasFTaylorSeriesUpToOn n f p s`: same thing, but inside a set `s`. The notion of derivative is now taken inside `s`. In particular, derivatives don't have to be unique. * `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to rank `n`. * `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`. * `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`. * `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`. * `iteratedFDerivWithin 𝕜 n f s x` is an `n`-th derivative of `f` over the field `𝕜` on the set `s` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a derivative within `s` of `iteratedFDerivWithin 𝕜 (n-1) f s` if one exists, and `0` otherwise. * `iteratedFDeriv 𝕜 n f x` is the `n`-th derivative of `f` over the field `𝕜` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a derivative of `iteratedFDeriv 𝕜 (n-1) f` if one exists, and `0` otherwise. In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≀ n`. In the whole space, `ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f` for `m ≀ n`. ## Implementation notes The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more complicated than the naive definitions one would guess from the intuition over the real or complex numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity in general. In the usual situations, they coincide with the usual definitions. ### Definition of `C^n` functions in domains One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n` functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`. This definition still has the problem that a function which is locally `C^n` would not need to be `C^n`, as different choices of sequences of derivatives around different points might possibly not be glued together to give a globally defined sequence of derivatives. (Note that this issue can not happen over reals, thanks to partition of unity, but the behavior over a general field is not so clear, and we want a definition for general fields). Also, there are locality problems for the order parameter: one could image a function which, for each `n`, has a nice sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore not be glued to give rise to an infinite sequence of derivatives. This would give a function which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`. The resulting definition is slightly more complicated to work with (in fact not so much), but it gives rise to completely satisfactory theorems. For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)` for each natural `m` is by definition `C^∞` at `0`. There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x` within `s`. However, this does not imply continuity or differentiability within `s` of the function at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file). ### Side of the composition, and universe issues With a naïve direct definition, the `n`-th derivative of a function belongs to the space `E →L[𝕜] (E →L[𝕜] (E ... F)...)))` where there are n iterations of `E →L[𝕜]`. This space may also be seen as the space of continuous multilinear functions on `n` copies of `E` with values in `F`, by uncurrying. This is the point of view that is usually adopted in textbooks, and that we also use. This means that the definition and the first proofs are slightly involved, as one has to keep track of the uncurrying operation. The uncurrying can be done from the left or from the right, amounting to defining the `n+1`-th derivative either as the derivative of the `n`-th derivative, or as the `n`-th derivative of the derivative. For proofs, it would be more convenient to use the latter approach (from the right), as it means to prove things at the `n+1`-th step we only need to understand well enough the derivative in `E →L[𝕜] F` (contrary to the approach from the left, where one would need to know enough on the `n`-th derivative to deduce things on the `n+1`-th derivative). However, the definition from the right leads to a universe polymorphism problem: if we define `iteratedFDeriv 𝕜 (n + 1) f x = iteratedFDeriv 𝕜 n (fderiv 𝕜 f) x` by induction, we need to generalize over all spaces (as `f` and `fderiv 𝕜 f` don't take values in the same space). It is only possible to generalize over all spaces in some fixed universe in an inductive definition. For `f : E → F`, then `fderiv 𝕜 f` is a map `E → (E →L[𝕜] F)`. Therefore, the definition will only work if `F` and `E →L[𝕜] F` are in the same universe. This issue does not appear with the definition from the left, where one does not need to generalize over all spaces. Therefore, we use the definition from the left. This means some proofs later on become a little bit more complicated: to prove that a function is `C^n`, the most efficient approach is to exhibit a formula for its `n`-th derivative and prove it is continuous (contrary to the inductive approach where one would prove smoothness statements without giving a formula for the derivative). In the end, this approach is still satisfactory as it is good to have formulas for the iterated derivatives in various constructions. One point where we depart from this explicit approach is in the proof of smoothness of a composition: there is a formula for the `n`-th derivative of a composition (Faà di Bruno's formula), but it is very complicated and barely usable, while the inductive proof is very simple. Thus, we give the inductive proof. As explained above, it works by generalizing over the target space, hence it only works well if all spaces belong to the same universe. To get the general version, we lift things to a common universe using a trick. ### Variables management The textbook definitions and proofs use various identifications and abuse of notations, for instance when saying that the natural space in which the derivative lives, i.e., `E →L[𝕜] (E →L[𝕜] ( ... →L[𝕜] F))`, is the same as a space of multilinear maps. When doing things formally, we need to provide explicit maps for these identifications, and chase some diagrams to see everything is compatible with the identifications. In particular, one needs to check that taking the derivative and then doing the identification, or first doing the identification and then taking the derivative, gives the same result. The key point for this is that taking the derivative commutes with continuous linear equivalences. Therefore, we need to implement all our identifications with continuous linear equivs. ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `⊀ : ℕ∞` with `∞`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open scoped Classical open NNReal Topology Filter local notation "∞" => (⊀ : ℕ∞) /- Porting note: These lines are not required in Mathlib4. attribute [local instance 1001] NormedAddCommGroup.toAddCommGroup NormedSpace.toModule' AddCommGroup.toAddCommMonoid -/ open Set Fin Filter Function universe u uE uF uG uX variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Functions with a Taylor series on a domain -/ /-- `HasFTaylorSeriesUpToOn n f p s` registers the fact that `p 0 = f` and `p (m+1)` is a derivative of `p m` for `m < n`, and is continuous for `m ≀ n`. This is a predicate analogous to `HasFDerivWithinAt` but for higher order derivatives. Notice that `p` does not sum up to `f` on the diagonal (`FormalMultilinearSeries.sum`), even if `f` is analytic and `n = ∞`: an additional `1/m!` factor on the `m`th term is necessary for that. -/ structure HasFTaylorSeriesUpToOn (n : ℕ∞) (f : E → F) (p : E → FormalMultilinearSeries 𝕜 E F) (s : Set E) : Prop where zero_eq : ∀ x ∈ s, (p x 0).uncurry0 = f x protected fderivWithin : ∀ m : ℕ, (m : ℕ∞) < n → ∀ x ∈ s, HasFDerivWithinAt (p · m) (p x m.succ).curryLeft s x cont : ∀ m : ℕ, (m : ℕ∞) ≀ n → ContinuousOn (p · m) s theorem HasFTaylorSeriesUpToOn.zero_eq' (h : HasFTaylorSeriesUpToOn n f p s) {x : E} (hx : x ∈ s) : p x 0 = (continuousMultilinearCurryFin0 𝕜 E F).symm (f x) := by rw [← h.zero_eq x hx] exact (p x 0).uncurry0_curry0.symm /-- If two functions coincide on a set `s`, then a Taylor series for the first one is as well a Taylor series for the second one. -/ theorem HasFTaylorSeriesUpToOn.congr (h : HasFTaylorSeriesUpToOn n f p s) (h₁ : ∀ x ∈ s, f₁ x = f x) : HasFTaylorSeriesUpToOn n f₁ p s := by refine ⟹fun x hx => ?_, h.fderivWithin, h.cont⟩ rw [h₁ x hx] exact h.zero_eq x hx theorem HasFTaylorSeriesUpToOn.mono (h : HasFTaylorSeriesUpToOn n f p s) {t : Set E} (hst : t ⊆ s) : HasFTaylorSeriesUpToOn n f p t := ⟹fun x hx => h.zero_eq x (hst hx), fun m hm x hx => (h.fderivWithin m hm x (hst hx)).mono hst, fun m hm => (h.cont m hm).mono hst⟩ theorem HasFTaylorSeriesUpToOn.of_le (h : HasFTaylorSeriesUpToOn n f p s) (hmn : m ≀ n) : HasFTaylorSeriesUpToOn m f p s := ⟹h.zero_eq, fun k hk x hx => h.fderivWithin k (lt_of_lt_of_le hk hmn) x hx, fun k hk => h.cont k (le_trans hk hmn)⟩ theorem HasFTaylorSeriesUpToOn.continuousOn (h : HasFTaylorSeriesUpToOn n f p s) : ContinuousOn f s := by have := (h.cont 0 bot_le).congr fun x hx => (h.zero_eq' hx).symm rwa [← (continuousMultilinearCurryFin0 𝕜 E F).symm.comp_continuousOn_iff] theorem hasFTaylorSeriesUpToOn_zero_iff : HasFTaylorSeriesUpToOn 0 f p s ↔ ContinuousOn f s ∧ ∀ x ∈ s, (p x 0).uncurry0 = f x := by refine ⟹fun H => ⟹H.continuousOn, H.zero_eq⟩, fun H => ⟹H.2, fun m hm => False.elim (not_le.2 hm bot_le), fun m hm ↩ ?_⟩⟩ obtain rfl : m = 0 := mod_cast hm.antisymm (zero_le _) have : EqOn (p · 0) ((continuousMultilinearCurryFin0 𝕜 E F).symm ∘ f) s := fun x hx ↩ (continuousMultilinearCurryFin0 𝕜 E F).eq_symm_apply.2 (H.2 x hx) rw [continuousOn_congr this, LinearIsometryEquiv.comp_continuousOn_iff] exact H.1 theorem hasFTaylorSeriesUpToOn_top_iff : HasFTaylorSeriesUpToOn ∞ f p s ↔ ∀ n : ℕ, HasFTaylorSeriesUpToOn n f p s := by constructor · intro H n; exact H.of_le le_top · intro H constructor · exact (H 0).zero_eq · intro m _ apply (H m.succ).fderivWithin m (WithTop.coe_lt_coe.2 (lt_add_one m)) · intro m _ apply (H m).cont m le_rfl /-- In the case that `n = ∞` we don't need the continuity assumption in `HasFTaylorSeriesUpToOn`. -/ theorem hasFTaylorSeriesUpToOn_top_iff' : HasFTaylorSeriesUpToOn ∞ f p s ↔ (∀ x ∈ s, (p x 0).uncurry0 = f x) ∧ ∀ m : ℕ, ∀ x ∈ s, HasFDerivWithinAt (fun y => p y m) (p x m.succ).curryLeft s x := -- Everything except for the continuity is trivial: ⟹fun h => ⟹h.1, fun m => h.2 m (WithTop.coe_lt_top m)⟩, fun h => ⟹h.1, fun m _ => h.2 m, fun m _ x hx => -- The continuity follows from the existence of a derivative: (h.2 m x hx).continuousWithinAt⟩⟩ /-- If a function has a Taylor series at order at least `1`, then the term of order `1` of this series is a derivative of `f`. -/ theorem HasFTaylorSeriesUpToOn.hasFDerivWithinAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≀ n) (hx : x ∈ s) : HasFDerivWithinAt f (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) s x := by have A : ∀ y ∈ s, f y = (continuousMultilinearCurryFin0 𝕜 E F) (p y 0) := fun y hy ↩ (h.zero_eq y hy).symm suffices H : HasFDerivWithinAt (continuousMultilinearCurryFin0 𝕜 E F ∘ (p · 0)) (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) s x from H.congr A (A x hx) rw [LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] have : ((0 : ℕ) : ℕ∞) < n := zero_lt_one.trans_le hn convert h.fderivWithin _ this x hx ext y v change (p x 1) (snoc 0 y) = (p x 1) (cons y v) congr with i rw [Unique.eq_default (α := Fin 1) i] rfl theorem HasFTaylorSeriesUpToOn.differentiableOn (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≀ n) : DifferentiableOn 𝕜 f s := fun _x hx => (h.hasFDerivWithinAt hn hx).differentiableWithinAt /-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then the term of order `1` of this series is a derivative of `f` at `x`. -/ theorem HasFTaylorSeriesUpToOn.hasFDerivAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≀ n) (hx : s ∈ 𝓝 x) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) x := (h.hasFDerivWithinAt hn (mem_of_mem_nhds hx)).hasFDerivAt hx /-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then in a neighborhood of `x`, the term of order `1` of this series is a derivative of `f`. -/ theorem HasFTaylorSeriesUpToOn.eventually_hasFDerivAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≀ n) (hx : s ∈ 𝓝 x) : ∀ᶠ y in 𝓝 x, HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p y 1)) y := (eventually_eventually_nhds.2 hx).mono fun _y hy => h.hasFDerivAt hn hy /-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then it is differentiable at `x`. -/ theorem HasFTaylorSeriesUpToOn.differentiableAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≀ n) (hx : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := (h.hasFDerivAt hn hx).differentiableAt /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p` is a Taylor series up to `n`, and `p (n + 1)` is a derivative of `p n`. -/ theorem hasFTaylorSeriesUpToOn_succ_iff_left {n : ℕ} : HasFTaylorSeriesUpToOn (n + 1) f p s ↔ HasFTaylorSeriesUpToOn n f p s ∧ (∀ x ∈ s, HasFDerivWithinAt (fun y => p y n) (p x n.succ).curryLeft s x) ∧ ContinuousOn (fun x => p x (n + 1)) s := by constructor · exact fun h ↩ ⟹h.of_le (WithTop.coe_le_coe.2 (Nat.le_succ n)), h.fderivWithin _ (WithTop.coe_lt_coe.2 (lt_add_one n)), h.cont (n + 1) le_rfl⟩ · intro h constructor · exact h.1.zero_eq · intro m hm by_cases h' : m < n · exact h.1.fderivWithin m (WithTop.coe_lt_coe.2 h') · have : m = n := Nat.eq_of_lt_succ_of_not_lt (WithTop.coe_lt_coe.1 hm) h' rw [this] exact h.2.1 · intro m hm by_cases h' : m ≀ n · apply h.1.cont m (WithTop.coe_le_coe.2 h') · have : m = n + 1 := le_antisymm (WithTop.coe_le_coe.1 hm) (not_le.1 h') rw [this] exact h.2.2 #adaptation_note /-- After https://github.com/leanprover/lean4/pull/4119, without `set_option maxSynthPendingDepth 2` this proof needs substantial repair. -/ set_option maxSynthPendingDepth 2 in -- Porting note: this was split out from `hasFTaylorSeriesUpToOn_succ_iff_right` to avoid a timeout. theorem HasFTaylorSeriesUpToOn.shift_of_succ {n : ℕ} (H : HasFTaylorSeriesUpToOn (n + 1 : ℕ) f p s) : (HasFTaylorSeriesUpToOn n (fun x => continuousMultilinearCurryFin1 𝕜 E F (p x 1)) (fun x => (p x).shift)) s := by constructor · intro x _ rfl · intro m (hm : (m : ℕ∞) < n) x (hx : x ∈ s) have A : (m.succ : ℕ∞) < n.succ := by rw [Nat.cast_lt] at hm ⊢ exact Nat.succ_lt_succ hm change HasFDerivWithinAt ((continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm ∘ (p · m.succ)) (p x m.succ.succ).curryRight.curryLeft s x rw [((continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm).comp_hasFDerivWithinAt_iff'] convert H.fderivWithin _ A x hx ext y v change p x (m + 2) (snoc (cons y (init v)) (v (last _))) = p x (m + 2) (cons y v) rw [← cons_snoc_eq_snoc_cons, snoc_init_self] · intro m (hm : (m : ℕ∞) ≀ n) suffices A : ContinuousOn (p · (m + 1)) s from ((continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm).continuous.comp_continuousOn A refine H.cont _ ?_ rw [Nat.cast_le] at hm ⊢ exact Nat.succ_le_succ hm /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p.shift` is a Taylor series up to `n` for `p 1`, which is a derivative of `f`. -/ theorem hasFTaylorSeriesUpToOn_succ_iff_right {n : ℕ} : HasFTaylorSeriesUpToOn (n + 1 : ℕ) f p s ↔ (∀ x ∈ s, (p x 0).uncurry0 = f x) ∧ (∀ x ∈ s, HasFDerivWithinAt (fun y => p y 0) (p x 1).curryLeft s x) ∧ HasFTaylorSeriesUpToOn n (fun x => continuousMultilinearCurryFin1 𝕜 E F (p x 1)) (fun x => (p x).shift) s := by constructor · intro H refine ⟹H.zero_eq, H.fderivWithin 0 (Nat.cast_lt.2 (Nat.succ_pos n)), ?_⟩ exact H.shift_of_succ · rintro ⟹Hzero_eq, Hfderiv_zero, Htaylor⟩ constructor · exact Hzero_eq · intro m (hm : (m : ℕ∞) < n.succ) x (hx : x ∈ s) cases' m with m · exact Hfderiv_zero x hx · have A : (m : ℕ∞) < n := by rw [Nat.cast_lt] at hm ⊢ exact Nat.lt_of_succ_lt_succ hm have : HasFDerivWithinAt ((continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm ∘ (p · m.succ)) ((p x).shift m.succ).curryLeft s x := Htaylor.fderivWithin _ A x hx rw [LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] at this convert this ext y v change (p x (Nat.succ (Nat.succ m))) (cons y v) = (p x m.succ.succ) (snoc (cons y (init v)) (v (last _))) rw [← cons_snoc_eq_snoc_cons, snoc_init_self] · intro m (hm : (m : ℕ∞) ≀ n.succ) cases' m with m · have : DifferentiableOn 𝕜 (fun x => p x 0) s := fun x hx => (Hfderiv_zero x hx).differentiableWithinAt exact this.continuousOn · refine (continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm.comp_continuousOn_iff.mp ?_ refine Htaylor.cont _ ?_ rw [Nat.cast_le] at hm ⊢ exact Nat.lt_succ_iff.mp hm /-! ### Smooth functions within a set around a point -/ variable (𝕜) /-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not better, is `C^∞` at `0` within `univ`. -/ def ContDiffWithinAt (n : ℕ∞) (f : E → F) (s : Set E) (x : E) : Prop := ∀ m : ℕ, (m : ℕ∞) ≀ n → ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn m f p u variable {𝕜} theorem contDiffWithinAt_nat {n : ℕ} : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u := ⟹fun H => H n le_rfl, fun ⟹u, hu, p, hp⟩ _m hm => ⟹u, hu, p, hp.of_le hm⟩⟩ theorem ContDiffWithinAt.of_le (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m ≀ n) : ContDiffWithinAt 𝕜 m f s x := fun k hk => h k (le_trans hk hmn) theorem contDiffWithinAt_iff_forall_nat_le : ContDiffWithinAt 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≀ n → ContDiffWithinAt 𝕜 m f s x := ⟹fun H _m hm => H.of_le hm, fun H m hm => H m hm _ le_rfl⟩ theorem contDiffWithinAt_top : ContDiffWithinAt 𝕜 ∞ f s x ↔ ∀ n : ℕ, ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_iff_forall_nat_le.trans <| by simp only [forall_prop_of_true, le_top] theorem ContDiffWithinAt.continuousWithinAt (h : ContDiffWithinAt 𝕜 n f s x) : ContinuousWithinAt f s x := by rcases h 0 bot_le with ⟹u, hu, p, H⟩ rw [mem_nhdsWithin_insert] at hu exact (H.continuousOn.continuousWithinAt hu.1).mono_of_mem hu.2 theorem ContDiffWithinAt.congr_of_eventuallyEq (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := fun m hm => let ⟹u, hu, p, H⟩ := h m hm ⟹{ x ∈ u | f₁ x = f x }, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟹hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ => And.right⟩ theorem ContDiffWithinAt.congr_of_eventuallyEq_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =á¶ [𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) h₁) (mem_of_mem_nhdsWithin (mem_insert x s) h₁ : _) theorem ContDiffWithinAt.congr_of_eventually_eq' (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =á¶ [𝓝[s] x] f) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq h₁ <| h₁.self_of_nhdsWithin hx theorem Filter.EventuallyEq.contDiffWithinAt_iff (h₁ : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟹fun H => ContDiffWithinAt.congr_of_eventuallyEq H h₁.symm hx.symm, fun H => H.congr_of_eventuallyEq h₁ hx⟩ theorem ContDiffWithinAt.congr (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin h₁) hx theorem ContDiffWithinAt.congr' (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr h₁ (h₁ _ hx) theorem ContDiffWithinAt.mono_of_mem (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := by intro m hm rcases h m hm with ⟹u, hu, p, H⟩ exact ⟹u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H⟩ theorem ContDiffWithinAt.mono (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : t ⊆ s) : ContDiffWithinAt 𝕜 n f t x := h.mono_of_mem <| Filter.mem_of_superset self_mem_nhdsWithin hst theorem ContDiffWithinAt.congr_nhds (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : 𝓝[s] x = 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := h.mono_of_mem <| hst ▾ self_mem_nhdsWithin theorem contDiffWithinAt_congr_nhds {t : Set E} (hst : 𝓝[s] x = 𝓝[t] x) : ContDiffWithinAt 𝕜 n f s x ↔ ContDiffWithinAt 𝕜 n f t x := ⟹fun h => h.congr_nhds hst, fun h => h.congr_nhds hst.symm⟩ theorem contDiffWithinAt_inter' (h : t ∈ 𝓝[s] x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr_nhds <| Eq.symm <| nhdsWithin_restrict'' _ h theorem contDiffWithinAt_inter (h : t ∈ 𝓝 x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds h) theorem contDiffWithinAt_insert_self : ContDiffWithinAt 𝕜 n f (insert x s) x ↔ ContDiffWithinAt 𝕜 n f s x := by simp_rw [ContDiffWithinAt, insert_idem] theorem contDiffWithinAt_insert {y : E} : ContDiffWithinAt 𝕜 n f (insert y s) x ↔ ContDiffWithinAt 𝕜 n f s x := by rcases eq_or_ne x y with (rfl | h) · exact contDiffWithinAt_insert_self simp_rw [ContDiffWithinAt, insert_comm x y, nhdsWithin_insert_of_ne h] alias ⟹ContDiffWithinAt.of_insert, ContDiffWithinAt.insert'⟩ := contDiffWithinAt_insert protected theorem ContDiffWithinAt.insert (h : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n f (insert x s) x := h.insert' /-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable within this set at this point. -/ theorem ContDiffWithinAt.differentiable_within_at' (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≀ n) : DifferentiableWithinAt 𝕜 f (insert x s) x := by rcases h 1 hn with ⟹u, hu, p, H⟩ rcases mem_nhdsWithin.1 hu with ⟹t, t_open, xt, tu⟩ rw [inter_comm] at tu have := ((H.mono tu).differentiableOn le_rfl) x ⟹mem_insert x s, xt⟩ exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 this theorem ContDiffWithinAt.differentiableWithinAt (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≀ n) : DifferentiableWithinAt 𝕜 f s x := (h.differentiable_within_at' hn).mono (subset_insert x s) /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt {n : ℕ} : ContDiffWithinAt 𝕜 (n + 1 : ℕ) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffWithinAt 𝕜 n f' u x := by constructor · intro h rcases h n.succ le_rfl with ⟹u, hu, p, Hp⟩ refine ⟹u, hu, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1), fun y hy => Hp.hasFDerivWithinAt (WithTop.coe_le_coe.2 (Nat.le_add_left 1 n)) hy, ?_⟩ intro m hm refine ⟹u, ?_, fun y : E => (p y).shift, ?_⟩ · -- Porting note: without the explicit argument Lean is not sure of the type. convert @self_mem_nhdsWithin _ _ x u have : x ∈ insert x s := by simp exact insert_eq_of_mem (mem_of_mem_nhdsWithin this hu) · rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp exact Hp.2.2.of_le hm · rintro ⟹u, hu, f', f'_eq_deriv, Hf'⟩ rw [contDiffWithinAt_nat] rcases Hf' n le_rfl with ⟹v, hv, p', Hp'⟩ refine ⟹v ∩ u, ?_, fun x => (p' x).unshift (f x), ?_⟩ · apply Filter.inter_mem _ hu apply nhdsWithin_le_of_mem hu exact nhdsWithin_mono _ (subset_insert x u) hv · rw [hasFTaylorSeriesUpToOn_succ_iff_right] refine ⟹fun y _ => rfl, fun y hy => ?_, ?_⟩ · change HasFDerivWithinAt (fun z => (continuousMultilinearCurryFin0 𝕜 E F).symm (f z)) (FormalMultilinearSeries.unshift (p' y) (f y) 1).curryLeft (v ∩ u) y -- Porting note: needed `erw` here. -- https://github.com/leanprover-community/mathlib4/issues/5164 erw [LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] convert (f'_eq_deriv y hy.2).mono inter_subset_right rw [← Hp'.zero_eq y hy.1] ext z change ((p' y 0) (init (@cons 0 (fun _ => E) z 0))) (@cons 0 (fun _ => E) z 0 (last 0)) = ((p' y 0) 0) z congr norm_num [eq_iff_true_of_subsingleton] · convert (Hp'.mono inter_subset_left).congr fun x hx => Hp'.zero_eq x hx.1 using 1 · ext x y change p' x 0 (init (@snoc 0 (fun _ : Fin 1 => E) 0 y)) y = p' x 0 0 y rw [init_snoc] · ext x k v y change p' x k (init (@snoc k (fun _ : Fin k.succ => E) v y)) (@snoc k (fun _ : Fin k.succ => E) v y (last k)) = p' x k v y rw [snoc_last, init_snoc] /-- A version of `contDiffWithinAt_succ_iff_hasFDerivWithinAt` where all derivatives are taken within the same set. -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt' {n : ℕ} : ContDiffWithinAt 𝕜 (n + 1 : ℕ) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) s x) ∧ ContDiffWithinAt 𝕜 n f' s x := by refine ⟹fun hf => ?_, ?_⟩ · obtain ⟹u, hu, f', huf', hf'⟩ := contDiffWithinAt_succ_iff_hasFDerivWithinAt.mp hf obtain ⟹w, hw, hxw, hwu⟩ := mem_nhdsWithin.mp hu rw [inter_comm] at hwu refine ⟹insert x s ∩ w, inter_mem_nhdsWithin _ (hw.mem_nhds hxw), inter_subset_left, f', fun y hy => ?_, ?_⟩ · refine ((huf' y <| hwu hy).mono hwu).mono_of_mem ?_ refine mem_of_superset ?_ (inter_subset_inter_left _ (subset_insert _ _)) exact inter_mem_nhdsWithin _ (hw.mem_nhds hy.2) · exact hf'.mono_of_mem (nhdsWithin_mono _ (subset_insert _ _) hu) · rw [← contDiffWithinAt_insert, contDiffWithinAt_succ_iff_hasFDerivWithinAt, insert_eq_of_mem (mem_insert _ _)] rintro ⟹u, hu, hus, f', huf', hf'⟩ exact ⟹u, hu, f', fun y hy => (huf' y hy).insert'.mono hus, hf'.insert.mono hus⟩ /-! ### Smooth functions within a set -/ variable (𝕜) /-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). -/ def ContDiffOn (n : ℕ∞) (f : E → F) (s : Set E) : Prop := ∀ x ∈ s, ContDiffWithinAt 𝕜 n f s x variable {𝕜} theorem HasFTaylorSeriesUpToOn.contDiffOn {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpToOn n f f' s) : ContDiffOn 𝕜 n f s := by intro x hx m hm use s simp only [Set.insert_eq_of_mem hx, self_mem_nhdsWithin, true_and_iff] exact ⟹f', hf.of_le hm⟩ theorem ContDiffOn.contDiffWithinAt (h : ContDiffOn 𝕜 n f s) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f s x := h x hx theorem ContDiffWithinAt.contDiffOn' {m : ℕ} (hm : (m : ℕ∞) ≀ n) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 m f (insert x s ∩ u) := by rcases h m hm with ⟹t, ht, p, hp⟩ rcases mem_nhdsWithin.1 ht with ⟹u, huo, hxu, hut⟩ rw [inter_comm] at hut exact ⟹u, huo, hxu, (hp.mono hut).contDiffOn⟩ theorem ContDiffWithinAt.contDiffOn {m : ℕ} (hm : (m : ℕ∞) ≀ n) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ContDiffOn 𝕜 m f u := let ⟹_u, uo, xu, h⟩ := h.contDiffOn' hm ⟹_, inter_mem_nhdsWithin _ (uo.mem_nhds xu), inter_subset_left, h⟩ protected theorem ContDiffWithinAt.eventually {n : ℕ} (h : ContDiffWithinAt 𝕜 n f s x) : ∀ᶠ y in 𝓝[insert x s] x, ContDiffWithinAt 𝕜 n f s y := by rcases h.contDiffOn le_rfl with ⟹u, hu, _, hd⟩ have : ∀ᶠ y : E in 𝓝[insert x s] x, u ∈ 𝓝[insert x s] y ∧ y ∈ u := (eventually_nhdsWithin_nhdsWithin.2 hu).and hu refine this.mono fun y hy => (hd y hy.2).mono_of_mem ?_ exact nhdsWithin_mono y (subset_insert _ _) hy.1 theorem ContDiffOn.of_le (h : ContDiffOn 𝕜 n f s) (hmn : m ≀ n) : ContDiffOn 𝕜 m f s := fun x hx => (h x hx).of_le hmn theorem ContDiffOn.of_succ {n : ℕ} (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 n f s := h.of_le <| WithTop.coe_le_coe.mpr le_self_add theorem ContDiffOn.one_of_succ {n : ℕ} (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 1 f s := h.of_le <| WithTop.coe_le_coe.mpr le_add_self theorem contDiffOn_iff_forall_nat_le : ContDiffOn 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≀ n → ContDiffOn 𝕜 m f s := ⟹fun H _ hm => H.of_le hm, fun H x hx m hm => H m hm x hx m le_rfl⟩ theorem contDiffOn_top : ContDiffOn 𝕜 ∞ f s ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := contDiffOn_iff_forall_nat_le.trans <| by simp only [le_top, forall_prop_of_true] theorem contDiffOn_all_iff_nat : (∀ n, ContDiffOn 𝕜 n f s) ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := by refine ⟹fun H n => H n, ?_⟩ rintro H (_ | n) exacts [contDiffOn_top.2 H, H n] theorem ContDiffOn.continuousOn (h : ContDiffOn 𝕜 n f s) : ContinuousOn f s := fun x hx => (h x hx).continuousWithinAt theorem ContDiffOn.congr (h : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s := fun x hx => (h x hx).congr h₁ (h₁ x hx) theorem contDiffOn_congr (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s ↔ ContDiffOn 𝕜 n f s := ⟹fun H => H.congr fun x hx => (h₁ x hx).symm, fun H => H.congr h₁⟩ theorem ContDiffOn.mono (h : ContDiffOn 𝕜 n f s) {t : Set E} (hst : t ⊆ s) : ContDiffOn 𝕜 n f t := fun x hx => (h x (hst hx)).mono hst theorem ContDiffOn.congr_mono (hf : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) : ContDiffOn 𝕜 n f₁ s₁ := (hf.mono hs).congr h₁ /-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/ theorem ContDiffOn.differentiableOn (h : ContDiffOn 𝕜 n f s) (hn : 1 ≀ n) : DifferentiableOn 𝕜 f s := fun x hx => (h x hx).differentiableWithinAt hn /-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/ theorem contDiffOn_of_locally_contDiffOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 n f (s ∩ u)) : ContDiffOn 𝕜 n f s := by intro x xs rcases h x xs with ⟹u, u_open, xu, hu⟩ apply (contDiffWithinAt_inter _).1 (hu x ⟹xs, xu⟩) exact IsOpen.mem_nhds u_open xu /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem contDiffOn_succ_iff_hasFDerivWithinAt {n : ℕ} : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ ∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffOn 𝕜 n f' u := by constructor · intro h x hx rcases (h x hx) n.succ le_rfl with ⟹u, hu, p, Hp⟩ refine ⟹u, hu, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1), fun y hy => Hp.hasFDerivWithinAt (WithTop.coe_le_coe.2 (Nat.le_add_left 1 n)) hy, ?_⟩ rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp intro z hz m hm refine ⟹u, ?_, fun x : E => (p x).shift, Hp.2.2.of_le hm⟩ -- Porting note: without the explicit arguments `convert` can not determine the type. convert @self_mem_nhdsWithin _ _ z u exact insert_eq_of_mem hz · intro h x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt] rcases h x hx with ⟹u, u_nhbd, f', hu, hf'⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert _ _) u_nhbd exact ⟹u, u_nhbd, f', hu, hf' x this⟩ /-! ### Iterated derivative within a set -/ variable (𝕜) /-- The `n`-th derivative of a function along a set, defined inductively by saying that the `n+1`-th derivative of `f` is the derivative of the `n`-th derivative of `f` along this set, together with an uncurrying step to see it as a multilinear map in `n+1` variables.. -/ noncomputable def iteratedFDerivWithin (n : ℕ) (f : E → F) (s : Set E) : E → E[×n]→L[𝕜] F := Nat.recOn n (fun x => ContinuousMultilinearMap.curry0 𝕜 E (f x)) fun _ rec x => ContinuousLinearMap.uncurryLeft (fderivWithin 𝕜 rec s x) /-- Formal Taylor series associated to a function within a set. -/ def ftaylorSeriesWithin (f : E → F) (s : Set E) (x : E) : FormalMultilinearSeries 𝕜 E F := fun n => iteratedFDerivWithin 𝕜 n f s x variable {𝕜} @[simp] theorem iteratedFDerivWithin_zero_apply (m : Fin 0 → E) : (iteratedFDerivWithin 𝕜 0 f s x : (Fin 0 → E) → F) m = f x := rfl theorem iteratedFDerivWithin_zero_eq_comp : iteratedFDerivWithin 𝕜 0 f s = (continuousMultilinearCurryFin0 𝕜 E F).symm ∘ f := rfl @[simp] theorem norm_iteratedFDerivWithin_zero : ‖iteratedFDerivWithin 𝕜 0 f s x‖ = ‖f x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDerivWithin_zero_eq_comp, comp_apply, LinearIsometryEquiv.norm_map] theorem iteratedFDerivWithin_succ_apply_left {n : ℕ} (m : Fin (n + 1) → E) : (iteratedFDerivWithin 𝕜 (n + 1) f s x : (Fin (n + 1) → E) → F) m = (fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n f s) s x : E → E[×n]→L[𝕜] F) (m 0) (tail m) := rfl /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the derivative of the `n`-th derivative. -/ theorem iteratedFDerivWithin_succ_eq_comp_left {n : ℕ} : iteratedFDerivWithin 𝕜 (n + 1) f s = (continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) => E) F : (E →L[𝕜] (E [×n]→L[𝕜] F)) → (E [×n.succ]→L[𝕜] F)) ∘ fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n f s) s := rfl theorem fderivWithin_iteratedFDerivWithin {s : Set E} {n : ℕ} : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n f s) s = (continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) => E) F).symm ∘ iteratedFDerivWithin 𝕜 (n + 1) f s := by rw [iteratedFDerivWithin_succ_eq_comp_left] ext1 x simp only [Function.comp_apply, LinearIsometryEquiv.symm_apply_apply] theorem norm_fderivWithin_iteratedFDerivWithin {n : ℕ} : ‖fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n f s) s x‖ = ‖iteratedFDerivWithin 𝕜 (n + 1) f s x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDerivWithin_succ_eq_comp_left, comp_apply, LinearIsometryEquiv.norm_map] theorem iteratedFDerivWithin_succ_apply_right {n : ℕ} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (m : Fin (n + 1) → E) : (iteratedFDerivWithin 𝕜 (n + 1) f s x : (Fin (n + 1) → E) → F) m = iteratedFDerivWithin 𝕜 n (fun y => fderivWithin 𝕜 f s y) s x (init m) (m (last n)) := by induction' n with n IH generalizing x · rw [iteratedFDerivWithin_succ_eq_comp_left, iteratedFDerivWithin_zero_eq_comp, iteratedFDerivWithin_zero_apply, Function.comp_apply, LinearIsometryEquiv.comp_fderivWithin _ (hs x hx)] rfl · let I := continuousMultilinearCurryRightEquiv' 𝕜 n E F have A : ∀ y ∈ s, iteratedFDerivWithin 𝕜 n.succ f s y = (I ∘ iteratedFDerivWithin 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) y := fun y hy ↩ by ext m rw [@IH y hy m] rfl calc (iteratedFDerivWithin 𝕜 (n + 2) f s x : (Fin (n + 2) → E) → F) m = (fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n.succ f s) s x : E → E[×n + 1]→L[𝕜] F) (m 0) (tail m) := rfl _ = (fderivWithin 𝕜 (I ∘ iteratedFDerivWithin 𝕜 n (fderivWithin 𝕜 f s) s) s x : E → E[×n + 1]→L[𝕜] F) (m 0) (tail m) := by rw [fderivWithin_congr A (A x hx)] _ = (I ∘ fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n (fderivWithin 𝕜 f s) s) s x : E → E[×n + 1]→L[𝕜] F) (m 0) (tail m) := by #adaptation_note /-- After https://github.com/leanprover/lean4/pull/4119 we need to either use `set_option maxSynthPendingDepth 2 in` or fill in an explicit argument as ``` simp only [LinearIsometryEquiv.comp_fderivWithin _ (f := iteratedFDerivWithin 𝕜 n (fderivWithin 𝕜 f s) s) (hs x hx)] ``` -/ set_option maxSynthPendingDepth 2 in simp only [LinearIsometryEquiv.comp_fderivWithin _ (hs x hx)] rfl _ = (fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) s x : E → E[×n]→L[𝕜] E →L[𝕜] F) (m 0) (init (tail m)) ((tail m) (last n)) := rfl _ = iteratedFDerivWithin 𝕜 (Nat.succ n) (fun y => fderivWithin 𝕜 f s y) s x (init m) (m (last (n + 1))) := by rw [iteratedFDerivWithin_succ_apply_left, tail_init_eq_init_tail] rfl /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the `n`-th derivative of the derivative. -/ theorem iteratedFDerivWithin_succ_eq_comp_right {n : ℕ} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 (n + 1) f s x = (continuousMultilinearCurryRightEquiv' 𝕜 n E F ∘ iteratedFDerivWithin 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) x := by ext m; rw [iteratedFDerivWithin_succ_apply_right hs hx]; rfl theorem norm_iteratedFDerivWithin_fderivWithin {n : ℕ} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : ‖iteratedFDerivWithin 𝕜 n (fderivWithin 𝕜 f s) s x‖ = ‖iteratedFDerivWithin 𝕜 (n + 1) f s x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDerivWithin_succ_eq_comp_right hs hx, comp_apply, LinearIsometryEquiv.norm_map] @[simp] theorem iteratedFDerivWithin_one_apply (h : UniqueDiffWithinAt 𝕜 s x) (m : Fin 1 → E) : iteratedFDerivWithin 𝕜 1 f s x m = fderivWithin 𝕜 f s x (m 0) := by simp only [iteratedFDerivWithin_succ_apply_left, iteratedFDerivWithin_zero_eq_comp, (continuousMultilinearCurryFin0 𝕜 E F).symm.comp_fderivWithin h] rfl /-- On a set of unique differentiability, the second derivative is obtained by taking the derivative of the derivative. -/ lemma iteratedFDerivWithin_two_apply (f : E → F) {z : E} (hs : UniqueDiffOn 𝕜 s) (hz : z ∈ s) (m : Fin 2 → E) : iteratedFDerivWithin 𝕜 2 f s z m = fderivWithin 𝕜 (fderivWithin 𝕜 f s) s z (m 0) (m 1) := by simp only [iteratedFDerivWithin_succ_apply_right hs hz] rfl theorem Filter.EventuallyEq.iteratedFDerivWithin' (h : f₁ =á¶ [𝓝[s] x] f) (ht : t ⊆ s) (n : ℕ) : iteratedFDerivWithin 𝕜 n f₁ t =á¶ [𝓝[s] x] iteratedFDerivWithin 𝕜 n f t := by induction' n with n ihn · exact h.mono fun y hy => DFunLike.ext _ _ fun _ => hy · have : fderivWithin 𝕜 _ t =á¶ [𝓝[s] x] fderivWithin 𝕜 _ t := ihn.fderivWithin' ht apply this.mono intro y hy simp only [iteratedFDerivWithin_succ_eq_comp_left, hy, (· ∘ ·)] protected theorem Filter.EventuallyEq.iteratedFDerivWithin (h : f₁ =á¶ [𝓝[s] x] f) (n : ℕ) : iteratedFDerivWithin 𝕜 n f₁ s =á¶ [𝓝[s] x] iteratedFDerivWithin 𝕜 n f s := h.iteratedFDerivWithin' Subset.rfl n /-- If two functions coincide in a neighborhood of `x` within a set `s` and at `x`, then their iterated differentials within this set at `x` coincide. -/ theorem Filter.EventuallyEq.iteratedFDerivWithin_eq (h : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) (n : ℕ) : iteratedFDerivWithin 𝕜 n f₁ s x = iteratedFDerivWithin 𝕜 n f s x := have : f₁ =á¶ [𝓝[insert x s] x] f := by simpa [EventuallyEq, hx] (this.iteratedFDerivWithin' (subset_insert _ _) n).self_of_nhdsWithin (mem_insert _ _) /-- If two functions coincide on a set `s`, then their iterated differentials within this set coincide. See also `Filter.EventuallyEq.iteratedFDerivWithin_eq` and `Filter.EventuallyEq.iteratedFDerivWithin`. -/ theorem iteratedFDerivWithin_congr (hs : EqOn f₁ f s) (hx : x ∈ s) (n : ℕ) : iteratedFDerivWithin 𝕜 n f₁ s x = iteratedFDerivWithin 𝕜 n f s x := (hs.eventuallyEq.filter_mono inf_le_right).iteratedFDerivWithin_eq (hs hx) _ /-- If two functions coincide on a set `s`, then their iterated differentials within this set coincide. See also `Filter.EventuallyEq.iteratedFDerivWithin_eq` and `Filter.EventuallyEq.iteratedFDerivWithin`. -/ protected theorem Set.EqOn.iteratedFDerivWithin (hs : EqOn f₁ f s) (n : ℕ) : EqOn (iteratedFDerivWithin 𝕜 n f₁ s) (iteratedFDerivWithin 𝕜 n f s) s := fun _x hx => iteratedFDerivWithin_congr hs hx n theorem iteratedFDerivWithin_eventually_congr_set' (y : E) (h : s =á¶ [𝓝[{y}ᶜ] x] t) (n : ℕ) : iteratedFDerivWithin 𝕜 n f s =á¶ [𝓝 x] iteratedFDerivWithin 𝕜 n f t := by induction' n with n ihn generalizing x · rfl · refine (eventually_nhds_nhdsWithin.2 h).mono fun y hy => ?_ simp only [iteratedFDerivWithin_succ_eq_comp_left, (· ∘ ·)] rw [(ihn hy).fderivWithin_eq_nhds, fderivWithin_congr_set' _ hy] theorem iteratedFDerivWithin_eventually_congr_set (h : s =á¶ [𝓝 x] t) (n : ℕ) : iteratedFDerivWithin 𝕜 n f s =á¶ [𝓝 x] iteratedFDerivWithin 𝕜 n f t := iteratedFDerivWithin_eventually_congr_set' x (h.filter_mono inf_le_left) n theorem iteratedFDerivWithin_congr_set (h : s =á¶ [𝓝 x] t) (n : ℕ) : iteratedFDerivWithin 𝕜 n f s x = iteratedFDerivWithin 𝕜 n f t x := (iteratedFDerivWithin_eventually_congr_set h n).self_of_nhds /-- The iterated differential within a set `s` at a point `x` is not modified if one intersects `s` with a neighborhood of `x` within `s`. -/ theorem iteratedFDerivWithin_inter' {n : ℕ} (hu : u ∈ 𝓝[s] x) : iteratedFDerivWithin 𝕜 n f (s ∩ u) x = iteratedFDerivWithin 𝕜 n f s x := iteratedFDerivWithin_congr_set (nhdsWithin_eq_iff_eventuallyEq.1 <| nhdsWithin_inter_of_mem' hu) _ /-- The iterated differential within a set `s` at a point `x` is not modified if one intersects `s` with a neighborhood of `x`. -/ theorem iteratedFDerivWithin_inter {n : ℕ} (hu : u ∈ 𝓝 x) : iteratedFDerivWithin 𝕜 n f (s ∩ u) x = iteratedFDerivWithin 𝕜 n f s x := iteratedFDerivWithin_inter' (mem_nhdsWithin_of_mem_nhds hu) /-- The iterated differential within a set `s` at a point `x` is not modified if one intersects `s` with an open set containing `x`. -/ theorem iteratedFDerivWithin_inter_open {n : ℕ} (hu : IsOpen u) (hx : x ∈ u) : iteratedFDerivWithin 𝕜 n f (s ∩ u) x = iteratedFDerivWithin 𝕜 n f s x := iteratedFDerivWithin_inter (hu.mem_nhds hx) @[simp] theorem contDiffOn_zero : ContDiffOn 𝕜 0 f s ↔ ContinuousOn f s := by refine ⟹fun H => H.continuousOn, fun H => ?_⟩ intro x hx m hm have : (m : ℕ∞) = 0 := le_antisymm hm bot_le rw [this] refine ⟹insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ rw [hasFTaylorSeriesUpToOn_zero_iff] exact ⟹by rwa [insert_eq_of_mem hx], fun x _ => by simp [ftaylorSeriesWithin]⟩ theorem contDiffWithinAt_zero (hx : x ∈ s) : ContDiffWithinAt 𝕜 0 f s x ↔ ∃ u ∈ 𝓝[s] x, ContinuousOn f (s ∩ u) := by constructor · intro h obtain ⟹u, H, p, hp⟩ := h 0 le_rfl refine ⟹u, ?_, ?_⟩ · simpa [hx] using H · simp only [Nat.cast_zero, hasFTaylorSeriesUpToOn_zero_iff] at hp exact hp.1.mono inter_subset_right · rintro ⟹u, H, hu⟩ rw [← contDiffWithinAt_inter' H] have h' : x ∈ s ∩ u := ⟹hx, mem_of_mem_nhdsWithin hx H⟩ exact (contDiffOn_zero.mpr hu).contDiffWithinAt h' /-- On a set with unique differentiability, any choice of iterated differential has to coincide with the one we have chosen in `iteratedFDerivWithin 𝕜 m f s`. -/ theorem HasFTaylorSeriesUpToOn.eq_iteratedFDerivWithin_of_uniqueDiffOn (h : HasFTaylorSeriesUpToOn n f p s) {m : ℕ} (hmn : (m : ℕ∞) ≀ n) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : p x m = iteratedFDerivWithin 𝕜 m f s x := by induction' m with m IH generalizing x · rw [h.zero_eq' hx, iteratedFDerivWithin_zero_eq_comp]; rfl · have A : (m : ℕ∞) < n := lt_of_lt_of_le (WithTop.coe_lt_coe.2 (lt_add_one m)) hmn have : HasFDerivWithinAt (fun y : E => iteratedFDerivWithin 𝕜 m f s y) (ContinuousMultilinearMap.curryLeft (p x (Nat.succ m))) s x := (h.fderivWithin m A x hx).congr (fun y hy => (IH (le_of_lt A) hy).symm) (IH (le_of_lt A) hx).symm rw [iteratedFDerivWithin_succ_eq_comp_left, Function.comp_apply, this.fderivWithin (hs x hx)] exact (ContinuousMultilinearMap.uncurry_curryLeft _).symm @[deprecated (since := "2024-03-28")] alias HasFTaylorSeriesUpToOn.eq_ftaylor_series_of_uniqueDiffOn := HasFTaylorSeriesUpToOn.eq_iteratedFDerivWithin_of_uniqueDiffOn /-- When a function is `C^n` in a set `s` of unique differentiability, it admits `ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/ protected theorem ContDiffOn.ftaylorSeriesWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) : HasFTaylorSeriesUpToOn n f (ftaylorSeriesWithin 𝕜 f s) s := by constructor · intro x _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.uncurry0_apply, iteratedFDerivWithin_zero_apply] · intro m hm x hx rcases (h x hx) m.succ (ENat.add_one_le_of_lt hm) with ⟹u, hu, p, Hp⟩ rw [insert_eq_of_mem hx] at hu rcases mem_nhdsWithin.1 hu with ⟹o, o_open, xo, ho⟩ rw [inter_comm] at ho have : p x m.succ = ftaylorSeriesWithin 𝕜 f s x m.succ := by change p x m.succ = iteratedFDerivWithin 𝕜 m.succ f s x rw [← iteratedFDerivWithin_inter_open o_open xo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟹hx, xo⟩ rw [← this, ← hasFDerivWithinAt_inter (IsOpen.mem_nhds o_open xo)] have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟹hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn (WithTop.coe_le_coe.2 (Nat.le_succ m)) (hs.inter o_open) ⟹hy, yo⟩ exact ((Hp.mono ho).fderivWithin m (WithTop.coe_lt_coe.2 (lt_add_one m)) x ⟹hx, xo⟩).congr (fun y hy => (A y hy).symm) (A x ⟹hx, xo⟩).symm · intro m hm apply continuousOn_of_locally_continuousOn intro x hx rcases h x hx m hm with ⟹u, hu, p, Hp⟩ rcases mem_nhdsWithin.1 hu with ⟹o, o_open, xo, ho⟩ rw [insert_eq_of_mem hx] at ho rw [inter_comm] at ho refine ⟹o, o_open, xo, ?_⟩ have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟹hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟹hy, yo⟩ exact ((Hp.mono ho).cont m le_rfl).congr fun y hy => (A y hy).symm theorem contDiffOn_of_continuousOn_differentiableOn (Hcont : ∀ m : ℕ, (m : ℕ∞) ≀ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) (Hdiff : ∀ m : ℕ, (m : ℕ∞) < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s) : ContDiffOn 𝕜 n f s := by intro x hx m hm rw [insert_eq_of_mem hx] refine ⟹s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ constructor · intro y _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.uncurry0_apply, iteratedFDerivWithin_zero_apply] · intro k hk y hy convert (Hdiff k (lt_of_lt_of_le hk hm) y hy).hasFDerivWithinAt · intro k hk exact Hcont k (le_trans hk hm) theorem contDiffOn_of_differentiableOn (h : ∀ m : ℕ, (m : ℕ∞) ≀ n → DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) : ContDiffOn 𝕜 n f s := contDiffOn_of_continuousOn_differentiableOn (fun m hm => (h m hm).continuousOn) fun m hm => h m (le_of_lt hm) theorem ContDiffOn.continuousOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : (m : ℕ∞) ≀ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedFDerivWithin 𝕜 m f s) s := (h.ftaylorSeriesWithin hs).cont m hmn theorem ContDiffOn.differentiableOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : (m : ℕ∞) < n) (hs : UniqueDiffOn 𝕜 s) : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s := fun x hx => ((h.ftaylorSeriesWithin hs).fderivWithin m hmn x hx).differentiableWithinAt theorem ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin {m : ℕ} (h : ContDiffWithinAt 𝕜 n f s x) (hmn : (m : ℕ∞) < n) (hs : UniqueDiffOn 𝕜 (insert x s)) : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f s) s x := by rcases h.contDiffOn' (ENat.add_one_le_of_lt hmn) with ⟹u, uo, xu, hu⟩ set t := insert x s ∩ u have A : t =á¶ [𝓝[≠] x] s := by simp only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter'] rw [← inter_assoc, nhdsWithin_inter_of_mem', ← diff_eq_compl_inter, insert_diff_of_mem, diff_eq_compl_inter] exacts [rfl, mem_nhdsWithin_of_mem_nhds (uo.mem_nhds xu)] have B : iteratedFDerivWithin 𝕜 m f s =á¶ [𝓝 x] iteratedFDerivWithin 𝕜 m f t := iteratedFDerivWithin_eventually_congr_set' _ A.symm _ have C : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f t) t x := hu.differentiableOn_iteratedFDerivWithin (Nat.cast_lt.2 m.lt_succ_self) (hs.inter uo) x ⟹mem_insert _ _, xu⟩ rw [differentiableWithinAt_congr_set' _ A] at C exact C.congr_of_eventuallyEq (B.filter_mono inf_le_left) B.self_of_nhds theorem contDiffOn_iff_continuousOn_differentiableOn (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, (m : ℕ∞) ≀ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧ ∀ m : ℕ, (m : ℕ∞) < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := ⟹fun h => ⟹fun _m hm => h.continuousOn_iteratedFDerivWithin hm hs, fun _m hm => h.differentiableOn_iteratedFDerivWithin hm hs⟩, fun h => contDiffOn_of_continuousOn_differentiableOn h.1 h.2⟩ theorem contDiffOn_succ_of_fderivWithin {n : ℕ} (hf : DifferentiableOn 𝕜 f s) (h : ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s := by intro x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt, insert_eq_of_mem hx] exact ⟹s, self_mem_nhdsWithin, fderivWithin 𝕜 f s, fun y hy => (hf y hy).hasFDerivWithinAt, h x hx⟩ /-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (expressed with `fderivWithin`) is `C^n`. -/ theorem contDiffOn_succ_iff_fderivWithin {n : ℕ} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s := by refine ⟹fun H => ?_, fun h => contDiffOn_succ_of_fderivWithin h.1 h.2⟩ refine ⟹H.differentiableOn (WithTop.coe_le_coe.2 (Nat.le_add_left 1 n)), fun x hx => ?_⟩ rcases contDiffWithinAt_succ_iff_hasFDerivWithinAt.1 (H x hx) with ⟹u, hu, f', hff', hf'⟩ rcases mem_nhdsWithin.1 hu with ⟹o, o_open, xo, ho⟩ rw [inter_comm, insert_eq_of_mem hx] at ho have := hf'.mono ho rw [contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds o_open xo))] at this apply this.congr_of_eventually_eq' _ hx have : o ∩ s ∈ 𝓝[s] x := mem_nhdsWithin.2 ⟹o, o_open, xo, Subset.refl _⟩ rw [inter_comm] at this refine Filter.eventuallyEq_of_mem this fun y hy => ?_ have A : fderivWithin 𝕜 f (s ∩ o) y = f' y := ((hff' y (ho hy)).mono ho).fderivWithin (hs.inter o_open y hy) rwa [fderivWithin_inter (o_open.mem_nhds hy.2)] at A theorem contDiffOn_succ_iff_hasFDerivWithin {n : ℕ} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ ∃ f' : E → E →L[𝕜] F, ContDiffOn 𝕜 n f' s ∧ ∀ x, x ∈ s → HasFDerivWithinAt f (f' x) s x := by rw [contDiffOn_succ_iff_fderivWithin hs] refine ⟹fun h => ⟹fderivWithin 𝕜 f s, h.2, fun x hx => (h.1 x hx).hasFDerivWithinAt⟩, fun h => ?_⟩ rcases h with ⟹f', h1, h2⟩ refine ⟹fun x hx => (h2 x hx).differentiableWithinAt, fun x hx => ?_⟩ exact (h1 x hx).congr' (fun y hy => (h2 y hy).fderivWithin (hs y hy)) hx /-- A function is `C^(n + 1)` on an open domain if and only if it is differentiable there, and its derivative (expressed with `fderiv`) is `C^n`. -/ theorem contDiffOn_succ_iff_fderiv_of_isOpen {n : ℕ} (hs : IsOpen s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 n (fun y => fderiv 𝕜 f y) s := by rw [contDiffOn_succ_iff_fderivWithin hs.uniqueDiffOn] exact Iff.rfl.and (contDiffOn_congr fun x hx ↩ fderivWithin_of_isOpen hs hx) /-- A function is `C^∞` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (expressed with `fderivWithin`) is `C^∞`. -/ theorem contDiffOn_top_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fun y => fderivWithin 𝕜 f s y) s := by constructor · intro h refine ⟹h.differentiableOn le_top, ?_⟩ refine contDiffOn_top.2 fun n => ((contDiffOn_succ_iff_fderivWithin hs).1 ?_).2 exact h.of_le le_top · intro h refine contDiffOn_top.2 fun n => ?_ have A : (n : ℕ∞) ≀ ∞ := le_top apply ((contDiffOn_succ_iff_fderivWithin hs).2 ⟹h.1, h.2.of_le A⟩).of_le exact WithTop.coe_le_coe.2 (Nat.le_succ n) /-- A function is `C^∞` on an open domain if and only if it is differentiable there, and its derivative (expressed with `fderiv`) is `C^∞`. -/ theorem contDiffOn_top_iff_fderiv_of_isOpen (hs : IsOpen s) : ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fun y => fderiv 𝕜 f y) s := by rw [contDiffOn_top_iff_fderivWithin hs.uniqueDiffOn] exact Iff.rfl.and <| contDiffOn_congr fun x hx ↩ fderivWithin_of_isOpen hs hx protected theorem ContDiffOn.fderivWithin (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≀ n) : ContDiffOn 𝕜 m (fun y => fderivWithin 𝕜 f s y) s := by cases' m with m · change ∞ + 1 ≀ n at hmn have : n = ∞ := by simpa using hmn rw [this] at hf exact ((contDiffOn_top_iff_fderivWithin hs).1 hf).2 · change (m.succ : ℕ∞) ≀ n at hmn exact ((contDiffOn_succ_iff_fderivWithin hs).1 (hf.of_le hmn)).2 theorem ContDiffOn.fderiv_of_isOpen (hf : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hmn : m + 1 ≀ n) : ContDiffOn 𝕜 m (fun y => fderiv 𝕜 f y) s := (hf.fderivWithin hs.uniqueDiffOn hmn).congr fun _ hx => (fderivWithin_of_isOpen hs hx).symm theorem ContDiffOn.continuousOn_fderivWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hn : 1 ≀ n) : ContinuousOn (fun x => fderivWithin 𝕜 f s x) s := ((contDiffOn_succ_iff_fderivWithin hs).1 (h.of_le hn)).2.continuousOn theorem ContDiffOn.continuousOn_fderiv_of_isOpen (h : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hn : 1 ≀ n) : ContinuousOn (fun x => fderiv 𝕜 f x) s := ((contDiffOn_succ_iff_fderiv_of_isOpen hs).1 (h.of_le hn)).2.continuousOn /-! ### Functions with a Taylor series on the whole space -/ /-- `HasFTaylorSeriesUpTo n f p` registers the fact that `p 0 = f` and `p (m+1)` is a derivative of `p m` for `m < n`, and is continuous for `m ≀ n`. This is a predicate analogous to `HasFDerivAt` but for higher order derivatives. Notice that `p` does not sum up to `f` on the diagonal (`FormalMultilinearSeries.sum`), even if `f` is analytic and `n = ∞`: an addition `1/m!` factor on the `m`th term is necessary for that. -/ structure HasFTaylorSeriesUpTo (n : ℕ∞) (f : E → F) (p : E → FormalMultilinearSeries 𝕜 E F) : Prop where zero_eq : ∀ x, (p x 0).uncurry0 = f x fderiv : ∀ m : ℕ, (m : ℕ∞) < n → ∀ x, HasFDerivAt (fun y => p y m) (p x m.succ).curryLeft x cont : ∀ m : ℕ, (m : ℕ∞) ≀ n → Continuous fun x => p x m theorem HasFTaylorSeriesUpTo.zero_eq' (h : HasFTaylorSeriesUpTo n f p) (x : E) : p x 0 = (continuousMultilinearCurryFin0 𝕜 E F).symm (f x) := by rw [← h.zero_eq x] exact (p x 0).uncurry0_curry0.symm theorem hasFTaylorSeriesUpToOn_univ_iff : HasFTaylorSeriesUpToOn n f p univ ↔ HasFTaylorSeriesUpTo n f p := by constructor · intro H constructor · exact fun x => H.zero_eq x (mem_univ x) · intro m hm x rw [← hasFDerivWithinAt_univ] exact H.fderivWithin m hm x (mem_univ x) · intro m hm rw [continuous_iff_continuousOn_univ] exact H.cont m hm · intro H constructor · exact fun x _ => H.zero_eq x · intro m hm x _ rw [hasFDerivWithinAt_univ] exact H.fderiv m hm x · intro m hm rw [← continuous_iff_continuousOn_univ] exact H.cont m hm theorem HasFTaylorSeriesUpTo.hasFTaylorSeriesUpToOn (h : HasFTaylorSeriesUpTo n f p) (s : Set E) : HasFTaylorSeriesUpToOn n f p s := (hasFTaylorSeriesUpToOn_univ_iff.2 h).mono (subset_univ _) theorem HasFTaylorSeriesUpTo.ofLe (h : HasFTaylorSeriesUpTo n f p) (hmn : m ≀ n) : HasFTaylorSeriesUpTo m f p := by rw [← hasFTaylorSeriesUpToOn_univ_iff] at h ⊢; exact h.of_le hmn theorem HasFTaylorSeriesUpTo.continuous (h : HasFTaylorSeriesUpTo n f p) : Continuous f := by rw [← hasFTaylorSeriesUpToOn_univ_iff] at h rw [continuous_iff_continuousOn_univ] exact h.continuousOn theorem hasFTaylorSeriesUpTo_zero_iff : HasFTaylorSeriesUpTo 0 f p ↔ Continuous f ∧ ∀ x, (p x 0).uncurry0 = f x := by simp [hasFTaylorSeriesUpToOn_univ_iff.symm, continuous_iff_continuousOn_univ, hasFTaylorSeriesUpToOn_zero_iff] theorem hasFTaylorSeriesUpTo_top_iff : HasFTaylorSeriesUpTo ∞ f p ↔ ∀ n : ℕ, HasFTaylorSeriesUpTo n f p := by simp only [← hasFTaylorSeriesUpToOn_univ_iff, hasFTaylorSeriesUpToOn_top_iff] /-- In the case that `n = ∞` we don't need the continuity assumption in `HasFTaylorSeriesUpTo`. -/ theorem hasFTaylorSeriesUpTo_top_iff' : HasFTaylorSeriesUpTo ∞ f p ↔ (∀ x, (p x 0).uncurry0 = f x) ∧ ∀ (m : ℕ) (x), HasFDerivAt (fun y => p y m) (p x m.succ).curryLeft x := by simp only [← hasFTaylorSeriesUpToOn_univ_iff, hasFTaylorSeriesUpToOn_top_iff', mem_univ, forall_true_left, hasFDerivWithinAt_univ] /-- If a function has a Taylor series at order at least `1`, then the term of order `1` of this series is a derivative of `f`. -/ theorem HasFTaylorSeriesUpTo.hasFDerivAt (h : HasFTaylorSeriesUpTo n f p) (hn : 1 ≀ n) (x : E) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) x := by rw [← hasFDerivWithinAt_univ] exact (hasFTaylorSeriesUpToOn_univ_iff.2 h).hasFDerivWithinAt hn (mem_univ _) theorem HasFTaylorSeriesUpTo.differentiable (h : HasFTaylorSeriesUpTo n f p) (hn : 1 ≀ n) : Differentiable 𝕜 f := fun x => (h.hasFDerivAt hn x).differentiableAt /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p.shift` is a Taylor series up to `n` for `p 1`, which is a derivative of `f`. -/ theorem hasFTaylorSeriesUpTo_succ_iff_right {n : ℕ} : HasFTaylorSeriesUpTo (n + 1 : ℕ) f p ↔ (∀ x, (p x 0).uncurry0 = f x) ∧ (∀ x, HasFDerivAt (fun y => p y 0) (p x 1).curryLeft x) ∧ HasFTaylorSeriesUpTo n (fun x => continuousMultilinearCurryFin1 𝕜 E F (p x 1)) fun x => (p x).shift := by simp only [hasFTaylorSeriesUpToOn_succ_iff_right, ← hasFTaylorSeriesUpToOn_univ_iff, mem_univ, forall_true_left, hasFDerivWithinAt_univ] /-! ### Smooth functions at a point -/ variable (𝕜) /-- A function is continuously differentiable up to `n` at a point `x` if, for any integer `k ≀ n`, there is a neighborhood of `x` where `f` admits derivatives up to order `n`, which are continuous. -/ def ContDiffAt (n : ℕ∞) (f : E → F) (x : E) : Prop := ContDiffWithinAt 𝕜 n f univ x variable {𝕜} theorem contDiffWithinAt_univ : ContDiffWithinAt 𝕜 n f univ x ↔ ContDiffAt 𝕜 n f x := Iff.rfl theorem contDiffAt_top : ContDiffAt 𝕜 ∞ f x ↔ ∀ n : ℕ, ContDiffAt 𝕜 n f x := by simp [← contDiffWithinAt_univ, contDiffWithinAt_top] theorem ContDiffAt.contDiffWithinAt (h : ContDiffAt 𝕜 n f x) : ContDiffWithinAt 𝕜 n f s x := h.mono (subset_univ _) theorem ContDiffWithinAt.contDiffAt (h : ContDiffWithinAt 𝕜 n f s x) (hx : s ∈ 𝓝 x) : ContDiffAt 𝕜 n f x := by rwa [ContDiffAt, ← contDiffWithinAt_inter hx, univ_inter] theorem ContDiffOn.contDiffAt (h : ContDiffOn 𝕜 n f s) (hx : s ∈ 𝓝 x) : ContDiffAt 𝕜 n f x := (h _ (mem_of_mem_nhds hx)).contDiffAt hx theorem ContDiffAt.congr_of_eventuallyEq (h : ContDiffAt 𝕜 n f x) (hg : f₁ =á¶ [𝓝 x] f) : ContDiffAt 𝕜 n f₁ x := h.congr_of_eventually_eq' (by rwa [nhdsWithin_univ]) (mem_univ x) theorem ContDiffAt.of_le (h : ContDiffAt 𝕜 n f x) (hmn : m ≀ n) : ContDiffAt 𝕜 m f x := ContDiffWithinAt.of_le h hmn theorem ContDiffAt.continuousAt (h : ContDiffAt 𝕜 n f x) : ContinuousAt f x := by simpa [continuousWithinAt_univ] using h.continuousWithinAt /-- If a function is `C^n` with `n ≥ 1` at a point, then it is differentiable there. -/ theorem ContDiffAt.differentiableAt (h : ContDiffAt 𝕜 n f x) (hn : 1 ≀ n) : DifferentiableAt 𝕜 f x := by simpa [hn, differentiableWithinAt_univ] using h.differentiableWithinAt nonrec lemma ContDiffAt.contDiffOn {m : ℕ} (h : ContDiffAt 𝕜 n f x) (hm : m ≀ n) : ∃ u ∈ 𝓝 x, ContDiffOn 𝕜 m f u := by simpa [nhdsWithin_univ] using h.contDiffOn hm /-- A function is `C^(n + 1)` at a point iff locally, it has a derivative which is `C^n`. -/ theorem contDiffAt_succ_iff_hasFDerivAt {n : ℕ} : ContDiffAt 𝕜 (n + 1 : ℕ) f x ↔ ∃ f' : E → E →L[𝕜] F, (∃ u ∈ 𝓝 x, ∀ x ∈ u, HasFDerivAt f (f' x) x) ∧ ContDiffAt 𝕜 n f' x := by rw [← contDiffWithinAt_univ, contDiffWithinAt_succ_iff_hasFDerivWithinAt] simp only [nhdsWithin_univ, exists_prop, mem_univ, insert_eq_of_mem] constructor · rintro ⟹u, H, f', h_fderiv, h_cont_diff⟩ rcases mem_nhds_iff.mp H with ⟹t, htu, ht, hxt⟩ refine ⟹f', ⟹t, ?_⟩, h_cont_diff.contDiffAt H⟩ refine ⟹mem_nhds_iff.mpr ⟹t, Subset.rfl, ht, hxt⟩, ?_⟩ intro y hyt refine (h_fderiv y (htu hyt)).hasFDerivAt ?_ exact mem_nhds_iff.mpr ⟹t, htu, ht, hyt⟩ · rintro ⟹f', ⟹u, H, h_fderiv⟩, h_cont_diff⟩ refine ⟹u, H, f', ?_, h_cont_diff.contDiffWithinAt⟩ intro x hxu exact (h_fderiv x hxu).hasFDerivWithinAt protected theorem ContDiffAt.eventually {n : ℕ} (h : ContDiffAt 𝕜 n f x) : ∀ᶠ y in 𝓝 x, ContDiffAt 𝕜 n f y := by simpa [nhdsWithin_univ] using ContDiffWithinAt.eventually h /-! ### Smooth functions -/ variable (𝕜) /-- A function is continuously differentiable up to `n` if it admits derivatives up to order `n`, which are continuous. Contrary to the case of definitions in domains (where derivatives might not be unique) we do not need to localize the definition in space or time. -/ def ContDiff (n : ℕ∞) (f : E → F) : Prop := ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpTo n f p variable {𝕜} /-- If `f` has a Taylor series up to `n`, then it is `C^n`. -/ theorem HasFTaylorSeriesUpTo.contDiff {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpTo n f f') : ContDiff 𝕜 n f := ⟹f', hf⟩ theorem contDiffOn_univ : ContDiffOn 𝕜 n f univ ↔ ContDiff 𝕜 n f := by constructor · intro H use ftaylorSeriesWithin 𝕜 f univ rw [← hasFTaylorSeriesUpToOn_univ_iff] exact H.ftaylorSeriesWithin uniqueDiffOn_univ · rintro ⟹p, hp⟩ x _ m hm exact ⟹univ, Filter.univ_sets _, p, (hp.hasFTaylorSeriesUpToOn univ).of_le hm⟩ theorem contDiff_iff_contDiffAt : ContDiff 𝕜 n f ↔ ∀ x, ContDiffAt 𝕜 n f x := by simp [← contDiffOn_univ, ContDiffOn, ContDiffAt] theorem ContDiff.contDiffAt (h : ContDiff 𝕜 n f) : ContDiffAt 𝕜 n f x := contDiff_iff_contDiffAt.1 h x theorem ContDiff.contDiffWithinAt (h : ContDiff 𝕜 n f) : ContDiffWithinAt 𝕜 n f s x := h.contDiffAt.contDiffWithinAt theorem contDiff_top : ContDiff 𝕜 ∞ f ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by simp [contDiffOn_univ.symm, contDiffOn_top] theorem contDiff_all_iff_nat : (∀ n, ContDiff 𝕜 n f) ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by simp only [← contDiffOn_univ, contDiffOn_all_iff_nat] theorem ContDiff.contDiffOn (h : ContDiff 𝕜 n f) : ContDiffOn 𝕜 n f s := (contDiffOn_univ.2 h).mono (subset_univ _) @[simp] theorem contDiff_zero : ContDiff 𝕜 0 f ↔ Continuous f := by rw [← contDiffOn_univ, continuous_iff_continuousOn_univ] exact contDiffOn_zero theorem contDiffAt_zero : ContDiffAt 𝕜 0 f x ↔ ∃ u ∈ 𝓝 x, ContinuousOn f u := by rw [← contDiffWithinAt_univ]; simp [contDiffWithinAt_zero, nhdsWithin_univ] theorem contDiffAt_one_iff : ContDiffAt 𝕜 1 f x ↔ ∃ f' : E → E →L[𝕜] F, ∃ u ∈ 𝓝 x, ContinuousOn f' u ∧ ∀ x ∈ u, HasFDerivAt f (f' x) x := by simp_rw [show (1 : ℕ∞) = (0 + 1 : ℕ) from (zero_add 1).symm, contDiffAt_succ_iff_hasFDerivAt, show ((0 : ℕ) : ℕ∞) = 0 from rfl, contDiffAt_zero, exists_mem_and_iff antitone_bforall antitone_continuousOn, and_comm] theorem ContDiff.of_le (h : ContDiff 𝕜 n f) (hmn : m ≀ n) : ContDiff 𝕜 m f := contDiffOn_univ.1 <| (contDiffOn_univ.2 h).of_le hmn theorem ContDiff.of_succ {n : ℕ} (h : ContDiff 𝕜 (n + 1) f) : ContDiff 𝕜 n f := h.of_le <| WithTop.coe_le_coe.mpr le_self_add theorem ContDiff.one_of_succ {n : ℕ} (h : ContDiff 𝕜 (n + 1) f) : ContDiff 𝕜 1 f := h.of_le <| WithTop.coe_le_coe.mpr le_add_self theorem ContDiff.continuous (h : ContDiff 𝕜 n f) : Continuous f := contDiff_zero.1 (h.of_le bot_le) /-- If a function is `C^n` with `n ≥ 1`, then it is differentiable. -/ theorem ContDiff.differentiable (h : ContDiff 𝕜 n f) (hn : 1 ≀ n) : Differentiable 𝕜 f := differentiableOn_univ.1 <| (contDiffOn_univ.2 h).differentiableOn hn theorem contDiff_iff_forall_nat_le : ContDiff 𝕜 n f ↔ ∀ m : ℕ, ↑m ≀ n → ContDiff 𝕜 m f := by simp_rw [← contDiffOn_univ]; exact contDiffOn_iff_forall_nat_le /-- A function is `C^(n+1)` iff it has a `C^n` derivative. -/ theorem contDiff_succ_iff_hasFDerivAt {n : ℕ} : ContDiff 𝕜 (n + 1 : ℕ) f ↔ ∃ f' : E → E →L[𝕜] F, ContDiff 𝕜 n f' ∧ ∀ x, HasFDerivAt f (f' x) x := by simp only [← contDiffOn_univ, ← hasFDerivWithinAt_univ, contDiffOn_succ_iff_hasFDerivWithin uniqueDiffOn_univ, Set.mem_univ, forall_true_left] theorem contDiff_one_iff_hasFDerivAt : ContDiff 𝕜 1 f ↔ ∃ f' : E → E →L[𝕜] F, Continuous f' ∧ ∀ x, HasFDerivAt f (f' x) x := by convert contDiff_succ_iff_hasFDerivAt using 4; simp /-! ### Iterated derivative -/ variable (𝕜) /-- The `n`-th derivative of a function, as a multilinear map, defined inductively. -/ noncomputable def iteratedFDeriv (n : ℕ) (f : E → F) : E → E[×n]→L[𝕜] F := Nat.recOn n (fun x => ContinuousMultilinearMap.curry0 𝕜 E (f x)) fun _ rec x => ContinuousLinearMap.uncurryLeft (fderiv 𝕜 rec x) /-- Formal Taylor series associated to a function. -/ def ftaylorSeries (f : E → F) (x : E) : FormalMultilinearSeries 𝕜 E F := fun n => iteratedFDeriv 𝕜 n f x variable {𝕜} @[simp] theorem iteratedFDeriv_zero_apply (m : Fin 0 → E) : (iteratedFDeriv 𝕜 0 f x : (Fin 0 → E) → F) m = f x := rfl theorem iteratedFDeriv_zero_eq_comp : iteratedFDeriv 𝕜 0 f = (continuousMultilinearCurryFin0 𝕜 E F).symm ∘ f := rfl @[simp] theorem norm_iteratedFDeriv_zero : ‖iteratedFDeriv 𝕜 0 f x‖ = ‖f x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDeriv_zero_eq_comp, comp_apply, LinearIsometryEquiv.norm_map] theorem iteratedFDerivWithin_zero_eq : iteratedFDerivWithin 𝕜 0 f s = iteratedFDeriv 𝕜 0 f := rfl theorem iteratedFDeriv_succ_apply_left {n : ℕ} (m : Fin (n + 1) → E) : (iteratedFDeriv 𝕜 (n + 1) f x : (Fin (n + 1) → E) → F) m = (fderiv 𝕜 (iteratedFDeriv 𝕜 n f) x : E → E[×n]→L[𝕜] F) (m 0) (tail m) := rfl /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the derivative of the `n`-th derivative. -/ theorem iteratedFDeriv_succ_eq_comp_left {n : ℕ} : iteratedFDeriv 𝕜 (n + 1) f = continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) => E) F ∘ fderiv 𝕜 (iteratedFDeriv 𝕜 n f) := rfl /-- Writing explicitly the derivative of the `n`-th derivative as the composition of a currying linear equiv, and the `n + 1`-th derivative. -/ theorem fderiv_iteratedFDeriv {n : ℕ} : fderiv 𝕜 (iteratedFDeriv 𝕜 n f) = (continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) => E) F).symm ∘ iteratedFDeriv 𝕜 (n + 1) f := by rw [iteratedFDeriv_succ_eq_comp_left] ext1 x simp only [Function.comp_apply, LinearIsometryEquiv.symm_apply_apply] theorem tsupport_iteratedFDeriv_subset (n : ℕ) : tsupport (iteratedFDeriv 𝕜 n f) ⊆ tsupport f := by induction' n with n IH · rw [iteratedFDeriv_zero_eq_comp] exact closure_minimal ((support_comp_subset (LinearIsometryEquiv.map_zero _) _).trans subset_closure) isClosed_closure · rw [iteratedFDeriv_succ_eq_comp_left] exact closure_minimal ((support_comp_subset (LinearIsometryEquiv.map_zero _) _).trans ((support_fderiv_subset 𝕜).trans IH)) isClosed_closure theorem support_iteratedFDeriv_subset (n : ℕ) : support (iteratedFDeriv 𝕜 n f) ⊆ tsupport f := subset_closure.trans (tsupport_iteratedFDeriv_subset n) theorem HasCompactSupport.iteratedFDeriv (hf : HasCompactSupport f) (n : ℕ) : HasCompactSupport (iteratedFDeriv 𝕜 n f) := hf.of_isClosed_subset isClosed_closure (tsupport_iteratedFDeriv_subset n) theorem norm_fderiv_iteratedFDeriv {n : ℕ} : ‖fderiv 𝕜 (iteratedFDeriv 𝕜 n f) x‖ = ‖iteratedFDeriv 𝕜 (n + 1) f x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDeriv_succ_eq_comp_left, comp_apply, LinearIsometryEquiv.norm_map] theorem iteratedFDerivWithin_univ {n : ℕ} : iteratedFDerivWithin 𝕜 n f univ = iteratedFDeriv 𝕜 n f := by induction' n with n IH · ext x; simp · ext x m rw [iteratedFDeriv_succ_apply_left, iteratedFDerivWithin_succ_apply_left, IH, fderivWithin_univ] theorem HasFTaylorSeriesUpTo.eq_iteratedFDeriv (h : HasFTaylorSeriesUpTo n f p) {m : ℕ} (hmn : (m : ℕ∞) ≀ n) (x : E) : p x m = iteratedFDeriv 𝕜 m f x := by rw [← iteratedFDerivWithin_univ] rw [← hasFTaylorSeriesUpToOn_univ_iff] at h exact h.eq_iteratedFDerivWithin_of_uniqueDiffOn hmn uniqueDiffOn_univ (mem_univ _) /-- In an open set, the iterated derivative within this set coincides with the global iterated derivative. -/ theorem iteratedFDerivWithin_of_isOpen (n : ℕ) (hs : IsOpen s) : EqOn (iteratedFDerivWithin 𝕜 n f s) (iteratedFDeriv 𝕜 n f) s := by induction' n with n IH · intro x _ ext1 simp only [Nat.zero_eq, iteratedFDerivWithin_zero_apply, iteratedFDeriv_zero_apply] · intro x hx rw [iteratedFDeriv_succ_eq_comp_left, iteratedFDerivWithin_succ_eq_comp_left] dsimp congr 1 rw [fderivWithin_of_isOpen hs hx] apply Filter.EventuallyEq.fderiv_eq filter_upwards [hs.mem_nhds hx] exact IH theorem ftaylorSeriesWithin_univ : ftaylorSeriesWithin 𝕜 f univ = ftaylorSeries 𝕜 f := by ext1 x; ext1 n change iteratedFDerivWithin 𝕜 n f univ x = iteratedFDeriv 𝕜 n f x rw [iteratedFDerivWithin_univ] theorem iteratedFDeriv_succ_apply_right {n : ℕ} (m : Fin (n + 1) → E) : (iteratedFDeriv 𝕜 (n + 1) f x : (Fin (n + 1) → E) → F) m = iteratedFDeriv 𝕜 n (fun y => fderiv 𝕜 f y) x (init m) (m (last n)) := by rw [← iteratedFDerivWithin_univ, ← iteratedFDerivWithin_univ, ← fderivWithin_univ] exact iteratedFDerivWithin_succ_apply_right uniqueDiffOn_univ (mem_univ _) _ /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the `n`-th derivative of the derivative. -/ theorem iteratedFDeriv_succ_eq_comp_right {n : ℕ} : iteratedFDeriv 𝕜 (n + 1) f x = (continuousMultilinearCurryRightEquiv' 𝕜 n E F ∘ iteratedFDeriv 𝕜 n fun y => fderiv 𝕜 f y) x := by ext m; rw [iteratedFDeriv_succ_apply_right]; rfl theorem norm_iteratedFDeriv_fderiv {n : ℕ} : ‖iteratedFDeriv 𝕜 n (fderiv 𝕜 f) x‖ = ‖iteratedFDeriv 𝕜 (n + 1) f x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDeriv_succ_eq_comp_right, comp_apply, LinearIsometryEquiv.norm_map] @[simp] theorem iteratedFDeriv_one_apply (m : Fin 1 → E) : iteratedFDeriv 𝕜 1 f x m = fderiv 𝕜 f x (m 0) := by rw [iteratedFDeriv_succ_apply_right, iteratedFDeriv_zero_apply]; rfl lemma iteratedFDeriv_two_apply (f : E → F) (z : E) (m : Fin 2 → E) : iteratedFDeriv 𝕜 2 f z m = fderiv 𝕜 (fderiv 𝕜 f) z (m 0) (m 1) := by simp only [iteratedFDeriv_succ_apply_right] rfl /-- When a function is `C^n` in a set `s` of unique differentiability, it admits `ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/ theorem contDiff_iff_ftaylorSeries : ContDiff 𝕜 n f ↔ HasFTaylorSeriesUpTo n f (ftaylorSeries 𝕜 f) := by constructor · rw [← contDiffOn_univ, ← hasFTaylorSeriesUpToOn_univ_iff, ← ftaylorSeriesWithin_univ] exact fun h => ContDiffOn.ftaylorSeriesWithin h uniqueDiffOn_univ · intro h; exact ⟹ftaylorSeries 𝕜 f, h⟩ theorem contDiff_iff_continuous_differentiable : ContDiff 𝕜 n f ↔ (∀ m : ℕ, (m : ℕ∞) ≀ n → Continuous fun x => iteratedFDeriv 𝕜 m f x) ∧ ∀ m : ℕ, (m : ℕ∞) < n → Differentiable 𝕜 fun x => iteratedFDeriv 𝕜 m f x := by simp [contDiffOn_univ.symm, continuous_iff_continuousOn_univ, differentiableOn_univ.symm, iteratedFDerivWithin_univ, contDiffOn_iff_continuousOn_differentiableOn uniqueDiffOn_univ] /-- If `f` is `C^n` then its `m`-times iterated derivative is continuous for `m ≀ n`. -/ theorem ContDiff.continuous_iteratedFDeriv {m : ℕ} (hm : (m : ℕ∞) ≀ n) (hf : ContDiff 𝕜 n f) : Continuous fun x => iteratedFDeriv 𝕜 m f x := (contDiff_iff_continuous_differentiable.mp hf).1 m hm /-- If `f` is `C^n` then its `m`-times iterated derivative is differentiable for `m < n`. -/ theorem ContDiff.differentiable_iteratedFDeriv {m : ℕ} (hm : (m : ℕ∞) < n) (hf : ContDiff 𝕜 n f) : Differentiable 𝕜 fun x => iteratedFDeriv 𝕜 m f x := (contDiff_iff_continuous_differentiable.mp hf).2 m hm theorem contDiff_of_differentiable_iteratedFDeriv (h : ∀ m : ℕ, (m : ℕ∞) ≀ n → Differentiable 𝕜 (iteratedFDeriv 𝕜 m f)) : ContDiff 𝕜 n f := contDiff_iff_continuous_differentiable.2 ⟹fun m hm => (h m hm).continuous, fun m hm => h m (le_of_lt hm)⟩ /-- A function is `C^(n + 1)` if and only if it is differentiable, and its derivative (formulated in terms of `fderiv`) is `C^n`. -/ theorem contDiff_succ_iff_fderiv {n : ℕ} : ContDiff 𝕜 (n + 1 : ℕ) f ↔ Differentiable 𝕜 f ∧ ContDiff 𝕜 n fun y => fderiv 𝕜 f y := by simp only [← contDiffOn_univ, ← differentiableOn_univ, ← fderivWithin_univ, contDiffOn_succ_iff_fderivWithin uniqueDiffOn_univ] theorem contDiff_one_iff_fderiv : ContDiff 𝕜 1 f ↔ Differentiable 𝕜 f ∧ Continuous (fderiv 𝕜 f) := contDiff_succ_iff_fderiv.trans <| Iff.rfl.and contDiff_zero /-- A function is `C^∞` if and only if it is differentiable, and its derivative (formulated in terms of `fderiv`) is `C^∞`. -/ theorem contDiff_top_iff_fderiv : ContDiff 𝕜 ∞ f ↔ Differentiable 𝕜 f ∧ ContDiff 𝕜 ∞ fun y => fderiv 𝕜 f y := by simp only [← contDiffOn_univ, ← differentiableOn_univ, ← fderivWithin_univ] rw [contDiffOn_top_iff_fderivWithin uniqueDiffOn_univ] theorem ContDiff.continuous_fderiv (h : ContDiff 𝕜 n f) (hn : 1 ≀ n) : Continuous fun x => fderiv 𝕜 f x := (contDiff_succ_iff_fderiv.1 (h.of_le hn)).2.continuous /-- If a function is at least `C^1`, its bundled derivative (mapping `(x, v)` to `Df(x) v`) is continuous. -/ theorem ContDiff.continuous_fderiv_apply (h : ContDiff 𝕜 n f) (hn : 1 ≀ n) : Continuous fun p : E × E => (fderiv 𝕜 f p.1 : E → F) p.2 := have A : Continuous fun q : (E →L[𝕜] F) × E => q.1 q.2 := isBoundedBilinearMap_apply.continuous have B : Continuous fun p : E × E => (fderiv 𝕜 f p.1, p.2) := ((h.continuous_fderiv hn).comp continuous_fst).prod_mk continuous_snd A.comp B
Analysis\Calculus\ContDiff\FiniteDimension.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Normed.Module.FiniteDimension /-! # Higher differentiability in finite dimensions. -/ noncomputable section universe uD uE uF uG variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {D : Type uD} [NormedAddCommGroup D] [NormedSpace 𝕜 D] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] /-! ### Finite dimensional results -/ section FiniteDimensional open Function FiniteDimensional variable [CompleteSpace 𝕜] /-- A family of continuous linear maps is `C^n` on `s` if all its applications are. -/ theorem contDiffOn_clm_apply {n : ℕ∞} {f : E → F →L[𝕜] G} {s : Set E} [FiniteDimensional 𝕜 F] : ContDiffOn 𝕜 n f s ↔ ∀ y, ContDiffOn 𝕜 n (fun x => f x y) s := by refine ⟹fun h y => h.clm_apply contDiffOn_const, fun h => ?_⟩ let d := finrank 𝕜 F have hd : d = finrank 𝕜 (Fin d → 𝕜) := (finrank_fin_fun 𝕜).symm let e₁ := ContinuousLinearEquiv.ofFinrankEq hd let e₂ := (e₁.arrowCongr (1 : G ≃L[𝕜] G)).trans (ContinuousLinearEquiv.piRing (Fin d)) rw [← id_comp f, ← e₂.symm_comp_self] exact e₂.symm.contDiff.comp_contDiffOn (contDiffOn_pi.mpr fun i => h _) theorem contDiff_clm_apply_iff {n : ℕ∞} {f : E → F →L[𝕜] G} [FiniteDimensional 𝕜 F] : ContDiff 𝕜 n f ↔ ∀ y, ContDiff 𝕜 n fun x => f x y := by simp_rw [← contDiffOn_univ, contDiffOn_clm_apply] /-- This is a useful lemma to prove that a certain operation preserves functions being `C^n`. When you do induction on `n`, this gives a useful characterization of a function being `C^(n+1)`, assuming you have already computed the derivative. The advantage of this version over `contDiff_succ_iff_fderiv` is that both occurrences of `ContDiff` are for functions with the same domain and codomain (`E` and `F`). This is not the case for `contDiff_succ_iff_fderiv`, which often requires an inconvenient need to generalize `F`, which results in universe issues (see the discussion in the section of `ContDiff.comp`). This lemma avoids these universe issues, but only applies for finite dimensional `E`. -/ theorem contDiff_succ_iff_fderiv_apply [FiniteDimensional 𝕜 E] {n : ℕ} {f : E → F} : ContDiff 𝕜 (n + 1 : ℕ) f ↔ Differentiable 𝕜 f ∧ ∀ y, ContDiff 𝕜 n fun x => fderiv 𝕜 f x y := by rw [contDiff_succ_iff_fderiv, contDiff_clm_apply_iff] theorem contDiffOn_succ_of_fderiv_apply [FiniteDimensional 𝕜 E] {n : ℕ} {f : E → F} {s : Set E} (hf : DifferentiableOn 𝕜 f s) (h : ∀ y, ContDiffOn 𝕜 n (fun x => fderivWithin 𝕜 f s x y) s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s := contDiffOn_succ_of_fderivWithin hf <| contDiffOn_clm_apply.mpr h theorem contDiffOn_succ_iff_fderiv_apply [FiniteDimensional 𝕜 E] {n : ℕ} {f : E → F} {s : Set E} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ DifferentiableOn 𝕜 f s ∧ ∀ y, ContDiffOn 𝕜 n (fun x => fderivWithin 𝕜 f s x y) s := by rw [contDiffOn_succ_iff_fderivWithin hs, contDiffOn_clm_apply] end FiniteDimensional
Analysis\Calculus\ContDiff\RCLike.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Analysis.Calculus.ContDiff.Defs import Mathlib.Analysis.Calculus.MeanValue /-! # Higher differentiability over `ℝ` or `ℂ` -/ noncomputable section open Set Fin Filter Function open scoped NNReal Topology section Real /-! ### Results over `ℝ` or `ℂ` The results in this section rely on the Mean Value Theorem, and therefore hold only over `ℝ` (and its extension fields such as `ℂ`). -/ variable {n : ℕ∞} {𝕂 : Type*} [RCLike 𝕂] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕂 E'] {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕂 F'] /-- If a function has a Taylor series at order at least 1, then at points in the interior of the domain of definition, the term of order 1 of this series is a strict derivative of `f`. -/ theorem HasFTaylorSeriesUpToOn.hasStrictFDerivAt {s : Set E'} {f : E' → F'} {x : E'} {p : E' → FormalMultilinearSeries 𝕂 E' F'} (hf : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≀ n) (hs : s ∈ 𝓝 x) : HasStrictFDerivAt f ((continuousMultilinearCurryFin1 𝕂 E' F') (p x 1)) x := hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt (hf.eventually_hasFDerivAt hn hs) <| (continuousMultilinearCurryFin1 𝕂 E' F').continuousAt.comp <| (hf.cont 1 hn).continuousAt hs /-- If a function is `C^n` with `1 ≀ n` around a point, and its derivative at that point is given to us as `f'`, then `f'` is also a strict derivative. -/ theorem ContDiffAt.hasStrictFDerivAt' {f : E' → F'} {f' : E' →L[𝕂] F'} {x : E'} (hf : ContDiffAt 𝕂 n f x) (hf' : HasFDerivAt f f' x) (hn : 1 ≀ n) : HasStrictFDerivAt f f' x := by rcases hf 1 hn with ⟹u, H, p, hp⟩ simp only [nhdsWithin_univ, mem_univ, insert_eq_of_mem] at H have := hp.hasStrictFDerivAt le_rfl H rwa [hf'.unique this.hasFDerivAt] /-- If a function is `C^n` with `1 ≀ n` around a point, and its derivative at that point is given to us as `f'`, then `f'` is also a strict derivative. -/ theorem ContDiffAt.hasStrictDerivAt' {f : 𝕂 → F'} {f' : F'} {x : 𝕂} (hf : ContDiffAt 𝕂 n f x) (hf' : HasDerivAt f f' x) (hn : 1 ≀ n) : HasStrictDerivAt f f' x := hf.hasStrictFDerivAt' hf' hn /-- If a function is `C^n` with `1 ≀ n` around a point, then the derivative of `f` at this point is also a strict derivative. -/ theorem ContDiffAt.hasStrictFDerivAt {f : E' → F'} {x : E'} (hf : ContDiffAt 𝕂 n f x) (hn : 1 ≀ n) : HasStrictFDerivAt f (fderiv 𝕂 f x) x := hf.hasStrictFDerivAt' (hf.differentiableAt hn).hasFDerivAt hn /-- If a function is `C^n` with `1 ≀ n` around a point, then the derivative of `f` at this point is also a strict derivative. -/ theorem ContDiffAt.hasStrictDerivAt {f : 𝕂 → F'} {x : 𝕂} (hf : ContDiffAt 𝕂 n f x) (hn : 1 ≀ n) : HasStrictDerivAt f (deriv f x) x := (hf.hasStrictFDerivAt hn).hasStrictDerivAt /-- If a function is `C^n` with `1 ≀ n`, then the derivative of `f` is also a strict derivative. -/ theorem ContDiff.hasStrictFDerivAt {f : E' → F'} {x : E'} (hf : ContDiff 𝕂 n f) (hn : 1 ≀ n) : HasStrictFDerivAt f (fderiv 𝕂 f x) x := hf.contDiffAt.hasStrictFDerivAt hn /-- If a function is `C^n` with `1 ≀ n`, then the derivative of `f` is also a strict derivative. -/ theorem ContDiff.hasStrictDerivAt {f : 𝕂 → F'} {x : 𝕂} (hf : ContDiff 𝕂 n f) (hn : 1 ≀ n) : HasStrictDerivAt f (deriv f x) x := hf.contDiffAt.hasStrictDerivAt hn /-- If `f` has a formal Taylor series `p` up to order `1` on `{x} ∪ s`, where `s` is a convex set, and `‖p x 1‖₊ < K`, then `f` is `K`-Lipschitz in a neighborhood of `x` within `s`. -/ theorem HasFTaylorSeriesUpToOn.exists_lipschitzOnWith_of_nnnorm_lt {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {f : E → F} {p : E → FormalMultilinearSeries ℝ E F} {s : Set E} {x : E} (hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)) (hs : Convex ℝ s) (K : ℝ≥0) (hK : ‖p x 1‖₊ < K) : ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by set f' := fun y => continuousMultilinearCurryFin1 ℝ E F (p y 1) have hder : ∀ y ∈ s, HasFDerivWithinAt f (f' y) s y := fun y hy => (hf.hasFDerivWithinAt le_rfl (subset_insert x s hy)).mono (subset_insert x s) have hcont : ContinuousWithinAt f' s x := (continuousMultilinearCurryFin1 ℝ E F).continuousAt.comp_continuousWithinAt ((hf.cont _ le_rfl _ (mem_insert _ _)).mono (subset_insert x s)) replace hK : ‖f' x‖₊ < K := by simpa only [f', LinearIsometryEquiv.nnnorm_map] exact hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (eventually_nhdsWithin_iff.2 <| eventually_of_forall hder) hcont K hK /-- If `f` has a formal Taylor series `p` up to order `1` on `{x} ∪ s`, where `s` is a convex set, then `f` is Lipschitz in a neighborhood of `x` within `s`. -/ theorem HasFTaylorSeriesUpToOn.exists_lipschitzOnWith {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {f : E → F} {p : E → FormalMultilinearSeries ℝ E F} {s : Set E} {x : E} (hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)) (hs : Convex ℝ s) : ∃ K, ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hf.exists_lipschitzOnWith_of_nnnorm_lt hs /-- If `f` is `C^1` within a convex set `s` at `x`, then it is Lipschitz on a neighborhood of `x` within `s`. -/ theorem ContDiffWithinAt.exists_lipschitzOnWith {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {f : E → F} {s : Set E} {x : E} (hf : ContDiffWithinAt ℝ 1 f s x) (hs : Convex ℝ s) : ∃ K : ℝ≥0, ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by rcases hf 1 le_rfl with ⟹t, hst, p, hp⟩ rcases Metric.mem_nhdsWithin_iff.mp hst with ⟚ε, ε0, hε⟩ replace hp : HasFTaylorSeriesUpToOn 1 f p (Metric.ball x ε ∩ insert x s) := hp.mono hε clear hst hε t rw [← insert_eq_of_mem (Metric.mem_ball_self ε0), ← insert_inter_distrib] at hp rcases hp.exists_lipschitzOnWith ((convex_ball _ _).inter hs) with ⟹K, t, hst, hft⟩ rw [inter_comm, ← nhdsWithin_restrict' _ (Metric.ball_mem_nhds _ ε0)] at hst exact ⟹K, t, hst, hft⟩ /-- If `f` is `C^1` at `x` and `K > ‖fderiv 𝕂 f x‖`, then `f` is `K`-Lipschitz in a neighborhood of `x`. -/ theorem ContDiffAt.exists_lipschitzOnWith_of_nnnorm_lt {f : E' → F'} {x : E'} (hf : ContDiffAt 𝕂 1 f x) (K : ℝ≥0) (hK : ‖fderiv 𝕂 f x‖₊ < K) : ∃ t ∈ 𝓝 x, LipschitzOnWith K f t := (hf.hasStrictFDerivAt le_rfl).exists_lipschitzOnWith_of_nnnorm_lt K hK /-- If `f` is `C^1` at `x`, then `f` is Lipschitz in a neighborhood of `x`. -/ theorem ContDiffAt.exists_lipschitzOnWith {f : E' → F'} {x : E'} (hf : ContDiffAt 𝕂 1 f x) : ∃ K, ∃ t ∈ 𝓝 x, LipschitzOnWith K f t := (hf.hasStrictFDerivAt le_rfl).exists_lipschitzOnWith /-- If `f` is `C^1`, it is locally Lipschitz. -/ lemma ContDiff.locallyLipschitz {f : E' → F'} (hf : ContDiff 𝕂 1 f) : LocallyLipschitz f := by intro x rcases hf.contDiffAt.exists_lipschitzOnWith with ⟹K, t, ht, hf⟩ use K, t /-- A `C^1` function with compact support is Lipschitz. -/ theorem ContDiff.lipschitzWith_of_hasCompactSupport {f : E' → F'} {n : ℕ∞} (hf : HasCompactSupport f) (h'f : ContDiff 𝕂 n f) (hn : 1 ≀ n) : ∃ C, LipschitzWith C f := by obtain ⟹C, hC⟩ := (hf.fderiv 𝕂).exists_bound_of_continuous (h'f.continuous_fderiv hn) refine ⟹⟹max C 0, le_max_right _ _⟩, ?_⟩ apply lipschitzWith_of_nnnorm_fderiv_le (h'f.differentiable hn) (fun x ↩ ?_) simp [← NNReal.coe_le_coe, hC x] end Real
Analysis\Calculus\Deriv\Add.lean
/- 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, Yury Kudryashov, Anatole Dedecker -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Add /-! # One-dimensional derivatives of sums etc In this file we prove formulas about derivatives of `f + g`, `-f`, `f - g`, and `∑ i, f i x` for functions from the base field to a normed space over this field. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative -/ universe u v w open scoped Classical open Topology Filter ENNReal open Filter Asymptotics Set variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L : Filter 𝕜} section Add /-! ### Derivative of the sum of two functions -/ nonrec theorem HasDerivAtFilter.add (hf : HasDerivAtFilter f f' x L) (hg : HasDerivAtFilter g g' x L) : HasDerivAtFilter (fun y => f y + g y) (f' + g') x L := by simpa using (hf.add hg).hasDerivAtFilter nonrec theorem HasStrictDerivAt.add (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) : HasStrictDerivAt (fun y => f y + g y) (f' + g') x := by simpa using (hf.add hg).hasStrictDerivAt nonrec theorem HasDerivWithinAt.add (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) : HasDerivWithinAt (fun y => f y + g y) (f' + g') s x := hf.add hg nonrec theorem HasDerivAt.add (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) : HasDerivAt (fun x => f x + g x) (f' + g') x := hf.add hg theorem derivWithin_add (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : derivWithin (fun y => f y + g y) s x = derivWithin f s x + derivWithin g s x := (hf.hasDerivWithinAt.add hg.hasDerivWithinAt).derivWithin hxs @[simp] theorem deriv_add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : deriv (fun y => f y + g y) x = deriv f x + deriv g x := (hf.hasDerivAt.add hg.hasDerivAt).deriv theorem HasStrictDerivAt.add_const (c : F) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun y ↩ f y + c) f' x := add_zero f' ▾ hf.add (hasStrictDerivAt_const x c) theorem HasDerivAtFilter.add_const (hf : HasDerivAtFilter f f' x L) (c : F) : HasDerivAtFilter (fun y => f y + c) f' x L := add_zero f' ▾ hf.add (hasDerivAtFilter_const x L c) nonrec theorem HasDerivWithinAt.add_const (hf : HasDerivWithinAt f f' s x) (c : F) : HasDerivWithinAt (fun y => f y + c) f' s x := hf.add_const c nonrec theorem HasDerivAt.add_const (hf : HasDerivAt f f' x) (c : F) : HasDerivAt (fun x => f x + c) f' x := hf.add_const c theorem derivWithin_add_const (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : derivWithin (fun y => f y + c) s x = derivWithin f s x := by simp only [derivWithin, fderivWithin_add_const hxs] theorem deriv_add_const (c : F) : deriv (fun y => f y + c) x = deriv f x := by simp only [deriv, fderiv_add_const] @[simp] theorem deriv_add_const' (c : F) : (deriv fun y => f y + c) = deriv f := funext fun _ => deriv_add_const c theorem HasStrictDerivAt.const_add (c : F) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun y ↩ c + f y) f' x := zero_add f' ▾ (hasStrictDerivAt_const x c).add hf theorem HasDerivAtFilter.const_add (c : F) (hf : HasDerivAtFilter f f' x L) : HasDerivAtFilter (fun y => c + f y) f' x L := zero_add f' ▾ (hasDerivAtFilter_const x L c).add hf nonrec theorem HasDerivWithinAt.const_add (c : F) (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun y => c + f y) f' s x := hf.const_add c nonrec theorem HasDerivAt.const_add (c : F) (hf : HasDerivAt f f' x) : HasDerivAt (fun x => c + f x) f' x := hf.const_add c theorem derivWithin_const_add (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : derivWithin (fun y => c + f y) s x = derivWithin f s x := by simp only [derivWithin, fderivWithin_const_add hxs] theorem deriv_const_add (c : F) : deriv (fun y => c + f y) x = deriv f x := by simp only [deriv, fderiv_const_add] @[simp] theorem deriv_const_add' (c : F) : (deriv fun y => c + f y) = deriv f := funext fun _ => deriv_const_add c end Add section Sum /-! ### Derivative of a finite sum of functions -/ variable {ι : Type*} {u : Finset ι} {A : ι → 𝕜 → F} {A' : ι → F} theorem HasDerivAtFilter.sum (h : ∀ i ∈ u, HasDerivAtFilter (A i) (A' i) x L) : HasDerivAtFilter (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x L := by simpa [ContinuousLinearMap.sum_apply] using (HasFDerivAtFilter.sum h).hasDerivAtFilter theorem HasStrictDerivAt.sum (h : ∀ i ∈ u, HasStrictDerivAt (A i) (A' i) x) : HasStrictDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := by simpa [ContinuousLinearMap.sum_apply] using (HasStrictFDerivAt.sum h).hasStrictDerivAt theorem HasDerivWithinAt.sum (h : ∀ i ∈ u, HasDerivWithinAt (A i) (A' i) s x) : HasDerivWithinAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) s x := HasDerivAtFilter.sum h theorem HasDerivAt.sum (h : ∀ i ∈ u, HasDerivAt (A i) (A' i) x) : HasDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := HasDerivAtFilter.sum h theorem derivWithin_sum (hxs : UniqueDiffWithinAt 𝕜 s x) (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) : derivWithin (fun y => ∑ i ∈ u, A i y) s x = ∑ i ∈ u, derivWithin (A i) s x := (HasDerivWithinAt.sum fun i hi => (h i hi).hasDerivWithinAt).derivWithin hxs @[simp] theorem deriv_sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) : deriv (fun y => ∑ i ∈ u, A i y) x = ∑ i ∈ u, deriv (A i) x := (HasDerivAt.sum fun i hi => (h i hi).hasDerivAt).deriv end Sum section Neg /-! ### Derivative of the negative of a function -/ nonrec theorem HasDerivAtFilter.neg (h : HasDerivAtFilter f f' x L) : HasDerivAtFilter (fun x => -f x) (-f') x L := by simpa using h.neg.hasDerivAtFilter nonrec theorem HasDerivWithinAt.neg (h : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => -f x) (-f') s x := h.neg nonrec theorem HasDerivAt.neg (h : HasDerivAt f f' x) : HasDerivAt (fun x => -f x) (-f') x := h.neg nonrec theorem HasStrictDerivAt.neg (h : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => -f x) (-f') x := by simpa using h.neg.hasStrictDerivAt theorem derivWithin.neg (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun y => -f y) s x = -derivWithin f s x := by simp only [derivWithin, fderivWithin_neg hxs, ContinuousLinearMap.neg_apply] theorem deriv.neg : deriv (fun y => -f y) x = -deriv f x := by simp only [deriv, fderiv_neg, ContinuousLinearMap.neg_apply] @[simp] theorem deriv.neg' : (deriv fun y => -f y) = fun x => -deriv f x := funext fun _ => deriv.neg end Neg section Neg2 /-! ### Derivative of the negation function (i.e `Neg.neg`) -/ variable (s x L) theorem hasDerivAtFilter_neg : HasDerivAtFilter Neg.neg (-1) x L := HasDerivAtFilter.neg <| hasDerivAtFilter_id _ _ theorem hasDerivWithinAt_neg : HasDerivWithinAt Neg.neg (-1) s x := hasDerivAtFilter_neg _ _ theorem hasDerivAt_neg : HasDerivAt Neg.neg (-1) x := hasDerivAtFilter_neg _ _ theorem hasDerivAt_neg' : HasDerivAt (fun x => -x) (-1) x := hasDerivAtFilter_neg _ _ theorem hasStrictDerivAt_neg : HasStrictDerivAt Neg.neg (-1) x := HasStrictDerivAt.neg <| hasStrictDerivAt_id _ theorem deriv_neg : deriv Neg.neg x = -1 := HasDerivAt.deriv (hasDerivAt_neg x) @[simp] theorem deriv_neg' : deriv (Neg.neg : 𝕜 → 𝕜) = fun _ => -1 := funext deriv_neg @[simp] theorem deriv_neg'' : deriv (fun x : 𝕜 => -x) x = -1 := deriv_neg x theorem derivWithin_neg (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin Neg.neg s x = -1 := (hasDerivWithinAt_neg x s).derivWithin hxs theorem differentiable_neg : Differentiable 𝕜 (Neg.neg : 𝕜 → 𝕜) := Differentiable.neg differentiable_id theorem differentiableOn_neg : DifferentiableOn 𝕜 (Neg.neg : 𝕜 → 𝕜) s := DifferentiableOn.neg differentiableOn_id theorem not_differentiableAt_abs_zero : ¬ DifferentiableAt ℝ (abs : ℝ → ℝ) 0 := by intro h have h₁ : deriv abs (0 : ℝ) = 1 := (uniqueDiffOn_Ici _ _ Set.left_mem_Ici).eq_deriv _ h.hasDerivAt.hasDerivWithinAt <| (hasDerivWithinAt_id _ _).congr_of_mem (fun _ h ↩ abs_of_nonneg h) Set.left_mem_Ici have h₂ : deriv abs (0 : ℝ) = -1 := (uniqueDiffOn_Iic _ _ Set.right_mem_Iic).eq_deriv _ h.hasDerivAt.hasDerivWithinAt <| (hasDerivWithinAt_neg _ _).congr_of_mem (fun _ h ↩ abs_of_nonpos h) Set.right_mem_Iic linarith lemma differentiableAt_comp_neg_iff {a : 𝕜} : DifferentiableAt 𝕜 f (-a) ↔ DifferentiableAt 𝕜 (fun x ↩ f (-x)) a := by refine ⟹fun H ↩ H.comp a differentiable_neg.differentiableAt, fun H ↩ ?_⟩ convert ((neg_neg a).symm ▾ H).comp (-a) differentiable_neg.differentiableAt ext simp only [Function.comp_apply, neg_neg] end Neg2 section Sub /-! ### Derivative of the difference of two functions -/ theorem HasDerivAtFilter.sub (hf : HasDerivAtFilter f f' x L) (hg : HasDerivAtFilter g g' x L) : HasDerivAtFilter (fun x => f x - g x) (f' - g') x L := by simpa only [sub_eq_add_neg] using hf.add hg.neg nonrec theorem HasDerivWithinAt.sub (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) : HasDerivWithinAt (fun x => f x - g x) (f' - g') s x := hf.sub hg nonrec theorem HasDerivAt.sub (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) : HasDerivAt (fun x => f x - g x) (f' - g') x := hf.sub hg theorem HasStrictDerivAt.sub (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) : HasStrictDerivAt (fun x => f x - g x) (f' - g') x := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem derivWithin_sub (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : derivWithin (fun y => f y - g y) s x = derivWithin f s x - derivWithin g s x := (hf.hasDerivWithinAt.sub hg.hasDerivWithinAt).derivWithin hxs @[simp] theorem deriv_sub (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : deriv (fun y => f y - g y) x = deriv f x - deriv g x := (hf.hasDerivAt.sub hg.hasDerivAt).deriv theorem HasDerivAtFilter.sub_const (hf : HasDerivAtFilter f f' x L) (c : F) : HasDerivAtFilter (fun x => f x - c) f' x L := by simpa only [sub_eq_add_neg] using hf.add_const (-c) nonrec theorem HasDerivWithinAt.sub_const (hf : HasDerivWithinAt f f' s x) (c : F) : HasDerivWithinAt (fun x => f x - c) f' s x := hf.sub_const c nonrec theorem HasDerivAt.sub_const (hf : HasDerivAt f f' x) (c : F) : HasDerivAt (fun x => f x - c) f' x := hf.sub_const c theorem derivWithin_sub_const (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : derivWithin (fun y => f y - c) s x = derivWithin f s x := by simp only [derivWithin, fderivWithin_sub_const hxs] theorem deriv_sub_const (c : F) : deriv (fun y => f y - c) x = deriv f x := by simp only [deriv, fderiv_sub_const] theorem HasDerivAtFilter.const_sub (c : F) (hf : HasDerivAtFilter f f' x L) : HasDerivAtFilter (fun x => c - f x) (-f') x L := by simpa only [sub_eq_add_neg] using hf.neg.const_add c nonrec theorem HasDerivWithinAt.const_sub (c : F) (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => c - f x) (-f') s x := hf.const_sub c theorem HasStrictDerivAt.const_sub (c : F) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => c - f x) (-f') x := by simpa only [sub_eq_add_neg] using hf.neg.const_add c nonrec theorem HasDerivAt.const_sub (c : F) (hf : HasDerivAt f f' x) : HasDerivAt (fun x => c - f x) (-f') x := hf.const_sub c theorem derivWithin_const_sub (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : derivWithin (fun y => c - f y) s x = -derivWithin f s x := by simp [derivWithin, fderivWithin_const_sub hxs] theorem deriv_const_sub (c : F) : deriv (fun y => c - f y) x = -deriv f x := by simp only [← derivWithin_univ, derivWithin_const_sub (uniqueDiffWithinAt_univ : UniqueDiffWithinAt 𝕜 _ _)] end Sub
Analysis\Calculus\Deriv\AffineMap.lean
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Linear import Mathlib.LinearAlgebra.AffineSpace.AffineMap /-! # Derivatives of affine maps In this file we prove formulas for one-dimensional derivatives of affine maps `f : 𝕜 →ᵃ[𝕜] E`. We also specialise some of these results to `AffineMap.lineMap` because it is useful to transfer MVT from dimension 1 to a domain in higher dimension. ## TODO Add theorems about `deriv`s and `fderiv`s of `ContinuousAffineMap`s once they will be ported to Mathlib 4. ## Keywords affine map, derivative, differentiability -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] (f : 𝕜 →ᵃ[𝕜] E) {a b : E} {L : Filter 𝕜} {s : Set 𝕜} {x : 𝕜} namespace AffineMap theorem hasStrictDerivAt : HasStrictDerivAt f (f.linear 1) x := by rw [f.decomp] exact f.linear.hasStrictDerivAt.add_const (f 0) theorem hasDerivAtFilter : HasDerivAtFilter f (f.linear 1) x L := by rw [f.decomp] exact f.linear.hasDerivAtFilter.add_const (f 0) theorem hasDerivWithinAt : HasDerivWithinAt f (f.linear 1) s x := f.hasDerivAtFilter theorem hasDerivAt : HasDerivAt f (f.linear 1) x := f.hasDerivAtFilter protected theorem derivWithin (hs : UniqueDiffWithinAt 𝕜 s x) : derivWithin f s x = f.linear 1 := f.hasDerivWithinAt.derivWithin hs @[simp] protected theorem deriv : deriv f x = f.linear 1 := f.hasDerivAt.deriv protected theorem differentiableAt : DifferentiableAt 𝕜 f x := f.hasDerivAt.differentiableAt protected theorem differentiable : Differentiable 𝕜 f := fun _ ↩ f.differentiableAt protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 f s x := f.differentiableAt.differentiableWithinAt protected theorem differentiableOn : DifferentiableOn 𝕜 f s := fun _ _ ↩ f.differentiableWithinAt /-! ### Line map In this section we specialize some lemmas to `AffineMap.lineMap` because this map is very useful to deduce higher dimensional lemmas from one-dimensional versions. -/ theorem hasStrictDerivAt_lineMap : HasStrictDerivAt (lineMap a b) (b - a) x := by simpa using (lineMap a b : 𝕜 →ᵃ[𝕜] E).hasStrictDerivAt theorem hasDerivAt_lineMap : HasDerivAt (lineMap a b) (b - a) x := hasStrictDerivAt_lineMap.hasDerivAt theorem hasDerivWithinAt_lineMap : HasDerivWithinAt (lineMap a b) (b - a) s x := hasDerivAt_lineMap.hasDerivWithinAt end AffineMap
Analysis\Calculus\Deriv\Basic.lean
/- 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 Mathlib.Analysis.Calculus.FDeriv.Basic import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace /-! # 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: - `HasDerivAtFilter f f' x L` states that the function `f` has the derivative `f'` at the point `x` as `x` goes along the filter `L`. - `HasDerivWithinAt f f' s x` states that the function `f` has the derivative `f'` at the point `x` within the subset `s`. - `HasDerivAt f f' x` states that the function `f` has the derivative `f'` at the point `x`. - `HasStrictDerivAt 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: - `derivWithin f s x` is a derivative of `f` at `x` within `s`. If the derivative does not exist, then `derivWithin 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 `fderivWithin_derivWithin` 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 (in `Linear.lean`) - addition (in `Add.lean`) - sum of finitely many functions (in `Add.lean`) - negation (in `Add.lean`) - subtraction (in `Add.lean`) - star (in `Star.lean`) - multiplication of two functions in `𝕜 → 𝕜` (in `Mul.lean`) - multiplication of a function in `𝕜 → 𝕜` and of a function in `𝕜 → E` (in `Mul.lean`) - powers of a function (in `Pow.lean` and `ZPow.lean`) - inverse `x → x⁻¹` (in `Inv.lean`) - division (in `Inv.lean`) - composition of a function in `𝕜 → F` with a function in `𝕜 → 𝕜` (in `Comp.lean`) - composition of a function in `F → E` with a function in `𝕜 → F` (in `Comp.lean`) - inverse function (assuming that it exists; the inverse function theorem is in `Inverse.lean`) - polynomials (in `Polynomial.lean`) 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 `HasDerivAt`'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 (fun x ↩ cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) := by simp; ring ``` The relationship between the derivative of a function and its definition from a standard undergraduate course as the limit of the slope `(f y - f x) / (y - x)` as `y` tends to `𝓝[≠] x` is developed in the file `Slope.lean`. ## 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/Basic.lean`. See the explanations there. -/ universe u v w noncomputable section open scoped Topology ENNReal NNReal open Filter Asymptotics Set open ContinuousLinearMap (smulRight smulRight_one_eq_iff) variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 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 HasDerivAtFilter (f : 𝕜 → F) (f' : F) (x : 𝕜) (L : Filter 𝕜) := HasFDerivAtFilter f (smulRight (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 HasDerivWithinAt (f : 𝕜 → F) (f' : F) (s : Set 𝕜) (x : 𝕜) := HasDerivAtFilter 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 HasDerivAt (f : 𝕜 → F) (f' : F) (x : 𝕜) := HasDerivAtFilter 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 HasStrictDerivAt (f : 𝕜 → F) (f' : F) (x : 𝕜) := HasStrictFDerivAt f (smulRight (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', HasDerivWithinAt f f' s x`), then `f x' = f x + (x' - x) • derivWithin f s x + o(x' - x)` where `x'` converges to `x` inside `s`. -/ def derivWithin (f : 𝕜 → F) (s : Set 𝕜) (x : 𝕜) := fderivWithin 𝕜 f s x 1 /-- Derivative of `f` at the point `x`, if it exists. Zero otherwise. If the derivative exists (i.e., `∃ f', HasDerivAt 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 variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L L₁ L₂ : Filter 𝕜} /-- Expressing `HasFDerivAtFilter f f' x L` in terms of `HasDerivAtFilter` -/ theorem hasFDerivAtFilter_iff_hasDerivAtFilter {f' : 𝕜 →L[𝕜] F} : HasFDerivAtFilter f f' x L ↔ HasDerivAtFilter f (f' 1) x L := by simp [HasDerivAtFilter] theorem HasFDerivAtFilter.hasDerivAtFilter {f' : 𝕜 →L[𝕜] F} : HasFDerivAtFilter f f' x L → HasDerivAtFilter f (f' 1) x L := hasFDerivAtFilter_iff_hasDerivAtFilter.mp /-- Expressing `HasFDerivWithinAt f f' s x` in terms of `HasDerivWithinAt` -/ theorem hasFDerivWithinAt_iff_hasDerivWithinAt {f' : 𝕜 →L[𝕜] F} : HasFDerivWithinAt f f' s x ↔ HasDerivWithinAt f (f' 1) s x := hasFDerivAtFilter_iff_hasDerivAtFilter /-- Expressing `HasDerivWithinAt f f' s x` in terms of `HasFDerivWithinAt` -/ theorem hasDerivWithinAt_iff_hasFDerivWithinAt {f' : F} : HasDerivWithinAt f f' s x ↔ HasFDerivWithinAt f (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') s x := Iff.rfl theorem HasFDerivWithinAt.hasDerivWithinAt {f' : 𝕜 →L[𝕜] F} : HasFDerivWithinAt f f' s x → HasDerivWithinAt f (f' 1) s x := hasFDerivWithinAt_iff_hasDerivWithinAt.mp theorem HasDerivWithinAt.hasFDerivWithinAt {f' : F} : HasDerivWithinAt f f' s x → HasFDerivWithinAt f (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') s x := hasDerivWithinAt_iff_hasFDerivWithinAt.mp /-- Expressing `HasFDerivAt f f' x` in terms of `HasDerivAt` -/ theorem hasFDerivAt_iff_hasDerivAt {f' : 𝕜 →L[𝕜] F} : HasFDerivAt f f' x ↔ HasDerivAt f (f' 1) x := hasFDerivAtFilter_iff_hasDerivAtFilter theorem HasFDerivAt.hasDerivAt {f' : 𝕜 →L[𝕜] F} : HasFDerivAt f f' x → HasDerivAt f (f' 1) x := hasFDerivAt_iff_hasDerivAt.mp theorem hasStrictFDerivAt_iff_hasStrictDerivAt {f' : 𝕜 →L[𝕜] F} : HasStrictFDerivAt f f' x ↔ HasStrictDerivAt f (f' 1) x := by simp [HasStrictDerivAt, HasStrictFDerivAt] protected theorem HasStrictFDerivAt.hasStrictDerivAt {f' : 𝕜 →L[𝕜] F} : HasStrictFDerivAt f f' x → HasStrictDerivAt f (f' 1) x := hasStrictFDerivAt_iff_hasStrictDerivAt.mp theorem hasStrictDerivAt_iff_hasStrictFDerivAt : HasStrictDerivAt f f' x ↔ HasStrictFDerivAt f (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') x := Iff.rfl alias ⟹HasStrictDerivAt.hasStrictFDerivAt, _⟩ := hasStrictDerivAt_iff_hasStrictFDerivAt /-- Expressing `HasDerivAt f f' x` in terms of `HasFDerivAt` -/ theorem hasDerivAt_iff_hasFDerivAt {f' : F} : HasDerivAt f f' x ↔ HasFDerivAt f (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') x := Iff.rfl alias ⟹HasDerivAt.hasFDerivAt, _⟩ := hasDerivAt_iff_hasFDerivAt theorem derivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) : derivWithin f s x = 0 := by unfold derivWithin rw [fderivWithin_zero_of_not_differentiableWithinAt h] simp theorem derivWithin_zero_of_isolated (h : 𝓝[s \ {x}] x = ⊥) : derivWithin f s x = 0 := by rw [derivWithin, fderivWithin_zero_of_isolated h, ContinuousLinearMap.zero_apply] theorem derivWithin_zero_of_nmem_closure (h : x ∉ closure s) : derivWithin f s x = 0 := by rw [derivWithin, fderivWithin_zero_of_nmem_closure h, ContinuousLinearMap.zero_apply] theorem differentiableWithinAt_of_derivWithin_ne_zero (h : derivWithin f s x ≠ 0) : DifferentiableWithinAt 𝕜 f s x := not_imp_comm.1 derivWithin_zero_of_not_differentiableWithinAt h theorem deriv_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : deriv f x = 0 := by unfold deriv rw [fderiv_zero_of_not_differentiableAt h] simp theorem differentiableAt_of_deriv_ne_zero (h : deriv f x ≠ 0) : DifferentiableAt 𝕜 f x := not_imp_comm.1 deriv_zero_of_not_differentiableAt h theorem UniqueDiffWithinAt.eq_deriv (s : Set 𝕜) (H : UniqueDiffWithinAt 𝕜 s x) (h : HasDerivWithinAt f f' s x) (h₁ : HasDerivWithinAt f f₁' s x) : f' = f₁' := smulRight_one_eq_iff.mp <| UniqueDiffWithinAt.eq H h h₁ theorem hasDerivAtFilter_iff_isLittleO : HasDerivAtFilter f f' x L ↔ (fun x' : 𝕜 => f x' - f x - (x' - x) • f') =o[L] fun x' => x' - x := hasFDerivAtFilter_iff_isLittleO .. theorem hasDerivAtFilter_iff_tendsto : HasDerivAtFilter f f' x L ↔ Tendsto (fun x' : 𝕜 => ‖x' - x‖⁻¹ * ‖f x' - f x - (x' - x) • f'‖) L (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem hasDerivWithinAt_iff_isLittleO : HasDerivWithinAt f f' s x ↔ (fun x' : 𝕜 => f x' - f x - (x' - x) • f') =o[𝓝[s] x] fun x' => x' - x := hasFDerivAtFilter_iff_isLittleO .. theorem hasDerivWithinAt_iff_tendsto : HasDerivWithinAt f f' s x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - (x' - x) • f'‖) (𝓝[s] x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem hasDerivAt_iff_isLittleO : HasDerivAt f f' x ↔ (fun x' : 𝕜 => f x' - f x - (x' - x) • f') =o[𝓝 x] fun x' => x' - x := hasFDerivAtFilter_iff_isLittleO .. theorem hasDerivAt_iff_tendsto : HasDerivAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - (x' - x) • f'‖) (𝓝 x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem HasDerivAtFilter.isBigO_sub (h : HasDerivAtFilter f f' x L) : (fun x' => f x' - f x) =O[L] fun x' => x' - x := HasFDerivAtFilter.isBigO_sub h nonrec theorem HasDerivAtFilter.isBigO_sub_rev (hf : HasDerivAtFilter f f' x L) (hf' : f' ≠ 0) : (fun x' => x' - x) =O[L] fun x' => f x' - f x := suffices AntilipschitzWith ‖f'‖₊⁻¹ (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') from hf.isBigO_sub_rev this AddMonoidHomClass.antilipschitz_of_bound (smulRight (1 : 𝕜 →L[𝕜] 𝕜) f') fun x => by simp [norm_smul, ← div_eq_inv_mul, mul_div_cancel_right₀ _ (mt norm_eq_zero.1 hf')] theorem HasStrictDerivAt.hasDerivAt (h : HasStrictDerivAt f f' x) : HasDerivAt f f' x := h.hasFDerivAt theorem hasDerivWithinAt_congr_set' {s t : Set 𝕜} (y : 𝕜) (h : s =á¶ [𝓝[{y}ᶜ] x] t) : HasDerivWithinAt f f' s x ↔ HasDerivWithinAt f f' t x := hasFDerivWithinAt_congr_set' y h theorem hasDerivWithinAt_congr_set {s t : Set 𝕜} (h : s =á¶ [𝓝 x] t) : HasDerivWithinAt f f' s x ↔ HasDerivWithinAt f f' t x := hasFDerivWithinAt_congr_set h alias ⟹HasDerivWithinAt.congr_set, _⟩ := hasDerivWithinAt_congr_set @[simp] theorem hasDerivWithinAt_diff_singleton : HasDerivWithinAt f f' (s \ {x}) x ↔ HasDerivWithinAt f f' s x := hasFDerivWithinAt_diff_singleton _ @[simp] theorem hasDerivWithinAt_Ioi_iff_Ici [PartialOrder 𝕜] : HasDerivWithinAt f f' (Ioi x) x ↔ HasDerivWithinAt f f' (Ici x) x := by rw [← Ici_diff_left, hasDerivWithinAt_diff_singleton] alias ⟹HasDerivWithinAt.Ici_of_Ioi, HasDerivWithinAt.Ioi_of_Ici⟩ := hasDerivWithinAt_Ioi_iff_Ici @[simp] theorem hasDerivWithinAt_Iio_iff_Iic [PartialOrder 𝕜] : HasDerivWithinAt f f' (Iio x) x ↔ HasDerivWithinAt f f' (Iic x) x := by rw [← Iic_diff_right, hasDerivWithinAt_diff_singleton] alias ⟹HasDerivWithinAt.Iic_of_Iio, HasDerivWithinAt.Iio_of_Iic⟩ := hasDerivWithinAt_Iio_iff_Iic theorem HasDerivWithinAt.Ioi_iff_Ioo [LinearOrder 𝕜] [OrderClosedTopology 𝕜] {x y : 𝕜} (h : x < y) : HasDerivWithinAt f f' (Ioo x y) x ↔ HasDerivWithinAt f f' (Ioi x) x := hasFDerivWithinAt_inter <| Iio_mem_nhds h alias ⟹HasDerivWithinAt.Ioi_of_Ioo, HasDerivWithinAt.Ioo_of_Ioi⟩ := HasDerivWithinAt.Ioi_iff_Ioo theorem hasDerivAt_iff_isLittleO_nhds_zero : HasDerivAt f f' x ↔ (fun h => f (x + h) - f x - h • f') =o[𝓝 0] fun h => h := hasFDerivAt_iff_isLittleO_nhds_zero theorem HasDerivAtFilter.mono (h : HasDerivAtFilter f f' x L₂) (hst : L₁ ≀ L₂) : HasDerivAtFilter f f' x L₁ := HasFDerivAtFilter.mono h hst theorem HasDerivWithinAt.mono (h : HasDerivWithinAt f f' t x) (hst : s ⊆ t) : HasDerivWithinAt f f' s x := HasFDerivWithinAt.mono h hst theorem HasDerivWithinAt.mono_of_mem (h : HasDerivWithinAt f f' t x) (hst : t ∈ 𝓝[s] x) : HasDerivWithinAt f f' s x := HasFDerivWithinAt.mono_of_mem h hst theorem HasDerivAt.hasDerivAtFilter (h : HasDerivAt f f' x) (hL : L ≀ 𝓝 x) : HasDerivAtFilter f f' x L := HasFDerivAt.hasFDerivAtFilter h hL theorem HasDerivAt.hasDerivWithinAt (h : HasDerivAt f f' x) : HasDerivWithinAt f f' s x := HasFDerivAt.hasFDerivWithinAt h theorem HasDerivWithinAt.differentiableWithinAt (h : HasDerivWithinAt f f' s x) : DifferentiableWithinAt 𝕜 f s x := HasFDerivWithinAt.differentiableWithinAt h theorem HasDerivAt.differentiableAt (h : HasDerivAt f f' x) : DifferentiableAt 𝕜 f x := HasFDerivAt.differentiableAt h @[simp] theorem hasDerivWithinAt_univ : HasDerivWithinAt f f' univ x ↔ HasDerivAt f f' x := hasFDerivWithinAt_univ theorem HasDerivAt.unique (h₀ : HasDerivAt f f₀' x) (h₁ : HasDerivAt f f₁' x) : f₀' = f₁' := smulRight_one_eq_iff.mp <| h₀.hasFDerivAt.unique h₁ theorem hasDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) : HasDerivWithinAt f f' (s ∩ t) x ↔ HasDerivWithinAt f f' s x := hasFDerivWithinAt_inter' h theorem hasDerivWithinAt_inter (h : t ∈ 𝓝 x) : HasDerivWithinAt f f' (s ∩ t) x ↔ HasDerivWithinAt f f' s x := hasFDerivWithinAt_inter h theorem HasDerivWithinAt.union (hs : HasDerivWithinAt f f' s x) (ht : HasDerivWithinAt f f' t x) : HasDerivWithinAt f f' (s ∪ t) x := hs.hasFDerivWithinAt.union ht.hasFDerivWithinAt theorem HasDerivWithinAt.hasDerivAt (h : HasDerivWithinAt f f' s x) (hs : s ∈ 𝓝 x) : HasDerivAt f f' x := HasFDerivWithinAt.hasFDerivAt h hs theorem DifferentiableWithinAt.hasDerivWithinAt (h : DifferentiableWithinAt 𝕜 f s x) : HasDerivWithinAt f (derivWithin f s x) s x := h.hasFDerivWithinAt.hasDerivWithinAt theorem DifferentiableAt.hasDerivAt (h : DifferentiableAt 𝕜 f x) : HasDerivAt f (deriv f x) x := h.hasFDerivAt.hasDerivAt @[simp] theorem hasDerivAt_deriv_iff : HasDerivAt f (deriv f x) x ↔ DifferentiableAt 𝕜 f x := ⟹fun h => h.differentiableAt, fun h => h.hasDerivAt⟩ @[simp] theorem hasDerivWithinAt_derivWithin_iff : HasDerivWithinAt f (derivWithin f s x) s x ↔ DifferentiableWithinAt 𝕜 f s x := ⟹fun h => h.differentiableWithinAt, fun h => h.hasDerivWithinAt⟩ theorem DifferentiableOn.hasDerivAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : HasDerivAt f (deriv f x) x := (h.hasFDerivAt hs).hasDerivAt theorem HasDerivAt.deriv (h : HasDerivAt f f' x) : deriv f x = f' := h.differentiableAt.hasDerivAt.unique h theorem deriv_eq {f' : 𝕜 → F} (h : ∀ x, HasDerivAt f (f' x) x) : deriv f = f' := funext fun x => (h x).deriv theorem HasDerivWithinAt.derivWithin (h : HasDerivWithinAt f f' s x) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin f s x = f' := hxs.eq_deriv _ h.differentiableWithinAt.hasDerivWithinAt h theorem fderivWithin_derivWithin : (fderivWithin 𝕜 f s x : 𝕜 → F) 1 = derivWithin f s x := rfl theorem derivWithin_fderivWithin : smulRight (1 : 𝕜 →L[𝕜] 𝕜) (derivWithin f s x) = fderivWithin 𝕜 f s x := by simp [derivWithin] theorem norm_derivWithin_eq_norm_fderivWithin : ‖derivWithin f s x‖ = ‖fderivWithin 𝕜 f s x‖ := by simp [← derivWithin_fderivWithin] theorem fderiv_deriv : (fderiv 𝕜 f x : 𝕜 → F) 1 = deriv f x := rfl @[simp] theorem fderiv_eq_smul_deriv (y : 𝕜) : (fderiv 𝕜 f x : 𝕜 → F) y = y • deriv f x := by rw [← fderiv_deriv, ← ContinuousLinearMap.map_smul] simp only [smul_eq_mul, mul_one] theorem deriv_fderiv : smulRight (1 : 𝕜 →L[𝕜] 𝕜) (deriv f x) = fderiv 𝕜 f x := by simp only [deriv, ContinuousLinearMap.smulRight_one_one] lemma fderiv_eq_deriv_mul {f : 𝕜 → 𝕜} {x y : 𝕜} : (fderiv 𝕜 f x : 𝕜 → 𝕜) y = (deriv f x) * y := by simp [mul_comm] theorem norm_deriv_eq_norm_fderiv : ‖deriv f x‖ = ‖fderiv 𝕜 f x‖ := by simp [← deriv_fderiv] theorem DifferentiableAt.derivWithin (h : DifferentiableAt 𝕜 f x) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin f s x = deriv f x := by unfold derivWithin deriv rw [h.fderivWithin hxs] theorem HasDerivWithinAt.deriv_eq_zero (hd : HasDerivWithinAt f 0 s x) (H : UniqueDiffWithinAt 𝕜 s x) : deriv f x = 0 := (em' (DifferentiableAt 𝕜 f x)).elim deriv_zero_of_not_differentiableAt fun h => H.eq_deriv _ h.hasDerivAt.hasDerivWithinAt hd theorem derivWithin_of_mem (st : t ∈ 𝓝[s] x) (ht : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f t x) : derivWithin f s x = derivWithin f t x := ((DifferentiableWithinAt.hasDerivWithinAt h).mono_of_mem st).derivWithin ht theorem derivWithin_subset (st : s ⊆ t) (ht : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f t x) : derivWithin f s x = derivWithin f t x := ((DifferentiableWithinAt.hasDerivWithinAt h).mono st).derivWithin ht theorem derivWithin_congr_set' (y : 𝕜) (h : s =á¶ [𝓝[{y}ᶜ] x] t) : derivWithin f s x = derivWithin f t x := by simp only [derivWithin, fderivWithin_congr_set' y h] theorem derivWithin_congr_set (h : s =á¶ [𝓝 x] t) : derivWithin f s x = derivWithin f t x := by simp only [derivWithin, fderivWithin_congr_set h] @[simp] theorem derivWithin_univ : derivWithin f univ = deriv f := by ext unfold derivWithin deriv rw [fderivWithin_univ] theorem derivWithin_inter (ht : t ∈ 𝓝 x) : derivWithin f (s ∩ t) x = derivWithin f s x := by unfold derivWithin rw [fderivWithin_inter ht] theorem derivWithin_of_mem_nhds (h : s ∈ 𝓝 x) : derivWithin f s x = deriv f x := by simp only [derivWithin, deriv, fderivWithin_of_mem_nhds h] theorem derivWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) : derivWithin f s x = deriv f x := derivWithin_of_mem_nhds (hs.mem_nhds hx) lemma deriv_eqOn {f' : 𝕜 → F} (hs : IsOpen s) (hf' : ∀ x ∈ s, HasDerivWithinAt f (f' x) s x) : s.EqOn (deriv f) f' := fun x hx ↩ by rw [← derivWithin_of_isOpen hs hx, (hf' _ hx).derivWithin <| hs.uniqueDiffWithinAt hx] theorem deriv_mem_iff {f : 𝕜 → F} {s : Set F} {x : 𝕜} : deriv f x ∈ s ↔ DifferentiableAt 𝕜 f x ∧ deriv f x ∈ s √ ¬DifferentiableAt 𝕜 f x ∧ (0 : F) ∈ s := by by_cases hx : DifferentiableAt 𝕜 f x <;> simp [deriv_zero_of_not_differentiableAt, *] theorem derivWithin_mem_iff {f : 𝕜 → F} {t : Set 𝕜} {s : Set F} {x : 𝕜} : derivWithin f t x ∈ s ↔ DifferentiableWithinAt 𝕜 f t x ∧ derivWithin f t x ∈ s √ ¬DifferentiableWithinAt 𝕜 f t x ∧ (0 : F) ∈ s := by by_cases hx : DifferentiableWithinAt 𝕜 f t x <;> simp [derivWithin_zero_of_not_differentiableWithinAt, *] theorem differentiableWithinAt_Ioi_iff_Ici [PartialOrder 𝕜] : DifferentiableWithinAt 𝕜 f (Ioi x) x ↔ DifferentiableWithinAt 𝕜 f (Ici x) x := ⟹fun h => h.hasDerivWithinAt.Ici_of_Ioi.differentiableWithinAt, fun h => h.hasDerivWithinAt.Ioi_of_Ici.differentiableWithinAt⟩ -- Golfed while splitting the file theorem derivWithin_Ioi_eq_Ici {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (f : ℝ → E) (x : ℝ) : derivWithin f (Ioi x) x = derivWithin f (Ici x) x := by by_cases H : DifferentiableWithinAt ℝ f (Ioi x) x · have A := H.hasDerivWithinAt.Ici_of_Ioi have B := (differentiableWithinAt_Ioi_iff_Ici.1 H).hasDerivWithinAt simpa using (uniqueDiffOn_Ici x).eq left_mem_Ici A B · rw [derivWithin_zero_of_not_differentiableWithinAt H, derivWithin_zero_of_not_differentiableWithinAt] rwa [differentiableWithinAt_Ioi_iff_Ici] at H section congr /-! ### Congruence properties of derivatives -/ theorem Filter.EventuallyEq.hasDerivAtFilter_iff (h₀ : f₀ =á¶ [L] f₁) (hx : f₀ x = f₁ x) (h₁ : f₀' = f₁') : HasDerivAtFilter f₀ f₀' x L ↔ HasDerivAtFilter f₁ f₁' x L := h₀.hasFDerivAtFilter_iff hx (by simp [h₁]) theorem HasDerivAtFilter.congr_of_eventuallyEq (h : HasDerivAtFilter f f' x L) (hL : f₁ =á¶ [L] f) (hx : f₁ x = f x) : HasDerivAtFilter f₁ f' x L := by rwa [hL.hasDerivAtFilter_iff hx rfl] theorem HasDerivWithinAt.congr_mono (h : HasDerivWithinAt f f' s x) (ht : ∀ x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : HasDerivWithinAt f₁ f' t x := HasFDerivWithinAt.congr_mono h ht hx h₁ theorem HasDerivWithinAt.congr (h : HasDerivWithinAt f f' s x) (hs : ∀ x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : HasDerivWithinAt f₁ f' s x := h.congr_mono hs hx (Subset.refl _) theorem HasDerivWithinAt.congr_of_mem (h : HasDerivWithinAt f f' s x) (hs : ∀ x ∈ s, f₁ x = f x) (hx : x ∈ s) : HasDerivWithinAt f₁ f' s x := h.congr hs (hs _ hx) theorem HasDerivWithinAt.congr_of_eventuallyEq (h : HasDerivWithinAt f f' s x) (h₁ : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) : HasDerivWithinAt f₁ f' s x := HasDerivAtFilter.congr_of_eventuallyEq h h₁ hx theorem Filter.EventuallyEq.hasDerivWithinAt_iff (h₁ : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) : HasDerivWithinAt f₁ f' s x ↔ HasDerivWithinAt f f' s x := ⟹fun h' ↩ h'.congr_of_eventuallyEq h₁.symm hx.symm, fun h' ↩ h'.congr_of_eventuallyEq h₁ hx⟩ theorem HasDerivWithinAt.congr_of_eventuallyEq_of_mem (h : HasDerivWithinAt f f' s x) (h₁ : f₁ =á¶ [𝓝[s] x] f) (hx : x ∈ s) : HasDerivWithinAt f₁ f' s x := h.congr_of_eventuallyEq h₁ (h₁.eq_of_nhdsWithin hx) theorem Filter.EventuallyEq.hasDerivWithinAt_iff_of_mem (h₁ : f₁ =á¶ [𝓝[s] x] f) (hx : x ∈ s) : HasDerivWithinAt f₁ f' s x ↔ HasDerivWithinAt f f' s x := ⟹fun h' ↩ h'.congr_of_eventuallyEq_of_mem h₁.symm hx, fun h' ↩ h'.congr_of_eventuallyEq_of_mem h₁ hx⟩ theorem HasStrictDerivAt.congr_deriv (h : HasStrictDerivAt f f' x) (h' : f' = g') : HasStrictDerivAt f g' x := h.congr_fderiv <| congr_arg _ h' theorem HasDerivAt.congr_deriv (h : HasDerivAt f f' x) (h' : f' = g') : HasDerivAt f g' x := HasFDerivAt.congr_fderiv h <| congr_arg _ h' theorem HasDerivWithinAt.congr_deriv (h : HasDerivWithinAt f f' s x) (h' : f' = g') : HasDerivWithinAt f g' s x := HasFDerivWithinAt.congr_fderiv h <| congr_arg _ h' theorem HasDerivAt.congr_of_eventuallyEq (h : HasDerivAt f f' x) (h₁ : f₁ =á¶ [𝓝 x] f) : HasDerivAt f₁ f' x := HasDerivAtFilter.congr_of_eventuallyEq h h₁ (mem_of_mem_nhds h₁ : _) theorem Filter.EventuallyEq.hasDerivAt_iff (h : f₀ =á¶ [𝓝 x] f₁) : HasDerivAt f₀ f' x ↔ HasDerivAt f₁ f' x := ⟹fun h' ↩ h'.congr_of_eventuallyEq h.symm, fun h' ↩ h'.congr_of_eventuallyEq h⟩ theorem Filter.EventuallyEq.derivWithin_eq (hs : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) : derivWithin f₁ s x = derivWithin f s x := by unfold derivWithin rw [hs.fderivWithin_eq hx] theorem derivWithin_congr (hs : EqOn f₁ f s) (hx : f₁ x = f x) : derivWithin f₁ s x = derivWithin f s x := by unfold derivWithin rw [fderivWithin_congr hs hx] theorem Filter.EventuallyEq.deriv_eq (hL : f₁ =á¶ [𝓝 x] f) : deriv f₁ x = deriv f x := by unfold deriv rwa [Filter.EventuallyEq.fderiv_eq] protected theorem Filter.EventuallyEq.deriv (h : f₁ =á¶ [𝓝 x] f) : deriv f₁ =á¶ [𝓝 x] deriv f := h.eventuallyEq_nhds.mono fun _ h => h.deriv_eq end congr section id /-! ### Derivative of the identity -/ variable (s x L) theorem hasDerivAtFilter_id : HasDerivAtFilter id 1 x L := (hasFDerivAtFilter_id x L).hasDerivAtFilter theorem hasDerivWithinAt_id : HasDerivWithinAt id 1 s x := hasDerivAtFilter_id _ _ theorem hasDerivAt_id : HasDerivAt id 1 x := hasDerivAtFilter_id _ _ theorem hasDerivAt_id' : HasDerivAt (fun x : 𝕜 => x) 1 x := hasDerivAtFilter_id _ _ theorem hasStrictDerivAt_id : HasStrictDerivAt id 1 x := (hasStrictFDerivAt_id x).hasStrictDerivAt theorem deriv_id : deriv id x = 1 := HasDerivAt.deriv (hasDerivAt_id x) @[simp] theorem deriv_id' : deriv (@id 𝕜) = fun _ => 1 := funext deriv_id @[simp] theorem deriv_id'' : (deriv fun x : 𝕜 => x) = fun _ => 1 := deriv_id' theorem derivWithin_id (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin id s x = 1 := (hasDerivWithinAt_id x s).derivWithin hxs end id section Const /-! ### Derivative of constant functions -/ variable (c : F) (s x L) theorem hasDerivAtFilter_const : HasDerivAtFilter (fun _ => c) 0 x L := (hasFDerivAtFilter_const c x L).hasDerivAtFilter theorem hasStrictDerivAt_const : HasStrictDerivAt (fun _ => c) 0 x := (hasStrictFDerivAt_const c x).hasStrictDerivAt theorem hasDerivWithinAt_const : HasDerivWithinAt (fun _ => c) 0 s x := hasDerivAtFilter_const _ _ _ theorem hasDerivAt_const : HasDerivAt (fun _ => c) 0 x := hasDerivAtFilter_const _ _ _ theorem deriv_const : deriv (fun _ => c) x = 0 := HasDerivAt.deriv (hasDerivAt_const x c) @[simp] theorem deriv_const' : (deriv fun _ : 𝕜 => c) = fun _ => 0 := funext fun x => deriv_const x c theorem derivWithin_const (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun _ => c) s x = 0 := (hasDerivWithinAt_const _ _ _).derivWithin hxs end Const section Continuous /-! ### Continuity of a function admitting a derivative -/ nonrec theorem HasDerivAtFilter.tendsto_nhds (hL : L ≀ 𝓝 x) (h : HasDerivAtFilter f f' x L) : Tendsto f L (𝓝 (f x)) := h.tendsto_nhds hL theorem HasDerivWithinAt.continuousWithinAt (h : HasDerivWithinAt f f' s x) : ContinuousWithinAt f s x := HasDerivAtFilter.tendsto_nhds inf_le_left h theorem HasDerivAt.continuousAt (h : HasDerivAt f f' x) : ContinuousAt f x := HasDerivAtFilter.tendsto_nhds le_rfl h protected theorem HasDerivAt.continuousOn {f f' : 𝕜 → F} (hderiv : ∀ x ∈ s, HasDerivAt f (f' x) x) : ContinuousOn f s := fun x hx => (hderiv x hx).continuousAt.continuousWithinAt end Continuous /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. This version only assumes that `‖f x - f x₀‖ ≀ C * ‖x - x₀‖` in a neighborhood of `x`. -/ theorem HasDerivAt.le_of_lip' {f : 𝕜 → F} {f' : F} {x₀ : 𝕜} (hf : HasDerivAt f f' x₀) {C : ℝ} (hC₀ : 0 ≀ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≀ C * ‖x - x₀‖) : ‖f'‖ ≀ C := by simpa using HasFDerivAt.le_of_lip' hf.hasFDerivAt hC₀ hlip /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. -/ theorem HasDerivAt.le_of_lipschitzOn {f : 𝕜 → F} {f' : F} {x₀ : 𝕜} (hf : HasDerivAt f f' x₀) {s : Set 𝕜} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖f'‖ ≀ C := by simpa using HasFDerivAt.le_of_lipschitzOn hf.hasFDerivAt hs hlip /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz then its derivative at `x₀` has norm bounded by `C`. -/ theorem HasDerivAt.le_of_lipschitz {f : 𝕜 → F} {f' : F} {x₀ : 𝕜} (hf : HasDerivAt f f' x₀) {C : ℝ≥0} (hlip : LipschitzWith C f) : ‖f'‖ ≀ C := by simpa using HasFDerivAt.le_of_lipschitz hf.hasFDerivAt hlip /-- Converse to the mean value inequality: if `f` is `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. This version only assumes that `‖f x - f x₀‖ ≀ C * ‖x - x₀‖` in a neighborhood of `x`. -/ theorem norm_deriv_le_of_lip' {f : 𝕜 → F} {x₀ : 𝕜} {C : ℝ} (hC₀ : 0 ≀ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≀ C * ‖x - x₀‖) : ‖deriv f x₀‖ ≀ C := by simpa [norm_deriv_eq_norm_fderiv] using norm_fderiv_le_of_lip' 𝕜 hC₀ hlip /-- Converse to the mean value inequality: if `f` is `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. Version using `deriv`. -/ theorem norm_deriv_le_of_lipschitzOn {f : 𝕜 → F} {x₀ : 𝕜} {s : Set 𝕜} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖deriv f x₀‖ ≀ C := by simpa [norm_deriv_eq_norm_fderiv] using norm_fderiv_le_of_lipschitzOn 𝕜 hs hlip /-- Converse to the mean value inequality: if `f` is `C`-lipschitz then its derivative at `x₀` has norm bounded by `C`. Version using `deriv`. -/ theorem norm_deriv_le_of_lipschitz {f : 𝕜 → F} {x₀ : 𝕜} {C : ℝ≥0} (hlip : LipschitzWith C f) : ‖deriv f x₀‖ ≀ C := by simpa [norm_deriv_eq_norm_fderiv] using norm_fderiv_le_of_lipschitz 𝕜 hlip
Analysis\Calculus\Deriv\Comp.lean
/- 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, Yury Kudryashov, Yuyang Zhao -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Comp import Mathlib.Analysis.Calculus.FDeriv.RestrictScalars /-! # One-dimensional derivatives of compositions of functions In this file we prove the chain rule for the following cases: * `HasDerivAt.comp` etc: `f : 𝕜' → 𝕜'` composed with `g : 𝕜 → 𝕜'`; * `HasDerivAt.scomp` etc: `f : 𝕜' → E` composed with `g : 𝕜 → 𝕜'`; * `HasFDerivAt.comp_hasDerivAt` etc: `f : E → F` composed with `g : 𝕜 → E`; Here `𝕜` is the base normed field, `E` and `F` are normed spaces over `𝕜` and `𝕜'` is an algebra over `𝕜` (e.g., `𝕜'=𝕜` or `𝕜=ℝ`, `𝕜'=ℂ`). We also give versions with the `of_eq` suffix, which require an equality proof instead of definitional equality of the different points used in the composition. These versions are often more flexible to use. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## Keywords derivative, chain rule -/ universe u v w open scoped Classical open Topology Filter ENNReal open Filter Asymptotics Set open ContinuousLinearMap (smulRight smulRight_one_eq_iff) variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L L₁ L₂ : Filter 𝕜} 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 -/ variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] {s' t' : Set 𝕜'} {h : 𝕜 → 𝕜'} {h₁ : 𝕜 → 𝕜} {h₂ : 𝕜' → 𝕜'} {h' h₂' : 𝕜'} {h₁' : 𝕜} {g₁ : 𝕜' → F} {g₁' : F} {L' : Filter 𝕜'} {y : 𝕜'} (x) theorem HasDerivAtFilter.scomp (hg : HasDerivAtFilter g₁ g₁' (h x) L') (hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') : HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by simpa using ((hg.restrictScalars 𝕜).comp x hh hL).hasDerivAtFilter theorem HasDerivAtFilter.scomp_of_eq (hg : HasDerivAtFilter g₁ g₁' y L') (hh : HasDerivAtFilter h h' x L) (hy : y = h x) (hL : Tendsto h L L') : HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by rw [hy] at hg; exact hg.scomp x hh hL theorem HasDerivWithinAt.scomp_hasDerivAt (hg : HasDerivWithinAt g₁ g₁' s' (h x)) (hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') : HasDerivAt (g₁ ∘ h) (h' • g₁') x := hg.scomp x hh <| tendsto_inf.2 ⟹hh.continuousAt, tendsto_principal.2 <| eventually_of_forall hs⟩ theorem HasDerivWithinAt.scomp_hasDerivAt_of_eq (hg : HasDerivWithinAt g₁ g₁' s' y) (hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') (hy : y = h x) : HasDerivAt (g₁ ∘ h) (h' • g₁') x := by rw [hy] at hg; exact hg.scomp_hasDerivAt x hh hs nonrec theorem HasDerivWithinAt.scomp (hg : HasDerivWithinAt g₁ g₁' t' (h x)) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := hg.scomp x hh <| hh.continuousWithinAt.tendsto_nhdsWithin hst theorem HasDerivWithinAt.scomp_of_eq (hg : HasDerivWithinAt g₁ g₁' t' y) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') (hy : y = h x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by rw [hy] at hg; exact hg.scomp x hh hst /-- The chain rule. -/ nonrec theorem HasDerivAt.scomp (hg : HasDerivAt g₁ g₁' (h x)) (hh : HasDerivAt h h' x) : HasDerivAt (g₁ ∘ h) (h' • g₁') x := hg.scomp x hh hh.continuousAt /-- The chain rule. -/ theorem HasDerivAt.scomp_of_eq (hg : HasDerivAt g₁ g₁' y) (hh : HasDerivAt h h' x) (hy : y = h x) : HasDerivAt (g₁ ∘ h) (h' • g₁') x := by rw [hy] at hg; exact hg.scomp x hh theorem HasStrictDerivAt.scomp (hg : HasStrictDerivAt g₁ g₁' (h x)) (hh : HasStrictDerivAt h h' x) : HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by simpa using ((hg.restrictScalars 𝕜).comp x hh).hasStrictDerivAt theorem HasStrictDerivAt.scomp_of_eq (hg : HasStrictDerivAt g₁ g₁' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) : HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by rw [hy] at hg; exact hg.scomp x hh theorem HasDerivAt.scomp_hasDerivWithinAt (hg : HasDerivAt g₁ g₁' (h x)) (hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh (mapsTo_univ _ _) theorem HasDerivAt.scomp_hasDerivWithinAt_of_eq (hg : HasDerivAt g₁ g₁' y) (hh : HasDerivWithinAt h h' s x) (hy : y = h x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by rw [hy] at hg; exact hg.scomp_hasDerivWithinAt x hh theorem derivWithin.scomp (hg : DifferentiableWithinAt 𝕜' g₁ t' (h x)) (hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t') (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := (HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh.hasDerivWithinAt hs).derivWithin hxs theorem derivWithin.scomp_of_eq (hg : DifferentiableWithinAt 𝕜' g₁ t' y) (hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t') (hxs : UniqueDiffWithinAt 𝕜 s x) (hy : y = h x) : derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by rw [hy] at hg; exact derivWithin.scomp x hg hh hs hxs theorem deriv.scomp (hg : DifferentiableAt 𝕜' g₁ (h x)) (hh : DifferentiableAt 𝕜 h x) : deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) := (HasDerivAt.scomp x hg.hasDerivAt hh.hasDerivAt).deriv theorem deriv.scomp_of_eq (hg : DifferentiableAt 𝕜' g₁ y) (hh : DifferentiableAt 𝕜 h x) (hy : y = h x) : deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) := by rw [hy] at hg; exact deriv.scomp x hg hh /-! ### Derivative of the composition of a scalar and vector functions -/ theorem HasDerivAtFilter.comp_hasFDerivAtFilter {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E} (hh₂ : HasDerivAtFilter h₂ h₂' (f x) L') (hf : HasFDerivAtFilter f f' x L'') (hL : Tendsto f L'' L') : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by convert (hh₂.restrictScalars 𝕜).comp x hf hL ext x simp [mul_comm] theorem HasDerivAtFilter.comp_hasFDerivAtFilter_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E} (hh₂ : HasDerivAtFilter h₂ h₂' y L') (hf : HasFDerivAtFilter f f' x L'') (hL : Tendsto f L'' L') (hy : y = f x) : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by rw [hy] at hh₂; exact hh₂.comp_hasFDerivAtFilter x hf hL theorem HasStrictDerivAt.comp_hasStrictFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) (hh : HasStrictDerivAt h₂ h₂' (f x)) (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by rw [HasStrictDerivAt] at hh convert (hh.restrictScalars 𝕜).comp x hf ext x simp [mul_comm] theorem HasStrictDerivAt.comp_hasStrictFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) (hh : HasStrictDerivAt h₂ h₂' y) (hf : HasStrictFDerivAt f f' x) (hy : y = f x) : HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by rw [hy] at hh; exact hh.comp_hasStrictFDerivAt x hf theorem HasDerivAt.comp_hasFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) (hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivAt f f' x) : HasFDerivAt (h₂ ∘ f) (h₂' • f') x := hh.comp_hasFDerivAtFilter x hf hf.continuousAt theorem HasDerivAt.comp_hasFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) (hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivAt f f' x) (hy : y = f x) : HasFDerivAt (h₂ ∘ f) (h₂' • f') x := by rw [hy] at hh; exact hh.comp_hasFDerivAt x hf theorem HasDerivAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x) (hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := hh.comp_hasFDerivAtFilter x hf hf.continuousWithinAt theorem HasDerivAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x) (hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivWithinAt f f' s x) (hy : y = f x) : HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf theorem HasDerivWithinAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x) (hh : HasDerivWithinAt h₂ h₂' t (f x)) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t) : HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := hh.comp_hasFDerivAtFilter x hf <| hf.continuousWithinAt.tendsto_nhdsWithin hst theorem HasDerivWithinAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x) (hh : HasDerivWithinAt h₂ h₂' t y) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t) (hy : y = f x) : HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf hst /-! ### Derivative of the composition of two scalar functions -/ theorem HasDerivAtFilter.comp (hh₂ : HasDerivAtFilter h₂ h₂' (h x) L') (hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') : HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by rw [mul_comm] exact hh₂.scomp x hh hL theorem HasDerivAtFilter.comp_of_eq (hh₂ : HasDerivAtFilter h₂ h₂' y L') (hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') (hy : y = h x) : HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by rw [hy] at hh₂; exact hh₂.comp x hh hL theorem HasDerivWithinAt.comp (hh₂ : HasDerivWithinAt h₂ h₂' s' (h x)) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by rw [mul_comm] exact hh₂.scomp x hh hst theorem HasDerivWithinAt.comp_of_eq (hh₂ : HasDerivWithinAt h₂ h₂' s' y) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') (hy : y = h x) : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by rw [hy] at hh₂; exact hh₂.comp x hh hst /-- The chain rule. Note that the function `h₂` is a function on an algebra. If you are looking for the chain rule with `h₂` taking values in a vector space, use `HasDerivAt.scomp`. -/ nonrec theorem HasDerivAt.comp (hh₂ : HasDerivAt h₂ h₂' (h x)) (hh : HasDerivAt h h' x) : HasDerivAt (h₂ ∘ h) (h₂' * h') x := hh₂.comp x hh hh.continuousAt /-- The chain rule. Note that the function `h₂` is a function on an algebra. If you are looking for the chain rule with `h₂` taking values in a vector space, use `HasDerivAt.scomp_of_eq`. -/ theorem HasDerivAt.comp_of_eq (hh₂ : HasDerivAt h₂ h₂' y) (hh : HasDerivAt h h' x) (hy : y = h x) : HasDerivAt (h₂ ∘ h) (h₂' * h') x := by rw [hy] at hh₂; exact hh₂.comp x hh theorem HasStrictDerivAt.comp (hh₂ : HasStrictDerivAt h₂ h₂' (h x)) (hh : HasStrictDerivAt h h' x) : HasStrictDerivAt (h₂ ∘ h) (h₂' * h') x := by rw [mul_comm] exact hh₂.scomp x hh theorem HasStrictDerivAt.comp_of_eq (hh₂ : HasStrictDerivAt h₂ h₂' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) : HasStrictDerivAt (h₂ ∘ h) (h₂' * h') x := by rw [hy] at hh₂; exact hh₂.comp x hh theorem HasDerivAt.comp_hasDerivWithinAt (hh₂ : HasDerivAt h₂ h₂' (h x)) (hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := hh₂.hasDerivWithinAt.comp x hh (mapsTo_univ _ _) theorem HasDerivAt.comp_hasDerivWithinAt_of_eq (hh₂ : HasDerivAt h₂ h₂' y) (hh : HasDerivWithinAt h h' s x) (hy : y = h x) : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by rw [hy] at hh₂; exact hh₂.comp_hasDerivWithinAt x hh theorem derivWithin.comp (hh₂ : DifferentiableWithinAt 𝕜' h₂ s' (h x)) (hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s s') (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (h₂ ∘ h) s x = derivWithin h₂ s' (h x) * derivWithin h s x := (hh₂.hasDerivWithinAt.comp x hh.hasDerivWithinAt hs).derivWithin hxs theorem derivWithin.comp_of_eq (hh₂ : DifferentiableWithinAt 𝕜' h₂ s' y) (hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s s') (hxs : UniqueDiffWithinAt 𝕜 s x) (hy : y = h x) : derivWithin (h₂ ∘ h) s x = derivWithin h₂ s' (h x) * derivWithin h s x := by rw [hy] at hh₂; exact derivWithin.comp x hh₂ hh hs hxs theorem deriv.comp (hh₂ : DifferentiableAt 𝕜' h₂ (h x)) (hh : DifferentiableAt 𝕜 h x) : deriv (h₂ ∘ h) x = deriv h₂ (h x) * deriv h x := (hh₂.hasDerivAt.comp x hh.hasDerivAt).deriv theorem deriv.comp_of_eq (hh₂ : DifferentiableAt 𝕜' h₂ y) (hh : DifferentiableAt 𝕜 h x) (hy : y = h x) : deriv (h₂ ∘ h) x = deriv h₂ (h x) * deriv h x := by rw [hy] at hh₂; exact deriv.comp x hh₂ hh protected nonrec theorem HasDerivAtFilter.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivAtFilter f f' x L) (hL : Tendsto f L L) (hx : f x = x) (n : ℕ) : HasDerivAtFilter f^[n] (f' ^ n) x L := by have := hf.iterate hL hx n rwa [ContinuousLinearMap.smulRight_one_pow] at this protected nonrec theorem HasDerivAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivAt f f' x) (hx : f x = x) (n : ℕ) : HasDerivAt f^[n] (f' ^ n) x := hf.iterate _ (have := hf.tendsto_nhds le_rfl; by rwa [hx] at this) hx n protected theorem HasDerivWithinAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivWithinAt f f' s x) (hx : f x = x) (hs : MapsTo f s s) (n : ℕ) : HasDerivWithinAt f^[n] (f' ^ n) s x := by have := HasFDerivWithinAt.iterate hf hx hs n rwa [ContinuousLinearMap.smulRight_one_pow] at this protected nonrec theorem HasStrictDerivAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasStrictDerivAt f f' x) (hx : f x = x) (n : ℕ) : HasStrictDerivAt f^[n] (f' ^ n) x := by have := hf.iterate hx n rwa [ContinuousLinearMap.smulRight_one_pow] at this end Composition section CompositionVector /-! ### Derivative of the composition of a function between vector spaces and a function on `𝕜` -/ open ContinuousLinearMap variable {l : F → E} {l' : F →L[𝕜] E} {y : F} 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 HasFDerivWithinAt.comp_hasDerivWithinAt {t : Set F} (hl : HasFDerivWithinAt l l' t (f x)) (hf : HasDerivWithinAt f f' s x) (hst : MapsTo f s t) : HasDerivWithinAt (l ∘ f) (l' f') s x := by simpa only [one_apply, one_smul, smulRight_apply, coe_comp', (· ∘ ·)] using (hl.comp x hf.hasFDerivWithinAt hst).hasDerivWithinAt /-- 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 HasFDerivWithinAt.comp_hasDerivWithinAt_of_eq {t : Set F} (hl : HasFDerivWithinAt l l' t y) (hf : HasDerivWithinAt f f' s x) (hst : MapsTo f s t) (hy : y = f x) : HasDerivWithinAt (l ∘ f) (l' f') s x := by rw [hy] at hl; exact hl.comp_hasDerivWithinAt x hf hst theorem HasFDerivAt.comp_hasDerivWithinAt (hl : HasFDerivAt l l' (f x)) (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (l ∘ f) (l' f') s x := hl.hasFDerivWithinAt.comp_hasDerivWithinAt x hf (mapsTo_univ _ _) theorem HasFDerivAt.comp_hasDerivWithinAt_of_eq (hl : HasFDerivAt l l' y) (hf : HasDerivWithinAt f f' s x) (hy : y = f x) : HasDerivWithinAt (l ∘ f) (l' f') s x := by rw [hy] at hl; exact hl.comp_hasDerivWithinAt x hf /-- 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 HasFDerivAt.comp_hasDerivAt (hl : HasFDerivAt l l' (f x)) (hf : HasDerivAt f f' x) : HasDerivAt (l ∘ f) (l' f') x := hasDerivWithinAt_univ.mp <| hl.comp_hasDerivWithinAt x hf.hasDerivWithinAt /-- 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 HasFDerivAt.comp_hasDerivAt_of_eq (hl : HasFDerivAt l l' y) (hf : HasDerivAt f f' x) (hy : y = f x) : HasDerivAt (l ∘ f) (l' f') x := by rw [hy] at hl; exact hl.comp_hasDerivAt x hf theorem HasStrictFDerivAt.comp_hasStrictDerivAt (hl : HasStrictFDerivAt l l' (f x)) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (l ∘ f) (l' f') x := by simpa only [one_apply, one_smul, smulRight_apply, coe_comp', (· ∘ ·)] using (hl.comp x hf.hasStrictFDerivAt).hasStrictDerivAt theorem HasStrictFDerivAt.comp_hasStrictDerivAt_of_eq (hl : HasStrictFDerivAt l l' y) (hf : HasStrictDerivAt f f' x) (hy : y = f x) : HasStrictDerivAt (l ∘ f) (l' f') x := by rw [hy] at hl; exact hl.comp_hasStrictDerivAt x hf theorem fderivWithin.comp_derivWithin {t : Set F} (hl : DifferentiableWithinAt 𝕜 l t (f x)) (hf : DifferentiableWithinAt 𝕜 f s x) (hs : MapsTo f s t) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (l ∘ f) s x = (fderivWithin 𝕜 l t (f x) : F → E) (derivWithin f s x) := (hl.hasFDerivWithinAt.comp_hasDerivWithinAt x hf.hasDerivWithinAt hs).derivWithin hxs theorem fderivWithin.comp_derivWithin_of_eq {t : Set F} (hl : DifferentiableWithinAt 𝕜 l t y) (hf : DifferentiableWithinAt 𝕜 f s x) (hs : MapsTo f s t) (hxs : UniqueDiffWithinAt 𝕜 s x) (hy : y = f x) : derivWithin (l ∘ f) s x = (fderivWithin 𝕜 l t (f x) : F → E) (derivWithin f s x) := by rw [hy] at hl; exact fderivWithin.comp_derivWithin x hl hf hs hxs theorem fderiv.comp_deriv (hl : DifferentiableAt 𝕜 l (f x)) (hf : DifferentiableAt 𝕜 f x) : deriv (l ∘ f) x = (fderiv 𝕜 l (f x) : F → E) (deriv f x) := (hl.hasFDerivAt.comp_hasDerivAt x hf.hasDerivAt).deriv theorem fderiv.comp_deriv_of_eq (hl : DifferentiableAt 𝕜 l y) (hf : DifferentiableAt 𝕜 f x) (hy : y = f x) : deriv (l ∘ f) x = (fderiv 𝕜 l (f x) : F → E) (deriv f x) := by rw [hy] at hl; exact fderiv.comp_deriv x hl hf end CompositionVector
Analysis\Calculus\Deriv\Inv.lean
/- Copyright (c) 2023 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp /-! # Derivatives of `x ↩ x⁻¹` and `f x / g x` In this file we prove `(x⁻¹)' = -1 / x ^ 2`, `((f x)⁻¹)' = -f' x / (f x) ^ 2`, and `(f x / g x)' = (f' x * g x - f x * g' x) / (g x) ^ 2` for different notions of derivative. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative -/ universe u v w open scoped Classical open Topology Filter ENNReal open Filter Asymptotics Set open ContinuousLinearMap (smulRight smulRight_one_eq_iff) variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L : Filter 𝕜} section Inverse /-! ### Derivative of `x ↩ x⁻¹` -/ theorem hasStrictDerivAt_inv (hx : x ≠ 0) : HasStrictDerivAt Inv.inv (-(x ^ 2)⁻¹) x := by suffices (fun p : 𝕜 × 𝕜 => (p.1 - p.2) * ((x * x)⁻¹ - (p.1 * p.2)⁻¹)) =o[𝓝 (x, x)] fun p => (p.1 - p.2) * 1 by refine this.congr' ?_ (eventually_of_forall fun _ => mul_one _) refine Eventually.mono ((isOpen_ne.prod isOpen_ne).mem_nhds ⟹hx, hx⟩) ?_ rintro ⟹y, z⟩ ⟹hy, hz⟩ simp only [mem_setOf_eq] at hy hz -- hy : y ≠ 0, hz : z ≠ 0 field_simp [hx, hy, hz] ring refine (isBigO_refl (fun p : 𝕜 × 𝕜 => p.1 - p.2) _).mul_isLittleO ((isLittleO_one_iff 𝕜).2 ?_) rw [← sub_self (x * x)⁻¹] exact tendsto_const_nhds.sub ((continuous_mul.tendsto (x, x)).inv₀ <| mul_ne_zero hx hx) theorem hasDerivAt_inv (x_ne_zero : x ≠ 0) : HasDerivAt (fun y => y⁻¹) (-(x ^ 2)⁻¹) x := (hasStrictDerivAt_inv x_ne_zero).hasDerivAt theorem hasDerivWithinAt_inv (x_ne_zero : x ≠ 0) (s : Set 𝕜) : HasDerivWithinAt (fun x => x⁻¹) (-(x ^ 2)⁻¹) s x := (hasDerivAt_inv x_ne_zero).hasDerivWithinAt theorem differentiableAt_inv : DifferentiableAt 𝕜 (fun x => x⁻¹) x ↔ x ≠ 0 := ⟹fun H => NormedField.continuousAt_inv.1 H.continuousAt, fun H => (hasDerivAt_inv H).differentiableAt⟩ theorem differentiableWithinAt_inv (x_ne_zero : x ≠ 0) : DifferentiableWithinAt 𝕜 (fun x => x⁻¹) s x := (differentiableAt_inv.2 x_ne_zero).differentiableWithinAt theorem differentiableOn_inv : DifferentiableOn 𝕜 (fun x : 𝕜 => x⁻¹) { x | x ≠ 0 } := fun _x hx => differentiableWithinAt_inv hx theorem deriv_inv : deriv (fun x => x⁻¹) x = -(x ^ 2)⁻¹ := by rcases eq_or_ne x 0 with (rfl | hne) · simp [deriv_zero_of_not_differentiableAt (mt differentiableAt_inv.1 (not_not.2 rfl))] · exact (hasDerivAt_inv hne).deriv @[simp] theorem deriv_inv' : (deriv fun x : 𝕜 => x⁻¹) = fun x => -(x ^ 2)⁻¹ := funext fun _ => deriv_inv theorem derivWithin_inv (x_ne_zero : x ≠ 0) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x => x⁻¹) s x = -(x ^ 2)⁻¹ := by rw [DifferentiableAt.derivWithin (differentiableAt_inv.2 x_ne_zero) hxs] exact deriv_inv theorem hasFDerivAt_inv (x_ne_zero : x ≠ 0) : HasFDerivAt (fun x => x⁻¹) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (-(x ^ 2)⁻¹) : 𝕜 →L[𝕜] 𝕜) x := hasDerivAt_inv x_ne_zero theorem hasFDerivWithinAt_inv (x_ne_zero : x ≠ 0) : HasFDerivWithinAt (fun x => x⁻¹) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (-(x ^ 2)⁻¹) : 𝕜 →L[𝕜] 𝕜) s x := (hasFDerivAt_inv x_ne_zero).hasFDerivWithinAt theorem fderiv_inv : fderiv 𝕜 (fun x => x⁻¹) x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (-(x ^ 2)⁻¹) := by rw [← deriv_fderiv, deriv_inv] theorem fderivWithin_inv (x_ne_zero : x ≠ 0) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x => x⁻¹) s x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (-(x ^ 2)⁻¹) := by rw [DifferentiableAt.fderivWithin (differentiableAt_inv.2 x_ne_zero) hxs] exact fderiv_inv variable {c : 𝕜 → 𝕜} {h : E → 𝕜} {c' : 𝕜} {z : E} {S : Set E} theorem HasDerivWithinAt.inv (hc : HasDerivWithinAt c c' s x) (hx : c x ≠ 0) : HasDerivWithinAt (fun y => (c y)⁻¹) (-c' / c x ^ 2) s x := by convert (hasDerivAt_inv hx).comp_hasDerivWithinAt x hc using 1 field_simp theorem HasDerivAt.inv (hc : HasDerivAt c c' x) (hx : c x ≠ 0) : HasDerivAt (fun y => (c y)⁻¹) (-c' / c x ^ 2) x := by rw [← hasDerivWithinAt_univ] at * exact hc.inv hx theorem DifferentiableWithinAt.inv (hf : DifferentiableWithinAt 𝕜 h S z) (hz : h z ≠ 0) : DifferentiableWithinAt 𝕜 (fun x => (h x)⁻¹) S z := (differentiableAt_inv.mpr hz).comp_differentiableWithinAt z hf @[simp] theorem DifferentiableAt.inv (hf : DifferentiableAt 𝕜 h z) (hz : h z ≠ 0) : DifferentiableAt 𝕜 (fun x => (h x)⁻¹) z := (differentiableAt_inv.mpr hz).comp z hf theorem DifferentiableOn.inv (hf : DifferentiableOn 𝕜 h S) (hz : ∀ x ∈ S, h x ≠ 0) : DifferentiableOn 𝕜 (fun x => (h x)⁻¹) S := fun x h => (hf x h).inv (hz x h) @[simp] theorem Differentiable.inv (hf : Differentiable 𝕜 h) (hz : ∀ x, h x ≠ 0) : Differentiable 𝕜 fun x => (h x)⁻¹ := fun x => (hf x).inv (hz x) theorem derivWithin_inv' (hc : DifferentiableWithinAt 𝕜 c s x) (hx : c x ≠ 0) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x => (c x)⁻¹) s x = -derivWithin c s x / c x ^ 2 := (hc.hasDerivWithinAt.inv hx).derivWithin hxs @[simp] theorem deriv_inv'' (hc : DifferentiableAt 𝕜 c x) (hx : c x ≠ 0) : deriv (fun x => (c x)⁻¹) x = -deriv c x / c x ^ 2 := (hc.hasDerivAt.inv hx).deriv end Inverse section Division /-! ### Derivative of `x ↩ c x / d x` -/ variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] {c d : 𝕜 → 𝕜'} {c' d' : 𝕜'} theorem HasDerivWithinAt.div (hc : HasDerivWithinAt c c' s x) (hd : HasDerivWithinAt d d' s x) (hx : d x ≠ 0) : HasDerivWithinAt (fun y => c y / d y) ((c' * d x - c x * d') / d x ^ 2) s x := by convert hc.mul ((hasDerivAt_inv hx).comp_hasDerivWithinAt x hd) using 1 · simp only [div_eq_mul_inv, (· ∘ ·)] · field_simp ring theorem HasStrictDerivAt.div (hc : HasStrictDerivAt c c' x) (hd : HasStrictDerivAt d d' x) (hx : d x ≠ 0) : HasStrictDerivAt (fun y => c y / d y) ((c' * d x - c x * d') / d x ^ 2) x := by convert hc.mul ((hasStrictDerivAt_inv hx).comp x hd) using 1 · simp only [div_eq_mul_inv, (· ∘ ·)] · field_simp ring theorem HasDerivAt.div (hc : HasDerivAt c c' x) (hd : HasDerivAt d d' x) (hx : d x ≠ 0) : HasDerivAt (fun y => c y / d y) ((c' * d x - c x * d') / d x ^ 2) x := by rw [← hasDerivWithinAt_univ] at * exact hc.div hd hx theorem DifferentiableWithinAt.div (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) (hx : d x ≠ 0) : DifferentiableWithinAt 𝕜 (fun x => c x / d x) s x := (hc.hasDerivWithinAt.div hd.hasDerivWithinAt hx).differentiableWithinAt @[simp] theorem DifferentiableAt.div (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) (hx : d x ≠ 0) : DifferentiableAt 𝕜 (fun x => c x / d x) x := (hc.hasDerivAt.div hd.hasDerivAt hx).differentiableAt theorem DifferentiableOn.div (hc : DifferentiableOn 𝕜 c s) (hd : DifferentiableOn 𝕜 d s) (hx : ∀ x ∈ s, d x ≠ 0) : DifferentiableOn 𝕜 (fun x => c x / d x) s := fun x h => (hc x h).div (hd x h) (hx x h) @[simp] theorem Differentiable.div (hc : Differentiable 𝕜 c) (hd : Differentiable 𝕜 d) (hx : ∀ x, d x ≠ 0) : Differentiable 𝕜 fun x => c x / d x := fun x => (hc x).div (hd x) (hx x) theorem derivWithin_div (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) (hx : d x ≠ 0) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x => c x / d x) s x = (derivWithin c s x * d x - c x * derivWithin d s x) / d x ^ 2 := (hc.hasDerivWithinAt.div hd.hasDerivWithinAt hx).derivWithin hxs @[simp] theorem deriv_div (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) (hx : d x ≠ 0) : deriv (fun x => c x / d x) x = (deriv c x * d x - c x * deriv d x) / d x ^ 2 := (hc.hasDerivAt.div hd.hasDerivAt hx).deriv end Division
Analysis\Calculus\Deriv\Inverse.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.FDeriv.Equiv /-! # Inverse function theorem - the easy half In this file we prove that `g' (f x) = (f' x)⁻¹` provided that `f` is strictly differentiable at `x`, `f' x ≠ 0`, and `g` is a local left inverse of `f` that is continuous at `f x`. This is the easy half of the inverse function theorem: the harder half states that `g` exists. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative, inverse function -/ universe u v w open scoped Classical open Topology Filter ENNReal open Filter Asymptotics Set variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L L₁ L₂ : Filter 𝕜} theorem HasStrictDerivAt.hasStrictFDerivAt_equiv {f : 𝕜 → 𝕜} {f' x : 𝕜} (hf : HasStrictDerivAt f f' x) (hf' : f' ≠ 0) : HasStrictFDerivAt f (ContinuousLinearEquiv.unitsEquivAut 𝕜 (Units.mk0 f' hf') : 𝕜 →L[𝕜] 𝕜) x := hf theorem HasDerivAt.hasFDerivAt_equiv {f : 𝕜 → 𝕜} {f' x : 𝕜} (hf : HasDerivAt f f' x) (hf' : f' ≠ 0) : HasFDerivAt f (ContinuousLinearEquiv.unitsEquivAut 𝕜 (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 HasStrictDerivAt.of_local_left_inverse {f g : 𝕜 → 𝕜} {f' a : 𝕜} (hg : ContinuousAt g a) (hf : HasStrictDerivAt f f' (g a)) (hf' : f' ≠ 0) (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : HasStrictDerivAt g f'⁻¹ a := (hf.hasStrictFDerivAt_equiv hf').of_local_left_inverse hg hfg /-- If `f` is a partial 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. -/ theorem PartialHomeomorph.hasStrictDerivAt_symm (f : PartialHomeomorph 𝕜 𝕜) {a f' : 𝕜} (ha : a ∈ f.target) (hf' : f' ≠ 0) (htff' : HasStrictDerivAt f f' (f.symm a)) : HasStrictDerivAt f.symm f'⁻¹ a := htff'.of_local_left_inverse (f.symm.continuousAt 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 HasDerivAt.of_local_left_inverse {f g : 𝕜 → 𝕜} {f' a : 𝕜} (hg : ContinuousAt g a) (hf : HasDerivAt f f' (g a)) (hf' : f' ≠ 0) (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : HasDerivAt g f'⁻¹ a := (hf.hasFDerivAt_equiv hf').of_local_left_inverse hg hfg /-- If `f` is a partial homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has a 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. -/ theorem PartialHomeomorph.hasDerivAt_symm (f : PartialHomeomorph 𝕜 𝕜) {a f' : 𝕜} (ha : a ∈ f.target) (hf' : f' ≠ 0) (htff' : HasDerivAt f f' (f.symm a)) : HasDerivAt f.symm f'⁻¹ a := htff'.of_local_left_inverse (f.symm.continuousAt ha) hf' (f.eventually_right_inverse ha) theorem HasDerivAt.eventually_ne (h : HasDerivAt f f' x) (hf' : f' ≠ 0) : ∀ᶠ z in 𝓝[≠] x, f z ≠ f x := (hasDerivAt_iff_hasFDerivAt.1 h).eventually_ne ⟹‖f'‖⁻¹, fun z => by field_simp [norm_smul, mt norm_eq_zero.1 hf']⟩ theorem HasDerivAt.tendsto_punctured_nhds (h : HasDerivAt f f' x) (hf' : f' ≠ 0) : Tendsto f (𝓝[≠] x) (𝓝[≠] f x) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ h.continuousAt.continuousWithinAt (h.eventually_ne hf') theorem not_differentiableWithinAt_of_local_left_inverse_hasDerivWithinAt_zero {f g : 𝕜 → 𝕜} {a : 𝕜} {s t : Set 𝕜} (ha : a ∈ s) (hsu : UniqueDiffWithinAt 𝕜 s a) (hf : HasDerivWithinAt f 0 t (g a)) (hst : MapsTo g s t) (hfg : f ∘ g =á¶ [𝓝[s] a] id) : ¬DifferentiableWithinAt 𝕜 g s a := by intro hg have := (hf.comp a hg.hasDerivWithinAt hst).congr_of_eventuallyEq_of_mem hfg.symm ha simpa using hsu.eq_deriv _ this (hasDerivWithinAt_id _ _) theorem not_differentiableAt_of_local_left_inverse_hasDerivAt_zero {f g : 𝕜 → 𝕜} {a : 𝕜} (hf : HasDerivAt f 0 (g a)) (hfg : f ∘ g =á¶ [𝓝 a] id) : ¬DifferentiableAt 𝕜 g a := by intro hg have := (hf.comp a hg.hasDerivAt).congr_of_eventuallyEq hfg.symm simpa using this.unique (hasDerivAt_id a)
Analysis\Calculus\Deriv\Linear.lean
/- Copyright (c) 2019 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Linear /-! # Derivatives of continuous linear maps from the base field In this file we prove that `f : 𝕜 →L[𝕜] E` (or `f : 𝕜 →ₗ[𝕜] E`) has derivative `f 1`. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative, linear map -/ universe u v w open Topology Filter open Filter Asymptotics Set variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {x : 𝕜} variable {s : Set 𝕜} variable {L : Filter 𝕜} section ContinuousLinearMap /-! ### Derivative of continuous linear maps -/ variable (e : 𝕜 →L[𝕜] F) protected theorem ContinuousLinearMap.hasDerivAtFilter : HasDerivAtFilter e (e 1) x L := e.hasFDerivAtFilter.hasDerivAtFilter protected theorem ContinuousLinearMap.hasStrictDerivAt : HasStrictDerivAt e (e 1) x := e.hasStrictFDerivAt.hasStrictDerivAt protected theorem ContinuousLinearMap.hasDerivAt : HasDerivAt e (e 1) x := e.hasDerivAtFilter protected theorem ContinuousLinearMap.hasDerivWithinAt : HasDerivWithinAt e (e 1) s x := e.hasDerivAtFilter @[simp] protected theorem ContinuousLinearMap.deriv : deriv e x = e 1 := e.hasDerivAt.deriv protected theorem ContinuousLinearMap.derivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin e s x = e 1 := e.hasDerivWithinAt.derivWithin hxs end ContinuousLinearMap section LinearMap /-! ### Derivative of bundled linear maps -/ variable (e : 𝕜 →ₗ[𝕜] F) protected theorem LinearMap.hasDerivAtFilter : HasDerivAtFilter e (e 1) x L := e.toContinuousLinearMap₁.hasDerivAtFilter protected theorem LinearMap.hasStrictDerivAt : HasStrictDerivAt e (e 1) x := e.toContinuousLinearMap₁.hasStrictDerivAt protected theorem LinearMap.hasDerivAt : HasDerivAt e (e 1) x := e.hasDerivAtFilter protected theorem LinearMap.hasDerivWithinAt : HasDerivWithinAt e (e 1) s x := e.hasDerivAtFilter @[simp] protected theorem LinearMap.deriv : deriv e x = e 1 := e.hasDerivAt.deriv protected theorem LinearMap.derivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin e s x = e 1 := e.hasDerivWithinAt.derivWithin hxs end LinearMap
Analysis\Calculus\Deriv\Mul.lean
/- Copyright (c) 2019 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, Anatole Dedecker, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Mul import Mathlib.Analysis.Calculus.FDeriv.Add /-! # Derivative of `f x * g x` In this file we prove formulas for `(f x * g x)'` and `(f x • g x)'`. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative, multiplication -/ universe u v w noncomputable section open scoped Topology Filter ENNReal open Filter Asymptotics Set open ContinuousLinearMap (smulRight smulRight_one_eq_iff) variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L L₁ L₂ : Filter 𝕜} /-! ### Derivative of bilinear maps -/ namespace ContinuousLinearMap variable {B : E →L[𝕜] F →L[𝕜] G} {u : 𝕜 → E} {v : 𝕜 → F} {u' : E} {v' : F} theorem hasDerivWithinAt_of_bilinear (hu : HasDerivWithinAt u u' s x) (hv : HasDerivWithinAt v v' s x) : HasDerivWithinAt (fun x ↩ B (u x) (v x)) (B (u x) v' + B u' (v x)) s x := by simpa using (B.hasFDerivWithinAt_of_bilinear hu.hasFDerivWithinAt hv.hasFDerivWithinAt).hasDerivWithinAt theorem hasDerivAt_of_bilinear (hu : HasDerivAt u u' x) (hv : HasDerivAt v v' x) : HasDerivAt (fun x ↩ B (u x) (v x)) (B (u x) v' + B u' (v x)) x := by simpa using (B.hasFDerivAt_of_bilinear hu.hasFDerivAt hv.hasFDerivAt).hasDerivAt theorem hasStrictDerivAt_of_bilinear (hu : HasStrictDerivAt u u' x) (hv : HasStrictDerivAt v v' x) : HasStrictDerivAt (fun x ↩ B (u x) (v x)) (B (u x) v' + B u' (v x)) x := by simpa using (B.hasStrictFDerivAt_of_bilinear hu.hasStrictFDerivAt hv.hasStrictFDerivAt).hasStrictDerivAt theorem derivWithin_of_bilinear (hxs : UniqueDiffWithinAt 𝕜 s x) (hu : DifferentiableWithinAt 𝕜 u s x) (hv : DifferentiableWithinAt 𝕜 v s x) : derivWithin (fun y => B (u y) (v y)) s x = B (u x) (derivWithin v s x) + B (derivWithin u s x) (v x) := (B.hasDerivWithinAt_of_bilinear hu.hasDerivWithinAt hv.hasDerivWithinAt).derivWithin hxs theorem deriv_of_bilinear (hu : DifferentiableAt 𝕜 u x) (hv : DifferentiableAt 𝕜 v x) : deriv (fun y => B (u y) (v y)) x = B (u x) (deriv v x) + B (deriv u x) (v x) := (B.hasDerivAt_of_bilinear hu.hasDerivAt hv.hasDerivAt).deriv end ContinuousLinearMap section SMul /-! ### Derivative of the multiplication of a scalar function and a vector function -/ variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] {c : 𝕜 → 𝕜'} {c' : 𝕜'} theorem HasDerivWithinAt.smul (hc : HasDerivWithinAt c c' s x) (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun y => c y • f y) (c x • f' + c' • f x) s x := by simpa using (HasFDerivWithinAt.smul hc hf).hasDerivWithinAt theorem HasDerivAt.smul (hc : HasDerivAt c c' x) (hf : HasDerivAt f f' x) : HasDerivAt (fun y => c y • f y) (c x • f' + c' • f x) x := by rw [← hasDerivWithinAt_univ] at * exact hc.smul hf nonrec theorem HasStrictDerivAt.smul (hc : HasStrictDerivAt c c' x) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun y => c y • f y) (c x • f' + c' • f x) x := by simpa using (hc.smul hf).hasStrictDerivAt theorem derivWithin_smul (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hf : DifferentiableWithinAt 𝕜 f s x) : derivWithin (fun y => c y • f y) s x = c x • derivWithin f s x + derivWithin c s x • f x := (hc.hasDerivWithinAt.smul hf.hasDerivWithinAt).derivWithin hxs theorem deriv_smul (hc : DifferentiableAt 𝕜 c x) (hf : DifferentiableAt 𝕜 f x) : deriv (fun y => c y • f y) x = c x • deriv f x + deriv c x • f x := (hc.hasDerivAt.smul hf.hasDerivAt).deriv theorem HasStrictDerivAt.smul_const (hc : HasStrictDerivAt c c' x) (f : F) : HasStrictDerivAt (fun y => c y • f) (c' • f) x := by have := hc.smul (hasStrictDerivAt_const x f) rwa [smul_zero, zero_add] at this theorem HasDerivWithinAt.smul_const (hc : HasDerivWithinAt c c' s x) (f : F) : HasDerivWithinAt (fun y => c y • f) (c' • f) s x := by have := hc.smul (hasDerivWithinAt_const x s f) rwa [smul_zero, zero_add] at this theorem HasDerivAt.smul_const (hc : HasDerivAt c c' x) (f : F) : HasDerivAt (fun y => c y • f) (c' • f) x := by rw [← hasDerivWithinAt_univ] at * exact hc.smul_const f theorem derivWithin_smul_const (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (f : F) : derivWithin (fun y => c y • f) s x = derivWithin c s x • f := (hc.hasDerivWithinAt.smul_const f).derivWithin hxs theorem deriv_smul_const (hc : DifferentiableAt 𝕜 c x) (f : F) : deriv (fun y => c y • f) x = deriv c x • f := (hc.hasDerivAt.smul_const f).deriv end SMul section ConstSMul variable {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] nonrec theorem HasStrictDerivAt.const_smul (c : R) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun y => c • f y) (c • f') x := by simpa using (hf.const_smul c).hasStrictDerivAt nonrec theorem HasDerivAtFilter.const_smul (c : R) (hf : HasDerivAtFilter f f' x L) : HasDerivAtFilter (fun y => c • f y) (c • f') x L := by simpa using (hf.const_smul c).hasDerivAtFilter nonrec theorem HasDerivWithinAt.const_smul (c : R) (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun y => c • f y) (c • f') s x := hf.const_smul c nonrec theorem HasDerivAt.const_smul (c : R) (hf : HasDerivAt f f' x) : HasDerivAt (fun y => c • f y) (c • f') x := hf.const_smul c theorem derivWithin_const_smul (hxs : UniqueDiffWithinAt 𝕜 s x) (c : R) (hf : DifferentiableWithinAt 𝕜 f s x) : derivWithin (fun y => c • f y) s x = c • derivWithin f s x := (hf.hasDerivWithinAt.const_smul c).derivWithin hxs theorem deriv_const_smul (c : R) (hf : DifferentiableAt 𝕜 f x) : deriv (fun y => c • f y) x = c • deriv f x := (hf.hasDerivAt.const_smul c).deriv /-- A variant of `deriv_const_smul` without differentiability assumption when the scalar multiplication is by field elements. -/ lemma deriv_const_smul' {f : 𝕜 → F} {x : 𝕜} {R : Type*} [Field R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] (c : R) : deriv (fun y ↩ c • f y) x = c • deriv f x := by by_cases hf : DifferentiableAt 𝕜 f x · exact deriv_const_smul c hf · rcases eq_or_ne c 0 with rfl | hc · simp only [zero_smul, deriv_const'] · have H : ¬DifferentiableAt 𝕜 (fun y ↩ c • f y) x := by contrapose! hf change DifferentiableAt 𝕜 (fun y ↩ f y) x conv => enter [2, y]; rw [← inv_smul_smul₀ hc (f y)] exact DifferentiableAt.const_smul hf c⁻¹ rw [deriv_zero_of_not_differentiableAt hf, deriv_zero_of_not_differentiableAt H, smul_zero] end ConstSMul section Mul /-! ### Derivative of the multiplication of two functions -/ variable {𝕜' 𝔞 : Type*} [NormedField 𝕜'] [NormedRing 𝔞] [NormedAlgebra 𝕜 𝕜'] [NormedAlgebra 𝕜 𝔞] {c d : 𝕜 → 𝔞} {c' d' : 𝔞} {u v : 𝕜 → 𝕜'} theorem HasDerivWithinAt.mul (hc : HasDerivWithinAt c c' s x) (hd : HasDerivWithinAt d d' s x) : HasDerivWithinAt (fun y => c y * d y) (c' * d x + c x * d') s x := by have := (HasFDerivWithinAt.mul' hc hd).hasDerivWithinAt rwa [ContinuousLinearMap.add_apply, ContinuousLinearMap.smul_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, one_smul, one_smul, add_comm] at this theorem HasDerivAt.mul (hc : HasDerivAt c c' x) (hd : HasDerivAt d d' x) : HasDerivAt (fun y => c y * d y) (c' * d x + c x * d') x := by rw [← hasDerivWithinAt_univ] at * exact hc.mul hd theorem HasStrictDerivAt.mul (hc : HasStrictDerivAt c c' x) (hd : HasStrictDerivAt d d' x) : HasStrictDerivAt (fun y => c y * d y) (c' * d x + c x * d') x := by have := (HasStrictFDerivAt.mul' hc hd).hasStrictDerivAt rwa [ContinuousLinearMap.add_apply, ContinuousLinearMap.smul_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, one_smul, one_smul, add_comm] at this theorem derivWithin_mul (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : derivWithin (fun y => c y * d y) s x = derivWithin c s x * d x + c x * derivWithin d s x := (hc.hasDerivWithinAt.mul hd.hasDerivWithinAt).derivWithin hxs @[simp] theorem deriv_mul (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : deriv (fun y => c y * d y) x = deriv c x * d x + c x * deriv d x := (hc.hasDerivAt.mul hd.hasDerivAt).deriv theorem HasDerivWithinAt.mul_const (hc : HasDerivWithinAt c c' s x) (d : 𝔞) : HasDerivWithinAt (fun y => c y * d) (c' * d) s x := by convert hc.mul (hasDerivWithinAt_const x s d) using 1 rw [mul_zero, add_zero] theorem HasDerivAt.mul_const (hc : HasDerivAt c c' x) (d : 𝔞) : HasDerivAt (fun y => c y * d) (c' * d) x := by rw [← hasDerivWithinAt_univ] at * exact hc.mul_const d theorem hasDerivAt_mul_const (c : 𝕜) : HasDerivAt (fun x => x * c) c x := by simpa only [one_mul] using (hasDerivAt_id' x).mul_const c theorem HasStrictDerivAt.mul_const (hc : HasStrictDerivAt c c' x) (d : 𝔞) : HasStrictDerivAt (fun y => c y * d) (c' * d) x := by convert hc.mul (hasStrictDerivAt_const x d) using 1 rw [mul_zero, add_zero] theorem derivWithin_mul_const (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (d : 𝔞) : derivWithin (fun y => c y * d) s x = derivWithin c s x * d := (hc.hasDerivWithinAt.mul_const d).derivWithin hxs theorem deriv_mul_const (hc : DifferentiableAt 𝕜 c x) (d : 𝔞) : deriv (fun y => c y * d) x = deriv c x * d := (hc.hasDerivAt.mul_const d).deriv theorem deriv_mul_const_field (v : 𝕜') : deriv (fun y => u y * v) x = deriv u x * v := by by_cases hu : DifferentiableAt 𝕜 u x · exact deriv_mul_const hu v · rw [deriv_zero_of_not_differentiableAt hu, zero_mul] rcases eq_or_ne v 0 with (rfl | hd) · simp only [mul_zero, deriv_const] · refine deriv_zero_of_not_differentiableAt (mt (fun H => ?_) hu) simpa only [mul_inv_cancel_right₀ hd] using H.mul_const v⁻¹ @[simp] theorem deriv_mul_const_field' (v : 𝕜') : (deriv fun x => u x * v) = fun x => deriv u x * v := funext fun _ => deriv_mul_const_field v theorem HasDerivWithinAt.const_mul (c : 𝔞) (hd : HasDerivWithinAt d d' s x) : HasDerivWithinAt (fun y => c * d y) (c * d') s x := by convert (hasDerivWithinAt_const x s c).mul hd using 1 rw [zero_mul, zero_add] theorem HasDerivAt.const_mul (c : 𝔞) (hd : HasDerivAt d d' x) : HasDerivAt (fun y => c * d y) (c * d') x := by rw [← hasDerivWithinAt_univ] at * exact hd.const_mul c theorem HasStrictDerivAt.const_mul (c : 𝔞) (hd : HasStrictDerivAt d d' x) : HasStrictDerivAt (fun y => c * d y) (c * d') x := by convert (hasStrictDerivAt_const _ _).mul hd using 1 rw [zero_mul, zero_add] theorem derivWithin_const_mul (hxs : UniqueDiffWithinAt 𝕜 s x) (c : 𝔞) (hd : DifferentiableWithinAt 𝕜 d s x) : derivWithin (fun y => c * d y) s x = c * derivWithin d s x := (hd.hasDerivWithinAt.const_mul c).derivWithin hxs theorem deriv_const_mul (c : 𝔞) (hd : DifferentiableAt 𝕜 d x) : deriv (fun y => c * d y) x = c * deriv d x := (hd.hasDerivAt.const_mul c).deriv theorem deriv_const_mul_field (u : 𝕜') : deriv (fun y => u * v y) x = u * deriv v x := by simp only [mul_comm u, deriv_mul_const_field] @[simp] theorem deriv_const_mul_field' (u : 𝕜') : (deriv fun x => u * v x) = fun x => u * deriv v x := funext fun _ => deriv_const_mul_field u end Mul section Prod section HasDeriv variable {ι : Type*} [DecidableEq ι] {𝔞' : Type*} [NormedCommRing 𝔞'] [NormedAlgebra 𝕜 𝔞'] {u : Finset ι} {f : ι → 𝕜 → 𝔞'} {f' : ι → 𝔞'} theorem HasDerivAt.finset_prod (hf : ∀ i ∈ u, HasDerivAt (f i) (f' i) x) : HasDerivAt (∏ i ∈ u, f i ·) (∑ i ∈ u, (∏ j ∈ u.erase i, f j x) • f' i) x := by simpa [ContinuousLinearMap.sum_apply, ContinuousLinearMap.smul_apply] using (HasFDerivAt.finset_prod (fun i hi ↩ (hf i hi).hasFDerivAt)).hasDerivAt theorem HasDerivWithinAt.finset_prod (hf : ∀ i ∈ u, HasDerivWithinAt (f i) (f' i) s x) : HasDerivWithinAt (∏ i ∈ u, f i ·) (∑ i ∈ u, (∏ j ∈ u.erase i, f j x) • f' i) s x := by simpa [ContinuousLinearMap.sum_apply, ContinuousLinearMap.smul_apply] using (HasFDerivWithinAt.finset_prod (fun i hi ↩ (hf i hi).hasFDerivWithinAt)).hasDerivWithinAt theorem HasStrictDerivAt.finset_prod (hf : ∀ i ∈ u, HasStrictDerivAt (f i) (f' i) x) : HasStrictDerivAt (∏ i ∈ u, f i ·) (∑ i ∈ u, (∏ j ∈ u.erase i, f j x) • f' i) x := by simpa [ContinuousLinearMap.sum_apply, ContinuousLinearMap.smul_apply] using (HasStrictFDerivAt.finset_prod (fun i hi ↩ (hf i hi).hasStrictFDerivAt)).hasStrictDerivAt theorem deriv_finset_prod (hf : ∀ i ∈ u, DifferentiableAt 𝕜 (f i) x) : deriv (∏ i ∈ u, f i ·) x = ∑ i ∈ u, (∏ j ∈ u.erase i, f j x) • deriv (f i) x := (HasDerivAt.finset_prod fun i hi ↩ (hf i hi).hasDerivAt).deriv theorem derivWithin_finset_prod (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (f i) s x) : derivWithin (∏ i ∈ u, f i ·) s x = ∑ i ∈ u, (∏ j ∈ u.erase i, f j x) • derivWithin (f i) s x := (HasDerivWithinAt.finset_prod fun i hi ↩ (hf i hi).hasDerivWithinAt).derivWithin hxs end HasDeriv variable {ι : Type*} {𝔞' : Type*} [NormedCommRing 𝔞'] [NormedAlgebra 𝕜 𝔞'] {u : Finset ι} {f : ι → 𝕜 → 𝔞'} {f' : ι → 𝔞'} theorem DifferentiableAt.finset_prod (hd : ∀ i ∈ u, DifferentiableAt 𝕜 (f i) x) : DifferentiableAt 𝕜 (∏ i ∈ u, f i ·) x := by classical exact (HasDerivAt.finset_prod (fun i hi ↩ DifferentiableAt.hasDerivAt (hd i hi))).differentiableAt theorem DifferentiableWithinAt.finset_prod (hd : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (f i) s x) : DifferentiableWithinAt 𝕜 (∏ i ∈ u, f i ·) s x := by classical exact (HasDerivWithinAt.finset_prod (fun i hi ↩ DifferentiableWithinAt.hasDerivWithinAt (hd i hi))).differentiableWithinAt theorem DifferentiableOn.finset_prod (hd : ∀ i ∈ u, DifferentiableOn 𝕜 (f i) s) : DifferentiableOn 𝕜 (∏ i ∈ u, f i ·) s := fun x hx ↩ .finset_prod (fun i hi ↩ hd i hi x hx) theorem Differentiable.finset_prod (hd : ∀ i ∈ u, Differentiable 𝕜 (f i)) : Differentiable 𝕜 (∏ i ∈ u, f i ·) := fun x ↩ .finset_prod (fun i hi ↩ hd i hi x) end Prod section Div variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] {c d : 𝕜 → 𝕜'} {c' d' : 𝕜'} theorem HasDerivAt.div_const (hc : HasDerivAt c c' x) (d : 𝕜') : HasDerivAt (fun x => c x / d) (c' / d) x := by simpa only [div_eq_mul_inv] using hc.mul_const d⁻¹ theorem HasDerivWithinAt.div_const (hc : HasDerivWithinAt c c' s x) (d : 𝕜') : HasDerivWithinAt (fun x => c x / d) (c' / d) s x := by simpa only [div_eq_mul_inv] using hc.mul_const d⁻¹ theorem HasStrictDerivAt.div_const (hc : HasStrictDerivAt c c' x) (d : 𝕜') : HasStrictDerivAt (fun x => c x / d) (c' / d) x := by simpa only [div_eq_mul_inv] using hc.mul_const d⁻¹ theorem DifferentiableWithinAt.div_const (hc : DifferentiableWithinAt 𝕜 c s x) (d : 𝕜') : DifferentiableWithinAt 𝕜 (fun x => c x / d) s x := (hc.hasDerivWithinAt.div_const _).differentiableWithinAt @[simp] theorem DifferentiableAt.div_const (hc : DifferentiableAt 𝕜 c x) (d : 𝕜') : DifferentiableAt 𝕜 (fun x => c x / d) x := (hc.hasDerivAt.div_const _).differentiableAt theorem DifferentiableOn.div_const (hc : DifferentiableOn 𝕜 c s) (d : 𝕜') : DifferentiableOn 𝕜 (fun x => c x / d) s := fun x hx => (hc x hx).div_const d @[simp] theorem Differentiable.div_const (hc : Differentiable 𝕜 c) (d : 𝕜') : Differentiable 𝕜 fun x => c x / d := fun x => (hc x).div_const d theorem derivWithin_div_const (hc : DifferentiableWithinAt 𝕜 c s x) (d : 𝕜') (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x => c x / d) s x = derivWithin c s x / d := by simp [div_eq_inv_mul, derivWithin_const_mul, hc, hxs] @[simp] theorem deriv_div_const (d : 𝕜') : deriv (fun x => c x / d) x = deriv c x / d := by simp only [div_eq_mul_inv, deriv_mul_const_field] end Div section CLMCompApply /-! ### Derivative of the pointwise composition/application of continuous linear maps -/ open ContinuousLinearMap variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {c : 𝕜 → F →L[𝕜] G} {c' : F →L[𝕜] G} {d : 𝕜 → E →L[𝕜] F} {d' : E →L[𝕜] F} {u : 𝕜 → F} {u' : F} theorem HasStrictDerivAt.clm_comp (hc : HasStrictDerivAt c c' x) (hd : HasStrictDerivAt d d' x) : HasStrictDerivAt (fun y => (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') x := by have := (hc.hasStrictFDerivAt.clm_comp hd.hasStrictFDerivAt).hasStrictDerivAt rwa [add_apply, comp_apply, comp_apply, smulRight_apply, smulRight_apply, one_apply, one_smul, one_smul, add_comm] at this theorem HasDerivWithinAt.clm_comp (hc : HasDerivWithinAt c c' s x) (hd : HasDerivWithinAt d d' s x) : HasDerivWithinAt (fun y => (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') s x := by have := (hc.hasFDerivWithinAt.clm_comp hd.hasFDerivWithinAt).hasDerivWithinAt rwa [add_apply, comp_apply, comp_apply, smulRight_apply, smulRight_apply, one_apply, one_smul, one_smul, add_comm] at this theorem HasDerivAt.clm_comp (hc : HasDerivAt c c' x) (hd : HasDerivAt d d' x) : HasDerivAt (fun y => (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') x := by rw [← hasDerivWithinAt_univ] at * exact hc.clm_comp hd theorem derivWithin_clm_comp (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun y => (c y).comp (d y)) s x = (derivWithin c s x).comp (d x) + (c x).comp (derivWithin d s x) := (hc.hasDerivWithinAt.clm_comp hd.hasDerivWithinAt).derivWithin hxs theorem deriv_clm_comp (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : deriv (fun y => (c y).comp (d y)) x = (deriv c x).comp (d x) + (c x).comp (deriv d x) := (hc.hasDerivAt.clm_comp hd.hasDerivAt).deriv theorem HasStrictDerivAt.clm_apply (hc : HasStrictDerivAt c c' x) (hu : HasStrictDerivAt u u' x) : HasStrictDerivAt (fun y => (c y) (u y)) (c' (u x) + c x u') x := by have := (hc.hasStrictFDerivAt.clm_apply hu.hasStrictFDerivAt).hasStrictDerivAt rwa [add_apply, comp_apply, flip_apply, smulRight_apply, smulRight_apply, one_apply, one_smul, one_smul, add_comm] at this theorem HasDerivWithinAt.clm_apply (hc : HasDerivWithinAt c c' s x) (hu : HasDerivWithinAt u u' s x) : HasDerivWithinAt (fun y => (c y) (u y)) (c' (u x) + c x u') s x := by have := (hc.hasFDerivWithinAt.clm_apply hu.hasFDerivWithinAt).hasDerivWithinAt rwa [add_apply, comp_apply, flip_apply, smulRight_apply, smulRight_apply, one_apply, one_smul, one_smul, add_comm] at this theorem HasDerivAt.clm_apply (hc : HasDerivAt c c' x) (hu : HasDerivAt u u' x) : HasDerivAt (fun y => (c y) (u y)) (c' (u x) + c x u') x := by have := (hc.hasFDerivAt.clm_apply hu.hasFDerivAt).hasDerivAt rwa [add_apply, comp_apply, flip_apply, smulRight_apply, smulRight_apply, one_apply, one_smul, one_smul, add_comm] at this theorem derivWithin_clm_apply (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hu : DifferentiableWithinAt 𝕜 u s x) : derivWithin (fun y => (c y) (u y)) s x = derivWithin c s x (u x) + c x (derivWithin u s x) := (hc.hasDerivWithinAt.clm_apply hu.hasDerivWithinAt).derivWithin hxs theorem deriv_clm_apply (hc : DifferentiableAt 𝕜 c x) (hu : DifferentiableAt 𝕜 u x) : deriv (fun y => (c y) (u y)) x = deriv c x (u x) + c x (deriv u x) := (hc.hasDerivAt.clm_apply hu.hasDerivAt).deriv end CLMCompApply
Analysis\Calculus\Deriv\Pi.lean
/- Copyright (c) 2023 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Heather Macbeth -/ import Mathlib.Analysis.Calculus.FDeriv.Pi import Mathlib.Analysis.Calculus.Deriv.Basic /-! # One-dimensional derivatives on pi-types. -/ variable {𝕜 ι : Type*} [DecidableEq ι] [Fintype ι] [NontriviallyNormedField 𝕜] theorem hasDerivAt_update (x : ι → 𝕜) (i : ι) (y : 𝕜) : HasDerivAt (Function.update x i) (Pi.single i (1 : 𝕜)) y := by convert (hasFDerivAt_update x y).hasDerivAt ext z j rw [Pi.single, Function.update_apply] split_ifs with h · simp [h] · simp [Pi.single_eq_of_ne h] theorem hasDerivAt_single (i : ι) (y : 𝕜) : HasDerivAt (Pi.single (f := fun _ ↩ 𝕜) i) (Pi.single i (1 : 𝕜)) y := hasDerivAt_update 0 i y theorem deriv_update (x : ι → 𝕜) (i : ι) (y : 𝕜) : deriv (Function.update x i) y = Pi.single i (1 : 𝕜) := (hasDerivAt_update x i y).deriv theorem deriv_single (i : ι) (y : 𝕜) : deriv (Pi.single (f := fun _ ↩ 𝕜) i) y = Pi.single i (1 : 𝕜) := deriv_update 0 i y
Analysis\Calculus\Deriv\Polynomial.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Eric Wieser -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Analysis.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.Deriv.Add /-! # Derivatives of polynomials In this file we prove that derivatives of polynomials in the analysis sense agree with their derivatives in the algebraic sense. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## TODO * Add results about multivariable polynomials. * Generalize some (most?) results to an algebra over the base field. ## Keywords derivative, polynomial -/ universe u v w open scoped Topology Filter ENNReal Polynomial open Set open ContinuousLinearMap (smulRight smulRight_one_eq_iff) variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L L₁ L₂ : Filter 𝕜} namespace Polynomial /-! ### Derivative of a polynomial -/ variable {R : Type*} [CommSemiring R] [Algebra R 𝕜] variable (p : 𝕜[X]) (q : R[X]) /-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/ protected theorem hasStrictDerivAt (x : 𝕜) : HasStrictDerivAt (fun x => p.eval x) (p.derivative.eval x) x := by induction p using Polynomial.induction_on' with | h_add p q hp hq => simpa using hp.add hq | h_monomial n a => simpa [mul_assoc] using (hasStrictDerivAt_pow n x).const_mul a protected theorem hasStrictDerivAt_aeval (x : 𝕜) : HasStrictDerivAt (fun x => aeval x q) (aeval x (derivative q)) x := by simpa only [aeval_def, eval₂_eq_eval_map, derivative_map] using (q.map (algebraMap R 𝕜)).hasStrictDerivAt x /-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/ protected theorem hasDerivAt (x : 𝕜) : HasDerivAt (fun x => p.eval x) (p.derivative.eval x) x := (p.hasStrictDerivAt x).hasDerivAt protected theorem hasDerivAt_aeval (x : 𝕜) : HasDerivAt (fun x => aeval x q) (aeval x (derivative q)) x := (q.hasStrictDerivAt_aeval x).hasDerivAt protected theorem hasDerivWithinAt (x : 𝕜) (s : Set 𝕜) : HasDerivWithinAt (fun x => p.eval x) (p.derivative.eval x) s x := (p.hasDerivAt x).hasDerivWithinAt protected theorem hasDerivWithinAt_aeval (x : 𝕜) (s : Set 𝕜) : HasDerivWithinAt (fun x => aeval x q) (aeval x (derivative q)) s x := (q.hasDerivAt_aeval x).hasDerivWithinAt protected theorem differentiableAt : DifferentiableAt 𝕜 (fun x => p.eval x) x := (p.hasDerivAt x).differentiableAt protected theorem differentiableAt_aeval : DifferentiableAt 𝕜 (fun x => aeval x q) x := (q.hasDerivAt_aeval x).differentiableAt protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 (fun x => p.eval x) s x := p.differentiableAt.differentiableWithinAt protected theorem differentiableWithinAt_aeval : DifferentiableWithinAt 𝕜 (fun x => aeval x q) s x := q.differentiableAt_aeval.differentiableWithinAt protected theorem differentiable : Differentiable 𝕜 fun x => p.eval x := fun _ => p.differentiableAt protected theorem differentiable_aeval : Differentiable 𝕜 fun x : 𝕜 => aeval x q := fun _ => q.differentiableAt_aeval protected theorem differentiableOn : DifferentiableOn 𝕜 (fun x => p.eval x) s := p.differentiable.differentiableOn protected theorem differentiableOn_aeval : DifferentiableOn 𝕜 (fun x => aeval x q) s := q.differentiable_aeval.differentiableOn @[simp] protected theorem deriv : deriv (fun x => p.eval x) x = p.derivative.eval x := (p.hasDerivAt x).deriv @[simp] protected theorem deriv_aeval : deriv (fun x => aeval x q) x = aeval x (derivative q) := (q.hasDerivAt_aeval x).deriv protected theorem derivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x => p.eval x) s x = p.derivative.eval x := by rw [DifferentiableAt.derivWithin p.differentiableAt hxs] exact p.deriv protected theorem derivWithin_aeval (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x => aeval x q) s x = aeval x (derivative q) := by simpa only [aeval_def, eval₂_eq_eval_map, derivative_map] using (q.map (algebraMap R 𝕜)).derivWithin hxs protected theorem hasFDerivAt (x : 𝕜) : HasFDerivAt (fun x => p.eval x) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x)) x := p.hasDerivAt x protected theorem hasFDerivAt_aeval (x : 𝕜) : HasFDerivAt (fun x => aeval x q) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (aeval x (derivative q))) x := q.hasDerivAt_aeval x protected theorem hasFDerivWithinAt (x : 𝕜) : HasFDerivWithinAt (fun x => p.eval x) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x)) s x := (p.hasFDerivAt x).hasFDerivWithinAt protected theorem hasFDerivWithinAt_aeval (x : 𝕜) : HasFDerivWithinAt (fun x => aeval x q) (smulRight (1 : 𝕜 →L[𝕜] 𝕜) (aeval x (derivative q))) s x := (q.hasFDerivAt_aeval x).hasFDerivWithinAt @[simp] protected theorem fderiv : fderiv 𝕜 (fun x => p.eval x) x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x) := (p.hasFDerivAt x).fderiv @[simp] protected theorem fderiv_aeval : fderiv 𝕜 (fun x => aeval x q) x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (aeval x (derivative q)) := (q.hasFDerivAt_aeval x).fderiv protected theorem fderivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x => p.eval x) s x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (p.derivative.eval x) := (p.hasFDerivWithinAt x).fderivWithin hxs protected theorem fderivWithin_aeval (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x => aeval x q) s x = smulRight (1 : 𝕜 →L[𝕜] 𝕜) (aeval x (derivative q)) := (q.hasFDerivWithinAt_aeval x).fderivWithin hxs end Polynomial
Analysis\Calculus\Deriv\Pow.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp /-! # Derivative of `(f x) ^ n`, `n : ℕ` In this file we prove that `(x ^ n)' = n * x ^ (n - 1)`, where `n` is a natural number. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative, power -/ universe u v w open scoped Classical open Topology Filter ENNReal open Filter Asymptotics Set variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L L₁ L₂ : Filter 𝕜} /-! ### Derivative of `x ↩ x^n` for `n : ℕ` -/ variable {c : 𝕜 → 𝕜} {c' : 𝕜} variable (n : ℕ) theorem hasStrictDerivAt_pow : ∀ (n : ℕ) (x : 𝕜), HasStrictDerivAt (fun x : 𝕜 ↩ x ^ n) ((n : 𝕜) * x ^ (n - 1)) x | 0, x => by simp [hasStrictDerivAt_const] | 1, x => by simpa using hasStrictDerivAt_id x | n + 1 + 1, x => by simpa [pow_succ, add_mul, mul_assoc] using (hasStrictDerivAt_pow (n + 1) x).mul (hasStrictDerivAt_id x) theorem hasDerivAt_pow (n : ℕ) (x : 𝕜) : HasDerivAt (fun x : 𝕜 => x ^ n) ((n : 𝕜) * x ^ (n - 1)) x := (hasStrictDerivAt_pow n x).hasDerivAt theorem hasDerivWithinAt_pow (n : ℕ) (x : 𝕜) (s : Set 𝕜) : HasDerivWithinAt (fun x : 𝕜 => x ^ n) ((n : 𝕜) * x ^ (n - 1)) s x := (hasDerivAt_pow n x).hasDerivWithinAt theorem differentiableAt_pow : DifferentiableAt 𝕜 (fun x : 𝕜 => x ^ n) x := (hasDerivAt_pow n x).differentiableAt theorem differentiableWithinAt_pow : DifferentiableWithinAt 𝕜 (fun x : 𝕜 => x ^ n) s x := (differentiableAt_pow n).differentiableWithinAt theorem differentiable_pow : Differentiable 𝕜 fun x : 𝕜 => x ^ n := fun _ => differentiableAt_pow n theorem differentiableOn_pow : DifferentiableOn 𝕜 (fun x : 𝕜 => x ^ n) s := (differentiable_pow n).differentiableOn theorem deriv_pow : deriv (fun x : 𝕜 => x ^ n) x = (n : 𝕜) * x ^ (n - 1) := (hasDerivAt_pow n x).deriv @[simp] theorem deriv_pow' : (deriv fun x : 𝕜 => x ^ n) = fun x => (n : 𝕜) * x ^ (n - 1) := funext fun _ => deriv_pow n theorem derivWithin_pow (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x : 𝕜 => x ^ n) s x = (n : 𝕜) * x ^ (n - 1) := (hasDerivWithinAt_pow n x s).derivWithin hxs theorem HasDerivWithinAt.pow (hc : HasDerivWithinAt c c' s x) : HasDerivWithinAt (fun y => c y ^ n) ((n : 𝕜) * c x ^ (n - 1) * c') s x := (hasDerivAt_pow n (c x)).comp_hasDerivWithinAt x hc theorem HasDerivAt.pow (hc : HasDerivAt c c' x) : HasDerivAt (fun y => c y ^ n) ((n : 𝕜) * c x ^ (n - 1) * c') x := by rw [← hasDerivWithinAt_univ] at * exact hc.pow n theorem derivWithin_pow' (hc : DifferentiableWithinAt 𝕜 c s x) (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun x => c x ^ n) s x = (n : 𝕜) * c x ^ (n - 1) * derivWithin c s x := (hc.hasDerivWithinAt.pow n).derivWithin hxs @[simp] theorem deriv_pow'' (hc : DifferentiableAt 𝕜 c x) : deriv (fun x => c x ^ n) x = (n : 𝕜) * c x ^ (n - 1) * deriv c x := (hc.hasDerivAt.pow n).deriv
Analysis\Calculus\Deriv\Prod.lean
/- Copyright (c) 2019 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Prod /-! # Derivatives of functions taking values in product types In this file we prove lemmas about derivatives of functions `f : 𝕜 → E × F` and of functions `f : 𝕜 → (Π i, E i)`. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## Keywords derivative -/ universe u v w open scoped Classical open Topology Filter open Filter Asymptotics Set variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L L₁ L₂ : Filter 𝕜} section CartesianProduct /-! ### Derivative of the cartesian product of two functions -/ variable {G : Type w} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {f₂ : 𝕜 → G} {f₂' : G} nonrec theorem HasDerivAtFilter.prod (hf₁ : HasDerivAtFilter f₁ f₁' x L) (hf₂ : HasDerivAtFilter f₂ f₂' x L) : HasDerivAtFilter (fun x => (f₁ x, f₂ x)) (f₁', f₂') x L := hf₁.prod hf₂ nonrec theorem HasDerivWithinAt.prod (hf₁ : HasDerivWithinAt f₁ f₁' s x) (hf₂ : HasDerivWithinAt f₂ f₂' s x) : HasDerivWithinAt (fun x => (f₁ x, f₂ x)) (f₁', f₂') s x := hf₁.prod hf₂ nonrec theorem HasDerivAt.prod (hf₁ : HasDerivAt f₁ f₁' x) (hf₂ : HasDerivAt f₂ f₂' x) : HasDerivAt (fun x => (f₁ x, f₂ x)) (f₁', f₂') x := hf₁.prod hf₂ nonrec theorem HasStrictDerivAt.prod (hf₁ : HasStrictDerivAt f₁ f₁' x) (hf₂ : HasStrictDerivAt f₂ f₂' x) : HasStrictDerivAt (fun x => (f₁ x, f₂ x)) (f₁', f₂') x := hf₁.prod hf₂ end CartesianProduct section Pi /-! ### Derivatives of functions `f : 𝕜 → Π i, E i` -/ variable {ι : Type*} [Fintype ι] {E' : ι → Type*} [∀ i, NormedAddCommGroup (E' i)] [∀ i, NormedSpace 𝕜 (E' i)] {φ : 𝕜 → ∀ i, E' i} {φ' : ∀ i, E' i} @[simp] theorem hasStrictDerivAt_pi : HasStrictDerivAt φ φ' x ↔ ∀ i, HasStrictDerivAt (fun x => φ x i) (φ' i) x := hasStrictFDerivAt_pi' @[simp] theorem hasDerivAtFilter_pi : HasDerivAtFilter φ φ' x L ↔ ∀ i, HasDerivAtFilter (fun x => φ x i) (φ' i) x L := hasFDerivAtFilter_pi' theorem hasDerivAt_pi : HasDerivAt φ φ' x ↔ ∀ i, HasDerivAt (fun x => φ x i) (φ' i) x := hasDerivAtFilter_pi theorem hasDerivWithinAt_pi : HasDerivWithinAt φ φ' s x ↔ ∀ i, HasDerivWithinAt (fun x => φ x i) (φ' i) s x := hasDerivAtFilter_pi theorem derivWithin_pi (h : ∀ i, DifferentiableWithinAt 𝕜 (fun x => φ x i) s x) (hs : UniqueDiffWithinAt 𝕜 s x) : derivWithin φ s x = fun i => derivWithin (fun x => φ x i) s x := (hasDerivWithinAt_pi.2 fun i => (h i).hasDerivWithinAt).derivWithin hs theorem deriv_pi (h : ∀ i, DifferentiableAt 𝕜 (fun x => φ x i) x) : deriv φ x = fun i => deriv (fun x => φ x i) x := (hasDerivAt_pi.2 fun i => (h i).hasDerivAt).deriv end Pi
Analysis\Calculus\Deriv\Shift.lean
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Comp /-! ### Invariance of the derivative under translation We show that if a function `h` has derivative `h'` at a point `a + x`, then `h (a + ·)` has derivative `h'` at `x`. Similarly for `x + a`. -/ /-- Translation in the domain does not change the derivative. -/ lemma HasDerivAt.comp_const_add {𝕜 : Type*} [NontriviallyNormedField 𝕜] (a x : 𝕜) {𝕜' : Type*} [NormedAddCommGroup 𝕜'] [NormedSpace 𝕜 𝕜'] {h : 𝕜 → 𝕜'} {h' : 𝕜'} (hh : HasDerivAt h h' (a + x)) : HasDerivAt (fun x ↩ h (a + x)) h' x := by simpa [Function.comp_def] using HasDerivAt.scomp (𝕜 := 𝕜) x hh <| hasDerivAt_id' x |>.const_add a /-- Translation in the domain does not change the derivative. -/ lemma HasDerivAt.comp_add_const {𝕜 : Type*} [NontriviallyNormedField 𝕜] (x a : 𝕜) {𝕜' : Type*} [NormedAddCommGroup 𝕜'] [NormedSpace 𝕜 𝕜'] {h : 𝕜 → 𝕜'} {h' : 𝕜'} (hh : HasDerivAt h h' (x + a)) : HasDerivAt (fun x ↩ h (x + a)) h' x := by simpa [Function.comp_def] using HasDerivAt.scomp (𝕜 := 𝕜) x hh <| hasDerivAt_id' x |>.add_const a /-- The derivative of `x ↩ f (-x)` at `a` is the negative of the derivative of `f` at `-a`. -/ lemma deriv_comp_neg {𝕜 : Type*} [NontriviallyNormedField 𝕜] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] (f : 𝕜 → F) (a : 𝕜) : deriv (fun x ↩ f (-x)) a = -deriv f (-a) := by by_cases h : DifferentiableAt 𝕜 f (-a) · simpa only [deriv_neg, neg_one_smul] using deriv.scomp a h (differentiable_neg _) · rw [deriv_zero_of_not_differentiableAt (mt differentiableAt_comp_neg_iff.mpr h), deriv_zero_of_not_differentiableAt h, neg_zero] /-- Translation in the domain does not change the derivative. -/ lemma deriv_comp_const_add {𝕜 : Type*} [NontriviallyNormedField 𝕜] (a x : 𝕜) {𝕜' : Type*} [NormedAddCommGroup 𝕜'] [NormedSpace 𝕜 𝕜'] {h : 𝕜 → 𝕜'} (hh : DifferentiableAt 𝕜 h (a + x)) : deriv (fun x ↩ h (a + x)) x = deriv h (a + x) := HasDerivAt.deriv hh.hasDerivAt.comp_const_add /-- Translation in the domain does not change the derivative. -/ lemma deriv_comp_add_const {𝕜 : Type*} [NontriviallyNormedField 𝕜] (a x : 𝕜) {𝕜' : Type*} [NormedAddCommGroup 𝕜'] [NormedSpace 𝕜 𝕜'] {h : 𝕜 → 𝕜'} (hh : DifferentiableAt 𝕜 h (x + a)) : deriv (fun x ↩ h (x + a)) x = deriv h (x + a) := HasDerivAt.deriv hh.hasDerivAt.comp_add_const
Analysis\Calculus\Deriv\Slope.lean
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.LinearAlgebra.AffineSpace.Slope /-! # Derivative as the limit of the slope In this file we relate the derivative of a function with its definition from a standard undergraduate course as the limit of the slope `(f y - f x) / (y - x)` as `y` tends to `𝓝[≠] x`. Since we are talking about functions taking values in a normed space instead of the base field, we use `slope f x y = (y - x)⁻¹ • (f y - f x)` instead of division. We also prove some estimates on the upper/lower limits of the slope in terms of the derivative. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## Keywords derivative, slope -/ universe u v w noncomputable section open Topology Filter TopologicalSpace open Filter Set section NormedField variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L L₁ L₂ : Filter 𝕜} /-- 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`. -/ theorem hasDerivAtFilter_iff_tendsto_slope {x : 𝕜} {L : Filter 𝕜} : HasDerivAtFilter f f' x L ↔ Tendsto (slope f x) (L ⊓ 𝓟 {x}ᶜ) (𝓝 f') := calc HasDerivAtFilter f f' x L ↔ Tendsto (fun y ↩ slope f x y - (y - x)⁻¹ • (y - x) • f') L (𝓝 0) := by simp only [hasDerivAtFilter_iff_tendsto, ← norm_inv, ← norm_smul, ← tendsto_zero_iff_norm_tendsto_zero, slope_def_module, smul_sub] _ ↔ Tendsto (fun y ↩ slope f x y - (y - x)⁻¹ • (y - x) • f') (L ⊓ 𝓟 {x}ᶜ) (𝓝 0) := .symm <| tendsto_inf_principal_nhds_iff_of_forall_eq <| by simp _ ↔ Tendsto (fun y ↩ slope f x y - f') (L ⊓ 𝓟 {x}ᶜ) (𝓝 0) := tendsto_congr' <| by refine (EqOn.eventuallyEq fun y hy ↩ ?_).filter_mono inf_le_right rw [inv_smul_smul₀ (sub_ne_zero.2 hy) f'] _ ↔ Tendsto (slope f x) (L ⊓ 𝓟 {x}ᶜ) (𝓝 f') := by rw [← nhds_translation_sub f', tendsto_comap_iff]; rfl theorem hasDerivWithinAt_iff_tendsto_slope : HasDerivWithinAt f f' s x ↔ Tendsto (slope f x) (𝓝[s \ {x}] x) (𝓝 f') := by simp only [HasDerivWithinAt, nhdsWithin, diff_eq, ← inf_assoc, inf_principal.symm] exact hasDerivAtFilter_iff_tendsto_slope theorem hasDerivWithinAt_iff_tendsto_slope' (hs : x ∉ s) : HasDerivWithinAt f f' s x ↔ Tendsto (slope f x) (𝓝[s] x) (𝓝 f') := by rw [hasDerivWithinAt_iff_tendsto_slope, diff_singleton_eq_self hs] theorem hasDerivAt_iff_tendsto_slope : HasDerivAt f f' x ↔ Tendsto (slope f x) (𝓝[≠] x) (𝓝 f') := hasDerivAtFilter_iff_tendsto_slope theorem hasDerivAt_iff_tendsto_slope_zero : HasDerivAt f f' x ↔ Tendsto (fun t ↩ t⁻¹ • (f (x + t) - f x)) (𝓝[≠] 0) (𝓝 f') := by have : 𝓝[≠] x = Filter.map (fun t ↩ x + t) (𝓝[≠] 0) := by simp [nhdsWithin, map_add_left_nhds_zero x, Filter.map_inf, add_right_injective x] simp [hasDerivAt_iff_tendsto_slope, this, slope, Function.comp] alias ⟹HasDerivAt.tendsto_slope_zero, _⟩ := hasDerivAt_iff_tendsto_slope_zero theorem HasDerivAt.tendsto_slope_zero_right [PartialOrder 𝕜] (h : HasDerivAt f f' x) : Tendsto (fun t ↩ t⁻¹ • (f (x + t) - f x)) (𝓝[>] 0) (𝓝 f') := h.tendsto_slope_zero.mono_left (nhds_right'_le_nhds_ne 0) theorem HasDerivAt.tendsto_slope_zero_left [PartialOrder 𝕜] (h : HasDerivAt f f' x) : Tendsto (fun t ↩ t⁻¹ • (f (x + t) - f x)) (𝓝[<] 0) (𝓝 f') := h.tendsto_slope_zero.mono_left (nhds_left'_le_nhds_ne 0) /-- Given a set `t` such that `s ∩ t` is dense in `s`, then the range of `derivWithin f s` is contained in the closure of the submodule spanned by the image of `t`. -/ theorem range_derivWithin_subset_closure_span_image (f : 𝕜 → F) {s t : Set 𝕜} (h : s ⊆ closure (s ∩ t)) : range (derivWithin f s) ⊆ closure (Submodule.span 𝕜 (f '' t)) := by rintro - ⟹x, rfl⟩ rcases eq_or_neBot (𝓝[s \ {x}] x) with H|H · simpa [derivWithin, fderivWithin, H] using subset_closure (zero_mem _) by_cases H' : DifferentiableWithinAt 𝕜 f s x; swap · rw [derivWithin_zero_of_not_differentiableWithinAt H'] exact subset_closure (zero_mem _) have I : (𝓝[(s ∩ t) \ {x}] x).NeBot := by rw [← mem_closure_iff_nhdsWithin_neBot] at H ⊢ have A : closure (s \ {x}) ⊆ closure (closure (s ∩ t) \ {x}) := closure_mono (diff_subset_diff_left h) have B : closure (s ∩ t) \ {x} ⊆ closure ((s ∩ t) \ {x}) := by convert closure_diff; exact closure_singleton.symm simpa using A.trans (closure_mono B) H have : Tendsto (slope f x) (𝓝[(s ∩ t) \ {x}] x) (𝓝 (derivWithin f s x)) := by apply Tendsto.mono_left (hasDerivWithinAt_iff_tendsto_slope.1 H'.hasDerivWithinAt) rw [inter_comm, inter_diff_assoc] exact nhdsWithin_mono _ inter_subset_right rw [← closure_closure, ← Submodule.topologicalClosure_coe] apply mem_closure_of_tendsto this filter_upwards [self_mem_nhdsWithin] with y hy simp only [slope, vsub_eq_sub, SetLike.mem_coe] refine Submodule.smul_mem _ _ (Submodule.sub_mem _ ?_ ?_) · apply Submodule.le_topologicalClosure apply Submodule.subset_span exact mem_image_of_mem _ hy.1.2 · apply Submodule.closure_subset_topologicalClosure_span suffices A : f x ∈ closure (f '' (s ∩ t)) from closure_mono (image_subset _ inter_subset_right) A apply ContinuousWithinAt.mem_closure_image · apply H'.continuousWithinAt.mono inter_subset_left rw [mem_closure_iff_nhdsWithin_neBot] exact I.mono (nhdsWithin_mono _ diff_subset) /-- Given a dense set `t`, then the range of `deriv f` is contained in the closure of the submodule spanned by the image of `t`. -/ theorem range_deriv_subset_closure_span_image (f : 𝕜 → F) {t : Set 𝕜} (h : Dense t) : range (deriv f) ⊆ closure (Submodule.span 𝕜 (f '' t)) := by rw [← derivWithin_univ] apply range_derivWithin_subset_closure_span_image simp [dense_iff_closure_eq.1 h] theorem isSeparable_range_derivWithin [SeparableSpace 𝕜] (f : 𝕜 → F) (s : Set 𝕜) : IsSeparable (range (derivWithin f s)) := by obtain ⟹t, ts, t_count, ht⟩ : ∃ t, t ⊆ s ∧ Set.Countable t ∧ s ⊆ closure t := (IsSeparable.of_separableSpace s).exists_countable_dense_subset have : s ⊆ closure (s ∩ t) := by rwa [inter_eq_self_of_subset_right ts] apply IsSeparable.mono _ (range_derivWithin_subset_closure_span_image f this) exact (Countable.image t_count f).isSeparable.span.closure theorem isSeparable_range_deriv [SeparableSpace 𝕜] (f : 𝕜 → F) : IsSeparable (range (deriv f)) := by rw [← derivWithin_univ] exact isSeparable_range_derivWithin _ _ end NormedField /-! ### Upper estimates on liminf and limsup -/ section Real variable {f : ℝ → ℝ} {f' : ℝ} {s : Set ℝ} {x : ℝ} {r : ℝ} theorem HasDerivWithinAt.limsup_slope_le (hf : HasDerivWithinAt f f' s x) (hr : f' < r) : ∀ᶠ z in 𝓝[s \ {x}] x, slope f x z < r := hasDerivWithinAt_iff_tendsto_slope.1 hf (IsOpen.mem_nhds isOpen_Iio hr) theorem HasDerivWithinAt.limsup_slope_le' (hf : HasDerivWithinAt f f' s x) (hs : x ∉ s) (hr : f' < r) : ∀ᶠ z in 𝓝[s] x, slope f x z < r := (hasDerivWithinAt_iff_tendsto_slope' hs).1 hf (IsOpen.mem_nhds isOpen_Iio hr) theorem HasDerivWithinAt.liminf_right_slope_le (hf : HasDerivWithinAt 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 RealSpace open Metric variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℝ 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'‖`. -/ theorem HasDerivWithinAt.limsup_norm_slope_le (hf : HasDerivWithinAt f f' s x) (hr : ‖f'‖ < r) : ∀ᶠ z in 𝓝[s] x, ‖z - x‖⁻¹ * ‖f z - f x‖ < r := by have hr₀ : 0 < r := lt_of_le_of_lt (norm_nonneg f') hr have A : ∀ᶠ z in 𝓝[s \ {x}] x, ‖(z - x)⁻¹ • (f z - f x)‖ ∈ Iio r := (hasDerivWithinAt_iff_tendsto_slope.1 hf).norm (IsOpen.mem_nhds isOpen_Iio hr) have B : ∀ᶠ z in 𝓝[{x}] x, ‖(z - x)⁻¹ • (f z - f x)‖ ∈ Iio r := mem_of_superset self_mem_nhdsWithin (singleton_subset_iff.2 <| by simp [hr₀]) have C := mem_sup.2 ⟹A, B⟩ rw [← nhdsWithin_union, diff_union_self, nhdsWithin_union, mem_sup] at C filter_upwards [C.1] simp only [norm_smul, mem_Iio, norm_inv] exact fun _ => id /-- 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 `HasDerivWithinAt.limsup_norm_slope_le` where `‖f z‖ - ‖f x‖` is replaced by `‖f z - f x‖`. -/ theorem HasDerivWithinAt.limsup_slope_norm_le (hf : HasDerivWithinAt f f' s x) (hr : ‖f'‖ < r) : ∀ᶠ z in 𝓝[s] x, ‖z - x‖⁻¹ * (‖f z‖ - ‖f x‖) < r := by apply (hf.limsup_norm_slope_le hr).mono intro 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 _) /-- 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 `HasDerivWithinAt.limsup_norm_slope_le` for a stronger version using limit superior and any set `s`. -/ theorem HasDerivWithinAt.liminf_right_norm_slope_le (hf : HasDerivWithinAt 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 * `HasDerivWithinAt.limsup_norm_slope_le` for a stronger version using limit superior and any set `s`; * `HasDerivWithinAt.liminf_right_norm_slope_le` for a stronger version using `‖f z - f xp‖` instead of `‖f z‖ - ‖f x‖`. -/ theorem HasDerivWithinAt.liminf_right_slope_norm_le (hf : HasDerivWithinAt f f' (Ici x) x) (hr : ‖f'‖ < r) : ∃ᶠ z in 𝓝[>] x, (z - x)⁻¹ * (‖f z‖ - ‖f x‖) < r := by have := (hf.Ioi_of_Ici.limsup_slope_norm_le hr).frequently refine this.mp (Eventually.mono self_mem_nhdsWithin fun z hxz hz ↩ ?_) rwa [Real.norm_eq_abs, abs_of_pos (sub_pos_of_lt hxz)] at hz end RealSpace
Analysis\Calculus\Deriv\Star.lean
/- Copyright (c) 2023 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Star /-! # Star operations on derivatives This file contains the usual formulas (and existence assertions) for the derivative of the star operation. Note that these only apply when the field that the derivative is respect to has a trivial star operation; which as should be expected rules out `𝕜 = ℂ`. -/ universe u v w variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f : 𝕜 → F} /-! ### Derivative of `x ↩ star x` -/ variable [StarRing 𝕜] [TrivialStar 𝕜] [StarAddMonoid F] [ContinuousStar F] variable [StarModule 𝕜 F] {f' : F} {s : Set 𝕜} {x : 𝕜} {L : Filter 𝕜} protected nonrec theorem HasDerivAtFilter.star (h : HasDerivAtFilter f f' x L) : HasDerivAtFilter (fun x => star (f x)) (star f') x L := by simpa using h.star.hasDerivAtFilter protected nonrec theorem HasDerivWithinAt.star (h : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => star (f x)) (star f') s x := h.star protected nonrec theorem HasDerivAt.star (h : HasDerivAt f f' x) : HasDerivAt (fun x => star (f x)) (star f') x := h.star protected nonrec theorem HasStrictDerivAt.star (h : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => star (f x)) (star f') x := by simpa using h.star.hasStrictDerivAt protected theorem derivWithin.star (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun y => star (f y)) s x = star (derivWithin f s x) := DFunLike.congr_fun (fderivWithin_star hxs) _ protected theorem deriv.star : deriv (fun y => star (f y)) x = star (deriv f x) := DFunLike.congr_fun fderiv_star _ @[simp] protected theorem deriv.star' : (deriv fun y => star (f y)) = fun x => star (deriv f x) := funext fun _ => deriv.star
Analysis\Calculus\Deriv\Support.lean
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Analysis.Calculus.Deriv.Basic /-! # Support of the derivative of a function In this file we prove that the (topological) support of a function includes the support of its derivative. As a corollary, we show that the derivative of a function with compact support has compact support. ## Keywords derivative, support -/ universe u v variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {E : Type v} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f : 𝕜 → E} /-! ### Support of derivatives -/ section Support open Function theorem support_deriv_subset : support (deriv f) ⊆ tsupport f := by intro x rw [← not_imp_not] intro h2x rw [not_mem_tsupport_iff_eventuallyEq] at h2x exact nmem_support.mpr (h2x.deriv_eq.trans (deriv_const x 0)) protected theorem HasCompactSupport.deriv (hf : HasCompactSupport f) : HasCompactSupport (deriv f) := hf.mono' support_deriv_subset end Support
Analysis\Calculus\Deriv\ZPow.lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.Deriv.Inv /-! # Derivatives of `x ^ m`, `m : â„€` In this file we prove theorems about (iterated) derivatives of `x ^ m`, `m : â„€`. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## Keywords derivative, power -/ universe u v w open scoped Classical open Topology Filter open Filter Asymptotics Set variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {E : Type v} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {x : 𝕜} variable {s : Set 𝕜} variable {m : â„€} /-! ### Derivative of `x ↩ x^m` for `m : â„€` -/ theorem hasStrictDerivAt_zpow (m : â„€) (x : 𝕜) (h : x ≠ 0 √ 0 ≀ m) : HasStrictDerivAt (fun x => x ^ m) ((m : 𝕜) * x ^ (m - 1)) x := by have : ∀ m : â„€, 0 < m → HasStrictDerivAt (· ^ m) ((m : 𝕜) * x ^ (m - 1)) x := fun m hm ↩ by lift m to ℕ using hm.le simp only [zpow_natCast, Int.cast_natCast] convert hasStrictDerivAt_pow m x using 2 rw [← Int.ofNat_one, ← Int.ofNat_sub, zpow_natCast] norm_cast at hm rcases lt_trichotomy m 0 with (hm | hm | hm) · have hx : x ≠ 0 := h.resolve_right hm.not_le have := (hasStrictDerivAt_inv ?_).scomp _ (this (-m) (neg_pos.2 hm)) <;> [skip; exact zpow_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, hasStrictDerivAt_const] · exact this m hm theorem hasDerivAt_zpow (m : â„€) (x : 𝕜) (h : x ≠ 0 √ 0 ≀ m) : HasDerivAt (fun x => x ^ m) ((m : 𝕜) * x ^ (m - 1)) x := (hasStrictDerivAt_zpow m x h).hasDerivAt theorem hasDerivWithinAt_zpow (m : â„€) (x : 𝕜) (h : x ≠ 0 √ 0 ≀ m) (s : Set 𝕜) : HasDerivWithinAt (fun x => x ^ m) ((m : 𝕜) * x ^ (m - 1)) s x := (hasDerivAt_zpow m x h).hasDerivWithinAt theorem differentiableAt_zpow : DifferentiableAt 𝕜 (fun x => x ^ m) x ↔ x ≠ 0 √ 0 ≀ m := ⟹fun H => NormedField.continuousAt_zpow.1 H.continuousAt, fun H => (hasDerivAt_zpow m x H).differentiableAt⟩ theorem differentiableWithinAt_zpow (m : â„€) (x : 𝕜) (h : x ≠ 0 √ 0 ≀ m) : DifferentiableWithinAt 𝕜 (fun x => x ^ m) s x := (differentiableAt_zpow.mpr h).differentiableWithinAt theorem differentiableOn_zpow (m : â„€) (s : Set 𝕜) (h : (0 : 𝕜) ∉ s √ 0 ≀ m) : DifferentiableOn 𝕜 (fun x => x ^ m) s := fun x hxs => differentiableWithinAt_zpow m x <| h.imp_left <| ne_of_mem_of_not_mem hxs theorem deriv_zpow (m : â„€) (x : 𝕜) : deriv (fun x => x ^ m) x = m * x ^ (m - 1) := by by_cases H : x ≠ 0 √ 0 ≀ m · exact (hasDerivAt_zpow m x H).deriv · rw [deriv_zero_of_not_differentiableAt (mt differentiableAt_zpow.1 H)] push_neg at H rcases H with ⟹rfl, hm⟩ rw [zero_zpow _ ((sub_one_lt _).trans hm).ne, mul_zero] @[simp] theorem deriv_zpow' (m : â„€) : (deriv fun x : 𝕜 => x ^ m) = fun x => (m : 𝕜) * x ^ (m - 1) := funext <| deriv_zpow m theorem derivWithin_zpow (hxs : UniqueDiffWithinAt 𝕜 s x) (h : x ≠ 0 √ 0 ≀ m) : derivWithin (fun x => x ^ m) s x = (m : 𝕜) * x ^ (m - 1) := (hasDerivWithinAt_zpow m x h s).derivWithin hxs @[simp] theorem iter_deriv_zpow' (m : â„€) (k : ℕ) : (deriv^[k] fun x : 𝕜 => x ^ m) = fun x => (∏ i ∈ Finset.range k, ((m : 𝕜) - i)) * x ^ (m - k) := by induction' k with k ihk · simp only [Nat.zero_eq, one_mul, Int.ofNat_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.ofNat_succ, ← sub_sub, Int.cast_sub, Int.cast_natCast, mul_assoc] theorem iter_deriv_zpow (m : â„€) (x : 𝕜) (k : ℕ) : deriv^[k] (fun y => y ^ m) x = (∏ i ∈ Finset.range k, ((m : 𝕜) - i)) * x ^ (m - k) := congr_fun (iter_deriv_zpow' m k) x theorem iter_deriv_pow (n : ℕ) (x : 𝕜) (k : ℕ) : deriv^[k] (fun x : 𝕜 => x ^ n) x = (∏ i ∈ Finset.range k, ((n : 𝕜) - i)) * x ^ (n - k) := by simp only [← zpow_natCast, iter_deriv_zpow, Int.cast_natCast] rcases le_or_lt k n with hkn | hnk · rw [Int.ofNat_sub hkn] · have : (∏ i ∈ Finset.range k, (n - i : 𝕜)) = 0 := Finset.prod_eq_zero (Finset.mem_range.2 hnk) (sub_self _) simp only [this, zero_mul] @[simp] theorem iter_deriv_pow' (n k : ℕ) : (deriv^[k] fun x : 𝕜 => x ^ n) = fun x => (∏ i ∈ Finset.range k, ((n : 𝕜) - i)) * x ^ (n - k) := funext fun x => iter_deriv_pow n x k theorem iter_deriv_inv (k : ℕ) (x : 𝕜) : deriv^[k] Inv.inv x = (∏ i ∈ 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] theorem iter_deriv_inv' (k : ℕ) : deriv^[k] Inv.inv = fun x : 𝕜 => (∏ i ∈ Finset.range k, (-1 - i : 𝕜)) * x ^ (-1 - k : â„€) := funext (iter_deriv_inv k) variable {f : E → 𝕜} {t : Set E} {a : E} theorem DifferentiableWithinAt.zpow (hf : DifferentiableWithinAt 𝕜 f t a) (h : f a ≠ 0 √ 0 ≀ m) : DifferentiableWithinAt 𝕜 (fun x => f x ^ m) t a := (differentiableAt_zpow.2 h).comp_differentiableWithinAt a hf theorem DifferentiableAt.zpow (hf : DifferentiableAt 𝕜 f a) (h : f a ≠ 0 √ 0 ≀ m) : DifferentiableAt 𝕜 (fun x => f x ^ m) a := (differentiableAt_zpow.2 h).comp a hf theorem DifferentiableOn.zpow (hf : DifferentiableOn 𝕜 f t) (h : (∀ x ∈ t, f x ≠ 0) √ 0 ≀ m) : DifferentiableOn 𝕜 (fun x => f x ^ m) t := fun x hx => (hf x hx).zpow <| h.imp_left fun h => h x hx theorem Differentiable.zpow (hf : Differentiable 𝕜 f) (h : (∀ x, f x ≠ 0) √ 0 ≀ m) : Differentiable 𝕜 fun x => f x ^ m := fun x => (hf x).zpow <| h.imp_left fun h => h x
Analysis\Calculus\FDeriv\Add.lean
/- 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 Mathlib.Analysis.Calculus.FDeriv.Linear import Mathlib.Analysis.Calculus.FDeriv.Comp /-! # Additive operations on derivatives For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of * sum of finitely many functions * multiplication of a function by a scalar constant * negative of a function * subtraction of two functions -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} section ConstSMul variable {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] /-! ### Derivative of a function multiplied by a constant -/ @[fun_prop] theorem HasStrictFDerivAt.const_smul (h : HasStrictFDerivAt f f' x) (c : R) : HasStrictFDerivAt (fun x => c • f x) (c • f') x := (c • (1 : F →L[𝕜] F)).hasStrictFDerivAt.comp x h theorem HasFDerivAtFilter.const_smul (h : HasFDerivAtFilter f f' x L) (c : R) : HasFDerivAtFilter (fun x => c • f x) (c • f') x L := (c • (1 : F →L[𝕜] F)).hasFDerivAtFilter.comp x h tendsto_map @[fun_prop] nonrec theorem HasFDerivWithinAt.const_smul (h : HasFDerivWithinAt f f' s x) (c : R) : HasFDerivWithinAt (fun x => c • f x) (c • f') s x := h.const_smul c @[fun_prop] nonrec theorem HasFDerivAt.const_smul (h : HasFDerivAt f f' x) (c : R) : HasFDerivAt (fun x => c • f x) (c • f') x := h.const_smul c @[fun_prop] theorem DifferentiableWithinAt.const_smul (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : DifferentiableWithinAt 𝕜 (fun y => c • f y) s x := (h.hasFDerivWithinAt.const_smul c).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.const_smul (h : DifferentiableAt 𝕜 f x) (c : R) : DifferentiableAt 𝕜 (fun y => c • f y) x := (h.hasFDerivAt.const_smul c).differentiableAt @[fun_prop] theorem DifferentiableOn.const_smul (h : DifferentiableOn 𝕜 f s) (c : R) : DifferentiableOn 𝕜 (fun y => c • f y) s := fun x hx => (h x hx).const_smul c @[fun_prop] theorem Differentiable.const_smul (h : Differentiable 𝕜 f) (c : R) : Differentiable 𝕜 fun y => c • f y := fun x => (h x).const_smul c theorem fderivWithin_const_smul (hxs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : fderivWithin 𝕜 (fun y => c • f y) s x = c • fderivWithin 𝕜 f s x := (h.hasFDerivWithinAt.const_smul c).fderivWithin hxs theorem fderiv_const_smul (h : DifferentiableAt 𝕜 f x) (c : R) : fderiv 𝕜 (fun y => c • f y) x = c • fderiv 𝕜 f x := (h.hasFDerivAt.const_smul c).fderiv end ConstSMul section Add /-! ### Derivative of the sum of two functions -/ @[fun_prop] nonrec theorem HasStrictFDerivAt.add (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun y => f y + g y) (f' + g') x := (hf.add hg).congr_left fun y => by simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply] abel theorem HasFDerivAtFilter.add (hf : HasFDerivAtFilter f f' x L) (hg : HasFDerivAtFilter g g' x L) : HasFDerivAtFilter (fun y => f y + g y) (f' + g') x L := .of_isLittleO <| (hf.isLittleO.add hg.isLittleO).congr_left fun _ => by simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply] abel @[fun_prop] nonrec theorem HasFDerivWithinAt.add (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun y => f y + g y) (f' + g') s x := hf.add hg @[fun_prop] nonrec theorem HasFDerivAt.add (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun x => f x + g x) (f' + g') x := hf.add hg @[fun_prop] theorem DifferentiableWithinAt.add (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : DifferentiableWithinAt 𝕜 (fun y => f y + g y) s x := (hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y + g y) x := (hf.hasFDerivAt.add hg.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.add (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y + g y) s := fun x hx => (hf x hx).add (hg x hx) @[simp, fun_prop] theorem Differentiable.add (hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g) : Differentiable 𝕜 fun y => f y + g y := fun x => (hf x).add (hg x) theorem fderivWithin_add (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : fderivWithin 𝕜 (fun y => f y + g y) s x = fderivWithin 𝕜 f s x + fderivWithin 𝕜 g s x := (hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).fderivWithin hxs theorem fderiv_add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (fun y => f y + g y) x = fderiv 𝕜 f x + fderiv 𝕜 g x := (hf.hasFDerivAt.add hg.hasFDerivAt).fderiv @[fun_prop] theorem HasStrictFDerivAt.add_const (hf : HasStrictFDerivAt f f' x) (c : F) : HasStrictFDerivAt (fun y => f y + c) f' x := add_zero f' ▾ hf.add (hasStrictFDerivAt_const _ _) theorem HasFDerivAtFilter.add_const (hf : HasFDerivAtFilter f f' x L) (c : F) : HasFDerivAtFilter (fun y => f y + c) f' x L := add_zero f' ▾ hf.add (hasFDerivAtFilter_const _ _ _) @[fun_prop] nonrec theorem HasFDerivWithinAt.add_const (hf : HasFDerivWithinAt f f' s x) (c : F) : HasFDerivWithinAt (fun y => f y + c) f' s x := hf.add_const c @[fun_prop] nonrec theorem HasFDerivAt.add_const (hf : HasFDerivAt f f' x) (c : F) : HasFDerivAt (fun x => f x + c) f' x := hf.add_const c @[fun_prop] theorem DifferentiableWithinAt.add_const (hf : DifferentiableWithinAt 𝕜 f s x) (c : F) : DifferentiableWithinAt 𝕜 (fun y => f y + c) s x := (hf.hasFDerivWithinAt.add_const c).differentiableWithinAt @[simp] theorem differentiableWithinAt_add_const_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => f y + c) s x ↔ DifferentiableWithinAt 𝕜 f s x := ⟹fun h => by simpa using h.add_const (-c), fun h => h.add_const c⟩ @[fun_prop] theorem DifferentiableAt.add_const (hf : DifferentiableAt 𝕜 f x) (c : F) : DifferentiableAt 𝕜 (fun y => f y + c) x := (hf.hasFDerivAt.add_const c).differentiableAt @[simp] theorem differentiableAt_add_const_iff (c : F) : DifferentiableAt 𝕜 (fun y => f y + c) x ↔ DifferentiableAt 𝕜 f x := ⟹fun h => by simpa using h.add_const (-c), fun h => h.add_const c⟩ @[fun_prop] theorem DifferentiableOn.add_const (hf : DifferentiableOn 𝕜 f s) (c : F) : DifferentiableOn 𝕜 (fun y => f y + c) s := fun x hx => (hf x hx).add_const c @[simp] theorem differentiableOn_add_const_iff (c : F) : DifferentiableOn 𝕜 (fun y => f y + c) s ↔ DifferentiableOn 𝕜 f s := ⟹fun h => by simpa using h.add_const (-c), fun h => h.add_const c⟩ @[fun_prop] theorem Differentiable.add_const (hf : Differentiable 𝕜 f) (c : F) : Differentiable 𝕜 fun y => f y + c := fun x => (hf x).add_const c @[simp] theorem differentiable_add_const_iff (c : F) : (Differentiable 𝕜 fun y => f y + c) ↔ Differentiable 𝕜 f := ⟹fun h => by simpa using h.add_const (-c), fun h => h.add_const c⟩ theorem fderivWithin_add_const (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : fderivWithin 𝕜 (fun y => f y + c) s x = fderivWithin 𝕜 f s x := if hf : DifferentiableWithinAt 𝕜 f s x then (hf.hasFDerivWithinAt.add_const c).fderivWithin hxs else by rw [fderivWithin_zero_of_not_differentiableWithinAt hf, fderivWithin_zero_of_not_differentiableWithinAt] simpa theorem fderiv_add_const (c : F) : fderiv 𝕜 (fun y => f y + c) x = fderiv 𝕜 f x := by simp only [← fderivWithin_univ, fderivWithin_add_const uniqueDiffWithinAt_univ] @[fun_prop] theorem HasStrictFDerivAt.const_add (hf : HasStrictFDerivAt f f' x) (c : F) : HasStrictFDerivAt (fun y => c + f y) f' x := zero_add f' ▾ (hasStrictFDerivAt_const _ _).add hf theorem HasFDerivAtFilter.const_add (hf : HasFDerivAtFilter f f' x L) (c : F) : HasFDerivAtFilter (fun y => c + f y) f' x L := zero_add f' ▾ (hasFDerivAtFilter_const _ _ _).add hf @[fun_prop] nonrec theorem HasFDerivWithinAt.const_add (hf : HasFDerivWithinAt f f' s x) (c : F) : HasFDerivWithinAt (fun y => c + f y) f' s x := hf.const_add c @[fun_prop] nonrec theorem HasFDerivAt.const_add (hf : HasFDerivAt f f' x) (c : F) : HasFDerivAt (fun x => c + f x) f' x := hf.const_add c @[fun_prop] theorem DifferentiableWithinAt.const_add (hf : DifferentiableWithinAt 𝕜 f s x) (c : F) : DifferentiableWithinAt 𝕜 (fun y => c + f y) s x := (hf.hasFDerivWithinAt.const_add c).differentiableWithinAt @[simp] theorem differentiableWithinAt_const_add_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => c + f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := ⟹fun h => by simpa using h.const_add (-c), fun h => h.const_add c⟩ @[fun_prop] theorem DifferentiableAt.const_add (hf : DifferentiableAt 𝕜 f x) (c : F) : DifferentiableAt 𝕜 (fun y => c + f y) x := (hf.hasFDerivAt.const_add c).differentiableAt @[simp] theorem differentiableAt_const_add_iff (c : F) : DifferentiableAt 𝕜 (fun y => c + f y) x ↔ DifferentiableAt 𝕜 f x := ⟹fun h => by simpa using h.const_add (-c), fun h => h.const_add c⟩ @[fun_prop] theorem DifferentiableOn.const_add (hf : DifferentiableOn 𝕜 f s) (c : F) : DifferentiableOn 𝕜 (fun y => c + f y) s := fun x hx => (hf x hx).const_add c @[simp] theorem differentiableOn_const_add_iff (c : F) : DifferentiableOn 𝕜 (fun y => c + f y) s ↔ DifferentiableOn 𝕜 f s := ⟹fun h => by simpa using h.const_add (-c), fun h => h.const_add c⟩ @[fun_prop] theorem Differentiable.const_add (hf : Differentiable 𝕜 f) (c : F) : Differentiable 𝕜 fun y => c + f y := fun x => (hf x).const_add c @[simp] theorem differentiable_const_add_iff (c : F) : (Differentiable 𝕜 fun y => c + f y) ↔ Differentiable 𝕜 f := ⟹fun h => by simpa using h.const_add (-c), fun h => h.const_add c⟩ theorem fderivWithin_const_add (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : fderivWithin 𝕜 (fun y => c + f y) s x = fderivWithin 𝕜 f s x := by simpa only [add_comm] using fderivWithin_add_const hxs c theorem fderiv_const_add (c : F) : fderiv 𝕜 (fun y => c + f y) x = fderiv 𝕜 f x := by simp only [add_comm c, fderiv_add_const] end Add section Sum /-! ### Derivative of a finite sum of functions -/ variable {ι : Type*} {u : Finset ι} {A : ι → E → F} {A' : ι → E →L[𝕜] F} @[fun_prop] theorem HasStrictFDerivAt.sum (h : ∀ i ∈ u, HasStrictFDerivAt (A i) (A' i) x) : HasStrictFDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := by dsimp [HasStrictFDerivAt] at * convert IsLittleO.sum h simp [Finset.sum_sub_distrib, ContinuousLinearMap.sum_apply] theorem HasFDerivAtFilter.sum (h : ∀ i ∈ u, HasFDerivAtFilter (A i) (A' i) x L) : HasFDerivAtFilter (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x L := by simp only [hasFDerivAtFilter_iff_isLittleO] at * convert IsLittleO.sum h simp [ContinuousLinearMap.sum_apply] @[fun_prop] theorem HasFDerivWithinAt.sum (h : ∀ i ∈ u, HasFDerivWithinAt (A i) (A' i) s x) : HasFDerivWithinAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) s x := HasFDerivAtFilter.sum h @[fun_prop] theorem HasFDerivAt.sum (h : ∀ i ∈ u, HasFDerivAt (A i) (A' i) x) : HasFDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := HasFDerivAtFilter.sum h @[fun_prop] theorem DifferentiableWithinAt.sum (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) : DifferentiableWithinAt 𝕜 (fun y => ∑ i ∈ u, A i y) s x := HasFDerivWithinAt.differentiableWithinAt <| HasFDerivWithinAt.sum fun i hi => (h i hi).hasFDerivWithinAt @[simp, fun_prop] theorem DifferentiableAt.sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) : DifferentiableAt 𝕜 (fun y => ∑ i ∈ u, A i y) x := HasFDerivAt.differentiableAt <| HasFDerivAt.sum fun i hi => (h i hi).hasFDerivAt @[fun_prop] theorem DifferentiableOn.sum (h : ∀ i ∈ u, DifferentiableOn 𝕜 (A i) s) : DifferentiableOn 𝕜 (fun y => ∑ i ∈ u, A i y) s := fun x hx => DifferentiableWithinAt.sum fun i hi => h i hi x hx @[simp, fun_prop] theorem Differentiable.sum (h : ∀ i ∈ u, Differentiable 𝕜 (A i)) : Differentiable 𝕜 fun y => ∑ i ∈ u, A i y := fun x => DifferentiableAt.sum fun i hi => h i hi x theorem fderivWithin_sum (hxs : UniqueDiffWithinAt 𝕜 s x) (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) : fderivWithin 𝕜 (fun y => ∑ i ∈ u, A i y) s x = ∑ i ∈ u, fderivWithin 𝕜 (A i) s x := (HasFDerivWithinAt.sum fun i hi => (h i hi).hasFDerivWithinAt).fderivWithin hxs theorem fderiv_sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) : fderiv 𝕜 (fun y => ∑ i ∈ u, A i y) x = ∑ i ∈ u, fderiv 𝕜 (A i) x := (HasFDerivAt.sum fun i hi => (h i hi).hasFDerivAt).fderiv end Sum section Neg /-! ### Derivative of the negative of a function -/ @[fun_prop] theorem HasStrictFDerivAt.neg (h : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => -f x) (-f') x := (-1 : F →L[𝕜] F).hasStrictFDerivAt.comp x h theorem HasFDerivAtFilter.neg (h : HasFDerivAtFilter f f' x L) : HasFDerivAtFilter (fun x => -f x) (-f') x L := (-1 : F →L[𝕜] F).hasFDerivAtFilter.comp x h tendsto_map @[fun_prop] nonrec theorem HasFDerivWithinAt.neg (h : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => -f x) (-f') s x := h.neg @[fun_prop] nonrec theorem HasFDerivAt.neg (h : HasFDerivAt f f' x) : HasFDerivAt (fun x => -f x) (-f') x := h.neg @[fun_prop] theorem DifferentiableWithinAt.neg (h : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (fun y => -f y) s x := h.hasFDerivWithinAt.neg.differentiableWithinAt @[simp] theorem differentiableWithinAt_neg_iff : DifferentiableWithinAt 𝕜 (fun y => -f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := ⟹fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ @[fun_prop] theorem DifferentiableAt.neg (h : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => -f y) x := h.hasFDerivAt.neg.differentiableAt @[simp] theorem differentiableAt_neg_iff : DifferentiableAt 𝕜 (fun y => -f y) x ↔ DifferentiableAt 𝕜 f x := ⟹fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ @[fun_prop] theorem DifferentiableOn.neg (h : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => -f y) s := fun x hx => (h x hx).neg @[simp] theorem differentiableOn_neg_iff : DifferentiableOn 𝕜 (fun y => -f y) s ↔ DifferentiableOn 𝕜 f s := ⟹fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ @[fun_prop] theorem Differentiable.neg (h : Differentiable 𝕜 f) : Differentiable 𝕜 fun y => -f y := fun x => (h x).neg @[simp] theorem differentiable_neg_iff : (Differentiable 𝕜 fun y => -f y) ↔ Differentiable 𝕜 f := ⟹fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ theorem fderivWithin_neg (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun y => -f y) s x = -fderivWithin 𝕜 f s x := if h : DifferentiableWithinAt 𝕜 f s x then h.hasFDerivWithinAt.neg.fderivWithin hxs else by rw [fderivWithin_zero_of_not_differentiableWithinAt h, fderivWithin_zero_of_not_differentiableWithinAt, neg_zero] simpa @[simp] theorem fderiv_neg : fderiv 𝕜 (fun y => -f y) x = -fderiv 𝕜 f x := by simp only [← fderivWithin_univ, fderivWithin_neg uniqueDiffWithinAt_univ] end Neg section Sub /-! ### Derivative of the difference of two functions -/ @[fun_prop] theorem HasStrictFDerivAt.sub (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun x => f x - g x) (f' - g') x := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem HasFDerivAtFilter.sub (hf : HasFDerivAtFilter f f' x L) (hg : HasFDerivAtFilter g g' x L) : HasFDerivAtFilter (fun x => f x - g x) (f' - g') x L := by simpa only [sub_eq_add_neg] using hf.add hg.neg @[fun_prop] nonrec theorem HasFDerivWithinAt.sub (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun x => f x - g x) (f' - g') s x := hf.sub hg @[fun_prop] nonrec theorem HasFDerivAt.sub (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun x => f x - g x) (f' - g') x := hf.sub hg @[fun_prop] theorem DifferentiableWithinAt.sub (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : DifferentiableWithinAt 𝕜 (fun y => f y - g y) s x := (hf.hasFDerivWithinAt.sub hg.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.sub (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y - g y) x := (hf.hasFDerivAt.sub hg.hasFDerivAt).differentiableAt @[simp] lemma DifferentiableAt.add_iff_left (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y + g y) x ↔ DifferentiableAt 𝕜 f x := by refine ⟹fun h ↩ ?_, fun hf ↩ hf.add hg⟩ simpa only [add_sub_cancel_right] using h.sub hg @[simp] lemma DifferentiableAt.add_iff_right (hg : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => f y + g y) x ↔ DifferentiableAt 𝕜 g x := by simp only [add_comm (f _), hg.add_iff_left] @[simp] lemma DifferentiableAt.sub_iff_left (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y - g y) x ↔ DifferentiableAt 𝕜 f x := by simp only [sub_eq_add_neg, differentiableAt_neg_iff, hg, add_iff_left] @[simp] lemma DifferentiableAt.sub_iff_right (hg : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => f y - g y) x ↔ DifferentiableAt 𝕜 g x := by simp only [sub_eq_add_neg, hg, add_iff_right, differentiableAt_neg_iff] @[fun_prop] theorem DifferentiableOn.sub (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y - g y) s := fun x hx => (hf x hx).sub (hg x hx) @[simp] lemma DifferentiableOn.add_iff_left (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y + g y) s ↔ DifferentiableOn 𝕜 f s := by refine ⟹fun h ↩ ?_, fun hf ↩ hf.add hg⟩ simpa only [add_sub_cancel_right] using h.sub hg @[simp] lemma DifferentiableOn.add_iff_right (hg : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => f y + g y) s ↔ DifferentiableOn 𝕜 g s := by simp only [add_comm (f _), hg.add_iff_left] @[simp] lemma DifferentiableOn.sub_iff_left (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y - g y) s ↔ DifferentiableOn 𝕜 f s := by simp only [sub_eq_add_neg, differentiableOn_neg_iff, hg, add_iff_left] @[simp] lemma DifferentiableOn.sub_iff_right (hg : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => f y - g y) s ↔ DifferentiableOn 𝕜 g s := by simp only [sub_eq_add_neg, differentiableOn_neg_iff, hg, add_iff_right] @[simp, fun_prop] theorem Differentiable.sub (hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g) : Differentiable 𝕜 fun y => f y - g y := fun x => (hf x).sub (hg x) @[simp] lemma Differentiable.add_iff_left (hg : Differentiable 𝕜 g) : Differentiable 𝕜 (fun y => f y + g y) ↔ Differentiable 𝕜 f := by refine ⟹fun h ↩ ?_, fun hf ↩ hf.add hg⟩ simpa only [add_sub_cancel_right] using h.sub hg @[simp] lemma Differentiable.add_iff_right (hg : Differentiable 𝕜 f) : Differentiable 𝕜 (fun y => f y + g y) ↔ Differentiable 𝕜 g := by simp only [add_comm (f _), hg.add_iff_left] @[simp] lemma Differentiable.sub_iff_left (hg : Differentiable 𝕜 g) : Differentiable 𝕜 (fun y => f y - g y) ↔ Differentiable 𝕜 f := by simp only [sub_eq_add_neg, differentiable_neg_iff, hg, add_iff_left] @[simp] lemma Differentiable.sub_iff_right (hg : Differentiable 𝕜 f) : Differentiable 𝕜 (fun y => f y - g y) ↔ Differentiable 𝕜 g := by simp only [sub_eq_add_neg, differentiable_neg_iff, hg, add_iff_right] theorem fderivWithin_sub (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : fderivWithin 𝕜 (fun y => f y - g y) s x = fderivWithin 𝕜 f s x - fderivWithin 𝕜 g s x := (hf.hasFDerivWithinAt.sub hg.hasFDerivWithinAt).fderivWithin hxs theorem fderiv_sub (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (fun y => f y - g y) x = fderiv 𝕜 f x - fderiv 𝕜 g x := (hf.hasFDerivAt.sub hg.hasFDerivAt).fderiv @[fun_prop] theorem HasStrictFDerivAt.sub_const (hf : HasStrictFDerivAt f f' x) (c : F) : HasStrictFDerivAt (fun x => f x - c) f' x := by simpa only [sub_eq_add_neg] using hf.add_const (-c) theorem HasFDerivAtFilter.sub_const (hf : HasFDerivAtFilter f f' x L) (c : F) : HasFDerivAtFilter (fun x => f x - c) f' x L := by simpa only [sub_eq_add_neg] using hf.add_const (-c) @[fun_prop] nonrec theorem HasFDerivWithinAt.sub_const (hf : HasFDerivWithinAt f f' s x) (c : F) : HasFDerivWithinAt (fun x => f x - c) f' s x := hf.sub_const c @[fun_prop] nonrec theorem HasFDerivAt.sub_const (hf : HasFDerivAt f f' x) (c : F) : HasFDerivAt (fun x => f x - c) f' x := hf.sub_const c @[fun_prop] theorem hasStrictFDerivAt_sub_const {x : F} (c : F) : HasStrictFDerivAt (· - c) (id 𝕜 F) x := (hasStrictFDerivAt_id x).sub_const c @[fun_prop] theorem hasFDerivAt_sub_const {x : F} (c : F) : HasFDerivAt (· - c) (id 𝕜 F) x := (hasFDerivAt_id x).sub_const c @[fun_prop] theorem DifferentiableWithinAt.sub_const (hf : DifferentiableWithinAt 𝕜 f s x) (c : F) : DifferentiableWithinAt 𝕜 (fun y => f y - c) s x := (hf.hasFDerivWithinAt.sub_const c).differentiableWithinAt @[simp] theorem differentiableWithinAt_sub_const_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => f y - c) s x ↔ DifferentiableWithinAt 𝕜 f s x := by simp only [sub_eq_add_neg, differentiableWithinAt_add_const_iff] @[fun_prop] theorem DifferentiableAt.sub_const (hf : DifferentiableAt 𝕜 f x) (c : F) : DifferentiableAt 𝕜 (fun y => f y - c) x := (hf.hasFDerivAt.sub_const c).differentiableAt @[deprecated DifferentiableAt.sub_iff_left (since := "2024-07-11")] theorem differentiableAt_sub_const_iff (c : F) : DifferentiableAt 𝕜 (fun y => f y - c) x ↔ DifferentiableAt 𝕜 f x := (differentiableAt_const _).sub_iff_left @[fun_prop] theorem DifferentiableOn.sub_const (hf : DifferentiableOn 𝕜 f s) (c : F) : DifferentiableOn 𝕜 (fun y => f y - c) s := fun x hx => (hf x hx).sub_const c @[deprecated DifferentiableOn.sub_iff_left (since := "2024-07-11")] theorem differentiableOn_sub_const_iff (c : F) : DifferentiableOn 𝕜 (fun y => f y - c) s ↔ DifferentiableOn 𝕜 f s := (differentiableOn_const _).sub_iff_left @[fun_prop] theorem Differentiable.sub_const (hf : Differentiable 𝕜 f) (c : F) : Differentiable 𝕜 fun y => f y - c := fun x => (hf x).sub_const c @[deprecated Differentiable.sub_iff_left (since := "2024-07-11")] theorem differentiable_sub_const_iff (c : F) : (Differentiable 𝕜 fun y => f y - c) ↔ Differentiable 𝕜 f := (differentiable_const _).sub_iff_left theorem fderivWithin_sub_const (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : fderivWithin 𝕜 (fun y => f y - c) s x = fderivWithin 𝕜 f s x := by simp only [sub_eq_add_neg, fderivWithin_add_const hxs] theorem fderiv_sub_const (c : F) : fderiv 𝕜 (fun y => f y - c) x = fderiv 𝕜 f x := by simp only [sub_eq_add_neg, fderiv_add_const] @[fun_prop] theorem HasStrictFDerivAt.const_sub (hf : HasStrictFDerivAt f f' x) (c : F) : HasStrictFDerivAt (fun x => c - f x) (-f') x := by simpa only [sub_eq_add_neg] using hf.neg.const_add c theorem HasFDerivAtFilter.const_sub (hf : HasFDerivAtFilter f f' x L) (c : F) : HasFDerivAtFilter (fun x => c - f x) (-f') x L := by simpa only [sub_eq_add_neg] using hf.neg.const_add c @[fun_prop] nonrec theorem HasFDerivWithinAt.const_sub (hf : HasFDerivWithinAt f f' s x) (c : F) : HasFDerivWithinAt (fun x => c - f x) (-f') s x := hf.const_sub c @[fun_prop] nonrec theorem HasFDerivAt.const_sub (hf : HasFDerivAt f f' x) (c : F) : HasFDerivAt (fun x => c - f x) (-f') x := hf.const_sub c @[fun_prop] theorem DifferentiableWithinAt.const_sub (hf : DifferentiableWithinAt 𝕜 f s x) (c : F) : DifferentiableWithinAt 𝕜 (fun y => c - f y) s x := (hf.hasFDerivWithinAt.const_sub c).differentiableWithinAt @[simp] theorem differentiableWithinAt_const_sub_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => c - f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := by simp [sub_eq_add_neg] @[fun_prop] theorem DifferentiableAt.const_sub (hf : DifferentiableAt 𝕜 f x) (c : F) : DifferentiableAt 𝕜 (fun y => c - f y) x := (hf.hasFDerivAt.const_sub c).differentiableAt @[deprecated DifferentiableAt.sub_iff_right (since := "2024-07-11")] theorem differentiableAt_const_sub_iff (c : F) : DifferentiableAt 𝕜 (fun y => c - f y) x ↔ DifferentiableAt 𝕜 f x := (differentiableAt_const _).sub_iff_right @[fun_prop] theorem DifferentiableOn.const_sub (hf : DifferentiableOn 𝕜 f s) (c : F) : DifferentiableOn 𝕜 (fun y => c - f y) s := fun x hx => (hf x hx).const_sub c @[deprecated DifferentiableOn.sub_iff_right (since := "2024-07-11")] theorem differentiableOn_const_sub_iff (c : F) : DifferentiableOn 𝕜 (fun y => c - f y) s ↔ DifferentiableOn 𝕜 f s := (differentiableOn_const _).sub_iff_right @[fun_prop] theorem Differentiable.const_sub (hf : Differentiable 𝕜 f) (c : F) : Differentiable 𝕜 fun y => c - f y := fun x => (hf x).const_sub c @[deprecated Differentiable.sub_iff_right (since := "2024-07-11")] theorem differentiable_const_sub_iff (c : F) : (Differentiable 𝕜 fun y => c - f y) ↔ Differentiable 𝕜 f := (differentiable_const _).sub_iff_right theorem fderivWithin_const_sub (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : fderivWithin 𝕜 (fun y => c - f y) s x = -fderivWithin 𝕜 f s x := by simp only [sub_eq_add_neg, fderivWithin_const_add, fderivWithin_neg, hxs] theorem fderiv_const_sub (c : F) : fderiv 𝕜 (fun y => c - f y) x = -fderiv 𝕜 f x := by simp only [← fderivWithin_univ, fderivWithin_const_sub uniqueDiffWithinAt_univ] end Sub end
Analysis\Calculus\FDeriv\Analytic.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Analytic.Basic import Mathlib.Analysis.Analytic.CPolynomial import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.ContDiff.Defs import Mathlib.Analysis.Calculus.FDeriv.Add /-! # Frechet derivatives of analytic functions. A function expressible as a power series at a point has a Frechet derivative there. Also the special case in terms of `deriv` when the domain is 1-dimensional. As an application, we show that continuous multilinear maps are smooth. We also compute their iterated derivatives, in `ContinuousMultilinearMap.iteratedFDeriv_eq`. -/ open Filter Asymptotics open scoped ENNReal universe u v variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type u} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] section fderiv variable {p : FormalMultilinearSeries 𝕜 E F} {r : ℝ≥0∞} variable {f : E → F} {x : E} {s : Set E} theorem HasFPowerSeriesAt.hasStrictFDerivAt (h : HasFPowerSeriesAt f p x) : HasStrictFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p 1)) x := by refine h.isBigO_image_sub_norm_mul_norm_sub.trans_isLittleO (IsLittleO.of_norm_right ?_) refine isLittleO_iff_exists_eq_mul.2 ⟹fun y => ‖y - (x, x)‖, ?_, EventuallyEq.rfl⟩ refine (continuous_id.sub continuous_const).norm.tendsto' _ _ ?_ rw [_root_.id, sub_self, norm_zero] theorem HasFPowerSeriesAt.hasFDerivAt (h : HasFPowerSeriesAt f p x) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p 1)) x := h.hasStrictFDerivAt.hasFDerivAt theorem HasFPowerSeriesAt.differentiableAt (h : HasFPowerSeriesAt f p x) : DifferentiableAt 𝕜 f x := h.hasFDerivAt.differentiableAt theorem AnalyticAt.differentiableAt : AnalyticAt 𝕜 f x → DifferentiableAt 𝕜 f x | ⟹_, hp⟩ => hp.differentiableAt theorem AnalyticAt.differentiableWithinAt (h : AnalyticAt 𝕜 f x) : DifferentiableWithinAt 𝕜 f s x := h.differentiableAt.differentiableWithinAt theorem HasFPowerSeriesAt.fderiv_eq (h : HasFPowerSeriesAt f p x) : fderiv 𝕜 f x = continuousMultilinearCurryFin1 𝕜 E F (p 1) := h.hasFDerivAt.fderiv theorem HasFPowerSeriesOnBall.differentiableOn [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) : DifferentiableOn 𝕜 f (EMetric.ball x r) := fun _ hy => (h.analyticAt_of_mem hy).differentiableWithinAt theorem AnalyticOn.differentiableOn (h : AnalyticOn 𝕜 f s) : DifferentiableOn 𝕜 f s := fun y hy => (h y hy).differentiableWithinAt theorem HasFPowerSeriesOnBall.hasFDerivAt [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1)) (x + y) := (h.changeOrigin hy).hasFPowerSeriesAt.hasFDerivAt theorem HasFPowerSeriesOnBall.fderiv_eq [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : fderiv 𝕜 f (x + y) = continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1) := (h.hasFDerivAt hy).fderiv /-- If a function has a power series on a ball, then so does its derivative. -/ theorem HasFPowerSeriesOnBall.fderiv [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) : HasFPowerSeriesOnBall (fderiv 𝕜 f) p.derivSeries x r := by refine .congr (f := fun z ↩ continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin (z - x) 1)) ?_ fun z hz ↩ ?_ · refine continuousMultilinearCurryFin1 𝕜 E F |>.toContinuousLinearEquiv.toContinuousLinearMap.comp_hasFPowerSeriesOnBall ?_ simpa using ((p.hasFPowerSeriesOnBall_changeOrigin 1 (h.r_pos.trans_le h.r_le)).mono h.r_pos h.r_le).comp_sub x dsimp only rw [← h.fderiv_eq, add_sub_cancel] simpa only [edist_eq_coe_nnnorm_sub, EMetric.mem_ball] using hz /-- If a function is analytic on a set `s`, so is its Fréchet derivative. -/ theorem AnalyticOn.fderiv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) : AnalyticOn 𝕜 (fderiv 𝕜 f) s := by intro y hy rcases h y hy with ⟹p, r, hp⟩ exact hp.fderiv.analyticAt /-- If a function is analytic on a set `s`, so are its successive Fréchet derivative. -/ theorem AnalyticOn.iteratedFDeriv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) (n : ℕ) : AnalyticOn 𝕜 (iteratedFDeriv 𝕜 n f) s := by induction' n with n IH · rw [iteratedFDeriv_zero_eq_comp] exact ((continuousMultilinearCurryFin0 𝕜 E F).symm : F →L[𝕜] E[×0]→L[𝕜] F).comp_analyticOn h · rw [iteratedFDeriv_succ_eq_comp_left] -- Porting note: for reasons that I do not understand at all, `?g` cannot be inlined. convert ContinuousLinearMap.comp_analyticOn ?g IH.fderiv case g => exact ↑(continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) ↩ E) F) simp /-- An analytic function is infinitely differentiable. -/ theorem AnalyticOn.contDiffOn [CompleteSpace F] (h : AnalyticOn 𝕜 f s) {n : ℕ∞} : ContDiffOn 𝕜 n f s := let t := { x | AnalyticAt 𝕜 f x } suffices ContDiffOn 𝕜 n f t from this.mono h have H : AnalyticOn 𝕜 f t := fun _x hx ↩ hx have t_open : IsOpen t := isOpen_analyticAt 𝕜 f contDiffOn_of_continuousOn_differentiableOn (fun m _ ↩ (H.iteratedFDeriv m).continuousOn.congr fun _ hx ↩ iteratedFDerivWithin_of_isOpen _ t_open hx) (fun m _ ↩ (H.iteratedFDeriv m).differentiableOn.congr fun _ hx ↩ iteratedFDerivWithin_of_isOpen _ t_open hx) theorem AnalyticAt.contDiffAt [CompleteSpace F] (h : AnalyticAt 𝕜 f x) {n : ℕ∞} : ContDiffAt 𝕜 n f x := by obtain ⟹s, hs, hf⟩ := h.exists_mem_nhds_analyticOn exact hf.contDiffOn.contDiffAt hs end fderiv section deriv variable {p : FormalMultilinearSeries 𝕜 𝕜 F} {r : ℝ≥0∞} variable {f : 𝕜 → F} {x : 𝕜} {s : Set 𝕜} protected theorem HasFPowerSeriesAt.hasStrictDerivAt (h : HasFPowerSeriesAt f p x) : HasStrictDerivAt f (p 1 fun _ => 1) x := h.hasStrictFDerivAt.hasStrictDerivAt protected theorem HasFPowerSeriesAt.hasDerivAt (h : HasFPowerSeriesAt f p x) : HasDerivAt f (p 1 fun _ => 1) x := h.hasStrictDerivAt.hasDerivAt protected theorem HasFPowerSeriesAt.deriv (h : HasFPowerSeriesAt f p x) : deriv f x = p 1 fun _ => 1 := h.hasDerivAt.deriv /-- If a function is analytic on a set `s`, so is its derivative. -/ theorem AnalyticOn.deriv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) : AnalyticOn 𝕜 (deriv f) s := (ContinuousLinearMap.apply 𝕜 F (1 : 𝕜)).comp_analyticOn h.fderiv /-- If a function is analytic on a set `s`, so are its successive derivatives. -/ theorem AnalyticOn.iterated_deriv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) (n : ℕ) : AnalyticOn 𝕜 (_root_.deriv^[n] f) s := by induction' n with n IH · exact h · simpa only [Function.iterate_succ', Function.comp_apply] using IH.deriv end deriv section fderiv variable {p : FormalMultilinearSeries 𝕜 E F} {r : ℝ≥0∞} {n : ℕ} variable {f : E → F} {x : E} {s : Set E} /-! The case of continuously polynomial functions. We get the same differentiability results as for analytic functions, but without the assumptions that `F` is complete. -/ theorem HasFiniteFPowerSeriesOnBall.differentiableOn (h : HasFiniteFPowerSeriesOnBall f p x n r) : DifferentiableOn 𝕜 f (EMetric.ball x r) := fun _ hy ↩ (h.cPolynomialAt_of_mem hy).analyticAt.differentiableWithinAt theorem HasFiniteFPowerSeriesOnBall.hasFDerivAt (h : HasFiniteFPowerSeriesOnBall f p x n r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1)) (x + y) := (h.changeOrigin hy).toHasFPowerSeriesOnBall.hasFPowerSeriesAt.hasFDerivAt theorem HasFiniteFPowerSeriesOnBall.fderiv_eq (h : HasFiniteFPowerSeriesOnBall f p x n r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : fderiv 𝕜 f (x + y) = continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1) := (h.hasFDerivAt hy).fderiv /-- If a function has a finite power series on a ball, then so does its derivative. -/ protected theorem HasFiniteFPowerSeriesOnBall.fderiv (h : HasFiniteFPowerSeriesOnBall f p x (n + 1) r) : HasFiniteFPowerSeriesOnBall (fderiv 𝕜 f) p.derivSeries x n r := by refine .congr (f := fun z ↩ continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin (z - x) 1)) ?_ fun z hz ↩ ?_ · refine continuousMultilinearCurryFin1 𝕜 E F |>.toContinuousLinearEquiv.toContinuousLinearMap.comp_hasFiniteFPowerSeriesOnBall ?_ simpa using ((p.hasFiniteFPowerSeriesOnBall_changeOrigin 1 h.finite).mono h.r_pos le_top).comp_sub x dsimp only rw [← h.fderiv_eq, add_sub_cancel] simpa only [edist_eq_coe_nnnorm_sub, EMetric.mem_ball] using hz /-- If a function has a finite power series on a ball, then so does its derivative. This is a variant of `HasFiniteFPowerSeriesOnBall.fderiv` where the degree of `f` is `< n` and not `< n + 1`. -/ theorem HasFiniteFPowerSeriesOnBall.fderiv' (h : HasFiniteFPowerSeriesOnBall f p x n r) : HasFiniteFPowerSeriesOnBall (fderiv 𝕜 f) p.derivSeries x (n - 1) r := by obtain rfl | hn := eq_or_ne n 0 · rw [zero_tsub] refine HasFiniteFPowerSeriesOnBall.bound_zero_of_eq_zero (fun y hy ↩ ?_) h.r_pos fun n ↩ ?_ · rw [Filter.EventuallyEq.fderiv_eq (f := fun _ ↩ 0)] · rw [fderiv_const, Pi.zero_apply] · exact Filter.eventuallyEq_iff_exists_mem.mpr ⟹EMetric.ball x r, EMetric.isOpen_ball.mem_nhds hy, fun z hz ↩ by rw [h.eq_zero_of_bound_zero z hz]⟩ · apply ContinuousMultilinearMap.ext; intro a change (continuousMultilinearCurryFin1 𝕜 E F) (p.changeOriginSeries 1 n a) = 0 rw [p.changeOriginSeries_finite_of_finite h.finite 1 (Nat.zero_le _)] exact map_zero _ · rw [← Nat.succ_pred hn] at h exact h.fderiv /-- If a function is polynomial on a set `s`, so is its Fréchet derivative. -/ theorem CPolynomialOn.fderiv (h : CPolynomialOn 𝕜 f s) : CPolynomialOn 𝕜 (fderiv 𝕜 f) s := by intro y hy rcases h y hy with ⟹p, r, n, hp⟩ exact hp.fderiv'.cPolynomialAt /-- If a function is polynomial on a set `s`, so are its successive Fréchet derivative. -/ theorem CPolynomialOn.iteratedFDeriv (h : CPolynomialOn 𝕜 f s) (n : ℕ) : CPolynomialOn 𝕜 (iteratedFDeriv 𝕜 n f) s := by induction' n with n IH · rw [iteratedFDeriv_zero_eq_comp] exact ((continuousMultilinearCurryFin0 𝕜 E F).symm : F →L[𝕜] E[×0]→L[𝕜] F).comp_cPolynomialOn h · rw [iteratedFDeriv_succ_eq_comp_left] convert ContinuousLinearMap.comp_cPolynomialOn ?g IH.fderiv case g => exact ↑(continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) ↩ E) F) simp /-- A polynomial function is infinitely differentiable. -/ theorem CPolynomialOn.contDiffOn (h : CPolynomialOn 𝕜 f s) {n : ℕ∞} : ContDiffOn 𝕜 n f s := let t := { x | CPolynomialAt 𝕜 f x } suffices ContDiffOn 𝕜 n f t from this.mono h have H : CPolynomialOn 𝕜 f t := fun _x hx ↩ hx have t_open : IsOpen t := isOpen_cPolynomialAt 𝕜 f contDiffOn_of_continuousOn_differentiableOn (fun m _ ↩ (H.iteratedFDeriv m).continuousOn.congr fun _ hx ↩ iteratedFDerivWithin_of_isOpen _ t_open hx) (fun m _ ↩ (H.iteratedFDeriv m).analyticOn.differentiableOn.congr fun _ hx ↩ iteratedFDerivWithin_of_isOpen _ t_open hx) theorem CPolynomialAt.contDiffAt (h : CPolynomialAt 𝕜 f x) {n : ℕ∞} : ContDiffAt 𝕜 n f x := let ⟹_, hs, hf⟩ := h.exists_mem_nhds_cPolynomialOn hf.contDiffOn.contDiffAt hs end fderiv section deriv variable {p : FormalMultilinearSeries 𝕜 𝕜 F} {r : ℝ≥0∞} variable {f : 𝕜 → F} {x : 𝕜} {s : Set 𝕜} /-- If a function is polynomial on a set `s`, so is its derivative. -/ protected theorem CPolynomialOn.deriv (h : CPolynomialOn 𝕜 f s) : CPolynomialOn 𝕜 (deriv f) s := (ContinuousLinearMap.apply 𝕜 F (1 : 𝕜)).comp_cPolynomialOn h.fderiv /-- If a function is polynomial on a set `s`, so are its successive derivatives. -/ theorem CPolynomialOn.iterated_deriv (h : CPolynomialOn 𝕜 f s) (n : ℕ) : CPolynomialOn 𝕜 (deriv^[n] f) s := by induction' n with n IH · exact h · simpa only [Function.iterate_succ', Function.comp_apply] using IH.deriv end deriv namespace ContinuousMultilinearMap variable {ι : Type*} {E : ι → Type*} [∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] [Fintype ι] (f : ContinuousMultilinearMap 𝕜 E F) open FormalMultilinearSeries protected theorem hasFiniteFPowerSeriesOnBall : HasFiniteFPowerSeriesOnBall f f.toFormalMultilinearSeries 0 (Fintype.card ι + 1) ⊀ := .mk' (fun m hm ↩ dif_neg (Nat.succ_le_iff.mp hm).ne) ENNReal.zero_lt_top fun y _ ↩ by rw [Finset.sum_eq_single_of_mem _ (Finset.self_mem_range_succ _), zero_add] · rw [toFormalMultilinearSeries, dif_pos rfl]; rfl · intro m _ ne; rw [toFormalMultilinearSeries, dif_neg ne.symm]; rfl theorem changeOriginSeries_support {k l : ℕ} (h : k + l ≠ Fintype.card ι) : f.toFormalMultilinearSeries.changeOriginSeries k l = 0 := Finset.sum_eq_zero fun _ _ ↩ by simp_rw [FormalMultilinearSeries.changeOriginSeriesTerm, toFormalMultilinearSeries, dif_neg h.symm, LinearIsometryEquiv.map_zero] variable {n : ℕ∞} (x : ∀ i, E i) open Finset in theorem changeOrigin_toFormalMultilinearSeries [DecidableEq ι] : continuousMultilinearCurryFin1 𝕜 (∀ i, E i) F (f.toFormalMultilinearSeries.changeOrigin x 1) = f.linearDeriv x := by ext y rw [continuousMultilinearCurryFin1_apply, linearDeriv_apply, changeOrigin, FormalMultilinearSeries.sum] cases isEmpty_or_nonempty ι · have (l) : 1 + l ≠ Fintype.card ι := by rw [add_comm, Fintype.card_eq_zero]; exact Nat.succ_ne_zero _ simp_rw [Fintype.sum_empty, changeOriginSeries_support _ (this _), zero_apply _, tsum_zero]; rfl rw [tsum_eq_single (Fintype.card ι - 1), changeOriginSeries]; swap · intro m hm rw [Ne, eq_tsub_iff_add_eq_of_le (by exact Fintype.card_pos), add_comm] at hm rw [f.changeOriginSeries_support hm, zero_apply] rw [sum_apply, ContinuousMultilinearMap.sum_apply, Fin.snoc_zero] simp_rw [changeOriginSeriesTerm_apply] refine (Fintype.sum_bijective (?_ ∘ Fintype.equivFinOfCardEq (Nat.add_sub_of_le Fintype.card_pos).symm) (.comp ?_ <| Equiv.bijective _) _ _ fun i ↩ ?_).symm · exact (⟹{·}ᶜ, by rw [card_compl, Fintype.card_fin, card_singleton, Nat.add_sub_cancel_left]⟩) · use fun _ _ ↩ (singleton_injective <| compl_injective <| Subtype.ext_iff.mp ·) intro ⟹s, hs⟩ have h : sᶜ.card = 1 := by rw [card_compl, hs, Fintype.card_fin, Nat.add_sub_cancel] obtain ⟹a, ha⟩ := card_eq_one.mp h exact ⟹a, Subtype.ext (compl_eq_comm.mp ha)⟩ rw [Function.comp_apply, Subtype.coe_mk, compl_singleton, piecewise_erase_univ, toFormalMultilinearSeries, dif_pos (Nat.add_sub_of_le Fintype.card_pos).symm] simp_rw [domDomCongr_apply, compContinuousLinearMap_apply, ContinuousLinearMap.proj_apply, Function.update_apply, (Equiv.injective _).eq_iff, ite_apply] congr; ext j obtain rfl | hj := eq_or_ne j i · rw [Function.update_same, if_pos rfl] · rw [Function.update_noteq hj, if_neg hj] protected theorem hasFDerivAt [DecidableEq ι] : HasFDerivAt f (f.linearDeriv x) x := by rw [← changeOrigin_toFormalMultilinearSeries] convert f.hasFiniteFPowerSeriesOnBall.hasFDerivAt (y := x) ENNReal.coe_lt_top rw [zero_add] /-- Technical lemma used in the proof of `hasFTaylorSeriesUpTo_iteratedFDeriv`, to compare sums over embedding of `Fin k` and `Fin (k + 1)`. -/ private lemma _root_.Equiv.succ_embeddingFinSucc_fst_symm_apply {ι : Type*} [DecidableEq ι] {n : ℕ} (e : Fin (n+1) ↪ ι) {k : ι} (h'k : k ∈ Set.range (Equiv.embeddingFinSucc n ι e).1) (hk : k ∈ Set.range e) : Fin.succ ((Equiv.embeddingFinSucc n ι e).1.toEquivRange.symm ⟹k, h'k⟩) = e.toEquivRange.symm ⟹k, hk⟩ := by rcases hk with ⟹j, rfl⟩ have hj : j ≠ 0 := by rintro rfl simp at h'k simp only [Function.Embedding.toEquivRange_symm_apply_self] have : e j = (Equiv.embeddingFinSucc n ι e).1 (Fin.pred j hj) := by simp simp_rw [this] simp [-Equiv.embeddingFinSucc_fst] /-- A continuous multilinear function `f` admits a Taylor series, whose successive terms are given by `f.iteratedFDeriv n`. This is the point of the definition of `f.iteratedFDeriv`. -/ theorem hasFTaylorSeriesUpTo_iteratedFDeriv : HasFTaylorSeriesUpTo ⊀ f (fun v n ↩ f.iteratedFDeriv n v) := by classical constructor · simp [ContinuousMultilinearMap.iteratedFDeriv] · rintro n - x suffices H : curryLeft (f.iteratedFDeriv (Nat.succ n) x) = (∑ e : Fin n ↪ ι, ((iteratedFDerivComponent f e.toEquivRange).linearDeriv (Pi.compRightL 𝕜 _ Subtype.val x)) ∘L (Pi.compRightL 𝕜 _ Subtype.val)) by have A : HasFDerivAt (f.iteratedFDeriv n) (∑ e : Fin n ↪ ι, ((iteratedFDerivComponent f e.toEquivRange).linearDeriv (Pi.compRightL 𝕜 _ Subtype.val x)) ∘L (Pi.compRightL 𝕜 _ Subtype.val)) x := by apply HasFDerivAt.sum (fun s _hs ↩ ?_) exact (ContinuousMultilinearMap.hasFDerivAt _ _).comp x (ContinuousLinearMap.hasFDerivAt _) rwa [← H] at A ext v m simp only [ContinuousMultilinearMap.iteratedFDeriv, curryLeft_apply, sum_apply, iteratedFDerivComponent_apply, Finset.univ_sigma_univ, Pi.compRightL_apply, ContinuousLinearMap.coe_sum', ContinuousLinearMap.coe_comp', Finset.sum_apply, Function.comp_apply, linearDeriv_apply, Finset.sum_sigma'] rw [← (Equiv.embeddingFinSucc n ι).sum_comp] congr with e congr with k by_cases hke : k ∈ Set.range e · simp only [hke, ↓reduceDIte] split_ifs with hkf · simp only [← Equiv.succ_embeddingFinSucc_fst_symm_apply e hkf hke, Fin.cons_succ] · obtain rfl : k = e 0 := by rcases hke with ⟹j, rfl⟩ simpa using hkf simp only [Function.Embedding.toEquivRange_symm_apply_self, Fin.cons_zero, Function.update, Pi.compRightL_apply] split_ifs with h · congr! · exfalso apply h simp_rw [← Equiv.embeddingFinSucc_snd e] · have hkf : k ∉ Set.range (Equiv.embeddingFinSucc n ι e).1 := by contrapose! hke rw [Equiv.embeddingFinSucc_fst] at hke exact Set.range_comp_subset_range _ _ hke simp only [hke, hkf, ↓reduceDIte, Pi.compRightL, ContinuousLinearMap.coe_mk', LinearMap.coe_mk, AddHom.coe_mk] rw [Function.update_noteq] contrapose! hke rw [show k = _ from Subtype.ext_iff_val.1 hke, Equiv.embeddingFinSucc_snd e] exact Set.mem_range_self _ · rintro n - apply continuous_finset_sum _ (fun e _ ↩ ?_) exact (ContinuousMultilinearMap.coe_continuous _).comp (ContinuousLinearMap.continuous _) theorem iteratedFDeriv_eq (n : ℕ) : iteratedFDeriv 𝕜 n f = f.iteratedFDeriv n := funext fun x ↩ (f.hasFTaylorSeriesUpTo_iteratedFDeriv.eq_iteratedFDeriv (m := n) le_top x).symm theorem norm_iteratedFDeriv_le (n : ℕ) (x : (i : ι) → E i) : ‖iteratedFDeriv 𝕜 n f x‖ ≀ Nat.descFactorial (Fintype.card ι) n * ‖f‖ * ‖x‖ ^ (Fintype.card ι - n) := by rw [f.iteratedFDeriv_eq] exact f.norm_iteratedFDeriv_le' n x lemma cPolynomialAt : CPolynomialAt 𝕜 f x := f.hasFiniteFPowerSeriesOnBall.cPolynomialAt_of_mem (by simp only [Metric.emetric_ball_top, Set.mem_univ]) lemma cPolyomialOn : CPolynomialOn 𝕜 f ⊀ := fun x _ ↩ f.cPolynomialAt x lemma contDiffAt : ContDiffAt 𝕜 n f x := (f.cPolynomialAt x).contDiffAt lemma contDiff : ContDiff 𝕜 n f := contDiff_iff_contDiffAt.mpr f.contDiffAt end ContinuousMultilinearMap namespace FormalMultilinearSeries variable (p : FormalMultilinearSeries 𝕜 E F) open Fintype ContinuousLinearMap in theorem derivSeries_apply_diag (n : ℕ) (x : E) : derivSeries p n (fun _ ↩ x) x = (n + 1) • p (n + 1) fun _ ↩ x := by simp only [derivSeries, compFormalMultilinearSeries_apply, changeOriginSeries, compContinuousMultilinearMap_coe, ContinuousLinearEquiv.coe_coe, LinearIsometryEquiv.coe_coe, Function.comp_apply, ContinuousMultilinearMap.sum_apply, map_sum, coe_sum', Finset.sum_apply, continuousMultilinearCurryFin1_apply, Matrix.zero_empty] convert Finset.sum_const _ · rw [Fin.snoc_zero, changeOriginSeriesTerm_apply, Finset.piecewise_same, add_comm] · rw [← card, card_subtype, ← Finset.powerset_univ, ← Finset.powersetCard_eq_filter, Finset.card_powersetCard, ← card, card_fin, eq_comm, add_comm, Nat.choose_succ_self_right] end FormalMultilinearSeries namespace HasFPowerSeriesOnBall open FormalMultilinearSeries ENNReal Nat variable {p : FormalMultilinearSeries 𝕜 E F} {f : E → F} {x : E} {r : ℝ≥0∞} (h : HasFPowerSeriesOnBall f p x r) (y : E) theorem iteratedFDeriv_zero_apply_diag : iteratedFDeriv 𝕜 0 f x = p 0 := by ext convert (h.hasSum <| EMetric.mem_ball_self h.r_pos).tsum_eq.symm · rw [iteratedFDeriv_zero_apply, add_zero] · rw [tsum_eq_single 0 fun n hn ↩ by haveI := NeZero.mk hn; exact (p n).map_zero] exact congr(p 0 $(Subsingleton.elim _ _)) open ContinuousLinearMap private theorem factorial_smul' {n : ℕ} : ∀ {F : Type max u v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F] {p : FormalMultilinearSeries 𝕜 E F} {f : E → F}, HasFPowerSeriesOnBall f p x r → n ! • p n (fun _ ↩ y) = iteratedFDeriv 𝕜 n f x (fun _ ↩ y) := by induction' n with n ih <;> intro F _ _ _ p f h · rw [factorial_zero, one_smul, h.iteratedFDeriv_zero_apply_diag] · rw [factorial_succ, mul_comm, mul_smul, ← derivSeries_apply_diag, ← smul_apply, ih h.fderiv, iteratedFDeriv_succ_apply_right] rfl variable [CompleteSpace F] theorem factorial_smul (n : ℕ) : n ! • p n (fun _ ↩ y) = iteratedFDeriv 𝕜 n f x (fun _ ↩ y) := by cases n · rw [factorial_zero, one_smul, h.iteratedFDeriv_zero_apply_diag] · rw [factorial_succ, mul_comm, mul_smul, ← derivSeries_apply_diag, ← smul_apply, factorial_smul' _ h.fderiv, iteratedFDeriv_succ_apply_right] rfl theorem hasSum_iteratedFDeriv [CharZero 𝕜] {y : E} (hy : y ∈ EMetric.ball 0 r) : HasSum (fun n ↩ (n ! : 𝕜)⁻¹ • iteratedFDeriv 𝕜 n f x fun _ ↩ y) (f (x + y)) := by convert h.hasSum hy with n rw [← h.factorial_smul y n, smul_comm, ← smul_assoc, nsmul_eq_mul, mul_inv_cancel <| cast_ne_zero.mpr n.factorial_ne_zero, one_smul] end HasFPowerSeriesOnBall
Analysis\Calculus\FDeriv\Basic.lean
/- 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 Mathlib.Analysis.Calculus.TangentCone import Mathlib.Analysis.NormedSpace.OperatorNorm.Asymptotics /-! # 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 `HasFDerivWithinAt f f' s x` says that `f` has derivative `f'` at `x`, where the domain of interest is restricted to `s`. We also have `HasFDerivAt f f' x := HasFDerivWithinAt f f' x univ` Finally, `HasStrictFDerivAt f f' x` means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability, i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse function theorem, and is defined here only to avoid proving theorems like `IsBoundedBilinearMap.hasFDerivAt` twice: first for `HasFDerivAt`, then for `HasStrictFDerivAt`. ## Main results In addition to the definition and basic properties of the derivative, the folder `Analysis/Calculus/FDeriv/` contains the usual formulas (and existence assertions) for the derivative of * constants * the identity * bounded linear maps (`Linear.lean`) * bounded bilinear maps (`Bilinear.lean`) * sum of two functions (`Add.lean`) * sum of finitely many functions (`Add.lean`) * multiplication of a function by a scalar constant (`Add.lean`) * negative of a function (`Add.lean`) * subtraction of two functions (`Add.lean`) * multiplication of a function by a scalar function (`Mul.lean`) * multiplication of two scalar functions (`Mul.lean`) * composition of functions (the chain rule) (`Comp.lean`) * inverse function (`Mul.lean`) (assuming that it exists; the inverse function theorem is in `../Inverse.lean`) 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 `HasDerivAt`'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. The simplifier is set up to prove automatically that some functions are differentiable, or differentiable at a point (but not differentiable on a set or within a set at a point, as checking automatically that the good domains are mapped one to the other when using composition is not something the simplifier can easily do). This means that one can write `example (x : ℝ) : Differentiable ℝ (fun x ↩ sin (exp (3 + x^2)) - 5 * cos x) := by simp`. If there are divisions, one needs to supply to the simplifier proofs that the denominators do not vanish, as in ```lean example (x : ℝ) (h : 1 + sin x ≠ 0) : DifferentiableAt ℝ (fun x ↩ exp x / (1 + sin x)) x := by simp [h] ``` Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be differentiable, in `Analysis.SpecialFunctions.Trigonometric`. The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general complicated multidimensional linear maps), but it will compute one-dimensional derivatives, see `Deriv.lean`. ## Implementation details The derivative is defined in terms of the `isLittleO` relation, but also characterized in terms of the `Tendsto` relation. We also introduce predicates `DifferentiableWithinAt 𝕜 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 `DifferentiableAt 𝕜 f x`, `DifferentiableOn 𝕜 f s` and `Differentiable 𝕜 f` to express the existence of a derivative. To be able to compute with derivatives, we write `fderivWithin 𝕜 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 `UniqueDiffWithinAt s x` and `UniqueDiffOn s`, defined in `TangentCone.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. To make sure that the simplifier can prove automatically that functions are differentiable, we tag many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable functions is differentiable, as well as their product, their cartesian product, and so on. A notable exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are differentiable, then their composition also is: `simp` would always be able to match this lemma, by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`), we add a lemma that if `f` is differentiable then so is `(fun x ↩ exp (f x))`. This means adding some boilerplate lemmas, but these can also be useful in their own right. Tests for this ability of the simplifier (with more examples) are provided in `Tests/Differentiable.lean`. ## Tags derivative, differentiable, Fréchet, calculus -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 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 `HasFDerivAt`), giving rise to the usual notion of Fréchet derivative, and for `L = 𝓝[s] x` (in `HasFDerivWithinAt`), giving rise to the notion of Fréchet derivative along the set `s`. -/ @[mk_iff hasFDerivAtFilter_iff_isLittleO] structure HasFDerivAtFilter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : Filter E) : Prop where of_isLittleO :: isLittleO : (fun x' => f x' - f x - f' (x' - x)) =o[L] fun x' => x' - x /-- 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`. -/ @[fun_prop] def HasFDerivWithinAt (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (x : E) := HasFDerivAtFilter f f' x (𝓝[s] x) /-- 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`. -/ @[fun_prop] def HasFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) := HasFDerivAtFilter f f' x (𝓝 x) /-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability* if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required, e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/ @[fun_prop] def HasStrictFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) := (fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] fun p : E × E => p.1 - p.2 variable (𝕜) /-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative there (possibly non-unique). -/ @[fun_prop] def DifferentiableWithinAt (f : E → F) (s : Set E) (x : E) := ∃ f' : E →L[𝕜] F, HasFDerivWithinAt f f' s x /-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly non-unique). -/ @[fun_prop] def DifferentiableAt (f : E → F) (x : E) := ∃ f' : E →L[𝕜] F, HasFDerivAt f f' x /-- If `f` has a derivative at `x` within `s`, then `fderivWithin 𝕜 f s x` is such a derivative. Otherwise, it is set to `0`. If `x` is isolated in `s`, we take the derivative within `s` to be zero for convenience. -/ irreducible_def fderivWithin (f : E → F) (s : Set E) (x : E) : E →L[𝕜] F := if 𝓝[s \ {x}] x = ⊥ then 0 else if h : ∃ f', HasFDerivWithinAt f f' s x then Classical.choose h else 0 /-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is set to `0`. -/ irreducible_def fderiv (f : E → F) (x : E) : E →L[𝕜] F := if h : ∃ f', HasFDerivAt f f' x then Classical.choose h else 0 /-- `DifferentiableOn 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/ @[fun_prop] def DifferentiableOn (f : E → F) (s : Set E) := ∀ x ∈ s, DifferentiableWithinAt 𝕜 f s x /-- `Differentiable 𝕜 f` means that `f` is differentiable at any point. -/ @[fun_prop] def Differentiable (f : E → F) := ∀ x, DifferentiableAt 𝕜 f x variable {𝕜} variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} theorem fderivWithin_zero_of_isolated (h : 𝓝[s \ {x}] x = ⊥) : fderivWithin 𝕜 f s x = 0 := by rw [fderivWithin, if_pos h] theorem fderivWithin_zero_of_nmem_closure (h : x ∉ closure s) : fderivWithin 𝕜 f s x = 0 := by apply fderivWithin_zero_of_isolated simp only [mem_closure_iff_nhdsWithin_neBot, neBot_iff, Ne, Classical.not_not] at h rw [eq_bot_iff, ← h] exact nhdsWithin_mono _ diff_subset theorem fderivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 f s x = 0 := by have : ¬∃ f', HasFDerivWithinAt f f' s x := h simp [fderivWithin, this] theorem fderiv_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : fderiv 𝕜 f x = 0 := by have : ¬∃ f', HasFDerivAt f f' x := h simp [fderiv, this] section DerivativeUniqueness /- In this section, we discuss the uniqueness of the derivative. We prove that the definitions `UniqueDiffWithinAt` and `UniqueDiffOn` 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 HasFDerivWithinAt.lim (h : HasFDerivWithinAt f f' s x) {α : Type*} (l : Filter α) {c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s) (clim : Tendsto (fun n => ‖c n‖) l atTop) (cdlim : Tendsto (fun n => c n • d n) l (𝓝 v)) : Tendsto (fun n => c n • (f (x + d n) - f x)) l (𝓝 (f' v)) := by have tendsto_arg : Tendsto (fun n => x + d n) l (𝓝[s] x) := by conv in 𝓝[s] x => rw [← add_zero x] rw [nhdsWithin, tendsto_inf] constructor · apply tendsto_const_nhds.add (tangentConeAt.lim_zero l clim cdlim) · rwa [tendsto_principal] have : (fun y => f y - f x - f' (y - x)) =o[𝓝[s] x] fun y => y - x := h.isLittleO have : (fun n => f (x + d n) - f x - f' (x + d n - x)) =o[l] fun n => x + d n - x := this.comp_tendsto tendsto_arg have : (fun n => f (x + d n) - f x - f' (d n)) =o[l] d := by simpa only [add_sub_cancel_left] have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun n => c n • d n := (isBigO_refl c l).smul_isLittleO this have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun _ => (1 : ℝ) := this.trans_isBigO (cdlim.isBigO_one ℝ) have L1 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) := (isLittleO_one_iff ℝ).1 this have L2 : Tendsto (fun n => f' (c n • d n)) l (𝓝 (f' v)) := Tendsto.comp f'.cont.continuousAt cdlim have L3 : Tendsto (fun 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 : (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) = fun n => c n • (f (x + d n) - f x) := by ext n simp [smul_add, smul_sub] rwa [this, zero_add] at L3 /-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the tangent cone to `s` at `x` -/ theorem HasFDerivWithinAt.unique_on (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt f f₁' s x) : EqOn f' f₁' (tangentConeAt 𝕜 s x) := fun _ ⟹_, _, dtop, clim, cdlim⟩ => tendsto_nhds_unique (hf.lim atTop dtop clim cdlim) (hg.lim atTop dtop clim cdlim) /-- `UniqueDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/ theorem UniqueDiffWithinAt.eq (H : UniqueDiffWithinAt 𝕜 s x) (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt f f₁' s x) : f' = f₁' := ContinuousLinearMap.ext_on H.1 (hf.unique_on hg) theorem UniqueDiffOn.eq (H : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h : HasFDerivWithinAt f f' s x) (h₁ : HasFDerivWithinAt f f₁' s x) : f' = f₁' := (H x hx).eq h h₁ end DerivativeUniqueness section FDerivProperties /-! ### Basic properties of the derivative -/ theorem hasFDerivAtFilter_iff_tendsto : HasFDerivAtFilter f f' x L ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) := by have h : ∀ x', ‖x' - x‖ = 0 → ‖f x' - f x - f' (x' - x)‖ = 0 := fun x' hx' => by rw [sub_eq_zero.1 (norm_eq_zero.1 hx')] simp rw [hasFDerivAtFilter_iff_isLittleO, ← isLittleO_norm_left, ← isLittleO_norm_right, isLittleO_iff_tendsto h] exact tendsto_congr fun _ => div_eq_inv_mul _ _ theorem hasFDerivWithinAt_iff_tendsto : HasFDerivWithinAt f f' s x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝[s] x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem hasFDerivAt_iff_tendsto : HasFDerivAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝 x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem hasFDerivAt_iff_isLittleO_nhds_zero : HasFDerivAt f f' x ↔ (fun h : E => f (x + h) - f x - f' h) =o[𝓝 0] fun h => h := by rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, ← map_add_left_nhds_zero x, isLittleO_map] simp [(· ∘ ·)] /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. This version only assumes that `‖f x - f x₀‖ ≀ C * ‖x - x₀‖` in a neighborhood of `x`. -/ theorem HasFDerivAt.le_of_lip' {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : HasFDerivAt f f' x₀) {C : ℝ} (hC₀ : 0 ≀ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≀ C * ‖x - x₀‖) : ‖f'‖ ≀ C := by refine le_of_forall_pos_le_add fun ε ε0 => opNorm_le_of_nhds_zero ?_ ?_ · exact add_nonneg hC₀ ε0.le rw [← map_add_left_nhds_zero x₀, eventually_map] at hlip filter_upwards [isLittleO_iff.1 (hasFDerivAt_iff_isLittleO_nhds_zero.1 hf) ε0, hlip] with y hy hyC rw [add_sub_cancel_left] at hyC calc ‖f' y‖ ≀ ‖f (x₀ + y) - f x₀‖ + ‖f (x₀ + y) - f x₀ - f' y‖ := norm_le_insert _ _ _ ≀ C * ‖y‖ + ε * ‖y‖ := add_le_add hyC hy _ = (C + ε) * ‖y‖ := (add_mul _ _ _).symm /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. -/ theorem HasFDerivAt.le_of_lipschitzOn {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : HasFDerivAt f f' x₀) {s : Set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖f'‖ ≀ C := by refine hf.le_of_lip' C.coe_nonneg ?_ filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs) /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz then its derivative at `x₀` has norm bounded by `C`. -/ theorem HasFDerivAt.le_of_lipschitz {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : HasFDerivAt f f' x₀) {C : ℝ≥0} (hlip : LipschitzWith C f) : ‖f'‖ ≀ C := hf.le_of_lipschitzOn univ_mem (lipschitzOnWith_univ.2 hlip) nonrec theorem HasFDerivAtFilter.mono (h : HasFDerivAtFilter f f' x L₂) (hst : L₁ ≀ L₂) : HasFDerivAtFilter f f' x L₁ := .of_isLittleO <| h.isLittleO.mono hst theorem HasFDerivWithinAt.mono_of_mem (h : HasFDerivWithinAt f f' t x) (hst : t ∈ 𝓝[s] x) : HasFDerivWithinAt f f' s x := h.mono <| nhdsWithin_le_iff.mpr hst nonrec theorem HasFDerivWithinAt.mono (h : HasFDerivWithinAt f f' t x) (hst : s ⊆ t) : HasFDerivWithinAt f f' s x := h.mono <| nhdsWithin_mono _ hst theorem HasFDerivAt.hasFDerivAtFilter (h : HasFDerivAt f f' x) (hL : L ≀ 𝓝 x) : HasFDerivAtFilter f f' x L := h.mono hL @[fun_prop] theorem HasFDerivAt.hasFDerivWithinAt (h : HasFDerivAt f f' x) : HasFDerivWithinAt f f' s x := h.hasFDerivAtFilter inf_le_left @[fun_prop] theorem HasFDerivWithinAt.differentiableWithinAt (h : HasFDerivWithinAt f f' s x) : DifferentiableWithinAt 𝕜 f s x := ⟹f', h⟩ @[fun_prop] theorem HasFDerivAt.differentiableAt (h : HasFDerivAt f f' x) : DifferentiableAt 𝕜 f x := ⟹f', h⟩ @[simp] theorem hasFDerivWithinAt_univ : HasFDerivWithinAt f f' univ x ↔ HasFDerivAt f f' x := by simp only [HasFDerivWithinAt, nhdsWithin_univ] rfl alias ⟹HasFDerivWithinAt.hasFDerivAt_of_univ, _⟩ := hasFDerivWithinAt_univ theorem hasFDerivWithinAt_of_mem_nhds (h : s ∈ 𝓝 x) : HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := by rw [HasFDerivAt, HasFDerivWithinAt, nhdsWithin_eq_nhds.mpr h] lemma hasFDerivWithinAt_of_isOpen (h : IsOpen s) (hx : x ∈ s) : HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := hasFDerivWithinAt_of_mem_nhds (h.mem_nhds hx) theorem hasFDerivWithinAt_insert {y : E} : HasFDerivWithinAt f f' (insert y s) x ↔ HasFDerivWithinAt f f' s x := by rcases eq_or_ne x y with (rfl | h) · simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO] apply Asymptotics.isLittleO_insert simp only [sub_self, map_zero] refine ⟹fun h => h.mono <| subset_insert y s, fun hf => hf.mono_of_mem ?_⟩ simp_rw [nhdsWithin_insert_of_ne h, self_mem_nhdsWithin] alias ⟹HasFDerivWithinAt.of_insert, HasFDerivWithinAt.insert'⟩ := hasFDerivWithinAt_insert protected theorem HasFDerivWithinAt.insert (h : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt g g' (insert x s) x := h.insert' theorem hasFDerivWithinAt_diff_singleton (y : E) : HasFDerivWithinAt f f' (s \ {y}) x ↔ HasFDerivWithinAt f f' s x := by rw [← hasFDerivWithinAt_insert, insert_diff_singleton, hasFDerivWithinAt_insert] theorem HasStrictFDerivAt.isBigO_sub (hf : HasStrictFDerivAt f f' x) : (fun p : E × E => f p.1 - f p.2) =O[𝓝 (x, x)] fun p : E × E => p.1 - p.2 := hf.isBigO.congr_of_sub.2 (f'.isBigO_comp _ _) theorem HasFDerivAtFilter.isBigO_sub (h : HasFDerivAtFilter f f' x L) : (fun x' => f x' - f x) =O[L] fun x' => x' - x := h.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_sub _ _) @[fun_prop] protected theorem HasStrictFDerivAt.hasFDerivAt (hf : HasStrictFDerivAt f f' x) : HasFDerivAt f f' x := by rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, isLittleO_iff] exact fun c hc => tendsto_id.prod_mk_nhds tendsto_const_nhds (isLittleO_iff.1 hf hc) protected theorem HasStrictFDerivAt.differentiableAt (hf : HasStrictFDerivAt f f' x) : DifferentiableAt 𝕜 f x := hf.hasFDerivAt.differentiableAt /-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ‖f'‖₊`, then `f` is `K`-Lipschitz in a neighborhood of `x`. -/ theorem HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt (hf : HasStrictFDerivAt f f' x) (K : ℝ≥0) (hK : ‖f'‖₊ < K) : ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := by have := hf.add_isBigOWith (f'.isBigOWith_comp _ _) hK simp only [sub_add_cancel, IsBigOWith] at this rcases exists_nhds_square this with ⟹U, Uo, xU, hU⟩ exact ⟹U, Uo.mem_nhds xU, lipschitzOnWith_iff_norm_sub_le.2 fun x hx y hy => hU (mk_mem_prod hx hy)⟩ /-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a neighborhood of `x`. See also `HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt` for a more precise statement. -/ theorem HasStrictFDerivAt.exists_lipschitzOnWith (hf : HasStrictFDerivAt f f' x) : ∃ K, ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := (exists_gt _).imp hf.exists_lipschitzOnWith_of_nnnorm_lt /-- Directional derivative agrees with `HasFDeriv`. -/ theorem HasFDerivAt.lim (hf : HasFDerivAt f f' x) (v : E) {α : Type*} {c : α → 𝕜} {l : Filter α} (hc : Tendsto (fun n => ‖c n‖) l atTop) : Tendsto (fun n => c n • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) := by refine (hasFDerivWithinAt_univ.2 hf).lim _ univ_mem hc ?_ intro U hU refine (eventually_ne_of_tendsto_norm_atTop hc (0 : 𝕜)).mono fun y hy => ?_ convert mem_of_mem_nhds hU dsimp only rw [← mul_smul, mul_inv_cancel hy, one_smul] theorem HasFDerivAt.unique (h₀ : HasFDerivAt f f₀' x) (h₁ : HasFDerivAt f f₁' x) : f₀' = f₁' := by rw [← hasFDerivWithinAt_univ] at h₀ h₁ exact uniqueDiffWithinAt_univ.eq h₀ h₁ theorem hasFDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) : HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by simp [HasFDerivWithinAt, nhdsWithin_restrict'' s h] theorem hasFDerivWithinAt_inter (h : t ∈ 𝓝 x) : HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by simp [HasFDerivWithinAt, nhdsWithin_restrict' s h] theorem HasFDerivWithinAt.union (hs : HasFDerivWithinAt f f' s x) (ht : HasFDerivWithinAt f f' t x) : HasFDerivWithinAt f f' (s ∪ t) x := by simp only [HasFDerivWithinAt, nhdsWithin_union] exact .of_isLittleO <| hs.isLittleO.sup ht.isLittleO theorem HasFDerivWithinAt.hasFDerivAt (h : HasFDerivWithinAt f f' s x) (hs : s ∈ 𝓝 x) : HasFDerivAt f f' x := by rwa [← univ_inter s, hasFDerivWithinAt_inter hs, hasFDerivWithinAt_univ] at h theorem DifferentiableWithinAt.differentiableAt (h : DifferentiableWithinAt 𝕜 f s x) (hs : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := h.imp fun _ hf' => hf'.hasFDerivAt hs /-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ theorem HasFDerivWithinAt.of_nhdsWithin_eq_bot (h : 𝓝[s\{x}] x = ⊥) : HasFDerivWithinAt f f' s x := by rw [← hasFDerivWithinAt_diff_singleton x, HasFDerivWithinAt, h, hasFDerivAtFilter_iff_isLittleO] apply isLittleO_bot /-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ theorem hasFDerivWithinAt_of_nmem_closure (h : x ∉ closure s) : HasFDerivWithinAt f f' s x := .of_nhdsWithin_eq_bot <| eq_bot_mono (nhdsWithin_mono _ diff_subset) <| by rwa [mem_closure_iff_nhdsWithin_neBot, not_neBot] at h theorem DifferentiableWithinAt.hasFDerivWithinAt (h : DifferentiableWithinAt 𝕜 f s x) : HasFDerivWithinAt f (fderivWithin 𝕜 f s x) s x := by by_cases H : 𝓝[s \ {x}] x = ⊥ · exact .of_nhdsWithin_eq_bot H · unfold DifferentiableWithinAt at h rw [fderivWithin, if_neg H, dif_pos h] exact Classical.choose_spec h theorem DifferentiableAt.hasFDerivAt (h : DifferentiableAt 𝕜 f x) : HasFDerivAt f (fderiv 𝕜 f x) x := by dsimp only [DifferentiableAt] at h rw [fderiv, dif_pos h] exact Classical.choose_spec h theorem DifferentiableOn.hasFDerivAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : HasFDerivAt f (fderiv 𝕜 f x) x := ((h x (mem_of_mem_nhds hs)).differentiableAt hs).hasFDerivAt theorem DifferentiableOn.differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := (h.hasFDerivAt hs).differentiableAt theorem DifferentiableOn.eventually_differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : ∀ᶠ y in 𝓝 x, DifferentiableAt 𝕜 f y := (eventually_eventually_nhds.2 hs).mono fun _ => h.differentiableAt protected theorem HasFDerivAt.fderiv (h : HasFDerivAt f f' x) : fderiv 𝕜 f x = f' := by ext rw [h.unique h.differentiableAt.hasFDerivAt] theorem fderiv_eq {f' : E → E →L[𝕜] F} (h : ∀ x, HasFDerivAt f (f' x) x) : fderiv 𝕜 f = f' := funext fun x => (h x).fderiv variable (𝕜) /-- Converse to the mean value inequality: if `f` is `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. This version only assumes that `‖f x - f x₀‖ ≀ C * ‖x - x₀‖` in a neighborhood of `x`. -/ theorem norm_fderiv_le_of_lip' {f : E → F} {x₀ : E} {C : ℝ} (hC₀ : 0 ≀ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≀ C * ‖x - x₀‖) : ‖fderiv 𝕜 f x₀‖ ≀ C := by by_cases hf : DifferentiableAt 𝕜 f x₀ · exact hf.hasFDerivAt.le_of_lip' hC₀ hlip · rw [fderiv_zero_of_not_differentiableAt hf] simp [hC₀] /-- Converse to the mean value inequality: if `f` is `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. Version using `fderiv`. -/ -- Porting note: renamed so that dot-notation makes sense theorem norm_fderiv_le_of_lipschitzOn {f : E → F} {x₀ : E} {s : Set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖fderiv 𝕜 f x₀‖ ≀ C := by refine norm_fderiv_le_of_lip' 𝕜 C.coe_nonneg ?_ filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs) /-- Converse to the mean value inequality: if `f` is `C`-lipschitz then its derivative at `x₀` has norm bounded by `C`. Version using `fderiv`. -/ theorem norm_fderiv_le_of_lipschitz {f : E → F} {x₀ : E} {C : ℝ≥0} (hlip : LipschitzWith C f) : ‖fderiv 𝕜 f x₀‖ ≀ C := norm_fderiv_le_of_lipschitzOn 𝕜 univ_mem (lipschitzOnWith_univ.2 hlip) variable {𝕜} protected theorem HasFDerivWithinAt.fderivWithin (h : HasFDerivWithinAt f f' s x) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = f' := (hxs.eq h h.differentiableWithinAt.hasFDerivWithinAt).symm theorem DifferentiableWithinAt.mono (h : DifferentiableWithinAt 𝕜 f t x) (st : s ⊆ t) : DifferentiableWithinAt 𝕜 f s x := by rcases h with ⟹f', hf'⟩ exact ⟹f', hf'.mono st⟩ theorem DifferentiableWithinAt.mono_of_mem (h : DifferentiableWithinAt 𝕜 f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) : DifferentiableWithinAt 𝕜 f t x := (h.hasFDerivWithinAt.mono_of_mem hst).differentiableWithinAt theorem differentiableWithinAt_univ : DifferentiableWithinAt 𝕜 f univ x ↔ DifferentiableAt 𝕜 f x := by simp only [DifferentiableWithinAt, hasFDerivWithinAt_univ, DifferentiableAt] theorem differentiableWithinAt_inter (ht : t ∈ 𝓝 x) : DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter ht] theorem differentiableWithinAt_inter' (ht : t ∈ 𝓝[s] x) : DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter' ht] theorem DifferentiableAt.differentiableWithinAt (h : DifferentiableAt 𝕜 f x) : DifferentiableWithinAt 𝕜 f s x := (differentiableWithinAt_univ.2 h).mono (subset_univ _) @[fun_prop] theorem Differentiable.differentiableAt (h : Differentiable 𝕜 f) : DifferentiableAt 𝕜 f x := h x protected theorem DifferentiableAt.fderivWithin (h : DifferentiableAt 𝕜 f x) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x := h.hasFDerivAt.hasFDerivWithinAt.fderivWithin hxs theorem DifferentiableOn.mono (h : DifferentiableOn 𝕜 f t) (st : s ⊆ t) : DifferentiableOn 𝕜 f s := fun x hx => (h x (st hx)).mono st theorem differentiableOn_univ : DifferentiableOn 𝕜 f univ ↔ Differentiable 𝕜 f := by simp only [DifferentiableOn, Differentiable, differentiableWithinAt_univ, mem_univ, forall_true_left] @[fun_prop] theorem Differentiable.differentiableOn (h : Differentiable 𝕜 f) : DifferentiableOn 𝕜 f s := (differentiableOn_univ.2 h).mono (subset_univ _) theorem differentiableOn_of_locally_differentiableOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ DifferentiableOn 𝕜 f (s ∩ u)) : DifferentiableOn 𝕜 f s := by intro x xs rcases h x xs with ⟹t, t_open, xt, ht⟩ exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 (ht x ⟹xs, xt⟩) theorem fderivWithin_of_mem (st : t ∈ 𝓝[s] x) (ht : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f t x) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x := ((DifferentiableWithinAt.hasFDerivWithinAt h).mono_of_mem st).fderivWithin ht theorem fderivWithin_subset (st : s ⊆ t) (ht : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f t x) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x := fderivWithin_of_mem (nhdsWithin_mono _ st self_mem_nhdsWithin) ht h theorem fderivWithin_inter (ht : t ∈ 𝓝 x) : fderivWithin 𝕜 f (s ∩ t) x = fderivWithin 𝕜 f s x := by have A : 𝓝[(s ∩ t) \ {x}] x = 𝓝[s \ {x}] x := by have : (s ∩ t) \ {x} = (s \ {x}) ∩ t := by rw [inter_comm, inter_diff_assoc, inter_comm] rw [this, ← nhdsWithin_restrict' _ ht] simp [fderivWithin, A, hasFDerivWithinAt_inter ht] @[simp] theorem fderivWithin_univ : fderivWithin 𝕜 f univ = fderiv 𝕜 f := by ext1 x nontriviality E have H : 𝓝[univ \ {x}] x ≠ ⊥ := by rw [← compl_eq_univ_diff, ← neBot_iff] exact Module.punctured_nhds_neBot 𝕜 E x simp [fderivWithin, fderiv, H] theorem fderivWithin_of_mem_nhds (h : s ∈ 𝓝 x) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x := by rw [← fderivWithin_univ, ← univ_inter s, fderivWithin_inter h] theorem fderivWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x := fderivWithin_of_mem_nhds (hs.mem_nhds hx) theorem fderivWithin_eq_fderiv (hs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableAt 𝕜 f x) : fderivWithin 𝕜 f s x = fderiv 𝕜 f x := by rw [← fderivWithin_univ] exact fderivWithin_subset (subset_univ _) hs h.differentiableWithinAt theorem fderiv_mem_iff {f : E → F} {s : Set (E →L[𝕜] F)} {x : E} : fderiv 𝕜 f x ∈ s ↔ DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ s √ ¬DifferentiableAt 𝕜 f x ∧ (0 : E →L[𝕜] F) ∈ s := by by_cases hx : DifferentiableAt 𝕜 f x <;> simp [fderiv_zero_of_not_differentiableAt, *] theorem fderivWithin_mem_iff {f : E → F} {t : Set E} {s : Set (E →L[𝕜] F)} {x : E} : fderivWithin 𝕜 f t x ∈ s ↔ DifferentiableWithinAt 𝕜 f t x ∧ fderivWithin 𝕜 f t x ∈ s √ ¬DifferentiableWithinAt 𝕜 f t x ∧ (0 : E →L[𝕜] F) ∈ s := by by_cases hx : DifferentiableWithinAt 𝕜 f t x <;> simp [fderivWithin_zero_of_not_differentiableWithinAt, *] theorem Asymptotics.IsBigO.hasFDerivWithinAt {s : Set E} {x₀ : E} {n : ℕ} (h : f =O[𝓝[s] x₀] fun x => ‖x - x₀‖ ^ n) (hx₀ : x₀ ∈ s) (hn : 1 < n) : HasFDerivWithinAt f (0 : E →L[𝕜] F) s x₀ := by simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO, h.eq_zero_of_norm_pow_within hx₀ hn.ne_bot, zero_apply, sub_zero, h.trans_isLittleO ((isLittleO_pow_sub_sub x₀ hn).mono nhdsWithin_le_nhds)] theorem Asymptotics.IsBigO.hasFDerivAt {x₀ : E} {n : ℕ} (h : f =O[𝓝 x₀] fun x => ‖x - x₀‖ ^ n) (hn : 1 < n) : HasFDerivAt f (0 : E →L[𝕜] F) x₀ := by rw [← nhdsWithin_univ] at h exact (h.hasFDerivWithinAt (mem_univ _) hn).hasFDerivAt_of_univ nonrec theorem HasFDerivWithinAt.isBigO_sub {f : E → F} {s : Set E} {x₀ : E} {f' : E →L[𝕜] F} (h : HasFDerivWithinAt f f' s x₀) : (f · - f x₀) =O[𝓝[s] x₀] (· - x₀) := h.isBigO_sub lemma DifferentiableWithinAt.isBigO_sub {f : E → F} {s : Set E} {x₀ : E} (h : DifferentiableWithinAt 𝕜 f s x₀) : (f · - f x₀) =O[𝓝[s] x₀] (· - x₀) := h.hasFDerivWithinAt.isBigO_sub nonrec theorem HasFDerivAt.isBigO_sub {f : E → F} {x₀ : E} {f' : E →L[𝕜] F} (h : HasFDerivAt f f' x₀) : (f · - f x₀) =O[𝓝 x₀] (· - x₀) := h.isBigO_sub nonrec theorem DifferentiableAt.isBigO_sub {f : E → F} {x₀ : E} (h : DifferentiableAt 𝕜 f x₀) : (f · - f x₀) =O[𝓝 x₀] (· - x₀) := h.hasFDerivAt.isBigO_sub end FDerivProperties section Continuous /-! ### Deducing continuity from differentiability -/ theorem HasFDerivAtFilter.tendsto_nhds (hL : L ≀ 𝓝 x) (h : HasFDerivAtFilter f f' x L) : Tendsto f L (𝓝 (f x)) := by have : Tendsto (fun x' => f x' - f x) L (𝓝 0) := by refine h.isBigO_sub.trans_tendsto (Tendsto.mono_left ?_ hL) rw [← sub_self x] exact tendsto_id.sub tendsto_const_nhds have := this.add (tendsto_const_nhds (x := f x)) rw [zero_add (f x)] at this exact this.congr (by simp only [sub_add_cancel, eq_self_iff_true, forall_const]) theorem HasFDerivWithinAt.continuousWithinAt (h : HasFDerivWithinAt f f' s x) : ContinuousWithinAt f s x := HasFDerivAtFilter.tendsto_nhds inf_le_left h theorem HasFDerivAt.continuousAt (h : HasFDerivAt f f' x) : ContinuousAt f x := HasFDerivAtFilter.tendsto_nhds le_rfl h @[fun_prop] theorem DifferentiableWithinAt.continuousWithinAt (h : DifferentiableWithinAt 𝕜 f s x) : ContinuousWithinAt f s x := let ⟹_, hf'⟩ := h hf'.continuousWithinAt @[fun_prop] theorem DifferentiableAt.continuousAt (h : DifferentiableAt 𝕜 f x) : ContinuousAt f x := let ⟹_, hf'⟩ := h hf'.continuousAt @[fun_prop] theorem DifferentiableOn.continuousOn (h : DifferentiableOn 𝕜 f s) : ContinuousOn f s := fun x hx => (h x hx).continuousWithinAt @[fun_prop] theorem Differentiable.continuous (h : Differentiable 𝕜 f) : Continuous f := continuous_iff_continuousAt.2 fun x => (h x).continuousAt protected theorem HasStrictFDerivAt.continuousAt (hf : HasStrictFDerivAt f f' x) : ContinuousAt f x := hf.hasFDerivAt.continuousAt theorem HasStrictFDerivAt.isBigO_sub_rev {f' : E ≃L[𝕜] F} (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) x) : (fun p : E × E => p.1 - p.2) =O[𝓝 (x, x)] fun p : E × E => f p.1 - f p.2 := ((f'.isBigO_comp_rev _ _).trans (hf.trans_isBigO (f'.isBigO_comp_rev _ _)).right_isBigO_add).congr (fun _ => rfl) fun _ => sub_add_cancel _ _ theorem HasFDerivAtFilter.isBigO_sub_rev (hf : HasFDerivAtFilter f f' x L) {C} (hf' : AntilipschitzWith C f') : (fun x' => x' - x) =O[L] fun x' => f x' - f x := have : (fun x' => x' - x) =O[L] fun x' => f' (x' - x) := isBigO_iff.2 ⟹C, eventually_of_forall fun _ => ZeroHomClass.bound_of_antilipschitz f' hf' _⟩ (this.trans (hf.isLittleO.trans_isBigO this).right_isBigO_add).congr (fun _ => rfl) fun _ => sub_add_cancel _ _ end Continuous section congr /-! ### congr properties of the derivative -/ theorem hasFDerivWithinAt_congr_set' (y : E) (h : s =á¶ [𝓝[{y}ᶜ] x] t) : HasFDerivWithinAt f f' s x ↔ HasFDerivWithinAt f f' t x := calc HasFDerivWithinAt f f' s x ↔ HasFDerivWithinAt f f' (s \ {y}) x := (hasFDerivWithinAt_diff_singleton _).symm _ ↔ HasFDerivWithinAt f f' (t \ {y}) x := by suffices 𝓝[s \ {y}] x = 𝓝[t \ {y}] x by simp only [HasFDerivWithinAt, this] simpa only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter', diff_eq, inter_comm] using h _ ↔ HasFDerivWithinAt f f' t x := hasFDerivWithinAt_diff_singleton _ theorem hasFDerivWithinAt_congr_set (h : s =á¶ [𝓝 x] t) : HasFDerivWithinAt f f' s x ↔ HasFDerivWithinAt f f' t x := hasFDerivWithinAt_congr_set' x <| h.filter_mono inf_le_left theorem differentiableWithinAt_congr_set' (y : E) (h : s =á¶ [𝓝[{y}ᶜ] x] t) : DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x := exists_congr fun _ => hasFDerivWithinAt_congr_set' _ h theorem differentiableWithinAt_congr_set (h : s =á¶ [𝓝 x] t) : DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x := exists_congr fun _ => hasFDerivWithinAt_congr_set h theorem fderivWithin_congr_set' (y : E) (h : s =á¶ [𝓝[{y}ᶜ] x] t) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x := by have : s =á¶ [𝓝[{x}ᶜ] x] t := nhdsWithin_compl_singleton_le x y h have : 𝓝[s \ {x}] x = 𝓝[t \ {x}] x := by simpa only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter', diff_eq, inter_comm] using this simp only [fderivWithin, hasFDerivWithinAt_congr_set' y h, this] theorem fderivWithin_congr_set (h : s =á¶ [𝓝 x] t) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x := fderivWithin_congr_set' x <| h.filter_mono inf_le_left theorem fderivWithin_eventually_congr_set' (y : E) (h : s =á¶ [𝓝[{y}ᶜ] x] t) : fderivWithin 𝕜 f s =á¶ [𝓝 x] fderivWithin 𝕜 f t := (eventually_nhds_nhdsWithin.2 h).mono fun _ => fderivWithin_congr_set' y theorem fderivWithin_eventually_congr_set (h : s =á¶ [𝓝 x] t) : fderivWithin 𝕜 f s =á¶ [𝓝 x] fderivWithin 𝕜 f t := fderivWithin_eventually_congr_set' x <| h.filter_mono inf_le_left theorem Filter.EventuallyEq.hasStrictFDerivAt_iff (h : f₀ =á¶ [𝓝 x] f₁) (h' : ∀ y, f₀' y = f₁' y) : HasStrictFDerivAt f₀ f₀' x ↔ HasStrictFDerivAt f₁ f₁' x := by refine isLittleO_congr ((h.prod_mk_nhds h).mono ?_) .rfl rintro p ⟹hp₁, hp₂⟩ simp only [*] theorem HasStrictFDerivAt.congr_fderiv (h : HasStrictFDerivAt f f' x) (h' : f' = g') : HasStrictFDerivAt f g' x := h' ▾ h theorem HasFDerivAt.congr_fderiv (h : HasFDerivAt f f' x) (h' : f' = g') : HasFDerivAt f g' x := h' ▾ h theorem HasFDerivWithinAt.congr_fderiv (h : HasFDerivWithinAt f f' s x) (h' : f' = g') : HasFDerivWithinAt f g' s x := h' ▾ h theorem HasStrictFDerivAt.congr_of_eventuallyEq (h : HasStrictFDerivAt f f' x) (h₁ : f =á¶ [𝓝 x] f₁) : HasStrictFDerivAt f₁ f' x := (h₁.hasStrictFDerivAt_iff fun _ => rfl).1 h theorem Filter.EventuallyEq.hasFDerivAtFilter_iff (h₀ : f₀ =á¶ [L] f₁) (hx : f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) : HasFDerivAtFilter f₀ f₀' x L ↔ HasFDerivAtFilter f₁ f₁' x L := by simp only [hasFDerivAtFilter_iff_isLittleO] exact isLittleO_congr (h₀.mono fun y hy => by simp only [hy, h₁, hx]) .rfl theorem HasFDerivAtFilter.congr_of_eventuallyEq (h : HasFDerivAtFilter f f' x L) (hL : f₁ =á¶ [L] f) (hx : f₁ x = f x) : HasFDerivAtFilter f₁ f' x L := (hL.hasFDerivAtFilter_iff hx fun _ => rfl).2 h theorem Filter.EventuallyEq.hasFDerivAt_iff (h : f₀ =á¶ [𝓝 x] f₁) : HasFDerivAt f₀ f' x ↔ HasFDerivAt f₁ f' x := h.hasFDerivAtFilter_iff h.eq_of_nhds fun _ => _root_.rfl theorem Filter.EventuallyEq.differentiableAt_iff (h : f₀ =á¶ [𝓝 x] f₁) : DifferentiableAt 𝕜 f₀ x ↔ DifferentiableAt 𝕜 f₁ x := exists_congr fun _ => h.hasFDerivAt_iff theorem Filter.EventuallyEq.hasFDerivWithinAt_iff (h : f₀ =á¶ [𝓝[s] x] f₁) (hx : f₀ x = f₁ x) : HasFDerivWithinAt f₀ f' s x ↔ HasFDerivWithinAt f₁ f' s x := h.hasFDerivAtFilter_iff hx fun _ => _root_.rfl theorem Filter.EventuallyEq.hasFDerivWithinAt_iff_of_mem (h : f₀ =á¶ [𝓝[s] x] f₁) (hx : x ∈ s) : HasFDerivWithinAt f₀ f' s x ↔ HasFDerivWithinAt f₁ f' s x := h.hasFDerivWithinAt_iff (h.eq_of_nhdsWithin hx) theorem Filter.EventuallyEq.differentiableWithinAt_iff (h : f₀ =á¶ [𝓝[s] x] f₁) (hx : f₀ x = f₁ x) : DifferentiableWithinAt 𝕜 f₀ s x ↔ DifferentiableWithinAt 𝕜 f₁ s x := exists_congr fun _ => h.hasFDerivWithinAt_iff hx theorem Filter.EventuallyEq.differentiableWithinAt_iff_of_mem (h : f₀ =á¶ [𝓝[s] x] f₁) (hx : x ∈ s) : DifferentiableWithinAt 𝕜 f₀ s x ↔ DifferentiableWithinAt 𝕜 f₁ s x := h.differentiableWithinAt_iff (h.eq_of_nhdsWithin hx) theorem HasFDerivWithinAt.congr_mono (h : HasFDerivWithinAt f f' s x) (ht : EqOn f₁ f t) (hx : f₁ x = f x) (h₁ : t ⊆ s) : HasFDerivWithinAt f₁ f' t x := HasFDerivAtFilter.congr_of_eventuallyEq (h.mono h₁) (Filter.mem_inf_of_right ht) hx theorem HasFDerivWithinAt.congr (h : HasFDerivWithinAt f f' s x) (hs : EqOn f₁ f s) (hx : f₁ x = f x) : HasFDerivWithinAt f₁ f' s x := h.congr_mono hs hx (Subset.refl _) theorem HasFDerivWithinAt.congr' (h : HasFDerivWithinAt f f' s x) (hs : EqOn f₁ f s) (hx : x ∈ s) : HasFDerivWithinAt f₁ f' s x := h.congr hs (hs hx) theorem HasFDerivWithinAt.congr_of_eventuallyEq (h : HasFDerivWithinAt f f' s x) (h₁ : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) : HasFDerivWithinAt f₁ f' s x := HasFDerivAtFilter.congr_of_eventuallyEq h h₁ hx theorem HasFDerivAt.congr_of_eventuallyEq (h : HasFDerivAt f f' x) (h₁ : f₁ =á¶ [𝓝 x] f) : HasFDerivAt f₁ f' x := HasFDerivAtFilter.congr_of_eventuallyEq h h₁ (mem_of_mem_nhds h₁ : _) theorem DifferentiableWithinAt.congr_mono (h : DifferentiableWithinAt 𝕜 f s x) (ht : EqOn f₁ f t) (hx : f₁ x = f x) (h₁ : t ⊆ s) : DifferentiableWithinAt 𝕜 f₁ t x := (HasFDerivWithinAt.congr_mono h.hasFDerivWithinAt ht hx h₁).differentiableWithinAt theorem DifferentiableWithinAt.congr (h : DifferentiableWithinAt 𝕜 f s x) (ht : ∀ x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : DifferentiableWithinAt 𝕜 f₁ s x := DifferentiableWithinAt.congr_mono h ht hx (Subset.refl _) theorem DifferentiableWithinAt.congr_of_eventuallyEq (h : DifferentiableWithinAt 𝕜 f s x) (h₁ : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) : DifferentiableWithinAt 𝕜 f₁ s x := (h.hasFDerivWithinAt.congr_of_eventuallyEq h₁ hx).differentiableWithinAt theorem DifferentiableOn.congr_mono (h : DifferentiableOn 𝕜 f s) (h' : ∀ x ∈ t, f₁ x = f x) (h₁ : t ⊆ s) : DifferentiableOn 𝕜 f₁ t := fun x hx => (h x (h₁ hx)).congr_mono h' (h' x hx) h₁ theorem DifferentiableOn.congr (h : DifferentiableOn 𝕜 f s) (h' : ∀ x ∈ s, f₁ x = f x) : DifferentiableOn 𝕜 f₁ s := fun x hx => (h x hx).congr h' (h' x hx) theorem differentiableOn_congr (h' : ∀ x ∈ s, f₁ x = f x) : DifferentiableOn 𝕜 f₁ s ↔ DifferentiableOn 𝕜 f s := ⟹fun h => DifferentiableOn.congr h fun y hy => (h' y hy).symm, fun h => DifferentiableOn.congr h h'⟩ theorem DifferentiableAt.congr_of_eventuallyEq (h : DifferentiableAt 𝕜 f x) (hL : f₁ =á¶ [𝓝 x] f) : DifferentiableAt 𝕜 f₁ x := hL.differentiableAt_iff.2 h theorem DifferentiableWithinAt.fderivWithin_congr_mono (h : DifferentiableWithinAt 𝕜 f s x) (hs : EqOn f₁ f t) (hx : f₁ x = f x) (hxt : UniqueDiffWithinAt 𝕜 t x) (h₁ : t ⊆ s) : fderivWithin 𝕜 f₁ t x = fderivWithin 𝕜 f s x := (HasFDerivWithinAt.congr_mono h.hasFDerivWithinAt hs hx h₁).fderivWithin hxt theorem Filter.EventuallyEq.fderivWithin_eq (hs : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) : fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := by simp only [fderivWithin, hs.hasFDerivWithinAt_iff hx] theorem Filter.EventuallyEq.fderivWithin' (hs : f₁ =á¶ [𝓝[s] x] f) (ht : t ⊆ s) : fderivWithin 𝕜 f₁ t =á¶ [𝓝[s] x] fderivWithin 𝕜 f t := (eventually_nhdsWithin_nhdsWithin.2 hs).mp <| eventually_mem_nhdsWithin.mono fun _y hys hs => EventuallyEq.fderivWithin_eq (hs.filter_mono <| nhdsWithin_mono _ ht) (hs.self_of_nhdsWithin hys) protected theorem Filter.EventuallyEq.fderivWithin (hs : f₁ =á¶ [𝓝[s] x] f) : fderivWithin 𝕜 f₁ s =á¶ [𝓝[s] x] fderivWithin 𝕜 f s := hs.fderivWithin' Subset.rfl theorem Filter.EventuallyEq.fderivWithin_eq_nhds (h : f₁ =á¶ [𝓝 x] f) : fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := (h.filter_mono nhdsWithin_le_nhds).fderivWithin_eq h.self_of_nhds theorem fderivWithin_congr (hs : EqOn f₁ f s) (hx : f₁ x = f x) : fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := (hs.eventuallyEq.filter_mono inf_le_right).fderivWithin_eq hx theorem fderivWithin_congr' (hs : EqOn f₁ f s) (hx : x ∈ s) : fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := fderivWithin_congr hs (hs hx) theorem Filter.EventuallyEq.fderiv_eq (h : f₁ =á¶ [𝓝 x] f) : fderiv 𝕜 f₁ x = fderiv 𝕜 f x := by rw [← fderivWithin_univ, ← fderivWithin_univ, h.fderivWithin_eq_nhds] protected theorem Filter.EventuallyEq.fderiv (h : f₁ =á¶ [𝓝 x] f) : fderiv 𝕜 f₁ =á¶ [𝓝 x] fderiv 𝕜 f := h.eventuallyEq_nhds.mono fun _ h => h.fderiv_eq end congr section id /-! ### Derivative of the identity -/ @[fun_prop] theorem hasStrictFDerivAt_id (x : E) : HasStrictFDerivAt id (id 𝕜 E) x := (isLittleO_zero _ _).congr_left <| by simp theorem hasFDerivAtFilter_id (x : E) (L : Filter E) : HasFDerivAtFilter id (id 𝕜 E) x L := .of_isLittleO <| (isLittleO_zero _ _).congr_left <| by simp @[fun_prop] theorem hasFDerivWithinAt_id (x : E) (s : Set E) : HasFDerivWithinAt id (id 𝕜 E) s x := hasFDerivAtFilter_id _ _ @[fun_prop] theorem hasFDerivAt_id (x : E) : HasFDerivAt id (id 𝕜 E) x := hasFDerivAtFilter_id _ _ @[simp, fun_prop] theorem differentiableAt_id : DifferentiableAt 𝕜 id x := (hasFDerivAt_id x).differentiableAt @[simp] theorem differentiableAt_id' : DifferentiableAt 𝕜 (fun x => x) x := (hasFDerivAt_id x).differentiableAt @[fun_prop] theorem differentiableWithinAt_id : DifferentiableWithinAt 𝕜 id s x := differentiableAt_id.differentiableWithinAt @[simp, fun_prop] theorem differentiable_id : Differentiable 𝕜 (id : E → E) := fun _ => differentiableAt_id @[simp] theorem differentiable_id' : Differentiable 𝕜 fun x : E => x := fun _ => differentiableAt_id @[fun_prop] theorem differentiableOn_id : DifferentiableOn 𝕜 id s := differentiable_id.differentiableOn @[simp] theorem fderiv_id : fderiv 𝕜 id x = id 𝕜 E := HasFDerivAt.fderiv (hasFDerivAt_id x) @[simp] theorem fderiv_id' : fderiv 𝕜 (fun x : E => x) x = ContinuousLinearMap.id 𝕜 E := fderiv_id theorem fderivWithin_id (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 id s x = id 𝕜 E := by rw [DifferentiableAt.fderivWithin differentiableAt_id hxs] exact fderiv_id theorem fderivWithin_id' (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x : E => x) s x = ContinuousLinearMap.id 𝕜 E := fderivWithin_id hxs end id section Const /-! ### Derivative of a constant function -/ @[fun_prop] theorem hasStrictFDerivAt_const (c : F) (x : E) : HasStrictFDerivAt (fun _ => c) (0 : E →L[𝕜] F) x := (isLittleO_zero _ _).congr_left fun _ => by simp only [zero_apply, sub_self] theorem hasFDerivAtFilter_const (c : F) (x : E) (L : Filter E) : HasFDerivAtFilter (fun _ => c) (0 : E →L[𝕜] F) x L := .of_isLittleO <| (isLittleO_zero _ _).congr_left fun _ => by simp only [zero_apply, sub_self] @[fun_prop] theorem hasFDerivWithinAt_const (c : F) (x : E) (s : Set E) : HasFDerivWithinAt (fun _ => c) (0 : E →L[𝕜] F) s x := hasFDerivAtFilter_const _ _ _ @[fun_prop] theorem hasFDerivAt_const (c : F) (x : E) : HasFDerivAt (fun _ => c) (0 : E →L[𝕜] F) x := hasFDerivAtFilter_const _ _ _ @[simp, fun_prop] theorem differentiableAt_const (c : F) : DifferentiableAt 𝕜 (fun _ => c) x := ⟹0, hasFDerivAt_const c x⟩ @[fun_prop] theorem differentiableWithinAt_const (c : F) : DifferentiableWithinAt 𝕜 (fun _ => c) s x := DifferentiableAt.differentiableWithinAt (differentiableAt_const _) theorem fderiv_const_apply (c : F) : fderiv 𝕜 (fun _ => c) x = 0 := HasFDerivAt.fderiv (hasFDerivAt_const c x) @[simp] theorem fderiv_const (c : F) : (fderiv 𝕜 fun _ : E => c) = 0 := by ext m rw [fderiv_const_apply] rfl theorem fderivWithin_const_apply (c : F) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun _ => c) s x = 0 := by rw [DifferentiableAt.fderivWithin (differentiableAt_const _) hxs] exact fderiv_const_apply _ @[simp, fun_prop] theorem differentiable_const (c : F) : Differentiable 𝕜 fun _ : E => c := fun _ => differentiableAt_const _ @[simp, fun_prop] theorem differentiableOn_const (c : F) : DifferentiableOn 𝕜 (fun _ => c) s := (differentiable_const _).differentiableOn @[fun_prop] theorem hasFDerivWithinAt_singleton (f : E → F) (x : E) : HasFDerivWithinAt f (0 : E →L[𝕜] F) {x} x := by simp only [HasFDerivWithinAt, nhdsWithin_singleton, hasFDerivAtFilter_iff_isLittleO, isLittleO_pure, ContinuousLinearMap.zero_apply, sub_self] @[fun_prop] theorem hasFDerivAt_of_subsingleton [h : Subsingleton E] (f : E → F) (x : E) : HasFDerivAt f (0 : E →L[𝕜] F) x := by rw [← hasFDerivWithinAt_univ, subsingleton_univ.eq_singleton_of_mem (mem_univ x)] exact hasFDerivWithinAt_singleton f x @[fun_prop] theorem differentiableOn_empty : DifferentiableOn 𝕜 f ∅ := fun _ => False.elim @[fun_prop] theorem differentiableOn_singleton : DifferentiableOn 𝕜 f {x} := forall_eq.2 (hasFDerivWithinAt_singleton f x).differentiableWithinAt @[fun_prop] theorem Set.Subsingleton.differentiableOn (hs : s.Subsingleton) : DifferentiableOn 𝕜 f s := hs.induction_on differentiableOn_empty fun _ => differentiableOn_singleton theorem hasFDerivAt_zero_of_eventually_const (c : F) (hf : f =á¶ [𝓝 x] fun _ => c) : HasFDerivAt f (0 : E →L[𝕜] F) x := (hasFDerivAt_const _ _).congr_of_eventuallyEq hf end Const end /-! ### Support of derivatives -/ section Support open Function variable (𝕜 : Type*) {E F : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] {f : E → F} {x : E} theorem HasStrictFDerivAt.of_nmem_tsupport (h : x ∉ tsupport f) : HasStrictFDerivAt f (0 : E →L[𝕜] F) x := by rw [not_mem_tsupport_iff_eventuallyEq] at h exact (hasStrictFDerivAt_const (0 : F) x).congr_of_eventuallyEq h.symm theorem HasFDerivAt.of_nmem_tsupport (h : x ∉ tsupport f) : HasFDerivAt f (0 : E →L[𝕜] F) x := (HasStrictFDerivAt.of_nmem_tsupport 𝕜 h).hasFDerivAt theorem HasFDerivWithinAt.of_not_mem_tsupport {s : Set E} {x : E} (h : x ∉ tsupport f) : HasFDerivWithinAt f (0 : E →L[𝕜] F) s x := (HasFDerivAt.of_nmem_tsupport 𝕜 h).hasFDerivWithinAt theorem fderiv_of_not_mem_tsupport (h : x ∉ tsupport f) : fderiv 𝕜 f x = 0 := (HasFDerivAt.of_nmem_tsupport 𝕜 h).fderiv theorem support_fderiv_subset : support (fderiv 𝕜 f) ⊆ tsupport f := fun x ↩ by rw [← not_imp_not, nmem_support] exact fderiv_of_not_mem_tsupport _ theorem tsupport_fderiv_subset : tsupport (fderiv 𝕜 f) ⊆ tsupport f := closure_minimal (support_fderiv_subset 𝕜) isClosed_closure protected theorem HasCompactSupport.fderiv (hf : HasCompactSupport f) : HasCompactSupport (fderiv 𝕜 f) := hf.mono' <| support_fderiv_subset 𝕜 protected theorem HasCompactSupport.fderiv_apply (hf : HasCompactSupport f) (v : E) : HasCompactSupport (fderiv 𝕜 f · v) := hf.fderiv 𝕜 |>.comp_left (g := fun L : E →L[𝕜] F ↩ L v) rfl end Support
Analysis\Calculus\FDeriv\Bilinear.lean
/- 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 Mathlib.Analysis.Calculus.FDeriv.Prod /-! # The derivative of bounded bilinear maps For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/Fderiv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of bounded bilinear maps. -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} section BilinearMap /-! ### Derivative of a bounded bilinear map -/ variable {b : E × F → G} {u : Set (E × F)} open NormedField -- Porting note (#11215): TODO: rewrite/golf using analytic functions? @[fun_prop] theorem IsBoundedBilinearMap.hasStrictFDerivAt (h : IsBoundedBilinearMap 𝕜 b) (p : E × F) : HasStrictFDerivAt b (h.deriv p) p := by simp only [HasStrictFDerivAt] simp only [← map_add_left_nhds_zero (p, p), isLittleO_map] set T := (E × F) × E × F calc _ = fun x ↩ h.deriv (x.1 - x.2) (x.2.1, x.1.2) := by ext ⟹⟹x₁, y₁⟩, ⟹x₂, y₂⟩⟩ rcases p with ⟹x, y⟩ simp only [map_sub, deriv_apply, Function.comp_apply, Prod.mk_add_mk, h.add_right, h.add_left, Prod.mk_sub_mk, h.map_sub_left, h.map_sub_right, sub_add_sub_cancel] abel -- _ =O[𝓝 (0 : T)] fun x ↩ ‖x.1 - x.2‖ * ‖(x.2.1, x.1.2)‖ := -- h.toContinuousLinearMap.deriv₂.isBoundedBilinearMap.isBigO_comp -- _ = o[𝓝 0] fun x ↩ ‖x.1 - x.2‖ * 1 := _ _ =o[𝓝 (0 : T)] fun x ↩ x.1 - x.2 := by -- TODO : add 2 `calc` steps instead of the next 3 lines refine h.toContinuousLinearMap.deriv₂.isBoundedBilinearMap.isBigO_comp.trans_isLittleO ?_ suffices (fun x : T ↩ ‖x.1 - x.2‖ * ‖(x.2.1, x.1.2)‖) =o[𝓝 0] fun x ↩ ‖x.1 - x.2‖ * 1 by simpa only [mul_one, isLittleO_norm_right] using this refine (isBigO_refl _ _).mul_isLittleO ((isLittleO_one_iff _).2 ?_) -- TODO: `continuity` fails exact (continuous_snd.fst.prod_mk continuous_fst.snd).norm.tendsto' _ _ (by simp) _ = _ := by simp [(· ∘ ·)] @[fun_prop] theorem IsBoundedBilinearMap.hasFDerivAt (h : IsBoundedBilinearMap 𝕜 b) (p : E × F) : HasFDerivAt b (h.deriv p) p := (h.hasStrictFDerivAt p).hasFDerivAt @[fun_prop] theorem IsBoundedBilinearMap.hasFDerivWithinAt (h : IsBoundedBilinearMap 𝕜 b) (p : E × F) : HasFDerivWithinAt b (h.deriv p) u p := (h.hasFDerivAt p).hasFDerivWithinAt @[fun_prop] theorem IsBoundedBilinearMap.differentiableAt (h : IsBoundedBilinearMap 𝕜 b) (p : E × F) : DifferentiableAt 𝕜 b p := (h.hasFDerivAt p).differentiableAt @[fun_prop] theorem IsBoundedBilinearMap.differentiableWithinAt (h : IsBoundedBilinearMap 𝕜 b) (p : E × F) : DifferentiableWithinAt 𝕜 b u p := (h.differentiableAt p).differentiableWithinAt protected theorem IsBoundedBilinearMap.fderiv (h : IsBoundedBilinearMap 𝕜 b) (p : E × F) : fderiv 𝕜 b p = h.deriv p := HasFDerivAt.fderiv (h.hasFDerivAt p) protected theorem IsBoundedBilinearMap.fderivWithin (h : IsBoundedBilinearMap 𝕜 b) (p : E × F) (hxs : UniqueDiffWithinAt 𝕜 u p) : fderivWithin 𝕜 b u p = h.deriv p := by rw [DifferentiableAt.fderivWithin (h.differentiableAt p) hxs] exact h.fderiv p @[fun_prop] theorem IsBoundedBilinearMap.differentiable (h : IsBoundedBilinearMap 𝕜 b) : Differentiable 𝕜 b := fun x => h.differentiableAt x @[fun_prop] theorem IsBoundedBilinearMap.differentiableOn (h : IsBoundedBilinearMap 𝕜 b) : DifferentiableOn 𝕜 b u := h.differentiable.differentiableOn variable (B : E →L[𝕜] F →L[𝕜] G) @[fun_prop] theorem ContinuousLinearMap.hasFDerivWithinAt_of_bilinear {f : G' → E} {g : G' → F} {f' : G' →L[𝕜] E} {g' : G' →L[𝕜] F} {x : G'} {s : Set G'} (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun y => B (f y) (g y)) (B.precompR G' (f x) g' + B.precompL G' f' (g x)) s x := (B.isBoundedBilinearMap.hasFDerivAt (f x, g x)).comp_hasFDerivWithinAt x (hf.prod hg) @[fun_prop] theorem ContinuousLinearMap.hasFDerivAt_of_bilinear {f : G' → E} {g : G' → F} {f' : G' →L[𝕜] E} {g' : G' →L[𝕜] F} {x : G'} (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun y => B (f y) (g y)) (B.precompR G' (f x) g' + B.precompL G' f' (g x)) x := (B.isBoundedBilinearMap.hasFDerivAt (f x, g x)).comp x (hf.prod hg) @[fun_prop] theorem ContinuousLinearMap.hasStrictFDerivAt_of_bilinear {f : G' → E} {g : G' → F} {f' : G' →L[𝕜] E} {g' : G' →L[𝕜] F} {x : G'} (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun y => B (f y) (g y)) (B.precompR G' (f x) g' + B.precompL G' f' (g x)) x := (B.isBoundedBilinearMap.hasStrictFDerivAt (f x, g x)).comp x (hf.prod hg) theorem ContinuousLinearMap.fderivWithin_of_bilinear {f : G' → E} {g : G' → F} {x : G'} {s : Set G'} (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) (hs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun y => B (f y) (g y)) s x = B.precompR G' (f x) (fderivWithin 𝕜 g s x) + B.precompL G' (fderivWithin 𝕜 f s x) (g x) := (B.hasFDerivWithinAt_of_bilinear hf.hasFDerivWithinAt hg.hasFDerivWithinAt).fderivWithin hs theorem ContinuousLinearMap.fderiv_of_bilinear {f : G' → E} {g : G' → F} {x : G'} (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (fun y => B (f y) (g y)) x = B.precompR G' (f x) (fderiv 𝕜 g x) + B.precompL G' (fderiv 𝕜 f x) (g x) := (B.hasFDerivAt_of_bilinear hf.hasFDerivAt hg.hasFDerivAt).fderiv end BilinearMap end
Analysis\Calculus\FDeriv\Comp.lean
/- 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 Mathlib.Analysis.Calculus.FDeriv.Basic /-! # The derivative of a composition (chain rule) For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of composition of functions (the chain rule). -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} 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 HasFDerivAtFilter.comp {g : F → G} {g' : F →L[𝕜] G} {L' : Filter F} (hg : HasFDerivAtFilter g g' (f x) L') (hf : HasFDerivAtFilter f f' x L) (hL : Tendsto f L L') : HasFDerivAtFilter (g ∘ f) (g'.comp f') x L := by let eq₁ := (g'.isBigO_comp _ _).trans_isLittleO hf.isLittleO let eq₂ := (hg.isLittleO.comp_tendsto hL).trans_isBigO hf.isBigO_sub refine .of_isLittleO <| eq₂.triangle <| eq₁.congr_left fun 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 : HasFDerivAtFilter g g' (f x) (L.map f)) (hf : HasFDerivAtFilter f f' x L) : HasFDerivAtFilter (g ∘ f) (g'.comp f') x L := by have := calc (fun x' => g (f x') - g (f x) - g' (f x' - f x)) =o[L] fun x' => f x' - f x := hg.isLittleO.comp_tendsto le_rfl _ =O[L] fun x' => x' - x := hf.isBigO_sub refine .of_isLittleO <| this.triangle ?_ calc (fun x' : E => g' (f x' - f x) - g'.comp f' (x' - x)) _ =á¶ [L] fun x' => g' (f x' - f x - f' (x' - x)) := eventually_of_forall fun x' => by simp _ =O[L] fun x' => f x' - f x - f' (x' - x) := g'.isBigO_comp _ _ _ =o[L] fun x' => x' - x := hf.isLittleO @[fun_prop] theorem HasFDerivWithinAt.comp {g : F → G} {g' : F →L[𝕜] G} {t : Set F} (hg : HasFDerivWithinAt g g' t (f x)) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t) : HasFDerivWithinAt (g ∘ f) (g'.comp f') s x := HasFDerivAtFilter.comp x hg hf <| hf.continuousWithinAt.tendsto_nhdsWithin hst @[fun_prop] theorem HasFDerivAt.comp_hasFDerivWithinAt {g : F → G} {g' : F →L[𝕜] G} (hg : HasFDerivAt g g' (f x)) (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (g ∘ f) (g'.comp f') s x := hg.comp x hf hf.continuousWithinAt @[fun_prop] theorem HasFDerivWithinAt.comp_of_mem {g : F → G} {g' : F →L[𝕜] G} {t : Set F} (hg : HasFDerivWithinAt g g' t (f x)) (hf : HasFDerivWithinAt f f' s x) (hst : Tendsto f (𝓝[s] x) (𝓝[t] f x)) : HasFDerivWithinAt (g ∘ f) (g'.comp f') s x := HasFDerivAtFilter.comp x hg hf hst /-- The chain rule. -/ @[fun_prop] theorem HasFDerivAt.comp {g : F → G} {g' : F →L[𝕜] G} (hg : HasFDerivAt g g' (f x)) (hf : HasFDerivAt f f' x) : HasFDerivAt (g ∘ f) (g'.comp f') x := HasFDerivAtFilter.comp x hg hf hf.continuousAt @[fun_prop] theorem DifferentiableWithinAt.comp {g : F → G} {t : Set F} (hg : DifferentiableWithinAt 𝕜 g t (f x)) (hf : DifferentiableWithinAt 𝕜 f s x) (h : MapsTo f s t) : DifferentiableWithinAt 𝕜 (g ∘ f) s x := (hg.hasFDerivWithinAt.comp x hf.hasFDerivWithinAt h).differentiableWithinAt @[fun_prop] theorem DifferentiableWithinAt.comp' {g : F → G} {t : Set F} (hg : DifferentiableWithinAt 𝕜 g t (f x)) (hf : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (g ∘ f) (s ∩ f ⁻¹' t) x := hg.comp x (hf.mono inter_subset_left) inter_subset_right @[fun_prop] theorem DifferentiableAt.comp {g : F → G} (hg : DifferentiableAt 𝕜 g (f x)) (hf : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (g ∘ f) x := (hg.hasFDerivAt.comp x hf.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableAt.comp_differentiableWithinAt {g : F → G} (hg : DifferentiableAt 𝕜 g (f x)) (hf : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (g ∘ f) s x := hg.differentiableWithinAt.comp x hf (mapsTo_univ _ _) theorem fderivWithin.comp {g : F → G} {t : Set F} (hg : DifferentiableWithinAt 𝕜 g t (f x)) (hf : DifferentiableWithinAt 𝕜 f s x) (h : MapsTo f s t) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (g ∘ f) s x = (fderivWithin 𝕜 g t (f x)).comp (fderivWithin 𝕜 f s x) := (hg.hasFDerivWithinAt.comp x hf.hasFDerivWithinAt h).fderivWithin hxs /-- A version of `fderivWithin.comp` that is useful to rewrite the composition of two derivatives into a single derivative. This version always applies, but creates a new side-goal `f x = y`. -/ theorem fderivWithin_fderivWithin {g : F → G} {f : E → F} {x : E} {y : F} {s : Set E} {t : Set F} (hg : DifferentiableWithinAt 𝕜 g t y) (hf : DifferentiableWithinAt 𝕜 f s x) (h : MapsTo f s t) (hxs : UniqueDiffWithinAt 𝕜 s x) (hy : f x = y) (v : E) : fderivWithin 𝕜 g t y (fderivWithin 𝕜 f s x v) = fderivWithin 𝕜 (g ∘ f) s x v := by subst y rw [fderivWithin.comp x hg hf h hxs, coe_comp', Function.comp_apply] /-- Ternary version of `fderivWithin.comp`, with equality assumptions of basepoints added, in order to apply more easily as a rewrite from right-to-left. -/ theorem fderivWithin.comp₃ {g' : G → G'} {g : F → G} {t : Set F} {u : Set G} {y : F} {y' : G} (hg' : DifferentiableWithinAt 𝕜 g' u y') (hg : DifferentiableWithinAt 𝕜 g t y) (hf : DifferentiableWithinAt 𝕜 f s x) (h2g : MapsTo g t u) (h2f : MapsTo f s t) (h3g : g y = y') (h3f : f x = y) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (g' ∘ g ∘ f) s x = (fderivWithin 𝕜 g' u y').comp ((fderivWithin 𝕜 g t y).comp (fderivWithin 𝕜 f s x)) := by substs h3g h3f exact (hg'.hasFDerivWithinAt.comp x (hg.hasFDerivWithinAt.comp x hf.hasFDerivWithinAt h2f) <| h2g.comp h2f).fderivWithin hxs theorem fderiv.comp {g : F → G} (hg : DifferentiableAt 𝕜 g (f x)) (hf : DifferentiableAt 𝕜 f x) : fderiv 𝕜 (g ∘ f) x = (fderiv 𝕜 g (f x)).comp (fderiv 𝕜 f x) := (hg.hasFDerivAt.comp x hf.hasFDerivAt).fderiv theorem fderiv.comp_fderivWithin {g : F → G} (hg : DifferentiableAt 𝕜 g (f x)) (hf : DifferentiableWithinAt 𝕜 f s x) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (g ∘ f) s x = (fderiv 𝕜 g (f x)).comp (fderivWithin 𝕜 f s x) := (hg.hasFDerivAt.comp_hasFDerivWithinAt x hf.hasFDerivWithinAt).fderivWithin hxs @[fun_prop] theorem DifferentiableOn.comp {g : F → G} {t : Set F} (hg : DifferentiableOn 𝕜 g t) (hf : DifferentiableOn 𝕜 f s) (st : MapsTo f s t) : DifferentiableOn 𝕜 (g ∘ f) s := fun x hx => DifferentiableWithinAt.comp x (hg (f x) (st hx)) (hf x hx) st @[fun_prop] theorem Differentiable.comp {g : F → G} (hg : Differentiable 𝕜 g) (hf : Differentiable 𝕜 f) : Differentiable 𝕜 (g ∘ f) := fun x => DifferentiableAt.comp x (hg (f x)) (hf x) @[fun_prop] theorem Differentiable.comp_differentiableOn {g : F → G} (hg : Differentiable 𝕜 g) (hf : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (g ∘ f) s := hg.differentiableOn.comp hf (mapsTo_univ _ _) /-- The chain rule for derivatives in the sense of strict differentiability. -/ @[fun_prop] protected theorem HasStrictFDerivAt.comp {g : F → G} {g' : F →L[𝕜] G} (hg : HasStrictFDerivAt g g' (f x)) (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => g (f x)) (g'.comp f') x := ((hg.comp_tendsto (hf.continuousAt.prod_map' hf.continuousAt)).trans_isBigO hf.isBigO_sub).triangle <| by simpa only [g'.map_sub, f'.coe_comp'] using (g'.isBigO_comp _ _).trans_isLittleO hf @[fun_prop] protected theorem Differentiable.iterate {f : E → E} (hf : Differentiable 𝕜 f) (n : ℕ) : Differentiable 𝕜 f^[n] := Nat.recOn n differentiable_id fun _ ihn => ihn.comp hf @[fun_prop] protected theorem DifferentiableOn.iterate {f : E → E} (hf : DifferentiableOn 𝕜 f s) (hs : MapsTo f s s) (n : ℕ) : DifferentiableOn 𝕜 f^[n] s := Nat.recOn n differentiableOn_id fun _ ihn => ihn.comp hf hs variable {x} protected theorem HasFDerivAtFilter.iterate {f : E → E} {f' : E →L[𝕜] E} (hf : HasFDerivAtFilter f f' x L) (hL : Tendsto f L L) (hx : f x = x) (n : ℕ) : HasFDerivAtFilter f^[n] (f' ^ n) x L := by induction' n with n ihn · exact hasFDerivAtFilter_id x L · rw [Function.iterate_succ, pow_succ] rw [← hx] at ihn exact ihn.comp x hf hL @[fun_prop] protected theorem HasFDerivAt.iterate {f : E → E} {f' : E →L[𝕜] E} (hf : HasFDerivAt f f' x) (hx : f x = x) (n : ℕ) : HasFDerivAt f^[n] (f' ^ n) x := by refine HasFDerivAtFilter.iterate hf ?_ hx n -- Porting note: was `convert hf.continuousAt` convert hf.continuousAt.tendsto exact hx.symm @[fun_prop] protected theorem HasFDerivWithinAt.iterate {f : E → E} {f' : E →L[𝕜] E} (hf : HasFDerivWithinAt f f' s x) (hx : f x = x) (hs : MapsTo f s s) (n : ℕ) : HasFDerivWithinAt f^[n] (f' ^ n) s x := by refine HasFDerivAtFilter.iterate hf ?_ hx n rw [_root_.nhdsWithin] -- Porting note: Added `rw` to get rid of an error convert tendsto_inf.2 ⟹hf.continuousWithinAt, _⟩ exacts [hx.symm, (tendsto_principal_principal.2 hs).mono_left inf_le_right] @[fun_prop] protected theorem HasStrictFDerivAt.iterate {f : E → E} {f' : E →L[𝕜] E} (hf : HasStrictFDerivAt f f' x) (hx : f x = x) (n : ℕ) : HasStrictFDerivAt f^[n] (f' ^ n) x := by induction' n with n ihn · exact hasStrictFDerivAt_id x · rw [Function.iterate_succ, pow_succ] rw [← hx] at ihn exact ihn.comp x hf @[fun_prop] protected theorem DifferentiableAt.iterate {f : E → E} (hf : DifferentiableAt 𝕜 f x) (hx : f x = x) (n : ℕ) : DifferentiableAt 𝕜 f^[n] x := (hf.hasFDerivAt.iterate hx n).differentiableAt @[fun_prop] protected theorem DifferentiableWithinAt.iterate {f : E → E} (hf : DifferentiableWithinAt 𝕜 f s x) (hx : f x = x) (hs : MapsTo f s s) (n : ℕ) : DifferentiableWithinAt 𝕜 f^[n] s x := (hf.hasFDerivWithinAt.iterate hx hs n).differentiableWithinAt end Composition end
Analysis\Calculus\FDeriv\Equiv.lean
/- 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 Mathlib.Analysis.Asymptotics.AsymptoticEquivalent import Mathlib.Analysis.Calculus.FDeriv.Linear import Mathlib.Analysis.Calculus.FDeriv.Comp /-! # The derivative of a linear equivalence For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of continuous linear equivalences. We also prove the usual formula for the derivative of the inverse function, assuming it exists. The inverse function theorem is in `Mathlib/Analysis/Calculus/InverseFunctionTheorem/FDeriv.lean`. -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} namespace ContinuousLinearEquiv /-! ### Differentiability of linear equivs, and invariance of differentiability -/ variable (iso : E ≃L[𝕜] F) @[fun_prop] protected theorem hasStrictFDerivAt : HasStrictFDerivAt iso (iso : E →L[𝕜] F) x := iso.toContinuousLinearMap.hasStrictFDerivAt @[fun_prop] protected theorem hasFDerivWithinAt : HasFDerivWithinAt iso (iso : E →L[𝕜] F) s x := iso.toContinuousLinearMap.hasFDerivWithinAt @[fun_prop] protected theorem hasFDerivAt : HasFDerivAt iso (iso : E →L[𝕜] F) x := iso.toContinuousLinearMap.hasFDerivAtFilter @[fun_prop] protected theorem differentiableAt : DifferentiableAt 𝕜 iso x := iso.hasFDerivAt.differentiableAt @[fun_prop] protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 iso s x := iso.differentiableAt.differentiableWithinAt protected theorem fderiv : fderiv 𝕜 iso x = iso := iso.hasFDerivAt.fderiv protected theorem fderivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 iso s x = iso := iso.toContinuousLinearMap.fderivWithin hxs @[fun_prop] protected theorem differentiable : Differentiable 𝕜 iso := fun _ => iso.differentiableAt @[fun_prop] protected theorem differentiableOn : DifferentiableOn 𝕜 iso s := iso.differentiable.differentiableOn theorem comp_differentiableWithinAt_iff {f : G → E} {s : Set G} {x : G} : DifferentiableWithinAt 𝕜 (iso ∘ f) s x ↔ DifferentiableWithinAt 𝕜 f s x := by refine ⟹fun H => ?_, fun H => iso.differentiable.differentiableAt.comp_differentiableWithinAt x H⟩ have : DifferentiableWithinAt 𝕜 (iso.symm ∘ iso ∘ f) s x := iso.symm.differentiable.differentiableAt.comp_differentiableWithinAt x H rwa [← Function.comp.assoc iso.symm iso f, iso.symm_comp_self] at this theorem comp_differentiableAt_iff {f : G → E} {x : G} : DifferentiableAt 𝕜 (iso ∘ f) x ↔ DifferentiableAt 𝕜 f x := by rw [← differentiableWithinAt_univ, ← differentiableWithinAt_univ, iso.comp_differentiableWithinAt_iff] theorem comp_differentiableOn_iff {f : G → E} {s : Set G} : DifferentiableOn 𝕜 (iso ∘ f) s ↔ DifferentiableOn 𝕜 f s := by rw [DifferentiableOn, DifferentiableOn] simp only [iso.comp_differentiableWithinAt_iff] theorem comp_differentiable_iff {f : G → E} : Differentiable 𝕜 (iso ∘ f) ↔ Differentiable 𝕜 f := by rw [← differentiableOn_univ, ← differentiableOn_univ] exact iso.comp_differentiableOn_iff theorem comp_hasFDerivWithinAt_iff {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] E} : HasFDerivWithinAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ HasFDerivWithinAt f f' s x := by refine ⟹fun H => ?_, fun H => iso.hasFDerivAt.comp_hasFDerivWithinAt x H⟩ have A : f = iso.symm ∘ iso ∘ f := by rw [← Function.comp.assoc, iso.symm_comp_self] rfl have B : f' = (iso.symm : F →L[𝕜] E).comp ((iso : E →L[𝕜] F).comp f') := by rw [← ContinuousLinearMap.comp_assoc, iso.coe_symm_comp_coe, ContinuousLinearMap.id_comp] rw [A, B] exact iso.symm.hasFDerivAt.comp_hasFDerivWithinAt x H theorem comp_hasStrictFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : HasStrictFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasStrictFDerivAt f f' x := by refine ⟹fun H => ?_, fun H => iso.hasStrictFDerivAt.comp x H⟩ convert iso.symm.hasStrictFDerivAt.comp x H using 1 <;> ext z <;> apply (iso.symm_apply_apply _).symm theorem comp_hasFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : HasFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasFDerivAt f f' x := by simp_rw [← hasFDerivWithinAt_univ, iso.comp_hasFDerivWithinAt_iff] theorem comp_hasFDerivWithinAt_iff' {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] F} : HasFDerivWithinAt (iso ∘ f) f' s x ↔ HasFDerivWithinAt f ((iso.symm : F →L[𝕜] E).comp f') s x := by rw [← iso.comp_hasFDerivWithinAt_iff, ← ContinuousLinearMap.comp_assoc, iso.coe_comp_coe_symm, ContinuousLinearMap.id_comp] theorem comp_hasFDerivAt_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} : HasFDerivAt (iso ∘ f) f' x ↔ HasFDerivAt f ((iso.symm : F →L[𝕜] E).comp f') x := by simp_rw [← hasFDerivWithinAt_univ, iso.comp_hasFDerivWithinAt_iff'] theorem comp_fderivWithin {f : G → E} {s : Set G} {x : G} (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderivWithin 𝕜 f s x) := by by_cases h : DifferentiableWithinAt 𝕜 f s x · rw [fderiv.comp_fderivWithin x iso.differentiableAt h hxs, iso.fderiv] · have : ¬DifferentiableWithinAt 𝕜 (iso ∘ f) s x := mt iso.comp_differentiableWithinAt_iff.1 h rw [fderivWithin_zero_of_not_differentiableWithinAt h, fderivWithin_zero_of_not_differentiableWithinAt this, ContinuousLinearMap.comp_zero] theorem comp_fderiv {f : G → E} {x : G} : fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) := by rw [← fderivWithin_univ, ← fderivWithin_univ] exact iso.comp_fderivWithin uniqueDiffWithinAt_univ lemma _root_.fderivWithin_continuousLinearEquiv_comp (L : G ≃L[𝕜] G') (f : E → (F →L[𝕜] G)) (hs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x ↩ (L : G →L[𝕜] G').comp (f x)) s x = (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L)) ∘L (fderivWithin 𝕜 f s x) := by change fderivWithin 𝕜 (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L) ∘ f) s x = _ rw [ContinuousLinearEquiv.comp_fderivWithin _ hs] lemma _root_.fderiv_continuousLinearEquiv_comp (L : G ≃L[𝕜] G') (f : E → (F →L[𝕜] G)) (x : E) : fderiv 𝕜 (fun x ↩ (L : G →L[𝕜] G').comp (f x)) x = (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L)) ∘L (fderiv 𝕜 f x) := by change fderiv 𝕜 (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L) ∘ f) x = _ rw [ContinuousLinearEquiv.comp_fderiv] lemma _root_.fderiv_continuousLinearEquiv_comp' (L : G ≃L[𝕜] G') (f : E → (F →L[𝕜] G)) : fderiv 𝕜 (fun x ↩ (L : G →L[𝕜] G').comp (f x)) = fun x ↩ (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L)) ∘L (fderiv 𝕜 f x) := by ext x : 1 exact fderiv_continuousLinearEquiv_comp L f x theorem comp_right_differentiableWithinAt_iff {f : F → G} {s : Set F} {x : E} : DifferentiableWithinAt 𝕜 (f ∘ iso) (iso ⁻¹' s) x ↔ DifferentiableWithinAt 𝕜 f s (iso x) := by refine ⟹fun H => ?_, fun H => H.comp x iso.differentiableWithinAt (mapsTo_preimage _ s)⟩ have : DifferentiableWithinAt 𝕜 ((f ∘ iso) ∘ iso.symm) s (iso x) := by rw [← iso.symm_apply_apply x] at H apply H.comp (iso x) iso.symm.differentiableWithinAt intro y hy simpa only [mem_preimage, apply_symm_apply] using hy rwa [Function.comp.assoc, iso.self_comp_symm] at this theorem comp_right_differentiableAt_iff {f : F → G} {x : E} : DifferentiableAt 𝕜 (f ∘ iso) x ↔ DifferentiableAt 𝕜 f (iso x) := by simp only [← differentiableWithinAt_univ, ← iso.comp_right_differentiableWithinAt_iff, preimage_univ] theorem comp_right_differentiableOn_iff {f : F → G} {s : Set F} : DifferentiableOn 𝕜 (f ∘ iso) (iso ⁻¹' s) ↔ DifferentiableOn 𝕜 f s := by refine ⟹fun H y hy => ?_, fun H y hy => iso.comp_right_differentiableWithinAt_iff.2 (H _ hy)⟩ rw [← iso.apply_symm_apply y, ← comp_right_differentiableWithinAt_iff] apply H simpa only [mem_preimage, apply_symm_apply] using hy theorem comp_right_differentiable_iff {f : F → G} : Differentiable 𝕜 (f ∘ iso) ↔ Differentiable 𝕜 f := by simp only [← differentiableOn_univ, ← iso.comp_right_differentiableOn_iff, preimage_univ] theorem comp_right_hasFDerivWithinAt_iff {f : F → G} {s : Set F} {x : E} {f' : F →L[𝕜] G} : HasFDerivWithinAt (f ∘ iso) (f'.comp (iso : E →L[𝕜] F)) (iso ⁻¹' s) x ↔ HasFDerivWithinAt f f' s (iso x) := by refine ⟹fun H => ?_, fun H => H.comp x iso.hasFDerivWithinAt (mapsTo_preimage _ s)⟩ rw [← iso.symm_apply_apply x] at H have A : f = (f ∘ iso) ∘ iso.symm := by rw [Function.comp.assoc, iso.self_comp_symm] rfl have B : f' = (f'.comp (iso : E →L[𝕜] F)).comp (iso.symm : F →L[𝕜] E) := by rw [ContinuousLinearMap.comp_assoc, iso.coe_comp_coe_symm, ContinuousLinearMap.comp_id] rw [A, B] apply H.comp (iso x) iso.symm.hasFDerivWithinAt intro y hy simpa only [mem_preimage, apply_symm_apply] using hy theorem comp_right_hasFDerivAt_iff {f : F → G} {x : E} {f' : F →L[𝕜] G} : HasFDerivAt (f ∘ iso) (f'.comp (iso : E →L[𝕜] F)) x ↔ HasFDerivAt f f' (iso x) := by simp only [← hasFDerivWithinAt_univ, ← comp_right_hasFDerivWithinAt_iff, preimage_univ] theorem comp_right_hasFDerivWithinAt_iff' {f : F → G} {s : Set F} {x : E} {f' : E →L[𝕜] G} : HasFDerivWithinAt (f ∘ iso) f' (iso ⁻¹' s) x ↔ HasFDerivWithinAt f (f'.comp (iso.symm : F →L[𝕜] E)) s (iso x) := by rw [← iso.comp_right_hasFDerivWithinAt_iff, ContinuousLinearMap.comp_assoc, iso.coe_symm_comp_coe, ContinuousLinearMap.comp_id] theorem comp_right_hasFDerivAt_iff' {f : F → G} {x : E} {f' : E →L[𝕜] G} : HasFDerivAt (f ∘ iso) f' x ↔ HasFDerivAt f (f'.comp (iso.symm : F →L[𝕜] E)) (iso x) := by simp only [← hasFDerivWithinAt_univ, ← iso.comp_right_hasFDerivWithinAt_iff', preimage_univ] theorem comp_right_fderivWithin {f : F → G} {s : Set F} {x : E} (hxs : UniqueDiffWithinAt 𝕜 (iso ⁻¹' s) x) : fderivWithin 𝕜 (f ∘ iso) (iso ⁻¹' s) x = (fderivWithin 𝕜 f s (iso x)).comp (iso : E →L[𝕜] F) := by by_cases h : DifferentiableWithinAt 𝕜 f s (iso x) · exact (iso.comp_right_hasFDerivWithinAt_iff.2 h.hasFDerivWithinAt).fderivWithin hxs · have : ¬DifferentiableWithinAt 𝕜 (f ∘ iso) (iso ⁻¹' s) x := by intro h' exact h (iso.comp_right_differentiableWithinAt_iff.1 h') rw [fderivWithin_zero_of_not_differentiableWithinAt h, fderivWithin_zero_of_not_differentiableWithinAt this, ContinuousLinearMap.zero_comp] theorem comp_right_fderiv {f : F → G} {x : E} : fderiv 𝕜 (f ∘ iso) x = (fderiv 𝕜 f (iso x)).comp (iso : E →L[𝕜] F) := by rw [← fderivWithin_univ, ← fderivWithin_univ, ← iso.comp_right_fderivWithin, preimage_univ] exact uniqueDiffWithinAt_univ end ContinuousLinearEquiv namespace LinearIsometryEquiv /-! ### Differentiability of linear isometry equivs, and invariance of differentiability -/ variable (iso : E ≃ₗᵢ[𝕜] F) @[fun_prop] protected theorem hasStrictFDerivAt : HasStrictFDerivAt iso (iso : E →L[𝕜] F) x := (iso : E ≃L[𝕜] F).hasStrictFDerivAt @[fun_prop] protected theorem hasFDerivWithinAt : HasFDerivWithinAt iso (iso : E →L[𝕜] F) s x := (iso : E ≃L[𝕜] F).hasFDerivWithinAt @[fun_prop] protected theorem hasFDerivAt : HasFDerivAt iso (iso : E →L[𝕜] F) x := (iso : E ≃L[𝕜] F).hasFDerivAt @[fun_prop] protected theorem differentiableAt : DifferentiableAt 𝕜 iso x := iso.hasFDerivAt.differentiableAt @[fun_prop] protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 iso s x := iso.differentiableAt.differentiableWithinAt protected theorem fderiv : fderiv 𝕜 iso x = iso := iso.hasFDerivAt.fderiv protected theorem fderivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 iso s x = iso := (iso : E ≃L[𝕜] F).fderivWithin hxs @[fun_prop] protected theorem differentiable : Differentiable 𝕜 iso := fun _ => iso.differentiableAt @[fun_prop] protected theorem differentiableOn : DifferentiableOn 𝕜 iso s := iso.differentiable.differentiableOn theorem comp_differentiableWithinAt_iff {f : G → E} {s : Set G} {x : G} : DifferentiableWithinAt 𝕜 (iso ∘ f) s x ↔ DifferentiableWithinAt 𝕜 f s x := (iso : E ≃L[𝕜] F).comp_differentiableWithinAt_iff theorem comp_differentiableAt_iff {f : G → E} {x : G} : DifferentiableAt 𝕜 (iso ∘ f) x ↔ DifferentiableAt 𝕜 f x := (iso : E ≃L[𝕜] F).comp_differentiableAt_iff theorem comp_differentiableOn_iff {f : G → E} {s : Set G} : DifferentiableOn 𝕜 (iso ∘ f) s ↔ DifferentiableOn 𝕜 f s := (iso : E ≃L[𝕜] F).comp_differentiableOn_iff theorem comp_differentiable_iff {f : G → E} : Differentiable 𝕜 (iso ∘ f) ↔ Differentiable 𝕜 f := (iso : E ≃L[𝕜] F).comp_differentiable_iff theorem comp_hasFDerivWithinAt_iff {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] E} : HasFDerivWithinAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ HasFDerivWithinAt f f' s x := (iso : E ≃L[𝕜] F).comp_hasFDerivWithinAt_iff theorem comp_hasStrictFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : HasStrictFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasStrictFDerivAt f f' x := (iso : E ≃L[𝕜] F).comp_hasStrictFDerivAt_iff theorem comp_hasFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : HasFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasFDerivAt f f' x := (iso : E ≃L[𝕜] F).comp_hasFDerivAt_iff theorem comp_hasFDerivWithinAt_iff' {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] F} : HasFDerivWithinAt (iso ∘ f) f' s x ↔ HasFDerivWithinAt f ((iso.symm : F →L[𝕜] E).comp f') s x := (iso : E ≃L[𝕜] F).comp_hasFDerivWithinAt_iff' theorem comp_hasFDerivAt_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} : HasFDerivAt (iso ∘ f) f' x ↔ HasFDerivAt f ((iso.symm : F →L[𝕜] E).comp f') x := (iso : E ≃L[𝕜] F).comp_hasFDerivAt_iff' theorem comp_fderivWithin {f : G → E} {s : Set G} {x : G} (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderivWithin 𝕜 f s x) := (iso : E ≃L[𝕜] F).comp_fderivWithin hxs theorem comp_fderiv {f : G → E} {x : G} : fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) := (iso : E ≃L[𝕜] F).comp_fderiv theorem comp_fderiv' {f : G → E} : fderiv 𝕜 (iso ∘ f) = fun x ↩ (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) := by ext x : 1 exact LinearIsometryEquiv.comp_fderiv iso end LinearIsometryEquiv /-- 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 HasStrictFDerivAt.of_local_left_inverse {f : E → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F} (hg : ContinuousAt g a) (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) (g a)) (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : HasStrictFDerivAt g (f'.symm : F →L[𝕜] E) a := by replace hg := hg.prod_map' hg replace hfg := hfg.prod_mk_nhds hfg have : (fun p : F × F => g p.1 - g p.2 - f'.symm (p.1 - p.2)) =O[𝓝 (a, a)] fun p : F × F => f' (g p.1 - g p.2) - (p.1 - p.2) := by refine ((f'.symm : F →L[𝕜] E).isBigO_comp _ _).congr (fun x => ?_) fun _ => rfl simp refine this.trans_isLittleO ?_ clear this refine ((hf.comp_tendsto hg).symm.congr' (hfg.mono ?_) (eventually_of_forall fun _ => rfl)).trans_isBigO ?_ · rintro p ⟹hp1, hp2⟩ simp [hp1, hp2] · refine (hf.isBigO_sub_rev.comp_tendsto hg).congr' (eventually_of_forall fun _ => rfl) (hfg.mono ?_) rintro p ⟹hp1, hp2⟩ simp only [(· ∘ ·), hp1, hp2] /-- 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 HasFDerivAt.of_local_left_inverse {f : E → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F} (hg : ContinuousAt g a) (hf : HasFDerivAt f (f' : E →L[𝕜] F) (g a)) (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : HasFDerivAt g (f'.symm : F →L[𝕜] E) a := by have : (fun x : F => g x - g a - f'.symm (x - a)) =O[𝓝 a] fun x : F => f' (g x - g a) - (x - a) := by refine ((f'.symm : F →L[𝕜] E).isBigO_comp _ _).congr (fun x => ?_) fun _ => rfl simp refine HasFDerivAtFilter.of_isLittleO <| this.trans_isLittleO ?_ clear this refine ((hf.isLittleO.comp_tendsto hg).symm.congr' (hfg.mono ?_) .rfl).trans_isBigO ?_ · intro p hp simp [hp, hfg.self_of_nhds] · refine ((hf.isBigO_sub_rev f'.antilipschitz).comp_tendsto hg).congr' (eventually_of_forall fun _ => rfl) (hfg.mono ?_) rintro p hp simp only [(· ∘ ·), hp, hfg.self_of_nhds] /-- If `f` is a partial homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an invertible derivative `f'` in the sense of strict differentiability 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. -/ theorem PartialHomeomorph.hasStrictFDerivAt_symm (f : PartialHomeomorph E F) {f' : E ≃L[𝕜] F} {a : F} (ha : a ∈ f.target) (htff' : HasStrictFDerivAt f (f' : E →L[𝕜] F) (f.symm a)) : HasStrictFDerivAt f.symm (f'.symm : F →L[𝕜] E) a := htff'.of_local_left_inverse (f.symm.continuousAt ha) (f.eventually_right_inverse ha) /-- If `f` is a partial homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an invertible 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. -/ theorem PartialHomeomorph.hasFDerivAt_symm (f : PartialHomeomorph E F) {f' : E ≃L[𝕜] F} {a : F} (ha : a ∈ f.target) (htff' : HasFDerivAt f (f' : E →L[𝕜] F) (f.symm a)) : HasFDerivAt f.symm (f'.symm : F →L[𝕜] E) a := htff'.of_local_left_inverse (f.symm.continuousAt ha) (f.eventually_right_inverse ha) theorem HasFDerivWithinAt.eventually_ne (h : HasFDerivWithinAt f f' s x) (hf' : ∃ C, ∀ z, ‖z‖ ≀ C * ‖f' z‖) : ∀ᶠ z in 𝓝[s \ {x}] x, f z ≠ f x := by rw [nhdsWithin, diff_eq, ← inf_principal, ← inf_assoc, eventually_inf_principal] have A : (fun z => z - x) =O[𝓝[s] x] fun z => f' (z - x) := isBigO_iff.2 <| hf'.imp fun C hC => eventually_of_forall fun z => hC _ have : (fun z => f z - f x) ~[𝓝[s] x] fun z => f' (z - x) := h.isLittleO.trans_isBigO A simpa [not_imp_not, sub_eq_zero] using (A.trans this.isBigO_symm).eq_zero_imp theorem HasFDerivAt.eventually_ne (h : HasFDerivAt f f' x) (hf' : ∃ C, ∀ z, ‖z‖ ≀ C * ‖f' z‖) : ∀ᶠ z in 𝓝[≠] x, f z ≠ f x := by simpa only [compl_eq_univ_diff] using (hasFDerivWithinAt_univ.2 h).eventually_ne hf' 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. -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] variable {f : E → F} {f' : E →L[ℝ] F} {x : E} theorem has_fderiv_at_filter_real_equiv {L : Filter E} : Tendsto (fun x' : E => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) ↔ Tendsto (fun x' : E => ‖x' - x‖⁻¹ • (f x' - f x - f' (x' - x))) L (𝓝 0) := by symm rw [tendsto_iff_norm_sub_tendsto_zero] refine tendsto_congr fun x' => ?_ simp [norm_smul] theorem HasFDerivAt.lim_real (hf : HasFDerivAt f f' x) (v : E) : Tendsto (fun c : ℝ => c • (f (x + c⁻¹ • v) - f x)) atTop (𝓝 (f' v)) := by apply hf.lim v rw [tendsto_atTop_atTop] exact fun b => ⟹b, fun a ha => le_trans ha (le_abs_self _)⟩ end section TangentCone variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 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. -/ theorem HasFDerivWithinAt.mapsTo_tangent_cone {x : E} (h : HasFDerivWithinAt f f' s x) : MapsTo f' (tangentConeAt 𝕜 s x) (tangentConeAt 𝕜 (f '' s) (f x)) := by rintro v ⟹c, d, dtop, clim, cdlim⟩ refine ⟹c, fun n => f (x + d n) - f x, mem_of_superset dtop ?_, clim, h.lim atTop dtop clim cdlim⟩ simp (config := { contextual := true }) [-mem_image, mem_image_of_mem] /-- 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. -/ theorem HasFDerivWithinAt.uniqueDiffWithinAt {x : E} (h : HasFDerivWithinAt f f' s x) (hs : UniqueDiffWithinAt 𝕜 s x) (h' : DenseRange f') : UniqueDiffWithinAt 𝕜 (f '' s) (f x) := by refine ⟹h'.dense_of_mapsTo f'.continuous hs.1 ?_, h.continuousWithinAt.mem_closure_image hs.2⟩ show Submodule.span 𝕜 (tangentConeAt 𝕜 s x) ≀ (Submodule.span 𝕜 (tangentConeAt 𝕜 (f '' s) (f x))).comap f' rw [Submodule.span_le] exact h.mapsTo_tangent_cone.mono Subset.rfl Submodule.subset_span theorem UniqueDiffOn.image {f' : E → E →L[𝕜] F} (hs : UniqueDiffOn 𝕜 s) (hf' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hd : ∀ x ∈ s, DenseRange (f' x)) : UniqueDiffOn 𝕜 (f '' s) := forall_mem_image.2 fun x hx => (hf' x hx).uniqueDiffWithinAt (hs x hx) (hd x hx) theorem HasFDerivWithinAt.uniqueDiffWithinAt_of_continuousLinearEquiv {x : E} (e' : E ≃L[𝕜] F) (h : HasFDerivWithinAt f (e' : E →L[𝕜] F) s x) (hs : UniqueDiffWithinAt 𝕜 s x) : UniqueDiffWithinAt 𝕜 (f '' s) (f x) := h.uniqueDiffWithinAt hs e'.surjective.denseRange theorem ContinuousLinearEquiv.uniqueDiffOn_image (e : E ≃L[𝕜] F) (h : UniqueDiffOn 𝕜 s) : UniqueDiffOn 𝕜 (e '' s) := h.image (fun _ _ => e.hasFDerivWithinAt) fun _ _ => e.surjective.denseRange @[simp] theorem ContinuousLinearEquiv.uniqueDiffOn_image_iff (e : E ≃L[𝕜] F) : UniqueDiffOn 𝕜 (e '' s) ↔ UniqueDiffOn 𝕜 s := ⟹fun h => e.symm_image_image s ▾ e.symm.uniqueDiffOn_image h, e.uniqueDiffOn_image⟩ @[simp] theorem ContinuousLinearEquiv.uniqueDiffOn_preimage_iff (e : F ≃L[𝕜] E) : UniqueDiffOn 𝕜 (e ⁻¹' s) ↔ UniqueDiffOn 𝕜 s := by rw [← e.image_symm_eq_preimage, e.symm.uniqueDiffOn_image_iff] end TangentCone
Analysis\Calculus\FDeriv\Extend.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.MeanValue /-! # Extending differentiability to the boundary We investigate how differentiable functions inside a set extend to differentiable functions on the boundary. For this, it suffices that the function and its derivative admit limits there. A general version of this statement is given in `hasFDerivWithinAt_closure_of_tendsto_fderiv`. One-dimensional versions, in which one wants to obtain differentiability at the left endpoint or the right endpoint of an interval, are given in `hasDerivWithinAt_Ici_of_tendsto_deriv` and `hasDerivWithinAt_Iic_of_tendsto_deriv`. These versions are formulated in terms of the one-dimensional derivative `deriv ℝ f`. -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Filter Set Metric ContinuousLinearMap open scoped Topology /-- If a function `f` is differentiable in a convex open set and continuous on its closure, and its derivative converges to a limit `f'` at a point on the boundary, then `f` is differentiable there with derivative `f'`. -/ theorem hasFDerivWithinAt_closure_of_tendsto_fderiv {f : E → F} {s : Set E} {x : E} {f' : E →L[ℝ] F} (f_diff : DifferentiableOn ℝ f s) (s_conv : Convex ℝ s) (s_open : IsOpen s) (f_cont : ∀ y ∈ closure s, ContinuousWithinAt f s y) (h : Tendsto (fun y => fderiv ℝ f y) (𝓝[s] x) (𝓝 f')) : HasFDerivWithinAt f f' (closure s) x := by classical -- one can assume without loss of generality that `x` belongs to the closure of `s`, as the -- statement is empty otherwise by_cases hx : x ∉ closure s · rw [← closure_closure] at hx; exact hasFDerivWithinAt_of_nmem_closure hx push_neg at hx rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO, Asymptotics.isLittleO_iff] /- One needs to show that `‖f y - f x - f' (y - x)‖ ≀ ε ‖y - x‖` for `y` close to `x` in `closure s`, where `ε` is an arbitrary positive constant. By continuity of the functions, it suffices to prove this for nearby points inside `s`. In a neighborhood of `x`, the derivative of `f` is arbitrarily close to `f'` by assumption. The mean value inequality completes the proof. -/ intro ε ε_pos obtain ⟹ή, ÎŽ_pos, hΎ⟩ : ∃ ÎŽ > 0, ∀ y ∈ s, dist y x < ÎŽ → ‖fderiv ℝ f y - f'‖ < ε := by simpa [dist_zero_right] using tendsto_nhdsWithin_nhds.1 h ε ε_pos set B := ball x ÎŽ suffices ∀ y ∈ B ∩ closure s, ‖f y - f x - (f' y - f' x)‖ ≀ ε * ‖y - x‖ from mem_nhdsWithin_iff.2 ⟹ή, ÎŽ_pos, fun y hy => by simpa using this y hy⟩ suffices ∀ p : E × E, p ∈ closure ((B ∩ s) ×ˢ (B ∩ s)) → ‖f p.2 - f p.1 - (f' p.2 - f' p.1)‖ ≀ ε * ‖p.2 - p.1‖ by rw [closure_prod_eq] at this intro y y_in apply this ⟹x, y⟩ have : B ∩ closure s ⊆ closure (B ∩ s) := isOpen_ball.inter_closure exact ⟹this ⟹mem_ball_self ÎŽ_pos, hx⟩, this y_in⟩ have key : ∀ p : E × E, p ∈ (B ∩ s) ×ˢ (B ∩ s) → ‖f p.2 - f p.1 - (f' p.2 - f' p.1)‖ ≀ ε * ‖p.2 - p.1‖ := by rintro ⟹u, v⟩ ⟹u_in, v_in⟩ have conv : Convex ℝ (B ∩ s) := (convex_ball _ _).inter s_conv have diff : DifferentiableOn ℝ f (B ∩ s) := f_diff.mono inter_subset_right have bound : ∀ z ∈ B ∩ s, ‖fderivWithin ℝ f (B ∩ s) z - f'‖ ≀ ε := by intro z z_in have h := hÎŽ z have : fderivWithin ℝ f (B ∩ s) z = fderiv ℝ f z := by have op : IsOpen (B ∩ s) := isOpen_ball.inter s_open rw [DifferentiableAt.fderivWithin _ (op.uniqueDiffOn z z_in)] exact (diff z z_in).differentiableAt (IsOpen.mem_nhds op z_in) rw [← this] at h exact le_of_lt (h z_in.2 z_in.1) simpa using conv.norm_image_sub_le_of_norm_fderivWithin_le' diff bound u_in v_in rintro ⟹u, v⟩ uv_in have f_cont' : ∀ y ∈ closure s, ContinuousWithinAt (f - ⇑f') s y := by intro y y_in exact Tendsto.sub (f_cont y y_in) f'.cont.continuousWithinAt refine ContinuousWithinAt.closure_le uv_in ?_ ?_ key all_goals -- common start for both continuity proofs have : (B ∩ s) ×ˢ (B ∩ s) ⊆ s ×ˢ s := by gcongr <;> exact inter_subset_right obtain ⟹u_in, v_in⟩ : u ∈ closure s ∧ v ∈ closure s := by simpa [closure_prod_eq] using closure_mono this uv_in apply ContinuousWithinAt.mono _ this simp only [ContinuousWithinAt] · rw [nhdsWithin_prod_eq] have : ∀ u v, f v - f u - (f' v - f' u) = f v - f' v - (f u - f' u) := by intros; abel simp only [this] exact Tendsto.comp continuous_norm.continuousAt ((Tendsto.comp (f_cont' v v_in) tendsto_snd).sub <| Tendsto.comp (f_cont' u u_in) tendsto_fst) · apply tendsto_nhdsWithin_of_tendsto_nhds rw [nhds_prod_eq] exact tendsto_const_nhds.mul (Tendsto.comp continuous_norm.continuousAt <| tendsto_snd.sub tendsto_fst) @[deprecated (since := "2024-07-10")] alias has_fderiv_at_boundary_of_tendsto_fderiv := hasFDerivWithinAt_closure_of_tendsto_fderiv /-- If a function is differentiable on the right of a point `a : ℝ`, continuous at `a`, and its derivative also converges at `a`, then `f` is differentiable on the right at `a`. -/ theorem hasDerivWithinAt_Ici_of_tendsto_deriv {s : Set ℝ} {e : E} {a : ℝ} {f : ℝ → E} (f_diff : DifferentiableOn ℝ f s) (f_lim : ContinuousWithinAt f s a) (hs : s ∈ 𝓝[>] a) (f_lim' : Tendsto (fun x => deriv f x) (𝓝[>] a) (𝓝 e)) : HasDerivWithinAt f e (Ici a) a := by /- This is a specialization of `hasFDerivWithinAt_closure_of_tendsto_fderiv`. To be in the setting of this theorem, we need to work on an open interval with closure contained in `s ∪ {a}`, that we call `t = (a, b)`. Then, we check all the assumptions of this theorem and we apply it. -/ obtain ⟹b, ab : a < b, sab : Ioc a b ⊆ s⟩ := mem_nhdsWithin_Ioi_iff_exists_Ioc_subset.1 hs let t := Ioo a b have ts : t ⊆ s := Subset.trans Ioo_subset_Ioc_self sab have t_diff : DifferentiableOn ℝ f t := f_diff.mono ts have t_conv : Convex ℝ t := convex_Ioo a b have t_open : IsOpen t := isOpen_Ioo have t_closure : closure t = Icc a b := closure_Ioo ab.ne have t_cont : ∀ y ∈ closure t, ContinuousWithinAt f t y := by rw [t_closure] intro y hy by_cases h : y = a · rw [h]; exact f_lim.mono ts · have : y ∈ s := sab ⟹lt_of_le_of_ne hy.1 (Ne.symm h), hy.2⟩ exact (f_diff.continuousOn y this).mono ts have t_diff' : Tendsto (fun x => fderiv ℝ f x) (𝓝[t] a) (𝓝 (smulRight (1 : ℝ →L[ℝ] ℝ) e)) := by simp only [deriv_fderiv.symm] exact Tendsto.comp (isBoundedBilinearMap_smulRight : IsBoundedBilinearMap ℝ _).continuous_right.continuousAt (tendsto_nhdsWithin_mono_left Ioo_subset_Ioi_self f_lim') -- now we can apply `hasFDerivWithinAt_closure_of_tendsto_fderiv` have : HasDerivWithinAt f e (Icc a b) a := by rw [hasDerivWithinAt_iff_hasFDerivWithinAt, ← t_closure] exact hasFDerivWithinAt_closure_of_tendsto_fderiv t_diff t_conv t_open t_cont t_diff' exact this.mono_of_mem (Icc_mem_nhdsWithin_Ici <| left_mem_Ico.2 ab) @[deprecated (since := "2024-07-10")] alias has_deriv_at_interval_left_endpoint_of_tendsto_deriv := hasDerivWithinAt_Ici_of_tendsto_deriv /-- If a function is differentiable on the left of a point `a : ℝ`, continuous at `a`, and its derivative also converges at `a`, then `f` is differentiable on the left at `a`. -/ theorem hasDerivWithinAt_Iic_of_tendsto_deriv {s : Set ℝ} {e : E} {a : ℝ} {f : ℝ → E} (f_diff : DifferentiableOn ℝ f s) (f_lim : ContinuousWithinAt f s a) (hs : s ∈ 𝓝[<] a) (f_lim' : Tendsto (fun x => deriv f x) (𝓝[<] a) (𝓝 e)) : HasDerivWithinAt f e (Iic a) a := by /- This is a specialization of `hasFDerivWithinAt_closure_of_tendsto_fderiv`. To be in the setting of this theorem, we need to work on an open interval with closure contained in `s ∪ {a}`, that we call `t = (b, a)`. Then, we check all the assumptions of this theorem and we apply it. -/ obtain ⟹b, ba, sab⟩ : ∃ b ∈ Iio a, Ico b a ⊆ s := mem_nhdsWithin_Iio_iff_exists_Ico_subset.1 hs let t := Ioo b a have ts : t ⊆ s := Subset.trans Ioo_subset_Ico_self sab have t_diff : DifferentiableOn ℝ f t := f_diff.mono ts have t_conv : Convex ℝ t := convex_Ioo b a have t_open : IsOpen t := isOpen_Ioo have t_closure : closure t = Icc b a := closure_Ioo (ne_of_lt ba) have t_cont : ∀ y ∈ closure t, ContinuousWithinAt f t y := by rw [t_closure] intro y hy by_cases h : y = a · rw [h]; exact f_lim.mono ts · have : y ∈ s := sab ⟹hy.1, lt_of_le_of_ne hy.2 h⟩ exact (f_diff.continuousOn y this).mono ts have t_diff' : Tendsto (fun x => fderiv ℝ f x) (𝓝[t] a) (𝓝 (smulRight (1 : ℝ →L[ℝ] ℝ) e)) := by simp only [deriv_fderiv.symm] exact Tendsto.comp (isBoundedBilinearMap_smulRight : IsBoundedBilinearMap ℝ _).continuous_right.continuousAt (tendsto_nhdsWithin_mono_left Ioo_subset_Iio_self f_lim') -- now we can apply `hasFDerivWithinAt_closure_of_tendsto_fderiv` have : HasDerivWithinAt f e (Icc b a) a := by rw [hasDerivWithinAt_iff_hasFDerivWithinAt, ← t_closure] exact hasFDerivWithinAt_closure_of_tendsto_fderiv t_diff t_conv t_open t_cont t_diff' exact this.mono_of_mem (Icc_mem_nhdsWithin_Iic <| right_mem_Ioc.2 ba) @[deprecated (since := "2024-07-10")] alias has_deriv_at_interval_right_endpoint_of_tendsto_deriv := hasDerivWithinAt_Iic_of_tendsto_deriv /-- If a real function `f` has a derivative `g` everywhere but at a point, and `f` and `g` are continuous at this point, then `g` is also the derivative of `f` at this point. -/ theorem hasDerivAt_of_hasDerivAt_of_ne {f g : ℝ → E} {x : ℝ} (f_diff : ∀ y ≠ x, HasDerivAt f (g y) y) (hf : ContinuousAt f x) (hg : ContinuousAt g x) : HasDerivAt f (g x) x := by have A : HasDerivWithinAt f (g x) (Ici x) x := by have diff : DifferentiableOn ℝ f (Ioi x) := fun y hy => (f_diff y (ne_of_gt hy)).differentiableAt.differentiableWithinAt -- next line is the nontrivial bit of this proof, appealing to differentiability -- extension results. apply hasDerivWithinAt_Ici_of_tendsto_deriv diff hf.continuousWithinAt self_mem_nhdsWithin have : Tendsto g (𝓝[>] x) (𝓝 (g x)) := tendsto_inf_left hg apply this.congr' _ apply mem_of_superset self_mem_nhdsWithin fun y hy => _ intros y hy exact (f_diff y (ne_of_gt hy)).deriv.symm have B : HasDerivWithinAt f (g x) (Iic x) x := by have diff : DifferentiableOn ℝ f (Iio x) := fun y hy => (f_diff y (ne_of_lt hy)).differentiableAt.differentiableWithinAt -- next line is the nontrivial bit of this proof, appealing to differentiability -- extension results. apply hasDerivWithinAt_Iic_of_tendsto_deriv diff hf.continuousWithinAt self_mem_nhdsWithin have : Tendsto g (𝓝[<] x) (𝓝 (g x)) := tendsto_inf_left hg apply this.congr' _ apply mem_of_superset self_mem_nhdsWithin fun y hy => _ intros y hy exact (f_diff y (ne_of_lt hy)).deriv.symm simpa using B.union A /-- If a real function `f` has a derivative `g` everywhere but at a point, and `f` and `g` are continuous at this point, then `g` is the derivative of `f` everywhere. -/ theorem hasDerivAt_of_hasDerivAt_of_ne' {f g : ℝ → E} {x : ℝ} (f_diff : ∀ y ≠ x, HasDerivAt f (g y) y) (hf : ContinuousAt f x) (hg : ContinuousAt g x) (y : ℝ) : HasDerivAt f (g y) y := by rcases eq_or_ne y x with (rfl | hne) · exact hasDerivAt_of_hasDerivAt_of_ne f_diff hf hg · exact f_diff y hne
Analysis\Calculus\FDeriv\Linear.lean
/- 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 Mathlib.Analysis.Calculus.FDeriv.Basic import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps /-! # The derivative of bounded linear maps For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of bounded linear maps. -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} section ContinuousLinearMap /-! ### Continuous linear maps There are currently two variants of these in mathlib, the bundled version (named `ContinuousLinearMap`, and denoted `E →L[𝕜] F`), and the unbundled version (with a predicate `IsBoundedLinearMap`). We give statements for both versions. -/ @[fun_prop] protected theorem ContinuousLinearMap.hasStrictFDerivAt {x : E} : HasStrictFDerivAt e e x := (isLittleO_zero _ _).congr_left fun x => by simp only [e.map_sub, sub_self] protected theorem ContinuousLinearMap.hasFDerivAtFilter : HasFDerivAtFilter e e x L := .of_isLittleO <| (isLittleO_zero _ _).congr_left fun x => by simp only [e.map_sub, sub_self] @[fun_prop] protected theorem ContinuousLinearMap.hasFDerivWithinAt : HasFDerivWithinAt e e s x := e.hasFDerivAtFilter @[fun_prop] protected theorem ContinuousLinearMap.hasFDerivAt : HasFDerivAt e e x := e.hasFDerivAtFilter @[simp, fun_prop] protected theorem ContinuousLinearMap.differentiableAt : DifferentiableAt 𝕜 e x := e.hasFDerivAt.differentiableAt @[fun_prop] protected theorem ContinuousLinearMap.differentiableWithinAt : DifferentiableWithinAt 𝕜 e s x := e.differentiableAt.differentiableWithinAt @[simp] protected theorem ContinuousLinearMap.fderiv : fderiv 𝕜 e x = e := e.hasFDerivAt.fderiv protected theorem ContinuousLinearMap.fderivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 e s x = e := by rw [DifferentiableAt.fderivWithin e.differentiableAt hxs] exact e.fderiv @[simp, fun_prop] protected theorem ContinuousLinearMap.differentiable : Differentiable 𝕜 e := fun _ => e.differentiableAt @[fun_prop] protected theorem ContinuousLinearMap.differentiableOn : DifferentiableOn 𝕜 e s := e.differentiable.differentiableOn theorem IsBoundedLinearMap.hasFDerivAtFilter (h : IsBoundedLinearMap 𝕜 f) : HasFDerivAtFilter f h.toContinuousLinearMap x L := h.toContinuousLinearMap.hasFDerivAtFilter @[fun_prop] theorem IsBoundedLinearMap.hasFDerivWithinAt (h : IsBoundedLinearMap 𝕜 f) : HasFDerivWithinAt f h.toContinuousLinearMap s x := h.hasFDerivAtFilter @[fun_prop] theorem IsBoundedLinearMap.hasFDerivAt (h : IsBoundedLinearMap 𝕜 f) : HasFDerivAt f h.toContinuousLinearMap x := h.hasFDerivAtFilter @[fun_prop] theorem IsBoundedLinearMap.differentiableAt (h : IsBoundedLinearMap 𝕜 f) : DifferentiableAt 𝕜 f x := h.hasFDerivAt.differentiableAt @[fun_prop] theorem IsBoundedLinearMap.differentiableWithinAt (h : IsBoundedLinearMap 𝕜 f) : DifferentiableWithinAt 𝕜 f s x := h.differentiableAt.differentiableWithinAt theorem IsBoundedLinearMap.fderiv (h : IsBoundedLinearMap 𝕜 f) : fderiv 𝕜 f x = h.toContinuousLinearMap := HasFDerivAt.fderiv h.hasFDerivAt theorem IsBoundedLinearMap.fderivWithin (h : IsBoundedLinearMap 𝕜 f) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = h.toContinuousLinearMap := by rw [DifferentiableAt.fderivWithin h.differentiableAt hxs] exact h.fderiv @[fun_prop] theorem IsBoundedLinearMap.differentiable (h : IsBoundedLinearMap 𝕜 f) : Differentiable 𝕜 f := fun _ => h.differentiableAt @[fun_prop] theorem IsBoundedLinearMap.differentiableOn (h : IsBoundedLinearMap 𝕜 f) : DifferentiableOn 𝕜 f s := h.differentiable.differentiableOn end ContinuousLinearMap end
Analysis\Calculus\FDeriv\Measurable.lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps import Mathlib.Analysis.Normed.Module.FiniteDimension import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic /-! # Derivative is measurable In this file we prove that the derivative of any function with complete codomain is a measurable function. Namely, we prove: * `measurableSet_of_differentiableAt`: the set `{x | DifferentiableAt 𝕜 f x}` is measurable; * `measurable_fderiv`: the function `fderiv 𝕜 f` is measurable; * `measurable_fderiv_apply_const`: for a fixed vector `y`, the function `fun x ↩ fderiv 𝕜 f x y` is measurable; * `measurable_deriv`: the function `deriv f` is measurable (for `f : 𝕜 → F`). We also show the same results for the right derivative on the real line (see `measurable_derivWithin_Ici` and `measurable_derivWithin_Ioi`), following the same proof strategy. We also prove measurability statements for functions depending on a parameter: for `f : α → E → F`, we show the measurability of `(p : α × E) ↩ fderiv 𝕜 (f p.1) p.2`. This requires additional assumptions. We give versions of the above statements (appending `with_param` to their names) when `f` is continuous and `E` is locally compact. ## Implementation We give a proof that avoids second-countability issues, by expressing the differentiability set as a function of open sets in the following way. Define `A (L, r, ε)` to be the set of points where, on a ball of radius roughly `r` around `x`, the function is uniformly approximated by the linear map `L`, up to `ε r`. It is an open set. Let also `B (L, r, s, ε) = A (L, r, ε) ∩ A (L, s, ε)`: we require that at two possibly different scales `r` and `s`, the function is well approximated by the linear map `L`. It is also open. We claim that the differentiability set of `f` is exactly `D = ⋂ ε > 0, ⋃ ÎŽ > 0, ⋂ r, s < ÎŽ, ⋃ L, B (L, r, s, ε)`. In other words, for any `ε > 0`, we require that there is a size `ÎŽ` such that, for any two scales below this size, the function is well approximated by a linear map, common to the two scales. The set `⋃ L, B (L, r, s, ε)` is open, as a union of open sets. Converting the intersections and unions to countable ones (using real numbers of the form `2 ^ (-n)`), it follows that the differentiability set is measurable. To prove the claim, there are two inclusions. One is trivial: if the function is differentiable at `x`, then `x` belongs to `D` (just take `L` to be the derivative, and use that the differentiability exactly says that the map is well approximated by `L`). This is proved in `mem_A_of_differentiable` and `differentiable_set_subset_D`. For the other direction, the difficulty is that `L` in the union may depend on `ε, r, s`. The key point is that, in fact, it doesn't depend too much on them. First, if `x` belongs both to `A (L, r, ε)` and `A (L', r, ε)`, then `L` and `L'` have to be close on a shell, and thus `‖L - L'‖` is bounded by `ε` (see `norm_sub_le_of_mem_A`). Assume now `x ∈ D`. If one has two maps `L` and `L'` such that `x` belongs to `A (L, r, ε)` and to `A (L', r', ε')`, one deduces that `L` is close to `L'` by arguing as follows. Consider another scale `s` smaller than `r` and `r'`. Take a linear map `L₁` that approximates `f` around `x` both at scales `r` and `s` w.r.t. `ε` (it exists as `x` belongs to `D`). Take also `L₂` that approximates `f` around `x` both at scales `r'` and `s` w.r.t. `ε'`. Then `L₁` is close to `L` (as they are close on a shell of radius `r`), and `L₂` is close to `L₁` (as they are close on a shell of radius `s`), and `L'` is close to `L₂` (as they are close on a shell of radius `r'`). It follows that `L` is close to `L'`, as we claimed. It follows that the different approximating linear maps that show up form a Cauchy sequence when `ε` tends to `0`. When the target space is complete, this sequence converges, to a limit `f'`. With the same kind of arguments, one checks that `f` is differentiable with derivative `f'`. To show that the derivative itself is measurable, add in the definition of `B` and `D` a set `K` of continuous linear maps to which `L` should belong. Then, when `K` is complete, the set `D K` is exactly the set of points where `f` is differentiable with a derivative in `K`. ## Tags derivative, measurable function, Borel σ-algebra -/ noncomputable section open Set Metric Asymptotics Filter ContinuousLinearMap MeasureTheory TopologicalSpace open scoped Topology namespace ContinuousLinearMap variable {𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] theorem measurable_apply₂ [MeasurableSpace E] [OpensMeasurableSpace E] [SecondCountableTopologyEither (E →L[𝕜] F) E] [MeasurableSpace F] [BorelSpace F] : Measurable fun p : (E →L[𝕜] F) × E => p.1 p.2 := isBoundedBilinearMap_apply.continuous.measurable end ContinuousLinearMap section fderiv variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f : E → F} (K : Set (E →L[𝕜] F)) namespace FDerivMeasurableAux /-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated at scale `r` by the linear map `L`, up to an error `ε`. We tweak the definition to make sure that this is an open set. -/ def A (f : E → F) (L : E →L[𝕜] F) (r ε : ℝ) : Set E := { x | ∃ r' ∈ Ioc (r / 2) r, ∀ y ∈ ball x r', ∀ z ∈ ball x r', ‖f z - f y - L (z - y)‖ < ε * r } /-- The set `B f K r s ε` is the set of points `x` around which there exists a continuous linear map `L` belonging to `K` (a given set of continuous linear maps) that approximates well the function `f` (up to an error `ε`), simultaneously at scales `r` and `s`. -/ def B (f : E → F) (K : Set (E →L[𝕜] F)) (r s ε : ℝ) : Set E := ⋃ L ∈ K, A f L r ε ∩ A f L s ε /-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its main use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable, with a derivative in `K`. -/ def D (f : E → F) (K : Set (E →L[𝕜] F)) : Set E := ⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), B f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e) theorem isOpen_A (L : E →L[𝕜] F) (r ε : ℝ) : IsOpen (A f L r ε) := by rw [Metric.isOpen_iff] rintro x ⟹r', r'_mem, hr'⟩ obtain ⟹s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between r'_mem.1 have : s ∈ Ioc (r / 2) r := ⟹s_gt, le_of_lt (s_lt.trans_le r'_mem.2)⟩ refine ⟹r' - s, by linarith, fun x' hx' => ⟹s, this, ?_⟩⟩ have B : ball x' s ⊆ ball x r' := ball_subset (le_of_lt hx') intro y hy z hz exact hr' y (B hy) z (B hz) theorem isOpen_B {K : Set (E →L[𝕜] F)} {r s ε : ℝ} : IsOpen (B f K r s ε) := by simp [B, isOpen_biUnion, IsOpen.inter, isOpen_A] theorem A_mono (L : E →L[𝕜] F) (r : ℝ) {ε ÎŽ : ℝ} (h : ε ≀ ÎŽ) : A f L r ε ⊆ A f L r ÎŽ := by rintro x ⟹r', r'r, hr'⟩ refine ⟹r', r'r, fun y hy z hz => (hr' y hy z hz).trans_le (mul_le_mul_of_nonneg_right h ?_)⟩ linarith [mem_ball.1 hy, r'r.2, @dist_nonneg _ _ y x] theorem le_of_mem_A {r ε : ℝ} {L : E →L[𝕜] F} {x : E} (hx : x ∈ A f L r ε) {y z : E} (hy : y ∈ closedBall x (r / 2)) (hz : z ∈ closedBall x (r / 2)) : ‖f z - f y - L (z - y)‖ ≀ ε * r := by rcases hx with ⟹r', r'mem, hr'⟩ apply le_of_lt exact hr' _ ((mem_closedBall.1 hy).trans_lt r'mem.1) _ ((mem_closedBall.1 hz).trans_lt r'mem.1) theorem mem_A_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : E} (hx : DifferentiableAt 𝕜 f x) : ∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ A f (fderiv 𝕜 f x) r ε := by let ÎŽ := (ε / 2) / 2 obtain ⟹R, R_pos, hR⟩ : ∃ R > 0, ∀ y ∈ ball x R, ‖f y - f x - fderiv 𝕜 f x (y - x)‖ ≀ ÎŽ * ‖y - x‖ := eventually_nhds_iff_ball.1 <| hx.hasFDerivAt.isLittleO.bound <| by positivity refine ⟹R, R_pos, fun r hr => ?_⟩ have : r ∈ Ioc (r / 2) r := right_mem_Ioc.2 <| half_lt_self hr.1 refine ⟹r, this, fun y hy z hz => ?_⟩ calc ‖f z - f y - (fderiv 𝕜 f x) (z - y)‖ = ‖f z - f x - (fderiv 𝕜 f x) (z - x) - (f y - f x - (fderiv 𝕜 f x) (y - x))‖ := by simp only [map_sub]; abel_nf _ ≀ ‖f z - f x - (fderiv 𝕜 f x) (z - x)‖ + ‖f y - f x - (fderiv 𝕜 f x) (y - x)‖ := norm_sub_le _ _ _ ≀ ÎŽ * ‖z - x‖ + ÎŽ * ‖y - x‖ := add_le_add (hR _ (ball_subset_ball hr.2.le hz)) (hR _ (ball_subset_ball hr.2.le hy)) _ ≀ ÎŽ * r + ÎŽ * r := by rw [mem_ball_iff_norm] at hz hy; gcongr _ = (ε / 2) * r := by ring _ < ε * r := by gcongr; exacts [hr.1, half_lt_self hε] theorem norm_sub_le_of_mem_A {c : 𝕜} (hc : 1 < ‖c‖) {r ε : ℝ} (hε : 0 < ε) (hr : 0 < r) {x : E} {L₁ L₂ : E →L[𝕜] F} (h₁ : x ∈ A f L₁ r ε) (h₂ : x ∈ A f L₂ r ε) : ‖L₁ - L₂‖ ≀ 4 * ‖c‖ * ε := by refine opNorm_le_of_shell (half_pos hr) (by positivity) hc ?_ intro y ley ylt rw [div_div, div_le_iff' (mul_pos (by norm_num : (0 : ℝ) < 2) (zero_lt_one.trans hc))] at ley calc ‖(L₁ - L₂) y‖ = ‖f (x + y) - f x - L₂ (x + y - x) - (f (x + y) - f x - L₁ (x + y - x))‖ := by simp _ ≀ ‖f (x + y) - f x - L₂ (x + y - x)‖ + ‖f (x + y) - f x - L₁ (x + y - x)‖ := norm_sub_le _ _ _ ≀ ε * r + ε * r := by apply add_le_add · apply le_of_mem_A h₂ · simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self] · simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le] · apply le_of_mem_A h₁ · simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self] · simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le] _ = 2 * ε * r := by ring _ ≀ 2 * ε * (2 * ‖c‖ * ‖y‖) := by gcongr _ = 4 * ‖c‖ * ε * ‖y‖ := by ring /-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/ theorem differentiable_set_subset_D : { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } ⊆ D f K := by intro x hx rw [D, mem_iInter] intro e have : (0 : ℝ) < (1 / 2) ^ e := by positivity rcases mem_A_of_differentiable this hx.1 with ⟹R, R_pos, hR⟩ obtain ⟹n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R := exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1) simp only [mem_iUnion, mem_iInter, B, mem_inter_iff] refine ⟹n, fun p hp q hq => ⟹fderiv 𝕜 f x, hx.2, ⟹?_, ?_⟩⟩⟩ <;> · refine hR _ ⟹pow_pos (by norm_num) _, lt_of_le_of_lt ?_ hn⟩ exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption) /-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/ theorem D_subset_differentiable_set {K : Set (E →L[𝕜] F)} (hK : IsComplete K) : D f K ⊆ { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := fun {n} => pow_pos (by norm_num) n rcases NormedField.exists_one_lt_norm 𝕜 with ⟹c, hc⟩ intro x hx have : ∀ e : ℕ, ∃ n : ℕ, ∀ p q, n ≀ p → n ≀ q → ∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) := by intro e have := mem_iInter.1 hx e rcases mem_iUnion.1 this with ⟹n, hn⟩ refine ⟹n, fun p q hp hq => ?_⟩ simp only [mem_iInter] at hn rcases mem_iUnion.1 (hn p hp q hq) with ⟹L, hL⟩ exact ⟹L, exists_prop.mp <| mem_iUnion.1 hL⟩ /- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K` such that, for `p, q ≥ n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and `2 ^ (-q)`, with an error `2 ^ (-e)`. -/ choose! n L hn using this /- All the operators `L e p q` that show up are close to each other. To prove this, we argue that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale `2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale `2 ^ (- p')`. -/ have M : ∀ e p q e' p' q', n e ≀ p → n e ≀ q → n e' ≀ p' → n e' ≀ q' → e ≀ e' → ‖L e p q - L e' p' q'‖ ≀ 12 * ‖c‖ * (1 / 2) ^ e := by intro e p q e' p' q' hp hq hp' hq' he' let r := max (n e) (n e') have I : ((1 : ℝ) / 2) ^ e' ≀ (1 / 2) ^ e := pow_le_pow_of_le_one (by norm_num) (by norm_num) he' have J1 : ‖L e p q - L e p r‖ ≀ 4 * ‖c‖ * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1 have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.1 exact norm_sub_le_of_mem_A hc P P I1 I2 have J2 : ‖L e p r - L e' p' r‖ ≀ 4 * ‖c‖ * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2 have I2 : x ∈ A f (L e' p' r) ((1 / 2) ^ r) ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.2 exact norm_sub_le_of_mem_A hc P P I1 (A_mono _ _ I I2) have J3 : ‖L e' p' r - L e' p' q'‖ ≀ 4 * ‖c‖ * (1 / 2) ^ e := by have I1 : x ∈ A f (L e' p' r) ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.1 have I2 : x ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' q' hp' hq').2.1 exact norm_sub_le_of_mem_A hc P P (A_mono _ _ I I1) (A_mono _ _ I I2) calc ‖L e p q - L e' p' q'‖ = ‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ := by congr 1; abel _ ≀ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ := norm_add₃_le _ _ _ _ ≀ 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e := by gcongr _ = 12 * ‖c‖ * (1 / 2) ^ e := by ring /- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this is a Cauchy sequence. -/ let L0 : ℕ → E →L[𝕜] F := fun e => L e (n e) (n e) have : CauchySeq L0 := by rw [Metric.cauchySeq_iff'] intro ε εpos obtain ⟹e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (12 * ‖c‖) := exists_pow_lt_of_lt_one (by positivity) (by norm_num) refine ⟹e, fun e' he' => ?_⟩ rw [dist_comm, dist_eq_norm] calc ‖L0 e - L0 e'‖ ≀ 12 * ‖c‖ * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he' _ < 12 * ‖c‖ * (ε / (12 * ‖c‖)) := by gcongr _ = ε := by field_simp -- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`. obtain ⟹f', f'K, hf'⟩ : ∃ f' ∈ K, Tendsto L0 atTop (𝓝 f') := cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this have Lf' : ∀ e p, n e ≀ p → ‖L e (n e) p - f'‖ ≀ 12 * ‖c‖ * (1 / 2) ^ e := by intro e p hp apply le_of_tendsto (tendsto_const_nhds.sub hf').norm rw [eventually_atTop] exact ⟹e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩ -- Let us show that `f` has derivative `f'` at `x`. have : HasFDerivAt f f' x := by simp only [hasFDerivAt_iff_isLittleO_nhds_zero, isLittleO_iff] /- to get an approximation with a precision `ε`, we will replace `f` with `L e (n e) m` for some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`, this makes it possible to cover all scales, and thus to obtain a good linear approximation in the whole ball of radius `(1/2)^(n e)`. -/ intro ε εpos have pos : 0 < 4 + 12 * ‖c‖ := by positivity obtain ⟹e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (4 + 12 * ‖c‖) := exists_pow_lt_of_lt_one (div_pos εpos pos) (by norm_num) rw [eventually_nhds_iff_ball] refine ⟹(1 / 2) ^ (n e + 1), P, fun y hy => ?_⟩ -- We need to show that `f (x + y) - f x - f' y` is small. For this, we will work at scale -- `k` where `k` is chosen with `‖y‖ ∌ 2 ^ (-k)`. by_cases y_pos : y = 0 · simp [y_pos] have yzero : 0 < ‖y‖ := norm_pos_iff.mpr y_pos have y_lt : ‖y‖ < (1 / 2) ^ (n e + 1) := by simpa using mem_ball_iff_norm.1 hy have yone : ‖y‖ ≀ 1 := le_trans y_lt.le (pow_le_one _ (by norm_num) (by norm_num)) -- define the scale `k`. obtain ⟹k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < ‖y‖ ∧ ‖y‖ ≀ (1 / 2) ^ k := exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num : (1 : ℝ) / 2 < 1) -- the scale is large enough (as `y` is small enough) have k_gt : n e < k := by have : ((1 : ℝ) / 2) ^ (k + 1) < (1 / 2) ^ (n e + 1) := lt_trans hk y_lt rw [pow_lt_pow_iff_right_of_lt_one (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num)] at this omega set m := k - 1 have m_ge : n e ≀ m := Nat.le_sub_one_of_lt k_gt have km : k = m + 1 := (Nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm rw [km] at hk h'k -- `f` is well approximated by `L e (n e) k` at the relevant scale -- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`). have J1 : ‖f (x + y) - f x - L e (n e) m (x + y - x)‖ ≀ (1 / 2) ^ e * (1 / 2) ^ m := by apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2 · simp only [mem_closedBall, dist_self] positivity · simpa only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, pow_succ, mul_one_div] using h'k have J2 : ‖f (x + y) - f x - L e (n e) m y‖ ≀ 4 * (1 / 2) ^ e * ‖y‖ := calc ‖f (x + y) - f x - L e (n e) m y‖ ≀ (1 / 2) ^ e * (1 / 2) ^ m := by simpa only [add_sub_cancel_left] using J1 _ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) := by field_simp; ring _ ≀ 4 * (1 / 2) ^ e * ‖y‖ := by gcongr -- use the previous estimates to see that `f (x + y) - f x - f' y` is small. calc ‖f (x + y) - f x - f' y‖ = ‖f (x + y) - f x - L e (n e) m y + (L e (n e) m - f') y‖ := congr_arg _ (by simp) _ ≀ 4 * (1 / 2) ^ e * ‖y‖ + 12 * ‖c‖ * (1 / 2) ^ e * ‖y‖ := norm_add_le_of_le J2 <| (le_opNorm _ _).trans <| by gcongr; exact Lf' _ _ m_ge _ = (4 + 12 * ‖c‖) * ‖y‖ * (1 / 2) ^ e := by ring _ ≀ (4 + 12 * ‖c‖) * ‖y‖ * (ε / (4 + 12 * ‖c‖)) := by gcongr _ = ε * ‖y‖ := by field_simp [ne_of_gt pos]; ring rw [← this.fderiv] at f'K exact ⟹this.differentiableAt, f'K⟩ theorem differentiable_set_eq_D (hK : IsComplete K) : { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } = D f K := Subset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK) end FDerivMeasurableAux open FDerivMeasurableAux variable [MeasurableSpace E] [OpensMeasurableSpace E] variable (𝕜 f) /-- The set of differentiability points of a function, with derivative in a given complete set, is Borel-measurable. -/ theorem measurableSet_of_differentiableAt_of_isComplete {K : Set (E →L[𝕜] F)} (hK : IsComplete K) : MeasurableSet { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by -- Porting note: was -- simp [differentiable_set_eq_D K hK, D, isOpen_B.measurableSet, MeasurableSet.iInter, -- MeasurableSet.iUnion] simp only [D, differentiable_set_eq_D K hK] repeat apply_rules [MeasurableSet.iUnion, MeasurableSet.iInter] <;> intro exact isOpen_B.measurableSet variable [CompleteSpace F] /-- The set of differentiability points of a function taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableAt : MeasurableSet { x | DifferentiableAt 𝕜 f x } := by have : IsComplete (univ : Set (E →L[𝕜] F)) := complete_univ convert measurableSet_of_differentiableAt_of_isComplete 𝕜 f this simp @[measurability, fun_prop] theorem measurable_fderiv : Measurable (fderiv 𝕜 f) := by refine measurable_of_isClosed fun s hs => ?_ have : fderiv 𝕜 f ⁻¹' s = { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ s } ∪ { x | ¬DifferentiableAt 𝕜 f x } ∩ { _x | (0 : E →L[𝕜] F) ∈ s } := Set.ext fun x => mem_preimage.trans fderiv_mem_iff rw [this] exact (measurableSet_of_differentiableAt_of_isComplete _ _ hs.isComplete).union ((measurableSet_of_differentiableAt _ _).compl.inter (MeasurableSet.const _)) @[measurability, fun_prop] theorem measurable_fderiv_apply_const [MeasurableSpace F] [BorelSpace F] (y : E) : Measurable fun x => fderiv 𝕜 f x y := (ContinuousLinearMap.measurable_apply y).comp (measurable_fderiv 𝕜 f) variable {𝕜} @[measurability, fun_prop] theorem measurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F] [BorelSpace F] (f : 𝕜 → F) : Measurable (deriv f) := by simpa only [fderiv_deriv] using measurable_fderiv_apply_const 𝕜 f 1 theorem stronglyMeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [h : SecondCountableTopologyEither 𝕜 F] (f : 𝕜 → F) : StronglyMeasurable (deriv f) := by borelize F rcases h.out with h𝕜|hF · exact stronglyMeasurable_iff_measurable_separable.2 ⟹measurable_deriv f, isSeparable_range_deriv _⟩ · exact (measurable_deriv f).stronglyMeasurable theorem aemeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F] [BorelSpace F] (f : 𝕜 → F) (ÎŒ : Measure 𝕜) : AEMeasurable (deriv f) ÎŒ := (measurable_deriv f).aemeasurable theorem aestronglyMeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [SecondCountableTopologyEither 𝕜 F] (f : 𝕜 → F) (ÎŒ : Measure 𝕜) : AEStronglyMeasurable (deriv f) ÎŒ := (stronglyMeasurable_deriv f).aestronglyMeasurable end fderiv section RightDeriv variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] variable {f : ℝ → F} (K : Set F) namespace RightDerivMeasurableAux /-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated at scale `r` by the linear map `h ↩ h • L`, up to an error `ε`. We tweak the definition to make sure that this is open on the right. -/ def A (f : ℝ → F) (L : F) (r ε : ℝ) : Set ℝ := { x | ∃ r' ∈ Ioc (r / 2) r, ∀ᵉ (y ∈ Icc x (x + r')) (z ∈ Icc x (x + r')), ‖f z - f y - (z - y) • L‖ ≀ ε * r } /-- The set `B f K r s ε` is the set of points `x` around which there exists a vector `L` belonging to `K` (a given set of vectors) such that `h • L` approximates well `f (x + h)` (up to an error `ε`), simultaneously at scales `r` and `s`. -/ def B (f : ℝ → F) (K : Set F) (r s ε : ℝ) : Set ℝ := ⋃ L ∈ K, A f L r ε ∩ A f L s ε /-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its main use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable, with a derivative in `K`. -/ def D (f : ℝ → F) (K : Set F) : Set ℝ := ⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), B f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e) theorem A_mem_nhdsWithin_Ioi {L : F} {r ε x : ℝ} (hx : x ∈ A f L r ε) : A f L r ε ∈ 𝓝[>] x := by rcases hx with ⟹r', rr', hr'⟩ rw [mem_nhdsWithin_Ioi_iff_exists_Ioo_subset] obtain ⟹s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between rr'.1 have : s ∈ Ioc (r / 2) r := ⟹s_gt, le_of_lt (s_lt.trans_le rr'.2)⟩ refine ⟹x + r' - s, by simp only [mem_Ioi]; linarith, fun x' hx' => ⟹s, this, ?_⟩⟩ have A : Icc x' (x' + s) ⊆ Icc x (x + r') := by apply Icc_subset_Icc hx'.1.le linarith [hx'.2] intro y hy z hz exact hr' y (A hy) z (A hz) theorem B_mem_nhdsWithin_Ioi {K : Set F} {r s ε x : ℝ} (hx : x ∈ B f K r s ε) : B f K r s ε ∈ 𝓝[>] x := by obtain ⟹L, LK, hL₁, hL₂⟩ : ∃ L : F, L ∈ K ∧ x ∈ A f L r ε ∧ x ∈ A f L s ε := by simpa only [B, mem_iUnion, mem_inter_iff, exists_prop] using hx filter_upwards [A_mem_nhdsWithin_Ioi hL₁, A_mem_nhdsWithin_Ioi hL₂] with y hy₁ hy₂ simp only [B, mem_iUnion, mem_inter_iff, exists_prop] exact ⟹L, LK, hy₁, hy₂⟩ theorem measurableSet_B {K : Set F} {r s ε : ℝ} : MeasurableSet (B f K r s ε) := measurableSet_of_mem_nhdsWithin_Ioi fun _ hx => B_mem_nhdsWithin_Ioi hx theorem A_mono (L : F) (r : ℝ) {ε ÎŽ : ℝ} (h : ε ≀ ÎŽ) : A f L r ε ⊆ A f L r ÎŽ := by rintro x ⟹r', r'r, hr'⟩ refine ⟹r', r'r, fun y hy z hz => (hr' y hy z hz).trans (mul_le_mul_of_nonneg_right h ?_)⟩ linarith [hy.1, hy.2, r'r.2] theorem le_of_mem_A {r ε : ℝ} {L : F} {x : ℝ} (hx : x ∈ A f L r ε) {y z : ℝ} (hy : y ∈ Icc x (x + r / 2)) (hz : z ∈ Icc x (x + r / 2)) : ‖f z - f y - (z - y) • L‖ ≀ ε * r := by rcases hx with ⟹r', r'mem, hr'⟩ have A : x + r / 2 ≀ x + r' := by linarith [r'mem.1] exact hr' _ ((Icc_subset_Icc le_rfl A) hy) _ ((Icc_subset_Icc le_rfl A) hz) theorem mem_A_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : ℝ} (hx : DifferentiableWithinAt ℝ f (Ici x) x) : ∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ A f (derivWithin f (Ici x) x) r ε := by have := hx.hasDerivWithinAt simp_rw [hasDerivWithinAt_iff_isLittleO, isLittleO_iff] at this rcases mem_nhdsWithin_Ici_iff_exists_Ico_subset.1 (this (half_pos hε)) with ⟹m, xm, hm⟩ refine ⟹m - x, by linarith [show x < m from xm], fun r hr => ?_⟩ have : r ∈ Ioc (r / 2) r := ⟹half_lt_self hr.1, le_rfl⟩ refine ⟹r, this, fun y hy z hz => ?_⟩ calc ‖f z - f y - (z - y) • derivWithin f (Ici x) x‖ = ‖f z - f x - (z - x) • derivWithin f (Ici x) x - (f y - f x - (y - x) • derivWithin f (Ici x) x)‖ := by congr 1; simp only [sub_smul]; abel _ ≀ ‖f z - f x - (z - x) • derivWithin f (Ici x) x‖ + ‖f y - f x - (y - x) • derivWithin f (Ici x) x‖ := (norm_sub_le _ _) _ ≀ ε / 2 * ‖z - x‖ + ε / 2 * ‖y - x‖ := (add_le_add (hm ⟹hz.1, hz.2.trans_lt (by linarith [hr.2])⟩) (hm ⟹hy.1, hy.2.trans_lt (by linarith [hr.2])⟩)) _ ≀ ε / 2 * r + ε / 2 * r := by gcongr · rw [Real.norm_of_nonneg] <;> linarith [hz.1, hz.2] · rw [Real.norm_of_nonneg] <;> linarith [hy.1, hy.2] _ = ε * r := by ring theorem norm_sub_le_of_mem_A {r x : ℝ} (hr : 0 < r) (ε : ℝ) {L₁ L₂ : F} (h₁ : x ∈ A f L₁ r ε) (h₂ : x ∈ A f L₂ r ε) : ‖L₁ - L₂‖ ≀ 4 * ε := by suffices H : ‖(r / 2) • (L₁ - L₂)‖ ≀ r / 2 * (4 * ε) by rwa [norm_smul, Real.norm_of_nonneg (half_pos hr).le, mul_le_mul_left (half_pos hr)] at H calc ‖(r / 2) • (L₁ - L₂)‖ = ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₂ - (f (x + r / 2) - f x - (x + r / 2 - x) • L₁)‖ := by simp [smul_sub] _ ≀ ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₂‖ + ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₁‖ := norm_sub_le _ _ _ ≀ ε * r + ε * r := by apply add_le_add · apply le_of_mem_A h₂ <;> simp [(half_pos hr).le] · apply le_of_mem_A h₁ <;> simp [(half_pos hr).le] _ = r / 2 * (4 * ε) := by ring /-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/ theorem differentiable_set_subset_D : { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } ⊆ D f K := by intro x hx rw [D, mem_iInter] intro e have : (0 : ℝ) < (1 / 2) ^ e := pow_pos (by norm_num) _ rcases mem_A_of_differentiable this hx.1 with ⟹R, R_pos, hR⟩ obtain ⟹n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R := exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1) simp only [mem_iUnion, mem_iInter, B, mem_inter_iff] refine ⟹n, fun p hp q hq => ⟹derivWithin f (Ici x) x, hx.2, ⟹?_, ?_⟩⟩⟩ <;> · refine hR _ ⟹pow_pos (by norm_num) _, lt_of_le_of_lt ?_ hn⟩ exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption) /-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/ theorem D_subset_differentiable_set {K : Set F} (hK : IsComplete K) : D f K ⊆ { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } := by have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := fun {n} => pow_pos (by norm_num) n intro x hx have : ∀ e : ℕ, ∃ n : ℕ, ∀ p q, n ≀ p → n ≀ q → ∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) := by intro e have := mem_iInter.1 hx e rcases mem_iUnion.1 this with ⟹n, hn⟩ refine ⟹n, fun p q hp hq => ?_⟩ simp only [mem_iInter] at hn rcases mem_iUnion.1 (hn p hp q hq) with ⟹L, hL⟩ exact ⟹L, exists_prop.mp <| mem_iUnion.1 hL⟩ /- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K` such that, for `p, q ≥ n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and `2 ^ (-q)`, with an error `2 ^ (-e)`. -/ choose! n L hn using this /- All the operators `L e p q` that show up are close to each other. To prove this, we argue that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale `2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale `2 ^ (- p')`. -/ have M : ∀ e p q e' p' q', n e ≀ p → n e ≀ q → n e' ≀ p' → n e' ≀ q' → e ≀ e' → ‖L e p q - L e' p' q'‖ ≀ 12 * (1 / 2) ^ e := by intro e p q e' p' q' hp hq hp' hq' he' let r := max (n e) (n e') have I : ((1 : ℝ) / 2) ^ e' ≀ (1 / 2) ^ e := pow_le_pow_of_le_one (by norm_num) (by norm_num) he' have J1 : ‖L e p q - L e p r‖ ≀ 4 * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1 have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.1 exact norm_sub_le_of_mem_A P _ I1 I2 have J2 : ‖L e p r - L e' p' r‖ ≀ 4 * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2 have I2 : x ∈ A f (L e' p' r) ((1 / 2) ^ r) ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.2 exact norm_sub_le_of_mem_A P _ I1 (A_mono _ _ I I2) have J3 : ‖L e' p' r - L e' p' q'‖ ≀ 4 * (1 / 2) ^ e := by have I1 : x ∈ A f (L e' p' r) ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.1 have I2 : x ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' q' hp' hq').2.1 exact norm_sub_le_of_mem_A P _ (A_mono _ _ I I1) (A_mono _ _ I I2) calc ‖L e p q - L e' p' q'‖ = ‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ := by congr 1; abel _ ≀ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ := (le_trans (norm_add_le _ _) (add_le_add_right (norm_add_le _ _) _)) _ ≀ 4 * (1 / 2) ^ e + 4 * (1 / 2) ^ e + 4 * (1 / 2) ^ e := by gcongr -- Porting note: proof was `by apply_rules [add_le_add]` _ = 12 * (1 / 2) ^ e := by ring /- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this is a Cauchy sequence. -/ let L0 : ℕ → F := fun e => L e (n e) (n e) have : CauchySeq L0 := by rw [Metric.cauchySeq_iff'] intro ε εpos obtain ⟹e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / 12 := exists_pow_lt_of_lt_one (div_pos εpos (by norm_num)) (by norm_num) refine ⟹e, fun e' he' => ?_⟩ rw [dist_comm, dist_eq_norm] calc ‖L0 e - L0 e'‖ ≀ 12 * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he' _ < 12 * (ε / 12) := mul_lt_mul' le_rfl he (le_of_lt P) (by norm_num) _ = ε := by field_simp [(by norm_num : (12 : ℝ) ≠ 0)] -- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`. obtain ⟹f', f'K, hf'⟩ : ∃ f' ∈ K, Tendsto L0 atTop (𝓝 f') := cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this have Lf' : ∀ e p, n e ≀ p → ‖L e (n e) p - f'‖ ≀ 12 * (1 / 2) ^ e := by intro e p hp apply le_of_tendsto (tendsto_const_nhds.sub hf').norm rw [eventually_atTop] exact ⟹e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩ -- Let us show that `f` has right derivative `f'` at `x`. have : HasDerivWithinAt f f' (Ici x) x := by simp only [hasDerivWithinAt_iff_isLittleO, isLittleO_iff] /- to get an approximation with a precision `ε`, we will replace `f` with `L e (n e) m` for some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`, this makes it possible to cover all scales, and thus to obtain a good linear approximation in the whole interval of length `(1/2)^(n e)`. -/ intro ε εpos obtain ⟹e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / 16 := exists_pow_lt_of_lt_one (div_pos εpos (by norm_num)) (by norm_num) have xmem : x ∈ Ico x (x + (1 / 2) ^ (n e + 1)) := by simp only [one_div, left_mem_Ico, lt_add_iff_pos_right, inv_pos, pow_pos, zero_lt_two, zero_lt_one] filter_upwards [Icc_mem_nhdsWithin_Ici xmem] with y hy -- We need to show that `f y - f x - f' (y - x)` is small. For this, we will work at scale -- `k` where `k` is chosen with `‖y - x‖ ∌ 2 ^ (-k)`. rcases eq_or_lt_of_le hy.1 with (rfl | xy) · simp only [sub_self, zero_smul, norm_zero, mul_zero, le_rfl] have yzero : 0 < y - x := sub_pos.2 xy have y_le : y - x ≀ (1 / 2) ^ (n e + 1) := by linarith [hy.2] have yone : y - x ≀ 1 := le_trans y_le (pow_le_one _ (by norm_num) (by norm_num)) -- define the scale `k`. obtain ⟹k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < y - x ∧ y - x ≀ (1 / 2) ^ k := exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num : (1 : ℝ) / 2 < 1) -- the scale is large enough (as `y - x` is small enough) have k_gt : n e < k := by have : ((1 : ℝ) / 2) ^ (k + 1) < (1 / 2) ^ (n e + 1) := lt_of_lt_of_le hk y_le rw [pow_lt_pow_iff_right_of_lt_one (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num)] at this omega set m := k - 1 have m_ge : n e ≀ m := Nat.le_sub_one_of_lt k_gt have km : k = m + 1 := (Nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm rw [km] at hk h'k -- `f` is well approximated by `L e (n e) k` at the relevant scale -- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`). have J : ‖f y - f x - (y - x) • L e (n e) m‖ ≀ 4 * (1 / 2) ^ e * ‖y - x‖ := calc ‖f y - f x - (y - x) • L e (n e) m‖ ≀ (1 / 2) ^ e * (1 / 2) ^ m := by apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2 · simp only [one_div, inv_pow, left_mem_Icc, le_add_iff_nonneg_right] positivity · simp only [pow_add, tsub_le_iff_left] at h'k simpa only [hy.1, mem_Icc, true_and_iff, one_div, pow_one] using h'k _ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) := by field_simp; ring _ ≀ 4 * (1 / 2) ^ e * (y - x) := by gcongr _ = 4 * (1 / 2) ^ e * ‖y - x‖ := by rw [Real.norm_of_nonneg yzero.le] calc ‖f y - f x - (y - x) • f'‖ = ‖f y - f x - (y - x) • L e (n e) m + (y - x) • (L e (n e) m - f')‖ := by simp only [smul_sub, sub_add_sub_cancel] _ ≀ 4 * (1 / 2) ^ e * ‖y - x‖ + ‖y - x‖ * (12 * (1 / 2) ^ e) := norm_add_le_of_le J <| by rw [norm_smul]; gcongr; exact Lf' _ _ m_ge _ = 16 * ‖y - x‖ * (1 / 2) ^ e := by ring _ ≀ 16 * ‖y - x‖ * (ε / 16) := by gcongr _ = ε * ‖y - x‖ := by ring rw [← this.derivWithin (uniqueDiffOn_Ici x x Set.left_mem_Ici)] at f'K exact ⟹this.differentiableWithinAt, f'K⟩ theorem differentiable_set_eq_D (hK : IsComplete K) : { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } = D f K := Subset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK) end RightDerivMeasurableAux open RightDerivMeasurableAux variable (f) /-- The set of right differentiability points of a function, with derivative in a given complete set, is Borel-measurable. -/ theorem measurableSet_of_differentiableWithinAt_Ici_of_isComplete {K : Set F} (hK : IsComplete K) : MeasurableSet { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } := by -- simp [differentiable_set_eq_d K hK, D, measurableSet_b, MeasurableSet.iInter, -- MeasurableSet.iUnion] simp only [differentiable_set_eq_D K hK, D] repeat apply_rules [MeasurableSet.iUnion, MeasurableSet.iInter] <;> intro exact measurableSet_B variable [CompleteSpace F] /-- The set of right differentiability points of a function taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableWithinAt_Ici : MeasurableSet { x | DifferentiableWithinAt ℝ f (Ici x) x } := by have : IsComplete (univ : Set F) := complete_univ convert measurableSet_of_differentiableWithinAt_Ici_of_isComplete f this simp @[measurability, fun_prop] theorem measurable_derivWithin_Ici [MeasurableSpace F] [BorelSpace F] : Measurable fun x => derivWithin f (Ici x) x := by refine measurable_of_isClosed fun s hs => ?_ have : (fun x => derivWithin f (Ici x) x) ⁻¹' s = { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ s } ∪ { x | ¬DifferentiableWithinAt ℝ f (Ici x) x } ∩ { _x | (0 : F) ∈ s } := Set.ext fun x => mem_preimage.trans derivWithin_mem_iff rw [this] exact (measurableSet_of_differentiableWithinAt_Ici_of_isComplete _ hs.isComplete).union ((measurableSet_of_differentiableWithinAt_Ici _).compl.inter (MeasurableSet.const _)) theorem stronglyMeasurable_derivWithin_Ici : StronglyMeasurable (fun x ↩ derivWithin f (Ici x) x) := by borelize F apply stronglyMeasurable_iff_measurable_separable.2 ⟹measurable_derivWithin_Ici f, ?_⟩ obtain ⟹t, t_count, ht⟩ : ∃ t : Set ℝ, t.Countable ∧ Dense t := exists_countable_dense ℝ suffices H : range (fun x ↩ derivWithin f (Ici x) x) ⊆ closure (Submodule.span ℝ (f '' t)) from IsSeparable.mono (t_count.image f).isSeparable.span.closure H rintro - ⟹x, rfl⟩ suffices H' : range (fun y ↩ derivWithin f (Ici x) y) ⊆ closure (Submodule.span ℝ (f '' t)) from H' (mem_range_self _) apply range_derivWithin_subset_closure_span_image calc Ici x = closure (Ioi x ∩ closure t) := by simp [dense_iff_closure_eq.1 ht] _ ⊆ closure (closure (Ioi x ∩ t)) := by apply closure_mono simpa [inter_comm] using (isOpen_Ioi (a := x)).closure_inter (s := t) _ ⊆ closure (Ici x ∩ t) := by rw [closure_closure] exact closure_mono (inter_subset_inter_left _ Ioi_subset_Ici_self) theorem aemeasurable_derivWithin_Ici [MeasurableSpace F] [BorelSpace F] (ÎŒ : Measure ℝ) : AEMeasurable (fun x => derivWithin f (Ici x) x) ÎŒ := (measurable_derivWithin_Ici f).aemeasurable theorem aestronglyMeasurable_derivWithin_Ici (ÎŒ : Measure ℝ) : AEStronglyMeasurable (fun x => derivWithin f (Ici x) x) ÎŒ := (stronglyMeasurable_derivWithin_Ici f).aestronglyMeasurable /-- The set of right differentiability points of a function taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableWithinAt_Ioi : MeasurableSet { x | DifferentiableWithinAt ℝ f (Ioi x) x } := by simpa [differentiableWithinAt_Ioi_iff_Ici] using measurableSet_of_differentiableWithinAt_Ici f @[measurability, fun_prop] theorem measurable_derivWithin_Ioi [MeasurableSpace F] [BorelSpace F] : Measurable fun x => derivWithin f (Ioi x) x := by simpa [derivWithin_Ioi_eq_Ici] using measurable_derivWithin_Ici f theorem stronglyMeasurable_derivWithin_Ioi : StronglyMeasurable (fun x ↩ derivWithin f (Ioi x) x) := by simpa [derivWithin_Ioi_eq_Ici] using stronglyMeasurable_derivWithin_Ici f theorem aemeasurable_derivWithin_Ioi [MeasurableSpace F] [BorelSpace F] (ÎŒ : Measure ℝ) : AEMeasurable (fun x => derivWithin f (Ioi x) x) ÎŒ := (measurable_derivWithin_Ioi f).aemeasurable theorem aestronglyMeasurable_derivWithin_Ioi (ÎŒ : Measure ℝ) : AEStronglyMeasurable (fun x => derivWithin f (Ioi x) x) ÎŒ := (stronglyMeasurable_derivWithin_Ioi f).aestronglyMeasurable end RightDeriv section WithParam /- In this section, we prove the measurability of the derivative in a context with parameters: given `f : α → E → F`, we want to show that `p ↩ fderiv 𝕜 (f p.1) p.2` is measurable. Contrary to the previous sections, some assumptions are needed for this: if `f p.1` depends arbitrarily on `p.1`, this is obviously false. We require that `f` is continuous and `E` is locally compact -- then the proofs in the previous sections adapt readily, as the set `A` defined above is open, so that the differentiability set `D` is measurable. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [LocallyCompactSpace E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {α : Type*} [TopologicalSpace α] [MeasurableSpace α] [MeasurableSpace E] [OpensMeasurableSpace α] [OpensMeasurableSpace E] {f : α → E → F} (K : Set (E →L[𝕜] F)) namespace FDerivMeasurableAux open Uniformity lemma isOpen_A_with_param {r s : ℝ} (hf : Continuous f.uncurry) (L : E →L[𝕜] F) : IsOpen {p : α × E | p.2 ∈ A (f p.1) L r s} := by have : ProperSpace E := .of_locallyCompactSpace 𝕜 simp only [A, half_lt_self_iff, not_lt, mem_Ioc, mem_ball, map_sub, mem_setOf_eq] apply isOpen_iff_mem_nhds.2 rintro ⟹a, x⟩ ⟹r', ⟹Irr', Ir'r⟩, hr⟩ have ha : Continuous (f a) := hf.uncurry_left a rcases exists_between Irr' with ⟹t, hrt, htr'⟩ rcases exists_between hrt with ⟹t', hrt', ht't⟩ obtain ⟹b, b_lt, hb⟩ : ∃ b, b < s * r ∧ ∀ y ∈ closedBall x t, ∀ z ∈ closedBall x t, ‖f a z - f a y - (L z - L y)‖ ≀ b := by have B : Continuous (fun (p : E × E) ↩ ‖f a p.2 - f a p.1 - (L p.2 - L p.1)‖) := by fun_prop have C : (closedBall x t ×ˢ closedBall x t).Nonempty := by simp; linarith rcases ((isCompact_closedBall x t).prod (isCompact_closedBall x t)).exists_isMaxOn C B.continuousOn with ⟹p, pt, hp⟩ simp only [mem_prod, mem_closedBall] at pt refine ⟹‖f a p.2 - f a p.1 - (L p.2 - L p.1)‖, hr p.1 (pt.1.trans_lt htr') p.2 (pt.2.trans_lt htr'), fun y hy z hz ↩ ?_⟩ have D : (y, z) ∈ closedBall x t ×ˢ closedBall x t := mem_prod.2 ⟹hy, hz⟩ exact hp D obtain ⟚ε, εpos, hε⟩ : ∃ ε, 0 < ε ∧ b + 2 * ε < s * r := ⟹(s * r - b) / 3, by linarith, by linarith⟩ obtain ⟹u, u_open, au, hu⟩ : ∃ u, IsOpen u ∧ a ∈ u ∧ ∀ (p : α × E), p.1 ∈ u → p.2 ∈ closedBall x t → dist (f.uncurry p) (f.uncurry (a, p.2)) < ε := by have C : Continuous (fun (p : α × E) ↩ f a p.2) := by fun_prop have D : ({a} ×ˢ closedBall x t).EqOn f.uncurry (fun p ↩ f a p.2) := by rintro ⟹b, y⟩ ⟹hb, -⟩ simp only [mem_singleton_iff] at hb simp [hb] obtain ⟹v, v_open, sub_v, hv⟩ : ∃ v, IsOpen v ∧ {a} ×ˢ closedBall x t ⊆ v ∧ ∀ p ∈ v, dist (Function.uncurry f p) (f a p.2) < ε := Uniform.exists_is_open_mem_uniformity_of_forall_mem_eq (s := {a} ×ˢ closedBall x t) (fun p _ ↩ hf.continuousAt) (fun p _ ↩ C.continuousAt) D (dist_mem_uniformity εpos) obtain ⟹w, w', w_open, -, sub_w, sub_w', hww'⟩ : ∃ (w : Set α) (w' : Set E), IsOpen w ∧ IsOpen w' ∧ {a} ⊆ w ∧ closedBall x t ⊆ w' ∧ w ×ˢ w' ⊆ v := generalized_tube_lemma isCompact_singleton (isCompact_closedBall x t) v_open sub_v refine ⟹w, w_open, sub_w rfl, ?_⟩ rintro ⟹b, y⟩ h hby exact hv _ (hww' ⟹h, sub_w' hby⟩) have : u ×ˢ ball x (t - t') ∈ 𝓝 (a, x) := prod_mem_nhds (u_open.mem_nhds au) (ball_mem_nhds _ (sub_pos.2 ht't)) filter_upwards [this] rintro ⟹a', x'⟩ ha'x' simp only [mem_prod, mem_ball] at ha'x' refine ⟹t', ⟹hrt', ht't.le.trans (htr'.le.trans Ir'r)⟩, fun y hy z hz ↩ ?_⟩ have dyx : dist y x ≀ t := by linarith [dist_triangle y x' x] have dzx : dist z x ≀ t := by linarith [dist_triangle z x' x] calc ‖f a' z - f a' y - (L z - L y)‖ = ‖(f a' z - f a z) + (f a y - f a' y) + (f a z - f a y - (L z - L y))‖ := by congr; abel _ ≀ ‖f a' z - f a z‖ + ‖f a y - f a' y‖ + ‖f a z - f a y - (L z - L y)‖ := norm_add₃_le _ _ _ _ ≀ ε + ε + b := by gcongr · rw [← dist_eq_norm] change dist (f.uncurry (a', z)) (f.uncurry (a, z)) ≀ ε apply (hu _ _ _).le · exact ha'x'.1 · simp [dzx] · rw [← dist_eq_norm'] change dist (f.uncurry (a', y)) (f.uncurry (a, y)) ≀ ε apply (hu _ _ _).le · exact ha'x'.1 · simp [dyx] · simp [hb, dyx, dzx] _ < s * r := by linarith lemma isOpen_B_with_param {r s t : ℝ} (hf : Continuous f.uncurry) (K : Set (E →L[𝕜] F)) : IsOpen {p : α × E | p.2 ∈ B (f p.1) K r s t} := by suffices H : IsOpen (⋃ L ∈ K, {p : α × E | p.2 ∈ A (f p.1) L r t ∧ p.2 ∈ A (f p.1) L s t}) by convert H; ext p; simp [B] refine isOpen_biUnion (fun L _ ↩ ?_) exact (isOpen_A_with_param hf L).inter (isOpen_A_with_param hf L) end FDerivMeasurableAux open FDerivMeasurableAux theorem measurableSet_of_differentiableAt_of_isComplete_with_param (hf : Continuous f.uncurry) {K : Set (E →L[𝕜] F)} (hK : IsComplete K) : MeasurableSet {p : α × E | DifferentiableAt 𝕜 (f p.1) p.2 ∧ fderiv 𝕜 (f p.1) p.2 ∈ K} := by have : {p : α × E | DifferentiableAt 𝕜 (f p.1) p.2 ∧ fderiv 𝕜 (f p.1) p.2 ∈ K} = {p : α × E | p.2 ∈ D (f p.1) K} := by simp [← differentiable_set_eq_D K hK] rw [this] simp only [D, mem_iInter, mem_iUnion] simp only [setOf_forall, setOf_exists] refine MeasurableSet.iInter (fun _ ↩ ?_) refine MeasurableSet.iUnion (fun _ ↩ ?_) refine MeasurableSet.iInter (fun _ ↩ ?_) refine MeasurableSet.iInter (fun _ ↩ ?_) refine MeasurableSet.iInter (fun _ ↩ ?_) refine MeasurableSet.iInter (fun _ ↩ ?_) have : ProperSpace E := .of_locallyCompactSpace 𝕜 exact (isOpen_B_with_param hf K).measurableSet variable (𝕜) variable [CompleteSpace F] /-- The set of differentiability points of a continuous function depending on a parameter taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableAt_with_param (hf : Continuous f.uncurry) : MeasurableSet {p : α × E | DifferentiableAt 𝕜 (f p.1) p.2} := by have : IsComplete (univ : Set (E →L[𝕜] F)) := complete_univ convert measurableSet_of_differentiableAt_of_isComplete_with_param hf this simp theorem measurable_fderiv_with_param (hf : Continuous f.uncurry) : Measurable (fun (p : α × E) ↩ fderiv 𝕜 (f p.1) p.2) := by refine measurable_of_isClosed (fun s hs ↩ ?_) have : (fun (p : α × E) ↩ fderiv 𝕜 (f p.1) p.2) ⁻¹' s = {p | DifferentiableAt 𝕜 (f p.1) p.2 ∧ fderiv 𝕜 (f p.1) p.2 ∈ s } ∪ { p | ¬DifferentiableAt 𝕜 (f p.1) p.2} ∩ { _p | (0 : E →L[𝕜] F) ∈ s} := Set.ext (fun x ↩ mem_preimage.trans fderiv_mem_iff) rw [this] exact (measurableSet_of_differentiableAt_of_isComplete_with_param hf hs.isComplete).union ((measurableSet_of_differentiableAt_with_param _ hf).compl.inter (MeasurableSet.const _)) theorem measurable_fderiv_apply_const_with_param [MeasurableSpace F] [BorelSpace F] (hf : Continuous f.uncurry) (y : E) : Measurable (fun (p : α × E) ↩ fderiv 𝕜 (f p.1) p.2 y) := (ContinuousLinearMap.measurable_apply y).comp (measurable_fderiv_with_param 𝕜 hf) variable {𝕜} theorem measurable_deriv_with_param [LocallyCompactSpace 𝕜] [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F] [BorelSpace F] {f : α → 𝕜 → F} (hf : Continuous f.uncurry) : Measurable (fun (p : α × 𝕜) ↩ deriv (f p.1) p.2) := by simpa only [fderiv_deriv] using measurable_fderiv_apply_const_with_param 𝕜 hf 1 theorem stronglyMeasurable_deriv_with_param [LocallyCompactSpace 𝕜] [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [h : SecondCountableTopologyEither α F] {f : α → 𝕜 → F} (hf : Continuous f.uncurry) : StronglyMeasurable (fun (p : α × 𝕜) ↩ deriv (f p.1) p.2) := by borelize F rcases h.out with hα|hF · have : ProperSpace 𝕜 := .of_locallyCompactSpace 𝕜 apply stronglyMeasurable_iff_measurable_separable.2 ⟹measurable_deriv_with_param hf, ?_⟩ have : range (fun (p : α × 𝕜) ↩ deriv (f p.1) p.2) ⊆ closure (Submodule.span 𝕜 (range f.uncurry)) := by rintro - ⟹p, rfl⟩ have A : deriv (f p.1) p.2 ∈ closure (Submodule.span 𝕜 (range (f p.1))) := by rw [← image_univ] apply range_deriv_subset_closure_span_image _ dense_univ (mem_range_self _) have B : range (f p.1) ⊆ range (f.uncurry) := by rintro - ⟹x, rfl⟩ exact mem_range_self (p.1, x) exact closure_mono (Submodule.span_mono B) A exact (isSeparable_range hf).span.closure.mono this · exact (measurable_deriv_with_param hf).stronglyMeasurable theorem aemeasurable_deriv_with_param [LocallyCompactSpace 𝕜] [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F] [BorelSpace F] {f : α → 𝕜 → F} (hf : Continuous f.uncurry) (ÎŒ : Measure (α × 𝕜)) : AEMeasurable (fun (p : α × 𝕜) ↩ deriv (f p.1) p.2) ÎŒ := (measurable_deriv_with_param hf).aemeasurable theorem aestronglyMeasurable_deriv_with_param [LocallyCompactSpace 𝕜] [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [SecondCountableTopologyEither α F] {f : α → 𝕜 → F} (hf : Continuous f.uncurry) (ÎŒ : Measure (α × 𝕜)) : AEStronglyMeasurable (fun (p : α × 𝕜) ↩ deriv (f p.1) p.2) ÎŒ := (stronglyMeasurable_deriv_with_param hf).aestronglyMeasurable end WithParam
Analysis\Calculus\FDeriv\Mul.lean
/- 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 Mathlib.Analysis.Calculus.FDeriv.Bilinear /-! # Multiplicative operations on derivatives For detailed documentation of the Fréchet derivative, see the module docstring of `Mathlib/Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of * multiplication of a function by a scalar function * product of finitely many scalar functions * taking the pointwise multiplicative inverse (i.e. `Inv.inv` or `Ring.inverse`) of a function -/ open scoped Classical open Filter Asymptotics ContinuousLinearMap Set Metric Topology NNReal ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} section CLMCompApply /-! ### Derivative of the pointwise composition/application of continuous linear maps -/ variable {H : Type*} [NormedAddCommGroup H] [NormedSpace 𝕜 H] {c : E → G →L[𝕜] H} {c' : E →L[𝕜] G →L[𝕜] H} {d : E → F →L[𝕜] G} {d' : E →L[𝕜] F →L[𝕜] G} {u : E → G} {u' : E →L[𝕜] G} @[fun_prop] theorem HasStrictFDerivAt.clm_comp (hc : HasStrictFDerivAt c c' x) (hd : HasStrictFDerivAt d d' x) : HasStrictFDerivAt (fun y => (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x := (isBoundedBilinearMap_comp.hasStrictFDerivAt (c x, d x)).comp x <| hc.prod hd @[fun_prop] theorem HasFDerivWithinAt.clm_comp (hc : HasFDerivWithinAt c c' s x) (hd : HasFDerivWithinAt d d' s x) : HasFDerivWithinAt (fun y => (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') s x := (isBoundedBilinearMap_comp.hasFDerivAt (c x, d x)).comp_hasFDerivWithinAt x <| hc.prod hd @[fun_prop] theorem HasFDerivAt.clm_comp (hc : HasFDerivAt c c' x) (hd : HasFDerivAt d d' x) : HasFDerivAt (fun y => (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x := (isBoundedBilinearMap_comp.hasFDerivAt (c x, d x)).comp x <| hc.prod hd @[fun_prop] theorem DifferentiableWithinAt.clm_comp (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : DifferentiableWithinAt 𝕜 (fun y => (c y).comp (d y)) s x := (hc.hasFDerivWithinAt.clm_comp hd.hasFDerivWithinAt).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.clm_comp (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : DifferentiableAt 𝕜 (fun y => (c y).comp (d y)) x := (hc.hasFDerivAt.clm_comp hd.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.clm_comp (hc : DifferentiableOn 𝕜 c s) (hd : DifferentiableOn 𝕜 d s) : DifferentiableOn 𝕜 (fun y => (c y).comp (d y)) s := fun x hx => (hc x hx).clm_comp (hd x hx) @[fun_prop] theorem Differentiable.clm_comp (hc : Differentiable 𝕜 c) (hd : Differentiable 𝕜 d) : Differentiable 𝕜 fun y => (c y).comp (d y) := fun x => (hc x).clm_comp (hd x) theorem fderivWithin_clm_comp (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : fderivWithin 𝕜 (fun y => (c y).comp (d y)) s x = (compL 𝕜 F G H (c x)).comp (fderivWithin 𝕜 d s x) + ((compL 𝕜 F G H).flip (d x)).comp (fderivWithin 𝕜 c s x) := (hc.hasFDerivWithinAt.clm_comp hd.hasFDerivWithinAt).fderivWithin hxs theorem fderiv_clm_comp (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : fderiv 𝕜 (fun y => (c y).comp (d y)) x = (compL 𝕜 F G H (c x)).comp (fderiv 𝕜 d x) + ((compL 𝕜 F G H).flip (d x)).comp (fderiv 𝕜 c x) := (hc.hasFDerivAt.clm_comp hd.hasFDerivAt).fderiv @[fun_prop] theorem HasStrictFDerivAt.clm_apply (hc : HasStrictFDerivAt c c' x) (hu : HasStrictFDerivAt u u' x) : HasStrictFDerivAt (fun y => (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x := (isBoundedBilinearMap_apply.hasStrictFDerivAt (c x, u x)).comp x (hc.prod hu) @[fun_prop] theorem HasFDerivWithinAt.clm_apply (hc : HasFDerivWithinAt c c' s x) (hu : HasFDerivWithinAt u u' s x) : HasFDerivWithinAt (fun y => (c y) (u y)) ((c x).comp u' + c'.flip (u x)) s x := (isBoundedBilinearMap_apply.hasFDerivAt (c x, u x)).comp_hasFDerivWithinAt x (hc.prod hu) @[fun_prop] theorem HasFDerivAt.clm_apply (hc : HasFDerivAt c c' x) (hu : HasFDerivAt u u' x) : HasFDerivAt (fun y => (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x := (isBoundedBilinearMap_apply.hasFDerivAt (c x, u x)).comp x (hc.prod hu) @[fun_prop] theorem DifferentiableWithinAt.clm_apply (hc : DifferentiableWithinAt 𝕜 c s x) (hu : DifferentiableWithinAt 𝕜 u s x) : DifferentiableWithinAt 𝕜 (fun y => (c y) (u y)) s x := (hc.hasFDerivWithinAt.clm_apply hu.hasFDerivWithinAt).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.clm_apply (hc : DifferentiableAt 𝕜 c x) (hu : DifferentiableAt 𝕜 u x) : DifferentiableAt 𝕜 (fun y => (c y) (u y)) x := (hc.hasFDerivAt.clm_apply hu.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.clm_apply (hc : DifferentiableOn 𝕜 c s) (hu : DifferentiableOn 𝕜 u s) : DifferentiableOn 𝕜 (fun y => (c y) (u y)) s := fun x hx => (hc x hx).clm_apply (hu x hx) @[fun_prop] theorem Differentiable.clm_apply (hc : Differentiable 𝕜 c) (hu : Differentiable 𝕜 u) : Differentiable 𝕜 fun y => (c y) (u y) := fun x => (hc x).clm_apply (hu x) theorem fderivWithin_clm_apply (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hu : DifferentiableWithinAt 𝕜 u s x) : fderivWithin 𝕜 (fun y => (c y) (u y)) s x = (c x).comp (fderivWithin 𝕜 u s x) + (fderivWithin 𝕜 c s x).flip (u x) := (hc.hasFDerivWithinAt.clm_apply hu.hasFDerivWithinAt).fderivWithin hxs theorem fderiv_clm_apply (hc : DifferentiableAt 𝕜 c x) (hu : DifferentiableAt 𝕜 u x) : fderiv 𝕜 (fun y => (c y) (u y)) x = (c x).comp (fderiv 𝕜 u x) + (fderiv 𝕜 c x).flip (u x) := (hc.hasFDerivAt.clm_apply hu.hasFDerivAt).fderiv end CLMCompApply section ContinuousMultilinearApplyConst /-! ### Derivative of the application of continuous multilinear maps to a constant -/ variable {ι : Type*} [Fintype ι] {M : ι → Type*} [∀ i, NormedAddCommGroup (M i)] [∀ i, NormedSpace 𝕜 (M i)] {H : Type*} [NormedAddCommGroup H] [NormedSpace 𝕜 H] {c : E → ContinuousMultilinearMap 𝕜 M H} {c' : E →L[𝕜] ContinuousMultilinearMap 𝕜 M H} @[fun_prop] theorem HasStrictFDerivAt.continuousMultilinear_apply_const (hc : HasStrictFDerivAt c c' x) (u : ∀ i, M i) : HasStrictFDerivAt (fun y ↩ (c y) u) (c'.flipMultilinear u) x := (ContinuousMultilinearMap.apply 𝕜 M H u).hasStrictFDerivAt.comp x hc @[fun_prop] theorem HasFDerivWithinAt.continuousMultilinear_apply_const (hc : HasFDerivWithinAt c c' s x) (u : ∀ i, M i) : HasFDerivWithinAt (fun y ↩ (c y) u) (c'.flipMultilinear u) s x := (ContinuousMultilinearMap.apply 𝕜 M H u).hasFDerivAt.comp_hasFDerivWithinAt x hc @[fun_prop] theorem HasFDerivAt.continuousMultilinear_apply_const (hc : HasFDerivAt c c' x) (u : ∀ i, M i) : HasFDerivAt (fun y ↩ (c y) u) (c'.flipMultilinear u) x := (ContinuousMultilinearMap.apply 𝕜 M H u).hasFDerivAt.comp x hc @[fun_prop] theorem DifferentiableWithinAt.continuousMultilinear_apply_const (hc : DifferentiableWithinAt 𝕜 c s x) (u : ∀ i, M i) : DifferentiableWithinAt 𝕜 (fun y ↩ (c y) u) s x := (hc.hasFDerivWithinAt.continuousMultilinear_apply_const u).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.continuousMultilinear_apply_const (hc : DifferentiableAt 𝕜 c x) (u : ∀ i, M i) : DifferentiableAt 𝕜 (fun y ↩ (c y) u) x := (hc.hasFDerivAt.continuousMultilinear_apply_const u).differentiableAt @[fun_prop] theorem DifferentiableOn.continuousMultilinear_apply_const (hc : DifferentiableOn 𝕜 c s) (u : ∀ i, M i) : DifferentiableOn 𝕜 (fun y ↩ (c y) u) s := fun x hx ↩ (hc x hx).continuousMultilinear_apply_const u @[fun_prop] theorem Differentiable.continuousMultilinear_apply_const (hc : Differentiable 𝕜 c) (u : ∀ i, M i) : Differentiable 𝕜 fun y ↩ (c y) u := fun x ↩ (hc x).continuousMultilinear_apply_const u theorem fderivWithin_continuousMultilinear_apply_const (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (u : ∀ i, M i) : fderivWithin 𝕜 (fun y ↩ (c y) u) s x = ((fderivWithin 𝕜 c s x).flipMultilinear u) := (hc.hasFDerivWithinAt.continuousMultilinear_apply_const u).fderivWithin hxs theorem fderiv_continuousMultilinear_apply_const (hc : DifferentiableAt 𝕜 c x) (u : ∀ i, M i) : (fderiv 𝕜 (fun y ↩ (c y) u) x) = (fderiv 𝕜 c x).flipMultilinear u := (hc.hasFDerivAt.continuousMultilinear_apply_const u).fderiv /-- Application of a `ContinuousMultilinearMap` to a constant commutes with `fderivWithin`. -/ theorem fderivWithin_continuousMultilinear_apply_const_apply (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (u : ∀ i, M i) (m : E) : (fderivWithin 𝕜 (fun y ↩ (c y) u) s x) m = (fderivWithin 𝕜 c s x) m u := by simp [fderivWithin_continuousMultilinear_apply_const hxs hc] /-- Application of a `ContinuousMultilinearMap` to a constant commutes with `fderiv`. -/ theorem fderiv_continuousMultilinear_apply_const_apply (hc : DifferentiableAt 𝕜 c x) (u : ∀ i, M i) (m : E) : (fderiv 𝕜 (fun y ↩ (c y) u) x) m = (fderiv 𝕜 c x) m u := by simp [fderiv_continuousMultilinear_apply_const hc] end ContinuousMultilinearApplyConst section SMul /-! ### Derivative of the product of a scalar-valued function and a vector-valued function If `c` is a differentiable scalar-valued function and `f` is a differentiable vector-valued function, then `fun x ↩ c x • f x` is differentiable as well. Lemmas in this section works for function `c` taking values in the base field, as well as in a normed algebra over the base field: e.g., they work for `c : E → ℂ` and `f : E → F` provided that `F` is a complex normed vector space. -/ variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] variable {c : E → 𝕜'} {c' : E →L[𝕜] 𝕜'} @[fun_prop] theorem HasStrictFDerivAt.smul (hc : HasStrictFDerivAt c c' x) (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun y => c y • f y) (c x • f' + c'.smulRight (f x)) x := (isBoundedBilinearMap_smul.hasStrictFDerivAt (c x, f x)).comp x <| hc.prod hf @[fun_prop] theorem HasFDerivWithinAt.smul (hc : HasFDerivWithinAt c c' s x) (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun y => c y • f y) (c x • f' + c'.smulRight (f x)) s x := (isBoundedBilinearMap_smul.hasFDerivAt (c x, f x)).comp_hasFDerivWithinAt x <| hc.prod hf @[fun_prop] theorem HasFDerivAt.smul (hc : HasFDerivAt c c' x) (hf : HasFDerivAt f f' x) : HasFDerivAt (fun y => c y • f y) (c x • f' + c'.smulRight (f x)) x := (isBoundedBilinearMap_smul.hasFDerivAt (c x, f x)).comp x <| hc.prod hf @[fun_prop] theorem DifferentiableWithinAt.smul (hc : DifferentiableWithinAt 𝕜 c s x) (hf : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (fun y => c y • f y) s x := (hc.hasFDerivWithinAt.smul hf.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.smul (hc : DifferentiableAt 𝕜 c x) (hf : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => c y • f y) x := (hc.hasFDerivAt.smul hf.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.smul (hc : DifferentiableOn 𝕜 c s) (hf : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => c y • f y) s := fun x hx => (hc x hx).smul (hf x hx) @[simp, fun_prop] theorem Differentiable.smul (hc : Differentiable 𝕜 c) (hf : Differentiable 𝕜 f) : Differentiable 𝕜 fun y => c y • f y := fun x => (hc x).smul (hf x) theorem fderivWithin_smul (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hf : DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 (fun y => c y • f y) s x = c x • fderivWithin 𝕜 f s x + (fderivWithin 𝕜 c s x).smulRight (f x) := (hc.hasFDerivWithinAt.smul hf.hasFDerivWithinAt).fderivWithin hxs theorem fderiv_smul (hc : DifferentiableAt 𝕜 c x) (hf : DifferentiableAt 𝕜 f x) : fderiv 𝕜 (fun y => c y • f y) x = c x • fderiv 𝕜 f x + (fderiv 𝕜 c x).smulRight (f x) := (hc.hasFDerivAt.smul hf.hasFDerivAt).fderiv @[fun_prop] theorem HasStrictFDerivAt.smul_const (hc : HasStrictFDerivAt c c' x) (f : F) : HasStrictFDerivAt (fun y => c y • f) (c'.smulRight f) x := by simpa only [smul_zero, zero_add] using hc.smul (hasStrictFDerivAt_const f x) @[fun_prop] theorem HasFDerivWithinAt.smul_const (hc : HasFDerivWithinAt c c' s x) (f : F) : HasFDerivWithinAt (fun y => c y • f) (c'.smulRight f) s x := by simpa only [smul_zero, zero_add] using hc.smul (hasFDerivWithinAt_const f x s) @[fun_prop] theorem HasFDerivAt.smul_const (hc : HasFDerivAt c c' x) (f : F) : HasFDerivAt (fun y => c y • f) (c'.smulRight f) x := by simpa only [smul_zero, zero_add] using hc.smul (hasFDerivAt_const f x) @[fun_prop] theorem DifferentiableWithinAt.smul_const (hc : DifferentiableWithinAt 𝕜 c s x) (f : F) : DifferentiableWithinAt 𝕜 (fun y => c y • f) s x := (hc.hasFDerivWithinAt.smul_const f).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.smul_const (hc : DifferentiableAt 𝕜 c x) (f : F) : DifferentiableAt 𝕜 (fun y => c y • f) x := (hc.hasFDerivAt.smul_const f).differentiableAt @[fun_prop] theorem DifferentiableOn.smul_const (hc : DifferentiableOn 𝕜 c s) (f : F) : DifferentiableOn 𝕜 (fun y => c y • f) s := fun x hx => (hc x hx).smul_const f @[fun_prop] theorem Differentiable.smul_const (hc : Differentiable 𝕜 c) (f : F) : Differentiable 𝕜 fun y => c y • f := fun x => (hc x).smul_const f theorem fderivWithin_smul_const (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (f : F) : fderivWithin 𝕜 (fun y => c y • f) s x = (fderivWithin 𝕜 c s x).smulRight f := (hc.hasFDerivWithinAt.smul_const f).fderivWithin hxs theorem fderiv_smul_const (hc : DifferentiableAt 𝕜 c x) (f : F) : fderiv 𝕜 (fun y => c y • f) x = (fderiv 𝕜 c x).smulRight f := (hc.hasFDerivAt.smul_const f).fderiv end SMul section Mul /-! ### Derivative of the product of two functions -/ variable {𝔞 𝔞' : Type*} [NormedRing 𝔞] [NormedCommRing 𝔞'] [NormedAlgebra 𝕜 𝔞] [NormedAlgebra 𝕜 𝔞'] {a b : E → 𝔞} {a' b' : E →L[𝕜] 𝔞} {c d : E → 𝔞'} {c' d' : E →L[𝕜] 𝔞'} @[fun_prop] theorem HasStrictFDerivAt.mul' {x : E} (ha : HasStrictFDerivAt a a' x) (hb : HasStrictFDerivAt b b' x) : HasStrictFDerivAt (fun y => a y * b y) (a x • b' + a'.smulRight (b x)) x := ((ContinuousLinearMap.mul 𝕜 𝔞).isBoundedBilinearMap.hasStrictFDerivAt (a x, b x)).comp x (ha.prod hb) @[fun_prop] theorem HasStrictFDerivAt.mul (hc : HasStrictFDerivAt c c' x) (hd : HasStrictFDerivAt d d' x) : HasStrictFDerivAt (fun y => c y * d y) (c x • d' + d x • c') x := by convert hc.mul' hd ext z apply mul_comm @[fun_prop] theorem HasFDerivWithinAt.mul' (ha : HasFDerivWithinAt a a' s x) (hb : HasFDerivWithinAt b b' s x) : HasFDerivWithinAt (fun y => a y * b y) (a x • b' + a'.smulRight (b x)) s x := ((ContinuousLinearMap.mul 𝕜 𝔞).isBoundedBilinearMap.hasFDerivAt (a x, b x)).comp_hasFDerivWithinAt x (ha.prod hb) @[fun_prop] theorem HasFDerivWithinAt.mul (hc : HasFDerivWithinAt c c' s x) (hd : HasFDerivWithinAt d d' s x) : HasFDerivWithinAt (fun y => c y * d y) (c x • d' + d x • c') s x := by convert hc.mul' hd ext z apply mul_comm @[fun_prop] theorem HasFDerivAt.mul' (ha : HasFDerivAt a a' x) (hb : HasFDerivAt b b' x) : HasFDerivAt (fun y => a y * b y) (a x • b' + a'.smulRight (b x)) x := ((ContinuousLinearMap.mul 𝕜 𝔞).isBoundedBilinearMap.hasFDerivAt (a x, b x)).comp x (ha.prod hb) @[fun_prop] theorem HasFDerivAt.mul (hc : HasFDerivAt c c' x) (hd : HasFDerivAt d d' x) : HasFDerivAt (fun y => c y * d y) (c x • d' + d x • c') x := by convert hc.mul' hd ext z apply mul_comm @[fun_prop] theorem DifferentiableWithinAt.mul (ha : DifferentiableWithinAt 𝕜 a s x) (hb : DifferentiableWithinAt 𝕜 b s x) : DifferentiableWithinAt 𝕜 (fun y => a y * b y) s x := (ha.hasFDerivWithinAt.mul' hb.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.mul (ha : DifferentiableAt 𝕜 a x) (hb : DifferentiableAt 𝕜 b x) : DifferentiableAt 𝕜 (fun y => a y * b y) x := (ha.hasFDerivAt.mul' hb.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.mul (ha : DifferentiableOn 𝕜 a s) (hb : DifferentiableOn 𝕜 b s) : DifferentiableOn 𝕜 (fun y => a y * b y) s := fun x hx => (ha x hx).mul (hb x hx) @[simp, fun_prop] theorem Differentiable.mul (ha : Differentiable 𝕜 a) (hb : Differentiable 𝕜 b) : Differentiable 𝕜 fun y => a y * b y := fun x => (ha x).mul (hb x) @[fun_prop] theorem DifferentiableWithinAt.pow (ha : DifferentiableWithinAt 𝕜 a s x) : ∀ n : ℕ, DifferentiableWithinAt 𝕜 (fun x => a x ^ n) s x | 0 => by simp only [pow_zero, differentiableWithinAt_const] | n + 1 => by simp only [pow_succ', DifferentiableWithinAt.pow ha n, ha.mul] @[simp, fun_prop] theorem DifferentiableAt.pow (ha : DifferentiableAt 𝕜 a x) (n : ℕ) : DifferentiableAt 𝕜 (fun x => a x ^ n) x := differentiableWithinAt_univ.mp <| ha.differentiableWithinAt.pow n @[fun_prop] theorem DifferentiableOn.pow (ha : DifferentiableOn 𝕜 a s) (n : ℕ) : DifferentiableOn 𝕜 (fun x => a x ^ n) s := fun x h => (ha x h).pow n @[simp, fun_prop] theorem Differentiable.pow (ha : Differentiable 𝕜 a) (n : ℕ) : Differentiable 𝕜 fun x => a x ^ n := fun x => (ha x).pow n theorem fderivWithin_mul' (hxs : UniqueDiffWithinAt 𝕜 s x) (ha : DifferentiableWithinAt 𝕜 a s x) (hb : DifferentiableWithinAt 𝕜 b s x) : fderivWithin 𝕜 (fun y => a y * b y) s x = a x • fderivWithin 𝕜 b s x + (fderivWithin 𝕜 a s x).smulRight (b x) := (ha.hasFDerivWithinAt.mul' hb.hasFDerivWithinAt).fderivWithin hxs theorem fderivWithin_mul (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : fderivWithin 𝕜 (fun y => c y * d y) s x = c x • fderivWithin 𝕜 d s x + d x • fderivWithin 𝕜 c s x := (hc.hasFDerivWithinAt.mul hd.hasFDerivWithinAt).fderivWithin hxs theorem fderiv_mul' (ha : DifferentiableAt 𝕜 a x) (hb : DifferentiableAt 𝕜 b x) : fderiv 𝕜 (fun y => a y * b y) x = a x • fderiv 𝕜 b x + (fderiv 𝕜 a x).smulRight (b x) := (ha.hasFDerivAt.mul' hb.hasFDerivAt).fderiv theorem fderiv_mul (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : fderiv 𝕜 (fun y => c y * d y) x = c x • fderiv 𝕜 d x + d x • fderiv 𝕜 c x := (hc.hasFDerivAt.mul hd.hasFDerivAt).fderiv @[fun_prop] theorem HasStrictFDerivAt.mul_const' (ha : HasStrictFDerivAt a a' x) (b : 𝔞) : HasStrictFDerivAt (fun y => a y * b) (a'.smulRight b) x := ((ContinuousLinearMap.mul 𝕜 𝔞).flip b).hasStrictFDerivAt.comp x ha @[fun_prop] theorem HasStrictFDerivAt.mul_const (hc : HasStrictFDerivAt c c' x) (d : 𝔞') : HasStrictFDerivAt (fun y => c y * d) (d • c') x := by convert hc.mul_const' d ext z apply mul_comm @[fun_prop] theorem HasFDerivWithinAt.mul_const' (ha : HasFDerivWithinAt a a' s x) (b : 𝔞) : HasFDerivWithinAt (fun y => a y * b) (a'.smulRight b) s x := ((ContinuousLinearMap.mul 𝕜 𝔞).flip b).hasFDerivAt.comp_hasFDerivWithinAt x ha @[fun_prop] theorem HasFDerivWithinAt.mul_const (hc : HasFDerivWithinAt c c' s x) (d : 𝔞') : HasFDerivWithinAt (fun y => c y * d) (d • c') s x := by convert hc.mul_const' d ext z apply mul_comm @[fun_prop] theorem HasFDerivAt.mul_const' (ha : HasFDerivAt a a' x) (b : 𝔞) : HasFDerivAt (fun y => a y * b) (a'.smulRight b) x := ((ContinuousLinearMap.mul 𝕜 𝔞).flip b).hasFDerivAt.comp x ha @[fun_prop] theorem HasFDerivAt.mul_const (hc : HasFDerivAt c c' x) (d : 𝔞') : HasFDerivAt (fun y => c y * d) (d • c') x := by convert hc.mul_const' d ext z apply mul_comm @[fun_prop] theorem DifferentiableWithinAt.mul_const (ha : DifferentiableWithinAt 𝕜 a s x) (b : 𝔞) : DifferentiableWithinAt 𝕜 (fun y => a y * b) s x := (ha.hasFDerivWithinAt.mul_const' b).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.mul_const (ha : DifferentiableAt 𝕜 a x) (b : 𝔞) : DifferentiableAt 𝕜 (fun y => a y * b) x := (ha.hasFDerivAt.mul_const' b).differentiableAt @[fun_prop] theorem DifferentiableOn.mul_const (ha : DifferentiableOn 𝕜 a s) (b : 𝔞) : DifferentiableOn 𝕜 (fun y => a y * b) s := fun x hx => (ha x hx).mul_const b @[fun_prop] theorem Differentiable.mul_const (ha : Differentiable 𝕜 a) (b : 𝔞) : Differentiable 𝕜 fun y => a y * b := fun x => (ha x).mul_const b theorem fderivWithin_mul_const' (hxs : UniqueDiffWithinAt 𝕜 s x) (ha : DifferentiableWithinAt 𝕜 a s x) (b : 𝔞) : fderivWithin 𝕜 (fun y => a y * b) s x = (fderivWithin 𝕜 a s x).smulRight b := (ha.hasFDerivWithinAt.mul_const' b).fderivWithin hxs theorem fderivWithin_mul_const (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (d : 𝔞') : fderivWithin 𝕜 (fun y => c y * d) s x = d • fderivWithin 𝕜 c s x := (hc.hasFDerivWithinAt.mul_const d).fderivWithin hxs theorem fderiv_mul_const' (ha : DifferentiableAt 𝕜 a x) (b : 𝔞) : fderiv 𝕜 (fun y => a y * b) x = (fderiv 𝕜 a x).smulRight b := (ha.hasFDerivAt.mul_const' b).fderiv theorem fderiv_mul_const (hc : DifferentiableAt 𝕜 c x) (d : 𝔞') : fderiv 𝕜 (fun y => c y * d) x = d • fderiv 𝕜 c x := (hc.hasFDerivAt.mul_const d).fderiv @[fun_prop] theorem HasStrictFDerivAt.const_mul (ha : HasStrictFDerivAt a a' x) (b : 𝔞) : HasStrictFDerivAt (fun y => b * a y) (b • a') x := ((ContinuousLinearMap.mul 𝕜 𝔞) b).hasStrictFDerivAt.comp x ha @[fun_prop] theorem HasFDerivWithinAt.const_mul (ha : HasFDerivWithinAt a a' s x) (b : 𝔞) : HasFDerivWithinAt (fun y => b * a y) (b • a') s x := ((ContinuousLinearMap.mul 𝕜 𝔞) b).hasFDerivAt.comp_hasFDerivWithinAt x ha @[fun_prop] theorem HasFDerivAt.const_mul (ha : HasFDerivAt a a' x) (b : 𝔞) : HasFDerivAt (fun y => b * a y) (b • a') x := ((ContinuousLinearMap.mul 𝕜 𝔞) b).hasFDerivAt.comp x ha @[fun_prop] theorem DifferentiableWithinAt.const_mul (ha : DifferentiableWithinAt 𝕜 a s x) (b : 𝔞) : DifferentiableWithinAt 𝕜 (fun y => b * a y) s x := (ha.hasFDerivWithinAt.const_mul b).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.const_mul (ha : DifferentiableAt 𝕜 a x) (b : 𝔞) : DifferentiableAt 𝕜 (fun y => b * a y) x := (ha.hasFDerivAt.const_mul b).differentiableAt @[fun_prop] theorem DifferentiableOn.const_mul (ha : DifferentiableOn 𝕜 a s) (b : 𝔞) : DifferentiableOn 𝕜 (fun y => b * a y) s := fun x hx => (ha x hx).const_mul b @[fun_prop] theorem Differentiable.const_mul (ha : Differentiable 𝕜 a) (b : 𝔞) : Differentiable 𝕜 fun y => b * a y := fun x => (ha x).const_mul b theorem fderivWithin_const_mul (hxs : UniqueDiffWithinAt 𝕜 s x) (ha : DifferentiableWithinAt 𝕜 a s x) (b : 𝔞) : fderivWithin 𝕜 (fun y => b * a y) s x = b • fderivWithin 𝕜 a s x := (ha.hasFDerivWithinAt.const_mul b).fderivWithin hxs theorem fderiv_const_mul (ha : DifferentiableAt 𝕜 a x) (b : 𝔞) : fderiv 𝕜 (fun y => b * a y) x = b • fderiv 𝕜 a x := (ha.hasFDerivAt.const_mul b).fderiv end Mul section Prod /-! ### Derivative of a finite product of functions -/ variable {ι : Type*} {𝔞 𝔞' : Type*} [NormedRing 𝔞] [NormedCommRing 𝔞'] [NormedAlgebra 𝕜 𝔞] [NormedAlgebra 𝕜 𝔞'] {u : Finset ι} {f : ι → E → 𝔞} {f' : ι → E →L[𝕜] 𝔞} {g : ι → E → 𝔞'} {g' : ι → E →L[𝕜] 𝔞'} @[fun_prop] theorem hasStrictFDerivAt_list_prod' [Fintype ι] {l : List ι} {x : ι → 𝔞} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↩ (l.map x).prod) (∑ i : Fin l.length, ((l.take i).map x).prod • smulRight (proj (l.get i)) ((l.drop (.succ i)).map x).prod) x := by induction l with | nil => simp [hasStrictFDerivAt_const] | cons a l IH => simp only [List.map_cons, List.prod_cons, ← proj_apply (R := 𝕜) (φ := fun _ : ι ↩ 𝔞) a] exact .congr_fderiv (.mul' (ContinuousLinearMap.hasStrictFDerivAt _) IH) (by ext; simp [Fin.sum_univ_succ, Finset.mul_sum, mul_assoc, add_comm]) @[fun_prop] theorem hasStrictFDerivAt_list_prod_finRange' {n : ℕ} {x : Fin n → 𝔞} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↩ ((List.finRange n).map x).prod) (∑ i : Fin n, (((List.finRange n).take i).map x).prod • smulRight (proj i) (((List.finRange n).drop (.succ i)).map x).prod) x := hasStrictFDerivAt_list_prod'.congr_fderiv <| Finset.sum_equiv (finCongr (List.length_finRange n)) (by simp) (by simp [Fin.forall_iff]) @[fun_prop] theorem hasStrictFDerivAt_list_prod_attach' [DecidableEq ι] {l : List ι} {x : {i // i ∈ l} → 𝔞} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↩ (l.attach.map x).prod) (∑ i : Fin l.length, ((l.attach.take i).map x).prod • smulRight (proj (l.attach.get (i.cast l.length_attach.symm))) ((l.attach.drop (.succ i)).map x).prod) x := hasStrictFDerivAt_list_prod'.congr_fderiv <| Eq.symm <| Finset.sum_equiv (finCongr l.length_attach.symm) (by simp) (by simp) @[fun_prop] theorem hasFDerivAt_list_prod' [Fintype ι] {l : List ι} {x : ι → 𝔞'} : HasFDerivAt (𝕜 := 𝕜) (fun x ↩ (l.map x).prod) (∑ i : Fin l.length, ((l.take i).map x).prod • smulRight (proj (l.get i)) ((l.drop (.succ i)).map x).prod) x := hasStrictFDerivAt_list_prod'.hasFDerivAt @[fun_prop] theorem hasFDerivAt_list_prod_finRange' {n : ℕ} {x : Fin n → 𝔞} : HasFDerivAt (𝕜 := 𝕜) (fun x ↩ ((List.finRange n).map x).prod) (∑ i : Fin n, (((List.finRange n).take i).map x).prod • smulRight (proj i) (((List.finRange n).drop (.succ i)).map x).prod) x := (hasStrictFDerivAt_list_prod_finRange').hasFDerivAt @[fun_prop] theorem hasFDerivAt_list_prod_attach' [DecidableEq ι] {l : List ι} {x : {i // i ∈ l} → 𝔞} : HasFDerivAt (𝕜 := 𝕜) (fun x ↩ (l.attach.map x).prod) (∑ i : Fin l.length, ((l.attach.take i).map x).prod • smulRight (proj (l.attach.get (i.cast l.length_attach.symm))) ((l.attach.drop (.succ i)).map x).prod) x := hasStrictFDerivAt_list_prod_attach'.hasFDerivAt /-- Auxiliary lemma for `hasStrictFDerivAt_multiset_prod`. For `NormedCommRing 𝔞'`, can rewrite as `Multiset` using `Multiset.prod_coe`. -/ @[fun_prop] theorem hasStrictFDerivAt_list_prod [DecidableEq ι] [Fintype ι] {l : List ι} {x : ι → 𝔞'} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↩ (l.map x).prod) (l.map fun i ↩ ((l.erase i).map x).prod • proj i).sum x := by refine .congr_fderiv hasStrictFDerivAt_list_prod' ?_ conv_rhs => arg 1; arg 2; rw [← List.finRange_map_get l] simp only [List.map_map, ← List.sum_toFinset _ (List.nodup_finRange _), List.toFinset_finRange, Function.comp_def, ((List.erase_get _).map _).prod_eq, List.eraseIdx_eq_take_drop_succ, List.map_append, List.prod_append] exact Finset.sum_congr rfl fun i _ ↩ by ext; simp only [smul_apply, smulRight_apply, smul_eq_mul]; ring @[fun_prop] theorem hasStrictFDerivAt_multiset_prod [DecidableEq ι] [Fintype ι] {u : Multiset ι} {x : ι → 𝔞'} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↩ (u.map x).prod) (u.map (fun i ↩ ((u.erase i).map x).prod • proj i)).sum x := u.inductionOn fun l ↩ by simpa using hasStrictFDerivAt_list_prod @[fun_prop] theorem hasFDerivAt_multiset_prod [DecidableEq ι] [Fintype ι] {u : Multiset ι} {x : ι → 𝔞'} : HasFDerivAt (𝕜 := 𝕜) (fun x ↩ (u.map x).prod) (Multiset.sum (u.map (fun i ↩ ((u.erase i).map x).prod • proj i))) x := hasStrictFDerivAt_multiset_prod.hasFDerivAt theorem hasStrictFDerivAt_finset_prod [DecidableEq ι] [Fintype ι] {x : ι → 𝔞'} : HasStrictFDerivAt (𝕜 := 𝕜) (∏ i ∈ u, · i) (∑ i ∈ u, (∏ j ∈ u.erase i, x j) • proj i) x := by simp only [Finset.sum_eq_multiset_sum, Finset.prod_eq_multiset_prod] exact hasStrictFDerivAt_multiset_prod theorem hasFDerivAt_finset_prod [DecidableEq ι] [Fintype ι] {x : ι → 𝔞'} : HasFDerivAt (𝕜 := 𝕜) (∏ i ∈ u, · i) (∑ i ∈ u, (∏ j ∈ u.erase i, x j) • proj i) x := hasStrictFDerivAt_finset_prod.hasFDerivAt section Comp @[fun_prop] theorem HasStrictFDerivAt.list_prod' {l : List ι} {x : E} (h : ∀ i ∈ l, HasStrictFDerivAt (f i ·) (f' i) x) : HasStrictFDerivAt (fun x ↩ (l.map (f · x)).prod) (∑ i : Fin l.length, ((l.take i).map (f · x)).prod • smulRight (f' (l.get i)) ((l.drop (.succ i)).map (f · x)).prod) x := by simp only [← List.finRange_map_get l, List.map_map] refine .congr_fderiv (hasStrictFDerivAt_list_prod_finRange'.comp x (hasStrictFDerivAt_pi.mpr fun i ↩ h (l.get i) (l.get_mem i i.isLt))) ?_ ext m simp [← Function.comp_def (f · x) (l.get ·), ← List.map_map, List.map_take, List.map_drop] /-- Unlike `HasFDerivAt.finset_prod`, supports non-commutative multiply and duplicate elements. -/ @[fun_prop] theorem HasFDerivAt.list_prod' {l : List ι} {x : E} (h : ∀ i ∈ l, HasFDerivAt (f i ·) (f' i) x) : HasFDerivAt (fun x ↩ (l.map (f · x)).prod) (∑ i : Fin l.length, ((l.take i).map (f · x)).prod • smulRight (f' (l.get i)) ((l.drop (.succ i)).map (f · x)).prod) x := by simp only [← List.finRange_map_get l, List.map_map] refine .congr_fderiv (hasFDerivAt_list_prod_finRange'.comp x (hasFDerivAt_pi.mpr fun i ↩ h (l.get i) (l.get_mem i i.isLt))) ?_ ext m simp [← Function.comp_def (f · x) (l.get ·), ← List.map_map, List.map_take, List.map_drop] @[fun_prop] theorem HasFDerivWithinAt.list_prod' {l : List ι} {x : E} (h : ∀ i ∈ l, HasFDerivWithinAt (f i ·) (f' i) s x) : HasFDerivWithinAt (fun x ↩ (l.map (f · x)).prod) (∑ i : Fin l.length, ((l.take i).map (f · x)).prod • smulRight (f' (l.get i)) ((l.drop (.succ i)).map (f · x)).prod) s x := by simp only [← List.finRange_map_get l, List.map_map] refine .congr_fderiv (hasFDerivAt_list_prod_finRange'.comp_hasFDerivWithinAt x (hasFDerivWithinAt_pi.mpr fun i ↩ h (l.get i) (l.get_mem i i.isLt))) ?_ ext m simp [← Function.comp_def (f · x) (l.get ·), ← List.map_map, List.map_take, List.map_drop] theorem fderiv_list_prod' {l : List ι} {x : E} (h : ∀ i ∈ l, DifferentiableAt 𝕜 (f i ·) x) : fderiv 𝕜 (fun x ↩ (l.map (f · x)).prod) x = ∑ i : Fin l.length, ((l.take i).map (f · x)).prod • smulRight (fderiv 𝕜 (fun x ↩ f (l.get i) x) x) ((l.drop (.succ i)).map (f · x)).prod := (HasFDerivAt.list_prod' fun i hi ↩ (h i hi).hasFDerivAt).fderiv theorem fderivWithin_list_prod' {l : List ι} {x : E} (hxs : UniqueDiffWithinAt 𝕜 s x) (h : ∀ i ∈ l, DifferentiableWithinAt 𝕜 (f i ·) s x) : fderivWithin 𝕜 (fun x ↩ (l.map (f · x)).prod) s x = ∑ i : Fin l.length, ((l.take i).map (f · x)).prod • smulRight (fderivWithin 𝕜 (fun x ↩ f (l.get i) x) s x) ((l.drop (.succ i)).map (f · x)).prod := (HasFDerivWithinAt.list_prod' fun i hi ↩ (h i hi).hasFDerivWithinAt).fderivWithin hxs @[fun_prop] theorem HasStrictFDerivAt.multiset_prod [DecidableEq ι] {u : Multiset ι} {x : E} (h : ∀ i ∈ u, HasStrictFDerivAt (g i ·) (g' i) x) : HasStrictFDerivAt (fun x ↩ (u.map (g · x)).prod) (u.map fun i ↩ ((u.erase i).map (g · x)).prod • g' i).sum x := by simp only [← Multiset.attach_map_val u, Multiset.map_map] exact .congr_fderiv (hasStrictFDerivAt_multiset_prod.comp x <| hasStrictFDerivAt_pi.mpr fun i ↩ h i i.prop) (by ext; simp [Finset.sum_multiset_map_count, u.erase_attach_map (g · x)]) /-- Unlike `HasFDerivAt.finset_prod`, supports duplicate elements. -/ @[fun_prop] theorem HasFDerivAt.multiset_prod [DecidableEq ι] {u : Multiset ι} {x : E} (h : ∀ i ∈ u, HasFDerivAt (g i ·) (g' i) x) : HasFDerivAt (fun x ↩ (u.map (g · x)).prod) (u.map fun i ↩ ((u.erase i).map (g · x)).prod • g' i).sum x := by simp only [← Multiset.attach_map_val u, Multiset.map_map] exact .congr_fderiv (hasFDerivAt_multiset_prod.comp x <| hasFDerivAt_pi.mpr fun i ↩ h i i.prop) (by ext; simp [Finset.sum_multiset_map_count, u.erase_attach_map (g · x)]) @[fun_prop] theorem HasFDerivWithinAt.multiset_prod [DecidableEq ι] {u : Multiset ι} {x : E} (h : ∀ i ∈ u, HasFDerivWithinAt (g i ·) (g' i) s x) : HasFDerivWithinAt (fun x ↩ (u.map (g · x)).prod) (u.map fun i ↩ ((u.erase i).map (g · x)).prod • g' i).sum s x := by simp only [← Multiset.attach_map_val u, Multiset.map_map] exact .congr_fderiv (hasFDerivAt_multiset_prod.comp_hasFDerivWithinAt x <| hasFDerivWithinAt_pi.mpr fun i ↩ h i i.prop) (by ext; simp [Finset.sum_multiset_map_count, u.erase_attach_map (g · x)]) theorem fderiv_multiset_prod [DecidableEq ι] {u : Multiset ι} {x : E} (h : ∀ i ∈ u, DifferentiableAt 𝕜 (g i ·) x) : fderiv 𝕜 (fun x ↩ (u.map (g · x)).prod) x = (u.map fun i ↩ ((u.erase i).map (g · x)).prod • fderiv 𝕜 (g i) x).sum := (HasFDerivAt.multiset_prod fun i hi ↩ (h i hi).hasFDerivAt).fderiv theorem fderivWithin_multiset_prod [DecidableEq ι] {u : Multiset ι} {x : E} (hxs : UniqueDiffWithinAt 𝕜 s x) (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (g i ·) s x) : fderivWithin 𝕜 (fun x ↩ (u.map (g · x)).prod) s x = (u.map fun i ↩ ((u.erase i).map (g · x)).prod • fderivWithin 𝕜 (g i) s x).sum := (HasFDerivWithinAt.multiset_prod fun i hi ↩ (h i hi).hasFDerivWithinAt).fderivWithin hxs theorem HasStrictFDerivAt.finset_prod [DecidableEq ι] {x : E} (hg : ∀ i ∈ u, HasStrictFDerivAt (g i) (g' i) x) : HasStrictFDerivAt (∏ i ∈ u, g i ·) (∑ i ∈ u, (∏ j ∈ u.erase i, g j x) • g' i) x := by simpa [← Finset.prod_attach u] using .congr_fderiv (hasStrictFDerivAt_finset_prod.comp x <| hasStrictFDerivAt_pi.mpr fun i ↩ hg i i.prop) (by ext; simp [Finset.prod_erase_attach (g · x), ← u.sum_attach]) theorem HasFDerivAt.finset_prod [DecidableEq ι] {x : E} (hg : ∀ i ∈ u, HasFDerivAt (g i) (g' i) x) : HasFDerivAt (∏ i ∈ u, g i ·) (∑ i ∈ u, (∏ j ∈ u.erase i, g j x) • g' i) x := by simpa [← Finset.prod_attach u] using .congr_fderiv (hasFDerivAt_finset_prod.comp x <| hasFDerivAt_pi.mpr fun i ↩ hg i i.prop) (by ext; simp [Finset.prod_erase_attach (g · x), ← u.sum_attach]) theorem HasFDerivWithinAt.finset_prod [DecidableEq ι] {x : E} (hg : ∀ i ∈ u, HasFDerivWithinAt (g i) (g' i) s x) : HasFDerivWithinAt (∏ i ∈ u, g i ·) (∑ i ∈ u, (∏ j ∈ u.erase i, g j x) • g' i) s x := by simpa [← Finset.prod_attach u] using .congr_fderiv (hasFDerivAt_finset_prod.comp_hasFDerivWithinAt x <| hasFDerivWithinAt_pi.mpr fun i ↩ hg i i.prop) (by ext; simp [Finset.prod_erase_attach (g · x), ← u.sum_attach]) theorem fderiv_finset_prod [DecidableEq ι] {x : E} (hg : ∀ i ∈ u, DifferentiableAt 𝕜 (g i) x) : fderiv 𝕜 (∏ i ∈ u, g i ·) x = ∑ i ∈ u, (∏ j ∈ u.erase i, (g j x)) • fderiv 𝕜 (g i) x := (HasFDerivAt.finset_prod fun i hi ↩ (hg i hi).hasFDerivAt).fderiv theorem fderivWithin_finset_prod [DecidableEq ι] {x : E} (hxs : UniqueDiffWithinAt 𝕜 s x) (hg : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (g i) s x) : fderivWithin 𝕜 (∏ i ∈ u, g i ·) s x = ∑ i ∈ u, (∏ j ∈ u.erase i, (g j x)) • fderivWithin 𝕜 (g i) s x := (HasFDerivWithinAt.finset_prod fun i hi ↩ (hg i hi).hasFDerivWithinAt).fderivWithin hxs end Comp end Prod section AlgebraInverse variable {R : Type*} [NormedRing R] [NormedAlgebra 𝕜 R] [CompleteSpace R] open NormedRing ContinuousLinearMap Ring /-- At an invertible element `x` of a normed algebra `R`, the Fréchet derivative of the inversion operation is the linear map `fun t ↩ - x⁻¹ * t * x⁻¹`. TODO: prove that `Ring.inverse` is analytic and use it to prove a `HasStrictFDerivAt` lemma. TODO (low prio): prove a version without assumption `[CompleteSpace R]` but within the set of units. -/ @[fun_prop] theorem hasFDerivAt_ring_inverse (x : RË£) : HasFDerivAt Ring.inverse (-mulLeftRight 𝕜 R ↑x⁻¹ ↑x⁻¹) x := have : (fun t : R => Ring.inverse (↑x + t) - ↑x⁻¹ + ↑x⁻¹ * t * ↑x⁻¹) =o[𝓝 0] id := (inverse_add_norm_diff_second_order x).trans_isLittleO (isLittleO_norm_pow_id one_lt_two) by simpa [hasFDerivAt_iff_isLittleO_nhds_zero] using this @[fun_prop] theorem differentiableAt_inverse {x : R} (hx : IsUnit x) : DifferentiableAt 𝕜 (@Ring.inverse R _) x := let ⟹u, hu⟩ := hx; hu ▾ (hasFDerivAt_ring_inverse u).differentiableAt @[fun_prop] theorem differentiableWithinAt_inverse {x : R} (hx : IsUnit x) (s : Set R) : DifferentiableWithinAt 𝕜 (@Ring.inverse R _) s x := (differentiableAt_inverse hx).differentiableWithinAt @[fun_prop] theorem differentiableOn_inverse : DifferentiableOn 𝕜 (@Ring.inverse R _) {x | IsUnit x} := fun _x hx => differentiableWithinAt_inverse hx _ theorem fderiv_inverse (x : RË£) : fderiv 𝕜 (@Ring.inverse R _) x = -mulLeftRight 𝕜 R ↑x⁻¹ ↑x⁻¹ := (hasFDerivAt_ring_inverse x).fderiv variable {h : E → R} {z : E} {S : Set E} @[fun_prop] theorem DifferentiableWithinAt.inverse (hf : DifferentiableWithinAt 𝕜 h S z) (hz : IsUnit (h z)) : DifferentiableWithinAt 𝕜 (fun x => Ring.inverse (h x)) S z := (differentiableAt_inverse hz).comp_differentiableWithinAt z hf @[simp, fun_prop] theorem DifferentiableAt.inverse (hf : DifferentiableAt 𝕜 h z) (hz : IsUnit (h z)) : DifferentiableAt 𝕜 (fun x => Ring.inverse (h x)) z := (differentiableAt_inverse hz).comp z hf @[fun_prop] theorem DifferentiableOn.inverse (hf : DifferentiableOn 𝕜 h S) (hz : ∀ x ∈ S, IsUnit (h x)) : DifferentiableOn 𝕜 (fun x => Ring.inverse (h x)) S := fun x h => (hf x h).inverse (hz x h) @[simp, fun_prop] theorem Differentiable.inverse (hf : Differentiable 𝕜 h) (hz : ∀ x, IsUnit (h x)) : Differentiable 𝕜 fun x => Ring.inverse (h x) := fun x => (hf x).inverse (hz x) end AlgebraInverse /-! ### Derivative of the inverse in a division ring Note these lemmas are primed as they need `CompleteSpace R`, whereas the other lemmas in `Mathlib/Analysis/Calculus/Deriv/Inv.lean` do not, but instead need `NontriviallyNormedField R`. -/ section DivisionRingInverse variable {R : Type*} [NormedDivisionRing R] [NormedAlgebra 𝕜 R] [CompleteSpace R] open NormedRing ContinuousLinearMap Ring /-- At an invertible element `x` of a normed division algebra `R`, the Fréchet derivative of the inversion operation is the linear map `fun t ↩ - x⁻¹ * t * x⁻¹`. -/ @[fun_prop] theorem hasFDerivAt_inv' {x : R} (hx : x ≠ 0) : HasFDerivAt Inv.inv (-mulLeftRight 𝕜 R x⁻¹ x⁻¹) x := by simpa using hasFDerivAt_ring_inverse (Units.mk0 _ hx) @[fun_prop] theorem differentiableAt_inv' {x : R} (hx : x ≠ 0) : DifferentiableAt 𝕜 Inv.inv x := (hasFDerivAt_inv' hx).differentiableAt @[fun_prop] theorem differentiableWithinAt_inv' {x : R} (hx : x ≠ 0) (s : Set R) : DifferentiableWithinAt 𝕜 (fun x => x⁻¹) s x := (differentiableAt_inv' hx).differentiableWithinAt @[fun_prop] theorem differentiableOn_inv' : DifferentiableOn 𝕜 (fun x : R => x⁻¹) {x | x ≠ 0} := fun _x hx => differentiableWithinAt_inv' hx _ /-- Non-commutative version of `fderiv_inv` -/ theorem fderiv_inv' {x : R} (hx : x ≠ 0) : fderiv 𝕜 Inv.inv x = -mulLeftRight 𝕜 R x⁻¹ x⁻¹ := (hasFDerivAt_inv' hx).fderiv /-- Non-commutative version of `fderivWithin_inv` -/ theorem fderivWithin_inv' {s : Set R} {x : R} (hx : x ≠ 0) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x => x⁻¹) s x = -mulLeftRight 𝕜 R x⁻¹ x⁻¹ := by rw [DifferentiableAt.fderivWithin (differentiableAt_inv' hx) hxs] exact fderiv_inv' hx variable {h : E → R} {z : E} {S : Set E} @[fun_prop] theorem DifferentiableWithinAt.inv' (hf : DifferentiableWithinAt 𝕜 h S z) (hz : h z ≠ 0) : DifferentiableWithinAt 𝕜 (fun x => (h x)⁻¹) S z := (differentiableAt_inv' hz).comp_differentiableWithinAt z hf @[simp, fun_prop] theorem DifferentiableAt.inv' (hf : DifferentiableAt 𝕜 h z) (hz : h z ≠ 0) : DifferentiableAt 𝕜 (fun x => (h x)⁻¹) z := (differentiableAt_inv' hz).comp z hf @[fun_prop] theorem DifferentiableOn.inv' (hf : DifferentiableOn 𝕜 h S) (hz : ∀ x ∈ S, h x ≠ 0) : DifferentiableOn 𝕜 (fun x => (h x)⁻¹) S := fun x h => (hf x h).inv' (hz x h) @[simp, fun_prop] theorem Differentiable.inv' (hf : Differentiable 𝕜 h) (hz : ∀ x, h x ≠ 0) : Differentiable 𝕜 fun x => (h x)⁻¹ := fun x => (hf x).inv' (hz x) end DivisionRingInverse end
Analysis\Calculus\FDeriv\Pi.lean
/- Copyright (c) 2023 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Heather Macbeth -/ import Mathlib.Analysis.Calculus.FDeriv.Add /-! # Derivatives on pi-types. -/ variable {𝕜 ι : Type*} [DecidableEq ι] [Fintype ι] [NontriviallyNormedField 𝕜] variable {E : ι → Type*} [∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] @[fun_prop] theorem hasFDerivAt_update (x : ∀ i, E i) {i : ι} (y : E i) : HasFDerivAt (Function.update x i) (.pi (Pi.single i (.id 𝕜 (E i)))) y := by set l := (ContinuousLinearMap.pi (Pi.single i (.id 𝕜 (E i)))) have update_eq : Function.update x i = (fun _ ↩ x) + l ∘ (· - x i) := by ext t j dsimp [l, Pi.single, Function.update] split_ifs with hji · subst hji simp · simp rw [update_eq] convert (hasFDerivAt_const _ _).add (l.hasFDerivAt.comp y (hasFDerivAt_sub_const (x i))) rw [zero_add, ContinuousLinearMap.comp_id] @[fun_prop] theorem hasFDerivAt_single {i : ι} (y : E i) : HasFDerivAt (Pi.single i) (.pi (Pi.single i (.id 𝕜 (E i)))) y := hasFDerivAt_update 0 y theorem fderiv_update (x : ∀ i, E i) {i : ι} (y : E i) : fderiv 𝕜 (Function.update x i) y = .pi (Pi.single i (.id 𝕜 (E i))) := (hasFDerivAt_update x y).fderiv theorem fderiv_single {i : ι} (y : E i) : fderiv 𝕜 (Pi.single i) y = .pi (Pi.single i (.id 𝕜 (E i))) := fderiv_update 0 y
Analysis\Calculus\FDeriv\Prod.lean
/- 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 Mathlib.Analysis.Calculus.FDeriv.Linear import Mathlib.Analysis.Calculus.FDeriv.Comp /-! # Derivative of the cartesian product of functions For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of cartesian products of functions, and functions into Pi-types. -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} section CartesianProduct /-! ### Derivative of the cartesian product of two functions -/ section Prod variable {f₂ : E → G} {f₂' : E →L[𝕜] G} protected theorem HasStrictFDerivAt.prod (hf₁ : HasStrictFDerivAt f₁ f₁' x) (hf₂ : HasStrictFDerivAt f₂ f₂' x) : HasStrictFDerivAt (fun x => (f₁ x, f₂ x)) (f₁'.prod f₂') x := hf₁.prod_left hf₂ theorem HasFDerivAtFilter.prod (hf₁ : HasFDerivAtFilter f₁ f₁' x L) (hf₂ : HasFDerivAtFilter f₂ f₂' x L) : HasFDerivAtFilter (fun x => (f₁ x, f₂ x)) (f₁'.prod f₂') x L := .of_isLittleO <| hf₁.isLittleO.prod_left hf₂.isLittleO @[fun_prop] nonrec theorem HasFDerivWithinAt.prod (hf₁ : HasFDerivWithinAt f₁ f₁' s x) (hf₂ : HasFDerivWithinAt f₂ f₂' s x) : HasFDerivWithinAt (fun x => (f₁ x, f₂ x)) (f₁'.prod f₂') s x := hf₁.prod hf₂ @[fun_prop] nonrec theorem HasFDerivAt.prod (hf₁ : HasFDerivAt f₁ f₁' x) (hf₂ : HasFDerivAt f₂ f₂' x) : HasFDerivAt (fun x => (f₁ x, f₂ x)) (f₁'.prod f₂') x := hf₁.prod hf₂ @[fun_prop] theorem hasFDerivAt_prod_mk_left (e₀ : E) (f₀ : F) : HasFDerivAt (fun e : E => (e, f₀)) (inl 𝕜 E F) e₀ := (hasFDerivAt_id e₀).prod (hasFDerivAt_const f₀ e₀) @[fun_prop] theorem hasFDerivAt_prod_mk_right (e₀ : E) (f₀ : F) : HasFDerivAt (fun f : F => (e₀, f)) (inr 𝕜 E F) f₀ := (hasFDerivAt_const e₀ f₀).prod (hasFDerivAt_id f₀) @[fun_prop] theorem DifferentiableWithinAt.prod (hf₁ : DifferentiableWithinAt 𝕜 f₁ s x) (hf₂ : DifferentiableWithinAt 𝕜 f₂ s x) : DifferentiableWithinAt 𝕜 (fun x : E => (f₁ x, f₂ x)) s x := (hf₁.hasFDerivWithinAt.prod hf₂.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.prod (hf₁ : DifferentiableAt 𝕜 f₁ x) (hf₂ : DifferentiableAt 𝕜 f₂ x) : DifferentiableAt 𝕜 (fun x : E => (f₁ x, f₂ x)) x := (hf₁.hasFDerivAt.prod hf₂.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.prod (hf₁ : DifferentiableOn 𝕜 f₁ s) (hf₂ : DifferentiableOn 𝕜 f₂ s) : DifferentiableOn 𝕜 (fun x : E => (f₁ x, f₂ x)) s := fun x hx => DifferentiableWithinAt.prod (hf₁ x hx) (hf₂ x hx) @[simp, fun_prop] theorem Differentiable.prod (hf₁ : Differentiable 𝕜 f₁) (hf₂ : Differentiable 𝕜 f₂) : Differentiable 𝕜 fun x : E => (f₁ x, f₂ x) := fun x => DifferentiableAt.prod (hf₁ x) (hf₂ x) theorem DifferentiableAt.fderiv_prod (hf₁ : DifferentiableAt 𝕜 f₁ x) (hf₂ : DifferentiableAt 𝕜 f₂ x) : fderiv 𝕜 (fun x : E => (f₁ x, f₂ x)) x = (fderiv 𝕜 f₁ x).prod (fderiv 𝕜 f₂ x) := (hf₁.hasFDerivAt.prod hf₂.hasFDerivAt).fderiv theorem DifferentiableWithinAt.fderivWithin_prod (hf₁ : DifferentiableWithinAt 𝕜 f₁ s x) (hf₂ : DifferentiableWithinAt 𝕜 f₂ s x) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x : E => (f₁ x, f₂ x)) s x = (fderivWithin 𝕜 f₁ s x).prod (fderivWithin 𝕜 f₂ s x) := (hf₁.hasFDerivWithinAt.prod hf₂.hasFDerivWithinAt).fderivWithin hxs end Prod section Fst variable {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F} @[fun_prop] theorem hasStrictFDerivAt_fst : HasStrictFDerivAt (@Prod.fst E F) (fst 𝕜 E F) p := (fst 𝕜 E F).hasStrictFDerivAt @[fun_prop] protected theorem HasStrictFDerivAt.fst (h : HasStrictFDerivAt f₂ f₂' x) : HasStrictFDerivAt (fun x => (f₂ x).1) ((fst 𝕜 F G).comp f₂') x := hasStrictFDerivAt_fst.comp x h theorem hasFDerivAtFilter_fst {L : Filter (E × F)} : HasFDerivAtFilter (@Prod.fst E F) (fst 𝕜 E F) p L := (fst 𝕜 E F).hasFDerivAtFilter protected theorem HasFDerivAtFilter.fst (h : HasFDerivAtFilter f₂ f₂' x L) : HasFDerivAtFilter (fun x => (f₂ x).1) ((fst 𝕜 F G).comp f₂') x L := hasFDerivAtFilter_fst.comp x h tendsto_map @[fun_prop] theorem hasFDerivAt_fst : HasFDerivAt (@Prod.fst E F) (fst 𝕜 E F) p := hasFDerivAtFilter_fst @[fun_prop] protected nonrec theorem HasFDerivAt.fst (h : HasFDerivAt f₂ f₂' x) : HasFDerivAt (fun x => (f₂ x).1) ((fst 𝕜 F G).comp f₂') x := h.fst @[fun_prop] theorem hasFDerivWithinAt_fst {s : Set (E × F)} : HasFDerivWithinAt (@Prod.fst E F) (fst 𝕜 E F) s p := hasFDerivAtFilter_fst @[fun_prop] protected nonrec theorem HasFDerivWithinAt.fst (h : HasFDerivWithinAt f₂ f₂' s x) : HasFDerivWithinAt (fun x => (f₂ x).1) ((fst 𝕜 F G).comp f₂') s x := h.fst @[fun_prop] theorem differentiableAt_fst : DifferentiableAt 𝕜 Prod.fst p := hasFDerivAt_fst.differentiableAt @[simp, fun_prop] protected theorem DifferentiableAt.fst (h : DifferentiableAt 𝕜 f₂ x) : DifferentiableAt 𝕜 (fun x => (f₂ x).1) x := differentiableAt_fst.comp x h @[fun_prop] theorem differentiable_fst : Differentiable 𝕜 (Prod.fst : E × F → E) := fun _ => differentiableAt_fst @[simp, fun_prop] protected theorem Differentiable.fst (h : Differentiable 𝕜 f₂) : Differentiable 𝕜 fun x => (f₂ x).1 := differentiable_fst.comp h @[fun_prop] theorem differentiableWithinAt_fst {s : Set (E × F)} : DifferentiableWithinAt 𝕜 Prod.fst s p := differentiableAt_fst.differentiableWithinAt @[fun_prop] protected theorem DifferentiableWithinAt.fst (h : DifferentiableWithinAt 𝕜 f₂ s x) : DifferentiableWithinAt 𝕜 (fun x => (f₂ x).1) s x := differentiableAt_fst.comp_differentiableWithinAt x h @[fun_prop] theorem differentiableOn_fst {s : Set (E × F)} : DifferentiableOn 𝕜 Prod.fst s := differentiable_fst.differentiableOn @[fun_prop] protected theorem DifferentiableOn.fst (h : DifferentiableOn 𝕜 f₂ s) : DifferentiableOn 𝕜 (fun x => (f₂ x).1) s := differentiable_fst.comp_differentiableOn h theorem fderiv_fst : fderiv 𝕜 Prod.fst p = fst 𝕜 E F := hasFDerivAt_fst.fderiv theorem fderiv.fst (h : DifferentiableAt 𝕜 f₂ x) : fderiv 𝕜 (fun x => (f₂ x).1) x = (fst 𝕜 F G).comp (fderiv 𝕜 f₂ x) := h.hasFDerivAt.fst.fderiv theorem fderivWithin_fst {s : Set (E × F)} (hs : UniqueDiffWithinAt 𝕜 s p) : fderivWithin 𝕜 Prod.fst s p = fst 𝕜 E F := hasFDerivWithinAt_fst.fderivWithin hs theorem fderivWithin.fst (hs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f₂ s x) : fderivWithin 𝕜 (fun x => (f₂ x).1) s x = (fst 𝕜 F G).comp (fderivWithin 𝕜 f₂ s x) := h.hasFDerivWithinAt.fst.fderivWithin hs end Fst section Snd variable {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F} @[fun_prop] theorem hasStrictFDerivAt_snd : HasStrictFDerivAt (@Prod.snd E F) (snd 𝕜 E F) p := (snd 𝕜 E F).hasStrictFDerivAt @[fun_prop] protected theorem HasStrictFDerivAt.snd (h : HasStrictFDerivAt f₂ f₂' x) : HasStrictFDerivAt (fun x => (f₂ x).2) ((snd 𝕜 F G).comp f₂') x := hasStrictFDerivAt_snd.comp x h theorem hasFDerivAtFilter_snd {L : Filter (E × F)} : HasFDerivAtFilter (@Prod.snd E F) (snd 𝕜 E F) p L := (snd 𝕜 E F).hasFDerivAtFilter protected theorem HasFDerivAtFilter.snd (h : HasFDerivAtFilter f₂ f₂' x L) : HasFDerivAtFilter (fun x => (f₂ x).2) ((snd 𝕜 F G).comp f₂') x L := hasFDerivAtFilter_snd.comp x h tendsto_map @[fun_prop] theorem hasFDerivAt_snd : HasFDerivAt (@Prod.snd E F) (snd 𝕜 E F) p := hasFDerivAtFilter_snd @[fun_prop] protected nonrec theorem HasFDerivAt.snd (h : HasFDerivAt f₂ f₂' x) : HasFDerivAt (fun x => (f₂ x).2) ((snd 𝕜 F G).comp f₂') x := h.snd @[fun_prop] theorem hasFDerivWithinAt_snd {s : Set (E × F)} : HasFDerivWithinAt (@Prod.snd E F) (snd 𝕜 E F) s p := hasFDerivAtFilter_snd @[fun_prop] protected nonrec theorem HasFDerivWithinAt.snd (h : HasFDerivWithinAt f₂ f₂' s x) : HasFDerivWithinAt (fun x => (f₂ x).2) ((snd 𝕜 F G).comp f₂') s x := h.snd @[fun_prop] theorem differentiableAt_snd : DifferentiableAt 𝕜 Prod.snd p := hasFDerivAt_snd.differentiableAt @[simp, fun_prop] protected theorem DifferentiableAt.snd (h : DifferentiableAt 𝕜 f₂ x) : DifferentiableAt 𝕜 (fun x => (f₂ x).2) x := differentiableAt_snd.comp x h @[fun_prop] theorem differentiable_snd : Differentiable 𝕜 (Prod.snd : E × F → F) := fun _ => differentiableAt_snd @[simp, fun_prop] protected theorem Differentiable.snd (h : Differentiable 𝕜 f₂) : Differentiable 𝕜 fun x => (f₂ x).2 := differentiable_snd.comp h @[fun_prop] theorem differentiableWithinAt_snd {s : Set (E × F)} : DifferentiableWithinAt 𝕜 Prod.snd s p := differentiableAt_snd.differentiableWithinAt @[fun_prop] protected theorem DifferentiableWithinAt.snd (h : DifferentiableWithinAt 𝕜 f₂ s x) : DifferentiableWithinAt 𝕜 (fun x => (f₂ x).2) s x := differentiableAt_snd.comp_differentiableWithinAt x h @[fun_prop] theorem differentiableOn_snd {s : Set (E × F)} : DifferentiableOn 𝕜 Prod.snd s := differentiable_snd.differentiableOn @[fun_prop] protected theorem DifferentiableOn.snd (h : DifferentiableOn 𝕜 f₂ s) : DifferentiableOn 𝕜 (fun x => (f₂ x).2) s := differentiable_snd.comp_differentiableOn h theorem fderiv_snd : fderiv 𝕜 Prod.snd p = snd 𝕜 E F := hasFDerivAt_snd.fderiv theorem fderiv.snd (h : DifferentiableAt 𝕜 f₂ x) : fderiv 𝕜 (fun x => (f₂ x).2) x = (snd 𝕜 F G).comp (fderiv 𝕜 f₂ x) := h.hasFDerivAt.snd.fderiv theorem fderivWithin_snd {s : Set (E × F)} (hs : UniqueDiffWithinAt 𝕜 s p) : fderivWithin 𝕜 Prod.snd s p = snd 𝕜 E F := hasFDerivWithinAt_snd.fderivWithin hs theorem fderivWithin.snd (hs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f₂ s x) : fderivWithin 𝕜 (fun x => (f₂ x).2) s x = (snd 𝕜 F G).comp (fderivWithin 𝕜 f₂ s x) := h.hasFDerivWithinAt.snd.fderivWithin hs end Snd section prodMap variable {f₂ : G → G'} {f₂' : G →L[𝕜] G'} {y : G} (p : E × G) @[fun_prop] protected theorem HasStrictFDerivAt.prodMap (hf : HasStrictFDerivAt f f' p.1) (hf₂ : HasStrictFDerivAt f₂ f₂' p.2) : HasStrictFDerivAt (Prod.map f f₂) (f'.prodMap f₂') p := (hf.comp p hasStrictFDerivAt_fst).prod (hf₂.comp p hasStrictFDerivAt_snd) @[fun_prop] protected theorem HasFDerivAt.prodMap (hf : HasFDerivAt f f' p.1) (hf₂ : HasFDerivAt f₂ f₂' p.2) : HasFDerivAt (Prod.map f f₂) (f'.prodMap f₂') p := (hf.comp p hasFDerivAt_fst).prod (hf₂.comp p hasFDerivAt_snd) @[simp, fun_prop] protected theorem DifferentiableAt.prod_map (hf : DifferentiableAt 𝕜 f p.1) (hf₂ : DifferentiableAt 𝕜 f₂ p.2) : DifferentiableAt 𝕜 (fun p : E × G => (f p.1, f₂ p.2)) p := (hf.comp p differentiableAt_fst).prod (hf₂.comp p differentiableAt_snd) end prodMap section Pi /-! ### Derivatives of functions `f : E → Π i, F' i` In this section we formulate `has*FDeriv*_pi` theorems as `iff`s, and provide two versions of each theorem: * the version without `'` deals with `φ : Π i, E → F' i` and `φ' : Π i, E →L[𝕜] F' i` and is designed to deduce differentiability of `fun x i ↩ φ i x` from differentiability of each `φ i`; * the version with `'` deals with `Ί : E → Π i, F' i` and `Ί' : E →L[𝕜] Π i, F' i` and is designed to deduce differentiability of the components `fun x ↩ Ί x i` from differentiability of `Ί`. -/ variable {ι : Type*} [Fintype ι] {F' : ι → Type*} [∀ i, NormedAddCommGroup (F' i)] [∀ i, NormedSpace 𝕜 (F' i)] {φ : ∀ i, E → F' i} {φ' : ∀ i, E →L[𝕜] F' i} {Ί : E → ∀ i, F' i} {Ί' : E →L[𝕜] ∀ i, F' i} @[simp] theorem hasStrictFDerivAt_pi' : HasStrictFDerivAt Ί Ί' x ↔ ∀ i, HasStrictFDerivAt (fun x => Ί x i) ((proj i).comp Ί') x := by simp only [HasStrictFDerivAt, ContinuousLinearMap.coe_pi] exact isLittleO_pi @[fun_prop] theorem hasStrictFDerivAt_pi'' (hφ : ∀ i, HasStrictFDerivAt (fun x => Ί x i) ((proj i).comp Ί') x) : HasStrictFDerivAt Ί Ί' x := hasStrictFDerivAt_pi'.2 hφ @[fun_prop] theorem hasStrictFDerivAt_apply (i : ι) (f : ∀ i, F' i) : HasStrictFDerivAt (𝕜 := 𝕜) (fun f : ∀ i, F' i => f i) (proj i) f := by let id' := ContinuousLinearMap.id 𝕜 (∀ i, F' i) have h := ((hasStrictFDerivAt_pi' (Ί := fun (f : ∀ i, F' i) (i' : ι) => f i') (Ί' := id') (x := f))).1 have h' : comp (proj i) id' = proj i := by rfl rw [← h']; apply h; apply hasStrictFDerivAt_id @[simp 1100] -- Porting note: increased priority to make lint happy theorem hasStrictFDerivAt_pi : HasStrictFDerivAt (fun x i => φ i x) (ContinuousLinearMap.pi φ') x ↔ ∀ i, HasStrictFDerivAt (φ i) (φ' i) x := hasStrictFDerivAt_pi' @[simp] theorem hasFDerivAtFilter_pi' : HasFDerivAtFilter Ί Ί' x L ↔ ∀ i, HasFDerivAtFilter (fun x => Ί x i) ((proj i).comp Ί') x L := by simp only [hasFDerivAtFilter_iff_isLittleO, ContinuousLinearMap.coe_pi] exact isLittleO_pi theorem hasFDerivAtFilter_pi : HasFDerivAtFilter (fun x i => φ i x) (ContinuousLinearMap.pi φ') x L ↔ ∀ i, HasFDerivAtFilter (φ i) (φ' i) x L := hasFDerivAtFilter_pi' @[simp] theorem hasFDerivAt_pi' : HasFDerivAt Ί Ί' x ↔ ∀ i, HasFDerivAt (fun x => Ί x i) ((proj i).comp Ί') x := hasFDerivAtFilter_pi' @[fun_prop] theorem hasFDerivAt_pi'' (hφ : ∀ i, HasFDerivAt (fun x => Ί x i) ((proj i).comp Ί') x) : HasFDerivAt Ί Ί' x := hasFDerivAt_pi'.2 hφ @[fun_prop] theorem hasFDerivAt_apply (i : ι) (f : ∀ i, F' i) : HasFDerivAt (𝕜 := 𝕜) (fun f : ∀ i, F' i => f i) (proj i) f := by apply HasStrictFDerivAt.hasFDerivAt apply hasStrictFDerivAt_apply theorem hasFDerivAt_pi : HasFDerivAt (fun x i => φ i x) (ContinuousLinearMap.pi φ') x ↔ ∀ i, HasFDerivAt (φ i) (φ' i) x := hasFDerivAtFilter_pi @[simp] theorem hasFDerivWithinAt_pi' : HasFDerivWithinAt Ί Ί' s x ↔ ∀ i, HasFDerivWithinAt (fun x => Ί x i) ((proj i).comp Ί') s x := hasFDerivAtFilter_pi' @[fun_prop] theorem hasFDerivWithinAt_pi'' (hφ : ∀ i, HasFDerivWithinAt (fun x => Ί x i) ((proj i).comp Ί') s x) : HasFDerivWithinAt Ί Ί' s x := hasFDerivWithinAt_pi'.2 hφ @[fun_prop] theorem hasFDerivWithinAt_apply (i : ι) (f : ∀ i, F' i) (s' : Set (∀ i, F' i)) : HasFDerivWithinAt (𝕜 := 𝕜) (fun f : ∀ i, F' i => f i) (proj i) s' f := by let id' := ContinuousLinearMap.id 𝕜 (∀ i, F' i) have h := ((hasFDerivWithinAt_pi' (Ί := fun (f : ∀ i, F' i) (i' : ι) => f i') (Ί' := id') (x := f) (s := s'))).1 have h' : comp (proj i) id' = proj i := by rfl rw [← h']; apply h; apply hasFDerivWithinAt_id theorem hasFDerivWithinAt_pi : HasFDerivWithinAt (fun x i => φ i x) (ContinuousLinearMap.pi φ') s x ↔ ∀ i, HasFDerivWithinAt (φ i) (φ' i) s x := hasFDerivAtFilter_pi @[simp] theorem differentiableWithinAt_pi : DifferentiableWithinAt 𝕜 Ί s x ↔ ∀ i, DifferentiableWithinAt 𝕜 (fun x => Ί x i) s x := ⟹fun h i => (hasFDerivWithinAt_pi'.1 h.hasFDerivWithinAt i).differentiableWithinAt, fun h => (hasFDerivWithinAt_pi.2 fun i => (h i).hasFDerivWithinAt).differentiableWithinAt⟩ @[fun_prop] theorem differentiableWithinAt_pi'' (hφ : ∀ i, DifferentiableWithinAt 𝕜 (fun x => Ί x i) s x) : DifferentiableWithinAt 𝕜 Ί s x := differentiableWithinAt_pi.2 hφ @[fun_prop] theorem differentiableWithinAt_apply (i : ι) (f : ∀ i, F' i) (s' : Set (∀ i, F' i)) : DifferentiableWithinAt (𝕜 := 𝕜) (fun f : ∀ i, F' i => f i) s' f := by apply HasFDerivWithinAt.differentiableWithinAt fun_prop @[simp] theorem differentiableAt_pi : DifferentiableAt 𝕜 Ί x ↔ ∀ i, DifferentiableAt 𝕜 (fun x => Ί x i) x := ⟹fun h i => (hasFDerivAt_pi'.1 h.hasFDerivAt i).differentiableAt, fun h => (hasFDerivAt_pi.2 fun i => (h i).hasFDerivAt).differentiableAt⟩ @[fun_prop] theorem differentiableAt_pi'' (hφ : ∀ i, DifferentiableAt 𝕜 (fun x => Ί x i) x) : DifferentiableAt 𝕜 Ί x := differentiableAt_pi.2 hφ @[fun_prop] theorem differentiableAt_apply (i : ι) (f : ∀ i, F' i) : DifferentiableAt (𝕜 := 𝕜) (fun f : ∀ i, F' i => f i) f := by have h := ((differentiableAt_pi (𝕜 := 𝕜) (Ί := fun (f : ∀ i, F' i) (i' : ι) => f i') (x := f))).1 apply h; apply differentiableAt_id theorem differentiableOn_pi : DifferentiableOn 𝕜 Ί s ↔ ∀ i, DifferentiableOn 𝕜 (fun x => Ί x i) s := ⟹fun h i x hx => differentiableWithinAt_pi.1 (h x hx) i, fun h x hx => differentiableWithinAt_pi.2 fun i => h i x hx⟩ @[fun_prop] theorem differentiableOn_pi'' (hφ : ∀ i, DifferentiableOn 𝕜 (fun x => Ί x i) s) : DifferentiableOn 𝕜 Ί s := differentiableOn_pi.2 hφ @[fun_prop] theorem differentiableOn_apply (i : ι) (s' : Set (∀ i, F' i)) : DifferentiableOn (𝕜 := 𝕜) (fun f : ∀ i, F' i => f i) s' := by have h := ((differentiableOn_pi (𝕜 := 𝕜) (Ί := fun (f : ∀ i, F' i) (i' : ι) => f i') (s := s'))).1 apply h; apply differentiableOn_id theorem differentiable_pi : Differentiable 𝕜 Ί ↔ ∀ i, Differentiable 𝕜 fun x => Ί x i := ⟹fun h i x => differentiableAt_pi.1 (h x) i, fun h x => differentiableAt_pi.2 fun i => h i x⟩ @[fun_prop] theorem differentiable_pi'' (hφ : ∀ i, Differentiable 𝕜 fun x => Ί x i) : Differentiable 𝕜 Ί := differentiable_pi.2 hφ @[fun_prop] theorem differentiable_apply (i : ι) : Differentiable (𝕜 := 𝕜) (fun f : ∀ i, F' i => f i) := by intro x; apply differentiableAt_apply -- TODO: find out which version (`φ` or `Ί`) works better with `rw`/`simp` theorem fderivWithin_pi (h : ∀ i, DifferentiableWithinAt 𝕜 (φ i) s x) (hs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x i => φ i x) s x = pi fun i => fderivWithin 𝕜 (φ i) s x := (hasFDerivWithinAt_pi.2 fun i => (h i).hasFDerivWithinAt).fderivWithin hs theorem fderiv_pi (h : ∀ i, DifferentiableAt 𝕜 (φ i) x) : fderiv 𝕜 (fun x i => φ i x) x = pi fun i => fderiv 𝕜 (φ i) x := (hasFDerivAt_pi.2 fun i => (h i).hasFDerivAt).fderiv end Pi end CartesianProduct end
Analysis\Calculus\FDeriv\RestrictScalars.lean
/- 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 Mathlib.Analysis.Calculus.FDeriv.Basic /-! # The derivative of the scalar restriction of a linear map For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of the scalar restriction of a linear map. -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section RestrictScalars /-! ### 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 `𝕜`. -/ variable (𝕜 : Type*) [NontriviallyNormedField 𝕜] variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedSpace 𝕜' E] variable [IsScalarTower 𝕜 𝕜' E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedSpace 𝕜' F] variable [IsScalarTower 𝕜 𝕜' F] variable {f : E → F} {f' : E →L[𝕜'] F} {s : Set E} {x : E} @[fun_prop] theorem HasStrictFDerivAt.restrictScalars (h : HasStrictFDerivAt f f' x) : HasStrictFDerivAt f (f'.restrictScalars 𝕜) x := h theorem HasFDerivAtFilter.restrictScalars {L} (h : HasFDerivAtFilter f f' x L) : HasFDerivAtFilter f (f'.restrictScalars 𝕜) x L := .of_isLittleO h.1 @[fun_prop] theorem HasFDerivAt.restrictScalars (h : HasFDerivAt f f' x) : HasFDerivAt f (f'.restrictScalars 𝕜) x := .of_isLittleO h.1 @[fun_prop] theorem HasFDerivWithinAt.restrictScalars (h : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt f (f'.restrictScalars 𝕜) s x := .of_isLittleO h.1 @[fun_prop] theorem DifferentiableAt.restrictScalars (h : DifferentiableAt 𝕜' f x) : DifferentiableAt 𝕜 f x := (h.hasFDerivAt.restrictScalars 𝕜).differentiableAt @[fun_prop] theorem DifferentiableWithinAt.restrictScalars (h : DifferentiableWithinAt 𝕜' f s x) : DifferentiableWithinAt 𝕜 f s x := (h.hasFDerivWithinAt.restrictScalars 𝕜).differentiableWithinAt @[fun_prop] theorem DifferentiableOn.restrictScalars (h : DifferentiableOn 𝕜' f s) : DifferentiableOn 𝕜 f s := fun x hx => (h x hx).restrictScalars 𝕜 @[fun_prop] theorem Differentiable.restrictScalars (h : Differentiable 𝕜' f) : Differentiable 𝕜 f := fun x => (h x).restrictScalars 𝕜 @[fun_prop] theorem HasFDerivWithinAt.of_restrictScalars {g' : E →L[𝕜] F} (h : HasFDerivWithinAt f g' s x) (H : f'.restrictScalars 𝕜 = g') : HasFDerivWithinAt f f' s x := by rw [← H] at h exact .of_isLittleO h.1 @[fun_prop] theorem hasFDerivAt_of_restrictScalars {g' : E →L[𝕜] F} (h : HasFDerivAt f g' x) (H : f'.restrictScalars 𝕜 = g') : HasFDerivAt f f' x := by rw [← H] at h exact .of_isLittleO h.1 theorem DifferentiableAt.fderiv_restrictScalars (h : DifferentiableAt 𝕜' f x) : fderiv 𝕜 f x = (fderiv 𝕜' f x).restrictScalars 𝕜 := (h.hasFDerivAt.restrictScalars 𝕜).fderiv theorem differentiableWithinAt_iff_restrictScalars (hf : DifferentiableWithinAt 𝕜 f s x) (hs : UniqueDiffWithinAt 𝕜 s x) : DifferentiableWithinAt 𝕜' f s x ↔ ∃ g' : E →L[𝕜'] F, g'.restrictScalars 𝕜 = fderivWithin 𝕜 f s x := by constructor · rintro ⟹g', hg'⟩ exact ⟹g', hs.eq (hg'.restrictScalars 𝕜) hf.hasFDerivWithinAt⟩ · rintro ⟹f', hf'⟩ exact ⟹f', hf.hasFDerivWithinAt.of_restrictScalars 𝕜 hf'⟩ theorem differentiableAt_iff_restrictScalars (hf : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜' f x ↔ ∃ g' : E →L[𝕜'] F, g'.restrictScalars 𝕜 = fderiv 𝕜 f x := by rw [← differentiableWithinAt_univ, ← fderivWithin_univ] exact differentiableWithinAt_iff_restrictScalars 𝕜 hf.differentiableWithinAt uniqueDiffWithinAt_univ end RestrictScalars
Analysis\Calculus\FDeriv\Star.lean
/- Copyright (c) 2023 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Analysis.Calculus.FDeriv.Linear import Mathlib.Analysis.Calculus.FDeriv.Comp import Mathlib.Analysis.Calculus.FDeriv.Equiv import Mathlib.Topology.Algebra.Module.Star /-! # Star operations on derivatives For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of the star operation. Note that these only apply when the field that the derivative is respect to has a trivial star operation; which as should be expected rules out `𝕜 = ℂ`. -/ open scoped Classical variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] [StarRing 𝕜] [TrivialStar 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [StarAddMonoid F] [NormedSpace 𝕜 F] [StarModule 𝕜 F] [ContinuousStar F] variable {f : E → F} {f' : E →L[𝕜] F} (e : E →L[𝕜] F) {x : E} {s : Set E} {L : Filter E} @[fun_prop] theorem HasStrictFDerivAt.star (h : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => star (f x)) (((starL' 𝕜 : F ≃L[𝕜] F) : F →L[𝕜] F) ∘L f') x := (starL' 𝕜 : F ≃L[𝕜] F).toContinuousLinearMap.hasStrictFDerivAt.comp x h theorem HasFDerivAtFilter.star (h : HasFDerivAtFilter f f' x L) : HasFDerivAtFilter (fun x => star (f x)) (((starL' 𝕜 : F ≃L[𝕜] F) : F →L[𝕜] F) ∘L f') x L := (starL' 𝕜 : F ≃L[𝕜] F).toContinuousLinearMap.hasFDerivAtFilter.comp x h Filter.tendsto_map @[fun_prop] nonrec theorem HasFDerivWithinAt.star (h : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => star (f x)) (((starL' 𝕜 : F ≃L[𝕜] F) : F →L[𝕜] F) ∘L f') s x := h.star @[fun_prop] nonrec theorem HasFDerivAt.star (h : HasFDerivAt f f' x) : HasFDerivAt (fun x => star (f x)) (((starL' 𝕜 : F ≃L[𝕜] F) : F →L[𝕜] F) ∘L f') x := h.star @[fun_prop] theorem DifferentiableWithinAt.star (h : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (fun y => star (f y)) s x := h.hasFDerivWithinAt.star.differentiableWithinAt @[simp] theorem differentiableWithinAt_star_iff : DifferentiableWithinAt 𝕜 (fun y => star (f y)) s x ↔ DifferentiableWithinAt 𝕜 f s x := (starL' 𝕜 : F ≃L[𝕜] F).comp_differentiableWithinAt_iff @[fun_prop] theorem DifferentiableAt.star (h : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => star (f y)) x := h.hasFDerivAt.star.differentiableAt @[simp] theorem differentiableAt_star_iff : DifferentiableAt 𝕜 (fun y => star (f y)) x ↔ DifferentiableAt 𝕜 f x := (starL' 𝕜 : F ≃L[𝕜] F).comp_differentiableAt_iff @[fun_prop] theorem DifferentiableOn.star (h : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => star (f y)) s := fun x hx => (h x hx).star @[simp] theorem differentiableOn_star_iff : DifferentiableOn 𝕜 (fun y => star (f y)) s ↔ DifferentiableOn 𝕜 f s := (starL' 𝕜 : F ≃L[𝕜] F).comp_differentiableOn_iff @[fun_prop] theorem Differentiable.star (h : Differentiable 𝕜 f) : Differentiable 𝕜 fun y => star (f y) := fun x => (h x).star @[simp] theorem differentiable_star_iff : (Differentiable 𝕜 fun y => star (f y)) ↔ Differentiable 𝕜 f := (starL' 𝕜 : F ≃L[𝕜] F).comp_differentiable_iff theorem fderivWithin_star (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun y => star (f y)) s x = ((starL' 𝕜 : F ≃L[𝕜] F) : F →L[𝕜] F) ∘L fderivWithin 𝕜 f s x := (starL' 𝕜 : F ≃L[𝕜] F).comp_fderivWithin hxs @[simp] theorem fderiv_star : fderiv 𝕜 (fun y => star (f y)) x = ((starL' 𝕜 : F ≃L[𝕜] F) : F →L[𝕜] F) ∘L fderiv 𝕜 f x := (starL' 𝕜 : F ≃L[𝕜] F).comp_fderiv
Analysis\Calculus\FDeriv\Symmetric.lean
/- Copyright (c) 2021 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.MeanValue /-! # Symmetry of the second derivative We show that, over the reals, the second derivative is symmetric. The most precise result is `Convex.second_derivative_within_at_symmetric`. It asserts that, if a function is differentiable inside a convex set `s` with nonempty interior, and has a second derivative within `s` at a point `x`, then this second derivative at `x` is symmetric. Note that this result does not require continuity of the first derivative. The following particular cases of this statement are especially relevant: `second_derivative_symmetric_of_eventually` asserts that, if a function is differentiable on a neighborhood of `x`, and has a second derivative at `x`, then this second derivative is symmetric. `second_derivative_symmetric` asserts that, if a function is differentiable, and has a second derivative at `x`, then this second derivative is symmetric. ## Implementation note For the proof, we obtain an asymptotic expansion to order two of `f (x + v + w) - f (x + v)`, by using the mean value inequality applied to a suitable function along the segment `[x + v, x + v + w]`. This expansion involves `f'' ⬝ w` as we move along a segment directed by `w` (see `Convex.taylor_approx_two_segment`). Consider the alternate sum `f (x + v + w) + f x - f (x + v) - f (x + w)`, corresponding to the values of `f` along a rectangle based at `x` with sides `v` and `w`. One can write it using the two sides directed by `w`, as `(f (x + v + w) - f (x + v)) - (f (x + w) - f x)`. Together with the previous asymptotic expansion, one deduces that it equals `f'' v w + o(1)` when `v, w` tends to `0`. Exchanging the roles of `v` and `w`, one instead gets an asymptotic expansion `f'' w v`, from which the equality `f'' v w = f'' w v` follows. In our most general statement, we only assume that `f` is differentiable inside a convex set `s`, so a few modifications have to be made. Since we don't assume continuity of `f` at `x`, we consider instead the rectangle based at `x + v + w` with sides `v` and `w`, in `Convex.isLittleO_alternate_sum_square`, but the argument is essentially the same. It only works when `v` and `w` both point towards the interior of `s`, to make sure that all the sides of the rectangle are contained in `s` by convexity. The general case follows by linearity, though. -/ open Asymptotics Set open scoped Topology variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {s : Set E} (s_conv : Convex ℝ s) {f : E → F} {f' : E → E →L[ℝ] F} {f'' : E →L[ℝ] E →L[ℝ] F} (hf : ∀ x ∈ interior s, HasFDerivAt f (f' x) x) {x : E} (xs : x ∈ s) (hx : HasFDerivWithinAt f' f'' (interior s) x) /-- Assume that `f` is differentiable inside a convex set `s`, and that its derivative `f'` is differentiable at a point `x`. Then, given two vectors `v` and `w` pointing inside `s`, one can Taylor-expand to order two the function `f` on the segment `[x + h v, x + h (v + w)]`, giving a bilinear estimate for `f (x + hv + hw) - f (x + hv)` in terms of `f' w` and of `f'' ⬝ w`, up to `o(h^2)`. This is a technical statement used to show that the second derivative is symmetric. -/ theorem Convex.taylor_approx_two_segment {v w : E} (hv : x + v ∈ interior s) (hw : x + v + w ∈ interior s) : (fun h : ℝ => f (x + h • v + h • w) - f (x + h • v) - h • f' x w - h ^ 2 • f'' v w - (h ^ 2 / 2) • f'' w w) =o[𝓝[>] 0] fun h => h ^ 2 := by -- it suffices to check that the expression is bounded by `ε * ((‖v‖ + ‖w‖) * ‖w‖) * h^2` for -- small enough `h`, for any positive `ε`. refine IsLittleO.trans_isBigO (isLittleO_iff.2 fun ε εpos => ?_) (isBigO_const_mul_self ((‖v‖ + ‖w‖) * ‖w‖) _ _) -- consider a ball of radius `ÎŽ` around `x` in which the Taylor approximation for `f''` is -- good up to `ÎŽ`. rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO, isLittleO_iff] at hx rcases Metric.mem_nhdsWithin_iff.1 (hx εpos) with ⟹ή, ÎŽpos, sΎ⟩ have E1 : ∀ᶠ h in 𝓝[>] (0 : ℝ), h * (‖v‖ + ‖w‖) < ÎŽ := by have : Filter.Tendsto (fun h => h * (‖v‖ + ‖w‖)) (𝓝[>] (0 : ℝ)) (𝓝 (0 * (‖v‖ + ‖w‖))) := (continuous_id.mul continuous_const).continuousWithinAt apply (tendsto_order.1 this).2 ÎŽ simpa only [zero_mul] using ÎŽpos have E2 : ∀ᶠ h in 𝓝[>] (0 : ℝ), (h : ℝ) < 1 := mem_nhdsWithin_Ioi_iff_exists_Ioo_subset.2 ⟹(1 : ℝ), by simp only [mem_Ioi, zero_lt_one], fun x hx => hx.2⟩ filter_upwards [E1, E2, self_mem_nhdsWithin] with h hÎŽ h_lt_1 hpos -- we consider `h` small enough that all points under consideration belong to this ball, -- and also with `0 < h < 1`. replace hpos : 0 < h := hpos have xt_mem : ∀ t ∈ Icc (0 : ℝ) 1, x + h • v + (t * h) • w ∈ interior s := by intro t ht have : x + h • v ∈ interior s := s_conv.add_smul_mem_interior xs hv ⟹hpos, h_lt_1.le⟩ rw [← smul_smul] apply s_conv.interior.add_smul_mem this _ ht rw [add_assoc] at hw rw [add_assoc, ← smul_add] exact s_conv.add_smul_mem_interior xs hw ⟹hpos, h_lt_1.le⟩ -- define a function `g` on `[0,1]` (identified with `[v, v + w]`) such that `g 1 - g 0` is the -- quantity to be estimated. We will check that its derivative is given by an explicit -- expression `g'`, that we can bound. Then the desired bound for `g 1 - g 0` follows from the -- mean value inequality. let g t := f (x + h • v + (t * h) • w) - (t * h) • f' x w - (t * h ^ 2) • f'' v w - ((t * h) ^ 2 / 2) • f'' w w set g' := fun t => f' (x + h • v + (t * h) • w) (h • w) - h • f' x w - h ^ 2 • f'' v w - (t * h ^ 2) • f'' w w with hg' -- check that `g'` is the derivative of `g`, by a straightforward computation have g_deriv : ∀ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt g (g' t) (Icc 0 1) t := by intro t ht apply_rules [HasDerivWithinAt.sub, HasDerivWithinAt.add] · refine (hf _ ?_).comp_hasDerivWithinAt _ ?_ · exact xt_mem t ht apply_rules [HasDerivAt.hasDerivWithinAt, HasDerivAt.const_add, HasDerivAt.smul_const, hasDerivAt_mul_const] · apply_rules [HasDerivAt.hasDerivWithinAt, HasDerivAt.smul_const, hasDerivAt_mul_const] · apply_rules [HasDerivAt.hasDerivWithinAt, HasDerivAt.smul_const, hasDerivAt_mul_const] · suffices H : HasDerivWithinAt (fun u => ((u * h) ^ 2 / 2) • f'' w w) ((((2 : ℕ) : ℝ) * (t * h) ^ (2 - 1) * (1 * h) / 2) • f'' w w) (Icc 0 1) t by convert H using 2 ring apply_rules [HasDerivAt.hasDerivWithinAt, HasDerivAt.smul_const, hasDerivAt_id', HasDerivAt.pow, HasDerivAt.mul_const] -- check that `g'` is uniformly bounded, with a suitable bound `ε * ((‖v‖ + ‖w‖) * ‖w‖) * h^2`. have g'_bound : ∀ t ∈ Ico (0 : ℝ) 1, ‖g' t‖ ≀ ε * ((‖v‖ + ‖w‖) * ‖w‖) * h ^ 2 := by intro t ht have I : ‖h • v + (t * h) • w‖ ≀ h * (‖v‖ + ‖w‖) := calc ‖h • v + (t * h) • w‖ ≀ ‖h • v‖ + ‖(t * h) • w‖ := norm_add_le _ _ _ = h * ‖v‖ + t * (h * ‖w‖) := by simp only [norm_smul, Real.norm_eq_abs, hpos.le, abs_of_nonneg, abs_mul, ht.left, mul_assoc] _ ≀ h * ‖v‖ + 1 * (h * ‖w‖) := by gcongr; exact ht.2.le _ = h * (‖v‖ + ‖w‖) := by ring calc ‖g' t‖ = ‖(f' (x + h • v + (t * h) • w) - f' x - f'' (h • v + (t * h) • w)) (h • w)‖ := by rw [hg'] have : h * (t * h) = t * (h * h) := by ring simp only [ContinuousLinearMap.coe_sub', ContinuousLinearMap.map_add, pow_two, ContinuousLinearMap.add_apply, Pi.smul_apply, smul_sub, smul_add, smul_smul, ← sub_sub, ContinuousLinearMap.coe_smul', Pi.sub_apply, ContinuousLinearMap.map_smul, this] _ ≀ ‖f' (x + h • v + (t * h) • w) - f' x - f'' (h • v + (t * h) • w)‖ * ‖h • w‖ := (ContinuousLinearMap.le_opNorm _ _) _ ≀ ε * ‖h • v + (t * h) • w‖ * ‖h • w‖ := by apply mul_le_mul_of_nonneg_right _ (norm_nonneg _) have H : x + h • v + (t * h) • w ∈ Metric.ball x ÎŽ ∩ interior s := by refine ⟹?_, xt_mem t ⟹ht.1, ht.2.le⟩⟩ rw [add_assoc, add_mem_ball_iff_norm] exact I.trans_lt hÎŽ simpa only [mem_setOf_eq, add_assoc x, add_sub_cancel_left] using sÎŽ H _ ≀ ε * (‖h • v‖ + ‖h • w‖) * ‖h • w‖ := by gcongr apply (norm_add_le _ _).trans gcongr simp only [norm_smul, Real.norm_eq_abs, abs_mul, abs_of_nonneg, ht.1, hpos.le, mul_assoc] exact mul_le_of_le_one_left (mul_nonneg hpos.le (norm_nonneg _)) ht.2.le _ = ε * ((‖v‖ + ‖w‖) * ‖w‖) * h ^ 2 := by simp only [norm_smul, Real.norm_eq_abs, abs_mul, abs_of_nonneg, hpos.le]; ring -- conclude using the mean value inequality have I : ‖g 1 - g 0‖ ≀ ε * ((‖v‖ + ‖w‖) * ‖w‖) * h ^ 2 := by simpa only [mul_one, sub_zero] using norm_image_sub_le_of_norm_deriv_le_segment' g_deriv g'_bound 1 (right_mem_Icc.2 zero_le_one) convert I using 1 · congr 1 simp only [g, Nat.one_ne_zero, add_zero, one_mul, zero_div, zero_mul, sub_zero, zero_smul, Ne, not_false_iff, zero_pow] abel · simp only [Real.norm_eq_abs, abs_mul, add_nonneg (norm_nonneg v) (norm_nonneg w), abs_of_nonneg, hpos.le, mul_assoc, norm_nonneg, abs_pow] /-- One can get `f'' v w` as the limit of `h ^ (-2)` times the alternate sum of the values of `f` along the vertices of a quadrilateral with sides `h v` and `h w` based at `x`. In a setting where `f` is not guaranteed to be continuous at `f`, we can still get this if we use a quadrilateral based at `h v + h w`. -/ theorem Convex.isLittleO_alternate_sum_square {v w : E} (h4v : x + (4 : ℝ) • v ∈ interior s) (h4w : x + (4 : ℝ) • w ∈ interior s) : (fun h : ℝ => f (x + h • (2 • v + 2 • w)) + f (x + h • (v + w)) - f (x + h • (2 • v + w)) - f (x + h • (v + 2 • w)) - h ^ 2 • f'' v w) =o[𝓝[>] 0] fun h => h ^ 2 := by have A : (1 : ℝ) / 2 ∈ Ioc (0 : ℝ) 1 := ⟹by norm_num, by norm_num⟩ have B : (1 : ℝ) / 2 ∈ Icc (0 : ℝ) 1 := ⟹by norm_num, by norm_num⟩ have C : ∀ w : E, (2 : ℝ) • w = 2 • w := fun w => by simp only [two_smul] have h2v2w : x + (2 : ℝ) • v + (2 : ℝ) • w ∈ interior s := by convert s_conv.interior.add_smul_sub_mem h4v h4w B using 1 simp only [smul_sub, smul_smul, one_div, add_sub_add_left_eq_sub, mul_add, add_smul] norm_num simp only [show (4 : ℝ) = (2 : ℝ) + (2 : ℝ) by norm_num, _root_.add_smul] abel have h2vww : x + (2 • v + w) + w ∈ interior s := by convert h2v2w using 1 simp only [two_smul] abel have h2v : x + (2 : ℝ) • v ∈ interior s := by convert s_conv.add_smul_sub_mem_interior xs h4v A using 1 simp only [smul_smul, one_div, add_sub_cancel_left, add_right_inj] norm_num have h2w : x + (2 : ℝ) • w ∈ interior s := by convert s_conv.add_smul_sub_mem_interior xs h4w A using 1 simp only [smul_smul, one_div, add_sub_cancel_left, add_right_inj] norm_num have hvw : x + (v + w) ∈ interior s := by convert s_conv.add_smul_sub_mem_interior xs h2v2w A using 1 simp only [smul_smul, one_div, add_sub_cancel_left, add_right_inj, smul_add, smul_sub] norm_num abel have h2vw : x + (2 • v + w) ∈ interior s := by convert s_conv.interior.add_smul_sub_mem h2v h2v2w B using 1 simp only [smul_add, smul_sub, smul_smul, ← C] norm_num abel have hvww : x + (v + w) + w ∈ interior s := by convert s_conv.interior.add_smul_sub_mem h2w h2v2w B using 1 rw [one_div, add_sub_add_right_eq_sub, add_sub_cancel_left, inv_smul_smul₀ two_ne_zero, two_smul] abel have TA1 := s_conv.taylor_approx_two_segment hf xs hx h2vw h2vww have TA2 := s_conv.taylor_approx_two_segment hf xs hx hvw hvww convert TA1.sub TA2 using 1 ext h simp only [two_smul, smul_add, ← add_assoc, ContinuousLinearMap.map_add, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul', ContinuousLinearMap.map_smul] abel /-- Assume that `f` is differentiable inside a convex set `s`, and that its derivative `f'` is differentiable at a point `x`. Then, given two vectors `v` and `w` pointing inside `s`, one has `f'' v w = f'' w v`. Superseded by `Convex.second_derivative_within_at_symmetric`, which removes the assumption that `v` and `w` point inside `s`. -/ theorem Convex.second_derivative_within_at_symmetric_of_mem_interior {v w : E} (h4v : x + (4 : ℝ) • v ∈ interior s) (h4w : x + (4 : ℝ) • w ∈ interior s) : f'' w v = f'' v w := by have A : (fun h : ℝ => h ^ 2 • (f'' w v - f'' v w)) =o[𝓝[>] 0] fun h => h ^ 2 := by convert (s_conv.isLittleO_alternate_sum_square hf xs hx h4v h4w).sub (s_conv.isLittleO_alternate_sum_square hf xs hx h4w h4v) using 1 ext h simp only [add_comm, smul_add, smul_sub] abel have B : (fun _ : ℝ => f'' w v - f'' v w) =o[𝓝[>] 0] fun _ => (1 : ℝ) := by have : (fun h : ℝ => 1 / h ^ 2) =O[𝓝[>] 0] fun h => 1 / h ^ 2 := isBigO_refl _ _ have C := this.smul_isLittleO A apply C.congr' _ _ · filter_upwards [self_mem_nhdsWithin] intro h (hpos : 0 < h) rw [← one_smul ℝ (f'' w v - f'' v w), smul_smul, smul_smul] congr 1 field_simp [LT.lt.ne' hpos] · filter_upwards [self_mem_nhdsWithin] with h (hpos : 0 < h) field_simp [LT.lt.ne' hpos, SMul.smul] simpa only [sub_eq_zero] using isLittleO_const_const_iff.1 B /-- If a function is differentiable inside a convex set with nonempty interior, and has a second derivative at a point of this convex set, then this second derivative is symmetric. -/ theorem Convex.second_derivative_within_at_symmetric {s : Set E} (s_conv : Convex ℝ s) (hne : (interior s).Nonempty) {f : E → F} {f' : E → E →L[ℝ] F} {f'' : E →L[ℝ] E →L[ℝ] F} (hf : ∀ x ∈ interior s, HasFDerivAt f (f' x) x) {x : E} (xs : x ∈ s) (hx : HasFDerivWithinAt f' f'' (interior s) x) (v w : E) : f'' v w = f'' w v := by /- we work around a point `x + 4 z` in the interior of `s`. For any vector `m`, then `x + 4 (z + t m)` also belongs to the interior of `s` for small enough `t`. This means that we will be able to apply `second_derivative_within_at_symmetric_of_mem_interior` to show that `f''` is symmetric, after cancelling all the contributions due to `z`. -/ rcases hne with ⟹y, hy⟩ obtain ⟹z, hz⟩ : ∃ z, z = ((1 : ℝ) / 4) • (y - x) := ⟹((1 : ℝ) / 4) • (y - x), rfl⟩ have A : ∀ m : E, Filter.Tendsto (fun t : ℝ => x + (4 : ℝ) • (z + t • m)) (𝓝 0) (𝓝 y) := by intro m have : x + (4 : ℝ) • (z + (0 : ℝ) • m) = y := by simp [hz] rw [← this] refine tendsto_const_nhds.add <| tendsto_const_nhds.smul <| tendsto_const_nhds.add ?_ exact continuousAt_id.smul continuousAt_const have B : ∀ m : E, ∀ᶠ t in 𝓝[>] (0 : ℝ), x + (4 : ℝ) • (z + t • m) ∈ interior s := by intro m apply nhdsWithin_le_nhds apply A m rw [mem_interior_iff_mem_nhds] at hy exact interior_mem_nhds.2 hy -- we choose `t m > 0` such that `x + 4 (z + (t m) m)` belongs to the interior of `s`, for any -- vector `m`. choose t ts tpos using fun m => ((B m).and self_mem_nhdsWithin).exists -- applying `second_derivative_within_at_symmetric_of_mem_interior` to the vectors `z` -- and `z + (t m) m`, we deduce that `f'' m z = f'' z m` for all `m`. have C : ∀ m : E, f'' m z = f'' z m := by intro m have : f'' (z + t m • m) (z + t 0 • (0 : E)) = f'' (z + t 0 • (0 : E)) (z + t m • m) := s_conv.second_derivative_within_at_symmetric_of_mem_interior hf xs hx (ts 0) (ts m) simp only [ContinuousLinearMap.map_add, ContinuousLinearMap.map_smul, add_right_inj, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul', add_zero, ContinuousLinearMap.zero_apply, smul_zero, ContinuousLinearMap.map_zero] at this exact smul_right_injective F (tpos m).ne' this -- applying `second_derivative_within_at_symmetric_of_mem_interior` to the vectors `z + (t v) v` -- and `z + (t w) w`, we deduce that `f'' v w = f'' w v`. Cross terms involving `z` can be -- eliminated thanks to the fact proved above that `f'' m z = f'' z m`. have : f'' (z + t v • v) (z + t w • w) = f'' (z + t w • w) (z + t v • v) := s_conv.second_derivative_within_at_symmetric_of_mem_interior hf xs hx (ts w) (ts v) simp only [ContinuousLinearMap.map_add, ContinuousLinearMap.map_smul, smul_add, smul_smul, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul', C] at this rw [add_assoc, add_assoc, add_right_inj, add_left_comm, add_right_inj, add_right_inj, mul_comm] at this apply smul_right_injective F _ this simp [(tpos v).ne', (tpos w).ne'] /-- If a function is differentiable around `x`, and has two derivatives at `x`, then the second derivative is symmetric. -/ theorem second_derivative_symmetric_of_eventually {f : E → F} {f' : E → E →L[ℝ] F} {f'' : E →L[ℝ] E →L[ℝ] F} (hf : ∀ᶠ y in 𝓝 x, HasFDerivAt f (f' y) y) (hx : HasFDerivAt f' f'' x) (v w : E) : f'' v w = f'' w v := by rcases Metric.mem_nhds_iff.1 hf with ⟚ε, εpos, hε⟩ have A : (interior (Metric.ball x ε)).Nonempty := by rwa [Metric.isOpen_ball.interior_eq, Metric.nonempty_ball] exact Convex.second_derivative_within_at_symmetric (convex_ball x ε) A (fun y hy => hε (interior_subset hy)) (Metric.mem_ball_self εpos) hx.hasFDerivWithinAt v w /-- If a function is differentiable, and has two derivatives at `x`, then the second derivative is symmetric. -/ theorem second_derivative_symmetric {f : E → F} {f' : E → E →L[ℝ] F} {f'' : E →L[ℝ] E →L[ℝ] F} (hf : ∀ y, HasFDerivAt f (f' y) y) (hx : HasFDerivAt f' f'' x) (v w : E) : f'' v w = f'' w v := second_derivative_symmetric_of_eventually (Filter.eventually_of_forall hf) hx v w
Analysis\Calculus\Gradient\Basic.lean
/- Copyright (c) 2023 Ziyu Wang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ziyu Wang, Chenyi Li, Sébastien Gouëzel, Penghao Yu, Zhipeng Cao -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.Calculus.FDeriv.Basic import Mathlib.Analysis.Calculus.Deriv.Basic /-! # Gradient ## Main Definitions Let `f` be a function from a Hilbert Space `F` to `𝕜` (`𝕜` is `ℝ` or `ℂ`) , `x` be a point in `F` and `f'` be a vector in F. Then `HasGradientWithinAt f f' s x` says that `f` has a gradient `f'` at `x`, where the domain of interest is restricted to `s`. We also have `HasGradientAt f f' x := HasGradientWithinAt f f' x univ` ## Main results This file contains the following parts of gradient. * the definition of gradient. * the theorems translating between `HasGradientAtFilter` and `HasFDerivAtFilter`, `HasGradientWithinAt` and `HasFDerivWithinAt`, `HasGradientAt` and `HasFDerivAt`, `Gradient` and `fderiv`. * theorems the Uniqueness of Gradient. * the theorems translating between `HasGradientAtFilter` and `HasDerivAtFilter`, `HasGradientAt` and `HasDerivAt`, `Gradient` and `deriv` when `F = 𝕜`. * the theorems about the congruence of the gradient. * the theorems about the gradient of constant function. * the theorems about the continuity of a function admitting a gradient. -/ open Topology InnerProductSpace Set noncomputable section variable {𝕜 F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [CompleteSpace F] variable {f : F → 𝕜} {f' x : F} /-- A function `f` has the gradient `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`. -/ def HasGradientAtFilter (f : F → 𝕜) (f' x : F) (L : Filter F) := HasFDerivAtFilter f (toDual 𝕜 F f') x L /-- `f` has the gradient `f'` at the point `x` within the subset `s` if `f x' = f x + ⟹f', x' - x⟩ + o (x' - x)` where `x'` converges to `x` inside `s`. -/ def HasGradientWithinAt (f : F → 𝕜) (f' : F) (s : Set F) (x : F) := HasGradientAtFilter f f' x (𝓝[s] x) /-- `f` has the gradient `f'` at the point `x` if `f x' = f x + ⟹f', x' - x⟩ + o (x' - x)` where `x'` converges to `x`. -/ def HasGradientAt (f : F → 𝕜) (f' x : F) := HasGradientAtFilter f f' x (𝓝 x) /-- Gradient of `f` at the point `x` within the set `s`, if it exists. Zero otherwise. If the derivative exists (i.e., `∃ f', HasGradientWithinAt f f' s x`), then `f x' = f x + ⟹f', x' - x⟩ + o (x' - x)` where `x'` converges to `x` inside `s`. -/ def gradientWithin (f : F → 𝕜) (s : Set F) (x : F) : F := (toDual 𝕜 F).symm (fderivWithin 𝕜 f s x) /-- Gradient of `f` at the point `x`, if it exists. Zero otherwise. If the derivative exists (i.e., `∃ f', HasGradientAt f f' x`), then `f x' = f x + ⟹f', x' - x⟩ + o (x' - x)` where `x'` converges to `x`. -/ def gradient (f : F → 𝕜) (x : F) : F := (toDual 𝕜 F).symm (fderiv 𝕜 f x) @[inherit_doc] scoped[Gradient] notation "∇" => gradient local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y open scoped Gradient variable {s : Set F} {L : Filter F} theorem hasGradientWithinAt_iff_hasFDerivWithinAt {s : Set F} : HasGradientWithinAt f f' s x ↔ HasFDerivWithinAt f (toDual 𝕜 F f') s x := Iff.rfl theorem hasFDerivWithinAt_iff_hasGradientWithinAt {frechet : F →L[𝕜] 𝕜} {s : Set F} : HasFDerivWithinAt f frechet s x ↔ HasGradientWithinAt f ((toDual 𝕜 F).symm frechet) s x := by rw [hasGradientWithinAt_iff_hasFDerivWithinAt, (toDual 𝕜 F).apply_symm_apply frechet] theorem hasGradientAt_iff_hasFDerivAt : HasGradientAt f f' x ↔ HasFDerivAt f (toDual 𝕜 F f') x := Iff.rfl theorem hasFDerivAt_iff_hasGradientAt {frechet : F →L[𝕜] 𝕜} : HasFDerivAt f frechet x ↔ HasGradientAt f ((toDual 𝕜 F).symm frechet) x := by rw [hasGradientAt_iff_hasFDerivAt, (toDual 𝕜 F).apply_symm_apply frechet] alias ⟹HasGradientWithinAt.hasFDerivWithinAt, _⟩ := hasGradientWithinAt_iff_hasFDerivWithinAt alias ⟹HasFDerivWithinAt.hasGradientWithinAt, _⟩ := hasFDerivWithinAt_iff_hasGradientWithinAt alias ⟹HasGradientAt.hasFDerivAt, _⟩ := hasGradientAt_iff_hasFDerivAt alias ⟹HasFDerivAt.hasGradientAt, _⟩ := hasFDerivAt_iff_hasGradientAt theorem gradient_eq_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : ∇ f x = 0 := by rw [gradient, fderiv_zero_of_not_differentiableAt h, map_zero] theorem HasGradientAt.unique {gradf gradg : F} (hf : HasGradientAt f gradf x) (hg : HasGradientAt f gradg x) : gradf = gradg := (toDual 𝕜 F).injective (hf.hasFDerivAt.unique hg.hasFDerivAt) theorem DifferentiableAt.hasGradientAt (h : DifferentiableAt 𝕜 f x) : HasGradientAt f (∇ f x) x := by rw [hasGradientAt_iff_hasFDerivAt, gradient, (toDual 𝕜 F).apply_symm_apply (fderiv 𝕜 f x)] exact h.hasFDerivAt theorem HasGradientAt.differentiableAt (h : HasGradientAt f f' x) : DifferentiableAt 𝕜 f x := h.hasFDerivAt.differentiableAt theorem DifferentiableWithinAt.hasGradientWithinAt (h : DifferentiableWithinAt 𝕜 f s x) : HasGradientWithinAt f (gradientWithin f s x) s x := by rw [hasGradientWithinAt_iff_hasFDerivWithinAt, gradientWithin, (toDual 𝕜 F).apply_symm_apply (fderivWithin 𝕜 f s x)] exact h.hasFDerivWithinAt theorem HasGradientWithinAt.differentiableWithinAt (h : HasGradientWithinAt f f' s x) : DifferentiableWithinAt 𝕜 f s x := h.hasFDerivWithinAt.differentiableWithinAt @[simp] theorem hasGradientWithinAt_univ : HasGradientWithinAt f f' univ x ↔ HasGradientAt f f' x := by rw [hasGradientWithinAt_iff_hasFDerivWithinAt, hasGradientAt_iff_hasFDerivAt] exact hasFDerivWithinAt_univ theorem DifferentiableOn.hasGradientAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : HasGradientAt f (∇ f x) x := (h.hasFDerivAt hs).hasGradientAt theorem HasGradientAt.gradient (h : HasGradientAt f f' x) : ∇ f x = f' := h.differentiableAt.hasGradientAt.unique h theorem gradient_eq {f' : F → F} (h : ∀ x, HasGradientAt f (f' x) x) : ∇ f = f' := funext fun x => (h x).gradient section OneDimension variable {g : 𝕜 → 𝕜} {g' u : 𝕜} {L' : Filter 𝕜} theorem HasGradientAtFilter.hasDerivAtFilter (h : HasGradientAtFilter g g' u L') : HasDerivAtFilter g (starRingEnd 𝕜 g') u L' := by have : ContinuousLinearMap.smulRight (1 : 𝕜 →L[𝕜] 𝕜) (starRingEnd 𝕜 g') = (toDual 𝕜 𝕜) g' := by ext; simp rwa [HasDerivAtFilter, this] theorem HasDerivAtFilter.hasGradientAtFilter (h : HasDerivAtFilter g g' u L') : HasGradientAtFilter g (starRingEnd 𝕜 g') u L' := by have : ContinuousLinearMap.smulRight (1 : 𝕜 →L[𝕜] 𝕜) g' = (toDual 𝕜 𝕜) (starRingEnd 𝕜 g') := by ext; simp rwa [HasGradientAtFilter, ← this] theorem HasGradientAt.hasDerivAt (h : HasGradientAt g g' u) : HasDerivAt g (starRingEnd 𝕜 g') u := by rw [hasGradientAt_iff_hasFDerivAt, hasFDerivAt_iff_hasDerivAt] at h simpa using h theorem HasDerivAt.hasGradientAt (h : HasDerivAt g g' u) : HasGradientAt g (starRingEnd 𝕜 g') u := by rw [hasGradientAt_iff_hasFDerivAt, hasFDerivAt_iff_hasDerivAt] simpa theorem gradient_eq_deriv : ∇ g u = starRingEnd 𝕜 (deriv g u) := by by_cases h : DifferentiableAt 𝕜 g u · rw [h.hasGradientAt.hasDerivAt.deriv, RCLike.conj_conj] · rw [gradient_eq_zero_of_not_differentiableAt h, deriv_zero_of_not_differentiableAt h, map_zero] end OneDimension section OneDimensionReal variable {g : ℝ → ℝ} {g' u : ℝ} {L' : Filter ℝ} theorem HasGradientAtFilter.hasDerivAtFilter' (h : HasGradientAtFilter g g' u L') : HasDerivAtFilter g g' u L' := h.hasDerivAtFilter theorem HasDerivAtFilter.hasGradientAtFilter' (h : HasDerivAtFilter g g' u L') : HasGradientAtFilter g g' u L' := h.hasGradientAtFilter theorem HasGradientAt.hasDerivAt' (h : HasGradientAt g g' u) : HasDerivAt g g' u := h.hasDerivAt theorem HasDerivAt.hasGradientAt' (h : HasDerivAt g g' u) : HasGradientAt g g' u := h.hasGradientAt theorem gradient_eq_deriv' : ∇ g u = deriv g u := gradient_eq_deriv end OneDimensionReal open Filter section GradientProperties theorem hasGradientAtFilter_iff_isLittleO : HasGradientAtFilter f f' x L ↔ (fun x' : F => f x' - f x - ⟪f', x' - x⟫) =o[L] fun x' => x' - x := hasFDerivAtFilter_iff_isLittleO .. theorem hasGradientWithinAt_iff_isLittleO : HasGradientWithinAt f f' s x ↔ (fun x' : F => f x' - f x - ⟪f', x' - x⟫) =o[𝓝[s] x] fun x' => x' - x := hasGradientAtFilter_iff_isLittleO theorem hasGradientWithinAt_iff_tendsto : HasGradientWithinAt f f' s x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - ⟪f', x' - x⟫‖) (𝓝[s] x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem hasGradientAt_iff_isLittleO : HasGradientAt f f' x ↔ (fun x' : F => f x' - f x - ⟪f', x' - x⟫) =o[𝓝 x] fun x' => x' - x := hasGradientAtFilter_iff_isLittleO theorem hasGradientAt_iff_tendsto : HasGradientAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - ⟪f', x' - x⟫‖) (𝓝 x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem HasGradientAtFilter.isBigO_sub (h : HasGradientAtFilter f f' x L) : (fun x' => f x' - f x) =O[L] fun x' => x' - x := HasFDerivAtFilter.isBigO_sub h theorem hasGradientWithinAt_congr_set' {s t : Set F} (y : F) (h : s =á¶ [𝓝[{y}ᶜ] x] t) : HasGradientWithinAt f f' s x ↔ HasGradientWithinAt f f' t x := hasFDerivWithinAt_congr_set' y h theorem hasGradientWithinAt_congr_set {s t : Set F} (h : s =á¶ [𝓝 x] t) : HasGradientWithinAt f f' s x ↔ HasGradientWithinAt f f' t x := hasFDerivWithinAt_congr_set h theorem hasGradientAt_iff_isLittleO_nhds_zero : HasGradientAt f f' x ↔ (fun h => f (x + h) - f x - ⟪f', h⟫) =o[𝓝 0] fun h => h := hasFDerivAt_iff_isLittleO_nhds_zero end GradientProperties section congr /-! ### Congruence properties of the Gradient -/ variable {f₀ f₁ : F → 𝕜} {f₀' f₁' : F} {x₀ x₁ : F} {s₀ s₁ t : Set F} {L₀ L₁ : Filter F} theorem Filter.EventuallyEq.hasGradientAtFilter_iff (h₀ : f₀ =á¶ [L] f₁) (hx : f₀ x = f₁ x) (h₁ : f₀' = f₁') : HasGradientAtFilter f₀ f₀' x L ↔ HasGradientAtFilter f₁ f₁' x L := h₀.hasFDerivAtFilter_iff hx (by simp [h₁]) theorem HasGradientAtFilter.congr_of_eventuallyEq (h : HasGradientAtFilter f f' x L) (hL : f₁ =á¶ [L] f) (hx : f₁ x = f x) : HasGradientAtFilter f₁ f' x L := by rwa [hL.hasGradientAtFilter_iff hx rfl] theorem HasGradientWithinAt.congr_mono (h : HasGradientWithinAt f f' s x) (ht : ∀ x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : HasGradientWithinAt f₁ f' t x := HasFDerivWithinAt.congr_mono h ht hx h₁ theorem HasGradientWithinAt.congr (h : HasGradientWithinAt f f' s x) (hs : ∀ x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : HasGradientWithinAt f₁ f' s x := h.congr_mono hs hx (by tauto) theorem HasGradientWithinAt.congr_of_mem (h : HasGradientWithinAt f f' s x) (hs : ∀ x ∈ s, f₁ x = f x) (hx : x ∈ s) : HasGradientWithinAt f₁ f' s x := h.congr hs (hs _ hx) theorem HasGradientWithinAt.congr_of_eventuallyEq (h : HasGradientWithinAt f f' s x) (h₁ : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) : HasGradientWithinAt f₁ f' s x := HasGradientAtFilter.congr_of_eventuallyEq h h₁ hx theorem HasGradientWithinAt.congr_of_eventuallyEq_of_mem (h : HasGradientWithinAt f f' s x) (h₁ : f₁ =á¶ [𝓝[s] x] f) (hx : x ∈ s) : HasGradientWithinAt f₁ f' s x := h.congr_of_eventuallyEq h₁ (h₁.eq_of_nhdsWithin hx) theorem HasGradientAt.congr_of_eventuallyEq (h : HasGradientAt f f' x) (h₁ : f₁ =á¶ [𝓝 x] f) : HasGradientAt f₁ f' x := HasGradientAtFilter.congr_of_eventuallyEq h h₁ (mem_of_mem_nhds h₁ : _) theorem Filter.EventuallyEq.gradient_eq (hL : f₁ =á¶ [𝓝 x] f) : ∇ f₁ x = ∇ f x := by unfold gradient rwa [Filter.EventuallyEq.fderiv_eq] protected theorem Filter.EventuallyEq.gradient (h : f₁ =á¶ [𝓝 x] f) : ∇ f₁ =á¶ [𝓝 x] ∇ f := h.eventuallyEq_nhds.mono fun _ h => h.gradient_eq end congr /-! ### The Gradient of constant functions -/ section Const variable (c : 𝕜) (s x L) theorem hasGradientAtFilter_const : HasGradientAtFilter (fun _ => c) 0 x L := by rw [HasGradientAtFilter, map_zero]; apply hasFDerivAtFilter_const c x L theorem hasGradientWithinAt_const : HasGradientWithinAt (fun _ => c) 0 s x := hasGradientAtFilter_const _ _ _ theorem hasGradientAt_const : HasGradientAt (fun _ => c) 0 x := hasGradientAtFilter_const _ _ _ theorem gradient_const : ∇ (fun _ => c) x = 0 := by rw [gradient, fderiv_const, Pi.zero_apply, map_zero] @[simp] theorem gradient_const' : (∇ fun _ : 𝕜 => c) = fun _ => 0 := funext fun x => gradient_const x c end Const section Continuous /-! ### Continuity of a function admitting a gradient -/ nonrec theorem HasGradientAtFilter.tendsto_nhds (hL : L ≀ 𝓝 x) (h : HasGradientAtFilter f f' x L) : Tendsto f L (𝓝 (f x)) := h.tendsto_nhds hL theorem HasGradientWithinAt.continuousWithinAt (h : HasGradientWithinAt f f' s x) : ContinuousWithinAt f s x := HasGradientAtFilter.tendsto_nhds inf_le_left h theorem HasGradientAt.continuousAt (h : HasGradientAt f f' x) : ContinuousAt f x := HasGradientAtFilter.tendsto_nhds le_rfl h protected theorem HasGradientAt.continuousOn {f' : F → F} (h : ∀ x ∈ s, HasGradientAt f (f' x) x) : ContinuousOn f s := fun x hx => (h x hx).continuousAt.continuousWithinAt end Continuous
Analysis\Calculus\InverseFunctionTheorem\ApproximatesLinearOn.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel -/ import Mathlib.Analysis.Normed.Operator.Banach import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace import Mathlib.Topology.PartialHomeomorph /-! # Non-linear maps close to affine maps In this file we study a map `f` such that `‖f x - f y - f' (x - y)‖ ≀ c * ‖x - y‖` on an open set `s`, where `f' : E →L[𝕜] F` is a continuous linear map and `c` is suitably small. Maps of this type behave like `f a + f' (x - a)` near each `a ∈ s`. When `f'` is onto, we show that `f` is locally onto. When `f'` is a continuous linear equiv, we show that `f` is a homeomorphism between `s` and `f '' s`. More precisely, we define `ApproximatesLinearOn.toPartialHomeomorph` to be a `PartialHomeomorph` with `toFun = f`, `source = s`, and `target = f '' s`. between `s` and `f '' s`. More precisely, we define `ApproximatesLinearOn.toPartialHomeomorph` to be a `PartialHomeomorph` with `toFun = f`, `source = s`, and `target = f '' s`. Maps of this type naturally appear in the proof of the inverse function theorem (see next section), and `ApproximatesLinearOn.toPartialHomeomorph` will imply that the locally inverse function and `ApproximatesLinearOn.toPartialHomeomorph` will imply that the locally inverse function exists. We define this auxiliary notion to split the proof of the inverse function theorem into small lemmas. This approach makes it possible - to prove a lower estimate on the size of the domain of the inverse function; - to reuse parts of the proofs in the case if a function is not strictly differentiable. E.g., for a function `f : E × F → G` with estimates on `f x y₁ - f x y₂` but not on `f x₁ y - f x₂ y`. ## Notations We introduce some `local notation` to make formulas shorter: * by `N` we denote `‖f'⁻¹‖`; * by `g` we denote the auxiliary contracting map `x ↩ x + f'.symm (y - f x)` used to prove that `{x | f x = y}` is nonempty. -/ open Function Set Filter Metric open scoped Topology NNReal noncomputable section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {ε : ℝ} open Filter Metric Set open ContinuousLinearMap (id) /-- We say that `f` approximates a continuous linear map `f'` on `s` with constant `c`, if `‖f x - f y - f' (x - y)‖ ≀ c * ‖x - y‖` whenever `x, y ∈ s`. This predicate is defined to facilitate the splitting of the inverse function theorem into small lemmas. Some of these lemmas can be useful, e.g., to prove that the inverse function is defined on a specific set. -/ def ApproximatesLinearOn (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (c : ℝ≥0) : Prop := ∀ x ∈ s, ∀ y ∈ s, ‖f x - f y - f' (x - y)‖ ≀ c * ‖x - y‖ @[simp] theorem approximatesLinearOn_empty (f : E → F) (f' : E →L[𝕜] F) (c : ℝ≥0) : ApproximatesLinearOn f f' ∅ c := by simp [ApproximatesLinearOn] namespace ApproximatesLinearOn variable {f : E → F} /-! First we prove some properties of a function that `ApproximatesLinearOn` a (not necessarily invertible) continuous linear map. -/ section variable {f' : E →L[𝕜] F} {s t : Set E} {c c' : ℝ≥0} theorem mono_num (hc : c ≀ c') (hf : ApproximatesLinearOn f f' s c) : ApproximatesLinearOn f f' s c' := fun x hx y hy => le_trans (hf x hx y hy) (mul_le_mul_of_nonneg_right hc <| norm_nonneg _) theorem mono_set (hst : s ⊆ t) (hf : ApproximatesLinearOn f f' t c) : ApproximatesLinearOn f f' s c := fun x hx y hy => hf x (hst hx) y (hst hy) theorem approximatesLinearOn_iff_lipschitzOnWith {f : E → F} {f' : E →L[𝕜] F} {s : Set E} {c : ℝ≥0} : ApproximatesLinearOn f f' s c ↔ LipschitzOnWith c (f - ⇑f') s := by have : ∀ x y, f x - f y - f' (x - y) = (f - f') x - (f - f') y := fun x y ↩ by simp only [map_sub, Pi.sub_apply]; abel simp only [this, lipschitzOnWith_iff_norm_sub_le, ApproximatesLinearOn] alias ⟹lipschitzOnWith, _root_.LipschitzOnWith.approximatesLinearOn⟩ := approximatesLinearOn_iff_lipschitzOnWith theorem lipschitz_sub (hf : ApproximatesLinearOn f f' s c) : LipschitzWith c fun x : s => f x - f' x := hf.lipschitzOnWith.to_restrict protected theorem lipschitz (hf : ApproximatesLinearOn f f' s c) : LipschitzWith (‖f'‖₊ + c) (s.restrict f) := by simpa only [restrict_apply, add_sub_cancel] using (f'.lipschitz.restrict s).add hf.lipschitz_sub protected theorem continuous (hf : ApproximatesLinearOn f f' s c) : Continuous (s.restrict f) := hf.lipschitz.continuous protected theorem continuousOn (hf : ApproximatesLinearOn f f' s c) : ContinuousOn f s := continuousOn_iff_continuous_restrict.2 hf.continuous end section LocallyOnto /-! We prove that a function which is linearly approximated by a continuous linear map with a nonlinear right inverse is locally onto. This will apply to the case where the approximating map is a linear equivalence, for the local inverse theorem, but also whenever the approximating map is onto, by Banach's open mapping theorem. -/ variable [CompleteSpace E] {s : Set E} {c : ℝ≥0} {f' : E →L[𝕜] F} /-- If a function is linearly approximated by a continuous linear map with a (possibly nonlinear) right inverse, then it is locally onto: a ball of an explicit radius is included in the image of the map. -/ theorem surjOn_closedBall_of_nonlinearRightInverse (hf : ApproximatesLinearOn f f' s c) (f'symm : f'.NonlinearRightInverse) {ε : ℝ} {b : E} (ε0 : 0 ≀ ε) (hε : closedBall b ε ⊆ s) : SurjOn f (closedBall b ε) (closedBall (f b) (((f'symm.nnnorm : ℝ)⁻¹ - c) * ε)) := by intro y hy rcases le_or_lt (f'symm.nnnorm : ℝ)⁻¹ c with hc | hc · refine ⟹b, by simp [ε0], ?_⟩ have : dist y (f b) ≀ 0 := (mem_closedBall.1 hy).trans (mul_nonpos_of_nonpos_of_nonneg (by linarith) ε0) simp only [dist_le_zero] at this rw [this] have If' : (0 : ℝ) < f'symm.nnnorm := by rw [← inv_pos]; exact (NNReal.coe_nonneg _).trans_lt hc have Icf' : (c : ℝ) * f'symm.nnnorm < 1 := by rwa [inv_eq_one_div, lt_div_iff If'] at hc have Jf' : (f'symm.nnnorm : ℝ) ≠ 0 := ne_of_gt If' have Jcf' : (1 : ℝ) - c * f'symm.nnnorm ≠ 0 := by apply ne_of_gt; linarith /- We have to show that `y` can be written as `f x` for some `x ∈ closedBall b ε`. The idea of the proof is to apply the Banach contraction principle to the map `g : x ↩ x + f'symm (y - f x)`, as a fixed point of this map satisfies `f x = y`. When `f'symm` is a genuine linear inverse, `g` is a contracting map. In our case, since `f'symm` is nonlinear, this map is not contracting (it is not even continuous), but still the proof of the contraction theorem holds: `uₙ = gⁿ b` is a Cauchy sequence, converging exponentially fast to the desired point `x`. Instead of appealing to general results, we check this by hand. The main point is that `f (u n)` becomes exponentially close to `y`, and therefore `dist (u (n+1)) (u n)` becomes exponentally small, making it possible to get an inductive bound on `dist (u n) b`, from which one checks that `u n` stays in the ball on which one has a control. Therefore, the bound can be checked at the next step, and so on inductively. -/ set g := fun x => x + f'symm (y - f x) with hg set u := fun n : ℕ => g^[n] b with hu have usucc : ∀ n, u (n + 1) = g (u n) := by simp [hu, ← iterate_succ_apply' g _ b] -- First bound: if `f z` is close to `y`, then `g z` is close to `z` (i.e., almost a fixed point). have A : ∀ z, dist (g z) z ≀ f'symm.nnnorm * dist (f z) y := by intro z rw [dist_eq_norm, hg, add_sub_cancel_left, dist_eq_norm'] exact f'symm.bound _ -- Second bound: if `z` and `g z` are in the set with good control, then `f (g z)` becomes closer -- to `y` than `f z` was (this uses the linear approximation property, and is the reason for the -- choice of the formula for `g`). have B : ∀ z ∈ closedBall b ε, g z ∈ closedBall b ε → dist (f (g z)) y ≀ c * f'symm.nnnorm * dist (f z) y := by intro z hz hgz set v := f'symm (y - f z) calc dist (f (g z)) y = ‖f (z + v) - y‖ := by rw [dist_eq_norm] _ = ‖f (z + v) - f z - f' v + f' v - (y - f z)‖ := by congr 1; abel _ = ‖f (z + v) - f z - f' (z + v - z)‖ := by simp only [v, ContinuousLinearMap.NonlinearRightInverse.right_inv, add_sub_cancel_left, sub_add_cancel] _ ≀ c * ‖z + v - z‖ := hf _ (hε hgz) _ (hε hz) _ ≀ c * (f'symm.nnnorm * dist (f z) y) := by gcongr simpa [dist_eq_norm'] using f'symm.bound (y - f z) _ = c * f'symm.nnnorm * dist (f z) y := by ring -- Third bound: a complicated bound on `dist w b` (that will show up in the induction) is enough -- to check that `w` is in the ball on which one has controls. Will be used to check that `u n` -- belongs to this ball for all `n`. have C : ∀ (n : ℕ) (w : E), dist w b ≀ f'symm.nnnorm * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n) / (1 - c * f'symm.nnnorm) * dist (f b) y → w ∈ closedBall b ε := fun n w hw ↩ by apply hw.trans rw [div_mul_eq_mul_div, div_le_iff]; swap; · linarith calc (f'symm.nnnorm : ℝ) * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n) * dist (f b) y = f'symm.nnnorm * dist (f b) y * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n) := by ring _ ≀ f'symm.nnnorm * dist (f b) y * 1 := by gcongr rw [sub_le_self_iff] positivity _ ≀ f'symm.nnnorm * (((f'symm.nnnorm : ℝ)⁻¹ - c) * ε) := by rw [mul_one] gcongr exact mem_closedBall'.1 hy _ = ε * (1 - c * f'symm.nnnorm) := by field_simp; ring /- Main inductive control: `f (u n)` becomes exponentially close to `y`, and therefore `dist (u (n+1)) (u n)` becomes exponentally small, making it possible to get an inductive bound on `dist (u n) b`, from which one checks that `u n` remains in the ball on which we have estimates. -/ have D : ∀ n : ℕ, dist (f (u n)) y ≀ ((c : ℝ) * f'symm.nnnorm) ^ n * dist (f b) y ∧ dist (u n) b ≀ f'symm.nnnorm * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n) / (1 - (c : ℝ) * f'symm.nnnorm) * dist (f b) y := fun n ↩ by induction' n with n IH; · simp [hu, le_refl] rw [usucc] have Ign : dist (g (u n)) b ≀ f'symm.nnnorm * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n.succ) / (1 - c * f'symm.nnnorm) * dist (f b) y := calc dist (g (u n)) b ≀ dist (g (u n)) (u n) + dist (u n) b := dist_triangle _ _ _ _ ≀ f'symm.nnnorm * dist (f (u n)) y + dist (u n) b := add_le_add (A _) le_rfl _ ≀ f'symm.nnnorm * (((c : ℝ) * f'symm.nnnorm) ^ n * dist (f b) y) + f'symm.nnnorm * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n) / (1 - c * f'symm.nnnorm) * dist (f b) y := by gcongr · exact IH.1 · exact IH.2 _ = f'symm.nnnorm * (1 - ((c : ℝ) * f'symm.nnnorm) ^ n.succ) / (1 - (c : ℝ) * f'symm.nnnorm) * dist (f b) y := by field_simp [Jcf', pow_succ]; ring refine ⟹?_, Ign⟩ calc dist (f (g (u n))) y ≀ c * f'symm.nnnorm * dist (f (u n)) y := B _ (C n _ IH.2) (C n.succ _ Ign) _ ≀ (c : ℝ) * f'symm.nnnorm * (((c : ℝ) * f'symm.nnnorm) ^ n * dist (f b) y) := by gcongr apply IH.1 _ = ((c : ℝ) * f'symm.nnnorm) ^ n.succ * dist (f b) y := by simp only [pow_succ']; ring -- Deduce from the inductive bound that `uₙ` is a Cauchy sequence, therefore converging. have : CauchySeq u := by refine cauchySeq_of_le_geometric _ (↑f'symm.nnnorm * dist (f b) y) Icf' fun n ↩ ?_ calc dist (u n) (u (n + 1)) = dist (g (u n)) (u n) := by rw [usucc, dist_comm] _ ≀ f'symm.nnnorm * dist (f (u n)) y := A _ _ ≀ f'symm.nnnorm * (((c : ℝ) * f'symm.nnnorm) ^ n * dist (f b) y) := by gcongr exact (D n).1 _ = f'symm.nnnorm * dist (f b) y * ((c : ℝ) * f'symm.nnnorm) ^ n := by ring obtain ⟹x, hx⟩ : ∃ x, Tendsto u atTop (𝓝 x) := cauchySeq_tendsto_of_complete this -- As all the `uₙ` belong to the ball `closedBall b ε`, so does their limit `x`. have xmem : x ∈ closedBall b ε := isClosed_ball.mem_of_tendsto hx (eventually_of_forall fun n => C n _ (D n).2) refine ⟹x, xmem, ?_⟩ -- It remains to check that `f x = y`. This follows from continuity of `f` on `closedBall b ε` -- and from the fact that `f uₙ` is converging to `y` by construction. have hx' : Tendsto u atTop (𝓝[closedBall b ε] x) := by simp only [nhdsWithin, tendsto_inf, hx, true_and_iff, tendsto_principal] exact eventually_of_forall fun n => C n _ (D n).2 have T1 : Tendsto (f ∘ u) atTop (𝓝 (f x)) := (hf.continuousOn.mono hε x xmem).tendsto.comp hx' have T2 : Tendsto (f ∘ u) atTop (𝓝 y) := by rw [tendsto_iff_dist_tendsto_zero] refine squeeze_zero (fun _ => dist_nonneg) (fun n => (D n).1) ?_ simpa using (tendsto_pow_atTop_nhds_zero_of_lt_one (by positivity) Icf').mul tendsto_const_nhds exact tendsto_nhds_unique T1 T2 theorem open_image (hf : ApproximatesLinearOn f f' s c) (f'symm : f'.NonlinearRightInverse) (hs : IsOpen s) (hc : Subsingleton F √ c < f'symm.nnnorm⁻¹) : IsOpen (f '' s) := by cases' hc with hE hc · exact isOpen_discrete _ simp only [isOpen_iff_mem_nhds, nhds_basis_closedBall.mem_iff, forall_mem_image] at hs ⊢ intro x hx rcases hs x hx with ⟚ε, ε0, hε⟩ refine ⟹(f'symm.nnnorm⁻¹ - c) * ε, mul_pos (sub_pos.2 hc) ε0, ?_⟩ exact (hf.surjOn_closedBall_of_nonlinearRightInverse f'symm (le_of_lt ε0) hε).mono hε Subset.rfl theorem image_mem_nhds (hf : ApproximatesLinearOn f f' s c) (f'symm : f'.NonlinearRightInverse) {x : E} (hs : s ∈ 𝓝 x) (hc : Subsingleton F √ c < f'symm.nnnorm⁻¹) : f '' s ∈ 𝓝 (f x) := by obtain ⟹t, hts, ht, xt⟩ : ∃ t, t ⊆ s ∧ IsOpen t ∧ x ∈ t := _root_.mem_nhds_iff.1 hs have := IsOpen.mem_nhds ((hf.mono_set hts).open_image f'symm ht hc) (mem_image_of_mem _ xt) exact mem_of_superset this (image_subset _ hts) theorem map_nhds_eq (hf : ApproximatesLinearOn f f' s c) (f'symm : f'.NonlinearRightInverse) {x : E} (hs : s ∈ 𝓝 x) (hc : Subsingleton F √ c < f'symm.nnnorm⁻¹) : map f (𝓝 x) = 𝓝 (f x) := by refine le_antisymm ((hf.continuousOn x (mem_of_mem_nhds hs)).continuousAt hs) (le_map fun t ht => ?_) have : f '' (s ∩ t) ∈ 𝓝 (f x) := (hf.mono_set inter_subset_left).image_mem_nhds f'symm (inter_mem hs ht) hc exact mem_of_superset this (image_subset _ inter_subset_right) end LocallyOnto /-! From now on we assume that `f` approximates an invertible continuous linear map `f : E ≃L[𝕜] F`. We also assume that either `E = {0}`, or `c < ‖f'⁻¹‖⁻¹`. We use `N` as an abbreviation for `‖f'⁻¹‖`. -/ variable {f' : E ≃L[𝕜] F} {s : Set E} {c : ℝ≥0} local notation "N" => ‖(f'.symm : F →L[𝕜] E)‖₊ protected theorem antilipschitz (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E √ c < N⁻¹) : AntilipschitzWith (N⁻¹ - c)⁻¹ (s.restrict f) := by cases' hc with hE hc · exact AntilipschitzWith.of_subsingleton convert (f'.antilipschitz.restrict s).add_lipschitzWith hf.lipschitz_sub hc simp [restrict] protected theorem injective (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E √ c < N⁻¹) : Injective (s.restrict f) := (hf.antilipschitz hc).injective protected theorem injOn (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E √ c < N⁻¹) : InjOn f s := injOn_iff_injective.2 <| hf.injective hc protected theorem surjective [CompleteSpace E] (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) univ c) (hc : Subsingleton E √ c < N⁻¹) : Surjective f := by cases' hc with hE hc · haveI : Subsingleton F := (Equiv.subsingleton_congr f'.toEquiv).1 hE exact surjective_to_subsingleton _ · apply forall_of_forall_mem_closedBall (fun y : F => ∃ a, f a = y) (f 0) _ have hc' : (0 : ℝ) < N⁻¹ - c := by rw [sub_pos]; exact hc let p : ℝ → Prop := fun R => closedBall (f 0) R ⊆ Set.range f have hp : ∀ᶠ r : ℝ in atTop, p ((N⁻¹ - c) * r) := by have hr : ∀ᶠ r : ℝ in atTop, 0 ≀ r := eventually_ge_atTop 0 refine hr.mono fun r hr => Subset.trans ?_ (image_subset_range f (closedBall 0 r)) refine hf.surjOn_closedBall_of_nonlinearRightInverse f'.toNonlinearRightInverse hr ?_ exact subset_univ _ refine ((tendsto_id.const_mul_atTop hc').frequently hp.frequently).mono ?_ exact fun R h y hy => h hy /-- A map approximating a linear equivalence on a set defines a partial equivalence on this set. Should not be used outside of this file, because it is superseded by `toPartialHomeomorph` below. This is a first step towards the inverse function. -/ def toPartialEquiv (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E √ c < N⁻¹) : PartialEquiv E F := (hf.injOn hc).toPartialEquiv _ _ /-- The inverse function is continuous on `f '' s`. Use properties of `PartialHomeomorph` instead. -/ theorem inverse_continuousOn (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E √ c < N⁻¹) : ContinuousOn (hf.toPartialEquiv hc).symm (f '' s) := by apply continuousOn_iff_continuous_restrict.2 refine ((hf.antilipschitz hc).to_rightInvOn' ?_ (hf.toPartialEquiv hc).right_inv').continuous exact fun x hx => (hf.toPartialEquiv hc).map_target hx /-- The inverse function is approximated linearly on `f '' s` by `f'.symm`. -/ theorem to_inv (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E √ c < N⁻¹) : ApproximatesLinearOn (hf.toPartialEquiv hc).symm (f'.symm : F →L[𝕜] E) (f '' s) (N * (N⁻¹ - c)⁻¹ * c) := fun x hx y hy ↩ by set A := hf.toPartialEquiv hc have Af : ∀ z, A z = f z := fun z => rfl rcases (mem_image _ _ _).1 hx with ⟹x', x's, rfl⟩ rcases (mem_image _ _ _).1 hy with ⟹y', y's, rfl⟩ rw [← Af x', ← Af y', A.left_inv x's, A.left_inv y's] calc ‖x' - y' - f'.symm (A x' - A y')‖ ≀ N * ‖f' (x' - y' - f'.symm (A x' - A y'))‖ := (f' : E →L[𝕜] F).bound_of_antilipschitz f'.antilipschitz _ _ = N * ‖A y' - A x' - f' (y' - x')‖ := by congr 2 simp only [ContinuousLinearEquiv.apply_symm_apply, ContinuousLinearEquiv.map_sub] abel _ ≀ N * (c * ‖y' - x'‖) := mul_le_mul_of_nonneg_left (hf _ y's _ x's) (NNReal.coe_nonneg _) _ ≀ N * (c * (((N⁻¹ - c)⁻¹ : ℝ≥0) * ‖A y' - A x'‖)) := by gcongr rw [← dist_eq_norm, ← dist_eq_norm] exact (hf.antilipschitz hc).le_mul_dist ⟹y', y's⟩ ⟹x', x's⟩ _ = (N * (N⁻¹ - c)⁻¹ * c : ℝ≥0) * ‖A x' - A y'‖ := by simp only [norm_sub_rev, NNReal.coe_mul]; ring variable [CompleteSpace E] section variable (f s) /-- Given a function `f` that approximates a linear equivalence on an open set `s`, returns a partial homeomorphism with `toFun = f` and `source = s`. -/ def toPartialHomeomorph (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E √ c < N⁻¹) (hs : IsOpen s) : PartialHomeomorph E F where toPartialEquiv := hf.toPartialEquiv hc open_source := hs open_target := hf.open_image f'.toNonlinearRightInverse hs <| by rwa [f'.toEquiv.subsingleton_congr] at hc continuousOn_toFun := hf.continuousOn continuousOn_invFun := hf.inverse_continuousOn hc @[simp] theorem toPartialHomeomorph_coe (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E √ c < N⁻¹) (hs : IsOpen s) : (hf.toPartialHomeomorph f s hc hs : E → F) = f := rfl @[simp] theorem toPartialHomeomorph_source (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E √ c < N⁻¹) (hs : IsOpen s) : (hf.toPartialHomeomorph f s hc hs).source = s := rfl @[simp] theorem toPartialHomeomorph_target (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E √ c < N⁻¹) (hs : IsOpen s) : (hf.toPartialHomeomorph f s hc hs).target = f '' s := rfl /-- A function `f` that approximates a linear equivalence on the whole space is a homeomorphism. -/ def toHomeomorph (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) univ c) (hc : Subsingleton E √ c < N⁻¹) : E ≃ₜ F := by refine (hf.toPartialHomeomorph _ _ hc isOpen_univ).toHomeomorphOfSourceEqUnivTargetEqUniv rfl ?_ rw [toPartialHomeomorph_target, image_univ, range_iff_surjective] exact hf.surjective hc end theorem closedBall_subset_target (hf : ApproximatesLinearOn f (f' : E →L[𝕜] F) s c) (hc : Subsingleton E √ c < N⁻¹) (hs : IsOpen s) {b : E} (ε0 : 0 ≀ ε) (hε : closedBall b ε ⊆ s) : closedBall (f b) ((N⁻¹ - c) * ε) ⊆ (hf.toPartialHomeomorph f s hc hs).target := (hf.surjOn_closedBall_of_nonlinearRightInverse f'.toNonlinearRightInverse ε0 hε).mono hε Subset.rfl end ApproximatesLinearOn
Analysis\Calculus\InverseFunctionTheorem\ContDiff.lean
/- Copyright (c) 2020 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Calculus.ContDiff.RCLike import Mathlib.Analysis.Calculus.InverseFunctionTheorem.FDeriv /-! # Inverse function theorem, smooth case In this file we specialize the inverse function theorem to `C^r`-smooth functions. -/ noncomputable section namespace ContDiffAt variable {𝕂 : Type*} [RCLike 𝕂] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕂 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕂 F] variable [CompleteSpace E] (f : E → F) {f' : E ≃L[𝕂] F} {a : E} /-- Given a `ContDiff` function over `𝕂` (which is `ℝ` or `ℂ`) with an invertible derivative at `a`, returns a `PartialHomeomorph` with `to_fun = f` and `a ∈ source`. -/ def toPartialHomeomorph {n : ℕ∞} (hf : ContDiffAt 𝕂 n f a) (hf' : HasFDerivAt f (f' : E →L[𝕂] F) a) (hn : 1 ≀ n) : PartialHomeomorph E F := (hf.hasStrictFDerivAt' hf' hn).toPartialHomeomorph f variable {f} @[simp] theorem toPartialHomeomorph_coe {n : ℕ∞} (hf : ContDiffAt 𝕂 n f a) (hf' : HasFDerivAt f (f' : E →L[𝕂] F) a) (hn : 1 ≀ n) : (hf.toPartialHomeomorph f hf' hn : E → F) = f := rfl theorem mem_toPartialHomeomorph_source {n : ℕ∞} (hf : ContDiffAt 𝕂 n f a) (hf' : HasFDerivAt f (f' : E →L[𝕂] F) a) (hn : 1 ≀ n) : a ∈ (hf.toPartialHomeomorph f hf' hn).source := (hf.hasStrictFDerivAt' hf' hn).mem_toPartialHomeomorph_source theorem image_mem_toPartialHomeomorph_target {n : ℕ∞} (hf : ContDiffAt 𝕂 n f a) (hf' : HasFDerivAt f (f' : E →L[𝕂] F) a) (hn : 1 ≀ n) : f a ∈ (hf.toPartialHomeomorph f hf' hn).target := (hf.hasStrictFDerivAt' hf' hn).image_mem_toPartialHomeomorph_target /-- Given a `ContDiff` function over `𝕂` (which is `ℝ` or `ℂ`) with an invertible derivative at `a`, returns a function that is locally inverse to `f`. -/ def localInverse {n : ℕ∞} (hf : ContDiffAt 𝕂 n f a) (hf' : HasFDerivAt f (f' : E →L[𝕂] F) a) (hn : 1 ≀ n) : F → E := (hf.hasStrictFDerivAt' hf' hn).localInverse f f' a theorem localInverse_apply_image {n : ℕ∞} (hf : ContDiffAt 𝕂 n f a) (hf' : HasFDerivAt f (f' : E →L[𝕂] F) a) (hn : 1 ≀ n) : hf.localInverse hf' hn (f a) = a := (hf.hasStrictFDerivAt' hf' hn).localInverse_apply_image /-- Given a `ContDiff` function over `𝕂` (which is `ℝ` or `ℂ`) with an invertible derivative at `a`, the inverse function (produced by `ContDiff.toPartialHomeomorph`) is also `ContDiff`. -/ theorem to_localInverse {n : ℕ∞} (hf : ContDiffAt 𝕂 n f a) (hf' : HasFDerivAt f (f' : E →L[𝕂] F) a) (hn : 1 ≀ n) : ContDiffAt 𝕂 n (hf.localInverse hf' hn) (f a) := by have := hf.localInverse_apply_image hf' hn apply (hf.toPartialHomeomorph f hf' hn).contDiffAt_symm (image_mem_toPartialHomeomorph_target hf hf' hn) · convert hf' · convert hf end ContDiffAt
Analysis\Calculus\InverseFunctionTheorem\Deriv.lean
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Inverse import Mathlib.Analysis.Calculus.InverseFunctionTheorem.FDeriv /-! # Inverse function theorem, 1D case In this file we prove a version of the inverse function theorem for maps `f : 𝕜 → 𝕜`. We use `ContinuousLinearEquiv.unitsEquivAut` to translate `HasStrictDerivAt f f' a` and `f' ≠ 0` into `HasStrictFDerivAt f (_ : 𝕜 ≃L[𝕜] 𝕜) a`. -/ open Filter open scoped Topology variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] [CompleteSpace 𝕜] (f : 𝕜 → 𝕜) noncomputable section namespace HasStrictDerivAt variable (f' a : 𝕜) (hf : HasStrictDerivAt f f' a) (hf' : f' ≠ 0) /-- A function that is inverse to `f` near `a`. -/ abbrev localInverse : 𝕜 → 𝕜 := (hf.hasStrictFDerivAt_equiv hf').localInverse _ _ _ variable {f f' a} theorem map_nhds_eq : map f (𝓝 a) = 𝓝 (f a) := (hf.hasStrictFDerivAt_equiv hf').map_nhds_eq_of_equiv theorem to_localInverse : HasStrictDerivAt (hf.localInverse f f' a hf') f'⁻¹ (f a) := (hf.hasStrictFDerivAt_equiv hf').to_localInverse theorem to_local_left_inverse {g : 𝕜 → 𝕜} (hg : ∀ᶠ x in 𝓝 a, g (f x) = x) : HasStrictDerivAt g f'⁻¹ (f a) := (hf.hasStrictFDerivAt_equiv hf').to_local_left_inverse hg end HasStrictDerivAt variable {f} /-- If a function has a non-zero strict derivative at all points, then it is an open map. -/ theorem isOpenMap_of_hasStrictDerivAt {f' : 𝕜 → 𝕜} (hf : ∀ x, HasStrictDerivAt f (f' x) x) (h0 : ∀ x, f' x ≠ 0) : IsOpenMap f := isOpenMap_iff_nhds_le.2 fun x => ((hf x).map_nhds_eq (h0 x)).ge @[deprecated (since := "2024-03-23")] alias open_map_of_strict_deriv := isOpenMap_of_hasStrictDerivAt
Analysis\Calculus\InverseFunctionTheorem\FDeriv.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.FDeriv.Equiv import Mathlib.Analysis.Calculus.InverseFunctionTheorem.ApproximatesLinearOn /-! # Inverse function theorem In this file we prove the inverse function theorem. It says that if a map `f : E → F` has an invertible strict derivative `f'` at `a`, then it is locally invertible, and the inverse function has derivative `f' ⁻¹`. We define `HasStrictFDerivAt.toPartialHomeomorph` that repacks a function `f` with a `hf : HasStrictFDerivAt f f' a`, `f' : E ≃L[𝕜] F`, into a `PartialHomeomorph`. The `toFun` of this `PartialHomeomorph` is defeq to `f`, so one can apply theorems about `PartialHomeomorph` to `hf.toPartialHomeomorph f`, and get statements about `f`. Then we define `HasStrictFDerivAt.localInverse` to be the `invFun` of this `PartialHomeomorph`, and prove two versions of the inverse function theorem: * `HasStrictFDerivAt.to_localInverse`: if `f` has an invertible derivative `f'` at `a` in the strict sense (`hf`), then `hf.localInverse f f' a` has derivative `f'.symm` at `f a` in the strict sense; * `HasStrictFDerivAt.to_local_left_inverse`: if `f` has an invertible derivative `f'` at `a` in the strict sense and `g` is locally left inverse to `f` near `a`, then `g` has derivative `f'.symm` at `f a` in the strict sense. Some related theorems, providing the derivative and higher regularity assuming that we already know the inverse function, are formulated in the `Analysis/Calculus/FDeriv` and `Analysis/Calculus/Deriv` folders, and in `ContDiff.lean`. ## Tags derivative, strictly differentiable, continuously differentiable, smooth, inverse function -/ open Function Set Filter Metric open scoped Topology NNReal noncomputable section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] variable {ε : ℝ} open Asymptotics Filter Metric Set open ContinuousLinearMap (id) /-! ### Inverse function theorem Let `f : E → F` be a map defined on a complete vector space `E`. Assume that `f` has an invertible derivative `f' : E ≃L[𝕜] F` at `a : E` in the strict sense. Then `f` approximates `f'` in the sense of `ApproximatesLinearOn` on an open neighborhood of `a`, and we can apply `ApproximatesLinearOn.toPartialHomeomorph` to construct the inverse function. -/ namespace HasStrictFDerivAt /-- If `f` has derivative `f'` at `a` in the strict sense and `c > 0`, then `f` approximates `f'` with constant `c` on some neighborhood of `a`. -/ theorem approximates_deriv_on_nhds {f : E → F} {f' : E →L[𝕜] F} {a : E} (hf : HasStrictFDerivAt f f' a) {c : ℝ≥0} (hc : Subsingleton E √ 0 < c) : ∃ s ∈ 𝓝 a, ApproximatesLinearOn f f' s c := by cases' hc with hE hc · refine ⟹univ, IsOpen.mem_nhds isOpen_univ trivial, fun x _ y _ => ?_⟩ simp [@Subsingleton.elim E hE x y] have := hf.def hc rw [nhds_prod_eq, Filter.Eventually, mem_prod_same_iff] at this rcases this with ⟹s, has, hs⟩ exact ⟹s, has, fun x hx y hy => hs (mk_mem_prod hx hy)⟩ theorem map_nhds_eq_of_surj [CompleteSpace E] [CompleteSpace F] {f : E → F} {f' : E →L[𝕜] F} {a : E} (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) (h : LinearMap.range f' = ⊀) : map f (𝓝 a) = 𝓝 (f a) := by let f'symm := f'.nonlinearRightInverseOfSurjective h set c : ℝ≥0 := f'symm.nnnorm⁻¹ / 2 with hc have f'symm_pos : 0 < f'symm.nnnorm := f'.nonlinearRightInverseOfSurjective_nnnorm_pos h have cpos : 0 < c := by simp [hc, half_pos, inv_pos, f'symm_pos] obtain ⟹s, s_nhds, hs⟩ : ∃ s ∈ 𝓝 a, ApproximatesLinearOn f f' s c := hf.approximates_deriv_on_nhds (Or.inr cpos) apply hs.map_nhds_eq f'symm s_nhds (Or.inr (NNReal.half_lt_self _)) simp [ne_of_gt f'symm_pos] variable [CompleteSpace E] {f : E → F} {f' : E ≃L[𝕜] F} {a : E} theorem approximates_deriv_on_open_nhds (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : ∃ s : Set E, a ∈ s ∧ IsOpen s ∧ ApproximatesLinearOn f (f' : E →L[𝕜] F) s (‖(f'.symm : F →L[𝕜] E)‖₊⁻¹ / 2) := by simp only [← and_assoc] refine ((nhds_basis_opens a).exists_iff fun s t => ApproximatesLinearOn.mono_set).1 ?_ exact hf.approximates_deriv_on_nhds <| f'.subsingleton_or_nnnorm_symm_pos.imp id fun hf' => half_pos <| inv_pos.2 hf' variable (f) /-- Given a function with an invertible strict derivative at `a`, returns a `PartialHomeomorph` with `to_fun = f` and `a ∈ source`. This is a part of the inverse function theorem. The other part `HasStrictFDerivAt.to_localInverse` states that the inverse function of this `PartialHomeomorph` has derivative `f'.symm`. -/ def toPartialHomeomorph (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : PartialHomeomorph E F := ApproximatesLinearOn.toPartialHomeomorph f (Classical.choose hf.approximates_deriv_on_open_nhds) (Classical.choose_spec hf.approximates_deriv_on_open_nhds).2.2 (f'.subsingleton_or_nnnorm_symm_pos.imp id fun hf' => NNReal.half_lt_self <| ne_of_gt <| inv_pos.2 hf') (Classical.choose_spec hf.approximates_deriv_on_open_nhds).2.1 variable {f} @[simp] theorem toPartialHomeomorph_coe (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : (hf.toPartialHomeomorph f : E → F) = f := rfl theorem mem_toPartialHomeomorph_source (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : a ∈ (hf.toPartialHomeomorph f).source := (Classical.choose_spec hf.approximates_deriv_on_open_nhds).1 theorem image_mem_toPartialHomeomorph_target (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : f a ∈ (hf.toPartialHomeomorph f).target := (hf.toPartialHomeomorph f).map_source hf.mem_toPartialHomeomorph_source theorem map_nhds_eq_of_equiv (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : map f (𝓝 a) = 𝓝 (f a) := (hf.toPartialHomeomorph f).map_nhds_eq hf.mem_toPartialHomeomorph_source variable (f f' a) /-- Given a function `f` with an invertible derivative, returns a function that is locally inverse to `f`. -/ def localInverse (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : F → E := (hf.toPartialHomeomorph f).symm variable {f f' a} theorem localInverse_def (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : hf.localInverse f _ _ = (hf.toPartialHomeomorph f).symm := rfl theorem eventually_left_inverse (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : ∀ᶠ x in 𝓝 a, hf.localInverse f f' a (f x) = x := (hf.toPartialHomeomorph f).eventually_left_inverse hf.mem_toPartialHomeomorph_source @[simp] theorem localInverse_apply_image (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : hf.localInverse f f' a (f a) = a := hf.eventually_left_inverse.self_of_nhds theorem eventually_right_inverse (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : ∀ᶠ y in 𝓝 (f a), f (hf.localInverse f f' a y) = y := (hf.toPartialHomeomorph f).eventually_right_inverse' hf.mem_toPartialHomeomorph_source theorem localInverse_continuousAt (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : ContinuousAt (hf.localInverse f f' a) (f a) := (hf.toPartialHomeomorph f).continuousAt_symm hf.image_mem_toPartialHomeomorph_target theorem localInverse_tendsto (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : Tendsto (hf.localInverse f f' a) (𝓝 <| f a) (𝓝 a) := (hf.toPartialHomeomorph f).tendsto_symm hf.mem_toPartialHomeomorph_source theorem localInverse_unique (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) {g : F → E} (hg : ∀ᶠ x in 𝓝 a, g (f x) = x) : ∀ᶠ y in 𝓝 (f a), g y = localInverse f f' a hf y := eventuallyEq_of_left_inv_of_right_inv hg hf.eventually_right_inverse <| (hf.toPartialHomeomorph f).tendsto_symm hf.mem_toPartialHomeomorph_source /-- If `f` has an invertible derivative `f'` at `a` in the sense of strict differentiability `(hf)`, then the inverse function `hf.localInverse f` has derivative `f'.symm` at `f a`. -/ theorem to_localInverse (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) : HasStrictFDerivAt (hf.localInverse f f' a) (f'.symm : F →L[𝕜] E) (f a) := (hf.toPartialHomeomorph f).hasStrictFDerivAt_symm hf.image_mem_toPartialHomeomorph_target <| by simpa [← localInverse_def] using hf /-- If `f : E → F` has an invertible derivative `f'` at `a` in the sense of strict differentiability and `g (f x) = x` in a neighborhood of `a`, then `g` has derivative `f'.symm` at `f a`. For a version assuming `f (g y) = y` and continuity of `g` at `f a` but not `[CompleteSpace E]` see `of_local_left_inverse`. -/ theorem to_local_left_inverse (hf : HasStrictFDerivAt f (f' : E →L[𝕜] F) a) {g : F → E} (hg : ∀ᶠ x in 𝓝 a, g (f x) = x) : HasStrictFDerivAt g (f'.symm : F →L[𝕜] E) (f a) := hf.to_localInverse.congr_of_eventuallyEq <| (hf.localInverse_unique hg).mono fun _ => Eq.symm end HasStrictFDerivAt /-- If a function has an invertible strict derivative at all points, then it is an open map. -/ theorem isOpenMap_of_hasStrictFDerivAt_equiv [CompleteSpace E] {f : E → F} {f' : E → E ≃L[𝕜] F} (hf : ∀ x, HasStrictFDerivAt f (f' x : E →L[𝕜] F) x) : IsOpenMap f := isOpenMap_iff_nhds_le.2 fun x => (hf x).map_nhds_eq_of_equiv.ge @[deprecated (since := "2024-03-23")] alias open_map_of_strict_fderiv_equiv := isOpenMap_of_hasStrictFDerivAt_equiv
Analysis\Calculus\InverseFunctionTheorem\FiniteDimensional.lean
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.InverseFunctionTheorem.ApproximatesLinearOn import Mathlib.Analysis.Normed.Module.FiniteDimension /-! # A lemma about `ApproximatesLinearOn` that needs `FiniteDimensional` In this file we prove that in a real vector space, a function `f` that approximates a linear equivalence on a subset `s` can be extended to a homeomorphism of the whole space. This used to be the only lemma in `Mathlib/Analysis/Calculus/Inverse` depending on `FiniteDimensional`, so it was moved to a new file when the original file got split. -/ open Set open scoped NNReal namespace ApproximatesLinearOn /-- In a real vector space, a function `f` that approximates a linear equivalence on a subset `s` can be extended to a homeomorphism of the whole space. -/ theorem exists_homeomorph_extension {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [FiniteDimensional ℝ F] {s : Set E} {f : E → F} {f' : E ≃L[ℝ] F} {c : ℝ≥0} (hf : ApproximatesLinearOn f (f' : E →L[ℝ] F) s c) (hc : Subsingleton E √ lipschitzExtensionConstant F * c < ‖(f'.symm : F →L[ℝ] E)‖₊⁻¹) : ∃ g : E ≃ₜ F, EqOn f g s := by -- the difference `f - f'` is Lipschitz on `s`. It can be extended to a Lipschitz function `u` -- on the whole space, with a slightly worse Lipschitz constant. Then `f' + u` will be the -- desired homeomorphism. obtain ⟹u, hu, uf⟩ : ∃ u : E → F, LipschitzWith (lipschitzExtensionConstant F * c) u ∧ EqOn (f - ⇑f') u s := hf.lipschitzOnWith.extend_finite_dimension let g : E → F := fun x => f' x + u x have fg : EqOn f g s := fun x hx => by simp_rw [g, ← uf hx, Pi.sub_apply, add_sub_cancel] have hg : ApproximatesLinearOn g (f' : E →L[ℝ] F) univ (lipschitzExtensionConstant F * c) := by apply LipschitzOnWith.approximatesLinearOn rw [lipschitzOnWith_univ] convert hu ext x simp only [g, add_sub_cancel_left, ContinuousLinearEquiv.coe_coe, Pi.sub_apply] haveI : FiniteDimensional ℝ E := f'.symm.finiteDimensional exact ⟹hg.toHomeomorph g hc, fg⟩ end ApproximatesLinearOn
Analysis\Calculus\IteratedDeriv\Defs.lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.ContDiff.Defs /-! # One-dimensional iterated derivatives We define the `n`-th derivative of a function `f : 𝕜 → F` as a function `iteratedDeriv n f : 𝕜 → F`, as well as a version on domains `iteratedDerivWithin n f s : 𝕜 → F`, and prove their basic properties. ## Main definitions and results Let `𝕜` be a nontrivially normed field, and `F` a normed vector space over `𝕜`. Let `f : 𝕜 → F`. * `iteratedDeriv n f` is the `n`-th derivative of `f`, seen as a function from `𝕜` to `F`. It is defined as the `n`-th Fréchet derivative (which is a multilinear map) applied to the vector `(1, ..., 1)`, to take advantage of all the existing framework, but we show that it coincides with the naive iterative definition. * `iteratedDeriv_eq_iterate` states that the `n`-th derivative of `f` is obtained by starting from `f` and differentiating it `n` times. * `iteratedDerivWithin n f s` is the `n`-th derivative of `f` within the domain `s`. It only behaves well when `s` has the unique derivative property. * `iteratedDerivWithin_eq_iterate` states that the `n`-th derivative of `f` in the domain `s` is obtained by starting from `f` and differentiating it `n` times within `s`. This only holds when `s` has the unique derivative property. ## Implementation details The results are deduced from the corresponding results for the more general (multilinear) iterated Fréchet derivative. For this, we write `iteratedDeriv n f` as the composition of `iteratedFDeriv 𝕜 n f` and a continuous linear equiv. As continuous linear equivs respect differentiability and commute with differentiation, this makes it possible to prove readily that the derivative of the `n`-th derivative is the `n+1`-th derivative in `iteratedDerivWithin_succ`, by translating the corresponding result `iteratedFDerivWithin_succ_apply_left` for the iterated Fréchet derivative. -/ noncomputable section open scoped Topology open Filter Asymptotics Set variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] /-- The `n`-th iterated derivative of a function from `𝕜` to `F`, as a function from `𝕜` to `F`. -/ def iteratedDeriv (n : ℕ) (f : 𝕜 → F) (x : 𝕜) : F := (iteratedFDeriv 𝕜 n f x : (Fin n → 𝕜) → F) fun _ : Fin n => 1 /-- The `n`-th iterated derivative of a function from `𝕜` to `F` within a set `s`, as a function from `𝕜` to `F`. -/ def iteratedDerivWithin (n : ℕ) (f : 𝕜 → F) (s : Set 𝕜) (x : 𝕜) : F := (iteratedFDerivWithin 𝕜 n f s x : (Fin n → 𝕜) → F) fun _ : Fin n => 1 variable {n : ℕ} {f : 𝕜 → F} {s : Set 𝕜} {x : 𝕜} theorem iteratedDerivWithin_univ : iteratedDerivWithin n f univ = iteratedDeriv n f := by ext x rw [iteratedDerivWithin, iteratedDeriv, iteratedFDerivWithin_univ] /-! ### Properties of the iterated derivative within a set -/ theorem iteratedDerivWithin_eq_iteratedFDerivWithin : iteratedDerivWithin n f s x = (iteratedFDerivWithin 𝕜 n f s x : (Fin n → 𝕜) → F) fun _ : Fin n => 1 := rfl /-- Write the iterated derivative as the composition of a continuous linear equiv and the iterated Fréchet derivative -/ theorem iteratedDerivWithin_eq_equiv_comp : iteratedDerivWithin n f s = (ContinuousMultilinearMap.piFieldEquiv 𝕜 (Fin n) F).symm ∘ iteratedFDerivWithin 𝕜 n f s := by ext x; rfl /-- Write the iterated Fréchet derivative as the composition of a continuous linear equiv and the iterated derivative. -/ theorem iteratedFDerivWithin_eq_equiv_comp : iteratedFDerivWithin 𝕜 n f s = ContinuousMultilinearMap.piFieldEquiv 𝕜 (Fin n) F ∘ iteratedDerivWithin n f s := by rw [iteratedDerivWithin_eq_equiv_comp, ← Function.comp.assoc, LinearIsometryEquiv.self_comp_symm, Function.id_comp] /-- The `n`-th Fréchet derivative applied to a vector `(m 0, ..., m (n-1))` is the derivative multiplied by the product of the `m i`s. -/ theorem iteratedFDerivWithin_apply_eq_iteratedDerivWithin_mul_prod {m : Fin n → 𝕜} : (iteratedFDerivWithin 𝕜 n f s x : (Fin n → 𝕜) → F) m = (∏ i, m i) • iteratedDerivWithin n f s x := by rw [iteratedDerivWithin_eq_iteratedFDerivWithin, ← ContinuousMultilinearMap.map_smul_univ] simp theorem norm_iteratedFDerivWithin_eq_norm_iteratedDerivWithin : ‖iteratedFDerivWithin 𝕜 n f s x‖ = ‖iteratedDerivWithin n f s x‖ := by rw [iteratedDerivWithin_eq_equiv_comp, Function.comp_apply, LinearIsometryEquiv.norm_map] @[simp] theorem iteratedDerivWithin_zero : iteratedDerivWithin 0 f s = f := by ext x simp [iteratedDerivWithin] @[simp] theorem iteratedDerivWithin_one {x : 𝕜} (h : UniqueDiffWithinAt 𝕜 s x) : iteratedDerivWithin 1 f s x = derivWithin f s x := by simp only [iteratedDerivWithin, iteratedFDerivWithin_one_apply h]; rfl /-- If the first `n` derivatives within a set of a function are continuous, and its first `n-1` derivatives are differentiable, then the function is `C^n`. This is not an equivalence in general, but this is an equivalence when the set has unique derivatives, see `contDiffOn_iff_continuousOn_differentiableOn_deriv`. -/ theorem contDiffOn_of_continuousOn_differentiableOn_deriv {n : ℕ∞} (Hcont : ∀ m : ℕ, (m : ℕ∞) ≀ n → ContinuousOn (fun x => iteratedDerivWithin m f s x) s) (Hdiff : ∀ m : ℕ, (m : ℕ∞) < n → DifferentiableOn 𝕜 (fun x => iteratedDerivWithin m f s x) s) : ContDiffOn 𝕜 n f s := by apply contDiffOn_of_continuousOn_differentiableOn · simpa only [iteratedFDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_continuousOn_iff] · simpa only [iteratedFDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_differentiableOn_iff] /-- To check that a function is `n` times continuously differentiable, it suffices to check that its first `n` derivatives are differentiable. This is slightly too strong as the condition we require on the `n`-th derivative is differentiability instead of continuity, but it has the advantage of avoiding the discussion of continuity in the proof (and for `n = ∞` this is optimal). -/ theorem contDiffOn_of_differentiableOn_deriv {n : ℕ∞} (h : ∀ m : ℕ, (m : ℕ∞) ≀ n → DifferentiableOn 𝕜 (iteratedDerivWithin m f s) s) : ContDiffOn 𝕜 n f s := by apply contDiffOn_of_differentiableOn simpa only [iteratedFDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_differentiableOn_iff] /-- On a set with unique derivatives, a `C^n` function has derivatives up to `n` which are continuous. -/ theorem ContDiffOn.continuousOn_iteratedDerivWithin {n : ℕ∞} {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : (m : ℕ∞) ≀ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedDerivWithin m f s) s := by simpa only [iteratedDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_continuousOn_iff] using h.continuousOn_iteratedFDerivWithin hmn hs theorem ContDiffWithinAt.differentiableWithinAt_iteratedDerivWithin {n : ℕ∞} {m : ℕ} (h : ContDiffWithinAt 𝕜 n f s x) (hmn : (m : ℕ∞) < n) (hs : UniqueDiffOn 𝕜 (insert x s)) : DifferentiableWithinAt 𝕜 (iteratedDerivWithin m f s) s x := by simpa only [iteratedDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_differentiableWithinAt_iff] using h.differentiableWithinAt_iteratedFDerivWithin hmn hs /-- On a set with unique derivatives, a `C^n` function has derivatives less than `n` which are differentiable. -/ theorem ContDiffOn.differentiableOn_iteratedDerivWithin {n : ℕ∞} {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : (m : ℕ∞) < n) (hs : UniqueDiffOn 𝕜 s) : DifferentiableOn 𝕜 (iteratedDerivWithin m f s) s := fun x hx => (h x hx).differentiableWithinAt_iteratedDerivWithin hmn <| by rwa [insert_eq_of_mem hx] /-- The property of being `C^n`, initially defined in terms of the Fréchet derivative, can be reformulated in terms of the one-dimensional derivative on sets with unique derivatives. -/ theorem contDiffOn_iff_continuousOn_differentiableOn_deriv {n : ℕ∞} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, (m : ℕ∞) ≀ n → ContinuousOn (iteratedDerivWithin m f s) s) ∧ ∀ m : ℕ, (m : ℕ∞) < n → DifferentiableOn 𝕜 (iteratedDerivWithin m f s) s := by simp only [contDiffOn_iff_continuousOn_differentiableOn hs, iteratedFDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_continuousOn_iff, LinearIsometryEquiv.comp_differentiableOn_iff] /-- The `n+1`-th iterated derivative within a set with unique derivatives can be obtained by differentiating the `n`-th iterated derivative. -/ theorem iteratedDerivWithin_succ {x : 𝕜} (hxs : UniqueDiffWithinAt 𝕜 s x) : iteratedDerivWithin (n + 1) f s x = derivWithin (iteratedDerivWithin n f s) s x := by rw [iteratedDerivWithin_eq_iteratedFDerivWithin, iteratedFDerivWithin_succ_apply_left, iteratedFDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_fderivWithin _ hxs, derivWithin] change ((ContinuousMultilinearMap.mkPiRing 𝕜 (Fin n) ((fderivWithin 𝕜 (iteratedDerivWithin n f s) s x : 𝕜 → F) 1) : (Fin n → 𝕜) → F) fun i : Fin n => 1) = (fderivWithin 𝕜 (iteratedDerivWithin n f s) s x : 𝕜 → F) 1 simp /-- The `n`-th iterated derivative within a set with unique derivatives can be obtained by iterating `n` times the differentiation operation. -/ theorem iteratedDerivWithin_eq_iterate {x : 𝕜} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedDerivWithin n f s x = (fun g : 𝕜 → F => derivWithin g s)^[n] f x := by induction' n with n IH generalizing x · simp · rw [iteratedDerivWithin_succ (hs x hx), Function.iterate_succ'] exact derivWithin_congr (fun y hy => IH hy) (IH hx) /-- The `n+1`-th iterated derivative within a set with unique derivatives can be obtained by taking the `n`-th derivative of the derivative. -/ theorem iteratedDerivWithin_succ' {x : 𝕜} (hxs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedDerivWithin (n + 1) f s x = (iteratedDerivWithin n (derivWithin f s) s) x := by rw [iteratedDerivWithin_eq_iterate hxs hx, iteratedDerivWithin_eq_iterate hxs hx]; rfl /-! ### Properties of the iterated derivative on the whole space -/ theorem iteratedDeriv_eq_iteratedFDeriv : iteratedDeriv n f x = (iteratedFDeriv 𝕜 n f x : (Fin n → 𝕜) → F) fun _ : Fin n => 1 := rfl /-- Write the iterated derivative as the composition of a continuous linear equiv and the iterated Fréchet derivative -/ theorem iteratedDeriv_eq_equiv_comp : iteratedDeriv n f = (ContinuousMultilinearMap.piFieldEquiv 𝕜 (Fin n) F).symm ∘ iteratedFDeriv 𝕜 n f := by ext x; rfl /-- Write the iterated Fréchet derivative as the composition of a continuous linear equiv and the iterated derivative. -/ theorem iteratedFDeriv_eq_equiv_comp : iteratedFDeriv 𝕜 n f = ContinuousMultilinearMap.piFieldEquiv 𝕜 (Fin n) F ∘ iteratedDeriv n f := by rw [iteratedDeriv_eq_equiv_comp, ← Function.comp.assoc, LinearIsometryEquiv.self_comp_symm, Function.id_comp] /-- The `n`-th Fréchet derivative applied to a vector `(m 0, ..., m (n-1))` is the derivative multiplied by the product of the `m i`s. -/ theorem iteratedFDeriv_apply_eq_iteratedDeriv_mul_prod {m : Fin n → 𝕜} : (iteratedFDeriv 𝕜 n f x : (Fin n → 𝕜) → F) m = (∏ i, m i) • iteratedDeriv n f x := by rw [iteratedDeriv_eq_iteratedFDeriv, ← ContinuousMultilinearMap.map_smul_univ]; simp theorem norm_iteratedFDeriv_eq_norm_iteratedDeriv : ‖iteratedFDeriv 𝕜 n f x‖ = ‖iteratedDeriv n f x‖ := by rw [iteratedDeriv_eq_equiv_comp, Function.comp_apply, LinearIsometryEquiv.norm_map] @[simp] theorem iteratedDeriv_zero : iteratedDeriv 0 f = f := by ext x; simp [iteratedDeriv] @[simp] theorem iteratedDeriv_one : iteratedDeriv 1 f = deriv f := by ext x; simp [iteratedDeriv] /-- The property of being `C^n`, initially defined in terms of the Fréchet derivative, can be reformulated in terms of the one-dimensional derivative. -/ theorem contDiff_iff_iteratedDeriv {n : ℕ∞} : ContDiff 𝕜 n f ↔ (∀ m : ℕ, (m : ℕ∞) ≀ n → Continuous (iteratedDeriv m f)) ∧ ∀ m : ℕ, (m : ℕ∞) < n → Differentiable 𝕜 (iteratedDeriv m f) := by simp only [contDiff_iff_continuous_differentiable, iteratedFDeriv_eq_equiv_comp, LinearIsometryEquiv.comp_continuous_iff, LinearIsometryEquiv.comp_differentiable_iff] /-- To check that a function is `n` times continuously differentiable, it suffices to check that its first `n` derivatives are differentiable. This is slightly too strong as the condition we require on the `n`-th derivative is differentiability instead of continuity, but it has the advantage of avoiding the discussion of continuity in the proof (and for `n = ∞` this is optimal). -/ theorem contDiff_of_differentiable_iteratedDeriv {n : ℕ∞} (h : ∀ m : ℕ, (m : ℕ∞) ≀ n → Differentiable 𝕜 (iteratedDeriv m f)) : ContDiff 𝕜 n f := contDiff_iff_iteratedDeriv.2 ⟹fun m hm => (h m hm).continuous, fun m hm => h m (le_of_lt hm)⟩ theorem ContDiff.continuous_iteratedDeriv {n : ℕ∞} (m : ℕ) (h : ContDiff 𝕜 n f) (hmn : (m : ℕ∞) ≀ n) : Continuous (iteratedDeriv m f) := (contDiff_iff_iteratedDeriv.1 h).1 m hmn theorem ContDiff.differentiable_iteratedDeriv {n : ℕ∞} (m : ℕ) (h : ContDiff 𝕜 n f) (hmn : (m : ℕ∞) < n) : Differentiable 𝕜 (iteratedDeriv m f) := (contDiff_iff_iteratedDeriv.1 h).2 m hmn /-- The `n+1`-th iterated derivative can be obtained by differentiating the `n`-th iterated derivative. -/ theorem iteratedDeriv_succ : iteratedDeriv (n + 1) f = deriv (iteratedDeriv n f) := by ext x rw [← iteratedDerivWithin_univ, ← iteratedDerivWithin_univ, ← derivWithin_univ] exact iteratedDerivWithin_succ uniqueDiffWithinAt_univ /-- The `n`-th iterated derivative can be obtained by iterating `n` times the differentiation operation. -/ theorem iteratedDeriv_eq_iterate : iteratedDeriv n f = deriv^[n] f := by ext x rw [← iteratedDerivWithin_univ] convert iteratedDerivWithin_eq_iterate uniqueDiffOn_univ (F := F) (mem_univ x) simp [derivWithin_univ] /-- The `n+1`-th iterated derivative can be obtained by taking the `n`-th derivative of the derivative. -/ theorem iteratedDeriv_succ' : iteratedDeriv (n + 1) f = iteratedDeriv n (deriv f) := by rw [iteratedDeriv_eq_iterate, iteratedDeriv_eq_iterate]; rfl
Analysis\Calculus\IteratedDeriv\Lemmas.lean
/- Copyright (c) 2023 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck, Ruben Van de Velde -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Shift import Mathlib.Analysis.Calculus.IteratedDeriv.Defs /-! # One-dimensional iterated derivatives This file contains a number of further results on `iteratedDerivWithin` that need more imports than are available in `Mathlib/Analysis/Calculus/IteratedDeriv/Defs.lean`. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] {n : ℕ} {x : 𝕜} {s : Set 𝕜} (hx : x ∈ s) (h : UniqueDiffOn 𝕜 s) {f g : 𝕜 → F} theorem iteratedDerivWithin_add (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) : iteratedDerivWithin n (f + g) s x = iteratedDerivWithin n f s x + iteratedDerivWithin n g s x := by simp_rw [iteratedDerivWithin, iteratedFDerivWithin_add_apply hf hg h hx, ContinuousMultilinearMap.add_apply] theorem iteratedDerivWithin_congr (hfg : Set.EqOn f g s) : Set.EqOn (iteratedDerivWithin n f s) (iteratedDerivWithin n g s) s := by induction n generalizing f g with | zero => rwa [iteratedDerivWithin_zero] | succ n IH => intro y hy have : UniqueDiffWithinAt 𝕜 s y := h.uniqueDiffWithinAt hy rw [iteratedDerivWithin_succ this, iteratedDerivWithin_succ this] exact derivWithin_congr (IH hfg) (IH hfg hy) theorem iteratedDerivWithin_const_add (hn : 0 < n) (c : F) : iteratedDerivWithin n (fun z => c + f z) s x = iteratedDerivWithin n f s x := by obtain ⟹n, rfl⟩ := n.exists_eq_succ_of_ne_zero hn.ne' rw [iteratedDerivWithin_succ' h hx, iteratedDerivWithin_succ' h hx] refine iteratedDerivWithin_congr h ?_ hx intro y hy exact derivWithin_const_add (h.uniqueDiffWithinAt hy) _ theorem iteratedDerivWithin_const_neg (hn : 0 < n) (c : F) : iteratedDerivWithin n (fun z => c - f z) s x = iteratedDerivWithin n (fun z => -f z) s x := by obtain ⟹n, rfl⟩ := n.exists_eq_succ_of_ne_zero hn.ne' rw [iteratedDerivWithin_succ' h hx, iteratedDerivWithin_succ' h hx] refine iteratedDerivWithin_congr h ?_ hx intro y hy have : UniqueDiffWithinAt 𝕜 s y := h.uniqueDiffWithinAt hy rw [derivWithin.neg this] exact derivWithin_const_sub this _ theorem iteratedDerivWithin_const_smul (c : R) (hf : ContDiffOn 𝕜 n f s) : iteratedDerivWithin n (c • f) s x = c • iteratedDerivWithin n f s x := by simp_rw [iteratedDerivWithin] rw [iteratedFDerivWithin_const_smul_apply hf h hx] simp only [ContinuousMultilinearMap.smul_apply] theorem iteratedDerivWithin_const_mul (c : 𝕜) {f : 𝕜 → 𝕜} (hf : ContDiffOn 𝕜 n f s) : iteratedDerivWithin n (fun z => c * f z) s x = c * iteratedDerivWithin n f s x := by simpa using iteratedDerivWithin_const_smul (F := 𝕜) hx h c hf variable (f) in theorem iteratedDerivWithin_neg : iteratedDerivWithin n (-f) s x = -iteratedDerivWithin n f s x := by rw [iteratedDerivWithin, iteratedDerivWithin, iteratedFDerivWithin_neg_apply h hx, ContinuousMultilinearMap.neg_apply] variable (f) in theorem iteratedDerivWithin_neg' : iteratedDerivWithin n (fun z => -f z) s x = -iteratedDerivWithin n f s x := iteratedDerivWithin_neg hx h f theorem iteratedDerivWithin_sub (hf : ContDiffOn 𝕜 n f s) (hg : ContDiffOn 𝕜 n g s) : iteratedDerivWithin n (f - g) s x = iteratedDerivWithin n f s x - iteratedDerivWithin n g s x := by rw [sub_eq_add_neg, sub_eq_add_neg, Pi.neg_def, iteratedDerivWithin_add hx h hf hg.neg, iteratedDerivWithin_neg' hx h] theorem iteratedDeriv_const_smul {n : ℕ} {f : 𝕜 → F} (h : ContDiff 𝕜 n f) (c : 𝕜) : iteratedDeriv n (fun x => f (c * x)) = fun x => c ^ n • iteratedDeriv n f (c * x) := by induction n with | zero => simp | succ n ih => funext x have h₀ : DifferentiableAt 𝕜 (iteratedDeriv n f) (c * x) := h.differentiable_iteratedDeriv n (Nat.cast_lt.mpr n.lt_succ_self) |>.differentiableAt have h₁ : DifferentiableAt 𝕜 (fun x => iteratedDeriv n f (c * x)) x := by rw [← Function.comp_def] apply DifferentiableAt.comp · exact h.differentiable_iteratedDeriv n (Nat.cast_lt.mpr n.lt_succ_self) |>.differentiableAt · exact differentiableAt_id'.const_mul _ rw [iteratedDeriv_succ, ih h.of_succ, deriv_const_smul _ h₁, iteratedDeriv_succ, ← Function.comp_def, deriv.scomp x h₀ (differentiableAt_id'.const_mul _), deriv_const_mul _ differentiableAt_id', deriv_id'', smul_smul, mul_one, pow_succ] theorem iteratedDeriv_const_mul {n : ℕ} {f : 𝕜 → 𝕜} (h : ContDiff 𝕜 n f) (c : 𝕜) : iteratedDeriv n (fun x => f (c * x)) = fun x => c ^ n * iteratedDeriv n f (c * x) := by simpa only [smul_eq_mul] using iteratedDeriv_const_smul h c lemma iteratedDeriv_neg (n : ℕ) (f : 𝕜 → F) (a : 𝕜) : iteratedDeriv n (fun x ↩ -(f x)) a = -(iteratedDeriv n f a) := by simp_rw [← iteratedDerivWithin_univ, iteratedDerivWithin_neg' (Set.mem_univ a) uniqueDiffOn_univ] lemma iteratedDeriv_comp_neg (n : ℕ) (f : 𝕜 → F) (a : 𝕜) : iteratedDeriv n (fun x ↩ f (-x)) a = (-1 : 𝕜) ^ n • iteratedDeriv n f (-a) := by induction' n with n ih generalizing a · simp only [Nat.zero_eq, iteratedDeriv_zero, pow_zero, one_smul] · have ih' : iteratedDeriv n (fun x ↩ f (-x)) = fun x ↩ (-1 : 𝕜) ^ n • iteratedDeriv n f (-x) := funext ih rw [iteratedDeriv_succ, iteratedDeriv_succ, ih', pow_succ', neg_mul, one_mul, deriv_comp_neg (f := fun x ↩ (-1 : 𝕜) ^ n • iteratedDeriv n f x), deriv_const_smul', neg_smul]
Analysis\Calculus\LineDeriv\Basic.lean
/- Copyright (c) 2023 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Slope /-! # Line derivatives We define the line derivative of a function `f : E → F`, at a point `x : E` along a vector `v : E`, as the element `f' : F` such that `f (x + t • v) = f x + t • f' + o (t)` as `t` tends to `0` in the scalar field `𝕜`, if it exists. It is denoted by `lineDeriv 𝕜 f x v`. This notion is generally less well behaved than the full Fréchet derivative (for instance, the composition of functions which are line-differentiable is not line-differentiable in general). The Fréchet derivative should therefore be favored over this one in general, although the line derivative may sometimes prove handy. The line derivative in direction `v` is also called the Gateaux derivative in direction `v`, although the term "Gateaux derivative" is sometimes reserved for the situation where there is such a derivative in all directions, for the map `v ↩ lineDeriv 𝕜 f x v` (which doesn't have to be linear in general). ## Main definition and results We mimic the definitions and statements for the Fréchet derivative and the one-dimensional derivative. We define in particular the following objects: * `LineDifferentiableWithinAt 𝕜 f s x v` * `LineDifferentiableAt 𝕜 f x v` * `HasLineDerivWithinAt 𝕜 f f' s x v` * `HasLineDerivAt 𝕜 f s x v` * `lineDerivWithin 𝕜 f s x v` * `lineDeriv 𝕜 f x v` and develop about them a basic API inspired by the one for the Fréchet derivative. We depart from the Fréchet derivative in two places, as the dependence of the following predicates on the direction would make them barely usable: * We do not define an analogue of the predicate `UniqueDiffOn`; * We do not define `LineDifferentiableOn` nor `LineDifferentiable`. -/ noncomputable section open scoped Topology Filter ENNReal NNReal open Filter Asymptotics Set variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] section Module /-! Results that do not rely on a topological structure on `E` -/ variable (𝕜) variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] /-- `f` has the derivative `f'` at the point `x` along the direction `v` in the set `s`. That is, `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0` and `x + t v ∈ s`. Note that this definition is less well behaved than the total Fréchet derivative, which should generally be favored over this one. -/ def HasLineDerivWithinAt (f : E → F) (f' : F) (s : Set E) (x : E) (v : E) := HasDerivWithinAt (fun t ↩ f (x + t • v)) f' ((fun t ↩ x + t • v) ⁻¹' s) (0 : 𝕜) /-- `f` has the derivative `f'` at the point `x` along the direction `v`. That is, `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0`. Note that this definition is less well behaved than the total Fréchet derivative, which should generally be favored over this one. -/ def HasLineDerivAt (f : E → F) (f' : F) (x : E) (v : E) := HasDerivAt (fun t ↩ f (x + t • v)) f' (0 : 𝕜) /-- `f` is line-differentiable at the point `x` in the direction `v` in the set `s` if there exists `f'` such that `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0` and `x + t v ∈ s`. -/ def LineDifferentiableWithinAt (f : E → F) (s : Set E) (x : E) (v : E) : Prop := DifferentiableWithinAt 𝕜 (fun t ↩ f (x + t • v)) ((fun t ↩ x + t • v) ⁻¹' s) (0 : 𝕜) /-- `f` is line-differentiable at the point `x` in the direction `v` if there exists `f'` such that `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0`. -/ def LineDifferentiableAt (f : E → F) (x : E) (v : E) : Prop := DifferentiableAt 𝕜 (fun t ↩ f (x + t • v)) (0 : 𝕜) /-- Line derivative of `f` at the point `x` in the direction `v` within the set `s`, if it exists. Zero otherwise. If the line derivative exists (i.e., `∃ f', HasLineDerivWithinAt 𝕜 f f' s x v`), then `f (x + t v) = f x + t lineDerivWithin 𝕜 f s x v + o (t)` when `t` tends to `0` and `x + t v ∈ s`. -/ def lineDerivWithin (f : E → F) (s : Set E) (x : E) (v : E) : F := derivWithin (fun t ↩ f (x + t • v)) ((fun t ↩ x + t • v) ⁻¹' s) (0 : 𝕜) /-- Line derivative of `f` at the point `x` in the direction `v`, if it exists. Zero otherwise. If the line derivative exists (i.e., `∃ f', HasLineDerivAt 𝕜 f f' x v`), then `f (x + t v) = f x + t lineDeriv 𝕜 f x v + o (t)` when `t` tends to `0`. -/ def lineDeriv (f : E → F) (x : E) (v : E) : F := deriv (fun t ↩ f (x + t • v)) (0 : 𝕜) variable {𝕜} variable {f f₁ : E → F} {f' f₀' f₁' : F} {s t : Set E} {x v : E} lemma HasLineDerivWithinAt.mono (hf : HasLineDerivWithinAt 𝕜 f f' s x v) (hst : t ⊆ s) : HasLineDerivWithinAt 𝕜 f f' t x v := HasDerivWithinAt.mono hf (preimage_mono hst) lemma HasLineDerivAt.hasLineDerivWithinAt (hf : HasLineDerivAt 𝕜 f f' x v) (s : Set E) : HasLineDerivWithinAt 𝕜 f f' s x v := HasDerivAt.hasDerivWithinAt hf lemma HasLineDerivWithinAt.lineDifferentiableWithinAt (hf : HasLineDerivWithinAt 𝕜 f f' s x v) : LineDifferentiableWithinAt 𝕜 f s x v := HasDerivWithinAt.differentiableWithinAt hf theorem HasLineDerivAt.lineDifferentiableAt (hf : HasLineDerivAt 𝕜 f f' x v) : LineDifferentiableAt 𝕜 f x v := HasDerivAt.differentiableAt hf theorem LineDifferentiableWithinAt.hasLineDerivWithinAt (h : LineDifferentiableWithinAt 𝕜 f s x v) : HasLineDerivWithinAt 𝕜 f (lineDerivWithin 𝕜 f s x v) s x v := DifferentiableWithinAt.hasDerivWithinAt h theorem LineDifferentiableAt.hasLineDerivAt (h : LineDifferentiableAt 𝕜 f x v) : HasLineDerivAt 𝕜 f (lineDeriv 𝕜 f x v) x v := DifferentiableAt.hasDerivAt h @[simp] lemma hasLineDerivWithinAt_univ : HasLineDerivWithinAt 𝕜 f f' univ x v ↔ HasLineDerivAt 𝕜 f f' x v := by simp only [HasLineDerivWithinAt, HasLineDerivAt, preimage_univ, hasDerivWithinAt_univ] theorem lineDerivWithin_zero_of_not_lineDifferentiableWithinAt (h : ¬LineDifferentiableWithinAt 𝕜 f s x v) : lineDerivWithin 𝕜 f s x v = 0 := derivWithin_zero_of_not_differentiableWithinAt h theorem lineDeriv_zero_of_not_lineDifferentiableAt (h : ¬LineDifferentiableAt 𝕜 f x v) : lineDeriv 𝕜 f x v = 0 := deriv_zero_of_not_differentiableAt h theorem hasLineDerivAt_iff_isLittleO_nhds_zero : HasLineDerivAt 𝕜 f f' x v ↔ (fun t : 𝕜 => f (x + t • v) - f x - t • f') =o[𝓝 0] fun t => t := by simp only [HasLineDerivAt, hasDerivAt_iff_isLittleO_nhds_zero, zero_add, zero_smul, add_zero] theorem HasLineDerivAt.unique (h₀ : HasLineDerivAt 𝕜 f f₀' x v) (h₁ : HasLineDerivAt 𝕜 f f₁' x v) : f₀' = f₁' := HasDerivAt.unique h₀ h₁ protected theorem HasLineDerivAt.lineDeriv (h : HasLineDerivAt 𝕜 f f' x v) : lineDeriv 𝕜 f x v = f' := by rw [h.unique h.lineDifferentiableAt.hasLineDerivAt] theorem lineDifferentiableWithinAt_univ : LineDifferentiableWithinAt 𝕜 f univ x v ↔ LineDifferentiableAt 𝕜 f x v := by simp only [LineDifferentiableWithinAt, LineDifferentiableAt, preimage_univ, differentiableWithinAt_univ] theorem LineDifferentiableAt.lineDifferentiableWithinAt (h : LineDifferentiableAt 𝕜 f x v) : LineDifferentiableWithinAt 𝕜 f s x v := (differentiableWithinAt_univ.2 h).mono (subset_univ _) @[simp] theorem lineDerivWithin_univ : lineDerivWithin 𝕜 f univ x v = lineDeriv 𝕜 f x v := by simp [lineDerivWithin, lineDeriv] theorem LineDifferentiableWithinAt.mono (h : LineDifferentiableWithinAt 𝕜 f t x v) (st : s ⊆ t) : LineDifferentiableWithinAt 𝕜 f s x v := (h.hasLineDerivWithinAt.mono st).lineDifferentiableWithinAt theorem HasLineDerivWithinAt.congr_mono (h : HasLineDerivWithinAt 𝕜 f f' s x v) (ht : EqOn f₁ f t) (hx : f₁ x = f x) (h₁ : t ⊆ s) : HasLineDerivWithinAt 𝕜 f₁ f' t x v := HasDerivWithinAt.congr_mono h (fun y hy ↩ ht hy) (by simpa using hx) (preimage_mono h₁) theorem HasLineDerivWithinAt.congr (h : HasLineDerivWithinAt 𝕜 f f' s x v) (hs : EqOn f₁ f s) (hx : f₁ x = f x) : HasLineDerivWithinAt 𝕜 f₁ f' s x v := h.congr_mono hs hx (Subset.refl _) theorem HasLineDerivWithinAt.congr' (h : HasLineDerivWithinAt 𝕜 f f' s x v) (hs : EqOn f₁ f s) (hx : x ∈ s) : HasLineDerivWithinAt 𝕜 f₁ f' s x v := h.congr hs (hs hx) theorem LineDifferentiableWithinAt.congr_mono (h : LineDifferentiableWithinAt 𝕜 f s x v) (ht : EqOn f₁ f t) (hx : f₁ x = f x) (h₁ : t ⊆ s) : LineDifferentiableWithinAt 𝕜 f₁ t x v := (HasLineDerivWithinAt.congr_mono h.hasLineDerivWithinAt ht hx h₁).differentiableWithinAt theorem LineDifferentiableWithinAt.congr (h : LineDifferentiableWithinAt 𝕜 f s x v) (ht : ∀ x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : LineDifferentiableWithinAt 𝕜 f₁ s x v := LineDifferentiableWithinAt.congr_mono h ht hx (Subset.refl _) theorem lineDerivWithin_congr (hs : EqOn f₁ f s) (hx : f₁ x = f x) : lineDerivWithin 𝕜 f₁ s x v = lineDerivWithin 𝕜 f s x v := derivWithin_congr (fun y hy ↩ hs hy) (by simpa using hx) theorem lineDerivWithin_congr' (hs : EqOn f₁ f s) (hx : x ∈ s) : lineDerivWithin 𝕜 f₁ s x v = lineDerivWithin 𝕜 f s x v := lineDerivWithin_congr hs (hs hx) theorem hasLineDerivAt_iff_tendsto_slope_zero : HasLineDerivAt 𝕜 f f' x v ↔ Tendsto (fun (t : 𝕜) ↩ t⁻¹ • (f (x + t • v) - f x)) (𝓝[≠] 0) (𝓝 f') := by simp only [HasLineDerivAt, hasDerivAt_iff_tendsto_slope_zero, zero_add, zero_smul, add_zero] alias ⟹HasLineDerivAt.tendsto_slope_zero, _⟩ := hasLineDerivAt_iff_tendsto_slope_zero theorem HasLineDerivAt.tendsto_slope_zero_right [PartialOrder 𝕜] (h : HasLineDerivAt 𝕜 f f' x v) : Tendsto (fun (t : 𝕜) ↩ t⁻¹ • (f (x + t • v) - f x)) (𝓝[>] 0) (𝓝 f') := h.tendsto_slope_zero.mono_left (nhds_right'_le_nhds_ne 0) theorem HasLineDerivAt.tendsto_slope_zero_left [PartialOrder 𝕜] (h : HasLineDerivAt 𝕜 f f' x v) : Tendsto (fun (t : 𝕜) ↩ t⁻¹ • (f (x + t • v) - f x)) (𝓝[<] 0) (𝓝 f') := h.tendsto_slope_zero.mono_left (nhds_left'_le_nhds_ne 0) theorem HasLineDerivWithinAt.hasLineDerivAt' (h : HasLineDerivWithinAt 𝕜 f f' s x v) (hs : ∀ᶠ t : 𝕜 in 𝓝 0, x + t • v ∈ s) : HasLineDerivAt 𝕜 f f' x v := h.hasDerivAt hs end Module section NormedSpace /-! Results that need a normed space structure on `E` -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {f f₀ f₁ : E → F} {f' : F} {s t : Set E} {x v : E} {L : E →L[𝕜] F} theorem HasLineDerivWithinAt.mono_of_mem (h : HasLineDerivWithinAt 𝕜 f f' t x v) (hst : t ∈ 𝓝[s] x) : HasLineDerivWithinAt 𝕜 f f' s x v := by apply HasDerivWithinAt.mono_of_mem h apply ContinuousWithinAt.preimage_mem_nhdsWithin'' _ hst (by simp) apply Continuous.continuousWithinAt; fun_prop theorem HasLineDerivWithinAt.hasLineDerivAt (h : HasLineDerivWithinAt 𝕜 f f' s x v) (hs : s ∈ 𝓝 x) : HasLineDerivAt 𝕜 f f' x v := h.hasLineDerivAt' <| (Continuous.tendsto' (by fun_prop) 0 _ (by simp)).eventually hs theorem LineDifferentiableWithinAt.lineDifferentiableAt (h : LineDifferentiableWithinAt 𝕜 f s x v) (hs : s ∈ 𝓝 x) : LineDifferentiableAt 𝕜 f x v := (h.hasLineDerivWithinAt.hasLineDerivAt hs).lineDifferentiableAt lemma HasFDerivWithinAt.hasLineDerivWithinAt (hf : HasFDerivWithinAt f L s x) (v : E) : HasLineDerivWithinAt 𝕜 f (L v) s x v := by let F := fun (t : 𝕜) ↩ x + t • v rw [show x = F (0 : 𝕜) by simp [F]] at hf have A : HasDerivWithinAt F (0 + (1 : 𝕜) • v) (F ⁻¹' s) 0 := ((hasDerivAt_const (0 : 𝕜) x).add ((hasDerivAt_id' (0 : 𝕜)).smul_const v)).hasDerivWithinAt simp only [one_smul, zero_add] at A exact hf.comp_hasDerivWithinAt (x := (0 : 𝕜)) A (mapsTo_preimage F s) lemma HasFDerivAt.hasLineDerivAt (hf : HasFDerivAt f L x) (v : E) : HasLineDerivAt 𝕜 f (L v) x v := by rw [← hasLineDerivWithinAt_univ] exact hf.hasFDerivWithinAt.hasLineDerivWithinAt v lemma DifferentiableAt.lineDeriv_eq_fderiv (hf : DifferentiableAt 𝕜 f x) : lineDeriv 𝕜 f x v = fderiv 𝕜 f x v := (hf.hasFDerivAt.hasLineDerivAt v).lineDeriv theorem LineDifferentiableWithinAt.mono_of_mem (h : LineDifferentiableWithinAt 𝕜 f s x v) (hst : s ∈ 𝓝[t] x) : LineDifferentiableWithinAt 𝕜 f t x v := (h.hasLineDerivWithinAt.mono_of_mem hst).lineDifferentiableWithinAt theorem lineDerivWithin_of_mem_nhds (h : s ∈ 𝓝 x) : lineDerivWithin 𝕜 f s x v = lineDeriv 𝕜 f x v := by apply derivWithin_of_mem_nhds apply (Continuous.continuousAt _).preimage_mem_nhds (by simpa using h) fun_prop theorem lineDerivWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) : lineDerivWithin 𝕜 f s x v = lineDeriv 𝕜 f x v := lineDerivWithin_of_mem_nhds (hs.mem_nhds hx) theorem hasLineDerivWithinAt_congr_set (h : s =á¶ [𝓝 x] t) : HasLineDerivWithinAt 𝕜 f f' s x v ↔ HasLineDerivWithinAt 𝕜 f f' t x v := by apply hasDerivWithinAt_congr_set let F := fun (t : 𝕜) ↩ x + t • v have B : ContinuousAt F 0 := by apply Continuous.continuousAt; fun_prop have : s =á¶ [𝓝 (F 0)] t := by convert h; simp [F] exact B.preimage_mem_nhds this theorem lineDifferentiableWithinAt_congr_set (h : s =á¶ [𝓝 x] t) : LineDifferentiableWithinAt 𝕜 f s x v ↔ LineDifferentiableWithinAt 𝕜 f t x v := ⟹fun h' ↩ ((hasLineDerivWithinAt_congr_set h).1 h'.hasLineDerivWithinAt).lineDifferentiableWithinAt, fun h' ↩ ((hasLineDerivWithinAt_congr_set h.symm).1 h'.hasLineDerivWithinAt).lineDifferentiableWithinAt⟩ theorem lineDerivWithin_congr_set (h : s =á¶ [𝓝 x] t) : lineDerivWithin 𝕜 f s x v = lineDerivWithin 𝕜 f t x v := by apply derivWithin_congr_set let F := fun (t : 𝕜) ↩ x + t • v have B : ContinuousAt F 0 := by apply Continuous.continuousAt; fun_prop have : s =á¶ [𝓝 (F 0)] t := by convert h; simp [F] exact B.preimage_mem_nhds this theorem Filter.EventuallyEq.hasLineDerivAt_iff (h : f₀ =á¶ [𝓝 x] f₁) : HasLineDerivAt 𝕜 f₀ f' x v ↔ HasLineDerivAt 𝕜 f₁ f' x v := by apply hasDerivAt_iff let F := fun (t : 𝕜) ↩ x + t • v have B : ContinuousAt F 0 := by apply Continuous.continuousAt; fun_prop have : f₀ =á¶ [𝓝 (F 0)] f₁ := by convert h; simp [F] exact B.preimage_mem_nhds this theorem Filter.EventuallyEq.lineDifferentiableAt_iff (h : f₀ =á¶ [𝓝 x] f₁) : LineDifferentiableAt 𝕜 f₀ x v ↔ LineDifferentiableAt 𝕜 f₁ x v := ⟹fun h' ↩ (h.hasLineDerivAt_iff.1 h'.hasLineDerivAt).lineDifferentiableAt, fun h' ↩ (h.hasLineDerivAt_iff.2 h'.hasLineDerivAt).lineDifferentiableAt⟩ theorem Filter.EventuallyEq.hasLineDerivWithinAt_iff (h : f₀ =á¶ [𝓝[s] x] f₁) (hx : f₀ x = f₁ x) : HasLineDerivWithinAt 𝕜 f₀ f' s x v ↔ HasLineDerivWithinAt 𝕜 f₁ f' s x v := by apply hasDerivWithinAt_iff · have A : Continuous (fun (t : 𝕜) ↩ x + t • v) := by fun_prop exact A.continuousWithinAt.preimage_mem_nhdsWithin'' h (by simp) · simpa using hx theorem Filter.EventuallyEq.hasLineDerivWithinAt_iff_of_mem (h : f₀ =á¶ [𝓝[s] x] f₁) (hx : x ∈ s) : HasLineDerivWithinAt 𝕜 f₀ f' s x v ↔ HasLineDerivWithinAt 𝕜 f₁ f' s x v := h.hasLineDerivWithinAt_iff (h.eq_of_nhdsWithin hx) theorem Filter.EventuallyEq.lineDifferentiableWithinAt_iff (h : f₀ =á¶ [𝓝[s] x] f₁) (hx : f₀ x = f₁ x) : LineDifferentiableWithinAt 𝕜 f₀ s x v ↔ LineDifferentiableWithinAt 𝕜 f₁ s x v := ⟹fun h' ↩ ((h.hasLineDerivWithinAt_iff hx).1 h'.hasLineDerivWithinAt).lineDifferentiableWithinAt, fun h' ↩ ((h.hasLineDerivWithinAt_iff hx).2 h'.hasLineDerivWithinAt).lineDifferentiableWithinAt⟩ theorem Filter.EventuallyEq.lineDifferentiableWithinAt_iff_of_mem (h : f₀ =á¶ [𝓝[s] x] f₁) (hx : x ∈ s) : LineDifferentiableWithinAt 𝕜 f₀ s x v ↔ LineDifferentiableWithinAt 𝕜 f₁ s x v := h.lineDifferentiableWithinAt_iff (h.eq_of_nhdsWithin hx) lemma HasLineDerivWithinAt.congr_of_eventuallyEq (hf : HasLineDerivWithinAt 𝕜 f f' s x v) (h'f : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) : HasLineDerivWithinAt 𝕜 f₁ f' s x v := by apply HasDerivWithinAt.congr_of_eventuallyEq hf _ (by simp [hx]) have A : Continuous (fun (t : 𝕜) ↩ x + t • v) := by fun_prop exact A.continuousWithinAt.preimage_mem_nhdsWithin'' h'f (by simp) theorem HasLineDerivAt.congr_of_eventuallyEq (h : HasLineDerivAt 𝕜 f f' x v) (h₁ : f₁ =á¶ [𝓝 x] f) : HasLineDerivAt 𝕜 f₁ f' x v := by apply HasDerivAt.congr_of_eventuallyEq h let F := fun (t : 𝕜) ↩ x + t • v rw [show x = F 0 by simp [F]] at h₁ exact (Continuous.continuousAt (by fun_prop)).preimage_mem_nhds h₁ theorem LineDifferentiableWithinAt.congr_of_eventuallyEq (h : LineDifferentiableWithinAt 𝕜 f s x v) (h₁ : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) : LineDifferentiableWithinAt 𝕜 f₁ s x v := (h.hasLineDerivWithinAt.congr_of_eventuallyEq h₁ hx).differentiableWithinAt theorem LineDifferentiableAt.congr_of_eventuallyEq (h : LineDifferentiableAt 𝕜 f x v) (hL : f₁ =á¶ [𝓝 x] f) : LineDifferentiableAt 𝕜 f₁ x v := by apply DifferentiableAt.congr_of_eventuallyEq h let F := fun (t : 𝕜) ↩ x + t • v rw [show x = F 0 by simp [F]] at hL exact (Continuous.continuousAt (by fun_prop)).preimage_mem_nhds hL theorem Filter.EventuallyEq.lineDerivWithin_eq (hs : f₁ =á¶ [𝓝[s] x] f) (hx : f₁ x = f x) : lineDerivWithin 𝕜 f₁ s x v = lineDerivWithin 𝕜 f s x v := by apply derivWithin_eq ?_ (by simpa using hx) have A : Continuous (fun (t : 𝕜) ↩ x + t • v) := by fun_prop exact A.continuousWithinAt.preimage_mem_nhdsWithin'' hs (by simp) theorem Filter.EventuallyEq.lineDerivWithin_eq_nhds (h : f₁ =á¶ [𝓝 x] f) : lineDerivWithin 𝕜 f₁ s x v = lineDerivWithin 𝕜 f s x v := (h.filter_mono nhdsWithin_le_nhds).lineDerivWithin_eq h.self_of_nhds theorem Filter.EventuallyEq.lineDeriv_eq (h : f₁ =á¶ [𝓝 x] f) : lineDeriv 𝕜 f₁ x v = lineDeriv 𝕜 f x v := by rw [← lineDerivWithin_univ, ← lineDerivWithin_univ, h.lineDerivWithin_eq_nhds] /-- Converse to the mean value inequality: if `f` is line differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then its line derivative at `x₀` in the direction `v` has norm bounded by `C * ‖v‖`. This version only assumes that `‖f x - f x₀‖ ≀ C * ‖x - x₀‖` in a neighborhood of `x`. -/ theorem HasLineDerivAt.le_of_lip' {f : E → F} {f' : F} {x₀ : E} (hf : HasLineDerivAt 𝕜 f f' x₀ v) {C : ℝ} (hC₀ : 0 ≀ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≀ C * ‖x - x₀‖) : ‖f'‖ ≀ C * ‖v‖ := by apply HasDerivAt.le_of_lip' hf (by positivity) have A : Continuous (fun (t : 𝕜) ↩ x₀ + t • v) := by fun_prop have : ∀ᶠ x in 𝓝 (x₀ + (0 : 𝕜) • v), ‖f x - f x₀‖ ≀ C * ‖x - x₀‖ := by simpa using hlip filter_upwards [(A.continuousAt (x := 0)).preimage_mem_nhds this] with t ht simp only [preimage_setOf_eq, add_sub_cancel_left, norm_smul, mem_setOf_eq, mul_comm (‖t‖)] at ht simpa [mul_assoc] using ht /-- Converse to the mean value inequality: if `f` is line differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then its line derivative at `x₀` in the direction `v` has norm bounded by `C * ‖v‖`. This version only assumes that `‖f x - f x₀‖ ≀ C * ‖x - x₀‖` in a neighborhood of `x`. -/ theorem HasLineDerivAt.le_of_lipschitzOn {f : E → F} {f' : F} {x₀ : E} (hf : HasLineDerivAt 𝕜 f f' x₀ v) {s : Set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖f'‖ ≀ C * ‖v‖ := by refine hf.le_of_lip' C.coe_nonneg ?_ filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs) /-- Converse to the mean value inequality: if `f` is line differentiable at `x₀` and `C`-lipschitz then its line derivative at `x₀` in the direction `v` has norm bounded by `C * ‖v‖`. -/ theorem HasLineDerivAt.le_of_lipschitz {f : E → F} {f' : F} {x₀ : E} (hf : HasLineDerivAt 𝕜 f f' x₀ v) {C : ℝ≥0} (hlip : LipschitzWith C f) : ‖f'‖ ≀ C * ‖v‖ := hf.le_of_lipschitzOn univ_mem (lipschitzOnWith_univ.2 hlip) variable (𝕜) /-- Converse to the mean value inequality: if `f` is `C`-lipschitz on a neighborhood of `x₀` then its line derivative at `x₀` in the direction `v` has norm bounded by `C * ‖v‖`. This version only assumes that `‖f x - f x₀‖ ≀ C * ‖x - x₀‖` in a neighborhood of `x`. Version using `lineDeriv`. -/ theorem norm_lineDeriv_le_of_lip' {f : E → F} {x₀ : E} {C : ℝ} (hC₀ : 0 ≀ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≀ C * ‖x - x₀‖) : ‖lineDeriv 𝕜 f x₀ v‖ ≀ C * ‖v‖ := by apply norm_deriv_le_of_lip' (by positivity) have A : Continuous (fun (t : 𝕜) ↩ x₀ + t • v) := by fun_prop have : ∀ᶠ x in 𝓝 (x₀ + (0 : 𝕜) • v), ‖f x - f x₀‖ ≀ C * ‖x - x₀‖ := by simpa using hlip filter_upwards [(A.continuousAt (x := 0)).preimage_mem_nhds this] with t ht simp only [preimage_setOf_eq, add_sub_cancel_left, norm_smul, mem_setOf_eq, mul_comm (‖t‖)] at ht simpa [mul_assoc] using ht /-- Converse to the mean value inequality: if `f` is `C`-lipschitz on a neighborhood of `x₀` then its line derivative at `x₀` in the direction `v` has norm bounded by `C * ‖v‖`. Version using `lineDeriv`. -/ theorem norm_lineDeriv_le_of_lipschitzOn {f : E → F} {x₀ : E} {s : Set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖lineDeriv 𝕜 f x₀ v‖ ≀ C * ‖v‖ := by refine norm_lineDeriv_le_of_lip' 𝕜 C.coe_nonneg ?_ filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs) /-- Converse to the mean value inequality: if `f` is `C`-lipschitz then its line derivative at `x₀` in the direction `v` has norm bounded by `C * ‖v‖`. Version using `lineDeriv`. -/ theorem norm_lineDeriv_le_of_lipschitz {f : E → F} {x₀ : E} {C : ℝ≥0} (hlip : LipschitzWith C f) : ‖lineDeriv 𝕜 f x₀ v‖ ≀ C * ‖v‖ := norm_lineDeriv_le_of_lipschitzOn 𝕜 univ_mem (lipschitzOnWith_univ.2 hlip) variable {𝕜} end NormedSpace section Zero variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] {f : E → F} {s : Set E} {x : E} theorem hasLineDerivWithinAt_zero : HasLineDerivWithinAt 𝕜 f 0 s x 0 := by simp [HasLineDerivWithinAt, hasDerivWithinAt_const] theorem hasLineDerivAt_zero : HasLineDerivAt 𝕜 f 0 x 0 := by simp [HasLineDerivAt, hasDerivAt_const] theorem lineDifferentiableWithinAt_zero : LineDifferentiableWithinAt 𝕜 f s x 0 := hasLineDerivWithinAt_zero.lineDifferentiableWithinAt theorem lineDifferentiableAt_zero : LineDifferentiableAt 𝕜 f x 0 := hasLineDerivAt_zero.lineDifferentiableAt theorem lineDeriv_zero : lineDeriv 𝕜 f x 0 = 0 := hasLineDerivAt_zero.lineDeriv end Zero section CompRight variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] {E' : Type*} [AddCommGroup E'] [Module 𝕜 E'] {f : E → F} {f' : F} {x v : E'} {L : E' →ₗ[𝕜] E} theorem HasLineDerivAt.of_comp {v : E'} (hf : HasLineDerivAt 𝕜 (f ∘ L) f' x v) : HasLineDerivAt 𝕜 f f' (L x) (L v) := by simpa [HasLineDerivAt] using hf theorem LineDifferentiableAt.of_comp {v : E'} (hf : LineDifferentiableAt 𝕜 (f ∘ L) x v) : LineDifferentiableAt 𝕜 f (L x) (L v) := hf.hasLineDerivAt.of_comp.lineDifferentiableAt end CompRight section SMul variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] {f : E → F} {s : Set E} {x v : E} {f' : F} theorem HasLineDerivWithinAt.smul (h : HasLineDerivWithinAt 𝕜 f f' s x v) (c : 𝕜) : HasLineDerivWithinAt 𝕜 f (c • f') s x (c • v) := by simp only [HasLineDerivWithinAt] at h ⊢ let g := fun (t : 𝕜) ↩ c • t let s' := (fun (t : 𝕜) ↩ x + t • v) ⁻¹' s have A : HasDerivAt g c 0 := by simpa using (hasDerivAt_id (0 : 𝕜)).const_smul c have B : HasDerivWithinAt (fun t ↩ f (x + t • v)) f' s' (g 0) := by simpa [g] using h have Z := B.scomp (0 : 𝕜) A.hasDerivWithinAt (mapsTo_preimage g s') simp only [g, s', Function.comp, smul_eq_mul, mul_comm c, ← smul_smul] at Z convert Z ext t simp [← smul_smul] theorem hasLineDerivWithinAt_smul_iff {c : 𝕜} (hc : c ≠ 0) : HasLineDerivWithinAt 𝕜 f (c • f') s x (c • v) ↔ HasLineDerivWithinAt 𝕜 f f' s x v := ⟹fun h ↩ by simpa [smul_smul, inv_mul_cancel hc] using h.smul (c ⁻¹), fun h ↩ h.smul c⟩ theorem HasLineDerivAt.smul (h : HasLineDerivAt 𝕜 f f' x v) (c : 𝕜) : HasLineDerivAt 𝕜 f (c • f') x (c • v) := by simp only [← hasLineDerivWithinAt_univ] at h ⊢ exact HasLineDerivWithinAt.smul h c theorem hasLineDerivAt_smul_iff {c : 𝕜} (hc : c ≠ 0) : HasLineDerivAt 𝕜 f (c • f') x (c • v) ↔ HasLineDerivAt 𝕜 f f' x v := ⟹fun h ↩ by simpa [smul_smul, inv_mul_cancel hc] using h.smul (c ⁻¹), fun h ↩ h.smul c⟩ theorem LineDifferentiableWithinAt.smul (h : LineDifferentiableWithinAt 𝕜 f s x v) (c : 𝕜) : LineDifferentiableWithinAt 𝕜 f s x (c • v) := (h.hasLineDerivWithinAt.smul c).lineDifferentiableWithinAt theorem lineDifferentiableWithinAt_smul_iff {c : 𝕜} (hc : c ≠ 0) : LineDifferentiableWithinAt 𝕜 f s x (c • v) ↔ LineDifferentiableWithinAt 𝕜 f s x v := ⟹fun h ↩ by simpa [smul_smul, inv_mul_cancel hc] using h.smul (c ⁻¹), fun h ↩ h.smul c⟩ theorem LineDifferentiableAt.smul (h : LineDifferentiableAt 𝕜 f x v) (c : 𝕜) : LineDifferentiableAt 𝕜 f x (c • v) := (h.hasLineDerivAt.smul c).lineDifferentiableAt theorem lineDifferentiableAt_smul_iff {c : 𝕜} (hc : c ≠ 0) : LineDifferentiableAt 𝕜 f x (c • v) ↔ LineDifferentiableAt 𝕜 f x v := ⟹fun h ↩ by simpa [smul_smul, inv_mul_cancel hc] using h.smul (c ⁻¹), fun h ↩ h.smul c⟩ theorem lineDeriv_smul {c : 𝕜} : lineDeriv 𝕜 f x (c • v) = c • lineDeriv 𝕜 f x v := by rcases eq_or_ne c 0 with rfl|hc · simp [lineDeriv_zero] by_cases H : LineDifferentiableAt 𝕜 f x v · exact (H.hasLineDerivAt.smul c).lineDeriv · have H' : ¬ (LineDifferentiableAt 𝕜 f x (c • v)) := by simpa [lineDifferentiableAt_smul_iff hc] using H simp [lineDeriv_zero_of_not_lineDifferentiableAt, H, H'] theorem lineDeriv_neg : lineDeriv 𝕜 f x (-v) = - lineDeriv 𝕜 f x v := by rw [← neg_one_smul (R := 𝕜) v, lineDeriv_smul, neg_one_smul] end SMul
Analysis\Calculus\LineDeriv\IntegrationByParts.lean
/- Copyright (c) 2024 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.LineDeriv.Basic import Mathlib.MeasureTheory.Integral.IntegralEqImproper /-! # Integration by parts for line derivatives Let `f, g : E → ℝ` be two differentiable functions on a real vector space endowed with a Haar measure. Then `∫ f * g' = - ∫ f' * g`, where `f'` and `g'` denote the derivatives of `f` and `g` in a given direction `v`, provided that `f * g`, `f' * g` and `f * g'` are all integrable. In this file, we prove this theorem as well as more general versions where the multiplication is replaced by a general continuous bilinear form, giving versions both for the line derivative and the Fréchet derivative. These results are derived from the one-dimensional version and a Fubini argument. ## Main statements * `integral_bilinear_hasLineDerivAt_right_eq_neg_left_of_integrable`: integration by parts in terms of line derivatives, with `HasLineDerivAt` assumptions and general bilinear form. * `integral_bilinear_hasFDerivAt_right_eq_neg_left_of_integrable`: integration by parts in terms of Fréchet derivatives, with `HasFDerivAt` assumptions and general bilinear form. * `integral_bilinear_fderiv_right_eq_neg_left_of_integrable`: integration by parts in terms of Fréchet derivatives, written with `fderiv` assumptions and general bilinear form. * `integral_smul_fderiv_eq_neg_fderiv_smul_of_integrable`: integration by parts for scalar action, in terms of Fréchet derivatives, written with `fderiv` assumptions. * `integral_mul_fderiv_eq_neg_fderiv_mul_of_integrable`: integration by parts for scalar multiplication, in terms of Fréchet derivatives, written with `fderiv` assumptions. ## Implementation notes A standard set of assumptions for integration by parts in a finite-dimensional real vector space (without boundary term) is that the functions tend to zero at infinity and have integrable derivatives. In this file, we instead assume that the functions are integrable and have integrable derivatives. These sets of assumptions are not directly comparable (an integrable function with integrable derivative does *not* have to tend to zero at infinity). The one we use is geared towards applications to Fourier transforms. TODO: prove similar theorems assuming that the functions tend to zero at infinity and have integrable derivatives. -/ open MeasureTheory Measure FiniteDimensional variable {E F G W : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup G] [NormedSpace ℝ G] [NormedAddCommGroup W] [NormedSpace ℝ W] [MeasurableSpace E] [BorelSpace E] {ÎŒ : Measure E} lemma integral_bilinear_hasLineDerivAt_right_eq_neg_left_of_integrable_aux1 [SigmaFinite ÎŒ] {f f' : E × ℝ → F} {g g' : E × ℝ → G} {B : F →L[ℝ] G →L[ℝ] W} (hf'g : Integrable (fun x ↩ B (f' x) (g x)) (ÎŒ.prod volume)) (hfg' : Integrable (fun x ↩ B (f x) (g' x)) (ÎŒ.prod volume)) (hfg : Integrable (fun x ↩ B (f x) (g x)) (ÎŒ.prod volume)) (hf : ∀ x, HasLineDerivAt ℝ f (f' x) x (0, 1)) (hg : ∀ x, HasLineDerivAt ℝ g (g' x) x (0, 1)) : ∫ x, B (f x) (g' x) ∂(ÎŒ.prod volume) = - ∫ x, B (f' x) (g x) ∂(ÎŒ.prod volume) := calc ∫ x, B (f x) (g' x) ∂(ÎŒ.prod volume) = ∫ x, (∫ t, B (f (x, t)) (g' (x, t))) ∂Ό := integral_prod _ hfg' _ = ∫ x, (- ∫ t, B (f' (x, t)) (g (x, t))) ∂Ό := by apply integral_congr_ae filter_upwards [hf'g.prod_right_ae, hfg'.prod_right_ae, hfg.prod_right_ae] with x hf'gx hfg'x hfgx apply integral_bilinear_hasDerivAt_right_eq_neg_left_of_integrable ?_ ?_ hfg'x hf'gx hfgx · intro t convert (hf (x, t)).scomp_of_eq t ((hasDerivAt_id t).add (hasDerivAt_const t (-t))) (by simp) <;> simp · intro t convert (hg (x, t)).scomp_of_eq t ((hasDerivAt_id t).add (hasDerivAt_const t (-t))) (by simp) <;> simp _ = - ∫ x, B (f' x) (g x) ∂(ÎŒ.prod volume) := by rw [integral_neg, integral_prod _ hf'g] lemma integral_bilinear_hasLineDerivAt_right_eq_neg_left_of_integrable_aux2 [FiniteDimensional ℝ E] {ÎŒ : Measure (E × ℝ)} [IsAddHaarMeasure ÎŒ] {f f' : E × ℝ → F} {g g' : E × ℝ → G} {B : F →L[ℝ] G →L[ℝ] W} (hf'g : Integrable (fun x ↩ B (f' x) (g x)) ÎŒ) (hfg' : Integrable (fun x ↩ B (f x) (g' x)) ÎŒ) (hfg : Integrable (fun x ↩ B (f x) (g x)) ÎŒ) (hf : ∀ x, HasLineDerivAt ℝ f (f' x) x (0, 1)) (hg : ∀ x, HasLineDerivAt ℝ g (g' x) x (0, 1)) : ∫ x, B (f x) (g' x) ∂Ό = - ∫ x, B (f' x) (g x) ∂Ό := by let Μ : Measure E := addHaar have A : Μ.prod volume = (addHaarScalarFactor (Μ.prod volume) ÎŒ) • ÎŒ := isAddLeftInvariant_eq_smul _ _ have Hf'g : Integrable (fun x ↩ B (f' x) (g x)) (Μ.prod volume) := by rw [A]; exact hf'g.smul_measure_nnreal have Hfg' : Integrable (fun x ↩ B (f x) (g' x)) (Μ.prod volume) := by rw [A]; exact hfg'.smul_measure_nnreal have Hfg : Integrable (fun x ↩ B (f x) (g x)) (Μ.prod volume) := by rw [A]; exact hfg.smul_measure_nnreal rw [isAddLeftInvariant_eq_smul ÎŒ (Μ.prod volume)] simp [integral_bilinear_hasLineDerivAt_right_eq_neg_left_of_integrable_aux1 Hf'g Hfg' Hfg hf hg] variable [FiniteDimensional ℝ E] [IsAddHaarMeasure ÎŒ] /-- **Integration by parts for line derivatives** Version with a general bilinear form `B`. If `B f g` is integrable, as well as `B f' g` and `B f g'` where `f'` and `g'` are derivatives of `f` and `g` in a given direction `v`, then `∫ B f g' = - ∫ B f' g`. -/ theorem integral_bilinear_hasLineDerivAt_right_eq_neg_left_of_integrable {f f' : E → F} {g g' : E → G} {v : E} {B : F →L[ℝ] G →L[ℝ] W} (hf'g : Integrable (fun x ↩ B (f' x) (g x)) ÎŒ) (hfg' : Integrable (fun x ↩ B (f x) (g' x)) ÎŒ) (hfg : Integrable (fun x ↩ B (f x) (g x)) ÎŒ) (hf : ∀ x, HasLineDerivAt ℝ f (f' x) x v) (hg : ∀ x, HasLineDerivAt ℝ g (g' x) x v) : ∫ x, B (f x) (g' x) ∂Ό = - ∫ x, B (f' x) (g x) ∂Ό := by by_cases hW : CompleteSpace W; swap · simp [integral, hW] rcases eq_or_ne v 0 with rfl|hv · have Hf' x : f' x = 0 := by simpa [(hasLineDerivAt_zero (f := f) (x := x)).lineDeriv] using (hf x).lineDeriv.symm have Hg' x : g' x = 0 := by simpa [(hasLineDerivAt_zero (f := g) (x := x)).lineDeriv] using (hg x).lineDeriv.symm simp [Hf', Hg'] have : Nontrivial E := nontrivial_iff.2 ⟹v, 0, hv⟩ let n := finrank ℝ E let E' := Fin (n - 1) → ℝ obtain ⟹L, hL⟩ : ∃ L : E ≃L[ℝ] (E' × ℝ), L v = (0, 1) := by have : finrank ℝ (E' × ℝ) = n := by simpa [this, E'] using Nat.sub_add_cancel finrank_pos have L₀ : E ≃L[ℝ] (E' × ℝ) := (ContinuousLinearEquiv.ofFinrankEq this).symm obtain ⟹M, hM⟩ : ∃ M : (E' × ℝ) ≃L[ℝ] (E' × ℝ), M (L₀ v) = (0, 1) := by apply SeparatingDual.exists_continuousLinearEquiv_apply_eq · simpa using hv · simp exact ⟹L₀.trans M, by simp [hM]⟩ let Μ := Measure.map L ÎŒ suffices H : ∫ (x : E' × ℝ), (B (f (L.symm x))) (g' (L.symm x)) ∂Μ = -∫ (x : E' × ℝ), (B (f' (L.symm x))) (g (L.symm x)) ∂Μ by have : ÎŒ = Measure.map L.symm Μ := by simp [Measure.map_map L.symm.continuous.measurable L.continuous.measurable] have hL : ClosedEmbedding L.symm := L.symm.toHomeomorph.closedEmbedding simpa [this, hL.integral_map] using H have L_emb : MeasurableEmbedding L := L.toHomeomorph.measurableEmbedding apply integral_bilinear_hasLineDerivAt_right_eq_neg_left_of_integrable_aux2 · simpa [L_emb.integrable_map_iff, Function.comp] using hf'g · simpa [L_emb.integrable_map_iff, Function.comp] using hfg' · simpa [L_emb.integrable_map_iff, Function.comp] using hfg · intro x have : f = (f ∘ L.symm) ∘ (L : E →ₗ[ℝ] (E' × ℝ)) := by ext y; simp specialize hf (L.symm x) rw [this] at hf convert hf.of_comp using 1 · simp · simp [← hL] · intro x have : g = (g ∘ L.symm) ∘ (L : E →ₗ[ℝ] (E' × ℝ)) := by ext y; simp specialize hg (L.symm x) rw [this] at hg convert hg.of_comp using 1 · simp · simp [← hL] /-- **Integration by parts for Fréchet derivatives** Version with a general bilinear form `B`. If `B f g` is integrable, as well as `B f' g` and `B f g'` where `f'` and `g'` are derivatives of `f` and `g` in a given direction `v`, then `∫ B f g' = - ∫ B f' g`. -/ theorem integral_bilinear_hasFDerivAt_right_eq_neg_left_of_integrable {f : E → F} {f' : E → (E →L[ℝ] F)} {g : E → G} {g' : E → (E →L[ℝ] G)} {v : E} {B : F →L[ℝ] G →L[ℝ] W} (hf'g : Integrable (fun x ↩ B (f' x v) (g x)) ÎŒ) (hfg' : Integrable (fun x ↩ B (f x) (g' x v)) ÎŒ) (hfg : Integrable (fun x ↩ B (f x) (g x)) ÎŒ) (hf : ∀ x, HasFDerivAt f (f' x) x) (hg : ∀ x, HasFDerivAt g (g' x) x) : ∫ x, B (f x) (g' x v) ∂Ό = - ∫ x, B (f' x v) (g x) ∂Ό := integral_bilinear_hasLineDerivAt_right_eq_neg_left_of_integrable hf'g hfg' hfg (fun x ↩ (hf x).hasLineDerivAt v) (fun x ↩ (hg x).hasLineDerivAt v) /-- **Integration by parts for Fréchet derivatives** Version with a general bilinear form `B`. If `B f g` is integrable, as well as `B f' g` and `B f g'` where `f'` and `g'` are the derivatives of `f` and `g` in a given direction `v`, then `∫ B f g' = - ∫ B f' g`. -/ theorem integral_bilinear_fderiv_right_eq_neg_left_of_integrable {f : E → F} {g : E → G} {v : E} {B : F →L[ℝ] G →L[ℝ] W} (hf'g : Integrable (fun x ↩ B (fderiv ℝ f x v) (g x)) ÎŒ) (hfg' : Integrable (fun x ↩ B (f x) (fderiv ℝ g x v)) ÎŒ) (hfg : Integrable (fun x ↩ B (f x) (g x)) ÎŒ) (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) : ∫ x, B (f x) (fderiv ℝ g x v) ∂Ό = - ∫ x, B (fderiv ℝ f x v) (g x) ∂Ό := integral_bilinear_hasFDerivAt_right_eq_neg_left_of_integrable hf'g hfg' hfg (fun x ↩ (hf x).hasFDerivAt) (fun x ↩ (hg x).hasFDerivAt) variable {𝕜 : Type*} [NormedField 𝕜] [NormedAlgebra ℝ 𝕜] [NormedSpace 𝕜 G] [IsScalarTower ℝ 𝕜 G] /-- **Integration by parts for Fréchet derivatives** Version with a scalar function: `∫ f • g' = - ∫ f' • g` when `f • g'` and `f' • g` and `f • g` are integrable, where `f'` and `g'` are the derivatives of `f` and `g` in a given direction `v`. -/ theorem integral_smul_fderiv_eq_neg_fderiv_smul_of_integrable {f : E → 𝕜} {g : E → G} {v : E} (hf'g : Integrable (fun x ↩ fderiv ℝ f x v • g x) ÎŒ) (hfg' : Integrable (fun x ↩ f x • fderiv ℝ g x v) ÎŒ) (hfg : Integrable (fun x ↩ f x • g x) ÎŒ) (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) : ∫ x, f x • fderiv ℝ g x v ∂Ό = - ∫ x, fderiv ℝ f x v • g x ∂Ό := integral_bilinear_fderiv_right_eq_neg_left_of_integrable (B := ContinuousLinearMap.lsmul ℝ 𝕜) hf'g hfg' hfg hf hg /-- **Integration by parts for Fréchet derivatives** Version with two scalar functions: `∫ f * g' = - ∫ f' * g` when `f * g'` and `f' * g` and `f * g` are integrable, where `f'` and `g'` are the derivatives of `f` and `g` in a given direction `v`. -/ theorem integral_mul_fderiv_eq_neg_fderiv_mul_of_integrable {f : E → 𝕜} {g : E → 𝕜} {v : E} (hf'g : Integrable (fun x ↩ fderiv ℝ f x v * g x) ÎŒ) (hfg' : Integrable (fun x ↩ f x * fderiv ℝ g x v) ÎŒ) (hfg : Integrable (fun x ↩ f x * g x) ÎŒ) (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) : ∫ x, f x * fderiv ℝ g x v ∂Ό = - ∫ x, fderiv ℝ f x v * g x ∂Ό := integral_bilinear_fderiv_right_eq_neg_left_of_integrable (B := ContinuousLinearMap.mul ℝ 𝕜) hf'g hfg' hfg hf hg
Analysis\Calculus\LineDeriv\Measurable.lean
/- Copyright (c) 2023 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.LineDeriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Measurable /-! # Measurability of the line derivative We prove in `measurable_lineDeriv` that the line derivative of a function (with respect to a locally compact scalar field) is measurable, provided the function is continuous. In `measurable_lineDeriv_uncurry`, assuming additionally that the source space is second countable, we show that `(x, v) ↩ lineDeriv 𝕜 f x v` is also measurable. An assumption such as continuity is necessary, as otherwise one could alternate in a non-measurable way between differentiable and non-differentiable functions along the various lines directed by `v`. -/ open MeasureTheory variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] [LocallyCompactSpace 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [MeasurableSpace E] [OpensMeasurableSpace E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F] {f : E → F} {v : E} /-! Measurability of the line derivative `lineDeriv 𝕜 f x v` with respect to a fixed direction `v`. -/ theorem measurableSet_lineDifferentiableAt (hf : Continuous f) : MeasurableSet {x : E | LineDifferentiableAt 𝕜 f x v} := by borelize 𝕜 let g : E → 𝕜 → F := fun x t ↩ f (x + t • v) have hg : Continuous g.uncurry := by fun_prop exact measurable_prod_mk_right (measurableSet_of_differentiableAt_with_param 𝕜 hg) theorem measurable_lineDeriv [MeasurableSpace F] [BorelSpace F] (hf : Continuous f) : Measurable (fun x ↩ lineDeriv 𝕜 f x v) := by borelize 𝕜 let g : E → 𝕜 → F := fun x t ↩ f (x + t • v) have hg : Continuous g.uncurry := by fun_prop exact (measurable_deriv_with_param hg).comp measurable_prod_mk_right theorem stronglyMeasurable_lineDeriv [SecondCountableTopologyEither E F] (hf : Continuous f) : StronglyMeasurable (fun x ↩ lineDeriv 𝕜 f x v) := by borelize 𝕜 let g : E → 𝕜 → F := fun x t ↩ f (x + t • v) have hg : Continuous g.uncurry := by fun_prop exact (stronglyMeasurable_deriv_with_param hg).comp_measurable measurable_prod_mk_right theorem aemeasurable_lineDeriv [MeasurableSpace F] [BorelSpace F] (hf : Continuous f) (ÎŒ : Measure E) : AEMeasurable (fun x ↩ lineDeriv 𝕜 f x v) ÎŒ := (measurable_lineDeriv hf).aemeasurable theorem aestronglyMeasurable_lineDeriv [SecondCountableTopologyEither E F] (hf : Continuous f) (ÎŒ : Measure E) : AEStronglyMeasurable (fun x ↩ lineDeriv 𝕜 f x v) ÎŒ := (stronglyMeasurable_lineDeriv hf).aestronglyMeasurable /-! Measurability of the line derivative `lineDeriv 𝕜 f x v` when varying both `x` and `v`. For this, we need an additional second countability assumption on `E` to make sure that open sets are measurable in `E × E`. -/ variable [SecondCountableTopology E] theorem measurableSet_lineDifferentiableAt_uncurry (hf : Continuous f) : MeasurableSet {p : E × E | LineDifferentiableAt 𝕜 f p.1 p.2} := by borelize 𝕜 let g : (E × E) → 𝕜 → F := fun p t ↩ f (p.1 + t • p.2) have : Continuous g.uncurry := hf.comp <| (continuous_fst.comp continuous_fst).add <| continuous_snd.smul (continuous_snd.comp continuous_fst) have M_meas : MeasurableSet {q : (E × E) × 𝕜 | DifferentiableAt 𝕜 (g q.1) q.2} := measurableSet_of_differentiableAt_with_param 𝕜 this exact measurable_prod_mk_right M_meas theorem measurable_lineDeriv_uncurry [MeasurableSpace F] [BorelSpace F] (hf : Continuous f) : Measurable (fun (p : E × E) ↩ lineDeriv 𝕜 f p.1 p.2) := by borelize 𝕜 let g : (E × E) → 𝕜 → F := fun p t ↩ f (p.1 + t • p.2) have : Continuous g.uncurry := hf.comp <| (continuous_fst.comp continuous_fst).add <| continuous_snd.smul (continuous_snd.comp continuous_fst) exact (measurable_deriv_with_param this).comp measurable_prod_mk_right theorem stronglyMeasurable_lineDeriv_uncurry (hf : Continuous f) : StronglyMeasurable (fun (p : E × E) ↩ lineDeriv 𝕜 f p.1 p.2) := by borelize 𝕜 let g : (E × E) → 𝕜 → F := fun p t ↩ f (p.1 + t • p.2) have : Continuous g.uncurry := hf.comp <| (continuous_fst.comp continuous_fst).add <| continuous_snd.smul (continuous_snd.comp continuous_fst) exact (stronglyMeasurable_deriv_with_param this).comp_measurable measurable_prod_mk_right theorem aemeasurable_lineDeriv_uncurry [MeasurableSpace F] [BorelSpace F] (hf : Continuous f) (ÎŒ : Measure (E × E)) : AEMeasurable (fun (p : E × E) ↩ lineDeriv 𝕜 f p.1 p.2) ÎŒ := (measurable_lineDeriv_uncurry hf).aemeasurable theorem aestronglyMeasurable_lineDeriv_uncurry (hf : Continuous f) (ÎŒ : Measure (E × E)) : AEStronglyMeasurable (fun (p : E × E) ↩ lineDeriv 𝕜 f p.1 p.2) ÎŒ := (stronglyMeasurable_lineDeriv_uncurry hf).aestronglyMeasurable
Analysis\Calculus\LineDeriv\QuadraticMap.lean
/- Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.LineDeriv.Basic import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.LinearAlgebra.QuadraticForm.Basic /-! # Quadratic forms are line (Gateaux) differentiable In this file we prove that a quadratic form is line differentiable, with the line derivative given by the polar bilinear form. Note that this statement does not need topology on the domain. In particular, it applies to discontinuous quadratic forms on infinite dimensional spaces. -/ variable {𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] namespace QuadraticMap theorem hasLineDerivAt (f : QuadraticMap 𝕜 E F) (a b : E) : HasLineDerivAt 𝕜 f (polar f a b) a b := by simpa [HasLineDerivAt, QuadraticMap.map_add, f.map_smul] using ((hasDerivAt_const (0 : 𝕜) (f a)).add <| ((hasDerivAt_id 0).mul (hasDerivAt_id 0)).smul (hasDerivAt_const 0 (f b))).add ((hasDerivAt_id 0).smul (hasDerivAt_const 0 (polar f a b))) theorem lineDifferentiableAt (f : QuadraticMap 𝕜 E F) (a b : E) : LineDifferentiableAt 𝕜 f a b := (f.hasLineDerivAt a b).lineDifferentiableAt @[simp] protected theorem lineDeriv (f : QuadraticMap 𝕜 E F) : lineDeriv 𝕜 f = polar f := by ext a b exact (f.hasLineDerivAt a b).lineDeriv end QuadraticMap
Analysis\Calculus\LocalExtr\Basic.lean
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Add /-! # Local extrema of differentiable functions ## Main definitions In a real normed space `E` we define `posTangentConeAt (s : Set E) (x : E)`. This would be the same as `tangentConeAt ℝ≥0 s x` if we had a theory of normed semifields. This set is used in the proof of Fermat's Theorem (see below), and can be used to formalize [Lagrange multipliers](https://en.wikipedia.org/wiki/Lagrange_multiplier) and/or [Karush–Kuhn–Tucker conditions](https://en.wikipedia.org/wiki/Karush–Kuhn–Tucker_conditions). ## Main statements For each theorem name listed below, we also prove similar theorems for `min`, `extr` (if applicable), and `fderiv`/`deriv` instead of `HasFDerivAt`/`HasDerivAt`. * `IsLocalMaxOn.hasFDerivWithinAt_nonpos` : `f' y ≀ 0` whenever `a` is a local maximum of `f` on `s`, `f` has derivative `f'` at `a` within `s`, and `y` belongs to the positive tangent cone of `s` at `a`. * `IsLocalMaxOn.hasFDerivWithinAt_eq_zero` : In the settings of the previous theorem, if both `y` and `-y` belong to the positive tangent cone, then `f' y = 0`. * `IsLocalMax.hasFDerivAt_eq_zero` : [Fermat's Theorem](https://en.wikipedia.org/wiki/Fermat's_theorem_(stationary_points)), the derivative of a differentiable function at a local extremum point equals zero. ## Implementation notes For each mathematical fact we prove several versions of its formalization: * for maxima and minima; * using `HasFDeriv*`/`HasDeriv*` or `fderiv*`/`deriv*`. For the `fderiv*`/`deriv*` versions we omit the differentiability condition whenever it is possible due to the fact that `fderiv` and `deriv` are defined to be zero for non-differentiable functions. ## References * [Fermat's Theorem](https://en.wikipedia.org/wiki/Fermat's_theorem_(stationary_points)); * [Tangent cone](https://en.wikipedia.org/wiki/Tangent_cone); ## Tags local extremum, tangent cone, Fermat's Theorem -/ universe u v open Filter Set open scoped Topology Convex section Module variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ} {s : Set E} {a x y : E} /-! ### Positive tangent cone -/ /-- "Positive" tangent cone to `s` at `x`; the only difference from `tangentConeAt` is that we require `c n → ∞` instead of `‖c n‖ → ∞`. One can think about `posTangentConeAt` as `tangentConeAt NNReal` but we have no theory of normed semifields yet. -/ def posTangentConeAt (s : Set E) (x : E) : Set E := { y : E | ∃ (c : ℕ → ℝ) (d : ℕ → E), (∀ᶠ n in atTop, x + d n ∈ s) ∧ Tendsto c atTop atTop ∧ Tendsto (fun n => c n • d n) atTop (𝓝 y) } theorem posTangentConeAt_mono : Monotone fun s => posTangentConeAt s a := by rintro s t hst y ⟹c, d, hd, hc, hcd⟩ exact ⟹c, d, mem_of_superset hd fun h hn => hst hn, hc, hcd⟩ theorem mem_posTangentConeAt_of_frequently_mem (h : ∃ᶠ t : ℝ in 𝓝[>] 0, x + t • y ∈ s) : y ∈ posTangentConeAt s x := by obtain ⟹a, ha, has⟩ := Filter.exists_seq_forall_of_frequently h refine ⟹a⁻¹, (a · • y), eventually_of_forall has, tendsto_inv_zero_atTop.comp ha, ?_⟩ refine tendsto_const_nhds.congr' ?_ filter_upwards [(tendsto_nhdsWithin_iff.1 ha).2] with n (hn : 0 < a n) simp [ne_of_gt hn] /-- If `[x -[ℝ] x + y] ⊆ s`, then `y` belongs to the positive tangnet cone of `s`. Before 2024-07-13, this lemma used to be called `mem_posTangentConeAt_of_segment_subset`. See also `sub_mem_posTangentConeAt_of_segment_subset` for the lemma that used to be called `mem_posTangentConeAt_of_segment_subset`. -/ theorem mem_posTangentConeAt_of_segment_subset (h : [x -[ℝ] x + y] ⊆ s) : y ∈ posTangentConeAt s x := by refine mem_posTangentConeAt_of_frequently_mem (Eventually.frequently ?_) rw [eventually_nhdsWithin_iff] filter_upwards [ge_mem_nhds one_pos] with t ht₁ ht₀ apply h rw [segment_eq_image', add_sub_cancel_left] exact mem_image_of_mem _ ⟹le_of_lt ht₀, ht₁⟩ @[deprecated (since := "2024-07-13")] -- cleanup docstrings when we drop this alias alias mem_posTangentConeAt_of_segment_subset' := mem_posTangentConeAt_of_segment_subset theorem sub_mem_posTangentConeAt_of_segment_subset (h : segment ℝ x y ⊆ s) : y - x ∈ posTangentConeAt s x := mem_posTangentConeAt_of_segment_subset <| by rwa [add_sub_cancel] @[simp] theorem posTangentConeAt_univ : posTangentConeAt univ a = univ := eq_univ_of_forall fun _ => mem_posTangentConeAt_of_segment_subset (subset_univ _) /-! ### Fermat's Theorem (vector space) -/ /-- If `f` has a local max on `s` at `a`, `f'` is the derivative of `f` at `a` within `s`, and `y` belongs to the positive tangent cone of `s` at `a`, then `f' y ≀ 0`. -/ theorem IsLocalMaxOn.hasFDerivWithinAt_nonpos (h : IsLocalMaxOn f s a) (hf : HasFDerivWithinAt f f' s a) (hy : y ∈ posTangentConeAt s a) : f' y ≀ 0 := by rcases hy with ⟹c, d, hd, hc, hcd⟩ have hc' : Tendsto (‖c ·‖) atTop atTop := tendsto_abs_atTop_atTop.comp hc suffices ∀ᶠ n in atTop, c n • (f (a + d n) - f a) ≀ 0 from le_of_tendsto (hf.lim atTop hd hc' hcd) this replace hd : Tendsto (fun n => a + d n) atTop (𝓝[s] (a + 0)) := tendsto_nhdsWithin_iff.2 ⟹tendsto_const_nhds.add (tangentConeAt.lim_zero _ hc' hcd), hd⟩ rw [add_zero] at hd filter_upwards [hd.eventually h, hc.eventually_ge_atTop 0] with n hfn hcn exact mul_nonpos_of_nonneg_of_nonpos hcn (sub_nonpos.2 hfn) /-- If `f` has a local max on `s` at `a` and `y` belongs to the positive tangent cone of `s` at `a`, then `f' y ≀ 0`. -/ theorem IsLocalMaxOn.fderivWithin_nonpos (h : IsLocalMaxOn f s a) (hy : y ∈ posTangentConeAt s a) : (fderivWithin ℝ f s a : E → ℝ) y ≀ 0 := by classical exact if hf : DifferentiableWithinAt ℝ f s a then h.hasFDerivWithinAt_nonpos hf.hasFDerivWithinAt hy else by rw [fderivWithin_zero_of_not_differentiableWithinAt hf]; rfl /-- If `f` has a local max on `s` at `a`, `f'` is a derivative of `f` at `a` within `s`, and both `y` and `-y` belong to the positive tangent cone of `s` at `a`, then `f' y ≀ 0`. -/ theorem IsLocalMaxOn.hasFDerivWithinAt_eq_zero (h : IsLocalMaxOn f s a) (hf : HasFDerivWithinAt f f' s a) (hy : y ∈ posTangentConeAt s a) (hy' : -y ∈ posTangentConeAt s a) : f' y = 0 := le_antisymm (h.hasFDerivWithinAt_nonpos hf hy) <| by simpa using h.hasFDerivWithinAt_nonpos hf hy' /-- If `f` has a local max on `s` at `a` and both `y` and `-y` belong to the positive tangent cone of `s` at `a`, then `f' y = 0`. -/ theorem IsLocalMaxOn.fderivWithin_eq_zero (h : IsLocalMaxOn f s a) (hy : y ∈ posTangentConeAt s a) (hy' : -y ∈ posTangentConeAt s a) : (fderivWithin ℝ f s a : E → ℝ) y = 0 := by classical exact if hf : DifferentiableWithinAt ℝ f s a then h.hasFDerivWithinAt_eq_zero hf.hasFDerivWithinAt hy hy' else by rw [fderivWithin_zero_of_not_differentiableWithinAt hf]; rfl /-- If `f` has a local min on `s` at `a`, `f'` is the derivative of `f` at `a` within `s`, and `y` belongs to the positive tangent cone of `s` at `a`, then `0 ≀ f' y`. -/ theorem IsLocalMinOn.hasFDerivWithinAt_nonneg (h : IsLocalMinOn f s a) (hf : HasFDerivWithinAt f f' s a) (hy : y ∈ posTangentConeAt s a) : 0 ≀ f' y := by simpa using h.neg.hasFDerivWithinAt_nonpos hf.neg hy /-- If `f` has a local min on `s` at `a` and `y` belongs to the positive tangent cone of `s` at `a`, then `0 ≀ f' y`. -/ theorem IsLocalMinOn.fderivWithin_nonneg (h : IsLocalMinOn f s a) (hy : y ∈ posTangentConeAt s a) : (0 : ℝ) ≀ (fderivWithin ℝ f s a : E → ℝ) y := by classical exact if hf : DifferentiableWithinAt ℝ f s a then h.hasFDerivWithinAt_nonneg hf.hasFDerivWithinAt hy else by rw [fderivWithin_zero_of_not_differentiableWithinAt hf]; rfl /-- If `f` has a local max on `s` at `a`, `f'` is a derivative of `f` at `a` within `s`, and both `y` and `-y` belong to the positive tangent cone of `s` at `a`, then `f' y ≀ 0`. -/ theorem IsLocalMinOn.hasFDerivWithinAt_eq_zero (h : IsLocalMinOn f s a) (hf : HasFDerivWithinAt f f' s a) (hy : y ∈ posTangentConeAt s a) (hy' : -y ∈ posTangentConeAt s a) : f' y = 0 := by simpa using h.neg.hasFDerivWithinAt_eq_zero hf.neg hy hy' /-- If `f` has a local min on `s` at `a` and both `y` and `-y` belong to the positive tangent cone of `s` at `a`, then `f' y = 0`. -/ theorem IsLocalMinOn.fderivWithin_eq_zero (h : IsLocalMinOn f s a) (hy : y ∈ posTangentConeAt s a) (hy' : -y ∈ posTangentConeAt s a) : (fderivWithin ℝ f s a : E → ℝ) y = 0 := by classical exact if hf : DifferentiableWithinAt ℝ f s a then h.hasFDerivWithinAt_eq_zero hf.hasFDerivWithinAt hy hy' else by rw [fderivWithin_zero_of_not_differentiableWithinAt hf]; rfl /-- **Fermat's Theorem**: the derivative of a function at a local minimum equals zero. -/ theorem IsLocalMin.hasFDerivAt_eq_zero (h : IsLocalMin f a) (hf : HasFDerivAt f f' a) : f' = 0 := by ext y apply (h.on univ).hasFDerivWithinAt_eq_zero hf.hasFDerivWithinAt <;> rw [posTangentConeAt_univ] <;> apply mem_univ /-- **Fermat's Theorem**: the derivative of a function at a local minimum equals zero. -/ theorem IsLocalMin.fderiv_eq_zero (h : IsLocalMin f a) : fderiv ℝ f a = 0 := by classical exact if hf : DifferentiableAt ℝ f a then h.hasFDerivAt_eq_zero hf.hasFDerivAt else fderiv_zero_of_not_differentiableAt hf /-- **Fermat's Theorem**: the derivative of a function at a local maximum equals zero. -/ theorem IsLocalMax.hasFDerivAt_eq_zero (h : IsLocalMax f a) (hf : HasFDerivAt f f' a) : f' = 0 := neg_eq_zero.1 <| h.neg.hasFDerivAt_eq_zero hf.neg /-- **Fermat's Theorem**: the derivative of a function at a local maximum equals zero. -/ theorem IsLocalMax.fderiv_eq_zero (h : IsLocalMax f a) : fderiv ℝ f a = 0 := by classical exact if hf : DifferentiableAt ℝ f a then h.hasFDerivAt_eq_zero hf.hasFDerivAt else fderiv_zero_of_not_differentiableAt hf /-- **Fermat's Theorem**: the derivative of a function at a local extremum equals zero. -/ theorem IsLocalExtr.hasFDerivAt_eq_zero (h : IsLocalExtr f a) : HasFDerivAt f f' a → f' = 0 := h.elim IsLocalMin.hasFDerivAt_eq_zero IsLocalMax.hasFDerivAt_eq_zero /-- **Fermat's Theorem**: the derivative of a function at a local extremum equals zero. -/ theorem IsLocalExtr.fderiv_eq_zero (h : IsLocalExtr f a) : fderiv ℝ f a = 0 := h.elim IsLocalMin.fderiv_eq_zero IsLocalMax.fderiv_eq_zero end Module /-! ### Fermat's Theorem -/ section Real variable {f : ℝ → ℝ} {f' : ℝ} {s : Set ℝ} {a b : ℝ} lemma one_mem_posTangentConeAt_iff_mem_closure : 1 ∈ posTangentConeAt s a ↔ a ∈ closure (Ioi a ∩ s) := by constructor · rintro ⟹c, d, hs, hc, hcd⟩ have : Tendsto (a + d ·) atTop (𝓝 a) := by simpa only [add_zero] using tendsto_const_nhds.add (tangentConeAt.lim_zero _ (tendsto_abs_atTop_atTop.comp hc) hcd) apply mem_closure_of_tendsto this filter_upwards [hc.eventually_gt_atTop 0, hcd.eventually (lt_mem_nhds one_pos), hs] with n hcn hcdn hdn simp_all · intro h apply mem_posTangentConeAt_of_frequently_mem rw [mem_closure_iff_frequently, ← map_add_left_nhds_zero, frequently_map] at h simpa [nhdsWithin, frequently_inf_principal] using h lemma one_mem_posTangentConeAt_iff_frequently : 1 ∈ posTangentConeAt s a ↔ ∃ᶠ x in 𝓝[>] a, x ∈ s := by rw [one_mem_posTangentConeAt_iff_mem_closure, mem_closure_iff_frequently, frequently_nhdsWithin_iff, inter_comm] simp_rw [mem_inter_iff] /-- **Fermat's Theorem**: the derivative of a function at a local minimum equals zero. -/ theorem IsLocalMin.hasDerivAt_eq_zero (h : IsLocalMin f a) (hf : HasDerivAt f f' a) : f' = 0 := by simpa using DFunLike.congr_fun (h.hasFDerivAt_eq_zero (hasDerivAt_iff_hasFDerivAt.1 hf)) 1 /-- **Fermat's Theorem**: the derivative of a function at a local minimum equals zero. -/ theorem IsLocalMin.deriv_eq_zero (h : IsLocalMin f a) : deriv f a = 0 := by classical exact if hf : DifferentiableAt ℝ f a then h.hasDerivAt_eq_zero hf.hasDerivAt else deriv_zero_of_not_differentiableAt hf /-- **Fermat's Theorem**: the derivative of a function at a local maximum equals zero. -/ theorem IsLocalMax.hasDerivAt_eq_zero (h : IsLocalMax f a) (hf : HasDerivAt f f' a) : f' = 0 := neg_eq_zero.1 <| h.neg.hasDerivAt_eq_zero hf.neg /-- **Fermat's Theorem**: the derivative of a function at a local maximum equals zero. -/ theorem IsLocalMax.deriv_eq_zero (h : IsLocalMax f a) : deriv f a = 0 := by classical exact if hf : DifferentiableAt ℝ f a then h.hasDerivAt_eq_zero hf.hasDerivAt else deriv_zero_of_not_differentiableAt hf /-- **Fermat's Theorem**: the derivative of a function at a local extremum equals zero. -/ theorem IsLocalExtr.hasDerivAt_eq_zero (h : IsLocalExtr f a) : HasDerivAt f f' a → f' = 0 := h.elim IsLocalMin.hasDerivAt_eq_zero IsLocalMax.hasDerivAt_eq_zero /-- **Fermat's Theorem**: the derivative of a function at a local extremum equals zero. -/ theorem IsLocalExtr.deriv_eq_zero (h : IsLocalExtr f a) : deriv f a = 0 := h.elim IsLocalMin.deriv_eq_zero IsLocalMax.deriv_eq_zero end Real