If you do a Taylor polynomial for $\ln(x)$ at 1 you can approximate:
$$\ln(2) \approx \sum^n_{k=1} \frac{(-1)^k}{k}$$
The problem is that this converges really slowly, for an error of at most $\frac{1}{n}$ you need to sum $n$ terms.
Are there better approximations?
- 427,504
- 2,205
-
There are many series which converge more rapidly at this wiki for the natural logarithm of 2. – Carl Christian Jun 13 '20 at 15:05
6 Answers
Similar to @Lutz Lehmann's answer $$\log(2)=-\log \left(\frac{1}{2}\right)=-\log \left(\frac{1-\frac{1}{3}}{1+\frac{1}{3}}\right)=2\sum_{n=0}^\infty\frac {(-1)^{n+1} }{(2n+1)\,3^{2n+1}}$$ which is alternating.
So, writing $$\log(2)=2\sum_{n=0}^p\frac {(-1)^{n+1} }{(2n+1)\,3^{2n+1}}+2\sum_{n=p+1}^\infty\frac {(-1)^{n+1} }{(2n+1)\,3^{2n+1}}$$ looking for $p$ in order to have $k$ exact significant figures, you need to solve for $p$ the equation $$\frac {2}{(2p+3)\,3^{2p+3}}=10^{-k}\implies p=\frac{W\left(2 \log (3) 10^k\right)}{2 \log (3)}-\frac{3}{2}$$ where $W(.)$ is Lambert function.
A very good approximation is just $p \sim k-\log(10)$ (which is not very fast).
Much faster would be to use one of the Machin like formulae for $\log(2)$ $$144 \tanh ^{-1}\left(\frac{1}{251}\right)+54 \tanh ^{-1}\left(\frac{1}{449}\right)-38 \tanh ^{-1}\left(\frac{1}{4801}\right)+62 \tanh ^{-1}\left(\frac{1}{8749}\right)$$ and use the series expansion $$\tanh ^{-1}(x)=\sinh ^{-1}\left(\frac{x}{\sqrt{1-x^2}}\right)=\sum_{n=0}^\infty \frac{(-1)^n (2 n)! }{4^n(2 n+1) (n!)^2} \left(\frac{x}{\sqrt{1-x^2}}\right)^{2 n+1}$$ Computing the partial sums from $0$ to $p$, this gives $$\left( \begin{array}{cc} p & \text{partial sum} \\ 0 & \color{red} { 0.69314}879768524097705624889400775230453401054328895 \\ 1 & \color{red} { 0.6931471805}4888240122015467945517617637052089006247 \\ 2 & \color{red} { 0.693147180559945}41250031627789944252986567946384249 \\ 3 & \color{red} { 0.69314718055994530941}612343717574660943915747172139 \\ 4 & \color{red} { 0.6931471805599453094172321}3439904033679757948070744 \\ 5 & \color{red} { 0.693147180559945309417232121458}01731170065313419101 \\ 6 & \color{red} { 0.6931471805599453094172321214581765}7010956709552748 \\ 7 & \color{red} { 0.693147180559945309417232121458176568075}47342767602 \\ 8 & \color{red} { 0.693147180559945309417232121458176568075500134}71847 \\ 9 & \color{red} { 0.6931471805599453094172321214581765680755001343602}5 \\ 10 & \color{red}{ 0.69314718055994530941723212145817656807550013436026} \end{array} \right)$$
Edit
The advantage of using the alternating series $$\tanh ^{-1}(x)=\sum_{n=0}^\infty \frac{(-1)^n (2 n)! }{4^n(2 n+1) (n!)^2} \left(\frac{x}{\sqrt{1-x^2}}\right)^{2 n+1}$$ is that $$ \left|\frac{b_{n+1}}{b_n}\right|=\frac{4 n^2+4 n+1}{2 (n+1) (2 n+3)}\frac{x}{\sqrt{1-x^2}} \to \frac{x}{\sqrt{1-x^2}}$$ which is very fast with so small values of $x$.
Moreover, we can easily know how many terms are required in order to have $$R_n=\frac{(2 n)! }{4^n(2 n+1) (n!)^2} \left(\frac{x}{\sqrt{1-x^2}}\right)^{2 n+1} \leq 10^{-k}$$ Using Stirling approximation and truncating to $O\left(\frac{1}{n^2}\right)$, we finally have $$n \geq -\frac{3 }{2 \log (a)}W(-A)\quad \text{with} \quad a=\frac{x}{\sqrt{1-x^2}}\quad \text{and} \quad A=\frac{\log(a)} 3\sqrt[3]{\frac{2 }{ \pi }10^{2 k}}$$
For example, using $x=\frac 1 {100}$ and $k=50$, this gives $n=\lceil 23.6945\rceil=24$.
Checking $$R_{23}=2.49\times 10^{-49}\qquad \text{and} \qquad R_{24}=2.34\times 10^{-51}$$
- 260,315
-
1I believe there is a mistake in your first series. It should not be alternating since you are using the Taylor series of $\tanh^{-1}$ and not that of $\tan^{-1}$. In fact, it should be the same series as the one by @Lutz Lehmann. – Gary Jun 15 '20 at 11:34
-
@Gary. I do not think so. I used $\sinh ^{-1}\left(\frac{x}{\sqrt{1-x^2}}\right)=\tanh ^{-1}(x)$ and then the expansion of $\sinh ^{-1}(y)$ with $y=\frac{x}{\sqrt{1-x^2}}$ – Claude Leibovici Jun 19 '20 at 07:02
-
Another frequently used expansion is $$ \ln(2)=\ln(\frac43)-\ln(\frac23)=\sum_{k=0}^\infty\frac2{3(2k+1)\cdot9^k} $$ There are other decompositions with arguments closer to $1$ (similar to the Euler-Machin like formulas for $\pi=4\arctan(1)$), but it is an open question if there is one that gives faster than this kind of linear convergence.
- 126,666
Since $\log(2)=-\log\left(\frac12\right)$ and since the Taylor series of the $\log$ function converges fast at $\frac12$, you can use this fact to compute $\log(2)$ quite fast.
- 427,504
-
2This needs less then $\log_2(k)$ terms for an error of at most $\frac{1}{k}$ – razivo Jun 13 '20 at 14:04
Maybe apply Newton's method to the equation $e^x -2=0$? The numerical scheme could be something like $x_0=1, \quad x_{n+1} = x_n - \dfrac{e^{x_n}-2}{e^{x_n}}=x_n-1+2e^{-x_n}$. The convergence will be fast, but it implies that you can accurately compute the exponential. The error committed when approximating $\ln 2$ by $x_3$ is close to $0.4 \times 10^{-6}$.
- 20,974
- 1
- 18
- 34
-
1I’d think that calculating the exponential to the required degree of accuracy will lead to diminishing returns as higher accuracy is needed. – razivo Jun 13 '20 at 13:41
-
Also, I will prefer not to need to calculate the exponential accurately. – razivo Jun 13 '20 at 13:42
-
2@razivo Run some numerical tests... the point is that you only need very few iterations of the Newton method and the power series of the exponential will converge faster than the one for the logarithm. – PierreCarre Jun 13 '20 at 13:43
-
If I want an error(at most) of $\frac{1}{n}$, how accurate would the exponential need to be( how many Taylor series terms) and how many iterations will be needed? – razivo Jun 13 '20 at 13:51
-
@razivo I've added some another answer which adds onto this answer and explains to some degree how/why this can be used to give very fast convergence with very few terms needed to evaluate the exponential. – Simply Beautiful Art Aug 28 '20 at 23:29
This answer adds onto PierreCarre's answer and is too long for a comment.
The cost of multiple evaluations of the exponential function when applying root-finding methods to $e^x-2$ are rapidly decreasing. Note that for Newton's method, one has
$$x_{n+1}=x_n-\Delta x_n,\quad\Delta x_n=1-2\exp(-x_n)$$
so that the next exponential function evaluated is
$$\exp(-x_{n+1})=\exp(-x_n+\Delta x_n)=\exp(-x_n)\exp(\Delta x_n)$$
where $\exp(-x_n)$ is already known and $\exp(\Delta x_n)$ can be computed extremely rapidly. As $x_n$ becomes more accurate, $\Delta x_n$ decreases, so less and less terms are needed to compute $\exp(\Delta x_n)$.
This essentially leaves only the initial evaluation of $\exp(x_0)$, which takes roughly $d/\log_{10}(d)$ iterations to compute to $d$ digits.
Additional notes:
An improved initial estimate should be taken from the other answers, using only their first few terms.
Since higher order derivatives are all just $e^x$, Householder methods such as Halley's method may be easily used to give faster iterative refinement.
- 74,685
Use Simpson's rule at $n=10$ and the definite integral definition of natural logarithm.
- 9,727