%! TEX root = NT.tex
% vim: tw=50
% 18/10/2023 10AM

\newpage
\section{Quadratic Reciprocity}

\begin{flashcard}[quadratic-residue-defn]
\begin{definition}[Quadratic residue]
  \glsnoundefn{qr}{quadratic residue}{quadratic
  residues}
  \glsnoundefn[qr]{nqr}{quadratic
  non-residue}{quadratic non-residues}
  \glsnoundefn[qr]{nr}{non-residue}{non-residues}
  \cloze{
  Let $p$ be a \gls{prime}, $a \in \ZZ$. We say $a \bmod
  p$ is a \emph{quadratic residue} if the equation
  $X^2 = a$ has a \gls{eq_sol} in $\ZZ / p\ZZ$. If
  there's no \gls{eq_sol}, we say $a$ is a \emph{quadratic
  non-residue}.
  }
\end{definition}
\end{flashcard}

\begin{example*}
  $p = 7$:
  \begin{center}
    \begin{tabular}{c|ccccccc}
      $x$ & $0$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ \\
      \hline
      $x^2 \bmod 7$ & $0$ & $1$ & $4$ & $2$ & $2$ & $4$ & $1$
    \end{tabular}
  \end{center}
  So the \glspl{qr} \gls{modulo} $7$ are $1$,
  $2$ and $4$. The \glspl{nr} are $3$, $5$ and
  $6$.
\end{example*}

\begin{flashcard}[number-of-qrs-mod-p-lemma]
\begin{lemma}
  If $p$ is an odd \gls{prime}, then there are \cloze{$\frac{p
  - 1}{2}$} \gls{qr} \gls{modulo} $p$, and
  \cloze{$\frac{p - 1}{2}$} \glspl{nr}.
\end{lemma}

\begin{proof}
  \cloze{
  Consider $\theta : \multbrack(\ZZ / p\ZZ) \to
  \multbrack(\ZZ
  / p\ZZ)$, $\theta(x) = x^2$. Want to show
  that the image of $\theta$ contains exactly
  $\frac{p - 1}{2}$ elements. Enough to show that
  each fibre of $\theta$ contains exactly $2$
  elements. If $x \in \multbrack(\ZZ / p\ZZ)$, then
  $\theta(x) = \theta(-x)$. If $x, y \in
  \multbrack(\ZZ /
  p\ZZ)$, $\theta(x) = x^2 = y^2 =
  \theta(y)$, then $(x + y)(x - y) \equiv 0
  \pmod{p}$, so $x \equiv y \pmod{p}$ or $x \equiv
  -y \pmod{p}$, as $p$ is \gls{prime}, so every fibre
  contains exactly $2$ elements as desired.
  }
\end{proof}
\end{flashcard}

\begin{flashcard}[legendre-symbol-notation]
\begin{notation*}[Legendre symbol]
  \glsnoundefn{leg_symb}{Legendre symbol}{Legendre
  symbols}
  \glssymboldefn{leg_symb}{Legendre symbol}{(ap)}
  \cloze{
  If $p$ is an odd \gls{prime}, $a \in \ZZ$, then the
  \emph{Legendre symbol} is
  \[ \legendre{a}{p} = \begin{cases}
    0 & p \divides a \\
    1 & p \ndivides a, \text{$a \bmod p$ is a
    \gls{qr}} \\
    -1 & p \ndivides a, \text{$a \bmod p$ is a
    \gls{nqr}}
  \end{cases} \]
  }
\end{notation*}
\end{flashcard}

