§
    OŠtjé1  ã                   ó¶   — d dl mZ d dlmZ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„Z G d„ d	e¦  «        Z G d
„ de¦  «        Z G d„ de¦  «        ZdS )é    )ÚS)ÚDefinedFunctionÚArgumentIndexError)ÚDummyÚuniquely_named_symbol)ÚgammaÚdigamma)Úcatalan)Ú	conjugatec                 óR   — ddl m}m} ||k    r |d¦  «        S  || ||||¦  «        S )Nr   )ÚbetaincÚmpf)Úmpmathr   r   )ÚaÚbÚx1Úx2Úregr   r   s          úd/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/functions/special/beta_functions.pyÚbetainc_mpmath_fixr   	   sH   € Ø#Ð#Ð#Ð#Ð#Ð#Ð#Ð#Ø	ˆR‚x€xØˆs�1‰vŒvˆàˆw�q˜!˜R  SÑ)Ô)Ð)ó    c                   óZ   — e Zd ZdZdZd„ Zedd„¦   «         Zd„ Zd„ Z	d„ Z
d	„ Zdd
„Zd„ ZdS )ÚbetaaÙ	  
    The beta integral is called the Eulerian integral of the first kind by
    Legendre:

    .. math::
        \mathrm{B}(x,y)  \int^{1}_{0} t^{x-1} (1-t)^{y-1} \mathrm{d}t.

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

    The Beta function or Euler's first integral is closely associated
    with the gamma function. The Beta function is often used in probability
    theory and mathematical statistics. It satisfies properties like:

    .. math::
        \mathrm{B}(a,1) = \frac{1}{a} \\
        \mathrm{B}(a,b) = \mathrm{B}(b,a)  \\
        \mathrm{B}(a,b) = \frac{\Gamma(a) \Gamma(b)}{\Gamma(a+b)}

    Therefore for integral values of $a$ and $b$:

    .. math::
        \mathrm{B} = \frac{(a-1)! (b-1)!}{(a+b-1)!}

    A special case of the Beta function when `x = y` is the
    Central Beta function. It satisfies properties like:

    .. math::
        \mathrm{B}(x) = 2^{1 - 2x}\mathrm{B}(x, \frac{1}{2})
        \mathrm{B}(x) = 2^{1 - 2x} cos(\pi x) \mathrm{B}(\frac{1}{2} - x, x)
        \mathrm{B}(x) = \int_{0}^{1} \frac{t^x}{(1 + t)^{2x}} dt
        \mathrm{B}(x) = \frac{2}{x} \prod_{n = 1}^{\infty} \frac{n(n + 2x)}{(n + x)^2}

    Examples
    ========

    >>> from sympy import I, pi
    >>> from sympy.abc import x, y

    The Beta function obeys the mirror symmetry:

    >>> from sympy import beta, conjugate
    >>> conjugate(beta(x, y))
    beta(conjugate(x), conjugate(y))

    Differentiation with respect to both $x$ and $y$ is supported:

    >>> from sympy import beta, diff
    >>> diff(beta(x, y), x)
    (polygamma(0, x) - polygamma(0, x + y))*beta(x, y)

    >>> diff(beta(x, y), y)
    (polygamma(0, y) - polygamma(0, x + y))*beta(x, y)

    >>> diff(beta(x), x)
    2*(polygamma(0, x) - polygamma(0, 2*x))*beta(x, x)

    We can numerically evaluate the Beta function to
    arbitrary precision for any complex numbers x and y:

    >>> from sympy import beta
    >>> beta(pi).evalf(40)
    0.02671848900111377452242355235388489324562

    >>> beta(1 + I).evalf(20)
    -0.2112723729365330143 - 0.7655283165378005676*I

    See Also
    ========

    gamma: Gamma function.
    uppergamma: Upper incomplete gamma function.
    lowergamma: Lower incomplete gamma function.
    polygamma: Polygamma function.
    loggamma: Log Gamma function.
    digamma: Digamma function.
    trigamma: Trigamma function.

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Beta_function
    .. [2] https://mathworld.wolfram.com/BetaFunction.html
    .. [3] https://dlmf.nist.gov/5.12

    Tc                 ó  — | j         \  }}|dk    r3t          ||¦  «        t          |¦  «        t          ||z   ¦  «        z
  z  S |dk    r3t          ||¦  «        t          |¦  «        t          ||z   ¦  «        z
  z  S t          | |¦  «        ‚)Né   é   )Úargsr   r	   r   )ÚselfÚargindexÚxÚys       r   Úfdiffz
