Ejemplo n.º 1
0
def test_messy():
    assert laplace_transform(Si(x), x, s) == ((-atan(s) + pi/2)/s, 0, True)

    assert laplace_transform(Shi(x), x, s) == (acoth(s)/s, 1, True)

    # where should the logs be simplified?
    assert laplace_transform(Chi(x), x, s) == \
        ((log(s**(-2)) - log((s**2 - 1)/s**2))/(2*s), 1, True)

    # TODO maybe simplify the inequalities?
    assert laplace_transform(besselj(a, x), x, s)[1:] == \
        (0, And(Integer(0) < re(a/2) + Rational(1, 2), Integer(0) < re(a/2) + 1))

    # NOTE s < 0 can be done, but argument reduction is not good enough yet
    assert fourier_transform(besselj(1, x)/x, x, s, noconds=False) == \
        (Piecewise((0, 4*abs(pi**2*s**2) > 1),
                   (2*sqrt(-4*pi**2*s**2 + 1), True)), s > 0)
    # TODO FT(besselj(0,x)) - conditions are messy (but for acceptable reasons)
    #                       - folding could be better

    assert integrate(E1(x)*besselj(0, x), (x, 0, oo), meijerg=True) == \
        log(1 + sqrt(2))
    assert integrate(E1(x)*besselj(1, x), (x, 0, oo), meijerg=True) == \
        log(Rational(1, 2) + sqrt(2)/2)

    assert integrate(1/x/sqrt(1 - x**2), x, meijerg=True) == \
        Piecewise((-acosh(1/x), 1 < abs(x**(-2))), (I*asin(1/x), True))
Ejemplo n.º 2
0
 def E(expr):
     res1 = integrate(expr*exponential(x, rate)*normal(y, mu1, sigma1),
                      (x, 0, oo), (y, -oo, oo), meijerg=True)
     res2 = integrate(expr*exponential(x, rate)*normal(y, mu1, sigma1),
                      (y, -oo, oo), (x, 0, oo), meijerg=True)
     assert expand_mul(res1) == expand_mul(res2)
     return res1
Ejemplo n.º 3
0
def test_integrate_linearterm_pow():
    # check integrate((a*x+b)^c, x)  --  issue sympy/sympy#3499
    y = Symbol('y', positive=True)
    # TODO: Remove conds='none' below, let the assumption take care of it.
    assert integrate(x**y, x, conds='none') == x**(y + 1)/(y + 1)
    assert integrate((exp(y)*x + 1/y)**(1 + sin(y)), x, conds='none') == \
        exp(-y)*(exp(y)*x + 1/y)**(2 + sin(y)) / (2 + sin(y))
Ejemplo n.º 4
0
def test_branch_bug():
    # TODO combsimp cannot prove that the factor is unity
    assert powdenest(integrate(erf(x**3), x, meijerg=True).diff(x),
                     polar=True) == 2*erf(x**3)*gamma(Rational(2, 3))/3/gamma(Rational(5, 3))
    assert integrate(erf(x**3), x, meijerg=True) == \
        2*x*erf(x**3)*gamma(Rational(2, 3))/(3*gamma(Rational(5, 3))) \
        - 2*gamma(Rational(2, 3))*lowergamma(Rational(2, 3), x**6)/(3*sqrt(pi)*gamma(Rational(5, 3)))
Ejemplo n.º 5
0
def test_sympyissue_4199():
    ypos = Symbol('y', positive=True)
    # TODO: Remove conds='none' below, let the assumption take care of it.
    assert (integrate(exp(-I*2*pi*ypos*x)*x, (x, -oo, oo), conds='none') ==
            Integral(exp(-I*2*pi*ypos*x)*x, (x, -oo, oo)))
    assert (integrate(exp(-I*2*pi*ypos*x)*x, (x, 0, oo), conds='none') ==
            Integral(exp(-2*I*pi*x*ypos)*x, (x, 0, oo)))
Ejemplo n.º 6
0
def test_sympyissue_3623():
    assert integrate(cos((n + 1)*x), x) == Piecewise(
        (x, Eq(n + 1, 0)), (sin((n + 1)*x)/(n + 1), True))
    assert integrate(cos((n - 1)*x), x) == Piecewise(
        (x, Eq(n - 1, 0)), (sin((n - 1)*x)/(n - 1), True))
    assert integrate(cos((n + 1)*x) + cos((n - 1)*x), x) == \
        Piecewise((x, Eq(n + 1, 0)), (sin((n + 1)*x)/(n + 1), True)) + \
        Piecewise((x, Eq(n - 1, 0)), (sin((n - 1)*x)/(n - 1), True))
