# Question:How to compute te expectation of an abstract random variable?

## Question:How to compute te expectation of an abstract random variable?

Maple 2015

Let E be a random variable of expectation mu and A an algebraic expression containing no random variable.
If E has any known Maple distribution, then  Mean(A+E) = A+mu.

But if E is an "abstract" random variable, Mean doesn't seem capable to compute the expectation of A+E.
Notional example:

```restart:
with(Statistics):
E := RandomVariable(Normal(mu, sigma)):
Mean(f(x)+E)
f(x) + mu
E := RandomVariable(Distribution(PDF = (z -> f(z)), Mean=mu)):
Mean(f(x)+E);
int((f(x) + _t) f(_t), _t = -infinity .. infinity)

IntegrationTools:-Expand(%);
f(x) (int(f(_t), _t = -infinity .. infinity)) + (int(f(_t) _t, _t = -infinity .. infinity))
```

Questions:

• Why does Mean not behave as expected for an abstract random variable?
• Is there a simple way to obtain the expected result (Mean (A+E) = A+mu) (maybe by completing the definition of the distribution of E, or by any other means)?

TIA

PS: I know that I can replace Mean(A+E)  by A+Mean(E)  to obtain the desired result: this is not the type of answer I look for.

PS: I know (since Carl Love showed me how long ago) that I can define a "random variable" plus an operator Expectation such that Expectation(A+E)  by A+Expectation(E) ... but it's not a way I would call simple

```Expectation := proc(e::algebraic)
local a,b;
if not hastype(e, RV) then e
elif e::RV then 'procname'(e)
elif e::`+` then map(thisproc, e)
elif e::`*` then
(a,b):= selectremove(hastype, e, RV);
b*thisproc(a)
else 'procname'(e)
end if
end proc:

#------------------------------------------------------------------------