Is there a predefined mathematical function for $ f(x) = \left\{\begin{aligned} &x &&: x < n\\ &x - n &&: x \ge n \end{aligned} \right.$

43 Views Asked by At

if n is a constant, is there a predefined/shorter mathematical function that can replace this function : $$ f(x) = \left\{\begin{aligned} &x &&: x < n\\ &x - n &&: x \ge n \end{aligned} \right.$$

where x >= 0 and x < 2n

3

There are 3 best solutions below

2
On BEST ANSWER

You can build this function from the Heaviside step:

$$f(x):= x-nH(x-n).$$

Make sure to use the convention $H(0):=1.$

0
On

The function is discontinuous if $n\neq0$, and any reasonable operations with continuous functions give again something continuous. So if you don't want a definition by cases you'll have to either use a discontinuous function at some point, or a complicated expression that won't be shorter than what you have. (e.g. something with $\arctan$ and floor.)

2
On

actually there IS a function that can do the same, which is the modulus

the above function is the same as

x mod n

although it isn't true for all values of x, it's what I have been looking for