## 2.4 Computing Natural Logarithms

A process for computing the natural logarithm of the number $$x$$ is now prescribed. Using the Taylor Series technique once again, we can take derivatives of the function $$y(u) = 1/(1+u)$$ and express the result in a power series form. Doing so, it can be shown that for values of $$-1< u \le 1$$, $\frac{1}{1+u} = 1 - u + u^2 - u^3 + u^4 - ...$ We’ll use this fact to compute the integral defining $$\ln x$$: $\begin{eqnarray*} \ln x &=& \int_1^x \frac{1}{z}\;dz = \int_0^{x-1}\frac{1}{1+u}\; du ~~~~~~~(u = z-1)\\ &=& \int_0^{x-1} \left( 1 - u + u^2 - u^3 + u^4 - ... \right)\;du \\ &=& \left( u - \frac{1}{2}u^2 + \frac{1}{3}u^3 - \frac{1}{4}u^4 +\frac{1}{5}u^5 - ... \right)\bigg\rvert_0^{x-1} \\ &=& (x-1) - \frac{1}{2}(x-1)^2 + \frac{1}{3}(x-1)^3 - \frac{1}{4}(x-1)^4 +\frac{1}{5}(x-1)^5 - ... \end{eqnarray*}$ And so, by replacing $$x$$ with $$1+x$$ on both sides of the equation, we can write $\ln (1+x) = x - \frac{1}{2}x^2 + \frac{1}{3}x^3 - \frac{1}{4}x^4 +\frac{1}{5}x^5 - ...$ where, again, this formula is only valid for $$-1 < x \le 1$$. For $$x<0$$ all of the terms in the above power series are negative, and so as $$x\rightarrow -1$$ the logarithm $$\ln(1+x)\rightarrow -\infty$$. (In fact, the series does not converge for $$x=-1$$.) For $$x=0$$ we get $$\ln 1 = 0$$ as we should. And we can compute a logarithm for any number greater than zero up to 2 (i.e., $$x$$ = 1). Thus, natural logarithms for all relevant numbers greater than zero and up to 2 can be computed to any required accuracy using the above power series.

But what about a value for $$\ln 3$$, for instance? Well, $$\ln 3 = \ln(2\times 1.5)$$ = $$\ln 2$$ + $$\ln 1.5$$ and so $$\ln 3$$ can be computed by addition of these two logarithms. What about a number like $$\ln 22.8$$? Similarly, we can write $$\ln 22.8 = \ln (2^4\times 1.425)$$ = $$4\ln 2+\ln(1+0.425)$$ and we have all that is necessary for performing this calculation. Through the use of our power series formula the natural logarithm for any number of interest may be computed to any desired accuracy, in principle.

And ultimately, what we have been interested in from the beginning is the computation of Base 10 or common logarithms. We know that $\log x = \ln x / \ln 10$ from our basic rule for changing bases, and so if we can compute $$\ln x$$ then we only need to divide by $$\ln 10$$ to obtain the common logarithm of $$x$$. From our previous argument, $\ln 10 = \ln (8\times 5/4) = \ln( 2^3 ) + \ln 1.25 = 3 \ln(1+1) + \ln(1+0.25).$ Let’s do it:

lnX = function(x){
x = x-1
lnCalc = 0
n = 0
while(abs(x^(n+1) / (n+1))>1e-7){
n=n+1
lnCalc = lnCalc + (-1)^(n-1) * x^n / n
}
lnCalc
}
ln10  = 3*lnX(2) + lnX(1.25)

The results:

 lnX(2) = 0.69315 lnX(1.25) = 0.22314 ln10 = 2.30259

So since we have just computed the value of $$\ln 10$$ and since we have a general formula that can be used for computing $$\ln x$$, we now have everything we need to compute the common logarithm $$\log x$$ for any arbitrary positive number.