Ejemplo n.º 1
0
def test_evalf_bugs():
    assert NS(sin(1) + exp(-10**10), 10) == NS(sin(1), 10)
    assert NS(exp(10**10) + sin(1), 10) == NS(exp(10**10), 10)
    assert NS('log(1+1/10**50)', 20) == '1.0000000000000000000e-50'
    assert NS('log(10**100,10)', 10) == '100.0000000'
    assert NS('log(2)', 10) == '0.6931471806'
    assert NS(
        '(sin(x)-x)/x**3', 15, subs={x: '1/10**50'}) == '-0.166666666666667'
    assert NS(sin(1) + Rational(
        1, 10**100)*I, 15) == '0.841470984807897 + 1.00000000000000e-100*I'
    assert x.evalf() == x
    assert NS((1 + I)**2*I, 6) == '-2.00000'
    d = {n: (
        -1)**Rational(6, 7), y: (-1)**Rational(4, 7), x: (-1)**Rational(2, 7)}
    assert NS((x*(1 + y*(1 + n))).subs(d).evalf(), 6) == '0.346011 + 0.433884*I'
    assert NS(((-I - sqrt(2)*I)**2).evalf()) == '-5.82842712474619'
    assert NS((1 + I)**2*I, 15) == '-2.00000000000000'
    # issue sympy/sympy#4758 (1/2):
    assert NS(Float(pi.evalf(69), 100) - pi) == '-4.43863937855894e-71'
    assert NS(pi.evalf(69) - pi) == '-0.e-71'
    # issue sympy/sympy#4758 (2/2): With the bug present, this still only fails if the
    # terms are in the order given here. This is not generally the case,
    # because the order depends on the hashes of the terms.
    assert NS(20 - 5008329267844*n**25 - 477638700*n**37 - 19*n,
              subs={n: .01}) == '19.8100000000000'
    assert NS(((x - 1)*((1 - x))**1000).n()
              ) == '(-x + 1.00000000000000)**1000*(x - 1.00000000000000)'
    assert NS((-x).n()) == '-x'
    assert NS((-2*x).n()) == '-2.00000000000000*x'
    assert NS((-2*x*y).n()) == '-2.00000000000000*x*y'
    assert cos(x).n(subs={x: 1+I}) == cos(x).subs(x, 1+I).n()
    # issue sympy/sympy#6660. Also NaN != mpmath.nan
    # In this order:
    # 0*nan, 0/nan, 0*inf, 0/inf
    # 0+nan, 0-nan, 0+inf, 0-inf
    # >>> n = Some Number
    # n*nan, n/nan, n*inf, n/inf
    # n+nan, n-nan, n+inf, n-inf
    assert (0*sin(oo)).n() == S.Zero
    assert (0/sin(oo)).n() == S.Zero
    assert (0*E**(oo)).n() == S.NaN
    assert (0/E**(oo)).n() == S.Zero

    assert (0+sin(oo)).n() == S.NaN
    assert (0-sin(oo)).n() == S.NaN
    assert (0+E**(oo)).n() == S.Infinity
    assert (0-E**(oo)).n() == S.NegativeInfinity

    assert (5*sin(oo)).n() == S.NaN
    assert (5/sin(oo)).n() == S.NaN
    assert (5*E**(oo)).n() == S.Infinity
    assert (5/E**(oo)).n() == S.Zero

    assert (5+sin(oo)).n() == S.NaN
    assert (5-sin(oo)).n() == S.NaN
    assert (5+E**(oo)).n() == S.Infinity
    assert (5-E**(oo)).n() == S.NegativeInfinity

    # issue sympy/sympy#7416
    assert as_mpmath(0.0, 10, {'chop': True}) == 0
Ejemplo n.º 2
0
def test_evalf_helpers():
    assert complex_accuracy((from_float(2.0), None, 35, None)) == 35
    assert complex_accuracy((from_float(2.0), from_float(10.0), 35, 100)) == 37
    assert complex_accuracy(
        (from_float(2.0), from_float(1000.0), 35, 100)) == 43
    assert complex_accuracy((from_float(2.0), from_float(10.0), 100, 35)) == 35
    assert complex_accuracy(
        (from_float(2.0), from_float(1000.0), 100, 35)) == 35

    _create_evalf_table()
    assert as_mpmath(1 + I, 2, {}) == mpc(1.0, 1.0)
