# Summary

In today's class we discussed some of the basic properties of quadratic residues. We then uncovered the Legendre symbol, exploring its connection to Euler's Criterion and using this to set a game-plan for answering the general question: when is a number *a* a square modulo a prime *p*?

# Announcements

Just as a reminder, we mentioned at the beginning of class that your project contracts are due this coming Friday, and that your project topics should be submitted by Monday, March 16th.

# Some Basic Properties of Quadratic Residues

Last class period we introduced quadratic residues, so we started today's class by computing the squares of all the residues mod 17 to determine what the quadratic residues (and non-residues) mod 17 were.

n | n^{2} |
n | n^{2} |
n | n^{2} |
---|---|---|---|---|---|

1 | 1 | 7 | $49 \equiv -2$ | 13 | $(-4)^2 \equiv -1$ |

2 | 4 | 8 | $64 \equiv 13 \equiv -4$ | 14 | $(-3)^2 \equiv 9$ |

3 | 9 | 9 | $(-8)^2 \equiv -4$ | 15 | $(-2)^2 \equiv 4$ |

4 | $16 \equiv -1$ | 10 | $(-7)^2 \equiv -2$ | 16 | $(-1)^2 \equiv 1$ |

5 | $25 \equiv 8$ | 11 | $(-6)^2 \equiv 2$ | ||

6 | $36 \equiv 2$ | 12 | $(-5)^2 \equiv 8$ |

This means that the quadratic residues mod 17 are

- 1, 2, 4, 8, 9, 13, 15, 16

and the quadratic nonresidues mod 17 are

- 3, 5, 6, 7, 10, 11, 12, 14

With this table as our motivation, let's try to prove some general statements about quadratic residues. First, we'll count the number of solutions to equations of the form

(1)when $p \nmid n$.

Lemma: If

pis an odd prime and $p \nmid n$, then the equation $x^2 \equiv n \mod{p}$ has either 0 solutions or 2 solutions.

Proof: First, if *n* is a quadratic nonresidue, then by definition $x^2 \equiv n \mod{p}$ has no solutions.

Now if *n* is a quadratic residue, then by definition this means $x^2 \equiv n \mod{p}$ does have at least one solution. Let's choose one solution $x_0$. Notice that we then also have

so that $-x_0$ is also a solution. Furthermore, we know that $x_0 \not \equiv x_1 \mod{p}$, since otherwise we'd have $p \mid 2x_0$, implying either $p \mid 2$ (impossible since *p* is odd) or $p \mid x_0$ (impossible since this would mean $0 \equiv 0^2 \equiv x_0^2 \equiv n \mod{p}$, which is ruled out since $p\nmid n$ by hypothesis). So this means that $x_0,-x_0$ are distinct solutions to the equation.

Are there any more? If $x_1$ were some solution to $x^2 \equiv n \mod{p}$, then this would mean that

(3)This in turn implies that $p \mid x_0^2 - x_1^2 = (x_0-x_1)(x_0+x_1)$, and then Euclid's Lemma says that $p \mid x_0 - x_1$ or $p \mid x_0+x_1$. In the former case we'd have $x_1 \equiv x_0 \mod{p}$, whereas in the latter we'd have $x_1 \equiv -x_0 \mod{p}$. Hence we see that any solution is equivalent to one of the two we have already produced, and so there aren't any new solutions. This makes the total number of solutions in this case equal to 2. $\square$

From our example we also noticed two other things: first that the quadratic residues are given by the squares of the first $\frac{p-1}{2}$ residue classes, and second that the number of quadratic residues is the same as the number of quadratic non-residues. Let's try to prove these observations.

Lemma: The residue classes of $1^2, 2^2, 3^2,\cdots, \left(\frac{p-1}{2}\right)^2$ are distinct and give a complete list of the quadratic residues modulo

p.

