Exemplo n.º 1
0
def test_subs1():
    e = Integral(exp(x - y), x)
    assert e.subs(y, 3) == Integral(exp(x - 3), x)
    e = Integral(exp(x - y), (x, 0, 1))
    assert e.subs(y, 3) == Integral(exp(x - 3), (x, 0, 1))
    f = Lambda(x, exp(-x**2))
    conv = Integral(f(x - y) * f(y), (y, -oo, oo))
    assert conv.subs({x: 0}) == Integral(exp(-2 * y**2), (y, -oo, oo))
Exemplo n.º 2
0
def test_pickling_polys_rootoftools():
    f = x**3 + x + 3

    for c in (RootOf, RootOf(f, 0)):
        check(c)

    for c in (RootSum, RootSum(f, Lambda(x, exp(x)))):
        check(c)
Exemplo n.º 3
0
def test_funcmatrix():
    X = FunctionMatrix(3, 3, Lambda((i, j), i - j))
    assert X[1, 1] == 0
    assert X[1, 2] == -1
    assert X.shape == (3, 3)
    assert X.rows == X.cols == 3
    assert Matrix(X) == Matrix(3, 3, lambda i, j: i - j)
    assert isinstance(X * X + X, MatrixExpr)
Exemplo n.º 4
0
def test_issue_922():
    assert rsolve(-2 * n / 3 + f(n) - f(n - 1) + 2 * (n - 1)**3 / 3 + 2 *
                  (n - 1)**2 / 3,
                  init={f(0): 0}) == [{
                            f:
                            Lambda(n,
                                   n * (-3 * n**3 + 2 * n**2 + 9 * n + 4) / 18)
                        }]
Exemplo n.º 5
0
def test_RootSum___eq__():
    f = Lambda(x, exp(x))

    assert (RootSum(x**3 + x + 1, f) == RootSum(x**3 + x + 1, f)) is True
    assert (RootSum(x**3 + x + 1, f) == RootSum(y**3 + y + 1, f)) is True

    assert (RootSum(x**3 + x + 1, f) == RootSum(x**3 + x + 2, f)) is False
    assert (RootSum(x**3 + x + 1, f) == RootSum(y**3 + y + 2, f)) is False
Exemplo n.º 6
0
def test_Lambda_equality():
    assert Lambda(x, 2 * x) == Lambda(y, 2 * y)
    # although variables are casts as Dummies, the expressions
    # should still compare equal
    assert Lambda((x, y), 2 * x) == Lambda((x, y), 2 * x)
    assert Lambda(x, 2 * x) != Lambda((x, y), 2 * x)
    assert Lambda(x, 2 * x) != 2 * x
Exemplo n.º 7
0
def test_DifferentialExtension_misc():
    # Odd ends
    assert DifferentialExtension(sin(y)*exp(x), x, dummy=False)._important_attrs == \
        (Poly(sin(y)*t0, t0, domain='ZZ[sin(y)]'), Poly(1, t0, domain='ZZ'),
         [Poly(1, x, domain='ZZ'), Poly(t0, t0, domain='ZZ')], [x, t0],
         [Lambda(i, exp(i))], [], [1], [x], [], [])
    pytest.raises(NotImplementedError, lambda: DifferentialExtension(sin(x), x))
    assert DifferentialExtension(10**x, x, dummy=False)._important_attrs == \
        (Poly(t0, t0), Poly(1, t0), [Poly(1, x), Poly(log(10)*t0, t0)], [x, t0],
         [Lambda(i, exp(i*log(10)))], [(exp(x*log(10)), 10**x)], [1], [x*log(10)],
         [], [])
    assert DifferentialExtension(log(x) + log(x**2), x, dummy=False)._important_attrs in [
        (Poly(3*t0, t0), Poly(2, t0), [Poly(1, x), Poly(2/x, t0)], [x, t0],
         [Lambda(i, log(i**2))], [], [], [], [1], [x**2]),
        (Poly(3*t0, t0), Poly(1, t0), [Poly(1, x), Poly(1/x, t0)], [x, t0],
         [Lambda(i, log(i))], [], [], [], [1], [x])]
    assert DifferentialExtension(Integer(0), x, dummy=False)._important_attrs == \
        (Poly(0, x), Poly(1, x), [Poly(1, x)], [x], [], [], [], [], [], [])
