+
    io6                        ^ 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 ^ RIHt ^ R	IHt ^ R
IHt ^RIHtHtHtHtHtHtHtHtHtHtH t H!t!H"t"H#t#H$t$H%t%H&t&H't'H(t( . ROt)RRR/R llt*RR lt+RR lt,],t-RR lt.RR lt/RR lt0RRR/R llt1RR lt2RR lt3RR lt4RR lt5RR lt6RR lt7]t8]t9].t:R# )     )	FiniteSet)Rational)Eq)Dummy)FallingFactorial)explog)sqrt)piecewise_fold)Integral)solveset)probabilityexpectationdensitywheregivenpspacecdfPSpacecharacteristic_functionsamplesample_iterrandom_symbolsindependent	dependentsampling_densitymoment_generating_functionquantile	is_randomsample_stochastic_processNevaluateTc                   ^ RI Hp V'       d   V! WW#4      P                  4       # V! WW#4      P                  \        4      # )a  
Return the nth moment of a random expression about c.

.. math::
    moment(X, c, n) = E((X-c)^{n})

Default value of c is 0.

Examples
========

>>> from sympy.stats import Die, moment, E
>>> X = Die('X', 6)
>>> moment(X, 1, 6)
-5/2
>>> moment(X, 2)
91/6
>>> moment(X, 1) == E(X)
True
)Moment) sympy.stats.symbolic_probabilityr#   doitrewriter   )Xnc	conditionr!   kwargsr#   s   &&&&$, x/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/stats/rv_interface.pymomentr-      s8    * 8aA)..00!%--h77    c                    \        V 4      '       d'   \        V 4      \        4       8X  d   ^ RIHp V! W4      # \        V ^V3/ VB # )aE  
Variance of a random expression.

.. math::
    variance(X) = E((X-E(X))^{2})

Examples
========

>>> from sympy.stats import Die, Bernoulli, variance
>>> from sympy import simplify, Symbol

>>> X = Die('X', 6)
>>> p = Symbol('p')
>>> B = Bernoulli('B', p, 1, 0)

>>> variance(2*X)
35/3

>>> simplify(variance(B))
p*(1 - p)
)Variance)r   r   r   r$   r0   cmoment)r'   r*   r+   r0   s   &&, r,   variancer2   5   s<    . ||q	VX-=%%1a-f--r.   c                ,    \        \        W3/ VB 4      # )a  
Standard Deviation of a random expression

.. math::
    std(X) = \sqrt(E((X-E(X))^{2}))

Examples
========

>>> from sympy.stats import Bernoulli, std
>>> from sympy import Symbol, simplify

>>> p = Symbol('p')
>>> B = Bernoulli('B', p, 1, 0)

>>> simplify(std(B))
sqrt(p*(1 - p))
)r
   r2   r'   r*   r+   s   &&,r,   standard_deviationr5   S   s    & 0011r.   c                   a \        W3/ VB pVP                  R\        ^4      4      o\        V\        4      '       d$   \        V3R lVP                  4        4       4      # \        \        V! V 4      S4      ) 4      # )a	  
Calculates entropy of a probability distribution.

Parameters
==========

expression : the random expression whose entropy is to be calculated
condition : optional, to specify conditions on random expression
b: base of the logarithm, optional
   By default, it is taken as Euler's number

Returns
=======

result : Entropy of the expression, a constant

Examples
========

>>> from sympy.stats import Normal, Die, entropy
>>> X = Normal('X', 0, 1)
>>> entropy(X)
log(2)/2 + 1/2 + log(pi)/2

>>> D = Die('D', 4)
>>> entropy(D)
log(4)

References
==========

