Derivation of Hamiltonian by constraining $L(q, v, t)$ with $v = \dot{q}$

I am trying to reconstruct a derivation that I encountered a while ago somewhere on the internet, in order to build some intuition both for $$H$$ and $$L$$ in classical mechanics, and for the operation of Legendre transforms. But I can't seem to make the argument work.

The question is: can we derive Hamiltonian mechanics $$H(q, p)$$ by starting with an initial Lagrangian function $$L(q, v, t)$$, assuming no relationship at this point between $$q$$ and $$v$$, and deriving the Euler-Lagrange equations for this Lagrangian with the constraint $$\dot{q} = v$$?

We'd use a Lagrange multiplier: \begin{align} \delta S & = \delta \int dt \left[ L(q(t), v(t), t) + \lambda(t) (\dot{q}(t) - v(t)) \right] \\ & = \int dt \left[ \left( \frac{\partial L}{\partial q} - \dot{\lambda}(t)\right) \delta q(t) + \left( \frac{\partial L}{\partial v} - \lambda(t) \right) \delta v(t) \right] + \left. \lambda(t)\delta q(t)\right|^f_i \end{align} where I've used integration by parts to turn $$\lambda \delta \dot{q}$$ into $$-\dot{\lambda} \delta q$$, spitting out a boundary term which will be zero if the variation vanishes at the endpoints, and ignoring the variation $$\delta \lambda$$ which encodes the constraint itself.

Then, setting the coefficient of $$\delta v$$ to zero gives us $$\lambda(t) = \frac{\partial L}{\partial v} := p(t)$$, and then, plugging this in, the variation w.r.t. $$\delta q(t)$$ produces the regular E-L equation $$\frac{\partial L}{\partial q} = \frac{d}{dt} p = \frac{d}{dt}\frac{\partial L}{\partial \dot{q}}$$. Great.

If we plug $$\lambda = p$$ back in, the expression $$S' = \int dt [L + p\dot{q} - pv]$$ looks like a "Legendre-transformed Action", but with $$pv$$ filling the role normally filled by $$p \dot{q}$$ (at least until you plug the constraint back in):

$$S' = \int dt [ p\dot{q} - (pv - L) ] \stackrel{?}{=} \int dt [ p\dot{q} - H ]$$

But this isn't exactly the same as the typical $$H = p\dot{q} - L$$ formulation, because of the $$v$$ floating around. And I recall from the now-lost source that there is some revealing way to interpret this modified action with the constraint term, $$S'$$, but I can't remember exactly what it is. I find myself very confused about what's going on here.

My specific mathematical questions are:

• In this formulation, how can I establish that this $$H$$ is no longer a function of $$v$$ or $$\dot{q}$$ but only of $$p$$? Given this, the variation of this transformed $$S'$$ readily produces Hamiltonian e.o.m., but I can't see how to support this.
• In a Hamiltonian formulation does this transformed action $$S' = \int dt [p\dot{q} - H]$$ have an interpretation, besides just being "the thing which $$= \int dt L$$? If you started with any old Hamiltonian function, would it be obvious that you could produce a variational equation for its dynamics in this way?
• Is there a way to go back to the $$L$$ formulation via another "constrained extremization"? The $$v = \dot{q}$$ constraint is very intuitive, but I can't see what constraint would go the other direction.

But I'm also just looking for insight on how this approach relates to the typical method. It may be that it's almost exactly the same, but it feels clearer—when I learned this we just sort of asserted that $$H$$ was an interesting thing to think about. Is there a book out there that develops classical mechanics this way?

• If you think of your $v(t)$ as the inverse of $p = \frac{\partial L}{\partial \dot{q}}$ where you solved for $\dot{q}$ as a function of $q$ and $p$, $\dot{q} = v(q,p)$, studying $S = \int L(t,q,v) dt$ means studying $L(t,q,v(q,p))$, where $v$ is some complicated function of $q$ and $p$. Whatever this function is by adding the constraint $\lambda (v - \dot{q})$ you are simply imposing that the result should reduce to the familiar Lagrangian as a function of $q$ and $\dot{q}$. It's basically a brilliant way to establish the Hamiltonian formalism and similar thinking is very common in physics. Commented Dec 1, 2023 at 23:55

This 3-way extended action principle is precisely the topic of my Phys.SE answer here. Concerning OP's main question, the Hamiltonian is defined as the Legendre transform $$H(q,p)~:=~ \sup_v (p_i v^i-L(q,v))$$ of the Lagrangian $$L(q,v)$$.

If you think of your $$v(t)$$ as the inverse of $$p = \frac{\partial L}{\partial \dot{q}}$$ where you solved for $$\dot{q}$$ as a function of $$q$$ and $$p$$, $$\dot{q} = v(q,p)$$, studying $$S = \int L(t,q,v) dt$$ means studying $$L(t,q,v(q,p))$$, where $$v$$ is some complicated function of $$q$$ and $$p$$. Whatever this function is by adding the constraint $$\lambda (v - \dot{q})$$ you are simply imposing that the result should reduce to the familiar Lagrangian as a function of $$q$$ and $$\dot{q}$$. It's basically a brilliant way to establish the Hamiltonian formalism directly without the usual way of needing to take differentials to derive it (see below), and similar thinking is very common in physics (for example this applies a similar idea to the bosonic string), however it simply looks like magic when done this way, and you are assuming that $$q$$ and $$p$$ are initially the variables until you impose the constraint, but you have not explained why $$q$$ and $$p$$ should be the variables.

Since you are likely really just looking for intuition for the Hamiltonian formalism, the best way to gain intuition for what's going on is simply to realize that the Euler-Lagrange equations are 2nd order differential equations. Any second order equation can be turned into a system of coupled first order equations, thus Hamiltonians arise from trying to turn the 2nd order ODE EL equations into a system of coupled 1st order ODEs.

From the EL eq's $$\frac{d}{dt} L_{\dot{q}} = L_q$$ it's completely clear that if we set $$p = L_{\dot{q}}$$ then $$p = L_{\dot{q}}$$ and $$\dot{p} = L_q$$ involves at most first order ODE's.

However everything is written in terms of $$q,\dot{q},p$$, we need to invert $$p = L_{\dot{q}}$$ and solve for $$\dot{q}$$ as a function of $$q$$ and $$p$$. If the $$\dot{q}$$ derivative of $$p = L_{\dot{q}}$$ has non-zero determinant, i.e. the Hessian of $$L$$ w.r.t. the $$\dot{q}$$'s, is non-zero, $$\det(L_{\dot{q}_i \dot{q}_j} ) \neq 0$$, then the inverse/implicit function theorem lets us invert this to set $$\dot{q} = \omega(q,p)$$.

Now $$\dot{q} = \omega(q,p)$$ and $$\dot{p} = L_q$$ are a system of coupled 1st order ODE's. By observation, setting $$H = p \omega - L$$ these equations can be written as $$\dot{q} = \frac{\partial H}{\partial p}$$ and $$\dot{p} = - \frac{\partial H}{\partial q}$$. I used the notation $$\omega$$ instead of $$\omega = v$$ to make you think a bit harder about it. Notice I pulled $$H$$ out of thin air, what is a natural way to derive this $$H$$?

From $$L = L(t,q,\dot{q})$$, using the EOM form (for fixed $$t$$) $$dL = L_q dq + L_{\dot{q}} d \dot{q} = \dot{p} dq + p d \dot{q}.$$ Note this trivially tells me that $$q$$ and $$\dot{q}$$ are the variables of the function I am taking the differential of. However, I can now use this to change these variables and make $$p$$ one of the variables by writing it as $$dL = \dot{p} dq - \dot{q} dp + d[p \dot{q}]$$ and then bringing the total derivative term over to the other side, forming $$dH = d[p \dot{q} - L] = - \dot{p} dq + \dot{q} dp$$ so that I now have a representation of the same problem where $$q$$ and $$p$$ are my variables, and I accidentally 'derived' the Legendre transformation as a by-product, this turns out to be the tool by which I can go from $$L = L(q,\dot{q})$$ to a description where $$q$$ and $$p$$ are the variables. This representation now satisfies $$\dot{q} = \frac{\partial H}{\partial p}$$ and $$\dot{p} = - \frac{\partial H}{\partial q}$$ as expected.

