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.


Thursday, October 22, 2015

Downgrading a Package in MacPorts

MacPorts installed a new version of XEmacs and it broke things. So instead of fixing it I just went back to the previous version.

Here's how I did it:

  1. Create a local repository in ~/lib/macports/local:

    % mkdir ~/lib/macports/local

  2. Add the local repository to /opt/local/etc/macports/sources.conf:

    file:///Users/jim/lib/macports/local

  3. Find the previous revision of XEmacs:

    % svn log http://svn.macports.org/repository/macports/trunk/dports/editors/xemacs

    It's r141410.

  4. Check it out (into ~/lib/macports/local):

    % svn co --revision r141410 http://svn.macports.org/repository/macports/trunk/dports/editors/xemacs/ editors/xemacs/

  5. Run portindex on the local repository:

    % portindex ~/lib/macports/local

    It should report: "Ports successfully parsed: 1"

  6. Now port list xemacs shows both versions.

    xemacs  @21.4.22  editors/xemacs
    xemacs  @21.5.16  editors/xemacs


  7. Install the local version

    # port install xemacs @21.4.22

That's it.