Ticket #9130: trac_9130-beta_function.patch

File trac_9130-beta_function.patch, 5.0 KB (added by burcin, 8 years ago)

combined Karen's patches

  • doc/en/reference/functions.rst

    # HG changeset patch
    # User Karen T. Kohl <ktkohl96@gmail.com>
    # Date 1326400728 21600
    # Node ID aa729a73616e28c3bdf89950090597856a2e61c3
    # Parent  92c93226b64f933e0af00bbcbd1a8a79c444f43f
    Trac 9130: symbolic beta function
    
    diff --git a/doc/en/reference/functions.rst b/doc/en/reference/functions.rst
    a b  
    99   sage/functions/transcendental
    1010   sage/functions/piecewise
    1111   sage/functions/orthogonal_polys
     12   sage/functions/other
    1213   sage/functions/special
    1314   sage/functions/wigner
    1415   sage/functions/generalized
    15    sage/functions/prime_pi
    16  No newline at end of file
     16   sage/functions/prime_pi
  • sage/functions/all.py

    diff --git a/sage/functions/all.py b/sage/functions/all.py
    a b  
    1515
    1616
    1717
    18 from other import ( ceil, floor, gamma, psi, factorial,
     18from other import ( ceil, floor, gamma, psi, factorial, beta,
    1919                    abs_symbolic, erf, sqrt,
    2020                    gamma_inc, incomplete_gamma,
    2121                    real_part, real,
  • sage/functions/other.py

    diff --git a/sage/functions/other.py b/sage/functions/other.py
    a b  
    11811181
    11821182binomial = Function_binomial()
    11831183
     1184class Function_beta(GinacFunction):
     1185    def __init__(self):
     1186        r"""
     1187        Return the beta function.  This is defined by
     1188
     1189        .. math::
     1190
     1191            B(p,q) = \int_0^1 t^{p-1}(1-t)^{1-q} dt
     1192
     1193        for complex or symbolic input `p` and `q`.
     1194        Note that the order of inputs does not matter:  `B(p,q)=B(q,p)`.
     1195
     1196        GiNaC is used to compute `B(p,q)`.  However, complex inputs
     1197        are not yet handled in general.  When GiNaC raises an error on
     1198        such inputs, we raise a NotImplementedError.
     1199
     1200        If either input is 1, GiNaC returns the reciprocal of the
     1201        other.  In other cases, GiNaC uses one of the following
     1202        formulas:
     1203
     1204        .. math::
     1205
     1206            B(p,q) = \Gamma(p)\Gamma(q)/\Gamma(p+q)
     1207
     1208        or
     1209
     1210        .. math::
     1211
     1212            B(p,q) = (-1)^q B(1-p-q, q).
     1213
     1214
     1215        For numerical inputs, GiNaC uses the formula
     1216
     1217        .. math::
     1218
     1219            B(p,q) =  \exp[\log\Gamma(p)+\log\Gamma(q)-\log\Gamma(p+q)]
     1220
     1221
     1222        INPUT:
     1223
     1224        -  ``p`` - number or symbolic expression
     1225
     1226        -  ``q`` - number or symbolic expression
     1227
     1228
     1229        OUTPUT: number or symbolic expression (if input is symbolic)
     1230
     1231        EXAMPLES::
     1232
     1233            sage: beta(3,2)
     1234            1/12
     1235            sage: beta(3,1)
     1236            1/3
     1237            sage: beta(1/2,1/2)
     1238            beta(1/2, 1/2)
     1239            sage: beta(-1,1)
     1240            -1
     1241            sage: beta(-1/2,-1/2)
     1242            0
     1243            sage: beta(x/2,3)
     1244            beta(1/2*x, 3)
     1245            sage: beta(.5,.5)
     1246            3.14159265358979
     1247            sage: beta(1,2.0+I)
     1248            0.400000000000000 - 0.200000000000000*I
     1249            sage: beta(3,x+I)
     1250            beta(x + I, 3)
     1251
     1252        Note that the order of arguments does not matter::
     1253
     1254            sage: beta(1/2,3*x)
     1255            beta(3*x, 1/2)
     1256
     1257        The following must be fixed to remain symbolic::
     1258
     1259            sage: beta(2,1+5*I)
     1260            -0.0305039787798408 - 0.0198938992042440*I
     1261
     1262        """
     1263        GinacFunction.__init__(self, "beta", nargs=2,
     1264                conversions=dict(maxima='beta', mathematica='Beta'))
     1265
     1266beta = Function_beta()
     1267
    11841268def _do_sqrt(x, prec=None, extend=True, all=False):
    11851269        r"""
    11861270        Used internally to compute the square root of x.
  • sage/symbolic/random_tests.py

    diff --git a/sage/symbolic/random_tests.py b/sage/symbolic/random_tests.py
    a b  
    1616        sage: [f for (one,f,arity) in _mk_full_functions()]
    1717        [Ei, abs, arccos, arccosh, arccot, arccoth, arccsc, arccsch,
    1818        arcsec, arcsech, arcsin, arcsinh, arctan, arctan2, arctanh,
    19         binomial, ceil, conjugate, cos, cosh, cot, coth, csc, csch,
     19        beta, binomial, ceil, conjugate, cos, cosh, cot, coth, csc, csch,
    2020        dickman_rho, dilog, dirac_delta, elliptic_e, elliptic_ec,
    2121        elliptic_eu, elliptic_f, elliptic_kc, elliptic_pi, erf, exp,
    2222        factorial, floor, heaviside, imag_part, integrate,
     
    237237        (euler_gamma - v3^(-e) + (v2 - factorial(-e/v2))^(((2.85879036573 - 1.18163393202*I)*v2 + (2.85879036573 - 1.18163393202*I)*v3)*pi - 0.247786879678 + 0.931826724898*I)*arccsc((0.891138386848 - 0.0936820840629*I)/v1) - (0.553423153995 - 0.5481180572*I)*v3 + 0.149683576515 - 0.155746451854*I)*v1 + arccsch(pi + e)*elliptic_f(khinchin*v2, 1.4656989704 + 0.863754357069*I)
    238238        sage: random_expr(5, verbose=True)
    239239        About to apply dirac_delta to [1]
    240         About to apply arccsch to [0]
    241         About to apply <built-in function add> to [0, arccsch(0)]
    242         arccsch(0)
     240        About to apply arcsec to [0]
     241        About to apply <built-in function add> to [0, arcsec(0)]
     242        arcsec(0)
     243
    243244    """
    244245    vars = [(1.0, sage.calculus.calculus.var('v%d' % (n+1))) for n in range(nvars)]
    245246    if ncoeffs is None: