What is $\arctan(x) + \arctan(y)$ I know $$g(x) = \arctan(x)+\arctan(y) = \arctan\left(\frac{x+y}{1-xy}\right)$$
which follows from the formula for $\tan(x+y)$. But my question is that my book defines it to be domain specific, by which I mean, has different definitions for different domains:
$$g(x) = \begin{cases}\arctan\left(\dfrac{x+y}{1-xy}\right), &xy < 1 \\[1.5ex] 
\pi + \arctan\left(\dfrac{x+y}{1-xy}\right), &x>0,\; y>0,\; xy>1 \\[1.5ex] 
-\pi + \arctan\left(\dfrac{x+y}{1-xy}\right), &x<0,\; y<0,\; xy > 1\end{cases}$$
Furthermore, When I plot the function $2\arctan(x)$, it turns out that the book definition is correct. I don't understand how such peculier definition emerges. Thank you. 

Here is a straightforward (though long) derivation of the piece wise function description of $\arctan(x)+\arctan(y)$.
We will show that:
$\arctan(x)+\arctan(y)=\begin{cases}-\frac{\pi}{2} \quad &\text{if $xy=1$, $x\lt 0$, and $y \lt 0$} \\\frac{\pi}{2} \quad &\text{if $xy=1$, $x\gt 0$, and $y \gt 0$} \\ \arctan\left(\frac{x+y}{1-xy}\right) \quad &\text{if $xy \lt 1$} \\\arctan\left(\frac{x+y}{1-xy}\right)+\pi \quad &\text{if $xy \gt 1$ and $x \gt 0$, $y \gt 0$}\\ \arctan\left(\frac{x+y}{1-xy}\right)-\pi \quad &\text{if $xy \gt 1$ and $x \lt 0$, $y \lt 0$} \end{cases}$
working from these below statements:

*

*$\arctan$ is strictly increasing and $\arctan(0)=0$


*if $x \gt 0$ then $\arctan(x)+\arctan(\frac{1}{x})= \frac{\pi}{2}$ and if $x \lt 0$ then $\arctan(x)+\arctan(\frac{1}{x})=-\frac{\pi}{2}$


*$\text{dom}(\arctan)=\mathbb R$ and $\text{image}(\arctan)=(-\frac{\pi}{2},\frac{\pi}{2})$

Case 1: $xy=1$
Under these circumstances, you can derive that $x\gt 0$ and $y \gt 0 \implies \arctan(x)+\arctan(y)=\frac{\pi}{2}$. Alternatively, $x \lt 0$ and $y \lt 0 \implies \arctan(x)+\arctan(y)  = -\frac{\pi}{2}$

Case 2: $xy \lt 1$
Under these circumstances, you can derive that $\arctan(x)+\arctan(y) \in (-\frac{\pi}{2},\frac{\pi}{2})$

Case 3: $xy \gt 1$
There are two subcases to consider. Either $x \gt 0$ and $y \gt 0$ OR $x \lt 0$ and $y \lt 0$.
If $x \gt 0$ and $y \gt 0$,  the we argue as follows.
Because $x \gt 0$ and $xy \gt 1$, we necessarily have that $y \gt \frac{1}{x}$. Next, because $x \gt 0$, we must have that $\arctan(x)+\arctan(\frac{1}{x}) = \frac{\pi}{2}$. Given that $\arctan$ is a strictly increasing function, we then have that $\frac{\pi}{2}=\arctan(x)+\arctan(\frac{1}{x}) \lt \arctan(x)+\arctan(y)$. Finally, we know that for any $z \gt 0:\arctan(z) \in (0,\frac{\pi}{2})$.
With the above argument, we conclude that $\arctan(x)+\arctan(y) \in (\frac{\pi}{2}, \pi)$.
A similar argument would lead one to have that if $x \lt 0$ and $y \lt 0$, then  $\arctan(x)+\arctan(y) \in (-\pi,-\frac{\pi}{2})$.

With these three cases established, we can now look at the identity:
$$\tan(\alpha+\beta)=\frac{\tan(\alpha)+\tan(\beta)}{1-\tan(\alpha)\tan(\beta)}$$
Letting $\alpha=\arctan(x)$ and $\beta=\arctan(y)$, we can rewrite the above identity as:
$$\tan(\arctan(x)+\arctan(y))=\frac{\tan(\arctan(x))+\tan(\arctan(y))}{1-\tan(\arctan(x))\tan(\arctan(y))}=\frac{x+y}{1-xy} \quad (\dagger_1)$$
From our previous work, we know that across all values of $x,y \in \mathbb R$, the sum $\arctan(x)+\arctan(y)$ can take on the values:

*

