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 moreSum 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 ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesSet Operations: Union, Intersection, and ComplementProof by CasesProving by Cases and ExhaustionVacuous Truth and Trivial CasesProof by Cases (Proof by Exhaustion)Mathematical InductionDivisibility and Greatest Common DivisorThe Fundamental Theorem of ArithmeticDivisibility Theory (Formal Treatment)Bézout's IdentityLinear Diophantine EquationsPell's EquationLagrange's Four-Square Theorem

Longest path: 81 steps · 382 total prerequisite topics

Prerequisites (4)

Leads To (1)