code: def lambertw(ctx, z, k=0):
      z = ctx.convert(z)
      k = int(k)
      if not ctx.isnormal(z):
          return _lambertw_special(ctx, z, k)
      prec = ctx.prec
      ctx.prec += 20 + ctx.mag(k or 1)
      wp = ctx.prec
      tol = wp - 5
      w, done = _lambertw_series(ctx, z, k, tol)
      if not done:
          # Use Halley iteration to solve w*exp(w) = z
          two = ctx.mpf(2)
          for i in xrange(100):
              ew = ctx.exp(w)
              wew = w * ew
              wewz = wew - z
              wn = w - wewz / (
                  wew + ew - (w + two) * wewz / (two * w + two)
              )
              if ctx.mag(wn - w) <= ctx.mag(wn) - tol:
                  w = wn
                  break
              else:
                  w = wn
          if i == 100:
              ctx.warn(
                  "Lambert W iteration failed to converge for z = %s"
                  % z
              )
      ctx.prec = prec
      return +w
  
imports: from ..libmp.backend import xrange
  import math
  import cmath
label_desc: Use image node_id 41 for calling a global function with example usage: lambertw(ctx, z, k) and returns: unknown, _lambertw_special