28

I'm thinking of making a table of logarithms ranging from 100-999 with 5 significant digits. By pen and paper that is. I'm doing this old school.

What first came to mind was to use $\log(ab) = \log(a) + \log(b)$ for reduction.
And then use the taylor series for $\log(1-x)$ when $-1 < x \leq 1$ But convergence is rather slow on this one.

Can you come up with a better method?

Mike Spivey
  • 55,550
Eberhardt
  • 423
  • Look at this thread here for some tricks that reduce the work and relevant background information. Essentially you don't want to use a single power series but do most of the work by using appropriate interpolations. – t.b. Sep 01 '11 at 22:11
  • The Feynman Lectures on Physics Vol1 Ch22 has the same ethos as the question and some good insight too. – Mark Bennet Sep 01 '11 at 22:44
  • 1
    You can find some actual calculations in this column: http://maa.org/editorial/euler/How%20Euler%20Did%20It%2021%20logs%20.pdf (it has an iterative method for base-10 logs, and half-way down page 3 it uses (a friendlier version of) the method in @Iasafro's post). Note that you need only use the series for reciprocals of integers since you can piece everything else together from those (and some ingenuity on your part). I also want to add that it's nice seeing someone else who is interested in this stuff (whenever I feel my arithmetic skills are declining I add to my log tables for practice). – Riley E Sep 02 '11 at 20:21
  • 4
    You are seriously doing this for fun? I know that my parents had to use logarithm tables when there were no affordable calculators. Why would you want to do this by hand today? – Raphael Sep 02 '11 at 21:24
  • 2
    @Raphael: While it's true that calculating things by hand is not that efficient when you want results, it is good practice at arithmetic. From my personal experience, as well as observing others, it seems that the jokes about basic skills (arithmetic, trig, calculus, etc.) degrading the higher one goes in mathematics are all too true. To counteract this, whenever I notice I'm getting sloppy with numbers I just pull out my table and add to it :) A slight digression: Another use for calculating things by hand (well, maybe not always by hand) is to help calculus students understand what.. – Riley E Sep 03 '11 at 04:58
  • ...convergence really means. Saying "$\sum_{n=0}^{\infty} \frac{1}{n!}$ converges by the ___ test" is one thing; showing them how fast zeroes get inserted after the decimal point of $\frac{1}{n!}$ for increasing $n$ is another. I'm not sure about Eberhard, but those are the two reasons I give people when I mention that I have my own log (and trig) tables. – Riley E Sep 03 '11 at 05:00
  • I am not sure that calculating anything (besides really basic stuff, maybe up to dealing with rationals) by hand is of use nowadays. It seems to me that the better exercise would be to sit down and learn how to quickly write a small programm that does the computation, or learn how to use bc etc. As a computer scientist, I am probably biased here. – Raphael Sep 03 '11 at 10:36
  • 1
    @Raphael As a computer scientist, aren't you interested in what method would do this quickest? Whether it's a human or computer computing? Robert's first solution takes about $2250$ multiplications (not bad). Iasafro's solution takes about 900 divisions and 450 cubings, and 450 raisings to 5. Robert's second solution takes about 2700 divisions, 900 squarings, and 900 cubings. Mine takes 1700 divisions. These kinds of comparisons should be important for making an efficient algorithm. Even if its just so the ideas can be applied to "bigger" problems. – 2'5 9'2 Sep 30 '11 at 17:12
  • That's right, but the OP explicitly stated he wanted to create a table by hand. I do not oppose finding efficient procedures, on the contrary, but I question the need for a table and the accuracy of doing long calculations by hand. – Raphael Oct 01 '11 at 12:17
  • I very nearly needed to do this today when I forgot my calculator for a chemistry test, and was unable to borrow one. Fortunately the problems were all overcooked and I didn't need to use anything past long division, but you never know... – AJMansfield Oct 23 '15 at 05:29
  • Have you ever tried Slide Rule for calculating logarithms? https://youtu.be/_diazeq0XS8 – Rita Geraghty Oct 26 '20 at 12:12
  • Another video on Slide Rule. https://youtu.be/6X4N5vR-O34 – Rita Geraghty Oct 26 '20 at 12:13
  • Another way of calculating logarithms is with few sets of abacuses as in video link here. Truly must-see. https://youtu.be/q62hQVfVGxU The guy is using a few Asian abacuses like Soroban and Suanpan. – Rita Geraghty Oct 26 '20 at 12:21

