Beispiel #1
0
def test_diofantissue_453():
    x = Symbol('x', real=True)
    assert isolve(abs((x - 1) / (x - 5)) <= Rational(1, 3),
                  x) == And(Integer(-1) <= x, x <= 2)
    assert solve(abs((x - 1) / (x - 5)) - Rational(1, 3), x) == [{
        x: -1
    }, {
        x: 2
    }]
Beispiel #2
0
def test_sympyissue_8974():
    assert isolve(-oo < x, x) == And(-oo < x, x < oo)
    assert isolve(oo > x, x) == And(-oo < x, x < oo)
Beispiel #3
0
def test_solve_univariate_inequality():
    assert isolve(x**2 >= 4, x, relational=False) == Union(Interval(-oo, -2, True),
        Interval(2, oo, False, True))
    assert isolve(x**2 >= 4, x) == Or(And(Le(2, x), Lt(x, oo)), And(Le(x, -2),
        Lt(-oo, x)))
    assert isolve((x - 1)*(x - 2)*(x - 3) >= 0, x, relational=False) == \
        Union(Interval(1, 2), Interval(3, oo, False, True))
    assert isolve((x - 1)*(x - 2)*(x - 3) >= 0, x) == \
        Or(And(Le(1, x), Le(x, 2)), And(Le(3, x), Lt(x, oo)))
    # issue sympy/sympy#2785:
    assert isolve(x**3 - 2*x - 1 > 0, x, relational=False) == \
        Union(Interval(-1, -sqrt(5)/2 + Rational(1, 2), True, True),
              Interval(Rational(1, 2) + sqrt(5)/2, oo, True, True))
    # issue sympy/sympy#2794:
    assert isolve(x**3 - x**2 + x - 1 > 0, x, relational=False) == \
        Interval(1, oo, True, True)

    # XXX should be limited in domain, e.g. between 0 and 2*pi
    assert isolve(sin(x) < S.Half, x) == \
        Or(And(-oo < x, x < pi/6), And(5*pi/6 < x, x < oo))
    assert isolve(sin(x) > S.Half, x) == And(pi/6 < x, x < 5*pi/6)

    # numerical testing in valid() is needed
    assert isolve(x**7 - x - 2 > 0, x) == \
        And(RootOf(x**7 - x - 2, 0) < x, x < oo)

    # handle numerator and denominator; although these would be handled as
    # rational inequalities, these test confirm that the right thing is done
    # when the domain is EX (e.g. when 2 is replaced with sqrt(2))
    assert isolve(1/(x - 2) > 0, x) == And(Integer(2) < x, x < oo)
    den = ((x - 1)*(x - 2)).expand()
    assert isolve((x - 1)/den <= 0, x) == \
        Or(And(-oo < x, x < 1), And(Integer(1) < x, x < 2))

    assert isolve(x > oo, x) is S.false
