# Why does Mathematica not recognize a convergent series?

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?

• Sum[(-1)^(Floor[k/2])/(k + 1), {k, 0, Infinity}, Regularization -> "Abel"]
– Syed
Dec 1, 2023 at 12:35
• 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? Dec 1, 2023 at 12:37
• @Nasser The Sum[(-1)^k/(k + 1), {k, 0, Infinity} is computed fast and correct.
– drer
Dec 1, 2023 at 12:42
• Reported as a bug. This appears to have regressed beginning with version 12.1. Dec 1, 2023 at 23:05
• To clarify (or confound) nomenclature, a power series is an infinite sum. The result from Mathematica's Series function is not. Dec 1, 2023 at 23:07

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.

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

• 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.
– drer
Dec 1, 2023 at 15:07
• @drer I am not familiar with the inner workings of Sum. sorry
– bmf
Dec 2, 2023 at 3:21
• This is by definition of series how it should work. @DanielLichtblau has identified the problem as a bug.
– drer
Dec 2, 2023 at 9:07
• @ВалерийЗаподовников 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.
– bmf
Dec 4, 2023 at 7:09
• @ВалерийЗаподовников Ok, in this case the Limit gives the finite result, so that DiscreteLimit does not bring any new information for answering my question.
– drer
Dec 8, 2023 at 20:00

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])    *)

• Comments have been moved to chat; please do not continue the discussion here.
– Kuba
Dec 3, 2023 at 19:52
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))$$

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.

• 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. Dec 4, 2023 at 5:39

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

• The series does not absolutely converge. Therefore, such a split is not grounded (see Wiki). Dec 1, 2023 at 17:52
• 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". Dec 1, 2023 at 18:00
• 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. Dec 2, 2023 at 0:30
• @DanielLichblau: Can you ground your empty words by theorems? Dec 2, 2023 at 16:06
• @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. Dec 3, 2023 at 19:04