Lecture 5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

2.

3 / MODULAR ARITHMETIC 53

2.3 MODULAR ARITHMETIC

The Modulus
If a is an integer and n is a positive integer, we define a mod n to be the remainder
when a is divided by n. The integer n is called the modulus. Thus, for any integer a,
we can rewrite Equation (2.1) as follows:

a = qn + r 0 … r 6 n; q = : a/n ;
a = : a/n ; * n + (a mod n)

11 mod 7 = 4; -11 mod 7 = 3

Two integers a and b are said to be congruent modulo n, if (a mod n) =


(b mod n). This is written as a K b (mod n).2

73 K 4 (mod 23); 21 K -9 (mod 10)

Note that if a K 0 (mod n), then n  a.

Properties of Congruences
Congruences have the following properties:
1. a K b (mod n) if n  (a - b).
2. a K b (mod n) implies b K a (mod n).
3. a K b (mod n) and b K c (mod n) imply a K c (mod n).
To demonstrate the first point, if n  (a - b), then (a - b) = kn for some k.
So we can write a = b + kn. Therefore, (a mod n) = (remainder when b +
kn is divided by n) = (remainder when b is divided by n) = (b mod n).

23 K 8 (mod 5) because 23 - 8 = 15 = 5 * 3
-11 K 5 (mod 8) because -11 - 5 = -16 = 8 * ( -2)
81 K 0 (mod 27) because 81 - 0 = 81 = 27 * 3

The remaining points are as easily proved.

2
We have just used the operator mod in two different ways: first as a binary operator that produces a re-
mainder, as in the expression a mod b; second as a congruence relation that shows the equivalence of two
integers, as in the expression a K b (mod n). See Appendix 2A for a discussion.
54 CHAPTER 2 / INTRODUCTION TO NUMBER THEORY

Modular Arithmetic Operations


Note that, by definition (Figure 2.1), the (mod n) operator maps all integers into
the set of integers {0, 1, c , (n - 1)}. This suggests the question: Can we perform
arithmetic operations within the confines of this set? It turns out that we can; this
technique is known as modular arithmetic.
Modular arithmetic exhibits the following properties:
1. [(a mod n) + (b mod n)] mod n = (a + b) mod n
2. [(a mod n) - (b mod n)] mod n = (a - b) mod n
3. [(a mod n) * (b mod n)] mod n = (a * b) mod n
We demonstrate the first property. Define (a mod n) = ra and (b mod n) = rb.
Then we can write a = ra + jn for some integer j and b = rb + kn for some integer k.
Then
(a + b) mod n = (ra + jn + rb + kn) mod n
= (ra + rb + (k + j)n) mod n
= (ra + rb) mod n
= [(a mod n) + (b mod n)] mod n

The remaining properties are proven as easily. Here are examples of the three
properties:

11 mod 8 = 3; 15 mod 8 = 7
[(11 mod 8) + (15 mod 8)] mod 8 = 10 mod 8 = 2
(11 + 15) mod 8 = 26 mod 8 = 2
[(11 mod 8) - (15 mod 8)] mod 8 = -4 mod 8 = 4
(11 - 15) mod 8 = -4 mod 8 = 4
[(11 mod 8) * (15 mod 8)] mod 8 = 21 mod 8 = 5
(11 * 15) mod 8 = 165 mod 8 = 5

Exponentiation is performed by repeated multiplication, as in ordinary


arithmetic.

To find 117 mod 13, we can proceed as follows:


112 = 121 K 4 (mod 13)
114 = (112)2 K 42 K 3 (mod 13)
117 = 11 * 112 * 114
117 K 11 * 4 * 3 K 132 K 2 (mod 13)

Thus, the rules for ordinary arithmetic involving addition, subtraction, and
multiplication carry over into modular arithmetic.
2.3 / MODULAR ARITHMETIC 55
Table 2.2 provides an illustration of modular addition and multiplication
modulo 8. Looking at addition, the results are straightforward, and there is a reg-
ular pattern to the matrix. Both matrices are symmetric about the main diagonal
in conformance to the commutative property of addition and multiplication. As in
ordinary addition, there is an additive inverse, or negative, to each integer in modu-
lar arithmetic. In this case, the negative of an integer x is the integer y such that
(x + y) mod 8 = 0. To find the additive inverse of an integer in the left-hand col-
umn, scan across the corresponding row of the matrix to find the value 0; the integer
at the top of that column is the additive inverse; thus, (2 + 6) mod 8 = 0. Similarly,
the entries in the multiplication table are straightforward. In modular arithmetic mod
8, the multiplicative inverse of x is the integer y such that (x * y) mod 8 = 1 mod 8.
Now, to find the multiplicative inverse of an integer from the multiplication table,
scan across the matrix in the row for that integer to find the value 1; the integer at
the top of that column is the multiplicative inverse; thus, (3 * 3) mod 8 = 1. Note
that not all integers mod 8 have a multiplicative inverse; more about that later.

Properties of Modular Arithmetic


Define the set Z n as the set of nonnegative integers less than n:

Z n = {0, 1, c , (n - 1)}

Table 2.2 Arithmetic Modulo 8


