(poly, rel)
return intervals
Solve a polynomial inequality with rational coefficients.

    Examples
    ========

    >>> from sympy import Poly
    >>> from sympy.abc import x
    >>> from sympy.solvers.inequalities import solve_poly_inequality

    >>> solve_poly_inequality(Poly(x, x, domain='ZZ'), '==')
    [{0}]

    >>> solve_poly_inequality(Poly(x**2 - 1, x, domain='ZZ'), '!=')
    [(-oo, -1), (-1, 1), (1, oo)]

    >>> solve_poly_inequality(Poly(x**2 - 1, x, domain='ZZ'), '==')
    [{-1}, {1}]

    See Also
    ========
    solve_poly_inequalities
Solve a polynomial inequality with rational coefficients.
Solve a polynomial inequality with rational coefficients .
def solve_poly_inequality(poly, rel):
    """Solve a polynomial inequality with rational coefficients.

    Examples
    ========

    >>> from sympy import Poly
    >>> from sympy.abc import x
    >>> from sympy.solvers.inequalities import solve_poly_inequality

    >>> solve_poly_inequality(Poly(x, x, domain='ZZ'), '==')
    [{0}]

    >>> solve_poly_inequality(Poly(x**2 - 1, x, domain='ZZ'), '!=')
    [(-oo, -1), (-1, 1), (1, oo)]

    >>> solve_poly_inequality(Poly(x**2 - 1, x, domain='ZZ'), '==')
    [{-1}, {1}]

    See Also
    ========
    solve_poly_inequalities
    """
    reals, intervals = poly.real_roots(multiple=False), []

    if rel == '==':
        for root, _ in reals:
            interval = Interval(root, root)
            intervals.append(interval)
    elif rel == '!=':
        left = S.NegativeInfinity

        for right, _ in reals + [(S.Infinity, 1)]:
            interval = Interval(left, right, True, True)
            intervals.append(interval)
            left = right
    else:
        if poly.LC() > 0:
            sign = +1
        else:
            sign = -1

        eq_sign, equal = None, False

        if rel == '>':
            eq_sign = +1
        elif rel == '<':
            eq_sign = -1
        elif rel == '>=':
            eq_sign, equal = +1, True
        elif rel == '<=':
            eq_sign, equal = -1, True
        else:
            raise ValueError("'%s' is not a valid relation" % rel)

        right, right_open = S.Infinity, True

        reals.sort(key=lambda w: w[0], reverse=True)
        for left, multiplicity in reals:
            if multiplicity % 2:
                if sign == eq_sign:
                    intervals.insert(
                        0, Interval(left, right, not equal, right_open))

                sign, right, right_open = -sign, left, not equal
            else:
                if sign == eq_sign and not equal:
                    intervals.insert(
                        0, Interval(left, right, True, right_open))
                    right, right_open = left, True
                elif sign != eq_sign and equal:
                    intervals.insert(0, Interval(left, left))

        if sign == eq_sign:
            intervals.insert(
                0, Interval(S.NegativeInfinity, right, True, right_open))

    return intervals
def solve_poly_inequality ( poly , rel ) : reals , intervals = poly . real_roots ( multiple = False ) , [ ] if rel == '==' : for root , _ in reals : interval = Interval ( root , root ) intervals . append ( interval ) elif rel == '!=' : left = S . NegativeInfinity for right , _ in reals + [ ( S . Infinity , 1 ) ] : interval = Interval ( left , right , True , True ) intervals . append ( interval ) left = right else : if poly . LC ( ) > 0 : sign = + 1 else : sign = - 1 eq_sign , equal = None , False if rel == '>' : eq_sign = + 1 elif rel == '<' : eq_sign = - 1 elif rel == '>=' : eq_sign , equal = + 1 , True elif rel == '<=' : eq_sign , equal = - 1 , True else : raise ValueError ( "'%s' is not a valid relation" % rel ) right , right_open = S . Infinity , True reals . sort ( key = lambda w : w [ 0 ] , reverse = True ) for left , multiplicity in reals : if multiplicity % 2 : if sign == eq_sign : intervals . insert ( 0 , Interval ( left , right , not equal , right_open ) ) sign , right , right_open = - sign , left , not equal else : if sign == eq_sign and not equal : intervals . insert ( 0 , Interval ( left , right , True , right_open ) ) right , right_open = left , True elif sign != eq_sign and equal : intervals . insert ( 0 , Interval ( left , left ) ) if sign == eq_sign : intervals . insert ( 0 , Interval ( S . NegativeInfinity , right , True , right_open ) ) return intervals