User:CaritasUbi/Casting out nines

Before the advent of pocket calculators, arithmetic was generally done by hand, and was frequently subject to errors. One technique to quickly verify that a calculation was accurate was called casting out nines.

This meant taking the sum of the digits of a number, subtracting 9 whenever the sum was greater than 9, or, equivalently, taking the sum of the digits and then taking the sum of the digits of that sum, and so on, until sum was less than 9. It was asserted that for any integers x, y, and z, if $$x + y = z$$, the sum of the digits of x plus the sum of the digits of y would always be congruent mod 9 with the sum of the digits of z.

Similarly for multiplication, if $$x \cdot y = z$$, the sum of the digits of x times the sum of the digits of y would always be congruent mod 9 with the sum of the digits of z.

So, for example, 241 x 382 = 92,062. The sum of digits of 241 = 2+4+1 = 7, and the sum of digits of 382 = 3+8+2 = 13, sum of digits of 13 = 4. So we can expect the product of 241 and 382 to have the sum of digits = 7 x 4 = 28 = 2 + 8 = 10 = 1 + 0 = 1. Examining our initial calculation, sum of digits of 92,062 = 9+ 2 + 0 + 6 + 2 = 19, 1 + 9 = 10, 1+0= 1. The match doesn't guarantee that our calculation is correct, but will definitely tell us if it is wrong.

This article develops a rigorous proof of the correctness of that technique.

Definition 1
Let $$s:\mathbb{N} \to \mathbb{N}$$ to be a function that maps an integer n to the sum of its digits. That is, for the digits of n (from right to left), $$ s(n) = d_0 + d_1 + d_2 + \dotsb = \sum_{k=0}^\infty d_k $$

where each of the digits $$d_k$$ is an integer $$ 0 \le d_k \le 9 $$.

Lemma 1
Lemma 1: Every positive integer is greater than or equal to the sum of its digits.

Proof: Let n be a positive integer with non-negative digits (from right to left) of $$d_0, d_1, \dotsc, $$ so that $$n = d_0 + 10d_1 + 100d_2 + \dotsc = \sum_{k=0}^\infty 10^k \cdot d_k$$. By induction over the number of digits, we see clearly that for single-digit numbers, $$d_0 = d_0$$. If we can show that the proposition is true for m digit numbers, it must also be true for m + 1 digit numbers, because since $$\sum_{k=0}^m 10^k \cdot d_k >= \sum_{k=0}^m d_k$$, and since every digit $$d_k$$is non-negative, $$10^kd_k \ge d_k$$ so $$ \sum_{k=0}^m 10^k \cdot d_k + (10^{m+1} \cdot d_{m+1}) >= \sum_{k=0}^m d_k + (d_{m+1}) $$

Hence, the proposition holds for numbers of any number of digits. $$\Box$$.

Lemma 2
Lemma 2: Every positive integer is congruent mod 9 to the sum of its digits.

Proof: Let n be a positive integer with non-negative digits (from right to left) $$ d_0, d_1, \dotsc. $$ so that $$

In this case, $$

By the definition of congruence, $$a \equiv b$$ mod p if and only if there is some integer m such that $$ a - b = p \cdot m $$. So $$a \equiv b$$ mod 9 if and only if there is some integer m such that $$ a - b = 9 \cdot m $$.

Now consider

$$ n - s(n) = \sum_{k=0}^\infty 10^k d_k - \sum_{k=0}^\infty d_k $$

$$ = (d_0 - d_0) + (10 d_1 - d_1) + (100 d_2 - d_2) + (1000 d_3 - d_3) + \dotsb $$

$$ = 0 d_0 + 9 d_1 + 99 d_2 + 999 d_3 + \dotsb $$

$$

This means that $$n - s(n)$$ is an even multiple of 9, hence

$$n \equiv s(n)$$ mod 9 $$\Box$$.

Lemma 3
Lemma 3: Repeated applications of $$s(n)$$ will eventually yield a single non-negative number less than 9.

Proof: Consider the series {$$ n, s(n), s(s(n)), \dotsc, s^k(n), \dotsc $$}. Evaluating each adjacent pair of terms, we see it cannot be the case that each pair must have the strictly greater than relation, because there are only finitely many non-negative integers less than n. Eventually, by Lemma 2, there must be a pair $$ s^k(n) = s^{k+1}(n) $$. This can only be true when $$s^k(n) \le 9$$, since $$s^{k+1}(n) = s^k(n) + d_{k+1}$$ and $$ 10^k > k $$ for all $$k \ge 0.$$ $$\Box$$.

So for conciseness, we will say in this article that $$s(n)$$ means repeated evaluations of the sum of digits function until $$0 \le s(n) < 9$$.

Theorem 1
Theorem 1: For all $$m, n \in \mathbb{N}$$: $$s(m) + s(n) \equiv s(m + n)$$ mod 9 and $$s(m) \cdot s(n) \equiv s(m \cdot n)$$ mod 9.

Proof: Let $$m, n \in \mathbb{N}$$ be given, where m has non-negative digits $$c_0, c_1, c_2, \dotsb$$ as defined above, and n has non-negative digits $$d_0, d_1, d_2, \dotsb$$.

Then $$ and $$ hence, for addition, $$

Then by Lemmas 2 and 3, $$ $$ $$ $$ which proves the first part of the theorem.

Similarly, for multiplication,

$$

$$

By Lemma 3, we can freely interchange x and s(x) and maintain equivalence mod 9, so

$$

$$

$$

$$

hence, $$

which proves part 2.$$\Box$$