Solving a Quadratic Diophantine equation for three variables I am trying to solve the following Diophantine equation $13x^2-y^2=z^2$. Is there a standard method for generating x and y so that $13x^2-y^2$ is always a square? Mathematica gives me the following triples $(x, y, z)$ as the first six primitive solutions: $(1, 2, 3), (1, 3, 2), (5, 1, 18), (5, 6, 17), (5, 17, 6), (5, 18, 1)$: though there appears to be  an infinite number of solutions.
 A: There is indeed a standard method, which is the same as the standard method used to parametrize all Pythagorean triples (and indeed, integer solutions of any quadratic form in three variables).
Forgetting the solution $(0,0,0)$, your equation is equivalent to $r^2+s^2=13$, where $r=\frac yx$ and $s=\frac zx$ are rational numbers. Fix your favorite rational solution, say $(r_0,s_0)=(2,3)$. Then the rational points on the circle $r^2+s^2=13$ other than $(2,3)$ are in one-to-one correspondence with lines through $(2,3)$ of rational slope. (Proving this isn't hard, and is the same as the Pythagorean case, but is an educational exercise.)
So the general rational solution $(r,s)$ to $r^2+s^2=13$ can be found by intersecting the line $s-3=m(r-2)$ (where $m$ is a generic rational number) with the circle:
\begin{align*}
r^2+(m(r-2)+3)^2&=13 \\
(m^2+1)r^2+(6 m-4m^2) r+(4 m^2-12 m-4)&=0 \\
(r-2) \big( (m^2+1) r-(2 m^2-6 m-2) \big)&=0.
\end{align*}
(We knew $r=2$ would be a solution ahead of time, so factoring the polynomial isn't that hard.) Ignoring the solutions $(2,\pm3)$, we see the general solution is
$$
r = \frac{2 m^2-6 m-2}{m^2+1}, \quad s=m(r-2)+3=\frac{-3 m^2-4 m+3}{m^2+1}.
$$
This essentially solves the original problem, other than the fact that these fractions may not be in lowest terms (but the gcd of the top and bottom is always a divisor of $26$, in this case).
