+
    iZ                        ^ RI t ^ RIHt ^ RIHt ^ RIHt ^ RIHt	 ^ RI
Ht ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtH t  ^ RI!H"t"H#t#H$t$H%t%H&t&H't'H(t(H)t)H*t*H+t+ . R!Ot,](PZ                  ! ]4      R 4       t.](PZ                  ! ]"4      R 4       t. ! R R]4      t/ ! R R]4      t0 ! R R]4      t1 ! R R]4      t2 ! R R]4      t3 ! R R ]4      t4R# )"    N)Sum)Add)Expr)expand)Mul)Eq)S)Symbol)Integral)Not)global_parameters)default_sort_key)_sympify)
Relational)Boolean)variance
covariance)
RandomSymbolpspace	dependentgiven
sampling_ERandomIndexedSymbol	is_randomPSpace
sampling_Prandom_symbolsProbabilityExpectationVariance
Covariancec                     V P                   p\        V4      ^8X  d   \        \        V4      4      V 8X  d   R# \        ;QJ d    R V 4       F  '       g   K   R# 	  R# ! R V 4       4      # )   Fc              3   8   "   T F  p\        V4      x  K  	  R # 5iN)r   ).0is   & ڀ/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/stats/symbolic_probability.py	<genexpr>_.<locals>.<genexpr>   s     +Uy||Us   T)free_symbolslennextiterany)xatomss   & r(   _r2      sR    NNE
5zQ4U,13+U+33+3+3+U+++    c                     R # )T )r0   s   &r(   r2   r2       s    r3   c                   L   a  ] tR t^%t o RtRtR	R ltR tR	R lt]t	R t
RtV tR# )
r   a  
Symbolic expression for the probability.

Examples
========

>>> from sympy.stats import Probability, Normal
>>> from sympy import Integral
>>> X = Normal("X", 0, 1)
>>> prob = Probability(X > 1)
>>> prob
Probability(X > 1)

Integral representation:

>>> prob.rewrite(Integral)
Integral(sqrt(2)*exp(-_z**2/2)/(2*sqrt(pi)), (_z, 1, oo))

Evaluation of the integral:

>>> prob.evaluate_integral()
sqrt(2)*(-sqrt(2)*sqrt(pi)*erf(sqrt(2)/2) + sqrt(2)*sqrt(pi))/(4*sqrt(pi))
TNc                    \        V4      pVf   \        P                  ! W4      pM"\        V4      p\        P                  ! WV4      pW$n        V# r%   )r   r   __new__
_condition)clsprob	conditionkwargsobjs   &&&, r(   r8   Probability.__new__@   sC    ~,,s)C +I,,s)4C"
r3   c                  a V P                   ^ ,          pV P                  oVP                  RR4      pVP                  RR4      p\        V\        4      '       dK   \
        P                  V P                  VP                   ^ ,          SVR7      P                  ! R/ VB ,
          # VP                  \        4      '       d   \        V4      P                  VSVR7      # \        S\        4      '       d   \        V4      p\        V4      ^8X  d>   V^ ,          S8X  d0   ^ RIHp V! V P                  V4      P                  ! R/ VB ^ ^4      # \$        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       d   \'        VS4      # \'        V4      P                  4       # Se/   \        S\(        \*        34      '       g   \-        RS,          4      hSR8X  g   V\
        P.                  J d   \
        P0                  # \        V\(        \*        34      '       g   \-        RV,          4      hV\
        P2                  J d   \
        P                  # V'       d   \5        VSVR	7      # Se$   \'        \7        VS4      4      P                  4       # \        V4      \9        4       8X  d   \'        VS4      # \        V4      P                  V4      p\;        VR
