Esempio n. 1
0
def test_ImageSet():
    assert ImageSet(Lambda(x, 1), S.Integers) == FiniteSet(1)
    assert ImageSet(Lambda(x, y), S.Integers) == FiniteSet(y)
    squares = ImageSet(Lambda(x, x**2), S.Naturals)
    assert 4 in squares
    assert 5 not in squares
    assert FiniteSet(*range(10)).intersect(squares) == FiniteSet(1, 4, 9)

    assert 16 not in squares.intersect(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

    c = ComplexRegion(Interval(1, 3)*Interval(1, 3))
    assert Tuple(2, 6) in ImageSet(Lambda((x, y), (x, 2*y)), c)
    assert Tuple(2, S.Half) in ImageSet(Lambda((x, y), (x, 1/y)), c)
    assert Tuple(2, -2) not in ImageSet(Lambda((x, y), (x, y**2)), c)
    assert Tuple(2, -2) in ImageSet(Lambda((x, y), (x, -2)), c)
    c3 = Interval(3, 7)*Interval(8, 11)*Interval(5, 9)
    assert Tuple(8, 3, 9) in ImageSet(Lambda((t, y, x), (y, t, x)), c3)
    assert Tuple(S(1)/8, 3, 9) in ImageSet(Lambda((t, y, x), (1/y, t, x)), c3)
    assert 2/pi not in ImageSet(Lambda((x, y), 2/x), c)
    assert 2/S(100) not in ImageSet(Lambda((x, y), 2/x), c)
    assert 2/S(3) in ImageSet(Lambda((x, y), 2/x), c)
Esempio n. 2
0
def test_imageset_intersect_real():
    from sympy import I
    from sympy.abc import n
    assert imageset(Lambda(n, n + (n - 1)*(n + 1)*I), S.Integers).intersect(S.Reals) == \
            FiniteSet(-1, 1)

    s = ImageSet(Lambda(n, -I*(I*(2*pi*n - pi/4) + log(Abs(sqrt(-I))))), S.Integers)
    assert s.intersect(S.Reals) == imageset(Lambda(n, 2*n*pi - pi/4), S.Integers)
Esempio n. 3
0
def test_infinitely_indexed_set_2():
    from sympy import exp
    from sympy.abc import n
    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)
Esempio n. 4
0
def test_issue_18050():
    assert imageset(Lambda(x, I * x + 1),
                    S.Integers) == ImageSet(Lambda(x, I * x + 1), S.Integers)
    assert imageset(Lambda(x, 3 * I * x + 4 + 8 * I),
                    S.Integers) == ImageSet(Lambda(x, 3 * I * x + 4 + 2 * I),
                                            S.Integers)
    # no 'Mod' for next 2 tests:
    assert imageset(Lambda(x, 2 * x + 3 * I),
                    S.Integers) == ImageSet(Lambda(x, 2 * x + 3 * I),
                                            S.Integers)
    r = Symbol('r', positive=True)
    assert imageset(Lambda(x, r * x + 10),
                    S.Integers) == ImageSet(Lambda(x, r * x + 10), S.Integers)
    # reduce real part:
    assert imageset(Lambda(x, 3 * x + 8 + 5 * I),
                    S.Integers) == ImageSet(Lambda(x, 3 * x + 2 + 5 * I),
                                            S.Integers)
Esempio n. 5
0
def test_infinitely_indexed_set_3():
    from sympy.abc import n, m, t
    assert imageset(Lambda(m, 2*pi*m), S.Integers).intersect(
            imageset(Lambda(n, 3*pi*n), S.Integers)) == \
        ImageSet(Lambda(t, 6*pi*t), S.Integers)
    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)
Esempio n. 6
0
def test_Integers_eval_imageset():
    ans = ImageSet(Lambda(x, 2 * x + Rational(3, 7)), S.Integers)
    im = imageset(Lambda(x, -2 * x + Rational(3, 7)), S.Integers)
    assert im == ans
    im = imageset(Lambda(x, -2 * x - Rational(11, 7)), S.Integers)
    assert im == ans
    y = Symbol('y')
    L = imageset(x, 2 * x + y, S.Integers)
    assert y + 4 in L

    _x = symbols('x', negative=True)
    eq = _x**2 - _x + 1
    assert imageset(_x, eq, S.Integers).lamda.expr == _x**2 + _x + 1
    eq = 3 * _x - 1
    assert imageset(_x, eq, S.Integers).lamda.expr == 3 * _x + 2

    assert imageset(x, (x, 1/x), S.Integers) == \
        ImageSet(Lambda(x, (x, 1/x)), S.Integers)
Esempio n. 7
0
def test_Integers_eval_imageset():
    ans = ImageSet(Lambda(x, 2 * x + S(3) / 7), S.Integers)
    im = imageset(Lambda(x, -2 * x + S(3) / 7), S.Integers)
    assert im == ans
    im = imageset(Lambda(x, -2 * x - S(11) / 7), S.Integers)
    assert im == ans
    y = Symbol('y')
    assert imageset(x, 2*x + y, S.Integers) == \
        imageset(x, 2*x + y % 2, S.Integers)

    _x = symbols('x', negative=True)
    eq = _x**2 - _x + 1
    assert imageset(_x, eq, S.Integers).lamda.expr == _x**2 + _x + 1
    eq = 3 * _x - 1
    assert imageset(_x, eq, S.Integers).lamda.expr == 3 * _x + 2

    assert imageset(x, (x, 1/x), S.Integers) == \
        ImageSet(Lambda(x, (x, 1/x)), S.Integers)
def test_ImageSet():
    squares = ImageSet(Lambda(x, x**2), S.Naturals)
    assert 4 in squares
    assert 5 not in squares
    assert FiniteSet(range(10)).intersect(squares) == FiniteSet(1, 4, 9)

    assert 16 not in squares.intersect(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 .25 in harmonics
    assert .3 not in harmonics

    assert harmonics.is_iterable
Esempio n. 9
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)).intersect(squares) == FiniteSet(1, 4, 9)

    assert 16 not in squares.intersect(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 .25 in harmonics
    assert .3 not in harmonics

    assert harmonics.is_iterable
Esempio n. 10
0
def test_infinitely_indexed_set_1():
    from sympy.abc import n, m, t
    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)) is S.EmptySet

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

    assert imageset(Lambda(m, 2*m), S.Integers).intersect(
                imageset(Lambda(n, 3*n), S.Integers)).dummy_eq(
            ImageSet(Lambda(t, 6*t), S.Integers))

    assert imageset(x, x/2 + Rational(1, 3), S.Integers).intersect(S.Integers) is S.EmptySet
    assert imageset(x, x/2 + S.Half, S.Integers).intersect(S.Integers) is S.Integers

    # https://github.com/sympy/sympy/issues/17355
    S53 = ImageSet(Lambda(n, 5*n + 3), S.Integers)
    assert S53.intersect(S.Integers) == S53
Esempio n. 11
0
def test_infinitely_indexed_set_1():
    from sympy.abc import n, m, t
    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)
Esempio n. 12
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', 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
Esempio n. 13
0
def imageset(*args):
    r"""
    Image of set under transformation ``f``.

    If this function can't compute the image, it returns an
    unevaluated ImageSet object.

    .. math::
        { f(x) | x \in self }

    Examples
    ========

    >>> from sympy import Interval, Symbol, imageset, sin, Lambda
    >>> x = Symbol('x')

    >>> imageset(x, 2*x, Interval(0, 2))
    [0, 4]

    >>> imageset(lambda x: 2*x, Interval(0, 2))
    [0, 4]

    >>> imageset(Lambda(x, sin(x)), Interval(-2, 1))
    ImageSet(Lambda(x, sin(x)), [-2, 1])

    See Also
    ========

    sympy.sets.fancysets.ImageSet

    """
    from sympy.core import Dummy, Lambda
    from sympy.sets.fancysets import ImageSet
    if len(args) == 3:
        f = Lambda(*args[:2])
    else:
        # var and expr are being defined this way to
        # support Python lambda and not just sympy Lambda
        f = args[0]
        if not isinstance(f, Lambda):
            var = Dummy()
            expr = args[0](var)
            f = Lambda(var, expr)
    set = args[-1]

    r = set._eval_imageset(f)
    if r is not None:
        return r

    return ImageSet(f, set)
