Mathlib theorem · Existing formal mathematics

Existing in Mathlib · Number theory

Quadratic Reciprocity

For two distinct odd primes p and q, whether q is a square modulo p and whether p is a square modulo q are linked. Their Legendre symbols multiply to a sign determined by the parities encoded by p divided by 2 and q divided by 2.

Exact theorem

Exact Mathlib statement

theorem legendreSym.quadratic_reciprocity {p q : ℕ} [Fact (Nat.Prime p)] [Fact (Nat.Prime q)] (hp : p ≠ 2) (hq : q ≠ 2) (hpq : p ≠ q) : legendreSym q ↑p * legendreSym p ↑q = (-1) ^ (p / 2 * (q / 2))

The theorem at a glance

Quadratic Reciprocity at a glance

A visual guide to the theorem's hypotheses, structure, and conclusion; the exact statement gives the formal detail.

The reciprocal Legendre-symbol product has one exact parity-controlled sign, with p divided by 2 and q divided by 2 interpreted by natural-number floor division. Explanatory diagram.
Detailed visual description

Green and blue prime medallions face each other across reciprocal arcs. A central formula gives the Legendre-symbol product and its sign exponent. Below it, the poster explicitly says natural division rounds down and separates the both-3-mod-4 minus case from the otherwise-plus case.

Statement structure

Statement and scope

Statement map for Quadratic ReciprocityFor distinct odd primes, the two Legendre symbols are related by the quadratic-reciprocity sign. Claim boundary: This page states Mathlib's Legendre-symbol formulation for primes supplied through Fact instances, with explicit exclusions p ≠ 2, q ≠ 2, and p ≠ q. It does not present the Jacobi-symbol variants or remove those hypotheses. The pinned upstream declaration is legendreSym.quadratic_reciprocity. The complete formal statement is available in the Exact Mathlib statement section.Mathematical readingFor distinct odd primes,the two Legendre symbolsare related by thequadratic-reciprocitysign.Claim boundaryThis page statesMathlib'sLegendre-symbolformulation for primessupplied through Factinstances, with explicitexclusions p ≠ 2, q ≠ 2,and p ≠ q. It does notpresent theJacobi-symbol variantsor remove thosehypotheses.Pinned declarationmathlib ·legendreSym.quadratic_reciprocityStatement map for Quadratic ReciprocityFor distinct odd primes, the two Legendre symbols are related by the quadratic-reciprocity sign. Claim boundary: This page states Mathlib's Legendre-symbol formulation for primes supplied through Fact instances, with explicit exclusions p ≠ 2, q ≠ 2, and p ≠ q. It does not present the Jacobi-symbol variants or remove those hypotheses. The pinned upstream declaration is legendreSym.quadratic_reciprocity. The complete formal statement is available in the Exact Mathlib statement section.Mathematical readingFor distinct odd primes,the two Legendre symbolsare related by thequadratic-reciprocitysign.Claim boundaryThis page statesMathlib'sLegendre-symbolformulation for primessupplied through Factinstances, with explicitexclusions p ≠ 2, q ≠ 2,and p ≠ q. It does notpresent theJacobi-symbol variantsor remove thosehypotheses.Pinned declarationmathlib ·legendreSym.quadratic_reciprocity

Read the exact Mathlib declaration

This map summarizes the statement's structure; the exact Mathlib declaration remains authoritative.

Quadratic residue information in two odd distinct primes is linked in both directions, with a parity-controlled sign. Explanatory scientific diagram.
Detailed visual description

Two large symmetric residue circles face each other across reciprocal gold arrows. Smaller paired circles below show one aligned exchange and one restrained red reversal cue, suggesting the parity-dependent sign without rendering notation.

Why it matters

A mathematical landmark

Quadratic reciprocity is a central symmetry law of elementary number theory. It turns one quadratic-residue question into another, with an exact sign correction.

Proof architecture

How quadratic characters yield reciprocity

4 curated stages

Mathlib's checked route prepares odd-prime field inputs, invokes its finite-field quadratic-character reciprocity identity, cancels the squared nonzero character factor, and evaluates the remaining parity signs.

These source-anchored stages explain the retained Mathlib proof route. They are generated explanations, not proof evidence or an extracted Lean proof-term dependency graph.

  1. Prepare the odd-prime inputs

    The non-two hypotheses supply the oddness and characteristic facts required by the quadratic-character identity.

    Odd p ∧ Odd q ∧ ringChar (ZMod q) ≠ 2

    Primality together with p ≠ 2 and q ≠ 2 supplies oddness for both primes, while the ZMod characteristic calculation supplies the non-characteristic-two input used later. The distinctness hypothesis is retained for the cross-field nonzero argument.

  2. Invoke the cross-field quadratic-character identity

    Mathlib’s quadraticChar_odd_prime identifies the quadratic character of q in ZMod p with the quadratic character of χ₄(p) · p in ZMod q.

    h := quadraticChar_odd_prime ...

    At stage 2, the proof obtains h : quadraticChar (ZMod p) q = quadraticChar (ZMod q) (χ₄ p * p) after rewriting the cardinality of ZMod p as p. A cobalt cross-field bead enters the forest-green field wheel; on the other side, a forest-green bead pairs with the antique-gold χ₄ motif before entering the cobalt field wheel. Matching gold result strands meet at a central balance. No Legendre-symbol product, square cancellation, parity evaluation, or final reciprocity conclusion is present.

  3. Normalize and cancel the square

    Unfolding the Legendre symbols exposes multiplicative quadratic characters, and the squared nonzero character factor collapses to one.

    quadraticChar (ZMod q) p ^ 2 = 1

    The final rewrite chain expands both Legendre symbols, aligns the natural and integer casts, substitutes the reciprocity relation, rotates the product, and uses quadraticChar_sq_one with prime_ne_zero. This algebraic cancellation leaves only parity-controlled sign factors.

  4. Evaluate the reciprocity sign

    Oddness evaluates the two character signs and leaves exactly the parity-controlled sign in quadratic reciprocity.

    legendreSym q p * legendreSym p q = (-1) ^ (p / 2 * (q / 2))

    The proof uses χ₄'s odd-input evaluation for p and q together with quadraticChar_neg_one in ZMod q. The exponent rewrites combine the two parity contributions and close the exact Legendre-symbol product stated by quadratic_reciprocity.

ProofAtlas record

What has been checked

Upstream indexedPinned source bytes verified locally
Locally reproducedExact upstream declaration replayed
Reviewed pageCurrent public presentation reviewed
Accepted Atlas resultNot recorded for the preferred artifact

Mathlib is the source of the theorem; the local Lean replay and page review are separate.

Claim boundary

No new theorem is claimed

This page states Mathlib's Legendre-symbol formulation for primes supplied through Fact instances, with explicit exclusions p ≠ 2, q ≠ 2, and p ≠ q. It does not present the Jacobi-symbol variants or remove those hypotheses.

Source and local evidence

Where the theorem comes from

Existing declaration
legendreSym.quadratic_reciprocity in mathlib
Relationship
The checked artifact is the upstream declaration itself
Local Lean evidence
artifact.library.mathlib.quadratic-reciprocity.v001
Source
Open the pinned upstream reference