Derivative of a composed function with several variables I am struggling to find the first derivative of a composed function with several variables. I think the solution of the problem involves the chain rule or some generalised form, but I can not see how to do it. Any hint or help is appreciated.
The situation:
Lets assume we have variables $x_1, \dots, x_4$. These are transformed by a function $f$, which returns more than the given $4$ parameters.
For example: $$
f: \mathbb{R}^4 \rightarrow \mathbb{R}^6, \quad
x_1, x_2, x_3, x_4 \rightarrow (0, x_1 + x_3, 2 \cdot x_1 + x_4, 0, x_2 + x_3, 2 \cdot x_2 + x_4)
$$ 
The 'output' of $f$, let us call it $\mathbf{y} = (y_1, y_2, \dots, y_6)$, is processed by another function $g$ which is defined as followed: 
$$g:\mathbb{R}^6 \rightarrow \mathbb{R}^6, (y_1, y_2, \dots, y_6) \rightarrow (\exp(-y_1), \exp(-y_2), \dots, \exp(-y_6))$$
Then we have a third function $h$ which takes the 'output' of $g$, let us call this 'output' $\mathbf{z} = (z_1, z_2, \dots, z_6)$, and processes it further, returning some single value, so we have $h: \mathbb{R}^6 \rightarrow \mathbb{R}$. (I will not show the concrete definition of $h$, because I do not think it does help, but rather complicates things.)
What I am looking for is the first derivative of $h$ with respect to the original four parameters $x_1, \dots, x_4$.
What I tried is to apply the simple chain rule, like in the following. But I am not shure if this is correct or if I do miss something. Let's say we are interested in the first derivative of $h$ with respect to $x_2$. Then I got the following with the simple chain rule:
$$
\frac{\partial h}{\partial x_4} = \frac{dh}{d\mathbf{z}} \cdot \frac{dg}{d\mathbf{y}} \cdot \frac{\partial f}{\partial x_2}
$$
While writing this question, I ask myself if I need some 'partial derivative' of $h$ and $g$, but with respect to which parameter? All involving $x_2$?
Any help or hints will be appreciated. Thank you!
Best,
Michael
 A: One considers a function $K:\mathbb R^4\to\mathbb R$ such that $K=h\circ g\circ f$ for some functions $f$, $g$ and $h$, with  $f:\mathbb R^4\to\mathbb R^6$, $g:\mathbb R^6\to\mathbb R^6$, and $h:\mathbb R^6\to\mathbb R$. 
Let $f=(f_i)_{1\leqslant i\leqslant6}$ and $g=(g_i)_{1\leqslant i\leqslant 6}$. Let $\partial_k$ denote the partial derivative with respect to the $k$th coordinate. 
Then, for every functions $\varphi:\mathbb R^n\to\mathbb R^m$ and $\psi:\mathbb R^m\to\mathbb R$ and every $\mathbf a$ in $\mathbb R^n$, the chain rule indicates that
$$
\partial_k(\psi\circ\varphi)(\mathbf a)=\sum\limits_{i=1}^{m}\partial_i\psi(\mathbf b)\cdot\partial_k\varphi(\mathbf a),
$$
where $\mathbf b=\varphi(\mathbf a)$ is in $\mathbb R^m$.
Using the chain rule twice, one sees that, for every $1\leqslant k\leqslant4$ and every $\mathbf a$ in $\mathbb R^4$,
$$
\partial_k K(\mathbf a)=\sum_{i=1}^6\partial_ih(\mathbf c)\cdot\sum_{j=1}^6\partial_jg_i(\mathbf b)\cdot\partial_kf_j(\mathbf a),
$$
where one used the shorthands $\mathbf b=f(\mathbf a)$ and $\mathbf c=g(\mathbf b)$, hence $\mathbf b$ and $\mathbf c$ are in $\mathbb R^6$.
