The Abacus: An Ancient Calculator

Chronicles of Computation — The Early Mechanisms

Danilo Poccia
Chronicles of Computation
4 min readJun 19, 2023

--

In the annals of human history, the invention of the abacus shows our innate desire to quantify and understand the world around us. We can find this ancient device, a precursor to the modern calculator, in ancient China. It’s actual origins are not clear, and it might have been first used by the Babylonians centuries before.

The abacus, or “suanpan” as it was known in China, was a simple yet ingenious device. It consisted of a series of rods, each adorned with beads. The beads in the upper section, known as “heaven beads”, represented the value of five when pushed down towards the horizontal beam. The beads in the lower section, the “earth beads”, represented a value of one when pushed up towards the beam. This structure allowed for complex calculations, including addition, subtraction, multiplication, division, and even root calculations.

Photo by Crissy Jarvis on Unsplash

The abacus was not just a tool for mathematicians. It was a ubiquitous instrument in the bustling markets of ancient China, where traders used it to calculate their profits and losses. It was probably a common sight to see a merchant, his fingers deftly moving the beads along the rods, his eyes focused on the task at hand. The abacus was a symbol of commerce and trade, an important tool for the economic vibrancy of ancient China.

The use of the abacus was not limited to physical calculations. At some point in time, skilled abacus users could perform calculations mentally, manipulating an imaginary abacus in their minds. This skill, known as abacus-based mental calculation, or mental abacus, was acquired through intensive training. Students would first memorize the principles of abacus operations, then practice calculations on a physical abacus. Over time, they would transition to performing calculations mentally, visualizing the movement of the beads in their minds.

The invention of the abacus is a symbol of our desire to understand and quantify the world around us. Let’s delve into some Python code that simulates the operation of an abacus. This code helps understand how the abacus facilitates arithmetic operations.

# Python code to simulate an abacus

class Abacus:
def __init__(self):
# Initialize 10 rods with 0 beads
self.rods = [0]*10

def add(self, rod, value):
print(f"Add {value} beads to rod {rod+1}")
# Add beads to a rod
self.rods[rod] += value
# Carry over beads if more than 10 on a rod
if self.rods[rod] >= 10:
self.carry(rod)

def carry(self, rod):
print(f"Carry over beads to rod {rod+2}")
self.rods[rod] -= 10
# Add bead to next rod
if rod < len(self.rods)-1:
self.add(rod+1, 1)
else:
print("Abacus is full")

def subtract(self, rod, value):
print(f"Subtract {value} beads to rod {rod+1}")
# Subtract beads from a rod
self.rods[rod] -= value
# Borrow beads if less than 0 on a rod
if self.rods[rod] < 0:
self.borrow(rod)

def borrow(self, rod):
print(f"Borrow over beads to rod {rod+2}")
self.rods[rod] += 10
# Subtract bead from next rod
if rod < len(self.rods)-1:
self.subtract(rod+1, 1)
else:
print("Abacus is empty")

def display(self):
# Display the current state of the abacus
print("Abacus:")
for i in range(9, -1, -1):
# Only show rods greather than 0
if self.rods[i] > 0:
print(f"Rod {i+1}: {'*' * self.rods[i]}")

# Create an abacus
abacus = Abacus()

# Add 7 beads to the first rod
abacus.add(0, 7)
abacus.display()

# Add 4 beads to the first rod (carry over)
abacus.add(0, 4)
abacus.display()

# Subtract 2 beads from the first rod (borrow)
abacus.subtract(0, 2)
abacus.display()

In this code, each rod on the abacus is represented by an element in a list. The add method adds beads to a rod, while the subtract method removes beads from a rod. If more than ten beads are added to a rod, the carry method is invoked to carry over the excess beads to the next rod. Similarly, if beads are subtracted from a rod and the number of beads becomes negative, the borrow method is invoked to borrow beads from the next rod. The display method prints the current state of the abacus, showing only rods that have at least a bead, with each bead represented by an asterisk.

The code creates an instance of the Abacus class and performs a series of operations: adding 7 beads to the first rod, adding 4 more beads to the first rod (which triggers a carry), and subtracting 2 beads from the first rod (which triggers a borrow). After each operation, it displays the current state of the abacus.

Save the previous file as abacus.py and run it using Python. Here’s the output with some calculations:

Add 7 beads to rod 1
Abacus:
Rod 1: *******
Add 4 beads to rod 1
Carry over beads to rod 2
Add 1 beads to rod 2
Abacus:
Rod 2: *
Rod 1: *
Subtract 2 beads to rod 1
Borrow over beads to rod 2
Subtract 1 beads to rod 2
Abacus:
Rod 1: *********

Try to change the rod and the number of beads added and subtracted. Check how carrying over and borrowing can work also across more than one rods.

The abacus, with its simple structure and ingenious design, has left an indelible mark on human history. The abacus was more than just a counting tool; it was a device that facilitated commerce, supported infrastructure projects, and drove economic growth. Its influence can still be seen today in modern computing systems, which, at their core, are tools designed to simplify and expedite calculations.

This story is part of the Chronicles of Computation book. The next section is Sunken Treasure: The Antikythera Mechanism.

--

--

Danilo Poccia
Chronicles of Computation

Passioned about IT, IoT, AI, ML, and other acronyms. Writing the Chronicles of Computation book. Chief Evangelist (EMEA) @ AWS. Opinions are my own.