# Understanding a proof of Lagrange's four-square theorem

I've been looking at Wikipedia's proof of the four-square theorem and trying to work out the details - I like that it doesn't need to separate the cases for $m$ even and odd, but there is one step that seems flawed if the $m$ even case is not dispensed with in advance.

Now let $m$ be the smallest positive integer such that $mp$ is the sum of four squares, $x_1^2+x_2^2+x_3^2+x_4^2$. We show by contradiction that $m$ equals $1$: supposing it is not the case, we prove the existence of a positive integer $r$ less than $m$, for which $rp$ is also the sum of four squares (this is the "infinite descent" method of Fermat).

For this purpose, we consider for each $x_i$ the $y_i$ which is in the same residue class modulo $m$ and between $-m/2+1$ and $m/2$ (included). It follows that $y_1^2+y_2^2+y_3^2+y_4^2=mr$, for some positive integer $r$ less than $m$.

What justifies the claim that $r<m$? From $y_i\in[-m/2+1,m/2]$ we get only $\sum y_i^2\le m^2$, and there still remains the case when each $y_i$ is equal to $m/2$.

Sorry to ask such a simple question, but there aren't any other proofs that I've seen that try to take this approach, and it would make my job easier (I'm writing a formal proof) if this approach is valid, since it saves me a few lemmas.

Assume $y_1=y_2=y_3=y_4=m/2$. Then $x_i=mk_i + m/2$, for some non-negative integers $k_1,...,k_4$ (because we can assume from the beginning of the problem that $x_1,...,x_4$ are non-negative). But this gives $mp=x_1^2+x_2^2+x_3^2+x_4^2=m^2(k_1^2+...+k_4^2+k_1+...+k_4+1)$, that is, $p=m(k_1^2+...+k_4^2+k_1+...+k_4+1)$, which is a contradiction since $p$ is prime.
Then $y_1,...,y_4$ cannot be all equal to $m/2$, and therefore $y_1^2+...+y_4^2<m^2$, which implies $r<m$.
• Well, I just wanted to avoid some troubles. What if $k_1^2+...+k_4^2+k_1+...+k_4 = 0$ and $m$ is prime? – Marco Flores Jul 16 '14 at 0:47
• Oh, I see. But if that sum is zero, then $m=p$ and thus is odd ($p$ is an odd prime), in contradiction to $y_1=m/2$ being an integer. – Mario Carneiro Jul 16 '14 at 0:58
• Hm, I got a bit farther in this problem and now I see that there is a similar problem in eliminating the case $r=0$, which happens when $y_i=0$. By a similar argument, you get that $m|p\implies m=p$, but now that's not a contradiction because $m$ could be odd in this case too. What gives? – Mario Carneiro Jul 16 '14 at 20:19
• The previous paragraph at Wikipedia's proof shows the existence of an integer $n$, such that $np$ is the sum of four squares and $0<n<p$. Thus the $m$ may be choosen at the beginning satisfying $m<p$, and then $m=p$ is a contradiction. – Marco Flores Jul 16 '14 at 21:04