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 Physlib.SpaceAndTime.Space.Derivatives.Basic public import Physlib.SpaceAndTime.Space.IsDistBounded public import Mathlib.Analysis.Calculus.Gradient.Basic

Gradient of functions and distributions on Space d

i. Overview

This module defines and proves basic properties of the gradient operator on functions from Space d to and on distributions from Space d to .

The gradient operator returns a vector field whose components are the partial derivatives of the input function with respect to each spatial coordinate.

ii. Key results

    grad : The gradient operator on functions from Space d to .

    distGrad : The gradient operator on distributions from Space d to .

iii. Table of contents

    A. The gradient of functions on Space d

      A.1. Gradient of the zero function

      A.2. Gradient distributes over addition

      A.3. Gradient of a constant function

      A.4. Gradient distributes over scalar multiplication

      A.5. Gradient distributes over negation

      A.6. Expansion in terms of basis vectors

      A.7. Components of the gradient

      A.8. Inner product with a gradient

      A.9. Gradient is equal to gradient from Mathlib

      A.10. Value of gradient in the direction of the position vector

      A.11. Gradient of the norm squared function

      A.12. Gradient of the inner product function

      A.13. Integrability with bounded functions

      A.14. Differentiability of gradient

    B. Gradient of distributions

      B.1. The definition

      B.2. The gradient of inner products

      B.3. The gradient as a sum over basis vectors

      B.4. The underlying function of the gradient distribution

      B.5. The gradient applied to a Schwartz function

      B.6. Gradient of constant distributions

      B.7. The gradient of a Schwartz map

iv. References

@[expose] public section

A. The gradient of functions on Space d

@[inherit_doc grad] scoped[Space] notation "∇" => grad

A.1. Gradient of the zero function

@[simp] lemma grad_zero : (0 : Space d ) = 0 := d: 0 = 0 d:(fun x => WithLp.toLp 2 fun i => (fderiv 0 x) (basis i)) = 0 d:(fun x => WithLp.toLp 2 fun i => 0) = 0 All goals completed! 🐙

A.2. Gradient distributes over addition

d:f1:Space d f2:Space d hf1:Differentiable f1hf2:Differentiable f2x:Space di:Fin d(deriv i f1 + deriv i f2) x = ((WithLp.toLp 2 fun i => deriv i f1 x) + WithLp.toLp 2 fun i => deriv i f2 x).ofLp i All goals completed! 🐙@[simp] lemma grad_fun_add_const (f : Space d ) (c : ) : (fun x => f x + c) = f := d:f:Space d c:( fun x => f x + c) = f d:f:Space d c:x:Space di:Fin d( (fun x => f x + c) x).ofLp i = ( f x).ofLp i All goals completed! 🐙

A.3. Gradient of a constant function

@[simp] lemma grad_const : (fun _ : Space d => c) = 0 := d:c:( fun x => c) = 0 d:c:(fun x => WithLp.toLp 2 fun i => (fderiv (fun x => c) x) (basis i)) = 0 d:c:(fun x => WithLp.toLp 2 fun i => 0) = 0 All goals completed! 🐙

A.4. Gradient distributes over scalar multiplication

d:f:Space d k:hf:Differentiable fx:Space di:Fin d(k deriv i f) x = (k WithLp.toLp 2 fun i => deriv i f x).ofLp i All goals completed! 🐙

A.5. Gradient distributes over negation

d:f:Space d x:Space di:Fin d(-fderiv f x) (basis i) = (-WithLp.toLp 2 fun i => deriv i f x).ofLp i All goals completed! 🐙

A.6. Expansion in terms of basis vectors

lemma grad_eq_sum {d} (f : Space d ) (x : Space d) : f x = i, ∂[i] f x EuclideanSpace.single i 1 := d:f:Space d x:Space d f x = i, deriv i f x EuclideanSpace.single i 1 d:f:Space d x:Space dj:Fin d( f x).ofLp j = (∑ i, deriv i f x EuclideanSpace.single i 1).ofLp j All goals completed! 🐙

