Solution (source code)

= Solution

The passage to <Hamiltonian mechanics> uses the <Legendre transform in mechanics>. Assume a <regular Lagrangian>: the velocity <Hessian matrix> $(\partial^2L/\partial v^i\partial v^j)$ is invertible. Then
$$
p_i=\frac{\partial L}{\partial v^i}
$$
defines a locally invertible map from the <tangent bundle> to the <cotangent bundle>. Write its local inverse as $v=v(t,q,p)$ and define the <Hamiltonian>
$$
H(t,q,p)=p_iv^i-L(t,q,v).
$$
Differentiating this expression, all terms containing $dv$ cancel because $p_i=L_{v^i}$. Hence
$$
dH=v^i\,dp_i-L_{q^i}\,dq^i-L_t\,dt,
\qquad H_{p_i}=v^i,\quad H_{q^i}=-L_{q^i}.
$$
The <Euler-Lagrange equations> become <Hamilton's equations>:
$$
\boxed{\dot q^i=H_{p_i},\qquad\dot p_i=-H_{q^i}.}
$$
Conversely, a solution of <Hamilton's equations> satisfies $\dot q=v(t,q,p)$, hence $p=L_v(t,q,\dot q)$, and $\dot p=L_q$ recovers the <Euler-Lagrange equations>. This proves local equivalence of the two descriptions.

On the <cotangent bundle>, choose the canonical <symplectic form> $\omega_{\mathrm{can}}=\sum_i dq^i\wedge dp_i=-d\lambda$ and the convention $\iota_{X_H}\omega_{\mathrm{can}}=dH$. Then $X_H=\sum_i(H_{p_i}\partial_{q^i}-H_{q^i}\partial_{p_i})$, so its integral curves are exactly the phase-space equations above. \b[This sign convention is used throughout these solutions.] For a <hyperregular Lagrangian>, the <Legendre transform in mechanics> is globally invertible and gives global equivalence; regularity alone only gives local equivalence. A singular velocity <Hessian matrix> may instead produce constraints, so the ordinary unconstrained argument does not apply to every <Lagrangian>.