A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Lagrange's Four-Square Theorem

Graduate Depth 80 in the knowledge graph ☐ I know this ☆ Set as goal
3topics build on this
382prerequisites beneath it
See this on the map →
Fundamental Theorem of Arithmetic (Rigorous Proof)Fermat's Last Theorem (Overview)+2 more→→Sum of Two Squares Theorem
four-squares representation diophantine

Core Idea

Every non-negative integer is the sum of four perfect squares. Unlike the two-square case, this holds universally with a clean statement, proven via quaternion algebras or generating functions.

Explainer

Start with a simple empirical observation: 1 = 1², 2 = 1² + 1², 3 = 1² + 1² + 1², 4 = 2², 5 = 2² + 1², 6 = 2² + 1² + 1², 7 = 2² + 1² + 1² + 1². Notice that 7 requires all four squares — no way to write it as the sum of three or fewer squares of integers. Lagrange's Four-Square Theorem, proved in 1770, asserts that this never gets worse: four squares always suffice for every non-negative integer.

To understand why four is special, contrast with two. From the Fundamental Theorem of Arithmetic you know that every integer factors uniquely into primes. The sum-of-two-squares theorem (a consequence of Fermat) says a positive integer is a sum of two squares if and only if in its prime factorization, every prime of the form 4k + 3 appears to an even power. So 3 (a 4k+3 prime to the first power) fails: 3 cannot be written as a² + b² for integers a, b. The two-square representation is selective. The three-square theorem (Legendre) says all integers are sums of three squares except those of the form 4^a(8b + 7). So 7 itself is excluded from three squares. But no such exceptions survive with four squares.

The classical proof uses quaternion algebras — a number system generalizing complex numbers to four dimensions, of the form a + bi + cj + dk. Crucially, quaternion norms multiply: N(qr) = N(q)N(r), where N(a + bi + cj + dk) = a² + b² + c² + d². This gives an identity of four squares: if m and n are each sums of four squares, then mn is also a sum of four squares. This multiplicativity means it suffices to prove the theorem for primes — the general case follows automatically from the prime factorization. For any prime p, one can show that among the p + 1 values 0², 1², …, ((p−1)/2)² and −1 − 0², −1 − 1², …, the pigeonhole principle guarantees a solution to a² + b² ≡ −1 (mod p), which bootstraps into representing p as a sum of four integer squares.

The theorem is tight in a precise sense: Legendre's three-square theorem shows that exactly the integers 4^a(8b + 7) require four squares and cannot be done with three. So Lagrange's result answers the question definitively — four squares are necessary in the worst case, and always sufficient. This makes the theorem a satisfying capstone: a clean, universal statement that falls out of the deep multiplicative structure of integers and the arithmetic of primes.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Set Operations: Union, Intersection, and Complement → Proof by Cases → Proving by Cases and Exhaustion → Vacuous Truth and Trivial Cases → Proof by Cases (Proof by Exhaustion) → Mathematical Induction → Divisibility and Greatest Common Divisor → The Fundamental Theorem of Arithmetic → Divisibility Theory (Formal Treatment) → Bézout's Identity → Linear Diophantine Equations → Pell's Equation → Lagrange's Four-Square Theorem

Longest path: 81 steps · 382 total prerequisite topics

Prerequisites (4)

Leads To (1)