Physlib.Mathematics.Calculus.Gradient
Elementary rules for the gradient
i. Overview
Mathlib defines the gradient `∇ f x` of a real-valued function on a real Hilbert space as the Riesz representative of its Fréchet derivative, but records no rules for the algebraic operations on `f` beyond constants. This file collects the elementary rules used throughout the classical mechanics of Physlib: a gradient is unchanged by adding a constant, it commutes with multiplication by a constant, the gradient of the quadratic form `⟪y, y⟫` is `2 • y`, and the gradient of a coordinate functional on Euclidean space is the corresponding basis vector.
These are the rules needed to differentiate Lagrangians and Hamiltonians of the form `kinetic − potential` with respect to positions and velocities.
These are rules for Mathlib's `gradient` on an abstract real Hilbert space. They are distinct from `Physlib.SpaceAndTime.Space.Derivatives.Grad`, whose `Space.grad` is a coordinate-valued operator on the structure `Space d`; nothing there applies to `EuclideanSpace ℝ (Fin 1)` or to a general inner product space. The file is deliberately real: two of its rules (`gradient_const_mul` and `gradient_inner_self`) are specific to real scalars, so the remaining ones are stated over `ℝ` as well.
ii. Key results
- `gradient_add_const` : `∇ (f + c) = ∇ f`. - `gradient_const_mul` : `∇ (c * f) = c • ∇ f` for differentiable `f`. - `gradient_inner_self` : `∇ (fun y => ⟪y, y⟫) x = 2 • x`. - `gradient_const_mul_inner_self` : `∇ (fun y => c * ⟪y, y⟫) x = (2 * c) • x`. - `gradient_coord` : `∇ (fun y => y i) x = EuclideanSpace.single i 1`. - `gradient_comp_coord` : `∇ (fun y => f (y i)) x = f' • EuclideanSpace.single i 1` when `HasDerivAt f f' (x i)`.
iii. Table of contents
- A. Gradients and constants
- B. Gradients of quadratic forms
- C. Coordinate functionals on Euclidean space
iv. References
- Mathlib, `Mathlib.Analysis.Calculus.Gradient.Basic`.
A. Gradients and constants
Adding a constant does not change the Fréchet derivative, hence not the gradient; multiplying by a constant scales both.
B. Gradients of quadratic forms
The quadratic form `y ↦ ⟪y, y⟫` has derivative `v ↦ 2 ⟪x, v⟫` at `x`, whose Riesz representative is `2 • x`.
C. Coordinate functionals on Euclidean space
The coordinate functional `y ↦ y i` on `EuclideanSpace ℝ ι` is the continuous linear map `EuclideanSpace.proj i`, whose Riesz representative is the basis vector `EuclideanSpace.single i 1`.
6 declarations
Let be a real Hilbert space and be a function. For any constant and any point , the gradient of the function at is equal to the gradient of at . That is, .
for Differentiable
Let be a real Hilbert space and be a real-valued function. For any constant and any point at which is differentiable, the gradient of the function at is equal to the constant multiplied by the gradient of at . In symbols, .
Let be a real Hilbert space. For any , the gradient of the function defined by at the point is given by .
Let be a real inner product space. For any scalar and any point , the gradient of the function at is given by
Let be a finite index set and let denote the real Euclidean space. For any index and any point , the gradient of the -th coordinate functional is equal to the -th standard basis vector (where has a at index and elsewhere).
Let be a finite index set and be a point in the Euclidean space . Let be a function that has a derivative at the -th coordinate of . Then the gradient of the function mapping to at the point is given by where is the -th standard basis vector (represented by `EuclideanSpace.single i 1`).
