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))
def test_intersection(): pytest.raises(TypeError, lambda: Intersection(1)) assert Intersection() == S.UniversalSet assert Interval(0, 2).intersection(Interval(1, 2)) == Interval(1, 2) assert Interval(0, 2).intersection(Interval(1, 2, True)) == \ Interval(1, 2, True) assert Interval(0, 2, True).intersection(Interval(1, 2)) == \ Interval(1, 2, False, False) assert Interval(0, 2, True, True).intersection(Interval(1, 2)) == \ Interval(1, 2, False, True) assert Interval(0, 2).intersection(Union(Interval(0, 1), Interval(2, 3))) == \ Union(Interval(0, 1), Interval(2, 2)) x = Symbol('x') assert Intersection(Interval(0, 1), FiniteSet(x)).is_iterable assert not Intersection(Interval(0, 1), Interval(0, x)).is_iterable assert FiniteSet(1, 2, x).intersection(FiniteSet(x)) == FiniteSet(x) assert FiniteSet('ham', 'eggs').intersection(FiniteSet('ham')) == \ FiniteSet('ham') assert FiniteSet(1, 2, 3, 4, 5).intersection(S.EmptySet) == S.EmptySet assert Interval(0, 5).intersection(FiniteSet(1, 3)) == FiniteSet(1, 3) assert Interval(0, 1, True, True).intersection(FiniteSet(1)) == S.EmptySet assert Union(Interval(0, 1), Interval(2, 3)).intersection(Interval(1, 2)) == \ Union(Interval(1, 1), Interval(2, 2)) assert Union(Interval(0, 1), Interval(2, 3)).intersection(Interval(0, 2)) == \ Union(Interval(0, 1), Interval(2, 2)) assert Union(Interval(0, 1), Interval(2, 3)).intersection(Interval(1, 2, True, True)) == \ S.EmptySet assert Union(Interval(0, 1), Interval(2, 3)).intersection(S.EmptySet) == \ S.EmptySet assert Union(Interval(0, 5), FiniteSet('ham')).intersection(FiniteSet(2, 3, 4, 5, 6)) == \ Union(FiniteSet(2, 3, 4, 5), Intersection(FiniteSet(6), Union(Interval(0, 5), FiniteSet('ham')))) # issue sympy/sympy#8217 assert Intersection(FiniteSet(x), FiniteSet(y)) == \ Intersection(FiniteSet(x), FiniteSet(y), evaluate=False) assert FiniteSet(x).intersection(S.Reals) == \ Intersection(S.Reals, FiniteSet(x), evaluate=False) # tests for the intersection alias assert Interval(0, 5).intersection(FiniteSet(1, 3)) == FiniteSet(1, 3) assert Interval(0, 1, True, True).intersection(FiniteSet(1)) == S.EmptySet assert Union(Interval(0, 1), Interval(2, 3)).intersection(Interval(1, 2)) == \ Union(Interval(1, 1), Interval(2, 2)) assert ProductSet(FiniteSet(1), FiniteSet(2)).intersection(Interval(1, 2)).is_Intersection # iterable i = Intersection(FiniteSet(1, 2, 3), Interval(2, 5), evaluate=False) assert i.is_iterable assert set(i) == {Integer(2), Integer(3)} # challenging intervals x = Symbol('x', real=True) i = Intersection(Interval(0, 3), Interval(x, 6)) assert (5 in i) is False pytest.raises(TypeError, lambda: 2 in i) # Singleton special cases assert Intersection(Interval(0, 1), S.EmptySet) == S.EmptySet assert Intersection(S.Reals, Interval(-oo, x, True)) == Interval(-oo, x, True) assert Intersection(S.Reals, Interval(-oo, x)) == Interval.Lopen(-oo, x) assert Intersection(S.Reals, Interval(x, oo)) == Interval.Ropen(x, oo) assert Intersection(S.Reals, Interval(-oo, 1)) == Interval.Lopen(-oo, 1) assert Intersection(S.Reals, Interval(1, oo)) == Interval.Ropen(1, oo) assert Intersection(S.ExtendedReals, Interval(1, 2)) == Interval(1, 2) # Products line = Interval(0, 5) i = Intersection(line**2, line**3, evaluate=False) assert (2, 2) not in i assert (2, 2, 2) not in i pytest.raises(ValueError, lambda: list(i)) assert (Intersection(Intersection(S.Integers, S.Naturals, evaluate=False), S.Reals, evaluate=False) == Intersection(S.Integers, S.Naturals, S.Reals, evaluate=False)) assert (imageset( Lambda(x, x**2), Intersection(FiniteSet(1, 2), FiniteSet(2, 3), evaluate=False)) == FiniteSet(4))
def test_sympyissue_22073(): assert -oo in Interval(-oo, 5) assert -oo not in Interval.Lopen(-oo, 5) assert -3 not in Interval.Lopen(-3, 5) assert -3 in Interval(-3, 5)