# 3 Modular arithmetic

## 3.3 Operations in modular arithmetic

The Division Algorithm tells us that all the possible remainders on division by an integer *n* lie in the set

We denote this set by _{n}. For each integer *n* ≥ 2 we have a set _{n}, and it is on these sets that we perform *modular arithmetic*. The modular addition operations +_{n} and modular multiplication operations ×_{n} are defined as follows.

### Definitions

For any integer *n* ≥ 2,

For *a* and *b* in _{n}, the operations +_{n} and ×_{n} are defined by:

*a*+_{n}*b*is the remainder of*a*+*b*on division by*n*;*a*×_{n}*b*is the remainder of*a*×*b*on division by*n*.

The integer *n* is called the **modulus** for this arithmetic.

*Note: **a* +_{n} *b* is read as *a* plus *b* (mod *n*), and may also be written *a* + *b* (mod *n*). Similarly, *a* ×_{n} *b* is read as *a* times *b* (mod *n*) and may also be written as *a* × *b* (mod *n*).

For example, _{7} = { 0,1,2,3,4,5,6} and we have

You have certainly met some modular arithmetic before, as the operations +_{12} and +_{24} are used in measuring time on 12-hour and 24-hour clocks, respectively.

### Exercise 41

Evaluate the following.

- (a) 3 +
_{5}7, 4 +_{17}5, 8 +_{16}12. - (b) 3 ×
_{5}7, 4 ×_{17}5, 8 ×_{16}12.

### Solution

- (a) 3 +
_{5}7 = 0, 4 +_{17}5 = 9, 8 +_{16}12 = 4. - (b) 3 ×
_{5}7 = 1, 4 ×_{17}5 = 3, 8 ×_{16}12 = 0.

In Sections 1 and 2 we listed some properties satisfied by the real and complex numbers. We now investigate whether the sets _{n} satisfy similar properties.

We also investigate what equations we can solve in _{n}; for example, can we solve the equations

These may look much simpler than the equations that we were trying to solve in , but they pose interesting questions. We shall see that the answers may depend on the modulus that we are using.

Before we discuss these questions further, we look at addition and multiplication tables, which provide a convenient way of
studying addition and multiplication in _{n}.

We consider addition first. Here are the addition tables for _{4} and _{7}.

In order to evaluate 4 +_{7} 2, say, we look in the row labelled 4 and the column labelled 2 in the second table to obtain the answer 6.

### Exercise 42

- (a) Use the tables above to solve the following equations.
- (i)
*x*+_{4}3 = 2 - (ii)
*x*+_{7}5 = 2 - (iii)
*x*+_{4}2 = 0 - (iv)
*x*+_{7}5 = 0

- (i)
- (b) What patterns do you notice in the tables?

### Solution

- (a)
- (i) 3 +
_{4}3 = 2, so*x*= 3. - (ii) 4 +
_{7}5 = 2, so*x*= 4. - (iii) 2 +
_{4}2 = 0, so*x*= 2. - (iv) 2 +
_{7}5 = 0, so*x*= 2.

- (i) 3 +
- (b) You may have noticed that:
- each element appears exactly once in each row and exactly once in each column;
- there is a pattern of diagonal stripes running down from right to left.

### Exercise 43

- (a) Construct the addition table for
_{6}. - (b) Solve the equations
*x*+_{6}1 = 5 and*x*+_{6}5 = 1.

### Solution

- (a)
- (b)
*x*+_{6}1 = 5 has solution*x*= 4. *x*+_{6}5 = 1 has solution*x*= 2.

For every integer *n* ≥ 2, the additive properties of _{n} are the same as the additive properties of , as follows.

Property A1 follows from the Division Algorithm and the definition of _{n}. The other properties can be deduced from the corresponding properties for integers.

### Exercise 44

By using the corresponding property for integers, prove property A5.

### Solution

By definition, *a* +_{n} *b* and *b* +_{n} *a* are the remainders of *a* + *b* and *b* + *a*, respectively, on division by *n*. But *a* + *b* = *b* + *a*, so *a* +_{n} *b* = *b*+_{n} *a*.

If *a*, *b* _{n} and *a* +_{n} *b* = 0, then we say that *b* is the **additive inverse** of *a* in _{n}. For example, 4 and 5 belong to _{9} and 4 +_{9} 5 = 0, so 5 is the additive inverse of 4 in _{9}. Property A3 states that every element of _{n} has an additive inverse in _{n}.

Additive inverses are sometimes written in the form −_{n}*a*; that is, if *a* +_{n} *b* = 0, then we write *b* = −_{n}*a*. For example, 5 = −_{9}4.

### Exercise 45

- (a) Use the addition table for
_{7}(which appear above Exercise 42) to complete the following table of additive inverses in_{7}. - (b) Complete the following table of additive inverses in
_{n}, explaining why your answers are correct.

### Solution

- (a)
- (b)
- The additive inverse of 0 is always 0, since 0 +
_{n}0 = 0. For any integer*r*> 0 in_{n},*n*−*r*_{n}and*r*+ (*n*−*r*) =*n*, so*r*+_{n}(*n*−*r*) = 0.

The existence of additive inverses means that, as well as doing addition modulo *n*, we can also do subtraction. We define *a* −_{n} *b* or, equivalently, *a* − *b* (mod *n*), to be the remainder of *a* − *b* on division by *n*.

(With this definition, *a* −_{n} *b* is equal to *a* +_{n} (−_{n}*b*).)

For example, to find 2 −_{8} 7, we have

Since 3 _{8}, it follows that