# Is there any variation known to the sum of two squares theorem?

Originally posed by Fermat and subsequently generalized as sum of two squares theorem, we can see the following statement.

An integer greater than one can be written as a sum of two squares if and only if its prime decomposition contains no factor $$p^k$$, where prime $$p\equiv 3 \pmod {4}$$ and $$k$$ is odd.

My question is simple. Is there any variation known to this theorem?

Such as, when we refer the theorem above as $$1 \pmod {4}$$ version, I would like to know whether there are any $$1 \pmod {6}$$ version, $$1 \pmod {8}$$ version, $$1 \pmod {12}$$ version...and so on.

The Diophantine equation won't have to be necessarily similar with the two square version. Such as, someone might find some property of prime decomposition regarding some modular restriction with a Diophantine equation higher that the degree 2.

I've tried to make the question simple, but I'm not sure whether they could have been conveyed to the readers. If the points were not clear, please let me clarify them with further comments. Thanks.

Edit: My question was posed to ask for some variation in regard of modular restriction of prime decomposition. For example let's think about some formula A which is a Diophantine polynomial.
$$A = n$$ when $$A = a^2 + b^2$$, it is sum of two squares theorem, which I refer as $$1 \pmod {4}$$ version. My main question is, whether there is any $$A$$ that makes $$n$$ on the right hand side being factorized only with $$1 \pmod {6}$$ numbers, or $$1 \pmod {8}$$ numbers, or $$1 \pmod {12}$$ numbers. If there is any, we may refer them as $$1 \pmod {6}$$ version, $$1 \pmod {8}$$ version, $$1 \pmod {12}$$ version. I see that already some of users are sharing their examples which I appreciate.

Thank you for your interests on my question.

• Not sure if you were looking only for variants in two squares formulation. If not, there is Legendre's three square theorem: $n = x^2 + y^2 + z^2$ iff $n$ is not of the form $n = 4^a(8b + 7)$ for non-negative integers $a, b$.
– vvg
Mar 15, 2022 at 13:18
• @vvg: Your one can be regarded as one the examples I was trying to find. Thanks! Mar 15, 2022 at 13:23
• Another variation is... the whole of class field theory. You can interpret the two squares theorem as giving a characterization of norms for the quadratic extension $\mathbb{Q}(i)/\mathbb{Q}$ in terms of certain prime behaviour. What happens for general abelian extensions of $\mathbb{Q}$ is a big part of class field theory. Mar 15, 2022 at 13:35
• @CaptainLama that's a great point. I think Cox' "primes of the form $x^2+ny^2$" would be a great read for the OP to get to a point where one can appreciate the connection to class field theory. Mar 15, 2022 at 13:38
• @Lukas Hegar: Thank you for your elaborate answer. I will also look for the source you've recommend. I really need to study one. Mar 15, 2022 at 13:42

The sum of two squares theorem can be proved by working in $$\Bbb Z[i]$$.

By working in $$\Bbb Z[\zeta_3]$$ instead, where $$\zeta_3$$ is a third root of unity, one may prove that an integer greater than one can be written in the form $$a^2+3b^2$$ (or equivalently, in the form $$a^2+ab+b^2$$, see the comments) if and only if its prime decomposition contains no factor $$p^k$$ where $$k$$ is odd and $$p$$ is a prime $$p \equiv 2 \pmod{3}$$.

There is a similar statement for every quadratic number field with class number one. This may be proved by using unique factorization in the ring of integers, quadratic reciprocity and the characterization of splitting of primes in quadratic extensions in terms of Legendre symbols.

Here are some more examples:

By working in $$\Bbb Z[\sqrt{2}]$$, one gets that an integer greater than one can be written in the form $$a^2-2b^2$$ if and only if its prime decomposition contains no factor $$p^k$$ where $$k$$ is odd and $$p$$ is a prime $$p \equiv 3,5 \pmod{8}$$.

By working in $$\Bbb Z[\sqrt{-2}]$$, one gets that an integer greater than one can be written in the form $$a^2+2b^2$$ if and only if its prime decomposition contains no factor $$p^k$$ where $$k$$ is odd and $$p$$ is a prime $$p \equiv 5,7 \pmod{8}$$.

By working in $$\Bbb Z[\frac{1+\sqrt{-19}}{2}]$$, one gets that an integer greater than one can be expressed as $$a^2+ab+5b^2$$ if and only if its prime decomposition contains no factor of the form $$p^k$$, where $$k$$ is odd and $$p=2$$ or $$p\equiv 3,4,8,10,12,13,14,15,18$$. Note that the quadratic form here is non-diagonal, because the ring of integers of $$\Bbb Q(\sqrt{-19})$$ is not $$\Bbb Z[\sqrt{-19}]$$.

