Lecture 12: Modular arithmetic

Congruence mod m

Modular numbers (equivalence classes mod m)

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:

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.


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.