Natural logarithm
High precision

To compute the natural logarithm with many digits of precision, the Taylor series approach is not efficient since the convergence is slow. Especially if x is near 1, a good alternative is to use Halley's method or Newton's method to invert the exponential function, because the series of the exponential function converges more quickly. For finding the value of y to give exp (y) − x = 0 {\displaystyle \exp(y)-x=0} using Halley's method, or equivalently to give exp (y / 2) − x exp (− y / 2) = 0 {\displaystyle \exp(y/2)-x\exp(-y/2)=0} using Newton's method, the iteration simplifies to y n + 1 = y n + 2 ⋅ x − exp (y n) x + exp (y n) {\displaystyle y_{n+1}=y_{n}+2\cdot {\frac {x-\exp(y_{n})}{x+\exp(y_{n})}}} which has cubic convergence to ln (x) {\displaystyle \ln(x)}.

Another alternative for extremely high precision calculation is the formula ln x ≈ π 2 M (1, 4 / s) − m ln 2, {\displaystyle \ln x\approx {\frac {\pi }{2M(1,4/s)}}-m\ln 2,} where M denotes the arithmetic-geometric mean of 1 and 4/ s, and s = x 2 m > 2 p / 2, {\displaystyle s=x2^{m}>2^{p/2},} with m chosen so that p bits of precision is attained. (For most purposes, the value of 8 for m is sufficient.) In fact, if this method is used, Newton inversion of the natural logarithm may conversely be used to calculate the exponential function efficiently. (The constants ln 2 {\displaystyle \ln 2} and π can be pre-computed to the desired precision using any of several known quickly converging series.) Or, the following formula can be used: ln x = π M (θ 2 2 (1 / x), θ 3 2 (1 / x)), x ∈ (1, ∞) {\displaystyle \ln x={\frac {\pi }{M\left(\theta _{2}^{2}(1/x),\theta _{3}^{2}(1/x)\right)}},\quad x\in (1,\infty)}

where θ 2 (x) = ∑ n ∈ Z x (n + 1 / 2) 2, θ 3 (x) = ∑ n ∈ Z x n 2 {\displaystyle \theta _{2}(x)=\sum _{n\in \mathbb {Z} }x^{(n+1/2)^{2}},\quad \theta _{3}(x)=\sum _{n\in \mathbb {Z} }x^{n^{2}}} are the Jacobi theta functions.

Based on a proposal by William Kahan and first implemented in the Hewlett-Packard HP-41C calculator in 1979 (referred to under "LN1" in the display, only), some calculators, operating systems (for example Berkeley UNIX 4.3BSD), computer algebra systems and programming languages (for example C99) provide a special natural logarithm plus 1 function, alternatively named LNP1, or log1p to give more accurate results for logarithms close to zero by passing arguments x, also close to zero, to a function log1p(x), which returns the value ln(1+ x), instead of passing a value y close to 1 to a function returning ln(y). The function log1p avoids in the floating point arithmetic a near cancelling of the absolute term 1 with the second term from the Taylor expansion of the natural logarithm. This keeps the argument, the result, and intermediate steps all close to zero where they can be most accurately represented as floating-point numbers.

In addition to base e, the IEEE 754-2008 standard defines similar logarithmic functions near 1 for binary and decimal logarithms: log (1 + x) and log (1 + x).

Similar inverse functions named " expm1 ", "expm" or "exp1m" exist as well, all with the meaning of expm1(x) = exp(x) − 1.

An identity in terms of the inverse hyperbolic tangent, l o g 1 p (x) = log (1 + x) = 2 a r t a n h (x 2 + x), {\displaystyle \mathrm {log1p} (x)=\log(1+x)=2~\mathrm {artanh} \left({\frac {x}{2+x}}\right)\,,} gives a high precision value for small values of x on systems that do not implement log1p(x).
detectable_content:number_placeholders[2], oulipo:avoid_letter[t]