Ejemplo n.º 7
0
def test_integrate_series():
    f = sin(x).series(x, 0, 10)
    g = x**2/2 - x**4/24 + x**6/720 - x**8/40320 + \
        x**10/3628800 + Integral(O(x**10), x)

    assert integrate(f, x) == g

    assert integrate(O(x**5), x) == Integral(O(x**5), x)
Ejemplo n.º 8
0
def test_sympyissue_4890():
    z = Symbol('z', positive=True)
    assert integrate(exp(-log(x)**2), x) == \
        sqrt(pi)*exp(Rational(1, 4))*erf(log(x)-Rational(1, 2))/2
    assert integrate(exp(log(x)**2), x) == \
        sqrt(pi)*exp(-Rational(1, 4))*erfi(log(x)+Rational(1, 2))/2
    assert integrate(exp(-z*log(x)**2), x) == \
        sqrt(pi)*exp(1/(4*z))*erf(sqrt(z)*log(x) - 1/(2*sqrt(z)))/(2*sqrt(z))
Ejemplo n.º 9
0
def test_sympyissue_4884():
    assert integrate(sqrt(x)*(1 + x)) == \
        Piecewise(
            (2*sqrt(x)*(x + 1)**2/5 - 2*sqrt(x)*(x + 1)/15 - 4*sqrt(x)/15,
             Abs(x + 1) > 1),
            (2*I*sqrt(-x)*(x + 1)**2/5 - 2*I*sqrt(-x)*(x + 1)/15 -
             4*I*sqrt(-x)/15, True))
    assert integrate(x**x*(1 + log(x))) == x**x
Ejemplo n.º 10
0
def test_evalf_sympyissue_4038():
    # The output form of an integral may differ by a step function between
    # revisions, making this test a bit useless. This can't be said about
    # other two tests. For now, all values of this evaluation are used here,
    # but in future this should be reconsidered.
    assert NS(integrate(1/(x**5 + 1), x).subs({x: 4}), chop=True) in \
        ['-0.000976138910649103', '0.965906660135753', '1.93278945918216']

    assert NS(Integral(1/(x**5 + 1), (x, 2, 4))) == '0.0144361088886740'
    assert NS(
        integrate(1/(x**5 + 1), (x, 2, 4)), chop=True) == '0.0144361088886740'
Ejemplo n.º 11
0
def test_diff_wrt():
    class Test(Expr):
        _diff_wrt = True
        is_commutative = True

    t = Test()
    assert integrate(t + 1, t) == t**2/2 + t
    assert integrate(t + 1, (t, 0, 1)) == Rational(3, 2)

    pytest.raises(ValueError, lambda: integrate(x + 1, x + 1))
    pytest.raises(ValueError, lambda: integrate(x + 1, (x + 1, 0, 1)))
Ejemplo n.º 12
0
def test_sympyissue_4665():
    # Allow only upper or lower limit evaluation
    e = Integral(x**2, (x, None, 1))
    f = Integral(x**2, (x, 1, None))
    assert e.doit() == Rational(1, 3)
    assert f.doit() == Rational(-1, 3)
    assert Integral(x*y, (x, None, y)).subs({y: t}) == Integral(x*t, (x, None, t))
    assert Integral(x*y, (x, y, None)).subs({y: t}) == Integral(x*t, (x, t, None))
    assert integrate(x**2, (x, None, 1)) == Rational(1, 3)
    assert integrate(x**2, (x, 1, None)) == Rational(-1, 3)
    assert integrate("x**2", ("x", "1", None)) == Rational(-1, 3)
Ejemplo n.º 13
0
def test_sympyissue_2708():
    # This test needs to use an integration function that can
    # not be evaluated in closed form.  Update as needed.
    f = 1/(a + z + log(z))
    integral_f = NonElementaryIntegral(f, (z, 2, 3))
    assert Integral(f, (z, 2, 3)).doit() == integral_f
    assert integrate(f + exp(z), (z, 2, 3)) == integral_f - exp(2) + exp(3)

    assert integrate(2*f + exp(z), (z, 2, 3)) == 2*integral_f - exp(2) + exp(3)
    assert (integrate(exp(1.2*n*s*z*(-t + z)/t), (z, 0, x)) ==
            1.0*NonElementaryIntegral(exp(-1.2*n*s*z)*exp(1.2*n*s*z**2/t),
                                      (z, 0, x)))
