Assume a function

$$f(x,y) = 2\vert x \vert + 2\vert y\vert - \vert x-y \vert - \vert x+y \vert$$ If $x>y$ then $f(x,y) = 2y$, If $x<y$ then $f(x,y) = 2\vert x \vert$

How to prove this? If $x>y$ then for $x>0$, $$f(x,y) = 2x + 2y -x + y -x - y = 2y $$ for $x<0$, we have $$f(x,y) = -2x + 2y + x + y +x - y = 2y $$

Now for $y>x$, can I write $f(x,y) = 2\vert x \vert + 2\vert y\vert - \vert y-x \vert - \vert x+y \vert$, such that for $y>0$, we have $$f(x,y) = 2x + 2y - y + x -x - y = 2x$$ and for $y<0$, we have $$f(x,y) = 2x - 2y + y + x - x + y = - 2x $$

Is my logic of proof sound?


1 Answer 1


It is a bit easier to consider this equality first:


Indeed let $y=cx$ ($x\neq 0$, it is trivially verified for $x=0$), then let consider $|x+y|+|x-y|=|x|\,(|1+c|+|1-c|)$

This transformation $y=cx$ allows us to deal only with one variable $c$ instead of two $x,y$ and to reduce the number of subcases to study.

  • $c\ge 1\implies |x|(1+c+c-1)=2c|x|=2|y|$
  • $c\le -1\implies |x|(-1-c+1-c)=-2c|x|=2|y|$
  • $-1\le c\le 1\implies |x|(1+c+1-c)=2|x|$

The first two cases correspond to $|c|\ge 1\iff |y|\ge|x|$ and the third one to $|y|\le |x|$, hence the result.

As a consequence the original problem's expression becomes:



You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .