Numerical approximations of $2^x$ where $x$ is between $0$ and $1.0$?

131 Views Asked by At

I've been looking everywhere for this. I've found a billion ways to approximate e^x, and ln(x), and I know I could combine those, what I'm looking for here is an independent numerical method to calculate $2^x$ with $0.0 < x < 1.0$. there is one here but it appears to be using an auto generated polynomial coefficients for numerical approximation, and doesn't really go into detail of how they were chosen.

I figured there would be some series approximation or a analytically derived polynomial expansion, but it seems like that isn't the case (though in that event I'd like to know why, or at least why e^x does and 2^x doesn't).

When I say independent, I mean that the method isn't for say, $e^x$, and then uses some transformation to get to $2^x$. Here's what I don't want, some derivation that comes down to $exp(x * ln(2))$. Constant log terms like $ln(2)$ are fine, and if it some how helped, an $e^c$ constant would be fine as well. It just can't rely on needing an numerical approximation for $ln(x)$ or $e^x$ or $log_{10}$ etc...

4

There are 4 best solutions below

4
On

Note that $$2^x=e^{\ln(2)x}$$ you can approximate like before (using taylor series or linear approximation etc). $$1+x\ln(2)+\frac{(x\ln(2))^2}{2}...$$

3
On

The Chebyshev series for $2^x$ on the interval $[0,1]$ is $\sum_{n=0}^\infty c_n T_n(2x-1)$ where $$c_n = \frac{2}{\pi} \int_0^1 \frac{2^x T_n(2x-1)}{\sqrt{x-x^2}}\; dx$$ (except $c_0$ has $1/\pi$ instead of $2/\pi$) where $T_n$ are the Chebyshev polynomials of the first kind. The first few terms are $$\eqalign{& 1.45699987501296291\,T_0 \left(2\,x-1 \right) + 0.497524867810441862 \,T_1 \left( 2\,x-1 \right) \cr +& 0.0428931119896796484\,T_2 \left( 2\,x-1 \right) + 0.00247142816399587408\,T_3 \left( 2\,x-1 \right)\cr +& 0.000106906116358177253\,T_4 \left( 2\,x-1 \right) + 0.00000370138142770695859\,T_5 \left( 2\,x-1 \right)\cr +& 0.000000106823753743946597\,T_6 \left( 2\,x-1 \right) + 0.00000000264303276285357833\,T_7 \left( 2\,x-1 \right)} $$ which has maximum error less than $6 \times 10^{-11}$.

2
On

Starting from Robert Israel's answer, we have $$c_n=2 \sqrt{2}\, I_n\left(\frac{\log (2)}{2}\right)$$ where $I_n$ is the modified Bessel function of the first kind and,as Robert Israel wrote $$2^x= \sqrt{2}I_0\left(\frac{\log (2)}{2}\right)+2 \sqrt{2}\sum_{n=1}^\infty I_n\left(\frac{\log (2)}{2}\right)\, T_n(2x-1)$$

Computing the maximum error $\Delta$ for the partial sum up to $p$, a quick and dirty linear regression gives $(R^2=0.9986)$ $$\log_{10}(|\Delta|)=0.90352 -1.60856 \,p$$

If you accept $\color{blue}{a=\log(2)}$ to be part of the approximation and assuming that you are noot too much requiring about accuracy, you could use an $[n,n]$ Padé approximant built at $x=\frac 12$ and get, for example, $$\color{blue}{2 ^x \sim \sqrt 2\,\frac {1+\frac{a }{2}t+\frac{a^2 }{10}t^2+\frac{a^3 }{120}t^3 } {1-\frac{a }{2}t+\frac{a^2 }{10}t^2-\frac{a^3 }{120}t^3 }}\qquad \text{where} \qquad \color{blue}{t=x-\frac 12}$$ which leads to a maximum error equal to $1.2 \times 10^{-8}$.

Edit

If we use the $[n,n]$ Padé approximant built at $x=\frac 12$,we have $(R^2=0.9981)$ $$\log_{10}(|\Delta|)=1.23774 -3.13141 \,n$$ For $n=5$, it would be $$\color{blue}{2^x\sim \sqrt 2\,\frac{30240+15120 y+3360 y^2+420 y^3+30 y^4+y^5} {30240-15120 y+3360 y^2-420 y^3+30 y^4-y^5 }}$$ where $\color{blue}{y=\left(x-\frac{1}{2}\right) \log (2)}$ and the maximum error is $2.44\times 10^{-15}$.

In fact, the general $[n,n]$ Padé approximant built at $x=\frac 12$ can write as $$\color{red}{2^x \sim \sqrt 2\,\frac{\sum_{k=0}^n \frac{(k+n)! }{k! (n-k)!}y^{n-k}} { \sum_{k=0}^n (-1)^{k-1} \frac{(k+n)! }{k! (n-k)!}y^{n-k}}}\qquad \text{where} \qquad \color{red}{y=\left(x-\frac{1}{2}\right) \log (2)}$$

5
On

Write $2=\frac{\frac32}{\frac34}=\frac{1+\frac12}{1-\frac14}$ or similarly $2=\frac{1+\frac13}{1-\frac13}$ and apply the binomial series with a sufficiently large number of terms $$ 2^x=\frac{\sum_{k=0}^\infty \binom{x}{k}2^{-k}}{\sum_{k=0}^\infty \binom{x}{k}(-1)^k4^{-k}} ~~\text{ or }~~ 2^x=\frac{\sum_{k=0}^\infty \binom{x}{k}3^{-k}}{\sum_{k=0}^\infty \binom{x}{k}(-1)^k3^{-k}} $$ This of course suffers the fate of all Taylor expansions in that it has very small errors at the development point and large errors at the other end of the interval under consideration. One could reduce that a little by using $2^x=2/2^{1-x}$ for $x$ closer to $1$, or suitably combine both approximations.