コード例 #1
0
ファイル: test_str.py プロジェクト: diofant/diofant
def test_Limit():
    assert str(Limit(sin(x) / x, x, y)) == 'Limit(sin(x)/x, x, y)'
    assert str(Limit(1 / x, x, 0)) == 'Limit(1/x, x, 0)'
    assert str(Limit(sin(x) / x, x, y,
                     dir=1)) == 'Limit(sin(x)/x, x, y, dir=1)'
    assert str(Limit(sin(x) / x, x, y,
                     dir=Reals)) == 'Limit(sin(x)/x, x, y, dir=Reals)'
コード例 #2
0
def test__eis():
    assert _eis(z).diff(z) == -_eis(z) + 1 / z
    pytest.raises(ArgumentIndexError, lambda: _eis(x).fdiff(2))

    assert _eis(1/z).series(z) == \
        z + z**2 + 2*z**3 + 6*z**4 + 24*z**5 + O(z**6)

    assert Ei(z).rewrite('tractable') == exp(z) * _eis(z)
    assert li(z).rewrite('tractable') == z * _eis(log(z))

    assert _eis(z).rewrite('intractable') == exp(-z) * Ei(z)

    assert expand(li(z).rewrite('tractable').diff(z).rewrite('intractable')) \
        == li(z).diff(z)

    assert expand(Ei(z).rewrite('tractable').diff(z).rewrite('intractable')) \
        == Ei(z).diff(z)

    assert _eis(z).series(
        z,
        n=2) == EulerGamma + log(z) + z * (-log(z) - EulerGamma + 1) + z**2 * (
            log(z) / 2 - Rational(3, 4) + EulerGamma / 2) + O(z**2)

    l = Limit(Ei(y / x) / exp(y / x), x, 0)
    assert l.doit() == l  # cover _eis._eval_aseries
コード例 #3
0
def test_Limit():
    e = Limit(sin(x)/x, x, 0)
    assert mathematica_code(e) == 'Hold[Limit[Sin[x]/x, x -> 0, Direction -> -1]]'
    e = Limit(sin(x)/x, x, 0, '-')
    assert mathematica_code(e) == 'Hold[Limit[Sin[x]/x, x -> 0, Direction -> 1]]'
    e = Limit(sin(x)/x, x, 0, 'real')
    assert mathematica_code(e) == 'Hold[Limit[Sin[x]/x, x -> 0, Direction -> Reals]]'
コード例 #4
0
ファイル: test_limits.py プロジェクト: naveensaigit/diofant
def test_basic4():
    assert limit(2*x + y*x, x, 0) == 0
    assert limit(2*x + y*x, x, 1) == 2 + y
    assert limit(2*x**8 + y*x**(-3), x, -2) == 512 - y/8
    assert limit(sqrt(x + 1) - sqrt(x), x, oo) == 0
    assert integrate(1/(x**3 + 1), (x, 0, oo)) == 2*pi*sqrt(3)/9

    # coverage test
    l = Limit(Piecewise((x, x > 1), (0, True)), x, -1)
    assert l.doit() == l
コード例 #5
0
ファイル: test_bessel.py プロジェクト: cbm755/diofant
def test_airybi():
    z = Symbol('z', extended_real=False)
    t = Symbol('t', negative=True)
    p = Symbol('p', positive=True)

    assert isinstance(airybi(z), airybi)

    assert airybi(0) == 3**Rational(5, 6) / (3 * gamma(Rational(2, 3)))
    assert airybi(oo) == oo
    assert airybi(-oo) == 0

    assert diff(airybi(z), z) == airybiprime(z)

    assert series(airybi(z), z, 0,
                  3) == (cbrt(3) * gamma(Rational(1, 3)) / (2 * pi) +
                         3**Rational(2, 3) * z * gamma(Rational(2, 3)) /
                         (2 * pi) + O(z**3))
    l = Limit(
        airybi(I / x) /
        (exp(Rational(2, 3) *
             (I / x)**Rational(3, 2)) * sqrt(pi * sqrt(I / x))), x, 0)
    assert l.doit() == l

    assert airybi(z).rewrite(hyper) == (root(3, 6) * z * hyper(
        (), (Rational(4, 3), ), z**3 / 9) / gamma(Rational(1, 3)) +
                                        3**Rational(5, 6) * hyper(
                                            (), (Rational(2, 3), ), z**3 / 9) /
                                        (3 * gamma(Rational(2, 3))))

    assert isinstance(airybi(z).rewrite(besselj), airybi)
    assert (airybi(t).rewrite(besselj) == sqrt(3) * sqrt(-t) *
            (besselj(-1 / 3, 2 * (-t)**Rational(3, 2) / 3) -
             besselj(Rational(1, 3), 2 * (-t)**Rational(3, 2) / 3)) / 3)
    assert airybi(z).rewrite(besseli) == (
        sqrt(3) * (z * besseli(Rational(1, 3), 2 * z**Rational(3, 2) / 3) /
                   cbrt(z**Rational(3, 2)) + cbrt(z**Rational(3, 2)) *
                   besseli(-Rational(1, 3), 2 * z**Rational(3, 2) / 3)) / 3)
    assert airybi(p).rewrite(besseli) == (
        sqrt(3) * sqrt(p) *
        (besseli(-Rational(1, 3), 2 * p**Rational(3, 2) / 3) +
         besseli(Rational(1, 3), 2 * p**Rational(3, 2) / 3)) / 3)
    assert airybi(p).rewrite(besselj) == airybi(p)

    assert expand_func(airybi(
        2 *
        cbrt(3 * z**5))) == (sqrt(3) * (1 - cbrt(z**5) / z**Rational(5, 3)) *
                             airyai(2 * cbrt(3) * z**Rational(5, 3)) / 2 +
                             (1 + cbrt(z**5) / z**Rational(5, 3)) *
                             airybi(2 * cbrt(3) * z**Rational(5, 3)) / 2)
    assert expand_func(airybi(x * y)) == airybi(x * y)
    assert expand_func(airybi(log(x))) == airybi(log(x))
    assert expand_func(airybi(2 * root(3 * z**5, 5))) == airybi(
        2 * root(3 * z**5, 5))

    assert airybi(x).taylor_term(-1, x) == 0
