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.

  • $\begingroup$ 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/… $\endgroup$
    – individ
    Mar 22, 2015 at 18:19
  • $\begingroup$ 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. $\endgroup$
    – lhf
    Sep 21, 2015 at 14:11

1 Answer 1


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)$

  • $\begingroup$ 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! $\endgroup$
    – Elaqqad
    Mar 22, 2015 at 11:41
  • 1
    $\begingroup$ I think you mean $qp(bdf)^2$ is NOT of the form $4^a(8b-1)$... that's what the theorem says. $\endgroup$
    – wilsonw
    Mar 22, 2015 at 11:43
  • 1
    $\begingroup$ I was really lost but I corrected it $\endgroup$
    – Elaqqad
    Mar 22, 2015 at 11:45
  • 1
    $\begingroup$ 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) $$ $\endgroup$
    – Elaqqad
    Mar 22, 2015 at 11:50
  • 1
    $\begingroup$ Yes you can reduce it to some finite cases $\endgroup$
    – Elaqqad
    Mar 22, 2015 at 12:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .