<s>[INST] General integer solution for $x^2+y^2-z^2=\pm 1$ How to find general solution (in terms of parameters) for diophantine equations
$x^2+y^2-z^2=1$ and $x^2+y^2-z^2=-1$?
It's easy to find such solutions for $x^2+y^2-z^2=0$ or $x^2+y^2-z^2-w^2=0$ or $x^2+y^2+z^2-w^2=0$, but for these ones I cannot find anything relevant.
 [/INST] I think that the solutions to $x^2+y^2-z^2=-1$ are  $x=RT-SU,y=RU+ST$ where $R^2+S^2-T^2-U^2=2$ then $z=R^2+S^2-1=T^2+U^2+1$ On the surface this looks similar to the solutions to the $+1$ case. However these are quite a bit rarer and depend on the locations of the primes. 
As we know, an integer can be uniquely written as $n=ab^2$ where $a$ (the squarefree part of $n$) is a product of distinct primes. $n$ can be written as a sum of two squares $n=j^2+k^2$ precisely when  $a$ has no prime divisors of the form $4m+3$ (and we know in how many ways this can be done as well.) So the solutions depend on when we have 2 consecutive even numbers of this form. 
For example $292=73\cdot4^2$ and $290=2\cdot5\cdot329$ thus we know that there are expressions as a sum of two squares: $$292=6^2+16^2$$ $$290=1^2+17^2=11^2+13^2.$$ Running through the various possiblities gives these solutions for $R,S,T,U,x,y$ with $x^2+y^2-291^2=-1:$


*

*6, 16, 17, 1, 86, 278 

*16, 6, 11, 13, 98, 274 

*16, 6, 17, 1, 266, 118 

*16, 6, 13, 11, 142, 254 


Certain families of solutions can be given. One is $x,y,z=2p,2p^2,2p^2+1.$
</s>