This site is supported by donations to The OEIS Foundation.

# Sums of squares

(Redirected from Lagrange's four-square theorem)

Please do not rely on any information it contains.

All positive integers can be expressed as sums of squares. Some can be expressed as the sum of two or three squares, some can be expressed as the sum of a million squares. And some can be expressed expressed as sums of squares in multiple ways. For example, 338350 is the sum of the first hundred nonzero squares. It can also be represented as 5802 + 432 + 102 + 12.

Since the square of a negative number is a positive number, we will not bother to distinguish between the squares of negative integers and the squares of positive integers in this article. However, we will distinguish between sums of squares that may include instances of 02 and those that must consist solely of the squares of nonzero integers; the latter will be referred to as "nonzero squares" here.

Among numbers that can be represented as the sum of a given number of squares, we may distinguish between those that can be represented with fewer squares and those that can't. For example, 25 = 42 + 32, but also 52, whereas 29 = 52 + 22 but we can't use ${\displaystyle ({\sqrt {29}})^{2}}$ (that is inelegant at best and cheating at worst).

 ${\displaystyle k}$ Numbers that can be represented with ${\displaystyle k}$ squares Numbers that can't be represented with fewer than ${\displaystyle k}$ squares 1 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, ... A000290 2 2, 5, 8, 10, 13, 17, 18, 20, 25, 26, 29, 32, ... A000404 2, 5, 8, 10, 13, 17, 18, 20, 26, 29, 32, 34, ... A000415 3 3, 6, 9, 11, 12, 14, 17, 18, 19, 21, 24, 26, 27, 30, ... A000408 3, 6, 11, 12, 14, 19, 21, 22, 24, 27, 30, 33, 35, 38, ... A000419 4 4, 7, 10, 12, 13, 15, 16, 18, 19, 20, 21, 22, 23, 25, ... A000414 7, 15, 23, 31, 39, 47, 55, 63, 71, 79, 87, 95, 103, ... A004771 5 5, 8, 11, 13, 14, 16, 17, 19, 20, 21, 22, 23, 24, 25, ... A047700 None 6 6, 9, 12, 14, 15, 16, 17, 20, 21, 22, ... 7 7, 10, 13, 15, 16, 18, 21, 22, ...

## Sums of four squares

The answer to Waring's problem for squares is that all integers have at least one representation as the sum of at most four squares.

Theorem SQS4. Every positive integer can be expressed as the sum of at most four nonzero squares. Or we can say that all positive integers are the sum of four squares, some, but not all, of which may be zero: that is, ${\displaystyle n=w^{2}+x^{2}+y^{2}+z^{2}}$, with ${\displaystyle w>x\geq y\geq z\geq 0}$.
Proof. PROOF GOES HERE. ENDOFPROOFMARK

When ${\displaystyle n\equiv 7\mod 8}$, the number requires four nonzero squares. Obviously prime numbers require at least two nonzero squares for their Waring representation. See Theorem P2SQ in the Gaussian integers article for a result regarding which primes can be expressed as the sum of two squares.

Corollary to Theorem SQS4. If ${\displaystyle n}$ is the sum of four equal nonzero squares, then it has at least two representations as sum of squares, at least one of which includes zeroes. The stricture ${\displaystyle w>x\geq y\geq z\geq 0}$ may have given the impression that the theorem does not cover the sums of equal squares, but this would be a false impression, as a little rewriting will show. If ${\displaystyle w=x=y=z>0}$, then ${\displaystyle n=4w^{2}}$ (or ${\displaystyle 4x^{2}}$, etc.). We can rewrite ${\displaystyle n=4w^{2}=2^{2}w^{2}=(2w)^{2}}$. Reassigning ${\displaystyle w:=2w}$ and 'resetting' ${\displaystyle x}$, ${\displaystyle y}$ and ${\displaystyle z}$ to 0 gives us a representation of ${\displaystyle n}$ satisfying the inequality ${\displaystyle w>x\geq y\geq z\geq 0}$ given in the theorem.

## Sums of five squares

With just a few exceptions (see A047701), all positive integers can be expressed as the sum of five nonzero squares. For example, 255 = 92 + 82 + 72 + 62 + 52.

Theorem SQS5. Every integer ${\displaystyle n>33}$ can be expressed as the sum of five nonzero squares.[1]
Proof. The cases ${\displaystyle 170>n>33}$ are examined one by one in the table below, demonstrating that each of them has at least one representation as the sum of five nonzero squares. For ${\displaystyle n>169}$, we will need the 4-square representation, which may include zeroes, which Theorem SQS4 tells us exists for all ${\displaystyle n}$. What is special about 169 is not that it is a square, but that it can also be represented as the sum of five, four, three or two squares. Solve the equation ${\displaystyle n-169=w^{2}+x^{2}+y^{2}+z^{2}}$ observing the stricture ${\displaystyle w>x\geq y\geq z\geq 0}$. If ${\displaystyle z>0}$, then ${\displaystyle n=13^{2}+w^{2}+x^{2}+y^{2}+z^{2}}$. If ${\displaystyle y>z=0}$, then ${\displaystyle n=12^{2}+5^{2}+w^{2}+x^{2}+y^{2}}$. If ${\displaystyle x>y=z=0}$, then ${\displaystyle n=12^{2}+4^{2}+3^{2}+w^{2}+x^{2}}$. And if only ${\displaystyle w>0}$, then we have ${\displaystyle n=10^{2}+8^{2}+2^{2}+1^{2}+w^{2}}$. □ [2]

Of course some integers have more than one representation as a sum of five nonzero squares, and the proof of Theorem SQS5 might not always give us the most "interesting" representation. Returning to our example of 255, the method outlined in the proof would give us 255 = (122 + 52) + (92 + 22 + 12).

 34 42 + 32 + 22 + 22 + 12 35 52 + 22 + 22 + 12 + 12 36 42 + 32 + 32 + 12 + 12 37 52 + 32 + 12 + 12 + 12 38 42 + 42 + 22 + 12 + 12 39 42 + 32 + 32 + 22 + 12 40 62 + 12 + 12 + 12 + 12 41 52 + 32 + 22 + 12 + 12 42 42 + 32 + 32 + 22 + 22 43 52 + 32 + 22 + 22 + 12 44 52 + 42 + 12 + 12 + 12 45 52 + 32 + 32 + 12 + 12 46 42 + 42 + 32 + 22 + 12 47 52 + 42 + 22 + 12 + 12 48 52 + 32 + 32 + 22 + 12 49 62 + 22 + 22 + 22 + 12 50 52 + 42 + 22 + 22 + 12 51 62 + 32 + 22 + 12 + 12 52 52 + 42 + 32 + 12 + 12 53 42 + 42 + 42 + 22 + 12 54 62 + 32 + 22 + 22 + 12 55 52 + 42 + 32 + 22 + 12 56 52 + 52 + 22 + 12 + 12 57 62 + 32 + 22 + 22 + 22 58 62 + 42 + 22 + 12 + 12 59 62 + 32 + 32 + 22 + 12 60 52 + 42 + 32 + 32 + 12 61 62 + 42 + 22 + 22 + 12 62 52 + 42 + 42 + 22 + 12 63 62 + 42 + 32 + 12 + 12 64 72 + 32 + 22 + 12 + 12 65 42 + 42 + 42 + 42 + 12 66 62 + 42 + 32 + 22 + 12 67 62 + 52 + 22 + 12 + 12 68 52 + 52 + 42 + 12 + 12 69 72 + 32 + 32 + 12 + 12 70 62 + 52 + 22 + 22 + 12 71 72 + 42 + 22 + 12 + 12 72 62 + 52 + 32 + 12 + 12 73 62 + 52 + 22 + 22 + 22 74 72 + 42 + 22 + 22 + 12 75 62 + 52 + 32 + 22 + 12 76 72 + 42 + 32 + 12 + 12 77 72 + 52 + 12 + 12 + 12 78 62 + 42 + 42 + 32 + 12 79 72 + 42 + 32 + 22 + 12 80 72 + 52 + 22 + 12 + 12 81 62 + 62 + 22 + 22 + 12 82 62 + 52 + 42 + 22 + 12 83 72 + 52 + 22 + 22 + 12 84 72 + 42 + 32 + 32 + 12 85 72 + 52 + 32 + 12 + 12 86 82 + 42 + 22 + 12 + 12 87 62 + 52 + 42 + 32 + 12 88 72 + 52 + 32 + 22 + 12 89 82 + 42 + 22 + 22 + 12 90 62 + 62 + 42 + 12 + 12 91 72 + 62 + 22 + 12 + 12 92 72 + 52 + 42 + 12 + 12 93 72 + 52 + 32 + 32 + 12 94 82 + 42 + 32 + 22 + 12 95 72 + 52 + 42 + 22 + 12 96 92 + 32 + 22 + 12 + 12 97 72 + 62 + 22 + 22 + 22 98 82 + 52 + 22 + 22 + 12 99 72 + 62 + 32 + 22 + 12 100 72 + 52 + 42 + 32 + 12 101 82 + 42 + 42 + 22 + 12 102 62 + 62 + 52 + 22 + 12 103 82 + 52 + 32 + 22 + 12 104 92 + 32 + 32 + 22 + 12 105 62 + 62 + 42 + 42 + 12 106 72 + 62 + 42 + 22 + 12 107 62 + 62 + 52 + 32 + 12 108 92 + 42 + 32 + 12 + 12 109 82 + 62 + 22 + 22 + 12 110 82 + 52 + 42 + 22 + 12 111 92 + 42 + 32 + 22 + 12 112 92 + 52 + 22 + 12 + 12 113 102 + 22 + 22 + 22 + 12 114 82 + 62 + 32 + 22 + 12 115 72 + 62 + 52 + 22 + 12 116 92 + 42 + 32 + 32 + 12 117 92 + 52 + 32 + 12 + 12 118 82 + 62 + 42 + 12 + 12 119 82 + 72 + 22 + 12 + 12 120 92 + 52 + 32 + 22 + 12 121 82 + 62 + 42 + 22 + 12 122 102 + 42 + 22 + 12 + 12 123 92 + 62 + 22 + 12 + 12 124 82 + 72 + 32 + 12 + 12 125 102 + 42 + 22 + 22 + 12 126 82 + 62 + 42 + 32 + 12 127 82 + 72 + 32 + 22 + 12 128 92 + 62 + 32 + 12 + 12 129 92 + 62 + 22 + 22 + 22 130 82 + 62 + 52 + 22 + 12 131 92 + 62 + 32 + 22 + 12 132 92 + 52 + 42 + 32 + 12 133 72 + 72 + 52 + 32 + 12 134 82 + 72 + 42 + 22 + 12 135 82 + 62 + 52 + 32 + 12 136 112 + 32 + 22 + 12 + 12 137 102 + 42 + 42 + 22 + 12 138 92 + 62 + 42 + 22 + 12 139 102 + 52 + 32 + 22 + 12 140 82 + 72 + 52 + 12 + 12 141 92 + 72 + 32 + 12 + 12 142 82 + 62 + 52 + 42 + 12 143 82 + 72 + 52 + 22 + 12 144 92 + 72 + 32 + 22 + 12 145 102 + 62 + 22 + 22 + 12 146 102 + 52 + 42 + 22 + 12 147 92 + 62 + 52 + 22 + 12 148 82 + 72 + 52 + 32 + 12 149 82 + 82 + 42 + 22 + 12 150 102 + 62 + 32 + 22 + 12 151 112 + 42 + 32 + 22 + 12 152 92 + 62 + 52 + 32 + 12 153 82 + 62 + 62 + 42 + 12 154 82 + 72 + 62 + 32 + 12 155 82 + 72 + 52 + 42 + 12 156 92 + 72 + 42 + 32 + 12 157 102 + 62 + 42 + 22 + 12 158 102 + 72 + 22 + 22 + 12 159 92 + 82 + 32 + 22 + 12 160 112 + 52 + 32 + 22 + 12 161 102 + 72 + 22 + 22 + 22 162 102 + 62 + 42 + 32 + 12 163 102 + 72 + 32 + 22 + 12 164 112 + 52 + 42 + 12 + 12 165 92 + 72 + 52 + 32 + 12 166 92 + 82 + 42 + 22 + 12 167 112 + 52 + 42 + 22 + 12 168 112 + 62 + 32 + 12 + 12 169 122 + 42 + 22 + 22 + 12

## References

1. This is part of Theorem 5.6 in Niven & Zuckerman (1980), on pages 144 and 145. In that book, they also prove that there infinitely many integers which are not the sum of four nonzero squares.
2. This is pretty much the same as the proof given in Niven & Zuckerman (1980), p. 145, but with the statements regarding numbers that are not the sums of four nonzero squares left out.
• Ivan Niven & Herbert S. Zuckerman, An Introduction to the Theory of Numbers, New York: John Wiley (1980).