code: def _(f, x):
      from sympy.solvers.solveset import solveset
      from sympy.series import limit
  
      # TODO: handle functions with infinitely many solutions (eg, sin, tan)
      # TODO: handle multivariate functions
  
      expr = f.expr
      if len(expr.free_symbols) > 1 or len(f.variables) != 1:
          return
      var = f.variables[0]
      if not var.is_real:
          if expr.subs(var, Dummy(real=True)).is_real is False:
              return
  
      if expr.is_Piecewise:
          result = S.EmptySet
          domain_set = x
          for p_expr, p_cond in expr.args:
              if p_cond is true:
                  intrvl = domain_set
              else:
                  intrvl = p_cond.as_set()
                  intrvl = Intersection(domain_set, intrvl)
  
              if p_expr.is_Number:
                  image = FiniteSet(p_expr)
              else:
                  image = imageset(Lambda(var, p_expr), intrvl)
              result = Union(result, image)
  
              # remove the part which has been `imaged`
              domain_set = Complement(domain_set, intrvl)
              if domain_set is S.EmptySet:
                  break
          return result
  
      if not x.start.is_comparable or not x.end.is_comparable:
          return
  
      try:
          from sympy.polys.polyutils import _nsort
  
          sing = list(singularities(expr, var, x))
          if len(sing) > 1:
              sing = _nsort(sing)
      except NotImplementedError:
          return
  
      if x.left_open:
          _start = limit(expr, var, x.start, dir="+")
      elif x.start not in sing:
          _start = f(x.start)
      if x.right_open:
          _end = limit(expr, var, x.end, dir="-")
      elif x.end not in sing:
          _end = f(x.end)
  
      if len(sing) == 0:
          soln_expr = solveset(diff(expr, var), var)
          if not (
              isinstance(soln_expr, FiniteSet)
              or soln_expr is S.EmptySet
          ):
              return
          solns = list(soln_expr)
  
          extr = [_start, _end] + [
              f(i) for i in solns if i.is_real and i in x
          ]
          start, end = Min(*extr), Max(*extr)
  
          left_open, right_open = False, False
          if _start <= _end:
              # the minimum or maximum value can occur simultaneously
              # on both the edge of the interval and in some interior
              # point
              if start == _start and start not in solns:
                  left_open = x.left_open
              if end == _end and end not in solns:
                  right_open = x.right_open
          else:
              if start == _end and start not in solns:
                  left_open = x.right_open
              if end == _start and end not in solns:
                  right_open = x.left_open
  
          return Interval(start, end, left_open, right_open)
      else:
          return (
              imageset(f, Interval(x.start, sing[0], x.left_open, True))
              + Union(
                  *[
                      imageset(
                          f, Interval(sing[i], sing[i + 1], True, True)
                      )
                      for i in range(0, len(sing) - 1)
                  ]
              )
              + imageset(
                  f, Interval(sing[-1], x.end, True, x.right_open)
              )
          )
  
imports: from sympy.core.singleton import S
  from sympy.sets.sets import Set
  from sympy.calculus.singularities import singularities
  from sympy.core import Expr, Add
  from sympy.core.function import Lambda, FunctionClass, diff, expand_mul
  from sympy.core.numbers import Float, oo
  from sympy.core.symbol import Dummy, symbols, Wild
  from sympy.functions.elementary.exponential import exp, log
  from sympy.functions.elementary.miscellaneous import Min, Max
  from sympy.logic.boolalg import true
  from sympy.multipledispatch import Dispatcher
  from sympy.sets import imageset, Interval, FiniteSet, Union, ImageSet, Intersection, Range, Complement
  from sympy.sets.sets import EmptySet, is_function_invertible_in_set
  from sympy.sets.fancysets import Integers, Naturals, Reals
  from sympy.functions.elementary.exponential import match_real_imag
label_desc: Use image node_id 3 for calling a global function with example usage: _(f, x) and returns: result, Interval, unknown