# Is $f(x)=|x|$ a convex function?

While reading an article on Convex functions, I came across the following statement:

The absolute value function $f(x)=|x|$ is convex (as reflected in the triangle inequality), even though it does not have a derivative at the point $x = 0$.

Now we know that $f^{'}(x)=1,\text{ for }x>0$ and $f^{'}(x)=-1,\text{ for }x<0$. Considering all values of $x\neq0$, we can still conclude that $f^{''}(x)=0$ for all $x\neq0$. But a function is said to be convex iff $f^{''}(x)>0$. Where ami I going wrong? Is there another definition for convex functions?

• Lot's of definitions: en.wikipedia.org/wiki/Convex_function but what you describe with f''(x) > 0 is strictly convex. Regular convex would be f''(x) \ge 0. The geometric definition is that the points in a line segment between to points lie above or on the graph. If we require above and never on then we are talking strictly convex. – fleablood Sep 22 '16 at 19:18

According to Wikipedia a convex function is "... if the line segment between any two points on the graph of the function lies above or on the graph"

Also (again Wikipedia), "If f is twice continuously differentiable and the domain is the real line, then we can characterize it as follows - $f$ convex if and only if $f''(x) \geq 0$ for all $x$".

But your function is not twice continuously differentiable.

Here is an another proof which I find easier to understand as it involves an alternative definition of convexity (which is more intuitive I find...)

### Definition of convexity

Let $f$ be a real function defined on a real interval $I$, $f$ is convex on $I$ if and only if:

$$f(\alpha x + \beta y) \leq \alpha f(x) + \beta f(y)$$

$$\forall x,y \in I \ : \forall \alpha, \beta \in \mathbb{R}_{\geq 0}, \ \alpha + \beta = 1 \$$

### Proof that $f(x) = |x|$ is convex:

Let $x,y \in R$ and $\alpha, \beta \in R_{\geq0}$ subject to $\alpha + \beta = 1$

\begin{aligned} f(\alpha x + \beta y ) & = |\alpha x + \beta y| &\text{Definition of $f$} \\ & \leq | \alpha x | + | \beta y| &\text{Triangle inequality} \\ & = | \alpha | |x| + |\beta| |y| &\text{Absolute value is multiplicative} \\ & = \alpha f(x) + \beta f(y) &\text{By definition} \end{aligned}

source 1

source 2

What is incorrect is your definition of convex functions.

According to the wikipedia page you linked, a function is called convex if $\forall x_1, x_2 \in X, \forall t \in [0, 1]: f(tx_1+(1-t)x_2)\leq t f(x_1)+(1-t)f(x_2).$

This is not equivalent to $f''(x)>0$.

$$\forall x_1, x_2 \in X, \forall t \in [0,1], f(tx_1+(1-t)x)2) \leq tf(x_1)+(1-t)f(x_2)$$

Can you check that $|x|$ is indeed convex using this definition? Hint: Triangle inequality.

The corresponding case when second derivative exists is $f^{"}(x) \geq 0$

Lots of definitions: en.wikipedia.org/wiki/Convex_function but what you describe with $f''(x) > 0$ is strictly convex. Regular convex would be $f''(x) \ge 0$. The geometric definition is that the points in a line segment between two points lie above or on the graph. If we remove the "or on" options and require above and never on then we are talking strictly convex.

postscript: well $f''(x) > 0$ is not a definition of strictly convex either. ... sigh....

if $f''(x) > 0$ for all $x$ but then $f$ is strictly convex but the converse needn't be true. But I think if $f$ is strictly convex and $f$ is doubly differentiable then $f''(x) = 0$ can only occur for at most one $x$. I think. And, of course, $f$ need not be doubly differentiable everywhere.

Anywhoo.... a linear function $f(x) = mx + b$ is technically convex. And that is doubly differentiable everywhere $f''(x) = 0$.

• I meant to say about the same thing, one might want to add a caveat though in that I'd find it odd for say $x^{4}$ not being strictly convex even though $f''(0)=0$. Thus the characterization via the deriviative is not really one. There is also a notion of strongly convex, which amounts to $f''$ being bounded away from $0$. – quid Sep 22 '16 at 19:20
• (x^4)'' = (4x^3)'=12x^2 \ne 0 and ... oh you meant not... I see. Hmm. I guess when someone says with such earnesty that f'' > 0 is definition... – fleablood Sep 22 '16 at 19:24