← Back to the Ideas Laboratory
The Art Laboratory

Ada Lovelace's First Computer Program

On the App behind the icon marked B7, the program Ada Lovelace wrote in Note G, the Bernoulli numbers it was built to find, and the twenty-five cards, run in a loop, that carried it there.

The App Itself

The Ada Lovelace computer program App is accessed from the icon, B7, adjacent to this one on the front page. Here follows a discussion on what the App does and what indeed, Ada's own program, which is simulated in the App, actually did. The world's first ever computer program was published in 1843, by Ada Lovelace, who was the daughter of the famous Lord Byron. The text below explains what we are seeing.

The program even has the dubious distinction of containing the world's first ever computer bug, an upside-down fraction causing it to generate an incorrect string of results. This needs to be fixed before the App gives the correct values. Thankfully, you just have to click on two tick boxes at the top of the page, correcting operations 4 and 24, to do this.

The App simulates the progression down the column of operations at the press of a key. As you click through, you can see the contents of the computer's memory and the operations being performed. Remember Ada's table only had 17 columns and that corresponds to 17 bytes of memory being used, yes that's bytes not megabytes!

Check out Ada's table of columns and rows with this reconstruction →

Ada's Program, as Documented in Note G

Ada's own program calculated a set of numbers called Bernoulli numbers. The program itself and its aim was carefully reconstructed by me from her famous section of text called Note G. So we have all these layers: my App, Ada's computer program, her documentation in Note G, and her ultimate goal to calculate Bernoulli numbers using computer programming. In light of these layers, the following account will lead us carefully from one aspect of the story to the next. Enjoy!

Diagram marking n = 4 in the reconstructed Note G table
Operation 4 — the exact step, marked here as n = 4, where the published table swaps two variables in a division and produces the famous first bug, corrected by the App's tick box above. Click through for the full reconstructed table.

Ada's actual computer program is essentially a table of columns and rows in which numbers are shown to be multiplied, divided, added or subtracted across the columns. The reading down the column corresponds to the progress of the calculation through time and to the literal movement of gears in the machine which was to perform these operations. The machine was Charles Babbage's Analytical Engine. Charles Babbage was a good friend of Ada Lovelace. Fully documented in engineering drawings and partly built in his lifetime and by his son afterwards, a complete working reconstruction of the Engine has never actually been finished; a long-running project continues to work towards one from the original drawings. Nevertheless, ongoing reconstruction of this important historical moment has helped to highlight the importance of the program too.

The Bernoulli Numbers

The purpose of Ada's program, apart from being an illustration of what a computer program might actually look like to an 1843 reader, is to create a sequence of numbers. This is the Bernoulli sequence and mathematicians, including Bernoulli himself, noted they kept popping up when calculations were made for summing up long sequences in different areas of maths.

They became prized, not only for their usefulness in shortcutting laborious multiplication in these sequences, but also because they were notoriously difficult to calculate themselves. Once calculated, they went into the world's mathematical tables and served as valuable basecamps for these long calculations. At the time of Ada in 1843, only 15 had been worked out. With modern computers the number is 100,000,000. Who knows how far Ada would have reached if Babbage had actually been able to build his machine and Ada had been able to run her program on it.

Ada's B7 is in fact the earliest Bernoulli number that uses the looping system of her program, and all subsequent Bernoullis use more and more of these loops. The reason for this is that the Bernoullis themselves had to be calculated from all the previous Bernoulli numbers that had come before them, and further, each of these numbers in turn had to be multiplied by a chain of ever increasing length made up of fractions, essentially 8/2×7/3×6/4×5/5… until the cycle for that Bernoulli number had ended. Then it would be on to the next Bernoulli number, and so on.

For orientation, we are placed early in the Bernoulli sequence here. In other words, in 1843, of the 15 Bernoullis that had been found, Ada was cutting her teeth on a repetitive method that could calculate the 4th Bernoulli from the previous 3. There would be 11 more Bernoullis to go after that, before she would have been breaking into the unknown value of the 16th Bernoulli number, and then ever onwards.

A note on the numbering. The App refers to Ada's B7 and that is clearly at odds with the idea that it was the 4th number to be found. Elsewhere you will see a reference to the modern convention of describing it as the 8th number, this doubling due to a convention that alternate Bernoullis must be counted even though they always equal zero. These are all different labels, designated at different times for the same thing.

The Material Reality of the Cards, and the Loop

You will see the operations described as cards. The cards resembled those that were used in the Jacquard textile looms of the day. Each card in Ada's program would initiate its particular operation, one after another, cycling through the whole stack of 25. These cards could also be counted backwards in a single wadge if a particular condition were met, such as a counter not yet reaching zero. You can see this simulated in the App, where cards 13 to 23 reappear a second time. In modern day terminology this is called a loop, and Ada's program used them. To calculate the Bernoulli numbers, many of these loops were put together, multiplying the computing power without any mental effort from the manual operator.

Finally, to summarise Ada's Note G, after 25 cards, one loop and 36 steps in all, the relatively early Bernoulli number, known as Ada's B7, pops out. Its value is −1/30. Note G is just a step by step guide of the calculation of this particular Bernoulli number. But her method is applicable to all the Bernoulli numbers that follow.