1
$\begingroup$

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:

https://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?

$\endgroup$
3
  • 1
    $\begingroup$ 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. $\endgroup$ – george2079 Dec 8 '14 at 16:02
  • $\begingroup$ ???? Sum[x/x!, {x, 2, Infinity, 2}] has always been part of the question. Maybe you missed it? $\endgroup$ – wolfies Dec 9 '14 at 1:05
  • $\begingroup$ doh! must work on reading comprehension $\endgroup$ – george2079 Dec 9 '14 at 12:33
4
$\begingroup$

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]
$\endgroup$
3
  • $\begingroup$ "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? $\endgroup$ – Szabolcs Dec 8 '14 at 20:44
  • $\begingroup$ 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. $\endgroup$ – Chip Hurst Dec 9 '14 at 4:55
  • $\begingroup$ @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. $\endgroup$ – Chip Hurst Dec 9 '14 at 5:02
2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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