*$-\frac{\pi}{2}$ or $\frac{\pi}{2}$


*$(-\frac{\pi}{2},\frac{\pi}{2})$


*$(-\pi,-\frac{\pi}{2})$ or $(\frac{\pi}{2},\pi)$
Importantly, we know that $\tan$ is a periodic function (with period of $\pi$) defined on $\cdots (-\frac{3\pi}{2},-\frac{\pi}{2}), (-\frac{\pi}{2},\frac{\pi}{2}),(\frac{\pi}{2},\frac{3\pi}{2})\cdots \quad (\dagger_2)$
Further, by definition, $\arctan$ is the inverse function of $\tan$ when $\tan$ is restricted to $(-\frac{\pi}{2},\frac{\pi}{2})$.

With the above work in mind, how do we now precisely determine what $\arctan(x)+\arctan(y)$ equals?

Firstly, we know from Case 1 that if $x \lt 0, y\lt 0,$ and $xy=1$, then $\arctan(x)+\arctan(y)=-\frac{\pi}{2}$. Similarly, if $x \gt 0, y \gt 0,$ and $xy=1$, then $\arctan(x)+\arctan(y)=\frac{\pi}{2}$
Next, we can use the result from Case 2 and $(\dagger_1)$ to conclude that if $xy \lt 1$, then $\arctan(x)+\arctan(y)=\arctan\left(\frac{x+y}{1-xy}\right)$. This is because the argument of $\tan$, in the instance of Case 2, spans from $(-\pi/2,\pi/2)$, which implies that we are dealing with a $\tan$ function whose domain is restricted to $(-\pi/2,\pi/2)$. Therefore, when we take the $\arctan$ of $\tan(z)$, it simply computes to $z$.
So far, then, we have the piecewise function:
$\arctan(x)+\arctan(y)=\begin{cases}-\frac{\pi}{2} \quad &\text{if $xy=1$, $x\lt 0$, and $y \lt 0$} \\\frac{\pi}{2} \quad &\text{if $xy=1$, $x\gt 0$, and $y \gt 0$} \\ \arctan\left(\frac{x+y}{1-xy}\right) \quad &\text{if $xy \lt 1$}\end{cases}$
For the final part (i.e. consider when $xy \gt 1$), suppose $z=\arctan(x)+\arctan(y) \in (-\pi,-\frac{\pi}{2}) \cup (\frac{\pi}{2},\pi)$. Although it is tempting to take the $\arctan$ of both sides in $(\dagger_1)$, we must remember that $\arctan$ is only the inverse function of $\tan$ restricted to $(-\frac{\pi}{2},\frac{\pi}{2})$. It is therefore invalid to claim that $\arctan\circ \tan(z)=z$. However, what IS valid is to employ the fact that $\tan$ is periodic as identified in $(\dagger_2)$. Therefore, suppose $z \in (-\pi,-\frac{\pi}{2})$, which corresponds to $x \lt 0$ and $y \lt 0$. We know that $\tan(z)=\tan(z+\pi)$, where $z+\pi \in (0,\frac{\pi}{2})$. Returning to $(\dagger_1)$, let us then write:
$$\tan(z+\pi)=\tan(z)=\frac{x+y}{1-xy}$$
We can then apply $\arctan$ to $\tan(z+\pi)$ which yields:
$$z+\pi=\arctan\left(\frac{x+y}{1-xy}\right) \implies \arctan(x)+\arctan(y)=\arctan\left(\frac{x+y}{1-xy}\right)-\pi$$
If $z \in (\frac{\pi}{2},\pi)$, which corresponds to $x \gt 0$ and $y \gt 0$ , a similar result applied to $z-\pi$ will yield:
$$z-\pi=\arctan\left(\frac{x+y}{1-xy}\right) \implies \arctan(x)+\arctan(y)=\arctan\left(\frac{x+y}{1-xy}\right)+\pi$$
With this we can completely fill in our piecewise function as follows:
$\arctan(x)+\arctan(y)=\begin{cases}-\frac{\pi}{2} \quad &\text{if $xy=1$, $x\lt 0$, and $y \lt 0$} \\\frac{\pi}{2} \quad &\text{if $xy=1$, $x\gt 0$, and $y \gt 0$} \\ \arctan\left(\frac{x+y}{1-xy}\right) \quad &\text{if $xy \lt 1$} \\\arctan\left(\frac{x+y}{1-xy}\right)+\pi \quad &\text{if $xy \gt 1$ and $x \gt 0$, $y \gt 0$}\\ \arctan\left(\frac{x+y}{1-xy}\right)-\pi \quad &\text{if $xy \gt 1$ and $x \lt 0$, $y \lt 0$} \end{cases}$
