2.4 Computing Natural Logarithms

A process for computing the natural logarithm of any arbitrary number \(x>0\) is now prescribed. We start by describing a simple infinite geometric series, namely,

\[ S_1 \equiv a + ar + ar^2 + ar^3 + ar^4 + \ldots \]

where \(|r|< 1\). If we multiply this series by \(r\) we form a new series

\[ S_2 = rS_1 = ar + ar^2 + ar^3 + ar^4 + ar^5 + \ldots \]

But note that if we add \(a\) to \(S_2\), which is itself an infinite series, then we get \(S_1\) again:

\[ a + S_2 = a + (ar + ar^2 + ar^3 + ar^4 + ar^5 + \ldots) = a + ar + ar^2 + ar^3 + ar^4 + ar^5 + \ldots = S_1 \]

and since we defined \(S_2 = rS_1\) we see that \(a + rS_1 = S_1\), or \(S_1 = \frac{a}{1-r}\). That is, the infinite series

\[ a + ar + ar^2 + ar^3 + ar^4 + \ldots = \frac{a}{1-r} \]

which converges to a finite number when \(r<1\). Now, if we let \(a=1\) and \(r=-z\), then we find that we can write

\[ \frac{1}{1+z} = 1 - z + z^2 - z^3 + z^4 - ... \]

which will be true for \(-1 < z < 1\). And this we will use to compute the integral defining \(\ln x\). Because now, from our definition of \(\ln x\), we find that

\[\begin{eqnarray*} \ln x &=& \int_1^x \frac{1}{u}\;du = \int_0^{x-1}\frac{1}{1+z}\; dz ~~~~~~~(z = u-1)\\ &=& \int_0^{x-1} \left( 1 - z + z^2 - z^3 + z^4 - ... \right)\;dz \\ &=& \left( z - \frac{1}{2}z^2 + \frac{1}{3}z^3 - \frac{1}{4}z^4 +\frac{1}{5}z^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 arrive at our final result:

\[ \ln (1+x) = x - \frac{1}{2}x^2 + \frac{1}{3}x^3 - \frac{1}{4}x^4 +\frac{1}{5}x^5 - ... \]

We note, too, that the formula will still be valid when \(x=1\), as the series still converges, and hence works so long as \(-1<x\le 1\). For \(-1<x<0\) all of the terms in the above power series are negative, thus the logarithm is negative as desired, and as \(x\rightarrow -1\) the logarithm \(\ln(1+x)\rightarrow -\infty\).

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 real numbers greater than zero and up to 2 can be computed to any required accuracy using the above power series.

But what about computing 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, both of which can be computed with our power series. 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. In other words, to find the natural logarithm of a general number \(z\), we can divide \(z\) by two a number of times until, say after \(n\) times, the remainder \(r\) is less than two. Then, we just need to compute

\[ \ln z = n~\ln 2 + \ln[1+~(r-1)~]. \]

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.


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. First, we write a function for computing the natural logarithm of \(x\), where \(0<x\le 2.\)

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
}

Some examples:

  • lnX(0.64) = -0.446287
  • lnX(1) = 0
  • lnX(1.75) = 0.5596157
  • lnX(2) = 0.6931472

Now, let’s calculate the natural logarithm of 10:

ln2   = lnX(2)
ln125 = lnX(1.25)
ln10  = 3*ln2 + ln125

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.