A different kind of computer VI: computers without electricity
Machines that compute with bronze, steel, water and marbles: the Antikythera mechanism, Babbage's engines, the MONIAC, the slide rule, the Curta and Turing Tumble. With Python versions of the gear train, the method of differences and the slide rule.
People have been building machines that calculate with gears, levers, water and marbles for more than two thousand years. Some of them did one job, like predicting where the moon would be next month. Others were general enough that, on paper, they could run any program. This part goes through a few of them, from a Greek shipwreck to a toy sold today, with Python versions of the tricks they relied on.
The Antikythera mechanism #
In 1901, divers working on a Roman-era shipwreck off the Greek island of Antikythera brought up statues, glass, coins and a corroded lump of bronze. The lump turned out to hold gears. It's now in 82 fragments at the National Archaeological Museum in Athens, with about a third of the original surviving, including 30 bronze gear wheels. It was built around the second century BC.1

Turning a handle on the side moved pointers on its dials. The front showed the positions of the sun and the moon in the zodiac and the phase of the moon, and the back predicted eclipses and kept track of the dates of the Olympic Games and other festivals. X-ray scans made in 2005 revealed gears hidden inside the fragments and inscriptions that work like a user's guide, and in 2021 a team at University College London published a model of the front display with the five planets known at the time.
The machine is a calculator in a precise sense: the numbers are built into the tooth counts. Greek astronomers, using Babylonian records, knew that the moon goes around the sky 254 times in 19 years. Take the gear that turns once a year with the sun and pass its motion through a chain of gears with the right teeth, and you get a pointer that turns 254 times for every 19 turns of the sun. Here's the chain that drives the moon pointer, checked in Python:
from fractions import Fraction
# (driver, driven) pairs from the sun wheel to the moon pointer
train = [(64, 38), (48, 24), (127, 32)]
ratio = Fraction(1)
for driver, driven in train:
ratio *= Fraction(driver, driven)
year = 365.2422 # days in a tropical year
sidereal = 27.321661 # days for the moon to circle the sky once
real = year / sidereal
print("gear ratio:", ratio, "=", round(float(ratio), 6))
print("real ratio:", round(real, 6))
error = (float(ratio) - real) * 360
print("error per year:", round(error, 3), "degrees")$ python3 gears.py gear ratio: 254/19 = 13.368421 real ratio: 13.368228 error per year: 0.069 degrees
Source
$ python3 gears.py
gear ratio: 254/19 = 13.368421
real ratio: 13.368228
error per year: 0.069 degreesWhat the script shows:
- When one gear drives another, the speed changes by the ratio of their teeth. A 64-tooth gear driving a 38-tooth gear makes the second one spin 64/38 times as fast. A chain of gears multiplies those fractions.
-
Fractionkeeps the result exact, so the product comes out as 254/19, exactly the 254 turns in 19 years, and not a rounded decimal. - The error is about 0.07 degrees per year. The moon's pointer would drift by one degree, about two widths of the full moon, only after some fourteen years of cranking.
- 127 is a prime number, and 254 is 2 times 127. A prime can't be split into a product of smaller ratios, so some gear in the chain needs at least 127 teeth. The one in the mechanism has exactly that.
Babbage and the method of differences #
In the early nineteenth century, navigation, engineering and finance ran on printed tables of logarithms, sines and interest, all calculated by people and copied by typesetters, with errors at every step. Charles Babbage wanted a machine that would calculate the tables and print them, with no human in between.
The trick he used is called the method of finite differences. Take any polynomial, list its values, then write the differences between neighboring values, then the differences of those differences. For a polynomial of degree n, the n-th differences are constant. Running that backwards, a whole table can be produced with nothing but additions, and addition is what gears do well.
This Python script does exactly what the machine does, for n² + n + 41:2
def is_prime(n):
return n > 1 and all(n % d for d in range(2, int(n ** 0.5) + 1))
# f(n) = n*n + n + 41, set up from f(0), f(1) and f(2)
value, d1, d2 = 41, 2, 2
for n in range(42):
if n < 6 or n > 37:
print(f"n={n} f={value}", "prime" if is_prime(value) else "NOT prime")
elif n == 6:
print("...")
value += d1 # only additions, like the engine
d1 += d2$ python3 engine.py n=0 f=41 prime n=1 f=43 prime n=2 f=47 prime n=3 f=53 prime n=4 f=61 prime n=5 f=71 prime ... n=38 f=1523 prime n=39 f=1601 prime n=40 f=1681 NOT prime n=41 f=1763 NOT prime
Source
$ python3 engine.py
n=0 f=41 prime
n=1 f=43 prime
n=2 f=47 prime
n=3 f=53 prime
n=4 f=61 prime
n=5 f=71 prime
...
n=38 f=1523 prime
n=39 f=1601 prime
n=40 f=1681 NOT prime
n=41 f=1763 NOT primeHow the setup works:
- The starting numbers come from the first three values. f(0) = 41, f(1) = 43 and f(2) = 47, so the first differences are 2 and 4, and their difference,
d2, is 2. For a polynomial of degree 2 that second difference never changes. - Each step is two additions: the first difference goes into the value, and the second difference goes into the first. There's no multiplication anywhere in the loop, even though the formula has an
n*n. - The engine does the same thing with columns of figure wheels, one column per difference, and the additions ripple from column to column as the operator turns the crank.
- The prime check is only there to show off the polynomial. It gives primes for every n from 0 to 39, and at 40 the run ends, because 40² + 40 + 41 is 41².
Babbage never finished a difference engine. He designed Difference Engine No. 2 between 1847 and 1849, and in 1985 the Science Museum in London decided to build it from his drawings. The calculating section was finished in 1991, for the two hundredth anniversary of his birth, and the printer in 2002. It has about 8,000 parts, weighs about five tonnes, works with 31-digit numbers and seventh-order differences, and runs on a hand crank.

