Пример #1
0
def test_diff():
    x, y = symbols('x, y')
    assert Rational(1, 3).diff(x) is S.Zero
    assert I.diff(x) is S.Zero
    assert pi.diff(x) is S.Zero
    assert x.diff(x, 0) == x
    assert (x**2).diff(x, 2, x) == 0
    assert (x**2).diff(x, y, 0) == 2 * x
    assert (x**2).diff(x, y) == 0
    pytest.raises(ValueError, lambda: x.diff(1, x))

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    p = Rational(5)
    e = a * b + b**p
    assert e.diff(a) == b
    assert e.diff(b) == a + 5 * b**4
    assert e.diff(b).diff(a) == Rational(1)
    e = a * (b + c)
    assert e.diff(a) == b + c
    assert e.diff(b) == a
    assert e.diff(b).diff(a) == Rational(1)
    e = c**p
    assert e.diff(c, 6) == Rational(0)
    assert e.diff(c, 5) == Rational(120)
    e = c**Rational(2)
    assert e.diff(c) == 2 * c
    e = a * b * c
    assert e.diff(c) == a * b
Пример #2
0
def test_diff():
    x, y = symbols('x, y')
    assert Rational(1, 3).diff(x) is Integer(0)
    assert I.diff(x) is Integer(0)
    assert pi.diff(x) is Integer(0)
    assert x.diff(x, 0) == x
    assert (x**2).diff(x, 2, x) == 0
    assert (x**2).diff(x, y, 0) == 2*x
    assert (x**2).diff(x, y) == 0
    pytest.raises(ValueError, lambda: x.diff(1, x))

    a = Symbol('a')
    b = Symbol('b')
    c = Symbol('c')
    p = Integer(5)
    e = a*b + b**p
    assert e.diff(a) == b
    assert e.diff(b) == a + 5*b**4
    assert e.diff(b).diff(a) == 1
    e = a*(b + c)
    assert e.diff(a) == b + c
    assert e.diff(b) == a
    assert e.diff(b).diff(a) == 1
    e = c**p
    assert e.diff(c, 6) == 0
    assert e.diff(c, 5) == 120
    e = c**2
    assert e.diff(c) == 2*c
    e = a*b*c
    assert e.diff(c) == a*b

    f = Function('f')
    assert f(x).diff(x, 2).diff(f(x).diff(x, 1)) == 0
Пример #3
0
def test_diff():
    assert Rational(1, 3).diff(x) is Integer(0)
    assert I.diff(x) is Integer(0)
    assert pi.diff(x) is Integer(0)
    assert x.diff((x, 0)) == x
    assert (x**2).diff((x, 2), x) == 0
    assert (x**2).diff(x, (y, 0)) == 2*x
    assert (x**2).diff(x, y) == 0
    pytest.raises(ValueError, lambda: x.diff((1, x)))

    p = Integer(5)
    e = a*b + b**p
    assert e.diff(a) == b
    assert e.diff(b) == a + 5*b**4
    assert e.diff(b).diff(a) == 1
    e = a*(b + c)
    assert e.diff(a) == b + c
    assert e.diff(b) == a
    assert e.diff(b).diff(a) == 1
    e = c**p
    assert e.diff((c, 6)) == 0
    assert e.diff((c, 5)) == 120
    e = c**2
    assert e.diff(c) == 2*c
    e = a*b*c
    assert e.diff(c) == a*b

    f = Function('f')
    assert f(x).diff((x, 2)).diff(f(x).diff((x, 1))) == 0
