Esempio n. 1
0
def test_subs_CondSet_tebr():
    with warns_deprecated_sympy():
        assert ConditionSet((x, y), {x + 1, x + y}, S.Reals) == \
            ConditionSet((x, y), Eq(x + 1, 0) & Eq(x + y, 0), S.Reals)

    c = ConditionSet((x, y), Eq(x + 1, 0) & Eq(x + y, 0), S.Reals)
    assert c.subs(x, z) == c
def test_free_symbols():
    assert ConditionSet(x, Eq(y, 0), FiniteSet(z)
        ).free_symbols == {y, z}
    assert ConditionSet(x, Eq(x, 0), FiniteSet(z)
        ).free_symbols == {z}
    assert ConditionSet(x, Eq(x, 0), FiniteSet(x, z)
        ).free_symbols == {x, z}
Esempio n. 3
0
def test_free_symbols():
    assert ConditionSet(x, Eq(y, 0), FiniteSet(z)).free_symbols == {y, z}
    assert ConditionSet(x, Eq(x, 0), FiniteSet(z)).free_symbols == {z}
    assert ConditionSet(x, Eq(x, 0), FiniteSet(x, z)).free_symbols == {x, z}
    assert ConditionSet(x, Eq(x, 0),
                        ImageSet(Lambda(y, y**2),
                                 S.Integers)).free_symbols == set()
Esempio n. 4
0
def test_failing_contains():
    # XXX This may have to return unevaluated Contains object
    # because 1/0 should not be defined for 1 and 0 in the context of
    # reals, but there is a nonsensical evaluation to ComplexInfinity
    # and the comparison is giving an error.
    assert ConditionSet(x, 1/x >= 0, S.Reals).contains(0) == \
        Contains(0, ConditionSet(x, 1/x >= 0, S.Reals), evaluate=False)
Esempio n. 5
0
def test_dummy_eq():
    C = ConditionSet
    I = S.Integers
    c = C(x, x < 1, I)
    assert c.dummy_eq(C(y, y < 1, I))
    assert c.dummy_eq(1) == False
    assert c.dummy_eq(C(x, x < 1, S.Reals)) == False

    c1 = ConditionSet((x, y), Eq(x + 1, 0) & Eq(x + y, 0), S.Reals)
    c2 = ConditionSet((x, y), Eq(x + 1, 0) & Eq(x + y, 0), S.Reals)
    c3 = ConditionSet((x, y), Eq(x + 1, 0) & Eq(x + y, 0), S.Complexes)
    assert c1.dummy_eq(c2)
    assert c1.dummy_eq(c3) is False
    assert c.dummy_eq(c1) is False
    assert c1.dummy_eq(c) is False

    # issue 19496
    m = Symbol('m')
    n = Symbol('n')
    a = Symbol('a')
    d1 = ImageSet(Lambda(m, m * pi), S.Integers)
    d2 = ImageSet(Lambda(n, n * pi), S.Integers)
    c1 = ConditionSet(x, Ne(a, 0), d1)
    c2 = ConditionSet(x, Ne(a, 0), d2)
    assert c1.dummy_eq(c2)
Esempio n. 6
0
def test_CondSet():
    sin_sols_principal = ConditionSet(Lambda(x, Eq(sin(x), 0)),
                                      Interval(0, 2 * pi, False, True))
    assert pi in sin_sols_principal
    assert pi / 2 not in sin_sols_principal
    assert 3 * pi not in sin_sols_principal
    assert 5 in ConditionSet(Lambda(x, x**2 > 4), S.Reals)
    assert 1 not in ConditionSet(Lambda(x, x**2 > 4), S.Reals)
Esempio n. 7
0
def test_bound_symbols():
    assert ConditionSet(x, Eq(y, 0), FiniteSet(z)).bound_symbols == {x}
    assert ConditionSet(x, Eq(x, 0), FiniteSet(x, y)).bound_symbols == {x}
    assert ConditionSet(x, x < 10, ImageSet(Lambda(y, y**2),
                                            S.Integers)).bound_symbols == {x}
    assert ConditionSet(x, x < 10,
                        ConditionSet(y, y > 1,
                                     S.Integers)).bound_symbols == {x}
