Exemplo n.º 1
0
def test_reduce_rational_inequalities_real_relational():
    assert reduce_rational_inequalities([], x) is false
    assert reduce_rational_inequalities(
        [[(x**2 + 3*x + 2)/(x**2 - 16) >= 0]], x, relational=False) == \
        Union(Interval.open(-oo, -4), Interval(-2, -1), Interval.open(4, oo))

    assert reduce_rational_inequalities(
        [[((-2*x - 10)*(3 - x))/((x**2 + 5)*(x - 2)**2) < 0]], x,
        relational=False) == \
        Union(Interval.open(-5, 2), Interval.open(2, 3))

    assert reduce_rational_inequalities([[(x + 1)/(x - 5) <= 0]], x,
                                        relational=False) == \
        Interval.Ropen(-1, 5)

    assert reduce_rational_inequalities([[(x**2 + 4*x + 3)/(x - 1) > 0]], x,
                                        relational=False) == \
        Union(Interval.open(-3, -1), Interval.open(1, oo))

    assert reduce_rational_inequalities([[(x**2 - 16)/(x - 1)**2 < 0]], x,
                                        relational=False) == \
        Union(Interval.open(-4, 1), Interval.open(1, 4))

    assert reduce_rational_inequalities([[(3*x + 1)/(x + 4) >= 1]], x,
                                        relational=False) == \
        Union(Interval.open(-oo, -4), Interval.Ropen(Rational(3, 2), oo))

    assert reduce_rational_inequalities([[(x - 8)/x <= 3 - x]], x,
                                        relational=False) == \
        Union(Interval.Lopen(-oo, -2), Interval.Lopen(0, 4))
Exemplo n.º 2
0
def test_reduce_rational_inequalities_real_relational():
    assert reduce_rational_inequalities([], x) is S.false
    assert reduce_rational_inequalities(
        [[(x**2 + 3*x + 2)/(x**2 - 16) >= 0]], x, relational=False) == \
        Union(Interval.open(-oo, -4), Interval(-2, -1), Interval.open(4, oo))

    assert reduce_rational_inequalities(
        [[((-2*x - 10)*(3 - x))/((x**2 + 5)*(x - 2)**2) < 0]], x,
        relational=False) == \
        Union(Interval.open(-5, 2), Interval.open(2, 3))

    assert reduce_rational_inequalities([[(x + 1)/(x - 5) <= 0]], x,
        relational=False) == \
        Interval.Ropen(-1, 5)

    assert reduce_rational_inequalities([[(x**2 + 4*x + 3)/(x - 1) > 0]], x,
        relational=False) == \
        Union(Interval.open(-3, -1), Interval.open(1, oo))

    assert reduce_rational_inequalities([[(x**2 - 16)/(x - 1)**2 < 0]], x,
        relational=False) == \
        Union(Interval.open(-4, 1), Interval.open(1, 4))

    assert reduce_rational_inequalities([[(3*x + 1)/(x + 4) >= 1]], x,
        relational=False) == \
        Union(Interval.open(-oo, -4), Interval.Ropen(Rational(3, 2), oo))

    assert reduce_rational_inequalities([[(x - 8)/x <= 3 - x]], x,
        relational=False) == \
        Union(Interval.Lopen(-oo, -2), Interval.Lopen(0, 4))
