Mathlib theorem · Existing formal mathematics

Existing in Mathlib · Number theory

Lagrange's Four-Square Theorem

For every natural number n, there are four natural numbers—some of which may be zero—whose squares add exactly to n.

Exact theorem

Exact Mathlib statement

theorem Nat.sum_four_squares (n : ℕ) : ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = n

The theorem at a glance

Lagrange's Four-Square Theorem at a glance

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

Every natural number has a representation as four natural-number squares, with zero terms allowed. Explanatory diagram.
Detailed visual description

The poster connects the exact four-square statement to Euler multiplication, the modular prime seed, least-multiplier descent, and final multiplicative induction without adding a representation count or uniqueness claim.

Statement structure

Statement and scope

Statement map for Lagrange's Four-Square TheoremEvery natural number is a sum of four squares of natural numbers. Claim boundary: This target indexes Mathlib's existence theorem that every natural number is a sum of four squares of natural numbers. It does not count representations, require all four terms to be nonzero, or claim a new proof. The pinned upstream declaration is Nat.sum_four_squares. The complete formal statement is available in the Exact Mathlib statement section.Mathematical readingEvery natural number isa sum of four squares ofnatural numbers.Claim boundaryThis target indexesMathlib's existencetheorem that everynatural number is a sumof four squares ofnatural numbers. It doesnot countrepresentations, requireall four terms to benonzero, or claim a newproof.Pinned declarationmathlib ·Nat.sum_four_squaresStatement map for Lagrange's Four-Square TheoremEvery natural number is a sum of four squares of natural numbers. Claim boundary: This target indexes Mathlib's existence theorem that every natural number is a sum of four squares of natural numbers. It does not count representations, require all four terms to be nonzero, or claim a new proof. The pinned upstream declaration is Nat.sum_four_squares. The complete formal statement is available in the Exact Mathlib statement section.Mathematical readingEvery natural number isa sum of four squares ofnatural numbers.Claim boundaryThis target indexesMathlib's existencetheorem that everynatural number is a sumof four squares ofnatural numbers. It doesnot countrepresentations, requireall four terms to benonzero, or claim a newproof.Pinned declarationmathlib ·Nat.sum_four_squares

Read the exact Mathlib declaration

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

Euler multiplication and a least-multiplier prime descent assemble four-square representations for every natural number. Explanatory scientific diagram.
Detailed visual description

The recurring four-arm rosette represents one sum of four squares. Euler's braid preserves that form under multiplication, the multiplier around a prime shrinks to one, and prime representations then assemble into a representation of an arbitrary natural number.

Why it matters

A mathematical landmark

Lagrange's theorem gives a universal additive representation of every natural number. Mathlib's proof combines Euler's four-square identity, prime descent, and multiplicative induction.

Proof architecture

Euler multiplication and Lagrange descent

5 curated stages

Mathlib proves that every natural number is a sum of four natural-number squares by establishing Euler's multiplicative identity, representing a multiple of each prime, descending a least positive multiplier to one, and extending prime representations to all naturals by multiplicative induction.

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. Two four-square representations multiply into another

    Euler's identity combines two four-coordinate representations while preserving the sum-of-four-squares form of their product.

    (sum of four squares) · (sum of four squares) = sum of four squares

    The proof first establishes Euler's four-square identity in a commutative ring and then a natural-number version using integer absolute values. This identity supplies the multiplicative step used both in prime descent and in the final induction.

  2. Start with four squares equal to a small positive multiple of a prime

    A modular sum-of-two-squares argument yields a four-square representation of k p with the multiplier strictly between zero and p.

    0 < k < p and a²+b²+c²+d² = k p

    For an odd prime, Mathlib uses a congruence for a sum of two squares modulo p, adds the square of one and the square of zero, and extracts a positive multiplier smaller than the prime. The prime two is handled directly.

  3. Minimality prepares a smaller multiplier

    Choose the least represented positive multiplier; halve it when even, or replace all four coordinates by least absolute residues when odd.

    m minimal; either m/2 or 0 < r < m

    Nat.findX selects a minimal positive m with four squares equal to m p. If m is even, a parity lemma divides the representation by two. If m is odd, each coordinate is replaced by a congruent representative with absolute value less than half m, producing a positive quotient r<m.

  4. The four-square identity completes the descent

    Euler's identity combines the reduced residues with the original representation and, after division, represents r p, contradicting minimality.

    m = 1; hence p = a²+b²+c²+d²

    In the odd case, a reordered four-square representation of m r is multiplied by the representation of m p. The Euler outputs are all divisible by m; division yields a four-square representation of r p with r<m. Together with the even case, this makes every assumption m>1 impossible, so the prime itself is a sum of four squares.

  5. Multiplicative induction reaches every natural number

    Zero and one are immediate, primes use the descent, and products use Euler's identity, completing multiplicative induction.

    ∀ n : ℕ, ∃ a b c d : ℕ, a²+b²+c²+d²=n

    Nat.sum_four_squares invokes Nat.recOnMul. The zero and one cases use representations with zero terms; the prime case invokes the theorem from page 4; and the product case combines two inductive representations with Euler's identity. Therefore every natural number has a four-square representation.

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 existence theorem that every natural number is a sum of four squares of natural numbers. It does not count representations, require all four terms to be nonzero, or claim a new proof.

Source and local evidence

Where the theorem comes from

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