7 Answers7

16

For $1 \le x \le 2$, $$\begin{eqnarray*} \ln(x) &\approx - 1.941064448+ \left( 3.529305040+ \left( - 2.461222169+ \left( \right.\right.\right.\cr & \left.\left.\left. 1.130626210+ \left( - 0.2887399591+ 0.03110401824\,x \right) x \right) x \right) x \right) x \end{eqnarray*}$$ with error less than $10^{-5}$. For $2^n \le x \le 2^{n+1}$, $\ln(x) = n \ln(2) + \ln(x/2^n)$.

Robert Israel
  • 448,999
  • By any chance, is this an economized Chebyshev approximation? – J. M. ain't a mathematician Sep 02 '11 at 07:19
  • 4
    No, it's the best approximation in $L^\infty$ norm by polynomials of degree $\le 5$, computed by Maple's numapprox[minimax] procedure using the Remez algorithm. – Robert Israel Sep 02 '11 at 17:33
  • Thank you, this is a very fast formula. I would have one question: The numbers here have the smallest possible size? Can one use only 6 digits of those numbers after the decimal mark, or Maple optimized that too? (I would use this algorithm on soroban) – Crouching Kitten May 18 '17 at 18:42
  • 1
    Rounding the coefficients might introduce a little bit more error, but not much. In fact, -1.941064+(3.529305+(-2.461222+(1.130626+(-.288740+0.031104x)x)x)x)*x would make the maximum error just slightly greater than $10^{-5}$. – Robert Israel May 18 '17 at 21:05
12

According to Wikipedia, http://en.wikipedia.org/wiki/Logarithm#Power_series, you can try $$\ln(z)=2\sum_{n=0}^\infty\,\frac{1}{2n+1}\left(\frac{z-1}{z+1}\right)^{2n+1}$$ And using that convergence is quickler for $z$ near to $1$, according to wikipedia for $z=1.5$ the first three terms of the series give an error of about $3\cdot 10^{-6}$.

t.b.
  • 78,116
  • 1
    For future visitors, see more about this identity here: https://math.stackexchange.com/a/1793287/405572 – D.R. Dec 08 '22 at 04:06
8

EDIT: This is the short, streamlined version. My original answer is below, and the motivation, background, and error discussion can be found there.

  1. Find approximations for $\ln(1.00)$ to $\ln(2.00)$ iterating the argument by $0.01$. $$\ln(1.00)=0$$ $$\ln(x+0.01)\approx\ln(x)+\frac{1}{600}\left(\frac{1}{x}+\frac{4}{x+0.005}+\frac{1}{x+0.01}\right)\qquad(1)$$
  2. Find approximations for $\ln(2.01)$ to $\ln(3.00)$. If $\ln(x/2)$ is already tabulated, $$\ln(x)=\ln(x/2)+\ln(2.00)$$ Otherwise, use equation $(1)$.
  3. Find approximations for $\ln(3.01)$ to $\ln(5.00)$. If $\ln(x/2)$ or $\ln(x/3)$ is already tabulated, $$\ln(x)=\ln(x/2)+\ln(2.00)\qquad\textrm{or}\qquad\ln(x)=\ln(x/3)+\ln(3.00)$$ Otherwise, use equation $(1)$.
  4. Find approximations for $\ln(5.01)$ to $\ln(7.00)$. If $\ln(x/2)$, $\ln(x/3)$, or $\ln(x/5)$ is already tabulated, $$\ln(x)=\ln(x/2)+\ln(2.00)\qquad\textrm{or}\qquad\ln(x)=\ln(x/3)+\ln(3.00)$$ $$\textrm{or}\qquad\ln(x)=\ln(x/5)+\ln(5.00)$$Otherwise, use equation $(1)$.
  5. Find approximations for $\ln(7.01)$ to $\ln(10.00)$. If $\ln(x/2)$, $\ln(x/3)$, $\ln(x/5)$, or $\ln(x/7)$ is already tabulated, $$\ln(x)=\ln(x/2)+\ln(2.00)\qquad\textrm{or}\qquad\ln(x)=\ln(x/3)+\ln(3.00)$$ $$\textrm{or}\qquad\ln(x)=\ln(x/5)+\ln(5.00)\qquad\textrm{or}\qquad\ln(x)=\ln(x/7)+\ln(7.00)$$ Otherwise, use equation $(1)$.
  6. Now approximations for $\ln(1.00)$ to $\ln(10.00)$ are tabulated. Add $2\ln(10.00)$ to obtain a table of $\ln(100), \ln(101), \ldots, \ln(1000)$. Personally, I would leave the table with arguments from $1.00$ to $10.00$ and instruct the reader to add $\ln(10.00)$ as necessary.

