[Math] Which rationals can be written as the sum of two rational squares

number theory

Which rational numbers can be written as the sum of two rational squares?

That is, for which rational numbers $a$, are there rational numbers $x$ and $y$ such that $a = x^2 + y^2$.

It is a famous theorem that if an integer can be written as the sum of two rational squares then it can be written as the sum of two integral squares, and then the solution is the famous one by Fermat, but I didn't find anything about the general case.

Best Answer

Let $r=\frac{p}{q}$, where $p$ and $q$ are integers. We will show that $r$ can be written as the sum of two rational squares if and only if $pq$ can be written as the sum of the squares of two integers.

Equivalently, if $p\ne 0$, then $\frac{p}{q}$ is a sum of the squares of two rationals if and only if every prime divisor of $pq$ of the form $4k+3$ occurs to an even power.

Proof: If $pq$ is the sum of the squares of two integers, it is clear that $r$ is the sum of the squares of two rationals.

For the other direction, suppose that $r$ can be written as the sum of the squares of two rationals. Without loss of generality we may assume that the rationals are $\frac{a}{c}$ and $\frac{b}{c}$ for some integers $a,b,c$. Then $$\frac{a^2+b^2}{c^2}=\frac{pq}{q^2}.$$ So $c^2pq$ is a sum of two squares. It follows that every prime of the form $4k+3$ occurs to an even degree in the prime power factorization of $c^2pq$, and hence of $pq$. It follows that $pq$ is a sum of two squares.