Skip to main content

Section 1.2 Modular arithmetic

Subsection 1.2.1 Congruence

Definition 1.2.1. Divisibilty.

Given integers \(a,b\in \Z\) we say that \(a\) divides \(b\) (or that \(b\) is a multiple of \(a\)) if there is an integer \(q\in \Z\) satisfying \(b=qa\text{.}\) In this case, \(q\) is called the quotient of \(b\) by \(a\text{.}\)

Definition 1.2.2. Congruence modulo \(n\).

Let \(n\) be a positive integer. Integers \(a\) and \(b\) are congruent modulo \(n\), denoted \(a\equiv b\pmod n\text{,}\) if one of the two following equivalent conditions holds:
\begin{align} n \amp \mid a-b\tag{1.2.1}\\ b \amp =a+qn \text{ for some } q\in \Z\text{.}\tag{1.2.2} \end{align}
The congruence class (or residue class) of \(a\) modulo \(n\text{,}\) denoted \(\overline{a}\) (or \([a]_n\)) is the set of all integers congruent to \(a\) modulo \(n\text{:}\) i.e.,
\begin{align*} \overline{a}=[a]_n \amp = \{b\in \Z\mid a\equiv b \pmod n\}\\ \amp = \{a+qn\mid q\in \Z\}\text{.} \end{align*}
Elements of a congruence class \([a]_n\) are called representatives (or residues) of that class.
The set of all congruence classes modulo \(n\) is denoted \(\Z/n\Z\text{:}\) i.e.,
\begin{equation*} \Z/n\Z=\{[a]_n\mid a\in \Z\}\text{.} \end{equation*}
The integer \(n\) in all the settings above is called a modulus.

Example 1.2.3. Congruence modulo \(3\).

Consider the modulus \(n=3\text{.}\)
  1. Compute \([5]_3\) and \([-1]_3\text{.}\)
  2. Find a finite list of integers \(a_1,a_2,\dots, a_r\) such that
    \begin{equation*} \Z/3\Z=\{[a_1]_3, [a_2]_3,\dots, [a_r]_3\}\text{.} \end{equation*}
  3. Compute \(\abs{\Z/3\Z}\text{.}\)
Solution.
  1. We have
    \begin{equation*} [5]_3=[-1]_3=[2]_3=\{\dots, -3,-1,2,5,\dots \}\text{.} \end{equation*}
  2. It is not difficult to show that for any \(a\in \Z\) we have \([a]_3=[k]_3\) for some \(k\in \{0,1,2\}\text{.}\) (See theory below more generally.) Thus
    \begin{equation*} \Z/3\Z=\{[0]_3,[1]_3,[2]_3\}\text{.} \end{equation*}
  3. The sets
    \begin{align*} [0]_3 \amp = \{\dots, -3,0,3,6,\dots\}\\ [1]_3 \amp = \{\dots,-2,1,4,7,\dots\}\\ [2]_3 \amp =\{\dots, -1,2,5,8,\dots\} \end{align*}
    are clearly all distinct from one another. Thus \(\abs{\Z/3\Z}=3\text{.}\)

Remark 1.2.4. Congruence classes.

Fix an integer \(n\text{.}\) The notation \(\overline{a}\) is ambiguous since it does not indicate the modulus \(n\) in question. This is one reason for the alternative notation \([a]_n\text{.}\) Furthermore, the \([a]_n\) notation somehow does a better job of reminding us that a congruence class is not itself an integer, but rather a set of integers.
We will use both notations interchangeably. Typically, we will favor \(\overline{a}\) when performing modular arithmetic (see below), and \([a]_n\) when asserting something about sets.

Proof.

See text for (1). Statements (2)-(3) then follow from general properties about equivalence relations and their corresponding equivalence classes. Statement (4) follows from (2) and the following observation:
\begin{equation*} 0< \abs{a-b} < n \implies n\nmid a-b\text{.} \end{equation*}

Definition 1.2.6. Least residue modulo \(n\).

Fix a positive modulus \(n\text{.}\) Given an integer \(a\) the least residue of \(a\) modulo \(n\text{,}\) denoted \(a\bmod n\) is the unique \(r\in \{0,1,2,\dots, n-1\}\) satisfying \(a\equiv r\pmod n\text{.}\)

Warning 1.2.7. Congruence relation and least residues.