This method uses equation $(1)$ roughly $100+50+33+33+27+27+23+23+23\approx340$ times. That means that you will do about $3(340)=1360$ divisions by numbers with at most four significant figures. You will divide by $600$ (comparatively simple) $340$ times. When you use equation $(1)$, you do $3$ additions, totalling about $1020$ additions. When you do not use equation $(1)$, you do addition once, and this happens about $900-340=560$ times. All together that's:

  • $1360$ divisions by numbers with at most 4 significant digits
  • $340$ divisions by $600$
  • $1580$ additions
  • no time-consuming multiplications or raising to powers, as most other methods involve

I think this is excellent considering that you will be producing $900$ numbers to five decimals of accuracy.


Original posted answer:

Here's an idea that has nothing to do with power series. First, read up on the Runge-Kutta method for approximating solutions to differential equations at http://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods. Just stick to the "common fourth-order" method. Most introductory differential equations courses cover Euler's method, which is a great concept, but usually impractical for its slowness. Runge-Kutta works a lot faster.

$y=\ln(x)$ is the solution to the differential equation $y'=\frac{1}{x}$ with initial condition $y(1)=0$. Apply Runge-Kutta with a step size of $0.01$ and iterate nine hundred times from $1.00$ up to $10.00$. You'll have approximate values for $\ln(1.01)$ up to $\ln(10.00)$. Then you can add the approximation for $\ln(10.00)$ (twice) to get approximations for $\ln(100)$ to $\ln(1000)$.

Error:

I do not know of any theorems for bounding the error with this method, but errors are usually very small in practice. I used Excel to do all of this, and the error on the final approximation for $\ln(10.00)$ was just less than $2.1\times10^{-11}$. If you did all of this by hand, then used some other method to find $\ln(10.00)$ with very high known precision, you could establish a bound on the error for $\ln(10.00)$. Then the monotonicity of $\frac{1}{x}$ would imply that all the errors on the intermediate steps were even smaller.

Complexity:

Given the specifics of this problem, each iteration will require you to do three decimal divisions by numbers that have at most four significant digits. (Note that since the differential equation is pure-time, $k2=k3$.) Each iteration will also have two doublings, several additions, and one division by 6, but the three decimal divisions will take most of your time. Also, each of these three quotients only gets used later in additions, doublings, and division by $6$, so I would bet that you would be safe recording only 7 decimals for each quotient. My feeling is that this will give you the results that you want much quicker than most methods based on power series. Just like this method, those require several divisions at each step. But power series methods also require raising to powers, and this method does not.

Improved Speed

