def test_reduce_poly_inequalities_real_relational(): global_assumptions.add(Q.real(x)) global_assumptions.add(Q.real(y)) assert reduce_poly_inequalities([[Eq(x ** 2, 0)]], x, relational=True) == Eq(x, 0) assert reduce_poly_inequalities([[Le(x ** 2, 0)]], x, relational=True) == Eq(x, 0) assert reduce_poly_inequalities([[Lt(x ** 2, 0)]], x, relational=True) == False assert reduce_poly_inequalities([[Ge(x ** 2, 0)]], x, relational=True) == True assert reduce_poly_inequalities([[Gt(x ** 2, 0)]], x, relational=True) == Or(Lt(x, 0), Lt(0, x)) assert reduce_poly_inequalities([[Ne(x ** 2, 0)]], x, relational=True) == Or(Lt(x, 0), Lt(0, x)) assert reduce_poly_inequalities([[Eq(x ** 2, 1)]], x, relational=True) == Or(Eq(x, -1), Eq(x, 1)) assert reduce_poly_inequalities([[Le(x ** 2, 1)]], x, relational=True) == And(Le(-1, x), Le(x, 1)) assert reduce_poly_inequalities([[Lt(x ** 2, 1)]], x, relational=True) == And(Lt(-1, x), Lt(x, 1)) assert reduce_poly_inequalities([[Ge(x ** 2, 1)]], x, relational=True) == Or(Le(x, -1), Le(1, x)) assert reduce_poly_inequalities([[Gt(x ** 2, 1)]], x, relational=True) == Or(Lt(x, -1), Lt(1, x)) assert reduce_poly_inequalities([[Ne(x ** 2, 1)]], x, relational=True) == Or( Lt(x, -1), And(Lt(-1, x), Lt(x, 1)), Lt(1, x) ) assert ( reduce_poly_inequalities([[Eq(x ** 2, 1.0)]], x, relational=True).evalf() == Or(Eq(x, -1.0), Eq(x, 1.0)).evalf() ) assert reduce_poly_inequalities([[Le(x ** 2, 1.0)]], x, relational=True) == And(Le(-1.0, x), Le(x, 1.0)) assert reduce_poly_inequalities([[Lt(x ** 2, 1.0)]], x, relational=True) == And(Lt(-1.0, x), Lt(x, 1.0)) assert reduce_poly_inequalities([[Ge(x ** 2, 1.0)]], x, relational=True) == Or(Le(x, -1.0), Le(1.0, x)) assert reduce_poly_inequalities([[Gt(x ** 2, 1.0)]], x, relational=True) == Or(Lt(x, -1.0), Lt(1.0, x)) assert reduce_poly_inequalities([[Ne(x ** 2, 1.0)]], x, relational=True) == Or( Lt(x, -1.0), And(Lt(-1.0, x), Lt(x, 1.0)), Lt(1.0, x) ) global_assumptions.remove(Q.real(x)) global_assumptions.remove(Q.real(y))
def test_reduce_poly_inequalities_real_relational(): global_assumptions.add(Q.real(x)) global_assumptions.add(Q.real(y)) assert reduce_poly_inequalities([[Eq(x**2, 0)]], x, relational=True) == Eq(x, 0) assert reduce_poly_inequalities([[Le(x**2, 0)]], x, relational=True) == Eq(x, 0) assert reduce_poly_inequalities([[Lt(x**2, 0)]], x, relational=True) == False assert reduce_poly_inequalities([[Ge(x**2, 0)]], x, relational=True) == True assert reduce_poly_inequalities([[Gt(x**2, 0)]], x, relational=True) == Or(Lt(x, 0), Lt(0, x)) assert reduce_poly_inequalities([[Ne(x**2, 0)]], x, relational=True) == Or(Lt(x, 0), Lt(0, x)) assert reduce_poly_inequalities([[Eq(x**2, 1)]], x, relational=True) == Or(Eq(x, -1), Eq(x, 1)) assert reduce_poly_inequalities([[Le(x**2, 1)]], x, relational=True) == And(Le(-1, x), Le(x, 1)) assert reduce_poly_inequalities([[Lt(x**2, 1)]], x, relational=True) == And(Lt(-1, x), Lt(x, 1)) assert reduce_poly_inequalities([[Ge(x**2, 1)]], x, relational=True) == Or(Le(x, -1), Le(1, x)) assert reduce_poly_inequalities([[Gt(x**2, 1)]], x, relational=True) == Or(Lt(x, -1), Lt(1, x)) assert reduce_poly_inequalities([[Ne(x**2, 1)]], x, relational=True) == Or(Lt(x, -1), And(Lt(-1, x), Lt(x, 1)), Lt(1, x)) assert reduce_poly_inequalities([[Eq(x**2, 1.0)]], x, relational=True).evalf() == Or(Eq(x, -1.0), Eq(x, 1.0)).evalf() assert reduce_poly_inequalities([[Le(x**2, 1.0)]], x, relational=True) == And(Le(-1.0, x), Le(x, 1.0)) assert reduce_poly_inequalities([[Lt(x**2, 1.0)]], x, relational=True) == And(Lt(-1.0, x), Lt(x, 1.0)) assert reduce_poly_inequalities([[Ge(x**2, 1.0)]], x, relational=True) == Or(Le(x, -1.0), Le(1.0, x)) assert reduce_poly_inequalities([[Gt(x**2, 1.0)]], x, relational=True) == Or(Lt(x, -1.0), Lt(1.0, x)) assert reduce_poly_inequalities([[Ne(x**2, 1.0)]], x, relational=True) == Or(Lt(x, -1.0), And(Lt(-1.0, x), Lt(x, 1.0)), Lt(1.0, x)) global_assumptions.remove(Q.real(x)) global_assumptions.remove(Q.real(y))
def test_reduce_poly_inequalities_real_interval(): global_assumptions.add(Q.real(x)) global_assumptions.add(Q.real(y)) assert reduce_poly_inequalities( [[Eq(x**2, 0)]], x, relational=False) == FiniteSet(0) assert reduce_poly_inequalities( [[Le(x**2, 0)]], x, relational=False) == FiniteSet(0) assert reduce_poly_inequalities( [[Lt(x**2, 0)]], x, relational=False) == S.EmptySet assert reduce_poly_inequalities( [[Ge(x**2, 0)]], x, relational=False) == Interval(-oo, oo) assert reduce_poly_inequalities( [[Gt(x**2, 0)]], x, relational=False) == FiniteSet(0).complement assert reduce_poly_inequalities( [[Ne(x**2, 0)]], x, relational=False) == FiniteSet(0).complement assert reduce_poly_inequalities( [[Eq(x**2, 1)]], x, relational=False) == FiniteSet(-1, 1) assert reduce_poly_inequalities( [[Le(x**2, 1)]], x, relational=False) == Interval(-1, 1) assert reduce_poly_inequalities( [[Lt(x**2, 1)]], x, relational=False) == Interval(-1, 1, True, True) assert reduce_poly_inequalities([[Ge(x**2, 1)]], x, relational=False) == Union(Interval(-oo, -1), Interval(1, oo)) assert reduce_poly_inequalities( [[Gt(x**2, 1)]], x, relational=False) == Interval(-1, 1).complement assert reduce_poly_inequalities( [[Ne(x**2, 1)]], x, relational=False) == FiniteSet(-1, 1).complement assert reduce_poly_inequalities([[Eq( x**2, 1.0)]], x, relational=False) == FiniteSet(-1.0, 1.0).evalf() assert reduce_poly_inequalities( [[Le(x**2, 1.0)]], x, relational=False) == Interval(-1.0, 1.0) assert reduce_poly_inequalities([[Lt( x**2, 1.0)]], x, relational=False) == Interval(-1.0, 1.0, True, True) assert reduce_poly_inequalities([[Ge(x**2, 1.0)]], x, relational=False) == Union(Interval(-inf, -1.0), Interval(1.0, inf)) assert reduce_poly_inequalities([[Gt(x**2, 1.0)]], x, relational=False) == Union(Interval(-inf, -1.0, right_open=True), Interval(1.0, inf, left_open=True)) assert reduce_poly_inequalities([[Ne( x**2, 1.0)]], x, relational=False) == FiniteSet(-1.0, 1.0).complement s = sqrt(2) assert reduce_poly_inequalities([[Lt( x**2 - 1, 0), Gt(x**2 - 1, 0)]], x, relational=False) == S.EmptySet assert reduce_poly_inequalities([[Le(x**2 - 1, 0), Ge( x**2 - 1, 0)]], x, relational=False) == FiniteSet(-1, 1) assert reduce_poly_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_poly_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_poly_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_poly_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_poly_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)) global_assumptions.remove(Q.real(x)) global_assumptions.remove(Q.real(y))
def test_reduce_poly_inequalities_real_interval(): global_assumptions.add(x_assume) global_assumptions.add(y_assume) assert reduce_poly_inequalities([[Eq(x**2, 0)]], x, relational=False) == [Interval(0, 0)] assert reduce_poly_inequalities([[Le(x**2, 0)]], x, relational=False) == [Interval(0, 0)] assert reduce_poly_inequalities([[Lt(x**2, 0)]], x, relational=False) == [] assert reduce_poly_inequalities([[Ge(x**2, 0)]], x, relational=False) == [Interval(-oo, oo)] assert reduce_poly_inequalities([[Gt(x**2, 0)]], x, relational=False) == [Interval(-oo, 0, right_open=True), Interval(0, oo, left_open=True)] assert reduce_poly_inequalities([[Ne(x**2, 0)]], x, relational=False) == [Interval(-oo, 0, right_open=True), Interval(0, oo, left_open=True)] assert reduce_poly_inequalities([[Eq(x**2, 1)]], x, relational=False) == [Interval(-1,-1), Interval(1, 1)] assert reduce_poly_inequalities([[Le(x**2, 1)]], x, relational=False) == [Interval(-1, 1)] assert reduce_poly_inequalities([[Lt(x**2, 1)]], x, relational=False) == [Interval(-1, 1, True, True)] assert reduce_poly_inequalities([[Ge(x**2, 1)]], x, relational=False) == [Interval(-oo, -1), Interval(1, oo)] assert reduce_poly_inequalities([[Gt(x**2, 1)]], x, relational=False) == [Interval(-oo, -1, right_open=True), Interval(1, oo, left_open=True)] assert reduce_poly_inequalities([[Ne(x**2, 1)]], x, relational=False) == [Interval(-oo, -1, right_open=True), Interval(-1, 1, True, True), Interval(1, oo, left_open=True)] assert reduce_poly_inequalities([[Eq(x**2, 1.0)]], x, relational=False) == [Interval(-1.0,-1.0), Interval(1.0, 1.0)] assert reduce_poly_inequalities([[Le(x**2, 1.0)]], x, relational=False) == [Interval(-1.0, 1.0)] assert reduce_poly_inequalities([[Lt(x**2, 1.0)]], x, relational=False) == [Interval(-1.0, 1.0, True, True)] assert reduce_poly_inequalities([[Ge(x**2, 1.0)]], x, relational=False) == [Interval(-inf, -1.0), Interval(1.0, inf)] assert reduce_poly_inequalities([[Gt(x**2, 1.0)]], x, relational=False) == [Interval(-inf, -1.0, right_open=True), Interval(1.0, inf, left_open=True)] assert reduce_poly_inequalities([[Ne(x**2, 1.0)]], x, relational=False) == [Interval(-inf, -1.0, right_open=True), Interval(-1.0, 1.0, True, True), Interval(1.0, inf, left_open=True)] s = sqrt(2) assert reduce_poly_inequalities([[Lt(x**2 - 1, 0), Gt(x**2 - 1, 0)]], x, relational=False) == [] assert reduce_poly_inequalities([[Le(x**2 - 1, 0), Ge(x**2 - 1, 0)]], x, relational=False) == [Interval(-1,-1), Interval(1, 1)] assert reduce_poly_inequalities([[Le(x**2 - 2, 0), Ge(x**2 - 1, 0)]], x, relational=False) == [Interval(-s, -1, False, False), Interval(1, s, False, False)] assert reduce_poly_inequalities([[Le(x**2 - 2, 0), Gt(x**2 - 1, 0)]], x, relational=False) == [Interval(-s, -1, False, True), Interval(1, s, True, False)] assert reduce_poly_inequalities([[Lt(x**2 - 2, 0), Ge(x**2 - 1, 0)]], x, relational=False) == [Interval(-s, -1, True, False), Interval(1, s, False, True)] assert reduce_poly_inequalities([[Lt(x**2 - 2, 0), Gt(x**2 - 1, 0)]], x, relational=False) == [Interval(-s, -1, True, True), Interval(1, s, True, True)] assert reduce_poly_inequalities([[Lt(x**2 - 2, 0), Ne(x**2 - 1, 0)]], x, relational=False) == [Interval(-s, -1, True, True), Interval(-1, 1, True, True), Interval(1, s, True, True)] global_assumptions.remove(x_assume) global_assumptions.remove(y_assume)
def test_reduce_poly_inequalities_real_interval(): global_assumptions.add(Q.real(x)) global_assumptions.add(Q.real(y)) assert reduce_poly_inequalities([[Eq(x**2, 0)]], x, relational=False) == FiniteSet(0) assert reduce_poly_inequalities([[Le(x**2, 0)]], x, relational=False) == FiniteSet(0) assert reduce_poly_inequalities([[Lt(x**2, 0)]], x, relational=False) == S.EmptySet assert reduce_poly_inequalities([[Ge(x**2, 0)]], x, relational=False) == Interval(-oo, oo) assert reduce_poly_inequalities([[Gt(x**2, 0)]], x, relational=False) == FiniteSet(0).complement assert reduce_poly_inequalities([[Ne(x**2, 0)]], x, relational=False) == FiniteSet(0).complement assert reduce_poly_inequalities([[Eq(x**2, 1)]], x, relational=False) == FiniteSet(-1, 1) assert reduce_poly_inequalities([[Le(x**2, 1)]], x, relational=False) == Interval(-1, 1) assert reduce_poly_inequalities([[Lt(x**2, 1)]], x, relational=False) == Interval(-1, 1, True, True) assert reduce_poly_inequalities([[Ge(x**2, 1)]], x, relational=False) == Union(Interval(-oo, -1), Interval(1, oo)) assert reduce_poly_inequalities([[Gt(x**2, 1)]], x, relational=False) == Interval(-1,1).complement assert reduce_poly_inequalities([[Ne(x**2, 1)]], x, relational=False) == FiniteSet(-1,1).complement assert reduce_poly_inequalities([[Eq(x**2, 1.0)]], x, relational=False) == FiniteSet(-1.0,1.0).evalf() assert reduce_poly_inequalities([[Le(x**2, 1.0)]], x, relational=False) == Interval(-1.0, 1.0) assert reduce_poly_inequalities([[Lt(x**2, 1.0)]], x, relational=False) == Interval(-1.0, 1.0, True, True) assert reduce_poly_inequalities([[Ge(x**2, 1.0)]], x, relational=False) == Union(Interval(-inf, -1.0), Interval(1.0, inf)) assert reduce_poly_inequalities([[Gt(x**2, 1.0)]], x, relational=False) == Union(Interval(-inf, -1.0, right_open=True), Interval(1.0, inf, left_open=True)) assert reduce_poly_inequalities([[Ne(x**2, 1.0)]], x, relational=False) == FiniteSet(-1.0, 1.0).complement s = sqrt(2) assert reduce_poly_inequalities([[Lt(x**2 - 1, 0), Gt(x**2 - 1, 0)]], x, relational=False) == S.EmptySet assert reduce_poly_inequalities([[Le(x**2 - 1, 0), Ge(x**2 - 1, 0)]], x, relational=False) == FiniteSet(-1,1) assert reduce_poly_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_poly_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_poly_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_poly_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_poly_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)) global_assumptions.remove(Q.real(x)) global_assumptions.remove(Q.real(y))