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
 A: Since the equation is homogeneous, we may WLOG assume $\gcd(x, y, z)=1$. (So that all solutions will be given by multiplying all the primitive solutions by any positive integer $k$) 
Now if $x$ is even, then $z$ is even, so $y$ is also even, a contradiction. Thus $x$ is odd, so $z$ is odd, and so $x^2 \equiv z^2 \equiv 1 \pmod{4}$. Thus $4 \mid 2y^2$, so $y$ is even. Note that if $p \mid x, z$ for some prime $p$, then $p$ is odd and $p \mid 2y^2$, so $p \mid y$, a contradiction, so $\gcd(x, z)=1$.
Let $y=2y'$, so that $2y'^2=\frac{z^2-x^2}{4}=(\frac{z-x}{2})(\frac{z+x}{2})$. Now $\gcd((\frac{z-x}{2}),(\frac{z+x}{2}))=\gcd(x, z)=1$, so we have 2 cases:
Case 1: $4 \mid z-x$. Then we have $\frac{z-x}{2}=2a^2, \frac{z+x}{2}=b^2, y'=ab$ for some $a, b \in \mathbb{Z}^+$, so $z=b^2+2a^2, x=b^2-2a^2, y=2ab, \, b>a\sqrt{2}>0$. Checking, these are indeed solutions.
Case 2: $4 \mid z+x$. Then we have $\frac{z-x}{2}=b^2, \frac{z+x}{2}=2a^2, y'=ab$ for some $a, b \in \mathbb{Z}^+$, so $z=b^2+2a^2, x=2a^2-b^2, y=2ab, \, a\sqrt{2}>b>0$. Checking, these are indeed solutions.
Therefore all primitive solutions are given by $(x, y, z)=(|b^2-2a^2|, 2ab, b^2+2a^2), a, b \in \mathbb{Z}^+$.
Therefore all positive integer solutions are given by $$(x, y, z)=(k|b^2-2a^2|, k(2ab), k(b^2+2a^2)), a, b, k \in \mathbb{Z}^+$$
A: Here's the identity that completely solves it,
$$((a^2-nb^2)t)^2+n(2abt)^2 = ((a^2+nb^2)t)^2\tag{1}$$
for arbitrary $a,b$ and scaling factor $t$. Yours is just the case $n = 2$.
EDIT:
To address ShreevatsaR's comment if this is the complete solution (when $x_1 x_2 x_3 \ne 0$), given rational $x_1, x_2, x_3$ such that,
$$x_1^2+nx_2^2 = x_3^2\tag{2}$$
one can always find particular rational $a,b,t$ that recovers those values using the formulas,
$$\begin{aligned}a &= x_1+x_3\\
b &= x_2\\
t &= \frac{1}{2(x_1+x_3)}\end{aligned}\tag{3}$$
Example: Given the smallest solution to ,
$$x_1^2+2x_2^2 = x_3^2$$
as {$x_1, x_2, x_3$} = {$1, 2, 3$}, then using (3), we find,
$$\begin{aligned}a &= 4\\
b &= 2\\
t &= 1/8\end{aligned}$$
which yields,
$$\begin{aligned}x_1 &= (a^2-2b^2)t = 1\\
x_2 &= 2abt = 2\\
x_3 &= (a^2+2b^2)t = 3\end{aligned}$$
which are precisely the values we started with. I hope everything is clear? 
A: The following method can be used to find all points on conics if one solution is obvious.


*

*Divide by $z^2$ to obtain $(x/z)^2 + n(y/z)^2 = 1$. This implies the question is equivalent to finding the rational points on the curve $x^2+ny^2 = 1$. (Equivalent in the sense that every integer solution for $x^2+ny^2=z^2$ gives a rational solution for $x^2+ny^2=1$ and vice versa.)

*Note that $(1,0)$ is a solution. If $(x_0,y_0)$ is an other solution, then we can draw the line between these two points. This line will have rational slope (since both points are rational).

*Thus we can recover all rational points on the curve by drawing lines through $(1,0)$ with rational slope and determining the intersection with the curve.

*Such a line can be parametrized by $$ \begin{aligned} x-1 &= rt \\ y &= t\end{aligned}, $$ where $t$ is the parameter and $r$ the (arbitrary) slope. (Actually you have to check the case where "$r=\infty$", i.e. $x-1=t$ and $y=0$ as well. This results in the solution $x=-1$ and $y=0$.)