To cut the computation time roughly in half, you could use some other method to find a decimal for $\ln(2)$ to high accuracy, and add use $\ln(2x)=\ln(x)+\ln(2)$. Specifically, after running Runge-Kutta ninety times up through $2.01$, you could approximate $\ln(2.02)$ with the approximations you have for $\ln(1.01)$ and $\ln(2)$. Alternate back to RK for $\ln(2.03)$, and continue alternating the methods. This would drop you from $900$ RK iterations down to $500$. Adding this modification to my Excel spreadsheet brought the final error on $\ln(10.00)$ up to a perfectly acceptable $7.1\times10^{-11}$.

2'5 9'2
  • 54,717
  • The "classical" version is good, though one might want to consider Gill's formulation to save on the number of quantities one must recall per step. – J. M. ain't a mathematician Sep 02 '11 at 19:04
  • @J.M.: I cannot see the article, but can you clarify what you mean? The only quantity that needs to be recalled to find, say $\ln(2.57)$ is $\ln(2.56)$. And the OP wants to have $\ln(2.56)$ recorded anyways as part of the final table. (That is, after adding $2\ln(10)$.) Is Gill's formulation trying to get to the end (that is, $\ln(10.00)$) with fewer steps in between? The OP wants a table of $900$ numbers no matter what the method. – 2'5 9'2 Sep 02 '11 at 20:40
  • Your formula (1) is a Simpson rule integration from 0 to 1 of x^t dt, which works out to (x-1)/Ln(x). Dorfler, in his book "Dead Reckoning" arrives at this same formula by extrapolation on Borchardt's AGM algorithm. – richard1941 Apr 30 '20 at 16:23
7

Another way, appropriate for making a table, is to start with $\ln(100) = 4.605170186$, and then for each $n$, $\ln(n+1) \approx \ln(n) + \frac{1}{n} - \frac{1}{2n^2} + \frac{1}{3n^3}$. The accumulated truncation error (not counting roundoff) will always be less than $10^{-7}$.

Robert Israel
  • 448,999
2

Reconsidering the original answer below, I find that taking square roots multiple times is far greater torture than dividing by the natural log of 10. So we are back to natural logs.

It is easy to calculate the natural log of a number that is sufficiently close to 1 by means of power series, continued fractions, or whatever you like. If your number is close to 1, then the natural log will be a small number, and multiplication by the natural log of 10 might be less of a headache. Of course, this does not cover the range of numbers you want; you must use RANGE REDUCTION. To do this, first calculate, by any means available, the base 10 logs of 1/0.5, 1/0.9, 1/0.99, and 1/0.999. Multiply your target number by these factors (easy on soroban because it is a shift and subtract), and accumulate the corresponding log on a second soroban with a couple of guard digits. That will get you down to the territory where $\frac{(x-1)}{(x+1)/2}$ takes care of the natural log of the remainder.

Another tool for range reduction is the square root. If you have an approximation that is not quite accurate enough, calculate Ln(Sqrt(x)) and double the result. Of course you best have a guard digit because you lose one bit of resolution when you double a number. On the other hand, if you have an approximation with a square root in it, and you can sacrifice some accuracy, calculate ln(x^2) and halve the result. This will remove square roots from your approximation. It is a tradeoff between work and accuracy.

Example: Log(2) = Log(1024)/10 = (3 + 0.4343 * Ln(1.024))/10 = 0.3 + 0.4343*0.024/1.012 = 0.3 + .010299960..., good enough for your table. Of course, for use in range reduction you will need another term in the power series for Ln(1.024). But if you multiply 1.024 by .99 a couple of times, you get 1.0036224, and Ln(1.024) = 2*Ln(1/0.99)+Ln(1.0026224). That last residue is approximated to 8 digits by 2*(x-1)/(x+1). Generation of the logs of 0.9, 0.99, and 0.999 to 8 digits may seem slow and laborious, but is is an investment that will pay back by simplifying all of the other logs.

==================================================================

Making a log table by pen and paper is not for the faint of heart; you must have perfect accuracy. I recommend pencil, eraser, and paper.

