Lecture 6 - Modular Arithmetic

# Summary

Today in class we introduced the notion of modular congruence and saw that it can be used to give an equivalence relation to the integers. Not only does this provide us with a way to split the integers up into distinct subgroups (a so-called "partition"), but it also behaves well with respect to addition and multiplication. We started to explore how we can use these arithmetic properties of congruences to prove results about integers.

# Congruence

The key idea in this chapter centers around the following

Definition: Two integers a and b are said to be congruence (or equivalent) module an integer m — written $a \equiv b \mod{m}$ — if $m \mid a-b$.

One of the benefits of modular congruence is that it behaves an awful lot like the regular "equals" you're used to playing with. In fact, modular congruence is an equivalence relation, which means it has the following properties

1. Reflexive: for any integer a and any modulus m, we have $a \equiv a \mod{m}$.
2. Symmetric: for any integers a and b and any modulus m, if $a \equiv b \mod{m}$ then $b \equiv a \mod{m}$.
3. Transitive: for any integers a,b and c, and any modulus m, if $a \equiv b \mod{m}$ and $b \equiv c \mod{m}$, then $a \equiv c \mod{m}$.

Proof: To prove the reflexive property, note that $a \equiv a \mod{m}$ just means that we want to verify $m \mid a - a=0$. We saw a while back, though, that any integer m divides 0, so this statement is valid.

To prove symmetry, we need to show that $a \equiv b \mod{m}$ implies $b \equiv a \mod{m}$. If $a \equiv b \mod{m}$, though, the definition of modular congruence tells us that $m \mid a-b$, so that $mk = a-b$. But then we have $m(-k) = -(a-b) = b-a$, and so $m \mid b-a$. By the definition of modular congruence, we therefore have $b \equiv a \mod{m}$.

Finally, for transitivity we are supposed to assume that $a \equiv b \mod{m}$ and $b \equiv c \mod{m}$, and somehow conclude that $a \equiv c \mod{m}$. To prove this result, we note that the first two congruence conditions tells us that $m \mid a-b$ and $m \mid b-c$. Our result on divisibility of integral linear combinations, then, tells us that $m \mid (a-b)+(b-c) = a-c$. Hence the definition of modular congruence tells us that $a \equiv c \mod{m}$.$\square$

The benefit of showing that modular congruence is an equivalence relation is that this tells us that congruence class partition the integers into distinct sets. For instance, when the modulus is 3, we know that every integer fits into one of the three collections

(1)
\begin{align} \begin{split} & \{x \in \mathbb{Z} : x \equiv 0 \mod{3}\} \\ & \{x \in \mathbb{Z} : x \equiv 1 \mod{3}\} \\ & \{x \in \mathbb{Z} : x \equiv 2 \mod{3}\} \end{split} \end{align}

We know this has to be true because the division algorithm tells us that any number has remainder either 0,1 or 2 after trying to divide by 3.

#### Example: Negative Numbers and Congruences

Suppose you want to know what the integer -2 is congruent to mod 3. The definition tells us that $-2 \equiv k \mod{3}$ is the same as saying $-2-k$ is divisible by 3. Note that choosing $k = 0,2$ makes $-2-k$ something which isn't divisible by 3, whereas choosing $k = 1$ leaves us with $-2-1 = -3$. Since $3 \mid -2-1$, we have $-2 \equiv 1 \mod{3}$.$\square$

Notice, however, that the way we've written these subsets isn't unique. For instance, since $1 \equiv 7 \mod{3}$, the transitive property of congruence shows that

(2)
\begin{align} \{x \in \mathbb{Z} : x \equiv 1 \mod{3}\} = \{x \in \mathbb{Z} : x \equiv 7 \mod{3}\}. \end{align}

With this observation in mind, one might be curious to know all the different ways of writing representatives for the congruence classes of a given modulus. This leads to the following

Definition: A collection of integers is called a complete residue system for modulus m if every integer is congruent modulo m to exactly one element from the collection.

