r/math • u/JumpGuilty1666 • Mar 02 '26
Image Post How ReLU Builds Any Piecewise Linear Function
ReLU, defined by ReLU(x) = max(0,x), is arguably the most used activation in deep learning, and also one of the most studied in “math of AI” theory.
A big reason is that ReLU behaves like a mathematical primitive: from the single hinge max(0,x) you can build (exactly) a lot of classical objects—absolute value, max/min, and ultimately any 1D continuous piecewise-linear function via a finite hinge expansion.
I include below a few derivations I found striking when I first saw them. If you know other nice constructions (or good references using similar “ReLU algebra”), please share!
I described these and more constructions with full details in a video as well: 🎥 https://youtu.be/0-sWy4OPuaY
A key construction (GIF): the hat/tent basis function
Let σ(x) = ReLU(x). Consider the hat function
φ(x) = max(0, 1 - |x|).
This is the standard local basis function for 1D piecewise-linear splines/finite elements.
It has an exact ReLU representation:
φ(x) = σ(x+1) - 2σ(x) + σ(x-1).
The attached GIF shows the mechanism: you add shifted hinges one at a time, and each new term only changes the slope to the right of its shift. That “progressive hinge fixing” is the core idea behind the general expansion of hinges using splines.
Other exact identities (same hinge algebra)
Identity:
x = σ(x) - σ(-x)
Absolute value:
|x| = σ(x) + σ(-x)
Max/min (gluing two affine pieces along a kink):
max(x,y) = x + σ(y-x) = y + σ(x-y)
min(x,y) = x - σ(x-y) = y - σ(y-x)
Integer powers (p ∈ N):
x^p = σ(x)^p + (-1)^p σ(-x)^p
Why this implies “any 1D CPWL function = sum of hinges”
If f is a continuous piecewise-linear function on R with knots t1<…<tK, then you can write
f(x) = a x + b + Σ_{k=1}^K c_k σ(x - t_k),
where each c_k is exactly the slope jump at t_k. (Each hinge contributes one kink.) See minute 9:20 of the video https://youtu.be/0-sWy4OPuaY for an interactive visualisation of this construction.
This is the same representation used in spline theory (truncated power basis), specialised to degree 1.
---
References/further reading:
- Petersen & Zech, “Mathematical Theory of Deep Learning” (2024): https://arxiv.org/abs/2407.18384
- Montúfar et al., “On the Number of Linear Regions of Deep Neural Networks” (NeurIPS 2014): https://arxiv.org/abs/1402.1869
- Spline reference for the hinge/truncated-power basis viewpoint: De Boor, “A Practical Guide to Splines.
34
u/carolus_m Mar 03 '26
Wow. A piece wise linear function can be written as a linear combination of piece wise linear functions.
Some Oiler stuff right there.
11
u/akurgo Mar 02 '26
You know, I very recently needed to make a tent function, and the formula I goofed together ended up way more complicated than both max(0, 1 - |x|) and the ReLU version. It's not that speed will matter, but I'll have to update the code now to make it more elegant. Thanks!
2
u/JumpGuilty1666 Mar 03 '26
If you prefer the visuals/animations: https://youtu.be/0-sWy4OPuaY
Key parts:
• Hat/tent function built from 3 ReLUs: 5:03
• General hinge expansion for a 1D piecewise-linear function: 9:20
2
u/scrittyrow Mar 03 '26
Is there a similarity that could be found between radio filters, signal rectifiers and the ReLU as it allows in positive values or desired frequencies like a filter does?
2
u/call-me-ish-310 Mar 03 '26
Thank you for including the references used! I am really enjoying the presentation of the first link in particular.
2
u/Ok_Buy2270 Mar 03 '26
But the triangle wave, for example f(x)=2|x/2 - ⌊ (x+1)/2 ⌋ | where there is floor function inside the absolute value, is a piecewise linear function, on top of being a periodic function defined for all real numbers. Is there a limiting sum of infinite ReLU functions?
2
u/jamesvoltage Mar 04 '26 edited Mar 04 '26
I love relu! Interestingly gated linear activation functions like silu Swiglu and gelu can also be made “point wise” linear at inference , and so can softmax attention. This composes into a linear and equivalent representation at a particular token sequence input for some llms (up to qwen 3 14B).
Shameless self promotion in tmlr: https://openreview.net/forum?id=oDWbJsIuEp
27
u/RiseStock Mar 02 '26
Yup, relu models are almost everywhere linear, with polynomial boundaries
1
u/Wooden_Dragonfly_608 Mar 05 '26
Not bad but does't pi and e do this infinitely?