# Egyptian multiplication and its legacy

6 July 2021

Ancient Egyptians1Iβm talking about Egyptian mathematics from roughly 3,500BC to 350BC, at which point they were replaced with more advanced Greek mathematics. used a non-positional system for writing numbers. It was based on signs which each represented a power of 10, and which were repeated to specify a number:

 1 10 100 1,000 10,000 100,000 1,000,000 πΊ π π’ πΌ π­ π π¨

So the number 69,105, for instance, would be represented as π­π­π­π­π­π­πΌπΌπΌπΌπΌπΌπΌπΌπΌπ’πΊπΊπΊπΊπΊ. This is very similar to roman numerals, or other non-positional systems.

The modern technique for long multiplication (the one we learn in school) relies on a positional system, such as Arabic numerals. In a positional system, instead of a different symbol for each power of the base (usually 10), thereβs a different symbol (a digit) for each number between 0 and the base, and the power of the base with which a digit is associated depends on its position within the number.

Instead, ancient Egyptians performed multiplication by repeated addition. To multiply numbers, say 9Γ13, ancient Egyptians would instead decompose one of the two operands into a sum of powers of two (so, in modern notation, 9=1+8=20+23), then compute the product of the other number with these powers of two through repeated addition (again using modern notation):

Then they would sum the lines corresponding to the base-2 decomposition of the other operand, yielding 13+104=117.

Compared to naive repeated addition, which requires $O(n)$ additions, where n is the smaller of the two operands, this one only needs $O(\log_2 n)$: $\log_2 n$ additions to compute the products with multiples of 2, and another $\log_2 n$ (at most) to sum the relevant multiples.

A somewhat more sophisticated version of Egyptian multiplication is known as peasant multiplication

## Computer multiplication

Computers basically use this method to multiply numbers too. An additional trick is that they work entirely in base 2, so computing $n\times 2^k$ simply requires shifting n to the left2Or to the right, depending on endianness. by k bits.

But we can also see what computers do as a form of long multiplication (the one you learn in school) in base 2:

 1 1 0 1 β 13 Γ 1 0 0 1 β 9 1 1 0 1 β 13 Γ 20 = 13 + 1 1 0 1 . . . β 13 Γ 23 = 104 1 1 1 0 1 0 1 β 117

So Egyptian multiplication is in reality not far from being a half-base-10, half-base-2 version of long multiplication.

## Generalizing

Just like multiplication is repeated addition, exponentiation is repeated multiplication, tetration is repeated exponentiation, etc. In fact, we can use the Egyptian technique to efficiently compute any associative iterated operation, not just those from the hyperoperation sequence. This section proves this generally, but feel free to skip it.

Generally, say we have a set with an associative operation β between its elements (i.e. a semigroup), and an operation β which represents repeated application of β (specifically, $aβn = aβaβ \cdots βa$, where a appears n times).

In our previous example, the set was that of the natural numbers, β was addition, and β was multiplication.

The goal is to compute $aβn$, where a is an element of our set, and n is an integer.

The most straightforward solution is to take the definition of $aβn$ above, and compute the $n-1$ β operations. But we can do better!

The key idea is to notice that $aβ(m+n) = (aβm) β (aβn)$. This is easy to verify: if we expand both sides of the equation, we end up with β applied to a, $m+n$ times. (This is where our associativity requirement on β comes in.)

As a particular case of this equality, we have $aβ2^{k+1} = aβ(2^k + 2^k) = (aβ2^k)β(aβ2^k)$. So if n is a power of 2, such that $n = 2^k$ for some k, then we can

• compute $aβ2 = aβa$,
• using this result, compute $aβ4 = (aβ2)β(aβ2)$,
• using this result, compute $aβ8 = (aβ4)β(aβ4)$,
• and so forth until we get to $aβ2^k = (aβ2^{k-1})β(aβ2^{k-1})$.

(This looks a lot like Egyptian multiplication!) Obviously, this only involves $k = \log_2 n$ applications of β, as opposed to $2^k-1=n-1$ if we had done it naively by applying β repeatedly.

More generally, if n is any integer, we can decompose it into a sum of powers of two (equivalently, write it out in binary). Formally, we get a sequence of numbers $K = {k_0 < \cdots < k_\mathrm{max}}$ such that $n = \sum_{i\in K} 2^i$. (In other words, the elements of K are the bit indices that are set to 1 in the binary representation of n.)

Then using the $aβ(m+n) = (aβm) β (aβn)$ identity again, we end up with $aβn = aβ2^{k_0} β \cdots β aβ2^{k_\mathrm{max}}$. Once again, we can compute and store all the $aβ2^k$ values in $O(\log_2 n)$ operations, and do the final assembly in at most $\log_2 n$ operations as well.

## Conclusion

Some modern algorithms, like binary exponentiation, are also basically this technique. This time β is multiplication, and β is exponentiation.

I find it cool that the key idea (even if itβs not incredibly complex) has been around for around 5,000 years!

For more, I recommend Mathematical Thought from Ancient to Modern Times by Morris Kline; volume 1 covers ancient civilizations.

1. Iβm talking about Egyptian mathematics from roughly 3,500BC to 350BC, at which point they were replaced with more advanced Greek mathematics.Β

2. Or to the right, depending on endianness.Β