Partial Derivatives of Nested Functions Suppose I have a function $f(x(a,b),y(a,b))$ of functions $x$ and $y$ such that $x,y,f : \mathbb{R}^2 \rightarrow \mathbb{R}$. How would I go about finding the partial second derivatives of $f$, $\frac{\partial^2 f}{\partial a^2}$, $\frac{\partial^2 f}{\partial a \partial b}$, $\frac{\partial^2 f}{\partial b \partial a}$, and $\frac{\partial^2 f}{\partial b^2}$?
So far, I have followed my intuition and figured that $\frac{\partial^2 f}{\partial a^2}$ would have the form
\begin{align*}
\frac{\partial^2 f}{\partial a^2} =& \frac{\partial}{\partial a} \frac{\partial f}{\partial a} \\
&\text{chain rule} \\
=& \frac{\partial}{\partial a} \left(\frac{\partial f}{\partial x} \frac{\partial x}{\partial a}+\frac{\partial f}{\partial y} \frac{\partial y}{\partial a}\right) \\
&\text{product rule} \\
=& \left(\frac{\partial}{\partial a}\frac{\partial f}{\partial x}\right) \frac{\partial x}{\partial a} +  \frac{\partial f}{\partial x} \left(\frac{\partial}{\partial a}\frac{\partial x}{\partial a}\right)+\left(\frac{\partial}{\partial a}\frac{\partial f}{\partial y}\right) \frac{\partial y}{\partial a} +  \frac{\partial f}{\partial y} \left(\frac{\partial}{\partial a}\frac{\partial y}{\partial a}\right)\\
&\text{simplify} \\
=& \left(\frac{\partial}{\partial a}\frac{\partial f}{\partial x}\right) \frac{\partial x}{\partial a} +  \frac{\partial f}{\partial x} \frac{\partial^2 x}{\partial a^2} +\left(\frac{\partial}{\partial a}\frac{\partial f}{\partial y}\right) \frac{\partial y}{\partial a} +  \frac{\partial f}{\partial y} \frac{\partial^2 y}{\partial a^2}\\
&\text{switch order of derivatives} \\
=& \underbrace{\left(\frac{\partial}{\partial x}\frac{\partial f}{\partial a}\right) \frac{\partial x}{\partial a}}_\text{(don't really like this step)} +  \frac{\partial f}{\partial x} \frac{\partial^2 x}{\partial a^2} +\underbrace{\left(\frac{\partial}{\partial y}\frac{\partial f}{\partial a}\right) \frac{\partial y}{\partial a}}_\text{(don't really like this step)} +  \frac{\partial f}{\partial y} \frac{\partial^2 y}{\partial a^2}\\
&\text{chain rule again} \\
=& \frac{\partial}{\partial x}\left(\frac{\partial f}{\partial x}\frac{\partial x}{\partial a}+\frac{\partial f}{\partial y}\frac{\partial y}{\partial a}\right) \frac{\partial x}{\partial a} +  \frac{\partial f}{\partial x} \frac{\partial^2 x}{\partial a^2} +\frac{\partial}{\partial y}\left(\frac{\partial f}{\partial x}\frac{\partial x}{\partial a}+\frac{\partial f}{\partial y}\frac{\partial y}{\partial a}\right) \frac{\partial y}{\partial a} +  \frac{\partial f}{\partial y} \frac{\partial^2 y}{\partial a^2} \\
&\text{product rule again} \\
=& \frac{\partial^2 f}{\partial x^2}\left(\frac{\partial x}{\partial a}\right)^2  +\frac{\partial f}{\partial x}\frac{\partial}{\partial x}\left(\frac{\partial x}{\partial a}\right) \frac{\partial x}{\partial a} + \frac{\partial^2 f}{\partial x\partial y}\frac{\partial y}{\partial a} \frac{\partial x}{\partial a}  +\frac{\partial f}{\partial y}\frac{\partial}{\partial x}\left(\frac{\partial y}{\partial a}\right) \frac{\partial x}{\partial a} +  \frac{\partial f}{\partial x} \frac{\partial^2 x}{\partial a^2} +\frac{\partial^2 f}{\partial y\partial x}\frac{\partial x}{\partial a} \frac{\partial y}{\partial a}  +\frac{\partial f}{\partial x}\frac{\partial}{\partial y}\left(\frac{\partial x}{\partial a}\right) \frac{\partial y}{\partial a} +\frac{\partial^2 f}{\partial y^2}\left(\frac{\partial y}{\partial a}\right)^2  +\frac{\partial f}{\partial y}\frac{\partial}{\partial y}\left(\frac{\partial y}{\partial a}\right) \frac{\partial y}{\partial a} + \frac{\partial f}{\partial y} \frac{\partial^2 y}{\partial a^2} \\
&\text{switch the order of derivatives again} \\
=& \frac{\partial^2 f}{\partial x^2}\left(\frac{\partial x}{\partial a}\right)^2  +\frac{\partial f}{\partial x}\underbrace{\frac{\partial}{\partial a}\left(\frac{\partial x}{\partial x}\right)}_\text{again, eh} \frac{\partial x}{\partial a} + \frac{\partial^2 f}{\partial x\partial y}\frac{\partial y}{\partial a} \frac{\partial x}{\partial a}  +\frac{\partial f}{\partial y}\underbrace{\frac{\partial}{\partial a}\left(\frac{\partial y}{\partial x}\right)}_\text{again, eh} \frac{\partial x}{\partial a} +  \frac{\partial f}{\partial x} \frac{\partial^2 x}{\partial a^2} +\frac{\partial^2 f}{\partial y\partial x}\frac{\partial x}{\partial a} \frac{\partial y}{\partial a}  +\frac{\partial f}{\partial x}\underbrace{\frac{\partial}{\partial a}\left(\frac{\partial x}{\partial y}\right)}_\text{again, eh} \frac{\partial y}{\partial a} +\frac{\partial^2 f}{\partial y^2}\left(\frac{\partial y}{\partial a}\right)^2  +\frac{\partial f}{\partial y}\underbrace{\frac{\partial}{\partial a}\left(\frac{\partial y}{\partial y}\right)}_\text{again, eh} \frac{\partial y}{\partial a} + \frac{\partial f}{\partial y} \frac{\partial^2 y}{\partial a^2} \\
&\text{simplify again} \\
=& \frac{\partial^2 f}{\partial x^2}\left(\frac{\partial x}{\partial a}\right)^2  + \frac{\partial^2 f}{\partial x\partial y}\frac{\partial y}{\partial a} \frac{\partial x}{\partial a}  +  \frac{\partial f}{\partial x} \frac{\partial^2 x}{\partial a^2} +\frac{\partial^2 f}{\partial y\partial x}\frac{\partial x}{\partial a} \frac{\partial y}{\partial a}  +\frac{\partial^2 f}{\partial y^2}\left(\frac{\partial y}{\partial a}\right)^2 + \frac{\partial f}{\partial y} \frac{\partial^2 y}{\partial a^2} \\
\end{align*}
In order to do this, I have assumed that the second order derivatives are continuous, allowing me to switch the order that I take those derivatives, and I am sort of ok with that. The other second order partial derivatives mentioned would be similar to this, but I am still unsure of my work. Does this intuitive approach hold up mathematically?
 A: The transformation in the line with don't really like this step is not admissible.
