<s>[INST] 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?
 [/INST] 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}
</s>