Key idea of this section
ln(1 + x) = x − x²/2 + x³/3 − x⁴/4 + … exactly for −1 < x ≤ 1 ln((1 + y)/(1 − y)) = 2(y + y³/3 + y⁵/5 + …) for |y| < 1
Derivation with an exact remainder
The series is due to Nicholas Mercator (Logarithmotechnia, 1668), and was found independently by Newton in 1665; two decades earlier Grégoire de Saint-Vincent and Alphonse Antonio de Sarasa had observed that areas under the hyperbola y = 1/x behave like logarithms. We derive it with an exact remainder. For t ≠ −1 and n ≥ 1 the finite geometric sum gives
1/(1 + t) = 1 − t + t² − … + (−t)ⁿ⁻¹ + (−t)ⁿ/(1 + t).
Integrating from 0 to x > −1 and using ln(1 + x) = ∫₀ˣ dt/(1 + t),
ln(1 + x) = ∑ₖ₌₁ⁿ (−1)ᵏ⁺¹ xᵏ/k + Rₙ(x), Rₙ(x) = (−1)ⁿ ∫₀ˣ tⁿ/(1 + t) dt.
Theorem 5.1. The series ∑k≥1 (−1)ᵏ⁺¹ xᵏ/k converges to ln(1 + x) if and only if −1 < x ≤ 1. Its radius of convergence is 1; it converges absolutely for |x| < 1, conditionally at x = 1, and diverges at x = −1.
Proof. For 0 ≤ x ≤ 1, 1 + t ≥ 1 on [0, x], so |Rₙ(x)| ≤ ∫₀ˣ tⁿ dt = xⁿ⁺¹/(n + 1) → 0. For −1 < x < 0, write x = −r with 0 < r < 1; on [x, 0] we have 1 + t ≥ 1 − r, so |Rₙ(x)| ≤ rⁿ⁺¹/((n + 1)(1 − r)) → 0. At x = −1 the series is −∑ 1/k, which diverges; for |x| > 1 the terms do not tend to 0. Absolute convergence for |x| < 1 follows from the ratio test, and at x = 1 the series ∑ (−1)ᵏ⁺¹/k is not absolutely convergent. ∎
At x = 1 we obtain the alternating harmonic series:
ln 2 = 1 − 1/2 + 1/3 − 1/4 + … ,
with error at most 1/(n + 1) after n terms. It converges far too slowly for computation: a million terms give only six correct decimals.
Rearrangements
Because the convergence at x = 1 is conditional, the Riemann rearrangement theorem says that the terms can be reordered to converge to any prescribed real number. A classical example takes one positive term followed by two negative terms:
1 − 1/2 − 1/4 + 1/3 − 1/6 − 1/8 + 1/5 − 1/10 − 1/12 + … = ½ ln 2.
Proof. Group the terms in threes. The k-th group is 1/(2k − 1) − 1/(4k − 2) − 1/(4k) = 1/(4k − 2) − 1/(4k) = ½(1/(2k − 1) − 1/(2k)). Summing over k gives ½ ln 2 for the grouped series, and since the individual terms tend to 0, the ungrouped series has the same sum. ∎
More generally (Pringsheim), taking p positive terms followed by q negative terms produces ln 2 + ½ ln(p/q).
Acceleration by the inverse hyperbolic tangent
Subtracting the series for ln(1 − y) from that for ln(1 + y) cancels the even powers:
ln((1 + y)/(1 − y)) = 2 ∑k≥0 y²ᵏ⁺¹/(2k + 1) = 2 artanh y, |y| < 1.
Every x > 0 can be written as (1 + y)/(1 − y) with y = (x − 1)/(x + 1) ∈ (−1, 1), so this single series computes every natural logarithm. For x = 2 we get y = 1/3, and
ln 2 = 2(1/3 + 1/81 + 1/1215 + 1/15309 + …).
Four terms give 0.6931348, with error about 1.24·10⁻⁵. Each further term gains roughly a factor of 9 = 1/y² in accuracy. The truncation error after the term with y²ⁿ⁻¹ is bounded by 2y²ⁿ⁺¹/((2n + 1)(1 − y²)).
Machin-type formulas
To make y even smaller one writes ln 2 as a combination of logarithms of rationals very close to 1. Since artanh(1/26) = ½ ln(27/25), artanh(1/4801) = ½ ln(2401/2400) and artanh(1/8749) = ½ ln(4375/4374), and these ratios factor over the primes 2, 3, 5, 7, one can solve for ln 2 and obtain, for instance,
ln 2 = 18 artanh(1/26) − 2 artanh(1/4801) + 8 artanh(1/8749),
a formula of the same kind as Machin's formula for π, and used in record computations of ln 2. Here 1/26 makes each term gain a factor of 676, so a few dozen terms deliver dozens of digits. Once ln 2, ln 3, ln 5 and ln 7 are known, ln x for any x can be obtained by range reduction: write x = 2ᵐ·u with u near 1 and evaluate ln u by the artanh series.
The arithmetic–geometric mean method
For very high precision a quadratically convergent method is used. The arithmetic–geometric mean M(a, b) of a, b > 0 is the common limit of aₙ₊₁ = (aₙ + bₙ)/2, bₙ₊₁ = √(aₙbₙ), and the error roughly squares at each step. A theorem going back to Gauss and made effective by Salamin, Brent and the Borweins states that for large s,
ln s = π / (2 M(1, 4/s)) + O(ln s / s²).
Choosing s = 2ᵐ·x with m large, and subtracting m ln 2, yields ln x to N digits in O(log N) AGM iterations. This is how arbitrary-precision libraries compute logarithms of millions of digits.
The logarithm in floating-point hardware
A practical libm logarithm does three things: it extracts the binary exponent m and mantissa u ∈ [1, 2) from the floating-point representation, so that ln x = m ln 2 + ln u; it reduces u further using a small table of values ln cᵢ with u/cᵢ close to 1; and it evaluates ln(u/cᵢ) by a short minimax polynomial. The constant ln 2 is stored in two pieces (a high part with trailing zero bits and a low correction) so that m·ln 2 is computed without rounding error. Correctly rounded logarithms, as in the CORE-MATH project, additionally need to rule out hard-to-round cases.
Exercise
- (a)How many terms of the alternating harmonic series are needed to guarantee an error below 10⁻⁴ for ln 2?
- (b)Use the artanh series with x = 3/2 (so y = 1/5) to compute ln(3/2) to five decimal places, and deduce ln 3 from ln 2 = 0.693147.
- (c)Find the radius and interval of convergence of ∑k≥1 xᵏ/(k·3ᵏ), and its sum.
Show solution
Answers: (a) The remainder bound |Rₙ(1)| ≤ 1/(n + 1) guarantees an error below 10⁻⁴ once n + 1 > 10⁴, that is, for n ≥ 10000. (The true error is close to 1/(2n), so in fact about 5000 terms come close to this accuracy.) (b) 2(1/5 + 1/375 + 1/15625 + 1/546875) = 2(0.2 + 0.0026667 + 0.000064 + 0.0000018) = 0.405465, and ln(3/2) = 0.405465…; then ln 3 = ln 2 + ln(3/2) ≈ 0.693147 + 0.405465 = 1.098612. (c) The series is −ln(1 − x/3). The radius is 3; it converges for −3 ≤ x < 3 (conditionally at x = −3, where the sum is −ln 2) and diverges at x = 3.