예제 #1
0
def test_AccumBounds():
    assert limit(sin(k) - sin(k + 1), k, oo) == AccumBounds(-2, 2)
    assert limit(cos(k) - cos(k + 1) + 1, k, oo) == AccumBounds(-1, 3)

    # not the exact bound
    assert limit(sin(k) - sin(k)*cos(k), k, oo) == AccumBounds(-2, 2)

    # test for issue #9934
    t1 = Mul(S.Half, 1/(-1 + cos(1)), Add(AccumBounds(-3, 1), cos(1)))
    assert limit(simplify(Sum(cos(n).rewrite(exp), (n, 0, k)).doit().rewrite(sin)), k, oo) == t1

    t2 = Mul(S.Half, Add(AccumBounds(-2, 2), sin(1)), 1/(-cos(1) + 1))
    assert limit(simplify(Sum(sin(n).rewrite(exp), (n, 0, k)).doit().rewrite(sin)), k, oo) == t2

    assert limit(frac(x)**x, x, oo) == AccumBounds(0, oo)
    assert limit(((sin(x) + 1)/2)**x, x, oo) == AccumBounds(0, oo)
예제 #2
0
def test_series_AccumBounds():
    assert limit(sin(k) - sin(k + 1), k, oo) == AccumBounds(-2, 2)
    assert limit(cos(k) - cos(k + 1) + 1, k, oo) == AccumBounds(-1, 3)

    # not the exact bound
    assert limit(sin(k) - sin(k)*cos(k), k, oo) == AccumBounds(-2, 2)

    # test for issue #9934
    t1 = Mul(AccumBounds(-S(3)/2 + cos(1)/2, cos(1)/2 + S.Half), 1/(-1 + cos(1)))
    assert limit(simplify(Sum(cos(n).rewrite(exp), (n, 0, k)).doit().rewrite(sin)), k, oo) == t1

    t2 = Mul(AccumBounds(-1 + sin(1)/2, sin(1)/2 + 1), 1/(1 - cos(1)))
    assert limit(simplify(Sum(sin(n).rewrite(exp), (n, 0, k)).doit().rewrite(sin)), k, oo) == t2

    assert limit(frac(x)**x, x, oo) == AccumBounds(0, oo)  # wolfram gives (0, 1)
    assert limit(((sin(x) + 1)/2)**x, x, oo) == AccumBounds(0, oo)  # wolfram says 0
예제 #3
0
 def _eval_nseries(self, x, n, logx, cdir=0):
     arg = self.args[0]
     arg0 = arg.subs(x, 0)
     if arg0.is_infinite:
         from sympy.calculus.util import AccumBounds
         from sympy.series.order import Order
         s = arg._eval_nseries(x, n, logx, cdir)
         o = Order(1, (x, 0)) if n <= 0  else AccumBounds(0, 1)
         return s + o
     r = self.subs(x, 0)
     if arg0 == r:
         direction = (arg - arg0).leadterm(x)[0]
         if direction.is_positive:
             return r + 1
         else:
             return r
     else:
         return r
예제 #4
0
def test_ceiling():
    assert limit(ceiling(x), x, -2, "+") == -1
    assert limit(ceiling(x), x, -2, "-") == -2
    assert limit(ceiling(x), x, -1, "+") == 0
    assert limit(ceiling(x), x, -1, "-") == -1
    assert limit(ceiling(x), x, 0, "+") == 1
    assert limit(ceiling(x), x, 0, "-") == 0
    assert limit(ceiling(x), x, 1, "+") == 2
    assert limit(ceiling(x), x, 1, "-") == 1
    assert limit(ceiling(x), x, 2, "+") == 3
    assert limit(ceiling(x), x, 2, "-") == 2
    assert limit(ceiling(x), x, 248, "+") == 249
    assert limit(ceiling(x), x, 248, "-") == 248

    # https://github.com/sympy/sympy/issues/14478
    assert limit(x * ceiling(3 / x) / 2, x, 0, '+') == Rational(3, 2)
    assert limit(ceiling(x + 1 / 2) - ceiling(x), x,
                 oo) == AccumBounds(-0.5, 1.5)
