# Jacobi's four-square theorem

In 1834, Carl Gustav Jakob Jacobi found an exact formula for the total number of ways a given positive integer n can be represented as the sum of four squares. Two representations are considered different if their terms are in different order or if the integer being squared (not just the square) is different; to illustrate, these are three of the eight different ways to represent 1:

\begin{align} & 1^2 + 0^2 + 0^2 + 0^2 \\ & 0^2 + 1^2 + 0^2 + 0^2 \\ & (-1)^2 + 0^2 + 0^2 + 0^2. \end{align}

The number of ways to represent n as the sum of four squares is eight times the sum of the divisors of n if n is odd and 24 times the sum of the odd divisors of n if n is even (see divisor function), i.e.

$r_4(n)=\begin{cases}8\sum\limits_{m|n}m&\text{if }n\text{ is odd}\\[12pt] 24\sum\limits_{\begin{smallmatrix} m|n \\ m\text{ odd} \end{smallmatrix}}m&\text{if }n\text{ is even}. \end{cases}$

Equivalently, it is eight times the sum of all its divisors which are not divisible by 4, i.e.

$r_4(n)=8\sum_{m\,:\, 4\nmid m|n}m.$

In particular, for a prime number p we have the explicit formula r4(p) = 8(p + 1).

The proof shows that the Theta series for the lattice Z4 is a modular form of a certain level, and hence equals a linear combination of Eisenstein series.