Imports
/- Copyright (c) 2025 Tomas Skrivan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tomas Skrivan, Joseph Tooby-Smith -/ module public import Physlib.Mathematics.VariationalCalculus.IsTestFunction public import Mathlib.Analysis.Calculus.BumpFunction.InnerProduct

Fundamental lemma of the calculus of variations

The key took in variational calculus is:

∀ h, ∫ x, f x * h x = 0 → f = 0

which allows use to go from reasoning about integrals to reasoning about functions.

Overview of variational calculus

The variational calculus API in Physlib is designed to match and formalize the physicists intuition of variational calculus. It is not designed to be a general API for variational calculus.

Within variational caclulus we are interested in function transformations, F : (X → U) → (Y → V). In physics this functional is often of the form L : (Time → U) → Time → ℝ, which represents the Lagrangian of a system. We will use this to explain the formalization within this API.

The action is nominally given by $$S[u] = \int L(u, t) dt,$$ however it is convenient to introduce another function φ and define the action as $$S[u] = \int φ(t) L(u, t) dt.$$ In the end we will set φ := fun _ => 1.

We now consider $$\frac{\partial}{\partial s} S[u + s * \delta u]$$ at s = 0, which is the variational derivative of S at u in the direction δu. This is equal to $$ \int φ(t) * \left. \frac{\partial}{\partial s} L(u + s * \delta u, t)\right|{s = 0}dt $$ Let us denote the function $$ \delta u,, t \mapsto \left. \frac{\partial}{\partial s} L(u + s * \delta u, t)\right|{s = 0} $$ as Lᵤ : (Time → U) → (Time → ℝ). Then the variational derivative is $$\int φ (t) Lᵤ(δu, t) dt.$$

It may then be possible to find a function Gᵤ : (Time → ℝ) → Time → U such that $$ \int φ(t) Lᵤ(δu, t) dt = \int \langle Gᵤ(φ, t), δu(t)\rangle dt $$ This is usually done by integration by parts.

We now set φ := fun _ => 1 and get grad u := Gᵤ (fun _ => 1), which is the variational gradient at u. The Euler–Lagrange equations, for example, are then grad u = 0.

In our API, the relationship between

    Lᵤ and Gᵤ is captured by the HasVarAdjoint.

    L and Gᵤ by HasVarAdjDeriv.

    L and grad u by HasVarGradientAt.

In practice we assume that L has a certain locality property IsLocalizedFunctionTransform, which allows us to work with functions φ and δu which have compact support.

This API assumes that U is an inner-product space. This can be considered as the full configuration space, or a local chart thereof.

References

    https://leanprover.zulipchat.com/#narrow/channel/479953-Physlib/topic/Variational.20Calculus/with/529022834

@[expose] public section

A version of fundamental_theorem_of_variational_calculus' for Continuous f. The proof uses assumption that source of f is finite-dimensional inner-product space, so that a bump function with compact support exists via ContDiffBump.hasCompactSupport from Analysis.Calculus.BumpFunction.Basic.

The proof is by contradiction, assume that there is x₀ such that f x₀ ≠ 0 then one construct construct g test function supported on the neighborhood of x₀ such that ⟪f x, g x⟫ ≥ 0 and ⟪f x, g x⟫ > 0 on a neighborhood of x₀.

Using Y for the theorem below to make use of bump functions in InnerProductSpaces. Y is a finite dimensional measurable space over with (standard) inner product.

