o
    *ήc%                    @   s  d Z ddlmZ ddlmZmZmZmZ ddlm	Z	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 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#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.m/Z/m0Z0 ddl1m2Z2 ddlm3Z3 ddl4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZC ddlDmEZE ddlFmGZG ddlHmIZImJZJ ddlKmLZLmMZM ejNZOg dZPeMQeGd d! ZRd"d# ZSG d$d% d%eJZTeEeO eOfd&d'ZUG d(d) d)eJZVdd+d,ZWG d-d. d.eJZXd/d0 ZYG d1d2 d2eJZZd3d4 Z[G d5d6 d6eJZ\d7d8 Z]G d9d: d:eJZ^d;d< Z_G d=d> d>eJZ`d?d@ ZaG dAdB dBeJZbdCdD ZcG dEdF dFeJZddGdH ZeG dIdJ dJeJZfdKdL ZgG dMdN dNeJZhdOdP ZiG dQdR dReJZjdSdT ZkdUdV ZlG dWdX dXeJZmdYdZ ZnG d[d\ d\eJZod]d^ ZpG d_d` d`eJZqdadb ZrG dcdd ddeJZsdedf ZtG dgdh dheJZudidj ZvG dkdl dleJZwddmdnZxG dodp dpeJZydqdr ZzG dsdt dteJZ{dudv Z|G dwdx dxeJZ}ddzd{Z~G d|d} d}eJZd~d ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZeZG dd deJZdd ZG dd deJZdd ZG dd deJZddÄ ZG ddń deJZddǄ ZG ddɄ deJZdd˄ ZG dd̈́ deJZddτ ZG ddф deJZddӄ ZG ddՄ deJZddׄ ZG ddل deJZddۄ ZG dd݄ deJZdd߄ ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZG dd deJZdd ZdS )a6  
Continuous Random Variables - Prebuilt variables

Contains
========
Arcsin
Benini
Beta
BetaNoncentral
BetaPrime
BoundedPareto
Cauchy
Chi
ChiNoncentral
ChiSquared
Dagum
Erlang
ExGaussian
Exponential
ExponentialPower
FDistribution
FisherZ
Frechet
Gamma
GammaInverse
Gumbel
Gompertz
Kumaraswamy
Laplace
Levy
LogCauchy
Logistic
LogLogistic
LogitNormal
LogNormal
Lomax
Maxwell
Moyal
Nakagami
Normal
Pareto
PowerFunction
QuadraticU
RaisedCosine
Rayleigh
Reciprocal
ShiftedGompertz
StudentT
Trapezoidal
Triangular
Uniform
UniformSum
VonMises
Wald
Weibull
WignerSemicircle
    )exp)atancossintan)besselibesseljbesselk)beta)Sum)Basic)Lambda)IRationalpi)EqNe)S)Dummy)sympify)binomial	factorial)Abssignlog)sinh)floor)sqrtMaxMin)	Piecewise)asin)erferfcerfierfinvexpint)gamma
lowergamma
uppergamma)hyper)	integrate)And)Interval)
MatrixBase)SingleContinuousPSpaceSingleContinuousDistribution)_value_check	is_random)5ContinuousRVArcsinBeniniBetaBetaNoncentral	BetaPrimeBoundedParetoCauchyChiChiNoncentral
ChiSquaredDagumErlang
ExGaussianExponentialExponentialPowerFDistributionFisherZFrechetGammaGammaInverseGompertzGumbelKumaraswamyLaplaceLevy	LogCauchyLogisticLogLogisticLogitNormal	LogNormalLomaxMaxwellMoyalNakagamiNormalGaussianInverseParetoPowerFunction
QuadraticURaisedCosineRayleigh
ReciprocalStudentTShiftedGompertzTrapezoidal
TriangularUniform
UniformSumVonMisesWaldWeibullWignerSemicirclec                 C   s   t dd | D S )Nc                 s       | ]}t |V  qd S Nr3   ).0i rn   </tmp/pip-target-vg8gfxp4/lib/python/sympy/stats/crv_types.py	<genexpr>       z_.<locals>.<genexpr>)any)xrn   rn   ro   _      rt   c                 K   sl   t tt|}|| }|ddr|j|  t| |}tdd |D r3ddlm}m	} || ||}|j
S )NcheckTc                 s   ri   rj   rk   )rl   argrn   rn   ro   rp      rq   zrv.<locals>.<genexpr>r   )CompoundPSpaceCompoundDistribution)listmapr   poprv   r0   rr   sympy.stats.compound_rvrx   ry   value)symbolclsargskwargsdistpspacerx   ry   rn   rn   ro   rv   s   

r   c                   @   s<   e Zd ZdZee efddZedd Ze	dd Z
dS )	ContinuousDistributionHandmade)pdfc                 C   s   t | ||S rj   )r   __new__)r   r   setrn   rn   ro   r      s   z&ContinuousDistributionHandmade.__new__c                 C   s
   | j d S N   )r   selfrn   rn   ro   r         
z"ContinuousDistributionHandmade.setc                 C   s4   t d}t| |||f}tt|dtjkd d S )Nrs   r   z&The pdf on the given set is incorrect.)r   r,   r2   r   r   false)r   r   rs   valrn   rn   ro   rv      s   z$ContinuousDistributionHandmade.checkN)__name__
__module____qualname__	_argnamesr.   oor   propertyr   staticmethodrv   rn   rn   rn   ro   r      s    
r   c                 K   sH   t ||| fd}t| |}|dd|d< t| jt||ffi |S )a  
    Create a Continuous Random Variable given the following:

    Parameters
    ==========

    symbol : Symbol
        Represents name of the random variable.
    density : Expression containing symbol
        Represents probability density function.
    set : set/Interval
        Represents the region where the pdf is valid, by default is real line.
    check : bool
        If True, it will check whether the given density
        integrates to 1 over the given set. If False, it
        will not perform this check. Default is False.


    Returns
    =======

    RandomSymbol

    Many common continuous random variable types are already implemented.
    This function should be necessary only very rarely.


    Examples
    ========

    >>> from sympy import Symbol, sqrt, exp, pi
    >>> from sympy.stats import ContinuousRV, P, E

    >>> x = Symbol("x")

    >>> pdf = sqrt(2)*exp(-x**2/2)/(2*sqrt(pi)) # Normal distribution
    >>> X = ContinuousRV(x, pdf)

    >>> E(X)
    0
    >>> P(X>0)
    1/2
    r   Trv   F)r!   as_relationalr   r|   r   namer   )r   densityr   r   r   rn   rn   ro   r4      s   ,
r4   c                   @   s,   e Zd ZdZedd Zdd Zdd ZdS )	ArcsinDistributionabc                 C      t | j| jS rj   r.   r   r   r   rn   rn   ro   r         zArcsinDistribution.setc                 C   s*   | j | j}}dtt|| ||    S r   )r   r   r   r   r   rs   r   r   rn   rn   ro   r         zArcsinDistribution.pdfc                 C   sN   | j | j}}ttj||k fdtt|| ||   t ||kftjdfS N   T)	r   r   r!   r   Zeror"   r   r   Oner   rn   rn   ro   _cdf   s   &zArcsinDistribution._cdfN)r   r   r   r   r   r   r   r   rn   rn   rn   ro   r      s    
r   r   c                 C      t | t||fS )a  
    Create a Continuous Random Variable with an arcsin distribution.

    The density of the arcsin distribution is given by

    .. math::
        f(x) := \frac{1}{\pi\sqrt{(x-a)(b-x)}}

    with :math:`x \in (a,b)`. It must hold that :math:`-\infty < a < b < \infty`.

    Parameters
    ==========

    a : Real number, the left interval boundary
    b : Real number, the right interval boundary

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Arcsin, density, cdf
    >>> from sympy import Symbol

    >>> a = Symbol("a", real=True)
    >>> b = Symbol("b", real=True)
    >>> z = Symbol("z")

    >>> X = Arcsin("x", a, b)

    >>> density(X)(z)
    1/(pi*sqrt((-a + z)*(b - z)))

    >>> cdf(X)(z)
    Piecewise((0, a > z),
            (2*asin(sqrt((-a + z)/(-a + b)))/pi, b >= z),
            (1, True))


    References
    ==========

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

    )r   r   r   r   r   rn   rn   ro   r5        2r5   c                   @   s8   e Zd ZdZedd Zedd Zdd Zdd	 Z	d
S )BeniniDistributionalphar
   sigmac                 C   .   t | dkd t |dkd t |dkd d S )Nr   'Shape parameter Alpha must be positive.&Shape parameter Beta must be positive.z'Scale parameter Sigma must be positive.r2   r   rn   rn   ro   rv   >     zBeniniDistribution.checkc                 C      t | jtS rj   )r.   r   r   r   rn   rn   ro   r   D     zBeniniDistribution.setc                 C   s`   | j | j| j}}}t| t||  |t|| d   || d| t||  |   S Nr   )r   r
   r   r   r   )r   rs   r   r
   r   rn   rn   ro   r   H  s   (zBeniniDistribution.pdfc                 C      t d)NzIThe moment generating function of the Benini distribution does not exist.NotImplementedErrorr   trn   rn   ro   _moment_generating_functionM     z.BeniniDistribution._moment_generating_functionN)
r   r   r   r   r   rv   r   r   r   r   rn   rn   rn   ro   r   ;  s    

r   c                 C      t | t|||fS )aW  
    Create a Continuous Random Variable with a Benini distribution.

    The density of the Benini distribution is given by

    .. math::
        f(x) := e^{-\alpha\log{\frac{x}{\sigma}}
                -\beta\log^2\left[{\frac{x}{\sigma}}\right]}
                \left(\frac{\alpha}{x}+\frac{2\beta\log{\frac{x}{\sigma}}}{x}\right)

    This is a heavy-tailed distribution and is also known as the log-Rayleigh
    distribution.

    Parameters
    ==========

    alpha : Real number, `\alpha > 0`, a shape
    beta : Real number, `\beta > 0`, a shape
    sigma : Real number, `\sigma > 0`, a scale

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Benini, density, cdf
    >>> from sympy import Symbol, pprint

    >>> alpha = Symbol("alpha", positive=True)
    >>> beta = Symbol("beta", positive=True)
    >>> sigma = Symbol("sigma", positive=True)
    >>> z = Symbol("z")

    >>> X = Benini("x", alpha, beta, sigma)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
    /                  /  z  \\             /  z  \            2/  z  \
    |        2*beta*log|-----||  - alpha*log|-----| - beta*log  |-----|
    |alpha             \sigma/|             \sigma/             \sigma/
    |----- + -----------------|*e
    \  z             z        /

    >>> cdf(X)(z)
    Piecewise((1 - exp(-alpha*log(z/sigma) - beta*log(z/sigma)**2), sigma <= z),
            (0, True))


    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Benini_distribution
    .. [2] http://reference.wolfram.com/legacy/v8/ref/BeniniDistribution.html

    )r   r   )r   r   r
   r   rn   rn   ro   r6   Q  s   <r6   c                   @   s>   e Zd ZdZeddZedd Zdd Zdd	 Z	d
d Z
dS )BetaDistributionr   r
   r   r   c                 C       t | dkd t |dkd d S Nr   r   r   r   r   rn   rn   ro   rv        zBetaDistribution.checkc                 C   s4   | j | j}}||d  d| |d   t|| S r   r   r
   beta_fnr   rs   r   r
   rn   rn   ro   r        &zBetaDistribution.pdfc                 C   s   t | jf| j| j ft| S rj   )r+   r   r
   r   r   rn   rn   ro   _characteristic_function     z)BetaDistribution._characteristic_functionc                 C   s   t | jf| j| j f|S rj   )r+   r   r
   r   rn   rn   ro   r        z,BetaDistribution._moment_generating_functionN)r   r   r   r   r.   r   r   rv   r   r   r   rn   rn   rn   ro   r     s    

r   c                 C   r   )a  
    Create a Continuous Random Variable with a Beta distribution.

    The density of the Beta distribution is given by

    .. math::
        f(x) := \frac{x^{\alpha-1}(1-x)^{\beta-1}} {\mathrm{B}(\alpha,\beta)}

    with :math:`x \in [0,1]`.

    Parameters
    ==========

    alpha : Real number, `\alpha > 0`, a shape
    beta : Real number, `\beta > 0`, a shape

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Beta, density, E, variance
    >>> from sympy import Symbol, simplify, pprint, factor

    >>> alpha = Symbol("alpha", positive=True)
    >>> beta = Symbol("beta", positive=True)
    >>> z = Symbol("z")

    >>> X = Beta("x", alpha, beta)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
     alpha - 1        beta - 1
    z         *(1 - z)
    --------------------------
          B(alpha, beta)

    >>> simplify(E(X))
    alpha/(alpha + beta)

    >>> factor(simplify(variance(X)))
    alpha*beta/((alpha + beta)**2*(alpha + beta + 1))

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Beta_distribution
    .. [2] http://mathworld.wolfram.com/BetaDistribution.html

    )r   r   r   r   r
   rn   rn   ro   r7        7r7   c                   @   s.   e Zd ZdZeddZedd Zdd ZdS )	BetaNoncentralDistributionr   r
   lamdar   r   c                 C   s.   t | dkd t |dkd t |dkd d S )Nr   r   r   z/Noncentrality parameter Lambda must be positiver   r   rn   rn   ro   rv     r   z BetaNoncentralDistribution.checkc                 C   sz   | j | j| j}}}td}tt| d |d |  ||| d   d| |d   t|t|| |  |dtfS )Nkr   r   r   )	r   r
   r   r   r   r   r   r   r   )r   rs   r   r
   r   r   rn   rn   ro   r     s   *zBetaNoncentralDistribution.pdfN)	r   r   r   r   r.   r   r   rv   r   rn   rn   rn   ro   r     s    

r   c                 C   r   )at  
    Create a Continuous Random Variable with a Type I Noncentral Beta distribution.

    The density of the Noncentral Beta distribution is given by

    .. math::
        f(x) := \sum_{k=0}^\infty e^{-\lambda/2}\frac{(\lambda/2)^k}{k!}
                \frac{x^{\alpha+k-1}(1-x)^{\beta-1}}{\mathrm{B}(\alpha+k,\beta)}

    with :math:`x \in [0,1]`.

    Parameters
    ==========

    alpha : Real number, `\alpha > 0`, a shape
    beta : Real number, `\beta > 0`, a shape
    lamda : Real number, `\lambda \geq 0`, noncentrality parameter

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import BetaNoncentral, density, cdf
    >>> from sympy import Symbol, pprint

    >>> alpha = Symbol("alpha", positive=True)
    >>> beta = Symbol("beta", positive=True)
    >>> lamda = Symbol("lamda", nonnegative=True)
    >>> z = Symbol("z")

    >>> X = BetaNoncentral("x", alpha, beta, lamda)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
      oo
    _____
    \    `
     \                                              -lamda
      \                          k                  -------
       \    k + alpha - 1 /lamda\         beta - 1     2
        )  z             *|-----| *(1 - z)        *e
       /                  \  2  /
      /    ------------------------------------------------
     /                  B(k + alpha, beta)*k!
    /____,
    k = 0

    Compute cdf with specific 'x', 'alpha', 'beta' and 'lamda' values as follows:

    >>> cdf(BetaNoncentral("x", 1, 1, 1), evaluate=False)(2).doit()
    2*exp(1/2)

    The argument evaluate=False prevents an attempt at evaluation
    of the sum for general x, before the argument 2 is passed.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Noncentral_beta_distribution
    .. [2] https://reference.wolfram.com/language/ref/NoncentralBetaDistribution.html

    )r   r   )r   r   r
   r   rn   rn   ro   r8     s   Dr8   c                   @   .   e Zd ZdZedd ZedeZdd Z	dS )BetaPrimeDistributionr   c                 C   r   r   r   r   rn   rn   ro   rv   D  r   zBetaPrimeDistribution.checkr   c                 C   s6   | j | j}}||d  d| | |   t|| S r   r   r   rn   rn   ro   r   K     (zBetaPrimeDistribution.pdfN
r   r   r   r   r   rv   r.   r   r   r   rn   rn   rn   ro   r   A  s    

r   c                 C   r   )a  
    Create a continuous random variable with a Beta prime distribution.

    The density of the Beta prime distribution is given by

    .. math::
        f(x) := \frac{x^{\alpha-1} (1+x)^{-\alpha -\beta}}{B(\alpha,\beta)}

    with :math:`x > 0`.

    Parameters
    ==========

    alpha : Real number, `\alpha > 0`, a shape
    beta : Real number, `\beta > 0`, a shape

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import BetaPrime, density
    >>> from sympy import Symbol, pprint

    >>> alpha = Symbol("alpha", positive=True)
    >>> beta = Symbol("beta", positive=True)
    >>> z = Symbol("z")

    >>> X = BetaPrime("x", alpha, beta)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
     alpha - 1        -alpha - beta
    z         *(z + 1)
    -------------------------------
             B(alpha, beta)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Beta_prime_distribution
    .. [2] http://mathworld.wolfram.com/BetaPrimeDistribution.html

    )r   r   r   rn   rn   ro   r9   O     1r9   c                   @   0   e Zd ZdZedd Zedd Zdd ZdS )	BoundedParetoDistributionr   leftrightc                 C   r   rj   r.   r   r   r   rn   rn   ro   r     r   zBoundedParetoDistribution.setc                 C   s*   t | jd t |jd t ||kd d S )NzShape must be positive.zLeft value should be positive.z"Right should be greater than left.)r2   is_positiver   rn   rn   ro   rv     s   zBoundedParetoDistribution.checkc                 C   sH   | j | j| j}}}|||  || d   }d|| |  }|| S r   r   )r   rs   r   r   r   numdenrn   rn   ro   r     s   zBoundedParetoDistribution.pdfN	r   r   r   r   r   r   r   rv   r   rn   rn   rn   ro   r         