예제 #5
0
def test_comparison_AccumBounds():
    assert (AccumBounds(1, 3) < 4) == S.true
    assert (AccumBounds(1, 3) < -1) == S.false
    assert (AccumBounds(1, 3) < 2).rel_op == '<'
    assert (AccumBounds(1, 3) <= 2).rel_op == '<='

    assert (AccumBounds(1, 3) > 4) == S.false
    assert (AccumBounds(1, 3) > -1) == S.true
    assert (AccumBounds(1, 3) > 2).rel_op == '>'
    assert (AccumBounds(1, 3) >= 2).rel_op == '>='

    assert (AccumBounds(1, 3) < AccumBounds(4, 6)) == S.true
    assert (AccumBounds(1, 3) < AccumBounds(2, 4)).rel_op == '<'
    assert (AccumBounds(1, 3) < AccumBounds(-2, 0)) == S.false

    assert (AccumBounds(1, 3) <= AccumBounds(4, 6)) == S.true
    assert (AccumBounds(1, 3) <= AccumBounds(-2, 0)) == S.false

    assert (AccumBounds(1, 3) > AccumBounds(4, 6)) == S.false
    assert (AccumBounds(1, 3) > AccumBounds(-2, 0)) == S.true

    assert (AccumBounds(1, 3) >= AccumBounds(4, 6)) == S.false
    assert (AccumBounds(1, 3) >= AccumBounds(-2, 0)) == S.true

    # issue 13499
    assert (cos(x) > 0).subs(x, oo) == (AccumBounds(-1, 1) > 0)

    c = Symbol('c')
    raises(TypeError, lambda: (AccumBounds(0, 1) < c))
    raises(TypeError, lambda: (AccumBounds(0, 1) <= c))
    raises(TypeError, lambda: (AccumBounds(0, 1) > c))
    raises(TypeError, lambda: (AccumBounds(0, 1) >= c))
예제 #6
0
def test_AccumBounds_pow():
    assert AccumBounds(0, 2)**2 == AccumBounds(0, 4)
    assert AccumBounds(-1, 1)**2 == AccumBounds(0, 1)
    assert AccumBounds(1, 2)**2 == AccumBounds(1, 4)
    assert AccumBounds(-1, 2)**3 == AccumBounds(-1, 8)
    assert AccumBounds(-1, 1)**0 == 1

    assert AccumBounds(1, 2)**Rational(5, 2) == AccumBounds(1, 4*sqrt(2))
    assert AccumBounds(-1, 2)**Rational(1, 3) == AccumBounds(-1, 2**Rational(1, 3))
    assert AccumBounds(0, 2)**S.Half == AccumBounds(0, sqrt(2))

    assert AccumBounds(-4, 2)**Rational(2, 3) == AccumBounds(0, 2*2**Rational(1, 3))

    assert AccumBounds(-1, 5)**S.Half == AccumBounds(0, sqrt(5))
    assert AccumBounds(-oo, 2)**S.Half == AccumBounds(0, sqrt(2))
    assert AccumBounds(-2, 3)**Rational(-1, 4) == AccumBounds(0, oo)

    assert AccumBounds(1, 5)**(-2) == AccumBounds(Rational(1, 25), 1)
    assert AccumBounds(-1, 3)**(-2) == AccumBounds(0, oo)
    assert AccumBounds(0, 2)**(-2) == AccumBounds(Rational(1, 4), oo)
    assert AccumBounds(-1, 2)**(-3) == AccumBounds(-oo, oo)
    assert AccumBounds(-3, -2)**(-3) == AccumBounds(Rational(-1, 8), Rational(-1, 27))
    assert AccumBounds(-3, -2)**(-2) == AccumBounds(Rational(1, 9), Rational(1, 4))
    assert AccumBounds(0, oo)**S.Half == AccumBounds(0, oo)
    assert AccumBounds(-oo, -1)**Rational(1, 3) == AccumBounds(-oo, -1)
    assert AccumBounds(-2, 3)**(Rational(-1, 3)) == AccumBounds(-oo, oo)
    assert AccumBounds(-oo, 0)**(-2) == AccumBounds(0, oo)
    assert AccumBounds(-2, 0)**(-2) == AccumBounds(Rational(1, 4), oo)

    assert AccumBounds(Rational(1, 3), S.Half)**oo is S.Zero
    assert AccumBounds(0, S.Half)**oo is S.Zero
    assert AccumBounds(S.Half, 1)**oo == AccumBounds(0, oo)
    assert AccumBounds(0, 1)**oo == AccumBounds(0, oo)
    assert AccumBounds(2, 3)**oo is oo
    assert AccumBounds(1, 2)**oo == AccumBounds(0, oo)
    assert AccumBounds(S.Half, 3)**oo == AccumBounds(0, oo)
    assert AccumBounds(Rational(-1, 3), Rational(-1, 4))**oo is S.Zero
    assert AccumBounds(-1, Rational(-1, 2))**oo == AccumBounds(-oo, oo)
    assert AccumBounds(-3, -2)**oo == FiniteSet(-oo, oo)
    assert AccumBounds(-2, -1)**oo == AccumBounds(-oo, oo)
    assert AccumBounds(-2, Rational(-1, 2))**oo == AccumBounds(-oo, oo)
    assert AccumBounds(Rational(-1, 2), S.Half)**oo is S.Zero
    assert AccumBounds(Rational(-1, 2), 1)**oo == AccumBounds(0, oo)
    assert AccumBounds(Rational(-2, 3), 2)**oo == AccumBounds(0, oo)
    assert AccumBounds(-1, 1)**oo == AccumBounds(-oo, oo)
    assert AccumBounds(-1, S.Half)**oo == AccumBounds(-oo, oo)
    assert AccumBounds(-1, 2)**oo == AccumBounds(-oo, oo)
    assert AccumBounds(-2, S.Half)**oo == AccumBounds(-oo, oo)

    assert AccumBounds(1, 2)**x == Pow(AccumBounds(1, 2), x)

    assert AccumBounds(2, 3)**(-oo) is S.Zero
    assert AccumBounds(0, 2)**(-oo) == AccumBounds(0, oo)
    assert AccumBounds(-1, 2)**(-oo) == AccumBounds(-oo, oo)

    assert (tan(x)**sin(2*x)).subs(x, AccumBounds(0, pi/2)) == \
        Pow(AccumBounds(-oo, oo), AccumBounds(0, 1))
