solve(a_=b_, x_,y_) := solve(a-b, x,y);
solve(a_+c_*y_^2, x_,y_) := (x=solve(replace(a,y,0),x) and y=0, x=0 and y=solve(replace(a,x,0)+c*y^2,y));
solve(a_+c_*y_, x_,y_) :=  block(xx:=mod(solve(a-c,x),c), if(isinteger(left(xx)), (x=left(xx)+c*n and y=expand(-replace(a/c,x,left(xx)+c*n))), 
	(x=solve(replace(a,y,0),x) and y=0, x=0 and y=solve(replace(a,x,0)+c*y,y)) ));
solve(a_+y_, x_,y_) := block(xx:=solve(a-1,x), if(isinteger(left(xx)), x=left(xx)+n and y=expand(-replace(a,x,left(xx)+n)), (x=solve(a,x) and y=0, x=0 and y=replace(a,x,0)) ));
solve(c_+b_*x_+a_*y_+x_*y_, x_,y_) := If(isconstant(a,b,c), x=sqrt(a*b-c)-a and y=sqrt(a*b-c)-b);
solve(c_+b_*x_+a_*y_+d_*x_*y_, x_,y_) := If(isconstant(a,b,c,d), x=sqrt(a*b-c*d)/d-a/d and y=sqrt(a*b-c*d)/d-b/d);
solve(x_^2+b_*x_*y_+c_*y_^2+f_, x_,y_):=if(b==2*(c)^0.5,solve(x+sqrt(c)*y+sqrt(-f),x,y));
solve(a_*x_^2+b_*x_*y_+y_^2+f_, x_,y_):=if(b==2*(a)^0.5,solve(sqrt(a)*x+y+sqrt(-f),x,y));
solve(a_*x_^2+b_*x_*y_+c_*y_^2+f_, x_,y_):=if(b==2*(a*c)^0.5,solve(sqrt(a)*x+sqrt(c)*y+sqrt(-f),x,y));
solve((a_+x_)*(b_+y_)+c_, x_,y_) := If(isconstant(a,b,c), x=sqrt(-c)-a and y=sqrt(-c)-b);
solve(x_^2+b_*y_^2+f_,x_,y_):= x=sqrt(-f-b*n^2) and y=n;
solve(x_^2+2x_*y_+y_^2+f_,x_,y_):= solve(x+y-sqrt(-f),x,y);
solve(x_^2+(-2)*x_*y_+y_^2+f_,x_,y_):= solve(x-y-sqrt(-f),x,y);
solve(x_^2+y_^2+(-25),x_,y_):= x=3 and y=4;
solve(x_^2-y_^2+(-9),x_,y_):= x=5 and y=4;
solve(x_^2-y_^2+-(16),x_,y_):= x=5 and y=3;


solve(a_=b_, x_,y_,z_) := solve(a-b, x,y,z);
solve(x_^2+y_^2-z_^2, x_,y_,z_):= x=3 and y=4 and z=5;

solve(a_=b_,c_=d_, x_,y_,z_) := solve(a-b,c-d, x,y,z);
solve(x_^2-y_^2+b_,y^2-z^2+(-9), x_,y_,z_):= x=sqrt(25-b) and y=5 and z=4;
solve(x_^2-y_^2+b_,y^2-z^2+(-16), x_,y_,z_):= x=sqrt(25-b) and y=5 and z=3;
solve(x_^2-y_^2+(-16),y^2-z^2+c_, x_,y_,z_):= x=5 and y=3 and z=sqrt(9+c);

solve(a_=b_):=if(has(a-b,z),solve(a-b,x,y,z),solve(a-b,x,y));
solve(a_=b_,c_=d_):=solve(a-b,c-d,x,y,z);