r   c                 C   r   )a-  
    Create a continuous random variable with a Bounded Pareto distribution.

    The density of the Bounded Pareto distribution is given by

    .. math::
        f(x) := \frac{\alpha L^{\alpha}x^{-\alpha-1}}{1-(\frac{L}{H})^{\alpha}}

    Parameters
    ==========

    alpha : Real Number, `\alpha > 0`
        Shape parameter
    left : Real Number, `left > 0`
        Location parameter
    right : Real Number, `right > left`
        Location parameter

    Examples
    ========

    >>> from sympy.stats import BoundedPareto, density, cdf, E
    >>> from sympy import symbols
    >>> L, H = symbols('L, H', positive=True)
    >>> X = BoundedPareto('X', 2, L, H)
    >>> x = symbols('x')
    >>> density(X)(x)
    2*L**2/(x**3*(1 - L**2/H**2))
    >>> cdf(X)(x)
    Piecewise((-H**2*L**2/(x**2*(H**2 - L**2)) + H**2/(H**2 - L**2), L <= x), (0, True))
    >>> E(X).simplify()
    2*H*L/(H + L)

    Returns
    =======

    RandomSymbol

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Pareto_distribution#Bounded_Pareto_distribution

    )r   r   )r   r   r   r   rn   rn   ro   r:     s   -r:   c                   @   D   e Zd ZdZedd Zdd Zdd Zdd	 Zd
d Z	dd Z
dS )CauchyDistributionx0r(   c                 C      t |dkd t | jd d S )Nr   'Scale parameter Gamma must be positive. Location parameter must be real.r2   is_realr   rn   rn   ro   rv        zCauchyDistribution.checkc                 C   s&   dt | j d|| j | j d    S Nr   r   )r   r(   r   r   rs   rn   rn   ro   r     s   &zCauchyDistribution.pdfc                 C   s,   | j | j}}dt t|| |  tj S r   )r   r(   r   r   r   Half)r   rs   r   r(   rn   rn   ro   r     s   zCauchyDistribution._cdfc                 C   s    t | jt | | jt|  S rj   )r   r   r   r(   r   r   rn   rn   ro   r     s    z+CauchyDistribution._characteristic_functionc                 C   r   )NzJThe moment generating function for the Cauchy distribution does not exist.r   r   rn   rn   ro   r     r   z.CauchyDistribution._moment_generating_functionc                 C   s   | j | jtt|tj    S rj   )r   r(   r   r   r   r   r   prn   rn   ro   	_quantile  r   zCauchyDistribution._quantileNr   r   r   r   r   rv   r   r   r   r   r   rn   rn   rn   ro   r     s    
r   c                 C   r   )aH  
    Create a continuous random variable with a Cauchy distribution.

    The density of the Cauchy distribution is given by

    .. math::
        f(x) := \frac{1}{\pi \gamma [1 + {(\frac{x-x_0}{\gamma})}^2]}

    Parameters
    ==========

    x0 : Real number, the location
    gamma : Real number, `\gamma > 0`, a scale

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Cauchy, density
    >>> from sympy import Symbol

    >>> x0 = Symbol("x0")
    >>> gamma = Symbol("gamma", positive=True)
    >>> z = Symbol("z")

    >>> X = Cauchy("x", x0, gamma)

    >>> density(X)(z)
    1/(pi*gamma*(1 + (-x0 + z)**2/gamma**2))

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Cauchy_distribution
    .. [2] http://mathworld.wolfram.com/CauchyDistribution.html

    )r   r   )r   r   r(   rn   rn   ro   r;     s   +r;   c                   @   s>   e Zd ZdZedd ZedeZdd Z	dd Z
d	d
 ZdS )ChiDistributionr   c                 C      t | dkd t | jd d S Nr   2Number of degrees of freedom (k) must be positive.4Number of degrees of freedom (k) must be an integer.r2   
is_integerr   rn   rn   ro   rv     r   zChiDistribution.checkr   c                 C   s@   dd| j d   || j d   t|d  d  t| j d  S Nr   r   )r   r   r(   r   rn   rn   ro   r     s   @zChiDistribution.pdfc                 C   s   | j }t|d ftjf|d  d }t| td t|d d  t|d  }t|d d ftddf|d  d }|||  S Nr   r      )r   r+   r   r   r   r   r(   r   r   r   r   part_1part_2part_3rn   rn   ro   r   "  s
    ,(z(ChiDistribution._characteristic_functionc                 C   s   | j }t|d ftjf|d d }|td t|d d  t|d  }t|d d ftdd f|d d }|||  S r   )r   r+   r   r   r   r(   r   rn   rn   ro   r   *  s
   ((z+ChiDistribution._moment_generating_functionN)r   r   r   r   r   rv   r.   r   r   r   r   r   rn   rn   rn   ro   r     s    

r   c                 C      t | t|fS )a]  
    Create a continuous random variable with a Chi distribution.

    The density of the Chi distribution is given by

    .. math::
        f(x) := \frac{2^{1-k/2}x^{k-1}e^{-x^2/2}}{\Gamma(k/2)}

    with :math:`x \geq 0`.

    Parameters
    ==========

    k : Positive integer, The number of degrees of freedom

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Chi, density, E
    >>> from sympy import Symbol, simplify

    >>> k = Symbol("k", integer=True)
    >>> z = Symbol("z")

    >>> X = Chi("x", k)

    >>> density(X)(z)
    2**(1 - k/2)*z**(k - 1)*exp(-z**2/2)/gamma(k/2)

    >>> simplify(E(X))
    sqrt(2)*gamma(k/2 + 1/2)/gamma(k/2)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Chi_distribution
    .. [2] http://mathworld.wolfram.com/ChiDistribution.html

    )r   r   r   r   rn   rn   ro   r<   2  s   .r<   c                   @   r   )ChiNoncentralDistributionr   lc                 C   s,   t | dkd t | jd t |dkd d S )Nr   r   r   z(Shift parameter Lambda must be positive.r   r  rn   rn   ro   rv   i  s   zChiNoncentralDistribution.checkr   c                 C   sZ   | j | j}}t|d |d   d ||  | || |d   t|d d ||  S r   )r   r  r   r   )r   rs   r   r  rn   rn   ro   r   q  s   LzChiNoncentralDistribution.pdfNr   rn   rn   rn   ro   r  f  s    

r  c                 C   r   )a0  
    Create a continuous random variable with a non-central Chi distribution.

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

    The density of the non-central Chi distribution is given by

    .. math::
        f(x) := \frac{e^{-(x^2+\lambda^2)/2} x^k\lambda}
                {(\lambda x)^{k/2}} I_{k/2-1}(\lambda x)

    with `x \geq 0`. Here, `I_\nu (x)` is the
    :ref:`modified Bessel function of the first kind <besseli>`.

    Parameters
    ==========

    k : A positive Integer, $k > 0$
        The number of degrees of freedom.
    lambda : Real number, `\lambda > 0`
        Shift parameter.

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import ChiNoncentral, density
    >>> from sympy import Symbol

    >>> k = Symbol("k", integer=True)
    >>> l = Symbol("l")
    >>> z = Symbol("z")

    >>> X = ChiNoncentral("x", k, l)

    >>> density(X)(z)
    l*z**k*exp(-l**2/2 - z**2/2)*besseli(k/2 - 1, l*z)/(l*z)**(k/2)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Noncentral_chi_distribution
    )r   r  r   r   r  rn   rn   ro   r=   u  r   r=   c                   @   sF   e Zd ZdZedd ZedeZdd Z	dd Z
d	d
 Zdd ZdS )ChiSquaredDistributionr   c                 C   r   r   r   r   rn   rn   ro   rv     r   zChiSquaredDistribution.checkr   c                 C   s@   | j }dd|d  t|d   ||d d   t| d  S r   )r   r(   r   r   rs   r   rn   rn   ro   r        :zChiSquaredDistribution.pdfc                 C   s8   | j }ttjt|d  t|d |d  |dkfdS )Nr   r   r   )r   r!   r   r   r(   r)   r
  rn   rn   ro   r     s
   *zChiSquaredDistribution._cdfc                 C   s   ddt  |  | j d  S r   )r   r   r   rn   rn   ro   r     s   z/ChiSquaredDistribution._characteristic_functionc                 C   s   dd|  | j  d  S r   r   r   rn   rn   ro   r     s   z2ChiSquaredDistribution._moment_generating_functionN)r   r   r   r   r   rv   r.   r   r   r   r   r   r   rn   rn   rn   ro   r	    s    

r	  c                 C   r  )a"  
    Create a continuous random variable with a Chi-squared distribution.

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

    The density of the Chi-squared distribution is given by

    .. math::
        f(x) := \frac{1}{2^{\frac{k}{2}}\Gamma\left(\frac{k}{2}\right)}
                x^{\frac{k}{2}-1} e^{-\frac{x}{2}}

    with :math:`x \geq 0`.

    Parameters
    ==========

    k : Positive integer
        The number of degrees of freedom.

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import ChiSquared, density, E, variance, moment
    >>> from sympy import Symbol

    >>> k = Symbol("k", integer=True, positive=True)
    >>> z = Symbol("z")

    >>> X = ChiSquared("x", k)

    >>> density(X)(z)
    z**(k/2 - 1)*exp(-z/2)/(2**(k/2)*gamma(k/2))

    >>> E(X)
    k

    >>> variance(X)
    2*k

    >>> moment(X, 3)
    k**3 + 6*k**2 + 8*k

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Chi_squared_distribution
    .. [2] http://mathworld.wolfram.com/Chi-SquaredDistribution.html
    )r   r	  r  rn   rn   ro   r>     s   8r>   c                   @   6   e Zd ZdZedeZedd Zdd Z	dd Z
d	S )
DagumDistributionr   r   r   r   c                 C   r   )Nr   z#Shape parameter p must be positive.z#Shape parameter a must be positive.#Scale parameter b must be positive.r   r  rn   rn   ro   rv     r   zDagumDistribution.checkc                 C   sJ   | j | j| j}}}|| | || ||  || | d |d    S r   r  r   rs   r   r   r   rn   rn   ro   r        4zDagumDistribution.pdfc                 C   sH   | j | j| j}}}ttjt|| |   |  |dkftjdfS Nr   T)r   r   r   r!   r   r   r   r  rn   rn   ro   r     s   &zDagumDistribution._cdfNr   r   r   r   r.   r   r   r   rv   r   r   rn   rn   rn   ro   r    s    

r  c                 C   r   )aK  
    Create a continuous random variable with a Dagum distribution.

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

    The density of the Dagum distribution is given by

    .. math::
        f(x) := \frac{a p}{x} \left( \frac{\left(\tfrac{x}{b}\right)^{a p}}
                {\left(\left(\tfrac{x}{b}\right)^a + 1 \right)^{p+1}} \right)

    with :math:`x > 0`.

    Parameters
    ==========

    p : Real number
        `p > 0`, a shape.
    a : Real number
        `a > 0`, a shape.
    b : Real number
        `b > 0`, a scale.

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Dagum, density, cdf
    >>> from sympy import Symbol

    >>> p = Symbol("p", positive=True)
    >>> a = Symbol("a", positive=True)
    >>> b = Symbol("b", positive=True)
    >>> z = Symbol("z")

    >>> X = Dagum("x", p, a, b)

    >>> density(X)(z)
    a*p*(z/b)**(a*p)*((z/b)**a + 1)**(-p - 1)/z

    >>> cdf(X)(z)
    Piecewise(((1 + (z/b)**(-a))**(-p), z >= 0), (0, True))


    References
    ==========

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

    )r   r  )r   r   r   r   rn   rn   ro   r?     s   9r?   c                 C   s   t | t|tj| fS )a  
    Create a continuous random variable with an Erlang distribution.

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

    The density of the Erlang distribution is given by

    .. math::
        f(x) := \frac{\lambda^k x^{k-1} e^{-\lambda x}}{(k-1)!}

    with :math:`x \in [0,\infty]`.

    Parameters
    ==========

    k : Positive integer
    l : Real number, `\lambda > 0`, the rate

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Erlang, density, cdf, E, variance
    >>> from sympy import Symbol, simplify, pprint

    >>> k = Symbol("k", integer=True, positive=True)
    >>> l = Symbol("l", positive=True)
    >>> z = Symbol("z")

    >>> X = Erlang("x", k, l)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
     k  k - 1  -l*z
    l *z     *e
    ---------------
        Gamma(k)

    >>> C = cdf(X)(z)
    >>> pprint(C, use_unicode=False)
    /lowergamma(k, l*z)
    |------------------  for z > 0
    <     Gamma(k)
    |
    \        0           otherwise


    >>> E(X)
    k/l

    >>> simplify(variance(X))
    k/l**2

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Erlang_distribution
    .. [2] http://mathworld.wolfram.com/ErlangDistribution.html

    )r   GammaDistributionr   r   r  rn   rn   ro   r@   Z  s   Cr@   c                   @   H   e Zd ZdZee eZedd Zdd Z	dd Z
