# log1pmx

##### Accurate `log(1+x) - x`

Compute $$\log(1+x) - x$$ accurately also for small \(x\), i.e., \(|x| \ll 1\).

- Keywords
- math

##### Usage

`log1pmx(x, tol_logcf = 1e-14)`

##### Arguments

- x
numeric vector with values \(x > -1\).

- tol_logcf
a non-negative number indicating the tolerance (maximal relative error) for the auxiliary

`logcf()`

function.

##### Details

In order to provide full accuracy, the computations happens differently in three regions for \(x\), $$m_l = -0.79149064$$ is the first cutpoint,

- \(x < ml\) or \(x > 1\):
use

`log1pmx(x) := log1p(x) - x`

,- \(|x| < 0.01\):
use \(t((((2/9 * y + 2/7)y + 2/5)y + 2/3)y - x)\),

- \(x \in [ml,1]\), and \(|x| >= 0.01\):
use \(t(2y logcf(y, 3, 2) - x)\),

where \(t := \frac{x}{2 + x}\), and \(y := t^2\).

Note that the formulas based on \(t\) are based on the (fast converging) formula $$\log(1+x) = 2\left(r + \frac{r^3}{3}+ \frac{r^5}{5} + \ldots\right),$$ where \(r := x/(x+2)\), see the reference.

##### Value

a numeric vector (with the same attributes as `x`

).

##### References

Abramowitz, M. and Stegun, I. A. (1972)
*Handbook of Mathematical Functions*. New York: Dover.
https://en.wikipedia.org/wiki/Abramowitz_and_Stegun provides
links to the full text which is in public domain.
Formula (4.1.29), p.68.

##### See Also

`logcf`

, the auxiliary function,
`lgamma1p`

which calls `log1pmx`

, `log1p`

##### Examples

```
# NOT RUN {
l1x <- curve(log1pmx, -.9999, 7, n=1001)
abline(h=0, v=-1:0, lty=3)
l1xz <- curve(log1pmx, -.1, .1, n=1001); abline(h=0, v=0, lty=3)
l1xz2 <- curve(log1pmx, -.01, .01, n=1001); abline(h=0, v=0, lty=3)
l1xz3 <- curve(-log1pmx(x), -.002, .002, n=2001, log="y", yaxt="n")
sfsmisc::eaxis(2); abline(v=0, lty=3)
# }
```

*Documentation reproduced from package DPQ, version 0.3-3, License: GPL (>= 2)*