예제 #7
0
def test_AccumBounds_func():
    assert (x**2 + 2*x + 1).subs(x, AccumBounds(-1, 1)) == AccumBounds(-1, 4)
    assert exp(AccumBounds(0, 1)) == AccumBounds(1, E)
    assert exp(AccumBounds(-oo, oo)) == AccumBounds(0, oo)
    assert log(AccumBounds(3, 6)) == AccumBounds(log(3), log(6))
예제 #8
0
def test_AccumBounds_div():
    assert AccumBounds(-1, 3)/AccumBounds(3, 4) == AccumBounds(Rational(-1, 3), 1)
    assert AccumBounds(-2, 4)/AccumBounds(-3, 4) == AccumBounds(-oo, oo)
    assert AccumBounds(-3, -2)/AccumBounds(-4, 0) == AccumBounds(S.Half, oo)

    # these two tests can have a better answer
    # after Union of AccumBounds is improved
    assert AccumBounds(-3, -2)/AccumBounds(-2, 1) == AccumBounds(-oo, oo)
    assert AccumBounds(2, 3)/AccumBounds(-2, 2) == AccumBounds(-oo, oo)

    assert AccumBounds(-3, -2)/AccumBounds(0, 4) == AccumBounds(-oo, Rational(-1, 2))
    assert AccumBounds(2, 4)/AccumBounds(-3, 0) == AccumBounds(-oo, Rational(-2, 3))
    assert AccumBounds(2, 4)/AccumBounds(0, 3) == AccumBounds(Rational(2, 3), oo)

    assert AccumBounds(0, 1)/AccumBounds(0, 1) == AccumBounds(0, oo)
    assert AccumBounds(-1, 0)/AccumBounds(0, 1) == AccumBounds(-oo, 0)
    assert AccumBounds(-1, 2)/AccumBounds(-2, 2) == AccumBounds(-oo, oo)

    assert 1/AccumBounds(-1, 2) == AccumBounds(-oo, oo)
    assert 1/AccumBounds(0, 2) == AccumBounds(S.Half, oo)
    assert (-1)/AccumBounds(0, 2) == AccumBounds(-oo, Rational(-1, 2))
    assert 1/AccumBounds(-oo, 0) == AccumBounds(-oo, 0)
    assert 1/AccumBounds(-1, 0) == AccumBounds(-oo, -1)
    assert (-2)/AccumBounds(-oo, 0) == AccumBounds(0, oo)
    assert 1/AccumBounds(-oo, -1) == AccumBounds(-1, 0)

    assert AccumBounds(1, 2)/a == Mul(AccumBounds(1, 2), 1/a, evaluate=False)

    assert AccumBounds(1, 2)/0 == AccumBounds(1, 2)*zoo
    assert AccumBounds(1, oo)/oo == AccumBounds(0, oo)
    assert AccumBounds(1, oo)/(-oo) == AccumBounds(-oo, 0)
    assert AccumBounds(-oo, -1)/oo == AccumBounds(-oo, 0)
    assert AccumBounds(-oo, -1)/(-oo) == AccumBounds(0, oo)
    assert AccumBounds(-oo, oo)/oo == AccumBounds(-oo, oo)
    assert AccumBounds(-oo, oo)/(-oo) == AccumBounds(-oo, oo)
    assert AccumBounds(-1, oo)/oo == AccumBounds(0, oo)
    assert AccumBounds(-1, oo)/(-oo) == AccumBounds(-oo, 0)
    assert AccumBounds(-oo, 1)/oo == AccumBounds(-oo, 0)
    assert AccumBounds(-oo, 1)/(-oo) == AccumBounds(0, oo)
