mathlib documentation

number_theory.legendre_symbol.quadratic_reciprocity

Legendre symbol and quadratic reciprocity. #

This file contains results about quadratic residues modulo a prime number.

We define the Legendre symbol $\Bigl(\frac{a}{p}\Bigr)$ as legendre_sym p a. Note the order of arguments! The advantage of this form is that then legendre_sym p is a multiplicative map.

The Legendre symbol is used to define the Jacobi symbol, jacobi_sym a b, for integers a and (odd) natural numbers b, which extends the Legendre symbol.

Main results #

We prove the law of quadratic reciprocity, see legendre_sym.quadratic_reciprocity and legendre_sym.quadratic_reciprocity', as well as the interpretations in terms of existence of square roots depending on the congruence mod 4, zmod.exists_sq_eq_prime_iff_of_mod_four_eq_one, and zmod.exists_sq_eq_prime_iff_of_mod_four_eq_three.

We also prove the supplementary laws that give conditions for when -1 or 2 (or -2) is a square modulo a prime p: legendre_sym.at_neg_one and zmod.exists_sq_eq_neg_one_iff for -1, legendre_sym.at_two and zmod.exists_sq_eq_two_iff for 2, legendre_sym.at_neg_two and zmod.exists_sq_eq_neg_two_iff for -2.

Implementation notes #

The proofs use results for quadratic characters on arbitrary finite fields from number_theory.legendre_symbol.quadratic_char, which in turn are based on properties of quadratic Gauss sums as provided by number_theory.legendre_symbol.gauss_sum.

Tags #

quadratic residue, quadratic nonresidue, Legendre symbol, quadratic reciprocity

theorem zmod.euler_criterion_units (p : ) [fact (nat.prime p)] (x : (zmod p)ˣ) :
(∃ (y : (zmod p)ˣ), y ^ 2 = x) x ^ (p / 2) = 1

Euler's Criterion: A unit x of zmod p is a square if and only if x ^ (p / 2) = 1.

theorem zmod.euler_criterion (p : ) [fact (nat.prime p)] {a : zmod p} (ha : a 0) :
is_square a a ^ (p / 2) = 1

Euler's Criterion: a nonzero a : zmod p is a square if and only if x ^ (p / 2) = 1.

theorem zmod.pow_div_two_eq_neg_one_or_one (p : ) [fact (nat.prime p)] {a : zmod p} (ha : a 0) :
a ^ (p / 2) = 1 a ^ (p / 2) = -1

If a : zmod p is nonzero, then a^(p/2) is either 1 or -1.

Definition of the Legendre symbol and basic properties #

def legendre_sym (p : ) [fact (nat.prime p)] (a : ) :

The Legendre symbol of a : ℤ and a prime p, legendre_sym p a, is an integer defined as

  • 0 if a is 0 modulo p;
  • 1 if a is a nonzero square modulo p
  • -1 otherwise.

Note the order of the arguments! The advantage of the order chosen here is that legendre_sym p is a multiplicative function ℤ → ℤ.

Equations
theorem legendre_sym.eq_pow (p : ) [fact (nat.prime p)] (a : ) :
(legendre_sym p a) = a ^ (p / 2)

We have the congruence legendre_sym p a ≡ a ^ (p / 2) mod p.

theorem legendre_sym.eq_one_or_neg_one (p : ) [fact (nat.prime p)] {a : } (ha : a 0) :

If p ∤ a, then legendre_sym p a is 1 or -1.

theorem legendre_sym.eq_neg_one_iff_not_one (p : ) [fact (nat.prime p)] {a : } (ha : a 0) :
theorem legendre_sym.eq_zero_iff (p : ) [fact (nat.prime p)] (a : ) :

The Legendre symbol of p and a is zero iff p ∣ a.

@[simp]
theorem legendre_sym.at_zero (p : ) [fact (nat.prime p)] :
@[simp]
theorem legendre_sym.at_one (p : ) [fact (nat.prime p)] :
@[protected]
theorem legendre_sym.mul (p : ) [fact (nat.prime p)] (a b : ) :

The Legendre symbol is multiplicative in a for p fixed.

@[simp]

The Legendre symbol is a homomorphism of monoids with zero.

Equations
theorem legendre_sym.sq_one (p : ) [fact (nat.prime p)] {a : } (ha : a 0) :
legendre_sym p a ^ 2 = 1

The square of the symbol is 1 if p ∤ a.

theorem legendre_sym.sq_one' (p : ) [fact (nat.prime p)] {a : } (ha : a 0) :
legendre_sym p (a ^ 2) = 1

The Legendre symbol of a^2 at p is 1 if p ∤ a.

@[protected]
theorem legendre_sym.mod (p : ) [fact (nat.prime p)] (a : ) :

The Legendre symbol depends only on a mod p.

theorem legendre_sym.eq_one_iff (p : ) [fact (nat.prime p)] {a : } (ha0 : a 0) :

When p ∤ a, then legendre_sym p a = 1 iff a is a square mod p.

theorem legendre_sym.eq_one_iff' (p : ) [fact (nat.prime p)] {a : } (ha0 : a 0) :

