MathGroup Archive 2007

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

Search the Archive

Mathematical expectation

  • To: mathgroup at
  • Subject: [mg84113] Mathematical expectation
  • From: Benoît Frénay <benoit.frenay at>
  • Date: Mon, 10 Dec 2007 20:40:00 -0500 (EST)


I'm new to Mathematica and I'm trying to define a generic mathematical 
expectation operator (called Esp) for i.i.d variables X[i] following the 
same distribution as the variable X (i.e. Esp[X[i]] == Esp[X]).  My code is

Esp[X[_]] := Esp[X]
Esp[X[_]^y_] := Esp[X^y]
Esp[Esp[x_]] := Esp[x]
Esp[Esp[x_]^y_] := Esp[x]^y
Esp[x_ + y_] := Esp[x] + Esp[y]
Esp[x_ y_] := Esp[x] Esp[y] /; FreeQ[x, y] && FreeQ[y, x]
Esp[c_] := c /; FreeQ[c, X]
Esp[c_ x_] := c Esp[x] /; NumberQ[c]

But when I feed
 >>> In[14]:= Esp[(X[1] + X[2])^2]
I obtain
 >>> Out[14]= Esp[(X[1] + X[2])^2]
In fact, I obtain the correct answer only if I ask Mathematica to expand 
the inner term:
In[16]:= Esp[Expand[(X[1] + X[2])^2]]
Out[16]= 2 Esp[X]^2 + 2 Esp[X^2]

Where am I wrong?


Benoît Frénay

  • Prev by Date: Re: Hi presision problem
  • Next by Date: Re: Binary Vector Manipulation
  • Previous by thread: Re: Re: ContourPlotOnSurface
  • Next by thread: Re: Mathematical expectation