A.7. Components of the gradient

lemma grad_apply {d} (f : Space d ) (x : Space d) (i : Fin d) : ( f x) i = ∂[i] f x := d:f:Space d x:Space di:Fin d( f x).ofLp i = deriv i f x All goals completed! 🐙

A.8. Inner product with a gradient

lemma grad_inner_single {d} (f : Space d ) (x : Space d) (i : Fin d) : f x, EuclideanSpace.single i 1⟫_ = ∂[i] f x := d:f:Space d x:Space di:Fin d f x, EuclideanSpace.single i 1⟫_ = deriv i f x All goals completed! 🐙lemma grad_inner_eq {d} (f : Space d ) (x : Space d) (y : EuclideanSpace (Fin d)) : f x, y⟫_ = i, y i * ∂[i] f x:= d:f:Space d x:Space dy:EuclideanSpace (Fin d) f x, y⟫_ = i, y.ofLp i * deriv i f x All goals completed! 🐙lemma inner_grad_eq {d} (f : Space d ) (x : EuclideanSpace (Fin d)) (y : Space d) : x, f y⟫_ = i, x i * ∂[i] f y := (real_inner_comm ( f y) x).trans (grad_inner_eq f y x)lemma grad_inner_repr_eq {d} (f : Space d ) (x y : Space d) : f x, (Space.basis).repr y⟫_ = fderiv f x y := d:f:Space d x:Space dy:Space d f x, basis.repr y⟫_ = (fderiv f x) y All goals completed! 🐙lemma repr_grad_inner_eq {d} (f : Space d ) (x y : Space d) : (Space.basis).repr x, f y⟫_ = fderiv f y x := (real_inner_comm ( f y) ((Space.basis).repr x)).trans (grad_inner_repr_eq f y x)

A.9. Gradient is equal to gradient from Mathlib

d:f:Space d x:Space dy:EuclideanSpace (Fin d) f x, y⟫_ = (fderiv f x) (basis.repr.symm y) All goals completed! 🐙d:f:Space d gradient f = basis.repr.symm basis.repr gradient f d:f:Space d x:Space di✝:Fin d(gradient f x).val i✝ = ((basis.repr.symm basis.repr gradient f) x).val i✝ All goals completed! 🐙d:f:Space d x:Space dgradient f x = basis.repr.symm ((basis.repr gradient f) x) All goals completed! 🐙lemma gradient_eq_sum {d} (f : Space d ) (x : Space d) : gradient f x = i, ∂[i] f x basis i := d:f:Space d x:Space dgradient f x = i, deriv i f x basis i All goals completed! 🐙d:f:EuclideanSpace (Fin d) x:EuclideanSpace (Fin d)y:EuclideanSpace (Fin d)hy:y = i, y.ofLp i EuclideanSpace.single i 1(fderiv f x) y = i, (fderiv f x) (EuclideanSpace.single i 1) EuclideanSpace.single i 1, y⟫_ conv_lhs => d:f:EuclideanSpace (Fin d) x:EuclideanSpace (Fin d)y:EuclideanSpace (Fin d)hy:y = i, y.ofLp i EuclideanSpace.single i 1| (fderiv f x) (∑ i, y.ofLp i EuclideanSpace.single i 1) All goals completed! 🐙d:f:Space d x:Space dhf:DifferentiableAt f xHasGradientAt f (gradient f x) x All goals completed! 🐙

A.10. Value of gradient in the direction of the position vector

The gradient in the direction of the space position.

