Given a random variable \(Y\), sometimes we want to compute the expectation of \(Y[Y\le a]\), where \([P]=1\) if the \(P\) and true and \([P]=0\) if \(P\) is false. (The notation is called Iverson Bracket.)
In Patrice, it can be convenient to write \(\mathbb E(Y[Y \le a])\) in terms of the left and right tails of \(Y\). With just a bit calculus, it is not difficult to see that if \(Y \ge 0\) and \(p \ge 1\),
\begin{align}
\mathbb E(Y^p[Y \le a])
&
=
a^p \mathbb P(Y \le a)-\int_0^ap y^{p-1} \mathbb P(Y \le y) \, dy
\\\\
&
=
\int_0^ap y^{p-1} P(Y>a) \, dy-a^p \mathbb P(Y>a)
\end{align}
Similarly
\begin{align}
\mathbb E(e^{-Y}[Y \le a])
&
=
\int_0^ae^{-y} \mathbb P(Y \le a) \mathbb \, d y+e^{-a} \mathbb P(Y \le a)
\\\\
&
=
1-\int_0^a e^{-y} P(Y > a) \, dy-e^{-a} P(Y > a)
\end{align}
I recently put these two qualities in a Mathematica package CalcMoment.m
. You can find it here.
You can load it and try it a Mathematica notebook like this
SetDirectory[NotebookDirectory[]];
Get["CalcMoment`"]
gdist = GammaDistribution[3, 7]
gtest = TruncatedMoment[gdist, p, a] == TruncatedMoment[gdist, p, a, MomentForm -> "Left"] == TruncatedMoment[gdist, p, a, MomentForm -> "Right"]
Assuming[0 < a && p >= 1, gtest // Activate // FullSimplify]
edist = ExponentialDistribution[1]
etest = TruncatedExpMoment[edist, a] == TruncatedExpMoment[edist, a, MomentForm -> "Left"] == TruncatedExpMoment[edist, a, MomentForm -> "Right"]
Assuming[0 < a, etest // Activate // FullSimplify]
The output is of course True
.