.. [1] https://en.wikipedia.org/wiki/Entropy_%28information_theory%29
.. [2] https://www.crmarsh.com/static/pdf/Charles_Marsh_Continuous_Entropy.pdf
.. [3] https://kconrad.math.uconn.edu/blurbs/analysis/entropypost.pdf
bc              3   J   <"   T F  q) \        VS4      ,          x  K  	  R # 5iN)r	   ).0probbases   & r,   	<genexpr>entropy.<locals>.<genexpr>   s     FuSt_,,s    #)	r   getr   
isinstancedictsumvaluesr   r	   )exprr*   r+   pdfr<   s   &&, @r,   entropyrF   i   sf    H $
,V
,C::c3q6"D#tFFFFCIt,,--r.   c           	     0   \        V 4      '       d   \        V 4      \        4       8X  g*   \        V4      '       d(   \        V4      \        4       8X  d   ^ RIHp V! WV4      # \        V \        W3/ VB ,
          V\        W3/ VB ,
          ,          V3/ VB # )a  
Covariance of two random expressions.

Explanation
===========

The expectation that the two variables will rise and fall together

.. math::
    covariance(X,Y) = E((X-E(X)) (Y-E(Y)))

Examples
========

>>> from sympy.stats import Exponential, covariance
>>> from sympy import Symbol

>>> rate = Symbol('lambda', positive=True, real=True)
>>> X = Exponential('X', rate)
>>> Y = Exponential('Y', rate)

