TITLE: Finding the integer solution that makes $\lvert x-y \rvert$ the greatest?
QUESTION [5 upvotes]: I was attempting to solve this problem. 
Let $x,y$ be non-negative integers which satisfy the equation. 
$$2^{x} +2^{y} = x^{2} +y^{2}$$
Find the maximum possible value for $\lvert x-y \rvert$?
At first I tried constructing a function of two variables and finding critical points but the critical points ended up having non-integer values. Then I tried manipulating the equation to get $x^2 +y^2$ to look like $\lvert x-y \rvert$ but that didn't help make it easier to find integer solutions. I ended up trying to guess solutions to the equation and the best I could come up with was $(3,0)$ which gives $\lvert x-y \rvert$ a value of $3$. Only thing is that I'm not sure if this is the highest that you can get the value of $\lvert x-y \rvert$ to be. 
I was wondering is there any way to solve this problem without guessing and prove that the solution you get is what maximizes $\lvert x-y \rvert$?

REPLY [3 votes]: Consider the function $f(x)=2^x-x^2$:

Note that for $x\ge5$, $f(x)\ge7$. Thus, there is no value $y$ so that $f(x)+f(y)=0$ since $f(y)\gt-2$.
Looking at the data, we get solutions of
$$
\{(0,3),(1,3),(2,2),(2,4),(3,0),(3,1),(4,2),(4,4)\}
$$
Thus, the solutions with the greatest $\left|x-y\right|$ are $\{(0,3),(3,0)\}$. Therefore,
$$
\max\left|x-y\right|=3
$$

$\boldsymbol{f(x)}$ is convex for $\boldsymbol{x\ge3}$ and increasing for $\boldsymbol{x\ge4}$
Since $f''(x)=\log(2)^22^x-2$, we have $f''(x)\ge0$ when $x\ge1-2\log_2(\log(2))$. And since $2^2\gt e\implies\log(2)\gt\frac12\implies\log_2(\log(2))\gt-1$, we get that $3\gt1-2\log_2(\log(2))$.
Therefore, $f''(x)\ge0$ when $x\ge3$.
Furthermore, since $\frac{f(4)-f(3)}{4-3}=1$, the Mean Value Theorem says that $f'(x)=1$ for some $x\in(3,4)$. Since $f(x)$ is convex for $x\ge3$, we have that $f'(x)\ge1$ for $x\ge4$.