Geodesics as Hamiltonian flows

In mathematics, the geodesic equations are second-order non-linear differential equations, and are commonly presented in the form of Euler–Lagrange equations of motion. However, they can also be presented as a set of coupled first-order equations, in the form of Hamilton's equations. This latter formulation is developed in this article.
Overview.
It is frequently said that geodesics are "straight lines in curved space". By using the Hamilton–Jacobi approach to the geodesic equation, this statement can be given a very intuitive meaning: geodesics describe the motions of particles that are not experiencing any forces. In flat space, it is well known that a particle moving in a straight line will continue to move in a straight line if it experiences no external forces; this is Newton's first law. The Hamiltonian describing such motion is well known to be formula_1 with "p" being the momentum. It is the conservation of momentum that leads to the straight motion of a particle. On a curved surface, exactly the same ideas are at play, except that, in order to measure distances correctly, one must use the metric. To measure momenta correctly, one must use the inverse of the metric. The motion of a free particle on a curved surface still has exactly the same form as above, i.e. consisting entirely of a kinetic term. The resulting motion is still, in a sense, a "straight line", which is why it is sometimes said that geodesics are "straight lines in curved space". This idea is developed in greater detail below.
Geodesics as an application of the principle of least action.
Given a (pseudo-)Riemannian manifold "M", a geodesic may be defined as the curve that results from the application of the principle of least action. A differential equation describing their shape may be derived, using variational principles, by minimizing (or finding the extremum) of the energy of a curve. Given a smooth curve
that maps an interval "I" of the real number line to the manifold "M", one writes the energy
where formula_4 is the tangent vector to the curve formula_5 at point formula_6.
Here, formula_7 is the metric tensor on the manifold "M". 
Using the energy given above as the action, one may choose to solve either the Euler–Lagrange equations or the Hamilton–Jacobi equations. Both methods give the geodesic equation as the solution; however, the Hamilton–Jacobi equations provide greater insight into the structure of the manifold, as shown below. In terms of the local coordinates on "M", the (Euler–Lagrange) geodesic equation is 
where the "x""a"("t") are the coordinates of the curve γ("t"), formula_9 are the Christoffel symbols, and repeated indices imply the use of the summation convention.
Hamiltonian approach to the geodesic equations.
Geodesics can be understood to be the Hamiltonian flows of a special Hamiltonian vector field defined on the cotangent space of the manifold. The Hamiltonian is constructed from the metric on the manifold, and is thus a quadratic form consisting entirely of the kinetic term. 
The geodesic equations are second-order differential equations; they can be re-expressed as first-order equations by introducing additional independent variables, as shown below. Note that a coordinate neighborhood "U" with coordinates "x""a" induces a "local trivialization" of 
by the map which sends a point 
of the form 
formula_12 to the point formula_13.
Then introduce the Hamiltonian as
Here, "g""ab"("x") is the inverse of the metric tensor: "g""ab"("x")"g""bc"("x") = formula_15. The behavior of the metric tensor under coordinate transformations implies that "H" is invariant under a change of variable. The geodesic equations can then be written as
and
The flow determined by these equations is called the cogeodesic flow; a simple substitution of one into the other obtains the Euler–Lagrange equations, which give the geodesic flow on the tangent bundle "TM". The geodesic lines are the projections of integral curves of the geodesic flow onto the manifold "M". This is a Hamiltonian flow, and the Hamiltonian is constant along the geodesics:
Thus, the geodesic flow splits the cotangent bundle into level sets of constant energy 
for each energy "E" ≥ 0, so that 