Solution (source code)

= Solution

For ordinary conservative <classical mechanics>, the <Lagrangian> is $L(q,\dot q,t)=T-V$, where $T$ is the <kinetic energy> and $V$ the <potential energy>. More generally it is the function whose <action> $\int L\,dt$ satisfies the <principle of stationary action>. The <canonical momenta> and <Hamiltonian> are
$$
p_i=\frac{\partial L}{\partial\dot q_i},\qquad
\boxed{H(q,p,t)=\sum_i p_i\dot q_i-L(q,\dot q,t).}
$$
For a <regular Lagrangian>, the first equations can be inverted to express the <generalized velocities> in terms of $q,p,t$; this defines the <Legendre transform> on <phase space>.

Along a solution of the <Euler-Lagrange equations>, $\dot p_i=\partial L/\partial q_i$. Taking a total <time derivative> gives
$$
\begin{aligned}
\frac{dH}{dt}
&=\sum_i\left(\dot p_i\dot q_i+p_i\ddot q_i\right)
-\sum_i\left(\frac{\partial L}{\partial q_i}\dot q_i+
\frac{\partial L}{\partial\dot q_i}\ddot q_i\right)
-\frac{\partial L}{\partial t}\\
&=-\frac{\partial L}{\partial t}.
\end{aligned}
$$
Thus an autonomous <Lagrangian> has
$$
\boxed{\frac{dH}{dt}=0.}
$$
For the usual time-independent mechanical coordinates and a velocity-independent <potential energy>, the <kinetic energy> is quadratic in the <generalized velocities>, so $\sum_i p_i\dot q_i=2T$ and $H=T+V$. The conservation proof itself uses the <Euler-Lagrange equations>, rather than assuming this special expression for <energy>.