Apparent paradox between Lagrangian and Hamiltonian formulations of classical mechanics I've recently come across a strange result when comparing the Hamiltonian and Lagrangian formulations of classical mechanics.
Suppose we are working in the regime where we can say the Hamiltonian $H$ is equal to the total energy $$H=T+V.\tag{1}$$ That is, the constraints are holonomic and time-independent, and the potential is $V=V(q)$ where $q$ a the generalized position vector $q=(q_1,q_2,\ldots,q_n)$. Let $$L=T-V\tag{2}$$ be the Lagrangian.
Now, the Euler-Lagrange equations tell us 
$$\frac{d}{dt}\frac{\partial L}{\partial \dot{q_\sigma}} - \frac{\partial L}{\partial q_\sigma} = 0,\tag{3}$$
for the generalized coordinate $q_\sigma,$ with $\sigma\in\{1,\ldots,n\}$. 
We also know that the conjugate momenta are defined by $p_\sigma = \frac{\partial L}{\partial \dot{q_\sigma}}$. So this equation tells us
$$\dot{p_\sigma} - \frac{\partial L}{\partial q_\sigma} = 0.\tag{4}$$
In the Hamiltonian formalism, we know that
$$\dot{p_\sigma} = -\frac{\partial H}{\partial q_\sigma}.\tag{5}$$
Combining these gives
$$\frac{\partial H}{\partial q_\sigma}=-\frac{\partial L}{\partial q_\sigma}.\tag{6}$$
Now, this seems very strange because in the regime we are considering, this implies that
$$\frac{\partial (T+V)}{\partial q_\sigma}=-\frac{\partial (T-V)}{\partial q_\sigma}\Rightarrow \frac{\partial T}{\partial q_\sigma}=0. \tag{7}$$
Of course, there are many examples where this is not true. I.e., simply consider the free particle analyzed using polar coordinates. Then we have
$$H = L = T = \frac{1}{2}m(\dot{r}^2 + r^2\dot{\theta}^2),\tag{8}$$
and so
$$\frac{\partial T}{\partial r } \neq 0.\tag{9}$$
What is the explanation for this strange discrepancy? Am I making a silly mistake somewhere?
 A: The problem is that the Lagrangian and the Hamiltonian are functions of different variables, so you must be exceedingly careful when comparing their partial derivatives. 
Consider the differential changes in $L$ and $H$ as you shift their arguments:
$$dL = \left(\frac{\partial L}{\partial q}\right) dq + \left(\frac{\partial L}{\partial \dot q}\right) d\dot q$$
$$dH = \left(\frac{\partial H}{\partial q}\right) dq + \left( \frac{\partial H}{\partial p}\right) dp$$
Finding $\frac{\partial L}{\partial q}$ corresponds to wiggling $q$ while holding $\dot q$ fixed.  On the other hand, finding $\frac{\partial H}{\partial q}$ corresponds to wiggling $q$ while holding $p$ fixed.  If $p$ can be expressed a function of $\dot q$ only, then these two situations coincide - however, if it also depends on $q$, then they do not, and the two partial derivatives are referring to two different things.
Explicitly, write $p = p(q,\dot q)$.  Then using the chain rule, we find that
$$dH = \left(\frac{\partial H}{\partial q}\right) dq + \left(\frac{\partial H}{\partial p}\right)\left[\frac{\partial p}{\partial q} dq + \frac{\partial p}{\partial \dot q} d\dot q\right]$$
So, if we shift $q$ but hold $\dot q$ fixed, we find that
$$ dL = \left(\frac{\partial L}{\partial q} \right)dq$$
while
$$ dH = \left[\left(\frac{\partial H}{\partial q} \right) + \left(\frac{\partial H}{\partial p}\right)\left(\frac{\partial p}{\partial q} \right)\right]dq$$
If $L(q,\dot q) = H(q,p(q,\dot q))$ as in the case of a free particle, then we would find that
$$dL = dH$$
so
$$\left(\frac{\partial L}{\partial q}\right)= \left(\frac{\partial H}{\partial q} \right) + \left(\frac{\partial H}{\partial p}\right)\left(\frac{\partial p}{\partial q} \right)$$

We can check this for the free particle in polar coordinates, where
$$L = \frac{1}{2}m(\dot r^2 + r^2 \dot \theta^2)$$
$$ H = \frac{p_r^2}{2m} + \frac{p_\theta^2}{2mr^2}$$
$$ p_r = m\dot r \hspace{1 cm} p_\theta = mr^2 \dot \theta$$
for the left hand side,
$$ \frac{\partial L}{\partial r} = mr \dot \theta^2$$
For the right hand side,
$$ \frac{\partial H}{\partial r} = -\frac{p_\theta^2}{mr^3} = -mr\dot\theta^2$$
$$ \frac{\partial H}{\partial p_\theta} = \frac{p_\theta}{mr^2} = \dot \theta$$
$$ \frac{\partial p_\theta}{\partial r} = 2mr\dot \theta$$
so
$$ \frac{\partial H}{\partial r} + \frac{\partial H}{\partial p_\theta} \frac{\partial p_\theta}{\partial r} = -mr\dot \theta^2 + (\dot \theta)(2mr\dot \theta) = mr\dot \theta^2$$
as expected.

Your mistake was subtle but common.  In thermodynamics, you will often find quantities written like this:
$$ p = -\left(\frac{\partial U}{\partial V}\right)_{S,N}$$
which means

The pressure $p$ is equal to minus the partial derivative of the internal energy $U$ with respect to the volume $V$, holding the entropy $S$ and particle number $N$ constant

This reminds us precisely what variables are being held constant when we perform our differentiation, so we don't make mistakes.
A: If you look at the values of the functions:
$$
H(q,p) = T(q,p) + V(q,p)\\
L(q, \dot{q}) = T(q, \dot{q}) - V(q,\dot{q})
$$
with
$$
T(q, \dot{q}) = T(q, p)
$$
The kinetic Energy as a function of $q$ and $\dot{q}$ and the kinetic Energy as a function of $q$ and $p$ are supposed to have the same value. BUT that doesn't mean they are the same function. 
If you write it down correctly, you should write it:
$$
T(q, \dot{q}) = \tilde{T}(q, p)
$$
If you keep this in your mind, then the paradox should vannish. 
