Note G: The First Computer Program i

Note G Calculator

Description: Interactive calculator for Bernoulli numbers using both Ada Lovelace's original 1843 algorithm and modern recursive formula.
How-to: Select algorithm mode (Modern or Historical), enter a value n (0-110), and click Calculate to see exact fractional results.
Historical Bug: In Historical mode, enable the Operation 13 bug to see Ada's original error from her published diagram.
Performance: Lower values (0-20) are instant. Higher values (40+) may take longer due to exact fraction arithmetic.

The Enchantress of Numbers

In 1843, Ada Lovelace wrote what is considered the world's first computer program — an algorithm to calculate Bernoulli numbers on Charles Babbage's proposed Analytical Engine. Though the machine was never built in her lifetime, her vision transcended hardware limitations and established the foundation of computer programming.

Who Was Ada Lovelace?

Augusta Ada King, Countess of Lovelace (1815–1852), was an English mathematician and writer who worked with Charles Babbage on his Analytical Engine. The daughter of poet Lord Byron, Ada possessed an exceptional gift for mathematics and logical reasoning.

While translating an Italian article about Babbage's machine, she added extensive notes of her own — labeled A through G. Note G contained a complete algorithm for computing Bernoulli numbers, making it the first published algorithm intended to be processed by a machine.

"The Analytical Engine weaves algebraical patterns just as the Jacquard loom weaves flowers and leaves."

— Ada Lovelace

Why Bernoulli Numbers?

Ada chose Bernoulli numbers to demonstrate the Analytical Engine's capabilities because:

Understanding Bernoulli Numbers

Bernoulli numbers are a sequence of rational numbers with deep connections to number theory and analysis. They appear in formulas for sums of powers, Taylor series, and the Riemann zeta function.

The Recursive Formula

The standard Bernoulli recurrence relation is:

Bₙ = -1/(n+1) × Σ(k=0 to n-1) [C(n+1,k) × Bₖ]

Where:

Base Cases

Known Values i

Bernoulli Number Reference

B₀ = 1: Starting value by definition.
B₁: Modern convention uses -1/2, Ada used +1/2. Both are valid depending on the definition used.
Even indices: Non-zero fractions that grow in complexity (B₂, B₄, B₆, B₈...).
Odd indices (shaded): All odd-indexed Bernoulli numbers except B₁ equal zero. This is a fundamental mathematical property!
Pattern: Notice alternating signs and how numerators grow much faster than denominators.

