Exemplo n.º 1
0
def jv(v, x):
    """Bessel function J_v(x)."""
    if isint(v):
        if isinstance(x, mpf):
            return make_mpf(libhyper.mpf_besseljn(int(v), x._mpf_, mp.prec))
        if isinstance(x, mpc):
            return make_mpc(libhyper.mpc_besseljn(int(v), x._mpc_, mp.prec))
    hx = x / 2
    return hx**v * hyp0f1(v + 1, -hx**2) / factorial(v)
Exemplo n.º 2
0
def jv(v, x):
    """Bessel function J_v(x)."""
    if isint(v):
        if isinstance(x, mpf):
            return make_mpf(libhyper.mpf_besseljn(int(v), x._mpf_, mp.prec))
        if isinstance(x, mpc):
            return make_mpc(libhyper.mpc_besseljn(int(v), x._mpc_, mp.prec))
    hx = x/2
    return hx**v * hyp0f1(v+1, -hx**2) / factorial(v)
Exemplo n.º 3
0
def hypsum(ar, af, ac, br, bf, bc, x):
    prec, rnd = prec_rounding
    if hasattr(x, "_mpf_") and not (ac or bc):
        v = libhyper.hypsum_internal(ar, af, ac, br, bf, bc, x._mpf_, None, prec, rnd)
        return make_mpf(v)
    else:
        if hasattr(x, "_mpc_"):
            re, im = x._mpc_
        else:
            re, im = x._mpf_, libmpf.fzero
        v = libhyper.hypsum_internal(ar, af, ac, br, bf, bc, re, im, prec, rnd)
        return make_mpc(v)
Exemplo n.º 4
0
def nthroot(x, n):
    """principal n-th root"""
    n = int(n)
    if isinstance(x, mpf):
        try:
            return make_mpf(libelefun.mpf_nthroot(x._mpf_, n, *prec_rounding))
        except ComplexResult:
            if mp.trap_complex:
                raise
            x = (x._mpf_, libmpf.fzero)
    else:
        x = x._mpc_
    return make_mpc(libmpc.mpc_nthroot(x, n, *prec_rounding))
Exemplo n.º 5
0
def hypsum(ar, af, ac, br, bf, bc, x):
    prec, rnd = prec_rounding
    if hasattr(x, "_mpf_") and not (ac or bc):
        v = libhyper.hypsum_internal(ar, af, ac, br, bf, bc, x._mpf_, None,
                                     prec, rnd)
        return make_mpf(v)
    else:
        if hasattr(x, "_mpc_"):
            re, im = x._mpc_
        else:
            re, im = x._mpf_, libmpf.fzero
        v = libhyper.hypsum_internal(ar, af, ac, br, bf, bc, re, im, prec, rnd)
        return make_mpc(v)
Exemplo n.º 6
0
def nthroot(x, n):
    """principal n-th root"""
    n = int(n)
    if isinstance(x, mpf):
        try:
            return make_mpf(libelefun.mpf_nthroot(x._mpf_, n, *prec_rounding))
        except ComplexResult:
            if mp.trap_complex:
                raise
            x = (x._mpf_, libmpf.fzero)
    else:
        x = x._mpc_
    return make_mpc(libmpc.mpc_nthroot(x, n, *prec_rounding))
Exemplo n.º 7
0
def psi(m, z):
    """
    Gives the polygamma function of order m of z, psi^(m)(z). Special
    cases are the digamma function (psi0), trigamma function (psi1),
    tetragamma (psi2) and pentagamma (psi4) functions.

    The parameter m should be a nonnegative integer.
    """
    z = convert_lossless(z)
    m = int(m)
    if isinstance(z, mpf):
        return make_mpf(gammazeta.mpf_psi(m, z._mpf_, *prec_rounding))
    else:
        return make_mpc(gammazeta.mpc_psi(m, z._mpc_, *prec_rounding))
Exemplo n.º 8
0
def psi(m, z):
    """
    Gives the polygamma function of order m of z, psi^(m)(z). Special
    cases are the digamma function (psi0), trigamma function (psi1),
    tetragamma (psi2) and pentagamma (psi4) functions.

    The parameter m should be a nonnegative integer.
    """
    z = convert_lossless(z)
    m = int(m)
    if isinstance(z, mpf):
        return make_mpf(gammazeta.mpf_psi(m, z._mpf_, *prec_rounding))
    else:
        return make_mpc(gammazeta.mpc_psi(m, z._mpc_, *prec_rounding))
Exemplo n.º 9
0
 def f(x, **kwargs):
     if not isinstance(x, mpnumeric):
         x = convert_lossless(x)
     prec, rounding = prec_rounding
     if kwargs:
         prec = kwargs.get('prec', prec)
         if 'dps' in kwargs:
             prec = dps_to_prec(kwargs['dps'])
         rounding = kwargs.get('rounding', rounding)
     if isinstance(x, mpf):
         try:
             return make_mpf(real_f(x._mpf_, prec, rounding))
         except ComplexResult:
             # Handle propagation to complex
             if mp.trap_complex:
                 raise
             return make_mpc(complex_f((x._mpf_, libmpf.fzero), prec, rounding))
     elif isinstance(x, mpc):
         return make_mpc(complex_f(x._mpc_, prec, rounding))
     elif isinstance(x, mpi):
         if interval_f:
             return make_mpi(interval_f(x._val, prec))
     raise NotImplementedError("%s of a %s" % (name, type(x)))
