[Math] Is the function $f(x) = |x|$ convex

convex-analysis

I am asking because some Internet pages contradict. In Wikipedia, the definition I found of a convex function is:

"Let $X$ be a convex set in a real vector space and let $f: X \to R$ be a function.

• $f$ is called convex if:

For all $x_1\ne x_2 \in X$ and for all $t\in (0,1): f(t x_1 + (1-t)x_2 ) \le tf(x_1) + (1-t)f(x_2)$.

• $f$ is called strictly convex if:

For all $x_1\ne x_2 \in X$ and for all $t \in (0,1) : f(t x_1 + (1-t)x_2 ) < tf(x_1) + (1-t)f(x_2)$."

According to this definition, the funcion $f(x) = |x|$ is convex, but in another page they say that we cannot talk about concavity of $|x|$ because it is not differentiable in $x=0$. I know that if $f''(x) \gt 0$ for all $x$, then the function is convex, but my dude is this is an "if and only if".

Can I use $f^{\prime \prime}(x)$ to define the concavity of a function?

Moreover, I am not sure of if a constant function is both concave and convex. This is a conceptual problem. I would like to know in which book I can verify if the distinction between concavity and strict concavity is valid, because I do not trust sites like Wikipedia.

Best Answer

Your condition is slightly off. A function is convex if $f''(x)\geq 0$ for all $x$. So yes, a constant function would be both concave and convex (but not strictly convex).

To show that $f(x)=|x|$ is convex, note that by the triangle inequality

$$f(tx_1+(1-t)x_2)=|tx_1+(1-t)x_2|\leq|tx_1|+|(1-t)x_2|=tf(x_1)+(1-t)f(x_2)$$

$f(x)$ is not differentiable at $x=0$, but this is okay. The theorem states that if $f$ is twice differentiable and convex then $f''(x)\geq 0$. Also note that $f''(x)\geq 0$ for all $x$ where $f''(x)$ is defined.

Convexity is a geometric condition. Think of a convex shape. If above the graph is a convex shape, then the function is called convex. This is a much more visual and natural way of thinking of it.

Using this geometric shape idea, if the corner at $x=0$ was slightly rounded and hence differentiable, it would still be the same shape basically. This geometric idea is probably the best way to look at it.

Edit for comments:

For strictly convex or convex, think about whether there are straight lines or not. Again geometrically is the best way to see these things. Think about the function $f(x)=x$. Then $f''(x)=0$. This is convex, but not strictly convex.

Geometrically, a function is convex if the area above the graph is convex (and equivalently, the area below the graph is concave) and concave if the area above is concave (area under is convex). So thinking of this geometrically, a function is strictly convex if it has a convex area above and not a convex area below the graph. This happens when there are lines.