Skip to main content
Logo image

Section 3.3 Modulo Arithmetic

Subsection 3.3.1 Terminology

All integers are said to be equivalent mod \(n\) to their remainder after dividing by \(n\text{.}\) For example \(9 \equiv 4 \pmod 5 \) because \(9/5\) has remainder 4. Similarly \(13 \equiv 1 \pmod 2 \) because \(13/2\) has remainder 1.
ExampleΒ 3.3.1 shows a function evaluated \(\pmod 5.\)

Example 3.3.1. Function mod 5.

\(n\) 0 1 2 3 4
\(n^2\) 0 1 4 4 1
The formal definition of modulo arithmetic requires two definitions.

Definition 3.3.2. Divides.

\(a\) divides \(b\text{,}\) written \(a|b,\) if and only if there exists some \(k \in \Z\) such that \(ak=b.\)

Definition 3.3.3. Modulo.

\(a\) is equivalent to \(b\) modulo \(n\text{,}\) written \(a \equiv b \pmod n,\) if and only if \(n|b-a. \)
Note you may be familiar with the operation % in programming. That is an operation like + or \(\times\text{.}\) Here we are using a different number system like integers or reals. Avoid conflating the two. For example % has an order of operation. The question of order does not make sense with arithmetic mod \(n\) as will be demonstrated below.

Subsection 3.3.2 Before or After?

To address the issue of order of operation under modulo arithmetic consider the function \(f(n)=n^2+3n+5 \pmod 7.\)

Example 3.3.4. Calculate function modulo n, each step.

\begin{align*} f(4) = & 4^2+3(4)+5 \pmod 7.\\ & \text{First we calculate each term above} \pmod 7.\\ 4^2 = & 16 \equiv 2 \pmod 7.\\ 3(4) = & 12 \equiv 5 \pmod 7.\\ 5 = & 5 \equiv 5 \pmod 7.\\ & \text{Next we add the terms} \pmod 7.\\ 2+5+5 = & 12 \equiv 5 \pmod 7.\\ & \text{Thus}\\ f(4) = & 5 \pmod 7. \end{align*}

Example 3.3.5. Calculate function modulo n, last step.

\begin{align*} f(4) & = & 4^2+3(4)+5 \pmod 7\\ & = & 33 \pmod 7\\ & \equiv & 5 \pmod 7. \end{align*}

Subsection 3.3.3 Discovering Properties

First, we identify a pattern to all the numbers equivalent to the same thing.

Checkpoint 3.3.7.

List four (4) numbers that are equivalent to \(3 \pmod 5\text{.}\) Base this on two numbers being equivalent modulo 5 if their remainders are the same after dividing by 5.
Next, get used to doing the arithmetic and think about what should be done with negative numbers.

Checkpoint 3.3.8.

Complete the table calculating \(\pmod 7\text{.}\) Remainders are never negative.
\(n\) 0 1 2 3 4 5 6
\(n^2-4\)

Checkpoint 3.3.9.

Find all solutions to the following equation modulo 5. \(n^2-4=0 \pmod 7. \)
The next examples illustrate an important difference between different moduli.

Checkpoint 3.3.11.

Complete the table below calculating modulo 8.
\(n\) 0 1 2 3 4 5 6 7
\(4n\)

Subsection 3.3.4 Visualization

Table 3.3.15. Graph Paper for function mod 5
4
3
2
1
0
0 1 2 3 4

Subsection 3.3.5 Proofs

The following should increase our understanding of modulo arithmetic and our skills writing proofs.
It makes sense that if \(2|6\) then \(-2|6\) as well. To prove the general statement \(a|b\) implies \(-a|b\text{,}\) we will start on the left of this implication (\(a|b\)). Now, the only thing we have is the definition of divides. This tells us \(ak=b\) for some integer \(k\text{.}\) We want \(-aj=b\) for some integer \(j\text{.}\) This suggests we try \(j=-k\text{.}\)

Proof.

By definition of divides \(a|b\) implies there exists \(k \in \Z\) such that \(ak=b\text{.}\) Consider
\begin{align*} (-a)(-k) & = \\ ak & = b \end{align*}
Thus \(-a|b\) by definition of divides.
The following theorem proves that our handling of negative numbers above is legitimate. To prove an implication we start on the left, so we know \(a \equiv b \pmod n\text{.}\) We know only the definition of modulo equivalence. \(n|(b-a)\text{.}\) Using the divides definition we know there exists an integer \(k\) such that \(nk=b-a\text{.}\) Next we consider where we want to end: \(n|(b-[a-n])\) which requires an integer \(k_2\) such that \(nk_2=(b-[a-n])\text{.}\) That expression can be simplified. \(nk_2=(b-a+n)\text{.}\) We know that n divides n, so we can modify the first expression to find \(k_2\text{.}\)

Proof.

By definition of modulo equivalence \(a \equiv b \pmod n\) implies that \(n|(b-a)\text{.}\) Thus, by definition of divides, there exists \(k \in \Z\) such that \(nk=b-a\text{.}\) Consider
\begin{align*} b-(a-n) & =\\ b-a+n & = nk+n\\ & = n(k+1). \end{align*}
Thus \(n|(b-(a-n))\) by definition of divides. This implies \(a-n \equiv b \pmod n\text{.}\)