Regularised sign

To regularise the sign a typical smooth function used is the inverse tangent or arctangent. Even better is the composition of the arctangent with the sinus. Another good approximation is given by the Error Function (erf).

Approximation with sin(atan())

The sign function is approximated with the following expression:

\[ \textrm{sign}_{\mathrm{sa}}(x)\DEF \sin\arctan(x/\kappa) = \dfrac{x}{\kappa\sqrt{1+\frac{x^2}{\kappa^2}}}.\]

The parameter \(\kappa\) is selected such that at \(x=h\) the approximation gives \(1-\epsilon\), where \(h\) and \(\epsilon\) are the tolerances specified by the user, ee Figure XO:fig:sign:SinAtan. A straightforward computation of the previous requirement yields

\[\sin\arctan(h/\kappa)= 1-\epsilon \implies \kappa = h \dfrac{\sqrt{(2-\epsilon)\epsilon}}{1-\epsilon}.\]

Because the function is odd, the same holds for \(x=-h\) where the approximation becomes \(\epsilon-1\). The first and second derivative of the \(\textrm{sign}_{\mathrm{sa}}\) function are respectively:

\[\begin{align*} \dfrac{\dd }{\dx}\textrm{sign}_{\mathrm{sa}} (x) &= \kappa^2 (\kappa^2+x^2)^{-3/2}, \\[1em] \dfrac{\dd^2 }{\dx^2}\textrm{sign}_{\mathrm{sa}}(x) &= -3\kappa^2 x (\kappa^2+x^2)^{-5/2}. \end{align*}\]

Approximation with erf

A function that closely resembles the sign function is the Error Function erf. It is scaled to fit the sharpness of the sign with a parameter \(\kappa\) such that for \(x=h\) the function \(\erf(h)=1-\epsilon\), where \(\epsilon\) and \(h\) are tolerances set by the user. In this case it is not possible to give an explicit expression for \(\kappa\), but its value is the numerical result of an easy non linear function, which is done automatically in XOptima and is invisible for the user. The approximation is

\[ \textrm{sign}_{\erf}(x)\DEF \erf(\kappa x).\]

Its first and second derivative are

\[ \dfrac{\dd }{\dx}\textrm{sign}_{\erf} (x)= \frac{2\kappa}{\sqrt{\pi}}e^{-\kappa^2 x^2}, \qquad \dfrac{\dd^2 }{\dx^2}\textrm{sign}_{\erf}(x) = -\frac{4k^3}{\sqrt{\pi}}x e^{-\kappa^2 x^2}.\]