Exemplo n.º 3
0
def test_reduce_poly_inequalities_real_interval():
    assert reduce_rational_inequalities(
        [[Eq(x**2, 0)]], x, relational=False) == FiniteSet(0)
    assert reduce_rational_inequalities(
        [[Le(x**2, 0)]], x, relational=False) == FiniteSet(0)
    assert reduce_rational_inequalities(
        [[Lt(x**2, 0)]], x, relational=False) == S.EmptySet
    assert reduce_rational_inequalities(
        [[Ge(x**2, 0)]], x, relational=False) == \
        S.Reals if x.is_extended_real else Interval(-oo, oo)
    assert reduce_rational_inequalities(
        [[Gt(x**2, 0)]], x, relational=False) == \
        FiniteSet(0).complement(S.Reals)
    assert reduce_rational_inequalities(
        [[Ne(x**2, 0)]], x, relational=False) == \
        FiniteSet(0).complement(S.Reals)

    assert reduce_rational_inequalities(
        [[Eq(x**2, 1)]], x, relational=False) == FiniteSet(-1, 1)
    assert reduce_rational_inequalities(
        [[Le(x**2, 1)]], x, relational=False) == Interval(-1, 1)
    assert reduce_rational_inequalities(
        [[Lt(x**2, 1)]], x, relational=False) == Interval(-1, 1, True, True)
    assert reduce_rational_inequalities(
        [[Ge(x**2, 1)]], x, relational=False) == \
        Union(Interval(-oo, -1, True), Interval(1, oo, False, True))
    assert reduce_rational_inequalities(
        [[Gt(x**2, 1)]], x, relational=False) == \
        Interval(-1, 1).complement(S.Reals)
    assert reduce_rational_inequalities(
        [[Ne(x**2, 1)]], x, relational=False) == \
        FiniteSet(-1, 1).complement(S.Reals)
    assert reduce_rational_inequalities([[Eq(
        x**2, 1.0)]], x, relational=False) == FiniteSet(-1.0, 1.0).evalf()
    assert reduce_rational_inequalities(
        [[Le(x**2, 1.0)]], x, relational=False) == Interval(-1.0, 1.0)
    assert reduce_rational_inequalities([[Lt(
        x**2, 1.0)]], x, relational=False) == Interval(-1.0, 1.0, True, True)
    assert reduce_rational_inequalities(
        [[Ge(x**2, 1.0)]], x, relational=False) == \
        Union(Interval(-inf, -1.0, True), Interval(1.0, inf, False, True))
    assert reduce_rational_inequalities(
        [[Gt(x**2, 1.0)]], x, relational=False) == \
        Union(Interval(-inf, -1.0, True, True),
        Interval(1.0, inf, True, True))
    assert reduce_rational_inequalities([[Ne(
        x**2, 1.0)]], x, relational=False) == \
        FiniteSet(-1.0, 1.0).complement(S.Reals)

    s = sqrt(2)

    assert reduce_rational_inequalities([[Lt(
        x**2 - 1, 0), Gt(x**2 - 1, 0)]], x, relational=False) == S.EmptySet
    assert reduce_rational_inequalities([[Le(x**2 - 1, 0), Ge(
        x**2 - 1, 0)]], x, relational=False) == FiniteSet(-1, 1)
    assert reduce_rational_inequalities(
        [[Le(x**2 - 2, 0), Ge(x**2 - 1, 0)]], x, relational=False
    ) == Union(Interval(-s, -1, False, False), Interval(1, s, False, False))
    assert reduce_rational_inequalities(
        [[Le(x**2 - 2, 0), Gt(x**2 - 1, 0)]], x, relational=False
    ) == Union(Interval(-s, -1, False, True), Interval(1, s, True, False))
    assert reduce_rational_inequalities(
        [[Lt(x**2 - 2, 0), Ge(x**2 - 1, 0)]], x, relational=False
    ) == Union(Interval(-s, -1, True, False), Interval(1, s, False, True))
    assert reduce_rational_inequalities(
        [[Lt(x**2 - 2, 0), Gt(x**2 - 1, 0)]], x, relational=False
    ) == Union(Interval(-s, -1, True, True), Interval(1, s, True, True))
    assert reduce_rational_inequalities(
        [[Lt(x**2 - 2, 0), Ne(x**2 - 1, 0)]], x, relational=False
    ) == Union(Interval(-s, -1, True, True), Interval(-1, 1, True, True),
        Interval(1, s, True, True))

    # issue sympy/sympy#10237
    assert reduce_rational_inequalities(
        [[x < oo, x >= 0, -oo < x]], x, relational=False) == Interval(0, oo, False, True)

    assert reduce_rational_inequalities([[Eq((x + 1)/(x**2 - 1),
                                             0)]], x) is S.false
