Why Legendre transform works? Consider a function $f=f(x,y)$, with $df=u\ dx+v\ dy$, and we want the Legendre transformation $g=f-ux$, with  $dg=df-u\ dx-x\ du=\color{red}{u\ dx}+v\ dy\color{red}{-u\ dx}-x\ du=v\ dy-x\ du$ (eliminating the dependence with $x$), then $g=g(u,y)$. 
I don't understand why this works, since we have, in principle, that $g=g(x,y,u)=f(x,y)-ux$, but if $g$ doesn't depends on $x$, then $\partial g/\partial x$ must be zero:
\begin{equation}
\frac{\partial g}{\partial x}=\color{red}{\frac{\partial f}{\partial x}-u}-\frac{\partial^2 f}{\partial^2 x}x=-\frac{\partial^2 f}{\partial^2 x}x=0
\end{equation}
(Since $\frac{\partial f}{\partial x}=u$) But why is $-\frac{\partial^2 f}{\partial^2 x}x=0$? 
Clearly I'm missing something here, I will appreciate your help.
 A: The point of the Legendre transform is to switch out independent variables. You can't write $g(x,y,u)$, because $x$ and $u$ aren't independent from one another. 
Another way of looking at it is that a partial derivative means taking the derivative with respect to one variable while holding all other independent variables constant. If the variables aren't independent, you're not really taking a partial derivative since you can't hold the other variables constant. Note that this means that a partial derivative with respect to one variable implies a knowledge of all other independent variables. 
We must either write $g(x,y)$ or $g(u,y)$. If the former, then
$g(x,y) = f(x,y) - \frac{\partial f}{\partial x} x$
then 
$\frac{\partial g}{\partial x} = \frac{\partial f}{\partial x} - \frac{\partial f}{\partial x} - \frac{\partial^2 f}{\partial x^2} x = -\frac{\partial^2 f}{\partial x^2} x$
and it is not zero in general.
And if we write $g(u,y)$, then $\frac{\partial g}{\partial x}$ is meaningless.
