# Maximum / minimum values of $z = x + |x - y|$ with constraints

Given a function $$z$$, with constraints $$|x|\le 1$$, $$|y|\leq2$$, find its minimum and maximum $$z = x + |x-y|$$ ... $$\frac{\partial f(x, y)}{\partial x} = \frac{x-y}{|x-y|} + 1$$ $$\frac{\partial f(x, y)}{\partial y} = \frac{y-x}{|x-y|}$$ Thus, it yields a system of equations, and by solving it we're to find function's extrema points: $$\begin{cases} \frac{x-y}{|x-y|} + 1 = 0 \\ \frac{y-x}{|x-y|} = 0 \end{cases}$$ I was unable to derive any solutions by brute force, and it is not quite clear to me if it is possible to do that with analytic methods. How to proceed?

What you'd like to do for the maximum is simultaneously make $$x$$ as large as possible and $$x$$ and $$y$$ as different as possible. The constraints $$|x|\le1, |y|\le2$$ allow you to this by choosing $$x=1$$ and $$y=-2$$, for a maximum value $$z=1+|1-(-2)|=4$$.
For the minimum, you want to simultaneously make $$x$$ as small as possible and $$x$$ and $$y$$ as close as possible. This happens with $$x=y=-1$$, for a minimum value of $$z=-1+|-1-(-1)|=-1$$.
\begin{align} z&=x+|x-y|\\ &\geqslant x+0\\ &\geqslant-1 \end{align} And \begin{align} z&=x+|x-y|\\ &=x+|x+(-y)|\\ &\leqslant x+|x|+|-y|\\ &=x+|x|+|y|\\ &\leqslant |x|+|x|+|y|\\ &= 2|x|+|y|\\ &\leqslant 2+2\\ &=4 \end{align} Can you find $$(x,y)$$ pairs wich for $$z=-1$$ and $$z=4$$?