Ejemplo n.º 3
0
def test_evalf_helpers():
    assert complex_accuracy((from_float(2.0), None, 35, None)) == 35
    assert complex_accuracy((from_float(2.0), from_float(10.0), 35, 100)) == 37
    assert complex_accuracy(
        (from_float(2.0), from_float(1000.0), 35, 100)) == 43
    assert complex_accuracy((from_float(2.0), from_float(10.0), 100, 35)) == 35
    assert complex_accuracy(
        (from_float(2.0), from_float(1000.0), 100, 35)) == 35

    _create_evalf_table()
    assert as_mpmath(1 + I, 2, {}) == mpc(1.0, 1.0)
Ejemplo n.º 4
0
def test_evalf_bugs():
    assert NS(sin(1) + exp(-10**10), 10) == NS(sin(1), 10)
    assert NS(exp(10**10) + sin(1), 10) == NS(exp(10**10), 10)
    assert NS('log(1+1/10**50)', 20) == '1.0000000000000000000e-50'
    assert NS('log(10**100,10)', 10) == '100.0000000'
    assert NS('log(2)', 10) == '0.6931471806'
    assert NS(
        '(sin(x)-x)/x**3', 15, subs={x: '1/10**50'}) == '-0.166666666666667'
    assert NS(sin(1) + I/10**100, 15) == '0.841470984807897 + 1.00000000000000e-100*I'
    assert x.evalf(strict=False) == x
    assert NS((1 + I)**2*I, 6) == '-2.00000'
    d = {n: (
        -1)**Rational(6, 7), y: (-1)**Rational(4, 7), x: (-1)**Rational(2, 7)}
    assert NS((x*(1 + y*(1 + n))).subs(d).evalf(), 6) == '0.346011 + 0.433884*I'
    assert NS(((-I - sqrt(2)*I)**2).evalf(), strict=False) == '-5.82842712474619'
    assert NS((1 + I)**2*I, 15) == '-2.00000000000000'
    # issue sympy/sympy#4758 (1/2):
    assert NS(Float(pi.evalf(69), 100) - pi) == '-4.43863937855894e-71'
    assert NS(pi.evalf(69) - pi, strict=False) == '-0.e-71'
    # issue sympy/sympy#4758 (2/2): With the bug present, this still only fails if the
    # terms are in the order given here. This is not generally the case,
    # because the order depends on the hashes of the terms.
    assert NS(20 - 5008329267844*n**25 - 477638700*n**37 - 19*n,
              subs={n: .01}, strict=False) == '19.8100000000000'
    assert NS(((x - 1)*((1 - x))**1000).evalf(strict=False),
              strict=False) == '(-x + 1.00000000000000)**1000*(x - 1.00000000000000)'
    assert NS((-x).evalf(strict=False)) == '-x'
    assert NS((-2*x).evalf(strict=False), strict=False) == '-2.00000000000000*x'
    assert NS((-2*x*y).evalf(strict=False), strict=False) == '-2.00000000000000*x*y'
    assert cos(x).evalf(subs={x: 1+I}) == cos(x).subs({x: 1 + I}).evalf()
    # issue sympy/sympy#6660. Also NaN != mpmath.nan
    # In this order:
    # 0*nan, 0/nan, 0*inf, 0/inf
    # 0+nan, 0-nan, 0+inf, 0-inf
    # >>> n = Some Number
    # n*nan, n/nan, n*inf, n/inf
    # n+nan, n-nan, n+inf, n-inf
    assert (0*sin(oo)).evalf() == 0
    assert (0/sin(oo)).evalf() == 0
    assert (0*E**oo).evalf() == nan
    assert (0/E**oo).evalf() == 0

    assert (0+sin(oo)).evalf() == nan
    assert (0-sin(oo)).evalf() == nan
    assert (0+E**oo).evalf() == +oo
    assert (0-E**oo).evalf() == -oo

    assert (5*sin(oo)).evalf() == nan
    assert (5/sin(oo)).evalf() == nan
    assert (5*E**oo).evalf() == oo
    assert (5/E**oo).evalf() == 0

    assert (5+sin(oo)).evalf() == nan
    assert (5-sin(oo)).evalf() == nan
    assert (5+E**oo).evalf() == +oo
    assert (5-E**oo).evalf() == -oo

    # issue sympy/sympy#7416
    assert as_mpmath(0.0, 10, {'chop': True}) == 0

    # issue sympy/sympy#5412
    assert (oo*I).evalf() == oo*I
    assert (oo + oo*I).evalf() == oo + oo*I