예제 #9
0
def test_AccumBounds_mul():
    assert AccumBounds(1, 2)*2 == AccumBounds(2, 4)
    assert 2*AccumBounds(1, 2) == AccumBounds(2, 4)
    assert AccumBounds(1, 2)*AccumBounds(2, 3) == AccumBounds(2, 6)

    assert AccumBounds(1, 2)*0 == 0
    assert AccumBounds(1, oo)*0 == AccumBounds(0, oo)
    assert AccumBounds(-oo, 1)*0 == AccumBounds(-oo, 0)
    assert AccumBounds(-oo, oo)*0 == AccumBounds(-oo, oo)

    assert AccumBounds(1, 2)*x == Mul(AccumBounds(1, 2), x, evaluate=False)

    assert AccumBounds(0, 2)*oo == AccumBounds(0, oo)
    assert AccumBounds(-2, 0)*oo == AccumBounds(-oo, 0)
    assert AccumBounds(0, 2)*(-oo) == AccumBounds(-oo, 0)
    assert AccumBounds(-2, 0)*(-oo) == AccumBounds(0, oo)
    assert AccumBounds(-1, 1)*oo == AccumBounds(-oo, oo)
    assert AccumBounds(-1, 1)*(-oo) == AccumBounds(-oo, oo)
    assert AccumBounds(-oo, oo)*oo == AccumBounds(-oo, oo)
예제 #10
0
파일: test_limits.py 프로젝트: msgoff/sympy
def test_heuristic():
    x = Symbol("x", real=True)
    assert heuristics(sin(1 / x) + atan(x), x, 0, "+") == AccumBounds(-1, 1)
    assert limit(log(2 + sqrt(atan(x)) * sqrt(sin(1 / x))), x, 0) == log(2)
def test_comparison_AccumBounds():
    assert (AccumBounds(1, 3) < 4) == S.true
    assert (AccumBounds(1, 3) < -1) == S.false
    assert (AccumBounds(1, 3) < 2) is None

    assert (AccumBounds(1, 3) > 4) == S.false
    assert (AccumBounds(1, 3) > -1) == S.true
    assert (AccumBounds(1, 3) > 2) is None

    assert (AccumBounds(1, 3) < AccumBounds(4, 6)) == S.true
    assert (AccumBounds(1, 3) < AccumBounds(2, 4)) is None
    assert (AccumBounds(1, 3) < AccumBounds(-2, 0)) == S.false