Ejemplo n.º 14
0
def test_sympyissue_3940():
    a, b, c, d = symbols('a:d', positive=True, finite=True)
    assert integrate(exp(-x**2 + I*c*x), x) == \
        -sqrt(pi)*exp(-c**2/4)*erf(I*c/2 - x)/2
    assert integrate(exp(a*x**2 + b*x + c), x) == \
        sqrt(pi)*exp(c)*exp(-b**2/(4*a))*erfi(sqrt(a)*x + b/(2*sqrt(a)))/(2*sqrt(a))

    assert expand_mul(integrate(exp(-x**2)*exp(I*k*x), (x, -oo, oo))) == \
        sqrt(pi)*exp(-k**2/4)
    a, d = symbols('a d', positive=True)
    assert expand_mul(integrate(exp(-a*x**2 + 2*d*x), (x, -oo, oo))) == \
        sqrt(pi)*exp(d**2/a)/sqrt(a)
Ejemplo n.º 15
0
def test_sympyissue_4403():
    x = Symbol('x')
    z = Symbol('z', positive=True)
    assert integrate(sqrt(x**2 + z**2), x) == \
        z**2*asinh(x/z)/2 + x*sqrt(x**2 + z**2)/2
    assert integrate(sqrt(x**2 - z**2), x) == \
        -z**2*acosh(x/z)/2 + x*sqrt(x**2 - z**2)/2

    x = Symbol('x', extended_real=True)
    y = Symbol('y', nonzero=True, extended_real=True)
    assert integrate(1/(x**2 + y**2)**Rational(3, 2), x) == \
        1/(y**2*sqrt(1 + y**2/x**2))
Ejemplo n.º 16
0
def test_sympyissue_4527():
    k, m = symbols('k m', integer=True)
    assert integrate(sin(k*x)*sin(m*x), (x, 0, pi)) == Piecewise(
        (0, And(Eq(k, 0), Eq(m, 0))),
        (-pi/2, Eq(k, -m)),
        (pi/2, Eq(k, m)),
        (0, True))
    assert integrate(sin(k*x)*sin(m*x), (x,)) == Piecewise(
        (0, And(Eq(k, 0), Eq(m, 0))),
        (-x*sin(m*x)**2/2 - x*cos(m*x)**2/2 + sin(m*x)*cos(m*x)/(2*m), Eq(k, -m)),
        (x*sin(m*x)**2/2 + x*cos(m*x)**2/2 - sin(m*x)*cos(m*x)/(2*m), Eq(k, m)),
        (m*sin(k*x)*cos(m*x)/(k**2 - m**2) -
         k*sin(m*x)*cos(k*x)/(k**2 - m**2), True))
Ejemplo n.º 17
0
def test_integrate_poly():
    p = Poly(x + x**2*y + y**3, x, y)

    qx = integrate(p, x)
    qy = integrate(p, y)

    assert isinstance(qx, Poly) is True
    assert isinstance(qy, Poly) is True

    assert qx.gens == (x, y)
    assert qy.gens == (x, y)

    assert qx.as_expr() == x**2/2 + x**3*y/3 + x*y**3
    assert qy.as_expr() == x*y + x**2*y**2/2 + y**4/4
Ejemplo n.º 18
0
def test_integrate_poly_defined():
    p = Poly(x + x**2*y + y**3, x, y)

    Qx = integrate(p, (x, 0, 1))
    Qy = integrate(p, (y, 0, pi))

    assert isinstance(Qx, Poly) is True
    assert isinstance(Qy, Poly) is True

    assert Qx.gens == (y,)
    assert Qy.gens == (x,)

    assert Qx.as_expr() == Rational(1, 2) + y/3 + y**3
    assert Qy.as_expr() == pi**4/4 + pi*x + pi**2*x**2/2
Ejemplo n.º 19
0
def test_recursive():
    a, b, c = symbols('a b c', positive=True)
    r = exp(-(x - a)**2)*exp(-(x - b)**2)
    e = integrate(r, (x, 0, oo), meijerg=True)
    assert simplify(e.expand()) == (
        sqrt(2)*sqrt(pi)*(
            (erf(sqrt(2)*(a + b)/2) + 1)*exp(-a**2/2 + a*b - b**2/2))/4)
    e = integrate(exp(-(x - a)**2)*exp(-(x - b)**2)*exp(c*x), (x, 0, oo), meijerg=True)
    assert simplify(e) == (
        sqrt(2)*sqrt(pi)*(erf(sqrt(2)*(2*a + 2*b + c)/4) + 1)*exp(-a**2 - b**2
                                                                  + (2*a + 2*b + c)**2/8)/4)
    assert simplify(integrate(exp(-(x - a - b - c)**2), (x, 0, oo), meijerg=True)) == \
        sqrt(pi)/2*(1 + erf(a + b + c))
    assert simplify(integrate(exp(-(x + a + b + c)**2), (x, 0, oo), meijerg=True)) == \
        sqrt(pi)/2*(1 - erf(a + b + c))
