C05 Chapter Contents
C05 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentC05BBF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

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

## 2  Specification

 SUBROUTINE C05BBF ( BRANCH, OFFSET, Z, W, RESID, IFAIL)
 INTEGER BRANCH, IFAIL REAL (KIND=nag_wp) RESID COMPLEX (KIND=nag_wp) Z, W LOGICAL OFFSET

## 3  Description

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 parameter 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.

## 4  References

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

## 5  Parameters

1:     $\mathrm{BRANCH}$ – INTEGERInput
On entry: the branch required.
2:     $\mathrm{OFFSET}$ – LOGICALInput
On entry: controls whether or not Z is being specified as an offset from $-\mathrm{exp}\left(-1\right)$.
3:     $\mathrm{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:     $\mathrm{W}$ – COMPLEX (KIND=nag_wp)Output
On exit: the value $W\left(\beta \right)$: see also the description of Z.
5:     $\mathrm{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:     $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if ${\mathbf{IFAIL}}\ne {\mathbf{0}}$ on exit, the recommended value is $-1$. When the value $-\mathbf{1}\text{​ or ​}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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: C05BBF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
${\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$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

## 7  Accuracy

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.

Not applicable.

## 9  Further Comments

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