Trouble with partial derivatives and changing variables I am struggling with how to bring a factor of $\frac{1}{r}$ inside of a derivative in the following question:
Spherical polar coordinates $(r,\theta,\phi)$ are defined in terms of cartesian coordinates $(x,y,z)$ by
$$x=r\ \mathrm{sin}\ \theta\ \mathrm{cos}\ \phi, \ y=r\ \mathrm{sin}\ \theta\ \mathrm{sin}\ \phi,\ z = r\ \mathrm{cos}\ \theta$$
Given that $f$ is a function of $r$ only, independent of $\theta$ and $\phi$, show that
$$\frac{\partial^2f}{\partial x^2} = \frac{1}{r}\frac{df}{dr} + \frac{x^2}{r}\frac{d}{dr}\left(\frac{1}{r}\frac{df}{dr}\right)$$
given that
$$\frac{\partial f}{\partial x} = \frac{x}{r}\frac{df}{dr}$$.
I can take a partial derivative of $\frac{\partial f}{\partial x}$ with respect to $x$ using the product rule:
$$\frac{\partial^2f}{\partial x^2} = \frac{df}{dr}\frac{\partial}{\partial x} \frac{x}{r} + \frac{x}{r}\frac{\partial}{\partial x}\frac{df}{dr}$$
$$= \frac{1}{r}\frac{df}{dr} +\frac{x}{r}\frac{\partial r}{\partial x}\frac{\partial}{\partial r}\left(\frac{df}{dr}\right) $$
$$\frac{\partial r}{\partial x} = \frac{\partial}{\partial x} \sqrt{x^2+y^2+z^2} = \frac{x}{r}$$
$$ \rightarrow \frac{1}{r}\frac{df}{dr} + \frac{x^2}{r^2}\frac{d}{dr}\left(\frac{df}{dr}\right)$$
and I don't see why this is equivalent to the "show that" expression.
Can anyone help me see why? Is it because my naive attempt at a chain rule has messed things up?
 A: We start with the property
$$\frac{\partial f}{\partial x}=\frac{x}{r}\frac{df}{dr}$$
Taking the partial derivative with respect to $x$,
$$\frac{\partial^2f}{\partial x^2}=\frac{\partial}{\partial x}\left(\frac{x}{r}\frac{df}{dr}\right)=\frac{1}{r}\frac{df}{dr}+x\frac{\partial}{\partial x}\left(\frac{1}{r}\frac{df}{dr}\right)$$
Here, all we did was employ the product rule. The function $\frac{1}{r}\frac{\partial f}{\partial r}$ is a function that only depends on $r$, so we can employ our starting equation again, where the partial derivative with respect to $x$ is equivalent to the total derivative with respect to $r$ then multiplying by $x/r$. Thus,
$$\frac{\partial^2f}{\partial x^2}=\frac{1}{r}\frac{df}{dr}+x\frac{\partial}{\partial x}\left(\frac{1}{r}\frac{df}{dr}\right)=\frac{1}{r}\frac{df}{dr}+x\frac{x}{r}\frac{d}{dr}\left(\frac{1}{r}\frac{df}{dr}\right)$$
and we are done. The error you have made is in factoring the $1/r$ out when taking the derivative with respect to $x$, which is not correct, since $r$ is also a function of $x$. Hope this helps!
Edit: As an explanation as to why your derivation was incorrect, we need to dive a bit into the notation that we use to represent derivative operators and how these operations change. It all has to do with coordinates, which are different from points. A point is just that; a point in a greater space. When working with PDEs, a point is just a location inside a domain, or along the boundary of the domain. A coordinate is a collection of numbers used to identify the point. You and I can have completely different coordinates but describe the same set of points, and so long as our equations are consistent then there is no issue.
The derivative operators we know and love so much cause an issue because of this. If we wanted a language we could both agree on, we would describe the change in a function as we move between points, but points are abstract and don't have native $\mathbb{R}^n$ representations, so there is no way to describe derivatives concretely without using coordinates (this not entirely true, since we can describe derivatives in terms of other properties, but the notion of direction then gets complicated). This means that if I want to talk about derivatives, I should stick with one set of coordinates and try not to mix them. If I do, I have to try to think of the quantities in question as functions of just one set of coordinates, not both.
We start with the function $f$. I can think of it as a function of $(x,y,z)$ and compute the quantity $\frac{\partial f}{\partial x}$. To find out how to compute this value in your coordinates, we instead assume that $f$ is a function of $(r,\theta,\phi)$ and do
$$\frac{\partial }{\partial x}f(r,\theta,\phi)=\frac{\partial f}{\partial r}\frac{\partial r}{\partial x}+\frac{\partial f}{\partial \theta}\frac{\partial\theta}{\partial x}+\frac{\partial f}{\partial\phi}\frac{\partial\phi}{\partial x}$$
We are told that $f$ only has radial dependency, so we again abuse notation and wriite this as
$$\frac{\partial f}{\partial x}=\frac{df}{dr}\frac{\partial r}{\partial x}$$
We have
$$r^2=x^2+y^2+z^2\implies2r\frac{\partial r}{\partial x}=2x\implies\frac{\partial r}{\partial x}=\frac{x}{r}$$
This last part mixes coordinates, so it's less than ideal. When we take future derivatives, we either have to think of the whole thing as a function of $(x,y,z)$, or as a function of $(r,\theta,\phi)$. For example,  if we wanted the derivative with respect to $x$ (like we do), we would do
$$\frac{\partial}{\partial x}\left(\frac{x}{r(x,y,z)}\right)$$
If instead we wanted a derivative with respect to $r$, we would have to write
$$\frac{\partial}{\partial r}\left(\frac{x(r,\theta,\phi)}{r}\right)$$
Ultimately, we have to make sure that when taking a derivative in one coordinate system, we treat the other coordinate system as functions. This all comes from the fact that we are abusing the notation and treating the coordinates as the points, which is not correct. To do this all rigorously, we would have to define functions that map points to coordinates, then take derivatives of composite functions, and the notation would get cumbersome. Instead, we settle for slightly confusing writing to simplify the nasty true writing.
I can dive even deeper if you'd like, but that's your quick and dirty explanation.