Between the two difference engines, Babbage designed something much bigger: the Analytical Engine. It separated the memory, which he called the store, from the arithmetic unit, called the mill, and it read its program from punched cards like the ones that controlled Jacquard looms. It could also change what it did next based on a result, which is the piece the difference engines lack. In 1843 Ada Lovelace translated an article about it and added her own notes, three times as long as the article, and the last one, Note G, lays out step by step how the engine would calculate Bernoulli numbers.3 The Analytical Engine was never built, and with unlimited cards and memory it would have been Turing complete.
The MONIAC: an economy made of water #
In 1949 Bill Phillips, a New Zealander studying economics at the London School of Economics, built a computer in which money is water. He made the prototype in his landlady's garage in Croydon for about 400 pounds, partly from the remains of a Lancaster bomber. Water is pumped to the top and flows down through clear tanks and pipes that stand for income, spending, taxes, savings and investment. Valves control how much flows where, and their settings stand for things like the tax rate or how much people save. Change the tax rate and the water levels move to a new balance, and the levels are the answer.

It was meant for teaching, and it turned out to be accurate to about 2 percent. Somewhere between twelve and fourteen were built, for universities, central banks and at least one company. Several still work, and there's one on display at the Science Museum in London and another at the Reserve Bank of New Zealand Museum.
The MONIAC is an analog computer. It doesn't count anything: it builds a physical system that behaves like the problem and lets physics find the answer. Lord Kelvin's tide-predicting machine of 1872 did the same with pulleys, adding up wave-like motions to predict the tides of a port. At MIT between 1928 and 1931, Vannevar Bush and Harold Hazen built the differential analyser, which solved differential equations with rotating shafts and wheel-and-disc integrators, and in 1934 Douglas Hartree and Arthur Porter built a smaller version in Manchester out of Meccano. Analog machines are fast and direct, and their precision is limited by how well the parts were made.
The slide rule: multiplying with a ruler #
Logarithms turn multiplication into addition: log(a × b) = log a + log b. Around 1622 William Oughtred, an English clergyman and mathematician, put two logarithmic scales side by side so that one could slide along the other. Sliding adds lengths, and adding the lengths of two logarithms multiplies the numbers. For the next three and a half centuries, engineers designed bridges, aircraft and power plants with it, and Apollo crews carried a Pickett slide rule on their way to the moon.4

