Computers use checksums to ensure that data was not corrupted in transmission. Now your brain can use a checksum for your mental math, with a few easy techniques.
It's important to have some way to check your mental math that doesn't take as long as solving the problem did originally, and ideally is much shorter. It's easy to check your math for the four basic operations of arithmetic (addition, subtraction, multiplication, and division) by calculating digit sums for the numbers involved. A digit sum is a special kind of checksum or data integrity check. Checksums are used all over the world of computing, from credit cards to ISBNs on books, to downloads you make with your web browser. Now your brain can use them, too.
Finding the digit sum of a number is easy. Just add all the digits of the number together. If the result is greater than 9, add the digits together again. Continue to do so until you have a one-digit result. If the result is 9, reduce it to 0. The result is the digit sum of the original number.1
For example, the digit sum of 381 is 3:
3 + 8 + 1 = 12 1 + 2 = 3
Similarly, the digit sum of 495 is 0:
4 + 9 + 5 = 18 1 + 8 = 9 (same as 0)
A number's digit sum is actually that number modulo 9—in other words, the remainder when that number is divided by 9. See "Calculate Any Weekday" [Hack #43] for a refresher on modulo arithmetic.
This technique is also known as casting out nines. Casting out nines and a similar technique known as casting out elevens (discussed in the following section) are all you need to check your arithmetic calculations rapidly and to a high degree of accuracy.
This section shows how to calculate checksums for the four basic operations: addition, subtraction, multiplication, and division. Only integers are used in the examples, but the techniques will work just as well for real numbers as long as they have the same number of decimal places. For example, if you are multiplying 13.52 by 14.6, think of the latter number as 14.60.
To check your answer after addition:
Find the digit sums for the numbers you are adding.
Add all the digit sums together.
Find the digit sum of the new number, and the digit sum of the answer number.
Compare these two digit sums. If the digit sums match, the answer should be correct.
Here is an example of checking addition successfully:
95 9 + 5 = 14; 1 + 4 = 5 + 42 4 + 2 = 6 + 22 2 + 2 = 4 ... 5 + 6 + 4 = 15; 1 + 5 = 6 159 1 + 5 + 9 = 15; 1 + 5 = 6 : OK
Here is another example of checking addition:
49 4 + 9 = 13; 1 + 3 = 4 + 37 3 + 7 = 10; 1 + 0 = 1 ... 4 + 1 = 5 76 7 + 6 = 13; 1 + 3 = 4 : WRONG (the answer should be 86)
The fact that the digit sum of the numbers being added does not match the digit sum of the result tells you that the result is incorrect.
Tip
Digit sums are even easier to calculate if you treat the 9s as 0s right away. Thus, instead of 4 + 9 = 13 in the example, just compute 4 + 0 = 4 and obtain your digit sum in one step.
To check your answer during multiplication:
Find the digit sums for the numbers you are multiplying.
Multiply them.
Find the digit sum of the new number, and the digit sum of the answer number.
Compare these two digit sums. If the digit sums match, the answer should be correct.
Here is an example of a correct multiplication:
33 3 + 3 = 6 x 27 2 + 7 = 9 = 0 ... 6 x 0 = 0 891 8 + 9 + 1 = 18; 1 + 8 = 9 = 0 : OK
Here is another example of checking multiplication:
76 7 + 6 = 13; 1 + 3 = 4 x 14 1 + 4 = 5 ... 4 x 5 = 20; 2 + 0 = 2 1164 1 + 1 + 6 + 4 = 12; 1 + 2 = 3 : WRONG (the answer should be 1064)
The fact that the digit sum of the product of the digit sums of the numbers being multiplied does not match the digit sum of the result tells you that the result is incorrect.
Subtraction is the inverse of addition. Checking a subtraction problem works the same way as checking an addition problem: simply turn the subtraction problem into an addition problem first, as in the following example:
58 26 2 + 6 = 8 - 26 → + 32 3 + 2 = 5 ... 8 + 5 = 13; 1 + 3 = 4 32 58 5 + 8 = 13; 1 + 3 = 4 : OK
Just as subtraction is the inverse of addition, so is division the inverse of multiplication. Thus, checking a division problem works the same way as checking a multiplication problem: first turn the division problem into a multiplication problem, as in the following example:
1081 / 23 = 46 23 2 + 3 = 5 x 46 4 + 6 = 10; 1 + 0 = 1 ... 5 x 1 = 5 1081 1 + 0 + 8 + 1 = 10; 1 + 0 = 1 : WRONG (the answer should be 47, not 46)
The fact that the digit sum of the product of the digit sums of the numbers being multiplied does not match the digit sum of the result tells you that the division result of 46 is incorrect.
Sometimes casting out nines will not find an error. For example, sometimes errors in two digits will cancel out, as in the following example:
272 2 + 7 + 2 = 11; 1 + 1 = 2 + 365 3 + 6 + 5 = 14; 1 + 4 = 5 ... 2 + 5 = 7 547 5 + 4 + 7 = 16; 1 + 6 = 7 : OK?
The correct answer is not 547, but 637 (6 + 3 + 7 = 16; 1 + 6 = 7).
Casting out nines will also not find errors of place (when the decimal point is misplaced, or the result is otherwise off by a power of 10). Estimating the order of magnitude [Hack #41] (roughly, finding the number of digits to the left of the decimal point) will help catch some errors of place, but casting out elevens is even better.
Casting out elevens (that is, calculating numbers modulo 11) is slightly more accurate than casting out nines. It will also catch errors that casting out nines will not, including errors of place, so it is useful as a cross-check.
To cast out elevens from an integer, simply add all of the digits in the odd places of the number (for example, the ones and hundreds digits, which are in places 1 and 3, counting from the right), then subtract all of the digits in the even places (for example, the tens and thousands digits, in places 2 and 4).
For example, casting out elevens from 5,924 gives the result 4 + 9 – 2 – 5 = 6.
If your result is greater than 11, cast out elevens from that number, and continue doing so until you have a number that's less than 11. If the result is less than 0, add 11 to it until you have a number that is at least 0 and less than 11. To cast out elevens from a sum, total the result of casting out elevens for each number you're adding, and then cast out elevens from that.
The following example is a cross-check of the sum from the previous section:
272 2 + 2 - 7 = -3; -3 + 11 = 8 + 365 5 + 3 - 6 = 2 ... 8 + 2 = 10 547 7 + 5 - 4 = 8 : WRONG (the answer should be 637)
A rigorous mathematical proof that casting out nines by summing the digits of a number will give you that number's remainder when divided by 9 is beyond the scope of this book, but it's fairly intuitive.
First, consider that 0
mod
9
is 0
,
1
mod
9
is
1
, 2
mod
9
is 2
, 3
mod
9
is 3
,
and so on. 9
mod
9
is
0
, 10
mod
9
is 1
, 11
mod
9
is 2
,
and the cycle continues.
Next, consider that 20
mod
9
is 2
,
30
mod
9
is
3
, and so on; check and see. You
will also find that 200
mod
9
is
2
, 2,000
mod
9
is 2
, 20,000
mod
9
is 2
, and so on. In fact, any integer
multiplied by any power of 10 and then calculated modulo 9 has the same result as the original integer
modulo 9.
Since (a
+
b
+
c)
mod
9
is the same as (a
mod
9)
+
(b
mod
9)
+
(c
mod
9)
,
and since (for example) the number 523 can be written as 500
+
20
+
3
,
simply adding the individual digits of 523 (5
+
2
+
3)
will
serve the same purpose as calculating the sum of 500 mod 9, 20 mod 9,
and 3 mod 9, to wit, finding 523 modulo
9.2
Figuring out why casting out elevens works is left as an exercise for the mathematically minded mind-performance hacker.
Mental checksums are most useful when you combine them with other math hacks [Hack #75]. Since checksums using both 9 and 11 are easy to find, checking your work won't add much time to your mental calculations unless you made a mistake—in which case, better late than wrong.
Get Mind Performance Hacks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.