Ejemplo n.º 20
0
def test_sympyissue_7383():
    x, z, R, a = symbols('x z R a')
    r = sqrt(x**2 + z**2)
    u = erf(a*r/sqrt(2))/r
    Ec = u.diff(z, z).subs({x: sqrt(R*R - z*z)})
    assert integrate(Ec, (z, -R, R)).simplify() == \
        -2*sqrt(2)*R*a**3*exp(-R**2*a**2/2)/(3*sqrt(pi))
Ejemplo n.º 21
0
def test_matrices():
    M = Matrix(2, 2, lambda i, j: (i + j + 1)*sin((i + j + 1)*x))

    assert integrate(M, x) == Matrix([
        [-cos(x), -cos(2*x)],
        [-cos(2*x), -cos(3*x)],
    ])
Ejemplo n.º 22
0
def test_piecewise_interval():
    p1 = Piecewise((x, Interval(0, 1).contains(x)), (0, True))
    assert p1.subs({x: -0.5}) == 0
    assert p1.subs({x: 0.5}) == 0.5
    assert p1.diff(x) == Piecewise((1, Interval(0, 1).contains(x)), (0, True))
    assert integrate(
        p1, x) == Piecewise((x**2/2, Interval(0, 1).contains(x)), (0, True))
Ejemplo n.º 23
0
def test_piecewise_fold():

    p = Piecewise((x, x < 1), (1, 1 <= x))

    assert piecewise_fold(x*p) == Piecewise((x**2, x < 1), (x, 1 <= x))
    assert piecewise_fold(p + p) == Piecewise((2*x, x < 1), (2, 1 <= x))
    assert piecewise_fold(Piecewise((1, x < 0), (2, True))
                          + Piecewise((10, x < 0), (-10, True))) == \
        Piecewise((11, x < 0), (-8, True))

    p1 = Piecewise((0, x < 0), (x, x <= 1), (0, True))
    p2 = Piecewise((0, x < 0), (1 - x, x <= 1), (0, True))

    p = 4*p1 + 2*p2
    assert integrate(
        piecewise_fold(p), (x, -oo, oo)) == integrate(2*x + 2, (x, 0, 1))
Ejemplo n.º 24
0
def test_sympyissue_6252():
    expr = 1/x/cbrt(a + b*x)
    anti = integrate(expr, x, meijerg=True)
    assert not expr.has(hyper)
    # XXX the expression is a mess, but actually upon differentiation and
    # putting in numerical values seems to work...
    assert not anti.has(hyper)
Ejemplo n.º 25
0
def test_sympyissue_8368():
    assert integrate(exp(-s*x)*cosh(x), (x, 0, oo)) == \
        Piecewise((pi*Piecewise((-s/(pi*(-s**2 + 1)), Abs(s**2) < 1),
                                (1/(pi*s*(1 - 1/s**2)), Abs(s**(-2)) < 1), (meijerg(((Rational(1, 2),), (0, 0)),
                                                                                    ((0, Rational(1, 2)), (0,)), polar_lift(s)**2), True)),
                   And(Abs(periodic_argument(polar_lift(s)**2, oo)) < pi, Ne(s**2, 1),
                       cos(Abs(periodic_argument(polar_lift(s)**2, oo))/2)*sqrt(Abs(s**2)) -
                       1 > 0)), (Integral(exp(-s*x)*cosh(x), (x, 0, oo)), True))
    assert integrate(exp(-s*x)*sinh(x), (x, 0, oo)) == \
        Piecewise((pi*Piecewise((2/(pi*(2*s**2 - 2)), Abs(s**2) < 1),
                                (-2/(pi*s**2*(-2 + 2/s**2)), Abs(s**(-2)) < 1),
                                (meijerg(((0,), (Rational(-1, 2), Rational(1, 2))),
                                         ((0, Rational(1, 2)), (Rational(-1, 2),)),
                                         polar_lift(s)**2), True)),
                   And(Abs(periodic_argument(polar_lift(s)**2, oo)) < pi, Ne(s**2, 1),
                       cos(Abs(periodic_argument(polar_lift(s)**2, oo))/2)*sqrt(Abs(s**2)) - 1 > 0)),
                  (Integral(E**(-s*x)*sinh(x), (x, 0, oo)), True))