def test_AccumBounds_pow():
    assert AccumBounds(0, 2)**2 == AccumBounds(0, 4)
    assert AccumBounds(-1, 1)**2 == AccumBounds(0, 1)
    assert AccumBounds(1, 2)**2 == AccumBounds(1, 4)
    assert AccumBounds(-1, 2)**3 == AccumBounds(-1, 8)
    assert AccumBounds(-1, 1)**0 == 1

    assert AccumBounds(1, 2)**(S(5) / 2) == AccumBounds(1, 4 * sqrt(2))
    assert AccumBounds(-1, 2)**(S(1) / 3) == AccumBounds(-1, 2**(S(1) / 3))
    assert AccumBounds(0, 2)**(S(1) / 2) == AccumBounds(0, sqrt(2))

    assert AccumBounds(-4, 2)**(S(2) / 3) == AccumBounds(0, 2 * 2**(S(1) / 3))

    assert AccumBounds(-1, 5)**(S(1) / 2) == AccumBounds(0, sqrt(5))
    assert AccumBounds(-oo, 2)**(S(1) / 2) == AccumBounds(0, sqrt(2))
    assert AccumBounds(-2, 3)**(S(-1) / 4) == AccumBounds(0, oo)

    assert AccumBounds(1, 5)**(-2) == AccumBounds(S(1) / 25, 1)
    assert AccumBounds(-1, 3)**(-2) == AccumBounds(0, oo)
    assert AccumBounds(0, 2)**(-2) == AccumBounds(S(1) / 4, oo)
    assert AccumBounds(-1, 2)**(-3) == AccumBounds(-oo, oo)
    assert AccumBounds(-3, -2)**(-3) == AccumBounds(S(-1) / 8, -S(1) / 27)
    assert AccumBounds(-3, -2)**(-2) == AccumBounds(S(1) / 9, S(1) / 4)
    assert AccumBounds(0, oo)**(S(1) / 2) == AccumBounds(0, oo)
    assert AccumBounds(-oo, -1)**(S(1) / 3) == AccumBounds(-oo, -1)
    assert AccumBounds(-2, 3)**(-S(1) / 3) == AccumBounds(-oo, oo)
    assert AccumBounds(-oo, 0)**(-2) == AccumBounds(0, oo)
    assert AccumBounds(-2, 0)**(-2) == AccumBounds(S(1) / 4, oo)

    assert AccumBounds(S(1) / 3, S(1) / 2)**oo == S(0)
    assert AccumBounds(0, S(1) / 2)**oo == S(0)
    assert AccumBounds(S(1) / 2, 1)**oo == AccumBounds(0, oo)
    assert AccumBounds(0, 1)**oo == AccumBounds(0, oo)
    assert AccumBounds(2, 3)**oo == oo
    assert AccumBounds(1, 2)**oo == AccumBounds(0, oo)
    assert AccumBounds(S(1) / 2, 3)**oo == AccumBounds(0, oo)
    assert AccumBounds(-S(1) / 3, -S(1) / 4)**oo == S(0)
    assert AccumBounds(-1, -S(1) / 2)**oo == AccumBounds(-oo, oo)
    assert AccumBounds(-3, -2)**oo == FiniteSet(-oo, oo)
    assert AccumBounds(-2, -1)**oo == AccumBounds(-oo, oo)
    assert AccumBounds(-2, -S(1) / 2)**oo == AccumBounds(-oo, oo)
    assert AccumBounds(-S(1) / 2, S(1) / 2)**oo == S(0)
    assert AccumBounds(-S(1) / 2, 1)**oo == AccumBounds(0, oo)
    assert AccumBounds(-S(2) / 3, 2)**oo == AccumBounds(0, oo)
    assert AccumBounds(-1, 1)**oo == AccumBounds(-oo, oo)
    assert AccumBounds(-1, S(1) / 2)**oo == AccumBounds(-oo, oo)
    assert AccumBounds(-1, 2)**oo == AccumBounds(-oo, oo)
    assert AccumBounds(-2, S(1) / 2)**oo == AccumBounds(-oo, oo)

    assert AccumBounds(1, 2)**x == Pow(AccumBounds(1, 2), x, evaluate=False)

    assert AccumBounds(2, 3)**(-oo) == S(0)
    assert AccumBounds(0, 2)**(-oo) == AccumBounds(0, oo)
    assert AccumBounds(-1, 2)**(-oo) == AccumBounds(-oo, oo)

    assert (tan(x)**sin(2*x)).subs(x, AccumBounds(0, pi/2)) == \
        Pow(AccumBounds(-oo, oo), AccumBounds(0, 1), evaluate=False)
