+0

# Strict ranges (number can't be more/less than...)

0
193
2

I called these ranges strict because limit the given numbers. If x is greater or less than the limit, the function will return the limit.

I created these mathematical functions because I think that math is faster that lines of code.

Strict range (Less).

x cannot be less than s

$$l\left(s,x\right)=\min\left(s,x\right)+\left|s-x\right|$$

if x is less than s will be returned s

Strict range (Greater).

x cannot be greater than s

$$g\left(s,x\right)=\max\left(s,x\right)-\left|s-x\right|$$

if x is greater than s will be returned s

Strict range (Greater and less).

x cannot be greater than m

x cannot be less than i

$$lg(m,x, i) = g(m, l(i, x))$$

All in a heap:

$$lg\left(m,x,i\right)=\max\left(m,\min\left(i,x\right)+\left|i-x\right|\right)-\left|m-\min\left(i,x\right)-\left|i-x\right|\right|$$

lg function can be less. Thanks to @heureka (see comments below).

$$lg\left(m,x,i\right)=\min\left(m,\max\left(i,x\right)\right)$$

Look at this in Desmos: https://www.desmos.com/calculator/shusnvnxzo

Sep 22, 2019
edited by JoshuaGreen  Sep 24, 2019
edited by JoshuaGreen  Oct 22, 2019

#1
+3

Strict ranges (number can't be more/less than...)

I assume:

$$\begin{array}{|rcll|} \hline l(s,x) &=& \max(s,x) \\ g(s,x) &=& \min(s,x) \\ \hline lg(m,x,i) &=& g(m, l(i, x)) \\ \mathbf{lg(m,x,i)}&=& \mathbf{ \min(m,\max(i,x)) } \\ \hline \end{array}$$

hint: $$\boxed{\max(s,x) - \min(s,x) = |s-x|}$$ Sep 23, 2019
edited by heureka  Sep 23, 2019
edited by heureka  Sep 23, 2019
#2
+2

You're right. I did not know that the lg (all in one heap) function could be so small. I didn't know that $$\max\left(a,b\right)-\min\left(a,b\right)=\left|a-b\right|$$. Thank you.

JoshuaGreen  Sep 23, 2019