Esempio n. 8
0
def test_CondSet_intersect():
    input_conditionset = ConditionSet(x, x**2 > 4,
                                      Interval(1, 4, False, False))
    other_domain = Interval(0, 3, False, False)
    output_conditionset = ConditionSet(x, x**2 > 4,
                                       Interval(1, 3, False, False))
    assert Intersection(input_conditionset,
                        other_domain) == output_conditionset
Esempio n. 9
0
def test_CondSet():
    sin_sols_principal = ConditionSet(x, Eq(sin(x), 0),
                                      Interval(0, 2 * pi, False, True))
    assert pi in sin_sols_principal
    assert pi / 2 not in sin_sols_principal
    assert 3 * pi not in sin_sols_principal
    assert 5 in ConditionSet(x, x**2 > 4, S.Reals)
    assert 1 not in ConditionSet(x, x**2 > 4, S.Reals)
    # in this case, 0 is not part of the base set so
    # it can't be in any subset selected by the condition
    assert 0 not in ConditionSet(x, y > 5, Interval(1, 7))
    # since 'in' requires a true/false, the following raises
    # an error because the given value provides no information
    # for the condition to evaluate (since the condition does
    # not depend on the dummy symbol): the result is `y > 5`.
    # In this case, ConditionSet is just acting like
    # Piecewise((Interval(1, 7), y > 5), (S.EmptySet, True)).
    raises(TypeError, lambda: 6 in ConditionSet(x, y > 5, Interval(1, 7)))

    assert isinstance(ConditionSet(x, x < 1, {x, y}).base_set, FiniteSet)
    raises(TypeError, lambda: ConditionSet(x, x + 1, {x, y}))
    raises(TypeError, lambda: ConditionSet(x, x, 1))

    I = S.Integers
    C = ConditionSet
    assert C(x, x < 1, C(x, x < 2, I)) == C(x, (x < 1) & (x < 2), I)
    assert C(y, y < 1, C(x, y < 2, I)) == C(x, (x < 1) & (y < 2), I)
    assert C(y, y < 1, C(x, x < 2, I)) == C(y, (y < 1) & (y < 2), I)
    assert C(y, y < 1, C(x, y < x, I)) == C(x, (x < 1) & (y < x), I)
    assert C(y, x < 1, C(x, y < x, I)) == C(L, (x < 1) & (y < L), I)
    c = C(y, x < 1, C(x, L < y, I))
    assert c == C(c.sym, (L < y) & (x < 1), I)
    assert c.sym not in (x, y, L)
    c = C(y, x < 1, C(x, y < x, FiniteSet(L)))
    assert c == C(L, And(x < 1, y < L), FiniteSet(L))
Esempio n. 10
0
def test_conditionset():
    assert solveset(Eq(sin(x)**2 + cos(x)**2, 1), x, domain=S.Reals) == \
        ConditionSet(x, True, S.Reals)

    assert solveset(Eq(x**2 + x*sin(x), 1), x, domain=S.Reals) == \
        ConditionSet(x, Eq(x*(x + sin(x)) - 1, 0), S.Reals)

    assert solveset(Eq(sin(Abs(x)), x), x, domain=S.Reals) == \
        ConditionSet(x, Eq(-x + sin(Abs(x)), 0), Interval(-oo, oo))

    assert solveset(Eq(-I*(exp(I*x) - exp(-I*x))/2, 1), x) == \
        imageset(Lambda(n, 2*n*pi + pi/2), S.Integers)

    assert solveset(x + sin(x) > 1, x, domain=S.Reals) == \
        ConditionSet(x, x + sin(x) > 1, S.Reals)
