# How to solve this equation with integers as a solution?

I want to solve the equation $$x^y + y = y^x + x$$ with $x$, $y$ are integer numbers. I tried

Solve[x^y + y == y^x + x, {x, y}, Integers]


How to solve the above equation?

-

First, one should mathematically analyze the problem. Obviously there are infinitely many solutions of the form {1, y} and {x, 1}, as well as {x,y} where x == y. So we can exclude such solutions from our search. Another point is remembering SystemOptions["ReduceOptions"]. There were questions dealing with them, so I'm not going to discuss these issues here; look at e.g. Solving/Reducing equations in $\mathbb{Z}/p\mathbb{Z}$.

Proceeding with similar problems, we should somehow restrict the search space. Of course, one can try e.g. x < 1000 and y < 1000, but then you would have to play with e.g. ExhaustiveSearchMaxPoints; on the other hand, if you try e.g. x < 100 and y < 100, then both Reduce and Solve work quite well:

Reduce[ x^y + y == x + y^x && 1 < x < 100 && 1 < y < 100 && x != y, {x, y}, Integers]

 (x == 2 && y == 3) || (x == 3 && y == 2)

Solve[ x^y + y == x + y^x && 1 < x < 100 && 1 < y < 100 && x != y, {x, y}, Integers]

 {{x -> 2, y -> 3}, {x -> 3, y -> 2}}


Now, one can be pretty sure that there are no other solutions besides x == y, as well as {1, y} and {x, 1} for larger numbers. The argument comes from the behavior of the exponential functions.

Edit

To make it more clear what kind of argumentation might be sufficient to prove an adequate theorem, I suggest to proceed further starting with a simple observation.

There is a symmetry between x and y, so we can assume that e.g. x is greater than y and make a substitution with k being a positive integer:

-x^y - y + y^x + x /. x -> k + y // Simplify

 k + y^(k + y) - (k + y)^y


Since we'd like to demonstrate that there are no different solutions besides those given above, let's plot the few first functions of the following family numbered with an integer parameter k:

f[ y_, k_Integer] := k + y^(k + y) - (k + y)^y


We know (see above) that these functions have roots at $y=1$; moreover, there is another root for $y > 1$, but we can simply prove that there is only one function for $k=1$ having another root at an integer point (namely $y=2$). All other functions have another root for $1 < y <2$:

Plot[ Tooltip @ Table[ f[y, k], {k, 5}], {y, 1, 2.3}, Evaluated -> True,
PlotStyle -> Thick, PlotLegends -> "Expressions", PlotRange -> {-1, 2}]


The formal proof is a simple exercise.

-