11
$\begingroup$

Bug introduced in 12.1, persisting through 13.2 or later


In one of my program run on Wolfram Cloud I run the command:

 Sum[(-1)^(Floor[k/2])/(k+1),{k,0,Infinity}]

and got the response

  Sum: Sum does not converge

This is very strange because the series obviously converges to $\frac\pi4+\frac{\log2}2$.

I have checked that the terms are correct running:

  Table[(-1)^(Floor[k/2])/(k+1),{k,0,20}]

What is the reason for the problem? I run the same code several years ago without any issue.

UPDATE: As pointed out by Roman the reason of the problem is most probably the usage of the Floor function. What is wrong with this?

$\endgroup$
19
  • 3
    $\begingroup$ Sum[(-1)^(Floor[k/2])/(k + 1), {k, 0, Infinity}, Regularization -> "Abel"] $\endgroup$
    – Syed
    Dec 1, 2023 at 12:35
  • $\begingroup$ I think because it is oscillating, it does not converge. Here is illustration: data = Table[{k, (-1)^(Floor[k/2])/(k + 1)}, {k, 0, 300}]; data = Table[{data[[k, 1]], Total[data[[1 ;; k]][[All, 2]]]}, {k, 1, Length@data}]; p = ListLinePlot[data]; Show[p, Plot[Pi/4 + Log[2]/2, {x, 0, Length[data]}, PlotStyle -> Red], PlotRange -> All] screen shot !Mathematica graphics so on average it does converge, but because it never settles due to +-, it is considered not to converge? $\endgroup$
    – Nasser
    Dec 1, 2023 at 12:37
  • $\begingroup$ @Nasser The Sum[(-1)^k/(k + 1), {k, 0, Infinity} is computed fast and correct. $\endgroup$
    – drer
    Dec 1, 2023 at 12:42
  • 3
    $\begingroup$ Reported as a bug. This appears to have regressed beginning with version 12.1. $\endgroup$ Dec 1, 2023 at 23:05
  • 2
    $\begingroup$ To clarify (or confound) nomenclature, a power series is an infinite sum. The result from Mathematica's `Series function is not. $\endgroup$ Dec 1, 2023 at 23:07

5 Answers 5

8
$\begingroup$

I suggested this to another answer and is a nifty little trick in many/enough/whateverwordworksbestforeachoneofus situations.

Do the sum to a point and take the limit that it goes to infinity in the following manner:

Limit[Sum[(-1)^(Floor[k/2])/(k + 1), {k, 0, xx}], {xx -> Infinity}]

to get

1/4 (π + Log[4])

P.S: taking the comments of a particular user into consideration, even though perhaps I should not, I am acknowledging that there is another answer similar to this one written by @user64494 and prior to mine that I had not seen.

As I explained in the comments I had not checked the submitted answer.

This can be understood since a week ago I suggested this approach to another question.

P.S 2: even with the previous phrasing it was clear how the answers were written, but some people are too uptight about minor things.

P.S 3: let's see if the other person will decide to appropriately cite, something that I highly doubt

$\endgroup$
15
  • 1
    $\begingroup$ This is a very interesting observation. I assumed however that this should be a normal way for Mathematica to treat the sums with Infinity as a summation limit. $\endgroup$
    – drer
    Dec 1, 2023 at 15:07
  • $\begingroup$ @drer I am not familiar with the inner workings of Sum. sorry $\endgroup$
    – bmf
    Dec 2, 2023 at 3:21
  • 1
    $\begingroup$ This is by definition of series how it should work. @DanielLichtblau has identified the problem as a bug. $\endgroup$
    – drer
    Dec 2, 2023 at 9:07
  • $\begingroup$ @ВалерийЗаподовников without the use of @ it's difficult to understand to whom you are referring. Also, you wrote why would you use DiscreteLimit and then say DiscreteLimit must be used so it's, also, difficult to understand what you meant to say to begin with. $\endgroup$
    – bmf
    Dec 4, 2023 at 7:09
  • 1
    $\begingroup$ @ВалерийЗаподовников Ok, in this case the Limit gives the finite result, so that DiscreteLimit does not bring any new information for answering my question. $\endgroup$
    – drer
    Dec 8, 2023 at 20:00
7
$\begingroup$

The explicit sum (without Floor magic) works fine:

Sum[1/(4 k + 1) + 1/(4 k + 2) - 1/(4 k + 3) - 1/(4 k + 4), {k, 0, ∞}]
(*    1/4 (π + Log[4])    *)
$\endgroup$
1
  • $\begingroup$ Comments have been moved to chat; please do not continue the discussion here. $\endgroup$
    – Kuba
    Dec 3, 2023 at 19:52
6
$\begingroup$
InverseZTransform[ZTransform[(-1)^(Floor[k/2]), k, z], z, k] // FullSimplify

$\cos \left(\frac{k \pi }{2}\right)+\sin \left(\frac{k \pi }{2}\right)$

Sum[(Cos[k π/2] + Sin[k π/2])/(k + 1), {k, 0, Infinity}] // FullSimplify

$\frac{1}{4} (\pi +\log (4))$

$\endgroup$
0
5
$\begingroup$

There is a workaround in 13.3.1 on Windows 10. We find a partial sum

Sum[(-1)^(Floor[k/2])/(k + 1), {k, 0, n}, Assumptions -> n \[Element] PositiveIntegers]

1/4 (\[Pi] + Log[4] - (-1)^Floor[(1 + n)/2] PolyGamma[0, 1 + n/4] + (-1)^ Floor[(1 + n)/2] PolyGamma[0, (2 + n)/4] - (-1)^ Floor[n/2] PolyGamma[0, (3 + n)/4] + (-1)^ Floor[n/2] PolyGamma[0, (5 + n)/4])

and then its limit as $n\to\infty$

DiscreteLimit[%, n -> Infinity]

1/4 (\[Pi] + Log[4])

The latest execution takes on my comp approximately 100s.

$\endgroup$
1
  • $\begingroup$ The key part here, BTW, is the use of DiscreteLimit, as that is the limit of the sequence which is different from the limit of the function. $\endgroup$ Dec 4, 2023 at 5:39
3
$\begingroup$

Break the sum into its parts, e.g.,

Sum[(-1)^(Floor[k/2])/(k + 1), {k, 0, Infinity, 2}] +
 Sum[(-1)^(Floor[k/2])/(k + 1), {k, 1, Infinity, 2}]

(* π/4 + Log[2]/2 *)
$\endgroup$
14
  • $\begingroup$ The series does not absolutely converge. Therefore, such a split is not grounded (see Wiki). $\endgroup$
    – user64494
    Dec 1, 2023 at 17:52
  • $\begingroup$ BTW, Sum[(-1)^(Floor[k/2])/(k + 1), {k, 0, Infinity, 3}] + Sum[(-1)^(Floor[k/2])/(k + 1), {k, 1, Infinity, 3}] + Sum[(-1)^(Floor[k/2])/(k + 1), {k, 2, Infinity, 3}] outputs "Sum::div: Sum does not converge". $\endgroup$
    – user64494
    Dec 1, 2023 at 18:00
  • $\begingroup$ Yes, this would need justification. One way to reason is that it is a difference of two absolutely convergent subsequences obtained by a very minor change to the grouping by @Roman. $\endgroup$ Dec 2, 2023 at 0:30
  • $\begingroup$ @DanielLichblau: Can you ground your empty words by theorems? $\endgroup$
    – user64494
    Dec 2, 2023 at 16:06
  • 3
    $\begingroup$ @user64494 Theorem: the sum of two convergent series is convergent. Theorem: if a(k) is alternating and their absolute values converges monotonically to 0, the series with terms a(k) converges. Combine these two. $\endgroup$
    – mickep
    Dec 3, 2023 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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