Thus, the initial approach is simply taking a function $$L = L(t,q,\dot{q})$$, assuming $$p = L_{\dot{q}}$$ is defined, inverting this for $$\dot{q} = v(q,p)$$, inserting this into $$L$$ to get $$L = L(t,q,v(q,p)) = \tilde{L}(t,q,p)$$, then ignoring all these steps and taking $$\tilde{L}(t,q,p)$$ as a given pulled out of thin air, noting we can collect the $$q$$'s and $$p$$'s up in a nice way such that we can define a function $$v = v(q,p)$$ and set $$\tilde{L}(t,q,p) = L(t,q,v(q,p))$$, and we then randomly impose the constraint that this function $$v$$ is actually the time derivative of $$q$$, $$\dot{q} = v(q,p)$$. All of this breaks down if $$p = L_{\dot{q}}$$ is not invertible, leading to the Dirac theory of constrained Hamiltonian systems, thus it's better to learn the normal way first, and treat this as a tool that may be useful.

I am trying to reconstruct a derivation that I encountered a while ago somewhere on the internet, in order to build some intuition both for $$H$$ and $$L$$ in classical mechanics, and for the operation of Legendre transforms. But I can't seem to make the argument work.

The question is: can we derive Hamiltonian mechanics $$H(q, p)$$ by starting with an initial Lagrangian function $$L(q, v, t)$$, assuming no relationship at this point between $$q$$ and $$v$$, and deriving the Euler-Lagrange equations for this Lagrangian with the constraint $$\dot{q} = v$$?

We'd use a Lagrange multiplier: \begin{align} \delta S & = \delta \int dt \left[ L(q(t), v(t), t) + \lambda(t) (\dot{q}(t) - v(t)) \right] \\ & = \int dt \left[ \left( \frac{\partial L}{\partial q} - \dot{\lambda}(t)\right) \delta q(t) + \left( \frac{\partial L}{\partial v} - \lambda(t) \right) \delta v(t) \right] + \left. \lambda(t)\delta q(t)\right|^f_i \end{align}

Since it has been a while, it might be helpful to first remember how Lagrange multipliers can help you minimize a constrained function before jumping right into minimizing a functional.

But if you are interested in a more direct answer, just jump down to the last section below.

Recall, if you want to minimize a function $$f(q,v)$$ subject to a constraint $$g(q,v)=0$$ you consider a new function $$h(q,v,\lambda) \equiv f(q,v) +\lambda g(q,v)$$ and you set all the derivatives of $$h$$ to zero: $$\frac{\partial h}{\partial q}=0\;,\qquad \frac{\partial h}{\partial v}=0\;,\qquad \frac{\partial h}{\partial \lambda}=0$$

For example, if you want to want to minimize $$f=q^2 + v^2$$ subject to the constraint $$v=2q+1$$ you consider $$h = q^2+v^2+\lambda(v-2q-1)$$ to find: $$2q-2\lambda=0\;,\qquad 2v+\lambda=0\;,\qquad v-2q-1=0\;,$$ which tells you that $$q=\lambda$$ and $$v=-\lambda/2$$ and then you use lambda to force the constraint to be true: $$-\lambda/2 - 2\lambda - 1 = 0\;,$$ which implies that: $$\lambda = -2/5\;,\qquad q= -2/5\;,\qquad v= 1/5\;,\qquad\;,$$ which is indeed the minimum, with respect to q, of $$f(q,2q+1)$$.

Ok, now on to a functionals. The actual action functional you want to minimize is: $$S[q] = \int dt L(q(t), \dot q(t))\;.$$

