K i1ddlmZddlmZmZddlmZmZddlm Z m Z ddl m Z ddl mZddZGdd eZGd d eZGd d eZy))S)DefinedFunctionArgumentIndexError)Dummyuniquely_named_symbol)gammadigamma)catalan) conjugatecDddlm}m}||k(r|dS||||||S)Nr)betaincmpf)mpmathr r)abx1x2regr rs l/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/functions/special/beta_functions.pybetainc_mpmath_fixr s(# Rx1v q!RS))cReZdZdZdZdZed dZdZdZ dZ d Z d d Z d Z y)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\}}|dk(r't||t|t||zz zS|dk(r't||t|t||zz zSt||)N)argsrr r)selfargindexxys rfdiffz beta.fdiffmsnyy1 q=1:wqzGAEN:; ; ]1:wqzGAEN:; ;$T84 4rNc| t||S|jr)|jrt||djSyy)NF)evaluate)r is_Numberdoit)clsr r!s revalz beta.evalxs? 91:  ;;1;;1u-224 4';rc |jdx}}t|jdk(}|r|jdn|jdx}}|jddr$|jdi|}|jdi|}|js |jrt j S|t jurd|z S|t jurd|z S||dzk(rd||zt|zz S||z}|jr8|jr,|jdur|jdurt jS||k(r ||k(r|s|St||S)NrrdeepTF) rlengetr&is_zerorComplexInfinityOner is_integer is_negativeZeror)rhintsr xoldsingle_argumentr!yoldss rr&z beta.doits-99Q<Ddii.A-#2499Q< ! DD 99VT "AA 99 $$ $ :Q3J :Q3J A:ac'!*n% % E LLQ]]q||u/D LLE !66M 9d?KAqzrc l|j\}}t|t|zt||zz SN)rr)rr4r r!s r_eval_expand_funczbeta._eval_expand_funcs/yy1Qxa 5Q<//rcj|jdjxr|jdjSNrr)ris_realrs r _eval_is_realzbeta._eval_is_reals)yy|##< ! (<(<>> 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\}}}}|dk(rd|z |dz z ||dz zzS|dk(rd|z |dz z||dz zzSt||NrrW)rrrrrrrrs rr"z betainc.fdiffsqyy 1b" q=Vq1u%%b1q5k1 1 ]Fa!e$R!a%[0 0$T84 4rc&t|jfSr:)rrr?s r _eval_mpmathzbetainc._eval_mpmaths!499,,rc>td|jDryy)Nc34K|]}|jywr:r>.0args r z(betainc._eval_is_real..0ss{{0Tallrr?s rr@zbetainc._eval_is_real 0dii0 0 1rcP|jtt|jSr:rBmapr rr?s rrCzbetainc._eval_conjugate tyy#i344rc ddlm}ttd||||gj}|||dz zd|z |dz zz|||fSrIrL)rrrrrrFrJrKs rrOz!betainc._eval_rewrite_as_Integral sR6 'aB^<AA BAE AEQU#33aR[AArc zddlm}||z||d|z f|dzf|z||z||d|z f|dzf|zz |z SNr)hyperr)sympy.functions.special.hyperrq)rrrrrrFrqs r_eval_rewrite_as_hyperzbetainc._eval_rewrite_as_hypers\7Aq!a%j1q5(B77"a%%APQE UVYZUZT\^`Ba:aaefffrN) rPrQrRrSnargsrTr"r]r@rCrOrsr+rrr r s5FN EJ 5-5B grr cNeZdZdZdZdZfdZdZdZdZ dZ d Z d Z xZ 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/ rWTc*t||||||Sr:)super__new__)r'rrrr __class__s rryzbetainc_regularized.__new__cswsAq"b11rcBtg|jtdfS)Nr)rrrr?s rr]z betainc_regularized._eval_mpmathfs !#5TYY#5!#555rc|j\}}}}|dk(r"d|z |dz z ||dz zzt||z S|dk(r!d|z |dz z||dz zzt||z St||rY)rrrr[s rr"zbetainc_regularized.fdiffisyy 1b" q=Vq1u%%b1q5k1DAJ> > ]Fa!e$R!a%[041:= =$T84 4rc>td|jDryy)Nc34K|]}|jywr:r`ras rrdz4betainc_regularized._eval_is_real..urerfTrgr?s rr@z!betainc_regularized._eval_is_realtrircP|jtt|jSr:rkr?s rrCz#betainc_regularized._eval_conjugatexrmrc ddlm}ttd||||gj}||dz zd|z |dz zz}|||||f} | |||ddfz SrIrL) rrrrrrFrJrK integrandexprs rrOz-betainc_regularized._eval_rewrite_as_Integral{sn6 'aB^<AA BAJAQ//  Ar2;/hy1a)444rc ddlm}||z||d|z f|dzf|z||z||d|z f|dzf|zz |z }|t||z Srp)rrrqr)rrrrrrFrqrs rrsz*betainc_regularized._eval_rewrite_as_hypersl7Aq!a%j1q5(B77"a%%APQE UVYZUZT\^`Ba:aaeffd1aj  r)rPrQrRrSrtrTryr]r"r@rCrOrs __classcell__)rzs@rrvrvs9DJ EJ26 555!rrvN)r) sympy.corersympy.core.functionrrsympy.core.symbolrr'sympy.functions.special.gamma_functionsrr %sympy.functions.combinatorial.numbersr $sympy.functions.elementary.complexesr rrr rvr+rrrsLC:B9:*S@?S@rggoggZk!/k!r