d:x:Space df:Space d hd:Differentiable fhx:¬x = 0(fderiv f x) (_root_.deriv (fun r => r) x x⁻¹ x) = i, (x⁻¹ basis.repr x).ofLp i * deriv i f x d:x:Space df:Space d hd:Differentiable fhx:¬x = 0 i, x⁻¹ * (x.val i * deriv i f x) = x_1, x⁻¹ * x.val x_1 * deriv x_1 f x All goals completed! 🐙
d:x:Space df:Space d hd:Differentiable f f x, basis.repr x⟫_ = x * (x⁻¹ * f x, basis.repr x⟫_) d:x:Space df:Space d hd:Differentiable fhx:x = 0 f x, basis.repr x⟫_ = x * (x⁻¹ * f x, basis.repr x⟫_)d:x:Space df:Space d hd:Differentiable fhx:¬x = 0 f x, basis.repr x⟫_ = x * (x⁻¹ * f x, basis.repr x⟫_) d:x:Space df:Space d hd:Differentiable fhx:x = 0 f x, basis.repr x⟫_ = x * (x⁻¹ * f x, basis.repr x⟫_) d:f:Space d hd:Differentiable f f 0, basis.repr 0⟫_ = 0 * (0⁻¹ * f 0, basis.repr 0⟫_) All goals completed! 🐙 d:x:Space df:Space d hd:Differentiable fhx✝:¬x = 0hx:x 0 f x, basis.repr x⟫_ = x * (x⁻¹ * f x, basis.repr x⟫_) All goals completed! 🐙d:x:Space df:Space d hd:Differentiable ft:ht:0 < thx:¬x = 0x * (_root_.deriv (fun r => f (r x)) (x⁻¹ * (t * x)) * (x⁻¹ * _root_.deriv (fun r => r) (t * x))) = _root_.deriv (fun r => f (r x)) t d:x:Space df:Space d hd:Differentiable ft:ht:0 < thx:¬x = 0x * (_root_.deriv (fun r => f (r x)) (x⁻¹ * (t * x)) * x⁻¹) = _root_.deriv (fun r => f (r x)) t All goals completed! 🐙f:Space hf:ContDiff 1 fx:Spaceh':Differentiable fhx:¬x = 0f (1 x) - f (0 x) + f 0 = f (1 x) - f 0 + f 0f:Space hf:ContDiff 1 fx:Spaceh':Differentiable fhx:¬x = 0IntervalIntegrable (_root_.deriv fun r => f (r x)) volume 0 1 f:Space hf:ContDiff 1 fx:Spaceh':Differentiable fhx:¬x = 0IntervalIntegrable (_root_.deriv fun r => f (r x)) volume 0 1 f:Space hf:ContDiff 1 fx:Spaceh':Differentiable fhx:¬x = 0IntervalIntegrable (_root_.deriv fun r => f (r x)) volume 0 1 f:Space hf:ContDiff 1 fx:Spaceh':Differentiable fhx:¬x = 0Continuous (_root_.deriv fun r => f (r x)) All goals completed! 🐙 All goals completed! 🐙

A.11. Gradient of the norm squared function

d:x:Space di:Fin d2 * x.val i = (2 basis.repr x).ofLp i All goals completed! 🐙

A.12. Gradient of the inner product function

The gradient of the inner product is given by 2 • x.

d:z:Space di:Fin d2 * z.val i = (2 basis.repr z).ofLp i All goals completed! 🐙
lemma grad_inner_left {d : } (x : Space d) : (fun y : Space d => y, x⟫_) = fun _ => basis.repr x := d:x:Space d( fun y => y, x⟫_) = fun x_1 => basis.repr x d:x:Space dz:Space di:Fin d( (fun y => y, x⟫_) z).ofLp i = (basis.repr x).ofLp i All goals completed! 🐙lemma grad_inner_right {d : } (x : Space d) : (fun y : Space d => x, y⟫_) = fun _ => basis.repr x := d:x:Space d( fun y => x, y⟫_) = fun x_1 => basis.repr x simp_rw d:x:Space d( fun y => x, y⟫_) = fun x_1 => basis.repr xd:x:Space d( fun y => y, x⟫_) = fun x_1 => basis.repr x] All goals completed! 🐙

A.13. Integrability with bounded functions