beta.fdiffm   s   € ØŒy‰ˆˆ1Ø�qŠ=ˆ=å˜˜1‘:”:�w q™zœz­G°A¸±E©N¬NÑ:Ñ;Ð;Ø˜Š]ˆ]å˜˜1‘:”:�w q™zœz­G°A¸±E©N¬NÑ:Ñ;Ð;å$ T¨8Ñ4Ô4Ð4r   Nc                 ó’   — |€t          ||¦  «        S |j        r+|j        r&t          ||d¬¦  «                             ¦   «         S d S d S )NF)Úevaluate)r   Ú	is_NumberÚdoit)Úclsr    r!   s      r   Úevalz	beta.evalx   s]   € àˆ9Ý˜˜1‘:”:ÐØŒ;ð 	5˜1œ;ð 	5Ý˜˜1 uÐ-Ñ-Ô-×2Ò2Ñ4Ô4Ð4ð	5ð 	5ð 	5ð 	5r   c                 óP  — | j         d         x}}t          | j         ¦  «        dk    }|r| j         d         n| j         d         x}}|                     dd¦  «        r |j        di |¤Ž} |j        di |¤Ž}|j        s|j        rt
          j        S |t
          j        u rd|z  S |t
          j        u rd|z  S ||dz   k    rd||z  t          |¦  «        z  z  S ||z   }|j	        r%|j
        r|j	        du r|j	        du rt
          j        S ||k    r
||k    r|s| S t          ||¦  «        S )Nr   r   ÚdeepTF© )r   ÚlenÚgetr&   Úis_zeror   ÚComplexInfinityÚOner
   Ú
is_integerÚis_negativeÚZeror   )r   Úhintsr    ÚxoldÚsingle_argumentr!   ÚyoldÚss           r   r&   z	beta.doit   sM  € Ø”9˜Q”<ÐˆˆDå˜dœi™.œ.¨AÒ-ˆØ#2ÐD�4”9˜Q”<�<¸¼	À!¼ÐDˆˆDØ�9Š9�V˜TÑ"Ô"ð 	 Ø�”��˜��ˆAØ�”��˜��ˆAØŒ9ð 	%˜œ	ð 	%ÝÔ$Ð$Ø•”ˆ:ˆ:Ø�Q‘3ˆJØ•”ˆ:ˆ:Ø�Q‘3ˆJØ��A‘Š:ˆ:Ø�a˜‘c�' !™*œ*‘nÑ%Ð%Ø�‰EˆØŒLð 	˜Qœ]ð 	¨q¬|¸uÐ/DÐ/DØŒL˜EÐ!Ð!Ý”6ˆMØ�Š9ˆ9˜˜dš˜¨?˜ØˆKÝ�A�q‰zŒzÐr   c                 óz   — | j         \  }}t          |¦  «        t          |¦  «        z  t          ||z   ¦  «        z  S ©N)r   r   )r   r4   r    r!   s       r   Ú_eval_expand_funczbeta._eval_expand_func—   s3   € ØŒy‰ˆˆ1Ý�Q‰xŒx�˜a™œÑ ¥5¨¨Q©¡<¤<Ñ/Ð/r   c                 óJ   — | j         d         j        o| j         d         j        S ©Nr   r   )r   Úis_real©r   s    r   Ú_eval_is_realzbeta._eval_is_real›   s   € ØŒy˜Œ|Ô#Ð<¨¬	°!¬Ô(<Ð<r   c                 ó¢   — |                       | j        d                              ¦   «         | j        d                              ¦   «         ¦  «        S r=   )Úfuncr   r   r?   s    r   Ú_eval_conjugatezbeta._eval_conjugatež   s:   € Ø�yŠy˜œ 1œ×/Ò/Ñ1Ô1°4´9¸Q´<×3IÒ3IÑ3KÔ3KÑLÔLÐLr   c                 ó   —  | j         di |¤ŽS )Nr+   )r;   )r   r    r!   Ú	piecewiseÚkwargss        r   Ú_eval_rewrite_as_gammazbeta._eval_rewrite_as_gamma¡   s   € Ø%ˆtÔ%Ð/Ð/¨Ð/Ð/Ð/r   c                 ó˜   — ddl m} t          t          d||g¦  «        j        ¦  «        } |||dz
  z  d|z
  |dz
  z  z  |ddf¦  «        S ©Nr   )ÚIntegralÚtr   ©Úsympy.integrals.integralsrJ   r   r   Úname)r   r    r!   rF   rJ   rK   s         r   Ú_eval_rewrite_as_Integralzbeta._eval_rewrite_as_Integral¤   se   € Ø6Ð6Ð6Ð6Ð6Ð6ÝÕ'¨¨a°¨VÑ4Ô4Ô9Ñ:Ô:ˆØˆx˜˜A ™E™
 A¨¡E¨Q°©UÑ#3Ñ3°a¸¸A°YÑ?Ô?Ð?r   r:   )T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