legendre_sym p a = -1 iff a is a nonsquare mod p.

theorem legendre_sym.card_sqrts (p : ) [fact (nat.prime p)] (hp : p 2) (a : ) :
({x : zmod p | x ^ 2 = a}.to_finset.card) = legendre_sym p a + 1

The number of square roots of a modulo p is determined by the Legendre symbol.

The value of the Legendre symbol at -1 #

See jacobi_sym.at_neg_one for the corresponding statement for the Jacobi symbol.

theorem legendre_sym.at_neg_one {p : } [fact (nat.prime p)] (hp : p 2) :

legendre_sym p (-1) is given by χ₄ p.

theorem zmod.exists_sq_eq_neg_one_iff {p : } [fact (nat.prime p)] :
is_square (-1) p % 4 3

-1 is a square in zmod p iff p is not congruent to 3 mod 4.

theorem zmod.mod_four_ne_three_of_sq_eq_neg_one {p : } [fact (nat.prime p)] {y : zmod p} (hy : y ^ 2 = -1) :
p % 4 3
theorem zmod.mod_four_ne_three_of_sq_eq_neg_sq' {p : } [fact (nat.prime p)] {x y : zmod p} (hy : y 0) (hxy : x ^ 2 = -y ^ 2) :
p % 4 3

If two nonzero squares are negatives of each other in zmod p, then p % 4 ≠ 3.

theorem zmod.mod_four_ne_three_of_sq_eq_neg_sq {p : } [fact (nat.prime p)] {x y : zmod p} (hx : x 0) (hxy : x ^ 2 = -y ^ 2) :
p % 4 3

The value of the Legendre symbol at 2 and -2 #

See jacobi_sym.at_two and jacobi_sym.at_neg_two for the corresponding statements for the Jacobi symbol.

theorem legendre_sym.at_two {p : } [fact (nat.prime p)] (hp : p 2) :

legendre_sym p 2 is given by χ₈ p.

theorem legendre_sym.at_neg_two {p : } [fact (nat.prime p)] (hp : p 2) :

legendre_sym p (-2) is given by χ₈' p.

theorem zmod.exists_sq_eq_two_iff {p : } [fact (nat.prime p)] (hp : p 2) :
is_square 2 p % 8 = 1 p % 8 = 7

2 is a square modulo an odd prime p iff p is congruent to 1 or 7 mod 8.

theorem zmod.exists_sq_eq_neg_two_iff {p : } [fact (nat.prime p)] (hp : p 2) :
is_square (-2) p % 8 = 1 p % 8 = 3

-2 is a square modulo an odd prime p iff p is congruent to 1 or 3 mod 8.

The Law of Quadratic Reciprocity #

See jacobi_sym.quadratic_reciprocity and variants for a version of Quadratic Reciprocity for the Jacobi symbol.

theorem legendre_sym.quadratic_reciprocity {p q : } [fact (nat.prime p)] [fact (nat.prime q)] (hp : p 2) (hq : q 2) (hpq : p q) :
legendre_sym q p * legendre_sym p q = (-1) ^ (p / 2 * (q / 2))

The Law of Quadratic Reciprocity: if p and q are distinct odd primes, then (q / p) * (p / q) = (-1)^((p-1)(q-1)/4).

theorem legendre_sym.quadratic_reciprocity' {p q : } [fact (nat.prime p)] [fact (nat.prime q)] (hp : p 2) (hq : q 2) :
legendre_sym q p = (-1) ^ (p / 2 * (q / 2)) * legendre_sym p q

The Law of Quadratic Reciprocity: if p and q are odd primes, then (q / p) = (-1)^((p-1)(q-1)/4) * (p / q).

theorem legendre_sym.quadratic_reciprocity_one_mod_four {p q : } [fact (nat.prime p)] [fact (nat.prime q)] (hp : p % 4 = 1) (hq : q 2) :

The Law of Quadratic Reciprocity: if p and q are odd primes and p % 4 = 1, then (q / p) = (p / q).

theorem legendre_sym.quadratic_reciprocity_three_mod_four {p q : } [fact (nat.prime p)] [fact (nat.prime q)] (hp : p % 4 = 3) (hq : q % 4 = 3) :

The Law of Quadratic Reciprocity: if p and q are primes that are both congruent to 3 mod 4, then (q / p) = -(p / q).

theorem zmod.exists_sq_eq_prime_iff_of_mod_four_eq_one {p q : } [fact (nat.prime p)] [fact (nat.prime q)] (hp1 : p % 4 = 1) (hq1 : q 2) :

If p and q are odd primes and p % 4 = 1, then q is a square mod p iff p is a square mod q.

theorem zmod.exists_sq_eq_prime_iff_of_mod_four_eq_three {p q : } [fact (nat.prime p)] [fact (nat.prime q)] (hp3 : p % 4 = 3) (hq3 : q % 4 = 3) (hpq : p q) :

If p and q are distinct primes that are both congruent to 3 mod 4, then q is a square mod p iff p is a nonsquare mod q.