Tuesday, March 15, 2016

The technology that powered geeks from Newton to Aldrin

Pop Quiz: What do Issac Newton, Buzz Aldrin and My Dad all have in common? They all solved math problems, at one time or another, using the same device: the mighty slide rule. After watching this video I realized I've never done a post on the slide rule, and as an aficionado of all things simultaneously basic and techy, I needed to correct that.

The technology really does go back hundreds of years, with Issac Newton clearly describing a device which anyone doing math in the 1960's or before would appreciate:

Mr. Newton, with the help of logarithms graduated upon scales by placing them parallel at equal distances or with the help of concentric circles graduated in the same way, finds the roots of equations. Three rules suffice for cubics, four for biquadratics. In the arrangement of these rulers, all the respective coefficients lie in the same straight line. From a point of which line, as far removed from the first rule as the graduated scales are from one another, in turn, a straight line is drawn over them, so as to agree with the conditions conforming with the nature of the equations; in one of

And here's an actual shot of Buzz Aldrin in space with a slide ruler floating in the background:

One can imagine that nearly every major undertaking involving complex math utilized the slide rule in one way or another. Consider this description of the building of the Golden Gate Bridge:

Charles Ellis and Leon Moisseiff calculated forces for the Golden Gate Bridge with only a circular slide rule and a manual adding machine. They worked for months -- by hand -- sometimes solving equations with more than thirty unknowns.

Those guys weren't messing around.

My favorite slide rule store does happen to come from the space program, specifically from the Apollo 13 mission:

Perhaps the most impressive use of the slide rule was during the Apollo 13 crisis. Engineers had to recalculate data to guide the crew safely back to Earth—and they had to do it quickly. Richard Ogle describes how it went down:

""NASA had at its disposal whole banks of sophisticated computers, of course, but these were not programmed to do the basic calculations [Commander Jim Lovell] needed. So the engineers reverted to that most mundane pre-pocket calculator workhorse, the slide rule. Had the engineers at Mission Control been forced to do the necessary calculations on paper, Apollo 13 might well have missed the trajectory needed to bring it back to earth altogether. Instead the slide rule, designed specifically to exploit human beings’ highly developed visual acuity, allowed them to perform a set of complicated calculations in seconds.""

OK, we all get that the slide rule is an amazing device. But how do you truly grok it? You could pick one up on eBay for under $10 or so and work towards mastering it. Or, you could install the App on your phone for free, and start playing with it right now. But, as they say, if you truly want to understand something, teach it. And I know of no more recalcitrant a student than the computer. So I decided to program a slide rule.

Here's my solution:

(struct scale (symbol location abs-fn scale-fn) #:prefab)

(define C (scale 'C 'slide
   (lambda (s)
     (log s))
   (lambda (a)
     (exp a))))

(define D (scale 'D 'body
   (lambda (s)
     (log s))
   (lambda (a)
     (exp a))))

(define CI (scale 'CI 'slide
    (lambda (s)
      (log (/ s (/ 1 s))))
    (lambda (a)
      (/ 1 (exp a)))))

(define DI (scale 'CI 'body
    (lambda (s)
      (log (/ s (/ 1 s))))
    (lambda (a)
      (/ 1 (exp a)))))


(define A (scale 'A 'body
   (lambda (s)
     (log (expt s (/ 1 2))))
   (lambda (a)
     (expt (exp a) 2))))

(define B (scale 'B 'slide
   (lambda (s)
     (log (expt s (/ 1 2))))
   (lambda (a)
     (expt (exp a) 2))))

(define R (scale 'R 'slide
   (lambda (s)
     (log (expt s 2)))
   (lambda (a)
     (sqrt (exp a)))))

(define K (scale 'K 'body
   (lambda (s)
     (log (expt s (/ 1 3))))
   (lambda (a)
     (expt (exp a) 3))))



(define (make-slide-rule)  
  (let ((offset 0))
    (lambda (action . args)
      (define (align s1 v1 s2 v2)
 (cond ((and (eq? (scale-location s1) 'body)
      (eq? (scale-location s2) 'slide))
        (set! offset
       (- ((scale-abs-fn s1) v1)
   ((scale-abs-fn s2) v2)))
        offset)
       ((and (eq? (scale-location s1) 'slide)
      (eq? (scale-location s2) 'body))
        (align s2 v2 s1 v1))
       (else
        (error (format "Must align body to slide, not ~a to ~a"
         (scale-location s1) (scale-location s2))))))
      (define (read s1 v1 s2)
 (cond ((and (eq? (scale-location s1) 'body)
      (eq? (scale-location s2) 'slide))
        ((scale-scale-fn s2) (- ((scale-abs-fn s1) v1) offset)))
       ((and (eq? (scale-location s1) 'slide)
      (eq? (scale-location s2) 'body))
        ((scale-scale-fn s2) (+ ((scale-abs-fn s1) v1) offset)))
       (else
        (error (format "Must read from slide to body, or body to slide. Not ~a to ~a"
         (scale-location s1) (scale-location s2))))))
      (case action
 ((align)
  (apply align args))
 ((offset) offset)
 ((read)
  (apply read args))
 (else
  (error (format "Unknown slide rule command: ~a" action)))))))

I found this page especially useful in developing my implementation.

What I learned from this little coding exercise was that there's really only two operations that you can perform with a slide rule: slide it and read it. So I implemented those two operations: align and read. For example, to perform basic multiplication, you align the C and D scales, and then read the value off the D scale relative to the C scale. Or, in code:

(define sr (make-slide-rule))
(sr 'align C 1 D 5)
(sr 'read C 3 D) ;; => 15

And here's an example of computing X3 using the K scale:

(define sr (make-slide-rule))
(sr 'align C 1 D 1)
(sr 'read C 3 K) ;; => 9

I definitely appreciate that by implementing more advanced scales, you could knock out some pretty hairy math with relative ease.

Don't get me wrong, I love me a calculator (even with its flaws) and gladly perform even the most basic mathematics on it. But from a design and hacking perspective, you really can't beat the mighty slide rule. It's definitely worth taking the time to understand how it works and why it was such an effective tool for so long.

No comments:

Post a Comment