In number theory, the sum of squares function is an arithmetic function that gives the number of representations for a given positive integer n {\displaystyle n} as the sum of k {\displaystyle k} squares, where representations that differ only in the order of the summands or in the signs of the numbers being squared are counted as different. It is denoted by r k ( n ) {\displaystyle r_{k}(n)}.

Definition

The function is defined as

r k ( n ) = | { ( a 1 , a 2 , … , a k ) ∈ Z k : n = a 1 2 + a 2 2 + ⋯ + a k 2 } | {\displaystyle r_{k}(n)=|\{(a_{1},a_{2},\ldots ,a_{k})\in \mathbb {Z} ^{k}\:\ n=a_{1}^{2}+a_{2}^{2}+\cdots +a_{k}^{2}\}|}

where | | {\displaystyle |\,\ |} denotes the cardinality of a set. In other words, r k ( n ) {\displaystyle r_{k}(n)} is the number of ways n {\displaystyle n} can be written as a sum of k {\displaystyle k} squares.

For example, r 2 ( 1 ) = 4 {\displaystyle r_{2}(1)=4} since 1 = 0 2 + ( ± 1 ) 2 = ( ± 1 ) 2 + 0 2 {\displaystyle 1=0^{2}+(\pm 1)^{2}=(\pm 1)^{2}+0^{2}} where each sum has two sign combinations, and also r 2 ( 2 ) = 4 {\displaystyle r_{2}(2)=4} since 2 = ( ± 1 ) 2 + ( ± 1 ) 2 {\displaystyle 2=(\pm 1)^{2}+(\pm 1)^{2}} with four sign combinations. On the other hand, r 2 ( 3 ) = 0 {\displaystyle r_{2}(3)=0} because there is no way to represent 3 as a sum of two squares.

Formulae

k = 2

Integers satisfying the sum of two squares theorem are squares of possible distances between integer lattice points; values up to 100 are shown, with •Squares (and thus integer distances) in red •Non-unique representations (up to rotation and reflection) bolded

The number of ways to write a natural number as sum of two squares is given by r 2 ( n ) {\displaystyle r_{2}(n)}. It is given explicitly by

r 2 ( n ) = 4 ( d 1 ( n ) − d 3 ( n ) ) {\displaystyle r_{2}(n)=4(d_{1}(n)-d_{3}(n))}

where d 1 ( n ) {\displaystyle d_{1}(n)} is the number of divisors of n {\displaystyle n} which are congruent to 1 modulo 4 and d 3 ( n ) {\displaystyle d_{3}(n)} is the number of divisors of n {\displaystyle n} which are congruent to 3 modulo 4. Using sums, the expression can be written as:

r 2 ( n ) = 4 ∑ d ∣ n d ≡ 1 , 3 ( mod 4 ) ( − 1 ) ( d − 1 ) / 2 {\displaystyle r_{2}(n)=4\sum _{d\mid n \atop d\,\equiv \,1,3{\pmod {4}}}(-1)^{(d-1)/2}}

The prime factorization n = 2 g p 1 f 1 p 2 f 2 ⋯ q 1 h 1 q 2 h 2 ⋯ {\displaystyle n=2^{g}p_{1}^{f_{1}}p_{2}^{f_{2}}\cdots q_{1}^{h_{1}}q_{2}^{h_{2}}\cdots }, where p i {\displaystyle p_{i}} are the prime factors of the form p i ≡ 1 ( mod 4 ) , {\displaystyle p_{i}\equiv 1{\pmod {4}},} and q i {\displaystyle q_{i}} are the prime factors of the form q i ≡ 3 ( mod 4 ) {\displaystyle q_{i}\equiv 3{\pmod {4}}} gives another formula

r 2 ( n ) = 4 ( f 1 + 1 ) ( f 2 + 1 ) ⋯ {\displaystyle r_{2}(n)=4(f_{1}+1)(f_{2}+1)\cdots }, if all exponents h 1 , h 2 , ⋯ {\displaystyle h_{1},h_{2},\cdots } are even. If one or more h i {\displaystyle h_{i}} are odd, then r 2 ( n ) = 0 {\displaystyle r_{2}(n)=0}.

k = 3

Gauss proved that for a squarefree number n > 4 {\displaystyle n>4},