Exemplo n.º 4
0
def test_reduce_poly_inequalities_complex_relational():
    assert reduce_rational_inequalities(
        [[Eq(x**2, 0)]], x, relational=True) == Eq(x, 0)
    assert reduce_rational_inequalities(
        [[Le(x**2, 0)]], x, relational=True) == Eq(x, 0)
    assert reduce_rational_inequalities(
        [[Lt(x**2, 0)]], x, relational=True) is S.false
    assert reduce_rational_inequalities(
        [[Ge(x**2, 0)]], x, relational=True) == And(Lt(-oo, x), Lt(x, oo))
    assert reduce_rational_inequalities(
        [[Gt(x**2, 0)]], x, relational=True) == \
        And(Or(And(Lt(-oo, x), Lt(x, 0)), And(Lt(0, x), Lt(x, oo))))
    assert reduce_rational_inequalities(
        [[Ne(x**2, 0)]], x, relational=True) == \
        And(Or(And(Lt(-oo, x), Lt(x, 0)), And(Lt(0, x), Lt(x, oo))))

    for one in (Integer(1), Float(1.0)):
        inf = one*oo
        assert reduce_rational_inequalities(
            [[Eq(x**2, one)]], x, relational=True) == \
            Or(Eq(x, -one), Eq(x, one))
        assert reduce_rational_inequalities(
            [[Le(x**2, one)]], x, relational=True) == \
            And(And(Le(-one, x), Le(x, one)))
        assert reduce_rational_inequalities(
            [[Lt(x**2, one)]], x, relational=True) == \
            And(And(Lt(-one, x), Lt(x, one)))
        assert reduce_rational_inequalities(
            [[Ge(x**2, one)]], x, relational=True) == \
            And(Or(And(Le(one, x), Lt(x, inf)), And(Le(x, -one), Lt(-inf, x))))
        assert reduce_rational_inequalities(
            [[Gt(x**2, one)]], x, relational=True) == \
            And(Or(And(Lt(-inf, x), Lt(x, -one)), And(Lt(one, x), Lt(x, inf))))
        assert reduce_rational_inequalities(
            [[Ne(x**2, one)]], x, relational=True) == \
            Or(And(Lt(-inf, x), Lt(x, -one)),
               And(Lt(-one, x), Lt(x, one)),
               And(Lt(one, x), Lt(x, inf)))
