C05 Chapter Contents
C05 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentC05BAF

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

C05BAF returns the real values of Lambert's $W$ function $W\left(x\right)$, via the routine name.

## 2  Specification

 FUNCTION C05BAF ( X, BRANCH, OFFSET, IFAIL)
 REAL (KIND=nag_wp) C05BAF
 INTEGER BRANCH, IFAIL REAL (KIND=nag_wp) X LOGICAL OFFSET

## 3  Description

C05BAF calculates an approximate value for the real branches of 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. C05BAF restricts $W$ and its argument $x$ to be real, resulting in a function defined for $x\ge -\mathrm{exp}\left(-1\right)$ and which is double valued on the interval $\left(-\mathrm{exp}\left(-1\right),0\right)$. This double-valued function is split into two real-valued branches according to the sign of $W\left(x\right)+1$. We denote by ${W}_{0}$ the branch satisfying ${W}_{0}\left(x\right)\ge -1$ for all real $x$, and by ${W}_{-1}$ the branch satisfying ${W}_{-1}\left(x\right)\le -1$ for all real $x$. You may select your branch of interest using the parameter BRANCH.
The precise method used to approximate $W$ is described fully in Barry et al. (1995). For $x$ close to $-\mathrm{exp}\left(-1\right)$ greater accuracy comes from evaluating $W\left(-\mathrm{exp}\left(-1\right)+\Delta x\right)$ rather than $W\left(x\right)$: by setting ${\mathbf{OFFSET}}=\mathrm{.TRUE.}$ on entry you inform C05BAF that you are providing $\Delta x$, not $x$, in X.

## 4  References

Barry D J, Culligan–Hensley P J, and Barry S J (1995) Real values of the $W$-function ACM Trans. Math. Software 21(2) 161–171

## 5  Parameters

1:     X – REAL (KIND=nag_wp)Input
On entry: if ${\mathbf{OFFSET}}=\mathrm{.TRUE.}$, X is the offset $\Delta x$ 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 x$.
If ${\mathbf{OFFSET}}=\mathrm{.FALSE.}$, X is the argument $x$ of the function; that is, $W\left(\beta \right)$ is computed, where $\beta =x$.
Constraints:
• if ${\mathbf{BRANCH}}=0$, $-\mathrm{exp}\left(-1\right)\le \beta$;
• if ${\mathbf{BRANCH}}=-1$, $-\mathrm{exp}\left(-1\right)\le \beta <0.0$.
2:     BRANCH – INTEGERInput
On entry: the real branch required.
${\mathbf{BRANCH}}=0$
The branch ${W}_{0}$ is selected.
${\mathbf{BRANCH}}=-1$
The branch ${W}_{-1}$ is selected.
Constraint: ${\mathbf{BRANCH}}=0$ or $-1$.
3:     OFFSET – LOGICALInput
On entry: controls whether or not X is being specified as an offset from $-\mathrm{exp}\left(-1\right)$.
4:     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: C05BAF 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$
An input parameter is invalid. If ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$ on entry, the output message provides more details of the nature of the warning.
${\mathbf{IFAIL}}=2$
Warning: the actual argument to $W$ was very close to $-\mathrm{exp}\left(-1\right)$. The output message provides more details of the nature of the warning.

## 7  Accuracy

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

None.

## 9  Example

This example reads from a file the values of the required branch, whether or not the arguments to $W$ are to be considered as offsets to $-\mathrm{exp}\left(-1\right)$, and the arguments ${\mathbf{X}}$ themselves. It then evaluates the function for these sets of input data ${\mathbf{X}}$ and prints the results.

### 9.1  Program Text

Program Text (c05bafe.f90)

### 9.2  Program Data

Program Data (c05bafe.d)

### 9.3  Program Results

Program Results (c05bafe.r)