Do not confuse the two quite similar looking notations \(a\equiv b\pmod n\) and \(a\bmod n\text{.}\) The first asserts that a certain relation holds, namely that \(a\) is congruent to \(b\) modulo \(n\text{.}\) The second denotes the unique integer in \(\{0,1,\dots, n-1\}\) that is congruent to \(a\) modulo \(n\text{.}\)
Said differently, the notion of the least residue defines a function
\begin{align*} \underline{\phantom{aa}}\bmod n \colon \Z \amp\rightarrow \{0,1,\dots, n-1\} \\ a \amp \longmapsto a\bmod n\text{.} \end{align*}

Subsection 1.2.2 Ring structure of \(\Z/n\Z\)

Example 1.2.12. Modular arithmetic.

Fix the modulus \(n=8\text{.}\) Find a representative \(r\in \{0,1,\dots, 7\}\) for the congruence class
\begin{equation*} \overline{43}(\overline{23}\, \overline{11}+\overline{17}) \text{.} \end{equation*}
Solution.

Specimen 4. Additive group \(\Z/n\Z\).

Fix a positive integer \(n\text{.}\) The pair \((\Z/n\Z, +)\) is a group, where \(+\) is the addition operation defined in CorollaryΒ 1.2.11.
The group identity of \(\Z/n\Z\) is the congruence class \(\overline{0}=[0]_n\text{.}\)
Given \(\overline{a}\in \Z/n\Z\text{,}\) its group inverse is \(\overline{-a}\text{,}\) denoted \(-\overline{a}\text{.}\)

Definition 1.2.14. Multiplicative units in \(\Z/n\Z\).

Fix a modulus \(n\text{.}\) An element \(\overline{a}\in \Z/n\Z\) is a unit (or (multiplicatively) invertible) if there is an element \(\overline{b}\in \Z/n\Z\) satisfying
\begin{equation*} \overline{a}\overline{b}=\overline{b}\overline{a}=\overline{1}\text{.} \end{equation*}
The element \(\overline{b}\) in this case is called the multiplicative inverse of \(\overline{a}\text{,}\) denoted \(\overline{a}^{-1}\text{.}\) The set of all units of \(\Z/n\Z\) is denoted \((\Z/n\Z)^*\text{:}\) i.e.,
\begin{equation} (\Z/n\Z)^*=\{\overline{a}\in \Z/n\Z\mid \overline{a}\overline{b}=\overline{1} \text{ for some } \overline{b}\in \Z/n\Z\}\text{.}\tag{1.2.10} \end{equation}

Specimen 5. Units modulo \(n\).

Fix a modulus \(n\text{.}\) The pair \(((\Z/n\Z)^*, \cdot)\) is a group, where \(\cdot\) is the operation defined in CorollaryΒ 1.2.11.
The group identity of \((\Z/n\Z)^*\) is \(\overline{1}\text{.}\)
Given \(\overline{a}\in (\Z/n\Z)^* \text{,}\) its group inverse is its multiplicative inverse \(\overline{a}^{-1}\text{.}\)

Example 1.2.15. Modulus \(n=5\).

Compute group tables for both \(\Z/5\Z\) and \((\Z/5\Z)^*\text{.}\) Naturally, for the latter you should first determine the units of \(\Z/5\Z\text{.}\)
Solution.

Definition 1.2.17. Greatest common divisor.

Let \(a\) and \(b\) be integers, at least one of which is nonzero. The greatest common divisor of \(a\) and \(b\text{,}\) denoted \(\gcd(a,b)\text{,}\) is the greatest positive integer dividing both \(a\) and \(b\text{:}\) i.e.,
\begin{equation} \gcd(a,b)=\max\{q\in \Z_{> 0}\mid q\mid a \text{ and } q\mid b\}\text{.}\tag{1.2.11} \end{equation}

Remark 1.2.18. Units mod \(n\).

As we will see later, it turns out that an element \(\overline{a}\in \Z/n\Z\) is a unit if and only if \(a\) is relatively prime to \(n\text{:}\) i.e., if and only if \(\gcd(a,b)=1\text{.}\) As a result of this very much non-obvious fact, we have
\begin{equation*} (\Z/n\Z)^*=\{\overline{a}\in \Z/n\Z\mid \gcd(a,n)=1\}\text{.} \end{equation*}