
    \h1                         S SK Jr  S SKJrJr  S SKJrJr  S SKJ	r	J
r
  S SKJr  S SKJr  SS jr " S S	\5      r " S
 S\5      r " S S\5      rg)    )S)DefinedFunctionArgumentIndexError)Dummyuniquely_named_symbol)gammadigamma)catalan)	conjugatec                 @    SSK JnJn  X#:X  a  U" S5      $ U" XX#U5      $ )Nr   )betaincmpf)mpmathr   r   )abx1x2regr   r   s          ^/var/www/auris/envauris/lib/python3.13/site-packages/sympy/functions/special/beta_functions.pybetainc_mpmath_fixr   	   s"    #	x1vqRS))    c                   ^    \ rS rSrSrSrS r\SS j5       rS r	S r
S	 rS
 rSS jrS rSrg)beta   a  
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                     U R                   u  p#US:X  a%  [        X#5      [        U5      [        X#-   5      -
  -  $ US:X  a%  [        X#5      [        U5      [        X#-   5      -
  -  $ [        X5      e)N      )argsr   r	   r   )selfargindexxys       r   fdiff
beta.fdiffm   sb    yyq=:wqzGAEN:;;]:wqzGAEN:;;$T44r   Nc                     Uc  [        X5      $ UR                  (       a*  UR                  (       a  [        XSS9R                  5       $ g g )NF)evaluate)r   	is_Numberdoit)clsr!   r"   s      r   eval	beta.evalx   s;    9:;;1;;u-2244 ';r   c                    U R                   S   =p#[        U R                   5      S:H  nU(       a  U R                   S   OU R                   S   =pVUR                  SS5      (       a$  UR                  " S0 UD6nUR                  " S0 UD6nUR                  (       d  UR                  (       a  [
        R                  $ U[
        R                  L a  SU-  $ U[
        R                  L a  SU-  $ XRS-   :X  a  SX%-  [        U5      -  -  $ X%-   nUR                  (       a?  UR                  (       a.  UR                  SL a  UR                  SL a  [
        R                  $ X#:X  a  XV:X  a	  U(       d  U $ [        X%5      $ )Nr   r   deepTF )r   lengetr(   is_zeror   ComplexInfinityOner
   
is_integeris_negativeZeror   )r   hintsr!   xoldsingle_argumentr"   yoldss           r   r(   	beta.doit   s   99Q<dii.A-#2499Q<		!D99VT""AA99		$$$:Q3J:Q3JA:ac'!*n%%ELLQ]]q||u/DLLE!66M9?KAzr   c                 h    U R                   u  p#[        U5      [        U5      -  [        X#-   5      -  $ N)r   r   )r   r7   r!   r"   s       r   _eval_expand_funcbeta._eval_expand_func   s+    yyQxa 5<//r   c                 t    U R                   S   R                  =(       a    U R                   S   R                  $ Nr   r   )r   is_realr   s    r   _eval_is_realbeta._eval_is_real   s)    yy|##<		!(<(<<r   c                     U R                  U R                  S   R                  5       U R                  S   R                  5       5      $ rB   )funcr   r   rD   s    r   _eval_conjugatebeta._eval_conjugate   s5    yy1//1499Q<3I3I3KLLr   c                 &    U R                   " S0 UD6$ )Nr.   )r?   )r   r!   r"   	piecewisekwargss        r   _eval_rewrite_as_gammabeta._eval_rewrite_as_gamma   s    %%///r   c                     SSK Jn  [        [        SX/5      R                  5      nU" XQS-
  -  SU-
  US-
  -  -  USS45      $ Nr   )Integraltr   sympy.integrals.integralsrR   r   r   name)r   r!   r"   rM   rR   rS   s         r   _eval_rewrite_as_Integralbeta._eval_rewrite_as_Integral   sJ    6'aV499:E
AEQU#33aAY??r   r.   r>   )T)__name__
__module____qualname____firstlineno____doc__
unbranchedr#   classmethodr*   r(   r?   rE   rI   rN   rW   __static_attributes__r.   r   r   r   r      sI    Ul J	5 5 500=M0@r   r   c                   D    \ rS rSrSrSrSrS rS rS r	S r
S	 rS
 rSrg)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                     U R                   u  p#pEUS:X  a  SU-
  US-
  -  * XBS-
  -  -  $ US:X  a  SU-
  US-
  -  XRS-
  -  -  $ [        X5      eN   r   rc   )r   r   r   r    r   r   r   r   s         r   r#   betainc.fdiff   sg    yybq=Vq1u%%bq5k11]Fa!e$Ra%[00$T44r   c                 &    [         U R                  4$ r>   )r   r   rD   s    r   _eval_mpmathbetainc._eval_mpmath  s    !499,,r   c                 H    [        S U R                   5       5      (       a  gg )Nc              3   8   #    U  H  oR                   v   M     g 7fr>   rC   .0args     r   	<genexpr>(betainc._eval_is_real.<locals>.<genexpr>       0is{{i   Tallr   rD   s    r   rE   betainc._eval_is_real      0dii000 1r   c                 P    U R                   " [        [        U R                  5      6 $ r>   rH   mapr   r   rD   s    r   rI   betainc._eval_conjugate
      yy#i344r   c           	          SSK Jn  [        [        SXX4/5      R                  5      nU" XqS-
  -  SU-
  US-
  -  -  XsU45      $ rQ   rT   )r   r   r   r   r   rM   rR   rS   s           r   rW   !betainc._eval_rewrite_as_Integral  sJ    6'aB^<AABE
AEQU#33aR[AAr   c                 v    SSK Jn  XA-  U" USU-
  4US-   4U5      -  X1-  U" USU-
  4US-   4U5      -  -
  U-  $ Nr   )hyperr   )sympy.functions.special.hyperr   )r   r   r   r   r   rM   r   s          r   _eval_rewrite_as_hyperbetainc._eval_rewrite_as_hyper  sX    7q!a%j1q5(B77"%%APQE
UVYZUZT\^`Ba:aaefffr   r.   N)rY   rZ   r[   r\   r]   nargsr^   r#   rj   rE   rI   rW   r   r`   r.   r   r   r   r      s5    FN EJ	5-5B
gr   r   c                   X   ^  \ rS rSrSrSrSrU 4S jrS rS r	S r
S	 rS
 rS rSrU =r$ )betainc_regularizedi  a  
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/

