Exemplo n.º 1
0
 def __rmul__(s, t):
     prec, rounding = prec_rounding
     if isinstance(t, int_types):
         return make_mpc(mpc_mul_int(s._mpc_, t, prec, rounding))
     t = mpc_convert_lhs(t)
     if t is NotImplemented:
         return t
     return t * s
Exemplo n.º 2
0
 def __rmul__(s, t):
     prec, rounding = prec_rounding
     if isinstance(t, int_types):
         return make_mpc(mpc_mul_int(s._mpc_, t, prec, rounding))
     t = mpc_convert_lhs(t)
     if t is NotImplemented:
         return t
     return t * s
Exemplo n.º 3
0
 def __mul__(s, t):
     prec, rounding = prec_rounding
     if not isinstance(t, mpc):
         if isinstance(t, int_types):
             return make_mpc(mpc_mul_int(s._mpc_, t, prec, rounding))
         t = mpc_convert_lhs(t)
         if t is NotImplemented:
             return t
         if isinstance(t, mpf):
             return make_mpc(mpc_mul_mpf(s._mpc_, t._mpf_, prec, rounding))
         t = mpc(t)
     return make_mpc(mpc_mul(s._mpc_, t._mpc_, prec, rounding))
Exemplo n.º 4
0
 def __mul__(s, t):
     prec, rounding = prec_rounding
     if not isinstance(t, mpc):
         if isinstance(t, int_types):
             return make_mpc(mpc_mul_int(s._mpc_, t, prec, rounding))
         t = mpc_convert_lhs(t)
         if t is NotImplemented:
             return t
         if isinstance(t, mpf):
             return make_mpc(mpc_mul_mpf(s._mpc_, t._mpf_, prec, rounding))
         t = mpc(t)
     return make_mpc(mpc_mul(s._mpc_, t._mpc_, prec, rounding))
Exemplo n.º 5
0
def mpc_psi0(z, prec, rnd=round_fast):
    """
    Computation of the digamma function (psi function of order 0)
    of a complex argument.
    """
    re, im = z
    # Fall back to the real case
    if im == fzero:
        return (mpf_psi0(re, prec, rnd), fzero)
    wp = prec + 20
    sign, man, exp, bc = re
    # Reflection formula
    if sign and exp+bc > 3:
        c = mpc_cos_pi(z, wp)
        s = mpc_sin_pi(z, wp)
        q = mpc_mul_mpf(mpc_div(c, s, wp), mpf_pi(wp), wp)
        p = mpc_psi0(mpc_sub(mpc_one, z, wp), wp)
        return mpc_sub(p, q, prec, rnd)
    # Just the logarithmic term
    if (not sign) and bc + exp > wp:
        return mpc_log(mpc_sub(z, mpc_one, wp), prec, rnd)
    # Initial recurrence to obtain a large enough z
    w = to_int(re)
    n = int(0.11*wp) + 2
    s = mpc_zero
    if w < n:
        for k in xrange(w, n):
            s = mpc_sub(s, mpc_reciprocal(z, wp), wp)
            z = mpc_add_mpf(z, fone, wp)
    z = mpc_sub(z, mpc_one, wp)
    # Logarithmic and endpoint term
    s = mpc_add(s, mpc_log(z, wp), wp)
    s = mpc_add(s, mpc_div(mpc_half, z, wp), wp)
    # Euler-Maclaurin remainder sum
    z2 = mpc_square(z, wp)
    t = mpc_one
    prev = mpc_zero
    k = 1
    eps = mpf_shift(fone, -wp+2)
    while 1:
        t = mpc_mul(t, z2, wp)
        bern = mpf_bernoulli(2*k, wp)
        term = mpc_mpf_div(bern, mpc_mul_int(t, 2*k, wp), wp)
        s = mpc_sub(s, term, wp)
        szterm = mpc_abs(term, 10)
        if k > 2 and mpf_le(szterm, eps):
            break
        prev = term
        k += 1
    return s
Exemplo n.º 6
0
def mpc_psi0(z, prec, rnd=round_fast):
    """
    Computation of the digamma function (psi function of order 0)
    of a complex argument.
    """
    re, im = z
    # Fall back to the real case
    if im == fzero:
        return (mpf_psi0(re, prec, rnd), fzero)
    wp = prec + 20
    sign, man, exp, bc = re
    # Reflection formula
    if sign and exp + bc > 3:
        c = mpc_cos_pi(z, wp)
        s = mpc_sin_pi(z, wp)
        q = mpc_mul(mpc_div(c, s, wp), (mpf_pi(wp), fzero), wp)
        p = mpc_psi0(mpc_sub(mpc_one, z, wp), wp)
        return mpc_sub(p, q, prec, rnd)
    # Just the logarithmic term
    if (not sign) and bc + exp > wp:
        return mpc_log(mpc_sub(z, mpc_one, wp), prec, rnd)
    # Initial recurrence to obtain a large enough z
    w = to_int(re)
    n = int(0.11 * wp) + 2
    s = mpc_zero
    if w < n:
        for k in xrange(w, n):
            s = mpc_sub(s, mpc_div(mpc_one, z, wp), wp)
            z = mpc_add_mpf(z, fone, wp)
    z = mpc_sub(z, mpc_one, wp)
    # Logarithmic and endpoint term
    s = mpc_add(s, mpc_log(z, wp), wp)
    s = mpc_add(s, mpc_div(mpc_half, z, wp), wp)
    # Euler-Maclaurin remainder sum
    z2 = mpc_mul(z, z, wp)
    t = mpc_one
    prev = mpc_zero
    k = 1
    eps = mpf_shift(fone, -wp + 2)
    while 1:
        t = mpc_mul(t, z2, wp)
        bern = mpf_bernoulli(2 * k, wp)
        term = mpc_div((bern, fzero), mpc_mul_int(t, 2 * k, wp), wp)
        s = mpc_sub(s, term, wp)
        szterm = mpc_abs(term, 10)
        if k > 2 and mpf_le(szterm, eps):
            break
        prev = term
        k += 1
    return s