Quadratic Diophantine Equation $x^2 + axy + y^2 = z^2$ I have been reading about this quadratic Diophantine equation of the form
$x^2 + axy + y^2 = z^2$
where x, y, z are integers to be solved and a is a given integer.
All integral solutions are given by
$x = k(an^2 - 2mn), y = k(m^2 - n^2), z = k(amn - m^2 - n^2)$ and
$x = k(m^2 - n^2), y = k(an^2 - 2mn), z = k(amn - m^2 - n^2)$
(due to diagonal symmetry in x and y)
where $m,n$ are integers with $\gcd(m,n) = 1,$ but $k \in \mathbb Q$ is rational such that $(a^2 - 4) \, k \in \mathbb Z.$ This is Theorem 2.3.2. on page 90 of An Introduction to Diophantine Equations by Andreescu, Andrica, and Cucurezeranu. (2010). EDIT BY WILL JAGY.
I have no problem understanding how the solution forms were derived; they were just basic algebraic manipulation. But then when it comes to the solutions in positive integers, the form becomes
$x = k(an^2 + 2mn), y = k(m^2 - n^2), z = k|amn + m^2 + n^2|$ and
$x = k(m^2 - n^2), y = k(an^2 + 2mn), z = k|amn + m^2 + n^2|$
where k, m, n are positive integers, an + 2 m > 0 and m > n.
What I can understand is that we apply modulus to the x, y, and z in the previous form to get the latter form (we want x, y, and z to be in positive integers), but I can't seem to understand how an + 2 m > 0 and m > n work to prove
$|x| = |k(an^2 - 2mn)| = kn|an - 2m| = kn(an + 2m) = k(an^2 + 2mn)$ and
$|z| = |k(amn - m^2 - n^2)| = k|amn + m^2 + n^2|$.
Can anyone help me on this? I've been pondering for almost a week. It's driving me crazy. Thank you in advance.
 A: If in the general integer solution, the parameter $n$ is replaced by $-n$, then one has
$$\{x,y\}=\{k(an^2+2mn),\ k(m^2-n^2)\},\ z=k(-amn-m^2-n^2).$$
This still describes all integer solutions, provided $m,n,k$ are allowed to be any integers. In an attempt to get only the solutions for which $x,y,z>0$ it might be tempting to suppose $m,n,k$ to be positive and then impose $m>n$ and also $an+2m>0,$ in order to force $x,y>0$, and then also place absolute values around the $z$ formula, to make $z>0$ also (since perhaps $a<0$ that would be necessary).
However doing this one will miss some positive solutions. Consider the case of $a=5$ and the solution $(x,y,z)=(1,3,5)$ to the equation $x^2+5xy+y^2=z^2.$ If one insists on positive $m,n$ as in the above formulas, then it must be that $k=1$ (since gcd of 1,3,5 is 1), and also $m^2-n^2=1$ is not possible as then $m=1,n=0$ against positivity. So it must be that $m^2-n^2=3,$ so that $m=2,n=1$ But the values $(m,n,k)=(2,1,1)$ lead to the wrong value for the other variable. That is, in the "positive $m,n,k$" formulation, if it is $x$ which is $3$, then $y$ doesn't come out $1$ under $(m,n,k)=(2,1,1).$ Instead it comes out $1\cdot(5\cdot 1^2+2 \cdot 2 \cdot 1)=9.$ 
Note that if we allow negative $m$ or $n$ we can get the solution $x,y,z=1,3,5$ using $k=1,m=2,n=-1.$
