Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Lean/Mathlib/Mathlib/RingTheory/PowerSeries/     Datei vom 15.10.2026 mit Größe 9 kB image not shown  

Quelle  Derivative.lean   Sprache: Lean

 

/-
Copyright (c) 2023 Richard M. Hill. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Richard M. Hill, Ralf Stephan
-/

module

public import Mathlib.RingTheory.MvPowerSeries.Derivative
public import Mathlib.RingTheory.PowerSeries.Substitution

import Mathlib.Algebra.Polynomial.Derivation

/-!
# Formal derivatives of univariate power series

This file defines `PowerSeries.derivative`, the formal derivative of a univariate
power series, as a `Derivation R R⟦X⟧ R⟦X⟧`.

See also `MvPowerSeries.pderiv` for the multivariate setting.

## Main definitions

- `PowerSeries.derivative`: the formal derivative, as a derivation.

## Main results

- `PowerSeries.coeff_derivative`: coefficient formula
  `coeff n (d⁄dX R f) = coeff (n + 1) f * (n + 1)`.
- `PowerSeries.derivative_coe`: compatibility with `Polynomial.derivative`.
- `PowerSeries.trunc_derivative`: truncation commutes with differentiation.
- `PowerSeries.derivative.ext`: a power series is determined by its constant term and derivative.
- `PowerSeries.derivative_pow`: power rule.
- `PowerSeries.derivative_inv`, `PowerSeries.derivative_inv'`: derivative of an inverse.
- `PowerSeries.derivative_subst`: chain rule for power series substitution.
-/


@[expose] public section

namespace PowerSeries

open Polynomial Derivation Nat

variable {R : Type*}

section CommutativeSemiring

variable [CommSemiring R]

/-- The formal derivative of a formal power series -/
noncomputable def derivative : Derivation R R⟦X⟧ R⟦X⟧ :=
  MvPowerSeries.pderiv ()

/-- Abbreviation of `PowerSeries.derivative`, the formal derivative on `R⟦X⟧` -/
scoped notation "d⁄dX" => derivative

@[simp] theorem derivative_C {r : R} : d⁄dX (C r) = 0 := MvPowerSeries.pderiv_C

theorem derivative_one : d⁄dX (1 : R⟦X⟧) = 0 := MvPowerSeries.pderiv_one

theorem coeff_derivative (f : R⟦X⟧) (n : ℕ) :
    coeff n (d⁄dX f) = coeff (n + 1) f * (n + 1) := by
  simp [coeff, derivative, MvPowerSeries.coeff_pderiv]

/-- The `k`-th coefficient of the `n`-th formal derivative: differentiating `n` times multiplies the
`(k + n)`-th coefficient by the ascending factorial `(k + 1)(k + 2) ⋯ (k + n)`. -/

theorem coeff_iterate_derivative (f : R⟦X⟧) (n k : ℕ) :
    coeff k (d⁄dX^[n] f) = (k + 1).ascFactorial n * coeff (k + n) f := by
  induction n generalizing k with
  | zero => simp
  | succ n ih =>
    rw [Function.iterate_succ_apply', coeff_derivative, ih, Nat.ascFactorial_succ,
      ← Nat.succ_ascFactorial]
    grind

/-- Specialisation of `coeff_iterate_derivative` at `k = 0`: the constant term of the `n`-th formal
derivative recovers `n !` times the `n`-th coefficient, `constantCoeff (Dⁿ f) = n ! * coeff n f`. -/

theorem constantCoeff_iterate_derivative (f : R⟦X⟧) (n : ℕ) :
    constantCoeff (d⁄dX^[n] f) = n ! * coeff n f := by
  simpa using coeff_iterate_derivative f n 0

theorem derivative_coe (f : R[X]) : d⁄dX (f : R⟦X⟧) = Polynomial.derivative f := by
  ext
  rw [coeff_derivative, coeff_coe, coeff_coe, Polynomial.coeff_derivative]

@[simp] theorem derivative_X : d⁄dX (X : R⟦X⟧) = 1 :=
  MvPowerSeries.pderiv_X_self

theorem iterate_derivative_zero {k : ℕ} : d⁄dX^[k] (0 : R⟦X⟧) = 0 := by
  simp

theorem derivative_monomial (a : R) (n : ℕ) :
    d⁄dX (monomial n a) = monomial (n - 1) (a * n) := by
  ext k
  rw [coeff_derivative, coeff_monomial, coeff_monomial]
  cases n with
  | zero => simp
  | succ n =>
    rw [Nat.add_sub_cancel]
    split_ifs with h₁ h₂ h₂
    · rw [h₂, Nat.cast_add, Nat.cast_one]
    · lia
    · lia
    · rw [zero_mul]

