\chapter{Congruences}

\section{Introduction}

\subsection{Congruences}

\begin{definition}[Congruence]\index{Congruence}
    Let \( a, b, m \in \Z \) with \( m > 0 \). We say that \( a \) is \term{congruent} to \( b \) modulo \( m \) if \( m \) divides \( a - b \), \[
        a \equiv b \pmod{m} \quad \text{if} \quad m \mid (a - b)
    \]
\end{definition}

\begin{remark}
    Congruence is a weaker version of equality.

    For example, if \( a = b \) then \( a + c = b + c \), and the same holds for congruences.
\end{remark}

\begin{lemma}
    Let \( a, b, c, m \in \Z \) with \( m > 0 \). If \( a \equiv b \pmod{m} \), then \[
        a + c \equiv b + c \pmod{m}
    \]
\end{lemma}

\begin{example}[mod 5]
    There are \( 5 \) equivalence classes modulo \( 5 \), \( 0, 1, 2, 3, 4 \) are all distinct modulo \( 5 \).
\end{example}

\begin{remark}
    For \( m \), there are \( m \) equivalence classes modulo \( m \), \( 0, 1, 2, \ldots, m - 1 \).
\end{remark}

\begin{proof}[Proof (Lemma 2.1.2).]
    \[
        (a + c) - (b + c) = a - b \equiv 0 \pmod{m}
    \]
\end{proof}

\begin{lemma}
    If \( a \equiv b \pmod{m} \) and \( b \equiv c \pmod{m} \), then \( a \equiv c \pmod{m} \).
\end{lemma}

\begin{proof}
    \[
        a - c = (a - b) + (b - c) \equiv 0 \pmod{m}
    \]
\end{proof}

\begin{lemma}
    If \( a \equiv b \pmod{m} \)< then \( a c \equiv b c \pmod{m} \).
\end{lemma}

\begin{proof}
    \[
        ac - bc = c(a - b) \equiv 0 \pmod{m}
    \]
\end{proof}

\begin{lemma}
    If \( ac \equiv bc \pmod{m} \), then \( a \equiv b \pmod{m} \) if \( m \) coprime to \( c \).
\end{lemma}

\begin{proof}
    \[
        m \mid (ac - bc) \implies m \mid c(a - b)
    \]

    Since \( m \) is prime, \( m \mid c \) or \( m \mid (a - b) \).

    However, \( m \nmid c \) by assumption, so \( m \mid (a - b) \).
\end{proof}

\begin{remark}
    This statement will not hold if \( m \) is not coprime to \( c \).

    For example, \( 2 \times 3 \equiv 0 \times 3 \pmod{6} \) but \( 2 \not\equiv 0 \pmod{6} \).
\end{remark}

\subsection{Congruences and Primes}

\begin{theorem}
    If \(a \) is coprime to \( m \), then there exists \( b \) such that \( ab \equiv 1 \pmod{m} \).
\end{theorem}

\begin{proof}
    By Bezout's Lemma, there exist \( x, y \) such that \( ax + my = 1 \).

    Rearranging, \( ax -1 = -my \equiv 1 \pmod{m} \).

    So \( b = x \) satisfies the condition.
\end{proof}

\begin{remark}
    Can there be \( b_1 \not\equiv b_2 \pmod{m} \) such that \( ab_1 \equiv 1 \pmod{m} \) and \( ab_2 \equiv 1 \pmod{m} \)?


    No. \[
        ab_1 \equiv ab_2 \pmod m \implies b_1ab_1 \equiv ab_2b_1 \pmod m \implies b_1 \equiv b_2 \pmod m
    \]
\end{remark}

\begin{example}[mod 5]
    \begin{itemize}
        \item \( 1^{-1} \equiv 1 \pmod{5} \)
        \item \( 2^{-1} \equiv 3 \pmod{5} \)
        \item \( 3^{-1} \equiv 2 \pmod{5} \)
        \item \( 4^{-1} \equiv 4 \pmod{5} \)
    \end{itemize}
\end{example}

\begin{example}[mod 8]
    Does \( 2^{-1} \) exist modulo \( 8 \)?

    No! \( 2 \) is not coprime to \( 8 \).

    Suppose \( 2b \equiv 1 \pmod{8} \), then \( 2b - 1 = 8k \) for some \( k \in \Z \). This is impossible, as \( 1 \) is not divisible by \( 2 \).