コード例 #6
0
ファイル: test_bessel.py プロジェクト: diofant/diofant
def test_airyai():
    z = Symbol('z', extended_real=False)
    r = Symbol('r', extended_real=True)
    t = Symbol('t', negative=True)
    p = Symbol('p', positive=True)

    assert isinstance(airyai(z), airyai)

    assert airyai(0) == cbrt(3)/(3*gamma(Rational(2, 3)))
    assert airyai(oo) == 0
    assert airyai(-oo) == 0

    assert diff(airyai(z), z) == airyaiprime(z)

    assert airyai(z).series(z, 0, 3) == (
        3**Rational(5, 6)*gamma(Rational(1, 3))/(6*pi) - root(3, 6)*z*gamma(Rational(2, 3))/(2*pi) + O(z**3))

    l = Limit(airyai(I/x)/(exp(-Rational(2, 3)*(I/x)**Rational(3, 2))*sqrt(pi*sqrt(I/x))/2), x, 0)
    assert l.doit() == l  # cover _airyais._eval_aseries

    assert airyai(z).rewrite(hyper) == (
        -3**Rational(2, 3)*z*hyper((), (Rational(4, 3),), z**3/9)/(3*gamma(Rational(1, 3))) +
        cbrt(3)*hyper((), (Rational(2, 3),), z**3/9)/(3*gamma(Rational(2, 3))))

    assert isinstance(airyai(z).rewrite(besselj), airyai)
    assert airyai(t).rewrite(besselj) == (
        sqrt(-t)*(besselj(-Rational(1, 3), 2*(-t)**Rational(3, 2)/3) +
                  besselj(Rational(1, 3), 2*(-t)**Rational(3, 2)/3))/3)
    assert airyai(z).rewrite(besseli) == (
        -z*besseli(Rational(1, 3), 2*z**Rational(3, 2)/3)/(3*cbrt(z**Rational(3, 2))) +
        cbrt(z**Rational(3, 2))*besseli(-Rational(1, 3), 2*z**Rational(3, 2)/3)/3)
    assert airyai(p).rewrite(besseli) == (
        sqrt(p)*(besseli(-Rational(1, 3), 2*p**Rational(3, 2)/3) -
                 besseli(Rational(1, 3), 2*p**Rational(3, 2)/3))/3)

    assert expand_func(airyai(2*cbrt(3*z**5))) == (
        -sqrt(3)*(-1 + cbrt(z**5)/z**Rational(5, 3))*airybi(2*cbrt(3)*z**Rational(5, 3))/6 +
        (1 + cbrt(z**5)/z**Rational(5, 3))*airyai(2*cbrt(3)*z**Rational(5, 3))/2)
    assert expand_func(airyai(x*y)) == airyai(x*y)
    assert expand_func(airyai(log(x))) == airyai(log(x))
    assert expand_func(airyai(2*root(3*z**5, 5))) == airyai(2*root(3*z**5, 5))

    assert (airyai(r).as_real_imag() ==
            airyai(r).as_real_imag(deep=False) == (airyai(r), 0))
    assert airyai(x).as_real_imag() == airyai(x).as_real_imag(deep=False)
    assert (airyai(x).as_real_imag() ==
            (airyai(re(x) - I*re(x)*abs(im(x))/abs(re(x)))/2 +
             airyai(re(x) + I*re(x)*abs(im(x))/abs(re(x)))/2,
             I*(airyai(re(x) - I*re(x)*abs(im(x))/abs(re(x))) -
                airyai(re(x) + I*re(x)*abs(im(x))/abs(re(x)))) *
             re(x)*abs(im(x))/(2*im(x)*abs(re(x)))))

    assert airyai(x).taylor_term(-1, x) == 0
