Notation to describe fetching number from set with conditions

26 Views Asked by At

I have a candidate value which is used to determine a price from a pre-set list.

i.e.

candidate = 3

if (0 < candidate < 5){
    price is x
} else if (5 < candidate t){
    price is y
} ...

Where the limits and prices are known in advance, I can use:

$$Price =\left\{{0 < candidate < 7: $4\\7 < candidate < 90: $8\\\\etc\\}\right\}$$

However, I'm not sure how I could create a general equation which shows the above, where there could be any number of conditions greater than 0 and that a candidate should fall between them. Conditions will go from 0 to infinity such that a tariff set with a single condition will be 0 < candidate < infinity.

My attempt was: $$Price =\left\{ {i: [0, n] \rightarrow Tarifs \\Tarifs_ix < candidate < Tarifs_iy : Tarifs_iPrice } \right\}$$

The above doesn't seem right though, I'm sure there's a correct way.

1

There are 1 best solutions below

0
On BEST ANSWER

As long as the bounds are strictly increasing, and the last one is $\infty$, you could write

$k = \min\{i | c < bound[i]\}; p = price[k] $

This way the min could be found by a linear or binary search.