\documentclass{article}
\usepackage{amssymb, mathrsfs, enumitem}
\usepackage{tikz-cd}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{color}
\usepackage{amsthm}
\usepackage{hyperref}
\usepackage{verbatim}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{amsmath, epsfig, colortbl}
\usepackage[breakable, skins]{tcolorbox}
\setlength{\parskip}{8pt}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{cor}{Corollary}
\theoremstyle{definition}
\newtheorem{prop}{Proposition}
\newtheorem{fact}{Fact}
\newtheorem{example}{Example}
\newtheorem{definition}{Definition}
\newenvironment{solution} {\paragraph{Solution.}}{\hfill$\square$}
\renewenvironment{proof} {\paragraph{Proof.}}{\hfill$\square$}
\renewcommand{\today}{}
\captionsetup{margin=.7in, format=hang}

\newtcolorbox{examplebox}{ breakable, enhanced}
\newtcolorbox{gptbox}{ breakable, enhanced,  colback  = blue!10}

\addtolength{\topmargin}{-.875in}
\addtolength{\oddsidemargin}{-.8in}
\addtolength{\textwidth}{1.6in}
\addtolength{\textheight}{1.75in}

\newcommand{\mc}{\mathcal}
\newcommand{\abs}[1]{\left| #1\right|}
\newcommand{\la}{\Leftarrow}
\newcommand{\ra}{\Rightarrow}
\renewcommand{\iff}{\Leftrightarrow}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\floor}[1]{\left\lfloor #1\right\rfloor}
\newcommand{\ceil}[1]{\left\lceil #1\right\rceil}
\renewcommand{\phi}{\varphi}

\newcommand{\ex}[1]{\begin{examplebox}\begin{example} #1 \end{example}\end{examplebox}}

\newcommand{\eps}{\epsilon}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\inv}[1]{#1^{-1}}
\newcommand{\ba}{\backslash}
\DeclareMathOperator{\Mod}{mod}
\renewcommand{\mod}[1]{\ (\Mod #1)}

\def\cents{\hbox{\rm\rlap/c}}




\begin{document}
\title{Math 127: Equivalence Relations}
\author{Mary Radcliffe}
\maketitle

\section{Equivalence Relations}

Relations can take many forms in mathematics. In these notes, we focus especially on equivalence relations, but there are many other types of relations (such as order relations) that exist. 

\begin{definition}
Let $X,Y$ be sets. A {\it relation} $R=R(x, y)$ is a logical formula for which $x$ takes the range of $X$ and $y$ takes the range of $Y$, sometimes called a {\it relation from $X$ to $Y$}. If $R(x, y)$ is true, we say that {\it $x$ is related to $y$ by $R$}, and we write $xRy$ to indicate that $x$ is related to $y$ by $R$.
\end{definition}

\ex{Let $f:X\to Y$ be a function. We can define a relation $R$ by $R(x, y) \equiv (f(x)=y)$.}

\ex{Let $X=Y=\Z$. We can define a relation $R$ by $R(a,b)\equiv a|b$.}

There are many other examples at hand, such as ordering on $\R$, multiples in $\Z$, coprimality relationships, etc. The definition we have here is simply that a relation gives some way to connect two elements to each other, that can either be true or false.

Of course, that's not a very useful thing, so let's add some conditions to make the relation carry more meaning. For this, we shall focus on relations from $X$ to $X$, also called relations {\it on $X$}. There are several properties that will be interesting in considering relations:

\begin{definition}
Let $X$ be a set, and let $\sim$ be a relation on $X$. 
\begin{itemize}
\item We say that $\sim$ is {\it reflexive} if $x\sim x$ $\forall x\in X$.
\item We say that $\sim$ is {\it symmetric} if $x\sim y \ra y\sim x$ $\forall x, y\in X$.
\item We say that $\sim$ is {\it antisymmetric} if $x\sim y \wedge y\sim x \ra x=y$ $\forall x, y\in X$.
\item We say that $\sim$ is {\it transitive} if $x\sim y \wedge y\sim z \ra x\sim z$ $\forall x, y, z\in X$.
\end{itemize}
\end{definition}

\ex{Let $X=\Z$, and define a relation $\sim$ by $x\sim y \equiv \gcd(x, y)=1$. Let's consider what properties $\sim$ satisfies.
\begin{itemize}
\item Reflexivity: NO. Take $|x|>1$, then $\gcd(x, x)=x \neq 1$, so $x\sim x$ is almost never true.
\item Symmetry: YES. Since $\gcd(x, y)=\gcd(y, x)$, we definitely have symmetry.
\item Antisymmetry: NO. Obviously we can't have symmetry and antisymmetry at the same time.
\item Transitivity: NO. Take $x=10, y=9, z=20$. Then we have $x\sim y$ and $y\sim z$, but we definitely don't get $x\sim z$. 
\end{itemize}}

\ex{Let $X=\R$, and define a relation $\leq$ as is standard. Let's consider what properties $\leq$ satisfies.
\begin{itemize}
\item Reflexivity: YES. Certainly $x\leq x$ is always true.
\item Symmetry: NO. It doesn't make sense that $x\leq y \ra y\leq x$.
\item Antisymmetry: YES. If $x\leq y \wedge y\leq x$, it is standard to conclude that $x=y$.
\item Transitivity: YES. If $x\leq y\wedge y\leq z$, we know that $x\leq z$.
\end{itemize}
}

What we are most interested in here is a type of relation called an {\it equivalence relation}.
\begin{definition}
A relation $R$ on $X$ is called an equivalence relation if it is reflexive, symmetric, and transitive.
\end{definition}

\ex{\label{E:evenodd}Define a relation $\sim$ on $\Z$ by $x\sim y$ if $x$ and $y$ have the same parity (even or odd). We claim that $\sim$ is an equivalence relation:
\begin{itemize}
\item Reflexivity: Since $x$ has the same parity as $x$, $x\sim x$.
\item Symmetry: If $x\sim y$, then $x$ and $y$ have the same parity. Thus $y$ and $x$ have the same parity, and hence $y\sim x$.
\item Transitivity: If $x\sim y$, then $x$ and $y$ have the same parity. If $y\sim z$, then $y$ and $z$ have the same parity. Since $y$ has only one parity, we can thus conclude that $x$ and $z$ have the same parity, so $x\sim z$.
\end{itemize}
Therefore $\sim$ is an equivalence relation.
}

What we notice about this example is that the equivalence relation we defined sliced up $\Z$ into two groups: the evens, and the odds. Everything in the evens group is related to everything else in the evens group under $\sim$, and everything in the odds group is related to everything else in the odds group under $\sim$, but there are no relations between the evens and odds. In general, this is exactly how equivalence relations will work.

\begin{theorem}\label{T:partition} Let $X$ be a set. Let \[\mathcal{S} = \{R\ | \ R\hbox{ is an equivalence relation on $X$}\},\]
and let \[\mathcal{U}=\{\hbox{pairwise disjoint partitions of $X$}\}.\]
Then there is a bijection $F:\mathcal{S}\to \mathcal{U}$, such that $\forall R \in \mathcal{S}$, if $xR y$, then $x$ and $y$ are in the same set of $F(R)$.
\end{theorem}

\begin{proof}
We first define the function $F$. Given a relation $R$, define $[x]_R=\{y\in X\ | \ xRy\}$. We then define the function $F$ by $F(R)=\{[x]_R\ | \ x\in X\}$. We must first show that $F$ is well defined; that is, that $F(R)$ is a pairwise disjoint partition of $X$.

We note that there are two properties to verify: that these sets are pairwise disjoint, and that they cover all of $X$. First, let us consider pairwise disjointness. Let $x\in X$, and note that $x\in[x]_R$ by symmetry, so $x\in \cup_{A\in F(R)}A$. This verifies that $F(R)$ covers all of $X$.

Now, let us suppose that for some $y\in X$, we also have that $x\in [y]_R$ for some $y\in X$. Let $z\in [y]_R$. Then $y\sim x$ and $y\sim z$, so by symmetry and transitivity, we have $x\sim z$. Thus, $z\in [x]_R$ $\forall z\in [y]_R$, so $[y]_R\subseteq [x]_R$. But then $y\in [x]_R$, so by repeating this argument we obtain $[x]_R\subseteq [y]_R$. Thus, $[y]_R=[x]_R$, and hence $x$ appears only in the set $[x]_R$ in $F(R)$. This establishes pairwise disjointness.

Hence, the function is well-defined.

Next, we establish bijectivity.

For injectivity, suppose that $R_1$ and $R_2$ are equivalence relations on $X$, and $R_1\not\equiv R_2$. Then there exist $x, y\in X$ that are related under one of $R_1, R_2$, but not the other; wolog, say $xR_1 y$ and $x\not R_2 y$. Then $y\in [x]_{R_1}$, but $y\notin [x]_{R_2}$, and hence $F(R_1)\neq F(R_2)$. Thus, the function is injective.

For surjectivity, let $U$ be a pairwise disjoint partition of $X$. Define a relation $R$ on $X$ by $x R y \equiv (x, y\hbox{ are in the same set in $U$})$. It is straightforward to establish that this is an equivalence relation, and that $F(R)=U$. Hence $F$ is surjective.

We note, moreover, that the property described on $F$ is immediate by definition of $F$.
\end{proof}

This theorem allows us fundamentally to think about equivalence relations as giving a mathematically precise way to simply break up a set into a partition that has properties we like. Indeed, we often care almost exclusively about the partitioning we have performed, and hence we give this a special name.

\begin{definition}
Let $\sim$ be an equivalence relation on $X$. The set $[x]_\sim$ as defined in the proof of Theorem \ref{T:partition} is called the {\it equivalence class}, or simply {\it class} of $x$ under $\sim$. We write $X/\sim = \{[x]_\sim\ | \ x\in X\}$.
\end{definition}

\ex{If we consider the equivalence relation as defined in Example \ref{E:evenodd}, we have two equivalence classes: odds and evens. We can then write $\Z/\sim = \{\hbox{$\{$odd integers$\}$, $\{$even integers$\}$}\}$. }

\section{Modular Arithmetic}

The most important reason that we are thinking about equivalence relations is to apply them to a particular situation. Specifically, we are interested in developing some theory around what is usually called modular arithmetic.

\begin{definition}
Let $n\in \N$ and let $a, b\in \Z$. We say that {\it $a$ is congruent to $b$ modulo $n$} if $n|(a-b)$. We write this as $a\equiv b\mod n$.
\end{definition}

We note the following theorem, whose proof is left as an exercise to the interested reader (but is quite straightforward).

\begin{theorem}\label{T:tfaemod}
Let $n\in\N$ and let $a, b\in \Z$. TFAE:
\begin{enumerate}
\item $a\equiv b\mod n$.
\item $a$ and $b$ leave the same remainder when divided by $n$.
\item $a=b+kn$ for some $k\in \Z$.
\end{enumerate}
\end{theorem}

Notice that this theorem is sufficient to establish the following corollary:

\begin{cor}
Congruence modulo $n$ is an equivalence relation on $\Z$.
\end{cor}

This is immediate, as the dividing of $\Z$ into classes based on what remainder is left when dividing by $n$ is clearly a pairwise disjoint partition of $\Z$, since remainders are unique by the Division Theorem. Hence, using part (b) of Theorem \ref{T:tfaemod} together with Theorem \ref{T:partition}, we immediately have that congruence forms an equivalence relation on $\Z$.

\begin{definition}
Let $n\in \N$. We denote by $\Z_n$ or $\Z/n\Z$ the set of equivalence classes under the relation of congruence modulo $n$. 
\end{definition}

Now, what we'd really like to do is think about how we can perform arithmetic operations modulo $n$, and if there is a consistent way to do so. That is to say, is there a well-defined way to understand $[a]_n+[b]_n$? Certainly, we could think of this as $[a+b]_n$, but the question that must be answered here is whether this is a well-defined operation. Since there are many different elements in $[a]_n$, would the arithmetic look different if we selected a different representative, instead of $a$? 

The good news is that, in most cases, the answer is no. The following theorem establishes that performing addition, multiplication, and subtraction is well-defined modulo $n$.

\begin{theorem} Let $a_1, a_2, b_1, b_2\in \Z$, and let $n\in\N$. Suppose, further, that $a_1\equiv a_2\mod n$ and $b_1\equiv b_2\mod n$. Then 
\begin{enumerate}
\item $a_1+b_1\equiv a_2+b_2\mod n$.
\item $a_1b_1\equiv a_2b_2\mod n$.
\item $a_1-b_1\equiv a_2-b_2\mod n$.
\end{enumerate}
\end{theorem}

\begin{proof}
The proofs of all three properties are similar. We include here only the proof of property 2, and leave the remaining proofs as an exercise.

Note that as $a_1\equiv a_2\mod n$, we have by Theorem \ref{T:tfaemod} that $a_1$ and $a_2$ have the same remainder when divided by $n$, so there exist $q_1, q_2, r$ such that $0\leq r<n$ and $a_1=q_1n+r$, $a_2=q_2n+r$. Likewise, there exist $q_1', q_2', r'$ such that $0\leq r'<n$ and $b_1=q_1'n+r'$ and $b_2=q_2'n+r'$.

Consider, then 
\begin{eqnarray*}
a_1b_1-a_2b_2 & = & (q_1n+r)(q_1'n+r')-(q_2n+r)(q_2'n+r')\\
& = & q_1q_1'n^2+q_1nr'+q_1'nr+rr'-(q_2q_2'n^2+q_2nr'+q_2'nr+rr')\\
& = & n(q_1q_1'n+q_1r'+q_1'r-q_2q_2'n-q_2r'-q_2'r)+rr'-rr'\\
& = & n(q_1q_1'n+q_1r'+q_1'r-q_2q_2'n-q_2r'-q_2'r).
\end{eqnarray*}
Then we have that $n|(a_1b_1-a_2b_2)$, and hence by definition $a_1b_1\equiv a_2b_2\mod n$.
\end{proof}

This allows us to perform these three basic arithmetic operations modulo $n$.

\ex{Determine $x$ so that \[3x+9=2x+6 \mod 7.\]

\solution{We can perform subtraction, addition, and multiplication modulo 7. Moreover, as the theorem shows, we can replace a number with any other number that it shares congruence with modulo 7. First, we subtract $2x$ from both sides, and then subtract 9 from both sides, to obtain
\[x \equiv -3\mod 7.\]
In general, we'd prefer to have positive numbers, so since $-3\equiv 4\mod 7$, we can write \[x\equiv 4\mod 7.\]
}
}

Ok, this is pretty great, but it's missing one operation! How do we perform division modulo $n$? Or even, can we?

\ex{\label{E:invfirst}Determine $x$ so that \[3x\equiv 1\mod 7.\]

Notice that there's no meaningful way to write $x\equiv \frac{1}{3}\mod 7$, since the equivalence relation of congruence modulo 7 is defined only in the integers. However, because we're very clever, we notice that 15 and 1 give the same remainder when divided by 7, so we can say that $x\equiv 5\mod 7$ will solve our problem.
}

But.... what if we're not very clever? Or what if the numbers are too big to just see the answer via observation. And also, will this always even work?

This leads us to our next section.

\subsection{Multiplicative Inverses}

As a reminder of how we defined division way back when, we had the following definition for the number $\frac{1}{n}$:

\begin{definition}
Let $n\in\Z$, with $n\neq 0$. We define $\frac{1}{n}$ to be a number such that $\frac{1}{n}n = 1$.
\end{definition}

That is to say, our definition of division is really based on multiplication. The reciprocal if $n$ is defined to be a number such that when you multiply by $n$, you get back to 1, the multiplicative identity. This is the definition we will adapt for modular arithmetic.

\begin{definition}
Let $n\in\N$ and let $a\in \Z$. We say that $u$ is a {\it multiplicative inverse} for $a\mod n$ if $au\equiv 1\mod n$.
\end{definition}

So, in Example \ref{E:invfirst}, we showed that $5$ is a multiplicative inverse for 3 modulo 7. Let's take a look at another example:

\ex{Determine $x$ so that $3x\equiv 1\mod 6$.

\solution{Well, in the previous example we just checked that we had an $x$ that worked. Since multiplication is the same for equivalent values, we can just try all the possible equivalence classes. That is to say, we can try all $x$ between 1 and 6 to see if they are the inverse:
\begin{eqnarray*}
3\cdot 1 \equiv 3\not\equiv 1\mod 6\\
3\cdot 2 \equiv 6\not\equiv 1\mod 6\\
3\cdot 3 \equiv 3\not\equiv 1\mod 6\\
3\cdot 4 \equiv 6\not\equiv 1\mod 6\\
3\cdot 5 \equiv 3\not\equiv 1\mod 6\\
3\cdot 6 \equiv 6\not\equiv 1\mod 6\\
\end{eqnarray*}
So.... nothing works. No such $x$ exists.
}
}

So sometimes inverses exist, and sometimes they don't. Let's take a look at a few examples to see if we can develop some intuition as to why. Here, you can imagine that the existence of inverses has been brute forced, as in the previous example.

\newpage

\ex{Which numbers have inverses modulo 6?

\quad

By exhaustive checking:
\begin{align*}
1&\hbox{ has an inverse, }1\\
2&\hbox{ does not have an inverse}\\
3&\hbox{ does not have an inverse}\\
4&\hbox{ does not have an inverse}\\
5&\hbox{ has an inverse, }5\\
6&\hbox{ does not have an inverse}
\end{align*}

}

\ex{Which numbers have inverses modulo 7?

\quad

By exhaustive checking:
\begin{align*}
1&\hbox{ has an inverse, }1\\
2&\hbox{ has an inverse, }4\\
3&\hbox{ has an inverse, }5\\
4&\hbox{ has an inverse, }2\\
5&\hbox{ has an inverse, }3\\
6&\hbox{ has an inverse, }6\\
7&\hbox{ does not have an inverse}
\end{align*}
}

\ex{Which numbers have inverses modulo 8?

\quad

By exhaustive checking:
\begin{align*}
1&\hbox{ has an inverse, }1\\
2&\hbox{ does not have an inverse}\\
3&\hbox{ has an inverse, }3\\
4&\hbox{ does not have an inverse}\\
5&\hbox{ has an inverse, }5\\
6&\hbox{ does not have an inverse}\\
7&\hbox{ has an inverse, }7\\
8&\hbox{ does not have an inverse}
\end{align*}
}

Examining the above 3 examples, you might notice a pattern: multiplicative inverses do not exist anytime the number we are interested in shares a factor with the modulus. This, in general, is the feature we are looking for.

\begin{theorem}\label{T:invexist}
Let $n\in \N$ and $a\in \Z$. Then $a$ has a multiplicative inverse modulo $n$ if and only if $a\perp n$.
\end{theorem}

\begin{proof}
Notice:
\begin{eqnarray*}
a\hbox{ has an inverse modulo $n$} & \iff & \exists u\in \Z,\ n|(au-1) \quad\quad\hbox{(by definition)}\\
& \iff & \exists u, v\in \Z,\ au-1=nv\\
& \iff & \exists u, v\in \Z,\ au-nv=1\\
& \iff & a\perp n \quad\quad\quad\quad\hbox{(by Bezout's Lemma)}
\end{eqnarray*}
\end{proof}

Cool, so we know exactly when inverses exist! Moreover, we can explain what's going on with 7: 7 is prime, so it's relatively prime to every number (other than 7 itself). This is of course always going to work for primes:

\begin{cor}
Let $p\in\N$ be a prime, and let $a\in\Z$, with $p\not| a$. Then $a$ has an inverse modulo $p$.
\end{cor}

This, however, doesn't really help us to find inverses. We know when they exist, but we don't really know what they are. In homework, you will show that they are unique$\mod n$, but we don't have a mechanism for calculating them, at least not yet. So let's build one.

\begin{definition}
Let $n\in\N$, and let $a\in \Z$. We define the {\it order} of $a$ modulo $n$ as
\[\inf\{k> 0\ | \ a^k\equiv 1\mod n\},\]
if such a number exists. If not, we say that the order of $a$ modulo $n$ is infinite.
\end{definition}

\begin{theorem}\label{T:finiteorder}
Let $n\in\N$ and let $a\in \Z$. Then $a$ is of finite order modulo $n$ if and only if $a\perp n$.
\end{theorem}

\begin{proof}
First, suppose that $a\not\perp n$. Then $a$ does not have a multiplicative inverse modulo $n$. Suppose, for the sake of contradiction, that the order of $a$ is finite; say the order of $a$ is $k> 0$. Then $a^k\equiv 1\mod n$, and hence $a(a^{k-1})\equiv 1\mod n$, so $a^{k-1}$ is a multiplicative inverse for $a$, which is impossible.

For the other direction, suppose that $a\perp n$. Then by Theorem \ref{T:invexist}, $a$ does have a multiplicative inverse modulo $n$, say $u$.

Now, consider $S=\{a^k\mod n\ | \ k\in\N\}$. Notice that as there are only $n$ distinct equivalence classes modulo $n$, we have that $|S|\leq n$. Hence, by the Pigeonhole Principle, there must exist $k, \ell\in\N$, with $k\neq \ell$ and $a^k\equiv a^\ell\mod n$. WOLOG, suppose that $k>\ell$. Then we have
\begin{eqnarray*}
a^k\equiv a^\ell\mod n & \ra & a^ku^\ell\equiv a^\ell u^\ell\mod n\\
& \ra & a^{k-\ell}a^\ell u^\ell \equiv a^\ell u^\ell\mod n\\
& \ra & a^{k-\ell} \equiv 1\mod n\\
& \ra & \hbox{the order of $a$ is at most $k-\ell$, which is finite}.
\end{eqnarray*}
\end{proof}

Cool! So if we wanted to find an inverse to an element, it is enough just to multiply that element by itself, and eventually we'll get to the identity. For example:

\ex{\label{E:ten}Calculate a multiplicative inverse for $8 \mod{17}$.

\solution{By Theorem \ref{T:finiteorder}, we know that for some $k>0$, we have that $10^k\equiv 1\mod{17}$. We then would have that the inverse of $10$ is $10^{k-1}$. So we can just check what the order of 10 is mod 17, by repeatedly multiplying by 10 until we get 1.
\begin{align*}
10^1 \equiv 10\mod{17}\\
10^2 \equiv 100\equiv 15 \mod{17}\\
10^3 \equiv 10\cdot 15 \equiv 150 \equiv 14\mod{17}\\
10^4 \equiv 10\cdot 14\equiv 140\equiv 4\mod{17}\\
10^5\equiv 10\cdot 4\equiv 40\equiv 6\mod{17}\\
10^6\equiv 10\cdot 6\equiv 60\equiv 9\mod{17}\\
10^7\equiv 10\cdot 9\equiv 90\equiv 5\mod{17}\\
10^8\equiv 10\cdot 5\equiv 50\equiv 16\mod{17}\\
10^9\equiv 10\cdot 16\equiv 160\equiv 7\mod{17}\\
10^{10}\equiv 10\cdot 7\equiv 70\equiv 2\mod{17}\\
10^{11}\equiv 10\cdot 2\equiv 20\equiv 3\mod{17}\\
10^{12}\equiv 10\cdot 3\equiv 30\equiv 13\mod{17}\\
10^{13}\equiv 10\cdot 13\equiv 130\equiv 11\mod{17}\\
10^{14}\equiv 10\cdot 11\equiv 110\equiv 8\mod{17}\\
10^{15}\equiv 10\cdot 8\equiv 80\equiv 12\mod{17}\\
10^{16}\equiv 10\cdot 12\equiv 120\equiv 1\mod{17}\\
\end{align*}

Therefore, we obtain that the multiplicative inverse of $10\mod{17}$ is $10^15$, which by our same set of calculations is congruent to $12\mod{17}$.
}}

This, however, was a lot of freakin work. It basically was terrible. It would be very nice if we could get a simpler approach than just brute force multiplication, because it required a lot of steps. This will be the subject of the totient theorem in the next section.

\subsection{Euler's Totient Theorem}

Euler's totient function is a tool that shows up in lots of places in mathematics. We begin this section here by defining the totient and stating the theorem. 

\begin{definition}
Let $n\in\N$. We define {\it Euler's $\phi$-function} on $n$ to be
\[\phi(n) = |\{m\in\N\ | \ m<n\wedge m\perp n\}|.\]
\end{definition}

That is to say, $\phi(n)$ is just the number of integers less than $n$ to which $n$ is coprime. Since we know that every integer is congruent to a number at most $n$ modulo $n$, we can also see this as asking how many equivalence classes modulo $n$ have multiplicative inverses. 

\ex{If $p$ is prime, then $\phi(p)=p-1$.

\quad

This is immediate, since $p$ being prime means that $p$ shares no factors with any number less than $p$. Hence, every positive integer less than $p$ is coprime to $p$, so $\phi(n) = p-1$.
}

\ex{If $p$ is an odd prime, then $\phi(2p)=p-1$.

\quad

Notice that $2p$ can only share a factor with $m<2p$ if either $m$ is even or if $m=p$. Notice that there are $\floor{\frac{2p-1}{2}}=\frac{2p-2}{2}=p-1$ even numbers less than $2p$, and hence there are $p-1+1=p$ numbers less than $2p$ with which $2p$ shares a factor. Thus, the number of numbers less than $2p$ with which $2p$ is coprime is $(2p-1)-(p)=p-1$, so $\phi(2p)=p-1$.
}

Of course, the purpose of this section was ultimately to connect this idea to finding multiplicative inverses modulo $n$ for some $n$. In particular, we have the following important theorem, known as Euler's Totient Theorem.

\begin{theorem}[Euler's Totient Theorem]\label{T:totient}
Let $n\in\N$, and let $a\in\Z$ with $a\perp n$. Then $a^{\phi(n)}\equiv 1\mod n$.
\end{theorem}

Before we prove the theorem, let's think about what this tells us. We already know that if $a$ is coprime to $n$, then we can find its multiplicative inverse by looking at powers of $a$. However, up to this point, we didn't know what power to look at, so we just had to keep slamming powers until we got the one we wanted. Now, though, we can simply take the power of $a$ given by the $\phi$ function.

\ex{Let's revisit Example \ref{E:ten} with this newfound knowledge.

We wish to calculate the multiplicative inverse of $10\mod{17}$. Since 17 is prime, we know that $\phi(17)=16$. By Euler's Totient Theorem, we know that $10^{\phi(17)}=10^{16}\equiv 1\mod{17}$. Hence, the multiplicative inverse of 10 modulo 17 is $10^{15}$.

Now, of course, that's exactly what we discovered in the previous example. However, now that we know that what we're after is $10^{15}$, we can calculate it much more efficiently. Consider:

\begin{align*}
10^2 &\equiv 100\equiv 15 \mod{17}\\
10^4 &\equiv (10^2)^2\equiv 15^2\equiv 225 \equiv 4\mod{17}\\
10^8 &\equiv (10^4)^2 \equiv 4^2 \equiv 16\mod{17}
\end{align*}

Now, we can put these pieces together to get what we're really after, which is $10^{15}$:
\begin{eqnarray*}
10^{15} &\equiv& 10^810^410^210 \mod{17}\\
&\equiv &16\cdot 4\cdot 15\cdot 10\mod{17}\\
& \equiv & 160\cdot 60\mod{17}\\
& \equiv & 7\cdot 9\mod{17}\\
& \equiv & 63 \equiv 12\mod{17}.
\end{eqnarray*}
This is, generally, a lot less work than having to calculate all the powers of 10 modulo 17. 
}

What remains, then, is to demonstrate a proof of the totient theorem.

\begin{proof}[Proof of Theorem \ref{T:totient}.]
For simplicity, write $\phi=\phi(n)$. Since $a\perp n$, we know that $a$ has a multiplicative inverse modulo $n$; let $u$ denote this inverse.

Define $X=\{m<n\ | \ m\perp n\}$, the set of integers from 1 to $n$ that are coprime to $n$. By definition, $|X|=\phi$, and hence we can write $X=\{x_1, x_2, \dots, x_\phi\}$. 

\begin{quote}{\bf Claim 1:} $ax_i\in X$ for all $1\leq i\leq \phi$.

{\bf Proof of Claim 1:} Since $a\perp n$ and $x_i\perp n$, we must have that $ax_i\perp n$. This is immediate if we consider the gcd in terms of prime decompositions, as in Homework 10, problem 3.\qed\end{quote}

\noindent Hence, we can define a function $f:X\to X$ by $f(x_i)=ax_i \mod n$, and this function is well defined. 
\begin{quote}{\bf Claim 2:} $f$ is bijective.

{\bf Proof of Claim 2:} First, suppose that $f(x_i)\equiv f(x_j)\mod n$. Then we must have that $ax_i\equiv ax_j\mod n$. Multiplying by $u$ on both sides, we thus obtain that $x_i\equiv x_j\mod n$, and hence $f$ is injective. 

Therefore, since $f:X\to X$ is injective, we must have that $|X|=|f(X)|$. But this must imply that $f(X)=X$, since $X$ is finite, and hence $f$ is also surjective.

Therefore, $f$ is bijective.\qed
\end{quote}

For $1\leq i\leq \phi$, put $y_i=f(x_i)$. Since $f$ is a bijection, we have that $X=\{x_1, x_2, \dots, x_\phi\}=\{y_1, y_2, \dots, y_\phi\}$ are two different enumerations of $X$, possibly listing the elements in a different order.

Therefore, if we consider $\prod_{x\in X}x$, we can write this as either $x_1x_2\dots x_\phi$ or as $y_1y_2\dots y_\phi$ and we will get the same outcome. Thus, we have
\begin{eqnarray*}
x_1x_2\dots x_\phi & \equiv & y_1y_2\dots y_\phi\mod n\\
& \equiv & f(x_1)f(x_2)\dots f(x_\phi)\mod n\quad\quad\quad\hbox{(by definition of $y_i$)}\\
& \equiv & ax_1ax_2\dots ax_\phi\mod n\quad\quad\quad\hbox{(by definition of $f$)}\\
& \equiv & a^\phi x_1x_2\dots x_\phi\mod n
\end{eqnarray*}

Now, since $x_i\in X$ for all $i$, we have that $x_i\perp n$ for all $i$, so each $x_i$ has a multiplicative inverse modulo $n$. In particular, put $u_i$ to be the inverse to $x_i$ for each $1\leq i\leq \phi$. Then multiplying both sides of the above equation by $u_1u_2\dots u_\phi$, we obtain 
\begin{eqnarray*}
x_1x_2\dots x_\phi & \equiv &a^\phi x_1x_2\dots x_\phi\mod n\\
x_1x_2\dots x_\phi u_1u_2\dots u_\phi & \equiv &a^\phi x_1x_2\dots x_\phi u_1u_2\dots u_\phi\mod n\\
(x_1u_1)(x_2u_2)\dots (x_\phi u_\phi) & \equiv & a^\phi(x_1u_1)(x_2u_2)\dots (x_\phi u_\phi)\mod n\\
1 & \equiv &a^\phi \mod n
\end{eqnarray*}
\end{proof}

\end{document}