Suppose I am interested in a sum across a set of even numbers, such as:

Sum[x, {x, 2, 20, 2}]

110

or

Sum[ x Boole[EvenQ[x]], {x, 1, 20}]

110

So far, so good.

HOWEVER, if I extend this to an infinite set, the first method works:

Sum[ (x/x!), {x, 2, Infinity, 2}]

Sinh[1]

… but the Boole method returns 0:

Sum[ (x/x!) Boole[EvenQ[x]], {x, 1, Infinity}]

0

My interest in this comes from a question on the mathSE site:

http://math.stackexchange.com/questions/1055438/what-is-the-probability-that-a-poisson-random-variable-is-prime

where someone asks how to calculate the probability of a Poisson random variable being prime, and I was actually trying the same type of problem with PrimeQ … and also getting 0. I wasn’t expecting mma to get an answer … but 0 is wrong. Any ideas?

=================

1

You probably know this but in this case you can readily handle it manually: Sum[x/x!, {x, 2, Infinity, 2}]. Search this site and you’ll find a few examples of more complicated cases that cant readily be treated like that and unfortunately there is no general solution.

– george2079

Dec 8 ’14 at 16:02

???? Sum[x/x!, {x, 2, Infinity, 2}] has always been part of the question. Maybe you missed it?

– wolfies

Dec 9 ’14 at 1:05

doh! must work on reading comprehension

– george2079

Dec 9 ’14 at 12:33

=================

2 Answers

2

=================

With infinite sums, the summand is evaluated. Since Q functions always return True or False, EvenQ[x] evaluates to False since x is not an even integer.

You can use Mod instead and everything works fine for your examples.

Sum[x/x! Boole[Mod[x,2] == 0], {x, 1, Infinity}] // FullSimplify

Sinh[1]

“Since Q functions always return True or False” –> I never realized this. Is there no exception? Is that the reason why Positive is not called PositiveQ?

– Szabolcs

Dec 8 ’14 at 20:44

Yes, that’s why there’s no Q at the end of Positive. The only (technical) exceptions I know of are EllipticNomeQ and InverseEllipticNomeQ. These are numerical functions that are denoted with a capital Q in literature.

– Chip Hurst

Dec 9 ’14 at 4:55

@Szabolcs, looking at Names[“System`*Q”] it appears the functions HypergeometricPFQ, MarcumQ, and QHypergeometricPFQ fall under the same category as EllipticNomeQ. But the answer is yes, if a boolean function ends in Q then it always returns True or False.

– Chip Hurst

Dec 9 ’14 at 5:02

look at:

Sum[(x/x!) Boole[EvenQ[x]], {x, 1, Infinity}] // Trace

the function Sum (in the case of infinity Sum) try to organize its argument which result in some evaluation.

in this case,

Boole[EvenQ[x]] evaluated to 0 because EvenQ[x] evaluated to False.