Esempio n. 1
0
def evalf_log(expr, prec, options):
    arg = expr.args[0]
    workprec = prec + 10
    xre, xim, xacc, _ = evalf(arg, workprec, options)

    if xim:
        # XXX: use get_abs etc instead
        re = evalf_log(C.log(C.Abs(arg, evaluate=False), evaluate=False), prec, options)
        im = mpf_atan2(xim, xre or fzero, prec)
        return re[0], im, re[2], prec

    imaginary_term = mpf_cmp(xre, fzero) < 0

    re = mpf_log(mpf_abs(xre), prec, rnd)
    size = fastlog(re)
    if prec - size > workprec:
        # We actually need to compute 1+x accurately, not x
        arg = C.Add(S.NegativeOne, arg, evaluate=False)
        xre, xim, _, _ = evalf_add(arg, prec, options)
        prec2 = workprec - fastlog(xre)
        re = mpf_log(mpf_add(xre, fone, prec2), prec, rnd)

    re_acc = prec

    if imaginary_term:
        return re, mpf_pi(prec), re_acc, prec
    else:
        return re, None, re_acc, None
Esempio n. 2
0
def evalf_log(expr, prec, options):
    arg = expr.args[0]
    workprec = prec + 10
    xre, xim, xacc, _ = evalf(arg, workprec, options)

    if xim:
        # XXX: use get_abs etc instead
        re = evalf_log(
            C.log(C.Abs(arg, evaluate=False), evaluate=False), prec, options)
        im = mpf_atan2(xim, xre or fzero, prec)
        return re[0], im, re[2], prec

    imaginary_term = (mpf_cmp(xre, fzero) < 0)

    re = mpf_log(mpf_abs(xre), prec, rnd)
    size = fastlog(re)
    if prec - size > workprec:
        # We actually need to compute 1+x accurately, not x
        arg = C.Add(S.NegativeOne, arg, evaluate=False)
        xre, xim, _, _ = evalf_add(arg, prec, options)
        prec2 = workprec - fastlog(xre)
        # xre is now x - 1 so we add 1 back here to calculate x
        re = mpf_log(mpf_abs(mpf_add(xre, fone, prec2)), prec, rnd)

    re_acc = prec

    if imaginary_term:
        return re, mpf_pi(prec), re_acc, prec
    else:
        return re, None, re_acc, None
Esempio n. 3
0
File: evalf.py Progetto: fxkr/sympy
 def calc_part(expr, nexpr):
     nint = int(to_int(nexpr, round_nearest))
     expr = C.Add(expr, -nint, evaluate=False)
     x, _, x_acc, _ = evalf(expr, 10, options)
     check_target(expr, (x, None, x_acc, None), 3)
     nint += int(no*(mpf_cmp(x or fzero, fzero) == no))
     nint = from_int(nint)
     return nint, fastlog(nint) + 10
Esempio n. 4
0
 def calc_part(expr, nexpr):
     nint = int(to_int(nexpr, round_nearest))
     expr = C.Add(expr, -nint, evaluate=False)
     x, _, x_acc, _ = evalf(expr, 10, options)
     check_target(expr, (x, None, x_acc, None), 3)
     nint += int(no * (mpf_cmp(x or fzero, fzero) == no))
     nint = from_int(nint)
     return nint, fastlog(nint) + 10
Esempio n. 5
0
 def calc_part(expr, nexpr):
     nint = int(to_int(nexpr, rnd))
     expr = C.Add(expr, -nint, evaluate=False)
     x, _, x_acc, _ = evalf(expr, 10, options)
     try:
         check_target(expr, (x, None, x_acc, None), 3)
     except PrecisionExhausted:
         if not expr.equals(0):
             raise PrecisionExhausted
         x = fzero
     nint += int(no * (mpf_cmp(x or fzero, fzero) == no))
     nint = from_int(nint)
     return nint, fastlog(nint) + 10
Esempio n. 6
0
 def calc_part(expr, nexpr):
     nint = int(to_int(nexpr, rnd))
     expr = C.Add(expr, -nint, evaluate=False)
     x, _, x_acc, _ = evalf(expr, 10, options)
     try:
         check_target(expr, (x, None, x_acc, None), 3)
     except PrecisionExhausted:
         if not expr.equals(0):
             raise PrecisionExhausted
         x = fzero
     nint += int(no*(mpf_cmp(x or fzero, fzero) == no))
     nint = from_int(nint)
     return nint, fastlog(nint) + 10