<s>[INST] Diophatine equation $x^2+y^2+z^2=t^2$ Probably duplicate but I don't find: I'd like to solve the diophantine equation
$$x^2+y^2+z^2=a^2$$
which has solutions, by exemple $1^2+2^2+2^2=3^2$ or $2^2+3^2+6^2=7^2$. Every such solution gives a rational point on the unit sphere.
Is there a complete description of the solutions such as for pythagorician triplet?
 [/INST] We'll start with Pythagorean triples to see the pattern. The complete rational solution to $x_1^2+x_2^2 = y_1^2$ has the form,
$$((a^2-b^2)t)^2+(2abt)^2 = ((a^2+b^2)t)^2\tag{1}$$
where $t$ is a scaling factor. 
Proof: For any solution where $x_1+y_1 \neq 0$ , one can always find rational {$a,b,t$} using the formulas $a,b,t = x_1+y_1,\; x_2,\; \frac{1}{2(x_1+y_1)}$. 
Similarly, for $x_1^2+x_2^2+x_3^2 = y_1^2$, it is,
$$((a^2-b^2-c^2)t)^2+(2abt)^2+(2act)^2 = ((a^2+b^2+c^2)t)^2\tag{2}$$
Proof: One can always find rational {$a,b,c,t$} using $a,b,c,t = x_1+y_1,\; x_2,\; x_3,\; \frac{1}{2(x_1+y_1)}$.
and so on for $n$ squares. See also Sums of Three Squares for more.
</s>