MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Use of Mathematica with Rule-based Equation Derivations

mmorriss at wrote:
> Hi All - I'm a many-year user of mathematica, but have always had one
> particular problem with it that I may have just simply missed reading
> about.
> Mathematica Version: 5.2
> Problem: I would like to develop a set of re-rewite rules to apply to the
> Expected Value operator.  For example:
> E[a x] = a E[x]  a -> constant, x -> variable
> E[b + f[x]] = b + E[f[x]] , etc.
> The issue is how does one using Mathematica distinguish a 'constant
> variable (i.e. a and b)' from a variable 'variable' (i.e. 'x')? The head
> of a, b and x is 'Symbol' and neither a, b nor x contain a number so I
> can't use a_?NumberQ to identify it as a constant.
> This actually goes to the wider question of how does one use Mathematica
> for symbolic derviations where numbers are not actually substituted in the
> derviation?
> E.g. E[a + E[b x]] /. Rule2
>    out= a + b E[x] etc.
> Thanks all - Mark Morrissey
> University of Oklahoma

One reasonable approach would be to use an explicit head to denote 
random variables (as opposed to scalares). Pulling out constant factors 
could then be done as below.

expectation[1] := 1

expectation[a_+b_] := expectation[a]+expectation[b]

expectation[a_*b_.] /; FreeQ[a,randomVariable] := a*expectation[b]

In[10]:= InputForm[expectation[a+c*randomVariable[b]^2]]

Out[10]//InputForm= a + c*expectation[randomVariable[b]^2]

A standard recommendation is that you not call the operator E.

Daniel Lichtblau
Wolfram Research

  • Prev by Date: No Biconditional?
  • Next by Date: Re: Mean of skew-normal distribution
  • Previous by thread: Use of Mathematica with Rule-based Equation Derivations
  • Next by thread: Re: Use of Mathematica with Rule-based Equation Derivations