Exemplo n.º 5
0
def test_reduce_poly_inequalities_real_interval():
    assert reduce_rational_inequalities([[Eq(x**2, 0)]], x,
                                        relational=False) == FiniteSet(0)
    assert reduce_rational_inequalities([[x**2 <= 0]], x,
                                        relational=False) == FiniteSet(0)
    assert reduce_rational_inequalities([[x**2 < 0]], x,
                                        relational=False) == S.EmptySet
    assert reduce_rational_inequalities([[x**2 >= 0]], x,
                                        relational=False) == S.ExtendedReals
    assert reduce_rational_inequalities(
        [[x**2 > 0]], x, relational=False) == \
        FiniteSet(0).complement(S.ExtendedReals)
    assert reduce_rational_inequalities(
        [[Ne(x**2, 0)]], x, relational=False) == \
        FiniteSet(0).complement(S.ExtendedReals)

    assert reduce_rational_inequalities([[Eq(x**2, 1)]], x,
                                        relational=False) == FiniteSet(-1, 1)
    assert reduce_rational_inequalities([[x**2 <= 1]], x,
                                        relational=False) == Interval(-1, 1)
    assert reduce_rational_inequalities([[x**2 < 1]], x,
                                        relational=False) == Interval(
                                            -1, 1, True, True)
    assert reduce_rational_inequalities(
        [[x**2 >= 1]], x, relational=False) == \
        Union(Interval(-oo, -1, False), Interval(1, oo, False, False))
    assert reduce_rational_inequalities(
        [[x**2 > 1]], x, relational=False) == \
        Interval(-1, 1).complement(S.ExtendedReals)
    assert reduce_rational_inequalities(
        [[Ne(x**2, 1)]], x, relational=False) == \
        FiniteSet(-1, 1).complement(S.ExtendedReals)
    assert reduce_rational_inequalities([[Eq(x**2, 1.0)]], x,
                                        relational=False) == FiniteSet(
                                            -1.0, 1.0).evalf()
    assert reduce_rational_inequalities([[x**2 <= 1.0]], x,
                                        relational=False) == Interval(
                                            -1.0, 1.0)
    assert reduce_rational_inequalities([[x**2 < 1.0]], x,
                                        relational=False) == Interval(
                                            -1.0, 1.0, True, True)
    assert reduce_rational_inequalities(
        [[x**2 >= 1.0]], x, relational=False) == \
        Union(Interval(-inf, -1.0), Interval(1.0, inf))
    assert reduce_rational_inequalities(
        [[x**2 > 1.0]], x, relational=False) == \
        Union(Interval(-inf, -1.0, False, True),
              Interval(1.0, inf, True))
    assert reduce_rational_inequalities([[Ne(
        x**2, 1.0)]], x, relational=False) == \
        FiniteSet(-1.0, 1.0).complement(S.ExtendedReals)

    s = sqrt(2)

    assert reduce_rational_inequalities([[x**2 - 1 < 0, x**2 - 1 > 0]],
                                        x,
                                        relational=False) == S.EmptySet
    assert reduce_rational_inequalities([[x**2 - 1 <= 0, x**2 - 1 >= 0]],
                                        x,
                                        relational=False) == FiniteSet(-1, 1)
    assert reduce_rational_inequalities([[x**2 - 2 <= 0, x**2 - 1 >= 0]],
                                        x,
                                        relational=False) == Union(
                                            Interval(-s, -1, False, False),
                                            Interval(1, s, False, False))
    assert reduce_rational_inequalities([[x**2 - 2 <= 0, x**2 - 1 > 0]],
                                        x,
                                        relational=False) == Union(
                                            Interval(-s, -1, False, True),
                                            Interval(1, s, True, False))
    assert reduce_rational_inequalities([[x**2 - 2 < 0, x**2 - 1 >= 0]],
                                        x,
                                        relational=False) == Union(
                                            Interval(-s, -1, True, False),
                                            Interval(1, s, False, True))
    assert reduce_rational_inequalities([[x**2 - 2 < 0, x**2 - 1 > 0]],
                                        x,
                                        relational=False) == Union(
                                            Interval(-s, -1, True, True),
                                            Interval(1, s, True, True))
    assert reduce_rational_inequalities(
        [[x**2 - 2 < 0, Ne(x**2 - 1, 0)]], x,
        relational=False) == Union(Interval(-s, -1, True, True),
                                   Interval(-1, 1, True, True),
                                   Interval(1, s, True, True))

    # issue sympy/sympy#10237
    assert reduce_rational_inequalities([[x < oo, x >= 0, -oo < x]],
                                        x,
                                        relational=False) == Interval(
                                            0, oo, False, True)

    assert reduce_rational_inequalities([[Eq(
        (x + 1) / (x**2 - 1), 0)]], x) is false
