Multivariable chain rule with vector valued function Suppose $f:\mathbb{R}^n \rightarrow \mathbb{R}$, $\mathbf{g}:\mathbb{R}^n \rightarrow \mathbb{R}^n$ and $\mathbf{x} \in \mathbb{R}^n$. How do I find a formula for $\nabla (f \circ g)(x)$? 

We have 
\begin{align*}
&f:\mathbb{R}^n \rightarrow \mathbb{R}\\
&\mathbf{y}\to f(\mathbf{y})=f(y_1,\ldots,y_n)\\
\\
&\mathbf{g}:\mathbb{R}^n \rightarrow \mathbb{R^n}\\
&\mathbf{x}\to \mathbf{g}(\mathbf{x})=\mathbf{g}(x_1,\ldots,x_n)\\
&\qquad\qquad\,=(g_1(x_1,\ldots,x_n),\ldots,g_n(x_1,\ldots,x_n))\\
\end{align*}

Recalling the nabla-operator applied to $f$
\begin{align*}
\nabla f(\mathbf{y})=\left(\frac{\partial f}{\partial y_1},\ldots,\frac{\partial f}{\partial y_n}\right)
\end{align*}
we  obtain
  \begin{align*}
\color{blue}{\nabla f(\mathbf{g}(\mathbf{x}))}
&=\left(\frac{\partial }{\partial x_j}f(\mathbf {g(\mathbf{x})})\right)_{1\leq j\leq n}\\
&=\left(\frac{\partial }{\partial x_j} f(\mathbf {g}(x_1,\ldots,x_n))\right)_{1\leq j\leq n}\\
&=\left(\frac{\partial }{\partial x_j}f(g_1(x_1,\ldots,x_n),\ldots,g_n(x_1,\ldots,x_n))\right)_{1\leq j\leq n}\\
&=\left(\frac{\partial  f}{\partial g_1}\cdot\frac{\partial g_1}{\partial x_j}+\cdots+
\frac{\partial  f}{\partial g_n}\cdot\frac{\partial g_n}{\partial x_j}\right)_{1\leq j\leq n}\\
&\,\,\color{blue}{=\left(\sum_{k=1}^n\frac{\partial f}{\partial g_k}\cdot\frac{\partial g_k}{\partial x_j}\right)_{1\leq j\leq n}}
\end{align*}