4      '       d   V'       d   VP                  4       # V# )r   
numsamplesFevaluateTrB   )BernoulliDistributionc              3   <   <"   T F  p\        VS4      x  K  	  R # 5ir%   )r   )r&   rvgiven_conditions   & r(   r)   #Probability.doit.<locals>.<genexpr>]   s     CFb9R11Fs   z4%s is not a relational or combination of relationals)rA   doitr5   )argsr9   get
isinstancer   r	   OnefuncrI   hasr   r   probabilityr   r   r,   sympy.stats.frv_typesrD   r/   r   r   r   
ValueErrorfalseZerotruer   r   r   hasattr)	selfhintsr<   rA   rB   condrvrD   resultrG   s	   &,      @r(   rI   Probability.doitJ   sz   IIaL	//YY|U3
99Z.i%%55499Y^^A%6-5 % 77;t< E>CE E E ==,--)$00O6> 1 @ @ o|44#I.F6{aF1I$@G,TYYy-A-F-F-O-OQRTUVVsCFCsssCFCCC"9o>>"9-2244&W0EFFS&( ) ) e#yAGG';66M)j'%:;;S " # #55LiZPP&uY@AFFHH )(y/::	"..y966""x;;= Mr3   c                F    V P                  WR 7      P                  RR7      # )r<   FrC   rN   rI   rW   argr<   r=   s   &&&,r(   _eval_rewrite_as_Integral%Probability._eval_rewrite_as_Integral   s!    yyy2777GGr3   c                H    V P                  \        4      P                  4       # r%   rewriter   rI   rW   s   &r(   evaluate_integralProbability.evaluate_integral       ||H%**,,r3   r5   r%   )__name__
__module____qualname____firstlineno____doc__is_commutativer8   rI   ra   _eval_rewrite_as_Sumrg   __static_attributes____classdictcell____classdict__s   @r(   r   r   %   s4     0 N3jH 5- -r3   c                   b   a  ] tR t^t o RtRR ltR tR tR tRR lt	RR lt
]
tR	 t]tR
tV tR# )r   a`  
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))

Nc                   \        V4      pVP                  '       d   ^ RIHp V! W4      # Vf+   \	        V4      '       g   V# \
        P                  ! W4      pM"\        V4      p\
        P                  ! WV4      pW%n        V# )r   )ExpectationMatrix)r   	is_Matrix-sympy.stats.symbolic_multivariate_probabilityrw   r   r   r8   r9   )r:   exprr<   r=   rw   r>   s   &&&,  r(   r8   Expectation.__new__   sh    ~>>>W$T55T??,,s)C +I,,s)4C"
r3   c                <    V P                   ^ ,          P                  # r   rJ   ro   rf   s   &r(   _eval_is_commutative Expectation._eval_is_commutative   s    yy|**+r3   c                  a V P                   ^ ,          pV P                  o\        V4      '       g   V# \        V\        4      '       d+   \        P
                  ! V3R lVP                    4       4      # \        V4      p\        V\        4      '       d+   \        P
                  ! V3R lVP                    4       4      # \        V\        4      '       d   . p. pVP                    F8  p\        V4      '       d   VP                  V4       K'  VP                  V4       K:  	  \        P
                  ! V4      \        \        P
                  ! V4      SR7      ,          # V # )r   c              3   Z   <"   T F   p\        VSR 7      P                  4       x  K"  	  R# 5ir]   Nr   r   r&   ar<   s   & r(   r)   %Expectation.expand.<locals>.<genexpr>   s+       (& !,A C J J L L&   (+c              3   Z   <"   T F   p\        VSR 7      P                  4       x  K"  	  R# 5ir   r   r   s   & r(   r)   r      s+       /- !,A C J J L L-r   r]   )
