Some thoughts about the method of complements

Some thoughts about the method of complements

By Marco Antonio Garrido
· 867 words · 5 minutes reading time

Last night, when I was in my bed, I had some reveries of my childhood. For whatever reason, I remembered when I first learnt to add 2 numbers at school and how, later on that day or that week, I asked my father how things worked with multiple numbers at the same time. Of course, I didn't know yet what a carry was and that question arose quickly after just a few examples that my father and I scribbled on a piece of paper. I was curious about that and I asked my father to explain to me how it worked.

My father was always reluctant to teach me ahead of what I was supposed to be learning at school, mainly to avoid conflicts with the way the subjects were explained by the teachers. But sometimes, especially with mathematics, I was really insistent and he gave in. Curious me, soon I was interested in the opposite of adding 2 numbers. So you can guess that again my father helped me with that and, of course, this time he covered the equivalent of the carries for subtraction, the borrows.

An unfortunate consequence of this is that for a while I didn't pay much attention to maths lessons at school, something that annoyed my teacher until she figured out that I was just waiting for something new to happen.

While I was enjoying these sweet memories about the carries and the borrows, I remembered another time of my life when I learnt how to add or subtract 2 numbers: my first year at university. I think every student of Computer Science or Engineering learns how computers perform these operations and they all know that both operations are performed as an addition of 2 binary numbers. The trick happens in the binary representation of negative numbers.

All of the sudden I had the following thought: does the trick work for decimal numbers? If so, how is it that we learn to subtract numbers, being that slightly more difficult than the addition, when that's all we need to learn?

Yes, yesterday it took me a while to fall asleep, but more importantly, the trick works for any radix, including decimal numbers, and it has a name: the method of the complements.

The method of complements

Let's talk about the method. Let's say we have $x$ and $y$ positive numbers and $x \ge y$. Let's call $n$ the number of digits of $x$ in base 10 (i.e. as a decimal number). Now if we want to get $x - y$, we can rewrite the expression in the following way after just adding and subtracting $10^{n}$:

$$x - y = x - y + 10^{n} - 10^{n} = x + \left(10^n - y\right) - 10^{n}$$

In the middle of that expression we can see the number $10^n - y$. This is called the radix complement. Imagine that we know that number, then $x - y$ is just the addition of $x$ and that number minus $10^n$, but this last subtraction is just removing the carry after adding the most significant digits. So the question is how we can get $10^n - y$.

Well, that's really easy if we think about $10^n - 1$. That number happens to be just a bunch of 9s (i.e. 9999... $n$ times). And one good thing about it is that subtracting any positive number to it is easy and it doesn't require any "borrowing". So you can do $(10^n - 1) - y$ and add 1 to it and you get the desired radix complement!

This is the theory about why this method works, let's see it in action with an example. Let's compute $7900176622 - 5123234329$. First we need the radix complement of $5123234329$:

- 5123234329
  4876765670 + 1 -> 4876765671

And then we add that result to $7900176622$:

   ·   ···
+  4876765671

And after dropping the last carry, we get $2776942293$, indeed the result of $7900176622 - 5123234329$.

Just to make clear that the subtraction for obtaining the radix complement is straightforward, you can consider it as a map of the original digits to their "complementaries". In that sense the digit 0 will be mapped to 9, 1 to 8, and so on following the next table:


Usually I try to finish these articles with a conclusion, but this time I don't really have one. I personally think this method is cool and probably faster to use than the traditional algorithm. Should this be learnt at schools instead? Maybe? Or why not teaching both?

The purpose of teaching any of the methods is just to make an introduction to arithmetic and help the kids develop their mathematical thinking skills. Once they get the concept of addition and subtraction (and other operations), they can move on and start using a calculator (because, nowadays, claiming that this is necessary for the events in which they won't have access to a calculator is just a blatant lie). So considering that, teaching this method, in addition to the traditional one, could be seen as another "game" with numbers so kids get used to play with them.

About the author

Marco Antonio Garrido

Freelance Software Engineer

I'm a Full-Stack Software Engineer with more than 5 years of experience in the industry. After working 4 years as a SDE at Amazon, I decided to start a new chapter in my career and become a freelancer.

LinkedIn | GitHub