コード例 #7
0
ファイル: test_bessel.py プロジェクト: skirpichev/diofant
def test_airyai():
    z = Symbol('z', extended_real=False)
    r = Symbol('r', extended_real=True)
    t = Symbol('t', negative=True)
    p = Symbol('p', positive=True)

    assert isinstance(airyai(z), airyai)

    assert airyai(0) == cbrt(3)/(3*gamma(Rational(2, 3)))
    assert airyai(oo) == 0
    assert airyai(-oo) == 0

    assert diff(airyai(z), z) == airyaiprime(z)

    assert series(airyai(z), z, 0, 3) == (
        3**Rational(5, 6)*gamma(Rational(1, 3))/(6*pi) - root(3, 6)*z*gamma(Rational(2, 3))/(2*pi) + O(z**3))

    l = Limit(airyai(I/x)/(exp(-Rational(2, 3)*(I/x)**Rational(3, 2))*sqrt(pi*sqrt(I/x))/2), x, 0)
    assert l.doit() == l  # cover _airyais._eval_aseries

    assert airyai(z).rewrite(hyper) == (
        -3**Rational(2, 3)*z*hyper((), (Rational(4, 3),), z**3/9)/(3*gamma(Rational(1, 3))) +
        cbrt(3)*hyper((), (Rational(2, 3),), z**3/9)/(3*gamma(Rational(2, 3))))

    assert isinstance(airyai(z).rewrite(besselj), airyai)
    assert airyai(t).rewrite(besselj) == (
        sqrt(-t)*(besselj(-Rational(1, 3), 2*(-t)**Rational(3, 2)/3) +
                  besselj(Rational(1, 3), 2*(-t)**Rational(3, 2)/3))/3)
    assert airyai(z).rewrite(besseli) == (
        -z*besseli(Rational(1, 3), 2*z**Rational(3, 2)/3)/(3*cbrt(z**Rational(3, 2))) +
        cbrt(z**Rational(3, 2))*besseli(-Rational(1, 3), 2*z**Rational(3, 2)/3)/3)
    assert airyai(p).rewrite(besseli) == (
        sqrt(p)*(besseli(-Rational(1, 3), 2*p**Rational(3, 2)/3) -
                 besseli(Rational(1, 3), 2*p**Rational(3, 2)/3))/3)

    assert expand_func(airyai(2*cbrt(3*z**5))) == (
        -sqrt(3)*(-1 + cbrt(z**5)/z**Rational(5, 3))*airybi(2*cbrt(3)*z**Rational(5, 3))/6 +
        (1 + cbrt(z**5)/z**Rational(5, 3))*airyai(2*cbrt(3)*z**Rational(5, 3))/2)
    assert expand_func(airyai(x*y)) == airyai(x*y)
    assert expand_func(airyai(log(x))) == airyai(log(x))
    assert expand_func(airyai(2*root(3*z**5, 5))) == airyai(2*root(3*z**5, 5))

    assert (airyai(r).as_real_imag() ==
            airyai(r).as_real_imag(deep=False) == (airyai(r), 0))
    assert airyai(x).as_real_imag() == airyai(x).as_real_imag(deep=False)
    assert (airyai(x).as_real_imag() ==
            (airyai(re(x) - I*re(x)*abs(im(x))/abs(re(x)))/2 +
             airyai(re(x) + I*re(x)*abs(im(x))/abs(re(x)))/2,
             I*(airyai(re(x) - I*re(x)*abs(im(x))/abs(re(x))) -
                airyai(re(x) + I*re(x)*abs(im(x))/Abs(re(x)))) *
             re(x)*abs(im(x))/(2*im(x)*abs(re(x)))))

    assert airyai(x).taylor_term(-1, x) == 0
コード例 #8
0
def test_diofant_parser():
    x = Symbol('x')
    inputs = {
        '2*x':
        2 * x,
        '3.00':
        Float(3),
        '22/7':
        Rational(22, 7),
        '2+3j':
        2 + 3 * I,
        'exp(x)':
        exp(x),
        '-(2)':
        -Integer(2),
        '[-1, -2, 3]': [Integer(-1), Integer(-2),
                        Integer(3)],
        'Symbol("x").free_symbols':
        x.free_symbols,
        'Float(Integer(3).evalf(3))':
        3.00,
        'factorint(12, visual=True)':
        Mul(Pow(2, 2, evaluate=False),
            Pow(3, 1, evaluate=False),
            evaluate=False),
        'Limit(sin(x), x, 0, dir=1)':
        Limit(sin(x), x, 0, dir=1),
    }
    for text, result in inputs.items():
        assert parse_expr(text) == result