Exemplo n.º 8
0
def test_ImageSet():
    squares = ImageSet(Lambda(x, x**2), S.Naturals)
    assert 4 in squares
    assert 5 not in squares
    assert FiniteSet(*range(10)).intersection(squares) == FiniteSet(1, 4, 9)

    assert 16 not in squares.intersection(Interval(0, 10))

    si = iter(squares)
    a, b, c, d = next(si), next(si), next(si), next(si)
    assert (a, b, c, d) == (1, 4, 9, 16)

    harmonics = ImageSet(Lambda(x, 1 / x), S.Naturals)
    assert Rational(1, 5) in harmonics
    assert Rational(.25) in harmonics
    assert 0.25 not in harmonics
    assert Rational(.3) not in harmonics

    assert harmonics.is_iterable
Exemplo n.º 9
0
def test_halfcircle():
    r, th = symbols('r, theta', extended_real=True)
    L = Lambda((r, th), (r * cos(th), r * sin(th)))
    halfcircle = ImageSet(L, Interval(0, 1) * Interval(0, pi))

    assert (1, 0) in halfcircle
    assert (0, -1) not in halfcircle
    assert (0, 0) in halfcircle

    assert not halfcircle.is_iterable
Exemplo n.º 10
0
def test_infinitely_indexed_set_1():
    assert imageset(Lambda(n, n), S.Integers) == imageset(Lambda(m, m), S.Integers)

    assert (imageset(Lambda(n, 2*n),
                     S.Integers).intersect(imageset(Lambda(m, 2*m + 1),
                                                    S.Integers)) ==
            EmptySet())

    assert (imageset(Lambda(n, 2*n),
                     S.Integers).intersect(imageset(Lambda(n, 2*n + 1),
                                                    S.Integers)) ==
            EmptySet())

    assert (imageset(Lambda(m, 2*m),
                     S.Integers).intersect(imageset(Lambda(n, 3*n),
                                                    S.Integers)) ==
            ImageSet(Lambda(t, 6*t), S.Integers))
Exemplo n.º 11
0
def test_integers():
    Z = S.Integers
    assert 5 in Z
    assert -5 in Z
    assert 5.5 not in Z
    zi = iter(Z)
    a, b, c, d = next(zi), next(zi), next(zi), next(zi)
    assert (a, b, c, d) == (0, 1, -1, 2)
    assert isinstance(a, Basic)

    assert Z.intersection(Interval(-5, 5)) == Range(-5, 6)
    assert Z.intersection(Interval(-5, 5, True, True)) == Range(-4, 5)
    assert Z.intersection(Set(x)) == Intersection(Z, Set(x), evaluate=False)

    assert Z.inf == -oo
    assert Z.sup == oo

    assert Z.boundary == Z

    assert imageset(Lambda((x, y), x * y),
                    Z) == ImageSet(Lambda((x, y), x * y), Z)
Exemplo n.º 12
0
def test_DifferentialExtension_handle_first():
    assert DifferentialExtension(exp(x)*log(x), x, handle_first='log',
                                 dummy=False)._important_attrs == \
        (Poly(t0*t1, t1), Poly(1, t1), [Poly(1, x), Poly(1/x, t0),
                                        Poly(t1, t1)], [x, t0, t1], [Lambda(i, log(i)), Lambda(i, exp(i))],
         [], [2], [x], [1], [x])
    assert DifferentialExtension(exp(x)*log(x), x, handle_first='exp',
                                 dummy=False)._important_attrs == \
        (Poly(t0*t1, t1), Poly(1, t1), [Poly(1, x), Poly(t0, t0),
                                        Poly(1/x, t1)], [x, t0, t1], [Lambda(i, exp(i)), Lambda(i, log(i))],
         [], [1], [x], [2], [x])

    # This one must have the log first, regardless of what we set it to
    # (because the log is inside of the exponential: x**x == exp(x*log(x)))
    assert DifferentialExtension(-x**x*log(x)**2 + x**x - x**x/x, x,
                                 handle_first='exp', dummy=False)._important_attrs == \
        DifferentialExtension(-x**x*log(x)**2 + x**x - x**x/x, x,
                              handle_first='log', dummy=False)._important_attrs == \
        (Poly((-1 + x - x*t0**2)*t1, t1), Poly(x, t1),
            [Poly(1, x), Poly(1/x, t0), Poly((1 + t0)*t1, t1)], [x, t0, t1],
            [Lambda(i, log(i)), Lambda(i, exp(t0*i))], [(exp(x*log(x)), x**x)],
            [2], [t0*x], [1], [x])
