# In a certain sense, can "Piecewise Linear" be Interpreted as "Non-Linear"?

I was looking at the following function (called "ReLU") :

I am trying to understand why this function ("ReLU") is considered to be non-linear, when it appears to look "piecewise linear" (and even contains the term "linear" in its name):

• Can someone please explain why the "ReLU" function is described as non-linear, when it seems to be linear in appearance? Is it possible that the individual "pieces" of the ReLU function are linear, but the entire function itself is somehow non-linear?

• When functions are defined in "pieces" - can we still determine if the entire function is "convex" or "non-convex" - or are we forced to only label the individual pieces of the function as convex and non-convex?

Thanks!

References:

• To see why the function is said to not be linear, consider the definition of "linear." In the context of linear algebra, linear means $R(x+y)=R(x)+R(y)$, which is not true for this function $R$. In the context of elementary algebra, it means the graph is a line, which is also not true (it is multiple line segments / rays, not a line). Bottom line: words actually mean things, and "linear" is a word. Jan 24 at 22:42
• If a piece of a function's graph (i.e. the function's restriction to a smaller interval) is not convex, then neither is the function as a whole. The converse is not true: even if all "pieces" of a function are convex, that does not guarantee the function as a whole is convex. That means more work needs to be done to determine if such a function as a whole is convex or not. Jan 24 at 22:47
• "When functions are defined in "pieces"" $\;-\;$ It is not useful to think of function definitions as being "in pieces" vs. not. A function is the same function no matter how you write its definition. You can define for example $|x|=\sqrt{x^2}$ in one piece, or you can write the definition piecewise for $\mathbb R^-, \mathbb R^+$ but it's still the same function in either case. And, like any local behaviors, a property that applies to only part of the domain does not necessarily apply to the entire domain e.g. $\sqrt{|x|}$ is concave on $\mathbb R^-,\mathbb R^+$ but not on $\mathbb R$.
– dxiv
Jan 25 at 0:15
• @runway44: Surely if all "pieces" of a function are convex, then the function is convex? Jan 25 at 0:19
• @TonyK Not necessarily, consider for example \,f(x) = \begin{cases}\begin{align}e^{-x} & & x \ge 0 \\ e^{x} & & x \lt 0\end{align}\end{cases}\,.
– dxiv
Jan 25 at 0:27

There are two competing definitions for a linear function $$f:\Bbb R\mapsto\Bbb R$$, but neither of them would allow ReLU.

The first definition most are exposed to is that a linear function is polynomial of degree 1, i.e. a function in the form

$$f(x) = ax + b$$

(as Brian Borchers points out in the comments, this type of function is usually called affine beyond elementary algebra to avoid conflict with the second definition below)

The second definition comes from linear algebra, and is a restriction on this class of functions. We say a function is linear iff

$$f(x+\alpha y) = f(x) + \alpha f(y)$$

for $$x,y$$ from some vector space and $$\alpha$$ from the underlying field. In this case, the vector space and the underlying field are both $$\Bbb R$$, and this implies the form

$$f(x) = ax$$

for all such functions.

Any attempt to put ReLU into this form will result in a function which is only valid on a half-line. To agree with the left half-line, we need $$f(x) \equiv 0$$; for the right half-line, we need $$f(x) = x$$.

Because there is a partition of the line into intervals such that ReLU is linear (in both senses) on the interior of each interval, we say that ReLU is piecewise linear. Obviously, any linear function is piecewise linear, but the same is not true in reverse, as we see here with ReLU.

So, to directly answer your question, "piecewise linear" should not be interpreted as "nonlinear" in general, but there are piecewise linear functions which are nonlinear (and those which are linear).

As with linearity, we can discuss convexity in both global and piecewise contexts.

A function is called convex on some domain when every pair of points $$x,y$$ in that domain has

$$f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)$$

for all $$\theta\in [0,1]$$.

Linear functions (in both senses) are convex, and so piecewise linear implies piecewise convex. Thus, ReLU is (at least) piecewise convex. However, we can directly verify that ReLU is globally convex as well by substituting the definition into the above inequality.

• Functions of the form $f(x)=ax+b$ are called "affine" to distinguish them from the other kind of linear function. Jan 25 at 0:09
• @BrianBorchers I agree in principal, but there are enough references that use "linear" to refer to affine functions on $\Bbb R$ (likely because their graphs are lines) that it warrants consideration. The purpose of the inclusion in this answer was to show that even the more permissive idea of linear functions fails to include ReLU. Jan 25 at 0:23
• @ Alex Jones: Thank you so much for your answer! Are we also able to determine if the ReLU function is "convex"? thank you so much! Jan 25 at 3:38
• @stats555 I added a brief discussion of convexity to the answer, but in short: ReLU is indeed globally convex. Jan 25 at 14:12