Exemplo n.º 10
0
 def f(x, **kwargs):
     if not isinstance(x, mpnumeric):
         x = convert_lossless(x)
     prec, rounding = prec_rounding
     if kwargs:
         prec = kwargs.get('prec', prec)
         if 'dps' in kwargs:
             prec = dps_to_prec(kwargs['dps'])
         rounding = kwargs.get('rounding', rounding)
     if isinstance(x, mpf):
         try:
             return make_mpf(real_f(x._mpf_, prec, rounding))
         except ComplexResult:
             # Handle propagation to complex
             if mp.trap_complex:
                 raise
             return make_mpc(
                 complex_f((x._mpf_, libmpf.fzero), prec, rounding))
     elif isinstance(x, mpc):
         return make_mpc(complex_f(x._mpc_, prec, rounding))
     elif isinstance(x, mpi):
         if interval_f:
             return make_mpi(interval_f(x._val, prec))
     raise NotImplementedError("%s of a %s" % (name, type(x)))
Exemplo n.º 11
0
def bernoulli(n):
    """nth Bernoulli number, B_n"""
    return make_mpf(gammazeta.mpf_bernoulli(int(n), *prec_rounding))
Exemplo n.º 12
0
def frexp(x):
    """Convert x to a scaled number y in the range [0.5, 1). Returns
    (y, n) such that x = y * 2**n. No rounding is performed."""
    x = convert_lossless(x)
    y, n = libmpf.mpf_frexp(x._mpf_)
    return make_mpf(y), n
Exemplo n.º 13
0
def atan2(y,x):
    """atan2(y, x) has the same magnitude as atan(y/x) but accounts for
    the signs of y and x. (Defined for real x and y only.)"""
    x = convert_lossless(x)
    y = convert_lossless(y)
    return make_mpf(libelefun.mpf_atan2(y._mpf_, x._mpf_, *prec_rounding))
Exemplo n.º 14
0
def frexp(x):
    """Convert x to a scaled number y in the range [0.5, 1). Returns
    (y, n) such that x = y * 2**n. No rounding is performed."""
    x = convert_lossless(x)
    y, n = libmpf.mpf_frexp(x._mpf_)
    return make_mpf(y), n
Exemplo n.º 15
0
def ldexp(x, n):
    """Calculate mpf(x) * 2**n efficiently. No rounding is performed."""
    x = convert_lossless(x)
    return make_mpf(libmpf.mpf_shift(x._mpf_, n))
Exemplo n.º 16
0
def hypot(x, y):
    """Returns the Euclidean distance sqrt(x*x + y*y). Both x and y
    must be real."""
    x = convert_lossless(x)
    y = convert_lossless(y)
    return make_mpf(libmpf.mpf_hypot(x._mpf_, y._mpf_, *prec_rounding))
Exemplo n.º 17
0
def atan2(y, x):
    """atan2(y, x) has the same magnitude as atan(y/x) but accounts for
    the signs of y and x. (Defined for real x and y only.)"""
    x = convert_lossless(x)
    y = convert_lossless(y)
    return make_mpf(libelefun.mpf_atan2(y._mpf_, x._mpf_, *prec_rounding))
Exemplo n.º 18
0
def ldexp(x, n):
    """Calculate mpf(x) * 2**n efficiently. No rounding is performed."""
    x = convert_lossless(x)
    return make_mpf(libmpf.mpf_shift(x._mpf_, n))
Exemplo n.º 19
0
def bernoulli(n):
    """nth Bernoulli number, B_n"""
    return make_mpf(gammazeta.mpf_bernoulli(int(n), *prec_rounding))
Exemplo n.º 20
0
def sum_hyp2f1_rat(a, b, c, z):
    prec, rnd = prec_rounding
    if hasattr(z, "_mpf_"):
        return make_mpf(libhyper.mpf_hyp2f1_rat(a, b, c, z._mpf_, prec, rnd))
    else:
        return make_mpc(libhyper.mpc_hyp2f1_rat(a, b, c, z._mpc_, prec, rnd))
Exemplo n.º 21
0
def sum_hyp2f1_rat(a, b, c, z):
    prec, rnd = prec_rounding
    if hasattr(z, "_mpf_"):
        return make_mpf(libhyper.mpf_hyp2f1_rat(a, b, c, z._mpf_, prec, rnd))
    else:
        return make_mpc(libhyper.mpc_hyp2f1_rat(a, b, c, z._mpc_, prec, rnd))
Exemplo n.º 22
0
def hypot(x, y):
    """Returns the Euclidean distance sqrt(x*x + y*y). Both x and y
    must be real."""
    x = convert_lossless(x)
    y = convert_lossless(y)
    return make_mpf(libmpf.mpf_hypot(x._mpf_, y._mpf_, *prec_rounding))
Exemplo n.º 23
0
def NEG(x):
    return make_mpf(mpf_neg(x._mpf_))
Exemplo n.º 24
0
def NEG(x):
    return make_mpf(mpf_neg(x._mpf_))