6.2 Modular Arithmetic
6.2 Modular Arithmetic
72
last edited April 30, 2016
73
last edited April 30, 2016
a = 5
b = 8.
a + b = 5 + 8 = 13.
a = c
b = d,
a+b = c + d,
a b = c d,
a⇥b = c ⇥ d.
Pause to think about this statement, and make sure it aligns with what you
know. Of course these are only several ways of combining these equations, and
every reader can think of several others. All of the above are “rules” of classical
arithmetic. What we would like to do now is consider whether similar rules
apply to modular arithmetic as well.
Suppose we have the following two congruence relations:
a ⌘ b (mod m)
c ⌘ d (mod m).
That is, do the rules that govern how we can combine equations in classical
arithmetic also govern the ways in which we combine statements in modular
arithmetic? In what follows we prove that indeed many of the rules do carry
over – the rules of modular arithmetic will be familiar to us.
74
last edited April 30, 2016
Addition
The first rule we consider is that associated with addition. Suppose we have
two congruence relations: a ⌘ b (mod m) and c ⌘ d (mod m). In other words,
a and b are congruent and c and d are congruent, both mod m. We can add the
left sides of these congruent relations, add the right sides, and the results will
again be congruent. In symbols,
Theorem 15.
If a ⌘ b (mod m) and
c ⌘ d (mod m), then
a+c ⌘ b+d (mod m).
Proving this result involves nothing more than applying the definition of
congruence and some basic algebraic manipulation.
Proof. By the definition of congruence (Definition 25) we know that a and b
di↵er by some multiple of m, i.e.,
b a = km (64)
for some k 2 Z. Likewise we know that c and d also di↵er by some multiple of
m, i.e.,
d c = jm (65)
for some j 2 Z. Note that we use j instead of k since the multiple of m by which
c and d di↵er might be di↵erent from the multiple by which a and b di↵er. Next
we add these two equations together:
(b a) + (d c) = km + jm. (66)
We can rewrite this equation as
(b + d) (a + c) = (j + k)m. (67)
By the definition of congruence modulo m, this is the same as saying that a + c
is congruent to b+d modulo m, since a+c and b+d di↵er by an integer multiple
(j + k) of m. In symbols, we have:
a+c⌘b+d (mod m), (68)
as desired.
A similar proof can be used to show that if a ⌘ b (mod m) and c ⌘ d
(mod m), then a c ⌘ b d (mod m).
These two results allow us to treat all numbers that are congruent modulo
m as identical when adding and subtracting numbers. If we know that a ⌘ 3
(mod 7) and b ⌘ 4 (mod 7), then we can know that a + b ⌘ 7 ⌘ 0 (mod 7).
This is true whether a is 10 or 703, and whether b is 7004, 10000, or 7,000,004.
What a and b actually are does not matter if we only want to determine whether
a + b is congruent to 0 or not.
75
last edited April 30, 2016
Multiplication
After understanding how addition and subtraction work in modular arithmetic,
we turn our attention to understanding multiplication. In classical arithmetic,
if a = 2 and b = 5, then of course a ⇥ b = 2 ⇥ 5 = 10. Does a similar relationship
also hold in modular arithmetic? In particular, if we know that a ⌘ 2 (mod m)
and b ⌘ 5 (mod m), do we know that a ⇥ b ⌘ 2 ⇥ 5 (mod m)?
The following theorem answers this question affirmatively.
Theorem 16.
If a ⌘ b (mod m) and
c ⌘ d (mod m), then
a⇥c ⌘ b⇥d (mod m).
b a = jm
d c = km
for some j, k 2 Z. Note that we use distinct multiples j and k for the two
equations, since a and b might di↵er by one multiple of m, and c and d might
di↵er by another multiple of m.
To prove the desired result, we rearrange the equations:
b = jm + a
d = km + c
bd = (jm + a)(km + c)
= jkm2 + jmc + kma + ac
= (jkm + jc + ka)m + ac.
bd ac = (jkm + jc + ka)m.
76
last edited April 30, 2016
Theorems 15 and 16 show us that we can treat all numbers that are congruent
modulo m as the same, in addition and in multiplication operations. Division
is much more complicated, and will not be discussed.
Remainders
We take a moment to draw out a connection to division with remainders, an idea
we considered briefly in Section 4.1. In particular, back in elementary school we
learned about a way of dividing integers by other integers that entirely avoids
decimals and fractions. In particular, suppose we divide 7 by 4. In third, fourth,
or fifth grade, we learned that we can write this as 1, remainder 3. That is, 4 can
1 time “into” 7, leaving over 3. As we got older, we learned that we could also
write the answer as 1.75 or 13⁄4, but we still occasionally deal with situations
in which discussing fractions would be silly. If we have 52 playing cards and 5
players, a dealer could give each player 10 cards and then be left with 2 cards.
It makes little sense to say that the dealer should give each player 10.2, or 10
and a fifth, cards.
What is the connection of modular arithmetic to division with remainders?
Suppose that we divide some integer a by another integer m. Notice that the
“remainder” is always congruent to a modulo m. For example, suppose we
divide 1031 by 19. We obtain 54, remainder 5. This tells us that 5 is congruent
to 1031 modulo 19. Likewise, since the remainder of 7381/57 is 28, we know
that 28 ⌘ 7381 (mod 57).
Why is the remainder after division always congruent to the number we are
dividing? One way to think about this is by considering how we can find a
remainder without actually doing any division. Suppose we want to know the
remainder of 11 after dividing by 3. We can subtract 3 over and over until we
obtain a number that is smaller than 3: 11, 8, 5, and eventually 2. Each time
we subtract 3, we are realizing that 3 can “go into” 11 one more time; whatever
is left at the end is the remainder. At the same time, we got from the original
number to the remainder by jumps of 3, so of course the di↵erence between 11
and 2 is divisible by 3, making 11 and 2 congruent. The same idea works for
dividing any number a with any other number m.
77
last edited April 30, 2016
Standard Representation
We have by now seen that in arithmetic modulo m, there is no di↵erence between
writing 1, 1 + m, 1 + 2m, and so forth, at least as far as addition, subtraction,
and multiplication are concerned. For this reason, writing 4+11 ⌘ 15 (mod 13)
is “just as correct” as writing 4 + 11 ⌘ 2 (mod 13), and “just as correct” as
writing 4 + 11 ⌘ 11 (mod 13). As far as arithmetic modulo 13 is concerned,
2, 15, and -11 are exactly the same number. However, in some applications it
is convenient to agree upon a standard way to represent numbers. What is a
good way to do this? Which of {. . . , a 2m, a m, a, a + m, a + 2m, . . .} should
we consider the standard representative?
You have likely encountered a similar problem back in your days learning
about trigonometric functions. A teacher may have asked you what is the inverse
sine of 1, i.e., sin 1 ( 1). You may have correctly answered 270 . Or you
may have correctly answered 90 . In fact, any number that can be written
270 + n360 , for any integer n 2 Z, would also be equally correct. But if
each student wrote a di↵erent number on an exam, it could take a long time to
determine whether or not every answer is correct. Is 1500 a correct solution?
Is 1530 ? For this reason, we might specify that we looking for a correct answer
between 0 and 360 , or else between 180 and 180 , since there is exactly one
correct answer in each of these ranges.
In the same way, when working in arithmetic modulo 41, the numbers
{. . . , 29, 12, 53, 94, 135, . . .} are all the same, yet we might hope to specify
one of them to be the standard representation of them. Indeed, in arithmetic
modulo m, we refer to the numbers {0, 1, 2, . . . , m 1} as the standard repre-
sentations of the integers. If numbers are always represented in this standard
form, determining whether or not two numbers are congruent is as easy as look-
ing at whether the numbers are equal. Notice also that this set of numbers is
also the set of possible remainders after dividing a number by m.
Example 1. Suppose we want to know the remainder of 17 ⇥ 18 when it is
divided by 19. We can do this in two di↵erent ways. First, we can multiply
the two numbers directly and obtain 306; some calculation will show that 306 is
congruent to 2 modulo 19. Alternatively, we know that 17 ⌘ 2 (mod 19) and
18 ⌘ 1 (mod 19). Multiplying both sides we see that 17⇥18 ⌘ ( 2)⇥( 1) ⌘ 2
(mod 19).
Example 2. Suppose we want to determine the standard form of 172 in mod
19 arithmetic. One way in which we can do this is by considering the square of
17, which is 289, divide that by 19 and then take the remainder. However, since
we know that 17 ⌘ 2 (mod 19), we can multiply this congruence equation
by itself to obtain 172 ⌘ 22 ⌘ 4 (mod 19). We can easily verify that the
remainder of 289, when divided by 17, is indeed 4.
Example 3. Suppose we want to determine the standard form of 18489391312
in mod 19 arithmetic. We should first notice that in mod 19 arithmetic, 18 is
congruent to 1, and so 18489391312 ⌘ ( 1)489391312 (mod 19). It is relatively
78
last edited April 30, 2016
easy to see that if n is odd then ( 1)n = 1, and if n is even then ( 1)n = 1.
Since 489391312 is even, 18489391312 ⌘ 1 (mod 19).
Dividing by 9
We can use the rules of modular addition and multiplication to prove a theorem
you may have once seen. Suppose we have a number, for example 2,383,623,
and want to know whether it is divisible by 9. Is there an easy way to figure this
out without doing “long division”? You may have learned the following trick:
add up the digits of the number (e..g., 2 + 3 + 8 + 3 + 6 + 2 + 3 = 27). If this
sum is divisible by 9, then so is the original number; if the sum is not divisible
by 9, then neither is the original number. Is this just a miraculous trick, or is
it something that we can prove should work?
The rules of modular addition and multiplication (Theorems 15 and 16
above) can help us prove this beautiful result. Let’s begin by proving a sim-
pler result about the remainders we get when we divide powers of 10 by 9. In
particular, the remainder is always 1.
Lemma 17. For any natural number n, we have 10n ⌘ 1 (mod 9).
Proof. Recall that if we have two congruences: a ⌘ b and c ⌘ d (mod m), then
we can combine them to form a new congruence relation: ac ⌘ bd (mod m).
Since 10 ⌘ 1 (mod 9), then we can combine the equation with itself to obtain
100 = 10 ⇥ 10 ⌘ 1 ⇥ 1 ⌘ 1 (mod 9). We can indeed combine this equation with
itself as many times as we want (e.g., n times), and therefore have 10n ⌘ 1n ⌘ 1
(mod 9) for any natural number n.
Next, let’s consider what happens when we divide numbers such as 300,
5000, and 2,000,000 by 9. What are the remainders? Theorem 16 can help us
see that the remainders are 3, 5, and 2 in these examples. To see why this is so,
notice that each of these numbers can be written as the product of an integer
and a power of 10: 300 = 3 · 102 , 5000 = 5 · 103 , and 2,000,000= 2 · 106 . This
leads us to the following theorem.
Lemma 18. For any natural numbers c and n, we have c · 10n ⌘ c (mod 9).
Proof. Recall that if we have two congruences: a ⌘ b and c ⌘ d (mod m), then
we can combine them to form a new congruence relation: ac ⌘ bd (mod m).
Since c ⌘ c and 10n ⌘ 1 (mod 9) for any n, then we can combine the equations
to obtain c · 10n ⌘ c · 1 ⌘ c (mod 9).
This now leads us to our central theorem:
Theorem 19. A number is divisible by 9 if and only if the sum of its digits
(written in base 10) is divisible by 9.
Proof. In base 10, every number can be written as a sum of ones, tens, hundreds,
thousands, and so forth. For example, 5776 = 5000+700+70+6. More generally,
we can write this as n = c0 + c1 101 + c2 102 + c3 103 + . . ., where the ci variables
79
last edited April 30, 2016
are the numbers of ones, tens, hundreds, thousands, and so forth. According to
Lemma 18, for each of the ci we have ci · 10n ⌘ ci (mod 9). Using Theorem 15,
we can combine the congruence relations
c0 ⌘ c0 (mod 9),
c1 ⌘ c1 101 (mod 9),
2
c2 ⌘ c2 10 (mod 9),
3
c3 ⌘ c2 10 (mod 9),
...
cn ⌘ c2 10n (mod 9),
to give us
80