@[simp]
theorem derivative_monomial_succ (a : R) (n : ℕ) :
    d⁄dX (monomial (n + 1) a) = monomial n (a * (n + 1)) := by
  simp [derivative_monomial]

theorem derivative_C_mul_X (a : R) : d⁄dX (C a * X) = C a := by
  simp

theorem derivative_C_mul_X_pow (a : R) (n : ℕ) :
    d⁄dX (C a * X ^ n) = C (a * n) * X ^ (n - 1) := by
  rw [← monomial_eq_C_mul_X_pow, ← monomial_eq_C_mul_X_pow, derivative_monomial]

theorem derivative_C_mul_X_sq (a : R) : d⁄dX (C a * X ^ 2) = C (a * 2) * X := by
  rw [derivative_C_mul_X_pow, Nat.cast_two, pow_one]

theorem derivative_X_pow (n : ℕ) : d⁄dX (X ^ n : R⟦X⟧) = C (n : R) * X ^ (n - 1) := by
  simp

theorem derivative_X_pow_succ (n : ℕ) :
    d⁄dX (X ^ (n + 1) : R⟦X⟧) = C (n + 1 : R) * X ^ n := by
  simp

theorem derivative_X_sq : d⁄dX (X ^ 2 : R⟦X⟧) = C 2 * X := by
  rw [derivative_X_pow, Nat.cast_two, pow_one]

theorem derivative_X_add_C (c : R) : d⁄dX (X + C c) = 1 := by
  simp

