Looking at the sum:


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?

  • 10
    $\begingroup$ Because machines can't represent irrational number such as $pi/2$. So you get some "large number" instead. $\endgroup$ – A.S. Mar 1 '16 at 11:32
  • 23
    $\begingroup$ It seems like a bug. You should report it. $\endgroup$ – Akiva Weinberger Mar 1 '16 at 11:33
  • 9
    $\begingroup$ @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. $\endgroup$ – Eric Towers Mar 1 '16 at 13:44
  • 3
    $\begingroup$ 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". $\endgroup$ – Daniel R. Collins Mar 1 '16 at 17:37
  • 5
    $\begingroup$ 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. $\endgroup$ – Jeppe Stig Nielsen Mar 1 '16 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.

  • 16
    $\begingroup$ It's funny and sad the same time that W|A represents real numbers in IEEE 754 format :-X $\endgroup$ – imanoob Mar 1 '16 at 12:43
  • 4
    $\begingroup$ 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$. $\endgroup$ – Daniel R. Collins Mar 1 '16 at 15:38
  • 9
    $\begingroup$ @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? $\endgroup$ – Paul Sinclair Mar 1 '16 at 16:22
  • 3
    $\begingroup$ 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. $\endgroup$ – Chris Chudzicki Mar 1 '16 at 16:37
  • 4
    $\begingroup$ @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. $\endgroup$ – leftaroundabout Mar 1 '16 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.

  • 4
    $\begingroup$ Nice party trick! $\endgroup$ – Stefan Mesken Mar 1 '16 at 12:04
  • 3
    $\begingroup$ 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. $\endgroup$ – Taemyr Mar 1 '16 at 12:33
  • 19
    $\begingroup$ What the devil is $\widetilde \infty$? $\endgroup$ – steven gregory Mar 1 '16 at 12:58
  • 44
    $\begingroup$ @Steven: Infiñity, of course. $\endgroup$ – Deusovi Mar 1 '16 at 13:57
  • 8
    $\begingroup$ @StevenGregory: That symbol "is complex infinity" (per fine print on the WA result), i.e.,point at infinity in the complex plane. $\endgroup$ – Daniel R. Collins Mar 1 '16 at 15:35



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).

  • $\begingroup$ I wonder how the internal calculation works... Is there any way we might be able to look at the relevant code segment? $\endgroup$ – Stefan Mesken Mar 1 '16 at 12:05
  • 3
    $\begingroup$ @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. $\endgroup$ – gerw Mar 1 '16 at 12:12
  • 3
    $\begingroup$ However computing tan(pi/2) with W|A gives infinity. wolframalpha.com/input/?i=tan(pi%2F2) $\endgroup$ – Taemyr Mar 1 '16 at 12:34
  • $\begingroup$ 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}$. $\endgroup$ – Henry Mar 2 '16 at 1:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.