dd	 Zd
d ZdS )ExGaussianDistributionmeanstdratec                 C       t |dkd t |dkd d S )Nr   z2Standard deviation of ExGaussian must be positive.z$Rate of ExGaussian must be positive.r   r  rn   rn   ro   rv     s   zExGaussianDistribution.checkc                 C   sv   | j | j| j}}}|d }t|d| ||d   d|   d }t|||d   | td|  }|| | S r   )r  r  r  r   r$   r   )r   rs   r  r  r  term1term2term3rn   rn   ro   r     s
   ($zExGaussianDistribution.pdfc           
      C   s   ddl m} | j| j| j}}}|||  }|| }|tdd||}|td|d ||}	|t| |d d  t|	  S )Nr   cdfrs   r   )sympy.statsr   r  r  r  rW   r   r   )
r   rs   r   r  r  r  uvGaussianCDF1GaussianCDF2rn   rn   ro   r     s   "zExGaussianDistribution._cdfc                 C   sV   | j | j| j}}}dt| |  d }tt| | |d |d  d  }|| S Nr   r   )r  r  r  r   r   r   r   r  r  r  r  r  rn   rn   ro   r     s   $z/ExGaussianDistribution._characteristic_functionc                 C   sN   | j | j| j}}}d||  d }t|| |d |d  d  }|| S r&  )r  r  r  r   r(  rn   rn   ro   r     s    z2ExGaussianDistribution._moment_generating_functionNr   r   r   r   r.   r   r   r   rv   r   r   r   r   rn   rn   rn   ro   r    s    

r  c                 C   r   )a  
    Create a continuous random variable with an Exponentially modified
    Gaussian (EMG) distribution.

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

    The density of the exponentially modified Gaussian distribution is given by

    .. math::
        f(x) := \frac{\lambda}{2}e^{\frac{\lambda}{2}(2\mu+\lambda\sigma^2-2x)}
            \text{erfc}(\frac{\mu + \lambda\sigma^2 - x}{\sqrt{2}\sigma})

    with $x > 0$. Note that the expected value is `1/\lambda`.

    Parameters
    ==========

    name : A string giving a name for this distribution
    mean : A Real number, the mean of Gaussian component
    std : A positive Real number,
        :math: `\sigma^2 > 0` the variance of Gaussian component
    rate : A positive Real number,
        :math: `\lambda > 0` the rate of Exponential component

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import ExGaussian, density, cdf, E
    >>> from sympy.stats import variance, skewness
    >>> from sympy import Symbol, pprint, simplify

    >>> mean = Symbol("mu")
    >>> std = Symbol("sigma", positive=True)
    >>> rate = Symbol("lamda", positive=True)
    >>> z = Symbol("z")
    >>> X = ExGaussian("x", mean, std, rate)

    >>> pprint(density(X)(z), use_unicode=False)
                 /           2             \
           lamda*\lamda*sigma  + 2*mu - 2*z/
           ---------------------------------     /  ___ /           2         \\
                           2                     |\/ 2 *\lamda*sigma  + mu - z/|
    lamda*e                                 *erfc|-----------------------------|
                                                 \           2*sigma           /
    ----------------------------------------------------------------------------
                                         2

    >>> cdf(X)(z)
    -(erf(sqrt(2)*(-lamda**2*sigma**2 + lamda*(-mu + z))/(2*lamda*sigma))/2 + 1/2)*exp(lamda**2*sigma**2/2 - lamda*(-mu + z)) + erf(sqrt(2)*(-mu + z)/(2*sigma))/2 + 1/2

    >>> E(X)
    (lamda*mu + 1)/lamda

    >>> simplify(variance(X))
    sigma**2 + lamda**(-2)

    >>> simplify(skewness(X))
    2/(lamda**2*sigma**2 + 1)**(3/2)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Exponentially_modified_Gaussian_distribution
    )r   r  )r   r  r  r  rn   rn   ro   rA     s   GrA   c                   @   sN   e Zd ZdZedeZedd Zdd Z	dd Z
d	d
 Zdd Zdd ZdS )ExponentialDistributionr  r   c                 C      t | dkd d S )Nr   zRate must be positive.r   r+  rn   rn   ro   rv     ru   zExponentialDistribution.checkc                 C   s   | j t| j  |  S rj   )r  r   r   rn   rn   ro   r   "     zExponentialDistribution.pdfc                 C   s$   t tjt| j |  |dkfdS )Nr   r   )r!   r   r   r   r  r   rn   rn   ro   r   %  s   zExponentialDistribution._cdfc                 C   s   | j }||t|   S rj   )r  r   r   r   r  rn   rn   ro   r   +  s   z0ExponentialDistribution._characteristic_functionc                 C   s   | j }|||  S rj   r+  r.  rn   rn   ro   r   /  s   z3ExponentialDistribution._moment_generating_functionc                 C   s   t d|  | j S r   )r   r  r   rn   rn   ro   r   3  s   z!ExponentialDistribution._quantileNr   r   r   r   r.   r   r   r   rv   r   r   r   r   r   rn   rn   rn   ro   r*    s    

r*  c                 C   r  )a-  
    Create a continuous random variable with an Exponential distribution.

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

    The density of the exponential distribution is given by

    .. math::
        f(x) := \lambda \exp(-\lambda x)

    with $x > 0$. Note that the expected value is `1/\lambda`.

    Parameters
    ==========

    rate : A positive Real number, `\lambda > 0`, the rate (or inverse scale/inverse mean)

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Exponential, density, cdf, E
    >>> from sympy.stats import variance, std, skewness, quantile
    >>> from sympy import Symbol

    >>> l = Symbol("lambda", positive=True)
    >>> z = Symbol("z")
    >>> p = Symbol("p")
    >>> X = Exponential("x", l)

    >>> density(X)(z)
    lambda*exp(-lambda*z)

    >>> cdf(X)(z)
    Piecewise((1 - exp(-lambda*z), z >= 0), (0, True))

    >>> quantile(X)(p)
    -log(1 - p)/lambda

    >>> E(X)
    1/lambda

    >>> variance(X)
    lambda**(-2)

    >>> skewness(X)
    2

    >>> X = Exponential('x', 10)

    >>> density(X)(z)
    10*exp(-10*z)

    >>> E(X)
    1/10

    >>> std(X)
    1/10

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Exponential_distribution
    .. [2] http://mathworld.wolfram.com/ExponentialDistribution.html

    )r   r*  )r   r  rn   rn   ro   rB   7  s   IrB   c                   @   s8   e Zd ZdZee eZedd Zdd Z	dd Z
dS )	ExponentialPowerDistributionmur   r
   c                 C   r  )Nr   z'Scale parameter alpha must be positive.z&Shape parameter beta must be positive.r   r1  rn   rn   ro   rv     r   z"ExponentialPowerDistribution.checkc                 C   sP   | j | j| j}}}|tt|| | |   }d| td|  }|| S r   )r2  r   r
   r   r   r(   r   rs   r2  r   r
   r   r   rn   rn   ro   r     s   z ExponentialPowerDistribution.pdfc                 C   s^   | j | j| j}}}td| t|| | | }dtd|  }t|| | | tj S r   )	r2  r   r
   r)   r   r(   r   r   r   r3  rn   rn   ro   r     s   z!ExponentialPowerDistribution._cdfNr  rn   rn   rn   ro   r0    s    
r0  c                 C   r   )a  
    Create a Continuous Random Variable with Exponential Power distribution.
    This distribution is known also as Generalized Normal
    distribution version 1.

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

    The density of the Exponential Power distribution is given by

    .. math::
        f(x) := \frac{\beta}{2\alpha\Gamma(\frac{1}{\beta})}
            e^{{-(\frac{|x - \mu|}{\alpha})^{\beta}}}

    with :math:`x \in [ - \infty, \infty ]`.

    Parameters
    ==========

    mu : Real number
        A location.
    alpha : Real number,`\alpha > 0`
        A  scale.
    beta : Real number, `\beta > 0`
        A shape.

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import ExponentialPower, density, cdf
    >>> from sympy import Symbol, pprint
    >>> z = Symbol("z")
    >>> mu = Symbol("mu")
    >>> alpha = Symbol("alpha", positive=True)
    >>> beta = Symbol("beta", positive=True)
    >>> X = ExponentialPower("x", mu, alpha, beta)
    >>> pprint(density(X)(z), use_unicode=False)
                     beta
           /|mu - z|\
          -|--------|
           \ alpha  /
    beta*e
    ---------------------
                  / 1  \
     2*alpha*Gamma|----|
                  \beta/
    >>> cdf(X)(z)
    1/2 + lowergamma(1/beta, (Abs(mu - z)/alpha)**beta)*sign(-mu + z)/(2*gamma(1/beta))

    References
    ==========

    .. [1] https://reference.wolfram.com/language/ref/ExponentialPowerDistribution.html
    .. [2] https://en.wikipedia.org/wiki/Generalized_normal_distribution#Version_1

    )r   r0  )r   r2  r   r
   rn   rn   ro   rC        >rC   c                   @   r  )
FDistributionDistributiond1d2r   c                 C   s,   t | dk| jfd t |dk|jfd d S )Nr   z/Degrees of freedom d1 must be positive integer.z/Degrees of freedom d2 must be positive integer.r   r6  rn   rn   ro   rv     s   zFDistributionDistribution.checkc                 C   sP   | j | j}}t|| | ||  || | ||   |t|d |d   S r   )r7  r8  r   r   r   rs   r7  r8  rn   rn   ro   r     s   *zFDistributionDistribution.pdfc                 C   r   )NzEThe moment generating function for the F-distribution does not exist.r   r   rn   rn   ro   r     r   z5FDistributionDistribution._moment_generating_functionN)r   r   r   r   r.   r   r   r   rv   r   r   rn   rn   rn   ro   r5    s    

r5  c                 C   r   )a/  
    Create a continuous random variable with a F distribution.

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

    The density of the F distribution is given by

    .. math::
        f(x) := \frac{\sqrt{\frac{(d_1 x)^{d_1} d_2^{d_2}}
                {(d_1 x + d_2)^{d_1 + d_2}}}}
                {x \mathrm{B} \left(\frac{d_1}{2}, \frac{d_2}{2}\right)}

    with :math:`x > 0`.

    Parameters
    ==========

    d1 : `d_1 > 0`, where `d_1` is the degrees of freedom (`n_1 - 1`)
    d2 : `d_2 > 0`, where `d_2` is the degrees of freedom (`n_2 - 1`)

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import FDistribution, density
    >>> from sympy import Symbol, pprint

    >>> d1 = Symbol("d1", positive=True)
    >>> d2 = Symbol("d2", positive=True)
    >>> z = Symbol("z")

    >>> X = FDistribution("x", d1, d2)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
      d2
      --    ______________________________
      2    /       d1            -d1 - d2
    d2  *\/  (d1*z)  *(d1*z + d2)
    --------------------------------------
                    /d1  d2\
                 z*B|--, --|
                    \2   2 /

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/F-distribution
    .. [2] http://mathworld.wolfram.com/F-Distribution.html

    )r   r5  r   r7  r8  rn   rn   ro   rD        :rD   c                   @   s0   e Zd ZdZee eZedd Zdd Z	dS )FisherZDistributionr6  c                 C   r   )Nr   z&Degree of freedom d1 must be positive.z&Degree of freedom d2 must be positive.r   r6  rn   rn   ro   rv   ;  r   zFisherZDistribution.checkc                 C   sh   | j | j}}d||d   ||d   t|d |d  t||  |td|  | || d   S r   )r7  r8  r   r   r9  rn   rn   ro   r   @  s   ,
zFisherZDistribution.pdfN
r   r   r   r   r.   r   r   r   rv   r   rn   rn   rn   ro   r<  6  s    
r<  c                 C   r   )a  
    Create a Continuous Random Variable with an Fisher's Z distribution.

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

    The density of the Fisher's Z distribution is given by

    .. math::
        f(x) := \frac{2d_1^{d_1/2} d_2^{d_2/2}} {\mathrm{B}(d_1/2, d_2/2)}
                \frac{e^{d_1z}}{\left(d_1e^{2z}+d_2\right)^{\left(d_1+d_2\right)/2}}


    .. TODO - What is the difference between these degrees of freedom?

    Parameters
    ==========

    d1 : `d_1 > 0`
        Degree of freedom.
    d2 : `d_2 > 0`
        Degree of freedom.

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import FisherZ, density
    >>> from sympy import Symbol, pprint

    >>> d1 = Symbol("d1", positive=True)
    >>> d2 = Symbol("d2", positive=True)
    >>> z = Symbol("z")

    >>> X = FisherZ("x", d1, d2)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
                                d1   d2
        d1   d2               - -- - --
        --   --                 2    2
        2    2  /    2*z     \           d1*z
    2*d1  *d2  *\d1*e    + d2/         *e
    -----------------------------------------
                     /d1  d2\
                    B|--, --|
                     \2   2 /

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Fisher%27s_z-distribution
    .. [2] http://mathworld.wolfram.com/Fishersz-Distribution.html

    )r   r<  r:  rn   rn   ro   rE   E  s   =rE   c                   @   s@   e Zd ZdZedeZedd ZdddZ	dd	 Z
d
d ZdS )FrechetDistributionr   smr   c                 C   r   )Nr   z'Shape parameter alpha must be positive.#Scale parameter s must be positive.r   r?  rn   rn   ro   rv     r   zFrechetDistribution.checkr   c                 C   s*   t tt|||f\}}}t| |||S rj   )rz   r{   r   r   r   )r   r   r@  rA  rn   rn   ro   r     s   zFrechetDistribution.__new__c                 C   sJ   | j | j| j}}}|| || | d|   t|| | |    S )Nr'  )r   r@  rA  r   r   rs   r   r@  rA  rn   rn   ro   r     r  zFrechetDistribution.pdfc                 C   sB   | j | j| j}}}tt|| | |   ||kftjdfS NT)r   r@  rA  r!   r   r   r   rC  rn   rn   ro   r     s    zFrechetDistribution._cdfNr   r   )r   r   r   r   r.   r   r   r   rv   r   r   r   rn   rn   rn   ro   r>    s    


r>  c                 C   r   )a  
    Create a continuous random variable with a Frechet distribution.

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

    The density of the Frechet distribution is given by

    .. math::
        f(x) := \frac{\alpha}{s} \left(\frac{x-m}{s}\right)^{-1-\alpha}
                 e^{-(\frac{x-m}{s})^{-\alpha}}

    with :math:`x \geq m`.

    Parameters
    ==========

    a : Real number, :math:`a \in \left(0, \infty\right)` the shape
    s : Real number, :math:`s \in \left(0, \infty\right)` the scale
    m : Real number, :math:`m \in \left(-\infty, \infty\right)` the minimum

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Frechet, density, cdf
    >>> from sympy import Symbol

    >>> a = Symbol("a", positive=True)
    >>> s = Symbol("s", positive=True)
    >>> m = Symbol("m", real=True)
    >>> z = Symbol("z")

    >>> X = Frechet("x", a, s, m)

    >>> density(X)(z)
    a*((-m + z)/s)**(-a - 1)*exp(-1/((-m + z)/s)**a)/s

    >>> cdf(X)(z)
    Piecewise((exp(-1/((-m + z)/s)**a), m <= z), (0, True))

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Fr%C3%A9chet_distribution

    )r   r>  )r   r   r@  rA  rn   rn   ro   rF     s   5rF   c                   @   F   e Zd ZdZedeZedd Zdd Z	dd Z
