Modular Arithmetic
1Around the clock
is not always . Think of the 24‐hour clock. When it’s 23:00, then two hours later, it will be 1:00, not 25:00. This is because the clock only counts hours from to , and after that, it starts over from .
This is exactly the idea of modular arithmetic. The term sounds fancy, but it really works just like a clock, except that there is no reason for a mathematician to restrict attention to 24‐hour clocks; instead, modular arithmetic talks about ‐hour clocks, where can be any positive integer. For example, a 5‐hour clock counts the hours as follows:
0, 1, 2, 3, 4, 0, 1, 2, 3, 4,
When a 24‐hour clock is at hour 0, we know that 24 (or 48, or 72) hours later, it’s again at 0. And 36 hours later, it’s at 12, and 25 hours later, it’s at 1.
When an ‐hour clock is at hour , where is it hours later? For this, we introduce the notation
As we have previously discussed, , and also and . Furthermore, and .
In general, the values tell us exactly how an ‐hour clock counts. To illustrate this, we come back to the 5‐hour clock:
What is ? Do not compute the number by yourself! Instead, go through the list of possible answers and try to argue for each why it cannot be the correct answer. Based on Sherlock Holmes, whatever remains must be the truth.
2Computing modulo
How can we compute , without simulating the passing of hours on an ‐hour clock? For example, what is ? This is asking where a 24‐hour clock is after hours. Well, as hours are exactly days, we know that hours are full days (equal to hours), plus extra hours (the difference between and ). Since the clock is at after each full day, it is therefore at after the hours. So,
Here is the general recipe for computing :
Compute how many full “‐hour days” are passing within hours, by taking and rounding down. The mathematical symbol for this is .
Multiply the result with to get the hours passing in these full days. The result is , and after this many hours, the clock is again at .
We still have extra hours to go, and this is also where the clock is after the total of hours.
So the formula is
While we’re at it: there is no reason to exclude negative values of . We can also ask where the clock was some hours ago. For example, , because when the clock is now at , then hours ago, it was at . The formula still works. If we compute and round down, we get . Multiplying this with gives . And finally, the extra hours still to go are .
We can also think of it like this: hours ago, full day and extra hours have passed.
Calculate .
Just to get some more practice...
Calculate the following numbers.
3Division with remainder
You may have encountered modular arithmetic back in school, in the context of division with remainder. For example, 16 divided by 5 is 3, with a remainder of 1. By this we mean that you can “fit" the number 5 three times into 16, but doing this, you only reach 15, so you have a remainder of 1. In the clock metaphor, a 5‐hour‐clock makes 3 full turns within 16 hours, after which 15 hours have passed. So after 16 hours, the clock is at 1. In formulas, . The result of the division with remainder also has a name, we call it , and it has the value 3. We also know how to compute for arbitrary integers and : take and round down. So the following holds:
Suppose you know that and . What is the number ?
Suppose you know that . What can you conclude about the integer ?
Suppose you know that . What can you conclude about the integer ?