def test_simpleDE():
    # Tests just the first valid DE
    for DE in simpleDE(exp(x), x, f):
        assert DE == (-f(x) + Derivative(f(x), x), 1)
        break
    for DE in simpleDE(sin(x), x, f):
        assert DE == (f(x) + Derivative(f(x), x, x), 2)
        break
    for DE in simpleDE(log(1 + x), x, f):
        assert DE == ((x + 1) * Derivative(f(x), x, 2) + Derivative(f(x), x),
                      2)
        break
    for DE in simpleDE(asin(x), x, f):
        assert DE == (x * Derivative(f(x), x) +
                      (x**2 - 1) * Derivative(f(x), x, x), 2)
        break
    for DE in simpleDE(exp(x) * sin(x), x, f):
        assert DE == (2 * f(x) - 2 * Derivative(f(x)) + Derivative(f(x), x, x),
                      2)
        break
    for DE in simpleDE(((1 + x) / (1 - x))**n, x, f):
        assert DE == (2 * n * f(x) + (x**2 - 1) * Derivative(f(x), x), 1)
        break
    for DE in simpleDE(airyai(x), x, f):
        assert DE == (-x * f(x) + Derivative(f(x), x, x), 2)
        break
Пример #2
0
def test_fps__hyper():
    f = sin(x)
    assert fps(f, x).truncate() == x - x ** 3 / 6 + x ** 5 / 120 + O(x ** 6)

    f = cos(x)
    assert fps(f, x).truncate() == 1 - x ** 2 / 2 + x ** 4 / 24 + O(x ** 6)

    f = exp(x)
    assert fps(f, x).truncate() == 1 + x + x ** 2 / 2 + x ** 3 / 6 + x ** 4 / 24 + x ** 5 / 120 + O(x ** 6)

    f = atan(x)
    assert fps(f, x).truncate() == x - x ** 3 / 3 + x ** 5 / 5 + O(x ** 6)

    f = exp(acos(x))
    assert fps(f, x).truncate() == (
        exp(pi / 2)
        - x * exp(pi / 2)
        + x ** 2 * exp(pi / 2) / 2
        - x ** 3 * exp(pi / 2) / 3
        + 5 * x ** 4 * exp(pi / 2) / 24
        - x ** 5 * exp(pi / 2) / 6
        + O(x ** 6)
    )

    f = exp(acosh(x))
    assert fps(f, x).truncate() == I + x - I * x ** 2 / 2 - I * x ** 4 / 8 + O(x ** 6)

    f = atan(1 / x)
    assert fps(f, x).truncate() == pi / 2 - x + x ** 3 / 3 - x ** 5 / 5 + O(x ** 6)

    f = x * atan(x) - log(1 + x ** 2) / 2
    assert fps(f, x, rational=False).truncate() == x ** 2 / 2 - x ** 4 / 12 + O(x ** 6)

    f = log(1 + x)
    assert fps(f, x, rational=False).truncate() == x - x ** 2 / 2 + x ** 3 / 3 - x ** 4 / 4 + x ** 5 / 5 + O(x ** 6)

    f = airyai(x ** 2)
    assert fps(f, x).truncate() == (
        3 ** Rational(5, 6) * gamma(Rational(1, 3)) / (6 * pi)
        - 3 ** Rational(2, 3) * x ** 2 / (3 * gamma(Rational(1, 3)))
        + O(x ** 6)
    )

    f = exp(x) * sin(x)
    assert fps(f, x).truncate() == x + x ** 2 + x ** 3 / 3 - x ** 5 / 30 + O(x ** 6)

    f = exp(x) * sin(x) / x
    assert fps(f, x).truncate() == 1 + x + x ** 2 / 3 - x ** 4 / 30 - x ** 5 / 90 + O(x ** 6)

    f = sin(x) * cos(x)
    assert fps(f, x).truncate() == x - 2 * x ** 3 / 3 + 2 * x ** 5 / 15 + O(x ** 6)
