Ada Lovelace's Calculation of Bernoulli's Numbers 1. Introduction
Total Page:16
File Type:pdf, Size:1020Kb
Ada Lovelace's Calculation of Bernoulli's Numbers Ada Lovelace's Calculation of Bernoulli's Numbers Rainer Glaschick, Paderborn, Germany ([email protected]) http://rclab.de/analyticalengine/ 2016-09-29 1. Introduction In 1843, an article with the title Sketch of the Analytical Engine… [ML1843] was published, that contains an extensive and on its level fairly complete description of Charles Babbage's plans for a fully automatic computing engine. Its name has been motivated by the aim that it should be able to numerically solve all computations in the field of mathematical analysis (p.688): … all the Operations of analysis come within the domain of the engine. The article consists of a translation of a report by L.F. Menabrea, originally written in French, and supplements designated as Note A to Note G. The author was Augusta Ada King, Countess of Lovelace, who signed the Notes not by name, only with her initials A.A.L. — for the reasons her biographies should be consulted, that are also the place to the never-ending discussion about her mathematical ability, while this article strongly supports her excellence. The closing Note G got much attention, because the corresponding table now is regarded the first fairly complex program ever. The use of machine instructions, variables and a conditional loop is easily seen; but it is instructive to look into the very details of the program — which few people might have done, not only because several typos are not widely known (the most complete and reliable source seems to be [MCK1989], in particular see p. 159, ft), but also because the program needs a feature, that was not considered in the engine at the time the article was written. Probably this was more clearly seen by Ada Lovelace than by Babbage himself. There are strong indications that the machine could not simply overwrite variables, never explicitely mentioned but implicitely honored by Ada Lovelace as well as Charles Babbage, and, as known so far, not obeyed by all that did build an emulator. The reader should be very careful not to take things for granted that are common today; nearly everybody, myself definitely included, had to find out that he did so at some place. This concerns in particular the assumption that variables can be easily overwritten, and that operation cards are used to perform an operation, once the operands are loaded. 2. The Analytical Engine As no Analytical Engine was ever built, there is no such thing as the Analytical Engine. The plans were continuously modified and improved; and because there was never an attempt to build at least a small prototype, there was no motivation to fix a design. Nevertheless, plans 16, 25 and 28 could be seen as milestones. Plan 25 is dated from 1840 and probably closest to the concept that Babbage introduced in Turin and which was the basis for the work of Menabrea and thus Ada Lovelace. That version was also 1 von 18 29.09.2016 08:12 Ada Lovelace's Calculation of Bernoulli's Numbers engraved and given away by Babbage; it is today the most used graphical view. Loops are not present and are only found in Plan 28 from 1845 (see Bromley in [AB2000], p.6 bottom to p.7 top), significantly later than Ada Lovelace's article. The article is obviously on a generic level and not specifically linked to a certain version. E.g. it is not mentioned that a machine according to Plan 25 would produce a double precision result for a multiplication, thus the operations were not just the plain four given in the article. In fact the nature of the machine is presented by examples, without presenting the model of the machine explicitly. That would not have been possible anyhow, as the concept of the Analytical Engine was completely new and no terminology existed for it. For today's reader, however, that is familiar with electronic computers, the hypothetical machine can be sketched coarsely. It will be called an abstract machine, as it is an abstraction from various plans, and, as is the principle for abstract machines, omit several technical details. 2.1. The abstract Analytical Engine The abstract Engine implied by Ada Lovelace has: a calculating unit (the mill) for the four basic calculations a storage unit (the store) for holding numeric values in variables, also called columns a control unit, using punched cards for programming A calculation step transfers two operands from the store to the mill, calculates the result, and sends it back to the store. Selection of the operands and the operation was done by different punched cards. It follows that normally one operation card and three variable cards were used, two for reading the operands and one for storing the result. To understand Note G, a three-address-machine with four operations is sufficient: Vx + Vy -> Vr Vx - Vy -> Vr Vx × Vy -> Vr Vx ÷ Vy -> Vr where Vx and Vy are the operand variables and Vr is the variable of the result. In the example of the Bernoulli numbers in Note G operations are repeated in a loop, but the mechanism is not explained. The Table only contains a descriptive text and no symbolic indication. To allow this, a conditional repetition, that goes back a predefined number of operations and variable cards if the result in the mill is not zero, is written as: ? ≠ 0 : => k The letter k represents the number of the operation that shall be executed next, although a real machine would use the number of cards to rewind. Note that Menabrea wrote (S.685): These new cards may follow the first, but may only come into play contingently upon one or other of the two circumstances just mentioned taking place. and refers to zero-crossings and overflows, that allow to activate alternative program 2 von 18 29.09.2016 08:12 Ada Lovelace's Calculation of Bernoulli's Numbers parts. According to the current knowledge, there were no plans for loops and conditional jumps of a maturity similar to the arithmetic operations, so that the above conditional backward jump must be seen as very generic. Note that using Jaquard cards for weaving, only a linear sequence is used; all repeats are unraveled, which explains the enormous number of cards cited in the article. 3. The program To demonstrate the exceptional power of the Analytical Engine, the last example in Note G explains the calculation of Bernoulli's numbers. They were probably well known to every professional mathematician, as Ada Lovelace does not bother to explain them or motivate their use. For today's readers, additional information is contained in the appendix. To follow the next chapters, this information is not necessary, if the reader just accepts the equations given. The example in Note G is preceeded by simpler ones, starting by calculating the two unknowns from the six coefficients in two equations, already in the translated part on p. 681, i.e. also in the french original written by Menabrea, which corresponds to unpublished notes by Babbage [CB1837] dated 1837. While these documents still need in-depth analysis, the first impression is that the tables used by Menabrea and Lovelace contain more information than Babbage's ones. Nevertheless, the first simple program ever was written down by Babbage and published by Menabrea; and it shows the sequential control of calculations by cards as well as the reuse of intermediate values, the latter being the primary motivation of Babbage to abandon the Difference Engine. However, the example in Note G is much closer to what we consider a non-trivial computer program today. 3.1. The calculations Starting point for the example are several equations for different methods to calculate Bernoulli's numbers. The equations are marked (1.) to (4.) in the article. The article claims that the second one is well known, but presumably all were common knowledge for mathematicians of that time (a question that might be studied separately), because the finally used equation (8.) is rewritten from the fourth. It was chosen for the illustration of the powers of the engine; moreover, it is the only one that does not use an infinite series and thus avoids discussions on termination and accuracy. Formula (8.) reads: 1 2푛 − 1 2푛 2푛 ⋅ (2푛 − 1) ⋅ (2푛 − 2) 0 = − ⋅ + 퐵1 + 퐵3 2 2푛 + 1 2 2 ⋅ 3 ⋅ 4 2푛 ⋅ (2푛 − 1) ⋅ (2⎜⎛푛 − 2⎟⎞) ⋅ (2푛 −� 3) ⋅ (2푛 − 4) � +퐵5 ⎝ ⎠ + ... + 퐵2푛−1 2 ⋅ 3 ⋅ 4 ⋅ 5 ⋅ 6 � � Evidently it allows, as noted in the article, to calculate 퐵2푛−1, once all previous 퐵2푖−1 have already been calculated. For this purpose, equation (8.) is represented as: 0 = 퐴0(푛) + 퐴1(푛) ⋅ 퐵1 + 퐴3(푛) ⋅ 퐵3 + ... + 퐴2푛−3(푛) ⋅ 퐵2푛−3 + 퐵2푛−1 3 von 18 29.09.2016 08:12 Ada Lovelace's Calculation of Bernoulli's Numbers The above notation differs from equation (9.) in the article, in that the remark in the article that A1, A3 &c. being … functions of n … is made explicit using functional notation. Thus the coefficients are (not given in this form in the article): 1 2푛 − 1 퐴0(푛) = − ⋅ 2 2푛 + 1 2푛 퐴1(푛) = 2 2푛 − 1 2푛 − 2 퐴3(푛) = 퐴1(푛) ⋅ ⋅ 3 4 2푛 − 3 2푛 − 4 퐴5(푛) = 퐴3(푛) ⋅ ⋅ 5 6 For a given 푛, the values can be calculated from already calculated ones of the same 푛, with the significant difference to Bernoulli's numbers, that only the last one is needed and only for the current round. So the equation for the next of Bernoulli's numbers has the finally used form: −퐵2푛−1 = 퐴0(푛) + 퐴1(푛) ⋅ 퐵1 + 퐴3(푛) ⋅ 퐵3 + ..