# Why does Wolframalpha think that this sum converges?

Looking at the sum:

$$\sum_{n=1}^\infty\tan\left(\frac\pi{2^n}\right)$$

I'd say that it does not converge, because for $n=1$ the tangent $\tan\left(\frac\pi 2\right)$ should be undefined. But Wolframlpha thinks that the sum converges somewhere around $1.63312×10^{16}$.

What am I missing?

• Because machines can't represent irrational number such as $pi/2$. So you get some "large number" instead.
– A.S.
Mar 1, 2016 at 11:32
• It seems like a bug. You should report it. Mar 1, 2016 at 11:33
• @A.S. : WolframAlpha and Wolfram Mathematica represent the number $\pi/2$ exactly as precisely as you do, as "$\pi/2$". Many CASs represent irrationals symbolically. Mar 1, 2016 at 13:44
• Building on the answer below by @Martín-BlasPérezPinilla : Initially for me WA reports "By the comparison test, the series converges", and then about 5 seconds later this switches to saying "By the ratio test, the series converges". Mar 1, 2016 at 17:37
• It is a bit hard to say whether $\sum_{n=1}^\infty\tan\left(\frac\pi{2^n}\right)$ converges or diverges because clearly the terms tend to zero quickly enough, and the problem is that the first term is not even properly defined. Mar 1, 2016 at 18:53

For floating point numbers stored in IEEE double precision format, the significant has $53$ bit of accuracy. The most significant bit is implied and is always one. Only $52$ bits are actually stored.

Since $1 \le \frac{\pi}{2} < 2$, among those numbers representable by IEEE, the closest number to $\frac{\pi}{2}$ is $$\left(\frac{\pi}{2}\right)_{fp} \stackrel{def}{=} 2^{-52}\left\lfloor \frac{\pi}{2} \times 2^{52}\right\rfloor$$

Numerically, we have $$\frac{\pi}{2} - \left(\frac{\pi}{2}\right)_{fp} \approx 6.1232339957\times 10^{-17}$$

Since for $\theta \approx \frac{\pi}{2}$, $\displaystyle\;\tan\theta \approx \frac{1}{\frac{\pi}{2} - \theta}$, we have

$$\tan\left(\frac{\pi}{2}\right)_{fp} \approx \frac{1}{6.1232339957\times 10^{-17}} \approx 1.6331239353 \times 10^{16}$$

This is approximately the number you observed.

• It's funny and sad the same time that W|A represents real numbers in IEEE 754 format :-X Mar 1, 2016 at 12:43
• And to be clear, if this is the result of the first term, then it completely overwhelms the rest of the series, because from $n = 2$ to infinity the sum is only about $1.8$. Mar 1, 2016 at 15:38
• @imanoob - do you have an alternative idea for representing numbers in the finite limitations of a computer that allows for reasonable computations such as this? Mar 1, 2016 at 16:22
• Preface: I do not really understand how W|A and Mathematica deal with symbolic vs. floating point representations. .....That said, your answer does not seem to explain why $\tan{(\pi/2)}=ComplexInfinity$ but $\sum_{n=1}^{\infty} \tan \frac{\pi}{2^n}$ does not evaluate to ComplexInfinity. Mar 1, 2016 at 16:37
• @mrc: it would be fair to complain that WA should notice this in a finite sum. And indeed it does. Complaining that it should notice this in any infinite sum would be less fair, actually. Mar 1, 2016 at 19:49

Possible explication: Wolfram Alpha applies some convergence test and says "is convergent". But as does not know any closed form, does a numerical approximation.

EDIT: interesting phenomenon: https://www.wolframalpha.com/input/?i=sum_(n%3D1)%5E7000+tan(pi%2F2%5En). Try and wait a bit.

• Nice party trick! Mar 1, 2016 at 12:04
• You don't need to sum to 7000. wolframalpha.com/input/?i=sum_(n%3D1)%5E1+tan(pi%2F2%5En) shows that W|A "knows" it's infinite at 1. Mar 1, 2016 at 12:33
• What the devil is $\widetilde \infty$? Mar 1, 2016 at 12:58
• @Steven: Infiñity, of course. Mar 1, 2016 at 13:57
• @StevenGregory: That symbol "is complex infinity" (per fine print on the WA result), i.e.,point at infinity in the complex plane. Mar 1, 2016 at 15:35

Computing

tan(pi/2)

with Python or Matlab yields $1.633123935319537\mathrm{e}{+}16$. Hence, this is just a result of rounding errors (the remaining terms in the sum are quite small).

• I wonder how the internal calculation works... Is there any way we might be able to look at the relevant code segment? Mar 1, 2016 at 12:05
• @Stefan: This is more related to floating-point arithmetic than to the actual source code of Python/Matlab. pi/2 is just the floating-point number nearest to $\pi/2$ and tan(pi/2) is an approximation of its tangent. Since $\pi/2 \ne$pi/2, tan(pi/2) is quite large.
– gerw
Mar 1, 2016 at 12:12
• However computing tan(pi/2) with W|A gives infinity. wolframalpha.com/input/?i=tan(pi%2F2) Mar 1, 2016 at 12:34
• The sum of the first $6000$ terms https://www.wolframalpha.com/input/?i=sum_(n%3D1)%5E6000+tan(pi%2F2%5En) gives an infinite number but the sum of the first $7000$ does not even though the difference should only be be about $2 \times 10^{-1806}$. Mar 2, 2016 at 1:18