Partial differentiation of a composite function This should be straightforward, but don't seem to be able to crack it. Take a function $f(x_1, x_2, x_3)$ and a function $g(x4, x5, x6)$. These two functions mapp from $R^3 \rightarrow R^1$. I am interested in the partial derivatives of the following combination $ h(x_1, x_2, x4, x5, x6) = f(x_1, x_2, g(x4, x5, x6))$, or in other words $\frac{\partial h}{\partial x_1}, \;\frac{\partial h}{\partial x_2}, \dots, \,\frac{\partial h}{\partial x_6}$. 
I only have access to $f$, $\frac{\partial f}{\partial x_{1,2,3}}$, $g$ and $\frac{\partial g}{\partial x_{4,5,6}}$ (i.e, $f$ and $g$ and their respective partial derivatives).
This should be a straightforward application of the chain rule, but I can't really see how it would work, and would appreciate a step-by-step guidance at how one would go at this.
 A: It should be clear that
$$\frac{\partial h}{\partial x_1}=\frac{\partial f}{\partial x_1}\big(x_1,x_2,g(x_4,x_5,x_6)\big)$$
The same for the partial w.r.t. $x_2$.
Use the chain rule for $x_4$:
$$\frac{\partial }{\partial x_4}f\big(x_1,x_2,g(x_4,x_5,x_6)\big)=\frac{\partial g}{\partial x_4}\big(x_4,x_5,x_6\big) \frac{\partial f}{\partial x_3} \big(x_1,x_2,g(x_4,x_5,x_6)\big).$$
The same for $x_5$ and $x_6$.
AN EXAMPLE:
$$f(x_1,x_2,x_3)=x_1x_2x_3$$
$$g(x_4,x_5,x_6)=x_4+x_5+x_6$$
So we have 
$$h(x_1,x_2,x_4,x_5,x_6):=f\big(x_1,x_2,g(x_4,x_5,x_6)\big)=x_1x_2(x_4+x_5+x_6)$$
Now we can see that 
$$\begin{align}
 \frac{\partial }{\partial x_1} f &= x_2x_3 \\
 \frac{\partial }{\partial x_4} g &=  1\\
 \frac{\partial }{\partial x_1} h &= x_2(x_4+x_5+x_6) \\
 \frac{\partial }{\partial x_4} h &= x_1x_2
\end{align}$$
Using the first formula:
$$\frac{\partial h}{\partial x_1}=\frac{\partial f}{\partial x_1}\big(x_1,x_2,g(x_4,x_5,x_6)\big)=x_2g(x_4,x_5,x_6)=x_2(x_4+x_5+x_6),$$
which agrees.
Using the second formula:
$$\frac{\partial }{\partial x_4}f\big(x_1,x_2,g(x_4,x_5,x_6)\big)=\frac{\partial g}{\partial x_4}\big(x_4,x_5,x_6\big) \frac{\partial f}{\partial x_3} \big(x_1,x_2,g(x_4,x_5,x_6)\big)
=1 \cdot x_1x_2,$$
which also agrees.