Exemplo n.º 13
0
def test_integrate_primitive():
    DE = DifferentialExtension(extension={
        'D': [Poly(1, x), Poly(1 / x, t)],
        'Tfuncs': [log]
    })
    assert integrate_primitive(Poly(t, t), Poly(1, t),
                               DE) == (x * log(x), -1, True)
    assert integrate_primitive(Poly(x, t), Poly(t, t),
                               DE) == (0, NonElementaryIntegral(x / log(x),
                                                                x), False)

    DE = DifferentialExtension(
        extension={
            'D': [Poly(1, x),
                  Poly(1 / x, t1),
                  Poly(1 / (x + 1), t2)],
            'Tfuncs': [log, Lambda(i, log(i + 1))]
        })
    assert integrate_primitive(Poly(t1, t2), Poly(t2, t2), DE) == \
        (0, NonElementaryIntegral(log(x)/log(1 + x), x), False)

    DE = DifferentialExtension(
        extension={
            'D': [Poly(1, x),
                  Poly(1 / x, t1),
                  Poly(1 / (x * t1), t2)],
            'Tfuncs': [log, Lambda(i, log(log(i)))]
        })
    assert integrate_primitive(Poly(t2, t2), Poly(t1, t2), DE) == \
        (0, NonElementaryIntegral(log(log(x))/log(x), x), False)

    DE = DifferentialExtension(extension={
        'D': [Poly(1, x), Poly(1 / x, t0)],
        'Tfuncs': [log]
    })
    assert integrate_primitive(Poly(x**2*t0**3 + (3*x**2 + x)*t0**2 + (3*x**2
                                                                       + 2*x)*t0 + x**2 + x, t0), Poly(x**2*t0**4 + 4*x**2*t0**3 + 6*x**2*t0**2 +
                                                                                                       4*x**2*t0 + x**2, t0), DE) == \
        (-1/(log(x) + 1), NonElementaryIntegral(1/(log(x) + 1), x), False)
Exemplo n.º 14
0
def test_halfcircle():
    # This test sometimes works and sometimes doesn't.
    # It may be an issue with solve? Maybe with using Lambdas/dummys?
    # I believe the code within fancysets is correct
    r, th = symbols('r, theta', extended_real=True)
    L = Lambda((r, th), (r*cos(th), r*sin(th)))
    halfcircle = ImageSet(L, Interval(0, 1)*Interval(0, pi))

    assert (1, 0) in halfcircle
    assert (0, -1) not in halfcircle
    assert (0, 0) in halfcircle

    assert not halfcircle.is_iterable
Exemplo n.º 15
0
def test_apart_full():
    f = 1 / (x**2 + 1)

    assert apart(f, full=False) == f
    assert apart(f, full=True) == \
        -RootSum(x**2 + 1, Lambda(a, a/(x - a)), auto=False)/2

    f = 1 / (x**3 + x + 1)

    assert apart(f, full=False) == f
    assert apart(f, full=True) == \
        RootSum(x**3 + x + 1,
        Lambda(a, (6*a**2/31 - 9*a/31 + Rational(4, 31))/(x - a)), auto=False)

    f = 1 / (x**5 + 1)

    assert apart(f, full=False) == \
        (-Rational(1, 5))*((x**3 - 2*x**2 + 3*x - 4)/(x**4 - x**3 + x**2 -
         x + 1)) + (Rational(1, 5))/(x + 1)
    assert apart(f, full=True) == \
        -RootSum(x**4 - x**3 + x**2 - x + 1,
        Lambda(a, a/(x - a)), auto=False)/5 + (Rational(1, 5))/(x + 1)