コード例 #9
0
def test_mathml_limits():
    # XXX No unevaluated limits
    lim_fun = sin(x) / x
    mml_1 = mp._print(Limit(lim_fun, x, 0))
    assert mml_1.childNodes[0].nodeName == 'limit'
    assert mml_1.childNodes[1].nodeName == 'bvar'
    assert mml_1.childNodes[2].nodeName == 'lowlimit'
    assert mml_1.childNodes[3].toxml() == mp._print(lim_fun).toxml()
コード例 #10
0
def test_diofantissue_558():
    n = Symbol('n')
    r = Symbol('r', positive=True)
    c = Symbol('c')
    expr = ((2*n*(n - r + 1)/(n + r*(n - r + 1)))**c +
            (r - 1)*(n*(n - r + 2)/(n + r*(n - r + 1)))**c - n)/(n**c - n)
    expr = expr.subs({c: c + 1})
    assert limit(expr, n, oo) == Limit(expr, n, oo)
コード例 #11
0
def test_basic5():
    class my(Function):
        @classmethod
        def eval(cls, arg):
            if arg is S.Infinity:
                return S.NaN

    assert limit(my(x), x, oo) == Limit(my(x), x, oo)
コード例 #12
0
ファイル: test_limits.py プロジェクト: goretkin/diofant
def test_basic5():
    class my(Function):
        @classmethod
        def eval(cls, arg):
            if arg is S.Infinity:
                return S.NaN
    assert limit(my(x), x, oo) == Limit(my(x), x, oo)

    assert limit(4/x > 8, x, 0)  # relational test
    assert limit(my(x) > 0, x, oo) == Limit(my(x) > 0, x, oo)

    # from https://groups.google.com/forum/#!topic/sympy/LkTMQKC_BOw
    # fix bisected to ade6d20 and c459d18
    a = Symbol('a', positive=True)
    f = exp(x*(-a - 1)) * sinh(x)
    assert limit(f, x, oo) == 0

    assert limit(O(x), x, x**2) == Limit(O(x), x, x**2)
コード例 #13
0
ファイル: test_bessel.py プロジェクト: skirpichev/diofant
def test_airybi():
    z = Symbol('z', extended_real=False)
    t = Symbol('t', negative=True)
    p = Symbol('p', positive=True)

    assert isinstance(airybi(z), airybi)

    assert airybi(0) == 3**Rational(5, 6)/(3*gamma(Rational(2, 3)))
    assert airybi(oo) == oo
    assert airybi(-oo) == 0

    assert diff(airybi(z), z) == airybiprime(z)

    assert series(airybi(z), z, 0, 3) == (
        cbrt(3)*gamma(Rational(1, 3))/(2*pi) + 3**Rational(2, 3)*z*gamma(Rational(2, 3))/(2*pi) + O(z**3))
    l = Limit(airybi(I/x)/(exp(Rational(2, 3)*(I/x)**Rational(3, 2))*sqrt(pi*sqrt(I/x))), x, 0)
    assert l.doit() == l

    assert airybi(z).rewrite(hyper) == (
        root(3, 6)*z*hyper((), (Rational(4, 3),), z**3/9)/gamma(Rational(1, 3)) +
        3**Rational(5, 6)*hyper((), (Rational(2, 3),), z**3/9)/(3*gamma(Rational(2, 3))))

    assert isinstance(airybi(z).rewrite(besselj), airybi)
    assert (airybi(t).rewrite(besselj) ==
            sqrt(3)*sqrt(-t)*(besselj(-1/3, 2*(-t)**Rational(3, 2)/3) -
                              besselj(Rational(1, 3),
                                      2*(-t)**Rational(3, 2)/3))/3)
    assert airybi(z).rewrite(besseli) == (
        sqrt(3)*(z*besseli(Rational(1, 3), 2*z**Rational(3, 2)/3)/cbrt(z**Rational(3, 2)) +
                 cbrt(z**Rational(3, 2))*besseli(-Rational(1, 3), 2*z**Rational(3, 2)/3))/3)
    assert airybi(p).rewrite(besseli) == (
        sqrt(3)*sqrt(p)*(besseli(-Rational(1, 3), 2*p**Rational(3, 2)/3) +
                         besseli(Rational(1, 3), 2*p**Rational(3, 2)/3))/3)
    assert airybi(p).rewrite(besselj) == airybi(p)

    assert expand_func(airybi(2*cbrt(3*z**5))) == (
        sqrt(3)*(1 - cbrt(z**5)/z**Rational(5, 3))*airyai(2*cbrt(3)*z**Rational(5, 3))/2 +
        (1 + cbrt(z**5)/z**Rational(5, 3))*airybi(2*cbrt(3)*z**Rational(5, 3))/2)
    assert expand_func(airybi(x*y)) == airybi(x*y)
    assert expand_func(airybi(log(x))) == airybi(log(x))
    assert expand_func(airybi(2*root(3*z**5, 5))) == airybi(2*root(3*z**5, 5))

    assert airybi(x).taylor_term(-1, x) == 0