+ 0 1 2 3 4 5 6 7
0 0 1 2 3 4 5 6 7
1 1 2 3 4 5 6 7 0
2 2 3 4 5 6 7 0 1
3 3 4 5 6 7 0 1 2
4 4 5 6 7 0 1 2 3
5 5 6 7 0 1 2 3 4
6 6 7 0 1 2 3 4 5
7 7 0 1 2 3 4 5 6
(a) Addition modulo 8

* 0 1 2 3 4 5 6 7 w -w w -1
0 0 0 0 0 0 0 0 0 0 0 —
1 0 1 2 3 4 5 6 7 1 7 1
2 0 2 4 6 0 2 4 6 2 6 —
3 0 3 6 1 4 7 2 5 3 5 3
4 0 4 0 4 0 4 0 4 4 4 —
5 0 5 2 7 4 1 6 3 5 3 5
6 0 6 4 2 0 6 4 2 6 2 —
7 0 7 6 5 4 3 2 1 7 1 7
(b) Multiplication modulo 8 (c) Additive and multiplicative
inverse modulo 8
56 CHAPTER 2 / INTRODUCTION TO NUMBER THEORY

This is referred to as the set of residues, or residue classes (mod n). To be more pre-
cise, each integer in Z n represents a residue class. We can label the residue classes
(mod n) as [0], [1], [2], c , [n - 1], where

[r] = {a: a is an integer, a K r (mod n)}

The residue classes (mod 4) are


[0] = { c , -16, -12, -8, -4, 0, 4, 8, 12, 16, c }
[1] = { c , -15, -11, -7, -3, 1, 5, 9, 13, 17, c }
[2] = { c , -14, -10, -6, -2, 2, 6, 10, 14, 18, c }
[3] = { c , -13, -9, -5, -1, 3, 7, 11, 15, 19, c }

Of all the integers in a residue class, the smallest nonnegative integer is the
one used to represent the residue class. Finding the smallest nonnegative integer to
which k is congruent modulo n is called reducing k modulo n.
If we perform modular arithmetic within Z n, the properties shown in Table 2.3
hold for integers in Z n. We show in the next section that this implies that Z n is a
commutative ring with a multiplicative identity element.
There is one peculiarity of modular arithmetic that sets it apart from ordinary
arithmetic. First, observe that (as in ordinary arithmetic) we can write the following:

if (a + b) K (a + c) (mod n) then b K c (mod n) (2.4)

(5 + 23) K (5 + 7)(mod 8); 23 K 7(mod 8)

Equation (2.4) is consistent with the existence of an additive inverse. Adding


the additive inverse of a to both sides of Equation (2.4), we have

(( -a) + a + b) K (( -a) + a + c)(mod n)


b K c (mod n)

Table 2.3 Properties of Modular Arithmetic for Integers in Z n

Property Expression
(w + x) mod n = (x + w) mod n
Commutative Laws
(w * x) mod n = (x * w) mod n
[(w + x) + y] mod n = [w + (x + y)] mod n
Associative Laws
[(w * x) * y] mod n = [w * (x * y)] mod n
Distributive Law [w * (x + y)] mod n = [(w * x) + (w * y)] mod n
(0 + w) mod n = w mod n
Identities
(1 * w) mod n = w mod n
Additive Inverse ( - w) For each w ∈ Z n, there exists a z such that w + z K 0 mod n
2.3 / MODULAR ARITHMETIC 57
However, the following statement is true only with the attached condition:

if (a * b) K (a * c)(mod n) then b K c(mod n) if a is relatively prime to n (2.5)

Recall that two integers are relatively prime if their only common positive integer
factor is 1. Similar to the case of Equation (2.4), we can say that Equation (2.5) is
consistent with the existence of a multiplicative inverse. Applying the multiplicative
inverse of a to both sides of Equation (2.5), we have

((a-1)ab) K ((a -1)ac)(mod n)


b K c(mod n)

To see this, consider an example in which the condition of Equation (2.5) does not
hold. The integers 6 and 8 are not relatively prime, since they have the common
factor 2. We have the following:
6 * 3 = 18 K 2(mod 8)
6 * 7 = 42 K 2(mod 8)
Yet 3 [ 7 (mod 8).

The reason for this strange result is that for any general modulus n, a multi-
plier a that is applied in turn to the integers 0 through (n - 1) will fail to produce a
complete set of residues if a and n have any factors in common.

With a = 6 and n = 8,

Z8 0 1 2 3 4 5 6 7
Multiply by 6 0 6 12 18 24 30 36 42
Residues 0 6 4 2 0 6 4 2

Because we do not have a complete set of residues when multiplying by


6, more than one integer in Z 8 maps into the same residue. Specifically,
6 * 0 mod 8 = 6 * 4 mod 8; 6 * 1 mod 8 = 6 * 5 mod 8; and so on. Because
this is a many-to-one mapping, there is not a unique inverse to the multiply
operation.
However, if we take a = 5 and n = 8, whose only common factor is 1,

Z8 0 1 2 3 4 5 6 7
Multiply by 5 0 5 10 15 20 25 30 35
Residues 0 5 2 7 4 1 6 3

The line of residues contains all the integers in Z 8, in a different order.

You might also like