All goals completed! 🐙d:f:Space d EuclideanSpace (Fin d)hf:IsDistBounded fη:𝓢(Space d, )h1:Integrable (fun x => f x, η x⟫_) (Measure.comap Subtype.val volume)he:MeasurePreserving (⇑(homeomorphUnitSphereProd (Space d))) (Measure.comap Subtype.val volume) (volume.toSphere.prod (Measure.volumeIoiPow (Module.finrank (Space d) - 1)))Integrable (((fun x => f x, η x⟫_) (homeomorphUnitSphereProd (Space d)).symm) (homeomorphUnitSphereProd (Space d))) (Measure.comap Subtype.val volume)d:f:Space d EuclideanSpace (Fin d)hf:IsDistBounded fη:𝓢(Space d, )h1:Integrable (fun x => f x, η x⟫_) (Measure.comap Subtype.val volume)he:MeasurePreserving (⇑(homeomorphUnitSphereProd (Space d))) (Measure.comap Subtype.val volume) (volume.toSphere.prod (Measure.volumeIoiPow (Module.finrank (Space d) - 1)))MeasurableEmbedding (homeomorphUnitSphereProd (Space d)) d:f:Space d EuclideanSpace (Fin d)hf:IsDistBounded fη:𝓢(Space d, )h1:Integrable (fun x => f x, η x⟫_) (Measure.comap Subtype.val volume)he:MeasurePreserving (⇑(homeomorphUnitSphereProd (Space d))) (Measure.comap Subtype.val volume) (volume.toSphere.prod (Measure.volumeIoiPow (Module.finrank (Space d) - 1)))x✝:{0}(((fun x => f x, η x⟫_) (homeomorphUnitSphereProd (Space d)).symm) (homeomorphUnitSphereProd (Space d))) x✝ = f x✝, η x✝⟫_d:f:Space d EuclideanSpace (Fin d)hf:IsDistBounded fη:𝓢(Space d, )h1:Integrable (fun x => f x, η x⟫_) (Measure.comap Subtype.val volume)he:MeasurePreserving (⇑(homeomorphUnitSphereProd (Space d))) (Measure.comap Subtype.val volume) (volume.toSphere.prod (Measure.volumeIoiPow (Module.finrank (Space d) - 1)))MeasurableEmbedding (homeomorphUnitSphereProd (Space d)) d:f:Space d EuclideanSpace (Fin d)hf:IsDistBounded fη:𝓢(Space d, )h1:Integrable (fun x => f x, η x⟫_) (Measure.comap Subtype.val volume)he:MeasurePreserving (⇑(homeomorphUnitSphereProd (Space d))) (Measure.comap Subtype.val volume) (volume.toSphere.prod (Measure.volumeIoiPow (Module.finrank (Space d) - 1)))MeasurableEmbedding (homeomorphUnitSphereProd (Space d)) All goals completed! 🐙

A.14. Differentiability of gradient

@[fun_prop] lemma contDiff_grad {n} {f : Space } (hf : ContDiff (n + 1) f) : ContDiff n (fun x => f x) := n:ℕ∞ωf:Space hf:ContDiff (n + 1) fContDiff n fun x => f x n:ℕ∞ωf:Space hf:ContDiff (n + 1) fContDiff n fun x => WithLp.toLp 2 fun i => deriv i f x n:ℕ∞ωf:Space hf:ContDiff (n + 1) fContDiff n (WithLp.toLp 2)n:ℕ∞ωf:Space hf:ContDiff (n + 1) fContDiff n fun x i => deriv i f x n:ℕ∞ωf:Space hf:ContDiff (n + 1) fContDiff n (WithLp.toLp 2) All goals completed! 🐙 n:ℕ∞ωf:Space hf:ContDiff (n + 1) fContDiff n fun x i => deriv i f x All goals completed! 🐙

B. Gradient of distributions

B.1. The definition

@[inherit_doc distGrad] scoped[Space] notation "∇ᵈ" => distGrad

B.2. The gradient of inner products