rJ   r9   r   rL   r   fromiter_expandr   appendr   )rW   rX   rz   expand_exprrF   nonrvr   r<   s   &,     @r(   r   Expectation.expand   s   yy|OO	KdC  <<  (!YY ( ( ( dmk3''<<  /(-- / / / c""BEYYQ<<IIaLLLO	 
 <<&{3<<3Cy'YYYr3   c           
        VP                  R R4      pV P                  pV P                  ^ ,          pVP                  RR4      pVP                  RR4      pV'       d   VP                  ! R	/ VB p\	        V4      '       d   \        V\        4      '       d   V# V'       d    VP                  RR4      p\        WCWWR7      # VP                  \        4      '       d   \        V4      P                  WC4      # Ve+   V P                  \        WC4      4      P                  ! R	/ VB # VP                  '       dj   \        VP                   Uu. uFK  p\        V\        4      '       g"   V P                  W4      P                  ! R	/ VB MV P                  W4      NKM  	  up!  # VP                   '       d   VP#                  \        4      '       d   V# \        V4      \%        4       8X  d   V P                  V4      # \        V4      P                  WFR7      p	\'        V	R4      '       d   V'       d   V	P                  ! R	/ VB # V	# u upi )
deepTrA   FrB   evalf)rA   r   rC   rI   r5   )rK   r9   rJ   rI   r   rL   r   r   rO   r   r   compute_expectationrN   r   is_Addr   is_Mulr1   r   rV   )
rW   rX   r   r<   rz   rA   rB   r   r`   rZ   s
   &,        r(   rI   Expectation.doit   s   yy&OO	yy|YY|U3
99Z.99%u%D*T;"?"?KIIgt,Ed*RR88'(($<33DDD  99U43499BEBB ;;;$(II/$-S &c;77 3277@%@=AYYs=VW$-/ 0 0 ;;;zz+&&$<68#99T?"11$1J66""x;;'''M/s   AH?c           	     @   VP                  \        4      p\        V4      ^8  d   \        4       h\        V4      ^ 8X  d   V# VP	                  4       pVP
                  f   \        R4      hVP                  pVP                  ^ ,          P                  4       '       d%   \        VP                  P                  4       4      pM\        VP                  R,           4      pVP
                  P                  '       d   \        VP                  WV4      \        \!        WV4      V4      ,          WeP
                  P"                  P$                  P&                  VP
                  P"                  P$                  P(                  34      # VP
                  P*                  '       d   \        h\-        VP                  WV4      \        \!        WV4      V4      ,          WeP
                  P"                  P$                  P&                  VP
                  P$                  P(                  34      # )r#   zProbability space not known_1)r1   r   r,   NotImplementedErrorpopr   rR   symbolnameisupperr
   loweris_Continuousr   replacer   r   domainsetinfsup	is_Finiter   )rW   r`   r<   r=   rvsrF   r   s   &&&,   r(   _eval_rewrite_as_Probability(Expectation._eval_rewrite_as_Probability'  s   ii%s8a<%''s8q=JWWY99:;;;;q>!!##FKK--/0FFKK$./F99"""CKK3K2PY4ZZ]ceneneueueyeye}e}  @B  @I  @I  @P  @P  @T  @T  @X  @X  ]Y  Z  Zyy"""))3;;r2;r"~y3YY\bdmdmdtdtdxdxd|d|  A  H  H  L  L  P  P  \Q  R  Rr3   c                H    V P                  WR 7      P                  RVR7      # )r]   F)r   rB   r^   )rW   r`   r<   rB   r=   s   &&&&,r(   ra   %Expectation._eval_rewrite_as_Integral@  s#    yyy277UX7VVr3   c                H    V P                  \        4      P                  4       # r%   rd   rf   s   &r(   rg   Expectation.evaluate_integralE  ri   r3   r5   r%   )NF)rj   rk   rl   rm   rn   r8   r   r   rI   r   ra   rp   rg   evaluate_sumrq   rr   rs   s   @r(   r   r      sA     CJ,8(VR2W 5- %Lr3   c                   b   a  ] tR tRt o RtRR ltR tR tRR ltRR lt	RR	 lt
]
tR
 tRtV tR# )r    iJ  a.  
Symbolic expression for the variance.

Examples
========

>>> from sympy import symbols, Integral
>>> from sympy.stats import Normal, Expectation, Variance, Probability
>>> mu = symbols("mu", positive=True)
>>> sigma = symbols("sigma", positive=True)
>>> X = Normal("X", mu, sigma)
>>> Variance(X)
Variance(X)
>>> Variance(X).evaluate_integral()
sigma**2

Integral representation of the underlying calculations:

>>> Variance(X).rewrite(Integral)
Integral(sqrt(2)*(X - Integral(sqrt(2)*X*exp(-(X - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma), (X, -oo, oo)))**2*exp(-(X - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma), (X, -oo, oo))

Integral representation, without expanding the PDF:

>>> Variance(X).rewrite(Probability)
-Integral(x*Probability(Eq(X, x)), (x, -oo, oo))**2 + Integral(x**2*Probability(Eq(X, x)), (x, -oo, oo))

Rewrite the variance in terms of the expectation

>>> Variance(X).rewrite(Expectation)
-Expectation(X)**2 + Expectation(X**2)

Some transformations based on the properties of the variance may happen:

>>> from sympy.abc import a
>>> Y = Normal("Y", 0, 1)
>>> Variance(a*X)
Variance(a*X)

To expand the variance in its expression, use ``expand()``:

>>> Variance(a*X).expand()
a**2*Variance(X)
>>> Variance(X + Y)
Variance(X + Y)
>>> Variance(X + Y).expand()
2*Covariance(X, Y) + Variance(X) + Variance(Y)

Nc                    \        V4      pVP                  '       d   ^ RIHp V! W4      # Vf   \        P
                  ! W4      pM"\        V4      p\        P
                  ! WV4      pW%n        V# )r   )VarianceMatrix)r   rx   ry   r   r   r8   r9   )r:   r`   r<   r=   r   r>   s   &&&,  r(   r8   Variance.__new__{  sZ    sm===T!#11,,s(C +I,,s3C"
r3   c                <    V P                   ^ ,          P                  # r}   r~   rf   s   &r(   r   Variance._eval_is_commutative      yy|***r3   c           	     p  a	 V P                   ^ ,          pV P                  o	\        V4      '       g   \        P                  # \        V\        4      '       d   V # \        V\        4      '       d   . pVP                    F'  p\        V4      '       g   K  VP                  V4       K)  	  \        V	3R lV 4       !  pV	3R lp\        \        V\        P                  ! V^4      4      !  pWW,           # \        V\        4      '       d   . p. pVP                    F?  p\        V4      '       d   VP                  V4       K'  VP                  V^,          4       KA  	  \        V4      ^ 8X  d   \        P                  # \        P                  ! V4      \        \        P                  ! V4      S	4      ,          # V # )r   c              3   X   <"   T F  p\        VS4      P                  4       x  K!  	  R # 5ir%   )r    r   )r&   xvr<   s   & r(   r)   "Variance.expand.<locals>.<genexpr>  s$     L2hr95<<>>s   '*c                 D   < ^\        V RS/ P                  4       ,          # )   r<   )r!   r   )r0   r<   s   &r(   <lambda>!Variance.expand.<locals>.<lambda>  s    Qz1'J	'J'Q'Q'S%Sr3   )rJ   r9   r   r	   rT   rL   r   r   r   map	itertoolscombinationsr   r,   r   r    )
rW   rX   r`   rF   r   	variancesmap_to_covarcovariancesr   r<   s
   &,       @r(   r   Variance.expand  s9   iilOO	~~66Mc<((KS!!BXXQ<<IIaL  LLMISLs<1G1GA1NOPK**S!!EBXXQ<<IIaLLLA&	 
 2w!|vv<<&xR0@)'LLL r3   c                \    \        V^,          V4      p\        W4      ^,          pWE,
          # )r   r   )rW   r`   r<   r=   e1e2s   &&&,  r(   _eval_rewrite_as_Expectation%Variance._eval_rewrite_as_Expectation  s(    S!VY/BS,a/B7Nr3   c                R    V P                  \        4      P                  \        4      # r%   re   r   r   r_   s   &&&,r(   r   %Variance._eval_rewrite_as_Probability      ||K(00==r3   c                T    \        V P                  ^ ,          V P                  RR7      # r   FrC   )r   rJ   r9   r_   s   &&&,r(   ra   "Variance._eval_rewrite_as_Integral  s    		!dooFFr3   c                H    V P                  \        4      P                  4       # r%   rd   rf   s   &r(   rg   Variance.evaluate_integral  ri   r3   r5   r%   )rj   rk   rl   rm   rn   r8   r   r   r   r   ra   rp   rg   rq   rr   rs   s   @r(   r    r    J  s=     /`+B
>G 5- -r3   c                      a  ] tR tRt o RtRR ltR tR t]R 4       t	]R 4       t
RR	 ltRR
 ltRR lt]tR tRtV tR# )r!   i  a  
Symbolic expression for the covariance.

Examples
========

>>> from sympy.stats import Covariance
>>> from sympy.stats import Normal
>>> X = Normal("X", 3, 2)
>>> Y = Normal("Y", 0, 1)
>>> Z = Normal("Z", 0, 1)
>>> W = Normal("W", 0, 1)
>>> cexpr = Covariance(X, Y)
>>> cexpr
Covariance(X, Y)

Evaluate the covariance, `X` and `Y` are independent,
therefore zero is the result:

>>> cexpr.evaluate_integral()
0

Rewrite the covariance expression in terms of expectations:

>>> from sympy.stats import Expectation
>>> cexpr.rewrite(Expectation)
Expectation(X*Y) - Expectation(X)*Expectation(Y)

In order to expand the argument, use ``expand()``:

>>> from sympy.abc import a, b, c, d
>>> Covariance(a*X + b*Y, c*Z + d*W)
Covariance(a*X + b*Y, c*Z + d*W)
>>> Covariance(a*X + b*Y, c*Z + d*W).expand()
a*c*Covariance(X, Z) + a*d*Covariance(W, X) + b*c*Covariance(Y, Z) + b*d*Covariance(W, Y)

This class is aware of some properties of the covariance:

>>> Covariance(X, X).expand()
Variance(X)
>>> Covariance(a*X, b*Y).expand()
a*b*Covariance(X, Y)
Nc                   \        V4      p\        V4      pVP                  '       g   VP                  '       d   ^ RIHp V! WV4      # VP	                  R\
        P                  4      '       d   \        W.\        R7      w  rVf   \        P                  ! WV4      pM"\        V4      p\        P                  ! WW#4      pW6n        V# )r   )CrossCovarianceMatrixrB   key)r   rx   ry   r   r   r   rB   sortedr   r   r8   r9   )r:   arg1arg2r<   r=   r   r>   s   &&&&,  r(   r8   Covariance.__new__  s    ~~>>>T^^^[(Y??::j"3"<"<==2BCJD,,s$/C +I,,s$:C"
r3   c                <    V P                   ^ ,          P                  # r}   r~   rf   s   &r(   r   Covariance._eval_is_commutative  r   r3   c                   V P                   ^ ,          pV P                   ^,          pV P                  pW#8X  d   \        W$4      P                  4       # \	        V4      '       g   \
        P                  # \	        V4      '       g   \
        P                  # \        W#.\        R7      w  r#\        V\        4      '       d#   \        V\        4      '       d   \        W#V4      # V P                  VP                  4       4      pV P                  VP                  4       4      pV UUU	U
u. uF8  w  rxV F-  w  rWy,          \        \        W.\        R7      RV/ ,          NK/  	  K:  	  pp	ppp
\        P                  ! V4      # u up
p	ppi )r   r   r<   )rJ   r9   r    r   r   r	   rT   r   r   rL   r   r!   _expand_single_argumentr   r   )rW   rX   r   r   r<   coeff_rv_list1coeff_rv_list2r   r1br2addendss   &,          r(   r   Covariance.expand  s.   yy|yy|OO	<D,335566M66MTL.>?
dL))j|.L.Ld)4455dkkmD55dkkmD #1P"0wWa 3z62(8H#I_U^___@N `"0 	 P||G$$Ps   %>E>
c                "   \        V\        4      '       d   \        P                  V3.# \        V\        4      '       d   . pVP
                   Fo  p\        V\        4      '       d#   VP                  V P                  V4      4       K;  \        V4      '       g   KN  VP                  \        P                  V34       Kq  	  V# \        V\        4      '       d   V P                  V4      .# \        V4      '       d   \        P                  V3.# R # r%   )