コード例 #14
0
def test_basic4():
    assert limit(2*x + y*x, x, 0) == 0
    assert limit(2*x + y*x, x, 1) == 2 + y
    assert limit(2*x**8 + y*x**(-3), x, -2) == 512 - y/8
    assert limit(sqrt(x + 1) - sqrt(x), x, oo) == 0
    assert integrate(1/(x**3 + 1), (x, 0, oo)) == 2*pi*sqrt(3)/9

    # coverage test
    assert limit(Piecewise((x, x > 1), (0, True)), x, -1) == 0

    # issue sympy/sympy#16714
    e = ((n**(n + 1) + (n + 1)**n)/n**(n + 1))**n
    assert limit(e, n, oo) == E**E

    # issue sympy/sympy#18492
    e1 = 2*sqrt(x)*Piecewise(((4*x - 2)/abs(sqrt(4 - 4*(2*x - 1)**2)),
                              4*x - 2 >= 0),
                             ((2 - 4*x)/abs(sqrt(4 - 4*(2*x - 1)**2)), True))
    e2 = Piecewise((x**2/2, x <= Rational(1, 2)), (x/2 - Rational(1, 8), True))
    e3 = Piecewise(((x - 9)/5, x < -1), ((x - 9)/5, x > 4),
                   (sqrt(abs(x - 3)), True))
    assert limit(e1, x, 0) == 1
    assert limit(e2, x, 0) == 0
    assert limit(e2, x, oo) == oo
    assert limit(e3, x, -1) == 2
    assert limit(e3, x, oo) == oo

    e4 = Piecewise((1, 0 < x), (0, True))

    assert limit(e4, x, 0, 1) == 0
    assert limit(e4, x, 0) == 1
    pytest.raises(PoleError, lambda: limit(e4, x, 0, Reals))

    e5 = Piecewise((1, 0 < x), (2, 1 < x), (0, True))

    assert limit(e5, x, oo) == 1
    assert limit(e5, x, 1, 1) == 1
    assert limit(e5, x, 1) == 1

    e6 = Limit(Piecewise((1, x > a), (0, True)), x, 0)
    assert e6.doit() == e6
コード例 #15
0
def test_basic5():
    class MyFunction(Function):
        @classmethod
        def eval(cls, arg):
            if arg is oo:
                return nan
    assert limit(MyFunction(x), x, oo) == Limit(MyFunction(x), x, oo)

    assert limit(4/x > 8, x, 0) is true  # relational test
    assert limit(MyFunction(x) > 0, x, oo) == Limit(MyFunction(x) > 0, x, oo)

    # issue diofant/diofant#1217
    assert limit(x > 0, x, 0) is true
    assert limit(x > 0, x, 0, 1) is false

    # issue sympy/sympy#11833
    a = Symbol('a', positive=True)
    f = exp(x*(-a - 1)) * sinh(x)
    assert limit(f, x, oo) == 0

    assert limit(O(x), x, x**2) == Limit(O(x), x, x**2)
コード例 #16
0
def test__eis():
    assert _eis(z).diff(z) == -_eis(z) + 1/z
    pytest.raises(ArgumentIndexError, lambda: _eis(x).fdiff(2))

    assert _eis(1/z).series(z) == \
        z + z**2 + 2*z**3 + 6*z**4 + 24*z**5 + O(z**6)

    assert Ei(z).rewrite('tractable') == exp(z)*_eis(z)
    assert li(z).rewrite('tractable') == z*_eis(log(z))

    assert _eis(z).rewrite('intractable') == exp(-z)*Ei(z)

    assert expand(li(z).rewrite('tractable').diff(z).rewrite('intractable')) \
        == li(z).diff(z)

    assert expand(Ei(z).rewrite('tractable').diff(z).rewrite('intractable')) \
        == Ei(z).diff(z)

    assert _eis(z).series(z, n=2) == EulerGamma + log(z) + z*(-log(z) -
                                                              EulerGamma + 1) + z**2*(log(z)/2 - Rational(3, 4) + EulerGamma/2) + O(z**2)

    l = Limit(Ei(y/x)/exp(y/x), x, 0)
    assert l.doit() == l  # cover _eis._eval_aseries
コード例 #17
0
def test_sympyissue_15673():
    p = symbols('p')
    alpha = symbols('α', positive=True)

    e = Limit(4*pi*p**(-alpha)*(p**3 - p**alpha)/(alpha - 3), p, 0)
    assert isinstance(e.doit(), Limit)  # but see diofant/diofant#425
コード例 #18
0
def test_series():
    for c in (Limit, Limit(y, x, 1), Order, Order(y)):
        check(c)
コード例 #19
0
def test_sympyissue_7391():
    f = Function('f')
    func = x*y*y/(x*x + y**4)
    l = Limit(func.subs({y: f(x)}), x, 0)
    assert l.doit() == l
    assert l.subs({f: Lambda(x, sqrt(x))}).doit() == Rational(1, 2)