There's another phenomenon that these examples so far haven't covered. If the number field is real quadratic and there is no unit with norm $$-1$$ in $$\mathcal O_K$$, then we need to introduce a $$\pm$$ in the quadratic form to get a correct statement. For example, in $$\Bbb Z[\sqrt{7}]$$ one has the fundamental unit $$3\sqrt{7}-8$$ with norm $$1$$, and so one gets that that an integer greater than one can be written in the form $$\pm(a^2-7b^2)$$ if and only if its prime decomposition contains no factor $$p^k$$ where $$k$$ is odd and $$p$$ is a prime $$p \equiv 5,11,13,15,17,23 \pmod{28}$$.

It is conjectured that there infinitely many real quadratic number fields of class number $$1$$, so if that conjecture holds, we get infinitely many such theorems. (LMFDB lists 177168 examples)

Here's the general theorem that may be specialized using some Legendre symbol computations (i.e. qudratic reciprocity) to give congruence conditions:

Theorem Let $$K=\Bbb Q(\sqrt{D})$$ be a quadratic number field with $$D$$ square-free and suppose that the ring of integers $$\mathcal O_K$$ has class number $$1$$. We have six cases:

1. $$D<0$$ and $$D \not\equiv 1 \pmod 4$$
2. $$D<0$$ and $$D\equiv 1 \pmod 8$$
3. $$D<0$$ and $$D\equiv 5 \pmod 8$$
4. $$D>0$$ and $$D \not\equiv 1 \pmod 4$$
5. $$D>0$$ and $$D \equiv 1 \pmod 8$$
6. $$D>0$$ and $$D \equiv 5 \pmod 8$$

For the cases 4-6, we have two subcases each:
a) the fundamental unit of $$\mathcal O_K$$ has norm $$-1$$
b) the fundamental unit of $$\mathcal O_K$$ has norm $$1$$

We then have the following properties:

1. An integer greater than one can be written in the form $$a^2-Db^2$$ if and only if its prime decomposition contains no factor $$p^k$$ where $$k$$ is odd and $$p$$ is a prime such that $$\left(\frac{D}{p}\right)=-1$$
2. An integer greater than one can be written in the form $$a^2+ab+\frac{1-D}{4}b^2$$ if and only if its prime decomposition contains no factor $$p^k$$ where $$k$$ is odd and $$p$$ is a prime such that $$p=2$$ or $$\left(\frac{D}{p}\right)=-1$$
3. An integer greater than one can be written in the form $$a^2+ab+\frac{1-D}{4}b^2$$ if and only if its prime decomposition contains no factor $$p^k$$ where $$k$$ is odd and $$p$$ is a prime such that $$\left(\frac{D}{p}\right)=-1$$
4. An integer greater than one can be written in the form $$a^2-Db^2$$ (in subcase a) or in the form $$\pm(a^2-Db^2)$$ (in subcase b) if and only if its prime decomposition contains no factor $$p^k$$ where $$k$$ is odd and $$p$$ is a prime such that $$\left(\frac{D}{p}\right)=-1$$
5. An integer greater than one can be written in the form $$a^2+ab+\frac{1-D}{4}b^2$$ (in subcase a) or in the form $$\pm(a^2+ab+\frac{1-D}{4}b^2)$$ (in subcase b) if and only if its prime decomposition contains no factor $$p^k$$ where $$k$$ is odd and $$p$$ is a prime such that $$p=2$$ or $$\left(\frac{D}{p}\right)=-1$$
6. An integer greater than one can be written in the form $$a^2+ab+\frac{1-D}{4}b^2$$ (in subcase a) or in the form $$\pm(a^2+ab+\frac{1-D}{4}b^2)$$ (in subcase b) if and only if its prime decomposition contains no factor $$p^k$$ where $$k$$ is odd and $$p$$ is a prime such that $$\left(\frac{D}{p}\right)=-1$$
• This could be the answer which I've been finding. Then, does there exist any variation which I refer as $1 \pmod {6}$ version, $1 \pmod {8}$ version, and $1 \pmod {12}$ version....and so on? If so, could you suggest some of them? Mar 15, 2022 at 13:22
• +1 for getting to the point. Correct me, if I'm wrong, but isn't the quadratic form associated with $\Bbb{Z}[\zeta_3]$ a non-diagonal form $a^2+ab+b^2$ instead of $a^2+3b^2$? Mar 16, 2022 at 20:12
• @JyrkiLahtonen you are correct, what I wrote is still right, though. The reason is that any element of $\Bbb Z[\zeta_3]$ differs only by a unit from an element of $\Bbb Z[\sqrt{-3}]$, that's an extra step one needs to do in the proof. Mar 16, 2022 at 20:18
• For general quadratic fields with discriminant $\equiv 1 \pmod{4}$ one gets a statement with a non-diagonal quadratic form. Maybe I should add such an example. Mar 16, 2022 at 20:22

Is there any variation known to this theorem?

This is a very broad question, but yes, there are many.

For example Legendre's three square theorem and Jacobi's four square theorem.

Furthermore, the sum of two cubes, three cubes, e.g., $$x^3+y^3+z^3=n$$ which became famous lately for $$n=42$$.

Staying closer to the the square theorem, one can also look at
$$ax^2+by^2=n$$ and representations of integers by quadratic forms. For example see

Representation of Positive Integers by Binary Quadratic Forms