>>> covariance(X, X)
lambda**(-2)
>>> covariance(X, Y)
0
>>> covariance(X, Y + rate*X)
1/lambda
)
Covariance)r   r   r   r$   rH   r   )r'   Yr*   r+   rH   s   &&&, r,   
covariancerJ      s    : 	!fh.IaLLVAYRXRZEZ?!	**	
[00	0	
[00	0	2  r.   c                `    \        WV3/ VB \        W3/ VB \        W3/ VB ,          ,          # )aa  
Correlation of two random expressions, also known as correlation
coefficient or Pearson's correlation.

Explanation
===========

The normalized expectation that the two variables will rise
and fall together

.. math::
    correlation(X,Y) = E((X-E(X))(Y-E(Y)) / (\sigma_x  \sigma_y))

Examples
========

>>> from sympy.stats import Exponential, correlation
>>> from sympy import Symbol

>>> rate = Symbol('lambda', positive=True, real=True)
>>> X = Exponential('X', rate)
>>> Y = Exponential('Y', rate)

>>> correlation(X, X)
1
>>> correlation(X, Y)
0
>>> correlation(X, Y + rate*X)
1/sqrt(1 + lambda**(-2))
)rJ   std)r'   rI   r*   r+   s   &&&,r,   correlationrM      s;    > aI00#a2Mf2M
1"6"3# $ $r.   c                   ^ RI Hp V'       d   V! WV4      P                  4       # V! WV4      P                  \        4      # )a$  
Return the nth central moment of a random expression about its mean.

.. math::
    cmoment(X, n) = E((X - E(X))^{n})

Examples
========

>>> from sympy.stats import Die, cmoment, variance
>>> X = Die('X', 6)
>>> cmoment(X, 3)
0
>>> cmoment(X, 2)
35/12
>>> cmoment(X, 2) == variance(X)
True
)CentralMoment)r$   rO   r%   r&   r   )r'   r(   r*   r!   r+   rO   s   &&&$, r,   r1   r1      s8    & ?Q9-2244y)11(;;r.   c                ^    \        W3/ VB p^V,          V,          \        WV3/ VB ,          # )a  
Return the nth Standardized moment of a random expression.

.. math::
    smoment(X, n) = E(((X - \mu)/\sigma_X)^{n})

Examples
========

>>> from sympy.stats import skewness, Exponential, smoment
>>> from sympy import Symbol
>>> rate = Symbol('lambda', positive=True, real=True)
>>> Y = Exponential('Y', rate)
>>> smoment(Y, 4)
9
>>> smoment(Y, 4) == smoment(3*Y, 4)
True
>>> smoment(Y, 3) == skewness(Y)
True
)rL   r1   )r'   r(   r*   r+   sigmas   &&&, r,   smomentrR      s2    * ''EeGa<i:6:::r.   c                     \        V ^3RV/VB # )a  
Measure of the asymmetry of the probability distribution.

Explanation
===========

Positive skew indicates that most of the values lie to the right of
the mean.

.. math::
    skewness(X) = E(((X - E(X))/\sigma_X)^{3})

Parameters
==========

condition : Expr containing RandomSymbols
        A conditional expression. skewness(X, X>0) is skewness of X given X > 0

Examples
========

>>> from sympy.stats import skewness, Exponential, Normal
>>> from sympy import Symbol
>>> X = Normal('X', 0, 1)
>>> skewness(X)
0
>>> skewness(X, X > 0) # find skewness given X > 0
(-sqrt(2)/sqrt(pi) + 4*sqrt(2)/pi**(3/2))/(1 - 2/pi)**(3/2)

>>> rate = Symbol('lambda', positive=True, real=True)
>>> Y = Exponential('Y', rate)
>>> skewness(Y)
2
r*   rR   r4   s   &&,r,   skewnessrU     s    F 1a79777r.   c                     \        V ^3RV/VB # )a  
Characterizes the tails/outliers of a probability distribution.

Explanation
===========

Kurtosis of any univariate normal distribution is 3. Kurtosis less than
3 means that the distribution produces fewer and less extreme outliers
than the normal distribution.

.. math::
    kurtosis(X) = E(((X - E(X))/\sigma_X)^{4})

Parameters
==========

condition : Expr containing RandomSymbols
        A conditional expression. kurtosis(X, X>0) is kurtosis of X given X > 0

Examples
========

>>> from sympy.stats import kurtosis, Exponential, Normal
>>> from sympy import Symbol
>>> X = Normal('X', 0, 1)
>>> kurtosis(X)
3
>>> kurtosis(X, X > 0) # find kurtosis given X > 0
(-4/pi - 12/pi**2 + 3)/(1 - 2/pi)**2

>>> rate = Symbol('lamda', positive=True, real=True)
>>> Y = Exponential('Y', rate)
>>> kurtosis(Y)
9

References
==========

.. [1] https://en.wikipedia.org/wiki/Kurtosis
.. [2] https://mathworld.wolfram.com/Kurtosis.html
r*   rT   r4   s   &&,r,   kurtosisrW   3  s    T 1a79777r.   c                0    \        \        W4      3RV/VB # )a>  
The factorial moment is a mathematical quantity defined as the expectation
or average of the falling factorial of a random variable.

.. math::
    factorial-moment(X, n) = E(X(X - 1)(X - 2)...(X - n + 1))

Parameters
==========

n: A natural number, n-th factorial moment.

condition : Expr containing RandomSymbols
        A conditional expression.

Examples
========

>>> from sympy.stats import factorial_moment, Poisson, Binomial
>>> from sympy import Symbol, S
>>> lamda = Symbol('lamda')
>>> X = Poisson('X', lamda)
>>> factorial_moment(X, 2)
lamda**2
>>> Y = Binomial('Y', 2, S.Half)
>>> factorial_moment(Y, 2)
1/2
>>> factorial_moment(Y, 2, Y > 1) # find factorial moment for Y > 1
2

References
==========

.. [1] https://en.wikipedia.org/wiki/Factorial_moment
.. [2] https://mathworld.wolfram.com/FactorialMoment.html
r*   )r   r   )r'   r(   r*   r+   s   &&&,r,   factorial_momentrY   `  s     J '-MMfMMr.   c           	        \        V 4      '       g   V # ^ RIHp ^ RIHp ^ RIHp \        \        V 4      V4      '       d   \        V 4      P                  V 4      p. pVP                  ! 4        Fk  w  rV	\        ^^4      8  g   K  ^V	,
          \        V 4      P                  \        W4      4      ,           \        ^^4      8  g   KZ  VP                  V4       Km  	  \        V!  # \        \        V 4      W434      '       dh   \        V 4      P                  V 4      p\!        R4      p
\#        \%        V! V
4      \        ^^4      ,
          4      V
\        V 4      P&                  4      pV# \)        R\+        \        V 4      4      ,          4      h)a  
Calculates the median of the probability distribution.

Explanation
===========

Mathematically, median of Probability distribution is defined as all those
values of `m` for which the following condition is satisfied

.. math::
    P(X\leq m) \geq  \frac{1}{2} \text{ and} \text{ } P(X\geq m)\geq \frac{1}{2}

Parameters
==========

X: The random expression whose median is to be calculated.

Returns
=======

The FiniteSet or an Interval which contains the median of the
random expression.

Examples
========

>>> from sympy.stats import Normal, Die, median
>>> N = Normal('N', 3, 1)
>>> median(N)
{3}
>>> D = Die('D')
>>> median(D)
{3, 4}

References
==========

.. [1] https://en.wikipedia.org/wiki/Median#Probability_distributions

)ContinuousPSpace)DiscretePSpace)FinitePSpacexz$The median of %s is not implemented.)r   sympy.stats.crvr[   sympy.stats.drvr\   sympy.stats.frvr]   r@   r   compute_cdfitemsr   r   r   appendr   r   r   r   setNotImplementedErrorstr)r'   r!   r+   r[   r\   r]   r   resultkeyvaluer^   s   &&,        r,   medianrk     s*   R Q<<0.,&)\**Qi##A&))+JCx1~%1u91I!!"Q*-+.19!Q+@c" & &!!&).?@@Qi##A&#J.Q(1a.)@A1fQimmT
DSPQ^S
TTr.   c           	     
   \        V \        W3/ VB ,
          V\        W3/ VB ,
          ,          V\        W#3/ VB ,
          ,          V3/ VB p\        W3/ VB \        W3/ VB ,          \        W#3/ VB ,          pWV,          # )a  