B₀
1
B₁ (Modern)
-1/2
B₁ (Ada's)
+1/2
B₂
1/6
B₃
0
B₄
-1/30
B₅
0
B₆
1/42
B₇
0
B₈
-1/30
B₉
0
B₁₀
5/66
B₁₁
0
B₁₂
-691/2730
B₁₃
0
B₁₄
7/6

Historical Note on B₁

In Ada Lovelace's era, mathematicians used B₁ = +1/2. Modern mathematics standardized on B₁ = -1/2 to make the generating function and recursion formulas more elegant. This calculator lets you experience both conventions—use Historical Mode to see Ada's original approach, or Modern Mode for the current standard.

Pattern Notice

Odd indices (shaded): All Bernoulli numbers with odd index greater than 1 equal zero (B₃ = B₅ = B₇ = B₉ = ... = 0). This is a fundamental mathematical property. Only B₁ and the even-indexed Bernoulli numbers are non-zero.

Bernoulli Number Calculator i

Using the Calculator

Step 1: Choose algorithm mode (Modern = standard formula, Historical = Ada's operation-based approach).
Step 2: Optionally enable the historical bug in Historical mode to see Ada's original error.
Step 3: Enter a value n between 0 and 110.
Step 4: Click Calculate to compute the nth Bernoulli number as an exact fraction.
Results: View exact fraction, decimal approximation, and detailed computation steps.

Experience Ada's algorithm in action! Enter a value of n to compute the nth Bernoulli number as an exact fraction.

Uses modern recursive formula with B₁ = -1/2 (standard mathematical convention)

Result: B

Computation Steps:


                

Ada's Note G: The Operation-Based Algorithm i

Historical Algorithm

Low-level approach: Sequential operations on named variables (V₁, V₂, etc.), simulating the Analytical Engine's Store and Mill.
Store: Memory columns holding variables.
Mill: Processor performing arithmetic.
Operations: Each step (Op.1, Op.2, etc.) manipulates specific variables, like assembly language for a mechanical computer.
B₁ = +1/2: Ada used the historical mathematical convention of her era.

Ada Lovelace's Note G is fundamentally different from modern programming—it's not written as a high-level formula, but as sequential operations for a machine that manipulates physical variables. Think of it as assembly language for a mechanical computer.

The Analytical Engine's Architecture

Babbage's Analytical Engine had two key components:

Ada's Algorithm Structure

Step 1: Initialize Store Variables

V₁ ← 1 (constant) V₂ ← 2 (constant) V₃ ← n (the index we're computing) V₄, V₅, V₆, V₇ ← 0 (working registers)

Step 2: Compute Key Ratio

The first three operations compute (n-1)/(n+1):

Op.1: V₄ = V₃ - V₁ → V₄ = n - 1 Op.2: V₅ = V₃ + V₁ → V₅ = n + 1 Op.3: V₄ = V₄ / V₅ → V₄ = (n-1)/(n+1)

Step 3: Initial Accumulation

Operations 4-6 begin combining with B₀ and B₁:

Op.4: V₆ = V₄ × B₀ Op.5: V₇ = V₄ × B₁ Op.6: V₆ = V₆ + V₇

Step 4: Loop Over Bernoulli Terms

Operations 7-13 repeat in a loop, processing each previous Bernoulli number with appropriate scaling factors. This is where the control flow emerges—Ada specified:

Step 5: Final Computation

Bₙ = -V₆ / V₅ HALT

The Historical B₇ Bug

⚠️ Operation 13 Error: In Ada's published diagram for computing B₇, Operation 13 was printed as:

V₂₁ - V₁₃ → V₁₃

But it should have been:

V₂₁ + V₁₃ → V₁₃

This subtraction instead of addition produces an incorrect result. The first bug! Modern computer scientists discovered this error when analyzing her work in the 1950s.

Why This Matters

"The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform."

— Ada Lovelace

Modern Algorithm: How It Works i

Modern Algorithm

High-level approach: Uses standard recursive formula Bₙ = -1/(n+1) × Σ(k=0 to n-1) [C(n+1,k) × Bₖ]
B₁ = -1/2: Modern mathematical convention.
Advantages: Concise, mathematically elegant, easier to understand and verify.
Comparison: This is what modern programmers would write, versus Ada's machine-level operations.

The modern approach uses a high-level mathematical formula rather than low-level operations:

The Recursive Formula

Bₙ = -1/(n+1) × Σ(k=0 to n-1) [C(n+1,k) × Bₖ]

Algorithm Steps

  1. Initialize: B₀ = 1, B₁ = -1/2 (modern convention)
  2. For each n ≥ 2:
    • Initialize sum = 0
    • For k from 0 to n-1:
      • Compute binomial coefficient C(n+1, k)
      • Multiply by Bₖ
      • Add to sum
    • Bₙ = -sum / (n+1)
  3. Simplify: Reduce fraction using GCD

Key Differences from Ada's Algorithm

Aspect Ada's Note G Modern
Approach Sequential operations (assembly-like) Mathematical formula (high-level)
B₁ value +1/2 (historical convention) -1/2 (modern convention)
Variables Named registers (V₁-V₇) Array indexing (B[k])
Abstraction Low-level machine operations High-level algorithm

Exact Fraction Arithmetic

Both algorithms preserve precision using exact rational arithmetic:

Legacy & Impact

Ada Lovelace's Note G represents far more than a mathematical exercise. She envisioned possibilities for computing that wouldn't be realized for over a century:

Today, Ada Lovelace Day (second Tuesday of October) celebrates women in STEM fields. Her vision and intellect continue to inspire programmers, mathematicians, and engineers worldwide.

A Letter to Charles Babbage

On August 14, 1843, shortly after completing her translation and notes on the Analytical Engine, Ada wrote this passionate letter to Charles Babbage:

My dear Babbage,

I am writing to you with a sense of urgency and excitement. As I continue to delve into the capabilities of your Analytical Engine, I am increasingly convinced that its potential far surpasses that of any mere calculating machine. The machine, with its ability to perform any calculation we can devise, seems to me to be a harbinger of a new age, where the boundaries between what is possible and what is not are redefined.

That brain of mine is something more than merely mortal, as time will show. I feel that I am destined to play a significant role in unlocking the mysteries that this machine can reveal. My understanding of mathematics and my ability to see patterns and connections that others might miss will, I believe, be crucial in maximizing the Engine's potential.

I implore you, my dear friend, to not let this project falter due to lack of support or resources. Your genius has brought us to the precipice of a new era, and it would be a travesty if this work were to go unfinished. I am committed to aiding you in any way I can, whether through my own financial means or by leveraging my connections to secure patronage.

Let us work together to ensure that the Analytical Engine is not just a dream, but a reality that will astound the world.

Your friend and collaborator,

Ada Lovelace

— Letter to Charles Babbage, August 14, 1843

This letter captures Ada's extraordinary confidence in her own abilities and her deep commitment to realizing the potential of the Analytical Engine. Her prophecy that her brain was "something more than merely mortal" proved prescient — her contributions to computing would not be fully appreciated until more than a century after her death.