All of the above methods are great for natural logs, but to get logs to base 10, you must divide each by the natural log of 10. That's no fun. I would try to get logs to base ten directly by Euler's method of finding upper and lower bounds that have known logs, so you have an upper and lower bound for the log. Then bisect that interval for the logs by taking the arithmetic mean and for the argument by taking the geometric mean. You have to be quick and accurate at taking square roots like Euler.

You could build a table of certain logarithms: 10^(-1/2), 10^(-1/4), etc. Twenty such entries would allow you to calculate logs to 5 places by multiplying your target number by the appropriate power of ten and adding the negative of that log to the total. You could probably use two soroban: one for the division, and one to accumulate the log.

Another method is to square the argument, and if greater, divide by 10 if the result is greater than ten. When you divide by 10, append a binary 1 to the log (which is represented in binary), otherwise, append a binary 0. Knuth has a discussion of this in chapter 1 of Fundamental Algorithms and gives the breakdown of the squaring method as a problem for the student.

I would start with the first few prime numbers, then use those to build the logs of the other numbers. For a number x that you cannot factor, find a nearby number y that you can factor. Then calculate Ln(x/y) by a power series. A really good one is the Pade approximation Ln(x+1)=x(6+x)/(6+4x). The smaller x, the better the approximation. Then multiply this by the log(e) = .4342944819. Add that to the log of the nearby number, and you will have it. Of course it is helpful to memorize a few things to ten or more places. I would start with the logs of 2, e, 3, and 7. (The logs of 4, 5, 6, 8, and 9 can be computed from these).

There are some other marvelous Pade approximations using the transformation y = (x-1)/(x+1). The simple approximation Ln(x) = 2y is amazingly good, but with a Pade approximation like 2y*N(y)/D(y), where N and D are polynomials, you can do amazingly well. (but you still have to multiply the result by Log(e))

Another approach is one I got from Nate Grossman of UCLA. As you know, the arithmetic-geometric mean algorithm converges quadratically. Here is a variant:

a(0) = 1, g(0) = x, thereafter, a(1+j)=(a(j)+g(j))/2 and g(1+j)=sqrt(a(1+j)g(j))

Note the slight difference from the standard AGM formula. The a's and g's converge to a common limit, but not quadratically. You can use Richardson extrapolation to speed convergence. The limit is d, and (x-1)/d is your approximant for the natural log. This was a popular method in the Forth Interest Group. Also see Ron Doerfler's book, "Dead Reckoning".

Another method taught by Professor Grossman was Newton-Raphson solution of the exponential function. However that passes the buck to finding a fast efficient way to calculate the exponential.

Hope I gave you some ideas. Creative factoring can greatly extend the first few simple results. Interesting problem!

. . . Richard

Have fun!

1

If you want to make a table of natural logarithms, you could do it fairly effectively using Newton Raphson. For each x ∈ [100,999], choose an initial y0 ∈ (4.6, 6.9) to taste, and then iterate: $$ y_{j+1} \;\;=\;\; y_j - \left[\dfrac{\exp(y_j) - x}{\exp(y_j)}\right] \;\;=\;\; y_j + x \exp(-y_j) - 1. $$ The Taylor series for exp(−yj) should converge quickly, unlike that of ln(1 − yj). For base 10 logarithms, you can do the conversion by dividing your natural logarithms by ln(10), which you can also find quickly by the above method.

  • If the range is from a particular number to another number 10 times as big, then it doesn't make much sense unless they're base-10 logarithms. – Michael Hardy Sep 01 '11 at 22:46
  • @Michael Hardy: good point; but he can convert by dividing by ln(10) throughout, which is similar to a computation he would have to do with a direct Talyor series computation anyhow. – Niel de Beaudrap Sep 01 '11 at 22:50
0

EDIT: 168 is too big for this technique, only use it on the first five primes and then use approximations using nearby numbers for the big primes.

There are $168$ prime numbers below $1000$. For every number $N$ below $1000$, there exists a unique vector $\left(\alpha_1, ..., \alpha_{168}\right) \in \mathbb{N^{168}}$ such that $N$ can be written $$ N = \prod_{i=1}^{168}p_i^{\alpha_i}.$$

