§
    PŠtjo6  ã                   ób  — d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ ddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( g d¢Z)dddœd„Z*dd„Z+dd„Z,e,Z-dd„Z.dd„Z/dd„Z0dddœd„Z1dd„Z2dd„Z3dd„Z4dd„Z5d d„Z6dd„Z7eZ8eZ9e.Z:dS )!é    )Ú	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_process)ÚPÚEÚHr   r   r   r   r   r   r   r   ÚvarianceÚstdÚskewnessÚkurtosisÚ
covariancer   ÚentropyÚmedianr   r   ÚcorrelationÚfactorial_momentÚmomentÚcmomentr   r   Úsmomentr   r!   NT)Úevaluatec                óž   — ddl m} |r  || |||¦  «                             ¦   «         S  || |||¦  «                             t          ¦  «        S )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
    r   )ÚMoment)Ú sympy.stats.symbolic_probabilityr3   ÚdoitÚrewriter   )ÚXÚnÚcÚ	conditionr1   Úkwargsr3   s          úV/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/stats/rv_interface.pyr.   r.      sd   € ð* 8Ð7Ð7Ð7Ð7Ð7Øð 1Øˆv�a˜˜A˜yÑ)Ô)×.Ò.Ñ0Ô0Ð0Øˆ6�!�Q˜˜9Ñ%Ô%×-Ò-­hÑ7Ô7Ð7ó    c                 ó    — t          | ¦  «        r1t          | ¦  «        t          ¦   «         k    rddlm}  || |¦  «        S t          | d|fi |¤ŽS )a�  
    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)
    r   )ÚVarianceé   )r    r   r   r4   r?   r/   )r7   r:   r;   r?   s       r<   r%   r%   5   sd   € õ. ��|„|ð &�˜q™	œ	¥V¡X¤XÒ-Ð-Ø=Ð=Ð=Ð=Ð=Ð=Øˆx˜˜9Ñ%Ô%Ð%å�1�a˜Ð-Ð- fÐ-Ð-Ð-r=   c                 ó8   — t          t          | |fi |¤Ž¦  «        S )aK  
    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
   r%   ©r7   r:   r;   s      r<   Ústandard_deviationrC   S   s$   € õ& •˜˜IÐ0Ð0¨Ð0Ð0Ñ1Ô1Ð1r=   c                 ó8  ‡— t          | |fi |¤Ž}|                     dt          d¦  «        ¦  «        Št          |t          ¦  «        r-t          ˆfd„|                     ¦   «         D ¦   «         ¦  «        S t          t           || ¦  «        ‰¦  «         ¦  «        S )am  
    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
    Úbr   c              3   ó@   •K  — | ]}| t          |‰¦  «        z  V — Œd S ©N)r	   )Ú.0ÚprobÚbases     €r<   ú	<genexpr>zentropy.<locals>.<genexpr>�   s2   øè è € ÐFÐF°˜�u�S  t™_œ_Ñ,ÐFÐFÐFÐFÐFÐFr=   )	r   Úgetr   Ú
isinstanceÚdictÚsumÚvaluesr   r	   )Úexprr:   r;   ÚpdfrJ   s       @r<   r*   r*   i   s—   ø€ õH �$˜	Ð
,Ð
, VÐ
,Ð
,€CØ�:Š:�c�3˜q™6œ6Ñ"Ô"€DÝ�#•tÑÔð GÝÐFÐFÐFÐF¸¿º¹¼ÐFÑFÔFÑFÔFÐFÝ�˜C˜C ™IœI tÑ,Ô,Ð,Ñ-Ô-Ð-r=   c           	      ó>  — t          | ¦  «        rt          | ¦  «        t          ¦   «         k    s.t          |¦  «        r2t          |¦  «        t          ¦   «         k    rddlm}  || ||¦  «        S t          | t          | |fi |¤Žz
  |t          ||fi |¤Žz
  z  |fi |¤ŽS )aE  
    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
    r   )Ú
