Seeming ambiguity when evaluating a function involving arctan? What am I missing? I'm trying to evaluate the following exactly:
$$\cos(\tan^{-1}(2)+\tan^{-1}(3))$$
There's a few ways to get the answer of $-\frac{\sqrt2}{2}$.  I'm interested in this particular path using the $\tan^{-1}(a)+\tan^{-1}(b) $ addition identity.  Here are the first few steps without issue:
$$\cos(\tan^{-1}(2)+\tan^{-1}(3))=\cos(\tan^{-1}(\frac{2+3}{1-2*3}))$$
$$=\cos(\tan^{-1}(-1))$$
At this point it seems straight forward to me to finish the evaluation, $-1$ can be written as $\tan(-\frac{\pi}{4})$ so we continue:
$$\cos(\tan^{-1}(\tan(-\frac{\pi}{4}))=\cos(-\frac{\pi}{4})=+\frac{\sqrt2}{2}$$
Oops...Note that we can force the "right" answer if we shift things around a bit:
$$\cos(\tan^{-1}(-1))=\cos(\tan^{-1}(-\tan(\frac{\pi}{4})))=\cos(\tan^{-1}(\tan(\pi-\frac{\pi}{4}))$$
$$\cos(\pi-\frac{\pi}{4})=-\frac{\sqrt2}{2}$$
Where did I go wrong here?  What needs to be specified at the beginning to avoid the ambiguity or what convention am I missing?
Thanks!
 A: You missed a key part of the addition identity:

$\arctan(u) + \arctan(v) = \arctan(\frac{u + v}{1 - uv})$ (mod $\pi$)

[my emphasis added on that (mod $\pi$)]
In words, after computing the quantity $\arctan(\frac{u \pm v}{1 \mp uv})$, you must then examine the input values $u$ and $v$ and use them to determine whether to add or subtract $\pi$ to get the correct answer for $\arctan(u) + \arctan(v)$. Determining whether $\pi$ gets added or subtracted can affect the positivity or negativity of the quantity $\cos(\arctan(u) + \arctan(v))$, because of the identity $\cos(\theta \pm \pi) = - \cos(\theta)$.
In your example, one can determine whether $\pi$ must be added or subtracted as follows. First, $\arctan(2)$ is the angle of the line of slope $2$ which lies in the interval $(\pi/4,\pi/2)$. And then, similarly, $\arctan(3)$ lies in that same interval $(\pi/4,\pi/2)$. Their sum $\arctan(2) + \arctan(3)$ is therefore an angle lying in the interval $(\pi/2,\pi)$. But the output of the $\arctan(...)$ on the right side of the addition identity is an angle in the interval $(-\pi/2,+\pi/2)$, so you must add $\pi$ to get a value in the interval $(\pi/2,3\pi/2)$, and when that's done you will have the correct value equal to the left hand side of the addition identity.
To summarize, what matters is not only the quadrants of the two angles $\arctan(u)$ and $\arctan(v)$, but their half-quadrants: in order to determine whether to add or subtract $\pi$ when using the addition identity, you must determine which of the four intervals the angles $\arctan(u)$ and $\arctan(v)$ lie in, namely:
$$(-\pi/2,-\pi/4], [-\pi/4,0], [0,\pi/4], [\pi/4,\pi/2)
$$
And that depends on which of the four intervals your inputs $u$ and $v$ line in, namely:
$$(\infty,-1], [-1,0], [0,+1], [+1,+\infty)
$$