Exemplo n.º 16
0
def test_apart_list():
    from diofant.utilities.iterables import numbered_symbols

    assert apart_list(1) == 1

    w0, w1, w2 = Symbol("w0"), Symbol("w1"), Symbol("w2")
    _a = Dummy("a")

    f = (-2 * x - 2 * x**2) / (3 * x**2 - 6 * x)
    assert apart_list(f, x,
                      dummies=numbered_symbols("w")) == (-1,
                                                         Poly(Rational(2, 3),
                                                              x,
                                                              domain='QQ'),
                                                         [(Poly(w0 - 2,
                                                                w0,
                                                                domain='ZZ'),
                                                           Lambda(_a, 2),
                                                           Lambda(_a, -_a + x),
                                                           1)])

    assert apart_list(
        2 / (x**2 - 2), x,
        dummies=numbered_symbols("w")) == (1, Poly(0, x, domain='ZZ'), [
            (Poly(w0**2 - 2, w0,
                  domain='ZZ'), Lambda(_a, _a / 2), Lambda(_a, -_a + x), 1)
        ])

    f = 36 / (x**5 - 2 * x**4 - 2 * x**3 + 4 * x**2 + x - 2)
    assert apart_list(
        f, x, dummies=numbered_symbols("w")) == (1, Poly(0, x, domain='ZZ'), [
            (Poly(w0 - 2, w0, domain='ZZ'), Lambda(_a, 4), Lambda(_a,
                                                                  -_a + x), 1),
            (Poly(w1**2 - 1, w1,
                  domain='ZZ'), Lambda(_a, -3 * _a - 6), Lambda(_a,
                                                                -_a + x), 2),
            (Poly(w2 + 1, w2, domain='ZZ'), Lambda(_a,
                                                   -4), Lambda(_a, -_a + x), 1)
        ])
Exemplo n.º 17
0
def test_sympyissue_18751():
    r = symbols('r', real=True, positive=True)
    theta = symbols('theta', real=True)

    eq = f(n) - 2 * r * cos(theta) * f(n - 1) + r**2 * f(n - 2)
    res = [{
        f:
        Lambda(
            n,
            r**n * (C0 * (cos(theta) - I * abs(sin(theta)))**n + C1 *
                    (cos(theta) + I * abs(sin(theta)))**n))
    }]

    assert rsolve(eq) == res
Exemplo n.º 18
0
    def compute_cdf(self, **kwargs):
        """ Compute the CDF from the PDF

        Returns a Lambda
        """
        x, z = symbols('x, z', integer=True, finite=True, cls=Dummy)
        left_bound = self.set.inf

        # CDF is integral of PDF from left bound to z
        pdf = self.pdf(x)
        cdf = summation(pdf, (x, left_bound, z), **kwargs)
        # CDF Ensure that CDF left of left_bound is zero
        cdf = Piecewise((cdf, z >= left_bound), (0, True))
        return Lambda(z, cdf)
Exemplo n.º 19
0
def test_call():
    # See the long history of this in issues sympy/sympy#5026 and sympy/sympy#5105.

    pytest.raises(TypeError, lambda: sin(x)({x: 1, sin(x): 2}))
    pytest.raises(TypeError, lambda: sin(x)(1))

    # No effect as there are no callables
    assert sin(x).rcall(1) == sin(x)
    assert (1 + sin(x)).rcall(1) == 1 + sin(x)

    # Effect in the pressence of callables
    l = Lambda(x, 2 * x)
    assert (l + x).rcall(y) == 2 * y + x
    assert (x**l).rcall(2) == x**4
Exemplo n.º 20
0
    def _inverse_cdf_expression(self):
        """ Inverse of the CDF

        Used by sample
        """
        x, z = symbols('x, z', extended_real=True, positive=True, cls=Dummy)
        # Invert CDF
        try:
            inverse_cdf = solve(self.cdf(x) - z, x)
        except NotImplementedError:
            inverse_cdf = None
        if not inverse_cdf or len(inverse_cdf) != 1:
            raise NotImplementedError("Could not invert CDF")

        return Lambda(z, inverse_cdf[0])
