Do Simple, Impossible Calculations FASTER!
@ Daniel J. Dick | Friday, Mar 18, 2022 | 5 minutes read | Update at Friday, Mar 18, 2022

No, my son, David, didn’t really balance those when he was three.

But he did google up vsauce videos. On his own. Why?

To find out why not all infinities were the same, of course!

For several days, he would watch and rewatch these videos stopping and backing them up a little to make sure he understood well what he saw.

So, it’s possible to do the impossible even faster than thought possible!

Did you ever need to solve an algebraically impossible formula?

Easy. Program a computer to guess for a few hours, and get a really inaccurate guess that may be close enough. That’s common, but there’s a better way!

So, what’s this talk about doing calculations faster?

Well, let’s start with a silly little cartoon I made about the Binary Search. I bet you did this kind of search without knowing it.

My First Programming Job

For my first programming job, Bill and Bill–the two guys in charge at Data Consultants, Inc., (DCI), gave me a test:

write a program in BASIC on a Wang computer to engineer a wooden arch for a church.

Here is a picture off the web of a Wang computer similar to the one I used in 1976 or 1977


An old Wang Computer

How did I pass this test? There was so much to take into consideration.

  1. The odd form of the wooden arches supporting the ceiling.
  2. The weight of the material per volume.
  3. The strength of the materials–tension, and compression strength.
  4. The moment, shear, etc.
  5. All the interdependencies of these things.

Solution? Iterate

Split up the arch into tiny sections.

Is the shear too much based on the total weight on one side too much for the shear that the wood an bear? Increase thickness and try again.

Does the moment or sum of the tiny sections times distance exceed what the wood will tolerate? Increase thickness and try again.

Does it sound like this would take forever to calculate? It would. But then that was OK. It was expected. And it was much better than letting a building collapse.

I passed my test. Or they gave the job to me because I was a kid showing diligence and commitment and creativity. Or perhaps they felt sorry for me and wanted to give me the job. So, they offered me $2/hour, and I was excited–my first real programming job!!!

Real Work - Develop an Automobile Financing System

Bill Pardini had a little special-purpose calculator in his office for automobile salespeople to calculate car payments, interest, insurance costs, and such. He had an idea for a much more complete system that would run on a Processor Tech 8080 computer in NorthStar Basic.

Processor Tech 8080 based microcomputer from the 1970s

We worked together to come up with a program. It was a special purpose spreadsheet. With it, you could fill in the car price, down payment, length of the loan, interest rate, insurance type, and such.

But something was very different. You could leave out any variable, and it would calculate that missing variable.

But interest and reverse interest calculations are not always algebraically solvable. So how did I accomplish this? I could not program the computer to keep guessing forever.

Magical Secret Sauce: Newton Raphson Iteration

How could an underpowered 8-bit computer running a BASIC interpreter do such complicated financial calculations so fast? I used a Newton-Raphson iteration.

I cut and pasted the Newton Method’s calculation from Wikipedia below:

Math formula for Newton-Raphson Iteration

I would rather see this expressed in terms of n and n-1 than x0 and x1. But the idea is you take the value of the function and divide it by its derivative at the same point.

The idea is to do the following for each variable you might want to calculate:

  1. Let that variable you are finding be x.
  2. Find a function. Call it f(x), and set it to 0.
  3. The idea is to find x where f(x) = 0.
  4. Find the derivative of f(x) with respect to x. Call it f'(x). This is the slope of f at x.
  5. Use f(x)/f'(x) to find out how far to move x to get f(x) closer to zero.

Usually, the iteration converges very accurately on a local zero, and does it really quickly.

Forty years later, this program is still in use. The program has been rewritten for newer machines in newer programming languages. But I heard someone say the Newton-Raphson iterations I used have not been touched. They just work, and they work really well.

Flagpole Footing Calculations

A few years later after completing the Auto Financing System, a friend who had a Civil Engineering business, wanted help improving some BASIC programs running on his Apple II+. One was a flagpole footing depth calculation.

The program he was using took several long minutes to run and only provided one digit of accuracy beyond the decimal place. The programmer had tried guessing much the same way Bob in the cartoon above tried guessing. It took a very long time to calculate the depth of the flagpole footing.

So once again I pulled out my handy-dandy Newton-Raphson iteration, and in a very short time, I had a version of the program that could calculate with extreme accuracy the footing depth within 1 1/2 seconds. This, on an Apple II+ running at 1MHz with an 8 bit 6502 processor.

The Testing is in the Tasting

My friend, the engineer, thought the calculations must be wrong. He could not believe the results could be produced so quickly. So, he tested it several times. And he found the results were very accurate every time.

What’s so funny is that 40 years after the vehicle financing program went on the market, many programmers had worked on keeping that program up-to-date and functioning on new systems as technology developed. But I was told they tended to avoid touching the original code I wrote as a kid as it worked, and it seemed many didn’t really know why.

But it is a very simple and useful tool.

© 2004 - 2022 Daniel J. Dick

Powered by Hugo with theme Dream.