Ejemplo n.º 26
0
def test_basics():
    assert Integral(0, x) != 0
    assert Integral(x, (x, 1, 1)) != 0
    assert Integral(oo, x) != oo
    assert Integral(nan, x) == nan

    assert diff(Integral(y, y), x) == 0
    assert diff(Integral(x, (x, 0, 1)), x) == 0
    assert diff(Integral(x, x), x) == x
    assert diff(Integral(t, (t, 0, x)), x) == x + Integral(0, (t, 0, x))

    e = (t + 1)**2
    assert diff(integrate(e, (t, 0, x)), x) == \
        diff(Integral(e, (t, 0, x)), x).doit().expand() == \
        ((1 + x)**2).expand()
    assert diff(integrate(e, (t, 0, x)), t) == \
        diff(Integral(e, (t, 0, x)), t) == 0
    assert diff(integrate(e, (t, 0, x)), a) == \
        diff(Integral(e, (t, 0, x)), a) == 0
    assert diff(integrate(e, t), a) == diff(Integral(e, t), a) == 0

    assert integrate(e, (t, a, x)).diff(x) == \
        Integral(e, (t, a, x)).diff(x).doit().expand()
    assert Integral(e, (t, a, x)).diff(x).doit() == ((1 + x)**2)
    assert integrate(e, (t, x, a)).diff(x).doit() == (-(1 + x)**2).expand()

    assert integrate(t**2, (t, x, 2*x)).diff(x) == 7*x**2

    assert Integral(x, x).atoms() == {x}
    assert Integral(f(x), (x, 0, 1)).atoms() == {0, 1, x}

    assert diff_test(Integral(x, (x, 3*y))) == {y}
    assert diff_test(Integral(x, (a, 3*y))) == {x, y}

    assert integrate(x, (x, oo, oo)) == 0  # issue sympy/sympy#8171
    assert integrate(x, (x, -oo, -oo)) == 0

    # sum integral of terms
    assert integrate(y + x + exp(x), x) == x*y + x**2/2 + exp(x)

    assert Integral(x).is_commutative
    n = Symbol('n', commutative=False)
    assert Integral(n + x, x).is_commutative is False
Ejemplo n.º 27
0
def test_integrate_DiracDelta():
    # This is here to check that deltaintegrate is being called, but also
    # to test definite integrals. More tests are in test_deltafunctions.py
    assert integrate(DiracDelta(x) * f(x), (x, -oo, oo)) == f(0)
    assert integrate(DiracDelta(x) * f(x), (x, 0, oo)) == f(0)/2
    assert integrate(DiracDelta(x)**2, (x, -oo, oo)) == DiracDelta(0)
    # issue sympy/sympy#4522
    assert integrate(integrate((4 - 4*x + x*y - 4*y) *
                               DiracDelta(x)*DiracDelta(y - 1), (x, 0, 1)), (y, 0, 1)) == 0
    # issue sympy/sympy#5729
    p = exp(-(x**2 + y**2))/pi
    assert integrate(p*DiracDelta(x - 10*y), (x, -oo, oo), (y, -oo, oo)) == \
        integrate(p*DiracDelta(x - 10*y), (y, -oo, oo), (x, -oo, oo)) == \
        integrate(p*DiracDelta(10*x - y), (x, -oo, oo), (y, -oo, oo)) == \
        integrate(p*DiracDelta(10*x - y), (y, -oo, oo), (x, -oo, oo)) == \
        1/sqrt(101*pi)
Ejemplo n.º 28
0
def test_trigsimp_issues():
    # issue sympy/sympy#4625 - factor_terms works, too
    assert trigsimp(sin(x)**3 + cos(x)**2*sin(x)) == sin(x)

    # issue sympy/sympy#5948
    assert trigsimp(diff(integrate(cos(x)/sin(x)**3, x), x)) == \
        cos(x)/sin(x)**3
    assert trigsimp(diff(integrate(sin(x)/cos(x)**3, x), x)) == \
        sin(x)/cos(x)**3

    # check integer exponents
    e = sin(x)**y/cos(x)**y
    assert trigsimp(e) == e
    assert trigsimp(e.subs({y: 2})) == tan(x)**2
    assert trigsimp(e.subs({x: 1})) == tan(1)**y

    # check for multiple patterns
    assert (cos(x)**2/sin(x)**2*cos(y)**2/sin(y)**2).trigsimp() == \
        1/tan(x)**2/tan(y)**2
    assert trigsimp(cos(x)/sin(x)*cos(x+y)/sin(x+y)) == \
        1/(tan(x)*tan(x + y))

    eq = cos(2)*(cos(3) + 1)**2/(cos(3) - 1)**2
    assert trigsimp(eq) == eq.factor()  # factor makes denom (-1 + cos(3))**2
    assert trigsimp(cos(2)*(cos(3) + 1)**2*(cos(3) - 1)**2) == \
        cos(2)*sin(3)**4

    # issue sympy/sympy#6789; this generates an expression that formerly caused
    # trigsimp to hang
    assert cot(x).equals(tan(x)) is False

    # nan or the unchanged expression is ok, but not sin(1)
    z = cos(x)**2 + sin(x)**2 - 1
    z1 = tan(x)**2 - 1/cot(x)**2
    n = (1 + z1/z)
    assert trigsimp(sin(n)) != sin(1)
    eq = x*(n - 1) - x*n
    assert trigsimp(eq) is nan
    assert trigsimp(eq, recursive=True) is nan
    assert trigsimp(1).is_Integer

    assert trigsimp(-sin(x)**4 - 2*sin(x)**2*cos(x)**2 - cos(x)**4) == -1