\end{example}

How many \( x \pmod{m} \) are such that \( x^2 \equiv 1 \pmod{m} \)?

For simplicity, we will assume that \( m \) is prime.

There will be only \( 2 \).

\begin{proof}
    \( x^2 - 1 \equiv 0 \pmod{m} \iff (x - 1)(x + 1) \equiv 0 \pmod{m} \).

    Thus, \( x - 1 \equiv 0 \pmod{m} \) and \( x + 1 \equiv 0 \pmod{m} \) are the only solutions.
\end{proof}

What if \( m = pq \), \( p \neq q \) and \( p, q \) are prime?

There will be \( 4 \) solutions.

\begin{proof}
    \( pq \mid (x - 1)(x + 1) \)

    \begin{itemize}
        \item \( x \equiv \pm 1 \pmod{pq} \)
        \item \( x \equiv 1 \pmod{p}, x \equiv -1 \pmod{q} \)
        \item \( x \equiv -1 \pmod{p}, x \equiv 1 \pmod{q} \)
    \end{itemize}
\end{proof}

Open question: how do ew know that we can satisfy both conditions?

\begin{example}
    Consider powers of \( 2 \) modulo \( 5 \).

    \begin{figure}[H]
        \centering
        \begin{tikzpicture}
            \node (2) at (0, 0) {2};
            \node (4) at (1, 0) {4};
            \node (3) at (2, 0) {3};
            \node (1) at (3, 0) {1};

            \draw[->] (2) -- (4);
            \draw[->] (4) -- (3);
            \draw[->] (3) -- (1);
            \draw[->] (1) to[bend left] (2);
        \end{tikzpicture}
    \end{figure}
\end{example}

\begin{example}
    Consider modulo \( 8 \).

    \begin{itemize}
        \item \( 3^2 \equiv 1 \pmod{8} \)
        \item \( 5^2 \equiv 1 \pmod{8} \)
        \item \( 7^2 \equiv 1 \pmod{8} \)
    \end{itemize}

    We see that all numbers coprime to \( 8 \) are congruent to \( 1 \) modulo \( 8 \). This means that \( 1 \) is a generator of the group of units modulo \( 8 \).
\end{example}

For any \( a \not\equiv 0 \pmod{m} \), \( a \) coprime to \( m \), is \( a^k \equiv 1 \pmod{m} \) for some \( k \)?

Yes!

\begin{proof}
    Because there is only finitely many options, \[
        a^i \equiv a^j \pmod{m}
    \] for some \( i > j \).

    Thus, \( a^i - a^j \equiv 0 \pmod{m} \), and \( a^j(a^{i - j} - 1) \equiv 0 \pmod{m} \).

    Since \( a \) is coprime to \( m \), \( a^{i - j} - 1 \equiv 0 \pmod{m} \implies a^{i - j} \equiv 1 \pmod{m} \).
\end{proof}

\begin{theorem}[Fermat's Little Theorem]\index{Fermat's Little Theorem}
    For \( p \in \N \) prime and \( a \in \Z \) coprime to \( p \), \[
        a^{p} \equiv a \pmod{p}
    \]

    In particular, \[
        a^{p - 1} \equiv 1 \pmod{p}
    \]
\end{theorem}

\begin{proof}[Proof. (Attempt)]
    {~~~}

    \begin{itemize}
        \item If \( a = 1 \), then the statement is trivial.
        \item If \( a = -1 \),
              \begin{itemize}
                  \item \( -1 \equiv 1 \pmod{2} \)
                  \item For other prime \( p \), \( (-1)^p = -1 \), and \( -1 \equiv 1 \pmod{p} \).
              \end{itemize}
        \item \( p = 5 \)

              \begin{table}[H]
                  \centering
                  \begin{tabular}{c|ccccc}
                      \( \times \) & 1 & 2 & 3 & 4 & 5 \\ \hline
                      1            & 1 & 2 & 3 & 4 & 5 \\
                      2            & 2 & 4 & 1 & 3 & 5 \\
                      3            & 3 & 1 & 4 & 2 & 5 \\
                      4            & 4 & 3 & 2 & 1 & 5 \\
                  \end{tabular}
              \end{table}

              We observe that in each row of the multiplication table, each number mod \( p \) appear exactly once.

              In other words, \( \{ a_1, d_2, \dots, a_{p - 1} \} \) are all distinct, and is a permutation of \( \{ 1, 2, \dots, p - 1 \} \pmod{p} \).

              Multiplying the centre row,
              \begin{align*}
                  a (2a) (3a) \cdots ((p-1)a)
                   & \equiv 1 2 3 \cdots (p-1) \pmod{p} \\
                  a^{p-1} (1 2 3 \cdots (p-1))
                   & \equiv 1 2 3 \cdots (p-1) \pmod{p} \\
                  a^{p-1}
                   & \equiv 1 \pmod{p}
              \end{align*}
    \end{itemize}
