Derivative of $\tan^{-1}\left(\sqrt{\frac{a-b}{a+b}}\tan \frac x2\right)$. 
Find the derivative of $\tan^{-1}\left(\sqrt{\frac{a-b}{a+b}}\tan \frac x2\right)$.

I'm learning differentiation and this is an exercise problem from my book. I used chain rule and got the following:
$\begin{align}
\dfrac d{dx}\left[\tan^{-1}\left(\sqrt{\frac{a-b}{a+b}}\tan\frac x2\right)\right] &= \dfrac{1}{1+\frac{a-b}{a+b}\tan^2\frac x 2}\cdot\dfrac{d}{dx}\left(\sqrt{\frac{a-b}{a+b}}\tan \frac x2\right)\\ &= \dfrac{1}{1+\frac{a-b}{a+b}\tan^2\frac x 2}\cdot\frac 1 2\sqrt{\frac{a-b}{a+b}}\sec^2\frac x 2
\end{align}$
But this doesn't match the answer in the book. The given answer is $\frac{\sqrt{a^2-b^2}}{2(a+b\cos x)}$. So, where did I go wrong and what is the correct solution?
 A: Power of $t$-formula
Let $t=\tan \dfrac{x}{2}$, then
\begin{align}
  \frac{dt}{dx} &= \frac{1}{2} \sec^2 \frac{x}{2} \\
  &= \frac{1+t^2}{2} \\
  \tan y &= t\sqrt{\frac{a-b}{a+b}} \\
  \sec^2 y \times \frac{dy}{dx} &=
  \frac{dt}{dx} \times \sqrt{\frac{a-b}{a+b}} \\
  \left( 1+\frac{a-b}{a+b} t^2 \right) \frac{dy}{dx}
  &= \frac{1+t^2}{2} \times \sqrt{\frac{a-b}{a+b}} \\
  \frac{dy}{dx} &=
  \sqrt{\frac{a-b}{a+b}} \times \frac{(a+b)(1+t^2)}{2[a+b+(a-b)t^2]} \\
  &= \frac{\sqrt{a^2-b^2}}{2} \times \frac{1+t^2}{a(1+t^2)+b(1-t^2)} \\
  &= \frac{\frac{1}{2} \sqrt{a^2-b^2}}
          {a+b\left( \frac{1-t^2}{1+t^2} \right)} \\
  &= \frac{\sqrt{a^2-b^2}}{2(a+b\cos x)}
\end{align}
A: Just keep going from where you stopped: Taking things one or two steps at a time, we have
$$\begin{align}
{1\over1+{a-b\over a+b}\tan^2{x\over2}}\cdot{1\over2}\sqrt{a-b\over a+b}\sec^2{x\over2}
&={a+b\over a+b+(a-b)\tan^2{x\over2}}\cdot{1\over2}\sqrt{a-b\over a+b}\sec^2{x\over2}\\
&={1\over2}\cdot{\sqrt{(a+b)(a-b)}\over a+b+(a-b)\tan^2{x\over2}}\cdot{1\over\cos^2{x\over2}}\\
&={1\over2}\cdot{\sqrt{a^2-b^2}\over(a+b)\cos^2{x\over2}+(a-b)\sin^2{x\over2}}\\
&={1\over2}\cdot{\sqrt{a^2-b^2}\over a\left(\cos^2{x\over2}+\sin^2{x\over2}\right)+b\left(\cos^2{x\over2}-\sin^2{x\over2}\right)}\\
&={1\over2}\cdot{\sqrt{a^2-b^2}\over a+b\cos x}
\end{align}$$
