For an odd prime p and integer a, the Legendre symbol(pa) (also written legendreSympa in Lean) is defined as
(pa)=⎩⎨⎧01−1p∣aa is a QR mod pa is a QNR mod p
Euler's criterion gives a computable formula: for p∤a,
(pa)≡a(p−1)/2(modp)
In Mathlib this is legendreSym.eq_pow: the integer value of legendreSympa cast into Z/pZ equals (amodp)p/2.
Visualization
Legendre symbol (7a) for p=7, a=1,…,6:
a
a3mod7
(7a)
1
1
+1
2
1
+1 (2 is QR: 32=9≡2)
3
6 ≡−1
−1 (3 is QNR)
4
1
+1 (4 =22)
5
6 ≡−1
−1 (5 is QNR)
6
6 ≡−1
−1 (6 is QNR)
Check: QRs mod 7 are {1,2,4} — three values, which is (7−1)/2=3. The product of all six symbols is (−1)3=−1.
Proof Sketch
The group (Z/pZ)× is cyclic of order p−1 by Primitive RootsPrimitive Rootsg is a primitive root mod p⟺{g0,g1,…,gp−2}=(Z/pZ)×A primitive root mod p is a generator of the cyclic group (Z/pZ)*, existing for every prime pRead more →. Let g be a generator; write a=gk.
a is a QR iff k is even. The map a↦a(p−1)/2 sends gk to gk(p−1)/2. Since gp−1=1, this is 1 when k is even and −1 when k is odd.
This coincides with the Legendre symbol, establishing Euler's criterion.
Multiplicativity (pab)=(pa)(pb) follows from the same power-map argument.
Connections
The Legendre symbol is the building block of Quadratic ReciprocityQuadratic Reciprocity(qp)(pq)=(−1)2p−1⋅2q−1Relationship between solvability of quadratic congruences for two odd primesRead more →, which relates (qp) and (pq) for distinct odd primes. The generalisation to composite moduli is the Jacobi SymbolJacobi Symbol(na)=i∏(pia)eiThe Jacobi symbol generalises the Legendre symbol to composite odd moduliRead more →.
Lean4 Proof
/-- Euler's criterion in Mathlib: the cast of `legendreSym p a` into `ZMod p`
equals `(a : ZMod p) ^ (p / 2)`. -/theorem legendre_euler_criterion (p : ℕ) [Fact p.Prime] (a : ℤ) :
(legendreSym p a : ZMod p) = (a : ZMod p) ^ (p / 2) :=
legendreSym.eq_pow p a