Пример #3
0
def test_fps__hyper():
    f = sin(x)
    assert fps(f, x).truncate() == x - x**3 / 6 + x**5 / 120 + O(x**6)

    f = cos(x)
    assert fps(f, x).truncate() == 1 - x**2 / 2 + x**4 / 24 + O(x**6)

    f = exp(x)
    assert fps(f, x).truncate(
    ) == 1 + x + x**2 / 2 + x**3 / 6 + x**4 / 24 + x**5 / 120 + O(x**6)

    f = atan(x)
    assert fps(f, x).truncate() == x - x**3 / 3 + x**5 / 5 + O(x**6)

    f = exp(acos(x))
    assert fps(
        f, x).truncate() == (exp(pi / 2) - x * exp(pi / 2) +
                             x**2 * exp(pi / 2) / 2 - x**3 * exp(pi / 2) / 3 +
                             5 * x**4 * exp(pi / 2) / 24 -
                             x**5 * exp(pi / 2) / 6 + O(x**6))

    f = exp(acosh(x))
    assert fps(f,
               x).truncate() == I + x - I * x**2 / 2 - I * x**4 / 8 + O(x**6)

    f = atan(1 / x)
    assert fps(f, x).truncate() == pi / 2 - x + x**3 / 3 - x**5 / 5 + O(x**6)

    f = x * atan(x) - log(1 + x**2) / 2
    assert fps(f, x,
               rational=False).truncate() == x**2 / 2 - x**4 / 12 + O(x**6)

    f = log(1 + x)
    assert fps(f, x, rational=False).truncate(
    ) == x - x**2 / 2 + x**3 / 3 - x**4 / 4 + x**5 / 5 + O(x**6)

    f = airyai(x**2)
    assert fps(f, x).truncate() == (3**Rational(5, 6) * gamma(Rational(1, 3)) /
                                    (6 * pi) - 3**Rational(2, 3) * x**2 /
                                    (3 * gamma(Rational(1, 3))) + O(x**6))

    f = exp(x) * sin(x)
    assert fps(f, x).truncate() == x + x**2 + x**3 / 3 - x**5 / 30 + O(x**6)

    f = exp(x) * sin(x) / x
    assert fps(
        f, x).truncate() == 1 + x + x**2 / 3 - x**4 / 30 - x**5 / 90 + O(x**6)

    f = sin(x) * cos(x)
    assert fps(f, x).truncate() == x - 2 * x**3 / 3 + 2 * x**5 / 15 + O(x**6)
Пример #4
0
def test_airy():
    from sympy import airyai, airybi

    expr1 = airyai(x)
    expr2 = airybi(x)

    prntr = SciPyPrinter()
    assert prntr.doprint(expr1) == 'scipy.special.airy(x)[0]'
    assert prntr.doprint(expr2) == 'scipy.special.airy(x)[2]'

    prntr = NumPyPrinter()
    assert prntr.doprint(expr1) == '  # Not supported in Python with NumPy:\n  # airyai\nairyai(x)'
    assert prntr.doprint(expr2) == '  # Not supported in Python with NumPy:\n  # airybi\nairybi(x)'

    prntr = PythonCodePrinter()
    assert prntr.doprint(expr1) == '  # Not supported in Python:\n  # airyai\nairyai(x)'
    assert prntr.doprint(expr2) == '  # Not supported in Python:\n  # airybi\nairybi(x)'
Пример #5
0
def test_airy():
    from sympy import airyai, airybi

    expr1 = airyai(x)
    expr2 = airybi(x)

    prntr = SciPyPrinter()
    assert prntr.doprint(expr1) == 'scipy.special.airy(x)[0]'
    assert prntr.doprint(expr2) == 'scipy.special.airy(x)[2]'

    prntr = NumPyPrinter()
    assert "Not supported" in prntr.doprint(expr1)
    assert "Not supported" in prntr.doprint(expr2)

    prntr = PythonCodePrinter()
    assert "Not supported" in prntr.doprint(expr1)
    assert "Not supported" in prntr.doprint(expr2)
Пример #6
0
def test_simpleDE():
    # Tests just the first valid DE
    for DE in simpleDE(exp(x), x, f):
        assert DE == (-f(x) + Derivative(f(x), x), 1)
        break
    for DE in simpleDE(sin(x), x, f):
        assert DE == (f(x) + Derivative(f(x), x, x), 2)
        break
    for DE in simpleDE(log(1 + x), x, f):
        assert DE == ((x + 1) * Derivative(f(x), x, 2) + Derivative(f(x), x), 2)
        break
    for DE in simpleDE(asin(x), x, f):
        assert DE == (x * Derivative(f(x), x) + (x ** 2 - 1) * Derivative(f(x), x, x), 2)
        break
    for DE in simpleDE(exp(x) * sin(x), x, f):
        assert DE == (2 * f(x) - 2 * Derivative(f(x)) + Derivative(f(x), x, x), 2)
        break
    for DE in simpleDE(((1 + x) / (1 - x)) ** n, x, f):
        assert DE == (2 * n * f(x) + (x ** 2 - 1) * Derivative(f(x), x), 1)
        break
    for DE in simpleDE(airyai(x), x, f):
        assert DE == (-x * f(x) + Derivative(f(x), x, x), 2)
        break