code: def solve_poly_inequality(poly, rel):
      """Solve a polynomial inequality with rational coefficients.
  
      Examples
      ========
  
      >>> from sympy import solve_poly_inequality, Poly
      >>> from sympy.abc import x
  
      >>> solve_poly_inequality(Poly(x, x, domain='ZZ'), '==')
      [{0}]
  
      >>> solve_poly_inequality(Poly(x**2 - 1, x, domain='ZZ'), '!=')
      [Interval.open(-oo, -1), Interval.open(-1, 1), Interval.open(1, oo)]
  
      >>> solve_poly_inequality(Poly(x**2 - 1, x, domain='ZZ'), '==')
      [{-1}, {1}]
  
      See Also
      ========
      solve_poly_inequalities
      """
      if not isinstance(poly, Poly):
          raise ValueError(
              "For efficiency reasons, `poly` should be a Poly instance"
          )
      if poly.as_expr().is_number:
          t = Relational(poly.as_expr(), 0, rel)
          if t is S.true:
              return [S.Reals]
          elif t is S.false:
              return [S.EmptySet]
          else:
              raise NotImplementedError(
                  "could not determine truth value of %s" % t
              )
  
      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
  
          for left, multiplicity in reversed(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
  
imports: import itertools
  from sympy.calculus.util import continuous_domain, periodicity, function_range
  from sympy.core import sympify
  from sympy.core.exprtools import factor_terms
  from sympy.core.relational import Relational, Lt, Ge, Eq
  from sympy.core.symbol import Symbol, Dummy
  from sympy.sets.sets import Interval, FiniteSet, Union, Intersection
  from sympy.core.singleton import S
  from sympy.core.function import expand_mul
  from sympy.functions.elementary.complexes import Abs
  from sympy.logic import And
  from sympy.polys import Poly, PolynomialError, parallel_poly_from_expr
  from sympy.polys.polyutils import _nsort
  from sympy.solvers.solveset import solvify, solveset
  from sympy.utilities.iterables import sift, iterable
  from sympy.utilities.misc import filldedent
label_desc: Use image node_id 1 for calling a global function with example usage: solve_poly_inequality(poly, rel) and returns: intervals, list, list