unbranchedr"   Úclassmethodr(   r&   r;   r@   rC   rG   rO   r+   r   r   r   r      s¾   € € € € € ðUð Uðl €Jð	5ð 	5ð 	5ð ð5ð 5ð 5ñ „[ð5ðð ð ð00ð 0ð 0ð=ð =ð =ðMð Mð Mð0ð 0ð 0ð 0ð@ð @ð @ð @ð @r   r   c                   ó>   — e Zd ZdZdZdZd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
S )r   a[  
    The Generalized Incomplete Beta function is defined as

    .. math::
        \mathrm{B}_{(x_1, x_2)}(a, b) = \int_{x_1}^{x_2} t^{a - 1} (1 - t)^{b - 1} dt

    The Incomplete Beta function is a special case
    of the Generalized Incomplete Beta function :

    .. math:: \mathrm{B}_z (a, b) = \mathrm{B}_{(0, z)}(a, b)

    The Incomplete Beta function satisfies :

    .. math:: \mathrm{B}_z (a, b) = (-1)^a \mathrm{B}_{\frac{z}{z - 1}} (a, 1 - a - b)

    The Beta function is a special case of the Incomplete Beta function :

    .. math:: \mathrm{B}(a, b) = \mathrm{B}_{1}(a, b)

    Examples
    ========

    >>> from sympy import betainc, symbols, conjugate
    >>> a, b, x, x1, x2 = symbols('a b x x1 x2')

    The Generalized Incomplete Beta function is given by:

    >>> betainc(a, b, x1, x2)
    betainc(a, b, x1, x2)

    The Incomplete Beta function can be obtained as follows:

    >>> betainc(a, b, 0, x)
    betainc(a, b, 0, x)

    The Incomplete Beta function obeys the mirror symmetry:

    >>> conjugate(betainc(a, b, x1, x2))
    betainc(conjugate(a), conjugate(b), conjugate(x1), conjugate(x2))

    We can numerically evaluate the Incomplete Beta function to
    arbitrary precision for any complex numbers a, b, x1 and x2:

    >>> from sympy import betainc, I
    >>> betainc(2, 3, 4, 5).evalf(10)
    56.08333333
    >>> betainc(0.75, 1 - 4*I, 0, 2 + 3*I).evalf(25)
    0.2241657956955709603655887 + 0.3619619242700451992411724*I

    The Generalized Incomplete Beta function can be expressed
    in terms of the Generalized Hypergeometric function.

    >>> from sympy import hyper
    >>> betainc(a, b, x1, x2).rewrite(hyper)
    (-x1**a*hyper((a, 1 - b), (a + 1,), x1) + x2**a*hyper((a, 1 - b), (a + 1,), x2))/a

    See Also
    ========

    beta: Beta function
    hyper: Generalized Hypergeometric function

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Beta_function#Incomplete_beta_function
    .. [2] https://dlmf.nist.gov/8.17
    .. [3] https://functions.wolfram.com/GammaBetaErf/Beta4/
    .. [4] https://functions.wolfram.com/GammaBetaErf/BetaRegularized4/02/

    é   Tc                 ó¤   — | j         \  }}}}|dk    rd|z
  |dz
  z   ||dz
  z  z  S |dk    rd|z
  |dz
  z  ||dz
  z  z  S t          | |¦  «        ‚©Né   r   rW   )r   r   ©r   r   r   r   r   r   s         r   r"   zbetainc.fdiffø   sv   € Ø”y‰ˆˆ1ˆb�"Ø�qŠ=ˆ=à˜‘V˜q 1™uÑ%Ð% b¨1¨q©5¡kÑ1Ð1Ø˜Š]ˆ]à˜‘F˜a !™eÑ$ R¨!¨a©%¡[Ñ0Ð0å$ T¨8Ñ4Ô4Ð4r   c                 ó   — t           | j        fS r:   )r   r   r?   s    r   Ú_eval_mpmathzbetainc._eval_mpmath  s   € Ý! 4¤9Ð,Ð,r   c                 óF   — t          d„ | j        D ¦   «         ¦  «        rdS d S )Nc              3   ó$   K  — | ]}|j         V — Œd S r:   ©r>   ©Ú.0Úargs     r   ú	<genexpr>z(betainc._eval_is_real.<locals>.<genexpr>  ó$   è è € Ð0Ð0˜sˆsŒ{Ð0Ð0Ð0Ð0Ð0Ð0r   T©Úallr   r?   s    r   r@   zbetainc._eval_is_real  ó2   € ÝÐ0Ð0 d¤iÐ0Ñ0Ô0Ñ0Ô0ð 	Ø�4ð	ð 	r   c                 óF   —  | j         t          t          | j        ¦  «        Ž S r:   ©rB   Úmapr   r   r?   s    r   rC   zbetainc._eval_conjugate
  ó   € ØˆtŒy�#�i¨¬Ñ3Ô3Ð4Ð4r   c           	      óœ   — ddl m} t          t          d||||g¦  «        j        ¦  «        } |||dz
  z  d|z
  |dz
  z  z  |||f¦  «        S rI   rL   )r   r   r   r   r   rF   rJ   rK   s           r   rO   z!betainc._eval_rewrite_as_Integral  si   € Ø6Ð6Ð6Ð6Ð6Ð6ÝÕ'¨¨a°°B¸¨^Ñ<Ô<ÔAÑBÔBˆØˆx˜˜A ™E™
 A¨¡E¨Q°©UÑ#3Ñ3°a¸¸R°[ÑAÔAÐAr   c                 ó†   — ddl m} ||z   ||d|z
  f|dz   f|¦  «        z  ||z   ||d|z
  f|dz   f|¦  «        z  z
  |z  S ©Nr   )Úhyperr   )Úsympy.functions.special.hyperrp   )r   r   r   r   r   rF   rp   s          r   Ú_eval_rewrite_as_hyperzbetainc._eval_rewrite_as_hyper  su   € Ø7Ð7Ð7Ð7Ð7Ð7Ø�A‘˜˜˜q ! a¡%˜j¨1¨q©5¨(°BÑ7Ô7Ñ7¸"¸a¹%À%À%ÈÈAÐPQÉEÈ
ÐUVÐYZÑUZÐT\Ð^`ÑBaÔBaÑ:aÑaÐefÑfÐfr   N)rP   rQ   rR   rS   ÚnargsrT   r"   r]   r@   rC   rO   rr   r+   r   r   r   r   ­   s�   € € € € € ðFð FðN €EØ€Jð	5ð 	5ð 	5ð-ð -ð -ðð ð ð5ð 5ð 5ðBð Bð Bð
gð gð gð gð gr   r   c                   óN   ‡ — e Zd ZdZdZdZˆ fd„Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zˆ xZS )Úbetainc_regularizeda�  
    The Generalized Regularized Incomplete Beta function is given by

    .. math::
        \mathrm{I}_{(x_1, x_2)}(a, b) = \frac{\mathrm{B}_{(x_1, x_2)}(a, b)}{\mathrm{B}(a, b)}

    The Regularized Incomplete Beta function is a special case
    of the Generalized Regularized Incomplete Beta function :

    .. math:: \mathrm{I}_z (a, b) = \mathrm{I}_{(0, z)}(a, b)

    The Regularized Incomplete Beta function is the cumulative distribution
    function of the beta distribution.

    Examples
    ========

    >>> from sympy import betainc_regularized, symbols, conjugate
    >>> a, b, x, x1, x2 = symbols('a b x x1 x2')

    The Generalized Regularized Incomplete Beta
    function is given by:

    >>> betainc_regularized(a, b, x1, x2)
    betainc_regularized(a, b, x1, x2)

    The Regularized Incomplete Beta function
    can be obtained as follows:

    >>> betainc_regularized(a, b, 0, x)
    betainc_regularized(a, b, 0, x)

    The Regularized Incomplete Beta function
    obeys the mirror symmetry:

    >>> conjugate(betainc_regularized(a, b, x1, x2))
    betainc_regularized(conjugate(a), conjugate(b), conjugate(x1), conjugate(x2))

    We can numerically evaluate the Regularized Incomplete Beta function
    to arbitrary precision for any complex numbers a, b, x1 and x2:

    >>> from sympy import betainc_regularized, pi, E
    >>> betainc_regularized(1, 2, 0, 0.25).evalf(10)
    0.4375000000
    >>> betainc_regularized(pi, E, 0, 1).evalf(5)
    1.00000

    The Generalized Regularized Incomplete Beta function can be
    expressed in terms of the Generalized Hypergeometric function.

    >>> from sympy import hyper
    >>> betainc_regularized(a, b, x1, x2).rewrite(hyper)
    (-x1**a*hyper((a, 1 - b), (a + 1,), x1) + x2**a*hyper((a, 1 - b), (a + 1,), x2))/(a*beta(a, b))

    See Also
    ========

    beta: Beta function
    hyper: Generalized Hypergeometric function

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Beta_function#Incomplete_beta_function
    .. [2] https://dlmf.nist.gov/8.17
    .. [3] https://functions.wolfram.com/GammaBetaErf/Beta4/
    .. [4] https://functions.wolfram.com/GammaBetaErf/BetaRegularized4/02/

    rW   Tc                 óN   •— t          ¦   «                              | ||||¦  «        S r:   )ÚsuperÚ__new__)r'   r   r   r   r   Ú	__class__s        €r   rx   zbetainc_regularized.__new__c  s!   ø€ Ý‰wŒw�Š˜s A q¨"¨bÑ1Ô1Ð1r   c                 óB   — t           g | j        ¢t          d¦  «        ‘R fS )Nr   )r   r   r   r?   s    r   r]   z betainc_regularized._eval_mpmathf  s#   € Ý!Ð#5 T¤YÐ#5µ°!±´Ð#5Ð#5Ð5Ð5r   c                 óè   — | j         \  }}}}|dk    r&d|z
  |dz
  z   ||dz
  z  z  t          ||¦  «        z  S |dk    r%d|z
  |dz
  z  ||dz
  z  z  t          ||¦  «        z  S t          | |¦  «        ‚rY   )r   r   r   r[   s         r   r"   zbetainc_regularized.fdiffi  s�   € Ø”y‰ˆˆ1ˆb�"Ø�qŠ=ˆ=à˜‘V˜q 1™uÑ%Ð% b¨1¨q©5¡kÑ1µD¸¸A±J´JÑ>Ð>Ø˜Š]ˆ]à˜‘F˜a !™eÑ$ R¨!¨a©%¡[Ñ0µ4¸¸1±:´:Ñ=Ð=å$ T¨8Ñ4Ô4Ð4r   c                 óF   — t          d„ | j        D ¦   «         ¦  «        rdS d S )Nc              3   ó$   K  — | ]}|j         V — Œd S r:   r`   ra   s     r   rd   z4betainc_regularized._eval_is_real.<locals>.<genexpr>u  re   r   Trf   r?   s    r   r@   z!betainc_regularized._eval_is_realt  rh   r   c                 óF   —  | j         t          t          | j        ¦  «        Ž S r:   rj   r?   s    r   rC   z#betainc_regularized._eval_conjugatex  rl   r   c           	      óÄ   — ddl m} t          t          d||||g¦  «        j        ¦  «        }||dz
  z  d|z
  |dz
  z  z  } |||||f¦  «        }	|	 |||ddf¦  «        z  S rI   rL   )