Ejemplo n.º 29
0
def test_sympyissue_5167():
    f = Function('f')
    assert Integral(Integral(f(x), x), x) == Integral(f(x), x, x)
    assert Integral(f(x)).args == (f(x), Tuple(x))
    assert Integral(Integral(f(x))).args == (f(x), Tuple(x), Tuple(x))
    assert Integral(Integral(f(x)), y).args == (f(x), Tuple(x), Tuple(y))
    assert Integral(Integral(f(x), z), y).args == (f(x), Tuple(z), Tuple(y))
    assert Integral(Integral(Integral(f(x), x), y), z).args == \
        (f(x), Tuple(x), Tuple(y), Tuple(z))
    assert integrate(Integral(f(x), x), x) == Integral(f(x), x, x)
    assert integrate(Integral(f(x), y), x) == y*Integral(f(x), x)
    assert integrate(Integral(f(x), x), y) in [Integral(y*f(x), x), y*Integral(f(x), x)]
    assert integrate(Integral(2, x), x) == x**2
    assert integrate(Integral(2, x), y) == 2*x*y
    # don't re-order given limits
    assert Integral(1, x, y).args != Integral(1, y, x).args
    # do as many as possibble
    assert Integral(f(x), y, x, y, x).doit() == y**2*Integral(f(x), x, x)/2
    assert Integral(f(x), (x, 1, 2), (w, 1, x), (z, 1, y)).doit() == \
        y*(x - 1)*Integral(f(x), (x, 1, 2)) - (x - 1)*Integral(f(x), (x, 1, 2))
Ejemplo n.º 30
0
def test_sympyissue_4892b():
    # Issues relating to issue sympy/sympy#4596 are making the actual result of this hard
    # to test.  The answer should be something like
    #
    # (-sin(y) + sqrt(-72 + 48*cos(y) - 8*cos(y)**2)/2)*log(x + sqrt(-72 +
    # 48*cos(y) - 8*cos(y)**2)/(2*(3 - cos(y)))) + (-sin(y) - sqrt(-72 +
    # 48*cos(y) - 8*cos(y)**2)/2)*log(x - sqrt(-72 + 48*cos(y) -
    # 8*cos(y)**2)/(2*(3 - cos(y)))) + x**2*sin(y)/2 + 2*x*cos(y)

    expr = (sin(y)*x**3 + 2*cos(y)*x**2 + 12)/(x**2 + 2)
    assert trigsimp(factor(integrate(expr, x).diff(x) - expr)) == 0
Ejemplo n.º 31
0
def test_multiple_integration():
    assert integrate((x**2) * (y**2), (x, 0, 1), (y, -1, 2)) == 1
    assert integrate((y**2) * (x**2), x, y) == Rational(1, 9) * (x**3) * (y**3)
    assert integrate(1/(x + 3)/(1 + x)**3, x) == \
        -Rational(1, 8)*log(3 + x) + Rational(1, 8)*log(1 + x) + x/(4 + 8*x + 4*x**2)
Ejemplo n.º 32
0
def test_sympyissue_3560():
    assert integrate(sqrt(x)**3, x) == 2 * sqrt(x)**5 / 5
    assert integrate(sqrt(x), x) == 2 * sqrt(x)**3 / 3
    assert integrate(1 / sqrt(x)**3, x) == -2 / sqrt(x)
Ejemplo n.º 33
0
def test_sympyissue_5178():
    assert integrate(sin(x)*f(y, z), (x, 0, pi), (y, 0, pi), (z, 0, pi)) == \
        2*Integral(f(y, z), (y, 0, pi), (z, 0, pi))