rL   r   r	   rM   r   rJ   r   r   _get_mul_nonrv_rv_tupler   )r:   rz   outvalr   s   &&  r(   r   "Covariance._expand_single_argument  s     dL))UUDM?"c""FYYa%%MM#"="=a"@Aq\\MM155!*-	  Mc""//566t__UUDM?" r3   c                    . p. pVP                    F8  p\        V4      '       d   VP                  V4       K'  VP                  V4       K:  	  \        P                  ! V4      \        P                  ! V4      3# r%   )rJ   r   r   r   r   )r:   mrF   r   r   s   &&   r(   r   "Covariance._get_mul_nonrv_rv_tuple-  sX    A||		!Q	 
 U#S\\"%566r3   c                l    \        W,          V4      p\        W4      \        W#4      ,          pWV,
          # r%   r   )rW   r   r   r<   r=   r   r   s   &&&&,  r(   r   'Covariance._eval_rewrite_as_Expectation8  s+    I.)+d*FFwr3   c                R    V P                  \        4      P                  \        4      # r%   r   rW   r   r   r<   r=   s   &&&&,r(   r   'Covariance._eval_rewrite_as_Probability=  r   r3   c                x    \        V P                  ^ ,          V P                  ^,          V P                  RR7      # r   )r   rJ   r9   r   s   &&&&,r(   ra   $Covariance._eval_rewrite_as_Integral@  s(    $))A,		!dooPUVVr3   c                H    V P                  \        4      P                  4       # r%   rd   rf   s   &r(   rg   Covariance.evaluate_integralE  ri   r3   r5   r%   )rj   rk   rl   rm   rn   r8   r   r   classmethodr   r   r   r   ra   rp   rg   rq   rr   rs   s   @r(   r!   r!     sd     *X&+%2 # #$ 7 7
>W 5- -r3   c                   ^   a a ] tR tRt oRtR	V 3R lltR tR	R ltR	R ltR	R lt	Rt
VtV ;t# )
MomentiI  a7  
Symbolic class for Moment