d	d
 Zdd ZdS )r  r   thetar   c                 C   r   )Nr   k must be positivezTheta must be positiver   rG  rn   rn   ro   rv     r   zGammaDistribution.checkc                 C   s8   | j | j}}||d  t| |  t|||   S r   )r   rH  r   r(   r   rs   r   rH  rn   rn   ro   r        *zGammaDistribution.pdfc                 C   s<   | j | j}}tt|t|| t| |dkftjdfS r  )r   rH  r!   r)   r   r(   r   rJ  rn   rn   ro   r     s
    zGammaDistribution._cdfc                 C   s   d| j t |  | j  S r   )rH  r   r   r   rn   rn   ro   r     r   z*GammaDistribution._characteristic_functionc                 C   s   d| j |  | j  S r   )rH  r   r   rn   rn   ro   r     r-  z-GammaDistribution._moment_generating_functionNr)  rn   rn   rn   ro   r    s    

r  c                 C   r   )a  
    Create a continuous random variable with a Gamma distribution.

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

    The density of the Gamma distribution is given by

    .. math::
        f(x) := \frac{1}{\Gamma(k) \theta^k} x^{k - 1} e^{-\frac{x}{\theta}}

    with :math:`x \in [0,1]`.

    Parameters
    ==========

    k : Real number, `k > 0`, a shape
    theta : Real number, `\theta > 0`, a scale

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Gamma, density, cdf, E, variance
    >>> from sympy import Symbol, pprint, simplify

    >>> k = Symbol("k", positive=True)
    >>> theta = Symbol("theta", positive=True)
    >>> z = Symbol("z")

    >>> X = Gamma("x", k, theta)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
                      -z
                    -----
         -k  k - 1  theta
    theta  *z     *e
    ---------------------
           Gamma(k)

    >>> C = cdf(X, meijerg=True)(z)
    >>> pprint(C, use_unicode=False)
    /            /     z  \
    |k*lowergamma|k, -----|
    |            \   theta/
    <----------------------  for z >= 0
    |     Gamma(k + 1)
    |
    \          0             otherwise

    >>> E(X)
    k*theta

    >>> V = simplify(variance(X))
    >>> pprint(V, use_unicode=False)
           2
    k*theta


    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Gamma_distribution
    .. [2] http://mathworld.wolfram.com/GammaDistribution.html

    )r   r  )r   r   rH  rn   rn   ro   rG     s   IrG   c                   @   rF  )GammaInverseDistributionr   r   c                 C   r   )Nr   zalpha must be positivezbeta must be positiver   r   rn   rn   ro   rv   H  r   zGammaInverseDistribution.checkc                 C   s:   | j | j}}|| t| || d   t| |  S r   )r   r   r(   r   r   rn   rn   ro   r   M     ,zGammaInverseDistribution.pdfc                 C   s8   | j | j}}tt||| t| |dkftjdfS r  )r   r   r!   r*   r(   r   r   r   rn   rn   ro   r   Q  s   zGammaInverseDistribution._cdfc                 C   sJ   | j | j}}dt | | |d   t|tdt | |  t| S )Nr   )r   r   r   r	   r   r(   r   r   r   r   rn   rn   ro   r   V  s   <z1GammaInverseDistribution._characteristic_functionc                 C   r   )NzQThe moment generating function for the gamma inverse distribution does not exist.r   r   rn   rn   ro   r   Z  r   z4GammaInverseDistribution._moment_generating_functionNr)  rn   rn   rn   ro   rL  C  s    

rL  c                 C   r   )aY  
    Create a continuous random variable with an inverse Gamma distribution.

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

    The density of the inverse Gamma distribution is given by

    .. math::
        f(x) := \frac{\beta^\alpha}{\Gamma(\alpha)} x^{-\alpha - 1}
                \exp\left(\frac{-\beta}{x}\right)

    with :math:`x > 0`.

    Parameters
    ==========

    a : Real number, `a > 0`, a shape
    b : Real number, `b > 0`, a scale

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import GammaInverse, density, cdf
    >>> from sympy import Symbol, pprint

    >>> a = Symbol("a", positive=True)
    >>> b = Symbol("b", positive=True)
    >>> z = Symbol("z")

    >>> X = GammaInverse("x", a, b)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
                -b
                ---
     a  -a - 1   z
    b *z      *e
    ---------------
       Gamma(a)

    >>> cdf(X)(z)
    Piecewise((uppergamma(a, b/z)/gamma(a), z > 0), (0, True))


    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Inverse-gamma_distribution

    )r   rL  r   rn   rn   ro   rH   ^  r;  rH   c                   @   r  )GumbelDistributionr
   r2  minimumc                 C   r,  )Nr   z&Scale parameter beta must be positive.r   rQ  rn   rn   ro   rv     ru   zGumbelDistribution.checkc                 C   sf   | j | j}}|| | }d| t| t|   }d| t|t|  }t|| jf|| j fS r   r
   r2  r   r!   rR  )r   rs   r
   r2  zf_maxf_minrn   rn   ro   r     s
   zGumbelDistribution.pdfc                 C   sT   | j | j}}|| | }tt|  }dtt|  }t|| jf|| j fS r   rS  )r   rs   r
   r2  rT  F_maxF_minrn   rn   ro   r     s
   zGumbelDistribution._cdfc                 C   sh   t dt| j |  tt| j |  }t dt| j |  tt| j |  }t|| jf|| j fS r   )r(   r   r
   r   r2  r!   rR  )r   r   cf_maxcf_minrn   rn   ro   r     s   ((z+GumbelDistribution._characteristic_functionc                 C   sX   t d| j|  t| j|  }t d| j|  t| j|  }t|| jf|| j fS r   )r(   r
   r   r2  r!   rR  )r   r   mgf_maxmgf_minrn   rn   ro   r     s     z.GumbelDistribution._moment_generating_functionNr)  rn   rn   rn   ro   rP    s    
rP  Fc                 C   r   )a  
    Create a Continuous Random Variable with Gumbel distribution.

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

    The density of the Gumbel distribution is given by

    For Maximum

    .. math::
        f(x) := \dfrac{1}{\beta} \exp \left( -\dfrac{x-\mu}{\beta}
                - \exp \left( -\dfrac{x - \mu}{\beta} \right) \right)

    with :math:`x \in [ - \infty, \infty ]`.

    For Minimum

    .. math::
        f(x) := \frac{e^{- e^{\frac{- \mu + x}{\beta}} + \frac{- \mu + x}{\beta}}}{\beta}

    with :math:`x \in [ - \infty, \infty ]`.

    Parameters
    ==========

    mu : Real number, `\mu`, a location
    beta : Real number, `\beta > 0`, a scale
    minimum : Boolean, by default ``False``, set to ``True`` for enabling minimum distribution

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Gumbel, density, cdf
    >>> from sympy import Symbol
    >>> x = Symbol("x")
    >>> mu = Symbol("mu")
    >>> beta = Symbol("beta", positive=True)
    >>> X = Gumbel("x", beta, mu)
    >>> density(X)(x)
    exp(-exp(-(-mu + x)/beta) - (-mu + x)/beta)/beta
    >>> cdf(X)(x)
    exp(-exp(-(-mu + x)/beta))

    References
    ==========

    .. [1] http://mathworld.wolfram.com/GumbelDistribution.html
    .. [2] https://en.wikipedia.org/wiki/Gumbel_distribution
    .. [3] http://www.mathwave.com/help/easyfit/html/analyses/distributions/gumbel_max.html
    .. [4] http://www.mathwave.com/help/easyfit/html/analyses/distributions/gumbel_min.html

    )r   rP  )r   r
   r2  rR  rn   rn   ro   rJ     s   ;rJ   c                   @   >   e Zd ZdZedeZedd Zdd Z	dd Z
d	d
 ZdS )GompertzDistributionr   etar   c                 C   r   Nr   b must be positivezeta must be positiver   r_  rn   rn   ro   rv     r   zGompertzDistribution.checkc                 C   s@   | j | j}}|| t||  t| t| t||   S rj   r`  r   r   r   rs   r`  r   rn   rn   ro   r   
  s   2zGompertzDistribution.pdfc                 C   s0   | j | j}}dt|t| t||    S r   rc  rd  rn   rn   ro   r        "zGompertzDistribution._cdfc                 C   s(   | j | j}}|t| t|| | S rj   )r`  r   r   r'   )r   r   r`  r   rn   rn   ro   r     s   z0GompertzDistribution._moment_generating_functionNr   r   r   r   r.   r   r   r   rv   r   r   r   rn   rn   rn   ro   r^     s    