def test_AccumBounds():
    assert AccumBounds(1, 2).args == (1, 2)
    assert AccumBounds(1, 2).delta == S(1)
    assert AccumBounds(1, 2).mid == S(3) / 2
    assert AccumBounds(1, 3).is_real == True

    assert AccumBounds(1, 1) == S(1)

    assert AccumBounds(1, 2) + 1 == AccumBounds(2, 3)
    assert 1 + AccumBounds(1, 2) == AccumBounds(2, 3)
    assert AccumBounds(1, 2) + AccumBounds(2, 3) == AccumBounds(3, 5)

    assert -AccumBounds(1, 2) == AccumBounds(-2, -1)

    assert AccumBounds(1, 2) - 1 == AccumBounds(0, 1)
    assert 1 - AccumBounds(1, 2) == AccumBounds(-1, 0)
    assert AccumBounds(2, 3) - AccumBounds(1, 2) == AccumBounds(0, 2)

    assert x + AccumBounds(1, 2) == Add(AccumBounds(1, 2), x)
    assert a + AccumBounds(1, 2) == AccumBounds(1 + a, 2 + a)
    assert AccumBounds(1, 2) - x == Add(AccumBounds(1, 2), -x)

    assert AccumBounds(-oo, 1) + oo == AccumBounds(-oo, oo)
    assert AccumBounds(1, oo) + oo == oo
    assert AccumBounds(1, oo) - oo == AccumBounds(-oo, oo)
    assert (-oo - AccumBounds(-1, oo)) == -oo
    assert AccumBounds(-oo, 1) - oo == -oo

    assert AccumBounds(1, oo) - oo == AccumBounds(-oo, oo)
    assert AccumBounds(-oo, 1) - (-oo) == AccumBounds(-oo, oo)
    assert (oo - AccumBounds(1, oo)) == AccumBounds(-oo, oo)
    assert (-oo - AccumBounds(1, oo)) == -oo

    assert AccumBounds(1, 2) / 2 == AccumBounds(S(1) / 2, 1)
    assert 2 / AccumBounds(2, 3) == AccumBounds(S(2) / 3, 1)
    assert 1 / AccumBounds(-1, 1) == AccumBounds(-oo, oo)

    assert abs(AccumBounds(1, 2)) == AccumBounds(1, 2)
    assert abs(AccumBounds(-2, -1)) == AccumBounds(1, 2)
    assert abs(AccumBounds(-2, 1)) == AccumBounds(0, 2)
    assert abs(AccumBounds(-1, 2)) == AccumBounds(0, 2)
예제 #14
0
def test_comparison_AccumBounds():
    assert (AccumBounds(1, 3) < 4) == S.true
    assert (AccumBounds(1, 3) < -1) == S.false
    assert (AccumBounds(1, 3) < 2).rel_op == '<'
    assert (AccumBounds(1, 3) <= 2).rel_op == '<='

    assert (AccumBounds(1, 3) > 4) == S.false
    assert (AccumBounds(1, 3) > -1) == S.true
    assert (AccumBounds(1, 3) > 2).rel_op == '>'
    assert (AccumBounds(1, 3) >= 2).rel_op == '>='

    assert (AccumBounds(1, 3) < AccumBounds(4, 6)) == S.true
    assert (AccumBounds(1, 3) < AccumBounds(2, 4)).rel_op == '<'
    assert (AccumBounds(1, 3) < AccumBounds(-2, 0)) == S.false

    # issue 13499
    assert (cos(x) > 0).subs(x, oo) == (AccumBounds(-1, 1) > 0)
