Calculating By Hand (I): $\ln2$
16 Aug 2018Over the Simcoe Day long weekend, I got back into one of my (many) nerdy interests: pen-and-paper calculation.
No, not basic arithmetic (${+}{-}{\times}{\div}$); anyone can multiply two 10-digit numbers together, if they’re patient (and careful!) enough. I’m talking about the funky buttons on the calculator, like $\sqrt[n]{\quad}$, $\ln$, $\exp$, $\sin$, $\pi$, … They never taught you how to do those in school, did they?
In this series of posts, I’ll be exploring different ways of calculating mathematical functions and constants by hand.
The goal: $\ln2$
For concreteness, we first need to pick a number to compute, preferably something that looks simple but lies beyond what we already know how to calculate. $\sqrt2$, $\ln2$, $e$ and $\pi$ are all good choices for this purpose. Here we focus on $\ln2$ to illustrate the general principles of pen-and-paper calculation, but we will also look at the others in future posts.
For reference, the humble calculator can give us the answer instantly:
With more computing power, we can of course extend this even further; the current record is 500 billion digits.
We will be a bit less ambitious, and just ask to compute by hand the value of $\ln2$ to 8 decimal places. In fact, here we have a subtle issue with rounding off (consider $0.999\ldots$ and $1.000\ldots$), but for our purposes we will be satisfied with any answer that is within $\frac12\times10^{-8}$ of the true value.
The first step is to notice that we can only make progress by using properties of the $\ln$ function. Each property can lead to an algorithm to compute the digits of $\ln2$, which can be more or less suited to hand calculation. We will consider three different approaches below.
$\ln$ as an inverse function
The most obvious approach might be to use the fact that $\ln$ is the inverse function to $\exp$; ie. calculating $\ln2$ is equivalent to solving the equation $e^x=2$. For instance, we might use the Newton method on $f(x)=e^x-2$:
Here we immediately run into a problem: we have traded one evaluation of $\ln$ for several evaluations of $\exp$ — which we also don’t know how to calculate by hand!
This is a general feature of root-finding algorithms: the function needs to be computed at several points to close in on the root. As such, root-finding could be valuable for functions with easily computed inverses, such as square roots, but are of no help for finding $\ln2$.
$\ln$ and integration
Another idea is to notice that $\ln x$ is the antiderivative of $\frac1x$, so
Now we can approximate this integral by splitting up the interval $[1,2]$ into $n$ equal parts, and applying a quadrature rule (in other words, performing numerical integration). For instance, the right Riemann sum for this integral is
A more accurate estimate is given by the trapezoidal rule:
For instance, choosing $n=5$ gives:
This is $2.5\times10^{-3}$ off the correct value, which seems great for just 5 terms. Of course, choosing larger $n$ will give better results.
However, before committing to this method and going into a reciprocal calculating frenzy, it would be prudent to perform an error analysis. The trapezoid rule has error $O(\frac1{n^2})$. To get an error of less than $\frac12\times10^{-8}$, we would need $n\sim\sqrt{2\times10^8}$ — on the order of 10000 terms!
More generally, if a quadrature rule gives error $O(\frac1{n^m})$, then we need $O(10^{k/m})$ terms to get to $k$-digit accuracy. Hence the exponential growth in the number of terms required affects not only the trapezoidal rule, but also higher-order methods such as Simpson’s rule. There are other methods for numerical integration, such as Gaussian quadrature and Romberg integration, which converge much faster, but require taking square roots or dividing by large integers. Hence, it is hard to implement numerical integration methods by hand to more than a couple of digits of accuracy.
$\ln$ and power series
A third approach is to look at the power series for $\ln$ around 1, namely
The obvious substitution is $x=1$, which gives
As pretty as this series is, it is nearly useless for hand computation: the error of this alternating series is roughly the size of the last term used, ie. $O(\frac1n)$ if we use $n$ terms. This translates to $\sim10^8$ terms for 8-digit accuracy, which is even worse than using the trapezoidal rule.
As an aside, note that
which is just the right Riemann sum that we have seen previously.
A smarter idea is to substitute $x=-\frac12$, yielding
which converges faster than the geometric series with ratio $\frac12$. In other words, the error of this series after $n$ terms is $O(\frac1{2^n})$, so only $O(k)$ terms are needed to get $k$-digit accuracy. Great!
Let’s try this out numerically with the first 5 terms:
We also have a good error bound:
which is comparable to the actual error of $4.6\times10^{-3}$.
Similarly, we have an error bound of $\frac1{(n+1)2^n}$ after the first $n$ terms of the series. This is smaller than $\frac12\times10^{-8}$ when $n\geq23$, ie. only 23 terms are needed to get 8-digit accuracy.
Conclusion
We now have a working algorithm for calculating $\ln2$, namely by using 23 terms of the power series expansion of $\ln(1-\frac12)$. Although not as ridiculously impossible as the other methods we have seen, this is still no small amount of manual work — perhaps a weekend project, if you’re so inclined.
There is a natural question to ask at this point: “Can we do better?” Going down this rabbit hole is when the fun really begins. In the next post, we will cover some neat tricks to cut down the amount of computation even further.
Comments (0)
Be the first to comment!