Where did it come from? (derivative of exponential) We all know this rule:

$\text{If } y = a^{f(x)} \text{ then } y' = a^{f(x)} \: f'(x)\ln a$

In my book there is the example:
Find $\frac{d}{dx}\left((x^{2} + 1)^{\sin x}\right)$
According to the rule, my answer is:
$(x^{2} + 1)^{\sin x} \cdot \cos x \cdot \ln(x^{2} + 1)$
But the answer of the book was:
$$(x^{2} + 1)^{\sin x}\left(\frac{2x \sin x}{x^{2} + 1} + \cos x \cdot \ln(x^{2} + 1)\right)$$
So, where did $\frac{2x \sin x}{x^{2} + 1}$ come from?
 A: The rule that you quote is only valid if a is a constant.
A: I will assume that this is not homework and go ahead to give a full solution.
As others have said, your rule only works for constant $a$. Following the hint in danielson's answer and setting $y=f(x)$, you have $$\log y=\sin x\log\left(1+x^2\right)$$
and differentiating both sides with respect to $x$ and using the chain and product rules gives $$\frac1y\frac{dy}{dx}=\cos x\log\left(1+x^2\right)+\frac{2x\sin x}{1+x^2}\quad\text{so that}\quad \frac{dy}{dx}=y\left(\cos x\log\left(1+x^2\right)+\frac{2x\sin x}{1+x^2}\right).$$Substituting back for $y$ gives the result. 
Tell me if you don't understand any of the applications of the chain rule.
A: Start with $$f(x)=e^{\ln(x^2+1)\sin(x)}$$
The chain rule gives
$$f'(x)=e^{\ln(x^2+1)\sin(x)}\times (\ln(x^2+1)\sin(x))'=(x^2+1)^{\sin(x)}(\ln(x^2+1)\sin(x))'$$
Take it from here.
A: The rule that you have given is for $\textit{constant}$ $a$, while the base of your function is a $\textit{function}$. So the rule does not apply here. 
To fix this, let $f(x) = (x^2 + 1)^{\sin(x)}$ and consider $\ln(f(x))$. Differentiate the new function, while also utilizing a nice property of exponents inside logarithmic functions, and try to deduce the derivative of the original function from this.

A: The rule is
$$\frac d{dx}u(x)^{v(x)}=v(x)u(x)^{v(x)-1}\frac{du}{dx}+u(x)^{v(x)}(\ln u(x))\frac{dv}{dx}.$$
You can derive this by the method of logarithmic differentiation. It is a special case of the two-variable chain rule:
$$\frac{dw}{dx}=\frac{\partial w}{\partial u}\frac{du}{dx}+\frac{\partial w}{\partial v}\frac{dv}{dx}.$$
Notice how it simplifies to familiar rules if either $u(x)$ or $v(u)$ is a constant. This makes the general formula easy to remember. If $u$ is variable and $v$ is constant then,
$$(u^v)
'=vu^{v-1}u';$$
if $v$ is variable and $u$ is constant, then
$$(u^v)'=u^v(\ln u)v';$$
if $u$ and $v$ are both variables, then
$$(u^v)'=vu^{v-1}u'+u^v(\ln u)v'.$$