r 3 ( n ) = { 24 h ( − n ) , if n ≡ 3 ( mod 8 ) , 0 if n ≡ 7 ( mod 8 ) , 12 h ( − 4 n ) otherwise , {\displaystyle r_{3}(n)={\begin{cases}24h(-n),&{\text{if }}n\equiv 3{\pmod {8}},\\0&{\text{if }}n\equiv 7{\pmod {8}},\\12h(-4n)&{\text{otherwise}},\end{cases}}}

where h ( m ) {\displaystyle h(m)} denotes the class number of an integer m {\displaystyle m}.

There exist extensions of Gauss' formula to arbitrary integer n {\displaystyle n}.

k = 4

The number of ways to represent n {\displaystyle n} as the sum of four squares was due to Carl Gustav Jakob Jacobi and it is eight times the sum of all its divisors which are not divisible by 4, i.e.

r 4 ( n ) = 8 ∑ d ∣ n , 4 ∤ d d . {\displaystyle r_{4}(n)=8\sum _{d\,\mid \,n,\ 4\,\nmid \,d}d.}

Representing n = 2 k m {\displaystyle n=2^{k}m}, where m {\displaystyle m} is an odd integer, one can express r 4 ( n ) {\displaystyle r_{4}(n)} in terms of the divisor function as follows:

r 4 ( n ) = 8 σ ( 2 min { k , 1 } m ) . {\displaystyle r_{4}(n)=8\sigma (2^{\min\{k,1\}}m).}

k = 6

The number of ways to represent n {\displaystyle n} as the sum of six squares is given by

r 6 ( n ) = 4 ∑ d ∣ n d 2 ( 4 ( − 4 n / d ) − ( − 4 d ) ) , {\displaystyle r_{6}(n)=4\sum _{d\mid n}d^{2}{\big (}4\left({\tfrac {-4}{n/d}}\right)-\left({\tfrac {-4}{d}}\right){\big )},}

where ( ⋅ ⋅ ) {\displaystyle \left({\tfrac {\cdot }{\cdot }}\right)} is the Kronecker symbol.

k = 8

Jacobi also found an explicit formula for the case k = 8 {\displaystyle k=8}:

r 8 ( n ) = 16 ∑ d ∣ n ( − 1 ) n + d d 3 . {\displaystyle r_{8}(n)=16\sum _{d\,\mid \,n}(-1)^{n+d}d^{3}.}

Generating function

The generating function of the sequence r k ( n ) {\displaystyle r_{k}(n)} for fixed k can be expressed in terms of the Jacobi theta function:

ϑ ( 0 ; q ) k = ϑ 3 k ( q ) = ∑ n = 0 ∞ r k ( n ) q n , {\displaystyle \vartheta (0;q)^{k}=\vartheta _{3}^{k}(q)=\sum _{n=0}^{\infty }r_{k}(n)q^{n},}

where

ϑ ( 0 ; q ) = ∑ n = − ∞ ∞ q n 2 = 1 + 2 q + 2 q 4 + 2 q 9 + 2 q 16 + ⋯ . {\displaystyle \vartheta (0;q)=\sum _{n=-\infty }^{\infty }q^{n^{2}}=1+2q+2q^{4}+2q^{9}+2q^{16}+\cdots .}

Numerical values

The first 30 values for r k ( n ) , k = 1 , … , 8 {\displaystyle r_{k}(n),\;k=1,\dots ,8} are listed in the table below:

n=r 1 ( n ) {\displaystyle r_{1}(n)}r 2 ( n ) {\displaystyle r_{2}(n)}r 3 ( n ) {\displaystyle r_{3}(n)}r 4 ( n ) {\displaystyle r_{4}(n)}r 5 ( n ) {\displaystyle r_{5}(n)}r 6 ( n ) {\displaystyle r_{6}(n)}r 7 ( n ) {\displaystyle r_{7}(n)}r 8 ( n ) {\displaystyle r_{8}(n)}
0011111111
11246810121416
22041224406084112
330083280160280448
42224624902525741136
550824481123128402016
62×300249624054412883136
770006432096023685504
823041224200102034449328
9322430104250876354212112
102×508241445601560442414112
11110024965602400756021312
1222×3008964002080924031808
131308241125602040845635168
142×7004819280032641108838528
153×500019296041601657656448
16242462473040921849474864
1717084814448034801780878624
182×320436312124043801974084784
191900241601520720027720109760
2022×50824144752655234440143136
213×700482561120460829456154112
222×1100242881840816031304149184
232300019216001056049728194688
2423×30024961200822452808261184
2552212302481210781243414252016
262×13087233620001020052248246176
2733003232022401312068320327040
2822×700019216001248074048390784
2929087224016801010468376390240
302×3×5004857627201414471120395136

See also

Further reading

Grosswald, Emil (1985). Representations of integers as sums of squares. Springer-Verlag. ISBN0387961267.

External links