Esempio n. 14
0
def intersection_sets(self, other): # noqa:F811
    if other.is_ComplexRegion:
        # self in rectangular form
        if (not self.polar) and (not other.polar):
            return ComplexRegion(Intersection(self.sets, other.sets))

        # self in polar form
        elif self.polar and other.polar:
            r1, theta1 = self.a_interval, self.b_interval
            r2, theta2 = other.a_interval, other.b_interval
            new_r_interval = Intersection(r1, r2)
            new_theta_interval = Intersection(theta1, theta2)

            # 0 and 2*Pi means the same
            if ((2*S.Pi in theta1 and S.Zero in theta2) or
               (2*S.Pi in theta2 and S.Zero in theta1)):
                new_theta_interval = Union(new_theta_interval,
                                           FiniteSet(0))
            return ComplexRegion(new_r_interval*new_theta_interval,
                                polar=True)


    if other.is_subset(S.Reals):
        new_interval = []
        x = symbols("x", cls=Dummy, real=True)

        # self in rectangular form
        if not self.polar:
            for element in self.psets:
                if S.Zero in element.args[1]:
                    new_interval.append(element.args[0])
            new_interval = Union(*new_interval)
            return Intersection(new_interval, other)

        # self in polar form
        elif self.polar:
            for element in self.psets:
                if S.Zero in element.args[1]:
                    new_interval.append(element.args[0])
                if S.Pi in element.args[1]:
                    new_interval.append(ImageSet(Lambda(x, -x), element.args[0]))
                if S.Zero in element.args[0]:
                    new_interval.append(FiniteSet(0))
            new_interval = Union(*new_interval)
            return Intersection(new_interval, other)
Esempio n. 15
0
def test_infinitely_indexed_set_1():
    from sympy.abc import n, m, t
    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)) is S.EmptySet

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

    assert imageset(Lambda(m, 2*m), S.Integers).intersect(
                imageset(Lambda(n, 3*n), S.Integers)) == \
            ImageSet(Lambda(t, 6*t), S.Integers)

    assert imageset(x, x / 2 + Rational(1, 3), S.Integers).intersect(
        S.Integers) is S.EmptySet
    assert imageset(x, x / 2 + S.Half, S.Integers).intersect(
        S.Integers) is S.Integers
Esempio n. 16
0
def test_ImageSet_iterator_not_injective():
    L = Lambda(x, x - x % 2)  # produces 0, 2, 2, 4, 4, 6, 6, ...
    evens = ImageSet(L, S.Naturals)
    i = iter(evens)
    # No repeats here
    assert (next(i), next(i), next(i), next(i)) == (0, 2, 4, 6)
Esempio n. 17
0
def test_infinitely_indexed_failed_diophantine():
    from sympy.abc import n, m, t
    assert imageset(Lambda(m, 2*pi*m), S.Integers).intersect(imageset(Lambda(n, 3*pi*n), S.Integers)) == \
            ImageSet(Lambda(t, -6*pi*t), S.Integers)
