# Lecture 31: GCD, Definition of modular numbers

• Review proof of correctness of GCD (this has been added to the lecture 30 notes

• Define $$\mathbb{Z}_n$$, the set of "modular numbers"

• Review exercises:
• Prove that $$\equiv_m$$ is an equivalence relation
• Prove $$[a] = [b]$$ if and only if $$rem(a,m) = rem(b,m)$$.

## Modular numbers

The next several lectures will explore the arithmetic of remainders. Usually these results are presented as a set of equations about congruence mod $$m$$ or about remainders when divided by $$m$$ (MCS does both).

Instead, we will raise the level of abstraction a bit. We will define a new kind of object (the modular number), and redefine operations like $$+$$ and $$\cdot$$ for these objects. This is not a new process: you already have several kinds of things you know how to add and multiply: natural numbers, integer, rationals, reals, complex numbers, vectors, matrices, and random variables, to name a few. Each of these kinds of objects has a different algorithm for doing arithmetic on them; but because they all have a common interface, you have built up lots of intuition about how to manipulate them.

Definition: $$a$$ is congruent to $$b$$ (mod $$m$$), (written $$a \equiv b~(mod~m)$$ or $$a \equiv_m b$$). if $$m|b-a$$.

Note: It is easy to misinterpret this as $$a \equiv (b~mod~m)$$; this interpretation leads to confusion. Think of the "mod $$m$$" as a big note on the side of your equations or proofs, not as part of your equations.

Note: $$\equiv_m$$ is an equivalence relation (proof left as a review exercise).

Definition: The set $$\mathbb{Z}_n$$ of modular numbers is defined by $$\mathbb{Z}_n = \mathbb{Z}/\equiv_m$$.

Recall that $$\mathbb{Z}/\equiv_m$$ is the set of equivalence classes of integers by the relation $$\equiv_m$$: $$\mathbb{Z}_{m} = \{\dots, [-2]_m, [-1]_m, _m, _m, _m, \dots\}$$, where $$[a]_m = \{b \mid b \equiv_m a\}$$. When the $$m$$ is clear from context, we will simply write $$[a]$$.

Note that $$[-1] = [m-1]$$ (because $$m|m-1 -(-1)$$ so $$-1 \equiv_m m-1$$), and $$[-2] = [m-2]$$, and $$[m] = $$ and $$[m+1] = $$, etc. In general, $$[a] = [rem(a,m)]$$, so $$\mathbb{Z}_m$$ can always be written as

$\mathbb{Z}_m = \{_m, _m, _m, \dots, [m-1]_m\}$

Key facts: the following are equivalent:

1. $$[a] = [b]$$ (mod $$m$$)
2. $$a \equiv b$$ (mod $$m$$)
3. $$m | b-a$$
4. $$rem(a,m) = rem(b,m)$$

This follows from the definitions, with the exception of the equivalence of (3) and (4). To see that (3) implies (4), assume $$m | b - a$$. If we write $$a = q_am + r_a$$ and $$b = q_bm + r_b$$, we see that $$km = (q_b - q_a)m + r_b - r_a$$. This means that $$r_b - r_a$$ is a multiple of $$m$$. Since $$r_b$$ and $$r_a$$ are both less than $$m$$, we have $$-m \lt r_b - r_a \lt m$$; since $$0$$ is the only multiple of $$m$$ satisfying this property, $$r_b - r_a = 0$$.