This script draws the two main scales, D on the body and C on the slide, with C moved so its 1 sits over the 2 on D:
import math
SCALE = 50 # characters from 1 to 10
def pos(x):
return round(math.log10(x) * SCALE)
def ruler(offset=0):
line = ["."] * offset + ["-"] * (SCALE + 2 - offset)
for k in range(1, 11):
p = offset + pos(k)
for i, ch in enumerate(str(k)):
if p + i < len(line):
line[p + i] = ch
return "".join(line)
print("D " + ruler())
print("C " + ruler(offset=pos(2)))
a, b = 2.5, 3.2
length = math.log10(a) + math.log10(b)
print(f"log {a} + log {b} = {length:.4f}")
print(f"{a} x {b} = {10 ** length:.4f}")$ python3 slide.py D 1--------------2--------3-----4----5---6--7--8--9-10 C ...............1--------------2--------3-----4----5- log 2.5 + log 3.2 = 0.9031 2.5 x 3.2 = 8.0000
Source
$ python3 slide.py
D 1--------------2--------3-----4----5---6--7--8--9-10
C ...............1--------------2--------3-----4----5-
log 2.5 + log 3.2 = 0.9031
2.5 x 3.2 = 8.0000Reading it:
-
posplaces each number at a distance proportional to its logarithm. That's why the marks crowd together toward 10: the distance from 1 to 2 is the same as from 2 to 4 and from 4 to 8. - Every number on C now sits over twice its value on D. Under C's 2 there's 4, under 3 there's 6, under 4 there's 8, so the whole two-times table can be read in one position.
- The last two lines do the same with decimals. The slide rule can't tell you where the decimal point goes, so the person using it works that out in their head.
- On a real rule the limit is the eye: a 25 cm scale gives about three significant digits, which was enough for most engineering.
The Curta: a calculator in the hand #
One of the most refined mechanical calculators ever sold fits in a hand and looks like a pepper grinder.5 Curt Herzstark, an engineer from a family of calculator makers in Vienna, started designing it in the 1930s. In 1943 he was arrested and sent to the Buchenwald concentration camp, where the guards, who knew his work, let him keep drawing it, hoping to present it to Hitler as a gift. After the camp was liberated in 1945 he took the drawings out with him, and the Curta went into production in Liechtenstein, sold from 1948 until 1972, when electronic calculators replaced it. About 140,000 were made.

Inside there's a single stepped drum, a cylinder with teeth of different lengths, an idea that goes back to Leibniz in the seventeenth century. Sliders on the side set a number, and each turn of the crank adds it to the result at the top. Multiplication is repeated addition with the carriage shifted one place for each digit, the same way multiplication is done on paper. Rally navigators kept using Curtas well into the 1980s.
Turing Tumble: a computer powered by gravity #
The last machine is a toy. Turing Tumble, launched on Kickstarter in 2017 by Paul and Alyssa Boswell, is a tilted board where blue and red marbles roll down through plastic parts: ramps, crossovers, and bits that flip left or right every time a marble passes. Gear bits connect to each other, so flipping one flips the others. With those pieces the board can count in binary and solve logic puzzles.

In 2021 a computer scientist at the University of Illinois proved that a Turing Tumble with an infinitely long board and an unlimited supply of pieces can simulate any Turing machine. Like Rule 110 in the last part, the proof needs a repeating pattern of pieces laid out in advance, and the marbles do the rest.
Where to start #
I'd start with the slide rule, because it's the one machine here that fits on a desk and costs nothing. Raise SCALE in the script to 400 or so, write the positions to a file, draw the marks on two strips of paper with a ruler, and multiply with them. Once the log scale makes sense by hand, a real slide rule from a flea market or an online auction reads much more easily.
For the method of differences, try other polynomials in the engine script. A cubic needs three differences, so it needs d3, and the setup values come from the first four results. Getting the setup right is the hard part, and it's exactly the step Babbage's operators did by hand before turning the crank.
For the Antikythera mechanism, the 2021 paper in Scientific Reports is open access and has detailed drawings of the gear trains. In London, the Science Museum shows Difference Engine No. 2 and a MONIAC. In Athens, the National Archaeological Museum keeps the fragments of the mechanism.
Notes
-
Derek de Solla Price spent two decades studying the fragments and published the first serious reconstruction, Gears from the Greeks, in 1974. ↩
-
Euler noticed in 1772 that this polynomial gives primes for every n from 0 to 39. ↩
-
Note G is often called the first computer program. Historians still argue about how much of it was Lovelace's own work and how much came from Babbage. ↩
-
Slide rules disappeared quickly after the HP-35, the first scientific pocket calculator, came out in 1972. Within a few years the big slide rule makers stopped production. ↩
-
Its shape also earned it the nickname math grenade. ↩