Find all solutions: $x^2 + 2y^2 = z^2$

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}^+$$


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?


The following method can be used to find all points on conics if one solution is obvious.

  1. 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.)
  2. 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).
  3. 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.
  4. 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$.)
  5. 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}.$$
  6. 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.