Skip to content

Sums of Squares

One of the oldest questions in number theory asks which integers can be written as sums of squares. Typical examples are

Representation Problems

One of the oldest questions in number theory asks which integers can be written as sums of squares. Typical examples are

5=12+22, 5=1^2+2^2, 25=32+42, 25=3^2+4^2,

and

50=12+72. 50=1^2+7^2.

Such problems are called representation problems because they ask how integers may be represented by quadratic forms.

The simplest equation of this type is

x2+y2=n, x^2+y^2=n,

where nn is a fixed positive integer and x,yZx,y\in\mathbb{Z}.

x2+y2=n x^2+y^2=n

The goal is to determine for which integers nn the equation has integer solutions.

Squares Modulo Small Integers

Congruences provide strong restrictions on sums of squares.

Modulo 44, every square is congruent to either 00 or 11:

020,121,220,321(mod4). 0^2\equiv0,\qquad 1^2\equiv1,\qquad 2^2\equiv0,\qquad 3^2\equiv1\pmod4.

Hence a sum of two squares can only be congruent to

0,1,2(mod4). 0,1,2\pmod4.

Therefore no integer congruent to 3(mod4)3\pmod4 can be written as a sum of two squares.

For example,

73(mod4), 7\equiv3\pmod4,

so the equation

x2+y2=7 x^2+y^2=7

has no integer solutions.

Congruence arguments of this kind are fundamental throughout number theory.

Fermat’s Theorem on Two Squares

The complete characterization of primes representable as sums of two squares is given by the following theorem.

Theorem. An odd prime pp can be written in the form

p=x2+y2 p=x^2+y^2

with integers x,yx,y if and only if

p1(mod4). p\equiv1\pmod4.

For example,

5=12+22, 5=1^2+2^2, 13=22+32, 13=2^2+3^2, 17=12+42, 17=1^2+4^2, 29=22+52. 29=2^2+5^2.

But primes such as

3,7,11,19 3,7,11,19

cannot be expressed as sums of two squares because they are congruent to 3(mod4)3\pmod4.

This theorem was stated by entity[“people”,“Pierre de Fermat”,“French mathematician”] and later proved rigorously by entity[“people”,“Leonhard Euler”,“Swiss mathematician”].

The General Criterion

The condition for arbitrary integers is more subtle.

Theorem. A positive integer nn can be expressed as a sum of two squares if and only if every prime congruent to

3(mod4) 3\pmod4

appears with even exponent in the prime factorization of nn.

For example,

45=325. 45=3^2\cdot5.

The prime 33(mod4)3\equiv3\pmod4 appears with exponent 22, which is even. Indeed,

45=32+62. 45=3^2+6^2.

Now consider

21=37. 21=3\cdot7.

Both primes are congruent to 3(mod4)3\pmod4, and both appear with odd exponent. Therefore 2121 cannot be represented as a sum of two squares.

Infinite Families of Solutions

Suppose

a2+b2=n a^2+b^2=n

and

c2+d2=m. c^2+d^2=m.

Then

(acbd)2+(ad+bc)2=nm. (ac-bd)^2+(ad+bc)^2=nm.

This identity shows that the product of two sums of squares is again a sum of two squares.

The identity may be written compactly as

$$ (a^2+b^2)(c^2+d^2)

(ac-bd)^2+(ad+bc)^2. $$

This formula explains why factorization plays a central role in the theory.

It also reflects multiplication in the Gaussian integers

Z[i], \mathbb{Z}[i],

where

i2=1. i^2=-1.

Indeed,

$$ (a+bi)(c+di)

(ac-bd)+(ad+bc)i. $$

The norm satisfies

N(a+bi)=a2+b2, N(a+bi)=a^2+b^2,

and multiplication of norms yields the identity above.

Lagrange’s Four-Square Theorem

The study of sums of squares extends naturally beyond two variables.

A fundamental result states that every positive integer can be written as a sum of four squares.

Theorem. For every positive integer nn, there exist integers a,b,c,da,b,c,d such that

n=a2+b2+c2+d2. n=a^2+b^2+c^2+d^2.

n=a2+b2+c2+d2 n=a^2+b^2+c^2+d^2

For example,

31=12+12+22+52. 31=1^2+1^2+2^2+5^2.

This theorem was proved by entity[“people”,“Joseph-Louis Lagrange”,“French mathematician”] in the eighteenth century.

The analogous problem for three squares is more delicate. Certain integers cannot be represented as sums of three squares, specifically those of the form

4k(8m+7). 4^k(8m+7).

Geometric Interpretation

The equation

x2+y2=n x^2+y^2=n

describes a circle of radius n\sqrt n. The problem asks which circles contain lattice points.

Similarly,

x2+y2+z2=n x^2+y^2+z^2=n

describes a sphere in three dimensions.

Thus the arithmetic theory of sums of squares becomes a problem about the distribution of lattice points on geometric surfaces. This interaction between algebra, geometry, and arithmetic is a recurring theme in modern number theory.