Imports
/- Copyright (c) 2025 Joseph Tooby-Smith. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhi Kai Pong, Joseph Tooby-Smith, Lode Vermeulen -/ module public import Mathlib.Analysis.Calculus.FDeriv.Symmetric public import Physlib.Mathematics.Distribution.Basic public import Physlib.Relativity.Tensors.RealTensor.Vector.Basic public import Physlib.SpaceAndTime.Space.Module public import Mathlib.Analysis.InnerProductSpace.Calculus

Derivatives on Space

i. Overview

In this module we define derivatives of functions and distributions on space Space d, in the standard directions.

ii. Key results

    deriv : The derivative of a function on space in a given direction.

    distDeriv : The derivative of a distribution on space in a given direction.

iii. Table of contents

    A. Derivatives of functions on Space d

      A.1. Basic equalities

      A.2. Derivative of the constant function

      A.3. Derivative distributes over addition

      A.4. Derivative distributes over scalar multiplication

      A.5. Two spatial derivatives commute

      A.6. Derivative of a component

      A.7. Derivative of a component squared

      A.8. Derivivatives of components

      A.9. Derivative of a norm squared

        A.9.1. Differentiability of the norm squared function

        A.9.2. Derivative of the norm squared function

      A.10. Derivative of the inner product

        A.10.1. Differentiability of the inner product function

        A.10.2. Derivative of the inner product function

        A.10.3. Derivative of the inner product on one side

      A.11. Differentiability of derivatives

    B. Derivatives of distributions on Space d

      B.1. The definition

      B.2. Basic equality

      B.3. Commutation of derivatives

iv. References

@[expose] public section

A. Derivatives of functions on Space d

