Skip to content

Science and invention

Ada Lovelace's first program: what Note G actually computed

A plain-English walk through the 25 operations, the bug in line 4, and the long argument over who deserves the credit

By Eternal Gardens

8 min read

A brass calculating engine and punched cards in a lamplit study
In this article
  1. What was Note G?
  2. What are Bernoulli numbers, and why did she pick them?
  3. How did the Note G program work, step by step?
  4. The loop and the decision
  5. The bug in operation 4
  6. Did Ada Lovelace really write the first computer program?
  7. What else did Lovelace see in the engine?
  8. Ask the Ada Lovelace character yourself

Ada Lovelace's first program is a table in Note G, the last of her notes on Charles Babbage's Analytical Engine, published in 1843. It lists 25 operations the engine would follow to work out one Bernoulli number, which she called B₇ (its value is −1/30). The engine was never built, so the program never ran.

That is the short answer. The longer one is more fun. The table holds a loop and a decision, much like code today. It also has a bug, and it sits in the middle of a long-running argument about credit.

What was Note G?

Note G is the seventh and last of the notes Lovelace added to her English translation of an article about Babbage's machine. The table at its end is the part people call the first computer program.

Menabrea's article came first. Babbage gave talks on his Analytical Engine in Turin in 1840. An Italian military engineer, Luigi Menabrea, wrote them up in French, and his paper came out in Geneva in October 1842. Charles Wheatstone, a scientist friend, asked Lovelace to translate it. Babbage suggested she add notes of her own.

She did, at length. Babbage later wrote that her notes ran to "about three times the length of the original memoir." They were labelled A to G and signed only "A.A.L." The whole piece appeared in Taylor's Scientific Memoirs in 1843. You can read the whole thing free in a transcription at Fourmilab.

Timeline of Ada Lovelace and Note G from 1833 to 1852
From a party in 1833 to a printed program in 1843. Dates from Wolfram, BBC Science Focus and the 1843 text.

What are Bernoulli numbers, and why did she pick them?

Bernoulli numbers are a sequence of fractions that turn up when you add powers, such as 1² + 2² + 3² and so on. Lovelace picked them because they were hard, which made them a good test of the engine.

Jacob Bernoulli described them in a book printed in 1713, after his death. Seki Takakazu found them in Japan at about the same time. Lovelace knew easier ways to get them. She said so, and then chose a harder one on purpose:

"As however our object is not simplicity or facility of computation, but the illustration of the powers of the engine, we prefer selecting the formula below, marked (8.)" Ada Lovelace, Note G, 1843

Her formula says that one long sum always equals zero:

0 = A₀ + A₁B₁ + A₃B₃ + A₅B₅ + … + B₂ₙ₋₁

Each A is a fraction built from n. Each B is a Bernoulli number. If you already know the earlier B's, the last one is the only unknown, so you can solve for it. Set n = 4 and you get B₇.

Her labels differ from the ones used today. She gave the numbers odd labels, each one lower than the modern index.

Lovelace's labelModern labelValue
B₁B₂1/6
B₃B₄−1/30
B₅B₆1/42
B₇B₈−1/30

The values are the standard modern ones. In Note G, B₁, B₃ and B₅ are given as data. The program finds B₇.

The original 1843 Note G table, a large printed grid of operations and variable columns
The table as printed in 1843: 'Diagram for the computation by the Engine of the Numbers of Bernoulli'. Public domain, via Wikimedia Commons.

How did the Note G program work, step by step?

The program fed numbers from storage columns into the engine's arithmetic unit, one operation at a time. Each line takes two stored values, does one sum with them, and puts the answer back in a column.

Babbage's design held numbers in columns of discs, which Lovelace called Variables: V₁, V₂, V₃ and so on. At the start, V₁ holds 1, V₂ holds 2 and V₃ holds n, which is 4. The given Bernoulli numbers sit in V₂₁, V₂₂ and V₂₃. The answer goes into V₂₄.

Here is what the 25 operations do, with the real numbers for n = 4.

  1. Operations 1 to 6 build A₀. The engine makes 2n (8), then 2n − 1 (7) and 2n + 1 (9). It divides them and halves the result to get 7/18. Then it subtracts that from an empty column, which turns it negative: A₀ = −7/18.
  2. Operation 7 works out n − 1 and keeps it in V₁₀ as a counter.
  3. Operations 8 to 12 make A₁ = 2n ÷ 2 = 4, multiply it by B₁, and add the result to the running total. The counter drops by one.
  4. Operations 13 to 23 build the next A one factor at a time. A₃ comes out as 14. The engine multiplies it by B₃, adds that to the total, and lowers the counter again.
  5. The group 13 to 23 then runs a second time to make A₅ = 28/3 and add B₅A₅. Now the counter reaches zero.
  6. Operation 24 moves the total into V₂₄. Operation 25 adds one to n and clears some working columns, ready for B₉.

The running total ends at 1/30. Since the full sum must equal zero, B₇ is −1/30. The table itself shows only sizes, not signs. Lovelace wrote that "the engine would bring out the sign for each of them correctly of course."

Redrawn and simplified version of the Note G table with all 25 operations and worked values for n equals 4
Our redrawn Note G table. Operation names and variables follow the 1843 original; the worked values for n = 4 are our own check.

The loop and the decision

Two features make this look like a modern program.

The first is a loop. Lovelace saw that operations 13 to 23 do the same job each time, using the same columns. Only operation 21 changes, reaching for the next B. As she put it, "every unit added to n in B₂ₙ₋₁, entails an additional repetition of operations (13…23)." That is why 25 operation cards can compute any Bernoulli number, however large n gets. She also planned for the engine to run through the whole series, one number after another. For that she described "a cycle of a cycle" of cards. Today we would call it a nested loop.

The second is a decision. Operation 7 checks whether n − 1 is zero. If it is, the engine has already finished B₁ and should stop or start the next number. If not, it carries on. Lovelace wrote that the engine follows one course or the other "contingently on the one or the other result of Operation 7."

Flow chart of the Note G program showing setup, the counter test, the repeated group of operations 13 to 23, and the reset
How the 25 operations fit together: one setup pass, a counter, and a group that repeats once for each extra value of n.

The bug in operation 4

The printed table has a mistake. Operation 4 divides V₅ by V₄, which gives 9/7. The text beside it says the result should be 7/9, so the division is upside down.

Stephen Wolfram spotted it in his 2015 essay on Lovelace: "the fraction is upside down." In 2018 the blog Two-Bit History rewrote the program in C and hit the same bug. It suggested the slip "may well have been a typesetting error." Run as printed, the program gives a wrong answer. Swap the two values and it gives −1/30.

Did Ada Lovelace really write the first computer program?

Note G was the first long program for Babbage's engine to appear in print. Whether Lovelace was the first person to write a program, and how much of Note G was hers alone, is still argued over.

Start with what is not in doubt. The notes carry her initials. Babbage, writing in 1864, said the selection of examples "was entirely her own." The Science Museum calls Note G "the first published algorithm, sometimes credited as the first computer programme."

Now the harder parts. Babbage's 1864 memoir says this about the Bernoulli section:

"So also was the algebraic working out of the different problems, except, indeed, that relating to the numbers of Bernouilli, which I had offered to do to save Lady Lovelace the trouble. This she sent back to me for an amendment, having detected a grave mistake which I had made in the process." Charles Babbage, Passages from the Life of a Philosopher, 1864 (Project Gutenberg)

So Babbage claims the algebra and gives her credit for finding his error. Her letters from 1843, quoted by Wolfram, show her deep in the work. In one she writes of "so amazing a quagmire & botheration with these Numbers."

Babbage had also sketched short sequences of operations for his engine years earlier. Wolfram describes ones from 1837 and 1838 that survive in Babbage's papers. Menabrea's own article, the one Lovelace translated, includes a table for solving two equations. Those came first. They were also much simpler. Wolfram writes that Babbage's papers hold "nothing as sophisticated" as her Bernoulli computation.

The last question is whether she had the maths. Some writers have doubted it. Christopher Hollings, Ursula Martin and Adrian Rice studied her papers in Oxford's Bodleian Library. In a 2020 piece for BBC Science Focus, they conclude that she was a capable mathematician, fully able to work with Babbage. Wolfram's verdict: "Babbage certainly helped and commented on Ada's work, but she was definitely the driver of it."

There is also a quibble about the word "program." The table shows what happens to each column at each step. The Oxford authors call it an "execution trace." The program proper would have been the stack of punched cards.

Four cards summing up what is agreed and what is argued about Lovelace's role in Note G
What the sources agree on, and where they part ways.

What else did Lovelace see in the engine?

