# Why exactly do we say $L = L(q, \dot{q})$ and $H = H(q, p)$?

In classical mechanics, we perform a Legendre transform to switch from $L(q, \dot{q})$ to $H(q, p)$. This has always been confusing to me, because we can always write $L$ in terms of $q$ and $p$ by just taking the expression for $\dot{q}(q, p)$ and stuffing it in.

In thermodynamics, we say $U$ is a function of $S$, $V$, and $N$ because $$dU = T dS + p dV + \mu dN,$$ which is exceptionally simple. But for the Lagrangian, we instead generally have $$dL = (\text{horrible expression})\, dq + (\text{horrible expression})\, d\dot{q}$$ In this case, I see no loss in 'naturalness' to switch to $q$ and $p$, so what's the real difference between considering $L(q, \dot{q})$ and $L(q, p)$?

We should abandon the "naive" langauge of functions depending on coordinates and consider functions as maps between mathematical spaces, which are only expressed in local coordinates after their domains have been defined.

The starting point for both the Lagrangian and the Hamiltonian formalism is a configuration space $Q$, whose coordinates are called $q^i$. It should be thought of as the space of positions of the system under considerations. The two formalisms now immediately take different paths: Lagrangian mechanics takes place on the tangent bundle $TQ$, Hamiltonian mechanics on the cotangent bundle $T^\ast Q$. The local coordinates on $TQ$ are denoted $(q^i,\dot{q}^i)$, the local coordinates on $T^\ast Q$ are $(q^i,p_i)$. Note that, since there is no metric on $Q$, you do not have a canonical identification of tangents and cotangents and therefore cannot switch between the description freely as one might be used to from Riemannian geometry. Note furthermore that $\dot{q}$ is not the derivative of anything - it's simply a notation for a new coordinate.

The Lagrangian is a function $L : TQ\to \mathbb{R}$. Given it, we may define a function $f : TQ\to T^\ast Q$ in local coordinates by $$f(q,\dot{q}) = \left(q,\frac{\partial L}{\partial \dot{q}}(q,\dot{q})\right)$$ and the associated Hamiltonian $H : T^\ast Q \to \mathbb{R}$ in local coordinates as the Legendre transform $$H(q,p) = \sup_{\dot{q}}\left(p_i \dot{q}^i - L(q,\dot{q})\right).$$ It should be clear here that neither $H(q,\dot{q})$ nor $L(q,p)$ are meaningful objects in this context - $H$ and $L$ act on different spaces, you cannot feed a $p$ into $L$ at all. Observe now that $f$ does permit us to do this in some sense, only rigorously: If $f$ is invertible, one may define a "co-Lagrangian" or "Hamiltonian Lagrangian" $L_H : T^\ast Q \to\mathbb{R}$ by $L_H(q,p) = L(f^{-1}(q,p))$. Crucially, $L$ and $L_H$ are different functions and should, for clarity's sake, never be denoted by the same symbol.

The expression in the definition of the Legendre transform obtains its extremum at $$p_i = \frac{\partial L}{\partial \dot{q}^i}(q,\dot{q}),$$ which means that $$H(q,p) = p_i\dot{q}^i - L(q,\dot{q})\tag{0}$$ holds exactly for a triple $(q,\dot{q},p)$ such that $$f(q,\dot{q}) = (q,p).\tag{1}$$ Note that the fact that $H$ does not depend on $\dot{q}$ means that $\dot{q}$ in eq. (0) is implicitly a function $\dot{q}(q,p)$ as defined implicitly by eq. (1).

Only when we impose the relation eq. (1) there is a functional relation between the $q,\dot{q},p$, otherwise there is not. This is why, as abstract functions, the Lagrangian is not a function of $p$ and the Hamiltonian is not a function of $\dot{q}$ - these are coordinates on different spaces with no relation to each other. It is only when we impose eq. (1) in order to express the Hamiltonian without the extremisation procedure prescribed in the Legendre transform that they become related, and not necessarily uniquely so. If $f$ is not invertible, then the Lagrangian system is a gauge theory and the Hamiltonian system is constrained - both terms which essentially mean that the relation between the $p$ and the $\dot{q}$ is not uniquely defined.

Finally, let me address a closely related confusion which nevertheless crops up because of the same reason, i.e. not respecting the actual domains functions are defined on. The $q,\dot{q}$ arguments of the Lagrangian are independent, and become dependent only when we consider a path $\gamma: I\to Q$, which induces a path $\tilde{\gamma} : I\to TQ, t\mapsto (\gamma(t),\dot{\gamma}(t))$ on the tangent bundle, where $\dot{\gamma}$ now denotes the actual time derivative, i.e. the tangent vector field to $\gamma$. The action is a function $S : [I,Q]\to\mathbb{R}$, where $[I,Q]$ denotes the space of all maps $I\to Q$, and is defined as $$S[\gamma] = \int_I L(\tilde{\gamma}).$$ When now considering this action, the physicist often writes the coordinates of $\tilde{\gamma}$ as $(q(t),\dot{q}(t))$, and it is only in this context that $\dot{q}(t)$ truly is a time-dependent function and the derivative of $q(t)$.

