What is causing this sign difference in the centrifugal term between Lagrangian and Hamiltonian formalism? Consider a central force problem of the form with the Lagrangian
$$
L(r, \theta, \dot{r}, \dot{\theta}) = \frac{1}{2} m \left( \dot{r}^2 + r^2 \dot{\theta}^2 \right) - V(r),
$$
where $r = |\vec{x}|$. Since $\theta$ is cyclic, we can show that $m r^2 \dot{\theta}$ is a constant of motion, and rewrite the Lagrangian as
$$
L(r, \dot{r}) = \frac{1}{2} m \dot{r}^2 + \frac{l^2}{2mr^2} - V(r).
$$
If I calculate the Hamiltonian from this, I get
$$
H_{1}(r, p_r) = \frac{p_r^2}{2m} - \frac{l^2}{2mr^2} + V(r)
$$
Taking another direction, I calculated first the Hamiltonian from the Lagrangian as
$$
H_{2}(r, \theta, p_r, p_{\theta}) = \frac{p_r^2}{2m} + \frac{p_{\theta}^2}{2mr^2} + V(r) = \frac{p_r^2}{2m} + \frac{l^2}{2mr^2} + V(r) = H_{2}(r, p_r),
$$
where I concluded that $p_\theta = m r^2 \dot{\theta} = l$ is a constant.
The problem is, that I get an apparent sign difference between the $\frac{l^2}{2mr^2}$ and $V(r)$ terms in $H_{1}$ and $H_{2}$, which I don't understand. I'm pretty sure that $H_1$ is wrong, but I don't know what kind of conceptual mistake did I make when calculating $H_1$.
Conceptual issue
Apparently, when I introduce the additional potential term in the Lagrangian formalism first, then calculate the Hamiltonian, I don't get the same Hamiltonian when I do it in reverse order. Why do I get different Hamiltonians?
 A: You can't insert a  the solution of the equation of motion back into the Lagragian. You must   eliminate the conserved quantity bu using a Routhian. See the section on cyclic coordinates and on central forces in spherical coordinates.
A: Just to give a bit of further intuition, what you have done is added a quantity which you expect to be zero “on shell” to the Lagrangian, in order to try to simplify its form. But the Lagrangian is being used in a sort of minimization procedure, we are trying to find a trajectory where nearby trajectories do not change the action. This means that we also care about what manipulations do “off shell” where the Euler Lagrange equations do not hold, or more precisely we care about what the manipulations do in the vicinity of the shell because it can move the shell through the phase space.
Once you see that this is what you are trying to do, it becomes more obvious that it has no mathematical validity. The fact that something is zero at a minimum does not mean that it does not perturb that minimum to add it. So for example the family of curves $y=x^2-cx+1$ has a minimum at $x=c/2$, but if I try to use this observed consequence to simplify the function, say by adding $0=cx-c^2/4$, now the minimum is at $x=0$ not at $x=c/2$. The fact that it happens to be zero along the family of solutions does not matter one bit, because the slope does not happen to be zero along the family of solutions, so when I add this the solutions roll to one side or the other.
Hope that helps!