d:f:(Space d)→d[] η:𝓢(Space d, )y:EuclideanSpace (Fin d)({ toFun := fun f => LinearMap.toContinuousLinearMap basis.repr.toLinearEquiv ∘SL LinearMap.toContinuousLinearMap (toDual (Space d)).symm.toLinearEquiv ∘SL (fderivD ) f, map_add' := , map_smul' := } f) η, y⟫_ = (((fderivD ) f) η) (basis.repr.symm y) All goals completed! 🐙lemma distGrad_eq_of_inner {d} (f : (Space d) →d[] ) (g : (Space d) →d[] EuclideanSpace (Fin d)) (h : η y, fderivD f η y = g η, basis.repr y⟫_) : ∇ᵈ f = g := d:f:(Space d)→d[] g:(Space d)→d[] EuclideanSpace (Fin d)h: (η : 𝓢(Space d, )) (y : Space d), (((fderivD ) f) η) y = g η, basis.repr y⟫_∇ᵈ f = g d:f:(Space d)→d[] g:(Space d)→d[] EuclideanSpace (Fin d)h: (η : 𝓢(Space d, )) (y : Space d), (((fderivD ) f) η) y = g η, basis.repr y⟫_η:𝓢(Space d, )(∇ᵈ f) η = g η d:f:(Space d)→d[] g:(Space d)→d[] EuclideanSpace (Fin d)h: (η : 𝓢(Space d, )) (y : Space d), (((fderivD ) f) η) y = g η, basis.repr y⟫_η:𝓢(Space d, )v:EuclideanSpace (Fin d)(∇ᵈ f) η, v⟫_ = g η, v⟫_ All goals completed! 🐙

B.3. The gradient as a sum over basis vectors

d:f:(Space d)→d[] η:𝓢(Space d, )y:EuclideanSpace (Fin d)h1: i, -f ((SchwartzMap.evalCLM (Space d) (basis i)) ((fderivCLM (Space d) ) η)) EuclideanSpace.single i 1, y⟫_ = (((fderivD ) f) η) (basis.repr.symm y)(∇ᵈ f) η, y⟫_ = i, -f ((SchwartzMap.evalCLM (Space d) (basis i)) ((fderivCLM (Space d) ) η)) EuclideanSpace.single i 1, y⟫_ All goals completed! 🐙

B.4. The underlying function of the gradient distribution

d:f:(Space d)→d[] ε:𝓢(Space d, )i:Fin d(∑ i, -f ((SchwartzMap.evalCLM (Space d) (basis i)) ((fderivCLM (Space d) ) ε)) EuclideanSpace.single i 1).ofLp i = ((distDeriv i) f) ε d:f:(Space d)→d[] ε:𝓢(Space d, )i:Fin d-f ((SchwartzMap.evalCLM (Space d) (basis i)) ((fderivCLM (Space d) ) ε)) = ((distDeriv i) f) ε All goals completed! 🐙

B.5. The gradient applied to a Schwartz function

All goals completed! 🐙

B.6. Gradient of constant distributions

@[simp] lemma distGrad_const {d} (c : ) : ∇ᵈ (Distribution.const (Space d) c) = 0 := d:c:∇ᵈ (const (Space d) c) = 0 d:c:ε:𝓢(Space d, )i:Fin d((∇ᵈ (const (Space d) c)) ε).ofLp i = (0 ε).ofLp i All goals completed! 🐙

B.7. The gradient of a Schwartz map

lemma gradSchwartz_apply_eq_grad {d} (η : 𝓢(Space d, )) (x : Space d) : gradSchwartz η x = η x := d:η:𝓢(Space d, )x:Space d(gradSchwartz η) x = (⇑η) x d:η:𝓢(Space d, )x:Space d x_1, (fderiv (⇑η) x) (basis x_1) EuclideanSpace.single x_1 1 = i, deriv i (⇑η) x EuclideanSpace.single i 1 All goals completed! 🐙