コード例 #20
0
ファイル: test_limits.py プロジェクト: goretkin/diofant
def test_doit2():
    f = Integral(2 * x, x)
    l = Limit(f, x, oo)
    # limit() breaks on the contained Integral.
    assert l.doit(deep=False) == l
コード例 #21
0
def test_basic1():
    assert limit(x, x, -oo) == -oo
    assert limit(x**2, x, -oo) == oo
    assert limit(x*log(x), x, 0) == 0
    assert limit(x - x**2, x, oo) == -oo
    assert limit((1 + x)**(1 + sqrt(2)), x, 0) == 1
    assert limit((1 + x)**oo, x, 0) == oo
    assert limit((1 + x)**oo, x, 0, dir=1) == 0
    assert limit((1 + x + y)**oo, x, 0, dir=1) == (1 + y)**oo
    assert limit(y/x/log(x), x, 0) == -oo*sign(y)
    assert limit(cos(x + y)/x, x, 0) == sign(cos(y))*oo
    limit(Sum(1/x, (x, 1, y)) - log(y), y, oo)
    limit(Sum(1/x, (x, 1, y)) - 1/y, y, oo)
    assert limit(nan, x, -oo) == nan
    assert limit(O(2)*x, x, nan) == nan
    assert limit(sin(O(x)), x, 0) == 0
    assert limit(1/(x - 1), x, 1) == oo
    assert limit(1/(x - 1), x, 1, dir=1) == -oo
    assert limit(1/(5 - x)**3, x, 5) == -oo
    assert limit(1/(5 - x)**3, x, 5, dir=1) == oo
    assert limit(1/sin(x), x, pi) == -oo
    assert limit(1/sin(x), x, pi, dir=1) == oo
    assert limit(1/cos(x), x, pi/2) == -oo
    assert limit(1/cos(x), x, pi/2, dir=1) == oo
    assert limit(1/tan(x**3), x, cbrt(2*pi)) == oo
    assert limit(1/tan(x**3), x, cbrt(2*pi), dir=1) == -oo
    assert limit(1/cot(x)**3, x, 3*pi/2) == -oo
    assert limit(1/cot(x)**3, x, 3*pi/2, dir=1) == oo

    # approaching 0
    # from dir=-1
    assert limit(1 + 1/x, x, 0) == oo
    # from dir=1
    # Add
    assert limit(1 + 1/x, x, 0, dir=1) == -oo
    # Pow
    assert limit(x**(-2), x, 0, dir=1) == oo
    assert limit(x**(-3), x, 0, dir=1) == -oo
    assert limit(1/sqrt(x), x, 0, dir=1) == (-oo)*I
    assert limit(x**2, x, 0, dir=1) == 0
    assert limit(sqrt(x), x, 0, dir=1) == 0
    assert limit(x**-pi, x, 0, dir=1) == oo*sign((-1)**(-pi))
    assert limit((1 + cos(x))**oo, x, 0) == oo

    assert limit(x**2, x, 0, dir=Reals) == 0
    assert limit(exp(x), x, 0, dir=Reals) == 1

    pytest.raises(PoleError, lambda: limit(1/x, x, 0, dir=Reals))

    # issue diofant/diofant#74
    assert limit(sign(log(1 - 1/x)), x, oo) == -1

    # issue sympy/sympy#8166
    f = Function('f')
    assert limit(f(x), x, 4) == Limit(f(x), x, 4)

    assert limit(exp(x), x, 0, dir=exp(I*pi/3)) == 1

    assert limit(sqrt(-1 + I*x), x, 0) == +I
    assert limit(sqrt(-1 + I*x), x, 0, dir=1) == -I
    assert limit(sqrt(-1 + I*x), x, 0, dir=exp(I*pi/3)) == -I

    assert limit(log(x + sqrt(x**2 + 1)), x, I) == I*pi/2
    assert limit(log(x + sqrt(x**2 + 1)), x, I, dir=1) == I*pi/2
    assert limit(log(x + sqrt(x**2 + 1)), x, I, dir=exp(I*pi/3)) == I*pi/2