Пример #4
0
def test_diff():
    x, y = symbols('x, y')
    assert Rational(1, 3).diff(x) is Integer(0)
    assert I.diff(x) is Integer(0)
    assert pi.diff(x) is Integer(0)
    assert x.diff(x, 0) == x
    assert (x**2).diff(x, 2, x) == 0
    assert (x**2).diff(x, y, 0) == 2*x
    assert (x**2).diff(x, y) == 0
    pytest.raises(ValueError, lambda: x.diff(1, x))

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    p = Integer(5)
    e = a*b + b**p
    assert e.diff(a) == b
    assert e.diff(b) == a + 5*b**4
    assert e.diff(b).diff(a) == 1
    e = a*(b + c)
    assert e.diff(a) == b + c
    assert e.diff(b) == a
    assert e.diff(b).diff(a) == 1
    e = c**p
    assert e.diff(c, 6) == 0
    assert e.diff(c, 5) == 120
    e = c**2
    assert e.diff(c) == 2*c
    e = a*b*c
    assert e.diff(c) == a*b

    f = Function('f')
    assert f(x).diff(x, 2).diff(f(x).diff(x, 1)) == 0
Пример #5
0
def test_evalf_powers():
    assert NS('pi**(10**20)', 10) == '1.339148777e+49714987269413385435'
    assert NS(pi**(10**100), 10) == ('4.946362032e+4971498726941338543512682882'
                                     '9089887365167832438044244613405349992494711208'
                                     '95526746555473864642912223')
    assert NS('2**(1/10**50)', 15) == '1.00000000000000'
    assert NS('2**(1/10**50)-1', 15) == '6.93147180559945e-51'

    assert Pow(2, 0, evaluate=False).evalf() == 1
    assert Pow(I, 5, evaluate=False).evalf() == I.evalf()
Пример #6
0
def test_pow_as_base_exp():
    assert (oo**(2 - x)).as_base_exp() == (oo, 2 - x)
    assert (oo**(x - 2)).as_base_exp() == (oo, x - 2)
    p = Rational(1, 2)**x
    assert p.base, p.exp == p.as_base_exp() == (2, -x)
    # issue sympy/sympy#8344:
    assert Pow(1, 2, evaluate=False).as_base_exp() == (1, 2)
    # issue sympy/sympy#21396
    assert I.as_base_exp() == (-1, Rational(1, 2))
    assert sqrt(I).as_base_exp() == (-1, Rational(1, 4))
Пример #7
0
def test_evalf_powers():
    assert NS('pi**(10**20)', 10) == '1.339148777e+49714987269413385435'
    assert NS(pi**(10**100), 10) == ('4.946362032e+4971498726941338543512682882'
                                     '9089887365167832438044244613405349992494711208'
                                     '95526746555473864642912223')
    assert NS('2**(1/10**50)', 15) == '1.00000000000000'
    assert NS('2**(1/10**50)-1', 15) == '6.93147180559945e-51'

    assert Pow(2, 0, evaluate=False).evalf() == 1
    assert Pow(I, 5, evaluate=False).evalf() == I.evalf()
Пример #8
0
def test_sympyissue_5486_bug():
    assert abs(Expr._from_mpmath(I._to_mpmath(15), 15) - I) < 1.0e-15
    pytest.raises(TypeError, lambda: Expr._from_mpmath(I, 15))
Пример #9
0
def test_issue_5486_bug():
    from diofant import I, Expr
    assert abs(Expr._from_mpmath(I._to_mpmath(15), 15) - I) < 1.0e-15
    pytest.raises(TypeError, lambda: Expr._from_mpmath(I, 15))
Пример #10
0
def test_sympyissue_5486_bug():
    assert abs(Expr._from_mpmath(I._to_mpmath(15), 15) - I) < 1.0e-15
    pytest.raises(TypeError, lambda: Expr._from_mpmath(I, 15))
Пример #11
0
def test_sympyissue_5486():
    assert not cos(sqrt(0.5 + I)).evalf(strict=False).is_Function
    assert abs(Expr._from_mpmath(I._to_mpmath(15), 15) - I) < 1.0e-15
Пример #12
0
def test_sympyissue_5486_bug():
    assert abs(Expr._from_mpmath(I._to_mpmath(15), 15) - I) < 1.0e-15