Exemplo n.º 21
0
def test_ccode_Pow():
    assert ccode(x**3) == 'pow(x, 3)'
    assert ccode(x**(y**3)) == 'pow(x, pow(y, 3))'
    g = implemented_function('g', Lambda(x, 2*x))
    assert ccode(1/(g(x)*3.5)**(x - y**x)/(x**2 + y)) == \
        'pow(3.5*2*x, -x + pow(y, x))/(pow(x, 2) + y)'
    assert ccode(x**-1.0) == '1.0/x'
    assert ccode(x**Rational(2, 3)) == 'pow(x, 2.0L/3.0L)'
    _cond_cfunc = [(lambda base, exp: exp.is_integer, 'dpowi'),
                   (lambda base, exp: not exp.is_integer, 'pow')]
    assert ccode(x**3, user_functions={'Pow': _cond_cfunc}) == 'dpowi(x, 3)'
    assert ccode(x**3.2, user_functions={'Pow': _cond_cfunc}) == 'pow(x, 3.2)'

    _cond_cfunc2 = [(lambda base, exp: base == 2, lambda base, exp: f'exp2({exp})'),
                    (lambda base, exp: base != 2, 'pow')]
    # Related to sympy/sympy#11353
    assert ccode(2**x, user_functions={'Pow': _cond_cfunc2}) == 'exp2(x)'
    assert ccode(x**2, user_functions={'Pow': _cond_cfunc2}) == 'pow(x, 2)'
Exemplo n.º 22
0
    def doit(self, **kwargs):
        evaluate = kwargs.pop('evaluate', True)

        expr, condition = self.expr, self.condition
        if condition is not None:
            # Recompute on new conditional expr
            expr = given(expr, condition, **kwargs)
        if not random_symbols(expr):
            return Lambda(x, DiracDelta(x - expr))
        if (isinstance(expr, RandomSymbol) and
                hasattr(expr.pspace, 'distribution') and
                isinstance(pspace(expr), SinglePSpace)):
            return expr.pspace.distribution
        result = pspace(expr).compute_density(expr, **kwargs)

        if evaluate and hasattr(result, 'doit'):
            return result.doit()
        else:
            return result
Exemplo n.º 23
0
def test_image_interval():
    x = Symbol('x', extended_real=True)
    a = Symbol('a', extended_real=True)
    assert imageset(x, 2 * x, Interval(-2, 1)) == Interval(-4, 2)
    assert imageset(x, 2*x, Interval(-2, 1, True, False)) == \
        Interval(-4, 2, True, False)
    assert imageset(x, x**2, Interval(-2, 1, True, False)) == \
        Interval(0, 4, False, True)
    assert imageset(x, x**2, Interval(-2, 1)) == Interval(0, 4)
    assert imageset(x, x**2, Interval(-2, 1, True, False)) == \
        Interval(0, 4, False, True)
    assert imageset(x, x**2, Interval(-2, 1, True, True)) == \
        Interval(0, 4, False, True)
    assert imageset(x, (x - 2)**2, Interval(1, 3)) == Interval(0, 1)
    assert imageset(x, 3*x**4 - 26*x**3 + 78*x**2 - 90*x, Interval(0, 4)) == \
        Interval(-35, 0)  # Multiple Maxima
    assert imageset(x, x + 1/x, Interval(-oo, oo)) == Interval(-oo, -2) \
        + Interval(2, oo)  # Single Infinite discontinuity
    assert imageset(x, 1/x + 1/(x - 1)**2, Interval(0, 2, True, False)) == \
        Interval(Rational(3, 2), oo, False, True)  # Multiple Infinite discontinuities

    # issue sympy/sympy#10113
    assert imageset(x, x**2 / (x**2 - 4),
                    Interval(-2, 2)) == Interval(-oo, 0, True)

    # Test for Python lambda
    assert imageset(lambda x: 2 * x, Interval(-2, 1)) == Interval(-4, 2)

    assert (imageset(Lambda(x, a * x),
                     Interval(0, 1)) == ImageSet(Lambda(x, a * x),
                                                 Interval(0, 1)))

    assert (imageset(Lambda(x, sin(cos(x))),
                     Interval(0, 1)) == ImageSet(Lambda(x, sin(cos(x))),
                                                 Interval(0, 1)))

    assert imageset(x, -(x - 2) * (x + 2), Interval(-3, 4)) == Interval(-12, 4)

    assert (imageset(z, 2 * z, ImageSet(Lambda((x, y), x * y),
                                        Interval(0, 2))) == ImageSet(
                                            Lambda(z, 2 * z),
                                            ImageSet(Lambda((x, y), x * y),
                                                     Interval(0, 2))))
