Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
fe0dc12
refactor: golf TotalDerivativeEquivalence, HarmonicOscillator, Damped…
Vilin97 Jul 6, 2026
c59cf54
refactor: golf total-derivative equivalence proofs
Vilin97 Jul 6, 2026
0a13959
fix: repair damped helper extraction
Vilin97 Jul 6, 2026
d2396f4
refactor: golf HarmonicOscillator trajectory_velocity proof and QFT l…
Vilin97 Jul 6, 2026
e1aa480
refactor: golf isTotalTimeDerivative_explicit and fix IsExtrema proofs
Vilin97 Jul 7, 2026
7600eef
refactor: golf Lagrangian and Curl proofs
Vilin97 Jul 7, 2026
5a6b0fc
refactor: golf planeWave_differentiable_space
Vilin97 Jul 7, 2026
7cf3b52
refactor: golf planeWave and decompose proofs
Vilin97 Jul 8, 2026
fa8dde1
refactor: golf hamiltonian_eq_electricField_scalarPotential
Vilin97 Jul 8, 2026
5a1ac57
refactor: golf iteratedDeriv lemma extraction and exists_curl simplif…
Vilin97 Jul 8, 2026
ff17f0b
refactor: golf decompose_reduce proof
Vilin97 Jul 8, 2026
4b6e5cf
refactor: golf div_of_curl, curl_of_curl, deriv_beta_wrt_T, chain_rul…
Vilin97 Jul 8, 2026
5950932
refactor: golf wave_fderiv_inner_eq_inner_fderiv_proj proof
Vilin97 Jul 8, 2026
b502caa
refactor: golf repeat fun_prop → all_goals fun_prop in 6 files
Vilin97 Jul 8, 2026
f87ea6f
refactor: golf deriv_beta_wrt_T and chain_rule_T_beta proofs
Vilin97 Jul 8, 2026
2a7a4b1
refactor: golf eventually_pos_ofβ proof
Vilin97 Jul 8, 2026
8f6c773
refactor: golf deriv_add, deriv_sub, deriv_coord_add proofs
Vilin97 Jul 8, 2026
c850641
refactor: golf div_linear_map proof
Vilin97 Jul 8, 2026
eed8207
refactor: golf time_deriv_cross_commute proof
Vilin97 Jul 8, 2026
9943d54
refactor: golf HarmonicOscillator, Slice, TimeAndSpace proofs
Vilin97 Jul 8, 2026
2177452
refactor: golf wave_differentiable, planeWave_time/space_deriv proofs
Vilin97 Jul 8, 2026
297f0b0
refactor: golf deriv_sum_inl/inr, time_deriv_curl_commute proofs
Vilin97 Jul 8, 2026
e1461dc
refactor: golf solidSphere_mass proof
Vilin97 Jul 8, 2026
d1b2204
refactor: golf damped-velocity, trajectory-acceleration, time-deriv-c…
Vilin97 Jul 8, 2026
aa66fa7
refactor: golf potentialEnergy_deriv proof
Vilin97 Jul 8, 2026
2b53703
refactor: golf gradient_dist_normPowerSeries_zpow, log, and their ten…
Vilin97 Jul 8, 2026
5ee3484
refactor: golf distDiv_norm_zpow_smul_repr_self_eq_smul and distLapla…
Vilin97 Jul 8, 2026
d2f4d05
refactor: golf distLaplacian_fundamentalSolution_norm_zpow
Vilin97 Jul 8, 2026
7411460
refactor: golf gradient, Laplacian, and distGrad proofs in Space/Norm
Vilin97 Jul 8, 2026
aaa1f2d
refactor: golf normPowerSeries_zpow_le and blockDiagonal_nonneg proofs
Vilin97 Jul 8, 2026
5effdea
refactor: golf trajectories_unique proof
Vilin97 Jul 8, 2026
e330956
refactor: golf trajectories_unique proof
Vilin97 Jul 8, 2026
84cc3e4
refactor: golf isExtrema_iff_tensors forward direction
Vilin97 Jul 8, 2026
6e08060
refactor: golf force_eq_linear proof
Vilin97 Jul 8, 2026
f0e3ce0
refactor: golf isTotalTimeDerivativeVelocity and kineticTerm_eq_sum_f…
Vilin97 Jul 8, 2026
6e077d6
refactor: golf HarmonicOscillator Solution and KineticTerm proofs
Vilin97 Jul 9, 2026
4b51f33
refactor: golf HarmonicOscillator Solution, Basic, and KineticTerm pr…
Vilin97 Jul 10, 2026
3ab2698
refactor: golf trajectory_contDiff, energy_conservation, and velocity…
Vilin97 Jul 10, 2026
4ed162a
refactor: golf normPowerSeries_differentiable proof
Vilin97 Jul 10, 2026
2e4b579
refactor: golf additional proofs in Solution, Basic, Norm, and Canoni…
Vilin97 Jul 10, 2026
242fe50
refactor: golf allowsTermForm_card_le_degree proof
Vilin97 Jul 10, 2026
2f85f1c
refactor: golf kineticTerm_add_time_mul_const proof
Vilin97 Jul 10, 2026
dd53967
refactor: replace simpa with simp and remove unused simp args
Vilin97 Jul 10, 2026
2c07dca
refactor: golf HarmonicOscillator, TotalDerivativeEquivalence, Kineti…
Vilin97 Jul 10, 2026
e0f3ef4
refactor: golf return_time, trajectories_unique, and isExtrema magnet…
Vilin97 Jul 10, 2026
fc0e9cc
fix: resolve compilation errors in IsExtrema and TotalDerivativeEquiv…
Vilin97 Jul 10, 2026
096dc41
fix: restore compilation of HarmonicOscillator, PhysHermite, WickCont…
Vilin97 Jul 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ lemma equationOfMotion_iff_newtons_2nd_law (xₜ : Time → EuclideanSpace ℝ (
have ha :
S.m • ∂ₜ (∂ₜ xₜ) t = -(S.γ • ∂ₜ xₜ t + S.k • xₜ t) :=
eq_neg_of_add_eq_zero_left h'
simpa [sub_eq_add_neg, neg_add, add_comm] using ha
simpa [force, sub_eq_add_neg, neg_add, add_comm] using ha
· intro h t
rw [h t]
module
Expand Down
74 changes: 29 additions & 45 deletions Physlib/ClassicalMechanics/DampedHarmonicOscillator/Solution.lean
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,13 @@ private lemma exp_decay_smul_velocity
∂ₜ (fun t : Time => exp (-a * t.val) • y t) =
fun t : Time => exp (-a * t.val) • (∂ₜ y t - a • y t) := by
funext t
rw [Time.deriv]
rw [fderiv_fun_smul (by fun_prop) (hy t)]
rw [fderiv_exp (by fun_prop), fderiv_fun_mul (by fun_prop) (by fun_prop)]
rw [Time.deriv, fderiv_fun_smul (by fun_prop) (hy t), fderiv_exp (by fun_prop),
fderiv_fun_mul (by fun_prop) (by fun_prop)]
simp only [add_apply, ContinuousLinearMap.smulRight_apply,
fderiv_fun_neg, fderiv_fun_const, Pi.zero_apply, Time.fderiv_val,
_root_.neg_apply, FunLike.coe_smul, Pi.smul_apply, smul_eq_mul]
rw [← Time.deriv_eq]
simp [smul_sub, smul_smul]
module
simp [smul_smul, sub_eq_add_neg]

private lemma exp_decay_smul_acceleration
(a μ : ℝ) (y : Time → EuclideanSpace ℝ (Fin 1))
Expand All @@ -197,11 +195,9 @@ private lemma exp_decay_smul_acceleration
(μ • y t - (2 * a) • ∂ₜ y t + a^2 • y t) := by
rw [exp_decay_smul_velocity a y hy]
funext t
rw [Time.deriv]
rw [fderiv_fun_smul (by fun_prop) (by fun_prop)]
rw [fderiv_exp (by fun_prop), fderiv_fun_mul (by fun_prop) (by fun_prop)]
rw [fderiv_fun_sub (hdy t) (by fun_prop)]
rw [fderiv_fun_const_smul (hy t)]
rw [Time.deriv, fderiv_fun_smul (by fun_prop) (by fun_prop),
fderiv_exp (by fun_prop), fderiv_fun_mul (by fun_prop) (by fun_prop),
fderiv_fun_sub (hdy t) (by fun_prop), fderiv_fun_const_smul (hy t)]
have hy''_t := congrFun hy'' t
rw [Time.deriv] at hy''_t
simp only [add_apply, _root_.sub_apply,
Expand All @@ -210,7 +206,7 @@ private lemma exp_decay_smul_acceleration
FunLike.coe_smul, Pi.smul_apply, smul_eq_mul]
rw [hy''_t, ← Time.deriv_eq]
simp [smul_add, smul_sub, smul_smul]
module
ext i; simp; ring

private lemma exp_decay_smul_equationOfMotion
(a μ : ℝ) (y : Time → EuclideanSpace ℝ (Fin 1))
Expand All @@ -219,11 +215,10 @@ private lemma exp_decay_smul_equationOfMotion
(hγ : S.γ = 2 * S.m * a) (hk : S.k = S.m * (a^2 - μ)) :
S.EquationOfMotion (fun t : Time => exp (-a * t.val) • y t) := by
intro t
rw [exp_decay_smul_acceleration a μ y hy hdy hy'']
rw [exp_decay_smul_velocity a y hy]
rw [hγ, hk]
rw [exp_decay_smul_acceleration a μ y hy hdy hy'', exp_decay_smul_velocity a y hy,
hγ, hk]
simp [smul_add, smul_sub, smul_smul]
module
ext i; simp; ring

/-!

Expand All @@ -234,12 +229,17 @@ polynomial, and hyperbolic base trajectories before the exponential decay factor

-/

private lemma fderiv_comp_val_eq_deriv {t : Time} (g : ℝ → ℝ)
(hg : DifferentiableAt ℝ g t.val) :
(fderiv ℝ (fun s : Time => g s.val) t) 1 = _root_.deriv g t.val := by
rw [fderiv_fun_comp t hg (by fun_prop), ContinuousLinearMap.comp_apply, Time.fderiv_val]
simp

private lemma criticallyDampedBase_velocity (IC : InitialConditions) :
∂ₜ (S.criticallyDampedBase IC) =
fun _ : Time => IC.v₀ + S.decayRate • IC.x₀ := by
funext t
change ∂ₜ (fun t : Time =>
IC.x₀ + t.val • (IC.v₀ + S.decayRate • IC.x₀)) t = _
unfold criticallyDampedBase
rw [Time.deriv_eq, fderiv_fun_add (by fun_prop) (by fun_prop),
fderiv_fun_const, fderiv_smul_const (by fun_prop)]
simp
Expand All @@ -262,11 +262,6 @@ private lemma underdampedBase_velocity (IC : InitialConditions) (hS : S.IsUnderd
(IC.v₀ + S.decayRate • IC.x₀) := by
have hΩ : S.angularFrequency ≠ 0 := S.angularFrequency_ne_zero_of_underdamped hS
funext t
have fderiv_comp_val_eq_deriv : ∀ g : ℝ → ℝ, DifferentiableAt ℝ g t.val →
(fderiv ℝ (fun s : Time => g s.val) t) 1 = _root_.deriv g t.val := by
intro g hg
rw [fderiv_fun_comp t hg (by fun_prop), ContinuousLinearMap.comp_apply, Time.fderiv_val]
simp
rw [Time.deriv_eq, fderiv_fun_add (by fun_prop) (by fun_prop),
fderiv_smul_const (by fun_prop), fderiv_smul_const (by fun_prop)]
simp only [add_apply, ContinuousLinearMap.smulRight_apply]
Expand All @@ -287,11 +282,6 @@ private lemma underdampedBase_acceleration (IC : InitialConditions) (hS : S.IsUn
have hΩ : S.angularFrequency ≠ 0 := S.angularFrequency_ne_zero_of_underdamped hS
rw [S.underdampedBase_velocity IC hS]
funext t
have fderiv_comp_val_eq_deriv : ∀ g : ℝ → ℝ, DifferentiableAt ℝ g t.val →
(fderiv ℝ (fun s : Time => g s.val) t) 1 = _root_.deriv g t.val := by
intro g hg
rw [fderiv_fun_comp t hg (by fun_prop), ContinuousLinearMap.comp_apply, Time.fderiv_val]
simp
rw [Time.deriv_eq, fderiv_fun_add (by fun_prop) (by fun_prop),
fderiv_smul_const (by fun_prop), fderiv_smul_const (by fun_prop)]
simp only [add_apply, ContinuousLinearMap.smulRight_apply]
Expand All @@ -312,11 +302,6 @@ private lemma overdampedBase_velocity (IC : InitialConditions) (hS : S.IsOverdam
(IC.v₀ + S.decayRate • IC.x₀) := by
have hΩ : S.angularFrequency ≠ 0 := S.angularFrequency_ne_zero_of_overdamped hS
funext t
have fderiv_comp_val_eq_deriv : ∀ g : ℝ → ℝ, DifferentiableAt ℝ g t.val →
(fderiv ℝ (fun s : Time => g s.val) t) 1 = _root_.deriv g t.val := by
intro g hg
rw [fderiv_fun_comp t hg (by fun_prop), ContinuousLinearMap.comp_apply, Time.fderiv_val]
simp
rw [Time.deriv_eq, fderiv_fun_add (by fun_prop) (by fun_prop),
fderiv_smul_const (by fun_prop), fderiv_smul_const (by fun_prop)]
simp only [add_apply, ContinuousLinearMap.smulRight_apply]
Expand All @@ -337,11 +322,6 @@ private lemma overdampedBase_acceleration (IC : InitialConditions) (hS : S.IsOve
have hΩ : S.angularFrequency ≠ 0 := S.angularFrequency_ne_zero_of_overdamped hS
rw [S.overdampedBase_velocity IC hS]
funext t
have fderiv_comp_val_eq_deriv : ∀ g : ℝ → ℝ, DifferentiableAt ℝ g t.val →
(fderiv ℝ (fun s : Time => g s.val) t) 1 = _root_.deriv g t.val := by
intro g hg
rw [fderiv_fun_comp t hg (by fun_prop), ContinuousLinearMap.comp_apply, Time.fderiv_val]
simp
rw [Time.deriv_eq, fderiv_fun_add (by fun_prop) (by fun_prop),
fderiv_smul_const (by fun_prop), fderiv_smul_const (by fun_prop)]
simp only [add_apply, ContinuousLinearMap.smulRight_apply]
Expand Down Expand Up @@ -375,8 +355,9 @@ lemma trajectory_equationOfMotion_of_criticallyDamped (IC : InitialConditions)
fun_prop)
(by
rw [S.criticallyDampedBase_velocity IC]
fun_prop) ?_ hγ hk
simpa using S.criticallyDampedBase_acceleration IC
fun_prop)
(by
simpa using S.criticallyDampedBase_acceleration IC) hγ hk

/-- In the underdamped regime, the selected trajectory satisfies the damped equation of
motion. -/
Expand All @@ -388,13 +369,14 @@ lemma trajectory_equationOfMotion_of_underdamped (IC : InitialConditions)
have hk : S.k = S.m * (S.decayRate^2 - (-S.angularFrequency^2)) := by
rw [S.k_eq_m_mul_ω_sq, S.angularFrequency_sq_of_underdamped hS]
ring
refine S.exp_decay_smul_equationOfMotion S.decayRate
(-S.angularFrequency^2) (S.underdampedBase IC)
refine S.exp_decay_smul_equationOfMotion S.decayRate (-S.angularFrequency^2)
(S.underdampedBase IC)
(by
unfold underdampedBase
fun_prop) ?_
(S.underdampedBase_acceleration IC hS) hγ hk
rw [show ∂ₜ (S.underdampedBase IC) = _ from S.underdampedBase_velocity IC hS]
unfold underdampedBase
rw [S.underdampedBase_velocity IC hS]
fun_prop

/-- In the overdamped regime, the selected trajectory satisfies the damped equation of
Expand All @@ -413,7 +395,8 @@ lemma trajectory_equationOfMotion_of_overdamped (IC : InitialConditions)
unfold overdampedBase
fun_prop) ?_
(S.overdampedBase_acceleration IC hS) hγ hk
rw [show ∂ₜ (S.overdampedBase IC) = _ from S.overdampedBase_velocity IC hS]
unfold overdampedBase
rw [S.overdampedBase_velocity IC hS]
fun_prop

/-- The selected trajectory satisfies the damped equation of motion. -/
Expand All @@ -424,8 +407,9 @@ lemma trajectory_equationOfMotion (IC : InitialConditions) :
· by_cases hCritical : S.IsCriticallyDamped
· exact S.trajectory_equationOfMotion_of_criticallyDamped IC hCritical
· have hOver : S.IsOverdamped := by
rw [IsOverdamped, IsUnderdamped] at *
exact lt_of_le_of_ne (not_lt.mp hUnder) (Ne.symm hCritical)
dsimp [IsOverdamped, IsUnderdamped, IsCriticallyDamped] at hUnder hCritical ⊢
have hle : 0 ≤ S.discriminant := not_lt.mp hUnder
exact lt_of_le_of_ne hle (Ne.symm hCritical)
exact S.trajectory_equationOfMotion_of_overdamped IC hOver

/-!
Expand Down
89 changes: 20 additions & 69 deletions Physlib/ClassicalMechanics/HarmonicOscillator/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ lemma kineticEnergy_deriv (xₜ : Time → EuclideanSpace ℝ (Fin 1)) (hx : Con
congr 1
simp only [smul_add]
module
repeat fun_prop
all_goals fun_prop

lemma potentialEnergy_deriv (xₜ : Time → EuclideanSpace ℝ (Fin 1)) (hx : ContDiff ℝ ∞ xₜ) :
∂ₜ (fun t => potentialEnergy S (xₜ t)) = fun t => ⟪∂ₜ xₜ t, S.k • xₜ t⟫_ℝ := by
Expand All @@ -293,10 +293,7 @@ lemma potentialEnergy_deriv (xₜ : Time → EuclideanSpace ℝ (Fin 1)) (hx : C
congr 1
module
rw [real_inner_comm, ← inner_smul_right]
repeat fun_prop
apply Differentiable.differentiableAt
rw [contDiff_infty_iff_fderiv] at hx
exact hx.1
all_goals (first | fun_prop | exact ((contDiff_infty_iff_fderiv.mp hx).1 t))

lemma energy_deriv (xₜ : Time → EuclideanSpace ℝ (Fin 1)) (hx : ContDiff ℝ ∞ xₜ) :
∂ₜ (energy S xₜ) = fun t => ⟪∂ₜ xₜ t, S.m • ∂ₜ (∂ₜ xₜ) t + S.k • xₜ t⟫_ℝ := by
Expand All @@ -309,8 +306,7 @@ lemma energy_deriv (xₜ : Time → EuclideanSpace ℝ (Fin 1)) (hx : ContDiff
rw [potentialEnergy_deriv, kineticEnergy_deriv]
simp only
rw [← inner_add_right]
fun_prop
fun_prop
all_goals fun_prop

/-!

Expand Down Expand Up @@ -374,19 +370,7 @@ The lagrangian is smooth in all its arguments.
@[fun_prop]
lemma contDiff_lagrangian (n : WithTop ℕ∞) : ContDiff ℝ n ↿S.lagrangian := by
rw [lagrangian_eq]
apply ContDiff.sub
· apply ContDiff.mul
· apply ContDiff.mul
· exact contDiff_const
· exact contDiff_const
· exact ContDiff.inner (𝕜 := ℝ) (contDiff_snd.comp contDiff_snd)
(contDiff_snd.comp contDiff_snd)
· apply ContDiff.mul
· apply ContDiff.mul
· exact contDiff_const
· exact contDiff_const
· exact ContDiff.inner (𝕜 := ℝ) (contDiff_fst.comp contDiff_snd)
(contDiff_fst.comp contDiff_snd)
fun_prop

lemma toDual_symm_innerSL (x : EuclideanSpace ℝ (Fin 1)) :
(InnerProductSpace.toDual ℝ (EuclideanSpace ℝ (Fin 1))).symm (innerSL ℝ x) = x := by
Expand All @@ -400,8 +384,6 @@ lemma gradient_inner_self (x : EuclideanSpace ℝ (Fin 1)) :
unfold gradient
rw [InnerProductSpace.toDual_symm_apply]
have hid : DifferentiableAt ℝ (fun y : EuclideanSpace ℝ (Fin 1) => y) x := differentiableAt_id
rw [show (fun y : EuclideanSpace ℝ (Fin 1) => ⟪y, y⟫_ℝ) =
fun y => ⟪(fun y => y) y, (fun y => y) y⟫_ℝ from rfl]
rw [fderiv_inner_apply (𝕜 := ℝ) hid hid]
simp only [fderiv_fun_id, ContinuousLinearMap.coe_id', id_eq, real_inner_comm, inner_smul_left',
ringHom_apply]
Expand All @@ -418,10 +400,8 @@ lemma gradient_const_mul_inner_self (c : ℝ) (x : EuclideanSpace ℝ (Fin 1)) :
rw [fderiv_const_mul]; fun_prop
_ = c • gradient (fun y : EuclideanSpace ℝ (Fin 1) => ⟪y, y⟫_ℝ) x := by
simp only [gradient, map_smul]
_ = c • ((2 : ℝ) • x) := by
rw [gradient_inner_self]
_ = (2 * c) • x := by
rw [smul_smul, mul_comm]
_ = c • ((2 : ℝ) • x) := by rw [gradient_inner_self]
_ = (2 * c) • x := by rw [smul_smul, mul_comm]

/-!

Expand Down Expand Up @@ -550,17 +530,9 @@ We now show that the force is equal to `- k x`.
/-- The force on the classical harmonic oscillator is `- k x`. -/
lemma force_eq_linear (x : EuclideanSpace ℝ (Fin 1)) : force S x = - S.k • x := by
unfold force potentialEnergy
have hpot : (fun y : EuclideanSpace ℝ (Fin 1) => (1 / (2 : ℝ)) • S.k • ⟪y, y⟫_ℝ) =
fun y => ((1 / (2 : ℝ)) * S.k) * ⟪y, y⟫_ℝ := by
funext y
simp [smul_eq_mul, mul_assoc]
rw [hpot]
have hgrad : gradient (fun y : EuclideanSpace ℝ (Fin 1) => ((1 / (2 : ℝ)) * S.k) * ⟪y, y⟫_ℝ) x
= S.k • x := by
simpa [smul_eq_mul, mul_assoc] using
(gradient_const_mul_inner_self (c := (1 / (2 : ℝ)) * S.k) x)
rw [hgrad]
simp [neg_smul]
simp only [smul_eq_mul]
simpa [mul_assoc] using congrArg Neg.neg
(gradient_const_mul_inner_self (c := (1/2) * S.k) x)

/-!

Expand All @@ -578,19 +550,8 @@ lemma gradLagrangian_eq_force (xₜ : Time → EuclideanSpace ℝ (Fin 1)) (hx :
rw [gradLagrangian_eq_eulerLagrangeOp S xₜ hx, eulerLagrangeOp]
congr
· simp [gradient_lagrangian_position_eq, force_eq_linear]
· conv_lhs =>
arg 1
ext t'
rw [gradient_lagrangian_velocity_eq]
show ∂ₜ (fun t' => S.m • ∂ₜ xₜ t') t = S.m • ∂ₜ (∂ₜ xₜ) t
have hd : DifferentiableAt ℝ (∂ₜ xₜ) t :=
(deriv_differentiable_of_contDiff xₜ hx).differentiableAt
calc
∂ₜ (fun t' => S.m • ∂ₜ xₜ t') t
= fderiv ℝ (fun t' => S.m • ∂ₜ xₜ t') t 1 := rfl
_ = S.m • (fderiv ℝ (∂ₜ xₜ) t 1) := by
exact congrArg (fun L => L 1) (fderiv_const_smul (c := S.m) (f := ∂ₜ xₜ) hd)
_ = S.m • ∂ₜ (∂ₜ xₜ) t := rfl
· simp [gradient_lagrangian_velocity_eq, Time.deriv_smul (∂ₜ xₜ) S.m
(deriv_differentiable_of_contDiff xₜ hx)]

/-!

Expand Down Expand Up @@ -636,9 +597,7 @@ lemma energy_conservation_of_equationOfMotion (xₜ : Time → EuclideanSpace
rw [energy_deriv _ _ hx]
rw [equationOfMotion_iff_newtons_2nd_law _ _ hx] at h
funext x
simp only [Pi.zero_apply]
rw [h]
simp [force_eq_linear]
simp [h x, force_eq_linear]

/-!

Expand Down Expand Up @@ -783,17 +742,15 @@ We now write down the gradients of the Hamiltonian with respect to the momentum
lemma gradient_hamiltonian_position_eq (t : Time) (x : EuclideanSpace ℝ (Fin 1))
(p : EuclideanSpace ℝ (Fin 1)) :
gradient (hamiltonian S t p) x = S.k • x := by
have h_eq : (fun y : EuclideanSpace ℝ (Fin 1) => hamiltonian S t p y) =
fun y => ((1 / (2 : ℝ)) * S.k) * ⟪y, y⟫_ℝ +
have h_eq : hamiltonian S t p = fun y : EuclideanSpace ℝ (Fin 1) =>
((1 / (2 : ℝ)) * S.k) * ⟪y, y⟫_ℝ +
((1 / (2 : ℝ)) * (1 / S.m) * ⟪p, p⟫_ℝ) := by
funext y; unfold hamiltonian; simp only [toCanonicalMomentum, lagrangian, one_div,
ext y; unfold hamiltonian; simp only [toCanonicalMomentum, lagrangian, one_div,
inner_self_eq_norm_sq_to_K, ringHom_apply, potentialEnergy, smul_eq_mul,
LinearEquiv.coe_symm_mk', inner_smul_right, norm_smul, norm_inv, norm_eq_abs]
have hm : S.m ≠ 0 := m_ne_zero S
field_simp
ring_nf
simp [mul_two]
change gradient (fun y : EuclideanSpace ℝ (Fin 1) => hamiltonian S t p y) x = S.k • x
simp [sq_abs]
ring
rw [h_eq, gradient_add_const', gradient_const_mul_inner_self]
ext; simp

Expand All @@ -806,11 +763,9 @@ lemma gradient_hamiltonian_momentum_eq (t : Time) (x : EuclideanSpace ℝ (Fin 1
funext y; unfold hamiltonian; simp only [toCanonicalMomentum, lagrangian, one_div,
inner_self_eq_norm_sq_to_K, ringHom_apply, potentialEnergy, smul_eq_mul,
LinearEquiv.coe_symm_mk', inner_smul_right, norm_smul, norm_inv, norm_eq_abs]
have hm : S.m ≠ 0 := m_ne_zero S
field_simp
ring_nf
simp [mul_two]
change gradient (fun y : EuclideanSpace ℝ (Fin 1) => hamiltonian S t y x) p = (1 / S.m) • p
simp [sq_abs]
ring
rw [h_eq, gradient_add_const', gradient_const_mul_inner_self]
ext; simp

Expand All @@ -831,11 +786,7 @@ lemma hamiltonian_eq_energy (xₜ : Time → EuclideanSpace ℝ (Fin 1)) :
rw [← toCanonicalMomentum_eq (S := S) (t := t) (x := xₜ t) (v := ∂ₜ xₜ t)]
exact LinearEquiv.symm_apply_apply (toCanonicalMomentum S t (xₜ t)) (∂ₜ xₜ t)
unfold hamiltonian lagrangian energy kineticEnergy potentialEnergy
simp only [toCanonicalMomentum_eq, inner_smul_left, one_div, smul_eq_mul]
rw [hsymm]
ring_nf
simp only [ringHom_apply, inner_self_eq_norm_sq_to_K, one_div, add_left_inj]
field_simp
simp [toCanonicalMomentum_eq, inner_smul_left, one_div, smul_eq_mul, hsymm]
ring

/-!
Expand Down
Loading