Find all solutions in positive integers of the Diophantine equation $x^2+2y^2 =z^2$ I can't solve the following exercise. It's already on this site, but the solution method is not the same as in my solutions manual.

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

The solution is given, but I do not understand the italicised parts.

13.1.8 $2y^2=z^2-x^2=(z-x)(z+x)$. $x$ and $y$ have the same parity, so $(z-x)/2$ and $(z+x)/2$ are integers. It suffices to assume $(x,z)=1$. Then either $((z-x)/2,z+x)=1$, and then $y^2=((z-x)/2)(z+x)=m^2n^2$, and solving $(z-x)/2=m^2$ and $z+x=n^2$ for $x$ and $y$ gives $x=(m^2-2n^2)/2,y=mn,z=(m^2+2n^2)/2$. Or $((z+x)/2,z-x)=1$ which gives $x=(2m^2-n^2)/2,y=mn,z=(2m^2+n^2)/2$.



*

*Why have x and y the same parity?

*Why are $(z-x)/2$ and $(z+x)/2$ integers? 

*Why do they assume $\gcd((z-x)/2,z+x)=1$ and next $\gcd((z+x)/2,z-x)=1$?

*How to solve $(z-x^2)/2 = m^2$ and $z-x=n^2$ for x and y to become the values for x, y and z?

 A: *

*$2y^2=z^2-x^2$, the left-hand side is an even number so $z,x$ must either both be even (even minus even is even) or they must both be odd (odd minus odd is even).  They did, however, mistype.  They typed $x,y$ have the same parity (false for some solutions) but meant $x,z$ gave the same parity (proven true here).

*$z-x$ must be even (by the argument above), so $\frac{z-x}{2}$ is an integer.

*$z+x$ must also be even by the exact same argument, so $\frac{z+x}{2}$ is also an integer.

*First they assume that $\gcd(x,z)=1$, because if they have a common factor, say $d$, then you have the expression:
$$2y^2=(z'd-x'd)(z'd+x'd)=d^2(z'-x')(z'+x')$$ and you can divide both sides by $d^2$ and get exactly the same expression ($x=x'd$, $y=y'd$, $z=z'd$). At some point this has to stop so you can assume that $x,z$ have no common factor.

*This is perhaps the hardest part:
Why is $$\gcd\left (\frac{(z-x)}{2},z+x\right )=1$$ or $$\gcd\left (z-x,\frac{(z+x)}{2}\right )=1$$ This follows from another result:



If $\gcd(z,x)=1$ then $\gcd(z-x,z+x)$ is $1$ or $2$

The result is proven here. Now, we know that both $z-x,z+x$ are divisible by $2$, and this is the largest factor they can have in common. Atleast one of $z-x,z+x$ is divisible by $2$ and not $4$. This means that we must have either $\gcd\left (\frac{(z-x)}{2},z+x\right )=1$ or $\gcd\left (z-x,\frac{(z+x)}{2}\right )=1$. Now, which one is it? We don't know! 


*

*If $\gcd\left (\frac{(z-x)}{2},z+x\right )=1$ then we know that $$y^2=\frac{(z-x)}{2}(z+x)$$
but $y^2$ is a square, and $\frac{(z-x)}{2},z+x$ have no factor in common! This must mean that $\frac{(z-x)}{2}=m^2$ is a square, and $z+x=n^2$ is a square. You can use this information to solve for $x,y,z$.

*If $\gcd\left (z-x,\frac{(z+x)}{2}\right )=1$ then again we know that $$y^2=(z-x)\frac{(z+x)}{2}$$
but $y^2$ is a square, and $z-x,\frac{(z+x)}{2}$ have again no factor in common! This must mean that $z-x=n^2$ is a square, and $\frac{z+x}{2}=m^2$ is a square.

