Suppose we have a configuration space manifold $M$.
The Lagrangian $\mathcal{L}(q, \dot{q})$ is a function on the tangent bundle $TM$. From $\mathcal{L}$ we can define the action functional $S$ which accepts paths on $M$ and returns the action for that path. A law of physics says that the extremal paths of the action functional are physical trajectories. With some calculation we find that the extremal paths satisfy the Euler-Lagrange equations
\begin{align*} \frac{d}{dt}\left(\frac{\partial \mathcal{L}}{\partial \dot{q}^i}\right) = \frac{\partial \mathcal{L}}{\partial q^i} \end{align*}
The Hamiltonian $H(q, p)$ is a function on the cotangent bundle $T^*M$, also called phase space. Any smooth manifold $M$ admits a canonical symplectic form $\omega$. This symplectic form induce a vector field on phase space (not on the manifold..) $X_H$. It is a law of physics that the integral curves of this vector field are physical trajectories. There is a relationship between $X_H$ and $dH$ which gives the following Hamilton differential equations of motion for the trajectories:
\begin{align*} \frac{dq^i}{dt} =& \frac{dH}{dp_i}\\ \frac{dp_i}{dt} =& - \frac{dH}{dq^i} \end{align*}
The Lagrangian induces a canonical isomorphism between $TM$ and $T^*M$ by $$ p = d_{\dot{q}}\mathcal{L} $$ which is $$ p^i(q, \dot{q}) = \frac{\partial \mathcal{L}}{\partial \dot{q}^i} $$ in coordinates.
I understand that there is a transformation from the space of Lagrangians (functions on the tangent bundle) to the space of Hamiltonians (functions on the cotangent bundle) which preserves the equations of motion. How can we derive this transformation from the constraint that the equations of motion are preserved?
One hint is that we can use the Euler-Lagrange equations and the duality condition derived from $\mathcal{L}$ to see
\begin{align*} \frac{dp_i}{dt} = \frac{\partial L}{\partial q^i} = -\frac{dH}{dq^i} \end{align*}
From $$ \frac{dq^i}{dt} = \frac{dH}{dp_i} $$ we get by the chain rule $$ \frac{dq^i}{dt} = \frac{dH}{dp_i} = \frac{dH}{dq^j}\frac{dq^j}{dp_i} + \frac{dH}{d\dot{q}^j}\frac{d\dot{q}^j}{dp_i} $$ and we can probably proceed from there but I'm not sure.
Ok, so I know the answer is $$ H(q, p) = \dot{q}(q, p)p - \mathcal{L}(q, \dot{q}(q, p)) $$ but I don't want to assume this, I want to DERIVE this. Then after that derivation I want to observe that this transformation is a Legendre transformation and then build intuition about why it is a Legendre transform.
What I want is in contrast to the usual treatment where you
- start with a Lagrangian
- Apply a Legendre transform (why???) to get a Hamiltonian
- Use the Legendre transform and Euler-Lagrange equations to derive Hamilton's equations.
But given by description above, Hamiltonian mechanics can stand alone without needing Lagrangian mechanics defined first. So we should be able to use the features of each to derive the bridge between the two.