
    \hZ                        S SK r S SKJr  S SKJr  S SKJr  S SKJr	  S SK
Jr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJrJ r   S SK!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+  / SQr,\(RZ                  " \5      S 5       r.\(RZ                  " \"5      S 5       r. " S S\5      r/ " S S\5      r0 " S S\5      r1 " S S\5      r2 " S S\5      r3 " S  S!\5      r4g)"    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                     U R                   n[        U5      S:X  a  [        [        U5      5      U :X  a  g[	        S U 5       5      $ )N   Fc              3   8   #    U  H  n[        U5      v   M     g 7fN)r   ).0is     X/var/www/auris/envauris/lib/python3.13/site-packages/sympy/stats/symbolic_probability.py	<genexpr>_.<locals>.<genexpr>   s     +Uy||Us   )free_symbolslennextiterany)xatomss     r(   _r2      s:    NNE
5zQ4U,1+U+++    c                     g)NT )r0   s    r(   r2   r2       s    r3   c                   @    \ rS rSrSrSrS
S jrS rS
S jr\r	S r
S	rg)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                     [        U5      nUc  [        R                  " X5      nO"[        U5      n[        R                  " XU5      nX$l        U$ r%   )r   r   __new__
_condition)clsprob	conditionkwargsobjs        r(   r9   Probability.__new__@   sC    ~,,s)C +I,,s)4C"
r3   c                 ^  ^ U R                   S   nU R                  mUR                  SS5      nUR                  SS5      n[        U[        5      (       a?  [
        R                  U R                  UR                   S   TUS9R                  " S0 UD6-
  $ UR                  [        5      (       a  [        U5      R                  UTUS9$ [        T[        5      (       a  [        U5      n[        U5      S:X  a8  US   T:X  a/  SSKJn  U" U R                  U5      R                  " S0 UD6SS5      $ [%        U4S	 jU 5       5      (       a  ['        UT5      $ ['        U5      R                  5       $ Tb)  [        T[(        [*        45      (       d  [-        S
T-  5      eTS:X  d  U[
        R.                  L a  [
        R0                  $ [        U[(        [*        45      (       d  [-        S
U-  5      eU[
        R2                  L a  [
        R                  $ U(       a  [5        UTUS9$ Tb#  ['        [7        UT5      5      R                  5       $ [        U5      [9        5       :X  a  ['        UT5      $ [        U5      R                  U5      n[;        US5      (       a  U(       a  UR                  5       $ U$ )Nr   
numsamplesFevaluateTrC   r#   )BernoulliDistributionc              3   <   >#    U  H  n[        UT5      v   M     g 7f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)rB   doitr5   )argsr:   get
isinstancer   r	   OnefuncrJ   hasr   r   probabilityr   r   r,   sympy.stats.frv_typesrE   r/   r   r   r   
ValueErrorfalseZerotruer   r   r   hasattr)	selfhintsr=   rB   rC   condrvrE   resultrH   s	           @r(   rJ   Probability.doitJ   sj   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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                 :    U R                  XS9R                  SS9$ )Nr=   FrD   rO   rJ   rX   argr=   r>   s       r(   _eval_rewrite_as_Integral%Probability._eval_rewrite_as_Integral   s!    yyy2777GGr3   c                 H    U R                  [        5      R                  5       $ r%   rewriter   rJ   rX   s    r(   evaluate_integralProbability.evaluate_integral       ||H%**,,r3   r5   r%   )__name__
__module____qualname____firstlineno____doc__is_commutativer9   rJ   rb   _eval_rewrite_as_Sumrh   __static_attributes__r5   r3   r(   r   r   %   s,    0 N3jH 5-r3   r   c                   V    \ rS rSrSrSS jrS rS rS rSS jr	SS	 jr
\
rS
 r\rSrg)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                    [        U5      nUR                  (       a  SSKJn  U" X5      $ Uc)  [	        U5      (       d  U$ [
        R                  " X5      nO"[        U5      n[
        R                  " XU5      nX%l        U$ )Nr   )ExpectationMatrix)r   	is_Matrix-sympy.stats.symbolic_multivariate_probabilityrv   r   r   r9   r:   )r;   exprr=   r>   rv   r?   s         r(   r9   Expectation.__new__   sf    ~>>W$T55T??,,s)C +I,,s)4C"
r3   c                 4    U R                   S   R                  $ Nr   rK   rp   rg   s    r(   _eval_is_commutative Expectation._eval_is_commutative   s    yy|**+r3   c                   ^ U R                   S   nU R                  m[        U5      (       d  U$ [        U[        5      (       a*  [        R
                  " U4S jUR                    5       5      $ [        U5      n[        U[        5      (       a*  [        R
                  " U4S jUR                    5       5      $ [        U[        5      (       a  / n/ nUR                    H7  n[        U5      (       a  UR                  U5        M&  UR                  U5        M9     [        R
                  " U5      [        [        R
                  " U5      TS9-  $ U $ )Nr   c              3   T   >#    U  H  n[        UTS 9R                  5       v   M     g7fr^   Nr   r   r&   ar=   s     r(   r)   %Expectation.expand.<locals>.<genexpr>   s+       (& !,A C J J L L&   %(c              3   T   >#    U  H  n[        UTS 9R                  5       v   M     g7fr   r   r   s     r(   r)   r      s+       /- !,A C J J L L-r   r^   )
rK   r:   r   rM   r   fromiter_expandr   appendr   )rX   rY   ry   expand_exprrG   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           
      Z   UR                  SS5      nU R                  nU R                  S   nUR                  SS5      nUR                  SS5      nU(       a  UR                  " S0 UD6n[	        U5      (       a  [        U[        5      (       a  U$ U(       a  UR                  SS5      n[        XCXWS9$ UR                  [        5      (       a  [        U5      R                  XC5      $ Ub*  U R                  [        XC5      5      R                  " S0 UD6$ UR                  (       ah  [        UR                   Vs/ s HJ  n[        U[        5      (       d!  U R                  X5      R                  " S0 UD6OU R                  X5      PML     sn6 $ UR                   (       a  UR#                  [        5      (       a  U$ [        U5      [%        5       :X  a  U R                  U5      $ [        U5      R                  XFS	9n	['        U	S
5      (       a  U(       a  U	R                  " S0 UD6$ U	$ s  snf )NdeepTr   rB   FrC   evalf)rB   r   rD   rJ   r5   )rL   r:   rK   rJ   r   rM   r   r   rP   r   r   compute_expectationrO   r   is_Addr   is_Mulr1   r   rW   )
rX   rY   r   r=   ry   rB   rC   r   ra   r[   s
             r(   rJ   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           	         UR                  [        5      n[        U5      S:  a
  [        5       e[        U5      S:X  a  U$ UR	                  5       nUR
                  c  [        S5      eUR                  nUR                  S   R                  5       (       a$  [        UR                  R                  5       5      nO[        UR                  S-   5      nUR
                  R                  (       a  [        UR                  XV5      [        [!        XV5      U5      -  XeR
                  R"                  R$                  R&                  UR
                  R"                  R$                  R(                  45      $ UR
                  R*                  (       a  [        e[-        UR                  XV5      [        [!        XV5      U5      -  XeR
                  R"                  R$                  R&                  UR
                  R$                  R(                  45      $ )Nr#   r   zProbability space not known_1)r1   r   r,   NotImplementedErrorpopr   rS   symbolnameisupperr
   loweris_Continuousr   replacer   r   domainsetinfsup	is_Finiter   )rX   ra   r=   r>   rvsrG   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                 <    U R                  XS9R                  SUS9$ )Nr^   F)r   rC   r_   )rX   ra   r=   rC   r>   s        r(   rb   %Expectation._eval_rewrite_as_Integral@  s#    yyy277UX7VVr3   c                 H    U R                  [        5      R                  5       $ r%   re   rg   s    r(   rh   Expectation.evaluate_integralE  rj   r3   r5   r%   )NF)rk   rl   rm   rn   ro   r9   r~   r   rJ   r   rb   rq   rh   evaluate_sumrr   r5   r3   r(   r   r      s>    CJ,8(VR2W 5- %Lr3   r   c                   V    \ rS rSrSrSS jrS rS rSS jrSS jr	SS	 jr
\
rS
 rSrg)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                     [        U5      nUR                  (       a  SSKJn  U" X5      $ Uc  [        R
                  " X5      nO"[        U5      n[        R
                  " XU5      nX%l        U$ )Nr   )VarianceMatrix)r   rw   rx   r   r   r9   r:   )r;   ra   r=   r>   r   r?   s         r(   r9   Variance.__new__{  sX    sm==T!#11,,s(C +I,,s3C"
r3   c                 4    U R                   S   R                  $ r|   r}   rg   s    r(   r~   Variance._eval_is_commutative      yy|***r3   c           	      >  ^	 U R                   S   nU R                  m	[        U5      (       d  [        R                  $ [        U[        5      (       a  U $ [        U[        5      (       a{  / nUR                    H&  n[        U5      (       d  M  UR                  U5        M(     [        U	4S jU 5       6 nU	4S jn[        [        U[        R                  " US5      5      6 nXW-   $ [        U[        5      (       a  / n/ nUR                    H:  n[        U5      (       a  UR                  U5        M&  UR                  US-  5        M<     [        U5      S:X  a  [        R                  $ [        R                  " U5      [        [        R                  " U5      T	5      -  $ U $ )Nr   c              3   X   >#    U  H  n[        UT5      R                  5       v   M!     g 7fr%   )r    r   )r&   xvr=   s     r(   r)   "Variance.expand.<locals>.<genexpr>  s$     L2hr95<<>>s   '*c                 <   > S[        U ST06R                  5       -  $ )N   r=   )r!   r   )r0   r=   s    r(   <lambda>!Variance.expand.<locals>.<lambda>  s    Qz1'J	'J'Q'Q'S%Sr3   r   )rK   r:   r   r	   rU   rM   r   r   r   map	itertoolscombinationsr   r,   r   r    )
rX   rY   ra   rG   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                 D    [        US-  U5      n[        X5      S-  nXE-
  $ )Nr   r   )rX   ra   r=   r>   e1e2s         r(   _eval_rewrite_as_Expectation%Variance._eval_rewrite_as_Expectation  s(    S!VY/BS,a/B7Nr3   c                 R    U R                  [        5      R                  [        5      $ r%   rf   r   r   r`   s       r(   r   %Variance._eval_rewrite_as_Probability      ||K(00==r3   c                 F    [        U R                  S   U R                  SS9$ )Nr   FrD   )r   rK   r:   r`   s       r(   rb   "Variance._eval_rewrite_as_Integral  s    		!dooFFr3   c                 H    U R                  [        5      R                  5       $ r%   re   rg   s    r(   rh   Variance.evaluate_integral  rj   r3   r5   r%   )rk   rl   rm   rn   ro   r9   r~   r   r   r   rb   rq   rh   rr   r5   r3   r(   r    r    J  s5    /`+B
>G 5-r3   r    c                   v    \ rS rSrSrSS jrS rS r\S 5       r	\S 5       r
SS	 jrSS
 jrSS jr\rS rSrg)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                    [        U5      n[        U5      nUR                  (       d  UR                  (       a  SSKJn  U" XU5      $ UR	                  S[
        R                  5      (       a  [        X/[        S9u  pUc  [        R                  " XU5      nO"[        U5      n[        R                  " XX#5      nX6l        U$ )Nr   )CrossCovarianceMatrixrC   key)r   rw   rx   r   r   r   rC   sortedr   r   r9   r:   )r;   arg1arg2r=   r>   r   r?   s          r(   r9   Covariance.__new__  s    ~~>>T^^[(Y??::j"3"<"<==2BCJD,,s$/C +I,,s$:C"
r3   c                 4    U R                   S   R                  $ r|   r}   rg   s    r(   r~   Covariance._eval_is_commutative  r   r3   c                    U R                   S   nU R                   S   nU R                  nX#:X  a  [        X$5      R                  5       $ [	        U5      (       d  [
        R                  $ [	        U5      (       d  [
        R                  $ [        X#/[        S9u  p#[        U[        5      (       a!  [        U[        5      (       a  [        X#U5      $ U R                  UR                  5       5      nU R                  UR                  5       5      nU VVV	V
s/ s H.  u  pxU  H"  u  pXy-  [        [        X/[        S9SU06-  PM$     M0     nn	nnn
[        R                  " U5      $ s  sn
n	nnf )Nr   r#   r   r=   )rK   r:   r    r   r   r	   rU   r   r   rM   r   r!   _expand_single_argumentr   r   )rX   rY   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   5E%
c                    [        U[        5      (       a  [        R                  U4/$ [        U[        5      (       a  / nUR
                   Hm  n[        U[        5      (       a"  UR                  U R                  U5      5        M:  [        U5      (       d  ML  UR                  [        R                  U45        Mo     U$ [        U[        5      (       a  U R                  U5      /$ [        U5      (       a  [        R                  U4/$ g r%   )
rM   r   r	   rN   r   rK   r   r   _get_mul_nonrv_rv_tupler   )r;   ry   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                     / n/ nUR                    H7  n[        U5      (       a  UR                  U5        M&  UR                  U5        M9     [        R                  " U5      [        R                  " U5      4$ r%   )rK   r   r   r   r   )r;   mrG   r   r   s        r(   r   "Covariance._get_mul_nonrv_rv_tuple-  sX    A||		!Q	 
 U#S\\"%566r3   c                 T    [        X-  U5      n[        X5      [        X#5      -  nXV-
  $ r%   r   )rX   r   r   r=   r>   r   r   s          r(   r   'Covariance._eval_rewrite_as_Expectation8  s+    I.)+d*FFwr3   c                 R    U R                  [        5      R                  [        5      $ r%   r   rX   r   r   r=   r>   s        r(   r   'Covariance._eval_rewrite_as_Probability=  r   r3   c                 b    [        U R                  S   U R                  S   U R                  SS9$ )Nr   r#   FrD   )r   rK   r:   r   s        r(   rb   $Covariance._eval_rewrite_as_Integral@  s(    $))A,		!dooPUVVr3   c                 H    U R                  [        5      R                  5       $ r%   re   rg   s    r(   rh   Covariance.evaluate_integralE  rj   r3   r5   r%   )rk   rl   rm   rn   ro   r9   r~   r   classmethodr   r   r   r   rb   rq   rh   rr   r5   r3   r(   r!   r!     s\    *X&+%2 # #$ 7 7
>W 5-r3   r!   c                   T   ^  \ rS rSrSrS	U 4S jjrS rS	S jrS	S jrS	S jr	Sr
U =r$ )
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                    > [        U5      n[        U5      n[        U5      nUb  [        U5      n[        TU ]	  XX#U5      $ [        TU ]	  XX#5      $ r%   r   superr9   )r;   Xncr=   r>   	__class__s         r(   r9   Moment.__new__l  sR    QKQKQK  +I7?31;;7?3100r3   c                 L    U R                  [        5      R                  " S0 UD6$ Nr5   rf   r   rJ   rX   rY   s     r(   rJ   Moment.doitv      ||K(--666r3   c                 $    [        X-
  U-  U5      $ r%   r   rX   r   r   r   r=   r>   s         r(   r   #Moment._eval_rewrite_as_Expectationy  s    AEA:y11r3   c                 R    U R                  [        5      R                  [        5      $ r%   r   r  s         r(   r   #Moment._eval_rewrite_as_Probability|  r   r3   c                 R    U R                  [        5      R                  [        5      $ r%   rf   r   r   r  s         r(   rb    Moment._eval_rewrite_as_Integral      ||K(00::r3   r5   )r   Nrk   rl   rm   rn   ro   r9   rJ   r   r   rb   rr   __classcell__r   s   @r(   r   r   I  s'    !D172>; ;r3   r   c                   T   ^  \ rS rSrSrS	U 4S jjrS rS	S jrS	S jrS	S jr	Sr
U =r$ )
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                    > [        U5      n[        U5      nUb  [        U5      n[        TU ]	  XX#5      $ [        TU ]	  XU5      $ r%   r   )r;   r   r   r=   r>   r   s        r(   r9   CentralMoment.__new__  sG    QKQK  +I7?31887?31--r3   c                 L    U R                  [        5      R                  " S0 UD6$ r  r  r  s     r(   rJ   CentralMoment.doit  r  r3   c                 Z    [        X40 UD6n[        XXS40 UD6R                  [         5      $ r%   )r   r   rf   )rX   r   r   r=   r>   mus         r(   r   *CentralMoment._eval_rewrite_as_Expectation  s.    00aB4V4<<[IIr3   c                 R    U R                  [        5      R                  [        5      $ r%   r   rX   r   r   r=   r>   s        r(   r   *CentralMoment._eval_rewrite_as_Probability  r   r3   c                 R    U R                  [        5      R                  [        5      $ r%   r  r  s        r(   rb   'CentralMoment._eval_rewrite_as_Integral  r  r3   r5   r%   r  r  s   @r(   r  r    s(    !D.7J>; ;r3   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>r1     s     )    1  $ " $ . # 3 / ' , ' ,@ @ @ C D, , L! "`-$ `-F@%$ @%Dq-t q-hH- H-V7;T 7;t7;D 7;r3   