Exemplo n.º 6
0
def test_reduce_poly_inequalities_complex_relational():
    assert reduce_rational_inequalities([[Eq(x**2, 0)]], x,
                                        relational=True) == Eq(x, 0)
    assert reduce_rational_inequalities([[x**2 <= 0]], x,
                                        relational=True) == Eq(x, 0)
    assert reduce_rational_inequalities([[x**2 < 0]], x,
                                        relational=True) is false
    assert reduce_rational_inequalities([[x**2 >= 0]], x,
                                        relational=True) is true
    assert reduce_rational_inequalities(
        [[x**2 > 0]], x, relational=True) == \
        (x < 0) | (Integer(0) < x)
    assert reduce_rational_inequalities(
        [[Ne(x**2, 0)]], x, relational=True) == \
        (x < 0) | (Integer(0) < x)

    for one in (Integer(1), Float(1.0)):
        assert reduce_rational_inequalities(
            [[Eq(x**2, one)]], x, relational=True) == \
            Eq(x, -one) | Eq(x, one)
        assert reduce_rational_inequalities(
            [[x**2 <= one]], x, relational=True) == \
            (-one <= x) & (x <= one)
        assert reduce_rational_inequalities(
            [[x**2 < one]], x, relational=True) == \
            (-one < x) & (x < one)
        assert reduce_rational_inequalities(
            [[x**2 >= one]], x, relational=True) == \
            (one <= x) | (x <= -one)
        assert reduce_rational_inequalities(
            [[x**2 > one]], x, relational=True) == \
            (one < x) | (x < -one)
        assert reduce_rational_inequalities(
            [[Ne(x**2, one)]], x, relational=True) == \
            (x < -one) | ((-one < x) & (x < one)) | (one < x)
Exemplo n.º 7
0
def test_reduce_poly_inequalities_real_interval():
    assert reduce_rational_inequalities(
        [[Eq(x**2, 0)]], x, relational=False) == FiniteSet(0)
    assert reduce_rational_inequalities(
        [[Le(x**2, 0)]], x, relational=False) == FiniteSet(0)
    assert reduce_rational_inequalities(
        [[Lt(x**2, 0)]], x, relational=False) == S.EmptySet
    assert reduce_rational_inequalities(
        [[Ge(x**2, 0)]], x, relational=False) == \
        S.Reals if x.is_extended_real else Interval(-oo, oo)
    assert reduce_rational_inequalities(
        [[Gt(x**2, 0)]], x, relational=False) == \
        FiniteSet(0).complement(S.Reals)
    assert reduce_rational_inequalities(
        [[Ne(x**2, 0)]], x, relational=False) == \
        FiniteSet(0).complement(S.Reals)

    assert reduce_rational_inequalities(
        [[Eq(x**2, 1)]], x, relational=False) == FiniteSet(-1, 1)
    assert reduce_rational_inequalities(
        [[Le(x**2, 1)]], x, relational=False) == Interval(-1, 1)
    assert reduce_rational_inequalities(
        [[Lt(x**2, 1)]], x, relational=False) == Interval(-1, 1, True, True)
    assert reduce_rational_inequalities(
        [[Ge(x**2, 1)]], x, relational=False) == \
        Union(Interval(-oo, -1, True), Interval(1, oo, False, True))
    assert reduce_rational_inequalities(
        [[Gt(x**2, 1)]], x, relational=False) == \
        Interval(-1, 1).complement(S.Reals)
    assert reduce_rational_inequalities(
        [[Ne(x**2, 1)]], x, relational=False) == \
        FiniteSet(-1, 1).complement(S.Reals)
    assert reduce_rational_inequalities([[Eq(
        x**2, 1.0)]], x, relational=False) == FiniteSet(-1.0, 1.0).evalf()
    assert reduce_rational_inequalities(
        [[Le(x**2, 1.0)]], x, relational=False) == Interval(-1.0, 1.0)
    assert reduce_rational_inequalities([[Lt(
        x**2, 1.0)]], x, relational=False) == Interval(-1.0, 1.0, True, True)
    assert reduce_rational_inequalities(
        [[Ge(x**2, 1.0)]], x, relational=False) == \
        Union(Interval(-inf, -1.0, True), Interval(1.0, inf, False, True))
    assert reduce_rational_inequalities(
        [[Gt(x**2, 1.0)]], x, relational=False) == \
        Union(Interval(-inf, -1.0, True, True),
              Interval(1.0, inf, True, True))
    assert reduce_rational_inequalities([[Ne(
        x**2, 1.0)]], x, relational=False) == \
        FiniteSet(-1.0, 1.0).complement(S.Reals)

    s = sqrt(2)

    assert reduce_rational_inequalities([[Lt(
        x**2 - 1, 0), Gt(x**2 - 1, 0)]], x, relational=False) == S.EmptySet
    assert reduce_rational_inequalities([[Le(x**2 - 1, 0), Ge(
        x**2 - 1, 0)]], x, relational=False) == FiniteSet(-1, 1)
    assert reduce_rational_inequalities(
        [[Le(x**2 - 2, 0), Ge(x**2 - 1, 0)]], x, relational=False
    ) == Union(Interval(-s, -1, False, False), Interval(1, s, False, False))
    assert reduce_rational_inequalities(
        [[Le(x**2 - 2, 0), Gt(x**2 - 1, 0)]], x, relational=False
    ) == Union(Interval(-s, -1, False, True), Interval(1, s, True, False))
    assert reduce_rational_inequalities(
        [[Lt(x**2 - 2, 0), Ge(x**2 - 1, 0)]], x, relational=False
    ) == Union(Interval(-s, -1, True, False), Interval(1, s, False, True))
    assert reduce_rational_inequalities(
        [[Lt(x**2 - 2, 0), Gt(x**2 - 1, 0)]], x, relational=False
    ) == Union(Interval(-s, -1, True, True), Interval(1, s, True, True))
    assert reduce_rational_inequalities(
        [[Lt(x**2 - 2, 0), Ne(x**2 - 1, 0)]], x, relational=False
    ) == Union(Interval(-s, -1, True, True), Interval(-1, 1, True, True),
               Interval(1, s, True, True))

    # issue sympy/sympy#10237
    assert reduce_rational_inequalities(
        [[x < oo, x >= 0, -oo < x]], x, relational=False) == Interval(0, oo, False, True)

    assert reduce_rational_inequalities([[Eq((x + 1)/(x**2 - 1),
                                             0)]], x) is false
