Why is the derivative of $f(x)^{g(x)}$ the same as the sum of the derivative of $x^n$ and $a^x$? We did the derivation of the following formula in class today-
$$(f(x)^{g(x)})'=g(x)f(x)^{g(x)-1}f'(x)+f(x)^{g(x)}ln(f(x))g'(x)$$
My question is that if there is a reason that this is just the sum of the derivative of $x^n$ and $a^x$?
 A: It is an instance of a general rule, which can be shown using multidimensional derivatives, but is very useful even when only dealing with variables of one function:
Whenever you derive an expression that contains $x$ several ways (and all the derivatives involved in the formula exist), you can just derive for each single instance of $x$ separately, and then adding the instances together.
Applied to you case, we have two instances of $x$, which I'll number: $f(x_1)^{g(x_2)}$
Now we can easily form the derivative for $x_1$, with $x_2$ considered a constant. Clearly the whole $g(x_2)$ then is a constant, so if we write $c=g(x_2)$ we get
\begin{align}
D_1 &= (f(x)^{g(x_2)})' && \text{drop the index just for $x_1$ to show we are deriving for this}\\
&= (f(x)^c)' && \text{just renaming the constant as above}\\
&= f(x)^{c-1} f'(x) && \text{using the rule for $x^c$ and the chain rule}\\
&= f(x)^{g(x_2)-1} f'(x) && \text{re-substituting the value of $c$}\\
&= f(x)^{g(x)-1} f'(x) && \text{dropping the index because we're done with this term}
\end{align}
In the same way, we can form the derivative for $x_2$:
\begin{align}
D_2 &= (f(x_1)^{g(x)})' && \text{dropping the index for $x_2$ this time}\\
&= (a^{g(x)})' && \text{renaming the constant as $a=f(x_1)$}\\
&= (a^{g(x)}\ln a) g'(x) && \text{exponential rule and chain rule}\\
&= f(x_1)^{g(x)}g'(x)\ln f(x_1) && \text{back-substitution of $a$}\\
&= f(x)^{g(x)}g'(x)\ln f(x) && \text{dropping the remaining indices}
\end{align}
The complete derivative then is the sum of those terms:
$$(f(x)^{g(x)})' = D_1 + D_2 = f(x)^{g(x)-1} f'(x) + f(x)^{g(x)}g'(x)\ln f(x)$$
The derivation of this rule uses the multidimensional chain rule for the two functions
$$h:\mathbb R^2\to\mathbb R, h(x_1,x_2)=f(x_1)^{g(x_2)}$$
and
$$\Delta:\mathbb R\to\mathbb R^2, \Delta(x) = (x,x)$$
or, more generally,
$$h(x_1,\ldots,x_n) = \text{(expression with indices on each instance of $x$)}$$
and
$$\Delta(x) = (\underbrace{x,\ldots,x}_{\text{$n$ copies}})$$
to give
\begin{align}
\frac{\mathrm d}{\mathrm dx}h(x,\ldots,x)
&= \frac{\mathrm d}{\mathrm dx}(h\circ\Delta)(x)\\
&= \sum_{k=1}^n \left(\frac{\partial h}{\partial x_k}\circ \Delta\right)(x)\frac{\mathrm d\Delta_k}{\mathrm dx}
\end{align}
where $\frac{\partial h}{\partial x_k}$ exactly means to derive $h$ for $x_k$ while treating all the other $x_i$ as constants, and $\Delta_k$ is the $k$-th component of $\Delta$, which by definition is just $Delta_k(x)=x$, therefore the derivative is $1$, giving us the final formula
$$\frac{\mathrm d}{\mathrm dx}h(x,\ldots,x)
= \sum_{k=1}^n \left(\frac{\partial h}{\partial x_k}\circ \Delta\right)(x)$$
where as above, the $\circ\Delta$ part just means replacing all $x_k$ with $x$.

Another instance of this rule, though normally derived differently, is the product rule:
\begin{align}
(f(x)g(x))' &= (f(x)g(x_2))'+(f(x_1)g(x))' && \text{this rule}\\
&= f'(x)g(x_2) + f(x_1)g'(x) && \text{$f(x_1)$ and $g(x_2)$ are constant factors}\\
&= f'(x)g(x) + f(x)g'(x) &&\text{dropping the index}
\end{align}
Even the sum rule can be seen as instance of this, as constant terms are dropped:
$$(f(x)+g(x))' = (f(x) + g(x_2))' + (f(x_1) + g(x))' = f'(x) +g'(x)$$
