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

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. 