Ejemplo n.º 34
0
def test_sympyissue_5413():
    # Note that this is not the same as testing ratint() becuase integrate()
    # pulls out the coefficient.
    assert integrate(-a / (a**2 + x**2),
                     x) == I * log(-I * a + x) / 2 - I * log(I * a + x) / 2
Ejemplo n.º 35
0
def test_sympyissue_4376():
    n = Symbol('n', integer=True, positive=True)
    assert simplify(
        integrate(n * (x**(1 / n) - 1), (x, 0, Rational(1, 2))) -
        (n**2 - 2**(1 / n) * n**2 - n * 2**(1 / n)) /
        (2**(1 + 1 / n) + n * 2**(1 + 1 / n))) == 0
Ejemplo n.º 36
0
def test_sympyissue_4403_2():
    assert integrate(sqrt(-x**2 - 4), x) == \
        -2*atan(x/sqrt(-4 - x**2)) + x*sqrt(-4 - x**2)/2
Ejemplo n.º 37
0
def test_sympyissue_3952():
    f = sin(x)
    assert integrate(f, x) == -cos(x)
    pytest.raises(ValueError, lambda: integrate(f, 2 * x))
Ejemplo n.º 38
0
def test_sympyissue_3788():
    assert integrate(1 / (1 + x**2), x) == atan(x)
Ejemplo n.º 39
0
def test_sympyissue_3740():
    f = 4 * log(x) - 2 * log(x)**2
    fid = diff(integrate(f, x), x)
    assert abs(f.subs({x: 42}).evalf() - fid.subs({x: 42}).evalf()) < 1e-10
Ejemplo n.º 40
0
def test_transcendental_functions():
    assert integrate(LambertW(2*x), x) == \
        -x + x*LambertW(2*x) + x/LambertW(2*x)
Ejemplo n.º 41
0
def test_sympyissue_3686(
):  # remove this when fresnel itegrals are implemented
    assert expand_func(integrate(sin(x**2), x)) == \
        sqrt(2)*sqrt(pi)*fresnels(sqrt(2)*x/sqrt(pi))/2
Ejemplo n.º 42
0
def test_sympyissue_3664():
    n = Symbol('n', integer=True, nonzero=True)
    assert integrate(-1./2 * x * sin(n * pi * x/2), [x, -2, 0]) == \
        2*cos(pi*n)/(pi*n)
    assert integrate(-x*sin(n*pi*x/2)/2, [x, -2, 0]) == \
        2*cos(pi*n)/(pi*n)
Ejemplo n.º 43
0
def test_integrate_omit_var():
    assert integrate(x) == x**2 / 2

    pytest.raises(ValueError, lambda: integrate(2))
    pytest.raises(ValueError, lambda: integrate(x * y))
Ejemplo n.º 44
0
def test_sympyissue_3635():
    assert integrate(x**2, y) == x**2 * y
    assert integrate(x**2, (y, -1, 1)) == 2 * x**2
Ejemplo n.º 45
0
def test_integrate_returns_piecewise():
    assert integrate(x**y, x) == Piecewise((log(x), Eq(y, -1)),
                                           (x**(y + 1) / (y + 1), True))
    assert integrate(x**y, y) == Piecewise((y, Eq(log(x), 0)),
                                           (x**y / log(x), True))
    assert integrate(exp(n * x), x) == Piecewise((x, Eq(n, 0)),
                                                 (exp(n * x) / n, True))
    assert integrate(x * exp(n * x), x) == Piecewise(
        (x**2 / 2, Eq(n**3, 0)), ((x * n**2 - n) * exp(n * x) / n**3, True))
    assert integrate(x**(n * y), x) == Piecewise(
        (log(x), Eq(n * y, -1)), (x**(n * y + 1) / (n * y + 1), True))
    assert integrate(x**(n * y), y) == Piecewise(
        (y, Eq(n * log(x), 0)), (x**(n * y) / (n * log(x)), True))
    assert integrate(cos(n * x), x) == Piecewise((x, Eq(n, 0)),
                                                 (sin(n * x) / n, True))
    assert integrate(cos(n * x)**2, x) == Piecewise(
        (x, Eq(n, 0)), ((n * x / 2 + sin(n * x) * cos(n * x) / 2) / n, True))
    assert integrate(x * cos(n * x), x) == Piecewise(
        (x**2 / 2, Eq(n, 0)), (x * sin(n * x) / n + cos(n * x) / n**2, True))
    assert integrate(sin(n * x), x) == Piecewise((0, Eq(n, 0)),
                                                 (-cos(n * x) / n, True))
    assert integrate(sin(n * x)**2, x) == Piecewise(
        (0, Eq(n, 0)), ((n * x / 2 - sin(n * x) * cos(n * x) / 2) / n, True))
    assert integrate(x * sin(n * x), x) == Piecewise(
        (0, Eq(n, 0)), (-x * cos(n * x) / n + sin(n * x) / n**2, True))
    assert integrate(exp(x * y), (x, 0, z)) == Piecewise(
        (z, Eq(y, 0)), (exp(y * z) / y - 1 / y, True))
