Why is $f'(x)= 0$ but $f$ is not a constant function? Let $f(x) := \arctan(x) + \arctan(1/x)$. Then 
\begin{align*}
f'(x) &= \frac{1}{x^2+1} + \frac{1}{(\frac{1}{x})^2 + 1}\cdot \frac{-1}{x^2} \\
&= \frac{1}{x^2 + 1} + \frac{-1}{x^2 + 1} \\
&= 0
\end{align*}
which should mean that $f$ is a constant function. However, this is false. If $x>0$, $f(x) = \pi/2$, and if $x<0$, $f(x) = -\pi/2$. This apparent contradiction probably has to do with the fact that $f$ is not defined at $x=0$. But where exactly does the reasoning break down?
I saw this in this question (comment thread a while down, searching arctan should find it).
 A: It is not true that $f'(x)=0$ implies $f$ is constant for functions $f$ with an arbitrary domain.  This implication is only valid when the domain is an interval.  Since the domain of your function is $(-\infty,0)\cup(0,\infty)$, you can conclude that $f$ is constant on each of those intervals, but not necessarily that it is constant on their union (i.e., that it takes the same constant value on each of them).
Indeed, more generally, given any constants $c$ and $d$, you could define a function $g(x)$ on $(-\infty,0)\cup(0,\infty)$ by $g(x)=c$ if $x<0$ and $g(x)=d$ if $x>0$.  Then $g'(x)=0$ for all $x$ in the domain of $g$, but $g$ is not constant (unless $c=d$).
A: The function can be rewritten as
$$f(x) = \begin{cases} \pi/2 & \text{ if }x > 0\\ -\pi/2 & \text{ if }x < 0\end{cases}$$
The derivative is defined only for $x \neq 0$. At $x=0$, the function is not even continuous, since $\lim_{x \to 0^+}f(x) = \pi/2$ and $\lim_{x \to 0^-} f(x) = -\pi/2$. Hence, in fact, we have that
$$f'(x) = 0 \text{ only when }x \neq 0$$
A: Ніnt:
$$ \arctan(x) + \arctan(1/x)={\rm sign}(x) \frac{\pi}{2}, x \neq 0.$$
