Solutions to a system of Diophantine equations In my research in a different field (representation theory), the following system of equations popped up:
$$
ax=by
$$
$$
xy+a+b-ax=p
$$
where $p\in\{0,1,2,3,4\}$ and $a,b,x,y$ are integers (I am also interested in the case where x and y are rationals). I have found some solutions in some special cases e.g. when a=0 or x=2. I also wrote a simple python script to find solutions and it seems to indicate that there should be a few infinite families of solutions and a few sporadic ones. However, this is not my field at all, and I am quite unsure about the difficulty of solving such a system. Does it seem likely that one can determine all (positive) integer solutions? All solutions with x, y rational?
 A: Here is the general solution for general value of $a$ and the set of values in $b$ which is dense in an infnite interval (dpending on $a$). More precisely, solve the first equation with respect to $y$ and get $y=a/bx$. We thus left with the quadratic equation in $x$ of the form:
$$
f(x):=ax^2-abx+b(a+b-p)=0.
$$
To get a rational solution in $x$ the discirminant of $f$ given by
$$
\Delta_{f}=(a-4)ab^2+ab(4p-4a)
$$
needs to be a square, i.e., we work with the deqree two equation $Y^2=\Delta_{f}$. We treat this equation in the $b-Y$ plane treating $a, p$ as a dummy variables. To get the solution we just put $Y=bt$, where $t$ is rational parameter. After necessary simplifications we get the solution
$$
b=\frac{4 \left(a^2-a p\right)}{a^2-4 a-t^2},\quad Y=bt.
$$
If $a^2-4a\geq 0$ then the rational function $b=b(t)$ has a pole and thus the set $b(\mathbb{Q})$ is dense in an appropriate interval.
A: Here is solution in positive integers.
The equation $ax=by$ implies that there are four integers $u,v,w,t$ such that $a=uv$, $x=wt$, $b=uw$, $y=vt$.
Then the second equation takes form
$$vwt^2 + uv + uw - uvwt = p.$$
There are two cases:
Case $u\leq t$. We have
$$uv + uw \leq p,$$
which has a finite number of solutions in $u,v,w$, which further give quadratic equation with respect to $t$, and so a finite number of solutions in $u,v,w,t$.
Case $u>t$. Let $d:=u-t>0$. Substituting $u=t+d$ we obtain
$$tv + dv + tw + dw - dvwt = p$$
that is
$$(tv - 2)(dw - 2) + (dv - 2)(tw - 2) = 8 - 2p.$$
Here we first consider the subcase when all $tv,dw,dv,tw\geq 3$ with a finite number of solutions. Then we consider 8 subcases with each of these products equal 1 or 2. For example:

*

*if $tv=1$, then $t=v=1$ further implying $d+w=2p-2$, again with a finite number of solutions.

*if $tv=2$, then $(t,v)=(1,2)$ or $(t,v)=(2,1)$, implying $(2d - 2)(w - 2) = 8 - 2p$ or $(d - 2)(2w - 2) = 8 - 2p$, respectively. Here we have a finite number of solutions unless $p=4$, in which case there are infinite series of solutions such as $(v,t,d)=(2,1,1)$ and arbitrary $w$.

