Finding all solutions: $a^2 + b^2 = c^2 + d^2$ I want to find all solutions to the problem of two squares equaling two other squares. $$a^2 + b^2 = c^2 + d^2 \qquad b \le N$$Clearly, without loss of generality, I can assume that
$$gcd(a,b,c,d) = 1$$
and $c\le a \le b \le d$. But after that, I'm a bit stuck. I can see an $N^2$ solution doing a meet-in-the-middle algorithm but I'm not sure there isn't a better way to solve this. On a Diophantine equations website it listed this problem as something "which can be done completely" but didn't give a parameterization of HOW to do it completely. Is the meet-in-the-middle the best or is there some better way to go about this?
Thanks for any help!!

This is easily solved by rearranging and factoring:
\begin{align}
a^2-c^2 &= d^2-b^2  \\
(a-c)(a+c) &= (d-b)(d+b).
\end{align}
If one of the factors is zero, than we have a trivial solution; one of the factors on the other side must also be zero, etc.
Assuming $a \ne \pm c$, we can find $g=\gcd(a-c,d-b)\ge 1$, say $a-c=gu$ and $d-b=gv$ for nonzero integers $u$ and $v$ with $\gcd(u,v)=1$. Now
\begin{align}
gu(a+c) &= gv(d+b)  \\
u(a+c) &= v(d+b).
\end{align}
Since $u$ and $v$ are coprime, we must have $a+c=kv$ and $d+b=ku$ for some nonzero integer $k$. Back-substituting will give you a parameterization (a.k.a. “complete solution”). From that point, it would be easy to apply the $N$ bound.
Bonus: This technique is equally effective for any equal sums-of-squares equation. See Bradley’s paper for more details and examples.