But instead we choose to minimize $$\tilde S[q,v] = \int dt L(q(t), v(t))$$ subject to $$\dot q(t) = v(t)$$ by considering a new functional of three arguments: $$\bar S[q,v,\lambda]\equiv \int dt \left(L(q(t), v(t)) + \lambda(t)\left(\dot q(t) - v(t)\right)\right)$$ and by setting the three functional derivatives to zero: $$\frac{\delta \bar S}{\delta q}=0\;,\qquad \frac{\delta \bar S}{\delta v}=0\;,\qquad \frac{\delta \bar S}{\delta \lambda}=0\;.$$

As an example, suppose that we are interested in a simple harmonic oscillator. In that case we have: $$S[q] = \int dt \left(\frac{1}{2}m\dot q^2 - \frac{1}{2}kq^2\right)$$

But instead we can consider: $$\bar S[q,v,\lambda] = \int dt \left(\frac{1}{2}mv^2 - \frac{1}{2}kq^2\right)+\lambda\left(\dot q - v\right)$$

By setting the three functional derivatives to zero we find: $$-kq-\dot \lambda=0\;,\qquad mv-\lambda=0\;,\qquad \dot q = v\;.$$

And then, as usual, we use lambda to enforce the constraint. But this time, since lambda is a function we find: $$\ddot \lambda = \frac{-k}{m}\lambda \equiv -\omega^2 \lambda$$ which has a general solution $$\lambda(t) = -\frac{Ak}{\omega}\cos(\omega t)+\frac{Bk}{\omega}\sin(\omega t)$$ and this tells us: $$q(t) = A\sin(\omega t) + B\cos(\omega t)$$ $$v(t) = \omega A\cos(\omega t) - B\omega\sin(\omega t)$$

The question is: can we derive Hamiltonian mechanics $$H(q, p)$$ by starting with an initial Lagrangian function $$L(q, v, t)$$, assuming no relationship at this point between $$q$$ and $$v$$, and deriving the Euler-Lagrange equations for this Lagrangian with the constraint $$\dot{q} = v$$?

Yes, but it has little (or nothing?) to do with constraints.

The action is: $$S = \int dt L\;,$$ and we can rewrite this (by definition of the Hamiltonian) as: $$S = \int dt \left(p\dot q - H(q,p)\right)\;,$$ where we can now, if we like, consider the path being varied to be a path in phase space rather than in configuration space. (Reference: Goldstein chapter 8.) I.e., we consider $$q$$ and $$p$$ as independent coordinate and $$\dot q$$ and $$\dot p$$ as their respective independent velocities.

In this case, the variation of the action leads to two times more equations (since we are in phase space not configuration space): $$\frac{\partial}{\partial q}(p\dot q - H(q,p)) = \frac{d}{dt}\frac{\partial}{\partial \dot q}(p\dot q - H(q,p))\tag{A}$$ and $$\frac{\partial}{\partial p}(p\dot q - H(q,p)) = \frac{d}{dt}\frac{\partial}{\partial \dot p}(p\dot q - H(q,p)) = 0\tag{B}$$

Equation A above can be rewritten as: $$-\frac{\partial H}{\partial q} = \frac{dp}{dt}\;.\tag{A'}$$

Equation B above can be rewritten as: $$(\dot q - \frac{\partial H(q,p)}{\partial p}) = 0\;.\tag{B'}$$

Equations A' and B' are Hamilton's equations of motion.

• Thanks. Working through your answer did clarify my confusion as to the $v/p$ dependency—taking max_v and plugging it back in of course removes the $v$ dependency. And the SHO example was helpful. But I am not so confused about the Lagrange-multiplier method in general—rather in its interpretation: * the "meaning" of $p\dot{q} - H$ (note that this gives $pdx - Hdt$ which is $dS$, for $S$ understood as a function of its endpoint with E-L satisfied.) * I guess my question is more of "why does this work"? But I didn't ask that. So I'll accept this as an answer to what I did ask. Commented Dec 3, 2023 at 20:24