Is this a valid derivation of the Legendre transformation from the Euler-Lagrange condition

E-L condition:

$$\frac{d p}{dt}=\frac{\partial L}{\partial q}$$

Where $p=\frac{\partial L}{\partial \dot{q}}$

Are the following steps valid:

$$\frac{\partial q}{dt} dp=\partial L$$

$$\dot{q} \: dp = \partial L$$

$$\int \dot{q} \: dp = L+C$$

By integration by parts the LHS becomes:

$$\int \dot{q} \: dp = \dot{q} p-\int p \: d \dot{q} = \dot{q} p- \int \frac{\partial L}{\partial \dot{q}} \:d \dot{q}=\dot{q} p-L+C_1$$

Substituting this back into the LHS:

$$\dot{q} p-L=L+C_2$$

If steps are valid, then this indicates that the Legendre transformation of the Lagrangian is just the Lagrangian plus some constant $C_2$, and that the Hamiltonian is thus $H=L+C_2$. Seems pretty fishy. If it is not fishy (if above steps are valid), then this question: Since it is derived from the E-L condition, does this result imply that the action of all functions that are their own Legendre transformation (plus a constant) is stationary?

-
More on the Legendre Transformation: physics.stackexchange.com/q/4384/2451 and links therein. – Qmechanic Sep 5 '13 at 14:08

You can't just multiply a differential equation with $\partial q$ and cancel the terms on the right side. Also you don't derive the Legendre transformation from the Euler-Lagrange equations. The Legendre transformation is a general mathematical procedure, that allows one to convert a Lagrangian into a Hamiltonian. This is because the Lagrangian is defined in terms of coordinates $q$ and velocities $\dot{q}$, and the momenta are derived quantities

$$p=\frac{\partial L(q,\dot{q})}{\partial \dot{q}}$$

On the other hand independent variables of the Hamiltonian are coordinates $q$ and momenta $p$, and the velocities are derived quantities

$$\dot{q}=\frac{\partial H(q,p)}{\partial p}$$

Now you see that if you swap $p$ and $\dot{q}$ you should swap $L$ and $H$. Functions with this property are called Legendre transforms, and the procedure for obtaining one from the other is called Legendre transformation. For example obtaining the Lagrangian from the Hamiltonian

$$L(q,\dot{q})=p\dot{q}-H(q,p)$$

You can check this by differentiation

$$\frac{\partial L(q,\dot{q})}{\dot{q}}=\frac{\partial p}{\partial \dot{q}}\dot{q}+p-\frac{\partial H(q,p)}{\partial p}\frac{\partial p}{\partial \dot{q}}=p$$

-

The Legendre transformaton is a procedure to transform your function to another function which will not depend on the previous independent variable but will depend on the slope. But in this process the information will not be lost. you can try it. take a graph $y=y(x)$. now take the new function as the $y$ intercept by the tangent at $(x,y)$. this intercept is your new function and the dependent variable is the slope at that point. try it out. you can see Calen's book on thermodynamics. everything is clear there.

-