<s>[INST] Find all solutions: $x^2 + 2y^2 = z^2$ I'm use to finding the solutions of linear Diophantine equations, but what are you suppose to do when you have quadratic terms? For example consider the following problem:

Find all solutions in positive integers to the following Diophantine equation
$x^2 + 2y^2 = z^2$

I'd usually start by finding the gcd and use some other tricks, but I'm not sure how to approach this type of problem
 [/INST] We can approach this in the same manner as Pythagorean Triples.
Let's only look for primitive solutions, $\gcd(x,y,z)=1$. Since
$$
z^2-x^2=2y^2
$$
$z$ and $x$ must have the same parity. That means both $z-x$ and $z+x$ are even so $y$ must be even. Therefore, for the triple to be primitive, $x$ and $z$ must be odd. Let $y=2ab$ where $(a,b)=1$ and $b$ is odd. Then, since one of $z+x$ or $z-x$ must be $2\bmod4$ and the other must be $0\bmod4$,
$$
\overbrace{2y^2}^{8a^2b^2}=\overbrace{(z+x)}^{4a^2}\overbrace{(z-x)}^{2b^2}\qquad\text{smaller factor is }2\bmod4
$$
or
$$
\overbrace{2y^2}^{8a^2b^2}=\overbrace{(z+x)}^{2b^2}\overbrace{(z-x)}^{4a^2}\qquad\text{larger factor is }2\bmod4
$$
Solving for $x$ and $z$ gives $x=2a^2-b^2$ if the smaller factor is $2\bmod4$, or $x=b^2-2a^2$ if the larger factor is $2\bmod4$. That is,
$$
x=\left|\,2a^2-b^2\right|,y=2ab,z=2a^2+b^2
$$
where $(a,b)=1$ and $b$ is odd.
For example,
$$
\begin{array}{c|cc}
a\backslash b\!\!&1&3&5&7\\\hline
1&(1,2,3)&(7,6,11)&(23,10,27)&(47,14,51)\\
2&(7,4,9)&(1,12,17)&(17,20,33)&(41,28,57)\\
3&(17,6,19)&\text{n/a}&(7,30,43)&(31,42,67)\\
4&(31,8,33)&(23,24,41)&(7,40,57)&(17,56,81)\\
5&(49,10,51)&(41,30,59)&\text{n/a}&(1,70,99)\\
6&(71,12,73)&\text{n/a}&(47,60,97)&(23,84,121)\\
7&(97,14,99)&(89,42,107)&(73,70,123)&\text{n/a}
\end{array}
$$
</s>