# Lecture 12: Modular arithmetic

• definitions of congruence
• equivalence classes
• defining operations (+, *, etc.)

## Congruence mod m

• Notation: a|b is read "a divides b". By definition, a|b if there is some c such that ca = b.

• Definition: given an integer m, two integers a and b are congruent modulo m if m|(a − b). We write a ≡ b (mod m). I will also sometimes say equivalent modulo m.

• Notation note: we are using that "mod" symbol in two different ways. The first was defined in a previous lecture: a mod b denotes the remainder when we divide a by b. The "mod m" in a ≡ b (mod m) is a note on the side of the equation indicating what we mean when we say ""

• Fact: These two uses of "mod" are quite related: a ≡ b (mod m) if and only if a mod m = b mod m.

## Modular numbers (equivalence classes mod m)

• Definition: if a, m ∈ Z then [a]m (called the equivalence class of a mod m) is the set of all integers that are congruent to a, mod m.

• Often times m will be clear from context, in which case I will omit it and just write [a].

• Example: If we are working mod 5, then [2]=[7]=[12]=[−3]=[−8]. All of these have a remainder of 2 when divided by 5.

• Note: a ≡ b (mod m) if and only if [a]=[b] (proof straightforward)

• Zm is the set of all equivalence classes of integers mod m.

• Example: Z5 = {[0],[1],[2],[3],[4]}. [5] is in Z5 but I didn't list it because [5] is the same as [0].

• In general, Zm = {[0],[1],…,[m − 1]}. The other equivalence classes are already contained in this list. For example, [m]=[0], [m + 1]=[1], and so on.

• If x ∈ Zm and n ∈ x then n is called a representative of x.

## Operations on equivalence classes

We can make equivalence classes behave like numbers by suitably defining operations on them. We just have to make sure that the operations we define make sense.

We can define addition as follows: if x, y ∈ Zm, then to compute x + y:

• choose representatives a of x and b of y
• x + y is then [a + b].

In other words, [a]+[b] is defined to be [a + b]. Example (still working mod 5): [2]+[6]=[8].

We have to check that this definition makes sense. There is freedom to choose different representatives; we must ensure that we get the same result if we make different choices. In other words, we must ensure that addition is well defined.

Example (still mod 5): Instead of writing [2]+[6], we might write [7]+[11] and get [18] instead of [8]. But since 8 ≡ 18, [18] and [8] are the same equivalence class.

Theorem: (working mod m) If a ≡ a and b ≡ b then a + b ≡ a′+b. In other words, if [a]=[a′] and [b]=[b′] then [a + b]=[a′+b′].

Proof: Since a ≡ a, by definition m|a − a. Expanding the definition of "divides", this means that a − a′=cm for some c. Similarly, b − b′=dm for some d. Adding these together, we have (a − a′) + (b − b′) = cm + dm. Rearranging yields (a + b)−(a′+b′) = (c + d)m. In other words, m|(a + b)−(a′+b′), or a + b ≡ a′+b. This means that [a + b]=[a′+b′], as desired.

### Notation

The definition of addition had a lot of words. We can use function definition notation to make it more concise. Addition is a function that takes a pair of equivalence classes and gives an equivalence class:

+ : Zm × Zm → Zm

It is given by the rule [a]+[b]=[a + b]. Using function notation:

+ : ([a],[b]) → [a + b]

Super important: Whenever defining functions on equivalence classes this way, you must check that the function is well defined (as we did for addition). Always check that choosing different representatives gives the same answer.

### Multiplication, other operations

We can define multiplication:

* : Zm × Zm → Zm is given by * : ([a],[b]) → [ab].

Example (still mod 5): [3][4]=[12].

Proof that * is well defined is left for the future.

I encourage you to think about other operations and whether they are well defined.