2
$\begingroup$

Why does Mathematica return:

Sum::div: Sum does not converge. >>

when I input:

Sum[Boole[!IntegerQ[x]], {x, 1, Infinity}]

The sum is obviously $0$.

$\endgroup$
9
  • 7
    $\begingroup$ What seems to happen is that !IntegerQ[x] gets evaluated right away to True, this is before the sum takes hold. Hence the result becomes Boole[True] which is 1 and the whole sum becomes just Sum[1, {x, 1, Infinity}] which diverges. You can see this more clearly like this: !Mathematica graphics need to find a way to tell M to delay this evaluation. $\endgroup$
    – Nasser
    Apr 13, 2014 at 14:07
  • 1
    $\begingroup$ what do you get for a finite sum? $\endgroup$
    – george2079
    Apr 13, 2014 at 14:11
  • $\begingroup$ The sum is 0 for any arbitrarily large finite value, but the infinite sum doesn't converge. I'm not sure why it evaluates it to true if I'm summing over natural numbers. $\endgroup$
    – user85798
    Apr 13, 2014 at 14:12
  • $\begingroup$ You can also see this more clearly like this Sum[Boole[Not[IntegerQ[x]]], {x, 1, k}] which gives k. So let k to any value, say Infinity, and you see the problem. It is all due to evaluation of !IntegerQ[x] before the sum even starts. Since you are summing to Infinity, I am not sure how else M will handle this, as the function needs to be analytical for M to figure the sum. $\endgroup$
    – Nasser
    Apr 13, 2014 at 14:24
  • $\begingroup$ So how do I make Mathematica evaluate the sum correctly? $\endgroup$
    – user85798
    Apr 13, 2014 at 14:31

2 Answers 2

2
$\begingroup$

found something that works:

 Sum[Boole[! (IntegerPart[x] == x)], {x, 1, Infinity}]

0

This other thing I suggested does not work:

 intq[x_?NumericQ] := IntegerQ[x];
 Sum[Boole[! intq[x]], {x, 1, Infinity}]

(* remains unevaluated *)

It could be Sum is smart enough to first simplify assuming integers:

 Simplify[ Boole[(! IntegerPart[x] == x)] , Element[x, Integers]]
 Simplify[ Boole[! intq[x]] , Element[x, Integers]]

0

Boole[! intq[x]]

$\endgroup$
1
  • $\begingroup$ One could also use a representation using Mod[]: Sum[Boole[Mod[x, 1] != 0], {x, 1, Infinity}] $\endgroup$ May 2, 2020 at 17:28
7
$\begingroup$

Before x is a assigned a value its Head is Symbol. Thus IntegerQ[x] yields False.

That means Boole[!IntegerQ[x]] will be simplified to 1 and the sum will not converge. This can be seen with Trace.

Any integer value as upper bound of the sum will however yield 0 as expected.

Sum[Boole[! IntegerQ[x]], {x, 1, 100}]

Out:

0

As far as I understand the behaviour of Sum in thise case it will evalute the exrpession symbolicaly in case of an infinite sum and numericaly in case of a finite sum.

edit: sorry didn't notice the comments

$\endgroup$

Your Answer

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

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