# Refine gives strange results

I have

pr[x_] := PDF[PoissonDistribution[2], x]


and

Overage[x_] := Sum[(d - x)*pr[d], {d, x, Infinity}]


I would like to have Mathematica try simplify this. If not possible, it should at least keep it the same. However,

Refine[Overage[z], Assumptions -> z >= 0 && z \[Element] Integers]


yields errors "Power::infy: Infinite expression 1/0 encountered." and "Infinity::indet: Indeterminate expression (0 ComplexInfinity)/E^2 encountered.".

This is because it uses the gamma function at some point. I can even pinpoint the issue to z==0.

However, for z==0, the expression is just Overage[0] which is well-defined.

What am I doing wrong here?

• @BobHanlon Even if d does not start at 0? Jun 28 '18 at 13:58
• You can manually subtract the finite part, Expectation[...] - Sum[..., {d, 0, x}]. Jun 28 '18 at 14:03

You can get rid of the warnings by using the following:

pr[x_] := Exp[-2] 2^x/x!
Overage[x_] := Sum[(d - x)*pr[d], {d, x, Infinity}]
f[z_] := Refine[Overage[z],
Assumptions -> z >= 0 && z \[Element] Integers]
f[z]


$$\frac{2^z \left(e^2 \left(-2^{-z}\right) z+e^2 2^{1-z}+\frac{2}{\Gamma (z+1)}+\frac{e^2 2^{-z} \Gamma (z+1,2)}{\Gamma (z)}-\frac{e^2 2^{1-z} \Gamma (z+1,2)}{\Gamma (z+1)}\right)}{e^2}$$

But if you can ignore the warnings and define

f[z_] := Refine[Overage[z], Assumptions -> z >= 0 && z \[Element] Integers]


then the function works as expected/desired

f[z]


$$\begin{array}{cc} \{ & \begin{array}{cc} -\frac{-2^{z+1} \Gamma (z)-2 e^2 \Gamma (z+1) \Gamma (z)+e^2 z \Gamma (z+1) \Gamma (z)+2 e^2 \Gamma (z) \Gamma (z+1,2)-e^2 \Gamma (z+1) \Gamma (z+1,2)}{e^2 \Gamma (z) \Gamma (z+1)} & z>0 \\ \text{Indeterminate} & \text{True} \\ \end{array} \\ \end{array}$$

f[0]
(* 2 *)

f[3]


$$\frac{9-e^2}{e^2}$$

• Thank you! Can I somehow eliminate the Gamma functions? If z is integer, I do not need it, I would suppose. But even without Gamma or !, the whole expression seems unnecessary complicated Jun 28 '18 at 14:08
• Simplicity is in the eye of the beholder. You could replace the Gamma[z] values with (z-1)! using f[z_] := Refine[Overage[z], Assumptions -> z >= 0 && z \[Element] Integers] /. Gamma[x_] -> (x - 1)!. There's not much of any simplification for the incomplete gamma: Gamma[z+1,2].
– JimB
Jun 28 '18 at 14:36
• I would prefer, though, to have my original pr function used instead of the clumsy long form Jun 28 '18 at 14:42
• Then keep the original pr function. As stated above all you have to do is ignore the warnings. The original function performs fine. It just gives some warnings. You can suppress the warnings by using the Quiet function. (Exp[-2] 2^x/x! is a "clumsy long form" compared to PDF[PoissonDistribution[2], x] ?? I agree that using PDF is more natural and the desired function to use.
– JimB
Jun 28 '18 at 15:07
• yes, PDF is easier to read, but also using my first pr function yields quite a messy expression because PoissonDistribution will be evaluated immediately Jun 28 '18 at 16:04