We know that Charles Babbage wrote a book of log tables:

enter image description here enter image description here

In doing this, Babbage was inspired to create Log Tables mechanically, leading to his design of the Difference Engine.

The Difference Engine didn't produce Log Tables, but a 'tabulation of polynomial functions'.

We can see that the operation of the Difference engine could produce a table that looked like this.

enter image description here

The difference engine exists today in the Science Museum in London, and was rebuilt in 1991.

Now it seems to me that you either input a polynomial to be evaluated(doesn't seem possible with the technology), or you set up a series of differences in the third column to be summed up into the first column.

My question is: How do you program Babbage's Difference Engine?

  • 2
    The Analytical Engine was programmable, but the Difference Engine was not. Sep 22 '19 at 12:57

How do you program Babbage's Difference Engine?

Simply you don't, as it is not programmable. (*1)

A Difference Engine is a fixed sequence adder.


A differential engine adds a series of values, called columns (registers), in the form R(n) = R(n) + R(n+1) with n ranging from 1 to the number of registers - in case of Babbage's machine six.

From an engineering point the machine isn't anything different from a pinwheel calculator, which, being able to solve a multiplication as a sequence of additions, is still just an adder.

Well, the Difference Engine is maybe special the way of organizing the adders in two groups to allow parallel operation. It only needs a fixed number of two calculation steps, independent of the number of columns, as a side effect the optimal number of columns is even. Calculation is done in two steps with all even columns in step 1 and all odd in step 2. A very simple and admirable way to increase performance due parallel processing.

Beside the number of columns, which defines the complexity of polynomial that can be calculated/approximated, there is the number of digits per column defining the precision. Babbage's machine was planned for 20, the prototype had 6, the 1991 #2 has 31.

Like the mentioned multiplication by a pinwheel calculator, a differential engine is not programmable at all (*2).

Use Case

The specific use case comes not from its mechanics or any 'programming', but the fact that a wide range of mathematical descriptions can be turned into a polynomial function, which again can be expressed as a series of addition, subtractions and multiplications, which then again can be reduced into simple additions.

And that's what the Difference Engines are about: Adding up a fixed sequence of intermediate values.

Change of Operation

The only change that could be done to a difference engine, much like to any adder, is to change the gearing to work in different number systems. Like using base 60 gears to calculate trigonometry or 1/20/12 gears to handle English currency, the later a use case for interest tables.

'Standard' Implementations

Since a difference engine is just a series of adders, it can as well be formed from any machine capable to add a series of values and keep track of each. Notable later examples showing this might be

*1 - As Tofro already pointed out.

*2 - Going as far as JeremyP does and call the preparation of the input programming might be quite over the edge, as it would turn any preparation of input values into programming, effectively making the term equivalent to preparation and thus meaningless.

  • 1
    I hesitated to do the technical explanation of the inner workings (I consider this off-topic. In addition [pun intended] I consider myself lazy). But, still +1 for the effort. And I strongly agree there is no programming involved.
    – tofro
    Sep 23 '19 at 17:26

Not at all.

The Difference Engine is not what we would call a programmable device. (So, it would also be considered off-topic for this site). It's more a slide rule than a computer.

The polynomal approximations to mathemathical functions are "hard-coded" into the gear transmission ratio.

What your linked Wikipedia article refers to as "programming" is only setting initial values.

  • @vsz you seem to have confused the Difference Engine with the Analytical Engine Sep 22 '19 at 19:42
  • 1
    The difference engine is programmable. It can be programmed to calculate the values of a wide variety of polynomials. It is not Turing complete because it can't do anything else.
    – JeremyP
    Sep 23 '19 at 9:04
  • 1
    @JeremyP Defnitely depends on your definition of programmable. Setting initial values to counters is not what I would call programmable.
    – tofro
    Sep 23 '19 at 9:17
  • 1
    @JeremyP Is shifting gears in a car programming?
    – tofro
    Sep 23 '19 at 9:40
  • 1
    I'm afraid that an explanation of a non-computer would be off-topic in a retrocomputing stack
    – tofro
    Sep 23 '19 at 12:55

Now it seems to me that you either input a polynomial to be evaluated(doesn't seem possible with the technology), or you set up a series of differences in the third column to be summed up into the first column.

In your example, the table is one way to represent the polynomial. So you have effectively input it.

If you repeatedly differentiate any polynomial function, you eventually end up with a constant. The first derivative of 2x2-3x+2 is 4x-3. The second derivative is simply 4. This means that, if you take the difference between successive values of the polynomial (for integer x), and put them in a column, then have another column which is the differences of the last column and so on, eventually you get a column where all the numbers of are the same as in the third column of your example.

Then you can calculate new values of the polynomial by adding the last column to the second to last column, then the new second to last column to the third to last column etc until you get to the first column. In your example, row 3 of column 3 must have a 4 in it which means row 4 of column 2 must have 11+4 = 15 in it which means the value for x = 5 is 22 + 55 = 37.

So the Difference Engine calculates successive values of a polynomial simply by doing repeated additions.

In maths a lot of functions can be approximated by polynomials. So you find a polynomial that approximates your function, set the Difference Engine up for that polynomial and then start churning out values. You have to be careful, because, after a while the error in the approximation will be greater than your desired accuracy and you have to stop.

  • 1
    I think you don't even have to differentiate, i.e. take the limit of f(x+h) - f(x) as h tends to 0. If it's a polynomial, f(x), then f(x + h) - f(x) is always a one-order-lower polynomial. I'm leaving this comment just in case anybody thinks there's something fishy in taking discrete steps in calculating the polynomial's 'next' value. There's not. The number of levels of addition sets a limit on the complexity of the polynomial but you're still calculating the one you settle on exactly.
    – Tommy
    Sep 23 '19 at 19:30
  • 1
    @Tommy Erm, no. It is not always exact. It is only exact until a certain number of iterations, defined due the input values as well as the number of valid digits the calculation is done. After that it'll be an approximation due dropped digits (dropping is not rounding). Continued calculation will make the result diverge ever more. That's the reason why difference machines were never used to calculate full tables at once, but rather to fill the room between known (hand/otherwise calculated) base values. That's why selecting the right start values - and their representation - is a qualified task
    – Raffzahn
    Sep 23 '19 at 20:08
  • 1
    @Raffzahn number theory has bitten me again; what I meant to say: the process of differencing and then performing a cascading add in order to make discrete steps along a polynomial will produce exactly correct steps along that polynomial. There's no Euler-esque approximation here. That said, as well as admitting that number of columns limits polynomial complexity you're absolutely right to point out, and I was wrong to omit, the observation that finitely-sized buckets will at some point lose data. I really just meant to get at the point that this isn't an approximate integral.
    – Tommy
    Sep 23 '19 at 21:15
  • 1
    @Tommy Yes, from a mathematical point you're absolut right. Sorry for being so nasty. I'm to much of an engineer to let this slip. :)
    – Raffzahn
    Sep 23 '19 at 22:46
  • 1
    When I was a maths undergraduate in the 1960s, we used this method with mechanical calculators to interpolate values in six-figure log tables. Sep 24 '19 at 12:56

Short answer

By our definition of programming of the last 30 years - you didn't program it, you merely gave integer parameters to a function and let it loop a few times and provide an integer answer.

Keep in mind people who performed mathematical calculations given to them during World War II were called "Computers." (i.e. computing can mean calculating and programming can mean scheduling something - like a TV program).

Long Answer

Charles Babbage took took much longer than he thought to design his Difference Engine; only a small part got built in his lifetime.

enter image description here

This is from the Science Museum in London.

There are a number of parts to this answer:

How do you calculate log₁₀ 60 without a calculator?

enter image description here

We can see the row for log₁₀ 60 in the book above. First we will cover off some assumed knowledge in Babbage's book:

The logarithm is the inverse function to exponentiation. This means:

  • log₁₀ 1 = 0
  • log₁₀ 10 = 1
  • log₁₀ 100 = 2

So log₁₀ 60 must be between 1 and 2.

Now as @xxavier has suggested - we can do logarithms using a Taylor series - ie

enter image description here

but this approximation only works for logs where 0 < x < 1.

Also note that this is natural log enter image description here not base 10 log, so we'll have to convert back later.

So how do we get to log₁₀ 60?

We look at another Logarithmic identity:

enter image description here

How does that help?

We can take what we did before - and simplify things:

enter image description here


enter image description here

Now we can go back to our Taylor series approximation:

enter image description here

Which is pretty close to a value provided by a calculator (-0.510826).

Now we convert back to log₁₀ n using another logarithmic identity.

enter image description here

This means we can do:

enter image description here

So to convert back to

$$ \log_{10}x $$

we can divide by

enter image description here

which is approx. 2.302.

So now

enter image description here

Which looks close to what Babbage got:

enter image description here

So we can confidently calculate a logarithm by hand.

But the Difference Engine can't expand Taylor series, it uses the Finite Differences Method.

How do you calculate a logarithm by the Finite Differences Method?

Babbage used the approach of Gaspard de Prony.

We'll use our Binomial expansion above to the sixth order:

We'll do this for a sixth order polynomial:

enter image description here

As an Excel function - this looks like this:


Now we build a table for this polynomial of sum of the differences between 0 and 1:

enter image description here

Now we shuffle top of columns to top row

enter image description here

Then we fill in first row with precomputed values, then populate each cell by adding the cell above and the cell above right:

enter image description here

So again we get

enter image description here

which we converted back to base 10 above.

You can see a detailed video of the finite differences method here.

How do we use Finite Differences in relation to the Difference Engine?

When initialising the engine - you can set values:

enter image description here

The values you are setting are the top row of the Finite Differences method from before.

enter image description here

Babbage's Difference Engine No.2 was designed for 7th order polynomials (our calculation was sixth order). This means our Finite Differences Method would have had 7 columns.

On the Difference Engine each vertical axle represents a number with 31 digits - with a gear corresponding to each digit, the most significant digit at the top:

enter image description here

Note that the Difference Engine represents negative numbers using tens complement.

So to enter our first value -0.10536 - we have to convert it to tens complement.

10's complement of a decimal number can be found by adding 1 to the 9's complement of that decimal number. It is just like 2's complement in binary number representation. For example, let us take a decimal number 10536; 9's complement of this number will be 99999-10536 which will be 89463. Now 10s complement will be 89463+1=89464.

(I'm assuming - similar to digital logic - there is a way to flag a 10s complement number - but that wasn't available to me at the time of writing.)

So assuming we are entering the value 0.89464 - this means we'll need to turn the 31 wheels to look like:

enter image description here

(We have entered a decimal fraction as an integer representing the numbers scaled up - and assume that it will be scaled back down later).

Then we repeat this activity for the other 6 columns of the table - against the next 6 vertical axles of gear-values.

enter image description here

How does the Difference Engine Add Numbers?

In our Finite Differences method - we had to take the cell above, and the cell above right.

Here we have two wheels representing values in the calculation, and the gear in the middle that adds.

enter image description here

How does the Difference Engine carry values to the next significant digit during addition?

To carry numbers up - there was an external device:

enter image description here

This was stacked in an vertical array for each value gear on the axle:

enter image description here

You can see the addition gear and the carry mechanism here:

enter image description here

In the context of the 1800s, when ships were getting lost or crashing, and reliable log tables were worth real money, the Difference Engine was (and is) a machine of great beauty.

enter image description here (The difference engine in the London Science Museum)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.