Principle of the Difference Engines
Difference engines are so called because of the mathematical principle on which they are based, namely, the method of finite differences. In general, calculating the value of a polynomial can require any or all of addition, subtraction, multiplication and division.
An advantage of the method of finite differences is that it eliminates the need for multiplication and division, and allows the values of a polynomial to be calculated using simple addition only. Adding two numbers using gearwheels is easier to implement than multiplication or division and so the method simplifies an otherwise complex mechanism.
If the first few values of a polynomial are known, the rest may be calculated using simple repeated addition. The method is illustrated in the diagram above for the function F(x) = x2 + 4. The values of x are shown in the first column incrementing by 1 each time (x = 1, 2, 3, 4 . . .). The values of the function x2 + 4 are shown in the second column with the first four values calculated by mental arithmetic or by hand (5, 8, 13, 20).
The next step is to calculate the first and second differences. The first differences are shown in the third column and are calculated by subtracting successive values from the previous column as shown by the solid arrows flowing from left to right (8-5=3, 13-8=5 etc.). The second differences are calculated by subtracting first difference pairs and these are shown in the last column.
With these initial values calculated the rest of the values of the function can be calculated by reversing the process. The values we wish to calculate are shown below the upper dotted line. For this polynomial, the second difference is a constant (2). To calculate the value of the function for x=5 the constant difference (2) is added to the first difference (7) to obtain the next first difference (9) (red arrow), which can then be added to the last function value (blue arrow) to yield F(5) = 29. This is the desired result, achieved without performing multiplication.
The process can then be repeated to yield the next first difference (11) which may be added to the last function value to get F(6) = 40, etc. Using this method, any second-degree polynomial can be computed this way and, more generally any nth degree polynomial can be computed, using only addition, starting with the nth difference.
Babbage's Difference Engine No. 2 has 'registers' to hold one number from each of the columns in the table (for example 20, 7, 2). It would add the second difference to the first, then add that result to the function value to compute the next entry in the table. There were enough 'registers' for seven differences, allowing it to compute 31-digit values for polynomials with terms up to x7.