• To give the last "closely related confusion" some "teeth" I just want to mention that when I was first taught the Lagrangians by Prof. Kirkland at Cornell, he mentioned "when we use the Lagrangian formalism I was never totally clear on why we take partial derivatives with respect to $q$ and $\dot q$ but a total time derivative with respect to $t$." The above is the heart of the answer. $L$ is a function $\mathbb R^2\to\mathbb R$ (or whatever); it only has those partials. It's only after subbing in $q(t),\dot q(t)$ that we get a function $\mathbb R \to \mathbb R$ that has a total derivative. Commented Jan 26, 2017 at 21:01

There's nothing stopping you from writing $L$ as a function of $q$ and $p$. In fact, you're required to write $L$ as a function of $q$ and $p$ to get the Hamiltonian! But the Euler-Lagrange equations become very ugly.

Consider the normal Euler-Lagrange equation

$$\frac{d}{dt}\frac{\partial L}{\partial \dot q}=\frac{\partial L}{\partial q}$$

Let's try writing this in terms of $q,p$. The left hand side just becomes $\dot p$. But the left hand side is a lot uglier. We'd have

$$\frac{\partial }{\partial q}L(q, p(q,\dot{q}))=\frac{\partial L}{\partial q}+\frac{\partial L}{\partial p}\frac{\partial p}{\partial q}$$ and the Euler-Lagrange equation becomes

$$\dot{p}=\frac{\partial L}{\partial q}+\frac{\partial L}{\partial p}\frac{\partial p}{\partial q}$$

This might not look ugly at first glance, but it is actually terrible. In order to write down the proper Euler-Lagrange equation, we need to know the functional form of $p$ in terms of $q$. Thus, the Lagrangian as a function of $(p,q)$ is not sufficient to generate equations of motion. This is avoided when we go to the Hamiltonian formalism, where Hamilton's equations treat $p$ and $q$ as independent.

1. Well, OP's question becomes simpler/cleaner to answer if we consider actions rather than Lagrangians, such as the Lagrangian action$$^1$$ $$S[q]~=~\int\!dt~L(q,\dot{q})~=~\left. \int\!dt~L(q,v)\right|_{v=\dot{q}}\tag{1}$$ and the Hamiltonian action $$S_H[q,p]~=~\int\!dt~\{p\dot{q}-H(q,p)\}.\tag{2}$$

2. Then OP is essentially asking the following question:

Starting form the Lagrangian $$L(q,v)$$, and assuming that we can invert the relation $$p~=~\frac{\partial L(q,v)}{\partial v}\tag{3}$$ to give some function $$v=f(p;q),\tag{4}$$ why can't we use the action $$\int\!dt~L(q,f(p;q))~=~\left. \int\!dt~L(q,v)\right|_{v=f(p;q)}\tag{5}$$ instead of the Lagrangian action (1)?

Answer: Well, since $$q$$ and $$\dot{q}\equiv\frac{dq}{dt}$$ are related in the action (1), this proposal (5) effectively amounts to an inconsistent partial substitution of the $$q$$ variable.

Example: If $$L(q,v)=\frac{m}{2}v^2-V(q)$$, then the EL equations$$^2$$ for OP's proposal (5) is the static limit $$p\approx 0\wedge V^{\prime}(q)\approx 0$$.

3. However, there does exists a natural way to obtain$$^3$$ the Hamiltonian action (2) from the Lagrangian action (1) [so that the Legendre transformation appears naturally] by starting with an extended action $$S_E[q,v,p]~:=~\int\!dt~\{p(\dot{q}-v)+L(q,v)\}.\tag{6}$$

• On one hand, if we integrate out the Lagrange multiplier $$p$$ in the extended action (6), we implement the constraint $$v~\approx~\dot{q},\tag{7}$$ and just return to the Lagrangian action (1).

• On the other hand, if we integrate out the velocity variable $$v$$, i.e. eliminate it via its EL eq. (3), i.e. substitute (4) into the extended action (6), $$\left.\{pv-L(q,v)\}\right|_{v=f(p;q)}~=~H(q,p),\tag{8}$$ it leads to the Hamiltonian action (2), i.e. its Legendre transform, cf. my Phys.SE answer here.

$$^1$$ We suppress explicit time dependence $$t$$ from the notation to avoid clutter.

$$^2$$ The $$\approx$$ symbol means equality modulo the EL equations.

$$^3$$ The inverse Legendre transformation $$(2)\Rightarrow (1)$$ follows by integrating out the momentum variable $$p$$, i.e. eliminate it via its EL equation $$\dot{q}~\approx~\frac{\partial H(q,p)}{\partial p},\tag{9}$$ which amounts to a substitution of the $$p$$ variable.

• Could you elaborate more on why that substitution is inconsistent. What exactly is the difference between doing this, and what we do when we write $\int dt \, p \dot q - H(q, p)$ and vary that? The difference I discern is that here, we're letting qdot get varied automatically by our variation in $q$ (we don't sub in $\dot q= \dot q (q, p))$ whereas in writing $\int dt \, L(q, p)$, we do that. But why does that matter (if it does)? Commented May 15 at 21:45
• I updated the answer. Commented May 15 at 23:56
• I do see that it doesn't work. I'm just trying to understand why we were allowed to do that when we had a Hamiltonian but not when we have a Lagrangian. Could you help me see that? Commented May 16 at 2:34
• I updated the answer. Commented May 16 at 5:54