# NAG FL Interfacec05bbf (lambertw_​complex)

## 1Purpose

c05bbf computes the values of Lambert's $W$ function $W\left(z\right)$.

## 2Specification

Fortran Interface
 Subroutine c05bbf ( z, w,
 Integer, Intent (In) :: branch Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (Out) :: resid Complex (Kind=nag_wp), Intent (In) :: z Complex (Kind=nag_wp), Intent (Out) :: w Logical, Intent (In) :: offset
#include <nag.h>
 void c05bbf_ (const Integer *branch, const logical *offset, const Complex *z, Complex *w, double *resid, Integer *ifail)
The routine may be called by the names c05bbf or nagf_roots_lambertw_complex.

## 3Description

c05bbf calculates an approximate value for Lambert's $W$ function (sometimes known as the ‘product log’ or ‘Omega’ function), which is the inverse function of
 $fw = wew for w∈C .$
The function $f$ is many-to-one, and so, except at $0$, $W$ is multivalued. c05bbf allows you to specify the branch of $W$ on which you would like the results to lie by using the argument branch. Our choice of branch cuts is as in Corless et al. (1996), and the ranges of the branches of $W$ are summarised in Figure 1.
Figure 1: Ranges of the branches of $W\left(z\right)$
For more information about the closure of each branch, which is not displayed in Figure 1, see Corless et al. (1996). The dotted lines in the Figure denote the asymptotic boundaries of the branches, at multiples of $\pi$.
The precise method used to approximate $W$ is as described in Corless et al. (1996). For $z$ close to $-\mathrm{exp}\left(-1\right)$ greater accuracy comes from evaluating $W\left(-\mathrm{exp}\left(-1\right)+\Delta z\right)$ rather than $W\left(z\right)$: by setting ${\mathbf{offset}}=\mathrm{.TRUE.}$ on entry you inform c05bbf that you are providing $\Delta z$, not $z$, in z.

## 4References

Corless R M, Gonnet G H, Hare D E G, Jeffrey D J and Knuth D E (1996) On the Lambert $W$ function Advances in Comp. Math. 3 329–359

## 5Arguments

1: $\mathbf{branch}$Integer Input
On entry: the branch required.
2: $\mathbf{offset}$Logical Input
On entry: controls whether or not z is being specified as an offset from $-\mathrm{exp}\left(-1\right)$.
3: $\mathbf{z}$Complex (Kind=nag_wp) Input
On entry: if ${\mathbf{offset}}=\mathrm{.TRUE.}$, z is the offset $\Delta z$ from $-\mathrm{exp}\left(-1\right)$ of the intended argument to $W$; that is, $W\left(\beta \right)$ is computed, where $\beta =-\mathrm{exp}\left(-1\right)+\Delta z$.
If ${\mathbf{offset}}=\mathrm{.FALSE.}$, z is the argument $z$ of the function; that is, $W\left(\beta \right)$ is computed, where $\beta =z$.
4: $\mathbf{w}$Complex (Kind=nag_wp) Output
On exit: the value $W\left(\beta \right)$: see also the description of z.
5: $\mathbf{resid}$Real (Kind=nag_wp) Output
On exit: the residual $\left|W\left(\beta \right)\mathrm{exp}\left(W\left(\beta \right)\right)-\beta \right|$: see also the description of z.
6: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $-1$ is recommended since useful values can be provided in some output arguments even when ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
Note: in some cases c05bbf may return useful information.
${\mathbf{ifail}}=1$
For the given offset ${\mathbf{z}}$, $W$ is negligibly different from $-1$: $\mathrm{Re}\left({\mathbf{z}}\right)=〈\mathit{\text{value}}〉$ and $\mathrm{Im}\left({\mathbf{z}}\right)=〈\mathit{\text{value}}〉$.
${\mathbf{z}}$ is close to $-\mathrm{exp}\left(-1\right)$. Enter ${\mathbf{z}}$ as an offset to $-\mathrm{exp}\left(-1\right)$ for greater accuracy: $\mathrm{Re}\left({\mathbf{z}}\right)=〈\mathit{\text{value}}〉$ and $\mathrm{Im}\left({\mathbf{z}}\right)=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=2$
The iterative procedure used internally did not converge in $〈\mathit{\text{value}}〉$ iterations. Check the value of resid for the accuracy of w.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

For a high percentage of ${\mathbf{z}}$, c05bbf is accurate to the number of decimal digits of precision on the host machine (see x02bef). An extra digit may be lost on some platforms and for a small proportion of ${\mathbf{z}}$. This depends on the accuracy of the base-$10$ logarithm on your system.

## 8Parallelism and Performance

c05bbf is not threaded in any implementation.

The following figures show the principal branch of $W$.
Figure 2: $\mathrm{real}\left({W}_{0}\left(z\right)\right)$