r^  c                 C   r   )a_  
    Create a Continuous Random Variable with Gompertz distribution.

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

    The density of the Gompertz distribution is given by

    .. math::
        f(x) := b \eta e^{b x} e^{\eta} \exp \left(-\eta e^{bx} \right)

    with :math:`x \in [0, \infty)`.

    Parameters
    ==========

    b : Real number, `b > 0`, a scale
    eta : Real number, `\eta > 0`, a shape

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Gompertz, density
    >>> from sympy import Symbol

    >>> b = Symbol("b", positive=True)
    >>> eta = Symbol("eta", positive=True)
    >>> z = Symbol("z")

    >>> X = Gompertz("x", b, eta)

    >>> density(X)(z)
    b*eta*exp(eta)*exp(b*z)*exp(-eta*exp(b*z))

    References
    ==========

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

    )r   r^  r   r   r`  rn   rn   ro   rI        .rI   c                   @   r  )
KumaraswamyDistributionr   r   c                 C   r   )Nr   za must be positiverb  r   r   rn   rn   ro   rv   O  r   zKumaraswamyDistribution.checkc                 C   s6   | j | j}}|| ||d   d||  |d   S r   r   r   rn   rn   ro   r   T  r   zKumaraswamyDistribution.pdfc                 C   sF   | j | j}}ttj|tjk fdd||  |  |tjkftjdfS Nr   T)r   r   r!   r   r   r   r   rn   rn   ro   r   X  s   zKumaraswamyDistribution._cdfNr  rn   rn   rn   ro   ri  J      

ri  c                 C   r   )a  
    Create a Continuous Random Variable with a Kumaraswamy distribution.

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

    The density of the Kumaraswamy distribution is given by

    .. math::
        f(x) := a b x^{a-1} (1-x^a)^{b-1}

    with :math:`x \in [0,1]`.

    Parameters
    ==========

    a : Real number, `a > 0`, a shape
    b : Real number, `b > 0`, a shape

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Kumaraswamy, density, cdf
    >>> from sympy import Symbol, pprint

    >>> a = Symbol("a", positive=True)
    >>> b = Symbol("b", positive=True)
    >>> z = Symbol("z")

    >>> X = Kumaraswamy("x", a, b)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
                       b - 1
         a - 1 /     a\
    a*b*z     *\1 - z /

    >>> cdf(X)(z)
    Piecewise((0, z < 0), (1 - (1 - z**a)**b, z <= 1), (1, True))

    References
    ==========

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

    )r   ri  r   rn   rn   ro   rK   _  s   5rK   c                   @   r  )LaplaceDistributionr2  r   c                 C   r   )Nr   r  z$Location parameter mu should be realr   rm  rn   rn   ro   rv     r   zLaplaceDistribution.checkc                 C   s0   | j | j}}dd|  tt||  |  S r   )r2  r   r   r   r   rs   r2  r   rn   rn   ro   r     re  zLaplaceDistribution.pdfc                 C   sT   | j | j}}ttjt|| |  ||k ftjtjt||  |   ||kfS rj   )r2  r   r!   r   r   r   r   rn  rn   rn   ro   r     s
   $zLaplaceDistribution._cdfc                 C   s(   t | jt | d| jd |d    S r   )r   r2  r   r   r   rn   rn   ro   r     s   (z,LaplaceDistribution._characteristic_functionc                 C   s$   t | j| d| jd |d    S r   )r   r2  r   r   rn   rn   ro   r     s   $z/LaplaceDistribution._moment_generating_functionNr)  rn   rn   rn   ro   rl    s    
rl  c                 C   sD   t |ttfrt |ttfrddlm} || ||S t| t||fS )a  
    Create a continuous random variable with a Laplace distribution.

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

    The density of the Laplace distribution is given by

    .. math::
        f(x) := \frac{1}{2 b} \exp \left(-\frac{|x-\mu|}b \right)

    Parameters
    ==========

    mu : Real number or a list/matrix, the location (mean) or the
        location vector
    b : Real number or a positive definite matrix, representing a scale
        or the covariance matrix.

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Laplace, density, cdf
    >>> from sympy import Symbol, pprint

    >>> mu = Symbol("mu")
    >>> b = Symbol("b", positive=True)
    >>> z = Symbol("z")

    >>> X = Laplace("x", mu, b)

    >>> density(X)(z)
    exp(-Abs(mu - z)/b)/(2*b)

    >>> cdf(X)(z)
    Piecewise((exp((-mu + z)/b)/2, mu > z), (1 - exp((mu - z)/b)/2, True))

    >>> L = Laplace('L', [1, 2], [[1, 0], [0, 1]])
    >>> pprint(density(L)(1, 2), use_unicode=False)
     5        /     ____\
    e *besselk\0, \/ 35 /
    ---------------------
              pi

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Laplace_distribution
    .. [2] http://mathworld.wolfram.com/LaplaceDistribution.html

    r   )MultivariateLaplace)
isinstancerz   r/   sympy.stats.joint_rv_typesro  r   rl  )r   r2  r   ro  rn   rn   ro   rL     s   :rL   c                   @   H   e Zd ZdZedd Zedd Zdd Zdd	 Z	d
d Z
dd ZdS )LevyDistributionr2  cc                 C   r   rj   )r.   r2  r   r   rn   rn   ro   r     r   zLevyDistribution.setc                 C   r   )Nr   z$c (scale parameter) must be positivez$mu (location paramater) must be realr   rt  rn   rn   ro   rv   	  r   zLevyDistribution.checkc                 C   sH   | j | j}}t|dt  t| d||    || tjtj   S r   )r2  ru  r   r   r   r   r   r   r   rs   r2  ru  rn   rn   ro   r   	  s   :zLevyDistribution.pdfc                 C   s&   | j | j}}tt|d||   S r   )r2  ru  r$   r   rv  rn   rn   ro   r   
	     zLevyDistribution._cdfc                 C   s2   | j | j}}tt| | tdt | |  S )N)r2  ru  r   r   r   )r   r   r2  ru  rn   rn   ro   r   	     $z)LevyDistribution._characteristic_functionc                 C   r   )NzCThe moment generating function of Levy distribution does not exist.r   r   rn   rn   ro   r   	  r   z,LevyDistribution._moment_generating_functionNr   r   r   r   r   r   r   rv   r   r   r   r   rn   rn   rn   ro   rs    s    

rs  c                 C   r   )a  
    Create a continuous random variable with a Levy distribution.

    The density of the Levy distribution is given by

    .. math::
        f(x) := \sqrt(\frac{c}{2 \pi}) \frac{\exp -\frac{c}{2 (x - \mu)}}{(x - \mu)^{3/2}}

    Parameters
    ==========

    mu : Real number
        The location parameter.
    c : Real number, `c > 0`
        A scale parameter.

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Levy, density, cdf
    >>> from sympy import Symbol

    >>> mu = Symbol("mu", real=True)
    >>> c = Symbol("c", positive=True)
    >>> z = Symbol("z")

    >>> X = Levy("x", mu, c)

    >>> density(X)(z)
    sqrt(2)*sqrt(c)*exp(-c/(-2*mu + 2*z))/(2*sqrt(pi)*(-mu + z)**(3/2))

    >>> cdf(X)(z)
    erfc(sqrt(c)*sqrt(1/(-2*mu + 2*z)))

    References
    ==========
    .. [1] https://en.wikipedia.org/wiki/L%C3%A9vy_distribution
    .. [2] http://mathworld.wolfram.com/LevyDistribution.html
    )r   rs  )r   r2  ru  rn   rn   ro   rM   	  rh  rM   c                   @   sH   e Zd ZdZedeZedd Z	dd Z
dd Zd	d
 Zdd ZdS )LogCauchyDistributionr2  r   r   c                 C   s&   t |dkdkd t | jdkd d S )Nr   Fr   r   r   r|  rn   rn   ro   rv   N	  s   zLogCauchyDistribution.checkc                 C   s6   | j | j}}d|t  |t|| d |d    S r   )r2  r   r   r   r   rs   r2  r   rn   rn   ro   r   S	  r   zLogCauchyDistribution.pdfc                 C   s0   | j | j}}dt tt|| |  tj S r   )r2  r   r   r   r   r   r   r}  rn   rn   ro   r   W	  re  zLogCauchyDistribution._cdfc                 C   r   )NzKThe characteristic function for the Log-Cauchy distribution does not exist.r   r   rn   rn   ro   r   [	  r   z.LogCauchyDistribution._characteristic_functionc                 C   r   )NzNThe moment generating function for the Log-Cauchy distribution does not exist.r   r   rn   rn   ro   r   _	  r   z1LogCauchyDistribution._moment_generating_functionN)r   r   r   r   r.   openr   r   r   rv   r   r   r   r   rn   rn   rn   ro   r{  I	  s    
r{  c                 C   r   )a3  
    Create a continuous random variable with a Log-Cauchy distribution.
    The density of the Log-Cauchy distribution is given by

    .. math::
        f(x) := \frac{1}{\pi x} \frac{\sigma}{(log(x)-\mu^2) + \sigma^2}

    Parameters
    ==========

    mu : Real number, the location

    sigma : Real number, `\sigma > 0`, a scale

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import LogCauchy, density, cdf
    >>> from sympy import Symbol, S

    >>> mu = 2
    >>> sigma = S.One / 5
    >>> z = Symbol("z")

    >>> X = LogCauchy("x", mu, sigma)

    >>> density(X)(z)
    1/(5*pi*z*((log(z) - 2)**2 + 1/25))

    >>> cdf(X)(z)
    atan(5*log(z) - 10)/pi + 1/2

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Log-Cauchy_distribution
    )r   r{  r   r2  r   rn   rn   ro   rN   c	  s   ,rN   c                   @   sP   e Zd ZdZee eZedd Zdd Z	dd Z
dd	 Zd
d Zdd ZdS )LogisticDistributionr2  r@  c                 C      t |dkd d S )Nr   rB  r   r  rn   rn   ro   rv   	  ru   zLogisticDistribution.checkc                 C   s>   | j | j}}t||  | |dt||  |  d   S r   )r2  r@  r   r   rs   r2  r@  rn   rn   ro   r   	     0zLogisticDistribution.pdfc                 C   s*   | j | j}}tjdt||  |   S r   )r2  r@  r   r   r   r  rn   rn   ro   r   	  r   zLogisticDistribution._cdfc                 C   sH   t tt| | j t | j | tt| j |  t|dftj	dfS r  )
r!   r   r   r2  r   r@  r   r   r   r   r   rn   rn   ro   r   	  s   Hz-LogisticDistribution._characteristic_functionc                 C   s,   t | j| td| j|  d| j|   S r   )r   r2  r   r@  r   rn   rn   ro   r   	  s   ,z0LogisticDistribution._moment_generating_functionc                 C   s"   | j | jttj tj|    S rj   )r2  r@  r   r   r   r   rn   rn   ro   r   	  s   "zLogisticDistribution._quantileNr/  rn   rn   rn   ro   r  	  s    
r  c                 C   r   )a  
    Create a continuous random variable with a logistic distribution.

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

    The density of the logistic distribution is given by

    .. math::
        f(x) := \frac{e^{-(x-\mu)/s}} {s\left(1+e^{-(x-\mu)/s}\right)^2}

    Parameters
    ==========

    mu : Real number, the location (mean)
    s : Real number, `s > 0`, a scale

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Logistic, density, cdf
    >>> from sympy import Symbol

    >>> mu = Symbol("mu", real=True)
    >>> s = Symbol("s", positive=True)
    >>> z = Symbol("z")

    >>> X = Logistic("x", mu, s)

    >>> density(X)(z)
    exp((mu - z)/s)/(s*(exp((mu - z)/s) + 1)**2)

    >>> cdf(X)(z)
    1/(exp((mu - z)/s) + 1)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Logistic_distribution
    .. [2] http://mathworld.wolfram.com/LogisticDistribution.html

    )r   r  r   r2  r@  rn   rn   ro   rO   	  r   rO   c                   @   rF  )LogLogisticDistributionr   r   c                 C   r   )Nr   z'Scale parameter Alpha must be positive.r   r   r   rn   rn   ro   rv   	  r   zLogLogisticDistribution.checkc                 C   s:   | j | j}}|| || |d   d|| |  d  S r   r   r   rn   rn   ro   r   	  rM  zLogLogisticDistribution.pdfc                 C   s$   | j | j}}dd|| |    S r   r   r   rn   rn   ro   r   	  s   zLogLogisticDistribution._cdfc                 C   s&   | j | j}}||d|  d|   S r   r   )r   r   r   r   rn   rn   ro   r   	  rw  z!LogLogisticDistribution._quantilec                 K   s6   | j \}}ttj|dkft| |tt|   dfS rj  )r   r!   r   NaNr   r   )r   exprvarr   r   r   rn   rn   ro   expectation	  s   
,z#LogLogisticDistribution.expectationN)r   r   r   r   r.   r   r   r   rv   r   r   r   r  rn   rn   rn   ro   r  	  s    

r  c                 C   r   )a  
    Create a continuous random variable with a log-logistic distribution.
    The distribution is unimodal when ``beta > 1``.

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

    The density of the log-logistic distribution is given by

    .. math::
        f(x) := \frac{(\frac{\beta}{\alpha})(\frac{x}{\alpha})^{\beta - 1}}
                {(1 + (\frac{x}{\alpha})^{\beta})^2}

    Parameters
    ==========

    alpha : Real number, `\alpha > 0`, scale parameter and median of distribution
    beta : Real number, `\beta > 0`, a shape parameter

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import LogLogistic, density, cdf, quantile
    >>> from sympy import Symbol, pprint

    >>> alpha = Symbol("alpha", positive=True)
    >>> beta = Symbol("beta", positive=True)
    >>> p = Symbol("p")
    >>> z = Symbol("z", positive=True)

    >>> X = LogLogistic("x", alpha, beta)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
                  beta - 1
           /  z  \
      beta*|-----|
           \alpha/
    ------------------------
                           2
          /       beta    \
          |/  z  \        |
    alpha*||-----|     + 1|
          \\alpha/        /

    >>> cdf(X)(z)
    1/(1 + (z/alpha)**(-beta))

    >>> quantile(X)(p)
    alpha*(p/(1 - p))**(1/beta)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Log-logistic_distribution

    )r   r  r   rn   rn   ro   rP   
  s   @rP   c                   @   s@   e Zd ZdZeddZedd Zdd Z	dd	 Z
d
d ZdS )LogitNormalDistributionr  r   r   c                 C   s4   t |d jduo|d dkd t | jdud d S )Nr   Fr   z+Squared scale parameter s must be positive.zLocation parameter must be realr   r  rn   rn   ro   rv   J
  s    zLogitNormalDistribution.checkc                 C   s   t |d|  S r   r   r   rn   rn   ro   _logitO
  s   zLogitNormalDistribution._logitc                 C   s\   | j | j}}t| || d  d|d   tjtdt |d    d|d|    S r   )r2  r@  r   r  r   r   r   r   r  rn   rn   ro   r   R
  s   NzLogitNormalDistribution.pdfc                 C   s>   | j | j}}tjd dt| || td|d     S r   )r2  r@  r   r   r#   r  r   r  rn   rn   ro   r   V
  r  zLogitNormalDistribution._cdfN)r   r   r   r   r.   r~  r   r   rv   r  r   r   rn   rn   rn   ro   r  F
  s    
r  c                 C   r   )aE  
    Create a continuous random variable with a Logit-Normal distribution.

    The density of the logistic distribution is given by

    .. math::
        f(x) := \frac{1}{s \sqrt{2 \pi}} \frac{1}{x(1 - x)} e^{- \frac{(logit(x)  - \mu)^2}{s^2}}
        where logit(x) = \log(\frac{x}{1 - x})
    Parameters
    ==========

    mu : Real number, the location (mean)
    s : Real number, `s > 0`, a scale

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import LogitNormal, density, cdf
    >>> from sympy import Symbol,pprint

    >>> mu = Symbol("mu", real=True)
    >>> s = Symbol("s", positive=True)
    >>> z = Symbol("z")
    >>> X = LogitNormal("x",mu,s)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
                              2
            /         /  z  \\
           -|-mu + log|-----||
            \         \1 - z//
           ---------------------
                       2
      ___           2*s
    \/ 2 *e
    ----------------------------
            ____
        2*\/ pi *s*z*(1 - z)

    >>> density(X)(z)
    sqrt(2)*exp(-(-mu + log(z/(1 - z)))**2/(2*s**2))/(2*sqrt(pi)*s*z*(1 - z))

    >>> cdf(X)(z)
    erf(sqrt(2)*(-mu + log(z/(1 - z)))/(2*s))/2 + 1/2


    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Logit-normal_distribution

    )r   r  r  rn   rn   ro   rQ   [
  s   ;rQ   c                   @   r]  )LogNormalDistributionr  r  r   c                 C   r  )Nr   zParameter std must be positive.r   r  rn   rn   ro   rv   
  ru   zLogNormalDistribution.checkc                 C   sD   | j | j}}tt|| d  d|d   |tdt  |  S r   )r  r  r   r   r   r   r   rs   r  r  rn   rn   ro   r   
  s   6zLogNormalDistribution.pdfc                 C   sJ   | j | j}}ttjtjtt|| td |   |dkftjdfS Nr   r   T)	r  r  r!   r   r   r#   r   r   r   r  rn   rn   ro   r   
  s
   .zLogNormalDistribution._cdfc                 C   r   )NzIMoment generating function of the log-normal distribution is not defined.r   r   rn   rn   ro   r   
  r   z1LogNormalDistribution._moment_generating_functionNrf  rn   rn   rn   ro   r  
  s    

r  c                 C   r   )a4  
    Create a continuous random variable with a log-normal distribution.

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

    The density of the log-normal distribution is given by

    .. math::
        f(x) := \frac{1}{x\sqrt{2\pi\sigma^2}}
                e^{-\frac{\left(\ln x-\mu\right)^2}{2\sigma^2}}

    with :math:`x \geq 0`.

    Parameters
    ==========

    mu : Real number
        The log-scale.
    sigma : Real number
        A shape. ($\sigma^2 > 0$)

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import LogNormal, density
    >>> from sympy import Symbol, pprint

    >>> mu = Symbol("mu", real=True)
    >>> sigma = Symbol("sigma", positive=True)
    >>> z = Symbol("z")

    >>> X = LogNormal("x", mu, sigma)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
                          2
           -(-mu + log(z))
           -----------------
                      2
      ___      2*sigma
    \/ 2 *e
    ------------------------
            ____
        2*\/ pi *sigma*z


    >>> X = LogNormal('x', 0, 1) # Mean 0, standard deviation 1

    >>> density(X)(z)
    sqrt(2)*exp(-log(z)**2/2)/(2*sqrt(pi)*z)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Lognormal
    .. [2] http://mathworld.wolfram.com/LogNormalDistribution.html

    )r   r  )r   r  r  rn   rn   ro   rR   
     BrR   c                   @   .   e Zd ZdZedeZedd Zdd Z	dS )LomaxDistributionr   r   r   c                 C   s4   t | jd t |jd t | jd t |jd d S )NzShape parameter should be real.zScale parameter should be real.z#Shape parameter should be positive.z#Scale parameter should be positive.r2   r   r   r  rn   rn   ro   rv   
  s   zLomaxDistribution.checkc                 C   s.   | j | j}}|| tj||  | d   S r   )r   r   r   r   )r   rs   lambar   rn   rn   ro   r         zLomaxDistribution.pdfNr=  rn   rn   rn   ro   r  
  s    

r  c                 C   r   )a  
    Create a continuous random variable with a Lomax distribution.

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

    The density of the Lomax distribution is given by

    .. math::
        f(x) := \frac{\alpha}{\lambda}\left[1+\frac{x}{\lambda}\right]^{-(\alpha+1)}

    Parameters
    ==========

    alpha : Real Number, `\alpha > 0`
        Shape parameter
    lamda : Real Number, `\lambda > 0`
        Scale parameter

    Examples
    ========

    >>> from sympy.stats import Lomax, density, cdf, E
    >>> from sympy import symbols
    >>> a, l = symbols('a, l', positive=True)
    >>> X = Lomax('X', a, l)
    >>> x = symbols('x')
    >>> density(X)(x)
    a*(1 + x/l)**(-a - 1)/l
    >>> cdf(X)(x)
    Piecewise((1 - 1/(1 + x/l)**a, x >= 0), (0, True))
    >>> a = 2
    >>> X = Lomax('X', a, l)
    >>> E(X)
    l

    Returns
    =======

    RandomSymbol

    References
    ==========

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

    )r   r  )r   r   r   rn   rn   ro   rS   
     0rS   c                   @   r  )
MaxwellDistributionr   r   c                 C   r,  )Nr   zParameter a must be positive.r   r  rn   rn   ro   rv   E  ru   zMaxwellDistribution.checkc                 C   s<   | j }tdt |d  t|d  d|d    |d  S Nr   r   )r   r   r   r   r   rs   r   rn   rn   ro   r   I  s   6zMaxwellDistribution.pdfc                 C   sP   | j }ttd| d|  td| t|d  d|d    tt|   S r   )r   r#   r   r   r   r  rn   rn   ro   r   M     JzMaxwellDistribution._cdfNr  rn   rn   rn   ro   r  @  s    

r  c                 C   r  )a  
    Create a continuous random variable with a Maxwell distribution.

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

    The density of the Maxwell distribution is given by

    .. math::
        f(x) := \sqrt{\frac{2}{\pi}} \frac{x^2 e^{-x^2/(2a^2)}}{a^3}

    with :math:`x \geq 0`.

    .. TODO - what does the parameter mean?

    Parameters
    ==========

    a : Real number, `a > 0`

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Maxwell, density, E, variance
    >>> from sympy import Symbol, simplify

    >>> a = Symbol("a", positive=True)
    >>> z = Symbol("z")

    >>> X = Maxwell("x", a)

    >>> density(X)(z)
    sqrt(2)*z**2*exp(-z**2/(2*a**2))/(sqrt(pi)*a**3)

    >>> E(X)
    2*sqrt(2)*a/sqrt(pi)

    >>> simplify(variance(X))
    a**2*(-8 + 3*pi)/pi

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Maxwell_distribution
    .. [2] http://mathworld.wolfram.com/MaxwellDistribution.html

    )r   r  )r   r   rn   rn   ro   rT   Q  s   6rT   c                   @   s4   e Zd ZdZedd Zdd Zdd Zdd	 Zd
S )MoyalDistributionr|  c                 C   s$   t | jd t |jo|dkd d S )Nr   r   z1Scale parameter must be real        and positive.r   r|  rn   rn   ro   rv     s   zMoyalDistribution.checkc                 C   sN   | j | j}}tt||  | || |   d }tdt | }|| S r   )r2  r   r   r   r   )r   rs   r2  r   r   r   rn   rn   ro   r     s   (zMoyalDistribution.pdfc                 C   sZ   | j | j}}tt| | }dt | |  ttddt| |   }|| tt S r   )r2  r   r   r   r(   r   r   r   r   r   r2  r   r  r  rn   rn   ro   r     s   ,z*MoyalDistribution._characteristic_functionc                 C   sP   | j | j}}t|| }dd| |  ttdd||   }|| tt S )Nr   r'  r   )r2  r   r   r(   r   r   r   r  rn   rn   ro   r     s   &z-MoyalDistribution._moment_generating_functionN)	r   r   r   r   r   rv   r   r   r   rn   rn   rn   ro   r    s    
r  c                 C   r   )aw  
    Create a continuous random variable with a Moyal distribution.

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

    The density of the Moyal distribution is given by

    .. math::
        f(x) := \frac{\exp-\frac{1}{2}\exp-\frac{x-\mu}{\sigma}-\frac{x-\mu}{2\sigma}}{\sqrt{2\pi}\sigma}

    with :math:`x \in \mathbb{R}`.

    Parameters
    ==========

    mu : Real number
        Location parameter
    sigma : Real positive number
        Scale parameter

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Moyal, density, cdf
    >>> from sympy import Symbol, simplify
    >>> mu = Symbol("mu", real=True)
    >>> sigma = Symbol("sigma", positive=True, real=True)
    >>> z = Symbol("z")
    >>> X = Moyal("x", mu, sigma)
    >>> density(X)(z)
    sqrt(2)*exp(-exp((mu - z)/sigma)/2 - (-mu + z)/(2*sigma))/(2*sqrt(pi)*sigma)
    >>> simplify(cdf(X)(z))
    1 - erf(sqrt(2)*exp((mu - z)/(2*sigma))/2)

    References
    ==========

    .. [1] https://reference.wolfram.com/language/ref/MoyalDistribution.html
    .. [2] http://www.stat.rice.edu/~dobelman/textfiles/DistributionsHandbook.pdf

    )r   r  r  rn   rn   ro   rU     r   rU   c                   @   r  )
NakagamiDistributionr2  omegar   c                 C   s"   t | tjkd t |dkd d S )Nz5Shape parameter mu must be greater than equal to 1/2.r   z(Spread parameter omega must be positive.)r2   r   r   r  rn   rn   ro   rv     s   zNakagamiDistribution.checkc                 C   sP   | j | j}}d||  t|||   |d| d   t| | |d   S r   )r2  r  r(   r   r   rs   r2  r  rn   rn   ro   r     s   BzNakagamiDistribution.pdfc                 C   s@   | j | j}}tt||| |d  t| |dkftjdfS r  )r2  r  r!   r)   r(   r   r   r  rn   rn   ro   r     s
   $zNakagamiDistribution._cdfNr  rn   rn   rn   ro   r    rk  r  c                 C   r   )aF  
    Create a continuous random variable with a Nakagami distribution.

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

    The density of the Nakagami distribution is given by

    .. math::
        f(x) := \frac{2\mu^\mu}{\Gamma(\mu)\omega^\mu} x^{2\mu-1}
                \exp\left(-\frac{\mu}{\omega}x^2 \right)

    with :math:`x > 0`.

    Parameters
    ==========

    mu : Real number, `\mu \geq \frac{1}{2}`, a shape
    omega : Real number, `\omega > 0`, the spread

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Nakagami, density, E, variance, cdf
    >>> from sympy import Symbol, simplify, pprint

    >>> mu = Symbol("mu", positive=True)
    >>> omega = Symbol("omega", positive=True)
    >>> z = Symbol("z")

    >>> X = Nakagami("x", mu, omega)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
                                    2
                               -mu*z
                               -------
        mu      -mu  2*mu - 1  omega
    2*mu  *omega   *z        *e
    ----------------------------------
                Gamma(mu)

    >>> simplify(E(X))
    sqrt(mu)*sqrt(omega)*gamma(mu + 1/2)/gamma(mu + 1)

    >>> V = simplify(variance(X))
    >>> pprint(V, use_unicode=False)
                        2
             omega*Gamma (mu + 1/2)
    omega - -----------------------
            Gamma(mu)*Gamma(mu + 1)

    >>> cdf(X)(z)
    Piecewise((lowergamma(mu, mu*z**2/omega)/gamma(mu), z > 0),
            (0, True))


    References
    ==========

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

    )r   r  )r   r2  r  rn   rn   ro   rV     s   FrV   c                   @   r   )NormalDistributionr  c                 C   r  )Nr   z#Standard deviation must be positiver   r  rn   rn   ro   rv   @  ru   zNormalDistribution.checkc                 C   s4   t || j d  d| jd   tdt | j  S r   )r   r  r  r   r   r   rn   rn   ro   r   D  s   4zNormalDistribution.pdfc                 C   s6   | j | j}}ttd| |  d|  d tj S r   )r  r  r#   r   r   r   r  rn   rn   ro   r   G  r   zNormalDistribution._cdfc                 C   s2   | j | j}}tt| | |d |d  d  S r   )r  r  r   r   r   r   r  r  rn   rn   ro   r   K  ry  z+NormalDistribution._characteristic_functionc                 C   s.   | j | j}}t|| |d |d  d  S r   )r  r  r   r  rn   rn   ro   r   O  r  z.NormalDistribution._moment_generating_functionc                 C   s.   | j | j}}||td td| d   S r   )r  r  r   r&   )r   r   r  r  rn   rn   ro   r   S  r  zNormalDistribution._quantileNr   rn   rn   rn   ro   r  =  s    
r  c                 C   sT   t |tst|ddrt |tst|ddr"ddlm} || ||S t| t||fS )a  
    Create a continuous random variable with a Normal distribution.

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

    The density of the Normal distribution is given by

    .. math::
        f(x) := \frac{1}{\sigma\sqrt{2\pi}} e^{ -\frac{(x-\mu)^2}{2\sigma^2} }

    Parameters
    ==========

    mu : Real number or a list representing the mean or the mean vector
    sigma : Real number or a positive definite square matrix,
         :math:`\sigma^2 > 0`, the variance

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Normal, density, E, std, cdf, skewness, quantile, marginal_distribution
    >>> from sympy import Symbol, simplify, pprint

    >>> mu = Symbol("mu")
    >>> sigma = Symbol("sigma", positive=True)
    >>> z = Symbol("z")
    >>> y = Symbol("y")
    >>> p = Symbol("p")
    >>> X = Normal("x", mu, sigma)

    >>> density(X)(z)
    sqrt(2)*exp(-(-mu + z)**2/(2*sigma**2))/(2*sqrt(pi)*sigma)

    >>> C = simplify(cdf(X))(z) # it needs a little more help...
    >>> pprint(C, use_unicode=False)
       /  ___          \
       |\/ 2 *(-mu + z)|
    erf|---------------|
       \    2*sigma    /   1
    -------------------- + -
             2             2

    >>> quantile(X)(p)
    mu + sqrt(2)*sigma*erfinv(2*p - 1)

    >>> simplify(skewness(X))
    0

    >>> X = Normal("x", 0, 1) # Mean 0, standard deviation 1
    >>> density(X)(z)
    sqrt(2)*exp(-z**2/2)/(2*sqrt(pi))

    >>> E(2*X + 1)
    1

    >>> simplify(std(2*X + 1))
    2

    >>> m = Normal('X', [1, 2], [[2, 1], [1, 2]])
    >>> pprint(density(m)(y, z), use_unicode=False)
              2          2
             y    y*z   z
           - -- + --- - -- + z - 1
      ___    3     3    3
    \/ 3 *e
    ------------------------------
                 6*pi

    >>> marginal_distribution(m, m[0])(1)
     1/(2*sqrt(pi))


    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Normal_distribution
    .. [2] http://mathworld.wolfram.com/NormalDistributionFunction.html

    	is_MatrixFr   )MultivariateNormal)rp  rz   getattrrq  r  r   r  )r   r  r  r  rn   rn   ro   rW   X  s   W
rW   c                   @   rr  )GaussianInverseDistributionr  shapec                 C   s
   t dtS Nr   )r.   r   r   rn   rn   ro   r     r   zGaussianInverseDistribution.setc                 C   s    t |dkd t | dkd d S )Nr   z Shape parameter must be positivezMean must be positiver   r  rn   rn   ro   rv     r   z!GaussianInverseDistribution.checkc                 C   sL   | j | j}}t| || d  d| |d   t|dt |d    S r  )r  r  r   r   r   r  rn   rn   ro   r     s   >zGaussianInverseDistribution.pdfc                 C   s   ddl m} | j| j}}|tddd}|t|| || tj  }td| | |t||  || tj   }|| S )Nr   r  rs   r   r   )	r!  r   r  r  rW   r   r   r   r   )r   rs   r   r2  r@  stdNormalcdf
first_termsecond_termrn   rn   ro   r     s   0z GaussianInverseDistribution._cdfc                 C   s>   | j | j}}t|| dtdd|d  t | |    S r   )r  r  r   r   r   r   r   r2  r@  rn   rn   ro   r     r  z4GaussianInverseDistribution._characteristic_functionc                 C   s:   | j | j}}t|| dtdd|d  | |    S r   )r  r  r   r   r  rn   rn   ro   r     rM  z7GaussianInverseDistribution._moment_generating_functionNrz  rn   rn   rn   ro   r    s    


r  c                 C   r   )a  
    Create a continuous random variable with an Inverse Gaussian distribution.
    Inverse Gaussian distribution is also known as Wald distribution.

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

    The density of the Inverse Gaussian distribution is given by

    .. math::
        f(x) := \sqrt{\frac{\lambda}{2\pi x^3}} e^{-\frac{\lambda(x-\mu)^2}{2x\mu^2}}

    Parameters
    ==========

    mu :
        Positive number representing the mean.
    lambda :
        Positive number representing the shape parameter.

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import GaussianInverse, density, E, std, skewness
    >>> from sympy import Symbol, pprint

    >>> mu = Symbol("mu", positive=True)
    >>> lamda = Symbol("lambda", positive=True)
    >>> z = Symbol("z", positive=True)
    >>> X = GaussianInverse("x", mu, lamda)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
                                       2
                      -lambda*(-mu + z)
                      -------------------
                                2
      ___   ________        2*mu *z
    \/ 2 *\/ lambda *e
    -------------------------------------
                    ____  3/2
                2*\/ pi *z

    >>> E(X)
    mu

    >>> std(X).expand()
    mu**(3/2)/sqrt(lambda)

    >>> skewness(X).expand()
    3*sqrt(mu)/sqrt(lambda)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Inverse_Gaussian_distribution
    .. [2] http://mathworld.wolfram.com/InverseGaussianDistribution.html

    )r   r  )r   r  r  rn   rn   ro   rX     r  rX   c                   @   rr  )ParetoDistributionxmr   c                 C   r   rj   )r.   r  r   r   rn   rn   ro   r   *  r   zParetoDistribution.setc                 C   r   )Nr   zXm must be positiveAlpha must be positiver   r  rn   rn   ro   rv   .  r   zParetoDistribution.checkc                 C   s&   | j | j}}|||  ||d   S r   r  r   rs   r  r   rn   rn   ro   r   3  rw  zParetoDistribution.pdfc                 C   s2   | j | j}}ttj|| ||   ||kfdS )Nr   )r  r   r!   r   r   r  rn   rn   ro   r   7  s
   zParetoDistribution._cdfc                 C   s2   | j | j}}|| | |  t| | |  S rj   )r  r   r*   r   r   r  r   rn   rn   ro   r   >  ry  z.ParetoDistribution._moment_generating_functionc                 C   s:   | j | j}}|t | | |  t| t | |  S rj   )r  r   r   r*   r  rn   rn   ro   r   B  rM  z+ParetoDistribution._characteristic_functionN)r   r   r   r   r   r   r   rv   r   r   r   r   rn   rn   rn   ro   r  '  s    

r  c                 C   r   )a  
    Create a continuous random variable with the Pareto distribution.

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

    The density of the Pareto distribution is given by

    .. math::
        f(x) := \frac{\alpha\,x_m^\alpha}{x^{\alpha+1}}

    with :math:`x \in [x_m,\infty]`.

    Parameters
    ==========

    xm : Real number, `x_m > 0`, a scale
    alpha : Real number, `\alpha > 0`, a shape

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Pareto, density
    >>> from sympy import Symbol

    >>> xm = Symbol("xm", positive=True)
    >>> beta = Symbol("beta", positive=True)
    >>> z = Symbol("z")

    >>> X = Pareto("x", xm, beta)

    >>> density(X)(z)
    beta*xm**beta*z**(-beta - 1)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Pareto_distribution
    .. [2] http://mathworld.wolfram.com/ParetoDistribution.html

    )r   r  )r   r  r   rn   rn   ro   rY   G  r  rY   c                   @   r   )	PowerFunctionDistributionr   r   r   c                 C   r   rj   r   r   rn   rn   ro   r     r   zPowerFunctionDistribution.setc                 C   s6   t |jd t |jd t ||k d t | jd d S )Nz-Continuous Boundary parameter should be real.zC 'a' the left Boundary must be smaller than 'b' the right Boundary.z.Continuous Shape parameter should be positive.r  r  rn   rn   ro   rv     s   zPowerFunctionDistribution.checkc                 C   s>   | j | j| j}}}||| |d   }|| | }|| S r   r  )r   rs   r   r   r   r   r   rn   rn   ro   r     s   zPowerFunctionDistribution.pdfNr   rn   rn   rn   ro   r  }  s    

r  c                 C   r   )a5  
    Creates a continuous random variable with a Power Function Distribution.

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

    The density of PowerFunction distribution is given by

    .. math::
        f(x) := \frac{{\alpha}(x - a)^{\alpha - 1}}{(b - a)^{\alpha}}

    with :math:`x \in [a,b]`.

    Parameters
    ==========

    alpha : Positive number, `0 < \alpha`, the shape paramater
    a : Real number, :math:`-\infty < a`, the left boundary
    b : Real number, :math:`a < b < \infty`, the right boundary

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import PowerFunction, density, cdf, E, variance
    >>> from sympy import Symbol
    >>> alpha = Symbol("alpha", positive=True)
    >>> a = Symbol("a", real=True)
    >>> b = Symbol("b", real=True)
    >>> z = Symbol("z")

    >>> X = PowerFunction("X", 2, a, b)

    >>> density(X)(z)
    (-2*a + 2*z)/(-a + b)**2

    >>> cdf(X)(z)
    Piecewise((a**2/(a**2 - 2*a*b + b**2) - 2*a*z/(a**2 - 2*a*b + b**2) +
    z**2/(a**2 - 2*a*b + b**2), a <= z), (0, True))

    >>> alpha = 2
    >>> a = 0
    >>> b = 1
    >>> Y = PowerFunction("Y", alpha, a, b)

    >>> E(Y)
    2/3

    >>> variance(Y)
    1/18

    References
    ==========

    .. [1] http://www.mathwave.com/help/easyfit/html/analyses/distributions/power_func.html

    )r   r  )r   r   r   r   rn   rn   ro   rZ     r4  rZ   c                   @   @   e Zd ZdZedd Zedd Zdd Zdd	 Z	d
d Z
dS )QuadraticUDistributionr   c                 C   r   rj   r   r   rn   rn   ro   r     r   zQuadraticUDistribution.setc                 C   s   t || kd|   d S )Nz&Parameter b must be in range (%s, oo).r   r   rn   rn   ro   rv     s   zQuadraticUDistribution.checkc                 C   sX   | j | j}}d|| d  }|| d }t||| d  t||k||kftjdfS )N   r   r   T)r   r   r!   r-   r   r   )r   rs   r   r   r   r
   rn   rn   ro   r     s    zQuadraticUDistribution.pdfc                 C   s   | j | j}}dt|| d|d d| d|   |d  |   t|| dd| || d  |     || d |d   S )N   r   rx  rN  r   )r   r   r   rO  rn   rn   ro   r     s   4&z2QuadraticUDistribution._moment_generating_functionc                 C   sj   | j | j}}dt tt| | tt| |  dt d| || d  |    || d |d   S )Nr  r  rN  r   r   )r   r   r   r   rO  rn   rn   ro   r     s   Fz/QuadraticUDistribution._characteristic_functionN)r   r   r   r   r   r   r   rv   r   r   r   rn   rn   rn   ro   r    s    

r  c                 C   r   )a  
    Create a Continuous Random Variable with a U-quadratic distribution.

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

    The density of the U-quadratic distribution is given by

    .. math::
        f(x) := \alpha (x-\beta)^2

    with :math:`x \in [a,b]`.

    Parameters
    ==========

    a : Real number
    b : Real number, :math:`a < b`

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import QuadraticU, density
    >>> from sympy import Symbol, pprint

    >>> a = Symbol("a", real=True)
    >>> b = Symbol("b", real=True)
    >>> z = Symbol("z")

    >>> X = QuadraticU("x", a, b)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
    /                2
    |   /  a   b    \
    |12*|- - - - + z|
    |   \  2   2    /
    <-----------------  for And(b >= z, a <= z)
    |            3
    |    (-a + b)
    |
    \        0                 otherwise

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/U-quadratic_distribution

    )r   r  r   rn   rn   ro   r[        8r[   c                   @   r  )RaisedCosineDistributionr  c                 C   s   t | j| j | j| j S rj   )r.   r2  r@  r   rn   rn   ro   r   4  s   zRaisedCosineDistribution.setc                 C   r  )Nr   zs must be positiver   r  rn   rn   ro   rv   8  ru   zRaisedCosineDistribution.checkc                 C   sT   | j | j}}tdtt||  |  d|  t|| |k||| kftjdfS )Nr   r   T)r2  r@  r!   r   r   r-   r   r   r  rn   rn   ro   r   <  s
   8zRaisedCosineDistribution.pdfc              	   C   s   | j | j}}ttt t | | d t|t | fttt | | d t|t| ftd t||  tt| |  || td |d |d     dfS r   )r2  r@  r!   r   r   r   r   r   r  rn   rn   ro   r   B  s
   *$Fz1RaisedCosineDistribution._characteristic_functionc                 C   sN   | j | j}}td t||  t||  || td |d |d     S r   )r2  r@  r   r   r   r  rn   rn   ro   r   H  s   @z4RaisedCosineDistribution._moment_generating_functionNr   r   r   r   r   r   r   rv   r   r   r   rn   rn   rn   ro   r  1  s    

r  c                 C   r   )a.  
    Create a Continuous Random Variable with a raised cosine distribution.

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

    The density of the raised cosine distribution is given by

    .. math::
        f(x) := \frac{1}{2s}\left(1+\cos\left(\frac{x-\mu}{s}\pi\right)\right)

    with :math:`x \in [\mu-s,\mu+s]`.

    Parameters
    ==========

    mu : Real number
    s : Real number, `s > 0`

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import RaisedCosine, density
    >>> from sympy import Symbol, pprint

    >>> mu = Symbol("mu", real=True)
    >>> s = Symbol("s", positive=True)
    >>> z = Symbol("z")

    >>> X = RaisedCosine("x", mu, s)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
    /   /pi*(-mu + z)\
    |cos|------------| + 1
    |   \     s      /
    <---------------------  for And(z >= mu - s, z <= mu + s)
    |         2*s
    |
    \          0                        otherwise

    References
    ==========

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

    )r   r  r  rn   rn   ro   r\   L  s   6r\   c                   @   rF  )RayleighDistributionr   r   c                 C   r,  )Nr   z'Scale parameter sigma must be positive.r   r  rn   rn   ro   rv     ru   zRayleighDistribution.checkc                 C   s,   | j }||d  t|d  d|d    S r   r   r   r   rs   r   rn   rn   ro   r     s   &zRayleighDistribution.pdfc                 C   s$   | j }dt|d d|d     S r   r  r  rn   rn   ro   r     s   zRayleighDistribution._cdfc                 C   sP   | j }d|| t|d  |d  d  ttd  t|| td t   S r   )r   r   r   r   r%   r   r   r   r   rn   rn   ro   r     r  z-RayleighDistribution._characteristic_functionc                 C   sN   | j }d|| t|d |d  d  ttd  t|| td d   S r   )r   r   r   r   r#   r  rn   rn   ro   r     s   Hz0RayleighDistribution._moment_generating_functionNr)  rn   rn   rn   ro   r    s    

r  c                 C   r  )a  
    Create a continuous random variable with a Rayleigh distribution.

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

    The density of the Rayleigh distribution is given by

    .. math ::
        f(x) := \frac{x}{\sigma^2} e^{-x^2/2\sigma^2}

    with :math:`x > 0`.

    Parameters
    ==========

    sigma : Real number, `\sigma > 0`

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Rayleigh, density, E, variance
    >>> from sympy import Symbol

    >>> sigma = Symbol("sigma", positive=True)
    >>> z = Symbol("z")

    >>> X = Rayleigh("x", sigma)

    >>> density(X)(z)
    z*exp(-z**2/(2*sigma**2))/sigma**2

    >>> E(X)
    sqrt(2)*sqrt(pi)*sigma/2

    >>> variance(X)
    -pi*sigma**2/2 + 2*sigma**2

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Rayleigh_distribution
    .. [2] http://mathworld.wolfram.com/RayleighDistribution.html

    )r   r  )r   r   rn   rn   ro   r]     s   4r]   c                   @   r   )	ReciprocalDistributionr   c                 C   r   rj   r   r   rn   rn   ro   r     r   zReciprocalDistribution.setc                 C   s,   t | dkd|   t | |k d| |f  d S )Nr   zParameter > 0. a = %sz.Parameter b must be in range (%s, +oo]. b = %sr   r   rn   rn   ro   rv     s   
zReciprocalDistribution.checkc                 C   s&   | j | j}}d|t|t|   S r   )r   r   r   r   rn   rn   ro   r     rw  zReciprocalDistribution.pdfNr   rn   rn   rn   ro   r    r   r  c                 C   r   )a  Creates a continuous random variable with a reciprocal distribution.


    Parameters
    ==========

    a : Real number, :math:`0 < a`
    b : Real number, :math:`a < b`

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Reciprocal, density, cdf
    >>> from sympy import symbols
    >>> a, b, x = symbols('a, b, x', positive=True)
    >>> R = Reciprocal('R', a, b)

    >>> density(R)(x)
    1/(x*(-log(a) + log(b)))
    >>> cdf(R)(x)
    Piecewise((log(a)/(log(a) - log(b)) - log(x)/(log(a) - log(b)), a <= x), (0, True))

    Reference
    =========

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

    )r   r  r   rn   rn   ro   r^     s   "r^   c                   @   r  )ShiftedGompertzDistributionr_  r   c                 C   r   ra  r   r_  rn   rn   ro   rv     r   z!ShiftedGompertzDistribution.checkc                 C   sR   | j | j}}|t| |  t| t| |   d|dt| |     S r   )r   r`  r   )r   rs   r   r`  rn   rn   ro   r      s   DzShiftedGompertzDistribution.pdfNr=  rn   rn   rn   ro   r        

r  c                 C   r   )a  
    Create a continuous random variable with a Shifted Gompertz distribution.

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

    The density of the Shifted Gompertz distribution is given by

    .. math::
        f(x) := b e^{-b x} e^{-\eta \exp(-b x)} \left[1 + \eta(1 - e^(-bx)) \right]

    with :math:`x \in [0, \infty)`.

    Parameters
    ==========

    b : Real number, `b > 0`, a scale
    eta : Real number, `\eta > 0`, a shape

    Returns
    =======

    RandomSymbol

    Examples
    ========
    >>> from sympy.stats import ShiftedGompertz, density
    >>> from sympy import Symbol

    >>> b = Symbol("b", positive=True)
    >>> eta = Symbol("eta", positive=True)
    >>> x = Symbol("x")

    >>> X = ShiftedGompertz("x", b, eta)

    >>> density(X)(x)
    b*(eta*(1 - exp(-b*x)) + 1)*exp(-b*x)*exp(-eta*exp(-b*x))

    References
    ==========

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

    )r   r  rg  rn   rn   ro   r`   $  s   -r`   c                   @   s@   e Zd ZdZee eZedd Zdd Z	dd Z
dd	 Zd
S )StudentTDistributionnuc                 C   r,  )Nr   z'Degrees of freedom nu must be positive.r   r  rn   rn   ro   rv   \  ru   zStudentTDistribution.checkc                 C   s@   | j }dt|ttj|d   d|d |  |d  d   S r   )r  r   r   r   r   r   rs   r  rn   rn   ro   r   `  r  zStudentTDistribution.pdfc                 C   sd   | j }tj|t|d d  ttj|d d ftddf|d  |  tt| t|d    S )Nr   r   r   )r  r   r   r(   r+   r   r   r   r  rn   rn   ro   r   d  s   (zStudentTDistribution._cdfc                 C   r   )NzKThe moment generating function for the Student-T distribution is undefined.r   r   rn   rn   ro   r   i  r   z0StudentTDistribution._moment_generating_functionNrf  rn   rn   rn   ro   r  W  s    
r  c                 C   r  )a0  
    Create a continuous random variable with a student's t distribution.

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

    The density of the student's t distribution is given by

    .. math::
        f(x) := \frac{\Gamma \left(\frac{\nu+1}{2} \right)}
                {\sqrt{\nu\pi}\Gamma \left(\frac{\nu}{2} \right)}
                \left(1+\frac{x^2}{\nu} \right)^{-\frac{\nu+1}{2}}

    Parameters
    ==========

    nu : Real number, `\nu > 0`, the degrees of freedom

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import StudentT, density, cdf
    >>> from sympy import Symbol, pprint

    >>> nu = Symbol("nu", positive=True)
    >>> z = Symbol("z")

    >>> X = StudentT("x", nu)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
               nu   1
             - -- - -
               2    2
     /     2\
     |    z |
     |1 + --|
     \    nu/
    -----------------
      ____  /     nu\
    \/ nu *B|1/2, --|
            \     2 /

    >>> cdf(X)(z)
    1/2 + z*gamma(nu/2 + 1/2)*hyper((1/2, nu/2 + 1/2), (3/2,),
                                -z**2/nu)/(sqrt(pi)*sqrt(nu)*gamma(nu/2))


    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Student_t-distribution
    .. [2] http://mathworld.wolfram.com/Studentst-Distribution.html

    )r   r  )r   r  rn   rn   ro   r_   m  s   >r_   c                   @   r   )	TrapezoidalDistributionr   r   ru  dc                 C   r   rj   )r.   r   r  r   rn   rn   ro   r     r   zTrapezoidalDistribution.setc                 C   sp   t | |k d|| f  t | |k||k fd| ||f  t ||k ||kfd|||f  t ||kd||f  d S )Nz$Lower bound parameter a < %s. a = %sz9Level start parameter b must be in range [%s, %s). b = %sz7Level end parameter c must be in range (%s, %s]. c = %sz$Upper bound parameter d > %s. d = %sr   r  rn   rn   ro   rv     s   zTrapezoidalDistribution.checkc                 C   s   | j | j| j| jf\}}}}td||  || || | |   t||k||k fd|| | |  t||k||k fd||  || || | |   t||k||kftjdfS r   )r   r   ru  r  r!   r-   r   r   )r   rs   r   r   ru  r  rn   rn   ro   r     s   4$4zTrapezoidalDistribution.pdfNr   rn   rn   rn   ro   r    s    