コード例 #22
0
def test_erf():
    assert erf(nan) == nan

    assert erf(oo) == 1
    assert erf(-oo) == -1

    assert erf(0) == 0

    assert erf(I*oo) == oo*I
    assert erf(-I*oo) == -oo*I

    assert erf(-2) == -erf(2)
    assert erf(-x*y) == -erf(x*y)
    assert erf(-x - y) == -erf(x + y)

    assert erf(erfinv(x)) == x
    assert erf(erfcinv(x)) == 1 - x
    assert erf(erf2inv(0, x)) == x
    assert erf(erf2inv(0, erf(erfcinv(1 - erf(erfinv(x)))))) == x

    assert erf(I).is_extended_real is False
    assert erf(w).is_extended_real is True
    assert erf(z).is_extended_real is None

    assert conjugate(erf(z)) == erf(conjugate(z))

    assert erf(x).as_leading_term(x) == 2*x/sqrt(pi)
    assert erf(1/x).as_leading_term(x) == erf(1/x)

    assert erf(z).rewrite('uppergamma') == sqrt(z**2)*erf(sqrt(z**2))/z
    assert erf(z).rewrite('erfc') == 1 - erfc(z)
    assert erf(z).rewrite('erfi') == -I*erfi(I*z)
    assert erf(z).rewrite('fresnels') == (1 + I)*(fresnelc(z*(1 - I)/sqrt(pi)) -
                                                  I*fresnels(z*(1 - I)/sqrt(pi)))
    assert erf(z).rewrite('fresnelc') == (1 + I)*(fresnelc(z*(1 - I)/sqrt(pi)) -
                                                  I*fresnels(z*(1 - I)/sqrt(pi)))
    assert erf(z).rewrite('hyper') == 2*z*hyper([Rational(1, 2)], [Rational(3, 2)], -z**2)/sqrt(pi)
    assert erf(z).rewrite('meijerg') == z*meijerg([Rational(1, 2)], [], [0], [Rational(-1, 2)], z**2)/sqrt(pi)
    assert erf(z).rewrite('expint') == sqrt(z**2)/z - z*expint(Rational(1, 2), z**2)/sqrt(pi)

    assert limit(exp(x)*exp(x**2)*(erf(x + 1/exp(x)) - erf(x)), x, oo) == \
        2/sqrt(pi)
    assert limit((1 - erf(z))*exp(z**2)*z, z, oo) == 1/sqrt(pi)
    assert limit((1 - erf(x))*exp(x**2)*sqrt(pi)*x, x, oo) == 1
    assert limit(((1 - erf(x))*exp(x**2)*sqrt(pi)*x - 1)*2*x**2, x, oo) == -1

    l = Limit((1 - erf(y/x))*exp(y**2/x**2), x, 0)
    assert l.doit() == l  # cover _erfs._eval_aseries

    assert erf(x).as_real_imag() == \
        ((erf(re(x) - I*re(x)*Abs(im(x))/Abs(re(x)))/2 +
          erf(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))/2,
          I*(erf(re(x) - I*re(x)*Abs(im(x))/Abs(re(x))) -
             erf(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))) *
          re(x)*Abs(im(x))/(2*im(x)*Abs(re(x)))))
    assert erf(x).as_real_imag() == erf(x).as_real_imag(deep=False)
    assert erf(w).as_real_imag() == (erf(w), 0)
    assert erf(w).as_real_imag() == erf(w).as_real_imag(deep=False)
    assert erf(I).as_real_imag() == (0, erfi(1))

    pytest.raises(ArgumentIndexError, lambda: erf(x).fdiff(2))

    assert erf(x).taylor_term(3, x, *(2*x/sqrt(pi), 0)) == -2*x**3/3/sqrt(pi)
コード例 #23
0
ファイル: test_limits.py プロジェクト: skirpichev/diofant
def test_doit2():
    f = Integral(2 * x, x)
    l = Limit(f, x, oo)
    # limit() breaks on the contained Integral.
    assert l.doit(deep=False) == l
コード例 #24
0
ファイル: test_limits.py プロジェクト: skirpichev/diofant
def test_doit():
    f = Integral(2 * x, x)
    l = Limit(f, x, oo)
    assert l.doit() == oo
コード例 #25
0
ファイル: test_limits.py プロジェクト: goretkin/diofant
def test_Limit():
    assert Limit(sin(x)/x, x, 0) != 1
    assert Limit(sin(x)/x, x, 0).doit() == 1
コード例 #26
0
ファイル: test_limits.py プロジェクト: goretkin/diofant
def test_doit():
    f = Integral(2 * x, x)
    l = Limit(f, x, oo)
    assert l.doit() == oo
コード例 #27
0
ファイル: test_limits.py プロジェクト: goretkin/diofant
def test_sympyissue_9205():
    assert Limit(x, x, a).free_symbols == {a}
    assert Limit(x, x, a, '-').free_symbols == {a}
    assert Limit(x + y, x + y, a).free_symbols == {a}
    assert Limit(-x**2 + y, x**2, a).free_symbols == {y, a}
コード例 #28
0
ファイル: test_limits.py プロジェクト: goretkin/diofant
def test_Limit_dir():
    pytest.raises(TypeError, lambda: Limit(x, x, 0, dir=0))
    pytest.raises(ValueError, lambda: Limit(x, x, 0, dir='0'))
コード例 #29
0
def test_issue_1164():
    # also sympy/sympy#14502
    assert limit(factorial(x) - x**x, x, oo) == -oo
    l = Limit(factorial(x) - x**oo, x, oo)
    assert l.doit() == l