rc   Tc                 &   > [         TU ]  XX#U5      $ r>   )super__new__)r)   r   r   r   r   	__class__s        r   r   betainc_regularized.__new__c  s    wsqb11r   c                 B    [         / U R                  Q[        S5      P74$ )Nr   )r   r   r   rD   s    r   rj    betainc_regularized._eval_mpmathf  s     !#5TYY#5!#555r   c                     U R                   u  p#pEUS:X  a   SU-
  US-
  -  * XBS-
  -  -  [        X#5      -  $ US:X  a  SU-
  US-
  -  XRS-
  -  -  [        X#5      -  $ [        X5      ere   )r   r   r   rg   s         r   r#   betainc_regularized.fdiffi  sy    yybq=Vq1u%%bq5k1DJ>>]Fa!e$Ra%[04:==$T44r   c                 H    [        S U R                   5       5      (       a  gg )Nc              3   8   #    U  H  oR                   v   M     g 7fr>   rn   ro   s     r   rr   4betainc_regularized._eval_is_real.<locals>.<genexpr>u  rt   ru   Trv   rD   s    r   rE   !betainc_regularized._eval_is_realt  ry   r   c                 P    U R                   " [        [        U R                  5      6 $ r>   r{   rD   s    r   rI   #betainc_regularized._eval_conjugatex  r~   r   c           	          SSK Jn  [        [        SXX4/5      R                  5      nXqS-
  -  SU-
  US-
  -  -  nU" XX445      n	X" XSS45      -  $ rQ   rT   )
r   r   r   r   r   rM   rR   rS   	integrandexprs
             r   rW   -betainc_regularized._eval_rewrite_as_Integral{  sb    6'aB^<AABAJAQ//		r;/hya)444r   c                     SSK Jn  XA-  U" USU-
  4US-   4U5      -  X1-  U" USU-
  4US-   4U5      -  -
  U-  nU[        X5      -  $ r   )r   r   r   )r   r   r   r   r   rM   r   r   s           r   r   *betainc_regularized._eval_rewrite_as_hyper  sf    7q!a%j1q5(B77"%%APQE
UVYZUZT\^`Ba:aaeffd1j  r   r.   )rY   rZ   r[   r\   r]   r   r^   r   rj   r#   rE   rI   rW   r   r`   __classcell__)r   s   @r   r   r     s>    DJ EJ26	555! !r   r   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   r   r.   r   r   <module>r      sL     C : B 9 :*S@? S@rggo ggZk!/ k!r   