8

What is a simple way to compute $10^x - 1$, where $x$ is close to zero?

Using exponentiation and then subtraction isn't good enough, because the fractional part is very small compared to the one that we subtract away.

J. M.
  • 3,155
  • 28
  • 37
Tom V
  • 83
  • 2
  • 7
    In terms of practical application, check whether your programming environment offers a function exp10m1, which is a recommend operation per IEEE-754 (2008) and provides exactly what you need. – njuffa Mar 24 '17 at 02:21

2 Answers2

14

Use the Taylor series expansion of $a^x$ about $x=0$ and evaluate a small number of terms for $a=10$:

$$a^x - 1 \approx x\log(a) + \frac{1}{2}x^2\log^2(a)+\cdots.$$

coolguy1000000
  • 991
  • 6
  • 14
13

Personally, in the absence of a special function like expm1 (see also this scicomp.SE question), I'd use a Padé approximant instead of a Taylor/Maclaurin series; usually, those have a slightly wider applicability for the same amount of computational effort.

I'll be discussing $\exp x-1$ for the rest of the answer, since $10^x-1=\exp(x\log 10)-1$.

To illustrate, here's a plot comparing the relative error of the $7$-th order Taylor polynomial

$$x+\frac{x^2}{2}+\frac{x^3}{6}+\frac{x^4}{24}+\frac{x^5}{120}+\frac{x^6}{720}+\frac{x^7}{5040}$$

and the $(4,3)$ Padé approximant

$$\frac{x+\frac{x^2}{14}+\frac{x^3}{42}+\frac{x^4}{840}}{1-\frac{3 x}{7}+\frac{x^2}{14}-\frac{x^3}{210}}$$

Taylor vs. Padé

Similar plots can be seen for order $2p+1$ Taylor polynomials vs. $(p+1,p)$ Padé approximants.


Another alternative presents itself, if your system has the $\sinh$ function: use the relation

$\exp x-1=2\exp\left(\frac{x}{2}\right)\sinh\left(\frac{x}{2}\right)$

Finally, Higham presents a neat trick in Accuracy and Stability of Numerical Algorithms (second edition, p. 19), and originally attributed to Kahan. Look there for more details.

J. M.
  • 3,155
  • 28
  • 37