<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] we can create an n-tuple of any length by finding an $A$ to match the $C$ of any previous triangle.
For $A=m^2-n^2$, we let $n=\sqrt{m^2-A}$ where $\lceil\sqrt{A+1}\space\rceil\le m\le \bigl\lceil\frac{A}{2}\bigr\rceil$. If any $m$ yields a positive integer $n$, we have $(m,n)$ for a Pythagorean triple.
The simplest triple is $3,4,5$ and we let $A=\sqrt{m^2-5}$ where;
$$m_{min}=\lceil\sqrt{5+1}\space\rceil=3\quad M_{max}=\lceil\frac{5}{2}\space\rceil=3$$
This one was easy: $n=\sqrt{3^2-5}=2\quad f(3,2)=(5,12,13)$
Let's try $(21,20,29)$. We have $A=29\implies 6\le m \le 15$ and we find $only$ $f(15,14)=(29,420,421)$
If we continue the process begun with $(3,4,5)$ we can find $(3,4,5)\rightarrow(5,12,13)\rightarrow(13,84,85)\rightarrow(85,132,157)\rightarrow(157,12324,12325)\text{ and so on.}$
So far, we have $3^2+4^2+12^2+84^2+132^2+12324^2=12325^2$
</s>