Exemplo n.º 8
0
def test_reduce_poly_inequalities_complex_relational():
    assert reduce_rational_inequalities(
        [[Eq(x**2, 0)]], x, relational=True) == Eq(x, 0)
    assert reduce_rational_inequalities(
        [[Le(x**2, 0)]], x, relational=True) == Eq(x, 0)
    assert reduce_rational_inequalities(
        [[Lt(x**2, 0)]], x, relational=True) is false
    assert reduce_rational_inequalities(
        [[Ge(x**2, 0)]], x, relational=True) == And(Lt(-oo, x), Lt(x, oo))
    assert reduce_rational_inequalities(
        [[Gt(x**2, 0)]], x, relational=True) == \
        And(Or(And(Lt(-oo, x), Lt(x, 0)), And(Lt(0, x), Lt(x, oo))))
    assert reduce_rational_inequalities(
        [[Ne(x**2, 0)]], x, relational=True) == \
        And(Or(And(Lt(-oo, x), Lt(x, 0)), And(Lt(0, x), Lt(x, oo))))

    for one in (Integer(1), Float(1.0)):
        inf = one*oo
        assert reduce_rational_inequalities(
            [[Eq(x**2, one)]], x, relational=True) == \
            Or(Eq(x, -one), Eq(x, one))
        assert reduce_rational_inequalities(
            [[Le(x**2, one)]], x, relational=True) == \
            And(And(Le(-one, x), Le(x, one)))
        assert reduce_rational_inequalities(
            [[Lt(x**2, one)]], x, relational=True) == \
            And(And(Lt(-one, x), Lt(x, one)))
        assert reduce_rational_inequalities(
            [[Ge(x**2, one)]], x, relational=True) == \
            And(Or(And(Le(one, x), Lt(x, inf)), And(Le(x, -one), Lt(-inf, x))))
        assert reduce_rational_inequalities(
            [[Gt(x**2, one)]], x, relational=True) == \
            And(Or(And(Lt(-inf, x), Lt(x, -one)), And(Lt(one, x), Lt(x, inf))))
        assert reduce_rational_inequalities(
            [[Ne(x**2, one)]], x, relational=True) == \
            Or(And(Lt(-inf, x), Lt(x, -one)),
               And(Lt(-one, x), Lt(x, one)),
               And(Lt(one, x), Lt(x, inf)))