Derivation of Pythagorean Triple General Solution Starting Point: I was reading on proof wiki about the derivation of the general solution to the pythagorean triple diophantine equation:
$$
x^2 + y^2 = z^2, 
$$
where $x,y,z > 0$ are integers.
I came across the following general solution to the primitive function:
\begin{align*}
x &= 2mn\\
y &= (m^2 - n^2)\\
z &= (m^2 + n^2)\\
\end{align*}
for coprime $m,n$.
I looked at the proof of it working (if you square $x$ and $y$ and add it it does indeed equal $z^2$) 
My one qualm was, how the hell did they start with that? For example, is there a natural way by starting with the original problem that you end up with the expression above?
I noticed that when attempting to derive the general solution myself, from start to finish,
I would begin by noting I can find all pairs such that $z$ and $y$ differ by a constant $k$... but I cannot make that final leap to end up with the equation above so that for any given $k$ you can find a solution.
Thanks ahead of time!

Here is the way to generate all relatively prime pythagorean triples:
Theorem: Let $m$ and $n$ be positive integers so that
$$
\begin{align} 
&m\gt n\tag{1}\\
&m+n\text{ is odd}\tag{2}\\
&m\text{ and }n\text{ are relatively prime}\tag{3}
\end{align}
$$
Then,
$$
\begin{align}
a &= m^2 - n^2\\
b &= 2mn\\
c &= m^2 + n^2
\end{align}\tag{4}
$$
gives all positive, relatively prime $a$, $b$, and $c$ so that
$$
a^2 + b^2 = c^2\tag{5}
$$
Proof: $(5)\Rightarrow(4):$
Suppose $a$, $b$, and $c$ are positive, relatively prime, and $a^2 + b^2 = c^2$.
Because $(2k)^2 = 4k^2$ and $(2k+1)^2 = 4(k+1)k + 1$, the square of an even
integer must be $0 \bmod{4}$ and the square of an odd integer must be $1 \bmod{4}$.
At least one of $a$ and $b$ must be odd; otherwise $a$, $b$, and $c$ would share a
common factor of $2$.  If both are odd, then $c^2$ would need to be $2 \bmod{4}$,
which is impossible.  Thus, one must be even and the other must be odd. This means that $c$ must be odd.  Without loss of generality, let $b$ be even.
Let $M = (c+a)/2$ and $N = (c-a)/2$.  Then
$$
\begin{align}
a &= M - N\tag{6}\\
c &= M + N\tag{7}\\
b^2 &= 4MN\tag{8}
\end{align}
$$
Thus, we have that $M \gt N \gt 0$ and one of $M$ and $N$ must be even and the othermust be odd.  Furthermore, $\gcd(M,N)$ divides $a$, $b$, and $c$; thus, $\gcd(M,N) = 1$. Since $b^2 = 4MN$ and $\gcd(M,N) = 1$, both $M$ and $N$ must be perfect squares.  Let $M = m^2$ and $N = n^2$, where $m$ and $n$ are positive; then, $(1)$, $(2)$, $(3)$, and $(4)$ are satisfied.
$(4)\Rightarrow(5):$
Suppose $(1)$, $(2)$, $(3)$, and $(4)$ are satisfied.  Then $(5)$ is satisfied:
$$
\begin{align}
a^2 + b^2
&= (m^2 - n^2)^2 + (2mn)^2\\
&= m^4 - 2 m^2 n^2 + n^4 + 4 m^2 n^2\\
&= m^4 + 2 m^2 n^2 + n^4\\
&= (m^2 + n^2)^2\\
&= c^2\tag{9}
\end{align}
$$
Furthermore, $a$ and $b$ are relatively prime since
$$
\begin{align}
\gcd(a,b)
&= \gcd(m^2-n^2,2mn)\\
&\:\mid\:\gcd(m-n,2) \gcd(m-n,m) \gcd(m-n,n)\\
&\times\gcd(m+n,2) \gcd(m+n,m) \gcd(m+n,n)\\
&=\gcd(m+n,2)^2 \gcd(n,m)^4\\
&= 1\tag{10}
\end{align}\\
$$
$\square$