Covariance)r    r   r   r4   rT   r   )r7   ÚYr:   r;   rT   s        r<   r)   r)   “   sË   € õ: 	�!‰Œð +� ™œ¥f¡h¤hÒ.Ð.µI¸a±L´LÐ.ÅVÈAÁYÄYÕRXÑRZÔRZÒEZÐEZØ?Ð?Ð?Ð?Ð?Ð?Øˆz˜!˜Q 	Ñ*Ô*Ð*åØ	
�[˜˜IÐ0Ð0¨Ð0Ð0Ñ	0Ø	
�[˜˜IÐ0Ð0¨Ð0Ð0Ñ	0ñ	2àðð ð ðð ð r=   c                 ó\   — t          | ||fi |¤Žt          | |fi |¤Žt          ||fi |¤Žz  z  S )a¹  
    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))
    )r)   r&   )r7   rU   r:   r;   s       r<   r,   r,   º   sS   € õ> �a˜˜IÐ0Ð0¨Ð0Ð0µ#°a¸Ð2MÐ2MÀfÐ2MÐ2MÝ
ˆ1ˆiÐ"Ð"˜6Ð"Ð"ñ3#ñ $ð $r=   c                óš   — ddl m} |r || ||¦  «                             ¦   «         S  || ||¦  «                             t          ¦  «        S )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
    r   )ÚCentralMoment)r4   rX   r5   r6   r   )r7   r8   r:   r1   r;   rX   s         r<   r/   r/   Ý   s`   € ð& ?Ð>Ð>Ð>Ð>Ð>Øð 5Øˆ}˜Q  9Ñ-Ô-×2Ò2Ñ4Ô4Ð4Øˆ=˜˜A˜yÑ)Ô)×1Ò1µ(Ñ;Ô;Ð;r=   c                 óN   — t          | |fi |¤Ž}d|z  |z  t          | ||fi |¤Žz  S )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
    r   )r&   r/   )r7   r8   r:   r;   Úsigmas        r<   r0   r0   ö   sB   € õ* ��9Ð'Ð' Ð'Ð'€EØˆe‰G�a‰<�  1 iÐ:Ð:°6Ð:Ð:Ñ:Ð:r=   c                 ó"   — t          | dfd|i|¤ŽS )aA  
    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:   ©r0   rB   s      r<   r'   r'     s"   € õF �1�aÐ7Ð7 9Ð7°Ð7Ð7Ð7r=   c                 ó"   — t          | dfd|i|¤ŽS )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:   r]   rB   s      r<   r(   r(   3  s"   € õT �1�aÐ7Ð7 9Ð7°Ð7Ð7Ð7r=   c                 ó<   — t          t          | |¦  «        fd|i|¤ŽS )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   )r7   r8   r:   r;   s       r<   r-   r-   `  s+   € õJ Õ'¨¨1Ñ-Ô-ÐMÐM¸ÐMÀfÐMÐMÐMr=   c           	      óx  — t          | ¦  «        s| S ddlm} ddlm} ddlm} t          t          | ¦  «        |¦  «        r³t          | ¦  «         	                    | ¦  «        }g } |j
        ¦   «         D ]v\  }}	|	t          dd¦  «        k    r]d|	z
  t          | ¦  «                             t          | |¦  «        ¦  «        z   t          dd¦  «        k    r|                     |¦  «         Œwt          |Ž S t          t          | ¦  «        ||f¦  «        r}t          | ¦  «         	                    | ¦  «        }t!          d¦  «        }
t#          t%           ||
¦  «        t          dd¦  «        z
  ¦  «        |