コード例 #30
0
def test_erf():
    assert erf(nan) == nan

    assert erf(oo) == 1
    assert erf(-oo) == -1

    assert erf(0) == 0

    assert erf(I * oo) == oo * I
    assert erf(-I * oo) == -oo * I

    assert erf(-2) == -erf(2)
    assert erf(-x * y) == -erf(x * y)
    assert erf(-x - y) == -erf(x + y)

    assert erf(erfinv(x)) == x
    assert erf(erfcinv(x)) == 1 - x
    assert erf(erf2inv(0, x)) == x
    assert erf(erf2inv(0, erf(erfcinv(1 - erf(erfinv(x)))))) == x

    assert erf(I).is_extended_real is False
    assert erf(w).is_extended_real is True
    assert erf(z).is_extended_real is None

    assert conjugate(erf(z)) == erf(conjugate(z))

    assert erf(x).as_leading_term(x) == 2 * x / sqrt(pi)
    assert erf(1 / x).as_leading_term(x) == erf(1 / x)

    assert erf(z).rewrite('uppergamma') == sqrt(z**2) * erf(sqrt(z**2)) / z
    assert erf(z).rewrite('erfc') == 1 - erfc(z)
    assert erf(z).rewrite('erfi') == -I * erfi(I * z)
    assert erf(z).rewrite('fresnels') == (1 + I) * (
        fresnelc(z * (1 - I) / sqrt(pi)) - I * fresnels(z *
                                                        (1 - I) / sqrt(pi)))
    assert erf(z).rewrite('fresnelc') == (1 + I) * (
        fresnelc(z * (1 - I) / sqrt(pi)) - I * fresnels(z *
                                                        (1 - I) / sqrt(pi)))
    assert erf(z).rewrite('hyper') == 2 * z * hyper(
        [Rational(1, 2)], [Rational(3, 2)], -z**2) / sqrt(pi)
    assert erf(z).rewrite('meijerg') == z * meijerg(
        [Rational(1, 2)], [], [0], [Rational(-1, 2)], z**2) / sqrt(pi)
    assert erf(z).rewrite('expint') == sqrt(z**2) / z - z * expint(
        Rational(1, 2), z**2) / sqrt(pi)

    assert limit(exp(x)*exp(x**2)*(erf(x + 1/exp(x)) - erf(x)), x, oo) == \
        2/sqrt(pi)
    assert limit((1 - erf(z)) * exp(z**2) * z, z, oo) == 1 / sqrt(pi)
    assert limit((1 - erf(x)) * exp(x**2) * sqrt(pi) * x, x, oo) == 1
    assert limit(((1 - erf(x)) * exp(x**2) * sqrt(pi) * x - 1) * 2 * x**2, x,
                 oo) == -1

    l = Limit((1 - erf(y / x)) * exp(y**2 / x**2), x, 0)
    assert l.doit() == l  # cover _erfs._eval_aseries

    assert erf(x).as_real_imag() == \
        ((erf(re(x) - I*re(x)*abs(im(x))/abs(re(x)))/2 +
          erf(re(x) + I*re(x)*abs(im(x))/abs(re(x)))/2,
          I*(erf(re(x) - I*re(x)*abs(im(x))/abs(re(x))) -
             erf(re(x) + I*re(x)*abs(im(x))/abs(re(x)))) *
          re(x)*abs(im(x))/(2*im(x)*abs(re(x)))))
    assert erf(x).as_real_imag() == erf(x).as_real_imag(deep=False)
    assert erf(w).as_real_imag() == (erf(w), 0)
    assert erf(w).as_real_imag() == erf(w).as_real_imag(deep=False)
    assert erf(I).as_real_imag() == (0, erfi(1))

    pytest.raises(ArgumentIndexError, lambda: erf(x).fdiff(2))

    assert erf(x).taylor_term(3, x, *(2 * x / sqrt(pi),
                                      0)) == -2 * x**3 / 3 / sqrt(pi)
コード例 #31
0
def test_Limit_free_symbols():
    # issue sympy/sympy#9205
    assert Limit(x, x, a).free_symbols == {a}
    assert Limit(x, x, a, 1).free_symbols == {a}
    assert Limit(x + y, x + y, a).free_symbols == {a}
    assert Limit(-x**2 + y, x**2, a).free_symbols == {y, a}
コード例 #32
0
ファイル: test_str.py プロジェクト: goretkin/diofant
def test_Limit():
    assert str(Limit(sin(x) / x, x, y)) == "Limit(sin(x)/x, x, y)"
    assert str(Limit(1 / x, x, 0)) == "Limit(1/x, x, 0)"
    assert str(Limit(sin(x) / x, x, y,
                     dir="-")) == "Limit(sin(x)/x, x, y, dir='-')"
コード例 #33
0
def test_Limit():
    assert str(Limit(sin(x) / x, x, y)) == 'Limit(sin(x)/x, x, y)'
    assert str(Limit(1 / x, x, 0)) == 'Limit(1/x, x, 0)'
    assert str(Limit(sin(x) / x, x, y,
                     dir='-')) == "Limit(sin(x)/x, x, y, dir='-')"