#### Example: Complete residue systems for $m=3$

The division algorithm tells us that $\{0,1,2\}$ is a complete residue system for $m=3$. But notice that so too are $\{3,4,5\}$ and $\{7,5,30\}$. On the other hand, note that $\{0,1,2,3\}$ is not a complete residue system, since it has a repeated congruence class; specifically, $0 \equiv 3 \mod{3}$. On the other hand, the set $\{1,2\}$ fails to be a complete residue system because not every integer is congruence to either 1 or 2. In particular, $6 \not\equiv 1 \mod{3}$ and $6 \not\equiv 2 \mod{3}$. $\square$

The fact that $\{0,1,2\}$ is a complete residue system for $m=3$ comes from the following more general result

Lemma: For any integer m, the set $\{0,1,\cdots,m-1\}$ is a complete residue system modulo m.

This complete residue system is so important that it gets its own name: it is called the least non-negative residue system for m.

# Congruence and Arithmetic

The reason that congruences are so important in number theory is that the notion of congruence plays well with addition and multiplication. By this we mean

For integers $a,b,c,d,m$ with $a \equiv c \mod{m}$ and $b \equiv d \mod{m}$, we have

• $a+b \equiv c+d \mod{m}$ and
• $ab \equiv cd \mod{m}$

This result is important because it tells us that when we're doing arithmetic computations module m, we can do our computations by choosing any integers which sit in the given congruence classes module m. We'll see an example of this after we prove the theorem.

Proof: We're given that $a \equiv c \mod{m}$ and $b \equiv d \mod{m}$, and these statements translate into the divisibility statements $m \mid a-c$ and $m \mid b-d$. By our result on divisibility of integral linear combinations, we have that

(3)
\begin{align} m \mid (a-c) + (b-d) = (a+b)-(c+d). \end{align}

This divisibility statement, in turn, tells us that $a+b \equiv c+d \mod{m}$. To verify the second statement, we'll choose a different integral linear combination:

(4)
\begin{align} m \mid b(a-c) + c(b-d) = ab - bc+bc -cd = ab-cd, \end{align}

and by the definition of congruence we have $ab \equiv cd \mod{m}$.$\square$

#### Example: Arithmetic Modulo 6

The following tables tells us how addition and multiplication work modulo six

+ 0 1 2 3 4 5
0 0 1 2 3 4 5
1 1 2 3 4 5 0
2 2 3 4 5 0 1
3 3 4 5 0 1 2
4 4 5 0 1 2 3
5 5 0 1 2 3 4
x 0 1 2 3 4 5
0 0 0 0 0 0 0
1 0 1 2 3 4 5
2 0 2 4 0 2 4
3 0 3 0 3 0 3
4 0 4 2 0 4 2
5 0 5 4 3 2 1

An important thing to notice about this table is that it gives us examples where $ca \equiv cb \mod {m}$ does not imply $a \equiv b \mod{m}$. For example, notice that we can find a and b so that $a \not\equiv b \mod{6}$, and yet $3a \equiv 3b \mod{6}$. Canceling coefficients is something you're probably really used to, so you need to be wary when doing modular arithmetic that you aren't carelessly "dividing" by constants. The following lemma tells us exactly what relationship such a,b have to each other.

Lemma: $ca \equiv cb \mod{m}$ is equivalent to $a \equiv b \mod{\frac{m}{(c,m)}}$.

#### Example: "Canceling" coefficients in modular equations

Notice that in the example above, anytime we have a and b such that $3a \equiv 3b \mod{6}$, we also have $a \equiv b \mod{2}$. For instance, we could choose $a = 1$ and $b = 3$, in which case we'd have $3(1) \equiv 3(3) \mod{6}$. Likewise if we have a and //b/ such that $4a \equiv 4b \mod{6}$, then it follows that $a \equiv b \mod{3}$; for example, if we choose $a = 2$ and $b = 5$, then we get $4(2) \equiv 4(5) \mod{6}$.$\square$