Her notes go well past arithmetic. In Note A she wrote that the engine "weaves algebraical patterns just as the Jacquard-loom weaves flowers and leaves." She guessed it might work on things other than numbers, if their rules could be written down. Music was her example: the engine "might compose elaborate and scientific pieces of music of any degree of complexity or extent."

She also set a limit. Note G opens with a warning:

"The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform." Ada Lovelace, Note G, 1843

About a century later, Alan Turing called this "Lady Lovelace's objection" and argued against it.

Babbage never finished the engine. The Science Museum's account of women in computing notes that "only trial pieces remain." Like many of Leonardo da Vinci's machines, Lovelace's program lived only on paper. Lovelace died on 27 November 1852, aged 36.

Ask the Ada Lovelace character yourself

If you want to test your understanding, you can talk with the Ada Lovelace character on Eternal Gardens. It is an Eternal Gardens interpretation of Ada Lovelace, grounded in published and public-domain sources. It is not the historical Ada Lovelace and does not speak for her. You can try it free, without an account.

The Ada Lovelace character's chat page on Eternal Gardens
The Ada Lovelace chat on Eternal Gardens, with suggested questions under the first message.

Some questions worth asking:

  • Why did you choose Bernoulli numbers for Note G, and not something simpler?
  • What does operation 7 do, and why does it matter if n is 1?
  • What did you mean when you said the engine cannot originate anything?
  • How did you and Babbage split the work on the notes?
  • What would the engine need in order to compose music?

Check its answers against the 1843 text, the way you would with any source. Our guide to getting trustworthy answers from historical AI characters has more on that. And if you would rather build a character of your own, see how to create an AI character.

Written with AI assistance and reviewed by Eternal Gardens.

Share this article

Frequently asked questions

What was Ada Lovelace's first program?

It is the table at the end of Note G, the last of her notes on Babbage's Analytical Engine, published in 1843. It sets out 25 operations the engine would follow to compute the Bernoulli number she called B₇, which is −1/30. A group of operations repeats as a loop. The engine was never built, so the program never ran.

What did Note G calculate?

Note G calculates a Bernoulli number. Lovelace used a formula in which a long sum always equals zero, so the newest Bernoulli number can be found from the earlier ones. Given B₁, B₃ and B₅, with n = 4, the table computes B₇. In today's numbering that is B₈, whose value is −1/30.

Did Ada Lovelace's program have a bug?

Yes. In operation 4 the printed table divides V₅ by V₄, but the result column says (2n − 1) ÷ (2n + 1), which needs V₄ ÷ V₅. Stephen Wolfram noted that the fraction is upside down, and a 2018 rewrite of the program in C hit the same error. It may have been a typesetting slip. Swap the two and the program gives −1/30.

Was Ada Lovelace really the first computer programmer?

It depends on what you count. Babbage sketched short operation sequences for his engine in 1837 and 1838, and Menabrea's 1842 paper has a small table for solving two equations. Note G is far longer and was the first full program for the engine to appear in print. Babbage said he did the Bernoulli algebra, while Lovelace found his mistake. Historians still disagree about how to divide the credit.

Why did Lovelace choose Bernoulli numbers?

She wanted a hard example. In Note G she wrote that her object was 'not simplicity or facility of computation, but the illustration of the powers of the engine.' Bernoulli numbers let her show a loop that repeats, columns that are reused, and a test that decides what the engine does next, all in one worked example.

Sources

  1. Menabrea, Sketch of the Analytical Engine, with notes by Ada Lovelace (1843), Fourmilab transcriptionfourmilab.ch
  2. Charles Babbage, Passages from the Life of a Philosopher (1864), Project Gutenberggutenberg.org
  3. Stephen Wolfram, Untangling the Tale of Ada Lovelace (2015)writings.stephenwolfram.com
  4. Hollings, Martin and Rice, How Ada Lovelace's notes on the Analytical Engine created the first computer program, BBC Science Focus (2020)sciencefocus.com
  5. Science Museum, Women in computingsciencemuseum.org.uk
  6. Two-Bit History, What Did Ada Lovelace's Program Actually Do? (2018)twobithistory.org
  7. Wikipedia, Note Gen.wikipedia.org
  8. Wikipedia, Bernoulli numberen.wikipedia.org
  9. Computer History Museum, Ada Lovelacecomputerhistory.org

About the author

Eternal Gardens

Eternal Gardens is an AI character platform where you can talk with characters drawn from the writings of historical and literary figures, and build worlds and stories with them.

All articles