class_docstr: Symbolic expression for the expectation.
  
  Examples
  ========
  
  >>> from sympy.stats import Expectation, Normal, Probability, Poisson
  >>> from sympy import symbols, Integral, Sum
  >>> mu = symbols("mu")
  >>> sigma = symbols("sigma", positive=True)
  >>> X = Normal("X", mu, sigma)
  >>> Expectation(X)
  Expectation(X)
  >>> Expectation(X).evaluate_integral().simplify()
  mu
  
  To get the integral expression of the expectation:
  
  >>> Expectation(X).rewrite(Integral)
  Integral(sqrt(2)*X*exp(-(X - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma), (X, -oo, oo))
  
  The same integral expression, in more abstract terms:
  
  >>> Expectation(X).rewrite(Probability)
  Integral(x*Probability(Eq(X, x)), (x, -oo, oo))
  
  To get the Summation expression of the expectation for discrete random variables:
  
  >>> lamda = symbols('lamda', positive=True)
  >>> Z = Poisson('Z', lamda)
  >>> Expectation(Z).rewrite(Sum)
  Sum(Z*lamda**Z*exp(-lamda)/factorial(Z), (Z, 0, oo))
  
  This class is aware of some properties of the expectation:
  
  >>> from sympy.abc import a
  >>> Expectation(a*X)
  Expectation(a*X)
  >>> Y = Normal("Y", 1, 2)
  >>> Expectation(X + Y)
  Expectation(X + Y)
  
  To expand the ``Expectation`` into its expression, use ``expand()``:
  
  >>> Expectation(X + Y).expand()
  Expectation(X) + Expectation(Y)
  >>> Expectation(a*X + Y).expand()
  a*Expectation(X) + Expectation(Y)
  >>> Expectation(a*X + Y)
  Expectation(a*X + Y)
  >>> Expectation((X + Y)*(X - Y)).expand()
  Expectation(X**2) - Expectation(Y**2)
  
  To evaluate the ``Expectation``, use ``doit()``:
  
  >>> Expectation(X + Y).doit()
  mu + 1
  >>> Expectation(X + Expectation(Y + Expectation(2*X))).doit()
  3*mu + 1
  
  To prevent evaluating nested ``Expectation``, use ``doit(deep=False)``
  
  >>> Expectation(X + Expectation(Y)).doit(deep=False)
  mu + Expectation(Expectation(Y))
  >>> Expectation(X + Expectation(Y + Expectation(2*X))).doit(deep=False)
  mu + Expectation(Expectation(Expectation(2*X) + Y))
class_docstr_tok: ["Symbolic","expression","for","the","expectation",".","Examples","========",">",">",">","from","sympy.stats","import","Expectation",",","Normal",",","Probability",",","Poisson",">",">",">","from","sympy","import","symbols",",","Integral",",","Sum",">",">",">","mu","=","symbols","(","``","mu","''",")",">",">",">","sigma","=","symbols","(","``","sigma","''",",","positive=True",")",">",">",">","X","=","Normal","(","``","X","''",",","mu",",","sigma",")",">",">",">","Expectation","(","X",")","Expectation","(","X",")",">",">",">","Expectation","(","X",")",".evaluate_integral","(",")",".simplify","(",")","mu","To","get","the","integral","expression","of","the","expectation",":",">",">",">","Expectation","(","X",")",".rewrite","(","Integral",")","Integral","(","sqrt","(","2",")","*","X","*","exp","(","-","(","X","-","mu",")","*","*","2\/","(","2","*","sigma","*","*","2",")",")","\/","(","2","*","sqrt","(","pi",")","*","sigma",")",",","(","X",",","-oo",",","oo",")",")","The","same","integral","expression",",","in","more","abstract","terms",":",">",">",">","Expectation","(","X",")",".rewrite","(","Probability",")","Integral","(","x","*","Probability","(","Eq","(","X",",","x",")",")",",","(","x",",","-oo",",","oo",")",")","To","get","the","Summation","expression","of","the","expectation","for","discrete","random","variables",":",">",">",">","lamda","=","symbols","(","'lamda","'",",","positive=True",")",">",">",">","Z","=","Poisson","(","'","Z","'",",","lamda",")",">",">",">","Expectation","(","Z",")",".rewrite","(","Sum",")","Sum","(","Z","*","lamda","*","*","Z","*","exp","(","-lamda",")","\/factorial","(","Z",")",",","(","Z",",","0",",","oo",")",")","This","class","is","aware","of","some","properties","of","the","expectation",":",">",">",">","from","sympy.abc","import","a",">",">",">","Expectation","(","a","*","X",")","Expectation","(","a","*","X",")",">",">",">","Y","=","Normal","(","``","Y","''",",","1",",","2",")",">",">",">","Expectation","(","X","+","Y",")","Expectation","(","X","+","Y",")","To","expand","the","``","Expectation","``","into","its","expression",",","use","``","expand","(",")","``",":",">",">",">","Expectation","(","X","+","Y",")",".expand","(",")","Expectation","(","X",")","+","Expectation","(","Y",")",">",">",">","Expectation","(","a","*","X","+","Y",")",".expand","(",")","a","*","Expectation","(","X",")","+","Expectation","(","Y",")",">",">",">","Expectation","(","a","*","X","+","Y",")","Expectation","(","a","*","X","+","Y",")",">",">",">","Expectation","(","(","X","+","Y",")","*","(","X","-","Y",")",")",".expand","(",")","Expectation","(","X","*","*","2",")","-","Expectation","(","Y","*","*","2",")","To","evaluate","the","``","Expectation","``",",","use","``","doit","(",")","``",":",">",">",">","Expectation","(","X","+","Y",")",".doit","(",")","mu","+","1",">",">",">","Expectation","(","X","+","Expectation","(","Y","+","Expectation","(","2","*","X",")",")",")",".doit","(",")","3","*","mu","+","1","To","prevent","evaluating","nested","``","Expectation","``",",","use","``","doit","(","deep=False",")","``",">",">",">","Expectation","(","X","+","Expectation","(","Y",")",")",".doit","(","deep=False",")","mu","+","Expectation","(","Expectation","(","Y",")",")",">",">",">","Expectation","(","X","+","Expectation","(","Y","+","Expectation","(","2","*","X",")",")",")",".doit","(","deep=False",")","mu","+","Expectation","(","Expectation","(","Expectation","(","2","*","X",")","+","Y",")",")"]
code: def _eval_rewrite_as_Probability(self, arg, condition=None, **kwargs):
      rvs = arg.atoms(RandomSymbol)
      if len(rvs) > 1:
          raise NotImplementedError()
      if len(rvs) == 0:
          return arg
  
      rv = rvs.pop()
      if rv.pspace is None:
          raise ValueError("Probability space not known")
  
      symbol = rv.symbol
      if symbol.name[0].isupper():
          symbol = Symbol(symbol.name.lower())
      else:
          symbol = Symbol(symbol.name + "_1")
  
      if rv.pspace.is_Continuous:
          return Integral(
              arg.replace(rv, symbol)
              * Probability(Eq(rv, symbol), condition),
              (
                  symbol,
                  rv.pspace.domain.set.inf,
                  rv.pspace.domain.set.sup,
              ),
          )
      else:
          if rv.pspace.is_Finite:
              raise NotImplementedError
          else:
              return Sum(
                  arg.replace(rv, symbol)
                  * Probability(Eq(rv, symbol), condition),
                  (symbol, rv.pspace.domain.set.inf, rv.pspace.set.sup),
              )
  
imports: import itertools
  from sympy.concrete.summations import Sum
  from sympy.core.add import Add
  from sympy.core.expr import Expr
  from sympy.core.function import expand
  from sympy.core.mul import Mul
  from sympy.core.relational import Eq
  from sympy.core.singleton import S
  from sympy.core.symbol import Symbol
  from sympy.integrals.integrals import Integral
  from sympy.logic.boolalg import Not
  from sympy.core.parameters import global_parameters
  from sympy.core.sorting import default_sort_key
  from sympy.core.sympify import _sympify
  from sympy.core.relational import Relational
  from sympy.logic.boolalg import Boolean
  from sympy.stats import variance, covariance
  from sympy.stats.rv import RandomSymbol, pspace, dependent, given, sampling_E, RandomIndexedSymbol, is_random, PSpace, sampling_P, random_symbols
label_desc: Use image node_id 5 for calling the Expectation obj's underlying member method code with example usage: obj._eval_rewrite_as_Probability(arg, condition) and returns: arg, Integral, Sum