Calculates the co-skewness of three random variables.

Explanation
===========

Mathematically Coskewness is defined as

.. math::
    coskewness(X,Y,Z)=\frac{E[(X-E[X]) * (Y-E[Y]) * (Z-E[Z])]} {\sigma_{X}\sigma_{Y}\sigma_{Z}}

Parameters
==========

X : RandomSymbol
        Random Variable used to calculate coskewness
Y : RandomSymbol
        Random Variable used to calculate coskewness
Z : RandomSymbol
        Random Variable used to calculate coskewness
condition : Expr containing RandomSymbols
        A conditional expression

Examples
========

>>> from sympy.stats import coskewness, Exponential, skewness
>>> from sympy import symbols
>>> p = symbols('p', positive=True)
>>> X = Exponential('X', p)
>>> Y = Exponential('Y', 2*p)
>>> coskewness(X, Y, Y)
0
>>> coskewness(X, Y + X, Y + 2*X)
16*sqrt(85)/85
>>> coskewness(X + 2*Y, Y + X, Y + 2*X, X > 3)
9*sqrt(170)/85
>>> coskewness(Y, Y, Y) == skewness(Y)
True
>>> coskewness(X, Y + p*X, Y + 2*p*X)
4/(sqrt(1 + 1/(4*p**2))*sqrt(4 + 1/(4*p**2)))

Returns
=======

coskewness : The coskewness of the three random variables

References
==========

.. [1] https://en.wikipedia.org/wiki/Coskewness

)r   rL   )r'   rI   Zr*   r+   numdens   &&&&,  r,   
coskewnessrp     s    l q;q>v>>A3F335A3F3356?KCIKC a
%f
%A(CF(C
Cq&v&'C7Nr.   )PEHr   r   r   r   r   r   r   r   r2   rL   rU   rW   rJ   r   rF   rk   r   r   rM   rY   r-   r1   r   r   rR   r   r    )r   Nr9   )T);
sympy.setsr   sympy.core.numbersr   sympy.core.relationalr   sympy.core.symbolr   (sympy.functions.combinatorial.factorialsr   &sympy.functions.elementary.exponentialr   r	   (sympy.functions.elementary.miscellaneousr
   $sympy.functions.elementary.piecewiser   sympy.integrals.integralsr   sympy.solvers.solvesetr   rvr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    __all__r-   r2   r5   rL   rF   rJ   rM   r1   rR   rU   rW   rY   rk   rp   rq   rr   rs    r.   r,   <module>r      s      ' $ # E = 9 ? . +, , , , , ,<8$ 86.<2( (.T$N $F<d <2;0#8J*8Z%NN=U@;| r.   