# Infinite expression encountered when simplifying ArcTan sums although the result is finite

If I attempt to simplify the sum ArcTan[1/x] + ArcTan[x] with

ArcTan[ Simplify[ TrigExpand[ Tan[ ArcTan[1/x] + ArcTan[x]]]]]

Mathematica returns

During evaluation of In[103]:= Power::infy: Infinite expression 1/0 encountered. >>

During evaluation of In[103]:= Power::infy: Infinite expression 1/0 encountered. >>

During evaluation of In[103]:= Infinity::indet: Indeterminate expression
ComplexInfinity + ComplexInfinity encountered. >>

Indeterminate

even though the result is $\pm\pi/2$. The error messages occur during the call to TrigExpand, and I can't think of a way to avoid them. Also, I tried in vain the assumption x > 0, so that the result is not ambiguous.

The full expression to simplify is

(1/(16 a))Q^2 (-16 ArcTan[r1/a] + 1/(2 r1^2)(16 π r1^2 + 32 r1 a
+ π a^2 + 8 π r1^2 Log[r1] + 4 ArcTan[a/r1] (7 a^2 - 8 r1^2 Log[r1])
- 2 ArcTan[r1/(2 a) - a/(2 r1)] (a^2 + 8 r1^2 Log[r1])))

I know that the Logs vanish after simplification and I was trying to prove this with Mathematica. It is possible if I split the expression into several parts, then simplify with the transformation rule for the addition of ArcTan, because none of the other methods work in this case, but the transformation rule aborts when it meets an infinite expression.

-
For what it's worth, the value of $\tan^{-1}x+\tan^{-1}(1/x)$ is not simply $\pi/2$ but $\begin{cases}\pi/2&\text{if$x>0$}\\-\pi/2&\text{if$x<0$}\end{cases}$ – Rahul Jul 15 '14 at 22:47
In addition, you're plugging it into Tan, which yields 1/0 in both cases. – Michael E2 Jul 15 '14 at 22:50
@RahulNarain I tried the assumption x>0, still the same. – auxsvr Jul 15 '14 at 22:51

This is an example related to limitations of standard symbolic capabilities of Mathematica, there are many similar issues ( usually they come from arbitrary choices of branches of complex functions), see e.g. analogous problems Why does Integrate declare a convergent integral divergent? or Bug in mathematica analytic integration?.

Functions like Log and Tan are not defined in the whole complex plane (rather on Riemann surfaces) and therefore one should carefully choose appropriate branches when they are transformed symbolically (they involve branching points around singularities) e.g.

TrigToExp[ ArcTan[1/x] + ArcTan[x]]
1/2 I Log[1 - I/x] - 1/2 I Log[1 + I/x] + 1/2 I Log[1 - I x] - 1/2 I Log[1 + I x]

For the problem at hand it is a good idea to transform the original expression to its exponential equivalent and then we can use FullSimplify:

FullSimplify[ TrigToExp[ArcTan[1/x] + ArcTan[x]], x > 0]
π/2
FullSimplify[ TrigToExp[ArcTan[1/x] + ArcTan[x]], x < 0]
-π/2

Of course the original expression involves also Tan (Tan[Pi/2] yields ComplexInfinity) and this is why we encounter the warning

Tan[ ArcTan[1/x] + ArcTan[x]] // FullSimplify
FullSimplify::infd: Expression Tan[ArcTan[1/x] + ArcTan[x]]
simplified to Indeterminate. >>

Indeterminate
-
The infinite expression error persists even if I simplify this expression using the transformation in the answer here. I prefer that method, because it is more flexible and allows me to simplify, for example, the numerator of a fraction with ArcTan, on which Mathematica's facilities for simplification fail. Is there a way to prevent this error during a transformation? – auxsvr Jul 16 '14 at 17:48
@auxsvr You should update your question accordingly to your needs including a minimal example demonstrating the problematic issue. It is not clear what you really want since I've provided an appropriate answer to the question as it has been posed above. That warning appears because you want to evaluate Tan at π/2 but appropriately speaking it doesn't belong to its domain. Sometimes it yields Indeterminate, in another cases it yields ComplexInfinity, Mathematica so far is not infallible. – Artes Jul 16 '14 at 18:36
Indeed, you have provided the answer to the original question, but I didn't know then that Mathematica's simplification functions are so sensitively dependent on the form of the expression. Thanks for your answer. – auxsvr Jul 16 '14 at 19:00