c05 Chapter Contents
c05 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_lambertW (c05bac)

## 1  Purpose

nag_lambertW (c05bac) returns the real values of Lambert's $W$ function $W\left(x\right)$.

## 2  Specification

 #include #include
 double nag_lambertW (double x, Integer branch, Nag_Boolean offset, NagError *fail)

## 3  Description

nag_lambertW (c05bac) 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. nag_lambertW (c05bac) 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 argument 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{Nag_TRUE}$ on entry you inform nag_lambertW (c05bac) 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  Arguments

1:     xdoubleInput
On entry: if ${\mathbf{offset}}=\mathrm{Nag_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{Nag_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:     branchIntegerInput
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:     offsetNag_BooleanInput
On entry: controls whether or not x is being specified as an offset from $-\mathrm{exp}\left(-1\right)$.
4:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_INT
On entry, ${\mathbf{branch}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{branch}}=0$ or $-1$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_REAL
On entry, ${\mathbf{branch}}=-1$, ${\mathbf{offset}}=\mathrm{Nag_FALSE}$ and ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{branch}}=-1$ and ${\mathbf{offset}}=\mathrm{Nag_FALSE}$ then ${\mathbf{x}}<0.0$.
On entry, ${\mathbf{branch}}=-1$, ${\mathbf{offset}}=\mathrm{Nag_TRUE}$ and ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{branch}}=-1$ and ${\mathbf{offset}}=\mathrm{Nag_TRUE}$ then ${\mathbf{x}}<\mathrm{exp}\left(-1.0\right)$.
On entry, ${\mathbf{offset}}=\mathrm{Nag_TRUE}$ and ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{offset}}=\mathrm{Nag_TRUE}$ then ${\mathbf{x}}\ge 0.0$.
On entry, ${\mathbf{offset}}=\mathrm{Nag_FALSE}$ and ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{offset}}=\mathrm{Nag_FALSE}$ then ${\mathbf{x}}\ge -\mathrm{exp}\left(-1.0\right)$.
NW_REAL
For the given offset ${\mathbf{x}}$, $W$ is negligibly different from $-1$: ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
${\mathbf{x}}$ is close to $-\mathrm{exp}\left(-1\right)$. Enter ${\mathbf{x}}$ as an offset to $-\mathrm{exp}\left(-1\right)$ for greater accuracy: ${\mathbf{x}}=〈\mathit{\text{value}}〉$.

## 7  Accuracy

For a high percentage of legal ${\mathbf{x}}$ on input, nag_lambertW (c05bac) is accurate to the number of decimal digits of precision on the host machine (see nag_decimal_digits (X02BEC)). 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 (c05bace.c)

### 9.2  Program Data

Program Data (c05bace.d)

### 9.3  Program Results

Program Results (c05bace.r)