<s>[INST] Parametrization of solutions of diophantine equation $x^2 + y^2 = z^2 + w^2$ I need integer solutions of $x^2 + y^2 = z^2 + w^2$ parametrized. Can it be done? Thanks.
 [/INST] First let us solve equation
$$
xy-zt=0.
$$
Let $(x,y,z,t)$ be any solution with $x\neq 0$, and let $u=\text{gcd}(x,z)>0$. Then $x=uv$ and $z=uw$ with $v,w$ coprime and $v\neq 0$. Then $xy-zt=0$ implies that $uvy=uwt$, or $vy=wt$. Because $v$ and $w$ are coprime, this implies that $t$ is divisible by $v$, so we can write $t=vr$ for some integer $r$. Then $vy=w(vr)$, hence  $y=wr$. In conclusion, any solution $(x,y,z,t)$ with $x\neq 0$ is representable in the form
$$
(x,y,z,t)=(uv,wr,uw,vr) \quad \text{for some integers} \,\, u,v,w,r. 
$$
If $x=0$, then either (a) $z=0$ and $y,t$ are arbitrary, or (b) $t=0$ and $y,z$ are arbitrary. However, these cases are also covered by the above family: take $u=0$, $r=1$ and $v,w$ arbitrary in case (a) and $v=0$, $w=1$, and $u,r$ arbitrary in case (b).
Now we are ready to solve the equation
$$
x^2+y^2=z^2+t^2.
$$
If $x$ and $y$ are both even, then $x^2+y^2$ is divisible by $4$, hence so is $z^2+t^2$, which is possible only if $z$ and $t$ are both even. Similarly, if $x$ and $y$ are both odd, then so are $z$ and $t$, and if $x$ and $y$ are of opposite parities, then so are $z$ and $t$. Hence, by permuting $z$ and $t$ if necessary, we may assume that $x$ and $z$ are of the same parity, and so are $y$ and $t$. Then rewrite the equation as
$$
\frac{x-z}{2}\cdot \frac{x+z}{2} = \frac{t-y}{2}\cdot \frac{t+y}{2}.
$$
Hence
$$
\left(\frac{x-z}{2},\frac{x+z}{2},\frac{t-y}{2},\frac{t+y}{2}\right)=(uv,wr,uw,vr) \quad \text{for some integers} \,\, u,v,w,r. 
$$
Thus, integer solutions to $x^2+y^2=z^2+t^2$ are
$$
(x,y,z,t)=\left(wr+uv,vr-uw,wr-uv,vr+uw\right), \quad u,v,w,r \in {\mathbb Z},
$$
as well as the solutions obtained from the above by swapping $z$ and $t$.
</s>