In general, define $$ G =\Bigl\{\prod_{i=1}^{168}p_i^{\alpha_i}\Big|\left(\alpha_1, ..., \alpha_{168}\right) \in \mathbb{Q^{168}}\Bigr\}.$$

$\left(G,\times\right)$ is a group isomorphic to $\left(\mathbb{Q^{168}},+\right)$ and $B_0=\left(p_1, ..., p_{168}\right)$ is its standard base. These numbers are too large to rapidly compute their logarithms, so we will find a new base $B=\left(b_1, ..., b_{168}\right)$ of $G$ such that all the $b_i$ are close to $1$.

Find $168$ large numbers (for the precision of five significant digits you mentioned, if they are over $1000$ it should be enough) $m_1, ...,m_{168}$ with the following property : both $m_i + 1$ and $m_i-1$ are in $G$. Let $b_i = \frac{m_i+1}{m_i-1}$. You will want these numbers to be independent multiplication-wise, so you need to use all $168$ primes. If you realise one of your $b_i$ is a product of others, pick a new $m_i$. Let $P$ be the matrix of the coordinates of $(b_i)$ in the standard base $B_0$. If it isn't invertible, remove the offending $m_i$ and pick some new ones. If you find this difficult, remember that all $p_i$ have to be used.

If $P$ is invertible, $B=\left(b_1, ..., b_{168}\right)$ is a base of $G$ multiplication-wise and $P^{-1}$ gives you the coordinates of the standard base $B_0$ in base $B$. If $X$ is the column vector of the coordinates of an element $x\in G$, then $Y=P^{-1}X$ gives you the coordinates of $x$ in base $B$. In particular, we have $$\ln x = \sum_{i=1}^{168} y_i \ln b_i. $$

Let $L = \left(\ln b_1,..., \ln b_{168}\right)$, we have $\ln x = LY=LP^{-1}X$.

If $T$ is the matrix of the coordinates of all the numbers $t_1, ..., t_{168}$ of $G$ whose logarithm you want in the standard base, then $$ \left( \ln t_1, ..., \ln t_{168}\right) = LP^{-1}T. $$

Let $Q$ be the matrix of the absolute values of $P^{-1}$. An upper bound on the errors is given by $$ \left( \Delta \ln t_1, ..., \Delta \ln t_{168}\right) = \left( \Delta \ln b_1, ..., \Delta \ln b_{168}\right) QT, $$ since $T$ only has non negative terms.

Now compute the logarithms of your new base: for any $n$, $$ \ln b_i = 2 \operatorname{arctanh}\left(\frac{1}{m_i}\right) = 2 \sum_{k=0}^{n} \frac{1}{\left(2k+1\right)m_i^{2k+1}} + 2 r_n\left(\frac{1}{m_i}\right),$$ with $$0<r_n\left(\frac{1}{m_i}\right)<\frac{1}{\left(2n+3\right)m_i^{2n+3}}\times\frac{1}{1-m_i^{-2}}.$$

This can be estimated quickly. You want your $m_i$'s to be big enough so you never have to compute more than one term in the 168 series. If $m_i>1000$, using the expression above, and calculating only the first term, $$ \Delta \ln b_i<7\times 10^{-10}.$$

You also want the $m_i$'s to be small enough so that the inversion of $P$ isn't too difficult. If they are not too big, $P$ will have many $0$ and should not be too hard to inverse using hand and paper. You typically want only five or six non zero terms on each column of $P^{-1}$, which is achievable by building your base cleverly, using the five smallest primes a lot, and the others only once. If you manage to do this, you will only have six fractions to sum to calculate the $\ln N$. The $m_i$'s for $i>5$ do not need to be as big as those used to interpolate the small primes.

EDIT : thinking about it, you should only do this for the small primes. For the large numbers, go to the nearest "nice" number and use $\ln a = \ln b + \ln \frac{a}{b}$ which can be calculated quickly with the Taylor series we mentioned.

Axel
  • 303
  • 1
  • 7