Logarithm Tables
September 30, 2011
The requirement to always display mantissas accurate to within 1 in 10000 makes this exercise harder than it looks. The two tricks are rounding instead of truncating, and calculating the mean (average) differences instead of some lower-bound difference for the extra digit. Here’s the log table:
(define (log-average-interp i k)
(define (add-on j)
(- (* (log10 (/ (+ i (* j 10) k) 1000.0)) 10000)
(* (log10 (/ (+ i (* j 10)) 1000.0)) 10000)))
(inexact->exact (round (average (map add-on (range 10))))))
(define (log-display-interp i)
(display " ")
(do ((k 1 (+ k 1))) ((= 10 k))
(display " ")
(display (pr2 (log-average-interp i k)))))
(define (log-display-line i)
(do ((j 0 (+ j 10))) ((= 100 j))
(display " ")
(display (pr4 (log10 (/ (+ i j) 1000)))))
(log-display-interp i))
(define (log-display-table)
(display-header)
(do ((i 1000 (+ i 100))) ((= 10000 i))
(if (zero? (modulo i 1000)) (display-bar))
(display (/ i 100))
(display " ")
(log-display-line i)
(newline)))
The mean difference is calculated in the log-average-interp function, where each fourth digit is calculated as the average amount of interpolation required over all ten possible third digits. Anti-logarithms are calculated similarly, but backwards:
(define (alog-average-interp i k)
(define (add-on j)
(- (* (expt 10 (+ 1 (/ (+ i (* j 10) k) 10000))) 100)
(* (expt 10 (+ 1 (/ (+ i (* j 10)) 10000))) 100)))
(inexact->exact (round (average (map add-on (range 10))))))
(define (alog-display-interp i)
(display " ")
(do ((k 1 (+ k 1))) ((= 10 k))
(display " ")
(display (pr2 (alog-average-interp i k)))))
(define (alog-display-line i)
(do ((j 0 (+ j 10))) ((= 100 j))
(display " ")
(display (pr4 (/ (expt 10 (+ 1 (/ (+ i j) 10000))) 100))))
(alog-display-interp i))
(define (alog-display-table)
(display-header)
(do ((i 1000 (+ i 100))) ((= 10000 i))
(if (zero? (modulo i 1000)) (display-bar))
(display (/ i 100))
(display " ")
(alog-display-line i)
(newline))))
We also need some auxiliary functions to handle the formatted printing, in addition to range, average and log10 from the Standard Prelude:
(define (pr4 x)
(let* ((x (inexact->exact (round (* x 10000))))
(s (number->string x)))
(if (< x 1000) (set! s (string-append "0" s)))
(if (< x 100) (set! s (string-append "0" s)))
(if (string x)))
(if (< x 10) (set! s (string-append " " s)))
s))
(define (display-header)
(display " ")
(do ((j 0 (+ j 1))) ((= j 10))
(display " ")
(display j))
(display " ")
(do ((j 1 (+ j 1))) ((= j 10))
(display " ")
(display j))
(newline))
(define (display-bar)
(display "-- ";)
(do ((j 0 (+ j 1))) ((= j 10))
(display " ") (display "----"))
(display " ")
(do ((j 1 (+ j 1))) ((= j 10))
(display " ") (display "--"))
(newline))
You can run the program at http://programmingpraxis.codepad.org/fiKOD0wV. The output is shown on the previous page.
I remember using tables 20 years ago and even 10 years ago. Using tables at the exam instead of or in addition to a calculator is still allowed in Denmark as far as I know, and it actually provides a benefit, because you can double check your results. I remember my previous mathematics teacher even taught us pupils to use a ruler and caliper, because it gave us a much better understanding of what logarithms were about.
I learned to use logarithms in school a long time ago (30 years or so). In my office, I have the 1957-58 edition of the CRC, which contains tables of logarithms to 4 digits, to 5 digits, logarithms of trig functions, etc. I haven’t used logarithm tables directly since school. However, I have several slide rules (which are based on logarithms) and use them on a regular basis.
Here is my python 3 code to produce the log and alog tables.
from math import log10 def printtable(title, func): fmthdr = ("{:2}" + " {:>4}"*10 + " " + " {:2}"*9).format fmtrow = ("{:2}" + " {:04}"*10 + " " + " {:2}"*9).format print("\n\n{:^80}".format(title)) print(fmthdr('',0,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9)) print(fmthdr(*(['--'] + ['----']*10 + ['--']*9))) for d12 in range(1000, 10000, 100): label = d12//100 sums = [0]*10 logs = [] for d3 in range(0, 100, 10): x = d12 + d3 logx = func(x) logs.append(round(logx)) for d4 in range(1, 10): y = d12 + d3 + d4 logy = func(y) sums[d4] += logy - logx sums = [round(s/10) for s in sums] print(fmtrow(label, *(logs + sums[1:]))) if d12%500 == 400: print() printtable("Logarithms", lambda x: log10(x/1000) * 10000) printtable("Antilogarithms", lambda x: pow(10, x/10000) * 1000)Mike: I still use my father’s slide rule. And I recently bought a 1.5″ diameter circular slide rule that hangs on my keychain — it’s already proven useful.
The bezel on my watch is a cicular slide rule, the pencil holder on my desk is a cylindrical one, and I have an E6B flight computer. I also have several of my fathers slide rules that date from the 50’s. My favorite is a credit card sized circular slide rule with a periodic table on the back and a pull out card with all sorts of mathmatical and physical constants, conversion formulas, etc.
When I served on a submarine we used ‘whiz wheels’ all the time. A skilled person with a whiz wheel could often do a computation faster then a person using a computer. We also practiced calculating targeting solutions in our heads.