Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
6  
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. –  Nasser Apr 13 at 14:07
1  
what do you get for a finite sum? –  george2079 Apr 13 at 14:11
    
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. –  LTS Apr 13 at 14:12
    
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. –  Nasser Apr 13 at 14:24
    
So how do I make Mathematica evaluate the sum correctly? –  LTS Apr 13 at 14:31

2 Answers 2

up vote 1 down vote accepted

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

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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