Smoothed Mathematical Functions

The functions in this section are smoothed equivalents of the original math functions that can be used to allow computing derivatives around discontinuities.

T smooth_abs(T x, T c = 0.001)

Smoothed version of abs(), defined as:

\text{smooth\_abs}(x,c) = \left\{\begin{array}{lll}
|x| & & \text{if }x < c\text{ or } x > c\\[5pt]
x^2\left(\frac{2}{c}-\frac{1}{c^2} x\right) & & \text{if }0 \leq x \leq c\\[5pt]
x^2\left(\frac{2}{c}+\frac{1}{c^2} x\right) & & \text{if }-c \leq x < 0
\end{array}\right.

Parameters:
T x

The input value

T c = 0.001

Cut-off point for the spline-approximated area (default: 0.001)

Returns:

The smoothed absolute value, defined as above

T smooth_max(T x, T y, T c = 0.001)

Smoothed version of the max(), defined as:

\text{smooth\_max}(x,y,c) = 0.5\left(x+y+\text{smooth\_abs}(x-y,c)\right)

Parameters:
T x

First argument to max

T y

Second argument to max

T c = 0.001

Cut-off point for the spline-approximated area (default: 0.001)

Returns:

The smoothed max function, defined as above

T smooth_min(T x, T y, T c = 0.001)

Smoothed version of the min(), defined as:

\text{smooth\_min}(x,y,c) = 0.5\left(x+y-\text{smooth\_abs}(x-y,c)\right)

Parameters:
T x

First argument to min

T y

Second argument to min

T c = 0.001

Cut-off point for the spline-approximated area (default: 0.001)

Returns:

The smoothed min function, defined as above


Last update: September 2022