\end{proof}

\begin{remark}
    Sometimes, \( a^{m-1} \equiv \pmod{m} \) even if \( m \) is not prime.

    For \( m \) such that \( 2^{m-1} \equiv 1 \pmod{m} \), \( m \) is called a \term{Carmichael prime}\index{Carmichael prime}.

    This offers a test wether a number \( m \) if prime: if \( 2^{m-1} \not\equiv 1 \pmod{m} \), then \( m \) is not prime.
\end{remark}

\begin{note}
    How to do fast exponential

    Suppose we want to calculate \( a^{100} \). We know \( 100 = 64 + 32 + 4 \), so instead taking the iterative approach, we can calculate \( a^{64} \), \( a^{32} \), and \( a^4 \) and multiply them together.

    More precisely,
    \begin{itemize}
        \item \( a^4 = (a^2)^2 \)
        \item \( a^32 = (a^{16})^2 = ((a^8)^2)^2 = (((a^4)^2)^2)^2 \)
        \item \( a^{64} = (a^{32})^2 \)
    \end{itemize}
\end{note}

\begin{theorem}
    What is true if \( m \) is not prime? \[
        a^{\varphi(m)} \equiv 1 \pmod{m}
    \]
\end{theorem}

\begin{definition}[Euler's Totient Function]\index{Euler's Totient Function}
    The \term{Euler's Totient Function} \( \varphi(m) \) is the number of integers \( a \) such that \( 1 \leq a \leq m \) and \( a \) is coprime to \( m \).
\end{definition}

\begin{example}
    Consider some example
    \begin{itemize}
        \item \( \varphi(4) = 2 \)
        \item \( \varphi(5) = 4 \)
        \item \( \varphi(6) = 2 \)
        \item \( \varphi(7) = 6 \)
        \item \( \varphi(8) = 4 \)
        \item \( \varphi(9) = 6 \)
    \end{itemize}
\end{example}

% \begin{remark}
%     If \( m \) is prime, then \( \phi(m) = m - 1 \).
% \end{remark}

\begin{remark}
    Consider \( p \) prime.

    \begin{itemize}
        \item \( \varphi(p) = p - 1 \)
        \item \( \varphi(p^2) = p^2 - p \)
        \item \( \varphi(p^k) = p^k - p^{k-1} \)
    \end{itemize}
\end{remark}

\begin{remark}
    Consider \( p_1, p_2 \) prime. \[
        \varphi(p_1 p_2) = (p_1 - 1)(p_2 - 1)
    \]
\end{remark}

% \begin{remark}
%     Consider \( p_1, p_2, \dots, p_k \) prime.

%     \[
%         \phi(p_1^{k_1} p_2^{k_2} \cdots p_k^{k_k}) = p_1^{k_1} (1 - \frac{1}{p_1}) p_2^{k_2} (1 - \frac{1}{p_2}) \cdots p_k^{k_k} (1 - \frac{1}{p_k})
%     \]
% \end{remark}

\begin{proof}[Proof (Theorem 2.1.8)]
    WTS \( a^{\varphi(m)} \equiv 1 \pmod{m} \).

    Define \( U_n \) the set of congruence number from 1 to \( m \) coprime to \( m \).

    We observe that \( aUm = \{ au: u \in U_m \} \) is also a set of congruence numbers coprime to \( m \), \[
        aU_m = U_m.
    \]

    This is because \( a \) has an inverse modulo \( m \), so \( ab_1 \equiv ab_2 \pmod{m} \implies b_1 \equiv b_2 \pmod{m} \).

    \[
        \prod_{x \in aU_p} x = a^{\varphi(m)} \left( \pi_{y \in U_p} y \right)
    \] and \[
        \prod_{x \in aU_p} x \equiv \prod_{y \in U_p} y \pmod{m}
    \] so \[
        \prod_{y \in U_p} y \equiv a^{\varphi(m)} \left( \pi_{y \in U_p} y \right) \pmod{m}
    \]

    Since \( y \in U_p \) has an inverse, we cancel this factor, \[
        1 \equiv a^{\varphi(m)} \pmod{m}
    \]
\end{proof}

\section{Euler's Totient Function}

\begin{theorem}[Chinese Remainder Theorem]\index{Chinese Remainder Theorem}
    Let \( m_1, m_2 \) be coprime. Then, for any \( a_1, a_2 \), there exists an \( a \) modulo \( m,n \) such that \[
        a \equiv a_1 \pmod{m_1} \quad \text{and} \quad a \equiv a_2 \pmod{m_2}
    \]
\end{theorem}

\begin{example}
    If given \( a \equiv 1 \pmod{6} \), can answer
    \begin{itemize}
        \item what \( a \) is modulo \( 7 \)?
        \item what \( a \) is modulo \( 2 \) and \( 3 \)?
    \end{itemize}

    \( a \equiv 1 \pmod{6} \implies a = 6k + 1 \) for some \( k \in \Z \).

    Knowing \( a \equiv 1 \pmod{6} \) does not tell us anything about \( a \) modulo \( 7 \). However, it does tell us something about \( a \) modulo \( 2 \) and \( 3 \).

    In fact, \( a \equiv 1 \pmod{6} \) tells us that \( a \equiv 1 \pmod{2} \) and \( a \equiv 1 \pmod{3} \). Looking at modulo 6 provides strictly more information than looking at modulo 2 and 3 separately.
\end{example}

\begin{remark}
    Information modulo \( m \) and \( n \) is decorrelated completely if \( m \) and \( n \) are coprime.
\end{remark}

\begin{remark}
    \( \varphi(p_1 p_2) = (p_1 - 1)(p_2 - 1) = \varphi(p_1) \varphi(p_2) \) if \( p_1, p_2 \) are prime.
\end{remark}

\begin{theorem}[Re-statement of the Chinese Remainder Theorem]
    If \( m_1, m_2 \) are coprime, then there is a map \[
        \Z/m \to \Z/m_1 \times \Z/m_2
    \]
\end{theorem}

\begin{remark}[Notation]
    \( \Z/m \) means number modulo \( m \). It has \( m \) elements, \( 0, 1, \dots, m - 1 \).

    \( \Z/m \) has addition, multiplication, \( \bar{0} \), and \( \bar{1} \)
\end{remark}

\begin{theorem}
    The mapping \( \Z/m \to \Z/m_1 \times \Z/m_2 \) is a bijection.
\end{theorem}

\begin{example}
    Consider \( m = 6, m_1 = 2, m_2 = 3 \).

    \begin{table}[H]
        \centering
        \begin{tabular}{ccccc}
            \( \Z/6 \) & \( \mapsto \) & \( \Z/2 \) & \( \times \) & \( \Z/3 \) \\
            1          &               & (1         & ,            & 1)         \\
            2          &               & (0         & ,            & 2)         \\
            3          &               & (1         & ,            & 0)         \\
            4          &               & (0         & ,            & 1)         \\
            5          &               & (1         & ,            & 2)         \\
            0          &               & (0         & ,            & 0)         \\
        \end{tabular}
    \end{table}
\end{example}

\vspace{-2em}
\begin{proof}
    WTS the mapping is a bijection.

    \begin{itemize}
        \item \textbf{Injectivity}:

              Suppose that \( \varphi(a \mod m) = \varphi(b \mod m) \).

              Then, \( a \equiv b \pmod{m_1} \) and \( a \equiv b \pmod{m_2} \), so \( m_1, m_2 \mid (a - b) \).

              By unique factorization, \( m = m_1 m_2 | (a - b) \) since \( gcd(m_1, m_2) = 1 \), so \( a \equiv b \pmod{m} \).

        \item \textbf{Surjectivity}:

              Since \( | \Z/m | = | \Z/m_1 \times \Z/m_2 | \) and the mapping is injective, it must be surjective.
    \end{itemize}
\end{proof}

\begin{example}
    Let \( m_1 = 4 \), \( m_2 = 9 \).

    Find \( a \pmod{36} \) such that \( a \equiv 3 \pmod{4} \) and \( a \equiv 5 \pmod{9} \).

    \begin{itemize}
        \item Method 1

              \( a = 4x + 3 \) for some \( x \in \Z \).

              We want \( 4x + 3 \equiv 5 \pmod{9} \), so \( 4x \equiv 2 \pmod{9} \).

              Since \( 4 \) coprime to \( 9 \), \( 4^{-1} \) exists modulo \( 9 \), so \( x \equiv 4^{-1} \cdot 2 \pmod{9} \).

              We have \( 4 \times 2 \equiv 8 \pmod{9} \implies 4 \times (-2) \equiv 1 \pmod{9} \), so \( x \equiv -2 \cdot 2 \equiv -4 \equiv 5 \pmod{9} \).

              Then, \( a = 4 \times 5 + 3 = 23 \).
    \end{itemize}
\end{example}

\begin{remark}
    This is a direct proof of surjectivity in.

    \begin{proof}
        WTS \( a \equiv a_1 \pmod{m_1} \) and \( a \equiv a_2 \pmod{m_2} \) for some \( a \).

        Let \( a = a_1 + m_1 x \) for some \( x \in \Z \).

        \( a + m_1 x \equiv a_2 \pmod{m_2} \iff x \equiv m_1^{-1} (a_2 - a_1) \pmod{m_2} \).

        \( m^{-1} \pmod{m_2} \) exists since \( m_1 \) and \( m_2 \) are coprime.
    \end{proof}
\end{remark}

\begin{remark}
    An extended version of the Chinese Remainder Theorem states that if \( m_1, m_2, \dots, m_k \) are pairwise coprime, then there is a bijection \[
        \Z/m \to \Z/m_1 \times \Z/m_2 \times \cdots \times \Z/m_k
    \]
\end{remark}

\begin{example}
    Let \( d = gcd(m_1, m_2) \), \( \Z/m \to \Z/m_1 \times \Z/m_2 \) a mapping.

    What condition on \( a_1, a_2 \) guarentee existence of \( a \pmod{m} \) such that \( a \equiv a_1 \pmod{m_1} \) and \( a \equiv a_2 \pmod{m_2} \)?

    \begin{figure}[H]
        \centering
        \begin{tikzpicture}
            \node (zm)  at ( 0, 2) {\( \Z/m \)};
            \node (zm1) at (-1, 1) {\( a_1 \in \Z/m_1 \)};
            \node (zm2) at ( 1, 1) {\( a_2 \in \Z/m_2 \)};
            \node (zd)  at ( 0, 0) {\( \Z/d \)};

            \draw[->] (zm) -- (zm1);
            \draw[->] (zm) -- (zm2);
            \draw[->] (zm1) -- (zd);
            \draw[->] (zm2) -- (zd);
        \end{tikzpicture}
    \end{figure}
\end{example}

\begin{theorem}
    If \( a_1 \equiv a_2 \pmod{d} \), then there exists \( a \) such that \( a \equiv a_1 \pmod{m_1} \) and \( a \equiv a_2 \pmod{m_2} \).
\end{theorem}

\begin{proof}
    Let \( a = a_1 + m_1 x \) for some \( x \in \Z \).

    Then, \( a_1 + m_1 x \equiv a_2 \pmod{m_2} \), so \( x_1 x \equiv a_2 - a_1 \pmod{m_2} \).

    Since \( a_1 \equiv a_2 \pmod{d} \), \( a_2 - a_1 = dy \) for some \( y \in \Z \).

    Then, \( d \cdot \left( \frac{m_1}{d} \right) x \equiv dy \pmod{m_2} \).

    This is equivalent to \( d \left( \left( \frac{m_1}{d} \right) x - y \right) \) divisible by \( d \cdot \left( \frac{m_2}{d} \right) \).

    Factor \( d \) out, \( \left( \frac{m_1}{d} \right) x - y \) is divisible by \( \left( \frac{m_2}{d} \right) \).

    In other words, \( \left( \frac{m_1}{d} \right) x \equiv y \pmod{\frac{m_2}{d}} \).

    Now \( \frac{m_1}{d} \) is invertible modulo \( \frac{m_2}{d} \).

    Thus, \( x \equiv \left( \frac{m_1}{d} \right)^{-1} y \pmod{\frac{m_2}{d}} \).
\end{proof}

\begin{theorem}
    The map \( \Z / m_1m_2\cdots m_r \to \Z/m_1 \times \cdots \times \Z/m_r \) is a bijection if and only if \( gcd(m_i, m_j) = 1 \) for all \( i \neq j \).
\end{theorem}

\begin{remark}
    \( \Z / m \) is a \term{ring}.
\end{remark}

\begin{definition}[Ring]\index{Ring}
    A \term{ring} is a mathematical structure that satisfies the following axioms:

    \begin{itemize}
        \item It has an addition \( + \), where \( a + b = b + a \).
        \item It has a multiplication \( \times \), where (for commutative rings) \( ab = ba \).
        \item It has a unique zero element \( 0 \), where \( 0 + a = a \) for all \( a \).
        \item It has a additive inverse \( -a \), where \( a + (-a) = 0 \).
        \item It has a unique one element \( 1 \), where \( 1 \times a = a \) for all \( a \).
        \item \( a (b + c) = ab + ac \).
    \end{itemize}

    In particular, if multiplication is commutative, then the ring is a \term{commutative ring}.
\end{definition}

\begin{example}
    Examples of rings include
    \begin{itemize}
        \item \( \Z \subseteq \Q \subseteq \R \subseteq \C \).

        \item \( \Z \to \Z / m \), \( a \mapsto a \pmod{m} \).

        \item Polynomials \( \R[x] \).

        \item Vector space \( \R^{\N} \), where multiplication is the element-wise multiplication.

        \item \( R^w = ( r_1, r_2, \dots, r_w, 0, 0, \dots) \) is similar to \( \R[x] \).

              \( R^{\N} \) is similar to the power series.

        \item The power-set \( \PP(S) \) of set \( S \), where
              \begin{itemize}
                  \item \( A + B = (A \setminus B) \cup (B \setminus A) \)
                  \item \( A \times B = A \cap B \)
                  \item \( 0 = \emptyset \)
                  \item \( -A = A \)
                  \item \( 1 = S \)
              \end{itemize}
              This is similar to \( \left( \Z/2 \right)^S \).
    \end{itemize}

    And some non-Examples
    \begin{itemize}
        \item \( \N_{\geq 0} \) does not have additive inverses.
        \item Set of \( 2 \times 2 \) matrices does not have multiplicative commutativity.
        \item \( \R[x]_{\text{deg} \leq 10} \) is not closed under multiplication.
    \end{itemize}
\end{example}

\begin{definition}
    The \term{unit} of a ring \( \RR \) is the set of elements that have a multiplicative inverse, \[
        U(\RR) = \RR^\times = \{ a | a \text{ has a multiplicative inverse} \}
    \]
\end{definition}

\begin{example}
    We consider the following examples.

    \begin{itemize}
        \item \( \Z^\times = \{ 1, -1 \} \)
        \item \( \Q^\times = \Q \setminus \{ 0 \} \)
        \item \( (\R[x])^\times = \R^\times = \text{constant polynomials} \)
        \item \( (\R^5)^\times = ( \R^\times )^5 = \{ (a, b, c, d, e), a,b,c,d,e \neq 0 \} \)
        \item \( ( \Z / m)^\times = \{ a \pmod{m}, gcd(a, m) = 1 \} \).

              This is also known as the \term{Euler Totient Function} \( \varphi(m) \).
    \end{itemize}
\end{example}

\begin{example}
    Consider \( \Q[\sqrt{2}] = \{ a + b \sqrt{2} \} | a, b \in \R \), where \[
        (a + b\sqrt{2})(c + d\sqrt{2}) = ac + \sqrt{2} (ad + bc) + 2bd
    \]

    Note that \[
        \frac{1}{a + b\sqrt{2}} = \frac{a - b\sqrt{2}}{a^2 - 2b^2}
    \]

    Makes sense as long as \( a^2 - 2b^2 \neq 0 \), so we avoid \( a = b = 0 \).

    Otherwise, \( a^2 - 2b^2 = 0 \implies 2 = (a / b)^2 \), and expressing \( \sqrt{2} \) as a rational number is impossible.
\end{example}

\begin{example}
    Consider \( \Z[\sqrt{2}] = \{ a + b \sqrt{2} \} | a, b \in \Z \).

    Similarly, \[
        \frac{1}{a + b\sqrt{2}} = \frac{a - b\sqrt{2}}{a^2 - 2b^2}
    \] and so \( a + b\sqrt{2} \) is invertible exactly when \( a^2 - 2b^2 = \pm a, b \).

    This can happen if \( a^2 - 2b^2 = \pm 1 \).

    We could take \( a = \pm 1 \), and \( b = 0, \pm 1 \); or \( a = \pm 2 \), \( b = \pm 2 \).

    In fact, \( a^2 - 2b^2 = 1 \) tells us the norm of the number is \( 1 \), and there are infinitely many solutions to this equation -- the power of any existing solution is also a solution, \[
        ( 3 \pm 2\sqrt{2} )^n, n \in \N
    \]
\end{example}

\begin{definition}[Field]\index{Field}
    A \term{field} is a commutative ring where every element has a multiplicative inverse (except for \( 0 \)).

    In other words, a field is a ring where \( \RR^\times = \RR \setminus \{ 0 \} \).
\end{definition}

\begin{proposition}
    \( U(\RR) \) is always a group.
\end{proposition}

\begin{lemma}
    \( U(\RR_1 \times \RR_2 \times \cdots \times \RR_k) = U(\RR_1) \times U(\RR_2) \times \cdots \times U(\RR_k) \).

    \( \RR_1 \times \cdots \times \RR_n \) has coordinate wise addition and multiplication.
\end{lemma}

\begin{proof}
    Say we have \( r_1, \dots, r_n \) with inverse \( s_1, \dots, S_n \).

    That is, \( (r_1, \dots, r_n)(s_1, \dots, s_n) = (1, \dots, 1) \).

    Then, \( (r_1, \dots, r_n) \) has inverse \( (s_1, \dots, s_n) \).

    This can happen if and only if \( r_i s_i = 1 \) for all \( i \).

    In other words, \( r_i \in U(\RR_i) \) for all \( i \).
\end{proof}

\begin{remark}
    By the lemma and the Chinese Remainder theorem, \[
        U( \Z/ 5^2 3^3 7^{10}) = U(\Z/5^2) \times U(\Z/3^7) \times U(\Z/7^{10})
    \]

    Understanding \( U(\Z/m) \) as a group reduces to understanding \( U(\Z/p^k) \) for prime \( p \).
\end{remark}

\begin{definition}[Cyclic Group]\index{Cyclic Group}
    A \term{cyclic group} is a group where all elements are powers of a single element, called the \term{generator} of the group. \[
        C = \{ a^k | k \in \Z \} = \langle a \rangle
    \]
\end{definition}

\begin{example}
    An example of a cyclic group is \( \Z / n\Z \), where \( 1 \) is a generator. Other generators are the numbers coprime to \( n \).

    The number of generators of \( \big( \Z / n\Z \big) \) is \( \varphi(n) \).
\end{example}

\begin{example}
    We consider \( U(\Z/m) \) for small \( m \).

    \begin{itemize}
        \item \( U(\Z/2) = \{ 1 \} = \langle 1 \rangle \)
        \item \( U(\Z/3) = \{ 1, 2 \} = \langle 2 \rangle \)
        \item \( U(\Z/4) = \{ 1, 3 \} = \{ \pm 1 \} = \langle 3 \rangle \)
        \item \( U(\Z/5) = \{ 1, 2, 3, 4 \} = \langle 2 \rangle = \langle 3 \rangle \)
        \item \( U(\Z/7) = \{ 1, 2, 3, 4, 5, 6 \} = \langle 3 \rangle = \langle 5 \rangle \)
        \item \( U(\Z/8) = \{ 1, 3, 5, 7 \} = \langle 3 \rangle \times \langle 5 \rangle = \{ \pm 1 \}^2 \cong \Z/2 \times \Z/2 \)
    \end{itemize}
\end{example}

\begin{definition}[Order of an Element]\index{Order of an Element}
    The \term{order} of an element \( g \) in a group \( ( G, \cdot ) \) is the smallest \( k \) such that \( g^k = 1 \).
\end{definition}

\begin{theorem}
    For \( p \) and odd prime, \( U(\Z/p) \) is cyclic.
\end{theorem}

\begin{remark}
    \( \Z / p \) is a field.
\end{remark}