In addition to the previous nicely written answers, let me add a review, which includes both a mathematical and a physical perspective. Let us start with Lagrangian mechanics, then develop Hamiltonian mechanics independently and finally relate the two via the fiber derivative.
A Lagrangian system is a tuple $(Q,M,L)$, where:
- $Q$ is an $n$-dimensional smooth manifold, called the configuration space;
- $M=TQ$ is the tangent bundle of $Q$, a smooth $2n$-dimensional manifold, called the velocity phase space;
- $L:TQ \to \mathbb{R}$ is a smooth function, called the Lagrangian of the Lagrangian system $(Q,M,L)$.
Note that in order for a Lagrangian system to be uniquely specified, you have to specify both the configuration space and the Lagrangian. In physics, we usually take specific Lagrangians, but note that this is a choice! We usually consider Lagrangians of the form kinetic energy- potential energy, which mathematically can be explicitly written as follows:
\begin{equation}
L:TQ \to \mathbb{R}, \; \; L(v)=m\frac{1}{2} g(v,v) - V(\pi(v)), \; \; m \in \mathbb{R}
\end{equation}
where
- $\pi:TQ \to Q$ is the canonical bundle projection, in local coordinates $\pi(q^{i},\dot q^{i})=q^{i}$;
- $g$ is a Riemannian metric on $Q$, $\frac{m}{2} g(v,v)$ îs the so-called kinetic energy;
- $V:Q \to \mathbb{R}$ is a smooth function on $Q$, the so-called potential energy.
Note that if we choose $Q=\mathbb{R}^{n}$ with the canonical metric induced by the Euclidean norm, we obtain the well-known formula from physics in coordinates:
\begin{equation}
L(q,\dot q)=\frac{m}{2} \sum_{i=1}^{n}\limits \dot q_i ^2 - V(q).
\end{equation}
To be more explicit, we make the specific choice of $n=1$ and moreover:
- $g$ being the canonical metric induced by the Euclidean norm;
- $V:Q \to \mathbb{R}, \;\; V(q)=\frac{kq^2}{2}$, where $k$ is a real number.
In this case, we obtain the one-dimensional harmonic oscillator Lagrangian:
\begin{equation}
L_{1dho}=\frac{m}{2} \dot{q}^2 - \frac{kq^2}{2}.
\end{equation}
This means concretely that $(\mathbb{R},T \mathbb{R} \cong \mathbb{R}^2,L_{1dho})$ is a Lagrangian system.
We could construct further examples from physics, by choosing a specific function $V$. However, that is not our purpose right now, as we just wanted to elaborate mathematically on the Lagrangian formalism. As a summary, let us conclude that the input data of the Lagrangian formalism consists of a smooth manifold $Q$ and a smooth function $L:TQ \to \mathbb{R}$, called the Lagrangian.
Let's turn now to the Hamiltonian formalism.
A Hamiltonian system is a tuple $(X,\omega,H)$, where:
- $X$ is a smooth $2n$-dimensional manifold;
- $\omega: T_a X \times T_a X \to \mathbb{R}$ is a non-degenerate $2$-form for all $a \in X$ and $d \omega=0$, i.e. $\omega$ is closed- that is, it's a symplectic form;
- $H:X \to \mathbb{R}$ is a smooth function, called the Hamiltonian.
Note that the symplectic form gives rise to dynamics, as it is related to the Poisson bracket via the formula
\begin{equation}
\{f,g\}=\omega(X_{f},X_{g}), \; \; \text{where} \; \; X_{f},X_{g} \; \; \text{ are the Hamiltonian vector fields associated to} \;\; f,g.
\end{equation}
Note, once again, that the input data of Hamiltonian mechanics is a symplectic manifold $(X,\omega)$ together with a smooth function, called the Hamiltonian $H$. Now let us recall the Darboux theorem.
Let $(X,\omega)$ be a symplectic manifold. Then every point $a \in X$ has an open neighbourhood $U \subset X$ and a chart
\begin{equation}
\varphi=(q^1,q^2,\dots,q^n,p_1,p_2,\dots,p_n):U \to \mathbb{R}^{2n}, \; \;
\end{equation}
such that in these coordinates, we have:
\begin{equation}
\omega|_{U}=dq^{j} \wedge dp_{j}.
\end{equation}
These coordinates $(q^1,\dots,q^n,p_1,\dots,p_n)$ are called canonical coordinates.
Note that the existence of canonical coordinates is a consequence of $(X,\omega)$ being a symplectic manifold! Now, we might ask the question: are these canonical coordinates related to the coordinates $(q^{i},\dot{q}^{i})$ of Lagrangian mechanics in any reasonable manner? So far, we did not make any connection, just wrote down the existence of such, which was implied by the symplectic structure!
Before we answer that question, let us give a whole class of examples known from physics, in this abstract language of symplectic geometry. To this end, we choose $X=T^{*}Q$ for some smooth manifold $Q$. We call $T^{*}Q$ the momentum phase space. In this case, the Hamiltonian becomes a function
\begin{equation}
H: T^{*}Q \to \mathbb{R}, \; \; H(q^{i},p_{i}) \in \mathbb{R}.
\end{equation}
As we can see, there's a fundamental difference between the Lagrangian and Hamiltonian, even if they are both smooth functions:
- The Lagrangian is a smooth function on the tangent bundle of the configuration space, i.e. on the velocity phase space;
- The Hamiltonian is a smooth function on the cotangent bundle of the configuration space (as a special case), i.e. on the momentum phase space.
So before turning to relating the two, let us give the concrete example of harmonic oscillator. In this case:
- $X=T^{*}\mathbb{R} \cong \mathbb{R}^2$;
- $H_{1dho}:\mathbb{R}^2 \to \mathbb{R}, \; \; H_{1dho}(q,p)=\frac{p^2}{2m} + \frac{1}{2} k q^2$, where $k,m \in \mathbb{R}$ are real numbers.
- $\omega_{1dho}=dq \wedge dp$
Explicitly, this means that the tuple $(T^{*}\mathbb{R} \cong \mathbb{R}^2,\omega_{1dho},H_{1dho})$ is a Hamiltonian system.
Now, as we have seen, that, at least in special case, both formalisms start from a smooth manifold $Q$, and are specified by two functions $L$,$H$ on the tangent and cotangent bundle respectively, in order to go from Lagrangian mechanics to Hamiltonian Mechanics, we would need a map
\begin{equation}
f:TQ \to T^{*}Q,
\end{equation}
with help of which, given a Lagrangian on $TQ$, we could produce a Hamiltonian on $T^{*}Q$. This is solved by the fiber derivative.
Let $(Q,M,L)$ be a Lagrangian system with Lagrangian $L:TQ \to \mathbb{R}$. The fiber derivative of $L$ is a map
\begin{equation}
\mathbb{F}L:TQ \to T^{*}Q, \; \; ((\mathbb{F}L)(v))(w):=\left.\frac{d}{dt}\right|_{t=0} L(v+tw).
\end{equation}
Clearly, $\mathbb{F}L$ is a smooth function, as $L$ is. In case $\mathbb{F}L$ is a diffeomorphism, we say that the Lagrangian $L$ is hyperregular. The function
\begin{equation}
E:TQ \to \mathbb{R}, \; \; E(v):=\mathbb{F}L(v)-L(v)
\end{equation}
is called the total energy of the Lagrangian system $(Q,M,L)$.
Now, suppose the Lagrangian $L$ takes the form introduced before, namely:
\begin{equation}
L(v)=\frac{m}{2} g(v,v) - V(\pi(v)), \; \; m \in \mathbb{R}.
\end{equation}
We have that $\mathbb{F}L(v)=m g(v,v)$, since:
- $\mathbb{F}V(\pi(v))$=0, because $V$ is constant on the fibers;
- $\left.\frac{d}{dt}\right|_{t=0} g(v+tv,v+tv)=\left. \frac{d}{dt} \right|_{t=0} (g(v,v)+g(v,tv)+g(tv, v)+g(tv, tv))=g(v,v)+g(v,v)=2g(v,v).$
Therefore, the total energy reads:
\begin{equation}
E=mg(v,v)- \frac{m}{2}g(v,v) + V(\pi(v))=\frac{m}{2} g(v,v)+V(\pi(v)),
\end{equation}
or in special case of $\mathbb{R}$, in physics notation:
\begin{equation}
E=\frac{mv^2}{2} +V(q),
\end{equation}
which is nothing else than the intuitive notion of total energy, i.e. the sum of kinetic and potential energy.
Now let us compare this abstract definition of fiber derivative, to something well-known, the Legendre transform. To this end, we consider $Q \subseteq \mathbb{R}^{n}, TQ \cong Q \times \mathbb{R}^{n}$. In this case, the fiber derivative reads:
\begin{equation}
((\mathbb{F}L)(x,v))(w):=(x, D_2 L(x,v)(w)),
\end{equation}
where $D_2$ denotes partial derivative of $L$ with respect to the second coordinate.
If we introduce coordinates $q^{i}$ on $Q$ and $(q^{i},\dot{q}^{i})$ on $TQ$ and $(q^{i},p_{i})$ on $T^{*}Q$,, this reduces to:
\begin{equation}
(\mathbb{F}L)(q^{i},\dot{q}^{i})=\left(q^{i},\frac{ \partial L}{\partial \dot q^{i}} \right),
\end{equation}
which lets us read off that $p_i=\frac{ \partial L}{\partial \dot q^{i}}$. Moreover, the thus associated $E$ is the Legendre transform of $L$.
Let us illustrate the above abstract definition of the Fiber derivative in an easier example. Consider the Lagrangian system $(\mathbb{R},\mathbb{R}^{2},L_{f})$ of a free particle, where
\begin{equation}
L_{f}(q,v):=\frac{mv^2}{2}.
\end{equation}
In this case, the fiber derivative is a map:
\begin{equation}
\mathbb{F} L_{f}: \mathbb{R}^2 \to \mathbb{R}^2, \;\; (\mathbb{F} L_{f}(q,v))(w)=m \langle v, w \rangle=\langle mv, w \rangle,
\end{equation}
so we can identify $(\mathbb{F} L_{f})(q,v) \in T^{*}_{q} \mathbb{R}$ with the momentum $p=mv$.
Now, let us go back into the more general picture. Let $(Q,M,L)$ be a Lagrangian system and choose coordinates $(q^{1},\dots,q^{n}$ on $Q$ and $(q^{1},\dots,q^{n},\dot{q}^{1},\dots,\dot{q}^{n})$ on $TQ$. We define a one-form locally, which is induced by L as:
\begin{equation}
\lambda_{L}:=\frac{\partial L}{\partial \dot q^{I}} dq^{i}.
\end{equation}
This one-form is called the Liouville form and gives rise to a two-form:
\begin{equation}
\omega_{L}:=- d \lambda_{L}= - \frac{\partial ^2 L}{\partial q^{j} \partial \dot{q}^{k}} dq^{j} \wedge dq^{k} - \frac{\partial^2 L}{\partial \dot{q}^{j} \dot{q}^{k}} d \dot{q}^{j} \wedge dq^{k}.
\end{equation}
I claim $\omega_L$ is well-defined on all of $M$ and it is closed, therefore, it is a symplectic form if and only if it is non-degenerate. We now give a proposition, which tells us when this is the case.
Let $(Q,M,L)$ be a Lagrangian system with Liouville one-form $\lambda_{L}$, which gives rise to the $2-$form $\omega_L$. Then, the following statements are equivalent:
- $\omega_L$ is non-degenerate;
- $L$ is hyperregular;
- $\det \left( \frac{\partial^2 L}{\partial \dot{q}^{j} \dot{q}^{k}}\right) \neq 0 $
We now conclude the relation between Lagrangian Mechanics and Hamiltonian Mechanics with the following proposition:
Let $(Q,M,L)$ be a Lagrangian system with a Lagrangian $L$ that is hyper regular. Then the tuple $\left(T^{*}Q,\omega:=(\mathbb{F}L)^{*} \omega_{L},H:=E \circ (\mathbb{F}L)^{-1} \right)$ is a Hamiltonian system.
In particular, this means that hyperregular Lagrangians $L$ on $TQ$ induce Hamiltonian systems on $T^{*}Q$. Conversely, one can show that hyperregular Hamiltonians on $T^{*}Q$ come from Lagrangians on $TQ$, which lets us conclude:
Not every Hamiltonian system has a Lagrangian formulation. A Hamiltonian system where the momentum phase space is a cotangent bundle admits a Lagrangian formulation precisely when its Hamiltonian is hyperregular. Moreover, there are Hamiltonian systems, which are not cotangent bundles.
References:
Martin Schottenloher, Geometric Quantization notes
K.H. Neeb, Physics and geometry notes
Ratiu Marsden, Introduction to Mechanics and Symmetry.
EDIT: A physical remark/add-on, related to your statement that in quantum mechanics one usually starts with a Hamiltonian. This follows from the fact that physicists usually describe QFTs via Path Integrals: the Lagrangian version of the path integral exists only for a specific class of Hamiltonians - see the derivation in Weinberg for this.
EDIT: I will add a concrete physical example, where the condition is not met. Consider the Lagrangian of a relativistic free particle
\begin{equation}
L_{inv}=-mc \sqrt{ \frac{dx^{\alpha}}{d \tau} \frac{dx_{\alpha}}{d \tau}}=-mc \sqrt{\dot{x} ^2}, \; \; \text{where} \; \; \dot x^{\alpha}:=\frac{dx^{\alpha}}{d \tau}.
\end{equation}
For the existence of the square root, we must have $\dot{x}^2>0$, i.e. $\dot x$ must be timeline. The Euler Lagrange equations read:
\begin{equation}
\frac{\partial L_{inv}}{\partial x^{\alpha}} - \frac{d}{d \tau} \frac{\partial L_{inv}}{\partial \dot{x}^{\alpha}}=0.
\end{equation}
Concretely, computing it, we obtain:
\begin{equation}
\frac{d}{d \tau} \frac{ mc \dot{x}_{\alpha}}{\sqrt {\dot{x}^2}}=0.
\end{equation}
The momentum canonically conjugate to $x^{\alpha}$ reads
\begin{equation}
p_{\alpha}=\frac{\partial L_{inv}}{\partial \dot{x}^{\alpha}}=-mc \frac{\dot{x}_{\alpha}}{\sqrt{\dot{x}^2}}.\end{equation}
It satisfies the constraint
\begin{equation}
p^2-mc^2=0.
\end{equation}
Note that the dynamics is encoded in this constraint! To see this, we could naively try to construct the Hamiltonian according to the Legendre transformation. We will see this won't work, but let's give it a try. Using the Legendre transform:
\begin{equation}
H=\dot{x}^{\alpha} p_{\alpha}-L_{inv}=mc \left(-\frac{\dot{x}^2}{\sqrt{\dot{x}^2}}+ \sqrt{\dot{x}^2} \right)=0,
\end{equation}
which means that the Hamiltonian is the constant zero function, if obtained by the Legendre transformation. The reason for this is precisely the regularity condition of $L_{inv}$. We claim that:
\begin{equation}
\det \left(\frac{\partial L_{inv}}{\partial \dot{x}^{\beta} \partial \dot{x}^{\alpha}}\right) \neq 0
\end{equation}
is not fulfilled. One can explicitly check, using the form of $L_{inv}$ that this is not fulfilled, but I leave the details to the reader. This can be found in Florian Sheck's book, chapter 4.11..
The upshot of this is the following: Passing from Lagrangian to Hamiltonian mechanics is always possible, if the Lagrangian is hyperregular. In case it is not, while passing from one to the other, we lose some data. We must keep track of this data in terms of constraints, we must do constrain analysis, as was pointed out in the comment of a different post by @AcuriousMind.
For a more detailed treatment of constraints for the Lagrangian I provided, please consult this post.