*Subsituting in the equation $x^2 + ny^2 = 1$, cancelling $1$'s and dividing by $t$ (which expresses that $(1,0)$ is a solution), we find $$ \begin{aligned} x &= \frac{n-r^2}{n+r^2} \\ y &= \frac{-2r}{r^2+n} \end{aligned}.$$

*Any integer solution for the original equation comes from the rational $x,y$'s above.  It's a bit a pain, but first write $r = a/b$ and then find out by what common factors you can multiply $x$ and $y$ to make sure that they both are integers. 

A: Um. For any prime $p \equiv 1,3 \pmod 8,$ there is a representation $p = u^2 + 2 v^2,$ as a result of which there is also a primitive representation $p^2 = u_2^2 + 2 v_2^2$ by Tito's formula. There is a representation of $4$ but not primitive. Finally, there is the trivial representation $q^2 = x^2$ when $q \equiv 5,7 \pmod 8.$ So, in fact, if you allow non-primitive answers, $z$ can be anything at all, and if $z$ has any factor $p \equiv 1,3 \pmod 8,$ there is a solution $z^2 = x^2 + 2 y^2$ with nonzero $y.$
Oh, products are not a problem, 
$$ (u^2 + 2 v^2)(x^2 + 2 y^2) = (ux + 2 vy)^2 + 2 (uy-vx)^2.   $$
Notice that negating one of these, as $v,$ gives a genuinely different formula on the right hand side.
This procedure does give all solutions; if you can factor $z,$ you can build all $(x,y).$
EEDDIITT: As an alternative, we can take the ellipse $x^2 + 2 y^2 = 1$ and parametrize all rational points, a procedure which gives everything and was called to my attention by Gerry Myerson. Done here Generating Pythagorean triples for $a^2+b^2=5c^2$? for the problem $a^2 + b^2 = 5 c^2. $ Went through it for rational points on the ellipse $x^2 + 2 y^2 = 1$ by lines through $(1,0).$ The result is exactly what Ivan Loh got, but without any thinking. I'm getting quicker at this. 
A: Basically, I will also transform the problem into that of finding rational points on the ellipse $x^{2}+2y^{2}=1$ as other answers did but I will use the Hilbert's Satz 90.
I will prove the following:
Solutions $(u,v)\in\mathbb{Q}^{2}$ of the Diophantine equation $u^{2}+2v^{2}=1$ is of the form $u=\frac{m^{2}-2n^{2}}{m^{2}+2n^{2}},v=\frac{-2mn}{m^{2}+2n^{2}}$.
Consider the Galois extension $\mathbb{Q}(\sqrt{-2})/\mathbb{Q}$. Write $u=\frac{x}{z},v=\frac{y}{z}~(x,y,z\in\mathbb{Z})$. Let $a=\frac{x+y\sqrt{-2}}{z}$. Then $N_{\mathbb{Q}(\sqrt{-2})/\mathbb{Q}}(a)=\frac{x+y\sqrt{-2}}{z}\cdot\frac{x-y\sqrt{-2}}{z}=\frac{x^{2}+2y^{2}}{z^{2}}=1$. 
Thus, $a=\bar{b}/b$ for some $b\in\mathbb{Q}(\sqrt{-2})^{*}$ since $H^{1}(\text{Gal}(\mathbb{Q}(\sqrt{-2})/\mathbb{Q}),\mathbb{Q}(\sqrt{-2})^{*})$ is trivial. Choose $s\in\mathbb{Z}$ so that $bs\in\mathbb{Z}[\sqrt{-2}]$.
Then $\frac{\bar{b}s}{bs}=a$. Write $bs=m+n\sqrt{-2}$. Then $a=\frac{m-n\sqrt{-2}}{m+n\sqrt{-2}}=\frac{(m-n\sqrt{-2})^{2}}{m^{2}+2n^{2}}=\frac{(m^{2}-2n^{2})+(-2mn)\sqrt{-2}}{m^{2}+2n^{2}}$. Hence, $u=\frac{m^{2}-2n^{2}}{m^{2}+2n^{2}},v=\frac{-2mn}{m^{2}+2n^{2}}$.
A: 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}
$$