@[inherit_doc deriv] macro "∂[" i:term "]" : term => `(deriv $i)

A.1. Basic equalities

lemma deriv_eq [AddCommGroup M] [Module M] [TopologicalSpace M] (μ : Fin d) (f : Space d M) (x : Space d) : deriv μ f x = fderiv f x (basis μ) := M:Type u_1d:inst✝²:AddCommGroup Minst✝¹:Module Minst✝:TopologicalSpace Mμ:Fin df:Space d Mx:Space dderiv μ f x = (fderiv f x) (basis μ) All goals completed! 🐙lemma deriv_eq_fderiv_fun [AddCommGroup M] [Module M] [TopologicalSpace M] (μ : Fin d) (f : Space d M) : deriv μ f = fun x => fderiv (fun x => f x) x (basis μ) := M:Type u_1d:inst✝²:AddCommGroup Minst✝¹:Module Minst✝:TopologicalSpace Mμ:Fin df:Space d Mderiv μ f = fun x => (fderiv (fun x => f x) x) (basis μ) All goals completed! 🐙lemma deriv_eq_fderiv_basis [AddCommGroup M] [Module M] [TopologicalSpace M] (μ : Fin d) (f : Space d M) (x : Space d) : deriv μ f x = fderiv f x (basis μ) := M:Type u_1d:inst✝²:AddCommGroup Minst✝¹:Module Minst✝:TopologicalSpace Mμ:Fin df:Space d Mx:Space dderiv μ f x = (fderiv f x) (basis μ) All goals completed! 🐙lemma fderiv_eq_sum_deriv {M d} [AddCommGroup M] [Module M] [TopologicalSpace M] (f : Space d M) (x y : Space d) : fderiv f x y = i : Fin d, y i ∂[i] f x := M:Type u_1d:inst✝²:AddCommGroup Minst✝¹:Module Minst✝:TopologicalSpace Mf:Space d Mx:Space dy:Space d(fderiv f x) y = i, y.val i deriv i f x conv_lhs => M:Type u_1d:inst✝²:AddCommGroup Minst✝¹:Module Minst✝:TopologicalSpace Mf:Space d Mx:Space dy:Space d| (fderiv f x) (∑ i, (basis.repr y).ofLp i basis i) All goals completed! 🐙TODO "Make the version of the derivative described through `deriv_eq_mfderiv_manifoldStructure` the definition of `deriv` and prove the equivalence with the current definition, under suitable conditions."

A.2. Derivative of the constant function

@[simp] lemma deriv_const [NormedAddCommGroup M] [NormedSpace M] (m : M) (μ : Fin d) : deriv μ (fun _ => m) t = 0 := M:Type u_1d:t:Space dinst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mm:Mμ:Fin dderiv μ (fun x => m) t = 0 All goals completed! 🐙

A.3. Derivative distributes over addition and subtraction

Eta-expanded form of Space.deriv_add


Derivatives on space distribute over addition.

@[to_fun] lemma deriv_add [NormedAddCommGroup M] [NormedSpace M] (f1 f2 : Space d M) (hf1 : Differentiable f1) (hf2 : Differentiable f2) : ∂[u] (f1 + f2) = ∂[u] f1 + ∂[u] f2 := M:Type u_1d:u:Fin dinst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mf1:Space d Mf2:Space d Mhf1:Differentiable f1hf2:Differentiable f2deriv u (f1 + f2) = deriv u f1 + deriv u f2 M:Type u_1d:u:Fin dinst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mf1:Space d Mf2:Space d Mhf1:Differentiable f1hf2:Differentiable f2x:Space dderiv u (f1 + f2) x = (deriv u f1 + deriv u f2) x All goals completed! 🐙

Derivatives on space distribute coordinate-wise over addition.

lemma deriv_coord_add (f1 f2 : Space d EuclideanSpace (Fin d)) (hf1 : Differentiable f1) (hf2 : Differentiable f2) : (∂[u] (fun x => f1 x i + f2 x i)) = (∂[u] (fun x => f1 x i)) + (∂[u] (fun x => f2 x i)) := deriv_add (fun x => f1 x i) (fun x => f2 x i) (d:u:Fin di:Fin df1:Space d EuclideanSpace (Fin d)f2:Space d EuclideanSpace (Fin d)hf1:Differentiable f1hf2:Differentiable f2Differentiable fun x => (f1 x).ofLp i All goals completed! 🐙) (d:u:Fin di:Fin df1:Space d EuclideanSpace (Fin d)f2:Space d EuclideanSpace (Fin d)hf1:Differentiable f1hf2:Differentiable f2Differentiable fun x => (f2 x).ofLp i All goals completed! 🐙)

Eta-expanded form of Space.deriv_sub


Derivatives on space distribute over subtraction.

@[to_fun] lemma deriv_sub [NormedAddCommGroup M] [NormedSpace M] (f1 f2 : Space d M) (hf1 : Differentiable f1) (hf2 : Differentiable f2) : ∂[u] (f1 - f2) = ∂[u] f1 - ∂[u] f2 := M:Type u_1d:u:Fin dinst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mf1:Space d Mf2:Space d Mhf1:Differentiable f1hf2:Differentiable f2deriv u (f1 - f2) = deriv u f1 - deriv u f2 M:Type u_1d:u:Fin dinst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mf1:Space d Mf2:Space d Mhf1:Differentiable f1hf2:Differentiable f2x:Space dderiv u (f1 - f2) x = (deriv u f1 - deriv u f2) x All goals completed! 🐙

A.4. Derivative distributes over scalar multiplication

Space derivatives on scalar product of functions.

lemma deriv_smul [NormedAddCommGroup M] [NormedSpace M] [NontriviallyNormedField 𝕜] [NormedAlgebra 𝕜] [NormedSpace 𝕜 M] {c : Space d 𝕜} {f : Space d M} (hc : DifferentiableAt c x) (hf : DifferentiableAt f x) : ∂[u] (c f) x = c x ∂[u] f x + ∂[u] c x f x := M:Type u_1𝕜:Type u_2d:x:Space du:Fin dinst✝⁴:NormedAddCommGroup Minst✝³:NormedSpace Minst✝²:NontriviallyNormedField 𝕜inst✝¹:NormedAlgebra 𝕜inst✝:NormedSpace 𝕜 Mc:Space d 𝕜f:Space d Mhc:DifferentiableAt c xhf:DifferentiableAt f xderiv u (c f) x = c x deriv u f x + deriv u c x f x All goals completed! 🐙

Space derivatives on scalar times function.

lemma deriv_const_smul [NormedAddCommGroup M] [NormedSpace M] [Semiring R] [Module R M] [SMulCommClass R M] [ContinuousConstSMul R M] {f : Space d M} (c : R) (h : Differentiable f) : ∂[u] (c f) = c ∂[u] f := M:Type u_1R:Type u_2d:u:Fin dinst✝⁵:NormedAddCommGroup Minst✝⁴:NormedSpace Minst✝³:Semiring Rinst✝²:Module R Minst✝¹:SMulCommClass R Minst✝:ContinuousConstSMul R Mf:Space d Mc:Rh:Differentiable fderiv u (c f) = c deriv u f M:Type u_1R:Type u_2d:u:Fin dinst✝⁵:NormedAddCommGroup Minst✝⁴:NormedSpace Minst✝³:Semiring Rinst✝²:Module R Minst✝¹:SMulCommClass R Minst✝:ContinuousConstSMul R Mf:Space d Mc:Rh:Differentiable fx:Space dderiv u (c f) x = (c deriv u f) x All goals completed! 🐙

Coordinate-wise scalar multiplication on space derivatives.

lemma deriv_coord_smul (f : Space d EuclideanSpace (Fin d)) (k : ) (hf : Differentiable f) : ∂[u] (fun x => k * f x i) x = k * ∂[u] (fun x => f x i) x := congrFun (deriv_const_smul (f := fun x => f x i) k (d:u:Fin di:Fin dx:Space df:Space d EuclideanSpace (Fin d)k:hf:Differentiable fDifferentiable fun x => (f x).ofLp i All goals completed! 🐙)) x

A.5. Two spatial derivatives commute

Derivatives on space commute with one another.

M:Type u_1d:u:Fin dv:Fin dinst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mf:Space d Mhf:ContDiff 2 fx:Space dDifferentiableAt (fderiv fun x => f x) xM:Type u_1d:u:Fin dv:Fin dinst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mf:Space d Mhf:ContDiff 2 fx:Space dDifferentiableAt (fun x => basis u) xM:Type u_1d:u:Fin dv:Fin dinst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mf:Space d Mhf:ContDiff 2 fx:Space dDifferentiableAt (fderiv fun x => f x) xM:Type u_1d:u:Fin dv:Fin dinst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mf:Space d Mhf:ContDiff 2 fx:Space dDifferentiableAt (fun x => basis v) x repeat All goals completed! 🐙

A.6. Derivative of a component

@[simp] lemma deriv_component_same (μ : Fin d) (x : Space d) : ∂[μ] (fun x => x μ) x = 1 := d:μ:Fin dx:Space dderiv μ (fun x => x.val μ) x = 1 d:μ:Fin dx:Space dderiv μ (fun x => (coordCLM μ) x) x = 1 d:μ:Fin dx:Space d(coordCLM μ) (basis μ) = 1 All goals completed! 🐙lemma deriv_component_diff (μ ν : Fin d) (x : Space d) (h : μ ν) : (deriv μ (fun x => x ν) x) = 0 := d:μ:Fin dν:Fin dx:Space dh:μ νderiv μ (fun x => x.val ν) x = 0 d:μ:Fin dν:Fin dx:Space dh:μ νderiv μ (fun x => (coordCLM ν) x) x = 0 d:μ:Fin dν:Fin dx:Space dh:μ ν(coordCLM ν) (basis μ) = 0 All goals completed! 🐙lemma deriv_component (μ ν : Fin d) (x : Space d) : (deriv ν (fun x => x μ) x) = if ν = μ then 1 else 0 := d:μ:Fin dν:Fin dx:Space dderiv ν (fun x => x.val μ) x = if ν = μ then 1 else 0 d:ν:Fin dx:Space dderiv ν (fun x => x.val ν) x = if ν = ν then 1 else 0d:μ:Fin dν:Fin dx:Space dh':ν μderiv ν (fun x => x.val μ) x = if ν = μ then 1 else 0 d:ν:Fin dx:Space dderiv ν (fun x => x.val ν) x = if ν = ν then 1 else 0 All goals completed! 🐙 d:μ:Fin dν:Fin dx:Space dh':ν μderiv ν (fun x => x.val μ) x = if ν = μ then 1 else 0 All goals completed! 🐙

A.7. Derivative of a component squared

d:ν:Fin dμ:Fin dx:Space d((2 x.val μ ^ (2 - 1)) fderiv (fun p => p.val μ) x) (basis ν) = if ν = μ then 2 * x.val μ else 0 All goals completed! 🐙

A.8. Derivivatives of components

n:d:ν:Fin dμ:Fin nf:Space d EuclideanSpace (Fin n)hf:Differentiable fx:Space d(fderiv (⇑(EuclideanSpace.proj μ)) (f x) ∘SL fderiv f x) (basis ν) = (deriv ν (fun x => f x) x).ofLp μ All goals completed! 🐙d:ν:Fin dμ:Fin 1 Fin df:Space d Lorentz.Vector dhf:Differentiable fx:Space d(fderiv (⇑(Lorentz.Vector.coordCLM μ)) (f x) ∘SL fderiv f x) (basis ν) = deriv ν (fun x => f x) x μ All goals completed! 🐙

A.9. Derivative of a norm squared

A.9.1. Differentiability of the norm squared function
@[fun_prop] lemma norm_sq_differentiable : Differentiable (fun x : Space d => x ^ 2) := (contDiff_norm_sq ).differentiable one_ne_zero
A.9.2. Derivative of the norm squared function
lemma deriv_norm_sq (x : Space d) (i : Fin d) : deriv i (fun x => x ^ 2) x = 2 * x i := d:x:Space di:Fin dderiv i (fun x => x ^ 2) x = 2 * x.val i All goals completed! 🐙

A.10. Derivative of the inner product

A.10.1. Differentiability of the inner product function

The inner product is differentiable.

@[fun_prop] lemma inner_differentiable {d : } : Differentiable (fun y : Space d => y, y⟫_) := differentiable_id.inner differentiable_id
@[fun_prop] lemma inner_differentiableAt {d : } (x : Space d) : DifferentiableAt (fun y : Space d => y, y⟫_) x := inner_differentiable x@[fun_prop] lemma inner_apply_differentiableAt {d : } [NormedAddCommGroup M] [NormedSpace M] {f : M Space d} {g : M Space d} (x : M) (hf : DifferentiableAt f x) (hg : DifferentiableAt g x) : DifferentiableAt (fun y : M => f y, g y⟫_) x := hf.inner hg@[fun_prop] lemma inner_apply_differentiable {d : } [NormedAddCommGroup M] [NormedSpace M] {f : M Space d} {g : M Space d} (hf : Differentiable f) (hg : Differentiable g) : Differentiable (fun y : M => f y, g y⟫_) := hf.inner hg@[fun_prop] lemma inner_contDiff {n : WithTop ℕ∞} {d : } : ContDiff n (fun y : Space d => y, y⟫_) := contDiff_id.inner contDiff_id@[fun_prop] lemma inner_apply_contDiff {n : WithTop ℕ∞} {d : } [NormedAddCommGroup M] [NormedSpace M] {f : M Space d} {g : M Space d} (hf : ContDiff n f) (hg : ContDiff n g) : ContDiff n (fun y : M => f y, g y⟫_) := hf.inner hg
A.10.2. Derivative of the inner product function
lemma deriv_eq_inner_self (x : Space d) (i : Fin d) : deriv i (fun x => x, x⟫_) x = 2 * x i := d:x:Space di:Fin dderiv i (fun x => x, x⟫_) x = 2 * x.val i All goals completed! 🐙
A.10.3. Derivative of the inner product on one side
@[simp] lemma deriv_inner_left {d} (x1 x2 : Space d) (i : Fin d) : deriv i (fun x => x, x2⟫_) x1 = x2 i := d:x1:Space dx2:Space di:Fin dderiv i (fun x => x, x2⟫_) x1 = x2.val i All goals completed! 🐙@[simp] lemma deriv_inner_right {d} (x1 x2 : Space d) (i : Fin d) : deriv i (fun x => x1, x⟫_) x2 = x1 i := d:x1:Space dx2:Space di:Fin dderiv i (fun x => x1, x⟫_) x2 = x1.val i All goals completed! 🐙

A.11. Differentiability of derivatives

lemma deriv_differentiable {M} [NormedAddCommGroup M] [NormedSpace M] {d : } {f : Space d M} (hf : ContDiff 2 f) (i : Fin d) : Differentiable (deriv i f) := M:Type u_1inst✝¹:NormedAddCommGroup Minst✝:NormedSpace Md:f:Space d Mhf:ContDiff 2 fi:Fin dDifferentiable (deriv i f) M:Type u_1inst✝¹:NormedAddCommGroup Minst✝:NormedSpace Md:f:Space d Mhf:ContDiff 2 fi:Fin dDifferentiable fun x => (fderiv f x) (basis i) All goals completed! 🐙lemma deriv_contDiff {d} {f : Space d } (hf : ContDiff (n + 1) f) : ContDiff n fun x i => deriv i f x := n:ℕ∞ωd:f:Space d hf:ContDiff (n + 1) fContDiff n fun x i => deriv i f x n:ℕ∞ωd:f:Space d hf:ContDiff (n + 1) fContDiff n fun x i => (fderiv f x) (basis i) All goals completed! 🐙

B. Derivatives of distributions on Space d

B.1. The definition

@[inherit_doc distDeriv] macro "∂ᵈ[" i:term "]" : term => `(distDeriv $i)

