@@ -5,6 +5,7 @@ Authors: Tomas Skrivan, Joseph Tooby-Smith
55-/
66import PhysLean.Mathematics.VariationalCalculus.HasVarAdjoint
77import Mathlib.Tactic.FunProp.Differentiable
8+ import Mathlib.Analysis.Calculus.BumpFunction.InnerProduct
89/-!
910
1011# Variational gradient
@@ -61,16 +62,84 @@ HasVarGradientAt
6162inductive HasVarGradientAt (S' : (X → U) → (X → ℝ)) (grad : X → U) (u : X → U)
6263 (μ : Measure X := by volume_tac) : Prop
6364 | intro (F')
64- (adjoint : HasVarAdjoint (fun δu t => deriv (fun s : ℝ => S' (u + s • δu) t) 0 ) F' μ)
65- (eq : F' (fun _ => 1 ) = grad)
65+ (diff : ∀ δu x, IsTestFunction δu →
66+ Differentiable ℝ (fun s : ℝ => S' (fun x' => u x' + s • δu x') x))
67+ (adjoint : HasVarAdjoint (fun δu x => deriv (fun s : ℝ => S' (u + s • δu) x) 0 ) F' μ)
68+ /- This condition is effectivelly saying that `F' (fun _ => 1) = grad` but `F'` is not
69+ guaranteed to produce meaningful result for `fun _ => 1` as it is not test function.
70+ Therefore we require that it is possible to glue `grad` together by -/
71+ (eq : ∀ (x : X), ∃ D : Set X,
72+ x ∈ D ∧ IsCompact D
73+ ∧
74+ ∀ (φ : X → ℝ), IsTestFunction φ → (∀ x ∈ D, φ x = 1 ) → F' φ x = grad x)
75+
76+
77+ lemma HasVarGradientAt.unique
78+ {X : Type *} [NormedAddCommGroup X] [InnerProductSpace ℝ X]
79+ [FiniteDimensional ℝ X] [MeasurableSpace X]
80+ {S' : (X → U) → (X → ℝ)} {grad grad' : X → U} {u : X → U} {μ : Measure X}
81+ [IsFiniteMeasureOnCompacts μ] [μ.IsOpenPosMeasure] [OpensMeasurableSpace X]
82+ (h : HasVarGradientAt S' grad u μ) (h' : HasVarGradientAt S' grad' u μ) :
83+ grad = grad' := by
84+
85+ obtain ⟨F,_,hF,eq⟩ := h
86+ obtain ⟨G,_,hG,eq'⟩ := h'
87+ funext x
88+ obtain ⟨D,hm,hD,hgrad⟩ := eq x
89+ obtain ⟨D',_,hD',hgrad'⟩ := eq' x
90+
91+ -- prepare test function that is one on `D ∪ D'`
92+ let r := sSup ((fun x => ‖x‖) '' (D ∪ D'))
93+ have : 0 ≤ r := by
94+ obtain ⟨x, h1, h2, h3⟩ := IsCompact.exists_sSup_image_eq_and_ge (s := D ∪ D')
95+ (IsCompact.union hD hD') (Set.Nonempty.inl (Set.nonempty_of_mem hm))
96+ (f := fun x => ‖x‖) (by fun_prop)
97+ unfold r
98+ apply le_of_le_of_eq (b := ‖x‖)
99+ · exact norm_nonneg x
100+ · rw [← h2]
101+
102+ let φ : ContDiffBump (0 : X) := {
103+ rIn := r + 1 ,
104+ rOut := r + 2 ,
105+ rIn_pos := by linarith,
106+ rIn_lt_rOut := by linarith}
107+
108+ -- few properties about `φ`
109+ let f := fun x => φ.toFun x
110+ have hφ : IsTestFunction (fun x : X => φ x) := by
111+ constructor
112+ apply ContDiffBump.contDiff
113+ apply ContDiffBump.hasCompactSupport
114+ have hφ' : ∀ x, x ∈ D ∪ D' → x ∈ Metric.closedBall 0 φ.rIn := by
115+ intro x hx
116+ simp [φ, r]
117+ obtain ⟨y, h1, h2, h3⟩ := IsCompact.exists_sSup_image_eq_and_ge (s := D ∪ D')
118+ (IsCompact.union hD hD') (Set.Nonempty.inl (Set.nonempty_of_mem hm))
119+ (f := fun x => ‖x‖) (by fun_prop)
120+ rw [h2]
121+ have h3' := h3 x hx
122+ apply le_trans h3'
123+ simp
124+ have h := hgrad φ hφ
125+ (by intros _ hx; unfold φ; rw[φ.one_of_mem_closedBall]; apply hφ'; simp[hx])
126+ have h' := hgrad' φ hφ
127+ (by intros _ hx; unfold φ; rw[φ.one_of_mem_closedBall]; apply hφ'; simp[hx])
128+ rw[← h, ← h',hF.unique hG φ hφ]
66129
67130/-- Variation of `S(x) = ∫ 1/2*m*‖ẋ‖² - V(x)` gives Newton's law of motion `δS(x) = - m*ẍ - V'(x)`-/
68- example (m : ℝ) (u V : ℝ → ℝ) (hu : ContDiff ℝ ∞ u) (hV : ContDiff ℝ ∞ V) :
131+ lemma euler_lagrange_particle_1d (m : ℝ) (u V : ℝ → ℝ)
132+ (hu : ContDiff ℝ ∞ u) (hV : ContDiff ℝ ∞ V) :
69133 HasVarGradientAt
70134 (fun (u : ℝ → ℝ) (t : ℝ) => 1 /2 * m * deriv u t ^ 2 - V (u t))
71135 (fun t => - m * deriv (deriv u) t - deriv V (u t))
72136 u := by
73137 apply HasVarGradientAt.intro
138+ case diff =>
139+ intro _ _ hδu
140+ have := hδu.1
141+ have : (2 :WithTop ℕ∞) ≤ ∞ := ENat.LEInfty.out
142+ fun_prop (config:={maxTransitionDepth:=2 }) (disch:=aesop) [deriv]
74143 case adjoint =>
75144 eta_expand
76145 have := hu.differentiable ENat.LEInfty.out
@@ -96,4 +165,15 @@ example (m : ℝ) (u V : ℝ → ℝ) (hu : ContDiff ℝ ∞ u) (hV : ContDiff
96165 · apply HasVarAdjoint.mul_left (hψ := by fun_prop)
97166 apply HasVarAdjoint.id
98167 case eq =>
99- simp only [mul_one, deriv_const_mul_field', Pi.neg_apply, neg_mul]
168+ intro x
169+ use (Metric.closedBall x 1 )
170+ constructor
171+ · simp
172+ · constructor
173+ · exact isCompact_closedBall x 1
174+ · intro φ hφ hφ'
175+ simp[hφ',hφ]
176+ have h : (fun x => m * deriv u x * φ x) =ᶠ[nhds x] (fun x => m * deriv u x) :=
177+ Filter.eventuallyEq_of_mem (Metric.closedBall_mem_nhds x Real.zero_lt_one)
178+ (by intro x' hx'; simp[hφ' x' hx'])
179+ simp[h.deriv_eq]
0 commit comments