Examples
========

>>> from sympy import Symbol, Integral
>>> from sympy.stats import Normal, Expectation, Probability, Moment
>>> mu = Symbol('mu', real=True)
>>> sigma = Symbol('sigma', positive=True)
>>> X = Normal('X', mu, sigma)
>>> M = Moment(X, 3, 1)

To evaluate the result of Moment use `doit`:

>>> M.doit()
mu**3 - 3*mu**2 + 3*mu*sigma**2 + 3*mu - 3*sigma**2 - 1

Rewrite the Moment expression in terms of Expectation:

>>> M.rewrite(Expectation)
Expectation((X - 1)**3)

Rewrite the Moment expression in terms of Probability:

>>> M.rewrite(Probability)
Integral((x - 1)**3*Probability(Eq(X, x)), (x, -oo, oo))

Rewrite the Moment expression in terms of Integral:

>>> M.rewrite(Integral)
Integral(sqrt(2)*(X - 1)**3*exp(-(X - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma), (X, -oo, oo))

c                   < \        V4      p\        V4      p\        V4      pVe   \        V4      p\        SV `	  WW#V4      # \        SV `	  WW#4      # r%   r   superr8   )r:   Xncr<   r=   	__class__s   &&&&&,r(   r8   Moment.__new__l  sR    QKQKQK  +I7?31;;7?3100r3   c                L    V P                  \        4      P                  ! R/ VB # Nr5   re   r   rI   rW   rX   s   &,r(   rI   Moment.doitv      ||K(--666r3   c                4    \        W,
          V,          V4      # r%   r   rW   r   r   r   r<   r=   s   &&&&&,r(   r   #Moment._eval_rewrite_as_Expectationy  s    AEA:y11r3   c                R    V P                  \        4      P                  \        4      # r%   r   r	  s   &&&&&,r(   r   #Moment._eval_rewrite_as_Probability|  r   r3   c                R    V P                  \        4      P                  \        4      # r%   re   r   r   r	  s   &&&&&,r(   ra    Moment._eval_rewrite_as_Integral      ||K(00::r3   r5   )r   Nrj   rk   rl   rm   rn   r8   rI   r   r   ra   rq   rr   __classcell__r   rt   s   @@r(   r   r   I  s)     !D172>; ;r3   r   c                   ^   a a ] tR tRt oRtR	V 3R lltR tR	R ltR	R ltR	R lt	Rt
VtV ;t# )
CentralMomenti  a  
Symbolic class Central Moment

Examples
========

>>> from sympy import Symbol, Integral
>>> from sympy.stats import Normal, Expectation, Probability, CentralMoment
>>> mu = Symbol('mu', real=True)
>>> sigma = Symbol('sigma', positive=True)
>>> X = Normal('X', mu, sigma)
>>> CM = CentralMoment(X, 4)

To evaluate the result of CentralMoment use `doit`:

>>> CM.doit().simplify()
3*sigma**4

Rewrite the CentralMoment expression in terms of Expectation:

>>> CM.rewrite(Expectation)
Expectation((-Expectation(X) + X)**4)

Rewrite the CentralMoment expression in terms of Probability:

>>> CM.rewrite(Probability)
Integral((x - Integral(x*Probability(True), (x, -oo, oo)))**4*Probability(Eq(X, x)), (x, -oo, oo))

Rewrite the CentralMoment expression in terms of Integral:

>>> CM.rewrite(Integral)
Integral(sqrt(2)*(X - Integral(sqrt(2)*X*exp(-(X - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma), (X, -oo, oo)))**4*exp(-(X - mu)**2/(2*sigma**2))/(2*sqrt(pi)*sigma), (X, -oo, oo))

c                   < \        V4      p\        V4      pVe   \        V4      p\        SV `	  WW#4      # \        SV `	  WV4      # r%   r   )r:   r   r   r<   r=   r   s   &&&&,r(   r8   CentralMoment.__new__  sG    QKQK  +I7?31887?31--r3   c                L    V P                  \        4      P                  ! R/ VB # r  r  r  s   &,r(   rI   CentralMoment.doit  r  r3   c                Z    \        W3/ VB p\        WWS3/ VB P                  \         4      # r%   )r   r   re   )rW   r   r   r<   r=   mus   &&&&, r(   r   *CentralMoment._eval_rewrite_as_Expectation  s.    00aB4V4<<[IIr3   c                R    V P                  \        4      P                  \        4      # r%   r   rW   r   r   r<   r=   s   &&&&,r(   r   *CentralMoment._eval_rewrite_as_Probability  r   r3   c                R    V P                  \        4      P                  \        4      # r%   r  r  s   &&&&,r(   ra   'CentralMoment._eval_rewrite_as_Integral  r  r3   r5   r%   r  r  s   @@r(   r  r    s*     !D.7J>; ;r3   r  )r   r   r    r!   )5r   sympy.concrete.summationsr   sympy.core.addr   sympy.core.exprr   sympy.core.functionr   r   sympy.core.mulr   sympy.core.relationalr   sympy.core.singletonr	   sympy.core.symbolr
   sympy.integrals.integralsr   sympy.logic.boolalgr   sympy.core.parametersr   sympy.core.sortingr   sympy.core.sympifyr   r   r   sympy.statsr   r   sympy.stats.rvr   r   r   r   r   r   r   r   r   r   __all__registerr2   r   r   r    r!   r   r  r5   r3   r(   <module>r3     s     )    1  $ " $ . # 3 / ' , ' ,@ @ @ C D, , L! "`-$ `-F@%$ @%Dq-t q-hH- H-V7;T 7;t7;D 7;r3   