\begin{flashcard}[eulers-criterion-prop]
\begin{proposition}[Euler's Criterion]
  \label{eulers_criterion}
  \cloze{
  If $p$ is an odd \gls{prime}, $a \in \ZZ$, then
  $a^{\frac{p - 1}{2}} \equiv \legendre{a}{p}
  \pmod{p}$.
  }
\end{proposition}

\begin{proof}
  \cloze{
  If $p \divides a$, this holds by definition, so
  let's assume $p \ndivides a$. Then
  \nameref{euler_fermat_thm} says
  \[ (a^{\frac{p - 1}{2}})^2 = a^{p - 1} \equiv 1
  \pmod{p} \implies a^{\frac{p - 1}{2}} \equiv \pm
  1 \pmod{p} \]
  If $a$ is a \gls{qr}, then $a \equiv
  x^2$ for some $x \in \ZZ$, hence $a^{\frac{p -
  1}{2}} \equiv x^{p - 1} \equiv 1 \pmod{p}$. So
  $a^{\frac{p - 1}{2}} \equiv \legendre{a}{p}
  \pmod{p}$ in this case.

  By \nameref{lagranges_thm}, the equation
  $X^{\frac{p - 1}{2}} = 1$ has at most $\frac{p -
  1}{2}$ \glspl{eq_sol} in $\ZZ / p\ZZ$. We've shown
  that the \glspl{qr} give $\frac{p -
  1}{2}$ \glspl{eq_sol}. If $a$ is a \gls{nqr},
  then we must have $a^{\frac{p -
  1}{2}} \equiv -1 \pmod{p}$, i.e. $a^{\frac{p -
  1}{2}} \equiv \legendre{a}{p} \pmod{p}$.
  }
\end{proof}
\end{flashcard}

\begin{flashcard}[legendre-multiplicative-coro]
\begin{corollary}
  If $a, b \in \ZZ$, then
  \[ \legendre{ab}{p} = \legendre{a}{p}
  \legendre{b}{p} .\]
\end{corollary}

\begin{proof}
  \cloze{
  For $p$ odd, $0$, $1$ and $-1$ lie in distinct
  congruence classes \gls{modulo} $p$. So it's enough to
  show that $\LHS \equiv \RHS \pmod{p}$. But
  \[ \LHS \equiv (ab)^{\frac{p - 1}{2}} \pmod{p},
  \qquad \RHS \equiv a^{\frac{p - 1}{2}} b^{\frac{p
  - 1}{2}} \pmod{p} \qedhere \]
  }
\end{proof}
\end{flashcard}

\begin{remark*}
  If we use $\mathrm{QR}$ to represent \glspl{qr}
  and $\mathrm{NQR}$ to represent
  \glspl{nqr}, we have
  \[ \mathrm{QR} \times \mathrm{QR} = \mathrm{QR},
  \qquad \mathrm{NQR} \times \mathrm{NQR} =
  \mathrm{QR}, \qquad \mathrm{NQR} \times
  \mathrm{QR} = \mathrm{NQR} .\]
\end{remark*}

\begin{flashcard}[minus-one-legendre-symbol]
\begin{corollary}
  \[ \legendre{-1}{p} = \cloze{(-1)^{\frac{p -
  1}{2}} = \begin{cases}
    1 & p \equiv 1 \pmod{4} \\
    -1 & p \equiv 3 \pmod{4}
  \end{cases}} \]
\end{corollary}
\end{flashcard}

\begin{flashcard}[modulo-angle-brackets-notation]
\begin{notation*}
  \glssymboldefn{gmod_brackets}{Gauss angle
  brackets}{a}
  If $p$ is an odd \gls{prime}, $a \in \ZZ$, then
  $\langle a \rangle$ denotes \cloze{the unique
  integer such that $a \equiv \langle a \rangle
  \pmod{p}$ and $-\frac{p}{2} < \langle a \rangle
  \frac{p}{2}$. (So $\langle a \rangle \in \left\{
  -\frac{p - 1}{2}, -\frac{p - 3}{2}, \ldots,
  \frac{p - 1}{2} \right\}$).}
\end{notation*}
\end{flashcard}

\begin{flashcard}[Gauss-s-lemma]
\begin{lemma}[Gauss's Lemma]
  \label{gausss_lemma}
  \cloze{
  Let $p$ be an odd \gls{prime}, $a \in \ZZ$, $p \nmid
  a$. Then $\legendre{a}{p} = (-1)^\mu$, where
  \[ \mu = \#\{i \in \ZZ \mid 0 < i < \frac{p}{2}
  \text{ and $\gmod{ai} < 0$}\} .\]
  }
\end{lemma}

\fcscrap{\vspace{-1em}

\textbf{Inspiration for proof:} One way of proving
\nameref{fermats_little_thm} is to consider the
action of $\times a$ on $1, \ldots, p - 1 \bmod
p$. Multiplication by $a$ will permute these, so
\begin{align*}
  \prod_{i = 1}^{p - 1} \equiv \prod_{i = 1}^{p -
  1} ai \pmod{p}
  &\implies (p - 1)! \equiv a^{p - 1} (p - 1)!
  \pmod{p} \\
  &\implies a^{p - 1} \equiv 1 \pmod{p}
\end{align*}
}

\begin{proof}
  \cloze{
  We consider
  \[ \prod_{i = 1}^{\frac{p - 1}{2}} ai =
  a^{\frac{p - 1}{2}} \prod_{i = 1}^{\frac{p -
  1}{2}} i = a^{\frac{p - 1}{2}} \left( \frac{p -
  1}{2} \right)! \]
  We also have
  \[ \prod_{i = 1}^{\frac{p - 1}{2}} ai \equiv
  \prod_{i = 1}^{\frac{p - 1}{2}} \gmod{ai}
  \pmod{p} .\]
  For each $i = 1, \ldots, \frac{p - 1}{2}$,
  there's a unique sign $\eps_i \in \{\pm 1\}$
  such that $\eps_i \gmod{ai} > 0$.

  \textbf{Claim:} The set $\left\{\eps \gmod{ai}
  \mid i = 1, \ldots, \frac{p -
  1}{2}\right\} = \left\{ 1, 2, \ldots, \frac{p -
  1}{2} \right\}$.

  Proof of claim: $\LHS \subset \RHS$ as $0 <
  \eps_i \gmod{ai} < \frac{p}{2}$. We
  need to show that if $i \neq j$, then $\eps_i
  \gmod{ai} \neq \eps_j \gmod{aj}$.
  If $\eps_i \gmod{ai} = \eps_j
  \gmod{aj}$, then
  \[ ai \equiv \eps_i \eps_j a_j \pmod{p} \implies
  i \equiv \pm j \pmod{p} .\]
  By assumption, $i, j \in \left\{ 1, \ldots,
  \frac{p - 1}{2} \right\}$. If $i \equiv \pm j
  \pmod{p}$ then we must have $i \equiv j
  \pmod{p}$, so $i = j$.

  Putting this together, we find
  \begin{align*}
    \prod_{i = 1}^{\frac{p - 1}{2}} \eps_i
    \gmod{ai}
    &\equiv \prod_{i = 1}^{\frac{p - 1}{2}}
    (\eps_i) \cdot \prod_{i = 1}^{\frac{p - 1}{2}}
    ai \\
    &= \prod_{i = 1}^{\frac{p - 1}{2}} (\eps_i)
    \cdot a^{\frac{p - 1}{2}} \cdot \left( \frac{p
    - 1}{2} \right)!
  \end{align*}
  and
  \begin{align*}
    \prod_{i = 1}^{\frac{p - 1}{2}} \eps_i
    \gmod{ai} \equiv \prod_{i = 1}^{\frac{p -
    1}{2}} i \equiv \left( \frac{p - 1}{2}
    \right)! \pmod{p}
    &\implies \left( \prod_{i = 1}^{\frac{p -
    1}{2}} \eps_i \right) \cdot a^{\frac{p -
    1}{2}} \equiv 1 \pmod{p} \\
    &\implies \prod_{i = 1}^{\frac{p - 1}{2}}
    \eps_i \equiv \legendre{a}{p} \pmod{p} \\
    &\implies (-1)^\mu = \legendre{a}{p}
    \qedhere
  \end{align*}
  }
\end{proof}
\end{flashcard}

\begin{example*}
  We can compute $\legendre{-1}{p}$ using
  \nameref{gausss_lemma}: $\legendre{-1}{p} =
  (-1)^\mu$ where
  \[ \mu = \# \left\{ 1 \le i \le \frac{p - 1}{2}
  ~\bigg|~ \gmod{-i} < 0\right\} = \#
  \left\{ 1 \le i \le \frac{p - 1}{2} ~\bigg|~ -i <
  0\right\} = \frac{p - 1}{2} \]