t          | ¦  «        j        ¦  «        }|S t)          dt+          t          | ¦  «        ¦  «        z  ¦  «        ‚)	aM  
    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

    r   )ÚContinuousPSpace)ÚDiscretePSpace)ÚFinitePSpacer   r@   Úxz$The median of %s is not implemented.)r    Úsympy.stats.crvrb   Úsympy.stats.drvrc   Úsympy.stats.frvrd   rM   r   Úcompute_cdfÚitemsr   r   r   Úappendr   r   r   r   ÚsetÚNotImplementedErrorÚstr)r7   r1   r;   rb   rc   rd   r   ÚresultÚkeyÚvaluere   s              r<   r+   r+   ‡  s¯  € õR �Q‰<Œ<ð Øˆà0Ð0Ð0Ð0Ð0Ð0Ø.Ð.Ð.Ð.Ð.Ð.Ø,Ð,Ð,Ð,Ð,Ð,å•&˜‘)”)˜\Ñ*Ô*ð "Ý�Q‰iŒi×#Ò# AÑ&Ô&ˆØˆØ#˜#œ)™+œ+ð 	#ð 	#‰JˆC�Ø•x  1‘~”~Ò%Ð%¨1¨u©9Ý�1‰IŒI×!Ò!¥" Q¨¡*¤*Ñ-Ô-ñ+.Ý19¸!¸Q±´ò+@ð +@à—’˜cÑ"Ô"Ð"øÝ˜&Ð!Ð!Ý•&˜‘)”)Ð.°Ð?Ñ@Ô@ð Ý�Q‰iŒi×#Ò# AÑ&Ô&ˆÝ�#‰JŒJˆÝ�.¨¨¨Q©¬µ(¸1¸a±.´.Ñ)@ÑAÔAÀ1ÅfÈQÁiÄiÄmÑTÔTˆØˆÝ
ÐDÅSÍÐPQÉÌÁ^Ä^ÑSÑ
TÔ
TÐTr=   c           	      óæ   — t          | t          | |fi |¤Žz
  |t          ||fi |¤Žz
  z  |t          ||fi |¤Žz
  z  |fi |¤Ž}t          | |fi |¤Žt          ||fi |¤Žz  t          ||fi |¤Žz  }||z  S )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   r&   )r7   rU   ÚZr:   r;   ÚnumÚdens          r<   Ú
coskewnessrv   Ç  sÒ   € õl �q�; q¨)Ð>Ð>°vÐ>Ð>Ñ>Ø•˜A˜yÐ3Ð3¨FÐ3Ð3Ñ3ñ5à•˜A˜yÐ3Ð3¨FÐ3Ð3Ñ3ñ5à6?ðKð KàCIðKð K€Cõ ˆa�Ð
%Ð
%˜fÐ
%Ð
%­¨A¨yÐ(CÐ(C¸FÐ(CÐ(CÑ
CÝˆq�)Ð&Ð&˜vÐ&Ð&ñ'€Càˆs‰7€Nr=   )r   NrG   )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.   r%   rC   r&   r*   r)   r,   r/   r0   r'   r(   r-   r+   rv   r"   r#   r$   © r=   r<   ú<module>r„      sê  ðØ  Ð  Ð  Ð  Ð  Ð  Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø $Ð $Ð $Ð $Ð $Ð $Ø #Ð #Ð #Ð #Ð #Ð #Ø EÐ EÐ EÐ EÐ EÐ EØ =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø .Ð .Ð .Ð .Ð .Ð .Ø +Ð +Ð +Ð +Ð +Ð +ð,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð ,ð<ð <ð <€ð8°$ð 8ð 8ð 8ð 8ð 8ð6.ð .ð .ð .ð<2ð 2ð 2ð 2ð( €ð(.ð (.ð (.ð (.ðT$ð $ð $ð $ðN $ð  $ð  $ð  $ðF<¨dð <ð <ð <ð <ð <ð2;ð ;ð ;ð ;ð0#8ð #8ð #8ð #8ðJ*8ð *8ð *8ð *8ðZ%Nð %Nð %Nð %NðN=Uð =Uð =Uð =Uð@;ð ;ð ;ð ;ð| €Ø€Ø€€€r=   