Proof: First, notice that for any $1 \leq i \leq \frac{p-1}{2}$, the number $i^2$ is a quadratic residue modulo *p*: indeed, we can "see" that this is a square, and moreover cannot be divisible by *p* (since the number *i* isn't divisible by *p*). Hence the numbers $1^2, 2^2, \cdots, \left(\frac{p-1}{2}\right)^2$ are all quadratic residues.

Moreover we know that for any $\frac{p+1}{2} \leq j \leq p-1$, the number $j^2$ must occur in the list $1^2, 2^2, \cdots, \left(\frac{p-1}{2}\right)^2$. This is true because the number $p-j$ must have residue which sits in the list $1,2,\cdots, \frac{p-1}{2}$, and of course we know that

(4)So we only have to prove that all the numbers $1^2, 2^2, \cdots, \left(\frac{p-1}{2}\right)^2$ are distinct. So let *i* and *j* be distinct residues between 1 and $\frac{p-1}{2}$, and suppose that $i^2 \equiv j^2 \mod{p}$. We'll derive a contradiction from this assumption. Notice first that the given congruence implies $p \mid i^2-j^2 = (i-j)(i+j)$. Now Euclid's Lemma says that either $p \mid i-j$ or $p \mid i+j$. The former implies that $i \equiv j \mod{p}$, a possibility we've already ruled out by assuming *i* and *j* are distinct residues. Hence we must be in the case $p \mid i+j$. But notice that if *i* and *j* are taken as least non-negative residues, then we have

But if $i+j$ satisfy these inequalities, then it is impossible for $p \mid i+j$. This is a contradiction, and so we conclude that $i^2 \equiv j^2 \mod{p}$ is impossible. $\square$

As a consequence of this result, we verify our second observation.

Corollary: There are precisely $\frac{p-1}{2}$ distinct quadratic residues and $\frac{p-1}{2}$ distinct quadratic nonresidues.

Proof: The previous lemma says that the numbers $1^2, 2^2, \cdots, \left(\frac{p-1}{2}\right)^2$ are distinct and give a complete list of the quadratic residues. Since there are $\frac{p-1}{2}$ numbers in this list, this means that there are $\frac{p-1}{2}$ quadratic residues.

How many quadratic nonresidues does this leave us with? There are *p-1* nonzero residues modulo *p*, and $\frac{p-1}{2}$ are quadratic residues. This means the remaining

are quadratic nonresidues. $\square$

# The Legendre Symbol

For the rest of this chapter, we're going to focus on the problem of giving good criteria to determine when a given nonzero residue class *a* is a square modulo *p*. Notice that right now, if I asked whether a given integer *a* is a square modulo *p*, the only way you could answer this question is by computing all the quadratic residues modulo *p* (i.e., by computing $1^2, 2^2, \cdots, \left(\frac{p-1}{2}\right)^2$) and seeing if *a* wound up on the list. This isn't a very efficient means for determining whether *a* is a residue or not.

We start by defining a "square indicator" function.

Definition: For an odd prime

pand $p \nmid a$, the Legendre symbol $\left(\frac{a}{p}\right)$ is defined as$\displaystyle \left(\frac{a}{p}\right) = \left\{\begin{array}{rl}1,&\mbox{ if } x^2 \equiv a \mod{p} \mbox{ has a solution,}\\-1 ,&\mbox{ if } x^2 \equiv a \mod{p} \mbox{ has no solutions.}\end{array}\right.$

**WARNING:** This notation could easily be confusing, as it looks as if the Legendre symbol has something to do with the fraction $\frac{a}{p}$. Hopefully in practice you won't be confused, since context will often tell you whether $\left(\frac{a}{p}\right)$ means the rational number "*a* divided by *p*" or the Legendre symbol "is *a* a square modulo *p*?" If you are ever confused, though, please ask so you can get things clarified sooner (rather than later).

#### Example: Legendre symbols modulo 17

We know that

(7)whereas

(8)since we already computed the quadratic residues (and nonresidues) mod 17. $\square$

It might seem that defining this Legendre symbol doesn't buy us anything, but we'll see that capturing the question "is this number a square mod *p*?" in the form of a function will have some real benefits.

## Euler's Criterion

To begin, though, we note that there are different ways for computing $\left(\frac{a}{p}\right)$ than simply computing all the quadratic residues mod *p*. The first real theorem in this direction is the following

Theorem (Euler's Criterion): For

pan odd prime and $p \nmid a$ we have$\displaystyle \left(\frac{a}{p}\right) \equiv a^{\frac{p-1}{2}} \mod{p}$

This theorem tells us that if we can compute the residue of $a^{\frac{p-1}{2}}\mod{p}$, then we can determine whether or not *a* is a square. Before we prove Euler's Criterion, though, let's see some consequences of this important result.

#### Example: Computing quadratic residue-ness through exponents

Let's see Euler's Criterion in action by determining whether 2 is a square modulo 19. For this, Euler's Criterion says that

(9)Now the left hand side is clearly $2^9 \mod{19}$, so we'll compute this power. For this, we'll use successive squaring. We have

(10)Hence we have

(11)Hence we have $\left(\frac{2}{19}\right) =-1$, and so we know that 2 is not a square mod 19. $\square$

## Is -1 a square?

One of the nicest applications of Euler's Criterion is that it gives us a fast way of checking whether -1 is a square modulo *p* based only on the congruence class of *p* mod 4.

Corollary: For an odd prime

p, we have$\left(\frac{-1}{p}\right) = \left\{\begin{array}{rl}1,&\mbox{ if } p \equiv 1 \mod{4}\\-1,& \mbox{ if }p \equiv 3 \mod{4}.\end{array}\right.$

Proof: Euler's criterion tells us that

(12)Hence to prove the corollary, we just need to show that $\frac{p-1}{2}$ is even whenever $p\equiv 1 \mod{4}$ and that $\frac{p-1}{2}$ is odd whenever $p \equiv 3 \mod{4}$. So let's try it out.

Suppose that $p \equiv 1 \mod{4}$. This means that $p = 4k+1$ for some integer *k*. Hence we have

But since the Legendre symbol is either 1 or -1, this congruence implies equality as integers.

On the other hand, suppose that $p \equiv 3 \mod{4}$. Then we have $p = 4k+3$ for some integer *k*, and we get

Again, since the Legendre symbol is either 1 or -1, this congruence tells us that we actually have an equality of integers. $\square$

# A Proof of Euler's Criterion

Now that we've seen some applications of Euler's Criterion, let's prove it. We'll break things down into 2 cases.

Case 1: *a* is a quadratic residue In this case, we have $\left(\frac{a}{p}\right) = 1$, and also that there is a solution to the equation $x^2 \equiv a \mod{p}$. Let $x_0$ be such a solution. Then we get

with the last equality coming from Fermat's Little Theorem. But we also know that $1 = \left(\frac{a}{p}\right)$, so the previous equation tells us that

(16)in this case.

Case 2: *a* is not a quadratic residue In this case, we know that $\left(\frac{a}{p}\right) = -1$, and we also know that there is no solution to $x^2 \equiv a \mod{p}$. Now we claim that in this case we can pair up the residues between 1 and *p-1* so that each pair has product *a*. To see that this is true, let *m* be any number between 1 and *p-1*. Now the equation $mx \equiv a \mod{p}$ has precisely one solution, since $(m,p) = 1$. Hence for each number between 1 and *p-1*, there is a unique "partner" n between 1 and *p-1* so that $mn = a \mod{p}$. Notice that $m \not \equiv n$ since this would imply that $m^2 \equiv a \mod{p}$, impossible since we're in the quadratic nonresidue case.

Now let's compute $\prod_{i=1}^{p-1}i$ in two ways. On the one hand, we know that

(17)because of Wilson's Theorem. On the other hand, since we can split the set $\{1,2,\cdots, p-1\}$ into $\frac{p-1}{2}$ pairs, each with product *a*, we get

Hence we get $a^{\frac{p-1}{2} \equiv -1 \mod{p}$, and since $\left(\frac{a}{p}\right) = -1$ in this case, we have

(19)$\square$

# Multiplicative behavior of the Legendre Symbol

Another bonus of Euler's Criterion is that it gives us a kind of "multiplicativity" for the Legendre symbol.

Lemma: For

pand odd prime and $p \nmid a,b$, we have

- $\left(\frac{a^2}{p}\right) = 1$;
- if $a \equiv b \mod{p}$, then $\left(\frac{a}{p}\right) = \left(\frac{b}{p}\right)$; and
- $\left(\frac{ab}{p}\right) = \left(\frac{a}{p}\right)\left(\frac{b}{p}\right)$.

Proof: The first two statements aren't hard to prove. The first just says that if you can visibly see that the top part of the Legendre symbol is a square, then you can immediately conclude that — well — it's a square. The second just says that the Legendre symbol is only defined for the congruence class of a given integer *a*; but of course we know this, because if $a \equiv b \mod{p}$ then the equation $x^2 \equiv a \mod{p}$ has solutions if and only if $x^2 \equiv b \mod{p}$ does.

So we have left to prove the last fact. For this, we'll use Euler's criterion twice (marked using $\star$ in the equation below):

(20)Notice that since the Legendre symbol is either 1 or -1, this congruence is enough to give us a *bona fide* equality of integers. $\square$

## Example: Computing the Legendre symbol of a random numbers

Suppose, as usual, that *p* is an odd prime and that $p \nmid a$. Let's write *a* as its prime factorization: $a = \pm 2^e p_1^{e_1}\cdots p_k^{e_k}$. Then the previous lemma tells us that

This means that if we want to know whether any given number *a* is a square mod *p*, it's enough for us to know whether -1 is a square mod *p*, and also to know which other primes *q* are squares mod *p*. $\square$

# A Final Note

To finish class I mentioned the following

Theorem: For an odd prime

p, we have$\displaystyle \left(\frac{2}{p}\right) = \left\{\begin{array}{rl}1, &\mbox{ if }p \equiv 1 \mbox{ or }p \equiv 7 \mod{8},\\-1, &\mbox{ if }p \equiv 3\mbox{ or }p \equiv 5 \mod{8}.\end{array}\right.$

We'll cover the proof next time in class, but I point it out because it will be a useful tool for answering questions on the homework.

[module Comments]