We recall
\begin{align*}
\frac{\partial f}{\partial a}=\frac{\partial f}{\partial x}\,\frac{\partial x}{\partial a}
+\frac{\partial f}{\partial y}\,\frac{\partial y}{\partial a}\tag{1}
\end{align*}
or more verbose
\begin{align*}
\frac{\partial f}{\partial a}\left(x(a,b),y(a,b)\right)
&=\frac{\partial f}{\partial x}\left(x(a,b),y(a,b)\right)\,\frac{\partial x}{\partial a}(a,b)\\
&\qquad+\frac{\partial f}{\partial y}\left(x(a,b),y(a,b)\right)\,\frac{\partial y}{\partial a}(a,b)\tag{2}
\end{align*}

Everything is fine up to
  \begin{align*}
\frac{\partial^2 f}{\partial a^2} =\cdots= \left(\frac{\partial}{\partial a}\frac{\partial f}{\partial x}\right) \frac{\partial x}{\partial a} +  \frac{\partial f}{\partial x} \frac{\partial^2 x}{\partial a^2} +\left(\frac{\partial}{\partial a}\frac{\partial f}{\partial y}\right) \frac{\partial y}{\partial a} +  \frac{\partial f}{\partial y} \frac{\partial^2 y}{\partial a^2}\tag{3}\\
\end{align*}
  The first term at the right-hand side of (3) is in fact
  \begin{align*}
\left(\frac{\partial}{\partial a}\left(\frac{\partial f}{\partial x}\right) \right)\frac{\partial x}{\partial a} 
\end{align*}
  which can be written more verbose as
  \begin{align*}
\left(\frac{\partial}{\partial a}\left(\frac{\partial f}{\partial x}\left(x(a,b),y(a,b)\right)\right) \right)\frac{\partial x}{\partial a}(a,b)\tag{4}
\end{align*}

We see in (4) it is not admissible to exchange the partial derivative operators but have instead to apply the same rule as in (1) resp. (2).

We obtain from (3) by applying the rule (1)
  \begin{align*}
\color{blue}{\frac{\partial^2 f}{\partial a^2}}& =\cdots\\
&= \left(\frac{\partial}{\partial a}\left(\frac{\partial f}{\partial x}\right)\right) \frac{\partial x}{\partial a} +  \frac{\partial f}{\partial x} \frac{\partial^2 x}{\partial a^2} +\left(\frac{\partial}{\partial a}\left(\frac{\partial f}{\partial y}\right)\right) \frac{\partial y}{\partial a} +  \frac{\partial f}{\partial y} \frac{\partial^2 y}{\partial a^2}\\
&=\left(\frac{\partial^2 f}{\partial x^2}\,\frac{\partial  x}{\partial a}
+\frac{\partial ^2f}{\partial y\partial x}\,\frac{\partial y}{\partial a}\right)\frac{\partial x}{\partial a}
+  \frac{\partial f}{\partial x} \frac{\partial^2 x}{\partial a^2}\\
&\qquad+\left(\frac{\partial^2 f}{\partial x\,\partial y}\,\frac{\partial  x}{\partial a}
+\frac{\partial ^2f}{\partial y^2}\,\frac{\partial y}{\partial a}\right)\frac{\partial x}{\partial a}
+  \frac{\partial f}{\partial y} \frac{\partial^2 y}{\partial a^2}\\
&\color{blue}{=\frac{\partial^2f}{\partial x^2}\left(\frac{\partial x}{\partial a}\right)^2
+2\frac{\partial ^2f}{\partial x\,\partial y}\,\frac{\partial x}{\partial a}\,\frac{\partial y}{\partial a}
+\frac{\partial^2f}{\partial y^2}\left(\frac{\partial y}{\partial a}\right)^2}\\
&\qquad\color{blue}{+\frac{\partial f}{\partial x}\,\frac{\partial^2 x}{\partial a^2}+\frac{\partial f}{\partial y}\,\frac{\partial^2 y}{\partial a^2}}
\end{align*}

In the last line we collect terms accordingly assuming the functions are continuous and we can change the order of partial derivatives.
