Al-Khwarizmi: Algorithms and Algebra

Chronicles of Computation — The Early Mechanisms

Danilo Poccia
Chronicles of Computation
4 min readJul 29, 2023

--

In the heart of the Islamic Golden Age, a Persian scholar named Muhammad ibn Musa al-Khwarizmi (780–850 CE) was making strides in the mathematical world that would echo through the centuries. Born in the region of Khwarezm, now modern-day Uzbekistan, al-Khwarizmi was a scholar in the House of Wisdom in Baghdad, an intellectual hub that attracted the brightest minds of the era.

Photo by Snowscat on Unsplash

Al-Khwarizmi’s works cover many different fields and include:

1. The Compendious Book on Calculation by Completion and Balancing: This is the foundational text of algebra and introduced systematic, rigorous algebraic methods for solving linear and quadratic equations.

2. The Book of the Description of the Earth: This is a significant work in geography that presented the coordinates of hundreds of cities and landmarks, and also discussed the idea of the Earth’s circumference.

3. The Book on the Calculation with Hindu Numerals: This book was instrumental in spreading the Indian numeral system, which we now know as Arabic numerals, throughout the Middle East and Europe.

4. Astronomical tables of Sind and Hind: This is a work in astronomy that includes a set of astronomical tables based on Indian and Greek astronomical knowledge.

Al-Khwarizmi’s most significant contribution was his book on algebra, a groundbreaking piece of literature that introduced the fundamental algebraic methods and techniques for solving equations. This book is considered the foundation of Algebra, a term derived from the Arabic word “al-jabr” in the title of his book, meaning “completion”.

In his book, al-Khwarizmi explained how to solve linear and quadratic equations, a concept that was revolutionary at the time. He introduced the method of “completion”, which involved moving a subtracted number to the other side of an equation, and “balancing”, which involved reducing equal amounts from both sides of an equation. These methods are still the basis of algebra today.

Al-Khwarizmi’s work was not limited to algebra. He made significant contributions to other fields such as astronomy and geography. His work on the calculation of the Islamic calendar, the determination of the direction of Mecca (Qibla), and the creation of one of the earliest world maps are testaments to his diverse intellectual prowess.

An interesting anecdote about al-Khwarizmi is that his name gave rise to the term “algorithm”. The Latin translation of his name, “Algoritmi”, was used in the olden days to refer to the decimal number system, and over time, it evolved into the modern term “algorithm”, reflecting the process of problem-solving that al-Khwarizmi’s work embodied.

Here’s a Python function that uses Al-Khwarizmi’s methods to solve a quadratic equation (x² + 6x + 9 = 0) by completing the square. The solution to this equation is (x = -3). This code extends the example to include generic solutions and modern concepts such as imaginary numbers:

import math

# Coefficients of the quadratic equation
# a*x^2 + b*x + c = 0
a = 1
b = 6
c = 9

# Calculate the discriminant
D = b**2 - 4*a*c

# Check if the discriminant is positive, negative or zero
if D > 0:
# Two distinct real roots exist
x1 = (-b + math.sqrt(D)) / (2*a)
x2 = (-b - math.sqrt(D)) / (2*a)
print(f"The solutions are {x1} and {x2}")
elif D == 0:
# Two equal real roots exist
x = -b / (2*a)
print(f"The solution is {x}")
else:
# Complex roots exist
real_part = -b / (2*a)
imaginary_part = math.sqrt(-D) / (2*a)
print(f"The solutions are {real_part} + {imaginary_part}i"
f"and {real_part} - {imaginary_part}i")

This Python code uses the quadratic formula, which is a direct application of Al-Khwarizmi’s method of completing the square. The discriminant D is calculated first. If D is positive, the equation has two distinct real roots. If D is zero, the equation has two equal real roots. If D is negative, the equation has complex roots. The roots are then calculated and printed accordingly.

Save the previous file as quadratic_equation.py and run it using Python. As expected, this code will output:

The solution is -3.0

Try changing the a, b, and c coefficients to solve different quadratic equations and see when the solution is real or complex.

Al-Khwarizmi’s work laid the groundwork for much of modern mathematics. His methods of problem-solving and his approach to mathematical equations shaped the field of algebra and made it a crucial part of mathematics. His influence extends beyond the realm of academia, with his methods being used in various fields such as engineering, physics, computer science, and more. Let’s not forget that we due him at least two words: algorithm and algebra.

This story is part of the Chronicles of Computation book. The next section is Al-Battani: Astronomy and Trigonometry.

--

--

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.