I need to do some simplification of an expression involving averages over a stochastic variable (in order to verify a long analytical calculation).
The easiest way to do that, I figured, were if I could implement an operator which would basically be short-hand for the averaging procedure, with all the appropriate properties. Then of course this operator would be present in the final expression, which is fine, and would enable me to compare easily with my own calculations.
So assuming I use
x for the stochastic variable, I tried defining
av[y_ + z_] := av[y] + av[z] av[c_ y_] := c av[y] /; FreeQ[c, x] av[c_] := c /; FreeQ[c, x]
Then when I write
D[av[x y], y]
which is fine, but when I write
D[av[Exp[-x y]], y]
-E^(-x y) y
-y av[Exp[-x y]] as I want, i.e., the
av is removed somehow.
I tried using
UpValue for teaching Mathematica that it could interchange differentiation and
av, but apparently that is not the problem.
I might be going about this entirely the wrong way, but I'd be grateful for any input. Note the builtin
Expectation function does not accomplish it either - e.g., it doesn't handle the derivatives as a proper average operator would. For example
h[y_] := Expectation[y, x \[Distributed] pp] (*pp unknown density*)
D[h[Exp[-x y]], x]
(Expectation^(0,1))[E^(-x y),x\[Distributed]pp] (Distributed^(1,0))[x,pp]-E^(-x y) y (Expectation^(1,0))[E^(-x y),x\[Distributed]pp]
whereas I wanted
-y h[Exp[-y x]]
(i.e moving the derivative inside the averaging h). Sune