Esempio n. 11
0
def test_solve_sqrt_3():
    R = Symbol('R')
    eq = sqrt(2) * R * sqrt(1 /
                            (R + 1)) + (R + 1) * (sqrt(2) * sqrt(1 /
                                                                 (R + 1)) - 1)
    sol = solveset_complex(eq, R)

    assert sol == FiniteSet(*[
        S(5) / 3 + 4 * sqrt(10) * cos(atan(3 * sqrt(111) / 251) / 3) /
        3, -sqrt(10) * cos(atan(3 * sqrt(111) / 251) / 3) / 3 +
        40 * re(1 / ((-S(1) / 2 - sqrt(3) * I / 2) *
                     (S(251) / 27 + sqrt(111) * I / 9)**(S(1) / 3))) / 9 +
        sqrt(30) * sin(atan(3 * sqrt(111) / 251) / 3) / 3 + S(5) / 3 + I *
        (-sqrt(30) * cos(atan(3 * sqrt(111) / 251) / 3) / 3 -
         sqrt(10) * sin(atan(3 * sqrt(111) / 251) / 3) / 3 + 40 * im(1 / (
             (-S(1) / 2 - sqrt(3) * I / 2) *
             (S(251) / 27 + sqrt(111) * I / 9)**(S(1) / 3))) / 9)
    ])

    # the number of real roots will depend on the value of m: for m=1 there are 4
    # and for m=-1 there are none.
    eq = -sqrt((m - q)**2 + (-m / (2 * q) + S(1) / 2)**2) + sqrt(
        (-m**2 / 2 - sqrt(4 * m**4 - 4 * m**2 + 8 * m + 1) / 4 - S(1) / 4)**2 +
        (m**2 / 2 - m - sqrt(4 * m**4 - 4 * m**2 + 8 * m + 1) / 4 -
         S(1) / 4)**2)
    unsolved_object = ConditionSet(
        q,
        Eq((-2 * sqrt(4 * q**2 * (m - q)**2 + (-m + q)**2) + sqrt(
            (-2 * m**2 - sqrt(4 * m**4 - 4 * m**2 + 8 * m + 1) - 1)**2 +
            (2 * m**2 - 4 * m - sqrt(4 * m**4 - 4 * m**2 + 8 * m + 1) - 1)**2)
            * Abs(q)) / Abs(q), 0), S.Reals)
    assert solveset_real(eq, q) == unsolved_object
Esempio n. 12
0
def _solve_abs(f, symbol, domain):
    """ Helper function to solve equation involving absolute value function """
    if not domain.is_subset(S.Reals):
        raise ValueError(
            filldedent('''
            Absolute values cannot be inverted in the
            complex domain.'''))
    p, q, r = Wild('p'), Wild('q'), Wild('r')
    pattern_match = f.match(p * Abs(q) + r) or {}
    if not pattern_match.get(p, S.Zero).is_zero:
        f_p, f_q, f_r = pattern_match[p], pattern_match[q], pattern_match[r]
        q_pos_cond = solve_univariate_inequality(f_q >= 0,
                                                 symbol,
                                                 relational=False)
        q_neg_cond = solve_univariate_inequality(f_q < 0,
                                                 symbol,
                                                 relational=False)

        sols_q_pos = solveset_real(f_p * f_q + f_r,
                                   symbol).intersect(q_pos_cond)
        sols_q_neg = solveset_real(f_p * (-f_q) + f_r,
                                   symbol).intersect(q_neg_cond)
        return Union(sols_q_pos, sols_q_neg)
    else:
        return ConditionSet(symbol, Eq(f, 0), domain)
def test_dummy_eq():
    C = ConditionSet
    I = S.Integers
    c = C(x, x < 1, I)
    assert c.dummy_eq(C(y, y < 1, I))
    assert c.dummy_eq(1) == False
    assert c.dummy_eq(C(x, x < 1, S.Reals)) == False
    raises(ValueError, lambda: c.dummy_eq(C(x, x < 1, S.Reals), z))

    c1 = ConditionSet((x, y), Eq(x + 1, 0) & Eq(x + y, 0), S.Reals)
    c2 = ConditionSet((x, y), Eq(x + 1, 0) & Eq(x + y, 0), S.Reals)
    c3 = ConditionSet((x, y), Eq(x + 1, 0) & Eq(x + y, 0), S.Complexes)
    assert c1.dummy_eq(c2)
    assert c1.dummy_eq(c3) is False
    assert c.dummy_eq(c1) is False
    assert c1.dummy_eq(c) is False