Ejemplo n.º 46
0
def test_sympyissue_4516():
    assert integrate(2**x - 2 * x, x) == 2**x / log(2) - x**2
Ejemplo n.º 47
0
def test_sympyissue_4100():
    R = Symbol('R', positive=True)
    assert integrate(sqrt(R**2 - x**2), (x, 0, R)) == pi * R**2 / 4
Ejemplo n.º 48
0
def test_sympyissue_7450():
    ans = integrate(exp(-(1 + I) * x), (x, 0, oo))
    assert re(ans) == Rational(1, 2) and im(ans) == Rational(-1, 2)
Ejemplo n.º 49
0
def test_sympyissue_4517():
    assert integrate((sqrt(x) - x**3)/cbrt(x), x) == \
        6*x**Rational(7, 6)/7 - 3*x**Rational(11, 3)/11
Ejemplo n.º 50
0
def test_integrate_functions():
    # issue sympy/sympy#4111
    assert integrate(f(x), x) == Integral(f(x), x)
    assert integrate(f(x), (x, 0, 1)) == Integral(f(x), (x, 0, 1))

    assert integrate(Derivative(f(y), y), x) == x * Derivative(f(y), y)
Ejemplo n.º 51
0
def test_sympyissue_5907():
    a = Symbol('a', real=True)
    assert (integrate(1 / (x**2 + a**2)**2, x) == x /
            (2 * a**4 + 2 * a**2 * x**2) + atan(x / a) / (2 * a**3))
Ejemplo n.º 52
0
def test_integrate_functions_1():
    assert integrate(f(x) * diff(f(x), x), x) == f(x)**2 / 2
    assert integrate(diff(f(x), x) / f(x), x) == log(f(x))
Ejemplo n.º 53
0
def test_limit_bug():
    z = Symbol('z', nonzero=True)
    assert integrate(sin(x*y*z), (x, 0, pi), (y, 0, pi)) == \
        (log(z**2) + 2*EulerGamma + 2*log(pi))/(2*z) - \
        (-log(pi*z) + log(pi**2*z**2)/2 + Ci(pi**2*z))/z + log(pi)/z
Ejemplo n.º 54
0
def test_integrate_derivatives():
    assert integrate(Derivative(f(x), x), x) == f(x)
Ejemplo n.º 55
0
def test_sympyissue_3532():
    assert integrate(exp(-x), (x, 0, oo)) == 1
Ejemplo n.º 56
0
def test_improper_integral():
    assert integrate(log(x), (x, 0, 1)) == -1
    assert integrate(x**(-2), (x, 1, oo)) == 1

    # issue sympy/sympy#10445:
    assert integrate(1 / (1 + exp(x)), (x, 0, oo)) == log(2)
Ejemplo n.º 57
0
def test_sympyissue_4052():
    f = Rational(1, 2) * asin(x) + x * sqrt(1 - x**2) / 2

    assert integrate(cos(asin(x)), x) == f
    assert integrate(sin(acos(x)), x) == f
Ejemplo n.º 58
0
def test_integrate_DiracDelta_fails():
    # issue sympy/sympy#6427
    integrate(DiracDelta(x - y - z), (x, 0, 1), (y, 0, 1),
              (z, 0, oo))  # = Rational(1, 2)
Ejemplo n.º 59
0
def test_sympyissue_3618():
    assert integrate(pi * sqrt(x), x) == 2 * pi * sqrt(x)**3 / 3
    assert integrate(pi*sqrt(x) + E*sqrt(x)**3, x) == \
        2*pi*sqrt(x)**3/3 + 2*E * sqrt(x)**5/5
Ejemplo n.º 60
0
def test_integrate_poly_accurately():
    assert integrate(x * sin(y), x) == x**2 * sin(y) / 2

    # when passed to risch_norman, this will be a CPU hog, so this really
    # checks, that integrated function is recognized as polynomial
    assert integrate(x**1000 * sin(y), x) == x**1001 * sin(y) / 1001