예제 #15
0
def test_intersection_AccumBounds():
    assert AccumBounds(0, 3).intersection(AccumBounds(1, 2)) == AccumBounds(1, 2)
    assert AccumBounds(0, 3).intersection(AccumBounds(1, 4)) == AccumBounds(1, 3)
    assert AccumBounds(0, 3).intersection(AccumBounds(-1, 2)) == AccumBounds(0, 2)
    assert AccumBounds(0, 3).intersection(AccumBounds(-1, 4)) == AccumBounds(0, 3)
    assert AccumBounds(0, 1).intersection(AccumBounds(2, 3)) == S.EmptySet
    raises(TypeError, lambda: AccumBounds(0, 3).intersection(1))
예제 #16
0
def test_union_AccumBounds():
    assert AccumBounds(0, 3).union(AccumBounds(1, 2)) == AccumBounds(0, 3)
    assert AccumBounds(0, 3).union(AccumBounds(1, 4)) == AccumBounds(0, 4)
    assert AccumBounds(0, 3).union(AccumBounds(-1, 2)) == AccumBounds(-1, 3)
    assert AccumBounds(0, 3).union(AccumBounds(-1, 4)) == AccumBounds(-1, 4)
    raises(TypeError, lambda: AccumBounds(0, 3).union(1))
def test_contains_AccumBounds():
    assert (1 in AccumBounds(1, 2)) == S.true
    raises(TypeError, lambda: a in AccumBounds(1, 2))
    assert (-oo in AccumBounds(1, oo)) == S.true
    assert (oo in AccumBounds(-oo, 0)) == S.true
예제 #18
0
파일: test_limits.py 프로젝트: msgoff/sympy
def test_issue_18442():
    assert limit(tan(x)**(2**(sqrt(pi))), x, oo,
                 dir="-") == AccumBounds(-oo, oo)
예제 #19
0
def test_AccumBounds():
    assert AccumBounds(1, 2).args == (1, 2)
    assert AccumBounds(1, 2).delta is S.One
    assert AccumBounds(1, 2).mid == Rational(3, 2)
    assert AccumBounds(1, 3).is_real == True

    assert AccumBounds(1, 1) is S.One

    assert AccumBounds(1, 2) + 1 == AccumBounds(2, 3)
    assert 1 + AccumBounds(1, 2) == AccumBounds(2, 3)
    assert AccumBounds(1, 2) + AccumBounds(2, 3) == AccumBounds(3, 5)

    assert -AccumBounds(1, 2) == AccumBounds(-2, -1)

    assert AccumBounds(1, 2) - 1 == AccumBounds(0, 1)
    assert 1 - AccumBounds(1, 2) == AccumBounds(-1, 0)
    assert AccumBounds(2, 3) - AccumBounds(1, 2) == AccumBounds(0, 2)

    assert x + AccumBounds(1, 2) == Add(AccumBounds(1, 2), x)
    assert a + AccumBounds(1, 2) == AccumBounds(1 + a, 2 + a)
    assert AccumBounds(1, 2) - x == Add(AccumBounds(1, 2), -x)

    assert AccumBounds(-oo, 1) + oo == AccumBounds(-oo, oo)
    assert AccumBounds(1, oo) + oo is oo
    assert AccumBounds(1, oo) - oo == AccumBounds(-oo, oo)
    assert (-oo - AccumBounds(-1, oo)) is -oo
    assert AccumBounds(-oo, 1) - oo is -oo

    assert AccumBounds(1, oo) - oo == AccumBounds(-oo, oo)
    assert AccumBounds(-oo, 1) - (-oo) == AccumBounds(-oo, oo)
    assert (oo - AccumBounds(1, oo)) == AccumBounds(-oo, oo)
    assert (-oo - AccumBounds(1, oo)) is -oo

    assert AccumBounds(1, 2)/2 == AccumBounds(S.Half, 1)
    assert 2/AccumBounds(2, 3) == AccumBounds(Rational(2, 3), 1)
    assert 1/AccumBounds(-1, 1) == AccumBounds(-oo, oo)

    assert abs(AccumBounds(1, 2)) == AccumBounds(1, 2)
    assert abs(AccumBounds(-2, -1)) == AccumBounds(1, 2)
    assert abs(AccumBounds(-2, 1)) == AccumBounds(0, 2)
    assert abs(AccumBounds(-1, 2)) == AccumBounds(0, 2)
    c = Symbol('c')
    raises(ValueError, lambda: AccumBounds(0, c))
    raises(ValueError, lambda: AccumBounds(1, -1))