A mathematical function for greater than operator

1.3k Views Asked by At

Are there a mathematical function that takes the integer variable $x$ and uses a constant $k$ then,

it outputs $x$ when $x > k$

else outputs Zero

For example, when $k=5$ and,

when $x$ is given inputs $2, 3, 4, 5, 6, 7$ respectively,

It must output $0, 0, 0, 0, 6, 7$ respectively.

I want a purely mathematical equation for the function.

(Only using variables, arithmetic symbols and other functions such as the absolute function, but without using comparison operators)

3

There are 3 best solutions below

2
On BEST ANSWER

Although fine answers have been given, alternatively one could do

$$f(x)=\frac x2\left(\frac{x-k}{|x-k|}+1\right)$$

Unfortunately we're dividing by $0$ if $x=k$, but if that doesn't occur, then you're good to go with this one.

Note that it is impossible to do only using variables and arithmetic symbols, since all of those are differentiable everywhere so any composition is also differentiable everywhere. We'll have to use "other functions such as the absolute function". I'm not quite sure to what extend we can use other mathematical functions, since, well, the one you described could be one.


Programatically however, as has been pointed out by @JMoravitz, a good solution would be

x(x>k);

Or, if boolean-to-integer conversion is not your thing, you could do

(x>k)?x:0;
0
On

I am not sure about what you consider to be algebraic but there is a famous function called the Heaviside function denoted by $u(x)$ which is equal to $1$ when $x>0$ and equal to $0$ otherwise. So for an integer $k$ your function will look something like this in terms of the Heavside function.

$$f(x) = xu(x-k)$$

Notice how when $x>k$ then $u(x-k) = 1$ so $f(x) = x$ and zero otherwise

3
On

Here is a solution using the ${\rm sign}(x)$ function: $$ f(x) = {x\over2}(1+{\rm sign}(x-k-0.5)). $$ We assume that both $x$ and $k$ are integers.