Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Lean/Mathlib/Mathlib/Analysis/Calculus/     Datei vom 15.10.2026 mit Größe 10 kB image not shown  

Quelle  DSlope.lean   Sprache: Lean

 

/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/

module

public import Mathlib.Analysis.Analytic.Basic
public import Mathlib.Analysis.Calculus.Deriv.Slope

import Mathlib.Analysis.Analytic.Constructions
import Mathlib.Analysis.Calculus.Deriv.Comp
import Mathlib.Analysis.Calculus.FDeriv.Analytic
import Mathlib.Analysis.Calculus.FDeriv.Mul

set_option doc.verso true
set_option doc.verso.suggestions false

/-!
# 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.
-/


@[expose] public section

open scoped Topology Filter

open Function Set Filter

variable {�� E : Type*} [NontriviallyNormedField ��] [NormedAddCommGroup E] [NormedSpace �� E]

open scoped 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_self ..

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_of_ne 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_nhdsNE (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).fun_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_notMem (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]

lemma sub_smul_dslope_of_zero {f : �� → E} {a : ��} (hf : f a = 0) (b : ��) :
    (b - a) • dslope f a b = f b := by
  simp [hf]

lemma pow_sub_smul_iterate_dslope_of_zero {f : �� → E} {a : ��} (n : ℕ)
    (hf : ∀ k < n, (Function.swap dslope a)^[k] f a = 0) (b : ��) :
    (b - a) ^ n • (Function.swap dslope a)^[n] f b = f b := by
  induction n generalizing f with
  | zero => simp
  | succ n ih =>
    rw [Function.iterate_succ_apply', pow_succ, mul_smul,
      sub_smul_dslope_of_zero (hf n n.lt_succ_self), ih (by grind)]

section analytic

variable {z : ��}

/--
If `f` has power series `p` at `z₀`, then `dslope f z₀` has power series `p.fslope` at `z₀`.
-/

theorem HasFPowerSeriesAt.dslope_fslope {p : FormalMultilinearSeries �� �� E}
    {z₀ : ��} (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, FormalMultilinearSeries.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 simp [field, 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⁻¹

@[deprecated (since := "2026-09-30")]
alias HasFPowerSeriesAt.has_fpower_series_dslope_fslope := HasFPowerSeriesAt.dslope_fslope

/--
Away from the base point `a`, the function `dslope f a` is analytic within `s` at `z` as soon as `f`
is.
-/

theorem AnalyticWithinAt.dslope_of_ne (hf : AnalyticWithinAt �� f s z) (hz : z ≠ a) :
    AnalyticWithinAt �� (dslope f a) s z := by
  suffices h : AnalyticWithinAt �� (fun w ↦ (w - a)⁻¹ • (f w - f a)) s z from
    h.congr_of_eventuallyEq (dslope_eventuallyEq_slope_of_ne f hz |>.filter_mono nhdsWithin_le_nhds)
      (by simp [dslope, slope, hz])
  apply_rules [sub, inv, analyticWithinAt_id, analyticWithinAt_const, smul]
  grind

/-- If `f` is analytic at `z`, then so is `dslope f a`, for any base point `a`. -/
@[fun_prop] protected theorem AnalyticAt.dslope (hf : AnalyticAt �� f z) (a : ��) :
    AnalyticAt �� (dslope f a) z := by
  rcases eq_or_ne z a with rfl | hz
  · obtain ⟨p, hp⟩ := hf
    exact hp.dslope_fslope.analyticAt
  · exact analyticWithinAt_univ.1 (hf.analyticWithinAt.dslope_of_ne hz)

/--
If `f` is analytic on `s` and the base point `a` does not lie in `s`, then `dslope f a` is analytic
on `s`.
-/

theorem AnalyticOn.dslope_of_notMem (hf : AnalyticOn �� f s) (ha : a ∉ s) :
    AnalyticOn �� (dslope f a) s :=
  fun z hz ↦ (hf z hz).dslope_of_ne (ne_of_mem_of_not_mem hz ha)

/--
If `f` is analytic on a set `s` that is a neighbourhood of the base point `a`, then `dslope f a` is
analytic on `s`.
-/

protected theorem AnalyticOn.dslope (hf : AnalyticOn �� f s) (ha : s ∈ �� a) :
    AnalyticOn �� (dslope f a) s := by
  intro z hz
  rcases eq_or_ne z a with hz' | hz'
  · have hfa : AnalyticAt �� f a :=
      analyticWithinAt_univ.1 ((hf a (mem_of_mem_nhds ha)).mono_of_mem_nhdsWithin
        (mem_nhdsWithin_of_mem_nhds ha))
    exact hz' ▸ (hfa.dslope a).analyticWithinAt
  · exact (hf z hz).dslope_of_ne hz'

/--
If `f` is analytic on a neighbourhood of `s`, then so is `dslope f a`, for any base point `a`.
-/

@[fun_prop] protected theorem AnalyticOnNhd.dslope (hf : AnalyticOnNhd �� f s) (a : ��) :
    AnalyticOnNhd �� (dslope f a) s :=
  fun z hz ↦ (hf z hz).dslope a

end analytic

Messung
CHZG
9210010097

¤ Dauer der Verarbeitung: 0.10 Sekunden  ¤

*© Formatika GbR, Deutschland