Mechanics III: the Hamiltonian
Move from Lagrangian mechanics to Hamiltonian mechanics.
September 12, 2026
Newton gave the first formulation of mechanics, in the 17th century. Newton had several insights: an object's motion is determined by its current position and velocity; an object's position only changes according to its velocity; an object's velocity can only change when a force is applied to it; in this case, the change in velocity is determined by Newton's famous \(F = ma.\) When doing Newtonian mechanics, force is the focus: most of the effort put in to solve a Newtonian mechanics problem is done to think about what forces are acting on which objects, and how strong these forces are.
In 1788, Lagrange introduced a more abstract framework for mechanics. His approach was based on the Lagrangian, and a physical system evolves to minimize the action integral \[ S=\int_{t_0}^{t_1}L\big(x(t),v(t),t\big)dt. \] A big advantage of Lagrange's approach was that it enabled us to prove Noether's theorem, giving us a tool to find various conservation laws.
In 1833, Hamilton introduced yet another approach to classical mechanics, which is even more abstract than Lagrange's approach. For him, conservation laws are the most basic concept.
That is, in Hamilton's approach, we start by writing down some physical quantity which we know should be conserved, and then find some way for physics to evolve which forces that quantity to be conserved.
Hamilton's approach is a bit more abstract than Newton's and Lagrange's, but it has two key advantages: it allows the tools of differential geometry to be used to study physics, and it generalizes well to quantum mechanics, where direct analogues of Newtonian or Lagrangian mechanics make less sense.
Hamilton's formalism might seem abstract, but it turned out to be key to developing quantum mechanics. We hope to elaborate on the connection to quantum in a later article, but for now our focus will be on exploring Hamilton's approach to classical mechanics. With that spiel, let's jump right into things!
Least action principle: a review
Let's quickly review Lagrangian mechanics. We start with the a certain function, known as the Lagrangian, \[ L(q_1,\dots,q_n,\dot q_1,\dots,\dot q_n,t), \] which depends on coordinates \(q_1,\dots,q_n\), the generalized velocity \(\dot q_1,\dots,\dot q_n\), and time \(t\). Throughout the article, to simplify notation we will denote the Lagrangian by \[ L(q,\dot q,t), \] where \(q\) should be understood to be shorthand for \(q_1,\dots,q_n\). In our previous article we usually took \(q\) to be the usual cartesian coordinate \(x\), so \(\dot q=v\) was velocity. But we could have taken \(q\) to be anything; for example, at the end of that article we thought about a pendulum and used \(q=\theta\) the angle the pendulum was at, instead of its literal \(x\)-coordinate. In physics, choosing the right coordinate system can often greatly simplify the mathematics involved -- in that pendulum example, the math is much simpler if you use \(\theta\) as your coordinate instead of tracking the \((x, y)\) coordinates of the position.
Given a Lagrangian \(L(q,\dot q,t)\), the action of a path \(q(t),\) starting at time \(t_0\) and ending at time \(t_1,\) is \[ S=\int_{t_0}^{t_1}L\big(q(t),\dot q(t),t\big)dt. \] Lagrange's key observation is that nature takes the path which minimizes the above action integral, given that the endpoints \(q(t_0)\) and \(q(t_1)\) are fixed.
Fermat's principle, commonly used in calculus, allows you to detect minima and maxima by looking at how your function changes under small perturbations. Let's perturb our path to get \(q(t)+\delta q(t)\), where \(\delta q\) is some small function such that \(\delta q(t_0)=\delta q(t_1)=0\) to make sure the endpoints don't move. Then the time-derivative \(\dot q(t)\) of \(q(t)\) changes to \(\dot q(t)+\delta\dot q(t)\), where \(\delta\dot q(t)\) denotes the derivative of \(\delta q(t)\).
Thus the action for the path \(q+\delta q\) is now \[ S + \delta S=\int_{t_0}^{t_1}L\big(q(t)+\delta q(t),\dot q(t)+\delta\dot q(t),t\big)dt. \] We can approximate the integrand as \[ L\big(q(t)+\delta q(t),\dot q(t)+\delta\dot q(t),t\big)\approx L\big(q(t),\dot q(t),t\big)+\frac{\partial L}{\partial q}\delta q(t)+\frac{\partial L}{\partial \dot q}\delta\dot q(t). \] Therefore, the perturbation \(\delta q\) changes the action by \[ \delta S=\int_{t_0}^{t_1}\bigg(\frac{\partial L}{\partial q}\delta q(t)+\frac{\partial L}{\partial \dot q}\delta\dot q(t)\bigg)dt. \] By Fermat's principle, for our original path to be a critical point of the action, we need \(\delta S=0\). Integrating by parts, \[ \delta S=\int_{t_0}^{t_1}\bigg(\frac{\partial L}{\partial q}-\frac d{dt}\frac{\partial L}{\partial \dot q}\bigg)\delta q(t)dt \] and for this quantity to be 0 for all small perturbations \(\delta q\), we need \[ \frac{\partial L}{\partial q}-\frac d{dt}\frac{\partial L}{\partial \dot q}=0. \] This is the Euler-Lagrange equation!
Generalized coordinates
Let us introduce some terminology. We call \(q_i\) the generalized coordinate, and \(\dot q_i\) the generalized velocity. We call the derivative \(p_i=\frac{\partial L}{\partial\dot q_i}\) the generalized momentum, and the derivative \(F_i=\frac{\partial L}{\partial q_i}\) the generalized force. Then the Euler-Lagrange equation is now simply \[F_i=\frac{dp_i}{dt}.\] As we saw in our previous article, when \(q_i=x_i\) are the usual cartesian coordinates, the momentum \(p_i\) and force \(F_i\) are the usual notions, and \(F_i=\frac{dp_i}{dt}\) is Newton's famous equation.
In other words, we can view the Euler-Lagrange equation as Newton's equation but in more general coordinates.
Mechanics, in terms of energy
In our article on Noether's theorem, we considered the function \[ H=\sum_{i=1}^np_i\dot q_i-L, \] which we called energy, or in our context, the Hamiltonian. Then its time-derivative is \[ \frac{dH}{dt}=\sum_{i=1}^n(\dot p_i\dot q_i+p_i\ddot q_i)-\frac{dL}{dt}. \] The multi-variable chain rule tells us \[ \frac{dL}{dt}=\sum_{i=1}^n\bigg(\frac{\partial L}{\partial q_i}\dot q_i+\frac{\partial L}{\partial \dot q_i}\ddot q_i\bigg)+\frac{\partial L}{\partial t}=\sum_{i=1}^n\big(F_i\dot q_i+p_i\ddot q_i\big)+\frac{\partial L}{\partial t}. \] Using the Euler-Lagrange equation, that \(F_i=\dot p_i\), we see \[ \frac{dH}{dt}=-\frac{\partial L}{\partial t}. \] In other words, the Hamiltonian \(H\) is conserved exactly when the Lagrangian \(L\) is time-independent. Again rephrasing, if your Lagrangian is symmetric with respect to time, then the resulting motion will obey conservation of energy.
Hamilton's idea was to take Lagrangian mechanics--formulated in terms of \(L,\) \(q_i\), and \(\dot q_i\)--and reformulate it in terms of \(H\), \(q_i\), and \(p_i\). This makes energy \(H\), position \(q_i,\) and momentum \(p_i\) the key concepts of the theory. Correspondingly, let us view \(H=H(q,p,t)\) as a function of \(q_i\), \(p_i\), and \(t\), instead of as a function of \(q_i\), \(\dot q_i\), and \(t\).
At first, it is not clear that changing coordinates from \(L, q, \dot{q}\) to \(H, q, p\) is that helpful -- but remember, in physics and mathematics, often choosing the right coordinate system can save you lots of work for a small initial cost! Let's explore why Hamilton wanted to make this change.
Euler-Lagrange equations... but with no Lagrangians
The Euler-Lagrange equations were derived by minimizing the action integral \[ S=\int_{t_0}^{t_1}L(q,\dot q, t)dt. \] Let us re-write the formula as \(L=\sum_{i=1}^np_i\dot q_i-H\), so \[ S=\int\bigg(\sum_{i=1}^np_i\dot q_idt-Hdt\bigg). \] We can rewrite \(\dot{q}_i \, dt\) as \(dq_i\) (using the language of differential forms described last week), so that \[ S=\int\bigg(\sum_{i=1}^np_idq_i-Hdt\bigg). \]
For a moment, let's simplify notation by supposing \(n=1\), and let's take a variation \(q\to q+\delta q\) where \(\delta q(t_0)=\delta q(t_1)=0\). This induces a variation \(p\to p+\delta p\) of our momentum, since the momentum is determined by the path. The action integral \[ S=\int_{t_0}^{t_1}\big(pdq-Hdt\big) \] changes to \[ S + \delta S=\int_{t_0}^{t_1}\bigg((p+\delta p)d(q+\delta q)-H\big(q(t)+\delta q(t),p(t)+\delta p(t),t\big)dt\bigg), \] so the change in \(S\) is \[ \delta S=\int_{t_0}^{t_1}\bigg(p d(\delta q)+\delta p\cdot dq-\frac{\partial H}{\partial p}\delta p\cdot dt-\frac{\partial H}{\partial q}\delta q\cdot dt\bigg). \] Let's split the integral into parts which involve \(\delta p\) and parts which involve \(\delta q\): \[ \delta S=\int_{t_0}^{t_1}\bigg(\delta p\cdot dq-\frac{\partial H}{\partial p}\delta p\cdot dt\bigg)+\int_{t_0}^{t_1}\bigg(p d(\delta q)-\frac{\partial H}{\partial q}\delta q\cdot dt\bigg). \] Let's focus on the term \(pd(\delta q)\) for now. We can integrate it by parts to find \[ \int_{t_0}^{t_1}p d(\delta q)=\bigg[p\delta q\bigg]_{t_0}^{t_1}-\int_{t_0}^{t_1}\delta q\cdot dp=-\int_{t_0}^{t_1}\delta q\cdot dp. \] Plugging this back into our original formula, we get \[ \delta S=\int_{t_0}^{t_1}\delta p\bigg(dq-\frac{\partial H}{\partial p}\cdot dt\bigg)-\int_{t_0}^{t_1}\delta q\bigg(dp+\frac{\partial H}{\partial q}\cdot dt\bigg). \] Remember that, by Fermat's principle, for the path \(q\) to be a critical point of the action integral, we need \(\delta S\) to always vanish. The only way that this integral vanishes for every choice of \(\delta q\) is when \[ dq=\frac{\partial H}{\partial p}\cdot dt\] and \[dp=-\frac{\partial H}{\partial q}\cdot dt. \] Rewriting this to avoid the language of differential forms, we find \[ \frac{\partial H}{\partial p}=\dot q,\ \ \frac{\partial H}{\partial q}=-\dot p. \] More generally, when there are \(n\) coordinates, \[ \boxed{\frac{\partial H}{\partial p_i}=\dot q_i,\ \ \frac{\partial H}{\partial q_i}=-\dot p_i}. \] These are called Hamilton's equations.
A digression for mathematicians: since \(\delta p\) and \(\delta q\) are not independent quantities, we have not fully justified Hamilton's equations. We will more rigorously prove these identities in the next section, but for now, let's just explore the implications.
The first advantage to Hamilton's new \(H, q, p\) coordinates is that the second-order equation \[ \frac d{dt}\frac{\partial L}{\partial \dot q_i}=\frac{\partial L}{\partial q_i} \] is replaced by the two first-order differential equations \[ \frac{\partial H}{\partial p_i}=\dot q_i,\ \ \frac{\partial H}{\partial q_i}=-\dot p_i. \] Differential equations are really hard -- and the higher the order of your equation, the harder it is. Mathematically, the two systems of equations are encoding the exact same thing, but first-order equations are easier to manipulate algebraically, and hence slightly preferable.
Moreover, our differential equations have become more symmetric: if we exchange \(p_i\) and \(q_i\), the differential equations almost don't change! This suggests that momentum and position are more related than you'd first expect.
Hamilton's equations, via differential forms
In this section, we satisfy the mathematicians by giving a more complete justification for Hamilton's equations. We will use the language of differential forms.
We're going to compute the differential \(dH\) in two different ways. The simplest way is to just observe that, from the definition of differentials, \[ dH=\sum_{i=1}^n\left(\frac{\partial H}{\partial p_i}dp_i+\frac{\partial H}{\partial q_i}dq_i\right)+\frac{\partial H}{\partial t}dt. \]
However, the formula \[H = \sum_{i=1}^n p_i\dot{q}_i - L\] allows us to compute \[dH = \sum_{i=1}^n d(p_i\dot{q}_i) - dL.\] The product rule says \[d(p_i\dot{q}_i) = p_i d\dot{q}_i + \dot{q}_i dp_i,\] and \[ dL=\sum_{i=1}^n\frac{\partial L}{\partial q_i}dq_i+\sum_{i=1}^n\frac{\partial L}{\partial\dot q_i}d\dot q_i+\frac{\partial L}{\partial t}dt. \] We can simplify this a little, using the Euler-Lagrange equations to write \[ dL=\sum_{i=1}^n\dot p_idq_i+\sum_{i=1}^np_id\dot q_i+\frac{\partial L}{\partial t}dt. \]
Putting this together, \[ dH=\sum_{i=1}^nd(p_i\dot q_i)-dL=\sum_{i=1}^n(p_id\dot q_i+\dot q_idp_i)-\sum_{i=1}^n\dot p_idq_i-\sum_{i=1}^np_id\dot q_i-\frac{\partial L}{\partial t}dt \] The \(p_id\dot{q}_i\) terms cancel, and so \[ dH=\sum_{i=1}^n\left(\dot q_idp_i-\dot p_idq_i\right)-\frac{\partial L}{\partial t}dt. \] Comparing this with our earlier expression \[ dH=\sum_{i=1}^n\left(\frac{\partial H}{\partial p_i}dp_i+\frac{\partial H}{\partial q_i}dq_i\right)+\frac{\partial H}{\partial t}dt, \] we conclude Hamilton's equations: comparing the \(dp_i\) terms we get \[\frac{\partial H}{\partial p_i} = \dot{q}_i,\] \[\frac{\partial H}{\partial q_i} = -\dot{p}_i.\]
Comparing the \(dt\) terms, we also deduce \[ \frac{\partial H}{\partial t}=-\frac{\partial L}{\partial t},\] which was the key to conservation of energy!
Conserved quantities
From now on, for simplicity, let's assume the Hamiltonian \(H\) is time-independent. Let's try to understand conserved quantities from the Hamiltonian perspective. Take a function \(F(q,p)\). Then the multi-variable chain rule tells us \[ \frac{d}{dt}F\big(q(t),p(t)\big)=\sum_{i=1}^n\bigg(\frac{\partial F}{\partial q_i}\dot q_i+\frac{\partial F}{\partial p_i}\dot p_i\bigg). \] So, \(F\) is conserved exactly when this sum is zero. Let us re-write the sum using Hamilton's equations as \[ \frac{d}{dt}F\big(q(t),p(t)\big)=\sum_{i=1}^n\bigg(\frac{\partial F}{\partial q_i}\frac{\partial H}{\partial p_i}-\frac{\partial F}{\partial p_i}\frac{\partial H}{\partial q_i}\bigg). \] We generally define, for two functions \(f\) and \(g\), their Poisson bracket to be \[ \boxed{\{f,g\}:=\sum_{i=1}^n\bigg(\frac{\partial f}{\partial p_i}\frac{\partial g}{\partial q_i}-\frac{\partial f}{\partial q_i}\frac{\partial g}{\partial p_i}\bigg)}. \] Thus \[ \frac{dF}{dt}=\{H,F\}, \] and that \(F\) is conserved exactly when \(\{H,F\}=0\).
At first, it might seem that introducing the Poisson bracket doesn't bring any real advantage: we have just rewritten the equation you need to study to determine if \(F\) is a conserved quantity or not. However, the Poisson bracket has some incredible algebraic properties which make it easier to study; we list the properties below, and you can click on a property to see a proof of it.
\[
\frac{\partial g}{\partial p_i}\frac{\partial f}{\partial q_i}-\frac{\partial g}{\partial q_i}\frac{\partial f}{\partial p_i}=-\bigg(\frac{\partial f}{\partial p_i}\frac{\partial g}{\partial q_i}-\frac{\partial f}{\partial q_i}\frac{\partial g}{\partial p_i}\bigg).
\]
Either because
\[
\frac{\partial f}{\partial p_i}\frac{\partial f}{\partial q_i}-\frac{\partial f}{\partial q_i}\frac{\partial f}{\partial p_i}=0,
\]
or use the first property that \(\{f,f\}=-\{f,f\}\).
Because derivatives are linear.
By the product rule,
\[
\frac{\partial f}{\partial p_i}\frac{\partial(gh)}{\partial q_i}-\frac{\partial f}{\partial q_i}\frac{\partial(gh)}{\partial p_i}
=g\bigg(\frac{\partial f}{\partial p_i}\frac{\partial h}{\partial q_i}-\frac{\partial f}{\partial q_i}\frac{\partial h}{\partial p_i}\bigg)+h\bigg(\frac{\partial f}{\partial p_i}\frac{\partial g}{\partial q_i}-\frac{\partial f}{\partial q_i}\frac{\partial g}{\partial p_i}\bigg).
\]
This proof is the most painful. Let's say \(n=1\) for simplicity. One way is to say
\[
\{f,\{g,h\}\}=\bigg\{f,\frac{\partial g}{\partial p}\frac{\partial h}{\partial q}-\frac{\partial g}{\partial q}\frac{\partial h}{\partial p}\bigg\},
\]
then apply the Leibniz rule to say
\[
\{f,\{g,h\}\}=\big\{f,\frac{\partial g}{\partial p}\big\}\frac{\partial h}{\partial q}+\big\{f,\frac{\partial h}{\partial q}\big\}\frac{\partial g}{\partial p}-\big\{f,\frac{\partial g}{\partial q}\big\}\frac{\partial h}{\partial p}-\big\{f,\frac{\partial h}{\partial p}\big\}\frac{\partial g}{\partial q}
\]
On the other hand,
\[
\{\{f,g\},h\}=\frac\partial{\partial p}\{f,g\}\frac{\partial h}{\partial q}-\frac\partial{\partial q}\{f,g\}\frac{\partial h}{\partial p}.
\]
By a version of the product rule, we see
\[
\frac\partial{\partial p}\{f,g\}=\big\{\frac{\partial f}{\partial p},g\big\}+\big\{f,\frac{\partial g}{\partial p}\big\},\ \ \frac\partial{\partial q}\{f,g\}=\big\{\frac{\partial f}{\partial q},g\big\}+\big\{f,\frac{\partial g}{\partial q}\big\}.
\]
Substituting into our earlier expression,
\[
\{\{f,g\},h\}=\big\{\frac{\partial f}{\partial p},g\big\}\frac{\partial h}{\partial q}+\big\{f,\frac{\partial g}{\partial p}\big\}\frac{\partial h}{\partial q}-\big\{\frac{\partial f}{\partial q},g\big\}\frac{\partial h}{\partial p}-\big\{f,\frac{\partial g}{\partial q}\big\}\frac{\partial h}{\partial p}.
\]
Similarly, swapping the roles of \(g\) and \(h\), we see
\[
\{\{f,h\},g\}=\big\{\frac{\partial f}{\partial p},h\big\}\frac{\partial g}{\partial q}+\big\{f,\frac{\partial h}{\partial p}\big\}\frac{\partial g}{\partial q}-\big\{\frac{\partial f}{\partial q},h\big\}\frac{\partial g}{\partial p}-\big\{f,\frac{\partial h}{\partial q}\big\}\frac{\partial g}{\partial p}.
\]
When we add these expressions, many terms cancel, and
\[
\{f,\{g,h\}\}+\{\{f,h\},g\}-\{\{f,g\},h\}=\big\{\frac{\partial f}{\partial p},g\big\}\frac{\partial h}{\partial q}-\big\{\frac{\partial f}{\partial q},g\big\}\frac{\partial h}{\partial p}-\big\{\frac{\partial f}{\partial p},h\big\}\frac{\partial g}{\partial q}+\big\{\frac{\partial f}{\partial q},h\big\}\frac{\partial g}{\partial p}.
\]
The right-hand-side can be further expanded out using the definition of the Poisson bracket and will equal 0.
anti-symmetry: \(\{g,f\}=-\{f,g\}\).
\(\{f,f\}=0\).
bilinearity: \(\{f,g+h\}=\{f,g\}+\{f,h\}\) and \(\{f,cg\}=c\{f,g\}\) for any scalar \(c.\)
Leibniz rule: \(\{f,gh\}=g\{f,h\}+h\{f,g\}\).
Jacobi identity: \(\{f,\{g,h\}\}+\{g,\{h,f\}\}+\{h,\{f,g\}\}=0\).
Let's explore what each of these properties mean in terms of conserved quantities, by substituting \(f=H\). The second identity says \[ \{H,H\}=0, \] so \(H\) is a conserved quantity. The bilinearity says \[ \{H,g+h\}=\{H,g\}+\{H,h\} \] and \[ \{H,cg\}=c\{H,g\}, \] so if both \(g\) and \(h\) are conserved quantities (i.e., \(\{H,g\}=\{H,h\}=0\)), then \(f+g\) and \(cg\) are conserved as well.
The Leibniz rule says that if \(g\) and \(h\) are conserved, then \(gh\) is also conserved, because \[ \{H,gh\}=g\{H,h\}+h\{H,g\}=g\cdot0+h\cdot0=0. \] Finally, the Jacobi identity says \[ \{H,\{g,h\}\}=\{g,\{H,h\}\}-\{h,\{H,g\}\} \] so if \(g\) and \(h\) are conserved, then so is \(\{g,h\}\). The first few properties are pretty simple, but this Jacobi identity is really surprising: the Poisson bracket gives us a very interesting way to take two conserved quantities and build a new one!
There are some situations where the Poisson bracket can build very nice conserved quantities. As an example, let's consider the 2D isotropic harmonic oscillator; this is the physical system of a particle moving in 2-dimensional space, experiencing some force always pulling it towards the origin (think of a 2-dimensional version of the solar system: the origin is like the sun, and the particle is a planet). The trajectories are ellipses, as illustrated in the below diagram (we warn that this fact is often counterintuitive to physics students, so you might want to ponder the animation for a moment, and think about how a force always pointing towards the origin can modify your velocity in such a way that you keep orbiting in an ellipse).
As our position coordinates, we can use \(x\) and \(y,\) the Cartesian coordinates of the particle. We will denote the momentum by \(p_x\) and \(p_y.\) The Hamiltonian is then \[H = \frac{p_x^2+p_y^2}{2m} + \frac{m\omega^2}{2}(x^2+y^2),\] where \(m\) is the mass of the particle, and \(\omega\) is its angular frequency of rotation.
Using the Poisson bracket, we can find a very non-obvious conserved quantity. Let's start with some `obvious' conserved quantities of this motion. The first is \(H\) itself. However, we can also break \(H\) into the sum \[H = E_x + E_y,\] where \[E_x = \frac{p_x^2}{2m} + \frac{m\omega^2x^2}{2},\] \[E_y = \frac{p_y^2}{2m} + \frac{m\omega^2y^2}{2},\] and each of \(E_x, E_y\) will be conserved quantities (you can think that our Hamiltonian could be representing one particle in 2-dimensions, or two particles in 1-dimension; in this two particle picture, each particle independently has conservation of energy, explaining why our total energy breaks up into a sum of two conserved quantities).
The rotational symmetry of \(H\) leads to conservation of angular momentum \[A = xp_y - yp_x.\] The Poisson bracket \(\{E_x, A\}\) is then a new conserved quantity. What quantity is it?
Well, \[\{E_x, A\} = \frac{\partial E_x}{\partial x}\frac{\partial A}{\partial p_x} - \frac{\partial E_x}{\partial p_x}\frac{\partial A}{\partial x}.\] Evaluating those derivatives, this simplifies to \[\{E_x, A\} = -\frac{1}{m}(p_xp_y+m^2\omega^2xy).\]
This new conserved quantity is not at all an obvious symmetry of our system! It is one component of the Fradkin tensor; in our article on Noether's theorem, we discussed how conservation laws come from symmetries. In this case, the Fradkin tensor comes from a very non-obvious symmetry of this Hamiltonian which was first discovered by the physicist David Fradkin. Using the Poisson bracket, one can very easily discovery this remarkable hidden phenomena!