<s>[INST] How to find pythagorean triples and n-tuples A pythagorean triple is any set of three positive integers $(a,b,c)$ where $a^2 + b^2 = c^2$ 
I'm wondering, is there a formula to find all pythagorean triples, and can it be generalized to $n$-tuples? (i.e  $a_1^2+a_2^2+a_3^2+a_4^2+....+a_n^2=x^2$)
 [/INST] Let $t$ be a scaling factor. Then the complete rational solutions are,
$$((a^2-b^2)t)^2+(2abt)^2 = ((a^2+b^2)t)^2$$
$$((a^2-b^2-c^2)t)^2+(2abt)^2+(2act)^2 = ((a^2+b^2+c^2)t)^2$$
$$((a^2-b^2-c^2-d^2)t)^2+(2abt)^2+(2act)^2+(2adt)^2 = ((a^2+b^2+c^2+d^2)t)^2$$
and so on.
</s>