Homepage › Solution manuals › Ivan Niven › An Introduction to the Theory of Numbers › Exercise 4.1.33 (There is a carry in the $i$th place iff $\{m/d^{i+1}\}+ \{n/d^{i+1}\} \geq 1$)
Exercise 4.1.33 (There is a carry in the $i$th place iff $\{m/d^{i+1}\}+ \{n/d^{i+1}\} \geq 1$)
Let the positive integers and be written in base , say and . Show that when and are added, that there is a carry in the th place (the place corresponding to ) if and only if .
Answers
Proof. We write the integers in base :
where (we can take the same , greater than the lengths of the representations of and in base ).
Reducing modulo , where , we obtain
so there is some integer such that
This equality defines . We put also . We want to compute , knowing . By equation (1) for two successive values of ,
By subtracting these two equalities, we obtain
thus
Since ,
so
and .
To summarize, we compute by the following induction rules, for :
where and denote the quotient and remainder in the Euclidean division of by (as in computer programs). This is the usual algorithm to compute a sum in base . This shows that is the carry corresponding to the sum of coefficients of , reported to the coefficient of , and this carry satisfies equation (1).
We note that . Moreover, . If , then , so , thus . This induction shows that or for all .
Now we can answer to the question.
We note that
Here
where (see Problem 31). Therefore
Therefore
and replacing by ,
Similarly
By equation (1),
By equations (4) and (5), this implies that
Conversely, if , then by the same equations (4) and (5),
Assume, for the sake of contradiction, that . Then equation (1) gives
so
in contradiction with (5). Therefore .
In conclusion
□
Note: to give an example of the algorithm given by (2) and (3), consider the sum . The following Python program compute this sum using (2) and (3):
d = 10 a = [7, 3, 2, 9, 5, 0] b = [5, 1, 7, 3, 7, 0] k = len(a) c = [0] * len(a) r = 0 for i in range(k): u = a[i] + b[i] + r c[i] = u % d r = u // d print(c) [2, 5, 9, 2, 3, 1]