This is actually coming from a business place, but it's all about being able to do math tricks, and that's why I'm posting here.
I want to implement the following function:
f(x)= 1, x ∈ (-∞,0] 2, x ∈ (0,1500] 3, x ∈ (1500,5000] 4, x ∈ (5000,10000] 5, x ∈ (10000,+∞)
The problem is I am using a specific language (QlikView/QlikSense), which does not have any case-like statements. Currently I am using the all-too-common nested-if solution:
It works. The problem is that x is a really long and really heavy business calculation formula. Repeating it multiple times not only makes the formula a headache, but also makes me paranoid about the language itself executing the same calculation multiple times.
That's why I turned to this impressively creative community. Can you find a way, using common math functions, to create this formula without using x more than once?
The language has most math funcitons implemented. There are a few of its own as well, but I doubt they are going to help (There is already a range-splitting one, but it won't work with non-symmetrical ranges like here). Nothing to stop you from researching though.