B.2. Basic equality

lemma distDeriv_apply {M d} [NormedAddCommGroup M] [NormedSpace M] (μ : Fin d) (f : (Space d) →d[] M) (ε : 𝓢(Space d, )) : (∂ᵈ[μ] f) ε = fderivD f ε (basis μ) := M:Typed:inst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mμ:Fin df:(Space d)→d[] Mε:𝓢(Space d, )((distDeriv μ) f) ε = (((fderivD ) f) ε) (basis μ) All goals completed! 🐙

B.3. Commutation of derivatives

lemma schwartMap_fderiv_comm {d} (μ ν : Fin d) (x : Space d) (η : 𝓢(Space d, )) : ((SchwartzMap.evalCLM (Space d) (basis μ)) ((fderivCLM (Space d) ) ((SchwartzMap.evalCLM (Space d) (basis ν)) ((fderivCLM (Space d) ) η)))) x = ((SchwartzMap.evalCLM (Space d) (basis ν)) ((fderivCLM (Space d) ) ((SchwartzMap.evalCLM (Space d) (basis μ)) ((fderivCLM (Space d) ) η)))) x := d:μ:Fin dν:Fin dx:Space dη:𝓢(Space d, )((SchwartzMap.evalCLM (Space d) (basis μ)) ((fderivCLM (Space d) ) ((SchwartzMap.evalCLM (Space d) (basis ν)) ((fderivCLM (Space d) ) η)))) x = ((SchwartzMap.evalCLM (Space d) (basis ν)) ((fderivCLM (Space d) ) ((SchwartzMap.evalCLM (Space d) (basis μ)) ((fderivCLM (Space d) ) η)))) x d:μ:Fin dν:Fin dx:Space dη:𝓢(Space d, )deriv μ (deriv ν η) x = deriv ν (deriv μ η) x All goals completed! 🐙lemma distDeriv_commute {M d} [NormedAddCommGroup M] [NormedSpace M] (μ ν : Fin d) (f : (Space d) →d[] M) : (∂ᵈ[ν] (∂ᵈ[μ] f)) = (∂ᵈ[μ] (∂ᵈ[ν] f)) := M:Typed:inst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mμ:Fin dν:Fin df:(Space d)→d[] M(distDeriv ν) ((distDeriv μ) f) = (distDeriv μ) ((distDeriv ν) f) M:Typed:inst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mμ:Fin dν:Fin df:(Space d)→d[] Mη:𝓢(Space d, )((distDeriv ν) ((distDeriv μ) f)) η = ((distDeriv μ) ((distDeriv ν) f)) η M:Typed:inst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mμ:Fin dν:Fin df:(Space d)→d[] Mη:𝓢(Space d, )f ((SchwartzMap.evalCLM (Space d) (basis μ)) ((fderivCLM (Space d) ) ((SchwartzMap.evalCLM (Space d) (basis ν)) ((fderivCLM (Space d) ) η)))) = f ((SchwartzMap.evalCLM (Space d) (basis ν)) ((fderivCLM (Space d) ) ((SchwartzMap.evalCLM (Space d) (basis μ)) ((fderivCLM (Space d) ) η)))) M:Typed:inst✝¹:NormedAddCommGroup Minst✝:NormedSpace Mμ:Fin dν:Fin df:(Space d)→d[] Mη:𝓢(Space d, )(SchwartzMap.evalCLM (Space d) (basis μ)) ((fderivCLM (Space d) ) ((SchwartzMap.evalCLM (Space d) (basis ν)) ((fderivCLM (Space d) ) η))) = (SchwartzMap.evalCLM (Space d) (basis ν)) ((fderivCLM (Space d) ) ((SchwartzMap.evalCLM (Space d) (basis μ)) ((fderivCLM (Space d) ) η))) All goals completed! 🐙