Though we didn't get to prove this lemma in class, I'll give a sketch of part of the proof below.

Proof: We'll only prove the $(\Rightarrow)$ direction, leaving the other direction for the enthusiastic student. Now if we're told that $ca \equiv cb \mod{m}$, then this translates to the divisibility statement $m \mid ca-cb$. Hence there is some integer e so that $me = ca-cb$. If we write $d = (c,m)$, then we can divide each of m and c by d and get an equation of integers

(5)
\begin{align} d~\frac{m}{d}~e = d~\frac{c}{d}(~a-b). \end{align}

Now since this is an equation of integers, we can cancel out the d on both sides, and we're left with the div

(6)
\begin{align} \frac{m}{d}~e = \frac{c}{d}~(a-b) \end{align}

from which we have $\frac{m}{d} \mid \frac{c}{d}(a-b)$. We know that $(\frac{m}{d},\frac{c}{d}) = 1$ by an old result, and we also know that this relative primality result together with our divisibility condition implies that

(7)
\begin{align} \frac{m}{d} \mid a-b \end{align}

from which we find $a \equiv b \mod{\frac{m}{d}}$ as desired.$\square$

#### Example: A divisibility criterion for 11

People have been talking about divisibility criteria for integers on the forum, so I thought we might talk about how one goes about proving such a result. We'll prove the following

Divisibility Criterion: Suppose that a number n has digits $a_ka_{k-1}\cdotsa_2a_1a_0$, meaning that $n = \sum_{i=0}^k a_i 10^i$. Then n is divisible by 11 if and only if the alternating sum of its digits — $\sum_{i=0}^k (-1)^i a_i$ — is divisible by 11.

Proof: To see that this is true, we'll take the equation $n = \sum_{i=0}^k a_i 10^i$ and consider what it gives us modulo 11. On the left hand side we just get $n \mod{11}$, but on the right hand side we get
$\sum_{i=0}^k a_i 10^i \mod{11}$. Notice that $10 \equiv -1 \mod{11}$. Now since "modding by 11" plays nicely with addition and multiplication, this means that $10^i \equiv (-1)^i \mod{11}$. Hence this means that our equation $n = \sum_{i=0}^i a_i10^i$ becomes

(8)
\begin{align} n \equiv \sum_{i=0}^k a_i 10^i \equiv \sum_{i=0}^k a_i (-1)^i \mod{11}. \end{align}

In particular, $n \equiv 0 \mod{11}$ if and only if $\sum_{i=0}^k (-1)^i a_i \equiv 0 \mod{11}$, meaning that n is divisible by 11 if and only if the alternating sum of its digits is divisible by 11.
$\square$

#### Example: Computing large powers (modularly)

One of the benefits of modular arithmetic is that it provides a context in which really large powers of a given integer can be computed. As an example, we'll compute $10^{80} \mod{13}$. (This is more than the number of atoms in the universe!). To do this, we start by computing successive square powers of 10. To make this as efficient as possible, I'll often use the trick of substituting a given integer with another small integer which is equivalent modulo 13 (for instance, using the facts that $10 \equiv -3 \mod{13}$ and that $9 \equiv -4 \mod{13}$. Witness:

(9)
\begin{align} \begin{split} &10^2 \equiv (-3)^{2} \equiv 9 \mod{13}\\ &10^4 \equiv 9^2 \equiv (-4)^2 \equiv 16 \equiv 3 \mod{13}\\ &10^8 \equiv 3^2 \equiv 9 \mod{13}\\ &10^{16} \equiv 9^2 \equiv 3 \mod{13}\\ &10^{32} \equiv 3^2 \equiv 9 \mod{13}\\ &10^{64} \equiv 9^2 \equiv 3 \mod{13}. \end{split} \end{align}

Now when it comes to computing $10^{80}$, we just notice that

(10)
\begin{align} 10^{80} = 10^{64 + 16} = 10^{64}10^{16} \equiv 3 \cdot 3 \equiv 9 \mod{13}. \end{align}

$\square$