\end{example*}

\begin{example*}
  Next compute $\legendre{2}{p} = (-1)^\mu$, where
  \[ \mu = \# \left\{ 0 < i < \frac{p}{2} ~\bigg|~
  \gmod{2i} < 0\right\} .\]
  If $i \in \ZZ$ and $0 < i < \frac{p}{4}$, then
  $0 < 2i < \frac{p}{2}$, so $\gmod{2i} =
  2i > 0$. If $i \in \ZZ$ and $\frac{p}{4} < i <
  \frac{p}{2}$, then $\frac{p}{2} < 2i < p$, so
  $-\frac{p}{2} < 2i - p < 0$, so $\gmod{2i}
  = 2i - p < 0$.

  So
  \[ \mu = \# \left\{ i \in \ZZ ~\bigg|~
  \frac{p}{4} < i < \frac{p}{2} \right\} =
  \left\lfloor \frac{p}{2} \right\rfloor -
  \left\lfloor \frac{p}{4} \right\rfloor \]
  where if $x \in \RR$, $\left\lfloor x
  \right\rfloor = \sup\{n \in \ZZ \mid n \le x\}$.
  Then $(-1)^\mu = \legendre{2}{p}$ depends on $p
  \bmod 8$.
  \begin{center}
    \renewcommand{\arraystretch}{1.3}
    \begin{tabular}{c|c|c|c|c|c|c}
      $p$
      & $\frac{p}{2}$
      & $\left\lfloor \frac{p}{2} \right\rfloor$
      & $\frac{p}{4}$
      & $\left\lfloor \frac{p}{4} \right\rfloor$
      & $\mu$
      & $(-1)^\mu$ \\
      \hline
      $8k + 1$ & $4k + \half$ & $4k$ & $2k + \frac{1}{4}$ & $2k$ & $2k$ & $1$ \\
      $8k + 3$ & $4k + \frac{3}{2}$ & $4k + 1$ & $2k + \frac{3}{4}$ & $2k$ & $2k + 1$ & $-1$ \\
      $8k + 5$ & $4k + \frac{5}{2}$ & $4k + 2$ & $2k + \frac{5}{4}$ & $2k + 1$ & $2k + 1$ & $-1$ \\
      $8k + 7$ & $4k + \frac{7}{2}$ & $4k + 3$ & $2k + \frac{7}{4}$ & $2k + 1$ & $2k + 2$ & $1$
    \end{tabular}
  \end{center}
  \[ \implies \legendre{2}{p} = \begin{cases}
    1 & p \equiv 1, 7 \pmod{8} \\
    -1 & p \equiv 3, 5 \pmod{8}
  \end{cases} \]
\end{example*}
