# When is a rational number a sum of three squares?

Which rational number $\dfrac pq$ can be written in the form $\left(\dfrac a b \right)^2 + \left( \dfrac c d \right)^2 + \left( \dfrac e f \right)^2$ where $a,c,e,p$ are nonnegative integers and $b,d,f,q$ are natural numbers?

It is known that a natural number can be written as sum of 3 squares iff it is not of the form $4^{a-1}(8b-1)$, where $a$ and $b$ is a natural number, due to a result of Legendre. Here by "squares" I mean they can be integers or non-integral rational. But I do not know how I can generalize these results to all rational numbers.

For the case of 2 squares it is much simpler. For a rational number $\dfrac pq$, if $p$ and $q$ are coprime, then it is a sum of 2 squares iff $p$ and $q$ can be written in terms of 2 squares, i.e. their prime decompositions do not contain a factor of the form $(4a-1)^{2b-1}$, where $a, b$ are natural numbers. But such result does not easily generalize to 3 squares.

• You seem to have only two squares here since you seek to solve $p/q=x^2+y^2$ for rational $x,y.$ – coffeemath Mar 22 '15 at 11:02
• Oops my bad. Corrected now. – wilsonw Mar 22 '15 at 11:04
• There is another option. If you imagine. $$\frac{a^2}{b^2}+\frac{c^2}{d^2}+\frac{e^2}{f^2}=\frac{p}{q}$$ How is this equation: $$qa^2+qc^2+qe^2=py^2$$ Then you can use this formula. math.stackexchange.com/questions/1127654/… – individ Mar 22 '15 at 18:19
• Can you give a reference or proof for the case of two squares mentioned in the last paragraph? See math.stackexchange.com/q/1445058/589. – lhf Sep 21 '15 at 14:11

Your question is equivalent to $qp(bdf)^2$ is sum of three squares which is equivalent to not being of the form $4^a(8b-1)$ and because $(bdf)^2$ is of the form $4^x(8y+1)$ you can easily conclude that $pq$ is not of the form $4^a(8b-1)$, the converse is also true, so as an answer:
A rational number $\frac{p}{q}$ is sum of three rational squares if and only if $pq$ is not of the form $4^a(8b-1)$
• yes we can if we say that $p$ is of the form $4^a(8b+x)$ and $q$ is of the form $4^{a'}(8b'+y)$ suct that $xy\neq-1 \mod 8$ but it's not elegant and I suspect that there is no a better way! – Elaqqad Mar 22 '15 at 11:41
• I think you mean $qp(bdf)^2$ is NOT of the form $4^a(8b-1)$... that's what the theorem says. – wilsonw Mar 22 '15 at 11:43
• It's not a deduction, The square of every integer is of the form $4^y(8x+1)$,by the following proof if $n=2^q(2p+1)$ then : $$n^2=4^q(8\frac{p^2+p}{2}+1)$$ – Elaqqad Mar 22 '15 at 11:50