0

For a programming task (an SQL expression) I need a function made of mathematical operators ($+$, $-$, $*$, $floor$, $ceil$, and comparison operators returning value $0$ (false) or $1$ (true)...) that maps a real value into 4 discrete values depending on 3 boundary values $a$, $b$, $c$ where $a < b < c$ and $x > 0$:

$$f(x, a, b, c) = \begin{cases} 0, & \text{if $x \lt a$}\\ 1, & \text{if $a \le x \lt b$}\\ 2, & \text{if $b \le x \lt c$}\\ 3, & \text{if $x \ge c$} \end{cases} $$

In SQL a CASE operator exists but but I want to avoid if because one constraint I have is the $x$ is in itself a complex expression, so the function should have $x$ mentioned just once.

As an example of the thing I need but with the simpler case of a single boundary value, for $$ f(x, a) = \begin{cases} 0, & \text{if $x \lt a$}\\ 1, & \text{if $x \ge a$} \end{cases} $$ the formula is: $f(x, a) = x \lt a$

dolmen
  • 101
  • How about $f(x)=(x\ge a)+(x\ge b)+(x\ge c)$? Does that work? – bjorn93 Dec 10 '21 at 15:51
  • For what it's worth, there is the Heaviside step function but it's just if/else in the end anyway. You can then just sum a list of them. https://en.wikipedia.org/wiki/Heaviside_step_function – PC1 Dec 10 '21 at 15:59

0 Answers0