theorem iterate_derivative_sum {ι : Type*} (k : ℕ) (s : Finset ι) (f : ι → R⟦X⟧) :
    d⁄dX^[k] (∑ b ∈ s, f b) = ∑ b ∈ s, d⁄dX^[k] (f b) := by
  induction k with
  | zero => simp
  | succ k ih => simp only [Function.iterate_succ_apply', ih, map_sum]

@[simp]
theorem iterate_derivative_smul {S : Type*} [SMul S R⟦X⟧]
    [LinearMap.CompatibleSMul R⟦X⟧ R⟦X⟧ S R] (s : S) (f : R⟦X⟧) (k : ℕ) :
    d⁄dX^[k] (s • f) = s • d⁄dX^[k] f := by
  induction k generalizing f with
  | zero => simp
  | succ k ih => simp [Function.iterate_succ_apply, ih]

-- We can't use `MvPowerSeries.trunc_pderiv` in the following proof,
-- since `PowerSeries.trunc` is not defined in terms of `MvPowerSeries.trunc`.
theorem trunc_derivative (f : R⟦X⟧) (n : ℕ) :
    trunc n (d⁄dX f) = Polynomial.derivative (trunc (n + 1) f) := by
  ext d
  rw [coeff_trunc]
  split_ifs with h
  · have : d + 1 < n + 1 := succ_lt_succ_iff.2 h
    rw [coeff_derivative, Polynomial.coeff_derivative, coeff_trunc, ite_eq_left this]
  · have : ¬d + 1 < n + 1 := by rwa [succ_lt_succ_iff]
    rw [Polynomial.coeff_derivative, coeff_trunc, ite_eq_right this, zero_mul]

theorem trunc_derivative' (f : R⟦X⟧) (n : ℕ) :
    trunc (n - 1) (d⁄dX f) = Polynomial.derivative (trunc n f) := by
  cases n <;> simp [trunc_derivative]

/-- The derivative of `g^n` equals `n * g^(n-1) * g'`. -/
theorem derivative_pow (g : R⟦X⟧) (n : ℕ) :
    d⁄dX (g ^ n) = n * g ^ (n - 1) * d⁄dX g :=
  MvPowerSeries.pderiv_pow g n

end CommutativeSemiring

/-- If `f` and `g` have the same constant term and derivative, then they are equal. -/
theorem derivative.ext [CommRing R] [HasUniqueDiv R] {f g : R⟦X⟧} (hD : d⁄dX f = d⁄dX g)
    (hc : constantCoeff f = constantCoeff g) : f = g :=
  MvPowerSeries.pderiv.ext (fun _ => hD) hc

@[simp]
theorem derivative_inv [CommRing R] (f : R⟦X⟧ˣ) :
    d⁄dX ↑f⁻¹ = -(↑f⁻¹ : R⟦X⟧) ^ 2 * d⁄dX f :=
  MvPowerSeries.pderiv_inv f

@[simp]
theorem derivative_invOf [CommRing R] (f : R⟦X⟧) [Invertible f] :
    d⁄dX ⅟f = -⅟f ^ 2 * d⁄dX f :=
  MvPowerSeries.pderiv_invOf f

/-
The following theorem is stated only in the case that `R` is a field. This is because
there is currently no instance of `Inv R⟦X⟧` for more general base rings `R`.
-/


@[simp] theorem derivative_inv' [Field R] (f : R⟦X⟧) : d⁄dX f⁻¹ = -f⁻¹ ^ 2 * d⁄dX f :=
  MvPowerSeries.pderiv_inv' f

/-- Chain rule for polynomials viewed as power series.  Use `derivative_subst` instead. -/
private theorem derivative_subst_coe [CommRing R] (p : Polynomial R) {g : R⟦X⟧} (hg : HasSubst g) :
    d⁄dX ((p : R⟦X⟧).subst g) = (d⁄dX (p : R⟦X⟧)).subst g * d⁄dX g := by
  simp [subst_coe hg, derivative_coe, Derivation.comp_aeval_eq (a := g) derivative p,
    smul_eq_mul]

theorem derivative_subst [CommRing R] {f g : R⟦X⟧} (hg : HasSubst g) :
    d⁄dX (f.subst g) = (d⁄dX f).subst g * d⁄dX g := by
  ext n
  obtain ⟨m, hm⟩ := (hg.eventually_coeff_pow_eq_zero (n + 1)).exists_forall_of_atTop
  have : coeff (n + 1) (f.subst g) = coeff (n + 1) ((↑(trunc (m + 1) f) : R⟦X⟧).subst g) := by
    rw [coeff_subst' hg, coeff_subst' hg]
    refine finsum_congr fun d ↦ ?_
    obtain hd | hd := lt_or_ge d m
    · rw [coeff_coe_trunc_of_lt (by lia)]
    · simp [coeff_trunc, hd, hm]
  rw [coeff_derivative, this, ← coeff_derivative, derivative_subst_coe _ hg, coeff_mul, coeff_mul]
  refine Finset.sum_congr rfl fun ⟨i, j⟩ hij ↦ ?_
  congr 1
  simp only [coeff_subst' hg, coeff_derivative, coeff_coe, coeff_trunc]
  exact finsum_congr fun d ↦ by split_ifs <;> simp (disch := grind [Finset.mem_antidiagonal]) [hm]

section deprecated

variable [CommSemiring R]

/--
The formal derivative of a power series in one variable.
This is defined here as a function, but will be packaged as a
derivation `derivative` on `R⟦X⟧`.
-/

@[deprecated derivative +typeChanged (since := "2026-06-26")]
noncomputable def derivativeFun (f : R⟦X⟧) := derivative.toFun f

@[deprecated "Use Derivation.map_add" (since := "2026-06-26")]
theorem derivativeFun_add (f g : R⟦X⟧) :
    derivativeFun (f + g) = derivativeFun f + derivativeFun g :=
  derivative.map_add f g

@[deprecated "Use Derivation.leibniz" (since := "2026-06-26")]
theorem derivativeFun_mul (f g : R⟦X⟧) :
    derivativeFun (f * g) = f • g.derivativeFun + g • f.derivativeFun :=
  derivative.leibniz f g

@[deprecated "Use Derivation.map_one_eq_zero" (since := "2026-06-26")]
theorem derivativeFun_one : derivativeFun (1 : R⟦X⟧) = 0 :=
  derivative.map_one_eq_zero

@[deprecated "Use Derivation.map_smul" (since := "2026-06-26")]
theorem derivativeFun_smul (r : R) (f : R⟦X⟧) : derivativeFun (r • f) = r • derivativeFun f :=
  derivative.map_smul r f

@[deprecated (since := "2026-06-26")] alias derivativeFun_C := derivative_C

@[deprecated (since := "2026-06-26")] alias coeff_derivativeFun := coeff_derivative

@[deprecated (since := "2026-06-26")] alias derivativeFun_coe := derivative_coe

@[deprecated (since := "2026-06-26")] alias trunc_derivativeFun := trunc_derivative

end deprecated

end PowerSeries

Messung
CHZG
9210010097

¤ Dauer der Verarbeitung: 0.6 Sekunden  ¤

*© Formatika GbR, Deutschland