V:Type u_2inst✝⁹:NormedAddCommGroup Vinst✝⁸:NormedSpace Vinst✝⁷:InnerProductSpace' VY:Type u_1inst✝⁶:NormedAddCommGroup Yinst✝⁵:InnerProductSpace Yinst✝⁴:FiniteDimensional Yinst✝³:MeasurableSpace Yf:Y Vμ:Measure Yinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Yhf:Continuous fhg: (g : Y V), IsTestFunction g (x : Y), f x, g x⟫_ μ = 0h₀:¬ (x : Y), f x = 0 xx₀:Yhx0:¬f x₀ = 0f₂:Y WithLp 2 V := (toL2 ) fx₂:WithLp 2 V := f₂ x₀hx2:x₂ 0hcont₂:ContinuousAt f₂ x₀δ₂:hδ₂_pos:δ₂ > 0hδ₂: x : Y⦄, dist x x₀ < δ₂ dist (f₂ x) (f₂ x₀) < x₂ / 2inner_pos₂: x Metric.ball x₀ δ₂, 0 < f₂ x, x₂⟫_inner_pos_V: x Metric.ball x₀ δ₂, 0 < f x, f x₀⟫_φ:Y hφ_testfun:IsTestFunction φhφ_pos_x₀:φ x₀ > 0hφ_non_neg: x Function.support φ, 0 φ xhφ_support_subset:Function.support φ Metric.ball x₀ (δ₂ / 2)hφ_pos_inner: x Metric.closedBall x₀ (δ₂ / 4), 0 < φ xg:Y V := fun x => φ x f x₀hg_test:IsTestFunction gkey_integral: (x : Y), φ x * f x, f x₀⟫_ μ = 0support_subset:Function.support φ Metric.ball x₀ δ₂supp_subset2:(Function.support fun x => φ x * f x, f x₀⟫_) Function.support φhinner_cont:Continuous fun x => f x, f x₀⟫_integrable_prod:Integrable (fun x => φ x * f x, f x₀⟫_) μh_nonneg: (x : Y), 0 φ x * f x, f x₀⟫_hμ_ball:0 < μ (Metric.ball x₀ (δ₂ / 4)):0 < μ (Metric.closedBall x₀ (δ₂ / 4))closedBall_subset_support:Metric.closedBall x₀ (δ₂ / 4) Function.support fun x => φ x * f x, f x₀⟫_False -- [4.2.4] putting everything together: positivity contradicts `key_integral : ∫ ... = 0` V:Type u_2inst✝⁹:NormedAddCommGroup Vinst✝⁸:NormedSpace Vinst✝⁷:InnerProductSpace' VY:Type u_1inst✝⁶:NormedAddCommGroup Yinst✝⁵:InnerProductSpace Yinst✝⁴:FiniteDimensional Yinst✝³:MeasurableSpace Yf:Y Vμ:Measure Yinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Yhf:Continuous fhg: (g : Y V), IsTestFunction g (x : Y), f x, g x⟫_ μ = 0h₀:¬ (x : Y), f x = 0 xx₀:Yhx0:¬f x₀ = 0f₂:Y WithLp 2 V := (toL2 ) fx₂:WithLp 2 V := f₂ x₀hx2:x₂ 0hcont₂:ContinuousAt f₂ x₀δ₂:hδ₂_pos:δ₂ > 0hδ₂: x : Y⦄, dist x x₀ < δ₂ dist (f₂ x) (f₂ x₀) < x₂ / 2inner_pos₂: x Metric.ball x₀ δ₂, 0 < f₂ x, x₂⟫_inner_pos_V: x Metric.ball x₀ δ₂, 0 < f x, f x₀⟫_φ:Y hφ_testfun:IsTestFunction φhφ_pos_x₀:φ x₀ > 0hφ_non_neg: x Function.support φ, 0 φ xhφ_support_subset:Function.support φ Metric.ball x₀ (δ₂ / 2)hφ_pos_inner: x Metric.closedBall x₀ (δ₂ / 4), 0 < φ xg:Y V := fun x => φ x f x₀hg_test:IsTestFunction gkey_integral: (x : Y), φ x * f x, f x₀⟫_ μ = 0support_subset:Function.support φ Metric.ball x₀ δ₂supp_subset2:(Function.support fun x => φ x * f x, f x₀⟫_) Function.support φhinner_cont:Continuous fun x => f x, f x₀⟫_integrable_prod:Integrable (fun x => φ x * f x, f x₀⟫_) μh_nonneg: (x : Y), 0 φ x * f x, f x₀⟫_hμ_ball:0 < μ (Metric.ball x₀ (δ₂ / 4)):0 < μ (Metric.closedBall x₀ (δ₂ / 4))closedBall_subset_support:Metric.closedBall x₀ (δ₂ / 4) Function.support fun x => φ x * f x, f x₀⟫_integral_pos:0 < (x : Y), φ x * f x, f x₀⟫_ μFalse All goals completed! 🐙
X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf':(fun x => f x, f x⟫_) = 0f = 0X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf':(fun x => f x, f x⟫_) =ᵐ[μ] 0Continuous fun x => f x, f x⟫_X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf':(fun x => f x, f x⟫_) =ᵐ[μ] 0Continuous 0 X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf':(fun x => f x, f x⟫_) = 0f = 0 X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf':(fun x => f x, f x⟫_) = 0x:Xf x = 0 x X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf':(fun x => f x, f x⟫_) = 0x:Xhf'':f x, f x⟫_ = 0 xf x = 0 x All goals completed! 🐙 X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf':(fun x => f x, f x⟫_) =ᵐ[μ] 0Continuous fun x => f x, f x⟫_ X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf✝:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf':(fun x => f x, f x⟫_) =ᵐ[μ] 0hf:Continuous fContinuous fun x => f x, f x⟫_ All goals completed! 🐙 X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf':(fun x => f x, f x⟫_) =ᵐ[μ] 0Continuous 0 All goals completed! 🐙 X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf': (x : X), f x, f x⟫_ μ = 00 fun x => f x, f x⟫_ X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf': (x : X), f x, f x⟫_ μ = 0x:X0 x (fun x => f x, f x⟫_) x X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf': (x : X), f x, f x⟫_ μ = 0x:X0 f x, f x⟫_ All goals completed! 🐙 X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf': (x : X), f x, f x⟫_ μ = 0Integrable (fun x => f x, f x⟫_) μ X:Type u_1inst✝⁸:NormedAddCommGroup Xinst✝⁷:NormedSpace Xinst✝⁶:MeasurableSpace XV:Type u_2inst✝⁵:NormedAddCommGroup Vinst✝⁴:NormedSpace Vinst✝³:InnerProductSpace' Vf:X Vμ:Measure Xinst✝²:IsFiniteMeasureOnCompacts μinst✝¹:μ.IsOpenPosMeasureinst✝:OpensMeasurableSpace Xhf:IsTestFunction fhg: (g : X V), IsTestFunction g (x : X), f x, g x⟫_ μ = 0hf': (x : X), f x, f x⟫_ μ = 0IsTestFunction fun x => f x, f x⟫_ All goals completed! 🐙