Mathlib theorem · Existing formal mathematics

Existing in Mathlib · Number theory

Fermat's Two-Square Classification

A natural number is a sum of two natural-number squares exactly when every prime factor leaving residue 3 modulo 4 occurs to an even exponent. Under Mathlib's valuation convention, zero is included.

Exact theorem

Exact Mathlib statement

theorem Nat.eq_sq_add_sq_iff {n : ℕ} : (∃ x y : ℕ, n = x ^ 2 + y ^ 2) ↔ ∀ q ∈ n.primeFactors, q % 4 = 3 → Even (padicValNat q n)

The theorem at a glance

Fermat's Two-Square Classification — the exact prime-factor criterion

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

Two-square representability is equivalent to even valuation at every prime factor congruent to 3 modulo 4. Explanatory diagram.
Detailed visual description

The classification connects a geometric-looking representation to arithmetic factor data. The source moves through the square-modulo-minus-one criterion and a square-times-squarefree decomposition before translating the condition into parity of prime exponents.

Statement structure

Statement and scope

Statement map for Fermat's Two-Square ClassificationA natural number is a sum of two squares exactly when all of its 3 mod 4 prime exponents are even. Claim boundary: This target indexes Mathlib's classification of all natural numbers representable as a sum of two natural-number squares. It is not only the prime case: representability is equivalent to every prime factor congruent to 3 modulo 4 occurring with even padicValNat exponent. The convention includes n = 0. The pinned upstream declaration is Nat.eq_sq_add_sq_iff. The complete formal statement is available in the Exact Mathlib statement section.Mathematical readingA natural number is asum of two squaresexactly when all of its3 mod 4 prime exponentsare even.Claim boundaryThis target indexesMathlib's classificationof all natural numbersrepresentable as a sumof two natural-numbersquares. It is not onlythe prime case:representability isequivalent to everyprime factor congruentto 3 modulo 4 occurringwith even padicValNatexponent. The conventionincludes n = 0.Pinned declarationmathlib ·Nat.eq_sq_add_sq_iffStatement map for Fermat's Two-Square ClassificationA natural number is a sum of two squares exactly when all of its 3 mod 4 prime exponents are even. Claim boundary: This target indexes Mathlib's classification of all natural numbers representable as a sum of two natural-number squares. It is not only the prime case: representability is equivalent to every prime factor congruent to 3 modulo 4 occurring with even padicValNat exponent. The convention includes n = 0. The pinned upstream declaration is Nat.eq_sq_add_sq_iff. The complete formal statement is available in the Exact Mathlib statement section.Mathematical readingA natural number is asum of two squaresexactly when all of its3 mod 4 prime exponentsare even.Claim boundaryThis target indexesMathlib's classificationof all natural numbersrepresentable as a sumof two natural-numbersquares. It is not onlythe prime case:representability isequivalent to everyprime factor congruentto 3 modulo 4 occurringwith even padicValNatexponent. The conventionincludes n = 0.Pinned declarationmathlib ·Nat.eq_sq_add_sq_iff

Read the exact Mathlib declaration

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

A natural number has a two-square representation exactly when every 3 mod 4 prime factor occurs with even exponent. Explanatory diagram.
Detailed visual description

One side assembles a number from two perpendicular square contributions. The other groups its prime-power factors by residue modulo four, pairing every factor from the 3 mod 4 class while leaving the other classes unrestricted.

Why it matters

A mathematical landmark

The two-square theorem is a model example of local-to-global arithmetic: a concrete additive representation is governed exactly by parity conditions in the prime factorization.

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 target indexes Mathlib's classification of all natural numbers representable as a sum of two natural-number squares. It is not only the prime case: representability is equivalent to every prime factor congruent to 3 modulo 4 occurring with even padicValNat exponent. The convention includes n = 0.

Source and local evidence

Where the theorem comes from

Existing declaration
Nat.eq_sq_add_sq_iff in mathlib
Relationship
The checked artifact is the upstream declaration itself
Local Lean evidence
artifact.library.mathlib.fermat-two-square-theorem.v001
Source
Open the pinned upstream reference