Sum of two absolute values

Consider the graph of y=x+1+x1y = |x + 1| + |x - 1|, the sum of the distances from a point xx on the number line to 1-1 and to 11.

Writing it by cases

The candidates for corners are the values where an absolute value changes sign, namely x=1x = -1 and x=1x = 1.

RangeExpression with the absolute values removedResultSlope
x<1x < -1(x+1)(x1)-(x + 1) - (x - 1)2x-2x2-2
1x1-1 \leq x \leq 1(x+1)+(1x)(x + 1) + (1 - x)2200
x>1x > 1(x+1)+(x1)(x + 1) + (x - 1)2x2x22

The corners are at (1,2)(-1, 2) and (1,2)(1, 2), and the flat bottom between them is the minimum value 22.

Why the minimum is 22

The value is obvious once distance is the picture. Stand anywhere between 1-1 and 11 and the two distances add up to exactly the gap between the points, which is 22. Step outside and you walk that excess twice over, so the sum can only grow. In symbols this is the triangle inequality.

x+1+x1(x+1)(x1)=2|x + 1| + |x - 1| \geq |(x + 1) - (x - 1)| = 2

Equality holds precisely on 1x1-1 \leq x \leq 1.

The minimum is attained along an interval

What makes this function interesting is that the minimum is attained not at a point but along a whole interval. Anywhere from 1-1 to 11, the sum of distances stays at 22. That flat bottom is the signature of a sum of absolute values.

Counting the solutions

The solutions of x+1+x1=k|x + 1| + |x - 1| = k can be read off the same shape.

Range of kkSolutions
k<2k < 2none
k=2k = 2every point of 1x1-1 \leq x \leq 1, infinitely many
k>2k > 2two, one on each outer arm

Raising and lowering the horizontal line changes the solutions in this way.

Relation to the median

Minimizing a sum of distances is a common problem in applications. On the number line, the point minimizing the total distance to several given points is their median; with an even number of points, anywhere in the interval between the middle two will do.

Quantity minimizedOptimal position
Sum of squaresthe mean
Sum of absolute valuesthe median

The robustness of the median against outliers is written right here, in this flat bottom. The large dots mark the corners and the middle point (0,2)(0, 2).