def test_imageset_intersect_interval():
    from sympy.abc import n
    f1 = ImageSet(Lambda(n, n*pi), S.Integers)
    f2 = ImageSet(Lambda(n, 2*n), Interval(0, pi))
    f3 = ImageSet(Lambda(n, 2*n*pi + pi/2), S.Integers)
    # complex expressions
    f4 = ImageSet(Lambda(n, n*I*pi), S.Integers)
    f5 = ImageSet(Lambda(n, 2*I*n*pi + pi/2), S.Integers)
    # non-linear expressions
    f6 = ImageSet(Lambda(n, log(n)), S.Integers)
    f7 = ImageSet(Lambda(n, n**2), S.Integers)
    f8 = ImageSet(Lambda(n, Abs(n)), S.Integers)
    f9 = ImageSet(Lambda(n, exp(n)), S.Naturals0)

    assert f1.intersect(Interval(-1, 1)) == FiniteSet(0)
    assert f2.intersect(Interval(1, 2)) == Interval(1, 2)
    assert f3.intersect(Interval(-1, 1)) == S.EmptySet
    assert f3.intersect(Interval(-5, 5)) == FiniteSet(-3*pi/2, pi/2)
    assert f4.intersect(Interval(-1, 1)) == FiniteSet(0)
    assert f4.intersect(Interval(1, 2)) == S.EmptySet
    assert f5.intersect(Interval(0, 1)) == S.EmptySet
    assert f6.intersect(Interval(0, 1)) == FiniteSet(S.Zero, log(2))
    assert f7.intersect(Interval(0, 10)) == Intersection(f7, Interval(0, 10))
    assert f8.intersect(Interval(0, 2)) == Intersection(f8, Interval(0, 2))
    assert f9.intersect(Interval(1, 2)) == Intersection(f9, Interval(1, 2))
