9
$\begingroup$

Bug introduced in 12.0 or earlier, persisting through 13.2 or later


Mathematica correctly identifies this sum as $\cos(x)$:

Sum[((-1)^n x^(2 n))/(2 n)!, {n, 0, Infinity}]

Mathematica also correctly identifies this product of sums as $\cos^2(x)$:

Sum[((-1)^i x^(2 i))/(2 i)!, {i, 0, Infinity}] Sum[((-1)^j x^(
   2 j))/(2 j)!, {j, 0, Infinity}]

However, when rearranged as this, Mathematica suddenly fails by finding $\cos^2(x) - \frac{1}{2}$ instead of $\cos^2(x)$:

Sum[((-1)^i x^(2 i))/(2 i)!*((-1)^j x^(2 j))/(2 j)!, {i, 0, 
  Infinity}, {j, 0, Infinity}]

It is interesting to note that it finds this sum to be the same as the above product for any finite number of terms, and only fails in the limit.

Is there a good reason for this happening?

$\endgroup$
11
  • 1
    $\begingroup$ What is even more interesting is that if you define: test[order_] := Factor[Sum[((-1)^i x^(2 i))/(2 i)!, {i, 0, order}] Sum[((-1)^j x^(2 j))/(2 j)!, {j, 0, order}] - Sum[((-1)^i x^(2 i))/(2 i)! ((-1)^j x^(2 j))/(2 j)!, {i, 0, order}, {j, 0, order}]] and then you do Limit[test[order], order -> Infinity] or Series[test[order], {order, Infinity, 2}] // Normal // Factor // TrigReduce you get a 0 as expected. But test[Infinity] // TrigReduce yields 1/2. $\endgroup$
    – bmf
    Nov 24, 2023 at 3:13
  • $\begingroup$ Sum[Sum[((-1)^i x^(2 i))/Factorial[2 i] ((-1)^j x^(2 j))/ Factorial[2 j], {i, 0, Infinity}], {j, 0, Infinity}] also works. $\endgroup$ Nov 24, 2023 at 9:27
  • $\begingroup$ Also, starting the sums from 1 rather than 0 correctly gives (Cos[x]-1)^2. $\endgroup$ Nov 24, 2023 at 9:32
  • 3
    $\begingroup$ The option Method -> "IteratedSummation" fixes it. As for the original, if the answer is wrong, how is that not a bug? Report to WRI. $\endgroup$
    – Goofy
    Nov 24, 2023 at 20:58
  • 1
    $\begingroup$ @bmf Yes, please add them. (Tagging I can manage on a good day, but I actually don't know how to add that as a header.) $\endgroup$ Nov 28, 2023 at 15:47

2 Answers 2

6
$\begingroup$

Expanding on the comment by @Goofy and after reading the docs we see that:

  1. "ParallelFirstToSucceed" try each method in parallel until one succeeds

  2. "ParallelBestQuality" try each method in parallel and return the best result

  3. "IteratedSummation" use iterated univariate summation

So, if we do

Sum[((-1)^i x^(2 i))/(2 i)!*((-1)^j x^(2 j))/(2 j)!, {i, 0, 
  Infinity}, {j, 0, Infinity}, Method -> "ParallelFirstToSucceed"]

or

Sum[((-1)^i x^(2 i))/(2 i)!*((-1)^j x^(2 j))/(2 j)!, {i, 0, 
  Infinity}, {j, 0, Infinity}, Method -> "ParallelBestQuality"]

or

Sum[((-1)^i x^(2 i))/(2 i)!*((-1)^j x^(2 j))/(2 j)!, {i, 0, 
  Infinity}, {j, 0, Infinity}, Method -> "IteratedSummation"]

And if we don't want to use any Method in the Sum

Limit[Sum[((-1)^i x^(2 i))/(2 i)!*((-1)^j x^(2 j))/(2 j)!, {i, xx, 
   Infinity}, {j, xx, Infinity}], {xx -> 0}]

or

Normal@Series[
  Sum[((-1)^i x^(2 i))/(2 i)!*((-1)^j x^(2 j))/(2 j)!, {i, xx, 
    Infinity}, {j, xx, Infinity}], {xx, 0, 0}]

all yield

Cos[x]^2

$\endgroup$
3
  • $\begingroup$ What does "best" mean in this context? Also, if all three of these options work, what is the failing default? $\endgroup$ Nov 26, 2023 at 2:59
  • $\begingroup$ @SamuelMartineau I am not sure what best means. I am pretty confident, though, that this should answer the latter question you posed; namely what is the failing condition. $\endgroup$
    – bmf
    Nov 26, 2023 at 12:20
  • $\begingroup$ The thing I find peculiar is that both "FirstToSucceed" and "BestQuality" work when ran in parallel… $\endgroup$ Nov 27, 2023 at 14:08
2
$\begingroup$

Vs 6 gets the correct result, but Wolfram $\alpha$ decides, too, that $$\sum_{m,n=0}^\infty \frac{ (-1)^{n+m} x^{2m+2n} }{(2n)!(2m)!} \quad \ne \quad \sum_{m=0}^\infty\left(\sum_{n=0}^\infty \frac{ (-1)^{n+m} x^{2m+2n} }{(2n)!(2m)!}\right) $$

Inspection of the double sum shows weight 1/2 only at $(n,m)=(0,0)$, but only for upper limits $m,n=\infty$

      Sum[((-1)^(m + n) x^(2 m) x^(2 n))/((2 n)! (2 m)!), 
          {n, 0, \[Infinity]}, {m, 0, \[Infinity]}] // TrigReduce 

$$\frac{1}{2} \cos (2 x)$$

      Sum[Sum[((-1)^(m+n) x^(2m) x^(2n))/((2n)!(2m)!),
               {n,0,\[Infinity]}], {m,0,\[Infinity]}]//TrigReduce

$$\frac{1}{2} (\cos (2 x)+1)$$

Today all infinite sums with 2-term recursions are expressed as hypergeometric series, a bit dangerous an attempt because of their complex definitions with cuts on the real line:

 ds= Assuming[0 < x < \[Pi]/2, 
     Sum[((-1)^(m + n) x^(2 m) x^(2 n))/((2 n)! (2 m)!), 
      {n, 2, \[Infinity]}, {m, 2, \[Infinity]}] // TrigReduce]

$$\begin{align}&\frac{113 x^{10} \, _3F_4\left(2,2,\frac{9}{2};1,\frac{11}{2},\frac{11}{2},6;-\frac{x^2}{4}\right)}{5443200}+\frac{x^{10} \, _4F_5\left(2,2,2,\frac{9}{2};1,1,\frac{11}{2},\frac{11}{2},6;-\frac{x^2}{4}\right)}{272160}\\&+\frac{x^{10} \, _5F_6\left(2,2,2,2,\frac{9}{2};1,1,1,\frac{11}{2},\frac{11}{2},6;-\frac{x^2}{4}\right)}{4082400}-\frac{8 x^{10} \, _3F_4\left(2,2,\frac{9}{2};1,\frac{11}{2},\frac{11}{2},6;-x^2\right)}{127575}\\&-\frac{x^{10} \, _4F_5\left(2,2,2,5;1,1,\frac{11}{2},6,6;-\frac{x^2}{4}\right)}{302400}-\frac{x^{10} \, _5F_6\left(2,2,2,2,5;1,1,1,\frac{11}{2},6,6;-\frac{x^2}{4}\right)}{4536000}\\&-\frac{57}{5} x^6 \, _1F_2\left(\frac{5}{2};\frac{7}{2},\frac{7}{2};-\frac{x^2}{4}\right)+\frac{32}{5} x^6 \, _1F_2\left(\frac{5}{2};\frac{7}{2},\frac{7}{2};-x^2\right)\\&-\frac{1796}{9} x^4 \, _1F_2\left(\frac{3}{2};\frac{5}{2},\frac{5}{2};-\frac{x^2}{4}\right)+\frac{32}{9} x^4 \, _1F_2\left(\frac{3}{2};\frac{5}{2},\frac{5}{2};-x^2\right)+5632 \text{Ci}(x)+\frac{797 x^6}{5400}-\\&\frac{131 x^4}{4}+2366 x^2+\frac{1711}{2} x^2 \cos (x)-30 x^2 \cos (2 x)-\\& -5632 \log (x)-\frac{10771}{2} x \sin (x)+65 x \sin (2 x) \end{align}$$

The nested sum is

   ns=Assuming[0 < x < \[Pi]/2, 
      Sum[Sum[((-1)^(m + n) x^(2 m) x^(2 n))/((2 n)! (2 m)!), 
             {n,  2, \[Infinity]}], 
        {m, 2, \[Infinity]}] // TrigReduce]

$$\frac{1}{4} \left(x^4\ - \ 4 x^2\ + \ 4 x^2 \ \cos (x)-8 \cos (x)\ + \ 2 \cos (2 x)+6\right)$$

On this level the lowest terms are equal

 Series[ds-ns,{x,0,2}]

  O[x^3]

and a plot shows identity, but an equality test seems to be to complex for the current versions, aborted after some minutes.

Only the case of lower bound 0 is showing a difference in the constant term.

$\endgroup$
2

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .