Note G[a] is a computer algorithm written by Ada Lovelace that was designed to calculate Bernoulli numbers using the hypothetical analytical engine.
[5][6][7][8] The algorithm was the last note in a series labelled A to G, which she employed as visual aids to accompany her English translation of Luigi Menabrea's 1842 French transcription of Charles Babbage's lecture on the analytical engine at the University of Turin, "Notions sur la machine analytique de Charles Babbage" ("Elements of Charles Babbage’s Analytical Machine").
These tests have independently concluded that there was a bug in the script, due to a minor typographical error.
[13] During Babbage's lecture, mathematician Luigi Menabrea wrote an account of the engine in French.
[12] A friend of Babbage's, Charles Wheatstone, suggested that in order to contribute, Lovelace should translate Menabrea's account.
[12][14] Babbage suggested that she augment the account with appendices, which she compiled at the end of her translation as a series of seven "notes" labelled A-G.
Her translation was published in August 1843,[12] in Taylor's Scientific Memoirs,[14][15] wherein Lovelace's name was signed "A.A.L".
[17] In the first notes, she explores beyond the numerical ambitions that Babbage had for the machine, and suggests the machine could take advantage of computation in order to deal with the realms of music, graphics,[18] and language.
[8][19][20] Again, it might act upon other things besides number, were objects found whose mutual fundamental relations could be expressed by those of the abstract science of operations, and which should be also susceptible of adaptations to the action of the operating notation and mechanism of the engine.
Supposing, for instance, that the fundamental relations of pitched sounds in the science of harmony and of musical composition were susceptible of such expression and adaptations, the engine might compose elaborate and scientific pieces of music of any degree of complexity or extent.She explains to readers how the analytical engine was separate from Babbage's earlier difference engine,[21] and likens its function to the Jacquard machine,[22] in that it used binary punch cards to denote machine language.
In note C, this point is furthered by the fact that simultaneous and iterated actions can be made by the machine, ensuring that any card or collection of cards can be used several times in the solution of a single problem,[20] essentially anticipating modern methods of control flow and looping.
[17][23] These ideas were brought to a head in the final note, G, where Lovelace sought to demonstrate an example of computation.
Note G only made use of only the four arithmetical operations: addition, subtraction, multiplication and division, the implementation of Babbage's vision: Under the impossibility of my here explaining the process through which this end is attained, we must limit ourselves to admitting that the first four operations of arithmetic, that is addition, subtraction, multiplication and division, can be performed in a direct manner through the intervention of the machine.
This granted, the machine is thence capable of performing every species of numerical calculation, for all such calculations ultimately resolve themselves into the four operations we have just named.It also uses Babbage's idea of storing information in columns of discs, each denoted by
(for variable) and a subscript number denoting which column is being referred to.
is a binomial coefficient, Bernoulli numbers can be calculated in many ways, but Lovelace deliberately chose an elaborate method in order to demonstrate the power of the engine.
In Note G, she states: "We will terminate these Notes by following up in detail the steps through which the engine could compute the Numbers of Bernoulli, this being (in the form in which we shall deduce it) a rather complicated example of its powers.
"[20] The particular algorithm used by Lovelace in Note G generates the eighth Bernoulli number (labelled as
In this way, any variables in this column have their superscript number incremented by one each time.
In column 6, "Statement of Results", the result assigned to the variable in column 4 is shown in its exact value based on the values of the two terms previously assigned.
This column is ostensibly not computed by the engine, and appears to be more to aid clarity and the reader's ability to follow the steps of the program.
Each time a variable either changes, or has its value become relevant by token of its presence as one of the terms in the current command, its value is stated or restated in its respective column.
This presumably mimics the computer's need for only relevant information, thereby tracking the value of a variable as the program parses.
[10] The program sought to calculate what is known by modern convention as the eighth Bernoulli number, listed as
This bug means that if the engine were ever to run this algorithm in this state, it would fail to generate Bernoulli numbers correctly, and would find its final goal value (the eighth Bernoulli number,
Lovelace's program can be implemented in a modern programming language, though due to the above stated error, if transcribed exactly it would return an incorrect final value for
The original program generalised in pseudocode follows as thus: The implementation in pseudocode highlights the fact that computer languages define variables on a stack, which obviates the need for tracking and specifying the current iteration of a variable.
In addition, Lovelace's program only allowed for variables to be defined by performing addition, subtraction, multiplication or division on two terms that were previously defined variables.
Modern syntax would be capable of performing each calculation more concisely.
), the strict notation of two-term arithmetic becomes cumbersome, as in order to define