Exemplo n.º 24
0
def test_rsolve():
    f = y(n + 2) - y(n + 1) - y(n)
    h = sqrt(5)*(Rational(1, 2) + sqrt(5)/2)**n \
        - sqrt(5)*(Rational(1, 2) - sqrt(5)/2)**n

    assert rsolve(f, y(n)) in [
        C0 * (Rational(1, 2) - sqrt(5) / 2)**n + C1 *
        (Rational(1, 2) + sqrt(5) / 2)**n,
        C1 * (Rational(1, 2) - sqrt(5) / 2)**n + C0 *
        (Rational(1, 2) + sqrt(5) / 2)**n,
    ]

    assert rsolve(f, y(n), [0, 5]) == h
    assert rsolve(f, y(n), {0: 0, 1: 5}) == h
    assert rsolve(f, y(n), {y(0): 0, y(1): 5}) == h
    assert rsolve(y(n) - y(n - 1) - y(n - 2), y(n), [0, 5]) == h
    assert rsolve(Eq(y(n), y(n - 1) + y(n - 2)), y(n), [0, 5]) == h

    assert f.subs(y, Lambda(k, rsolve(f, y(n)).subs(n, k))).simplify() == 0

    f = (n - 1) * y(n + 2) - (n**2 + 3 * n - 2) * y(n + 1) + 2 * n * (n +
                                                                      1) * y(n)
    g = C1 * factorial(n) + C0 * 2**n
    h = -3 * factorial(n) + 3 * 2**n

    assert rsolve(f, y(n)) == g
    assert rsolve(f, y(n), []) == g
    assert rsolve(f, y(n), {}) == g

    assert rsolve(f, y(n), [0, 3]) == h
    assert rsolve(f, y(n), {0: 0, 1: 3}) == h
    assert rsolve(f, y(n), {y(0): 0, y(1): 3}) == h

    assert f.subs(y, Lambda(k, rsolve(f, y(n)).subs(n, k))).simplify() == 0

    f = y(n) - y(n - 1) - 2

    assert rsolve(f, y(n), {y(0): 0}) == 2 * n
    assert rsolve(f, y(n), {y(0): 1}) == 2 * n + 1
    assert rsolve(f, y(n), {y(0): 0, y(1): 1}) is None

    assert f.subs(y, Lambda(k, rsolve(f, y(n)).subs(n, k))).simplify() == 0

    f = 3 * y(n - 1) - y(n) - 1

    assert rsolve(f, y(n), {y(0): 0}) == -3**n / 2 + Rational(1, 2)
    assert rsolve(f, y(n), {y(0): 1}) == 3**n / 2 + Rational(1, 2)
    assert rsolve(f, y(n), {y(0): 2}) == 3 * 3**n / 2 + Rational(1, 2)

    assert f.subs(y, Lambda(k, rsolve(f, y(n)).subs(n, k))).simplify() == 0

    f = y(n) - 1 / n * y(n - 1)
    assert rsolve(f, y(n)) == C0 / factorial(n)
    assert f.subs(y, Lambda(k, rsolve(f, y(n)).subs(n, k))).simplify() == 0

    f = y(n) - 1 / n * y(n - 1) - 1
    assert rsolve(f, y(n)) is None

    f = 2 * y(n - 1) + (1 - n) * y(n) / n

    assert rsolve(f, y(n), {y(1): 1}) == 2**(n - 1) * n
    assert rsolve(f, y(n), {y(1): 2}) == 2**(n - 1) * n * 2
    assert rsolve(f, y(n), {y(1): 3}) == 2**(n - 1) * n * 3

    assert f.subs(y, Lambda(k, rsolve(f, y(n)).subs(n, k))).simplify() == 0

    f = (n - 1) * (n - 2) * y(n + 2) - (n + 1) * (n + 2) * y(n)

    assert rsolve(f, y(n), {y(3): 6, y(4): 24}) == n * (n - 1) * (n - 2)
    assert rsolve(f, y(n), {
        y(3): 6,
        y(4): -24
    }) == -n * (n - 1) * (n - 2) * (-1)**(n)

    assert f.subs(y, Lambda(k, rsolve(f, y(n)).subs(n, k))).simplify() == 0

    assert rsolve(Eq(y(n + 1), a * y(n)), y(n), {y(1): a}).simplify() == a**n

    assert rsolve(y(n) - a*y(n-2), y(n),
                  {y(1): sqrt(a)*(a + b), y(2): a*(a - b)}).simplify() == \
        a**(n/2)*(-(-1)**n*b + a)

    f = (-16 * n**2 + 32 * n - 12) * y(n - 1) + (4 * n**2 - 12 * n + 9) * y(n)

    assert expand_func(rsolve(f, y(n),
                              {y(1): binomial(2*n + 1, 3)}).rewrite(gamma)).simplify() == \
        2**(2*n)*n*(2*n - 1)*(4*n**2 - 1)/12

    assert (rsolve(y(n) + a * (y(n + 1) + y(n - 1)) / 2, y(n)) -
            (C0 * (-sqrt(-1 + a**(-2)) - 1 / a)**n + C1 *
             (sqrt(-1 + a**(-2)) - 1 / a)**n)).simplify() == 0
Exemplo n.º 25
0
def test_sym_integral():
    f = Lambda(x, exp(-x**2))
    l = lambdify(x, Integral(f(x), (x, -oo, oo)), modules="diofant")
    assert l(y).doit() == sqrt(pi)
Exemplo n.º 26
0
def test_integral():
    f = Lambda(x, exp(-x**2))
    l = lambdify(x, Integral(f(x), (x, -oo, oo)), modules="diofant")
    assert l(x) == Integral(exp(-x**2), (x, -oo, oo))
Exemplo n.º 27
0
def test_ImageSet_simplification():
    assert imageset(Lambda(n, n), S.Integers) == S.Integers
    assert (imageset(Lambda(n, sin(n)),
                     imageset(Lambda(m, tan(m)),
                              S.Integers)) == imageset(Lambda(m, sin(tan(m))),
                                                       S.Integers))
Exemplo n.º 28
0
def test_infinitely_indexed_set_3():
    assert imageset(Lambda(n, 2 * n + 1),
                    S.Integers) == imageset(Lambda(n, 2 * n - 1), S.Integers)
    assert imageset(Lambda(n, 3 * n + 2),
                    S.Integers) == imageset(Lambda(n, 3 * n - 1), S.Integers)
Exemplo n.º 29
0
def test_infinitely_indexed_diophantine():
    assert (imageset(Lambda(m, 2 * pi * m), S.Integers).intersection(
        imageset(Lambda(n, 3 * pi * n),
                 S.Integers)) == ImageSet(Lambda(t, 6 * pi * t), S.Integers))
Exemplo n.º 30
0
def test_infinitely_indexed_set_2():
    a = Symbol('a', integer=True)
    assert imageset(Lambda(n, n),
                    S.Integers) == imageset(Lambda(n, n + a), S.Integers)
    assert imageset(Lambda(n, n),
                    S.Integers) == imageset(Lambda(n, -n + a), S.Integers)
    assert imageset(Lambda(n, -6 * n),
                    S.Integers) == ImageSet(Lambda(n, 6 * n), S.Integers)
    assert imageset(Lambda(n, 2 * n + pi),
                    S.Integers) == ImageSet(Lambda(n, 2 * n + pi), S.Integers)
    assert imageset(Lambda(n, pi * n + pi),
                    S.Integers) == ImageSet(Lambda(n, pi * n + pi), S.Integers)
    assert imageset(Lambda(n, exp(n)), S.Integers) != imageset(
        Lambda(n, n), S.Integers)