r  c                 C   s   t | t||||fS )a;  
    Create a continuous random variable with a trapezoidal distribution.

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

    The density of the trapezoidal distribution is given by

    .. math::
        f(x) := \begin{cases}
                  0 & \mathrm{for\ } x < a, \\
                  \frac{2(x-a)}{(b-a)(d+c-a-b)} & \mathrm{for\ } a \le x < b, \\
                  \frac{2}{d+c-a-b} & \mathrm{for\ } b \le x < c, \\
                  \frac{2(d-x)}{(d-c)(d+c-a-b)} & \mathrm{for\ } c \le x < d, \\
                  0 & \mathrm{for\ } d < x.
                \end{cases}

    Parameters
    ==========

    a : Real number, :math:`a < d`
    b : Real number, :math:`a \le b < c`
    c : Real number, :math:`b < c \le d`
    d : Real number

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Trapezoidal, density
    >>> from sympy import Symbol, pprint

    >>> a = Symbol("a")
    >>> b = Symbol("b")
    >>> c = Symbol("c")
    >>> d = Symbol("d")
    >>> z = Symbol("z")

    >>> X = Trapezoidal("x", a,b,c,d)

    >>> pprint(density(X)(z), use_unicode=False)
    /        -2*a + 2*z
    |-------------------------  for And(a <= z, b > z)
    |(-a + b)*(-a - b + c + d)
    |
    |           2
    |     --------------        for And(b <= z, c > z)
    <     -a - b + c + d
    |
    |        2*d - 2*z
    |-------------------------  for And(d >= z, c <= z)
    |(-c + d)*(-a - b + c + d)
    |
    \            0                     otherwise

    References
    ==========

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

    )r   r  )r   r   r   ru  r  rn   rn   ro   ra     s   Bra   c                   @   r  )TriangularDistributionr   r   ru  c                 C   r   rj   r   r   rn   rn   ro   r     r   zTriangularDistribution.setc                 C   s:   t || kd| |f  t | |k||kfd| ||f  d S )NzParameter b > %s. b = %sz-Parameter c must be in range [%s, %s]. c = %sr   r  rn   rn   ro   rv     s   zTriangularDistribution.checkc                 C   s   | j | j| j}}}td||  || ||   t||k||k fd||  t||fd||  || ||   t||k ||kftjdfS r   )r   r   ru  r!   r-   r   r   r   )r   rs   r   r   ru  rn   rn   ro   r     s   ,,zTriangularDistribution.pdfc                 C   s   | j | j| j}}}d|| tt| |  || tt| |   || tt| |    || ||  ||  |d   S )Nrx  r   )r   r   ru  r   r   r   r   r   r   ru  rn   rn   ro   r   &  s   lz/TriangularDistribution._characteristic_functionc                 C   sv   | j | j| j}}}d|| t||  || t||   || t||    || ||  ||  |d   S r   )r   r   ru  r   r  rn   rn   ro   r   *  s   >z2TriangularDistribution._moment_generating_functionNr  rn   rn   rn   ro   r    s    

r  c                 C   r   )a  
    Create a continuous random variable with a triangular distribution.

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

    The density of the triangular distribution is given by

    .. math::
        f(x) := \begin{cases}
                  0 & \mathrm{for\ } x < a, \\
                  \frac{2(x-a)}{(b-a)(c-a)} & \mathrm{for\ } a \le x < c, \\
                  \frac{2}{b-a} & \mathrm{for\ } x = c, \\
                  \frac{2(b-x)}{(b-a)(b-c)} & \mathrm{for\ } c < x \le b, \\
                  0 & \mathrm{for\ } b < x.
                \end{cases}

    Parameters
    ==========

    a : Real number, :math:`a \in \left(-\infty, \infty\right)`
    b : Real number, :math:`a < b`
    c : Real number, :math:`a \leq c \leq b`

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Triangular, density
    >>> from sympy import Symbol, pprint

    >>> a = Symbol("a")
    >>> b = Symbol("b")
    >>> c = Symbol("c")
    >>> z = Symbol("z")

    >>> X = Triangular("x", a,b,c)

    >>> pprint(density(X)(z), use_unicode=False)
    /    -2*a + 2*z
    |-----------------  for And(a <= z, c > z)
    |(-a + b)*(-a + c)
    |
    |       2
    |     ------              for c = z
    <     -a + b
    |
    |   2*b - 2*z
    |----------------   for And(b >= z, c < z)
    |(-a + b)*(b - c)
    |
    \        0                otherwise

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Triangular_distribution
    .. [2] http://mathworld.wolfram.com/TriangularDistribution.html

    )r   r  )r   r   r   ru  rn   rn   ro   rb   0  s   Brb   c                   @   sP   e Zd ZdZedd Zedd Zdd Zdd	 Z	d
d Z
dd Zdd ZdS )UniformDistributionr   r   c                 C   r   rj   r   r   rn   rn   ro   r   {  r   zUniformDistribution.setc                 C   s   t | |k d d S )Nz,Lower limit should be less than Upper limit.r   r  rn   rn   ro   rv     ru   zUniformDistribution.checkc                 C   s:   | j | j}}ttj||  t||k||kftjdfS rD  )r   r   r!   r   r   r-   r   r   rs   r   r   rn   rn   ro   r     s
   zUniformDistribution.pdfc                 C   s>   | j | j}}ttj||k f|| ||  ||kftjdfS rD  )r   r   r!   r   r   r   r  rn   rn   ro   r     s   zUniformDistribution._cdfc                 C   sT   | j | j}}ttt| | tt| |  t| ||   t|dftjdfS r  )r   r   r!   r   r   r   r   r   r   r   r   r   rn   rn   ro   r     s   :z,UniformDistribution._characteristic_functionc                 C   sH   | j | j}}tt|| t||  |||   t|dftjdfS r  )r   r   r!   r   r   r   r   r  rn   rn   ro   r     s   .z/UniformDistribution._moment_generating_functionc                 K   sL   d|d< t j| ||fi |}|t| j| j| jt| j| j| ji}|S )NTevaluate)r1   r  subsr   r   r   r    )r   r  r  r   resultrn   rn   ro   r    s   zUniformDistribution.expectationN)r   r   r   r   r   r   r   rv   r   r   r   r   r  rn   rn   rn   ro   r  x  s    

r  c                 C   r   )a  
    Create a continuous random variable with a uniform distribution.

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

    The density of the uniform distribution is given by

    .. math::
        f(x) := \begin{cases}
                  \frac{1}{b - a} & \text{for } x \in [a,b]  \\
                  0               & \text{otherwise}
                \end{cases}

    with :math:`x \in [a,b]`.

    Parameters
    ==========

    a : Real number, :math:`-\infty < a`, the left boundary
    b : Real number, :math:`a < b < \infty`, the right boundary

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Uniform, density, cdf, E, variance
    >>> from sympy import Symbol, simplify

    >>> a = Symbol("a", negative=True)
    >>> b = Symbol("b", positive=True)
    >>> z = Symbol("z")

    >>> X = Uniform("x", a, b)

    >>> density(X)(z)
    Piecewise((1/(-a + b), (b >= z) & (a <= z)), (0, True))

    >>> cdf(X)(z)
    Piecewise((0, a > z), ((-a + z)/(-a + b), b >= z), (1, True))

    >>> E(X)
    a/2 + b/2

    >>> simplify(variance(X))
    a**2/12 - a*b/6 + b**2/12

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29
    .. [2] http://mathworld.wolfram.com/UniformDistribution.html

    )r   r  )r   r   r   rn   rn   ro   rc     s   <rc   c                   @   rr  )UniformSumDistributionnc                 C   s   t d| jS r  )r.   r  r   rn   rn   ro   r     r   zUniformSumDistribution.setc                 C   s   t | dk| jfd d S )Nr   z%Parameter n must be positive integer.r   r  rn   rn   ro   rv     s   zUniformSumDistribution.checkc                 C   sP   | j }td}dt|d  td| t|| || |d   |dt|f S )Nr   r   r'  r   )r  r   r   r   r   r   r   rs   r  r   rn   rn   ro   r     s   0zUniformSumDistribution.pdfc              	   C   sh   | j }td}ttj|dk fdt| td| t|| || |  |dt|f ||kftj	dfS )Nr   r   r   r'  T)
r  r   r!   r   r   r   r   r   r   r   r  rn   rn   ro   r     s   (zUniformSumDistribution._cdfc                 C   s   t t| d t|  | j S r   )r   r   r  r   rn   rn   ro   r      r   z/UniformSumDistribution._characteristic_functionc                 C   s   t |d | | j S r   )r   r  r   rn   rn   ro   r     r-  z2UniformSumDistribution._moment_generating_functionNrz  rn   rn   rn   ro   r    s    

r  c                 C   r  )aW  
    Create a continuous random variable with an Irwin-Hall distribution.

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

    The probability distribution function depends on a single parameter
    $n$ which is an integer.

    The density of the Irwin-Hall distribution is given by

    .. math ::
        f(x) := \frac{1}{(n-1)!}\sum_{k=0}^{\left\lfloor x\right\rfloor}(-1)^k
                \binom{n}{k}(x-k)^{n-1}

    Parameters
    ==========

    n : A positive integer, `n > 0`

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import UniformSum, density, cdf
    >>> from sympy import Symbol, pprint

    >>> n = Symbol("n", integer=True)
    >>> z = Symbol("z")

    >>> X = UniformSum("x", n)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
    floor(z)
      ___
      \  `
       \         k         n - 1 /n\
        )    (-1) *(-k + z)     *| |
       /                         \k/
      /__,
     k = 0
    --------------------------------
                (n - 1)!

    >>> cdf(X)(z)
    Piecewise((0, z < 0), (Sum((-1)**_k*(-_k + z)**n*binomial(n, _k),
                    (_k, 0, floor(z)))/factorial(n), n >= z), (1, True))


    Compute cdf with specific 'x' and 'n' values as follows :
    >>> cdf(UniformSum("x", 5), evaluate=False)(2).doit()
    9/40

    The argument evaluate=False prevents an attempt at evaluation
    of the sum for general n, before the argument 2 is passed.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Uniform_sum_distribution
    .. [2] http://mathworld.wolfram.com/UniformSumDistribution.html

    )r   r  )r   r  rn   rn   ro   rd     s   Frd   c                   @   s2   e Zd ZdZedde Zedd Zdd Z	dS )	VonMisesDistributionr2  r   r   r   c                 C   r  )Nr   rI  r   r  rn   rn   ro   rv   W  ru   zVonMisesDistribution.checkc                 C   s4   | j | j}}t|t||  dt td|  S )Nr   r   )r2  r   r   r   r   r   )r   rs   r2  r   rn   rn   ro   r   [  r   zVonMisesDistribution.pdfN)
r   r   r   r   r.   r   r   r   rv   r   rn   rn   rn   ro   r  R  s    
r  c                 C   r   )a  
    Create a Continuous Random Variable with a von Mises distribution.

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

    The density of the von Mises distribution is given by

    .. math::
        f(x) := \frac{e^{\kappa\cos(x-\mu)}}{2\pi I_0(\kappa)}

    with :math:`x \in [0,2\pi]`.

    Parameters
    ==========

    mu : Real number
        Measure of location.
    k : Real number
        Measure of concentration.

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import VonMises, density
    >>> from sympy import Symbol, pprint

    >>> mu = Symbol("mu")
    >>> k = Symbol("k", positive=True)
    >>> z = Symbol("z")

    >>> X = VonMises("x", mu, k)

    >>> D = density(X)(z)
    >>> pprint(D, use_unicode=False)
         k*cos(mu - z)
        e
    ------------------
    2*pi*besseli(0, k)


    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Von_Mises_distribution
    .. [2] http://mathworld.wolfram.com/vonMisesDistribution.html

    )r   r  )r   r2  r   rn   rn   ro   re   _  r   re   c                   @   r  )WeibullDistributionr   r   c                 C   r   )Nr   r  zBeta must be positiver   r   rn   rn   ro   rv     r   zWeibullDistribution.checkc                 C   s8   | j | j}}||| |d   t|| |   | S r   )r   r
   r   r   rn   rn   ro   r     rK  zWeibullDistribution.pdfNr=  rn   rn   rn   ro   r    r  r  c                 C   r   )a  
    Create a continuous random variable with a Weibull distribution.

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

    The density of the Weibull distribution is given by

    .. math::
        f(x) := \begin{cases}
                  \frac{k}{\lambda}\left(\frac{x}{\lambda}\right)^{k-1}
                  e^{-(x/\lambda)^{k}} & x\geq0\\
                  0 & x<0
                \end{cases}

    Parameters
    ==========

    lambda : Real number, $\lambda > 0$, a scale
    k : Real number, $k > 0$, a shape

    Returns
    =======

    RandomSymbol

    Examples
    ========

    >>> from sympy.stats import Weibull, density, E, variance
    >>> from sympy import Symbol, simplify

    >>> l = Symbol("lambda", positive=True)
    >>> k = Symbol("k", positive=True)
    >>> z = Symbol("z")

    >>> X = Weibull("x", l, k)

    >>> density(X)(z)
    k*(z/lambda)**(k - 1)*exp(-(z/lambda)**k)/lambda

    >>> simplify(E(X))
    lambda*gamma(1 + 1/k)

    >>> simplify(variance(X))
    lambda**2*(-gamma(1 + 1/k)**2 + gamma(1 + 2/k))

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Weibull_distribution
    .. [2] http://mathworld.wolfram.com/WeibullDistribution.html

    )r   r  r   rn   rn   ro   rg     r  rg   c                   @   r  )WignerSemicircleDistributionRc                 C   s   t | j | jS rj   )r.   r  r   rn   rn   ro   r     s   z WignerSemicircleDistribution.setc                 C   r,  )Nr   zRadius R must be positive.r   r  rn   rn   ro   rv     ru   z"WignerSemicircleDistribution.checkc                 C   s*   | j }dt|d   t|d |d   S r   )r  r   r   )r   rs   r  rn   rn   ro   r     s   $z WignerSemicircleDistribution.pdfc                 C   4   t dtd| j|  | j|  t|dftjdfS Nr   r   r   T)r!   r   r  r   r   r   r   rn   rn   ro   r        (z5WignerSemicircleDistribution._characteristic_functionc                 C   r  r  )r!   r   r  r   r   r   r   rn   rn   ro   r     r  z8WignerSemicircleDistribution._moment_generating_functionNr  rn   rn   rn   ro   r    s    

r  c                 C   r  )af  
    Create a continuous random variable with a Wigner semicircle distribution.

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

    The density of the Wigner semicircle distribution is given by

    .. math::
        f(x) := \frac2{\pi R^2}\,\sqrt{R^2-x^2}

    with :math:`x \in [-R,R]`.

    Parameters
    ==========

    R : Real number, `R > 0`, the radius

    Returns
    =======

    A RandomSymbol.

    Examples
    ========

    >>> from sympy.stats import WignerSemicircle, density, E
    >>> from sympy import Symbol

    >>> R = Symbol("R", positive=True)
    >>> z = Symbol("z")

    >>> X = WignerSemicircle("x", R)

    >>> density(X)(z)
    2*sqrt(R**2 - z**2)/(pi*R**2)

    >>> E(X)
    0

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Wigner_semicircle_distribution
    .. [2] http://mathworld.wolfram.com/WignersSemicircleLaw.html

    )r   r  )r   r  rn   rn   ro   rh      s   1rh   N)r   r   rE  )F)__doc__&sympy.functions.elementary.exponentialr   (sympy.functions.elementary.trigonometricr   r   r   r   sympy.functions.special.besselr   r   r	   &sympy.functions.special.beta_functionsr
   r   sympy.concrete.summationsr   sympy.core.basicr   sympy.core.functionr   sympy.core.numbersr   r   r   sympy.core.relationalr   r   sympy.core.singletonr   sympy.core.symbolr   sympy.core.sympifyr   (sympy.functions.combinatorial.factorialsr   r   $sympy.functions.elementary.complexesr   r   r   %sympy.functions.elementary.hyperbolicr   #sympy.functions.elementary.integersr   (sympy.functions.elementary.miscellaneousr   r   r    $sympy.functions.elementary.piecewiser!   r"   'sympy.functions.special.error_functionsr#   r$   r%   r&   r'   'sympy.functions.special.gamma_functionsr(   r)   r*   sympy.functions.special.hyperr+   sympy.integrals.integralsr,   sympy.logic.boolalgr-   sympy.sets.setsr.   sympy.matricesr/   sympy.stats.crvr0   r1   sympy.stats.rvr2   r3   Infinityr   __all__registerrt   r   r   r4   r   r5   r   r6   r   r7   r   r8   r   r9   r   r:   r   r;   r   r<   r  r=   r	  r>   r  r?   r@   r  rA   r*  rB   r0  rC   r5  rD   r<  rE   r>  rF   r  rG   rL  rH   rP  rJ   r^  rI   ri  rK   rl  rL   rs  rM   r{  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rW   r  rX   rf   r  rY   r  rZ   r  r[   r  r\   r  r]   r  r^   r  r`   r  r_   r  ra   r  rb   r  rc   r  rd   r  re   r  rg   r  rh   rn   rn   rn   ro   <module>   s   <8
:
8B=K53148>?I)MOE?B
;OA
!@4;E437EAG6:7Lb#D 6D><9)3DHH,B L=>