Esempio n. 14
0
def test_flatten():
    """Tests whether there is basic denesting functionality"""
    inner = ConditionSet(x, sin(x) + x > 0)
    outer = ConditionSet(x, Contains(x, inner), S.Reals)
    assert outer == ConditionSet(x, sin(x) + x > 0, S.Reals)

    inner = ConditionSet(y, sin(y) + y > 0)
    outer = ConditionSet(x, Contains(y, inner), S.Reals)
    assert outer != ConditionSet(x, sin(x) + x > 0, S.Reals)

    inner = ConditionSet(x, sin(x) + x > 0).intersect(Interval(-1, 1))
    outer = ConditionSet(x, Contains(x, inner), S.Reals)
    assert outer == ConditionSet(x, sin(x) + x > 0, Interval(-1, 1))
Esempio n. 15
0
def test_dummy_eq():
    C = ConditionSet
    I = S.Integers
    c = C(x, x < 1, I)
    assert c.dummy_eq(C(y, y < 1, I))
    assert c.dummy_eq(1) == False
    assert c.dummy_eq(C(x, x < 1, S.Reals)) == False
    raises(ValueError, lambda: c.dummy_eq(C(x, x < 1, S.Reals), z))

    # to eventually be removed
    c1 = ConditionSet((x, y), {x + 1, x + y}, S.Reals)
    c2 = ConditionSet((x, y), {x + 1, x + y}, S.Reals)
    c3 = ConditionSet((x, y), {x + 1, x + y}, S.Complexes)
    assert c1.dummy_eq(c2)
    assert c1.dummy_eq(c3) is False
    assert c.dummy_eq(c1) is False
    assert c1.dummy_eq(c) is False
Esempio n. 16
0
def test_as_dummy():
    _0, _1 = symbols('_0 _1')
    assert ConditionSet(x, x < 1, Interval(y, oo)
        ).as_dummy() == ConditionSet(_0, _0 < 1, Interval(y, oo))
    assert ConditionSet(x, x < 1, Interval(x, oo)
        ).as_dummy() == ConditionSet(_0, _0 < 1, Interval(x, oo))
    assert ConditionSet(x, x < 1, ImageSet(Lambda(y, y**2), S.Integers)
        ).as_dummy() == ConditionSet(
            _0, _0 < 1, ImageSet(Lambda(_0, _0**2), S.Integers))
    e = ConditionSet((x, y), x <= y, S.Reals**2)
    assert e.bound_symbols == [x, y]
    assert e.as_dummy() == ConditionSet((_0, _1), _0 <= _1, S.Reals**2)
    assert e.as_dummy() == ConditionSet((y, x), y <= x, S.Reals**2
        ).as_dummy()
Esempio n. 17
0
def test_improve_coverage():
    from sympy.solvers.solveset import _has_rational_power
    x = Symbol('x')
    y = exp(x+1/x**2)
    solution = solveset(y**2+y, x, S.Reals)
    unsolved_object = ConditionSet(x, Eq((exp((x**3 + 1)/x**2) + 1)*exp((x**3 + 1)/x**2), 0), S.Reals)
    assert solution == unsolved_object

    assert _has_rational_power(sin(x)*exp(x) + 1, x) == (False, S.One)
    assert _has_rational_power((sin(x)**2)*(exp(x) + 1)**3, x) == (False, S.One)
def test_simplified_FiniteSet_in_CondSet():
    assert ConditionSet(x, And(x < 1, x > -3), FiniteSet(0, 1, 2)) == FiniteSet(0)
    assert ConditionSet(x, x < 0, FiniteSet(0, 1, 2)) == EmptySet()
    assert ConditionSet(x, And(x < -3), EmptySet()) == EmptySet()
    y = Symbol('y')
    assert (ConditionSet(x, And(x > 0), FiniteSet(-1, 0, 1, y)) ==
        Union(FiniteSet(1), ConditionSet(x, And(x > 0), FiniteSet(y))))
    assert (ConditionSet(x, Eq(Mod(x, 3), 1), FiniteSet(1, 4, 2, y)) ==
        Union(FiniteSet(1, 4), ConditionSet(x, Eq(Mod(x, 3), 1), FiniteSet(y))))