r   r   r   r   r   rF   rJ   rK   Ú	integrandÚexprs
             r   rO   z-betainc_regularized._eval_rewrite_as_Integral{  sŠ   € Ø6Ð6Ð6Ð6Ð6Ð6ÝÕ'¨¨a°°B¸¨^Ñ<Ô<ÔAÑBÔBˆØ˜˜A™‘J  A¡¨¨Q©Ñ/Ñ/ˆ	Øˆx˜	 A r¨2 ;Ñ/Ô/ˆØ�h�h˜y¨1¨a°¨)Ñ4Ô4Ñ4Ð4r   c                 ó¬   — ddl m} ||z   ||d|z
  f|dz   f|¦  «        z  ||z   ||d|z
  f|dz   f|¦  «        z  z
  |z  }|t          ||¦  «        z  S ro   )rq   rp   r   )r   r   r   r   r   rF   rp   r�   s           r   rr   z*betainc_regularized._eval_rewrite_as_hyper‚  s‡   € Ø7Ð7Ð7Ð7Ð7Ð7Ø�A‘˜˜˜q ! a¡%˜j¨1¨q©5¨(°BÑ7Ô7Ñ7¸"¸a¹%À%À%ÈÈAÐPQÉEÈ
ÐUVÐYZÑUZÐT\Ð^`ÑBaÔBaÑ:aÑaÐefÑfˆØ•d˜1˜a‘j”jÑ Ð r   )rP   rQ   rR   rS   rs   rT   rx   r]   r"   r@   rC   rO   rr   Ú__classcell__)ry   s   @r   ru   ru     s«   ø€ € € € € ðDð DðJ €EØ€Jð2ð 2ð 2ð 2ð 2ð6ð 6ð 6ð	5ð 	5ð 	5ðð ð ð5ð 5ð 5ð5ð 5ð 5ð!ð !ð !ð !ð !ð !ð !r   ru   N)r   )Ú
sympy.corer   Úsympy.core.functionr   r   Úsympy.core.symbolr   r   Ú'sympy.functions.special.gamma_functionsr   r	   Ú%sympy.functions.combinatorial.numbersr
   Ú$sympy.functions.elementary.complexesr   r   r   r   ru   r+   r   r   ú<module>rŠ      sK  ðØ Ð Ð Ð Ð Ð Ø CÐ CÐ CÐ CÐ CÐ CÐ CÐ CØ :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ø BÐ BÐ BÐ BÐ BÐ BÐ BÐ BØ 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø :Ð :Ð :Ð :Ð :Ð :ð*ð *ð *ð *ðS@ð S@ð S@ð S@ð S@ˆ?ñ S@ô S@ð S@ðrggð ggð ggð ggð ggˆoñ ggô ggð ggðZk!ð k!ð k!ð k!ð k!˜/ñ k!ô k!ð k!ð k!ð k!r   