Beispiel #4
0
def test_solve_univariate_inequality():
    assert isolve(x**2 >= 4,
                  x, relational=False) == Union(Interval(-oo, -2),
                                                Interval(2, oo))
    assert isolve(x**2 >= 4, x) == (Integer(2) <= x) | (x <= -2)
    assert isolve((x - 1)*(x - 2)*(x - 3) >= 0, x, relational=False) == \
        Union(Interval(1, 2), Interval(3, oo))
    assert isolve((x - 1)*(x - 2)*(x - 3) >= 0, x) == \
        ((Integer(1) <= x) & (x <= 2)) | (Integer(3) <= x)
    # issue sympy/sympy#2785:
    assert isolve(x**3 - 2*x - 1 > 0, x, relational=False) == \
        Union(Interval(-1, -sqrt(5)/2 + Rational(1, 2), True, True),
              Interval(Rational(1, 2) + sqrt(5)/2, oo, True))
    # issue sympy/sympy#2794:
    assert isolve(x**3 - x**2 + x - 1 > 0, x, relational=False) == \
        Interval(1, oo, True)

    # XXX should be limited in domain, e.g. between 0 and 2*pi
    assert isolve(sin(x) < Rational(1, 2),
                  x) == (x < pi / 6) | (5 * pi / 6 < x)
    assert isolve(sin(x) > Rational(1, 2),
                  x) == (pi / 6 < x) & (x < 5 * pi / 6)

    # numerical testing in valid() is needed
    assert isolve(x**7 - x - 2 > 0, x) == (RootOf(x**7 - x - 2, 0) < x)

    # handle numerator and denominator; although these would be handled as
    # rational inequalities, these test confirm that the right thing is done
    # when the domain is EX (e.g. when 2 is replaced with sqrt(2))
    assert isolve(1 / (x - 2) > 0, x) == (Integer(2) < x)
    den = ((x - 1) * (x - 2)).expand()
    assert isolve((x - 1) / den <= 0,
                  x) == (x < 1) | ((Integer(1) < x) & (x < 2))

    assert isolve(x > oo, x) is false

    # issue sympy/sympy#10268
    assert reduce_inequalities(log(x) < 300) == (-oo < x) & (x < E**300)
def test_diofantissue_453():
    x = Symbol('x', real=True)
    assert isolve(abs((x - 1)/(x - 5)) <= Rational(1, 3),
                  x) == And(Integer(-1) <= x, x <= 2)
    assert solve(abs((x - 1)/(x - 5)) - Rational(1, 3), x) == [{x: -1}, {x: 2}]
def test_sympyissue_8974():
    assert isolve(-oo < x, x) == And(-oo < x, x < oo)
    assert isolve(oo > x, x) == And(-oo < x, x < oo)
def test_solve_univariate_inequality():
    assert isolve(x**2 >= 4, x, relational=False) == Union(Interval(-oo, -2, True),
                                                           Interval(2, oo, False, True))
    assert isolve(x**2 >= 4, x) == Or(And(Le(2, x), Lt(x, oo)), And(Le(x, -2),
                                                                    Lt(-oo, x)))
    assert isolve((x - 1)*(x - 2)*(x - 3) >= 0, x, relational=False) == \
        Union(Interval(1, 2), Interval(3, oo, False, True))
    assert isolve((x - 1)*(x - 2)*(x - 3) >= 0, x) == \
        Or(And(Le(1, x), Le(x, 2)), And(Le(3, x), Lt(x, oo)))
    # issue sympy/sympy#2785:
    assert isolve(x**3 - 2*x - 1 > 0, x, relational=False) == \
        Union(Interval(-1, -sqrt(5)/2 + Rational(1, 2), True, True),
              Interval(Rational(1, 2) + sqrt(5)/2, oo, True, True))
    # issue sympy/sympy#2794:
    assert isolve(x**3 - x**2 + x - 1 > 0, x, relational=False) == \
        Interval(1, oo, True, True)

    # XXX should be limited in domain, e.g. between 0 and 2*pi
    assert isolve(sin(x) < Rational(1, 2), x) == \
        Or(And(-oo < x, x < pi/6), And(5*pi/6 < x, x < oo))
    assert isolve(sin(x) > Rational(1, 2), x) == And(pi/6 < x, x < 5*pi/6)

    # numerical testing in valid() is needed
    assert isolve(x**7 - x - 2 > 0, x) == \
        And(RootOf(x**7 - x - 2, 0) < x, x < oo)

    # handle numerator and denominator; although these would be handled as
    # rational inequalities, these test confirm that the right thing is done
    # when the domain is EX (e.g. when 2 is replaced with sqrt(2))
    assert isolve(1/(x - 2) > 0, x) == And(Integer(2) < x, x < oo)
    den = ((x - 1)*(x - 2)).expand()
    assert isolve((x - 1)/den <= 0, x) == \
        Or(And(-oo < x, x < 1), And(Integer(1) < x, x < 2))

    assert isolve(x > oo, x) is false