Esempio n. 19
0
def _solve_real_trig(f, symbol):
    """ Helper to solve trigonometric equations """
    f = trigsimp(f)
    f = f.rewrite(exp)
    f = together(f)
    g, h = fraction(f)
    y = Dummy('y')
    g, h = g.expand(), h.expand()
    g, h = g.subs(exp(I * symbol), y), h.subs(exp(I * symbol), y)
    if g.has(symbol) or h.has(symbol):
        return ConditionSet(symbol, Eq(f, 0), S.Reals)

    solns = solveset_complex(g, y) - solveset_complex(h, y)

    if isinstance(solns, FiniteSet):
        return Union(
            *[invert_complex(exp(I * symbol), s, symbol)[1] for s in solns])
    elif solns is S.EmptySet:
        return S.EmptySet
    else:
        return ConditionSet(symbol, Eq(f, 0), S.Reals)
Esempio n. 20
0
def _solve_as_poly(f, symbol, solveset_solver, invert_func):
    """
    Solve the equation using polynomial techniques if it already is a
    polynomial equation or, with a change of variables, can be made so.
    """
    result = None
    if f.is_polynomial(symbol):

        solns = roots(f, symbol, cubics=True, quartics=True,
                      quintics=True, domain='EX')
        num_roots = sum(solns.values())
        if degree(f, symbol) <= num_roots:
            result = FiniteSet(*solns.keys())
        else:
            poly = Poly(f, symbol)
            solns = poly.all_roots()
            if poly.degree() <= len(solns):
                result = FiniteSet(*solns)
            else:
                result = ConditionSet(Lambda(symbol, Eq(f, 0)), S.Complexes)
    else:
        poly = Poly(f)
        if poly is None:
            result = ConditionSet(Lambda(symbol, Eq(f, 0)), S.Complexes)
        gens = [g for g in poly.gens if g.has(symbol)]

        if len(gens) == 1:
            poly = Poly(poly, gens[0])
            gen = poly.gen
            deg = poly.degree()
            poly = Poly(poly.as_expr(), poly.gen, composite=True)
            poly_solns = FiniteSet(*roots(poly, cubics=True, quartics=True,
                                          quintics=True).keys())

            if len(poly_solns) < deg:
                result = ConditionSet(Lambda(symbol, Eq(f, 0)), S.Complexes)

            if gen != symbol:
                y = Dummy('y')
                lhs, rhs_s = invert_func(gen, y, symbol)
                if lhs is symbol:
                    result = Union(*[rhs_s.subs(y, s) for s in poly_solns])
                else:
                    result = ConditionSet(Lambda(symbol, Eq(f, 0)), S.Complexes)
        else:
            result = ConditionSet(Lambda(symbol, Eq(f, 0)), S.Complexes)

    if result is not None:
        if isinstance(result, FiniteSet):
            # this is to simplify solutions like -sqrt(-I) to sqrt(2)/2
            # - sqrt(2)*I/2. We are not expanding for solution with free
            # variables because that makes the solution more complicated. For
            # example expand_complex(a) returns re(a) + I*im(a)
            if all([s.free_symbols == set() and not isinstance(s, RootOf)
                    for s in result]):
                s = Dummy('s')
                result = imageset(Lambda(s, expand_complex(s)), result)
        return result
    else:
        return ConditionSet(Lambda(symbol, Eq(f, 0)), S.Complexes)
Esempio n. 21
0
def test_contains():
    assert 6 in ConditionSet(x, x > 5, Interval(1, 7))
    assert (8 in ConditionSet(x, y > 5, Interval(1, 7))) is False
    # `in` should give True or False; in this case there is not
    # enough information for that result
    raises(TypeError, lambda: 6 in ConditionSet(x, y > 5, Interval(1, 7)))
    assert ConditionSet(x, y > 5, Interval(1, 7)).contains(6) == (y > 5)
    assert ConditionSet(x, y > 5, Interval(1, 7)).contains(8) is S.false
    assert ConditionSet(x, y > 5, Interval(1, 7)).contains(w) == And(
        S.One <= w, w <= 7, y > 5)
    assert 0 not in ConditionSet(x, 1 / x >= 0, S.Reals)
