sng(0) = 0
but I need a symbolic function or expression that evaluates to +1
or -1
as per the following definition:
$$\mathrm{side}\left(u\right) = \begin{cases} +1, & \text{if $u \geq 0$} \\ -1, & \text{if $u \lt 0$} \end{cases}$$
I’ve tried the following but each have their own problems:
side = sgn(u) # Evaluates to 0 at u = 0
side = u/abs(u) # “ValueError: power::eval(): division by zero” at u = 0
side = 1 - (u < 0)*2 # “TypeError: unable to simplify to float approximation”
# These next two use a Python expression so ‘u’ gets evaluated too early.
side = -1 if u < 0 else 1
side = lambda u: -1 if u < 0 else 1
Is there a way I can define this function symbolically?