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$)
 A: 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.
A: If (a,b,c) is a pythagorian triple, so is (ka,kb,ck) so we only need concern ourselves with coprime  triplets (if two have a common factor the third will as well).
Note: if $n = 2k+1 = m^2$ is an odd square then $k^2 + m^2 = k^2 + 2k + 1 = (k+1)^2$.  So that is a method of generating infinite triplets:  ie. for $i \in \mathbb Z$ $(2i^2 + 2i ,2i+1, 2i^2 + 2i+1  )$
Such solutions are all of coprime pythogarian triplets.
Wolog assume $a \le b$. 
Then $a^2 = c^2 - b^2 = (c-b)(c+b)$.  $\gcd((c - b),(c+b)) | 2c$ and $\gcd((c - b),(c+b)) | 2b$ so $gcd(c-b, c+ b) =\{1,2\}$.  So $a^2 = (c-b)(c+b)$ means either both $(c + b)$ and $(c -b)$ are perfect squares or 2 times perfect squares.  But $\gcd(a, c \pm b) =\{1,2\}$ for the same reasons. So $c -b$ = 1 or 2.
If $c - b = 2$ then $a^2 = c^2 - (c - 2)^2 = 4c - 4$ as $(a/2)^2 = c - 2$ which is pretty much impossible if $0 < a < c$.
So $c = b+1$.
Not sure how to extend to n-tuples. 
A: 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$