Esempio n. 22
0
def test_flatten():
    """Tests whether there is basic denesting functionality"""
    inner = ConditionSet(x, sin(x) + x > 0)
    outer = ConditionSet(x, Contains(x, inner), S.Reals)
    assert outer == ConditionSet(x, sin(x) + x > 0, S.Reals)

    inner = ConditionSet(y, sin(y) + y > 0)
    outer = ConditionSet(x, Contains(y, inner), S.Reals)
    assert outer != ConditionSet(x, sin(x) + x > 0, S.Reals)

    inner = ConditionSet(x, sin(x) + x > 0).intersect(Interval(-1, 1))
    outer = ConditionSet(x, Contains(x, inner), S.Reals)
    assert outer == ConditionSet(x, sin(x) + x > 0, Interval(-1, 1))

    def test_duplicate():
        from sympy.core.function import BadSignatureError
        # test coverage for line 95 in conditionset.py, check for duplicates in symbols
        dup = symbols('a,a')
        raises(BadSignatureError, lambda: ConditionSet(dup, x < 0))
Esempio n. 23
0
def test_as_dummy():
    _0 = Symbol('_0')
    assert ConditionSet(x, x < 1, Interval(y, oo)).as_dummy() == ConditionSet(
        _0, _0 < 1, Interval(y, oo))
    assert ConditionSet(x, x < 1, Interval(x, oo)).as_dummy() == ConditionSet(
        _0, _0 < 1, Interval(x, oo))
    assert ConditionSet(x, x < 1,
                        ImageSet(Lambda(y, y**2),
                                 S.Integers)).as_dummy() == ConditionSet(
                                     _0, _0 < 1,
                                     ImageSet(Lambda(_0, _0**2), S.Integers))
Esempio n. 24
0
def _solve_abs(f, symbol):
    """ Helper function to solve equation involving absolute value function """
    p, q, r = Wild('p'), Wild('q'), Wild('r')
    pattern_match = f.match(p*Abs(q) + r) or {}
    if not pattern_match.get(p, S.Zero).is_zero:
        f_p, f_q, f_r = pattern_match[p], pattern_match[q], pattern_match[r]
        q_pos_cond = solve_univariate_inequality(f_q >= 0, symbol,
                                                 relational=False)
        q_neg_cond = solve_univariate_inequality(f_q < 0, symbol,
                                                 relational=False)

        sols_q_pos = solveset_real(f_p*f_q + f_r,
                                           symbol).intersect(q_pos_cond)
        sols_q_neg = solveset_real(f_p*(-f_q) + f_r,
                                           symbol).intersect(q_neg_cond)
        return Union(sols_q_pos, sols_q_neg)
    else:
        return ConditionSet(symbol, Eq(f, 0), S.Complexes)
Esempio n. 25
0
def test_solve_abs():
    assert solveset_real(Abs(x) - 2, x) == FiniteSet(-2, 2)
    assert solveset_real(Abs(x + 3) - 2*Abs(x - 3), x) == \
        FiniteSet(1, 9)
    assert solveset_real(2*Abs(x) - Abs(x - 1), x) == \
        FiniteSet(-1, Rational(1, 3))

    assert solveset_real(Abs(x - 7) - 8, x) == FiniteSet(-S(1), S(15))

    # issue 9565. Note: solveset_real does not solve this as it is
    # solveset's job to handle Relationals
    assert solveset(Abs((x - 1)/(x - 5)) <= S(1)/3, domain=S.Reals
        ) == Interval(-1, 2)

    # issue #10069
    assert solveset_real(abs(1/(x - 1)) - 1 > 0, x) == \
        ConditionSet(x, Eq((1 - Abs(x - 1))/Abs(x - 1) > 0, 0),
            S.Reals)
    assert solveset(abs(1/(x - 1)) - 1 > 0, x, domain=S.Reals
        ) == Union(Interval.open(0, 1), Interval.open(1, 2))
Esempio n. 26
0
def test_solve_decomposition():
    x = Symbol('x')
    n = Dummy('n')

    f1 = exp(3*x) - 6*exp(2*x) + 11*exp(x) - 6
    f2 = sin(x)**2 - 2*sin(x) + 1
    f3 = sin(x)**2 - sin(x)
    f4 = sin(x + 1)
    f5 = exp(x + 2) - 1
    f6 = 1/log(x)

    s1 = ImageSet(Lambda(n, 2*n*pi), S.Integers)
    s2 = ImageSet(Lambda(n, 2*n*pi + pi), S.Integers)
    s3 = ImageSet(Lambda(n, 2*n*pi + pi/2), S.Integers)
    s4 = ImageSet(Lambda(n, 2*n*pi - 1), S.Integers)
    s5 = ImageSet(Lambda(n, (2*n + 1)*pi - 1), S.Integers)

    assert solve_decomposition(f1, x, S.Reals) == FiniteSet(0, log(2), log(3))
    assert solve_decomposition(f2, x, S.Reals) == s3
    assert solve_decomposition(f3, x, S.Reals) == Union(s1, s2, s3)
    assert solve_decomposition(f4, x, S.Reals) == Union(s4, s5)
    assert solve_decomposition(f5, x, S.Reals) == FiniteSet(-2)
    assert solve_decomposition(f6, x, S.Reals) == ConditionSet(x, Eq(f6, 0), S.Reals)
Esempio n. 27
0
def test_issue_9849():
    assert ConditionSet(x, Eq(x, x), S.Naturals) == S.Naturals
    assert ConditionSet(x, Eq(Abs(sin(x)), -1), S.Naturals) == S.EmptySet
Esempio n. 28
0
def test_issue_10555():
    f = Function('f')
    assert solveset(f(x) - pi/2, x, S.Reals) == \
        ConditionSet(x, Eq(2*f(x) - pi, 0), S.Reals)
Esempio n. 29
0
def test_conditionset_equality():
    ''' Checking equality of different representations of ConditionSet'''
    assert solveset(Eq(tan(x), y), x) == ConditionSet(x, Eq(tan(x), y),
                                                      S.Complexes)
Esempio n. 30
0
def test_subs_CondSet():
    s = FiniteSet(z, y)
    c = ConditionSet(x, x < 2, s)
    # you can only replace sym with a symbol that is not in
    # the free symbols
    assert c.subs(x, 1) == c
    assert c.subs(x, y) == ConditionSet(y, y < 2, s)

    # double subs needed to change dummy if the base set
    # also contains the dummy
    orig = ConditionSet(y, y < 2, s)
    base = orig.subs(y, w)
    and_dummy = base.subs(y, w)
    assert base == ConditionSet(y, y < 2, {w, z})
    assert and_dummy == ConditionSet(w, w < 2, {w, z})

    assert c.subs(x, w) == ConditionSet(w, w < 2, s)
    assert ConditionSet(x, x < y,
                        s).subs(y, w) == ConditionSet(x, x < w, s.subs(y, w))
    # if the user uses assumptions that cause the condition
    # to evaluate, that can't be helped from SymPy's end
    n = Symbol('n', negative=True)
    assert ConditionSet(n, 0 < n, S.Integers) is S.EmptySet
    p = Symbol('p', positive=True)
    assert ConditionSet(n, n < y, S.Integers).subs(n, x) == ConditionSet(
        x, x < y, S.Integers)
    nc = Symbol('nc', commutative=False)
    raises(ValueError, lambda: ConditionSet(x, x < p, S.Integers).subs(x, nc))
    raises(ValueError, lambda: ConditionSet(x, x < p, S.Integers).subs(x, n))
    raises(ValueError, lambda: ConditionSet(x + 1, x < 1, S.Integers))
    raises(ValueError, lambda: ConditionSet(x + 1, x < 1, s))
    assert ConditionSet(n, n < x, Interval(0, oo)).subs(x,
                                                        p) == Interval(0, oo)
    assert ConditionSet(n, n < x, Interval(-oo,
                                           0)).subs(x, p) == Interval(-oo, 0)

    assert ConditionSet(f(x),
                        f(x) < 1,
                        {w, z}).subs(f(x),
                                     y) == ConditionSet(y, y < 1, {w, z})

    # issue 17341
    k = Symbol('k')
    img1 = ImageSet(Lambda(k, 2 * k * pi + asin(y)), S.Integers)
    img2 = ImageSet(Lambda(k, 2 * k * pi + asin(S.One / 3)), S.Integers)
    assert ConditionSet(x, Contains(y, Interval(-1, 1)),
                        img1).subs(y, S.One / 3).dummy_eq(img2)