Esempio n. 19
0
def test_ImageSet():
    raises(ValueError, lambda: ImageSet(x, S.Integers))
    assert ImageSet(Lambda(x, 1), S.Integers) == FiniteSet(1)
    assert ImageSet(Lambda(x, y), S.Integers) == {y}
    assert ImageSet(Lambda(x, 1), S.EmptySet) == S.EmptySet
    empty = Intersection(FiniteSet(log(2) / pi), S.Integers)
    assert unchanged(ImageSet, Lambda(x, 1), empty)  # issue #17471
    squares = ImageSet(Lambda(x, x**2), S.Naturals)
    assert 4 in squares
    assert 5 not in squares
    assert FiniteSet(*range(10)).intersect(squares) == FiniteSet(1, 4, 9)

    assert 16 not in squares.intersect(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 (1, 2) not in harmonics

    assert harmonics.is_iterable

    assert imageset(x, -x, Interval(0, 1)) == Interval(-1, 0)

    assert ImageSet(Lambda(x, x**2), Interval(0, 2)).doit() == Interval(0, 4)
    assert ImageSet(Lambda((x, y), 2 * x), {4}, {3}).doit() == FiniteSet(8)
    assert (ImageSet(Lambda((x, y), x + y), {1, 2, 3},
                     {10, 20, 30}).doit() == FiniteSet(11, 12, 13, 21, 22, 23,
                                                       31, 32, 33))

    c = Interval(1, 3) * Interval(1, 3)
    assert Tuple(2, 6) in ImageSet(Lambda(((x, y), ), (x, 2 * y)), c)
    assert Tuple(2, S.Half) in ImageSet(Lambda(((x, y), ), (x, 1 / y)), c)
    assert Tuple(2, -2) not in ImageSet(Lambda(((x, y), ), (x, y**2)), c)
    assert Tuple(2, -2) in ImageSet(Lambda(((x, y), ), (x, -2)), c)
    c3 = ProductSet(Interval(3, 7), Interval(8, 11), Interval(5, 9))
    assert Tuple(8, 3, 9) in ImageSet(Lambda(((t, y, x), ), (y, t, x)), c3)
    assert Tuple(Rational(1, 8), 3,
                 9) in ImageSet(Lambda(((t, y, x), ), (1 / y, t, x)), c3)
    assert 2 / pi not in ImageSet(Lambda(((x, y), ), 2 / x), c)
    assert 2 / S(100) not in ImageSet(Lambda(((x, y), ), 2 / x), c)
    assert Rational(2, 3) in ImageSet(Lambda(((x, y), ), 2 / x), c)

    S1 = imageset(lambda x, y: x + y, S.Integers, S.Naturals)
    assert S1.base_pset == ProductSet(S.Integers, S.Naturals)
    assert S1.base_sets == (S.Integers, S.Naturals)

    # Passing a set instead of a FiniteSet shouldn't raise
    assert unchanged(ImageSet, Lambda(x, x**2), {1, 2, 3})

    S2 = ImageSet(Lambda(((x, y), ), x + y), {(1, 2), (3, 4)})
    assert 3 in S2.doit()
    # FIXME: This doesn't yet work:
    #assert 3 in S2
    assert S2._contains(3) is None

    raises(TypeError, lambda: ImageSet(Lambda(x, x**2), 1))
Esempio n. 20
0
def test_ImageSet():
    raises(ValueError, lambda: ImageSet(x, S.Integers))
    assert ImageSet(Lambda(x, 1), S.Integers) == FiniteSet(1)
    assert ImageSet(Lambda(x, y), S.Integers) == {y}
    assert ImageSet(Lambda(x, 1), S.EmptySet) == S.EmptySet
    empty = Intersection(FiniteSet(log(2) / pi), S.Integers)
    assert unchanged(ImageSet, Lambda(x, 1), empty)  # issue #17471
    squares = ImageSet(Lambda(x, x**2), S.Naturals)
    assert 4 in squares
    assert 5 not in squares
    assert FiniteSet(*range(10)).intersect(squares) == FiniteSet(1, 4, 9)

    assert 16 not in squares.intersect(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 (1, 2) not in harmonics

    assert harmonics.is_iterable

    assert imageset(x, -x, Interval(0, 1)) == Interval(-1, 0)

    assert ImageSet(Lambda(x, x**2), Interval(0, 2)).doit() == Interval(0, 4)

    c = ComplexRegion(Interval(1, 3) * Interval(1, 3))
    assert Tuple(2, 6) in ImageSet(Lambda((x, y), (x, 2 * y)), c)
    assert Tuple(2, S.Half) in ImageSet(Lambda((x, y), (x, 1 / y)), c)
    assert Tuple(2, -2) not in ImageSet(Lambda((x, y), (x, y**2)), c)
    assert Tuple(2, -2) in ImageSet(Lambda((x, y), (x, -2)), c)
    c3 = Interval(3, 7) * Interval(8, 11) * Interval(5, 9)
    assert Tuple(8, 3, 9) in ImageSet(Lambda((t, y, x), (y, t, x)), c3)
    assert Tuple(S(1) / 8, 3, 9) in ImageSet(Lambda((t, y, x), (1 / y, t, x)),
                                             c3)
    assert 2 / pi not in ImageSet(Lambda((x, y), 2 / x), c)
    assert 2 / S(100) not in ImageSet(Lambda((x, y), 2 / x), c)
    assert 2 / S(3) in ImageSet(Lambda((x, y), 2 / x), c)

    assert imageset(lambda x, y: x + y, S.Integers,
                    S.Naturals).base_set == ProductSet(S.Integers, S.Naturals)
Esempio n. 21
0
def test_imageset_intersection():
    n = Dummy()
    s = ImageSet(Lambda(n, -I*(I*(2*pi*n - pi/4) +
        log(Abs(sqrt(-I))))), S.Integers)
    assert s.intersect(S.Reals) == ImageSet(
        Lambda(n, 2*pi*n + pi*Rational(7, 4)), S.Integers)
Esempio n. 22
0
def test_imageset_intersect_diophantine():
    from sympy.abc import m, n
    # Check that same lambda variable for both ImageSets is handled correctly
    img1 = ImageSet(Lambda(n, 2 * n + 1), S.Integers)
    img2 = ImageSet(Lambda(n, 4 * n + 1), S.Integers)
    assert img1.intersect(img2) == img2
    # Empty solution set returned by diophantine:
    assert ImageSet(Lambda(n, 2 * n), S.Integers).intersect(
        ImageSet(Lambda(n, 2 * n + 1), S.Integers)) == S.EmptySet
    # Check intersection with S.Integers:
    assert ImageSet(Lambda(n, 9 / n + 20 * n / 3),
                    S.Integers).intersect(S.Integers) == FiniteSet(
                        -61, -23, 23, 61)
    # Single solution (2, 3) for diophantine solution:
    assert ImageSet(Lambda(n, (n - 2)**2), S.Integers).intersect(
        ImageSet(Lambda(n, -(n - 3)**2), S.Integers)) == FiniteSet(0)
    # Single parametric solution for diophantine solution:
    assert ImageSet(Lambda(n, n**2 + 5), S.Integers).intersect(
        ImageSet(Lambda(m, 2 * m),
                 S.Integers)) == ImageSet(Lambda(n, 4 * n**2 + 4 * n + 6),
                                          S.Integers)
    # 4 non-parametric solution couples for dioph. equation:
    assert ImageSet(Lambda(n, n**2 - 9), S.Integers).intersect(
        ImageSet(Lambda(m, -m**2), S.Integers)) == FiniteSet(-9, 0)
    # Double parametric solution for diophantine solution:
    assert ImageSet(Lambda(m, m**2 + 40), S.Integers).intersect(
        ImageSet(Lambda(n, 41 * n), S.Integers)) == Intersection(
            ImageSet(Lambda(m, m**2 + 40), S.Integers),
            ImageSet(Lambda(n, 41 * n), S.Integers))
    # Check that diophantine returns *all* (8) solutions (permute=True)
    assert ImageSet(Lambda(n, n**4 - 2**4), S.Integers).intersect(
        ImageSet(Lambda(m, -m**4 + 3**4), S.Integers)) == FiniteSet(0, 65)
    assert ImageSet(Lambda(n, pi / 12 + n * 5 * pi / 12),
                    S.Integers).intersect(
                        ImageSet(Lambda(n, 7 * pi / 12 + n * 11 * pi / 12),
                                 S.Integers)) == ImageSet(
                                     Lambda(n, 55 * pi * n / 12 + 17 * pi / 4),
                                     S.Integers)
    # TypeError raised by diophantine (#18081)
    assert ImageSet(Lambda(n, n*log(2)), S.Integers).intersection(S.Integers) \
            == Intersection(ImageSet(Lambda(n, n*log(2)), S.Integers), S.Integers)
    # NotImplementedError raised by diophantine (no solver for cubic_thue)
    assert ImageSet(Lambda(n, n**3 + 1), S.Integers).intersect(
        ImageSet(Lambda(n, n**3), S.Integers)) == Intersection(
            ImageSet(Lambda(n, n**3 + 1), S.Integers),
            ImageSet(Lambda(n, n**3), S.Integers))
Esempio n. 23
0
from sympy import Symbol, S, pi, Dummy, Lambda
from sympy.sets.sets import FiniteSet, Interval
from sympy.sets.fancysets import ImageSet
x = Symbol('x')
N = S.Naturals
squares = ImageSet(Lambda(x, x**2), N)  # {x**2 for x in N}
print 4 in squares
print squares
print FiniteSet(0, 1, 2, 3, 4, 5, 6, 7, 9, 10).intersect(squares)
print FiniteSet(9, 16, 25).intersect(squares)
Esempio n. 24
0
def test_issue_16871b():
    assert ImageSet(Lambda(x, x - 3), S.Integers).is_subset(S.Integers)
Esempio n. 25
0
def _set_pow(x, y):  # noqa:F811
    return ImageSet(Lambda((_x, _y), (_x**_y)), x, y)
Esempio n. 26
0
 def _eval_imageset(self, f):
     from sympy.sets.fancysets import ImageSet
     return ImageSet(f, self)
Esempio n. 27
0
def test_no_mod_on_imaginary():
    assert imageset(Lambda(x, 2*x + 3*I), S.Integers
        ) == ImageSet(Lambda(x, 2*x + I), S.Integers)
Esempio n. 28
0
def test_fun():
    assert (FiniteSet(
        *ImageSet(Lambda(x, sin(pi * x / 4)), Range(-10, 11))) == FiniteSet(
            -1, -sqrt(2) / 2, 0,
            sqrt(2) / 2, 1))
Esempio n. 29
0
def _(x, y):
    return ImageSet(Lambda((_x, _y), (_x**_y)), x, y)
Esempio n. 30
0
def test_ImageSet():
    assert ImageSet(Lambda(x, 1), S.Integers) == FiniteSet(1)
    assert ImageSet(Lambda(x, y), S.Integers) == FiniteSet(y)
    squares = ImageSet(Lambda(x, x**2), S.Naturals)
    assert 4 in squares
    assert 5 not in squares
    assert FiniteSet(*range(10)).intersect(squares) == FiniteSet(1, 4, 9)

    assert 16 not in squares.intersect(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

    c = ComplexRegion(Interval(1, 3) * Interval(1, 3))
    assert Tuple(2, 6) in ImageSet(Lambda((x, y), (x, 2 * y)), c)
    assert Tuple(2, S.Half) in ImageSet(Lambda((x, y), (x, 1 / y)), c)
    assert Tuple(2, -2) not in ImageSet(Lambda((x, y), (x, y**2)), c)
    assert Tuple(2, -2) in ImageSet(Lambda((x, y), (x, -2)), c)
    c3 = Interval(3, 7) * Interval(8, 11) * Interval(5, 9)
    assert Tuple(8, 3, 9) in ImageSet(Lambda((t, y, x), (y, t, x)), c3)
    assert Tuple(S(1) / 8, 3, 9) in ImageSet(Lambda((t, y, x), (1 / y, t, x)),
                                             c3)
    assert 2 / pi not in ImageSet(Lambda((x, y), 2 / x), c)
    assert 2 / S(100) not in ImageSet(Lambda((x, y), 2 / x), c)
    assert 2 / S(3) in ImageSet(Lambda((x, y), 2 / x), c)
Esempio n. 31
0
def test_issue_9543():
    assert ImageSet(Lambda(x, x**2), S.Naturals).is_subset(S.Reals)
Esempio n. 32
0
def test_issue_16871():
    assert ImageSet(Lambda(x, x), FiniteSet(1)) == {1}
    assert ImageSet(Lambda(x, x - 3), S.Integers).intersection(
        S.Integers) is S.Integers
                   latex)
from sympy.sets.sets import FiniteSet, Interval
from sympy.sets.fancysets import ImageSet

t = Symbol('t')
T = Symbol(r'\mathbb{T}')
# Iterables
print(latex(T))
TS0 = tsc(S.EmptySet, latex(T) + '=' + latex(S.EmptySet))
TS1 = tsc(Range(-2, 1), latex(T) + '=' + latex(Range(-2, 1)))
TS2 = tsc(Range(-oo, 5, 5), latex(T) + '=' + latex(Range(-oo, 5, 5)))
TS3 = tsc(Range(0, oo, 7), latex(T) + '=' + latex(Range(0, oo, 7)))
TS4 = tsc(S.Naturals, latex(T) + '=' + latex(S.Naturals))
TS5 = tsc(S.Naturals0, latex(T) + '=' + latex(S.Naturals0))
TS6 = tsc(S.Integers, latex(T) + '=' + latex(S.Integers))
TS7 = tsc(ImageSet(Lambda(t, -t), S.Naturals),
          latex(T) + '=' + latex(ImageSet(Lambda(t, -t), S.Naturals)))
# TODO: Create an instance of rational numbers in some subset like Interval(0,1s).
# TODO: Recorrer las fracciones de la siguiente manera:
# https://mathoverflow.net/questions/200656/is-there-a-natural-bijection-from-mathbbn-to-mathbbq

# Non-interables

TS9 = tsc(S.Reals, latex(T) + '=' + latex(S.Reals))  # Means Interval(-oo,+oo).
TS10 = tsc(S.UniversalSet, latex(T) + '=' + latex(S.UniversalSet))
# print(list(TS1.ts))

# TODO: Implementar raise
try:
    iterator = iter(TS9.ts)
except TypeError: