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$.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityfound 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]]
Mod[]
: Sum[Boole[Mod[x, 1] != 0], {x, 1, Infinity}]
$\endgroup$
May 2, 2020 at 17:28
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
!IntegerQ[x]
gets evaluated right away to True, this is before the sum takes hold. Hence the result becomesBoole[True]
which is1
and the whole sum becomes justSum[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$Sum[Boole[Not[IntegerQ[x]]], {x, 1, k}]
which givesk
. So letk
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$