Tuesday, December 8, 2015

Ada Lovelace, Charles Babbage and the First Computer Program

The 10th of December 2015 will be the 200th Anniversary of the birth of Ada Lovelace.

In 1842, in Italy, Charles Babbage gave his only public lecture on The Analytical Engine. The lecture was transcribed, in French, by an Italian military engineer. Ada translated the transcript into English, and subsequently Babbage suggested she add her own commentary on the transcript.

This she did, and in 1843 she published the translation of the lecture, along with a copious set of her own notes (that were twice as long as the translation of the lecture). In one of these notes is a diagram that is considered to be the earliest published computer program.

I was intrigued as to what this program looked like, and how we could run it today. So I explored this in the following three articles:

Part 1: Starting with the diagram, I wrote my own version of the algorithm in a modern programming language (Python). Then I wrote a transliteration of the diagram (also in Python) that could be run directly, and produced an "assembly language" listing that corresponds to the cards that would be used to program the Analytical Engine (if it had been built).

Part 2: I wrote an emulator for the Analytical Engine, which could run the assembly language program produced in Part 1.

Part 3: I code up an assembler that reads a mnemonic format corresponding directly to the diagram in Ada's note and produces the appropriate sequence of cards needed to program the Analytical Engine Emulator from Part 2. Finally we produce a program that corresponds directly to Ada's diagram and runs on the Analytical Engine Emulator.

The end result is an emulator for the Analytical Engine in Python that lets you run Ada's program to generate Bernoulli Numbers, or you can write your own programs for it.