8.2 Modular Arithmetic: A Case Study
Let us consider a context in which different integers can be seen to be the “same".
Consider an analogue clock.
At 1 o’clock, a digital clock may read either 1:00 or 13:00 while from an analogue perspective, these are the same time. Alternatively, if you are scheduling something in 24 hours time, then that is equivalent to scheduling something at the same time the next day.
We can formalise and generalise these ideas. Recall that any integer can be written as where is some integer divisor and is the remainder: an integer such that .
For example . Hence is the remainder when is divided by . The quotient, , is .
At first glance this appears silly: why not just write ? The reason is that by writing all terms remain integers. That is, we continue to work exclusively within the integer number system.
Note that the remainder behaves like our clock: it increases as expected until we get to an upper bound, in this case , when it then ’resets’ and starts counting up again from 0. If we only want to consider two integers as being “different” if they have different remainders (e.g. if we only wanted to keep track of the time in the day and didn’t care which day it was), we could use the language of congruence.
Definition 8.2 (Congruence).
For and , we say is congruent to modulo , and write , or sometimes , if there is some such that .
Example 8.3.
-
(a)
as is divisible by 10.
-
(b)
As we saw with the clock, as .
-
(c)
as .
Note that when we work with congruent integers, we always clearly state what value we are working with. This is very important as changing the value completely changes which integers are equivalent. In particular, every integer is congruent to .
There are a number of ways we can view congruent integers.
Theorem 8.4.
Let and
The following are equivalent:
-
(a)
;
-
(b)
divides ;
-
(c)
and have same remainder when divided by ;
-
(d)
for some .
Proof.
(a) (d) and (d) (a) both follow directly from Definition 8.2.
For (d) (b), if for some , then is a divisor of by definition.
For (b) (c), we know there exist integers and such that and where and are remainders. Then . If divides , then so as required.
Finally, (d) as if and have the same remainder when divided by , then and for some integers , so, substituting for , we can write . As and are both integers, we have written where is an integer.
We have therefore shown that all of these statements are equivalent to one another.
Corollary 8.5.
Every integer is congruent to exactly one of the numbers .
Proof.
Let . Then we can uniquely write where is the remainder with .
Then so, by Definition 8.2, which concludes the proof.
Exercise 8.6.
Working , write in three different ways.
Solution (please try for yourself before looking)
Since , we have
Corollary 8.7.
Let be a divisor of , , and , then .
Proof.
By assumption, we have for some . Moreover, as , then Definition 8.2 means that for some . Together, this means . As , by Definition 8.2, we therefore also have .
8.2.1 Modular Arithmetic Operations
Now we have objects which are equivalent, we would like to be able to combine these. Just like we can add time together without breaking our clock, we can have addition and multiplication modulo .
Proposition 8.8 (Addition and Multiplication).
If and such that and , then
-
(a)
-
(b)
-
(c)
-
(d)
for every .
Proof.
By assumption, divides and divides .
-
(a)
Then divides , so .
-
(b)
The Linear Combination Lemma implies that divides
and so .
- (c)
-
(d)
This can be proven by induction. Let be the statement that .
For the base case of , this follows from the assumption .
For the induction step, suppose for some . Then by part (c) of this theorem with and and using the fact that , we have
Thus,
This proves that and thus holds for all by induction.
Altogether, we can now define the following set.
Definition 8.9.
For , addition and multiplication on the set
is defined as follows. For every :
-
•
is the unique such that .
-
•
is the unique such that .
From this, we can then form addition and multiplication tables.
| 0 | 1 | 2 | 3 | 4 | |
| 0 | 0 | 1 | 2 | 3 | 4 |
| 1 | 1 | 2 | 3 | 4 | 0 |
| 2 | 2 | 3 | 4 | 0 | 1 |
| 3 | 3 | 4 | 0 | 1 | 2 |
| 4 | 4 | 0 | 1 | 2 | 3 |
| 0 | 1 | 2 | 3 | 4 | |
| 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 2 | 3 | 4 |
| 2 | 0 | 2 | 4 | 1 | 3 |
| 3 | 0 | 3 | 1 | 4 | 2 |
| 4 | 0 | 4 | 3 | 2 | 1 |
We can then define subtraction.
Proposition 8.10.
Every has an additive inverse i.e. there exists such that .
Proof.
Let and such that . Then, by Proposition 8.8 (a), we have . Moreover, by Proposition 8.8 (b), . Finally, from Corollary 8.5, we know there exists a such that .
However, we have to be a bit more careful with the definition of division.
Proposition 8.11 (Division).
Suppose is coprime to . Then if such that , we have i.e. we can “divide” both sides of the equation by .
Proof.
Suppose and are coprime and . Then by definition 8.2, divides . Since and are coprime, must divides , and so by definition.
This doesn’t work without the coprime condition. Indeed, consider multiplication modulo 6. If we take , then we see that but .
We can also see this from our multiplication tables. With our usual definition of division, , where is called the multiplicative inverse of . This is the unique real number such that . But the only real number we can’t divide by is 0 i.e. 0 has no multiplicative inverse, because there is no real number that we can multiply by 0 to give us 1.
We can apply a similar thinking to working modulo . We can define to be the multiplicative inverse of modulo if . But notice in your multiplication table modulo 6, say, that some rows (rows 0,2,3,4) don’t contain a 1 in them at all! This means there is no multiplicative inverse in for 0, 2, 3 and 4. These are precisely the elements in that are not coprime with 6.
| 0 | 1 | 2 | 3 | 4 | 5 | |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 2 | 3 | 4 | 5 |
| 2 | 0 | 2 | 4 | 0 | 2 | 4 |
| 3 | 0 | 3 | 0 | 3 | 0 | 3 |
| 4 | 0 | 4 | 2 | 0 | 4 | 2 |
| 5 | 0 | 5 | 4 | 3 | 2 | 1 |
Corollary 8.12.
If is prime, then every has both an additive and multiplicative inverse.
If a set has both well-defined addition and multiplication, and their inverses, then we call the set a field. See more in Introduction to Mathematical Analysis next term.
8.2.2 Applications of Modular Arithmetic
Congruences do let us solve some nice problems.
Exercise 8.13.
Show that the sequence given by , contains no squares.
Solution (please try for yourself before looking)
We want to show that there is no such that for any . To simplify this, we consider this equation modulo 3 so, recalling , we want to solve
We can use an exhaustive proof here:
| Case 1: | |||
| Case 2: | |||
| Case 3: |
Any other integer is equivalent to one of these cases modulo 3 meaning there is no integer such that .
Exercise 8.14.
Let with digits . Show that is divisible by 3 if and only if the sum of the digits is divisible by 3.
Solution (please try for yourself before looking)
Let with digits , then we can write
Note that so any power of 10 is also equal to 1 mod 3. Therefore, considering this equation modulo 3 we get,
Therefore is divisible by 3 (i.e. ), if and only if the sum of the digits is divisible by 3.
Exercise 8.15.
Prove that the last digit of is 7.
Solution (please try for yourself before looking)
To find the last digit of a number, we consider it modulo 10.
We therefore first consider powers of modulo 10:
So in general, the last digit of depends on the value of . We therefore want to find . Similarly to above, we have
Hence so and the last digit of is therefore .