Ada Lovelace's Note G, or the first program for a machine that didn't exist
The first computer program contained a bug. It was written in 1843 for a machine that would never be built, by a mathematician who never saw it execute a single step, and somewhere in operation 4 she — or the typesetter — swapped two variable names in a division, producing a wrong answer that would sit undetected for over a century until someone finally ran the code on a real computer.
The mathematician was Augusta Ada King, Countess of Lovelace, and the machine was Charles Babbage’s Analytical Engine. In August 1840, Babbage had traveled to Turin and described his proposed Engine — a steam-powered brass calculating machine with a memory store, an arithmetic unit, and a mechanism for reading punched cards — to an audience of Italian scientists. One of them, Luigi Menabrea, transcribed the lecture and published it in French in October 1842. A year later, Charles Wheatstone of the Royal Society suggested that Lovelace translate it into English for Taylor’s Scientific Memoirs. She did, and then went considerably further.
Lovelace’s seven notes — appended to the translation and labeled A through G — ran to roughly three times the length of Menabrea’s original paper. Notes A through F explained the Engine’s architecture. Note G, the last and longest, presented a step-by-step program for computing Bernoulli numbers — a sequence of fractions that arise throughout analysis and that Jakob Bernoulli had studied a century and a half earlier. The program was twenty-five operations long. Menabrea’s longest example was eleven, and it contained no loops. Lovelace’s did: she organized repeated operations into groups that could be cycled through multiple times, inventing what every programmer today would recognize as a loop.
She tracked variables with superscript indices — a running notation of their successive values — and wrote what amounts to a modern state table for a computation, something that wouldn’t have a proper name for another hundred years. Her stated goal was not efficiency. “The object,” she wrote, “is not simplicity or facility of computation, but the illustration of the powers of the Engine.”
The collaboration with Babbage was intense and not always smooth. He supplied the mathematical formulas; she converted them to machine operations. At one point she caught a “grave mistake” in his work and sent it back corrected — a correction he later recalled with something that sounds like chagrin. The irony is that a different error survived. The swapped variables in operation 4 mean the published algorithm would compute −25621/630 where it should have computed −1/30. It is, as far as anyone can tell, the oldest software bug in existence.
The Analytical Engine was never finished. The program was never run in Lovelace’s lifetime — she died in 1852, at thirty-six, of uterine cancer. The first confirmed execution of Note G happened on a modern computer, by researchers who discovered the bug in the process.
What she had grasped, and what Babbage himself had not quite articulated, was that the Engine was not a calculator. It could manipulate any symbols that followed logical rules — numbers, yes, but also musical notes or algebraic expressions or anything else that could be encoded. The machine’s power lay not in what it computed but in the generality of how it could compute: a procedure written down once, followed by anything that understood the rules.
Every programming language since begins from that observation. The machine she described was never finished. The idea inside Note G was finished enough.
Sources
- Note G — Wikipedia — Algorithm structure, the bug, loop invention, Lovelace’s variable notation, publication context.
- What Did Ada Lovelace’s Program Actually Do? — Two Bit History — Technical analysis of the 25-operation program, the computed values, and the oldest known software bug.
- The First Published Computer Programs — History of Information — Translation and publication history, significance of Lovelace’s annotations relative to Menabrea’s original.